]>
Commit | Line | Data |
---|---|---|
a15eb0a5 SC |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: mac/toplevel.cpp | |
3 | // Purpose: implements wxTopLevelWindow for MSW | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 24.09.01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) | |
6aa89a22 | 9 | // License: wxWindows licence |
a15eb0a5 SC |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "toplevel.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/app.h" | |
33 | #include "wx/toplevel.h" | |
422644a3 | 34 | #include "wx/frame.h" |
a15eb0a5 SC |
35 | #include "wx/string.h" |
36 | #include "wx/log.h" | |
37 | #include "wx/intl.h" | |
38 | #endif //WX_PRECOMP | |
39 | ||
5f0b2f22 | 40 | #include "wx/mac/uma.h" |
422644a3 | 41 | #include "wx/mac/aga.h" |
7c091673 | 42 | #include "wx/app.h" |
5f0b2f22 | 43 | #include "wx/tooltip.h" |
a07c1212 | 44 | #include "wx/dnd.h" |
1f90939c SC |
45 | #if wxUSE_SYSTEM_OPTIONS |
46 | #include "wx/sysopt.h" | |
47 | #endif | |
5f0b2f22 | 48 | |
dd49c691 SC |
49 | #include "ToolUtils.h" |
50 | ||
51 | ||
34dc8f91 SC |
52 | #define wxMAC_DEBUG_REDRAW 0 |
53 | #ifndef wxMAC_DEBUG_REDRAW | |
54 | #define wxMAC_DEBUG_REDRAW 0 | |
55 | #endif | |
56 | ||
a15eb0a5 SC |
57 | // ---------------------------------------------------------------------------- |
58 | // globals | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
61 | // list of all frames and modeless dialogs | |
32b5be3d RR |
62 | wxWindowList wxModelessWindows; |
63 | ||
64 | // double click testing | |
65 | static Point gs_lastWhere; | |
66 | static long gs_lastWhen = 0; | |
67 | ||
6a7e6411 | 68 | |
45ff8005 | 69 | #if TARGET_CARBON |
6a7e6411 | 70 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); |
45ff8005 | 71 | #endif |
6a7e6411 | 72 | |
a15eb0a5 SC |
73 | // ============================================================================ |
74 | // wxTopLevelWindowMac implementation | |
75 | // ============================================================================ | |
76 | ||
851b3a88 SC |
77 | // --------------------------------------------------------------------------- |
78 | // Carbon Events | |
79 | // --------------------------------------------------------------------------- | |
80 | ||
81 | #if TARGET_CARBON | |
82 | ||
83 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; | |
84 | ||
1542ea39 | 85 | static const EventTypeSpec eventList[] = |
851b3a88 SC |
86 | { |
87 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , | |
c5c9378c | 88 | |
e40298d5 | 89 | { kEventClassKeyboard, kEventRawKeyDown } , |
c5c9378c SC |
90 | { kEventClassKeyboard, kEventRawKeyRepeat } , |
91 | { kEventClassKeyboard, kEventRawKeyUp } , | |
92 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
93 | ||
851b3a88 SC |
94 | { kEventClassWindow , kEventWindowUpdate } , |
95 | { kEventClassWindow , kEventWindowActivated } , | |
96 | { kEventClassWindow , kEventWindowDeactivated } , | |
97 | { kEventClassWindow , kEventWindowBoundsChanging } , | |
98 | { kEventClassWindow , kEventWindowBoundsChanged } , | |
99 | { kEventClassWindow , kEventWindowClose } , | |
100 | ||
101 | { kEventClassMouse , kEventMouseDown } , | |
102 | { kEventClassMouse , kEventMouseUp } , | |
de127c69 | 103 | { kEventClassMouse , kEventMouseWheelMoved } , |
851b3a88 SC |
104 | { kEventClassMouse , kEventMouseMoved } , |
105 | { kEventClassMouse , kEventMouseDragged } , | |
106 | ||
107 | } ; | |
108 | ||
109 | static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
110 | { | |
111 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 112 | |
c5c9378c | 113 | wxWindow* focus = wxWindow::FindFocus() ; |
e40298d5 | 114 | char charCode ; |
1542ea39 | 115 | UInt32 keyCode ; |
c5c9378c | 116 | UInt32 modifiers ; |
e40298d5 | 117 | Point point ; |
c5c9378c SC |
118 | |
119 | EventRef rawEvent ; | |
1542ea39 | 120 | |
c5c9378c | 121 | GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; |
1542ea39 | 122 | |
e40298d5 JS |
123 | GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
124 | GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
125 | GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
126 | GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, | |
127 | sizeof( Point ), NULL, &point ); | |
128 | ||
e40298d5 JS |
129 | switch ( GetEventKind( event ) ) |
130 | { | |
131 | case kEventTextInputUnicodeForKeyEvent : | |
ace07c80 | 132 | // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not |
5d2e69e8 | 133 | // get its own kEventTextInputUnicodeForKeyEvent, so we route back the |
ace07c80 SC |
134 | wxControl* control = wxDynamicCast( focus , wxControl ) ; |
135 | if ( control ) | |
136 | { | |
137 | ControlHandle macControl = (ControlHandle) control->GetMacControl() ; | |
138 | if ( macControl ) | |
139 | { | |
140 | ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; | |
141 | result = noErr ; | |
142 | } | |
143 | } | |
144 | /* | |
145 | // this may lead to double events sent to a window in case all handlers have skipped the key down event | |
77a4354e VZ |
146 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; |
147 | UInt32 message = (keyCode << 8) + charCode; | |
148 | ||
1542ea39 | 149 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
150 | focus , message , modifiers , when , point.h , point.v ) ) |
151 | { | |
152 | result = noErr ; | |
153 | } | |
ace07c80 | 154 | */ |
e40298d5 JS |
155 | break ; |
156 | } | |
c5c9378c SC |
157 | |
158 | return result ; | |
159 | } | |
160 | ||
161 | static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
162 | { | |
163 | OSStatus result = eventNotHandledErr ; | |
164 | ||
165 | wxWindow* focus = wxWindow::FindFocus() ; | |
e40298d5 | 166 | char charCode ; |
1542ea39 | 167 | UInt32 keyCode ; |
c5c9378c | 168 | UInt32 modifiers ; |
e40298d5 JS |
169 | Point point ; |
170 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
171 | ||
172 | GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); | |
173 | GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
174 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
175 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, | |
176 | sizeof( Point ), NULL, &point ); | |
177 | ||
178 | UInt32 message = (keyCode << 8) + charCode; | |
179 | switch( GetEventKind( event ) ) | |
180 | { | |
181 | case kEventRawKeyRepeat : | |
182 | case kEventRawKeyDown : | |
e40298d5 | 183 | { |
404f1d80 SC |
184 | WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; |
185 | WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
186 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
187 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( | |
188 | focus , message , modifiers , when , point.h , point.v ) ) | |
189 | { | |
190 | result = noErr ; | |
191 | } | |
192 | wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; | |
e40298d5 JS |
193 | } |
194 | break ; | |
195 | case kEventRawKeyUp : | |
1542ea39 | 196 | if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( |
e40298d5 JS |
197 | focus , message , modifiers , when , point.h , point.v ) ) |
198 | { | |
199 | result = noErr ; | |
200 | } | |
201 | break ; | |
202 | case kEventRawKeyModifiersChanged : | |
203 | { | |
204 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
205 | ||
206 | event.m_shiftDown = modifiers & shiftKey; | |
207 | event.m_controlDown = modifiers & controlKey; | |
208 | event.m_altDown = modifiers & optionKey; | |
209 | event.m_metaDown = modifiers & cmdKey; | |
210 | ||
211 | event.m_x = point.h; | |
212 | event.m_y = point.v; | |
213 | event.m_timeStamp = when; | |
214 | wxWindow* focus = wxWindow::FindFocus() ; | |
215 | event.SetEventObject(focus); | |
216 | ||
8d60dc8a | 217 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey ) |
e40298d5 JS |
218 | { |
219 | event.m_keyCode = WXK_CONTROL ; | |
220 | event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
221 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
222 | } | |
8d60dc8a | 223 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey ) |
e40298d5 JS |
224 | { |
225 | event.m_keyCode = WXK_SHIFT ; | |
226 | event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
227 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
228 | } | |
8d60dc8a | 229 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey ) |
e40298d5 JS |
230 | { |
231 | event.m_keyCode = WXK_ALT ; | |
232 | event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
233 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
234 | } | |
b7aec135 SC |
235 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & cmdKey ) |
236 | { | |
237 | event.m_keyCode = WXK_COMMAND ; | |
238 | event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
239 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
240 | } | |
e40298d5 JS |
241 | wxTheApp->s_lastModifiers = modifiers ; |
242 | } | |
243 | break ; | |
244 | } | |
851b3a88 SC |
245 | |
246 | return result ; | |
247 | } | |
248 | ||
67245665 | 249 | pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
851b3a88 SC |
250 | { |
251 | OSStatus result = eventNotHandledErr ; | |
252 | ||
e40298d5 JS |
253 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
254 | Point point ; | |
255 | UInt32 modifiers = 0; | |
256 | EventMouseButton button = 0 ; | |
257 | UInt32 click = 0 ; | |
1542ea39 | 258 | |
e40298d5 JS |
259 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, |
260 | sizeof( Point ), NULL, &point ); | |
261 | GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, | |
262 | sizeof( UInt32 ), NULL, &modifiers ); | |
263 | GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, | |
264 | sizeof( EventMouseButton ), NULL, &button ); | |
265 | GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, | |
266 | sizeof( UInt32 ), NULL, &click ); | |
1542ea39 | 267 | |
e40298d5 JS |
268 | if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) |
269 | modifiers += btnState ; | |
1542ea39 | 270 | |
01c18566 SC |
271 | // temporary hack to support true two button mouse |
272 | if ( button == kEventMouseButtonSecondary ) | |
273 | { | |
274 | modifiers |= controlKey ; | |
275 | } | |
e40298d5 | 276 | WindowRef window ; |
851b3a88 | 277 | short windowPart = ::FindWindow(point, &window); |
a3195b73 | 278 | |
67245665 SC |
279 | // either we really are active or we are capturing mouse events |
280 | ||
281 | if ( (IsWindowActive(window) && windowPart == inContent) || | |
282 | (wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindow() == toplevelWindow) ) | |
851b3a88 | 283 | { |
e40298d5 JS |
284 | switch ( GetEventKind( event ) ) |
285 | { | |
286 | case kEventMouseDown : | |
287 | toplevelWindow->MacFireMouseEvent( mouseDown , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
288 | result = noErr ; | |
289 | break ; | |
290 | case kEventMouseUp : | |
291 | toplevelWindow->MacFireMouseEvent( mouseUp , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
292 | result = noErr ; | |
293 | break ; | |
294 | case kEventMouseMoved : | |
3c589c7f | 295 | wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; |
e40298d5 JS |
296 | result = noErr ; |
297 | break ; | |
298 | case kEventMouseDragged : | |
299 | toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
300 | result = noErr ; | |
301 | break ; | |
de127c69 GD |
302 | case kEventMouseWheelMoved : |
303 | { | |
304 | //bClearTooltip = false; | |
305 | EventMouseWheelAxis axis = kEventMouseWheelAxisY; | |
306 | SInt32 delta = 0; | |
307 | Point mouseLoc = {0, 0}; | |
308 | if (::GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis, | |
309 | NULL, sizeof(EventMouseWheelAxis), NULL, &axis) == noErr && | |
310 | ::GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger, | |
311 | NULL, sizeof(SInt32), NULL, &delta) == noErr && | |
312 | ::GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, | |
313 | NULL, sizeof(Point), NULL, &mouseLoc) == noErr) | |
314 | { | |
315 | wxMouseEvent wheelEvent(wxEVT_MOUSEWHEEL); | |
316 | ||
317 | wheelEvent.m_x = mouseLoc.h; | |
318 | wheelEvent.m_y = mouseLoc.v; | |
319 | ||
320 | wheelEvent.m_wheelRotation = delta; | |
321 | wheelEvent.m_wheelDelta = 1; | |
322 | wheelEvent.m_linesPerAction = 1; | |
323 | ||
324 | wxWindow* currentMouseWindow = NULL; | |
325 | wxWindow::MacGetWindowFromPoint(wxPoint(mouseLoc.h, mouseLoc.v), ¤tMouseWindow); | |
326 | ||
327 | if (currentMouseWindow) | |
328 | { | |
329 | currentMouseWindow->GetEventHandler()->ProcessEvent(wheelEvent); | |
330 | result = noErr; | |
331 | } | |
332 | } | |
333 | } | |
334 | break ; | |
e40298d5 JS |
335 | default : |
336 | break ; | |
337 | } | |
338 | } | |
1542ea39 | 339 | |
e40298d5 | 340 | return result ; |
1542ea39 | 341 | |
851b3a88 SC |
342 | |
343 | } | |
344 | static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
345 | { | |
346 | OSStatus result = eventNotHandledErr ; | |
347 | OSStatus err = noErr ; | |
348 | ||
e40298d5 JS |
349 | UInt32 attributes; |
350 | WindowRef windowRef ; | |
351 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; | |
1542ea39 | 352 | |
e40298d5 JS |
353 | GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL, |
354 | sizeof( WindowRef ), NULL, &windowRef ); | |
1542ea39 | 355 | |
e40298d5 JS |
356 | switch( GetEventKind( event ) ) |
357 | { | |
358 | case kEventWindowUpdate : | |
359 | if ( !wxPendingDelete.Member(toplevelWindow) ) | |
360 | toplevelWindow->MacUpdate( EventTimeToTicks( GetEventTime( event ) ) ) ; | |
361 | result = noErr ; | |
362 | break ; | |
363 | case kEventWindowActivated : | |
364 | toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , true) ; | |
365 | result = noErr ; | |
366 | break ; | |
367 | case kEventWindowDeactivated : | |
368 | toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ; | |
369 | result = noErr ; | |
370 | break ; | |
371 | case kEventWindowClose : | |
372 | toplevelWindow->Close() ; | |
373 | result = noErr ; | |
374 | break ; | |
375 | case kEventWindowBoundsChanged : | |
376 | err = GetEventParameter( event, kEventParamAttributes, typeUInt32, | |
377 | NULL, sizeof( UInt32 ), NULL, &attributes ); | |
378 | if ( err == noErr ) | |
379 | { | |
380 | Rect newContentRect ; | |
381 | ||
382 | GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, | |
383 | sizeof( newContentRect ), NULL, &newContentRect ); | |
1542ea39 RD |
384 | |
385 | toplevelWindow->SetSize( newContentRect.left , newContentRect.top , | |
386 | newContentRect.right - newContentRect.left , | |
851b3a88 SC |
387 | newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); |
388 | ||
e40298d5 JS |
389 | result = noErr; |
390 | } | |
391 | break ; | |
f81bfef9 SC |
392 | case kEventWindowBoundsChanging : |
393 | err = GetEventParameter( event, kEventParamAttributes, typeUInt32, | |
394 | NULL, sizeof( UInt32 ), NULL, &attributes ); | |
395 | if ( err == noErr ) | |
396 | { | |
397 | Rect newContentRect ; | |
398 | ||
399 | GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, | |
400 | sizeof( newContentRect ), NULL, &newContentRect ); | |
5d2e69e8 | 401 | |
83901ec2 SC |
402 | wxSize formerSize = toplevelWindow->GetSize() ; |
403 | ||
404 | if ( (attributes & kWindowBoundsChangeSizeChanged ) || | |
405 | ( attributes & kWindowBoundsChangeOriginChanged ) ) | |
406 | toplevelWindow->SetSize( newContentRect.left , newContentRect.top , | |
407 | newContentRect.right - newContentRect.left , | |
408 | newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); | |
409 | ||
410 | int x , y , w , h ; | |
411 | toplevelWindow->GetPosition( &x , &y ) ; | |
412 | toplevelWindow->GetSize( &w , &h ) ; | |
413 | Rect adjustedRect = { y , x , y + h , x + w } ; | |
414 | ||
415 | if ( !EqualRect( &newContentRect , &adjustedRect ) ) | |
f81bfef9 | 416 | { |
83901ec2 | 417 | SetEventParameter( event , kEventParamCurrentBounds , typeQDRectangle, sizeof( adjustedRect ) , &adjustedRect ) ; |
f81bfef9 | 418 | } |
83901ec2 SC |
419 | |
420 | if ( toplevelWindow->GetSize() != formerSize ) | |
421 | toplevelWindow->Update() ; | |
422 | ||
f81bfef9 SC |
423 | result = noErr ; |
424 | } | |
425 | break ; | |
e40298d5 JS |
426 | default : |
427 | break ; | |
428 | } | |
429 | return result ; | |
851b3a88 SC |
430 | } |
431 | ||
432 | pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
433 | { | |
434 | OSStatus result = eventNotHandledErr ; | |
435 | ||
436 | switch ( GetEventClass( event ) ) | |
437 | { | |
c5c9378c | 438 | case kEventClassKeyboard : |
e40298d5 | 439 | result = KeyboardEventHandler( handler, event , data ) ; |
c5c9378c | 440 | break ; |
851b3a88 | 441 | case kEventClassTextInput : |
e40298d5 | 442 | result = TextInputEventHandler( handler, event , data ) ; |
851b3a88 SC |
443 | break ; |
444 | case kEventClassWindow : | |
e40298d5 JS |
445 | result = WindowEventHandler( handler, event , data ) ; |
446 | break ; | |
851b3a88 | 447 | case kEventClassMouse : |
e40298d5 JS |
448 | result = MouseEventHandler( handler, event , data ) ; |
449 | break ; | |
851b3a88 SC |
450 | default : |
451 | break ; | |
452 | } | |
453 | return result ; | |
454 | } | |
455 | ||
456 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) | |
457 | ||
458 | #endif | |
459 | ||
5f0b2f22 SC |
460 | // --------------------------------------------------------------------------- |
461 | // wxWindowMac utility functions | |
462 | // --------------------------------------------------------------------------- | |
463 | ||
464 | // Find an item given the Macintosh Window Reference | |
465 | ||
466 | wxList *wxWinMacWindowList = NULL; | |
76a5e5d2 | 467 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef) |
5f0b2f22 | 468 | { |
46d0c707 SC |
469 | if ( wxWinMacWindowList == NULL ) |
470 | return NULL ; | |
5f0b2f22 SC |
471 | wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); |
472 | if (!node) | |
473 | return NULL; | |
eb22f2a6 | 474 | return (wxTopLevelWindowMac *)node->GetData(); |
5f0b2f22 SC |
475 | } |
476 | ||
76a5e5d2 | 477 | void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win) |
5f0b2f22 SC |
478 | { |
479 | // adding NULL WindowRef is (first) surely a result of an error and | |
480 | // (secondly) breaks menu command processing | |
427ff662 | 481 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
5f0b2f22 SC |
482 | |
483 | if ( !wxWinMacWindowList->Find((long)inWindowRef) ) | |
484 | wxWinMacWindowList->Append((long)inWindowRef, win); | |
485 | } | |
486 | ||
487 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) | |
488 | { | |
489 | wxWinMacWindowList->DeleteObject(win); | |
490 | } | |
491 | ||
492 | ||
a15eb0a5 SC |
493 | // ---------------------------------------------------------------------------- |
494 | // wxTopLevelWindowMac creation | |
495 | // ---------------------------------------------------------------------------- | |
496 | ||
76a5e5d2 | 497 | WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL; |
245f3581 | 498 | wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; |
1f90939c | 499 | bool wxTopLevelWindowMac::s_macWindowCompositing = FALSE; |
5f0b2f22 | 500 | |
a15eb0a5 SC |
501 | void wxTopLevelWindowMac::Init() |
502 | { | |
503 | m_iconized = | |
504 | m_maximizeOnShow = FALSE; | |
5f0b2f22 SC |
505 | m_macNoEraseUpdateRgn = NewRgn() ; |
506 | m_macNeedsErasing = false ; | |
6a17ca35 | 507 | m_macWindow = NULL ; |
1f90939c | 508 | m_macUsesCompositing = FALSE ; |
851b3a88 | 509 | #if TARGET_CARBON |
7c091673 | 510 | m_macEventHandler = NULL ; |
851b3a88 | 511 | #endif |
a15eb0a5 SC |
512 | } |
513 | ||
118f012e SC |
514 | class wxMacDeferredWindowDeleter : public wxObject |
515 | { | |
516 | public : | |
1542ea39 RD |
517 | wxMacDeferredWindowDeleter( WindowRef windowRef ) |
518 | { | |
519 | m_macWindow = windowRef ; | |
118f012e | 520 | } |
1542ea39 RD |
521 | virtual ~wxMacDeferredWindowDeleter() |
522 | { | |
523 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
118f012e SC |
524 | } |
525 | protected : | |
526 | WindowRef m_macWindow ; | |
527 | } ; | |
528 | ||
a15eb0a5 SC |
529 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
530 | wxWindowID id, | |
531 | const wxString& title, | |
532 | const wxPoint& pos, | |
533 | const wxSize& size, | |
534 | long style, | |
535 | const wxString& name) | |
536 | { | |
537 | // init our fields | |
538 | Init(); | |
539 | ||
540 | m_windowStyle = style; | |
541 | ||
542 | SetName(name); | |
543 | ||
544 | m_windowId = id == -1 ? NewControlId() : id; | |
545 | ||
546 | wxTopLevelWindows.Append(this); | |
547 | ||
548 | if ( parent ) | |
549 | parent->AddChild(this); | |
550 | ||
551 | return TRUE; | |
552 | } | |
553 | ||
554 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
555 | { | |
6a17ca35 SC |
556 | if ( m_macWindow ) |
557 | { | |
558 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
118f012e | 559 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 560 | } |
1542ea39 | 561 | |
f75363ee | 562 | #if TARGET_CARBON |
7c091673 SC |
563 | if ( m_macEventHandler ) |
564 | { | |
565 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
566 | m_macEventHandler = NULL ; | |
567 | } | |
1542ea39 | 568 | #endif |
851b3a88 | 569 | |
5f0b2f22 SC |
570 | wxRemoveMacWindowAssociation( this ) ; |
571 | ||
a15eb0a5 SC |
572 | if ( wxModelessWindows.Find(this) ) |
573 | wxModelessWindows.DeleteObject(this); | |
574 | ||
76a5e5d2 | 575 | DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; |
a15eb0a5 SC |
576 | } |
577 | ||
578 | ||
579 | // ---------------------------------------------------------------------------- | |
580 | // wxTopLevelWindowMac maximize/minimize | |
581 | // ---------------------------------------------------------------------------- | |
582 | ||
583 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
584 | { | |
1f90939c SC |
585 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
586 | wxMacWindowClipper clip (this); | |
b7aec135 SC |
587 | ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ; |
588 | ||
589 | Rect tempRect ; | |
590 | GrafPtr port ; | |
591 | GetPort( &port ) ; | |
592 | Point pt = { 0, 0 } ; | |
593 | SetPortWindowPort((WindowRef)m_macWindow) ; | |
594 | LocalToGlobal( &pt ) ; | |
595 | SetPort( port ) ; | |
596 | ||
597 | GetWindowPortBounds((WindowRef)m_macWindow, &tempRect ) ; | |
598 | SetSize( pt.h , pt.v , tempRect.right-tempRect.left , | |
599 | tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING); | |
a15eb0a5 SC |
600 | } |
601 | ||
602 | bool wxTopLevelWindowMac::IsMaximized() const | |
603 | { | |
b7aec135 | 604 | return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ; |
a15eb0a5 SC |
605 | } |
606 | ||
607 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
608 | { | |
b7aec135 SC |
609 | if ( IsWindowCollapsable((WindowRef)m_macWindow) ) |
610 | CollapseWindow((WindowRef)m_macWindow , iconize ) ; | |
a15eb0a5 SC |
611 | } |
612 | ||
613 | bool wxTopLevelWindowMac::IsIconized() const | |
614 | { | |
b7aec135 | 615 | return IsWindowCollapsed((WindowRef)m_macWindow ) ; |
a15eb0a5 SC |
616 | } |
617 | ||
618 | void wxTopLevelWindowMac::Restore() | |
619 | { | |
620 | // not available on mac | |
621 | } | |
622 | ||
623 | // ---------------------------------------------------------------------------- | |
624 | // wxTopLevelWindowMac misc | |
625 | // ---------------------------------------------------------------------------- | |
626 | ||
627 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) | |
628 | { | |
629 | // this sets m_icon | |
630 | wxTopLevelWindowBase::SetIcon(icon); | |
631 | } | |
5f0b2f22 SC |
632 | |
633 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, | |
634 | const wxPoint& pos, | |
635 | const wxSize& size, | |
636 | long style, | |
1542ea39 | 637 | const wxString& name ) |
5f0b2f22 | 638 | { |
47ac4f9b | 639 | OSStatus err = noErr ; |
e40298d5 JS |
640 | SetName(name); |
641 | m_windowStyle = style; | |
642 | m_isShown = FALSE; | |
1542ea39 | 643 | |
e40298d5 | 644 | // create frame. |
1542ea39 | 645 | |
5f0b2f22 | 646 | Rect theBoundsRect; |
1542ea39 | 647 | |
e40298d5 JS |
648 | m_x = (int)pos.x; |
649 | m_y = (int)pos.y; | |
650 | if ( m_y < 50 ) | |
651 | m_y = 50 ; | |
652 | if ( m_x < 20 ) | |
653 | m_x = 20 ; | |
1542ea39 | 654 | |
e40298d5 | 655 | m_width = size.x; |
1542ea39 | 656 | if (m_width == -1) |
5f0b2f22 | 657 | m_width = 20; |
e40298d5 | 658 | m_height = size.y; |
1542ea39 | 659 | if (m_height == -1) |
5f0b2f22 | 660 | m_height = 20; |
1542ea39 | 661 | |
5f0b2f22 | 662 | ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); |
1542ea39 | 663 | |
5f0b2f22 | 664 | // translate the window attributes in the appropriate window class and attributes |
1542ea39 | 665 | |
5f0b2f22 SC |
666 | WindowClass wclass = 0; |
667 | WindowAttributes attr = kWindowNoAttributes ; | |
1542ea39 | 668 | |
f5744893 | 669 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 670 | { |
1542ea39 | 671 | if ( |
f5744893 SC |
672 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
673 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
674 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 675 | ) |
5f0b2f22 | 676 | { |
f5744893 SC |
677 | wclass = kFloatingWindowClass ; |
678 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
679 | { | |
680 | attr |= kWindowSideTitlebarAttribute ; | |
681 | } | |
682 | } | |
683 | else | |
684 | { | |
2b5f62a0 | 685 | #if TARGET_CARBON |
f5744893 | 686 | wclass = kPlainWindowClass ; |
2b5f62a0 VZ |
687 | #else |
688 | wclass = kFloatingWindowClass ; | |
689 | #endif | |
5f0b2f22 SC |
690 | } |
691 | } | |
692 | else if ( HasFlag( wxCAPTION ) ) | |
693 | { | |
1542ea39 | 694 | wclass = kDocumentWindowClass ; |
5f0b2f22 SC |
695 | } |
696 | else | |
697 | { | |
f5744893 | 698 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
47ac4f9b | 699 | HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
700 | { |
701 | wclass = kDocumentWindowClass ; | |
702 | } | |
703 | else | |
704 | { | |
2b5f62a0 | 705 | #if TARGET_CARBON |
f5744893 | 706 | wclass = kPlainWindowClass ; |
2b5f62a0 VZ |
707 | #else |
708 | wclass = kModalWindowClass ; | |
709 | #endif | |
f5744893 | 710 | } |
5f0b2f22 | 711 | } |
1542ea39 | 712 | |
47ac4f9b | 713 | if ( HasFlag( wxMINIMIZE_BOX ) ) |
5f0b2f22 | 714 | { |
5f0b2f22 SC |
715 | attr |= kWindowCollapseBoxAttribute ; |
716 | } | |
47ac4f9b SC |
717 | if ( HasFlag( wxMAXIMIZE_BOX ) ) |
718 | { | |
719 | attr |= kWindowFullZoomAttribute ; | |
720 | } | |
5f0b2f22 SC |
721 | if ( HasFlag( wxRESIZE_BORDER ) ) |
722 | { | |
723 | attr |= kWindowResizableAttribute ; | |
724 | } | |
47ac4f9b | 725 | if ( HasFlag( wxCLOSE_BOX) ) |
5f0b2f22 SC |
726 | { |
727 | attr |= kWindowCloseBoxAttribute ; | |
728 | } | |
1542ea39 | 729 | |
1f90939c SC |
730 | attr |= kWindowLiveResizeAttribute; //turn on live resizing |
731 | ||
b9c10231 SC |
732 | #if TARGET_CARBON |
733 | #if 0 // having problems right now with that | |
6a7e6411 RD |
734 | if (HasFlag(wxSTAY_ON_TOP)) |
735 | wclass = kUtilityWindowClass; | |
b9c10231 SC |
736 | #endif |
737 | #endif | |
6a7e6411 | 738 | |
1f90939c SC |
739 | //this setup lets us have compositing and non-compositing |
740 | //windows in the same application. | |
741 | ||
742 | if ( wxTopLevelWindowMac::s_macWindowCompositing ) | |
743 | { | |
744 | attr |= kWindowCompositingAttribute; | |
745 | m_macUsesCompositing = TRUE; | |
746 | } | |
747 | else | |
748 | { | |
749 | m_macUsesCompositing = FALSE; | |
750 | } | |
751 | ||
45ff8005 | 752 | #if TARGET_CARBON |
6a7e6411 RD |
753 | if ( HasFlag(wxFRAME_SHAPED) ) |
754 | { | |
755 | WindowDefSpec customWindowDefSpec; | |
756 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
757 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
758 | ||
47ac4f9b | 759 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, |
6a7e6411 RD |
760 | attr, &theBoundsRect, |
761 | (WindowRef*) &m_macWindow); | |
762 | } | |
763 | else | |
45ff8005 | 764 | #endif |
6a7e6411 | 765 | { |
47ac4f9b | 766 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
6a7e6411 RD |
767 | } |
768 | ||
47ac4f9b | 769 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); |
5f0b2f22 | 770 | wxAssociateWinWithMacWindow( m_macWindow , this ) ; |
427ff662 | 771 | UMASetWTitle( (WindowRef)m_macWindow , title ) ; |
1f90939c SC |
772 | if ( wxTopLevelWindowMac::s_macWindowCompositing ) |
773 | { | |
774 | ::GetRootControl( (WindowRef)m_macWindow, (ControlHandle*)&m_macRootControl ) ; | |
775 | } | |
776 | else | |
777 | { | |
778 | ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ; | |
779 | } | |
851b3a88 | 780 | #if TARGET_CARBON |
e40298d5 | 781 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
1542ea39 | 782 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(), |
73bdd73a | 783 | GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler); |
851b3a88 | 784 | #endif |
5f0b2f22 | 785 | m_macFocus = NULL ; |
6a7e6411 RD |
786 | |
787 | ||
45ff8005 | 788 | #if TARGET_CARBON |
6a7e6411 RD |
789 | if ( HasFlag(wxFRAME_SHAPED) ) |
790 | { | |
791 | // default shape matches the window size | |
792 | wxRegion rgn(0, 0, m_width, m_height); | |
793 | SetShape(rgn); | |
794 | } | |
45ff8005 | 795 | #endif |
3dfafdb9 RD |
796 | |
797 | wxWindowCreateEvent event(this); | |
798 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
799 | } |
800 | ||
1f90939c SC |
801 | bool wxTopLevelWindowMac::MacEnableCompositing( bool useCompositing ) |
802 | { | |
803 | bool oldval = s_macWindowCompositing; | |
804 | s_macWindowCompositing = useCompositing; | |
805 | return oldval; | |
806 | } | |
807 | ||
1542ea39 | 808 | void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin) |
5f0b2f22 | 809 | { |
76a5e5d2 SC |
810 | ((Point*)localOrigin)->h = 0; |
811 | ((Point*)localOrigin)->v = 0; | |
812 | ((Rect*)clipRect)->left = 0; | |
813 | ((Rect*)clipRect)->top = 0; | |
814 | ((Rect*)clipRect)->right = m_width; | |
815 | ((Rect*)clipRect)->bottom = m_height; | |
5f0b2f22 SC |
816 | *window = m_macWindow ; |
817 | *rootwin = this ; | |
818 | } | |
819 | ||
5d2e69e8 | 820 | void wxTopLevelWindowMac::ClearBackground() |
5f0b2f22 | 821 | { |
5d2e69e8 | 822 | wxWindow::ClearBackground() ; |
5f0b2f22 SC |
823 | } |
824 | ||
1542ea39 | 825 | WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding() |
5f0b2f22 SC |
826 | { |
827 | return m_macRootControl ; | |
828 | } | |
829 | ||
830 | ||
831 | void wxTopLevelWindowMac::MacUpdate( long timestamp) | |
832 | { | |
66a09d47 | 833 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
76a5e5d2 | 834 | |
1925be65 SC |
835 | RgnHandle visRgn = NewRgn() ; |
836 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), visRgn ); | |
76a5e5d2 | 837 | BeginUpdate( (WindowRef)m_macWindow ) ; |
5f0b2f22 | 838 | |
1542ea39 | 839 | RgnHandle updateRgn = NewRgn(); |
5f0b2f22 | 840 | RgnHandle diffRgn = NewRgn() ; |
1925be65 | 841 | |
5f0b2f22 SC |
842 | if ( updateRgn && diffRgn ) |
843 | { | |
732b3a75 SC |
844 | #if 1 |
845 | // macos internal control redraws clean up areas we'd like to redraw ourselves | |
846 | // therefore we pick the boundary rect and make sure we can redraw it | |
1925be65 SC |
847 | // this has to be intersected by the visRgn in order to avoid drawing over its own |
848 | // boundaries | |
732b3a75 SC |
849 | RgnHandle trueUpdateRgn = NewRgn() ; |
850 | Rect trueUpdateRgnBoundary ; | |
851 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), trueUpdateRgn ); | |
852 | GetRegionBounds( trueUpdateRgn , &trueUpdateRgnBoundary ) ; | |
1925be65 SC |
853 | RectRgn( updateRgn , &trueUpdateRgnBoundary ) ; |
854 | SectRgn( updateRgn , visRgn , updateRgn ) ; | |
732b3a75 SC |
855 | if ( trueUpdateRgn ) |
856 | DisposeRgn( trueUpdateRgn ) ; | |
857 | SetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ) ; | |
858 | #else | |
76a5e5d2 | 859 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); |
732b3a75 | 860 | #endif |
76a5e5d2 | 861 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; |
5f0b2f22 SC |
862 | if ( !EmptyRgn( updateRgn ) ) |
863 | { | |
864 | MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ; | |
865 | } | |
866 | } | |
867 | if ( updateRgn ) | |
868 | DisposeRgn( updateRgn ); | |
869 | if ( diffRgn ) | |
870 | DisposeRgn( diffRgn ); | |
1925be65 SC |
871 | if ( visRgn ) |
872 | DisposeRgn( visRgn ) ; | |
5d2e69e8 | 873 | |
76a5e5d2 SC |
874 | EndUpdate( (WindowRef)m_macWindow ) ; |
875 | SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
5f0b2f22 SC |
876 | m_macNeedsErasing = false ; |
877 | } | |
878 | ||
879 | ||
880 | // Raise the window to the top of the Z order | |
881 | void wxTopLevelWindowMac::Raise() | |
882 | { | |
7f3c339c | 883 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
884 | } |
885 | ||
886 | // Lower the window to the bottom of the Z order | |
887 | void wxTopLevelWindowMac::Lower() | |
888 | { | |
76a5e5d2 | 889 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
890 | } |
891 | ||
1542ea39 | 892 | void wxTopLevelWindowMac::MacFireMouseEvent( |
e40298d5 | 893 | wxUint16 kind , wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp ) |
5f0b2f22 SC |
894 | { |
895 | wxMouseEvent event(wxEVT_LEFT_DOWN); | |
851b3a88 SC |
896 | bool isDown = !(modifiers & btnState) ; // 1 is for up |
897 | bool controlDown = modifiers & controlKey ; // for simulating right mouse | |
1542ea39 | 898 | |
5f0b2f22 | 899 | event.m_leftDown = isDown && !controlDown; |
1542ea39 | 900 | |
5f0b2f22 SC |
901 | event.m_middleDown = FALSE; |
902 | event.m_rightDown = isDown && controlDown; | |
903 | ||
851b3a88 | 904 | if ( kind == mouseDown ) |
5f0b2f22 SC |
905 | { |
906 | if ( controlDown ) | |
907 | event.SetEventType(wxEVT_RIGHT_DOWN ) ; | |
908 | else | |
909 | event.SetEventType(wxEVT_LEFT_DOWN ) ; | |
910 | } | |
851b3a88 | 911 | else if ( kind == mouseUp ) |
5f0b2f22 SC |
912 | { |
913 | if ( controlDown ) | |
914 | event.SetEventType(wxEVT_RIGHT_UP ) ; | |
915 | else | |
916 | event.SetEventType(wxEVT_LEFT_UP ) ; | |
917 | } | |
918 | else | |
919 | { | |
920 | event.SetEventType(wxEVT_MOTION ) ; | |
921 | } | |
922 | ||
851b3a88 SC |
923 | event.m_shiftDown = modifiers & shiftKey; |
924 | event.m_controlDown = modifiers & controlKey; | |
925 | event.m_altDown = modifiers & optionKey; | |
926 | event.m_metaDown = modifiers & cmdKey; | |
5f0b2f22 | 927 | |
851b3a88 SC |
928 | Point localwhere ; |
929 | localwhere.h = x ; | |
930 | localwhere.v = y ; | |
1542ea39 RD |
931 | |
932 | GrafPtr port ; | |
5f0b2f22 | 933 | ::GetPort( &port ) ; |
76a5e5d2 | 934 | ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ; |
5f0b2f22 SC |
935 | ::GlobalToLocal( &localwhere ) ; |
936 | ::SetPort( port ) ; | |
937 | ||
851b3a88 | 938 | if ( kind == mouseDown ) |
5f0b2f22 | 939 | { |
5be55d56 | 940 | if ( timestamp - gs_lastWhen <= (long) GetDblTime() ) |
5f0b2f22 | 941 | { |
32b5be3d | 942 | if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 ) |
5f0b2f22 | 943 | { |
32b5be3d RR |
944 | // This is not right if the second mouse down |
945 | // event occured in a differen window. We | |
946 | // correct this in MacDispatchMouseEvent. | |
5f0b2f22 SC |
947 | if ( controlDown ) |
948 | event.SetEventType(wxEVT_RIGHT_DCLICK ) ; | |
949 | else | |
950 | event.SetEventType(wxEVT_LEFT_DCLICK ) ; | |
951 | } | |
32b5be3d | 952 | gs_lastWhen = 0 ; |
5f0b2f22 SC |
953 | } |
954 | else | |
955 | { | |
851b3a88 | 956 | gs_lastWhen = timestamp ; |
5f0b2f22 | 957 | } |
32b5be3d | 958 | gs_lastWhere = localwhere ; |
5f0b2f22 SC |
959 | } |
960 | ||
961 | event.m_x = localwhere.h; | |
962 | event.m_y = localwhere.v; | |
963 | event.m_x += m_x; | |
964 | event.m_y += m_y; | |
965 | ||
851b3a88 | 966 | event.m_timeStamp = timestamp; |
5f0b2f22 SC |
967 | event.SetEventObject(this); |
968 | if ( wxTheApp->s_captureWindow ) | |
969 | { | |
970 | int x = event.m_x ; | |
971 | int y = event.m_y ; | |
972 | wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; | |
973 | event.m_x = x ; | |
974 | event.m_y = y ; | |
2e6857fa | 975 | event.SetEventObject( wxTheApp->s_captureWindow ) ; |
5f0b2f22 | 976 | wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; |
1542ea39 | 977 | |
851b3a88 | 978 | if ( kind == mouseUp ) |
5f0b2f22 SC |
979 | { |
980 | wxTheApp->s_captureWindow = NULL ; | |
6b57b49a | 981 | if ( !wxIsBusy() ) |
5f0b2f22 SC |
982 | { |
983 | m_cursor.MacInstall() ; | |
984 | } | |
985 | } | |
986 | } | |
987 | else | |
988 | { | |
989 | MacDispatchMouseEvent( event ) ; | |
990 | } | |
991 | } | |
e40298d5 | 992 | |
851b3a88 | 993 | #if !TARGET_CARBON |
5f0b2f22 | 994 | |
76a5e5d2 | 995 | void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part) |
5f0b2f22 | 996 | { |
1542ea39 | 997 | MacFireMouseEvent( mouseDown , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 998 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
999 | } |
1000 | ||
76a5e5d2 | 1001 | void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part) |
5f0b2f22 SC |
1002 | { |
1003 | switch (part) | |
1004 | { | |
1542ea39 | 1005 | case inContent: |
5f0b2f22 | 1006 | { |
1542ea39 | 1007 | MacFireMouseEvent( mouseUp , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 1008 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
1009 | } |
1010 | break ; | |
1011 | } | |
1012 | } | |
1013 | ||
76a5e5d2 | 1014 | void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part) |
5f0b2f22 SC |
1015 | { |
1016 | switch (part) | |
1017 | { | |
1542ea39 | 1018 | case inContent: |
5f0b2f22 | 1019 | { |
1542ea39 | 1020 | MacFireMouseEvent( nullEvent /*moved*/ , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 1021 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
1022 | } |
1023 | break ; | |
1024 | } | |
1025 | } | |
851b3a88 SC |
1026 | |
1027 | #endif | |
1028 | ||
245f3581 DE |
1029 | void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) |
1030 | { | |
1031 | if(s_macDeactivateWindow) | |
1032 | { | |
365796b1 | 1033 | wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow); |
245f3581 DE |
1034 | s_macDeactivateWindow->MacActivate(timestamp, false); |
1035 | } | |
1036 | } | |
1037 | ||
851b3a88 | 1038 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) |
5f0b2f22 | 1039 | { |
17f8d2a7 VZ |
1040 | // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this); |
1041 | ||
245f3581 DE |
1042 | if(s_macDeactivateWindow==this) |
1043 | s_macDeactivateWindow=NULL; | |
1044 | MacDelayedDeactivation(timestamp); | |
5f0b2f22 | 1045 | wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); |
851b3a88 | 1046 | event.m_timeStamp = timestamp ; |
5f0b2f22 | 1047 | event.SetEventObject(this); |
1542ea39 | 1048 | |
5f0b2f22 | 1049 | GetEventHandler()->ProcessEvent(event); |
1542ea39 | 1050 | |
76a5e5d2 | 1051 | UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ; |
1542ea39 | 1052 | |
a006e78b JS |
1053 | // Early versions of MacOS X don't refresh backgrounds properly, |
1054 | // so refresh the whole window on activation and deactivation. | |
1055 | long osVersion = UMAGetSystemVersion(); | |
1925be65 | 1056 | if (osVersion >= 0x1000 && osVersion < 0x1020 ) |
732b3a75 | 1057 | { |
a006e78b | 1058 | Refresh(TRUE); |
732b3a75 | 1059 | } |
a006e78b | 1060 | else |
732b3a75 SC |
1061 | { |
1062 | // for the moment we have to resolve some redrawing issues like this | |
1063 | // the OS is stealing some redrawing areas as soon as it draws a control | |
1064 | Refresh(TRUE); | |
1065 | } | |
5f0b2f22 SC |
1066 | } |
1067 | ||
851b3a88 SC |
1068 | #if !TARGET_CARBON |
1069 | ||
1542ea39 | 1070 | void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ) |
5f0b2f22 SC |
1071 | { |
1072 | } | |
1073 | ||
851b3a88 SC |
1074 | #endif |
1075 | ||
5f0b2f22 SC |
1076 | void wxTopLevelWindowMac::SetTitle(const wxString& title) |
1077 | { | |
1078 | wxWindow::SetTitle( title ) ; | |
427ff662 | 1079 | UMASetWTitle( (WindowRef)m_macWindow , title ) ; |
5f0b2f22 SC |
1080 | } |
1081 | ||
1082 | bool wxTopLevelWindowMac::Show(bool show) | |
1083 | { | |
1084 | if ( !wxWindow::Show(show) ) | |
1085 | return FALSE; | |
1086 | ||
1087 | if (show) | |
1542ea39 | 1088 | { |
1f90939c SC |
1089 | #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003 |
1090 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1091 | { | |
1092 | ::ShowWindow( (WindowRef)m_macWindow ); | |
1093 | } | |
1094 | else | |
1095 | #endif | |
1096 | { | |
1097 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); | |
1098 | } | |
1099 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
1100 | // no need to generate events here, they will get them triggered by macos | |
1101 | // actually they should be , but apparently they are not | |
1102 | wxSize size(m_width, m_height); | |
1103 | wxSizeEvent event(size, m_windowId); | |
1104 | event.SetEventObject(this); | |
1105 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1106 | } |
1107 | else | |
1108 | { | |
1f90939c SC |
1109 | #if wxUSE_SYSTEM_OPTIONS |
1110 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1111 | { | |
1112 | ::HideWindow((WindowRef) m_macWindow ); | |
1113 | } | |
1114 | else | |
1115 | #endif | |
1116 | { | |
1117 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); | |
1118 | } | |
5f0b2f22 SC |
1119 | } |
1120 | ||
1121 | if ( !show ) | |
1122 | { | |
1123 | } | |
1124 | else | |
1125 | { | |
1542ea39 | 1126 | Refresh() ; |
5f0b2f22 SC |
1127 | } |
1128 | ||
1129 | return TRUE; | |
1130 | } | |
1131 | ||
1132 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
1133 | { | |
1f90939c SC |
1134 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
1135 | wxMacWindowClipper clip (this); | |
1136 | ||
5f0b2f22 SC |
1137 | int former_x = m_x ; |
1138 | int former_y = m_y ; | |
1139 | int former_w = m_width ; | |
1140 | int former_h = m_height ; | |
1542ea39 | 1141 | |
e40298d5 JS |
1142 | int actualWidth = width; |
1143 | int actualHeight = height; | |
1144 | int actualX = x; | |
1145 | int actualY = y; | |
1542ea39 RD |
1146 | |
1147 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
5f0b2f22 | 1148 | actualWidth = m_minWidth; |
1542ea39 | 1149 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
5f0b2f22 | 1150 | actualHeight = m_minHeight; |
1542ea39 | 1151 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
5f0b2f22 | 1152 | actualWidth = m_maxWidth; |
1542ea39 | 1153 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
5f0b2f22 SC |
1154 | actualHeight = m_maxHeight; |
1155 | ||
1156 | bool doMove = false ; | |
1157 | bool doResize = false ; | |
1542ea39 | 1158 | |
5f0b2f22 SC |
1159 | if ( actualX != former_x || actualY != former_y ) |
1160 | { | |
1161 | doMove = true ; | |
1162 | } | |
1163 | if ( actualWidth != former_w || actualHeight != former_h ) | |
1164 | { | |
1165 | doResize = true ; | |
1166 | } | |
1167 | ||
1168 | if ( doMove || doResize ) | |
1169 | { | |
1170 | m_x = actualX ; | |
1171 | m_y = actualY ; | |
5f0b2f22 SC |
1172 | |
1173 | if ( doMove ) | |
76a5e5d2 | 1174 | ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost |
1542ea39 | 1175 | |
789a620a SC |
1176 | m_width = actualWidth ; |
1177 | m_height = actualHeight ; | |
1178 | ||
5f0b2f22 | 1179 | if ( doResize ) |
1542ea39 RD |
1180 | ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true); |
1181 | ||
2b5f62a0 VZ |
1182 | // the OS takes care of invalidating and erasing the new area so we only have to |
1183 | // take care of refreshing for full repaints | |
1184 | ||
e441e1f4 | 1185 | if ( doResize && HasFlag(wxFULL_REPAINT_ON_RESIZE) ) |
2b5f62a0 | 1186 | Refresh() ; |
1542ea39 RD |
1187 | |
1188 | ||
5f0b2f22 SC |
1189 | if ( IsKindOf( CLASSINFO( wxFrame ) ) ) |
1190 | { | |
1191 | wxFrame* frame = (wxFrame*) this ; | |
1066fece | 1192 | #if wxUSE_STATUSBAR |
5f0b2f22 | 1193 | frame->PositionStatusBar(); |
1066fece JS |
1194 | #endif |
1195 | #if wxUSE_TOOLBAR | |
5f0b2f22 | 1196 | frame->PositionToolBar(); |
1066fece | 1197 | #endif |
5f0b2f22 SC |
1198 | } |
1199 | if ( doMove ) | |
1200 | wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified | |
1201 | ||
1202 | MacRepositionScrollBars() ; | |
1203 | if ( doMove ) | |
1204 | { | |
1205 | wxPoint point(m_x, m_y); | |
1206 | wxMoveEvent event(point, m_windowId); | |
1207 | event.SetEventObject(this); | |
1208 | GetEventHandler()->ProcessEvent(event) ; | |
1209 | } | |
1210 | if ( doResize ) | |
1211 | { | |
1212 | MacRepositionScrollBars() ; | |
1213 | wxSize size(m_width, m_height); | |
1214 | wxSizeEvent event(size, m_windowId); | |
1215 | event.SetEventObject(this); | |
1216 | GetEventHandler()->ProcessEvent(event); | |
1217 | } | |
1218 | } | |
1542ea39 | 1219 | |
5f0b2f22 SC |
1220 | } |
1221 | ||
1222 | /* | |
1223 | * Invalidation Mechanism | |
1224 | * | |
1225 | * The update mechanism reflects exactely the windows mechanism | |
1226 | * the rect gets added to the window invalidate region, if the eraseBackground flag | |
1227 | * has been true for any part of the update rgn the background is erased in the entire region | |
1228 | * not just in the specified rect. | |
1229 | * | |
1542ea39 | 1230 | * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have |
5f0b2f22 SC |
1231 | * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event |
1232 | * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window | |
1233 | * will get the eraseBackground event first | |
1234 | */ | |
1542ea39 RD |
1235 | |
1236 | void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ) | |
5f0b2f22 | 1237 | { |
e40298d5 JS |
1238 | GrafPtr formerPort ; |
1239 | GetPort( &formerPort ) ; | |
1240 | SetPortWindowPort( (WindowRef)m_macWindow ) ; | |
1542ea39 | 1241 | |
e40298d5 | 1242 | m_macNeedsErasing |= eraseBackground ; |
1542ea39 | 1243 | |
e40298d5 JS |
1244 | // if we already know that we will have to erase, there's no need to track the rest |
1245 | if ( !m_macNeedsErasing) | |
5f0b2f22 | 1246 | { |
e40298d5 JS |
1247 | // we end only here if eraseBackground is false |
1248 | // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn | |
1249 | // we will have to erase anyway | |
1542ea39 RD |
1250 | |
1251 | RgnHandle updateRgn = NewRgn(); | |
e40298d5 JS |
1252 | RgnHandle diffRgn = NewRgn() ; |
1253 | if ( updateRgn && diffRgn ) | |
1254 | { | |
1255 | GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn ); | |
1256 | Point pt = {0,0} ; | |
1257 | LocalToGlobal( &pt ) ; | |
1258 | OffsetRgn( updateRgn , -pt.h , -pt.v ) ; | |
1259 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; | |
1260 | if ( !EmptyRgn( diffRgn ) ) | |
1261 | { | |
1262 | m_macNeedsErasing = true ; | |
1263 | } | |
1264 | } | |
1265 | if ( updateRgn ) | |
1266 | DisposeRgn( updateRgn ); | |
1267 | if ( diffRgn ) | |
1268 | DisposeRgn( diffRgn ); | |
1542ea39 | 1269 | |
e40298d5 | 1270 | if ( !m_macNeedsErasing ) |
5f0b2f22 | 1271 | { |
e40298d5 JS |
1272 | RgnHandle rectRgn = NewRgn() ; |
1273 | SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ; | |
1274 | UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
1275 | DisposeRgn( rectRgn ) ; | |
5f0b2f22 SC |
1276 | } |
1277 | } | |
e40298d5 JS |
1278 | InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ; |
1279 | // turn this on to debug the refreshing cycle | |
34dc8f91 | 1280 | #if wxMAC_DEBUG_REDRAW |
e40298d5 | 1281 | PaintRect( rect ) ; |
5f0b2f22 | 1282 | #endif |
e40298d5 | 1283 | SetPort( formerPort ) ; |
5f0b2f22 | 1284 | } |
a07c1212 | 1285 | |
6a7e6411 | 1286 | |
1542ea39 RD |
1287 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1288 | { | |
6a7e6411 RD |
1289 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, |
1290 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1291 | ||
45ff8005 | 1292 | #if TARGET_CARBON |
6a7e6411 RD |
1293 | // The empty region signifies that the shape should be removed from the |
1294 | // window. | |
1295 | if ( region.IsEmpty() ) | |
1296 | { | |
1297 | wxSize sz = GetClientSize(); | |
1298 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1299 | return SetShape(rgn); | |
1300 | } | |
1301 | ||
1302 | // Make a copy of the region | |
1303 | RgnHandle shapeRegion = NewRgn(); | |
1304 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1305 | ||
1306 | // Dispose of any shape region we may already have | |
1307 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1308 | if ( oldRgn ) | |
1309 | DisposeRgn(oldRgn); | |
1310 | ||
1311 | // Save the region so we can use it later | |
1312 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1313 | ||
1314 | // Tell the window manager that the window has changed shape | |
1315 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1316 | return TRUE; | |
45ff8005 RD |
1317 | #else |
1318 | return FALSE; | |
1319 | #endif | |
6a7e6411 RD |
1320 | } |
1321 | ||
6a7e6411 RD |
1322 | // --------------------------------------------------------------------------- |
1323 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1324 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1325 | // --------------------------------------------------------------------------- | |
1326 | ||
45ff8005 | 1327 | #if TARGET_CARBON |
1925be65 | 1328 | |
6a7e6411 RD |
1329 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1330 | { | |
1331 | GetWindowPortBounds(window, inRect); | |
1332 | Point pt = {inRect->left, inRect->top}; | |
1333 | SetPort((GrafPtr) GetWindowPort(window)); | |
1334 | LocalToGlobal(&pt); | |
1335 | inRect->top = pt.v; | |
1336 | inRect->left = pt.h; | |
1337 | inRect->bottom += pt.v; | |
1338 | inRect->right += pt.h; | |
1339 | } | |
1340 | ||
1341 | ||
1342 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1343 | { | |
1344 | /*------------------------------------------------------ | |
1345 | Define which options your custom window supports. | |
1346 | --------------------------------------------------------*/ | |
1347 | //just enable everything for our demo | |
1348 | *(OptionBits*)param=//kWindowCanGrow| | |
1349 | //kWindowCanZoom| | |
1350 | //kWindowCanCollapse| | |
1351 | //kWindowCanGetWindowRegion| | |
1352 | //kWindowHasTitleBar| | |
1353 | //kWindowSupportsDragHilite| | |
1354 | kWindowCanDrawInCurrentPort| | |
1355 | //kWindowCanMeasureTitle| | |
1356 | kWindowWantsDisposeAtProcessDeath| | |
1357 | kWindowSupportsSetGrowImageRegion| | |
1358 | kWindowDefSupportsColorGrafPort; | |
1359 | return 1; | |
1542ea39 | 1360 | } |
6a7e6411 RD |
1361 | |
1362 | // The content region is left as a rectangle matching the window size, this is | |
1363 | // so the origin in the paint event, and etc. still matches what the | |
1364 | // programmer expects. | |
1365 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1366 | { | |
1367 | SetEmptyRgn(rgn); | |
1368 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1369 | if (win) | |
1370 | { | |
1371 | wxRect r = win->GetRect(); | |
1372 | SetRectRgn(rgn, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom()); | |
1373 | } | |
1374 | } | |
1375 | ||
1376 | // The structure region is set to the shape given to the SetShape method. | |
1377 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1378 | { | |
1379 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1380 | ||
1381 | SetEmptyRgn(rgn); | |
1382 | if (cachedRegion) | |
1383 | { | |
1384 | Rect windowRect; | |
1385 | wxShapedMacWindowGetPos(window, &windowRect); //how big is the window | |
1386 | CopyRgn(cachedRegion, rgn); //make a copy of our cached region | |
1387 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1388 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1389 | } | |
1390 | } | |
1391 | ||
1392 | ||
1393 | ||
1394 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1395 | { | |
1396 | GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param; | |
1397 | ||
1398 | switch(rgnRec->regionCode) | |
1399 | { | |
1400 | case kWindowStructureRgn: | |
1401 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1402 | break; | |
1403 | case kWindowContentRgn: | |
1404 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1405 | break; | |
1406 | default: | |
1407 | SetEmptyRgn(rgnRec->winRgn); | |
1408 | } //switch | |
1409 | ||
1410 | return noErr; | |
1411 | } | |
1412 | ||
1413 | ||
1414 | static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param) | |
1415 | { | |
1416 | /*------------------------------------------------------ | |
1417 | Determine the region of the window which was hit | |
1418 | --------------------------------------------------------*/ | |
1419 | Point hitPoint; | |
1420 | static RgnHandle tempRgn=nil; | |
1421 | ||
1422 | if(!tempRgn) | |
1423 | tempRgn=NewRgn(); | |
1424 | ||
1425 | SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked | |
1426 | ||
1427 | //Mac OS 8.5 or later | |
1428 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1429 | if (PtInRgn(hitPoint, tempRgn)) //in window content region? | |
1430 | return wInContent; | |
1431 | ||
1432 | return wNoHit;//no significant area was hit. | |
1433 | } | |
1434 | ||
1435 | ||
1436 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1437 | { | |
1438 | switch(message) | |
1439 | { | |
1440 | case kWindowMsgHitTest: | |
1441 | return wxShapedMacWindowHitTest(window,param); | |
1442 | ||
1443 | case kWindowMsgGetFeatures: | |
1444 | return wxShapedMacWindowGetFeatures(window,param); | |
1445 | ||
1446 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1447 | case kWindowMsgGetRegion: | |
1448 | return wxShapedMacWindowGetRegion(window,param); | |
1449 | } | |
1450 | ||
1451 | return 0; | |
1452 | } | |
1925be65 | 1453 | |
45ff8005 | 1454 | #endif |
6a7e6411 | 1455 | // --------------------------------------------------------------------------- |
1925be65 | 1456 |