From b48f51ca745c5d3dfd704947812bbea90a44a1eb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 25 Sep 2006 11:46:58 +0000 Subject: [PATCH] add wxTLW::UseNativeDecorations[ByDefault]() to allow the programmer to control whether windows use native or custom decorations git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41428 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 4 +++ docs/latex/wx/tlw.tex | 58 +++++++++++++++++++++++++++++++ include/wx/univ/toplevel.h | 17 ++++++++- src/univ/topluniv.cpp | 71 ++++++++++++++++++++++++-------------- 4 files changed, 123 insertions(+), 27 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 0a221c1b1c..21bd9fd96d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -88,6 +88,10 @@ wxGTK: - Automatically use stock items for menu items with standard ids. - Setting cursor now works for all controls. +wxUniv: + +- Added wxTLW::UseNativeDecorations() and UseNativeDecorationsByDefault() + 2.7.0 ----- diff --git a/docs/latex/wx/tlw.tex b/docs/latex/wx/tlw.tex index dba609ba32..2949193ae8 100644 --- a/docs/latex/wx/tlw.tex +++ b/docs/latex/wx/tlw.tex @@ -152,6 +152,21 @@ Returns \true if the window is iconized. Returns \true if the window is maximized. +\membersection{wxTopLevelWindow::IsUsingNativeDecorations}{wxtoplevelwindowisusingnativedecorations} + +\constfunc{bool}{IsUsingNativeDecorations}{\void} + +\bftt{This method is specific to wxUniversal port} + +Returns \true if this window is using native decorations, \false if we draw +them ourselves. + +\wxheading{See also} + +\helpref{UseNativeDecorations}{wxtoplevelwindowusenativedecorations},\\ +\helpref{UseNativeDecorationsByDefault}{wxtoplevelwindowusenativedecorationsbydefault} + + \membersection{wxTopLevelWindow::Maximize}\label{wxtoplevelwindowmaximize} \func{void}{Maximize}{\param{bool }{maximize}} @@ -354,3 +369,46 @@ Note that showing a window full screen also actually \wxheading{See also} \helpref{wxTopLevelWindow::IsFullScreen}{wxtoplevelwindowisfullscreen} + + +\membersection{wxTopLevelWindow::UseNativeDecorations}\label{wxtoplevelwindowusenativedecorations} + +\func{void}{UseNativeDecorations}{\param{bool }{native = \true}} + +\bftt{This method is specific to wxUniversal port} + +Use native or custom-drawn decorations for this window only. Notice that to +have any effect this method must be called before really creating the window, +i.e. two step creation must be used: +\begin{verbatim} + MyFrame *frame = new MyFrame; // use default ctor + frame->UseNativeDecorations(false); // change from default "true" + frame->Create(parent, title, ...); // really create the frame +\end{verbatim} + +\wxheading{See also} + +\helpref{UseNativeDecorationsByDefault}{wxtoplevelwindowusenativedecorationsbydefault},\\ +\helpref{IsUsingNativeDecorations}{wxtoplevelwindowisusingnativedecorations} + + +\membersection{wxTopLevelWindow::UseNativeDecorationsByDefault}\label{wxtoplevelwindowusenativedecorationsbydefault} + +\func{void}{UseNativeDecorationsByDefault}{\param{bool }{native = \true}} + +\bftt{This method is specific to wxUniversal port} + +Top level windows in wxUniversal port can use either system-provided window +decorations (i.e. title bar and various icons, buttons and menus in it) or draw +the decorations themselves. By default the system decorations are used if they +are available, but this method can be called with \arg{native} set to \false to +change this for all windows created after this point. + +Also note that if \texttt{WXDECOR} environment variable is set, then custom +decorations are used by default and so it may make sense to call this method +with default argument if the application can't use custom decorations at all +for some reason. + +\wxheading{See also} + +\helpref{UseNativeDecorations}{wxtoplevelwindowusenativedecorations} diff --git a/include/wx/univ/toplevel.h b/include/wx/univ/toplevel.h index 7350e71e91..17681cfd9a 100644 --- a/include/wx/univ/toplevel.h +++ b/include/wx/univ/toplevel.h @@ -115,6 +115,18 @@ public: long style = wxDEFAULT_FRAME_STYLE, const wxString& name = wxFrameNameStr); + // wxUniv-specific methods: do [not] use native decorations for this (or + // all) window(s) + // + // notice that this has no effect if the system doesn't support any native + // decorations anyhow and that by default native decorations are used + // + // if UseNativeDecorations() is used, it must be called before Create() + static UseNativeDecorationsByDefault(bool native = true); + void UseNativeDecorations(bool native = true); + bool IsUsingNativeDecorations() const; + + // implement base class pure virtuals virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL); virtual wxPoint GetClientAreaOrigin() const; @@ -166,8 +178,11 @@ protected: static int ms_drawDecorations; // true if wxTLW can be iconized static int ms_canIconize; + + // true if we're using native decorations + bool m_usingNativeDecorations; // true for currently active frame - bool m_isActive:1; + bool m_isActive; // version of icon for titlebar (16x16) wxIcon m_titlebarIcon; // saved window style in fullscreen mdoe diff --git a/src/univ/topluniv.cpp b/src/univ/topluniv.cpp index 3d0f437c5b..fa5ecced11 100644 --- a/src/univ/topluniv.cpp +++ b/src/univ/topluniv.cpp @@ -80,6 +80,15 @@ int wxTopLevelWindow::ms_canIconize = -1; void wxTopLevelWindow::Init() { + // once-only ms_drawDecorations initialization + if ( ms_drawDecorations == -1 ) + { + ms_drawDecorations = + !wxSystemSettings::HasFeature(wxSYS_CAN_DRAW_FRAME_DECORATIONS) || + wxGetEnv(wxT("WXDECOR"), NULL); + } + + m_usingNativeDecorations = ms_drawDecorations == 0; m_isActive = false; m_windowStyle = 0; m_pressedButton = 0; @@ -97,21 +106,7 @@ bool wxTopLevelWindow::Create(wxWindow *parent, long styleOrig = 0, exstyleOrig = 0; - if ( ms_drawDecorations == -1 ) - { - ms_drawDecorations = - !wxSystemSettings::HasFeature(wxSYS_CAN_DRAW_FRAME_DECORATIONS) - || wxGetEnv(wxT("WXDECOR"), NULL); - // FIXME -- wxUniv should provide a way to force non-native decorations! - // $WXDECOR is just a hack in absence of better wxUniv solution - } - - if ( ms_canIconize == -1 ) - { - ms_canIconize = wxSystemSettings::HasFeature(wxSYS_CAN_ICONIZE_FRAME); - } - - if ( ms_drawDecorations ) + if ( !m_usingNativeDecorations ) { CreateInputHandler(wxINP_HANDLER_TOPLEVEL); @@ -120,7 +115,7 @@ bool wxTopLevelWindow::Create(wxWindow *parent, style &= ~(wxCAPTION | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU | wxRESIZE_BORDER | wxFRAME_TOOL_WINDOW | wxRESIZE_BORDER); - style |= wxSIMPLE_BORDER; + style |= wxBORDER_NONE; SetExtraStyle(exstyleOrig & ~wxWS_EX_CONTEXTHELP); } @@ -128,7 +123,7 @@ bool wxTopLevelWindow::Create(wxWindow *parent, size, style, name) ) return false; - if ( ms_drawDecorations ) + if ( !m_usingNativeDecorations ) { m_windowStyle = styleOrig; m_exStyle = exstyleOrig; @@ -141,7 +136,7 @@ bool wxTopLevelWindow::ShowFullScreen(bool show, long style) { if ( show == IsFullScreen() ) return false; - if ( ms_drawDecorations ) + if ( !m_usingNativeDecorations ) { if ( show ) { @@ -160,12 +155,34 @@ bool wxTopLevelWindow::ShowFullScreen(bool show, long style) return wxTopLevelWindowNative::ShowFullScreen(show, style); } +/* static */ wxTopLevelWindow::UseNativeDecorationsByDefault(bool native) +{ + ms_drawDecorations = !native; +} + +void wxTopLevelWindow::UseNativeDecorations(bool native) +{ + wxASSERT_MSG( !m_windowStyle, _T("must be called before Create()") ); + + m_usingNativeDecorations = native; +} + +bool wxTopLevelWindow::IsUsingNativeDecorations() const +{ + return m_usingNativeDecorations; +} + long wxTopLevelWindow::GetDecorationsStyle() const { long style = 0; if ( m_windowStyle & wxCAPTION ) { + if ( ms_canIconize == -1 ) + { + ms_canIconize = wxSystemSettings::HasFeature(wxSYS_CAN_ICONIZE_FRAME); + } + style |= wxTOPLEVEL_TITLEBAR | wxTOPLEVEL_BUTTON_CLOSE; if ( (m_windowStyle & wxMINIMIZE_BOX) && ms_canIconize ) style |= wxTOPLEVEL_BUTTON_ICONIZE; @@ -209,7 +226,7 @@ void wxTopLevelWindow::RefreshTitleBar() wxPoint wxTopLevelWindow::GetClientAreaOrigin() const { - if ( ms_drawDecorations ) + if ( !m_usingNativeDecorations ) { int w, h; wxTopLevelWindowNative::DoGetClientSize(&w, &h); @@ -227,7 +244,7 @@ wxPoint wxTopLevelWindow::GetClientAreaOrigin() const void wxTopLevelWindow::DoGetClientSize(int *width, int *height) const { - if ( ms_drawDecorations ) + if ( !m_usingNativeDecorations ) { int w, h; wxTopLevelWindowNative::DoGetClientSize(&w, &h); @@ -246,7 +263,7 @@ void wxTopLevelWindow::DoGetClientSize(int *width, int *height) const void wxTopLevelWindow::DoSetClientSize(int width, int height) { - if ( ms_drawDecorations ) + if ( !m_usingNativeDecorations ) { wxSize size = m_renderer->GetFrameTotalSize(wxSize(width, height), GetDecorationsStyle()); @@ -258,9 +275,11 @@ void wxTopLevelWindow::DoSetClientSize(int width, int height) void wxTopLevelWindow::OnNcPaint(wxNcPaintEvent& event) { - if ( !ms_drawDecorations || !m_renderer ) + if ( m_usingNativeDecorations || !m_renderer ) + { event.Skip(); - else + } + else // we're drawing the decorations ourselves { // get the window rect wxRect rect(GetSize()); @@ -285,7 +304,7 @@ long wxTopLevelWindow::HitTest(const wxPoint& pt) const int wxTopLevelWindow::GetMinWidth() const { - if ( ms_drawDecorations ) + if ( !m_usingNativeDecorations ) { return wxMax(wxTopLevelWindowNative::GetMinWidth(), m_renderer->GetFrameMinSize(GetDecorationsStyle()).x); @@ -296,7 +315,7 @@ int wxTopLevelWindow::GetMinWidth() const int wxTopLevelWindow::GetMinHeight() const { - if ( ms_drawDecorations ) + if ( !m_usingNativeDecorations ) { return wxMax(wxTopLevelWindowNative::GetMinHeight(), m_renderer->GetFrameMinSize(GetDecorationsStyle()).y); @@ -313,7 +332,7 @@ void wxTopLevelWindow::SetIcons(const wxIconBundle& icons) { wxTopLevelWindowNative::SetIcons(icons); - if ( ms_drawDecorations && m_renderer ) + if ( !m_usingNativeDecorations && m_renderer ) { wxSize size = m_renderer->GetFrameIconSize(); const wxIcon& icon = icons.GetIcon( size );