X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ae53adb467c9bf372cc5238f04e8b8a55392e541..d109c5849ed117966311a44875c97ae3d77b44e5:/src/mac/carbon/toplevel.cpp diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index a649ffa03e..d41ae760f0 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -49,6 +49,9 @@ #include +//For targeting OSX +#include "wx/mac/private.h" + // ---------------------------------------------------------------------------- // globals // ---------------------------------------------------------------------------- @@ -424,7 +427,8 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev short windowPart = ::FindWindow(screenMouseLocation, &window); wxWindow* currentMouseWindow = NULL ; - + ControlRef control = NULL ; + if ( window ) { QDGlobalToLocalPoint( UMAGetWindowPort(window ) , &windowMouseLocation ) ; @@ -436,14 +440,27 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev else if ( (IsWindowActive(window) && windowPart == inContent) ) { ControlPartCode part ; - ControlRef control = wxMacFindControlUnderMouse( windowMouseLocation , window , &part ) ; + control = wxMacFindControlUnderMouse( 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 = wxFindControlFromMacControl( control ) ; + if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved ) + { + // for wxToolBar to function we have to send certaint events to it + // instead of its children (wxToolBarTools) + ControlRef parent ; + GetSuperControl(control, &parent ); + wxWindow *wxParent = wxFindControlFromMacControl( parent ) ; + if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) ) + currentMouseWindow = wxParent ; + } + } } } - + wxMouseEvent wxevent(wxEVT_LEFT_DOWN); SetupMouseEvent( wxevent , cEvent ) ; @@ -533,13 +550,16 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) != wxMacFindControlUnderMouse( windowMouseLocation , window , &dummyPart ) ) ) { - EventModifiers modifiers = cEvent.GetParameter(kEventParamKeyModifiers, typeUInt32) ; - Point clickLocation = windowMouseLocation ; -#if TARGET_API_MAC_OSX - currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ; -#endif - HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation , - modifiers , (ControlActionUPP ) -1 ) ; + if ( currentMouseWindow->MacIsReallyEnabled() ) + { + EventModifiers modifiers = cEvent.GetParameter(kEventParamKeyModifiers, typeUInt32) ; + Point clickLocation = windowMouseLocation ; + #if TARGET_API_MAC_OSX + currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ; + #endif + HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation , + modifiers , (ControlActionUPP ) -1 ) ; + } result = noErr ; } } @@ -549,6 +569,29 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev // update cursor ? } } // else if ( currentMouseWindow ) + else + { + // 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 + wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; + if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control ) + { + EventModifiers modifiers = cEvent.GetParameter(kEventParamKeyModifiers, typeUInt32) ; + Point clickLocation = windowMouseLocation ; +#if TARGET_API_MAC_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 + HandleControlClick( control , clickLocation , + modifiers , (ControlActionUPP ) -1 ) ; + result = noErr ; + } + } return result ; } @@ -731,6 +774,12 @@ void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; +typedef struct +{ + wxPoint m_position ; + wxSize m_size ; +} FullScreenData ; + void wxTopLevelWindowMac::Init() { m_iconized = @@ -742,6 +791,7 @@ void wxTopLevelWindowMac::Init() m_macUsesCompositing = FALSE; #endif m_macEventHandler = NULL ; + m_macFullScreenData = NULL ; } class wxMacDeferredWindowDeleter : public wxObject @@ -775,6 +825,7 @@ bool wxTopLevelWindowMac::Create(wxWindow *parent, SetName(name); m_windowId = id == -1 ? NewControlId() : id; + wxWindow::SetTitle( title ) ; MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; @@ -806,6 +857,10 @@ wxTopLevelWindowMac::~wxTopLevelWindowMac() if ( wxModelessWindows.Find(this) ) wxModelessWindows.DeleteObject(this); + + FullScreenData *data = (FullScreenData *) m_macFullScreenData ; + delete data ; + m_macFullScreenData = NULL ; } @@ -931,6 +986,16 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, { wclass = kDocumentWindowClass ; } +#if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 ) + else if ( HasFlag( wxFRAME_DRAWER ) ) + { + wclass = kDrawerWindowClass; + // Should this be left for compositing check below? + // CreateNewWindow will fail without it, should wxDrawerWindow turn + // on compositing before calling MacCreateRealWindow? + attr |= kWindowCompositingAttribute;// | kWindowStandardHandlerAttribute; + } +#endif //10.2 and up else { if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || @@ -1116,6 +1181,72 @@ bool wxTopLevelWindowMac::Show(bool show) return TRUE ; } +bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) +{ + if ( show ) + { + FullScreenData *data = (FullScreenData *)m_macFullScreenData ; + delete data ; + data = new FullScreenData() ; + + m_macFullScreenData = data ; + data->m_position = GetPosition() ; + data->m_size = GetSize() ; + + if ( style & wxFULLSCREEN_NOMENUBAR ) + { + HideMenuBar() ; + } + int left , top , right , bottom ; + wxRect client = wxGetClientDisplayRect() ; + + int x, y, w, h ; + + x = client.x ; + y = client.y ; + w = client.width ; + h = client.height ; + + MacGetContentAreaInset( left , top , right , bottom ) ; + + if ( style & wxFULLSCREEN_NOCAPTION ) + { + y -= top ; + h += top ; + } + if ( style & wxFULLSCREEN_NOBORDER ) + { + x -= left ; + w += left + right ; + h += bottom ; + } + if ( style & wxFULLSCREEN_NOTOOLBAR ) + { + // TODO + } + if ( style & wxFULLSCREEN_NOSTATUSBAR ) + { + // TODO + } + SetSize( x , y , w, h ) ; + } + else + { + ShowMenuBar() ; + FullScreenData *data = (FullScreenData *) m_macFullScreenData ; + SetPosition( data->m_position ) ; + SetSize( data->m_size ) ; + delete data ; + m_macFullScreenData = NULL ; + } + return FALSE; +} + +bool wxTopLevelWindowMac::IsFullScreen() const +{ + return m_macFullScreenData != NULL ; +} + // we are still using coordinates of the content view, todo switch to structure bounds void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )