summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a614fca)
raw | patch | inline | side by side (parent: a614fca)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Thu, 14 Jun 2007 20:37:08 +0000 (20:37 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Thu, 14 Jun 2007 20:37:08 +0000 (20:37 +0000) |
src/display/canvas-grid.cpp | patch | blob | history |
index 8c626355df6bc656de3fa8eb0413237f637b5895..e1cafb1fd6df240102481ce4d013c3d4a876f3e8 100644 (file)
return TRUE;
}
+/** If the passed scalar is invalid (<=0), then set the widget and the scalar
+ to use the given old value.
+ @param oldVal old value to use if the new one is invalid
+ @param pTarget the scalar to validate
+ @param widget widget associated with the scalar
+*/
+static void validateScalar(double oldVal,
+ double* pTarget,
+ Inkscape::UI::Widget::RegisteredScalarUnit& widget)
+{
+ // Avoid nullness.
+ if ( pTarget == NULL )
+ return;
+
+ // Invalid new value?
+ if ( *pTarget <= 0 )
+ {
+ // If the old value is somehow invalid as well, then default to 1.
+ if ( oldVal <= 0 )
+ oldVal = 1;
+
+ // Reset the scalar and associated widget to the old value.
+ *pTarget = oldVal;
+ widget.setValue( *pTarget);
+ } //if
+
+} //validateScalar
+
+
+/** If the passed int is invalid (<=0), then set the widget and the int
+ to use the given old value.
+ @param oldVal old value to use if the new one is invalid
+ @param pTarget the int to validate
+ @param widget widget associated with the int
+*/
+static void validateInt(gint oldVal,
+ gint* pTarget,
+ Inkscape::UI::Widget::RegisteredSuffixedInteger& widget)
+{
+ // Avoid nullness.
+ if ( pTarget == NULL )
+ return;
+ // Invalid new value?
+ if ( *pTarget <= 0 )
+ {
+ // If the old value is somehow invalid as well, then default to 1.
+ if ( oldVal <= 0 )
+ oldVal = 1;
+
+ // Reset the int and associated widget to the old value.
+ *pTarget = oldVal;
+ widget.setValue( *pTarget);
+ } //if
+
+} //validateInt
void
CanvasXYGrid::readRepr()
{
+ char buff[100];
gchar const* value;
if ( (value = repr->attribute("originx")) ) {
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[NR::X], &gridunit);
origin[NR::X] = sp_units_get_pixels(origin[NR::X], *(gridunit));
+
}
if ( (value = repr->attribute("originy")) ) {
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[NR::Y], &gridunit);
}
if ( (value = repr->attribute("spacingx")) ) {
+ double oldVal = spacing[NR::X];
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[NR::X], &gridunit);
+ validateScalar( oldVal, &spacing[NR::X], _rsu_sx );
spacing[NR::X] = sp_units_get_pixels(spacing[NR::X], *(gridunit));
+
}
if ( (value = repr->attribute("spacingy")) ) {
+ double oldVal = spacing[NR::Y];
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[NR::Y], &gridunit);
+ validateScalar( oldVal, &spacing[NR::Y], _rsu_sy );
spacing[NR::Y] = sp_units_get_pixels(spacing[NR::Y], *(gridunit));
+
}
if ( (value = repr->attribute("color")) ) {
}
if ( (value = repr->attribute("empspacing")) ) {
+ gint oldVal = empspacing;
empspacing = atoi(value);
+ validateInt( oldVal, &empspacing, _rsi );
}
-
+
if ( (value = repr->attribute("dotted")) ) {
render_dotted = (strcmp(value,"true") == 0);
- }
+ }
for (GSList *l = canvasitems; l != NULL; l = l->next) {
sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) );