X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a979e444a3caa71811cdff39d55fea4a1ac9c7b6..0d1c8f39baaaeb7a7f757091209eab471ef5dbc4:/src/mac/carbon/toplevel.cpp diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index bdcba53822..7c57eeed86 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -24,9 +24,10 @@ #pragma hdrstop #endif +#include "wx/toplevel.h" + #ifndef WX_PRECOMP #include "wx/app.h" - #include "wx/toplevel.h" #include "wx/frame.h" #include "wx/string.h" #include "wx/log.h" @@ -38,7 +39,6 @@ #include "wx/mac/uma.h" #include "wx/mac/aga.h" -#include "wx/app.h" #include "wx/tooltip.h" #include "wx/dnd.h" @@ -86,14 +86,14 @@ 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 + + { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , + { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } , { kEventClassWindow , kEventWindowShown } , { kEventClassWindow , kEventWindowActivated } , @@ -112,60 +112,6 @@ static const EventTypeSpec eventList[] = { kEventClassMouse , kEventMouseDragged } , } ; -static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) -{ - OSStatus result = eventNotHandledErr ; - wxWindow* focus ; - UInt32 keyCode, modifiers ; - Point point ; - EventRef rawEvent ; - unsigned char charCode ; - - 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 ); - - focus = wxWindow::FindFocus() ; - - switch ( GetEventKind( event ) ) - { - case kEventTextInputUnicodeForKeyEvent : - // this is only called when no default handler has jumped in, e.g. a wxControl on a floater window does not - // get its own kEventTextInputUnicodeForKeyEvent, so we reroute the event back to the control - wxControl* control = wxDynamicCast( focus , wxControl ) ; - if ( control ) - { - ControlRef macControl = (ControlRef) control->GetHandle() ; - if ( macControl ) - { - ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; - result = noErr ; - } - } - -#if 0 - // 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 ; - } -#endif - break ; - - default: - break ; - } - - return result ; -} - static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; @@ -176,7 +122,10 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event focus = (wxTopLevelWindowMac*) data ; unsigned char charCode ; - wxChar uniChar = 0 ; + wxChar uniChar[2] ; + uniChar[0] = 0; + uniChar[1] = 0; + UInt32 keyCode ; UInt32 modifiers ; Point point ; @@ -187,21 +136,23 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr ) { UniChar buf[2] ; + int numChars = dataSize / sizeof( UniChar) + 1; UniChar* charBuf = buf ; - if ( dataSize > 4 ) - charBuf = new UniChar[ dataSize / sizeof( UniChar) ] ; + 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 , 1 ) ; + converter.MB2WC( uniChar , (const char*)charBuf , 2 ) ; #endif - if ( dataSize > 4 ) + if ( numChars * 2 > 4 ) delete[] charBuf ; } #endif @@ -221,7 +172,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; wxTheApp->MacSetCurrentEvent( event , handler ) ; if ( /* focus && */ wxTheApp->MacSendKeyDownEvent( - focus , message , modifiers , when , point.h , point.v , uniChar ) ) + focus , message , modifiers , when , point.h , point.v , uniChar[0] ) ) { result = noErr ; } @@ -231,7 +182,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event case kEventRawKeyUp : if ( /* focus && */ wxTheApp->MacSendKeyUpEvent( - focus , message , modifiers , when , point.h , point.v , uniChar ) ) + focus , message , modifiers , when , point.h , point.v , uniChar[0] ) ) { result = noErr ; } @@ -249,7 +200,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event event.m_y = point.v; #if wxUSE_UNICODE - event.m_uniChar = uniChar ; + event.m_uniChar = uniChar[0] ; #endif event.SetTimestamp(when); @@ -502,7 +453,7 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev Point screenMouseLocation = cEvent.GetParameter(kEventParamMouseLocation) ; Point windowMouseLocation = screenMouseLocation ; - WindowRef window ; + WindowRef window = NULL; short windowPart = ::FindWindow(screenMouseLocation, &window); wxWindow* currentMouseWindow = NULL ; @@ -553,6 +504,10 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev #endif } } + + // disabled windows must not get any input messages + if ( currentMouseWindow && !currentMouseWindow->MacIsReallyEnabled() ) + currentMouseWindow = NULL; } } @@ -617,9 +572,7 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev // make tooltips current #if wxUSE_TOOLTIPS - if ( wxevent.GetEventType() == wxEVT_MOTION - || wxevent.GetEventType() == wxEVT_ENTER_WINDOW - || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW ) + if ( wxevent.GetEventType() == wxEVT_MOTION ) wxToolTip::RelayEvent( currentMouseWindow , wxevent ); #endif @@ -694,8 +647,8 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev cursorPoint += cursorTarget->GetPosition(); } - } // else if ( currentMouseWindow ) - else + } + 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 @@ -704,17 +657,17 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev { EventModifiers modifiers = cEvent.GetParameter(kEventParamKeyModifiers, typeUInt32) ; Point clickLocation = windowMouseLocation ; +#if TARGET_API_MAC_OSX if ( toplevelWindow->MacUsesCompositing() ) { -#ifdef __WXMAC_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 } +#endif // TARGET_API_MAC_OSX HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ; result = noErr ; @@ -779,12 +732,7 @@ static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef hand wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ; if ( frame ) { -#if wxUSE_STATUSBAR - frame->PositionStatusBar(); -#endif -#if wxUSE_TOOLBAR - frame->PositionToolBar(); -#endif + frame->PositionBars(); } wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ; @@ -854,18 +802,21 @@ static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef hand 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 kEventClassKeyboard : - result = KeyboardEventHandler( handler, event , data ) ; + case kEventClassTextInput : + result = wxMacUnicodeTextEventHandler( handler, event , data ) ; break ; - case kEventClassTextInput : - result = TextInputEventHandler( handler, event , data ) ; + case kEventClassKeyboard : + result = KeyboardEventHandler( handler, event , data ) ; break ; case kEventClassWindow : @@ -936,6 +887,7 @@ typedef struct { wxPoint m_position ; wxSize m_size ; + bool m_wasResizable ; } FullScreenData ; @@ -1043,7 +995,7 @@ void wxTopLevelWindowMac::Maximize(bool maximize) wxMacPortStateHelper help( (GrafPtr)GetWindowPort( (WindowRef)m_macWindow) ) ; wxMacWindowClipper clip( this ); #endif - +#if 0 if ( !IsWindowInStandardState( (WindowRef)m_macWindow, NULL, NULL ) ) { Rect rect; @@ -1052,8 +1004,18 @@ void wxTopLevelWindowMac::Maximize(bool maximize) SetWindowIdealUserState((WindowRef)m_macWindow, &rect); SetWindowUserState((WindowRef)m_macWindow, &rect); } - ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ; +#else + Point idealSize = { 0 , 0 } ; + if ( maximize ) + { + Rect rect ; + GetAvailableWindowPositioningBounds(GetMainDevice(),&rect) ; + idealSize.h = rect.right - rect.left ; + idealSize.v = rect.bottom - rect.top ; + } + ZoomWindowIdeal( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , &idealSize ) ; +#endif } bool wxTopLevelWindowMac::IsMaximized() const @@ -1272,7 +1234,9 @@ void wxTopLevelWindowMac::MacCreateRealWindow( // the root control level handler MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; -#if TARGET_API_MAC_OSX + // Causes the inner part of the window not to be metal + // if the style is used before window creation. +#if 0 // TARGET_API_MAC_OSX if ( m_macUsesCompositing && m_macWindow != NULL ) { if ( GetExtraStyle() & wxFRAME_EX_METAL ) @@ -1355,22 +1319,21 @@ bool wxTopLevelWindowMac::Show(bool show) if ( !wxTopLevelWindowBase::Show(show) ) return false; - if (show) - { + bool plainTransition = false; + #if wxUSE_SYSTEM_OPTIONS - // code contributed by Ryan Wilcox December 18, 2003 - bool plainTransition = UMAGetSystemVersion() >= 0x1000 ; - if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) - plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ; + // code contributed by Ryan Wilcox December 18, 2003 + plainTransition = UMAGetSystemVersion() >= 0x1000 ; + if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) + plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ; +#endif + if (show) + { if ( plainTransition ) ::ShowWindow( (WindowRef)m_macWindow ); else ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL ); -#else - - ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL ); -#endif ::SelectWindow( (WindowRef)m_macWindow ) ; @@ -1381,19 +1344,10 @@ bool wxTopLevelWindowMac::Show(bool show) } else { -#if wxUSE_SYSTEM_OPTIONS - bool plainTransition = UMAGetSystemVersion() >= 0x1000 ; - if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) - plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ; if ( plainTransition ) - { - ::HideWindow((WindowRef) m_macWindow ); - } + ::HideWindow( (WindowRef)m_macWindow ); else -#endif - { - ::TransitionWindow((WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL ); - } + ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL ); } MacPropagateVisibilityChanged() ; @@ -1412,6 +1366,7 @@ bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) m_macFullScreenData = data ; data->m_position = GetPosition() ; data->m_size = GetSize() ; + data->m_wasResizable = MacGetWindowAttributes() & kWindowResizableAttribute ; if ( style & wxFULLSCREEN_NOMENUBAR ) HideMenuBar() ; @@ -1452,11 +1407,15 @@ bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) } SetSize( x , y , w, h ) ; + if ( data->m_wasResizable ) + MacChangeWindowAttributes( kWindowNoAttributes , kWindowResizableAttribute ) ; } else { ShowMenuBar() ; FullScreenData *data = (FullScreenData *) m_macFullScreenData ; + if ( data->m_wasResizable ) + MacChangeWindowAttributes( kWindowResizableAttribute , kWindowNoAttributes ) ; SetPosition( data->m_position ) ; SetSize( data->m_size ) ; @@ -1472,11 +1431,11 @@ bool wxTopLevelWindowMac::IsFullScreen() const return m_macFullScreenData != NULL ; } -void wxTopLevelWindowMac::SetExtraStyle(long exStyle) +void wxTopLevelWindowMac::SetExtraStyle(long exStyle) { if ( GetExtraStyle() == exStyle ) return ; - + wxTopLevelWindowBase::SetExtraStyle( exStyle ) ; #if TARGET_API_MAC_OSX @@ -1489,12 +1448,13 @@ void wxTopLevelWindowMac::SetExtraStyle(long exStyle) #endif } -// we are still using coordinates of the content view; TODO: switch to structure bounds - +// TODO: switch to structure bounds - +// we are still using coordinates of the content view +// void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) { - Rect content ; - Rect structure ; + Rect content, structure ; + GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ; GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ; @@ -1839,4 +1799,3 @@ static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 return 0; } -