Blender  V2.93
GHOST_WindowViewCocoa.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 /* NSView subclass for drawing and handling input.
21  *
22  * COCOA_VIEW_BASE_CLASS will be either NSView or NSOpenGLView depending if
23  * we use a Metal or OpenGL layer for drawing in the view. We use macros
24  * to defined classes for each case, so we don't have to duplicate code as
25  * Objective-C does not have multiple inheritance. */
26 
27 // We need to subclass it in order to give Cocoa the feeling key events are trapped
28 @interface COCOA_VIEW_CLASS : COCOA_VIEW_BASE_CLASS <NSTextInput>
29 {
32 
33  bool composing;
34  NSString *composing_text;
35 
36  bool immediate_draw;
37 }
38 - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa
39  windowCocoa:(GHOST_WindowCocoa *)winCocoa;
40 @end
41 
42 @implementation COCOA_VIEW_CLASS
43 
44 - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa
45  windowCocoa:(GHOST_WindowCocoa *)winCocoa
46 {
47  systemCocoa = sysCocoa;
48  associatedWindow = winCocoa;
49 
50  composing = false;
51  composing_text = nil;
52 
53  immediate_draw = false;
54 }
55 
56 - (BOOL)acceptsFirstResponder
57 {
58  return YES;
59 }
60 
61 - (BOOL)acceptsFirstMouse:(NSEvent *)event
62 {
63  return YES;
64 }
65 
66 // The trick to prevent Cocoa from complaining (beeping)
67 - (void)keyDown:(NSEvent *)event
68 {
70 
71  /* Start or continue composing? */
72  if ([[event characters] length] == 0 || [[event charactersIgnoringModifiers] length] == 0 ||
73  composing) {
74  composing = YES;
75 
76  // interpret event to call insertText
77  NSMutableArray *events;
78  events = [[NSMutableArray alloc] initWithCapacity:1];
79  [events addObject:event];
80  [self interpretKeyEvents:events]; // calls insertText
81  [events removeObject:event];
82  [events release];
83  return;
84  }
85 }
86 
87 - (void)keyUp:(NSEvent *)event
88 {
90 }
91 
92 - (void)flagsChanged:(NSEvent *)event
93 {
95 }
96 
97 - (void)mouseDown:(NSEvent *)event
98 {
100 }
101 
102 - (void)mouseUp:(NSEvent *)event
103 {
105 }
106 
107 - (void)rightMouseDown:(NSEvent *)event
108 {
110 }
111 
112 - (void)rightMouseUp:(NSEvent *)event
113 {
115 }
116 
117 - (void)mouseMoved:(NSEvent *)event
118 {
120 }
121 
122 - (void)mouseDragged:(NSEvent *)event
123 {
125 }
126 
127 - (void)rightMouseDragged:(NSEvent *)event
128 {
130 }
131 
132 - (void)scrollWheel:(NSEvent *)event
133 {
135 }
136 
137 - (void)otherMouseDown:(NSEvent *)event
138 {
140 }
141 
142 - (void)otherMouseUp:(NSEvent *)event
143 {
145 }
146 
147 - (void)otherMouseDragged:(NSEvent *)event
148 {
150 }
151 
152 - (void)magnifyWithEvent:(NSEvent *)event
153 {
155 }
156 
157 - (void)smartMagnifyWithEvent:(NSEvent *)event
158 {
160 }
161 
162 - (void)rotateWithEvent:(NSEvent *)event
163 {
165 }
166 
167 - (void)tabletPoint:(NSEvent *)event
168 {
169  systemCocoa->handleTabletEvent(event, [event type]);
170 }
171 
172 - (void)tabletProximity:(NSEvent *)event
173 {
174  systemCocoa->handleTabletEvent(event, [event type]);
175 }
176 
177 - (BOOL)isOpaque
178 {
179  return YES;
180 }
181 
182 - (void)drawRect:(NSRect)rect
183 {
184  if ([self inLiveResize]) {
185  /* Don't redraw while in live resize */
186  }
187  else {
188  [super drawRect:rect];
190 
191  /* For some cases like entering fullscreen we need to redraw immediately
192  * so our window does not show blank during the animation */
195  }
196 }
197 
198 // Text input
199 
200 - (void)composing_free
201 {
202  composing = NO;
203 
204  if (composing_text) {
205  [composing_text release];
206  composing_text = nil;
207  }
208 }
209 
210 - (void)insertText:(id)chars
211 {
212  [self composing_free];
213 }
214 
215 - (void)setMarkedText:(id)chars selectedRange:(NSRange)range
216 {
217  [self composing_free];
218  if ([chars length] == 0)
219  return;
220 
221  // start composing
222  composing = YES;
223  composing_text = [chars copy];
224 
225  // if empty, cancel
226  if ([composing_text length] == 0)
227  [self composing_free];
228 }
229 
230 - (void)unmarkText
231 {
232  [self composing_free];
233 }
234 
235 - (BOOL)hasMarkedText
236 {
237  return (composing) ? YES : NO;
238 }
239 
240 - (void)doCommandBySelector:(SEL)selector
241 {
242 }
243 
244 - (BOOL)isComposing
245 {
246  return composing;
247 }
248 
249 - (NSInteger)conversationIdentifier
250 {
251  return (NSInteger)self;
252 }
253 
254 - (NSAttributedString *)attributedSubstringFromRange:(NSRange)range
255 {
256  return [[[NSAttributedString alloc] init] autorelease];
257 }
258 
259 - (NSRange)markedRange
260 {
261  unsigned int length = (composing_text) ? [composing_text length] : 0;
262 
263  if (composing)
264  return NSMakeRange(0, length);
265 
266  return NSMakeRange(NSNotFound, 0);
267 }
268 
269 - (NSRange)selectedRange
270 {
271  unsigned int length = (composing_text) ? [composing_text length] : 0;
272  return NSMakeRange(0, length);
273 }
274 
275 - (NSRect)firstRectForCharacterRange:(NSRange)range
276 {
277  return NSZeroRect;
278 }
279 
280 - (NSUInteger)characterIndexForPoint:(NSPoint)point
281 {
282  return NSNotFound;
283 }
284 
285 - (NSArray *)validAttributesForMarkedText
286 {
287  return [NSArray array];
288 }
289 
290 @end
@ GHOST_kEventWindowUpdate
Definition: GHOST_Types.h:200
#define COCOA_VIEW_BASE_CLASS
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
Definition: btQuaternion.h:895
GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa *window)
GHOST_TSuccess handleMouseEvent(void *eventPtr)
GHOST_TSuccess handleKeyEvent(void *eventPtr)
GHOST_TSuccess handleTabletEvent(void *eventPtr, short eventType)
void dispatchEvents()
bool getImmediateDraw(void) const
GHOST_SystemCocoa * systemCocoa
GHOST_WindowCocoa * associatedWindow