/src/wrappers/gtk/library/gtk_menu.e

http://github.com/tybor/Liberty · Specman e · 570 lines · 103 code · 157 blank · 310 comment · 3 complexity · 498cb6e33b2c0edbcff2cc57ae178a91 MD5 · raw file

  1. indexing
  2. description: "GtkMenu -- A menu widget."
  3. copyright: "[
  4. Copyright (C) 2006 eiffel-libraries team, 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 GTK_MENU
  19. -- A GtkMenu is a GtkMenuShell that implements a drop down menu
  20. -- consisting of a list of GtkMenuItem objects which can be
  21. -- navigated and activated by the user to perform application
  22. -- functions.
  23. -- A GtkMenu is most commonly dropped down by activating a
  24. -- GtkMenuItem in a GtkMenuBar or popped up by activating a
  25. -- GtkMenuItem in another GtkMenu.
  26. -- A GtkMenu can also be popped up by activating a
  27. -- GtkOptionMenu. Other composite widgets such as the GtkNotebook
  28. -- can pop up a GtkMenu as well.
  29. -- Applications can display a GtkMenu as a popup menu by calling
  30. -- the gtk_menu_popup() function. The example below shows how an
  31. -- application can pop up a menu when the 3rd mouse button is
  32. -- pressed.
  33. -- TODO: Eiffelize this Example 1. Connecting the popup signal
  34. -- handler.
  35. -- /* connect our handler which will popup the menu */
  36. -- g_signal_connect_swapped (window, "button_press_event",
  37. -- G_CALLBACK (my_popup_handler), menu);
  38. -- TODO: Eiffelize this Example 2. Signal handler which
  39. -- displays a popup menu.
  40. -- static gint
  41. -- my_popup_handler (GtkWidget *widget, GdkEvent *event)
  42. -- {
  43. -- GtkMenu *menu;
  44. -- GdkEventButton *event_button;
  45. -- g_return_val_if_fail (widget != NULL, FALSE);
  46. -- g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
  47. -- g_return_val_if_fail (event != NULL, FALSE);
  48. -- /* The "widget" is the menu that was supplied when
  49. -- * g_signal_connect_swapped() was called.
  50. -- */
  51. -- menu = GTK_MENU (widget);
  52. -- if (event->type == GDK_BUTTON_PRESS)
  53. -- {
  54. -- event_button = (GdkEventButton *) event;
  55. -- if (event_button->button == 3)
  56. -- {
  57. -- gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
  58. -- event_button->button, event_button->time);
  59. -- return TRUE;
  60. -- }
  61. -- }
  62. -- return FALSE;
  63. -- }
  64. inherit
  65. GTK_MENU_SHELL redefine struct_size end
  66. -- GtkMenu implements AtkImplementorIface interface.
  67. insert
  68. G_OBJECT_FACTORY [GTK_WIDGET]
  69. GTK_MENU_EXTERNALS
  70. creation make, from_external_pointer
  71. feature {} -- Creation
  72. make is
  73. -- Creates a new GtkMenu.
  74. require gtk_initialized: gtk.is_initialized
  75. do
  76. from_external_pointer (gtk_menu_new)
  77. end
  78. feature
  79. -- TODO: set_screen (a_screen: GDK_SCREEN) is Sets the GdkScreen on
  80. -- which the menu will be displayed. If `a_screen0 is Void it
  81. -- should be determined by the widget the menu is attached to.
  82. -- do
  83. -- gtk_menu_set_screen (handle, a_screen.handle)
  84. --end
  85. reorder_child (a_child: GTK_WIDGET; a_new_position: INTEGER) is
  86. -- Moves GtkMenuItem `a_child' to `a_new_position' within the
  87. -- GtkMenu.Positions are numbered from 0 to n-1.
  88. require
  89. valid_child: a_child/=Void
  90. do
  91. gtk_menu_reorder_child (handle, a_child.handle, a_new_position)
  92. end
  93. attach (a_child: GTK_WIDGET;
  94. left_attach, right_attach, top_attach, bottom_attach: INTEGER) is
  95. -- Adds a new GtkMenuItem to a (table) menu. The number of
  96. -- 'cells' that an item will occupy is specified by
  97. -- left_attach, right_attach, top_attach and
  98. -- bottom_attach. These each represent the leftmost,
  99. -- rightmost, uppermost and lower column and row numbers of
  100. -- the table. (Columns and rows are indexed from zero).
  101. -- Note that this function is not related to gtk_menu_detach.
  102. -- `left_attach': The column number to attach the left side
  103. -- of the item to.
  104. -- `right_attach': The column number to attach the right side
  105. -- of the item to.
  106. -- `top_attach' : The row number to attach the top of the
  107. -- item to.
  108. -- `bottom_attach' : The row number to attach the bottom of
  109. -- the item to.
  110. require
  111. positive_left_attach: left_attach >= 0 -- since it is a guint
  112. positive_right_attach: right_attach >= 0 -- since it is a guint
  113. positive_top_attach: top_attach >= 0 -- since it is a guint
  114. positive_bottom_attach: bottom_attach >= 0 -- since it is a guint
  115. do
  116. gtk_menu_attach (handle, a_child.handle,
  117. left_attach, right_attach,
  118. top_attach, bottom_attach)
  119. end
  120. -- TODO: understand then wrap popup (a_parent_shell, a_parent_item:
  121. -- GTK_WIDGET; a) is do
  122. -- void gtk_menu_popup (GtkMenu *menu, GtkWidget
  123. -- *parent_menu_shell, GtkWidget *parent_menu_item,
  124. -- GtkMenuPositionFunc func, gpointer data, guint button, guint32
  125. -- activate_time);
  126. -- Displays a menu and makes it available for
  127. -- selection. Applications can use this function to display
  128. -- context-sensitive menus, and will typically supply NULL for the
  129. -- parent_menu_shell, parent_menu_item, func and data
  130. -- parameters. The default menu positioning function will position
  131. -- the menu at the current mouse cursor position.
  132. -- The button parameter should be the mouse button pressed to
  133. -- initiate the menu popup. If the menu popup was initiated by
  134. -- something other than a mouse button press, such as a mouse
  135. -- button release or a keypress, button should be 0.
  136. -- The activate_time parameter should be the time stamp of the
  137. -- event that initiated the popup. If such an event is not
  138. -- available, use gtk_get_current_event_time() instead.
  139. -- menu : a GtkMenu.
  140. -- parent_menu_shell : the menu shell containing the triggering menu item,
  141. -- or NULL
  142. -- parent_menu_item : the menu item whose activation triggered the popup,
  143. -- or NULL
  144. -- func : a user supplied function used to position the menu,
  145. -- or NULL
  146. -- data : user supplied data to be passed to func.
  147. -- button : the mouse button which was pressed to initiate the
  148. -- event.
  149. -- activate_time : the time at which the activation event occurred.
  150. -- TODO: gtk_menu_set_accel_group ()
  151. -- void gtk_menu_set_accel_group (GtkMenu *menu, GtkAccelGroup
  152. -- *accel_group);
  153. -- Set the GtkAccelGroup which holds global accelerators for the
  154. -- menu. This accelerator group needs to also be added to all
  155. -- windows that this menu is being used in with
  156. -- gtk_window_add_accel_group(), in order for those windows to
  157. -- support all the accelerators contained in this group.
  158. -- menu : a GtkMenu.
  159. -- accel_group : the GtkAccelGroup to be associated with the menu.
  160. -- -----------------------------------------------------------------------
  161. -- gtk_menu_get_accel_group ()
  162. -- GtkAccelGroup* gtk_menu_get_accel_group (GtkMenu *menu);
  163. -- Gets the GtkAccelGroup which holds global accelerators for the
  164. -- menu. See gtk_menu_set_accel_group().
  165. -- menu : a GtkMenu.
  166. -- Returns : the GtkAccelGroup associated with the menu.
  167. -- -----------------------------------------------------------------------
  168. -- gtk_menu_set_accel_path ()
  169. -- void gtk_menu_set_accel_path (GtkMenu *menu, const gchar
  170. -- *accel_path);
  171. -- Sets an accelerator path for this menu from which accelerator
  172. -- paths for its immediate children, its menu items, can be
  173. -- constructed. The main purpose of this function is to spare the
  174. -- programmer the inconvenience of having to call
  175. -- gtk_menu_item_set_accel_path() on each menu item that should
  176. -- support runtime user changable accelerators. Instead, by just
  177. -- calling gtk_menu_set_accel_path() on their parent, each menu
  178. -- item of this menu, that contains a label describing its purpose,
  179. -- automatically gets an accel path assigned. For example, a menu
  180. -- containing menu items "New" and "Exit", will, after
  181. -- gtk_menu_set_accel_path (menu, "<Gnumeric-Sheet>/File"); has
  182. -- been called, assign its items the accel paths:
  183. -- "<Gnumeric-Sheet>/File/New" and "<Gnumeric-Sheet>/File/Exit".
  184. -- Assigning accel paths to menu items then enables the user to
  185. -- change their accelerators at runtime. More details about
  186. -- accelerator paths and their default setups can be found at
  187. -- gtk_accel_map_add_entry().
  188. -- menu : a valid GtkMenu accel_path : a valid accelerator path
  189. -- -----------------------------------------------------------------------
  190. set_title (a_title: STRING) is
  191. -- Sets `a_title' as the title for the menu. The title is
  192. -- displayed when the menu is shown as a tearoff menu.
  193. require title_not_void: a_title /= Void
  194. do
  195. gtk_menu_set_title (handle, a_title.to_external)
  196. end
  197. title: STRING is
  198. -- the title of the menu. See `set_title'. Can be Void if
  199. -- the menu has no title set on it.
  200. local ptr: POINTER
  201. do
  202. ptr := gtk_menu_get_title (handle)
  203. if ptr.is_not_null then
  204. -- create Result.from_external_copy (ptr)
  205. create {CONST_STRING} Result.from_external (ptr)
  206. end
  207. end
  208. is_torn_off: BOOLEAN is
  209. -- Is the menu currently torn off.
  210. do
  211. Result := gtk_menu_get_tearoff_state (handle).to_boolean
  212. end
  213. popdown is
  214. -- Removes the menu from the screen.
  215. do
  216. gtk_menu_popdown (handle)
  217. end
  218. reposition is
  219. -- Repositions the menu according to its position function.
  220. do
  221. gtk_menu_reposition (handle)
  222. end
  223. active_item: GTK_WIDGET is
  224. -- the selected menu item from the menu. This is used by the
  225. -- GtkOptionMenu. If a selection has not yet been made, the
  226. -- first menu item is selected.
  227. do
  228. Result := wrapper(gtk_menu_get_active (handle))
  229. end
  230. set_active (an_index: INTEGER) is
  231. -- Selects the specified menu item within the menu. This is
  232. -- used by the GtkOptionMenu and should not be used by anyone
  233. -- else. `an_index' is values are from 0 to n-1.
  234. require natural_index: an_index >= 0
  235. do
  236. gtk_menu_set_active (handle, an_index)
  237. end
  238. set_tearoff is
  239. -- Changes the tearoff state of the menu. A menu is normally
  240. -- displayed as drop down menu which persists as long as the
  241. -- menu is active. It can also be displayed as a tearoff menu
  242. -- which persists until it is closed or reattached.
  243. do
  244. gtk_menu_set_tearoff_state (handle, 1)
  245. ensure is_torn_off
  246. end
  247. unset_tearoff is
  248. -- Changes the tearoff state of the menu. A menu is normally
  249. -- displayed as drop down menu which persists as long as the
  250. -- menu is active. It can also be displayed as a tearoff menu
  251. -- which persists until it is closed or reattached.
  252. do
  253. gtk_menu_set_tearoff_state (handle, 0)
  254. ensure not is_torn_off
  255. end
  256. -- TODO: wrap gtk_menu_attach_to_widget ()
  257. -- void gtk_menu_attach_to_widget (GtkMenu *menu, GtkWidget
  258. -- *attach_widget, GtkMenuDetachFunc detacher);
  259. -- Attaches the menu to the widget and provides a callback function
  260. -- that will be invoked when the menu calls gtk_menu_detach()
  261. -- during its destruction.
  262. -- menu : a GtkMenu.
  263. -- attach_widget : the GtkWidget that the menu will be attached to.
  264. -- detacher : the user supplied callback function that will be called
  265. -- when the menu calls gtk_menu_detach(), or NULL
  266. -- TODO: wrap gtk_menu_detach ()
  267. -- void gtk_menu_detach (GtkMenu *menu);
  268. -- Detaches the menu from the widget to which it had been
  269. -- attached. This function will call the callback function,
  270. -- detacher, provided when the gtk_menu_attach_to_widget() function
  271. -- was called.
  272. -- menu : a GtkMenu.
  273. -- -----------------------------------------------------------------------
  274. -- TODO: wrap gtk_menu_get_attach_widget ()
  275. -- GtkWidget* gtk_menu_get_attach_widget (GtkMenu *menu);
  276. -- Returns the GtkWidget that the menu is attached to.
  277. -- menu : a GtkMenu.
  278. -- Returns : the GtkWidget that the menu is attached to.
  279. -- -----------------------------------------------------------------------
  280. -- TODO: wrap gtk_menu_get_for_attach_widget ()
  281. -- GList* gtk_menu_get_for_attach_widget (GtkWidget *widget);
  282. -- widget : a GtkWidget * Returns a list of the menus which are attached
  283. -- to this widget. This list is owned by GTK+ and must not be
  284. -- modified.
  285. -- Returns : the list of menus attached to his widget.
  286. -- Since 2.6
  287. -- -----------------------------------------------------------------------
  288. -- GtkMenuPositionFunc ()
  289. -- void (*GtkMenuPositionFunc) (GtkMenu *menu,
  290. -- gint *x,
  291. -- gint *y,
  292. -- gboolean *push_in,
  293. -- gpointer user_data);
  294. -- A user function supplied when calling gtk_menu_popup() which controls
  295. -- the positioning of the menu when it is displayed. The function sets the
  296. -- x and y parameters to the coordinates where the menu is to be drawn.
  297. -- menu : a GtkMenu.
  298. -- x : address of the gint representing the horizontal position
  299. -- where the menu shall be drawn. This is an output parameter.
  300. -- y : address of the gint representing the vertical position
  301. -- where the menu shall be drawn. This is an output parameter.
  302. -- push_in : whether the menu should be pushed in to be completely
  303. -- inside the screen instead of just clamped to the size to
  304. -- the screen.
  305. -- user_data : the data supplied by the user in the gtk_menu_popup() data
  306. -- parameter.
  307. -- -----------------------------------------------------------------------
  308. -- GtkMenuDetachFunc ()
  309. -- void (*GtkMenuDetachFunc) (GtkWidget *attach_widget,
  310. -- GtkMenu *menu);
  311. -- A user function supplied when calling gtk_menu_attach_to_widget() which
  312. -- will be called when the menu is later detached from the widget.
  313. -- attach_widget : the GtkWidget that the menu is being detached from.
  314. -- menu : the GtkMenu being detached.
  315. -- -----------------------------------------------------------------------
  316. -- TODO: wrap gtk_menu_set_monitor ()
  317. -- void gtk_menu_set_monitor (GtkMenu *menu,
  318. -- gint monitor_num);
  319. -- Informs GTK+ on which monitor a menu should be popped up. See
  320. -- gdk_screen_get_monitor_geometry().
  321. -- This function should be called from a GtkMenuPositionFunc if the menu
  322. -- should not appear on the same monitor as the pointer. This information
  323. -- can't be reliably inferred from the coordinates returned by a
  324. -- GtkMenuPositionFunc, since, for very long menus, these coordinates may
  325. -- extend beyond the monitor boundaries or even the screen boundaries.
  326. -- menu : a GtkMenu
  327. -- monitor_num : the number of the monitor on which the menu should be
  328. -- popped up
  329. -- Since 2.4
  330. feature -- Properties
  331. -- "tearoff-state" gboolean : Read / Write
  332. -- "tearoff-title" gchararray : Read / Write
  333. -- The "tearoff-state" property
  334. -- "tearoff-state" gboolean : Read / Write
  335. -- A boolean that indicates whether the menu is torn-off.
  336. -- Default value: FALSE
  337. -- Since 2.6
  338. -- -----------------------------------------------------------------------
  339. -- The "tearoff-title" property
  340. -- "tearoff-title" gchararray : Read / Write
  341. -- A title that may be displayed by the window manager when this menu is
  342. -- torn-off.
  343. -- Default value: ""
  344. feature -- Child Properties
  345. -- "bottom-attach" gint : Read / Write
  346. -- "left-attach" gint : Read / Write
  347. -- "right-attach" gint : Read / Write
  348. -- "top-attach" gint : Read / Write
  349. -- Child Property Details
  350. -- The "bottom-attach" child property
  351. -- "bottom-attach" gint : Read / Write
  352. -- The row number to attach the bottom of the child to.
  353. -- Allowed values: >= -1
  354. -- Default value: -1
  355. -- -----------------------------------------------------------------------
  356. -- The "left-attach" child property
  357. -- "left-attach" gint : Read / Write
  358. -- The column number to attach the left side of the child to.
  359. -- Allowed values: >= -1
  360. -- Default value: -1
  361. -- -----------------------------------------------------------------------
  362. -- The "right-attach" child property
  363. -- "right-attach" gint : Read / Write
  364. -- The column number to attach the right side of the child to.
  365. -- Allowed values: >= -1
  366. -- Default value: -1
  367. -- -----------------------------------------------------------------------
  368. -- The "top-attach" child property
  369. -- "top-attach" gint : Read / Write
  370. -- The row number to attach the top of the child to.
  371. -- Allowed values: >= -1
  372. -- Default value: -1
  373. feature -- Style Properties
  374. -- "horizontal-offset" gint : Read
  375. -- "vertical-offset" gint : Read
  376. -- "vertical-padding" gint : Read
  377. -- Style Property Details
  378. -- The "horizontal-offset" style property
  379. -- "horizontal-offset" gint : Read
  380. -- When the menu is a submenu, position it this number of pixels offset
  381. -- horizontally.
  382. -- Default value: -2
  383. -- -----------------------------------------------------------------------
  384. -- The "vertical-offset" style property
  385. -- "vertical-offset" gint : Read
  386. -- When the menu is a submenu, position it this number of pixels offset
  387. -- vertically.
  388. -- Default value: 0
  389. -- -----------------------------------------------------------------------
  390. -- The "vertical-padding" style property
  391. -- "vertical-padding" gint : Read
  392. -- Extra space at the top and bottom of the menu.
  393. -- Allowed values: >= 0
  394. -- Default value: 1
  395. -- Signals
  396. -- "move-scroll"
  397. -- void user_function (GtkMenu *menu,
  398. -- GtkScrollType *arg1,
  399. -- gpointer user_data) : Run last / Action
  400. feature -- Signal Details
  401. -- The "move-scroll" signal
  402. -- void user_function (GtkMenu *menu,
  403. -- GtkScrollType *arg1,
  404. -- gpointer user_data) : Run last / Action
  405. -- menu : the object which received the signal.
  406. -- arg1 :
  407. -- user_data : user data set when the signal handler was connected.
  408. feature -- size
  409. struct_size: INTEGER is
  410. external "C inline use <gtk/gtk.h>"
  411. alias "sizeof(GtkMenu)"
  412. end
  413. end