X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/03647350fc7cd141953c72e0284e928847d30f44..47e175a24f862aa8b7ca7dd4a2bb5957991e7f2d:/src/osx/carbon/nonownedwnd.cpp diff --git a/src/osx/carbon/nonownedwnd.cpp b/src/osx/carbon/nonownedwnd.cpp index db30cb846c..45344b01a6 100644 --- a/src/osx/carbon/nonownedwnd.cpp +++ b/src/osx/carbon/nonownedwnd.cpp @@ -3,7 +3,7 @@ // Purpose: implementation of wxNonOwnedWindow // Author: Stefan Csomor // Created: 2008-03-24 -// RCS-ID: $Id: nonownedwnd.cpp 50329 2007-11-29 17:00:58Z VS $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor 2008 // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -51,6 +51,21 @@ void wxNonOwnedWindowCarbonImpl::Lower() ::SendBehind( m_macWindow , NULL ) ; } +void wxNonOwnedWindowCarbonImpl::ShowWithoutActivating() +{ + bool plainTransition = true; + +#if wxUSE_SYSTEM_OPTIONS + if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) + plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ; +#endif + + if ( plainTransition ) + ::ShowWindow( (WindowRef)m_macWindow ); + else + ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL ); +} + bool wxNonOwnedWindowCarbonImpl::Show(bool show) { bool plainTransition = true; @@ -62,14 +77,8 @@ bool wxNonOwnedWindowCarbonImpl::Show(bool show) if (show) { -#if wxOSX_USE_CARBON - if ( plainTransition ) - ::ShowWindow( (WindowRef)m_macWindow ); - else - ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL ); - + ShowWithoutActivating(); ::SelectWindow( (WindowRef)m_macWindow ) ; -#endif } else { @@ -228,12 +237,12 @@ void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set ) set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ; // For some reason, Tiger uses white as the background color for this appearance, - // while most apps using it use the typical striped background. Restore that behavior + // while most apps using it use the typical striped background. Restore that behaviour // for wx. // TODO: Determine if we need this on Leopard as well. (should be harmless either way, // though) // since when creating the peering is not yet completely set-up we call both setters - // explicitely + // explicitly m_wxPeer->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ; SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ; } @@ -245,6 +254,7 @@ void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set ) static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); +WXDLLEXPORT void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ); // --------------------------------------------------------------------------- // Carbon Events @@ -296,7 +306,6 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event UInt32 keyCode ; UInt32 modifiers ; - Point point ; UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; #if wxUSE_UNICODE @@ -313,22 +322,17 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event 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 +#endif // wxUSE_UNICODE - GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode ); + GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, 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 ) ) @@ -340,7 +344,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[0] ) ) + focus , message , modifiers , when , uniChar[0] ) ) { result = noErr ; } @@ -350,7 +354,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event case kEventRawKeyUp : if ( /* focus && */ wxTheApp->MacSendKeyUpEvent( - focus , message , modifiers , when , point.h , point.v , uniChar[0] ) ) + focus , message , modifiers , when , uniChar[0] ) ) { result = noErr ; } @@ -361,11 +365,9 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event wxKeyEvent event(wxEVT_KEY_DOWN); event.m_shiftDown = modifiers & shiftKey; - event.m_controlDown = modifiers & controlKey; + event.m_rawControlDown = modifiers & controlKey; event.m_altDown = modifiers & optionKey; - event.m_metaDown = modifiers & cmdKey; - event.m_x = point.h; - event.m_y = point.v; + event.m_controlDown = event.m_metaDown = modifiers & cmdKey; #if wxUSE_UNICODE event.m_uniChar = uniChar[0] ; @@ -376,7 +378,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & controlKey ) { - event.m_keyCode = WXK_CONTROL ; + event.m_keyCode = WXK_RAW_CONTROL ; event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->HandleWindowEvent( event ) ; } @@ -394,7 +396,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event } if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & cmdKey ) { - event.m_keyCode = WXK_COMMAND ; + event.m_keyCode = WXK_CONTROL; event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->HandleWindowEvent( event ) ; } @@ -419,7 +421,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event EventMouseButton g_lastButton = 0 ; bool g_lastButtonWasFakeRight = false ; -void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) +WXDLLEXPORT void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) { UInt32 modifiers = cEvent.GetParameter(kEventParamKeyModifiers, typeUInt32) ; Point screenMouseLocation = cEvent.GetParameter(kEventParamMouseLocation) ; @@ -437,9 +439,9 @@ void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) wxevent.m_x = screenMouseLocation.h; wxevent.m_y = screenMouseLocation.v; wxevent.m_shiftDown = modifiers & shiftKey; - wxevent.m_controlDown = modifiers & controlKey; + wxevent.m_rawControlDown = modifiers & controlKey; wxevent.m_altDown = modifiers & optionKey; - wxevent.m_metaDown = modifiers & cmdKey; + wxevent.m_controlDown = wxevent.m_metaDown = modifiers & cmdKey; wxevent.m_clickCount = clickCount; wxevent.SetTimestamp( cEvent.GetTicks() ) ; @@ -528,8 +530,9 @@ void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) break ; } break ; - - case kEventMouseWheelMoved : + // TODO http://developer.apple.com/qa/qa2005/qa1453.html + // add declaration for 10.4 and change to kEventMouseScroll + case kEventMouseWheelMoved : { wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ; @@ -540,7 +543,7 @@ void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) wxevent.m_wheelDelta = 1; wxevent.m_linesPerAction = 1; if ( axis == kEventMouseWheelAxisX ) - wxevent.m_wheelAxis = 1; + wxevent.m_wheelAxis = wxMOUSE_WHEEL_HORIZONTAL; } break ; @@ -711,8 +714,8 @@ wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(handler), if ( currentMouseWindow->HandleWindowEvent(wxevent) ) { - if ((currentMouseWindowParent != NULL) && - (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL)) + if ( currentMouseWindowParent && + !currentMouseWindowParent->GetChildren().Member(currentMouseWindow) ) currentMouseWindow = NULL; result = noErr; @@ -919,7 +922,7 @@ wxNonOwnedWindowEventHandler(EventHandlerCallRef WXUNUSED(handler), // mix this in from window.cpp pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ; -pascal OSStatus wxNonOwnedEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +static pascal OSStatus wxNonOwnedEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; @@ -1124,7 +1127,7 @@ wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl() m_macEventHandler = NULL ; } - if ( m_macWindow ) + if ( m_macWindow && !m_wxPeer->IsNativeWindowWrapper()) DisposeWindow( m_macWindow ); FullScreenData *data = (FullScreenData *) m_macFullScreenData ; @@ -1135,18 +1138,16 @@ wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl() } -void wxNonOwnedWindowCarbonImpl::Destroy() +void wxNonOwnedWindowCarbonImpl::WillBeDestroyed() { if ( m_macEventHandler ) { ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); m_macEventHandler = NULL ; } - - wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) ) ; } -void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref) +static void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref) { InstallWindowEventHandler(window, GetwxNonOwnedEventHandlerUPP(), GetEventTypeCount(eventList), eventList, ref, handler ); @@ -1183,11 +1184,18 @@ void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler() } void wxNonOwnedWindowCarbonImpl::Create( - wxWindow* parent, - const wxPoint& pos, - const wxSize& size, - long style, long extraStyle, - const wxString& WXUNUSED(name) ) + wxWindow* WXUNUSED(parent), + WXWindow nativeWindow ) +{ + m_macWindow = nativeWindow; +} + +void wxNonOwnedWindowCarbonImpl::Create( + wxWindow* parent, + const wxPoint& pos, + const wxSize& size, + long style, long extraStyle, + const wxString& WXUNUSED(name) ) { OSStatus err = noErr ; @@ -1213,7 +1221,7 @@ void wxNonOwnedWindowCarbonImpl::Create( if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) || ( style & wxSYSTEM_MENU ) || ( style & wxCAPTION ) || - ( style &wxTINY_CAPTION_HORIZ) || ( style &wxTINY_CAPTION_VERT) + ( style & wxTINY_CAPTION) ) { if ( ( style & wxSTAY_ON_TOP ) ) @@ -1221,7 +1229,7 @@ void wxNonOwnedWindowCarbonImpl::Create( else wclass = kFloatingWindowClass ; - if ( ( style &wxTINY_CAPTION_VERT) ) + if ( ( style & wxTINY_CAPTION) ) attr |= kWindowSideTitlebarAttribute ; } else @@ -1320,13 +1328,13 @@ void wxNonOwnedWindowCarbonImpl::Create( customWindowDefSpec.defType = kWindowDefProcPtr; customWindowDefSpec.u.defProc = #ifdef __LP64__ - (WindowDefUPP) wxShapedMacWindowDef; + (WindowDefUPP) wxShapedMacWindowDef; #else - NewWindowDefUPP(wxShapedMacWindowDef); + NewWindowDefUPP(wxShapedMacWindowDef); #endif err = ::CreateCustomWindow( &customWindowDefSpec, wclass, - attr, &theBoundsRect, - (WindowRef*) &m_macWindow); + attr, &theBoundsRect, + (WindowRef*) &m_macWindow); } else { @@ -1419,6 +1427,11 @@ bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show, transition = kWindowZoomTransitionEffect; break; + case wxSHOW_EFFECT_NONE: + // wxNonOwnedWindow is supposed to call Show() itself in this case + wxFAIL_MSG( "ShowWithEffect() shouldn't be called" ); + return false; + case wxSHOW_EFFECT_MAX: wxFAIL_MSG( "invalid effect flag" ); return false; @@ -1664,6 +1677,11 @@ void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x, int *y ) *y = (int)p.y; } +bool wxNonOwnedWindowCarbonImpl::IsActive() +{ + return ActiveNonFloatingWindow() == m_macWindow; +} + wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, long style, long extraStyle, const wxString& name ) { @@ -1671,3 +1689,11 @@ wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWind now->Create( parent, pos, size, style , extraStyle, name ); return now; } + +wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow ) +{ + wxNonOwnedWindowCarbonImpl* now = new wxNonOwnedWindowCarbonImpl( wxpeer ); + now->Create( parent, nativeWindow ); + return now; +} +