Make gtk argument parsing use goption. Add gtk_get_option_group and

2004-09-05  Anders Carlsson  <andersca@gnome.org>

	* gdk/gdk.c: (gdk_arg_class_cb), (gdk_arg_name_cb),
	(gdk_add_option_entries_libgtk_only), (gdk_pre_parse_libgtk_only),
	(gdk_parse_args):
	* gdk/gdk.h:
	* gdk/gdkinternals.h:
	* gdk/linux-fb/gdkmain-fb.c: (_gdk_windowing_init):
	* gdk/win32/gdkmain-win32.c: (_gdk_windowing_init):
	* gdk/x11/gdkdisplay-x11.c: (gdk_display_open):
	* gdk/x11/gdkmain-x11.c: (_gdk_windowing_init):
	* gtk/gtkmain.c: (gtk_arg_debug_cb), (gtk_arg_no_debug_cb),
	(gtk_arg_module_cb), (gtk_arg_warnings_cb),
	(do_pre_parse_initialization), (do_post_parse_initialization),
	(pre_parse_hook), (post_parse_hook), (gtk_get_option_group),
	(gtk_init_with_args), (gtk_parse_args):
	* gtk/gtkmain.h:
	Make gtk argument parsing use goption. Add gtk_get_option_group and
	gtk_init_with_args.

	* tests/testtreemodel.c: (main):
	Use gtk_init_with_args.
This commit is contained in:
Anders Carlsson 2004-09-05 15:09:55 +00:00 committed by Anders Carlsson
parent b2e8a932e6
commit 04d65a6d3d
14 changed files with 390 additions and 370 deletions

View File

@ -1,3 +1,26 @@
2004-09-05 Anders Carlsson <andersca@gnome.org>
* gdk/gdk.c: (gdk_arg_class_cb), (gdk_arg_name_cb),
(gdk_add_option_entries_libgtk_only), (gdk_pre_parse_libgtk_only),
(gdk_parse_args):
* gdk/gdk.h:
* gdk/gdkinternals.h:
* gdk/linux-fb/gdkmain-fb.c: (_gdk_windowing_init):
* gdk/win32/gdkmain-win32.c: (_gdk_windowing_init):
* gdk/x11/gdkdisplay-x11.c: (gdk_display_open):
* gdk/x11/gdkmain-x11.c: (_gdk_windowing_init):
* gtk/gtkmain.c: (gtk_arg_debug_cb), (gtk_arg_no_debug_cb),
(gtk_arg_module_cb), (gtk_arg_warnings_cb),
(do_pre_parse_initialization), (do_post_parse_initialization),
(pre_parse_hook), (post_parse_hook), (gtk_get_option_group),
(gtk_init_with_args), (gtk_parse_args):
* gtk/gtkmain.h:
Make gtk argument parsing use goption. Add gtk_get_option_group and
gtk_init_with_args.
* tests/testtreemodel.c: (main):
Use gtk_init_with_args.
Sun Sep 5 01:04:01 2004 Matthias Clasen <maclas@gmx.de>
Allow sorting of tree models to be turned off

View File

@ -1,3 +1,26 @@
2004-09-05 Anders Carlsson <andersca@gnome.org>
* gdk/gdk.c: (gdk_arg_class_cb), (gdk_arg_name_cb),
(gdk_add_option_entries_libgtk_only), (gdk_pre_parse_libgtk_only),
(gdk_parse_args):
* gdk/gdk.h:
* gdk/gdkinternals.h:
* gdk/linux-fb/gdkmain-fb.c: (_gdk_windowing_init):
* gdk/win32/gdkmain-win32.c: (_gdk_windowing_init):
* gdk/x11/gdkdisplay-x11.c: (gdk_display_open):
* gdk/x11/gdkmain-x11.c: (_gdk_windowing_init):
* gtk/gtkmain.c: (gtk_arg_debug_cb), (gtk_arg_no_debug_cb),
(gtk_arg_module_cb), (gtk_arg_warnings_cb),
(do_pre_parse_initialization), (do_post_parse_initialization),
(pre_parse_hook), (post_parse_hook), (gtk_get_option_group),
(gtk_init_with_args), (gtk_parse_args):
* gtk/gtkmain.h:
Make gtk argument parsing use goption. Add gtk_get_option_group and
gtk_init_with_args.
* tests/testtreemodel.c: (main):
Use gtk_init_with_args.
Sun Sep 5 01:04:01 2004 Matthias Clasen <maclas@gmx.de>
Allow sorting of tree models to be turned off

