gtk/auto/menu_shell.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{Buildable, Container, DirectionType, MenuDirectionType, MenuItem, Widget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14 /// A [`MenuShell`][crate::MenuShell] is the abstract base class used to derive the
15 /// [`Menu`][crate::Menu] and [`MenuBar`][crate::MenuBar] subclasses.
16 ///
17 /// A [`MenuShell`][crate::MenuShell] is a container of [`MenuItem`][crate::MenuItem] objects arranged
18 /// in a list which can be navigated, selected, and activated by the
19 /// user to perform application functions. A [`MenuItem`][crate::MenuItem] can have a
20 /// submenu associated with it, allowing for nested hierarchical menus.
21 ///
22 /// # Terminology
23 ///
24 /// A menu item can be “selected”, this means that it is displayed
25 /// in the prelight state, and if it has a submenu, that submenu
26 /// will be popped up.
27 ///
28 /// A menu is “active” when it is visible onscreen and the user
29 /// is selecting from it. A menubar is not active until the user
30 /// clicks on one of its menuitems. When a menu is active,
31 /// passing the mouse over a submenu will pop it up.
32 ///
33 /// There is also is a concept of the current menu and a current
34 /// menu item. The current menu item is the selected menu item
35 /// that is furthest down in the hierarchy. (Every active menu shell
36 /// does not necessarily contain a selected menu item, but if
37 /// it does, then the parent menu shell must also contain
38 /// a selected menu item.) The current menu is the menu that
39 /// contains the current menu item. It will always have a GTK
40 /// grab and receive all key presses.
41 ///
42 /// This is an Abstract Base Class, you cannot instantiate it.
43 ///
44 /// ## Properties
45 ///
46 ///
47 /// #### `take-focus`
48 /// A boolean that determines whether the menu and its submenus grab the
49 /// keyboard focus. See [`MenuShellExt::set_take_focus()`][crate::prelude::MenuShellExt::set_take_focus()] and
50 /// [`MenuShellExt::takes_focus()`][crate::prelude::MenuShellExt::takes_focus()].
51 ///
52 /// Readable | Writeable
53 /// <details><summary><h4>Container</h4></summary>
54 ///
55 ///
56 /// #### `border-width`
57 /// Readable | Writeable
58 ///
59 ///
60 /// #### `child`
61 /// Writeable
62 ///
63 ///
64 /// #### `resize-mode`
65 /// Readable | Writeable
66 /// </details>
67 /// <details><summary><h4>Widget</h4></summary>
68 ///
69 ///
70 /// #### `app-paintable`
71 /// Readable | Writeable
72 ///
73 ///
74 /// #### `can-default`
75 /// Readable | Writeable
76 ///
77 ///
78 /// #### `can-focus`
79 /// Readable | Writeable
80 ///
81 ///
82 /// #### `composite-child`
83 /// Readable
84 ///
85 ///
86 /// #### `double-buffered`
87 /// Whether the widget is double buffered.
88 ///
89 /// Readable | Writeable
90 ///
91 ///
92 /// #### `events`
93 /// Readable | Writeable
94 ///
95 ///
96 /// #### `expand`
97 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
98 ///
99 /// Readable | Writeable
100 ///
101 ///
102 /// #### `focus-on-click`
103 /// Whether the widget should grab focus when it is clicked with the mouse.
104 ///
105 /// This property is only relevant for widgets that can take focus.
106 ///
107 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
108 /// GtkComboBox) implemented this property individually.
109 ///
110 /// Readable | Writeable
111 ///
112 ///
113 /// #### `halign`
114 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
115 ///
116 /// Readable | Writeable
117 ///
118 ///
119 /// #### `has-default`
120 /// Readable | Writeable
121 ///
122 ///
123 /// #### `has-focus`
124 /// Readable | Writeable
125 ///
126 ///
127 /// #### `has-tooltip`
128 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
129 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
130 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
131 /// whether it will provide a tooltip or not.
132 ///
133 /// Note that setting this property to [`true`] for the first time will change
134 /// the event masks of the GdkWindows of this widget to include leave-notify
135 /// and motion-notify events. This cannot and will not be undone when the
136 /// property is set to [`false`] again.
137 ///
138 /// Readable | Writeable
139 ///
140 ///
141 /// #### `height-request`
142 /// Readable | Writeable
143 ///
144 ///
145 /// #### `hexpand`
146 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
147 ///
148 /// Readable | Writeable
149 ///
150 ///
151 /// #### `hexpand-set`
152 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
153 ///
154 /// Readable | Writeable
155 ///
156 ///
157 /// #### `is-focus`
158 /// Readable | Writeable
159 ///
160 ///
161 /// #### `margin`
162 /// Sets all four sides' margin at once. If read, returns max
163 /// margin on any side.
164 ///
165 /// Readable | Writeable
166 ///
167 ///
168 /// #### `margin-bottom`
169 /// Margin on bottom side of widget.
170 ///
171 /// This property adds margin outside of the widget's normal size
172 /// request, the margin will be added in addition to the size from
173 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
174 ///
175 /// Readable | Writeable
176 ///
177 ///
178 /// #### `margin-end`
179 /// Margin on end of widget, horizontally. This property supports
180 /// left-to-right and right-to-left text directions.
181 ///
182 /// This property adds margin outside of the widget's normal size
183 /// request, the margin will be added in addition to the size from
184 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
185 ///
186 /// Readable | Writeable
187 ///
188 ///
189 /// #### `margin-left`
190 /// Margin on left side of widget.
191 ///
192 /// This property adds margin outside of the widget's normal size
193 /// request, the margin will be added in addition to the size from
194 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
195 ///
196 /// Readable | Writeable
197 ///
198 ///
199 /// #### `margin-right`
200 /// Margin on right side of widget.
201 ///
202 /// This property adds margin outside of the widget's normal size
203 /// request, the margin will be added in addition to the size from
204 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
205 ///
206 /// Readable | Writeable
207 ///
208 ///
209 /// #### `margin-start`
210 /// Margin on start of widget, horizontally. This property supports
211 /// left-to-right and right-to-left text directions.
212 ///
213 /// This property adds margin outside of the widget's normal size
214 /// request, the margin will be added in addition to the size from
215 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
216 ///
217 /// Readable | Writeable
218 ///
219 ///
220 /// #### `margin-top`
221 /// Margin on top side of widget.
222 ///
223 /// This property adds margin outside of the widget's normal size
224 /// request, the margin will be added in addition to the size from
225 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
226 ///
227 /// Readable | Writeable
228 ///
229 ///
230 /// #### `name`
231 /// Readable | Writeable
232 ///
233 ///
234 /// #### `no-show-all`
235 /// Readable | Writeable
236 ///
237 ///
238 /// #### `opacity`
239 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
240 /// more details about window opacity.
241 ///
242 /// Before 3.8 this was only available in GtkWindow
243 ///
244 /// Readable | Writeable
245 ///
246 ///
247 /// #### `parent`
248 /// Readable | Writeable
249 ///
250 ///
251 /// #### `receives-default`
252 /// Readable | Writeable
253 ///
254 ///
255 /// #### `scale-factor`
256 /// The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
257 /// more details about widget scaling.
258 ///
259 /// Readable
260 ///
261 ///
262 /// #### `sensitive`
263 /// Readable | Writeable
264 ///
265 ///
266 /// #### `style`
267 /// The style of the widget, which contains information about how it will look (colors, etc).
268 ///
269 /// Readable | Writeable
270 ///
271 ///
272 /// #### `tooltip-markup`
273 /// Sets the text of tooltip to be the given string, which is marked up
274 /// with the [Pango text markup language][PangoMarkupFormat].
275 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
276 ///
277 /// This is a convenience property which will take care of getting the
278 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
279 /// will automatically be set to [`true`] and there will be taken care of
280 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
281 ///
282 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
283 /// are set, the last one wins.
284 ///
285 /// Readable | Writeable
286 ///
287 ///
288 /// #### `tooltip-text`
289 /// Sets the text of tooltip to be the given string.
290 ///
291 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
292 ///
293 /// This is a convenience property which will take care of getting the
294 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
295 /// will automatically be set to [`true`] and there will be taken care of
296 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
297 ///
298 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
299 /// are set, the last one wins.
300 ///
301 /// Readable | Writeable
302 ///
303 ///
304 /// #### `valign`
305 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
306 ///
307 /// Readable | Writeable
308 ///
309 ///
310 /// #### `vexpand`
311 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
312 ///
313 /// Readable | Writeable
314 ///
315 ///
316 /// #### `vexpand-set`
317 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
318 ///
319 /// Readable | Writeable
320 ///
321 ///
322 /// #### `visible`
323 /// Readable | Writeable
324 ///
325 ///
326 /// #### `width-request`
327 /// Readable | Writeable
328 ///
329 ///
330 /// #### `window`
331 /// The widget's window if it is realized, [`None`] otherwise.
332 ///
333 /// Readable
334 /// </details>
335 ///
336 /// ## Signals
337 ///
338 ///
339 /// #### `activate-current`
340 /// An action signal that activates the current menu item within
341 /// the menu shell.
342 ///
343 /// Action
344 ///
345 ///
346 /// #### `cancel`
347 /// An action signal which cancels the selection within the menu shell.
348 /// Causes the [`selection-done`][struct@crate::MenuShell#selection-done] signal to be emitted.
349 ///
350 /// Action
351 ///
352 ///
353 /// #### `cycle-focus`
354 /// A keybinding signal which moves the focus in the
355 /// given `direction`.
356 ///
357 /// Action
358 ///
359 ///
360 /// #### `deactivate`
361 /// This signal is emitted when a menu shell is deactivated.
362 ///
363 ///
364 ///
365 ///
366 /// #### `insert`
367 /// The ::insert signal is emitted when a new [`MenuItem`][crate::MenuItem] is added to
368 /// a [`MenuShell`][crate::MenuShell]. A separate signal is used instead of
369 /// GtkContainer::add because of the need for an additional position
370 /// parameter.
371 ///
372 /// The inverse of this signal is the GtkContainer::removed signal.
373 ///
374 ///
375 ///
376 ///
377 /// #### `move-current`
378 /// An keybinding signal which moves the current menu item
379 /// in the direction specified by `direction`.
380 ///
381 /// Action
382 ///
383 ///
384 /// #### `move-selected`
385 /// The ::move-selected signal is emitted to move the selection to
386 /// another item.
387 ///
388 ///
389 ///
390 ///
391 /// #### `selection-done`
392 /// This signal is emitted when a selection has been
393 /// completed within a menu shell.
394 ///
395 ///
396 /// <details><summary><h4>Container</h4></summary>
397 ///
398 ///
399 /// #### `add`
400 ///
401 ///
402 ///
403 /// #### `check-resize`
404 ///
405 ///
406 ///
407 /// #### `remove`
408 ///
409 ///
410 ///
411 /// #### `set-focus-child`
412 ///
413 /// </details>
414 /// <details><summary><h4>Widget</h4></summary>
415 ///
416 ///
417 /// #### `accel-closures-changed`
418 ///
419 ///
420 ///
421 /// #### `button-press-event`
422 /// The ::button-press-event signal will be emitted when a button
423 /// (typically from a mouse) is pressed.
424 ///
425 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the
426 /// widget needs to enable the [`gdk::EventMask::BUTTON_PRESS_MASK`][crate::gdk::EventMask::BUTTON_PRESS_MASK] mask.
427 ///
428 /// This signal will be sent to the grab widget if there is one.
429 ///
430 ///
431 ///
432 ///
433 /// #### `button-release-event`
434 /// The ::button-release-event signal will be emitted when a button
435 /// (typically from a mouse) is released.
436 ///
437 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the
438 /// widget needs to enable the [`gdk::EventMask::BUTTON_RELEASE_MASK`][crate::gdk::EventMask::BUTTON_RELEASE_MASK] mask.
439 ///
440 /// This signal will be sent to the grab widget if there is one.
441 ///
442 ///
443 ///
444 ///
445 /// #### `can-activate-accel`
446 /// Determines whether an accelerator that activates the signal
447 /// identified by `signal_id` can currently be activated.
448 /// This signal is present to allow applications and derived
449 /// widgets to override the default [`Widget`][crate::Widget] handling
450 /// for determining whether an accelerator can be activated.
451 ///
452 ///
453 ///
454 ///
455 /// #### `child-notify`
456 /// The ::child-notify signal is emitted for each
457 /// [child property][child-properties] that has
458 /// changed on an object. The signal's detail holds the property name.
459 ///
460 /// Detailed
461 ///
462 ///
463 /// #### `composited-changed`
464 /// The ::composited-changed signal is emitted when the composited
465 /// status of `widgets` screen changes.
466 /// See [`Screen::is_composited()`][crate::gdk::Screen::is_composited()].
467 ///
468 /// Action
469 ///
470 ///
471 /// #### `configure-event`
472 /// The ::configure-event signal will be emitted when the size, position or
473 /// stacking of the `widget`'s window has changed.
474 ///
475 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
476 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
477 /// automatically for all new windows.
478 ///
479 ///
480 ///
481 ///
482 /// #### `damage-event`
483 /// Emitted when a redirected window belonging to `widget` gets drawn into.
484 /// The region/area members of the event shows what area of the redirected
485 /// drawable was drawn into.
486 ///
487 ///
488 ///
489 ///
490 /// #### `delete-event`
491 /// The ::delete-event signal is emitted if a user requests that
492 /// a toplevel window is closed. The default handler for this signal
493 /// destroys the window. Connecting [`WidgetExtManual::hide_on_delete()`][crate::prelude::WidgetExtManual::hide_on_delete()] to
494 /// this signal will cause the window to be hidden instead, so that
495 /// it can later be shown again without reconstructing it.
496 ///
497 ///
498 ///
499 ///
500 /// #### `destroy`
501 /// Signals that all holders of a reference to the widget should release
502 /// the reference that they hold. May result in finalization of the widget
503 /// if all references are released.
504 ///
505 /// This signal is not suitable for saving widget state.
506 ///
507 ///
508 ///
509 ///
510 /// #### `destroy-event`
511 /// The ::destroy-event signal is emitted when a [`gdk::Window`][crate::gdk::Window] is destroyed.
512 /// You rarely get this signal, because most widgets disconnect themselves
513 /// from their window before they destroy it, so no widget owns the
514 /// window at destroy time.
515 ///
516 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
517 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
518 /// automatically for all new windows.
519 ///
520 ///
521 ///
522 ///
523 /// #### `direction-changed`
524 /// The ::direction-changed signal is emitted when the text direction
525 /// of a widget changes.
526 ///
527 ///
528 ///
529 ///
530 /// #### `drag-begin`
531 /// The ::drag-begin signal is emitted on the drag source when a drag is
532 /// started. A typical reason to connect to this signal is to set up a
533 /// custom drag icon with e.g. [`WidgetExt::drag_source_set_icon_pixbuf()`][crate::prelude::WidgetExt::drag_source_set_icon_pixbuf()].
534 ///
535 /// Note that some widgets set up a drag icon in the default handler of
536 /// this signal, so you may have to use `g_signal_connect_after()` to
537 /// override what the default handler did.
538 ///
539 ///
540 ///
541 ///
542 /// #### `drag-data-delete`
543 /// The ::drag-data-delete signal is emitted on the drag source when a drag
544 /// with the action [`gdk::DragAction::MOVE`][crate::gdk::DragAction::MOVE] is successfully completed. The signal
545 /// handler is responsible for deleting the data that has been dropped. What
546 /// "delete" means depends on the context of the drag operation.
547 ///
548 ///
549 ///
550 ///
551 /// #### `drag-data-get`
552 /// The ::drag-data-get signal is emitted on the drag source when the drop
553 /// site requests the data which is dragged. It is the responsibility of
554 /// the signal handler to fill `data` with the data in the format which
555 /// is indicated by `info`. See [`SelectionData::set()`][crate::SelectionData::set()] and
556 /// [`SelectionData::set_text()`][crate::SelectionData::set_text()].
557 ///
558 ///
559 ///
560 ///
561 /// #### `drag-data-received`
562 /// The ::drag-data-received signal is emitted on the drop site when the
563 /// dragged data has been received. If the data was received in order to
564 /// determine whether the drop will be accepted, the handler is expected
565 /// to call `gdk_drag_status()` and not finish the drag.
566 /// If the data was received in response to a [`drag-drop`][struct@crate::Widget#drag-drop] signal
567 /// (and this is the last target to be received), the handler for this
568 /// signal is expected to process the received data and then call
569 /// `gtk_drag_finish()`, setting the `success` parameter depending on
570 /// whether the data was processed successfully.
571 ///
572 /// Applications must create some means to determine why the signal was emitted
573 /// and therefore whether to call `gdk_drag_status()` or `gtk_drag_finish()`.
574 ///
575 /// The handler may inspect the selected action with
576 /// [`DragContext::selected_action()`][crate::gdk::DragContext::selected_action()] before calling
577 /// `gtk_drag_finish()`, e.g. to implement [`gdk::DragAction::ASK`][crate::gdk::DragAction::ASK] as
578 /// shown in the following example:
579 ///
580 ///
581 /// **⚠️ The following code is in C ⚠️**
582 ///
583 /// ```C
584 /// void
585 /// drag_data_received (GtkWidget *widget,
586 /// GdkDragContext *context,
587 /// gint x,
588 /// gint y,
589 /// GtkSelectionData *data,
590 /// guint info,
591 /// guint time)
592 /// {
593 /// if ((data->length >= 0) && (data->format == 8))
594 /// {
595 /// GdkDragAction action;
596 ///
597 /// // handle data here
598 ///
599 /// action = gdk_drag_context_get_selected_action (context);
600 /// if (action == GDK_ACTION_ASK)
601 /// {
602 /// GtkWidget *dialog;
603 /// gint response;
604 ///
605 /// dialog = gtk_message_dialog_new (NULL,
606 /// GTK_DIALOG_MODAL |
607 /// GTK_DIALOG_DESTROY_WITH_PARENT,
608 /// GTK_MESSAGE_INFO,
609 /// GTK_BUTTONS_YES_NO,
610 /// "Move the data ?\n");
611 /// response = gtk_dialog_run (GTK_DIALOG (dialog));
612 /// gtk_widget_destroy (dialog);
613 ///
614 /// if (response == GTK_RESPONSE_YES)
615 /// action = GDK_ACTION_MOVE;
616 /// else
617 /// action = GDK_ACTION_COPY;
618 /// }
619 ///
620 /// gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
621 /// }
622 /// else
623 /// gtk_drag_finish (context, FALSE, FALSE, time);
624 /// }
625 /// ```
626 ///
627 ///
628 ///
629 ///
630 /// #### `drag-drop`
631 /// The ::drag-drop signal is emitted on the drop site when the user drops
632 /// the data onto the widget. The signal handler must determine whether
633 /// the cursor position is in a drop zone or not. If it is not in a drop
634 /// zone, it returns [`false`] and no further processing is necessary.
635 /// Otherwise, the handler returns [`true`]. In this case, the handler must
636 /// ensure that `gtk_drag_finish()` is called to let the source know that
637 /// the drop is done. The call to `gtk_drag_finish()` can be done either
638 /// directly or in a [`drag-data-received`][struct@crate::Widget#drag-data-received] handler which gets
639 /// triggered by calling [`WidgetExt::drag_get_data()`][crate::prelude::WidgetExt::drag_get_data()] to receive the data for one
640 /// or more of the supported targets.
641 ///
642 ///
643 ///
644 ///
645 /// #### `drag-end`
646 /// The ::drag-end signal is emitted on the drag source when a drag is
647 /// finished. A typical reason to connect to this signal is to undo
648 /// things done in [`drag-begin`][struct@crate::Widget#drag-begin].
649 ///
650 ///
651 ///
652 ///
653 /// #### `drag-failed`
654 /// The ::drag-failed signal is emitted on the drag source when a drag has
655 /// failed. The signal handler may hook custom code to handle a failed DnD
656 /// operation based on the type of error, it returns [`true`] is the failure has
657 /// been already handled (not showing the default "drag operation failed"
658 /// animation), otherwise it returns [`false`].
659 ///
660 ///
661 ///
662 ///
663 /// #### `drag-leave`
664 /// The ::drag-leave signal is emitted on the drop site when the cursor
665 /// leaves the widget. A typical reason to connect to this signal is to
666 /// undo things done in [`drag-motion`][struct@crate::Widget#drag-motion], e.g. undo highlighting
667 /// with [`WidgetExt::drag_unhighlight()`][crate::prelude::WidgetExt::drag_unhighlight()].
668 ///
669 ///
670 /// Likewise, the [`drag-leave`][struct@crate::Widget#drag-leave] signal is also emitted before the
671 /// ::drag-drop signal, for instance to allow cleaning up of a preview item
672 /// created in the [`drag-motion`][struct@crate::Widget#drag-motion] signal handler.
673 ///
674 ///
675 ///
676 ///
677 /// #### `drag-motion`
678 /// The ::drag-motion signal is emitted on the drop site when the user
679 /// moves the cursor over the widget during a drag. The signal handler
680 /// must determine whether the cursor position is in a drop zone or not.
681 /// If it is not in a drop zone, it returns [`false`] and no further processing
682 /// is necessary. Otherwise, the handler returns [`true`]. In this case, the
683 /// handler is responsible for providing the necessary information for
684 /// displaying feedback to the user, by calling `gdk_drag_status()`.
685 ///
686 /// If the decision whether the drop will be accepted or rejected can't be
687 /// made based solely on the cursor position and the type of the data, the
688 /// handler may inspect the dragged data by calling [`WidgetExt::drag_get_data()`][crate::prelude::WidgetExt::drag_get_data()] and
689 /// defer the `gdk_drag_status()` call to the [`drag-data-received`][struct@crate::Widget#drag-data-received]
690 /// handler. Note that you must pass [`DestDefaults::DROP`][crate::DestDefaults::DROP],
691 /// [`DestDefaults::MOTION`][crate::DestDefaults::MOTION] or [`DestDefaults::ALL`][crate::DestDefaults::ALL] to [`WidgetExtManual::drag_dest_set()`][crate::prelude::WidgetExtManual::drag_dest_set()]
692 /// when using the drag-motion signal that way.
693 ///
694 /// Also note that there is no drag-enter signal. The drag receiver has to
695 /// keep track of whether he has received any drag-motion signals since the
696 /// last [`drag-leave`][struct@crate::Widget#drag-leave] and if not, treat the drag-motion signal as
697 /// an "enter" signal. Upon an "enter", the handler will typically highlight
698 /// the drop site with [`WidgetExt::drag_highlight()`][crate::prelude::WidgetExt::drag_highlight()].
699 ///
700 ///
701 /// **⚠️ The following code is in C ⚠️**
702 ///
703 /// ```C
704 /// static void
705 /// drag_motion (GtkWidget *widget,
706 /// GdkDragContext *context,
707 /// gint x,
708 /// gint y,
709 /// guint time)
710 /// {
711 /// GdkAtom target;
712 ///
713 /// PrivateData *private_data = GET_PRIVATE_DATA (widget);
714 ///
715 /// if (!private_data->drag_highlight)
716 /// {
717 /// private_data->drag_highlight = 1;
718 /// gtk_drag_highlight (widget);
719 /// }
720 ///
721 /// target = gtk_drag_dest_find_target (widget, context, NULL);
722 /// if (target == GDK_NONE)
723 /// gdk_drag_status (context, 0, time);
724 /// else
725 /// {
726 /// private_data->pending_status
727 /// = gdk_drag_context_get_suggested_action (context);
728 /// gtk_drag_get_data (widget, context, target, time);
729 /// }
730 ///
731 /// return TRUE;
732 /// }
733 ///
734 /// static void
735 /// drag_data_received (GtkWidget *widget,
736 /// GdkDragContext *context,
737 /// gint x,
738 /// gint y,
739 /// GtkSelectionData *selection_data,
740 /// guint info,
741 /// guint time)
742 /// {
743 /// PrivateData *private_data = GET_PRIVATE_DATA (widget);
744 ///
745 /// if (private_data->suggested_action)
746 /// {
747 /// private_data->suggested_action = 0;
748 ///
749 /// // We are getting this data due to a request in drag_motion,
750 /// // rather than due to a request in drag_drop, so we are just
751 /// // supposed to call gdk_drag_status(), not actually paste in
752 /// // the data.
753 ///
754 /// str = gtk_selection_data_get_text (selection_data);
755 /// if (!data_is_acceptable (str))
756 /// gdk_drag_status (context, 0, time);
757 /// else
758 /// gdk_drag_status (context,
759 /// private_data->suggested_action,
760 /// time);
761 /// }
762 /// else
763 /// {
764 /// // accept the drop
765 /// }
766 /// }
767 /// ```
768 ///
769 ///
770 ///
771 ///
772 /// #### `draw`
773 /// This signal is emitted when a widget is supposed to render itself.
774 /// The `widget`'s top left corner must be painted at the origin of
775 /// the passed in context and be sized to the values returned by
776 /// [`WidgetExt::allocated_width()`][crate::prelude::WidgetExt::allocated_width()] and
777 /// [`WidgetExt::allocated_height()`][crate::prelude::WidgetExt::allocated_height()].
778 ///
779 /// Signal handlers connected to this signal can modify the cairo
780 /// context passed as `cr` in any way they like and don't need to
781 /// restore it. The signal emission takes care of calling `cairo_save()`
782 /// before and `cairo_restore()` after invoking the handler.
783 ///
784 /// The signal handler will get a `cr` with a clip region already set to the
785 /// widget's dirty region, i.e. to the area that needs repainting. Complicated
786 /// widgets that want to avoid redrawing themselves completely can get the full
787 /// extents of the clip region with `gdk_cairo_get_clip_rectangle()`, or they can
788 /// get a finer-grained representation of the dirty region with
789 /// `cairo_copy_clip_rectangle_list()`.
790 ///
791 ///
792 ///
793 ///
794 /// #### `enter-notify-event`
795 /// The ::enter-notify-event will be emitted when the pointer enters
796 /// the `widget`'s window.
797 ///
798 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
799 /// to enable the [`gdk::EventMask::ENTER_NOTIFY_MASK`][crate::gdk::EventMask::ENTER_NOTIFY_MASK] mask.
800 ///
801 /// This signal will be sent to the grab widget if there is one.
802 ///
803 ///
804 ///
805 ///
806 /// #### `event`
807 /// The GTK+ main loop will emit three signals for each GDK event delivered
808 /// to a widget: one generic ::event signal, another, more specific,
809 /// signal that matches the type of event delivered (e.g.
810 /// [`key-press-event`][struct@crate::Widget#key-press-event]) and finally a generic
811 /// [`event-after`][struct@crate::Widget#event-after] signal.
812 ///
813 ///
814 ///
815 ///
816 /// #### `event-after`
817 /// After the emission of the [`event`][struct@crate::Widget#event] signal and (optionally)
818 /// the second more specific signal, ::event-after will be emitted
819 /// regardless of the previous two signals handlers return values.
820 ///
821 ///
822 ///
823 ///
824 /// #### `focus`
825 ///
826 ///
827 ///
828 /// #### `focus-in-event`
829 /// The ::focus-in-event signal will be emitted when the keyboard focus
830 /// enters the `widget`'s window.
831 ///
832 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
833 /// to enable the [`gdk::EventMask::FOCUS_CHANGE_MASK`][crate::gdk::EventMask::FOCUS_CHANGE_MASK] mask.
834 ///
835 ///
836 ///
837 ///
838 /// #### `focus-out-event`
839 /// The ::focus-out-event signal will be emitted when the keyboard focus
840 /// leaves the `widget`'s window.
841 ///
842 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
843 /// to enable the [`gdk::EventMask::FOCUS_CHANGE_MASK`][crate::gdk::EventMask::FOCUS_CHANGE_MASK] mask.
844 ///
845 ///
846 ///
847 ///
848 /// #### `grab-broken-event`
849 /// Emitted when a pointer or keyboard grab on a window belonging
850 /// to `widget` gets broken.
851 ///
852 /// On X11, this happens when the grab window becomes unviewable
853 /// (i.e. it or one of its ancestors is unmapped), or if the same
854 /// application grabs the pointer or keyboard again.
855 ///
856 ///
857 ///
858 ///
859 /// #### `grab-focus`
860 /// Action
861 ///
862 ///
863 /// #### `grab-notify`
864 /// The ::grab-notify signal is emitted when a widget becomes
865 /// shadowed by a GTK+ grab (not a pointer or keyboard grab) on
866 /// another widget, or when it becomes unshadowed due to a grab
867 /// being removed.
868 ///
869 /// A widget is shadowed by a [`WidgetExt::grab_add()`][crate::prelude::WidgetExt::grab_add()] when the topmost
870 /// grab widget in the grab stack of its window group is not
871 /// its ancestor.
872 ///
873 ///
874 ///
875 ///
876 /// #### `hide`
877 /// The ::hide signal is emitted when `widget` is hidden, for example with
878 /// [`WidgetExt::hide()`][crate::prelude::WidgetExt::hide()].
879 ///
880 ///
881 ///
882 ///
883 /// #### `hierarchy-changed`
884 /// The ::hierarchy-changed signal is emitted when the
885 /// anchored state of a widget changes. A widget is
886 /// “anchored” when its toplevel
887 /// ancestor is a [`Window`][crate::Window]. This signal is emitted when
888 /// a widget changes from un-anchored to anchored or vice-versa.
889 ///
890 ///
891 ///
892 ///
893 /// #### `key-press-event`
894 /// The ::key-press-event signal is emitted when a key is pressed. The signal
895 /// emission will reoccur at the key-repeat rate when the key is kept pressed.
896 ///
897 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
898 /// to enable the [`gdk::EventMask::KEY_PRESS_MASK`][crate::gdk::EventMask::KEY_PRESS_MASK] mask.
899 ///
900 /// This signal will be sent to the grab widget if there is one.
901 ///
902 ///
903 ///
904 ///
905 /// #### `key-release-event`
906 /// The ::key-release-event signal is emitted when a key is released.
907 ///
908 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
909 /// to enable the [`gdk::EventMask::KEY_RELEASE_MASK`][crate::gdk::EventMask::KEY_RELEASE_MASK] mask.
910 ///
911 /// This signal will be sent to the grab widget if there is one.
912 ///
913 ///
914 ///
915 ///
916 /// #### `keynav-failed`
917 /// Gets emitted if keyboard navigation fails.
918 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
919 ///
920 ///
921 ///
922 ///
923 /// #### `leave-notify-event`
924 /// The ::leave-notify-event will be emitted when the pointer leaves
925 /// the `widget`'s window.
926 ///
927 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
928 /// to enable the [`gdk::EventMask::LEAVE_NOTIFY_MASK`][crate::gdk::EventMask::LEAVE_NOTIFY_MASK] mask.
929 ///
930 /// This signal will be sent to the grab widget if there is one.
931 ///
932 ///
933 ///
934 ///
935 /// #### `map`
936 /// The ::map signal is emitted when `widget` is going to be mapped, that is
937 /// when the widget is visible (which is controlled with
938 /// [`WidgetExt::set_visible()`][crate::prelude::WidgetExt::set_visible()]) and all its parents up to the toplevel widget
939 /// are also visible. Once the map has occurred, [`map-event`][struct@crate::Widget#map-event] will
940 /// be emitted.
941 ///
942 /// The ::map signal can be used to determine whether a widget will be drawn,
943 /// for instance it can resume an animation that was stopped during the
944 /// emission of [`unmap`][struct@crate::Widget#unmap].
945 ///
946 ///
947 ///
948 ///
949 /// #### `map-event`
950 /// The ::map-event signal will be emitted when the `widget`'s window is
951 /// mapped. A window is mapped when it becomes visible on the screen.
952 ///
953 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
954 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
955 /// automatically for all new windows.
956 ///
957 ///
958 ///
959 ///
960 /// #### `mnemonic-activate`
961 /// The default handler for this signal activates `widget` if `group_cycling`
962 /// is [`false`], or just makes `widget` grab focus if `group_cycling` is [`true`].
963 ///
964 ///
965 ///
966 ///
967 /// #### `motion-notify-event`
968 /// The ::motion-notify-event signal is emitted when the pointer moves
969 /// over the widget's [`gdk::Window`][crate::gdk::Window].
970 ///
971 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget
972 /// needs to enable the [`gdk::EventMask::POINTER_MOTION_MASK`][crate::gdk::EventMask::POINTER_MOTION_MASK] mask.
973 ///
974 /// This signal will be sent to the grab widget if there is one.
975 ///
976 ///
977 ///
978 ///
979 /// #### `move-focus`
980 /// Action
981 ///
982 ///
983 /// #### `parent-set`
984 /// The ::parent-set signal is emitted when a new parent
985 /// has been set on a widget.
986 ///
987 ///
988 ///
989 ///
990 /// #### `popup-menu`
991 /// This signal gets emitted whenever a widget should pop up a context
992 /// menu. This usually happens through the standard key binding mechanism;
993 /// by pressing a certain key while a widget is focused, the user can cause
994 /// the widget to pop up a menu. For example, the [`Entry`][crate::Entry] widget creates
995 /// a menu with clipboard commands. See the
996 /// [Popup Menu Migration Checklist][checklist-popup-menu]
997 /// for an example of how to use this signal.
998 ///
999 /// Action
1000 ///
1001 ///
1002 /// #### `property-notify-event`
1003 /// The ::property-notify-event signal will be emitted when a property on
1004 /// the `widget`'s window has been changed or deleted.
1005 ///
1006 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1007 /// to enable the [`gdk::EventMask::PROPERTY_CHANGE_MASK`][crate::gdk::EventMask::PROPERTY_CHANGE_MASK] mask.
1008 ///
1009 ///
1010 ///
1011 ///
1012 /// #### `proximity-in-event`
1013 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1014 /// to enable the [`gdk::EventMask::PROXIMITY_IN_MASK`][crate::gdk::EventMask::PROXIMITY_IN_MASK] mask.
1015 ///
1016 /// This signal will be sent to the grab widget if there is one.
1017 ///
1018 ///
1019 ///
1020 ///
1021 /// #### `proximity-out-event`
1022 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1023 /// to enable the [`gdk::EventMask::PROXIMITY_OUT_MASK`][crate::gdk::EventMask::PROXIMITY_OUT_MASK] mask.
1024 ///
1025 /// This signal will be sent to the grab widget if there is one.
1026 ///
1027 ///
1028 ///
1029 ///
1030 /// #### `query-tooltip`
1031 /// Emitted when [`has-tooltip`][struct@crate::Widget#has-tooltip] is [`true`] and the hover timeout
1032 /// has expired with the cursor hovering "above" `widget`; or emitted when `widget` got
1033 /// focus in keyboard mode.
1034 ///
1035 /// Using the given coordinates, the signal handler should determine
1036 /// whether a tooltip should be shown for `widget`. If this is the case
1037 /// [`true`] should be returned, [`false`] otherwise. Note that if
1038 /// `keyboard_mode` is [`true`], the values of `x` and `y` are undefined and
1039 /// should not be used.
1040 ///
1041 /// The signal handler is free to manipulate `tooltip` with the therefore
1042 /// destined function calls.
1043 ///
1044 ///
1045 ///
1046 ///
1047 /// #### `realize`
1048 /// The ::realize signal is emitted when `widget` is associated with a
1049 /// [`gdk::Window`][crate::gdk::Window], which means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called or the
1050 /// widget has been mapped (that is, it is going to be drawn).
1051 ///
1052 ///
1053 ///
1054 ///
1055 /// #### `screen-changed`
1056 /// The ::screen-changed signal gets emitted when the
1057 /// screen of a widget has changed.
1058 ///
1059 ///
1060 ///
1061 ///
1062 /// #### `scroll-event`
1063 /// The ::scroll-event signal is emitted when a button in the 4 to 7
1064 /// range is pressed. Wheel mice are usually configured to generate
1065 /// button press events for buttons 4 and 5 when the wheel is turned.
1066 ///
1067 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1068 /// to enable the [`gdk::EventMask::SCROLL_MASK`][crate::gdk::EventMask::SCROLL_MASK] mask.
1069 ///
1070 /// This signal will be sent to the grab widget if there is one.
1071 ///
1072 ///
1073 ///
1074 ///
1075 /// #### `selection-clear-event`
1076 /// The ::selection-clear-event signal will be emitted when the
1077 /// the `widget`'s window has lost ownership of a selection.
1078 ///
1079 ///
1080 ///
1081 ///
1082 /// #### `selection-get`
1083 ///
1084 ///
1085 ///
1086 /// #### `selection-notify-event`
1087 ///
1088 ///
1089 ///
1090 /// #### `selection-received`
1091 ///
1092 ///
1093 ///
1094 /// #### `selection-request-event`
1095 /// The ::selection-request-event signal will be emitted when
1096 /// another client requests ownership of the selection owned by
1097 /// the `widget`'s window.
1098 ///
1099 ///
1100 ///
1101 ///
1102 /// #### `show`
1103 /// The ::show signal is emitted when `widget` is shown, for example with
1104 /// [`WidgetExt::show()`][crate::prelude::WidgetExt::show()].
1105 ///
1106 ///
1107 ///
1108 ///
1109 /// #### `show-help`
1110 /// Action
1111 ///
1112 ///
1113 /// #### `size-allocate`
1114 ///
1115 ///
1116 ///
1117 /// #### `state-changed`
1118 /// The ::state-changed signal is emitted when the widget state changes.
1119 /// See `gtk_widget_get_state()`.
1120 ///
1121 ///
1122 ///
1123 ///
1124 /// #### `state-flags-changed`
1125 /// The ::state-flags-changed signal is emitted when the widget state
1126 /// changes, see [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
1127 ///
1128 ///
1129 ///
1130 ///
1131 /// #### `style-set`
1132 /// The ::style-set signal is emitted when a new style has been set
1133 /// on a widget. Note that style-modifying functions like
1134 /// `gtk_widget_modify_base()` also cause this signal to be emitted.
1135 ///
1136 /// Note that this signal is emitted for changes to the deprecated
1137 /// `GtkStyle`. To track changes to the [`StyleContext`][crate::StyleContext] associated
1138 /// with a widget, use the [`style-updated`][struct@crate::Widget#style-updated] signal.
1139 ///
1140 ///
1141 ///
1142 ///
1143 /// #### `style-updated`
1144 /// The ::style-updated signal is a convenience signal that is emitted when the
1145 /// [`changed`][struct@crate::StyleContext#changed] signal is emitted on the `widget`'s associated
1146 /// [`StyleContext`][crate::StyleContext] as returned by [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()].
1147 ///
1148 /// Note that style-modifying functions like `gtk_widget_override_color()` also
1149 /// cause this signal to be emitted.
1150 ///
1151 ///
1152 ///
1153 ///
1154 /// #### `touch-event`
1155 ///
1156 ///
1157 ///
1158 /// #### `unmap`
1159 /// The ::unmap signal is emitted when `widget` is going to be unmapped, which
1160 /// means that either it or any of its parents up to the toplevel widget have
1161 /// been set as hidden.
1162 ///
1163 /// As ::unmap indicates that a widget will not be shown any longer, it can be
1164 /// used to, for example, stop an animation on the widget.
1165 ///
1166 ///
1167 ///
1168 ///
1169 /// #### `unmap-event`
1170 /// The ::unmap-event signal will be emitted when the `widget`'s window is
1171 /// unmapped. A window is unmapped when it becomes invisible on the screen.
1172 ///
1173 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1174 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
1175 /// automatically for all new windows.
1176 ///
1177 ///
1178 ///
1179 ///
1180 /// #### `unrealize`
1181 /// The ::unrealize signal is emitted when the [`gdk::Window`][crate::gdk::Window] associated with
1182 /// `widget` is destroyed, which means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been
1183 /// called or the widget has been unmapped (that is, it is going to be
1184 /// hidden).
1185 ///
1186 ///
1187 ///
1188 ///
1189 /// #### `visibility-notify-event`
1190 /// The ::visibility-notify-event will be emitted when the `widget`'s
1191 /// window is obscured or unobscured.
1192 ///
1193 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1194 /// to enable the [`gdk::EventMask::VISIBILITY_NOTIFY_MASK`][crate::gdk::EventMask::VISIBILITY_NOTIFY_MASK] mask.
1195 ///
1196 ///
1197 ///
1198 ///
1199 /// #### `window-state-event`
1200 /// The ::window-state-event will be emitted when the state of the
1201 /// toplevel window associated to the `widget` changes.
1202 ///
1203 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget
1204 /// needs to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable
1205 /// this mask automatically for all new windows.
1206 ///
1207 ///
1208 /// </details>
1209 ///
1210 /// # Implements
1211 ///
1212 /// [`MenuShellExt`][trait@crate::prelude::MenuShellExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
1213 #[doc(alias = "GtkMenuShell")]
1214 pub struct MenuShell(Object<ffi::GtkMenuShell, ffi::GtkMenuShellClass>) @extends Container, Widget, @implements Buildable;
1215
1216 match fn {
1217 type_ => || ffi::gtk_menu_shell_get_type(),
1218 }
1219}
1220
1221impl MenuShell {
1222 pub const NONE: Option<&'static MenuShell> = None;
1223}
1224
1225mod sealed {
1226 pub trait Sealed {}
1227 impl<T: super::IsA<super::MenuShell>> Sealed for T {}
1228}
1229
1230/// Trait containing all [`struct@MenuShell`] methods.
1231///
1232/// # Implementors
1233///
1234/// [`MenuBar`][struct@crate::MenuBar], [`MenuShell`][struct@crate::MenuShell], [`Menu`][struct@crate::Menu]
1235pub trait MenuShellExt: IsA<MenuShell> + sealed::Sealed + 'static {
1236 /// Activates the menu item within the menu shell.
1237 /// ## `menu_item`
1238 /// the [`MenuItem`][crate::MenuItem] to activate
1239 /// ## `force_deactivate`
1240 /// if [`true`], force the deactivation of the
1241 /// menu shell after the menu item is activated
1242 #[doc(alias = "gtk_menu_shell_activate_item")]
1243 fn activate_item(&self, menu_item: &impl IsA<Widget>, force_deactivate: bool) {
1244 unsafe {
1245 ffi::gtk_menu_shell_activate_item(
1246 self.as_ref().to_glib_none().0,
1247 menu_item.as_ref().to_glib_none().0,
1248 force_deactivate.into_glib(),
1249 );
1250 }
1251 }
1252
1253 /// Adds a new [`MenuItem`][crate::MenuItem] to the end of the menu shell's
1254 /// item list.
1255 /// ## `child`
1256 /// The [`MenuItem`][crate::MenuItem] to add
1257 #[doc(alias = "gtk_menu_shell_append")]
1258 fn append(&self, child: &impl IsA<MenuItem>) {
1259 unsafe {
1260 ffi::gtk_menu_shell_append(
1261 self.as_ref().to_glib_none().0,
1262 child.as_ref().to_glib_none().0,
1263 );
1264 }
1265 }
1266
1267 /// Establishes a binding between a [`MenuShell`][crate::MenuShell] and a [`gio::MenuModel`][crate::gio::MenuModel].
1268 ///
1269 /// The contents of `shell` are removed and then refilled with menu items
1270 /// according to `model`. When `model` changes, `shell` is updated.
1271 /// Calling this function twice on `shell` with different `model` will
1272 /// cause the first binding to be replaced with a binding to the new
1273 /// model. If `model` is [`None`] then any previous binding is undone and
1274 /// all children are removed.
1275 ///
1276 /// `with_separators` determines if toplevel items (eg: sections) have
1277 /// separators inserted between them. This is typically desired for
1278 /// menus but doesn’t make sense for menubars.
1279 ///
1280 /// If `action_namespace` is non-[`None`] then the effect is as if all
1281 /// actions mentioned in the `model` have their names prefixed with the
1282 /// namespace, plus a dot. For example, if the action “quit” is
1283 /// mentioned and `action_namespace` is “app” then the effective action
1284 /// name is “app.quit”.
1285 ///
1286 /// This function uses [`Actionable`][crate::Actionable] to define the action name and
1287 /// target values on the created menu items. If you want to use an
1288 /// action group other than “app” and “win”, or if you want to use a
1289 /// [`MenuShell`][crate::MenuShell] outside of a [`ApplicationWindow`][crate::ApplicationWindow], then you will need
1290 /// to attach your own action group to the widget hierarchy using
1291 /// [`WidgetExt::insert_action_group()`][crate::prelude::WidgetExt::insert_action_group()]. As an example, if you created a
1292 /// group with a “quit” action and inserted it with the name “mygroup”
1293 /// then you would use the action name “mygroup.quit” in your
1294 /// [`gio::MenuModel`][crate::gio::MenuModel].
1295 ///
1296 /// For most cases you are probably better off using
1297 /// [`Menu::from_model()`][crate::Menu::from_model()] or [`MenuBar::from_model()`][crate::MenuBar::from_model()] or just
1298 /// directly passing the [`gio::MenuModel`][crate::gio::MenuModel] to [`GtkApplicationExt::set_app_menu()`][crate::prelude::GtkApplicationExt::set_app_menu()] or
1299 /// [`GtkApplicationExt::set_menubar()`][crate::prelude::GtkApplicationExt::set_menubar()].
1300 /// ## `model`
1301 /// the [`gio::MenuModel`][crate::gio::MenuModel] to bind to or [`None`] to remove
1302 /// binding
1303 /// ## `action_namespace`
1304 /// the namespace for actions in `model`
1305 /// ## `with_separators`
1306 /// [`true`] if toplevel items in `shell` should have
1307 /// separators between them
1308 #[doc(alias = "gtk_menu_shell_bind_model")]
1309 fn bind_model(
1310 &self,
1311 model: Option<&impl IsA<gio::MenuModel>>,
1312 action_namespace: Option<&str>,
1313 with_separators: bool,
1314 ) {
1315 unsafe {
1316 ffi::gtk_menu_shell_bind_model(
1317 self.as_ref().to_glib_none().0,
1318 model.map(|p| p.as_ref()).to_glib_none().0,
1319 action_namespace.to_glib_none().0,
1320 with_separators.into_glib(),
1321 );
1322 }
1323 }
1324
1325 /// Cancels the selection within the menu shell.
1326 #[doc(alias = "gtk_menu_shell_cancel")]
1327 fn cancel(&self) {
1328 unsafe {
1329 ffi::gtk_menu_shell_cancel(self.as_ref().to_glib_none().0);
1330 }
1331 }
1332
1333 /// Deactivates the menu shell.
1334 ///
1335 /// Typically this results in the menu shell being erased
1336 /// from the screen.
1337 #[doc(alias = "gtk_menu_shell_deactivate")]
1338 fn deactivate(&self) {
1339 unsafe {
1340 ffi::gtk_menu_shell_deactivate(self.as_ref().to_glib_none().0);
1341 }
1342 }
1343
1344 /// Deselects the currently selected item from the menu shell,
1345 /// if any.
1346 #[doc(alias = "gtk_menu_shell_deselect")]
1347 fn deselect(&self) {
1348 unsafe {
1349 ffi::gtk_menu_shell_deselect(self.as_ref().to_glib_none().0);
1350 }
1351 }
1352
1353 /// Gets the parent menu shell.
1354 ///
1355 /// The parent menu shell of a submenu is the [`Menu`][crate::Menu] or [`MenuBar`][crate::MenuBar]
1356 /// from which it was opened up.
1357 ///
1358 /// # Returns
1359 ///
1360 /// the parent [`MenuShell`][crate::MenuShell]
1361 #[doc(alias = "gtk_menu_shell_get_parent_shell")]
1362 #[doc(alias = "get_parent_shell")]
1363 fn parent_shell(&self) -> Option<Widget> {
1364 unsafe {
1365 from_glib_none(ffi::gtk_menu_shell_get_parent_shell(
1366 self.as_ref().to_glib_none().0,
1367 ))
1368 }
1369 }
1370
1371 /// Gets the currently selected item.
1372 ///
1373 /// # Returns
1374 ///
1375 /// the currently selected item
1376 #[doc(alias = "gtk_menu_shell_get_selected_item")]
1377 #[doc(alias = "get_selected_item")]
1378 fn selected_item(&self) -> Option<Widget> {
1379 unsafe {
1380 from_glib_none(ffi::gtk_menu_shell_get_selected_item(
1381 self.as_ref().to_glib_none().0,
1382 ))
1383 }
1384 }
1385
1386 /// Returns [`true`] if the menu shell will take the keyboard focus on popup.
1387 ///
1388 /// # Returns
1389 ///
1390 /// [`true`] if the menu shell will take the keyboard focus on popup.
1391 #[doc(alias = "gtk_menu_shell_get_take_focus")]
1392 #[doc(alias = "get_take_focus")]
1393 fn takes_focus(&self) -> bool {
1394 unsafe {
1395 from_glib(ffi::gtk_menu_shell_get_take_focus(
1396 self.as_ref().to_glib_none().0,
1397 ))
1398 }
1399 }
1400
1401 /// Adds a new [`MenuItem`][crate::MenuItem] to the menu shell’s item list
1402 /// at the position indicated by `position`.
1403 /// ## `child`
1404 /// The [`MenuItem`][crate::MenuItem] to add
1405 /// ## `position`
1406 /// The position in the item list where `child`
1407 /// is added. Positions are numbered from 0 to n-1
1408 #[doc(alias = "gtk_menu_shell_insert")]
1409 fn insert(&self, child: &impl IsA<Widget>, position: i32) {
1410 unsafe {
1411 ffi::gtk_menu_shell_insert(
1412 self.as_ref().to_glib_none().0,
1413 child.as_ref().to_glib_none().0,
1414 position,
1415 );
1416 }
1417 }
1418
1419 /// Adds a new [`MenuItem`][crate::MenuItem] to the beginning of the menu shell's
1420 /// item list.
1421 /// ## `child`
1422 /// The [`MenuItem`][crate::MenuItem] to add
1423 #[doc(alias = "gtk_menu_shell_prepend")]
1424 fn prepend(&self, child: &impl IsA<Widget>) {
1425 unsafe {
1426 ffi::gtk_menu_shell_prepend(
1427 self.as_ref().to_glib_none().0,
1428 child.as_ref().to_glib_none().0,
1429 );
1430 }
1431 }
1432
1433 /// Select the first visible or selectable child of the menu shell;
1434 /// don’t select tearoff items unless the only item is a tearoff
1435 /// item.
1436 /// ## `search_sensitive`
1437 /// if [`true`], search for the first selectable
1438 /// menu item, otherwise select nothing if
1439 /// the first item isn’t sensitive. This
1440 /// should be [`false`] if the menu is being
1441 /// popped up initially.
1442 #[doc(alias = "gtk_menu_shell_select_first")]
1443 fn select_first(&self, search_sensitive: bool) {
1444 unsafe {
1445 ffi::gtk_menu_shell_select_first(
1446 self.as_ref().to_glib_none().0,
1447 search_sensitive.into_glib(),
1448 );
1449 }
1450 }
1451
1452 /// Selects the menu item from the menu shell.
1453 /// ## `menu_item`
1454 /// The [`MenuItem`][crate::MenuItem] to select
1455 #[doc(alias = "gtk_menu_shell_select_item")]
1456 fn select_item(&self, menu_item: &impl IsA<Widget>) {
1457 unsafe {
1458 ffi::gtk_menu_shell_select_item(
1459 self.as_ref().to_glib_none().0,
1460 menu_item.as_ref().to_glib_none().0,
1461 );
1462 }
1463 }
1464
1465 /// If `take_focus` is [`true`] (the default) the menu shell will take
1466 /// the keyboard focus so that it will receive all keyboard events
1467 /// which is needed to enable keyboard navigation in menus.
1468 ///
1469 /// Setting `take_focus` to [`false`] is useful only for special applications
1470 /// like virtual keyboard implementations which should not take keyboard
1471 /// focus.
1472 ///
1473 /// The `take_focus` state of a menu or menu bar is automatically
1474 /// propagated to submenus whenever a submenu is popped up, so you
1475 /// don’t have to worry about recursively setting it for your entire
1476 /// menu hierarchy. Only when programmatically picking a submenu and
1477 /// popping it up manually, the `take_focus` property of the submenu
1478 /// needs to be set explicitly.
1479 ///
1480 /// Note that setting it to [`false`] has side-effects:
1481 ///
1482 /// If the focus is in some other app, it keeps the focus and keynav in
1483 /// the menu doesn’t work. Consequently, keynav on the menu will only
1484 /// work if the focus is on some toplevel owned by the onscreen keyboard.
1485 ///
1486 /// To avoid confusing the user, menus with `take_focus` set to [`false`]
1487 /// should not display mnemonics or accelerators, since it cannot be
1488 /// guaranteed that they will work.
1489 ///
1490 /// See also `gdk_keyboard_grab()`
1491 /// ## `take_focus`
1492 /// [`true`] if the menu shell should take the keyboard
1493 /// focus on popup
1494 #[doc(alias = "gtk_menu_shell_set_take_focus")]
1495 fn set_take_focus(&self, take_focus: bool) {
1496 unsafe {
1497 ffi::gtk_menu_shell_set_take_focus(
1498 self.as_ref().to_glib_none().0,
1499 take_focus.into_glib(),
1500 );
1501 }
1502 }
1503
1504 /// An action signal that activates the current menu item within
1505 /// the menu shell.
1506 /// ## `force_hide`
1507 /// if [`true`], hide the menu after activating the menu item
1508 #[doc(alias = "activate-current")]
1509 fn connect_activate_current<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId {
1510 unsafe extern "C" fn activate_current_trampoline<
1511 P: IsA<MenuShell>,
1512 F: Fn(&P, bool) + 'static,
1513 >(
1514 this: *mut ffi::GtkMenuShell,
1515 force_hide: glib::ffi::gboolean,
1516 f: glib::ffi::gpointer,
1517 ) {
1518 let f: &F = &*(f as *const F);
1519 f(
1520 MenuShell::from_glib_borrow(this).unsafe_cast_ref(),
1521 from_glib(force_hide),
1522 )
1523 }
1524 unsafe {
1525 let f: Box_<F> = Box_::new(f);
1526 connect_raw(
1527 self.as_ptr() as *mut _,
1528 b"activate-current\0".as_ptr() as *const _,
1529 Some(transmute::<_, unsafe extern "C" fn()>(
1530 activate_current_trampoline::<Self, F> as *const (),
1531 )),
1532 Box_::into_raw(f),
1533 )
1534 }
1535 }
1536
1537 fn emit_activate_current(&self, force_hide: bool) {
1538 self.emit_by_name::<()>("activate-current", &[&force_hide]);
1539 }
1540
1541 /// An action signal which cancels the selection within the menu shell.
1542 /// Causes the [`selection-done`][struct@crate::MenuShell#selection-done] signal to be emitted.
1543 #[doc(alias = "cancel")]
1544 fn connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1545 unsafe extern "C" fn cancel_trampoline<P: IsA<MenuShell>, F: Fn(&P) + 'static>(
1546 this: *mut ffi::GtkMenuShell,
1547 f: glib::ffi::gpointer,
1548 ) {
1549 let f: &F = &*(f as *const F);
1550 f(MenuShell::from_glib_borrow(this).unsafe_cast_ref())
1551 }
1552 unsafe {
1553 let f: Box_<F> = Box_::new(f);
1554 connect_raw(
1555 self.as_ptr() as *mut _,
1556 b"cancel\0".as_ptr() as *const _,
1557 Some(transmute::<_, unsafe extern "C" fn()>(
1558 cancel_trampoline::<Self, F> as *const (),
1559 )),
1560 Box_::into_raw(f),
1561 )
1562 }
1563 }
1564
1565 fn emit_cancel(&self) {
1566 self.emit_by_name::<()>("cancel", &[]);
1567 }
1568
1569 /// A keybinding signal which moves the focus in the
1570 /// given `direction`.
1571 /// ## `direction`
1572 /// the direction to cycle in
1573 #[doc(alias = "cycle-focus")]
1574 fn connect_cycle_focus<F: Fn(&Self, DirectionType) + 'static>(&self, f: F) -> SignalHandlerId {
1575 unsafe extern "C" fn cycle_focus_trampoline<
1576 P: IsA<MenuShell>,
1577 F: Fn(&P, DirectionType) + 'static,
1578 >(
1579 this: *mut ffi::GtkMenuShell,
1580 direction: ffi::GtkDirectionType,
1581 f: glib::ffi::gpointer,
1582 ) {
1583 let f: &F = &*(f as *const F);
1584 f(
1585 MenuShell::from_glib_borrow(this).unsafe_cast_ref(),
1586 from_glib(direction),
1587 )
1588 }
1589 unsafe {
1590 let f: Box_<F> = Box_::new(f);
1591 connect_raw(
1592 self.as_ptr() as *mut _,
1593 b"cycle-focus\0".as_ptr() as *const _,
1594 Some(transmute::<_, unsafe extern "C" fn()>(
1595 cycle_focus_trampoline::<Self, F> as *const (),
1596 )),
1597 Box_::into_raw(f),
1598 )
1599 }
1600 }
1601
1602 fn emit_cycle_focus(&self, direction: DirectionType) {
1603 self.emit_by_name::<()>("cycle-focus", &[&direction]);
1604 }
1605
1606 /// This signal is emitted when a menu shell is deactivated.
1607 #[doc(alias = "deactivate")]
1608 fn connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1609 unsafe extern "C" fn deactivate_trampoline<P: IsA<MenuShell>, F: Fn(&P) + 'static>(
1610 this: *mut ffi::GtkMenuShell,
1611 f: glib::ffi::gpointer,
1612 ) {
1613 let f: &F = &*(f as *const F);
1614 f(MenuShell::from_glib_borrow(this).unsafe_cast_ref())
1615 }
1616 unsafe {
1617 let f: Box_<F> = Box_::new(f);
1618 connect_raw(
1619 self.as_ptr() as *mut _,
1620 b"deactivate\0".as_ptr() as *const _,
1621 Some(transmute::<_, unsafe extern "C" fn()>(
1622 deactivate_trampoline::<Self, F> as *const (),
1623 )),
1624 Box_::into_raw(f),
1625 )
1626 }
1627 }
1628
1629 /// The ::insert signal is emitted when a new [`MenuItem`][crate::MenuItem] is added to
1630 /// a [`MenuShell`][crate::MenuShell]. A separate signal is used instead of
1631 /// GtkContainer::add because of the need for an additional position
1632 /// parameter.
1633 ///
1634 /// The inverse of this signal is the GtkContainer::removed signal.
1635 /// ## `child`
1636 /// the [`MenuItem`][crate::MenuItem] that is being inserted
1637 /// ## `position`
1638 /// the position at which the insert occurs
1639 #[doc(alias = "insert")]
1640 fn connect_insert<F: Fn(&Self, &Widget, i32) + 'static>(&self, f: F) -> SignalHandlerId {
1641 unsafe extern "C" fn insert_trampoline<
1642 P: IsA<MenuShell>,
1643 F: Fn(&P, &Widget, i32) + 'static,
1644 >(
1645 this: *mut ffi::GtkMenuShell,
1646 child: *mut ffi::GtkWidget,
1647 position: libc::c_int,
1648 f: glib::ffi::gpointer,
1649 ) {
1650 let f: &F = &*(f as *const F);
1651 f(
1652 MenuShell::from_glib_borrow(this).unsafe_cast_ref(),
1653 &from_glib_borrow(child),
1654 position,
1655 )
1656 }
1657 unsafe {
1658 let f: Box_<F> = Box_::new(f);
1659 connect_raw(
1660 self.as_ptr() as *mut _,
1661 b"insert\0".as_ptr() as *const _,
1662 Some(transmute::<_, unsafe extern "C" fn()>(
1663 insert_trampoline::<Self, F> as *const (),
1664 )),
1665 Box_::into_raw(f),
1666 )
1667 }
1668 }
1669
1670 /// An keybinding signal which moves the current menu item
1671 /// in the direction specified by `direction`.
1672 /// ## `direction`
1673 /// the direction to move
1674 #[doc(alias = "move-current")]
1675 fn connect_move_current<F: Fn(&Self, MenuDirectionType) + 'static>(
1676 &self,
1677 f: F,
1678 ) -> SignalHandlerId {
1679 unsafe extern "C" fn move_current_trampoline<
1680 P: IsA<MenuShell>,
1681 F: Fn(&P, MenuDirectionType) + 'static,
1682 >(
1683 this: *mut ffi::GtkMenuShell,
1684 direction: ffi::GtkMenuDirectionType,
1685 f: glib::ffi::gpointer,
1686 ) {
1687 let f: &F = &*(f as *const F);
1688 f(
1689 MenuShell::from_glib_borrow(this).unsafe_cast_ref(),
1690 from_glib(direction),
1691 )
1692 }
1693 unsafe {
1694 let f: Box_<F> = Box_::new(f);
1695 connect_raw(
1696 self.as_ptr() as *mut _,
1697 b"move-current\0".as_ptr() as *const _,
1698 Some(transmute::<_, unsafe extern "C" fn()>(
1699 move_current_trampoline::<Self, F> as *const (),
1700 )),
1701 Box_::into_raw(f),
1702 )
1703 }
1704 }
1705
1706 fn emit_move_current(&self, direction: MenuDirectionType) {
1707 self.emit_by_name::<()>("move-current", &[&direction]);
1708 }
1709
1710 /// The ::move-selected signal is emitted to move the selection to
1711 /// another item.
1712 /// ## `distance`
1713 /// +1 to move to the next item, -1 to move to the previous
1714 ///
1715 /// # Returns
1716 ///
1717 /// [`true`] to stop the signal emission, [`false`] to continue
1718 #[doc(alias = "move-selected")]
1719 fn connect_move_selected<F: Fn(&Self, i32) -> glib::Propagation + 'static>(
1720 &self,
1721 f: F,
1722 ) -> SignalHandlerId {
1723 unsafe extern "C" fn move_selected_trampoline<
1724 P: IsA<MenuShell>,
1725 F: Fn(&P, i32) -> glib::Propagation + 'static,
1726 >(
1727 this: *mut ffi::GtkMenuShell,
1728 distance: libc::c_int,
1729 f: glib::ffi::gpointer,
1730 ) -> glib::ffi::gboolean {
1731 let f: &F = &*(f as *const F);
1732 f(
1733 MenuShell::from_glib_borrow(this).unsafe_cast_ref(),
1734 distance,
1735 )
1736 .into_glib()
1737 }
1738 unsafe {
1739 let f: Box_<F> = Box_::new(f);
1740 connect_raw(
1741 self.as_ptr() as *mut _,
1742 b"move-selected\0".as_ptr() as *const _,
1743 Some(transmute::<_, unsafe extern "C" fn()>(
1744 move_selected_trampoline::<Self, F> as *const (),
1745 )),
1746 Box_::into_raw(f),
1747 )
1748 }
1749 }
1750
1751 /// This signal is emitted when a selection has been
1752 /// completed within a menu shell.
1753 #[doc(alias = "selection-done")]
1754 fn connect_selection_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1755 unsafe extern "C" fn selection_done_trampoline<P: IsA<MenuShell>, F: Fn(&P) + 'static>(
1756 this: *mut ffi::GtkMenuShell,
1757 f: glib::ffi::gpointer,
1758 ) {
1759 let f: &F = &*(f as *const F);
1760 f(MenuShell::from_glib_borrow(this).unsafe_cast_ref())
1761 }
1762 unsafe {
1763 let f: Box_<F> = Box_::new(f);
1764 connect_raw(
1765 self.as_ptr() as *mut _,
1766 b"selection-done\0".as_ptr() as *const _,
1767 Some(transmute::<_, unsafe extern "C" fn()>(
1768 selection_done_trampoline::<Self, F> as *const (),
1769 )),
1770 Box_::into_raw(f),
1771 )
1772 }
1773 }
1774
1775 #[doc(alias = "take-focus")]
1776 fn connect_take_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1777 unsafe extern "C" fn notify_take_focus_trampoline<
1778 P: IsA<MenuShell>,
1779 F: Fn(&P) + 'static,
1780 >(
1781 this: *mut ffi::GtkMenuShell,
1782 _param_spec: glib::ffi::gpointer,
1783 f: glib::ffi::gpointer,
1784 ) {
1785 let f: &F = &*(f as *const F);
1786 f(MenuShell::from_glib_borrow(this).unsafe_cast_ref())
1787 }
1788 unsafe {
1789 let f: Box_<F> = Box_::new(f);
1790 connect_raw(
1791 self.as_ptr() as *mut _,
1792 b"notify::take-focus\0".as_ptr() as *const _,
1793 Some(transmute::<_, unsafe extern "C" fn()>(
1794 notify_take_focus_trampoline::<Self, F> as *const (),
1795 )),
1796 Box_::into_raw(f),
1797 )
1798 }
1799 }
1800}
1801
1802impl<O: IsA<MenuShell>> MenuShellExt for O {}
1803
1804impl fmt::Display for MenuShell {
1805 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1806 f.write_str("MenuShell")
1807 }
1808}