function new_pixmap (window_wgt, filename)
{
local pixmask;
pixmask = gdk_pixmap_create_from_xpm
(window_wgt.get_window(),
window_wgt.get_color_struct (GTK_COLOR_BACKGROUND, GTK_STATE_NORMAL),
filename);
if (car(pixmask))
gtk_pixmap_new (car(pixmask), cadr(pixmask));
else
nil;
}
method GtkWidget.get_color_struct (where, state)
{
local color = new GdkColor();
color.pixel = .get_color (where, state);
color;
}
function create_toolbar ()
{
local toolbar, vbox, toolbar, button, entry;
win_toolbar = new (GtkWindow);
win_toolbar.signal ("destroy", #win_toolbar = nil);
win_toolbar.title = "Toolbar test";
win_toolbar.border_width = 0;
win_toolbar.set_policy(FALSE, TRUE, TRUE);
win_toolbar.realize();
vbox = new(GtkVBox);
win_toolbar.add(vbox);
vbox.show();
toolbar = new(GtkToolbar);
toolbar.set_orientation(GTK_ORIENTATION_HORIZONTAL);
toolbar.set_style(GTK_TOOLBAR_BOTH);
toolbar.set_button_relief(GTK_RELIEF_NONE);
vbox.pack_start(toolbar, FALSE, FALSE, 0);
vbox.show();
button = toolbar.append_item("Horizontal", "Horizontal toolbar layout",
"Toolbar/Horizontal",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked",
`((@toolbar).set_orientation(GTK_ORIENTATION_HORIZONTAL)));
button = toolbar.append_item("Vertical", "Vertical toolbar layout",
"Toolbar/Vertical",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked",
`((@toolbar).set_orientation(GTK_ORIENTATION_VERTICAL)));
toolbar.append_space();
button = toolbar.append_item("Icons", "Only show toolbar icons",
"Toolbar/Icons",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked", `((@toolbar).set_style(GTK_TOOLBAR_ICONS)));
button = toolbar.append_item("Text", "Only show toolbar text",
"Toolbar/Text",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked", `((@toolbar).set_style(GTK_TOOLBAR_TEXT)));
button = toolbar.append_item("Both", "Show toolbar icons and text",
"Toolbar/Both",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked", `((@toolbar).set_style(GTK_TOOLBAR_BOTH)));
toolbar.append_space();
entry = new(GtkEntry);
toolbar.append_widget(entry, "This is an unusable GtkEntry ;-)", nil);
toolbar.append_space();
button = toolbar.append_item("Small", "Use small spaces",
"Toolbar/Small",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked", `((@toolbar).set_space_size(5)));
button = toolbar.append_item("Big", "Use big spaces",
"Toolbar/Big",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked", `((@toolbar).set_space_size(15)));
toolbar.append_space();
button = toolbar.append_item("Enable", "Enable tooltips",
"Toolbar/Enable",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked", `((@toolbar).set_tooltips(TRUE)));
button = toolbar.append_item("Disable", "Disable tooltips",
"Toolbar/Disable",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked", `((@toolbar).set_tooltips(FALSE)));
toolbar.append_space();
button.label = "Borders";
button = toolbar.append_item("Borders", "Show button borders",
"Toolbar/Borders",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked", `((@toolbar).set_button_relief(GTK_RELIEF_NORMAL)));
button = toolbar.append_item("Borderless", "Hide button borders",
"Toolbar/Borderless",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked", `((@toolbar).set_button_relief(GTK_RELIEF_NONE)));
toolbar.append_space();
button.label = "Empty";
button = toolbar.append_item("Empty", "Empty spaces",
"Toolbar/Empty",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked",
`((@toolbar).set_space_style(GTK_TOOLBAR_SPACE_EMPTY)));
button.label = "Lines";
button = toolbar.append_item("Lines", "Lines in spaces",
"Toolbar/Lines",
new_pixmap(win_toolbar, "test.xpm"));
button.signal("clicked",
`((@toolbar).set_space_style(GTK_TOOLBAR_SPACE_LINE)));
toolbar.set_tooltips(TRUE);
win_toolbar.show_all();
win_toolbar;
}
function main ()
{
local window, win_toolbar;
TRUE=1;
FALSE=0;
window = create_toolbar ();
window.signal ("destroy", #exit_program(0));
init_ipc("toolbar", "toolbarq");
gtk_main ();
}
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.