sp-namedview.cpp revision 8048a042cbc2237f7785606a1d39d2f68d8929c1
/*
* <sodipodi:namedview> implementation
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
* Copyright (C) 1999-2013 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 "event-log.h"
#include "display/canvas-grid.h"
#include "display/guideline.h"
#include "svg/svg-color.h"
#include "attributes.h"
#include "document.h"
#include "document-undo.h"
#include "desktop-events.h"
#include "desktop-handles.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.
#include "sp-root.h"
using Inkscape::DocumentUndo;
#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);
{
}
{
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 = "#3f3fff";
const char* gridempcolor = "#3f3fff";
const char* gridopacity = "0.15";
const char* gridempopacity = "0.38";
gridoriginx = value;
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;
}
}
}
{
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;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_BBOX_CATEGORY, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_NODE_CATEGORY, value ? sp_str_to_bool(value) : TRUE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OTHERS_CATEGORY, value ? sp_str_to_bool(value) : TRUE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_GRID, value ? sp_str_to_bool(value) : TRUE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_GUIDE, value ? sp_str_to_bool(value) : TRUE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_NODE_SMOOTH, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_LINE_MIDPOINT, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_TEXT_BASELINE, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_BBOX_EDGE_MIDPOINT, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_BBOX_MIDPOINT, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_PATH_INTERSECTION, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_PATH, value ? sp_str_to_bool(value) : FALSE);
break;
break;
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_PATH_CLIP, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_PATH_MASK, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_BBOX_EDGE, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_BBOX_CORNER, value ? sp_str_to_bool(value) : FALSE);
break;
nv->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_PAGE_BORDER, value ? sp_str_to_bool(value) : FALSE);
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;
}
case SP_ATTR_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) {
}
}
}
}
namespace {
{
// 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
}
} // namespace
{
Inkscape::CanvasGrid::writeNewGridToRepr(this->getRepr(),document,static_cast<Inkscape::GridType>(gridtype));
}
/*
* Restores window geometry from the document settings or defaults in prefs
*/
{
bool show_dialogs = true;
// restore window size and position stored with the document
bool sizeSet = false;
if (win) {
}
sizeSet = true;
if ((w > 0) && (h > 0)) {
#ifndef WIN32
// This will happen on sp_desktop_widget_size_allocate
}
#endif
desktop->setWindowSize(w, h);
sizeSet = true;
}
}
{
desktop->setWindowSize(w, h);
}
// restore zoom and view
}
// cancel any history of zooms up to this point
if (show_dialogs) {
desktop->show_dialogs();
}
}
bool SPNamedView::getSnapGlobal() const
{
}
void SPNamedView::setSnapGlobal(bool v)
{
}
{
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_viewport_in_file) {
}
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;
}
{
return (SPNamedView *) nv;
}
}
return (SPNamedView *) nv;
}
void SPNamedView::setGuides(bool v)
{
}
bool SPNamedView::getGuides()
{
unsigned int v;
if (!set) { // hide guides if not specified, for backwards compatibility
v = FALSE;
}
return v;
}
/**
* Gets page fitting margin information from the namedview node in the XML.
* \param nv_repr reference to this document's namedview
* \param key the same key used by the RegisteredScalarUnit in
* \param margin_units units for the margin
* \param return_units units to return the result in
* \param width width in px (for percentage margins)
* \param height height in px (for percentage margins)
* \param use_width true if the this key is left or right margins, false
* otherwise. Used for percentage margins.
* \return the margin size in px, else 0.0 if anything is invalid.
*/
double const width,
double const height,
bool const use_width)
{
double value;
return 0.0;
}
if (*margin_units == percent) {
}
// if (!sp_convert_distance (&value, margin_units, return_units)) {
return 0.0;
}
return value;
}
/**
* 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 *= tr;
}
}
if (g) {
}
}
}
}
}
/*
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:fileencoding=utf-8:textwidth=99 :