]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/toplevel.cpp
cleanup, fixing exports
[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->GetEventHandler()->ProcessEvent( 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->GetEventHandler()->ProcessEvent( 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->GetEventHandler()->ProcessEvent( 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->GetEventHandler()->ProcessEvent( 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 ControlRef wxMacFindSubControl( wxTopLevelWindowMac* toplevelWindow, const Point& location , ControlRef superControl , ControlPartCode *outPart )
394 {
395 if ( superControl )
396 {
397 UInt16 childrenCount = 0 ;
398 ControlHandle sibling ;
399 Rect r ;
400 OSStatus err = CountSubControls( superControl , &childrenCount ) ;
401 if ( err == errControlIsNotEmbedder )
402 return NULL ;
403
404 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
405
406 for ( UInt16 i = childrenCount ; i >=1 ; --i )
407 {
408 err = GetIndexedSubControl( superControl , i , & sibling ) ;
409 if ( err == errControlIsNotEmbedder )
410 return NULL ;
411
412 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
413 if ( IsControlVisible( sibling ) )
414 {
415 UMAGetControlBoundsInWindowCoords( sibling , &r ) ;
416 if ( MacPtInRect( location , &r ) )
417 {
418 ControlHandle child = wxMacFindSubControl( toplevelWindow , location , sibling , outPart ) ;
419 if ( child )
420 {
421 return child ;
422 }
423 else
424 {
425 Point testLocation = location ;
426
427 if ( toplevelWindow )
428 {
429 testLocation.h -= r.left ;
430 testLocation.v -= r.top ;
431 }
432
433 *outPart = TestControl( sibling , testLocation ) ;
434
435 return sibling ;
436 }
437 }
438 }
439 }
440 }
441
442 return NULL ;
443 }
444
445
446 #define NEW_CAPTURE_HANDLING 1
447
448 pascal OSStatus
449 wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(handler),
450 EventRef event,
451 void *data)
452 {
453 wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
454
455 OSStatus result = eventNotHandledErr ;
456
457 wxMacCarbonEvent cEvent( event ) ;
458
459 Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
460 Point windowMouseLocation = screenMouseLocation ;
461
462 WindowRef window = NULL;
463 short windowPart = ::FindWindow(screenMouseLocation, &window);
464
465 wxWindow* currentMouseWindow = NULL ;
466 ControlRef control = NULL ;
467
468 #if NEW_CAPTURE_HANDLING
469 if ( wxApp::s_captureWindow )
470 {
471 window = (WindowRef) wxApp::s_captureWindow->MacGetTopLevelWindowRef() ;
472 windowPart = inContent ;
473 }
474 #endif
475
476 if ( window )
477 {
478 wxMacGlobalToLocal( window, &windowMouseLocation ) ;
479
480 if ( wxApp::s_captureWindow
481 #if !NEW_CAPTURE_HANDLING
482 && wxApp::s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent
483 #endif
484 )
485 {
486 currentMouseWindow = wxApp::s_captureWindow ;
487 }
488 else if ( (IsWindowActive(window) && windowPart == inContent) )
489 {
490 ControlPartCode part ;
491 control = FindControlUnderMouse( windowMouseLocation , window , &part ) ;
492 // if there is no control below the mouse position, send the event to the toplevel window itself
493 if ( control == 0 )
494 {
495 currentMouseWindow = (wxWindow*) data ;
496 }
497 else
498 {
499 currentMouseWindow = (wxWindow*) wxFindControlFromMacControl( control ) ;
500 #ifndef __WXUNIVERSAL__
501 if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved )
502 {
503 #if wxUSE_TOOLBAR
504 // for wxToolBar to function we have to send certaint events to it
505 // instead of its children (wxToolBarTools)
506 ControlRef parent ;
507 GetSuperControl(control, &parent );
508 wxWindow *wxParent = (wxWindow*) wxFindControlFromMacControl( parent ) ;
509 if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) )
510 currentMouseWindow = wxParent ;
511 #endif
512 }
513 #endif
514 }
515
516 // disabled windows must not get any input messages
517 if ( currentMouseWindow && !currentMouseWindow->MacIsReallyEnabled() )
518 currentMouseWindow = NULL;
519 }
520 }
521
522 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
523 SetupMouseEvent( wxevent , cEvent ) ;
524
525 // handle all enter / leave events
526
527 if ( currentMouseWindow != g_MacLastWindow )
528 {
529 if ( g_MacLastWindow )
530 {
531 wxMouseEvent eventleave(wxevent);
532 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
533 g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
534 eventleave.SetEventObject( g_MacLastWindow ) ;
535 wxevent.SetId( g_MacLastWindow->GetId() ) ;
536
537 #if wxUSE_TOOLTIPS
538 wxToolTip::RelayEvent( g_MacLastWindow , eventleave);
539 #endif
540
541 g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave);
542 }
543
544 if ( currentMouseWindow )
545 {
546 wxMouseEvent evententer(wxevent);
547 evententer.SetEventType( wxEVT_ENTER_WINDOW );
548 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
549 evententer.SetEventObject( currentMouseWindow ) ;
550 wxevent.SetId( currentMouseWindow->GetId() ) ;
551
552 #if wxUSE_TOOLTIPS
553 wxToolTip::RelayEvent( currentMouseWindow , evententer );
554 #endif
555
556 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
557 }
558
559 g_MacLastWindow = currentMouseWindow ;
560 }
561
562 if ( windowPart == inMenuBar )
563 {
564 // special case menu bar, as we are having a low-level runloop we must do it ourselves
565 if ( cEvent.GetKind() == kEventMouseDown )
566 {
567 ::MenuSelect( screenMouseLocation ) ;
568 ::HiliteMenu(0);
569 result = noErr ;
570 }
571 }
572 else if ( currentMouseWindow )
573 {
574 wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent();
575
576 currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
577
578 wxevent.SetEventObject( currentMouseWindow ) ;
579 wxevent.SetId( currentMouseWindow->GetId() ) ;
580
581 // make tooltips current
582
583 #if wxUSE_TOOLTIPS
584 if ( wxevent.GetEventType() == wxEVT_MOTION )
585 wxToolTip::RelayEvent( currentMouseWindow , wxevent );
586 #endif
587
588 if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) )
589 {
590 if ((currentMouseWindowParent != NULL) &&
591 (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
592 currentMouseWindow = NULL;
593
594 result = noErr;
595 }
596 else
597 {
598 // if the user code did _not_ handle the event, then perform the
599 // default processing
600 if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN )
601 {
602 // ... that is set focus to this window
603 if (currentMouseWindow->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow)
604 currentMouseWindow->SetFocus();
605 }
606
607 // if built-in find control is finding the wrong control (ie static box instead of overlaid
608 // button, we cannot let the standard handler do its job, but must handle manually
609
610 if ( cEvent.GetKind() == kEventMouseDown )
611 {
612 if ( currentMouseWindow->MacIsReallyEnabled() )
613 {
614 EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
615 Point clickLocation = windowMouseLocation ;
616
617 currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ;
618
619 HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation ,
620 modifiers , (ControlActionUPP ) -1 ) ;
621
622 if ((currentMouseWindowParent != NULL) &&
623 (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
624 {
625 currentMouseWindow = NULL;
626 }
627 }
628
629 result = noErr ;
630 }
631 }
632
633 if ( cEvent.GetKind() == kEventMouseUp && wxApp::s_captureWindow )
634 {
635 wxApp::s_captureWindow = NULL ;
636 // update cursor ?
637 }
638
639 // update cursor
640
641 wxWindow* cursorTarget = currentMouseWindow ;
642 wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ;
643
644 while ( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
645 {
646 cursorTarget = cursorTarget->GetParent() ;
647 if ( cursorTarget )
648 cursorPoint += cursorTarget->GetPosition();
649 }
650
651 }
652 else // currentMouseWindow == NULL
653 {
654 // don't mess with controls we don't know about
655 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
656 // so we try sending them the correct control directly
657 if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control )
658 {
659 EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
660 Point clickLocation = windowMouseLocation ;
661
662 HIPoint hiPoint ;
663 hiPoint.x = clickLocation.h ;
664 hiPoint.y = clickLocation.v ;
665 HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ;
666 clickLocation.h = (int)hiPoint.x ;
667 clickLocation.v = (int)hiPoint.y ;
668
669 HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ;
670 result = noErr ;
671 }
672 }
673
674 return result ;
675 }
676
677 static pascal OSStatus
678 wxMacTopLevelWindowEventHandler(EventHandlerCallRef WXUNUSED(handler),
679 EventRef event,
680 void *data)
681 {
682 OSStatus result = eventNotHandledErr ;
683
684 wxMacCarbonEvent cEvent( event ) ;
685
686 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
687 wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
688
689 switch ( GetEventKind( event ) )
690 {
691 case kEventWindowActivated :
692 {
693 toplevelWindow->MacActivate( cEvent.GetTicks() , true) ;
694 wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId());
695 wxevent.SetTimestamp( cEvent.GetTicks() ) ;
696 wxevent.SetEventObject(toplevelWindow);
697 toplevelWindow->GetEventHandler()->ProcessEvent(wxevent);
698 // we still sending an eventNotHandledErr in order to allow for default processing
699 }
700 break ;
701
702 case kEventWindowDeactivated :
703 {
704 toplevelWindow->MacActivate(cEvent.GetTicks() , false) ;
705 wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId());
706 wxevent.SetTimestamp( cEvent.GetTicks() ) ;
707 wxevent.SetEventObject(toplevelWindow);
708 toplevelWindow->GetEventHandler()->ProcessEvent(wxevent);
709 // we still sending an eventNotHandledErr in order to allow for default processing
710 }
711 break ;
712
713 case kEventWindowShown :
714 toplevelWindow->Refresh() ;
715 result = noErr ;
716 break ;
717
718 case kEventWindowClose :
719 toplevelWindow->Close() ;
720 result = noErr ;
721 break ;
722
723 case kEventWindowBoundsChanged :
724 {
725 UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes, typeUInt32) ;
726 Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
727 wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ;
728 if ( attributes & kWindowBoundsChangeSizeChanged )
729 {
730 #ifndef __WXUNIVERSAL__
731 // according to the other ports we handle this within the OS level
732 // resize event, not within a wxSizeEvent
733 wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ;
734 if ( frame )
735 {
736 frame->PositionBars();
737 }
738 #endif
739 wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ;
740 event.SetEventObject( toplevelWindow ) ;
741
742 toplevelWindow->GetEventHandler()->ProcessEvent(event) ;
743 toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
744 }
745
746 if ( attributes & kWindowBoundsChangeOriginChanged )
747 {
748 wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ;
749 event.SetEventObject( toplevelWindow ) ;
750 toplevelWindow->GetEventHandler()->ProcessEvent(event) ;
751 }
752
753 result = noErr ;
754 }
755 break ;
756
757 case kEventWindowBoundsChanging :
758 {
759 UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ;
760 Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
761
762 if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) )
763 {
764 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
765 int left , top , right , bottom ;
766 toplevelWindow->MacGetContentAreaInset( left , top , right , bottom ) ;
767
768 wxRect r(
769 newRect.left - left,
770 newRect.top - top,
771 newRect.right - newRect.left + left + right,
772 newRect.bottom - newRect.top + top + bottom ) ;
773
774 // this is a EVT_SIZING not a EVT_SIZE type !
775 wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ;
776 wxevent.SetEventObject( toplevelWindow ) ;
777 wxRect adjustR = r ;
778 if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) )
779 adjustR = wxevent.GetRect() ;
780
781 if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() )
782 adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ;
783 if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() )
784 adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ;
785 if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() )
786 adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ;
787 if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() )
788 adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ;
789 const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ;
790 if ( !EqualRect( &newRect , &adjustedRect ) )
791 cEvent.SetParameter<Rect>( kEventParamCurrentBounds , &adjustedRect ) ;
792 toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
793 }
794
795 result = noErr ;
796 }
797 break ;
798
799 case kEventWindowGetRegion :
800 {
801 if ( toplevelWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
802 {
803 WindowRegionCode windowRegionCode ;
804
805 // Fetch the region code that is being queried
806 GetEventParameter( event,
807 kEventParamWindowRegionCode,
808 typeWindowRegionCode, NULL,
809 sizeof windowRegionCode, NULL,
810 &windowRegionCode ) ;
811
812 // If it is the opaque region code then set the
813 // region to empty and return noErr to stop event
814 // propagation
815 if ( windowRegionCode == kWindowOpaqueRgn ) {
816 RgnHandle region;
817 GetEventParameter( event,
818 kEventParamRgnHandle,
819 typeQDRgnHandle, NULL,
820 sizeof region, NULL,
821 &region) ;
822 SetEmptyRgn(region) ;
823 result = noErr ;
824 }
825 }
826 }
827 break ;
828
829 default :
830 break ;
831 }
832
833 return result ;
834 }
835
836 // mix this in from window.cpp
837 pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
838
839 pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
840 {
841 OSStatus result = eventNotHandledErr ;
842
843 switch ( GetEventClass( event ) )
844 {
845 case kEventClassTextInput :
846 result = wxMacUnicodeTextEventHandler( handler, event , data ) ;
847 break ;
848
849 case kEventClassKeyboard :
850 result = KeyboardEventHandler( handler, event , data ) ;
851 break ;
852
853 case kEventClassWindow :
854 result = wxMacTopLevelWindowEventHandler( handler, event , data ) ;
855 break ;
856
857 case kEventClassMouse :
858 result = wxMacTopLevelMouseEventHandler( handler, event , data ) ;
859 break ;
860
861 default :
862 break ;
863 }
864
865 return result ;
866 }
867
868 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler )
869
870 // ---------------------------------------------------------------------------
871 // wxWindowMac utility functions
872 // ---------------------------------------------------------------------------
873
874 // Find an item given the Macintosh Window Reference
875
876 WX_DECLARE_HASH_MAP(WindowRef, wxTopLevelWindowMac*, wxPointerHash, wxPointerEqual, MacWindowMap);
877
878 static MacWindowMap wxWinMacWindowList;
879
880 wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
881 {
882 MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef);
883
884 return (node == wxWinMacWindowList.end()) ? NULL : node->second;
885 }
886
887 void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ;
888 void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win)
889 {
890 // adding NULL WindowRef is (first) surely a result of an error and
891 // nothing else :-)
892 wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
893
894 wxWinMacWindowList[inWindowRef] = win;
895 }
896
897 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ;
898 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
899 {
900 MacWindowMap::iterator it;
901 for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it )
902 {
903 if ( it->second == win )
904 {
905 wxWinMacWindowList.erase(it);
906 break;
907 }
908 }
909 }
910
911 // ----------------------------------------------------------------------------
912 // wxTopLevelWindowMac creation
913 // ----------------------------------------------------------------------------
914
915 wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL;
916
917 typedef struct
918 {
919 wxPoint m_position ;
920 wxSize m_size ;
921 bool m_wasResizable ;
922 } FullScreenData ;
923
924 void wxTopLevelWindowMac::Init()
925 {
926 m_iconized =
927 m_maximizeOnShow = false;
928 m_macWindow = NULL ;
929
930 m_macEventHandler = NULL ;
931 m_macFullScreenData = NULL ;
932 }
933
934 wxMacDeferredWindowDeleter::wxMacDeferredWindowDeleter( WindowRef windowRef )
935 {
936 m_macWindow = windowRef ;
937 }
938
939 wxMacDeferredWindowDeleter::~wxMacDeferredWindowDeleter()
940 {
941 UMADisposeWindow( (WindowRef) m_macWindow ) ;
942 }
943
944 bool wxTopLevelWindowMac::Create(wxWindow *parent,
945 wxWindowID id,
946 const wxString& title,
947 const wxPoint& pos,
948 const wxSize& size,
949 long style,
950 const wxString& name)
951 {
952 // init our fields
953 Init();
954
955 m_windowStyle = style;
956
957 SetName( name );
958
959 m_windowId = id == -1 ? NewControlId() : id;
960 wxWindow::SetLabel( title ) ;
961
962 DoMacCreateRealWindow( parent, title, pos , size , style , name ) ;
963
964 SetBackgroundColour(wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive)));
965
966 if (GetExtraStyle() & wxFRAME_EX_METAL)
967 MacSetMetalAppearance(true);
968
969 wxTopLevelWindows.Append(this);
970
971 if ( parent )
972 parent->AddChild(this);
973
974 return true;
975 }
976
977 wxTopLevelWindowMac::~wxTopLevelWindowMac()
978 {
979 if ( m_macWindow )
980 {
981 #if wxUSE_TOOLTIPS
982 wxToolTip::NotifyWindowDelete(m_macWindow) ;
983 #endif
984 wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ;
985 }
986
987 if ( m_macEventHandler )
988 {
989 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
990 m_macEventHandler = NULL ;
991 }
992
993 wxRemoveMacWindowAssociation( this ) ;
994
995 if ( wxModelessWindows.Find(this) )
996 wxModelessWindows.DeleteObject(this);
997
998 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
999 delete data ;
1000 m_macFullScreenData = NULL ;
1001
1002 // avoid dangling refs
1003 if ( s_macDeactivateWindow == this )
1004 s_macDeactivateWindow = NULL;
1005 }
1006
1007
1008 // ----------------------------------------------------------------------------
1009 // wxTopLevelWindowMac maximize/minimize
1010 // ----------------------------------------------------------------------------
1011
1012 void wxTopLevelWindowMac::Maximize(bool maximize)
1013 {
1014 Point idealSize = { 0 , 0 } ;
1015 if ( maximize )
1016 {
1017 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1018 HIRect bounds ;
1019 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal,
1020 &bounds);
1021 idealSize.h = bounds.size.width;
1022 idealSize.v = bounds.size.height;
1023 #else
1024 Rect rect ;
1025 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect) ;
1026 idealSize.h = rect.right - rect.left ;
1027 idealSize.v = rect.bottom - rect.top ;
1028 #endif
1029 }
1030 ZoomWindowIdeal( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , &idealSize ) ;
1031 }
1032
1033 bool wxTopLevelWindowMac::IsMaximized() const
1034 {
1035 return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ;
1036 }
1037
1038 void wxTopLevelWindowMac::Iconize(bool iconize)
1039 {
1040 if ( IsWindowCollapsable( (WindowRef)m_macWindow) )
1041 CollapseWindow( (WindowRef)m_macWindow , iconize ) ;
1042 }
1043
1044 bool wxTopLevelWindowMac::IsIconized() const
1045 {
1046 return IsWindowCollapsed((WindowRef)m_macWindow ) ;
1047 }
1048
1049 void wxTopLevelWindowMac::Restore()
1050 {
1051 if ( IsMaximized() )
1052 Maximize(false);
1053 else if ( IsIconized() )
1054 Iconize(false);
1055 }
1056
1057 // ----------------------------------------------------------------------------
1058 // wxTopLevelWindowMac misc
1059 // ----------------------------------------------------------------------------
1060
1061 wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const
1062 {
1063 return wxPoint(0, 0) ;
1064 }
1065
1066 bool wxTopLevelWindowMac::SetBackgroundColour(const wxColour& col )
1067 {
1068 if ( !wxTopLevelWindowBase::SetBackgroundColour(col) && m_hasBgCol )
1069 return false ;
1070
1071 if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) )
1072 SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDocumentWindowBackground, false ) ;
1073 else if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) )
1074 SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDialogBackgroundActive, false ) ;
1075 // TODO BETTER THEME SUPPORT
1076 return true;
1077 }
1078
1079 void wxTopLevelWindowMacInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref)
1080 {
1081 InstallWindowEventHandler(window, GetwxMacTopLevelEventHandlerUPP(),
1082 GetEventTypeCount(eventList), eventList, ref, handler );
1083 }
1084
1085 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1086 {
1087 if ( m_macEventHandler != NULL )
1088 {
1089 verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ;
1090 }
1091 wxTopLevelWindowMacInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow),(EventHandlerRef *)&m_macEventHandler,this);
1092 }
1093
1094 void wxTopLevelWindowMac::MacCreateRealWindow(
1095 const wxString& title,
1096 const wxPoint& pos,
1097 const wxSize& size,
1098 long style,
1099 const wxString& name )
1100 {
1101 DoMacCreateRealWindow( NULL, title, pos, size, style, name );
1102 }
1103
1104 void wxTopLevelWindowMac::DoMacCreateRealWindow(
1105 wxWindow* parent,
1106 const wxString& title,
1107 const wxPoint& pos,
1108 const wxSize& size,
1109 long style,
1110 const wxString& name )
1111 {
1112 OSStatus err = noErr ;
1113 SetName(name);
1114 m_windowStyle = style;
1115 m_isShown = false;
1116
1117 // create frame.
1118 int x = (int)pos.x;
1119 int y = (int)pos.y;
1120
1121 Rect theBoundsRect;
1122 wxRect display = wxGetClientDisplayRect() ;
1123
1124 if ( x == wxDefaultPosition.x )
1125 x = display.x ;
1126
1127 if ( y == wxDefaultPosition.y )
1128 y = display.y ;
1129
1130 int w = WidthDefault(size.x);
1131 int h = HeightDefault(size.y);
1132
1133 ::SetRect(&theBoundsRect, x, y , x + w, y + h);
1134
1135 // translate the window attributes in the appropriate window class and attributes
1136 WindowClass wclass = 0;
1137 WindowAttributes attr = kWindowNoAttributes ;
1138 WindowGroupRef group = NULL ;
1139 bool activationScopeSet = false;
1140 WindowActivationScope activationScope = kWindowActivationScopeNone;
1141
1142 if ( HasFlag( wxFRAME_TOOL_WINDOW) )
1143 {
1144 if (
1145 HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
1146 HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) ||
1147 HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT)
1148 )
1149 {
1150 if ( HasFlag( wxSTAY_ON_TOP ) )
1151 wclass = kUtilityWindowClass;
1152 else
1153 wclass = kFloatingWindowClass ;
1154
1155 if ( HasFlag(wxTINY_CAPTION_VERT) )
1156 attr |= kWindowSideTitlebarAttribute ;
1157 }
1158 else
1159 {
1160 wclass = kPlainWindowClass ;
1161 activationScopeSet = true;
1162 activationScope = kWindowActivationScopeNone;
1163 }
1164 }
1165 else if ( HasFlag( wxPOPUP_WINDOW ) )
1166 {
1167 // TEMPORARY HACK!
1168 // Until we've got a real wxPopupWindow class on wxMac make it a
1169 // little easier for wxFrame to be used to emulate it and workaround
1170 // the lack of wxPopupWindow.
1171 if ( HasFlag( wxBORDER_NONE ) )
1172 wclass = kHelpWindowClass ; // has no border
1173 else
1174 wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
1175 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1176 group = GetWindowGroupOfClass( // float above other windows
1177 kFloatingWindowClass) ;
1178 }
1179 else if ( HasFlag( wxCAPTION ) )
1180 {
1181 wclass = kDocumentWindowClass ;
1182 attr |= kWindowInWindowMenuAttribute ;
1183 }
1184 else if ( HasFlag( wxFRAME_DRAWER ) )
1185 {
1186 wclass = kDrawerWindowClass;
1187 }
1188 else
1189 {
1190 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
1191 HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) )
1192 {
1193 wclass = kDocumentWindowClass ;
1194 }
1195 else if ( HasFlag( wxNO_BORDER ) )
1196 {
1197 wclass = kSimpleWindowClass ;
1198 }
1199 else
1200 {
1201 wclass = kPlainWindowClass ;
1202 }
1203 }
1204
1205 if ( wclass != kPlainWindowClass )
1206 {
1207 if ( HasFlag( wxMINIMIZE_BOX ) )
1208 attr |= kWindowCollapseBoxAttribute ;
1209
1210 if ( HasFlag( wxMAXIMIZE_BOX ) )
1211 attr |= kWindowFullZoomAttribute ;
1212
1213 if ( HasFlag( wxRESIZE_BORDER ) )
1214 attr |= kWindowResizableAttribute ;
1215
1216 if ( HasFlag( wxCLOSE_BOX) )
1217 attr |= kWindowCloseBoxAttribute ;
1218 }
1219 attr |= kWindowLiveResizeAttribute;
1220
1221 if ( HasFlag(wxSTAY_ON_TOP) )
1222 group = GetWindowGroupOfClass(kUtilityWindowClass) ;
1223
1224 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT ) )
1225 group = GetWindowGroupOfClass(kFloatingWindowClass) ;
1226
1227 if ( group == NULL && parent != NULL )
1228 {
1229 WindowRef parenttlw = (WindowRef) parent->MacGetTopLevelWindowRef();
1230 if( parenttlw )
1231 group = GetWindowGroupParent( GetWindowGroup( parenttlw ) );
1232 }
1233
1234 attr |= kWindowCompositingAttribute;
1235 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1236 attr |= kWindowFrameworkScaledAttribute;
1237 #endif
1238
1239 if ( HasFlag(wxFRAME_SHAPED) )
1240 {
1241 WindowDefSpec customWindowDefSpec;
1242 customWindowDefSpec.defType = kWindowDefProcPtr;
1243 customWindowDefSpec.u.defProc =
1244 #ifdef __LP64__
1245 (WindowDefUPP) wxShapedMacWindowDef;
1246 #else
1247 NewWindowDefUPP(wxShapedMacWindowDef);
1248 #endif
1249 err = ::CreateCustomWindow( &customWindowDefSpec, wclass,
1250 attr, &theBoundsRect,
1251 (WindowRef*) &m_macWindow);
1252 }
1253 else
1254 {
1255 err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
1256 }
1257
1258 if ( err == noErr && m_macWindow != NULL && group != NULL )
1259 SetWindowGroup( (WindowRef) m_macWindow , group ) ;
1260
1261 wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );
1262
1263 // setup a separate group for each window, so that overlays can be handled easily
1264
1265 WindowGroupRef overlaygroup = NULL;
1266 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &overlaygroup ));
1267 verify_noerr( SetWindowGroupParent( overlaygroup, GetWindowGroup( (WindowRef) m_macWindow )));
1268 verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , overlaygroup ));
1269
1270 if ( activationScopeSet )
1271 {
1272 verify_noerr( SetWindowActivationScope( (WindowRef) m_macWindow , activationScope ));
1273 }
1274
1275 // the create commands are only for content rect,
1276 // so we have to set the size again as structure bounds
1277 SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ;
1278
1279 wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ;
1280 UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ;
1281 m_peer = new wxMacControl(this , true /*isRootControl*/) ;
1282
1283 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1284 // the content view, so we have to retrieve it explicitly
1285 HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID ,
1286 m_peer->GetControlRefAddr() ) ;
1287 if ( !m_peer->Ok() )
1288 {
1289 // compatibility mode fallback
1290 GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ;
1291 }
1292
1293 // the root control level handler
1294 MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ;
1295
1296 // Causes the inner part of the window not to be metal
1297 // if the style is used before window creation.
1298 #if 0 // TARGET_API_MAC_OSX
1299 if ( m_macUsesCompositing && m_macWindow != NULL )
1300 {
1301 if ( GetExtraStyle() & wxFRAME_EX_METAL )
1302 MacSetMetalAppearance( true ) ;
1303 }
1304 #endif
1305
1306 if ( m_macWindow != NULL )
1307 {
1308 MacSetUnifiedAppearance( true ) ;
1309 }
1310
1311 HIViewRef growBoxRef = 0 ;
1312 err = HIViewFindByID( HIViewGetRoot( (WindowRef)m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef );
1313 if ( err == noErr && growBoxRef != 0 )
1314 HIGrowBoxViewSetTransparent( growBoxRef, true ) ;
1315
1316 // the frame window event handler
1317 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ;
1318 MacInstallTopLevelWindowEventHandler() ;
1319
1320 DoSetWindowVariant( m_windowVariant ) ;
1321
1322 m_macFocus = NULL ;
1323
1324 if ( HasFlag(wxFRAME_SHAPED) )
1325 {
1326 // default shape matches the window size
1327 wxRegion rgn( 0, 0, w, h );
1328 SetShape( rgn );
1329 }
1330
1331 wxWindowCreateEvent event(this);
1332 GetEventHandler()->ProcessEvent(event);
1333 }
1334
1335 void wxTopLevelWindowMac::ClearBackground()
1336 {
1337 wxWindow::ClearBackground() ;
1338 }
1339
1340 // Raise the window to the top of the Z order
1341 void wxTopLevelWindowMac::Raise()
1342 {
1343 ::SelectWindow( (WindowRef)m_macWindow ) ;
1344 }
1345
1346 // Lower the window to the bottom of the Z order
1347 void wxTopLevelWindowMac::Lower()
1348 {
1349 ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
1350 }
1351
1352 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp)
1353 {
1354 if (s_macDeactivateWindow)
1355 {
1356 wxLogTrace(TRACE_ACTIVATE,
1357 wxT("Doing delayed deactivation of %p"),
1358 s_macDeactivateWindow);
1359
1360 s_macDeactivateWindow->MacActivate(timestamp, false);
1361 }
1362 }
1363
1364 void wxTopLevelWindowMac::MacActivate( long timestamp , bool WXUNUSED(inIsActivating) )
1365 {
1366 wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this);
1367
1368 if (s_macDeactivateWindow == this)
1369 s_macDeactivateWindow = NULL;
1370
1371 MacDelayedDeactivation(timestamp);
1372 }
1373
1374 void wxTopLevelWindowMac::SetTitle(const wxString& title)
1375 {
1376 wxWindow::SetLabel( title ) ;
1377 UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ;
1378 }
1379
1380 wxString wxTopLevelWindowMac::GetTitle() const
1381 {
1382 return wxWindow::GetLabel();
1383 }
1384
1385 bool wxTopLevelWindowMac::Show(bool show)
1386 {
1387 if ( !wxTopLevelWindowBase::Show(show) )
1388 return false;
1389
1390 bool plainTransition = true;
1391
1392 #if wxUSE_SYSTEM_OPTIONS
1393 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) )
1394 plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ;
1395 #endif
1396
1397 if (show)
1398 {
1399 if ( plainTransition )
1400 ::ShowWindow( (WindowRef)m_macWindow );
1401 else
1402 ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL );
1403
1404 ::SelectWindow( (WindowRef)m_macWindow ) ;
1405
1406 // because apps expect a size event to occur at this moment
1407 wxSizeEvent event(GetSize() , m_windowId);
1408 event.SetEventObject(this);
1409 GetEventHandler()->ProcessEvent(event);
1410 }
1411 else
1412 {
1413 if ( plainTransition )
1414 ::HideWindow( (WindowRef)m_macWindow );
1415 else
1416 ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL );
1417 }
1418
1419 return true ;
1420 }
1421
1422 bool wxTopLevelWindowMac::ShowWithEffect(wxShowEffect effect,
1423 unsigned timeout,
1424 wxDirection dir)
1425 {
1426 // TODO factor common code
1427 if ( !wxTopLevelWindowBase::Show(true) )
1428 return false;
1429
1430 WindowTransitionEffect transition = 0 ;
1431 switch( effect )
1432 {
1433 case wxSHOW_EFFECT_ROLL :
1434 case wxSHOW_EFFECT_SLIDE :
1435 transition = kWindowGenieTransitionEffect;
1436 break;
1437 case wxSHOW_EFFECT_BLEND :
1438 transition = kWindowFadeTransitionEffect;
1439 break;
1440 case wxSHOW_EFFECT_EXPAND :
1441 default :
1442 // having sheets would be fine, but this might lead to a repositioning
1443 #if 0
1444 if ( GetParent() )
1445 transition = kWindowSheetTransitionEffect;
1446 else
1447 #endif
1448 transition = kWindowZoomTransitionEffect;
1449 break;
1450 }
1451
1452 TransitionWindowOptions options;
1453 options.version = 0;
1454 options.duration = timeout / 1000.0;
1455 options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) GetParent()->MacGetTopLevelWindowRef() :0;
1456 options.userData = 0;
1457
1458 wxSize size = wxGetDisplaySize();
1459 Rect bounds;
1460 GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds );
1461 CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top );
1462
1463 if ( dir & wxRIGHT )
1464 {
1465 hiBounds.origin.x = size.x;
1466 hiBounds.size.width = 0;
1467 }
1468 if ( dir & wxUP )
1469 {
1470 hiBounds.origin.y = 0;
1471 hiBounds.size.height = 0;
1472 }
1473 if ( dir & wxDOWN )
1474 {
1475 hiBounds.origin.y = size.y;
1476 hiBounds.size.height = 0;
1477 }
1478 if ( dir & wxLEFT )
1479 {
1480 hiBounds.origin.x = 0;
1481 hiBounds.size.width = 0;
1482 }
1483
1484 ::TransitionWindowWithOptions( (WindowRef)m_macWindow, transition, kWindowShowTransitionAction, transition == kWindowGenieTransitionEffect ? &hiBounds : NULL ,
1485 false, &options );
1486
1487 ::SelectWindow( (WindowRef)m_macWindow ) ;
1488
1489 // because apps expect a size event to occur at this moment
1490 wxSizeEvent event(GetSize() , m_windowId);
1491 event.SetEventObject(this);
1492 GetEventHandler()->ProcessEvent(event);
1493
1494 return true;
1495 }
1496
1497 bool wxTopLevelWindowMac::HideWithEffect(wxShowEffect effect,
1498 unsigned timeout ,
1499 wxDirection dir )
1500 {
1501 if ( !wxTopLevelWindowBase::Show(false) )
1502 return false;
1503
1504 WindowTransitionEffect transition = 0 ;
1505 switch( effect )
1506 {
1507 case wxSHOW_EFFECT_ROLL :
1508 case wxSHOW_EFFECT_SLIDE :
1509 transition = kWindowGenieTransitionEffect;
1510 break;
1511 case wxSHOW_EFFECT_BLEND :
1512 transition = kWindowFadeTransitionEffect;
1513 break;
1514 case wxSHOW_EFFECT_EXPAND :
1515 default:
1516 #if 0
1517 if ( GetParent() )
1518 transition = kWindowSheetTransitionEffect;
1519 else
1520 #endif
1521 transition = kWindowZoomTransitionEffect;
1522 break;
1523 }
1524 TransitionWindowOptions options;
1525 options.version = 0;
1526 options.duration = timeout / 1000.0;
1527 options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) GetParent()->MacGetTopLevelWindowRef() :0;
1528 options.userData = 0;
1529
1530 wxSize size = wxGetDisplaySize();
1531 Rect bounds;
1532 GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds );
1533 CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top );
1534
1535 if ( dir & wxRIGHT )
1536 {
1537 hiBounds.origin.x = size.x;
1538 hiBounds.size.width = 0;
1539 }
1540 if ( dir & wxUP )
1541 {
1542 hiBounds.origin.y = 0;
1543 hiBounds.size.height = 0;
1544 }
1545 if ( dir & wxDOWN )
1546 {
1547 hiBounds.origin.y = size.y;
1548 hiBounds.size.height = 0;
1549 }
1550 if ( dir & wxLEFT )
1551 {
1552 hiBounds.origin.x = 0;
1553 hiBounds.size.width = 0;
1554 }
1555 ::TransitionWindowWithOptions( (WindowRef)m_macWindow, transition, kWindowHideTransitionAction, transition == kWindowGenieTransitionEffect ? &hiBounds : NULL ,
1556 false, &options );
1557
1558 return true;
1559 }
1560
1561 bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style)
1562 {
1563 if ( show )
1564 {
1565 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
1566 delete data ;
1567 data = new FullScreenData() ;
1568
1569 m_macFullScreenData = data ;
1570 data->m_position = GetPosition() ;
1571 data->m_size = GetSize() ;
1572 data->m_wasResizable = MacGetWindowAttributes() & kWindowResizableAttribute ;
1573
1574 if ( style & wxFULLSCREEN_NOMENUBAR )
1575 HideMenuBar() ;
1576
1577 wxRect client = wxGetClientDisplayRect() ;
1578
1579 int left , top , right , bottom ;
1580 int x, y, w, h ;
1581
1582 x = client.x ;
1583 y = client.y ;
1584 w = client.width ;
1585 h = client.height ;
1586
1587 MacGetContentAreaInset( left , top , right , bottom ) ;
1588
1589 if ( style & wxFULLSCREEN_NOCAPTION )
1590 {
1591 y -= top ;
1592 h += top ;
1593 }
1594
1595 if ( style & wxFULLSCREEN_NOBORDER )
1596 {
1597 x -= left ;
1598 w += left + right ;
1599 h += bottom ;
1600 }
1601
1602 if ( style & wxFULLSCREEN_NOTOOLBAR )
1603 {
1604 // TODO
1605 }
1606
1607 if ( style & wxFULLSCREEN_NOSTATUSBAR )
1608 {
1609 // TODO
1610 }
1611
1612 SetSize( x , y , w, h ) ;
1613 if ( data->m_wasResizable )
1614 MacChangeWindowAttributes( kWindowNoAttributes , kWindowResizableAttribute ) ;
1615 }
1616 else
1617 {
1618 ShowMenuBar() ;
1619 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
1620 if ( data->m_wasResizable )
1621 MacChangeWindowAttributes( kWindowResizableAttribute , kWindowNoAttributes ) ;
1622 SetPosition( data->m_position ) ;
1623 SetSize( data->m_size ) ;
1624
1625 delete data ;
1626 m_macFullScreenData = NULL ;
1627 }
1628
1629 return false;
1630 }
1631
1632 bool wxTopLevelWindowMac::IsFullScreen() const
1633 {
1634 return m_macFullScreenData != NULL ;
1635 }
1636
1637
1638 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha)
1639 {
1640 OSStatus result = SetWindowAlpha((WindowRef)m_macWindow, float(alpha)/255.0);
1641 return result == noErr;
1642 }
1643
1644
1645 bool wxTopLevelWindowMac::CanSetTransparent()
1646 {
1647 return true;
1648 }
1649
1650
1651 void wxTopLevelWindowMac::SetExtraStyle(long exStyle)
1652 {
1653 if ( GetExtraStyle() == exStyle )
1654 return ;
1655
1656 wxTopLevelWindowBase::SetExtraStyle( exStyle ) ;
1657
1658 if ( m_macWindow != NULL )
1659 {
1660 bool metal = GetExtraStyle() & wxFRAME_EX_METAL ;
1661
1662 if ( MacGetMetalAppearance() != metal )
1663 {
1664 if ( MacGetUnifiedAppearance() )
1665 MacSetUnifiedAppearance( !metal ) ;
1666
1667 MacSetMetalAppearance( metal ) ;
1668 }
1669 }
1670 }
1671
1672 bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style)
1673 {
1674 if ( !wxTopLevelWindowBase::SetBackgroundStyle(style) )
1675 return false ;
1676
1677 WindowRef windowRef = HIViewGetWindow( (HIViewRef)GetHandle() );
1678
1679 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1680 {
1681 OSStatus err = HIWindowChangeFeatures( windowRef, 0, kWindowIsOpaque );
1682 verify_noerr( err );
1683 err = ReshapeCustomWindow( windowRef );
1684 verify_noerr( err );
1685 }
1686
1687 return true ;
1688 }
1689
1690 // TODO: switch to structure bounds -
1691 // we are still using coordinates of the content view
1692 //
1693 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1694 {
1695 Rect content, structure ;
1696
1697 GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ;
1698 GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ;
1699
1700 left = content.left - structure.left ;
1701 top = content.top - structure.top ;
1702 right = structure.right - content.right ;
1703 bottom = structure.bottom - content.bottom ;
1704 }
1705
1706 void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
1707 {
1708 m_cachedClippedRectValid = false ;
1709 Rect bounds = { y , x , y + height , x + width } ;
1710 verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1711 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1712 }
1713
1714 void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const
1715 {
1716 Rect bounds ;
1717
1718 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1719
1720 if (x)
1721 *x = bounds.left ;
1722 if (y)
1723 *y = bounds.top ;
1724 }
1725
1726 void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const
1727 {
1728 Rect bounds ;
1729
1730 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1731
1732 if (width)
1733 *width = bounds.right - bounds.left ;
1734 if (height)
1735 *height = bounds.bottom - bounds.top ;
1736 }
1737
1738 void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const
1739 {
1740 Rect bounds ;
1741
1742 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ;
1743
1744 if (width)
1745 *width = bounds.right - bounds.left ;
1746 if (height)
1747 *height = bounds.bottom - bounds.top ;
1748 }
1749
1750 void wxTopLevelWindowMac::DoCentre(int dir)
1751 {
1752 if ( m_macWindow != 0 )
1753 wxTopLevelWindowBase::DoCentre(dir);
1754 }
1755
1756 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set )
1757 {
1758 if ( MacGetUnifiedAppearance() )
1759 MacSetUnifiedAppearance( false ) ;
1760
1761 MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes ,
1762 set ? kWindowNoAttributes : kWindowMetalAttribute ) ;
1763 }
1764
1765 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1766 {
1767 return MacGetWindowAttributes() & kWindowMetalAttribute ;
1768 }
1769
1770 void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set )
1771 {
1772 if ( MacGetMetalAppearance() )
1773 MacSetMetalAppearance( false ) ;
1774
1775 MacChangeWindowAttributes( set ? kWindowUnifiedTitleAndToolbarAttribute : kWindowNoAttributes ,
1776 set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ;
1777
1778 // For some reason, Tiger uses white as the background color for this appearance,
1779 // while most apps using it use the typical striped background. Restore that behavior
1780 // for wx.
1781 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1782 // though)
1783 SetBackgroundColour( wxSYS_COLOUR_WINDOW ) ;
1784 }
1785
1786 bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
1787 {
1788 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ;
1789 }
1790
1791 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear )
1792 {
1793 ChangeWindowAttributes( (WindowRef)m_macWindow, attributesToSet, attributesToClear ) ;
1794 }
1795
1796 wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const
1797 {
1798 UInt32 attr = 0 ;
1799 GetWindowAttributes( (WindowRef) m_macWindow, &attr ) ;
1800
1801 return attr ;
1802 }
1803
1804 void wxTopLevelWindowMac::MacPerformUpdates()
1805 {
1806 // for composited windows this also triggers a redraw of all
1807 // invalid views in the window
1808 HIWindowFlush((WindowRef) m_macWindow) ;
1809 }
1810
1811 // Attracts the users attention to this window if the application is
1812 // inactive (should be called when a background event occurs)
1813
1814 static pascal void wxMacNMResponse( NMRecPtr ptr )
1815 {
1816 NMRemove( ptr ) ;
1817 DisposePtr( (Ptr)ptr ) ;
1818 }
1819
1820 void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags))
1821 {
1822 NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ;
1823 static wxMacNMUPP nmupp( wxMacNMResponse );
1824
1825 memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ;
1826 notificationRequest->qType = nmType ;
1827 notificationRequest->nmMark = 1 ;
1828 notificationRequest->nmIcon = 0 ;
1829 notificationRequest->nmSound = 0 ;
1830 notificationRequest->nmStr = NULL ;
1831 notificationRequest->nmResp = nmupp ;
1832
1833 verify_noerr( NMInstall( notificationRequest ) ) ;
1834 }
1835
1836 // ---------------------------------------------------------------------------
1837 // Shape implementation
1838 // ---------------------------------------------------------------------------
1839
1840
1841 bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
1842 {
1843 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
1844 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1845
1846 // The empty region signifies that the shape
1847 // should be removed from the window.
1848 if ( region.IsEmpty() )
1849 {
1850 wxSize sz = GetClientSize();
1851 wxRegion rgn(0, 0, sz.x, sz.y);
1852 if ( rgn.IsEmpty() )
1853 return false ;
1854 else
1855 return SetShape(rgn);
1856 }
1857
1858 // Make a copy of the region
1859 RgnHandle shapeRegion = NewRgn();
1860 CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion );
1861
1862 // Dispose of any shape region we may already have
1863 RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() );
1864 if ( oldRgn )
1865 DisposeRgn(oldRgn);
1866
1867 // Save the region so we can use it later
1868 SetWRefCon((WindowRef)MacGetWindowRef(), (URefCon)shapeRegion);
1869
1870 // inform the window manager that the window has changed shape
1871 ReshapeCustomWindow((WindowRef)MacGetWindowRef());
1872
1873 return true;
1874 }
1875
1876 // ---------------------------------------------------------------------------
1877 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1878 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1879 // ---------------------------------------------------------------------------
1880
1881 static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect)
1882 {
1883 GetWindowPortBounds(window, inRect);
1884 Point pt = { inRect->top ,inRect->left };
1885 wxMacLocalToGlobal( window, &pt ) ;
1886 inRect->bottom += pt.v - inRect->top;
1887 inRect->right += pt.h - inRect->left;
1888 inRect->top = pt.v;
1889 inRect->left = pt.h;
1890 }
1891
1892 static SInt32 wxShapedMacWindowGetFeatures(WindowRef WXUNUSED(window), SInt32 param)
1893 {
1894 /*------------------------------------------------------
1895 Define which options your custom window supports.
1896 --------------------------------------------------------*/
1897 //just enable everything for our demo
1898 *(OptionBits*)param =
1899 //kWindowCanGrow |
1900 //kWindowCanZoom |
1901 //kWindowCanCollapse |
1902 //kWindowCanGetWindowRegion |
1903 //kWindowHasTitleBar |
1904 //kWindowSupportsDragHilite |
1905 kWindowCanDrawInCurrentPort |
1906 //kWindowCanMeasureTitle |
1907 kWindowWantsDisposeAtProcessDeath |
1908 kWindowSupportsGetGrowImageRegion |
1909 kWindowDefSupportsColorGrafPort;
1910
1911 return 1;
1912 }
1913
1914 // The content region is left as a rectangle matching the window size, this is
1915 // so the origin in the paint event, and etc. still matches what the
1916 // programmer expects.
1917 static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn)
1918 {
1919 SetEmptyRgn(rgn);
1920 wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window);
1921 if (win)
1922 {
1923 Rect r ;
1924 wxShapedMacWindowGetPos( window, &r ) ;
1925 RectRgn( rgn , &r ) ;
1926 }
1927 }
1928
1929 // The structure region is set to the shape given to the SetShape method.
1930 static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn)
1931 {
1932 RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window);
1933
1934 SetEmptyRgn(rgn);
1935 if (cachedRegion)
1936 {
1937 Rect windowRect;
1938 wxShapedMacWindowGetPos(window, &windowRect); // how big is the window
1939 CopyRgn(cachedRegion, rgn); // make a copy of our cached region
1940 OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window
1941 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1942 }
1943 }
1944
1945 static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param)
1946 {
1947 GetWindowRegionPtr rgnRec = (GetWindowRegionPtr)param;
1948
1949 if (rgnRec == NULL)
1950 return paramErr;
1951
1952 switch (rgnRec->regionCode)
1953 {
1954 case kWindowStructureRgn:
1955 wxShapedMacWindowStructureRegion(window, rgnRec->winRgn);
1956 break;
1957
1958 case kWindowContentRgn:
1959 wxShapedMacWindowContentRegion(window, rgnRec->winRgn);
1960 break;
1961
1962 default:
1963 SetEmptyRgn(rgnRec->winRgn);
1964 break;
1965 }
1966
1967 return noErr;
1968 }
1969
1970 // Determine the region of the window which was hit
1971 //
1972 static SInt32 wxShapedMacWindowHitTest(WindowRef window, SInt32 param)
1973 {
1974 Point hitPoint;
1975 static RgnHandle tempRgn = NULL;
1976
1977 if (tempRgn == NULL)
1978 tempRgn = NewRgn();
1979
1980 // get the point clicked
1981 SetPt( &hitPoint, LoWord(param), HiWord(param) );
1982
1983 // Mac OS 8.5 or later
1984 wxShapedMacWindowStructureRegion(window, tempRgn);
1985 if (PtInRgn( hitPoint, tempRgn )) //in window content region?
1986 return wInContent;
1987
1988 // no significant area was hit
1989 return wNoHit;
1990 }
1991
1992 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode), WindowRef window, SInt16 message, SInt32 param)
1993 {
1994 switch (message)
1995 {
1996 case kWindowMsgHitTest:
1997 return wxShapedMacWindowHitTest(window, param);
1998
1999 case kWindowMsgGetFeatures:
2000 return wxShapedMacWindowGetFeatures(window, param);
2001
2002 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
2003 case kWindowMsgGetRegion:
2004 return wxShapedMacWindowGetRegion(window, param);
2005
2006 default:
2007 break;
2008 }
2009
2010 return 0;
2011 }