From c50c6fb23b0a538f3403f42149e2f5b90957d7ac Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 27 Feb 2008 17:46:14 +0000 Subject: [PATCH] add SetNativeTheme() (slightly modified patch 1884553) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52149 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 3 ++- docs/latex/wx/app.tex | 13 +++++++++++++ include/wx/app.h | 3 +++ include/wx/gtk/app.h | 1 + src/gtk/app.cpp | 24 ++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 4f12f8d4dc..fa3672d775 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -279,7 +279,8 @@ All (GUI): - Made wxSizer::Fit() set the client size of the target window - Add support for wxDatePickerCtrl in wxGenericValidator (Herry Ayen Yang) - Added wxWindow::HasFocus(). -- Added wxGLCanvas::IsDisplaySupported() +- Added wxGLCanvas::IsDisplaySupported(). +- Added wxApp::SetNativeTheme() (Stefan H.). wxGTK: diff --git a/docs/latex/wx/app.tex b/docs/latex/wx/app.tex index adefdadd83..3c2a3a25fa 100644 --- a/docs/latex/wx/app.tex +++ b/docs/latex/wx/app.tex @@ -734,6 +734,19 @@ know what you're doing if you call it. \helpref{wxApp::GetInstance}{wxappgetinstance} +\membersection{wxApp::SetNativeTheme}\label{wxappsetnativetheme} + +\func{bool}{SetNativeTheme}{\param{const}{wxString\&}{theme}} + +Allows runtime switching of the UI environment theme. Currently implemented for wxGTK2-only. + +Return \true if theme was successfully changed. + +\wxheading{Parameters} + +\docparam{theme}{The name of the new theme or an absolute path to a gtkrc-theme-file} + + \membersection{wxApp::SetTopWindow}\label{wxappsettopwindow} \func{void}{SetTopWindow}{\param{wxWindow* }{window}} diff --git a/include/wx/app.h b/include/wx/app.h index d01c877acf..553a29aa5c 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -509,6 +509,9 @@ public: // if it's unknown virtual wxLayoutDirection GetLayoutDirection() const; + // Change the theme used by the application, return true on success. + virtual bool SetNativeTheme(const wxString& WXUNUSED(theme)) { return false; } + // command line parsing (GUI-specific) // ------------------------------------------------------------------------ diff --git a/include/wx/gtk/app.h b/include/wx/gtk/app.h index b258ea5a99..ce6da5421e 100644 --- a/include/wx/gtk/app.h +++ b/include/wx/gtk/app.h @@ -36,6 +36,7 @@ public: * (palette/visual/colorcube). under wxMSW, OnInitGui() does nothing by * default. when overriding this method, the code in it is likely to be * platform dependent, otherwise use OnInit(). */ + virtual bool SetNativeTheme(const wxString& theme); virtual bool OnInitGui(); // override base class (pure) virtuals diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 138f2eac56..d16741238b 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -251,6 +251,30 @@ wxApp::~wxApp() { } +bool wxApp::SetNativeTheme(const wxString& theme) +{ + wxString path; + path = gtk_rc_get_theme_dir(); + path += "/"; + path += theme.utf8_str(); + path += "/gtk-2.0/gtkrc"; + + if ( wxFileExists(path.utf8_str()) ) + gtk_rc_add_default_file(path.utf8_str()); + else if ( wxFileExists(theme.utf8_str()) ) + gtk_rc_add_default_file(theme.utf8_str()); + else + { + wxLogWarning("Theme \"%s\" not available.", theme); + + return false; + } + + gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE); + + return true; +} + bool wxApp::OnInitGui() { if ( !wxAppBase::OnInitGui() ) -- 2.47.2