almost works now; just need to fix the drag icons

This commit is contained in:
fgerlits 2007-08-31 15:22:53 +00:00
parent f6f09abee0
commit d5e1a62090
2 changed files with 64 additions and 102 deletions

View file

@ -222,33 +222,30 @@ TestWindow :: setupDndCallbacks (void) throw ()
Gtk::TARGET_SAME_APP)); Gtk::TARGET_SAME_APP));
// set up the left tree view // set up the left tree view
treeView[0]->drag_source_set(targets, treeView[0]->enable_model_drag_source(targets,
Gdk::MODIFIER_MASK, Gdk::MODIFIER_MASK,
Gdk::ACTION_COPY | Gdk::ACTION_MOVE); Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
treeView[0]->signal_drag_data_get().connect(sigc::bind<int>( treeView[0]->signal_drag_data_get().connect(sigc::bind<int>(
sigc::mem_fun(*this, sigc::mem_fun(*this,
&TestWindow::onTreeViewDragDataGet), &TestWindow::onTreeViewDragDataGet),
0)); 0));
treeView[0]->drag_dest_set(targets, treeView[0]->enable_model_drag_dest(targets,
Gtk::DEST_DEFAULT_ALL, Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
treeView[0]->signal_drag_data_received().connect(sigc::bind<int>( treeView[0]->signal_drag_data_received().connect(sigc::bind<int>(
sigc::mem_fun(*this, sigc::mem_fun(*this,
&TestWindow::onTreeViewDragDataReceived), &TestWindow::onTreeViewDragDataReceived),
0)); 0));
// set up the right tree view // set up the right tree view
treeView[1]->drag_source_set(targets, treeView[1]->enable_model_drag_source(targets,
Gdk::MODIFIER_MASK, Gdk::MODIFIER_MASK,
Gdk::ACTION_COPY | Gdk::ACTION_MOVE); Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
treeView[1]->signal_drag_data_get().connect(sigc::bind<int>( treeView[1]->signal_drag_data_get().connect(sigc::bind<int>(
sigc::mem_fun(*this, sigc::mem_fun(*this,
&TestWindow::onTreeViewDragDataGet), &TestWindow::onTreeViewDragDataGet),
1)); 1));
treeView[1]->drag_dest_set(targets, treeView[1]->enable_model_drag_dest(targets,
Gtk::DEST_DEFAULT_ALL, Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
treeView[1]->signal_drag_data_received().connect(sigc::bind<int>( treeView[1]->signal_drag_data_received().connect(sigc::bind<int>(
sigc::mem_fun(*this, sigc::mem_fun(*this,
&TestWindow::onTreeViewDragDataReceived), &TestWindow::onTreeViewDragDataReceived),
@ -395,96 +392,51 @@ TestWindow :: onTreeViewDragDataReceived(
} }
if (source == destination) { if (source == destination) {
moveRow(destination, x, y, stripped); insertRow(destination, x, y, stripped, ROW_MOVE);
context->drag_finish(true, true, time); context->drag_finish(true, true, time);
} else { } else {
insertRow(destination, x, y, stripped); insertRow(destination, x, y, stripped, ROW_COPY);
context->drag_finish(true, false, time); context->drag_finish(true, false, time);
} }
} }
/*------------------------------------------------------------------------------
* Move the selected row to the given position.
*----------------------------------------------------------------------------*/
void
TestWindow :: moveRow (int index,
int x,
int y,
Glib::ustring value) throw ()
{
Glib::RefPtr<Gtk::TreeView::Selection> selection
= treeView[index]->get_selection();
std::list<Gtk::TreePath> rows = selection->get_selected_rows();
assert (rows.size() == 1);
Gtk::TreeIter source = treeModel[index]->get_iter(rows.front());
Gtk::TreePath destPath;
Gtk::TreeViewDropPosition destPos;
treeView[index]->get_dest_row_at_pos(x, y, destPath, destPos);
std::cerr << "path: " << destPath.to_string()
<< ", pos: " << int(destPos)
<< std::endl;
Gtk::TreeIter destination = treeModel[index]->get_iter(destPath);
Gtk::TreeRow newRow;
switch (destPos) {
case Gtk::TREE_VIEW_DROP_BEFORE:
case Gtk::TREE_VIEW_DROP_INTO_OR_BEFORE:
newRow = *treeModel[index]->insert(destination);
break;
case Gtk::TREE_VIEW_DROP_AFTER:
case Gtk::TREE_VIEW_DROP_INTO_OR_AFTER:
newRow = *treeModel[index]->insert_after(destination);
break;
default: std::cerr << "oops in moveRow()" << std::endl;
return;
}
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
Glib::RefPtr<Gdk::Pixbuf> pixbuf = wf->getPixbuf(
WidgetConstants::audioClipIconImage);
newRow[modelColumns.pixbufColumn] = pixbuf;
newRow[modelColumns.textColumn] = value;
treeModel[index]->erase(source);
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Insert a string row into a tree view. * Insert a string row into a tree view.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
TestWindow :: insertRow (int index, TestWindow :: insertRow (int index,
int x, int x,
int y, int y,
Glib::ustring value) throw () Glib::ustring value,
RowOperation operation) throw ()
{ {
Gtk::TreePath destPath; Gtk::TreePath destPath;
Gtk::TreeViewDropPosition destPos; Gtk::TreeViewDropPosition destPos;
treeView[index]->get_dest_row_at_pos(x, y, destPath, destPos); treeView[index]->get_dest_row_at_pos(x, y, destPath, destPos);
std::cerr << "path: " << destPath.to_string() // get_drag_dest_row() does not work here, for some strange reason
<< ", pos: " << int(destPos)
<< std::endl;
Gtk::TreeIter destination = treeModel[index]->get_iter(destPath);
Gtk::TreeRow newRow; Gtk::TreeRow newRow;
switch (destPos) {
case Gtk::TREE_VIEW_DROP_BEFORE:
case Gtk::TREE_VIEW_DROP_INTO_OR_BEFORE:
newRow = *treeModel[index]->insert(destination);
break;
case Gtk::TREE_VIEW_DROP_AFTER: if (destPath.gobj() == 0) {
case Gtk::TREE_VIEW_DROP_INTO_OR_AFTER: newRow = *treeModel[index]->append();
newRow = *treeModel[index]->insert_after(destination);
break;
default: std::cerr << "oops in insertRow()" << std::endl; } else {
return; assert (!destPath.empty());
Gtk::TreeIter destination = treeModel[index]->get_iter(destPath);
if (destPos == Gtk::TREE_VIEW_DROP_BEFORE
|| destPos == Gtk::TREE_VIEW_DROP_INTO_OR_BEFORE) {
newRow = *treeModel[index]->insert(destination);
} else if (destPos == Gtk::TREE_VIEW_DROP_AFTER
|| destPos == Gtk::TREE_VIEW_DROP_INTO_OR_AFTER) {
newRow = *treeModel[index]->insert_after(destination);
} else {
assert (false);
return;
}
} }
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance(); Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
@ -492,6 +444,17 @@ std::cerr << "path: " << destPath.to_string()
WidgetConstants::audioClipIconImage); WidgetConstants::audioClipIconImage);
newRow[modelColumns.pixbufColumn] = pixbuf; newRow[modelColumns.pixbufColumn] = pixbuf;
newRow[modelColumns.textColumn] = value; newRow[modelColumns.textColumn] = value;
if (operation == ROW_MOVE) {
Glib::RefPtr<Gtk::TreeView::Selection>
selection = treeView[index]->get_selection();
std::list<Gtk::TreePath>
rows = selection->get_selected_rows();
assert (rows.size() == 1);
Gtk::TreeIter source = treeModel[index]->get_iter(rows.front());
treeModel[index]->erase(source);
}
} }
@ -514,6 +477,8 @@ TestWindow :: onLabelDragDataReceived(
context->drag_finish(true, true, time); context->drag_finish(true, true, time);
} else { } else {
std::cerr << "unknown type of data dropped on the label"
<< std::endl;
label->set_label(*getResourceUstring("dropHereText")); label->set_label(*getResourceUstring("dropHereText"));
context->drag_finish(false, false, time); context->drag_finish(false, false, time);
} }

View file

@ -72,6 +72,15 @@ using namespace LiveSupport::Core;
*/ */
class TestWindow : public LocalizedObject class TestWindow : public LocalizedObject
{ {
public:
/**
* The possible DnD operations.
*/
typedef enum { ROW_COPY,
ROW_MOVE } RowOperation;
private: private:
/** /**
@ -109,20 +118,6 @@ class TestWindow : public LocalizedObject
} }
} }
/**
* Move the selected row to the given position.
*
* @param index which tree view to work on.
* @param x the x coordinate of the new location of the row.
* @param y the y coordinate of the new location of the row.
* @param value the string to put into the new row.
*/
void
moveRow (int index,
int x,
int y,
Glib::ustring value) throw ();
/** /**
* Insert a string row into a tree view. * Insert a string row into a tree view.
* *
@ -130,12 +125,14 @@ class TestWindow : public LocalizedObject
* @param x the x coordinate of the location of the new row. * @param x the x coordinate of the location of the new row.
* @param y the y coordinate of the location of the new row. * @param y the y coordinate of the location of the new row.
* @param value the string to put into the new row. * @param value the string to put into the new row.
* @param operation whether to copy or move the row.
*/ */
void void
insertRow (int index, insertRow (int index,
int x, int x,
int y, int y,
Glib::ustring value) throw (); Glib::ustring value,
RowOperation operation) throw ();
protected: protected: