+BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase)
+END_EVENT_TABLE()
+
+
+// ---------------------------------------------------------------------------
+// Carbon Events
+// ---------------------------------------------------------------------------
+
+extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
+
+static const EventTypeSpec eventList[] =
+{
+ // TODO remove control related event like key and mouse (except for WindowLeave events)
+#if 1
+ { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
+
+ { kEventClassKeyboard, kEventRawKeyDown } ,
+ { kEventClassKeyboard, kEventRawKeyRepeat } ,
+ { kEventClassKeyboard, kEventRawKeyUp } ,
+ { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
+#endif
+
+ { kEventClassWindow , kEventWindowShown } ,
+ { kEventClassWindow , kEventWindowActivated } ,
+ { kEventClassWindow , kEventWindowDeactivated } ,
+ { kEventClassWindow , kEventWindowBoundsChanging } ,
+ { kEventClassWindow , kEventWindowBoundsChanged } ,
+ { kEventClassWindow , kEventWindowClose } ,
+
+ // we have to catch these events on the toplevel window level, as controls don't get the
+ // raw mouse events anymore
+
+ { kEventClassMouse , kEventMouseDown } ,
+ { kEventClassMouse , kEventMouseUp } ,
+ { kEventClassMouse , kEventMouseWheelMoved } ,
+ { kEventClassMouse , kEventMouseMoved } ,
+ { kEventClassMouse , kEventMouseDragged } ,
+} ;
+
+static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ wxWindow* focus = wxWindow::FindFocus() ;
+ char charCode ;
+ UInt32 keyCode ;
+ UInt32 modifiers ;
+ Point point ;
+
+ EventRef rawEvent ;
+
+ GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
+
+ GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
+ GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
+ GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
+ GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL,
+ sizeof( Point ), NULL, &point );
+
+ switch ( GetEventKind( event ) )
+ {
+ case kEventTextInputUnicodeForKeyEvent :
+ // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
+ // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
+ wxControl* control = wxDynamicCast( focus , wxControl ) ;
+ if ( control )
+ {
+ ControlRef macControl = (ControlRef) control->GetHandle() ;
+ if ( macControl )
+ {
+ ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ;
+ result = noErr ;
+ }
+ }
+ /*
+ // this may lead to double events sent to a window in case all handlers have skipped the key down event
+ UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
+ UInt32 message = (keyCode << 8) + charCode;
+
+ if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
+ focus , message , modifiers , when , point.h , point.v ) )
+ {
+ result = noErr ;
+ }
+ */
+ break ;
+ }
+
+ return result ;
+}
+
+static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ wxWindow* focus = wxWindow::FindFocus() ;
+ if ( focus == NULL )
+ return result ;
+
+ char charCode ;
+ UInt32 keyCode ;
+ UInt32 modifiers ;
+ Point point ;
+ UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
+
+ GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
+ GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
+ GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
+ GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
+ sizeof( Point ), NULL, &point );
+
+ UInt32 message = (keyCode << 8) + charCode;
+ switch( GetEventKind( event ) )
+ {
+ case kEventRawKeyRepeat :
+ case kEventRawKeyDown :
+ {
+ WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
+ WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
+ wxTheApp->MacSetCurrentEvent( event , handler ) ;
+ if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
+ focus , message , modifiers , when , point.h , point.v ) )
+ {
+ result = noErr ;
+ }
+ wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
+ }
+ break ;
+ case kEventRawKeyUp :
+ if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent(
+ focus , message , modifiers , when , point.h , point.v ) )
+ {
+ result = noErr ;
+ }
+ break ;
+ case kEventRawKeyModifiersChanged :
+ {
+ wxKeyEvent event(wxEVT_KEY_DOWN);
+
+ event.m_shiftDown = modifiers & shiftKey;
+ event.m_controlDown = modifiers & controlKey;
+ event.m_altDown = modifiers & optionKey;
+ event.m_metaDown = modifiers & cmdKey;
+
+ event.m_x = point.h;
+ event.m_y = point.v;
+ event.m_timeStamp = when;
+ wxWindow* focus = wxWindow::FindFocus() ;
+ event.SetEventObject(focus);
+
+ if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey )
+ {
+ event.m_keyCode = WXK_CONTROL ;
+ event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
+ focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+ if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey )
+ {
+ event.m_keyCode = WXK_SHIFT ;
+ event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
+ focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+ if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey )
+ {
+ event.m_keyCode = WXK_ALT ;
+ event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
+ focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+ if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & cmdKey )
+ {
+ event.m_keyCode = WXK_COMMAND ;
+ event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
+ focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+ wxTheApp->s_lastModifiers = modifiers ;
+ }
+ break ;
+ }
+
+ return result ;
+}
+
+// we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
+// for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the
+// mouse down at all
+
+// This handler can also be called from app level where data (ie target window) may be null or a non wx window
+
+wxWindow* g_MacLastWindow = NULL ;
+
+static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent )
+{
+ UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ;
+ Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
+
+ // this parameter are not given for all events
+ EventMouseButton button = 0 ;
+ UInt32 clickCount = 0 ;
+ cEvent.GetParameter<EventMouseButton>(kEventParamMouseButton, typeMouseButton , &button) ;
+ cEvent.GetParameter<UInt32>(kEventParamClickCount, typeUInt32 , &clickCount ) ;
+
+ wxevent.m_x = screenMouseLocation.h;
+ wxevent.m_y = screenMouseLocation.v;
+ wxevent.m_shiftDown = modifiers & shiftKey;
+ wxevent.m_controlDown = modifiers & controlKey;
+ wxevent.m_altDown = modifiers & optionKey;
+ wxevent.m_metaDown = modifiers & cmdKey;
+ wxevent.SetTimestamp( cEvent.GetTicks() ) ;
+ // a control click is interpreted as a right click
+ if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
+ {
+ button = kEventMouseButtonSecondary ;
+ }
+
+ // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
+ // this button
+ if ( button != 0 && cEvent.GetKind() != kEventMouseUp )
+ {
+ switch( button )
+ {
+ case kEventMouseButtonPrimary :
+ wxevent.m_leftDown = true ;
+ break ;
+ case kEventMouseButtonSecondary :
+ wxevent.m_rightDown = true ;
+ break ;
+ case kEventMouseButtonTertiary :
+ wxevent.m_middleDown = true ;
+ break ;
+ }
+ }
+ // determinate the correct click button
+ if ( button == kEventMouseButtonSecondary )
+ {
+ if (cEvent.GetKind() == kEventMouseDown )
+ wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
+ else if ( cEvent.GetKind() == kEventMouseUp )
+ wxevent.SetEventType(wxEVT_RIGHT_UP ) ;
+ }
+ else if ( button == kEventMouseButtonTertiary )
+ {
+ if (cEvent.GetKind() == kEventMouseDown )
+ wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
+ else if ( cEvent.GetKind() == kEventMouseUp )
+ wxevent.SetEventType(wxEVT_MIDDLE_UP ) ;
+ }
+ else
+ {
+ if (cEvent.GetKind() == kEventMouseDown )
+ wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
+ else if ( cEvent.GetKind() == kEventMouseUp )
+ wxevent.SetEventType(wxEVT_LEFT_UP ) ;
+ else if ( cEvent.GetKind() == kEventMouseWheelMoved )
+ {
+ wxevent.SetEventType(wxEVT_MOUSEWHEEL ) ;
+
+ // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
+ SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeLongInteger) ;
+
+ wxevent.m_wheelRotation = delta;
+ wxevent.m_wheelDelta = 1;
+ wxevent.m_linesPerAction = 1;
+ }
+ else
+ wxevent.SetEventType(wxEVT_MOTION ) ;
+ }
+}
+
+ControlRef wxMacFindSubControl( Point location , ControlRef superControl , ControlPartCode *outPart )
+{
+ if ( superControl )
+ {
+ UInt16 childrenCount = 0 ;
+ OSStatus err = CountSubControls( superControl , &childrenCount ) ;
+ if ( err == errControlIsNotEmbedder )
+ return NULL ;
+ wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
+
+ for ( UInt16 i = childrenCount ; i >=1 ; --i )
+ {
+ ControlHandle sibling ;
+ err = GetIndexedSubControl( superControl , i , & sibling ) ;
+ if ( err == errControlIsNotEmbedder )
+ return NULL ;
+
+ wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
+ if ( IsControlVisible( sibling ) )
+ {
+ Rect r ;
+ GetControlBounds( sibling , &r ) ;
+ if ( MacPtInRect( location , &r ) )
+ {
+ ControlHandle child = wxMacFindSubControl( location , sibling , outPart ) ;
+ if ( child )
+ return child ;
+ else
+ {
+ *outPart = TestControl( sibling , location ) ;
+ return sibling ;
+ }
+ }
+ }
+ }
+ }
+ return NULL ;
+}
+
+ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart )
+{
+#if TARGET_API_MAC_OSX
+ if ( UMAGetSystemVersion() >= 1030 )
+ return FindControlUnderMouse( location , window , outPart ) ;
+#endif
+ ControlRef rootControl = NULL ;
+ verify_noerr( GetRootControl( window , &rootControl ) ) ;
+ return wxMacFindSubControl( location , rootControl , outPart ) ;
+
+}
+pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+
+ OSStatus result = eventNotHandledErr ;
+
+ wxMacCarbonEvent cEvent( event ) ;
+
+ Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
+ Point windowMouseLocation = screenMouseLocation ;
+
+ WindowRef window ;
+ short windowPart = ::FindWindow(screenMouseLocation, &window);
+
+ wxWindow* currentMouseWindow = NULL ;
+ if ( window )
+ {
+ // calculate window relative coordinates
+ GrafPtr port;
+ ::GetPort( &port ) ;
+ ::SetPort( UMAGetWindowPort(window ) ) ;
+ ::GlobalToLocal( &windowMouseLocation ) ;
+ ::SetPort( port ) ;
+
+ if ( wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent )
+ {
+ currentMouseWindow = wxTheApp->s_captureWindow ;
+ }
+ else if ( (IsWindowActive(window) && windowPart == inContent) )
+ {
+ ControlPartCode part ;
+ ControlRef control = wxMacFindControlUnderMouse( windowMouseLocation , window , &part ) ;
+ if ( control == 0 )
+ currentMouseWindow = (wxWindow*) data ;
+ else
+ currentMouseWindow = wxFindControlFromMacControl( control ) ;
+ }
+ }
+
+ wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
+ SetupMouseEvent( wxevent , cEvent ) ;
+
+ // handle all enter / leave events
+
+ if ( currentMouseWindow != g_MacLastWindow )
+ {
+ if ( g_MacLastWindow )
+ {
+ wxMouseEvent eventleave(wxevent);
+ eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
+ g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
+ eventleave.SetEventObject( g_MacLastWindow ) ;
+
+#if wxUSE_TOOLTIPS
+ wxToolTip::RelayEvent( g_MacLastWindow , eventleave);
+#endif // wxUSE_TOOLTIPS
+ g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave);
+ }
+ if ( currentMouseWindow )
+ {
+ wxMouseEvent evententer(wxevent);
+ evententer.SetEventType( wxEVT_ENTER_WINDOW );
+ currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
+ evententer.SetEventObject( currentMouseWindow ) ;
+#if wxUSE_TOOLTIPS
+ wxToolTip::RelayEvent( currentMouseWindow , evententer);
+#endif // wxUSE_TOOLTIPS
+ currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
+ }
+ g_MacLastWindow = currentMouseWindow ;
+ }
+
+ if ( windowPart == inMenuBar )
+ {
+ // special case menu bar, as we are having a low-level runloop we must do it ourselves
+ if ( cEvent.GetKind() == kEventMouseDown )
+ {
+ ::MenuSelect( screenMouseLocation ) ;
+ result = noErr ;
+ }
+ } // if ( windowPart == inMenuBar )
+ else if ( currentMouseWindow )
+ {
+ currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
+
+ wxevent.SetEventObject( currentMouseWindow ) ;
+
+ // update cursor
+
+ wxWindow* cursorTarget = currentMouseWindow ;
+ wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ;
+
+ while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
+ {
+ cursorTarget = cursorTarget->GetParent() ;
+ if ( cursorTarget )
+ cursorPoint += cursorTarget->GetPosition() ;
+ }
+
+ // update focus
+
+ if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN )
+ {
+ // set focus to this window
+ if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow)
+ currentMouseWindow->SetFocus();
+ }
+
+ // make tooltips current
+
+ #if wxUSE_TOOLTIPS
+ if ( wxevent.GetEventType() == wxEVT_MOTION
+ || wxevent.GetEventType() == wxEVT_ENTER_WINDOW
+ || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW )
+ wxToolTip::RelayEvent( currentMouseWindow , wxevent);
+ #endif // wxUSE_TOOLTIPS
+ if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) )
+ result = noErr;
+ else
+ {
+ ControlPartCode dummyPart ;
+ // if built-in find control is finding the wrong control (ie static box instead of overlaid
+ // button, we cannot let the standard handler do its job, but must handle manually
+
+ if ( ( cEvent.GetKind() == kEventMouseDown ) &&
+ (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) !=
+ wxMacFindControlUnderMouse( windowMouseLocation , window , &dummyPart ) ) )
+ {
+ EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
+ HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , windowMouseLocation ,
+ modifiers , (ControlActionUPP ) -1 ) ;
+ result = noErr ;
+ }
+ }
+ if ( cEvent.GetKind() == kEventMouseUp && wxTheApp->s_captureWindow )
+ {
+ wxTheApp->s_captureWindow = NULL ;
+ // update cursor ?
+ }
+ } // else if ( currentMouseWindow )
+ return result ;
+}
+
+static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ wxMacCarbonEvent cEvent( event ) ;
+
+ // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
+ wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
+
+ switch( GetEventKind( event ) )
+ {
+ case kEventWindowActivated :
+ {
+ toplevelWindow->MacActivate( cEvent.GetTicks() , true) ;
+ wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId());
+ wxevent.SetTimestamp( cEvent.GetTicks() ) ;
+ wxevent.SetEventObject(toplevelWindow);
+ toplevelWindow->GetEventHandler()->ProcessEvent(wxevent);
+ // we still sending an eventNotHandledErr in order to allow for default processing
+ break ;
+ }
+ case kEventWindowDeactivated :
+ {
+ toplevelWindow->MacActivate(cEvent.GetTicks() , false) ;
+ wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId());
+ wxevent.SetTimestamp( cEvent.GetTicks() ) ;
+ wxevent.SetEventObject(toplevelWindow);
+ toplevelWindow->GetEventHandler()->ProcessEvent(wxevent);
+ // we still sending an eventNotHandledErr in order to allow for default processing
+ break ;
+ }
+ case kEventWindowShown :
+ toplevelWindow->Refresh() ;
+ result = noErr ;
+ break ;
+ case kEventWindowClose :
+ toplevelWindow->Close() ;
+ result = noErr ;
+ break ;
+ case kEventWindowBoundsChanged :
+ {
+ UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ;
+ Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
+ wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ;
+ if ( attributes & kWindowBoundsChangeSizeChanged )
+ {
+ // according to the other ports we handle this within the OS level
+ // resize event, not within a wxSizeEvent
+ wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ;
+ if ( frame )
+ {
+ #if wxUSE_STATUSBAR
+ frame->PositionStatusBar();
+ #endif
+ #if wxUSE_TOOLBAR
+ frame->PositionToolBar();
+ #endif
+ }
+
+ wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ;
+ event.SetEventObject( toplevelWindow ) ;
+
+ toplevelWindow->GetEventHandler()->ProcessEvent(event) ;
+ }
+ if ( attributes & kWindowBoundsChangeOriginChanged )
+ {
+ wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ;
+ event.SetEventObject( toplevelWindow ) ;
+ toplevelWindow->GetEventHandler()->ProcessEvent(event) ;
+ }
+ result = noErr ;
+ break ;
+ }
+ case kEventWindowBoundsChanging :
+ {
+ UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ;
+ Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ;
+
+ if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) )
+ {
+ // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
+ int left , top , right , bottom ;
+ toplevelWindow->MacGetContentAreaInset( left , top , right , bottom ) ;
+ wxRect r( newRect.left - left , newRect.top - top ,
+ newRect.right - newRect.left + left + right , newRect.bottom - newRect.top + top + bottom ) ;
+ // this is a EVT_SIZING not a EVT_SIZE type !
+ wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ;
+ wxevent.SetEventObject( toplevelWindow ) ;
+ wxRect adjustR = r ;
+ if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) )
+ adjustR = wxevent.GetRect() ;
+
+ if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() )
+ adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ;
+ if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() )
+ adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ;
+ if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() )
+ adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ;
+ if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() )
+ adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ;
+ Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ;
+ if ( !EqualRect( &newRect , &adjustedRect ) )
+ cEvent.SetParameter( kEventParamCurrentBounds , &adjustedRect ) ;
+ }
+
+ result = noErr ;
+ break ;
+ }
+ default :
+ break ;
+ }
+ return result ;
+}
+
+pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ switch ( GetEventClass( event ) )
+ {
+ case kEventClassKeyboard :
+ result = KeyboardEventHandler( handler, event , data ) ;
+ break ;
+ case kEventClassTextInput :
+ result = TextInputEventHandler( handler, event , data ) ;
+ break ;
+ case kEventClassWindow :
+ result = wxMacTopLevelWindowEventHandler( handler, event , data ) ;
+ break ;
+ case kEventClassMouse :
+ result = wxMacTopLevelMouseEventHandler( handler, event , data ) ;
+ break ;
+ default :
+ break ;
+ }
+ return result ;
+}
+
+DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler )
+