ruby-****@sourc*****
ruby-****@sourc*****
2012年 11月 27日 (火) 03:16:21 JST
------------------------- REMOTE_ADDR = 184.145.95.170 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dnd-intro ------------------------- @@ -32,13 +32,23 @@ 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) + # Gtk::Drag.source_set(source_widget, start_button_mask, targets, actions) + treeview.enable_model_drag_source(Gdk::Window::BUTTON1_MASK, TVDND_TARGETS, TVDND_ACTIONS) or a less involved one: - Gtk::TreeView#enable_model_drag_source(start_button_mask, targets, actions) + # Gtk::TreeView#enable_model_drag_source(start_button_mask, targets, actions) + treeview.enable_model_drag_dest(TVDND_TARGETS, Gdk::DragContext::ACTION_ASK) + +The targets argument above identifies all the objects that dnd source and destination will accept. It is convenient to assemble all your targets in a constant since your source and destination widgets need to agree they both will operate with the same drag-and-drop objects (data). Namely, when your source and destination widgets are registered, they should be given the same set of targets as a parameter. The targets argument in either case above is an array of target entries, where each entry is, as mentioned above, the tuple in the form [target, flags, info]. Though you may get away by specifying an empty array ([]) for your targets argument, it is better to create constants to be used when registering your source and destination widgets. Here is a code snippet from our next example program: + + TVDND_FLAGS = Gtk::Drag::TARGET_SAME_WIDGET # TARGET_{SAME_APP, SAME_WIDGET, OTHER_APP, OTHER_WIDGET} + TVDND_INFO = 0 + TVDND_TARGETS = [["tv_item", TVDND_FLAGS, TVDND_INFO]] + TVDND_ACTIONS = Gdk::DragContext::ACTION_MOVE # _ASK,_COPY,_LINK,_MOVE,_DEFAULT,_PRIVATE + -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: +In both of the cases, enabling model source and destination 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,