X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cb352236d9c7228e336a98c2c1a22e933c67e449..f5f172485bf36ac1025395efc8073c1592c30c08:/src/gtk/app.cpp diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 14b556b2e5..e982ec4ab0 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -7,12 +7,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __VMS -// vms_jackets.h should for proper working be included before anything else -# include -#undef ConnectionNumber -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -32,10 +26,13 @@ #include #endif -#include "wx/gtk/win_gtk.h" #include "wx/gtk/private.h" #include "wx/apptrait.h" +#if wxUSE_LIBHILDON + #include +#endif // wxUSE_LIBHILDON + #include //----------------------------------------------------------------------------- @@ -51,22 +48,15 @@ // global data //----------------------------------------------------------------------------- -bool g_mainThreadLocked = false; - -static GtkWidget *gs_RootWindow = (GtkWidget*) NULL; +static GtkWidget *gs_RootWindow = NULL; //----------------------------------------------------------------------------- // wxYield //----------------------------------------------------------------------------- -// not static because used by textctrl.cpp -// -// MT-FIXME -bool wxIsInsideYield = false; - bool wxApp::Yield(bool onlyIfNeeded) { - if ( wxIsInsideYield ) + if ( m_isInsideYield ) { if ( !onlyIfNeeded ) { @@ -84,7 +74,7 @@ bool wxApp::Yield(bool onlyIfNeeded) } #endif // wxUSE_THREADS - wxIsInsideYield = true; + m_isInsideYield = true; #if wxUSE_LOG // disable log flushing from here because a call to wxYield() shouldn't @@ -108,7 +98,7 @@ bool wxApp::Yield(bool onlyIfNeeded) wxLog::Resume(); #endif - wxIsInsideYield = false; + m_isInsideYield = false; return true; } @@ -209,6 +199,11 @@ bool wxApp::DoIdle() g_source_remove(m_idleSourceId); m_idleSourceId = 0; } + + // Pending events can be added asynchronously, + // need to keep idle source if any have appeared + needMore = needMore || HasPendingEvents(); + // if more idle processing requested if (needMore) { @@ -221,31 +216,6 @@ bool wxApp::DoIdle() return false; } -#if wxUSE_THREADS - -static GPollFunc wxgs_poll_func; - -extern "C" { -static gint wxapp_poll_func( GPollFD *ufds, guint nfds, gint timeout ) -{ - gdk_threads_enter(); - - wxMutexGuiLeave(); - g_mainThreadLocked = true; - - gint res = (*wxgs_poll_func)(ufds, nfds, timeout); - - wxMutexGuiEnter(); - g_mainThreadLocked = false; - - gdk_threads_leave(); - - return res; -} -} - -#endif // wxUSE_THREADS - //----------------------------------------------------------------------------- // Access to the root window global //----------------------------------------------------------------------------- @@ -266,10 +236,6 @@ GtkWidget* wxGetRootWindow() IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler) -BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) - EVT_IDLE(wxAppBase::OnIdle) -END_EVENT_TABLE() - wxApp::wxApp() { #ifdef __WXDEBUG__ @@ -285,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() ) @@ -328,6 +318,15 @@ bool wxApp::OnInitGui() } } +#if wxUSE_LIBHILDON + m_hildonProgram = hildon_program_get_instance(); + if ( !m_hildonProgram ) + { + wxLogError(_("Unable to initialize Hildon program")); + return false; + } +#endif // wxUSE_LIBHILDON + return true; } @@ -346,27 +345,22 @@ GdkVisual *wxApp::GetGdkVisual() return visual; } -bool wxApp::Initialize(int& argc, wxChar **argv) +// use unusual names for the parameters to avoid conflict with wxApp::arg[cv] +bool wxApp::Initialize(int& argc_, wxChar **argv_) { - if ( !wxAppBase::Initialize(argc, argv) ) + if ( !wxAppBase::Initialize(argc_, argv_) ) return false; #if wxUSE_THREADS if (!g_thread_supported()) + { g_thread_init(NULL); - - wxgs_poll_func = g_main_context_get_poll_func(NULL); - g_main_context_set_poll_func(NULL, wxapp_poll_func); + gdk_threads_init(); + } #endif // wxUSE_THREADS - // We should have the wxUSE_WCHAR_T test on the _outside_ -#if wxUSE_WCHAR_T // gtk+ 2.0 supports Unicode through UTF-8 strings wxConvCurrent = &wxConvUTF8; -#else // !wxUSE_WCHAR_T - if (!wxOKlibc()) - wxConvCurrent = (wxMBConv*) NULL; -#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T // decide which conversion to use for the file names @@ -403,19 +397,19 @@ bool wxApp::Initialize(int& argc, wxChar **argv) bool init_result; + int i; #if wxUSE_UNICODE // gtk_init() wants UTF-8, not wchar_t, so convert - int i; - char **argvGTK = new char *[argc + 1]; - for ( i = 0; i < argc; i++ ) + char **argvGTK = new char *[argc_ + 1]; + for ( i = 0; i < argc_; i++ ) { - argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv[i])); + argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv_[i])); } - argvGTK[argc] = NULL; + argvGTK[argc_] = NULL; - int argcGTK = argc; + int argcGTK = argc_; #ifdef __WXGPE__ init_result = true; // is there a _check() version of this? @@ -425,18 +419,19 @@ bool wxApp::Initialize(int& argc, wxChar **argv) #endif wxUpdateLocaleIsUtf8(); - if ( argcGTK != argc ) + if ( argcGTK != argc_ ) { // we have to drop the parameters which were consumed by GTK+ for ( i = 0; i < argcGTK; i++ ) { - while ( strcmp(wxConvUTF8.cWX2MB(argv[i]), argvGTK[i]) != 0 ) + while ( strcmp(wxConvUTF8.cWX2MB(argv_[i]), argvGTK[i]) != 0 ) { - memmove(argv + i, argv + i + 1, (argc - i)*sizeof(*argv)); + memmove(argv_ + i, argv_ + i + 1, (argc_ - i)*sizeof(*argv_)); } } - argc = argcGTK; + argc_ = argcGTK; + argv_[argc_] = NULL; } //else: gtk_init() didn't modify our parameters @@ -448,14 +443,14 @@ bool wxApp::Initialize(int& argc, wxChar **argv) delete [] argvGTK; #else // !wxUSE_UNICODE - // gtk_init() shouldn't actually change argv itself (just its contents) so + // gtk_init() shouldn't actually change argv_ itself (just its contents) so // it's ok to pass pointer to it - init_result = gtk_init_check( &argc, &argv ); + init_result = gtk_init_check( &argc_, &argv_ ); #endif // wxUSE_UNICODE/!wxUSE_UNICODE // update internal arg[cv] as GTK+ may have removed processed options: - this->argc = argc; - this->argv = argv; + this->argc = argc_; + this->argv = argv_; if ( m_traits ) { @@ -466,10 +461,10 @@ bool wxApp::Initialize(int& argc, wxChar **argv) wxArrayString opt, desc; m_traits->GetStandardCmdLineOptions(opt, desc); - for ( int i = 0; i < argc; i++ ) + for ( i = 0; i < argc_; i++ ) { // leave just the names of the options with values - const wxString str = wxString(argv[i]).BeforeFirst('='); + const wxString str = wxString(argv_[i]).BeforeFirst('='); for ( size_t j = 0; j < opt.size(); j++ ) { @@ -482,7 +477,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv) // options) it, so abort, just as we do if incorrect // program option is given wxLogError(_("Invalid GTK+ command line option, use \"%s --help\""), - argv[0]); + argv_[0]); return false; } } @@ -518,16 +513,21 @@ void wxApp::CleanUp() { if (m_idleSourceId != 0) g_source_remove(m_idleSourceId); -#if wxUSE_THREADS - delete m_idleMutex; - m_idleMutex = NULL; -#endif + // release reference acquired by Initialize() g_type_class_unref(g_type_class_peek(GTK_TYPE_WIDGET)); gdk_threads_leave(); wxAppBase::CleanUp(); + + // delete this mutex as late as possible as it's used from WakeUpIdle(), in + // particular do it after calling the base class CleanUp() which can result + // in it being called +#if wxUSE_THREADS + delete m_idleMutex; + m_idleMutex = NULL; +#endif } void wxApp::WakeUpIdle() @@ -573,3 +573,15 @@ void wxApp::OnAssertFailure(const wxChar *file, } #endif // __WXDEBUG__ + +#if wxUSE_THREADS +void wxGUIAppTraits::MutexGuiEnter() +{ + gdk_threads_enter(); +} + +void wxGUIAppTraits::MutexGuiLeave() +{ + gdk_threads_leave(); +} +#endif // wxUSE_THREADS