Code

remember sticky_zoom toggle button state
[inkscape.git] / src / widgets / desktop-widget.cpp
index 324e5b0087d1401b55198368d89f4efcedf91582..a2f88c16d184ae07597f58a706d2744199e1d980 100644 (file)
 #include <gtkmm/paned.h>
 #include <gtk/gtk.h>
 
-#include "macros.h"
-#include "inkscape-private.h"
-#include "desktop-handles.h"
+#include "box3d-context.h"
+#include "color-profile-fns.h"
+#include "conn-avoid-ref.h"
 #include "desktop-events.h"
-#include "document.h"
+#include "desktop-handles.h"
 #include "desktop-widget.h"
-#include "sp-namedview.h"
-#include "interface.h"
-#include "toolbox.h"
-#include "preferences.h"
-#include "file.h"
 #include "display/canvas-arena.h"
 #include "display/nr-arena.h"
+#include "document.h"
+#include "ege-color-prof-tracker.h"
+#include "ege-select-one-action.h"
 #include <extension/db.h>
+#include "file.h"
 #include "helper/units.h"
+#include "inkscape-private.h"
+#include "interface.h"
+#include "macros.h"
+#include "preferences.h"
+#include "sp-image.h"
+#include "sp-item.h"
+#include "sp-namedview.h"
+#include "toolbox.h"
+#include "ui/dialog/dialog-manager.h"
+#include "ui/dialog/swatches.h"
+#include "ui/icon-names.h"
+#include "ui/widget/dock.h"
+#include "ui/widget/layer-selector.h"
+#include "ui/widget/selected-style.h"
 #include "widgets/button.h"
 #include "widgets/ruler.h"
-#include "widgets/widget-sizes.h"
-#include "widgets/spw-utilities.h"
 #include "widgets/spinbutton-events.h"
-#include "widgets/layer-selector.h"
+#include "widgets/spw-utilities.h"
 #include "widgets/toolbox.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"
-#include "ege-color-prof-tracker.h"
-#include "color-profile-fns.h"
-#include "box3d-context.h"
-#include "sp-image.h"
+#include "widgets/widget-sizes.h"
 
 #if defined (SOLARIS) && (SOLARIS == 8)
 #include "round.h"
@@ -111,6 +112,7 @@ static void sp_dtw_zoom_200 (GtkMenuItem *item, gpointer data);
 static void sp_dtw_zoom_page (GtkMenuItem *item, gpointer data);
 static void sp_dtw_zoom_drawing (GtkMenuItem *item, gpointer data);
 static void sp_dtw_zoom_selection (GtkMenuItem *item, gpointer data);
+static void sp_dtw_sticky_zoom_toggled (GtkMenuItem *item, gpointer data);
 
 SPViewWidgetClass *dtw_parent_class;
 
@@ -313,10 +315,9 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     {
         using Inkscape::UI::Dialogs::SwatchesPanel;
 
-        SwatchesPanel* swatches = new SwatchesPanel("/embedded/swatches");
-        swatches->setOrientation( Gtk::ANCHOR_SOUTH );
-        dtw->panels = GTK_WIDGET(swatches->gobj());
-        gtk_box_pack_end( GTK_BOX( dtw->vbox ), dtw->panels, FALSE, TRUE, 0 );
+        dtw->panels = new SwatchesPanel("/embedded/swatches");
+        dtw->panels->setOrientation( Gtk::ANCHOR_SOUTH );
+        gtk_box_pack_end( GTK_BOX( dtw->vbox ), GTK_WIDGET(dtw->panels->gobj()), FALSE, TRUE, 0 );
     }
 
     hbox = gtk_hbox_new (FALSE, 0);
@@ -374,11 +375,12 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     dtw->sticky_zoom = sp_button_new_from_data ( Inkscape::ICON_SIZE_DECORATION,
                                                  SP_BUTTON_TYPE_TOGGLE,
                                                  NULL,
-                                                 "sticky_zoom",
+                                                 INKSCAPE_ICON_ZOOM_ORIGINAL,
                                                  _("Zoom drawing if window size changes"),
                                                  dtw->tt);
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dtw->sticky_zoom), prefs->getBool("/options/stickyzoom/value"));
     gtk_box_pack_start (GTK_BOX (dtw->vscrollbar_box), dtw->sticky_zoom, FALSE, FALSE, 0);
+    g_signal_connect (G_OBJECT (dtw->sticky_zoom), "toggled", G_CALLBACK (sp_dtw_sticky_zoom_toggled), 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);
@@ -396,7 +398,7 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     dtw->cms_adjust = sp_button_new_from_data( Inkscape::ICON_SIZE_DECORATION,
                                                SP_BUTTON_TYPE_TOGGLE,
                                                NULL,
-                                               "color_management",
+                                               INKSCAPE_ICON_COLOR_MANAGEMENT,
                                                tip,
                                                dtw->tt );
 #if ENABLE_LCMS
@@ -499,10 +501,10 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     eventbox = gtk_event_box_new ();
     gtk_container_add (GTK_CONTAINER (eventbox), dtw->coord_status);
     gtk_tooltips_set_tip (dtw->tt, eventbox, _("Cursor coordinates"), NULL);
-    GtkWidget *label_x = gtk_label_new("X:");
+    GtkWidget *label_x = gtk_label_new(_("X:"));
     gtk_misc_set_alignment (GTK_MISC(label_x), 0.0, 0.5);
     gtk_table_attach(GTK_TABLE(dtw->coord_status),  label_x, 1,2, 0,1, GTK_FILL, GTK_FILL, 0, 0);
-    GtkWidget *label_y = gtk_label_new("Y:");
+    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(NULL);
@@ -513,7 +515,7 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     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);
+    gtk_table_attach(GTK_TABLE(dtw->coord_status),  gtk_label_new(_("Z:")), 3,4, 0,2, GTK_FILL, GTK_FILL, 0, 0);
     gtk_table_attach(GTK_TABLE(dtw->coord_status),  dtw->zoom_status, 4,5, 0,2, GTK_FILL, GTK_FILL, 0, 0);
     sp_set_font_size_smaller (dtw->coord_status);
     gtk_box_pack_end (GTK_BOX (statusbar_tail), eventbox, FALSE, FALSE, 1);
@@ -656,16 +658,14 @@ sp_desktop_widget_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
         }
 
         if (SP_BUTTON_IS_DOWN(dtw->sticky_zoom)) {
-            /* Calculate zoom per pixel */
-            double const zpsp = zoom / hypot (area.dimensions()[Geom::X], area.dimensions()[Geom::Y]);
             /* Find new visible area */
             Geom::Rect newarea = dtw->desktop->get_display_area();
             /* Calculate adjusted zoom */
-            zoom = zpsp * hypot(newarea.dimensions()[Geom::X], newarea.dimensions()[Geom::Y]);
-            dtw->desktop->zoom_absolute(newarea.midpoint()[Geom::X], newarea.midpoint()[Geom::Y], zoom);
-        } else {
-            dtw->desktop->zoom_absolute(area.midpoint()[Geom::X], area.midpoint()[Geom::Y], zoom);
+            double oldshortside = MIN(   area.width(),    area.height());
+            double newshortside = MIN(newarea.width(), newarea.height());
+            zoom *= newshortside / oldshortside;
         }
+        dtw->desktop->zoom_absolute(area.midpoint()[Geom::X], area.midpoint()[Geom::Y], zoom);
 
     } else {
         if (GTK_WIDGET_CLASS (dtw_parent_class)->size_allocate) {
@@ -858,6 +858,7 @@ SPDesktopWidget::shutdown()
                 Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
 
                 sp_document_ref(doc);
+                sp_namedview_document_from_window(desktop);
                 if (sp_file_save_document(*window, doc)) {
                     sp_document_unref(doc);
                 } else { // save dialog cancelled or save failed
@@ -1243,9 +1244,9 @@ sp_desktop_widget_layout (SPDesktopWidget *dtw)
     }
 
     if (!prefs->getBool(pref_root + "panels/state", true)) {
-        gtk_widget_hide_all( dtw->panels );
+        gtk_widget_hide_all( GTK_WIDGET(dtw->panels->gobj()) );
     } else {
-        gtk_widget_show_all( dtw->panels );
+        gtk_widget_show_all( GTK_WIDGET(dtw->panels->gobj()) );
     }
 
     if (!prefs->getBool(pref_root + "scrollbars/state", true)) {
@@ -1361,6 +1362,8 @@ sp_desktop_widget_new (SPNamedView *namedview)
     sp_commands_toolbox_set_desktop (dtw->commands_toolbox, dtw->desktop);
     sp_snap_toolbox_set_desktop (dtw->snap_toolbox, dtw->desktop);
 
+    dtw->panels->setDesktop( dtw->desktop );
+
     return SP_VIEW_WIDGET (dtw);
 }
 
@@ -1614,6 +1617,13 @@ sp_dtw_zoom_selection (GtkMenuItem */*item*/, gpointer data)
     static_cast<SPDesktop*>(data)->zoom_selection();
 }
 
+static void
+sp_dtw_sticky_zoom_toggled (GtkMenuItem *, gpointer data)
+{
+    SPDesktopWidget *dtw = SP_DESKTOP_WIDGET(data);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    prefs->setBool("/options/stickyzoom/value", SP_BUTTON_IS_DOWN(dtw->sticky_zoom));
+}
 
 
 void