diff --git a/include/wx/osx/carbon/private.h b/include/wx/osx/carbon/private.h index 64fa447e14..a960cc3a81 100644 --- a/include/wx/osx/carbon/private.h +++ b/include/wx/osx/carbon/private.h @@ -1008,6 +1008,8 @@ public : virtual bool IsFullScreen() const; + bool EnableFullScreenView(bool enable) wxOVERRIDE; + virtual bool ShowFullScreen(bool show, long style); virtual void ShowWithoutActivating(); diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 0e422c56b0..13e25f4eff 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -239,6 +239,8 @@ public : virtual bool IsFullScreen() const; + bool EnableFullScreenView(bool enable) wxOVERRIDE; + virtual bool ShowFullScreen(bool show, long style); virtual void ShowWithoutActivating(); diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index f16850a083..5f45f0ccd1 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -867,6 +867,8 @@ public : virtual void ShowWithoutActivating() { Show(true); } + virtual bool EnableFullScreenView(bool enable) = 0; + virtual bool ShowFullScreen(bool show, long style)= 0; virtual void RequestUserAttention(int flags) = 0; diff --git a/include/wx/osx/toplevel.h b/include/wx/osx/toplevel.h index 73b218fe75..d88846dd3b 100644 --- a/include/wx/osx/toplevel.h +++ b/include/wx/osx/toplevel.h @@ -64,6 +64,7 @@ public: virtual bool IsActive(); virtual void ShowWithoutActivating(); + bool EnableFullScreenView(bool enable = true) wxOVERRIDE; virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL) ; virtual bool IsFullScreen() const ; diff --git a/include/wx/toplevel.h b/include/wx/toplevel.h index ca3bf6afdc..232ae9fd1a 100644 --- a/include/wx/toplevel.h +++ b/include/wx/toplevel.h @@ -182,6 +182,11 @@ public: // set the frame icons virtual void SetIcons(const wxIconBundle& icons) { m_icons = icons; } + virtual bool EnableFullScreenView(bool WXUNUSED(enable) = true) + { + return false; + } + // maximize the window to cover entire screen virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL) = 0; diff --git a/interface/wx/toplevel.h b/interface/wx/toplevel.h index e7f5c3423f..f40e315c82 100644 --- a/interface/wx/toplevel.h +++ b/interface/wx/toplevel.h @@ -534,7 +534,35 @@ public: focus. */ virtual void ShowWithoutActivating(); - + + /** + Adds or removes a full screen button to the right upper corner of a + window's title bar under OS X 10.7 and later. + + Currently only available for wxOSX/Cocoa. + + @param enable + If @true (default) adds the full screen button in the title bar; + if @false the button is removed. + + @return @true if the button was added or removed, @false if running + under a pre-OS X 10.7 system or another OS. + + @note Having the button is also required to let ShowFullScreen() + make use of the full screen API available since OS X 10.7: a full + screen window gets its own space and entering and exiting the mode + is animated. + If the button is not present the old way of switching to full screen + is used. + + @onlyfor{wxosx} + + @see ShowFullScreen() + + @since 3.1.0 + */ + virtual bool EnableFullScreenView(bool enable = true); + /** Depending on the value of @a show parameter the window is either shown full screen or restored to its normal state. @a style is a bit list @@ -553,7 +581,7 @@ public: @note Showing a window full screen also actually @ref wxWindow::Show() "Show()"s the window if it isn't shown. - @see IsFullScreen() + @see EnableFullScreenView(), IsFullScreen() */ virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL); diff --git a/samples/display/display.cpp b/samples/display/display.cpp index 89858bf45b..f0ae8b4fb6 100644 --- a/samples/display/display.cpp +++ b/samples/display/display.cpp @@ -219,6 +219,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, menuBar->Append(menuDisplay, _("&Display")); menuBar->Append(helpMenu, _("&Help")); + EnableFullScreenView(); + // ... and attach this menu bar to the frame SetMenuBar(menuBar); #endif // wxUSE_MENUS diff --git a/src/osx/carbon/nonownedwnd.cpp b/src/osx/carbon/nonownedwnd.cpp index f9acf7e4d8..88d3766b31 100644 --- a/src/osx/carbon/nonownedwnd.cpp +++ b/src/osx/carbon/nonownedwnd.cpp @@ -1536,6 +1536,11 @@ bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const return m_macFullScreenData != NULL ; } +bool wxNonOwnedWindowCarbonImpl::EnableFullScreenView(bool WXUNUSED(enable)) +{ + return false; +} + bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show, long style) { if ( show ) diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index 9e79c6a458..8a83c71d46 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -91,6 +91,19 @@ bool shouldHandleSelector(SEL selector) } + +#define wxHAS_FULL_SCREEN_API (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) + +#if wxHAS_FULL_SCREEN_API + +static bool IsUsingFullScreenApi(WXWindow macWindow) +{ + return [macWindow respondsToSelector:@selector(toggleFullScreen:)] + && ([macWindow collectionBehavior] & NSWindowCollectionBehaviorFullScreenPrimary); +} + +#endif + // // wx category for NSWindow (our own and wrapped instances) // @@ -924,11 +937,55 @@ typedef struct bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const { +#if wxHAS_FULL_SCREEN_API + if ( IsUsingFullScreenApi(m_macWindow) ) + { + return [m_macWindow styleMask] & NSFullScreenWindowMask; + } +#endif + return m_macFullScreenData != NULL ; } +bool wxNonOwnedWindowCocoaImpl::EnableFullScreenView(bool enable) +{ +#if wxHAS_FULL_SCREEN_API + if ( [ m_macWindow respondsToSelector:@selector(setCollectionBehavior:) ] ) + { + NSUInteger collectionBehavior = [m_macWindow collectionBehavior]; + if (enable) + { + collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary; + } + else + { + collectionBehavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; + } + [m_macWindow setCollectionBehavior: collectionBehavior]; + + return true; + } +#else + wxUnusedVar(enable); +#endif + + return false; +} + bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style)) { +#if wxHAS_FULL_SCREEN_API + if ( IsUsingFullScreenApi(m_macWindow) ) + { + if ( show != IsFullScreen() ) + { + [m_macWindow toggleFullScreen: nil]; + } + + return true; + } +#endif + if ( show ) { FullScreenData *data = (FullScreenData *)m_macFullScreenData ; diff --git a/src/osx/toplevel_osx.cpp b/src/osx/toplevel_osx.cpp index b0dc820904..848199a388 100644 --- a/src/osx/toplevel_osx.cpp +++ b/src/osx/toplevel_osx.cpp @@ -190,6 +190,11 @@ void wxTopLevelWindowMac::ShowWithoutActivating() SendSizeEvent(); } +bool wxTopLevelWindowMac::EnableFullScreenView(bool enable) +{ + return m_nowpeer->EnableFullScreenView(enable); +} + bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) { return m_nowpeer->ShowFullScreen(show, style);