view.cpp revision 09ba3247163582bf2e30e17c4c154aa259ce038a
159N/A#define __SP_VIEW_C__
159N/A
159N/A/** \file
159N/A * View implementation
159N/A *
159N/A * Authors:
159N/A * Lauris Kaplinski <lauris@kaplinski.com>
159N/A * Ralf Stephan <ralf@ark.in-berlin.de>
159N/A *
159N/A * Copyright (C) 2001-2002 Lauris Kaplinski
159N/A * Copyright (C) 2001 Ximian, Inc.
159N/A *
159N/A * Released under GNU GPL, read the file 'COPYING' for more information
159N/A */
159N/A
159N/A#ifdef HAVE_CONFIG_H
159N/A# include "config.h"
159N/A#endif
159N/A
159N/A#include "libnr/nr-point.h"
2745N/A#include "document.h"
159N/A#include "view.h"
159N/A#include "message-stack.h"
159N/A#include "message-context.h"
159N/A#include "verbs.h"
1544N/A#include "inkscape-private.h"
618N/A
159N/Anamespace Inkscape {
159N/Anamespace UI {
844N/Anamespace View {
1544N/A
1544N/Astatic void
1258N/A_onPositionSet (double x, double y, View* v)
159N/A{
2899N/A v->onPositionSet (x,y);
2899N/A}
159N/A
159N/Astatic void
159N/A_onResized (double x, double y, View* v)
159N/A{
1440N/A v->onResized (x,y);
1440N/A}
159N/A
159N/Astatic void
159N/A_onRedrawRequested (View* v)
1440N/A{
159N/A v->onRedrawRequested();
206N/A}
1440N/A
159N/Astatic void
1475N/A_onStatusMessage (Inkscape::MessageType type, gchar const *message, View* v)
1475N/A{
159N/A v->onStatusMessage (type, message);
1544N/A}
159N/A
1544N/Astatic void
159N/A_onDocumentURISet (gchar const* uri, View* v)
159N/A{
1544N/A v->onDocumentURISet (uri);
159N/A}
159N/A
159N/Astatic void
159N/A_onDocumentResized (double x, double y, View* v)
{
v->onDocumentResized (x,y);
}
//--------------------------------------------------------------------
View::View()
: _doc(0)
{
_message_stack = GC::release(new Inkscape::MessageStack());
_tips_message_context = new Inkscape::MessageContext(_message_stack);
_position_set_connection = _position_set_signal.connect (sigc::bind (sigc::ptr_fun (&_onPositionSet), this));
_resized_connection = _resized_signal.connect (sigc::bind (sigc::ptr_fun (&_onResized), this));
_redraw_requested_connection = _redraw_requested_signal.connect (sigc::bind (sigc::ptr_fun (&_onRedrawRequested), this));
_message_changed_connection = _message_stack->connectChanged (sigc::bind (sigc::ptr_fun (&_onStatusMessage), this));
}
/**
* Deletes and nulls all View message stacks and disconnects it from signals.
*/
View::~View()
{
_close();
}
void View::_close() {
_message_changed_connection.disconnect();
delete _tips_message_context;
_tips_message_context = 0;
_message_stack = 0;
if (_doc) {
_document_uri_set_connection.disconnect();
_document_resized_connection.disconnect();
if (inkscape_remove_document(_doc)) {
// this was the last view of this document, so delete it
delete _doc;
}
_doc = NULL;
}
Inkscape::Verb::delete_all_view (this);
}
void View::setPosition (double x, double y)
{
_position_set_signal.emit (x,y);
}
void View::setPosition(Geom::Point const &p)
{
setPosition (double(p[Geom::X]), double(p[Geom::Y]));
}
void View::emitResized (double width, double height)
{
_resized_signal.emit (width, height);
}
void View::requestRedraw()
{
_redraw_requested_signal.emit();
}
/**
* Disconnects the view from the document signals, connects the view
* to a new one, and emits the _document_set_signal on the view.
*
* This is code comon to all subclasses and called from their
* setDocument() methods after they are done.
*
* \param doc The new document to connect the view to.
*/
void View::setDocument(SPDocument *doc) {
g_return_if_fail(doc != NULL);
if (_doc) {
_document_uri_set_connection.disconnect();
_document_resized_connection.disconnect();
if (inkscape_remove_document(_doc)) {
// this was the last view of this document, so delete it
delete _doc;
}
}
inkscape_add_document(doc);
_doc = doc;
_document_uri_set_connection =
_doc->connectURISet(sigc::bind(sigc::ptr_fun(&_onDocumentURISet), this));
_document_resized_connection =
_doc->connectResized(sigc::bind(sigc::ptr_fun(&_onDocumentResized), this));
_document_uri_set_signal.emit (SP_DOCUMENT_URI(_doc));
}
}}}
/*
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 :