diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2011-08-28 19:18:21 +0000 |
|---|---|---|
| committer | Krzysztof Kosinski <tweenk.pl@gmail.com> | 2011-08-28 19:18:21 +0000 |
| commit | be7df18d6aef42dd657426b6a9d30834e5f54ca6 (patch) | |
| tree | 9bc96a469b9cf6595004d1733d1b7104eb764092 /src | |
| parent | Remove last forward declaration of NRPixBlock (diff) | |
| download | inkscape-be7df18d6aef42dd657426b6a9d30834e5f54ca6.tar.gz inkscape-be7df18d6aef42dd657426b6a9d30834e5f54ca6.zip | |
Remove nr-object.h and nr-macros.h
(bzr r10582.1.10)
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/effect.cpp | 18 | ||||
| -rw-r--r-- | src/extension/effect.h | 4 | ||||
| -rw-r--r-- | src/helper/action.cpp | 185 | ||||
| -rw-r--r-- | src/helper/action.h | 51 | ||||
| -rw-r--r-- | src/interface.cpp | 37 | ||||
| -rw-r--r-- | src/libnr/Makefile_insert | 3 | ||||
| -rw-r--r-- | src/libnr/nr-macros.h | 61 | ||||
| -rw-r--r-- | src/libnr/nr-object.cpp | 318 | ||||
| -rw-r--r-- | src/libnr/nr-object.h | 157 | ||||
| -rw-r--r-- | src/verbs.cpp | 232 | ||||
| -rw-r--r-- | src/verbs.h | 4 | ||||
| -rw-r--r-- | src/widgets/button.cpp | 62 | ||||
| -rw-r--r-- | src/widgets/button.h | 5 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 26 |
14 files changed, 181 insertions, 982 deletions
diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index e01eb760a..b42caca06 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -355,21 +355,15 @@ Effect::set_pref_dialog (PrefDialog * prefdialog) return; } -/** \brief Create an action for a \c EffectVerb - \param view Which view the action should be created for - \return The built action. - - Calls \c make_action_helper with the \c vector. -*/ SPAction * Effect::EffectVerb::make_action (Inkscape::UI::View::View * view) { - return make_action_helper(view, &vector, static_cast<void *>(this)); + return make_action_helper(view, &perform, static_cast<void *>(this)); } /** \brief Decode the verb code and take appropriate action */ void -Effect::EffectVerb::perform( SPAction *action, void * data, void */*pdata*/ ) +Effect::EffectVerb::perform( SPAction *action, void * data ) { Inkscape::UI::View::View * current_view = sp_action_get_view(action); // SPDocument * current_document = current_view->doc; @@ -388,14 +382,6 @@ Effect::EffectVerb::perform( SPAction *action, void * data, void */*pdata*/ ) return; } -/** - * Action vector to define functions called if a staticly defined file verb - * is called. - */ -SPActionEventVector Effect::EffectVerb::vector = - {{NULL}, Effect::EffectVerb::perform, NULL, NULL, NULL, NULL}; - - } } /* namespace Inkscape, Extension */ /* diff --git a/src/extension/effect.h b/src/extension/effect.h index 28ebc5d96..61a826ad4 100644 --- a/src/extension/effect.h +++ b/src/extension/effect.h @@ -53,9 +53,7 @@ class Effect : public Extension { back to the effect that created it. */ class EffectVerb : public Inkscape::Verb { private: - static void perform (SPAction * action, void * mydata, void * otherdata); - /** \brief Function to call for specific actions */ - static SPActionEventVector vector; + static void perform (SPAction * action, void * mydata); /** \brief The effect that this verb represents. */ Effect * _effect; diff --git a/src/helper/action.cpp b/src/helper/action.cpp index 84d150615..3eb881300 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -1,5 +1,3 @@ -#define __SP_ACTION_C__ - /** \file * SPAction implementation * @@ -23,26 +21,31 @@ static void sp_action_class_init (SPActionClass *klass); static void sp_action_init (SPAction *action); -static void sp_action_finalize (NRObject *object); +static void sp_action_finalize (GObject *object); -static NRActiveObjectClass *parent_class; +static GObjectClass *parent_class; /** * Register SPAction class and return its type. */ -NRType +GType sp_action_get_type (void) { - static unsigned int type = 0; - if (!type) { - type = nr_object_register_type (NR_TYPE_ACTIVE_OBJECT, - "SPAction", - sizeof (SPActionClass), - sizeof (SPAction), - (void (*) (NRObjectClass *)) sp_action_class_init, - (void (*) (NRObject *)) sp_action_init); - } - return type; + static GType type = 0; + if (!type) { + GTypeInfo info = { + sizeof(SPActionClass), + NULL, NULL, + (GClassInitFunc) sp_action_class_init, + NULL, NULL, + sizeof(SPAction), + 0, + (GInstanceInitFunc) sp_action_init, + NULL + }; + type = g_type_register_static(G_TYPE_OBJECT, "SPAction", &info, (GTypeFlags)0); + } + return type; } /** @@ -51,14 +54,10 @@ sp_action_get_type (void) static void sp_action_class_init (SPActionClass *klass) { - NRObjectClass * object_class; - - object_class = (NRObjectClass *) klass; + parent_class = (GObjectClass*) g_type_class_ref(G_TYPE_OBJECT); - parent_class = (NRActiveObjectClass *) (((NRObjectClass *) klass)->parent); - - object_class->finalize = sp_action_finalize; - object_class->cpp_ctor = NRObject::invoke_ctor<SPAction>; + GObjectClass *object_class = (GObjectClass *) klass; + object_class->finalize = sp_action_finalize; } /** @@ -72,24 +71,32 @@ sp_action_init (SPAction *action) action->view = NULL; action->id = action->name = action->tip = NULL; action->image = NULL; + + new (&action->signal_perform) sigc::signal<void>(); + new (&action->signal_set_sensitive) sigc::signal<void, bool>(); + new (&action->signal_set_active) sigc::signal<void, bool>(); + new (&action->signal_set_name) sigc::signal<void, Glib::ustring const &>(); } /** * Called before SPAction object destruction. */ static void -sp_action_finalize (NRObject *object) +sp_action_finalize (GObject *object) { - SPAction *action; + SPAction *action = SP_ACTION(object); - action = (SPAction *) object; + g_free (action->image); + g_free (action->tip); + g_free (action->name); + g_free (action->id); - if (action->image) free (action->image); - if (action->tip) free (action->tip); - if (action->name) free (action->name); - if (action->id) free (action->id); + action->signal_perform.~signal(); + action->signal_set_sensitive.~signal(); + action->signal_set_active.~signal(); + action->signal_set_name.~signal(); - ((NRObjectClass *) (parent_class))->finalize (object); + parent_class->finalize (object); } /** @@ -103,14 +110,14 @@ sp_action_new(Inkscape::UI::View::View *view, const gchar *image, Inkscape::Verb * verb) { - SPAction *action = (SPAction *)nr_object_new(SP_TYPE_ACTION); + SPAction *action = (SPAction *)g_object_new(SP_TYPE_ACTION, NULL); action->view = view; action->sensitive = TRUE; - if (id) action->id = strdup (id); - if (name) action->name = strdup (name); - if (tip) action->tip = strdup (tip); - if (image) action->image = strdup (image); + action->id = g_strdup (id); + action->name = g_strdup (name); + action->tip = g_strdup (tip); + action->image = g_strdup (image); action->verb = verb; return action; @@ -147,41 +154,16 @@ public: \return None \brief Executes an action \param action The action to be executed - \param data Data that is passed into the action. This depends - on the situation that the action is used in. - - This function implements the 'action' in SPActions. It first validates - its parameters, making sure it got an action passed in. Then it - turns that action into its parent class of NRActiveObject. The - NRActiveObject allows for listeners to be attached to it. This - function goes through those listeners and calls them with the - vector that was attached to the listener. + \param data ignored */ void sp_action_perform (SPAction *action, void * data) { - NRActiveObject *aobject; - - nr_return_if_fail (action != NULL); - nr_return_if_fail (SP_IS_ACTION (action)); + g_return_if_fail (action != NULL); + g_return_if_fail (SP_IS_ACTION (action)); Inkscape::Debug::EventTracker<ActionEvent> tracker(action); - - aobject = NR_ACTIVE_OBJECT(action); - if (aobject->callbacks) { - unsigned int i; - for (i = 0; i < aobject->callbacks->length; i++) { - NRObjectListener *listener; - SPActionEventVector *avector; - - listener = &aobject->callbacks->listeners[i]; - avector = (SPActionEventVector *) listener->vector; - - if ((listener->size >= sizeof (SPActionEventVector)) && avector != NULL && avector->perform != NULL) { - avector->perform (action, listener->data, data); - } - } - } + action->signal_perform.emit(); } /** @@ -190,26 +172,10 @@ sp_action_perform (SPAction *action, void * data) void sp_action_set_active (SPAction *action, unsigned int active) { - nr_return_if_fail (action != NULL); - nr_return_if_fail (SP_IS_ACTION (action)); + g_return_if_fail (action != NULL); + g_return_if_fail (SP_IS_ACTION (action)); - if (active != action->active) { - NRActiveObject *aobject; - action->active = active; - aobject = (NRActiveObject *) action; - if (aobject->callbacks) { - unsigned int i; - for (i = 0; i < aobject->callbacks->length; i++) { - NRObjectListener *listener; - SPActionEventVector *avector; - listener = aobject->callbacks->listeners + i; - avector = (SPActionEventVector *) listener->vector; - if ((listener->size >= sizeof (SPActionEventVector)) && avector->set_active) { - avector->set_active (action, active, listener->data); - } - } - } - } + action->signal_set_active.emit(active); } /** @@ -218,59 +184,20 @@ sp_action_set_active (SPAction *action, unsigned int active) void sp_action_set_sensitive (SPAction *action, unsigned int sensitive) { - nr_return_if_fail (action != NULL); - nr_return_if_fail (SP_IS_ACTION (action)); + g_return_if_fail (action != NULL); + g_return_if_fail (SP_IS_ACTION (action)); - if (sensitive != action->sensitive) { - NRActiveObject *aobject; - action->sensitive = sensitive; - aobject = (NRActiveObject *) action; - if (aobject->callbacks) { - unsigned int i; - for (i = 0; i < aobject->callbacks->length; i++) { - NRObjectListener *listener; - SPActionEventVector *avector; - listener = aobject->callbacks->listeners + i; - avector = (SPActionEventVector *) listener->vector; - if ((listener->size >= sizeof (SPActionEventVector)) && avector->set_sensitive) { - avector->set_sensitive (action, sensitive, listener->data); - } - } - } - } + action->signal_set_sensitive.emit(sensitive); } - -/** - * Change name for all actions that can be taken with the action. - */ void -sp_action_set_name (SPAction *action, Glib::ustring name) +sp_action_set_name (SPAction *action, Glib::ustring const &name) { - nr_return_if_fail (action != NULL); - nr_return_if_fail (SP_IS_ACTION (action)); - - NRActiveObject *aobject; - g_free(action->name); - action->name = g_strdup(name.c_str()); - aobject = (NRActiveObject *) action; - if (aobject->callbacks) { - unsigned int i; - for (i = 0; i < aobject->callbacks->length; i++) { - NRObjectListener *listener; - SPActionEventVector *avector; - listener = aobject->callbacks->listeners + i; - avector = (SPActionEventVector *) listener->vector; - if ((listener->size >= sizeof (SPActionEventVector)) && avector->set_name) { - avector->set_name (action, name, listener->data); - } - } - } + g_free(action->name); + action->name = g_strdup(name.data()); + action->signal_set_name.emit(name); } - - - /** * Return View associated with the action. */ diff --git a/src/helper/action.h b/src/helper/action.h index 14a91b453..7e4da3312 100644 --- a/src/helper/action.h +++ b/src/helper/action.h @@ -1,11 +1,6 @@ -#ifndef __SP_ACTION_H__ -#define __SP_ACTION_H__ - /** \file * Inkscape UI action implementation - */ - -/* + *//* * Author: * Lauris Kaplinski <lauris@kaplinski.com> * @@ -14,41 +9,27 @@ * This code is in public domain */ -/** A macro to get the GType for actions */ -#define SP_TYPE_ACTION (sp_action_get_type()) -/** A macro to cast and check the cast of changing an object to an action */ -#define SP_ACTION(o) (NR_CHECK_INSTANCE_CAST((o), SP_TYPE_ACTION, SPAction)) -/** A macro to check whether or not something is an action */ -#define SP_IS_ACTION(o) (NR_CHECK_INSTANCE_TYPE((o), SP_TYPE_ACTION)) +#ifndef SEEN_INKSCAPE_SP_ACTION_H +#define SEEN_INKSCAPE_SP_ACTION_H +#include <sigc++/sigc++.h> +#include <glibmm/ustring.h> #include "helper/helper-forward.h" -#include "libnr/nr-object.h" #include "forward.h" -#include <glibmm/ustring.h> -//class Inkscape::UI::View::View; +#define SP_TYPE_ACTION (sp_action_get_type()) +#define SP_ACTION(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_ACTION, SPAction)) +#define SP_ACTION_CLASS(o) (G_TYPE_CHECK_CLASS_CAST((o), SP_TYPE_ACTION, SPActionClass)) +#define SP_IS_ACTION(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_ACTION)) namespace Inkscape { class Verb; } - -/** This is a structure that is used to hold all the possible - actions that can be taken with an action. These are the - function pointers available. */ -struct SPActionEventVector { - NRObjectEventVector object_vector; /**< Parent class */ - void (* perform)(SPAction *action, void *ldata, void *pdata); /**< Actually do the action of the event. Called by sp_perform_action */ - void (* set_active)(SPAction *action, unsigned active, void *data); /**< Callback for activation change */ - void (* set_sensitive)(SPAction *action, unsigned sensitive, void *data); /**< Callback for a change in sensitivity */ - void (* set_shortcut)(SPAction *action, unsigned shortcut, void *data); /**< Callback for setting the shortcut for this function */ - void (* set_name)(SPAction *action, Glib::ustring, void *data); /**< Callback for setting the name for this function */ -}; - /** All the data that is required to be an action. This structure identifies the action and has the data to create menus and toolbars for the action */ -struct SPAction : public NRActiveObject { +struct SPAction : public GObject { unsigned sensitive : 1; /**< Value to track whether the action is sensitive */ unsigned active : 1; /**< Value to track whether the action is active */ Inkscape::UI::View::View *view; /**< The View to which this action is attached */ @@ -57,14 +38,19 @@ struct SPAction : public NRActiveObject { gchar *tip; /**< A tooltip to describe the action */ gchar *image; /**< An image to visually identify the action */ Inkscape::Verb *verb; /**< The verb that produced this action */ + + sigc::signal<void> signal_perform; + sigc::signal<void, bool> signal_set_sensitive; + sigc::signal<void, bool> signal_set_active; + sigc::signal<void, Glib::ustring const &> signal_set_name; }; /** The action class is the same as its parent. */ struct SPActionClass { - NRActiveObjectClass parent_class; /**< Parent Class */ + GObjectClass parent_class; /**< Parent Class */ }; -NRType sp_action_get_type(); +GType sp_action_get_type(); SPAction *sp_action_new(Inkscape::UI::View::View *view, gchar const *id, @@ -76,12 +62,11 @@ SPAction *sp_action_new(Inkscape::UI::View::View *view, void sp_action_perform(SPAction *action, void *data); void sp_action_set_active(SPAction *action, unsigned active); void sp_action_set_sensitive(SPAction *action, unsigned sensitive); -void sp_action_set_name (SPAction *action, Glib::ustring); +void sp_action_set_name(SPAction *action, Glib::ustring const &name); Inkscape::UI::View::View *sp_action_get_view(SPAction *action); #endif - /* Local Variables: mode:c++ diff --git a/src/interface.cpp b/src/interface.cpp index fb0d23e1b..8cb9698b7 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -125,25 +125,12 @@ static void sp_ui_drag_leave( GtkWidget *widget, GdkDragContext *drag_context, guint event_time, gpointer user_data ); -static void sp_ui_menu_item_set_sensitive(SPAction *action, - unsigned int sensitive, - void *data); -static void sp_ui_menu_item_set_name(SPAction *action, - Glib::ustring name, - void *data); +static void sp_ui_menu_item_set_name(GtkWidget *data, + Glib::ustring const &name); static void sp_recent_open(GtkRecentChooser *, gpointer); static void injectRenamedIcons(); -SPActionEventVector menu_item_event_vector = { - {NULL}, - NULL, - NULL, /* set_active */ - sp_ui_menu_item_set_sensitive, /* set_sensitive */ - NULL, /* set_shortcut */ - sp_ui_menu_item_set_name /* set_name */ -}; - static const int MIN_ONSCREEN_DISTANCE = 50; void @@ -508,7 +495,6 @@ sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb *verb, Inkscape:: unsigned int shortcut; action = verb->get_action(view); - if (!action) return NULL; shortcut = sp_shortcut_get_primary(verb); @@ -542,7 +528,15 @@ sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb *verb, Inkscape:: gtk_container_add((GtkContainer *) item, name_lbl); } - nr_active_object_add_listener((NRActiveObject *)action, (NRObjectEventVector *)&menu_item_event_vector, sizeof(SPActionEventVector), item); + action->signal_set_sensitive.connect( + sigc::bind<0>( + sigc::ptr_fun(>k_widget_set_sensitive), + item)); + action->signal_set_name.connect( + sigc::bind<0>( + sigc::ptr_fun(&sp_ui_menu_item_set_name), + item)); + if (!action->sensitive) { gtk_widget_set_sensitive(item, FALSE); } @@ -716,7 +710,6 @@ sp_ui_menu_append_check_item_from_verb(GtkMenu *menu, Inkscape::UI::View::View * gtk_container_add((GtkContainer *) item, l); } #if 0 - nr_active_object_add_listener((NRActiveObject *)action, (NRObjectEventVector *)&menu_item_event_vector, sizeof(SPActionEventVector), item); if (!action->sensitive) { gtk_widget_set_sensitive(item, FALSE); } @@ -1587,13 +1580,7 @@ sp_ui_overwrite_file(gchar const *filename) } static void -sp_ui_menu_item_set_sensitive(SPAction */*action*/, unsigned int sensitive, void *data) -{ - return gtk_widget_set_sensitive(GTK_WIDGET(data), sensitive); -} - -static void -sp_ui_menu_item_set_name(SPAction */*action*/, Glib::ustring name, void *data) +sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name) { void *child = GTK_BIN (data)->child; //child is either diff --git a/src/libnr/Makefile_insert b/src/libnr/Makefile_insert index c4b6daa12..487f34be1 100644 --- a/src/libnr/Makefile_insert +++ b/src/libnr/Makefile_insert @@ -1,8 +1,5 @@ ## Makefile.am fragment sourced by src/Makefile.am. ink_common_sources += \ - libnr/nr-macros.h \ - libnr/nr-object.cpp \ - libnr/nr-object.h \ libnr/nr-point-fns.cpp \ libnr/nr-point-fns.h diff --git a/src/libnr/nr-macros.h b/src/libnr/nr-macros.h deleted file mode 100644 index 37a3675e6..000000000 --- a/src/libnr/nr-macros.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef __NR_MACROS_H__ -#define __NR_MACROS_H__ - -/* - * Pixel buffer rendering library - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * - * This code is in public domain - */ - -#include <math.h> - -#if HAVE_STDLIB_H -#include <stdlib.h> -#endif -#include <assert.h> - -#ifndef TRUE -#define TRUE (!0) -#endif -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef MAX -#define MAX(a,b) (((a) < (b)) ? (b) : (a)) -#endif -#ifndef MIN -#define MIN(a,b) (((a) > (b)) ? (b) : (a)) -#endif - -/** Returns v bounded to within [a, b]. If v is NaN then returns a. - * - * \pre \a a \<= \a b. - */ -#define NR_CLAMP(v,a,b) \ - (assert (a <= b), \ - ((v) >= (a)) \ - ? (((v) > (b)) \ - ? (b) \ - : (v)) \ - : (a)) - -#undef CLAMP /* get rid of glib's version, which doesn't handle NaN correctly */ -#define CLAMP(v,a,b) NR_CLAMP(v,a,b) - -#define NR_DF_TEST_CLOSE(a,b,e) (fabs ((a) - (b)) <= (e)) - -// Todo: move these into nr-matrix.h -#define NR_RECT_DFLS_TEST_EMPTY(a) (((a)->x0 >= (a)->x1) || ((a)->y0 >= (a)->y1)) -#define NR_RECT_DFLS_TEST_EMPTY_REF(a) (((a).x0 >= (a).x1) || ((a).y0 >= (a).y1)) -#define NR_RECT_DFLS_TEST_INTERSECT(a,b) (((a)->x0 < (b)->x1) && ((a)->x1 > (b)->x0) && ((a)->y0 < (b)->y1) && ((a)->y1 > (b)->y0)) -#define NR_RECT_DFLS_TEST_INTERSECT_REF(a,b) (((a).x0 < (b).x1) && ((a).x1 > (b).x0) && ((a).y0 < (b).y1) && ((a).y1 > (b).y0)) -#define NR_RECT_DF_POINT_DF_TEST_INSIDE(r,p) (((p)->x >= (r)->x0) && ((p)->x < (r)->x1) && ((p)->y >= (r)->y0) && ((p)->y < (r)->y1)) -#define NR_RECT_LS_POINT_LS_TEST_INSIDE(r,p) (((p)->x >= (r)->x0) && ((p)->x < (r)->x1) && ((p)->y >= (r)->y0) && ((p)->y < (r)->y1)) -#define NR_RECT_LS_TEST_INSIDE(r,x,y) ((x >= (r)->x0) && (x < (r)->x1) && (y >= (r)->y0) && (y < (r)->y1)) - -#define NR_MATRIX_D_FROM_DOUBLE(d) ((NR::Matrix *) &(d)[0]) - -#endif diff --git a/src/libnr/nr-object.cpp b/src/libnr/nr-object.cpp deleted file mode 100644 index d92052d10..000000000 --- a/src/libnr/nr-object.cpp +++ /dev/null @@ -1,318 +0,0 @@ -#define __NR_OBJECT_C__ - -/* - * RGBA display list system for inkscape - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * MenTaLguY <mental@rydia.net> - * - * This code is in public domain - */ - -#include <string.h> -#include <stdio.h> - -#include <typeinfo> - -#include <glib/gmem.h> -#include <libnr/nr-macros.h> - -#include "nr-object.h" -#include "debug/event-tracker.h" -#include "debug/simple-event.h" -#include "util/share.h" -#include "util/format.h" - -unsigned int nr_emit_fail_warning(const gchar *file, unsigned int line, const gchar *method, const gchar *expr) -{ - fprintf (stderr, "File %s line %d (%s): Assertion %s failed\n", file, line, method, expr); - return 1; -} - -/* NRObject */ - -static NRObjectClass **classes = NULL; -static unsigned int classes_len = 0; -static unsigned int classes_size = 0; - -NRType nr_type_is_a(NRType type, NRType test) -{ - nr_return_val_if_fail(type < classes_len, FALSE); - nr_return_val_if_fail(test < classes_len, FALSE); - - NRObjectClass *c = classes[type]; - - while (c) { - if (c->type == test) { - return TRUE; - } - c = c->parent; - } - - return FALSE; -} - -void const *nr_object_check_instance_cast(void const *ip, NRType tc) -{ - nr_return_val_if_fail(ip != NULL, NULL); - nr_return_val_if_fail(nr_type_is_a(((NRObject const *) ip)->klass->type, tc), ip); - return ip; -} - -unsigned int nr_object_check_instance_type(void const *ip, NRType tc) -{ - if (ip == NULL) { - return FALSE; - } - - return nr_type_is_a(((NRObject const *) ip)->klass->type, tc); -} - -NRType nr_object_register_type(NRType parent, - gchar const *name, - unsigned int csize, - unsigned int isize, - void (* cinit) (NRObjectClass *), - void (* iinit) (NRObject *)) -{ - if (classes_len >= classes_size) { - classes_size += 32; - classes = g_renew (NRObjectClass *, classes, classes_size); - if (classes_len == 0) { - classes[0] = NULL; - classes_len = 1; - } - } - - NRType const type = classes_len; - classes_len += 1; - - classes[type] = (NRObjectClass*) new char[csize]; - NRObjectClass *c = classes[type]; - - /* FIXME: is this necessary? */ - memset(c, 0, csize); - - if (classes[parent]) { - memcpy(c, classes[parent], classes[parent]->csize); - } - - c->type = type; - c->parent = classes[parent]; - c->name = strdup(name); - c->csize = csize; - c->isize = isize; - c->cinit = cinit; - c->iinit = iinit; - - c->cinit(c); - - return type; -} - -static void nr_object_class_init (NRObjectClass *klass); -static void nr_object_init (NRObject *object); -static void nr_object_finalize (NRObject *object); - -NRType nr_object_get_type() -{ - static NRType type = 0; - - if (!type) { - type = nr_object_register_type (0, - "NRObject", - sizeof (NRObjectClass), - sizeof (NRObject), - (void (*) (NRObjectClass *)) nr_object_class_init, - (void (*) (NRObject *)) nr_object_init); - } - - return type; -} - -static void nr_object_class_init(NRObjectClass *c) -{ - c->finalize = nr_object_finalize; - c->cpp_ctor = NRObject::invoke_ctor<NRObject>; -} - -static void nr_object_init (NRObject */*object*/) -{ -} - -static void nr_object_finalize (NRObject */*object*/) -{ -} - -/* Dynamic lifecycle */ - -static void nr_class_tree_object_invoke_init(NRObjectClass *c, NRObject *object) -{ - if (c->parent) { - nr_class_tree_object_invoke_init(c->parent, object); - } - c->iinit (object); -} - -namespace { - -namespace Debug = Inkscape::Debug; -namespace Util = Inkscape::Util; - -typedef Debug::SimpleEvent<Debug::Event::FINALIZERS> BaseFinalizerEvent; - -class FinalizerEvent : public BaseFinalizerEvent { -public: - FinalizerEvent(NRObject *object) - : BaseFinalizerEvent(Util::share_static_string("nr-object-finalizer")) - { - _addProperty("object", Util::format("%p", object)); - _addProperty("class", Util::share_static_string(typeid(*object).name())); - } -}; - -void finalize_object(void *base, void *) -{ - NRObject *object = reinterpret_cast<NRObject *>(base); - Debug::EventTracker<FinalizerEvent> tracker(object); - object->klass->finalize(object); - object->~NRObject(); -} - -} - -NRObject *NRObject::alloc(NRType type) -{ - nr_return_val_if_fail (type < classes_len, NULL); - - NRObjectClass *c = classes[type]; - - if ( c->parent && c->cpp_ctor == c->parent->cpp_ctor ) { - g_error("Cannot instantiate NRObject class %s which has not registered a C++ constructor\n", c->name); - } - - NRObject *object = reinterpret_cast<NRObject *>( - ::operator new(c->isize, Inkscape::GC::SCANNED, Inkscape::GC::AUTO, - &finalize_object, NULL) - ); - memset(object, 0xf0, c->isize); - - c->cpp_ctor(object); - object->klass = c; - nr_class_tree_object_invoke_init (c, object); - - return object; -} - -/* NRActiveObject */ - -static void nr_active_object_class_init(NRActiveObjectClass *c); -static void nr_active_object_init(NRActiveObject *object); -static void nr_active_object_finalize(NRObject *object); - -static NRObjectClass *parent_class; - -NRType nr_active_object_get_type() -{ - static NRType type = 0; - if (!type) { - type = nr_object_register_type (NR_TYPE_OBJECT, - "NRActiveObject", - sizeof (NRActiveObjectClass), - sizeof (NRActiveObject), - (void (*) (NRObjectClass *)) nr_active_object_class_init, - (void (*) (NRObject *)) nr_active_object_init); - } - return type; -} - -static void nr_active_object_class_init(NRActiveObjectClass *c) -{ - NRObjectClass *object_class = (NRObjectClass *) c; - - parent_class = object_class->parent; - - object_class->finalize = nr_active_object_finalize; - object_class->cpp_ctor = NRObject::invoke_ctor<NRActiveObject>; -} - -static void nr_active_object_init(NRActiveObject */*object*/) -{ -} - -static void nr_active_object_finalize(NRObject *object) -{ - NRActiveObject *aobject = (NRActiveObject *) object; - - if (aobject->callbacks) { - for (unsigned int i = 0; i < aobject->callbacks->length; i++) { - NRObjectListener *listener = aobject->callbacks->listeners + i; - if ( listener->vector->dispose ) { - listener->vector->dispose(object, listener->data); - } - } - g_free (aobject->callbacks); - } - - ((NRObjectClass *) (parent_class))->finalize(object); -} - -void nr_active_object_add_listener(NRActiveObject *object, - const NRObjectEventVector *vector, - unsigned int size, - void *data) -{ - if (!object->callbacks) { - object->callbacks = (NRObjectCallbackBlock*)g_malloc(sizeof(NRObjectCallbackBlock)); - object->callbacks->size = 1; - object->callbacks->length = 0; - } - - if (object->callbacks->length >= object->callbacks->size) { - int newsize = object->callbacks->size << 1; - object->callbacks = (NRObjectCallbackBlock *) - g_realloc(object->callbacks, sizeof(NRObjectCallbackBlock) + (newsize - 1) * sizeof (NRObjectListener)); - object->callbacks->size = newsize; - } - - NRObjectListener *listener = object->callbacks->listeners + object->callbacks->length; - listener->vector = vector; - listener->size = size; - listener->data = data; - object->callbacks->length += 1; -} - -void nr_active_object_remove_listener_by_data(NRActiveObject *object, void *data) -{ - if (object->callbacks == NULL) { - return; - } - - for (unsigned i = 0; i < object->callbacks->length; i++) { - NRObjectListener *listener = object->callbacks->listeners + i; - if ( listener->data == data ) { - object->callbacks->length -= 1; - if ( object->callbacks->length < 1 ) { - g_free(object->callbacks); - object->callbacks = NULL; - } else if ( object->callbacks->length != i ) { - *listener = object->callbacks->listeners[object->callbacks->length]; - } - return; - } - } -} - - - -/* - 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 : diff --git a/src/libnr/nr-object.h b/src/libnr/nr-object.h deleted file mode 100644 index 269130284..000000000 --- a/src/libnr/nr-object.h +++ /dev/null @@ -1,157 +0,0 @@ -#ifndef __NR_OBJECT_H__ -#define __NR_OBJECT_H__ - -/* - * RGBA display list system for inkscape - * - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * MenTaLguY <mental@rydia.net> - * - * This code is in public domain - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <glib/gtypes.h> -#include "gc-managed.h" -#include "gc-finalized.h" -#include "gc-anchored.h" - -typedef guint32 NRType; - -struct NRObject; -struct NRObjectClass; - -#define NR_TYPE_OBJECT (nr_object_get_type ()) -#define NR_OBJECT(o) (NR_CHECK_INSTANCE_CAST ((o), NR_TYPE_OBJECT, NRObject)) -#define NR_IS_OBJECT(o) (NR_CHECK_INSTANCE_TYPE ((o), NR_TYPE_OBJECT)) - -#define NR_TYPE_ACTIVE_OBJECT (nr_active_object_get_type ()) -#define NR_ACTIVE_OBJECT(o) (NR_CHECK_INSTANCE_CAST ((o), NR_TYPE_ACTIVE_OBJECT, NRActiveObject)) -#define NR_IS_ACTIVE_OBJECT(o) (NR_CHECK_INSTANCE_TYPE ((o), NR_TYPE_ACTIVE_OBJECT)) - -#define nr_return_if_fail(expr) if (!(expr) && nr_emit_fail_warning (__FILE__, __LINE__, "?", #expr)) return -#define nr_return_val_if_fail(expr,val) if (!(expr) && nr_emit_fail_warning (__FILE__, __LINE__, "?", #expr)) return (val) - -unsigned int nr_emit_fail_warning (const gchar *file, unsigned int line, const gchar *method, const gchar *expr); - -#ifndef NR_DISABLE_CAST_CHECKS -#define NR_CHECK_INSTANCE_CAST(ip, tc, ct) ((ct *) nr_object_check_instance_cast (ip, tc)) -#else -#define NR_CHECK_INSTANCE_CAST(ip, tc, ct) ((ct *) ip) -#endif - -#define NR_CHECK_INSTANCE_TYPE(ip, tc) nr_object_check_instance_type (ip, tc) -#define NR_OBJECT_GET_CLASS(ip) (((NRObject *) ip)->klass) - -NRType nr_type_is_a (NRType type, NRType test); - -void const *nr_object_check_instance_cast(void const *ip, NRType tc); -unsigned int nr_object_check_instance_type(void const *ip, NRType tc); - -NRType nr_object_register_type (NRType parent, - gchar const *name, - unsigned int csize, - unsigned int isize, - void (* cinit) (NRObjectClass *), - void (* iinit) (NRObject *)); - -/* NRObject */ - -class NRObject : public Inkscape::GC::Managed<>, - public Inkscape::GC::Finalized, - public Inkscape::GC::Anchored -{ -public: - NRObjectClass *klass; - - static NRObject *alloc(NRType type); - - template <typename T> - static void invoke_ctor(NRObject *object) { - new (object) T(); - } - - /* these can go away eventually */ - NRObject *reference() { - return Inkscape::GC::anchor(this); - } - NRObject *unreference() { - Inkscape::GC::release(this); - return NULL; - } - -protected: - NRObject() {} - -private: - NRObject(NRObject const &); // no copy - void operator=(NRObject const &); // no assign - - void *operator new(size_t size, void *placement) { (void)size; return placement; } -}; - -struct NRObjectClass { - NRType type; - NRObjectClass *parent; - - gchar *name; - unsigned int csize; - unsigned int isize; - void (* cinit) (NRObjectClass *); - void (* iinit) (NRObject *); - void (* finalize) (NRObject *object); - void (*cpp_ctor)(NRObject *object); -}; - -NRType nr_object_get_type (void); - -/* Dynamic lifecycle */ - -inline NRObject *nr_object_new (NRType type) { - return NRObject::alloc(type); -} - -inline NRObject *nr_object_ref (NRObject *object) { - return object->reference(); -} -inline NRObject *nr_object_unref (NRObject *object) { - return object->unreference(); -} - -/* NRActiveObject */ - -struct NRObjectEventVector { - void (* dispose) (NRObject *object, void *data); -}; - -struct NRObjectListener { - const NRObjectEventVector *vector; - unsigned int size; - void *data; -}; - -struct NRObjectCallbackBlock { - unsigned int size; - unsigned int length; - NRObjectListener listeners[1]; -}; - -struct NRActiveObject : public NRObject { - NRActiveObject() : callbacks(NULL) {} - NRObjectCallbackBlock *callbacks; -}; - -struct NRActiveObjectClass : public NRObjectClass { -}; - -NRType nr_active_object_get_type (void); - -void nr_active_object_add_listener (NRActiveObject *object, const NRObjectEventVector *vector, unsigned int size, void *data); -void nr_active_object_remove_listener_by_data (NRActiveObject *object, void *data); - -#endif - diff --git a/src/verbs.cpp b/src/verbs.cpp index ac8699654..43d100138 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -118,8 +118,7 @@ namespace Inkscape { file operations. */ class FileVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -137,8 +136,7 @@ public: edit operations. */ class EditVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -156,8 +154,7 @@ public: selection operations. */ class SelectionVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -175,8 +172,7 @@ public: layer operations. */ class LayerVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -194,8 +190,7 @@ public: operations related to objects. */ class ObjectVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -213,8 +208,7 @@ public: operations relative to context. */ class ContextVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -232,8 +226,7 @@ public: zoom operations. */ class ZoomVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -252,8 +245,7 @@ public: dialog operations. */ class DialogVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -271,8 +263,7 @@ public: help operations. */ class HelpVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -290,8 +281,7 @@ public: tutorial operations. */ class TutorialVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -309,8 +299,7 @@ public: text operations. */ class TextVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -363,9 +352,7 @@ Verb::Verb(gchar const *id, gchar const *name, gchar const *tip, gchar const *im Verb::~Verb(void) { /// \todo all the actions need to be cleaned up first. - if (_actions != NULL) { - delete _actions; - } + delete _actions; if (_full_tip) { g_free(_full_tip); @@ -395,8 +382,8 @@ Verb::make_action(Inkscape::UI::View::View */*view*/) SPAction * FileVerb::make_action(Inkscape::UI::View::View *view) { - //std::cout << "fileverb: make_action: " << &vector << std::endl; - return make_action_helper(view, &vector); + //std::cout << "fileverb: make_action: " << &perform << std::endl; + return make_action_helper(view, &perform); } /** \brief Create an action for a \c EditVerb @@ -408,8 +395,8 @@ FileVerb::make_action(Inkscape::UI::View::View *view) SPAction * EditVerb::make_action(Inkscape::UI::View::View *view) { - //std::cout << "editverb: make_action: " << &vector << std::endl; - return make_action_helper(view, &vector); + //std::cout << "editverb: make_action: " << &perform << std::endl; + return make_action_helper(view, &perform); } /** \brief Create an action for a \c SelectionVerb @@ -421,7 +408,7 @@ EditVerb::make_action(Inkscape::UI::View::View *view) SPAction * SelectionVerb::make_action(Inkscape::UI::View::View *view) { - return make_action_helper(view, &vector); + return make_action_helper(view, &perform); } /** \brief Create an action for a \c LayerVerb @@ -433,7 +420,7 @@ SelectionVerb::make_action(Inkscape::UI::View::View *view) SPAction * LayerVerb::make_action(Inkscape::UI::View::View *view) { - return make_action_helper(view, &vector); + return make_action_helper(view, &perform); } /** \brief Create an action for a \c ObjectVerb @@ -445,7 +432,7 @@ LayerVerb::make_action(Inkscape::UI::View::View *view) SPAction * ObjectVerb::make_action(Inkscape::UI::View::View *view) { - return make_action_helper(view, &vector); + return make_action_helper(view, &perform); } /** \brief Create an action for a \c ContextVerb @@ -457,7 +444,7 @@ ObjectVerb::make_action(Inkscape::UI::View::View *view) SPAction * ContextVerb::make_action(Inkscape::UI::View::View *view) { - return make_action_helper(view, &vector); + return make_action_helper(view, &perform); } /** \brief Create an action for a \c ZoomVerb @@ -469,7 +456,7 @@ ContextVerb::make_action(Inkscape::UI::View::View *view) SPAction * ZoomVerb::make_action(Inkscape::UI::View::View *view) { - return make_action_helper(view, &vector); + return make_action_helper(view, &perform); } /** \brief Create an action for a \c DialogVerb @@ -481,7 +468,7 @@ ZoomVerb::make_action(Inkscape::UI::View::View *view) SPAction * DialogVerb::make_action(Inkscape::UI::View::View *view) { - return make_action_helper(view, &vector); + return make_action_helper(view, &perform); } /** \brief Create an action for a \c HelpVerb @@ -493,7 +480,7 @@ DialogVerb::make_action(Inkscape::UI::View::View *view) SPAction * HelpVerb::make_action(Inkscape::UI::View::View *view) { - return make_action_helper(view, &vector); + return make_action_helper(view, &perform); } /** \brief Create an action for a \c TutorialVerb @@ -505,7 +492,7 @@ HelpVerb::make_action(Inkscape::UI::View::View *view) SPAction * TutorialVerb::make_action(Inkscape::UI::View::View *view) { - return make_action_helper(view, &vector); + return make_action_helper(view, &perform); } /** \brief Create an action for a \c TextVerb @@ -517,7 +504,7 @@ TutorialVerb::make_action(Inkscape::UI::View::View *view) SPAction * TextVerb::make_action(Inkscape::UI::View::View *view) { - return make_action_helper(view, &vector); + return make_action_helper(view, &perform); } /** \brief A quick little convience function to make building actions @@ -534,7 +521,7 @@ TextVerb::make_action(Inkscape::UI::View::View *view) the vector that is passed in. */ SPAction * -Verb::make_action_helper(Inkscape::UI::View::View *view, SPActionEventVector *vector, void *in_pntr) +Verb::make_action_helper(Inkscape::UI::View::View *view, void (*perform_fun)(SPAction *, void *), void *in_pntr) { SPAction *action; @@ -542,23 +529,14 @@ Verb::make_action_helper(Inkscape::UI::View::View *view, SPActionEventVector *ve action = sp_action_new(view, _id, _(_name), _(_tip), _image, this); - if (action != NULL) { - if (in_pntr == NULL) { - nr_active_object_add_listener( - (NRActiveObject *) action, - (NRObjectEventVector *) vector, - sizeof(SPActionEventVector), - reinterpret_cast<void *>(_code) - ); - } else { - nr_active_object_add_listener( - (NRActiveObject *) action, - (NRObjectEventVector *) vector, - sizeof(SPActionEventVector), - in_pntr - ); - } - } + if (action == NULL) return NULL; + + action->signal_perform.connect( + sigc::bind( + sigc::bind( + sigc::ptr_fun(perform_fun), + in_pntr ? in_pntr : reinterpret_cast<void*>(_code)), + action)); return action; } @@ -703,8 +681,8 @@ Verb::delete_view(Inkscape::UI::View::View *view) if (action_found != _actions->end()) { SPAction *action = action_found->second; - nr_object_unref(NR_OBJECT(action)); _actions->erase(action_found); + g_object_unref(action); } return; @@ -785,7 +763,7 @@ Verb::getbyid(gchar const *id) /** \brief Decode the verb code and take appropriate action */ void -FileVerb::perform(SPAction *action, void *data, void */*pdata*/) +FileVerb::perform(SPAction *action, void *data) { #if 0 /* These aren't used, but are here to remind people not to use @@ -857,7 +835,7 @@ FileVerb::perform(SPAction *action, void *data, void */*pdata*/) /** \brief Decode the verb code and take appropriate action */ void -EditVerb::perform(SPAction *action, void *data, void */*pdata*/) +EditVerb::perform(SPAction *action, void *data) { SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action)); if (!dt) @@ -988,7 +966,7 @@ EditVerb::perform(SPAction *action, void *data, void */*pdata*/) /** \brief Decode the verb code and take appropriate action */ void -SelectionVerb::perform(SPAction *action, void *data, void */*pdata*/) +SelectionVerb::perform(SPAction *action, void *data) { SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action)); @@ -1108,7 +1086,7 @@ SelectionVerb::perform(SPAction *action, void *data, void */*pdata*/) /** \brief Decode the verb code and take appropriate action */ void -LayerVerb::perform(SPAction *action, void *data, void */*pdata*/) +LayerVerb::perform(SPAction *action, void *data) { SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action)); size_t verb = reinterpret_cast<std::size_t>(data); @@ -1312,7 +1290,7 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/) /** \brief Decode the verb code and take appropriate action */ void -ObjectVerb::perform( SPAction *action, void *data, void */*pdata*/ ) +ObjectVerb::perform( SPAction *action, void *data) { SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action)); if (!dt) @@ -1395,7 +1373,7 @@ ObjectVerb::perform( SPAction *action, void *data, void */*pdata*/ ) /** \brief Decode the verb code and take appropriate action */ void -ContextVerb::perform(SPAction *action, void *data, void */*pdata*/) +ContextVerb::perform(SPAction *action, void *data) { SPDesktop *dt; sp_verb_t verb; @@ -1579,7 +1557,7 @@ ContextVerb::perform(SPAction *action, void *data, void */*pdata*/) /** \brief Decode the verb code and take appropriate action */ void -TextVerb::perform(SPAction *action, void */*data*/, void */*pdata*/) +TextVerb::perform(SPAction *action, void */*data*/) { SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action)); if (!dt) @@ -1593,7 +1571,7 @@ TextVerb::perform(SPAction *action, void */*data*/, void */*pdata*/) /** \brief Decode the verb code and take appropriate action */ void -ZoomVerb::perform(SPAction *action, void *data, void */*pdata*/) +ZoomVerb::perform(SPAction *action, void *data) { SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action)); if (!dt) @@ -1754,7 +1732,7 @@ ZoomVerb::perform(SPAction *action, void *data, void */*pdata*/) /** \brief Decode the verb code and take appropriate action */ void -DialogVerb::perform(SPAction *action, void *data, void */*pdata*/) +DialogVerb::perform(SPAction *action, void *data) { if (reinterpret_cast<std::size_t>(data) != SP_VERB_DIALOG_TOGGLE) { // unhide all when opening a new dialog @@ -1866,7 +1844,7 @@ DialogVerb::perform(SPAction *action, void *data, void */*pdata*/) /** \brief Decode the verb code and take appropriate action */ void -HelpVerb::perform(SPAction *action, void *data, void */*pdata*/) +HelpVerb::perform(SPAction *action, void *data) { SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action)); g_assert(dt->_dlg_mgr != NULL); @@ -1900,7 +1878,7 @@ HelpVerb::perform(SPAction *action, void *data, void */*pdata*/) /** \brief Decode the verb code and take appropriate action */ void -TutorialVerb::perform(SPAction */*action*/, void *data, void */*pdata*/) +TutorialVerb::perform(SPAction */*action*/, void *data) { switch (reinterpret_cast<std::size_t>(data)) { case SP_VERB_TUTORIAL_BASIC: @@ -1942,92 +1920,12 @@ TutorialVerb::perform(SPAction */*action*/, void *data, void */*pdata*/) } } // end of sp_verb_action_tutorial_perform() - -/** - * Action vector to define functions called if a staticly defined file verb - * is called. - */ -SPActionEventVector FileVerb::vector = - {{NULL},FileVerb::perform, NULL, NULL, NULL, NULL}; -/** - * Action vector to define functions called if a staticly defined edit verb is - * called. - */ -SPActionEventVector EditVerb::vector = - {{NULL},EditVerb::perform, NULL, NULL, NULL, NULL}; - -/** - * Action vector to define functions called if a staticly defined selection - * verb is called - */ -SPActionEventVector SelectionVerb::vector = - {{NULL},SelectionVerb::perform, NULL, NULL, NULL, NULL}; - -/** - * Action vector to define functions called if a staticly defined layer - * verb is called - */ -SPActionEventVector LayerVerb::vector = - {{NULL}, LayerVerb::perform, NULL, NULL, NULL, NULL}; - -/** - * Action vector to define functions called if a staticly defined object - * editing verb is called - */ -SPActionEventVector ObjectVerb::vector = - {{NULL},ObjectVerb::perform, NULL, NULL, NULL, NULL}; - -/** - * Action vector to define functions called if a staticly defined context - * verb is called - */ -SPActionEventVector ContextVerb::vector = - {{NULL},ContextVerb::perform, NULL, NULL, NULL, NULL}; - -/** - * Action vector to define functions called if a staticly defined zoom verb - * is called - */ -SPActionEventVector ZoomVerb::vector = - {{NULL},ZoomVerb::perform, NULL, NULL, NULL, NULL}; - - -/** - * Action vector to define functions called if a staticly defined dialog verb - * is called - */ -SPActionEventVector DialogVerb::vector = - {{NULL},DialogVerb::perform, NULL, NULL, NULL, NULL}; - -/** - * Action vector to define functions called if a staticly defined help verb - * is called - */ -SPActionEventVector HelpVerb::vector = - {{NULL},HelpVerb::perform, NULL, NULL, NULL, NULL}; - -/** - * Action vector to define functions called if a staticly defined tutorial verb - * is called - */ -SPActionEventVector TutorialVerb::vector = - {{NULL},TutorialVerb::perform, NULL, NULL, NULL, NULL}; - -/** - * Action vector to define functions called if a staticly defined tutorial verb - * is called - */ -SPActionEventVector TextVerb::vector = - {{NULL},TextVerb::perform, NULL, NULL, NULL, NULL}; - - /* *********** Effect Last ********** */ /** \brief A class to represent the last effect issued */ class EffectLastVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -2043,12 +1941,6 @@ public: } }; /* EffectLastVerb class */ -/** - * The vector to attach in the last effect verb. - */ -SPActionEventVector EffectLastVerb::vector = - {{NULL},EffectLastVerb::perform, NULL, NULL, NULL, NULL}; - /** \brief Create an action for a \c EffectLastVerb \param view Which view the action should be created for \return The built action. @@ -2058,12 +1950,12 @@ SPActionEventVector EffectLastVerb::vector = SPAction * EffectLastVerb::make_action(Inkscape::UI::View::View *view) { - return make_action_helper(view, &vector); + return make_action_helper(view, &perform); } /** \brief Decode the verb code and take appropriate action */ void -EffectLastVerb::perform(SPAction *action, void *data, void */*pdata*/) +EffectLastVerb::perform(SPAction *action, void *data) { /* These aren't used, but are here to remind people not to use the CURRENT_DOCUMENT macros unless they really have to. */ @@ -2094,8 +1986,7 @@ EffectLastVerb::perform(SPAction *action, void *data, void */*pdata*/) /** \brief A class to represent the canvas fitting verbs */ class FitCanvasVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -2111,12 +2002,6 @@ public: } }; /* FitCanvasVerb class */ -/** - * The vector to attach in the fit canvas verb. - */ -SPActionEventVector FitCanvasVerb::vector = - {{NULL},FitCanvasVerb::perform, NULL, NULL, NULL, NULL}; - /** \brief Create an action for a \c FitCanvasVerb \param view Which view the action should be created for \return The built action. @@ -2126,13 +2011,13 @@ SPActionEventVector FitCanvasVerb::vector = SPAction * FitCanvasVerb::make_action(Inkscape::UI::View::View *view) { - SPAction *action = make_action_helper(view, &vector); + SPAction *action = make_action_helper(view, &perform); return action; } /** \brief Decode the verb code and take appropriate action */ void -FitCanvasVerb::perform(SPAction *action, void *data, void */*pdata*/) +FitCanvasVerb::perform(SPAction *action, void *data) { SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action)); if (!dt) return; @@ -2163,8 +2048,7 @@ FitCanvasVerb::perform(SPAction *action, void *data, void */*pdata*/) /** \brief A class to represent the object unlocking and unhiding verbs */ class LockAndHideVerb : public Verb { private: - static void perform(SPAction *action, void *mydata, void *otherdata); - static SPActionEventVector vector; + static void perform(SPAction *action, void *mydata); protected: virtual SPAction *make_action(Inkscape::UI::View::View *view); public: @@ -2180,12 +2064,6 @@ public: } }; /* LockAndHideVerb class */ -/** - * The vector to attach in the lock'n'hide verb. - */ -SPActionEventVector LockAndHideVerb::vector = - {{NULL},LockAndHideVerb::perform, NULL, NULL, NULL, NULL}; - /** \brief Create an action for a \c LockAndHideVerb \param view Which view the action should be created for \return The built action. @@ -2195,13 +2073,13 @@ SPActionEventVector LockAndHideVerb::vector = SPAction * LockAndHideVerb::make_action(Inkscape::UI::View::View *view) { - SPAction *action = make_action_helper(view, &vector); + SPAction *action = make_action_helper(view, &perform); return action; } /** \brief Decode the verb code and take appropriate action */ void -LockAndHideVerb::perform(SPAction *action, void *data, void */*pdata*/) +LockAndHideVerb::perform(SPAction *action, void *data) { SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action)); if (!dt) return; diff --git a/src/verbs.h b/src/verbs.h index d20189cde..224a809b0 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -403,8 +403,8 @@ public: gchar const * set_tip (gchar const * tip) { _tip = tip; return _tip; } protected: - SPAction * make_action_helper (Inkscape::UI::View::View * view, SPActionEventVector * vector, void * in_pntr = NULL); - virtual SPAction * make_action (Inkscape::UI::View::View * view); + SPAction *make_action_helper (Inkscape::UI::View::View *view, void (*perform_fun)(SPAction *, void *), void *in_pntr = NULL); + virtual SPAction *make_action (Inkscape::UI::View::View *view); public: /** \brief Inititalizes the Verb with the parameters diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index e0b3a0fb9..1360e0a30 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -43,20 +43,10 @@ static gint sp_button_process_event (SPButton *button, GdkEvent *event); static void sp_button_set_action (SPButton *button, SPAction *action); static void sp_button_set_doubleclick_action (SPButton *button, SPAction *action); -static void sp_button_action_set_active (SPAction *action, unsigned int active, void *data); -static void sp_button_action_set_sensitive (SPAction *action, unsigned int sensitive, void *data); -static void sp_button_action_set_shortcut (SPAction *action, unsigned int shortcut, void *data); +static void sp_button_action_set_active (SPButton *button, bool active); static void sp_button_set_composed_tooltip (GtkWidget *widget, SPAction *action); static GtkToggleButtonClass *parent_class; -SPActionEventVector button_event_vector = { - {NULL}, - NULL, - sp_button_action_set_active, - sp_button_action_set_sensitive, - sp_button_action_set_shortcut, - NULL -}; GType sp_button_get_type(void) { @@ -98,6 +88,8 @@ sp_button_init (SPButton *button) { button->action = NULL; button->doubleclick_action = NULL; + new (&button->c_set_active) sigc::connection(); + new (&button->c_set_sensitive) sigc::connection(); gtk_container_set_border_width (GTK_CONTAINER (button), 0); @@ -111,18 +103,18 @@ sp_button_init (SPButton *button) static void sp_button_destroy (GtkObject *object) { - SPButton *button; - - button = SP_BUTTON (object); + SPButton *button = SP_BUTTON (object); if (button->action) { sp_button_set_action (button, NULL); } - if (button->doubleclick_action) { sp_button_set_doubleclick_action (button, NULL); } + button->c_set_active.~connection(); + button->c_set_sensitive.~connection(); + ((GtkObjectClass *) (parent_class))->destroy (object); } @@ -212,12 +204,13 @@ static void sp_button_set_doubleclick_action (SPButton *button, SPAction *action) { if (button->doubleclick_action) { - nr_object_unref ((NRObject *) button->doubleclick_action); + g_object_unref (button->doubleclick_action); } button->doubleclick_action = action; if (action) { - button->doubleclick_action = (SPAction *) nr_object_ref ((NRObject *) action); + g_object_ref(action); } + } static void @@ -226,17 +219,25 @@ sp_button_set_action (SPButton *button, SPAction *action) GtkWidget *child; if (button->action) { - nr_active_object_remove_listener_by_data ((NRActiveObject *) button->action, button); - nr_object_unref ((NRObject *) button->action); + button->c_set_active.disconnect(); + button->c_set_sensitive.disconnect(); child = gtk_bin_get_child (GTK_BIN (button)); if (child) { gtk_container_remove (GTK_CONTAINER (button), child); } + g_object_unref(button->action); } button->action = action; if (action) { - button->action = (SPAction *) nr_object_ref ((NRObject *) action); - nr_active_object_add_listener ((NRActiveObject *) action, (NRObjectEventVector *) &button_event_vector, sizeof (SPActionEventVector), button); + g_object_ref(action); + button->c_set_active = action->signal_set_active.connect( + sigc::bind<0>( + sigc::ptr_fun(&sp_button_action_set_active), + SP_BUTTON(button))); + button->c_set_sensitive = action->signal_set_sensitive.connect( + sigc::bind<0>( + sigc::ptr_fun(>k_widget_set_sensitive), + GTK_WIDGET(button))); if (action->image) { child = sp_icon_new (button->lsize, action->image); gtk_widget_show (child); @@ -248,10 +249,8 @@ sp_button_set_action (SPButton *button, SPAction *action) } static void -sp_button_action_set_active (SPAction */*action*/, unsigned int active, void *data) +sp_button_action_set_active (SPButton *button, bool active) { - SPButton *button; - button = (SPButton *) data; if (button->type != SP_BUTTON_TYPE_TOGGLE) { return; } @@ -262,19 +261,6 @@ sp_button_action_set_active (SPAction */*action*/, unsigned int active, void *da } } -static void -sp_button_action_set_sensitive (SPAction */*action*/, unsigned int sensitive, void *data) -{ - gtk_widget_set_sensitive (GTK_WIDGET (data), sensitive); -} - -static void -sp_button_action_set_shortcut (SPAction *action, unsigned int /*shortcut*/, void *data) -{ - SPButton *button=SP_BUTTON (data); - sp_button_set_composed_tooltip (GTK_WIDGET (button), action); -} - static void sp_button_set_composed_tooltip(GtkWidget *widget, SPAction *action) { if (action) { @@ -308,7 +294,7 @@ sp_button_new_from_data( Inkscape::IconSize size, GtkWidget *button; SPAction *action=sp_action_new(view, name, name, tip, name, 0); button = sp_button_new (size, type, action, NULL); - nr_object_unref ((NRObject *) action); + g_object_unref(action); return button; } diff --git a/src/widgets/button.h b/src/widgets/button.h index 759096443..41863357d 100644 --- a/src/widgets/button.h +++ b/src/widgets/button.h @@ -17,7 +17,7 @@ #define SP_IS_BUTTON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), SP_TYPE_BUTTON)) #include <gtk/gtk.h> - +#include <sigc++/sigc++.h> #include "helper/action.h" #include "icon-size.h" @@ -38,6 +38,9 @@ struct SPButton { unsigned int psize; SPAction *action; SPAction *doubleclick_action; + + sigc::connection c_set_active; + sigc::connection c_set_sensitive; }; struct SPButtonClass { diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 61c7c8e88..7edc24420 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -863,23 +863,6 @@ static void trigger_sp_action( GtkAction* /*act*/, gpointer user_data ) } } -static void sp_action_action_set_sensitive(SPAction * /*action*/, unsigned int sensitive, void *data) -{ - if ( data ) { - GtkAction* act = GTK_ACTION(data); - gtk_action_set_sensitive( act, sensitive ); - } -} - -static SPActionEventVector action_event_vector = { - {NULL}, - NULL, - NULL, - sp_action_action_set_sensitive, - NULL, - NULL -}; - static GtkAction* create_action_for_verb( Inkscape::Verb* verb, Inkscape::UI::View::View* view, Inkscape::IconSize size ) { GtkAction* act = 0; @@ -891,8 +874,13 @@ static GtkAction* create_action_for_verb( Inkscape::Verb* verb, Inkscape::UI::Vi g_signal_connect( G_OBJECT(inky), "activate", G_CALLBACK(trigger_sp_action), targetAction ); - SPAction*rebound = dynamic_cast<SPAction *>( nr_object_ref( dynamic_cast<NRObject *>(targetAction) ) ); - nr_active_object_add_listener( (NRActiveObject *)rebound, (NRObjectEventVector *)&action_event_vector, sizeof(SPActionEventVector), inky ); + // FIXME: memory leak: this is not unrefed anywhere + g_object_ref(G_OBJECT(targetAction)); + g_object_set_data_full(G_OBJECT(inky), "SPAction", (void*) targetAction, (GDestroyNotify) &g_object_unref); + targetAction->signal_set_sensitive.connect( + sigc::bind<0>( + sigc::ptr_fun(>k_action_set_sensitive), + GTK_ACTION(inky))); return act; } |
