Added support for using OS X' full screen API (available since OS X 10.7).

Added EnableFullScreenView() to have a full screen button in the title bar and also allowing ShowFullScreen() to make use of the newer full screen API.

See #14357.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76495 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Dimitri Schoolwerth 2014-05-11 22:41:13 +00:00
parent f641dfd78c
commit 6451d23158
10 changed files with 111 additions and 2 deletions

View File

@ -1008,6 +1008,8 @@ public :
virtual bool IsFullScreen() const;
bool EnableFullScreenView(bool enable) wxOVERRIDE;
virtual bool ShowFullScreen(bool show, long style);
virtual void ShowWithoutActivating();

View File

@ -239,6 +239,8 @@ public :
virtual bool IsFullScreen() const;
bool EnableFullScreenView(bool enable) wxOVERRIDE;
virtual bool ShowFullScreen(bool show, long style);
virtual void ShowWithoutActivating();

View File

@ -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;

View File

@ -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 ;

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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 )

View File

@ -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 ;

View File

@ -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);