static GtkWidget* find_widget(GtkWidget* parent, const gchar* name, int depth) { // printf("%*.*c%s\n", depth, depth, ' ', gtk_widget_get_name(parent)); GtkWidget *widget = NULL; if (g_strcasecmp(gtk_widget_get_name(parent), name) == 0) { return parent; } if (GTK_IS_BIN(parent)) { return find_widget(gtk_bin_get_child(GTK_BIN(parent)), name, depth + 1); } if (GTK_IS_CONTAINER(parent)) { GList *list = gtk_container_get_children(GTK_CONTAINER(parent)); for (GList *node = list; node; node = node->next) { widget = find_widget(GTK_WIDGET(node->data), name, depth + 1); if (widget) { break; } } g_list_free(list); } return widget; }
static void hildon_desktop_item_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkBin *bin; GtkAllocation alloc; GtkRequisition req; g_return_if_fail (GTK_IS_BIN (widget)); bin = GTK_BIN (widget); widget->allocation = *allocation; if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) { gtk_widget_size_request (bin->child,&req); alloc.x = allocation->x; alloc.y = allocation->y; alloc.width = req.width; alloc.height = req.height; gtk_widget_size_allocate (bin->child,&alloc); } }
void widget_set_sensitive(GtkWidget * widget, gboolean sensitive) { GtkWidget *button; gtk_widget_set_sensitive(widget, sensitive); /** @bug Gtk bug 56070. If the mouse is over a toolbar button that * becomes sensitive, one can't click it without moving the mouse out * and in again. This bug is registered in Bugzilla as a Gtk bug. The * workaround tests if the mouse is inside the currently sensitivized * button, and if yes call button_enter() */ if (!GTK_IS_BIN(widget)) return; button = gtk_bin_get_child(GTK_BIN(widget)); if (sensitive && GTK_IS_BUTTON(button)) { gint x, y, state; gtk_widget_get_pointer(button, &x, &y); state = GTK_WIDGET_STATE(button); if ((state == GTK_STATE_NORMAL || state == GTK_STATE_PRELIGHT) && x >= 0 && y >= 0 && x < button->allocation.width && y < button->allocation.height) { gtk_button_enter(GTK_BUTTON(button)); GTK_BUTTON(button)->in_button = TRUE; gtk_widget_set_state(widget, GTK_STATE_PRELIGHT); } } }
void glade_gtk_container_add_child (GladeWidgetAdaptor * adaptor, GtkWidget * container, GtkWidget * child) { GtkWidget *container_child = NULL; if (GTK_IS_BIN (container)) container_child = gtk_bin_get_child (GTK_BIN (container)); /* Get a placeholder out of the way before adding the child if its a GtkBin */ if (GTK_IS_BIN (container) && container_child != NULL && GLADE_IS_PLACEHOLDER (container_child)) gtk_container_remove (GTK_CONTAINER (container), container_child); gtk_container_add (GTK_CONTAINER (container), child); }
static VteTerminal* window_get_term_widget (GtkWindow *window) { GtkWidget *widget = gtk_bin_get_child (GTK_BIN (window)); if (GTK_IS_BIN (widget)) widget = gtk_bin_get_child (GTK_BIN (widget)); return VTE_TERMINAL (widget); }
static void hd_panel_window_dialog_queued (HildonDesktopPanelExpandable *container, GtkWidget *widget, gpointer object) { gtk_widget_set_name (widget, HD_PANEL_WINDOW_DIALOG_BUTTON_NAME); if (GTK_IS_BIN (widget) && GTK_IS_WIDGET (GTK_BIN (widget)->child)) gtk_widget_set_name (GTK_BIN (widget)->child, HD_PANEL_WINDOW_DIALOG_BUTTON_NAME); }
static void gimp_frame_label_widget_notify (GtkFrame *frame) { GtkWidget *label_widget = gtk_frame_get_label_widget (frame); if (label_widget) { GtkLabel *label = NULL; if (GTK_IS_LABEL (label_widget)) { gfloat xalign, yalign; label = GTK_LABEL (label_widget); gtk_frame_get_label_align (frame, &xalign, &yalign); gtk_misc_set_alignment (GTK_MISC (label), xalign, yalign); } else if (GTK_IS_BIN (label_widget)) { GtkWidget *child = gtk_bin_get_child (GTK_BIN (label_widget)); if (GTK_IS_LABEL (child)) label = GTK_LABEL (child); } if (label) { PangoAttrList *attrs = pango_attr_list_new (); PangoAttribute *attr; gboolean bold; gtk_widget_style_get (GTK_WIDGET (frame), "label_bold", &bold, NULL); attr = pango_attr_weight_new (bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); attr->start_index = 0; attr->end_index = -1; pango_attr_list_insert (attrs, attr); gtk_label_set_attributes (label, attrs); pango_attr_list_unref (attrs); } } }
static gboolean budgie_panel_draw(GtkWidget *widget, cairo_t *cr, gpointer userdata) { GtkStyleContext *style; GtkAllocation alloc; gtk_widget_get_allocation(widget, &alloc); style = gtk_widget_get_style_context(widget); gtk_render_background(style, cr, 0, 0, alloc.width, alloc.height); gtk_render_frame(style, cr, 0, 0, alloc.width, alloc.height); if (GTK_IS_BIN(widget)) { gtk_container_propagate_draw(GTK_CONTAINER(widget), gtk_bin_get_child(GTK_BIN(widget)), cr); return TRUE; } return FALSE; }
static void hildon_desktop_item_size_request (GtkWidget *widget, GtkRequisition *requisition) { GtkRequisition req; GtkBin *bin; g_return_if_fail (GTK_IS_BIN (widget)); bin = GTK_BIN (widget); if (bin->child) { gtk_widget_size_request (bin->child,&req); requisition->width = req.width; requisition->height = req.height; } else if (GTK_WIDGET_CLASS (hildon_desktop_item_parent_class)) GTK_WIDGET_CLASS (hildon_desktop_item_parent_class)->size_request (widget,requisition); }
// From: http://stackoverflow.com/questions/5401327/finding-children-of-a-gtkwidget // Find first widget in a widget tree by its name GtkWidget* gtk_widget_find_by_name(GtkWidget* root, const gchar* name) { int len = strlen(name); const gchar* widget_name = gtk_widget_get_name((GtkWidget*)root); if (g_ascii_strncasecmp(widget_name, (gchar*)name, len) == 0) { return root; } if (GTK_IS_BIN(root)) { GtkWidget *child = gtk_bin_get_child(GTK_BIN(root)); return gtk_widget_find_by_name(child, name); } if (GTK_IS_CONTAINER(root)) { GList *children = gtk_container_get_children(GTK_CONTAINER(root)); while ((children = g_list_next(children)) != NULL) { GtkWidget* widget = gtk_widget_find_by_name((GtkWidget*)children->data, name); if (widget != NULL) { return widget; } } } return NULL; }
// ZRL 目前只识别缩放比例设置,将来扩展状态栏工具时再充实该函数 GtkWidget* statusbar_features_property_proxy (MidoriWebSettings* settings, const gchar* property, GtkWidget* toolbar) { const gchar* kind = NULL; GtkWidget* button = NULL; GtkWidget* image; // ZRL 暂时屏蔽其他功能 2014.12.20 #if 0 if (!strcmp (property, "auto-load-images") || !strcmp (property, "enable-javascript") || !strcmp (property, "enable-plugins")) kind = "toggle"; else if (!strcmp (property, "identify-as")) kind = "custom-user-agent"; else if (strstr (property, "font") != NULL) kind = "font"; else if (!strcmp (property, "zoom-level")) #else if (!strcmp (property, "zoom-level")) #endif { MidoriBrowser* browser = midori_browser_get_for_widget (toolbar); guint i; button = gtk_combo_box_text_new_with_entry (); gtk_entry_set_width_chars (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (button))), 4); for (i = 0; i < G_N_ELEMENTS (zoom_levels); i++) gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (button), zoom_levels[i].label); g_signal_connect (button, "changed", G_CALLBACK (statusbar_features_zoom_level_changed_cb), browser); g_signal_connect (browser, "notify::tab", G_CALLBACK (statusbar_features_browser_notify_tab_cb), button); statusbar_features_browser_notify_tab_cb (browser, NULL, button); return button; } // ZRL 暂时屏蔽其他功能 2014.12.20 #if 0 button = katze_property_proxy (settings, property, kind); if (GTK_IS_BIN (button)) { GtkWidget* label = gtk_bin_get_child (GTK_BIN (button)); if (GTK_IS_LABEL (label)) gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); } if (!strcmp (property, "auto-load-images")) { g_object_set_data (G_OBJECT (button), "feature-label", _("Images")); image = gtk_image_new_from_stock (STOCK_IMAGE, GTK_ICON_SIZE_MENU); gtk_button_set_image (GTK_BUTTON (button), image); gtk_widget_set_tooltip_text (button, _("Load images automatically")); statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button); g_signal_connect (toolbar, "notify::toolbar-style", G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button); } if (!strcmp (property, "enable-javascript")) { g_object_set_data (G_OBJECT (button), "feature-label", _("Scripts")); image = gtk_image_new_from_stock (STOCK_SCRIPT, GTK_ICON_SIZE_MENU); gtk_button_set_image (GTK_BUTTON (button), image); gtk_widget_set_tooltip_text (button, _("Enable scripts")); statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button); g_signal_connect (toolbar, "notify::toolbar-style", G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button); } else if (!strcmp (property, "enable-plugins")) { if (!midori_web_settings_has_plugin_support ()) gtk_widget_hide (button); g_object_set_data (G_OBJECT (button), "feature-label", _("Netscape plugins")); image = gtk_image_new_from_stock (MIDORI_STOCK_PLUGINS, GTK_ICON_SIZE_MENU); gtk_button_set_image (GTK_BUTTON (button), image); gtk_widget_set_tooltip_text (button, _("Enable Netscape plugins")); statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button); g_signal_connect (toolbar, "notify::toolbar-style", G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button); } #endif return button; }
static gboolean gail_focus_watcher (GSignalInvocationHint *ihint, guint n_param_values, const GValue *param_values, gpointer data) { GObject *object; GtkWidget *widget; GdkEvent *event; object = g_value_get_object (param_values + 0); g_return_val_if_fail (GTK_IS_WIDGET(object), FALSE); event = g_value_get_boxed (param_values + 1); widget = GTK_WIDGET (object); if (event->type == GDK_FOCUS_CHANGE) { if (event->focus_change.in) { if (GTK_IS_WINDOW (widget)) { GtkWidget *focus_widget; GtkWindow *window; GtkWindowType type; window = GTK_WINDOW (widget); focus_widget = gtk_window_get_focus (window); g_object_get (window, "type", &type, NULL); if (focus_widget) { /* * If we already have a potential focus widget set this * windows's focus widget to focus_before_menu so that * it will be reported when menu item is unset. */ if (next_focus_widget) { if (GTK_IS_MENU_ITEM (next_focus_widget) && !focus_before_menu) { void *vp_focus_before_menu = &focus_before_menu; focus_before_menu = focus_widget; g_object_add_weak_pointer (G_OBJECT (focus_before_menu), vp_focus_before_menu); } return TRUE; } widget = focus_widget; } else if (type == GTK_WINDOW_POPUP) { if (GTK_IS_BIN (widget)) { GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget)); if (GTK_IS_WIDGET (child) && gtk_widget_has_grab (child)) { if (GTK_IS_MENU_SHELL (child)) { if (gtk_menu_shell_get_selected_item (GTK_MENU_SHELL (child))) { /* * We have a menu which has a menu item selected * so we do not report focus on the menu. */ return TRUE; } } widget = child; } } else /* popup window has no children; this edge case occurs in some custom code (OOo for instance) */ { return TRUE; } } else /* Widget is a non-popup toplevel with no focus children; don't emit for this case either, as it's useless */ { return TRUE; } } } else { if (next_focus_widget) { GtkWidget *toplevel; toplevel = gtk_widget_get_toplevel (next_focus_widget); if (toplevel == widget) next_focus_widget = NULL; } /* focus out */ widget = NULL; } } else { if (event->type == GDK_MOTION_NOTIFY && gtk_widget_has_focus (widget)) { if (widget == _focus_widget) { return TRUE; } } else { return TRUE; } } #ifdef GDK_WINDOWING_X11 /* * If the focus widget is a GtkSocket without a plug * then ignore the focus notification as the embedded * plug will report a focus notification. */ if (GTK_IS_SOCKET (widget) && gtk_socket_get_plug_window (GTK_SOCKET (widget)) != NULL) return TRUE; #endif /* * The widget may not yet be visible on the screen so we wait until it is. */ gail_focus_notify_when_idle (widget); return TRUE; }
static gboolean callback_button_box_click (GtkWidget * widget, GdkEvent * event, gpointer user_data) { GList *list, *header_list; GList *hlist = NULL, *slist = NULL; GtkWidget *notebook = NULL; GtkWidget *textview = NULL; GFile *hexfile; GtkWidget *sc_window, *tree_view; gboolean is_header, is_slice, is_hexval; CodecComponents component = (CodecComponents) user_data; char *xml_name = ui->current_xml; char *hex_name = ui->current_hex; switch (component) { case COMPONENTS_HEADERS_GENERAL: is_header = TRUE; is_slice = FALSE; is_hexval = FALSE; break; case COMPONENTS_HEADERS_SLICE: is_slice = TRUE; is_header = FALSE; is_hexval = FALSE; break; case COMPONENTS_HEXVAL: is_hexval = TRUE; is_header = FALSE; is_slice = FALSE; break; default: break; } if (ui->prev_page) gtk_widget_destroy (GTK_WIDGET (ui->prev_page)); if (ui->notebook_hash) g_hash_table_destroy (ui->notebook_hash); ui->notebook_hash = g_hash_table_new (g_str_hash, g_str_equal); if (!is_hexval) { header_list = analyzer_get_list_header_strings (xml_name); while (header_list) { if (strcmp (header_list->data, "comment")) { if (is_header && !g_str_has_prefix (header_list->data, "slice")) hlist = g_list_append (hlist, header_list->data); else if (is_slice && g_str_has_prefix (header_list->data, "slice")) hlist = g_list_append (hlist, header_list->data); } header_list = header_list->next; } notebook = gtk_notebook_new (); g_object_set (G_OBJECT (notebook), "expand", TRUE, NULL); gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); gtk_notebook_popup_enable (GTK_NOTEBOOK (notebook)); gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), TRUE); g_list_foreach (hlist, (GFunc) populate_notebook, (gpointer) notebook); while (hlist) { sc_window = g_hash_table_lookup (ui->notebook_hash, hlist->data); if (sc_window && GTK_IS_BIN (sc_window)) tree_view = gtk_bin_get_child (GTK_BIN (sc_window)); if (tree_view) { list = analyzer_get_list_analyzer_node_from_xml (xml_name, hlist->data); if (list) { GtkTreeStore *treestore; GtkTreeModel *model; treestore = gtk_tree_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); g_list_foreach (list, (GFunc) fill_tree_store, treestore); analyzer_node_list_free (list); list = NULL; model = GTK_TREE_MODEL (treestore); gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model); g_object_unref (model); } } hlist = hlist->next; } ui->prev_page = notebook; gtk_container_add (GTK_CONTAINER (ui->parsed_info_vbox), notebook); } else { /*Display the hex dump of the frame */ GtkWidget *scrolled_window; GtkTextBuffer *buffer; gchar *contents; gsize length; textview = gtk_text_view_new (); gtk_text_view_set_left_margin (GTK_TEXT_VIEW (textview), 20); g_object_set (G_OBJECT (textview), "expand", TRUE, "editable", FALSE, NULL); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); gtk_container_add (GTK_CONTAINER (scrolled_window), textview); hexfile = g_file_new_for_path (hex_name); if (hexfile) { if (g_file_load_contents (hexfile, NULL, &contents, &length, NULL, NULL)) { buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview)); gtk_text_buffer_set_text (buffer, contents, length); g_free (contents); g_object_unref (G_OBJECT (hexfile)); } } ui->prev_page = scrolled_window; gtk_container_add (GTK_CONTAINER (ui->parsed_info_vbox), scrolled_window); } gtk_widget_show_all (ui->main_window); return TRUE; }
static void brasero_project_type_chooser_build_recent (BraseroProjectTypeChooser *self, GtkRecentManager *recent) { GtkSizeGroup *image_group; GtkSizeGroup *group; GList *list = NULL; gchar *filename; GList *recents; GList *iter; recents = gtk_recent_manager_get_items (recent); for (iter = recents; iter; iter = iter->next) { GtkRecentInfo *info; const gchar *mime; info = iter->data; mime = gtk_recent_info_get_mime_type (info); if (!mime) continue; /* filter those we want */ if (strcmp (mime, "application/x-brasero") && strcmp (mime, "application/x-cd-image") && strcmp (mime, "application/x-cdrdao-toc") && strcmp (mime, "application/x-toc") && strcmp (mime, "application/x-cue") && strcmp (mime, "audio/x-scpls") && strcmp (mime, "audio/x-ms-asx") && strcmp (mime, "audio/x-mp3-playlist") && strcmp (mime, "audio/x-mpegurl")) continue; /* sort */ list = g_list_insert_sorted (list, info, brasero_project_type_chooser_sort_recent); if (g_list_length (list) > 5) list = g_list_delete_link (list, g_list_last (list)); } group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH); image_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH); /* If a project was left unfinished last time then add another entry */ filename = g_build_filename (g_get_user_config_dir (), "brasero", BRASERO_SESSION_TMP_PROJECT_PATH, NULL); if (g_file_test (filename, G_FILE_TEST_EXISTS)) { gchar *uri; GtkWidget *link; GtkWidget *image; uri = g_filename_to_uri (filename, NULL, NULL); image = gtk_image_new_from_icon_name ("brasero", GTK_ICON_SIZE_BUTTON); gtk_size_group_add_widget (image_group, image); link = gtk_button_new_with_label (_("Last _Unsaved Project")); g_object_set_data_full (G_OBJECT (link), "BraseroButtonURI", uri, g_free); gtk_button_set_relief (GTK_BUTTON (link), GTK_RELIEF_NONE); gtk_button_set_alignment (GTK_BUTTON (link), 0.0, 0.5); gtk_button_set_focus_on_click (GTK_BUTTON (link), FALSE); gtk_button_set_image (GTK_BUTTON (link), image); gtk_button_set_use_underline (GTK_BUTTON (link), TRUE); g_signal_connect (link, "clicked", G_CALLBACK (brasero_project_type_chooser_last_unsaved_clicked_cb), self); gtk_widget_show (link); gtk_widget_set_tooltip_text (link, _("Load the last project that was not burned and not saved")); gtk_box_pack_start (GTK_BOX (self->priv->recent_box), link, FALSE, TRUE, 0); gtk_size_group_add_widget (group, link); } g_free (filename); for (iter = list; iter; iter = iter->next) { GtkRecentInfo *info; GList *child_iter; const gchar *name; GIcon *icon; GtkWidget *image; const gchar *uri; GtkWidget *child; GtkWidget *link; GList *children; gchar *tooltip; info = iter->data; tooltip = gtk_recent_info_get_uri_display (info); icon = gtk_recent_info_get_gicon (info); image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_BUTTON); g_object_unref (icon); gtk_size_group_add_widget (image_group, image); gtk_widget_show (image); gtk_widget_set_tooltip_text (image, tooltip); name = gtk_recent_info_get_display_name (info); uri = gtk_recent_info_get_uri (info); /* Don't use mnemonics with filenames */ link = gtk_button_new_with_label (name); g_object_set_data_full (G_OBJECT (link), "BraseroButtonURI", g_strdup (uri), g_free); gtk_button_set_relief (GTK_BUTTON (link), GTK_RELIEF_NONE); gtk_button_set_image (GTK_BUTTON (link), image); gtk_button_set_alignment (GTK_BUTTON (link), 0.0, 0.5); gtk_button_set_focus_on_click (GTK_BUTTON (link), FALSE); g_signal_connect (link, "clicked", G_CALLBACK (brasero_project_type_chooser_recent_clicked_cb), self); gtk_widget_show (link); gtk_widget_set_tooltip_text (link, tooltip); gtk_box_pack_start (GTK_BOX (self->priv->recent_box), link, FALSE, TRUE, 0); g_free (tooltip); gtk_size_group_add_widget (group, link); /* That's a tedious hack to avoid mnemonics which are hardcoded * when you add an image to a button. BUG? */ if (!GTK_IS_BIN (link)) continue; child = gtk_bin_get_child (GTK_BIN (link)); if (!GTK_IS_ALIGNMENT (child)) continue; gtk_alignment_set (GTK_ALIGNMENT (child), 0.0, 0.5, 1.0, 1.0); child = gtk_bin_get_child (GTK_BIN (child)); if (!GTK_IS_BOX (child)) continue; children = gtk_container_get_children (GTK_CONTAINER (child)); for (child_iter = children; child_iter; child_iter = child_iter->next) { GtkWidget *widget; widget = child_iter->data; if (GTK_IS_LABEL (widget)) { gtk_label_set_use_underline (GTK_LABEL (widget), FALSE); gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); /* Make sure that the name is not too long */ gtk_box_set_child_packing (GTK_BOX (child), widget, TRUE, TRUE, 0, GTK_PACK_START); gtk_label_set_ellipsize (GTK_LABEL (widget), PANGO_ELLIPSIZE_END); break; } } g_list_free (children); } g_object_unref (image_group); g_object_unref (group); if (!g_list_length (list)) { GtkWidget *label; gchar *string; string = g_strdup_printf ("<i>%s</i>", _("No recently used project")); label = gtk_label_new (string); gtk_label_set_use_markup (GTK_LABEL (label), TRUE); g_free (string); gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (self->priv->recent_box), label, FALSE, FALSE, 0); } g_list_free (list); g_list_foreach (recents, (GFunc) gtk_recent_info_unref, NULL); g_list_free (recents); }