1 /* testmenubars.c -- test different packing directions
2 * Copyright (C) 2005 Red Hat, Inc.
3 * Author: Matthias Clasen
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
32 menu
= gtk_menu_new ();
34 menuitem
= gtk_menu_item_new_with_label ("One");
35 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), menuitem
);
36 gtk_widget_show (menuitem
);
37 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem
),
38 create_menu (depth
- 1));
40 menuitem
= gtk_menu_item_new_with_mnemonic ("Two");
41 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), menuitem
);
42 gtk_widget_show (menuitem
);
43 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem
),
44 create_menu (depth
- 1));
46 menuitem
= gtk_menu_item_new_with_mnemonic ("Three");
47 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), menuitem
);
48 gtk_widget_show (menuitem
);
49 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem
),
50 create_menu (depth
- 1));
56 create_menubar (GtkPackDirection pack_dir
,
57 GtkPackDirection child_pack_dir
,
64 menubar
= gtk_menu_bar_new ();
65 gtk_menu_bar_set_pack_direction (GTK_MENU_BAR (menubar
),
67 gtk_menu_bar_set_child_pack_direction (GTK_MENU_BAR (menubar
),
70 menuitem
= gtk_image_menu_item_new_from_stock (GTK_STOCK_HOME
, NULL
);
71 gtk_menu_shell_append (GTK_MENU_SHELL (menubar
), menuitem
);
72 gtk_label_set_angle (GTK_LABEL (GTK_BIN (menuitem
)->child
), angle
);
73 menu
= create_menu (2, TRUE
);
74 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem
), menu
);
76 menuitem
= gtk_menu_item_new_with_label ("foo");
77 gtk_menu_shell_append (GTK_MENU_SHELL (menubar
), menuitem
);
78 gtk_label_set_angle (GTK_LABEL (GTK_BIN (menuitem
)->child
), angle
);
79 menu
= create_menu (2, TRUE
);
80 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem
), menu
);
82 menuitem
= gtk_menu_item_new_with_label ("bar");
83 gtk_menu_shell_append (GTK_MENU_SHELL (menubar
), menuitem
);
84 gtk_label_set_angle (GTK_LABEL (GTK_BIN (menuitem
)->child
), angle
);
85 menu
= create_menu (2, TRUE
);
86 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem
), menu
);
92 main (int argc
, char **argv
)
94 static GtkWidget
*window
= NULL
;
101 gtk_init (&argc
, &argv
);
111 GtkAccelGroup
*accel_group
;
113 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
115 g_signal_connect (window
, "destroy",
116 G_CALLBACK(gtk_main_quit
), NULL
);
117 g_signal_connect (window
, "delete-event",
118 G_CALLBACK (gtk_true
), NULL
);
120 accel_group
= gtk_accel_group_new ();
121 gtk_window_add_accel_group (GTK_WINDOW (window
), accel_group
);
123 gtk_window_set_title (GTK_WINDOW (window
), "menus");
124 gtk_container_set_border_width (GTK_CONTAINER (window
), 0);
126 box1
= gtk_vbox_new (FALSE
, 0);
127 box2
= gtk_hbox_new (FALSE
, 0);
128 box3
= gtk_vbox_new (FALSE
, 0);
130 /* Rotation by 0 and 180 degrees is broken in Pango, #166832 */
131 menubar1
= create_menubar (GTK_PACK_DIRECTION_LTR
, GTK_PACK_DIRECTION_LTR
, 0.01);
132 menubar2
= create_menubar (GTK_PACK_DIRECTION_BTT
, GTK_PACK_DIRECTION_BTT
, 90);
133 menubar3
= create_menubar (GTK_PACK_DIRECTION_TTB
, GTK_PACK_DIRECTION_TTB
, 270);
134 menubar4
= create_menubar (GTK_PACK_DIRECTION_RTL
, GTK_PACK_DIRECTION_RTL
, 180.01);
135 menubar5
= create_menubar (GTK_PACK_DIRECTION_LTR
, GTK_PACK_DIRECTION_BTT
, 90);
136 menubar6
= create_menubar (GTK_PACK_DIRECTION_BTT
, GTK_PACK_DIRECTION_LTR
, 0.01);
138 gtk_container_add (GTK_CONTAINER (window
), box1
);
139 gtk_box_pack_start (GTK_BOX (box1
), menubar1
, FALSE
, TRUE
, 0);
140 gtk_box_pack_start (GTK_BOX (box1
), box2
, FALSE
, TRUE
, 0);
141 gtk_box_pack_start (GTK_BOX (box2
), menubar2
, FALSE
, TRUE
, 0);
142 gtk_box_pack_start (GTK_BOX (box2
), box3
, TRUE
, TRUE
, 0);
143 gtk_box_pack_start (GTK_BOX (box2
), menubar3
, FALSE
, TRUE
, 0);
144 gtk_box_pack_start (GTK_BOX (box1
), menubar4
, FALSE
, TRUE
, 0);
145 gtk_box_pack_start (GTK_BOX (box3
), menubar5
, TRUE
, TRUE
, 0);
146 gtk_box_pack_start (GTK_BOX (box3
), menubar6
, TRUE
, TRUE
, 0);
148 gtk_widget_show_all (box1
);
150 separator
= gtk_hseparator_new ();
151 gtk_box_pack_start (GTK_BOX (box1
), separator
, FALSE
, TRUE
, 0);
152 gtk_widget_show (separator
);
154 box2
= gtk_vbox_new (FALSE
, 10);
155 gtk_container_set_border_width (GTK_CONTAINER (box2
), 10);
156 gtk_box_pack_start (GTK_BOX (box1
), box2
, FALSE
, TRUE
, 0);
157 gtk_widget_show (box2
);
159 button
= gtk_button_new_with_label ("close");
160 g_signal_connect_swapped (button
, "clicked",
161 G_CALLBACK(gtk_widget_destroy
), window
);
162 gtk_box_pack_start (GTK_BOX (box2
), button
, TRUE
, TRUE
, 0);
163 GTK_WIDGET_SET_FLAGS (button
, GTK_CAN_DEFAULT
);
164 gtk_widget_grab_default (button
);
165 gtk_widget_show (button
);
168 if (!GTK_WIDGET_VISIBLE (window
))
170 gtk_widget_show (window
);
174 gtk_widget_destroy (window
);