static void menus_init(void) { GError *error = NULL; gchar *uifile; if (!initialise) return; initialise = FALSE; _setup_global_actions (); uifile = build_ui_filename ("ui/toolbox-ui.xml"); if (!gtk_ui_manager_add_ui_from_file (_ui_manager, uifile, &error)) { g_warning ("building menus failed: %s", error->message); g_error_free (error); error = NULL; } g_free (uifile); /* the display menu */ display_actions = create_or_ref_display_actions (TRUE); display_ui_manager = gtk_ui_manager_new (); g_signal_connect (G_OBJECT (display_ui_manager), "connect_proxy", G_CALLBACK (_ui_manager_connect_proxy), NULL); gtk_ui_manager_set_add_tearoffs (display_ui_manager, DIA_SHOW_TEAROFFS); gtk_ui_manager_insert_action_group (display_ui_manager, display_actions, 0); gtk_ui_manager_insert_action_group (display_ui_manager, tool_actions, 0); if (!gtk_ui_manager_add_ui_from_string (display_ui_manager, ui_info, -1, &error)) { g_warning ("built-in menus failed: %s", error->message); g_error_free (error); error = NULL; } uifile = build_ui_filename ("ui/popup-ui.xml"); /* TODO it would be more elegant if we had only one definition of the * menu hierarchy and merge it into a popup somehow. */ if (!gtk_ui_manager_add_ui_from_file (display_ui_manager, uifile, &error)) { g_warning ("building menus failed: %s", error->message); g_error_free (error); error = NULL; } g_free (uifile); display_accels = gtk_ui_manager_get_accel_group (display_ui_manager); display_menubar = gtk_ui_manager_get_widget (display_ui_manager, DISPLAY_MENU); g_assert (display_menubar); add_plugin_actions (_ui_manager, TOOLBOX_MENU); add_plugin_actions (display_ui_manager, DISPLAY_MENU); add_plugin_actions (display_ui_manager, INVISIBLE_MENU); /* after creating all menu items */ load_accels (); }
GtkWidget * menus_create_display_menubar (GtkUIManager **ui_manager, GtkActionGroup **actions) { GtkWidget *menu_bar; GError *error = NULL; gchar *uifile; *actions = create_or_ref_display_actions (TRUE); tool_actions = create_or_ref_tool_actions (); *ui_manager = gtk_ui_manager_new (); gtk_ui_manager_set_add_tearoffs (*ui_manager, DIA_SHOW_TEAROFFS); gtk_ui_manager_insert_action_group (*ui_manager, *actions, 0); gtk_ui_manager_insert_action_group (*ui_manager, tool_actions, 0); g_object_unref (G_OBJECT (tool_actions)); uifile = build_ui_filename ("ui/display-ui.xml"); if (!gtk_ui_manager_add_ui_from_file (*ui_manager, uifile, &error)) { g_warning ("building menus failed: %s", error->message); g_error_free (error); g_free (uifile); return NULL; } g_free (uifile); add_plugin_actions (*ui_manager, DISPLAY_MENU); menu_bar = gtk_ui_manager_get_widget (*ui_manager, DISPLAY_MENU); return menu_bar; }
G_MODULE_EXPORT void plugin_init (PlannerPlugin *plugin) { PlannerPluginPriv *priv; GtkUIManager *ui; gchar *filename; priv = g_new0 (PlannerPluginPriv, 1); plugin->priv = priv; priv->actions = gtk_action_group_new ("HTML plugin actions"); gtk_action_group_set_translation_domain (priv->actions, GETTEXT_PACKAGE); gtk_action_group_add_actions (priv->actions, action_entries, G_N_ELEMENTS (action_entries), plugin); ui = planner_window_get_ui_manager (plugin->main_window); gtk_ui_manager_insert_action_group (ui, priv->actions, 0); filename = mrp_paths_get_ui_dir ("html-plugin.ui"); gtk_ui_manager_add_ui_from_file (ui, filename, NULL); g_free (filename); gtk_ui_manager_ensure_update (ui); }
static gboolean gimp_ui_manager_entry_load (GimpUIManager *manager, GimpUIManagerUIEntry *entry, GError **error) { gchar *filename = NULL; const gchar *menus_dir_override = g_getenv ("GIMP_TESTING_MENUS_DIR"); /* In order for test cases to be able to run without GIMP being * installed yet, allow them to override the menus directory to the * menus dir in the source root */ if (menus_dir_override) filename = g_build_filename (menus_dir_override, entry->basename, NULL); else filename = g_build_filename (gimp_data_directory (), "menus", entry->basename, NULL); if (manager->gimp->be_verbose) g_print ("loading menu '%s' for %s\n", gimp_filename_to_utf8 (filename), entry->ui_path); entry->merge_id = gtk_ui_manager_add_ui_from_file (GTK_UI_MANAGER (manager), filename, error); g_free (filename); if (! entry->merge_id) return FALSE; return TRUE; }
static void usage_view_activate (PlannerView *view) { PlannerUsageViewPriv *priv; gchar *filename; priv = PLANNER_USAGE_VIEW (view)->priv; priv->actions = gtk_action_group_new ("TimeTableView"); gtk_action_group_set_translation_domain (priv->actions, GETTEXT_PACKAGE); gtk_action_group_add_actions (priv->actions, entries, G_N_ELEMENTS (entries), view); gtk_ui_manager_insert_action_group (priv->ui_manager, priv->actions, 0); filename = mrp_paths_get_ui_dir ("time-table-view.ui"); priv->merged_id = gtk_ui_manager_add_ui_from_file (priv->ui_manager, filename, NULL); g_free (filename); gtk_ui_manager_ensure_update (priv->ui_manager); usage_view_update_zoom_sensitivity (view); gtk_widget_grab_focus (priv->tree); }
void gtkhtml_editor_private_init (GtkhtmlEditor *editor) { GtkhtmlEditorPrivate *priv = editor->priv; gchar *filename; GError *error = NULL; priv->manager = gtk_ui_manager_new (); priv->core_actions = gtk_action_group_new ("core"); priv->html_actions = gtk_action_group_new ("html"); priv->context_actions = gtk_action_group_new ("core-context"); priv->html_context_actions = gtk_action_group_new ("html-context"); priv->language_actions = gtk_action_group_new ("language"); priv->spell_check_actions = gtk_action_group_new ("spell-check"); priv->suggestion_actions = gtk_action_group_new ("suggestion"); /* GtkhtmlSpellLanguage -> GtkhtmlSpellChecker */ priv->available_spell_checkers = g_hash_table_new_full ( g_direct_hash, g_direct_equal, (GDestroyNotify) NULL, (GDestroyNotify) g_object_unref); /* GtkhtmlSpellLanguage -> UI Merge ID */ priv->spell_suggestion_menus = g_hash_table_new (g_direct_hash, g_direct_equal); filename = gtkhtml_editor_find_data_file ("gtkhtml-editor-manager.ui"); if (!gtk_ui_manager_add_ui_from_file (priv->manager, filename, &error)) { g_critical ("Couldn't load builder file: %s\n", error->message); g_clear_error (&error); } g_free (filename); filename = gtkhtml_editor_find_data_file ("gtkhtml-editor-builder.ui"); priv->builder = gtk_builder_new (); /* To keep translated strings in subclasses */ gtk_builder_set_translation_domain (priv->builder, GETTEXT_PACKAGE); if (!gtk_builder_add_from_file (priv->builder, filename, &error)) { g_critical ("Couldn't load builder file: %s\n", error->message); g_clear_error (&error); } g_free (filename); gtkhtml_editor_actions_init (editor); gtk_window_add_accel_group ( GTK_WINDOW (editor), gtk_ui_manager_get_accel_group (priv->manager)); gtk_builder_connect_signals (priv->builder, NULL); /* Wait to construct the main window widgets * until the 'html' property is initialized. */ }
/** Create a new gnc embedded window plugin. */ GncEmbeddedWindow * gnc_embedded_window_new (const gchar *action_group_name, GtkActionEntry *action_entries, gint n_action_entries, const gchar *ui_filename, GtkWidget *enclosing_win, gboolean add_accelerators, gpointer user_data) { GncEmbeddedWindowPrivate *priv; GncEmbeddedWindow *window; gchar *ui_fullname; GError *error = NULL; guint merge_id; ENTER("group %s, first %p, num %d, ui file %s, parent %p, add accelerators %d, user data %p", action_group_name, action_entries, n_action_entries, ui_filename, enclosing_win, add_accelerators, user_data); window = g_object_new (GNC_TYPE_EMBEDDED_WINDOW, NULL); priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window); /* Determine the full pathname of the ui file */ ui_fullname = gnc_filepath_locate_ui_file (ui_filename); g_return_val_if_fail (ui_fullname != NULL, NULL); priv->parent_window = enclosing_win; /* Create menu and toolbar information */ priv->action_group = gtk_action_group_new (action_group_name); gnc_gtk_action_group_set_translation_domain(priv->action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions (priv->action_group, action_entries, n_action_entries, user_data); gtk_ui_manager_insert_action_group (window->ui_merge, priv->action_group, 0); merge_id = gtk_ui_manager_add_ui_from_file (window->ui_merge, ui_fullname, &error); /* Error checking */ g_assert(merge_id || error); if (error) { g_critical("Failed to load ui file.\n Filename %s\n Error %s", ui_fullname, error->message); g_error_free(error); g_free(ui_fullname); LEAVE("window %p", window); return window; } /* Add accelerators (if wanted) */ if (add_accelerators) gtk_window_add_accel_group (GTK_WINDOW(enclosing_win), gtk_ui_manager_get_accel_group(window->ui_merge)); gtk_ui_manager_ensure_update (window->ui_merge); g_free(ui_fullname); LEAVE("window %p", window); return window; }
void libre_impuesto_window_actions_init (LibreImpuestoWindow *impuesto_window) { GtkActionGroup *action_group; GtkUIManager *ui_manager; gchar *filename; GError *error; gboolean ret_val; g_return_if_fail (IS_LIBRE_IMPUESTO_WINDOW (impuesto_window)); ui_manager = libre_impuesto_window_get_ui_manager (impuesto_window); action_group = libre_impuesto_add_action_group(ui_manager, "impuesto"); gtk_action_group_add_actions ( action_group, impuesto_entries, G_N_ELEMENTS (impuesto_entries), impuesto_window); gtk_action_group_add_toggle_actions ( action_group, impuesto_toggle_entries, G_N_ELEMENTS (impuesto_toggle_entries), impuesto_window); error = NULL; filename = g_build_filename (LIBRE_IMPUESTO_UIDIR, "libre-impuestos-menu.ui", NULL); ret_val = gtk_ui_manager_add_ui_from_file (ui_manager, filename, &error); g_free (filename); if (!ret_val) { g_critical("%s", error->message); } g_object_bind_property (impuesto_window, "headerbar-visible", libre_impuesto_window_get_action (impuesto_window, "show-headerbar"), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); g_object_bind_property (impuesto_window, "sidebar-visible", libre_impuesto_window_get_action( impuesto_window, "show-sidebar"), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); g_object_bind_property (impuesto_window, "statusbar-visible", libre_impuesto_window_get_action (impuesto_window, "show-statusbar"), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); }
static void task_view_activate (PlannerView *view) { PlannerTaskViewPriv *priv; gboolean show_critical; gboolean show_nostd_days; gchar *filename; priv = PLANNER_TASK_VIEW (view)->priv; priv->actions = gtk_action_group_new ("TaskView"); gtk_action_group_set_translation_domain (priv->actions, GETTEXT_PACKAGE); gtk_action_group_add_actions (priv->actions, entries, G_N_ELEMENTS (entries), view); gtk_action_group_add_toggle_actions (priv->actions, toggle_entries, G_N_ELEMENTS (toggle_entries), view); gtk_ui_manager_insert_action_group (priv->ui_manager, priv->actions, 0); filename = mrp_paths_get_ui_dir ("task-view.ui"); priv->merged_id = gtk_ui_manager_add_ui_from_file (priv->ui_manager, filename, NULL); g_free (filename); gtk_ui_manager_ensure_update (priv->ui_manager); /* Set the initial UI state. */ show_critical = planner_conf_get_bool (CRITICAL_PATH_KEY, NULL); show_nostd_days = planner_conf_get_bool (NOSTDDAYS_PATH_KEY, NULL); planner_task_tree_set_highlight_critical (PLANNER_TASK_TREE (priv->tree), show_critical); planner_task_tree_set_nonstandard_days (PLANNER_TASK_TREE (priv->tree), show_nostd_days); gtk_toggle_action_set_active ( GTK_TOGGLE_ACTION (gtk_action_group_get_action (priv->actions, "HighlightCriticalTasks")), show_critical); gtk_toggle_action_set_active ( GTK_TOGGLE_ACTION (gtk_action_group_get_action (priv->actions, "NonstandardDays")), show_nostd_days); task_view_selection_changed_cb (PLANNER_TASK_TREE (priv->tree), view); gtk_widget_grab_focus (priv->tree); }
void menus_get_integrated_ui_menubar (GtkWidget **menubar, GtkWidget **toolbar, GtkAccelGroup **accel_group) { GError *error = NULL; gchar *uifile; _setup_global_actions (); g_return_if_fail (_ui_manager != NULL); /* the integrated ui menu */ display_actions = create_or_ref_display_actions (FALSE); g_return_if_fail (tool_actions != NULL); /* maybe better to put this into toolbox_actions? */ gtk_action_group_add_toggle_actions (display_actions, integrated_ui_view_toggle_entries, G_N_ELEMENTS (integrated_ui_view_toggle_entries), NULL); /* for stand-alone they are per display */ gtk_ui_manager_insert_action_group (_ui_manager, display_actions, 0); tool_actions = create_or_ref_tool_actions (); gtk_ui_manager_insert_action_group (_ui_manager, tool_actions, 0); uifile = build_ui_filename ("ui/integrated-ui.xml"); if (!gtk_ui_manager_add_ui_from_file (_ui_manager, uifile, &error)) { g_warning ("building integrated ui menus failed: %s", error->message); g_error_free (error); error = NULL; } g_free (uifile); if (!gtk_ui_manager_add_ui_from_string (_ui_manager, ui_info, -1, &error)) { g_warning ("built-in menus failed: %s", error->message); g_error_free (error); error = NULL; } add_plugin_actions (_ui_manager, NULL); /* after creating all menu items */ load_accels (); if (menubar) *menubar = gtk_ui_manager_get_widget (_ui_manager, INTEGRATED_MENU); if (toolbar) *toolbar = create_integrated_ui_toolbar (); if (accel_group) *accel_group = gtk_ui_manager_get_accel_group (_ui_manager); }
static void impl_activate (PeasActivatable *bplugin) { RBIpodPlugin *plugin = RB_IPOD_PLUGIN (bplugin); RBRemovableMediaManager *rmm = NULL; GtkUIManager *uimanager = NULL; RBShell *shell; gboolean scanned; char *file; g_object_get (plugin, "object", &shell, NULL); g_object_get (G_OBJECT (shell), "removable-media-manager", &rmm, "ui-manager", &uimanager, NULL); rb_media_player_source_init_actions (shell); /* add ipod UI */ plugin->action_group = gtk_action_group_new ("iPodActions"); gtk_action_group_set_translation_domain (plugin->action_group, GETTEXT_PACKAGE); _rb_action_group_add_display_page_actions (plugin->action_group, G_OBJECT (shell), rb_ipod_plugin_actions, G_N_ELEMENTS (rb_ipod_plugin_actions)); gtk_ui_manager_insert_action_group (uimanager, plugin->action_group, 0); file = rb_find_plugin_data_file (G_OBJECT (bplugin), "ipod-ui.xml"); plugin->ui_merge_id = gtk_ui_manager_add_ui_from_file (uimanager, file, NULL); g_free (file); /* watch for new removable media, and cause a rescan */ g_signal_connect (G_OBJECT (rmm), "create-source-mount", G_CALLBACK (create_source_cb), plugin); /* only scan if we're being loaded after the initial scan has been done */ g_object_get (G_OBJECT (rmm), "scanned", &scanned, NULL); if (scanned) rb_removable_media_manager_scan (rmm); g_object_unref (rmm); g_object_unref (uimanager); g_object_unref (shell); }
static RBSource * create_source_cb (RBRemovableMediaManager *rmm, GMount *mount, MPIDDevice *device_info, RBGenericPlayerPlugin *plugin) { RBSource *source = NULL; if (rb_psp_is_mount_player (mount, device_info)) source = RB_SOURCE (rb_psp_source_new (RB_PLUGIN (plugin), plugin->shell, mount, device_info)); if (source == NULL && rb_nokia770_is_mount_player (mount, device_info)) source = RB_SOURCE (rb_nokia770_source_new (RB_PLUGIN (plugin), plugin->shell, mount, device_info)); if (source == NULL && rb_generic_player_is_mount_player (mount, device_info)) source = RB_SOURCE (rb_generic_player_source_new (RB_PLUGIN (plugin), plugin->shell, mount, device_info)); if (plugin->actions == NULL) { plugin->actions = gtk_action_group_new ("GenericPlayerActions"); gtk_action_group_set_translation_domain (plugin->actions, GETTEXT_PACKAGE); _rb_action_group_add_source_actions (plugin->actions, G_OBJECT (plugin->shell), rb_generic_player_plugin_actions, G_N_ELEMENTS (rb_generic_player_plugin_actions)); } if (source) { if (plugin->ui_merge_id == 0) { GtkUIManager *uimanager = NULL; char *file = NULL; g_object_get (G_OBJECT (plugin->shell), "ui-manager", &uimanager, NULL); gtk_ui_manager_insert_action_group (uimanager, plugin->actions, 0); file = rb_plugin_find_file (RB_PLUGIN (plugin), "generic-player-ui.xml"); plugin->ui_merge_id = gtk_ui_manager_add_ui_from_file (uimanager, file, NULL); g_free (file); g_object_unref (G_OBJECT (uimanager)); } plugin->player_sources = g_list_prepend (plugin->player_sources, source); g_signal_connect_object (G_OBJECT (source), "deleted", G_CALLBACK (rb_generic_player_plugin_source_deleted), plugin, 0); } return source; }
/*! \brief Create and attach the menu bar * * Create the menu bar and attach it to the main window. * * First, the GtkActionGroup object is created and filled with * entries of type GtkActionEntry (each entry specifies a single * action, such as opening a file). Then the GtkUIManager object * is created and used to load menus.xml file with the menu * description. Finally, the GtkAccelGroup is added to the * main window to enable keyboard accelerators and a pointer * to the menu bar is retrieved from the GtkUIManager object. * \param window Window to add the menubar to * \param [out] menubar Created menubar */ static void x_window_create_menu(GtkWindow *window, GtkWidget **menubar) { GtkUIManager *ui; GtkActionGroup *action_group; GError *error = NULL; /* Create and fill the action group object */ action_group = gtk_action_group_new(""); gtk_action_group_add_actions(action_group, actions, G_N_ELEMENTS(actions), NULL); /* Create the UI manager object */ ui = gtk_ui_manager_new(); gtk_ui_manager_insert_action_group(ui, action_group, 0); /* Load the menu path from the system data path */ gchar *menu_file = NULL; const gchar * const *sys_dirs = eda_get_system_data_dirs(); for (gint i = 0; sys_dirs[i]; ++i) { if (menu_file) { g_free(menu_file); menu_file = NULL; } menu_file = g_build_filename(sys_dirs[i], "gattrib-menus.xml", NULL); if (g_file_test(menu_file, G_FILE_TEST_IS_REGULAR)) { break; } } gtk_ui_manager_add_ui_from_file(ui, menu_file, &error); if(error != NULL) { /* An error occured, terminate */ fprintf(stderr, _("Error loading %1$s:\n%2$s\n"), menu_file, error->message); exit(1); } g_free(menu_file); gtk_window_add_accel_group (window, gtk_ui_manager_get_accel_group(ui)); *menubar = gtk_ui_manager_get_widget(ui, "/ui/menubar/"); }
GtkWidget* create_menu (GtkAccelGroup *accel) { // UI Manager creates a menu from XML description GtkActionGroup *group = gtk_action_group_new("MainActionGroup"); GtkWidget *menubar; uimanager = gtk_ui_manager_new(); gtk_action_group_add_actions(group, entries, NUM_ENTRIES, NULL); gtk_ui_manager_insert_action_group(uimanager, group, 0); gtk_ui_manager_add_ui_from_file(uimanager, UI_DIR "/menu.ui", NULL); menubar = gtk_ui_manager_get_widget(uimanager, "/MenuBar"); gtk_window_add_accel_group(GTK_WINDOW(editor_window), gtk_ui_manager_get_accel_group(uimanager)); return menubar; }
G_MODULE_EXPORT void plugin_init (PlannerPlugin *plugin) { PlannerPluginPriv *priv; GtkUIManager *ui; gint i = -1; gchar *filename; priv = g_new0 (PlannerPluginPriv, 1); plugin->priv = priv; gda_init (PACKAGE, VERSION, 0, NULL); g_object_set_data (G_OBJECT (plugin->main_window), PROJECT_ID, GINT_TO_POINTER (i)); g_object_set_data (G_OBJECT (plugin->main_window), "sql-plugin-revision", GINT_TO_POINTER (i)); g_object_set_data (G_OBJECT (plugin->main_window), "sql-plugin", plugin); /* Create the actions, get the ui manager and merge the whole */ priv->actions = gtk_action_group_new ("SQL plugin actions"); gtk_action_group_set_translation_domain (priv->actions, GETTEXT_PACKAGE); gtk_action_group_add_actions (priv->actions, entries, G_N_ELEMENTS (entries), plugin); ui = planner_window_get_ui_manager (plugin->main_window); gtk_ui_manager_insert_action_group (ui, priv->actions, 0); filename = mrp_paths_get_ui_dir ("sql-plugin.ui"); gtk_ui_manager_add_ui_from_file (ui, filename, NULL); g_free (filename); gtk_ui_manager_ensure_update (ui); }
int clip_GTK_UIMANAGERADDUIFROMFILE(ClipMachine * ClipMachineMemory) { C_object *cmanager = _fetch_co_arg(ClipMachineMemory); gchar *filename = _clip_parc(ClipMachineMemory, 2); GError *error; guint ret; CHECKARG2(1, MAP_type_of_ClipVarType, NUMERIC_type_of_ClipVarType); CHECKCOBJ(cmanager, GTK_IS_UI_MANAGER(cmanager->object)); CHECKARG(2, CHARACTER_type_of_ClipVarType); ret = gtk_ui_manager_add_ui_from_file(GTK_UI_MANAGER(cmanager->object), filename, &error); _clip_retni(ClipMachineMemory, ret); return 0; err: return 1; }
static VALUE rg_add_ui(int argc, VALUE *argv, VALUE self) { GError* error = NULL; guint ret; VALUE buffer; if (argc == 1) { VALUE buffer_or_filename; rb_scan_args(argc, argv, "10", &buffer_or_filename); StringValue(buffer_or_filename); buffer = rb_funcall(buffer_or_filename, rb_intern("include?"), 1, CSTR2RVAL("<ui>")); if (RVAL2CBOOL(buffer)){ StringValue(buffer_or_filename); ret = gtk_ui_manager_add_ui_from_string(_SELF(self), RSTRING_PTR(buffer_or_filename), RSTRING_LEN(buffer_or_filename), &error); } else { ret = gtk_ui_manager_add_ui_from_file(_SELF(self), RVAL2CSTR(buffer_or_filename), &error); } } else { VALUE merge_id, path, name, action, type, top; rb_scan_args(argc, argv, "60", &merge_id, &path, &name, &action, &type, &top); ret = NUM2UINT(merge_id); gtk_ui_manager_add_ui(_SELF(self), ret, RVAL2CSTR(path), RVAL2CSTR(name), RVAL2CSTR(action), RVAL2GFLAGS(type, GTK_TYPE_UI_MANAGER_ITEM_TYPE), RVAL2CBOOL(top)); } if (ret == 0) RAISE_GERROR(error); return UINT2NUM(ret); }
int main(int argc, char *argv[]) { GtkWidget *window; GtkActionGroup *actionGroup; GtkUIManager *ui; GtkWidget *vbox; guint ret; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "GtkUIManager"); gtk_window_set_default_size(GTK_WINDOW(window), 300, 200); actionGroup = gtk_action_group_new("Actions"); gtk_action_group_add_actions(actionGroup, entries, 10, NULL); ui = gtk_ui_manager_new(); gtk_ui_manager_insert_action_group(ui, actionGroup, 0); ret = gtk_ui_manager_add_ui_from_file(ui, "./gtk-test/gtk_ui_manager.xml", NULL); if (ret == 0) { g_print("gtk_ui_manager_add_ui_from_file error!\n"); return -1; } vbox = gtk_vbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(vbox), gtk_ui_manager_get_widget(ui, "/MenuBar"), FALSE, FALSE, 2); gtk_container_add(GTK_CONTAINER(window), vbox); g_signal_connect(GTK_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_widget_show_all(window); gtk_main(); return 0; }
GtkWidget *generate_menu (TboWindow *window){ GtkWidget *menu; GtkUIManager *manager; GError *error = NULL; manager = gtk_ui_manager_new (); gtk_ui_manager_add_ui_from_file (manager, DATA_DIR "/ui/tbo-menu-ui.xml", &error); if (error != NULL) { g_warning (_("Could not merge tbo-menu-ui.xml: %s"), error->message); g_error_free (error); } MENU_ACTION_GROUP = gtk_action_group_new ("MenuActions"); gtk_action_group_set_translation_domain (MENU_ACTION_GROUP, NULL); gtk_action_group_add_actions (MENU_ACTION_GROUP, tbo_menu_entries, G_N_ELEMENTS (tbo_menu_entries), window); gtk_ui_manager_insert_action_group (manager, MENU_ACTION_GROUP, 0); menu = gtk_ui_manager_get_widget (manager, "/menubar"); return menu; }
static gboolean create_window(void) { GError *error = NULL; builder = gtk_builder_new(); if( !gtk_builder_add_from_file(builder, PACKAGE_DATA_DIR "/chimara.ui", &error) ) { #ifdef DEBUG g_error_free(error); error = NULL; if( !gtk_builder_add_from_file(builder, PACKAGE_SRC_DIR "/chimara.ui", &error) ) { #endif /* DEBUG */ return FALSE; #ifdef DEBUG } #endif /* DEBUG */ } window = GTK_WIDGET(load_object("chimara")); aboutwindow = GTK_WIDGET(load_object("aboutwindow")); prefswindow = GTK_WIDGET(load_object("prefswindow")); GtkActionGroup *actiongroup = GTK_ACTION_GROUP(load_object("actiongroup")); /* Set the default value of the "View/Toolbar" menu item upon creation of a new window to the "show-toolbar-default" setting, but bind the setting one-way only - we don't want toolbars to disappear suddenly */ GtkToggleAction *toolbar_action = GTK_TOGGLE_ACTION(load_object("toolbar")); gtk_toggle_action_set_active(toolbar_action, g_settings_get_boolean(state_settings, "show-toolbar-default")); g_settings_bind(state_settings, "show-toolbar-default", toolbar_action, "active", G_SETTINGS_BIND_SET); const gchar **ptr; GtkRecentFilter *filter = gtk_recent_filter_new(); /* TODO: Use mimetypes and construct the filter dynamically depending on what plugins are installed */ const gchar *patterns[] = { "*.z[1-8]", "*.[zg]lb", "*.[zg]blorb", "*.ulx", "*.blb", "*.blorb", NULL }; for(ptr = patterns; *ptr; ptr++) gtk_recent_filter_add_pattern(filter, *ptr); GtkRecentChooser *recent = GTK_RECENT_CHOOSER(load_object("recent")); gtk_recent_chooser_add_filter(recent, filter); uimanager = gtk_ui_manager_new(); if( !gtk_ui_manager_add_ui_from_file(uimanager, PACKAGE_DATA_DIR "/chimara.menus", &error) ) { #ifdef DEBUG g_error_free(error); error = NULL; if( !gtk_ui_manager_add_ui_from_file(uimanager, PACKAGE_SRC_DIR "/chimara.menus", &error) ) #endif /* DEBUG */ return FALSE; } glk = chimara_if_new(); g_object_set(glk, "ignore-errors", TRUE, /*"interpreter-number", CHIMARA_IF_ZMACHINE_TANDY_COLOR,*/ NULL); if( !chimara_glk_set_css_from_file(CHIMARA_GLK(glk), PACKAGE_DATA_DIR "/style.css", &error) ) { #ifdef DEBUG g_error_free(error); error = NULL; if( !chimara_glk_set_css_from_file(CHIMARA_GLK(glk), PACKAGE_SRC_DIR "/style.css", &error) ) #endif /* DEBUG */ return FALSE; } /* DON'T UNCOMMENT THIS your eyes will burn but it is a good test of programmatically altering just one style chimara_glk_set_css_from_string(CHIMARA_GLK(glk), "buffer { font-family: 'Comic Sans MS'; }");*/ GtkBox *vbox = GTK_BOX( gtk_builder_get_object(builder, "vbox") ); if(vbox == NULL) return FALSE; gtk_ui_manager_insert_action_group(uimanager, actiongroup, 0); GtkWidget *menubar = gtk_ui_manager_get_widget(uimanager, "/menubar"); toolbar = gtk_ui_manager_get_widget(uimanager, "/toolbar"); gtk_widget_set_no_show_all(toolbar, TRUE); if(gtk_toggle_action_get_active(toolbar_action)) gtk_widget_show(toolbar); else gtk_widget_hide(toolbar); /* Connect the accelerators */ GtkAccelGroup *accels = gtk_ui_manager_get_accel_group(uimanager); gtk_window_add_accel_group(GTK_WINDOW(window), accels); gtk_box_pack_end(vbox, glk, TRUE, TRUE, 0); gtk_box_pack_start(vbox, menubar, FALSE, FALSE, 0); gtk_box_pack_start(vbox, toolbar, FALSE, FALSE, 0); gtk_builder_connect_signals(builder, glk); g_signal_connect(glk, "notify::program-name", G_CALLBACK(change_window_title), window); g_signal_connect(glk, "notify::story-name", G_CALLBACK(change_window_title), window); /* Create preferences window */ preferences_create(CHIMARA_GLK(glk)); return TRUE; }
static void show_view_activate (PlannerView *view) { PlannerShowViewPriv *priv; gboolean show_critical, show_nostd_days, show_guidelines; gchar *filename; priv = PLANNER_SHOW_VIEW (view)->priv; priv->actions = gtk_action_group_new ("ShowView"); gtk_action_group_set_translation_domain (priv->actions, GETTEXT_PACKAGE); gtk_action_group_add_actions (priv->actions, entries, G_N_ELEMENTS (entries), view); gtk_action_group_add_toggle_actions (priv->actions, toggle_entries, G_N_ELEMENTS (toggle_entries), view); gtk_ui_manager_insert_action_group (priv->ui_manager, priv->actions, 0); filename = mrp_paths_get_ui_dir ("show-view.ui"); priv->merged_id = gtk_ui_manager_add_ui_from_file (priv->ui_manager, filename, NULL); g_free (filename); gtk_ui_manager_ensure_update (priv->ui_manager); /* Set the initial UI state. */ show_critical = planner_gantt_chart_get_highlight_critical_tasks ( PLANNER_GANTT_CHART (priv->gantt)); show_nostd_days = planner_gantt_chart_get_nonstandard_days ( PLANNER_GANTT_CHART (priv->gantt)); show_guidelines = planner_gantt_chart_get_show_guidelines ( PLANNER_GANTT_CHART (priv->gantt)); planner_task_tree_set_highlight_critical (PLANNER_TASK_TREE (priv->tree), show_critical); planner_task_tree_set_nonstandard_days (PLANNER_TASK_TREE (priv->tree), show_nostd_days); gtk_toggle_action_set_active ( GTK_TOGGLE_ACTION (gtk_action_group_get_action (priv->actions, "HighlightCriticalTasks")), show_critical); gtk_toggle_action_set_active ( GTK_TOGGLE_ACTION (gtk_action_group_get_action (priv->actions, "NonstandardDays")), show_nostd_days); gtk_toggle_action_set_active ( GTK_TOGGLE_ACTION (gtk_action_group_get_action (priv->actions, "ShowGuideLines")), show_guidelines); show_view_selection_changed_cb (PLANNER_TASK_TREE (priv->tree), PLANNER_SHOW_VIEW (view)); show_view_update_zoom_sensitivity (PLANNER_SHOW_VIEW (view)); gtk_widget_grab_focus (priv->gantt); }
static void impl_activate (PeasActivatable *bplugin) { RBMtpPlugin *plugin = RB_MTP_PLUGIN (bplugin); GtkUIManager *uimanager = NULL; RBRemovableMediaManager *rmm; char *file = NULL; RBShell *shell; #if defined(HAVE_GUDEV) gboolean rmm_scanned = FALSE; #else int num_mtp_devices; LIBMTP_raw_device_t *mtp_devices; #endif g_object_get (plugin, "object", &shell, NULL); g_object_get (shell, "ui-manager", &uimanager, "removable-media-manager", &rmm, NULL); /* ui */ rb_media_player_source_init_actions (shell); plugin->action_group = gtk_action_group_new ("MTPActions"); gtk_action_group_set_translation_domain (plugin->action_group, GETTEXT_PACKAGE); _rb_action_group_add_display_page_actions (plugin->action_group, G_OBJECT (shell), rb_mtp_plugin_actions, G_N_ELEMENTS (rb_mtp_plugin_actions)); gtk_ui_manager_insert_action_group (uimanager, plugin->action_group, 0); file = rb_find_plugin_data_file (G_OBJECT (bplugin), "mtp-ui.xml"); plugin->ui_merge_id = gtk_ui_manager_add_ui_from_file (uimanager, file, NULL); g_object_unref (uimanager); g_object_unref (shell); /* device detection */ #if defined(HAVE_GUDEV) plugin->create_device_source_id = g_signal_connect_object (rmm, "create-source-device", G_CALLBACK (create_source_device_cb), plugin, 0); /* only scan if we're being loaded after the initial scan has been done */ g_object_get (rmm, "scanned", &rmm_scanned, NULL); if (rmm_scanned) rb_removable_media_manager_scan (rmm); #else if (rb_mtp_plugin_setup_dbus_hal_connection (plugin) == FALSE) { rb_debug ("not scanning for MTP devices because we couldn't get a HAL context"); g_object_unref (rmm); return; } rb_profile_start ("scanning for MTP devices"); LIBMTP_Detect_Raw_Devices (&mtp_devices, &num_mtp_devices); if (num_mtp_devices > 0) { int num_hal_devices; char **hal_devices; int i; rb_debug ("%d MTP devices found", num_mtp_devices); hal_devices = libhal_get_all_devices (plugin->hal_context, &num_hal_devices, NULL); for (i = 0; i < num_hal_devices; i++) { /* should narrow this down a bit - usb only, for a start */ rb_mtp_plugin_maybe_add_source (plugin, hal_devices[i], mtp_devices, num_mtp_devices); } libhal_free_string_array (hal_devices); } if (mtp_devices != NULL) { free (mtp_devices); } rb_profile_end ("scanning for MTP devices"); #endif g_object_unref (rmm); }
/** * Create the toolbar for the integrated UI * @return Main toolbar (GtkToolbar*) for the integrated UI main window */ static GtkWidget * create_integrated_ui_toolbar (void) { GtkToolbar *toolbar; GtkToolItem *sep; GtkWidget *w; GError *error = NULL; gchar *uifile; uifile = build_ui_filename ("ui/toolbar-ui.xml"); if (!gtk_ui_manager_add_ui_from_file (_ui_manager, uifile, &error)) { g_warning ("building menus failed: %s", error->message); g_error_free (error); error = NULL; toolbar = GTK_TOOLBAR (gtk_toolbar_new ()); } else { toolbar = GTK_TOOLBAR(gtk_ui_manager_get_widget (_ui_manager, "/Toolbar")); } g_free (uifile); /* Zoom Combo Box Entry */ w = gtk_combo_box_text_new_with_entry (); g_object_set_data (G_OBJECT (toolbar), DIA_INTEGRATED_TOOLBAR_ZOOM_COMBO, w); integrated_ui_toolbar_add_custom_item (toolbar, w); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), ZOOM_FIT); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), _("800%")); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), _("400%")); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), _("300%")); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), _("200%")); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), _("150%")); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), _("100%")); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), _("75%")); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), _("50%")); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), _("25%")); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), _("10%")); g_signal_connect (G_OBJECT (w), "changed", G_CALLBACK (integrated_ui_toolbar_zoom_combo_selection_changed), NULL); /* Get the combo's GtkEntry child to set the width for the widget */ w = gtk_bin_get_child (GTK_BIN (w)); gtk_entry_set_width_chars (GTK_ENTRY (w), 6); g_signal_connect (G_OBJECT (w), "activate", G_CALLBACK(integrated_ui_toolbar_zoom_activate), NULL); /* Seperator */ sep = gtk_separator_tool_item_new (); gtk_toolbar_insert (toolbar, sep, -1); gtk_widget_show (GTK_WIDGET (sep)); /* Snap to grid */ w = dia_toggle_button_new_with_icon_names ("dia-grid-on", "dia-grid-off"); g_signal_connect (G_OBJECT (w), "toggled", G_CALLBACK (integrated_ui_toolbar_grid_snap_toggle), toolbar); gtk_widget_set_tooltip_text (w, _("Toggles snap-to-grid.")); g_object_set_data (G_OBJECT (toolbar), DIA_INTEGRATED_TOOLBAR_SNAP_GRID, w); integrated_ui_toolbar_add_custom_item (toolbar, w); /* Object Snapping */ w = dia_toggle_button_new_with_icon_names ("dia-mainpoints-on", "dia-mainpoints-off"); g_signal_connect (G_OBJECT (w), "toggled", G_CALLBACK (integrated_ui_toolbar_object_snap_toggle), toolbar); gtk_widget_set_tooltip_text (w, _("Toggles object snapping.")); g_object_set_data (G_OBJECT (toolbar), DIA_INTEGRATED_TOOLBAR_OBJECT_SNAP, w); integrated_ui_toolbar_add_custom_item (toolbar, w); sep = gtk_separator_tool_item_new (); gtk_toolbar_insert (toolbar, sep, -1); gtk_widget_show (GTK_WIDGET (sep)); return GTK_WIDGET (toolbar); }
static gboolean analyzer_ui_init (void) { GtkActionGroup *action_group; char *path; ui = g_slice_new0 (AnalyzerUI); path = g_build_filename (DATADIR, "codecanalyzer", "ui", "mainwindow.xml", NULL); ui->builder = make_builder (path); g_free (path); ui->main_window = get_widget_from_builder (ui->builder, "Codecanalyzer-main-window"); ui->main_vbox = get_widget_from_builder (ui->builder, "MainVBox"); ui->child_vbox1 = get_widget_from_builder (ui->builder, "child_vbox1"); ui->child_vbox2 = get_widget_from_builder (ui->builder, "child_vbox2"); ui->child_vbox3 = get_widget_from_builder (ui->builder, "child_vbox3"); ui->menubar_vbox = get_widget_from_builder (ui->builder, "menubar_vbox"); ui->stream_chooser = get_widget_from_builder (ui->builder, "StreamChooser"); ui->numframes_chooser = get_widget_from_builder (ui->builder, "NumFrameEntryButton"); ui->analyze_button = get_widget_from_builder (ui->builder, "AnalyzeButton"); ui->cancel_button = get_widget_from_builder (ui->builder, "CancelButton"); ui->hbox1_in_vbox2 = get_widget_from_builder (ui->builder, "hbox1_in_vbox2"); ui->child_hbox_in_vbox1_2 = get_widget_from_builder (ui->builder, "child_hbox_in_vbox1_2"); ui->thumbnails_scroll_window = get_widget_from_builder (ui->builder, "thumbnails_scrolled_window"); ui->thumbnails_view_port = get_widget_from_builder (ui->builder, "thumbnails_view_port"); ui->general_info_frame = get_widget_from_builder (ui->builder, "general_info_frame"); ui->general_info_vbox = get_widget_from_builder (ui->builder, "general_info_vbox"); ui->general_info_treeview = get_widget_from_builder (ui->builder, "general_info_treeview"); ui->parsed_info_hbox = get_widget_from_builder (ui->builder, "parsed_info_hbox"); ui->parsed_info_vbox = get_widget_from_builder (ui->builder, "parsed_info_vbox"); ui->parsed_info_frame = get_widget_from_builder (ui->builder, "parsed_info_frame"); ui->parsed_info_button_box = get_widget_from_builder (ui->builder, "parsed_info_button_box"); /* Create menu */ action_group = gtk_action_group_new ("ActionGroup"); gtk_action_group_add_actions (action_group, entries_actiongroup, G_N_ELEMENTS (entries_actiongroup), NULL); ui->menu_manager = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (ui->menu_manager, action_group, 0); path = g_build_filename (DATADIR, "codecanalyzer", "ui", "menu.xml", NULL); gtk_ui_manager_add_ui_from_file (ui->menu_manager, path, NULL); g_free (path); ui->menubar = gtk_ui_manager_get_widget (ui->menu_manager, "/MainMenu"); gtk_box_pack_start (GTK_BOX (ui->menubar_vbox), ui->menubar, FALSE, FALSE, 0); gtk_window_add_accel_group (GTK_WINDOW (ui->main_window), gtk_ui_manager_get_accel_group (ui->menu_manager)); ui->notebook_hash = g_hash_table_new (g_str_hash, g_str_equal); ui->prev_page = NULL; ui->num_frames = 0; gtk_window_maximize (GTK_WINDOW (ui->main_window)); path = g_build_filename (DATADIR, "codecanalyzer", "pixmaps", "codecanalyzer-logo.png", NULL); if (!gtk_window_set_icon_from_file (GTK_WINDOW (ui->main_window), path, NULL)) g_warning ("Failed to load the icon image.. "); g_free (path); return TRUE; }
void create_window() { p_hBox=gtk_hbox_new(FALSE,0); //GtkWidget *buttonFindChar; GdkDisplay *display = gdk_display_get_default(); GdkScreen *screen = gdk_display_get_screen(display, 0); int screen_width = gdk_screen_get_width(screen); int screen_height = gdk_screen_get_height(screen); //GError *error=NULL; pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(pWindow), "GtkImage"); g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL); p_vBox = gtk_vbox_new (FALSE, 0); GtkUIManager *p_uiManager = NULL; GtkActionGroup *p_actionGroup = NULL; GtkActionEntry entries[] = { {"FichierMenuAction", NULL, "Fichier", NULL, NULL, NULL}, {"NouveauAction", GTK_STOCK_SAVE_AS, "Enregistrer", "<Control>N", "Enregistrer", G_CALLBACK (menu_new)}, {"OuvrirAction", GTK_STOCK_OPEN, "Ouvrir", "<Control>O", "Ouvrir", G_CALLBACK(menu_open)}, {"QuitterAction", GTK_STOCK_QUIT, "Quitter", "<control>Q", "Quitter", G_CALLBACK (menu_quit)}, {"AideMenuAction", NULL, "Aide", NULL, NULL, NULL}, {"AideAction", GTK_STOCK_HELP, "Aide", "<Release>F1", "Aide", G_CALLBACK (menu_help)}, {"AproposAction", GTK_STOCK_ABOUT, "A propos", "<Control>A", "About", G_CALLBACK (menu_about)}, {"Binarize",GTK_STOCK_INDENT, "Binarize","<Control>B","Binarize", G_CALLBACK(Binarize)}, {"Detection", GTK_STOCK_OPEN, "Detection", "<Control>A", "Detection", G_CALLBACK (afficher_findchar)}, }; // pHBox= gtk_vbox_new(FALSE,8); // pVBox = gtk_vbox_new(FALSE, 8); //gtk_container_add(GTK_CONTAINER(pWindow), pVBox); //gtk_container_add(GTK_CONTAINER(pWindow),pHBox ); /* pixbuf2=gdk_pixbuf_new_from_file("image2.bmp", &error); pixbuf = gdk_pixbuf_new_from_file (sChemin, &error); GdkPixbuf *pixbuf_mini = NULL; GdkPixbuf *pixbuf_mini2=NULL; //pixbuf_mini2=gdk_pixbuf_scale_simple(pixbuf2,625,450, // GDK_INTERP_NEAREST); pixbuf_mini = gdk_pixbuf_scale_simple (pixbuf,625, 450, GDK_INTERP_NEAREST); pImage2=gtk_image_new_from_pixbuf(pixbuf_mini2); pImage = gtk_image_new_from_pixbuf (pixbuf_mini); buttonFindChar = gtk_button_new_with_label("FindChar"); g_signal_connect(G_OBJECT(buttonFindChar), "clicked", G_CALLBACK(afficher_findchar), NULL);*/ gtk_container_set_border_width (GTK_CONTAINER (pWindow), 10); gtk_window_set_default_size(GTK_WINDOW(pWindow), screen_width, screen_height); gtk_window_move(GTK_WINDOW(pWindow), 0, 600); /* Creation du menu */ p_uiManager = gtk_ui_manager_new (); p_actionGroup = gtk_action_group_new ("menuActionGroup"); gtk_action_group_add_actions (p_actionGroup, entries, G_N_ELEMENTS (entries), NULL); gtk_ui_manager_insert_action_group (p_uiManager, p_actionGroup, 0); gtk_ui_manager_add_ui_from_file (p_uiManager, "menu.xml", NULL); //gtk_box_pack_start(GTK_BOX(pVBox),pHBox,FALSE,TRUE,0); // gtk_container_add (GTK_CONTAINER (pHBox), p_vBox); // gtk_box_pack_end(GTK_BOX(p_vBox), buttonFindChar, FALSE,TRUE , 0); // gtk_box_pack_end(GTK_BOX(p_vBox), pImage, TRUE, TRUE, 0); //gtk_box_pack_end(GTK_BOX(p_vBox),pImage2,FALSE,TRUE,0); gtk_container_add(GTK_CONTAINER(pWindow),p_vBox ); g_signal_connect (p_uiManager, "add_widget", G_CALLBACK (menu_addWidget), p_vBox); gtk_widget_show_all(pWindow); gtk_main(); }
int main(int argc, char** argv) { GtkWidget * window; GtkWidget * menubox; GtkActionGroup * actiongroup; GtkUIManager * menumanager; GError * error; GtkWidget * menubar; // Not a good idea to start gtk without this line // In fact, I'm not sure if it starts without it. gtk_init(&argc, &argv); // Make the main window // TOPLEVEL means that the window manager deals with it window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Buffalo"); gtk_window_set_default_size(GTK_WINDOW(window), 900, 600); // The menubox, the place to pack the menu menubox = gtk_vbox_new(FALSE, 0); // Really should look that FALSE up later // As everything in gtk does, actions need a box too actiongroup = gtk_action_group_new("MainActions"); // Not sure what this does yet... // Maybe it'll be obvious when I have to refer to it later // Named reservation after indian reservations gtk_action_group_set_translation_domain(actiongroup, "reservation"); menumanager = gtk_ui_manager_new(); // This shows by itself gtk_container_add(GTK_CONTAINER(window), menubox); // I need to understand the next two entries thoroughly before I // hand in my report. I don't know how much of the report I will // have to take explaining the procedure. gtk_action_group_add_actions(actiongroup, menuentries, nentries, NULL); gtk_ui_manager_insert_action_group(menumanager, actiongroup, 0); // No errors! I certainly don't want random errors showing from // unassigned memory error = NULL; // Load the XML file gtk_ui_manager_add_ui_from_file(menumanager, "BuffaloMainMenu.xml", &error); // Output errors loading the xml file, if any. if(error) { g_message ("The menu failed. Gtk says: %s", error->message); g_error_free(error); } // Connect the quit signal. I don't know why gtk doesn't just // have this as the default. Maybe GTK3 does. g_signal_connect(window, "destroy", G_CALLBACK(quitBuffalo),NULL); // Time to pack the menubar menubar = gtk_ui_manager_get_widget(menumanager, "/MainMenu"); gtk_box_pack_start(GTK_BOX(menubox), menubar, FALSE, FALSE, 0); // The notes on the example say, 'Make sure that the accelerators work' // What?! gtk_window_add_accel_group(GTK_WINDOW(window),gtk_ui_manager_get_accel_group(menumanager)); // show_all is new! gtk_widget_show_all(window); // THE moment of a gui program. gtk_main(); return 0; }
void e_composer_private_constructed (EMsgComposer *composer) { EMsgComposerPrivate *priv = composer->priv; EFocusTracker *focus_tracker; EComposerHeader *header; EShell *shell; EClientCache *client_cache; EHTMLEditor *editor; EHTMLEditorView *view; GtkUIManager *ui_manager; GtkAction *action; GtkWidget *container; GtkWidget *widget; GtkWidget *send_widget; GtkWindow *window; GSettings *settings; const gchar *path; gchar *filename, *gallery_path; gint ii; GError *error = NULL; editor = e_msg_composer_get_editor (composer); ui_manager = e_html_editor_get_ui_manager (editor); view = e_html_editor_get_view (editor); settings = e_util_ref_settings ("org.gnome.evolution.mail"); shell = e_msg_composer_get_shell (composer); client_cache = e_shell_get_client_cache (shell); /* Each composer window gets its own window group. */ window = GTK_WINDOW (composer); priv->window_group = gtk_window_group_new (); gtk_window_group_add_window (priv->window_group, window); priv->async_actions = gtk_action_group_new ("async"); priv->charset_actions = gtk_action_group_new ("charset"); priv->composer_actions = gtk_action_group_new ("composer"); priv->extra_hdr_names = g_ptr_array_new (); priv->extra_hdr_values = g_ptr_array_new (); priv->charset = e_composer_get_default_charset (); priv->is_from_new_message = FALSE; priv->set_signature_from_message = FALSE; priv->disable_signature = FALSE; priv->busy = FALSE; priv->saved_editable = FALSE; priv->drop_occured = FALSE; priv->dnd_is_uri = FALSE; priv->check_if_signature_is_changed = FALSE; priv->ignore_next_signature_change = FALSE; priv->dnd_history_saved = FALSE; priv->focused_entry = NULL; e_composer_actions_init (composer); filename = e_composer_find_data_file ("evolution-composer.ui"); gtk_ui_manager_add_ui_from_file (ui_manager, filename, &error); g_free (filename); /* We set the send button as important to have a label */ path = "/main-toolbar/pre-main-toolbar/send"; send_widget = gtk_ui_manager_get_widget (ui_manager, path); gtk_tool_item_set_is_important (GTK_TOOL_ITEM (send_widget), TRUE); composer_setup_charset_menu (composer); if (error != NULL) { /* Henceforth, bad things start happening. */ g_critical ("%s", error->message); g_clear_error (&error); } /* Configure an EFocusTracker to manage selection actions. */ focus_tracker = e_focus_tracker_new (GTK_WINDOW (composer)); action = e_html_editor_get_action (editor, "cut"); e_focus_tracker_set_cut_clipboard_action (focus_tracker, action); action = e_html_editor_get_action (editor, "copy"); e_focus_tracker_set_copy_clipboard_action (focus_tracker, action); action = e_html_editor_get_action (editor, "paste"); e_focus_tracker_set_paste_clipboard_action (focus_tracker, action); action = e_html_editor_get_action (editor, "select-all"); e_focus_tracker_set_select_all_action (focus_tracker, action); action = e_html_editor_get_action (editor, "undo"); e_focus_tracker_set_undo_action (focus_tracker, action); action = e_html_editor_get_action (editor, "redo"); e_focus_tracker_set_redo_action (focus_tracker, action); priv->focus_tracker = focus_tracker; widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (composer), widget); gtk_widget_show (widget); container = widget; /* Construct the main menu and toolbar. */ widget = e_html_editor_get_managed_widget (editor, "/main-menu"); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); gtk_widget_show (widget); widget = e_html_editor_get_managed_widget (editor, "/main-toolbar"); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); gtk_widget_show (widget); /* Construct the header table. */ widget = e_composer_header_table_new (client_cache); gtk_container_set_border_width (GTK_CONTAINER (widget), 6); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); priv->header_table = g_object_ref (widget); gtk_widget_show (widget); header = e_composer_header_table_get_header ( E_COMPOSER_HEADER_TABLE (widget), E_COMPOSER_HEADER_SUBJECT); e_binding_bind_property ( view, "spell-checker", header->input_widget, "spell-checker", G_BINDING_SYNC_CREATE); /* Construct the editing toolbars. We'll have to reparent * the embedded EHTMLEditorView a little further down. */ widget = GTK_WIDGET (editor); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); gtk_widget_show (widget); /* Construct the attachment paned. */ widget = e_attachment_paned_new (); gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); priv->attachment_paned = g_object_ref_sink (widget); gtk_widget_show (widget); e_binding_bind_property ( view, "editable", widget, "sensitive", G_BINDING_SYNC_CREATE); container = e_attachment_paned_get_content_area ( E_ATTACHMENT_PANED (priv->attachment_paned)); widget = gtk_paned_new (GTK_ORIENTATION_VERTICAL); gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); gtk_widget_show (widget); container = widget; widget = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_widget_set_size_request (widget, -1, GALLERY_INITIAL_HEIGHT); gtk_paned_pack1 (GTK_PANED (container), widget, FALSE, FALSE); priv->gallery_scrolled_window = g_object_ref (widget); gtk_widget_show (widget); /* Reparent the scrolled window containing the web view * widget into the content area of the top attachment pane. */ widget = GTK_WIDGET (view); widget = gtk_widget_get_parent (widget); gtk_widget_reparent (widget, container); /* Construct the picture gallery. */ container = priv->gallery_scrolled_window; /* FIXME This should be an EMsgComposer property. */ gallery_path = g_settings_get_string ( settings, "composer-gallery-path"); widget = e_picture_gallery_new (gallery_path); gtk_container_add (GTK_CONTAINER (container), widget); priv->gallery_icon_view = g_object_ref_sink (widget); g_free (gallery_path); e_signal_connect_notify_swapped ( view, "notify::mode", G_CALLBACK (composer_update_gallery_visibility), composer); g_signal_connect_swapped ( ACTION (PICTURE_GALLERY), "toggled", G_CALLBACK (composer_update_gallery_visibility), composer); /* Initial sync */ composer_update_gallery_visibility (composer); /* Bind headers to their corresponding actions. */ for (ii = 0; ii < E_COMPOSER_NUM_HEADERS; ii++) { EComposerHeaderTable *table; EComposerHeader *header; GtkAction *action; table = E_COMPOSER_HEADER_TABLE (priv->header_table); header = e_composer_header_table_get_header (table, ii); switch (ii) { case E_COMPOSER_HEADER_FROM: e_widget_undo_attach ( GTK_WIDGET (e_composer_from_header_get_name_entry (E_COMPOSER_FROM_HEADER (header))), focus_tracker); e_widget_undo_attach ( GTK_WIDGET (e_composer_from_header_get_address_entry (E_COMPOSER_FROM_HEADER (header))), focus_tracker); action = ACTION (VIEW_FROM_OVERRIDE); e_binding_bind_property ( header, "override-visible", action, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); continue; case E_COMPOSER_HEADER_BCC: action = ACTION (VIEW_BCC); break; case E_COMPOSER_HEADER_CC: action = ACTION (VIEW_CC); break; case E_COMPOSER_HEADER_REPLY_TO: action = ACTION (VIEW_REPLY_TO); e_widget_undo_attach ( GTK_WIDGET (header->input_widget), focus_tracker); break; case E_COMPOSER_HEADER_SUBJECT: e_widget_undo_attach ( GTK_WIDGET (header->input_widget), focus_tracker); continue; default: continue; } e_binding_bind_property ( header, "sensitive", action, "sensitive", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); e_binding_bind_property ( header, "visible", action, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); } /* Disable actions that start asynchronous activities while an * asynchronous activity is in progress. We enforce this with * a simple inverted binding to EMsgComposer's "busy" property. */ e_binding_bind_property ( composer, "busy", priv->async_actions, "sensitive", G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN); e_binding_bind_property ( composer, "busy", priv->header_table, "sensitive", G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN); g_object_unref (settings); }
int main(int argc, char **argv) { GtkWidget *menubar, *pri_vbox, *tabla, *scroll; GtkAccelGroup *accel_group; GtkUIManager *ui_manager; GtkAction *action; LIBXML_TEST_VERSION karakter_betoltes("ruin.xml"); //return 0; gtk_init(&argc, &argv); action_group = gtk_action_group_new("main_menu"); action = gtk_action_new("uj-karakter", "Új karakter", "Új karakter létrehozása", GTK_STOCK_NEW); gtk_action_group_add_action_with_accel(action_group, action, "<Control>N"); action = gtk_action_new("karakter-megnyitas", "Karakter megnyitása", "Elmentett karakter megnyitása", GTK_STOCK_OPEN); gtk_action_group_add_action_with_accel(action_group, action, "<Control>O"); action = gtk_action_new("karakter-mentes", "Karakter mentése", "Karakter adatainak mentése", GTK_STOCK_SAVE); gtk_action_group_add_action_with_accel(action_group, action, "<Control>S"); action = gtk_action_new("kilepes", "Kilépés", "Kilépés a programból", GTK_STOCK_QUIT); gtk_action_group_add_action_with_accel(action_group, action, "<Control>Q"); g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(kilepes_func), NULL); action = gtk_action_new("karakter-menu", "Karakter", "Karakter", NULL); gtk_action_group_add_action(action_group, action); gtk_action_group_add_radio_actions(action_group, menu_items, nezet_menu_szama, 0, G_CALLBACK(nezet_menu), NULL); action = gtk_action_new("nezet-menu", "Nézet", "Nézet", NULL); gtk_action_group_add_action(action_group, action); ui_manager = gtk_ui_manager_new(); gtk_ui_manager_set_add_tearoffs(ui_manager, FALSE); gtk_ui_manager_insert_action_group(ui_manager, action_group, 0); gtk_ui_manager_add_ui_from_file(ui_manager, "magus_kargen_res.ui", NULL); accel_group = gtk_accel_group_new(); main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(main_window), "destroy", G_SIGNAL_FUNC(main_window_destroy), NULL); gtk_window_add_accel_group(GTK_WINDOW(main_window), accel_group); gtk_window_set_title(GTK_WINDOW(main_window), "M.A.G.U.S. - Reneszánsz karakternyilvántartó"); menubar = gtk_ui_manager_get_widget(ui_manager, "/menu"); book = gtk_notebook_new(); gtk_notebook_set_scrollable(GTK_NOTEBOOK(book), TRUE); gtk_notebook_popup_enable(GTK_NOTEBOOK(book)); g_signal_connect(GTK_OBJECT(book), "change-current-page", G_SIGNAL_FUNC(lapvaltas), NULL); /* Azonnal látható és hallható dolgok */ scroll = gtk_scrolled_window_new(NULL, NULL); tabla = gtk_table_new(18, 2, FALSE); azonnal_lathato_dolgok_lap(GTK_TABLE(tabla)); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla); gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(EGYBOL_LATHATO_HALLHATO_DOLGOK)); /* A játékos és a karakter adatai */ scroll = gtk_scrolled_window_new(NULL, NULL); tabla = gtk_table_new(4, 2, FALSE); jatekos_es_karakter_lap(GTK_TABLE(tabla)); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla); gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(A_JATEKOS_ES_A_KARAKTER_ADATAI)); /* Képességek */ scroll = gtk_scrolled_window_new(NULL, NULL); tabla = gtk_table_new(10, 2, FALSE); kepessegek_lap(GTK_TABLE(tabla)); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla); gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(KEPESSEGEK)); /* Főbb adatok */ scroll = gtk_scrolled_window_new(NULL, NULL); tabla = gtk_table_new(26, 4, FALSE); fobb_adatok_lap(GTK_TABLE(tabla)); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla); gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(A_KARAKTER_FOBB_ADATAI)); /* Megjelenés */ scroll = gtk_scrolled_window_new(NULL, NULL); tabla = gtk_table_new(10, 4, FALSE); megjelenes_lap(GTK_TABLE(tabla)); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla); gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(MEGJELENES)); /* Állandó érzelmek */ scroll = gtk_scrolled_window_new(NULL, NULL); tabla = gtk_table_new(15, 2, FALSE); erzelmek_lap(GTK_TABLE(tabla)); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla); gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(ALLANDO_ERZELMEK)); /* Szimpatikus viszonyok. Ide majd egy TableView kene */ gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(SZIMPATIKUS_VISZONYOK)); /* Kapcsolatok, ismertseg. Ide majd egy TableView kene */ gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ISMERTSEG)); /* Kulonleges kepessegek, hatranyok. Ide is TableView kene */ gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KULONLEGES_KEPESSEGEK)); /* Tapasztalati pontok, átváltás */ scroll = gtk_scrolled_window_new(NULL, NULL); tabla = gtk_table_new(3, 2, FALSE); tapasztalat_lap(GTK_TABLE(tabla)); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla); gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(TAPASZTALATI_PONTOK)); /* Képzettségek. Ide majd egy TableView kell */ gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KEPZETTSEGEK)); /* Nyelvek. Ide is TableView */ gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(NYELVEK)); /* Harcértékek */ scroll = gtk_scrolled_window_new(NULL, NULL); tabla = gtk_table_new(5, 4, FALSE); harcertekek_lap(GTK_TABLE(tabla)); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla); gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(HARCERTEKEK)); /* Életerő */ scroll = gtk_scrolled_window_new(NULL, NULL); tabla = gtk_table_new(3, 4, FALSE); eletero_lap(GTK_TABLE(tabla)); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla); gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(ELETERO)); /* Pszi */ scroll = gtk_scrolled_window_new(NULL, NULL); tabla = gtk_table_new(5, 2, FALSE); pszi_lap(GTK_TABLE(tabla)); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla); gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(PSZI)); /* Mágia */ gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MAGIA)); /* Fegyverek és pajzsok. Ide két TableView kell. */ gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(FEGYVEREK_PAJZS)); /* Állatok, csatlósok, szolgák. Ide sok TableView kell */ gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ALLATOK_CSATLOSOK)); /* Mesterek és tanítók. Ide két TableView kell */ gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MESTEREK)); /* Földbirtokok. Ide is TableView kell */ gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(BIRTOKOK_BEFEKTETESEK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ALAKULATOK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ISKOLAK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MUVEK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ERTEKEK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(RUHAK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(VARAZSTARGYAK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(FELSZERELES)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(VARAZSLATOK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(TANULAS)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(SEBESULESEK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(BETEGSEGEK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(VARAZSLAT_KUTATAS)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KULONLEGES_DOLGOK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MEGJEGYZESEK)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(TORTENET)); gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KEPEK)); pri_vbox = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(pri_vbox), menubar, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(pri_vbox), book, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(main_window), pri_vbox); gtk_widget_show_all(main_window); gtk_window_maximize(GTK_WINDOW(main_window)); gtk_main(); xmlCleanupParser(); return 0; }
static void build_ui (EmerillonWindow *self) { GtkAction *action; GtkWidget *vbox; GtkWidget *menubar; GtkToolItem *throbber; GtkWidget *viewport; GtkWidget *hpaned; GtkWidget *embed_view; ClutterActor *scale; GError *error = NULL; /* Action entries. */ self->priv->main_actions = gtk_action_group_new ("MenuActionsWindow"); gtk_action_group_set_translation_domain (self->priv->main_actions, GETTEXT_PACKAGE); gtk_action_group_add_actions (self->priv->main_actions, action_entries, G_N_ELEMENTS (action_entries), self); /* Toggle entries. */ gtk_action_group_add_toggle_actions (self->priv->main_actions, toggle_entries, G_N_ELEMENTS (toggle_entries), self); /* Radio entries. */ gtk_action_group_add_radio_actions (self->priv->main_actions, radio_entries, G_N_ELEMENTS (radio_entries), 0, G_CALLBACK (cmd_map_change_map), self); /* Short labels. */ action = gtk_action_group_get_action (self->priv->main_actions, "ViewZoomIn"); g_object_set (action, "short_label", _("In"), NULL); action = gtk_action_group_get_action (self->priv->main_actions, "ViewZoomOut"); g_object_set (action, "short_label", _("Out"), NULL); /* UI manager. */ self->priv->ui_manager = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (self->priv->ui_manager, self->priv->main_actions, 0); if (!gtk_ui_manager_add_ui_from_file (self->priv->ui_manager, EMERILLON_DATADIR "/emerillon-ui.xml", &error)) { g_warning ("building menus failed: %s", error->message); g_error_free (error); return; } g_signal_connect (self->priv->ui_manager, "connect_proxy", G_CALLBACK (connect_proxy_cb), self); g_signal_connect (self->priv->ui_manager, "disconnect_proxy", G_CALLBACK (disconnect_proxy_cb), self); gtk_window_add_accel_group (GTK_WINDOW (self), gtk_ui_manager_get_accel_group (self->priv->ui_manager)); /* Main box. */ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (self), vbox); gtk_widget_show (vbox); /* Menu. */ menubar = gtk_ui_manager_get_widget (self->priv->ui_manager, "/MainMenu"); g_assert (GTK_IS_WIDGET (menubar)); gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0); gtk_widget_show (menubar); /* Toolbar. */ self->priv->toolbar = gtk_ui_manager_get_widget (self->priv->ui_manager, "/Toolbar"); gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->toolbar), "primary-toolbar"); self->priv->throbber = gtk_spinner_new (); throbber = gtk_tool_item_new (); gtk_container_add (GTK_CONTAINER (throbber), self->priv->throbber); gtk_widget_show (GTK_WIDGET (self->priv->throbber)); gtk_widget_show (GTK_WIDGET (throbber)); gtk_toolbar_insert (GTK_TOOLBAR (self->priv->toolbar), throbber, -1); gtk_box_pack_start (GTK_BOX (vbox), self->priv->toolbar, FALSE, FALSE, 0); gtk_widget_show (self->priv->toolbar); /* Statusbar. */ self->priv->statusbar = gtk_statusbar_new (); gtk_box_pack_end (GTK_BOX (vbox), GTK_WIDGET (self->priv->statusbar), FALSE, FALSE, 0); gtk_widget_show (self->priv->statusbar); self->priv->tooltip_message_context_id = gtk_statusbar_get_context_id ( GTK_STATUSBAR (self->priv->statusbar), "tooltip-message"); /* Viewport. */ viewport = gtk_frame_new (NULL); /* Map. */ embed_view = gtk_champlain_embed_new (); gtk_container_add (GTK_CONTAINER (viewport), embed_view); /* FIXME: workaround for a champlain-gtk bug, replace with _show(). */ gtk_widget_show_all (embed_view); self->priv->view = gtk_champlain_embed_get_view (GTK_CHAMPLAIN_EMBED (embed_view)); g_signal_connect (self->priv->view, "notify::zoom-level", G_CALLBACK (zoom_changed_cb), self); g_signal_connect (self->priv->view, "notify::map-source", G_CALLBACK (zoom_changed_cb), self); g_signal_connect (self->priv->view, "notify::state", G_CALLBACK (state_changed_cb), self); g_object_set (self->priv->view, "zoom-level", 1, "kinetic-mode", TRUE, NULL); champlain_view_center_on (self->priv->view, 40, 0); scale = champlain_scale_new (); champlain_scale_connect_view (CHAMPLAIN_SCALE (scale), self->priv->view); /* align to the bottom left */ champlain_view_bin_layout_add (self->priv->view, scale, CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END); /* Sidebar. */ self->priv->sidebar = emerillon_sidebar_new (); gtk_widget_set_size_request (self->priv->sidebar, 200, -1); /* Horizontal pane. */ hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL); gtk_paned_pack1 (GTK_PANED (hpaned), self->priv->sidebar, FALSE, FALSE); gtk_paned_pack2 (GTK_PANED (hpaned), viewport, TRUE, FALSE); gtk_widget_show (self->priv->sidebar); gtk_widget_show (viewport); g_signal_connect_after (self->priv->sidebar, "show", G_CALLBACK (sidebar_visibility_changed_cb), self); g_signal_connect_after (self->priv->sidebar, "hide", G_CALLBACK (sidebar_visibility_changed_cb), self); gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0); gtk_widget_show (hpaned); update_ui_visibility (self); }
int main (int argc, char **argv) { GtkWidget *window; GtkWidget *main_hbox; GtkWidget *vseparator; GtkWidget *button; GtkWidget *main_vbox; GtkWidget *menubar; GtkWidget *vbox; GtkWidget *label; GtkAccelGroup *accel_group; PangoFontDescription *font_desc; int i; char *p; p = progname = argv[0]; while (*p) { if (*p == '/') progname = p+1; p++; } gtk_init (&argc, &argv); for (i=1; i<argc; i++) { if (!strcmp(argv[i], "--data-file") || !strcmp(argv[i], "-f")) { i++; if (i < argc) data_file = argv[i]; else usage(); } else { usage(); } } window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_resizable (GTK_WINDOW (window), TRUE); gtk_window_set_default_size (GTK_WINDOW (window), 350, 350); g_signal_connect (window, "destroy", G_CALLBACK (exit_callback), NULL); gtk_window_set_title (GTK_WINDOW(window), "KanjiPad"); main_vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (window), main_vbox); gtk_widget_show (main_vbox); /* Menu */ GtkActionGroup *action_group; /* Packing group for our Actions */ GtkUIManager *menu_manager; /* The magic widget! */ GError *error; /* For reporting exceptions or errors */ GtkWidget *toolbar; /* The actual toolbar */ action_group = gtk_action_group_new ("MainMenu"); gtk_action_group_add_actions (action_group, entries, n_entries, NULL); gtk_action_group_add_toggle_actions (action_group, toggle_entries, n_toggle_entries, NULL); menu_manager = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (menu_manager, action_group, 0); error = NULL; gtk_ui_manager_add_ui_from_file (menu_manager, "ui.xml", &error); if (error){ g_message ("building menus failed: %s", error->message); g_error_free (error); } //Add the menu bar menubar = gtk_ui_manager_get_widget (menu_manager, "/MainMenu"); gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, FALSE, 0); /*accel_group = gtk_accel_group_new (); factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group); gtk_item_factory_create_items (factory, nmenu_items, menu_items, NULL);*/ /* create a menubar */ /*menubar = gtk_item_factory_get_widget (factory, "<main>"); gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, TRUE, 0); gtk_widget_show (menubar);*/ /* Install the accelerator table in the main window */ //gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); main_hbox = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER(window), main_hbox); gtk_box_pack_start (GTK_BOX(main_vbox), main_hbox, TRUE, TRUE, 0); gtk_widget_show (main_hbox); /* toolbar = gtk_ui_manager_get_widget (menu_manager, "/MainToolbar"); gtk_box_pack_start (GTK_BOX (main_hbox), toolbar, FALSE, FALSE, 0); gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group (menu_manager)); */ /* Area for user to draw characters in */ pad_area = pad_area_create (); gtk_box_pack_start (GTK_BOX (main_hbox), pad_area->widget, TRUE, TRUE, 0); gtk_widget_show (pad_area->widget); vseparator = gtk_vseparator_new(); gtk_box_pack_start (GTK_BOX (main_hbox), vseparator, FALSE, FALSE, 0); gtk_widget_show (vseparator); /* Area in which to draw guesses */ vbox = gtk_vbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (main_hbox), vbox, FALSE, FALSE, 0); gtk_widget_show (vbox); karea = gtk_drawing_area_new(); g_signal_connect (karea, "configure_event", G_CALLBACK (karea_configure_event), NULL); g_signal_connect (karea, "expose_event", G_CALLBACK (karea_expose_event), NULL); g_signal_connect (karea, "button_press_event", G_CALLBACK (karea_button_press_event), NULL); gtk_widget_set_events (karea, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); #ifdef G_OS_WIN32 font_desc = pango_font_description_from_string ("MS Gothic 18"); #else font_desc = pango_font_description_from_string ("Sans 18"); #endif gtk_widget_modify_font (karea, font_desc); gtk_box_pack_start (GTK_BOX (vbox), karea, TRUE, TRUE, 0); gtk_widget_show (karea); /* Buttons */ label = gtk_label_new ("\xe5\xbc\x95"); /* We have to set the alignment here, since GTK+ will fail * to get the width of the string appropriately... */ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_widget_modify_font (label, font_desc); gtk_widget_show (label); lookup_button = button = gtk_button_new (); gtk_container_add (GTK_CONTAINER (button), label); g_signal_connect (button, "clicked", G_CALLBACK (look_up_callback), NULL); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_widget_show (button); label = gtk_label_new ("\xe6\x88\xbb"); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_widget_modify_font (label, font_desc); gtk_widget_show (label); undo_button = button = gtk_button_new (); gtk_container_add (GTK_CONTAINER (button), label); g_signal_connect (button, "clicked", G_CALLBACK (undo_callback), NULL); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_widget_show (button); label = gtk_label_new ("\xe6\xb6\x88"); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_widget_modify_font (label, font_desc); gtk_widget_show (label); clear_button = button = gtk_button_new (); gtk_container_add (GTK_CONTAINER (button), label); g_signal_connect (button, "clicked", G_CALLBACK (clear_callback), NULL); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_widget_show (button); gtk_widget_show(window); pango_font_description_free (font_desc); init_engine(); update_sensitivity (); gtk_main(); return 0; }