sp-namedview.cpp revision ab17729e09d54ccfcb65645e6dae62a343e9c6b7
#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-2008 Authors
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "config.h"
#include <cstring>
#include <string>
#include "display/canvas-grid.h"
#include "display/guideline.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 "preferences.h"
#include "desktop.h"
#include "conn-avoid-ref.h" // for defaultConnSpacing.
#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::Document *doc, 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->grids_visible = false;
nv->default_layer_id = 0;
}
static void sp_namedview_generate_old_grid(SPNamedView * /*nv*/, SPDocument *document, Inkscape::XML::Node *repr) {
bool old_grid_settings_present = false;
// set old settings
const char* gridspacingx = "1px";
const char* gridspacingy = "1px";
const char* gridoriginy = "0px";
const char* gridoriginx = "0px";
const char* gridempspacing = "5";
const char* gridcolor = "#0000ff";
const char* gridempcolor = "#0000ff";
const char* gridopacity = "0.2";
const char* gridempopacity = "0.4";
old_grid_settings_present = true;
}
gridoriginy = value;
old_grid_settings_present = true;
}
old_grid_settings_present = true;
}
old_grid_settings_present = true;
}
old_grid_settings_present = true;
}
old_grid_settings_present = true;
}
old_grid_settings_present = true;
}
gridopacity = value;
old_grid_settings_present = true;
}
old_grid_settings_present = true;
}
if (old_grid_settings_present) {
// generate new xy grid with the correct settings
// first create the child xml node, then hook it to repr. This order is important, to not set off listeners to repr before the new node is complete.
// remove all old settings
// SPDocumentUndo::done(doc, SP_VERB_DIALOG_NAMEDVIEW, _("Create new grid from pre0.46 grid settings"));
}
}
{
}
/* Construct guideline list */
if (SP_IS_GUIDE(o)) {
}
}
// backwards compatibility with grid settings (pre 0.46)
}
{
}
// delete grids:
delete gr;
}
}
}
{
// TODO investigate why we grab this and then never use it
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) { // don't show grids if not specified, for backwards compatibility
nv->grids_visible = false;
} else {
}
break;
case SP_ATTR_GRIDTOLERANCE:
break;
case SP_ATTR_GUIDETOLERANCE:
break;
case SP_ATTR_OBJECTTOLERANCE:
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;
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"));
g_warning("sp_namedview_add_grid - how come doc is null here?!");
return NULL;
}
}
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_OBJECT(no) )
return;
if (SP_IS_GUIDE(no)) {
TRUE);
}
}
}
}
}
{
delete gr;
break;
}
}
} else {
break;
}
}
}
}
}
static Inkscape::XML::Node *sp_namedview_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
{
if ( ( flags & SP_OBJECT_WRITE_EXT ) &&
{
if (repr) {
} else {
}
}
return repr;
}
{
if (desktop->guides_active) {
}
}
// 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 (nv->window_maximized) {
if (win){
}
} else {
// prevent the window from moving off the screen to the right or to the bottom
// prevent the window from moving off the screen to the left or to the top
if (w>0 && h>0) {
desktop->setWindowSize(w, h);
}
}
}
// 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
}
{
}
}
{
}
}
{
}
}
{
if (show) {
} else {
}
}
}
{
unsigned int v;
if (!set) { // hide guides if not specified, for backwards compatibility
v = FALSE;
} else {
v = !v;
}
}
{
/* we don't want the document to get dirty on startup; that's when
we call this function with dirty_document = false */
if (dirty_document) {
}
}
{
}
{
return ++viewcount;
}
{
return views;
}
/* This should be moved somewhere */
{
if (str) {
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;
}
}
/**
* Returns the first grid it could find that isEnabled(). Returns NULL, if none is enabled
*/
{
return grid;
}
return NULL;
}
point_on_line[0] += tr[0];
}
}
}
}
/*
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 :