Code

clean up redundancies. add a placeholder for Export dialog
[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"
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         _doc = 0;
101     }
102     
103    Inkscape::Verb::delete_all_view (this);
106 void View::setPosition (double x, double y)
108     _position_set_signal.emit (x,y);
111 void View::setPosition(NR::Point const &p) 
112
113     setPosition (double(p[NR::X]), double(p[NR::Y])); 
116 void View::emitResized (double width, double height)
118     _resized_signal.emit (width, height);
121 void View::requestRedraw() 
123     _redraw_requested_signal.emit();
126 /**
127  * Disconnects the view from the document signals, connects the view 
128  * to a new one, and emits the _document_set_signal on the view.
129  *
130  * This is code comon to all subclasses and called from their
131  * setDocument() methods after they are done.
132  * 
133  * \param doc The new document to connect the view to.
134  */
135 void View::setDocument(SPDocument *doc) {
136     g_return_if_fail(doc != NULL);
138     if (_doc) {
139         _document_uri_set_connection.disconnect();
140         _document_resized_connection.disconnect();
141     }
143     _doc = doc;
144     _document_uri_set_connection = 
145         _doc->connectURISet(sigc::bind(sigc::ptr_fun(&_onDocumentURISet), this));
146     _document_resized_connection = 
147         _doc->connectResized(sigc::bind(sigc::ptr_fun(&_onDocumentResized), this));
148     _document_uri_set_signal.emit (SP_DOCUMENT_URI(_doc));
151 }}}
153 /*
154   Local Variables:
155   mode:c++
156   c-file-style:"stroustrup"
157   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
158   indent-tabs-mode:nil
159   fill-column:99
160   End:
161 */
162 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :