1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #ifndef SEEN_COMBO_TOOL_ITEM
3 #define SEEN_COMBO_TOOL_ITEM
4 
5 /*
6  * Authors:
7  *   Tavmjong Bah <tavmjong@free.fr>
8  *
9  * Copyright  (C) 2017 Tavmjong Bah
10  *
11  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12  */
13 
14 /**
15    A combobox that can be displayed in a toolbar
16 */
17 
18 #include <gtkmm/toolitem.h>
19 #include <gtkmm/liststore.h>
20 #include <sigc++/sigc++.h>
21 #include <vector>
22 
23 namespace Gtk {
24 class Box;
25 class ComboBox;
26 class Label;
27 class MenuItem;
28 class RadioMenuItem;
29 }
30 
31 namespace Inkscape {
32 namespace UI {
33 namespace Widget {
34 class ComboToolItemColumns : public Gtk::TreeModel::ColumnRecord {
35 public:
ComboToolItemColumns()36     ComboToolItemColumns() {
37         add (col_label);
38         add (col_value);
39         add (col_icon);
40         add (col_pixbuf);
41         add (col_data);  // Used to store a pointer
42         add (col_tooltip);
43         add (col_sensitive);
44     }
45     Gtk::TreeModelColumn<Glib::ustring> col_label;
46     Gtk::TreeModelColumn<Glib::ustring> col_value;
47     Gtk::TreeModelColumn<Glib::ustring> col_icon;
48     Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> >   col_pixbuf;
49     Gtk::TreeModelColumn<void *>        col_data;
50     Gtk::TreeModelColumn<Glib::ustring> col_tooltip;
51     Gtk::TreeModelColumn<bool>          col_sensitive;
52 };
53 
54 
55 class ComboToolItem : public Gtk::ToolItem {
56 
57 public:
58     static ComboToolItem* create(const Glib::ustring &label,
59                                  const Glib::ustring &tooltip,
60                                  const Glib::ustring &stock_id,
61                                  Glib::RefPtr<Gtk::ListStore> store,
62                                  bool                 has_entry = false);
63 
64     /* Style of combobox */
65     void use_label(  bool use_label  );
66     void use_icon(   bool use_icon   );
67     void focus_on_click( bool focus_on_click );
68     void use_pixbuf( bool use_pixbuf );
69     void use_group_label( bool use_group_label ); // Applies to tool item only
70 
get_active()71     gint get_active() { return _active; }
72     Glib::ustring get_active_text();
73     void set_active( gint active );
set_icon_size(Gtk::BuiltinIconSize size)74     void set_icon_size( Gtk::BuiltinIconSize size ) { _icon_size = size; }
75 
get_store()76     Glib::RefPtr<Gtk::ListStore> get_store() { return _store; }
77 
signal_changed()78     sigc::signal<void, int> signal_changed() { return _changed; }
signal_changed_after()79     sigc::signal<void, int> signal_changed_after() { return _changed_after; }
80 
81 protected:
82     bool on_create_menu_proxy() override;
83     void populate_combobox();
84 
85     /* Signals */
86     sigc::signal<void, int> _changed;
87     sigc::signal<void, int> _changed_after;  // Needed for unit tracker which eats _changed.
88 
89 private:
90 
91     Glib::ustring _group_label;
92     Glib::ustring _tooltip;
93     Glib::ustring _stock_id;
94     Glib::RefPtr<Gtk::ListStore> _store;
95 
96     gint _active;  /* Active menu item/button */
97 
98     /* Style */
99     bool _use_label;
100     bool _use_icon;   // Applies to menu item only
101     bool _use_pixbuf;
102     Gtk::BuiltinIconSize _icon_size;
103 
104     /* Combobox in tool */
105     Gtk::ComboBox* _combobox;
106     Gtk::Label* _group_label_widget;
107     Gtk::Box* _container;
108 
109     Gtk::MenuItem* _menuitem;
110     std::vector<Gtk::RadioMenuItem*> _radiomenuitems;
111 
112     /* Internal Callbacks */
113     void on_changed_combobox();
114     void on_toggled_radiomenu(int n);
115 
116     ComboToolItem(Glib::ustring group_label,
117                   Glib::ustring tooltip,
118                   Glib::ustring stock_id,
119                   Glib::RefPtr<Gtk::ListStore> store,
120                   bool          has_entry = false);
121 };
122 }
123 }
124 }
125 #endif /* SEEN_COMBO_TOOL_ITEM */
126 
127 /*
128   Local Variables:
129   mode:c++
130   c-file-style:"stroustrup"
131   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
132   indent-tabs-mode:nil
133   fill-column:99
134   End:
135 */
136 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
137