Code

Don't force focus on the canvas when the desktop is given
[inkscape.git] / src / widgets / desktop-widget.cpp
index 6b15bb370a0b081576b18f5f8e2eeb38e8caa0f5..3562e7b2a8a63307f55c5dc03ef0d62f28e5d124 100644 (file)
@@ -9,7 +9,9 @@
  *   bulia byak <buliabyak@users.sf.net>
  *   Ralf Stephan <ralf@ark.in-berlin.de>
  *   John Bintz <jcoswell@coswellproductions.org>
+ *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
  *
+ * Copyright (C) 2007 Johan Engelen
  * Copyright (C) 2006 John Bintz
  * Copyright (C) 2004 MenTaLguY
  * Copyright (C) 1999-2002 Lauris Kaplinski
@@ -37,6 +39,7 @@
 #include "prefs-utils.h"
 #include "file.h"
 #include "display/canvas-arena.h"
+#include "display/nr-arena.h"
 #include <extension/db.h>
 #include "helper/units.h"
 #include "widgets/button.h"
 #include "widgets/spw-utilities.h"
 #include "widgets/spinbutton-events.h"
 #include "widgets/layer-selector.h"
+#include "ui/dialog/dialog-manager.h"
+#include "ui/widget/dock.h"
 #include "ui/widget/selected-style.h"
 #include "sp-item.h"
 #include "dialogs/swatches.h"
 #include "conn-avoid-ref.h"
+#include "ege-select-one-action.h"
+
+#if defined (SOLARIS_2_8)
+#include "round.h"
+using Inkscape::round;
+#endif
 
 #ifdef WITH_INKBOARD
 #endif
@@ -76,8 +87,6 @@ static void sp_desktop_widget_realize (GtkWidget *widget);
 
 static gint sp_desktop_widget_event (GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw);
 
-
-
 static void sp_desktop_widget_adjustment_value_changed (GtkAdjustment *adj, SPDesktopWidget *dtw);
 static void sp_desktop_widget_namedview_modified (SPObject *obj, guint flags, SPDesktopWidget *dtw);
 
@@ -97,11 +106,18 @@ static void sp_dtw_zoom_selection (GtkMenuItem *item, gpointer data);
 
 SPViewWidgetClass *dtw_parent_class;
 
-void 
+void
 SPDesktopWidget::setMessage (Inkscape::MessageType type, const gchar *message)
 {
     GtkLabel *sb=GTK_LABEL(this->select_status);
     gtk_label_set_markup (sb, message ? message : "");
+
+    // make sure the important messages are displayed immediately!
+    if (type == Inkscape::IMMEDIATE_MESSAGE && GTK_WIDGET_DRAWABLE (GTK_WIDGET(sb))) {
+        gtk_widget_queue_draw(GTK_WIDGET(sb));
+        gdk_window_process_updates(GTK_WIDGET(sb)->window, TRUE);
+    }
+
     // FIXME: TODO: remove <b></b> before displaying as tooltip
     gtk_tooltips_set_tip (this->tt, this->select_status_eventbox, message ? message : "", NULL);
 }
@@ -160,6 +176,7 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
 {
     GtkWidget *widget;
     GtkWidget *tbl;
+    GtkWidget *canvas_tbl;
 
     GtkWidget *hbox;
     GtkWidget *eventbox;
@@ -170,11 +187,11 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     widget = GTK_WIDGET (dtw);
 
     dtw->window = 0;
-    
+
     dtw->desktop = NULL;
 
     dtw->_interaction_disabled_counter = 0;
-    
+
     dtw->tt = gtk_tooltips_new ();
 
     /* Main table */
@@ -207,9 +224,11 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     dtw->tool_toolbox = sp_tool_toolbox_new ();
     gtk_box_pack_start (GTK_BOX (hbox), dtw->tool_toolbox, FALSE, TRUE, 0);
 
-    tbl = gtk_table_new (4, 3, FALSE);
+    tbl = gtk_table_new (2, 3, FALSE);
     gtk_box_pack_start (GTK_BOX (hbox), tbl, TRUE, TRUE, 1);
 
+    canvas_tbl = gtk_table_new (3, 3, FALSE);
+
     /* Horizontal ruler */
     eventbox = gtk_event_box_new ();
     dtw->hruler = sp_hruler_new ();
@@ -217,7 +236,7 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     sp_ruler_set_metric (GTK_RULER (dtw->hruler), SP_PT);
     gtk_tooltips_set_tip (dtw->tt, dtw->hruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT))), NULL);
     gtk_container_add (GTK_CONTAINER (eventbox), dtw->hruler);
-    gtk_table_attach (GTK_TABLE (tbl), eventbox, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL), widget->style->xthickness, 0);
+    gtk_table_attach (GTK_TABLE (canvas_tbl), eventbox, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL), widget->style->xthickness, 0);
     g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_hruler_event), dtw);
     g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw);
     g_signal_connect (G_OBJECT (eventbox), "motion_notify_event", G_CALLBACK (sp_dt_hruler_event), dtw);
@@ -229,7 +248,7 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     sp_ruler_set_metric (GTK_RULER (dtw->vruler), SP_PT);
     gtk_tooltips_set_tip (dtw->tt, dtw->vruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT))), NULL);
     gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler));
-    gtk_table_attach (GTK_TABLE (tbl), eventbox, 0, 1, 1, 2, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL), 0, widget->style->ythickness);
+    gtk_table_attach (GTK_TABLE (canvas_tbl), eventbox, 0, 1, 1, 2, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL), 0, widget->style->ythickness);
     g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_vruler_event), dtw);
     g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_vruler_event), dtw);
     g_signal_connect (G_OBJECT (eventbox), "motion_notify_event", G_CALLBACK (sp_dt_vruler_event), dtw);
@@ -237,7 +256,8 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     /* Horizontal scrollbar */
     dtw->hadj = (GtkAdjustment *) gtk_adjustment_new (0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0);
     dtw->hscrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (dtw->hadj));
