1 /**
2 * \brief Labelled Widget - Adds a label with optional icon or suffix to
3 * another widget.
4 *
5 * Authors:
6 * Carl Hetherington <inkscape@carlh.net>
7 * Derek P. Moore <derekm@hackunix.org>
8 *
9 * Copyright (C) 2004 Carl Hetherington
10 *
11 * Released under GNU GPL. Read the file 'COPYING' for more information.
12 */
14 #ifdef HAVE_CONFIG_H
15 # include <config.h>
16 #endif
18 /* For getting the Gtkmmified Icon manager */
19 #include "widgets/icon.h"
21 #include "labelled.h"
23 namespace Inkscape {
24 namespace UI {
25 namespace Widget {
27 /**
28 * Construct a Labelled Widget.
29 *
30 * \param label Label.
31 * \param widget Widget to label; should be allocated with new, as it will
32 * be passed to Gtk::manage().
33 * \param suffix Suffix, placed after the widget (defaults to "").
34 * \param icon Icon filename, placed before the label (defaults to "").
35 * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the text
36 * indicates the next character should be used for the
37 * mnemonic accelerator key (defaults to true).
38 */
39 Labelled::Labelled(Glib::ustring const &label, Glib::ustring const &tooltip,
40 Gtk::Widget *widget,
41 Glib::ustring const &suffix,
42 Glib::ustring const &icon,
43 bool mnemonic)
44 : _widget(widget),
45 _label(new Gtk::Label(label, 1.0, 0.5, mnemonic)),
46 _suffix(new Gtk::Label(suffix, 0.0, 0.5)),
47 _tooltips()
48 {
49 g_assert(g_utf8_validate(icon.c_str(), -1, NULL));
50 if (icon != "") {
51 _icon = sp_icon_get_icon(icon.c_str(), Inkscape::ICON_SIZE_LARGE_TOOLBAR);
52 pack_start(*Gtk::manage(_icon), Gtk::PACK_SHRINK);
53 }
54 pack_start(*Gtk::manage(_label), Gtk::PACK_EXPAND_WIDGET, 6);
55 pack_start(*Gtk::manage(_widget), Gtk::PACK_SHRINK, 6);
56 if (mnemonic) {
57 _label->set_mnemonic_widget(*_widget);
58 }
59 _tooltips.set_tip(*_widget, tooltip);
60 }
63 /**
64 * Allow the setting of the width of the labelled widget
65 */
66 void Labelled::setWidgetSizeRequest(int width, int height)
67 {
68 if (_widget)
69 _widget->set_size_request(width, height);
72 }
74 const Gtk::Widget* const
75 Labelled::getWidget() const
76 {
77 return _widget;
78 }
80 const Gtk::Label* const
81 Labelled::getLabel() const
82 {
83 return _label;
84 }
89 } // namespace Widget
90 } // namespace UI
91 } // namespace Inkscape
93 /*
94 Local Variables:
95 mode:c++
96 c-file-style:"stroustrup"
97 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
98 indent-tabs-mode:nil
99 fill-column:99
100 End:
101 */
102 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :