1 /*
2 * The reference corresponding to the inkscape:perspectiveID attribute
3 *
4 * Copyright (C) 2007 Johan Engelen
5 * Copyright (C) 2007 Maximilian Albert
6 *
7 * Released under GNU GPL, read the file 'COPYING' for more information.
8 */
10 #include "persp3d-reference.h"
11 #include "persp3d.h"
12 #include "uri.h"
14 static void persp3dreference_href_changed(SPObject *old_ref, SPObject *ref, Persp3DReference *persp3dref);
15 static void persp3dreference_delete_self(SPObject *deleted, Persp3DReference *persp3dref);
16 static void persp3dreference_source_modified(SPObject *iSource, guint flags, Persp3DReference *persp3dref);
18 Persp3DReference::Persp3DReference(SPObject* i_owner) : URIReference(i_owner)
19 {
20 owner=i_owner;
21 persp_href = NULL;
22 persp_repr = NULL;
23 persp = NULL;
24 _changed_connection = changedSignal().connect(sigc::bind(sigc::ptr_fun(persp3dreference_href_changed), this)); // listening to myself, this should be virtual instead
25 }
27 Persp3DReference::~Persp3DReference(void)
28 {
29 _changed_connection.disconnect(); // to do before unlinking
31 quit_listening();
32 unlink();
33 }
35 bool
36 Persp3DReference::_acceptObject(SPObject *obj) const
37 {
38 return SP_IS_PERSP3D(obj);
39 /* effic: Don't bother making this an inline function: _acceptObject is a virtual function,
40 typically called from a context where the runtime type is not known at compile time. */
41 }
43 void
44 Persp3DReference::unlink(void)
45 {
46 g_free(persp_href);
47 persp_href = NULL;
48 detach();
49 }
51 void
52 Persp3DReference::start_listening(Persp3D* to)
53 {
54 if ( to == NULL ) {
55 return;
56 }
57 persp = to;
58 persp_repr = SP_OBJECT_REPR(to);
59 _delete_connection = to->connectDelete(sigc::bind(sigc::ptr_fun(&persp3dreference_delete_self), this));
60 _modified_connection = to->connectModified(sigc::bind<2>(sigc::ptr_fun(&persp3dreference_source_modified), this));
61 }
63 void
64 Persp3DReference::quit_listening(void)
65 {
66 if ( persp == NULL ) {
67 return;
68 }
69 _modified_connection.disconnect();
70 _delete_connection.disconnect();
71 persp_repr = NULL;
72 persp = NULL;
73 }
75 static void
76 persp3dreference_href_changed(SPObject */*old_ref*/, SPObject */*ref*/, Persp3DReference *persp3dref)
77 {
78 persp3dref->quit_listening();
79 Persp3D *refobj = SP_PERSP3D(persp3dref->getObject());
80 if ( refobj ) {
81 persp3dref->start_listening(refobj);
82 }
84 persp3dref->owner->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
85 }
87 static void
88 persp3dreference_delete_self(SPObject */*deleted*/, Persp3DReference *persp3dref)
89 {
90 g_return_if_fail(persp3dref->owner);
91 persp3dref->owner->deleteObject();
92 }
94 static void
95 persp3dreference_source_modified(SPObject */*iSource*/, guint /*flags*/, Persp3DReference *persp3dref)
96 {
97 persp3dref->owner->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
98 }
101 /*
102 Local Variables:
103 mode:c++
104 c-file-style:"stroustrup"
105 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
106 indent-tabs-mode:nil
107 fill-column:99
108 End:
109 */
110 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :