/*
* <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 "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;
this->zoom = 0;
this->guidecolor = 0;
this->guidehicolor = 0;
this->borderlayer = 0;
this->page_size_units = NULL;
this->window_x = 0;
this->cy = 0;
this->window_y = 0;
this->svg_units = unit_table.getUnit("px"); // legacy behavior: if no viewbox present, default to 'px' units
this->display_units = NULL;
this->page_size_units = NULL;
this->pagecolor = 0;
this->cx = 0;
this->pageshadow = 0;
this->window_width = 0;
this->window_height = 0;
this->window_maximized = 0;
this->bordercolor = 0;
this->showguides = TRUE;
this->lockguides = false;
this->grids_visible = false;
this->showborder = TRUE;
this->pagecheckerboard = FALSE;
this->showpageshadow = TRUE;
this->viewcount = 0;
this->default_layer_id = 0;
this->connector_spacing = defaultConnSpacing;
}
SPNamedView::~SPNamedView() {
}
static void sp_namedview_generate_old_grid(SPNamedView * /*nv*/, SPDocument *document, Inkscape::XML::Node *repr) {
bool old_grid_settings_present = false;
// set old settings
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"));
}
}
this->readAttr( "inkscape:document-units" );
this->readAttr( "units" );
this->readAttr( "viewonly" );
this->readAttr( "showguides" );
this->readAttr( "showgrid" );
this->readAttr( "gridtolerance" );
this->readAttr( "guidetolerance" );
this->readAttr( "objecttolerance" );
this->readAttr( "guidecolor" );
this->readAttr( "guideopacity" );
this->readAttr( "guidehicolor" );
this->readAttr( "guidehiopacity" );
this->readAttr( "showborder" );
this->readAttr( "inkscape:showpageshadow" );
this->readAttr( "borderlayer" );
this->readAttr( "bordercolor" );
this->readAttr( "borderopacity" );
this->readAttr( "pagecolor" );
this->readAttr( "inkscape:pagecheckerboard" );
this->readAttr( "inkscape:pageopacity" );
this->readAttr( "inkscape:pageshadow" );
this->readAttr( "inkscape:zoom" );
this->readAttr( "inkscape:cx" );
this->readAttr( "inkscape:cy" );
this->readAttr( "inkscape:window-width" );
this->readAttr( "inkscape:window-height" );
this->readAttr( "inkscape:window-x" );
this->readAttr( "inkscape:window-y" );
this->readAttr( "inkscape:window-maximized" );
this->readAttr( "inkscape:snap-global" );
this->readAttr( "inkscape:snap-bbox" );
this->readAttr( "inkscape:snap-nodes" );
this->readAttr( "inkscape:snap-others" );
this->readAttr( "inkscape:snap-from-guide" );
this->readAttr( "inkscape:snap-center" );
this->readAttr( "inkscape:snap-smooth-nodes" );
this->readAttr( "inkscape:snap-midpoints" );
this->readAttr( "inkscape:snap-object-midpoints" );
this->readAttr( "inkscape:snap-text-baseline" );
this->readAttr( "inkscape:snap-bbox-edge-midpoints" );
this->readAttr( "inkscape:snap-bbox-midpoints" );
this->readAttr( "inkscape:snap-to-guides" );
this->readAttr( "inkscape:snap-grids" );
this->readAttr( "inkscape:snap-intersection-paths" );
this->readAttr( "inkscape:object-paths" );
this->readAttr( "inkscape:snap-perpendicular" );
this->readAttr( "inkscape:snap-tangential" );
this->readAttr( "inkscape:snap-path-clip" );
this->readAttr( "inkscape:snap-path-mask" );
this->readAttr( "inkscape:object-nodes" );
this->readAttr( "inkscape:bbox-paths" );
this->readAttr( "inkscape:bbox-nodes" );
this->readAttr( "inkscape:snap-page" );
this->readAttr( "inkscape:current-layer" );
this->readAttr( "inkscape:connector-spacing" );
this->readAttr( "inkscape:lockguides" );
/* Construct guideline list */
if (SP_IS_GUIDE(o)) {
//g_object_set(G_OBJECT(g), "color", nv->guidecolor, "hicolor", nv->guidehicolor, NULL);
g->setColor(this->guidecolor);
g->setHiColor(this->guidehicolor);
g->readAttr( "inkscape:color" );
}
}
// backwards compatibility with grid settings (pre 0.46)
// If viewbox defined: try to calculate the SVG unit from document width and viewbox
double factor = svgwidth.value(unit_table.primary(Inkscape::Util::UNIT_TYPE_LINEAR)) / viewbox.width();
} else { // force the document units to be px
}
}
// delete grids:
for(std::vector<Inkscape::CanvasGrid *>::const_iterator it=this->grids.begin();it!=this->grids.end();++it )
delete *it;
SPObjectGroup::release();
}
switch (key) {
case SP_ATTR_VIEWONLY:
break;
case SP_ATTR_SHOWGUIDES:
if (!value) { // show guides if not specified, for backwards compatibility
this->showguides = TRUE;
} else {
}
sp_namedview_setup_guides(this);
break;
case SP_ATTR_SHOWGRIDS:
if (!value) { // don't show grids if not specified, for backwards compatibility
this->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:
this->borderlayer = SP_BORDER_LAYER_BOTTOM;
break;
case SP_ATTR_BORDERCOLOR:
if (value) {
}
break;
case SP_ATTR_BORDEROPACITY:
break;
case SP_ATTR_PAGECOLOR:
if (value) {
}
break;
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;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_BBOX_CATEGORY, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_NODE_CATEGORY, value ? sp_str_to_bool(value) : TRUE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OTHERS_CATEGORY, value ? sp_str_to_bool(value) : TRUE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_GRID, value ? sp_str_to_bool(value) : TRUE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_GUIDE, value ? sp_str_to_bool(value) : TRUE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_NODE_SMOOTH, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_LINE_MIDPOINT, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_TEXT_BASELINE, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_BBOX_EDGE_MIDPOINT, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_BBOX_MIDPOINT, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_PATH_INTERSECTION, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_PATH, value ? sp_str_to_bool(value) : FALSE);
break;
break;
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_PATH_CLIP, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_PATH_MASK, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP, value ? sp_str_to_bool(value) : TRUE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_BBOX_EDGE, value ? sp_str_to_bool(value) : FALSE);
break;
this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_BBOX_CORNER, value ? sp_str_to_bool(value) : FALSE);
break;
this->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 display 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.
*
* Note that these units are not the same as the units used for the values in SVG!
*
* We default to `px'.
*/
/* 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 if ( req_unit->isAbsolute() ) {
} 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). */
}
}
this->display_units = new_unit;
break;
}
case SP_ATTR_UNITS: {
// Only used in "Custom size" section of Document Properties dialog
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 if ( req_unit->isAbsolute() ) {
} 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). */
}
}
this->page_size_units = new_unit;
break;
}
sp_namedview_lock_guides(this);
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
for(std::vector<Inkscape::CanvasGrid *>::const_iterator it=nv->grids.begin();it!=nv->grids.end();++it ) {
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;
}
} else {
if ( !SP_IS_OBJECT(no) ) {
return;
}
if (SP_IS_GUIDE(no)) {
//g_object_set(G_OBJECT(g), "color", this->guidecolor, "hicolor", this->guidehicolor, NULL);
g->setColor(this->guidecolor);
g->setHiColor(this->guidehicolor);
g->readAttr("inkscape:color");
if (this->editable) {
if ((*it)->guides_active) {
}
}
}
}
}
}
for(std::vector<Inkscape::CanvasGrid *>::iterator it=this->grids.begin();it!=this->grids.end();++it ) {
delete (*it);
break;
}
}
} else {
break;
}
}
}
}
Inkscape::XML::Node* SPNamedView::write(Inkscape::XML::Document *xml_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();
}
}
{
}
{
}
{
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) {
guide->showSPGuide();
} else {
guide->hideSPGuide();
}
}
{
}
{
unsigned int v;
if (!set) { // hide guides if not specified, for backwards compatibility
v = FALSE;
} else {
v = !v;
}
}
{
unsigned int v;
if (!set) { // hide guides if not specified, for backwards compatibility
v = true;
} 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;
}
{
return sp_document_namedview(const_cast<SPDocument *>(document), id); // use a const_cast here to avoid duplicating code
}
{
}
{
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) {
}
return 0.0;
}
return value;
}
/**
* Returns namedview's default unit.
* If no default unit is set, "px" is returned
*/
{
}
{
return *svg_units;
}
/**
* Returns the first grid it could find that isEnabled(). Returns NULL, if none is enabled
*/
{
for(std::vector<Inkscape::CanvasGrid *>::const_iterator it=namedview->grids.begin();it!=namedview->grids.end();++it ) {
return (*it);
}
return NULL;
}
point_on_line *= tr;
}
}
for(std::vector<Inkscape::CanvasGrid *>::iterator it=this->grids.begin();it!=this->grids.end();++it ) {
}
}
}
}
/*
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 :