Commit b44565f3 authored by Arturo Espinosa's avatar Arturo Espinosa

Demo works fine. I have to add the missing functions for setting the toolbar's

parameters on the fly. - Federico
parent 4da7b2f2
......@@ -46,6 +46,9 @@ static void gtk_toolbar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_toolbar_add (GtkContainer *container,
GtkWidget *widget);
static void gtk_toolbar_foreach (GtkContainer *container,
GtkCallback callback,
gpointer callback_data);
static GtkContainerClass *parent_class;
......@@ -93,6 +96,7 @@ gtk_toolbar_class_init(GtkToolbarClass *class)
widget_class->size_allocate = gtk_toolbar_size_allocate;
container_class->add = gtk_toolbar_add;
container_class->foreach = gtk_toolbar_foreach;
}
static void
......@@ -105,6 +109,7 @@ gtk_toolbar_init(GtkToolbar *toolbar)
toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
toolbar->style = GTK_TOOLBAR_ICONS;
toolbar->space_size = DEFAULT_SPACE_SIZE;
toolbar->tooltips = gtk_tooltips_new();
}
GtkWidget *
......@@ -134,6 +139,8 @@ gtk_toolbar_destroy(GtkObject *object)
toolbar = GTK_TOOLBAR(object);
gtk_tooltips_unref(toolbar->tooltips); /* XXX: do I have to unref the tooltips? */
for (children = toolbar->children; children; children = children->next) {
child = children->data;
......@@ -313,22 +320,51 @@ gtk_toolbar_add(GtkContainer *container,
g_warning("gtk_toolbar_add: use gtk_toolbar_add_item() instead!");
}
static void
gtk_toolbar_foreach(GtkContainer *container,
GtkCallback callback,
gpointer callback_data)
{
GtkToolbar *toolbar;
GList *children;
Child *child;
g_return_if_fail(container != NULL);
g_return_if_fail(GTK_IS_TOOLBAR(container));
g_return_if_fail(callback != NULL);
toolbar = GTK_TOOLBAR(container);
for (children = toolbar->children; children; children = children->next) {
child = children->data;
if (child)
(*callback) (child->button, callback_data);
}
}
void
gtk_toolbar_append_item(GtkToolbar *toolbar,
const char *text,
const char *tooltip_text,
GtkPixmap *icon)
GtkPixmap *icon,
GtkSignalFunc callback,
gpointer user_data)
{
gtk_toolbar_insert_item(toolbar, text, tooltip_text, icon, toolbar->num_children);
gtk_toolbar_insert_item(toolbar, text, tooltip_text, icon,
callback, user_data, toolbar->num_children);
}
void
gtk_toolbar_prepend_item(GtkToolbar *toolbar,
const char *text,
const char *tooltip_text,
GtkPixmap *icon)
GtkPixmap *icon,
GtkSignalFunc callback,
gpointer user_data)
{
gtk_toolbar_insert_item(toolbar, text, tooltip_text, icon, 0);
gtk_toolbar_insert_item(toolbar, text, tooltip_text, icon,
callback, user_data, 0);
}
void
......@@ -336,6 +372,8 @@ gtk_toolbar_insert_item(GtkToolbar *toolbar,
const char *text,
const char *tooltip_text,
GtkPixmap *icon,
GtkSignalFunc callback,
gpointer user_data,
gint position)
{
Child *child;
......@@ -348,6 +386,10 @@ gtk_toolbar_insert_item(GtkToolbar *toolbar,
child->button = gtk_button_new();
if (callback)
gtk_signal_connect(GTK_OBJECT(child->button), "clicked",
callback, user_data);
if (text)
child->label = gtk_label_new(text);
else
......@@ -432,6 +474,7 @@ gtk_toolbar_insert_space(GtkToolbar *toolbar,
/* NULL child means it is a space in the toolbar, rather than a button */
toolbar->children = g_list_insert(toolbar->children, NULL, position);
toolbar->num_children++;
if (GTK_WIDGET_VISIBLE(toolbar))
gtk_widget_queue_resize(GTK_WIDGET(toolbar));
......
......@@ -25,6 +25,8 @@
#include <gtk/gtkcontainer.h>
#include <gtk/gtkenums.h>
#include <gtk/gtkpixmap.h>
#include <gtk/gtksignal.h>
#include <gtk/gtktooltips.h>
#ifdef __cplusplus
......@@ -50,6 +52,8 @@ struct _GtkToolbar
GtkToolbarStyle style;
gint space_size; /* big optional space between buttons */
GtkTooltips *tooltips;
gint child_maxw;
gint child_maxh;
};
......@@ -67,15 +71,21 @@ GtkWidget *gtk_toolbar_new (GtkOrientation orientation,
void gtk_toolbar_append_item (GtkToolbar *toolbar,
const char *text,
const char *tooltip_text,
GtkPixmap *icon);
GtkPixmap *icon,
GtkSignalFunc callback,
gpointer user_data);
void gtk_toolbar_prepend_item (GtkToolbar *toolbar,
const char *text,
const char *tooltip_text,
GtkPixmap *icon);
GtkPixmap *icon,
GtkSignalFunc callback,
gpointer user_data);
void gtk_toolbar_insert_item (GtkToolbar *toolbar,
const char *text,
const char *tooltip_text,
GtkPixmap *icon,
GtkSignalFunc callback,
gpointer user_data,
gint position);
void gtk_toolbar_append_space (GtkToolbar *toolbar);
void gtk_toolbar_prepend_space (GtkToolbar *toolbar);
......
......@@ -548,6 +548,81 @@ create_button_box ()
gtk_widget_destroy (window);
}
GtkWidget *
new_pixmap (char *filename, GdkWindow *window, GdkColor *background)
{
GtkWidget *wpixmap;
GdkPixmap *pixmap;
GdkBitmap *mask;
pixmap = gdk_pixmap_create_from_xpm (window, &mask,
background,
"test.xpm");
wpixmap = gtk_pixmap_new (pixmap, mask);
return wpixmap;
}
void
create_toolbar (void)
{
static GtkWidget *window = NULL;
GtkWidget *toolbar;
if (!window)
{
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Toolbar test");
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (destroy_window),
&window);
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (destroy_window),
&window);
gtk_container_border_width (GTK_CONTAINER (window), 0);
gtk_widget_realize (window);
toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"New", "New document",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
NULL, NULL);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Open", "Open existing",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
NULL, NULL);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Close", "Close current document",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
NULL, NULL);
gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Undo", "Undo screw-up",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
NULL, NULL);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Redo", "Redo not-screwup-after-all",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
NULL, NULL);
gtk_container_add (GTK_CONTAINER (window), toolbar);
gtk_widget_show (toolbar);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
}
void
create_handle_box ()
{
......@@ -3278,6 +3353,7 @@ create_main_window ()
{ "check buttons", create_check_buttons },
{ "radio buttons", create_radio_buttons },
{ "button box", create_button_box },
{ "toolbar", create_toolbar },
{ "handle box", create_handle_box },
{ "reparent", create_reparent },
{ "pixmap", create_pixmap },
......
......@@ -548,6 +548,81 @@ create_button_box ()
gtk_widget_destroy (window);
}
GtkWidget *
new_pixmap (char *filename, GdkWindow *window, GdkColor *background)
{
GtkWidget *wpixmap;
GdkPixmap *pixmap;
GdkBitmap *mask;
pixmap = gdk_pixmap_create_from_xpm (window, &mask,
background,
"test.xpm");
wpixmap = gtk_pixmap_new (pixmap, mask);
return wpixmap;
}
void
create_toolbar (void)
{
static GtkWidget *window = NULL;
GtkWidget *toolbar;
if (!window)
{
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Toolbar test");
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (destroy_window),
&window);
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (destroy_window),
&window);
gtk_container_border_width (GTK_CONTAINER (window), 0);
gtk_widget_realize (window);
toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"New", "New document",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
NULL, NULL);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Open", "Open existing",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
NULL, NULL);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Close", "Close current document",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
NULL, NULL);
gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Undo", "Undo screw-up",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
NULL, NULL);
gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
"Redo", "Redo not-screwup-after-all",
GTK_PIXMAP (new_pixmap ("test.xpm", window->window,
&window->style->bg[GTK_STATE_NORMAL])),
NULL, NULL);
gtk_container_add (GTK_CONTAINER (window), toolbar);
gtk_widget_show (toolbar);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
}
void
create_handle_box ()
{
......@@ -3278,6 +3353,7 @@ create_main_window ()
{ "check buttons", create_check_buttons },
{ "radio buttons", create_radio_buttons },
{ "button box", create_button_box },
{ "toolbar", create_toolbar },
{ "handle box", create_handle_box },
{ "reparent", create_reparent },
{ "pixmap", create_pixmap },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment