~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/document.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Kees Cook, Ted Gould
  • Date: 2008-02-10 14:20:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080210142016-vcnb2zqyhszu0xvb
Tags: 0.46~pre1-0ubuntu1
[ Kees Cook ]
* debian/control:
  - add libgtkspell-dev build-dep to gain GtkSpell features (LP: #183547).
  - update Standards version (no changes needed).
  - add Vcs and Homepage fields.
  - switch to new python-lxml dep.
* debian/{control,rules}: switch from dpatch to quilt for more sanity.
* debian/patches/20_fix_glib_and_gxx43_ftbfs.patch:
  - merged against upstream fixes.
  - added additional fixes for newly written code.
* debian/rules: enable parallel building.

[ Ted Gould ]
* Updating POTFILES.in to make it so things build correctly.
* debian/control:
  - add ImageMagick++ and libboost-dev to build-deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
# include "config.h"
39
39
#endif
40
40
#include <gtk/gtkmain.h>
 
41
#include <string>
 
42
#include <cstring>
41
43
#include "application/application.h"
42
44
#include "application/editor.h"
43
45
#include "libnr/nr-matrix-fns.h"
53
55
#include "libavoid/router.h"
54
56
#include "libnr/nr-rect.h"
55
57
#include "sp-item-group.h"
 
58
#include "profile-manager.h"
 
59
#include "persp3d.h"
56
60
 
57
61
#include "display/nr-arena-item.h"
58
62
 
59
63
#include "dialogs/rdf.h"
60
64
 
 
65
#include "transf_mat_3x4.h"
 
66
 
61
67
#define A4_WIDTH_STR "210mm"
62
68
#define A4_HEIGHT_STR "297mm"
63
69
 
70
76
 
71
77
static gint doc_count = 0;
72
78
 
 
79
static unsigned long next_serial = 0;
 
80
 
73
81
SPDocument::SPDocument() {
74
82
    SPDocumentPrivate *p;
75
83
 
94
102
    // Don't use the Consolidate moves optimisation.
95
103
    router->ConsolidateMoves = false;
96
104
 
 
105
    perspectives = NULL;
 
106
 
97
107
    p = new SPDocumentPrivate();
98
108
 
 
109
    p->serial = next_serial++;
 
110
 
99
111
    p->iddef = g_hash_table_new(g_direct_hash, g_direct_equal);
100
112
    p->reprdef = g_hash_table_new(g_direct_hash, g_direct_equal);
101
113
 
106
118
    p->history_size = 0;
107
119
    p->undo = NULL;
108
120
    p->redo = NULL;
 
121
    p->seeking = false;
109
122
 
110
123
    priv = p;
111
124
 
 
125
    // Once things are set, hook in the manager
 
126
    profileManager = new Inkscape::ProfileManager(this);
 
127
 
112
128
    // XXX only for testing!
113
129
    priv->undoStackObservers.add(p->console_output_undo_observer);
114
130
}
116
132
SPDocument::~SPDocument() {
117
133
    collectOrphans();
118
134
 
 
135
    // kill/unhook this first
 
136
    if ( profileManager ) {
 
137
        delete profileManager;
 
138
        profileManager = 0;
 
139
    }
 
140
 
119
141
    if (priv) {
120
 
        inkscape_remove_document(this);
121
 
 
122
142
        if (priv->partial) {
123
143
            sp_repr_free_log(priv->partial);
124
144
            priv->partial = NULL;
181
201
    }
182
202
 
183
203
    //delete this->_whiteboard_session_manager;
 
204
 
 
205
}
 
206
 
 
207
void SPDocument::add_persp3d (Persp3D * const persp)
 
208
{
 
209
    SPDefs *defs = SP_ROOT(this->root)->defs;
 
210
    for (SPObject *i = sp_object_first_child(SP_OBJECT(defs)); i != NULL; i = SP_OBJECT_NEXT(i) ) {
 
211
        if (SP_IS_PERSP3D(i)) {
 
212
            g_print ("Encountered a Persp3D in defs\n");
 
213
        }
 
214
    }
 
215
 
 
216
    g_print ("Adding Persp3D to defs\n");
 
217
    persp3d_create_xml_element (this);
 
218
}
 
219
 
 
220
void SPDocument::remove_persp3d (Persp3D * const persp)
 
221
{
 
222
    // TODO: Delete the repr, maybe perform a check if any boxes are still linked to the perspective.
 
223
    //       Anything else?
 
224
    g_print ("Please implement deletion of perspectives here.\n");
 
225
}
 
226
 
 
227
unsigned long SPDocument::serial() const {
 
228
    return priv->serial;
184
229
}
185
230
 
186
231
void SPDocument::queueForOrphanCollection(SPObject *object) {
204
249
    }
205
250
}
206
251
 
207
 
void SPDocument::reset_key (void *dummy)
 
252
void SPDocument::reset_key (void */*dummy*/)
208
253
{
209
254
    actionkey = NULL;
210
255
}
220
265
    Inkscape::XML::Node *rroot;
221
266
    Inkscape::Version sodipodi_version;
222
267
 
223
 
    rroot = sp_repr_document_root(rdoc);
 
268
    rroot = rdoc->root();
224
269
 
225
270
    document = new SPDocument();
226
271
 
261
306
 
262
307
    /* Quick hack 3 - Set uri attributes */
263
308
    if (uri) {
264
 
        /* fixme: Think, what this means for images (Lauris) */
265
309
        rroot->setAttribute("sodipodi:docname", uri);
266
 
        if (document->base)
267
 
            rroot->setAttribute("sodipodi:docbase", document->base);
268
310
    }
269
311
    /* End of quick hack 3 */
270
312
 
277
319
        // see if there's a template with id="base" in the preferences
278
320
        if (!r) {
279
321
            // if there's none, create an empty element
280
 
            rnew = sp_repr_new("sodipodi:namedview");
 
322
            rnew = rdoc->createElement("sodipodi:namedview");
281
323
            rnew->setAttribute("id", "base");
282
324
        } else {
283
325
            // otherwise, take from preferences
284
 
            rnew = r->duplicate();
 
326
            rnew = r->duplicate(rroot->document());
285
327
        }
286
328
        // insert into the document
287
329
        rroot->addChild(rnew, NULL);
292
334
    /* Defs */
293
335
    if (!SP_ROOT(document->root)->defs) {
294
336
        Inkscape::XML::Node *r;
295
 
        r = sp_repr_new("svg:defs");
 
337
        r = rdoc->createElement("svg:defs");
296
338
        rroot->addChild(r, NULL);
297
339
        Inkscape::GC::release(r);
298
340
        g_assert(SP_ROOT(document->root)->defs);
305
347
        inkscape_ref();
306
348
    }
307
349
 
 
350
    // Remark: Here, we used to create a "currentpersp3d" element in the document defs.
 
351
    // But this is probably a bad idea since we need to adapt it for every change of selection, which will
 
352
    // completely clutter the undo history. Maybe rather save it to prefs on exit and re-read it on startup?
 
353
 
 
354
    document->current_persp3d = persp3d_create_xml_element (document);
 
355
 
308
356
    sp_document_set_undo_sensitive(document, true);
309
357
 
310
358
    // reset undo key when selection changes, so that same-key actions on different objects are not coalesced
317
365
        document->_selection_changed_connection = Inkscape::NSApplication::Editor::connectSelectionChanged (sigc::mem_fun (*document, &SPDocument::reset_key));
318
366
        document->_desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::mem_fun (*document, &SPDocument::reset_key));
