Code

Implemented dynamic repositioning of toolboxes.
authorJon A. Cruz <jon@joncruz.org>
Mon, 11 Jan 2010 09:09:52 +0000 (01:09 -0800)
committerJon A. Cruz <jon@joncruz.org>
Mon, 11 Jan 2010 09:09:52 +0000 (01:09 -0800)
src/ui/uxmanager.cpp
src/widgets/desktop-widget.cpp
src/widgets/desktop-widget.h
src/widgets/toolbox.cpp

index 48ff9dca0237c9b3d7740749d6fa4981baeb4265..2153606c1e303efa1e9a182eafb43ba4ff4cf36a 100644 (file)
@@ -58,15 +58,19 @@ UXManager::~UXManager()
 
 void UXManager::setTask(SPDesktop* dt, gint val)
 {
-    GtkOrientation orientation = (val == 0)? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
     for (vector<SPDesktopWidget*>::iterator it = dtws.begin(); it != dtws.end(); ++it) {
-        if ((*it)->desktop == dt) {
-            vector<GtkWidget*>& boxes = trackedBoxes[dt];
-            for (vector<GtkWidget*>::iterator it2 = boxes.begin(); it2 != boxes.end(); ++it2) {
-                gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(*it2), "BarIdValue"));
-                if (id != 1) {
-                    //ToolboxFactory::setOrientation(*it2, orientation);
-                }
+        SPDesktopWidget* dtw = *it;
+        if (dtw->desktop == dt) {
+            if (val == 0) {
+                dtw->setToolboxPosition("ToolToolbar", GTK_POS_LEFT);
+                dtw->setToolboxPosition("CommandsToolbar", GTK_POS_TOP);
+                dtw->setToolboxPosition("SnapToolbar", GTK_POS_TOP);
+                // for now skip "AuxToolbar";
+            } else {
+                dtw->setToolboxPosition("ToolToolbar", GTK_POS_TOP);
+                dtw->setToolboxPosition("CommandsToolbar", GTK_POS_LEFT);
+                dtw->setToolboxPosition("SnapToolbar", GTK_POS_RIGHT);
+                // for now skip "AuxToolbar";
             }
             break;
         }
@@ -95,8 +99,8 @@ void UXManager::connectToDesktop( vector<GtkWidget *> const & toolboxes, SPDeskt
 
     for (vector<GtkWidget*>::const_iterator it = toolboxes.begin(); it != toolboxes.end(); ++it ) {
         GtkWidget* toolbox = *it;
-        ToolboxFactory::setToolboxDesktop( toolbox, desktop );
 
+        ToolboxFactory::setToolboxDesktop( toolbox, desktop );
         vector<GtkWidget*>& tracked = trackedBoxes[desktop];
         if (find(tracked.begin(), tracked.end(), toolbox) == tracked.end()) {
             tracked.push_back(toolbox);
index f70ade5a3cae4fa816737b30ad3cdc8e523ae2a5..6655df3ebfe7fd57cdc4d7bdd5cfdc738749b5a0 100644 (file)
@@ -292,7 +292,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
     GtkWidget *tbl;
     GtkWidget *canvas_tbl;
 
-    GtkWidget *hbox;
     GtkWidget *eventbox;
     GtkStyle *style;
 
@@ -323,25 +322,25 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
         gtk_box_pack_end( GTK_BOX( dtw->vbox ), GTK_WIDGET(dtw->panels->gobj()), FALSE, TRUE, 0 );
     }
 
-    hbox = gtk_hbox_new (FALSE, 0);
-    gtk_box_pack_end (GTK_BOX (dtw->vbox), hbox, TRUE, TRUE, 0);
-    gtk_widget_show (hbox);
+    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);
 
     dtw->snap_toolbox = ToolboxFactory::createSnapToolbox();
     ToolboxFactory::setOrientation( dtw->snap_toolbox, GTK_ORIENTATION_VERTICAL );
-    gtk_box_pack_end (GTK_BOX (hbox), dtw->snap_toolbox, FALSE, TRUE, 0);
+    gtk_box_pack_end( GTK_BOX(dtw->hbox), dtw->snap_toolbox, FALSE, TRUE, 0 );
 
     dtw->commands_toolbox = ToolboxFactory::createCommandsToolbox();
     gtk_box_pack_end (GTK_BOX (dtw->vbox), dtw->commands_toolbox, FALSE, TRUE, 0);
 
     dtw->tool_toolbox = ToolboxFactory::createToolToolbox();
-    gtk_box_pack_start (GTK_BOX (hbox), dtw->tool_toolbox, FALSE, TRUE, 0);
+    gtk_box_pack_start( GTK_BOX(dtw->hbox), dtw->tool_toolbox, FALSE, TRUE, 0 );
 
     tbl = gtk_table_new (2, 3, FALSE);
-    gtk_box_pack_start (GTK_BOX (hbox), tbl, TRUE, TRUE, 1);
+    gtk_box_pack_start( GTK_BOX(dtw->hbox), tbl, TRUE, TRUE, 1 );
 
     canvas_tbl = gtk_table_new (3, 3, FALSE);
 
@@ -1341,6 +1340,47 @@ SPDesktopWidget::isToolboxButtonActive (const gchar* id)
     return isActive;
 }
 
+void SPDesktopWidget::setToolboxPosition(Glib::ustring const& id, GtkPositionType pos)
+{
+    // Note - later on these won't be individual member variables.
+    GtkWidget* toolbox = 0;
+    if (id == "ToolToolbar") {
+        toolbox = tool_toolbox;
+    } else if (id == "AuxToolbar") {
+        toolbox = aux_toolbox;
+    } else if (id == "CommandsToolbar") {
+        toolbox = commands_toolbox;
+    } else if (id == "SnapToolbar") {
+        toolbox = snap_toolbox;
+    }
+
+
+    if (toolbox) {
+        switch(pos) {
+            case GTK_POS_TOP:
+            case GTK_POS_BOTTOM:
+                if ( gtk_widget_is_ancestor(toolbox, hbox) ) {
+                    gtk_widget_reparent( toolbox, vbox );
+                    gtk_box_set_child_packing(GTK_BOX(vbox), toolbox, FALSE, TRUE, 0, GTK_PACK_START);
+                }
+                ToolboxFactory::setOrientation(toolbox, GTK_ORIENTATION_HORIZONTAL);
+                break;
+            case GTK_POS_LEFT:
+            case GTK_POS_RIGHT:
+                if ( !gtk_widget_is_ancestor(toolbox, hbox) ) {
+                    gtk_widget_reparent( toolbox, hbox );
+                    gtk_box_set_child_packing(GTK_BOX(hbox), toolbox, FALSE, TRUE, 0, GTK_PACK_START);
+                    if (pos == GTK_POS_LEFT) {
+                        gtk_box_reorder_child( GTK_BOX(hbox), toolbox, 0 );
+                    }
+                }
+                ToolboxFactory::setOrientation(toolbox, GTK_ORIENTATION_VERTICAL);
+                break;
+        }
+    }
+}
+
+
 SPViewWidget *sp_desktop_widget_new( SPNamedView *namedview )
 {
     SPDesktopWidget* dtw = SPDesktopWidget::createInstance(namedview);
index c9bedb1ab42f7b1658a6f23b27b3a9d4a0f46434..33f2a6ae717586c686b1f95efb8cb689ef365ed2 100644 (file)
@@ -76,6 +76,8 @@ struct SPDesktopWidget {
     // The root vbox of the window layout.
     GtkWidget *vbox;
 
+    GtkWidget *hbox;
+
     GtkWidget *menubar, *statusbar;
 
     Inkscape::UI::Dialogs::SwatchesPanel *panels;
@@ -218,6 +220,7 @@ struct SPDesktopWidget {
     void setToolboxAdjustmentValue (gchar const * id, double value);
     void setToolboxSelectOneValue (gchar const * id, gint value);
     bool isToolboxButtonActive (gchar const *id);
+    void setToolboxPosition(Glib::ustring const& id, GtkPositionType pos);
     void setCoordinateStatus(Geom::Point p);
     void requestCanvasUpdate();
     void requestCanvasUpdateAndWait();
index 25014160db2ebfe06fed9bfc0dc6ece48989c00b..c12896d70913090c8cc7de9942d9c769652b49e3 100644 (file)
 
 #include "toolbox.h"
 
+//#define ENABLE_TASK_SUPPORT 1
+
 using Inkscape::UnitTracker;
 using Inkscape::UI::UXManager;