Code

Completed base code to flip toolbox orientation.
authorJon A. Cruz <jon@joncruz.org>
Sun, 10 Jan 2010 11:22:05 +0000 (03:22 -0800)
committerJon A. Cruz <jon@joncruz.org>
Sun, 10 Jan 2010 11:22:05 +0000 (03:22 -0800)
Basic integration of task switching control.

src/ui/uxmanager.cpp
src/ui/uxmanager.h
src/widgets/desktop-widget.cpp
src/widgets/toolbox.cpp

index d152e473e4aba910ef8084f01f37f639a92a8064..48ff9dca0237c9b3d7740749d6fa4981baeb4265 100644 (file)
 # include "config.h"
 #endif
 
+#include <algorithm>
+
 #include "uxmanager.h"
 #include "util/ege-tags.h"
 #include "widgets/toolbox.h"
+#include "widgets/desktop-widget.h"
+
+using std::map;
+using std::vector;
+
+static vector<SPDesktop*> desktops;
+static vector<SPDesktopWidget*> dtws;
+static map<SPDesktop*, vector<GtkWidget*> > trackedBoxes;
+
+
 
 namespace Inkscape {
 namespace UI {
@@ -44,11 +56,55 @@ 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);
+                }
+            }
+            break;
+        }
+    }
+}
+
 
-void UXManager::connectToDesktop( std::vector<GtkWidget *> const & toolboxes, SPDesktop *desktop )
+void UXManager::addTrack( SPDesktopWidget* dtw )
 {
-    for (std::vector<GtkWidget*>::const_iterator it = toolboxes.begin(); it != toolboxes.end(); ++it ) {
-        ToolboxFactory::setToolboxDesktop( *it, desktop );
+    if (std::find(dtws.begin(), dtws.end(), dtw) == dtws.end()) {
+        dtws.push_back(dtw);
+    }
+}
+
+void UXManager::delTrack( SPDesktopWidget* dtw )
+{
+    vector<SPDesktopWidget*>::iterator iter = std::find(dtws.begin(), dtws.end(), dtw);
+    if (iter != dtws.end()) {
+        dtws.erase(iter);
+    }
+}
+
+void UXManager::connectToDesktop( vector<GtkWidget *> const & toolboxes, SPDesktop *desktop )
+{
+//static map<SPDesktop*, vector<GtkWidget*> > trackedBoxes;
+
+    for (vector<GtkWidget*>::const_iterator it = toolboxes.begin(); it != toolboxes.end(); ++it ) {
+        GtkWidget* toolbox = *it;
+        ToolboxFactory::setToolboxDesktop( toolbox, desktop );
+
+        vector<GtkWidget*>& tracked = trackedBoxes[desktop];
+        if (find(tracked.begin(), tracked.end(), toolbox) == tracked.end()) {
+            tracked.push_back(toolbox);
+        }
+    }
+
+    if (std::find(desktops.begin(), desktops.end(), desktop) == desktops.end()) {
+        desktops.push_back(desktop);
     }
 }
 
index c8b077a577af05a9a9bfce5f8aeb4733dc75f27e..862c675d02499792f3b72e7530ecccec975ea17b 100644 (file)
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
+#include <glib.h>
 #include <vector>
 
-typedef struct _GtkWidget GtkWidget;
+extern "C"
+{
+    typedef struct _GObject GObject;
+    typedef struct _GtkWidget GtkWidget;
+}
+
 class SPDesktop;
 
+struct SPDesktopWidget;
+
+
 namespace Inkscape {
 namespace UI {
 
@@ -25,8 +34,13 @@ public:
     static UXManager* getInstance();
     virtual ~UXManager();
 
+    void addTrack( SPDesktopWidget* dtw );
+    void delTrack( SPDesktopWidget* dtw );
+
     void connectToDesktop( std::vector<GtkWidget *> const & toolboxes, SPDesktop *desktop );
 
+    void setTask(SPDesktop* dt, gint val);
+
 private:
     UXManager();
 };
index f7e7f911d5aa2c4f8dba90d1bacfb1dfa329141b..f70ade5a3cae4fa816737b30ad3cdc8e523ae2a5 100644 (file)
@@ -571,6 +571,8 @@ sp_desktop_widget_destroy (GtkObject *object)
 {
     SPDesktopWidget *dtw = SP_DESKTOP_WIDGET (object);
 
+    UXManager::getInstance()->delTrack(dtw);
+
     if (dtw->desktop) {
         if ( watcher ) {
             watcher->remove(dtw);
@@ -1341,7 +1343,11 @@ SPDesktopWidget::isToolboxButtonActive (const gchar* id)
 
 SPViewWidget *sp_desktop_widget_new( SPNamedView *namedview )
 {
-    return SP_VIEW_WIDGET(SPDesktopWidget::createInstance(namedview));
+    SPDesktopWidget* dtw = SPDesktopWidget::createInstance(namedview);
+
+    UXManager::getInstance()->addTrack(dtw);
+
+    return SP_VIEW_WIDGET(dtw);
 }
 
 SPDesktopWidget* SPDesktopWidget::createInstance(SPNamedView *namedview)
index a09e04132650cdeeceb9f0f26a19ec4e09c3fc68..5eb19bbd68ceef40d24614cf582f428a3b51524b 100644 (file)
 #include "../xml/attribute-record.h"
 #include "../xml/node-event-vector.h"
 #include "../xml/repr.h"
+#include "ui/uxmanager.h"
 
 #include "toolbox.h"
 
 using Inkscape::UnitTracker;
+using Inkscape::UI::UXManager;
 
 typedef void (*SetupFunction)(GtkWidget *toolbox, SPDesktop *desktop);
 typedef void (*UpdateFunction)(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox);
@@ -137,6 +139,13 @@ static void       sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* ma
 
 namespace { GtkWidget *sp_text_toolbox_new (SPDesktop *desktop); }
 
+
+static void fireTaskChange( EgeSelectOneAction *act, SPDesktop *dt )
+{
+    gint selected = ege_select_one_action_get_active( act );
+    UXManager::getInstance()->setTask(dt, selected);
+}
+
 using Inkscape::UI::ToolboxFactory;
 
 
@@ -828,6 +837,39 @@ Glib::RefPtr<Gtk::ActionGroup> create_or_fetch_actions( SPDesktop* desktop )
         }
     }
 
+    if ( !mainActions->get_action("TaskSetAction") ) {
+        GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
+
+        GtkTreeIter iter;
+        gtk_list_store_append( model, &iter );
+        gtk_list_store_set( model, &iter,
+                            0, _("Default"),
+                            1, _("Default interface setup"),
+                            2, 0,
+                            -1 );
+
+        gtk_list_store_append( model, &iter );
+        gtk_list_store_set( model, &iter,
+                            0, _("Custom"),
+                            1, _("Set the custom task"),
+                            2, 0,
+                            -1 );
+
+        EgeSelectOneAction* act = ege_select_one_action_new( "TaskSetAction", _("Task"), (""), NULL, GTK_TREE_MODEL(model) );
+        g_object_set( act, "short_label", _("Task:"), NULL );
+        mainActions->add(Glib::wrap(GTK_ACTION(act)));
+        //g_object_set_data( holder, "mode_action", act );
+
+        ege_select_one_action_set_appearance( act, "minimal" );
+        ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
+        g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
+        ege_select_one_action_set_icon_column( act, 2 );
+        //ege_select_one_action_set_icon_size( act, secondarySize );
+        ege_select_one_action_set_tooltip_column( act, 1  );
+
+        //ege_select_one_action_set_active( act, mode );
+        g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(fireTaskChange), desktop );
+    }
 
     return mainActions;
 }
@@ -1630,6 +1672,9 @@ void ToolboxFactory::setOrientation(GtkWidget* toolbox, GtkOrientation orientati
     //g_message("        [%s]", g_type_name(type));
     //g_message("             %p", g_object_get_data(G_OBJECT(toolbox), BAR_ID_KEY));
 
+    GtkPositionType pos = (orientation == GTK_ORIENTATION_HORIZONTAL) ? GTK_POS_LEFT : GTK_POS_TOP;
+    GtkHandleBox* handleBox = 0;
+
     if (GTK_IS_BIN(toolbox)) {
         //g_message("            is a BIN");
         GtkWidget* child = gtk_bin_get_child(GTK_BIN(toolbox));
@@ -1646,23 +1691,37 @@ void ToolboxFactory::setOrientation(GtkWidget* toolbox, GtkOrientation orientati
                     //GType type3 = GTK_WIDGET_TYPE(child2);
                     //g_message("                child    [%s]", g_type_name(type3));
                     g_message("need to add dynamic switch");
-
+                    for (GList* curr = children; curr; curr = g_list_next(curr)) {
+                        GtkWidget* child2 = GTK_WIDGET(curr->data);
+
+                        if (GTK_IS_TOOLBAR(child2)) {
+                            GtkToolbar* childBar = GTK_TOOLBAR(child2);
+                            gtk_toolbar_set_orientation(childBar, orientation);
+                            if (GTK_IS_HANDLE_BOX(toolbox)) {
+                                handleBox = GTK_HANDLE_BOX(toolbox);
+                            }
+                        }
+                    }
                     g_list_free(children);
                 } else {
-                    //g_message("                    has no children %p", children);
-                    // The call is being made before the toolbox proper has been setup.
                     if (GTK_IS_HANDLE_BOX(toolbox)) {
-                        GtkPositionType pos = (orientation == GTK_ORIENTATION_HORIZONTAL) ? GTK_POS_LEFT : GTK_POS_TOP;
-                        gtk_handle_box_set_handle_position(GTK_HANDLE_BOX(toolbox), pos);
-                        //g_message("Setting position");
+                        handleBox = GTK_HANDLE_BOX(toolbox);
                     }
+                    // The call is being made before the toolbox proper has been setup.
+                }
+            } else if (GTK_IS_TOOLBAR(child)) {
+                GtkToolbar* toolbar = GTK_TOOLBAR(child);
+                gtk_toolbar_set_orientation( toolbar, orientation );
+                if (GTK_IS_HANDLE_BOX(toolbox)) {
+                    handleBox = GTK_HANDLE_BOX(toolbox);
                 }
             }
         }
     }
 
-
-
+    if (handleBox) {
+        gtk_handle_box_set_handle_position(handleBox, pos);
+    }
 }
 
 static void
@@ -1861,6 +1920,8 @@ setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop)
         "    <separator />"
         "    <toolitem action='DialogPreferences' />"
         "    <toolitem action='DialogDocumentProperties' />"
+        "    <separator />"
+        "    <toolitem action='TaskSetAction' />"
         "  </toolbar>"
         "</ui>";