Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / sp-switch.cpp
index 65ecc5442ffbe0a3824b444d33c8672a0fba8086..19c014b9b50e76c46168158a2f3eda7b8bcf34ce 100644 (file)
@@ -1,10 +1,11 @@
-#define __SP_SWITCH_CPP__
-
 /*
  * SVG <switch> implementation
  *
  * Authors:
  *   Andrius R. <knutux@gmail.com>
+ *   MenTaLguY  <mental@rydia.net>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2006 authors
  *
@@ -21,6 +22,9 @@
 #include "display/nr-arena-group.h"
 #include "conditions.h"
 
+#include <sigc++/functors/ptr_fun.h>
+#include <sigc++/adaptors/bind.h>
+
 static void sp_switch_class_init (SPSwitchClass *klass);
 static void sp_switch_init (SPSwitch *group);
 
@@ -60,7 +64,7 @@ static void sp_switch_init (SPSwitch *group)
     group->group = new CSwitch(group);
 }
 
-CSwitch::CSwitch(SPGroup *group) : CGroup(group), _cached_item(NULL), _release_handler_id(0) {
+CSwitch::CSwitch(SPGroup *group) : CGroup(group), _cached_item(NULL) {
 }
 
 CSwitch::~CSwitch() {
@@ -68,11 +72,13 @@ CSwitch::~CSwitch() {
 }
 
 SPObject *CSwitch::_evaluateFirst() {
-    for (SPObject *child = sp_object_first_child(_group) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
-        if (SP_IS_ITEM(child) && sp_item_evaluate(SP_ITEM(child)))
-            return child;
+    SPObject *first = 0;
+    for (SPObject *child = _group->firstChild() ; child && !first ; child = child->getNext() ) {
+        if (SP_IS_ITEM(child) && sp_item_evaluate(SP_ITEM(child))) {
+           first = child;
+       }
     }
-    return NULL;
+    return first;
 }
 
 GSList *CSwitch::_childList(bool add_ref, SPObject::Action action) {
@@ -111,7 +117,7 @@ void CSwitch::onOrderChanged (Inkscape::XML::Node *, Inkscape::XML::Node *, Inks
     _reevaluate();
 }
 
-void CSwitch::_reevaluate(bool add_to_arena) {
+void CSwitch::_reevaluate(bool /*add_to_arena*/) {
     SPObject *evaluated_child = _evaluateFirst();
     if (!evaluated_child || _cached_item == evaluated_child) {
         return;
@@ -133,10 +139,7 @@ void CSwitch::_reevaluate(bool add_to_arena) {
     }
 
     _cached_item = evaluated_child;
-    _release_handler_id = g_signal_connect(
-                                    G_OBJECT(evaluated_child), "release",
-                                    G_CALLBACK(&CSwitch::_releaseItem),
-                                    this);
+    _release_connection = evaluated_child->connectRelease(sigc::bind(sigc::ptr_fun(&CSwitch::_releaseItem), this));
 
     _group->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
 }
@@ -151,8 +154,7 @@ void CSwitch::_releaseLastItem(SPObject *obj)
     if (NULL == _cached_item || _cached_item != obj)
         return;
 
-    g_signal_handler_disconnect(G_OBJECT(_cached_item), _release_handler_id);
-    _release_handler_id = 0;
+    _release_connection.disconnect();
     _cached_item = NULL;
 }
 
@@ -168,13 +170,23 @@ void CSwitch::_showChildren (NRArena *arena, NRArenaItem *ai, unsigned int key,
         if (SP_IS_ITEM (o)) {
             child = SP_ITEM (o);
             child->setEvaluated(o == evaluated_child);
-            ac = sp_item_invoke_show (child, arena, key, flags);
+            ac = child->invoke_show (arena, key, flags);
             if (ac) {
                 nr_arena_item_add_child (ai, ac, ar);
                 ar = ac;
-                nr_arena_item_unref (ac);
             }
         }
         l = g_slist_remove (l, o);
     }
 }
+
+/*
+  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 :