From 5efe91c3c922431d177a0d52fac2ff8071f83192 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 10 Jan 2010 03:22:05 -0800 Subject: [PATCH] Completed base code to flip toolbox orientation. Basic integration of task switching control. --- src/ui/uxmanager.cpp | 62 +++++++++++++++++++++++++-- src/ui/uxmanager.h | 16 ++++++- src/widgets/desktop-widget.cpp | 8 +++- src/widgets/toolbox.cpp | 77 ++++++++++++++++++++++++++++++---- 4 files changed, 150 insertions(+), 13 deletions(-) diff --git a/src/ui/uxmanager.cpp b/src/ui/uxmanager.cpp index d152e473e..48ff9dca0 100644 --- a/src/ui/uxmanager.cpp +++ b/src/ui/uxmanager.cpp @@ -13,9 +13,21 @@ # include "config.h" #endif +#include + #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 desktops; +static vector dtws; +static map > 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::iterator it = dtws.begin(); it != dtws.end(); ++it) { + if ((*it)->desktop == dt) { + vector& boxes = trackedBoxes[dt]; + for (vector::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 const & toolboxes, SPDesktop *desktop ) +void UXManager::addTrack( SPDesktopWidget* dtw ) { - for (std::vector::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::iterator iter = std::find(dtws.begin(), dtws.end(), dtw); + if (iter != dtws.end()) { + dtws.erase(iter); + } +} + +void UXManager::connectToDesktop( vector const & toolboxes, SPDesktop *desktop ) +{ +//static map > trackedBoxes; + + for (vector::const_iterator it = toolboxes.begin(); it != toolboxes.end(); ++it ) { + GtkWidget* toolbox = *it; + ToolboxFactory::setToolboxDesktop( toolbox, desktop ); + + vector& 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); } } diff --git a/src/ui/uxmanager.h b/src/ui/uxmanager.h index c8b077a57..862c675d0 100644 --- a/src/ui/uxmanager.h +++ b/src/ui/uxmanager.h @@ -11,11 +11,20 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include -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 const & toolboxes, SPDesktop *desktop ); + void setTask(SPDesktop* dt, gint val); + private: UXManager(); }; diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index f7e7f911d..f70ade5a3 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -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) diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index a09e04132..5eb19bbd6 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -98,10 +98,12 @@ #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 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) " " " " " " + " " + " " " " ""; -- 2.30.2