]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/toplevel.cpp
9f15a883d92ee24aca7d858f35cecd334f50526f
[wxWidgets.git] / src / mac / carbon / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/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 #ifdef __GNUG__
21 #pragma implementation "toplevel.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/app.h"
33 #include "wx/toplevel.h"
34 #include "wx/frame.h"
35 #include "wx/string.h"
36 #include "wx/log.h"
37 #include "wx/intl.h"
38 #endif //WX_PRECOMP
39
40 #include "wx/mac/uma.h"
41 #include "wx/mac/aga.h"
42 #include "wx/app.h"
43 #include "wx/tooltip.h"
44 #include "wx/dnd.h"
45 #if wxUSE_SYSTEM_OPTIONS
46 #include "wx/sysopt.h"
47 #endif
48
49 #include <ToolUtils.h>
50
51 // ----------------------------------------------------------------------------
52 // globals
53 // ----------------------------------------------------------------------------
54
55 // list of all frames and modeless dialogs
56 wxWindowList wxModelessWindows;
57
58 static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param);
59
60 // ============================================================================
61 // wxTopLevelWindowMac implementation
62 // ============================================================================
63
64 BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase)
65 END_EVENT_TABLE()
66
67
68 // ---------------------------------------------------------------------------
69 // Carbon Events
70 // ---------------------------------------------------------------------------
71
72 extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
73
74 static const EventTypeSpec eventList[] =
75 {
76 // TODO remove control related event like key and mouse (except for WindowLeave events)
77 #if 1
78 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
79
80 { kEventClassKeyboard, kEventRawKeyDown } ,
81 { kEventClassKeyboard, kEventRawKeyRepeat } ,
82 { kEventClassKeyboard, kEventRawKeyUp } ,
83 { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
84 #endif
85
86 { kEventClassWindow , kEventWindowShown } ,
87 { kEventClassWindow , kEventWindowActivated } ,
88 { kEventClassWindow , kEventWindowDeactivated } ,
89 { kEventClassWindow , kEventWindowBoundsChanging } ,
90 { kEventClassWindow , kEventWindowBoundsChanged } ,
91 { kEventClassWindow , kEventWindowClose } ,
92
93 // we have to catch these events on the toplevel window level, as controls don't get the
94 // raw mouse events anymore
95
96 { kEventClassMouse , kEventMouseDown } ,
97 { kEventClassMouse , kEventMouseUp } ,
98 { kEventClassMouse , kEventMouseWheelMoved } ,
99 { kEventClassMouse , kEventMouseMoved } ,
100 { kEventClassMouse , kEventMouseDragged } ,
101 } ;
102
103 static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
104 {
105 OSStatus result = eventNotHandledErr ;
106
107 wxWindow* focus = wxWindow::FindFocus() ;
108 char charCode ;
109 UInt32 keyCode ;
110 UInt32 modifiers ;
111 Point point ;
112
113 EventRef rawEvent ;
114
115 GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
116
117 GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
118 GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
119 GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
120 GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL,
121 sizeof( Point ), NULL, &point );
122
123 switch ( GetEventKind( event ) )
124 {
125 case kEventTextInputUnicodeForKeyEvent :
126 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
127 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
128 wxControl* control = wxDynamicCast( focus , wxControl ) ;
129 if ( control )
130 {
131 ControlRef macControl = (ControlRef) control->GetHandle() ;
132 if ( macControl )
133 {
134 ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ;
135 result = noErr ;
136 }
137 }
138 /*
139 // this may lead to double events sent to a window in case all handlers have skipped the key down event
140 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
141 UInt32 message = (keyCode << 8) + charCode;
142
143 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
144 focus , message , modifiers , when , point.h , point.v ) )
145 {
146 result = noErr ;
147 }
148 */
149 break ;
150 }
151
152 return result ;
153 }
154
155 static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
156 {
157 OSStatus result = eventNotHandledErr ;
158
159 wxWindow* focus = wxWindow::FindFocus() ;
160 char charCode ;
161 UInt32 keyCode ;
162 UInt32 modifiers ;
163 Point point ;
164 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
165
166 GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
167 GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
168 GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
169 GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
170 sizeof( Point ), NULL, &point );
171
172 UInt32 message = (keyCode << 8) + charCode;
173 switch( GetEventKind( event ) )
174 {
175 case kEventRawKeyRepeat :
176 case kEventRawKeyDown :
177 {
178 WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
179 WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
180 wxTheApp->MacSetCurrentEvent( event , handler ) ;
181 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
182 focus , message , modifiers , when , point.h , point.v ) )
183 {
184 result = noErr ;
185 }
186 wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
187 }
188 break ;
189 case kEventRawKeyUp :
190 if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent(
191 focus , message , modifiers , when , point.h , point.v ) )
192 {
193 result = noErr ;
194 }
195 break ;
196 case kEventRawKeyModifiersChanged :
197 {
198 wxKeyEvent event(wxEVT_KEY_DOWN);
199
200 event.m_shiftDown = modifiers & shiftKey;
201 event.m_controlDown = modifiers & controlKey;
202 event.m_altDown = modifiers & optionKey;
203 event.m_metaDown = modifiers & cmdKey;
204
205 event.m_x = point.h;
206 event.m_y = point.v;
207 event.m_timeStamp = when;
208 wxWindow* focus = wxWindow::FindFocus() ;
209 event.SetEventObject(focus);
210
211 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey )
212 {
213 event.m_keyCode = WXK_CONTROL ;
214 event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
215 focus->GetEventHandler()->ProcessEvent( event ) ;
216 }
217 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey )
218 {
219 event.m_keyCode = WXK_SHIFT ;
220 event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
221 focus->GetEventHandler()->ProcessEvent( event ) ;
222 }
223 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey )
224 {
225 event.m_keyCode = WXK_ALT ;
226 event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
227 focus->GetEventHandler()->ProcessEvent( event ) ;
228 }
229 if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & cmdKey )
230 {
231 event.m_keyCode = WXK_COMMAND ;
232 event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
233 focus->GetEventHandler()->ProcessEvent( event ) ;
234 }
235 wxTheApp->s_lastModifiers = modifiers ;
236 }
237 break ;
238 }
239
240 return result ;
241 }
242
243 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
244 // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the
245 // mouse down at all
246
247 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
248
249 wxWindow* g_MacLastWindow = NULL ;
250
251 static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent )
252 {
253 UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ;
254 Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
255
256 // this parameter are not given for all events
257 EventMouseButton button = 0 ;
258 UInt32 clickCount = 0 ;
259 cEvent.GetParameter<EventMouseButton>(kEventParamMouseButton, typeMouseButton , &button) ;
260 cEvent.GetParameter<UInt32>(kEventParamClickCount, typeUInt32 , &clickCount ) ;
261
262 wxevent.m_x = screenMouseLocation.h;
263 wxevent.m_y = screenMouseLocation.v;
264 wxevent.m_shiftDown = modifiers & shiftKey;
265 wxevent.m_controlDown = modifiers & controlKey;
266 wxevent.m_altDown = modifiers & optionKey;
267 wxevent.m_metaDown = modifiers & cmdKey;
268 wxevent.SetTimestamp( cEvent.GetTicks() ) ;
269 // a control click is interpreted as a right click
270 if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
271 {
272 button = kEventMouseButtonSecondary ;
273 }
274
275 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
276 // this button
277 if ( button != 0 && cEvent.GetKind() != kEventMouseUp )
278 {
279 switch( button )
280 {
281 case kEventMouseButtonPrimary :
282 wxevent.m_leftDown = true ;
283 break ;
284 case kEventMouseButtonSecondary :
285 wxevent.m_rightDown = true ;
286 break ;
287 case kEventMouseButtonTertiary :
288 wxevent.m_middleDown = true ;
289 break ;
290 }
291 }
292 // determinate the correct click button
293 if ( button == kEventMouseButtonSecondary )
294 {
295 if (cEvent.GetKind() == kEventMouseDown )
296 wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DOWN : wxEVT_RIGHT_DCLICK ) ;
297 else if ( cEvent.GetKind() == kEventMouseUp )
298 wxevent.SetEventType(wxEVT_RIGHT_UP ) ;
299 }
300 else if ( button == kEventMouseButtonTertiary )
301 {
302 if (cEvent.GetKind() == kEventMouseDown )
303 wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
304 else if ( cEvent.GetKind() == kEventMouseUp )
305 wxevent.SetEventType(wxEVT_MIDDLE_UP ) ;
306 }
307 else
308 {
309 if (cEvent.GetKind() == kEventMouseDown )
310 wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
311 else if ( cEvent.GetKind() == kEventMouseUp )
312 wxevent.SetEventType(wxEVT_LEFT_UP ) ;
313 else if ( cEvent.GetKind() == kEventMouseWheelMoved )
314 {
315 wxevent.SetEventType(wxEVT_MOUSEWHEEL ) ;
316
317 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
318 SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeLongInteger) ;
319
320 wxevent.m_wheelRotation = delta;
321 wxevent.m_wheelDelta = 1;
322 wxevent.m_linesPerAction = 1;
323 }
324 else
325 wxevent.SetEventType(wxEVT_MOTION ) ;
326 }
327 }
328
329 ControlRef wxMacFindSubControl( Point location , ControlRef superControl , ControlPartCode *outPart )
330 {
331 if ( superControl )
332 {
333 UInt16 childrenCount = 0 ;
334 OSStatus err = CountSubControls( superControl , &childrenCount ) ;
335 if ( err == errControlIsNotEmbedder )
336 return NULL ;
337 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
338
339 for ( UInt16 i = childrenCount ; i >=1 ; --i )
340 {
341 ControlHandle sibling ;
342 err = GetIndexedSubControl( superControl , i , & sibling ) ;
343 if ( err == errControlIsNotEmbedder )
344 return NULL ;
345
346 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
347 if ( IsControlVisible( sibling ) )
348 {
349 Rect r ;
350 GetControlBounds( sibling , &r ) ;
351 if ( MacPtInRect( location , &r ) )
352 {
353 ControlHandle child = wxMacFindSubControl( location , sibling , outPart ) ;
354 if ( child )
355 return child ;
356 else
357 {
358 *outPart = TestControl( sibling , location ) ;
359 return sibling ;
360 }
361 }
362 }
363 }
364 }
365 return NULL ;
366 }
367
368 ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart )
369 {
370 #if TARGET_API_MAC_OSX
371 return FindControlUnderMouse( location , window , outPart ) ;
372 #else
373 ControlRef rootControl = NULL ;
374 verify_noerr( GetRootControl( window , &rootControl ) ) ;
375 return wxMacFindSubControl( location , rootControl , outPart ) ;
376 #endif
377 }
378 pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
379 {
380
381 OSStatus result = eventNotHandledErr ;
382
383 wxMacCarbonEvent cEvent( event ) ;
384
385 Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
386 Point windowMouseLocation = screenMouseLocation ;
387
388 WindowRef window ;
389 short windowPart = ::FindWindow(screenMouseLocation, &window);
390
391 wxWindow* currentMouseWindow = NULL ;
392 if ( window )
393 {
394 // calculate window relative coordinates
395 GrafPtr port;
396 ::GetPort( &port ) ;
397 ::SetPort( UMAGetWindowPort(window ) ) ;
398 ::GlobalToLocal( &windowMouseLocation ) ;
399 ::SetPort( port ) ;
400
401 if ( wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent )
402 {
403 currentMouseWindow = wxTheApp->s_captureWindow ;
404 }
405 else if ( (IsWindowActive(window) && windowPart == inContent) )
406 {
407 ControlPartCode part ;
408 ControlRef control = wxMacFindControlUnderMouse( windowMouseLocation , window , &part ) ;
409 if ( control == 0 )
410 currentMouseWindow = (wxWindow*) data ;
411 else
412 currentMouseWindow = wxFindControlFromMacControl( control ) ;
413 }
414 }
415
416 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
417 SetupMouseEvent( wxevent , cEvent ) ;
418
419 // handle all enter / leave events
420
421 if ( currentMouseWindow != g_MacLastWindow )
422 {
423 if ( g_MacLastWindow )
424 {
425 wxMouseEvent eventleave(wxevent);
426 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
427 g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
428 eventleave.SetEventObject( g_MacLastWindow ) ;
429
430 #if wxUSE_TOOLTIPS
431 wxToolTip::RelayEvent( g_MacLastWindow , eventleave);
432 #endif // wxUSE_TOOLTIPS
433 g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave);
434 }
435 if ( currentMouseWindow )
436 {
437 wxMouseEvent evententer(wxevent);
438 evententer.SetEventType( wxEVT_ENTER_WINDOW );
439 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
440 evententer.SetEventObject( currentMouseWindow ) ;
441 #if wxUSE_TOOLTIPS
442 wxToolTip::RelayEvent( currentMouseWindow , evententer);
443 #endif // wxUSE_TOOLTIPS
444 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
445 }
446 g_MacLastWindow = currentMouseWindow ;
447 }
448
449 if ( windowPart == inMenuBar )
450 {
451 // special case menu bar, as we are having a low-level runloop we must do it ourselves
452 if ( cEvent.GetKind() == kEventMouseDown )
453 {
454 ::MenuSelect( screenMouseLocation ) ;
455 result = noErr ;
456 }
457 } // if ( windowPart == inMenuBar )
458 else if ( currentMouseWindow )
459 {
460 currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
461
462 wxevent.SetEventObject( currentMouseWindow ) ;
463
464 // update cursor
465
466 wxWindow* cursorTarget = currentMouseWindow ;
467 wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ;
468
469 while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
470 {
471 cursorTarget = cursorTarget->GetParent() ;
472 if ( cursorTarget )
473 cursorPoint += cursorTarget->GetPosition() ;
474 }
475
476 // update focus
477
478 if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN )
479 {
480 // set focus to this window
481 if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow)
482 currentMouseWindow->SetFocus();
483 }
484
485 // make tooltips current
486
487 #if wxUSE_TOOLTIPS
488 if ( wxevent.GetEventType() == wxEVT_MOTION
489 || wxevent.GetEventType() == wxEVT_ENTER_WINDOW
490 || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW )
491 wxToolTip::RelayEvent( currentMouseWindow , wxevent);
492 #endif // wxUSE_TOOLTIPS
493 if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) )
494 result = noErr;
495 if ( cEvent.GetKind() == kEventMouseUp && wxTheApp->s_captureWindow )
496 {
497 wxTheApp->s_captureWindow = NULL ;
498 // update cursor ?
499 }
500 } // else if ( currentMouseWindow )
501 return result ;
502 }
503
504 static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
505 {
506 OSStatus result = eventNotHandledErr ;
507
508 wxMacCarbonEvent cEvent( event ) ;
509
510 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
511 wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
512
513 switch( GetEventKind( event ) )
514 {
515 case kEventWindowActivated :
516 {
517 toplevelWindow->MacActivate( cEvent.GetTicks() , true) ;
518 wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId());
519 wxevent.SetTimestamp( cEvent.GetTicks() ) ;
520 wxevent.SetEventObject(toplevelWindow);
521 toplevelWindow->GetEventHandler()->ProcessEvent(wxevent);
522 // we still sending an eventNotHandledErr in order to allow for default processing
523 break ;
524 }
525 case kEventWindowDeactivated :
526 {
527 toplevelWindow->MacActivate(cEvent.GetTicks() , false) ;
528 wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId());
529 wxevent.SetTimestamp( cEvent.GetTicks() ) ;
530 wxevent.SetEventObject(toplevelWindow);
531 toplevelWindow->GetEventHandler()->ProcessEvent(wxevent);
532 // we still sending an eventNotHandledErr in order to allow for default processing
533 break ;
534 }
535 case kEventWindowShown :
536 toplevelWindow->Refresh() ;
537 result = noErr ;
538 break ;
539 case kEventWindowClose :
540 toplevelWindow->Close() ;
541 result = noErr ;
542 break ;
543 case kEventWindowBoundsChanged :
544 {
545 UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ;
546 Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
547 wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ;
548 if ( attributes & kWindowBoundsChangeSizeChanged )
549 {
550 // according to the other ports we handle this within the OS level
551 // resize event, not within a wxSizeEvent
552 wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ;
553 if ( frame )
554 {
555 #if wxUSE_STATUSBAR
556 frame->PositionStatusBar();
557 #endif
558 #if wxUSE_TOOLBAR
559 frame->PositionToolBar();
560 #endif
561 }
562
563 wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ;
564 event.SetEventObject( toplevelWindow ) ;
565
566 toplevelWindow->GetEventHandler()->ProcessEvent(event) ;
567 }
568 if ( attributes & kWindowBoundsChangeOriginChanged )
569 {
570 wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ;
571 event.SetEventObject( toplevelWindow ) ;
572 toplevelWindow->GetEventHandler()->ProcessEvent(event) ;
573 }
574 result = noErr ;
575 break ;
576 }
577 case kEventWindowBoundsChanging :
578 {
579 UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ;
580 Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
581 wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ;
582
583 if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) )
584 {
585 // this is a EVT_SIZING not a EVT_SIZE type !
586 wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ;
587 wxevent.SetEventObject( toplevelWindow ) ;
588 wxRect adjustR = r ;
589 if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) )
590 {
591 adjustR = wxevent.GetRect() ;
592 }
593 if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() )
594 adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ;
595 if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() )
596 adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ;
597 if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() )
598 adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ;
599 if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() )
600 adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ;
601 Rect adjustedRect = { adjustR.y , adjustR.x , adjustR.y + adjustR.height , adjustR.x + adjustR.width } ;
602 if ( !EqualRect( &newRect , &adjustedRect ) )
603 cEvent.SetParameter( kEventParamCurrentBounds , &adjustedRect ) ;
604 }
605
606 result = noErr ;
607 break ;
608 }
609 default :
610 break ;
611 }
612 return result ;
613 }
614
615 pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
616 {
617 OSStatus result = eventNotHandledErr ;
618
619 switch ( GetEventClass( event ) )
620 {
621 case kEventClassKeyboard :
622 result = KeyboardEventHandler( handler, event , data ) ;
623 break ;
624 case kEventClassTextInput :
625 result = TextInputEventHandler( handler, event , data ) ;
626 break ;
627 case kEventClassWindow :
628 result = wxMacTopLevelWindowEventHandler( handler, event , data ) ;
629 break ;
630 case kEventClassMouse :
631 result = wxMacTopLevelMouseEventHandler( handler, event , data ) ;
632 break ;
633 default :
634 break ;
635 }
636 return result ;
637 }
638
639 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler )
640
641 // ---------------------------------------------------------------------------
642 // wxWindowMac utility functions
643 // ---------------------------------------------------------------------------
644
645 // Find an item given the Macintosh Window Reference
646
647 wxList wxWinMacWindowList(wxKEY_INTEGER);
648 wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
649 {
650 wxNode *node = wxWinMacWindowList.Find((long)inWindowRef);
651 if (!node)
652 return NULL;
653 return (wxTopLevelWindowMac *)node->GetData();
654 }
655
656 void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ;
657 void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win)
658 {
659 // adding NULL WindowRef is (first) surely a result of an error and
660 // (secondly) breaks menu command processing
661 wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
662
663 if ( !wxWinMacWindowList.Find((long)inWindowRef) )
664 wxWinMacWindowList.Append((long)inWindowRef, win);
665 }
666
667 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ;
668 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
669 {
670 wxWinMacWindowList.DeleteObject(win);
671 }
672
673
674 // ----------------------------------------------------------------------------
675 // wxTopLevelWindowMac creation
676 // ----------------------------------------------------------------------------
677
678 wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL;
679
680 void wxTopLevelWindowMac::Init()
681 {
682 m_iconized =
683 m_maximizeOnShow = FALSE;
684 m_macWindow = NULL ;
685 #if TARGET_API_MAC_OSX
686 m_macUsesCompositing = TRUE;
687 #else
688 m_macUsesCompositing = FALSE;
689 #endif
690 m_macEventHandler = NULL ;
691 }
692
693 class wxMacDeferredWindowDeleter : public wxObject
694 {
695 public :
696 wxMacDeferredWindowDeleter( WindowRef windowRef )
697 {
698 m_macWindow = windowRef ;
699 }
700 virtual ~wxMacDeferredWindowDeleter()
701 {
702 UMADisposeWindow( (WindowRef) m_macWindow ) ;
703 }
704 protected :
705 WindowRef m_macWindow ;
706 } ;
707
708 bool wxTopLevelWindowMac::Create(wxWindow *parent,
709 wxWindowID id,
710 const wxString& title,
711 const wxPoint& pos,
712 const wxSize& size,
713 long style,
714 const wxString& name)
715 {
716 // init our fields
717 Init();
718
719 m_windowStyle = style;
720
721 SetName(name);
722
723 m_windowId = id == -1 ? NewControlId() : id;
724
725 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
726
727 wxTopLevelWindows.Append(this);
728
729 if ( parent )
730 parent->AddChild(this);
731
732 return TRUE;
733 }
734
735 wxTopLevelWindowMac::~wxTopLevelWindowMac()
736 {
737 if ( m_macWindow )
738 {
739 wxToolTip::NotifyWindowDelete(m_macWindow) ;
740 wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ;
741 }
742
743 if ( m_macEventHandler )
744 {
745 ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);
746 m_macEventHandler = NULL ;
747 }
748
749 wxRemoveMacWindowAssociation( this ) ;
750
751 if ( wxModelessWindows.Find(this) )
752 wxModelessWindows.DeleteObject(this);
753 }
754
755
756 // ----------------------------------------------------------------------------
757 // wxTopLevelWindowMac maximize/minimize
758 // ----------------------------------------------------------------------------
759
760 void wxTopLevelWindowMac::Maximize(bool maximize)
761 {
762 wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ;
763 wxMacWindowClipper clip (this);
764 ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ;
765 /*
766 Rect r ;
767 GDHandle device = NULL ;
768 verify_noerr( GetWindowGreatestAreaDevice( (WindowRef) m_macWindow , kWindowContentRgn ,
769 &device , NULL ) ;
770 verify_noerr( GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ) ;
771
772 Rect tempRect ;
773 GrafPtr port ;
774 GetPort( &port ) ;
775 Point pt = { 0, 0 } ;
776 SetPortWindowPort((WindowRef)m_macWindow) ;
777 LocalToGlobal( &pt ) ;
778 SetPort( port ) ;
779
780 GetWindowPortBounds((WindowRef)m_macWindow, &tempRect ) ;
781 SetSize( pt.h , pt.v , tempRect.right-tempRect.left ,
782 tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING);
783 */
784 }
785
786 bool wxTopLevelWindowMac::IsMaximized() const
787 {
788 return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ;
789 }
790
791 void wxTopLevelWindowMac::Iconize(bool iconize)
792 {
793 if ( IsWindowCollapsable((WindowRef)m_macWindow) )
794 CollapseWindow((WindowRef)m_macWindow , iconize ) ;
795 }
796
797 bool wxTopLevelWindowMac::IsIconized() const
798 {
799 return IsWindowCollapsed((WindowRef)m_macWindow ) ;
800 }
801
802 void wxTopLevelWindowMac::Restore()
803 {
804 // not available on mac
805 }
806
807 // ----------------------------------------------------------------------------
808 // wxTopLevelWindowMac misc
809 // ----------------------------------------------------------------------------
810
811 wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const
812 {
813 return wxPoint(0,0) ;
814 }
815
816 void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
817 {
818 // this sets m_icon
819 wxTopLevelWindowBase::SetIcon(icon);
820 }
821
822 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
823 {
824 wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ;
825
826 if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme )
827 {
828 SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ;
829 }
830 }
831
832 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
833 {
834 if ( m_macEventHandler != NULL )
835 {
836 verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ;
837 }
838 InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(),
839 GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler);
840 }
841
842 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
843 const wxPoint& pos,
844 const wxSize& size,
845 long style,
846 const wxString& name )
847 {
848 OSStatus err = noErr ;
849 SetName(name);
850 m_windowStyle = style;
851 m_isShown = FALSE;
852
853 // create frame.
854
855 Rect theBoundsRect;
856
857 int x = (int)pos.x;
858 int y = (int)pos.y;
859 if ( y < 50 )
860 y = 50 ;
861 if ( x < 20 )
862 x = 20 ;
863
864 int w = WidthDefault(size.x);
865 int h = HeightDefault(size.y);
866
867 ::SetRect(&theBoundsRect, x, y , x + w, y + h);
868
869 // translate the window attributes in the appropriate window class and attributes
870
871 WindowClass wclass = 0;
872 WindowAttributes attr = kWindowNoAttributes ;
873
874 if ( HasFlag( wxFRAME_TOOL_WINDOW) )
875 {
876 if (
877 HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
878 HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) ||
879 HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT)
880 )
881 {
882 wclass = kFloatingWindowClass ;
883 if ( HasFlag(wxTINY_CAPTION_VERT) )
884 {
885 attr |= kWindowSideTitlebarAttribute ;
886 }
887 }
888 else
889 {
890 wclass = kPlainWindowClass ;
891 }
892 }
893 else if ( HasFlag( wxCAPTION ) )
894 {
895 wclass = kDocumentWindowClass ;
896 }
897 else
898 {
899 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
900 HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) )
901 {
902 wclass = kDocumentWindowClass ;
903 }
904 else
905 {
906 wclass = kPlainWindowClass ;
907 }
908 }
909
910 if ( HasFlag( wxMINIMIZE_BOX ) )
911 {
912 attr |= kWindowCollapseBoxAttribute ;
913 }
914 if ( HasFlag( wxMAXIMIZE_BOX ) )
915 {
916 attr |= kWindowFullZoomAttribute ;
917 }
918 if ( HasFlag( wxRESIZE_BORDER ) )
919 {
920 attr |= kWindowResizableAttribute ;
921 }
922 if ( HasFlag( wxCLOSE_BOX) )
923 {
924 attr |= kWindowCloseBoxAttribute ;
925 }
926
927 if (UMAGetSystemVersion() >= 0x1000)
928 {
929 // turn on live resizing (OS X only)
930 attr |= kWindowLiveResizeAttribute;
931 }
932
933 if (HasFlag(wxSTAY_ON_TOP))
934 wclass = kUtilityWindowClass;
935
936 #if TARGET_API_MAC_OSX
937 attr |= kWindowCompositingAttribute;
938 #endif
939
940 if ( HasFlag(wxFRAME_SHAPED) )
941 {
942 WindowDefSpec customWindowDefSpec;
943 customWindowDefSpec.defType = kWindowDefProcPtr;
944 customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef);
945
946 err = ::CreateCustomWindow( &customWindowDefSpec, wclass,
947 attr, &theBoundsRect,
948 (WindowRef*) &m_macWindow);
949 }
950 else
951 {
952 err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
953 }
954
955 wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );
956 wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ;
957 UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ;
958 if ( m_macUsesCompositing )
959 {
960 ::GetRootControl( (WindowRef)m_macWindow, (ControlRef*)&m_macControl ) ;
961 }
962 else
963 {
964 ::CreateRootControl( (WindowRef)m_macWindow , (ControlRef*)&m_macControl ) ;
965 }
966 // the root control level handleer
967 MacInstallEventHandler() ;
968
969 // the frame window event handler
970 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ;
971 MacInstallTopLevelWindowEventHandler() ;
972
973 m_macFocus = NULL ;
974
975 if ( HasFlag(wxFRAME_SHAPED) )
976 {
977 // default shape matches the window size
978 wxRegion rgn(0, 0, w, h);
979 SetShape(rgn);
980 }
981
982 wxWindowCreateEvent event(this);
983 GetEventHandler()->ProcessEvent(event);
984 }
985
986 void wxTopLevelWindowMac::ClearBackground()
987 {
988 wxWindow::ClearBackground() ;
989 }
990
991 // Raise the window to the top of the Z order
992 void wxTopLevelWindowMac::Raise()
993 {
994 ::SelectWindow( (WindowRef)m_macWindow ) ;
995 }
996
997 // Lower the window to the bottom of the Z order
998 void wxTopLevelWindowMac::Lower()
999 {
1000 ::SendBehind( (WindowRef)m_macWindow , NULL ) ;
1001 }
1002
1003
1004 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp)
1005 {
1006 if(s_macDeactivateWindow)
1007 {
1008 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow);
1009 s_macDeactivateWindow->MacActivate(timestamp, false);
1010 }
1011 }
1012
1013 void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating )
1014 {
1015 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
1016
1017 if(s_macDeactivateWindow==this)
1018 s_macDeactivateWindow=NULL;
1019 MacDelayedDeactivation(timestamp);
1020 MacPropagateHiliteChanged() ;
1021 }
1022
1023 void wxTopLevelWindowMac::SetTitle(const wxString& title)
1024 {
1025 wxWindow::SetTitle( title ) ;
1026 UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ;
1027 }
1028
1029 bool wxTopLevelWindowMac::Show(bool show)
1030 {
1031 if ( !wxTopLevelWindowBase::Show(show) )
1032 return FALSE;
1033
1034 if (show)
1035 {
1036 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1037 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) )
1038 {
1039 ::ShowWindow( (WindowRef)m_macWindow );
1040 }
1041 else
1042 #endif
1043 {
1044 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil);
1045 }
1046 ::SelectWindow( (WindowRef)m_macWindow ) ;
1047 // as apps expect a size event to occur at this moment
1048 wxSizeEvent event( GetSize() , m_windowId);
1049 event.SetEventObject(this);
1050 GetEventHandler()->ProcessEvent(event);
1051 }
1052 else
1053 {
1054 #if wxUSE_SYSTEM_OPTIONS
1055 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) )
1056 {
1057 ::HideWindow((WindowRef) m_macWindow );
1058 }
1059 else
1060 #endif
1061 {
1062 ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil);
1063 }
1064 }
1065
1066 MacPropagateVisibilityChanged() ;
1067
1068 return TRUE ;
1069 }
1070
1071 // we are still using coordinates of the content view, todo switch to structure bounds
1072
1073 void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
1074 {
1075 Rect bounds = { y , x , y + height , x + width } ;
1076 verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1077 }
1078
1079 void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const
1080 {
1081 Rect bounds ;
1082 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1083 if(x) *x = bounds.left ;
1084 if(y) *y = bounds.top ;
1085 }
1086 void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const
1087 {
1088 Rect bounds ;
1089 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ;
1090 if(width) *width = bounds.right - bounds.left ;
1091 if(height) *height = bounds.bottom - bounds.top ;
1092 }
1093
1094 void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const
1095 {
1096 Rect bounds ;
1097 verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ;
1098 if(width) *width = bounds.right - bounds.left ;
1099 if(height) *height = bounds.bottom - bounds.top ;
1100 }
1101
1102 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set )
1103 {
1104 #if TARGET_API_MAC_OSX
1105 UInt32 attr = 0 ;
1106 GetWindowAttributes((WindowRef) m_macWindow , &attr ) ;
1107 wxASSERT_MSG( attr & kWindowCompositingAttribute ,
1108 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1109
1110 MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes ,
1111 set ? kWindowNoAttributes : kWindowMetalAttribute ) ;
1112 #endif
1113 }
1114
1115 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1116 {
1117 #if TARGET_API_MAC_OSX
1118 return MacGetWindowAttributes() & kWindowMetalAttribute ;
1119 #else
1120 return false ;
1121 #endif
1122 }
1123
1124 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear )
1125 {
1126 ChangeWindowAttributes ( (WindowRef) m_macWindow , attributesToSet, attributesToClear ) ;
1127 }
1128
1129 wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const
1130 {
1131 UInt32 attr = 0 ;
1132 GetWindowAttributes((WindowRef) m_macWindow , &attr ) ;
1133 return attr ;
1134 }
1135
1136 // ---------------------------------------------------------------------------
1137 // Shape implementation
1138 // ---------------------------------------------------------------------------
1139
1140
1141 bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
1142 {
1143 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE,
1144 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1145
1146 // The empty region signifies that the shape should be removed from the
1147 // window.
1148 if ( region.IsEmpty() )
1149 {
1150 wxSize sz = GetClientSize();
1151 wxRegion rgn(0, 0, sz.x, sz.y);
1152 return SetShape(rgn);
1153 }
1154
1155 // Make a copy of the region
1156 RgnHandle shapeRegion = NewRgn();
1157 CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion );
1158
1159 // Dispose of any shape region we may already have
1160 RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() );
1161 if ( oldRgn )
1162 DisposeRgn(oldRgn);
1163
1164 // Save the region so we can use it later
1165 SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion);
1166
1167 // Tell the window manager that the window has changed shape
1168 ReshapeCustomWindow((WindowRef)MacGetWindowRef());
1169 return TRUE;
1170 }
1171
1172 // ---------------------------------------------------------------------------
1173 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1174 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1175 // ---------------------------------------------------------------------------
1176
1177 static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect)
1178 {
1179 GetWindowPortBounds(window, inRect);
1180 Point pt = {inRect->left, inRect->top};
1181 SetPort((GrafPtr) GetWindowPort(window));
1182 LocalToGlobal(&pt);
1183 inRect->top = pt.v;
1184 inRect->left = pt.h;
1185 inRect->bottom += pt.v;
1186 inRect->right += pt.h;
1187 }
1188
1189
1190 static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param)
1191 {
1192 /*------------------------------------------------------
1193 Define which options your custom window supports.
1194 --------------------------------------------------------*/
1195 //just enable everything for our demo
1196 *(OptionBits*)param=//kWindowCanGrow|
1197 //kWindowCanZoom|
1198 //kWindowCanCollapse|
1199 //kWindowCanGetWindowRegion|
1200 //kWindowHasTitleBar|
1201 //kWindowSupportsDragHilite|
1202 kWindowCanDrawInCurrentPort|
1203 //kWindowCanMeasureTitle|
1204 kWindowWantsDisposeAtProcessDeath|
1205 kWindowSupportsSetGrowImageRegion|
1206 kWindowDefSupportsColorGrafPort;
1207 return 1;
1208 }
1209
1210 // The content region is left as a rectangle matching the window size, this is
1211 // so the origin in the paint event, and etc. still matches what the
1212 // programmer expects.
1213 static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn)
1214 {
1215 SetEmptyRgn(rgn);
1216 wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window);
1217 if (win)
1218 {
1219 Rect r ;
1220 wxShapedMacWindowGetPos(window, &r ) ;
1221 RectRgn( rgn , &r ) ;
1222 }
1223 }
1224
1225 // The structure region is set to the shape given to the SetShape method.
1226 static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn)
1227 {
1228 RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window);
1229
1230 SetEmptyRgn(rgn);
1231 if (cachedRegion)
1232 {
1233 Rect windowRect;
1234 wxShapedMacWindowGetPos(window, &windowRect); //how big is the window
1235 CopyRgn(cachedRegion, rgn); //make a copy of our cached region
1236 OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window
1237 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1238 }
1239 }
1240
1241
1242
1243 static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param)
1244 {
1245 GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param;
1246
1247 switch(rgnRec->regionCode)
1248 {
1249 case kWindowStructureRgn:
1250 wxShapedMacWindowStructureRegion(window, rgnRec->winRgn);
1251 break;
1252 case kWindowContentRgn:
1253 wxShapedMacWindowContentRegion(window, rgnRec->winRgn);
1254 break;
1255 default:
1256 SetEmptyRgn(rgnRec->winRgn);
1257 } //switch
1258
1259 return noErr;
1260 }
1261
1262
1263 static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param)
1264 {
1265 /*------------------------------------------------------
1266 Determine the region of the window which was hit
1267 --------------------------------------------------------*/
1268 Point hitPoint;
1269 static RgnHandle tempRgn=nil;
1270
1271 if(!tempRgn)
1272 tempRgn=NewRgn();
1273
1274 SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked
1275
1276 //Mac OS 8.5 or later
1277 wxShapedMacWindowStructureRegion(window, tempRgn);
1278 if (PtInRgn(hitPoint, tempRgn)) //in window content region?
1279 return wInContent;
1280
1281 return wNoHit;//no significant area was hit.
1282 }
1283
1284
1285 static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param)
1286 {
1287 switch(message)
1288 {
1289 case kWindowMsgHitTest:
1290 return wxShapedMacWindowHitTest(window,param);
1291
1292 case kWindowMsgGetFeatures:
1293 return wxShapedMacWindowGetFeatures(window,param);
1294
1295 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1296 case kWindowMsgGetRegion:
1297 return wxShapedMacWindowGetRegion(window,param);
1298 }
1299
1300 return 0;
1301 }
1302
1303 // ---------------------------------------------------------------------------
1304