Functions to test the toolbar space style.

* gtk/testgtk.c: Functions to test the toolbar space style.

	* gtk/gtktoolbar.c: Add a private GtkToolbarChildSpace subclass of
	GtkToolbarChild to hold allocation. Set default space style to
	GTK_TOOLBAR_SPACE_EMPTY, define SPACE_LINE_* for separator
	fraction defaults.
	(gtk_toolbar_paint_space_line): New function; paints the separator
	line, using "toolbar" as the detail.
	(gtk_toolbar_expose): (gtk_toolbar_draw): Handle CHILD_SPACE when
	style is set to SPACE_LINE.
	(gtk_toolbar_size_allocate): Store space allocations.
	(gtk_toolbar_insert_element): If we are a space, allocate and
	initialize a GtkToolbarChildSpace instead of a GtkToolbarChild.
	(gtk_toolbar_set_space_style): New function.

	* gtk/gtktoolbar.h: Add GtkToolbarSpaceStyle, with styles of EMPTY
	and LINE. Add prototype for gtk_toolbar_set_space_style.
This commit is contained in:
Andrew T. Veliath 1998-12-08 13:25:35 +00:00
parent 287b0ce008
commit d6acd1ecd3
11 changed files with 313 additions and 20 deletions

View File

@ -1,3 +1,23 @@
1998-12-08 Andrew T. Veliath <andrewtv@usa.net>
* gtk/testgtk.c: Functions to test the toolbar space style.
* gtk/gtktoolbar.c: Add a private GtkToolbarChildSpace subclass of
GtkToolbarChild to hold allocation. Set default space style to
GTK_TOOLBAR_SPACE_EMPTY, define SPACE_LINE_* for separator
fraction defaults.
(gtk_toolbar_paint_space_line): New function; paints the separator
line, using "toolbar" as the detail.
(gtk_toolbar_expose): (gtk_toolbar_draw): Handle CHILD_SPACE when
style is set to SPACE_LINE.
(gtk_toolbar_size_allocate): Store space allocations.
(gtk_toolbar_insert_element): If we are a space, allocate and
initialize a GtkToolbarChildSpace instead of a GtkToolbarChild.
(gtk_toolbar_set_space_style): New function.
* gtk/gtktoolbar.h: Add GtkToolbarSpaceStyle, with styles of EMPTY
and LINE. Add prototype for gtk_toolbar_set_space_style.
Mon Dec 7 16:03:55 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkthemes.h: Remove random unnecessary includes

View File

@ -1,3 +1,23 @@
1998-12-08 Andrew T. Veliath <andrewtv@usa.net>
* gtk/testgtk.c: Functions to test the toolbar space style.
* gtk/gtktoolbar.c: Add a private GtkToolbarChildSpace subclass of
GtkToolbarChild to hold allocation. Set default space style to
GTK_TOOLBAR_SPACE_EMPTY, define SPACE_LINE_* for separator
fraction defaults.
(gtk_toolbar_paint_space_line): New function; paints the separator
line, using "toolbar" as the detail.
(gtk_toolbar_expose): (gtk_toolbar_draw): Handle CHILD_SPACE when
style is set to SPACE_LINE.
(gtk_toolbar_size_allocate): Store space allocations.
(gtk_toolbar_insert_element): If we are a space, allocate and
initialize a GtkToolbarChildSpace instead of a GtkToolbarChild.
(gtk_toolbar_set_space_style): New function.
* gtk/gtktoolbar.h: Add GtkToolbarSpaceStyle, with styles of EMPTY
and LINE. Add prototype for gtk_toolbar_set_space_style.
Mon Dec 7 16:03:55 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkthemes.h: Remove random unnecessary includes

View File

@ -1,3 +1,23 @@
1998-12-08 Andrew T. Veliath <andrewtv@usa.net>
* gtk/testgtk.c: Functions to test the toolbar space style.
* gtk/gtktoolbar.c: Add a private GtkToolbarChildSpace subclass of
GtkToolbarChild to hold allocation. Set default space style to
GTK_TOOLBAR_SPACE_EMPTY, define SPACE_LINE_* for separator
fraction defaults.
(gtk_toolbar_paint_space_line): New function; paints the separator
line, using "toolbar" as the detail.
(gtk_toolbar_expose): (gtk_toolbar_draw): Handle CHILD_SPACE when
style is set to SPACE_LINE.
(gtk_toolbar_size_allocate): Store space allocations.
(gtk_toolbar_insert_element): If we are a space, allocate and
initialize a GtkToolbarChildSpace instead of a GtkToolbarChild.
(gtk_toolbar_set_space_style): New function.
* gtk/gtktoolbar.h: Add GtkToolbarSpaceStyle, with styles of EMPTY
and LINE. Add prototype for gtk_toolbar_set_space_style.
Mon Dec 7 16:03:55 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkthemes.h: Remove random unnecessary includes

View File

@ -1,3 +1,23 @@
1998-12-08 Andrew T. Veliath <andrewtv@usa.net>
* gtk/testgtk.c: Functions to test the toolbar space style.
* gtk/gtktoolbar.c: Add a private GtkToolbarChildSpace subclass of
GtkToolbarChild to hold allocation. Set default space style to
GTK_TOOLBAR_SPACE_EMPTY, define SPACE_LINE_* for separator
fraction defaults.
(gtk_toolbar_paint_space_line): New function; paints the separator
line, using "toolbar" as the detail.
(gtk_toolbar_expose): (gtk_toolbar_draw): Handle CHILD_SPACE when
style is set to SPACE_LINE.
(gtk_toolbar_size_allocate): Store space allocations.
(gtk_toolbar_insert_element): If we are a space, allocate and
initialize a GtkToolbarChildSpace instead of a GtkToolbarChild.
(gtk_toolbar_set_space_style): New function.
* gtk/gtktoolbar.h: Add GtkToolbarSpaceStyle, with styles of EMPTY
and LINE. Add prototype for gtk_toolbar_set_space_style.
Mon Dec 7 16:03:55 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkthemes.h: Remove random unnecessary includes

View File

@ -1,3 +1,23 @@
1998-12-08 Andrew T. Veliath <andrewtv@usa.net>
* gtk/testgtk.c: Functions to test the toolbar space style.
* gtk/gtktoolbar.c: Add a private GtkToolbarChildSpace subclass of
GtkToolbarChild to hold allocation. Set default space style to
GTK_TOOLBAR_SPACE_EMPTY, define SPACE_LINE_* for separator
fraction defaults.
(gtk_toolbar_paint_space_line): New function; paints the separator
line, using "toolbar" as the detail.
(gtk_toolbar_expose): (gtk_toolbar_draw): Handle CHILD_SPACE when
style is set to SPACE_LINE.
(gtk_toolbar_size_allocate): Store space allocations.
(gtk_toolbar_insert_element): If we are a space, allocate and
initialize a GtkToolbarChildSpace instead of a GtkToolbarChild.
(gtk_toolbar_set_space_style): New function.
* gtk/gtktoolbar.h: Add GtkToolbarSpaceStyle, with styles of EMPTY
and LINE. Add prototype for gtk_toolbar_set_space_style.
Mon Dec 7 16:03:55 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkthemes.h: Remove random unnecessary includes

View File

@ -1,3 +1,23 @@
1998-12-08 Andrew T. Veliath <andrewtv@usa.net>
* gtk/testgtk.c: Functions to test the toolbar space style.
* gtk/gtktoolbar.c: Add a private GtkToolbarChildSpace subclass of
GtkToolbarChild to hold allocation. Set default space style to
GTK_TOOLBAR_SPACE_EMPTY, define SPACE_LINE_* for separator
fraction defaults.
(gtk_toolbar_paint_space_line): New function; paints the separator
line, using "toolbar" as the detail.
(gtk_toolbar_expose): (gtk_toolbar_draw): Handle CHILD_SPACE when
style is set to SPACE_LINE.
(gtk_toolbar_size_allocate): Store space allocations.
(gtk_toolbar_insert_element): If we are a space, allocate and
initialize a GtkToolbarChildSpace instead of a GtkToolbarChild.
(gtk_toolbar_set_space_style): New function.
* gtk/gtktoolbar.h: Add GtkToolbarSpaceStyle, with styles of EMPTY
and LINE. Add prototype for gtk_toolbar_set_space_style.
Mon Dec 7 16:03:55 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkthemes.h: Remove random unnecessary includes

View File

@ -1,3 +1,23 @@
1998-12-08 Andrew T. Veliath <andrewtv@usa.net>
* gtk/testgtk.c: Functions to test the toolbar space style.
* gtk/gtktoolbar.c: Add a private GtkToolbarChildSpace subclass of
GtkToolbarChild to hold allocation. Set default space style to
GTK_TOOLBAR_SPACE_EMPTY, define SPACE_LINE_* for separator
fraction defaults.
(gtk_toolbar_paint_space_line): New function; paints the separator
line, using "toolbar" as the detail.
(gtk_toolbar_expose): (gtk_toolbar_draw): Handle CHILD_SPACE when
style is set to SPACE_LINE.
(gtk_toolbar_size_allocate): Store space allocations.
(gtk_toolbar_insert_element): If we are a space, allocate and
initialize a GtkToolbarChildSpace instead of a GtkToolbarChild.
(gtk_toolbar_set_space_style): New function.
* gtk/gtktoolbar.h: Add GtkToolbarSpaceStyle, with styles of EMPTY
and LINE. Add prototype for gtk_toolbar_set_space_style.
Mon Dec 7 16:03:55 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtkthemes.h: Remove random unnecessary includes

View File

@ -26,8 +26,12 @@
#include "gtktoolbar.h"
#define DEFAULT_SPACE_SIZE 5
#define DEFAULT_SPACE_SIZE 5
#define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_EMPTY
#define SPACE_LINE_DIVISION 10
#define SPACE_LINE_START 3
#define SPACE_LINE_END 7
enum {
ORIENTATION_CHANGED,
@ -35,6 +39,14 @@ enum {
LAST_SIGNAL
};
typedef struct _GtkToolbarChildSpace GtkToolbarChildSpace;
struct _GtkToolbarChildSpace
{
GtkToolbarChild child;
gint alloc_x, alloc_y;
};
static void gtk_toolbar_class_init (GtkToolbarClass *class);
static void gtk_toolbar_init (GtkToolbar *toolbar);
static void gtk_toolbar_destroy (GtkObject *object);
@ -154,6 +166,7 @@ gtk_toolbar_init (GtkToolbar *toolbar)
toolbar->style = GTK_TOOLBAR_ICONS;
toolbar->relief = GTK_RELIEF_NORMAL;
toolbar->space_size = DEFAULT_SPACE_SIZE;
toolbar->space_style = DEFAULT_SPACE_STYLE;
toolbar->tooltips = gtk_tooltips_new ();
toolbar->button_maxw = 0;
toolbar->button_maxh = 0;
@ -257,6 +270,47 @@ gtk_toolbar_unmap (GtkWidget *widget)
}
}
static void
gtk_toolbar_paint_space_line (GtkWidget *widget,
GdkRectangle *area,
GtkToolbarChild *child)
{
GtkToolbar *toolbar;
GtkToolbarChildSpace *child_space;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_TOOLBAR (widget));
g_return_if_fail (child != NULL);
g_return_if_fail (child->type == GTK_TOOLBAR_CHILD_SPACE);
toolbar = GTK_TOOLBAR (widget);
child_space = (GtkToolbarChildSpace *) child;
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
gtk_paint_vline (widget->style, widget->window,
GTK_WIDGET_STATE (widget), area, widget,
"toolbar",
child_space->alloc_y + toolbar->button_maxh *
SPACE_LINE_START / SPACE_LINE_DIVISION,
child_space->alloc_y + toolbar->button_maxh *
SPACE_LINE_END / SPACE_LINE_DIVISION,
child_space->alloc_x +
(toolbar->space_size -
widget->style->klass->xthickness) / 2);
else
gtk_paint_hline (widget->style, widget->window,
GTK_WIDGET_STATE (widget), area, widget,
"toolbar",
child_space->alloc_x + toolbar->button_maxw *
SPACE_LINE_START / SPACE_LINE_DIVISION,
child_space->alloc_x + toolbar->button_maxw *
SPACE_LINE_END / SPACE_LINE_DIVISION,
child_space->alloc_y +
(toolbar->space_size -
widget->style->klass->ythickness) / 2);
}
static void
gtk_toolbar_draw (GtkWidget *widget,
GdkRectangle *area)
@ -277,8 +331,12 @@ gtk_toolbar_draw (GtkWidget *widget,
{
child = children->data;
if ((child->type != GTK_TOOLBAR_CHILD_SPACE)
&& gtk_widget_intersect (child->widget, area, &child_area))
if (child->type == GTK_TOOLBAR_CHILD_SPACE)
{
if (toolbar->space_style == GTK_TOOLBAR_SPACE_LINE)
gtk_toolbar_paint_space_line (widget, area, child);
}
else if (gtk_widget_intersect (child->widget, area, &child_area))
gtk_widget_draw (child->widget, &child_area);
}
}
@ -307,9 +365,13 @@ gtk_toolbar_expose (GtkWidget *widget,
{
child = children->data;
if ((child->type != GTK_TOOLBAR_CHILD_SPACE)
&& GTK_WIDGET_NO_WINDOW (child->widget)
&& gtk_widget_intersect (child->widget, &event->area, &child_event.area))
if (child->type == GTK_TOOLBAR_CHILD_SPACE)
{
if (toolbar->space_style == GTK_TOOLBAR_SPACE_LINE)
gtk_toolbar_paint_space_line (widget, &event->area, child);
}
else if (GTK_WIDGET_NO_WINDOW (child->widget)
&& gtk_widget_intersect (child->widget, &event->area, &child_event.area))
gtk_widget_event (child->widget, (GdkEvent *) &child_event);
}
}
@ -413,6 +475,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
GtkToolbar *toolbar;
GList *children;
GtkToolbarChild *child;
GtkToolbarChildSpace *child_space;
GtkAllocation alloc;
gint border_width;
@ -437,10 +500,21 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
switch (child->type)
{
case GTK_TOOLBAR_CHILD_SPACE:
child_space = (GtkToolbarChildSpace *) child;
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
alloc.x += toolbar->space_size;
{
child_space->alloc_x = alloc.x;
child_space->alloc_y = allocation->y + (allocation->height - toolbar->button_maxh) / 2;
alloc.x += toolbar->space_size;
}
else
alloc.y += toolbar->space_size;
{
child_space->alloc_x = allocation->x + (allocation->width - toolbar->button_maxw) / 2;
child_space->alloc_y = alloc.y;
alloc.y += toolbar->space_size;
}
break;
@ -746,7 +820,11 @@ gtk_toolbar_insert_element (GtkToolbar *toolbar,
else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
g_return_val_if_fail (widget == NULL, NULL);
child = g_new (GtkToolbarChild, 1);
if (type == GTK_TOOLBAR_CHILD_SPACE)
child = (GtkToolbarChild *) g_new (GtkToolbarChildSpace, 1);
else
child = g_new (GtkToolbarChild, 1);
child->type = type;
child->icon = NULL;
child->label = NULL;
@ -755,6 +833,8 @@ gtk_toolbar_insert_element (GtkToolbar *toolbar,
{
case GTK_TOOLBAR_CHILD_SPACE:
child->widget = NULL;
((GtkToolbarChildSpace *) child)->alloc_x =
((GtkToolbarChildSpace *) child)->alloc_y = 0;
break;
case GTK_TOOLBAR_CHILD_WIDGET:
@ -881,6 +961,20 @@ gtk_toolbar_set_space_size (GtkToolbar *toolbar,
}
}
void
gtk_toolbar_set_space_style (GtkToolbar *toolbar,
GtkToolbarSpaceStyle space_style)
{
g_return_if_fail (toolbar != NULL);
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
if (toolbar->space_style != space_style)
{
toolbar->space_style = space_style;
gtk_widget_queue_resize (GTK_WIDGET (toolbar));
}
}
void
gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
gint enable)

View File

@ -48,6 +48,12 @@ typedef enum
GTK_TOOLBAR_CHILD_WIDGET
} GtkToolbarChildType;
typedef enum
{
GTK_TOOLBAR_SPACE_EMPTY,
GTK_TOOLBAR_SPACE_LINE
} GtkToolbarSpaceStyle;
typedef struct _GtkToolbarChild GtkToolbarChild;
typedef struct _GtkToolbar GtkToolbar;
typedef struct _GtkToolbarClass GtkToolbarClass;
@ -69,6 +75,7 @@ struct _GtkToolbar
GtkOrientation orientation;
GtkToolbarStyle style;
gint space_size; /* big optional space between buttons */
GtkToolbarSpaceStyle space_style;
GtkTooltips *tooltips;
@ -170,17 +177,19 @@ void gtk_toolbar_insert_widget (GtkToolbar *toolbar,
gint position);
/* Style functions */
void gtk_toolbar_set_orientation (GtkToolbar *toolbar,
GtkOrientation orientation);
void gtk_toolbar_set_style (GtkToolbar *toolbar,
GtkToolbarStyle style);
void gtk_toolbar_set_space_size (GtkToolbar *toolbar,
gint space_size);
void gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
gint enable);
void gtk_toolbar_set_button_relief (GtkToolbar *toolbar,
GtkReliefStyle relief);
GtkReliefStyle gtk_toolbar_get_button_relief (GtkToolbar *toolbar);
void gtk_toolbar_set_orientation (GtkToolbar *toolbar,
GtkOrientation orientation);
void gtk_toolbar_set_style (GtkToolbar *toolbar,
GtkToolbarStyle style);
void gtk_toolbar_set_space_size (GtkToolbar *toolbar,
gint space_size);
void gtk_toolbar_set_space_style (GtkToolbar *toolbar,
GtkToolbarSpaceStyle space_style);
void gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
gint enable);
void gtk_toolbar_set_button_relief (GtkToolbar *toolbar,
GtkReliefStyle relief);
GtkReliefStyle gtk_toolbar_get_button_relief (GtkToolbar *toolbar);
#ifdef __cplusplus

View File

@ -657,6 +657,20 @@ set_toolbar_borderless (GtkWidget *widget,
gtk_toolbar_set_button_relief (GTK_TOOLBAR (data), GTK_RELIEF_NONE);
}
static void
set_toolbar_space_style_empty (GtkWidget *widget,
gpointer data)
{
gtk_toolbar_set_space_style (GTK_TOOLBAR (data), GTK_TOOLBAR_SPACE_EMPTY);
}
static void
set_toolbar_space_style_line (GtkWidget *widget,
gpointer data)
{
gtk_toolbar_set_space_style (GTK_TOOLBAR (data), GTK_TOOLBAR_SPACE_LINE);
}
static void
create_toolbar (void)
{
@ -743,6 +757,17 @@ create_toolbar (void)
new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
(GtkSignalFunc) set_toolbar_borderless, toolbar);
gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Empty", "Empty spaces", NULL,
new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
(GtkSignalFunc) set_toolbar_space_style_empty, toolbar);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Lines", "Lines in spaces", NULL,
new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
(GtkSignalFunc) set_toolbar_space_style_line, toolbar);
gtk_container_add (GTK_CONTAINER (window), toolbar);
}

View File

@ -657,6 +657,20 @@ set_toolbar_borderless (GtkWidget *widget,
gtk_toolbar_set_button_relief (GTK_TOOLBAR (data), GTK_RELIEF_NONE);
}
static void
set_toolbar_space_style_empty (GtkWidget *widget,
gpointer data)
{
gtk_toolbar_set_space_style (GTK_TOOLBAR (data), GTK_TOOLBAR_SPACE_EMPTY);
}
static void
set_toolbar_space_style_line (GtkWidget *widget,
gpointer data)
{
gtk_toolbar_set_space_style (GTK_TOOLBAR (data), GTK_TOOLBAR_SPACE_LINE);
}
static void
create_toolbar (void)
{
@ -743,6 +757,17 @@ create_toolbar (void)
new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
(GtkSignalFunc) set_toolbar_borderless, toolbar);
gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Empty", "Empty spaces", NULL,
new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
(GtkSignalFunc) set_toolbar_space_style_empty, toolbar);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Lines", "Lines in spaces", NULL,
new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
(GtkSignalFunc) set_toolbar_space_style_line, toolbar);
gtk_container_add (GTK_CONTAINER (window), toolbar);
}