Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / widgets / desktop-widget.cpp
index 591ea62531ed0add2689ab3aa119bf080f2c7059..7a3e337ded52557484b94d5f626b51bbe21ae2f3 100644 (file)
@@ -1,5 +1,3 @@
-#define __SP_DESKTOP_WIDGET_C__
-
 /** \file
  * Desktop widget implementation
  */
@@ -10,6 +8,8 @@
  *   Ralf Stephan <ralf@ark.in-berlin.de>
  *   John Bintz <jcoswell@coswellproductions.org>
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2007 Johan Engelen
  * Copyright (C) 2006 John Bintz
@@ -41,6 +41,7 @@
 #include <extension/db.h>
 #include "file.h"
 #include "helper/units.h"
+#include "helper/unit-tracker.h"
 #include "inkscape-private.h"
 #include "interface.h"
 #include "macros.h"
@@ -69,7 +70,7 @@
 using Inkscape::round;
 #endif
 
-
+using Inkscape::UnitTracker;
 using Inkscape::UI::UXManager;
 using Inkscape::UI::ToolboxFactory;
 
@@ -325,7 +326,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
     dtw->hbox = gtk_hbox_new(FALSE, 0);
     gtk_box_pack_end( GTK_BOX (dtw->vbox), dtw->hbox, TRUE, TRUE, 0 );
     gtk_widget_show(dtw->hbox);
-
     dtw->aux_toolbox = ToolboxFactory::createAuxToolbox();
     gtk_box_pack_end (GTK_BOX (dtw->vbox), dtw->aux_toolbox, FALSE, TRUE, 0);
 
@@ -730,7 +731,7 @@ void SPDesktopWidget::updateNamedview()
     modified_connection = desktop->namedview->connectModified(sigc::mem_fun(*this, &SPDesktopWidget::namedviewModified));
     namedviewModified(desktop->namedview, SP_OBJECT_MODIFIED_FLAG);
 
-    updateTitle(SP_DOCUMENT_NAME (desktop->doc()));
+    updateTitle( desktop->doc()->getName() );
 }
 
 /**
@@ -857,7 +858,7 @@ SPDesktopWidget::shutdown()
                 GTK_BUTTONS_NONE,
                 _("<span weight=\"bold\" size=\"larger\">Save changes to document \"%s\" before closing?</span>\n\n"
                   "If you close without saving, your changes will be discarded."),
-                SP_DOCUMENT_NAME(doc));
+                doc->getName());
             // fix for bug 1767940:
             GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS);
 
@@ -899,7 +900,7 @@ SPDesktopWidget::shutdown()
         }
         /* Code to check data loss */
         bool allow_data_loss = FALSE;
-        while (sp_document_repr_root(doc)->attribute("inkscape:dataloss") != NULL && allow_data_loss == FALSE) {
+        while (doc->getReprRoot()->attribute("inkscape:dataloss") != NULL && allow_data_loss == FALSE) {
             GtkWidget *dialog;
 
             /** \todo
@@ -913,7 +914,7 @@ SPDesktopWidget::shutdown()
                 GTK_BUTTONS_NONE,
                 _("<span weight=\"bold\" size=\"larger\">The file \"%s\" was saved with a format (%s) that may cause data loss!</span>\n\n"
                   "Do you want to save this file as Inkscape SVG?"),
-                SP_DOCUMENT_NAME(doc)? SP_DOCUMENT_NAME(doc) : "Unnamed",
+                doc->getName() ? doc->getName() : "Unnamed",
                 SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE);
             // fix for bug 1767940:
             GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS);
@@ -1510,6 +1511,40 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags)
         sp_ruler_set_metric(GTK_RULER (this->vruler), nv->getDefaultMetric());
         sp_ruler_set_metric(GTK_RULER (this->hruler), nv->getDefaultMetric());
 
+        /* This loops through all the grandchildren of aux toolbox,
+         * and for each that it finds, it performs an sp_search_by_data_recursive(),
+         * looking for widgets that hold some "tracker" data (this is used by
+         * all toolboxes to refer to the unit selector). The default document units 
+         * is then selected within these unit selectors.
+         *
+         * Of course it would be nice to be able to refer to the toolbox and the
+         * unit selector directly by name, but I don't yet see a way to do that.
+         * 
+         * This should solve: https://bugs.launchpad.net/inkscape/+bug/362995
+         */
+        if (GTK_IS_CONTAINER(aux_toolbox)) {
+            GList *ch = gtk_container_get_children (GTK_CONTAINER(aux_toolbox));
+            for (GList *i = ch; i != NULL; i = i->next) {
+                if (GTK_IS_CONTAINER(i->data)) {
+                    GList *grch = gtk_container_get_children (GTK_CONTAINER(i->data));
+                    for (GList *j = grch; j != NULL; j = j->next) {                        
+                        if (!GTK_IS_WIDGET(j->data)) // wasn't a widget
+                            continue;
+
+                        gpointer t = sp_search_by_data_recursive(GTK_WIDGET(j->data), (gpointer) "tracker");
+                        if (t == NULL) // didn't find any tracker data
+                            continue;
+
+                        UnitTracker *tracker = reinterpret_cast<UnitTracker*>( t );
+                        if (tracker == NULL) // it's null when inkscape is first opened
+                            continue;
+
+                        tracker->setActiveUnit( nv->doc_units );
+                    } // grandchildren
+                } // if child is a container
+            } // children
+        } // if aux_toolbox is a container
+
         gtk_tooltips_set_tip(this->tt, this->hruler_box, gettext(sp_unit_get_plural (nv->doc_units)), NULL);
         gtk_tooltips_set_tip(this->tt, this->vruler_box, gettext(sp_unit_get_plural (nv->doc_units)), NULL);
 
@@ -1540,7 +1575,7 @@ bool SPDesktopWidget::onFocusInEvent(GdkEventFocus*)
 {
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
     if (prefs->getBool("/options/bitmapautoreload/value", true)) {
-        GSList const *imageList = (desktop->doc())->get_resource_list("image");
+        GSList const *imageList = (desktop->doc())->getResourceList("image");
         for (GSList const *p = imageList; p; p = p->next) {
             SPImage* image = SP_IMAGE(p->data);
             sp_image_refresh_if_outdated( image );