summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorAlexander Valavanis <valavanisalex@gmail.com>2018-12-29 17:21:51 +0000
committerAlexander Valavanis <valavanisalex@gmail.com>2018-12-29 17:21:51 +0000
commitc86cbcffd19cc7408b02991a8ae30bba86b62bbc (patch)
tree8422d3169aa599e97ecdb7ec59ee3f832bcc17d3 /src/widgets
parentRm deprecated budget widgets (diff)
downloadinkscape-c86cbcffd19cc7408b02991a8ae30bba86b62bbc.tar.gz
inkscape-c86cbcffd19cc7408b02991a8ae30bba86b62bbc.zip
Move Button to Inkscape namespace
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/CMakeLists.txt2
-rw-r--r--src/widgets/button.cpp274
-rw-r--r--src/widgets/button.h92
-rw-r--r--src/widgets/desktop-widget.cpp34
-rw-r--r--src/widgets/desktop-widget.h11
-rw-r--r--src/widgets/toolbox.cpp18
6 files changed, 34 insertions, 397 deletions
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt
index 4bd1504f7..1180ed736 100644
--- a/src/widgets/CMakeLists.txt
+++ b/src/widgets/CMakeLists.txt
@@ -2,7 +2,6 @@
add_subdirectory(gimp)
set(widgets_SRC
- button.cpp
desktop-widget.cpp
eek-preview.cpp
ege-adjustment-action.cpp
@@ -31,7 +30,6 @@ set(widgets_SRC
# -------
# Headers
- button.h
desktop-widget.h
eek-preview.h
ege-adjustment-action.h
diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp
deleted file mode 100644
index 199a69b34..000000000
--- a/src/widgets/button.cpp
+++ /dev/null
@@ -1,274 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/** @file
- * Generic button widget
- *//*
- * Authors:
- * see git history
- * MenTaLguY <mental@rydia.net>
- * Lauris Kaplinski <lauris@kaplinski.com>
- * bulia byak <buliabyak@users.sf.net>
- *
- *
- * Copyright (C) 2018 Authors
- * Released under GNU GPL v2+, read the file 'COPYING' for more information.
- */
-
-#include <glibmm.h>
-
-#include "button.h"
-#include "helper/action-context.h"
-#include "helper/action.h"
-#include "shortcuts.h"
-#include "ui/icon-loader.h"
-#include "ui/interface.h"
-
-SPButton::~SPButton()
-{
- if (_action) {
- _c_set_active.disconnect();
- _c_set_sensitive.disconnect();
- g_object_unref(_action);
- }
-
- if (_doubleclick_action) {
- set_doubleclick_action(nullptr);
- }
-
- _c_set_active.~connection();
- _c_set_sensitive.~connection();
-}
-
-void
-SPButton::get_preferred_width_vfunc(int &minimal_width, int &natural_width) const
-{
- auto child = get_child();
-
- if (child) {
- child->get_preferred_width(minimal_width, natural_width);
- } else {
- minimal_width = 0;
- natural_width = 0;
- }
-
- auto context = get_style_context();
-
- auto padding = context->get_padding(Gtk::STATE_FLAG_NORMAL);
- auto border = context->get_border(Gtk::STATE_FLAG_NORMAL);
-
- minimal_width += MAX(2, padding.get_left() + padding.get_right() + border.get_left() + border.get_right());
- natural_width += MAX(2, padding.get_left() + padding.get_right() + border.get_left() + border.get_right());
-}
-
-void
-SPButton::get_preferred_height_vfunc(int &minimal_height, int &natural_height) const
-{
- auto child = get_child();
-
- if (child) {
- child->get_preferred_height(minimal_height, natural_height);
- } else {
- minimal_height = 0;
- natural_height = 0;
- }
-
- auto context = get_style_context();
-
- auto padding = context->get_padding(Gtk::STATE_FLAG_NORMAL);
- auto border = context->get_border(Gtk::STATE_FLAG_NORMAL);
-
- minimal_height += MAX(2, padding.get_top() + padding.get_bottom() + border.get_top() + border.get_bottom());
- natural_height += MAX(2, padding.get_top() + padding.get_bottom() + border.get_top() + border.get_bottom());
-}
-
-void
-SPButton::on_clicked()
-{
- if (_type == SP_BUTTON_TYPE_TOGGLE) {
- Gtk::Button::on_clicked();
- }
-}
-
-bool
-SPButton::process_event(GdkEvent *event)
-{
- switch (event->type) {
- case GDK_2BUTTON_PRESS:
- if (_doubleclick_action) {
- sp_action_perform(_doubleclick_action, nullptr);
- }
- return true;
- break;
- default:
- break;
- }
-
- return false;
-}
-
-void
-SPButton::perform_action()
-{
- if (_action) {
- sp_action_perform(_action, nullptr);
- }
-}
-
-SPButton::SPButton(GtkIconSize size,
- SPButtonType type,
- SPAction *action,
- SPAction *doubleclick_action)
- :
- _action(nullptr),
- _doubleclick_action(nullptr),
- _type(type),
- _lsize(CLAMP(size, GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_DIALOG))
-{
- new (&_c_set_active) sigc::connection();
- new (&_c_set_sensitive) sigc::connection();
-
- set_border_width(0);
-
- set_can_focus(false);
- set_can_default(false);
-
- _on_clicked = signal_clicked().connect(sigc::mem_fun(*this, &SPButton::perform_action));
-
- signal_event().connect(sigc::mem_fun(*this, &SPButton::process_event));
-
- set_action(action);
-
- if (doubleclick_action) {
- set_doubleclick_action(doubleclick_action);
- }
-
- // The Inkscape style is no-relief buttons
- set_relief(Gtk::RELIEF_NONE);
-}
-
-void
-SPButton::toggle_set_down(bool down)
-{
- _on_clicked.block();
- set_active(down);
- _on_clicked.unblock();
-}
-
-void
-SPButton::set_doubleclick_action(SPAction *action)
-{
- if (_doubleclick_action) {
- g_object_unref(_doubleclick_action);
- }
- _doubleclick_action = action;
- if (action) {
- g_object_ref(action);
- }
-}
-
-void
-SPButton::set_action(SPAction *action)
-{
- Gtk::Widget *child;
-
- if (_action) {
- _c_set_active.disconnect();
- _c_set_sensitive.disconnect();
- child = get_child();
- if (child) {
- remove();
- }
- g_object_unref(_action);
- }
-
- _action = action;
- if (action) {
- g_object_ref(action);
- _c_set_active = action->signal_set_active.connect(
- sigc::mem_fun(*this, &SPButton::action_set_active));
-
- _c_set_sensitive = action->signal_set_sensitive.connect(
- sigc::mem_fun(*this, &Gtk::Widget::set_sensitive));
-
- if (action->image) {
- child = Glib::wrap(sp_get_icon_image(action->image, _lsize));
- child->show();
- add(*child);
- }
- }
-
- set_composed_tooltip(action);
-}
-
-void
-SPButton::action_set_active(bool active)
-{
- if (_type != SP_BUTTON_TYPE_TOGGLE) {
- return;
- }
-
- /* temporarily lobotomized until SPActions are per-view */
- if (false && !active != !get_active()) {
- toggle_set_down(active);
- }
-}
-
-void
-SPButton::set_composed_tooltip(SPAction *action)
-{
- if (action) {
- unsigned int shortcut = sp_shortcut_get_primary(action->verb);
- if (shortcut != GDK_KEY_VoidSymbol) {
- // there's both action and shortcut
-
- gchar *key = sp_shortcut_get_label(shortcut);
-
- gchar *tip = g_strdup_printf("%s (%s)", action->tip, key);
- set_tooltip_text(tip);
- g_free(tip);
- g_free(key);
- } else {
- // action has no shortcut
- set_tooltip_text(action->tip);
- }
- } else {
- // no action
- set_tooltip_text(nullptr);
- }
-}
-
-SPButton::SPButton(GtkIconSize size,
- SPButtonType type,
- Inkscape::UI::View::View *view,
- const gchar *name,
- const gchar *tip)
- :
- _action(nullptr),
- _doubleclick_action(nullptr),
- _type(type),
- _lsize(CLAMP(size, GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_DIALOG))
-{
- new (&_c_set_active) sigc::connection();
- new (&_c_set_sensitive) sigc::connection();
- set_border_width(0);
-
- set_can_focus(false);
- set_can_default(false);
-
- _on_clicked = signal_clicked().connect(sigc::mem_fun(*this, &SPButton::perform_action));
- signal_event().connect(sigc::mem_fun(*this, &SPButton::process_event));
-
- auto action = sp_action_new(Inkscape::ActionContext(view), name, name, tip, name, nullptr);
- set_action(action);
- g_object_unref(action);
-}
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 :
diff --git a/src/widgets/button.h b/src/widgets/button.h
deleted file mode 100644
index 736eed273..000000000
--- a/src/widgets/button.h
+++ /dev/null
@@ -1,92 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/** @file
- * Generic button widget
- *//*
- * Authors:
- * see git history
- * Lauris Kaplinski <lauris@kaplinski.com>
- *
- * Copyright (C) 2018 Authors
- * Released under GNU GPL v2+, read the file 'COPYING' for more information.
- */
-#ifndef SEEN_SP_BUTTON_H
-#define SEEN_SP_BUTTON_H
-
-#include <gtkmm/togglebutton.h>
-#include <sigc++/connection.h>
-
-struct SPAction;
-
-namespace Inkscape {
-namespace UI {
-namespace View {
-class View;
-}
-}
-}
-
-enum SPButtonType {
- SP_BUTTON_TYPE_NORMAL,
- SP_BUTTON_TYPE_TOGGLE
-};
-
-struct SPBChoiceData {
- guchar *px;
-};
-
-class SPButton : public Gtk::ToggleButton{
-private:
- SPButtonType _type;
- GtkIconSize _lsize;
- unsigned int _psize;
- SPAction *_action;
- SPAction *_doubleclick_action;
-
- sigc::connection _c_set_active;
- sigc::connection _c_set_sensitive;
-
- void set_action(SPAction *action);
- void set_doubleclick_action(SPAction *action);
- void set_composed_tooltip(SPAction *action);
- void action_set_active(bool active);
- void perform_action();
- bool process_event(GdkEvent *event);
-
- sigc::connection _on_clicked;
-
-protected:
- virtual void get_preferred_width_vfunc(int &minimum_width, int &natural_width) const override;
- virtual void get_preferred_height_vfunc(int &minimum_height, int &natural_height) const override;
- void on_clicked() override;
-
-public:
- SPButton(GtkIconSize size,
- SPButtonType type,
- SPAction *action,
- SPAction *doubleclick_action);
-
- SPButton(GtkIconSize size,
- SPButtonType type,
- Inkscape::UI::View::View *view,
- const gchar *name,
- const gchar *tip);
-
- ~SPButton();
-
- void toggle_set_down(bool down);
-};
-
-#define SP_BUTTON_IS_DOWN(b) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))
-
-#endif // !SEEN_SP_BUTTON_H
-
-/*
- 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 :
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index cc92f0f78..dab0e5fdf 100644
--- a/src/widgets/desktop-widget.cpp
+++ b/src/widgets/desktop-widget.cpp
@@ -33,8 +33,6 @@
#include <gtkmm/separator.h>
#include <gtkmm/separatormenuitem.h>
-
-
#include <gdkmm/types.h>
#if GTK_CHECK_VERSION(3,20,0)
#include <gdkmm/seat.h>
@@ -76,6 +74,7 @@
#include "ui/interface.h"
#include "ui/tools/box3d-tool.h"
#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"
@@ -86,7 +85,6 @@
#include "util/units.h"
// We're in the "widgets" directory, so no need to explicitly prefix these:
-#include "button.h"
#include "gimp/ruler.h"
#include "spinbutton-events.h"
#include "spw-utilities.h"
@@ -382,11 +380,11 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
// Lock guides button
- dtw->_guides_lock = Gtk::manage(new SPButton( GTK_ICON_SIZE_MENU,
- SP_BUTTON_TYPE_TOGGLE,
- nullptr,
- INKSCAPE_ICON("object-locked"),
- _("Toggle lock of all guides in the document")));
+ dtw->_guides_lock = Gtk::manage(new Inkscape::UI::Widget::Button(GTK_ICON_SIZE_MENU,
+ Inkscape::UI::Widget::BUTTON_TYPE_TOGGLE,
+ nullptr,
+ INKSCAPE_ICON("object-locked"),
+ _("Toggle lock of all guides in the document")));
auto guides_lock_style_provider = Gtk::CssProvider::create();
guides_lock_style_provider->load_from_data("GtkWidget { padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; }");
@@ -440,11 +438,11 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
dtw->_canvas_tbl->attach(*dtw->_vscrollbar_box, 2, 0, 1, 2);
// Sticky zoom button
- dtw->_sticky_zoom = Gtk::manage(new SPButton( GTK_ICON_SIZE_MENU,
- SP_BUTTON_TYPE_TOGGLE,
- nullptr,
- INKSCAPE_ICON("zoom-original"),
- _("Zoom drawing if window size changes")));
+ dtw->_sticky_zoom = Gtk::manage(new Inkscape::UI::Widget::Button(GTK_ICON_SIZE_MENU,
+ Inkscape::UI::Widget::BUTTON_TYPE_TOGGLE,
+ nullptr,
+ INKSCAPE_ICON("zoom-original"),
+ _("Zoom drawing if window size changes")));
dtw->_sticky_zoom->set_name("StickyZoom");
dtw->_sticky_zoom->set_active(prefs->getBool("/options/stickyzoom/value"));
dtw->_sticky_zoom->signal_toggled().connect(sigc::mem_fun(dtw, &SPDesktopWidget::sticky_zoom_toggled));
@@ -464,11 +462,11 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
tip = act->tip;
}
}
- dtw->_cms_adjust = Gtk::manage(new SPButton( GTK_ICON_SIZE_MENU,
- SP_BUTTON_TYPE_TOGGLE,
- nullptr,
- INKSCAPE_ICON("color-management"),
- tip ));
+ dtw->_cms_adjust = Gtk::manage(new Inkscape::UI::Widget::Button(GTK_ICON_SIZE_MENU,
+ Inkscape::UI::Widget::BUTTON_TYPE_TOGGLE,
+ nullptr,
+ INKSCAPE_ICON("color-management"),
+ tip ));
dtw->_cms_adjust->set_name("CMS_Adjust");
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
diff --git a/src/widgets/desktop-widget.h b/src/widgets/desktop-widget.h
index a16dbd2c7..078508fa5 100644
--- a/src/widgets/desktop-widget.h
+++ b/src/widgets/desktop-widget.h
@@ -26,7 +26,6 @@
// forward declaration
typedef struct _EgeColorProfTracker EgeColorProfTracker;
-class SPButton;
struct SPCanvas;
struct SPCanvasItem;
class SPDesktop;
@@ -43,6 +42,14 @@ class SpinButton;
class ToggleButton;
}
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+class Button;
+}
+}
+}
+
#define SP_TYPE_DESKTOP_WIDGET SPDesktopWidget::getType()
#define SP_DESKTOP_WIDGET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SP_TYPE_DESKTOP_WIDGET, SPDesktopWidget))
#define SP_DESKTOP_WIDGET_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), SP_TYPE_DESKTOP_WIDGET, SPDesktopWidgetClass))
@@ -109,7 +116,7 @@ private:
Gtk::ToggleButton *_guides_lock;
- SPButton *_cms_adjust;
+ Inkscape::UI::Widget::Button *_cms_adjust;
Gtk::ToggleButton *_sticky_zoom;
Gtk::Grid *_coord_status;
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index 924e49140..fe105aea6 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -55,11 +55,11 @@
#include "ui/interface.h"
#include "ui/tools-switch.h"
#include "ui/uxmanager.h"
+#include "ui/widget/button.h"
#include "ui/widget/spinbutton.h"
#include "ui/widget/style-swatch.h"
#include "ui/widget/unit-tracker.h"
-#include "widgets/button.h"
#include "widgets/ege-adjustment-action.h"
#include "widgets/spinbutton-events.h"
#include "widgets/spw-utilities.h"
@@ -258,7 +258,7 @@ static void update_aux_toolbox(SPDesktop *desktop, ToolBase *eventcontext, GtkWi
static void setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop);
static void update_commands_toolbox(SPDesktop *desktop, ToolBase *eventcontext, GtkWidget *toolbox);
-static GtkToolItem * sp_toolbox_button_item_new_from_verb_with_doubleclick( GtkWidget *t, GtkIconSize size, SPButtonType type,
+static GtkToolItem * sp_toolbox_button_item_new_from_verb_with_doubleclick( GtkWidget *t, GtkIconSize size, Inkscape::UI::Widget::ButtonType type,
Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb,
Inkscape::UI::View::View *view);
@@ -325,12 +325,12 @@ Gtk::Widget* VerbAction::create_tool_item_vfunc()
GtkIconSize toolboxSize = ToolboxFactory::prefToSize("/toolbox/tools/small");
GtkWidget* toolbox = nullptr;
auto holder = Glib::wrap(sp_toolbox_button_item_new_from_verb_with_doubleclick( toolbox, toolboxSize,
- SP_BUTTON_TYPE_TOGGLE,
+ Inkscape::UI::Widget::BUTTON_TYPE_TOGGLE,
verb,
verb2,
view ));
- auto button_widget = static_cast<SPButton *>(holder->get_child());
+ auto button_widget = static_cast<Inkscape::UI::Widget::Button *>(holder->get_child());
if ( active ) {
button_widget->toggle_set_down(active);
@@ -360,8 +360,8 @@ void VerbAction::set_active(bool active)
for ( Glib::SListHandle<Gtk::Widget*>::iterator it = proxies.begin(); it != proxies.end(); ++it ) {
Gtk::ToolItem* ti = dynamic_cast<Gtk::ToolItem*>(*it);
if (ti) {
- // *should* have one child that is the SPButton
- auto child = dynamic_cast<SPButton *>(ti->get_child());
+ // *should* have one child that is the Inkscape::UI::Widget::Button
+ auto child = dynamic_cast<Inkscape::UI::Widget::Button *>(ti->get_child());
if (child) {
child->toggle_set_down(active);
}
@@ -458,7 +458,7 @@ void delete_prefspusher(GObject * /*obj*/, PrefPusher *watcher )
// ------------------------------------------------------
-GtkToolItem * sp_toolbox_button_item_new_from_verb_with_doubleclick(GtkWidget *t, GtkIconSize size, SPButtonType type,
+GtkToolItem * sp_toolbox_button_item_new_from_verb_with_doubleclick(GtkWidget *t, GtkIconSize size, Inkscape::UI::Widget::ButtonType type,
Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb,
Inkscape::UI::View::View *view)
{
@@ -475,8 +475,8 @@ GtkToolItem * sp_toolbox_button_item_new_from_verb_with_doubleclick(GtkWidget *t
}
/* fixme: Handle sensitive/unsensitive */
- /* fixme: Implement SPButton construction from action */
- auto b = Gtk::manage(new SPButton(size, type, action, doubleclick_action));
+ /* fixme: Implement Inkscape::UI::Widget::Button construction from action */
+ auto b = Gtk::manage(new Inkscape::UI::Widget::Button(size, type, action, doubleclick_action));
b->show();
auto b_toolitem = Gtk::manage(new Gtk::ToolItem());
b_toolitem->add(*b);