Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / ui / view / view.cpp
1 /** \file
2  * View implementation
3  *
4  * Authors:
5  *   Lauris Kaplinski <lauris@kaplinski.com>
6  *   Ralf Stephan <ralf@ark.in-berlin.de>
7  *   Jon A. Cruz <jon@joncruz.org>
8  *
9  * Copyright (C) 2001-2002 Lauris Kaplinski
10  * Copyright (C) 2001 Ximian, Inc.
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
19 #include "libnr/nr-point.h"
20 #include "document.h"
21 #include "view.h"
22 #include "message-stack.h"
23 #include "message-context.h"
24 #include "verbs.h"
25 #include "inkscape-private.h"
27 namespace Inkscape {
28 namespace UI {
29 namespace View {
31 static void 
32 _onPositionSet (double x, double y, View* v)
33 {
34     v->onPositionSet (x,y);
35 }
37 static void 
38 _onResized (double x, double y, View* v)
39 {
40     v->onResized (x,y);
41 }
43 static void 
44 _onRedrawRequested (View* v)
45 {
46     v->onRedrawRequested();
47 }
49 static void 
50 _onStatusMessage (Inkscape::MessageType type, gchar const *message, View* v)
51 {
52     v->onStatusMessage (type, message);
53 }
55 static void 
56 _onDocumentURISet (gchar const* uri, View* v)
57 {
58     v->onDocumentURISet (uri);
59 }
61 static void 
62 _onDocumentResized (double x, double y, View* v)
63 {
64     v->onDocumentResized (x,y);
65 }
67 //--------------------------------------------------------------------
68 View::View()
69 :  _doc(0)
70 {
71     _message_stack = GC::release(new Inkscape::MessageStack());
72     _tips_message_context = new Inkscape::MessageContext(_message_stack);
74     _position_set_connection = _position_set_signal.connect (sigc::bind (sigc::ptr_fun (&_onPositionSet), this));
75     _resized_connection = _resized_signal.connect (sigc::bind (sigc::ptr_fun (&_onResized), this));
76     _redraw_requested_connection = _redraw_requested_signal.connect (sigc::bind (sigc::ptr_fun (&_onRedrawRequested), this));
77     
78     _message_changed_connection = _message_stack->connectChanged (sigc::bind (sigc::ptr_fun (&_onStatusMessage), this));
79 }
81 /**
82  * Deletes and nulls all View message stacks and disconnects it from signals.
83  */
84 View::~View()
85 {
86     _close();
87 }
89 void View::_close() {
90     _message_changed_connection.disconnect();
92     delete _tips_message_context;
93     _tips_message_context = 0;
95     _message_stack = 0;
97     if (_doc) {
98         _document_uri_set_connection.disconnect();
99         _document_resized_connection.disconnect();
100         if (inkscape_remove_document(_doc)) {
101             // this was the last view of this document, so delete it
102             delete _doc;
103         }
104         _doc = NULL;
105     }
106     
107    Inkscape::Verb::delete_all_view (this);
110 void View::setPosition (double x, double y)
112     _position_set_signal.emit (x,y);
115 void View::setPosition(Geom::Point const &p) 
116
117     setPosition (double(p[Geom::X]), double(p[Geom::Y])); 
120 void View::emitResized (double width, double height)
122     _resized_signal.emit (width, height);
125 void View::requestRedraw() 
127     _redraw_requested_signal.emit();
130 /**
131  * Disconnects the view from the document signals, connects the view 
132  * to a new one, and emits the _document_set_signal on the view.
133  *
134  * This is code comon to all subclasses and called from their
135  * setDocument() methods after they are done.
136  * 
137  * \param doc The new document to connect the view to.
138  */
139 void View::setDocument(SPDocument *doc) {
140     g_return_if_fail(doc != NULL);
142     if (_doc) {
143         _document_uri_set_connection.disconnect();
144         _document_resized_connection.disconnect();
145         if (inkscape_remove_document(_doc)) {
146             // this was the last view of this document, so delete it
147             delete _doc;
148         }
149     }
151     inkscape_add_document(doc);
153     _doc = doc;
154     _document_uri_set_connection = 
155         _doc->connectURISet(sigc::bind(sigc::ptr_fun(&_onDocumentURISet), this));
156     _document_resized_connection = 
157         _doc->connectResized(sigc::bind(sigc::ptr_fun(&_onDocumentResized), this));
158     _document_uri_set_signal.emit( _doc->getURI() );
161 }}}
163 /*
164   Local Variables:
165   mode:c++
166   c-file-style:"stroustrup"
167   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
168   indent-tabs-mode:nil
169   fill-column:99
170   End:
171 */
172 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :