summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/icon-combobox.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /src/ui/widget/icon-combobox.h
parentInitial commit. (diff)
downloadinkscape-upstream.tar.xz
inkscape-upstream.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/ui/widget/icon-combobox.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/ui/widget/icon-combobox.h b/src/ui/widget/icon-combobox.h
new file mode 100644
index 0000000..6c1770c
--- /dev/null
+++ b/src/ui/widget/icon-combobox.h
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#ifndef ICON_COMBO_BOX_SEEN_
+#define ICON_COMBO_BOX_SEEN_
+
+#include <gtkmm/combobox.h>
+#include <gtkmm/liststore.h>
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class IconComboBox : public Gtk::ComboBox {
+public:
+ IconComboBox() {
+ _model = Gtk::ListStore::create(_columns);
+ set_model(_model);
+
+ pack_start(_renderer, false);
+ _renderer.set_property("stock_size", Gtk::ICON_SIZE_BUTTON);
+ _renderer.set_padding(2, 0);
+ add_attribute(_renderer, "icon_name", _columns.icon_name);
+
+ pack_start(_columns.label);
+ }
+
+ void add_row(const Glib::ustring& icon_name, const Glib::ustring& label, int id) {
+ Gtk::TreeModel::Row row = *_model->append();
+ row[_columns.id] = id;
+ row[_columns.icon_name] = icon_name;
+ row[_columns.label] = ' ' + label;
+ }
+
+ void set_active_by_id(int id) {
+ for (auto i = _model->children().begin(); i != _model->children().end(); ++i) {
+ const int data = (*i)[_columns.id];
+ if (data == id) {
+ set_active(i);
+ break;
+ }
+ }
+ };
+
+ int get_active_row_id() const {
+ if (auto it = get_active()) {
+ return (*it)[_columns.id];
+ }
+ return -1;
+ }
+
+private:
+ class Columns : public Gtk::TreeModel::ColumnRecord
+ {
+ public:
+ Columns() {
+ add(icon_name);
+ add(label);
+ add(id);
+ }
+
+ Gtk::TreeModelColumn<Glib::ustring> icon_name;
+ Gtk::TreeModelColumn<Glib::ustring> label;
+ Gtk::TreeModelColumn<int> id;
+ };
+
+ Columns _columns;
+ Glib::RefPtr<Gtk::ListStore> _model;
+ Gtk::CellRendererPixbuf _renderer;
+};
+
+}}}
+
+#endif