diff options
author | Havoc Pennington <hp@redhat.com> | 2000-10-20 23:14:41 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2000-10-20 23:14:41 +0000 |
commit | 1c9f0c0bac5e73d80968fc791568f1566e3ec5e6 (patch) | |
tree | a274b213438121a8a69c6a61318322b94164d59e /tests | |
parent | 779e461e89dc5d423d9d5440d76e1f607b074b21 (diff) | |
download | gdk-pixbuf-1c9f0c0bac5e73d80968fc791568f1566e3ec5e6.tar.gz |
create some stock buttons with the default accel group (create_image):
2000-10-04 Havoc Pennington <hp@redhat.com>
* gtk/testgtk.c (create_buttons): create some stock buttons
with the default accel group
(create_image): test some new GtkImage features
(make_message_dialog): test GtkMessageDialog
(create_modal_window): fix someone's bizzarro indentation
* gtk/gtkwindow.h, gtk/gtkwindow.c: Implement
GTK_WIN_POS_CENTER_ON_PARENT.
Add "destroy with parent" setting, which means the window goes
away with its transient parent.
(gtk_window_get_default_accel_group): get the default accel group
for the window.
(gtk_window_set_destroy_with_parent): set/unset destroy with
parent flag
(gtk_window_read_rcfiles): invalidate icon set caches
after reloading rcfiles
* gtk/gtkenums.h (GtkWindowPosition): add
GTK_WIN_POS_CENTER_ON_PARENT, which centers a dialog
on its parent window when the dialog is mapped for the first time.
* gtk/gtkmessagedialog.h, gtk/gtkmessagedialog.c: Add
a simple message dialog class
* gtk/gtkdialog.c (gtk_dialog_init): Connect delete event
handler to emit response signal, and maybe later it would
honor a hide_on_delete flag - though that isn't there yet.
Set border width on the vbox to 2, so we get some padding.
Use a button box for the action area.
(gtk_dialog_key_press): synthesize a delete event if Esc
is pressed and the GtkWidget key press handler didn't
handle the escape key.
(gtk_dialog_new_with_buttons): new function creates a dialog
with some default buttons in it.
(gtk_dialog_add_action_widget): add an activatable widget
as a button in the dialog - you can also add a non-activatable
widget by accessing the action area directly.
(gtk_dialog_add_button): add a simple button - stock ID or
label - to the action area
(gtk_dialog_response): emit response signal
(gtk_dialog_run): block waiting for the dialog, return
the response. Override normal delete_event behavior, so that
delete_event does nothing inside gtk_dialog_run().
* gtk/gtkdialog.h, gtk/gtkdialog.c: Add "response" signal
emitted when an action widget is clicked or the dialog gets
delete_event
* gtk/gtk.h: add gtkmessagedialog.h
* gtk/Makefile.am: add gtkmessagedialog.[hc]
2000-10-20 Havoc Pennington <hp@redhat.com>
* gtk/gtk-sections.txt: Add dialog docs
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testgtk.c | 134 | ||||
-rw-r--r-- | tests/testgtkrc | 10 |
2 files changed, 132 insertions, 12 deletions
diff --git a/tests/testgtk.c b/tests/testgtk.c index 86d9be591..a24554f6b 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -161,8 +161,12 @@ create_buttons (void) if (!window) { + GtkAccelGroup *accel_group; + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + accel_group = gtk_window_get_default_accel_group (GTK_WINDOW (window)); + gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroyed), &window); @@ -180,15 +184,15 @@ create_buttons (void) gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0); button[0] = gtk_button_new_with_label ("button1"); - button[1] = gtk_button_new_with_label ("button2"); + button[1] = gtk_button_new_accel ("_button2", accel_group); button[2] = gtk_button_new_with_label ("button3"); - button[3] = gtk_button_new_with_label ("button4"); + button[3] = gtk_button_new_stock (GTK_STOCK_BUTTON_OK, NULL); button[4] = gtk_button_new_with_label ("button5"); button[5] = gtk_button_new_with_label ("button6"); button[6] = gtk_button_new_with_label ("button7"); - button[7] = gtk_button_new_with_label ("button8"); + button[7] = gtk_button_new_stock (GTK_STOCK_BUTTON_CLOSE, accel_group); button[8] = gtk_button_new_with_label ("button9"); - + gtk_signal_connect (GTK_OBJECT (button[0]), "clicked", GTK_SIGNAL_FUNC(button_window), button[1]); @@ -2222,6 +2226,65 @@ create_tooltips (void) } /* + * GtkImage + */ + +static void +pack_image (GtkWidget *box, + const gchar *text, + GtkWidget *image) +{ + gtk_box_pack_start (GTK_BOX (box), + gtk_label_new (text), + FALSE, FALSE, 0); + + gtk_box_pack_start (GTK_BOX (box), + image, + TRUE, TRUE, 0); +} + +static void +create_image (void) +{ + static GtkWidget *window = NULL; + + if (window == NULL) + { + GtkWidget *vbox; + GdkPixmap *pixmap; + GdkBitmap *mask; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(gtk_widget_destroyed), + &window); + + vbox = gtk_vbox_new (FALSE, 5); + + gtk_container_add (GTK_CONTAINER (window), vbox); + + pack_image (vbox, "Stock Warning Dialog", + gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, + GTK_ICON_SIZE_DIALOG)); + + pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, + gtk_widget_get_colormap (window), + &mask, + NULL, + openfile); + + pack_image (vbox, "Pixmap", + gtk_image_new_from_pixmap (pixmap, mask)); + } + + if (!GTK_WIDGET_VISIBLE (window)) + gtk_widget_show_all (window); + else + gtk_widget_destroy (window); +} + +/* * Menu demo */ @@ -2609,12 +2672,12 @@ create_modal_window (void) /* Pack widgets */ gtk_container_add (GTK_CONTAINER (window), box1); - gtk_box_pack_start (GTK_BOX (box1), frame1, TRUE, TRUE, 4); - gtk_container_add (GTK_CONTAINER (frame1), box2); - gtk_box_pack_start (GTK_BOX (box2), btnColor, FALSE, FALSE, 4); - gtk_box_pack_start (GTK_BOX (box2), btnFile, FALSE, FALSE, 4); - gtk_box_pack_start (GTK_BOX (box1), gtk_hseparator_new (), FALSE, FALSE, 4); - gtk_box_pack_start (GTK_BOX (box1), btnClose, FALSE, FALSE, 4); + gtk_box_pack_start (GTK_BOX (box1), frame1, TRUE, TRUE, 4); + gtk_container_add (GTK_CONTAINER (frame1), box2); + gtk_box_pack_start (GTK_BOX (box2), btnColor, FALSE, FALSE, 4); + gtk_box_pack_start (GTK_BOX (box2), btnFile, FALSE, FALSE, 4); + gtk_box_pack_start (GTK_BOX (box1), gtk_hseparator_new (), FALSE, FALSE, 4); + gtk_box_pack_start (GTK_BOX (box1), btnClose, FALSE, FALSE, 4); /* connect signals */ gtk_signal_connect_object (GTK_OBJECT (btnClose), "clicked", @@ -2637,6 +2700,53 @@ create_modal_window (void) } /* + * GtkMessageDialog + */ + +static void +make_message_dialog (GtkWidget **dialog, + GtkMessageType type, + GtkButtonsType buttons) +{ + if (*dialog) + { + if (GTK_WIDGET_REALIZED (*dialog)) + gdk_window_show ((*dialog)->window); + + return; + } + + *dialog = gtk_message_dialog_new (NULL, 0, type, buttons, + "This is a message dialog; it can wrap long lines. This is a long line. La la la. Look this line is wrapped. Blah blah blah blah blah blah. (Note: testgtk has a nonstandard gtkrc that changes some of the message dialog icons.)"); + + gtk_signal_connect_object (GTK_OBJECT (*dialog), + "response", + GTK_SIGNAL_FUNC (gtk_widget_destroy), + GTK_OBJECT (*dialog)); + + gtk_signal_connect (GTK_OBJECT (*dialog), + "destroy", + GTK_SIGNAL_FUNC (gtk_widget_destroyed), + dialog); + + gtk_widget_show (*dialog); +} + +static void +create_message_dialog (void) +{ + static GtkWidget *info = NULL; + static GtkWidget *warning = NULL; + static GtkWidget *error = NULL; + static GtkWidget *question = NULL; + + make_message_dialog (&info, GTK_MESSAGE_INFO, GTK_BUTTONS_OK); + make_message_dialog (&warning, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE); + make_message_dialog (&error, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK_CANCEL); + make_message_dialog (&question, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO); +} + +/* * GtkScrolledWindow */ @@ -8624,11 +8734,13 @@ create_main_window (void) { "font selection", create_font_selection }, { "gamma curve", create_gamma_curve }, { "handle box", create_handle_box }, + { "image", create_image }, { "item factory", create_item_factory }, { "labels", create_labels }, { "layout", create_layout }, { "list", create_list }, { "menus", create_menus }, + { "message dialog", create_message_dialog }, { "modal window", create_modal_window }, { "notebook", create_notebook }, { "panes", create_panes }, @@ -8771,8 +8883,6 @@ main (int argc, char *argv[]) gtk_init (&argc, &argv); - gdk_rgb_init (); - /* bindings test */ binding_set = gtk_binding_set_by_class (gtk_type_class (GTK_TYPE_WIDGET)); diff --git a/tests/testgtkrc b/tests/testgtkrc index 85fb90453..170ad4d1f 100644 --- a/tests/testgtkrc +++ b/tests/testgtkrc @@ -29,6 +29,16 @@ style "defaultfont" font_name = "Sans 12" } +style "myicons" +{ + stock["gtk-dialog-warning"] = + { + { "3DRings.xpm", *, *, *} + } +} + +class "GtkImage" style "myicons" + # common default class "GtkWidget" style "defaultfont" |