D'n'D testing
This commit is contained in:
parent
f7d9b517e0
commit
9681e780d7
|
@ -101,6 +101,10 @@ TestWindow :: TestWindow (void) throw ()
|
|||
modelColumns.textColumn);
|
||||
fillTreeModel();
|
||||
|
||||
glade->get_widget("label1", label);
|
||||
label->set_label(*getResourceUstring("dropHereText"));
|
||||
setupDndCallbacks();
|
||||
|
||||
glade->connect_clicked("okButton1", sigc::mem_fun(*this,
|
||||
&TestWindow::onOkButtonClicked));
|
||||
}
|
||||
|
@ -165,6 +169,40 @@ TestWindow :: fillTreeModel (void) throw ()
|
|||
Gtk::TreeModel::Row row = *treeModel->append();
|
||||
row[modelColumns.pixbufColumn] = pixbuf;
|
||||
row[modelColumns.textColumn] = text;
|
||||
|
||||
row = *treeModel->append();
|
||||
row[modelColumns.pixbufColumn] = pixbuf;
|
||||
row[modelColumns.textColumn] = "1";
|
||||
|
||||
row = *treeModel->append();
|
||||
row[modelColumns.pixbufColumn] = pixbuf;
|
||||
row[modelColumns.textColumn] = "2";
|
||||
|
||||
row = *treeModel->append();
|
||||
row[modelColumns.pixbufColumn] = pixbuf;
|
||||
row[modelColumns.textColumn] = "3";
|
||||
|
||||
row = *treeModel->append();
|
||||
row[modelColumns.pixbufColumn] = pixbuf;
|
||||
row[modelColumns.textColumn] = "4";
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Set up the D'n'D callbacks.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TestWindow :: setupDndCallbacks (void) throw ()
|
||||
{
|
||||
std::list<Gtk::TargetEntry> targets;
|
||||
targets.push_back(Gtk::TargetEntry("STRING"));
|
||||
|
||||
treeView->drag_source_set(targets);
|
||||
treeView->signal_drag_data_get().connect(sigc::mem_fun(*this,
|
||||
&TestWindow::onTreeViewDragDataGet));
|
||||
label->drag_dest_set(targets);
|
||||
label->signal_drag_data_received().connect(sigc::mem_fun(*this,
|
||||
&TestWindow::onLabelDragDataReceived));
|
||||
}
|
||||
|
||||
|
||||
|
@ -211,3 +249,50 @@ TestWindow :: run (void) throw ()
|
|||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The callback for the start of the drag.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TestWindow :: onTreeViewDragDataGet(
|
||||
const Glib::RefPtr<Gdk::DragContext> & context,
|
||||
Gtk::SelectionData & selectionData,
|
||||
guint info,
|
||||
guint time)
|
||||
throw ()
|
||||
{
|
||||
Glib::RefPtr<Gtk::TreeView::Selection> selection
|
||||
= treeView->get_selection();
|
||||
Gtk::TreeModel::Row row = *selection->get_selected();
|
||||
Glib::ustring dropString = row[modelColumns.textColumn];
|
||||
|
||||
selectionData.set(selectionData.get_target(),
|
||||
8 /* 8 bits format*/,
|
||||
(const guchar *) dropString.c_str(),
|
||||
dropString.bytes());
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The callback for the end of the drag.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TestWindow :: onLabelDragDataReceived(
|
||||
const Glib::RefPtr<Gdk::DragContext> & context,
|
||||
int x,
|
||||
int y,
|
||||
const Gtk::SelectionData & selectionData,
|
||||
guint info,
|
||||
guint time)
|
||||
throw ()
|
||||
{
|
||||
if (selectionData.get_length() >= 0 && selectionData.get_format() == 8) {
|
||||
Glib::ustring data = selectionData.get_data_as_string();
|
||||
label->set_label(data);
|
||||
|
||||
} else {
|
||||
label->set_label(*getResourceUstring("dropHereText"));
|
||||
}
|
||||
|
||||
context->drag_finish(false, false, time);
|
||||
}
|
||||
|
||||
|
|
|
@ -79,13 +79,19 @@ class TestWindow : public LocalizedObject
|
|||
*/
|
||||
void
|
||||
configureBundle (void) throw ();
|
||||
|
||||
|
||||
/**
|
||||
* Fill the tree model.
|
||||
*/
|
||||
void
|
||||
fillTreeModel (void) throw ();
|
||||
|
||||
/**
|
||||
* Set up the D'n'D callbacks.
|
||||
*/
|
||||
void
|
||||
setupDndCallbacks (void) throw ();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -104,6 +110,11 @@ class TestWindow : public LocalizedObject
|
|||
*/
|
||||
ZebraTreeView * treeView;
|
||||
|
||||
/**
|
||||
* The drop target label.
|
||||
*/
|
||||
Gtk::Label * label;
|
||||
|
||||
/**
|
||||
* The OK button.
|
||||
*/
|
||||
|
@ -165,6 +176,30 @@ class TestWindow : public LocalizedObject
|
|||
virtual bool
|
||||
onDeleteEvent (GdkEventAny * event) throw ();
|
||||
|
||||
/**
|
||||
* The callback for the start of the drag.
|
||||
*/
|
||||
virtual void
|
||||
onTreeViewDragDataGet(
|
||||
const Glib::RefPtr<Gdk::DragContext> & context,
|
||||
Gtk::SelectionData & selectionData,
|
||||
guint info,
|
||||
guint time)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* The callback for the end of the drag.
|
||||
*/
|
||||
virtual void
|
||||
onLabelDragDataReceived(
|
||||
const Glib::RefPtr<Gdk::DragContext> & context,
|
||||
int x,
|
||||
int y,
|
||||
const Gtk::SelectionData & selectionData,
|
||||
guint info,
|
||||
guint time)
|
||||
throw ();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
||||
<!--Generated with glade3 3.2.0 on Wed Aug 8 11:34:54 2007 by fgerlits@fgerlits-laptop-->
|
||||
<!--Generated with glade3 3.2.0 on Thu Aug 16 15:39:58 2007 by fgerlits@fgerlits-laptop-->
|
||||
<glade-interface>
|
||||
<widget class="GtkWindow" id="mainWindow1">
|
||||
<property name="width_request">300</property>
|
||||
<property name="height_request">200</property>
|
||||
<property name="height_request">300</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox1">
|
||||
|
@ -35,11 +35,25 @@
|
|||
<property name="can_focus">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="headers_clickable">True</property>
|
||||
<property name="reorderable">True</property>
|
||||
<property name="rules_hint">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="label" translatable="yes">drag target</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHButtonBox" id="hbuttonbox1">
|
||||
<property name="visible">True</property>
|
||||
|
@ -60,7 +74,7 @@
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
|
|
|
@ -12,5 +12,7 @@ hu:table
|
|||
textOne:string { "Egy - megérett a meggy." }
|
||||
textTwo:string { "Kettő - csipkebokor vessző." }
|
||||
textThree:string { "Három - te leszel a párom. " }
|
||||
|
||||
dropHereText:string { "Ide lehet húzni dolgokat." }
|
||||
}
|
||||
|
||||
|
|
|
@ -12,5 +12,7 @@ root:table
|
|||
textOne:string { "When I was One, I had just begun." }
|
||||
textTwo:string { "When I was Two, I was nearly new." }
|
||||
textThree:string { "When I was Three, I was hardly me." }
|
||||
|
||||
dropHereText:string { "You can drop things here." }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue