1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Authors:
4  *   Carl Hetherington <inkscape@carlh.net>
5  *   Derek P. Moore <derekm@hackunix.org>
6  *
7  * Copyright (C) 2004 Carl Hetherington
8  *
9  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10  */
11 
12 #include "labelled.h"
13 #include "ui/icon-loader.h"
14 #include <gtkmm/image.h>
15 #include <gtkmm/label.h>
16 
17 namespace Inkscape {
18 namespace UI {
19 namespace Widget {
20 
Labelled(Glib::ustring const & label,Glib::ustring const & tooltip,Gtk::Widget * widget,Glib::ustring const & suffix,Glib::ustring const & icon,bool mnemonic)21 Labelled::Labelled(Glib::ustring const &label, Glib::ustring const &tooltip,
22                    Gtk::Widget *widget,
23                    Glib::ustring const &suffix,
24                    Glib::ustring const &icon,
25                    bool mnemonic)
26     : Gtk::Box(Gtk::ORIENTATION_HORIZONTAL),
27       _widget(widget),
28       _label(new Gtk::Label(label, Gtk::ALIGN_START, Gtk::ALIGN_CENTER, mnemonic)),
29       _suffix(nullptr)
30 {
31     g_assert(g_utf8_validate(icon.c_str(), -1, nullptr));
32     if (icon != "") {
33         _icon = Gtk::manage(sp_get_icon_image(icon, Gtk::ICON_SIZE_LARGE_TOOLBAR));
34         pack_start(*_icon, Gtk::PACK_SHRINK);
35     }
36 
37     set_spacing(6);
38     // Setting margins separately allows for more control over them
39     set_margin_start(6);
40     set_margin_end(6);
41     pack_start(*Gtk::manage(_label), Gtk::PACK_SHRINK);
42     pack_start(*Gtk::manage(_widget), Gtk::PACK_SHRINK);
43     if (mnemonic) {
44         _label->set_mnemonic_widget(*_widget);
45     }
46     widget->set_tooltip_text(tooltip);
47 }
48 
49 
setWidgetSizeRequest(int width,int height)50 void Labelled::setWidgetSizeRequest(int width, int height)
51 {
52     if (_widget)
53         _widget->set_size_request(width, height);
54 
55 
56 }
57 
58 Gtk::Label const *
getLabel() const59 Labelled::getLabel() const
60 {
61     return _label;
62 }
63 
64 void
setLabelText(const Glib::ustring & str)65 Labelled::setLabelText(const Glib::ustring &str)
66 {
67     _label->set_text(str);
68 }
69 
70 void
setTooltipText(const Glib::ustring & tooltip)71 Labelled::setTooltipText(const Glib::ustring &tooltip)
72 {
73     _label->set_tooltip_text(tooltip);
74     _widget->set_tooltip_text(tooltip);
75 }
76 
on_mnemonic_activate(bool group_cycling)77 bool Labelled::on_mnemonic_activate ( bool group_cycling )
78 {
79     return _widget->mnemonic_activate ( group_cycling );
80 }
81 
82 void
set_hexpand(bool expand)83 Labelled::set_hexpand(bool expand)
84 {
85     // should only have 2 children, but second child may not be _widget
86     child_property_pack_type(*get_children().back()) = expand ? Gtk::PACK_END
87                                                               : Gtk::PACK_START;
88 
89     Gtk::Box::set_hexpand(expand);
90 }
91 
92 } // namespace Widget
93 } // namespace UI
94 } // namespace Inkscape
95 
96 /*
97   Local Variables:
98   mode:c++
99   c-file-style:"stroustrup"
100   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
101   indent-tabs-mode:nil
102   fill-column:99
103   End:
104 */
105 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
106