canvas-grid.cpp revision 208e5a33acc4a8ad9d8c0488f047c260346f1258
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan * Copyright (C) Johan Engelen 2006-2007 <johan@shouraizou.nl>
2ae41f94c30465830758177491494f918a7a79bcLaszlo Hordos * Copyright (C) Lauris Kaplinski 2000
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan "axonomgrid"
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan// ##########################################################
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan// Grid CanvasItem
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienlestatic void grid_canvasitem_class_init (GridCanvasItemClass *klass);
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienlestatic void grid_canvasitem_init (GridCanvasItem *grid);
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienlestatic void grid_canvasitem_destroy (GtkObject *object);
5779b9adde0a838db067a3d76f3124eeb8e86d4cJason Vincentstatic void grid_canvasitem_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
5779b9adde0a838db067a3d76f3124eeb8e86d4cJason Vincentstatic void grid_canvasitem_render (SPCanvasItem *item, SPCanvasBuf *buf);
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan "GridCanvasItem",
7483266ec82ab642b8991a17132b83b6b5d72c3dTravis Hall grid_canvasitem_type = gtk_type_unique (sp_canvas_item_get_type (), &grid_canvasitem_info);
93f72edb164ef872eab6e4d482baa186a0dd6c62Andi Egloffgrid_canvasitem_class_init (GridCanvasItemClass *klass)
376d1bf8f8ca562eecccbf0a0d34aa7c7352e152Laszlo Hordos parent_class = (SPCanvasItemClass*)gtk_type_class (sp_canvas_item_get_type ());
2ae41f94c30465830758177491494f918a7a79bcLaszlo Hordos g_return_if_fail (INKSCAPE_IS_GRID_CANVASITEM (object));
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
2ae41f94c30465830758177491494f918a7a79bcLaszlo Hordosgrid_canvasitem_render (SPCanvasItem * item, SPCanvasBuf * buf)
9c8c2c05a3d08f94d29b4a42b8a0506a4e97e4faLaszlo Hordos GridCanvasItem *gridcanvasitem = INKSCAPE_GRID_CANVASITEM (item);
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan if (gridcanvasitem->grid) gridcanvasitem->grid->Render(buf);
10a9be648c010204b8ba63b283aa177749227e11Paul Bryangrid_canvasitem_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
376d1bf8f8ca562eecccbf0a0d34aa7c7352e152Laszlo Hordos GridCanvasItem *gridcanvasitem = INKSCAPE_GRID_CANVASITEM (item);
2aa8de21e6cca211bdb436c58886b60f4d32d073Brendan Miller// ##########################################################
9c8c2c05a3d08f94d29b4a42b8a0506a4e97e4faLaszlo Hordos static Inkscape::XML::NodeEventVector const _repr_events = {
2aa8de21e6cca211bdb436c58886b60f4d32d073Brendan MillerCanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc)
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan gtk_object_destroy(GTK_OBJECT(canvasitems->data));
376d1bf8f8ca562eecccbf0a0d34aa7c7352e152Laszlo Hordos canvasitems = g_slist_remove(canvasitems, canvasitems->data);
dd291c383b4490ed77e47d65b4c52595d915f802Chad KienleCanvasGrid::getGridTypeFromSVGName(char const *typestr)
dd291c383b4490ed77e47d65b4c52595d915f802Chad Kienle for (t = GRID_MAXTYPENR; t >= 0; t--) { //this automatically defaults to grid0 which is rectangular grid
dd291c383b4490ed77e47d65b4c52595d915f802Chad KienleCanvasGrid::getGridTypeFromName(char const *typestr)
dd291c383b4490ed77e47d65b4c52595d915f802Chad Kienle for (t = GRID_MAXTYPENR; t >= 0; t--) { //this automatically defaults to grid0 which is rectangular grid
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan* writes an <inkscape:grid> child to repr.
10a9be648c010204b8ba63b283aa177749227e11Paul BryanCanvasGrid::writeNewGridToRepr(Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype)
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan if (!repr) return;
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan // 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.
376d1bf8f8ca562eecccbf0a0d34aa7c7352e152Laszlo Hordos Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan newnode = xml_doc->createElement("inkscape:grid");
90e23b56c7ebf9dffe7ad87f1031103d2b49c08ePaul Bryan newnode->setAttribute("type", getSVGName(gridtype));
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan// Inkscape::GC::release(repr); FIX THIS. THIS SHOULD BE HERE!!!
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan sp_document_done(doc, SP_VERB_DIALOG_NAMEDVIEW, _("Create new grid"));
2ae41f94c30465830758177491494f918a7a79bcLaszlo Hordos* Creates a new CanvasGrid object of type gridtype
88f2d7061bb42999901dcff81c37089b000d32e0Paul BryanCanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype)
88f2d7061bb42999901dcff81c37089b000d32e0Paul Bryan return (CanvasGrid*) new CanvasXYGrid(nv, repr, doc);
90e23b56c7ebf9dffe7ad87f1031103d2b49c08ePaul Bryan return (CanvasGrid*) new CanvasAxonomGrid(nv, repr, doc);
4b93fff6cbed4e2ae34e954b9b9bd4f318d34cd4Andi Egloff* creates a new grid canvasitem for the SPDesktop given as parameter. Keeps a link to this canvasitem in the canvasitems list.
4b93fff6cbed4e2ae34e954b9b9bd4f318d34cd4Andi EgloffCanvasGrid::createCanvasItem(SPDesktop * desktop)
7483266ec82ab642b8991a17132b83b6b5d72c3dTravis Hall //Johan: I think for multiple desktops it is best if each has their own canvasitem, but share the same CanvasGrid object; that is what this function is for.
7483266ec82ab642b8991a17132b83b6b5d72c3dTravis Hall // check if there is already a canvasitem on this desktop linking to this grid
7483266ec82ab642b8991a17132b83b6b5d72c3dTravis Hall for (GSList *l = canvasitems; l != NULL; l = l->next) {
7483266ec82ab642b8991a17132b83b6b5d72c3dTravis Hall if ( sp_desktop_gridgroup(desktop) == SP_CANVAS_GROUP(SP_CANVAS_ITEM(l->data)->parent) ) {
7483266ec82ab642b8991a17132b83b6b5d72c3dTravis Hall GridCanvasItem * item = INKSCAPE_GRID_CANVASITEM( sp_canvas_item_new(sp_desktop_gridgroup(desktop), INKSCAPE_TYPE_GRID_CANVASITEM, NULL) );
7483266ec82ab642b8991a17132b83b6b5d72c3dTravis Hall gtk_object_ref(GTK_OBJECT(item)); // since we're keeping a link to this item, we need to bump up the ref count
47196c962e3caf7cdf7ea5d00ccdefc9f208bdceLaszlo Hordos canvasitems = g_slist_prepend(canvasitems, item);
88f2d7061bb42999901dcff81c37089b000d32e0Paul BryanCanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gchar const *oldval, gchar const *newval, bool is_interactive, void *data)
4b93fff6cbed4e2ae34e954b9b9bd4f318d34cd4Andi Egloff ((CanvasGrid*) data)->onReprAttrChanged(repr, key, oldval, newval, is_interactive);
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle// ##########################################################
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle// CanvasXYGrid
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle* "attach_all" function
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle* A DIRECT COPY-PASTE FROM DOCUMENT-PROPERTIES.CPP TO QUICKLY GET RESULTS
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle * Helper function that attachs widgets in a 3xn table. The widgets come in an
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle * array that has two entries per table row. The two entries code for four
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle * possible cases: (0,0) means insert space in first column; (0, non-0) means
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle * (non-0, non-0) means two widgets in columns 2 and 3.
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienlestatic inline void
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienleattach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int start = 0)
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2) {
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle table.attach (const_cast<Gtk::Widget&>(*arr[i]), 1, 2, r, r+1,
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 2, 3, r, r+1,
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 1, 3, r, r+1,
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle } else if (arr[i]) {
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle Gtk::Label& label = reinterpret_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i]));
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienleCanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc)
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle snapper = new CanvasXYGridSnapper(this, namedview, 0);
0d225a5b73f6420cb2afb27337f53e9772d8e610chad.kienle // initialize widgets:
static gboolean
if (!str) {
return FALSE;
gchar *u;
return FALSE;
while (isspace(*u)) {
*val = v;
return TRUE;
*val = v;
return TRUE;
return FALSE;
*val = v;
return TRUE;
return FALSE;
if (!str) {
return FALSE;
gchar *u;
return FALSE;
return TRUE;
double* pTarget,
if ( *pTarget <= 0 ) {
if ( oldVal <= 0 )
if ( *pTarget <= 0 ) {
if ( oldVal <= 0 )
* Called when XML node attribute changed; updates dialog widgets if change was not done by widgets themselves.
CanvasXYGrid::onReprAttrChanged(Inkscape::XML::Node *repr, gchar const *key, gchar const *oldval, gchar const *newval, bool is_interactive)
readRepr();
return vbox;
guint r, g, b, a;
guchar *p;
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
guint r, g, b, a;
guchar *p;
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
guint r, g, b, a;
guchar *p;
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
if (!render_dotted) {
gdouble y;
gdouble x;
gdouble y;
gdouble x;
CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d) : LineSnapper(nv, d)
LineList s;
if (SP_ACTIVE_DESKTOP) {