Code

75b6c453b349096e539e76ed2409252a9f4fc877
[inkscape.git] / src / ui / view / view.cpp
1 #define __SP_VIEW_C__
3 /** \file
4  * View implementation
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   Ralf Stephan <ralf@ark.in-berlin.de>
9  *
10  * Copyright (C) 2001-2002 Lauris Kaplinski
11  * Copyright (C) 2001 Ximian, Inc.
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #ifdef HAVE_CONFIG_H
17 # include "config.h"
18 #endif
20 #include "libnr/nr-point.h"
21 #include "document.h"
22 #include "view.h"
23 #include "message-stack.h"
24 #include "message-context.h"
25 #include "verbs.h"
26 #include "inkscape-private.h"
28 namespace Inkscape {
29 namespace UI {
30 namespace View {
32 static void 
33 _onPositionSet (double x, double y, View* v)
34 {
35     v->onPositionSet (x,y);
36 }
38 static void 
39 _onResized (double x, double y, View* v)
40 {
41     v->onResized (x,y);
42 }
44 static void 
45 _onRedrawRequested (View* v)
46 {
47     v->onRedrawRequested();
48 }
50 static void 
51 _onStatusMessage (Inkscape::MessageType type, gchar const *message, View* v)
52 {
53     v->onStatusMessage (type, message);
54 }
56 static void 
57 _onDocumentURISet (gchar const* uri, View* v)
58 {
59     v->onDocumentURISet (uri);
60 }
62 static void 
63 _onDocumentResized (double x, double y, View* v)
64 {
65     v->onDocumentResized (x,y);
66 }
68 //--------------------------------------------------------------------
69 View::View()
70 :  _doc(0)
71 {
72     _message_stack = GC::release(new Inkscape::MessageStack());
73     _tips_message_context = new Inkscape::MessageContext(_message_stack);
75     _position_set_connection = _position_set_signal.connect (sigc::bind (sigc::ptr_fun (&_onPositionSet), this));
76     _resized_connection = _resized_signal.connect (sigc::bind (sigc::ptr_fun (&_onResized), this));
77     _redraw_requested_connection = _redraw_requested_signal.connect (sigc::bind (sigc::ptr_fun (&_onRedrawRequested), this));
78     
79     _message_changed_connection = _message_stack->connectChanged (sigc::bind (sigc::ptr_fun (&_onStatusMessage), this));
80 }
82 /**
83  * Deletes and nulls all View message stacks and disconnects it from signals.
84  */
85 View::~View()
86 {
87     if (_doc) {
88         inkscape_remove_document(_doc);
89     }
90     _close();
91 }
93 void View::_close() {
94     _message_changed_connection.disconnect();
96     delete _tips_message_context;
97     _tips_message_context = 0;
99     _message_stack = 0;
101     if (_doc) {
102         _document_uri_set_connection.disconnect();
103         _document_resized_connection.disconnect();
104         _doc = 0;
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         inkscape_remove_document(_doc);
146     }
148     inkscape_add_document(doc);
150     _doc = doc;
151     _document_uri_set_connection = 
152         _doc->connectURISet(sigc::bind(sigc::ptr_fun(&_onDocumentURISet), this));
153     _document_resized_connection = 
154         _doc->connectResized(sigc::bind(sigc::ptr_fun(&_onDocumentResized), this));
155     _document_uri_set_signal.emit (SP_DOCUMENT_URI(_doc));
158 }}}
160 /*
161   Local Variables:
162   mode:c++
163   c-file-style:"stroustrup"
164   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
165   indent-tabs-mode:nil
166   fill-column:99
167   End:
168 */
169 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :