static GtkImage* get_image_from_button (GtkWidget *button) { GtkWidget *child; GList *list; GtkImage *image = NULL; child = gtk_bin_get_child (GTK_BIN (button)); if (GTK_IS_IMAGE (child)) image = GTK_IMAGE (child); else { if (GTK_IS_ALIGNMENT (child)) child = gtk_bin_get_child (GTK_BIN (child)); if (GTK_IS_CONTAINER (child)) { list = gtk_container_get_children (GTK_CONTAINER (child)); if (!list) return NULL; if (GTK_IS_IMAGE (list->data)) image = GTK_IMAGE (list->data); g_list_free (list); } } return image; }
static void count_labels (GtkContainer *container, gint *n_labels) { GList *children, *tmp_list; children = gtk_container_get_children (container); for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next) { if (GTK_IS_LABEL (tmp_list->data)) { (*n_labels)++; } /* * Label for button which are GtkTreeView column headers are in a * GtkHBox in a GtkAlignment. */ else if (GTK_IS_ALIGNMENT (tmp_list->data)) { GtkWidget *widget; widget = gtk_bin_get_child (GTK_BIN (tmp_list->data)); if (GTK_IS_LABEL (widget)) (*n_labels)++; } else if (GTK_IS_CONTAINER (tmp_list->data)) { count_labels (GTK_CONTAINER (tmp_list->data), n_labels); } } g_list_free (children); }
GtkLabel *wxButton::GTKGetLabel() const { GtkWidget* child = gtk_bin_get_child(GTK_BIN(m_widget)); #ifdef __WXGTK4__ if (GTK_IS_LABEL(child)) return GTK_LABEL(child); return NULL; #else wxGCC_WARNING_SUPPRESS(deprecated-declarations) if ( GTK_IS_ALIGNMENT(child) ) { GtkWidget* box = gtk_bin_get_child(GTK_BIN(child)); GtkLabel* label = NULL; wxGtkList list(gtk_container_get_children(GTK_CONTAINER(box))); for (GList* item = list; item; item = item->next) { if (GTK_IS_LABEL(item->data)) label = GTK_LABEL(item->data); } return label; } return GTK_LABEL(child); wxGCC_WARNING_RESTORE() #endif }
void wxToggleButton::DoApplyWidgetStyle(GtkRcStyle *style) { GTKApplyStyle(m_widget, style); GtkWidget* child = gtk_bin_get_child(GTK_BIN(m_widget)); GTKApplyStyle(child, style); #ifndef __WXGTK4__ wxGCC_WARNING_SUPPRESS(deprecated-declarations) // for buttons with images, the path to the label is (at least in 2.12) // GtkButton -> GtkAlignment -> GtkHBox -> GtkLabel if ( GTK_IS_ALIGNMENT(child) ) { GtkWidget* box = gtk_bin_get_child(GTK_BIN(child)); if ( GTK_IS_BOX(box) ) { wxGtkList list(gtk_container_get_children(GTK_CONTAINER(box))); for (GList* item = list; item; item = item->next) { GTKApplyStyle(GTK_WIDGET(item->data), style); } } } wxGCC_WARNING_RESTORE() #endif }
static SpiceUsbDevice *get_usb_device(GtkWidget *widget) { if (!GTK_IS_ALIGNMENT(widget)) return NULL; widget = gtk_bin_get_child(GTK_BIN(widget)); return g_object_get_data(G_OBJECT(widget), "usb-device"); }
static void fix_button_align (GtkWidget *button) { GtkWidget *child; child = gtk_bin_get_child (GTK_BIN (button)); if (GTK_IS_ALIGNMENT (child)) g_object_set (G_OBJECT (child), "xalign", 0.0, NULL); else if (GTK_IS_LABEL (child)) g_object_set (G_OBJECT (child), "xalign", 0.0, NULL); }
static gint get_n_labels_from_button (GtkWidget *button) { GtkWidget *child; gint n_labels; n_labels = 0; child = gtk_bin_get_child (GTK_BIN (button)); if (GTK_IS_ALIGNMENT (child)) child = gtk_bin_get_child (GTK_BIN (child)); if (GTK_IS_CONTAINER (child)) count_labels (GTK_CONTAINER (child), &n_labels); return n_labels; }
static GtkWidget * get_label_from_button (GtkWidget *button) { GtkWidget *child; child = gtk_bin_get_child (GTK_BIN (button)); G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (GTK_IS_ALIGNMENT (child)) child = gtk_bin_get_child (GTK_BIN (child)); G_GNUC_END_IGNORE_DEPRECATIONS if (GTK_IS_CONTAINER (child)) child = find_label_child (GTK_CONTAINER (child)); else if (!GTK_IS_LABEL (child)) child = NULL; return child; }
GtkLabel *wxButton::GTKGetLabel() const { GtkWidget* child = gtk_bin_get_child(GTK_BIN(m_widget)); if ( GTK_IS_ALIGNMENT(child) ) { GtkWidget* box = gtk_bin_get_child(GTK_BIN(child)); GtkLabel* label = NULL; wxGtkList list(gtk_container_get_children(GTK_CONTAINER(box))); for (GList* item = list; item; item = item->next) { if (GTK_IS_LABEL(item->data)) label = GTK_LABEL(item->data); } return label; } return GTK_LABEL(child); }
void wxToggleButton::DoApplyWidgetStyle(GtkRcStyle *style) { GTKApplyStyle(m_widget, style); GtkWidget* child = gtk_bin_get_child(GTK_BIN(m_widget)); GTKApplyStyle(child, style); // for buttons with images, the path to the label is (at least in 2.12) // GtkButton -> GtkAlignment -> GtkHBox -> GtkLabel if ( GTK_IS_ALIGNMENT(child) ) { GtkWidget* box = gtk_bin_get_child(GTK_BIN(child)); if ( GTK_IS_BOX(box) ) { wxGtkList list(gtk_container_get_children(GTK_CONTAINER(box))); for (GList* item = list; item; item = item->next) { GTKApplyStyle(GTK_WIDGET(item->data), style); } } } }
void wxButton::DoApplyWidgetStyle(GtkRcStyle *style) { gtk_widget_modify_style(m_widget, style); GtkWidget *child = GTK_BIN(m_widget)->child; gtk_widget_modify_style(child, style); // for buttons with images, the path to the label is (at least in 2.12) // GtkButton -> GtkAlignment -> GtkHBox -> GtkLabel if ( GTK_IS_ALIGNMENT(child) ) { GtkWidget *box = GTK_BIN(child)->child; if ( GTK_IS_BOX(box) ) { for (GList* item = GTK_BOX(box)->children; item; item = item->next) { GtkBoxChild* boxChild = static_cast<GtkBoxChild*>(item->data); gtk_widget_modify_style(boxChild->widget, style); } } } }
static GtkWidget* get_label_from_button (GtkWidget *button, gint index, gboolean allow_many) { GtkWidget *child; if (index > 0 && !allow_many) g_warning ("Inconsistent values passed to get_label_from_button"); child = gtk_bin_get_child (GTK_BIN (button)); if (GTK_IS_ALIGNMENT (child)) child = gtk_bin_get_child (GTK_BIN (child)); if (GTK_IS_CONTAINER (child)) child = find_label_child (GTK_CONTAINER (child), &index, allow_many); else if (!GTK_IS_LABEL (child)) child = NULL; return child; }
static int gtkButtonSetPaddingAttrib(Ihandle* ih, const char* value) { iupStrToIntInt(value, &ih->data->horiz_padding, &ih->data->vert_padding, 'x'); if (ih->handle) { if (ih->data->type == IUP_BUTTON_TEXT) /* text only */ { GtkMisc* misc = (GtkMisc*)gtk_bin_get_child((GtkBin*)ih->handle); gtk_misc_set_padding(misc, ih->data->horiz_padding, ih->data->vert_padding); } else { GtkAlignment* alignment = (GtkAlignment*)gtk_bin_get_child((GtkBin*)ih->handle); if (GTK_IS_ALIGNMENT(alignment)) gtk_alignment_set_padding(alignment, ih->data->vert_padding, ih->data->vert_padding, ih->data->horiz_padding, ih->data->horiz_padding); } return 0; } else return 1; /* store until not mapped, when mapped will be set again */ }
/** * he_check_button_set_alignment: * @button: a #HeCheckButton * @xalign: the horizontal alignment of the contents, from 0 (left) to 1 (right). * @yalign: the vertical alignment of the contents, from 0 (top) to 1 (bottom). * @xscale: the amount that the child widget expands horizontally to fill up unused space, from 0 to 1 * @yscale: the amount that the child widget expands vertically to fill up unused space, from 0 to 1 * * Sets the alignment of the contents of the widget. If you don't need * to change @xscale or @yscale you can just use * gtk_button_set_alignment() instead. * * Note that for this method to work properly, the child widget of * @button must be a #GtkAlignment. That's what #HeCheckButton uses by * default, so this function will work unless you add a custom widget * to @button. * * Since: 2.2 **/ void he_check_button_set_alignment (HeCheckButton *button, gfloat xalign, gfloat yalign, gfloat xscale, gfloat yscale) { HeCheckButtonPrivate *priv; GtkWidget *child; g_return_if_fail (HE_IS_CHECK_BUTTON (button)); priv = HE_CHECK_BUTTON_GET_PRIVATE (button); child = gtk_bin_get_child (GTK_BIN (button)); /* If the button has no child, use priv->alignment, which is the default one */ if (child == NULL) child = priv->alignment; if (GTK_IS_ALIGNMENT (child)) { gtk_alignment_set (GTK_ALIGNMENT (priv->alignment), xalign, yalign, xscale, yscale); } }
static AtkRelationSet * gtk_widget_accessible_ref_relation_set (AtkObject *obj) { GtkWidget *widget; AtkRelationSet *relation_set; GtkWidget *label; AtkObject *array[1]; AtkRelation* relation; widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); if (widget == NULL) return NULL; relation_set = ATK_OBJECT_CLASS (_gtk_widget_accessible_parent_class)->ref_relation_set (obj); if (GTK_IS_BOX (widget)) return relation_set; if (!atk_relation_set_contains (relation_set, ATK_RELATION_LABELLED_BY)) { label = find_label (widget); if (label == NULL) { if (GTK_IS_BUTTON (widget)) /* * Handle the case where GnomeIconEntry is the mnemonic widget. * The GtkButton which is a grandchild of the GnomeIconEntry * should really be the mnemonic widget. See bug #133967. */ { GtkWidget *temp_widget; temp_widget = gtk_widget_get_parent (widget); if (GTK_IS_ALIGNMENT (temp_widget)) { temp_widget = gtk_widget_get_parent (temp_widget); if (GTK_IS_BOX (temp_widget)) { label = find_label (temp_widget); if (!label) label = find_label (gtk_widget_get_parent (temp_widget)); } } } else if (GTK_IS_COMBO_BOX (widget)) /* * Handle the case when GtkFileChooserButton is the mnemonic * widget. The GtkComboBox which is a child of the * GtkFileChooserButton should be the mnemonic widget. * See bug #359843. */ { GtkWidget *temp_widget; temp_widget = gtk_widget_get_parent (widget); if (GTK_IS_BOX (temp_widget)) { label = find_label (temp_widget); } } } if (label) { array[0] = gtk_widget_get_accessible (label); relation = atk_relation_new (array, 1, ATK_RELATION_LABELLED_BY); atk_relation_set_add (relation_set, relation); g_object_unref (relation); } } return relation_set; }
AtkRelationSet* gail_label_ref_relation_set (AtkObject *obj) { GtkWidget *widget; AtkRelationSet *relation_set; g_return_val_if_fail (GAIL_IS_LABEL (obj), NULL); widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); if (widget == NULL) /* * State is defunct */ return NULL; relation_set = ATK_OBJECT_CLASS (gail_label_parent_class)->ref_relation_set (obj); if (!atk_relation_set_contains (relation_set, ATK_RELATION_LABEL_FOR)) { /* * Get the mnemonic widget * * The relation set is not updated if the mnemonic widget is changed */ GtkWidget *mnemonic_widget = gtk_label_get_mnemonic_widget (GTK_LABEL (widget)); if (mnemonic_widget) { AtkObject *accessible_array[1]; AtkRelation* relation; if (!gtk_widget_get_can_focus (mnemonic_widget)) { /* * Handle the case where a GtkFileChooserButton is specified as the * mnemonic widget. use the combobox which is a child of the * GtkFileChooserButton as the mnemonic widget. See bug #359843. */ if (GTK_IS_BOX (mnemonic_widget)) { GList *list, *tmpl; list = gtk_container_get_children (GTK_CONTAINER (mnemonic_widget)); if (g_list_length (list) == 2) { tmpl = g_list_last (list); if (GTK_IS_COMBO_BOX(tmpl->data)) { mnemonic_widget = GTK_WIDGET(tmpl->data); } } g_list_free (list); } /* * Handle the case where a GnomeIconEntry is specified as the * mnemonic widget. use the button which is a grandchild of the * GnomeIconEntry as the mnemonic widget. See bug #133967. */ else if (GTK_IS_BOX (mnemonic_widget)) { GList *list; list = gtk_container_get_children (GTK_CONTAINER (mnemonic_widget)); if (g_list_length (list) == 1) { if (GTK_IS_ALIGNMENT (list->data)) { GtkWidget *temp_widget; temp_widget = gtk_bin_get_child (GTK_BIN (list->data)); if (GTK_IS_BUTTON (temp_widget)) mnemonic_widget = temp_widget; } else if (GTK_IS_HBOX (list->data)) { GtkWidget *temp_widget; temp_widget = GTK_WIDGET (list->data); g_list_free (list); list = gtk_container_get_children (GTK_CONTAINER (temp_widget)); } } g_list_free (list); } } accessible_array[0] = gtk_widget_get_accessible (mnemonic_widget); relation = atk_relation_new (accessible_array, 1, ATK_RELATION_LABEL_FOR); atk_relation_set_add (relation_set, relation); /* * Unref the relation so that it is not leaked. */ g_object_unref (relation); } } return relation_set; }
/* Make the size of dialogs smaller by breaking GNOME HIG * http://library.gnome.org/devel/hig-book/stable/design-window.html.en * According to GNOME HIG, spacings are increased by the multiples of 6. * Change them to the multiples of 1 can greatly reduce the required size * while still keeping some degree of spacing. */ static void break_gnome_hig( GtkWidget* w, gpointer _factor ) { int factor = GPOINTER_TO_INT(_factor); /* g_debug( G_OBJECT_TYPE_NAME(w) ); */ if( GTK_IS_CONTAINER(w) ) { int val; val = gtk_container_get_border_width( (GtkContainer*)w ); /* border of dialog defaults to 12 under gnome */ if( GTK_IS_DIALOG(w) ) { if( val > 0 ) gtk_container_set_border_width( (GtkContainer*)w, val / factor ); } else { if( GTK_IS_BOX(w) ) /* boxes, spacing defaults to 6, 12, 18 under gnome */ { int spacing = gtk_box_get_spacing( (GtkBox*)w ); gtk_box_set_spacing( (GtkBox*)w, spacing / factor ); } else if( GTK_IS_TABLE(w) ) /* tables, spacing defaults to 6, 12, 18 under gnome */ { int spacing; int col, row; g_object_get( w, "n-columns", &col, "n-rows", &row, NULL ); if( col > 1 ) { --col; while( --col >= 0 ) { spacing = gtk_table_get_col_spacing( (GtkTable*)w, col ); if( spacing > 0 ) gtk_table_set_col_spacing( (GtkTable*)w, col, spacing / factor ); } } if( row > 1 ) { --row; while( --row >= 0 ) { spacing = gtk_table_get_row_spacing( (GtkTable*)w, row ); if( spacing > 0 ) gtk_table_set_row_spacing( (GtkTable*)w, row, spacing / factor ); } } /* FIXME: handle default spacings */ } else if( GTK_IS_ALIGNMENT(w) ) /* groups, has 12 px indent by default */ { int t, b, l, r; gtk_alignment_get_padding( (GtkAlignment*)w, &t, &b, &l, &r ); if( l > 0 ) { l /= (factor / 2); /* groups still need proper indent not to hurt usability */ gtk_alignment_set_padding( (GtkAlignment*)w, t, b, l, r ); } } if( val > 0 ) gtk_container_set_border_width( (GtkContainer*)w, val * 2 / factor ); } gtk_container_foreach( (GtkContainer*)w, break_gnome_hig, GINT_TO_POINTER(factor) ); } }
static G_CONST_RETURN gchar* gail_window_get_name (AtkObject *accessible) { G_CONST_RETURN gchar* name; name = ATK_OBJECT_CLASS (gail_window_parent_class)->get_name (accessible); if (name == NULL) { /* * Get the window title if it exists */ GtkWidget* widget = GTK_ACCESSIBLE (accessible)->widget; if (widget == NULL) /* * State is defunct */ return NULL; gail_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); if (GTK_IS_WINDOW (widget)) { GtkWindow *window = GTK_WINDOW (widget); name = gtk_window_get_title (window); if (name == NULL && accessible->role == ATK_ROLE_TOOL_TIP) { GtkWidget *child; child = gtk_bin_get_child (GTK_BIN (window)); /* could be some kind of egg notification bubble thingy? */ /* Handle new GTK+ GNOME 2.20 tooltips */ if (GTK_IS_ALIGNMENT(child)) { child = gtk_bin_get_child (GTK_BIN (child)); if (GTK_IS_BOX(child)) { GList *children; guint count; children = gtk_container_get_children (GTK_CONTAINER (child)); count = g_list_length (children); if (count == 2) { child = (GtkWidget *) g_list_nth_data (children, 1); } g_list_free (children); } } if (!GTK_IS_LABEL (child)) { g_message ("ATK_ROLE_TOOLTIP object found, but doesn't look like a tooltip."); return NULL; } name = gtk_label_get_text (GTK_LABEL (child)); } } } return name; }
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); }
static void gwy_graph_data_update_ncurves(GwyGraphData *graph_data) { GwyGraphDataCurve *curve; GtkTreeView *treeview; GtkTreeViewColumn *column; GtkWidget *table, *label; guint i, ncolumns, ncurves = 0; ncolumns = graph_data->curves->len; gwy_debug("old ncurves: %d", ncolumns); /* Reconnect all signals just to be sure. * GraphModel is a bit cagey when changes in its curves are regarded */ for (i = 0; i < graph_data->curves->len; i++) { curve = &g_array_index(graph_data->curves, GwyGraphDataCurve, i); gwy_signal_handler_disconnect(curve->gcmodel, curve->changed_id); gwy_object_unref(curve->gcmodel); } g_array_set_size(graph_data->curves, 0); if (graph_data->graph_model) { GwyGraphDataCurve newcurve; ncurves = gwy_graph_model_get_n_curves(graph_data->graph_model); for (i = 0; i < ncurves; i++) { newcurve.gcmodel = gwy_graph_model_get_curve(graph_data->graph_model, i); g_object_ref(newcurve.gcmodel); newcurve.changed_id = g_signal_connect_swapped (newcurve.gcmodel, "data-changed", G_CALLBACK(gwy_graph_data_update_nrows), graph_data); g_array_append_val(graph_data->curves, newcurve); } } gwy_debug("ncurves: %d", ncurves); /* Update the number of columns. */ treeview = GTK_TREE_VIEW(graph_data); while (ncolumns > ncurves) { ncolumns--; gwy_debug("removing column %d", ncolumns); column = gtk_tree_view_get_column(treeview, ncolumns); gtk_tree_view_remove_column(treeview, column); } while (ncolumns < ncurves) { GtkRequisition req; GtkWidget *align; gwy_debug("adding column %d", ncolumns); column = gtk_tree_view_column_new(); g_object_set_qdata(G_OBJECT(column), quark_id, GINT_TO_POINTER(ncolumns)); gwy_graph_data_pack_renderer(graph_data, column, 0); gwy_graph_data_pack_renderer(graph_data, column, 1); table = gtk_table_new(2, 2, TRUE); label = gtk_label_new(NULL); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 2, 0, 1); label = gtk_label_new(NULL); gtk_label_set_width_chars(GTK_LABEL(label), COL_WIDTH); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); label = gtk_label_new(NULL); gtk_label_set_width_chars(GTK_LABEL(label), COL_WIDTH); gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 1, 2); gtk_widget_show_all(table); gtk_tree_view_column_set_widget(column, table); gtk_widget_size_request(table, &req); g_object_set(column, "sizing", GTK_TREE_VIEW_COLUMN_FIXED, "fixed-width", req.width, NULL); gtk_tree_view_append_column(treeview, column); align = gtk_widget_get_parent(table); /* XXX: The alignment is Gtk+'s private widget. */ if (align && GTK_IS_ALIGNMENT(align)) { g_signal_connect(align, "notify::xscale", G_CALLBACK(fix_xscale), NULL); fix_xscale(align); } ncolumns++; } if (graph_data->graph_model) gwy_graph_data_update_headers(graph_data); if (graph_data->store) gwy_graph_data_update_nrows(graph_data); }
static GtkWidget* find_label_child (GtkContainer *container, gint *index, gboolean allow_many) { GList *children, *tmp_list; GtkWidget *child; children = gtk_container_get_children (container); child = NULL; for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next) { if (GTK_IS_LABEL (tmp_list->data)) { if (!allow_many) { if (child) { child = NULL; break; } child = GTK_WIDGET (tmp_list->data); } else { if (*index == 0) { child = GTK_WIDGET (tmp_list->data); break; } (*index)--; } } /* * Label for button which are GtkTreeView column headers are in a * GtkHBox in a GtkAlignment. */ else if (GTK_IS_ALIGNMENT (tmp_list->data)) { GtkWidget *widget; widget = gtk_bin_get_child (GTK_BIN (tmp_list->data)); if (GTK_IS_LABEL (widget)) { if (!allow_many) { if (child) { child = NULL; break; } child = widget; } else { if (*index == 0) { child = widget; break; } (*index)--; } } } else if (GTK_IS_CONTAINER (tmp_list->data)) { child = find_label_child (GTK_CONTAINER (tmp_list->data), index, allow_many); if (child) break; } } g_list_free (children); return child; }