ruby-****@sourc*****
ruby-****@sourc*****
2012年 11月 26日 (月) 11:09:46 JST
------------------------- REMOTE_ADDR = 184.145.95.170 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dnd-intro ------------------------- @@ -23,5 +23,28 @@ # (10.2.2) === The DnD Source And Destination Objects +The source locations and/or widgets are those in which the objects to be dragged originally reside, and the destinations are places, widgets or object onto which you wish to drop the dragged objects. These widgets or objects may be different, for instance you may plan to drag an icon from an icon view onto some other viewing area, perhaps a canvas or a text widget. Or they can be one and the same widget and indeed the same object, as is the case when you are reordering rows in a tree view, or items in the text view. In the previous chapter 9, (section: 9.6.2.2), we have already seen our toolbar 'dnd-toolbox.rb' example in which the source and destination are of the same type namely Gtk::Frame, but they are two different objects. -The source locations and/or widgets are those in which the objects to be dragged originally reside, and the destinations are places, widgets or object onto which you wish to drop the dragged objects. These widgets or objects may be different, for instance if you plan to drag an icon from an icon view onto some other viewing area, perhaps a canvas or a text widget. Or they can be one and the same widget and indeed the same object, as is the case when you are reordering rows in a tree view, or items in the text view. +Normally, you have to set up source and destination widgets. There exists a plethora of methods to accomplish this. with the exception of the widgets that support dnd by design, in which you can choose the default dnd behaviour with almost no extra work, you need register a widget as source or destination or both. When setting up a widget as source or destination widget, you have to identify the drag-object(s) or as we mentioned in previous paragraph the 'target(s)'. During this registration you also need to specify the((*action*))the dnd system is to take for the item being dragged. This action is defined as a constant in Gdk::DragContext#GdkDragAction and conveys to the Gtk system whether the item is to be copied, moved, removed from the source, and how to react at the destination at the time the drop occurs. Following are two API examples to show what kind of arguments you may be required to supply when registering a widget as a source: + + Gtk::Drag.source_set(source_widget, start_button_mask, targets, actions) + +or a less involved one: + + Gtk::TreeView#enable_model_drag_source(start_button_mask, targets, actions) + +In both the cases above you also define which mouse button should be used to initiate and actually carry out the dragging itself. In our tool-bar example we used yet a different way to register the source widget: + + Gtk::Drag.begin( + widget=src_widget, + targets=Gtk::TargetList.new(TBDND_TARGETS), # [["toolbar", Gtk::Drag::TARGET_SAME_APP, 100]] + actions=TBDND_ACTION, # Gdk::DragContext::ACTION_ASK + button=e.button, + event # Gdk::Event::DRAG_LEAVE + ) + +When you are registering a destination, you may need to provide additional flags, controlling the potential resulting action after the drop. + + Gtk::Drag.dest_set(widget, flags, targets, actions) + +Do not be too much concerned with all the different ways we may be using when setting up source and destination widgets. Try to emulate the examples you can find in our tutorial, they should provide enough material, to grasp the basic understanding.