+BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase)
+END_EVENT_TABLE()
+
+
+// ---------------------------------------------------------------------------
+// Carbon Events
+// ---------------------------------------------------------------------------
+
+static const EventTypeSpec eventList[] =
+{
+ // TODO: remove control related event like key and mouse (except for WindowLeave events)
+
+ { kEventClassKeyboard, kEventRawKeyDown } ,
+ { kEventClassKeyboard, kEventRawKeyRepeat } ,
+ { kEventClassKeyboard, kEventRawKeyUp } ,
+ { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
+
+ { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
+ { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } ,
+
+ { 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 KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+ // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
+ // FindFocus does not return the actual focus window, but the enclosing window
+ wxWindow* focus = wxWindow::DoFindFocus();
+ if ( focus == NULL )
+ focus = (wxTopLevelWindowMac*) data ;
+
+ unsigned char charCode ;
+ wxChar uniChar[2] ;
+ uniChar[0] = 0;
+ uniChar[1] = 0;
+
+ UInt32 keyCode ;
+ UInt32 modifiers ;
+ Point point ;
+ UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
+
+#if wxUSE_UNICODE
+ ByteCount dataSize = 0 ;
+ if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr )
+ {
+ UniChar buf[2] ;
+ int numChars = dataSize / sizeof( UniChar) + 1;
+
+ UniChar* charBuf = buf ;
+
+ if ( numChars * 2 > 4 )
+ charBuf = new UniChar[ numChars ] ;
+ GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ;
+ charBuf[ numChars - 1 ] = 0;
+
+#if SIZEOF_WCHAR_T == 2
+ uniChar = charBuf[0] ;
+#else
+ wxMBConvUTF16 converter ;
+ converter.MB2WC( uniChar , (const char*)charBuf , 2 ) ;
+#endif
+
+ if ( numChars * 2 > 4 )
+ delete[] charBuf ;
+ }
+#endif
+
+ 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 && */ wxTheApp->MacSendKeyDownEvent(
+ focus , message , modifiers , when , point.h , point.v , uniChar[0] ) )
+ {
+ result = noErr ;
+ }
+ wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
+ }
+ break ;
+
+ case kEventRawKeyUp :
+ if ( /* focus && */ wxTheApp->MacSendKeyUpEvent(
+ focus , message , modifiers , when , point.h , point.v , uniChar[0] ) )
+ {
+ 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;
+
+#if wxUSE_UNICODE
+ event.m_uniChar = uniChar[0] ;
+#endif
+
+ event.SetTimestamp(when);
+ event.SetEventObject(focus);
+
+ if ( /* focus && */ (modifiers ^ wxApp::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 ^ wxApp::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 ^ wxApp::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 ^ wxApp::s_lastModifiers ) & cmdKey )
+ {
+ event.m_keyCode = WXK_COMMAND ;
+ event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
+ focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+
+ wxApp::s_lastModifiers = modifiers ;
+ }
+ break ;
+
+ default:
+ 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 ;
+
+EventMouseButton g_lastButton = 0 ;
+
+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 ;
+
+ // otherwise we report double clicks by connecting a left click with a ctrl-left click
+ if ( clickCount > 1 && button != g_lastButton )
+ clickCount = 1 ;
+
+ // we must make sure that our synthetic 'right' button corresponds in
+ // mouse down, moved and mouse up, and does not deliver a right down and left up
+
+ if ( cEvent.GetKind() == kEventMouseDown )
+ g_lastButton = button ;
+
+ if ( button == 0 )
+ g_lastButton = 0 ;
+ else if ( g_lastButton )
+ button = g_lastButton ;
+
+ // determine 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 ;
+
+ default:
+ break ;
+ }
+ }
+
+ // translate into wx types
+ switch ( cEvent.GetKind() )
+ {
+ case kEventMouseDown :
+ switch ( button )
+ {
+ case kEventMouseButtonPrimary :
+ wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
+ break ;
+
+ case kEventMouseButtonSecondary :
+ wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
+ break ;
+
+ case kEventMouseButtonTertiary :
+ wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
+ break ;
+
+ default:
+ break ;
+ }
+ break ;
+
+ case kEventMouseUp :
+ switch ( button )
+ {
+ case kEventMouseButtonPrimary :
+ wxevent.SetEventType( wxEVT_LEFT_UP ) ;
+ break ;
+
+ case kEventMouseButtonSecondary :
+ wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
+ break ;
+
+ case kEventMouseButtonTertiary :
+ wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
+ break ;
+
+ default:
+ break ;
+ }
+ break ;
+
+ case kEventMouseWheelMoved :
+ {
+ wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ;
+
+ EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
+ SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeSInt32) ;
+
+ wxevent.m_wheelRotation = delta;
+ wxevent.m_wheelDelta = 1;
+ wxevent.m_linesPerAction = 1;
+ if ( axis == kEventMouseWheelAxisX )
+ wxevent.m_wheelAxis = 1;
+ }
+ break ;
+
+ default :
+ wxevent.SetEventType( wxEVT_MOTION ) ;
+ break ;
+ }
+}
+
+ControlRef wxMacFindSubControl( wxTopLevelWindowMac* toplevelWindow, const Point& location , ControlRef superControl , ControlPartCode *outPart )
+{
+ if ( superControl )
+ {
+ UInt16 childrenCount = 0 ;
+ ControlHandle sibling ;
+ Rect r ;
+ 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 )
+ {
+ err = GetIndexedSubControl( superControl , i , & sibling ) ;
+ if ( err == errControlIsNotEmbedder )
+ return NULL ;
+
+ wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
+ if ( IsControlVisible( sibling ) )
+ {
+ UMAGetControlBoundsInWindowCoords( sibling , &r ) ;
+ if ( MacPtInRect( location , &r ) )
+ {
+ ControlHandle child = wxMacFindSubControl( toplevelWindow , location , sibling , outPart ) ;
+ if ( child )
+ {
+ return child ;
+ }
+ else
+ {
+ Point testLocation = location ;
+
+ if ( toplevelWindow )
+ {
+ testLocation.h -= r.left ;
+ testLocation.v -= r.top ;
+ }
+
+ *outPart = TestControl( sibling , testLocation ) ;
+
+ return sibling ;
+ }
+ }
+ }
+ }
+ }
+
+ return NULL ;
+}
+
+ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow , const Point& location , WindowRef window , ControlPartCode *outPart )
+{
+#if TARGET_API_MAC_OSX
+ if ( UMAGetSystemVersion() >= 0x1030 )
+ return FindControlUnderMouse( location , window , outPart ) ;
+#endif
+
+ ControlRef rootControl = NULL ;
+ verify_noerr( GetRootControl( window , &rootControl ) ) ;
+
+ return wxMacFindSubControl( toplevelWindow , location , rootControl , outPart ) ;
+}
+
+#define NEW_CAPTURE_HANDLING 1
+
+pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ;
+
+ OSStatus result = eventNotHandledErr ;
+
+ wxMacCarbonEvent cEvent( event ) ;
+
+ Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
+ Point windowMouseLocation = screenMouseLocation ;
+
+ WindowRef window = NULL;
+ short windowPart = ::FindWindow(screenMouseLocation, &window);
+
+ wxWindow* currentMouseWindow = NULL ;
+ ControlRef control = NULL ;
+
+#if NEW_CAPTURE_HANDLING
+ if ( wxApp::s_captureWindow )
+ {
+ window = (WindowRef) wxApp::s_captureWindow->MacGetTopLevelWindowRef() ;
+ windowPart = inContent ;
+ }
+#endif
+
+ if ( window )
+ {
+ wxMacGlobalToLocal( window, &windowMouseLocation ) ;
+
+ if ( wxApp::s_captureWindow
+#if !NEW_CAPTURE_HANDLING
+ && wxApp::s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent
+#endif
+ )
+ {
+ currentMouseWindow = wxApp::s_captureWindow ;
+ }
+ else if ( (IsWindowActive(window) && windowPart == inContent) )
+ {
+ ControlPartCode part ;
+ control = wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &part ) ;
+ // if there is no control below the mouse position, send the event to the toplevel window itself
+ if ( control == 0 )
+ {
+ currentMouseWindow = (wxWindow*) data ;
+ }
+ else
+ {
+ currentMouseWindow = wxFindControlFromMacControl( control ) ;
+ if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved )
+ {
+#if wxUSE_TOOLBAR
+ // for wxToolBar to function we have to send certaint events to it
+ // instead of its children (wxToolBarTools)
+ ControlRef parent ;
+ GetSuperControl(control, &parent );
+ wxWindow *wxParent = wxFindControlFromMacControl( parent ) ;
+ if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) )
+ currentMouseWindow = wxParent ;
+#endif
+ }
+ }
+
+ // disabled windows must not get any input messages
+ if ( currentMouseWindow && !currentMouseWindow->MacIsReallyEnabled() )
+ currentMouseWindow = NULL;
+ }
+ }
+
+ 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 ) ;
+ wxevent.SetId( g_MacLastWindow->GetId() ) ;
+
+#if wxUSE_TOOLTIPS
+ wxToolTip::RelayEvent( g_MacLastWindow , eventleave);
+#endif
+
+ 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 ) ;
+ wxevent.SetId( currentMouseWindow->GetId() ) ;
+
+#if wxUSE_TOOLTIPS
+ wxToolTip::RelayEvent( currentMouseWindow , evententer );
+#endif
+
+ 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 ;
+ }
+ }
+ else if ( currentMouseWindow )
+ {
+ wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent();
+
+ currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
+
+ wxevent.SetEventObject( currentMouseWindow ) ;
+ wxevent.SetId( currentMouseWindow->GetId() ) ;
+
+ // make tooltips current
+
+#if wxUSE_TOOLTIPS
+ if ( wxevent.GetEventType() == wxEVT_MOTION )
+ wxToolTip::RelayEvent( currentMouseWindow , wxevent );
+#endif
+
+ if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) )
+ {
+ if ((currentMouseWindowParent != NULL) &&
+ (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
+ currentMouseWindow = NULL;
+
+ result = noErr;
+ }
+ else
+ {
+ // if the user code did _not_ handle the event, then perform the
+ // default processing
+ if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN )
+ {
+ // ... that is set focus to this window
+ if (currentMouseWindow->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow)
+ currentMouseWindow->SetFocus();
+ }
+
+ 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 )
+#ifdef __WXMAC_OSX__
+ &&
+ (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) !=
+ wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &dummyPart ) )
+#endif
+ )
+ {
+ if ( currentMouseWindow->MacIsReallyEnabled() )
+ {
+ EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
+ Point clickLocation = windowMouseLocation ;
+
+ currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ;
+
+ HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation ,
+ modifiers , (ControlActionUPP ) -1 ) ;
+
+ if ((currentMouseWindowParent != NULL) &&
+ (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
+ {
+ currentMouseWindow = NULL;
+ }
+ }
+
+ result = noErr ;
+ }
+ }
+
+ if ( cEvent.GetKind() == kEventMouseUp && wxApp::s_captureWindow )
+ {
+ wxApp::s_captureWindow = NULL ;
+ // update cursor ?
+ }
+
+ // 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();
+ }
+
+ }
+ else // currentMouseWindow == NULL
+ {
+ // don't mess with controls we don't know about
+ // for some reason returning eventNotHandledErr does not lead to the correct behaviour
+ // so we try sending them the correct control directly
+ if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control )
+ {
+ EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
+ Point clickLocation = windowMouseLocation ;
+#if TARGET_API_MAC_OSX
+ HIPoint hiPoint ;
+ hiPoint.x = clickLocation.h ;
+ hiPoint.y = clickLocation.v ;
+ HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ;
+ clickLocation.h = (int)hiPoint.x ;
+ clickLocation.v = (int)hiPoint.y ;
+#endif // TARGET_API_MAC_OSX
+
+ HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ;
+ result = noErr ;
+ }
+ }
+
+ 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 )
+ {
+ frame->PositionBars();
+ }
+
+ wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ;
+ event.SetEventObject( toplevelWindow ) ;
+
+ toplevelWindow->GetEventHandler()->ProcessEvent(event) ;
+ toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
+ }
+
+ 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() ) ;
+ const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ;
+ if ( !EqualRect( &newRect , &adjustedRect ) )
+ cEvent.SetParameter<Rect>( kEventParamCurrentBounds , &adjustedRect ) ;
+ toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
+ }
+
+ result = noErr ;
+ }
+ break ;
+
+ default :
+ break ;
+ }
+
+ return result ;
+}
+
+// mix this in from window.cpp
+pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
+
+pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ switch ( GetEventClass( event ) )
+ {
+ case kEventClassTextInput :
+ result = wxMacUnicodeTextEventHandler( handler, event , data ) ;
+ break ;
+
+ case kEventClassKeyboard :
+ result = KeyboardEventHandler( 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 )
+