]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/mac/carbon/toplevel.cpp | |
3 | // Purpose: implements wxTopLevelWindow for Mac | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 24.09.01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2001-2004 Stefan Csomor | |
9 | // License: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/app.h" | |
29 | #include "wx/toplevel.h" | |
30 | #include "wx/frame.h" | |
31 | #include "wx/string.h" | |
32 | #include "wx/log.h" | |
33 | #include "wx/intl.h" | |
34 | #include "wx/settings.h" | |
35 | #include "wx/strconv.h" | |
36 | #include "wx/control.h" | |
37 | #endif //WX_PRECOMP | |
38 | ||
39 | #include "wx/mac/uma.h" | |
40 | #include "wx/mac/aga.h" | |
41 | #include "wx/app.h" | |
42 | #include "wx/tooltip.h" | |
43 | #include "wx/dnd.h" | |
44 | ||
45 | #if wxUSE_SYSTEM_OPTIONS | |
46 | #include "wx/sysopt.h" | |
47 | #endif | |
48 | ||
49 | #ifndef __DARWIN__ | |
50 | #include <ToolUtils.h> | |
51 | #endif | |
52 | ||
53 | // for targeting OSX | |
54 | #include "wx/mac/private.h" | |
55 | ||
56 | // ---------------------------------------------------------------------------- | |
57 | // constants | |
58 | // ---------------------------------------------------------------------------- | |
59 | ||
60 | // trace mask for activation tracing messages | |
61 | static const wxChar *TRACE_ACTIVATE = _T("activation"); | |
62 | ||
63 | // ---------------------------------------------------------------------------- | |
64 | // globals | |
65 | // ---------------------------------------------------------------------------- | |
66 | ||
67 | // list of all frames and modeless dialogs | |
68 | wxWindowList wxModelessWindows; | |
69 | ||
70 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); | |
71 | ||
72 | // ============================================================================ | |
73 | // wxTopLevelWindowMac implementation | |
74 | // ============================================================================ | |
75 | ||
76 | BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase) | |
77 | END_EVENT_TABLE() | |
78 | ||
79 | ||
80 | // --------------------------------------------------------------------------- | |
81 | // Carbon Events | |
82 | // --------------------------------------------------------------------------- | |
83 | ||
84 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; | |
85 | ||
86 | static const EventTypeSpec eventList[] = | |
87 | { | |
88 | // TODO: remove control related event like key and mouse (except for WindowLeave events) | |
89 | #if 1 | |
90 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , | |
91 | ||
92 | { kEventClassKeyboard, kEventRawKeyDown } , | |
93 | { kEventClassKeyboard, kEventRawKeyRepeat } , | |
94 | { kEventClassKeyboard, kEventRawKeyUp } , | |
95 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
96 | #endif | |
97 | ||
98 | { kEventClassWindow , kEventWindowShown } , | |
99 | { kEventClassWindow , kEventWindowActivated } , | |
100 | { kEventClassWindow , kEventWindowDeactivated } , | |
101 | { kEventClassWindow , kEventWindowBoundsChanging } , | |
102 | { kEventClassWindow , kEventWindowBoundsChanged } , | |
103 | { kEventClassWindow , kEventWindowClose } , | |
104 | ||
105 | // we have to catch these events on the toplevel window level, | |
106 | // as controls don't get the raw mouse events anymore | |
107 | ||
108 | { kEventClassMouse , kEventMouseDown } , | |
109 | { kEventClassMouse , kEventMouseUp } , | |
110 | { kEventClassMouse , kEventMouseWheelMoved } , | |
111 | { kEventClassMouse , kEventMouseMoved } , | |
112 | { kEventClassMouse , kEventMouseDragged } , | |
113 | } ; | |
114 | ||
115 | static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
116 | { | |
117 | OSStatus result = eventNotHandledErr ; | |
118 | wxWindow* focus ; | |
119 | UInt32 keyCode, modifiers ; | |
120 | Point point ; | |
121 | EventRef rawEvent ; | |
122 | unsigned char charCode ; | |
123 | ||
124 | GetEventParameter( event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL, sizeof(rawEvent), NULL, &rawEvent ) ; | |
125 | ||
126 | GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode ); | |
127 | GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
128 | GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers ); | |
129 | GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point ); | |
130 | ||
131 | focus = wxWindow::FindFocus() ; | |
132 | ||
133 | switch ( GetEventKind( event ) ) | |
134 | { | |
135 | case kEventTextInputUnicodeForKeyEvent : | |
136 | { | |
137 | // this is only called when no default handler has jumped in, e.g. a wxControl on a floater window does not | |
138 | // get its own kEventTextInputUnicodeForKeyEvent, so we reroute the event back to the control | |
139 | wxControl* control = wxDynamicCast( focus , wxControl ) ; | |
140 | if ( control ) | |
141 | { | |
142 | ControlRef macControl = (ControlRef) control->GetHandle() ; | |
143 | if ( macControl ) | |
144 | { | |
145 | ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; | |
146 | result = noErr ; | |
147 | } | |
148 | } | |
149 | ||
150 | #if 0 | |
151 | // this may lead to double events sent to a window in case all handlers have skipped the key down event | |
152 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
153 | UInt32 message = (keyCode << 8) + charCode; | |
154 | ||
155 | if ( (focus != NULL) && | |
156 | wxTheApp->MacSendKeyDownEvent( focus , message , modifiers , when , point.h , point.v ) ) | |
157 | { | |
158 | result = noErr ; | |
159 | } | |
160 | #endif | |
161 | } | |
162 | break ; | |
163 | ||
164 | default: | |
165 | break ; | |
166 | } | |
167 | ||
168 | return result ; | |
169 | } | |
170 | ||
171 | static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
172 | { | |
173 | OSStatus result = eventNotHandledErr ; | |
174 | // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl) | |
175 | // FindFocus does not return the actual focus window, but the enclosing window | |
176 | wxWindow* focus = wxWindow::DoFindFocus(); | |
177 | if ( focus == NULL ) | |
178 | focus = (wxTopLevelWindowMac*) data ; | |
179 | ||
180 | unsigned char charCode ; | |
181 | wxChar uniChar = 0 ; | |
182 | UInt32 keyCode ; | |
183 | UInt32 modifiers ; | |
184 | Point point ; | |
185 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
186 | ||
187 | #if wxUSE_UNICODE | |
188 | UInt32 dataSize = 0 ; | |
189 | if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr ) | |
190 | { | |
191 | UniChar buf[2] ; | |
192 | ||
193 | UniChar* charBuf = buf ; | |
194 | ||
195 | if ( dataSize > 4 ) | |
196 | charBuf = new UniChar[ dataSize / sizeof( UniChar) ] ; | |
197 | GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ; | |
198 | ||
199 | #if SIZEOF_WCHAR_T == 2 | |
200 | uniChar = charBuf[0] ; | |
201 | #else | |
202 | wxMBConvUTF16 converter ; | |
203 | converter.MB2WC( &uniChar , (const char*)charBuf , 1 ) ; | |
204 | #endif | |
205 | ||
206 | if ( dataSize > 4 ) | |
207 | delete[] charBuf ; | |
208 | } | |
209 | #endif | |
210 | ||
211 | GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode ); | |
212 | GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
213 | GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers ); | |
214 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point ); | |
215 | ||
216 | UInt32 message = (keyCode << 8) + charCode; | |
217 | switch ( GetEventKind( event ) ) | |
218 | { | |
219 | case kEventRawKeyRepeat : | |
220 | case kEventRawKeyDown : | |
221 | { | |
222 | WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; | |
223 | WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
224 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
225 | if ( /* focus && */ wxTheApp->MacSendKeyDownEvent( | |
226 | focus , message , modifiers , when , point.h , point.v , uniChar ) ) | |
227 | { | |
228 | result = noErr ; | |
229 | } | |
230 | wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; | |
231 | } | |
232 | break ; | |
233 | ||
234 | case kEventRawKeyUp : | |
235 | if ( /* focus && */ wxTheApp->MacSendKeyUpEvent( | |
236 | focus , message , modifiers , when , point.h , point.v , uniChar ) ) | |
237 | { | |
238 | result = noErr ; | |
239 | } | |
240 | break ; | |
241 | ||
242 | case kEventRawKeyModifiersChanged : | |
243 | { | |
244 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
245 | ||
246 | event.m_shiftDown = modifiers & shiftKey; | |
247 | event.m_controlDown = modifiers & controlKey; | |
248 | event.m_altDown = modifiers & optionKey; | |
249 | event.m_metaDown = modifiers & cmdKey; | |
250 | event.m_x = point.h; | |
251 | event.m_y = point.v; | |
252 | ||
253 | #if wxUSE_UNICODE | |
254 | event.m_uniChar = uniChar ; | |
255 | #endif | |
256 | ||
257 | event.SetTimestamp(when); | |
258 | event.SetEventObject(focus); | |
259 | ||
260 | if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & controlKey ) | |
261 | { | |
262 | event.m_keyCode = WXK_CONTROL ; | |
263 | event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
264 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
265 | } | |
266 | if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & shiftKey ) | |
267 | { | |
268 | event.m_keyCode = WXK_SHIFT ; | |
269 | event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
270 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
271 | } | |
272 | if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & optionKey ) | |
273 | { | |
274 | event.m_keyCode = WXK_ALT ; | |
275 | event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
276 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
277 | } | |
278 | if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & cmdKey ) | |
279 | { | |
280 | event.m_keyCode = WXK_COMMAND ; | |
281 | event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
282 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
283 | } | |
284 | ||
285 | wxApp::s_lastModifiers = modifiers ; | |
286 | } | |
287 | break ; | |
288 | ||
289 | default: | |
290 | break; | |
291 | } | |
292 | ||
293 | return result ; | |
294 | } | |
295 | ||
296 | // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr | |
297 | // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the | |
298 | // mouse down at all | |
299 | // | |
300 | // This handler can also be called from app level where data (ie target window) may be null or a non wx window | |
301 | ||
302 | wxWindow* g_MacLastWindow = NULL ; | |
303 | ||
304 | static EventMouseButton lastButton = 0 ; | |
305 | ||
306 | static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) | |
307 | { | |
308 | UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ; | |
309 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
310 | ||
311 | // this parameter are not given for all events | |
312 | EventMouseButton button = 0 ; | |
313 | UInt32 clickCount = 0 ; | |
314 | cEvent.GetParameter<EventMouseButton>( kEventParamMouseButton, typeMouseButton , &button ) ; | |
315 | cEvent.GetParameter<UInt32>( kEventParamClickCount, typeUInt32 , &clickCount ) ; | |
316 | ||
317 | wxevent.m_x = screenMouseLocation.h; | |
318 | wxevent.m_y = screenMouseLocation.v; | |
319 | wxevent.m_shiftDown = modifiers & shiftKey; | |
320 | wxevent.m_controlDown = modifiers & controlKey; | |
321 | wxevent.m_altDown = modifiers & optionKey; | |
322 | wxevent.m_metaDown = modifiers & cmdKey; | |
323 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
324 | ||
325 | // a control click is interpreted as a right click | |
326 | if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) ) | |
327 | button = kEventMouseButtonSecondary ; | |
328 | ||
329 | // otherwise we report double clicks by connecting a left click with a ctrl-left click | |
330 | if ( clickCount > 1 && button != lastButton ) | |
331 | clickCount = 1 ; | |
332 | ||
333 | // we must make sure that our synthetic 'right' button corresponds in | |
334 | // mouse down, moved and mouse up, and does not deliver a right down and left up | |
335 | ||
336 | if ( cEvent.GetKind() == kEventMouseDown ) | |
337 | lastButton = button ; | |
338 | ||
339 | if ( button == 0 ) | |
340 | lastButton = 0 ; | |
341 | else if ( lastButton ) | |
342 | button = lastButton ; | |
343 | ||
344 | // determine the correct down state, wx does not want a 'down' for a mouseUp event, | |
345 | // while mac delivers this button | |
346 | if ( button != 0 && cEvent.GetKind() != kEventMouseUp ) | |
347 | { | |
348 | switch ( button ) | |
349 | { | |
350 | case kEventMouseButtonPrimary : | |
351 | wxevent.m_leftDown = true ; | |
352 | break ; | |
353 | ||
354 | case kEventMouseButtonSecondary : | |
355 | wxevent.m_rightDown = true ; | |
356 | break ; | |
357 | ||
358 | case kEventMouseButtonTertiary : | |
359 | wxevent.m_middleDown = true ; | |
360 | break ; | |
361 | ||
362 | default: | |
363 | break ; | |
364 | } | |
365 | } | |
366 | ||
367 | // translate into wx types | |
368 | switch ( cEvent.GetKind() ) | |
369 | { | |
370 | case kEventMouseDown : | |
371 | switch ( button ) | |
372 | { | |
373 | case kEventMouseButtonPrimary : | |
374 | wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ; | |
375 | break ; | |
376 | ||
377 | case kEventMouseButtonSecondary : | |
378 | wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ; | |
379 | break ; | |
380 | ||
381 | case kEventMouseButtonTertiary : | |
382 | wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ; | |
383 | break ; | |
384 | ||
385 | default: | |
386 | break ; | |
387 | } | |
388 | break ; | |
389 | ||
390 | case kEventMouseUp : | |
391 | switch ( button ) | |
392 | { | |
393 | case kEventMouseButtonPrimary : | |
394 | wxevent.SetEventType( wxEVT_LEFT_UP ) ; | |
395 | break ; | |
396 | ||
397 | case kEventMouseButtonSecondary : | |
398 | wxevent.SetEventType( wxEVT_RIGHT_UP ) ; | |
399 | break ; | |
400 | ||
401 | case kEventMouseButtonTertiary : | |
402 | wxevent.SetEventType( wxEVT_MIDDLE_UP ) ; | |
403 | break ; | |
404 | ||
405 | default: | |
406 | break ; | |
407 | } | |
408 | break ; | |
409 | ||
410 | case kEventMouseWheelMoved : | |
411 | { | |
412 | wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ; | |
413 | ||
414 | // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ; | |
415 | SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeLongInteger) ; | |
416 | ||
417 | wxevent.m_wheelRotation = delta; | |
418 | wxevent.m_wheelDelta = 1; | |
419 | wxevent.m_linesPerAction = 1; | |
420 | } | |
421 | break ; | |
422 | ||
423 | default : | |
424 | wxevent.SetEventType( wxEVT_MOTION ) ; | |
425 | break ; | |
426 | } | |
427 | } | |
428 | ||
429 | ControlRef wxMacFindSubControl( wxTopLevelWindowMac* toplevelWindow, const Point& location , ControlRef superControl , ControlPartCode *outPart ) | |
430 | { | |
431 | if ( superControl ) | |
432 | { | |
433 | UInt16 childrenCount = 0 ; | |
434 | ControlHandle sibling ; | |
435 | Rect r ; | |
436 | OSStatus err = CountSubControls( superControl , &childrenCount ) ; | |
437 | if ( err == errControlIsNotEmbedder ) | |
438 | return NULL ; | |
439 | ||
440 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
441 | ||
442 | for ( UInt16 i = childrenCount ; i >=1 ; --i ) | |
443 | { | |
444 | err = GetIndexedSubControl( superControl , i , & sibling ) ; | |
445 | if ( err == errControlIsNotEmbedder ) | |
446 | return NULL ; | |
447 | ||
448 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
449 | if ( IsControlVisible( sibling ) ) | |
450 | { | |
451 | UMAGetControlBoundsInWindowCoords( sibling , &r ) ; | |
452 | if ( MacPtInRect( location , &r ) ) | |
453 | { | |
454 | ControlHandle child = wxMacFindSubControl( toplevelWindow , location , sibling , outPart ) ; | |
455 | if ( child ) | |
456 | { | |
457 | return child ; | |
458 | } | |
459 | else | |
460 | { | |
461 | Point testLocation = location ; | |
462 | ||
463 | if ( toplevelWindow && toplevelWindow->MacUsesCompositing() ) | |
464 | { | |
465 | testLocation.h -= r.left ; | |
466 | testLocation.v -= r.top ; | |
467 | } | |
468 | ||
469 | *outPart = TestControl( sibling , testLocation ) ; | |
470 | ||
471 | return sibling ; | |
472 | } | |
473 | } | |
474 | } | |
475 | } | |
476 | } | |
477 | ||
478 | return NULL ; | |
479 | } | |
480 | ||
481 | ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow , const Point& location , WindowRef window , ControlPartCode *outPart ) | |
482 | { | |
483 | #if TARGET_API_MAC_OSX | |
484 | if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow == 0 || toplevelWindow->MacUsesCompositing() ) ) | |
485 | return FindControlUnderMouse( location , window , outPart ) ; | |
486 | #endif | |
487 | ||
488 | ControlRef rootControl = NULL ; | |
489 | verify_noerr( GetRootControl( window , &rootControl ) ) ; | |
490 | ||
491 | return wxMacFindSubControl( toplevelWindow , location , rootControl , outPart ) ; | |
492 | } | |
493 | ||
494 | #define NEW_CAPTURE_HANDLING 1 | |
495 | ||
496 | pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
497 | { | |
498 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; | |
499 | ||
500 | OSStatus result = eventNotHandledErr ; | |
501 | ||
502 | wxMacCarbonEvent cEvent( event ) ; | |
503 | ||
504 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
505 | Point windowMouseLocation = screenMouseLocation ; | |
506 | ||
507 | WindowRef window ; | |
508 | short windowPart = ::FindWindow(screenMouseLocation, &window); | |
509 | ||
510 | wxWindow* currentMouseWindow = NULL ; | |
511 | ControlRef control = NULL ; | |
512 | ||
513 | #if NEW_CAPTURE_HANDLING | |
514 | if ( wxApp::s_captureWindow ) | |
515 | { | |
516 | window = (WindowRef) wxApp::s_captureWindow->MacGetTopLevelWindowRef() ; | |
517 | windowPart = inContent ; | |
518 | } | |
519 | #endif | |
520 | ||
521 | if ( window ) | |
522 | { | |
523 | QDGlobalToLocalPoint( UMAGetWindowPort(window ) , &windowMouseLocation ) ; | |
524 | ||
525 | if ( wxApp::s_captureWindow | |
526 | #if !NEW_CAPTURE_HANDLING | |
527 | && wxApp::s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent | |
528 | #endif | |
529 | ) | |
530 | { | |
531 | currentMouseWindow = wxApp::s_captureWindow ; | |
532 | } | |
533 | else if ( (IsWindowActive(window) && windowPart == inContent) ) | |
534 | { | |
535 | ControlPartCode part ; | |
536 | control = wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &part ) ; | |
537 | // if there is no control below the mouse position, send the event to the toplevel window itself | |
538 | if ( control == 0 ) | |
539 | { | |
540 | currentMouseWindow = (wxWindow*) data ; | |
541 | } | |
542 | else | |
543 | { | |
544 | currentMouseWindow = wxFindControlFromMacControl( control ) ; | |
545 | if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved ) | |
546 | { | |
547 | #if wxUSE_TOOLBAR | |
548 | // for wxToolBar to function we have to send certaint events to it | |
549 | // instead of its children (wxToolBarTools) | |
550 | ControlRef parent ; | |
551 | GetSuperControl(control, &parent ); | |
552 | wxWindow *wxParent = wxFindControlFromMacControl( parent ) ; | |
553 | if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) ) | |
554 | currentMouseWindow = wxParent ; | |
555 | #endif | |
556 | } | |
557 | } | |
558 | } | |
559 | } | |
560 | ||
561 | wxMouseEvent wxevent(wxEVT_LEFT_DOWN); | |
562 | SetupMouseEvent( wxevent , cEvent ) ; | |
563 | ||
564 | // handle all enter / leave events | |
565 | ||
566 | if ( currentMouseWindow != g_MacLastWindow ) | |
567 | { | |
568 | if ( g_MacLastWindow ) | |
569 | { | |
570 | wxMouseEvent eventleave(wxevent); | |
571 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
572 | g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
573 | eventleave.SetEventObject( g_MacLastWindow ) ; | |
574 | wxevent.SetId( g_MacLastWindow->GetId() ) ; | |
575 | ||
576 | #if wxUSE_TOOLTIPS | |
577 | wxToolTip::RelayEvent( g_MacLastWindow , eventleave); | |
578 | #endif | |
579 | ||
580 | g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave); | |
581 | } | |
582 | ||
583 | if ( currentMouseWindow ) | |
584 | { | |
585 | wxMouseEvent evententer(wxevent); | |
586 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
587 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
588 | evententer.SetEventObject( currentMouseWindow ) ; | |
589 | wxevent.SetId( currentMouseWindow->GetId() ) ; | |
590 | ||
591 | #if wxUSE_TOOLTIPS | |
592 | wxToolTip::RelayEvent( currentMouseWindow , evententer ); | |
593 | #endif | |
594 | ||
595 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); | |
596 | } | |
597 | ||
598 | g_MacLastWindow = currentMouseWindow ; | |
599 | } | |
600 | ||
601 | if ( windowPart == inMenuBar ) | |
602 | { | |
603 | // special case menu bar, as we are having a low-level runloop we must do it ourselves | |
604 | if ( cEvent.GetKind() == kEventMouseDown ) | |
605 | { | |
606 | ::MenuSelect( screenMouseLocation ) ; | |
607 | result = noErr ; | |
608 | } | |
609 | } | |
610 | else if ( currentMouseWindow ) | |
611 | { | |
612 | wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent(); | |
613 | ||
614 | currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ; | |
615 | ||
616 | wxevent.SetEventObject( currentMouseWindow ) ; | |
617 | wxevent.SetId( currentMouseWindow->GetId() ) ; | |
618 | ||
619 | // make tooltips current | |
620 | ||
621 | #if wxUSE_TOOLTIPS | |
622 | if ( wxevent.GetEventType() == wxEVT_MOTION | |
623 | || wxevent.GetEventType() == wxEVT_ENTER_WINDOW | |
624 | || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
625 | wxToolTip::RelayEvent( currentMouseWindow , wxevent ); | |
626 | #endif | |
627 | ||
628 | if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
629 | { | |
630 | if ((currentMouseWindowParent != NULL) && | |
631 | (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL)) | |
632 | currentMouseWindow = NULL; | |
633 | ||
634 | result = noErr; | |
635 | } | |
636 | else | |
637 | { | |
638 | // if the user code did _not_ handle the event, then perform the | |
639 | // default processing | |
640 | if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) | |
641 | { | |
642 | // ... that is set focus to this window | |
643 | if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow) | |
644 | currentMouseWindow->SetFocus(); | |
645 | } | |
646 | ||
647 | ControlPartCode dummyPart ; | |
648 | // if built-in find control is finding the wrong control (ie static box instead of overlaid | |
649 | // button, we cannot let the standard handler do its job, but must handle manually | |
650 | ||
651 | if ( ( cEvent.GetKind() == kEventMouseDown ) | |
652 | #ifdef __WXMAC_OSX__ | |
653 | && | |
654 | (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) != | |
655 | wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &dummyPart ) ) | |
656 | #endif | |
657 | ) | |
658 | { | |
659 | if ( currentMouseWindow->MacIsReallyEnabled() ) | |
660 | { | |
661 | EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ; | |
662 | Point clickLocation = windowMouseLocation ; | |
663 | ||
664 | if ( toplevelWindow->MacUsesCompositing() ) | |
665 | currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ; | |
666 | ||
667 | HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation , | |
668 | modifiers , (ControlActionUPP ) -1 ) ; | |
669 | ||
670 | if ((currentMouseWindowParent != NULL) && | |
671 | (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL)) | |
672 | { | |
673 | currentMouseWindow = NULL; | |
674 | } | |
675 | } | |
676 | ||
677 | result = noErr ; | |
678 | } | |
679 | } | |
680 | ||
681 | if ( cEvent.GetKind() == kEventMouseUp && wxApp::s_captureWindow ) | |
682 | { | |
683 | wxApp::s_captureWindow = NULL ; | |
684 | // update cursor ? | |
685 | } | |
686 | ||
687 | // update cursor | |
688 | ||
689 | wxWindow* cursorTarget = currentMouseWindow ; | |
690 | wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ; | |
691 | ||
692 | while ( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) | |
693 | { | |
694 | cursorTarget = cursorTarget->GetParent() ; | |
695 | if ( cursorTarget ) | |
696 | cursorPoint += cursorTarget->GetPosition(); | |
697 | } | |
698 | ||
699 | } // else if ( currentMouseWindow ) | |
700 | else | |
701 | { | |
702 | // don't mess with controls we don't know about | |
703 | // for some reason returning eventNotHandledErr does not lead to the correct behaviour | |
704 | // so we try sending them the correct control directly | |
705 | if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control ) | |
706 | { | |
707 | EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ; | |
708 | Point clickLocation = windowMouseLocation ; | |
709 | if ( toplevelWindow->MacUsesCompositing() ) | |
710 | { | |
711 | #ifdef __WXMAC_OSX__ | |
712 | HIPoint hiPoint ; | |
713 | hiPoint.x = clickLocation.h ; | |
714 | hiPoint.y = clickLocation.v ; | |
715 | HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ; | |
716 | clickLocation.h = (int)hiPoint.x ; | |
717 | clickLocation.v = (int)hiPoint.y ; | |
718 | #endif | |
719 | } | |
720 | ||
721 | HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ; | |
722 | result = noErr ; | |
723 | } | |
724 | } | |
725 | ||
726 | return result ; | |
727 | } | |
728 | ||
729 | static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
730 | { | |
731 | OSStatus result = eventNotHandledErr ; | |
732 | ||
733 | wxMacCarbonEvent cEvent( event ) ; | |
734 | ||
735 | // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ; | |
736 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; | |
737 | ||
738 | switch ( GetEventKind( event ) ) | |
739 | { | |
740 | case kEventWindowActivated : | |
741 | { | |
742 | toplevelWindow->MacActivate( cEvent.GetTicks() , true) ; | |
743 | wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId()); | |
744 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
745 | wxevent.SetEventObject(toplevelWindow); | |
746 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
747 | // we still sending an eventNotHandledErr in order to allow for default processing | |
748 | } | |
749 | break ; | |
750 | ||
751 | case kEventWindowDeactivated : | |
752 | { | |
753 | toplevelWindow->MacActivate(cEvent.GetTicks() , false) ; | |
754 | wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId()); | |
755 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
756 | wxevent.SetEventObject(toplevelWindow); | |
757 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
758 | // we still sending an eventNotHandledErr in order to allow for default processing | |
759 | } | |
760 | break ; | |
761 | ||
762 | case kEventWindowShown : | |
763 | toplevelWindow->Refresh() ; | |
764 | result = noErr ; | |
765 | break ; | |
766 | ||
767 | case kEventWindowClose : | |
768 | toplevelWindow->Close() ; | |
769 | result = noErr ; | |
770 | break ; | |
771 | ||
772 | case kEventWindowBoundsChanged : | |
773 | { | |
774 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes, typeUInt32) ; | |
775 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
776 | wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; | |
777 | if ( attributes & kWindowBoundsChangeSizeChanged ) | |
778 | { | |
779 | // according to the other ports we handle this within the OS level | |
780 | // resize event, not within a wxSizeEvent | |
781 | wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ; | |
782 | if ( frame ) | |
783 | { | |
784 | #if wxUSE_STATUSBAR | |
785 | frame->PositionStatusBar(); | |
786 | #endif | |
787 | #if wxUSE_TOOLBAR | |
788 | frame->PositionToolBar(); | |
789 | #endif | |
790 | } | |
791 | ||
792 | wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ; | |
793 | event.SetEventObject( toplevelWindow ) ; | |
794 | ||
795 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; | |
796 | toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
797 | } | |
798 | ||
799 | if ( attributes & kWindowBoundsChangeOriginChanged ) | |
800 | { | |
801 | wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ; | |
802 | event.SetEventObject( toplevelWindow ) ; | |
803 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; | |
804 | } | |
805 | ||
806 | result = noErr ; | |
807 | } | |
808 | break ; | |
809 | ||
810 | case kEventWindowBoundsChanging : | |
811 | { | |
812 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
813 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
814 | ||
815 | if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) ) | |
816 | { | |
817 | // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates | |
818 | int left , top , right , bottom ; | |
819 | toplevelWindow->MacGetContentAreaInset( left , top , right , bottom ) ; | |
820 | ||
821 | wxRect r( | |
822 | newRect.left - left, | |
823 | newRect.top - top, | |
824 | newRect.right - newRect.left + left + right, | |
825 | newRect.bottom - newRect.top + top + bottom ) ; | |
826 | ||
827 | // this is a EVT_SIZING not a EVT_SIZE type ! | |
828 | wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ; | |
829 | wxevent.SetEventObject( toplevelWindow ) ; | |
830 | wxRect adjustR = r ; | |
831 | if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
832 | adjustR = wxevent.GetRect() ; | |
833 | ||
834 | if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() ) | |
835 | adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ; | |
836 | if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() ) | |
837 | adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ; | |
838 | if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() ) | |
839 | adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ; | |
840 | if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() ) | |
841 | adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ; | |
842 | const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ; | |
843 | if ( !EqualRect( &newRect , &adjustedRect ) ) | |
844 | cEvent.SetParameter<Rect>( kEventParamCurrentBounds , &adjustedRect ) ; | |
845 | toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
846 | } | |
847 | ||
848 | result = noErr ; | |
849 | } | |
850 | break ; | |
851 | ||
852 | default : | |
853 | break ; | |
854 | } | |
855 | ||
856 | return result ; | |
857 | } | |
858 | ||
859 | pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
860 | { | |
861 | OSStatus result = eventNotHandledErr ; | |
862 | ||
863 | switch ( GetEventClass( event ) ) | |
864 | { | |
865 | case kEventClassKeyboard : | |
866 | result = KeyboardEventHandler( handler, event , data ) ; | |
867 | break ; | |
868 | ||
869 | case kEventClassTextInput : | |
870 | result = TextInputEventHandler( handler, event , data ) ; | |
871 | break ; | |
872 | ||
873 | case kEventClassWindow : | |
874 | result = wxMacTopLevelWindowEventHandler( handler, event , data ) ; | |
875 | break ; | |
876 | ||
877 | case kEventClassMouse : | |
878 | result = wxMacTopLevelMouseEventHandler( handler, event , data ) ; | |
879 | break ; | |
880 | ||
881 | default : | |
882 | break ; | |
883 | } | |
884 | ||
885 | return result ; | |
886 | } | |
887 | ||
888 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler ) | |
889 | ||
890 | // --------------------------------------------------------------------------- | |
891 | // wxWindowMac utility functions | |
892 | // --------------------------------------------------------------------------- | |
893 | ||
894 | // Find an item given the Macintosh Window Reference | |
895 | ||
896 | WX_DECLARE_HASH_MAP(WindowRef, wxTopLevelWindowMac*, wxPointerHash, wxPointerEqual, MacWindowMap); | |
897 | ||
898 | static MacWindowMap wxWinMacWindowList; | |
899 | ||
900 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) | |
901 | { | |
902 | MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef); | |
903 | ||
904 | return (node == wxWinMacWindowList.end()) ? NULL : node->second; | |
905 | } | |
906 | ||
907 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; | |
908 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) | |
909 | { | |
910 | // adding NULL WindowRef is (first) surely a result of an error and | |
911 | // nothing else :-) | |
912 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
913 | ||
914 | wxWinMacWindowList[inWindowRef] = win; | |
915 | } | |
916 | ||
917 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; | |
918 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) | |
919 | { | |
920 | MacWindowMap::iterator it; | |
921 | for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it ) | |
922 | { | |
923 | if ( it->second == win ) | |
924 | { | |
925 | wxWinMacWindowList.erase(it); | |
926 | break; | |
927 | } | |
928 | } | |
929 | } | |
930 | ||
931 | // ---------------------------------------------------------------------------- | |
932 | // wxTopLevelWindowMac creation | |
933 | // ---------------------------------------------------------------------------- | |
934 | ||
935 | wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; | |
936 | ||
937 | typedef struct | |
938 | { | |
939 | wxPoint m_position ; | |
940 | wxSize m_size ; | |
941 | bool m_wasResizable ; | |
942 | } | |
943 | FullScreenData ; | |
944 | ||
945 | void wxTopLevelWindowMac::Init() | |
946 | { | |
947 | m_iconized = | |
948 | m_maximizeOnShow = false; | |
949 | m_macWindow = NULL ; | |
950 | ||
951 | #if TARGET_API_MAC_OSX | |
952 | m_macUsesCompositing = ( UMAGetSystemVersion() >= 0x1030 ); | |
953 | #else | |
954 | m_macUsesCompositing = false; | |
955 | #endif | |
956 | ||
957 | m_macEventHandler = NULL ; | |
958 | m_macFullScreenData = NULL ; | |
959 | } | |
960 | ||
961 | class wxMacDeferredWindowDeleter : public wxObject | |
962 | { | |
963 | public : | |
964 | wxMacDeferredWindowDeleter( WindowRef windowRef ) | |
965 | { | |
966 | m_macWindow = windowRef ; | |
967 | } | |
968 | ||
969 | virtual ~wxMacDeferredWindowDeleter() | |
970 | { | |
971 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
972 | } | |
973 | ||
974 | protected : | |
975 | WindowRef m_macWindow ; | |
976 | } ; | |
977 | ||
978 | bool wxTopLevelWindowMac::Create(wxWindow *parent, | |
979 | wxWindowID id, | |
980 | const wxString& title, | |
981 | const wxPoint& pos, | |
982 | const wxSize& size, | |
983 | long style, | |
984 | const wxString& name) | |
985 | { | |
986 | // init our fields | |
987 | Init(); | |
988 | ||
989 | m_windowStyle = style; | |
990 | ||
991 | SetName( name ); | |
992 | ||
993 | m_windowId = id == -1 ? NewControlId() : id; | |
994 | wxWindow::SetLabel( title ) ; | |
995 | ||
996 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; | |
997 | ||
998 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); | |
999 | ||
1000 | if (GetExtraStyle() & wxFRAME_EX_METAL) | |
1001 | MacSetMetalAppearance(true); | |
1002 | ||
1003 | wxTopLevelWindows.Append(this); | |
1004 | ||
1005 | if ( parent ) | |
1006 | parent->AddChild(this); | |
1007 | ||
1008 | return true; | |
1009 | } | |
1010 | ||
1011 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
1012 | { | |
1013 | if ( m_macWindow ) | |
1014 | { | |
1015 | #if wxUSE_TOOLTIPS | |
1016 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
1017 | #endif | |
1018 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; | |
1019 | } | |
1020 | ||
1021 | if ( m_macEventHandler ) | |
1022 | { | |
1023 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
1024 | m_macEventHandler = NULL ; | |
1025 | } | |
1026 | ||
1027 | wxRemoveMacWindowAssociation( this ) ; | |
1028 | ||
1029 | if ( wxModelessWindows.Find(this) ) | |
1030 | wxModelessWindows.DeleteObject(this); | |
1031 | ||
1032 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
1033 | delete data ; | |
1034 | m_macFullScreenData = NULL ; | |
1035 | } | |
1036 | ||
1037 | ||
1038 | // ---------------------------------------------------------------------------- | |
1039 | // wxTopLevelWindowMac maximize/minimize | |
1040 | // ---------------------------------------------------------------------------- | |
1041 | ||
1042 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
1043 | { | |
1044 | // TODO: check if this is still necessary | |
1045 | #if 0 | |
1046 | wxMacPortStateHelper help( (GrafPtr)GetWindowPort( (WindowRef)m_macWindow) ) ; | |
1047 | wxMacWindowClipper clip( this ); | |
1048 | #endif | |
1049 | ||
1050 | if ( !IsWindowInStandardState( (WindowRef)m_macWindow, NULL, NULL ) ) | |
1051 | { | |
1052 | Rect rect; | |
1053 | ||
1054 | GetWindowBounds((WindowRef)m_macWindow, kWindowGlobalPortRgn, &rect); | |
1055 | SetWindowIdealUserState((WindowRef)m_macWindow, &rect); | |
1056 | SetWindowUserState((WindowRef)m_macWindow, &rect); | |
1057 | } | |
1058 | ||
1059 | ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ; | |
1060 | } | |
1061 | ||
1062 | bool wxTopLevelWindowMac::IsMaximized() const | |
1063 | { | |
1064 | return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ; | |
1065 | } | |
1066 | ||
1067 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
1068 | { | |
1069 | if ( IsWindowCollapsable( (WindowRef)m_macWindow) ) | |
1070 | CollapseWindow( (WindowRef)m_macWindow , iconize ) ; | |
1071 | } | |
1072 | ||
1073 | bool wxTopLevelWindowMac::IsIconized() const | |
1074 | { | |
1075 | return IsWindowCollapsed((WindowRef)m_macWindow ) ; | |
1076 | } | |
1077 | ||
1078 | void wxTopLevelWindowMac::Restore() | |
1079 | { | |
1080 | if ( IsMaximized() ) | |
1081 | Maximize(false); | |
1082 | else if ( IsIconized() ) | |
1083 | Iconize(false); | |
1084 | } | |
1085 | ||
1086 | // ---------------------------------------------------------------------------- | |
1087 | // wxTopLevelWindowMac misc | |
1088 | // ---------------------------------------------------------------------------- | |
1089 | ||
1090 | wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const | |
1091 | { | |
1092 | return wxPoint(0, 0) ; | |
1093 | } | |
1094 | ||
1095 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) | |
1096 | { | |
1097 | // this sets m_icon | |
1098 | wxTopLevelWindowBase::SetIcon(icon); | |
1099 | } | |
1100 | ||
1101 | void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) | |
1102 | { | |
1103 | wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ; | |
1104 | ||
1105 | if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme ) | |
1106 | { | |
1107 | SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ; | |
1108 | } | |
1109 | } | |
1110 | ||
1111 | void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler() | |
1112 | { | |
1113 | if ( m_macEventHandler != NULL ) | |
1114 | { | |
1115 | verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; | |
1116 | } | |
1117 | ||
1118 | InstallWindowEventHandler( | |
1119 | MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(), | |
1120 | GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler ); | |
1121 | } | |
1122 | ||
1123 | void wxTopLevelWindowMac::MacCreateRealWindow( | |
1124 | const wxString& title, | |
1125 | const wxPoint& pos, | |
1126 | const wxSize& size, | |
1127 | long style, | |
1128 | const wxString& name ) | |
1129 | { | |
1130 | OSStatus err = noErr ; | |
1131 | SetName(name); | |
1132 | m_windowStyle = style; | |
1133 | m_isShown = false; | |
1134 | ||
1135 | // create frame. | |
1136 | int x = (int)pos.x; | |
1137 | int y = (int)pos.y; | |
1138 | ||
1139 | Rect theBoundsRect; | |
1140 | wxRect display = wxGetClientDisplayRect() ; | |
1141 | ||
1142 | if ( x == wxDefaultPosition.x ) | |
1143 | x = display.x ; | |
1144 | ||
1145 | if ( y == wxDefaultPosition.y ) | |
1146 | y = display.y ; | |
1147 | ||
1148 | int w = WidthDefault(size.x); | |
1149 | int h = HeightDefault(size.y); | |
1150 | ||
1151 | ::SetRect(&theBoundsRect, x, y , x + w, y + h); | |
1152 | ||
1153 | // translate the window attributes in the appropriate window class and attributes | |
1154 | WindowClass wclass = 0; | |
1155 | WindowAttributes attr = kWindowNoAttributes ; | |
1156 | WindowGroupRef group = NULL ; | |
1157 | ||
1158 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) | |
1159 | { | |
1160 | if ( | |
1161 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || | |
1162 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
1163 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
1164 | ) | |
1165 | { | |
1166 | wclass = kFloatingWindowClass ; | |
1167 | ||
1168 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
1169 | attr |= kWindowSideTitlebarAttribute ; | |
1170 | } | |
1171 | else | |
1172 | { | |
1173 | wclass = kPlainWindowClass ; | |
1174 | } | |
1175 | } | |
1176 | else if ( HasFlag( wxCAPTION ) ) | |
1177 | { | |
1178 | wclass = kDocumentWindowClass ; | |
1179 | attr |= kWindowInWindowMenuAttribute ; | |
1180 | } | |
1181 | #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 ) | |
1182 | else if ( HasFlag( wxFRAME_DRAWER ) ) | |
1183 | { | |
1184 | wclass = kDrawerWindowClass; | |
1185 | // we must force compositing on a drawer | |
1186 | m_macUsesCompositing = true ; | |
1187 | } | |
1188 | #endif //10.2 and up | |
1189 | else | |
1190 | { | |
1191 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || | |
1192 | HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) ) | |
1193 | { | |
1194 | wclass = kDocumentWindowClass ; | |
1195 | } | |
1196 | else | |
1197 | { | |
1198 | wclass = kPlainWindowClass ; | |
1199 | } | |
1200 | } | |
1201 | ||
1202 | if ( wclass != kPlainWindowClass ) | |
1203 | { | |
1204 | if ( HasFlag( wxMINIMIZE_BOX ) ) | |
1205 | attr |= kWindowCollapseBoxAttribute ; | |
1206 | ||
1207 | if ( HasFlag( wxMAXIMIZE_BOX ) ) | |
1208 | attr |= kWindowFullZoomAttribute ; | |
1209 | ||
1210 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
1211 | attr |= kWindowResizableAttribute ; | |
1212 | ||
1213 | if ( HasFlag( wxCLOSE_BOX) ) | |
1214 | attr |= kWindowCloseBoxAttribute ; | |
1215 | } | |
1216 | ||
1217 | // turn on live resizing (OS X only) | |
1218 | if (UMAGetSystemVersion() >= 0x1000) | |
1219 | attr |= kWindowLiveResizeAttribute; | |
1220 | ||
1221 | if ( HasFlag(wxSTAY_ON_TOP) ) | |
1222 | group = GetWindowGroupOfClass(kUtilityWindowClass) ; | |
1223 | ||
1224 | #if TARGET_API_MAC_OSX | |
1225 | if ( m_macUsesCompositing ) | |
1226 | attr |= kWindowCompositingAttribute; | |
1227 | #endif | |
1228 | ||
1229 | if ( HasFlag(wxFRAME_SHAPED) ) | |
1230 | { | |
1231 | WindowDefSpec customWindowDefSpec; | |
1232 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
1233 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
1234 | ||
1235 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, | |
1236 | attr, &theBoundsRect, | |
1237 | (WindowRef*) &m_macWindow); | |
1238 | } | |
1239 | else | |
1240 | { | |
1241 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; | |
1242 | } | |
1243 | ||
1244 | if ( err == noErr && m_macWindow != NULL && group != NULL ) | |
1245 | SetWindowGroup( (WindowRef) m_macWindow , group ) ; | |
1246 | ||
1247 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); | |
1248 | ||
1249 | // the create commands are only for content rect, | |
1250 | // so we have to set the size again as structure bounds | |
1251 | SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; | |
1252 | ||
1253 | wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ; | |
1254 | UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ; | |
1255 | m_peer = new wxMacControl(this , true /*isRootControl*/) ; | |
1256 | ||
1257 | #if TARGET_API_MAC_OSX | |
1258 | if ( m_macUsesCompositing ) | |
1259 | { | |
1260 | // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of | |
1261 | // the content view, so we have to retrieve it explicitly | |
1262 | HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , | |
1263 | m_peer->GetControlRefAddr() ) ; | |
1264 | if ( !m_peer->Ok() ) | |
1265 | { | |
1266 | // compatibility mode fallback | |
1267 | GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ; | |
1268 | } | |
1269 | } | |
1270 | #endif | |
1271 | { | |
1272 | ::CreateRootControl( (WindowRef)m_macWindow , m_peer->GetControlRefAddr() ) ; | |
1273 | } | |
1274 | ||
1275 | // the root control level handler | |
1276 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; | |
1277 | ||
1278 | #if TARGET_API_MAC_OSX | |
1279 | if ( m_macUsesCompositing && m_macWindow != NULL ) | |
1280 | { | |
1281 | if ( GetExtraStyle() & wxFRAME_EX_METAL ) | |
1282 | MacSetMetalAppearance( true ) ; | |
1283 | } | |
1284 | #endif | |
1285 | ||
1286 | // the frame window event handler | |
1287 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; | |
1288 | MacInstallTopLevelWindowEventHandler() ; | |
1289 | ||
1290 | DoSetWindowVariant( m_windowVariant ) ; | |
1291 | ||
1292 | m_macFocus = NULL ; | |
1293 | ||
1294 | if ( HasFlag(wxFRAME_SHAPED) ) | |
1295 | { | |
1296 | // default shape matches the window size | |
1297 | wxRegion rgn( 0, 0, w, h ); | |
1298 | SetShape( rgn ); | |
1299 | } | |
1300 | ||
1301 | wxWindowCreateEvent event(this); | |
1302 | GetEventHandler()->ProcessEvent(event); | |
1303 | } | |
1304 | ||
1305 | void wxTopLevelWindowMac::ClearBackground() | |
1306 | { | |
1307 | wxWindow::ClearBackground() ; | |
1308 | } | |
1309 | ||
1310 | // Raise the window to the top of the Z order | |
1311 | void wxTopLevelWindowMac::Raise() | |
1312 | { | |
1313 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
1314 | } | |
1315 | ||
1316 | // Lower the window to the bottom of the Z order | |
1317 | void wxTopLevelWindowMac::Lower() | |
1318 | { | |
1319 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; | |
1320 | } | |
1321 | ||
1322 | void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) | |
1323 | { | |
1324 | if (s_macDeactivateWindow) | |
1325 | { | |
1326 | wxLogTrace(TRACE_ACTIVATE, | |
1327 | wxT("Doing delayed deactivation of %p"), | |
1328 | s_macDeactivateWindow); | |
1329 | ||
1330 | s_macDeactivateWindow->MacActivate(timestamp, false); | |
1331 | } | |
1332 | } | |
1333 | ||
1334 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) | |
1335 | { | |
1336 | wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this); | |
1337 | ||
1338 | if (s_macDeactivateWindow == this) | |
1339 | s_macDeactivateWindow = NULL; | |
1340 | ||
1341 | MacDelayedDeactivation(timestamp); | |
1342 | MacPropagateHiliteChanged() ; | |
1343 | } | |
1344 | ||
1345 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
1346 | { | |
1347 | wxWindow::SetLabel( title ) ; | |
1348 | UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ; | |
1349 | } | |
1350 | ||
1351 | wxString wxTopLevelWindowMac::GetTitle() const | |
1352 | { | |
1353 | return wxWindow::GetLabel(); | |
1354 | } | |
1355 | ||
1356 | bool wxTopLevelWindowMac::Show(bool show) | |
1357 | { | |
1358 | if ( !wxTopLevelWindowBase::Show(show) ) | |
1359 | return false; | |
1360 | ||
1361 | bool plainTransition = false; | |
1362 | ||
1363 | #if wxUSE_SYSTEM_OPTIONS | |
1364 | // code contributed by Ryan Wilcox December 18, 2003 | |
1365 | plainTransition = UMAGetSystemVersion() >= 0x1000 ; | |
1366 | if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) | |
1367 | plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ; | |
1368 | #endif | |
1369 | ||
1370 | if (show) | |
1371 | { | |
1372 | if ( plainTransition ) | |
1373 | ::ShowWindow( (WindowRef)m_macWindow ); | |
1374 | else | |
1375 | ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL ); | |
1376 | ||
1377 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
1378 | ||
1379 | // because apps expect a size event to occur at this moment | |
1380 | wxSizeEvent event(GetSize() , m_windowId); | |
1381 | event.SetEventObject(this); | |
1382 | GetEventHandler()->ProcessEvent(event); | |
1383 | } | |
1384 | else | |
1385 | { | |
1386 | if ( plainTransition ) | |
1387 | ::HideWindow( (WindowRef)m_macWindow ); | |
1388 | else | |
1389 | ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL ); | |
1390 | } | |
1391 | ||
1392 | MacPropagateVisibilityChanged() ; | |
1393 | ||
1394 | return true ; | |
1395 | } | |
1396 | ||
1397 | bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) | |
1398 | { | |
1399 | if ( show ) | |
1400 | { | |
1401 | FullScreenData *data = (FullScreenData *)m_macFullScreenData ; | |
1402 | delete data ; | |
1403 | data = new FullScreenData() ; | |
1404 | ||
1405 | m_macFullScreenData = data ; | |
1406 | data->m_position = GetPosition() ; | |
1407 | data->m_size = GetSize() ; | |
1408 | data->m_wasResizable = MacGetWindowAttributes() & kWindowResizableAttribute ; | |
1409 | ||
1410 | if ( style & wxFULLSCREEN_NOMENUBAR ) | |
1411 | HideMenuBar() ; | |
1412 | ||
1413 | wxRect client = wxGetClientDisplayRect() ; | |
1414 | ||
1415 | int left , top , right , bottom ; | |
1416 | int x, y, w, h ; | |
1417 | ||
1418 | x = client.x ; | |
1419 | y = client.y ; | |
1420 | w = client.width ; | |
1421 | h = client.height ; | |
1422 | ||
1423 | MacGetContentAreaInset( left , top , right , bottom ) ; | |
1424 | ||
1425 | if ( style & wxFULLSCREEN_NOCAPTION ) | |
1426 | { | |
1427 | y -= top ; | |
1428 | h += top ; | |
1429 | } | |
1430 | ||
1431 | if ( style & wxFULLSCREEN_NOBORDER ) | |
1432 | { | |
1433 | x -= left ; | |
1434 | w += left + right ; | |
1435 | h += bottom ; | |
1436 | } | |
1437 | ||
1438 | if ( style & wxFULLSCREEN_NOTOOLBAR ) | |
1439 | { | |
1440 | // TODO | |
1441 | } | |
1442 | ||
1443 | if ( style & wxFULLSCREEN_NOSTATUSBAR ) | |
1444 | { | |
1445 | // TODO | |
1446 | } | |
1447 | ||
1448 | SetSize( x , y , w, h ) ; | |
1449 | if( data->m_wasResizable ) | |
1450 | MacChangeWindowAttributes( kWindowNoAttributes , kWindowResizableAttribute ) ; | |
1451 | } | |
1452 | else | |
1453 | { | |
1454 | ShowMenuBar() ; | |
1455 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
1456 | if( data->m_wasResizable ) | |
1457 | MacChangeWindowAttributes( kWindowResizableAttribute , kWindowNoAttributes ) ; | |
1458 | SetPosition( data->m_position ) ; | |
1459 | SetSize( data->m_size ) ; | |
1460 | ||
1461 | delete data ; | |
1462 | m_macFullScreenData = NULL ; | |
1463 | } | |
1464 | ||
1465 | return false; | |
1466 | } | |
1467 | ||
1468 | bool wxTopLevelWindowMac::IsFullScreen() const | |
1469 | { | |
1470 | return m_macFullScreenData != NULL ; | |
1471 | } | |
1472 | ||
1473 | void wxTopLevelWindowMac::SetExtraStyle(long exStyle) | |
1474 | { | |
1475 | if ( GetExtraStyle() == exStyle ) | |
1476 | return ; | |
1477 | ||
1478 | wxTopLevelWindowBase::SetExtraStyle( exStyle ) ; | |
1479 | ||
1480 | #if TARGET_API_MAC_OSX | |
1481 | if ( m_macUsesCompositing && m_macWindow != NULL ) | |
1482 | { | |
1483 | bool metal = GetExtraStyle() & wxFRAME_EX_METAL ; | |
1484 | if ( MacGetMetalAppearance() != metal ) | |
1485 | MacSetMetalAppearance( metal ) ; | |
1486 | } | |
1487 | #endif | |
1488 | } | |
1489 | ||
1490 | // we are still using coordinates of the content view | |
1491 | // TODO: switch to structure bounds | |
1492 | // | |
1493 | void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) | |
1494 | { | |
1495 | Rect content, structure ; | |
1496 | ||
1497 | GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ; | |
1498 | GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ; | |
1499 | ||
1500 | left = content.left - structure.left ; | |
1501 | top = content.top - structure.top ; | |
1502 | right = structure.right - content.right ; | |
1503 | bottom = structure.bottom - content.bottom ; | |
1504 | } | |
1505 | ||
1506 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
1507 | { | |
1508 | m_cachedClippedRectValid = false ; | |
1509 | Rect bounds = { y , x , y + height , x + width } ; | |
1510 | verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1511 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
1512 | } | |
1513 | ||
1514 | void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const | |
1515 | { | |
1516 | Rect bounds ; | |
1517 | ||
1518 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1519 | ||
1520 | if (x) | |
1521 | *x = bounds.left ; | |
1522 | if (y) | |
1523 | *y = bounds.top ; | |
1524 | } | |
1525 | ||
1526 | void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const | |
1527 | { | |
1528 | Rect bounds ; | |
1529 | ||
1530 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1531 | ||
1532 | if (width) | |
1533 | *width = bounds.right - bounds.left ; | |
1534 | if (height) | |
1535 | *height = bounds.bottom - bounds.top ; | |
1536 | } | |
1537 | ||
1538 | void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const | |
1539 | { | |
1540 | Rect bounds ; | |
1541 | ||
1542 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ; | |
1543 | ||
1544 | if (width) | |
1545 | *width = bounds.right - bounds.left ; | |
1546 | if (height) | |
1547 | *height = bounds.bottom - bounds.top ; | |
1548 | } | |
1549 | ||
1550 | void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) | |
1551 | { | |
1552 | #if TARGET_API_MAC_OSX | |
1553 | wxASSERT_MSG( m_macUsesCompositing , | |
1554 | wxT("Cannot set metal appearance on a non-compositing window") ) ; | |
1555 | ||
1556 | MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , | |
1557 | set ? kWindowNoAttributes : kWindowMetalAttribute ) ; | |
1558 | #endif | |
1559 | } | |
1560 | ||
1561 | bool wxTopLevelWindowMac::MacGetMetalAppearance() const | |
1562 | { | |
1563 | #if TARGET_API_MAC_OSX | |
1564 | return MacGetWindowAttributes() & kWindowMetalAttribute ; | |
1565 | #else | |
1566 | return false ; | |
1567 | #endif | |
1568 | } | |
1569 | ||
1570 | void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) | |
1571 | { | |
1572 | ChangeWindowAttributes( (WindowRef)m_macWindow, attributesToSet, attributesToClear ) ; | |
1573 | } | |
1574 | ||
1575 | wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const | |
1576 | { | |
1577 | UInt32 attr = 0 ; | |
1578 | GetWindowAttributes( (WindowRef) m_macWindow, &attr ) ; | |
1579 | ||
1580 | return attr ; | |
1581 | } | |
1582 | ||
1583 | void wxTopLevelWindowMac::MacPerformUpdates() | |
1584 | { | |
1585 | #if TARGET_API_MAC_OSX | |
1586 | if ( m_macUsesCompositing ) | |
1587 | { | |
1588 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 | |
1589 | // for composited windows this also triggers a redraw of all | |
1590 | // invalid views in the window | |
1591 | if ( UMAGetSystemVersion() >= 0x1030 ) | |
1592 | HIWindowFlush((WindowRef) m_macWindow) ; | |
1593 | else | |
1594 | #endif | |
1595 | { | |
1596 | // the only way to trigger the redrawing on earlier systems is to call | |
1597 | // ReceiveNextEvent | |
1598 | ||
1599 | EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; | |
1600 | UInt32 currentEventClass = 0 ; | |
1601 | UInt32 currentEventKind = 0 ; | |
1602 | if ( currentEvent != NULL ) | |
1603 | { | |
1604 | currentEventClass = ::GetEventClass( currentEvent ) ; | |
1605 | currentEventKind = ::GetEventKind( currentEvent ) ; | |
1606 | } | |
1607 | ||
1608 | if ( currentEventClass != kEventClassMenu ) | |
1609 | { | |
1610 | // when tracking a menu, strange redraw errors occur if we flush now, so leave.. | |
1611 | EventRef theEvent; | |
1612 | OSStatus status = noErr ; | |
1613 | status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ; | |
1614 | } | |
1615 | } | |
1616 | } | |
1617 | else | |
1618 | #endif | |
1619 | { | |
1620 | BeginUpdate( (WindowRef) m_macWindow ) ; | |
1621 | ||
1622 | RgnHandle updateRgn = NewRgn(); | |
1623 | if ( updateRgn ) | |
1624 | { | |
1625 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); | |
1626 | UpdateControls( (WindowRef)m_macWindow , updateRgn ) ; | |
1627 | ||
1628 | // if ( !EmptyRgn( updateRgn ) ) | |
1629 | // MacDoRedraw( updateRgn , 0 , true) ; | |
1630 | ||
1631 | DisposeRgn( updateRgn ); | |
1632 | } | |
1633 | ||
1634 | EndUpdate( (WindowRef)m_macWindow ) ; | |
1635 | QDFlushPortBuffer( GetWindowPort( (WindowRef)m_macWindow ) , NULL ) ; | |
1636 | } | |
1637 | } | |
1638 | ||
1639 | // Attracts the users attention to this window if the application is | |
1640 | // inactive (should be called when a background event occurs) | |
1641 | ||
1642 | static pascal void wxMacNMResponse( NMRecPtr ptr ) | |
1643 | { | |
1644 | NMRemove( ptr ) ; | |
1645 | DisposePtr( (Ptr)ptr ) ; | |
1646 | } | |
1647 | ||
1648 | void wxTopLevelWindowMac::RequestUserAttention(int flags ) | |
1649 | { | |
1650 | NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ; | |
1651 | static wxMacNMUPP nmupp( wxMacNMResponse ); | |
1652 | ||
1653 | memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ; | |
1654 | notificationRequest->qType = nmType ; | |
1655 | notificationRequest->nmMark = 1 ; | |
1656 | notificationRequest->nmIcon = 0 ; | |
1657 | notificationRequest->nmSound = 0 ; | |
1658 | notificationRequest->nmStr = NULL ; | |
1659 | notificationRequest->nmResp = nmupp ; | |
1660 | ||
1661 | verify_noerr( NMInstall( notificationRequest ) ) ; | |
1662 | } | |
1663 | ||
1664 | // --------------------------------------------------------------------------- | |
1665 | // Shape implementation | |
1666 | // --------------------------------------------------------------------------- | |
1667 | ||
1668 | ||
1669 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) | |
1670 | { | |
1671 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false, | |
1672 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1673 | ||
1674 | // The empty region signifies that the shape | |
1675 | // should be removed from the window. | |
1676 | if ( region.IsEmpty() ) | |
1677 | { | |
1678 | wxSize sz = GetClientSize(); | |
1679 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1680 | if ( rgn.IsEmpty() ) | |
1681 | return false ; | |
1682 | else | |
1683 | return SetShape(rgn); | |
1684 | } | |
1685 | ||
1686 | // Make a copy of the region | |
1687 | RgnHandle shapeRegion = NewRgn(); | |
1688 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1689 | ||
1690 | // Dispose of any shape region we may already have | |
1691 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1692 | if ( oldRgn ) | |
1693 | DisposeRgn(oldRgn); | |
1694 | ||
1695 | // Save the region so we can use it later | |
1696 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1697 | ||
1698 | // inform the window manager that the window has changed shape | |
1699 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1700 | ||
1701 | return true; | |
1702 | } | |
1703 | ||
1704 | // --------------------------------------------------------------------------- | |
1705 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1706 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1707 | // --------------------------------------------------------------------------- | |
1708 | ||
1709 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) | |
1710 | { | |
1711 | GetWindowPortBounds(window, inRect); | |
1712 | Point pt = { inRect->left, inRect->top }; | |
1713 | ||
1714 | QDLocalToGlobalPoint( GetWindowPort(window), &pt ) ; | |
1715 | inRect->top = pt.v; | |
1716 | inRect->left = pt.h; | |
1717 | inRect->bottom += pt.v; | |
1718 | inRect->right += pt.h; | |
1719 | } | |
1720 | ||
1721 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1722 | { | |
1723 | /*------------------------------------------------------ | |
1724 | Define which options your custom window supports. | |
1725 | --------------------------------------------------------*/ | |
1726 | //just enable everything for our demo | |
1727 | *(OptionBits*)param = | |
1728 | //kWindowCanGrow | | |
1729 | //kWindowCanZoom | | |
1730 | //kWindowCanCollapse | | |
1731 | //kWindowCanGetWindowRegion | | |
1732 | //kWindowHasTitleBar | | |
1733 | //kWindowSupportsDragHilite | | |
1734 | kWindowCanDrawInCurrentPort | | |
1735 | //kWindowCanMeasureTitle | | |
1736 | kWindowWantsDisposeAtProcessDeath | | |
1737 | kWindowSupportsGetGrowImageRegion | | |
1738 | kWindowDefSupportsColorGrafPort; | |
1739 | ||
1740 | return 1; | |
1741 | } | |
1742 | ||
1743 | // The content region is left as a rectangle matching the window size, this is | |
1744 | // so the origin in the paint event, and etc. still matches what the | |
1745 | // programmer expects. | |
1746 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1747 | { | |
1748 | SetEmptyRgn(rgn); | |
1749 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1750 | if (win) | |
1751 | { | |
1752 | Rect r ; | |
1753 | wxShapedMacWindowGetPos( window, &r ) ; | |
1754 | RectRgn( rgn , &r ) ; | |
1755 | } | |
1756 | } | |
1757 | ||
1758 | // The structure region is set to the shape given to the SetShape method. | |
1759 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1760 | { | |
1761 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1762 | ||
1763 | SetEmptyRgn(rgn); | |
1764 | if (cachedRegion) | |
1765 | { | |
1766 | Rect windowRect; | |
1767 | wxShapedMacWindowGetPos(window, &windowRect); // how big is the window | |
1768 | CopyRgn(cachedRegion, rgn); // make a copy of our cached region | |
1769 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1770 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1771 | } | |
1772 | } | |
1773 | ||
1774 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1775 | { | |
1776 | GetWindowRegionPtr rgnRec = (GetWindowRegionPtr)param; | |
1777 | ||
1778 | if (rgnRec == NULL) | |
1779 | return paramErr; | |
1780 | ||
1781 | switch (rgnRec->regionCode) | |
1782 | { | |
1783 | case kWindowStructureRgn: | |
1784 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1785 | break; | |
1786 | ||
1787 | case kWindowContentRgn: | |
1788 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1789 | break; | |
1790 | ||
1791 | default: | |
1792 | SetEmptyRgn(rgnRec->winRgn); | |
1793 | break; | |
1794 | } | |
1795 | ||
1796 | return noErr; | |
1797 | } | |
1798 | ||
1799 | // Determine the region of the window which was hit | |
1800 | // | |
1801 | static SInt32 wxShapedMacWindowHitTest(WindowRef window, SInt32 param) | |
1802 | { | |
1803 | Point hitPoint; | |
1804 | static RgnHandle tempRgn = NULL; | |
1805 | ||
1806 | if (tempRgn == NULL) | |
1807 | tempRgn = NewRgn(); | |
1808 | ||
1809 | // get the point clicked | |
1810 | SetPt( &hitPoint, LoWord(param), HiWord(param) ); | |
1811 | ||
1812 | // Mac OS 8.5 or later | |
1813 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1814 | if (PtInRgn( hitPoint, tempRgn )) //in window content region? | |
1815 | return wInContent; | |
1816 | ||
1817 | // no significant area was hit | |
1818 | return wNoHit; | |
1819 | } | |
1820 | ||
1821 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1822 | { | |
1823 | switch (message) | |
1824 | { | |
1825 | case kWindowMsgHitTest: | |
1826 | return wxShapedMacWindowHitTest(window, param); | |
1827 | ||
1828 | case kWindowMsgGetFeatures: | |
1829 | return wxShapedMacWindowGetFeatures(window, param); | |
1830 | ||
1831 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1832 | case kWindowMsgGetRegion: | |
1833 | return wxShapedMacWindowGetRegion(window, param); | |
1834 | ||
1835 | default: | |
1836 | break; | |
1837 | } | |
1838 | ||
1839 | return 0; | |
1840 | } | |
1841 |