View File

@ -1,3 +1,26 @@
2004-09-05 Anders Carlsson <andersca@gnome.org>
* gdk/gdk.c: (gdk_arg_class_cb), (gdk_arg_name_cb),
(gdk_add_option_entries_libgtk_only), (gdk_pre_parse_libgtk_only),
(gdk_parse_args):
* gdk/gdk.h:
* gdk/gdkinternals.h:
* gdk/linux-fb/gdkmain-fb.c: (_gdk_windowing_init):
* gdk/win32/gdkmain-win32.c: (_gdk_windowing_init):
* gdk/x11/gdkdisplay-x11.c: (gdk_display_open):
* gdk/x11/gdkmain-x11.c: (_gdk_windowing_init):
* gtk/gtkmain.c: (gtk_arg_debug_cb), (gtk_arg_no_debug_cb),
(gtk_arg_module_cb), (gtk_arg_warnings_cb),
(do_pre_parse_initialization), (do_post_parse_initialization),
(pre_parse_hook), (post_parse_hook), (gtk_get_option_group),
(gtk_init_with_args), (gtk_parse_args):
* gtk/gtkmain.h:
Make gtk argument parsing use goption. Add gtk_get_option_group and
gtk_init_with_args.
* tests/testtreemodel.c: (main):
Use gtk_init_with_args.
Sun Sep 5 01:04:01 2004 Matthias Clasen <maclas@gmx.de>
Allow sorting of tree models to be turned off

View File

@ -1,3 +1,26 @@
2004-09-05 Anders Carlsson <andersca@gnome.org>
* gdk/gdk.c: (gdk_arg_class_cb), (gdk_arg_name_cb),
(gdk_add_option_entries_libgtk_only), (gdk_pre_parse_libgtk_only),
(gdk_parse_args):
* gdk/gdk.h:
* gdk/gdkinternals.h:
* gdk/linux-fb/gdkmain-fb.c: (_gdk_windowing_init):
* gdk/win32/gdkmain-win32.c: (_gdk_windowing_init):
* gdk/x11/gdkdisplay-x11.c: (gdk_display_open):
* gdk/x11/gdkmain-x11.c: (_gdk_windowing_init):
* gtk/gtkmain.c: (gtk_arg_debug_cb), (gtk_arg_no_debug_cb),
(gtk_arg_module_cb), (gtk_arg_warnings_cb),
(do_pre_parse_initialization), (do_post_parse_initialization),
(pre_parse_hook), (post_parse_hook), (gtk_get_option_group),
(gtk_init_with_args), (gtk_parse_args):
* gtk/gtkmain.h:
Make gtk argument parsing use goption. Add gtk_get_option_group and
gtk_init_with_args.
* tests/testtreemodel.c: (main):
Use gtk_init_with_args.
Sun Sep 5 01:04:01 2004 Matthias Clasen <maclas@gmx.de>
Allow sorting of tree models to be turned off

273
gdk/gdk.c
View File

@ -77,135 +77,6 @@ static const int gdk_ndebug_keys = G_N_ELEMENTS (gdk_debug_keys);
#endif /* G_ENABLE_DEBUG */
static GdkArgContext *
gdk_arg_context_new (gpointer cb_data)
{
GdkArgContext *result = g_new (GdkArgContext, 1);
result->tables = g_ptr_array_new ();
result->cb_data = cb_data;
return result;
}
static void
gdk_arg_context_destroy (GdkArgContext *context)
{
g_ptr_array_free (context->tables, TRUE);
g_free (context);
}
static void
gdk_arg_context_add_table (GdkArgContext *context, GdkArgDesc *table)
{
g_ptr_array_add (context->tables, table);
}
static void
gdk_arg_context_parse (GdkArgContext *context, gint *argc, gchar ***argv)
{
int i, j, k;
if (argc && argv)
{
for (i = 1; i < *argc; i++)
{
char *arg;
if (!((*argv)[i][0] == '-' && (*argv)[i][1] == '-'))
continue;
arg = (*argv)[i] + 2;
/* '--' terminates list of arguments */
if (*arg == 0)
{
(*argv)[i] = NULL;
break;
}
for (j = 0; j < context->tables->len; j++)
{
GdkArgDesc *table = context->tables->pdata[j];
for (k = 0; table[k].name; k++)
{
switch (table[k].type)
{
case GDK_ARG_STRING:
case GDK_ARG_CALLBACK:
case GDK_ARG_INT:
{
int len = strlen (table[k].name);
if (strncmp (arg, table[k].name, len) == 0 &&
(arg[len] == '=' || arg[len] == 0))
{
char *value = NULL;
(*argv)[i] = NULL;
if (arg[len] == '=')
value = arg + len + 1;
else if (i < *argc - 1)
{
value = (*argv)[i + 1];
(*argv)[i+1] = NULL;
i++;
}
else
value = "";
switch (table[k].type)
{
case GDK_ARG_STRING:
*(gchar **)table[k].location = g_strdup (value);
break;
case GDK_ARG_INT:
*(gint *)table[k].location = atoi (value);
break;
case GDK_ARG_CALLBACK:
(*table[k].callback)(table[k].name, value, context->cb_data);
break;
default:
;
}
goto next_arg;
}
break;
}
case GDK_ARG_BOOL:
case GDK_ARG_NOBOOL:
if (strcmp (arg, table[k].name) == 0)
{
(*argv)[i] = NULL;
*(gboolean *)table[k].location = (table[k].type == GDK_ARG_BOOL) ? TRUE : FALSE;
goto next_arg;
}
}
}
}
next_arg:
;
}
for (i = 1; i < *argc; i++)
{
for (k = i; k < *argc; k++)
if ((*argv)[k] != NULL)
break;
if (k > i)
{
k -= i;
for (j = i + k; j < *argc; j++)
(*argv)[j-k] = (*argv)[j];
*argc -= k;
}
}
}
}
#ifdef G_ENABLE_DEBUG
static void
gdk_arg_debug_cb (const char *key, const char *value, gpointer user_data)
@ -224,49 +95,78 @@ gdk_arg_no_debug_cb (const char *key, const char *value, gpointer user_data)
}
#endif /* G_ENABLE_DEBUG */
static void
gdk_arg_class_cb (const char *key, const char *value, gpointer user_data)
static gboolean
gdk_arg_class_cb (const char *key, const char *value, gpointer user_data, GError **error)
{
gdk_set_program_class (value);
return TRUE;
}
static void
gdk_arg_name_cb (const char *key, const char *value, gpointer user_data)
static gboolean
gdk_arg_name_cb (const char *key, const char *value, gpointer user_data, GError **error)
{
g_set_prgname (value);
return TRUE;
}
static GdkArgDesc gdk_args[] = {
{ "class" , GDK_ARG_CALLBACK, NULL, gdk_arg_class_cb },
{ "name", GDK_ARG_CALLBACK, NULL, gdk_arg_name_cb },
{ "display", GDK_ARG_STRING, &_gdk_display_name, (GdkArgFunc)NULL },
{ "screen", GDK_ARG_INT, &_gdk_screen_number, (GdkArgFunc)NULL },
static GOptionEntry gdk_args[] = {
{ "class", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_class_cb, NULL, NULL },
{ "name", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_name_cb, NULL, NULL },
{ "display", 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &_gdk_display_name, NULL, NULL },
{ "screen", 0, 0, G_OPTION_ARG_INT, &_gdk_screen_number, NULL, NULL },
#ifdef G_ENABLE_DEBUG
{ "gdk-debug", GDK_ARG_CALLBACK, NULL, gdk_arg_debug_cb },
{ "gdk-no-debug", GDK_ARG_CALLBACK, NULL, gdk_arg_no_debug_cb },
{ "gdk-debug", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_debug_cb, NULL, NULL },
{ "gdk-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_no_debug_cb, NULL, NULL },
#endif /* G_ENABLE_DEBUG */
{ NULL }
};
/**
* _gdk_get_command_line_args:
* @argv: location to store argv pointer
* @argc: location
* gdk_add_option_entries_libgtk_only:
* @group: An option group.
*
* Retrieve the command line arguments passed to gdk_init().
* The returned argv pointer points to static storage ; no
* copy is made.
* Appends gdk option entries to the passed in option group. This is
* not public API and must not be used by applications.
**/
void
_gdk_get_command_line_args (int *argc,
char ***argv)
gdk_add_option_entries_libgtk_only (GOptionGroup *group)
{
*argc = gdk_argc;
*argv = gdk_argv;
g_option_group_add_entries (group, gdk_args);
g_option_group_add_entries (group, _gdk_windowing_args);
}
void
gdk_pre_parse_libgtk_only (void)
{
gdk_initialized = TRUE;
/* We set the fallback program class here, rather than lazily in
* gdk_get_program_class, since we don't want -name to override it.
*/
gdk_progclass = g_strdup (g_get_prgname ());
if (gdk_progclass && gdk_progclass[0])
gdk_progclass[0] = g_ascii_toupper (gdk_progclass[0]);
#ifdef G_ENABLE_DEBUG
{
gchar *debug_string = getenv("GDK_DEBUG");
if (debug_string != NULL)
_gdk_debug_flags = g_parse_debug_string (debug_string,
(GDebugKey *) gdk_debug_keys,
gdk_ndebug_keys);
}
#endif /* G_ENABLE_DEBUG */
g_type_init ();
/* Do any setup particular to the windowing system
*/
_gdk_windowing_init ();
}
/**
* gdk_parse_args:
* @argc: the number of command line arguments.
@ -287,70 +187,27 @@ void
gdk_parse_args (int *argc,
char ***argv)
{
GdkArgContext *arg_context;
gint i;
GOptionContext *option_context;
GOptionGroup *option_group;
if (gdk_initialized)
return;
gdk_initialized = TRUE;
/* Save a copy of the original argc and argv */
if (argc && argv)
{
gdk_argc = *argc;
gdk_argv = g_malloc ((gdk_argc + 1) * sizeof (char*));
for (i = 0; i < gdk_argc; i++)
gdk_argv[i] = g_strdup ((*argv)[i]);
gdk_argv[gdk_argc] = NULL;
}
if (argc && argv && *argc > 0)
{
gchar *d;
d = strrchr((*argv)[0], G_DIR_SEPARATOR);
if (d != NULL)
g_set_prgname (d + 1);
else
g_set_prgname ((*argv)[0]);
}
else
{
g_set_prgname ("<unknown>");
}
/* We set the fallback program class here, rather than lazily in
* gdk_get_program_class, since we don't want -name to override it.
*/
gdk_progclass = g_strdup (g_get_prgname ());
if (gdk_progclass[0])
gdk_progclass[0] = g_ascii_toupper (gdk_progclass[0]);
gdk_pre_parse_libgtk_only ();
#ifdef G_ENABLE_DEBUG
{
gchar *debug_string = getenv("GDK_DEBUG");
if (debug_string != NULL)
_gdk_debug_flags = g_parse_debug_string (debug_string,
(GDebugKey *) gdk_debug_keys,
gdk_ndebug_keys);
}
#endif /* G_ENABLE_DEBUG */
option_context = g_option_context_new (NULL);
g_option_context_set_ignore_unknown_options (option_context, TRUE);
g_option_context_set_help_enabled (option_context, FALSE);
option_group = g_option_group_new (NULL, NULL, NULL, NULL, NULL);
g_option_context_set_main_group (option_context, option_group);
arg_context = gdk_arg_context_new (NULL);
gdk_arg_context_add_table (arg_context, gdk_args);
gdk_arg_context_add_table (arg_context, _gdk_windowing_args);
gdk_arg_context_parse (arg_context, argc, argv);
gdk_arg_context_destroy (arg_context);
g_option_group_add_entries (option_group, gdk_args);
g_option_group_add_entries (option_group, _gdk_windowing_args);
g_option_context_parse (option_context, argc, argv, NULL);
g_option_context_free (option_context);
GDK_NOTE (MISC, g_message ("progname: \"%s\"", g_get_prgname ()));
g_type_init ();
/* Do any setup particular to the windowing system
*/
_gdk_windowing_init (argc, argv);
}
/**

View File

@ -67,6 +67,8 @@ void gdk_init (gint *argc,
gchar ***argv);
gboolean gdk_init_check (gint *argc,
gchar ***argv);
void gdk_add_option_entries_libgtk_only (GOptionGroup *group);
void gdk_pre_parse_libgtk_only (void);
#ifndef GDK_DISABLE_DEPRECATED
void gdk_exit (gint error_code);

View File

@ -238,9 +238,7 @@ void _gdk_colormap_real_destroy (GdkColormap *colormap);
void _gdk_cursor_destroy (GdkCursor *cursor);
extern GdkArgDesc _gdk_windowing_args[];
void _gdk_windowing_init (gint *argc,
gchar ***argv);
extern GOptionEntry _gdk_windowing_args[];
void _gdk_windowing_set_default_display (GdkDisplay *display);
gchar *_gdk_windowing_substitute_screen_number (const gchar *display_name,
@ -327,9 +325,6 @@ GType _gdk_pixmap_impl_get_type (void) G_GNUC_CONST;
void _gdk_image_exit (void);
void _gdk_windowing_exit (void);
void _gdk_get_command_line_args (int *argc,
char ***argv);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -65,7 +65,7 @@ static const int gdk_ndebug_keys = sizeof(gdk_debug_keys)/sizeof(GDebugKey);
#endif /* G_ENABLE_DEBUG */
GdkArgDesc _gdk_windowing_args[] = {
GOptionEntry _gdk_windowing_args[] = {
{ NULL }
};
@ -883,7 +883,7 @@ gdk_fb_display_destroy (GdkFBDisplay *display)
}
void
_gdk_windowing_init (int *argc, char ***argv)
_gdk_windowing_init (void)
{
if (gdk_initialized)
return;

View File

@ -52,15 +52,14 @@
static gboolean gdk_synchronize = FALSE;
GdkArgDesc _gdk_windowing_args[] = {
{ "sync", GDK_ARG_BOOL, &gdk_synchronize, (GdkArgFunc) NULL},
{ "no-wintab", GDK_ARG_BOOL, &_gdk_input_ignore_wintab,
(GdkArgFunc) NULL},
{ "ignore-wintab", GDK_ARG_BOOL, &_gdk_input_ignore_wintab,
(GdkArgFunc) NULL},
{ "use-wintab", GDK_ARG_NOBOOL, &_gdk_input_ignore_wintab,
(GdkArgFunc) NULL},
{ "max-colors", GDK_ARG_INT, &_gdk_max_colors, (GdkArgFunc) NULL},
GOptionEntry _gdk_windowing_args[] = {
{ "sync", 0, 0, G_OPTION_ARG_NONE, &_gdk_synchronize, NULL, NULL },
{ "no-wintab", 0, 0, G_OPTION_ARG_NONE, &_gdk_input_ignore_wintab, NULL, NULL },
{ "ignore-wintab", 0, 0, G_OPTION_ARG_NONE, &_gdk_input_ignore_wintab, NULL, NULL },
#if 0
{ "use-wintab", 0, 0, G_OPTION_ARG_NONE, &_gdk_input_ignore_wintab, NULL, NULL },
#endif
{ "max-colors", 0, 0, G_OPTION_ARG_INT, &_gdk_max_colors, NULL, NULL },
{ NULL }
};
@ -75,8 +74,7 @@ DllMain (HINSTANCE hinstDLL,
}
void
_gdk_windowing_init (gint *argc,
gchar ***argv)
_gdk_windowing_init (void)
{
gchar buf[10];

View File

@ -130,6 +130,7 @@ gdk_display_x11_class_init (GdkDisplayX11Class * class)
parent_class = g_type_class_peek_parent (class);
}
/**
* gdk_display_open:
* @display_name: the name of the display to open
@ -148,7 +149,7 @@ gdk_display_open (const gchar *display_name)
GdkDisplayX11 *display_x11;
GdkWindowAttr attr;
gint argc;
gchar **argv;
gchar *argv[1];
const char *sm_client_id;
XClassHint *class_hint;
@ -227,7 +228,13 @@ gdk_display_open (const gchar *display_name)
class_hint->res_name = g_get_prgname ();
class_hint->res_class = (char *)gdk_get_program_class ();
_gdk_get_command_line_args (&argc, &argv);
/* XmbSetWMProperties sets the RESOURCE_NAME environment variable
* from argv[0], so we just synthesize an argument array here.
*/
argc = 1;
argv[0] = g_get_prgname ();
XmbSetWMProperties (display_x11->xdisplay,
display_x11->leader_window,
NULL, NULL, argv, argc, NULL, NULL,

View File

@ -86,14 +86,13 @@ static int gdk_x_io_error (Display *display);
static GSList *gdk_error_traps = NULL; /* List of error traps */
static GSList *gdk_error_trap_free_list = NULL; /* Free list */
GdkArgDesc _gdk_windowing_args[] = {
{ "sync", GDK_ARG_BOOL, &_gdk_synchronize, (GdkArgFunc)NULL },
GOptionEntry _gdk_windowing_args[] = {
{ "sync", 0, 0, G_OPTION_ARG_NONE, &_gdk_synchronize, NULL, NULL },
{ NULL }
};
void
_gdk_windowing_init (gint *argc,
gchar ***argv)
_gdk_windowing_init (void)
{
_gdk_x11_initialize_locale ();

View File

@ -348,35 +348,71 @@ gtk_disable_setlocale (void)
#undef gtk_init_check
#endif
/**
* gtk_parse_args:
* @argc: a pointer to the number of command line arguments.
* @argv: a pointer to the array of command line arguments.
*
* Parses command line arguments, and initializes global
* attributes of GTK+, but does not actually open a connection
* to a display. (See gdk_display_open(), gdk_get_display_arg_name())
*
* Any arguments used by GTK+ or GDK are removed from the array and
* @argc and @argv are updated accordingly.
*
* You shouldn't call this function explicitely if you are using
* gtk_init(), or gtk_init_check().
*
* Return value: %TRUE if initialization succeeded, otherwise %FALSE.
**/
gboolean
gtk_parse_args (int *argc,
char ***argv)
static GString *gtk_modules_string = NULL;
#ifdef G_ENABLE_DEBUG
static gboolean
gtk_arg_debug_cb (const char *key, const char *value, gpointer user_data)
{
gtk_debug_flags |= g_parse_debug_string (value,
gtk_debug_keys,
gtk_ndebug_keys);
return TRUE;
}
static gboolean
gtk_arg_no_debug_cb (const char *key, const char *value, gpointer user_data)
{
gtk_debug_flags &= ~g_parse_debug_string (value,
gtk_debug_keys,
gtk_ndebug_keys);
}
#endif /* G_ENABLE_DEBUG */
static gboolean
gtk_arg_module_cb (const char *key, const char *value, gpointer user_data)
{
if (value && *value)
{
if (gtk_modules_string)
g_string_append_c (gtk_modules_string, G_SEARCHPATH_SEPARATOR);
else
gtk_modules_string = g_string_new (NULL);
g_string_append (gtk_modules_string, value);
}
return TRUE;
}
static gboolean
gtk_arg_warnings_cb (const char *key, const char *value, gpointer user_data)
{
GLogLevelFlags fatal_mask;
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
g_log_set_always_fatal (fatal_mask);
return TRUE;
}
static GOptionEntry gtk_args[] = {
{ "gtk-module", 0, 0, G_OPTION_ARG_CALLBACK, gtk_arg_module_cb, NULL, NULL },
{ "g-fatal-warnings", 0, 0, G_OPTION_ARG_CALLBACK, gtk_arg_warnings_cb, NULL, NULL },
#ifdef G_ENABLE_DEBUG
{ "gtk-debug", 0, 0, G_OPTION_ARG_CALLBACK, gtk_arg_debug_cb, NULL, NULL },
{ "gtk-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, gtk_arg_no_debug_cb, NULL, NULL },
#endif /* G_ENABLE_DEBUG */
{ NULL }
};
static void
do_pre_parse_initialization (int *argc,
char ***argv)
{
GString *gtk_modules_string = NULL;
const gchar *env_string;
if (gtk_initialized)
return TRUE;
if (!check_setugid ())
return FALSE;
#if 0
g_set_error_handler (gtk_error);
@ -391,7 +427,7 @@ gtk_parse_args (int *argc,
g_warning ("Locale not supported by C library.\n\tUsing the fallback 'C' locale.");
}
gdk_parse_args (argc, argv);
gdk_pre_parse_libgtk_only ();
gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
#ifdef G_ENABLE_DEBUG
@ -408,109 +444,13 @@ gtk_parse_args (int *argc,
env_string = g_getenv ("GTK_MODULES");
if (env_string)
gtk_modules_string = g_string_new (env_string);
}
if (argc && argv)
{
gint i, j, k;
for (i = 1; i < *argc;)
{
if (strcmp ("--gtk-module", (*argv)[i]) == 0 ||
strncmp ("--gtk-module=", (*argv)[i], 13) == 0)
{
gchar *module_name = (*argv)[i] + 12;
if (*module_name == '=')
module_name++;
else if (i + 1 < *argc)
{
(*argv)[i] = NULL;
i += 1;
module_name = (*argv)[i];
}
(*argv)[i] = NULL;
if (module_name && *module_name)
{
if (gtk_modules_string)
g_string_append_c (gtk_modules_string, G_SEARCHPATH_SEPARATOR);
else
gtk_modules_string = g_string_new (NULL);
g_string_append (gtk_modules_string, module_name);
}
}
else if (strcmp ("--g-fatal-warnings", (*argv)[i]) == 0)
{
GLogLevelFlags fatal_mask;
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
g_log_set_always_fatal (fatal_mask);
(*argv)[i] = NULL;
}
#ifdef G_ENABLE_DEBUG
else if ((strcmp ("--gtk-debug", (*argv)[i]) == 0) ||
(strncmp ("--gtk-debug=", (*argv)[i], 12) == 0))
{
gchar *equal_pos = strchr ((*argv)[i], '=');
if (equal_pos != NULL)
{
gtk_debug_flags |= g_parse_debug_string (equal_pos+1,
gtk_debug_keys,
gtk_ndebug_keys);
}
else if ((i + 1) < *argc && (*argv)[i + 1])
{
gtk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
gtk_debug_keys,
gtk_ndebug_keys);
(*argv)[i] = NULL;
i += 1;
}
(*argv)[i] = NULL;
}
else if ((strcmp ("--gtk-no-debug", (*argv)[i]) == 0) ||
(strncmp ("--gtk-no-debug=", (*argv)[i], 15) == 0))
{
gchar *equal_pos = strchr ((*argv)[i], '=');
if (equal_pos != NULL)
{
gtk_debug_flags &= ~g_parse_debug_string (equal_pos+1,
gtk_debug_keys,
gtk_ndebug_keys);
}
else if ((i + 1) < *argc && (*argv)[i + 1])
{
gtk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
gtk_debug_keys,
gtk_ndebug_keys);
(*argv)[i] = NULL;
i += 1;
}
(*argv)[i] = NULL;
}
#endif /* G_ENABLE_DEBUG */
i += 1;
}
for (i = 1; i < *argc; i++)
{
for (k = i; k < *argc; k++)
if ((*argv)[k] != NULL)
break;
if (k > i)
{
k -= i;
for (j = i + k; j < *argc; j++)
(*argv)[j-k] = (*argv)[j];
*argc -= k;
}
}
}
static void
do_post_parse_initialization (int *argc,
char ***argv)
{
GSList *slist;
if (gtk_debug_flags & GTK_DEBUG_UPDATES)
gdk_window_set_debug_updates (TRUE);
@ -552,8 +492,133 @@ gtk_parse_args (int *argc,
_gtk_modules_init (argc, argv, gtk_modules_string->str);
g_string_free (gtk_modules_string, TRUE);
}
}
typedef struct
{
gboolean open_default_display;
} OptionGroupInfo;
static gboolean
pre_parse_hook (GOptionContext *context,
GOptionGroup *group,
gpointer data,
GError **error)
{
do_pre_parse_initialization (NULL, NULL);
return TRUE;
}
static gboolean
post_parse_hook (GOptionContext *context,
GOptionGroup *group,
gpointer data,
GError **error)
{
OptionGroupInfo *info = data;
do_post_parse_initialization (NULL, NULL);
if (info->open_default_display)
return gdk_display_open_default_libgtk_only () != NULL;
else
_gtk_modules_init (argc, argv, "");
return TRUE;
}
GOptionGroup *
gtk_get_option_group (gboolean open_default_display)
{
GOptionGroup *group;
OptionGroupInfo *info;
info = g_new0 (OptionGroupInfo, 1);
info->open_default_display = open_default_display;
group = g_option_group_new ("gtk", _("GTK+ Options"), _("Show GTK+ Options"), info, g_free);
g_option_group_set_parse_hooks (group, pre_parse_hook, post_parse_hook);
gdk_add_option_entries_libgtk_only (group);
g_option_group_add_entries (group, gtk_args);
return group;
}
gboolean
gtk_init_with_args (int *argc,
char ***argv,
char *parameter_string,
GOptionEntry *entries,
char *translation_domain,
GError **error)
{
GOptionContext *context;
GOptionGroup *gtk_group;
gboolean retval;
if (gtk_initialized)
return TRUE;
gtk_group = gtk_get_option_group (TRUE);
context = g_option_context_new (parameter_string);
g_option_context_add_group (context, gtk_group);
if (entries)
g_option_context_add_main_entries (context, entries, translation_domain);
retval = g_option_context_parse (context, argc, argv, error);
g_option_context_free (context);
return retval;
}
/**
* gtk_parse_args:
* @argc: a pointer to the number of command line arguments.
* @argv: a pointer to the array of command line arguments.
*
* Parses command line arguments, and initializes global
* attributes of GTK+, but does not actually open a connection
* to a display. (See gdk_display_open(), gdk_get_display_arg_name())
*
* Any arguments used by GTK+ or GDK are removed from the array and
* @argc and @argv are updated accordingly.
*
* You shouldn't call this function explicitely if you are using
* gtk_init(), or gtk_init_check().
*
* Return value: %TRUE if initialization succeeded, otherwise %FALSE.
**/
gboolean
gtk_parse_args (int *argc,
char ***argv)
{
GOptionContext *option_context;
if (gtk_initialized)
return TRUE;
if (!check_setugid ())
return FALSE;
do_pre_parse_initialization (argc, argv);
option_context = g_option_context_new (NULL);
g_option_context_set_ignore_unknown_options (option_context, TRUE);
g_option_context_set_help_enabled (option_context, FALSE);
g_option_context_add_main_entries (option_context, gtk_args, NULL);
g_option_context_parse (option_context, argc, argv, NULL);
g_option_context_free (option_context);
do_post_parse_initialization (argc, argv);
return TRUE;
}

View File

@ -94,6 +94,16 @@ void gtk_init (int *argc,
gboolean gtk_init_check (int *argc,
char ***argv);
gboolean gtk_init_with_args (int *argc,
char ***argv,
char *parameter_string,
GOptionEntry *entries,
char *translation_domain,
GError **error);
GOptionGroup *gtk_get_option_group (gboolean open_default_display);
#ifdef G_PLATFORM_WIN32
/* Variants that are used to check for correct struct packing

View File

@ -234,12 +234,7 @@ main (int argc, char *argv[])
GtkTreeModel *model;
GOptionContext *context;
gtk_init (&argc, &argv);
context = g_option_context_new ("");
g_option_context_add_main_entries (context, entries, "");
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
gtk_init_with_args (&argc, &argv, NULL, entries, NULL, NULL);
model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING));