ruby-****@sourc*****
ruby-****@sourc*****
2012年 11月 27日 (火) 07:10:29 JST
------------------------- REMOTE_ADDR = 184.145.95.170 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dnd-intro ------------------------- @@ -74,13 +74,20 @@ == DnD Tree View Items +Some Gtk widgets have built in drag-and-drop mechanism, which require very little or no additional coding. Such a widget is Gtk::TreeView. In such widgets you should be able to use the dnd feature with little or no programming. However, sometimes you are not satisfied with the default dnd behaviour, and you may need to try to implement some customized dnd functionality. As you will see Gtk::TreeView provides a number of methods to help you accomplish this. We will investigate some of these issues in our example after the next one. -{{image_right("treeview-builtin-dnd-s1.png")}} +# (10.2.1) +=== Builti-in DnD Tree View Mechanism -Some Gtk widgets have built in drag-and-drop mechanism, which require very little or no additional coding. Such a widget is Gtk::TreeView. So our first example program will show that only with a line of code you can get the complete drag-and-drop behaviour for free. All you need is to set up the reorderable attribute to true, by using the 'Gtk::TreeView#reorderable=' method. The drag objects here are the tree view rows, regardless whether they are leaf or nodes with children. When you left-click, hold the mouse button down and drag the mouse simultaneously the cursor changes to the 'move-icon' and the row you are dragging appears underneath it. If you look carefully, when dragging, you will notice that a potential drop position is shown, namely, the items over which you are dragging the row get highlighted, and the when you are in-between i.e., above or below rows a line appears. If you are dropping the dragged row onto a highlighted row it will become it's child, but if you drop it when the line indicator is shown, the dragged item will be placed at that position. +{{image_right("treeview-builtin-dnd.png")}} +Our first example program will show that only with a line of code you can get the complete drag-and-drop behaviour for free. All you need is to set up the reorderable attribute to true, by using the 'Gtk::TreeView#reorderable=' method. The drag objects here are the tree view rows, regardless whether they are leaf or nodes with children. When you left-click, hold the mouse button down and drag the mouse simultaneously the cursor changes to the 'move-icon' and the row you are dragging appears underneath it. If you look carefully, when dragging, you will notice that a potential drop position is shown, namely, the items over which you are dragging the row get highlighted, and the when you are in-between i.e., above or below rows a line appears. If you are dropping the dragged row onto a highlighted row it will become it's child, but if you drop it when the line indicator is shown, the dragged item will be placed at that position. + + + + Let's look at the code: @@ -189,3 +196,17 @@ window.add(scrolled_win) window.show_all Gtk.main + + + + + +# (10.2.2) +=== Custom Made DnD In Tree View