diff options
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/widgets/desktop-widget.cpp | 26 | ||||
| -rw-r--r-- | src/widgets/desktop-widget.h | 5 | ||||
| -rw-r--r-- | src/widgets/ege-adjustment-action.cpp | 1130 | ||||
| -rw-r--r-- | src/widgets/ege-adjustment-action.h | 189 | ||||
| -rw-r--r-- | src/widgets/ink-comboboxentry-action.cpp | 964 | ||||
| -rw-r--r-- | src/widgets/ink-comboboxentry-action.h | 107 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 265 | ||||
| -rw-r--r-- | src/widgets/toolbox.h | 14 |
9 files changed, 70 insertions, 2634 deletions
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index c6dad3f1a..4c0617167 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -3,14 +3,12 @@ add_subdirectory(gimp) set(widgets_SRC desktop-widget.cpp - ege-adjustment-action.cpp ege-paint-def.cpp fill-style.cpp gradient-image.cpp gradient-selector.cpp gradient-vector.cpp ink-action.cpp - ink-comboboxentry-action.cpp ink-toggle-action.cpp paint-selector.cpp sp-attribute-widget.cpp @@ -26,7 +24,6 @@ set(widgets_SRC # ------- # Headers desktop-widget.h - ege-adjustment-action.h ege-paint-def.h fill-n-stroke-factory.h fill-style.h @@ -34,7 +31,6 @@ set(widgets_SRC gradient-selector.h gradient-vector.h ink-action.h - ink-comboboxentry-action.h ink-toggle-action.h paint-selector.h sp-attribute-widget.h diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index e94448e2c..8bf236972 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -60,7 +60,6 @@ #include "ui/uxmanager.h" #include "ui/widget/button.h" #include "ui/widget/dock.h" -#include "ui/widget/ink-select-one-action.h" #include "ui/widget/layer-selector.h" #include "ui/widget/selected-style.h" #include "ui/widget/spin-button-tool-item.h" @@ -1527,6 +1526,22 @@ void SPDesktopWidget::layoutWidgets() } } +Gtk::Toolbar * +SPDesktopWidget::get_toolbar_by_name(const Glib::ustring& name) +{ + // The name is actually attached to the GtkGrid that contains + // the toolbar, so we need to get the grid first + auto widget = sp_search_by_name_recursive(Glib::wrap(aux_toolbox), name); + auto grid = dynamic_cast<Gtk::Grid*>(widget); + + if (!grid) return nullptr; + + auto child = grid->get_child_at(0,0); + auto tb = dynamic_cast<Gtk::Toolbar*>(child); + + return tb; +} + void SPDesktopWidget::setToolboxFocusTo (const gchar* label) { @@ -1565,15 +1580,6 @@ SPDesktopWidget::setToolboxAdjustmentValue (gchar const *id, double value) else g_warning ("Could not find GtkAdjustment for %s\n", id); } -void -SPDesktopWidget::setToolboxSelectOneValue (gchar const *id, int value) -{ - gpointer hb = sp_search_by_data_recursive(aux_toolbox, (gpointer) id); - if (static_cast<InkSelectOneAction*>(hb)) { - static_cast<InkSelectOneAction*>(hb)->set_active( value ); - } -} - bool SPDesktopWidget::isToolboxButtonActive (const gchar* id) diff --git a/src/widgets/desktop-widget.h b/src/widgets/desktop-widget.h index d21ba7bb8..59c031120 100644 --- a/src/widgets/desktop-widget.h +++ b/src/widgets/desktop-widget.h @@ -218,11 +218,10 @@ public: void updateZoom() override { _dtw->update_zoom(); } void letZoomGrabFocus() override { _dtw->letZoomGrabFocus(); } void updateRotation() override { _dtw->update_rotation(); } + Gtk::Toolbar* get_toolbar_by_name(const Glib::ustring& name) override {return _dtw->get_toolbar_by_name(name);} void setToolboxFocusTo(const gchar *id) override { _dtw->setToolboxFocusTo(id); } void setToolboxAdjustmentValue(const gchar *id, double val) override { _dtw->setToolboxAdjustmentValue (id, val); } - void setToolboxSelectOneValue (gchar const *id, int val) override - { _dtw->setToolboxSelectOneValue (id, val); } bool isToolboxButtonActive (gchar const* id) override { return _dtw->isToolboxButtonActive (id); } void setCoordinateStatus (Geom::Point p) override @@ -255,9 +254,9 @@ public: void presentWindow(); bool showInfoDialog( Glib::ustring const &message ); bool warnDialog (Glib::ustring const &text); + Gtk::Toolbar* get_toolbar_by_name(const Glib::ustring& name); void setToolboxFocusTo (gchar const *); void setToolboxAdjustmentValue (gchar const * id, double value); - void setToolboxSelectOneValue (gchar const * id, gint value); bool isToolboxButtonActive (gchar const *id); void setToolboxPosition(Glib::ustring const& id, GtkPositionType pos); void setCoordinateStatus(Geom::Point p); diff --git a/src/widgets/ege-adjustment-action.cpp b/src/widgets/ege-adjustment-action.cpp deleted file mode 100644 index 49280bcd3..000000000 --- a/src/widgets/ege-adjustment-action.cpp +++ /dev/null @@ -1,1130 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later OR MPL-1.1 OR LGPL-2.1-or-later -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is EGE Adjustment Action. - * - * The Initial Developer of the Original Code is - * Jon A. Cruz. - * Portions created by the Initial Developer are Copyright (C) 2006 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* Note: this file should be kept compilable as both .cpp and .c */ - -#include <cmath> -#include <cstring> -#include <vector> -#include <algorithm> - -#include <gtkmm/container.h> -#include <gtkmm/radiomenuitem.h> -#include <gtkmm/adjustment.h> -#include <gdk/gdkkeysyms.h> -#include <gdkmm/display.h> - -#include "ui/icon-loader.h" -#include "ui/icon-names.h" -#include "ui/widget/ink-spinscale.h" -#include "widgets/ege-adjustment-action.h" - -static void ege_adjustment_action_finalize( GObject* object ); -static void ege_adjustment_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); -static void ege_adjustment_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); - -static GtkWidget* create_menu_item( GtkAction* action ); -static GtkWidget* create_tool_item( GtkAction* action ); -static void connect_proxy( GtkAction *action, GtkWidget *proxy ); -static void disconnect_proxy( GtkAction *action, GtkWidget *proxy ); - -static gboolean focus_in_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ); -static gboolean focus_out_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ); -static gboolean keypress_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ); - -static void ege_adjustment_action_defocus( EgeAdjustmentAction* action ); - -static void egeAct_free_description( gpointer data, gpointer user_data ); -static void egeAct_free_all_descriptions( EgeAdjustmentAction* action ); - -static EgeCreateAdjWidgetCB gFactoryCb = nullptr; -static GQuark gDataName = 0; - -enum { - APPEARANCE_UNKNOWN = -1, - APPEARANCE_NONE = 0, - APPEARANCE_FULL, /* label, then all choices represented by separate buttons */ - APPEARANCE_COMPACT, /* label, then choices in a drop-down menu */ - APPEARANCE_MINIMAL, /* no label, just choices in a drop-down menu */ -}; - -/* TODO need to have appropriate icons setup for these: */ -static const gchar *floogles[] = { - INKSCAPE_ICON("list-remove"), - INKSCAPE_ICON("list-add"), - INKSCAPE_ICON("go-down"), - INKSCAPE_ICON("help-about"), - INKSCAPE_ICON("go-up"), - nullptr}; - -typedef struct _EgeAdjustmentDescr EgeAdjustmentDescr; - -struct _EgeAdjustmentDescr -{ - gchar* descr; - gdouble value; -}; - -typedef struct { - GtkAdjustment* adj; - GtkWidget* focusWidget; - gdouble climbRate; - guint digits; - gdouble epsilon; - gchar* format; - gchar* selfId; - EgeWidgetFixup toolPost; - gdouble lastVal; - gdouble step; - gdouble page; - gint appearanceMode; - gboolean transferFocus; - std::vector<EgeAdjustmentDescr*> descriptions; - gchar* appearance; - gchar* iconId; - GtkIconSize iconSize; - Inkscape::UI::Widget::UnitTracker *unitTracker; -} EgeAdjustmentActionPrivate; - -#define EGE_ADJUSTMENT_ACTION_GET_PRIVATE(o) \ - reinterpret_cast<EgeAdjustmentActionPrivate *>( ege_adjustment_action_get_instance_private (o)) - -enum { - PROP_ADJUSTMENT = 1, - PROP_FOCUS_WIDGET, - PROP_CLIMB_RATE, - PROP_DIGITS, - PROP_SELFID, - PROP_TOOL_POST, - PROP_APPEARANCE, - PROP_ICON_ID, - PROP_ICON_SIZE, - PROP_UNIT_TRACKER -}; - -enum { - BUMP_TOP = 0, - BUMP_PAGE_UP, - BUMP_UP, - BUMP_NONE, - BUMP_DOWN, - BUMP_PAGE_DOWN, - BUMP_BOTTOM, - BUMP_CUSTOM = 100 -}; - -G_DEFINE_TYPE_WITH_PRIVATE(EgeAdjustmentAction, ege_adjustment_action, GTK_TYPE_ACTION); - -static void ege_adjustment_action_class_init( EgeAdjustmentActionClass* klass ) -{ - if ( klass ) { - GObjectClass * objClass = G_OBJECT_CLASS( klass ); - - gDataName = g_quark_from_string("ege-adj-action"); - - - objClass->finalize = ege_adjustment_action_finalize; - - objClass->get_property = ege_adjustment_action_get_property; - objClass->set_property = ege_adjustment_action_set_property; - - klass->parent_class.create_menu_item = create_menu_item; - klass->parent_class.create_tool_item = create_tool_item; - klass->parent_class.connect_proxy = connect_proxy; - klass->parent_class.disconnect_proxy = disconnect_proxy; - - g_object_class_install_property( objClass, - PROP_ADJUSTMENT, - g_param_spec_object( "adjustment", - "Adjustment", - "The adjustment to change", - GTK_TYPE_ADJUSTMENT, - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_FOCUS_WIDGET, - g_param_spec_pointer( "focus-widget", - "Focus Widget", - "The widget to return focus to", - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_CLIMB_RATE, - g_param_spec_double( "climb-rate", - "Climb Rate", - "The acelleraton rate", - 0.0, G_MAXDOUBLE, 0.0, - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_DIGITS, - g_param_spec_uint( "digits", - "Digits", - "The number of digits to show", - 0, 20, 0, - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_SELFID, - g_param_spec_string( "self-id", - "Self ID", - "Marker for self pointer", - nullptr, - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_TOOL_POST, - g_param_spec_pointer( "tool-post", - "Tool Widget post process", - "Function for final adjustments", - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_APPEARANCE, - g_param_spec_string( "appearance", - "Appearance hint", - "A hint for how to display", - "", - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_ICON_ID, - g_param_spec_string( "iconId", - "Icon ID", - "The id for the icon", - "", - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_ICON_SIZE, - g_param_spec_int( "iconSize", - "Icon Size", - "The size the icon", - (int)GTK_ICON_SIZE_MENU, - (int)GTK_ICON_SIZE_DIALOG, - (int)GTK_ICON_SIZE_SMALL_TOOLBAR, - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_UNIT_TRACKER, - g_param_spec_pointer( "unit_tracker", - "Unit Tracker", - "The widget that keeps track of the unit", - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - } -} - -void ege_adjustment_action_set_compact_tool_factory( EgeCreateAdjWidgetCB factoryCb ) -{ - gFactoryCb = factoryCb; -} - -static void ege_adjustment_action_init( EgeAdjustmentAction* action ) -{ - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE( action ); - priv->adj = nullptr; - priv->focusWidget = nullptr; - priv->climbRate = 0.0; - priv->digits = 2; - priv->epsilon = 0.009; - priv->format = g_strdup_printf("%%0.%df%%s%%s", priv->digits); - priv->selfId = nullptr; - priv->toolPost = nullptr; - priv->lastVal = 0.0; - priv->step = 0.0; - priv->page = 0.0; - priv->appearanceMode = APPEARANCE_NONE; - priv->transferFocus = FALSE; - //priv->descriptions = 0; - priv->appearance = nullptr; - priv->iconId = nullptr; - priv->iconSize = GTK_ICON_SIZE_SMALL_TOOLBAR; - priv->unitTracker = nullptr; -} - -static void ege_adjustment_action_finalize( GObject* object ) -{ - EgeAdjustmentAction* action = nullptr; - g_return_if_fail( object != nullptr ); - g_return_if_fail( IS_EGE_ADJUSTMENT_ACTION(object) ); - - action = EGE_ADJUSTMENT_ACTION( object ); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - - // g_free(NULL) does nothing - g_free( priv->format ); - g_free( priv->selfId ); - g_free( priv->appearance ); - g_free( priv->iconId ); - - egeAct_free_all_descriptions( action ); - - if ( G_OBJECT_CLASS(ege_adjustment_action_parent_class)->finalize ) { - (*G_OBJECT_CLASS(ege_adjustment_action_parent_class)->finalize)(object); - } -} - -EgeAdjustmentAction* ege_adjustment_action_new( GtkAdjustment* adjustment, - const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *stock_id, - gdouble climb_rate, - guint digits, - Inkscape::UI::Widget::UnitTracker *unit_tracker ) -{ - GObject* obj = (GObject*)g_object_new( EGE_ADJUSTMENT_ACTION_TYPE, - "name", name, - "label", label, - "tooltip", tooltip, - "stock_id", stock_id, - "adjustment", adjustment, - "climb-rate", climb_rate, - "digits", digits, - "unit_tracker", unit_tracker, - NULL ); - - EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( obj ); - - return action; -} - -static void ege_adjustment_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ) -{ - EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( obj ); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - switch ( propId ) { - case PROP_ADJUSTMENT: - g_value_set_object( value, priv->adj ); - break; - - case PROP_FOCUS_WIDGET: - g_value_set_pointer( value, priv->focusWidget ); - break; - - case PROP_CLIMB_RATE: - g_value_set_double( value, priv->climbRate ); - break; - - case PROP_DIGITS: - g_value_set_uint( value, priv->digits ); - break; - - case PROP_SELFID: - g_value_set_string( value, priv->selfId ); - break; - - case PROP_TOOL_POST: - g_value_set_pointer( value, (void*)priv->toolPost ); - break; - - case PROP_APPEARANCE: - g_value_set_string( value, priv->appearance ); - break; - - case PROP_ICON_ID: - g_value_set_string( value, priv->iconId ); - break; - - case PROP_ICON_SIZE: - g_value_set_int( value, priv->iconSize ); - break; - - case PROP_UNIT_TRACKER: - g_value_set_pointer( value, priv->unitTracker ); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); - } -} - -void ege_adjustment_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ) -{ - EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( obj ); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - switch ( propId ) { - case PROP_ADJUSTMENT: - { - priv->adj = GTK_ADJUSTMENT( g_value_get_object( value ) ); - g_object_get( G_OBJECT(priv->adj), - "step-increment", &priv->step, - "page-increment", &priv->page, - NULL ); - } - break; - - case PROP_FOCUS_WIDGET: - { - /* TODO unhook prior */ - priv->focusWidget = (GtkWidget*)g_value_get_pointer( value ); - } - break; - - case PROP_CLIMB_RATE: - { - /* TODO pass on */ - priv->climbRate = g_value_get_double( value ); - } - break; - - case PROP_DIGITS: - { - /* TODO pass on */ - priv->digits = g_value_get_uint( value ); - switch ( priv->digits ) { - case 0: priv->epsilon = 0.9; break; - case 1: priv->epsilon = 0.09; break; - case 2: priv->epsilon = 0.009; break; - case 3: priv->epsilon = 0.0009; break; - case 4: priv->epsilon = 0.00009; break; - } - if ( priv->format ) { - g_free( priv->format ); - } - priv->format = g_strdup_printf("%%0.%df%%s%%s", priv->digits); - } - break; - - case PROP_SELFID: - { - /* TODO pass on */ - gchar* prior = priv->selfId; - priv->selfId = g_value_dup_string( value ); - g_free( prior ); - } - break; - - case PROP_TOOL_POST: - { - priv->toolPost = (EgeWidgetFixup)g_value_get_pointer( value ); - } - break; - - case PROP_APPEARANCE: - { - gchar* tmp = priv->appearance; - gchar* newVal = g_value_dup_string( value ); - priv->appearance = newVal; - g_free( tmp ); - - if ( !priv->appearance || (strcmp("", newVal) == 0) ) { - priv->appearanceMode = APPEARANCE_NONE; - } else if ( strcmp("full", newVal) == 0 ) { - priv->appearanceMode = APPEARANCE_FULL; - } else if ( strcmp("compact", newVal) == 0 ) { - priv->appearanceMode = APPEARANCE_COMPACT; - } else if ( strcmp("minimal", newVal) == 0 ) { - priv->appearanceMode = APPEARANCE_MINIMAL; - } else { - priv->appearanceMode = APPEARANCE_UNKNOWN; - } - } - break; - - case PROP_ICON_ID: - { - gchar* tmp = priv->iconId; - priv->iconId = g_value_dup_string( value ); - g_free( tmp ); - } - break; - - case PROP_ICON_SIZE: - { - priv->iconSize = (GtkIconSize)g_value_get_int( value ); - } - break; - - case PROP_UNIT_TRACKER: - { - priv->unitTracker = (Inkscape::UI::Widget::UnitTracker*)g_value_get_pointer( value ); - } - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); - } -} - -GtkAdjustment* ege_adjustment_action_get_adjustment( EgeAdjustmentAction* action ) -{ - g_return_val_if_fail( IS_EGE_ADJUSTMENT_ACTION(action), NULL ); - - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - - return priv->adj; -} - -void ege_adjustment_action_set_focuswidget( EgeAdjustmentAction* action, GtkWidget* widget ) -{ - g_return_if_fail( IS_EGE_ADJUSTMENT_ACTION(action) ); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - - /* TODO unhook prior */ - - priv->focusWidget = widget; -} - -GtkWidget* ege_adjustment_action_get_focuswidget( EgeAdjustmentAction* action ) -{ - g_return_val_if_fail( IS_EGE_ADJUSTMENT_ACTION(action), NULL ); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - - return priv->focusWidget; -} - -static void egeAct_free_description( gpointer data, gpointer user_data ) { - (void)user_data; - if ( data ) { - EgeAdjustmentDescr* descr = (EgeAdjustmentDescr*)data; - if ( descr->descr ) { - g_free( descr->descr ); - descr->descr = nullptr; - } - g_free( descr ); - } -} - -static void egeAct_free_all_descriptions( EgeAdjustmentAction* action ) -{ - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - for(auto i:priv->descriptions) { - egeAct_free_description(i,nullptr); - } - for(auto i:priv->descriptions) { - g_free(i); - } - priv->descriptions.clear(); -} - -static gint egeAct_compare_descriptions( gconstpointer a, gconstpointer b ) -{ - gint val = 0; - - EgeAdjustmentDescr const * aa = (EgeAdjustmentDescr const *)a; - EgeAdjustmentDescr const * bb = (EgeAdjustmentDescr const *)b; - - if ( aa && bb ) { - if ( aa->value < bb->value ) { - val = -1; - } else if ( aa->value > bb->value ) { - val = 1; - } - } - - return val; -} - -void ege_adjustment_action_set_descriptions( EgeAdjustmentAction* action, gchar const** descriptions, gdouble const* values, guint count ) -{ - g_return_if_fail( IS_EGE_ADJUSTMENT_ACTION(action) ); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - - egeAct_free_all_descriptions( action ); - - if ( count && descriptions && values ) { - guint i = 0; - for ( i = 0; i < count; i++ ) { - EgeAdjustmentDescr* descr = g_new0( EgeAdjustmentDescr, 1 ); - descr->descr = descriptions[i] ? g_strdup( descriptions[i] ) : nullptr; - descr->value = values[i]; - priv->descriptions.push_back(descr); - std::sort(priv->descriptions.begin(),priv->descriptions.end()); - } - } -} - -void ege_adjustment_action_set_appearance( EgeAdjustmentAction* action, gchar const* val ) -{ - g_object_set( G_OBJECT(action), "appearance", val, NULL ); -} - -static void process_menu_action( GtkWidget* obj, gpointer data ) -{ - GtkCheckMenuItem* item = GTK_CHECK_MENU_ITEM(obj); - if ( gtk_check_menu_item_get_active (item)) { - EgeAdjustmentAction* act = (EgeAdjustmentAction*)g_object_get_qdata( G_OBJECT(obj), gDataName ); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (act); - gint what = GPOINTER_TO_INT(data); - - - gdouble base = gtk_adjustment_get_value( priv->adj ); - gdouble lower = 0.0; - gdouble upper = 0.0; - gdouble step = 0.0; - gdouble page = 0.0; - g_object_get( G_OBJECT(priv->adj), - "lower", &lower, - "upper", &upper, - "step-increment", &step, - "page-increment", &page, - NULL ); - - switch ( what ) { - case BUMP_TOP: - gtk_adjustment_set_value( priv->adj, upper ); - break; - - case BUMP_PAGE_UP: - gtk_adjustment_set_value( priv->adj, base + page ); - break; - - case BUMP_UP: - gtk_adjustment_set_value( priv->adj, base + step ); - break; - - case BUMP_DOWN: - gtk_adjustment_set_value( priv->adj, base - step ); - break; - - case BUMP_PAGE_DOWN: - gtk_adjustment_set_value( priv->adj, base - page ); - break; - - case BUMP_BOTTOM: - gtk_adjustment_set_value( priv->adj, lower ); - break; - - default: - if ( what >= BUMP_CUSTOM ) { - guint index = what - BUMP_CUSTOM; - if ( index < priv->descriptions.size() ) { - EgeAdjustmentDescr* descr = priv->descriptions[index]; - if ( descr ) { - gtk_adjustment_set_value( priv->adj, descr->value ); - } - } - } - } - } -} - -static void create_single_menu_item( GCallback toggleCb, int val, GtkWidget* menu, EgeAdjustmentAction* act, GtkWidget** dst, Gtk::RadioMenuItem::Group *group, gdouble num, gboolean active ) -{ - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (act); - char* str = nullptr; - EgeAdjustmentDescr* marker = nullptr; - std::vector<EgeAdjustmentDescr*> cur = priv->descriptions; - - for (auto descr:cur) { - gdouble delta = num - descr->value; - if ( delta < 0.0 ) { - delta = -delta; - } - if ( delta < priv->epsilon ) { - marker = descr; - break; - } - } - - str = g_strdup_printf( priv->format, num, - ((marker && marker->descr) ? ": " : ""), - ((marker && marker->descr) ? marker->descr : "")); - - auto rmi = new Gtk::RadioMenuItem(*group,Glib::ustring(str)); - *dst = GTK_WIDGET(rmi->gobj()); - if ( active ) { - gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(*dst), TRUE ); - } - gtk_menu_shell_append( GTK_MENU_SHELL(menu), *dst ); - g_object_set_qdata( G_OBJECT(*dst), gDataName, act ); - - g_signal_connect( G_OBJECT(*dst), "toggled", toggleCb, GINT_TO_POINTER(val) ); - - g_free(str); -} - -static int flush_explicit_items( std::vector<EgeAdjustmentDescr*> descriptions, - int pos, - GCallback toggleCb, - int val, - GtkWidget* menu, - EgeAdjustmentAction* act, - GtkWidget** dst, - Gtk::RadioMenuItem::Group *group, - gdouble num ) -{ - if(pos >= descriptions.size() || pos < 0) return pos; - EgeAdjustmentDescr* descr = descriptions[pos]; - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (act); - - gdouble valUpper = num + priv->epsilon; - gdouble valLower = num - priv->epsilon; - - while ( pos>=0 && pos<descriptions.size() && descr && (descr->value >= valLower) ) { - if ( descr->value > valUpper ) { - create_single_menu_item( toggleCb, val + ( std::find(priv->descriptions.begin(),priv->descriptions.end(),descr) - priv->descriptions.begin() ) , menu, act, dst, group, descr->value, FALSE ); - } - pos--; - descr = (pos<0) ? descriptions[pos] : nullptr; - } - - return pos; -} - -static GtkWidget* create_popup_number_menu( EgeAdjustmentAction* act ) -{ - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (act); - GtkWidget* menu = gtk_menu_new(); - - Gtk::RadioMenuItem::Group group; - GtkWidget* single = nullptr; - std::vector<EgeAdjustmentDescr*> list = priv->descriptions; - int addOns = list.size() - 1; - - gdouble base = gtk_adjustment_get_value( priv->adj ); - gdouble lower = 0.0; - gdouble upper = 0.0; - gdouble step = 0.0; - gdouble page = 0.0; - g_object_get( G_OBJECT(priv->adj), - "lower", &lower, - "upper", &upper, - "step-increment", &step, - "page-increment", &page, - NULL ); - - - if ( base < upper ) { - addOns = flush_explicit_items( list, addOns, G_CALLBACK(process_menu_action), BUMP_CUSTOM, menu, act, &single, &group, upper ); - create_single_menu_item( G_CALLBACK(process_menu_action), BUMP_TOP, menu, act, &single, &group, upper, FALSE ); - if ( (base + page) < upper ) { - addOns = flush_explicit_items( list, addOns, G_CALLBACK(process_menu_action), BUMP_CUSTOM, menu, act, &single, &group, base + page ); - create_single_menu_item( G_CALLBACK(process_menu_action), BUMP_PAGE_UP, menu, act, &single, &group, base + page, FALSE ); - } - if ( (base + step) < upper ) { - addOns = flush_explicit_items( list, addOns, G_CALLBACK(process_menu_action), BUMP_CUSTOM, menu, act, &single, &group, base + step ); - create_single_menu_item( G_CALLBACK(process_menu_action), BUMP_UP, menu, act, &single, &group, base + step, FALSE ); - } - } - - addOns = flush_explicit_items( list, addOns, G_CALLBACK(process_menu_action), BUMP_CUSTOM, menu, act, &single, &group, base ); - create_single_menu_item( G_CALLBACK(process_menu_action), BUMP_NONE, menu, act, &single, &group, base, TRUE ); - - if ( base > lower ) { - if ( (base - step) > lower ) { - addOns = flush_explicit_items( list, addOns, G_CALLBACK(process_menu_action), BUMP_CUSTOM, menu, act, &single, &group, base - step ); - create_single_menu_item( G_CALLBACK(process_menu_action), BUMP_DOWN, menu, act, &single, &group, base - step, FALSE ); - } - if ( (base - page) > lower ) { - addOns = flush_explicit_items( list, addOns, G_CALLBACK(process_menu_action), BUMP_CUSTOM, menu, act, &single, &group, base - page ); - create_single_menu_item( G_CALLBACK(process_menu_action), BUMP_PAGE_DOWN, menu, act, &single, &group, base - page, FALSE ); - } - addOns = flush_explicit_items( list, addOns, G_CALLBACK(process_menu_action), BUMP_CUSTOM, menu, act, &single, &group, lower ); - create_single_menu_item( G_CALLBACK(process_menu_action), BUMP_BOTTOM, menu, act, &single, &group, lower, FALSE ); - } - - if ( !priv->descriptions.empty() ) { - gdouble value = ((EgeAdjustmentDescr*)priv->descriptions[0])->value; - flush_explicit_items( list, addOns, G_CALLBACK(process_menu_action), BUMP_CUSTOM, menu, act, &single, &group, value ); - } - - return menu; -} - -static GtkWidget* create_menu_item( GtkAction* action ) -{ - GtkWidget* item = nullptr; - - if ( IS_EGE_ADJUSTMENT_ACTION(action) ) { - EgeAdjustmentAction* act = EGE_ADJUSTMENT_ACTION( action ); - GValue value; - GtkWidget* subby = nullptr; - - memset( &value, 0, sizeof(value) ); - g_value_init( &value, G_TYPE_STRING ); - g_object_get_property( G_OBJECT(action), "label", &value ); - - item = gtk_menu_item_new_with_label( g_value_get_string( &value ) ); - - subby = create_popup_number_menu( act ); - gtk_menu_item_set_submenu( GTK_MENU_ITEM(item), subby ); - gtk_widget_show_all( subby ); - g_value_unset( &value ); - } else { - item = GTK_ACTION_CLASS(ege_adjustment_action_parent_class)->create_menu_item( action ); - } - - return item; -} - -static void value_changed_cb( GtkSpinButton* spin, EgeAdjustmentAction* act ) -{ - if ( gtk_widget_has_focus( GTK_WIDGET(spin) ) ) { - gint start = 0, end = 0; - if (GTK_IS_EDITABLE(spin) && gtk_editable_get_selection_bounds (GTK_EDITABLE(spin), &start, &end) - && start != end) { - // #167846, #363000 If the spin button has a selection, its probably - // because we got here from a Tab key from another spin, if so don't defocus - return; - } - ege_adjustment_action_defocus( act ); - } -} - -static gboolean event_cb( EgeAdjustmentAction* act, GdkEvent* evt ) -{ - gboolean handled = FALSE; - if ( evt->type == GDK_BUTTON_PRESS ) { - if ( evt->button.button == 3 ) { - if ( IS_EGE_ADJUSTMENT_ACTION(act) ) { - GtkWidget* menu = create_popup_number_menu(act); - gtk_widget_show_all( menu ); - gtk_menu_popup_at_pointer( GTK_MENU(menu), evt ); - } - handled = TRUE; - } - } - - return handled; -} - -static GtkWidget* create_tool_item( GtkAction* action ) -{ - GtkWidget* item = nullptr; - - if ( IS_EGE_ADJUSTMENT_ACTION(action) ) { - EgeAdjustmentAction* act = EGE_ADJUSTMENT_ACTION( action ); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (act); - GtkWidget* spinbutton = nullptr; - auto hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); - gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); - GValue value; - memset( &value, 0, sizeof(value) ); - g_value_init( &value, G_TYPE_STRING ); - g_object_get_property( G_OBJECT(action), "short_label", &value ); - - if ( priv->appearanceMode == APPEARANCE_FULL ) { - /* Slider */ - InkSpinScale* inkspinscale = - new InkSpinScale(Glib::wrap(priv->adj)); - inkspinscale->set_label( g_value_get_string( &value )); - inkspinscale->set_digits(0); - spinbutton = (GtkWidget*)inkspinscale->gobj(); - gtk_widget_set_size_request(spinbutton, 100, -1); - - } else if ( priv->appearanceMode == APPEARANCE_MINIMAL ) { - spinbutton = gtk_scale_button_new( GTK_ICON_SIZE_MENU, 0, 100, 2, nullptr ); - gtk_scale_button_set_adjustment( GTK_SCALE_BUTTON(spinbutton), priv->adj ); - gtk_scale_button_set_icons( GTK_SCALE_BUTTON(spinbutton), floogles ); - } else { - if ( gFactoryCb ) { - spinbutton = gFactoryCb( priv->adj, priv->climbRate, priv->digits, priv->unitTracker ); - } else { - spinbutton = gtk_spin_button_new( priv->adj, priv->climbRate, priv->digits ); - } - } - - item = GTK_WIDGET( gtk_tool_item_new() ); - - { - GValue tooltip; - memset( &tooltip, 0, sizeof(tooltip) ); - g_value_init( &tooltip, G_TYPE_STRING ); - g_object_get_property( G_OBJECT(action), "tooltip", &tooltip ); - const gchar* tipstr = g_value_get_string( &tooltip ); - if ( tipstr && *tipstr ) { - gtk_widget_set_tooltip_text( spinbutton, tipstr ); - } - g_value_unset( &tooltip ); - } - - if ( priv->appearanceMode != APPEARANCE_FULL ) { - GtkWidget* filler1 = gtk_label_new(" "); - gtk_box_pack_start( GTK_BOX(hb), filler1, FALSE, FALSE, 0 ); - - /* Use an icon if available or use short-label */ - if ( priv->iconId && strcmp( priv->iconId, "" ) != 0 ) { - GtkWidget *icon = sp_get_icon_image(priv->iconId, priv->iconSize); - gtk_box_pack_start( GTK_BOX(hb), icon, FALSE, FALSE, 0 ); - } else { - GtkWidget* lbl = gtk_label_new( g_value_get_string( &value ) ? g_value_get_string( &value ) : "wwww" ); - gtk_widget_set_halign(lbl, GTK_ALIGN_END); - gtk_box_pack_start( GTK_BOX(hb), lbl, FALSE, FALSE, 0 ); - } - } - - if ( priv->appearanceMode == APPEARANCE_FULL ) { - gtk_box_pack_start( GTK_BOX(hb), spinbutton, TRUE, TRUE, 0 ); - } else { - gtk_box_pack_start( GTK_BOX(hb), spinbutton, FALSE, FALSE, 0 ); - } - - gtk_container_add( GTK_CONTAINER(item), hb ); - - if ( priv->selfId ) { - g_object_set_data( G_OBJECT(spinbutton), priv->selfId, spinbutton ); - } - - g_signal_connect( G_OBJECT(spinbutton), "focus-in-event", G_CALLBACK(focus_in_cb), action ); - g_signal_connect( G_OBJECT(spinbutton), "focus-out-event", G_CALLBACK(focus_out_cb), action ); - g_signal_connect( G_OBJECT(spinbutton), "key-press-event", G_CALLBACK(keypress_cb), action ); - - g_signal_connect( G_OBJECT(spinbutton), "value-changed", G_CALLBACK(value_changed_cb), action ); - - g_signal_connect_swapped( G_OBJECT(spinbutton), "event", G_CALLBACK(event_cb), action ); - if ( priv->appearanceMode == APPEARANCE_FULL ) { - /* */ - } else if ( priv->appearanceMode == APPEARANCE_MINIMAL ) { - /* */ - } else { - gtk_entry_set_width_chars( GTK_ENTRY(spinbutton), priv->digits + 3 ); - } - - gtk_widget_show_all( item ); - - /* Shrink or whatnot after shown */ - if ( priv->toolPost ) { - priv->toolPost( item ); - } - - g_value_unset( &value ); - } else { - item = GTK_ACTION_CLASS(ege_adjustment_action_parent_class)->create_tool_item( action ); - } - - return item; -} - -static void connect_proxy( GtkAction *action, GtkWidget *proxy ) -{ - GTK_ACTION_CLASS(ege_adjustment_action_parent_class)->connect_proxy( action, proxy ); -} - -static void disconnect_proxy( GtkAction *action, GtkWidget *proxy ) -{ - GTK_ACTION_CLASS(ege_adjustment_action_parent_class)->disconnect_proxy( action, proxy ); -} - -void ege_adjustment_action_defocus( EgeAdjustmentAction* action ) -{ - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - if ( priv->transferFocus ) { - if ( priv->focusWidget ) { - gtk_widget_grab_focus( priv->focusWidget ); - } - } -} - -gboolean focus_in_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ) -{ - (void)event; - if ( IS_EGE_ADJUSTMENT_ACTION(data) ) { - EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( data ); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - if ( GTK_IS_SPIN_BUTTON(widget) ) { - priv->lastVal = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); - } else if ( GTK_IS_SCALE_BUTTON(widget) ) { - priv->lastVal = gtk_scale_button_get_value( GTK_SCALE_BUTTON(widget) ); - } else if (GTK_IS_RANGE(widget) ) { - priv->lastVal = gtk_range_get_value( GTK_RANGE(widget) ); - } - priv->transferFocus = TRUE; - } - - return FALSE; /* report event not consumed */ -} - -static gboolean focus_out_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ) -{ - (void)widget; - (void)event; - if ( IS_EGE_ADJUSTMENT_ACTION(data) ) { - EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( data ); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - priv->transferFocus = FALSE; - } - - return FALSE; /* report event not consumed */ -} - - -static gboolean process_tab( GtkWidget* widget, int direction ) -{ - gboolean handled = FALSE; - GtkWidget* parent = gtk_widget_get_parent(widget); - GtkWidget* gp = parent ? gtk_widget_get_parent(parent) : nullptr; - GtkWidget* ggp = gp ? gtk_widget_get_parent(gp) : nullptr; - - if ( ggp && GTK_IS_TOOLBAR(ggp) ) { - std::vector<Gtk::Widget*> kids = Glib::wrap(GTK_CONTAINER(ggp))->get_children(); - if ( !kids.empty() ) { - GtkWidget* curr = widget; - while ( curr && (gtk_widget_get_parent(curr) != ggp) ) { - curr = gtk_widget_get_parent( curr ); - } - if ( curr ) { - std::vector<Gtk::Widget*>::iterator mid=kids.end(); - for(auto i = kids.begin(); i!= kids.end(); ++i){ - if(curr == (*i)->gobj()) - mid = i; - } - while ( mid != kids.end() && !(mid==kids.begin() && direction<0 ) ) { - mid = ( direction < 0 ) ? std::prev(mid) : ++mid; - if ( mid!=kids.end() && GTK_IS_TOOL_ITEM((*mid)->gobj()) ) { - /* potential target */ - GtkWidget* child = gtk_bin_get_child( GTK_BIN((*mid)->gobj()) ); - if ( child && GTK_IS_BOX(child) ) { /* could be ours */ - std::vector<Gtk::Widget*> subChildren = Glib::wrap(GTK_CONTAINER(child))->get_children(); - if ( ! subChildren.empty() ) { - Gtk::Widget *last = subChildren[subChildren.size()-1]; - if ( GTK_IS_SPIN_BUTTON(last->gobj()) && gtk_widget_is_sensitive( GTK_WIDGET(last->gobj()) ) ) { - gtk_widget_grab_focus( GTK_WIDGET(last->gobj()) ); - handled = TRUE; - mid = kids.end(); /* to stop loop */ - } - } - } - } - } - } - } - } - - return handled; -} - -gboolean keypress_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ) -{ - gboolean wasConsumed = FALSE; /* default to report event not consumed */ - EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION(data); - auto priv = EGE_ADJUSTMENT_ACTION_GET_PRIVATE (action); - guint key = 0; - gdk_keymap_translate_keyboard_state( Gdk::Display::get_default()->get_keymap(), - event->hardware_keycode, (GdkModifierType)event->state, - 0, &key, nullptr, nullptr, nullptr ); - - switch ( key ) { - case GDK_KEY_Escape: - { - priv->transferFocus = TRUE; - gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), priv->lastVal ); - ege_adjustment_action_defocus( action ); - wasConsumed = TRUE; - } - break; - - case GDK_KEY_Return: - case GDK_KEY_KP_Enter: - { - priv->transferFocus = TRUE; - ege_adjustment_action_defocus( action ); - wasConsumed = TRUE; - } - break; - - case GDK_KEY_Tab: - { - priv->transferFocus = FALSE; - wasConsumed = process_tab( widget, 1 ); - } - break; - - case GDK_KEY_ISO_Left_Tab: - { - priv->transferFocus = FALSE; - wasConsumed = process_tab( widget, -1 ); - } - break; - - case GDK_KEY_Up: - case GDK_KEY_KP_Up: - { - priv->transferFocus = FALSE; - gdouble val = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); - gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), val + priv->step ); - wasConsumed = TRUE; - } - break; - - case GDK_KEY_Down: - case GDK_KEY_KP_Down: - { - priv->transferFocus = FALSE; - gdouble val = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); - gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), val - priv->step ); - wasConsumed = TRUE; - } - break; - - case GDK_KEY_Page_Up: - case GDK_KEY_KP_Page_Up: - { - priv->transferFocus = FALSE; - gdouble val = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); - gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), val + priv->page ); - wasConsumed = TRUE; - } - break; - - case GDK_KEY_Page_Down: - case GDK_KEY_KP_Page_Down: - { - priv->transferFocus = FALSE; - gdouble val = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); - gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), val - priv->page ); - wasConsumed = TRUE; - } - break; - - case GDK_KEY_z: - case GDK_KEY_Z: - { - priv->transferFocus = FALSE; - gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), priv->lastVal ); - 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/widgets/ege-adjustment-action.h b/src/widgets/ege-adjustment-action.h deleted file mode 100644 index 14229490c..000000000 --- a/src/widgets/ege-adjustment-action.h +++ /dev/null @@ -1,189 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later OR MPL-1.1 OR LGPL-2.1-or-later -#ifndef SEEN_EGE_ADJUSTMENT_ACTION -#define SEEN_EGE_ADJUSTMENT_ACTION -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is EGE Adjustment Action. - * - * The Initial Developer of the Original Code is - * Jon A. Cruz. - * Portions created by the Initial Developer are Copyright (C) 2006 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** \file - * GtkAction subclass that represents a GtkAdjustment value. - */ - -/* Note: this file should be kept compilable as both .cpp and .c */ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - - -#define EGE_ADJUSTMENT_ACTION_TYPE ( ege_adjustment_action_get_type() ) -#define EGE_ADJUSTMENT_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_CAST( (obj), EGE_ADJUSTMENT_ACTION_TYPE, EgeAdjustmentAction) ) -#define EGE_ADJUSTMENT_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( (klass), EGE_ADJUSTMENT_ACTION_TYPE, EgeAdjustmentActionClass) ) -#define IS_EGE_ADJUSTMENT_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), EGE_ADJUSTMENT_ACTION_TYPE) ) -#define IS_EGE_ADJUSTMENT_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE( (klass), EGE_ADJUSTMENT_ACTION_TYPE) ) -#define EGE_ADJUSTMENT_ACTION_GET_CLASS( obj ) ( G_TYPE_INSTANCE_GET_CLASS( (obj), EGE_ADJUSTMENT_ACTION_TYPE, EgeAdjustmentActionClass) ) - -typedef struct _EgeAdjustmentAction EgeAdjustmentAction; -typedef struct _EgeAdjustmentActionClass EgeAdjustmentActionClass; - -namespace Inkscape { - namespace UI { - namespace Widget { - class UnitTracker; - } - } -} - -/** - * Instance structure of EgeAdjustmentAction. - */ -struct _EgeAdjustmentAction -{ - /** Parent instance structure. */ - GtkAction action; -}; - -/** - * Class structure of EgeAdjustmentAction. - */ -struct _EgeAdjustmentActionClass -{ - /** Parent class structure. */ - GtkActionClass parent_class; -}; - -/** Standard Gtk type function */ -GType ege_adjustment_action_get_type( void ); - - -/* - * Note: This normally could be implemented via a GType property for the class to construct, - * but gtkmm classes implemented in C++ only will often not function properly. - * - */ - -/** Callback type for widgets creation factory */ -typedef GtkWidget* (*EgeCreateAdjWidgetCB)( GtkAdjustment *adjustment, gdouble climb_rate, guint digits, Inkscape::UI::Widget::UnitTracker *unit_tracker ); - -/** - * Sets a factory callback to be used to create the specific widget. - * - * @param factoryCb the callback to use to create custom widgets, NULL to use the default. - */ -void ege_adjustment_action_set_compact_tool_factory( EgeCreateAdjWidgetCB factoryCb ); - - -/** - * Creates a new EgeAdjustmentAction instance. - * This is a GtkAction subclass that manages a value stored in a - * GtkAdjustment. - * - * @param adjustment The GtkAdjustment to manage. - * @param name Functional name for the action. - * @param label Display label for the action. - * @param tooltip Tooltip for the action. - * @param stock_id Icon id to use. - * @param climb_rate Used for created widgets. - * @param digits Used for created widgets. - * @param unit_tracker Used to store unit. - */ -EgeAdjustmentAction* ege_adjustment_action_new( GtkAdjustment* adjustment, - const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *stock_id, - gdouble climb_rate, - guint digits, - Inkscape::UI::Widget::UnitTracker *unit_tracker - ); -/** - * Returns a pointer to the GtkAdjustment represented by the given - * EgeAdjustmentAction. - * - * @param action The action to fetch the GtkAdjustment for. - */ -GtkAdjustment* ege_adjustment_action_get_adjustment( EgeAdjustmentAction* action ); - -/** - * Sets the GtkWidget to return focus to. - * This is used to be able to transfer focus back out of a toolbar. - * - * @param action The action to set the widget for. - * @param widget The widget to return focus to after editing. - * @see ege_adjustment_action_get_focuswidget - */ -void ege_adjustment_action_set_focuswidget( EgeAdjustmentAction* action, GtkWidget* widget ); - -/** - * Returns a pointer to the GtkWidget to return focus to after changing - * the value. - * - * @param action The action to fetch the focus widget for. - * @returns A pointer to the widget to return focus to, NULL if none set. - * @see ege_adjustment_action_set_focuswidget - */ -GtkWidget* ege_adjustment_action_get_focuswidget( EgeAdjustmentAction* action ); - -/** - * Set a list of values with labels to explicitly include in menus. - * - * @param action The action to set explicit entries for. - * @param descriptions Array of descriptions to include. - * Descriptions will be matched one-for-one with numbers in the 'values' array. - * @param values Array of values to include. - * Values will be matched one-for-one with numbers in the 'descriptions' array. - * @param count Number of items in the 'descriptions' and 'values' arrays. - */ -void ege_adjustment_action_set_descriptions( EgeAdjustmentAction* action, gchar const** descriptions, gdouble const* values, guint count ); - -/** - * Sets a hint to be used in determining the display form. - * This is the XForms style 'appearance' hint: "full", "compact", "minimal". - * - * @param action The action to set the tooltip column for. - * @param val The value of the appearance hint. - */ -void ege_adjustment_action_set_appearance( EgeAdjustmentAction* action, gchar const* val ); - -/** Callback type for post-creation 'fixup' pass on generated widgets */ -typedef void (*EgeWidgetFixup)(GtkWidget *widget); - - -G_END_DECLS - -#endif /* SEEN_EGE_ADJUSTMENT_ACTION */ diff --git a/src/widgets/ink-comboboxentry-action.cpp b/src/widgets/ink-comboboxentry-action.cpp deleted file mode 100644 index a49d5c2c3..000000000 --- a/src/widgets/ink-comboboxentry-action.cpp +++ /dev/null @@ -1,964 +0,0 @@ -// 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 <iostream> -#include <cstring> -#include <glibmm/ustring.h> - -#include <gtk/gtk.h> -#include <gdk/gdkkeysyms.h> -#include <gdkmm/display.h> - -#include "widgets/ink-comboboxentry-action.h" -#include "ui/icon-names.h" - -// Must handle both tool and menu items! -static GtkWidget* create_tool_item( GtkAction* action ); -static GtkWidget* create_menu_item( GtkAction* action ); - -// Internal -static gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text, gboolean exclude = false, gboolean ignore_case = false ); -static Glib::ustring check_comma_separated_text( Ink_ComboBoxEntry_Action* action ); - -// Callbacks -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 ); - -enum { - PROP_MODEL = 1, - PROP_COMBOBOX, - PROP_ENTRY, - PROP_ENTRY_WIDTH, - PROP_EXTRA_WIDTH, - PROP_CELL_DATA_FUNC, - PROP_SEPARATOR_FUNC, - PROP_POPUP, - PROP_FOCUS_WIDGET -}; - -enum { - CHANGED = 0, - ACTIVATED, - N_SIGNALS -}; -static guint signals[N_SIGNALS] = {0}; - -static GQuark gDataName = 0; - -static void ink_comboboxentry_action_init (Ink_ComboBoxEntry_Action *action); -static void ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *klass); - -G_DEFINE_TYPE(Ink_ComboBoxEntry_Action, ink_comboboxentry_action, GTK_TYPE_ACTION); - -static void ink_comboboxentry_action_finalize (GObject *object) -{ - // Free any allocated resources. - - G_OBJECT_CLASS (ink_comboboxentry_action_parent_class)->finalize (object); -} - - -static void ink_comboboxentry_action_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - Ink_ComboBoxEntry_Action *action = INK_COMBOBOXENTRY_ACTION (object); - - switch(property_id) { - - case PROP_MODEL: - action->model = GTK_TREE_MODEL( g_value_get_object( value )); - break; - - case PROP_COMBOBOX: - action->combobox = GTK_COMBO_BOX (g_value_get_object (value)); - break; - - case PROP_ENTRY: - action->entry = GTK_ENTRY( g_value_get_object( value )); - break; - - case PROP_ENTRY_WIDTH: - action->entry_width = g_value_get_int( value ); - break; - - case PROP_EXTRA_WIDTH: - action->extra_width = g_value_get_int( value ); - break; - - case PROP_CELL_DATA_FUNC: - action->cell_data_func = g_value_get_pointer( value ); - break; - - case PROP_SEPARATOR_FUNC: - action->separator_func = g_value_get_pointer( value ); - break; - - case PROP_POPUP: - action->popup = g_value_get_boolean( value ); - break; - - case PROP_FOCUS_WIDGET: - action->focusWidget = (GtkWidget*)g_value_get_pointer( value ); - break; - - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - - -static void ink_comboboxentry_action_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - Ink_ComboBoxEntry_Action *action = INK_COMBOBOXENTRY_ACTION (object); - - switch(property_id) { - - case PROP_MODEL: - g_value_set_object (value, action->model); - break; - - case PROP_COMBOBOX: - g_value_set_object (value, action->combobox); - break; - - case PROP_ENTRY: - g_value_set_object (value, action->entry); - break; - - case PROP_ENTRY_WIDTH: - g_value_set_int (value, action->entry_width); - break; - - case PROP_EXTRA_WIDTH: - g_value_set_int (value, action->extra_width); - break; - - case PROP_CELL_DATA_FUNC: - g_value_set_pointer (value, action->cell_data_func); - break; - - case PROP_SEPARATOR_FUNC: - g_value_set_pointer (value, action->separator_func); - break; - - case PROP_POPUP: - g_value_set_boolean (value, action->popup); - break; - - case PROP_FOCUS_WIDGET: - g_value_set_pointer (value, action->focusWidget); - break; - - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -ink_comboboxentry_action_connect_proxy (GtkAction *action, - GtkWidget *proxy) -{ - /* Override any proxy properties. */ - // if (GTK_IS_MENU_ITEM (proxy)) { - // } - - GTK_ACTION_CLASS (ink_comboboxentry_action_parent_class)->connect_proxy (action, proxy); -} - -static void -ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *klass) -{ - - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GtkActionClass *gtkaction_class = GTK_ACTION_CLASS (klass); - - gtkaction_class->connect_proxy = ink_comboboxentry_action_connect_proxy; - - gobject_class->finalize = ink_comboboxentry_action_finalize; - gobject_class->set_property = ink_comboboxentry_action_set_property; - gobject_class->get_property = ink_comboboxentry_action_get_property; - - gDataName = g_quark_from_string("ink_comboboxentry-action"); - - klass->parent_class.create_tool_item = create_tool_item; - klass->parent_class.create_menu_item = create_menu_item; - - g_object_class_install_property ( - gobject_class, - PROP_MODEL, - g_param_spec_object ("model", - "Tree Model", - "Tree Model", - GTK_TYPE_TREE_MODEL, - (GParamFlags)G_PARAM_READWRITE)); - g_object_class_install_property ( - gobject_class, - PROP_COMBOBOX, - g_param_spec_object ("combobox", - "GtkComboBoxEntry", - "GtkComboBoxEntry", - GTK_TYPE_WIDGET, - (GParamFlags)G_PARAM_READABLE)); - g_object_class_install_property ( - gobject_class, - PROP_ENTRY, - g_param_spec_object ("entry", - "GtkEntry", - "GtkEntry", - GTK_TYPE_WIDGET, - (GParamFlags)G_PARAM_READABLE)); - g_object_class_install_property ( - gobject_class, - PROP_ENTRY_WIDTH, - g_param_spec_int ("entry_width", - "EntryBox width", - "EntryBox width (characters)", - -1.0, 100, -1.0, - (GParamFlags)G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_EXTRA_WIDTH, - g_param_spec_int ("extra_width", - "Extra width", - "Extra width (px)", - -1.0, 500, -1.0, - (GParamFlags)G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_CELL_DATA_FUNC, - g_param_spec_pointer ("cell_data_func", - "Cell Data Func", - "Cell Deta Function", - (GParamFlags)G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_SEPARATOR_FUNC, - g_param_spec_pointer ("separator_func", - "Separator Func", - "Separator Function", - (GParamFlags)G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_POPUP, - g_param_spec_boolean ("popup", - "Entry Popup", - "Entry Popup", - false, - (GParamFlags)G_PARAM_READWRITE)); - - g_object_class_install_property( gobject_class, - PROP_FOCUS_WIDGET, - g_param_spec_pointer( "focus-widget", - "Focus Widget", - "The widget to return focus to", - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - // We need to know when GtkComboBoxEvent or Menu ready for reading - signals[CHANGED] = g_signal_new( "changed", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(Ink_ComboBoxEntry_ActionClass, changed), - nullptr, nullptr, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - // Probably not needed... originally to keep track of key-presses. - signals[ACTIVATED] = g_signal_new( "activated", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(Ink_ComboBoxEntry_ActionClass, activated), - nullptr, nullptr, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - -} - -static void ink_comboboxentry_action_init (Ink_ComboBoxEntry_Action *action) -{ - action->active = -1; - action->text = strdup(""); - action->entry_completion = nullptr; - action->indicator = nullptr; - action->popup = false; - action->info = nullptr; - action->info_cb = nullptr; - action->info_cb_id = 0; - action->info_cb_blocked = false; - action->warning = nullptr; - action->warning_cb = nullptr; - action->warning_cb_id = 0; - action->warning_cb_blocked = false; - action->altx_name = nullptr; - action->focusWidget = nullptr; -} - -Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new (const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *stock_id, - GtkTreeModel *model, - gint entry_width, - gint extra_width, - void *cell_data_func, - void *separator_func, - GtkWidget *focusWidget) -{ - g_return_val_if_fail (name != nullptr, NULL); - - return (Ink_ComboBoxEntry_Action*)g_object_new (INK_COMBOBOXENTRY_TYPE_ACTION, - "name", name, - "label", label, - "tooltip", tooltip, - "stock-id", stock_id, - "model", model, - "entry_width", entry_width, - "extra_width", extra_width, - "cell_data_func", cell_data_func, - "separator_func", separator_func, - "focus-widget", focusWidget, - NULL); -} - -// Create a widget for a toolbar. -GtkWidget* create_tool_item( GtkAction* action ) -{ - GtkWidget* item = nullptr; - - if ( INK_COMBOBOXENTRY_IS_ACTION( action ) && INK_COMBOBOXENTRY_ACTION(action)->model ) { - - Ink_ComboBoxEntry_Action* ink_comboboxentry_action = INK_COMBOBOXENTRY_ACTION( action ); - - gchar *action_name = g_strdup( gtk_action_get_name( action ) ); - gchar *combobox_name = g_strjoin( nullptr, action_name, "_combobox", NULL ); - gchar *entry_name = g_strjoin( nullptr, action_name, "_entry", NULL ); - g_free( action_name ); - - item = GTK_WIDGET( gtk_tool_item_new() ); - - GtkWidget* comboBoxEntry = gtk_combo_box_new_with_model_and_entry (ink_comboboxentry_action->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); - gtk_container_add(GTK_CONTAINER(item), comboBoxEntry); - } - - ink_comboboxentry_action->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), action ); - - // Optionally add separator function... - if( ink_comboboxentry_action->separator_func != nullptr ) { - gtk_combo_box_set_row_separator_func( ink_comboboxentry_action->combobox, - GtkTreeViewRowSeparatorFunc (ink_comboboxentry_action->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( ink_comboboxentry_action->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 (ink_comboboxentry_action->cell_data_func), - nullptr, nullptr ); - } - - // Optionally widen the combobox width... which widens the drop-down list in list mode. - if( ink_comboboxentry_action->extra_width > 0 ) { - GtkRequisition req; - gtk_widget_get_preferred_size(GTK_WIDGET(ink_comboboxentry_action->combobox), &req, nullptr); - gtk_widget_set_size_request( GTK_WIDGET( ink_comboboxentry_action->combobox ), - req.width + ink_comboboxentry_action->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 ) ) { - - ink_comboboxentry_action->entry = GTK_ENTRY(child); - - // Change width - if( ink_comboboxentry_action->entry_width > 0 ) { - gtk_entry_set_width_chars (GTK_ENTRY (child), ink_comboboxentry_action->entry_width ); - } - - // Add pop-up entry completion if required - if( ink_comboboxentry_action->popup ) { - ink_comboboxentry_action_popup_enable( ink_comboboxentry_action ); - } - - // Add altx_name if required - if( ink_comboboxentry_action->altx_name ) { - g_object_set_data( G_OBJECT( child ), ink_comboboxentry_action->altx_name, ink_comboboxentry_action->entry ); - } - - // Add signal for GtkEntry to check if finished typing. - g_signal_connect( G_OBJECT(child), "activate", G_CALLBACK(entry_activate_cb), action ); - g_signal_connect( G_OBJECT(child), "key-press-event", G_CALLBACK(keypress_cb), action ); - } - - gtk_activatable_set_related_action( GTK_ACTIVATABLE (item), GTK_ACTION( action ) ); - gtk_widget_show_all( item ); - - } else { - - item = GTK_ACTION_CLASS(ink_comboboxentry_action_parent_class)->create_tool_item( action ); - - } - - return item; -} - -// Create a drop-down menu. -GtkWidget* create_menu_item( GtkAction* action ) -{ - GtkWidget* item = nullptr; - - item = GTK_ACTION_CLASS(ink_comboboxentry_action_parent_class)->create_menu_item( action ); - g_warning( "ink_comboboxentry_action: create_menu_item not implemented" ); - // One can easily modify ege-select-one-action routine to implement this. - return item; -} - -// Setters/Getters --------------------------------------------------- - -GtkTreeModel *ink_comboboxentry_action_get_model( Ink_ComboBoxEntry_Action* action ) { - - return action->model; -} - -GtkComboBox *ink_comboboxentry_action_get_comboboxentry( Ink_ComboBoxEntry_Action* action ) { - - return action->combobox; -} - -gchar* ink_comboboxentry_action_get_active_text( Ink_ComboBoxEntry_Action* action ) { - - gchar* text = g_strdup( action->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 ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* action, const gchar* text, int row ) { - - if( strcmp( action->text, text ) != 0 ) { - g_free( action->text ); - action->text = g_strdup( text ); - } - - // Get active row or -1 if none - if( row < 0 ) { - row = get_active_row_from_text( action, action->text ); - } - action->active = row; - - // Set active row, check that combobox has been created. - if( action->combobox ) { - gtk_combo_box_set_active( GTK_COMBO_BOX( action->combobox ), action->active ); - } - - // Fiddle with entry - if( action->entry ) { - - // Explicitly set text in GtkEntry box (won't be set if text not in list). - gtk_entry_set_text( action->entry, text ); - - // Show or hide warning -- this might be better moved to text-toolbox.cpp - if( action->info_cb_id != 0 && - !action->info_cb_blocked ) { - g_signal_handler_block (G_OBJECT(action->entry), - action->info_cb_id ); - action->info_cb_blocked = true; - } - if( action->warning_cb_id != 0 && - !action->warning_cb_blocked ) { - g_signal_handler_block (G_OBJECT(action->entry), - action->warning_cb_id ); - action->warning_cb_blocked = true; - } - - bool set = false; - if( action->warning != nullptr ) { - Glib::ustring missing = check_comma_separated_text( action ); - if( !missing.empty() ) { - gtk_entry_set_icon_from_icon_name( action->entry, - GTK_ENTRY_ICON_SECONDARY, - INKSCAPE_ICON("dialog-warning") ); - // Can't add tooltip until icon set - Glib::ustring warning = action->warning; - warning += ": "; - warning += missing; - gtk_entry_set_icon_tooltip_text( action->entry, - GTK_ENTRY_ICON_SECONDARY, - warning.c_str() ); - - if( action->warning_cb ) { - - // Add callback if we haven't already - if( action->warning_cb_id == 0 ) { - action->warning_cb_id = - g_signal_connect( G_OBJECT(action->entry), - "icon-press", - G_CALLBACK(action->warning_cb), - action); - } - // Unblock signal - if( action->warning_cb_blocked ) { - g_signal_handler_unblock (G_OBJECT(action->entry), - action->warning_cb_id ); - action->warning_cb_blocked = false; - } - } - set = true; - } - } - - if( !set && action->info != nullptr ) { - gtk_entry_set_icon_from_icon_name( GTK_ENTRY(action->entry), - GTK_ENTRY_ICON_SECONDARY, - INKSCAPE_ICON("edit-select-all") ); - gtk_entry_set_icon_tooltip_text( action->entry, - GTK_ENTRY_ICON_SECONDARY, - action->info ); - - if( action->info_cb ) { - // Add callback if we haven't already - if( action->info_cb_id == 0 ) { - action->info_cb_id = - g_signal_connect( G_OBJECT(action->entry), - "icon-press", - G_CALLBACK(action->info_cb), - action); - } - // Unblock signal - if( action->info_cb_blocked ) { - g_signal_handler_unblock (G_OBJECT(action->entry), - action->info_cb_id ); - action->info_cb_blocked = false; - } - } - set = true; - } - - if( !set ) { - gtk_entry_set_icon_from_icon_name( GTK_ENTRY(action->entry), - GTK_ENTRY_ICON_SECONDARY, - nullptr ); - } - } - - // Return if active text in list - gboolean found = ( action->active != -1 ); - return found; -} - -void ink_comboboxentry_action_set_entry_width( Ink_ComboBoxEntry_Action* action, gint entry_width ) { - - action->entry_width = entry_width; - - // Widget may not have been created.... - if( action->entry ) { - gtk_entry_set_width_chars( GTK_ENTRY(action->entry), entry_width ); - } -} - -void ink_comboboxentry_action_set_extra_width( Ink_ComboBoxEntry_Action* action, gint extra_width ) { - - action->extra_width = extra_width; - - // Widget may not have been created.... - if( action->combobox ) { - GtkRequisition req; - gtk_widget_get_preferred_size(GTK_WIDGET(action->combobox), &req, nullptr); - gtk_widget_set_size_request( GTK_WIDGET( action->combobox ), req.width + action->extra_width, -1 ); - } -} - -void ink_comboboxentry_action_popup_enable( Ink_ComboBoxEntry_Action* action ) { - - action->popup = true; - - // Widget may not have been created.... - if( action->entry ) { - - // Check we don't already have a GtkEntryCompletion - if( action->entry_completion ) return; - - action->entry_completion = gtk_entry_completion_new(); - - gtk_entry_set_completion( action->entry, action->entry_completion ); - gtk_entry_completion_set_model( action->entry_completion, action->model ); - gtk_entry_completion_set_text_column( action->entry_completion, 0 ); - gtk_entry_completion_set_popup_completion( action->entry_completion, true ); - gtk_entry_completion_set_inline_completion( action->entry_completion, false ); - gtk_entry_completion_set_inline_selection( action->entry_completion, true ); - - g_signal_connect (G_OBJECT (action->entry_completion), "match-selected", G_CALLBACK (match_selected_cb), action ); - - - } -} - -void ink_comboboxentry_action_popup_disable( Ink_ComboBoxEntry_Action* action ) { - - action->popup = false; - - if( action->entry_completion ) { - gtk_widget_destroy(GTK_WIDGET(action->entry_completion)); - action->entry_completion = nullptr; - } -} -void ink_comboboxentry_action_set_tooltip( Ink_ComboBoxEntry_Action* action, const gchar* tooltip ) { - - // Widget may not have been created.... - if( action->entry ) { - gtk_widget_set_tooltip_text ( GTK_WIDGET(action->entry), tooltip); - } - if( action->combobox ) { - gtk_widget_set_tooltip_text ( GTK_WIDGET(action->combobox), tooltip); - } - -} - -void ink_comboboxentry_action_set_info( Ink_ComboBoxEntry_Action* action, const gchar* info ) { - - g_free( action->info ); - action->info = g_strdup( info ); - - // Widget may not have been created.... - if( action->entry ) { - gtk_entry_set_icon_tooltip_text( GTK_ENTRY(action->entry), - GTK_ENTRY_ICON_SECONDARY, - action->info ); - } -} - -void ink_comboboxentry_action_set_info_cb( Ink_ComboBoxEntry_Action* action, gpointer info_cb ) { - - action->info_cb = info_cb; -} - -void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, const gchar* warning ) { - - g_free( action->warning ); - action->warning = g_strdup( warning ); - - // Widget may not have been created.... - if( action->entry ) { - gtk_entry_set_icon_tooltip_text( GTK_ENTRY(action->entry), - GTK_ENTRY_ICON_SECONDARY, - action->warning ); - } -} - -void ink_comboboxentry_action_set_warning_cb( Ink_ComboBoxEntry_Action* action, gpointer warning_cb ) { - - action->warning_cb = warning_cb; -} - -void ink_comboboxentry_action_set_altx_name( Ink_ComboBoxEntry_Action* action, const gchar* altx_name ) { - - g_free( action->altx_name ); - action->altx_name = g_strdup( altx_name ); - - // Widget may not have been created.... - if( action->entry ) { - g_object_set_data( G_OBJECT(action->entry), action->altx_name, action->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 get_active_row_from_text( Ink_ComboBoxEntry_Action* 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 -static Glib::ustring check_comma_separated_text( Ink_ComboBoxEntry_Action* action ) { - - Glib::ustring missing; - - // Parse fallback_list using a comma as deliminator - gchar** tokens = g_strsplit( action->text, ",", 0 ); - - gint i = 0; - while( tokens[i] != nullptr ) { - - // Remove any surrounding white space. - g_strstrip( tokens[i] ); - - if( get_active_row_from_text( action, 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 --------------------------------------------------- - -static void 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 - Ink_ComboBoxEntry_Action *action = INK_COMBOBOXENTRY_ACTION( 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 - g_signal_emit( G_OBJECT(action), signals[CHANGED], 0 ); - } -} - -static void entry_activate_cb( GtkEntry* widget, gpointer data ) { - - // Get text from entry box.. check if it matches a menu entry. - - // Get action - Ink_ComboBoxEntry_Action *action = INK_COMBOBOXENTRY_ACTION( 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 - g_signal_emit( G_OBJECT(action), signals[CHANGED], 0 ); - -} - -static gboolean match_selected_cb( GtkEntryCompletion* /*widget*/, GtkTreeModel* model, GtkTreeIter* iter, gpointer data ) -{ - // Get action - Ink_ComboBoxEntry_Action *action = INK_COMBOBOXENTRY_ACTION( 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 - g_signal_emit( G_OBJECT(action), signals[CHANGED], 0 ); - - return true; - } - return false; -} - -static void ink_comboboxentry_action_defocus( Ink_ComboBoxEntry_Action* action ) -{ - if ( action->focusWidget ) { - gtk_widget_grab_focus( action->focusWidget ); - } -} - -gboolean keypress_cb( GtkWidget * /*widget*/, GdkEventKey *event, gpointer data ) -{ - gboolean wasConsumed = FALSE; /* default to report event not consumed */ - guint key = 0; - Ink_ComboBoxEntry_Action* action = INK_COMBOBOXENTRY_ACTION( 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 ); - ink_comboboxentry_action_defocus( action ); - wasConsumed = TRUE; - } - break; - - case GDK_KEY_Return: - case GDK_KEY_KP_Enter: - { - ink_comboboxentry_action_defocus( action ); - //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/widgets/ink-comboboxentry-action.h b/src/widgets/ink-comboboxentry-action.h deleted file mode 100644 index fa7dd5cdf..000000000 --- a/src/widgets/ink-comboboxentry-action.h +++ /dev/null @@ -1,107 +0,0 @@ -// 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 <gtk/gtk.h> - -#define INK_COMBOBOXENTRY_TYPE_ACTION (ink_comboboxentry_action_get_type()) -#define INK_COMBOBOXENTRY_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INK_COMBOBOXENTRY_TYPE_ACTION, Ink_ComboBoxEntry_Action)) -#define INK_COMBOBOXENTRY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INK_COMBOBOXENTRY_TYPE_ACTION, Ink_ComboBoxEntry_ActionClass)) -#define INK_COMBOBOXENTRY_IS_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INK_COMBOBOXENTRY_TYPE_ACTION)) -#define INK_COMBOBOXENTRY_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INK_COMBOBOXENTRY_TYPE_ACTION, Ink_ComboBoxEntry_ActionClass)) - -typedef struct _Ink_ComboBoxEntry_ActionClass Ink_ComboBoxEntry_ActionClass; -typedef struct _Ink_ComboBoxEntry_Action Ink_ComboBoxEntry_Action; - -struct _Ink_ComboBoxEntry_ActionClass { - GtkActionClass parent_class; - - void (*changed) (Ink_ComboBoxEntry_Action* action); - void (*activated) (Ink_ComboBoxEntry_Action* action); -}; - -struct _Ink_ComboBoxEntry_Action { - GtkAction parent_instance; - - GtkTreeModel *model; - GtkComboBox *combobox; - GtkEntry *entry; - GtkEntryCompletion *entry_completion; - GtkWidget *indicator; - - gpointer cell_data_func; // drop-down menu format - gpointer separator_func; - - gint active; // Index of active menu item (-1 if not in list). - gchar *text; // Text of active menu item or entry box. - gint entry_width;// Width of GtkEntry in characters. - gint extra_width;// Extra Width of GtkComboBox.. to widen drop-down list in list mode. - gboolean popup; // Do we pop-up an entry-completion dialog? - 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. - GtkWidget *focusWidget; -}; - - -GType ink_comboboxentry_action_get_type (); - -/** - * Creates a GtkAction subclass that wraps a GtkComboBoxEntry object. - */ -Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new ( const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *stock_id, - GtkTreeModel *model, - gint entry_width = -1, - gint extra_width = -1, - gpointer cell_data_func = nullptr, - gpointer separator_func = nullptr, - GtkWidget* focusWidget = nullptr); - -GtkTreeModel *ink_comboboxentry_action_get_model( Ink_ComboBoxEntry_Action* action ); -GtkComboBox *ink_comboboxentry_action_get_comboboxentry( Ink_ComboBoxEntry_Action* action ); - -gchar* ink_comboboxentry_action_get_active_text( Ink_ComboBoxEntry_Action* action ); -gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* action, const gchar* text, int row=-1 ); - -void ink_comboboxentry_action_set_entry_width( Ink_ComboBoxEntry_Action* action, gint entry_width ); -void ink_comboboxentry_action_set_extra_width( Ink_ComboBoxEntry_Action* action, gint extra_width ); - -void ink_comboboxentry_action_popup_enable( Ink_ComboBoxEntry_Action* action ); -void ink_comboboxentry_action_popup_disable( Ink_ComboBoxEntry_Action* action ); - -void ink_comboboxentry_action_set_info( Ink_ComboBoxEntry_Action* action, const gchar* info ); -void ink_comboboxentry_action_set_info_cb( Ink_ComboBoxEntry_Action* action, gpointer info_cb ); -void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, const gchar* warning_cb ); -void ink_comboboxentry_action_set_warning_cb(Ink_ComboBoxEntry_Action* action, gpointer warning ); -void ink_comboboxentry_action_set_tooltip( Ink_ComboBoxEntry_Action* action, const gchar* tooltip ); - -void ink_comboboxentry_action_set_altx_name( Ink_ComboBoxEntry_Action* action, const gchar* altx_name ); - -#endif /* SEEN_INK_COMBOBOXENTRY_ACTION */ diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index b3f25c764..10a24a0d1 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -60,7 +60,6 @@ #include "ui/widget/style-swatch.h" #include "ui/widget/unit-tracker.h" -#include "widgets/ege-adjustment-action.h" #include "widgets/spinbutton-events.h" #include "widgets/spw-utilities.h" #include "widgets/widget-sizes.h" @@ -182,63 +181,64 @@ static struct { gchar const *type_name; gchar const *data_name; GtkWidget *(*create_func)(SPDesktop *desktop); - GtkWidget *(*prep_func)(SPDesktop *desktop, GtkActionGroup* mainActions); gchar const *ui_name; gint swatch_verb_id; gchar const *swatch_tool; gchar const *swatch_tip; } const aux_toolboxes[] = { - { "/tools/select", "select_toolbox", Inkscape::UI::Toolbar::SelectToolbar::create, nullptr, "SelectToolbar", - SP_VERB_INVALID, nullptr, nullptr}, - { "/tools/nodes", "node_toolbox", Inkscape::UI::Toolbar::NodeToolbar::create, nullptr, "NodeToolbar", - SP_VERB_INVALID, nullptr, nullptr}, - { "/tools/tweak", "tweak_toolbox", Inkscape::UI::Toolbar::TweakToolbar::create, nullptr, "TweakToolbar", - SP_VERB_CONTEXT_TWEAK_PREFS, "/tools/tweak", N_("Color/opacity used for color tweaking")}, - { "/tools/spray", "spray_toolbox", Inkscape::UI::Toolbar::SprayToolbar::create, nullptr, "SprayToolbar", - SP_VERB_INVALID, nullptr, nullptr}, - { "/tools/zoom", "zoom_toolbox", Inkscape::UI::Toolbar::ZoomToolbar::create, nullptr, "ZoomToolbar", - SP_VERB_INVALID, nullptr, nullptr}, + { "/tools/select", "select_toolbox", Inkscape::UI::Toolbar::SelectToolbar::create, "SelectToolbar", + SP_VERB_INVALID, nullptr, nullptr}, + { "/tools/nodes", "node_toolbox", Inkscape::UI::Toolbar::NodeToolbar::create, "NodeToolbar", + SP_VERB_INVALID, nullptr, nullptr}, + { "/tools/tweak", "tweak_toolbox", Inkscape::UI::Toolbar::TweakToolbar::create, "TweakToolbar", + SP_VERB_CONTEXT_TWEAK_PREFS, "/tools/tweak", N_("Color/opacity used for color tweaking")}, + { "/tools/spray", "spray_toolbox", Inkscape::UI::Toolbar::SprayToolbar::create, "SprayToolbar", + SP_VERB_INVALID, nullptr, nullptr}, + { "/tools/zoom", "zoom_toolbox", Inkscape::UI::Toolbar::ZoomToolbar::create, "ZoomToolbar", + SP_VERB_INVALID, nullptr, nullptr}, // If you change MeasureToolbar here, change it also in desktop-widget.cpp - { "/tools/measure", "measure_toolbox", Inkscape::UI::Toolbar::MeasureToolbar::create, nullptr, "MeasureToolbar", - SP_VERB_INVALID, nullptr, nullptr}, - { "/tools/shapes/star", "star_toolbox", Inkscape::UI::Toolbar::StarToolbar::create, nullptr, "StarToolbar", - SP_VERB_CONTEXT_STAR_PREFS, "/tools/shapes/star", N_("Style of new stars")}, - { "/tools/shapes/rect", "rect_toolbox", Inkscape::UI::Toolbar::RectToolbar::create, nullptr, "RectToolbar", - SP_VERB_CONTEXT_RECT_PREFS, "/tools/shapes/rect", N_("Style of new rectangles")}, - { "/tools/shapes/3dbox", "3dbox_toolbox", Inkscape::UI::Toolbar::Box3DToolbar::create, nullptr, "3DBoxToolbar", - SP_VERB_CONTEXT_3DBOX_PREFS, "/tools/shapes/3dbox", N_("Style of new 3D boxes")}, - { "/tools/shapes/arc", "arc_toolbox", Inkscape::UI::Toolbar::ArcToolbar::create, nullptr, "ArcToolbar", - SP_VERB_CONTEXT_ARC_PREFS, "/tools/shapes/arc", N_("Style of new ellipses")}, - { "/tools/shapes/spiral", "spiral_toolbox", Inkscape::UI::Toolbar::SpiralToolbar::create, nullptr, "SpiralToolbar", - SP_VERB_CONTEXT_SPIRAL_PREFS, "/tools/shapes/spiral", N_("Style of new spirals")}, - { "/tools/freehand/pencil", "pencil_toolbox", Inkscape::UI::Toolbar::PencilToolbar::create_pencil, nullptr, "PencilToolbar", - SP_VERB_CONTEXT_PENCIL_PREFS, "/tools/freehand/pencil", N_("Style of new paths created by Pencil")}, - { "/tools/freehand/pen", "pen_toolbox", Inkscape::UI::Toolbar::PencilToolbar::create_pen, nullptr, "PenToolbar", - SP_VERB_CONTEXT_PEN_PREFS, "/tools/freehand/pen", N_("Style of new paths created by Pen")}, - { "/tools/calligraphic", "calligraphy_toolbox", Inkscape::UI::Toolbar::CalligraphyToolbar::create, nullptr, "CalligraphyToolbar", - SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS, "/tools/calligraphic", N_("Style of new calligraphic strokes")}, - { "/tools/eraser", "eraser_toolbox", Inkscape::UI::Toolbar::EraserToolbar::create, nullptr, "EraserToolbar", - SP_VERB_CONTEXT_ERASER_PREFS, "/tools/eraser", _("TBD")}, - { "/tools/lpetool", "lpetool_toolbox", Inkscape::UI::Toolbar::LPEToolbar::create, nullptr, "LPEToolToolbar", - SP_VERB_CONTEXT_LPETOOL_PREFS, "/tools/lpetool", _("TBD")}, + { "/tools/measure", "measure_toolbox", Inkscape::UI::Toolbar::MeasureToolbar::create, "MeasureToolbar", + SP_VERB_INVALID, nullptr, nullptr}, + { "/tools/shapes/star", "star_toolbox", Inkscape::UI::Toolbar::StarToolbar::create, "StarToolbar", + SP_VERB_CONTEXT_STAR_PREFS, "/tools/shapes/star", N_("Style of new stars")}, + { "/tools/shapes/rect", "rect_toolbox", Inkscape::UI::Toolbar::RectToolbar::create, "RectToolbar", + SP_VERB_CONTEXT_RECT_PREFS, "/tools/shapes/rect", N_("Style of new rectangles")}, + { "/tools/shapes/3dbox", "3dbox_toolbox", Inkscape::UI::Toolbar::Box3DToolbar::create, "3DBoxToolbar", + SP_VERB_CONTEXT_3DBOX_PREFS, "/tools/shapes/3dbox", N_("Style of new 3D boxes")}, + { "/tools/shapes/arc", "arc_toolbox", Inkscape::UI::Toolbar::ArcToolbar::create, "ArcToolbar", + SP_VERB_CONTEXT_ARC_PREFS, "/tools/shapes/arc", N_("Style of new ellipses")}, + { "/tools/shapes/spiral", "spiral_toolbox", Inkscape::UI::Toolbar::SpiralToolbar::create, "SpiralToolbar", + SP_VERB_CONTEXT_SPIRAL_PREFS, "/tools/shapes/spiral", N_("Style of new spirals")}, + { "/tools/freehand/pencil", "pencil_toolbox", Inkscape::UI::Toolbar::PencilToolbar::create_pencil, "PencilToolbar", + SP_VERB_CONTEXT_PENCIL_PREFS, "/tools/freehand/pencil", N_("Style of new paths created by Pencil")}, + { "/tools/freehand/pen", "pen_toolbox", Inkscape::UI::Toolbar::PencilToolbar::create_pen, "PenToolbar", + SP_VERB_CONTEXT_PEN_PREFS, "/tools/freehand/pen", N_("Style of new paths created by Pen")}, + { "/tools/calligraphic", "calligraphy_toolbox", Inkscape::UI::Toolbar::CalligraphyToolbar::create, "CalligraphyToolbar", + SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS, "/tools/calligraphic", N_("Style of new calligraphic strokes")}, + { "/tools/eraser", "eraser_toolbox", Inkscape::UI::Toolbar::EraserToolbar::create, "EraserToolbar", + SP_VERB_CONTEXT_ERASER_PREFS, "/tools/eraser", _("TBD")}, + { "/tools/lpetool", "lpetool_toolbox", Inkscape::UI::Toolbar::LPEToolbar::create, "LPEToolToolbar", + SP_VERB_CONTEXT_LPETOOL_PREFS, "/tools/lpetool", _("TBD")}, // If you change TextToolbar here, change it also in desktop-widget.cpp - { "/tools/text", "text_toolbox", nullptr, Inkscape::UI::Toolbar::TextToolbar::prep, "TextToolbar", - SP_VERB_INVALID, nullptr, nullptr}, - { "/tools/dropper", "dropper_toolbox", Inkscape::UI::Toolbar::DropperToolbar::create, nullptr, "DropperToolbar", - SP_VERB_INVALID, nullptr, nullptr}, - { "/tools/connector", "connector_toolbox", Inkscape::UI::Toolbar::ConnectorToolbar::create, nullptr, "ConnectorToolbar", - SP_VERB_INVALID, nullptr, nullptr}, - { "/tools/gradient", "gradient_toolbox", Inkscape::UI::Toolbar::GradientToolbar::create, nullptr, "GradientToolbar", - SP_VERB_INVALID, nullptr, nullptr}, - { "/tools/mesh", "mesh_toolbox", Inkscape::UI::Toolbar::MeshToolbar::create, nullptr, "MeshToolbar", - SP_VERB_INVALID, nullptr, nullptr}, + { "/tools/text", "text_toolbox", Inkscape::UI::Toolbar::TextToolbar::create, "TextToolbar", + SP_VERB_INVALID, nullptr, nullptr}, + { "/tools/dropper", "dropper_toolbox", Inkscape::UI::Toolbar::DropperToolbar::create, "DropperToolbar", + SP_VERB_INVALID, nullptr, nullptr}, + { "/tools/connector", "connector_toolbox", Inkscape::UI::Toolbar::ConnectorToolbar::create, "ConnectorToolbar", + SP_VERB_INVALID, nullptr, nullptr}, + { "/tools/gradient", "gradient_toolbox", Inkscape::UI::Toolbar::GradientToolbar::create, "GradientToolbar", + SP_VERB_INVALID, nullptr, nullptr}, + { "/tools/mesh", "mesh_toolbox", Inkscape::UI::Toolbar::MeshToolbar::create, "MeshToolbar", + SP_VERB_INVALID, nullptr, nullptr}, #if HAVE_POTRACE - { "/tools/paintbucket", "paintbucket_toolbox", Inkscape::UI::Toolbar::PaintbucketToolbar::create, nullptr, "PaintbucketToolbar", - SP_VERB_CONTEXT_PAINTBUCKET_PREFS, "/tools/paintbucket", N_("Style of Paint Bucket fill objects")}, + { "/tools/paintbucket", "paintbucket_toolbox", Inkscape::UI::Toolbar::PaintbucketToolbar::create, "PaintbucketToolbar", + SP_VERB_CONTEXT_PAINTBUCKET_PREFS, "/tools/paintbucket", N_("Style of Paint Bucket fill objects")}, #else - { "/tools/paintbucket", "paintbucket_toolbox", nullptr, nullptr, "PaintbucketToolbar", SP_VERB_NONE, "/tools/paintbucket", N_("Disabled")}, + { "/tools/paintbucket", "paintbucket_toolbox", nullptr, "PaintbucketToolbar", + SP_VERB_NONE, "/tools/paintbucket", N_("Disabled")}, #endif - { nullptr, nullptr, nullptr, nullptr, nullptr, SP_VERB_INVALID, nullptr, nullptr } + { nullptr, nullptr, nullptr, nullptr, + SP_VERB_INVALID, nullptr, nullptr } }; @@ -464,55 +464,6 @@ static GtkWidget* createCustomSlider( GtkAdjustment *adjustment, gdouble climbRa return widget; } -EgeAdjustmentAction * create_adjustment_action( gchar const *name, - gchar const *label, gchar const *shortLabel, gchar const *tooltip, - Glib::ustring const &path, gdouble def, - gboolean altx, gchar const *altx_mark, - gdouble lower, gdouble upper, gdouble step, gdouble page, - gchar const** descrLabels, gdouble const* descrValues, guint descrCount, - Inkscape::UI::Widget::UnitTracker *unit_tracker, - gdouble climb/* = 0.1*/, guint digits/* = 3*/, double factor/* = 1.0*/ ) -{ - static bool init = false; - if ( !init ) { - init = true; - ege_adjustment_action_set_compact_tool_factory( createCustomSlider ); - } - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( prefs->getDouble(path, def) * factor, - lower, upper, step, page, 0 ) ); - - EgeAdjustmentAction* act = ege_adjustment_action_new( adj, name, label, tooltip, nullptr, climb, digits, unit_tracker ); - if ( shortLabel ) { - g_object_set( act, "short_label", shortLabel, NULL ); - } - - if ( (descrCount > 0) && descrLabels && descrValues ) { - ege_adjustment_action_set_descriptions( act, descrLabels, descrValues, descrCount ); - } - - // The EgeAdjustmentAction class uses this to create a data member - // with the specified name, that simply points to the object itself. - // It appears to only be used by the DesktopWidget to find the named - // object - // - // TODO: Get rid of this and look up widgets by name instead. - if ( altx && altx_mark ) { - g_object_set( G_OBJECT(act), "self-id", altx_mark, NULL ); - } - - if (unit_tracker) { - unit_tracker->addAdjustment(adj); - } - - // Using a cast just to make sure we pass in the right kind of function pointer - g_object_set( G_OBJECT(act), "tool-post", static_cast<EgeWidgetFixup>(sp_set_font_size_smaller), NULL ); - - return act; -} - - void ToolboxFactory::setToolboxDesktop(GtkWidget *toolbox, SPDesktop *desktop) { sigc::connection *conn = static_cast<sigc::connection*>(g_object_get_data(G_OBJECT(toolbox), @@ -723,60 +674,20 @@ void update_tool_toolbox( SPDesktop *desktop, ToolBase *eventcontext, GtkWidget * * \details This is the one that appears below the main menu, and contains * tool-specific toolbars. Each toolbar is created here, using - * either: - * * Its "create" method - this directly prepares a GtkToolbar - * widget, containing all the tools, or - * * Its "prep" method - this defines a set of GtkActions, which - * are later used to populate a toolbar. + * its "create" method. + * * The actual method used for each toolbar is specified in the * "aux_toolboxes" array, defined above. - * - * \todo Needs to be rewritten so that GtkActions and GtkUIManager - * are not used. This means that the "prep" approach is deprecated - * and we should adapt all toolbars to have a "create" method instead. */ void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); GtkSizeGroup* grouper = gtk_size_group_new( GTK_SIZE_GROUP_BOTH ); - Glib::RefPtr<Gtk::ActionGroup> mainActions = create_or_fetch_actions( desktop ); - - // The UI Manager creates widgets based on the definitions in the - // "toolbar-select.ui" file. This is only used with the "prep" - // method of toolbar-creation - GtkUIManager* mgr = gtk_ui_manager_new(); - GError *err = nullptr; - gtk_ui_manager_insert_action_group( mgr, mainActions->gobj(), 0 ); - Glib::ustring filename = get_filename(UIS, "toolbar-select.ui"); - guint ret = gtk_ui_manager_add_ui_from_file(mgr, filename.c_str(), &err); - if(err) { - g_warning("Failed to load aux toolbar %s: %s", filename.c_str(), err->message); - g_error_free(err); - return; - } - - // For the "prep" method, we create a "fake" set of toolbars - // that just contain a set of GtkActions. These are stored - // in the "dataHolders" map. - std::map<std::string, GtkWidget*> dataHolders; // Loop through all the toolboxes and create them using either - // their "prep" or "create" methods. + // their "create" methods. for (int i = 0 ; aux_toolboxes[i].type_name ; i++ ) { - if ( aux_toolboxes[i].prep_func ) { - - // For the "prep" method, create a "fake" toolbar - // that only contains a set of GtkActions. In other - // words, this doesn't actually show anything... it - // just defines behaviour. - GtkWidget* kludge = aux_toolboxes[i].prep_func(desktop, mainActions->gobj()); - gtk_widget_set_name( kludge, "Kludge" ); - dataHolders[aux_toolboxes[i].type_name] = kludge; - } else if (aux_toolboxes[i].create_func) { - - // For the "create" method, directly create a "real" toolbar, - // which contains visible, fully functional widgets. Note that - // this should also contain any swatches that are needed. + if (aux_toolboxes[i].create_func) { GtkWidget *sub_toolbox = aux_toolboxes[i].create_func(desktop); gtk_widget_set_name( sub_toolbox, "SubToolBox" ); @@ -824,78 +735,6 @@ void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) } } - // Second pass to create toolbars *after* all GtkActions are created - // This is only used for toolbars that are being created using the "prep" - // method - for (int i = 0 ; aux_toolboxes[i].type_name ; i++ ) { - if ( aux_toolboxes[i].prep_func ) { - - // Get the previously created "fake" toolbar that just contains - // invisible GtkAction definitions - auto kludge = dataHolders[aux_toolboxes[i].type_name]; - - // The thing that we put into the toolbox is actually a GtkGrid. - // It contains three elements... from left-to-right: - // * A "real" toolbar containing all the visible, fully functional - // widgets - // * (optionally) A swatch widget for use with that toolbar - // * The "fake" toolbar containing the action definitions, which we - // created previously - auto holder = gtk_grid_new(); - gtk_widget_set_name( holder, aux_toolboxes[i].ui_name ); - - // First pack the "fake" toolbar with the action definitions - gtk_grid_attach( GTK_GRID(holder), kludge, 2, 0, 1, 1); - - // Now, use the UI Manager to create a "real" toolbar. This works - // because the actions needed by the UI file have all been defined - // in the "fake" toolbar - gchar* tmp = g_strdup_printf( "/ui/%s", aux_toolboxes[i].ui_name ); - GtkWidget* toolBar = gtk_ui_manager_get_widget( mgr, tmp ); - g_free( tmp ); - tmp = nullptr; - - // This part is just for styling - if ( prefs->getBool( "/toolbox/icononly", true) ) { - gtk_toolbar_set_style( GTK_TOOLBAR(toolBar), GTK_TOOLBAR_ICONS ); - } - - GtkIconSize toolboxSize = ToolboxFactory::prefToSize("/toolbox/small"); - gtk_toolbar_set_icon_size( GTK_TOOLBAR(toolBar), static_cast<GtkIconSize>(toolboxSize) ); - gtk_widget_set_hexpand(toolBar, TRUE); - gtk_grid_attach( GTK_GRID(holder), toolBar, 0, 0, 1, 1); - - // Add a swatch widget if one was specified - if ( aux_toolboxes[i].swatch_verb_id != SP_VERB_INVALID ) { - Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch( nullptr, _(aux_toolboxes[i].swatch_tip) ); - swatch->setDesktop( desktop ); - swatch->setClickVerb( aux_toolboxes[i].swatch_verb_id ); - swatch->setWatchedTool( aux_toolboxes[i].swatch_tool, true ); - swatch->set_margin_start(AUX_BETWEEN_BUTTON_GROUPS); - swatch->set_margin_end(AUX_BETWEEN_BUTTON_GROUPS); - swatch->set_margin_top(AUX_SPACING); - swatch->set_margin_bottom(AUX_SPACING); - - auto swatch_ = GTK_WIDGET( swatch->gobj() ); - gtk_grid_attach( GTK_GRID(holder), swatch_, 1, 0, 1, 1); - } - if(i==0){ - gtk_widget_show_all( holder ); - } else { - gtk_widget_show_now( holder ); - } - sp_set_font_size_smaller( holder ); - - gtk_size_group_add_widget( grouper, holder ); - - // Finally add the grid to the toolbox. - // As described above, a pointer is also stored so that toolbars can be - // switched later. - gtk_container_add( GTK_CONTAINER(toolbox), holder ); - g_object_set_data( G_OBJECT(toolbox), aux_toolboxes[i].data_name, holder ); - } - } - g_object_unref( G_OBJECT(grouper) ); } diff --git a/src/widgets/toolbox.h b/src/widgets/toolbox.h index f396f4d9a..3a1bb4cc3 100644 --- a/src/widgets/toolbox.h +++ b/src/widgets/toolbox.h @@ -20,8 +20,6 @@ #define TOOLBAR_SLIDER_HINT "compact" -typedef struct _EgeAdjustmentAction EgeAdjustmentAction; - class SPDesktop; namespace Inkscape { @@ -72,18 +70,6 @@ public: } // namespace UI } // namespace Inkscape - -// utility - - EgeAdjustmentAction * create_adjustment_action( gchar const *name, - gchar const *label, gchar const *shortLabel, gchar const *tooltip, - Glib::ustring const &path, gdouble def, - gboolean altx, gchar const *altx_mark, - gdouble lower, gdouble upper, gdouble step, gdouble page, - gchar const** descrLabels, gdouble const* descrValues, guint descrCount, - Inkscape::UI::Widget::UnitTracker *unit_tracker = nullptr, - gdouble climb = 0.1, guint digits = 3, double factor = 1.0 ); - #endif /* !SEEN_TOOLBOX_H */ /* |
