X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d88ffaaa76c8c98f326457fb313bc98690cf64b6..dd12ce22d806e6a9c40cf7bdfddbb237cd55b0ca:/src/mac/carbon/toplevel.cpp diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index ab1c994ddd..a54c02df21 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 // ---------------------------------------------------------------------------- @@ -442,7 +445,19 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev 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 ; + } + } } } @@ -506,15 +521,6 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev cursorPoint += cursorTarget->GetPosition() ; } - // update focus - - if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) - { - // set focus to this window - if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow) - currentMouseWindow->SetFocus(); - } - // make tooltips current #if wxUSE_TOOLTIPS @@ -527,6 +533,15 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev result = noErr; else { + // if the user code did _not_ handle the event, then perform the + // default processing + if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) + { + // ... that is set focus to this window + if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow) + currentMouseWindow->SetFocus(); + } + ControlPartCode dummyPart ; // if built-in find control is finding the wrong control (ie static box instead of overlaid // button, we cannot let the standard handler do its job, but must handle manually @@ -535,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 ; } } @@ -557,7 +575,7 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev // 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 ( toplevelWindow && control ) + if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control ) { EventModifiers modifiers = cEvent.GetParameter(kEventParamKeyModifiers, typeUInt32) ; Point clickLocation = windowMouseLocation ; @@ -723,6 +741,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler ) // Find an item given the Macintosh Window Reference +#if KEY_wxList_DEPRECATED wxList wxWinMacWindowList(wxKEY_INTEGER); wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) { @@ -748,7 +767,43 @@ void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) { wxWinMacWindowList.DeleteObject(win); } +#else + +WX_DECLARE_HASH_MAP(WindowRef, wxTopLevelWindowMac*, wxPointerHash, wxPointerEqual, MacWindowMap); + +static MacWindowMap wxWinMacWindowList; + +wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) +{ + MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef); + + return (node == wxWinMacWindowList.end()) ? NULL : node->second; +} +void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; +void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) +{ + // adding NULL WindowRef is (first) surely a result of an error and + // nothing else :-) + wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); + + wxWinMacWindowList[inWindowRef] = win; +} + +void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; +void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) +{ + MacWindowMap::iterator it; + for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it ) + { + if ( it->second == win ) + { + wxWinMacWindowList.erase(it); + break; + } + } +} +#endif // deprecated wxList // ---------------------------------------------------------------------------- // wxTopLevelWindowMac creation @@ -756,6 +811,12 @@ void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; +typedef struct +{ + wxPoint m_position ; + wxSize m_size ; +} FullScreenData ; + void wxTopLevelWindowMac::Init() { m_iconized = @@ -767,6 +828,7 @@ void wxTopLevelWindowMac::Init() m_macUsesCompositing = FALSE; #endif m_macEventHandler = NULL ; + m_macFullScreenData = NULL ; } class wxMacDeferredWindowDeleter : public wxObject @@ -800,6 +862,7 @@ bool wxTopLevelWindowMac::Create(wxWindow *parent, SetName(name); m_windowId = id == -1 ? NewControlId() : id; + wxWindow::SetTitle( title ) ; MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; @@ -831,6 +894,10 @@ wxTopLevelWindowMac::~wxTopLevelWindowMac() if ( wxModelessWindows.Find(this) ) wxModelessWindows.DeleteObject(this); + + FullScreenData *data = (FullScreenData *) m_macFullScreenData ; + delete data ; + m_macFullScreenData = NULL ; } @@ -918,10 +985,14 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, int x = (int)pos.x; int y = (int)pos.y; - if ( y < 50 ) - y = 50 ; - if ( x < 20 ) - x = 20 ; + + 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); @@ -956,6 +1027,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 ) || @@ -1141,6 +1222,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 )