[ruby-gnome2-doc-cvs] [Ruby-GNOME2 Project Website] update - tut-gtk2-dnd-native-treev

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2013年 3月 13日 (水) 06:23:04 JST


-------------------------
REMOTE_ADDR = 184.145.80.119
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dnd-native-treev
-------------------------
@@ -1,31 +1,44 @@
-= Drag And Drop
+= (10) Drag And Drop
 {{link "tut-gtk2-dnd-intro", "tut-gtk2-dnd", "tut-gtk", "tut-gtk2-dnd-textv-n-iconv"}}
 
 
-#######################################################################
-#### Do not forget to update the return arrow in "tut-gtk2-dynui". ####
-#######################################################################
 
-
+# (10.3)/(9a) [current file: tut-gtk2-dnd-native-treev]
 == Sorry, still under construction
 
 
-# (10.3)/(9a) [current file: tut-gtk2-dnd-native-treev]
+##    10.3 DnD Widgets With Their Own Gdk::Window
+##
+##       10.3.1 DnD In Text View Widget
+##
+##       10.3.2 DnD Tree View Items
+##          10.3.2.1 Built-in DnD Tree View Mechanism
+##          10.3.2.2 Custom Made DnD In Tree View
+##
+##
+##       10.3.3 DnD Icon View Items
+##
+##       10.3.4 Dragging And Dropping Onto Drawable Widgets
+##          10.3.4.1 DnD Onto Gtk::Gtk::DrawingArea
+##          10.3.4.2 DnD And Cairo
 
 
 
 
 # (10.3)
 == DnD Widgets With Their Own Gdk::Window
+(10.3){{br}}
 
+Now that we have learned the basics of drag-and-drop mechanism exploring the widgets without their own Gdk::Window, which we also dubbed "widgets without native DnD support", it is time to look at those GTk widgets, that do support DnD by design. Since these Gtk widgets have built in drag-and-drop mechanism, they in general require very little or no additional coding. However, sometimes you are not satisfied with the default dnd behaviour, and you may need to try to implement some customized dnd functionality. Gtk widgets provide a number of methods, attributes and signals that comprise "dnd infrastructure" to help you mould the DnD behaviour to better fit your needs. In the continuation of this chapter we will investigate both of these options and mechanisms. The most prominent widgets from this category are the Gtk::TextView, Gtk::IconView, and Gtk::TreeView.
 
-Now that we have learned the basics of drag-and-drop mechanism exploring the widgets without their own Gdk::Window, which we also dubbed "widgets without native DnD support", it is time to look at those GTk widgets, that do support DnD by design. Since these Gtk widgets have built in drag-and-drop mechanism, they in general require very little or no additional coding. However, sometimes you are not satisfied with the default dnd behaviour, and you may need to try to implement some customized dnd functionality. Gtk widgets provide a number of methods, attributes and signals that comprise "dnd infrastructure" to help you mould the DnD behaviour to better fit your needs. In the continuation of this chapter we will investigate both of these options and mechanisms. The most prominent widgets from this category are the Gtk::TreeView, Gtk::TextView, and Gtk::IconView.
 
 
 
 # (10.3.1)
 === DnD In Text View Widget
+(10.3.1){{br}}
 
+
 Of the three TextView, IconView, and TreeView widgets, the Gtk::TreeView widget is the list demanding to implement drag-and-drop features in your own Gtk GUI programs. Its DnD functionality is fully enabled for any Grk::TextView object you create, and users can start dragging text-view objects by selecting and dragging them to desired locations within the text-view. It is even possible to drag items external to the application with the text-view, whose contents can be converted to plain text, or replaced with the URI text. This text-view's default behaviour is quite satisfying when used on selected text within the text-view itself, but is rather limited for external items, nevertheless, it is fully functional, without any additional programming (coding) effort.  
 
 {{image_right("drag-in-txtv-colage.png")}}
@@ -38,12 +51,29 @@
     Either '$DEBUG' or '$MONITOR' variable must be set to((*true*))for the 'prn_dnd_sig_parms' debug method to work! If both '$DEBUG' or '$MONITOR' variables are set '$MONITOR' cancels a more verbose '$DEBUG' setting.
 
 
+Let's look at the program listing:
 
-{{br}}
+
+# (10.3.1.1)
+=== Complete 'textview-native-dnd.rb' Program Listing
+(10.3.1.1){{br}}
 
-Let's look at the program listing:
 
 :Programmer's Note:
+    (10.3.1.1.1){{br}}
     (HikiGtk and HikiDnDdbg modules can be viewed and copied from section:  10.2.1.1 [((<Time To Start Using Object-Oriented Programming Paradigm|tut-gtk2-dnd-intro#Time To Start Using Object-Oriented Programming Paradigm>))])
 
 ((*textview-native-dnd.rb*))
@@ -69,7 +86,24 @@
                             "line-3 abc d\nline-4 ...\nline-5 -- +++ [ ] {{}}\n" +
                             "line-6 _____________\n" +
                             "Last line."
-  =begin
+ =begin
        Gtk::Widget drag related signals and mnemonics of their parameters:
        -------------------------------------------------------------------
        drag-begin ............... self, drag_context
@@ -121,12 +138,34 @@
  TextViewDND.new("Exploring Native Text-View DnD")
 
 
+{{br}}
+
+
 The main point of this program example is to see that drag-and-drop actions, when used with Gtk::TextView widget, trigger all of the Gtk::Widget's drag related signals, and how to use relevant signal parameters to try to better understand the behind the scene DnD processes. You may find 'prn_dnd_sig_parms' method in HikiDnDdbg module a useful tool when writing your own programs employing DnD mechanisms.
+
+When reading the above program following is the output on the controlling terminal or console, after you drag and drop an item:
 
 
 :Console Output:
 
-    Following is the output on the controlling terminal or console, after you drag and drop an item:
+    (10.3.1.1.2){{br}}
 
      drag-begin .............................. caught.
      drag-motion ... potentially many 'drag-motion' signals were caught.
@@ -142,12 +164,31 @@
      # $MONITOR=true
      $DEBUG=true	# $MONITOR cancels $DEBUG
 
-
 {{br}}
 
 This example may seem too trivial to even consider it to include in the tutorial, however it took me a while before I figured out, that setting up a Gtk::TextView as destination widget manually causes Gtk only to misbehave. However, there may be circumstances when you may need to provide your own custom DnD actions, particularly when you wanted to drop into Gtk::TextView external objects and render them either as images and pixbufs or rich-text for that matter, which theoretically should all be possible, however, the documentation is far too vague about these situations, and projects that would need these features in their programs end up often as rather expensive RND operations. However, as we will see later, in the segment 10.3.3.1 (((<Custom DnD In Text View|tut-gtk2-dnd-textv-n-iconv#Custom DnD In Text View>))) it is possible to insert images into text-view by dragging and dropping. 
-
-
 
 
 
@@ -155,32 +174,59 @@
 {{br}}
 
 
+
 # (10.3.2)
 === DnD Tree View Items
+(10.3.2){{br}}
+
 
 Another widget, that requires almost no programming effort to activate native drag-and-drop features is Gtk::TreeView. Besides, this widget is one of those, where dragged and dropped objects are strictly the items belonging to some particular data structures and/or hierarchies and must be of a rather particular format, namely, the rows of predetermined sets of columns stored in related data models or data stores. This particularity about data structure and format is best met if dragging and dropping occurs within the same widget, i.e. you should always be able to drag one row within a list or a tree view to a new location, as long as the drop occurs in the same widget in which the drag also started. Currently this is even more true for a generic Gtk library, used by languages like Ruby, Python and alike, than is for the original GTK+ C and C++ (a.k.a. gtkmm) implementations. Namely, the original C GTK+ implementation allows you to drag rows of data from one list/tree view to
  another, i.e. in GTK+ you are not limited to the single widget, as you are in Ruby or Python when using Gtk+.
 
+When using DnD mechanism to move around rows within single tree or list view, you are actually employing the native DnD facilities. We will look at these next.
 
-When using DnD mechanism to move around rows within single tree or list view, you are actually employing the native DnD facilities. We will look at these next.
+
+
+#### Some Gtk widgets have built in drag-and-drop mechanism, which require very little or no additional coding. Such a widget is Gtk::TreeView. 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.
+
+
+
 
 
 
 
 # (10.3.2.1)
 === Built-in DnD Tree View Mechanism
+(10.3.2.1){{br}}
 
 
 {{image_right("treeview-builtin-dnd-s1.png")}}
 
 Next 'treeview-built-in-dnd.rb' 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 node items 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 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.
 
-
-
 # (10.3.2.1.1)
 :Office Supplies Array Initialization Module
 
+    (10.3.2.1.1){{br}}
     In the 'treeview-built-in-dnd.rb' example program we use auxiliary initialization application dependent module. If this module were useful also in many other tutorial example programs it would be wise to place it in a common directory or folder, along with our 'HikiGtk' module file (hiki-gtk.rb). However, we decided to place it in the same directory where also the example 'treeview-built-in-dnd.rb' program resides. This requires in the example program we tell Ruby interpreter to also include our current directory, from which we are going to run our example code, in the load path (look for the declarative statement ((*"$: << '.'"*)) at the beginning of the example program). Indeed, you could have as well specified the full path in the 'require' declarative instead, however, I wanted to repeat the idiom expanding the load path, so you get used to it, because it is very convenient when you use module files in other directories.
-
 
     Following is the module file, which you should copy into your working directory along with the program example:
 
@@ -236,11 +263,39 @@
 
 
 
-Let's look now at the example program:
+Let's look now at the (10.3.2.1) example program:
 
+=== 'treeview-built-in-dnd.rb' Program Listing 
+(10.3.2.1 - /continued/){{br}}
 
-:Programmer's Note:
-    (HikiGtk and HikiDnDdbg modules can be viewed and copied from section:  10.2.1.1 [((<Time To Start Using Object-Oriented Programming Paradigm|tut-gtk2-dnd-intro#Time To Start Using Object-Oriented Programming Paradigm>))])
+
 
 
 ((*treeview-built-in-dnd.rb*))
@@ -342,18 +370,47 @@
 ##       10.3.3 DnD Icon View Items
 ##
 ##       10.3.4 Dragging And Dropping Onto Drawable Widgets
-##          10.3.4.1 DnD Onto Gtk::Gtk::DrawingArea
+##          10.3.4.1 DnD Onto Gtk::DrawingArea
 ##          10.3.4.2 DnD And Cairo
 
 
 
 
 
-{{br}}
-{{br}}
+
 
 # (10.3.2.2)
 === Custom DnD In Tree View
+(10.3.2.2){{br}}
+
 
 To explore how to use custom DnD for tree-view widgets, we are going to use almost the same code as before in the 'treeview-built-in-dnd.rb' example. Our program here is called 'treeview-custom-dnd.rb'. Just like the parts with new custom Dnd, the preamble in program example here changed a bit, because we added the module to help us with debugging messages. If you need to refresh your memory about the 'requiring' and 'including' modules and classes or perhaps about the BasicWindow class, please refer back to section 10.2.1.1 (((<Time To Start Using Object-Oriented Programming Paradigm|tut-gtk2-dnd-intro#Time To Start Using Object-Oriented Programming Paradigm>))).
 
@@ -378,6 +407,37 @@
 
 
 :Programmer's Note:
+
+    (10.3.2.2.1){{br}}
     (HikiGtk and HikiDnDdbg modules can be viewed and copied from section:  10.2.1.1 [((<Time To Start Using Object-Oriented Programming Paradigm|tut-gtk2-dnd-intro#Time To Start Using Object-Oriented Programming Paradigm>))])
 
 




ruby-gnome2-cvs メーリングリストの案内
Back to archive index