319
367
    }
320
 
    inkscape_add_document(document);
321
368
 
322
369
    return document;
323
370
}
341
388
        rdoc = sp_repr_read_file(uri, SP_SVG_NS_URI);
342
389
        /* If file cannot be loaded, return NULL without warning */
343
390
        if (rdoc == NULL) return NULL;
344
 
        rroot = sp_repr_document_root(rdoc);
 
391
        rroot = rdoc->root();
345
392
        /* If xml file is not svg, return NULL without warning */
346
393
        /* fixme: destroy document */
347
394
        if (strcmp(rroot->name(), "svg:svg") != 0) return NULL;
390
437
    /* If it cannot be loaded, return NULL without warning */
391
438
    if (rdoc == NULL) return NULL;
392
439
 
393
 
    rroot = sp_repr_document_root(rdoc);
 
440
    rroot = rdoc->root();
394
441
    /* If xml file is not svg, return NULL without warning */
395
442
    /* fixme: destroy document */
396
443
    if (strcmp(rroot->name(), "svg:svg") != 0) return NULL;
402
449
    return doc;
403
450
}
404
451
 
405
 
SPDocument *sp_document_new_dummy() {
406
 
    SPDocument *document = new SPDocument();
407
 
    inkscape_add_document(document);
408
 
    return document;
409
 
}
410
 
 
411
452
SPDocument *
412
453
sp_document_ref(SPDocument *doc)
413
454
{
488
529
}
489
530
 
490
531
/**
491
 
 * Given an NRRect that may, for example, correspond to the bbox of an object
 
532
 * Given an NR::Rect that may, for example, correspond to the bbox of an object,
492
533
 * this function fits the canvas to that rect by resizing the canvas
493
534
 * and translating the document root into position.
494
535
 */
495
 
void SPDocument::fitToRect(NRRect const & rect)
 
536
void SPDocument::fitToRect(NR::Rect const &rect)
496
537
{
497
 
    g_return_if_fail(!empty(rect));
498
 
    
499
 
    gdouble w = rect.x1 - rect.x0;
500
 
    gdouble h = rect.y1 - rect.y0;
501
 
    gdouble old_height = sp_document_height(this);
502
 
    SPUnit unit = sp_unit_get_by_id(SP_UNIT_PX);
503
 
    sp_document_set_width(this, w, &unit);
504
 
    sp_document_set_height(this, h, &unit);
505
 
 
506
 
    NR::translate tr = NR::translate::translate(-rect.x0,-(rect.y0 + (h - old_height)));
507
 
    static_cast<SPGroup *>(root)->translateChildItems(tr);
 
538
    g_return_if_fail(!rect.isEmpty());
 
539
 
 
540
    using NR::X; using NR::Y;
 
541
    double const w = rect.extent(X);
 
542
    double const h = rect.extent(Y);
 
543
 
 
544
    double const old_height = sp_document_height(this);
 
545
    SPUnit const &px(sp_unit_get_by_id(SP_UNIT_PX));
 
546
    sp_document_set_width(this, w, &px);
 
547
    sp_document_set_height(this, h, &px);
 
548
 
 
549
    NR::translate const tr(NR::Point(0, (old_height - h))
 
550
                           - rect.min());
 
551
    SP_GROUP(root)->translateChildItems(tr);
508
552
}
509
553
 
510
554
void sp_document_set_uri(SPDocument *document, gchar const *uri)
548
592
    // changing uri in the document repr must not be not undoable
549
593
    bool saved = sp_document_get_undo_sensitive(document);
550
594
    sp_document_set_undo_sensitive(document, false);
551
 
    if (document->base)
552
 
        repr->setAttribute("sodipodi:docbase", document->base);
553
595
 
554
596
    repr->setAttribute("sodipodi:docname", document->name);
555
597
    sp_document_set_undo_sensitive(document, saved);
837
879
            s = find_items_in_area(s, SP_GROUP(o), dkey, area, test);
838
880
        } else {
839
881
            SPItem *child = SP_ITEM(o);
840
 
            NR::Rect box = sp_item_bbox_desktop(child);
841
 
            if (test(area, box) && (take_insensitive || child->isVisibleAndUnlocked(dkey))) {
 
882
            NR::Maybe<NR::Rect> box = sp_item_bbox_desktop(child);
 
883
            if ( box && test(area, *box) && (take_insensitive || child->isVisibleAndUnlocked(dkey))) {
842
884
                s = g_slist_append(s, child);
843
885
            }
844
886
        }
1004
1046
    return find_items_in_area(NULL, SP_GROUP(document->root), dkey, box, overlaps);
1005
1047
}
1006
1048
 
 
1049
GSList *
 
1050
sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<NR::Point> points)
 
1051
{
 
1052
    GSList *items = NULL;
 
1053
 
 
1054
    // When picking along the path, we don't want small objects close together 
 
1055
    // (such as hatching strokes) to obscure each other by their deltas, 
 
1056
    // so we temporarily set delta to a small value
 
1057
    gdouble saved_delta = prefs_get_double_attribute ("options.cursortolerance", "value", 1.0);
 
1058
    prefs_set_double_attribute ("options.cursortolerance", "value", 0.25);
 
1059
 
 
1060
    for(unsigned int i = 0; i < points.size(); i++) {
 
1061
        SPItem *item = sp_document_item_at_point(document, key, points[i],
 
1062
                                         false, NULL);
 
1063
        if (item && !g_slist_find(items, item))
 
1064
            items = g_slist_prepend (items, item);
 
1065
    }
 
1066
 
 
1067
    // and now we restore it back
 
1068
    prefs_set_double_attribute ("options.cursortolerance", "value", saved_delta);
 
1069
 
 
1070
    return items;
 
1071
}
 
1072
 
1007
1073
SPItem *
1008
1074
sp_document_item_at_point(SPDocument *document, unsigned const key, NR::Point const p,
1009
1075
                          gboolean const into_groups, SPItem *upto)
1098
1164
/* Helpers */
1099
1165
 
1100
1166
gboolean
1101
 
sp_document_resource_list_free(gpointer key, gpointer value, gpointer data)
 
1167
sp_document_resource_list_free(gpointer /*key*/, gpointer value, gpointer /*data*/)
1102
1168
{
1103
1169
    g_slist_free((GSList *) value);
1104
1170
    return TRUE;
1160
1226
    return start - newend;
1161
1227
}
1162
1228
 
 
1229
bool SPDocument::isSeeking() const {
 
1230
    return priv->seeking;
 
1231
}
 
1232
 
1163
1233
 
1164
1234
/*
1165
1235
  Local Variables: