~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to demos/gtk-demo/ui_manager.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* UI Manager
 
2
 *
 
3
 * The GtkUIManager object allows the easy creation of menus
 
4
 * from an array of actions and a description of the menu hierarchy.
 
5
 */
 
6
 
 
7
#include <gtk/gtk.h>
 
8
 
 
9
static void
 
10
activate_action (GtkAction *action)
 
11
{
 
12
  g_message ("Action \"%s\" activated", gtk_action_get_name (action));
 
13
}
 
14
 
 
15
static void
 
16
activate_radio_action (GtkAction *action, GtkRadioAction *current)
 
17
{
 
18
  g_message ("Radio action \"%s\" selected", 
 
19
             gtk_action_get_name (GTK_ACTION (current)));
 
20
}
 
21
 
 
22
static GtkActionEntry entries[] = {
 
23
  { "FileMenu", NULL, "_File" },               /* name, stock id, label */
 
24
  { "PreferencesMenu", NULL, "_Preferences" }, /* name, stock id, label */
 
25
  { "ColorMenu", NULL, "_Color"  },            /* name, stock id, label */
 
26
  { "ShapeMenu", NULL, "_Shape" },             /* name, stock id, label */
 
27
  { "HelpMenu", NULL, "_Help" },               /* name, stock id, label */
 
28
  { "New", GTK_STOCK_NEW,                      /* name, stock id */
 
29
    "_New", "<control>N",                      /* label, accelerator */
 
30
    "Create a new file",                       /* tooltip */ 
 
31
    G_CALLBACK (activate_action) },      
 
32
  { "Open", GTK_STOCK_OPEN,                    /* name, stock id */
 
33
    "_Open","<control>O",                      /* label, accelerator */     
 
34
    "Open a file",                             /* tooltip */
 
35
    G_CALLBACK (activate_action) }, 
 
36
  { "Save", GTK_STOCK_SAVE,                    /* name, stock id */
 
37
    "_Save","<control>S",                      /* label, accelerator */     
 
38
    "Save current file",                       /* tooltip */
 
39
    G_CALLBACK (activate_action) },
 
40
  { "SaveAs", GTK_STOCK_SAVE,                  /* name, stock id */
 
41
    "Save _As...", NULL,                       /* label, accelerator */     
 
42
    "Save to a file",                          /* tooltip */
 
43
    G_CALLBACK (activate_action) },
 
44
  { "Quit", GTK_STOCK_QUIT,                    /* name, stock id */
 
45
    "_Quit", "<control>Q",                     /* label, accelerator */     
 
46
    "Quit",                                    /* tooltip */
 
47
    G_CALLBACK (activate_action) },
 
48
  { "About", NULL,                             /* name, stock id */
 
49
    "_About", "<control>A",                    /* label, accelerator */     
 
50
    "About",                                   /* tooltip */  
 
51
    G_CALLBACK (activate_action) },
 
52
  { "Logo", "demo-gtk-logo",                   /* name, stock id */
 
53
     NULL, NULL,                               /* label, accelerator */     
 
54
    "GTK+",                                    /* tooltip */
 
55
    G_CALLBACK (activate_action) },
 
56
};
 
57
static guint n_entries = G_N_ELEMENTS (entries);
 
58
 
 
59
 
 
60
static GtkToggleActionEntry toggle_entries[] = {
 
61
  { "Bold", GTK_STOCK_BOLD,                    /* name, stock id */
 
62
     "_Bold", "<control>B",                    /* label, accelerator */     
 
63
    "Bold",                                    /* tooltip */
 
64
    G_CALLBACK (activate_action), 
 
65
    TRUE },                                    /* is_active */
 
66
};
 
67
static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
 
68
 
 
69
enum {
 
70
  COLOR_RED,
 
71
  COLOR_GREEN,
 
72
  COLOR_BLUE
 
73
};
 
74
 
 
75
static GtkRadioActionEntry color_entries[] = {
 
76
  { "Red", NULL,                               /* name, stock id */
 
77
    "_Red", "<control>R",                      /* label, accelerator */     
 
78
    "Blood", COLOR_RED },                      /* tooltip, value */
 
79
  { "Green", NULL,                             /* name, stock id */
 
80
    "_Green", "<control>G",                    /* label, accelerator */     
 
81
    "Grass", COLOR_GREEN },                    /* tooltip, value */
 
82
  { "Blue", NULL,                              /* name, stock id */
 
83
    "_Blue", "<control>B",                     /* label, accelerator */     
 
84
    "Sky", COLOR_BLUE },                       /* tooltip, value */
 
85
};
 
86
static guint n_color_entries = G_N_ELEMENTS (color_entries);
 
87
 
 
88
enum {
 
89
  SHAPE_SQUARE,
 
90
  SHAPE_RECTANGLE,
 
91
  SHAPE_OVAL
 
92
};
 
93
 
 
94
static GtkRadioActionEntry shape_entries[] = {
 
95
  { "Square", NULL,                            /* name, stock id */
 
96
    "_Square", "<control>S",                   /* label, accelerator */     
 
97
    "Square",  SHAPE_SQUARE },                 /* tooltip, value */
 
98
  { "Rectangle", NULL,                         /* name, stock id */
 
99
    "_Rectangle", "<control>R",                /* label, accelerator */     
 
100
    "Rectangle", SHAPE_RECTANGLE },            /* tooltip, value */
 
101
  { "Oval", NULL,                              /* name, stock id */
 
102
    "_Oval", "<control>O",                     /* label, accelerator */     
 
103
    "Egg", SHAPE_OVAL },                       /* tooltip, value */  
 
104
};
 
105
static guint n_shape_entries = G_N_ELEMENTS (shape_entries);
 
106
 
 
107
static const gchar *ui_info = 
 
108
"<ui>"
 
109
"  <menubar name='MenuBar'>"
 
110
"    <menu action='FileMenu'>"
 
111
"      <menuitem action='New'/>"
 
112
"      <menuitem action='Open'/>"
 
113
"      <menuitem action='Save'/>"
 
114
"      <menuitem action='SaveAs'/>"
 
115
"      <separator/>"
 
116
"      <menuitem action='Quit'/>"
 
117
"    </menu>"
 
118
"    <menu action='PreferencesMenu'>"
 
119
"      <menu action='ColorMenu'>"
 
120
"       <menuitem action='Red'/>"
 
121
"       <menuitem action='Green'/>"
 
122
"       <menuitem action='Blue'/>"
 
123
"      </menu>"
 
124
"      <menu action='ShapeMenu'>"
 
125
"        <menuitem action='Square'/>"
 
126
"        <menuitem action='Rectangle'/>"
 
127
"        <menuitem action='Oval'/>"
 
128
"      </menu>"
 
129
"      <menuitem action='Bold'/>"
 
130
"    </menu>"
 
131
"    <menu action='HelpMenu'>"
 
132
"      <menuitem action='About'/>"
 
133
"    </menu>"
 
134
"  </menubar>"
 
135
"  <toolbar  name='ToolBar'>"
 
136
"    <toolitem action='Open'/>"
 
137
"    <toolitem action='Quit'/>"
 
138
"    <separator action='Sep1'/>"
 
139
"    <toolitem action='Logo'/>"
 
140
"  </toolbar>"
 
141
"</ui>";
 
142
 
 
143
GtkWidget *
 
144
do_ui_manager (GtkWidget *do_widget)
 
145
{
 
146
  static GtkWidget *window = NULL;
 
147
  
 
148
  if (!window)
 
149
    {
 
150
      GtkWidget *box1;
 
151
      GtkWidget *box2;
 
152
      GtkWidget *separator;
 
153
      GtkWidget *label;
 
154
      GtkWidget *button;
 
155
      GtkUIManager *ui;
 
156
      GtkActionGroup *actions;
 
157
      GError *error = NULL;
 
158
 
 
159
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
160
      gtk_window_set_screen (GTK_WINDOW (window),
 
161
                             gtk_widget_get_screen (do_widget));
 
162
      
 
163
      g_signal_connect (window, "destroy",
 
164
                        G_CALLBACK (gtk_widget_destroyed), &window);
 
165
      g_signal_connect (window, "delete-event",
 
166
                        G_CALLBACK (gtk_true), NULL);
 
167
 
 
168
      actions = gtk_action_group_new ("Actions");
 
169
      gtk_action_group_add_actions (actions, entries, n_entries, NULL);
 
170
      gtk_action_group_add_toggle_actions (actions, 
 
171
                                           toggle_entries, n_toggle_entries, 
 
172
                                           NULL);
 
173
      gtk_action_group_add_radio_actions (actions, 
 
174
                                          color_entries, n_color_entries, 
 
175
                                          COLOR_RED,
 
176
                                          G_CALLBACK (activate_radio_action), 
 
177
                                          NULL);
 
178
      gtk_action_group_add_radio_actions (actions, 
 
179
                                          shape_entries, n_shape_entries, 
 
180
                                          SHAPE_OVAL,
 
181
                                          G_CALLBACK (activate_radio_action), 
 
182
                                          NULL);
 
183
 
 
184
      ui = gtk_ui_manager_new ();
 
185
      gtk_ui_manager_insert_action_group (ui, actions, 0);
 
186
      g_object_unref (actions);
 
187
      gtk_window_add_accel_group (GTK_WINDOW (window), 
 
188
                                  gtk_ui_manager_get_accel_group (ui));
 
189
      gtk_window_set_title (GTK_WINDOW (window), "UI Manager");
 
190
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);
 
191
 
 
192
      
 
193
      if (!gtk_ui_manager_add_ui_from_string (ui, ui_info, -1, &error))
 
194
        {
 
195
          g_message ("building menus failed: %s", error->message);
 
196
          g_error_free (error);
 
197
        }
 
198
 
 
199
      box1 = gtk_vbox_new (FALSE, 0);
 
200
      gtk_container_add (GTK_CONTAINER (window), box1);
 
201
      
 
202
      gtk_box_pack_start (GTK_BOX (box1),
 
203
                          gtk_ui_manager_get_widget (ui, "/MenuBar"),
 
204
                          FALSE, FALSE, 0);
 
205
 
 
206
      label = gtk_label_new ("Type\n<alt>\nto start");
 
207
      gtk_widget_set_size_request (label, 200, 200);
 
208
      gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
 
209
      gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0);
 
210
 
 
211
 
 
212
      separator = gtk_hseparator_new ();
 
213
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
 
214
 
 
215
 
 
216
      box2 = gtk_vbox_new (FALSE, 10);
 
217
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
 
218
      gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
 
219
 
 
220
      button = gtk_button_new_with_label ("close");
 
221
      g_signal_connect_swapped (button, "clicked",
 
222
                                G_CALLBACK (gtk_widget_destroy), window);
 
223
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
 
224
      GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
 
225
      gtk_widget_grab_default (button);
 
226
 
 
227
      gtk_widget_show_all (window);
 
228
      g_object_unref (ui);
 
229
    }
 
230
  else
 
231
    {
 
232
      gtk_widget_destroy (window);
 
233
      window = NULL;
 
234
    }
 
235
 
 
236
  return window;
 
237
}