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 99367a1530 (commitcomment-25789514)
This commit is contained in:
@@ -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__)
|
||||
|
@@ -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?"));
|
||||
|
@@ -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__
|
||||
|
Reference in New Issue
Block a user