2010-11-08 16:26:38 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
/*******************************************************
|
|
|
|
* Simple Test *
|
|
|
|
*******************************************************/
|
2010-11-08 16:26:38 +00:00
|
|
|
enum {
|
|
|
|
SIMPLE_COLUMN_NAME,
|
|
|
|
SIMPLE_COLUMN_ICON,
|
|
|
|
SIMPLE_COLUMN_DESCRIPTION,
|
|
|
|
N_SIMPLE_COLUMNS
|
|
|
|
};
|
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
static GtkCellRenderer *cell_1 = NULL, *cell_2 = NULL, *cell_3 = NULL;
|
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
static GtkTreeModel *
|
|
|
|
simple_list_model (void)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store =
|
|
|
|
gtk_list_store_new (N_SIMPLE_COLUMNS,
|
|
|
|
G_TYPE_STRING, /* name text */
|
|
|
|
G_TYPE_STRING, /* icon name */
|
|
|
|
G_TYPE_STRING); /* description text */
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
SIMPLE_COLUMN_NAME, "Alice in wonderland",
|
2013-06-24 21:31:22 +00:00
|
|
|
SIMPLE_COLUMN_ICON, "system-run",
|
2010-11-08 16:26:38 +00:00
|
|
|
SIMPLE_COLUMN_DESCRIPTION,
|
2010-11-13 06:09:36 +00:00
|
|
|
"Twas brillig, and the slithy toves "
|
|
|
|
"did gyre and gimble in the wabe; "
|
|
|
|
"all mimsy were the borogoves, "
|
|
|
|
"and the mome raths outgrabe",
|
2010-11-08 16:26:38 +00:00
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
SIMPLE_COLUMN_NAME, "Marry Poppins",
|
2013-06-24 21:31:22 +00:00
|
|
|
SIMPLE_COLUMN_ICON, "dialog-information",
|
2010-11-08 16:26:38 +00:00
|
|
|
SIMPLE_COLUMN_DESCRIPTION, "Supercalifragilisticexpialidocious",
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
SIMPLE_COLUMN_NAME, "George Bush",
|
2013-06-24 21:31:22 +00:00
|
|
|
SIMPLE_COLUMN_ICON, "dialog-warning",
|
2010-11-13 06:09:36 +00:00
|
|
|
SIMPLE_COLUMN_DESCRIPTION, "It's a very good question, very direct, "
|
|
|
|
"and I'm not going to answer it",
|
2010-11-08 16:26:38 +00:00
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
SIMPLE_COLUMN_NAME, "Whinnie the pooh",
|
2013-06-24 21:31:22 +00:00
|
|
|
SIMPLE_COLUMN_ICON, "process-stop",
|
2010-11-08 16:26:38 +00:00
|
|
|
SIMPLE_COLUMN_DESCRIPTION, "The most wonderful thing about tiggers, "
|
|
|
|
"is tiggers are wonderful things",
|
|
|
|
-1);
|
|
|
|
|
2010-11-13 06:09:36 +00:00
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
SIMPLE_COLUMN_NAME, "Aleister Crowley",
|
2013-06-24 21:31:22 +00:00
|
|
|
SIMPLE_COLUMN_ICON, "help-about",
|
2010-11-13 06:09:36 +00:00
|
|
|
SIMPLE_COLUMN_DESCRIPTION,
|
|
|
|
"Thou shalt do what thou wilt shall be the whole of the law",
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
SIMPLE_COLUMN_NAME, "Mark Twain",
|
2013-06-24 21:31:22 +00:00
|
|
|
SIMPLE_COLUMN_ICON, "application-exit",
|
2010-11-13 06:09:36 +00:00
|
|
|
SIMPLE_COLUMN_DESCRIPTION,
|
|
|
|
"Giving up smoking is the easiest thing in the world. "
|
|
|
|
"I know because I've done it thousands of times.",
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
return (GtkTreeModel *)store;
|
|
|
|
}
|
|
|
|
|
2010-11-09 04:23:12 +00:00
|
|
|
static GtkWidget *
|
2012-05-05 03:39:58 +00:00
|
|
|
simple_iconview (void)
|
2010-11-08 16:26:38 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkWidget *iconview;
|
2010-11-08 16:26:38 +00:00
|
|
|
GtkCellArea *area;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
iconview = gtk_icon_view_new ();
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
model = simple_list_model ();
|
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
gtk_icon_view_set_model (GTK_ICON_VIEW (iconview), model);
|
|
|
|
gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (iconview), GTK_ORIENTATION_HORIZONTAL);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
cell_1 = renderer = gtk_cell_renderer_text_new ();
|
2010-12-21 12:11:01 +00:00
|
|
|
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, FALSE, FALSE, FALSE);
|
2010-11-08 16:26:38 +00:00
|
|
|
gtk_cell_area_attribute_connect (area, renderer, "text", SIMPLE_COLUMN_NAME);
|
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
cell_2 = renderer = gtk_cell_renderer_pixbuf_new ();
|
2010-11-08 16:26:38 +00:00
|
|
|
g_object_set (G_OBJECT (renderer), "xalign", 0.0F, NULL);
|
2010-12-21 12:11:01 +00:00
|
|
|
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, TRUE, FALSE, FALSE);
|
2013-06-24 21:31:22 +00:00
|
|
|
gtk_cell_area_attribute_connect (area, renderer, "icon-name", SIMPLE_COLUMN_ICON);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
cell_3 = renderer = gtk_cell_renderer_text_new ();
|
2010-11-08 16:26:38 +00:00
|
|
|
g_object_set (G_OBJECT (renderer),
|
|
|
|
"wrap-mode", PANGO_WRAP_WORD,
|
|
|
|
"wrap-width", 215,
|
|
|
|
NULL);
|
2010-12-21 12:11:01 +00:00
|
|
|
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, FALSE, TRUE, FALSE);
|
2010-11-08 16:26:38 +00:00
|
|
|
gtk_cell_area_attribute_connect (area, renderer, "text", SIMPLE_COLUMN_DESCRIPTION);
|
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
return iconview;
|
2010-11-09 04:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
orientation_changed (GtkComboBox *combo,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-09 04:23:12 +00:00
|
|
|
{
|
|
|
|
GtkOrientation orientation = gtk_combo_box_get_active (combo);
|
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
gtk_icon_view_set_item_orientation (iconview, orientation);
|
2010-11-09 04:23:12 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
static void
|
|
|
|
align_cell_2_toggled (GtkToggleButton *toggle,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-09 04:50:53 +00:00
|
|
|
{
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
|
2010-11-09 04:50:53 +00:00
|
|
|
gboolean align = gtk_toggle_button_get_active (toggle);
|
|
|
|
|
|
|
|
gtk_cell_area_cell_set (area, cell_2, "align", align, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
align_cell_3_toggled (GtkToggleButton *toggle,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-09 04:50:53 +00:00
|
|
|
{
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
|
2010-11-09 04:50:53 +00:00
|
|
|
gboolean align = gtk_toggle_button_get_active (toggle);
|
|
|
|
|
|
|
|
gtk_cell_area_cell_set (area, cell_3, "align", align, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
expand_cell_1_toggled (GtkToggleButton *toggle,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-09 04:50:53 +00:00
|
|
|
{
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
|
2010-11-09 04:50:53 +00:00
|
|
|
gboolean expand = gtk_toggle_button_get_active (toggle);
|
|
|
|
|
|
|
|
gtk_cell_area_cell_set (area, cell_1, "expand", expand, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
expand_cell_2_toggled (GtkToggleButton *toggle,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-09 04:50:53 +00:00
|
|
|
{
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
|
2010-11-09 04:50:53 +00:00
|
|
|
gboolean expand = gtk_toggle_button_get_active (toggle);
|
|
|
|
|
|
|
|
gtk_cell_area_cell_set (area, cell_2, "expand", expand, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
expand_cell_3_toggled (GtkToggleButton *toggle,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-09 04:50:53 +00:00
|
|
|
{
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
|
2010-11-09 04:50:53 +00:00
|
|
|
gboolean expand = gtk_toggle_button_get_active (toggle);
|
|
|
|
|
|
|
|
gtk_cell_area_cell_set (area, cell_3, "expand", expand, NULL);
|
|
|
|
}
|
|
|
|
|
2010-11-09 04:23:12 +00:00
|
|
|
static void
|
|
|
|
simple_cell_area (void)
|
|
|
|
{
|
|
|
|
GtkWidget *window, *widget;
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkWidget *iconview, *frame, *vbox, *hbox;
|
2010-11-09 04:23:12 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2010-11-09 04:23:12 +00:00
|
|
|
|
2010-11-12 12:55:28 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "CellArea expand and alignments");
|
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
iconview = simple_iconview ();
|
2010-11-09 04:23:12 +00:00
|
|
|
|
2011-04-22 13:38:40 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
2010-11-08 16:26:38 +00:00
|
|
|
frame = gtk_frame_new (NULL);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (frame, TRUE);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-11-09 04:23:12 +00:00
|
|
|
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
|
2010-11-09 04:50:53 +00:00
|
|
|
gtk_widget_set_halign (frame, GTK_ALIGN_FILL);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), iconview);
|
2010-11-09 04:23:12 +00:00
|
|
|
|
|
|
|
/* Now add some controls */
|
2011-04-22 13:38:40 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox);
|
2018-12-26 07:20:34 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), frame);
|
2010-11-09 04:23:12 +00:00
|
|
|
|
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Horizontal");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Vertical");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), widget);
|
2010-11-09 04:23:12 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (orientation_changed), iconview);
|
2010-11-09 04:23:12 +00:00
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
widget = gtk_check_button_new_with_label ("Align 2nd Cell");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), widget);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
g_signal_connect (G_OBJECT (widget), "toggled",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (align_cell_2_toggled), iconview);
|
2010-11-09 04:50:53 +00:00
|
|
|
|
|
|
|
widget = gtk_check_button_new_with_label ("Align 3rd Cell");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), widget);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
g_signal_connect (G_OBJECT (widget), "toggled",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (align_cell_3_toggled), iconview);
|
2010-11-09 04:50:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
widget = gtk_check_button_new_with_label ("Expand 1st Cell");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), widget);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
g_signal_connect (G_OBJECT (widget), "toggled",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (expand_cell_1_toggled), iconview);
|
2010-11-09 04:50:53 +00:00
|
|
|
|
|
|
|
widget = gtk_check_button_new_with_label ("Expand 2nd Cell");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), widget);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
g_signal_connect (G_OBJECT (widget), "toggled",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (expand_cell_2_toggled), iconview);
|
2010-11-09 04:50:53 +00:00
|
|
|
|
|
|
|
widget = gtk_check_button_new_with_label ("Expand 3rd Cell");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), widget);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2010-11-09 04:50:53 +00:00
|
|
|
g_signal_connect (G_OBJECT (widget), "toggled",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (expand_cell_3_toggled), iconview);
|
2010-11-09 04:23:12 +00:00
|
|
|
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), hbox);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
gtk_widget_show (window);
|
|
|
|
}
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
/*******************************************************
|
|
|
|
* Focus Test *
|
|
|
|
*******************************************************/
|
2010-11-11 07:13:06 +00:00
|
|
|
static GtkCellRenderer *focus_renderer, *sibling_renderer;
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
enum {
|
|
|
|
FOCUS_COLUMN_NAME,
|
|
|
|
FOCUS_COLUMN_CHECK,
|
|
|
|
FOCUS_COLUMN_STATIC_TEXT,
|
|
|
|
N_FOCUS_COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkTreeModel *
|
|
|
|
focus_list_model (void)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store =
|
|
|
|
gtk_list_store_new (N_FOCUS_COLUMNS,
|
|
|
|
G_TYPE_STRING, /* name text */
|
|
|
|
G_TYPE_BOOLEAN, /* check */
|
|
|
|
G_TYPE_STRING); /* static text */
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
FOCUS_COLUMN_NAME, "Enter a string",
|
|
|
|
FOCUS_COLUMN_CHECK, TRUE,
|
|
|
|
FOCUS_COLUMN_STATIC_TEXT, "Does it fly ?",
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
FOCUS_COLUMN_NAME, "Enter a string",
|
|
|
|
FOCUS_COLUMN_CHECK, FALSE,
|
|
|
|
FOCUS_COLUMN_STATIC_TEXT, "Would you put it in a toaster ?",
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
FOCUS_COLUMN_NAME, "Type something",
|
|
|
|
FOCUS_COLUMN_CHECK, FALSE,
|
|
|
|
FOCUS_COLUMN_STATIC_TEXT, "Does it feed on cute kittens ?",
|
|
|
|
-1);
|
|
|
|
|
|
|
|
return (GtkTreeModel *)store;
|
|
|
|
}
|
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
static void
|
|
|
|
cell_toggled (GtkCellRendererToggle *cell_renderer,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *path,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-10 13:25:13 +00:00
|
|
|
{
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkTreeModel *model = gtk_icon_view_get_model (iconview);
|
2010-11-10 13:25:13 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean active;
|
|
|
|
|
|
|
|
g_print ("Cell toggled !\n");
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter_from_string (model, &iter, path))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter, FOCUS_COLUMN_CHECK, &active, -1);
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter, FOCUS_COLUMN_CHECK, !active, -1);
|
|
|
|
}
|
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
static void
|
|
|
|
cell_edited (GtkCellRendererToggle *cell_renderer,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *path,
|
|
|
|
const char *new_text,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-12 10:25:07 +00:00
|
|
|
{
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkTreeModel *model = gtk_icon_view_get_model (iconview);
|
2010-11-12 10:25:07 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
g_print ("Cell edited with new text '%s' !\n", new_text);
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter_from_string (model, &iter, path))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter, FOCUS_COLUMN_NAME, new_text, -1);
|
|
|
|
}
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
static GtkWidget *
|
2012-05-05 03:39:58 +00:00
|
|
|
focus_iconview (gboolean color_bg, GtkCellRenderer **focus, GtkCellRenderer **sibling)
|
2010-11-10 10:17:06 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkWidget *iconview;
|
2010-11-10 10:17:06 +00:00
|
|
|
GtkCellArea *area;
|
2010-11-12 14:09:57 +00:00
|
|
|
GtkCellRenderer *renderer, *toggle;
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
iconview = gtk_icon_view_new ();
|
2010-11-10 10:17:06 +00:00
|
|
|
|
|
|
|
model = focus_list_model ();
|
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
gtk_icon_view_set_model (GTK_ICON_VIEW (iconview), model);
|
|
|
|
gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (iconview), GTK_ORIENTATION_HORIZONTAL);
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
|
2010-11-10 10:17:06 +00:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
g_object_set (G_OBJECT (renderer), "editable", TRUE, NULL);
|
2010-12-21 12:11:01 +00:00
|
|
|
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, TRUE, FALSE, FALSE);
|
2010-11-10 10:17:06 +00:00
|
|
|
gtk_cell_area_attribute_connect (area, renderer, "text", FOCUS_COLUMN_NAME);
|
|
|
|
|
2010-11-12 12:55:28 +00:00
|
|
|
if (color_bg)
|
|
|
|
g_object_set (G_OBJECT (renderer), "cell-background", "red", NULL);
|
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
g_signal_connect (G_OBJECT (renderer), "edited",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (cell_edited), iconview);
|
2010-11-12 10:25:07 +00:00
|
|
|
|
2010-11-12 14:09:57 +00:00
|
|
|
toggle = renderer = gtk_cell_renderer_toggle_new ();
|
2010-11-10 10:17:06 +00:00
|
|
|
g_object_set (G_OBJECT (renderer), "xalign", 0.0F, NULL);
|
2010-12-21 12:11:01 +00:00
|
|
|
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, FALSE, TRUE, FALSE);
|
2010-11-10 10:17:06 +00:00
|
|
|
gtk_cell_area_attribute_connect (area, renderer, "active", FOCUS_COLUMN_CHECK);
|
|
|
|
|
2010-11-12 12:55:28 +00:00
|
|
|
if (color_bg)
|
|
|
|
g_object_set (G_OBJECT (renderer), "cell-background", "green", NULL);
|
2010-11-13 06:09:36 +00:00
|
|
|
|
|
|
|
if (focus)
|
|
|
|
*focus = renderer;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
g_signal_connect (G_OBJECT (renderer), "toggled",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (cell_toggled), iconview);
|
2010-11-10 13:25:13 +00:00
|
|
|
|
2010-11-12 14:09:57 +00:00
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
2010-11-10 10:17:06 +00:00
|
|
|
g_object_set (G_OBJECT (renderer),
|
|
|
|
"wrap-mode", PANGO_WRAP_WORD,
|
|
|
|
"wrap-width", 150,
|
|
|
|
NULL);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
if (color_bg)
|
|
|
|
g_object_set (G_OBJECT (renderer), "cell-background", "blue", NULL);
|
2010-11-13 06:09:36 +00:00
|
|
|
|
|
|
|
if (sibling)
|
|
|
|
*sibling = renderer;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, FALSE, TRUE, FALSE);
|
2010-11-10 10:17:06 +00:00
|
|
|
gtk_cell_area_attribute_connect (area, renderer, "text", FOCUS_COLUMN_STATIC_TEXT);
|
|
|
|
|
2010-11-12 14:09:57 +00:00
|
|
|
gtk_cell_area_add_focus_sibling (area, toggle, renderer);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
return iconview;
|
2010-11-10 10:17:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 07:13:06 +00:00
|
|
|
static void
|
|
|
|
focus_sibling_toggled (GtkToggleButton *toggle,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-11 07:13:06 +00:00
|
|
|
{
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
|
2010-11-11 07:13:06 +00:00
|
|
|
gboolean active = gtk_toggle_button_get_active (toggle);
|
|
|
|
|
|
|
|
if (active)
|
|
|
|
gtk_cell_area_add_focus_sibling (area, focus_renderer, sibling_renderer);
|
|
|
|
else
|
|
|
|
gtk_cell_area_remove_focus_sibling (area, focus_renderer, sibling_renderer);
|
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (iconview));
|
2010-11-11 07:13:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
focus_cell_area (void)
|
|
|
|
{
|
|
|
|
GtkWidget *window, *widget;
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkWidget *iconview, *frame, *vbox, *hbox;
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2011-04-22 13:38:40 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2010-11-12 12:55:28 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Focus and editable cells");
|
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
iconview = focus_iconview (FALSE, &focus_renderer, &sibling_renderer);
|
2010-11-10 10:17:06 +00:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (frame, TRUE);
|
2010-11-10 10:17:06 +00:00
|
|
|
|
|
|
|
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_halign (frame, GTK_ALIGN_FILL);
|
|
|
|
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), iconview);
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
/* Now add some controls */
|
2011-04-22 13:38:40 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox);
|
|
|
|
gtk_box_append (GTK_BOX (hbox), frame);
|
2010-11-10 13:25:13 +00:00
|
|
|
|
2010-11-12 10:44:45 +00:00
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Horizontal");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Vertical");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), widget);
|
2010-11-12 10:44:45 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (orientation_changed), iconview);
|
2010-11-12 10:44:45 +00:00
|
|
|
|
2010-11-11 07:13:06 +00:00
|
|
|
widget = gtk_check_button_new_with_label ("Focus Sibling");
|
2010-11-12 12:55:28 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), widget);
|
2010-11-10 13:25:13 +00:00
|
|
|
|
2010-11-11 07:13:06 +00:00
|
|
|
g_signal_connect (G_OBJECT (widget), "toggled",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (focus_sibling_toggled), iconview);
|
2010-11-11 07:13:06 +00:00
|
|
|
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), hbox);
|
2010-11-10 10:17:06 +00:00
|
|
|
|
|
|
|
gtk_widget_show (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
/*******************************************************
|
|
|
|
* Background Area *
|
|
|
|
*******************************************************/
|
|
|
|
static void
|
|
|
|
cell_spacing_changed (GtkSpinButton *spin_button,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-12 12:55:28 +00:00
|
|
|
{
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkCellArea *area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (iconview));
|
2020-07-24 13:54:49 +00:00
|
|
|
int value;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
value = (int)gtk_spin_button_get_value (spin_button);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
gtk_cell_area_box_set_spacing (GTK_CELL_AREA_BOX (area), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
row_spacing_changed (GtkSpinButton *spin_button,
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkIconView *iconview)
|
2010-11-12 12:55:28 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int value;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
value = (int)gtk_spin_button_get_value (spin_button);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
gtk_icon_view_set_row_spacing (iconview, value);
|
2010-11-12 12:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-05 03:39:58 +00:00
|
|
|
item_padding_changed (GtkSpinButton *spin_button,
|
|
|
|
GtkIconView *iconview)
|
2010-11-12 12:55:28 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int value;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
value = (int)gtk_spin_button_get_value (spin_button);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
gtk_icon_view_set_item_padding (iconview, value);
|
2010-11-12 12:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
background_area (void)
|
|
|
|
{
|
|
|
|
GtkWidget *window, *widget, *label, *main_vbox;
|
2012-05-05 03:39:58 +00:00
|
|
|
GtkWidget *iconview, *frame, *vbox, *hbox;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2011-04-22 13:38:40 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
|
|
|
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), main_vbox);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Background Area");
|
|
|
|
|
|
|
|
label = gtk_label_new ("In this example, row spacing gets devided into the background area, "
|
2012-05-05 03:39:58 +00:00
|
|
|
"column spacing is added between each background area, item_padding is "
|
2010-11-23 07:26:46 +00:00
|
|
|
"prepended space distributed to the background area.");
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
|
|
|
gtk_label_set_width_chars (GTK_LABEL (label), 40);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (main_vbox), label);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2012-05-05 03:39:58 +00:00
|
|
|
iconview = focus_iconview (TRUE, NULL, NULL);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (frame, TRUE);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_halign (frame, GTK_ALIGN_FILL);
|
|
|
|
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), iconview);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
/* Now add some controls */
|
2011-04-22 13:38:40 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox);
|
|
|
|
gtk_box_append (GTK_BOX (hbox), frame);
|
2018-12-26 07:20:34 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (main_vbox), hbox);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Horizontal");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Vertical");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), widget);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (orientation_changed), iconview);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (0, 10, 1);
|
|
|
|
label = gtk_label_new ("Cell spacing");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
2011-04-22 13:38:40 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), label);
|
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
|
|
|
gtk_box_append (GTK_BOX (vbox), hbox);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "value-changed",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (cell_spacing_changed), iconview);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (0, 10, 1);
|
2012-05-05 03:39:58 +00:00
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), gtk_icon_view_get_row_spacing (GTK_ICON_VIEW (iconview)));
|
2010-11-12 12:55:28 +00:00
|
|
|
label = gtk_label_new ("Row spacing");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
2011-04-22 13:38:40 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), label);
|
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
|
|
|
gtk_box_append (GTK_BOX (vbox), hbox);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "value-changed",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (row_spacing_changed), iconview);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
widget = gtk_spin_button_new_with_range (0, 30, 1);
|
2012-05-05 03:39:58 +00:00
|
|
|
label = gtk_label_new ("Item padding");
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
2012-05-05 03:39:58 +00:00
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), gtk_icon_view_get_item_padding (GTK_ICON_VIEW (iconview)));
|
2011-04-22 13:38:40 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), label);
|
|
|
|
gtk_box_append (GTK_BOX (hbox), widget);
|
|
|
|
gtk_box_append (GTK_BOX (vbox), hbox);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (widget), "value-changed",
|
2012-05-05 03:39:58 +00:00
|
|
|
G_CALLBACK (item_padding_changed), iconview);
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
gtk_widget_show (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-12-15 20:22:35 +00:00
|
|
|
if (g_getenv ("RTL"))
|
|
|
|
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
|
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
simple_cell_area ();
|
2010-11-10 10:17:06 +00:00
|
|
|
focus_cell_area ();
|
2010-11-12 12:55:28 +00:00
|
|
|
background_area ();
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (TRUE)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|