gtk/demos/gtk-demo/button_box.c

128 lines
3.9 KiB
C
Raw Normal View History

/* Button Boxes
*
* The Button Box widgets are used to arrange buttons with padding.
*/
#include <glib/gi18n.h>
#include <gtk/gtk.h>
static GtkWidget *
create_bbox (gint horizontal,
char *title,
gint spacing,
gint layout)
{
GtkWidget *frame;
GtkWidget *bbox;
GtkWidget *button;
frame = gtk_frame_new (title);
if (horizontal)
bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
else
bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
g_object_set (bbox, "margin", 5, NULL);
gtk_container_add (GTK_CONTAINER (frame), bbox);
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
new function, turns off decorations for a window. 2001-03-07 Havoc Pennington <hp@redhat.com> * gtk/gtkwindow.c (gtk_window_set_decorated): new function, turns off decorations for a window. * demos/gtk-demo/button_box.c (create_bbox): adapt to button box changes * gtk/gtklabel.c (gtk_label_get_layout_offsets): new function to get location of PangoLayout inside the label, closes #51198 * gtk/testgtk.c (create_bbox): fix up button box usage * gtk/testcalendar.c (create_calendar): fix up button box usage * gtk/gtkfilesel.c (gtk_file_selection_init): fixup buttonbox usage * gtk/gtkdialog.c (gtk_dialog_init): fixup buttonbox usage * gtk/gtkhbbox.h: deprecations * gtk/gtkvbbox.h: deprecations * gtk/gtkbox.c (gtk_box_get_spacing): new function, used to emulate deprecated gtk_button_box_get_spacing * gtk/gtkbbox.h: deprecate some useless functions, remove entirely the "set global default" functions (struct _GtkButtonBox): remove "spacing" field, use the one from GtkBox base class * gtk/gtkbbox.c (_gtk_button_box_child_requisition): rename with uscore * gtk/gtkiconfactory.c (gtk_icon_set_render_icon): If we fail to render the icon, return the missing image icon. * gtk/gtkimage.c (gtk_image_set_from_file): fall back to missing image icon if the load fails. * gtk/gtkstock.h (GTK_STOCK_MISSING_IMAGE): Add stock icon for use when no image is found; should be the Netscape "missing image" icon eventually but for now is a random image * gtk/gtkwindow.c (gtk_window_set_role): new function, sets the role for the session manager * gtk/testgtk.c (dnd_drop): remove use of GTK_WINDOW_DIALOG * gtk/gtkcompat.h (GTK_WINDOW_DIALOG): compat #define GTK_WINDOW_DIALOG GTK_WINDOW_TOPLEVEL * gtk/gtkenums.h (enum GtkWindowType): remove GTK_WINDOW_DIALOG
2001-03-07 21:10:44 +00:00
gtk_box_set_spacing (GTK_BOX (bbox), spacing);
button = gtk_button_new_with_label (_("OK"));
gtk_container_add (GTK_CONTAINER (bbox), button);
button = gtk_button_new_with_label (_("Cancel"));
gtk_container_add (GTK_CONTAINER (bbox), button);
button = gtk_button_new_with_label (_("Help"));
gtk_container_add (GTK_CONTAINER (bbox), button);
return frame;
}
GtkWidget *
do_button_box (GtkWidget *do_widget)
{
static GtkWidget *window = NULL;
GtkWidget *main_vbox;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *frame_horz;
GtkWidget *frame_vert;
if (!window)
{
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Button Boxes");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&window);
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
g_object_set (main_vbox, "margin", 10, NULL);
gtk_container_add (GTK_CONTAINER (window), main_vbox);
frame_horz = gtk_frame_new ("Horizontal Button Boxes");
2016-10-02 15:37:22 +00:00
gtk_widget_set_margin_top (frame_horz, 10);
gtk_widget_set_margin_bottom (frame_horz, 10);
gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz);
2016-10-02 15:37:22 +00:00
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
g_object_set (vbox, "margin", 10, NULL);
gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Spread", 40, GTK_BUTTONBOX_SPREAD));
gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Edge", 40, GTK_BUTTONBOX_EDGE));
gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Start", 40, GTK_BUTTONBOX_START));
gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "End", 40, GTK_BUTTONBOX_END));
gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Center", 40, GTK_BUTTONBOX_CENTER));
gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Expand", 0, GTK_BUTTONBOX_EXPAND));
frame_vert = gtk_frame_new ("Vertical Button Boxes");
gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert);
2016-10-02 15:37:22 +00:00
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
g_object_set (hbox, "margin", 10, NULL);
gtk_container_add (GTK_CONTAINER (frame_vert), hbox);
gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Spread", 10, GTK_BUTTONBOX_SPREAD));
gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Edge", 10, GTK_BUTTONBOX_EDGE));
gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Start", 10, GTK_BUTTONBOX_START));
gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "End", 10, GTK_BUTTONBOX_END));
gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Center", 10, GTK_BUTTONBOX_CENTER));
gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Expand", 0, GTK_BUTTONBOX_EXPAND));
}
if (!gtk_widget_get_visible (window))
2017-01-19 09:02:04 +00:00
gtk_widget_show (window);
else
gtk_widget_destroy (window);
return window;
}