Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
menu-set-tooltips-shift-icons.cpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: GPL-2.0-or-later
7
/*
8
* Authors:
9
* Tavmjong Bah <tavmjong@free.fr>
10
* Patrick Storz <eduard.braun2@gmx.de>
11
* Daniel Boles <dboles.src+inkscape@gmail.com>
12
*
13
* Copyright (C) 2020-2023 Authors
14
*
15
* The contents of this file may be used under the GNU General Public License Version 2 or later.
16
* Read the file 'COPYING' for more information.
17
*
18
*/
19
20
#include "
ui/desktop/menu-set-tooltips-shift-icons.h
"
21
22
#include <glibmm/ustring.h>
23
#include <gtkmm/box.h>
24
#include <gtkmm/button.h>
25
#include <gtkmm/cssprovider.h>
26
#include <gtkmm/image.h>
27
#include <gtkmm/label.h>
28
29
#include "
inkscape-application.h
"
// Action extra data
30
#include "
ui/shortcuts.h
"
// TEMP???
31
#include "
ui/util.h
"
32
33
// Could be used to update status bar.
34
// bool on_enter_notify(GdkEventCrossing* crossing_event, Gtk::MenuItem* menuitem)
35
// {
36
// return false;
37
// }
38
39
[[nodiscard]]
static
Glib::ustring
find_label
(Gtk::Widget &
parent
)
40
{
41
Glib::ustring
label
;
42
Inkscape::UI::for_each_child
(
parent
, [&](Gtk::Widget
const
&
child
)
43
{
44
if
(
auto
const
label_widget =
dynamic_cast<
Gtk::Label
const
*
>
(&
child
)) {
45
label
= label_widget->get_label();
46
return
Inkscape::UI::ForEachResult::_break
;
47
}
48
return
Inkscape::UI::ForEachResult::_continue
;
49
});
50
return
label
;
51
}
52
60
bool
61
set_tooltips_and_shift_icons
(Gtk::Widget &menu,
bool
const
shift_icons)
62
{
63
/*
64
int width{}, height{};
65
66
if (shift_icons) {
67
menu.add_css_class("shifticonmenu");
68
gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
69
}
70
*/
71
72
bool
shifted =
false
;
73
74
// Calculate required shift. We need an example!
75
// Search for GtkModelButton -> Gtk::Box, Gtk::Image (optional), Gtk::Label.
76
static
auto
app =
InkscapeApplication::instance
();
77
auto
&label_to_tooltip_map = app->get_menu_label_to_tooltip_map();
78
79
Inkscape::UI::for_each_child
(menu, [&](Gtk::Widget &
child
) {
80
81
// Set tooltip.
82
Glib::ustring
label
;
83
if
(
child
.get_name().raw() ==
"GtkModelButton"
) {
84
label = find_label(child);
85
}
86
87
if (!
label
.empty()) {
88
auto it = label_to_tooltip_map.find(label);
89
if (it != label_to_tooltip_map.end()) {
90
child.set_tooltip_text(it->second);
// Set tooltip on GtkModelButton.
91
}
92
}
93
94
// The ModelButton contains in order: GtkBox, GtkImage (optionally), GtkLabel, GtkPopoverMenu (optionally).
95
// for (auto child2 = child.get_first_child(); child2 != nullptr; child2 = child2->get_next_sibling()) {
96
// if (auto box = dynamic_cast<Gtk::Box*>(child2)) {
97
// // Do something with box. We might be able to use box width to calculate shift.
98
// }
99
// if (auto image = dynamic_cast<Gtk::Image*>(child2)) {
100
// // Do something with image.
101
// }
102
// if (auto label = dynamic_cast<Gtk::Image*>(child2)) {
103
// // Do something with label. Redundant with above.
104
// }
105
// if (child2->get_name() == "GtkPopoverMenu") {
106
// // Doesn't work as there are whole lot of widgets in the tree.
107
// set_tooltips_and_shift_icons(*child2, shift_icons);
108
// }
109
// }
110
111
// TODO: GTK4: Figure out the kind of shift we need.
112
113
// if (!shift_icons || shifted || !box) {
114
// return Inkscape::UI::ForEachResult::_continue;
115
// }
116
117
// width += box->get_spacing();
118
// auto const margin_side = widget->get_direction() == Gtk::TextDirection::RTL ? "right" : "left";
119
// // TODO: GTK4: as per TODOs above.
120
// auto const css_str = Glib::ustring::compose(".shifticonmenu menuitem box { margin-%1: -%2px; }"
121
// ".shifticonmenu modelbutton box > label:only-child { margin-%1: %2px; }",
122
// margin_side, width);
123
// Glib::RefPtr<Gtk::CssProvider> provider = Gtk::CssProvider::create();
124
// provider->load_from_data(css_str);
125
// auto const display = Gdk::Display::get_default();
126
// Gtk::StyleContext::add_provider_for_display(display, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
127
// shifted = true;
128
129
// Recurse
130
set_tooltips_and_shift_icons
(
child
, shift_icons);
131
132
return
Inkscape::UI::ForEachResult::_continue
;
133
});
134
135
return
shifted;
136
}
137
138
/*
139
Local Variables:
140
mode:c++
141
c-file-style:"stroustrup"
142
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
143
indent-tabs-mode:nil
144
fill-column:99
145
End:
146
*/
147
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
InkscapeApplication::instance
static InkscapeApplication * instance()
Singleton instance.
Definition
inkscape-application.cpp:505
parent
static char const *const parent
Definition
dir-util.cpp:70
inkscape-application.h
label
Glib::ustring label
Definition
measure-tool.cpp:63
set_tooltips_and_shift_icons
bool set_tooltips_and_shift_icons(Gtk::Widget &menu, bool const shift_icons)
Go over a widget representing a menu, & set tooltips on its items from app label-to-tooltip map.
Definition
menu-set-tooltips-shift-icons.cpp:61
find_label
static Glib::ustring find_label(Gtk::Widget &parent)
Definition
menu-set-tooltips-shift-icons.cpp:39
menu-set-tooltips-shift-icons.h
Go over a widget representing a menu, & set tooltips on its items from app label-to-tooltip map.
Inkscape::UI::ForEachResult::_break
@ _break
Inkscape::UI::ForEachResult::_continue
@ _continue
Inkscape::UI::for_each_child
Gtk::Widget * for_each_child(Gtk::Widget &widget, Func &&func, bool const plus_self=false, bool const recurse=false, int const level=0)
Call Func with a reference to each child of parent, until it returns _break.
Definition
util.h:90
child
Ocnode * child[8]
Definition
quantize.cpp:33
shortcuts.h
util.h
src
ui
desktop
menu-set-tooltips-shift-icons.cpp
Generated on Sun Jul 20 2025 04:02:03 for Inkscape by
1.9.8