fxruby 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/doc/apes02.html +6 -6
  2. data/doc/apes03.html +11 -11
  3. data/doc/book.html +1 -1
  4. data/doc/build.html +63 -63
  5. data/doc/ch03s02.html +7 -7
  6. data/doc/ch03s03.html +18 -18
  7. data/doc/ch03s04.html +11 -11
  8. data/doc/ch03s05.html +14 -14
  9. data/doc/ch04s02.html +14 -14
  10. data/doc/ch04s03.html +15 -15
  11. data/doc/ch04s04.html +28 -28
  12. data/doc/ch05s02.html +49 -49
  13. data/doc/ch05s03.html +8 -8
  14. data/doc/changes.html +263 -193
  15. data/doc/clipboardtut.html +57 -45
  16. data/doc/cvs.html +10 -10
  17. data/doc/differences.html +4 -4
  18. data/doc/dragdroptut.html +50 -50
  19. data/doc/events.html +11 -11
  20. data/doc/examples.html +48 -48
  21. data/doc/gems.html +37 -37
  22. data/doc/goals.html +4 -4
  23. data/doc/implementation.html +4 -4
  24. data/doc/infosources.html +6 -6
  25. data/doc/library.html +19 -19
  26. data/doc/opengl.html +31 -31
  27. data/doc/pt01.html +1 -1
  28. data/doc/pt02.html +1 -1
  29. data/doc/scintilla.html +15 -15
  30. data/doc/style.css +3 -0
  31. data/doc/todo.html +5 -5
  32. data/doc/tutorial1.html +34 -34
  33. data/doc/unicode.html +56 -0
  34. data/ext/fox16/dialogs_wrap.cpp +38 -14
  35. data/ext/fox16/frames_wrap.cpp +856 -22
  36. data/ext/fox16/fx3d_wrap.cpp +169 -144
  37. data/ext/fox16/icons_wrap.cpp +24 -6
  38. data/ext/fox16/image_wrap.cpp +24 -6
  39. data/ext/fox16/label_wrap.cpp +23 -8
  40. data/ext/fox16/markfuncs.cpp +8 -1
  41. data/ext/fox16/mdi_wrap.cpp +53 -23
  42. data/ext/fox16/menu_wrap.cpp +43 -19
  43. data/ext/fox16/scintilla_wrap.cpp +31 -7
  44. data/ext/fox16/table_wrap.cpp +31 -7
  45. data/ext/fox16/text_wrap.cpp +31 -7
  46. data/ext/fox16/treelist_wrap.cpp +300 -276
  47. data/ext/fox16/ui_wrap.cpp +385 -26
  48. data/lib/fox16/aliases.rb +3 -0
  49. data/lib/fox16/version.rb +1 -1
  50. data/rdoc-sources/FXFoldingList.rb +2 -2
  51. data/tests/TC_FXDirList.rb +1 -1
  52. data/tests/TC_FXGLViewer.rb +2 -0
  53. data/tests/TC_FXHeader.rb +1 -1
  54. data/tests/TC_FXIconList.rb +1 -1
  55. data/tests/TC_FXId.rb +1 -1
  56. data/tests/TC_FXList.rb +1 -1
  57. data/tests/TC_FXListBox.rb +1 -1
  58. data/tests/TC_FXMenuCommand.rb +0 -14
  59. data/tests/TC_FXTable.rb +0 -32
  60. data/tests/TC_FXTableItem.rb +1 -1
  61. data/tests/TC_FXTreeList.rb +1 -1
  62. data/tests/TC_FXTreeListBox.rb +1 -1
  63. metadata +5 -4
@@ -1,56 +1,68 @@
1
1
  <html><head>
2
2
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
3
- <title>Chapter&nbsp;6.&nbsp;Unicode and FXRuby</title><meta name="generator" content="DocBook XSL Stylesheets V1.61.2"><link rel="home" href="book.html" title="Developing Graphical User Interfaces with FXRuby"><link rel="up" href="pt01.html" title="Part&nbsp;I.&nbsp;The Basics"><link rel="previous" href="ch05s03.html" title="Putting It All Together"><link rel="next" href="examples.html" title="Chapter&nbsp;7.&nbsp;Examples"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&nbsp;6.&nbsp;Unicode and FXRuby</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch05s03.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;I.&nbsp;The Basics</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="examples.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="clipboardtut"></a>Chapter&nbsp;6.&nbsp;Unicode and FXRuby</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="clipboardtut.html#d0e1608">Basic Application</a></dt></dl></div><p>Beginning with version 1.6, FOX and FXRuby provide support for the
4
- display of Unicode strings in FOX widgets. For some excellent discussion
5
- about how to use Unicode in Ruby, I recommend Patrick Hall's article, <a href="http://ruphus.com/blog/2005/06/11/ruby-and-unicode/" target="_top">"Ruby and
6
- Unicode"</a> and why the lucky stiff's follow-up article, <a href="http://redhanded.hobix.com/inspect/closingInOnUnicodeWithJcode.html" target="_top">"Closing
7
- in on Unicode with Jcode"</a>. Here, we're going to make use of the
8
- ideas in those articles to give a quick demonstration of how to use FXRuby's
9
- support for Unicode.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1608"></a>Basic Application</h2></div></div><div></div></div><p>Here's the original version of our "Hello, World!" program:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">require 'fox16'
3
+ <title>Chapter&nbsp;4.&nbsp;Working With the Clipboard</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="book.html" title="Developing Graphical User Interfaces with FXRuby"><link rel="up" href="pt01.html" title="Part&nbsp;I.&nbsp;The Basics"><link rel="prev" href="ch03s05.html" title="Adding an icon"><link rel="next" href="ch04s02.html" title="Acquiring the Clipboard"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&nbsp;4.&nbsp;Working With the Clipboard</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s05.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;I.&nbsp;The Basics</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ch04s02.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="clipboardtut"></a>Chapter&nbsp;4.&nbsp;Working With the Clipboard</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="clipboardtut.html#d0e986">Basic Application</a></span></dt><dt><span class="section"><a href="ch04s02.html">Acquiring the Clipboard</a></span></dt><dt><span class="section"><a href="ch04s03.html">Sending Data to the Clipboard</a></span></dt><dt><span class="section"><a href="ch04s04.html">Pasting Data from the Clipboard</a></span></dt></dl></div><p>Two of the standard FOX widgets, <code class="classname">FXText</code> and
4
+ <code class="classname">FXTextField</code>, provide clipboard support out of the
5
+ box. For example, you can select some text in an
6
+ <code class="classname">FXTextField</code> and then press Ctrl+C to copy that text
7
+ to the system clipboard. You can also press Ctrl+X to "cut" the selected
8
+ text to the clipboard, or Ctrl+V to paste text from the clipboard into an
9
+ <code class="classname">FXText</code> or <code class="classname">FXTextField</code> widget.
10
+ The purpose of this tutorial is to demonstrate how to interact with the
11
+ clipboard programmatically, so that you can integrate additional clipboard
12
+ support into your FXRuby applications.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e986"></a>Basic Application</h2></div></div></div><p>In order to illustrate how to integrate cut and paste operations
13
+ into your application, we'll start from a simple FXRuby application that
14
+ doesn't yet provide any clipboard support. This application simply
15
+ presents a list of customers (from some external source).</p><pre class="programlisting">require 'rubygems'
16
+ require_gem 'fxruby'
17
+ require 'customer'
10
18
 
11
19
  include Fox
12
20
 
13
- application = FXApp.new("Hello", "FoxTest")
14
- main = FXMainWindow.new(application, "Hello", nil, nil, DECOR_ALL)
15
- FXButton.new(main, "&amp;Hello, World!", nil, application, FXApp::ID_QUIT)
16
- application.create()
17
- main.show(PLACEMENT_SCREEN)
18
- application.run()
19
- </pre></td></tr></table><p>and here's the modified version:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">require 'fox16'
20
- <span class="bold"><b>require 'jcode'</b></span>
21
+ class ClipMainWindow &lt; FXMainWindow
22
+ def initialize(anApp)
23
+ # Initialize base class first
24
+ super(anApp, "Clipboard Example", nil, nil, DECOR_ALL, 0, 0, 400, 300)
21
25
 
22
- <span class="bold"><b>$KCODE = 'u'</b></span>
23
-
24
- <span class="bold"><b>class UString &lt; String
25
- # Show u-prefix as in Python
26
- def inspect; "u#{ super }" end
27
-
28
- # Count multibyte characters
29
- def length; self.scan(/./).length end
30
-
31
- # Reverse the string
32
- def reverse; self.scan(/./).reverse.join end
26
+ # Place the list in a sunken frame
27
+ sunkenFrame = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK,
28
+ 0, 0, 0, 0, 0, 0, 0, 0)
29
+
30
+ # Customer list
31
+ customerList = FXList.new(sunkenFrame, nil, 0, LIST_BROWSESELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
32
+ $customers.each do |customer|
33
+ customerList.appendItem(customer.name, nil, customer)
34
+ end
35
+ end
36
+
37
+ def create
38
+ super
39
+ show(PLACEMENT_SCREEN)
40
+ end
33
41
  end
34
42
 
35
- module Kernel
36
- def u( str )
37
- UString.new str.gsub(/U\+([0-9a-fA-F]{4,4})/u){["#$1".hex ].pack('U*')}
43
+ if __FILE__ == $0
44
+ FXApp.new("ClipboardExample", "FXRuby") do |theApp|
45
+ ClipMainWindow.new(theApp)
46
+ theApp.create
47
+ theApp.run
38
48
  end
39
- end</b></span>
40
-
41
- include Fox
49
+ end
50
+ </pre><p>We're assuming that the "customer" module defines a
51
+ <code class="classname">Customer</code> class and a global array
52
+ <code class="varname">$customers</code> that contains the list of customers. For a
53
+ real world application, you might access this information from a database
54
+ or some other source, but for this example we'll just use a hard-coded
55
+ array:</p><pre class="programlisting"># customer.rb
42
56
 
43
- <span class="bold"><b>question = u'U+00bfHabla espaU+00f1ol?'</b></span>
57
+ Customer = Struct.new("Customer", :name, :address, :zip)
44
58
 
45
- application = FXApp.new("Hello", "FoxTest")
46
- main = FXMainWindow.new(application, "Hello", nil, nil, DECOR_ALL)
47
- FXButton.new(main, <span class="bold"><b>question</b></span>, nil, application, FXApp::ID_QUIT)
48
- application.create()
49
- main.show(PLACEMENT_SCREEN)
50
- application.run()
51
- </pre></td></tr></table><p>The <span class="bold"><b>jcode</b></span> library (part of the
52
- standard Ruby library) provides a number of extensions to Ruby's
53
- <tt class="classname">String</tt> class, to ensure that its methods work
54
- properly for non-ASCII character encodings. By setting the
55
- <tt class="varname">$KCODE</tt> global variable to "u", we're telling Ruby which
56
- character encoding it is that we're using (UTF-8).</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch05s03.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="pt01.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="examples.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Putting It All Together&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Chapter&nbsp;7.&nbsp;Examples</td></tr></table></div></body></html>
59
+ $customers = []
60
+ $customers &lt;&lt; Customer.new("Reed Richards", "123 Maple, Central City, NY", 010111)
61
+ $customers &lt;&lt; Customer.new("Sue Storm", "123 Maple, Anytown, NC", 12345)
62
+ $customers &lt;&lt; Customer.new("Benjamin J. Grimm", "123 Maple, Anytown, NC", 12345)
63
+ $customers &lt;&lt; Customer.new("Johnny Storm", "123 Maple, Anytown, NC", 12345)
64
+ </pre><p>The goals for the next few sections are to extend this application
65
+ so that users can select a customer from the list and copy that customer's
66
+ information to the clipboard, and subsequently paste that information into
67
+ another copy of the program (or some other clipboard-aware
68
+ application).</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s05.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="pt01.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ch04s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Adding an icon&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Acquiring the Clipboard</td></tr></table></div></body></html>
data/doc/cvs.html CHANGED
@@ -1,6 +1,6 @@
1
1
  <html><head>
2
2
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
3
- <title>Appendix&nbsp;F.&nbsp;Getting the Sources from CVS</title><meta name="generator" content="DocBook XSL Stylesheets V1.61.2"><link rel="home" href="book.html" title="Developing Graphical User Interfaces with FXRuby"><link rel="up" href="pt02.html" title="Part&nbsp;II.&nbsp;Appendices"><link rel="previous" href="apes03.html" title="Virtual Functions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Appendix&nbsp;F.&nbsp;Getting the Sources from CVS</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apes03.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;II.&nbsp;Appendices</th><td width="20%" align="right">&nbsp;</td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="cvs"></a>Appendix&nbsp;F.&nbsp;Getting the Sources from CVS</h2></div></div><div></div></div><p>All of the source code for FXRuby is available for anonymous,
3
+ <title>Appendix&nbsp;F.&nbsp;Getting the Sources from CVS</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="book.html" title="Developing Graphical User Interfaces with FXRuby"><link rel="up" href="pt02.html" title="Part&nbsp;II.&nbsp;Appendices"><link rel="prev" href="apes03.html" title="Virtual Functions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Appendix&nbsp;F.&nbsp;Getting the Sources from CVS</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apes03.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;II.&nbsp;Appendices</th><td width="20%" align="right">&nbsp;</td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="cvs"></a>Appendix&nbsp;F.&nbsp;Getting the Sources from CVS</h2></div></div></div><p>All of the source code for FXRuby is available for anonymous,
4
4
  read-only CVS access. This chapter describes how to check out the sources
5
5
  for either the stable or development release of FXRuby and then build FXRuby
6
6
  from those sources. The information in this chapter builds on the basic CVS
@@ -19,17 +19,17 @@
19
19
  modified SWIG interface files. I always use the latest development version
20
20
  of <a href="http://www.swig.org" target="_top">SWIG</a>, but any release after,
21
21
  say, SWIG 1.3.15 should work fine. The older SWIG 1.1 releases will
22
- definitely <span class="emphasis"><em>not</em></span> work.</p><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4834"></a>Checking out the stable version</h2></div></div><div></div></div><p>The stable version of FXRuby is the 1.0.x branch and is compatible
22
+ definitely <span class="emphasis"><em>not</em></span> work.</p><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e5077"></a>Checking out the stable version</h2></div></div></div><p>The stable version of FXRuby is the 1.0.x branch and is compatible
23
23
  with any of the FOX 1.0.x releases. It is <span class="emphasis"><em>not</em></span>
24
24
  compatible with any other release branches of FOX (e.g. the FOX 1.2.x or
25
- 1.3.x series of releases).</p><p>To check out the stable version of FXRuby, do the following:</p><div class="orderedlist"><ol type="1"><li><p>Log in to the CVS server by typing:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="screen">cvs -d:pserver:anonymous@rubyforge.org:/var/cvs/fxruby login</pre></td></tr></table><p>When prompted for a password for <span class="emphasis"><em>anonymous</em></span>,
26
- simply press the <b class="keycap">Enter</b> key.</p></li><li><p>Check out the stable branch of FXRuby by typing:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="screen">cvs -z3 -d:pserver:anonymous@rubyforge.org:/var/cvs/fxruby co -rrelease10 FXRuby</pre></td></tr></table></li></ol></div><p>At this point, you should be ready to change to the top-level
25
+ 1.3.x series of releases).</p><p>To check out the stable version of FXRuby, do the following:</p><div class="orderedlist"><ol type="1"><li><p>Log in to the CVS server by typing:</p><pre class="screen">cvs -d:pserver:anonymous@rubyforge.org:/var/cvs/fxruby login</pre><p>When prompted for a password for <span class="emphasis"><em>anonymous</em></span>,
26
+ simply press the <span><strong class="keycap">Enter</strong></span> key.</p></li><li><p>Check out the stable branch of FXRuby by typing:</p><pre class="screen">cvs -z3 -d:pserver:anonymous@rubyforge.org:/var/cvs/fxruby co -rrelease10 FXRuby</pre></li></ol></div><p>At this point, you should be ready to change to the top-level
27
27
  directory and go through the normal build and installation process, as
28
- described in an earlier chapter.</p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4867"></a>Regenerating wrapper code with SWIG</h2></div></div><div></div></div><p>If you make changes to any of the SWIG interface files (the files
29
- ending with a <tt class="filename">.i</tt> extension, in the <tt class="filename">swig-interfaces</tt> subdirectory) you will need
30
- to re-run SWIG to regenerate parts of the FXRuby source code:</p><div class="orderedlist"><ol type="1"><li><p>Change directories to the <tt class="filename">swig-interfaces</tt> subdirectory of the
28
+ described in an earlier chapter.</p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e5110"></a>Regenerating wrapper code with SWIG</h2></div></div></div><p>If you make changes to any of the SWIG interface files (the files
29
+ ending with a <code class="filename">.i</code> extension, in the <code class="filename">swig-interfaces</code> subdirectory) you will need
30
+ to re-run SWIG to regenerate parts of the FXRuby source code:</p><div class="orderedlist"><ol type="1"><li><p>Change directories to the <code class="filename">swig-interfaces</code> subdirectory of the
31
31
  FXRuby source tree.</p></li><li><p>Type the following command to create a "bootstrap"
32
- <tt class="filename">dependencies</tt> file:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="screen">touch dependencies</pre></td></tr></table><p>You should only need to do this for the initial checkout of the
33
- sources; after that, the <tt class="filename">dependencies</tt> file will
32
+ <code class="filename">dependencies</code> file:</p><pre class="screen">touch dependencies</pre><p>You should only need to do this for the initial checkout of the
33
+ sources; after that, the <code class="filename">dependencies</code> file will
34
34
  be updated as described in the next step.</p></li><li><p>Build the "depend" target to generate the real
35
- <tt class="filename">dependencies</tt> file by typing:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="screen">make depend</pre></td></tr></table></li><li><p>Finally, regenerate the sources by typing:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="screen">make</pre></td></tr></table></li></ol></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apes03.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="pt02.html">Up</a></td><td width="40%" align="right">&nbsp;</td></tr><tr><td width="40%" align="left" valign="top">Virtual Functions&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;</td></tr></table></div></body></html>
35
+ <code class="filename">dependencies</code> file by typing:</p><pre class="screen">make depend</pre></li><li><p>Finally, regenerate the sources by typing:</p><pre class="screen">make</pre></li></ol></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apes03.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="pt02.html">Up</a></td><td width="40%" align="right">&nbsp;</td></tr><tr><td width="40%" align="left" valign="top">Virtual Functions&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;</td></tr></table></div></body></html>
data/doc/differences.html CHANGED
@@ -1,11 +1,11 @@
1
1
  <html><head>
2
2
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
3
- <title>Appendix&nbsp;C.&nbsp;Differences between FOX and FXRuby</title><meta name="generator" content="DocBook XSL Stylesheets V1.61.2"><link rel="home" href="book.html" title="Developing Graphical User Interfaces with FXRuby"><link rel="up" href="pt02.html" title="Part&nbsp;II.&nbsp;Appendices"><link rel="previous" href="scintilla.html" title="Appendix&nbsp;B.&nbsp;Using Scintilla with FXRuby"><link rel="next" href="library.html" title="Appendix&nbsp;D.&nbsp;The FXRuby Standard Library"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Appendix&nbsp;C.&nbsp;Differences between FOX and FXRuby</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="scintilla.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;II.&nbsp;Appendices</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="library.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="differences"></a>Appendix&nbsp;C.&nbsp;Differences between FOX and FXRuby</h2></div></div><div></div></div><p>The FXRuby API follows the FOX API very closely and for the most part, you should be able to use the standard FOX class documentation as a reference. In some cases, however, fundamental differences between Ruby and C++ necessitated slight changes in the API. For some other cases, FOX classes were enhanced to take advantage of Ruby language features (such as iterators). The purpose of this chapter is to identify some of the differences between the C++ and Ruby interfaces to FOX.</p><p>One difference that should be easy to cope with is the substitution of Ruby Strings for FXStrings. Any function that would normally expect an <span class="type">FXString</span> input argument insteads takes a Ruby String. Similarly, functions that would return an <span class="type">FXString</span> will instead return a Ruby string. For functions that would normally accept a <tt class="constant">NULL</tt> or empty string argument, just pass <tt class="constant">nil</tt> or an empty string ("").</p><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3915"></a>Functions that expect arrays of objects</h2></div></div><div></div></div><p>One common pattern in FOX member function argument lists is to expect a pointer to an array of values, followed by an integer indicating the number of values in the array. This of course isn't necessary in Ruby, where <tt class="classname">Array</tt> objects "know" their lengths. As a result, functions such as <tt class="methodname">FXWindow::acquireClipboard()</tt>, whose C++ declaration looks like this:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">FXbool acquireClipboard(const FXDragType *types, FXuint numTypes);</pre></td></tr></table><p>are called from Ruby code by passing in a single <tt class="classname">Array</tt> argument, e.g.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">myWindow.acquireClipboard(typesArray)</pre></td></tr></table></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3935"></a>Functions that return values by reference</h2></div></div><div></div></div><p>Many FOX methods take advantage of the C++ language feature of returning values by reference. For example, the <tt class="methodname">getCursorPos()</tt> member function for class <tt class="classname">FXWindow</tt> has the declaration:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">FXint getCursorPos(FXint&amp; x, FXint&amp; y, FXint&amp; buttons) const;</pre></td></tr></table><p>which indicates that the function takes references to three integers (x, y and buttons). To call this function from a C++ program, you'd write code like this:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">FXint x, y;
3
+ <title>Appendix&nbsp;C.&nbsp;Differences between FOX and FXRuby</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="book.html" title="Developing Graphical User Interfaces with FXRuby"><link rel="up" href="pt02.html" title="Part&nbsp;II.&nbsp;Appendices"><link rel="prev" href="scintilla.html" title="Appendix&nbsp;B.&nbsp;Using Scintilla with FXRuby"><link rel="next" href="library.html" title="Appendix&nbsp;D.&nbsp;The FXRuby Standard Library"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Appendix&nbsp;C.&nbsp;Differences between FOX and FXRuby</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="scintilla.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;II.&nbsp;Appendices</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="library.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="differences"></a>Appendix&nbsp;C.&nbsp;Differences between FOX and FXRuby</h2></div></div></div><p>The FXRuby API follows the FOX API very closely and for the most part, you should be able to use the standard FOX class documentation as a reference. In some cases, however, fundamental differences between Ruby and C++ necessitated slight changes in the API. For some other cases, FOX classes were enhanced to take advantage of Ruby language features (such as iterators). The purpose of this chapter is to identify some of the differences between the C++ and Ruby interfaces to FOX.</p><p>One difference that should be easy to cope with is the substitution of Ruby Strings for FXStrings. Any function that would normally expect an <span class="type">FXString</span> input argument insteads takes a Ruby String. Similarly, functions that would return an <span class="type">FXString</span> will instead return a Ruby string. For functions that would normally accept a <code class="constant">NULL</code> or empty string argument, just pass <code class="constant">nil</code> or an empty string ("").</p><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4158"></a>Functions that expect arrays of objects</h2></div></div></div><p>One common pattern in FOX member function argument lists is to expect a pointer to an array of values, followed by an integer indicating the number of values in the array. This of course isn't necessary in Ruby, where <code class="classname">Array</code> objects "know" their lengths. As a result, functions such as <code class="methodname">FXWindow::acquireClipboard()</code>, whose C++ declaration looks like this:</p><pre class="programlisting">FXbool acquireClipboard(const FXDragType *types, FXuint numTypes);</pre><p>are called from Ruby code by passing in a single <code class="classname">Array</code> argument, e.g.</p><pre class="programlisting">myWindow.acquireClipboard(typesArray)</pre></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4178"></a>Functions that return values by reference</h2></div></div></div><p>Many FOX methods take advantage of the C++ language feature of returning values by reference. For example, the <code class="methodname">getCursorPos()</code> member function for class <code class="classname">FXWindow</code> has the declaration:</p><pre class="programlisting">FXint getCursorPos(FXint&amp; x, FXint&amp; y, FXint&amp; buttons) const;</pre><p>which indicates that the function takes references to three integers (x, y and buttons). To call this function from a C++ program, you'd write code like this:</p><pre class="programlisting">FXint x, y;
4
4
  FXuint buttons;
5
5
 
6
6
  if (window-&gt;getCursorPosition(x, y, buttons))
7
- fprintf(stderr, "Current position is (%d, %d)\n", x, y);</pre></td></tr></table><p>Since this idiom doesn't translate well to Ruby, some functions' interfaces have been slightly modified. For example, the FXRuby implementation of <tt class="methodname">getCursorPos()</tt> returns the three values as an <tt class="classname">Array</tt>, e.g.:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">x, y, buttons = aWindow.getCursorPos()</pre></td></tr></table><p>The following table shows how these kinds of functions are implemented in FXRuby:</p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><thead><tr><th align="center">Instance Method</th><th align="center">Return Value</th></tr></thead><tbody><tr><td><tt class="methodname">FXDial#range</tt></td><td>Returns a <tt class="classname">Range</tt> instance.</td></tr><tr><td><tt class="methodname">FXDial#range=(aRange)</tt></td><td>Accepts a <tt class="classname">Range</tt> instance as its input.</td></tr><tr><td><tt class="methodname">FXFontDialog#fontSelection</tt></td><td>Returns the <tt class="classname">FXFontDesc</tt> instance</td></tr><tr><td><tt class="methodname">FXFontSelector#fontSelection</tt></td><td>Returns the <tt class="classname">FXFontDesc</tt> instance</td></tr><tr><td><tt class="methodname">FXGLObject#bounds(range)</tt></td><td>Takes an <tt class="classname">FXRange</tt> instance as its input and returns a (possibly modified) <tt class="classname">FXRange</tt> instance.</td></tr><tr><td><tt class="methodname">FXGLViewer#eyeToScreen(eye)</tt></td><td>Takes an array of eye coordinates (floats) as its input and returns the screen point coordinate as an array of integers [sx, sy]</td></tr><tr><td><tt class="methodname">FXGLViewer#getBoreVector(sx, sy)</tt></td><td>Returns the endpoint and direction vector as an array of arrays [point, dir]</td></tr><tr><td><tt class="methodname">FXGLViewer#light</tt></td><td>Returns a <tt class="classname">FXLight</tt> instance</td></tr><tr><td><tt class="methodname">FXGLViewer#viewport</tt></td><td>Returns an <tt class="classname">FXViewport</tt> instance.</td></tr><tr><td><tt class="methodname">FXPrinterDialog#printer</tt></td><td>Returns the <tt class="classname">FXPrinter</tt> instance</td></tr><tr><td><tt class="methodname">FXScrollArea#position</tt></td><td>Returns the position as an array of integers [x, y]</td></tr><tr><td><tt class="methodname">FXSlider#range</tt></td><td>Returns a <tt class="classname">Range</tt> instance.</td></tr><tr><td><tt class="methodname">FXSlider#range=(aRange)</tt></td><td>Accepts a <tt class="classname">Range</tt> instance as its input.</td></tr><tr><td><tt class="methodname">FXSpinner#range</tt></td><td>Returns a <tt class="classname">Range</tt> instance.</td></tr><tr><td><tt class="methodname">FXSpinner#range=(aRange)</tt></td><td>Accepts a <tt class="classname">Range</tt> instance as its input.</td></tr><tr><td><tt class="methodname">FXText#appendText(text, notify=false)</tt></td><td>Append text to the end of the buffer.</td></tr><tr><td><tt class="methodname">FXText#appendStyledText(text, style=0, notify=false)</tt></td><td>Append styled text to the end of the buffer.</td></tr><tr><td><tt class="methodname">FXText#extractText(pos, n)</tt></td><td>Extracts <span class="emphasis"><em>n</em></span> characters from the buffer beginning at position <span class="emphasis"><em>pos</em></span> and returns the result as a String.</td></tr><tr><td><tt class="methodname">FXText#extractStyle(pos, n)</tt></td><td>Extracts <span class="emphasis"><em>n</em></span> style characters from the buffer beginning at position <span class="emphasis"><em>pos</em></span> and returns the result as a String.</td></tr><tr><td><tt class="methodname">FXText#insertText(pos, text, notify=false)</tt></td><td>Insert <span class="emphasis"><em>text</em></span> at position <span class="emphasis"><em>pos</em></span> in the buffer.</td></tr><tr><td><tt class="methodname">FXText#insertStyledText(pos, text, style=0, notify=false)</tt></td><td>Insert <span class="emphasis"><em>text</em></span> at position <span class="emphasis"><em>pos</em></span> in the buffer.</td></tr><tr><td><tt class="methodname">FXText#replaceText(pos, m, text, notify=false)</tt></td><td>Replace <span class="emphasis"><em>m</em></span> characters at <span class="emphasis"><em>pos</em></span> by <span class="emphasis"><em>text</em></span>.</td></tr><tr><td><tt class="methodname">FXText#replaceStyledText(pos, m, text, style=0, notify=false)</tt></td><td>Replace <span class="emphasis"><em>m</em></span> characters at <span class="emphasis"><em>pos</em></span> by <span class="emphasis"><em>text</em></span>.</td></tr><tr><td><tt class="methodname">FXText#setDelimiters(delimiters)</tt></td><td>Change delimiters of words (<span class="emphasis"><em>delimiters</em></span> is a string).</td></tr><tr><td><tt class="methodname">FXText#getDelimiters()</tt></td><td>Return word delimiters as a string.</td></tr><tr><td><tt class="methodname">FXWindow#cursorPosition</tt></td><td>Returns an array of integers [x, y, buttons]</td></tr><tr><td><tt class="methodname">FXWindow#translateCoordinatesFrom(window, x, y)</tt></td><td>Returns the translated coordinates as an array [x, y]</td></tr><tr><td><tt class="methodname">FXWindow#translateCoordinatesTo(window, x, y)</tt></td><td>Returns the translated coordinates as an array [x, y]</td></tr></tbody></table></div></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4225"></a>Iterators</h2></div></div><div></div></div><p>Several classes have been extended with an <tt class="methodname">each</tt> method to provide Ruby-style iterators. These classes include <tt class="classname">FXComboBox</tt>, <tt class="classname">FXGLGroup</tt>, <tt class="classname">FXHeader</tt>, <tt class="classname">FXIconList</tt>, <tt class="classname">FXList</tt>, <tt class="classname">FXListBox</tt>, <tt class="classname">FXTreeItem</tt>, <tt class="classname">FXTreeList</tt> and <tt class="classname">FXTreeListBox</tt>. These classes also mix-in Ruby's <tt class="classname">Enumerable</tt> module so that you can take full advantage of the iterators.</p><p>The block parameters passed to your code block vary depending on the class. For example, iterating over an <tt class="classname">FXList</tt> instance yields <tt class="classname">FXListItem</tt> parameters:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">aList.each { |aListItem|
7
+ fprintf(stderr, "Current position is (%d, %d)\n", x, y);</pre><p>Since this idiom doesn't translate well to Ruby, some functions' interfaces have been slightly modified. For example, the FXRuby implementation of <code class="methodname">getCursorPos()</code> returns the three values as an <code class="classname">Array</code>, e.g.:</p><pre class="programlisting">x, y, buttons = aWindow.getCursorPos()</pre><p>The following table shows how these kinds of functions are implemented in FXRuby:</p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><thead><tr><th align="center">Instance Method</th><th align="center">Return Value</th></tr></thead><tbody><tr><td><code class="methodname">FXDial#range</code></td><td>Returns a <code class="classname">Range</code> instance.</td></tr><tr><td><code class="methodname">FXDial#range=(aRange)</code></td><td>Accepts a <code class="classname">Range</code> instance as its input.</td></tr><tr><td><code class="methodname">FXFontDialog#fontSelection</code></td><td>Returns the <code class="classname">FXFontDesc</code> instance</td></tr><tr><td><code class="methodname">FXFontSelector#fontSelection</code></td><td>Returns the <code class="classname">FXFontDesc</code> instance</td></tr><tr><td><code class="methodname">FXGLObject#bounds(range)</code></td><td>Takes an <code class="classname">FXRange</code> instance as its input and returns a (possibly modified) <code class="classname">FXRange</code> instance.</td></tr><tr><td><code class="methodname">FXGLViewer#eyeToScreen(eye)</code></td><td>Takes an array of eye coordinates (floats) as its input and returns the screen point coordinate as an array of integers [sx, sy]</td></tr><tr><td><code class="methodname">FXGLViewer#getBoreVector(sx, sy)</code></td><td>Returns the endpoint and direction vector as an array of arrays [point, dir]</td></tr><tr><td><code class="methodname">FXGLViewer#light</code></td><td>Returns a <code class="classname">FXLight</code> instance</td></tr><tr><td><code class="methodname">FXGLViewer#viewport</code></td><td>Returns an <code class="classname">FXViewport</code> instance.</td></tr><tr><td><code class="methodname">FXPrinterDialog#printer</code></td><td>Returns the <code class="classname">FXPrinter</code> instance</td></tr><tr><td><code class="methodname">FXScrollArea#position</code></td><td>Returns the position as an array of integers [x, y]</td></tr><tr><td><code class="methodname">FXSlider#range</code></td><td>Returns a <code class="classname">Range</code> instance.</td></tr><tr><td><code class="methodname">FXSlider#range=(aRange)</code></td><td>Accepts a <code class="classname">Range</code> instance as its input.</td></tr><tr><td><code class="methodname">FXSpinner#range</code></td><td>Returns a <code class="classname">Range</code> instance.</td></tr><tr><td><code class="methodname">FXSpinner#range=(aRange)</code></td><td>Accepts a <code class="classname">Range</code> instance as its input.</td></tr><tr><td><code class="methodname">FXText#appendText(text, notify=false)</code></td><td>Append text to the end of the buffer.</td></tr><tr><td><code class="methodname">FXText#appendStyledText(text, style=0, notify=false)</code></td><td>Append styled text to the end of the buffer.</td></tr><tr><td><code class="methodname">FXText#extractText(pos, n)</code></td><td>Extracts <span class="emphasis"><em>n</em></span> characters from the buffer beginning at position <span class="emphasis"><em>pos</em></span> and returns the result as a String.</td></tr><tr><td><code class="methodname">FXText#extractStyle(pos, n)</code></td><td>Extracts <span class="emphasis"><em>n</em></span> style characters from the buffer beginning at position <span class="emphasis"><em>pos</em></span> and returns the result as a String.</td></tr><tr><td><code class="methodname">FXText#insertText(pos, text, notify=false)</code></td><td>Insert <span class="emphasis"><em>text</em></span> at position <span class="emphasis"><em>pos</em></span> in the buffer.</td></tr><tr><td><code class="methodname">FXText#insertStyledText(pos, text, style=0, notify=false)</code></td><td>Insert <span class="emphasis"><em>text</em></span> at position <span class="emphasis"><em>pos</em></span> in the buffer.</td></tr><tr><td><code class="methodname">FXText#replaceText(pos, m, text, notify=false)</code></td><td>Replace <span class="emphasis"><em>m</em></span> characters at <span class="emphasis"><em>pos</em></span> by <span class="emphasis"><em>text</em></span>.</td></tr><tr><td><code class="methodname">FXText#replaceStyledText(pos, m, text, style=0, notify=false)</code></td><td>Replace <span class="emphasis"><em>m</em></span> characters at <span class="emphasis"><em>pos</em></span> by <span class="emphasis"><em>text</em></span>.</td></tr><tr><td><code class="methodname">FXText#setDelimiters(delimiters)</code></td><td>Change delimiters of words (<span class="emphasis"><em>delimiters</em></span> is a string).</td></tr><tr><td><code class="methodname">FXText#getDelimiters()</code></td><td>Return word delimiters as a string.</td></tr><tr><td><code class="methodname">FXWindow#cursorPosition</code></td><td>Returns an array of integers [x, y, buttons]</td></tr><tr><td><code class="methodname">FXWindow#translateCoordinatesFrom(window, x, y)</code></td><td>Returns the translated coordinates as an array [x, y]</td></tr><tr><td><code class="methodname">FXWindow#translateCoordinatesTo(window, x, y)</code></td><td>Returns the translated coordinates as an array [x, y]</td></tr></tbody></table></div></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4468"></a>Iterators</h2></div></div></div><p>Several classes have been extended with an <code class="methodname">each</code> method to provide Ruby-style iterators. These classes include <code class="classname">FXComboBox</code>, <code class="classname">FXGLGroup</code>, <code class="classname">FXHeader</code>, <code class="classname">FXIconList</code>, <code class="classname">FXList</code>, <code class="classname">FXListBox</code>, <code class="classname">FXTreeItem</code>, <code class="classname">FXTreeList</code> and <code class="classname">FXTreeListBox</code>. These classes also mix-in Ruby's <code class="classname">Enumerable</code> module so that you can take full advantage of the iterators.</p><p>The block parameters passed to your code block vary depending on the class. For example, iterating over an <code class="classname">FXList</code> instance yields <code class="classname">FXListItem</code> parameters:</p><pre class="programlisting">aList.each { |aListItem|
8
8
  puts "text for this item = #{aListItem.getText()}"
9
- }</pre></td></tr></table><p>whereas iterating over an <tt class="classname">FXComboBox</tt> instance yields two parameters, the item text (a string) and the item data:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">aComboBox.each { |itemText, itemData|
9
+ }</pre><p>whereas iterating over an <code class="classname">FXComboBox</code> instance yields two parameters, the item text (a string) and the item data:</p><pre class="programlisting">aComboBox.each { |itemText, itemData|
10
10
  puts "text for this item = #{itemText}"
11
- }</pre></td></tr></table><p>The following table shows the block parameters for each of these classes' iterators:</p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><thead><tr><th align="center">Class</th><th align="center">Block Parameters</th></tr></thead><tbody><tr><td><tt class="classname">FXComboBox</tt></td><td>the item text (a string) and user data</td></tr><tr><td><tt class="classname">FXGLGroup</tt></td><td>an <tt class="classname">FXGLObject</tt> instance</td></tr><tr><td><tt class="classname">FXHeader</tt></td><td>an <tt class="classname">FXHeaderItem</tt> instance</td></tr><tr><td><tt class="classname">FXIconList</tt></td><td>an <tt class="classname">FXIconItem</tt> instance</td></tr><tr><td><tt class="classname">FXList</tt></td><td>an <tt class="classname">FXListItem</tt> instance</td></tr><tr><td><tt class="classname">FXListBox</tt></td><td>the item text (a string), icon (an <tt class="classname">FXIcon</tt> instance) and user data</td></tr><tr><td><tt class="classname">FXTreeItem</tt></td><td>an <tt class="classname">FXTreeItem</tt> instance</td></tr><tr><td><tt class="classname">FXTreeList</tt></td><td>an <tt class="classname">FXTreeItem</tt> instance</td></tr><tr><td><tt class="classname">FXTreeListBox</tt></td><td>an <tt class="classname">FXTreeItem</tt> instance</td></tr></tbody></table></div></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4369"></a>Attribute Accessors</h2></div></div><div></div></div><p>FOX strictly handles access to all object attributes through member functions, e.g. <tt class="methodname">setBackgroundColor</tt> and <tt class="methodname">getBackgroundColor</tt> or <tt class="methodname">setText</tt> and <tt class="methodname">getText</tt>. FXRuby exposes all of these functions but also provides aliases that look more like regular Ruby attribute accessors. The names for these accessors are based on the FOX method names; for example, <tt class="methodname">setBackgroundColor</tt> and <tt class="methodname">getBackgroundColor</tt> are aliased to <tt class="methodname">backgroundColor=</tt> and <tt class="methodname">backgroundColor</tt>, respectively.</p><p>In many cases these aliases allow you to write more compact and legible code. For example, consider this code snippet:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">aLabel.setText(aLabel.getText() + " (modified)")</pre></td></tr></table><p>Now consider a different code snippet, using the aliased accessor method names:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">aLabel.text += " (modified)"</pre></td></tr></table><p>While these two are functionally equivalent, the latter is a bit easier to read and understand at first glance.</p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4408"></a>Message Passing</h2></div></div><div></div></div><p>FOX message maps are implemented as static C++ class members. With FXRuby, you just associate messages with message handlers in the class <tt class="methodname">initialize</tt> method using the <tt class="methodname">FXMAPFUNC()</tt>, <tt class="methodname">FXMAPTYPE()</tt>, <tt class="methodname">FXMAPTYPES()</tt> or <tt class="methodname">FXMAPFUNCS()</tt> methods. See almost any of the example programs for examples of how this is done.</p><p>As in C++ FOX, the last argument passed to your message handler functions contains message-specific data. For instance, all <tt class="constant">SEL_PAINT</tt> messages pass an <tt class="classname">FXEvent</tt> object through this argument to give you some information about the size of the exposed rectangle. On the other hand, a <tt class="constant">SEL_COMMAND</tt> message from an <tt class="classname">FXHeader</tt> object passes the index of the selected header item through this argument. Instead of guessing what's in this last argument, your best bet is to instead invoke a member function on the sending object to find out what you need, instead of relying on the data passed through this pointer. For example, if you get a <tt class="constant">SEL_COMMAND</tt> message from an <tt class="classname">FXColorWell</tt> object, the data passed through that last argument is supposed to be the new RGB color value. Instead of trying to interpret the argument's contents, just turn around and call the color well's <tt class="methodname">getRGBA()</tt> member function to retrieve its color. Similarly, if you get a <tt class="constant">SEL_COMMAND</tt> message from a tree list, call its <tt class="methodname">getCurrentItem()</tt> method to find out which item was selected.</p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4457"></a>Catching Operating System Signals</h2></div></div><div></div></div><p>The <tt class="methodname">FXApp#addSignal</tt> and <tt class="methodname">FXApp#removeSignal</tt> methods have been enhanced to accept either a string or integer as their first argument. If it's a string (e.g. "SIGINT" or just "INT") the code will determine the corresponding signal number for you (similar to the standard Ruby library's <tt class="methodname">Process.kill</tt> module method). For examples of how to use this, see the <tt class="filename">datatarget.rb</tt> or <tt class="filename">imageviewer.rb</tt> example programs.</p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4477"></a>Support for Multithreaded Applications</h2></div></div><div></div></div><p>There is some support for multithreaded FXRuby applications, but it's not wonderful. The current implementation does what is also done in Ruby/GTK; it turns over some idle processing time to the Ruby thread scheduler to let other threads do their thing. As I learn more about Ruby's threading implementation I may try something different, but this seems to work OK for now. For a simple example, see the <tt class="filename">groupbox.rb</tt> example program, in which the clock label that appears in the lower right-hand corner is continuously updated (by a separate thread).</p><p>If you suspect that FXRuby's threads support is interfering with your application's performance, you may want to try tweaking the amount of time that the main application thread "sleeps" during idle processing; do this by setting the <tt class="classname">FXApp</tt> object's <i class="structfield"><tt>sleepTime</tt></i> attribute. The default value for <i class="structfield"><tt>FXApp#sleepTime</tt></i> is 100 milliseconds. You can also disable the threads support completely by calling <tt class="methodname">FXApp#threadsEnabled=false</tt> (and subsequently re-enable it with <tt class="methodname">FXApp#threadsEnabled=true</tt>).</p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4502"></a>Debugging Tricks</h2></div></div><div></div></div><p>As a debugging tool, you can optionally catch exceptions raised in message handlers. To turn on this feature, call the <tt class="methodname">setIgnoreExceptions(true)</tt> module method. When this is enabled, any exceptions raised in message handler functions will cause a standard stack trace to be dumped to the standard output, but then your application will, for better or worse, proceed normally. Thanks to Ted Meng for this suggestion.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="scintilla.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="pt02.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="library.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Appendix&nbsp;B.&nbsp;Using Scintilla with FXRuby&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Appendix&nbsp;D.&nbsp;The FXRuby Standard Library</td></tr></table></div></body></html>
11
+ }</pre><p>The following table shows the block parameters for each of these classes' iterators:</p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><thead><tr><th align="center">Class</th><th align="center">Block Parameters</th></tr></thead><tbody><tr><td><code class="classname">FXComboBox</code></td><td>the item text (a string) and user data</td></tr><tr><td><code class="classname">FXGLGroup</code></td><td>an <code class="classname">FXGLObject</code> instance</td></tr><tr><td><code class="classname">FXHeader</code></td><td>an <code class="classname">FXHeaderItem</code> instance</td></tr><tr><td><code class="classname">FXIconList</code></td><td>an <code class="classname">FXIconItem</code> instance</td></tr><tr><td><code class="classname">FXList</code></td><td>an <code class="classname">FXListItem</code> instance</td></tr><tr><td><code class="classname">FXListBox</code></td><td>the item text (a string), icon (an <code class="classname">FXIcon</code> instance) and user data</td></tr><tr><td><code class="classname">FXTreeItem</code></td><td>an <code class="classname">FXTreeItem</code> instance</td></tr><tr><td><code class="classname">FXTreeList</code></td><td>an <code class="classname">FXTreeItem</code> instance</td></tr><tr><td><code class="classname">FXTreeListBox</code></td><td>an <code class="classname">FXTreeItem</code> instance</td></tr></tbody></table></div></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4612"></a>Attribute Accessors</h2></div></div></div><p>FOX strictly handles access to all object attributes through member functions, e.g. <code class="methodname">setBackgroundColor</code> and <code class="methodname">getBackgroundColor</code> or <code class="methodname">setText</code> and <code class="methodname">getText</code>. FXRuby exposes all of these functions but also provides aliases that look more like regular Ruby attribute accessors. The names for these accessors are based on the FOX method names; for example, <code class="methodname">setBackgroundColor</code> and <code class="methodname">getBackgroundColor</code> are aliased to <code class="methodname">backgroundColor=</code> and <code class="methodname">backgroundColor</code>, respectively.</p><p>In many cases these aliases allow you to write more compact and legible code. For example, consider this code snippet:</p><pre class="programlisting">aLabel.setText(aLabel.getText() + " (modified)")</pre><p>Now consider a different code snippet, using the aliased accessor method names:</p><pre class="programlisting">aLabel.text += " (modified)"</pre><p>While these two are functionally equivalent, the latter is a bit easier to read and understand at first glance.</p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4651"></a>Message Passing</h2></div></div></div><p>FOX message maps are implemented as static C++ class members. With FXRuby, you just associate messages with message handlers in the class <code class="methodname">initialize</code> method using the <code class="methodname">FXMAPFUNC()</code>, <code class="methodname">FXMAPTYPE()</code>, <code class="methodname">FXMAPTYPES()</code> or <code class="methodname">FXMAPFUNCS()</code> methods. See almost any of the example programs for examples of how this is done.</p><p>As in C++ FOX, the last argument passed to your message handler functions contains message-specific data. For instance, all <code class="constant">SEL_PAINT</code> messages pass an <code class="classname">FXEvent</code> object through this argument to give you some information about the size of the exposed rectangle. On the other hand, a <code class="constant">SEL_COMMAND</code> message from an <code class="classname">FXHeader</code> object passes the index of the selected header item through this argument. Instead of guessing what's in this last argument, your best bet is to instead invoke a member function on the sending object to find out what you need, instead of relying on the data passed through this pointer. For example, if you get a <code class="constant">SEL_COMMAND</code> message from an <code class="classname">FXColorWell</code> object, the data passed through that last argument is supposed to be the new RGB color value. Instead of trying to interpret the argument's contents, just turn around and call the color well's <code class="methodname">getRGBA()</code> member function to retrieve its color. Similarly, if you get a <code class="constant">SEL_COMMAND</code> message from a tree list, call its <code class="methodname">getCurrentItem()</code> method to find out which item was selected.</p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4700"></a>Catching Operating System Signals</h2></div></div></div><p>The <code class="methodname">FXApp#addSignal</code> and <code class="methodname">FXApp#removeSignal</code> methods have been enhanced to accept either a string or integer as their first argument. If it's a string (e.g. "SIGINT" or just "INT") the code will determine the corresponding signal number for you (similar to the standard Ruby library's <code class="methodname">Process.kill</code> module method). For examples of how to use this, see the <code class="filename">datatarget.rb</code> or <code class="filename">imageviewer.rb</code> example programs.</p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4720"></a>Support for Multithreaded Applications</h2></div></div></div><p>There is some support for multithreaded FXRuby applications, but it's not wonderful. The current implementation does what is also done in Ruby/GTK; it turns over some idle processing time to the Ruby thread scheduler to let other threads do their thing. As I learn more about Ruby's threading implementation I may try something different, but this seems to work OK for now. For a simple example, see the <code class="filename">groupbox.rb</code> example program, in which the clock label that appears in the lower right-hand corner is continuously updated (by a separate thread).</p><p>If you suspect that FXRuby's threads support is interfering with your application's performance, you may want to try tweaking the amount of time that the main application thread "sleeps" during idle processing; do this by setting the <code class="classname">FXApp</code> object's <em class="structfield"><code>sleepTime</code></em> attribute. The default value for <em class="structfield"><code>FXApp#sleepTime</code></em> is 100 milliseconds. You can also disable the threads support completely by calling <code class="methodname">FXApp#threadsEnabled=false</code> (and subsequently re-enable it with <code class="methodname">FXApp#threadsEnabled=true</code>).</p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e4745"></a>Debugging Tricks</h2></div></div></div><p>As a debugging tool, you can optionally catch exceptions raised in message handlers. To turn on this feature, call the <code class="methodname">setIgnoreExceptions(true)</code> module method. When this is enabled, any exceptions raised in message handler functions will cause a standard stack trace to be dumped to the standard output, but then your application will, for better or worse, proceed normally. Thanks to Ted Meng for this suggestion.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="scintilla.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="pt02.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="library.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Appendix&nbsp;B.&nbsp;Using Scintilla with FXRuby&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Appendix&nbsp;D.&nbsp;The FXRuby Standard Library</td></tr></table></div></body></html>
data/doc/dragdroptut.html CHANGED
@@ -1,11 +1,11 @@
1
1
  <html><head>
2
2
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
3
- <title>Chapter&nbsp;5.&nbsp;Drag and Drop</title><meta name="generator" content="DocBook XSL Stylesheets V1.61.2"><link rel="home" href="book.html" title="Developing Graphical User Interfaces with FXRuby"><link rel="up" href="pt01.html" title="Part&nbsp;I.&nbsp;The Basics"><link rel="previous" href="ch04s04.html" title="Pasting Data from the Clipboard"><link rel="next" href="ch05s02.html" title="Drag Sources"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&nbsp;5.&nbsp;Drag and Drop</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04s04.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;I.&nbsp;The Basics</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ch05s02.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="dragdroptut"></a>Chapter&nbsp;5.&nbsp;Drag and Drop</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="dragdroptut.html#d0e1201">Drop Sites</a></dt><dt><a href="ch05s02.html">Drag Sources</a></dt><dt><a href="ch05s03.html">Putting It All Together</a></dt></dl></div><p>One of the more powerful features available to FOX applications is
3
+ <title>Chapter&nbsp;5.&nbsp;Drag and Drop</title><link rel="stylesheet" href="style.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="book.html" title="Developing Graphical User Interfaces with FXRuby"><link rel="up" href="pt01.html" title="Part&nbsp;I.&nbsp;The Basics"><link rel="prev" href="ch04s04.html" title="Pasting Data from the Clipboard"><link rel="next" href="ch05s02.html" title="Drag Sources"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&nbsp;5.&nbsp;Drag and Drop</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04s04.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;I.&nbsp;The Basics</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ch05s02.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="dragdroptut"></a>Chapter&nbsp;5.&nbsp;Drag and Drop</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="dragdroptut.html#d0e1201">Drop Sites</a></span></dt><dt><span class="section"><a href="ch05s02.html">Drag Sources</a></span></dt><dt><span class="section"><a href="ch05s03.html">Putting It All Together</a></span></dt></dl></div><p>One of the more powerful features available to FOX applications is
4
4
  drag-and-drop. It's also one of the more complicated to understand. For more
5
5
  background, see the standard FOX documentation on <a href="http://www.fox-toolkit.com/draganddrop.html" target="_top">Drag and
6
- Drop</a>.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1201"></a>Drop Sites</h2></div></div><div></div></div><p>We're going to start by presenting a skeleton application consisting
7
- of a main window widget (a <tt class="classname">DropSite</tt> instance) that
8
- parents an <tt class="classname">FXCanvas</tt> widget:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">require 'rubygems'
6
+ Drop</a>.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1201"></a>Drop Sites</h2></div></div></div><p>We're going to start by presenting a skeleton application consisting
7
+ of a main window widget (a <code class="classname">DropSite</code> instance) that
8
+ parents an <code class="classname">FXCanvas</code> widget:</p><pre class="programlisting">require 'rubygems'
9
9
  require_gem 'fxruby'
10
10
 
11
11
  include Fox
@@ -35,13 +35,13 @@ if __FILE__ == $0
35
35
  theApp.run
36
36
  end
37
37
  end
38
- </pre></td></tr></table><p>Since the main program (i.e. the part at the end) won't change for
38
+ </pre><p>Since the main program (i.e. the part at the end) won't change for
39
39
  the rest of the tutorial, I won't show that code anymore. Since an
40
- <tt class="classname">FXCanvas</tt> widget relies on some other object (its
40
+ <code class="classname">FXCanvas</code> widget relies on some other object (its
41
41
  message target) to draw its contents, we need to handle
42
- <tt class="constant">SEL_PAINT</tt> messages generated by the canvas. We'll do
42
+ <code class="constant">SEL_PAINT</code> messages generated by the canvas. We'll do
43
43
  that by adding a handler that clears the canvas to its current background
44
- color:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">require 'rubygems'
44
+ color:</p><pre class="programlisting">require 'rubygems'
45
45
  require_gem 'fxruby'
46
46
 
47
47
  include Fox
@@ -54,13 +54,13 @@ class DropSite &lt; FXMainWindow
54
54
  # Fill main window with canvas
55
55
  @canvas = FXCanvas.new(self, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y)
56
56
 
57
- <span class="bold"><b> # Handle expose events on the canvas
57
+ <span class="bold"><strong> # Handle expose events on the canvas
58
58
  @canvas.connect(SEL_PAINT) { |sender, sel, event|
59
59
  FXDCWindow.new(@canvas, event) { |dc|
60
60
  dc.foreground = @canvas.backColor
61
61
  dc.fillRectangle(event.rect.x, event.rect.y, event.rect.w, event.rect.h)
62
62
  }
63
- }</b></span>
63
+ }</strong></span>
64
64
  end
65
65
 
66
66
  def create
@@ -71,14 +71,14 @@ class DropSite &lt; FXMainWindow
71
71
  show(PLACEMENT_SCREEN)
72
72
  end
73
73
  end
74
- </pre></td></tr></table><p>Run this basic version of the program to be sure that it's working
74
+ </pre><p>Run this basic version of the program to be sure that it's working
75
75
  properly so far. You should simply see an empty window with a white
76
76
  background.</p><p>Now, on to the fun stuff. Our goal is to be able to drag color data
77
- from some other window, such as an <tt class="classname">FXColorWell</tt>
77
+ from some other window, such as an <code class="classname">FXColorWell</code>
78
78
  widget, and drop it onto the canvas in order to change the canvas'
79
79
  background color. In order for a FOX widget to be able to accept drops at
80
- all, we need to first call its <tt class="methodname">dropEnable()</tt>
81
- method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">def initialize(anApp)
80
+ all, we need to first call its <code class="methodname">dropEnable()</code>
81
+ method:</p><pre class="programlisting">def initialize(anApp)
82
82
  # Initialize base class
83
83
  super(anApp, "Drop Site", nil, nil, DECOR_ALL, 0, 0, 400, 300)
84
84
 
@@ -93,10 +93,10 @@ end
93
93
  }
94
94
  }
95
95
 
96
- <span class="bold"><b> # Enable canvas for drag-and-drop messages
96
+ <span class="bold"><strong> # Enable canvas for drag-and-drop messages
97
97
  @canvas.dropEnable
98
- </b></span>end
99
- </pre></td></tr></table><p>At this point, let's try a little test to see if the program does
98
+ </strong></span>end
99
+ </pre><p>At this point, let's try a little test to see if the program does
100
100
  anything interesting yet. Start by running some other FOX or FXRuby
101
101
  program to use as a drag source for the color data. You should be able to
102
102
  use any program that displays an FXColorWell widget, and this includes the
@@ -106,15 +106,15 @@ end
106
106
  and try to drag a color from one of these color wells onto this window. At
107
107
  this point, the mouse pointer should turn into a stop sign, indicating
108
108
  that the canvas isn't accepting drops of color data yet.</p><p>To correct this problem, we need to use the canvas'
109
- <tt class="methodname">acceptDrop()</tt> method to indicate whether or not
109
+ <code class="methodname">acceptDrop()</code> method to indicate whether or not
110
110
  we'll accept certain kinds of drops. You can call
