2004-08-04 14:32:45 +00:00
|
|
|
/* testiconview.c
|
|
|
|
* Copyright (C) 2002 Anders Carlsson <andersca@gnu.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2004-08-04 14:32:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2017-03-12 18:36:21 +00:00
|
|
|
#include <glib/gstdio.h>
|
2004-08-04 14:32:45 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2004-11-09 19:25:55 +00:00
|
|
|
#define NUMBER_OF_ITEMS 10
|
|
|
|
#define SOME_ITEMS 100
|
|
|
|
#define MANY_ITEMS 10000
|
2004-08-04 14:32:45 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fill_model (GtkTreeModel *model)
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
int i;
|
|
|
|
char *str, *str2;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store = GTK_LIST_STORE (model);
|
2007-06-11 15:38:53 +00:00
|
|
|
gint32 size;
|
2004-08-04 14:32:45 +00:00
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file ("gnome-textfile.png", NULL);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
gtk_list_store_prepend (store, &iter);
|
|
|
|
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
0, pixbuf,
|
|
|
|
1, "Really really\nreally really loooooooooong item name",
|
|
|
|
2, 0,
|
|
|
|
3, "This is a <b>Test</b> of <i>markup</i>",
|
2005-05-02 20:28:37 +00:00
|
|
|
4, TRUE,
|
2004-08-04 14:32:45 +00:00
|
|
|
-1);
|
2005-05-02 20:28:37 +00:00
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
while (i < NUMBER_OF_ITEMS - 1)
|
|
|
|
{
|
2007-06-11 15:38:53 +00:00
|
|
|
GdkPixbuf *pb;
|
|
|
|
size = g_random_int_range (20, 70);
|
|
|
|
pb = gdk_pixbuf_scale_simple (pixbuf, size, size, GDK_INTERP_NEAREST);
|
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
str = g_strdup_printf ("Icon %d", i);
|
|
|
|
str2 = g_strdup_printf ("Icon <b>%d</b>", i);
|
|
|
|
gtk_list_store_prepend (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
2007-06-11 15:38:53 +00:00
|
|
|
0, pb,
|
2004-08-04 14:32:45 +00:00
|
|
|
1, str,
|
|
|
|
2, i,
|
|
|
|
3, str2,
|
2005-05-02 20:28:37 +00:00
|
|
|
4, TRUE,
|
2004-08-04 14:32:45 +00:00
|
|
|
-1);
|
|
|
|
g_free (str);
|
|
|
|
g_free (str2);
|
|
|
|
i++;
|
|
|
|
}
|
2005-04-29 15:24:30 +00:00
|
|
|
|
2005-05-06 04:14:32 +00:00
|
|
|
// gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 2, GTK_SORT_ASCENDING);
|
2004-08-04 14:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreeModel *
|
|
|
|
create_model (void)
|
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
|
2005-05-02 20:28:37 +00:00
|
|
|
store = gtk_list_store_new (5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
|
|
|
return GTK_TREE_MODEL (store);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
foreach_selected_remove (GtkWidget *button, GtkIconView *icon_list)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
GList *list, *selected;
|
|
|
|
|
|
|
|
selected = gtk_icon_view_get_selected_items (icon_list);
|
|
|
|
model = gtk_icon_view_get_model (icon_list);
|
|
|
|
|
|
|
|
for (list = selected; list; list = list->next)
|
|
|
|
{
|
|
|
|
GtkTreePath *path = list->data;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-29 15:24:30 +00:00
|
|
|
static void
|
|
|
|
swap_rows (GtkWidget *button, GtkIconView *icon_list)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter, iter2;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
model = gtk_icon_view_get_model (icon_list);
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), -2, GTK_SORT_ASCENDING);
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter_first (model, &iter);
|
|
|
|
iter2 = iter;
|
|
|
|
gtk_tree_model_iter_next (model, &iter2);
|
|
|
|
gtk_list_store_swap (GTK_LIST_STORE (model), &iter, &iter2);
|
|
|
|
}
|
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
static void
|
2020-07-24 13:54:49 +00:00
|
|
|
add_n_items (GtkIconView *icon_list, int n)
|
2004-08-04 14:32:45 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
static int count = NUMBER_OF_ITEMS;
|
2004-08-04 14:32:45 +00:00
|
|
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store;
|
|
|
|
GdkPixbuf *pixbuf;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *str, *str2;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2004-08-04 14:32:45 +00:00
|
|
|
|
|
|
|
store = GTK_LIST_STORE (gtk_icon_view_get_model (icon_list));
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file ("gnome-textfile.png", NULL);
|
|
|
|
|
|
|
|
|
2004-11-09 19:25:55 +00:00
|
|
|
for (i = 0; i < n; i++)
|
2004-08-04 14:32:45 +00:00
|
|
|
{
|
|
|
|
str = g_strdup_printf ("Icon %d", count);
|
|
|
|
str2 = g_strdup_printf ("Icon <b>%d</b>", count);
|
|
|
|
gtk_list_store_prepend (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
0, pixbuf,
|
|
|
|
1, str,
|
|
|
|
2, i,
|
|
|
|
3, str2,
|
|
|
|
-1);
|
|
|
|
g_free (str);
|
|
|
|
g_free (str2);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-09 19:25:55 +00:00
|
|
|
static void
|
|
|
|
add_some (GtkWidget *button, GtkIconView *icon_list)
|
|
|
|
{
|
|
|
|
add_n_items (icon_list, SOME_ITEMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_many (GtkWidget *button, GtkIconView *icon_list)
|
|
|
|
{
|
|
|
|
add_n_items (icon_list, MANY_ITEMS);
|
|
|
|
}
|
|
|
|
|
2004-12-14 14:08:30 +00:00
|
|
|
static void
|
|
|
|
add_large (GtkWidget *button, GtkIconView *icon_list)
|
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
GdkPixbuf *pixbuf, *pb;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *str;
|
2004-12-14 14:08:30 +00:00
|
|
|
|
|
|
|
store = GTK_LIST_STORE (gtk_icon_view_get_model (icon_list));
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file ("gnome-textfile.png", NULL);
|
|
|
|
|
|
|
|
pb = gdk_pixbuf_scale_simple (pixbuf,
|
|
|
|
2 * gdk_pixbuf_get_width (pixbuf),
|
|
|
|
2 * gdk_pixbuf_get_height (pixbuf),
|
|
|
|
GDK_INTERP_BILINEAR);
|
|
|
|
|
|
|
|
str = g_strdup_printf ("Some really long text");
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
0, pb,
|
|
|
|
1, str,
|
|
|
|
2, 0,
|
|
|
|
3, str,
|
|
|
|
-1);
|
|
|
|
g_object_unref (pb);
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
pb = gdk_pixbuf_scale_simple (pixbuf,
|
|
|
|
3 * gdk_pixbuf_get_width (pixbuf),
|
|
|
|
3 * gdk_pixbuf_get_height (pixbuf),
|
|
|
|
GDK_INTERP_BILINEAR);
|
|
|
|
|
|
|
|
str = g_strdup ("see how long text behaves when placed underneath "
|
|
|
|
"an oversized icon which would allow for long lines");
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
0, pb,
|
|
|
|
1, str,
|
|
|
|
2, 1,
|
|
|
|
3, str,
|
|
|
|
-1);
|
|
|
|
g_object_unref (pb);
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
pb = gdk_pixbuf_scale_simple (pixbuf,
|
|
|
|
3 * gdk_pixbuf_get_width (pixbuf),
|
|
|
|
3 * gdk_pixbuf_get_height (pixbuf),
|
|
|
|
GDK_INTERP_BILINEAR);
|
|
|
|
|
|
|
|
str = g_strdup ("short text");
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
0, pb,
|
|
|
|
1, str,
|
|
|
|
2, 2,
|
|
|
|
3, str,
|
|
|
|
-1);
|
|
|
|
g_object_unref (pb);
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
}
|
|
|
|
|
2004-08-04 20:32:26 +00:00
|
|
|
static void
|
|
|
|
select_all (GtkWidget *button, GtkIconView *icon_list)
|
|
|
|
{
|
|
|
|
gtk_icon_view_select_all (icon_list);
|
|
|
|
}
|
|
|
|
|
2005-04-29 15:24:30 +00:00
|
|
|
static void
|
|
|
|
select_nonexisting (GtkWidget *button, GtkIconView *icon_list)
|
|
|
|
{
|
|
|
|
GtkTreePath *path = gtk_tree_path_new_from_indices (999999, -1);
|
|
|
|
gtk_icon_view_select_path (icon_list, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
2004-08-04 20:32:26 +00:00
|
|
|
static void
|
|
|
|
unselect_all (GtkWidget *button, GtkIconView *icon_list)
|
|
|
|
{
|
|
|
|
gtk_icon_view_unselect_all (icon_list);
|
|
|
|
}
|
2004-08-04 14:32:45 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
selection_changed (GtkIconView *icon_list)
|
|
|
|
{
|
|
|
|
g_print ("Selection changed!\n");
|
|
|
|
}
|
|
|
|
|
2004-08-04 20:32:26 +00:00
|
|
|
typedef struct {
|
|
|
|
GtkIconView *icon_list;
|
|
|
|
GtkTreePath *path;
|
|
|
|
} ItemData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_item_data (ItemData *data)
|
|
|
|
{
|
|
|
|
gtk_tree_path_free (data->path);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
static void
|
2004-11-09 18:08:53 +00:00
|
|
|
item_activated (GtkIconView *icon_view,
|
|
|
|
GtkTreePath *path)
|
2004-08-04 14:32:45 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel *model;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *text;
|
2004-11-09 18:08:53 +00:00
|
|
|
|
|
|
|
model = gtk_icon_view_get_model (icon_view);
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
2004-08-04 20:32:26 +00:00
|
|
|
gtk_tree_model_get (model, &iter, 1, &text, -1);
|
2004-08-04 14:32:45 +00:00
|
|
|
g_print ("Item activated, text is %s\n", text);
|
2004-08-04 20:32:26 +00:00
|
|
|
g_free (text);
|
2004-11-09 18:08:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-05-02 20:28:37 +00:00
|
|
|
static void
|
|
|
|
toggled (GtkCellRendererToggle *cell,
|
2020-07-24 18:40:36 +00:00
|
|
|
char *path_string,
|
2005-05-02 20:28:37 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL (data);
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
|
|
|
|
gboolean value;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
gtk_tree_model_get (model, &iter, 4, &value, -1);
|
|
|
|
|
|
|
|
value = !value;
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter, 4, value, -1);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
edited (GtkCellRendererText *cell,
|
2020-07-24 18:40:36 +00:00
|
|
|
char *path_string,
|
|
|
|
char *new_text,
|
2005-05-02 20:28:37 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL (data);
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter, 1, new_text, -1);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
2004-11-09 18:08:53 +00:00
|
|
|
static void
|
|
|
|
item_cb (GtkWidget *menuitem,
|
|
|
|
ItemData *data)
|
|
|
|
{
|
|
|
|
item_activated (data->icon_list, data->path);
|
2004-08-04 14:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-06-26 21:50:16 +00:00
|
|
|
do_popup_menu (GtkWidget *icon_list,
|
|
|
|
GtkTreePath *path)
|
2004-08-04 14:32:45 +00:00
|
|
|
{
|
2018-01-16 04:57:57 +00:00
|
|
|
GtkIconView *icon_view = GTK_ICON_VIEW (icon_list);
|
2004-08-04 14:32:45 +00:00
|
|
|
GtkWidget *menu;
|
2019-12-27 04:16:53 +00:00
|
|
|
GtkWidget *item;
|
2004-08-04 20:32:26 +00:00
|
|
|
ItemData *data;
|
2005-05-02 20:28:37 +00:00
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
if (!path)
|
|
|
|
return;
|
|
|
|
|
2020-02-24 12:21:46 +00:00
|
|
|
menu = gtk_popover_new ();
|
|
|
|
gtk_widget_set_parent (menu, icon_list);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
2004-08-04 20:32:26 +00:00
|
|
|
data = g_new0 (ItemData, 1);
|
2007-03-12 03:13:51 +00:00
|
|
|
data->icon_list = icon_view;
|
2004-08-04 20:32:26 +00:00
|
|
|
data->path = path;
|
2004-10-28 15:00:05 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (menu), "item-path", data, (GDestroyNotify)free_item_data);
|
2004-08-04 20:32:26 +00:00
|
|
|
|
2019-12-27 04:16:53 +00:00
|
|
|
item = gtk_button_new_with_label ("Activate");
|
2020-05-11 13:54:23 +00:00
|
|
|
gtk_popover_set_child (GTK_POPOVER (menu), item);
|
2019-12-27 04:16:53 +00:00
|
|
|
g_signal_connect (item, "clicked", G_CALLBACK (item_cb), data);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
2019-12-27 04:16:53 +00:00
|
|
|
gtk_popover_popup (GTK_POPOVER (menu));
|
2004-08-04 14:32:45 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 21:50:16 +00:00
|
|
|
static void
|
2019-05-29 17:10:46 +00:00
|
|
|
press_handler (GtkGestureClick *gesture,
|
|
|
|
guint n_press,
|
2020-07-24 20:32:16 +00:00
|
|
|
double x,
|
|
|
|
double y,
|
2019-05-29 17:10:46 +00:00
|
|
|
GtkWidget *widget)
|
2004-08-04 14:32:45 +00:00
|
|
|
{
|
2018-06-26 21:50:16 +00:00
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
/* Ignore double-clicks and triple-clicks */
|
2018-06-26 21:50:16 +00:00
|
|
|
if (n_press > 1)
|
|
|
|
return;
|
2004-08-04 14:32:45 +00:00
|
|
|
|
2018-06-26 21:50:16 +00:00
|
|
|
path = gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (widget), x, y);
|
|
|
|
do_popup_menu (widget, path);
|
2004-08-04 14:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
popup_menu_handler (GtkWidget *widget)
|
|
|
|
{
|
2018-06-26 21:50:16 +00:00
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
list = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (widget));
|
|
|
|
|
|
|
|
if (list)
|
|
|
|
{
|
|
|
|
path = (GtkTreePath*)list->data;
|
|
|
|
g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_popup_menu (widget, path);
|
2004-08-04 14:32:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2005-05-06 04:14:32 +00:00
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
int
|
2020-07-24 18:40:36 +00:00
|
|
|
main (int argc, char **argv)
|
2004-08-04 14:32:45 +00:00
|
|
|
{
|
2005-05-06 04:14:32 +00:00
|
|
|
GtkWidget *paned, *tv;
|
2004-08-04 14:32:45 +00:00
|
|
|
GtkWidget *window, *icon_list, *scrolled_window;
|
|
|
|
GtkWidget *vbox, *bbox;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkTreeModel *model;
|
2005-05-02 20:28:37 +00:00
|
|
|
GtkCellRenderer *cell;
|
2005-05-06 04:14:32 +00:00
|
|
|
GtkTreeViewColumn *tvc;
|
2017-11-18 01:19:53 +00:00
|
|
|
GdkContentFormats *targets;
|
2018-06-26 21:50:16 +00:00
|
|
|
GtkGesture *gesture;
|
2004-08-04 14:32:45 +00:00
|
|
|
|
2017-03-12 18:36:21 +00:00
|
|
|
#ifdef GTK_SRCDIR
|
|
|
|
g_chdir (GTK_SRCDIR);
|
|
|
|
#endif
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2004-08-04 14:32:45 +00:00
|
|
|
|
|
|
|
/* to test rtl layout, set RTL=1 in the environment */
|
|
|
|
if (g_getenv ("RTL"))
|
|
|
|
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2004-08-04 14:32:45 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 700, 400);
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), vbox);
|
2004-12-14 14:08:30 +00:00
|
|
|
|
2010-10-29 23:47:13 +00:00
|
|
|
paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_vexpand (paned, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), paned);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
|
|
|
icon_list = gtk_icon_view_new ();
|
|
|
|
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_list), GTK_SELECTION_MULTIPLE);
|
|
|
|
|
2005-05-06 04:14:32 +00:00
|
|
|
tv = gtk_tree_view_new ();
|
|
|
|
tvc = gtk_tree_view_column_new ();
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tv), tvc);
|
|
|
|
|
2019-05-29 17:10:46 +00:00
|
|
|
gesture = gtk_gesture_click_new ();
|
2018-06-26 21:50:16 +00:00
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture),
|
|
|
|
GDK_BUTTON_SECONDARY);
|
|
|
|
g_signal_connect (gesture, "pressed",
|
|
|
|
G_CALLBACK (press_handler), icon_list);
|
|
|
|
gtk_widget_add_controller (icon_list, GTK_EVENT_CONTROLLER (gesture));
|
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
g_signal_connect (icon_list, "selection_changed",
|
|
|
|
G_CALLBACK (selection_changed), NULL);
|
|
|
|
g_signal_connect (icon_list, "popup_menu",
|
|
|
|
G_CALLBACK (popup_menu_handler), NULL);
|
|
|
|
|
|
|
|
g_signal_connect (icon_list, "item_activated",
|
2004-11-09 18:08:53 +00:00
|
|
|
G_CALLBACK (item_activated), NULL);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
|
|
|
model = create_model ();
|
|
|
|
gtk_icon_view_set_model (GTK_ICON_VIEW (icon_list), model);
|
2005-05-06 04:14:32 +00:00
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (tv), model);
|
2004-08-04 14:32:45 +00:00
|
|
|
fill_model (model);
|
2005-05-02 20:28:37 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_list), 0);
|
|
|
|
gtk_icon_view_set_text_column (GTK_ICON_VIEW (icon_list), 1);
|
2005-05-02 20:28:37 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_toggle_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_list), cell, FALSE);
|
|
|
|
g_object_set (cell, "activatable", TRUE, NULL);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_list),
|
|
|
|
cell, "active", 4, NULL);
|
|
|
|
g_signal_connect (cell, "toggled", G_CALLBACK (toggled), model);
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_list), cell, FALSE);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_list),
|
|
|
|
cell, "pixbuf", 0, NULL);
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_list), cell, FALSE);
|
|
|
|
g_object_set (cell,
|
|
|
|
"editable", TRUE,
|
|
|
|
"xalign", 0.5,
|
|
|
|
"wrap-mode", PANGO_WRAP_WORD_CHAR,
|
|
|
|
"wrap-width", 100,
|
|
|
|
NULL);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_list),
|
|
|
|
cell, "text", 1, NULL);
|
|
|
|
g_signal_connect (cell, "edited", G_CALLBACK (edited), model);
|
2005-05-06 04:14:32 +00:00
|
|
|
|
|
|
|
/* now the tree view... */
|
|
|
|
cell = gtk_cell_renderer_toggle_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (tvc), cell, FALSE);
|
|
|
|
g_object_set (cell, "activatable", TRUE, NULL);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (tvc),
|
|
|
|
cell, "active", 4, NULL);
|
|
|
|
g_signal_connect (cell, "toggled", G_CALLBACK (toggled), model);
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (tvc), cell, FALSE);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (tvc),
|
|
|
|
cell, "pixbuf", 0, NULL);
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (tvc), cell, FALSE);
|
|
|
|
g_object_set (cell, "editable", TRUE, NULL);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (tvc),
|
|
|
|
cell, "text", 1, NULL);
|
|
|
|
g_signal_connect (cell, "edited", G_CALLBACK (edited), model);
|
2005-05-02 20:28:37 +00:00
|
|
|
#endif
|
2005-05-06 04:14:32 +00:00
|
|
|
/* Allow DND between the icon view and the tree view */
|
|
|
|
|
2020-02-18 00:41:42 +00:00
|
|
|
targets = gdk_content_formats_new_for_gtype (GTK_TYPE_TREE_ROW_DATA);
|
2005-05-14 07:19:48 +00:00
|
|
|
gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW (icon_list),
|
2005-05-06 04:14:32 +00:00
|
|
|
GDK_BUTTON1_MASK,
|
2017-11-14 21:32:23 +00:00
|
|
|
targets,
|
2005-05-06 04:14:32 +00:00
|
|
|
GDK_ACTION_MOVE);
|
2005-05-14 07:19:48 +00:00
|
|
|
gtk_icon_view_enable_model_drag_dest (GTK_ICON_VIEW (icon_list),
|
2017-11-14 21:32:23 +00:00
|
|
|
targets,
|
2005-05-06 04:14:32 +00:00
|
|
|
GDK_ACTION_MOVE);
|
|
|
|
|
2005-05-14 07:19:48 +00:00
|
|
|
gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (tv),
|
2005-05-06 04:14:32 +00:00
|
|
|
GDK_BUTTON1_MASK,
|
2017-11-14 21:32:23 +00:00
|
|
|
targets,
|
2005-05-06 04:14:32 +00:00
|
|
|
GDK_ACTION_MOVE);
|
2005-05-14 07:19:48 +00:00
|
|
|
gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW (tv),
|
2017-11-14 21:32:23 +00:00
|
|
|
targets,
|
2005-05-06 04:14:32 +00:00
|
|
|
GDK_ACTION_MOVE);
|
2017-11-18 01:19:53 +00:00
|
|
|
gdk_content_formats_unref (targets);
|
2020-05-02 04:51:20 +00:00
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
scrolled_window = gtk_scrolled_window_new ();
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), icon_list);
|
2004-08-04 14:32:45 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2004-12-14 14:08:30 +00:00
|
|
|
|
2020-05-07 12:30:39 +00:00
|
|
|
gtk_paned_set_start_child (GTK_PANED (paned), scrolled_window);
|
2005-05-02 20:28:37 +00:00
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
scrolled_window = gtk_scrolled_window_new ();
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), tv);
|
2005-05-06 04:14:32 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
|
2020-05-07 12:30:39 +00:00
|
|
|
gtk_paned_set_end_child (GTK_PANED (paned), scrolled_window);
|
2005-05-06 04:14:32 +00:00
|
|
|
|
2019-02-04 17:44:55 +00:00
|
|
|
bbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_widget_set_halign (bbox, GTK_ALIGN_START);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), bbox);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
2004-11-09 19:25:55 +00:00
|
|
|
button = gtk_button_new_with_label ("Add some");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (add_some), icon_list);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (bbox), button);
|
2004-11-09 19:25:55 +00:00
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
button = gtk_button_new_with_label ("Add many");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (add_many), icon_list);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (bbox), button);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
2004-12-14 14:08:30 +00:00
|
|
|
button = gtk_button_new_with_label ("Add large");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (add_large), icon_list);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (bbox), button);
|
2004-12-14 14:08:30 +00:00
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
button = gtk_button_new_with_label ("Remove selected");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (foreach_selected_remove), icon_list);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (bbox), button);
|
2004-08-04 20:32:26 +00:00
|
|
|
|
2005-04-29 15:24:30 +00:00
|
|
|
button = gtk_button_new_with_label ("Swap");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (swap_rows), icon_list);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (bbox), button);
|
2005-04-29 15:24:30 +00:00
|
|
|
|
2019-02-04 17:44:55 +00:00
|
|
|
bbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_widget_set_halign (bbox, GTK_ALIGN_START);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), bbox);
|
2004-12-14 14:08:30 +00:00
|
|
|
|
2004-08-04 20:32:26 +00:00
|
|
|
button = gtk_button_new_with_label ("Select all");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (select_all), icon_list);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (bbox), button);
|
2004-08-04 20:32:26 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Unselect all");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (unselect_all), icon_list);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (bbox), button);
|
2008-08-05 12:30:15 +00:00
|
|
|
|
2005-04-29 15:24:30 +00:00
|
|
|
button = gtk_button_new_with_label ("Select nonexisting");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (select_nonexisting), icon_list);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (bbox), button);
|
2005-04-29 15:24:30 +00:00
|
|
|
|
2004-08-04 14:32:45 +00:00
|
|
|
icon_list = gtk_icon_view_new ();
|
2008-08-05 12:30:15 +00:00
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
scrolled_window = gtk_scrolled_window_new ();
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), icon_list);
|
2004-08-04 14:32:45 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
2020-05-02 04:51:20 +00:00
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2020-05-07 12:30:39 +00:00
|
|
|
gtk_paned_set_end_child (GTK_PANED (paned), scrolled_window);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (TRUE)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2004-08-04 14:32:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|