diff options
| author | Alexander Valavanis <valavanisalex@gmail.com> | 2019-06-05 19:34:19 +0000 |
|---|---|---|
| committer | Alexander Valavanis <valavanisalex@gmail.com> | 2019-06-05 19:34:19 +0000 |
| commit | 346e764345e1fbf877307313cd4779874dfd3ed9 (patch) | |
| tree | d5c326e85f752a1cd54301bc19592d90d9445e51 /src/ui/widget | |
| parent | Merge changes (diff) | |
| parent | Finish TextToolbar migration (diff) | |
| download | inkscape-346e764345e1fbf877307313cd4779874dfd3ed9.tar.gz inkscape-346e764345e1fbf877307313cd4779874dfd3ed9.zip | |
Merge branch 'text-toolbar-migration'
Diffstat (limited to 'src/ui/widget')
| -rw-r--r-- | src/ui/widget/combo-box-entry-tool-item.cpp | 684 | ||||
| -rw-r--r-- | src/ui/widget/combo-box-entry-tool-item.h | 155 | ||||
| -rw-r--r-- | src/ui/widget/combo-tool-item.cpp | 53 | ||||
| -rw-r--r-- | src/ui/widget/combo-tool-item.h | 15 | ||||
| -rw-r--r-- | src/ui/widget/ink-select-one-action.cpp | 269 | ||||
| -rw-r--r-- | src/ui/widget/ink-select-one-action.h | 143 | ||||
| -rw-r--r-- | src/ui/widget/spin-button-tool-item.cpp | 27 | ||||
| -rw-r--r-- | src/ui/widget/spin-button-tool-item.h | 6 | ||||
| -rw-r--r-- | src/ui/widget/unit-tracker.cpp | 57 | ||||
| -rw-r--r-- | src/ui/widget/unit-tracker.h | 11 |
10 files changed, 922 insertions, 498 deletions
diff --git a/src/ui/widget/combo-box-entry-tool-item.cpp b/src/ui/widget/combo-box-entry-tool-item.cpp new file mode 100644 index 000000000..2c3a37693 --- /dev/null +++ b/src/ui/widget/combo-box-entry-tool-item.cpp @@ -0,0 +1,684 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * A subclass of GtkAction that wraps a GtkComboBoxEntry. + * Features: + * Setting GtkEntryBox width in characters. + * Passing a function for formatting cells. + * Displaying a warning if entry text isn't in list. + * Check comma separated values in text against list. (Useful for font-family fallbacks.) + * Setting names for GtkComboBoxEntry and GtkEntry (actionName_combobox, actionName_entry) + * to allow setting resources. + * + * Author(s): + * Tavmjong Bah + * Jon A. Cruz <jon@joncruz.org> + * + * Copyright (C) 2010 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +/* + * We must provide for both a toolbar item and a menu item. + * As we don't know which widgets are used (or even constructed), + * we must keep track of things like active entry ourselves. + */ + +#include "combo-box-entry-tool-item.h" + +#include <iostream> +#include <cstring> +#include <glibmm/ustring.h> + +#include <gtk/gtk.h> +#include <gdk/gdkkeysyms.h> +#include <gdkmm/display.h> + +#include "ui/icon-names.h" + +static GQuark gDataName = 0; + + //gDataName = g_quark_from_string("ink_comboboxentry-action"); + +namespace Inkscape { +namespace UI { +namespace Widget { + +ComboBoxEntryToolItem::ComboBoxEntryToolItem(Glib::ustring name, + Glib::ustring label, + Glib::ustring tooltip, + GtkTreeModel *model, + gint entry_width, + gint extra_width, + void *cell_data_func, + void *separator_func, + GtkWidget *focusWidget) + : _label(std::move(label)), + _tooltip(std::move(tooltip)), + _model(model), + _entry_width(entry_width), + _extra_width(extra_width), + _cell_data_func(cell_data_func), + _separator_func(separator_func), + _focusWidget(focusWidget), + _active(-1), + _text(strdup("")), + _entry_completion(nullptr), + _indicator(nullptr), + _popup(false), + _info(nullptr), + _info_cb(nullptr), + _info_cb_id(0), + _info_cb_blocked(false), + _warning(nullptr), + _warning_cb(nullptr), + _warning_cb_id(0), + _warning_cb_blocked(false), + _altx_name(nullptr) +{ + set_name(name); + + gchar *action_name = g_strdup( get_name().c_str() ); + gchar *combobox_name = g_strjoin( nullptr, action_name, "_combobox", NULL ); + gchar *entry_name = g_strjoin( nullptr, action_name, "_entry", NULL ); + g_free( action_name ); + + GtkWidget* comboBoxEntry = gtk_combo_box_new_with_model_and_entry (_model); + gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (comboBoxEntry), 0); + + // Name it so we can muck with it using an RC file + gtk_widget_set_name( comboBoxEntry, combobox_name ); + g_free( combobox_name ); + + { + gtk_widget_set_halign(comboBoxEntry, GTK_ALIGN_START); + gtk_widget_set_hexpand(comboBoxEntry, FALSE); + gtk_widget_set_vexpand(comboBoxEntry, FALSE); + add(*Glib::wrap(comboBoxEntry)); + } + + _combobox = GTK_COMBO_BOX (comboBoxEntry); + + //gtk_combo_box_set_active( GTK_COMBO_BOX( comboBoxEntry ), ink_comboboxentry_action->active ); + gtk_combo_box_set_active( GTK_COMBO_BOX( comboBoxEntry ), 0 ); + + g_signal_connect( G_OBJECT(comboBoxEntry), "changed", G_CALLBACK(combo_box_changed_cb), this ); + + // Optionally add separator function... + if( _separator_func != nullptr ) { + gtk_combo_box_set_row_separator_func( _combobox, + GtkTreeViewRowSeparatorFunc (_separator_func), + nullptr, nullptr ); + } + + // FIXME: once gtk3 migration is done this can be removed + // https://bugzilla.gnome.org/show_bug.cgi?id=734915 + gtk_widget_show_all (comboBoxEntry); + + // Optionally add formatting... + if( _cell_data_func != nullptr ) { + GtkCellRenderer *cell = gtk_cell_renderer_text_new(); + gtk_cell_layout_clear( GTK_CELL_LAYOUT( comboBoxEntry ) ); + gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( comboBoxEntry ), cell, true ); + gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT( comboBoxEntry ), cell, + GtkCellLayoutDataFunc (_cell_data_func), + nullptr, nullptr ); + } + + // Optionally widen the combobox width... which widens the drop-down list in list mode. + if( _extra_width > 0 ) { + GtkRequisition req; + gtk_widget_get_preferred_size(GTK_WIDGET(_combobox), &req, nullptr); + gtk_widget_set_size_request( GTK_WIDGET( _combobox ), + req.width + _extra_width, -1 ); + } + + // Get reference to GtkEntry and fiddle a bit with it. + GtkWidget *child = gtk_bin_get_child( GTK_BIN(comboBoxEntry) ); + + // Name it so we can muck with it using an RC file + gtk_widget_set_name( child, entry_name ); + g_free( entry_name ); + + if( child && GTK_IS_ENTRY( child ) ) { + + _entry = GTK_ENTRY(child); + + // Change width + if( _entry_width > 0 ) { + gtk_entry_set_width_chars (GTK_ENTRY (child), _entry_width ); + } + + // Add pop-up entry completion if required + if( _popup ) { + popup_enable(); + } + + // Add altx_name if required + if( _altx_name ) { + g_object_set_data( G_OBJECT( child ), _altx_name, _entry ); + } + + // Add signal for GtkEntry to check if finished typing. + g_signal_connect( G_OBJECT(child), "activate", G_CALLBACK(entry_activate_cb), this ); + g_signal_connect( G_OBJECT(child), "key-press-event", G_CALLBACK(keypress_cb), this ); + } + + set_tooltip(tooltip.c_str()); + + show_all(); +} + +// Setters/Getters --------------------------------------------------- + +gchar* +ComboBoxEntryToolItem::get_active_text() +{ + gchar* text = g_strdup( _text ); + return text; +} + +/* + * For the font-family list we need to handle two cases: + * Text is in list store: + * In this case we use row number as the font-family list can have duplicate + * entries, one in the document font part and one in the system font part. In + * order that scrolling through the list works properly we must distinguish + * between the two. + * Text is not in the list store (i.e. default font-family is not on system): + * In this case we have a row number of -1, and the text must be set by hand. + */ +gboolean +ComboBoxEntryToolItem::set_active_text(const gchar* text, int row) +{ + if( strcmp( _text, text ) != 0 ) { + g_free( _text ); + _text = g_strdup( text ); + } + + // Get active row or -1 if none + if( row < 0 ) { + row = get_active_row_from_text(this, _text); + } + _active = row; + + // Set active row, check that combobox has been created. + if( _combobox ) { + gtk_combo_box_set_active( GTK_COMBO_BOX( _combobox ), _active ); + } + + // Fiddle with entry + if( _entry ) { + + // Explicitly set text in GtkEntry box (won't be set if text not in list). + gtk_entry_set_text( _entry, text ); + + // Show or hide warning -- this might be better moved to text-toolbox.cpp + if( _info_cb_id != 0 && + !_info_cb_blocked ) { + g_signal_handler_block (G_OBJECT(_entry), + _info_cb_id ); + _info_cb_blocked = true; + } + if( _warning_cb_id != 0 && + !_warning_cb_blocked ) { + g_signal_handler_block (G_OBJECT(_entry), + _warning_cb_id ); + _warning_cb_blocked = true; + } + + bool set = false; + if( _warning != nullptr ) { + Glib::ustring missing = check_comma_separated_text(); + if( !missing.empty() ) { + gtk_entry_set_icon_from_icon_name( _entry, + GTK_ENTRY_ICON_SECONDARY, + INKSCAPE_ICON("dialog-warning") ); + // Can't add tooltip until icon set + Glib::ustring warning = _warning; + warning += ": "; + warning += missing; + gtk_entry_set_icon_tooltip_text( _entry, + GTK_ENTRY_ICON_SECONDARY, + warning.c_str() ); + + if( _warning_cb ) { + + // Add callback if we haven't already + if( _warning_cb_id == 0 ) { + _warning_cb_id = + g_signal_connect( G_OBJECT(_entry), + "icon-press", + G_CALLBACK(_warning_cb), + this); + } + // Unblock signal + if( _warning_cb_blocked ) { + g_signal_handler_unblock (G_OBJECT(_entry), + _warning_cb_id ); + _warning_cb_blocked = false; + } + } + set = true; + } + } + + if( !set && _info != nullptr ) { + gtk_entry_set_icon_from_icon_name( GTK_ENTRY(_entry), + GTK_ENTRY_ICON_SECONDARY, + INKSCAPE_ICON("edit-select-all") ); + gtk_entry_set_icon_tooltip_text( _entry, + GTK_ENTRY_ICON_SECONDARY, + _info ); + + if( _info_cb ) { + // Add callback if we haven't already + if( _info_cb_id == 0 ) { + _info_cb_id = + g_signal_connect( G_OBJECT(_entry), + "icon-press", + G_CALLBACK(_info_cb), + this); + } + // Unblock signal + if( _info_cb_blocked ) { + g_signal_handler_unblock (G_OBJECT(_entry), + _info_cb_id ); + _info_cb_blocked = false; + } + } + set = true; + } + + if( !set ) { + gtk_entry_set_icon_from_icon_name( GTK_ENTRY(_entry), + GTK_ENTRY_ICON_SECONDARY, + nullptr ); + } + } + + // Return if active text in list + gboolean found = ( _active != -1 ); + return found; +} + +void +ComboBoxEntryToolItem::set_entry_width(gint entry_width) +{ + _entry_width = entry_width; + + // Clamp to limits + if(entry_width < -1) entry_width = -1; + if(entry_width > 100) entry_width = 100; + + // Widget may not have been created.... + if( _entry ) { + gtk_entry_set_width_chars( GTK_ENTRY(_entry), entry_width ); + } +} + +void +ComboBoxEntryToolItem::set_extra_width( gint extra_width ) +{ + _extra_width = extra_width; + + // Clamp to limits + if(extra_width < -1) extra_width = -1; + if(extra_width > 500) extra_width = 500; + + // Widget may not have been created.... + if( _combobox ) { + GtkRequisition req; + gtk_widget_get_preferred_size(GTK_WIDGET(_combobox), &req, nullptr); + gtk_widget_set_size_request( GTK_WIDGET( _combobox ), req.width + _extra_width, -1 ); + } +} + +void +ComboBoxEntryToolItem::popup_enable() +{ + _popup = true; + + // Widget may not have been created.... + if( _entry ) { + + // Check we don't already have a GtkEntryCompletion + if( _entry_completion ) return; + + _entry_completion = gtk_entry_completion_new(); + + gtk_entry_set_completion( _entry, _entry_completion ); + gtk_entry_completion_set_model( _entry_completion, _model ); + gtk_entry_completion_set_text_column( _entry_completion, 0 ); + gtk_entry_completion_set_popup_completion( _entry_completion, true ); + gtk_entry_completion_set_inline_completion( _entry_completion, false ); + gtk_entry_completion_set_inline_selection( _entry_completion, true ); + + g_signal_connect (G_OBJECT (_entry_completion), "match-selected", G_CALLBACK (match_selected_cb), this); + } +} + +void +ComboBoxEntryToolItem::popup_disable() +{ + _popup = false; + + if( _entry_completion ) { + gtk_widget_destroy(GTK_WIDGET(_entry_completion)); + _entry_completion = nullptr; + } +} + +void +ComboBoxEntryToolItem::set_tooltip(const gchar* tooltip) +{ + set_tooltip_text(tooltip); + gtk_widget_set_tooltip_text ( GTK_WIDGET(_combobox), tooltip); + + // Widget may not have been created.... + if( _entry ) { + gtk_widget_set_tooltip_text ( GTK_WIDGET(_entry), tooltip); + } +} + +void +ComboBoxEntryToolItem::set_info(const gchar* info) +{ + g_free( _info ); + _info = g_strdup( info ); + + // Widget may not have been created.... + if( _entry ) { + gtk_entry_set_icon_tooltip_text( GTK_ENTRY(_entry), + GTK_ENTRY_ICON_SECONDARY, + _info ); + } +} + +void +ComboBoxEntryToolItem::set_info_cb(gpointer info_cb) +{ + _info_cb = info_cb; +} + +void +ComboBoxEntryToolItem::set_warning(const gchar* warning) +{ + g_free( _warning ); + _warning = g_strdup( warning ); + + // Widget may not have been created.... + if( _entry ) { + gtk_entry_set_icon_tooltip_text( GTK_ENTRY(_entry), + GTK_ENTRY_ICON_SECONDARY, + _warning ); + } +} + +void +ComboBoxEntryToolItem::set_warning_cb(gpointer warning_cb) +{ + _warning_cb = warning_cb; +} + +void +ComboBoxEntryToolItem::set_altx_name(const gchar* altx_name) +{ + g_free(_altx_name); + _altx_name = g_strdup( altx_name ); + + // Widget may not have been created.... + if(_entry) { + g_object_set_data( G_OBJECT(_entry), _altx_name, _entry ); + } +} + +// Internal --------------------------------------------------- + +// Return row of active text or -1 if not found. If exclude is true, +// use 3d colunm if available to exclude row from checking (useful to +// skip rows added for font-families included in doc and not on +// system) +gint +ComboBoxEntryToolItem::get_active_row_from_text(ComboBoxEntryToolItem *action, + const gchar *target_text, + gboolean exclude, + gboolean ignore_case ) +{ + // Check if text in list + gint row = 0; + gboolean found = false; + GtkTreeIter iter; + gboolean valid = gtk_tree_model_get_iter_first( action->_model, &iter ); + while ( valid ) { + + // See if we should exclude a row + gboolean check = true; // If true, font-family is on system. + if( exclude && gtk_tree_model_get_n_columns( action->_model ) > 2 ) { + gtk_tree_model_get( action->_model, &iter, 2, &check, -1 ); + } + + if( check ) { + // Get text from list entry + gchar* text = nullptr; + gtk_tree_model_get( action->_model, &iter, 0, &text, -1 ); // Column 0 + + if( !ignore_case ) { + // Case sensitive compare + if( strcmp( target_text, text ) == 0 ){ + found = true; + break; + } + } else { + // Case insensitive compare + gchar* target_text_casefolded = g_utf8_casefold( target_text, -1 ); + gchar* text_casefolded = g_utf8_casefold( text, -1 ); + gboolean equal = (strcmp( target_text_casefolded, text_casefolded ) == 0 ); + g_free( text_casefolded ); + g_free( target_text_casefolded ); + if( equal ) { + found = true; + break; + } + } + } + + ++row; + valid = gtk_tree_model_iter_next( action->_model, &iter ); + } + + if( !found ) row = -1; + + return row; +} + +// Checks if all comma separated text fragments are in the list and +// returns a ustring with a list of missing fragments. +// This is useful for checking if all fonts in a font-family fallback +// list are available on the system. +// +// This routine could also create a Pango Markup string to show which +// fragments are invalid in the entry box itself. See: +// http://developer.gnome.org/pango/stable/PangoMarkupFormat.html +// However... it appears that while one can retrieve the PangoLayout +// for a GtkEntry box, it is only a copy and changing it has no effect. +// PangoLayout * pl = gtk_entry_get_layout( entry ); +// pango_layout_set_markup( pl, "NEW STRING", -1 ); // DOESN'T WORK +Glib::ustring +ComboBoxEntryToolItem::check_comma_separated_text() +{ + Glib::ustring missing; + + // Parse fallback_list using a comma as deliminator + gchar** tokens = g_strsplit( _text, ",", 0 ); + + gint i = 0; + while( tokens[i] != nullptr ) { + + // Remove any surrounding white space. + g_strstrip( tokens[i] ); + + if( get_active_row_from_text( this, tokens[i], true, true ) == -1 ) { + missing += tokens[i]; + missing += ", "; + } + ++i; + } + g_strfreev( tokens ); + + // Remove extra comma and space from end. + if( missing.size() >= 2 ) { + missing.resize( missing.size()-2 ); + } + return missing; +} + +// Callbacks --------------------------------------------------- + +void +ComboBoxEntryToolItem::combo_box_changed_cb( GtkComboBox* widget, gpointer data ) +{ + // Two things can happen to get here: + // An item is selected in the drop-down menu. + // Text is typed. + // We only react here if an item is selected. + + // Get action + auto action = reinterpret_cast<ComboBoxEntryToolItem *>( data ); + + // Check if item selected: + gint newActive = gtk_combo_box_get_active(widget); + if( newActive >= 0 && newActive != action->_active ) { + + action->_active = newActive; + + GtkTreeIter iter; + if( gtk_combo_box_get_active_iter( GTK_COMBO_BOX( action->_combobox ), &iter ) ) { + + gchar* text = nullptr; + gtk_tree_model_get( action->_model, &iter, 0, &text, -1 ); + gtk_entry_set_text( action->_entry, text ); + + g_free( action->_text ); + action->_text = text; + } + + // Now let the world know + action->_signal_changed.emit(); + } +} + +void +ComboBoxEntryToolItem::entry_activate_cb( GtkEntry *widget, + gpointer data ) +{ + // Get text from entry box.. check if it matches a menu entry. + + // Get action + auto action = reinterpret_cast<ComboBoxEntryToolItem*>( data ); + + // Get text + g_free( action->_text ); + action->_text = g_strdup( gtk_entry_get_text( widget ) ); + + // Get row + action->_active = + get_active_row_from_text( action, action->_text ); + + // Set active row + gtk_combo_box_set_active( GTK_COMBO_BOX( action->_combobox), action->_active ); + + // Now let the world know + action->_signal_changed.emit(); +} + +gboolean +ComboBoxEntryToolItem::match_selected_cb( GtkEntryCompletion* /*widget*/, GtkTreeModel* model, GtkTreeIter* iter, gpointer data ) +{ + // Get action + auto action = reinterpret_cast<ComboBoxEntryToolItem*>(data); + GtkEntry *entry = action->_entry; + + if( entry) { + gchar *family = nullptr; + gtk_tree_model_get(model, iter, 0, &family, -1); + + // Set text in GtkEntry + gtk_entry_set_text (GTK_ENTRY (entry), family ); + + // Set text in GtkAction + g_free( action->_text ); + action->_text = family; + + // Get row + action->_active = + get_active_row_from_text( action, action->_text ); + + // Set active row + gtk_combo_box_set_active( GTK_COMBO_BOX( action->_combobox), action->_active ); + + // Now let the world know + action->_signal_changed.emit(); + + return true; + } + return false; +} + +void +ComboBoxEntryToolItem::defocus() +{ + if ( _focusWidget ) { + gtk_widget_grab_focus( _focusWidget ); + } +} + +gboolean +ComboBoxEntryToolItem::keypress_cb( GtkWidget * /*widget*/, GdkEventKey *event, gpointer data ) +{ + gboolean wasConsumed = FALSE; /* default to report event not consumed */ + guint key = 0; + auto action = reinterpret_cast<ComboBoxEntryToolItem*>(data); + gdk_keymap_translate_keyboard_state( Gdk::Display::get_default()->get_keymap(), + event->hardware_keycode, (GdkModifierType)event->state, + 0, &key, nullptr, nullptr, nullptr ); + + switch ( key ) { + + // TODO Add bindings for Tab/LeftTab + case GDK_KEY_Escape: + { + //gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), action->private_data->lastVal ); + action->defocus(); + wasConsumed = TRUE; + } + break; + + case GDK_KEY_Return: + case GDK_KEY_KP_Enter: + { + action->defocus(); + //wasConsumed = TRUE; + } + break; + + + } + + return wasConsumed; +} + +} +} +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/combo-box-entry-tool-item.h b/src/ui/widget/combo-box-entry-tool-item.h new file mode 100644 index 000000000..70c8e94e7 --- /dev/null +++ b/src/ui/widget/combo-box-entry-tool-item.h @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * A subclass of GtkAction that wraps a GtkComboBoxEntry. + * Features: + * Setting GtkEntryBox width in characters. + * Passing a function for formatting cells. + * Displaying a warning if text isn't in list. + * Setting names for GtkComboBoxEntry and GtkEntry (actionName_combobox, actionName_entry) + * to allow setting resources. + * + * Author(s): + * Tavmjong Bah + * Jon A. Cruz <jon@joncruz.org> + * + * Copyright (C) 2010 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef SEEN_INK_COMBOBOXENTRY_ACTION +#define SEEN_INK_COMBOBOXENTRY_ACTION + +#include <gtkmm/toolitem.h> + +namespace Inkscape { +namespace UI { +namespace Widget { + +/** + * Creates a Gtk::ToolItem subclass that wraps a Gtk::ComboBox object. + */ +class ComboBoxEntryToolItem : public Gtk::ToolItem { +private: + Glib::ustring _tooltip; + Glib::ustring _label; + GtkTreeModel *_model; ///< Tree Model + GtkComboBox *_combobox; + GtkEntry *_entry; + gint _entry_width;// Width of GtkEntry in characters. + gint _extra_width;// Extra Width of GtkComboBox.. to widen drop-down list in list mode. + gpointer _cell_data_func; // drop-down menu format + gpointer _separator_func; + gboolean _popup; // Do we pop-up an entry-completion dialog? + GtkEntryCompletion *_entry_completion; + GtkWidget *_focusWidget; ///< The widget to return focus to + + GtkWidget *_indicator; + gint _active; // Index of active menu item (-1 if not in list). + gchar *_text; // Text of active menu item or entry box. + gchar *_info; // Text for tooltip info about entry. + gpointer _info_cb; // Callback for clicking info icon. + gint _info_cb_id; + gboolean _info_cb_blocked; + gchar *_warning; // Text for tooltip warning that entry isn't in list. + gpointer _warning_cb; // Callback for clicking warning icon. + gint _warning_cb_id; + gboolean _warning_cb_blocked; + gchar *_altx_name; // Target for Alt-X keyboard shortcut. + + // Signals + sigc::signal<void> _signal_changed; + + void (*changed) (ComboBoxEntryToolItem* action); + void (*activated) (ComboBoxEntryToolItem* action); + + static gint get_active_row_from_text(ComboBoxEntryToolItem *action, + const gchar *target_text, + gboolean exclude = false, + gboolean ignore_case = false); + void defocus(); + + static void combo_box_changed_cb( GtkComboBox* widget, gpointer data ); + static void entry_activate_cb( GtkEntry *widget, + gpointer data ); + static gboolean match_selected_cb( GtkEntryCompletion *widget, + GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data); + static gboolean keypress_cb( GtkWidget *widget, + GdkEventKey *event, + gpointer data ); + + Glib::ustring check_comma_separated_text(); + +public: + ComboBoxEntryToolItem(const Glib::ustring name, + const Glib::ustring label, + const Glib::ustring tooltip, + GtkTreeModel *model, + gint entry_width = -1, + gint extra_width = -1, + gpointer cell_data_func = nullptr, + gpointer separator_func = nullptr, + GtkWidget* focusWidget = nullptr); + + gchar* get_active_text(); + gboolean set_active_text(const gchar* text, int row=-1); + + void set_entry_width(gint entry_width); + void set_extra_width(gint extra_width); + + void popup_enable(); + void popup_disable(); + + void set_info( const gchar* info ); + void set_info_cb( gpointer info_cb ); + void set_warning( const gchar* warning_cb ); + void set_warning_cb(gpointer warning ); + void set_tooltip( const gchar* tooltip ); + + void set_altx_name( const gchar* altx_name ); + + // Accessor methods + decltype(_model) get_model() const {return _model;} + decltype(_combobox) get_combobox() const {return _combobox;} + decltype(_entry) get_entry() const {return _entry;} + decltype(_entry_width) get_entry_width() const {return _entry_width;} + decltype(_extra_width) get_extra_width() const {return _extra_width;} + decltype(_cell_data_func) get_cell_data_func() const {return _cell_data_func;} + decltype(_separator_func) get_separator_func() const {return _separator_func;} + decltype(_popup) get_popup() const {return _popup;} + decltype(_focusWidget) get_focus_widget() const {return _focusWidget;} + + decltype(_active) get_active() const {return _active;} + + decltype(_signal_changed) signal_changed() {return _signal_changed;} + + // Mutator methods + void set_model (decltype(_model) model) {_model = model;} + void set_combobox (decltype(_combobox) combobox) {_combobox = combobox;} + void set_entry (decltype(_entry) entry) {_entry = entry;} + void set_cell_data_func(decltype(_cell_data_func) cell_data_func) {_cell_data_func = cell_data_func;} + void set_separator_func(decltype(_separator_func) separator_func) {_separator_func = separator_func;} + void set_popup (decltype(_popup) popup) {_popup = popup;} + void set_focus_widget (decltype(_focusWidget) focus_widget) {_focusWidget = focus_widget;} + + // This doesn't seem right... surely we should set the active row in the Combobox too? + void set_active (decltype(_active) active) {_active = active;} +}; + +} +} +} +#endif /* SEEN_INK_COMBOBOXENTRY_ACTION */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/combo-tool-item.cpp b/src/ui/widget/combo-tool-item.cpp index a6c44f7eb..b8638ba72 100644 --- a/src/ui/widget/combo-tool-item.cpp +++ b/src/ui/widget/combo-tool-item.cpp @@ -34,15 +34,17 @@ ComboToolItem* ComboToolItem::create(const Glib::ustring &group_label, const Glib::ustring &tooltip, const Glib::ustring &stock_id, - Glib::RefPtr<Gtk::ListStore> store ) + Glib::RefPtr<Gtk::ListStore> store, + bool has_entry) { - return new ComboToolItem(group_label, tooltip, stock_id, store); + return new ComboToolItem(group_label, tooltip, stock_id, store, has_entry); } ComboToolItem::ComboToolItem(Glib::ustring group_label, Glib::ustring tooltip, Glib::ustring stock_id, - Glib::RefPtr<Gtk::ListStore> store ) : + Glib::RefPtr<Gtk::ListStore> store, + bool has_entry) : _group_label(std::move( group_label )), _tooltip(std::move( tooltip )), _stock_id(std::move( stock_id )), @@ -63,9 +65,45 @@ ComboToolItem::ComboToolItem(Glib::ustring group_label, } // Create combobox - _combobox = Gtk::manage (new Gtk::ComboBox()); + _combobox = Gtk::manage (new Gtk::ComboBox(has_entry)); _combobox->set_model(_store); + populate_combobox(); + + _combobox->signal_changed().connect( + sigc::mem_fun(*this, &ComboToolItem::on_changed_combobox)); + + box->add (*_combobox); + + show_all(); +} + +void +ComboToolItem::use_label(bool use_label) +{ + _use_label = use_label; + populate_combobox(); +} + +void +ComboToolItem::use_icon(bool use_icon) +{ + _use_icon = use_icon; + populate_combobox(); +} + +void +ComboToolItem::use_pixbuf(bool use_pixbuf) +{ + _use_pixbuf = use_pixbuf; + populate_combobox(); +} + +void +ComboToolItem::populate_combobox() +{ + _combobox->clear(); + ComboToolItemColumns columns; if (_use_icon) { Gtk::CellRendererPixbuf *renderer = new Gtk::CellRendererPixbuf; @@ -89,13 +127,6 @@ ComboToolItem::ComboToolItem(Glib::ustring group_label, } _combobox->set_active (_active); - - _combobox->signal_changed().connect( - sigc::mem_fun(*this, &ComboToolItem::on_changed_combobox)); - - box->add (*_combobox); - - show_all(); } void diff --git a/src/ui/widget/combo-tool-item.h b/src/ui/widget/combo-tool-item.h index 1e4590163..d2ca874f0 100644 --- a/src/ui/widget/combo-tool-item.h +++ b/src/ui/widget/combo-tool-item.h @@ -54,12 +54,13 @@ public: static ComboToolItem* create(const Glib::ustring &label, const Glib::ustring &tooltip, const Glib::ustring &stock_id, - Glib::RefPtr<Gtk::ListStore> store ); + Glib::RefPtr<Gtk::ListStore> store, + bool has_entry = false); - /* Style of action */ - void use_label( bool use_label ) { _use_label = use_label; } - void use_icon( bool use_icon ) { _use_icon = use_icon; } - void use_pixbuf( bool use_pixbuf ) { _use_pixbuf = use_pixbuf; } + /* Style of combobox */ + void use_label( bool use_label ); + void use_icon( bool use_icon ); + void use_pixbuf( bool use_pixbuf ); void use_group_label( bool use_group_label ) { _use_group_label = use_group_label; } gint get_active() { return _active; } @@ -74,6 +75,7 @@ public: protected: bool on_create_menu_proxy() override; + void populate_combobox(); /* Signals */ sigc::signal<void, int> _changed; @@ -108,7 +110,8 @@ private: ComboToolItem(Glib::ustring group_label, Glib::ustring tooltip, Glib::ustring stock_id, - Glib::RefPtr<Gtk::ListStore> store ); + Glib::RefPtr<Gtk::ListStore> store, + bool has_entry = false); }; } } diff --git a/src/ui/widget/ink-select-one-action.cpp b/src/ui/widget/ink-select-one-action.cpp deleted file mode 100644 index 95f38b511..000000000 --- a/src/ui/widget/ink-select-one-action.cpp +++ /dev/null @@ -1,269 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Authors: - * Tavmjong Bah <tavmjong@free.fr> - * - * Copyright (C) 2017 Tavmjong Bah - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - - -/** \file - An action (menu/toolbar item) that allows selecting one choice out of many. - - The choices may be displayed as: - - 1. A group of items in a toolbar with labels and/or icons. - 2. As a drop-down menu with a labels and/or icons. -*/ - -#include "ink-select-one-action.h" - -#include <iostream> -#include <utility> -#include <gtkmm/toolitem.h> -#include <gtkmm/menuitem.h> -#include <gtkmm/radioaction.h> -#include <gtkmm/radiomenuitem.h> -#include <gtkmm/combobox.h> -#include <gtkmm/menu.h> -#include <gtkmm/box.h> -#include <gtkmm/label.h> -#include <gtkmm/image.h> - -InkSelectOneAction* InkSelectOneAction::create(const Glib::ustring &name, - const Glib::ustring &group_label, - const Glib::ustring &tooltip, - const Glib::ustring &stock_id, - Glib::RefPtr<Gtk::ListStore> store ) { - - return new InkSelectOneAction(name, group_label, tooltip, stock_id, store); -} - -InkSelectOneAction::InkSelectOneAction (const Glib::ustring &name, - const Glib::ustring &group_label, - const Glib::ustring &tooltip, - const Glib::ustring &stock_id, - Glib::RefPtr<Gtk::ListStore> store ) : - Gtk::Action(name, stock_id, group_label, tooltip), - _name( name ), - _group_label( group_label ), - _tooltip( tooltip ), - _stock_id( stock_id ), - _store (std::move(store)), - _use_radio (true), - _use_label (true), - _use_icon (true), - _use_pixbuf (false), - _icon_size ( Gtk::ICON_SIZE_LARGE_TOOLBAR ), - _combobox (nullptr), - _radioaction (nullptr), - _menuitem (nullptr) -{ -} - -void InkSelectOneAction::set_active (gint active) { - - if (active < 0) { - std::cerr << "InkSelectOneAction::set_active: active < 0: " << active << std::endl; - return; - } - - if (_active != active) { - - _active = active; - - if (_combobox) { - _combobox->set_active (active); - } - - if (_radioaction) { - _radioaction->set_current_value (active); - } - - if (active < _radiomenuitems.size()) { - _radiomenuitems[ active ]->set_active(); - } - } -} - -Glib::ustring InkSelectOneAction::get_active_text () { - Gtk::TreeModel::Row row = _store->children()[_active]; - InkSelectOneActionColumns columns; - Glib::ustring label = row[columns.col_label]; - return label; -} - -Gtk::Widget* InkSelectOneAction::create_menu_item_vfunc() { - - if (_menuitem == nullptr) { - - _menuitem = Gtk::manage (new Gtk::MenuItem); - Gtk::Menu *menu = Gtk::manage (new Gtk::Menu); - - Gtk::RadioButton::Group group; - int index = 0; - auto children = _store->children(); - for (auto row : children) { - InkSelectOneActionColumns columns; - Glib::ustring label = row[columns.col_label ]; - Glib::ustring icon = row[columns.col_icon ]; - Glib::ustring tooltip = row[columns.col_tooltip ]; - bool sensitive = row[columns.col_sensitive ]; - - Gtk::RadioMenuItem* button = Gtk::manage(new Gtk::RadioMenuItem(group)); - button->set_label (label); - button->set_tooltip_text( tooltip ); - button->set_sensitive( sensitive ); - - button->signal_toggled().connect( sigc::bind<0>( - sigc::mem_fun(*this, &InkSelectOneAction::on_toggled_radiomenu), index++) - ); - - menu->add (*button); - - _radiomenuitems.push_back( button ); - } - - if ( _active < _radiomenuitems.size()) { - _radiomenuitems[ _active ]->set_active(); - } - - _menuitem->set_submenu (*menu); - _menuitem->show_all(); - } - - return _menuitem; -} - - -Gtk::Widget* InkSelectOneAction::create_tool_item_vfunc() { - // Either a group of radio actions or a combobox with labels and/or icons. - - Gtk::ToolItem *tool_item = new Gtk::ToolItem; - - Gtk::Box* box = Gtk::manage(new Gtk::Box()); - tool_item->add (*box); - - if (_use_group_label) { - Gtk::Label *group_label = Gtk::manage (new Gtk::Label( _group_label + ": " )); - box->add( *group_label ); - } - - if (_use_radio) { - // Create radio actions (note: these are not radio buttons). - - Gtk::RadioAction::Group group; - int index = 0; - auto children = _store->children(); - for (auto row : children) { - InkSelectOneActionColumns columns; - Glib::ustring label = row[columns.col_label ]; - Glib::ustring icon = row[columns.col_icon ]; - Glib::ustring tooltip = row[columns.col_tooltip ]; - bool sensitive = row[columns.col_sensitive]; - Glib::RefPtr<Gtk::RadioAction> action; - if (_use_icon) { - action = - Gtk::RadioAction::create_with_icon_name (group, "Anonymous", icon, label, tooltip); - } else { - action = - Gtk::RadioAction::create (group, "Anonymous", label, tooltip); - } - action->set_property( "value", index++ ); // To identify uniquely each radioaction. - action->set_sensitive( sensitive ); - - // Save first action for use in setting/getting active value. - if (!_radioaction) { - _radioaction = action; - } - - Gtk::ToolItem* item = action->create_tool_item(); - box->add (*item); - } - - if (_radioaction) { - _radioaction->set_current_value (_active); - } - - _radioaction->signal_changed().connect( sigc::mem_fun(*this, &InkSelectOneAction::on_changed_radioaction)); - - } else { - // Create combobox - - _combobox = Gtk::manage (new Gtk::ComboBox()); - _combobox->set_model(_store); - - InkSelectOneActionColumns columns; - if (_use_icon) { - Gtk::CellRendererPixbuf *renderer = new Gtk::CellRendererPixbuf; - renderer->set_property ("stock_size", Gtk::ICON_SIZE_LARGE_TOOLBAR); - _combobox->pack_start (*renderer, false); - _combobox->add_attribute (*renderer, "icon_name", columns.col_icon ); - } else if (_use_pixbuf) { - Gtk::CellRendererPixbuf *renderer = new Gtk::CellRendererPixbuf; - //renderer->set_property ("stock_size", Gtk::ICON_SIZE_LARGE_TOOLBAR); - _combobox->pack_start (*renderer, false); - _combobox->add_attribute (*renderer, "pixbuf", columns.col_pixbuf ); - } - - if (_use_label) { - _combobox->pack_start(columns.col_label); - } - - std::vector<Gtk::CellRenderer*> cells = _combobox->get_cells(); - for (auto & cell : cells) { - _combobox->add_attribute (*cell, "sensitive", columns.col_sensitive); - } - - _combobox->set_active (_active); - - _combobox->signal_changed().connect( - sigc::mem_fun(*this, &InkSelectOneAction::on_changed_combobox)); - - box->add (*_combobox); - } - - tool_item->show_all(); - - return tool_item; -} - -void InkSelectOneAction::on_changed_combobox() { - - int row = _combobox->get_active_row_number(); - if (row < 0) row = 0; // Happens when Gtk::ListStore reconstructed - set_active( row ); - _changed.emit (_active); - _changed_after.emit (_active); -} - -void InkSelectOneAction::on_changed_radioaction(const Glib::RefPtr<Gtk::RadioAction>& current) { - - set_active( current->get_current_value() ); - _changed.emit (_active); - _changed_after.emit (_active); -} - -void InkSelectOneAction::on_toggled_radiomenu(int n) { - - // toggled emitted twice, first for button toggled off, second for button toggled on. - // We want to react only to the button turned on. - if ( n < _radiomenuitems.size() &&_radiomenuitems[ n ]->get_active()) { - set_active ( n ); - _changed.emit (_active); - _changed_after.emit (_active); - } -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/ink-select-one-action.h b/src/ui/widget/ink-select-one-action.h deleted file mode 100644 index efe249da8..000000000 --- a/src/ui/widget/ink-select-one-action.h +++ /dev/null @@ -1,143 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef SEEN_INK_SELECT_ONE_ACTION -#define SEEN_INK_SELECT_ONE_ACTION - -/* - * Authors: - * Tavmjong Bah <tavmjong@free.fr> - * - * Copyright (C) 2017 Tavmjong Bah - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -/** - An action (menu/toolbar item) that allows selecting one choice out of many. - - The choices may be displayed as: - - 1. A group of items in a toolbar with labels and/or icons. - 2. As a drop-down menu with a labels and/or icons. -*/ - -#include <gtkmm/action.h> -#include <gtkmm/liststore.h> -#include <sigc++/sigc++.h> -#include <vector> - -namespace Gtk { -class ComboBox; -class RadioAction; -class MenuItem; -class RadioMenuItem; -} - -class InkSelectOneActionColumns : public Gtk::TreeModel::ColumnRecord { - -public: - InkSelectOneActionColumns() { - add (col_label); - add (col_icon); - add (col_pixbuf); - add (col_data); // Used to store a pointer - add (col_tooltip); - add (col_sensitive); - } - Gtk::TreeModelColumn<Glib::ustring> col_label; - Gtk::TreeModelColumn<Glib::ustring> col_icon; - Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > col_pixbuf; - Gtk::TreeModelColumn<void *> col_data; - Gtk::TreeModelColumn<Glib::ustring> col_tooltip; - Gtk::TreeModelColumn<bool> col_sensitive; -}; - - -class InkSelectOneAction : public Gtk::Action { - -public: - - static InkSelectOneAction* create(const Glib::ustring &name, - const Glib::ustring &label, - const Glib::ustring &tooltip, - const Glib::ustring &stock_id, - Glib::RefPtr<Gtk::ListStore> store ); - - /* Style of action */ - void use_radio( bool use_radio ) { _use_radio = use_radio; } - void use_label( bool use_label ) { _use_label = use_label; } - void use_icon( bool use_icon ) { _use_icon = use_icon; } - void use_pixbuf( bool use_pixbuf ) { _use_pixbuf = use_pixbuf; } - void use_group_label( bool use_group_label ) { _use_group_label = use_group_label; } - - gint get_active() { return _active; } - Glib::ustring get_active_text(); - void set_active( gint active ); - void set_icon_size( Gtk::BuiltinIconSize size ) { _icon_size = size; } - - Glib::RefPtr<Gtk::ListStore> get_store() { return _store; } - - sigc::signal<void, int> signal_changed() { return _changed; } - sigc::signal<void, int> signal_changed_after() { return _changed_after; } - -protected: - - Gtk::Widget* create_menu_item_vfunc() override; - Gtk::Widget* create_tool_item_vfunc() override; - - /* Signals */ - sigc::signal<void, int> _changed; - sigc::signal<void, int> _changed_after; // Needed for unit tracker which eats _changed. - -private: - - Glib::ustring _name; - Glib::ustring _group_label; - Glib::ustring _tooltip; - Glib::ustring _stock_id; - Glib::RefPtr<Gtk::ListStore> _store; - - gint _active; /* Active menu item/button */ - - /* Style */ - bool _use_radio; // Applies to tool item only - bool _use_label; - bool _use_icon; // Applies to menu item only - bool _use_pixbuf; - bool _use_group_label; // Applies to tool item only - Gtk::BuiltinIconSize _icon_size; - - /* Combobox in tool */ - Gtk::ComboBox* _combobox; - - /* Need to track one action to get active action. */ - Glib::RefPtr<Gtk::RadioAction> _radioaction; - - Gtk::MenuItem* _menuitem; - std::vector<Gtk::RadioMenuItem*> _radiomenuitems; - - /* Internal Callbacks */ - void on_changed_combobox(); - void on_changed_radioaction(const Glib::RefPtr<Gtk::RadioAction>& current); - void on_toggled_radiomenu(int n); - - InkSelectOneAction (const Glib::ustring &name, - const Glib::ustring &group_label, - const Glib::ustring &tooltip, - const Glib::ustring &stock_id, - Glib::RefPtr<Gtk::ListStore> store ); - -}; - - -#endif /* SEEN_INK_SELECT_ONE_ACTION */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/spin-button-tool-item.cpp b/src/ui/widget/spin-button-tool-item.cpp index f8c285344..e190d8dd2 100644 --- a/src/ui/widget/spin-button-tool-item.cpp +++ b/src/ui/widget/spin-button-tool-item.cpp @@ -3,6 +3,7 @@ #include "spin-button-tool-item.h" #include <gtkmm/box.h> +#include <gtkmm/image.h> #include <gtkmm/radiomenuitem.h> #include <gtkmm/toolbar.h> @@ -390,14 +391,28 @@ SpinButtonToolItem::SpinButtonToolItem(const Glib::ustring name, _btn->add_events(Gdk::KEY_PRESS_MASK); // Create a label - auto label = Gtk::manage(new Gtk::Label(label_text)); + _label = Gtk::manage(new Gtk::Label(label_text)); // Arrange the widgets in a horizontal box - auto hbox = Gtk::manage(new Gtk::Box()); - hbox->set_spacing(3); - hbox->pack_start(*label); - hbox->pack_start(*_btn); - add(*hbox); + _hbox = Gtk::manage(new Gtk::Box()); + _hbox->set_spacing(3); + _hbox->pack_start(*_label); + _hbox->pack_start(*_btn); + add(*_hbox); + show_all(); +} + +void +SpinButtonToolItem::set_icon(const Glib::ustring& icon_name) +{ + _hbox->remove(*_label); + _icon = Gtk::manage(new Gtk::Image(icon_name, Gtk::ICON_SIZE_SMALL_TOOLBAR)); + + if(_icon) { + _hbox->pack_start(*_icon); + _hbox->reorder_child(*_icon, 0); + } + show_all(); } diff --git a/src/ui/widget/spin-button-tool-item.h b/src/ui/widget/spin-button-tool-item.h index 1b33e8580..4386d4799 100644 --- a/src/ui/widget/spin-button-tool-item.h +++ b/src/ui/widget/spin-button-tool-item.h @@ -5,6 +5,7 @@ #include <gtkmm/toolitem.h> namespace Gtk { +class Box; class RadioButtonGroup; class RadioMenuItem; } @@ -29,6 +30,10 @@ private: double _last_val; ///< The last value of the adjustment bool _transfer_focus; ///< Whether or not to transfer focus + Gtk::Box *_hbox; ///< Horizontal box, to store widgets + Gtk::Widget *_label; ///< A text label to describe the setting + Gtk::Widget *_icon; ///< An icon to describe the setting + /** A widget that grabs focus when this one loses it */ Gtk::Widget * _focus_widget; @@ -72,6 +77,7 @@ public: void set_custom_numeric_menu_data(std::vector<double>& values, const std::vector<Glib::ustring>& labels = std::vector<Glib::ustring>()); Glib::RefPtr<Gtk::Adjustment> get_adjustment(); + void set_icon(const Glib::ustring& icon_name); }; } // namespace Widget } // namespace UI diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index 4abfaa9c8..0bdd3210a 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -19,7 +19,6 @@ #include "unit-tracker.h" -#include "ink-select-one-action.h" #include "combo-tool-item.h" #define COLUMN_STRING 0 @@ -41,7 +40,7 @@ UnitTracker::UnitTracker(UnitType unit_type) : { UnitTable::UnitMap m = unit_table.units(unit_type); - InkSelectOneActionColumns columns; + ComboToolItemColumns columns; _store = Gtk::ListStore::create(columns); Gtk::TreeModel::Row row; @@ -67,7 +66,6 @@ UnitTracker::UnitTracker(UnitType unit_type) : UnitTracker::~UnitTracker() { - _actionList.clear(); _combo_list.clear(); // Unhook weak references to GtkAdjustments @@ -91,7 +89,7 @@ void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit) { if (unit) { - InkSelectOneActionColumns columns; + ComboToolItemColumns columns; int index = 0; for (auto& row: _store->children() ) { Glib::ustring storedUnit = row[columns.col_label]; @@ -122,7 +120,7 @@ void UnitTracker::addAdjustment(GtkAdjustment *adj) void UnitTracker::addUnit(Inkscape::Util::Unit const *u) { - InkSelectOneActionColumns columns; + ComboToolItemColumns columns; Gtk::TreeModel::Row row; row = *(_store->append()); @@ -134,7 +132,7 @@ void UnitTracker::addUnit(Inkscape::Util::Unit const *u) void UnitTracker::prependUnit(Inkscape::Util::Unit const *u) { - InkSelectOneActionColumns columns; + ComboToolItemColumns columns; Gtk::TreeModel::Row row; row = *(_store->prepend()); @@ -153,28 +151,6 @@ void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val) _priorValues[adj] = val; } -/** - * \deprecated Use create_tool_item instead - */ -InkSelectOneAction *UnitTracker::createAction(Glib::ustring const &name, - Glib::ustring const &label, - Glib::ustring const &tooltip) -{ - InkSelectOneAction* act = - InkSelectOneAction::create( name, label, tooltip, "NotUsed", _store); - - act->use_radio( false ); - act->use_label( true ); - act->use_icon( false ); - act->use_group_label( false ); - act->set_active( _active ); - - act->signal_changed().connect(sigc::mem_fun(*this, &UnitTracker::_unitChangedCB)); - _actionList.push_back(act); - - return act; -} - ComboToolItem * UnitTracker::create_tool_item(Glib::ustring const &label, Glib::ustring const &tooltip) @@ -192,14 +168,6 @@ void UnitTracker::_unitChangedCB(int active) _setActive(active); } -void UnitTracker::_actionFinalizedCB(gpointer data, GObject *where_the_object_was) -{ - if (data && where_the_object_was) { - UnitTracker *self = reinterpret_cast<UnitTracker *>(data); - self->_actionFinalized(where_the_object_was); - } -} - void UnitTracker::_adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was) { if (data && where_the_object_was) { @@ -208,17 +176,6 @@ void UnitTracker::_adjustmentFinalizedCB(gpointer data, GObject *where_the_objec } } -void UnitTracker::_actionFinalized(GObject *where_the_object_was) -{ - InkSelectOneAction* act = (InkSelectOneAction*)(where_the_object_was); - auto it = std::find(_actionList.begin(),_actionList.end(), act); - if (it != _actionList.end()) { - _actionList.erase(it); - } else { - g_warning("Received a finalization callback for unknown object %p", where_the_object_was); - } -} - void UnitTracker::_adjustmentFinalized(GObject *where_the_object_was) { GtkAdjustment* adj = (GtkAdjustment*)(where_the_object_was); @@ -238,7 +195,7 @@ void UnitTracker::_setActive(gint active) if (_store) { // Find old and new units - InkSelectOneActionColumns columns; + ComboToolItemColumns columns; int index = 0; Glib::ustring oldAbbr( "NotFound" ); Glib::ustring newAbbr( "NotFound" ); @@ -274,10 +231,6 @@ void UnitTracker::_setActive(gint active) } _active = active; - for (auto act: _actionList) { - act->set_active (active); - } - for (auto combo : _combo_list) { if(combo) combo->set_active(active); } diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h index c876d8224..1f16292ff 100644 --- a/src/ui/widget/unit-tracker.h +++ b/src/ui/widget/unit-tracker.h @@ -20,17 +20,13 @@ #include <vector> #include <gtkmm/liststore.h> -#include <gtkmm/action.h> #include "util/units.h" -class InkSelectOneAction; - using Inkscape::Util::Unit; using Inkscape::Util::UnitType; typedef struct _GObject GObject; -typedef struct _GtkAction GtkAction; typedef struct _GtkAdjustment GtkAdjustment; typedef struct _GtkListStore GtkListStore; @@ -55,10 +51,6 @@ public: void prependUnit(Inkscape::Util::Unit const *u); void setFullVal(GtkAdjustment *adj, gdouble val); - InkSelectOneAction *createAction(Glib::ustring const &name, - Glib::ustring const &label, - Glib::ustring const &tooltip); - ComboToolItem *create_tool_item(Glib::ustring const &label, Glib::ustring const &tooltip); @@ -68,14 +60,12 @@ protected: private: // Callbacks void _unitChangedCB(int active); - static void _actionFinalizedCB(gpointer data, GObject *where_the_object_was); static void _adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was); void _setActive(gint index); void _fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit); // Cleanup - void _actionFinalized(GObject *where_the_object_was); void _adjustmentFinalized(GObject *where_the_object_was); gint _active; @@ -84,7 +74,6 @@ private: bool _activeUnitInitialized; Glib::RefPtr<Gtk::ListStore> _store; - std::vector<InkSelectOneAction*> _actionList; std::vector<ComboToolItem *> _combo_list; std::vector<GtkAdjustment*> _adjList; std::map <GtkAdjustment *, gdouble> _priorValues; |
