summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPST 1998 Shawn T. Amundson <amundson@gimp.org>1998-03-02 00:32:52 +0000
committerShawn Amundson <amundson@src.gnome.org>1998-03-02 00:32:52 +0000
commitf6f1ce01c6b33fe75e32c7e76ef5e7fc9ce494ab (patch)
treedca8f578054ea33fd2973ee3eb6d6d38e4a60342
parent80fd0a0c0068cd09d120e1a74df26cf82004a491 (diff)
downloadgtk+-f6f1ce01c6b33fe75e32c7e76ef5e7fc9ce494ab.tar.gz
Required changes for version change to 0.99.4
Sun Mar 1 15:18:38 PST 1998 Shawn T. Amundson <amundson@gimp.org> * Required changes for version change to 0.99.4 * gtk/gtktree.[ch]: patch from J. Bolliet to correct some bugs * gtk/testgtk.c: added test here from J. Bolliet, removed testtree * gtk/clist: gtk-abilleira-981602-0, allows gtk_clist_set_pixmap and gtk_clist_set_pixtext to not require a mask * gdk/gdkdraw.c,gdk.h: gtk-trow-980217-0 adds gdk_draw_lines and fixes some things about gdk_draw_polygon
-rw-r--r--ChangeLog14
-rw-r--r--ChangeLog.pre-2-014
-rw-r--r--ChangeLog.pre-2-1014
-rw-r--r--ChangeLog.pre-2-214
-rw-r--r--ChangeLog.pre-2-414
-rw-r--r--ChangeLog.pre-2-614
-rw-r--r--ChangeLog.pre-2-814
-rw-r--r--NEWS9
-rw-r--r--README5
-rw-r--r--configure.in2
-rw-r--r--docs/faq/gtkfaq.sgml54
-rw-r--r--docs/gtkfaq.sgml54
-rw-r--r--gdk/gdk.h6
-rw-r--r--gdk/gdkdraw.c54
-rw-r--r--glib/configure.in2
-rw-r--r--gtk/Makefile.am11
-rw-r--r--gtk/gtkclist.c50
-rw-r--r--gtk/gtktree.c141
-rw-r--r--gtk/gtktree.h4
-rw-r--r--gtk/gtktreeitem.c15
-rw-r--r--gtk/gtktreeitem.h2
-rw-r--r--gtk/testgtk.c500
-rw-r--r--gtk/testtree.c244
-rw-r--r--tests/testgtk.c500
24 files changed, 1452 insertions, 299 deletions
diff --git a/ChangeLog b/ChangeLog
index 6de5e54424..e172eb6c33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Sun Mar 1 15:18:38 PST 1998 Shawn T. Amundson <amundson@gimp.org>
+
+ * Required changes for version change to 0.99.4
+
+ * gtk/gtktree.[ch]: patch from J. Bolliet to correct some bugs
+ * gtk/testgtk.c: added test here from J. Bolliet, removed testtree
+
+ * gtk/clist: gtk-abilleira-981602-0, allows gtk_clist_set_pixmap
+ and gtk_clist_set_pixtext to not require a mask
+
+ * gdk/gdkdraw.c,gdk.h: gtk-trow-980217-0
+ adds gdk_draw_lines and fixes some things about
+ gdk_draw_polygon
+
Sun Mar 1 17:40:58 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkpixmap.c: Make sure either the window or
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index 6de5e54424..e172eb6c33 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,17 @@
+Sun Mar 1 15:18:38 PST 1998 Shawn T. Amundson <amundson@gimp.org>
+
+ * Required changes for version change to 0.99.4
+
+ * gtk/gtktree.[ch]: patch from J. Bolliet to correct some bugs
+ * gtk/testgtk.c: added test here from J. Bolliet, removed testtree
+
+ * gtk/clist: gtk-abilleira-981602-0, allows gtk_clist_set_pixmap
+ and gtk_clist_set_pixtext to not require a mask
+
+ * gdk/gdkdraw.c,gdk.h: gtk-trow-980217-0
+ adds gdk_draw_lines and fixes some things about
+ gdk_draw_polygon
+
Sun Mar 1 17:40:58 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkpixmap.c: Make sure either the window or
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 6de5e54424..e172eb6c33 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,17 @@
+Sun Mar 1 15:18:38 PST 1998 Shawn T. Amundson <amundson@gimp.org>
+
+ * Required changes for version change to 0.99.4
+
+ * gtk/gtktree.[ch]: patch from J. Bolliet to correct some bugs
+ * gtk/testgtk.c: added test here from J. Bolliet, removed testtree
+
+ * gtk/clist: gtk-abilleira-981602-0, allows gtk_clist_set_pixmap
+ and gtk_clist_set_pixtext to not require a mask
+
+ * gdk/gdkdraw.c,gdk.h: gtk-trow-980217-0
+ adds gdk_draw_lines and fixes some things about
+ gdk_draw_polygon
+
Sun Mar 1 17:40:58 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkpixmap.c: Make sure either the window or
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index 6de5e54424..e172eb6c33 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,17 @@
+Sun Mar 1 15:18:38 PST 1998 Shawn T. Amundson <amundson@gimp.org>
+
+ * Required changes for version change to 0.99.4
+
+ * gtk/gtktree.[ch]: patch from J. Bolliet to correct some bugs
+ * gtk/testgtk.c: added test here from J. Bolliet, removed testtree
+
+ * gtk/clist: gtk-abilleira-981602-0, allows gtk_clist_set_pixmap
+ and gtk_clist_set_pixtext to not require a mask
+
+ * gdk/gdkdraw.c,gdk.h: gtk-trow-980217-0
+ adds gdk_draw_lines and fixes some things about
+ gdk_draw_polygon
+
Sun Mar 1 17:40:58 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkpixmap.c: Make sure either the window or
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index 6de5e54424..e172eb6c33 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,17 @@
+Sun Mar 1 15:18:38 PST 1998 Shawn T. Amundson <amundson@gimp.org>
+
+ * Required changes for version change to 0.99.4
+
+ * gtk/gtktree.[ch]: patch from J. Bolliet to correct some bugs
+ * gtk/testgtk.c: added test here from J. Bolliet, removed testtree
+
+ * gtk/clist: gtk-abilleira-981602-0, allows gtk_clist_set_pixmap
+ and gtk_clist_set_pixtext to not require a mask
+
+ * gdk/gdkdraw.c,gdk.h: gtk-trow-980217-0
+ adds gdk_draw_lines and fixes some things about
+ gdk_draw_polygon
+
Sun Mar 1 17:40:58 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkpixmap.c: Make sure either the window or
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index 6de5e54424..e172eb6c33 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,17 @@
+Sun Mar 1 15:18:38 PST 1998 Shawn T. Amundson <amundson@gimp.org>
+
+ * Required changes for version change to 0.99.4
+
+ * gtk/gtktree.[ch]: patch from J. Bolliet to correct some bugs
+ * gtk/testgtk.c: added test here from J. Bolliet, removed testtree
+
+ * gtk/clist: gtk-abilleira-981602-0, allows gtk_clist_set_pixmap
+ and gtk_clist_set_pixtext to not require a mask
+
+ * gdk/gdkdraw.c,gdk.h: gtk-trow-980217-0
+ adds gdk_draw_lines and fixes some things about
+ gdk_draw_polygon
+
Sun Mar 1 17:40:58 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkpixmap.c: Make sure either the window or
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index 6de5e54424..e172eb6c33 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,17 @@
+Sun Mar 1 15:18:38 PST 1998 Shawn T. Amundson <amundson@gimp.org>
+
+ * Required changes for version change to 0.99.4
+
+ * gtk/gtktree.[ch]: patch from J. Bolliet to correct some bugs
+ * gtk/testgtk.c: added test here from J. Bolliet, removed testtree
+
+ * gtk/clist: gtk-abilleira-981602-0, allows gtk_clist_set_pixmap
+ and gtk_clist_set_pixtext to not require a mask
+
+ * gdk/gdkdraw.c,gdk.h: gtk-trow-980217-0
+ adds gdk_draw_lines and fixes some things about
+ gdk_draw_polygon
+
Sun Mar 1 17:40:58 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkpixmap.c: Make sure either the window or
diff --git a/NEWS b/NEWS
index 9d954176b2..43d24b57a0 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-Forthcoming Changes for GTK+ 0.99.4:
+Overview of Changes in GTK+ 0.99.4:
* Reference counting revolution integrated.
Refer to docs/refcounting.txt on this issue.
@@ -23,6 +23,10 @@ Forthcoming Changes for GTK+ 0.99.4:
* Many enhancements to GtkNotebook.
* New widget GtkSpinButton, check out testgtk.
* New widget GtkTipsQuery for letting the user query tooltips of widgets.
+* Addition of gtkeditable base widget to encapsulate selection and
+ clipboard handling (Entry and Text use this)
+* Text widget more complete
+* Additions to GtkStatusBar to make it complete.
* Gdk now supports regions.
* Access masks for widget arguments (GTK_ARG_READABLE/GTK_ARG_WRITABLE).
* Function replacements:
@@ -32,7 +36,8 @@ Forthcoming Changes for GTK+ 0.99.4:
* Support for quit handlers in gtk_main().
* Motif window mangaer hints support.
* Widget arguments are now flagged for readability/writability.
-* Various FAQ updates.
+* Additions to documentation.
+* Various FAQ updates. (FAQ now included)
* Clean ups and many many bug fixes by a lot of people all over the place.
* New, long and descriptive ChangeLog entries for bored readers ;)
diff --git a/README b/README
index 33cd6bf33f..db87a72807 100644
--- a/README
+++ b/README
@@ -1,10 +1,13 @@
-This is GTK+ version 0.99.3. GTK, which stands for the Gimp ToolKit,
+This is GTK+ version 0.99.4. GTK, which stands for the Gimp ToolKit,
is a library for creating graphical user interfaces.
The official ftp site is:
ftp://ftp.gimp.org/pub/gtk
+The official web site is:
+ http://www.gimp.org/gtk
+
Patches can be uploaded to:
ftp://ftp.gimp.org/incoming
diff --git a/configure.in b/configure.in
index 94572ef61c..db95e1a5c6 100644
--- a/configure.in
+++ b/configure.in
@@ -6,7 +6,7 @@ cflags_set=${CFLAGS+set}
GTK_MAJOR_VERSION=0
GTK_MINOR_VERSION=99
-GTK_MICRO_VERSION=3
+GTK_MICRO_VERSION=4
GTK_VERSION=$GTK_MAJOR_VERSION.$GTK_MINOR_VERSION.$GTK_MICRO_VERSION
# For automake.
diff --git a/docs/faq/gtkfaq.sgml b/docs/faq/gtkfaq.sgml
index b8efe3c4a3..8daeaf7d78 100644
--- a/docs/faq/gtkfaq.sgml
+++ b/docs/faq/gtkfaq.sgml
@@ -696,6 +696,60 @@ uses glib (see below), it will be more portable and safer to use on multiple pla
<!-- Examples, anybody? I've been mulling some over. NF -->
+<sect1>How do I use color allocation?
+<p>
+One of the nice things about GDK is that it's based on top of Xlib; this is also
+a problem, especially in the area of color management. If you want to use color
+in your program (drawing a rectangle or such, your code should look something like
+this:
+<tscreen>
+<verb>
+{
+ GdkColor *color;
+ int width, height;
+ GtkWidget *widget;
+
+ ...
+
+ /* first, create a GC to draw on */
+ gc = gdk_gc_new(widget->window);
+
+ /* find proper dimensions for rectangle */
+ gdk_window_get_size(widget->window, &width, &height);
+
+ /* the color we want to use */
+ color = (GdkColor *)malloc(sizeof(GdkColor));
+
+ /* red, green, and blue are passed values, indicating the RGB triple
+ * of the color we want to draw. Note that the values of the RGB components
+ * within the GdkColor are taken from 0 to 65535, not 0 to 255.
+ */
+ color->red = red * (65535/255);
+ color->green = green * (65535/255);
+ color->blue = blue * (65535/255);
+
+ /* the pixel value indicates the index in the colormap of the color.
+ * it is simply a combination of the RGB values we set earlier
+ */
+ color->pixel = (gulong)(red*65536 + green*256 + blue);
+
+ /* However, the pixel valule is only truly valid on 24-bit (TrueColor)
+ * displays. Therefore, this call is required so that GDK and X can
+ * give us the closest color available in the colormap
+ */
+ gdk_color_alloc(gtk_widget_get_colormap(widget), color);
+
+ /* set the foreground to our color */
+ gdk_gc_set_foreground(gc, color);
+
+ /* draw the rectangle */
+ gdk_draw_rectangle(widget->window, gc, 1, 0, 0, width, height);
+
+ ...
+}
+</verb>
+</tscreen>
+
<!-- ***************************************************************** -->
<sect>About glib
<!-- ***************************************************************** -->
diff --git a/docs/gtkfaq.sgml b/docs/gtkfaq.sgml
index b8efe3c4a3..8daeaf7d78 100644
--- a/docs/gtkfaq.sgml
+++ b/docs/gtkfaq.sgml
@@ -696,6 +696,60 @@ uses glib (see below), it will be more portable and safer to use on multiple pla
<!-- Examples, anybody? I've been mulling some over. NF -->
+<sect1>How do I use color allocation?
+<p>
+One of the nice things about GDK is that it's based on top of Xlib; this is also
+a problem, especially in the area of color management. If you want to use color
+in your program (drawing a rectangle or such, your code should look something like
+this:
+<tscreen>
+<verb>
+{
+ GdkColor *color;
+ int width, height;
+ GtkWidget *widget;
+
+ ...
+
+ /* first, create a GC to draw on */
+ gc = gdk_gc_new(widget->window);
+
+ /* find proper dimensions for rectangle */
+ gdk_window_get_size(widget->window, &width, &height);
+
+ /* the color we want to use */
+ color = (GdkColor *)malloc(sizeof(GdkColor));
+
+ /* red, green, and blue are passed values, indicating the RGB triple
+ * of the color we want to draw. Note that the values of the RGB components
+ * within the GdkColor are taken from 0 to 65535, not 0 to 255.
+ */
+ color->red = red * (65535/255);
+ color->green = green * (65535/255);
+ color->blue = blue * (65535/255);
+
+ /* the pixel value indicates the index in the colormap of the color.
+ * it is simply a combination of the RGB values we set earlier
+ */
+ color->pixel = (gulong)(red*65536 + green*256 + blue);
+
+ /* However, the pixel valule is only truly valid on 24-bit (TrueColor)
+ * displays. Therefore, this call is required so that GDK and X can
+ * give us the closest color available in the colormap
+ */
+ gdk_color_alloc(gtk_widget_get_colormap(widget), color);
+
+ /* set the foreground to our color */
+ gdk_gc_set_foreground(gc, color);
+
+ /* draw the rectangle */
+ gdk_draw_rectangle(widget->window, gc, 1, 0, 0, width, height);
+
+ ...
+}
+</verb>
+</tscreen>
+
<!-- ***************************************************************** -->
<sect>About glib
<!-- ***************************************************************** -->
diff --git a/gdk/gdk.h b/gdk/gdk.h
index 6c2cb59bdc..3ccab2c3d0 100644
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -563,6 +563,12 @@ void gdk_draw_segments (GdkDrawable *drawable,
GdkGC *gc,
GdkSegment *segs,
gint nsegs);
+void gdk_draw_lines (GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkPoint *points,
+ gint npoints);
+
+
/* Selections
diff --git a/gdk/gdkdraw.c b/gdk/gdkdraw.c
index de23f6c4f5..3d39d3faac 100644
--- a/gdk/gdkdraw.c
+++ b/gdk/gdkdraw.c
@@ -142,6 +142,9 @@ gdk_draw_polygon (GdkDrawable *drawable,
{
GdkWindowPrivate *drawable_private;
GdkGCPrivate *gc_private;
+ GdkPoint *local_points = points;
+ gint local_npoints = npoints;
+ gint local_alloc = 0;
g_return_if_fail (drawable != NULL);
g_return_if_fail (gc != NULL);
@@ -158,14 +161,24 @@ gdk_draw_polygon (GdkDrawable *drawable,
}
else
{
- XDrawLines (drawable_private->xdisplay, drawable_private->xwindow,
- gc_private->xgc, (XPoint*) points, npoints, CoordModeOrigin);
-
if ((points[0].x != points[npoints-1].x) ||
- (points[0].y != points[npoints-1].y))
- XDrawLine (drawable_private->xdisplay, drawable_private->xwindow,
- gc_private->xgc, points[npoints-1].x, points[npoints-1].y,
- points[0].x, points[0].y);
+ (points[0].y != points[npoints-1].y))
+ {
+ local_alloc = 1;
+ ++local_npoints;
+ local_points = (GdkPoint*) g_malloc (local_npoints * sizeof(GdkPoint));
+ memcpy (local_points, points, npoints * sizeof(GdkPoint));
+ local_points[npoints].x = points[0].x;
+ local_points[npoints].y = points[0].y;
+ }
+
+ XDrawLines (drawable_private->xdisplay, drawable_private->xwindow,
+ gc_private->xgc,
+ (XPoint*) local_points, local_npoints,
+ CoordModeOrigin);
+
+ if (local_alloc)
+ g_free (local_points);
}
}
@@ -401,3 +414,30 @@ gdk_draw_segments (GdkDrawable *drawable,
(XSegment *) segs,
nsegs);
}
+
+void
+gdk_draw_lines (GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkPoint *points,
+ gint npoints)
+{
+ GdkWindowPrivate *drawable_private;
+ GdkGCPrivate *gc_private;
+
+ if (npoints <= 0)
+ return;
+
+ g_return_if_fail (drawable != NULL);
+ g_return_if_fail (points != NULL);
+ g_return_if_fail (gc != NULL);
+
+ drawable_private = (GdkWindowPrivate*) drawable;
+ gc_private = (GdkGCPrivate*) gc;
+
+ XDrawLines (drawable_private->xdisplay,
+ drawable_private->xwindow,
+ gc_private->xgc,
+ (XPoint *) points,
+ npoints,
+ CoordModeOrigin);
+}
diff --git a/glib/configure.in b/glib/configure.in
index 0816180ee5..9925feebb5 100644
--- a/glib/configure.in
+++ b/glib/configure.in
@@ -5,7 +5,7 @@ AC_INIT(glist.c)
cflags_set=${CFLAGS+set}
dnl Initialize automake stuff
-AM_INIT_AUTOMAKE(glib, 0.99.3)
+AM_INIT_AUTOMAKE(glib, 0.99.4)
# Specify a configuration file
AM_CONFIG_HEADER(glibconfig.h)
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index c311c02402..6892253c4c 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -220,7 +220,7 @@ EXTRA_DIST = \
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/glib @x_cflags@
-noinst_PROGRAMS = testgtk testinput testselection simple testtree
+noinst_PROGRAMS = testgtk testinput testselection simple
testgtk_LDADD = \
libgtk.la \
$(top_builddir)/gdk/libgdk.la \
@@ -253,14 +253,6 @@ simple_LDADD = \
$(top_builddir)/glib/libglib.la \
-lm
-testtree_LDADD = \
- libgtk.la \
- $(top_builddir)/gdk/libgdk.la \
- @x_ldflags@ \
- @x_libs@ \
- $(top_builddir)/glib/libglib.la \
- -lm
-
DEPS = \
$(top_builddir)/gtk/libgtk.la \
$(top_builddir)/gdk/libgdk.la \
@@ -270,7 +262,6 @@ testgtk_DEPENDENCIES = $(DEPS)
testinput_DEPENDENCIES = $(DEPS)
testselection_DEPENDENCIES = $(DEPS)
simple_DEPENDENCIES = $(DEPS)
-testtree_DEPENDENCIES = $(DEPS)
.PHONY: files
diff --git a/gtk/gtkclist.c b/gtk/gtkclist.c
index a6a873cc74..e4cef3d624 100644
--- a/gtk/gtkclist.c
+++ b/gtk/gtkclist.c
@@ -986,7 +986,9 @@ gtk_clist_set_pixmap (GtkCList * clist,
clist_row = (g_list_nth (clist->row_list, row))->data;
gdk_pixmap_ref (pixmap);
- gdk_pixmap_ref (mask);
+
+ if (mask) gdk_pixmap_ref (mask);
+
cell_set_pixmap (clist, clist_row, column, pixmap, mask);
/* redraw the list if it's not frozen */
@@ -1019,9 +1021,11 @@ gtk_clist_get_pixmap (GtkCList * clist,
return 0;
if (pixmap)
+ {
*pixmap = GTK_CELL_PIXMAP (clist_row->cell[column])->pixmap;
- if (mask)
+ // mask can be NULL
*mask = GTK_CELL_PIXMAP (clist_row->cell[column])->mask;
+ }
return 1;
}
@@ -1047,7 +1051,7 @@ gtk_clist_set_pixtext (GtkCList * clist,
clist_row = (g_list_nth (clist->row_list, row))->data;
gdk_pixmap_ref (pixmap);
- gdk_pixmap_ref (mask);
+ if (mask) gdk_pixmap_ref (mask);
cell_set_pixtext (clist, clist_row, column, text, spacing, pixmap, mask);
/* redraw the list if it's not frozen */
@@ -1087,8 +1091,9 @@ gtk_clist_get_pixtext (GtkCList * clist,
*spacing = GTK_CELL_PIXTEXT (clist_row->cell[column])->spacing;
if (pixmap)
*pixmap = GTK_CELL_PIXTEXT (clist_row->cell[column])->pixmap;
- if (mask)
- *mask = GTK_CELL_PIXTEXT (clist_row->cell[column])->mask;
+
+ // mask can be NULL
+ *mask = GTK_CELL_PIXTEXT (clist_row->cell[column])->mask;
return 1;
}
@@ -2536,9 +2541,11 @@ draw_row (GtkCList * clist,
ydest = (clip_rectangle.y + (clip_rectangle.height / 2)) - height / 2 +
clist_row->cell[i].vertical;
- gdk_gc_set_clip_mask (fg_gc, GTK_CELL_PIXMAP (clist_row->cell[i])->mask);
- gdk_gc_set_clip_origin (fg_gc, xdest, ydest);
-
+ if (GTK_CELL_PIXMAP (clist_row->cell[i])->mask)
+ {
+ gdk_gc_set_clip_mask (fg_gc, GTK_CELL_PIXMAP (clist_row->cell[i])->mask);
+ gdk_gc_set_clip_origin (fg_gc, xdest, ydest);
+ }
gdk_draw_pixmap (clist->clist_window,
fg_gc,
GTK_CELL_PIXMAP (clist_row->cell[i])->pixmap,
@@ -2547,8 +2554,11 @@ draw_row (GtkCList * clist,
ydest,
pixmap_width, height);
- gdk_gc_set_clip_origin (fg_gc, 0, 0);
- gdk_gc_set_clip_mask (fg_gc, NULL);
+ if (GTK_CELL_PIXMAP (clist_row->cell[i])->mask)
+ {
+ gdk_gc_set_clip_origin (fg_gc, 0, 0);
+ gdk_gc_set_clip_mask (fg_gc, NULL);
+ }
break;
case GTK_CELL_PIXTEXT:
@@ -2559,9 +2569,12 @@ draw_row (GtkCList * clist,
ydest = (clip_rectangle.y + (clip_rectangle.height / 2)) - height / 2 +
clist_row->cell[i].vertical;
- gdk_gc_set_clip_mask (fg_gc, GTK_CELL_PIXTEXT (clist_row->cell[i])->mask);
- gdk_gc_set_clip_origin (fg_gc, xdest, ydest);
-
+ if (GTK_CELL_PIXTEXT (clist_row->cell[i])->mask)
+ {
+ gdk_gc_set_clip_mask (fg_gc, GTK_CELL_PIXTEXT (clist_row->cell[i])->mask);
+ gdk_gc_set_clip_origin (fg_gc, xdest, ydest);
+ }
+
gdk_draw_pixmap (clist->clist_window,
fg_gc,
GTK_CELL_PIXTEXT (clist_row->cell[i])->pixmap,
@@ -3495,13 +3508,15 @@ cell_empty (GtkCList * clist,
case GTK_CELL_PIXMAP:
gdk_pixmap_unref (GTK_CELL_PIXMAP (clist_row->cell[column])->pixmap);
- gdk_bitmap_unref (GTK_CELL_PIXMAP (clist_row->cell[column])->mask);
+ if (GTK_CELL_PIXMAP (clist_row->cell[column])->mask)
+ gdk_bitmap_unref (GTK_CELL_PIXMAP (clist_row->cell[column])->mask);
break;
case GTK_CELL_PIXTEXT:
g_free (GTK_CELL_PIXTEXT (clist_row->cell[column])->text);
gdk_pixmap_unref (GTK_CELL_PIXTEXT (clist_row->cell[column])->pixmap);
- gdk_bitmap_unref (GTK_CELL_PIXTEXT (clist_row->cell[column])->mask);
+ if (GTK_CELL_PIXTEXT (clist_row->cell[column])->mask)
+ gdk_bitmap_unref (GTK_CELL_PIXTEXT (clist_row->cell[column])->mask);
break;
case GTK_CELL_WIDGET:
@@ -3539,10 +3554,11 @@ cell_set_pixmap (GtkCList * clist,
{
cell_empty (clist, clist_row, column);
- if (pixmap && mask)
+ if (pixmap)
{
clist_row->cell[column].type = GTK_CELL_PIXMAP;
GTK_CELL_PIXMAP (clist_row->cell[column])->pixmap = pixmap;
+ // We set the mask even if it is NULL
GTK_CELL_PIXMAP (clist_row->cell[column])->mask = mask;
}
}
@@ -3558,7 +3574,7 @@ cell_set_pixtext (GtkCList * clist,
{
cell_empty (clist, clist_row, column);
- if (text && pixmap && mask)
+ if (text && pixmap)
{
clist_row->cell[column].type = GTK_CELL_PIXTEXT;
GTK_CELL_PIXTEXT (clist_row->cell[column])->text = g_strdup (text);
diff --git a/gtk/gtktree.c b/gtk/gtktree.c
index 4f839ccd0b..e753a9a44a 100644
--- a/gtk/gtktree.c
+++ b/gtk/gtktree.c
@@ -578,7 +578,9 @@ gtk_tree_motion_notify (GtkWidget *widget,
g_return_val_if_fail (GTK_IS_TREE (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
+#ifdef TREE_DEBUG
g_print("gtk_tree_motion_notify\n");
+#endif /* TREE_DEBUG */
return FALSE;
}
@@ -635,6 +637,20 @@ gtk_tree_remove_item (GtkTree *container,
g_list_free (item_list);
}
+/* used by gtk_tree_remove_items to make the function independant of
+ order in list of items to remove.
+ Sort item bu depth in tree */
+static gint
+gtk_tree_sort_item_by_depth(GtkWidget* a, GtkWidget* b)
+{
+ if((GTK_TREE(a->parent)->level) < (GTK_TREE(b->parent)->level))
+ return 1;
+ if((GTK_TREE(a->parent)->level) > (GTK_TREE(b->parent)->level))
+ return -1;
+
+ return 0;
+}
+
void
gtk_tree_remove_items (GtkTree *tree,
GList *items)
@@ -642,40 +658,96 @@ gtk_tree_remove_items (GtkTree *tree,
GtkWidget *widget;
GList *selected_widgets;
GList *tmp_list;
- GtkTree *real_tree, *root_tree;
+ GList *sorted_list;
+ GtkTree *real_tree;
+ GtkTree *root_tree;
g_return_if_fail (tree != NULL);
g_return_if_fail (GTK_IS_TREE (tree));
+#ifdef TREE_DEBUG
+ g_print("+ gtk_tree_remove_items [ tree %#x items list %#x ]\n", (int)tree, (int)items);
+#endif /* TREE_DEBUG */
+
root_tree = GTK_TREE(GTK_TREE_ROOT_TREE(tree));
tmp_list = items;
selected_widgets = NULL;
+ sorted_list = NULL;
widget = NULL;
+#ifdef TREE_DEBUG
+ g_print("* sort list by depth\n");
+#endif /* TREE_DEBUG */
+ while(tmp_list)
+ {
+#ifdef TREE_DEBUG
+ g_print("* item [%#x] depth [%d]\n",
+ (int)tmp_list->data,
+ (int)GTK_TREE(GTK_WIDGET(tmp_list->data)->parent)->level);
+#endif /* TREE_DEBUG */
+
+ sorted_list = g_list_insert_sorted(sorted_list,
+ tmp_list->data,
+ (GCompareFunc)gtk_tree_sort_item_by_depth);
+ tmp_list = g_list_next(tmp_list);
+ }
+
+#ifdef TREE_DEBUG
+ /* print sorted list */
+ g_print("* sorted list result\n");
+ tmp_list = sorted_list;
+ while(tmp_list)
+ {
+ g_print("* item [%#x] depth [%d]\n",
+ (int)tmp_list->data,
+ (int)GTK_TREE(GTK_WIDGET(tmp_list->data)->parent)->level);
+ tmp_list = g_list_next(tmp_list);
+ }
+#endif /* TREE_DEBUG */
+
+#ifdef TREE_DEBUG
+ g_print("* scan sorted list\n");
+#endif /* TREE_DEBUG */
+ tmp_list = sorted_list;
while (tmp_list)
{
widget = tmp_list->data;
tmp_list = tmp_list->next;
+#ifdef TREE_DEBUG
+ g_print("* item [%#x] subtree [%#x]\n",
+ (int)widget, (int)GTK_TREE_ITEM_SUBTREE(widget));
+#endif /* TREE_DEBUG */
+
/* get real owner of this widget */
real_tree = GTK_TREE(widget->parent);
+#ifdef TREE_DEBUG
+ g_print("* subtree having this widget [%#x]\n", (int)real_tree);
+#endif /* TREE_DEBUG */
+
if (widget->state == GTK_STATE_SELECTED)
- selected_widgets = g_list_prepend (selected_widgets, widget);
+ {
+ selected_widgets = g_list_prepend (selected_widgets, widget);
+#ifdef TREE_DEBUG
+ g_print("* selected widget - adding it in selected list [%#x]\n",
+ (int)selected_widgets);
+#endif /* TREE_DEBUG */
+ }
/* remove this item of his real parent */
+#ifdef TREE_DEBUG
+ g_print("* remove widget of his owner tree\n");
+#endif /* TREE_DEBUG */
real_tree->children = g_list_remove (real_tree->children, widget);
- /* delete subtree if there is no children in it */
- if(real_tree->children == NULL &&
- real_tree != root_tree)
- {
- gtk_tree_item_remove_subtree(GTK_TREE_ITEM(real_tree->tree_owner));
- }
-
/* remove subtree associate at this item if it exist */
if(GTK_TREE_ITEM(widget)->subtree)
{
+#ifdef TREE_DEBUG
+ g_print("* remove subtree associate at this item [%#x]\n",
+ (int) GTK_TREE_ITEM(widget)->subtree);
+#endif /* TREE_DEBUG */
if (GTK_WIDGET_MAPPED (GTK_TREE_ITEM(widget)->subtree))
gtk_widget_unmap (GTK_TREE_ITEM(widget)->subtree);
@@ -683,36 +755,81 @@ gtk_tree_remove_items (GtkTree *tree,
GTK_TREE_ITEM(widget)->subtree = NULL;
}
- /* remove really widget for this item */
+ /* really remove widget for this item */
+#ifdef TREE_DEBUG
+ g_print("* unmap and unparent widget [%#x]\n", (int)widget);
+#endif /* TREE_DEBUG */
if (GTK_WIDGET_MAPPED (widget))
gtk_widget_unmap (widget);
gtk_widget_unparent (widget);
+
+ /* delete subtree if there is no children in it */
+ if(real_tree->children == NULL &&
+ real_tree != root_tree)
+ {
+#ifdef TREE_DEBUG
+ g_print("* owner tree don't have children ... destroy it\n");
+#endif /* TREE_DEBUG */
+ gtk_tree_item_remove_subtree(GTK_TREE_ITEM(real_tree->tree_owner));
+ }
+
+#ifdef TREE_DEBUG
+ g_print("* next item in list\n");
+#endif /* TREE_DEBUG */
}
if (selected_widgets)
{
+#ifdef TREE_DEBUG
+ g_print("* scan selected item list\n");
+#endif /* TREE_DEBUG */
tmp_list = selected_widgets;
while (tmp_list)
{
widget = tmp_list->data;
tmp_list = tmp_list->next;
- gtk_tree_unselect_child (tree, widget);
+#ifdef TREE_DEBUG
+ g_print("* widget [%#x] subtree [%#x]\n",
+ (int)widget, (int)GTK_TREE_ITEM_SUBTREE(widget));
+#endif /* TREE_DEBUG */
+
+ /* remove widget of selection */
+ root_tree->selection = g_list_remove (root_tree->selection, widget);
+
+ /* unref it to authorize is destruction */
+ gtk_widget_unref (widget);
}
+
+ /* emit only one selection_changed signal */
+ gtk_signal_emit (GTK_OBJECT (root_tree),
+ tree_signals[SELECTION_CHANGED]);
}
+#ifdef TREE_DEBUG
+ g_print("* free selected_widgets list\n");
+#endif /* TREE_DEBUG */
g_list_free (selected_widgets);
+ g_list_free (sorted_list);
if (root_tree->children && !root_tree->selection &&
(root_tree->selection_mode == GTK_SELECTION_BROWSE))
{
+#ifdef TREE_DEBUG
+ g_print("* BROWSE mode, select another item\n");
+#endif /* TREE_DEBUG */
widget = root_tree->children->data;
gtk_tree_select_child (root_tree, widget);
}
if (GTK_WIDGET_VISIBLE (root_tree))
- gtk_widget_queue_resize (GTK_WIDGET (root_tree));
+ {
+#ifdef TREE_DEBUG
+ g_print("* query queue resizing for root_tree\n");
+#endif /* TREE_DEBUG */
+ gtk_widget_queue_resize (GTK_WIDGET (root_tree));
+ }
}
void
diff --git a/gtk/gtktree.h b/gtk/gtktree.h
index aaacd86c2f..a764b3ea1e 100644
--- a/gtk/gtktree.h
+++ b/gtk/gtktree.h
@@ -18,6 +18,8 @@
#ifndef __GTK_TREE_H__
#define __GTK_TREE_H__
+/* set this flag to enable tree debugging output */
+/* #define TREE_DEBUG */
#include <gdk/gdk.h>
#include <gtk/gtkcontainer.h>
@@ -32,7 +34,7 @@ extern "C" {
#define GTK_TREE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_tree_get_type (), GtkTreeClass)
#define GTK_IS_TREE(obj) GTK_CHECK_TYPE (obj, gtk_tree_get_type ())
-#define GTK_IS_ROOT_TREE(obj) (GTK_TREE(obj)->root_tree == NULL)
+#define GTK_IS_ROOT_TREE(obj) (GTK_TREE(obj)->root_tree == obj)
#define GTK_TREE_ROOT_TREE(obj) (GTK_TREE(obj)->root_tree ? GTK_TREE(obj)->root_tree : GTK_TREE(obj))
#define GTK_TREE_SELECTION(obj) (GTK_TREE_ROOT_TREE(obj)->selection)
diff --git a/gtk/gtktreeitem.c b/gtk/gtktreeitem.c
index 04bdeb5d74..7b01510ab9 100644
--- a/gtk/gtktreeitem.c
+++ b/gtk/gtktreeitem.c
@@ -633,8 +633,12 @@ gtk_tree_item_draw_focus (GtkWidget *widget)
widget->allocation.width - 1 - dx,
widget->allocation.height - 1);
- if(GTK_TREE(widget->parent)->view_line)
- gtk_tree_item_draw_lines(widget);
+ if(GTK_TREE(widget->parent)->view_line &&
+ (!GTK_IS_ROOT_TREE(widget->parent) ||
+ (GTK_IS_ROOT_TREE(widget->parent) && GTK_TREE_ITEM(widget)->subtree != NULL)))
+ {
+ gtk_tree_item_draw_lines(widget);
+ }
}
}
@@ -836,6 +840,10 @@ gtk_tree_item_destroy (GtkObject *object)
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_TREE_ITEM (object));
+#ifdef TREE_DEBUG
+ g_print("+ gtk_tree_item_destroy [object %#x]\n", (int)object);
+#endif /* TREE_DEBUG */
+
item = GTK_TREE_ITEM(object);
/* free sub tree if it exist */
@@ -877,6 +885,9 @@ gtk_tree_item_destroy (GtkObject *object)
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+#ifdef TREE_DEBUG
+ g_print("- gtk_tree_item_destroy\n");
+#endif /* TREE_DEBUG */
}
void
diff --git a/gtk/gtktreeitem.h b/gtk/gtktreeitem.h
index 6affddd3dc..035e016330 100644
--- a/gtk/gtktreeitem.h
+++ b/gtk/gtktreeitem.h
@@ -32,7 +32,7 @@ extern "C" {
#define GTK_TREE_ITEM_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_tree_item_get_type (), GtkTreeItemClass)
#define GTK_IS_TREE_ITEM(obj) GTK_CHECK_TYPE (obj, gtk_tree_item_get_type ())
-#define GTK_TREE_ITEM_SUBTREE(obj) GTK_TREE_ITEM(obj)->subtree;
+#define GTK_TREE_ITEM_SUBTREE(obj) GTK_TREE_ITEM(obj)->subtree
typedef struct _GtkTreeItem GtkTreeItem;
typedef struct _GtkTreeItemClass GtkTreeItemClass;
diff --git a/gtk/testgtk.c b/gtk/testgtk.c
index 61619b8ff5..36765ca606 100644
--- a/gtk/testgtk.c
+++ b/gtk/testgtk.c
@@ -29,6 +29,30 @@ static GtkWidget *sheets = NULL;
static GtkWidget *rings = NULL;
void create_shapes(void);
+
+/* macro, structure and variables used by tree window demos */
+#define DEFAULT_NUMBER_OF_ITEM 3
+#define DEFAULT_RECURSION_LEVEL 3
+
+struct {
+ GSList* selection_mode_group;
+ GtkWidget* single_button;
+ GtkWidget* browse_button;
+ GtkWidget* multiple_button;
+ GtkWidget* draw_line_button;
+ GtkWidget* view_line_button;
+ GtkWidget* no_root_item_button;
+ GtkWidget* nb_item_spinner;
+ GtkWidget* recursion_spinner;
+} sTreeSampleSelection;
+
+typedef struct sTreeButtons {
+ guint nb_item_add;
+ GtkWidget* add_button;
+ GtkWidget* remove_button;
+} sTreeButtons;
+/* end of tree section */
+
void
destroy_window (GtkWidget *widget,
GtkWidget **window)
@@ -992,6 +1016,481 @@ handle_box_child_signal (GtkHandleBox *hb,
action);
}
+/* funtions used by tree window demos */
+static guint
+cb_tree_delete_event(GtkWidget* w)
+{
+ return TRUE;
+}
+
+static void
+cb_tree_destroy_event(GtkWidget* w)
+{
+ sTreeButtons* tree_buttons;
+
+ /* free buttons structure associate at this tree */
+ tree_buttons = gtk_object_get_user_data(GTK_OBJECT(w));
+ free(tree_buttons);
+}
+static void
+cb_add_new_item(GtkWidget* w, GtkTree* tree)
+{
+ sTreeButtons* tree_buttons;
+ GList* selected_list;
+ GtkWidget* selected_item;
+ GtkWidget* subtree;
+ GtkWidget* item_new;
+ char buffer[255];
+
+ tree_buttons = gtk_object_get_user_data(GTK_OBJECT(tree));
+
+ selected_list = GTK_TREE_SELECTION(tree);
+
+ if(selected_list == NULL)
+ {
+ /* there is no item in tree */
+ subtree = GTK_WIDGET(tree);
+ }
+ else
+ {
+ /* list can have only one element */
+ selected_item = GTK_WIDGET(selected_list->data);
+
+ subtree = GTK_TREE_ITEM_SUBTREE(selected_item);
+
+ if(subtree == NULL)
+ {
+ /* current selected item have not subtree ... create it */
+ subtree = gtk_tree_new();
+ gtk_tree_item_set_subtree(GTK_TREE_ITEM(selected_item),
+ subtree);
+ }
+ }
+
+ /* at this point, we know which subtree will be used to add new item */
+ /* create a new item */
+ sprintf(buffer, "item add %d", tree_buttons->nb_item_add);
+ item_new = gtk_tree_item_new_with_label(buffer);
+ gtk_tree_append(GTK_TREE(subtree), item_new);
+ gtk_widget_show(item_new);
+
+ tree_buttons->nb_item_add++;
+}
+
+static void
+cb_remove_item(GtkWidget*w, GtkTree* tree)
+{
+ GList* selected_list;
+ GList* clear_list;
+
+ selected_list = GTK_TREE_SELECTION(tree);
+
+ clear_list = NULL;
+
+ while (selected_list)
+ {
+ clear_list = g_list_prepend (clear_list, selected_list->data);
+ selected_list = selected_list->next;
+ }
+
+ clear_list = g_list_reverse (clear_list);
+ gtk_tree_remove_items(tree, clear_list);
+
+ g_list_free (clear_list);
+}
+
+static void
+cb_tree_changed(GtkTree* tree)
+{
+ sTreeButtons* tree_buttons;
+ GList* selected_list;
+ guint nb_selected;
+
+ tree_buttons = gtk_object_get_user_data(GTK_OBJECT(tree));
+
+ selected_list = GTK_TREE_SELECTION(tree);
+ nb_selected = g_list_length(selected_list);
+
+ if(nb_selected == 0)
+ {
+ if(tree->children == NULL)
+ gtk_widget_set_sensitive(tree_buttons->add_button, TRUE);
+ else
+ gtk_widget_set_sensitive(tree_buttons->add_button, FALSE);
+ gtk_widget_set_sensitive(tree_buttons->remove_button, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(tree_buttons->remove_button, TRUE);
+ gtk_widget_set_sensitive(tree_buttons->add_button, (nb_selected == 1));
+ }
+}
+
+static void
+create_subtree(GtkWidget* item, guint level, guint nb_item_max, guint recursion_level_max)
+{
+ GtkWidget* item_subtree;
+ GtkWidget* item_new;
+ guint nb_item;
+ char buffer[255];
+ int no_root_item;
+
+ if(level == recursion_level_max) return;
+
+ if(level == -1)
+ {
+ /* query with no root item */
+ level = 0;
+ item_subtree = item;
+ no_root_item = 1;
+ }
+ else
+ {
+ /* query with no root item */
+ /* create subtree and associate it with current item */
+ item_subtree = gtk_tree_new();
+ no_root_item = 0;
+ }
+
+ for(nb_item = 0; nb_item < nb_item_max; nb_item++)
+ {
+ sprintf(buffer, "item %d-%d", level, nb_item);
+ item_new = gtk_tree_item_new_with_label(buffer);
+ gtk_tree_append(GTK_TREE(item_subtree), item_new);
+ create_subtree(item_new, level+1, nb_item_max, recursion_level_max);
+ gtk_widget_show(item_new);
+ }
+
+ if(!no_root_item)
+ gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), item_subtree);
+}
+
+static void
+create_tree_sample(guint selection_mode,
+ guint draw_line, guint view_line, guint no_root_item,
+ guint nb_item_max, guint recursion_level_max)
+{
+ GtkWidget* window;
+ GtkWidget* box1;
+ GtkWidget* box2;
+ GtkWidget* separator;
+ GtkWidget* button;
+ GtkWidget* scrolled_win;
+ GtkWidget* root_tree;
+ GtkWidget* root_item;
+ sTreeButtons* tree_buttons;
+
+ /* create tree buttons struct */
+ if((tree_buttons = g_malloc(sizeof(sTreeButtons))) == NULL)
+ {
+ g_error("can't allocate memory for tree structure !\n");
+ return;
+ }
+ tree_buttons->nb_item_add = 0;
+
+ /* create top level window */
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), "Tree Sample");
+ gtk_signal_connect(GTK_OBJECT (window), "delete_event",
+ (GtkSignalFunc) cb_tree_delete_event, NULL);
+ gtk_signal_connect(GTK_OBJECT(window), "destroy",
+ (GtkSignalFunc) cb_tree_destroy_event, NULL);
+ gtk_object_set_user_data(GTK_OBJECT(window), tree_buttons);
+
+ box1 = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(window), box1);
+ gtk_widget_show(box1);
+
+ /* create tree box */
+ box2 = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(box1), box2, TRUE, TRUE, 0);
+ gtk_container_border_width(GTK_CONTAINER(box2), 5);
+ gtk_widget_show(box2);
+
+ /* create scrolled window */
+ scrolled_win = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_box_pack_start (GTK_BOX (box2), scrolled_win, TRUE, TRUE, 0);
+ gtk_widget_set_usize (scrolled_win, 200, 200);
+ gtk_widget_show (scrolled_win);
+
+ /* create root tree widget */
+ root_tree = gtk_tree_new();
+ gtk_signal_connect(GTK_OBJECT(root_tree), "selection_changed",
+ (GtkSignalFunc)cb_tree_changed,
+ (gpointer)NULL);
+ gtk_object_set_user_data(GTK_OBJECT(root_tree), tree_buttons);
+ gtk_container_add(GTK_CONTAINER(scrolled_win), root_tree);
+ gtk_tree_set_selection_mode(GTK_TREE(root_tree), selection_mode);
+ gtk_tree_set_view_lines(GTK_TREE(root_tree), draw_line);
+ gtk_tree_set_view_mode(GTK_TREE(root_tree), !view_line);
+ gtk_widget_show(root_tree);
+
+ if ( no_root_item )
+ {
+ /* set root tree to subtree function with root item variable */
+ root_item = GTK_WIDGET(root_tree);
+ }
+ else
+ {
+ /* create root tree item widget */
+ root_item = gtk_tree_item_new_with_label("root item");
+ gtk_tree_append(GTK_TREE(root_tree), root_item);
+ gtk_widget_show(root_item);
+ }
+ create_subtree(root_item, -no_root_item, nb_item_max, recursion_level_max);
+
+ box2 = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(box2), 5);
+ gtk_widget_show(box2);
+
+ button = gtk_button_new_with_label("Add Item");
+ gtk_widget_set_sensitive(button, FALSE);
+ gtk_signal_connect(GTK_OBJECT (button), "clicked",
+ (GtkSignalFunc) cb_add_new_item,
+ (gpointer)root_tree);
+ gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ tree_buttons->add_button = button;
+
+ button = gtk_button_new_with_label("Remove Item(s)");
+ gtk_widget_set_sensitive(button, FALSE);
+ gtk_signal_connect(GTK_OBJECT (button), "clicked",
+ (GtkSignalFunc) cb_remove_item,
+ (gpointer)root_tree);
+ gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ tree_buttons->remove_button = button;
+
+ /* create separator */
+ separator = gtk_hseparator_new();
+ gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, FALSE, 0);
+ gtk_widget_show(separator);
+
+ /* create button box */
+ box2 = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(box2), 5);
+ gtk_widget_show(box2);
+
+ button = gtk_button_new_with_label("Close");
+ gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);
+ gtk_signal_connect_object(GTK_OBJECT (button), "clicked",
+ (GtkSignalFunc) gtk_widget_destroy,
+ GTK_OBJECT(window));
+ gtk_widget_show(button);
+
+ gtk_widget_show(window);
+}
+
+static void
+cb_create_tree(GtkWidget* w)
+{
+ guint selection_mode;
+ guint view_line;
+ guint draw_line;
+ guint no_root_item;
+ guint nb_item;
+ guint recursion_level;
+
+ /* get selection mode choice */
+ if(GTK_TOGGLE_BUTTON(sTreeSampleSelection.single_button)->active)
+ selection_mode = GTK_SELECTION_SINGLE;
+ else
+ if(GTK_TOGGLE_BUTTON(sTreeSampleSelection.browse_button)->active)
+ selection_mode = GTK_SELECTION_BROWSE;
+ else
+ if(GTK_TOGGLE_BUTTON(sTreeSampleSelection.multiple_button)->active)
+ selection_mode = GTK_SELECTION_MULTIPLE;
+
+ /* get options choice */
+ draw_line = GTK_TOGGLE_BUTTON(sTreeSampleSelection.draw_line_button)->active;
+ view_line = GTK_TOGGLE_BUTTON(sTreeSampleSelection.view_line_button)->active;
+ no_root_item = GTK_TOGGLE_BUTTON(sTreeSampleSelection.no_root_item_button)->active;
+
+ /* get levels */
+ nb_item = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sTreeSampleSelection.nb_item_spinner));
+ recursion_level = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sTreeSampleSelection.recursion_spinner));
+
+ create_tree_sample(selection_mode, draw_line, view_line, no_root_item, nb_item, recursion_level);
+}
+
+void
+create_tree_mode_window(void)
+{
+ static GtkWidget* window;
+ GtkWidget* box1;
+ GtkWidget* box2;
+ GtkWidget* box3;
+ GtkWidget* box4;
+ GtkWidget* box5;
+ GtkWidget* button;
+ GtkWidget* frame;
+ GtkWidget* separator;
+ GtkWidget* label;
+ GtkWidget* spinner;
+ GtkAdjustment *adj;
+
+ if (!window)
+ {
+ /* create toplevel window */
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), "Tree Mode Selection Window");
+ gtk_signal_connect(GTK_OBJECT (window), "delete_event",
+ (GtkSignalFunc) gtk_main_quit, NULL);
+ gtk_signal_connect (GTK_OBJECT (window), "destroy",
+ GTK_SIGNAL_FUNC(destroy_window), &window);
+ box1 = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(window), box1);
+ gtk_widget_show(box1);
+
+ /* create upper box - selection box */
+ box2 = gtk_vbox_new(FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(box1), box2, TRUE, TRUE, 0);
+ gtk_container_border_width(GTK_CONTAINER(box2), 5);
+ gtk_widget_show(box2);
+
+ box3 = gtk_hbox_new(FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(box2), box3, TRUE, TRUE, 0);
+ gtk_widget_show(box3);
+
+ /* create selection mode frame */
+ frame = gtk_frame_new("Selection Mode");
+ gtk_box_pack_start(GTK_BOX(box3), frame, TRUE, TRUE, 0);
+ gtk_widget_show(frame);
+
+ box4 = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(frame), box4);
+ gtk_container_border_width(GTK_CONTAINER(box4), 5);
+ gtk_widget_show(box4);
+
+ /* create radio button */
+ button = gtk_radio_button_new_with_label(NULL, "SINGLE");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ sTreeSampleSelection.single_button = button;
+
+ button = gtk_radio_button_new_with_label(gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
+ "BROWSE");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ sTreeSampleSelection.browse_button = button;
+
+ button = gtk_radio_button_new_with_label(gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
+ "MULTIPLE");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ sTreeSampleSelection.multiple_button = button;
+
+ sTreeSampleSelection.selection_mode_group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
+
+ /* create option mode frame */
+ frame = gtk_frame_new("Options");
+ gtk_box_pack_start(GTK_BOX(box3), frame, TRUE, TRUE, 0);
+ gtk_widget_show(frame);
+
+ box4 = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(frame), box4);
+ gtk_container_border_width(GTK_CONTAINER(box4), 5);
+ gtk_widget_show(box4);
+
+ /* create check button */
+ button = gtk_check_button_new_with_label("Draw line");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
+ gtk_widget_show(button);
+ sTreeSampleSelection.draw_line_button = button;
+
+ button = gtk_check_button_new_with_label("View Line mode");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
+ gtk_widget_show(button);
+ sTreeSampleSelection.view_line_button = button;
+
+ button = gtk_check_button_new_with_label("Without Root item");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ sTreeSampleSelection.no_root_item_button = button;
+
+ /* create recursion parameter */
+ frame = gtk_frame_new("Size Parameters");
+ gtk_box_pack_start(GTK_BOX(box2), frame, TRUE, TRUE, 0);
+ gtk_widget_show(frame);
+
+ box4 = gtk_hbox_new(FALSE, 5);
+ gtk_container_add(GTK_CONTAINER(frame), box4);
+ gtk_container_border_width(GTK_CONTAINER(box4), 5);
+ gtk_widget_show(box4);
+
+ /* create number of item spin button */
+ box5 = gtk_hbox_new(FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(box4), box5, FALSE, FALSE, 0);
+ gtk_widget_show(box5);
+
+ label = gtk_label_new("Number of Item");
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_box_pack_start (GTK_BOX (box5), label, FALSE, TRUE, 0);
+ gtk_widget_show(label);
+
+ adj = (GtkAdjustment *) gtk_adjustment_new ((gfloat)DEFAULT_NUMBER_OF_ITEM, 1.0, 255.0, 1.0,
+ 5.0, 0.0);
+ spinner = gtk_spin_button_new (adj, 0, 0);
+ gtk_box_pack_start (GTK_BOX (box5), spinner, FALSE, TRUE, 0);
+ gtk_widget_show(spinner);
+ sTreeSampleSelection.nb_item_spinner = spinner;
+
+ /* create recursion level spin button */
+ box5 = gtk_hbox_new(FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(box4), box5, FALSE, FALSE, 0);
+ gtk_widget_show(box5);
+
+ label = gtk_label_new("Depth Level");
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_box_pack_start (GTK_BOX (box5), label, FALSE, TRUE, 0);
+ gtk_widget_show(label);
+
+ adj = (GtkAdjustment *) gtk_adjustment_new ((gfloat)DEFAULT_RECURSION_LEVEL, 0.0, 255.0, 1.0,
+ 5.0, 0.0);
+ spinner = gtk_spin_button_new (adj, 0, 0);
+ gtk_box_pack_start (GTK_BOX (box5), spinner, FALSE, TRUE, 0);
+ gtk_widget_show(spinner);
+ sTreeSampleSelection.recursion_spinner = spinner;
+
+ /* create horizontal separator */
+ separator = gtk_hseparator_new();
+ gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, FALSE, 0);
+ gtk_widget_show(separator);
+
+ /* create bottom button box */
+ box2 = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(box2), 5);
+ gtk_widget_show(box2);
+
+ button = gtk_button_new_with_label("Create Tree Sample");
+ gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);
+ gtk_signal_connect(GTK_OBJECT (button), "clicked",
+ (GtkSignalFunc) cb_create_tree, NULL);
+ gtk_widget_show(button);
+
+ button = gtk_button_new_with_label("Close");
+ gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);
+ gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
+ GTK_SIGNAL_FUNC(gtk_widget_destroy),
+ GTK_OBJECT (window));
+ gtk_widget_show(button);
+
+ }
+ if (!GTK_WIDGET_VISIBLE (window))
+ gtk_widget_show (window);
+ else
+ gtk_widget_destroy (window);
+}
+
+/* end of function used by tree demos */
+
static void
create_handle_box ()
{
@@ -4703,6 +5202,7 @@ create_main_window ()
{ "spinbutton", create_spins },
{ "list", create_list },
{ "clist", create_clist},
+ { "tree", create_tree_mode_window},
{ "color selection", create_color_selection },
{ "file selection", create_file_selection },
{ "dialog", create_dialog },
diff --git a/gtk/testtree.c b/gtk/testtree.c
deleted file mode 100644
index 20d4e3e917..0000000000
--- a/gtk/testtree.c
+++ /dev/null
@@ -1,244 +0,0 @@
-#include "gtk.h"
-
-typedef struct sTreeButtons {
- GtkWidget *button_add, *button_remove;
-} sTreeButton;
-
-static gint cb_delete_event() {
- return TRUE;
-}
-static void cb_destroy_event() {
- gtk_main_quit();
-}
-static void cb_tree_changed(GtkTree* tree) {
- sTreeButton* tree_buttons;
- GList* selected;
- gint nb_selected;
-
- g_print("selection changed !\n");
-
- tree_buttons = gtk_object_get_user_data(GTK_OBJECT(tree));
-
- selected = tree->selection;
- nb_selected = g_list_length(selected);
-
- if(nb_selected == 0) {
- if(tree->children == NULL)
- gtk_widget_set_sensitive(tree_buttons->button_add, TRUE);
- else
- gtk_widget_set_sensitive(tree_buttons->button_add, FALSE);
- gtk_widget_set_sensitive(tree_buttons->button_remove, FALSE);
- } else {
- gtk_widget_set_sensitive(tree_buttons->button_remove, TRUE);
- gtk_widget_set_sensitive(tree_buttons->button_add, (nb_selected == 1));
- }
-}
-
-static void add_tree_item(GtkWidget* w, GtkTree* tree) {
- static gint nb_item_add = 0;
- GList* selected;
- gint nb_selected;
- GtkTreeItem *selected_item;
- GtkWidget* new_item;
- GtkWidget* subtree;
- gchar buffer[255];
-
- selected = GTK_TREE_SELECTION(tree);
- nb_selected = g_list_length(selected);
- selected_item = NULL;
-
- if(nb_selected > 1) return;
-
- if(nb_selected == 0 && tree->children != NULL) return;
-
- if(tree->children == NULL) {
- subtree = GTK_WIDGET(tree);
- } else {
- selected_item = GTK_TREE_ITEM(selected->data);
- subtree = GTK_TREE_ITEM_SUBTREE(selected_item);
- }
- if(!subtree) { /* create a new subtree if not exist */
- subtree = gtk_tree_new();
- gtk_signal_connect(GTK_OBJECT(subtree), "selection_changed",
- (GtkSignalFunc)cb_tree_changed,
- (gpointer)NULL);
- gtk_tree_item_set_subtree(GTK_TREE_ITEM(selected_item), subtree);
- }
-
- /* create a new item */
- sprintf(buffer, "new item %d", nb_item_add++);
- new_item = gtk_tree_item_new_with_label(buffer);
- gtk_tree_append(GTK_TREE(subtree), new_item);
- gtk_widget_show(new_item);
-}
-
-static void remove_tree_item(GtkWidget* w, GtkTree* tree) {
- GList* selected, *clear_list;
- GtkTree* root_tree;
-
- root_tree = GTK_TREE_ROOT_TREE(tree);
- selected = GTK_TREE_SELECTION(tree);
-
- clear_list = NULL;
-
- while (selected) {
- clear_list = g_list_prepend (clear_list, selected->data);
- selected = selected->next;
- }
-
- if(clear_list) {
- clear_list = g_list_reverse (clear_list);
- gtk_tree_remove_items(root_tree, clear_list);
-
- selected = clear_list;
-
- while (selected) {
- gtk_widget_destroy (GTK_WIDGET (selected->data));
- selected = selected->next;
- }
-
- g_list_free (clear_list);
- }
-}
-
-void create_tree_item(GtkWidget* parent, int level, int nb_item, int level_max) {
- int i;
- char buffer[255];
- GtkWidget *item, *tree;
-
- for(i = 0; i<nb_item; i++) {
-
- sprintf(buffer, "item %d-%d", level, i);
- item = gtk_tree_item_new_with_label(buffer);
- gtk_tree_append(GTK_TREE(parent), item);
- gtk_widget_show(item);
-
- if(level < level_max) {
- tree = gtk_tree_new();
-
- gtk_signal_connect(GTK_OBJECT(tree), "selection_changed",
- (GtkSignalFunc)cb_tree_changed,
- (gpointer)NULL);
- create_tree_item(tree, level+1, nb_item, level_max);
- gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree);
-/* gtk_tree_item_expand(GTK_TREE_ITEM(item)); */
-
- }
- }
-
-}
-
-void create_tree_page(GtkWidget* parent, GtkSelectionMode mode,
- char* page_name) {
- GtkWidget *root, *scrolled_win;
- GtkWidget *root_item, *root_subtree;
- GtkWidget *box, *label;
- GtkWidget *button;
- sTreeButton* tree_buttons;
-
- /* create notebook page */
- box = gtk_vbox_new(FALSE, 5);
- gtk_container_border_width (GTK_CONTAINER (box), 5);
- gtk_widget_show (box);
-
- label = gtk_label_new(page_name);
- gtk_notebook_append_page(GTK_NOTEBOOK(parent), box, label);
-
- scrolled_win = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_box_pack_start (GTK_BOX (box), scrolled_win, TRUE, TRUE, 0);
- gtk_widget_set_usize (scrolled_win, 200, 200);
- gtk_widget_show (scrolled_win);
-
- root = gtk_tree_new();
- gtk_container_add(GTK_CONTAINER(scrolled_win), root);
- gtk_tree_set_selection_mode(GTK_TREE(root), mode);
-/* gtk_tree_set_view_lines(GTK_TREE(root), 0); */
-/* gtk_tree_set_view_mode(GTK_TREE(root), GTK_TREE_VIEW_ITEM); */
- gtk_signal_connect(GTK_OBJECT(root), "selection_changed",
- (GtkSignalFunc)cb_tree_changed,
- (gpointer)NULL);
- gtk_widget_show(root);
-
- root_item = gtk_tree_item_new_with_label("root");
- gtk_tree_append(GTK_TREE(root), root_item);
- gtk_widget_show(root_item);
-
- root_subtree = gtk_tree_new();
- gtk_signal_connect(GTK_OBJECT(root_subtree), "selection_changed",
- (GtkSignalFunc)cb_tree_changed,
- (gpointer)NULL);
- create_tree_item(root_subtree, 1, 3, 3);
- gtk_tree_item_set_subtree(GTK_TREE_ITEM(root_item), root_subtree);
-
- tree_buttons = g_malloc(sizeof(sTreeButton));
-
- button = gtk_button_new_with_label("Add");
- gtk_box_pack_start(GTK_BOX (box), button, TRUE, TRUE, 0);
- gtk_signal_connect(GTK_OBJECT(button), "clicked",
- (GtkSignalFunc)add_tree_item,
- (gpointer)root);
- gtk_widget_set_sensitive(button, FALSE);
- gtk_widget_show(button);
- tree_buttons->button_add = button;
-
- button = gtk_button_new_with_label("Remove");
- gtk_box_pack_start(GTK_BOX (box), button, TRUE, TRUE, 0);
- gtk_signal_connect(GTK_OBJECT(button), "clicked",
- (GtkSignalFunc)remove_tree_item,
- (gpointer)root);
- gtk_widget_set_sensitive(button, FALSE);
- gtk_widget_show(button);
- tree_buttons->button_remove = button;
-
- gtk_object_set_user_data(GTK_OBJECT(root), (gpointer)tree_buttons);
-}
-
-int main(int argc, char** argv)
-{
- GtkWidget* window, *notebook;
- GtkWidget* box1;
- GtkWidget* separator;
- GtkWidget* button;
-
- gtk_init (&argc, &argv);
-
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(window), "Test Tree");
- gtk_signal_connect (GTK_OBJECT (window), "delete_event",
- (GtkSignalFunc) cb_delete_event, NULL);
- gtk_signal_connect (GTK_OBJECT (window), "destroy",
- (GtkSignalFunc) cb_destroy_event, NULL);
- box1 = gtk_vbox_new(FALSE, 0);
- gtk_container_add(GTK_CONTAINER(window), box1);
- gtk_widget_show(box1);
-
- /* create notebook */
- notebook = gtk_notebook_new ();
- gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
- gtk_box_pack_start (GTK_BOX (box1), notebook, TRUE, TRUE, 0);
- gtk_widget_show (notebook);
-
- /* create unique selection page */
- create_tree_page(notebook, GTK_SELECTION_SINGLE, "Single");
- create_tree_page(notebook, GTK_SELECTION_BROWSE, "Browse");
- create_tree_page(notebook, GTK_SELECTION_MULTIPLE, "Multiple");
-
- separator = gtk_hseparator_new();
- gtk_box_pack_start(GTK_BOX (box1), separator, TRUE, TRUE, 0);
- gtk_widget_show (separator);
-
- button = gtk_button_new_with_label("Close");
- gtk_box_pack_start(GTK_BOX (box1), button, TRUE, TRUE, 0);
- gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
- (GtkSignalFunc)gtk_widget_destroy,
- GTK_OBJECT(window));
- gtk_widget_show(button);
-
- gtk_widget_show(window);
-
- gtk_main();
-
- return 0;
-}
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 61619b8ff5..36765ca606 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -29,6 +29,30 @@ static GtkWidget *sheets = NULL;
static GtkWidget *rings = NULL;
void create_shapes(void);
+
+/* macro, structure and variables used by tree window demos */
+#define DEFAULT_NUMBER_OF_ITEM 3
+#define DEFAULT_RECURSION_LEVEL 3
+
+struct {
+ GSList* selection_mode_group;
+ GtkWidget* single_button;
+ GtkWidget* browse_button;
+ GtkWidget* multiple_button;
+ GtkWidget* draw_line_button;
+ GtkWidget* view_line_button;
+ GtkWidget* no_root_item_button;
+ GtkWidget* nb_item_spinner;
+ GtkWidget* recursion_spinner;
+} sTreeSampleSelection;
+
+typedef struct sTreeButtons {
+ guint nb_item_add;
+ GtkWidget* add_button;
+ GtkWidget* remove_button;
+} sTreeButtons;
+/* end of tree section */
+
void
destroy_window (GtkWidget *widget,
GtkWidget **window)
@@ -992,6 +1016,481 @@ handle_box_child_signal (GtkHandleBox *hb,
action);
}
+/* funtions used by tree window demos */
+static guint
+cb_tree_delete_event(GtkWidget* w)
+{
+ return TRUE;
+}
+
+static void
+cb_tree_destroy_event(GtkWidget* w)
+{
+ sTreeButtons* tree_buttons;
+
+ /* free buttons structure associate at this tree */
+ tree_buttons = gtk_object_get_user_data(GTK_OBJECT(w));
+ free(tree_buttons);
+}
+static void
+cb_add_new_item(GtkWidget* w, GtkTree* tree)
+{
+ sTreeButtons* tree_buttons;
+ GList* selected_list;
+ GtkWidget* selected_item;
+ GtkWidget* subtree;
+ GtkWidget* item_new;
+ char buffer[255];
+
+ tree_buttons = gtk_object_get_user_data(GTK_OBJECT(tree));
+
+ selected_list = GTK_TREE_SELECTION(tree);
+
+ if(selected_list == NULL)
+ {
+ /* there is no item in tree */
+ subtree = GTK_WIDGET(tree);
+ }
+ else
+ {
+ /* list can have only one element */
+ selected_item = GTK_WIDGET(selected_list->data);
+
+ subtree = GTK_TREE_ITEM_SUBTREE(selected_item);
+
+ if(subtree == NULL)
+ {
+ /* current selected item have not subtree ... create it */
+ subtree = gtk_tree_new();
+ gtk_tree_item_set_subtree(GTK_TREE_ITEM(selected_item),
+ subtree);
+ }
+ }
+
+ /* at this point, we know which subtree will be used to add new item */
+ /* create a new item */
+ sprintf(buffer, "item add %d", tree_buttons->nb_item_add);
+ item_new = gtk_tree_item_new_with_label(buffer);
+ gtk_tree_append(GTK_TREE(subtree), item_new);
+ gtk_widget_show(item_new);
+
+ tree_buttons->nb_item_add++;
+}
+
+static void
+cb_remove_item(GtkWidget*w, GtkTree* tree)
+{
+ GList* selected_list;
+ GList* clear_list;
+
+ selected_list = GTK_TREE_SELECTION(tree);
+
+ clear_list = NULL;
+
+ while (selected_list)
+ {
+ clear_list = g_list_prepend (clear_list, selected_list->data);
+ selected_list = selected_list->next;
+ }
+
+ clear_list = g_list_reverse (clear_list);
+ gtk_tree_remove_items(tree, clear_list);
+
+ g_list_free (clear_list);
+}
+
+static void
+cb_tree_changed(GtkTree* tree)
+{
+ sTreeButtons* tree_buttons;
+ GList* selected_list;
+ guint nb_selected;
+
+ tree_buttons = gtk_object_get_user_data(GTK_OBJECT(tree));
+
+ selected_list = GTK_TREE_SELECTION(tree);
+ nb_selected = g_list_length(selected_list);
+
+ if(nb_selected == 0)
+ {
+ if(tree->children == NULL)
+ gtk_widget_set_sensitive(tree_buttons->add_button, TRUE);
+ else
+ gtk_widget_set_sensitive(tree_buttons->add_button, FALSE);
+ gtk_widget_set_sensitive(tree_buttons->remove_button, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(tree_buttons->remove_button, TRUE);
+ gtk_widget_set_sensitive(tree_buttons->add_button, (nb_selected == 1));
+ }
+}
+
+static void
+create_subtree(GtkWidget* item, guint level, guint nb_item_max, guint recursion_level_max)
+{
+ GtkWidget* item_subtree;
+ GtkWidget* item_new;
+ guint nb_item;
+ char buffer[255];
+ int no_root_item;
+
+ if(level == recursion_level_max) return;
+
+ if(level == -1)
+ {
+ /* query with no root item */
+ level = 0;
+ item_subtree = item;
+ no_root_item = 1;
+ }
+ else
+ {
+ /* query with no root item */
+ /* create subtree and associate it with current item */
+ item_subtree = gtk_tree_new();
+ no_root_item = 0;
+ }
+
+ for(nb_item = 0; nb_item < nb_item_max; nb_item++)
+ {
+ sprintf(buffer, "item %d-%d", level, nb_item);
+ item_new = gtk_tree_item_new_with_label(buffer);
+ gtk_tree_append(GTK_TREE(item_subtree), item_new);
+ create_subtree(item_new, level+1, nb_item_max, recursion_level_max);
+ gtk_widget_show(item_new);
+ }
+
+ if(!no_root_item)
+ gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), item_subtree);
+}
+
+static void
+create_tree_sample(guint selection_mode,
+ guint draw_line, guint view_line, guint no_root_item,
+ guint nb_item_max, guint recursion_level_max)
+{
+ GtkWidget* window;
+ GtkWidget* box1;
+ GtkWidget* box2;
+ GtkWidget* separator;
+ GtkWidget* button;
+ GtkWidget* scrolled_win;
+ GtkWidget* root_tree;
+ GtkWidget* root_item;
+ sTreeButtons* tree_buttons;
+
+ /* create tree buttons struct */
+ if((tree_buttons = g_malloc(sizeof(sTreeButtons))) == NULL)
+ {
+ g_error("can't allocate memory for tree structure !\n");
+ return;
+ }
+ tree_buttons->nb_item_add = 0;
+
+ /* create top level window */
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), "Tree Sample");
+ gtk_signal_connect(GTK_OBJECT (window), "delete_event",
+ (GtkSignalFunc) cb_tree_delete_event, NULL);
+ gtk_signal_connect(GTK_OBJECT(window), "destroy",
+ (GtkSignalFunc) cb_tree_destroy_event, NULL);
+ gtk_object_set_user_data(GTK_OBJECT(window), tree_buttons);
+
+ box1 = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(window), box1);
+ gtk_widget_show(box1);
+
+ /* create tree box */
+ box2 = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(box1), box2, TRUE, TRUE, 0);
+ gtk_container_border_width(GTK_CONTAINER(box2), 5);
+ gtk_widget_show(box2);
+
+ /* create scrolled window */
+ scrolled_win = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_box_pack_start (GTK_BOX (box2), scrolled_win, TRUE, TRUE, 0);
+ gtk_widget_set_usize (scrolled_win, 200, 200);
+ gtk_widget_show (scrolled_win);
+
+ /* create root tree widget */
+ root_tree = gtk_tree_new();
+ gtk_signal_connect(GTK_OBJECT(root_tree), "selection_changed",
+ (GtkSignalFunc)cb_tree_changed,
+ (gpointer)NULL);
+ gtk_object_set_user_data(GTK_OBJECT(root_tree), tree_buttons);
+ gtk_container_add(GTK_CONTAINER(scrolled_win), root_tree);
+ gtk_tree_set_selection_mode(GTK_TREE(root_tree), selection_mode);
+ gtk_tree_set_view_lines(GTK_TREE(root_tree), draw_line);
+ gtk_tree_set_view_mode(GTK_TREE(root_tree), !view_line);
+ gtk_widget_show(root_tree);
+
+ if ( no_root_item )
+ {
+ /* set root tree to subtree function with root item variable */
+ root_item = GTK_WIDGET(root_tree);
+ }
+ else
+ {
+ /* create root tree item widget */
+ root_item = gtk_tree_item_new_with_label("root item");
+ gtk_tree_append(GTK_TREE(root_tree), root_item);
+ gtk_widget_show(root_item);
+ }
+ create_subtree(root_item, -no_root_item, nb_item_max, recursion_level_max);
+
+ box2 = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(box2), 5);
+ gtk_widget_show(box2);
+
+ button = gtk_button_new_with_label("Add Item");
+ gtk_widget_set_sensitive(button, FALSE);
+ gtk_signal_connect(GTK_OBJECT (button), "clicked",
+ (GtkSignalFunc) cb_add_new_item,
+ (gpointer)root_tree);
+ gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ tree_buttons->add_button = button;
+
+ button = gtk_button_new_with_label("Remove Item(s)");
+ gtk_widget_set_sensitive(button, FALSE);
+ gtk_signal_connect(GTK_OBJECT (button), "clicked",
+ (GtkSignalFunc) cb_remove_item,
+ (gpointer)root_tree);
+ gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ tree_buttons->remove_button = button;
+
+ /* create separator */
+ separator = gtk_hseparator_new();
+ gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, FALSE, 0);
+ gtk_widget_show(separator);
+
+ /* create button box */
+ box2 = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(box2), 5);
+ gtk_widget_show(box2);
+
+ button = gtk_button_new_with_label("Close");
+ gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);
+ gtk_signal_connect_object(GTK_OBJECT (button), "clicked",
+ (GtkSignalFunc) gtk_widget_destroy,
+ GTK_OBJECT(window));
+ gtk_widget_show(button);
+
+ gtk_widget_show(window);
+}
+
+static void
+cb_create_tree(GtkWidget* w)
+{
+ guint selection_mode;
+ guint view_line;
+ guint draw_line;
+ guint no_root_item;
+ guint nb_item;
+ guint recursion_level;
+
+ /* get selection mode choice */
+ if(GTK_TOGGLE_BUTTON(sTreeSampleSelection.single_button)->active)
+ selection_mode = GTK_SELECTION_SINGLE;
+ else
+ if(GTK_TOGGLE_BUTTON(sTreeSampleSelection.browse_button)->active)
+ selection_mode = GTK_SELECTION_BROWSE;
+ else
+ if(GTK_TOGGLE_BUTTON(sTreeSampleSelection.multiple_button)->active)
+ selection_mode = GTK_SELECTION_MULTIPLE;
+
+ /* get options choice */
+ draw_line = GTK_TOGGLE_BUTTON(sTreeSampleSelection.draw_line_button)->active;
+ view_line = GTK_TOGGLE_BUTTON(sTreeSampleSelection.view_line_button)->active;
+ no_root_item = GTK_TOGGLE_BUTTON(sTreeSampleSelection.no_root_item_button)->active;
+
+ /* get levels */
+ nb_item = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sTreeSampleSelection.nb_item_spinner));
+ recursion_level = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sTreeSampleSelection.recursion_spinner));
+
+ create_tree_sample(selection_mode, draw_line, view_line, no_root_item, nb_item, recursion_level);
+}
+
+void
+create_tree_mode_window(void)
+{
+ static GtkWidget* window;
+ GtkWidget* box1;
+ GtkWidget* box2;
+ GtkWidget* box3;
+ GtkWidget* box4;
+ GtkWidget* box5;
+ GtkWidget* button;
+ GtkWidget* frame;
+ GtkWidget* separator;
+ GtkWidget* label;
+ GtkWidget* spinner;
+ GtkAdjustment *adj;
+
+ if (!window)
+ {
+ /* create toplevel window */
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), "Tree Mode Selection Window");
+ gtk_signal_connect(GTK_OBJECT (window), "delete_event",
+ (GtkSignalFunc) gtk_main_quit, NULL);
+ gtk_signal_connect (GTK_OBJECT (window), "destroy",
+ GTK_SIGNAL_FUNC(destroy_window), &window);
+ box1 = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(window), box1);
+ gtk_widget_show(box1);
+
+ /* create upper box - selection box */
+ box2 = gtk_vbox_new(FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(box1), box2, TRUE, TRUE, 0);
+ gtk_container_border_width(GTK_CONTAINER(box2), 5);
+ gtk_widget_show(box2);
+
+ box3 = gtk_hbox_new(FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(box2), box3, TRUE, TRUE, 0);
+ gtk_widget_show(box3);
+
+ /* create selection mode frame */
+ frame = gtk_frame_new("Selection Mode");
+ gtk_box_pack_start(GTK_BOX(box3), frame, TRUE, TRUE, 0);
+ gtk_widget_show(frame);
+
+ box4 = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(frame), box4);
+ gtk_container_border_width(GTK_CONTAINER(box4), 5);
+ gtk_widget_show(box4);
+
+ /* create radio button */
+ button = gtk_radio_button_new_with_label(NULL, "SINGLE");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ sTreeSampleSelection.single_button = button;
+
+ button = gtk_radio_button_new_with_label(gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
+ "BROWSE");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ sTreeSampleSelection.browse_button = button;
+
+ button = gtk_radio_button_new_with_label(gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
+ "MULTIPLE");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ sTreeSampleSelection.multiple_button = button;
+
+ sTreeSampleSelection.selection_mode_group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
+
+ /* create option mode frame */
+ frame = gtk_frame_new("Options");
+ gtk_box_pack_start(GTK_BOX(box3), frame, TRUE, TRUE, 0);
+ gtk_widget_show(frame);
+
+ box4 = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(frame), box4);
+ gtk_container_border_width(GTK_CONTAINER(box4), 5);
+ gtk_widget_show(box4);
+
+ /* create check button */
+ button = gtk_check_button_new_with_label("Draw line");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
+ gtk_widget_show(button);
+ sTreeSampleSelection.draw_line_button = button;
+
+ button = gtk_check_button_new_with_label("View Line mode");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
+ gtk_widget_show(button);
+ sTreeSampleSelection.view_line_button = button;
+
+ button = gtk_check_button_new_with_label("Without Root item");
+ gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
+ sTreeSampleSelection.no_root_item_button = button;
+
+ /* create recursion parameter */
+ frame = gtk_frame_new("Size Parameters");
+ gtk_box_pack_start(GTK_BOX(box2), frame, TRUE, TRUE, 0);
+ gtk_widget_show(frame);
+
+ box4 = gtk_hbox_new(FALSE, 5);
+ gtk_container_add(GTK_CONTAINER(frame), box4);
+ gtk_container_border_width(GTK_CONTAINER(box4), 5);
+ gtk_widget_show(box4);
+
+ /* create number of item spin button */
+ box5 = gtk_hbox_new(FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(box4), box5, FALSE, FALSE, 0);
+ gtk_widget_show(box5);
+
+ label = gtk_label_new("Number of Item");
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_box_pack_start (GTK_BOX (box5), label, FALSE, TRUE, 0);
+ gtk_widget_show(label);
+
+ adj = (GtkAdjustment *) gtk_adjustment_new ((gfloat)DEFAULT_NUMBER_OF_ITEM, 1.0, 255.0, 1.0,
+ 5.0, 0.0);
+ spinner = gtk_spin_button_new (adj, 0, 0);
+ gtk_box_pack_start (GTK_BOX (box5), spinner, FALSE, TRUE, 0);
+ gtk_widget_show(spinner);
+ sTreeSampleSelection.nb_item_spinner = spinner;
+
+ /* create recursion level spin button */
+ box5 = gtk_hbox_new(FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(box4), box5, FALSE, FALSE, 0);
+ gtk_widget_show(box5);
+
+ label = gtk_label_new("Depth Level");
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_box_pack_start (GTK_BOX (box5), label, FALSE, TRUE, 0);
+ gtk_widget_show(label);
+
+ adj = (GtkAdjustment *) gtk_adjustment_new ((gfloat)DEFAULT_RECURSION_LEVEL, 0.0, 255.0, 1.0,
+ 5.0, 0.0);
+ spinner = gtk_spin_button_new (adj, 0, 0);
+ gtk_box_pack_start (GTK_BOX (box5), spinner, FALSE, TRUE, 0);
+ gtk_widget_show(spinner);
+ sTreeSampleSelection.recursion_spinner = spinner;
+
+ /* create horizontal separator */
+ separator = gtk_hseparator_new();
+ gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, FALSE, 0);
+ gtk_widget_show(separator);
+
+ /* create bottom button box */
+ box2 = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(box2), 5);
+ gtk_widget_show(box2);
+
+ button = gtk_button_new_with_label("Create Tree Sample");
+ gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);
+ gtk_signal_connect(GTK_OBJECT (button), "clicked",
+ (GtkSignalFunc) cb_create_tree, NULL);
+ gtk_widget_show(button);
+
+ button = gtk_button_new_with_label("Close");
+ gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);
+ gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
+ GTK_SIGNAL_FUNC(gtk_widget_destroy),
+ GTK_OBJECT (window));
+ gtk_widget_show(button);
+
+ }
+ if (!GTK_WIDGET_VISIBLE (window))
+ gtk_widget_show (window);
+ else
+ gtk_widget_destroy (window);
+}
+
+/* end of function used by tree demos */
+
static void
create_handle_box ()
{
@@ -4703,6 +5202,7 @@ create_main_window ()
{ "spinbutton", create_spins },
{ "list", create_list },
{ "clist", create_clist},
+ { "tree", create_tree_mode_window},
{ "color selection", create_color_selection },
{ "file selection", create_file_selection },
{ "dialog", create_dialog },