]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/toplevel.cpp
CGFloat
[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& c )
994 {
995 wxColour col = c;
996 if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) )
997 col = wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground));
998 else if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) )
999 col = wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive));
1000
1001 if ( !wxTopLevelWindowBase::SetBackgroundColour(col) && m_hasBgCol )
1002 return false ;
1003
1004 if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground)) )
1005 {
1006 SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDocumentWindowBackground, false ) ;
1007 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
1008 }
1009 else if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive)) )
1010 {
1011 SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDialogBackgroundActive, false ) ;
1012 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
1013 }
1014 return true;
1015 }
1016
1017 void wxTopLevelWindowMacInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref)
1018 {
1019 InstallWindowEventHandler(window, GetwxMacTopLevelEventHandlerUPP(),
1020 GetEventTypeCount(eventList), eventList, ref, handler );
1021 }
1022
1023 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1024 {
1025 if ( m_macEventHandler != NULL )
1026 {
1027 verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ;
1028 }
1029 wxTopLevelWindowMacInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow),(EventHandlerRef *)&m_macEventHandler,this);
1030 }
1031
1032 void wxTopLevelWindowMac::MacCreateRealWindow(
1033 const wxString& title,
1034 const wxPoint& pos,
1035 const wxSize& size,
1036 long style,
1037 const wxString& name )
1038 {
1039 DoMacCreateRealWindow( NULL, title, pos, size, style, name );
1040 }
1041
1042 void wxTopLevelWindowMac::DoMacCreateRealWindow(
1043 wxWindow* parent,
1044 const wxString& title,
1045 const wxPoint& pos,
1046 const wxSize& size,
1047 long style,
1048 const wxString& name )
1049 {
1050 OSStatus err = noErr ;
1051 SetName(name);
1052 m_windowStyle = style;
1053 m_isShown = false;
1054
1055 // create frame.
1056 int x = (int)pos.x;
1057 int y = (int)pos.y;
1058
1059 Rect theBoundsRect;
1060 wxRect display = wxGetClientDisplayRect() ;
1061
1062 if ( x == wxDefaultPosition.x )
1063 x = display.x ;
1064
1065 if ( y == wxDefaultPosition.y )
1066 y = display.y ;
1067
1068 int w = WidthDefault(size.x);
1069 int h = HeightDefault(size.y);
1070
1071 ::SetRect(&theBoundsRect, x, y , x + w, y + h);
1072
1073 // translate the window attributes in the appropriate window class and attributes
1074 WindowClass wclass = 0;
1075 WindowAttributes attr = kWindowNoAttributes ;
1076 WindowGroupRef group = NULL ;
1077 bool activationScopeSet = false;
1078 WindowActivationScope activationScope = kWindowActivationScopeNone;
1079
1080 if ( HasFlag( wxFRAME_TOOL_WINDOW) )
1081 {
1082 if (
1083 HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
1084 HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) ||
1085 HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT)
1086 )
1087 {
1088 if ( HasFlag( wxSTAY_ON_TOP ) )
1089 wclass = kUtilityWindowClass;
1090 else
1091 wclass = kFloatingWindowClass ;
1092
1093 if ( HasFlag(wxTINY_CAPTION_VERT) )
1094 attr |= kWindowSideTitlebarAttribute ;
1095 }
1096 else
1097 {
1098 wclass = kPlainWindowClass ;
1099 activationScopeSet = true;
1100 activationScope = kWindowActivationScopeNone;
1101 }
1102 }
1103 else if ( HasFlag( wxPOPUP_WINDOW ) )
1104 {
1105 // TEMPORARY HACK!
1106 // Until we've got a real wxPopupWindow class on wxMac make it a
1107 // little easier for wxFrame to be used to emulate it and workaround
1108 // the lack of wxPopupWindow.
1109 if ( HasFlag( wxBORDER_NONE ) )
1110 wclass = kHelpWindowClass ; // has no border
1111 else
1112 wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
1113 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1114 group = GetWindowGroupOfClass( // float above other windows
1115 kFloatingWindowClass) ;
1116 }
1117 else if ( HasFlag( wxCAPTION ) )
1118 {
1119 wclass = kDocumentWindowClass ;
1120 attr |= kWindowInWindowMenuAttribute ;
1121 }
1122 else if ( HasFlag( wxFRAME_DRAWER ) )
1123 {
1124 wclass = kDrawerWindowClass;
1125 }
1126 else
1127 {
1128 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
1129 HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) )
1130 {
1131 wclass = kDocumentWindowClass ;
1132 }
1133 else if ( HasFlag( wxNO_BORDER ) )
1134 {
1135 wclass = kSimpleWindowClass ;
1136 }
1137 else
1138 {
1139 wclass = kPlainWindowClass ;
1140 }
1141 }
1142
1143 if ( wclass != kPlainWindowClass )
1144 {
1145 if ( HasFlag( wxMINIMIZE_BOX ) )
1146 attr |= kWindowCollapseBoxAttribute ;
1147
1148 if ( HasFlag( wxMAXIMIZE_BOX ) )
1149 attr |= kWindowFullZoomAttribute ;
1150
1151 if ( HasFlag( wxRESIZE_BORDER ) )
1152 attr |= kWindowResizableAttribute ;
1153
1154 if ( HasFlag( wxCLOSE_BOX) )
1155 attr |= kWindowCloseBoxAttribute ;
1156 }
1157 attr |= kWindowLiveResizeAttribute;
1158
1159 if ( HasFlag(wxSTAY_ON_TOP) )
1160 group = GetWindowGroupOfClass(kUtilityWindowClass) ;
1161
1162 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT ) )
1163 group = GetWindowGroupOfClass(kFloatingWindowClass) ;
1164
1165 if ( group == NULL && parent != NULL )
1166 {
1167 WindowRef parenttlw = (WindowRef) parent->MacGetTopLevelWindowRef();
1168 if( parenttlw )
1169 group = GetWindowGroupParent( GetWindowGroup( parenttlw ) );
1170 }
1171
1172 attr |= kWindowCompositingAttribute;
1173 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1174 attr |= kWindowFrameworkScaledAttribute;
1175 #endif
1176
1177 if ( HasFlag(wxFRAME_SHAPED) )
1178 {
1179 WindowDefSpec customWindowDefSpec;
1180 customWindowDefSpec.defType = kWindowDefProcPtr;
1181 customWindowDefSpec.u.defProc =
1182 #ifdef __LP64__
1183 (WindowDefUPP) wxShapedMacWindowDef;
1184 #else
1185 NewWindowDefUPP(wxShapedMacWindowDef);
1186 #endif
1187 err = ::CreateCustomWindow( &customWindowDefSpec, wclass,
1188 attr, &theBoundsRect,
1189 (WindowRef*) &m_macWindow);
1190 }
1191 else
1192 {
1193 err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
1194 }
1195
1196 if ( err == noErr && m_macWindow != NULL && group != NULL )
1197 SetWindowGroup( (WindowRef) m_macWindow , group ) ;
1198
1199 wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );
1200
1201 // setup a separate group for each window, so that overlays can be handled easily
1202
1203 WindowGroupRef overlaygroup = NULL;
1204 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &overlaygroup ));
1205 verify_noerr( SetWindowGroupParent( overlaygroup, GetWindowGroup( (WindowRef) m_macWindow )));
1206 verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , overlaygroup ));
1207
1208 if ( activationScopeSet )
1209 {
1210 verify_noerr( SetWindowActivationScope( (WindowRef) m_macWindow , activationScope ));
1211 }
1212
1213 // the create commands are only for content rect,
1214 // so we have to set the size again as structure bounds
1215 SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ;
1216
1217 wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ;
1218 SetWindowTitleWithCFString( (WindowRef) m_macWindow , wxCFStringRef( title , GetFont().GetEncoding() ) );
1219 m_peer = new wxMacControl(this , true /*isRootControl*/) ;
1220
1221 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1222 // the content view, so we have to retrieve it explicitly
1223 HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID ,
1224 m_peer->GetControlRefAddr() ) ;
1225 if ( !m_peer->Ok() )
1226 {
1227 // compatibility mode fallback
1228 GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ;
1229 }
1230
1231 // the root control level handler
1232 MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ;
1233
1234 // Causes the inner part of the window not to be metal
1235 // if the style is used before window creation.
1236 #if 0 // TARGET_API_MAC_OSX
1237 if ( m_macUsesCompositing && m_macWindow != NULL )
1238 {
1239 if ( GetExtraStyle() & wxFRAME_EX_METAL )
1240 MacSetMetalAppearance( true ) ;
1241 }
1242 #endif
1243
1244 if ( m_macWindow != NULL )
1245 {
1246 MacSetUnifiedAppearance( true ) ;
1247 }
1248
1249 HIViewRef growBoxRef = 0 ;
1250 err = HIViewFindByID( HIViewGetRoot( (WindowRef)m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef );
1251 if ( err == noErr && growBoxRef != 0 )
1252 HIGrowBoxViewSetTransparent( growBoxRef, true ) ;
1253
1254 // the frame window event handler
1255 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ;
1256 MacInstallTopLevelWindowEventHandler() ;
1257
1258 DoSetWindowVariant( m_windowVariant ) ;
1259
1260 m_macFocus = NULL ;
1261
1262 if ( HasFlag(wxFRAME_SHAPED) )
1263 {
1264 // default shape matches the window size
1265 wxRegion rgn( 0, 0, w, h );
1266 SetShape( rgn );
1267 }
1268
1269 wxWindowCreateEvent event(this);
1270 HandleWindowEvent(event);
1271 }
1272
1273 void wxTopLevelWindowMac::ClearBackground()
1274 {
1275 wxWindow::ClearBackground() ;
1276 }
1277
1278 // Raise the window to the top of the Z order
1279 void wxTopLevelWindowMac::Raise()
1280 {
1281 ::SelectWindow( (WindowRef)m_macWindow ) ;
1282 }
1283
1284 // Lower the window to the bottom of the Z order
1285 void wxTopLevelWindowMac::Lower()
1286 {
1287 ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
1288 }
1289
1290 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp)
1291 {
1292 if (s_macDeactivateWindow)
1293 {
1294 wxLogTrace(TRACE_ACTIVATE,
1295 wxT("Doing delayed deactivation of %p"),
1296 s_macDeactivateWindow);
1297
1298 s_macDeactivateWindow->MacActivate(timestamp, false);
1299 }
1300 }
1301
1302 void wxTopLevelWindowMac::MacActivate( long timestamp , bool WXUNUSED(inIsActivating) )
1303 {
1304 wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this);
1305
1306 if (s_macDeactivateWindow == this)
1307 s_macDeactivateWindow = NULL;
1308
1309 MacDelayedDeactivation(timestamp);
1310 }
1311
1312 void wxTopLevelWindowMac::SetTitle(const wxString& title)
1313 {
1314 wxWindow::SetLabel( title ) ;
1315 SetWindowTitleWithCFString( (WindowRef) m_macWindow , wxCFStringRef( title , GetFont().GetEncoding() ) ) ;
1316 }
1317
1318 wxString wxTopLevelWindowMac::GetTitle() const
1319 {
1320 return wxWindow::GetLabel();
1321 }
1322
1323 bool wxTopLevelWindowMac::Show(bool show)
1324 {
1325 if ( !wxTopLevelWindowBase::Show(show) )
1326 return false;
1327
1328 bool plainTransition = true;
1329
1330 #if wxUSE_SYSTEM_OPTIONS
1331 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) )
1332 plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ;
1333 #endif
1334
1335 if (show)
1336 {
1337 if ( plainTransition )
1338 ::ShowWindow( (WindowRef)m_macWindow );
1339 else
1340 ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL );
1341
1342 ::SelectWindow( (WindowRef)m_macWindow ) ;
1343
1344 // because apps expect a size event to occur at this moment
1345 wxSizeEvent event(GetSize() , m_windowId);
1346 event.SetEventObject(this);
1347 HandleWindowEvent(event);
1348 }
1349 else
1350 {
1351 if ( plainTransition )
1352 ::HideWindow( (WindowRef)m_macWindow );
1353 else
1354 ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL );
1355 }
1356
1357 return true ;
1358 }
1359
1360 bool wxTopLevelWindowMac::ShowWithEffect(wxShowEffect effect,
1361 unsigned timeout,
1362 wxDirection dir)
1363 {
1364 // TODO factor common code
1365 if ( !wxTopLevelWindowBase::Show(true) )
1366 return false;
1367
1368 WindowTransitionEffect transition = 0 ;
1369 switch( effect )
1370 {
1371 case wxSHOW_EFFECT_ROLL :
1372 case wxSHOW_EFFECT_SLIDE :
1373 transition = kWindowGenieTransitionEffect;
1374 break;
1375 case wxSHOW_EFFECT_BLEND :
1376 transition = kWindowFadeTransitionEffect;
1377 break;
1378 case wxSHOW_EFFECT_EXPAND :
1379 default :
1380 // having sheets would be fine, but this might lead to a repositioning
1381 #if 0
1382 if ( GetParent() )
1383 transition = kWindowSheetTransitionEffect;
1384 else
1385 #endif
1386 transition = kWindowZoomTransitionEffect;
1387 break;
1388 }
1389
1390 TransitionWindowOptions options;
1391 options.version = 0;
1392 options.duration = timeout / 1000.0;
1393 options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) GetParent()->MacGetTopLevelWindowRef() :0;
1394 options.userData = 0;
1395
1396 wxSize size = wxGetDisplaySize();
1397 Rect bounds;
1398 GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds );
1399 CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top );
1400
1401 if ( dir & wxRIGHT )
1402 {
1403 hiBounds.origin.x = size.x;
1404 hiBounds.size.width = 0;
1405 }
1406 if ( dir & wxUP )
1407 {
1408 hiBounds.origin.y = 0;
1409 hiBounds.size.height = 0;
1410 }
1411 if ( dir & wxDOWN )
1412 {
1413 hiBounds.origin.y = size.y;
1414 hiBounds.size.height = 0;
1415 }
1416 if ( dir & wxLEFT )
1417 {
1418 hiBounds.origin.x = 0;
1419 hiBounds.size.width = 0;
1420 }
1421
1422 ::TransitionWindowWithOptions( (WindowRef)m_macWindow, transition, kWindowShowTransitionAction, transition == kWindowGenieTransitionEffect ? &hiBounds : NULL ,
1423 false, &options );
1424
1425 ::SelectWindow( (WindowRef)m_macWindow ) ;
1426
1427 // because apps expect a size event to occur at this moment
1428 wxSizeEvent event(GetSize() , m_windowId);
1429 event.SetEventObject(this);
1430 HandleWindowEvent(event);
1431
1432 return true;
1433 }
1434
1435 bool wxTopLevelWindowMac::HideWithEffect(wxShowEffect effect,
1436 unsigned timeout ,
1437 wxDirection dir )
1438 {
1439 if ( !wxTopLevelWindowBase::Show(false) )
1440 return false;
1441
1442 WindowTransitionEffect transition = 0 ;
1443 switch( effect )
1444 {
1445 case wxSHOW_EFFECT_ROLL :
1446 case wxSHOW_EFFECT_SLIDE :
1447 transition = kWindowGenieTransitionEffect;
1448 break;
1449 case wxSHOW_EFFECT_BLEND :
1450 transition = kWindowFadeTransitionEffect;
1451 break;
1452 case wxSHOW_EFFECT_EXPAND :
1453 default:
1454 #if 0
1455 if ( GetParent() )
1456 transition = kWindowSheetTransitionEffect;
1457 else
1458 #endif
1459 transition = kWindowZoomTransitionEffect;
1460 break;
1461 }
1462 TransitionWindowOptions options;
1463 options.version = 0;
1464 options.duration = timeout / 1000.0;
1465 options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) GetParent()->MacGetTopLevelWindowRef() :0;
1466 options.userData = 0;
1467
1468 wxSize size = wxGetDisplaySize();
1469 Rect bounds;
1470 GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds );
1471 CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top );
1472
1473 if ( dir & wxRIGHT )
1474 {
1475 hiBounds.origin.x = size.x;
1476 hiBounds.size.width = 0;
1477 }
1478 if ( dir & wxUP )
1479 {
1480 hiBounds.origin.y = 0;
1481 hiBounds.size.height = 0;
1482 }
1483 if ( dir & wxDOWN )
1484 {
1485 hiBounds.origin.y = size.y;
1486 hiBounds.size.height = 0;
1487 }
1488 if ( dir & wxLEFT )
1489 {
1490 hiBounds.origin.x = 0;
1491 hiBounds.size.width = 0;
1492 }
1493 ::TransitionWindowWithOptions( (WindowRef)m_macWindow, transition, kWindowHideTransitionAction, transition == kWindowGenieTransitionEffect ? &hiBounds : NULL ,
1494 false, &options );
1495
1496 return true;
1497 }
1498
1499 bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style)
1500 {
1501 if ( show )
1502 {
1503 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
1504 delete data ;
1505 data = new FullScreenData() ;
1506
1507 m_macFullScreenData = data ;
1508 data->m_position = GetPosition() ;
1509 data->m_size = GetSize() ;
1510 data->m_wasResizable = MacGetWindowAttributes() & kWindowResizableAttribute ;
1511
1512 if ( style & wxFULLSCREEN_NOMENUBAR )
1513 HideMenuBar() ;
1514
1515 wxRect client = wxGetClientDisplayRect() ;
1516
1517 int left , top , right , bottom ;
1518 int x, y, w, h ;
1519
1520 x = client.x ;
1521 y = client.y ;
1522 w = client.width ;
1523 h = client.height ;
1524
1525 MacGetContentAreaInset( left , top , right , bottom ) ;
1526
1527 if ( style & wxFULLSCREEN_NOCAPTION )
1528 {
1529 y -= top ;
1530 h += top ;
1531 }
1532
1533 if ( style & wxFULLSCREEN_NOBORDER )
1534 {
1535 x -= left ;
1536 w += left + right ;
1537 h += bottom ;
1538 }
1539
1540 if ( style & wxFULLSCREEN_NOTOOLBAR )
1541 {
1542 // TODO
1543 }
1544
1545 if ( style & wxFULLSCREEN_NOSTATUSBAR )
1546 {
1547 // TODO
1548 }
1549
1550 SetSize( x , y , w, h ) ;
1551 if ( data->m_wasResizable )
1552 MacChangeWindowAttributes( kWindowNoAttributes , kWindowResizableAttribute ) ;
1553 }
1554 else
1555 {
1556 ShowMenuBar() ;
1557 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
1558 if ( data->m_wasResizable )
1559 MacChangeWindowAttributes( kWindowResizableAttribute , kWindowNoAttributes ) ;
1560 SetPosition( data->m_position ) ;
1561 SetSize( data->m_size ) ;
1562
1563 delete data ;
1564 m_macFullScreenData = NULL ;
1565 }
1566
1567 return false;
1568 }
1569
1570 bool wxTopLevelWindowMac::IsFullScreen() const
1571 {
1572 return m_macFullScreenData != NULL ;
1573 }
1574
1575
1576 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha)
1577 {
1578 OSStatus result = SetWindowAlpha((WindowRef)m_macWindow, float(alpha)/255.0);
1579 return result == noErr;
1580 }
1581
1582
1583 bool wxTopLevelWindowMac::CanSetTransparent()
1584 {
1585 return true;
1586 }
1587
1588
1589 void wxTopLevelWindowMac::SetExtraStyle(long exStyle)
1590 {
1591 if ( GetExtraStyle() == exStyle )
1592 return ;
1593
1594 wxTopLevelWindowBase::SetExtraStyle( exStyle ) ;
1595
1596 if ( m_macWindow != NULL )
1597 {
1598 bool metal = GetExtraStyle() & wxFRAME_EX_METAL ;
1599
1600 if ( MacGetMetalAppearance() != metal )
1601 {
1602 if ( MacGetUnifiedAppearance() )
1603 MacSetUnifiedAppearance( !metal ) ;
1604
1605 MacSetMetalAppearance( metal ) ;
1606 }
1607 }
1608 }
1609
1610 bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style)
1611 {
1612 if ( !wxTopLevelWindowBase::SetBackgroundStyle(style) )
1613 return false ;
1614
1615 WindowRef windowRef = HIViewGetWindow( (HIViewRef)GetHandle() );
1616
1617 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1618 {
1619 OSStatus err = HIWindowChangeFeatures( windowRef, 0, kWindowIsOpaque );
1620 verify_noerr( err );
1621 err = ReshapeCustomWindow( windowRef );
1622 verify_noerr( err );
1623 }
1624
1625 return true ;
1626 }
1627
1628 // TODO: switch to structure bounds -
1629 // we are still using coordinates of the content view
1630 //
1631 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1632 {
1633 Rect content, structure ;
1634
1635 GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ;
1636 GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ;
1637
1638 left = content.left - structure.left ;
1639 top = content.top - structure.top ;
1640 right = structure.right - content.right ;
1641 bottom = structure.bottom - content.bottom ;
1642 }
1643
1644 void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
1645 {
1646 m_cachedClippedRectValid = false ;
1647 Rect bounds = { y , x , y + height , x + width } ;
1648 verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1649 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1650 }
1651
1652 void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const
1653 {
1654 Rect bounds ;
1655
1656 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1657
1658 if (x)
1659 *x = bounds.left ;
1660 if (y)
1661 *y = bounds.top ;
1662 }
1663
1664 void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const
1665 {
1666 Rect bounds ;
1667
1668 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1669
1670 if (width)
1671 *width = bounds.right - bounds.left ;
1672 if (height)
1673 *height = bounds.bottom - bounds.top ;
1674 }
1675
1676 void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const
1677 {
1678 Rect bounds ;
1679
1680 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ;
1681
1682 if (width)
1683 *width = bounds.right - bounds.left ;
1684 if (height)
1685 *height = bounds.bottom - bounds.top ;
1686 }
1687
1688 void wxTopLevelWindowMac::DoCentre(int dir)
1689 {
1690 if ( m_macWindow != 0 )
1691 wxTopLevelWindowBase::DoCentre(dir);
1692 }
1693
1694 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set )
1695 {
1696 if ( MacGetUnifiedAppearance() )
1697 MacSetUnifiedAppearance( false ) ;
1698
1699 MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes ,
1700 set ? kWindowNoAttributes : kWindowMetalAttribute ) ;
1701 }
1702
1703 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1704 {
1705 return MacGetWindowAttributes() & kWindowMetalAttribute ;
1706 }
1707
1708 void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set )
1709 {
1710 if ( MacGetMetalAppearance() )
1711 MacSetMetalAppearance( false ) ;
1712
1713 MacChangeWindowAttributes( set ? kWindowUnifiedTitleAndToolbarAttribute : kWindowNoAttributes ,
1714 set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ;
1715
1716 // For some reason, Tiger uses white as the background color for this appearance,
1717 // while most apps using it use the typical striped background. Restore that behavior
1718 // for wx.
1719 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1720 // though)
1721 SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ;
1722 }
1723
1724 bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
1725 {
1726 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ;
1727 }
1728
1729 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear )
1730 {
1731 ChangeWindowAttributes( (WindowRef)m_macWindow, attributesToSet, attributesToClear ) ;
1732 }
1733
1734 wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const
1735 {
1736 UInt32 attr = 0 ;
1737 GetWindowAttributes( (WindowRef) m_macWindow, &attr ) ;
1738
1739 return attr ;
1740 }
1741
1742 void wxTopLevelWindowMac::MacPerformUpdates()
1743 {
1744 // for composited windows this also triggers a redraw of all
1745 // invalid views in the window
1746 HIWindowFlush((WindowRef) m_macWindow) ;
1747 }
1748
1749 // Attracts the users attention to this window if the application is
1750 // inactive (should be called when a background event occurs)
1751
1752 static pascal void wxMacNMResponse( NMRecPtr ptr )
1753 {
1754 NMRemove( ptr ) ;
1755 DisposePtr( (Ptr)ptr ) ;
1756 }
1757
1758 void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags))
1759 {
1760 NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ;
1761 static wxMacNMUPP nmupp( wxMacNMResponse );
1762
1763 memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ;
1764 notificationRequest->qType = nmType ;
1765 notificationRequest->nmMark = 1 ;
1766 notificationRequest->nmIcon = 0 ;
1767 notificationRequest->nmSound = 0 ;
1768 notificationRequest->nmStr = NULL ;
1769 notificationRequest->nmResp = nmupp ;
1770
1771 verify_noerr( NMInstall( notificationRequest ) ) ;
1772 }
1773
1774 // ---------------------------------------------------------------------------
1775 // Shape implementation
1776 // ---------------------------------------------------------------------------
1777
1778
1779 bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
1780 {
1781 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
1782 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1783
1784 // The empty region signifies that the shape
1785 // should be removed from the window.
1786 if ( region.IsEmpty() )
1787 {
1788 wxSize sz = GetClientSize();
1789 wxRegion rgn(0, 0, sz.x, sz.y);
1790 if ( rgn.IsEmpty() )
1791 return false ;
1792 else
1793 return SetShape(rgn);
1794 }
1795
1796 // Make a copy of the region
1797 RgnHandle shapeRegion = NewRgn();
1798 HIShapeGetAsQDRgn( region.GetWXHRGN(), shapeRegion );
1799
1800 // Dispose of any shape region we may already have
1801 RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() );
1802 if ( oldRgn )
1803 DisposeRgn(oldRgn);
1804
1805 // Save the region so we can use it later
1806 SetWRefCon((WindowRef)MacGetWindowRef(), (URefCon)shapeRegion);
1807
1808 // inform the window manager that the window has changed shape
1809 ReshapeCustomWindow((WindowRef)MacGetWindowRef());
1810
1811 return true;
1812 }
1813
1814 // ---------------------------------------------------------------------------
1815 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1816 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1817 // ---------------------------------------------------------------------------
1818
1819 static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect)
1820 {
1821 GetWindowPortBounds(window, inRect);
1822 Point pt = { inRect->top ,inRect->left };
1823 wxMacLocalToGlobal( window, &pt ) ;
1824 inRect->bottom += pt.v - inRect->top;
1825 inRect->right += pt.h - inRect->left;
1826 inRect->top = pt.v;
1827 inRect->left = pt.h;
1828 }
1829
1830 static SInt32 wxShapedMacWindowGetFeatures(WindowRef WXUNUSED(window), SInt32 param)
1831 {
1832 /*------------------------------------------------------
1833 Define which options your custom window supports.
1834 --------------------------------------------------------*/
1835 //just enable everything for our demo
1836 *(OptionBits*)param =
1837 //kWindowCanGrow |
1838 //kWindowCanZoom |
1839 kWindowCanCollapse |
1840 //kWindowCanGetWindowRegion |
1841 //kWindowHasTitleBar |
1842 //kWindowSupportsDragHilite |
1843 kWindowCanDrawInCurrentPort |
1844 //kWindowCanMeasureTitle |
1845 kWindowWantsDisposeAtProcessDeath |
1846 kWindowSupportsGetGrowImageRegion |
1847 kWindowDefSupportsColorGrafPort;
1848
1849 return 1;
1850 }
1851
1852 // The content region is left as a rectangle matching the window size, this is
1853 // so the origin in the paint event, and etc. still matches what the
1854 // programmer expects.
1855 static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn)
1856 {
1857 SetEmptyRgn(rgn);
1858 wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window);
1859 if (win)
1860 {
1861 Rect r ;
1862 wxShapedMacWindowGetPos( window, &r ) ;
1863 RectRgn( rgn , &r ) ;
1864 }
1865 }
1866
1867 // The structure region is set to the shape given to the SetShape method.
1868 static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn)
1869 {
1870 RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window);
1871
1872 SetEmptyRgn(rgn);
1873 if (cachedRegion)
1874 {
1875 Rect windowRect;
1876 wxShapedMacWindowGetPos(window, &windowRect); // how big is the window
1877 CopyRgn(cachedRegion, rgn); // make a copy of our cached region
1878 OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window
1879 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1880 }
1881 }
1882
1883 static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param)
1884 {
1885 GetWindowRegionPtr rgnRec = (GetWindowRegionPtr)param;
1886
1887 if (rgnRec == NULL)
1888 return paramErr;
1889
1890 switch (rgnRec->regionCode)
1891 {
1892 case kWindowStructureRgn:
1893 wxShapedMacWindowStructureRegion(window, rgnRec->winRgn);
1894 break;
1895
1896 case kWindowContentRgn:
1897 wxShapedMacWindowContentRegion(window, rgnRec->winRgn);
1898 break;
1899
1900 default:
1901 SetEmptyRgn(rgnRec->winRgn);
1902 break;
1903 }
1904
1905 return noErr;
1906 }
1907
1908 // Determine the region of the window which was hit
1909 //
1910 static SInt32 wxShapedMacWindowHitTest(WindowRef window, SInt32 param)
1911 {
1912 Point hitPoint;
1913 static RgnHandle tempRgn = NULL;
1914
1915 if (tempRgn == NULL)
1916 tempRgn = NewRgn();
1917
1918 // get the point clicked
1919 SetPt( &hitPoint, LoWord(param), HiWord(param) );
1920
1921 // Mac OS 8.5 or later
1922 wxShapedMacWindowStructureRegion(window, tempRgn);
1923 if (PtInRgn( hitPoint, tempRgn )) //in window content region?
1924 return wInContent;
1925
1926 // no significant area was hit
1927 return wNoHit;
1928 }
1929
1930 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode), WindowRef window, SInt16 message, SInt32 param)
1931 {
1932 switch (message)
1933 {
1934 case kWindowMsgHitTest:
1935 return wxShapedMacWindowHitTest(window, param);
1936
1937 case kWindowMsgGetFeatures:
1938 return wxShapedMacWindowGetFeatures(window, param);
1939
1940 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1941 case kWindowMsgGetRegion:
1942 return wxShapedMacWindowGetRegion(window, param);
1943
1944 default:
1945 break;
1946 }
1947
1948 return 0;
1949 }