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