-// ---------------------------------------------------------------------------
-// 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 } ,
- { kEventClassWindow , kEventWindowGetRegion } ,
-
- // 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->HandleWindowEvent( event ) ;
- }
- if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & shiftKey )
- {
- event.m_keyCode = WXK_SHIFT ;
- event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
- focus->HandleWindowEvent( event ) ;
- }
- if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & optionKey )
- {
- event.m_keyCode = WXK_ALT ;
- event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
- focus->HandleWindowEvent( event ) ;
- }
- if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & cmdKey )
- {
- event.m_keyCode = WXK_COMMAND ;
- event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
- focus->HandleWindowEvent( 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 ;
-bool g_lastButtonWasFakeRight = false ;
-
-void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent )
-{
- UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ;
- Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
-
- // these parameters are not given for all events
- EventMouseButton button = 0 ;
- UInt32 clickCount = 0 ;
- UInt32 mouseChord = 0;
-
- cEvent.GetParameter<EventMouseButton>( kEventParamMouseButton, typeMouseButton , &button ) ;
- cEvent.GetParameter<UInt32>( kEventParamClickCount, typeUInt32 , &clickCount ) ;
- // the chord is the state of the buttons pressed currently
- cEvent.GetParameter<UInt32>( kEventParamMouseChord, typeUInt32 , &mouseChord ) ;
-
- 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.m_clickCount = clickCount;
- wxevent.SetTimestamp( cEvent.GetTicks() ) ;
-
- // a control click is interpreted as a right click
- bool thisButtonIsFakeRight = false ;
- if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
- {
- button = kEventMouseButtonSecondary ;
- thisButtonIsFakeRight = true ;
- }
-
- // 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 ;
- g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
- }
-
- if ( button == 0 )
- {
- g_lastButton = 0 ;
- g_lastButtonWasFakeRight = false ;
- }
- else if ( g_lastButton == kEventMouseButtonSecondary && g_lastButtonWasFakeRight )
- button = g_lastButton ;
-
- // Adjust the chord mask to remove the primary button and add the
- // secondary button. It is possible that the secondary button is
- // already pressed, e.g. on a mouse connected to a laptop, but this
- // possibility is ignored here:
- if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
- mouseChord = ((mouseChord & ~1U) | 2U);
-
- if(mouseChord & 1U)
- wxevent.m_leftDown = true ;
- if(mouseChord & 2U)
- wxevent.m_rightDown = true ;
- if(mouseChord & 4U)
- wxevent.m_middleDown = true ;
-
- // 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 ;
-
- case kEventMouseEntered :
- case kEventMouseExited :
- case kEventMouseDragged :
- case kEventMouseMoved :
- wxevent.SetEventType( wxEVT_MOTION ) ;
- break;
- default :
- break ;
- }
-}
-
-#define NEW_CAPTURE_HANDLING 1
-
-pascal OSStatus
-wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(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 = FindControlUnderMouse( 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 = (wxWindow*) wxFindControlFromMacControl( control ) ;
-#ifndef __WXUNIVERSAL__
- 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 = (wxWindow*) wxFindControlFromMacControl( parent ) ;
- if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) )
- currentMouseWindow = wxParent ;
-#endif
- }
-#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->HandleWindowEvent(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->HandleWindowEvent(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 ) ;
- ::HiliteMenu(0);
- 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->HandleWindowEvent(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();
- }
- }
-
- 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 ) ;
-
- extern wxCursor gGlobalCursor;
-
- if (!gGlobalCursor.IsOk())
- {
- 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 ;
-
- 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 ;
-
- HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ;
- result = noErr ;
- }
- }
-
- return result ;
-}
-
-static pascal OSStatus
-wxMacTopLevelWindowEventHandler(EventHandlerCallRef WXUNUSED(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->HandleWindowEvent(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->HandleWindowEvent(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 )
- {
-#ifndef __WXUNIVERSAL__
- // 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();
- }
-#endif
- wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ;
- event.SetEventObject( toplevelWindow ) ;
-
- toplevelWindow->HandleWindowEvent(event) ;
- toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
- }
-
- if ( attributes & kWindowBoundsChangeOriginChanged )
- {
- wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ;
- event.SetEventObject( toplevelWindow ) ;
- toplevelWindow->HandleWindowEvent(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->HandleWindowEvent(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 ;
-
- case kEventWindowGetRegion :
- {
- if ( toplevelWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
- {
- WindowRegionCode windowRegionCode ;
-
- // Fetch the region code that is being queried
- GetEventParameter( event,
- kEventParamWindowRegionCode,
- typeWindowRegionCode, NULL,
- sizeof windowRegionCode, NULL,
- &windowRegionCode ) ;
-
- // If it is the opaque region code then set the
- // region to empty and return noErr to stop event
- // propagation
- if ( windowRegionCode == kWindowOpaqueRgn ) {
- RgnHandle region;
- GetEventParameter( event,
- kEventParamRgnHandle,
- typeQDRgnHandle, NULL,
- sizeof region, NULL,
- ®ion) ;
- SetEmptyRgn(region) ;
- 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 )
-
-// ---------------------------------------------------------------------------
-// wxWindowMac utility functions
-// ---------------------------------------------------------------------------
-
-// Find an item given the Macintosh Window Reference
-
-WX_DECLARE_HASH_MAP(WindowRef, wxTopLevelWindowMac*, wxPointerHash, wxPointerEqual, MacWindowMap);
-
-static MacWindowMap wxWinMacWindowList;
-
-wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
-{
- MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef);
-
- return (node == wxWinMacWindowList.end()) ? NULL : node->second;
-}
-
-void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ;
-void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win)
-{
- // adding NULL WindowRef is (first) surely a result of an error and
- // nothing else :-)
- wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
-
- wxWinMacWindowList[inWindowRef] = win;
-}
-
-void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ;
-void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
-{
- MacWindowMap::iterator it;
- for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it )
- {
- if ( it->second == win )
- {
- wxWinMacWindowList.erase(it);
- break;
- }
- }
-}
-