X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b12a7313f55208ffde4f002838ebf8a7d63c91ba..47e175a24f862aa8b7ca7dd4a2bb5957991e7f2d:/src/osx/carbon/nonownedwnd.cpp diff --git a/src/osx/carbon/nonownedwnd.cpp b/src/osx/carbon/nonownedwnd.cpp index 98644d6f0b..45344b01a6 100644 --- a/src/osx/carbon/nonownedwnd.cpp +++ b/src/osx/carbon/nonownedwnd.cpp @@ -1,9 +1,9 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/nonownedwnd.cpp +// Name: src/osx/carbon/nonownedwnd.cpp // 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 ///////////////////////////////////////////////////////////////////////////// @@ -28,374 +28,15 @@ #include "wx/sysopt.h" #endif -// -// TODO BEGIN move to nonowned_osx.cpp -// - -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -// trace mask for activation tracing messages -#define TRACE_ACTIVATE "activation" - -wxWindow* g_MacLastWindow = NULL ; +// ============================================================================ +// wxNonOwnedWindow implementation +// ============================================================================ // unified title and toolbar constant - not in Tiger headers, so we duplicate it here #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7) -// --------------------------------------------------------------------------- -// wxWindowMac utility functions -// --------------------------------------------------------------------------- - -// Find an item given the Macintosh Window Reference - -WX_DECLARE_HASH_MAP(WXWindow, wxNonOwnedWindow*, wxPointerHash, wxPointerEqual, MacWindowMap); - -static MacWindowMap wxWinMacWindowList; - -wxNonOwnedWindow *wxFindWindowFromWXWindow(WXWindow inWindowRef) -{ - MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef); - - return (node == wxWinMacWindowList.end()) ? NULL : node->second; -} - -void wxAssociateWindowWithWXWindow(WXWindow inWindowRef, wxNonOwnedWindow *win) ; -void wxAssociateWindowWithWXWindow(WXWindow inWindowRef, wxNonOwnedWindow *win) -{ - // adding NULL WindowRef is (first) surely a result of an error and - // nothing else :-) - wxCHECK_RET( inWindowRef != (WXWindow) NULL, wxT("attempt to add a NULL WindowRef to window list") ); - - wxWinMacWindowList[inWindowRef] = win; -} - -void wxRemoveWXWindowAssociation(wxNonOwnedWindow *win) ; -void wxRemoveWXWindowAssociation(wxNonOwnedWindow *win) -{ - MacWindowMap::iterator it; - for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it ) - { - if ( it->second == win ) - { - wxWinMacWindowList.erase(it); - break; - } - } -} - -wxNonOwnedWindow* wxNonOwnedWindow::GetFromWXWindow( WXWindow win ) -{ - return wxFindWindowFromWXWindow( win ); -} - -// ---------------------------------------------------------------------------- -// wxNonOwnedWindow creation -// ---------------------------------------------------------------------------- - -IMPLEMENT_ABSTRACT_CLASS( wxNonOwnedWindowImpl , wxObject ) - -wxNonOwnedWindow *wxNonOwnedWindow::s_macDeactivateWindow = NULL; - -void wxNonOwnedWindow::Init() -{ - m_nowpeer = NULL; -} - -bool wxNonOwnedWindow::Create(wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - // init our fields - Init(); - - m_windowStyle = style; - - SetName( name ); - - m_windowId = id == -1 ? NewControlId() : id; - m_windowStyle = style; - m_isShown = false; - - // create frame. - int x = (int)pos.x; - int y = (int)pos.y; - - wxRect display = wxGetClientDisplayRect() ; - - if ( x == wxDefaultPosition.x ) - x = display.x ; - - if ( y == wxDefaultPosition.y ) - y = display.y ; - - int w = WidthDefault(size.x); - int h = HeightDefault(size.y); - - // temporary define, TODO -#if wxOSX_USE_CARBON - m_nowpeer = new wxNonOwnedWindowCarbonImpl( this ); -#elif wxOSX_USE_COCOA - m_nowpeer = new wxNonOwnedWindowCocoaImpl( this ); -#elif wxOSX_USE_IPHONE - m_nowpeer = new wxNonOwnedWindowIPhoneImpl( this ); -#endif - - m_nowpeer->Create( parent, wxPoint(x,y) , wxSize(w,h) , style , GetExtraStyle(), name ) ; - wxAssociateWindowWithWXWindow( m_nowpeer->GetWXWindow() , this ) ; -#if wxOSX_USE_CARBON - // temporary cast, TODO - m_peer = (wxMacControl*) wxWidgetImpl::CreateContentView(this); -#else - m_peer = wxWidgetImpl::CreateContentView(this); -#endif - - DoSetWindowVariant( m_windowVariant ) ; - - wxWindowCreateEvent event(this); - HandleWindowEvent(event); - - SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE )); - - if ( parent ) - parent->AddChild(this); - - return true; -} - -wxNonOwnedWindow::~wxNonOwnedWindow() -{ - wxRemoveWXWindowAssociation( this ) ; - if ( m_nowpeer ) - m_nowpeer->Destroy(); - - // avoid dangling refs - if ( s_macDeactivateWindow == this ) - s_macDeactivateWindow = NULL; -} - -// ---------------------------------------------------------------------------- -// wxNonOwnedWindow misc -// ---------------------------------------------------------------------------- - -bool wxNonOwnedWindow::ShowWithEffect(wxShowEffect effect, - unsigned timeout ) -{ - if ( !wxWindow::Show(true) ) - return false; - - // because apps expect a size event to occur at this moment - wxSizeEvent event(GetSize() , m_windowId); - event.SetEventObject(this); - HandleWindowEvent(event); - - - return m_nowpeer->ShowWithEffect(true, effect, timeout); -} - -bool wxNonOwnedWindow::HideWithEffect(wxShowEffect effect, - unsigned timeout ) -{ - if ( !wxWindow::Show(false) ) - return false; - - return m_nowpeer->ShowWithEffect(false, effect, timeout); -} - -wxPoint wxNonOwnedWindow::GetClientAreaOrigin() const -{ - int left, top, width, height; - m_nowpeer->GetContentArea(left, top, width, height); - return wxPoint(left, top); -} - -bool wxNonOwnedWindow::SetBackgroundColour(const wxColour& c ) -{ - if ( !wxWindow::SetBackgroundColour(c) && m_hasBgCol ) - return false ; - - if ( GetBackgroundStyle() != wxBG_STYLE_CUSTOM ) - { - return m_nowpeer->SetBackgroundColour(c); - } - return true; -} - -// Raise the window to the top of the Z order -void wxNonOwnedWindow::Raise() -{ - m_nowpeer->Raise(); -} - -// Lower the window to the bottom of the Z order -void wxNonOwnedWindow::Lower() -{ - m_nowpeer->Lower(); -} - -void wxNonOwnedWindow::MacDelayedDeactivation(long timestamp) -{ - if (s_macDeactivateWindow) - { - wxLogTrace(TRACE_ACTIVATE, - wxT("Doing delayed deactivation of %p"), - s_macDeactivateWindow); - - s_macDeactivateWindow->MacActivate(timestamp, false); - } -} - -void wxNonOwnedWindow::MacActivate( long timestamp , bool WXUNUSED(inIsActivating) ) -{ - wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this); - - if (s_macDeactivateWindow == this) - s_macDeactivateWindow = NULL; - - MacDelayedDeactivation(timestamp); -} - -bool wxNonOwnedWindow::Show(bool show) -{ - if ( !wxWindow::Show(show) ) - return false; - - if ( m_nowpeer ) - m_nowpeer->Show(show); - - if ( show ) - { - // because apps expect a size event to occur at this moment - wxSizeEvent event(GetSize() , m_windowId); - event.SetEventObject(this); - HandleWindowEvent(event); - } - - return true ; -} - -bool wxNonOwnedWindow::SetTransparent(wxByte alpha) -{ - return m_nowpeer->SetTransparent(alpha); -} - - -bool wxNonOwnedWindow::CanSetTransparent() -{ - return m_nowpeer->CanSetTransparent(); -} - - -void wxNonOwnedWindow::SetExtraStyle(long exStyle) -{ - if ( GetExtraStyle() == exStyle ) - return ; - - wxWindow::SetExtraStyle( exStyle ) ; - - if ( m_nowpeer ) - m_nowpeer->SetExtraStyle(exStyle); -} - -bool wxNonOwnedWindow::SetBackgroundStyle(wxBackgroundStyle style) -{ - if ( !wxWindow::SetBackgroundStyle(style) ) - return false ; - - return m_nowpeer->SetBackgroundStyle(style); -} - -void wxNonOwnedWindow::DoMoveWindow(int x, int y, int width, int height) -{ - m_cachedClippedRectValid = false ; - - m_nowpeer->MoveWindow(x, y, width, height); - wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified -} - -void wxNonOwnedWindow::DoGetPosition( int *x, int *y ) const -{ - int x1,y1 ; - m_nowpeer->GetPosition(x1, y1); - - if (x) - *x = x1 ; - if (y) - *y = y1 ; -} - -void wxNonOwnedWindow::DoGetSize( int *width, int *height ) const -{ - int w,h; - - m_nowpeer->GetSize(w, h); - - if (width) - *width = w ; - if (height) - *height = h ; -} - -void wxNonOwnedWindow::DoGetClientSize( int *width, int *height ) const -{ - int left, top, w, h; - m_nowpeer->GetContentArea(left, top, w, h); - - if (width) - *width = w ; - if (height) - *height = h ; -} - - -void wxNonOwnedWindow::Update() -{ - m_nowpeer->Update(); -} - -WXWindow wxNonOwnedWindow::GetWXWindow() const -{ - return m_nowpeer ? m_nowpeer->GetWXWindow() : NULL; -} - -// --------------------------------------------------------------------------- -// Shape implementation -// --------------------------------------------------------------------------- - - -bool wxNonOwnedWindow::SetShape(const wxRegion& region) -{ - wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false, - _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); - - // The empty region signifies that the shape - // should be removed from the window. - if ( region.IsEmpty() ) - { - wxSize sz = GetClientSize(); - wxRegion rgn(0, 0, sz.x, sz.y); - if ( rgn.IsEmpty() ) - return false ; - else - return SetShape(rgn); - } - - return m_nowpeer->SetShape(region); -} - -// -// TODO END move to nonowned_osx.cpp -// - -#if wxOSX_USE_CARBON - IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCarbonImpl , wxNonOwnedWindowImpl ) - WXWindow wxNonOwnedWindowCarbonImpl::GetWXWindow() const { return (WXWindow) m_macWindow; @@ -410,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; @@ -421,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 { @@ -458,12 +108,18 @@ bool wxNonOwnedWindowCarbonImpl::SetBackgroundColour(const wxColour& col ) if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground)) ) { SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDocumentWindowBackground, false ) ; - SetBackgroundStyle(wxBG_STYLE_SYSTEM); + m_wxPeer->SetBackgroundStyle(wxBG_STYLE_SYSTEM); + // call directly if object is not yet completely constructed + if ( m_wxPeer->GetNonOwnedPeer() == NULL ) + SetBackgroundStyle(wxBG_STYLE_SYSTEM); } else if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive)) ) { SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDialogBackgroundActive, false ) ; - SetBackgroundStyle(wxBG_STYLE_SYSTEM); + m_wxPeer->SetBackgroundStyle(wxBG_STYLE_SYSTEM); + // call directly if object is not yet completely constructed + if ( m_wxPeer->GetNonOwnedPeer() == NULL ) + SetBackgroundStyle(wxBG_STYLE_SYSTEM); } return true; } @@ -485,7 +141,7 @@ void wxNonOwnedWindowCarbonImpl::SetExtraStyle( long exStyle ) } bool wxNonOwnedWindowCarbonImpl::SetBackgroundStyle(wxBackgroundStyle style) -{ +{ if ( style == wxBG_STYLE_TRANSPARENT ) { OSStatus err = HIWindowChangeFeatures( m_macWindow, 0, kWindowIsOpaque ); @@ -581,11 +237,14 @@ 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 + // explicitly m_wxPeer->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ; + SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ; } @@ -595,12 +254,7 @@ void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set ) static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); -// ============================================================================ -// wxNonOwnedWindow implementation -// ============================================================================ - -// unified title and toolbar constant - not in Tiger headers, so we duplicate it here -#define kWindowUnifiedTitleAndToolbarAttribute (1 << 7) +WXDLLEXPORT void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ); // --------------------------------------------------------------------------- // Carbon Events @@ -652,7 +306,6 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event UInt32 keyCode ; UInt32 modifiers ; - Point point ; UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; #if wxUSE_UNICODE @@ -669,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 ) ) @@ -696,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 ; } @@ -706,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 ; } @@ -717,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] ; @@ -732,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 ) ; } @@ -750,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 ) ; } @@ -775,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) ; @@ -793,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() ) ; @@ -884,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 ) ; @@ -896,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 ; @@ -973,9 +620,9 @@ wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(handler), // instead of its children (wxToolBarTools) ControlRef parent ; GetSuperControl(control, &parent ); - wxWindow *wxParent = (wxWindow*) wxFindWindowFromWXWidget((WXWidget) parent ) ; - if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) ) - currentMouseWindow = wxParent ; + wxWindow *wxparent = (wxWindow*) wxFindWindowFromWXWidget((WXWidget) parent ) ; + if ( wxparent && wxparent->IsKindOf( CLASSINFO( wxToolBar ) ) ) + currentMouseWindow = wxparent ; #endif } #endif @@ -1037,6 +684,18 @@ wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(handler), result = noErr ; } } + else if ( window && windowPart == inProxyIcon ) + { + // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves + if ( cEvent.GetKind() == kEventMouseDown ) + { + if ( ::TrackWindowProxyDrag( window, screenMouseLocation ) != errUserWantsToDragWindow ) + { + // TODO Track change of file path and report back + result = noErr ; + } + } + } else if ( currentMouseWindow ) { wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent(); @@ -1055,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; @@ -1099,6 +758,16 @@ wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(handler), } else // currentMouseWindow == NULL { + if (toplevelWindow && !control) + { + extern wxCursor gGlobalCursor; + if (!gGlobalCursor.IsOk()) + { + // update cursor when over toolbar and titlebar etc. + wxSTANDARD_CURSOR->MacInstall() ; + } + } + // 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 @@ -1138,22 +807,14 @@ wxNonOwnedWindowEventHandler(EventHandlerCallRef WXUNUSED(handler), { case kEventWindowActivated : { - toplevelWindow->MacActivate( cEvent.GetTicks() , true) ; - wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId()); - wxevent.SetTimestamp( cEvent.GetTicks() ) ; - wxevent.SetEventObject(toplevelWindow); - toplevelWindow->HandleWindowEvent(wxevent); + toplevelWindow->HandleActivated( cEvent.GetTicks() , true) ; // 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); + toplevelWindow->HandleActivated( cEvent.GetTicks() , false) ; // we still sending an eventNotHandledErr in order to allow for default processing } break ; @@ -1175,27 +836,12 @@ wxNonOwnedWindowEventHandler(EventHandlerCallRef WXUNUSED(handler), 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 + toplevelWindow->HandleResized(cEvent.GetTicks() ) ; } if ( attributes & kWindowBoundsChangeOriginChanged ) { - wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ; - event.SetEventObject( toplevelWindow ) ; - toplevelWindow->HandleWindowEvent(event) ; + toplevelWindow->HandleMoved(cEvent.GetTicks() ) ; } result = noErr ; @@ -1210,35 +856,26 @@ wxNonOwnedWindowEventHandler(EventHandlerCallRef WXUNUSED(handler), if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) ) { // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates - int left , top , right , bottom ; - - toplevelWindow->GetNonOwnedPeer()->GetContentArea(left, top, right, bottom); - - wxRect r( + int left , top , width , height ; + // structure width + int swidth, sheight; + + toplevelWindow->GetNonOwnedPeer()->GetContentArea(left, top, width, height); + toplevelWindow->GetNonOwnedPeer()->GetSize(swidth, sheight); + int deltawidth = swidth - width; + int deltaheight = sheight - height; + wxRect adjustR( 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 } ; + newRect.right - newRect.left + deltawidth, + newRect.bottom - newRect.top + deltaheight ) ; + + toplevelWindow->HandleResizing( cEvent.GetTicks(), &adjustR ); + + const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + top + adjustR.height - deltaheight , + adjustR.x + left + adjustR.width - deltawidth } ; if ( !EqualRect( &newRect , &adjustedRect ) ) cEvent.SetParameter( kEventParamCurrentBounds , &adjustedRect ) ; - toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified } result = noErr ; @@ -1285,14 +922,19 @@ 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 ; switch ( GetEventClass( event ) ) { case kEventClassTextInput : - result = wxMacUnicodeTextEventHandler( handler, event , data ) ; + { + // TODO remove as soon as all events are on implementation classes only + wxNonOwnedWindow* toplevelWindow = data ? ((wxNonOwnedWindowImpl*) data)->GetWXPeer() : NULL; + + result = wxMacUnicodeTextEventHandler( handler, event , toplevelWindow ) ; + } break ; case kEventClassKeyboard : @@ -1485,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 ; @@ -1496,12 +1138,16 @@ wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl() } -void wxNonOwnedWindowCarbonImpl::Destroy() -{ - wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) ) ; +void wxNonOwnedWindowCarbonImpl::WillBeDestroyed() +{ + if ( m_macEventHandler ) + { + ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); + m_macEventHandler = NULL ; + } } -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 ); @@ -1538,11 +1184,18 @@ void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler() } void wxNonOwnedWindowCarbonImpl::Create( - wxWindow* parent, - const wxPoint& pos, - const wxSize& size, - long style, long extraStyle, - const wxString& 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 ; @@ -1568,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 ) ) @@ -1576,12 +1229,12 @@ void wxNonOwnedWindowCarbonImpl::Create( else wclass = kFloatingWindowClass ; - if ( ( style &wxTINY_CAPTION_VERT) ) + if ( ( style & wxTINY_CAPTION) ) attr |= kWindowSideTitlebarAttribute ; } else { - if ( HasFlag( wxNO_BORDER ) ) + if ( style & wxNO_BORDER ) { wclass = kSimpleWindowClass ; } @@ -1675,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 { @@ -1774,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; @@ -1838,27 +1496,27 @@ bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show, return true; } -void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString& title, wxFontEncoding encoding ) +void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString& title, wxFontEncoding encoding ) { SetWindowTitleWithCFString( m_macWindow , wxCFStringRef( title , encoding ) ) ; } - + bool wxNonOwnedWindowCarbonImpl::IsMaximized() const { return IsWindowInStandardState( m_macWindow , NULL , NULL ) ; } - + bool wxNonOwnedWindowCarbonImpl::IsIconized() const { return IsWindowCollapsed((WindowRef)GetWXWindow() ) ; } - + void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize ) { if ( IsWindowCollapsable( m_macWindow ) ) CollapseWindow( m_macWindow , iconize ) ; } - + void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize) { Point idealSize = { 0 , 0 } ; @@ -1879,12 +1537,12 @@ void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize) } ZoomWindowIdeal( (WindowRef)GetWXWindow() , maximize ? inZoomOut : inZoomIn , &idealSize ) ; } - + bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const { return m_macFullScreenData != NULL ; } - + bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show, long style) { if ( show ) @@ -1906,7 +1564,7 @@ bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show, long style) wxRect client = wxGetClientDisplayRect() ; - int left , top , right , bottom ; + int left, top, width, height ; int x, y, w, h ; x = client.x ; @@ -1914,19 +1572,23 @@ bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show, long style) w = client.width ; h = client.height ; - GetContentArea( left , top , right , bottom ) ; + GetContentArea( left, top, width, height ) ; + int outerwidth, outerheight; + GetSize( outerwidth, outerheight ); if ( style & wxFULLSCREEN_NOCAPTION ) { y -= top ; h += top ; + // avoid adding the caption twice to the height + outerheight -= top; } if ( style & wxFULLSCREEN_NOBORDER ) { x -= left ; - w += left + right ; - h += bottom ; + w += outerwidth - width; + h += outerheight - height; } if ( style & wxFULLSCREEN_NOTOOLBAR ) @@ -1997,9 +1659,9 @@ void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x, int *y ) HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowContentID , &contentView) ; HIPointConvert( &p, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceView, contentView ); if ( x ) - *x = p.x; + *x = (int)p.x; if ( y ) - *y = p.y; + *y = (int)p.y; } void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x, int *y ) @@ -2010,8 +1672,28 @@ void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x, int *y ) HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowContentID , &contentView) ; HIPointConvert( &p, kHICoordSpaceView, contentView, kHICoordSpace72DPIGlobal, NULL ); if ( x ) - *x = p.x; + *x = (int)p.x; if ( y ) - *y = p.y; + *y = (int)p.y; +} + +bool wxNonOwnedWindowCarbonImpl::IsActive() +{ + return ActiveNonFloatingWindow() == m_macWindow; } -#endif // wxOSX_USE_CARBON + +wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, + long style, long extraStyle, const wxString& name ) +{ + wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCarbonImpl( wxpeer ); + 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; +} +