diff --git a/docs/changes.txt b/docs/changes.txt index cc2babda77..d444e3f67a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -85,6 +85,7 @@ All (GUI): - Add wxAppProgressIndicator for MSW (Chaobin Zhang) and OS X (Tobias Taschner). - Add wxEVT_MAGNIFY mouse event (Joost Nieuwenhuijse). - Add wxProcess::Activate(). +- Add wxTopLevelWindow::Enable{Maximize,Minimize}Button() (John Roberts). - Make results of wxDC::DrawEllipticArc() consistent across all platforms. - XRC handler for wxAuiToolBar added (Kinaou Hervé, David Hart). - Improve wxLIST_AUTOSIZE_XXX support in generic wxListCtrl (Kinaou Hervé). diff --git a/include/wx/msw/toplevel.h b/include/wx/msw/toplevel.h index e70031c47c..ae5541647d 100644 --- a/include/wx/msw/toplevel.h +++ b/include/wx/msw/toplevel.h @@ -68,6 +68,8 @@ public: // wxMSW only: EnableCloseButton(false) may be used to remove the "Close" // button from the title bar virtual bool EnableCloseButton(bool enable = true); + virtual bool EnableMaximizeButton(bool enable = true) wxOVERRIDE; + virtual bool EnableMinimizeButton(bool enable = true) wxOVERRIDE; // Set window transparency if the platform supports it virtual bool SetTransparent(wxByte alpha); diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index d545e7a8de..60c7924787 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -232,6 +232,8 @@ public : virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ; virtual bool EnableCloseButton(bool enable) wxOVERRIDE; + virtual bool EnableMaximizeButton(bool enable) wxOVERRIDE; + virtual bool EnableMinimizeButton(bool enable) wxOVERRIDE; virtual bool IsMaximized() const; diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index dc620aebfc..ba19e45960 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -848,6 +848,8 @@ public : virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) = 0; virtual bool EnableCloseButton(bool enable) = 0; + virtual bool EnableMaximizeButton(bool enable) = 0; + virtual bool EnableMinimizeButton(bool enable) = 0; virtual bool IsMaximized() const = 0; diff --git a/include/wx/osx/toplevel.h b/include/wx/osx/toplevel.h index b129827318..e82711a861 100644 --- a/include/wx/osx/toplevel.h +++ b/include/wx/osx/toplevel.h @@ -77,6 +77,8 @@ public: // EnableCloseButton(false) used to disable the "Close" // button on the title bar virtual bool EnableCloseButton(bool enable = true) wxOVERRIDE; + virtual bool EnableMaximizeButton(bool enable = true) wxOVERRIDE; + virtual bool EnableMinimizeButton(bool enable = true) wxOVERRIDE; virtual void SetLabel(const wxString& label) { SetTitle( label ); } virtual wxString GetLabel() const { return GetTitle(); } diff --git a/include/wx/toplevel.h b/include/wx/toplevel.h index b6a2a49767..3af91b4afb 100644 --- a/include/wx/toplevel.h +++ b/include/wx/toplevel.h @@ -206,6 +206,8 @@ public: // enable/disable close button [x] virtual bool EnableCloseButton(bool WXUNUSED(enable) = true) { return false; } + virtual bool EnableMaximizeButton(bool WXUNUSED(enable) = true) { return false; } + virtual bool EnableMinimizeButton(bool WXUNUSED(enable) = true) { return false; } // Attracts the users attention to this window if the application is // inactive (should be called when a background event occurs) diff --git a/interface/wx/toplevel.h b/interface/wx/toplevel.h index c07ec6ccc8..523fe1bb79 100644 --- a/interface/wx/toplevel.h +++ b/interface/wx/toplevel.h @@ -148,6 +148,39 @@ public: */ virtual bool EnableCloseButton(bool enable = true); + /** + Enables or disables the Maximize button (in the right or left upper + corner of a frame or dialog). + + Currently only implemented for wxMSW and wxOSX. + + The window style must contain wxMAXIMIZE_BOX. + + Returns @true if operation was successful. Note that a successful + operation does not change the window style flags. + + @since 3.1.0 + */ + virtual bool EnableMaximizeButton(bool enable = true); + + /** + Enables or disables the Minimize button (in the right or left upper + corner of a frame or dialog). + + Currently only implemented for wxMSW and wxOSX. + + The window style must contain wxMINIMIZE_BOX. + + Note that in wxMSW a successful operation will change the window + style flags. + + Returns @true if operation was successful. Note that a successful + operation does not change the window style flags. + + @since 3.1.0 + */ + virtual bool EnableMinimizeButton(bool enable = true); + /** Returns a pointer to the button which is the default for this window, or @c @NULL. The default button is the one activated by pressing the Enter diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index e71c58ab69..631d987663 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -1194,6 +1194,56 @@ bool wxTopLevelWindowMSW::EnableCloseButton(bool enable) return true; } +// Window must have wxCAPTION and either wxCLOSE_BOX or wxSYSTEM_MENU for the +// button to be visible. Also check for wxMAXIMIZE_BOX because we don't want +// to enable a button that is excluded from the current style. + +bool wxTopLevelWindowMSW::EnableMaximizeButton(bool enable) +{ + if ( ( HasFlag(wxCAPTION) && + ( HasFlag(wxCLOSE_BOX) || HasFlag(wxSYSTEM_MENU) ) ) && + HasFlag(wxMAXIMIZE_BOX) ) + { + if ( enable ) + { + SetWindowStyleFlag(GetWindowStyleFlag() | wxMAXIMIZE_BOX); + } + else + { + SetWindowStyleFlag(GetWindowStyleFlag() ^ wxMAXIMIZE_BOX); + // Restore the style to our internal store + wxWindowBase::SetWindowStyleFlag(GetWindowStyle() | wxMAXIMIZE_BOX); + } + + return true; + } + + return false; +} + +bool wxTopLevelWindowMSW::EnableMinimizeButton(bool enable) +{ + if ( ( HasFlag(wxCAPTION) && + ( HasFlag(wxCLOSE_BOX) || HasFlag(wxSYSTEM_MENU) ) ) && + HasFlag(wxMINIMIZE_BOX) ) + { + if ( enable ) + { + SetWindowStyleFlag(GetWindowStyleFlag() | wxMINIMIZE_BOX); + } + else + { + SetWindowStyleFlag(GetWindowStyleFlag() ^ wxMINIMIZE_BOX); + // Restore the style to our internal store + wxWindowBase::SetWindowStyleFlag(GetWindowStyle() | wxMINIMIZE_BOX); + } + + return true; + } + + return false; +} + void wxTopLevelWindowMSW::RequestUserAttention(int flags) { #if defined(FLASHW_STOP) && wxUSE_DYNLIB_CLASS diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index fbb0407757..2cff0c70ca 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -946,6 +946,20 @@ bool wxNonOwnedWindowCocoaImpl::EnableCloseButton(bool enable) return true; } +bool wxNonOwnedWindowCocoaImpl::EnableMaximizeButton(bool enable) +{ + [[m_macWindow standardWindowButton:NSWindowZoomButton] setEnabled:enable]; + + return true; +} + +bool wxNonOwnedWindowCocoaImpl::EnableMinimizeButton(bool enable) +{ + [[m_macWindow standardWindowButton:NSWindowMiniaturizeButton] setEnabled:enable]; + + return true; +} + bool wxNonOwnedWindowCocoaImpl::IsMaximized() const { if (([m_macWindow styleMask] & NSResizableWindowMask) != 0) diff --git a/src/osx/toplevel_osx.cpp b/src/osx/toplevel_osx.cpp index 3f9ef35893..fa115345c1 100644 --- a/src/osx/toplevel_osx.cpp +++ b/src/osx/toplevel_osx.cpp @@ -215,6 +215,23 @@ bool wxTopLevelWindowMac::EnableCloseButton(bool enable) return false; } +bool wxTopLevelWindowMac::EnableMaximizeButton(bool enable) +{ + // Both wxRESIZE_BORDER and wxMAXIMIZE_BOX create a resize border and + // add a maximize button. + if ( HasFlag(wxMAXIMIZE_BOX) || HasFlag(wxRESIZE_BORDER) ) + return m_nowpeer->EnableMaximizeButton( enable); + return false; +} + +bool wxTopLevelWindowMac::EnableMinimizeButton(bool enable) +{ + if ( HasFlag(wxMINIMIZE_BOX) ) + return m_nowpeer->EnableMinimizeButton( enable); + + return false; +} + void wxTopLevelWindowMac::RequestUserAttention(int flags) { return m_nowpeer->RequestUserAttention(flags);