Gtk::TreeView. How can I ensure uniqueness while drag and drop rows?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I am developing a gtkmm applcation with classes derived from
Gtk::TreeStore, and Gtk::TreeView. My tree is two-level one, and user
can drag and drop rows with some constraints:
 - top-level rows (folders) must be unique, so user can move this rows
and must not copy them.
 - second-level rows (thumbnails) must be unique inside their parents
(folders), so user can move these rows both inside their parents, and
to another top-level rows (folders). But user cannot copy them to their
parents, and can only copy them to another top-level rows (folders).

 I could ensure these constraints if I know whether I copy or move the
row while dragging it over the tree view. I can get this info by
catching status of Control key ("copy" when Control key pressed, and
"move" when the key released). But I can get this status (by catching
key_pressed_event/key_released_event) only BEFORE dragging rows, when
the tree view widget has focus. DURING drag and drop process another
object grabs focus (this object can be seen as small rectangle moving
over the tree view with mouse pointer, and it answers on Control key
pressing/releasing, not tree view widget). But I have no idea how can I
get access to this object and whether I can get Control key status from it.

 So my first question: can anybody teach me how can I get access to this
object?

Another way to fulfill the task could be let the row be copied where it
has not to, and then check for unique violation and remove wrong row.
Perhaps I could do this in on_rows_reordered() event. But this event do
not occur in my application after I move or copy rows. I try both
on_rows_reordered() event, and signal_rows_reordered() with no success.
Trying on_row_inserted() and on_row_deleted() events work as it should
be, but these events don't help me with this task.

And my second question: why isn't on_rows_reordered() event occured for me?

Perhaps someone can teach me some other way to ensure uniqueness for
such a case.

Thank you, Mikhail.

PS Here are some fragments of my tree model and tree view code:

class MThumbnailViewMdl : public Gtk::TreeStore
{
  private:
  MThumbnailViewMdl();
	
  public:
  MThumbnailViewMdlCol mdlCol;
  static Glib::RefPtr<MThumbnailViewMdl> create();

  private:
  bool drag_data_received_vfunc(const TreeModel::Path& dst,
                                const Gtk::SelectionData& selData);
  void on_row_deleted(const TreeModel::Path& path);
  void on_row_inserted(const TreeModel::Path& path,
                       const TreeModel::iterator& iter);
  bool row_draggable_vfunc(const Gtk::TreeModel::Path& path) const;
  bool row_drop_possible_vfunc(const Gtk::TreeModel::Path& dst,
                               const Gtk::SelectionData& selData) const;
  void on_rows_reordered(const TreeModel::Path& path,
                         const TreeModel::iterator& iter,
                         int* new_order);
  void on_rowsReordered(const TreeModel::Path& path,
                        const TreeModel::iterator& iter,
                        int* newOrder);
};

MThumbnailViewMdl::MThumbnailViewMdl() :
  processDnD(false)
{
  set_column_types(mdlCol);
  signal_rows_reordered().connect(sigc::mem_fun(*this,
                                &MThumbnailViewMdl::on_rowsReordered));
}
void MThumbnailViewMdl::on_rows_reordered(const TreeModel::Path& path,
                                       const TreeModel::iterator&iter,
                                       int* new_order)
{
  std::cout << "MThumbnailViewMdl::on_row_reordered" << std::endl;
  Gtk::TreeStore::on_rows_reordered(path,iter,new_order);
}
void MThumbnailViewMdl::on_rowsReordered(const TreeModel::Path& path,
                                     const TreeModel::iterator& iter,
                                     int* newOrder)
{
  std::cout << "MThumbnailViewMdl::on_rowsReordered" << std::endl;
}

class MThumbnailView : public Gtk::TreeView
{
  public:
  MThumbnailView();
  virtual ~MThumbnailView();

  MThumbnailViewMdlCol* getMdlCol();
  Glib::RefPtr<MThumbnailViewMdl> getTreeMdl();

  private:
  MThumbnailViewMdlCol mdlCol;
  Glib::RefPtr<MThumbnailViewMdl> rcpTreeMdl;
  void setTreeMdl();
};

MThumbnailView::MThumbnailView()
{
  rcpTreeMdl = MThumbnailViewMdl::create();

  setTreeMdl();
  set_reorderable();
  set_model(rcpTreeMdl);
  enable_model_drag_source();
  enable_model_drag_dest();
  ...	
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNmV3gAAoJENKVKl8fDg/67mMH/j7xgFadS1BSXQ847XmtizFv
JMNMGIB4+6KgsunLOKFkQbBmXdzu7xwvdSDSqOOq6TDfok6LbjEirORChrPqf9wQ
p0lKIHTGRdtQd956YhryW8a8nPvnxh0+0fIiu4APbnNVI11zJqTmcug/JbX7hapv
6BmRu5bW1M7GsajSr/vMZHvacsIFCPWlBevEgGUT3kcRq6vgZE5Z17E/p/WJRaac
oCU1KCGrWVZYaBlHYaoteLhIdjFBGWjbIOxvsBSyrDibqORy3MRWwSp7OodoxdZc
3lGha4CPBaBTHrxTc6KF1Tl98g0VwgpFLsxJYdVZ2m3L19st2OpeMhn/BYcar7c=
=Qa89
-----END PGP SIGNATURE-----


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]