/src/wrappers/gtk/examples/gtk-demo/ui_manager.e

http://github.com/tybor/Liberty · Specman e · 262 lines · 21 code · 35 blank · 206 comment · 2 complexity · acca099d04cdcbaac4e5795ea2624c32 MD5 · raw file

  1. indexing
  2. description: "."
  3. copyright: "[
  4. Copyright (C) 2006 Paolo Redaelli, GTK+ team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. class UI_MANAGER
  19. creation make, from_external_pointer
  20. feature {} -- Creation
  21. -- /* UI Manager
  22. -- *
  23. -- * The GtkUIManager object allows the easy creation of menus
  24. -- * from an array of actions and a description of the menu hierarchy.
  25. -- */
  26. -- #include <gtk/gtk.h>
  27. -- static void
  28. -- activate_action (GtkAction *action)
  29. -- {
  30. -- g_message ("Action \"%s\" activated", gtk_action_get_name (action));
  31. -- }
  32. -- static void
  33. -- activate_radio_action (GtkAction *action, GtkRadioAction *current)
  34. -- {
  35. -- g_message ("Radio action \"%s\" selected",
  36. -- gtk_action_get_name (GTK_ACTION (current)));
  37. -- }
  38. -- static GtkActionEntry entries[] = {
  39. -- { "FileMenu", NULL, "_File" }, /* name, stock id, label */
  40. -- { "PreferencesMenu", NULL, "_Preferences" }, /* name, stock id, label */
  41. -- { "ColorMenu", NULL, "_Color" }, /* name, stock id, label */
  42. -- { "ShapeMenu", NULL, "_Shape" }, /* name, stock id, label */
  43. -- { "HelpMenu", NULL, "_Help" }, /* name, stock id, label */
  44. -- { "New", GTK_STOCK_NEW, /* name, stock id */
  45. -- "_New", "<control>N", /* label, accelerator */
  46. -- "Create a new file", /* tooltip */
  47. -- G_CALLBACK (activate_action) },
  48. -- { "Open", GTK_STOCK_OPEN, /* name, stock id */
  49. -- "_Open","<control>O", /* label, accelerator */
  50. -- "Open a file", /* tooltip */
  51. -- G_CALLBACK (activate_action) },
  52. -- { "Save", GTK_STOCK_SAVE, /* name, stock id */
  53. -- "_Save","<control>S", /* label, accelerator */
  54. -- "Save current file", /* tooltip */
  55. -- G_CALLBACK (activate_action) },
  56. -- { "SaveAs", GTK_STOCK_SAVE, /* name, stock id */
  57. -- "Save _As...", NULL, /* label, accelerator */
  58. -- "Save to a file", /* tooltip */
  59. -- G_CALLBACK (activate_action) },
  60. -- { "Quit", GTK_STOCK_QUIT, /* name, stock id */
  61. -- "_Quit", "<control>Q", /* label, accelerator */
  62. -- "Quit", /* tooltip */
  63. -- G_CALLBACK (activate_action) },
  64. -- { "About", NULL, /* name, stock id */
  65. -- "_About", "<control>A", /* label, accelerator */
  66. -- "About", /* tooltip */
  67. -- G_CALLBACK (activate_action) },
  68. -- { "Logo", "demo-gtk-logo", /* name, stock id */
  69. -- NULL, NULL, /* label, accelerator */
  70. -- "GTK+", /* tooltip */
  71. -- G_CALLBACK (activate_action) },
  72. -- };
  73. -- static guint n_entries = G_N_ELEMENTS (entries);
  74. -- static GtkToggleActionEntry toggle_entries[] = {
  75. -- { "Bold", GTK_STOCK_BOLD, /* name, stock id */
  76. -- "_Bold", "<control>B", /* label, accelerator */
  77. -- "Bold", /* tooltip */
  78. -- G_CALLBACK (activate_action),
  79. -- TRUE }, /* is_active */
  80. -- };
  81. -- static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
  82. -- enum {
  83. -- COLOR_RED,
  84. -- COLOR_GREEN,
  85. -- COLOR_BLUE
  86. -- };
  87. -- static GtkRadioActionEntry color_entries[] = {
  88. -- { "Red", NULL, /* name, stock id */
  89. -- "_Red", "<control>R", /* label, accelerator */
  90. -- "Blood", COLOR_RED }, /* tooltip, value */
  91. -- { "Green", NULL, /* name, stock id */
  92. -- "_Green", "<control>G", /* label, accelerator */
  93. -- "Grass", COLOR_GREEN }, /* tooltip, value */
  94. -- { "Blue", NULL, /* name, stock id */
  95. -- "_Blue", "<control>B", /* label, accelerator */
  96. -- "Sky", COLOR_BLUE }, /* tooltip, value */
  97. -- };
  98. -- static guint n_color_entries = G_N_ELEMENTS (color_entries);
  99. -- enum {
  100. -- SHAPE_SQUARE,
  101. -- SHAPE_RECTANGLE,
  102. -- SHAPE_OVAL
  103. -- };
  104. -- static GtkRadioActionEntry shape_entries[] = {
  105. -- { "Square", NULL, /* name, stock id */
  106. -- "_Square", "<control>S", /* label, accelerator */
  107. -- "Square", SHAPE_SQUARE }, /* tooltip, value */
  108. -- { "Rectangle", NULL, /* name, stock id */
  109. -- "_Rectangle", "<control>R", /* label, accelerator */
  110. -- "Rectangle", SHAPE_RECTANGLE }, /* tooltip, value */
  111. -- { "Oval", NULL, /* name, stock id */
  112. -- "_Oval", "<control>O", /* label, accelerator */
  113. -- "Egg", SHAPE_OVAL }, /* tooltip, value */
  114. -- };
  115. -- static guint n_shape_entries = G_N_ELEMENTS (shape_entries);
  116. -- static const gchar *ui_info =
  117. -- "<ui>"
  118. -- " <menubar name='MenuBar'>"
  119. -- " <menu action='FileMenu'>"
  120. -- " <menuitem action='New'/>"
  121. -- " <menuitem action='Open'/>"
  122. -- " <menuitem action='Save'/>"
  123. -- " <menuitem action='SaveAs'/>"
  124. -- " <separator/>"
  125. -- " <menuitem action='Quit'/>"
  126. -- " </menu>"
  127. -- " <menu action='PreferencesMenu'>"
  128. -- " <menu action='ColorMenu'>"
  129. -- " <menuitem action='Red'/>"
  130. -- " <menuitem action='Green'/>"
  131. -- " <menuitem action='Blue'/>"
  132. -- " </menu>"
  133. -- " <menu action='ShapeMenu'>"
  134. -- " <menuitem action='Square'/>"
  135. -- " <menuitem action='Rectangle'/>"
  136. -- " <menuitem action='Oval'/>"
  137. -- " </menu>"
  138. -- " <menuitem action='Bold'/>"
  139. -- " </menu>"
  140. -- " <menu action='HelpMenu'>"
  141. -- " <menuitem action='About'/>"
  142. -- " </menu>"
  143. -- " </menubar>"
  144. -- " <toolbar name='ToolBar'>"
  145. -- " <toolitem action='Open'/>"
  146. -- " <toolitem action='Quit'/>"
  147. -- " <separator action='Sep1'/>"
  148. -- " <toolitem action='Logo'/>"
  149. -- " </toolbar>"
  150. -- "</ui>";
  151. -- GtkWidget *
  152. -- do_ui_manager (GtkWidget *do_widget)
  153. -- {
  154. -- static GtkWidget *window = NULL;
  155. -- if (!window)
  156. -- {
  157. -- GtkWidget *box1;
  158. -- GtkWidget *box2;
  159. -- GtkWidget *separator;
  160. -- GtkWidget *label;
  161. -- GtkWidget *button;
  162. -- GtkUIManager *ui;
  163. -- GtkActionGroup *actions;
  164. -- GError *error = NULL;
  165. -- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  166. -- gtk_window_set_screen (GTK_WINDOW (window),
  167. -- gtk_widget_get_screen (do_widget));
  168. -- g_signal_connect (window, "destroy",
  169. -- G_CALLBACK (gtk_widget_destroyed), &window);
  170. -- g_signal_connect (window, "delete-event",
  171. -- G_CALLBACK (gtk_true), NULL);
  172. -- actions = gtk_action_group_new ("Actions");
  173. -- gtk_action_group_add_actions (actions, entries, n_entries, NULL);
  174. -- gtk_action_group_add_toggle_actions (actions,
  175. -- toggle_entries, n_toggle_entries,
  176. -- NULL);
  177. -- gtk_action_group_add_radio_actions (actions,
  178. -- color_entries, n_color_entries,
  179. -- COLOR_RED,
  180. -- G_CALLBACK (activate_radio_action),
  181. -- NULL);
  182. -- gtk_action_group_add_radio_actions (actions,
  183. -- shape_entries, n_shape_entries,
  184. -- SHAPE_OVAL,
  185. -- G_CALLBACK (activate_radio_action),
  186. -- NULL);
  187. -- ui = gtk_ui_manager_new ();
  188. -- gtk_ui_manager_insert_action_group (ui, actions, 0);
  189. -- gtk_window_add_accel_group (GTK_WINDOW (window),
  190. -- gtk_ui_manager_get_accel_group (ui));
  191. -- gtk_window_set_title (GTK_WINDOW (window), "UI Manager");
  192. -- gtk_container_set_border_width (GTK_CONTAINER (window), 0);
  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. -- box1 = gtk_vbox_new (FALSE, 0);
  199. -- gtk_container_add (GTK_CONTAINER (window), box1);
  200. -- gtk_box_pack_start (GTK_BOX (box1),
  201. -- gtk_ui_manager_get_widget (ui, "/MenuBar"),
  202. -- FALSE, FALSE, 0);
  203. -- label = gtk_label_new ("Type\n<alt>\nto start");
  204. -- gtk_widget_set_size_request (label, 200, 200);
  205. -- gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
  206. -- gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0);
  207. -- separator = gtk_hseparator_new ();
  208. -- gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
  209. -- box2 = gtk_vbox_new (FALSE, 10);
  210. -- gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  211. -- gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
  212. -- button = gtk_button_new_with_label ("close");
  213. -- g_signal_connect_swapped (button, "clicked",
  214. -- G_CALLBACK (gtk_widget_destroy), window);
  215. -- gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
  216. -- GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  217. -- gtk_widget_grab_default (button);
  218. -- gtk_widget_show_all (window);
  219. -- }
  220. -- else
  221. -- {
  222. -- gtk_widget_destroy (window);
  223. -- window = NULL;
  224. -- }
  225. -- return window;
  226. -- }
  227. end