1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Helpers to connect signals to events that popup a menu in both GTK3 and GTK4.
4 * Plus miscellaneous helpers primarily useful with widgets used as popop menus.
8 * Daniel Boles <dboles.src+inkscape@gmail.com>
10 * Copyright (C) 2023 Daniel Boles
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 #ifndef SEEN_UI_POPUP_MENU_H
16 #define SEEN_UI_POPUP_MENU_H
20 #include <sigc++/connection.h>
21 #include <sigc++/slot.h>
36 namespace Inkscape::UI
{
38 /// Information from a GestureClick if a popup menu was opened by click
39 struct PopupMenuClick
{ int n_press
{}; double x
{}, y
{}; };
40 /// Optional: not present if popup wasnʼt triggered by click.
41 using PopupMenuOptionalClick
= std::optional
<PopupMenuClick
>;
43 /// Return whether a popup was activated.
44 /// Click param is nullopt if popup wasnʼt triggered by a click.
45 using PopupMenuSlot
= sigc::slot
<bool (PopupMenuOptionalClick
)>;
47 /// Connect slot to a widgetʼs key and button events that traditionally trigger a popup menu, i.e.:
48 /// * The keys used by GTK3ʼs signal Widget::popup-menu: the Menu key, or the Shift+F10 combination
49 /// * The right mouse button or other platform convention, as per gtk_event_triggers_context_menu()
50 void on_popup_menu(Gtk::Widget
&widget
, PopupMenuSlot slot
);
52 /// Replace Gtk::Menu::popup_at_pointer. If x or y
53 /// offsets != 0, :pointing-to is set to {x,y,1,1}
54 /// else it is set to the full allocation of @a widget, translated into the coordinate space of the
55 /// @a popoverʼs parent (:relative-to) widget. Hence, the @a widget must be the @a popoverʼs parent
56 /// (:relative-to) widget or a descendant thereof.
57 void popup_at(Gtk::Popover
&popover
, Gtk::Widget
&widget
,
58 double x_offset
= 0.0, double y_offset
= 0.0);
59 /// @copydoc popup_at()
60 void popup_at(Gtk::Popover
&popover
, Gtk::Widget
&widget
,
61 std::optional
<Geom::Point
> const &offset
);
63 /// As popup_at() but point to center of widget
64 void popup_at_center(Gtk::Popover
&popover
, Gtk::Widget
&widget
);
66 /// As popup_at() but point to center of @a rect
67 /// @a rect must be valid within the coords of @widget, & @awidget must be a descendant of @parent.
68 void popup_at(Gtk::Popover
&popover
, Gtk::Widget
&widget
, Gdk::Rectangle
const &rect
);
70 } // namespace Inkscape::UI
72 #endif // SEEN_UI_POPUP_MENU_H
77 c-file-style:"stroustrup"
78 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
83 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :