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

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2012年 12月 7日 (金) 13:11:34 JST


-------------------------
REMOTE_ADDR = 74.14.158.129
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dnd-intro
-------------------------
@@ -172,9 +172,183 @@
 
 
 
+# (((((((((((((((((((((
+You almost certainly are by now aware, that for these drag-and-drop actions neither the source button widget as nor the destination label widgets, offer any particular help with the drag-and-drop operations (actions). We have to provide the appropriate signal handler callbacks, and perform the swapping of the widgets' positions ourselves.
+
+
+
+{{br}}
 # (10.2.1.1)
 :Time To Start Using Object-Oriented Programming Paradigm
+
+    So far in our tutorial we have mostly ignore the fact that Gtk is really an object oriented GUI system, intended to be used as such. Ruby itself is an excellent object oriented language and it would be inappropriate if we continued to ignore these facts.
+
+    From this point on, we will try to stay in the OO paradigm, and we plan that our example programs reflect this, and will from now on consistently use the((*BasicWindow*))class, which provides all the required Gtk::Window behaviours and properties. In fact it itself is a subclass of Gtk::Window class.
+
+    In order to use it in your program examples that follow in this tutorial, you need to make sure that the directory in which 'hiki-gtk.rb' file with 'BasicWindow' class definition resides will be included in Ruby's load path.
+
+    Hence before you continue, take a few moments and copy the following file into a desired directory on your system:
+    
+    ((*hiki-gtk.rb*))
+
+     module HikiGtk
+       require 'gtk2'
+     
+       class BasicWindow < Gtk::Window
+         def initialize(title = nil)
+           super(Gtk::Window::TOPLEVEL)
+           
+           set_title(title) if title
+           set_size_request(300, 200)
+           border_width = 10
+     
+           signal_connect("key_press_event") do |widget, event|
+             if event.state.control_mask? and event.keyval == Gdk::Keyval::GDK_q
+               destroy
+               true
+             else
+               false
+             end
+           end
+     
+           signal_connect("delete_event") { |widget, event| quit }
+           signal_connect("destroy") { Gtk.main_quit }
+         end
+     
+         def quit
+           puts "DEBUG: quiting Hiki example"
+           destroy
+           false
+         end
+       end
+     end
+      
+
+    The name and location of the directory into which you copy this file are arbitrary, and all you need to do in your program examples is modify the '$:' line in the listing to point to this directory. For instance if you copy this file into a folder called '/home/mary/mygtk-lib', then in all the example programs you copy from this tutorial, you should change the line((*$: << '~/work/HikiLib'*)) to((*$: << '/home/mary/mygtk-lib'*)).  
+
+
+
+
+
+{{br}}
+# (10.2.1 - continued)
+(Back to our 'Dragging a Button Onto a Label' discussion) 
+
+The program starts with the widening of the Ruby load path ($:), to ensure our tutorial 'hiki-gtk.rb' class and 'hiki-dnd-dbg.rb' module are found, and with the usual preparation of the driving 'BasicWindow' class.
+
+ $: << '~/work/HikiLib'
+ require 'hiki-gtk.rb'
+ include HikiGtk
+ require 'hiki-dnd-dbg.rb'
+ include HikiDBG
+
+Note:
+    As you see above we are using here an auxiliary module stored in file called 'hiki-dnd-dbg.rb'. You should copy this file into the folder, where you earlier copied the BasicWindow' class file ('hiki-gtk.rb'). Do this now. Here is the file:
+
+    ((*hiki-dnd-dbg.rb*))
+
+     module HikiDBG
+     
+       def blow_up(targs)
+         target_names="\n"
+         line=""
+         targs.each do |token|
+           if line.length > 65
+             target_names += "\t\t" + line
+             line = "\n\t\t"
+           end
+           line += token.name + ", "
+         end
+         target_names + line.chop.chop + ";\n"
+       end
+     
+     
+     # NOTE:
+     #       Global value {{ $DEBUG }} must be set to true for this method to run!
+     # ALSO:
+     #	If you are using Gtk::TextView as source and/or destination, you
+     #	may alse need to initialize {{ $text_buffer }} global variable to
+     #	your {{ Gtk::TextView#buffer }}
+     
+       def prn_dnd_sig_parms(sig, *parms)
+     
+         return if (!($DEBUG||=false)) && (!($MONITOR||=false))
+     
+         w=dc=x=y=d=i=t=nil
+         case sig
+         when /drag-begin/;		w, dc			= parms
+         when /drag-data-delete/;	w, dc			= parms
+         when /drag-data-get/;	w, dc, d, i, t		= parms
+         when /drag-data-received/;	w, dc, x, y, d, i, t	= parms
+         when /drag-drop/;		w, dc, x, y, t		= parms
+         when /drag-end/;		w, dc			= parms
+         when /drag-leave/;		w, dc, t		= parms
+         when /drag-motion/;		w, dc, x, y, t		= parms
+         end
+     
+         # -- ignore all remaining 'drag-motion' signals, but keep
+         #    recording the latest x, y positions!
+         if ($prev_sig||=nil) == sig && sig == 'drag-motion'
+           if sig == 'drag-motion'
+             $prev_x = x; $prev_y = y
+           end
+           return
+         end
+         $prev_sig = sig
+         print "#{sig}"
+     
+         if $MONITOR		# ||= false
+           msg = sig == 'drag-motion' ?
+              " ... potentially many 'drag-motion' signals were caught." : " caught.\n"
+           puts msg
+           return
+         else
+           print ":\n"
+         end
+     
+         # -- Note: 
+         #       display targets only for 'drag-data-received' and 
+         #       'drag-data-get' signals
+         if !dc.nil?
+           print "\t#{dc.class}.targets: "
+           if sig == 'drag-data-received' || sig == 'drag-data-get'
+             print blow_up(dc.targets)
+           else
+             print "\n"
+           end
+           print "\tdrag_context.selection.name=#{dc.selection.name}," if !dc.selection.nil?
+         end
+         print "\tx,y=(#{x},#{y}), "	 if !x.nil?
+         if !d.nil?
+           
+           print "\n\tdata.class=#{d.class}, "
+           print "\n\tdata.target.class=#{d.target.class}; "
+           print "\n\tdata.target.name /atom.name/ = #{d.target.name}" #=> GTK_TREE_MODEL_ROW | tv_item |...
+           print "\n\tdata.text=#{d.text.strip}, " if d.text != "" && ! d.text.nil?
+         end
+         print "\n\tinfo=#{i}, "	 if !i.nil?
+         print "time=#{t} "		 if !t.nil?
+     
+         if $prev_x != nil
+             print "\n\n ....\t( [final x,y=(#{$prev_x},#{$prev_y})] .... " +
+                   "remaining 'drag-motion' signals\n     \t   before final one were blocked! )\n"
+            $prev_x = $prev_y = nil
+         end
+         puts
+       end
+       
+       def show_if_widget_contains_its_own_gdk_window(w)
+         answer = "#{w.class} does not contain its own Gdk::Window"
+         if w.respond_to? :no_window?
+           # widget.no_window? #=> false is o.k., contains Gdk::Window
+           answer = "#{w.class} contains its own Gdk::Window" if ! w.no_window?
+         end
+         answer    
+       end
+     
+     end
 
+# )))))))))))))))))))))
 
 
 {{br}}




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