X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/291b0f5b14b62be240ae5cb1ec2ade3d8db6a776..55410bb4f67febe1ca20654f078ea4fb9a6223ae:/src/gtk/app.cpp diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index ad027a0232..18c05dda50 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 //----------------------------------------------------------------------------- @@ -47,72 +44,6 @@ wxFORCE_LINK_MODULE(gnome_vfs) #endif -//----------------------------------------------------------------------------- -// global data -//----------------------------------------------------------------------------- - -bool g_mainThreadLocked = false; - -static GtkWidget *gs_RootWindow = (GtkWidget*) NULL; - -//----------------------------------------------------------------------------- -// wxYield -//----------------------------------------------------------------------------- - -// not static because used by textctrl.cpp -// -// MT-FIXME -bool wxIsInsideYield = false; - -bool wxApp::Yield(bool onlyIfNeeded) -{ - if ( wxIsInsideYield ) - { - if ( !onlyIfNeeded ) - { - wxFAIL_MSG( wxT("wxYield called recursively" ) ); - } - - return false; - } - -#if wxUSE_THREADS - if ( !wxThread::IsMain() ) - { - // can't call gtk_main_iteration() from other threads like this - return true; - } -#endif // wxUSE_THREADS - - wxIsInsideYield = true; - -#if wxUSE_LOG - // disable log flushing from here because a call to wxYield() shouldn't - // normally result in message boxes popping up &c - wxLog::Suspend(); -#endif - - while (EventsPending()) - gtk_main_iteration(); - - // It's necessary to call ProcessIdle() to update the frames sizes which - // might have been changed (it also will update other things set from - // OnUpdateUI() which is a nice (and desired) side effect). But we - // call ProcessIdle() only once since this is not meant for longish - // background jobs (controlled by wxIdleEvent::RequestMore() and the - // return value of Processidle(). - ProcessIdle(); - -#if wxUSE_LOG - // let the logs be flashed again - wxLog::Resume(); -#endif - - wxIsInsideYield = false; - - return true; -} - //----------------------------------------------------------------------------- // local functions //----------------------------------------------------------------------------- @@ -209,6 +140,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,43 +157,20 @@ 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 //----------------------------------------------------------------------------- GtkWidget* wxGetRootWindow() { - if (gs_RootWindow == NULL) + static GtkWidget *s_RootWindow = NULL; + + if (s_RootWindow == NULL) { - gs_RootWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL ); - gtk_widget_realize( gs_RootWindow ); + s_RootWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL ); + gtk_widget_realize( s_RootWindow ); } - return gs_RootWindow; + return s_RootWindow; } //----------------------------------------------------------------------------- @@ -266,10 +179,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 +194,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 +261,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; } @@ -354,20 +296,14 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) #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 @@ -404,10 +340,10 @@ 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++ ) { @@ -438,6 +374,7 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) } argc_ = argcGTK; + argv_[argc_] = NULL; } //else: gtk_init() didn't modify our parameters @@ -467,7 +404,7 @@ 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('='); @@ -519,16 +456,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() @@ -574,3 +516,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