-    gtk_table_attach (GTK_TABLE (tbl), dtw->hscrollbar, 1, 2, 2, 3, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_FILL), 0, 0);
+    gtk_table_attach (GTK_TABLE (canvas_tbl), dtw->hscrollbar, 1, 2, 2, 3, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_SHRINK), 0, 0);
+
     /* Vertical scrollbar and the sticky zoom button */
     dtw->vscrollbar_box = gtk_vbox_new (FALSE, 0);
     dtw->sticky_zoom = sp_button_new_from_data ( Inkscape::ICON_SIZE_DECORATION,
@@ -251,8 +271,8 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     dtw->vadj = (GtkAdjustment *) gtk_adjustment_new (0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0);
     dtw->vscrollbar = gtk_vscrollbar_new (GTK_ADJUSTMENT (dtw->vadj));
     gtk_box_pack_start (GTK_BOX (dtw->vscrollbar_box), dtw->vscrollbar, TRUE, TRUE, 0);
-    gtk_table_attach (GTK_TABLE (tbl), dtw->vscrollbar_box, 2, 3, 0, 2, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
-
+    gtk_table_attach (GTK_TABLE (canvas_tbl), dtw->vscrollbar_box, 2, 3, 0, 2, (GtkAttachOptions)(GTK_SHRINK), (GtkAttachOptions)(GTK_FILL), 0, 0);
+   
     /* Canvas */
     dtw->canvas = SP_CANVAS (sp_canvas_new_aa ());
     GTK_WIDGET_SET_FLAGS (GTK_WIDGET (dtw->canvas), GTK_CAN_FOCUS);
@@ -261,7 +281,34 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     gtk_widget_set_style (GTK_WIDGET (dtw->canvas), style);
     gtk_widget_set_extension_events(GTK_WIDGET (dtw->canvas) , GDK_EXTENSION_EVENTS_ALL);
     g_signal_connect (G_OBJECT (dtw->canvas), "event", G_CALLBACK (sp_desktop_widget_event), dtw);
-    gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (dtw->canvas), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
+    gtk_table_attach (GTK_TABLE (canvas_tbl), GTK_WIDGET(dtw->canvas), 1, 2, 1, 2, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), 0, 0);
+
+    /* Dock */
+    bool create_dock = 
+        prefs_get_int_attribute_limited ("options.dialogtype", "value", Inkscape::UI::Dialog::FLOATING, 0, 1) == 
+        Inkscape::UI::Dialog::DOCK;
+    
+    if (create_dock)
+    {
+        dtw->dock = new Inkscape::UI::Widget::Dock();
+
+        Gtk::HPaned *paned = new Gtk::HPaned();
+        paned->pack1(*Glib::wrap(canvas_tbl));
+        paned->pack2(dtw->dock->getWidget(), Gtk::FILL);
+
+        /* Prevent the paned from catching F6 and F8 by unsetting the default callbacks */ 
+        if (GtkPanedClass *paned_class = GTK_PANED_CLASS (G_OBJECT_GET_CLASS (paned->gobj()))) {
+            paned_class->cycle_child_focus = NULL;
+            paned_class->cycle_handle_focus = NULL;
+        }
+
+        gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (paned->gobj()), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 
+                          (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
+
+    } else {
+        gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (canvas_tbl), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 
+                          (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
+    }
 
     dtw->selected_style = new Inkscape::UI::Widget::SelectedStyle(true);
     GtkHBox *ss_ = dtw->selected_style->gobj();
@@ -305,10 +352,12 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     GtkWidget *label_y = gtk_label_new("Y:");
     gtk_misc_set_alignment (GTK_MISC(label_y), 0.0, 0.5);
     gtk_table_attach(GTK_TABLE(dtw->coord_status),  label_y, 1,2, 1,2, GTK_FILL, GTK_FILL, 0, 0);
-    dtw->coord_status_x = gtk_label_new("0.0");
-    gtk_misc_set_alignment (GTK_MISC(dtw->coord_status_x), 0.0, 0.5);
-    dtw->coord_status_y = gtk_label_new("0.0");
-    gtk_misc_set_alignment (GTK_MISC(dtw->coord_status_y), 0.0, 0.5);
+    dtw->coord_status_x = gtk_label_new(NULL);
+    gtk_label_set_markup( GTK_LABEL(dtw->coord_status_x), "<tt>   0.00 </tt>" );
+    gtk_misc_set_alignment (GTK_MISC(dtw->coord_status_x), 1.0, 0.5);
+    dtw->coord_status_y = gtk_label_new(NULL);
+    gtk_label_set_markup( GTK_LABEL(dtw->coord_status_y), "<tt>   0.00 </tt>" );
+    gtk_misc_set_alignment (GTK_MISC(dtw->coord_status_y), 1.0, 0.5);
     gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->coord_status_x, 2,3, 0,1, GTK_FILL, GTK_FILL, 0, 0);
     gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->coord_status_y, 2,3, 1,2, GTK_FILL, GTK_FILL, 0, 0);
     gtk_table_attach(GTK_TABLE(dtw->coord_status),  gtk_label_new("Z:"), 3,4, 0,2, GTK_FILL, GTK_FILL, 0, 0);
@@ -373,29 +422,44 @@ sp_desktop_widget_destroy (GtkObject *object)
 
 /**
  * Set the title in the desktop-window (if desktop has an own window).
- * 
+ *
  * The title has form file name: desktop number - Inkscape.
  * The desktop number is only shown if it's 2 or higher,
  */
 void
 SPDesktopWidget::updateTitle(gchar const* uri)
 {
-    GtkWindow *window = GTK_WINDOW (gtk_object_get_data (GTK_OBJECT(this), "window"));
+       Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+
     if (window) {
         gchar const *fname = ( TRUE
                                ? uri
                                : g_basename(uri) );
         GString *name = g_string_new ("");
         if (this->desktop->number > 1) {
-            g_string_printf (name, _("%s: %d - Inkscape"), fname, this->desktop->number);
+            if (this->desktop->getMode() == RENDERMODE_OUTLINE) {
+                g_string_printf (name, _("%s: %d (outline) - Inkscape"), fname, this->desktop->number);
+            } else {
+                g_string_printf (name, _("%s: %d - Inkscape"), fname, this->desktop->number);
+            }
         } else {
-            g_string_printf (name, _("%s - Inkscape"), fname);
+            if (this->desktop->getMode() == RENDERMODE_OUTLINE) {
+                g_string_printf (name, _("%s (outline) - Inkscape"), fname);
+            } else {
+                g_string_printf (name, _("%s - Inkscape"), fname);
+            }
         }
-        gtk_window_set_title (window, name->str);
+        window->set_title (name->str);
         g_string_free (name, TRUE);
     }
 }
 
+Inkscape::UI::Widget::Dock*
+SPDesktopWidget::getDock()
+{
+    return dock;
+}
+
 /**
  * Callback to allocate space for desktop widget.
  */
@@ -526,42 +590,30 @@ sp_dtw_desktop_deactivate (SPDesktopWidget *dtw)
  *  to save, discard, or cancel.  Returns TRUE if the shutdown operation
  *  is cancelled or if the save is cancelled or fails, FALSE otherwise.
  */
-bool 
+bool
 SPDesktopWidget::shutdown()
 {
     g_assert(desktop != NULL);
+
     if (inkscape_is_sole_desktop_for_document(*desktop)) {
         SPDocument *doc = desktop->doc();
         if (sp_document_repr_root(doc)->attribute("sodipodi:modified") != NULL) {
             GtkWidget *dialog;
 
-            dialog = gtk_message_dialog_new(
+            /** \todo
+             * FIXME !!! obviously this will have problems if the document
+             * name contains markup characters
+             */
+            dialog = gtk_message_dialog_new_with_markup(
                 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(this))),
                 GTK_DIALOG_DESTROY_WITH_PARENT,
                 GTK_MESSAGE_WARNING,
                 GTK_BUTTONS_NONE,
-                "Document modified");
-
-            gchar *markup;
-            /** \todo
-             * FIXME !!! obviously this will have problems if the document 
-             * name contains markup characters
-             */
-            markup = g_strdup_printf(
                 _("<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));
-
-            /** \todo
-             * FIXME !!! Gtk 2.3+ gives us gtk_message_dialog_set_markup() 
-             * (and actually even 
-             * gtk_message_dialog_new_with_markup(..., format, ...)!) -- 
-             * until then, we will have to be a little bit evil here and 
-             * poke at GtkMessageDialog::label, which is private... 
-             */
-
-            gtk_label_set_markup(GTK_LABEL(GTK_MESSAGE_DIALOG(dialog)->label), markup);
-            g_free(markup);
+            // fix for bug 1767940:             
+            GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS);
 
             GtkWidget *close_button;
             close_button = gtk_button_new_with_mnemonic(_("Close _without saving"));
@@ -578,14 +630,19 @@ SPDesktopWidget::shutdown()
 
             switch (response) {
             case GTK_RESPONSE_YES:
-                sp_document_ref(doc);
-                if (sp_file_save_document(doc)) {
+            {
+               Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+                   
+               sp_document_ref(doc);
+                if (sp_file_save_document(*window, doc)) {
                     sp_document_unref(doc);
                 } else { // save dialog cancelled or save failed
                     sp_document_unref(doc);
                     return TRUE;
                 }
+                
                 break;
+            }
             case GTK_RESPONSE_NO:
                 break;
             default: // cancel pressed, or dialog was closed
@@ -598,34 +655,21 @@ SPDesktopWidget::shutdown()
         while (sp_document_repr_root(doc)->attribute("inkscape:dataloss") != NULL && allow_data_loss == FALSE) {
             GtkWidget *dialog;
 
-            dialog = gtk_message_dialog_new(
+            /** \todo
+             * FIXME !!! obviously this will have problems if the document
+             * name contains markup characters
+             */
+            dialog = gtk_message_dialog_new_with_markup(
                 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(this))),
                 GTK_DIALOG_DESTROY_WITH_PARENT,
                 GTK_MESSAGE_WARNING,
                 GTK_BUTTONS_NONE,
-                "Document modified");
-
-            gchar *markup;
-            /** \todo 
-             * FIXME !!! obviously this will have problems if the document 
-             * name contains markup characters
-             */
-            markup = g_strdup_printf(
                 _("<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 in another format?"),
                 SP_DOCUMENT_NAME(doc),
                 Inkscape::Extension::db.get(sp_document_repr_root(doc)->attribute("inkscape:output_extension"))->get_name());
-
-            /** \todo
-             * FIXME !!! Gtk 2.3+ gives us gtk_message_dialog_set_markup() 
-             * (and actually even 
-             * gtk_message_dialog_new_with_markup(..., format, ...)!) -- 
-             * until then, we will have to be a little bit evil here and 
-             * poke at GtkMessageDialog::label, which is private... 
-             */
-
-            gtk_label_set_markup(GTK_LABEL(GTK_MESSAGE_DIALOG(dialog)->label), markup);
-            g_free(markup);
+            // fix for bug 1767940:             
+            GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS);
 
             GtkWidget *close_button;
             close_button = gtk_button_new_with_mnemonic(_("Close _without saving"));
@@ -642,14 +686,20 @@ SPDesktopWidget::shutdown()
 
             switch (response) {
             case GTK_RESPONSE_YES:
-                sp_document_ref(doc);
-                if (sp_file_save_dialog(doc)) {
+            {
+               sp_document_ref(doc);
+               
+               Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+               
+                if (sp_file_save_dialog(*window, doc)) {
                     sp_document_unref(doc);
                 } else { // save dialog cancelled or save failed
                     sp_document_unref(doc);
                     return TRUE;
                 }
+                
                 break;
+            }
             case GTK_RESPONSE_NO:
                 allow_data_loss = TRUE;
                 break;
@@ -660,22 +710,44 @@ SPDesktopWidget::shutdown()
         }
     }
 
+    /* Save window geometry to prefs for use as a default.
+     * Use depends on setting of "options.savewindowgeometry".
+     * But we save the info here regardless of the setting.
+     */
+    {
+        gint full = desktop->is_fullscreen() ? 1 : 0;
+        gint maxed = desktop->is_maximized() ? 1 : 0;
+        prefs_set_int_attribute("desktop.geometry", "fullscreen", full);
+        prefs_set_int_attribute("desktop.geometry", "maximized", maxed);
+        gint w, h, x, y;
+        desktop->getWindowGeometry(x, y, w, h);
+        // Don't save geom for maximized windows.  It 
+        // just tells you the current maximized size, which is not
+        // as useful as whatever value it had previously.
+        if (!maxed && !full) {
+            prefs_set_int_attribute("desktop.geometry", "width", w);
+            prefs_set_int_attribute("desktop.geometry", "height", h);
+            prefs_set_int_attribute("desktop.geometry", "x", x);
+            prefs_set_int_attribute("desktop.geometry", "y", y);
+        }
+    }
+
     return FALSE;
 }
 
 /**
  * \pre this->desktop->main != 0
  */
-void 
+void
 SPDesktopWidget::requestCanvasUpdate() {
     gtk_widget_queue_draw (GTK_WIDGET (SP_CANVAS_ITEM (this->desktop->main)->canvas));
 }
 
-void 
+void
 SPDesktopWidget::requestCanvasUpdateAndWait() {
     requestCanvasUpdate();
-    
-    while (gtk_events_pending()) 
+
+    while (gtk_events_pending())
       gtk_main_iteration_do(FALSE);
 
 }
@@ -684,9 +756,9 @@ void
 SPDesktopWidget::enableInteraction()
 {
   g_return_if_fail(_interaction_disabled_counter > 0);
-  
+
   _interaction_disabled_counter--;
-  
+
   if (_interaction_disabled_counter == 0) {
     gtk_widget_set_sensitive(GTK_WIDGET(this), TRUE);
   }
@@ -698,88 +770,93 @@ SPDesktopWidget::disableInteraction()
   if (_interaction_disabled_counter == 0) {
     gtk_widget_set_sensitive(GTK_WIDGET(this), FALSE);
   }
-  
+
   _interaction_disabled_counter++;
 }
 
-void 
+void
 SPDesktopWidget::setCoordinateStatus(NR::Point p)
 {
     gchar *cstr;
-    cstr=g_strdup_printf("%6.2f", dt2r * p[NR::X]);
-    gtk_label_set_text (GTK_LABEL (this->coord_status_x), cstr);
+    cstr = g_strdup_printf("<tt>%7.2f </tt>", dt2r * p[NR::X]);
+    gtk_label_set_markup( GTK_LABEL(this->coord_status_x), cstr );
     g_free(cstr);
-    cstr=g_strdup_printf("%6.2f", dt2r * p[NR::Y]);
-    gtk_label_set_text (GTK_LABEL (this->coord_status_y), cstr);
+
+    cstr = g_strdup_printf("<tt>%7.2f </tt>", dt2r * p[NR::Y]);
+    gtk_label_set_markup( GTK_LABEL(this->coord_status_y), cstr );
     g_free(cstr);
 }
 
 void
 SPDesktopWidget::letZoomGrabFocus()
 {
-    if (zoom_status) 
+    if (zoom_status)
         gtk_widget_grab_focus (zoom_status);
 }
-    
-void 
+
+void
 SPDesktopWidget::getWindowGeometry (gint &x, gint &y, gint &w, gint &h)
 {
-    GtkWindow *window = GTK_WINDOW (gtk_object_get_data (GTK_OBJECT(this), "window"));
+    gboolean vis = GTK_WIDGET_VISIBLE (this);
+
+    Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+    
     if (window)
     {
-        gtk_window_get_size (window, &w, &h);
-        gtk_window_get_position (window, &x, &y);
+        window->get_size (w, h);
+        window->get_position (x, y);
     }
 }
 
 void
 SPDesktopWidget::setWindowPosition (NR::Point p)
 {
-    GtkWindow *window = GTK_WINDOW (gtk_object_get_data (GTK_OBJECT(this), "window"));
+       Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+    
     if (window)
     {
-        gtk_window_move (window, gint(round(p[NR::X])), gint(round(p[NR::Y])));
+        window->move (gint(round(p[NR::X])), gint(round(p[NR::Y])));
     }
 }
 
 void
 SPDesktopWidget::setWindowSize (gint w, gint h)
 {
-    GtkWindow *window = GTK_WINDOW (gtk_object_get_data (GTK_OBJECT(this), "window"));
+       Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+    
     if (window)
     {
-        gtk_window_set_default_size (window, w, h);
-        gtk_window_reshow_with_initial_size (window);
+        window->set_default_size (w, h);
+        window->reshow_with_initial_size ();
     }
 }
 
 /**
- * \note transientizing does not work on windows; when you minimize a document 
- * and then open it back, only its transient emerges and you cannot access 
- * the document window.
+ * \note transientizing does not work on windows; when you minimize a document
+ * and then open it back, only its transient emerges and you cannot access
+ * the document window. The document window must be restored by rightclicking
+ * the taskbar button and pressing "Restore"
  */
 void
 SPDesktopWidget::setWindowTransient (void *p, int transient_policy)
 {
-#ifndef WIN32
     GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(this)));
     if (w)
     {
         gtk_window_set_transient_for (GTK_WINDOW(p), w);
-        
-        /* 
+
+        /*
          * This enables "aggressive" transientization,
-         * i.e. dialogs always emerging on top when you switch documents. Note 
-         * however that this breaks "click to raise" policy of a window 
-         * manager because the switched-to document will be raised at once 
+         * i.e. dialogs always emerging on top when you switch documents. Note
+         * however that this breaks "click to raise" policy of a window
+         * manager because the switched-to document will be raised at once
          * (so that its transients also could raise)
          */
         if (transient_policy == 2)
-        
+
             // without this, a transient window not always emerges on top
-            gtk_window_present (w); 
+            gtk_window_present (w);
     }
-#endif
 }
 
 void
@@ -787,7 +864,7 @@ SPDesktopWidget::presentWindow()
 {
     GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(this)));
     if (w)
-        gtk_window_present (w); 
+        gtk_window_present (w);
 }
 
 bool
@@ -801,7 +878,7 @@ SPDesktopWidget::warnDialog (gchar* text)
                 GTK_DIALOG_DESTROY_WITH_PARENT,
                 GTK_MESSAGE_WARNING,
                 GTK_BUTTONS_YES_NO,
-                text);
+                "%s", text);
         gint response = gtk_dialog_run(GTK_DIALOG(dialog));
         gtk_widget_destroy(dialog);
         if (response == GTK_RESPONSE_YES)
@@ -810,20 +887,68 @@ SPDesktopWidget::warnDialog (gchar* text)
     return false;
 }
 
+void
+sp_desktop_widget_iconify(SPDesktopWidget *dtw)
+{
+    GtkWindow *topw = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(dtw->canvas)));
+    if (GTK_IS_WINDOW(topw)) {
+        if (dtw->desktop->is_iconified()) {
+            gtk_window_deiconify(topw);
+        } else {
+            gtk_window_iconify(topw);
+        }
+    }
+}
+
+void
+sp_desktop_widget_maximize(SPDesktopWidget *dtw)
+{
+    GtkWindow *topw = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(dtw->canvas)));
+    if (GTK_IS_WINDOW(topw)) {
+        if (dtw->desktop->is_maximized()) {
+            gtk_window_unmaximize(topw);
+        } else {
+            // Save geometry to prefs before maximizing so that 
+            // something useful is stored there, because GTK doesn't maintain
+            // a separate non-maximized size.
+            if (!dtw->desktop->is_iconified() && !dtw->desktop->is_fullscreen()) 
+            {
+                gint w, h, x, y;
+                dtw->getWindowGeometry(x, y, w, h);
+                prefs_set_int_attribute("desktop.geometry", "width", w);
+                prefs_set_int_attribute("desktop.geometry", "height", h);
+                prefs_set_int_attribute("desktop.geometry", "x", x);
+                prefs_set_int_attribute("desktop.geometry", "y", y);
+            }
+            gtk_window_maximize(topw);
+        }
+    }
+}
+
 void
 sp_desktop_widget_fullscreen(SPDesktopWidget *dtw)
 {
 #ifdef HAVE_GTK_WINDOW_FULLSCREEN
     GtkWindow *topw = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(dtw->canvas)));
     if (GTK_IS_WINDOW(topw)) {
-        if (dtw->desktop->is_fullscreen) {
-            dtw->desktop->is_fullscreen = FALSE;
+        if (dtw->desktop->is_fullscreen()) {
             gtk_window_unfullscreen(topw);
-            sp_desktop_widget_layout (dtw);
+            // widget layout is triggered by the resulting window_state_event
         } else {
-            dtw->desktop->is_fullscreen = TRUE;
+            // Save geometry to prefs before maximizing so that 
+            // something useful is stored there, because GTK doesn't maintain
+            // a separate non-maximized size.
+            if (!dtw->desktop->is_iconified() && !dtw->desktop->is_maximized()) 
+            {
+                gint w, h, x, y;
+                dtw->getWindowGeometry(x, y, w, h);
+                prefs_set_int_attribute("desktop.geometry", "width", w);
+                prefs_set_int_attribute("desktop.geometry", "height", h);
+                prefs_set_int_attribute("desktop.geometry", "x", x);
+                prefs_set_int_attribute("desktop.geometry", "y", y);
+            }
             gtk_window_fullscreen(topw);
-            sp_desktop_widget_layout (dtw);
+            // widget layout is triggered by the resulting window_state_event
         }
     }
 #endif /* HAVE_GTK_WINDOW_FULLSCREEN */
@@ -835,7 +960,7 @@ sp_desktop_widget_fullscreen(SPDesktopWidget *dtw)
 void
 sp_desktop_widget_layout (SPDesktopWidget *dtw)
 {
-    bool fullscreen = dtw->desktop->is_fullscreen;
+    bool fullscreen = dtw->desktop->is_fullscreen();
 
     if (prefs_get_int_attribute (fullscreen ? "fullscreen.menu" : "window.menu", "state", 1) == 0) {
         gtk_widget_hide_all (dtw->menubar);
@@ -896,7 +1021,7 @@ void
 SPDesktopWidget::setToolboxFocusTo (const gchar* label)
 {
     gpointer hb = sp_search_by_data_recursive(aux_toolbox, (gpointer) label);
-    if (hb && GTK_IS_WIDGET(hb)) 
+    if (hb && GTK_IS_WIDGET(hb))
     {
         gtk_widget_grab_focus(GTK_WIDGET(hb));
     }
@@ -912,12 +1037,34 @@ SPDesktopWidget::setToolboxAdjustmentValue (gchar const *id, double value)
     }
 }
 
+void
+SPDesktopWidget::setToolboxSelectOneValue (gchar const *id, int value)
+{
+    gpointer hb = sp_search_by_data_recursive(aux_toolbox, (gpointer) id);
+    if (hb) {
+        ege_select_one_action_set_active((EgeSelectOneAction*) hb, value);
+    }
+}
+
+
 bool
 SPDesktopWidget::isToolboxButtonActive (const gchar* id)
 {
-    GtkToggleButton *b = (GtkToggleButton *) sp_search_by_data_recursive(aux_toolbox, (gpointer) id);
+    bool isActive = false;
+    gpointer thing = sp_search_by_data_recursive(aux_toolbox, (gpointer) id);
+    if ( !thing ) {
+        //g_message( "Unable to locate item for {%s}", id );
+    } else if ( GTK_IS_TOGGLE_BUTTON(thing) ) {
+        GtkToggleButton *b = GTK_TOGGLE_BUTTON(thing);
+        isActive = gtk_toggle_button_get_active( b ) != 0;
+    } else if ( GTK_IS_TOGGLE_ACTION(thing) ) {
+        GtkToggleAction* act = GTK_TOGGLE_ACTION(thing);
+        isActive = gtk_toggle_action_get_active( act ) != 0;
+    } else {
+        //g_message( "Item for {%s} is of an unsupported type", id );
+    }
 
-    return gtk_toggle_button_get_active (b) != 0;
+    return isActive;
 }
 
 SPViewWidget *
@@ -926,7 +1073,8 @@ sp_desktop_widget_new (SPNamedView *namedview)
     SPDesktopWidget *dtw = (SPDesktopWidget*)gtk_type_new (SP_TYPE_DESKTOP_WIDGET);
 
     dtw->dt2r = 1.0 / namedview->doc_units->unittobase;
-    dtw->ruler_origin = namedview->gridorigin;
+
+    dtw->ruler_origin = NR::Point(0,0); //namedview->gridorigin;   Why was the grid origin used here?
 
     dtw->desktop = new SPDesktop();
     dtw->stub = new SPDesktopWidget::WidgetStub (dtw);
@@ -937,7 +1085,7 @@ sp_desktop_widget_new (SPNamedView *namedview)
     // Add the shape geometry to libavoid for autorouting connectors.
     // This needs desktop set for its spacing preferences.
     init_avoided_shape_geometry(dtw->desktop);
-    
+
     dtw->selected_style->setDesktop(dtw->desktop);
 
     /* Once desktop is set, we can update rulers */
@@ -995,7 +1143,7 @@ sp_desktop_widget_namedview_modified (SPObject *obj, guint flags, SPDesktopWidge
     SPNamedView *nv=SP_NAMEDVIEW(obj);
     if (flags & SP_OBJECT_MODIFIED_FLAG) {
         dtw->dt2r = 1.0 / nv->doc_units->unittobase;
-        dtw->ruler_origin = nv->gridorigin;
+        dtw->ruler_origin = NR::Point(0,0); //nv->gridorigin;   Why was the grid origin used here?
 
         sp_ruler_set_metric (GTK_RULER (dtw->vruler), nv->getDefaultMetric());
         sp_ruler_set_metric (GTK_RULER (dtw->hruler), nv->getDefaultMetric());
@@ -1022,16 +1170,11 @@ sp_desktop_widget_adjustment_value_changed (GtkAdjustment *adj, SPDesktopWidget
 }
 
 /* we make the desktop window with focus active, signal is connected in interface.c */
-
-gint
-sp_desktop_widget_set_focus (GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw)
+bool SPDesktopWidget::onFocusInEvent(GdkEventFocus*)
 {
-    inkscape_activate_desktop (dtw->desktop);
-
-    /* give focus to canvas widget */
-    gtk_widget_grab_focus (GTK_WIDGET (dtw->canvas));
-
-    return FALSE;
+    inkscape_activate_desktop (desktop);
+       
+    return false;
 }
 
 static gdouble
@@ -1181,6 +1324,9 @@ sp_desktop_widget_update_zoom (SPDesktopWidget *dtw)
 {
     g_signal_handlers_block_by_func (G_OBJECT (dtw->zoom_status), (gpointer)G_CALLBACK (sp_dtw_zoom_value_changed), dtw);
     gtk_spin_button_set_value (GTK_SPIN_BUTTON (dtw->zoom_status), log(dtw->desktop->current_zoom()) / log(2));
+    gtk_widget_queue_draw(GTK_WIDGET(dtw->zoom_status));
+    if (GTK_WIDGET(dtw->zoom_status)->window)
+        gdk_window_process_updates(GTK_WIDGET(dtw->zoom_status)->window, TRUE);
     g_signal_handlers_unblock_by_func (G_OBJECT (dtw->zoom_status), (gpointer)G_CALLBACK (sp_dtw_zoom_value_changed), dtw);
 }
 
@@ -1190,11 +1336,11 @@ sp_desktop_widget_toggle_rulers (SPDesktopWidget *dtw)
     if (GTK_WIDGET_VISIBLE (dtw->hruler)) {
         gtk_widget_hide_all (dtw->hruler);
         gtk_widget_hide_all (dtw->vruler);
-        prefs_set_int_attribute (dtw->desktop->is_fullscreen ? "fullscreen.rulers" : "window.rulers", "state", 0);
+        prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.rulers" : "window.rulers", "state", 0);
     } else {
         gtk_widget_show_all (dtw->hruler);
         gtk_widget_show_all (dtw->vruler);
-        prefs_set_int_attribute (dtw->desktop->is_fullscreen ? "fullscreen.rulers" : "window.rulers", "state", 1);
+        prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.rulers" : "window.rulers", "state", 1);
     }
 }
 
@@ -1204,11 +1350,11 @@ sp_desktop_widget_toggle_scrollbars (SPDesktopWidget *dtw)
     if (GTK_WIDGET_VISIBLE (dtw->hscrollbar)) {
         gtk_widget_hide_all (dtw->hscrollbar);
         gtk_widget_hide_all (dtw->vscrollbar_box);
-        prefs_set_int_attribute (dtw->desktop->is_fullscreen ? "fullscreen.scrollbars" : "window.scrollbars", "state", 0);
+        prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.scrollbars" : "window.scrollbars", "state", 0);
     } else {
         gtk_widget_show_all (dtw->hscrollbar);
         gtk_widget_show_all (dtw->vscrollbar_box);
-        prefs_set_int_attribute (dtw->desktop->is_fullscreen ? "fullscreen.scrollbars" : "window.scrollbars", "state", 1);
+        prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.scrollbars" : "window.scrollbars", "state", 1);
     }
 }
 
@@ -1252,11 +1398,9 @@ sp_desktop_widget_update_scrollbars (SPDesktopWidget *dtw, double scale)
 
     /* The desktop region we always show unconditionally */
     SPDocument *doc = dtw->desktop->doc();
-    NR::Rect const r = sp_item_bbox_desktop(SP_ITEM(SP_DOCUMENT_ROOT(doc)));
-    NR::Rect darea(NR::Point(MIN(r.min()[NR::X], -sp_document_width(doc)),
-                             MIN(r.min()[NR::Y], -sp_document_height(doc))),
-                   NR::Point(MAX(r.max()[NR::X], 2 * sp_document_width(doc)),
-                             MAX(r.max()[NR::Y], 2 * sp_document_height(doc))));
+    NR::Rect darea(NR::Point(-sp_document_width(doc), -sp_document_height(doc)),
+                   NR::Point(2 * sp_document_width(doc), 2 * sp_document_height(doc)));
+    darea = NR::union_bounds(darea, sp_item_bbox_desktop(SP_ITEM(SP_DOCUMENT_ROOT(doc))));
 
     /* Canvas region we always show unconditionally */
     NR::Rect carea(NR::Point(darea.min()[NR::X] * scale - 64,
@@ -1267,7 +1411,7 @@ sp_desktop_widget_update_scrollbars (SPDesktopWidget *dtw, double scale)
     NR::Rect viewbox = dtw->canvas->getViewbox();
 
     /* Viewbox is always included into scrollable region */
-    carea = NR::Rect::union_bounds(carea, viewbox);
+    carea = NR::union_bounds(carea, viewbox);
 
     set_adjustment(dtw->hadj, carea.min()[NR::X], carea.max()[NR::X],
                    viewbox.dimensions()[NR::X],