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