From aa740fe757525511d9d624fe79c9a31175de8ed7 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Tue, 23 Oct 2007 14:54:09 +0000 Subject: [PATCH] some more refactoring --- .../products/gLiveSupport/src/DndMethods.cxx | 16 ++-- .../products/gLiveSupport/src/DndMethods.h | 15 +++- .../gLiveSupport/src/SearchWindow.cxx | 42 ++------- .../products/gLiveSupport/src/SearchWindow.h | 86 ++++++++++--------- 4 files changed, 74 insertions(+), 85 deletions(-) diff --git a/campcaster/src/products/gLiveSupport/src/DndMethods.cxx b/campcaster/src/products/gLiveSupport/src/DndMethods.cxx index 1ee163588..6de87e9aa 100644 --- a/campcaster/src/products/gLiveSupport/src/DndMethods.cxx +++ b/campcaster/src/products/gLiveSupport/src/DndMethods.cxx @@ -54,7 +54,7 @@ using namespace LiveSupport::GLiveSupport; * Set up the D'n'D callbacks. *----------------------------------------------------------------------------*/ void -DndMethods :: setupDndCallbacks (void) throw () +DndMethods :: setupDndCallbacks (DndType type) throw () { Gtk::TreeView * treeView = getTreeViewForDnd(); @@ -62,15 +62,17 @@ DndMethods :: setupDndCallbacks (void) throw () targets.push_back(Gtk::TargetEntry("STRING", Gtk::TARGET_SAME_APP)); - // set up the tree view as a d'n'd source - treeView->enable_model_drag_source(targets); - treeView->signal_drag_data_get().connect(sigc::mem_fun(*this, + if (type | DND_SOURCE) { + treeView->enable_model_drag_source(targets); + treeView->signal_drag_data_get().connect(sigc::mem_fun(*this, &DndMethods::onTreeViewDragDataGet)); + } - // set up the tree view as a d'n'd target - treeView->enable_model_drag_dest(targets); - treeView->signal_drag_data_received().connect(sigc::mem_fun(*this, + if (type | DND_DEST) { + treeView->enable_model_drag_dest(targets); + treeView->signal_drag_data_received().connect(sigc::mem_fun(*this, &DndMethods::onTreeViewDragDataReceived)); + } } diff --git a/campcaster/src/products/gLiveSupport/src/DndMethods.h b/campcaster/src/products/gLiveSupport/src/DndMethods.h index da3dfb109..998bcad13 100644 --- a/campcaster/src/products/gLiveSupport/src/DndMethods.h +++ b/campcaster/src/products/gLiveSupport/src/DndMethods.h @@ -124,10 +124,21 @@ class DndMethods int y) throw (); /** - * Set up the D'n'D callbacks. + * Types of d'n'd. + */ + typedef enum { DND_SOURCE = 1, + DND_DEST = 2 + } DndType; + + /** + * Set up the d'n'd callbacks. + * + * @param type set up callbacks for d'n'd source or destination + * (default: both). */ void - setupDndCallbacks (void) throw (); + setupDndCallbacks (DndType type = DndType(DND_SOURCE | DND_DEST)) + throw (); /** * The callback for supplying the data for the drag and drop. diff --git a/campcaster/src/products/gLiveSupport/src/SearchWindow.cxx b/campcaster/src/products/gLiveSupport/src/SearchWindow.cxx index 5559d0d29..456c53f66 100644 --- a/campcaster/src/products/gLiveSupport/src/SearchWindow.cxx +++ b/campcaster/src/products/gLiveSupport/src/SearchWindow.cxx @@ -237,7 +237,7 @@ SearchWindow :: constructSearchResultsView(void) throw () false /* call this first */); searchResultsTreeView->signal_row_activated().connect(sigc::mem_fun(*this, &SearchWindow::onDoubleClick)); - setupDndCallbacks(); + setupDndCallbacks(DND_SOURCE); audioClipContextMenu = constructAudioClipContextMenu(); playlistContextMenu = constructPlaylistContextMenu(); @@ -1123,44 +1123,12 @@ SearchWindow :: updatePagingToolbar(void) throw () /*------------------------------------------------------------------------------ - * Set up the D'n'D callbacks. + * The name of the window for the d'n'd methods. *----------------------------------------------------------------------------*/ -void -SearchWindow :: setupDndCallbacks (void) throw () +Glib::ustring +SearchWindow :: getWindowNameForDnd (void) throw () { - std::list targets; - targets.push_back(Gtk::TargetEntry("STRING", - Gtk::TARGET_SAME_APP)); - - // set up the tree view as a d'n'd source - searchResultsTreeView->enable_model_drag_source(targets); - searchResultsTreeView->signal_drag_data_get().connect(sigc::mem_fun(*this, - &SearchWindow::onTreeViewDragDataGet)); + return bundleName; } -/*------------------------------------------------------------------------------ - * The callback for supplying the data for the drag and drop. - *----------------------------------------------------------------------------*/ -void -SearchWindow :: onTreeViewDragDataGet( - const Glib::RefPtr & context, - Gtk::SelectionData & selectionData, - guint info, - guint time) - throw () -{ - Glib::ustring dropString = bundleName; - Ptr::Ref playable = getFirstSelectedPlayable(); - - while ((playable = getNextSelectedPlayable())) { - dropString += " "; - dropString += std::string(*playable->getId()); - } - - selectionData.set(selectionData.get_target(), - 8 /* 8 bits format*/, - (const guchar *) dropString.c_str(), - dropString.bytes()); -} - diff --git a/campcaster/src/products/gLiveSupport/src/SearchWindow.h b/campcaster/src/products/gLiveSupport/src/SearchWindow.h index cffb91348..8dc63c58d 100644 --- a/campcaster/src/products/gLiveSupport/src/SearchWindow.h +++ b/campcaster/src/products/gLiveSupport/src/SearchWindow.h @@ -41,6 +41,7 @@ #endif #include "GuiWindow.h" +#include "DndMethods.h" #include "LiveSupport/Core/NumericTools.h" #include "LiveSupport/Core/Ptr.h" @@ -75,6 +76,7 @@ using namespace LiveSupport::Widgets; * @version $Revision$ */ class SearchWindow : public GuiWindow, + public DndMethods, private NumericTools { private: @@ -399,32 +401,6 @@ class SearchWindow : public GuiWindow, void displayRemoteSearchError(const XmlRpcException & error) throw (); - - /** - * Return the topmost selected row. - * Sets selectedPaths and selectedIter; does not increment it. - * - * @return the first selected playable item. - */ - Ptr::Ref - getFirstSelectedPlayable(void) throw (); - - /** - * Used to iterate over the selected rows. - * Reset to the first row by onEntryClicked(). - * Returns a 0 pointer if nothing is selected or we have reached - * the end of the list of selected rows. - * - * @return the next selected playable item. - */ - Ptr::Ref - getNextSelectedPlayable(void) throw (); - - /** - * Set up the D'n'D callbacks. - */ - void - setupDndCallbacks (void) throw (); protected: @@ -625,20 +601,52 @@ class SearchWindow : public GuiWindow, onForwardButtonClicked(void) throw (); /** - * The callback for supplying the data for the drag and drop. - * - * @param context the drag context. - * @param selectionData the data (filled in by this function). - * @param info not used. - * @param time timestamp for the d'n'd operation. + * The tree view we want to implement d'n'd on. */ - void - onTreeViewDragDataGet( - const Glib::RefPtr & context, - Gtk::SelectionData & selectionData, - guint info, - guint time) - throw (); + virtual Gtk::TreeView * + getTreeViewForDnd (void) throw () + { + return searchResultsTreeView; + } + + /** + * The name of the window for the d'n'd methods. + */ + virtual Glib::ustring + getWindowNameForDnd (void) throw (); + + /** + * Return the topmost selected row. + * Sets selectedPaths and selectedIter; does not increment it. + * + * @return the first selected playable item. + */ + virtual Ptr::Ref + getFirstSelectedPlayable(void) throw (); + + /** + * Used to iterate over the selected rows. + * Reset to the first row by onEntryClicked(). + * Returns a 0 pointer if nothing is selected or we have reached + * the end of the list of selected rows. + * + * @return the next selected playable item. + */ + virtual Ptr::Ref + getNextSelectedPlayable(void) throw (); + + /** + * Add an item to the tree view at the given position. + * Required to implement by DndMethods, does not do anything here. + * + * @param iter the iterator pointing to the row to be filled in. + * @param id the ID of the item to add. + */ + virtual void + addItem(Gtk::TreeIter iter, + Ptr::Ref id) throw () + { + } public: