]>
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 | } | |
942 | FullScreenData ; | |
943 | ||
944 | void wxTopLevelWindowMac::Init() | |
945 | { | |
946 | m_iconized = | |
947 | m_maximizeOnShow = false; | |
948 | m_macWindow = NULL ; | |
949 | ||
950 | #if TARGET_API_MAC_OSX | |
951 | m_macUsesCompositing = ( UMAGetSystemVersion() >= 0x1030 ); | |
952 | #else | |
953 | m_macUsesCompositing = false; | |
954 | #endif | |
955 | ||
956 | m_macEventHandler = NULL ; | |
957 | m_macFullScreenData = NULL ; | |
958 | } | |
959 | ||
960 | class wxMacDeferredWindowDeleter : public wxObject | |
961 | { | |
962 | public : | |
963 | wxMacDeferredWindowDeleter( WindowRef windowRef ) | |
964 | { | |
965 | m_macWindow = windowRef ; | |
966 | } | |
967 | ||
968 | virtual ~wxMacDeferredWindowDeleter() | |
969 | { | |
970 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
971 | } | |
972 | ||
973 | protected : | |
974 | WindowRef m_macWindow ; | |
975 | } ; | |
976 | ||
977 | bool wxTopLevelWindowMac::Create(wxWindow *parent, | |
978 | wxWindowID id, | |
979 | const wxString& title, | |
980 | const wxPoint& pos, | |
981 | const wxSize& size, | |
982 | long style, | |
983 | const wxString& name) | |
984 | { | |
985 | // init our fields | |
986 | Init(); | |
987 | ||
988 | m_windowStyle = style; | |
989 | ||
990 | SetName( name ); | |
991 | ||
992 | m_windowId = id == -1 ? NewControlId() : id; | |
993 | wxWindow::SetLabel( title ) ; | |
994 | ||
995 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; | |
996 | ||
997 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); | |
998 | ||
999 | if (GetExtraStyle() & wxFRAME_EX_METAL) | |
1000 | MacSetMetalAppearance(true); | |
1001 | ||
1002 | wxTopLevelWindows.Append(this); | |
1003 | ||
1004 | if ( parent ) | |
1005 | parent->AddChild(this); | |
1006 | ||
1007 | return true; | |
1008 | } | |
1009 | ||
1010 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
1011 | { | |
1012 | if ( m_macWindow ) | |
1013 | { | |
1014 | #if wxUSE_TOOLTIPS | |
1015 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
1016 | #endif | |
1017 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; | |
1018 | } | |
1019 | ||
1020 | if ( m_macEventHandler ) | |
1021 | { | |
1022 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
1023 | m_macEventHandler = NULL ; | |
1024 | } | |
1025 | ||
1026 | wxRemoveMacWindowAssociation( this ) ; | |
1027 | ||
1028 | if ( wxModelessWindows.Find(this) ) | |
1029 | wxModelessWindows.DeleteObject(this); | |
1030 | ||
1031 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
1032 | delete data ; | |
1033 | m_macFullScreenData = NULL ; | |
1034 | } | |
1035 | ||
1036 | ||
1037 | // ---------------------------------------------------------------------------- | |
1038 | // wxTopLevelWindowMac maximize/minimize | |
1039 | // ---------------------------------------------------------------------------- | |
1040 | ||
1041 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
1042 | { | |
1043 | // TODO: check if this is still necessary | |
1044 | #if 0 | |
1045 | wxMacPortStateHelper help( (GrafPtr)GetWindowPort( (WindowRef)m_macWindow) ) ; | |
1046 | wxMacWindowClipper clip( this ); | |
1047 | #endif | |
1048 | ||
1049 | if ( !IsWindowInStandardState( (WindowRef)m_macWindow, NULL, NULL ) ) | |
1050 | { | |
1051 | Rect rect; | |
1052 | ||
1053 | GetWindowBounds((WindowRef)m_macWindow, kWindowGlobalPortRgn, &rect); | |
1054 | SetWindowIdealUserState((WindowRef)m_macWindow, &rect); | |
1055 | SetWindowUserState((WindowRef)m_macWindow, &rect); | |
1056 | } | |
1057 | ||
1058 | ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ; | |
1059 | } | |
1060 | ||
1061 | bool wxTopLevelWindowMac::IsMaximized() const | |
1062 | { | |
1063 | return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ; | |
1064 | } | |
1065 | ||
1066 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
1067 | { | |
1068 | if ( IsWindowCollapsable( (WindowRef)m_macWindow) ) | |
1069 | CollapseWindow( (WindowRef)m_macWindow , iconize ) ; | |
1070 | } | |
1071 | ||
1072 | bool wxTopLevelWindowMac::IsIconized() const | |
1073 | { | |
1074 | return IsWindowCollapsed((WindowRef)m_macWindow ) ; | |
1075 | } | |
1076 | ||
1077 | void wxTopLevelWindowMac::Restore() | |
1078 | { | |
1079 | if ( IsMaximized() ) | |
1080 | Maximize(false); | |
1081 | else if ( IsIconized() ) | |
1082 | Iconize(false); | |
1083 | } | |
1084 | ||
1085 | // ---------------------------------------------------------------------------- | |
1086 | // wxTopLevelWindowMac misc | |
1087 | // ---------------------------------------------------------------------------- | |
1088 | ||
1089 | wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const | |
1090 | { | |
1091 | return wxPoint(0, 0) ; | |
1092 | } | |
1093 | ||
1094 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) | |
1095 | { | |
1096 | // this sets m_icon | |
1097 | wxTopLevelWindowBase::SetIcon(icon); | |
1098 | } | |
1099 | ||
1100 | void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) | |
1101 | { | |
1102 | wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ; | |
1103 | ||
1104 | if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme ) | |
1105 | { | |
1106 | SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ; | |
1107 | } | |
1108 | } | |
1109 | ||
1110 | void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler() | |
1111 | { | |
1112 | if ( m_macEventHandler != NULL ) | |
1113 | { | |
1114 | verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; | |
1115 | } | |
1116 | ||
1117 | InstallWindowEventHandler( | |
1118 | MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(), | |
1119 | GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler ); | |
1120 | } | |
1121 | ||
1122 | void wxTopLevelWindowMac::MacCreateRealWindow( | |
1123 | const wxString& title, | |
1124 | const wxPoint& pos, | |
1125 | const wxSize& size, | |
1126 | long style, | |
1127 | const wxString& name ) | |
1128 | { | |
1129 | OSStatus err = noErr ; | |
1130 | SetName(name); | |
1131 | m_windowStyle = style; | |
1132 | m_isShown = false; | |
1133 | ||
1134 | // create frame. | |
1135 | int x = (int)pos.x; | |
1136 | int y = (int)pos.y; | |
1137 | ||
1138 | Rect theBoundsRect; | |
1139 | wxRect display = wxGetClientDisplayRect() ; | |
1140 | ||
1141 | if ( x == wxDefaultPosition.x ) | |
1142 | x = display.x ; | |
1143 | ||
1144 | if ( y == wxDefaultPosition.y ) | |
1145 | y = display.y ; | |
1146 | ||
1147 | int w = WidthDefault(size.x); | |
1148 | int h = HeightDefault(size.y); | |
1149 | ||
1150 | ::SetRect(&theBoundsRect, x, y , x + w, y + h); | |
1151 | ||
1152 | // translate the window attributes in the appropriate window class and attributes | |
1153 | WindowClass wclass = 0; | |
1154 | WindowAttributes attr = kWindowNoAttributes ; | |
1155 | WindowGroupRef group = NULL ; | |
1156 | ||
1157 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) | |
1158 | { | |
1159 | if ( | |
1160 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || | |
1161 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
1162 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
1163 | ) | |
1164 | { | |
1165 | wclass = kFloatingWindowClass ; | |
1166 | ||
1167 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
1168 | attr |= kWindowSideTitlebarAttribute ; | |
1169 | } | |
1170 | else | |
1171 | { | |
1172 | wclass = kPlainWindowClass ; | |
1173 | } | |
1174 | } | |
1175 | else if ( HasFlag( wxCAPTION ) ) | |
1176 | { | |
1177 | wclass = kDocumentWindowClass ; | |
1178 | attr |= kWindowInWindowMenuAttribute ; | |
1179 | } | |
1180 | #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 ) | |
1181 | else if ( HasFlag( wxFRAME_DRAWER ) ) | |
1182 | { | |
1183 | wclass = kDrawerWindowClass; | |
1184 | // we must force compositing on a drawer | |
1185 | m_macUsesCompositing = true ; | |
1186 | } | |
1187 | #endif //10.2 and up | |
1188 | else | |
1189 | { | |
1190 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || | |
1191 | HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) ) | |
1192 | { | |
1193 | wclass = kDocumentWindowClass ; | |
1194 | } | |
1195 | else | |
1196 | { | |
1197 | wclass = kPlainWindowClass ; | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | if ( wclass != kPlainWindowClass ) | |
1202 | { | |
1203 | if ( HasFlag( wxMINIMIZE_BOX ) ) | |
1204 | attr |= kWindowCollapseBoxAttribute ; | |
1205 | ||
1206 | if ( HasFlag( wxMAXIMIZE_BOX ) ) | |
1207 | attr |= kWindowFullZoomAttribute ; | |
1208 | ||
1209 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
1210 | attr |= kWindowResizableAttribute ; | |
1211 | ||
1212 | if ( HasFlag( wxCLOSE_BOX) ) | |
1213 | attr |= kWindowCloseBoxAttribute ; | |
1214 | } | |
1215 | ||
1216 | // turn on live resizing (OS X only) | |
1217 | if (UMAGetSystemVersion() >= 0x1000) | |
1218 | attr |= kWindowLiveResizeAttribute; | |
1219 | ||
1220 | if ( HasFlag(wxSTAY_ON_TOP) ) | |
1221 | group = GetWindowGroupOfClass(kUtilityWindowClass) ; | |
1222 | ||
1223 | #if TARGET_API_MAC_OSX | |
1224 | if ( m_macUsesCompositing ) | |
1225 | attr |= kWindowCompositingAttribute; | |
1226 | #endif | |
1227 | ||
1228 | if ( HasFlag(wxFRAME_SHAPED) ) | |
1229 | { | |
1230 | WindowDefSpec customWindowDefSpec; | |
1231 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
1232 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
1233 | ||
1234 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, | |
1235 | attr, &theBoundsRect, | |
1236 | (WindowRef*) &m_macWindow); | |
1237 | } | |
1238 | else | |
1239 | { | |
1240 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; | |
1241 | } | |
1242 | ||
1243 | if ( err == noErr && m_macWindow != NULL && group != NULL ) | |
1244 | SetWindowGroup( (WindowRef) m_macWindow , group ) ; | |
1245 | ||
1246 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); | |
1247 | ||
1248 | // the create commands are only for content rect, | |
1249 | // so we have to set the size again as structure bounds | |
1250 | SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; | |
1251 | ||
1252 | wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ; | |
1253 | UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ; | |
1254 | m_peer = new wxMacControl(this , true /*isRootControl*/) ; | |
1255 | ||
1256 | #if TARGET_API_MAC_OSX | |
1257 | if ( m_macUsesCompositing ) | |
1258 | { | |
1259 | // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of | |
1260 | // the content view, so we have to retrieve it explicitly | |
1261 | HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , | |
1262 | m_peer->GetControlRefAddr() ) ; | |
1263 | if ( !m_peer->Ok() ) | |
1264 | { | |
1265 | // compatibility mode fallback | |
1266 | GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ; | |
1267 | } | |
1268 | } | |
1269 | #endif | |
1270 | { | |
1271 | ::CreateRootControl( (WindowRef)m_macWindow , m_peer->GetControlRefAddr() ) ; | |
1272 | } | |
1273 | ||
1274 | // the root control level handler | |
1275 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; | |
1276 | ||
1277 | #if TARGET_API_MAC_OSX | |
1278 | if ( m_macUsesCompositing && m_macWindow != NULL ) | |
1279 | { | |
1280 | if ( GetExtraStyle() & wxFRAME_EX_METAL ) | |
1281 | MacSetMetalAppearance( true ) ; | |
1282 | } | |
1283 | #endif | |
1284 | ||
1285 | // the frame window event handler | |
1286 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; | |
1287 | MacInstallTopLevelWindowEventHandler() ; | |
1288 | ||
1289 | DoSetWindowVariant( m_windowVariant ) ; | |
1290 | ||
1291 | m_macFocus = NULL ; | |
1292 | ||
1293 | if ( HasFlag(wxFRAME_SHAPED) ) | |
1294 | { | |
1295 | // default shape matches the window size | |
1296 | wxRegion rgn( 0, 0, w, h ); | |
1297 | SetShape( rgn ); | |
1298 | } | |
1299 | ||
1300 | wxWindowCreateEvent event(this); | |
1301 | GetEventHandler()->ProcessEvent(event); | |
1302 | } | |
1303 | ||
1304 | void wxTopLevelWindowMac::ClearBackground() | |
1305 | { | |
1306 | wxWindow::ClearBackground() ; | |
1307 | } | |
1308 | ||
1309 | // Raise the window to the top of the Z order | |
1310 | void wxTopLevelWindowMac::Raise() | |
1311 | { | |
1312 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
1313 | } | |
1314 | ||
1315 | // Lower the window to the bottom of the Z order | |
1316 | void wxTopLevelWindowMac::Lower() | |
1317 | { | |
1318 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; | |
1319 | } | |
1320 | ||
1321 | void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) | |
1322 | { | |
1323 | if (s_macDeactivateWindow) | |
1324 | { | |
1325 | wxLogTrace(TRACE_ACTIVATE, | |
1326 | wxT("Doing delayed deactivation of %p"), | |
1327 | s_macDeactivateWindow); | |
1328 | ||
1329 | s_macDeactivateWindow->MacActivate(timestamp, false); | |
1330 | } | |
1331 | } | |
1332 | ||
1333 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) | |
1334 | { | |
1335 | wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this); | |
1336 | ||
1337 | if (s_macDeactivateWindow == this) | |
1338 | s_macDeactivateWindow = NULL; | |
1339 | ||
1340 | MacDelayedDeactivation(timestamp); | |
1341 | MacPropagateHiliteChanged() ; | |
1342 | } | |
1343 | ||
1344 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
1345 | { | |
1346 | wxWindow::SetLabel( title ) ; | |
1347 | UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ; | |
1348 | } | |
1349 | ||
1350 | wxString wxTopLevelWindowMac::GetTitle() const | |
1351 | { | |
1352 | return wxWindow::GetLabel(); | |
1353 | } | |
1354 | ||
1355 | bool wxTopLevelWindowMac::Show(bool show) | |
1356 | { | |
1357 | if ( !wxTopLevelWindowBase::Show(show) ) | |
1358 | return false; | |
1359 | ||
1360 | bool plainTransition = false; | |
1361 | ||
1362 | #if wxUSE_SYSTEM_OPTIONS | |
1363 | // code contributed by Ryan Wilcox December 18, 2003 | |
1364 | plainTransition = UMAGetSystemVersion() >= 0x1000 ; | |
1365 | if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) | |
1366 | plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ; | |
1367 | #endif | |
1368 | ||
1369 | if (show) | |
1370 | { | |
1371 | if ( plainTransition ) | |
1372 | ::ShowWindow( (WindowRef)m_macWindow ); | |
1373 | else | |
1374 | ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL ); | |
1375 | ||
1376 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
1377 | ||
1378 | // because apps expect a size event to occur at this moment | |
1379 | wxSizeEvent event(GetSize() , m_windowId); | |
1380 | event.SetEventObject(this); | |
1381 | GetEventHandler()->ProcessEvent(event); | |
1382 | } | |
1383 | else | |
1384 | { | |
1385 | if ( plainTransition ) | |
1386 | ::HideWindow( (WindowRef)m_macWindow ); | |
1387 | else | |
1388 | ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL ); | |
1389 | } | |
1390 | ||
1391 | MacPropagateVisibilityChanged() ; | |
1392 | ||
1393 | return true ; | |
1394 | } | |
1395 | ||
1396 | bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) | |
1397 | { | |
1398 | if ( show ) | |
1399 | { | |
1400 | FullScreenData *data = (FullScreenData *)m_macFullScreenData ; | |
1401 | delete data ; | |
1402 | data = new FullScreenData() ; | |
1403 | ||
1404 | m_macFullScreenData = data ; | |
1405 | data->m_position = GetPosition() ; | |
1406 | data->m_size = GetSize() ; | |
1407 | ||
1408 | if ( style & wxFULLSCREEN_NOMENUBAR ) | |
1409 | HideMenuBar() ; | |
1410 | ||
1411 | wxRect client = wxGetClientDisplayRect() ; | |
1412 | ||
1413 | int left , top , right , bottom ; | |
1414 | int x, y, w, h ; | |
1415 | ||
1416 | x = client.x ; | |
1417 | y = client.y ; | |
1418 | w = client.width ; | |
1419 | h = client.height ; | |
1420 | ||
1421 | MacGetContentAreaInset( left , top , right , bottom ) ; | |
1422 | ||
1423 | if ( style & wxFULLSCREEN_NOCAPTION ) | |
1424 | { | |
1425 | y -= top ; | |
1426 | h += top ; | |
1427 | } | |
1428 | ||
1429 | if ( style & wxFULLSCREEN_NOBORDER ) | |
1430 | { | |
1431 | x -= left ; | |
1432 | w += left + right ; | |
1433 | h += bottom ; | |
1434 | } | |
1435 | ||
1436 | if ( style & wxFULLSCREEN_NOTOOLBAR ) | |
1437 | { | |
1438 | // TODO | |
1439 | } | |
1440 | ||
1441 | if ( style & wxFULLSCREEN_NOSTATUSBAR ) | |
1442 | { | |
1443 | // TODO | |
1444 | } | |
1445 | ||
1446 | SetSize( x , y , w, h ) ; | |
1447 | } | |
1448 | else | |
1449 | { | |
1450 | ShowMenuBar() ; | |
1451 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
1452 | SetPosition( data->m_position ) ; | |
1453 | SetSize( data->m_size ) ; | |
1454 | ||
1455 | delete data ; | |
1456 | m_macFullScreenData = NULL ; | |
1457 | } | |
1458 | ||
1459 | return false; | |
1460 | } | |
1461 | ||
1462 | bool wxTopLevelWindowMac::IsFullScreen() const | |
1463 | { | |
1464 | return m_macFullScreenData != NULL ; | |
1465 | } | |
1466 | ||
1467 | void wxTopLevelWindowMac::SetExtraStyle(long exStyle) | |
1468 | { | |
1469 | if ( GetExtraStyle() == exStyle ) | |
1470 | return ; | |
1471 | ||
1472 | wxTopLevelWindowBase::SetExtraStyle( exStyle ) ; | |
1473 | ||
1474 | #if TARGET_API_MAC_OSX | |
1475 | if ( m_macUsesCompositing && m_macWindow != NULL ) | |
1476 | { | |
1477 | bool metal = GetExtraStyle() & wxFRAME_EX_METAL ; | |
1478 | if ( MacGetMetalAppearance() != metal ) | |
1479 | MacSetMetalAppearance( metal ) ; | |
1480 | } | |
1481 | #endif | |
1482 | } | |
1483 | ||
1484 | // we are still using coordinates of the content view | |
1485 | // TODO: switch to structure bounds | |
1486 | // | |
1487 | void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) | |
1488 | { | |
1489 | Rect content, structure ; | |
1490 | ||
1491 | GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ; | |
1492 | GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ; | |
1493 | ||
1494 | left = content.left - structure.left ; | |
1495 | top = content.top - structure.top ; | |
1496 | right = structure.right - content.right ; | |
1497 | bottom = structure.bottom - content.bottom ; | |
1498 | } | |
1499 | ||
1500 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
1501 | { | |
1502 | m_cachedClippedRectValid = false ; | |
1503 | Rect bounds = { y , x , y + height , x + width } ; | |
1504 | verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1505 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
1506 | } | |
1507 | ||
1508 | void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const | |
1509 | { | |
1510 | Rect bounds ; | |
1511 | ||
1512 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1513 | ||
1514 | if (x) | |
1515 | *x = bounds.left ; | |
1516 | if (y) | |
1517 | *y = bounds.top ; | |
1518 | } | |
1519 | ||
1520 | void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const | |
1521 | { | |
1522 | Rect bounds ; | |
1523 | ||
1524 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1525 | ||
1526 | if (width) | |
1527 | *width = bounds.right - bounds.left ; | |
1528 | if (height) | |
1529 | *height = bounds.bottom - bounds.top ; | |
1530 | } | |
1531 | ||
1532 | void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const | |
1533 | { | |
1534 | Rect bounds ; | |
1535 | ||
1536 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ; | |
1537 | ||
1538 | if (width) | |
1539 | *width = bounds.right - bounds.left ; | |
1540 | if (height) | |
1541 | *height = bounds.bottom - bounds.top ; | |
1542 | } | |
1543 | ||
1544 | void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) | |
1545 | { | |
1546 | #if TARGET_API_MAC_OSX | |
1547 | wxASSERT_MSG( m_macUsesCompositing , | |
1548 | wxT("Cannot set metal appearance on a non-compositing window") ) ; | |
1549 | ||
1550 | MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , | |
1551 | set ? kWindowNoAttributes : kWindowMetalAttribute ) ; | |
1552 | #endif | |
1553 | } | |
1554 | ||
1555 | bool wxTopLevelWindowMac::MacGetMetalAppearance() const | |
1556 | { | |
1557 | #if TARGET_API_MAC_OSX | |
1558 | return MacGetWindowAttributes() & kWindowMetalAttribute ; | |
1559 | #else | |
1560 | return false ; | |
1561 | #endif | |
1562 | } | |
1563 | ||
1564 | void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) | |
1565 | { | |
1566 | ChangeWindowAttributes( (WindowRef)m_macWindow, attributesToSet, attributesToClear ) ; | |
1567 | } | |
1568 | ||
1569 | wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const | |
1570 | { | |
1571 | UInt32 attr = 0 ; | |
1572 | GetWindowAttributes( (WindowRef) m_macWindow, &attr ) ; | |
1573 | ||
1574 | return attr ; | |
1575 | } | |
1576 | ||
1577 | void wxTopLevelWindowMac::MacPerformUpdates() | |
1578 | { | |
1579 | #if TARGET_API_MAC_OSX | |
1580 | if ( m_macUsesCompositing ) | |
1581 | { | |
1582 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 | |
1583 | // for composited windows this also triggers a redraw of all | |
1584 | // invalid views in the window | |
1585 | if ( UMAGetSystemVersion() >= 0x1030 ) | |
1586 | HIWindowFlush((WindowRef) m_macWindow) ; | |
1587 | else | |
1588 | #endif | |
1589 | { | |
1590 | // the only way to trigger the redrawing on earlier systems is to call | |
1591 | // ReceiveNextEvent | |
1592 | ||
1593 | EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; | |
1594 | UInt32 currentEventClass = 0 ; | |
1595 | UInt32 currentEventKind = 0 ; | |
1596 | if ( currentEvent != NULL ) | |
1597 | { | |
1598 | currentEventClass = ::GetEventClass( currentEvent ) ; | |
1599 | currentEventKind = ::GetEventKind( currentEvent ) ; | |
1600 | } | |
1601 | ||
1602 | if ( currentEventClass != kEventClassMenu ) | |
1603 | { | |
1604 | // when tracking a menu, strange redraw errors occur if we flush now, so leave.. | |
1605 | EventRef theEvent; | |
1606 | OSStatus status = noErr ; | |
1607 | status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ; | |
1608 | } | |
1609 | } | |
1610 | } | |
1611 | else | |
1612 | #endif | |
1613 | { | |
1614 | BeginUpdate( (WindowRef) m_macWindow ) ; | |
1615 | ||
1616 | RgnHandle updateRgn = NewRgn(); | |
1617 | if ( updateRgn ) | |
1618 | { | |
1619 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); | |
1620 | UpdateControls( (WindowRef)m_macWindow , updateRgn ) ; | |
1621 | ||
1622 | // if ( !EmptyRgn( updateRgn ) ) | |
1623 | // MacDoRedraw( updateRgn , 0 , true) ; | |
1624 | ||
1625 | DisposeRgn( updateRgn ); | |
1626 | } | |
1627 | ||
1628 | EndUpdate( (WindowRef)m_macWindow ) ; | |
1629 | QDFlushPortBuffer( GetWindowPort( (WindowRef)m_macWindow ) , NULL ) ; | |
1630 | } | |
1631 | } | |
1632 | ||
1633 | // Attracts the users attention to this window if the application is | |
1634 | // inactive (should be called when a background event occurs) | |
1635 | ||
1636 | static pascal void wxMacNMResponse( NMRecPtr ptr ) | |
1637 | { | |
1638 | NMRemove( ptr ) ; | |
1639 | DisposePtr( (Ptr)ptr ) ; | |
1640 | } | |
1641 | ||
1642 | void wxTopLevelWindowMac::RequestUserAttention(int flags ) | |
1643 | { | |
1644 | NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ; | |
1645 | static wxMacNMUPP nmupp( wxMacNMResponse ); | |
1646 | ||
1647 | memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ; | |
1648 | notificationRequest->qType = nmType ; | |
1649 | notificationRequest->nmMark = 1 ; | |
1650 | notificationRequest->nmIcon = 0 ; | |
1651 | notificationRequest->nmSound = 0 ; | |
1652 | notificationRequest->nmStr = NULL ; | |
1653 | notificationRequest->nmResp = nmupp ; | |
1654 | ||
1655 | verify_noerr( NMInstall( notificationRequest ) ) ; | |
1656 | } | |
1657 | ||
1658 | // --------------------------------------------------------------------------- | |
1659 | // Shape implementation | |
1660 | // --------------------------------------------------------------------------- | |
1661 | ||
1662 | ||
1663 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) | |
1664 | { | |
1665 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false, | |
1666 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1667 | ||
1668 | // The empty region signifies that the shape | |
1669 | // should be removed from the window. | |
1670 | if ( region.IsEmpty() ) | |
1671 | { | |
1672 | wxSize sz = GetClientSize(); | |
1673 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1674 | if ( rgn.IsEmpty() ) | |
1675 | return false ; | |
1676 | else | |
1677 | return SetShape(rgn); | |
1678 | } | |
1679 | ||
1680 | // Make a copy of the region | |
1681 | RgnHandle shapeRegion = NewRgn(); | |
1682 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1683 | ||
1684 | // Dispose of any shape region we may already have | |
1685 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1686 | if ( oldRgn ) | |
1687 | DisposeRgn(oldRgn); | |
1688 | ||
1689 | // Save the region so we can use it later | |
1690 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1691 | ||
1692 | // inform the window manager that the window has changed shape | |
1693 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1694 | ||
1695 | return true; | |
1696 | } | |
1697 | ||
1698 | // --------------------------------------------------------------------------- | |
1699 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1700 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1701 | // --------------------------------------------------------------------------- | |
1702 | ||
1703 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) | |
1704 | { | |
1705 | GetWindowPortBounds(window, inRect); | |
1706 | Point pt = { inRect->left, inRect->top }; | |
1707 | ||
1708 | QDLocalToGlobalPoint( GetWindowPort(window), &pt ) ; | |
1709 | inRect->top = pt.v; | |
1710 | inRect->left = pt.h; | |
1711 | inRect->bottom += pt.v; | |
1712 | inRect->right += pt.h; | |
1713 | } | |
1714 | ||
1715 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1716 | { | |
1717 | /*------------------------------------------------------ | |
1718 | Define which options your custom window supports. | |
1719 | --------------------------------------------------------*/ | |
1720 | //just enable everything for our demo | |
1721 | *(OptionBits*)param = | |
1722 | //kWindowCanGrow | | |
1723 | //kWindowCanZoom | | |
1724 | //kWindowCanCollapse | | |
1725 | //kWindowCanGetWindowRegion | | |
1726 | //kWindowHasTitleBar | | |
1727 | //kWindowSupportsDragHilite | | |
1728 | kWindowCanDrawInCurrentPort | | |
1729 | //kWindowCanMeasureTitle | | |
1730 | kWindowWantsDisposeAtProcessDeath | | |
1731 | kWindowSupportsGetGrowImageRegion | | |
1732 | kWindowDefSupportsColorGrafPort; | |
1733 | ||
1734 | return 1; | |
1735 | } | |
1736 | ||
1737 | // The content region is left as a rectangle matching the window size, this is | |
1738 | // so the origin in the paint event, and etc. still matches what the | |
1739 | // programmer expects. | |
1740 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1741 | { | |
1742 | SetEmptyRgn(rgn); | |
1743 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1744 | if (win) | |
1745 | { | |
1746 | Rect r ; | |
1747 | wxShapedMacWindowGetPos( window, &r ) ; | |
1748 | RectRgn( rgn , &r ) ; | |
1749 | } | |
1750 | } | |
1751 | ||
1752 | // The structure region is set to the shape given to the SetShape method. | |
1753 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1754 | { | |
1755 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1756 | ||
1757 | SetEmptyRgn(rgn); | |
1758 | if (cachedRegion) | |
1759 | { | |
1760 | Rect windowRect; | |
1761 | wxShapedMacWindowGetPos(window, &windowRect); // how big is the window | |
1762 | CopyRgn(cachedRegion, rgn); // make a copy of our cached region | |
1763 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1764 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1765 | } | |
1766 | } | |
1767 | ||
1768 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1769 | { | |
1770 | GetWindowRegionPtr rgnRec = (GetWindowRegionPtr)param; | |
1771 | ||
1772 | if (rgnRec == NULL) | |
1773 | return paramErr; | |
1774 | ||
1775 | switch (rgnRec->regionCode) | |
1776 | { | |
1777 | case kWindowStructureRgn: | |
1778 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1779 | break; | |
1780 | ||
1781 | case kWindowContentRgn: | |
1782 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1783 | break; | |
1784 | ||
1785 | default: | |
1786 | SetEmptyRgn(rgnRec->winRgn); | |
1787 | break; | |
1788 | } | |
1789 | ||
1790 | return noErr; | |
1791 | } | |
1792 | ||
1793 | // Determine the region of the window which was hit | |
1794 | // | |
1795 | static SInt32 wxShapedMacWindowHitTest(WindowRef window, SInt32 param) | |
1796 | { | |
1797 | Point hitPoint; | |
1798 | static RgnHandle tempRgn = NULL; | |
1799 | ||
1800 | if (tempRgn == NULL) | |
1801 | tempRgn = NewRgn(); | |
1802 | ||
1803 | // get the point clicked | |
1804 | SetPt( &hitPoint, LoWord(param), HiWord(param) ); | |
1805 | ||
1806 | // Mac OS 8.5 or later | |
1807 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1808 | if (PtInRgn( hitPoint, tempRgn )) //in window content region? | |
1809 | return wInContent; | |
1810 | ||
1811 | // no significant area was hit | |
1812 | return wNoHit; | |
1813 | } | |
1814 | ||
1815 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1816 | { | |
1817 | switch (message) | |
1818 | { | |
1819 | case kWindowMsgHitTest: | |
1820 | return wxShapedMacWindowHitTest(window, param); | |
1821 | ||
1822 | case kWindowMsgGetFeatures: | |
1823 | return wxShapedMacWindowGetFeatures(window, param); | |
1824 | ||
1825 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1826 | case kWindowMsgGetRegion: | |
1827 | return wxShapedMacWindowGetRegion(window, param); | |
1828 | ||
1829 | default: | |
1830 | break; | |
1831 | } | |
1832 | ||
1833 | return 0; | |
1834 | } | |
1835 |