some dnd working, not good yet

This commit is contained in:
fgerlits 2007-08-30 16:58:45 +00:00
parent a8c1eb0c3c
commit f6f09abee0
2 changed files with 170 additions and 31 deletions

View File

@ -34,6 +34,7 @@
#endif
#include <iostream>
#include <cassert>
#include "LiveSupport/Widgets/WidgetFactory.h"
#include "LiveSupport/Widgets/Colors.h"
@ -322,12 +323,12 @@ TestWindow :: onTreeViewDragDataGet(
std::list<Gtk::TreePath> rows = selection->get_selected_rows();
Glib::ustring dropString = leftOrRight(index);
// we can assume there is only one row selected, due to bug
// ...
if (rows.size() >= 1) {
Gtk::TreeRow row = *treeModel[index]->get_iter(rows.front());
dropString += " ";
dropString += row[modelColumns.textColumn];
}
// http://bugzilla.gnome.org/show_bug.cgi?id=70479
assert (rows.size() == 1);
Gtk::TreeRow row = *treeModel[index]->get_iter(rows.front());
dropString += " ";
dropString += row[modelColumns.textColumn];
selectionData.set(selectionData.get_target(),
8 /* 8 bits format*/,
@ -350,37 +351,147 @@ TestWindow :: onTreeViewDragDataReceived(
int index)
throw ()
{
if (selectionData.get_length() >= 0 && selectionData.get_format() == 8) {
Glib::ustring data = selectionData.get_data_as_string();
if (data.find("left") == 0) {
std::cerr << "left -> "
<< leftOrRight(index)
<< ": "
<< data.substr(5)
<< std::endl;
context->drag_finish(true, false, time);
} else if (data.find("right") == 0) {
std::cerr << "right -> "
<< leftOrRight(index)
<< ": "
<< data.substr(6)
<< std::endl;
context->drag_finish(true, false, time);
} else {
std::cerr << "unknown string dropped on "
<< leftOrRight(index)
<< " tree view: "
<< data
<< std::endl;
context->drag_finish(false, false, time);
}
} else {
if (selectionData.get_length() < 0 || selectionData.get_format() != 8) {
std::cerr << "unknown type of data dropped on "
<< leftOrRight(index)
<< " tree view"
<< std::endl;
context->drag_finish(false, false, time);
return;
}
Glib::ustring data = selectionData.get_data_as_string();
Glib::ustring stripped;
int source = -1;
int destination = index;
if (data.find("left") == 0) {
std::cerr << "left -> "
<< leftOrRight(index)
<< ": "
<< data.substr(5)
<< std::endl;
stripped = data.substr(5);
source = 0;
} else if (data.find("right") == 0) {
std::cerr << "right -> "
<< leftOrRight(index)
<< ": "
<< data.substr(6)
<< std::endl;
stripped = data.substr(6);
source = 1;
} else {
std::cerr << "unknown string dropped on "
<< leftOrRight(index)
<< " tree view: "
<< data
<< std::endl;
context->drag_finish(false, false, time);
return;
}
if (source == destination) {
moveRow(destination, x, y, stripped);
context->drag_finish(true, true, time);
} else {
insertRow(destination, x, y, stripped);
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.
*----------------------------------------------------------------------------*/
void
TestWindow :: insertRow (int index,
int x,
int y,
Glib::ustring value) throw ()
{
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 insertRow()" << 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;
}

View File

@ -109,6 +109,34 @@ 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.
*
* @param index which tree view to work on.
* @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 value the string to put into the new row.
*/
void
insertRow (int index,
int x,
int y,
Glib::ustring value) throw ();
protected: