From 25057abaacf5ccf30bf136ec2ac430eb61664c3b Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sun, 6 Feb 2005 19:17:35 +0000 Subject: [PATCH] Can suppress themed notebook page with wxNB_NOPAGETHEME or setting system option msw.notebook.themed-background to 0 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31807 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/artprov.tex | 10 +++---- docs/latex/wx/menu.tex | 4 +-- docs/latex/wx/notebook.tex | 40 +++++++++++++++++++++++++ include/wx/defs.h | 1 + include/wx/msw/notebook.h | 2 ++ include/wx/notebook.h | 3 ++ samples/widgets/widgets.cpp | 16 ++++++++-- src/msw/notebook.cpp | 59 +++++++++++++++++++++++++++++++++++++ 8 files changed, 125 insertions(+), 10 deletions(-) diff --git a/docs/latex/wx/artprov.tex b/docs/latex/wx/artprov.tex index 109ae25880..c30aaaf824 100644 --- a/docs/latex/wx/artprov.tex +++ b/docs/latex/wx/artprov.tex @@ -6,11 +6,11 @@ \section{\class{wxArtProvider}}\label{wxartprovider} wxArtProvider class is used to customize the look of wxWidgets application. -When wxWidgets need to display an icon or a bitmap (e.g. in the standard file -dialog), it does not use hard-coded resource but asks wxArtProvider for it -instead. This way the users can plug in own wxArtProvider class and easily -replace standard art with his/her own version. It is easy thing to do: all -that is needed is to derive a class from wxArtProvider, override it's +When wxWidgets needs to display an icon or a bitmap (e.g. in the standard file +dialog), it does not use a hard-coded resource but asks wxArtProvider for it +instead. This way users can plug in their own wxArtProvider class and easily +replace standard art with their own version. All +that is needed is to derive a class from wxArtProvider, override its \helpref{CreateBitmap}{wxartprovidercreatebitmap} method and register the provider with \helpref{wxArtProvider::PushProvider}{wxartproviderpushprovider}: diff --git a/docs/latex/wx/menu.tex b/docs/latex/wx/menu.tex index f4bd4b7c50..6e88366e33 100644 --- a/docs/latex/wx/menu.tex +++ b/docs/latex/wx/menu.tex @@ -30,8 +30,8 @@ group is formed by a contiguous range of radio items, i.e. it starts at the first item of this kind and ends with the first item of a different kind (or the end of the menu). Notice that because the radio groups are defined in terms of the item positions inserting or removing the items in the menu containing -the radio items risks to not work correctly. Finally note that the radio items -are only supported under Windows and GTK+ currently. +the radio items risks to not work correctly. Finally note that radio items +are not supported under Motif. \wxheading{Allocation strategy} diff --git a/docs/latex/wx/notebook.tex b/docs/latex/wx/notebook.tex index e3b4287fdf..514a107684 100644 --- a/docs/latex/wx/notebook.tex +++ b/docs/latex/wx/notebook.tex @@ -29,6 +29,7 @@ managed by wxNotebook. \twocolitem{\windowstyle{wxNB\_BOTTOM}}{Place tabs under instead of above the notebook pages.} \twocolitem{\windowstyle{wxNB\_FIXEDWIDTH}}{(Windows only) All tabs will have same width.} \twocolitem{\windowstyle{wxNB\_MULTILINE}}{(Windows only) There can be several rows of tabs.} +\twocolitem{\windowstyle{wxNB\_NOPAGETHEME}}{(Windows only) Display a solid colour on notebook pages, and not a gradient, which can reduce performance.} \end{twocollist} @@ -39,6 +40,38 @@ See also \helpref{window styles overview}{windowstyles}. \input noteevt.inc +\wxheading{Page backgrounds} + +On Windows XP, the default theme paints a gradient on the notebook's pages. +If you wish to suppress this theme, for aesthetic or performance reasons, +there are three ways of doing it. You can use wxNB\_NOPAGETHEME to disable +themed drawing for a particular notebook, you can call {\tt wxSystemOptions::SetOption} +to disable it for the whole application, or you can disable it for individual +pages by using {\tt SetBackgroundColour}. + +To disable themed pages globally: + +\begin{verbatim} + wxSystemOptions::SetOption(wxT("msw.notebook.themed-background"), 0); +\end{verbatim} + +Set the value to 1 to enable it again. + +To give a single page a solid background that more or less fits in with the +overall theme, use: + +\begin{verbatim} + wxColour col = notebook->GetThemeBackgroundColour(); + if (col.Ok()) + { + page->SetBackgroundColour(col); + } +\end{verbatim} + +On platforms other than Windows, or if the application is not using Windows +themes, {\tt GetThemeBackgroundColour} will return an uninitialised colour object, +and the above code will therefore work on all platforms. + \wxheading{See also} \helpref{wxNotebookEvent}{wxnotebookevent}, \helpref{wxImageList}{wximagelist},\rtfsp @@ -228,6 +261,13 @@ the platform and so\rtfsp \helpref{wxNotebookEvent::GetSelection}{wxnotebookeventgetselection} should be used instead in this case. +\membersection{wxNotebook::GetThemeBackgroundColour}\label{wxnotebookgetthemebackgroundcolour} + +\constfunc{wxColour}{GetThemeBackgroundColour}{\void} + +If running under Windows and themes are enabled for the application, this function +returns a suitable colour for painting the background of a notebook page, and can be passed +to {\tt SetBackgroundColour}. Otherwise, an uninitialised colour will be returned. \membersection{wxNotebook::HitTest}\label{wxnotebookhittest} diff --git a/include/wx/defs.h b/include/wx/defs.h index aef702f397..a5ecd73a6d 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1471,6 +1471,7 @@ enum wxBorder #define wxNB_RIGHT 0x0040 #define wxNB_BOTTOM 0x0080 #define wxNB_MULTILINE 0x0100 +#define wxNB_NOPAGETHEME 0x0200 #define wxNB_DEFAULT wxNB_TOP /* diff --git a/include/wx/msw/notebook.h b/include/wx/msw/notebook.h index 97a3141c54..6bed22bbfe 100644 --- a/include/wx/msw/notebook.h +++ b/include/wx/msw/notebook.h @@ -167,6 +167,8 @@ public: virtual bool DoPhase(int nPhase); #endif // wxUSE_CONSTRAINTS + // Attempts to get colour for UX theme page background + wxColour GetThemeBackgroundColour() const; // implementation only // ------------------- diff --git a/include/wx/notebook.h b/include/wx/notebook.h index 3160358587..d67a95e65a 100644 --- a/include/wx/notebook.h +++ b/include/wx/notebook.h @@ -91,6 +91,9 @@ public: // implement some base class functions virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; + // On platforms that support it, get the theme page background colour, else invalid colour + virtual wxColour GetThemeBackgroundColour() const { return wxNullColour; } + protected: DECLARE_NO_COPY_CLASS(wxNotebookBase) }; diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index 3f956fd383..fc545d0008 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -39,6 +39,7 @@ #include "wx/textctrl.h" #endif +#include "wx/sysopt.h" #include "wx/bookctrl.h" #include "wx/sizer.h" #include "wx/colordlg.h" @@ -220,7 +221,7 @@ bool WidgetsApp::OnInit() { if ( !wxApp::OnInit() ) return false; - + // the reason for having these ifdef's is that I often run two copies of // this sample side by side and it is useful to see which one is which wxString title; @@ -288,11 +289,15 @@ WidgetsFrame::WidgetsFrame(const wxString& title) wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); - // we have 2 panes: book which pages demonstrating the controls in the + // we have 2 panes: book with pages demonstrating the controls in the // upper one and the log window with some buttons in the lower + + int style = wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN|wxBC_DEFAULT; + // Uncomment to suppress page theme (draw in solid colour) + // style |= wxNB_NOPAGETHEME; m_book = new wxBookCtrl(m_panel, wxID_ANY, wxDefaultPosition, - wxDefaultSize, wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN|wxBC_DEFAULT); + wxDefaultSize, style); InitBook(); #ifndef __SMARTPHONE__ @@ -377,6 +382,11 @@ void WidgetsFrame::InitBook() false, // don't select n // image id ); + +/* + wxColour colour = m_book->MSWGetBgColourForChild(pages[n]); + pages[n]->SetBackgroundColour(colour); +*/ } } diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 7b5b6de8e5..3f2390950c 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -34,6 +34,7 @@ #include "wx/control.h" #include "wx/notebook.h" #include "wx/app.h" +#include "wx/sysopt.h" #include "wx/msw/private.h" @@ -681,6 +682,17 @@ bool wxNotebook::InsertPage(size_t nPage, SetSelection(selNew); InvalidateBestSize(); + + if (HasFlag(wxNB_NOPAGETHEME) || (wxSystemOptions::HasOption(wxT("msw.notebook.themed-background")) && + wxSystemOptions::GetOptionInt(wxT("msw.notebook.themed-background")) == 0)) + { + wxColour col = GetThemeBackgroundColour(); + if (col.Ok()) + { + pPage->SetBackgroundColour(col); + } + } + return true; } @@ -993,6 +1005,53 @@ wxColour wxNotebook::MSWGetBgColourForChild(wxWindow *win) #endif // wxUSE_UXTHEME +// Windows only: attempts to get colour for UX theme page background +wxColour wxNotebook::GetThemeBackgroundColour() const +{ +#if wxUSE_UXTHEME + if (wxUxThemeEngine::Get()) + { + wxUxThemeHandle hTheme((wxNotebook*) this, L"TAB"); + if (hTheme) + { + // This is total guesswork. + // See PlatformSDK\Include\Tmschema.h for values + COLORREF themeColor; + wxUxThemeEngine::Get()->GetThemeColor( + hTheme, + 10 /* TABP_BODY */, + 1 /* NORMAL */, + 3821 /* FILLCOLORHINT */, + &themeColor); + + /* + [DS] Workaround for WindowBlinds: + Some themes return a near black theme color using FILLCOLORHINT, + this makes notebook pages have an ugly black background and makes + text (usually black) unreadable. Retry again with FILLCOLOR. + + This workaround potentially breaks appearance of some themes, + but in practice it already fixes some themes. + */ + if (themeColor == 1) + { + wxUxThemeEngine::Get()->GetThemeColor( + hTheme, + 10 /* TABP_BODY */, + 1 /* NORMAL */, + 3802 /* FILLCOLOR */, + &themeColor); + } + + wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor)); + return colour; + } + } +#endif // wxUSE_UXTHEME + + return GetBackgroundColour(); +} + // ---------------------------------------------------------------------------- // wxNotebook base class virtuals // ---------------------------------------------------------------------------- -- 2.45.2