2005-07-13 05:44:22 +00:00
|
|
|
/* testtreeview.c
|
|
|
|
* Copyright (C) 2001 Red Hat, Inc
|
|
|
|
* Author: Jonathan Blandford
|
|
|
|
*
|
|
|
|
* 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/>.
|
2005-07-13 05:44:22 +00:00
|
|
|
*/
|
|
|
|
|
2000-12-21 22:17:38 +00:00
|
|
|
#include <string.h>
|
2001-05-03 00:46:19 +00:00
|
|
|
#include <gtk/gtk.h>
|
2006-03-22 18:38:47 +00:00
|
|
|
#include <stdlib.h>
|
2001-01-09 17:45:34 +00:00
|
|
|
|
|
|
|
/* Don't copy this bad example; inline RGB data is always a better
|
|
|
|
* idea than inline XPMs.
|
|
|
|
*/
|
2020-03-06 17:05:43 +00:00
|
|
|
static const char *book_closed_xpm[] = {
|
2001-01-09 17:45:34 +00:00
|
|
|
"16 16 6 1",
|
|
|
|
" c None s None",
|
|
|
|
". c black",
|
|
|
|
"X c red",
|
|
|
|
"o c yellow",
|
|
|
|
"O c #808080",
|
|
|
|
"# c white",
|
|
|
|
" ",
|
|
|
|
" .. ",
|
|
|
|
" ..XX. ",
|
|
|
|
" ..XXXXX. ",
|
|
|
|
" ..XXXXXXXX. ",
|
|
|
|
".ooXXXXXXXXX. ",
|
|
|
|
"..ooXXXXXXXXX. ",
|
|
|
|
".X.ooXXXXXXXXX. ",
|
|
|
|
".XX.ooXXXXXX.. ",
|
|
|
|
" .XX.ooXXX..#O ",
|
|
|
|
" .XX.oo..##OO. ",
|
|
|
|
" .XX..##OO.. ",
|
|
|
|
" .X.#OO.. ",
|
|
|
|
" ..O.. ",
|
|
|
|
" .. ",
|
|
|
|
" "
|
|
|
|
};
|
|
|
|
|
|
|
|
static void run_automated_tests (void);
|
2001-01-06 01:31:58 +00:00
|
|
|
|
|
|
|
/* This custom model is to test custom model use. */
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
#define GTK_TYPE_MODEL_TYPES (gtk_tree_model_types_get_type ())
|
|
|
|
#define GTK_TREE_MODEL_TYPES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_MODEL_TYPES, GtkTreeModelTypes))
|
|
|
|
#define GTK_TREE_MODEL_TYPES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_MODEL_TYPES, GtkTreeModelTypesClass))
|
|
|
|
#define GTK_IS_TREE_MODEL_TYPES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_MODEL_TYPES))
|
|
|
|
#define GTK_IS_TREE_MODEL_TYPES_GET_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_MODEL_TYPES))
|
2001-01-06 01:31:58 +00:00
|
|
|
|
|
|
|
typedef struct _GtkTreeModelTypes GtkTreeModelTypes;
|
|
|
|
typedef struct _GtkTreeModelTypesClass GtkTreeModelTypesClass;
|
|
|
|
|
|
|
|
struct _GtkTreeModelTypes
|
|
|
|
{
|
2002-10-13 23:22:33 +00:00
|
|
|
GObject parent;
|
2001-01-06 01:31:58 +00:00
|
|
|
|
|
|
|
gint stamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkTreeModelTypesClass
|
|
|
|
{
|
2002-10-13 23:22:33 +00:00
|
|
|
GObjectClass parent_class;
|
2001-01-06 01:31:58 +00:00
|
|
|
|
|
|
|
guint (* get_flags) (GtkTreeModel *tree_model);
|
|
|
|
gint (* get_n_columns) (GtkTreeModel *tree_model);
|
|
|
|
GType (* get_column_type) (GtkTreeModel *tree_model,
|
|
|
|
gint index);
|
|
|
|
gboolean (* get_iter) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path);
|
|
|
|
GtkTreePath *(* get_path) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
void (* get_value) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint column,
|
|
|
|
GValue *value);
|
|
|
|
gboolean (* iter_next) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
gboolean (* iter_children) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent);
|
|
|
|
gboolean (* iter_has_child) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
gint (* iter_n_children) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
gboolean (* iter_nth_child) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
gint n);
|
|
|
|
gboolean (* iter_parent) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *child);
|
|
|
|
void (* ref_iter) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
void (* unref_iter) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
|
|
|
|
/* These will be moved into the GtkTreeModelIface eventually */
|
|
|
|
void (* changed) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
void (* inserted) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
void (* child_toggled) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
void (* deleted) (GtkTreeModel *tree_model,
|
|
|
|
GtkTreePath *path);
|
|
|
|
};
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
GType gtk_tree_model_types_get_type (void) G_GNUC_CONST;
|
2001-01-06 01:31:58 +00:00
|
|
|
GtkTreeModelTypes *gtk_tree_model_types_new (void);
|
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
COLUMNS_NONE,
|
|
|
|
COLUMNS_ONE,
|
|
|
|
COLUMNS_LOTS,
|
|
|
|
COLUMNS_LAST
|
|
|
|
} ColumnsType;
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
static const char *column_type_names[] = {
|
2001-01-16 03:49:24 +00:00
|
|
|
"No columns",
|
|
|
|
"One column",
|
|
|
|
"Many columns"
|
|
|
|
};
|
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
#define N_COLUMNS 9
|
|
|
|
|
|
|
|
static GType*
|
|
|
|
get_model_types (void)
|
|
|
|
{
|
|
|
|
static GType column_types[N_COLUMNS] = { 0 };
|
|
|
|
|
|
|
|
if (column_types[0] == 0)
|
|
|
|
{
|
|
|
|
column_types[0] = G_TYPE_STRING;
|
|
|
|
column_types[1] = G_TYPE_STRING;
|
|
|
|
column_types[2] = GDK_TYPE_PIXBUF;
|
|
|
|
column_types[3] = G_TYPE_FLOAT;
|
|
|
|
column_types[4] = G_TYPE_UINT;
|
|
|
|
column_types[5] = G_TYPE_UCHAR;
|
|
|
|
column_types[6] = G_TYPE_CHAR;
|
2001-01-16 03:49:24 +00:00
|
|
|
#define BOOL_COLUMN 7
|
|
|
|
column_types[BOOL_COLUMN] = G_TYPE_BOOLEAN;
|
2001-01-09 17:45:34 +00:00
|
|
|
column_types[8] = G_TYPE_INT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return column_types;
|
|
|
|
}
|
|
|
|
|
2001-01-16 03:49:24 +00:00
|
|
|
static void
|
|
|
|
toggled_callback (GtkCellRendererToggle *celltoggle,
|
|
|
|
gchar *path_string,
|
|
|
|
GtkTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model = NULL;
|
|
|
|
GtkTreeModelSort *sort_model = NULL;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean active = FALSE;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
|
|
|
if (GTK_IS_TREE_MODEL_SORT (model))
|
|
|
|
{
|
|
|
|
sort_model = GTK_TREE_MODEL_SORT (model);
|
|
|
|
model = gtk_tree_model_sort_get_model (sort_model);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (model == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sort_model)
|
|
|
|
{
|
|
|
|
g_warning ("FIXME implement conversion from TreeModelSort iter to child model iter");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_string (path_string);
|
|
|
|
if (!gtk_tree_model_get_iter (model,
|
|
|
|
&iter, path))
|
|
|
|
{
|
|
|
|
g_warning ("%s: bad path?", G_STRLOC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
if (GTK_IS_LIST_STORE (model))
|
|
|
|
{
|
2001-02-21 19:59:23 +00:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (model),
|
2001-01-16 03:49:24 +00:00
|
|
|
&iter,
|
|
|
|
BOOL_COLUMN,
|
|
|
|
&active,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model),
|
|
|
|
&iter,
|
|
|
|
BOOL_COLUMN,
|
|
|
|
!active,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
else if (GTK_IS_TREE_STORE (model))
|
|
|
|
{
|
2001-02-21 19:59:23 +00:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (model),
|
2001-01-16 03:49:24 +00:00
|
|
|
&iter,
|
|
|
|
BOOL_COLUMN,
|
|
|
|
&active,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_tree_store_set (GTK_TREE_STORE (model),
|
|
|
|
&iter,
|
|
|
|
BOOL_COLUMN,
|
|
|
|
!active,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warning ("don't know how to actually toggle value for model type %s",
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (model)));
|
|
|
|
}
|
|
|
|
|
2006-03-22 18:38:47 +00:00
|
|
|
static void
|
|
|
|
edited_callback (GtkCellRendererText *renderer,
|
|
|
|
const gchar *path_string,
|
|
|
|
const gchar *new_text,
|
|
|
|
GtkTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model = NULL;
|
|
|
|
GtkTreeModelSort *sort_model = NULL;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
guint value = atoi (new_text);
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
|
|
|
if (GTK_IS_TREE_MODEL_SORT (model))
|
|
|
|
{
|
|
|
|
sort_model = GTK_TREE_MODEL_SORT (model);
|
|
|
|
model = gtk_tree_model_sort_get_model (sort_model);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (model == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sort_model)
|
|
|
|
{
|
|
|
|
g_warning ("FIXME implement conversion from TreeModelSort iter to child model iter");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_string (path_string);
|
|
|
|
if (!gtk_tree_model_get_iter (model,
|
|
|
|
&iter, path))
|
|
|
|
{
|
|
|
|
g_warning ("%s: bad path?", G_STRLOC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
if (GTK_IS_LIST_STORE (model))
|
|
|
|
{
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model),
|
|
|
|
&iter,
|
|
|
|
4,
|
|
|
|
value,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
else if (GTK_IS_TREE_STORE (model))
|
|
|
|
{
|
|
|
|
gtk_tree_store_set (GTK_TREE_STORE (model),
|
|
|
|
&iter,
|
|
|
|
4,
|
|
|
|
value,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warning ("don't know how to actually toggle value for model type %s",
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (model)));
|
|
|
|
}
|
2001-01-16 03:49:24 +00:00
|
|
|
|
|
|
|
static ColumnsType current_column_type = COLUMNS_LOTS;
|
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
static void
|
|
|
|
set_columns_type (GtkTreeView *tree_view, ColumnsType type)
|
|
|
|
{
|
|
|
|
GtkTreeViewColumn *col;
|
|
|
|
GtkCellRenderer *rend;
|
2001-01-19 22:39:19 +00:00
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GtkWidget *image;
|
2010-09-27 12:48:26 +00:00
|
|
|
GtkAdjustment *adjustment;
|
2010-09-18 23:54:31 +00:00
|
|
|
|
2001-01-16 03:49:24 +00:00
|
|
|
current_column_type = type;
|
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
col = gtk_tree_view_get_column (tree_view, 0);
|
|
|
|
while (col)
|
|
|
|
{
|
|
|
|
gtk_tree_view_remove_column (tree_view, col);
|
|
|
|
|
|
|
|
col = gtk_tree_view_get_column (tree_view, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case COLUMNS_NONE:
|
|
|
|
break;
|
|
|
|
|
remove validation idle
2001-02-08 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (gtk_text_view_destroy_layout): remove
validation idle
* demos/gtk-demo/main.c (create_tree): adjust to changes in text
cell renderer
* demos/pixbuf-demo.c (timeout): remove deprecated
gtk_widget_draw
* demos/testpixbuf-save.c (main): remove deprecated
gtk_drawing_area_size
* gtk/gtktreeview.c (gtk_tree_view_size_allocate): allocate
buttons even if the model isn't setup. gtk_tree_view_check_dirty()
at the start of the allocation.
(gtk_tree_view_check_dirty): handle column->button == NULL, handle
unsetup or NULL model.
* gtk/gtkstyle.c (gtk_default_draw_flat_box): drawing for the
even/odd/sorted cells in the tree view.
* gtk/gtktreeselection.c (gtk_tree_selection_real_unselect_all):
bugfixes
* gtk/gtktreeview.c: assorted bugfixy stuff. Draw the row
backgrounds with draw_flat_box using different detail for even/odd
rows.
* gtk/gtkrbtree.c, gtkrbtree.h: Keep track of the parity of each
row, so we can draw the alternating colors thing
* gtk/gtktexttag.c (gtk_text_tag_set_property): if we change a
property from a synonym property, notify for the synonym.
Also, nuke the background_gdk_set and foreground_gdk_set synonyms
(gtk_text_tag_get_property): Always return the font, even if
all its fields aren't set
* gtk/gtkcellrenderertext.h (struct _GtkCellRendererText): don't
store the attr list; it leaves us with no way to change attributes
in _render according to the render flags, and no way to implement
get_property. Instead store all the specific text attributes.
Separate whether an attribute is enabled from its value. Sync all
properties with GtkTextTag, make them all consistent, etc.
* gtk/gtkcellrenderer.h: Add a flag GTK_CELL_RENDERER_SORTED so
renderers can highlight the sort row/column
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_get_property): use
accessor functions to get values; this has the side effect of
showing up which accessor functions were missing. Added those.
* gtk/gtktreeviewcolumn.h: Replace set_justification with
set_alignment, to be consistent with GtkLabel, GtkMisc
* gtk/gtktreeviewcolumn.c: Added code to display sort indicator
arrow.
* gtk/Makefile.am (gtk_public_h_sources): add gtktreesortable.h
* gtk/gtktreesortable.h: updates in here
2001-02-08 23:36:53 +00:00
|
|
|
case COLUMNS_LOTS:
|
2001-01-09 17:45:34 +00:00
|
|
|
rend = gtk_cell_renderer_text_new ();
|
2010-12-01 13:42:54 +00:00
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Column 1",
|
|
|
|
rend,
|
|
|
|
"text", 1,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
|
|
|
|
|
2001-09-08 00:56:30 +00:00
|
|
|
col = gtk_tree_view_column_new();
|
|
|
|
gtk_tree_view_column_set_title (col, "Column 2");
|
2001-01-09 17:45:34 +00:00
|
|
|
|
2001-09-08 00:56:30 +00:00
|
|
|
rend = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
gtk_tree_view_column_pack_start (col, rend, FALSE);
|
|
|
|
gtk_tree_view_column_add_attribute (col, rend, "pixbuf", 2);
|
|
|
|
rend = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_tree_view_column_pack_start (col, rend, TRUE);
|
|
|
|
gtk_tree_view_column_add_attribute (col, rend, "text", 0);
|
2001-01-09 23:24:20 +00:00
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
|
2001-07-09 17:09:35 +00:00
|
|
|
gtk_tree_view_set_expander_column (tree_view, col);
|
2001-01-09 17:45:34 +00:00
|
|
|
|
2001-01-16 03:49:24 +00:00
|
|
|
rend = gtk_cell_renderer_toggle_new ();
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (rend, "toggled",
|
|
|
|
G_CALLBACK (toggled_callback), tree_view);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Column 3",
|
|
|
|
rend,
|
|
|
|
"active", BOOL_COLUMN,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
|
2001-01-19 22:39:19 +00:00
|
|
|
|
2001-06-07 22:33:14 +00:00
|
|
|
pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **)book_closed_xpm);
|
2001-01-19 22:39:19 +00:00
|
|
|
|
|
|
|
image = gtk_image_new_from_pixbuf (pixbuf);
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_object_unref (pixbuf);
|
2020-05-11 14:57:25 +00:00
|
|
|
|
2001-01-19 22:39:19 +00:00
|
|
|
gtk_tree_view_column_set_widget (col, image);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
|
|
|
rend = gtk_cell_renderer_toggle_new ();
|
|
|
|
|
|
|
|
/* you could also set this per-row by tying it to a column
|
|
|
|
* in the model of course.
|
|
|
|
*/
|
2003-02-28 01:45:51 +00:00
|
|
|
g_object_set (rend, "radio", TRUE, NULL);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (rend, "toggled",
|
up version to 1.3.7, interface age 0, binary age 0. depend on glib 1.3.7.
Thu Jun 28 17:18:41 2001 Tim Janik <timj@gtk.org>
* configure.in (GTK_MICRO_VERSION): up version to 1.3.7, interface
age 0, binary age 0. depend on glib 1.3.7.
* gtk/gtkcontainer.c: remove g_signal_handlers_disconnect_by_func() hack.
* gtk/gtkmenubar.c: same here.
* gtk/gtkcontainer.c (gtk_container_focus_tab): fix param-spec retrival.
* gtk/gtkcolorsel.c (gtk_color_selection_init): fix connect_data() usage.
* gtk/gtkentry.c (gtk_entry_focus_in): same here.
* gtk/gtkmenubar.c (add_to_window): likewise.
* gtk/gtktextbtree.c: and here...
* gtk/gtktextview.c (gtk_text_view_ensure_layout): same thing.
* gtk/gtktoolbar.c (gtk_toolbar_init): once more.
* gtk/gtktreemodel.c (connect_ref_callbacks): and another time.
* gtk/gtktreeviewcolumn.c:
(_gtk_tree_view_column_set_tree_view): yet again.
* demos/gtk-demo/images.c (progressive_timeout): demonstrate
signal connections without g_signal_connect_data().
* demos/gtk-demo/stock_browser.c (do_stock_browser): second
demo of the matter.
* demos/testpixbuf.c (main): running out of equality phrases for the
ChangeLog, but had to adapt connections here as well.
* demos/testanimation.c (progressive_timeout): and for the fun of it,
tackled this the same way.
* tests/testtext.c (create_view): ok, it's becoming a pain at this
point, but had enough enery for one more fix.
* tests/testtreecolumns.c (main): stand up man, do your work!
* tests/testtreeview.c (set_columns_type): ok, this is the last file i
fix, either that's been all of it or CVS gtk is broken yet again.
2001-06-28 17:12:40 +00:00
|
|
|
G_CALLBACK (toggled_callback), tree_view);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Column 4",
|
|
|
|
rend,
|
|
|
|
"active", BOOL_COLUMN,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
|
adapt to handle PangoColor
2001-01-26 Havoc Pennington <hp@redhat.com>
* gtk/gtktextlayout.c (convert_color): adapt to handle PangoColor
* gtk/gtktreeview.c (gtk_tree_view_widget_to_tree_coords): fix to
not offset by TREE_VIEW_HEADER_HEIGHT
(gtk_tree_view_tree_to_widget_coords): fix to not offset by
TREE_VIEW_HEADER_HEIGHT
* configure.in (included_loaders): for me, --with-included-loaders
generates the error "the specified loader yes does not exist",
i.e. the arg defaults to "yes", so change test for value ""
to test for value "yes", and include all loaders in that case.
* gtk/gtkrbtree.c (_gtk_rbtree_get_depth): new function
* gtk/gtktreeview.c (gtk_tree_view_get_cell_rect): fix to properly
handle TREE_VIEW_VERTICAL_SEPARATOR
(gtk_tree_view_bin_expose): fix to consider the row offset as
pointing halfway into vertical separator.
(gtk_tree_view_draw_node_focus_rect): ditto
* gtk/gtkdebug.h, gtk/gtkmain.c (gtk_init_check): Add
--gtk-debug=updates, which causes gdk_window_set_debug_updates
(TRUE) to be called.
* gdk/gdkwindow.c (gdk_window_set_debug_updates): Allow enabling a
debug mode where the invalid region is colored in on invalidate,
so you can see the flicker and know whether your redraw code is
doing a good job.
* gtk/gtktreeview.c (gtk_tree_view_queue_draw_node): Work in
tree window coordinates (clip rect is in tree window coords)
* gtk/Makefile.am: add gtktreednd.[hc]
* gtk/gtkliststore.c: implement gtktreednd interfaces.
* gtk/gtktreednd.c, gtk/gtktreednd.h: New interface to support
drag-and-drop data operations on a model (so we can set up tree
drag-and-drop automatically)
* gtk/testgtk.c: Add a window to change sensitivity in the
GtkLabel test; add a way to change the entry frame in GtkEntry
test
* gtk/gtkentry.c (gtk_entry_set_has_frame):
(gtk_entry_get_has_frame): new functions to remove the frame
around an entry
(gtk_entry_size_request): shrink requisition if no frame
(gtk_entry_draw_focus): don't draw frame if no frame
* gtk/gtkstyle.c (gtk_default_draw_check): draw custom look for
checks inside a cell renderer
(gtk_default_draw_option): ditto for options
* gtk/gtktreeviewcolumn.c (update_button_contents): add/remove
children from the alignment, not the button
(gtk_tree_view_column_init): ref/sink the column, to emulate
GObject refcounting.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_init): ref/sink
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_render):
Use theme functions to draw the toggles
* gdk/gdkpango.c (gdk_pango_get_gc): use GdkRGB to alloc colors
* gdk/gdkpango.h, gdk/gdkpango.c: Add GdkPangoAttrStipple and
GdkPangoAttrEmbossed to use in rendering insensitive text
* gdk/gdkpango.c (gdk_draw_layout_line): render new properties
* gtk/gtkstyle.c (gtk_default_draw_layout): handle sensitivity
using new GDK features
2001-01-26 21:12:05 +00:00
|
|
|
|
2006-03-22 18:38:47 +00:00
|
|
|
rend = gtk_cell_renderer_spin_new ();
|
|
|
|
|
|
|
|
adjustment = gtk_adjustment_new (0, 0, 10000, 100, 100, 100);
|
|
|
|
g_object_set (rend, "editable", TRUE, NULL);
|
|
|
|
g_object_set (rend, "adjustment", adjustment, NULL);
|
|
|
|
|
|
|
|
g_signal_connect (rend, "edited",
|
|
|
|
G_CALLBACK (edited_callback), tree_view);
|
|
|
|
|
adapt to handle PangoColor
2001-01-26 Havoc Pennington <hp@redhat.com>
* gtk/gtktextlayout.c (convert_color): adapt to handle PangoColor
* gtk/gtktreeview.c (gtk_tree_view_widget_to_tree_coords): fix to
not offset by TREE_VIEW_HEADER_HEIGHT
(gtk_tree_view_tree_to_widget_coords): fix to not offset by
TREE_VIEW_HEADER_HEIGHT
* configure.in (included_loaders): for me, --with-included-loaders
generates the error "the specified loader yes does not exist",
i.e. the arg defaults to "yes", so change test for value ""
to test for value "yes", and include all loaders in that case.
* gtk/gtkrbtree.c (_gtk_rbtree_get_depth): new function
* gtk/gtktreeview.c (gtk_tree_view_get_cell_rect): fix to properly
handle TREE_VIEW_VERTICAL_SEPARATOR
(gtk_tree_view_bin_expose): fix to consider the row offset as
pointing halfway into vertical separator.
(gtk_tree_view_draw_node_focus_rect): ditto
* gtk/gtkdebug.h, gtk/gtkmain.c (gtk_init_check): Add
--gtk-debug=updates, which causes gdk_window_set_debug_updates
(TRUE) to be called.
* gdk/gdkwindow.c (gdk_window_set_debug_updates): Allow enabling a
debug mode where the invalid region is colored in on invalidate,
so you can see the flicker and know whether your redraw code is
doing a good job.
* gtk/gtktreeview.c (gtk_tree_view_queue_draw_node): Work in
tree window coordinates (clip rect is in tree window coords)
* gtk/Makefile.am: add gtktreednd.[hc]
* gtk/gtkliststore.c: implement gtktreednd interfaces.
* gtk/gtktreednd.c, gtk/gtktreednd.h: New interface to support
drag-and-drop data operations on a model (so we can set up tree
drag-and-drop automatically)
* gtk/testgtk.c: Add a window to change sensitivity in the
GtkLabel test; add a way to change the entry frame in GtkEntry
test
* gtk/gtkentry.c (gtk_entry_set_has_frame):
(gtk_entry_get_has_frame): new functions to remove the frame
around an entry
(gtk_entry_size_request): shrink requisition if no frame
(gtk_entry_draw_focus): don't draw frame if no frame
* gtk/gtkstyle.c (gtk_default_draw_check): draw custom look for
checks inside a cell renderer
(gtk_default_draw_option): ditto for options
* gtk/gtktreeviewcolumn.c (update_button_contents): add/remove
children from the alignment, not the button
(gtk_tree_view_column_init): ref/sink the column, to emulate
GObject refcounting.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_init): ref/sink
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_render):
Use theme functions to draw the toggles
* gdk/gdkpango.c (gdk_pango_get_gc): use GdkRGB to alloc colors
* gdk/gdkpango.h, gdk/gdkpango.c: Add GdkPangoAttrStipple and
GdkPangoAttrEmbossed to use in rendering insensitive text
* gdk/gdkpango.c (gdk_draw_layout_line): render new properties
* gtk/gtkstyle.c (gtk_default_draw_layout): handle sensitivity
using new GDK features
2001-01-26 21:12:05 +00:00
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Column 5",
|
|
|
|
rend,
|
2006-03-22 18:38:47 +00:00
|
|
|
"text", 4,
|
adapt to handle PangoColor
2001-01-26 Havoc Pennington <hp@redhat.com>
* gtk/gtktextlayout.c (convert_color): adapt to handle PangoColor
* gtk/gtktreeview.c (gtk_tree_view_widget_to_tree_coords): fix to
not offset by TREE_VIEW_HEADER_HEIGHT
(gtk_tree_view_tree_to_widget_coords): fix to not offset by
TREE_VIEW_HEADER_HEIGHT
* configure.in (included_loaders): for me, --with-included-loaders
generates the error "the specified loader yes does not exist",
i.e. the arg defaults to "yes", so change test for value ""
to test for value "yes", and include all loaders in that case.
* gtk/gtkrbtree.c (_gtk_rbtree_get_depth): new function
* gtk/gtktreeview.c (gtk_tree_view_get_cell_rect): fix to properly
handle TREE_VIEW_VERTICAL_SEPARATOR
(gtk_tree_view_bin_expose): fix to consider the row offset as
pointing halfway into vertical separator.
(gtk_tree_view_draw_node_focus_rect): ditto
* gtk/gtkdebug.h, gtk/gtkmain.c (gtk_init_check): Add
--gtk-debug=updates, which causes gdk_window_set_debug_updates
(TRUE) to be called.
* gdk/gdkwindow.c (gdk_window_set_debug_updates): Allow enabling a
debug mode where the invalid region is colored in on invalidate,
so you can see the flicker and know whether your redraw code is
doing a good job.
* gtk/gtktreeview.c (gtk_tree_view_queue_draw_node): Work in
tree window coordinates (clip rect is in tree window coords)
* gtk/Makefile.am: add gtktreednd.[hc]
* gtk/gtkliststore.c: implement gtktreednd interfaces.
* gtk/gtktreednd.c, gtk/gtktreednd.h: New interface to support
drag-and-drop data operations on a model (so we can set up tree
drag-and-drop automatically)
* gtk/testgtk.c: Add a window to change sensitivity in the
GtkLabel test; add a way to change the entry frame in GtkEntry
test
* gtk/gtkentry.c (gtk_entry_set_has_frame):
(gtk_entry_get_has_frame): new functions to remove the frame
around an entry
(gtk_entry_size_request): shrink requisition if no frame
(gtk_entry_draw_focus): don't draw frame if no frame
* gtk/gtkstyle.c (gtk_default_draw_check): draw custom look for
checks inside a cell renderer
(gtk_default_draw_option): ditto for options
* gtk/gtktreeviewcolumn.c (update_button_contents): add/remove
children from the alignment, not the button
(gtk_tree_view_column_init): ref/sink the column, to emulate
GObject refcounting.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_init): ref/sink
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_render):
Use theme functions to draw the toggles
* gdk/gdkpango.c (gdk_pango_get_gc): use GdkRGB to alloc colors
* gdk/gdkpango.h, gdk/gdkpango.c: Add GdkPangoAttrStipple and
GdkPangoAttrEmbossed to use in rendering insensitive text
* gdk/gdkpango.c (gdk_draw_layout_line): render new properties
* gtk/gtkstyle.c (gtk_default_draw_layout): handle sensitivity
using new GDK features
2001-01-26 21:12:05 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
|
2006-03-22 18:38:47 +00:00
|
|
|
#if 0
|
adapt to handle PangoColor
2001-01-26 Havoc Pennington <hp@redhat.com>
* gtk/gtktextlayout.c (convert_color): adapt to handle PangoColor
* gtk/gtktreeview.c (gtk_tree_view_widget_to_tree_coords): fix to
not offset by TREE_VIEW_HEADER_HEIGHT
(gtk_tree_view_tree_to_widget_coords): fix to not offset by
TREE_VIEW_HEADER_HEIGHT
* configure.in (included_loaders): for me, --with-included-loaders
generates the error "the specified loader yes does not exist",
i.e. the arg defaults to "yes", so change test for value ""
to test for value "yes", and include all loaders in that case.
* gtk/gtkrbtree.c (_gtk_rbtree_get_depth): new function
* gtk/gtktreeview.c (gtk_tree_view_get_cell_rect): fix to properly
handle TREE_VIEW_VERTICAL_SEPARATOR
(gtk_tree_view_bin_expose): fix to consider the row offset as
pointing halfway into vertical separator.
(gtk_tree_view_draw_node_focus_rect): ditto
* gtk/gtkdebug.h, gtk/gtkmain.c (gtk_init_check): Add
--gtk-debug=updates, which causes gdk_window_set_debug_updates
(TRUE) to be called.
* gdk/gdkwindow.c (gdk_window_set_debug_updates): Allow enabling a
debug mode where the invalid region is colored in on invalidate,
so you can see the flicker and know whether your redraw code is
doing a good job.
* gtk/gtktreeview.c (gtk_tree_view_queue_draw_node): Work in
tree window coordinates (clip rect is in tree window coords)
* gtk/Makefile.am: add gtktreednd.[hc]
* gtk/gtkliststore.c: implement gtktreednd interfaces.
* gtk/gtktreednd.c, gtk/gtktreednd.h: New interface to support
drag-and-drop data operations on a model (so we can set up tree
drag-and-drop automatically)
* gtk/testgtk.c: Add a window to change sensitivity in the
GtkLabel test; add a way to change the entry frame in GtkEntry
test
* gtk/gtkentry.c (gtk_entry_set_has_frame):
(gtk_entry_get_has_frame): new functions to remove the frame
around an entry
(gtk_entry_size_request): shrink requisition if no frame
(gtk_entry_draw_focus): don't draw frame if no frame
* gtk/gtkstyle.c (gtk_default_draw_check): draw custom look for
checks inside a cell renderer
(gtk_default_draw_option): ditto for options
* gtk/gtktreeviewcolumn.c (update_button_contents): add/remove
children from the alignment, not the button
(gtk_tree_view_column_init): ref/sink the column, to emulate
GObject refcounting.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_init): ref/sink
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_render):
Use theme functions to draw the toggles
* gdk/gdkpango.c (gdk_pango_get_gc): use GdkRGB to alloc colors
* gdk/gdkpango.h, gdk/gdkpango.c: Add GdkPangoAttrStipple and
GdkPangoAttrEmbossed to use in rendering insensitive text
* gdk/gdkpango.c (gdk_draw_layout_line): render new properties
* gtk/gtkstyle.c (gtk_default_draw_layout): handle sensitivity
using new GDK features
2001-01-26 21:12:05 +00:00
|
|
|
|
|
|
|
rend = gtk_cell_renderer_text_new ();
|
|
|
|
|
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Column 6",
|
|
|
|
rend,
|
|
|
|
"text", 4,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
|
|
|
|
|
|
|
|
rend = gtk_cell_renderer_text_new ();
|
|
|
|
|
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Column 7",
|
|
|
|
rend,
|
|
|
|
"text", 5,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
|
|
|
|
|
|
|
|
rend = gtk_cell_renderer_text_new ();
|
|
|
|
|
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Column 8",
|
|
|
|
rend,
|
|
|
|
"text", 6,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
|
|
|
|
|
|
|
|
rend = gtk_cell_renderer_text_new ();
|
|
|
|
|
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Column 9",
|
|
|
|
rend,
|
|
|
|
"text", 7,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
|
|
|
|
|
|
|
|
rend = gtk_cell_renderer_text_new ();
|
|
|
|
|
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Column 10",
|
|
|
|
rend,
|
|
|
|
"text", 8,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-05-06 10:34:56 +00:00
|
|
|
G_GNUC_FALLTHROUGH;
|
2001-01-09 17:45:34 +00:00
|
|
|
|
|
|
|
case COLUMNS_ONE:
|
|
|
|
rend = gtk_cell_renderer_text_new ();
|
|
|
|
|
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Column 0",
|
|
|
|
rend,
|
|
|
|
"text", 0,
|
|
|
|
NULL);
|
2001-01-09 23:24:20 +00:00
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
gtk_tree_view_insert_column (GTK_TREE_VIEW (tree_view), col, 0);
|
2020-03-06 17:05:43 +00:00
|
|
|
break;
|
|
|
|
case COLUMNS_LAST:
|
2001-01-09 17:45:34 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-16 03:49:24 +00:00
|
|
|
static ColumnsType
|
|
|
|
get_columns_type (void)
|
|
|
|
{
|
|
|
|
return current_column_type;
|
|
|
|
}
|
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
static GdkPixbuf *our_pixbuf;
|
|
|
|
|
2001-01-06 01:31:58 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2001-01-08 18:26:05 +00:00
|
|
|
/* MODEL_TYPES, */
|
|
|
|
MODEL_TREE,
|
|
|
|
MODEL_LIST,
|
|
|
|
MODEL_SORTED_TREE,
|
|
|
|
MODEL_SORTED_LIST,
|
2001-01-09 17:45:34 +00:00
|
|
|
MODEL_EMPTY_LIST,
|
|
|
|
MODEL_EMPTY_TREE,
|
2001-01-08 18:26:05 +00:00
|
|
|
MODEL_NULL,
|
|
|
|
MODEL_LAST
|
2001-01-06 01:31:58 +00:00
|
|
|
} ModelType;
|
|
|
|
|
2001-01-08 18:26:05 +00:00
|
|
|
/* FIXME add a custom model to test */
|
2001-01-06 01:31:58 +00:00
|
|
|
static GtkTreeModel *models[MODEL_LAST];
|
2001-01-08 18:26:05 +00:00
|
|
|
static const char *model_names[MODEL_LAST] = {
|
|
|
|
"GtkTreeStore",
|
|
|
|
"GtkListStore",
|
|
|
|
"GtkTreeModelSort wrapping GtkTreeStore",
|
|
|
|
"GtkTreeModelSort wrapping GtkListStore",
|
2001-01-09 17:45:34 +00:00
|
|
|
"Empty GtkListStore",
|
|
|
|
"Empty GtkTreeStore",
|
2001-01-08 18:26:05 +00:00
|
|
|
"NULL (no model)"
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkTreeModel*
|
|
|
|
create_list_model (void)
|
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gint i;
|
2001-01-09 17:45:34 +00:00
|
|
|
GType *t;
|
|
|
|
|
|
|
|
t = get_model_types ();
|
2001-01-08 18:26:05 +00:00
|
|
|
|
2001-06-30 02:38:17 +00:00
|
|
|
store = gtk_list_store_new (N_COLUMNS,
|
|
|
|
t[0], t[1], t[2],
|
|
|
|
t[3], t[4], t[5],
|
|
|
|
t[6], t[7], t[8]);
|
2001-01-08 18:26:05 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 200)
|
|
|
|
{
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
|
|
|
|
msg = g_strdup_printf ("%d", i);
|
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
gtk_list_store_set (store, &iter, 0, msg, 1, "Foo! Foo! Foo!",
|
|
|
|
2, our_pixbuf,
|
|
|
|
3, 7.0, 4, (guint) 9000,
|
|
|
|
5, 'f', 6, 'g',
|
|
|
|
7, TRUE, 8, 23245454,
|
|
|
|
-1);
|
2001-01-08 18:26:05 +00:00
|
|
|
|
|
|
|
g_free (msg);
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_TREE_MODEL (store);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
typesystem_recurse (GType type,
|
|
|
|
GtkTreeIter *parent_iter,
|
|
|
|
GtkTreeStore *store)
|
|
|
|
{
|
|
|
|
GType* children;
|
|
|
|
guint n_children = 0;
|
|
|
|
gint i;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
gtk_tree_store_append (store, &iter, parent_iter);
|
|
|
|
|
2002-02-13 16:40:31 +00:00
|
|
|
str = g_strdup_printf ("%ld", (glong)type);
|
2001-01-09 17:45:34 +00:00
|
|
|
gtk_tree_store_set (store, &iter, 0, str, 1, g_type_name (type),
|
|
|
|
2, our_pixbuf,
|
|
|
|
3, 7.0, 4, (guint) 9000,
|
|
|
|
5, 'f', 6, 'g',
|
|
|
|
7, TRUE, 8, 23245454,
|
|
|
|
-1);
|
2001-01-08 18:26:05 +00:00
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
children = g_type_children (type, &n_children);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < n_children)
|
|
|
|
{
|
|
|
|
typesystem_recurse (children[i], &iter, store);
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (children);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreeModel*
|
|
|
|
create_tree_model (void)
|
|
|
|
{
|
|
|
|
GtkTreeStore *store;
|
|
|
|
gint i;
|
2001-01-09 17:45:34 +00:00
|
|
|
GType *t;
|
2001-01-08 18:26:05 +00:00
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
/* Make the tree more interesting */
|
2011-05-27 02:20:45 +00:00
|
|
|
/* - we need this magic here so we are sure the type ends up being
|
|
|
|
* registered and gcc doesn't optimize away the code */
|
|
|
|
g_type_class_unref (g_type_class_ref (gtk_scrolled_window_get_type ()));
|
|
|
|
g_type_class_unref (g_type_class_ref (gtk_label_get_type ()));
|
2011-06-09 04:21:11 +00:00
|
|
|
g_type_class_unref (g_type_class_ref (gtk_scrollbar_get_type ()));
|
2011-05-27 02:20:45 +00:00
|
|
|
g_type_class_unref (g_type_class_ref (pango_layout_get_type ()));
|
2001-01-09 17:45:34 +00:00
|
|
|
|
|
|
|
t = get_model_types ();
|
|
|
|
|
2001-06-30 02:38:17 +00:00
|
|
|
store = gtk_tree_store_new (N_COLUMNS,
|
|
|
|
t[0], t[1], t[2],
|
|
|
|
t[3], t[4], t[5],
|
|
|
|
t[6], t[7], t[8]);
|
2001-01-08 18:26:05 +00:00
|
|
|
|
|
|
|
i = 0;
|
2001-11-21 23:49:17 +00:00
|
|
|
while (i < G_TYPE_FUNDAMENTAL_MAX)
|
2001-01-08 18:26:05 +00:00
|
|
|
{
|
|
|
|
typesystem_recurse (i, NULL, store);
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_TREE_MODEL (store);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-04-24 01:53:11 +00:00
|
|
|
model_selected (GtkComboBox *combo_box, gpointer data)
|
2001-01-08 18:26:05 +00:00
|
|
|
{
|
|
|
|
GtkTreeView *tree_view = GTK_TREE_VIEW (data);
|
|
|
|
gint hist;
|
|
|
|
|
2010-04-24 01:53:11 +00:00
|
|
|
hist = gtk_combo_box_get_active (combo_box);
|
2001-01-08 18:26:05 +00:00
|
|
|
|
|
|
|
if (models[hist] != gtk_tree_view_get_model (tree_view))
|
|
|
|
{
|
|
|
|
gtk_tree_view_set_model (tree_view, models[hist]);
|
|
|
|
}
|
|
|
|
}
|
2001-01-06 01:31:58 +00:00
|
|
|
|
2001-01-16 03:49:24 +00:00
|
|
|
static void
|
2010-04-24 01:53:11 +00:00
|
|
|
columns_selected (GtkComboBox *combo_box, gpointer data)
|
2001-01-16 03:49:24 +00:00
|
|
|
{
|
|
|
|
GtkTreeView *tree_view = GTK_TREE_VIEW (data);
|
|
|
|
gint hist;
|
|
|
|
|
2010-04-24 01:53:11 +00:00
|
|
|
hist = gtk_combo_box_get_active (combo_box);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
|
|
|
if (hist != get_columns_type ())
|
|
|
|
{
|
|
|
|
set_columns_type (tree_view, hist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
static void
|
2013-01-18 05:08:26 +00:00
|
|
|
on_row_activated (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
g_print ("Row activated\n");
|
|
|
|
}
|
2001-01-19 22:39:19 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2001-01-06 01:31:58 +00:00
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char **argv)
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *sw;
|
|
|
|
GtkWidget *tv;
|
2011-09-27 00:53:31 +00:00
|
|
|
GtkWidget *box;
|
2010-04-24 01:53:11 +00:00
|
|
|
GtkWidget *combo_box;
|
2001-01-08 18:26:05 +00:00
|
|
|
GtkTreeModel *model;
|
2017-11-18 01:19:53 +00:00
|
|
|
GdkContentFormats *targets;
|
2001-01-06 01:31:58 +00:00
|
|
|
gint i;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2001-01-06 01:31:58 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2001-01-06 01:31:58 +00:00
|
|
|
|
2010-12-15 20:36:47 +00:00
|
|
|
if (g_getenv ("RTL"))
|
|
|
|
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
|
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
our_pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) book_closed_xpm);
|
|
|
|
|
2001-01-08 18:26:05 +00:00
|
|
|
#if 0
|
2001-01-06 01:31:58 +00:00
|
|
|
models[MODEL_TYPES] = GTK_TREE_MODEL (gtk_tree_model_types_new ());
|
2001-01-08 18:26:05 +00:00
|
|
|
#endif
|
|
|
|
models[MODEL_LIST] = create_list_model ();
|
|
|
|
models[MODEL_TREE] = create_tree_model ();
|
|
|
|
|
|
|
|
model = create_list_model ();
|
2001-06-14 23:25:52 +00:00
|
|
|
models[MODEL_SORTED_LIST] = gtk_tree_model_sort_new_with_model (model);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_object_unref (model);
|
2001-01-08 18:26:05 +00:00
|
|
|
|
|
|
|
model = create_tree_model ();
|
2001-06-14 23:25:52 +00:00
|
|
|
models[MODEL_SORTED_TREE] = gtk_tree_model_sort_new_with_model (model);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_object_unref (model);
|
2001-01-09 17:45:34 +00:00
|
|
|
|
2001-07-09 17:09:35 +00:00
|
|
|
models[MODEL_EMPTY_LIST] = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_INT));
|
|
|
|
models[MODEL_EMPTY_TREE] = GTK_TREE_MODEL (gtk_tree_store_new (1, G_TYPE_INT));
|
2001-01-08 18:26:05 +00:00
|
|
|
|
|
|
|
models[MODEL_NULL] = NULL;
|
2001-01-09 17:45:34 +00:00
|
|
|
|
|
|
|
run_automated_tests ();
|
2001-01-08 18:26:05 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2006-03-22 18:38:47 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 430, 400);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
2011-09-27 00:53:31 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), box);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
|
|
|
tv = gtk_tree_view_new_with_model (models[0]);
|
2013-01-18 05:08:26 +00:00
|
|
|
g_signal_connect (tv, "row-activated", G_CALLBACK (on_row_activated), NULL);
|
|
|
|
|
2020-02-18 00:41:42 +00:00
|
|
|
targets = gdk_content_formats_new_for_gtype (GTK_TYPE_TREE_ROW_DATA);
|
2001-11-06 19:10:03 +00:00
|
|
|
gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (tv),
|
|
|
|
GDK_BUTTON1_MASK,
|
2017-11-14 21:32:23 +00:00
|
|
|
targets,
|
2001-11-06 19:10:03 +00:00
|
|
|
GDK_ACTION_MOVE | GDK_ACTION_COPY);
|
|
|
|
|
|
|
|
gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW (tv),
|
2017-11-14 21:32:23 +00:00
|
|
|
targets,
|
2001-11-06 19:10:03 +00:00
|
|
|
GDK_ACTION_MOVE | GDK_ACTION_COPY);
|
2017-11-18 01:19:53 +00:00
|
|
|
gdk_content_formats_unref (targets);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
|
|
|
/* Model menu */
|
2010-10-02 16:19:46 +00:00
|
|
|
combo_box = gtk_combo_box_text_new ();
|
2011-09-27 00:53:31 +00:00
|
|
|
gtk_widget_set_halign (combo_box, GTK_ALIGN_CENTER);
|
2010-04-24 01:53:11 +00:00
|
|
|
for (i = 0; i < MODEL_LAST; i++)
|
2010-10-02 16:19:46 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), model_names[i]);
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), combo_box);
|
2010-04-24 01:53:11 +00:00
|
|
|
g_signal_connect (combo_box,
|
2002-10-13 23:22:33 +00:00
|
|
|
"changed",
|
|
|
|
G_CALLBACK (model_selected),
|
|
|
|
tv);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
|
|
|
/* Columns menu */
|
2010-10-02 16:19:46 +00:00
|
|
|
combo_box = gtk_combo_box_text_new ();
|
2011-09-27 00:53:31 +00:00
|
|
|
gtk_widget_set_halign (combo_box, GTK_ALIGN_CENTER);
|
2010-04-24 01:53:11 +00:00
|
|
|
for (i = 0; i < COLUMNS_LAST; i++)
|
2010-10-02 16:19:46 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), column_type_names[i]);
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), combo_box);
|
2001-01-16 03:49:24 +00:00
|
|
|
|
|
|
|
set_columns_type (GTK_TREE_VIEW (tv), COLUMNS_LOTS);
|
2010-04-24 01:53:11 +00:00
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), COLUMNS_LOTS);
|
|
|
|
|
|
|
|
g_signal_connect (combo_box,
|
2002-10-13 23:22:33 +00:00
|
|
|
"changed",
|
|
|
|
G_CALLBACK (columns_selected),
|
|
|
|
tv);
|
2001-01-06 01:31:58 +00:00
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
2011-09-27 00:53:31 +00:00
|
|
|
gtk_widget_set_hexpand (sw, TRUE);
|
|
|
|
gtk_widget_set_vexpand (sw, TRUE);
|
2001-01-06 01:31:58 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2001-01-08 18:26:05 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), sw);
|
2001-01-06 01:31:58 +00:00
|
|
|
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), tv);
|
2001-01-08 18:26:05 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2001-01-06 01:31:58 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2001-01-06 01:31:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GtkTreeModelTypes
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void gtk_tree_model_types_init (GtkTreeModelTypes *model_types);
|
|
|
|
static void gtk_tree_model_types_tree_model_init (GtkTreeModelIface *iface);
|
|
|
|
static gint gtk_real_model_types_get_n_columns (GtkTreeModel *tree_model);
|
|
|
|
static GType gtk_real_model_types_get_column_type (GtkTreeModel *tree_model,
|
|
|
|
gint index);
|
|
|
|
static GtkTreePath *gtk_real_model_types_get_path (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static void gtk_real_model_types_get_value (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint column,
|
|
|
|
GValue *value);
|
|
|
|
static gboolean gtk_real_model_types_iter_next (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static gboolean gtk_real_model_types_iter_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent);
|
|
|
|
static gboolean gtk_real_model_types_iter_has_child (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static gint gtk_real_model_types_iter_n_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static gboolean gtk_real_model_types_iter_nth_child (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
gint n);
|
|
|
|
static gboolean gtk_real_model_types_iter_parent (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *child);
|
|
|
|
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
GType
|
2001-01-06 01:31:58 +00:00
|
|
|
gtk_tree_model_types_get_type (void)
|
|
|
|
{
|
2002-10-13 23:22:33 +00:00
|
|
|
static GType model_types_type = 0;
|
2001-01-06 01:31:58 +00:00
|
|
|
|
|
|
|
if (!model_types_type)
|
|
|
|
{
|
2009-11-06 00:21:09 +00:00
|
|
|
const GTypeInfo model_types_info =
|
2001-01-06 01:31:58 +00:00
|
|
|
{
|
|
|
|
sizeof (GtkTreeModelTypesClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2001-11-18 00:10:57 +00:00
|
|
|
NULL, /* class_init */
|
2001-01-06 01:31:58 +00:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GtkTreeModelTypes),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gtk_tree_model_types_init
|
|
|
|
};
|
|
|
|
|
2009-11-06 00:21:09 +00:00
|
|
|
const GInterfaceInfo tree_model_info =
|
2001-01-06 01:31:58 +00:00
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gtk_tree_model_types_tree_model_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
model_types_type = g_type_register_static (G_TYPE_OBJECT,
|
|
|
|
"GtkTreeModelTypes",
|
|
|
|
&model_types_info, 0);
|
2001-01-06 01:31:58 +00:00
|
|
|
g_type_add_interface_static (model_types_type,
|
|
|
|
GTK_TYPE_TREE_MODEL,
|
|
|
|
&tree_model_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return model_types_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkTreeModelTypes *
|
|
|
|
gtk_tree_model_types_new (void)
|
|
|
|
{
|
|
|
|
GtkTreeModelTypes *retval;
|
|
|
|
|
2004-11-19 23:30:47 +00:00
|
|
|
retval = g_object_new (GTK_TYPE_MODEL_TYPES, NULL);
|
2001-01-06 01:31:58 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_types_tree_model_init (GtkTreeModelIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_n_columns = gtk_real_model_types_get_n_columns;
|
|
|
|
iface->get_column_type = gtk_real_model_types_get_column_type;
|
|
|
|
iface->get_path = gtk_real_model_types_get_path;
|
|
|
|
iface->get_value = gtk_real_model_types_get_value;
|
|
|
|
iface->iter_next = gtk_real_model_types_iter_next;
|
|
|
|
iface->iter_children = gtk_real_model_types_iter_children;
|
|
|
|
iface->iter_has_child = gtk_real_model_types_iter_has_child;
|
|
|
|
iface->iter_n_children = gtk_real_model_types_iter_n_children;
|
|
|
|
iface->iter_nth_child = gtk_real_model_types_iter_nth_child;
|
|
|
|
iface->iter_parent = gtk_real_model_types_iter_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_types_init (GtkTreeModelTypes *model_types)
|
|
|
|
{
|
|
|
|
model_types->stamp = g_random_int ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static GType column_types[] = {
|
|
|
|
G_TYPE_STRING, /* GType */
|
|
|
|
G_TYPE_STRING /* type name */
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_real_model_types_get_n_columns (GtkTreeModel *tree_model)
|
|
|
|
{
|
|
|
|
return G_N_ELEMENTS (column_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
|
|
|
gtk_real_model_types_get_column_type (GtkTreeModel *tree_model,
|
|
|
|
gint index)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (index < G_N_ELEMENTS (column_types), G_TYPE_INVALID);
|
|
|
|
|
|
|
|
return column_types[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Use default implementation of this */
|
|
|
|
static gboolean
|
|
|
|
gtk_real_model_types_get_iter (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The toplevel nodes of the tree are the reserved types, G_TYPE_NONE through
|
|
|
|
* G_TYPE_RESERVED_FUNDAMENTAL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static GtkTreePath *
|
|
|
|
gtk_real_model_types_get_path (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
GtkTreePath *retval;
|
|
|
|
GType type;
|
|
|
|
GType parent;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_TYPES (tree_model), NULL);
|
|
|
|
g_return_val_if_fail (iter != NULL, NULL);
|
|
|
|
|
|
|
|
type = GPOINTER_TO_INT (iter->user_data);
|
|
|
|
|
|
|
|
retval = gtk_tree_path_new ();
|
|
|
|
|
|
|
|
parent = g_type_parent (type);
|
|
|
|
while (parent != G_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
GType* children = g_type_children (parent, NULL);
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
if (!children || children[0] == G_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
g_warning ("bad iterator?");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (children[i] != type)
|
|
|
|
++i;
|
|
|
|
|
|
|
|
gtk_tree_path_prepend_index (retval, i);
|
|
|
|
|
|
|
|
g_free (children);
|
|
|
|
|
|
|
|
type = parent;
|
|
|
|
parent = g_type_parent (parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The fundamental type itself is the index on the toplevel */
|
|
|
|
gtk_tree_path_prepend_index (retval, type);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_real_model_types_get_value (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint column,
|
|
|
|
GValue *value)
|
|
|
|
{
|
|
|
|
GType type;
|
|
|
|
|
|
|
|
type = GPOINTER_TO_INT (iter->user_data);
|
|
|
|
|
|
|
|
switch (column)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
g_value_init (value, G_TYPE_STRING);
|
|
|
|
|
2008-05-25 08:41:15 +00:00
|
|
|
str = g_strdup_printf ("%ld", (long int) type);
|
2001-01-06 01:31:58 +00:00
|
|
|
g_value_set_string (value, str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
g_value_init (value, G_TYPE_STRING);
|
|
|
|
g_value_set_string (value, g_type_name (type));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_warning ("Bad column %d requested", column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_real_model_types_iter_next (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
|
|
|
|
GType parent;
|
|
|
|
GType type;
|
|
|
|
|
|
|
|
type = GPOINTER_TO_INT (iter->user_data);
|
|
|
|
|
|
|
|
parent = g_type_parent (type);
|
2001-11-21 23:49:17 +00:00
|
|
|
|
2001-01-06 01:31:58 +00:00
|
|
|
if (parent == G_TYPE_INVALID)
|
|
|
|
{
|
2001-11-21 23:49:17 +00:00
|
|
|
/* find next _valid_ fundamental type */
|
|
|
|
do
|
|
|
|
type++;
|
|
|
|
while (!g_type_name (type) && type <= G_TYPE_FUNDAMENTAL_MAX);
|
|
|
|
if (type <= G_TYPE_FUNDAMENTAL_MAX)
|
|
|
|
{
|
|
|
|
/* found one */
|
|
|
|
iter->user_data = GINT_TO_POINTER (type);
|
2001-01-06 01:31:58 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GType* children = g_type_children (parent, NULL);
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
g_assert (children != NULL);
|
|
|
|
|
|
|
|
while (children[i] != type)
|
|
|
|
++i;
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
|
|
|
if (children[i] != G_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
iter->user_data = GINT_TO_POINTER (children[i]);
|
2020-03-06 04:01:01 +00:00
|
|
|
g_free (children);
|
2001-01-06 01:31:58 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (children);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_real_model_types_iter_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent)
|
|
|
|
{
|
|
|
|
GType type;
|
|
|
|
GType* children;
|
|
|
|
|
|
|
|
type = GPOINTER_TO_INT (parent->user_data);
|
|
|
|
|
|
|
|
children = g_type_children (type, NULL);
|
|
|
|
|
|
|
|
if (!children || children[0] == G_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
g_free (children);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iter->user_data = GINT_TO_POINTER (children[0]);
|
|
|
|
g_free (children);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_real_model_types_iter_has_child (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
GType type;
|
|
|
|
GType* children;
|
|
|
|
|
|
|
|
type = GPOINTER_TO_INT (iter->user_data);
|
|
|
|
|
|
|
|
children = g_type_children (type, NULL);
|
|
|
|
|
|
|
|
if (!children || children[0] == G_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
g_free (children);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (children);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_real_model_types_iter_n_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
if (iter == NULL)
|
|
|
|
{
|
2001-11-21 23:49:17 +00:00
|
|
|
return G_TYPE_FUNDAMENTAL_MAX;
|
2001-01-06 01:31:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GType type;
|
|
|
|
GType* children;
|
|
|
|
guint n_children = 0;
|
|
|
|
|
|
|
|
type = GPOINTER_TO_INT (iter->user_data);
|
|
|
|
|
|
|
|
children = g_type_children (type, &n_children);
|
|
|
|
|
|
|
|
g_free (children);
|
|
|
|
|
|
|
|
return n_children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_real_model_types_iter_nth_child (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
gint n)
|
|
|
|
{
|
|
|
|
if (parent == NULL)
|
|
|
|
{
|
|
|
|
/* fundamental type */
|
2001-11-21 23:49:17 +00:00
|
|
|
if (n < G_TYPE_FUNDAMENTAL_MAX)
|
2001-01-06 01:31:58 +00:00
|
|
|
{
|
|
|
|
iter->user_data = GINT_TO_POINTER (n);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GType type = GPOINTER_TO_INT (parent->user_data);
|
|
|
|
guint n_children = 0;
|
|
|
|
GType* children = g_type_children (type, &n_children);
|
|
|
|
|
|
|
|
if (n_children == 0)
|
|
|
|
{
|
|
|
|
g_free (children);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (n >= n_children)
|
|
|
|
{
|
|
|
|
g_free (children);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iter->user_data = GINT_TO_POINTER (children[n]);
|
|
|
|
g_free (children);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_real_model_types_iter_parent (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *child)
|
|
|
|
{
|
|
|
|
GType type;
|
|
|
|
GType parent;
|
|
|
|
|
|
|
|
type = GPOINTER_TO_INT (child->user_data);
|
|
|
|
|
|
|
|
parent = g_type_parent (type);
|
|
|
|
|
|
|
|
if (parent == G_TYPE_INVALID)
|
|
|
|
{
|
2001-11-21 23:49:17 +00:00
|
|
|
if (type > G_TYPE_FUNDAMENTAL_MAX)
|
2008-05-25 08:41:15 +00:00
|
|
|
g_warning ("no parent for %ld %s\n",
|
|
|
|
(long int) type,
|
|
|
|
g_type_name (type));
|
2001-01-06 01:31:58 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iter->user_data = GINT_TO_POINTER (parent);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
/*
|
|
|
|
* Automated testing
|
|
|
|
*/
|
|
|
|
|
2009-11-09 05:15:56 +00:00
|
|
|
#if 0
|
|
|
|
|
2001-01-10 23:44:22 +00:00
|
|
|
static void
|
|
|
|
treestore_torture_recurse (GtkTreeStore *store,
|
|
|
|
GtkTreeIter *root,
|
|
|
|
gint depth)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
gint i;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
model = GTK_TREE_MODEL (store);
|
|
|
|
|
|
|
|
if (depth > 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
++depth;
|
|
|
|
|
|
|
|
gtk_tree_store_append (store, &iter, root);
|
|
|
|
|
|
|
|
gtk_tree_model_iter_children (model, &iter, root);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
|
|
|
gtk_tree_store_append (store, &iter, root);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (gtk_tree_model_iter_children (model, &iter, root))
|
|
|
|
gtk_tree_store_remove (store, &iter);
|
|
|
|
|
|
|
|
gtk_tree_store_append (store, &iter, root);
|
|
|
|
|
|
|
|
/* inserts before last node in tree */
|
|
|
|
i = 0;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
|
|
|
gtk_tree_store_insert_before (store, &iter, root, &iter);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inserts after the node before the last node */
|
|
|
|
i = 0;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
|
|
|
gtk_tree_store_insert_after (store, &iter, root, &iter);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inserts after the last node */
|
|
|
|
gtk_tree_store_append (store, &iter, root);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
|
|
|
gtk_tree_store_insert_after (store, &iter, root, &iter);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove everything again */
|
|
|
|
while (gtk_tree_model_iter_children (model, &iter, root))
|
|
|
|
gtk_tree_store_remove (store, &iter);
|
|
|
|
|
|
|
|
|
|
|
|
/* Prepends */
|
|
|
|
gtk_tree_store_prepend (store, &iter, root);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
|
|
|
gtk_tree_store_prepend (store, &iter, root);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove everything again */
|
|
|
|
while (gtk_tree_model_iter_children (model, &iter, root))
|
|
|
|
gtk_tree_store_remove (store, &iter);
|
|
|
|
|
|
|
|
gtk_tree_store_append (store, &iter, root);
|
|
|
|
gtk_tree_store_append (store, &iter, root);
|
|
|
|
gtk_tree_store_append (store, &iter, root);
|
|
|
|
gtk_tree_store_append (store, &iter, root);
|
|
|
|
|
|
|
|
while (gtk_tree_model_iter_children (model, &iter, root))
|
|
|
|
{
|
|
|
|
treestore_torture_recurse (store, &iter, depth);
|
|
|
|
gtk_tree_store_remove (store, &iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-09 05:15:56 +00:00
|
|
|
#endif
|
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
static void
|
|
|
|
run_automated_tests (void)
|
|
|
|
{
|
2001-01-10 23:44:22 +00:00
|
|
|
g_print ("Running automated tests...\n");
|
|
|
|
|
2001-01-09 17:45:34 +00:00
|
|
|
/* FIXME TreePath basic verification */
|
|
|
|
|
2001-01-10 23:44:22 +00:00
|
|
|
/* FIXME generic consistency checks on the models */
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Make sure list store mutations don't crash anything */
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
gint i;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2001-06-30 02:38:17 +00:00
|
|
|
store = gtk_list_store_new (1, G_TYPE_INT);
|
2001-01-10 23:44:22 +00:00
|
|
|
|
|
|
|
model = GTK_TREE_MODEL (store);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2002-02-24 04:18:44 +00:00
|
|
|
while (gtk_tree_model_get_iter_first (model, &iter))
|
2001-01-10 23:44:22 +00:00
|
|
|
gtk_list_store_remove (store, &iter);
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
|
|
|
|
/* inserts before last node in list */
|
|
|
|
i = 0;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
|
|
|
gtk_list_store_insert_before (store, &iter, &iter);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inserts after the node before the last node */
|
|
|
|
i = 0;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
|
|
|
gtk_list_store_insert_after (store, &iter, &iter);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inserts after the last node */
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
|
|
|
gtk_list_store_insert_after (store, &iter, &iter);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove everything again */
|
2002-02-24 04:18:44 +00:00
|
|
|
while (gtk_tree_model_get_iter_first (model, &iter))
|
2001-01-10 23:44:22 +00:00
|
|
|
gtk_list_store_remove (store, &iter);
|
|
|
|
|
|
|
|
|
|
|
|
/* Prepends */
|
|
|
|
gtk_list_store_prepend (store, &iter);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 100)
|
|
|
|
{
|
|
|
|
gtk_list_store_prepend (store, &iter);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove everything again */
|
2002-02-24 04:18:44 +00:00
|
|
|
while (gtk_tree_model_get_iter_first (model, &iter))
|
2001-01-10 23:44:22 +00:00
|
|
|
gtk_list_store_remove (store, &iter);
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_object_unref (store);
|
2001-01-10 23:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Make sure tree store mutations don't crash anything */
|
|
|
|
GtkTreeStore *store;
|
2001-06-26 17:01:53 +00:00
|
|
|
GtkTreeIter root;
|
|
|
|
|
2001-06-30 02:38:17 +00:00
|
|
|
store = gtk_tree_store_new (1, G_TYPE_INT);
|
2001-07-09 17:09:35 +00:00
|
|
|
gtk_tree_store_append (GTK_TREE_STORE (store), &root, NULL);
|
|
|
|
/* Remove test until it is rewritten to work */
|
|
|
|
/* treestore_torture_recurse (store, &root, 0);*/
|
2001-01-10 23:44:22 +00:00
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_object_unref (store);
|
2001-01-10 23:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_print ("Passed.\n");
|
2001-01-09 17:45:34 +00:00
|
|
|
}
|