From 04209e3a3e9e40b9a7d1f8559a8c476762bcd14a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Nov 2017 22:02:36 +0100 Subject: [PATCH] Remove GetStandardCmdLineOptions() from wxGTK Unfortunately there is no reasonable way to implement this function for all glibc versions as the information we need is stored in the private _GOptionGroup struct whose layout has already changed once (in 2.44) and could change again, so we can't rely on it. We really need a g_option_group_get_entries() in glib itself, but the request to add it at http://bugzilla.gnome.org/show_bug.cgi?id=431021 hasn't been touched since 10 years, so it seems unlikely to happen. See https://github.com/wxWidgets/wxWidgets/commit/99367a1530de233ccfd06eca366bb995cb55f4a0#commitcomment-25789514 --- include/wx/unix/apptrait.h | 2 - src/gtk/app.cpp | 32 ------------- src/gtk/utilsgtk.cpp | 95 -------------------------------------- 3 files changed, 129 deletions(-) diff --git a/include/wx/unix/apptrait.h b/include/wx/unix/apptrait.h index 1095a3c37b..65136534e9 100644 --- a/include/wx/unix/apptrait.h +++ b/include/wx/unix/apptrait.h @@ -64,8 +64,6 @@ public: #ifdef __WXGTK20__ virtual wxString GetDesktopEnvironment() const wxOVERRIDE; - virtual wxString GetStandardCmdLineOptions(wxArrayString& names, - wxArrayString& desc) const wxOVERRIDE; #endif // __WXGTK20____ #if defined(__WXGTK20__) diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 0be93fc816..f0f4418bcf 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -402,38 +402,6 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) this->argv = argv_; #endif - if ( m_traits ) - { - // if there are still GTK+ standard options unparsed in the command - // line, it means that they were not syntactically correct and GTK+ - // already printed a warning on the command line and we should now - // exit: - wxArrayString opt, desc; - m_traits->GetStandardCmdLineOptions(opt, desc); - - for ( i = 0; i < argc_; i++ ) - { - // leave just the names of the options with values - const wxString str = wxString(argv_[i]).BeforeFirst('='); - - for ( size_t j = 0; j < opt.size(); j++ ) - { - // remove the leading spaces from the option string as it does - // have them - if ( opt[j].Trim(false).BeforeFirst('=') == str ) - { - // a GTK+ option can be left on the command line only if - // there was an error in (or before, in another standard - // 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]); - return false; - } - } - } - } - if ( !init_result ) { wxLogError(_("Unable to initialize GTK+, is DISPLAY set properly?")); diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 110288eed7..43d4a3f3a4 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -417,98 +417,3 @@ wxString wxGUIAppTraits::GetDesktopEnvironment() const } #endif // __UNIX__ - -#ifdef __UNIX__ - -// see the hack below in wxCmdLineParser::GetUsageString(). -// TODO: replace this hack with a g_option_group_get_entries() -// call as soon as such function exists; -// see http://bugzilla.gnome.org/show_bug.cgi?id=431021 for the relative -// feature request -struct _GOptionGroup -{ - gchar *name; - gchar *description; - gchar *help_description; - - GDestroyNotify destroy_notify; - gpointer user_data; - - GTranslateFunc translate_func; - GDestroyNotify translate_notify; - gpointer translate_data; - - GOptionEntry *entries; - gint n_entries; - - GOptionParseFunc pre_parse_func; - GOptionParseFunc post_parse_func; - GOptionErrorFunc error_func; -}; - -static -wxString wxGetNameFromGtkOptionEntry(const GOptionEntry *opt) -{ - wxString ret; - - if (opt->short_name) - ret << wxT("-") << opt->short_name; - if (opt->long_name) - { - if (!ret.empty()) - ret << wxT(", "); - ret << wxT("--") << opt->long_name; - - if (opt->arg_description) - ret << wxT("=") << opt->arg_description; - } - - return wxT(" ") + ret; -} - -wxString -wxGUIAppTraits::GetStandardCmdLineOptions(wxArrayString& names, - wxArrayString& desc) const -{ - wxString usage; - - // Check whether GLib version is lower than the last tested version for - // which the code below works because, as we use the undocumented - // _GOptionGroup struct, we don't want to run this code with future - // versions which might change it and result in run-time crashes. - if (glib_check_version(2,50,0)) - { - usage << _("The following standard GTK+ options are also supported:\n"); - - // passing true here means that the function can open the default - // display while parsing (not really used here anyhow) - GOptionGroup *gtkOpts = gtk_get_option_group(true); - - // WARNING: here we access the internals of GOptionGroup: - GOptionEntry *entries = ((_GOptionGroup*)gtkOpts)->entries; - unsigned int n_entries = ((_GOptionGroup*)gtkOpts)->n_entries; - wxArrayString namesOptions, descOptions; - - for ( size_t n = 0; n < n_entries; n++ ) - { - if ( entries[n].flags & G_OPTION_FLAG_HIDDEN ) - continue; // skip - - names.push_back(wxGetNameFromGtkOptionEntry(&entries[n])); - - const gchar * const entryDesc = entries[n].description; - desc.push_back(wxString(entryDesc)); - } - - // This function is deprecated in favour of g_option_group_unref(), but - // we need to continue using it as long as we support glib < 2.44 where - // the new function was introduced, so just suppress the warning. - wxGCC_WARNING_SUPPRESS(deprecated-declarations) - g_option_group_free (gtkOpts); - wxGCC_WARNING_RESTORE(deprecated-declarations) - } - - return usage; -} - -#endif // __UNIX__