111
- <tt class="methodname">acceptDrop()</tt> any time after receiving the initial
112
- <tt class="constant">SEL_DND_ENTER</tt> message, but it's usually done in
113
- response to a <tt class="constant">SEL_DND_MOTION</tt> message. Let's add a
114
- handler for <tt class="constant">SEL_DND_MOTION</tt> messages from the canvas
111
+ <code class="methodname">acceptDrop()</code> any time after receiving the initial
112
+ <code class="constant">SEL_DND_ENTER</code> message, but it's usually done in
113
+ response to a <code class="constant">SEL_DND_MOTION</code> message. Let's add a
114
+ handler for <code class="constant">SEL_DND_MOTION</code> messages from the canvas
115
115
  in DropSite's initialize() method. For now, we'll unconditionally accept
116
116
  drops from any drag source, regardless of what kind of data they're
117
- offering:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">def initialize(anApp)
117
+ offering:</p><pre class="programlisting">def initialize(anApp)
118
118
  # Initialize base class
119
119
  super(anApp, "Drop Site", nil, nil, DECOR_ALL, 0, 0, 400, 300)
120
120
 
@@ -132,13 +132,13 @@ end
132
132
  # Enable canvas for drag-and-drop messages
133
133
  @canvas.dropEnable
134
134
 
135
- <span class="bold"><b> # Handle SEL_DND_MOTION messages from the canvas
135
+ <span class="bold"><strong> # Handle SEL_DND_MOTION messages from the canvas
136
136
  @canvas.connect(SEL_DND_MOTION) {
137
137
  # Accept drops unconditionally (for now)
138
138
  @canvas.acceptDrop
139
139
  }
140
- </b></span>end
141
- </pre></td></tr></table><p>Now try the previous test again. This time, when you try to drag
140
+ </strong></span>end
141
+ </pre><p>Now try the previous test again. This time, when you try to drag
142
142
  from a color well to the drop-enabled canvas, you should see the mouse
143
143
  pointer turn into a small filled square. This is a visual cue to the user
144
144
  indicating that the canvas will accept a drop of the drag-and-drop
@@ -152,35 +152,35 @@ end
152
152
  types for any kind of application-specific data that you need; but for
153
153
  now, we're going to use FOX's built-in drag type for color data.</p><p>Drag types (even the standard ones) must be registered before they
154
154
  can be used, and so we'll start by adding a few lines to
155
- <tt class="classname">DropSite</tt>'s <tt class="methodname">create()</tt> method
156
- to register the drag type for color data:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">def create
155
+ <code class="classname">DropSite</code>'s <code class="methodname">create()</code> method
156
+ to register the drag type for color data:</p><pre class="programlisting">def create
157
157
  # Create the main window and canvas
158
158
  super
159
159
 
160
- <span class="bold"><b> # Register the drag type for colors
160
+ <span class="bold"><strong> # Register the drag type for colors
161
161
  FXWindow.colorType = getApp().registerDragType(FXWindow.colorTypeName)
162
162
 
163
- </b></span> # Show the main window
163
+ </strong></span> # Show the main window
164
164
  show(PLACEMENT_SCREEN)
165
165
  end
166
- </pre></td></tr></table><p>Note that the first time that
167
- <tt class="methodname">registerDragType()</tt> is called for a particular
168
- drag type name (such as <tt class="methodname">FXWindow.colorTypeName</tt>)
166
+ </pre><p>Note that the first time that
167
+ <code class="methodname">registerDragType()</code> is called for a particular
168
+ drag type name (such as <code class="methodname">FXWindow.colorTypeName</code>)
169
169
  it will generate a unique identifier for that drag type. Subsequent calls
170
- to <tt class="methodname">registerDragType()</tt> for the same drag type name
170
+ to <code class="methodname">registerDragType()</code> for the same drag type name
171
171
  will just return the previously-generated drag type. Now, we want to
172
- modify our <tt class="constant">SEL_DND_MOTION</tt> handler so that it's a
173
- little more picky about which kinds of drops it will accept:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"># Handle SEL_DND_MOTION messages from the canvas
172
+ modify our <code class="constant">SEL_DND_MOTION</code> handler so that it's a
173
+ little more picky about which kinds of drops it will accept:</p><pre class="programlisting"># Handle SEL_DND_MOTION messages from the canvas
174
174
  @canvas.connect(SEL_DND_MOTION) {
175
- <span class="bold"><b> if @canvas.offeredDNDType?(FROM_DRAGNDROP, FXWindow.colorType)
175
+ <span class="bold"><strong> if @canvas.offeredDNDType?(FROM_DRAGNDROP, FXWindow.colorType)
176
176
  @canvas.acceptDrop
177
177
  end
178
- </b></span>}
179
- </pre></td></tr></table><p>Here, we call the canvas' <tt class="methodname">offeredDNDType?</tt>
178
+ </strong></span>}
179
+ </pre><p>Here, we call the canvas' <code class="methodname">offeredDNDType?</code>
180
180
  method to ask if the drag source can provide its data in the requested
181
- format. Only if <tt class="methodname">offeredDNDType?</tt> returns true will
182
- we call <tt class="methodname">acceptDrop()</tt> as before.</p><p>The last step is to actually handle the drop, and for that we add a
183
- handler for the <tt class="constant">SEL_DND_DROP</tt> message:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting"><span class="bold"><b># Handle SEL_DND_DROP message from the canvas
181
+ format. Only if <code class="methodname">offeredDNDType?</code> returns true will
182
+ we call <code class="methodname">acceptDrop()</code> as before.</p><p>The last step is to actually handle the drop, and for that we add a
183
+ handler for the <code class="constant">SEL_DND_DROP</code> message:</p><pre class="programlisting"><span class="bold"><strong># Handle SEL_DND_DROP message from the canvas
184
184
  @canvas.connect(SEL_DND_DROP) {
185
185
  # Try to obtain the data as color values first
186
186
  data = @canvas.getDNDData(FROM_DRAGNDROP, FXWindow.colorType)
@@ -188,21 +188,21 @@ end
188
188
  # Update canvas background color
189
189
  @canvas.backColor = Fox.fxdecodeColorData(data)
190
190
  end
191
- }</b></span></pre></td></tr></table><p>Assuming that the drag source is able to provide its data in the
192
- requested format, the <tt class="methodname">getDNDData()</tt> method will
191
+ }</strong></span></pre><p>Assuming that the drag source is able to provide its data in the
192
+ requested format, the <code class="methodname">getDNDData()</code> method will
193
193
  return a String (which for our purposes is just a byte buffer). If you've
194
194
  defined your own application-specific drag types, this data can of course
195
195
  be anything, and we'll see examples of this in a later tutorial. But the
196
196
  data for standard drag types like
197
- <tt class="methodname">FXWindow.colorType</tt> can be decoded using the
197
+ <code class="methodname">FXWindow.colorType</code> can be decoded using the
198
198
  appropriate built-in library functions. In this case, we use the
199
- <tt class="methodname">fxdecodeColorData()</tt> method to convert the bytes
199
+ <code class="methodname">fxdecodeColorData()</code> method to convert the bytes
200
200
  into a color value that we can use.</p><p>Now comes the moment of truth. Try running your test program again
201
201
  (one that displays a color well). Now, when you drag a color from a color
202
- well and drop it onto the <tt class="classname">DropSite</tt> window, the
202
+ well and drop it onto the <code class="classname">DropSite</code> window, the
203
203
  canvas should change its background color accordingly.</p><p>The complete program is listed below, and is included in the
204
- <tt class="filename">examples</tt> directory under the file
205
- name <tt class="filename">dropsite.rb</tt>.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">require 'rubygems'
204
+ <code class="filename">examples</code> directory under the file
205
+ name <code class="filename">dropsite.rb</code>.</p><pre class="programlisting">require 'rubygems'
206
206
  require_gem 'fxruby'
207
207
 
208
208
  include Fox
@@ -263,4 +263,4 @@ if __FILE__ == $0
263
263
  theApp.run
264
264
  end
265
265
  end
266
- </pre></td></tr></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s04.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="pt01.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ch05s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Pasting Data from the Clipboard&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Drag Sources</td></tr></table></div></body></html>
266
+ </pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s04.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="pt01.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ch05s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Pasting Data from the Clipboard&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Drag Sources</td></tr></table></div></body></html>