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