static void attachment_button_update_cell_view (EAttachmentButton *button) { GtkCellView *cell_view; EAttachment *attachment; GtkTreeRowReference *reference; GtkTreeModel *model = NULL; GtkTreePath *path = NULL; cell_view = GTK_CELL_VIEW (button->priv->cell_view); attachment = e_attachment_button_get_attachment (button); if (attachment == NULL) goto exit; reference = e_attachment_get_reference (attachment); if (reference == NULL) goto exit; model = gtk_tree_row_reference_get_model (reference); path = gtk_tree_row_reference_get_path (reference); exit: gtk_cell_view_set_model (cell_view, model); if (model) gtk_cell_view_set_displayed_row (cell_view, path); if (path != NULL) gtk_tree_path_free (path); }
/** * Initialize the head cellview, create list store and set the cell renderers. */ static void cell_view_init(HybridHead *head) { GtkListStore *store; GtkCellRenderer *renderer; GtkTreePath *path; g_return_if_fail(head != NULL); store = gtk_list_store_new(HYBRID_HEAD_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, GDK_TYPE_PIXBUF); gtk_cell_view_set_model(GTK_CELL_VIEW(head->cellview), GTK_TREE_MODEL(store)); g_object_unref(store); /* buddy icon renderer */ renderer = gtk_cell_renderer_pixbuf_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(head->cellview), renderer, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(head->cellview), renderer, "pixbuf", HYBRID_HEAD_PIXBUF_COLUMN, NULL); g_object_set(renderer, "yalign", 0.5, "xpad", 3, "ypad", 0, NULL); /* buddy name renderer */ renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(head->cellview), renderer, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(head->cellview), renderer, "markup", HYBRID_HEAD_NAME_COLUMN, NULL); g_object_set(renderer, "xalign", 0.0, "yalign", 0.0, "xpad", 6, "ypad", 0, NULL); g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); /* status icon renderer */ renderer = gtk_cell_renderer_pixbuf_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(head->cellview), renderer, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(head->cellview), renderer, "pixbuf", HYBRID_HEAD_STATUS_ICON_COLUMN, NULL); g_object_set(renderer, "yalign", 0.5, "xpad", 10, "ypad", 0, NULL); gtk_list_store_append(store, &head->iter); path = gtk_tree_path_new_from_string("0"); gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(head->cellview), path); gtk_tree_path_free(path); }
static void gtk_cell_view_dispose (GObject *object) { GtkCellView *cellview = GTK_CELL_VIEW (object); gtk_cell_view_set_model (cellview, NULL); if (cellview->priv->area) { g_object_unref (cellview->priv->area); cellview->priv->area = NULL; } if (cellview->priv->context) { g_signal_handler_disconnect (cellview->priv->context, cellview->priv->size_changed_id); g_object_unref (cellview->priv->context); cellview->priv->context = NULL; cellview->priv->size_changed_id = 0; } G_OBJECT_CLASS (gtk_cell_view_parent_class)->dispose (object); }
static void gtk_cell_view_set_property (GObject *object, guint param_id, const GValue *value, GParamSpec *pspec) { GtkCellView *view = GTK_CELL_VIEW (object); GtkCellViewPrivate *priv = view->priv; GtkCellArea *area; GtkCellAreaContext *context; switch (param_id) { case PROP_ORIENTATION: priv->orientation = g_value_get_enum (value); if (priv->context) gtk_cell_area_context_reset (priv->context); _gtk_orientable_set_style_classes (GTK_ORIENTABLE (object)); break; case PROP_BACKGROUND: { GdkColor color; if (!g_value_get_string (value)) gtk_cell_view_set_background_color (view, NULL); else if (gdk_color_parse (g_value_get_string (value), &color)) gtk_cell_view_set_background_color (view, &color); else g_warning ("Don't know color `%s'", g_value_get_string (value)); g_object_notify (object, "background-gdk"); } break; case PROP_BACKGROUND_GDK: gtk_cell_view_set_background_color (view, g_value_get_boxed (value)); break; case PROP_BACKGROUND_RGBA: gtk_cell_view_set_background_rgba (view, g_value_get_boxed (value)); break; case PROP_BACKGROUND_SET: view->priv->background_set = g_value_get_boolean (value); break; case PROP_MODEL: gtk_cell_view_set_model (view, g_value_get_object (value)); break; case PROP_CELL_AREA: /* Construct-only, can only be assigned once */ area = g_value_get_object (value); if (area) { if (priv->area != NULL) { g_warning ("cell-area has already been set, ignoring construct property"); g_object_ref_sink (area); g_object_unref (area); } else priv->area = g_object_ref_sink (area); } break; case PROP_CELL_AREA_CONTEXT: /* Construct-only, can only be assigned once */ context = g_value_get_object (value); if (context) { if (priv->context != NULL) { g_warning ("cell-area-context has already been set, ignoring construct property"); g_object_ref_sink (context); g_object_unref (context); } else priv->context = g_object_ref (context); } break; case PROP_DRAW_SENSITIVE: gtk_cell_view_set_draw_sensitive (view, g_value_get_boolean (value)); break; case PROP_FIT_MODEL: gtk_cell_view_set_fit_model (view, g_value_get_boolean (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; } }
/** * Create the buddy tips panel. We implement it with GtkCellView. * The layout is: * * ----------------------------------------------------- * | | Name | Proto | Status | * | Icon |--------------(markup)-| Icon | Icon | * | (32×32) | Mood phrase | (16×16)| (16×16)| * ----------------------------------------------------- */ static void create_buddy_tips_panel(GtkWidget *vbox, HybridChatWindow *chat) { GtkWidget *cellview; GtkListStore *store; GtkCellRenderer *renderer; GtkTreePath *path; HybridAccount *account; HybridModule *proto; HybridBuddy *buddy; gchar *name_text; gchar *mood_text; GdkPixbuf *icon_pixbuf; GdkPixbuf *proto_pixbuf; GdkPixbuf *presence_pixbuf; GtkWidget *eventbox; g_return_if_fail(vbox != NULL); cellview = gtk_cell_view_new(); store = gtk_list_store_new(LABEL_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, GDK_TYPE_PIXBUF, GDK_TYPE_PIXBUF); gtk_cell_view_set_model(GTK_CELL_VIEW(cellview), GTK_TREE_MODEL(store)); /* * GtkCellView doesn't have a GdkWindow, we wrap it with an EventBox, * and then setup tooltip on the EventBox. */ eventbox = gtk_event_box_new(); gtk_event_box_set_visible_window(GTK_EVENT_BOX(eventbox), FALSE); gtk_container_add(GTK_CONTAINER(eventbox), cellview); /* buddy icon renderer */ renderer = gtk_cell_renderer_pixbuf_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cellview), renderer, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cellview), renderer, "pixbuf", BUDDY_ICON_COLUMN, NULL); g_object_set(renderer, "yalign", 0.5, "xpad", 3, "ypad", 0, NULL); /* buddy name renderer */ renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cellview), renderer, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cellview), renderer, "markup", BUDDY_NAME_COLUMN, NULL); g_object_set(renderer, "xalign", 0.0, "xpad", 6, "ypad", 0, NULL); g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); /* protocol icon renderer */ renderer = gtk_cell_renderer_pixbuf_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cellview), renderer, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cellview), renderer, "pixbuf", BUDDY_PROTO_ICON_COLUMN, NULL); g_object_set(renderer, "xalign", 0.0, "xpad", 6, "ypad", 0, NULL); /* status icon renderer */ renderer = gtk_cell_renderer_pixbuf_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cellview), renderer, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cellview), renderer, "pixbuf", BUDDY_STATUS_ICON_COLUMN, NULL); g_object_set(renderer, "xalign", 0.0, "xpad", 6, "ypad", 0, NULL); gtk_list_store_append(store, &chat->tipiter); path = gtk_tree_path_new_from_string("0"); gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(cellview), path); gtk_tree_path_free(path); chat->tiplabel = cellview; if (IS_SYSTEM_CHAT(chat)) { buddy = chat->data; hybrid_tooltip_setup(eventbox, NULL, NULL, init_tooltip, buddy); icon_pixbuf = hybrid_create_round_pixbuf(buddy->icon_data, buddy->icon_data_length, 32); presence_pixbuf = hybrid_create_presence_pixbuf(buddy->state, 16); mood_text = g_markup_escape_text(buddy->mood ? buddy->mood : "", -1); name_text = g_strdup_printf( "<b>%s</b>\n<small><span font=\"#8f8f8f\">%s</span></small>", buddy->name && *(buddy->name) != '\0' ? buddy->name : buddy->id, mood_text); gtk_list_store_set(store, &chat->tipiter, BUDDY_ICON_COLUMN, icon_pixbuf, BUDDY_NAME_COLUMN, name_text, BUDDY_STATUS_ICON_COLUMN, presence_pixbuf, -1); g_object_unref(icon_pixbuf); g_object_unref(presence_pixbuf); g_free(name_text); g_free(mood_text); } account = chat->account; proto = account->proto; proto_pixbuf = hybrid_create_proto_icon(proto->info->name, 16); gtk_list_store_set(store, &chat->tipiter, BUDDY_PROTO_ICON_COLUMN, proto_pixbuf, -1); g_object_unref(proto_pixbuf); gtk_box_pack_start(GTK_BOX(vbox), eventbox, FALSE, FALSE, 5); }
/** * Create the tab label widget for the GtkNotebook. * The layout is: * * ----------------------------------------------------- * | Status | | Close Button | * | Icon | buddy name (markup) | | * | (16×16) | | (16×16) | * ----------------------------------------------------- * |- GtkEventBox -> GtkCellView -|--- GtkEventBox ---| */ static GtkWidget* create_note_label(HybridChatWindow *chat) { GtkWidget *hbox; GtkWidget *eventbox; GtkWidget *close_image; GtkWidget *label; GtkListStore *store; GtkCellRenderer *renderer; GtkTreePath *path; HybridBuddy *buddy; GdkPixbuf *icon_pixbuf; g_return_val_if_fail(chat != NULL, NULL); hbox = gtk_hbox_new(FALSE, 0); label = gtk_cell_view_new(); store = gtk_list_store_new(TAB_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING); gtk_cell_view_set_model(GTK_CELL_VIEW(label), GTK_TREE_MODEL(store)); g_object_unref(store); /* buddy icon renderer */ renderer = gtk_cell_renderer_pixbuf_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(label), renderer, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(label), renderer, "pixbuf", TAB_STATUS_ICON_COLUMN, NULL); g_object_set(renderer, "yalign", 0.5, "xpad", 3, "ypad", 0, NULL); /* buddy name renderer */ renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(label), renderer, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(label), renderer, "markup", TAB_NAME_COLUMN, NULL); g_object_set(renderer, "xalign", 0.5, "xpad", 6, "ypad", 0, NULL); g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); chat->tablabel = label; gtk_list_store_append(store, &chat->tabiter); path = gtk_tree_path_new_from_string("0"); gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(label), path); gtk_tree_path_free(path); if (IS_SYSTEM_CHAT(chat)) { buddy = chat->data; icon_pixbuf = hybrid_create_presence_pixbuf(buddy->state, 16); gtk_list_store_set(store, &chat->tabiter, TAB_STATUS_ICON_COLUMN, icon_pixbuf, TAB_NAME_COLUMN, buddy->name && *(buddy->name) != '\0' ? buddy->name : buddy->id, -1); g_object_unref(icon_pixbuf); } eventbox = gtk_event_box_new(); gtk_event_box_set_visible_window(GTK_EVENT_BOX(eventbox), FALSE); gtk_container_add(GTK_CONTAINER(eventbox), label); gtk_box_pack_start(GTK_BOX(hbox), eventbox, TRUE, TRUE, 0); gtk_widget_add_events(eventbox, GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK); g_signal_connect(G_OBJECT(eventbox), "button-press-event", G_CALLBACK(tab_press_cb), chat); /* close button */ eventbox = gtk_event_box_new(); gtk_event_box_set_visible_window(GTK_EVENT_BOX(eventbox), FALSE); close_image = gtk_image_new_from_file(PIXMAPS_DIR"menus/close.png"); g_signal_connect(G_OBJECT(eventbox), "button-press-event", G_CALLBACK(tab_close_press_cb), chat); gtk_container_add(GTK_CONTAINER(eventbox), close_image); gtk_box_pack_start(GTK_BOX(hbox), eventbox, FALSE, FALSE, 0); gtk_widget_show_all(hbox); return hbox; }
int main (int argc, char **argv) { GtkWidget *window, *cellview, *mainbox; GtkWidget *combobox, *comboboxtext, *comboboxgrid; GtkWidget *tmp, *boom; GtkCellRenderer *renderer; GtkTreeModel *model; GtkTreePath *path; GtkTreeIter iter; GdkRGBA color; GtkCellArea *area; gchar *text; gint i; gtk_init (&argc, &argv); if (g_getenv ("RTL")) gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL); if (g_getenv ("LISTMODE")) { GtkCssProvider *provider = gtk_css_provider_new (); gtk_css_provider_load_from_data (provider, "* { -GtkComboBox-appears-as-list: true; }", -1, NULL); gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_FALLBACK); } window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (window), 5); g_signal_connect (window, "destroy", gtk_main_quit, NULL); mainbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_container_add (GTK_CONTAINER (window), mainbox); /* GtkCellView */ tmp = gtk_frame_new ("GtkCellView"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); cellview = gtk_cell_view_new (); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview), renderer, FALSE); g_object_set (renderer, "icon-name", "dialog-warning", NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview), renderer, TRUE); g_object_set (renderer, "text", "la la la", NULL); gtk_container_add (GTK_CONTAINER (boom), cellview); /* GtkComboBox list */ tmp = gtk_frame_new ("GtkComboBox (list)"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_list_blaat (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "icon-name", 0, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); /* GtkComboBox dynamic list */ tmp = gtk_frame_new ("GtkComboBox (dynamic list)"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_empty_list_blaat (); combobox = gtk_combo_box_new_with_model (model); g_signal_connect (combobox, "notify::popup-shown", G_CALLBACK (populate_list_blaat), combobox); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "icon-name", 0, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); /* GtkComboBox custom entry */ tmp = gtk_frame_new ("GtkComboBox (custom)"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_list_blaat (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "icon-name", 0, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); tmp = gtk_cell_view_new (); gtk_widget_show (tmp); gtk_cell_view_set_model (GTK_CELL_VIEW (tmp), model); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (tmp), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (tmp), renderer, "text", 1, NULL); color.red = 1.0; color.blue = 1.0; color.green = 0; color.alpha = 1.0; gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (tmp), &color); displayed_row_changed (GTK_COMBO_BOX (combobox), GTK_CELL_VIEW (tmp)); g_signal_connect (combobox, "changed", G_CALLBACK (displayed_row_changed), tmp); gtk_container_add (GTK_CONTAINER (combobox), tmp); /* GtkComboBox tree */ tmp = gtk_frame_new ("GtkComboBox (tree)"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_tree_blaat (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "icon-name", 0, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); #if 0 g_timeout_add (1000, (GSourceFunc) animation_timer, model); #endif /* GtkComboBox (grid mode) */ tmp = gtk_frame_new ("GtkComboBox (grid mode)"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); comboboxgrid = create_combo_box_grid_demo (); gtk_box_pack_start (GTK_BOX (boom), comboboxgrid, FALSE, FALSE, 0); /* GtkComboBoxEntry */ tmp = gtk_frame_new ("GtkComboBox with entry"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); comboboxtext = gtk_combo_box_text_new_with_entry (); setup_combo_entry (GTK_COMBO_BOX_TEXT (comboboxtext)); gtk_container_add (GTK_CONTAINER (boom), comboboxtext); /* Phylogenetic tree */ tmp = gtk_frame_new ("What are you ?"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_phylogenetic_tree (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); /* Capitals */ tmp = gtk_frame_new ("Where are you ?"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_capital_tree (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, capital_sensitive, NULL, NULL); path = gtk_tree_path_new_from_indices (0, 8, -1); gtk_tree_model_get_iter (model, &iter, path); gtk_tree_path_free (path); gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter); #if 1 gdk_threads_add_timeout (1000, (GSourceFunc) capital_animation, model); #endif /* Aligned Food */ tmp = gtk_frame_new ("Hungry ?"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_food_list (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (combobox)); renderer = gtk_cell_renderer_text_new (); gtk_cell_area_add_with_properties (area, renderer, "align", TRUE, "expand", TRUE, NULL); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_area_add_with_properties (area, renderer, "align", TRUE, "expand", TRUE, NULL); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); /* Ellipsizing growing combos */ tmp = gtk_frame_new ("Unconstrained Menu"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_list_long (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_text_new (); g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); gtk_combo_box_set_popup_fixed_width (GTK_COMBO_BOX (combobox), FALSE); tmp = gtk_frame_new ("Looong"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); combobox = gtk_combo_box_text_new (); for (i = 0; i < 200; i++) { text = g_strdup_printf ("Item %d", i); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combobox), text); g_free (text); } gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 53); gtk_container_add (GTK_CONTAINER (tmp), combobox); gtk_widget_show_all (window); gtk_main (); return 0; }