X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f1c8bd4d13ee2e1a6830c68770b7acdad7ca946..a71dec776e22b9bdaa73027d67ec5c0c7d0b21df:/src/mac/carbon/toplevel.cpp diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index 0b7780598c..0723699637 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -36,6 +36,7 @@ #include "wx/log.h" #include "wx/intl.h" #include "wx/settings.h" + #include "wx/strconv.h" #include "wx/control.h" #endif //WX_PRECOMP @@ -167,17 +168,40 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event return result ; char charCode ; + wxChar uniChar = 0 ; UInt32 keyCode ; UInt32 modifiers ; Point point ; UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; +#if wxUSE_UNICODE + UInt32 dataSize = 0 ; + if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize , NULL ) == noErr ) + { + UniChar buf[2] ; + + UniChar* charBuf = buf ; + + if ( dataSize > 4 ) + charBuf = new UniChar[ dataSize / sizeof( UniChar) ] ; + GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ; +#if SIZEOF_WCHAR_T == 2 + uniChar = charBuf[0] ; +#else + wxMBConvUTF16BE converter ; + converter.MB2WC( &uniChar , (const char*)charBuf , 1 ) ; +#endif + if ( dataSize > 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 ) ) { @@ -188,7 +212,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; wxTheApp->MacSetCurrentEvent( event , handler ) ; if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( - focus , message , modifiers , when , point.h , point.v ) ) + focus , message , modifiers , when , point.h , point.v , uniChar ) ) { result = noErr ; } @@ -197,7 +221,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event break ; case kEventRawKeyUp : if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( - focus , message , modifiers , when , point.h , point.v ) ) + focus , message , modifiers , when , point.h , point.v , uniChar ) ) { result = noErr ; } @@ -210,37 +234,39 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event event.m_controlDown = modifiers & controlKey; event.m_altDown = modifiers & optionKey; event.m_metaDown = modifiers & cmdKey; - +#if wxUSE_UNICODE + event.m_uniChar = uniChar ; +#endif event.m_x = point.h; event.m_y = point.v; event.SetTimestamp(when); event.SetEventObject(focus); - if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey ) + 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 ^ wxTheApp->s_lastModifiers ) & shiftKey ) + 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 ^ wxTheApp->s_lastModifiers ) & optionKey ) + 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 ^ wxTheApp->s_lastModifiers ) & cmdKey ) + 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 ) ; } - wxTheApp->s_lastModifiers = modifiers ; + wxApp::s_lastModifiers = modifiers ; } break ; } @@ -282,6 +308,10 @@ static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) button = kEventMouseButtonSecondary ; } + // otherwise we report double clicks by connecting a left click with a ctrl-left click + if ( clickCount > 1 && button != 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 @@ -438,9 +468,9 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev { QDGlobalToLocalPoint( UMAGetWindowPort(window ) , &windowMouseLocation ) ; - if ( wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent ) + if ( wxApp::s_captureWindow && wxApp::s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent ) { - currentMouseWindow = wxTheApp->s_captureWindow ; + currentMouseWindow = wxApp::s_captureWindow ; } else if ( (IsWindowActive(window) && windowPart == inContent) ) { @@ -575,9 +605,9 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev result = noErr ; } } - if ( cEvent.GetKind() == kEventMouseUp && wxTheApp->s_captureWindow ) + if ( cEvent.GetKind() == kEventMouseUp && wxApp::s_captureWindow ) { - wxTheApp->s_captureWindow = NULL ; + wxApp::s_captureWindow = NULL ; // update cursor ? } @@ -685,6 +715,7 @@ static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef hand event.SetEventObject( toplevelWindow ) ; toplevelWindow->GetEventHandler()->ProcessEvent(event) ; + toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified } if ( attributes & kWindowBoundsChangeOriginChanged ) { @@ -725,6 +756,7 @@ static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef hand 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( kEventParamCurrentBounds , &adjustedRect ) ; + toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified } result = noErr ; @@ -899,6 +931,9 @@ bool wxTopLevelWindowMac::Create(wxWindow *parent, MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); + + if (GetExtraStyle() & wxFRAME_EX_METAL) + MacSetMetalAppearance(true); wxTopLevelWindows.Append(this); @@ -912,7 +947,9 @@ wxTopLevelWindowMac::~wxTopLevelWindowMac() { if ( m_macWindow ) { +#if wxUSE_TOOLTIPS wxToolTip::NotifyWindowDelete(m_macWindow) ; +#endif wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; } @@ -1081,19 +1118,19 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, } } - if ( HasFlag( wxMINIMIZE_BOX ) ) + if ( HasFlag( wxMINIMIZE_BOX ) && wclass != kPlainWindowClass ) { attr |= kWindowCollapseBoxAttribute ; } - if ( HasFlag( wxMAXIMIZE_BOX ) ) + if ( HasFlag( wxMAXIMIZE_BOX ) && wclass != kPlainWindowClass ) { attr |= kWindowFullZoomAttribute ; } - if ( HasFlag( wxRESIZE_BORDER ) ) + if ( HasFlag( wxRESIZE_BORDER ) && wclass != kPlainWindowClass ) { attr |= kWindowResizableAttribute ; } - if ( HasFlag( wxCLOSE_BOX) ) + if ( HasFlag( wxCLOSE_BOX) && wclass != kPlainWindowClass ) { attr |= kWindowCloseBoxAttribute ; } @@ -1166,6 +1203,8 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; MacInstallTopLevelWindowEventHandler() ; + DoSetWindowVariant( m_windowVariant ) ; + m_macFocus = NULL ; if ( HasFlag(wxFRAME_SHAPED) ) @@ -1347,8 +1386,10 @@ void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &ri void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) { + m_cachedClippedRectValid = false ; Rect bounds = { y , x , y + height , x + width } ; verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; + wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified } void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const @@ -1406,6 +1447,58 @@ wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const return attr ; } +void wxTopLevelWindowMac::MacPerformUpdates() +{ +#if TARGET_API_MAC_OSX + if ( m_macUsesCompositing ) + { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 + // for composited windows this also triggers a redraw of all + // invalid views in the window + if( UMAGetSystemVersion() >= 0x1030 ) + HIWindowFlush((WindowRef) m_macWindow) ; + else +#endif + { + // the only way to trigger the redrawing on earlier systems is to call + // ReceiveNextEvent + + EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; + UInt32 currentEventClass = 0 ; + UInt32 currentEventKind = 0 ; + if ( currentEvent != NULL ) + { + currentEventClass = ::GetEventClass( currentEvent ) ; + currentEventKind = ::GetEventKind( currentEvent ) ; + } + if ( currentEventClass != kEventClassMenu ) + { + // when tracking a menu, strange redraw errors occur if we flush now, so leave.. + EventRef theEvent; + OSStatus status = noErr ; + status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ; + } + } + } + else +#endif + { + BeginUpdate( (WindowRef) m_macWindow ) ; + + RgnHandle updateRgn = NewRgn(); + if ( updateRgn ) + { + GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); + UpdateControls( (WindowRef)m_macWindow , updateRgn ) ; + // if ( !EmptyRgn( updateRgn ) ) + // MacDoRedraw( updateRgn , 0 , true) ; + DisposeRgn( updateRgn ); + } + EndUpdate( (WindowRef)m_macWindow ) ; + QDFlushPortBuffer( GetWindowPort( (WindowRef)m_macWindow ) , NULL ) ; + } +} + // Attracts the users attention to this window if the application is // inactive (should be called when a background event occurs)