sp-namedview.cpp revision 4550d1abdb3f428b8cd47c144d2cd112254bfb8e
#define __SP_NAMEDVIEW_C__
/*
* <sodipodi:namedview> implementation
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
* Copyright (C) 1999-2005 Authors
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "config.h"
#include "display/canvas-grid.h"
#include "svg/svg-color.h"
#include "attributes.h"
#include "document.h"
#include "desktop-events.h"
#include "desktop-handles.h"
#include "event-log.h"
#include "sp-guide.h"
#include "sp-item-group.h"
#include "sp-namedview.h"
#include "prefs-utils.h"
#include "desktop.h"
#include "conn-avoid-ref.h" // for defaultConnSpacing.
#include "isnan.h" //temp fix for isnan(). include last
#define DEFAULTTOLERANCE 0.4
#define DEFAULTGRIDCOLOR 0x3f3fff25
#define DEFAULTGRIDEMPCOLOR 0x3f3fff60
#define DEFAULTGRIDEMPSPACING 5
#define DEFAULTGUIDECOLOR 0x0000ff7f
#define DEFAULTGUIDEHICOLOR 0xff00007f
#define DEFAULTBORDERCOLOR 0x000000ff
#define DEFAULTPAGECOLOR 0xffffff00
static void sp_namedview_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
static Inkscape::XML::Node *sp_namedview_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
static SPObjectGroupClass * parent_class;
{
static GType namedview_type = 0;
if (!namedview_type) {
sizeof(SPNamedViewClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(SPNamedView),
16, /* n_preallocs */
NULL, /* value_table */
};
namedview_type = g_type_register_static(SP_TYPE_OBJECTGROUP, "SPNamedView", &namedview_info, (GTypeFlags)0);
}
return namedview_type;
}
{
}
{
nv->default_layer_id = 0;
}
{
}
/* Construct guideline list */
if (SP_IS_GUIDE(o)) {
}
}
}
{
}
// delete grids:
delete gr;
}
}
}
{
switch (key) {
case SP_ATTR_VIEWONLY:
break;
case SP_ATTR_SHOWGUIDES:
if (!value) { // show guides if not specified, for backwards compatibility
} else {
}
break;
case SP_ATTR_SHOWGRIDS:
if (!value) { // show grids if not specified, for backwards compatibility
nv->grids_visible = false;
} else {
}
break;
case SP_ATTR_GRIDTOLERANCE:
if (value) {
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &nv->gridtolerance, &nv->gridtoleranceunit);
}
break;
case SP_ATTR_GUIDETOLERANCE:
if (value) {
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &nv->guidetolerance, &nv->guidetoleranceunit);
}
break;
case SP_ATTR_OBJECTTOLERANCE:
if (value) {
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &nv->objecttolerance, &nv->objecttoleranceunit);
}
break;
case SP_ATTR_GUIDECOLOR:
if (value) {
}
}
break;
case SP_ATTR_GUIDEOPACITY:
}
break;
case SP_ATTR_GUIDEHICOLOR:
if (value) {
}
}
break;
case SP_ATTR_GUIDEHIOPACITY:
}
break;
case SP_ATTR_SHOWBORDER:
break;
case SP_ATTR_BORDERLAYER:
break;
case SP_ATTR_BORDERCOLOR:
if (value) {
}
break;
case SP_ATTR_BORDEROPACITY:
break;
case SP_ATTR_PAGECOLOR:
if (value) {
}
break;
break;
break;
case SP_ATTR_SHOWPAGESHADOW:
break;
case SP_ATTR_INKSCAPE_ZOOM:
break;
case SP_ATTR_INKSCAPE_CX:
break;
case SP_ATTR_INKSCAPE_CY:
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
case SP_ATTR_INKSCAPE_DOCUMENT_UNITS: {
/* The default unit if the document doesn't override this: e.g. for files saved as
* `plain SVG', or non-inkscape files, or files created by an inkscape 0.40 &
* earlier.
*
* Here we choose `px': useful for screen-destined SVGs, and fewer bug reports
* about "not the same numbers as what's in the SVG file" (at least for documents
* without a viewBox attribute on the root <svg> element). Similarly, it's also
* the most reliable unit (i.e. least likely to be wrong in different viewing
* conditions) for viewBox-less SVG files given that it's the unit that inkscape
* uses for all coordinates.
*
* For documents that do have a viewBox attribute on the root <svg> element, it
* might be better if we used either viewBox coordinates or if we used the unit of
* say the width attribute of the root <svg> element. However, these pose problems
* in that they aren't in general absolute units as currently required by
* doc_units.
*/
if (value) {
/* fixme: Document errors should be reported in the status bar or
* the like (e.g. as per
* http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log
* should be only for programmer errors. */
} else {
g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'",
value);
/* fixme: Don't use g_log (see above). */
}
}
break;
}
default:
}
break;
}
}
/**
* add a grid item from SVG-repr. Check if this namedview already has a gridobject for this one! If desktop=null, add grid-canvasitem to all desktops of this namedview,
* otherwise only add it to the specified desktop.
*/
static Inkscape::CanvasGrid*
//check if namedview already has an object for this grid
grid = g;
break;
}
}
if (!grid) {
//create grid object
Inkscape::GridType gridtype = Inkscape::CanvasGrid::getGridTypeFromSVGName(repr->attribute("type"));
if (desktop)
else
//Initialize the snapping parameters for the new grid
}
if (!desktop) {
//add canvasitem to all desktops
}
} else {
//add canvasitem only for specified desktop
}
return grid;
}
static void sp_namedview_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
{
}
} else {
if (SP_IS_GUIDE(no)) {
TRUE);
if (nv->showguides) {
}
} else {
}
}
}
}
}
}
}
{
delete gr;
break;
}
}
} else {
break;
}
}
}
}
}
static Inkscape::XML::Node *sp_namedview_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
{
if ( ( flags & SP_OBJECT_WRITE_EXT ) &&
{
if (repr) {
} else {
/// \todo FIXME: Plumb an appropriate XML::Document into this
}
}
return repr;
}
{
if (desktop->guides_active) {
}
if (showguides) {
}
} else {
}
}
}
// generate grids specified in SVG:
if (repr) {
}
}
}
}
#define MIN_ONSCREEN_DISTANCE 50
/*
* Restores window geometry from the document settings or defaults in prefs
*/
{
// restore window size and position stored with the document
if (geometry_from_file) {
if (w>0 && h>0 && x>0 && y>0) {
x = MIN(gdk_screen_width() - w, x);
y = MIN(gdk_screen_height() - h, y);
}
if (w>0 && h>0) {
desktop->setWindowSize(w, h);
}
if (x>0 && y>0) {
}
}
// restore zoom and view
}
// cancel any history of zooms up to this point
if (desktop->zooms_past) {
}
}
{
if ( nv->default_layer_id != 0 ) {
}
// don't use that object if it's not at least group
}
// if that didn't work out, look for the topmost layer
if (!layer) {
}
}
}
if (layer) {
}
// FIXME: find a better place to do this
}
{
// saving window geometry is not undoable
if (save_geometry_in_file) {
gint w, h, x, y;
desktop->getWindowGeometry(x, y, w, h);
}
// restore undoability
}
{
}
// delete grids:
while ( grids ) {
delete gr;
}
}
{
}
}
{
if (nv->showguides) {
}
} else {
}
}
}
}
{
unsigned int v;
if (!set) { // hide guides if not specified, for backwards compatibility
v = FALSE;
} else {
v = !v;
}
sp_document_set_undo_sensitive(doc, false);
}
{
sp_document_set_undo_sensitive(doc, false);
}
{
}
{
return ++viewcount;
}
{
return views;
}
/* This should be moved somewhere */
{
if (str) {
return TRUE;
}
}
return FALSE;
}
/* fixme: Collect all these length parsing methods and think common sane API */
{
if (!str) {
return FALSE;
}
gchar *u;
if (!u) {
return FALSE;
}
while (isspace(*u)) {
u += 1;
}
if (!*u) {
/* No unit specified - keep default */
*val = v;
return TRUE;
}
if (base & SP_UNIT_DEVICE) {
*val = v;
return TRUE;
}
}
if (base & SP_UNIT_ABSOLUTE) {
} else {
return FALSE;
}
*val = v;
return TRUE;
}
return FALSE;
}
{
if (!str) {
return FALSE;
}
gchar *u;
if (!u) {
return FALSE;
}
return TRUE;
}
{
SPObject *nv = sp_item_group_get_child_by_name((SPGroup *) document->root, NULL, "sodipodi:namedview");
return (SPNamedView *) nv;
}
}
return (SPNamedView *) nv;
}
/**
* Returns namedview's default metric.
*/
{
if (doc_units) {
return sp_unit_get_metric(doc_units);
} else {
return SP_PT;
}
}
/*
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:encoding=utf-8:textwidth=99 :