Drag and drop between TreeViews
- From: "Hajo Molegraaf" <hjausenet hotmail com>
- To: gtkmm-list gnome org
- Subject: Drag and drop between TreeViews
- Date: Fri, 06 May 2005 18:09:50 +0200
Hi,
I'm doing my first steps with programming in gtkmm (2.4) and there are a few
things that I cannot get to work. One is drag and drop between TreeViews,
like in a file browser. I found some hints on the internet
(http://mail.gnome.org/archives/glademm-list/2004-January/msg00010.html),
but it calls for programming skills that I do not (yet) have. There it is
said that I "have to derive from the Model (!) [TreeStore] and override the
dnd vfuncs". I tried it (hardly knowing what I'm doing) and it didn't work.
Can someone explain me what to do? I added a short program where I tried to
make things work. Only dnd within a TreeView works, and only the
drag_data_delete_vfunc is called.
Thanks for the help,
Hajo Molegraaf
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/paned.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/treeview.h>
#include <gtkmm/treestore.h>
#include <iostream>
class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumns() { add(text); }
Gtk::TreeModelColumn<Glib::ustring> text;
};
class MyTreeStore : public Gtk::TreeStore
{
public:
static Glib::RefPtr<MyTreeStore>
MyTreeStore::create(const Gtk::TreeModelColumnRecord& cols)
{
MyTreeStore *x=new MyTreeStore(cols);
x->reference();
return Glib::RefPtr<MyTreeStore>(x);
}
private:
MyTreeStore(const Gtk::TreeModelColumnRecord& cols) :
Gtk::TreeStore(cols) {}
virtual bool drag_data_get_vfunc(const Gtk::TreeModel::Path& path,
Gtk::SelectionData* selection_data);
virtual bool drag_data_delete_vfunc(const Gtk::TreeModel::Path& path);
virtual bool drag_data_received_vfunc(const Gtk::TreeModel::Path& dest,
Gtk::SelectionData* selection_data);
};
bool MyTreeStore::drag_data_get_vfunc( const Gtk::TreeModel::Path& path,
Gtk::SelectionData* selection_data )
{
std::cout << "MyTreeStore::drag_data_get_vfunc\n";
//what am I supposed to do here
//what am I supposed to return
return true;
}
bool MyTreeStore::drag_data_delete_vfunc( const Gtk::TreeModel::Path& path )
{
std::cout << "MyTreeStore::drag_data_delete_vfunc\n";
//what am I supposed to do here
//what am I supposed to return
return true;
}
bool MyTreeStore::drag_data_received_vfunc( const Gtk::TreeModel::Path&
path,
Gtk::SelectionData* selection_data )
{
std::cout << "MyTreeStore::drag_data_received_vfunc\n";
//what am I supposed to do here
//what am I supposed to return
return true;
}
class MyView : public Gtk::TreeView
{
public:
MyView();
~MyView() {}
protected:
void fill();
ModelColumns model;
Glib::RefPtr<MyTreeStore> store;
};
MyView::MyView() :
store(MyTreeStore::create(model))
{
set_model(store);
append_column("Text", model.text);
fill();
// do I need to call these?
enable_model_drag_dest();
enable_model_drag_source();
}
void MyView::fill()
{
Gtk::TreeModel::Row row;
row = *(store->append());
row[model.text] = "text A";
row = *(store->append());
row[model.text] = "text B";
row = *(store->append());
row[model.text] = "text C";
}
class MainWindow : public Gtk::Window
{
public:
MainWindow();
~MainWindow() {}
protected:
MyView view1, view2;
};
MainWindow::MainWindow()
{
Gtk::HPaned* hpaned = Gtk::manage( new Gtk::HPaned() );
Gtk::ScrolledWindow* sw1 = Gtk::manage( new Gtk::ScrolledWindow() );
Gtk::ScrolledWindow* sw2 = Gtk::manage( new Gtk::ScrolledWindow() );
sw1->add(view1);
sw2->add(view2);
hpaned->add1(*sw1);
hpaned->add2(*sw2);
add(*hpaned);
show_all_children();
set_default_size(640,480);
set_title("Main Window");
set_modal(false);
property_window_position().set_value(Gtk::WIN_POS_CENTER);
set_resizable(true);
}
int main (int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
MainWindow mainWindow;
Gtk::Main::run(mainWindow);
return 0;
}
_________________________________________________________________
Nieuw: Download nu MSN Messenger 7.0 http://messenger.msn.nl/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]