fxruby 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/doc/apes02.html +6 -6
- data/doc/apes03.html +11 -11
- data/doc/book.html +1 -1
- data/doc/build.html +63 -63
- data/doc/ch03s02.html +7 -7
- data/doc/ch03s03.html +18 -18
- data/doc/ch03s04.html +11 -11
- data/doc/ch03s05.html +14 -14
- data/doc/ch04s02.html +14 -14
- data/doc/ch04s03.html +15 -15
- data/doc/ch04s04.html +28 -28
- data/doc/ch05s02.html +49 -49
- data/doc/ch05s03.html +8 -8
- data/doc/changes.html +263 -193
- data/doc/clipboardtut.html +57 -45
- data/doc/cvs.html +10 -10
- data/doc/differences.html +4 -4
- data/doc/dragdroptut.html +50 -50
- data/doc/events.html +11 -11
- data/doc/examples.html +48 -48
- data/doc/gems.html +37 -37
- data/doc/goals.html +4 -4
- data/doc/implementation.html +4 -4
- data/doc/infosources.html +6 -6
- data/doc/library.html +19 -19
- data/doc/opengl.html +31 -31
- data/doc/pt01.html +1 -1
- data/doc/pt02.html +1 -1
- data/doc/scintilla.html +15 -15
- data/doc/style.css +3 -0
- data/doc/todo.html +5 -5
- data/doc/tutorial1.html +34 -34
- data/doc/unicode.html +56 -0
- data/ext/fox16/dialogs_wrap.cpp +38 -14
- data/ext/fox16/frames_wrap.cpp +856 -22
- data/ext/fox16/fx3d_wrap.cpp +169 -144
- data/ext/fox16/icons_wrap.cpp +24 -6
- data/ext/fox16/image_wrap.cpp +24 -6
- data/ext/fox16/label_wrap.cpp +23 -8
- data/ext/fox16/markfuncs.cpp +8 -1
- data/ext/fox16/mdi_wrap.cpp +53 -23
- data/ext/fox16/menu_wrap.cpp +43 -19
- data/ext/fox16/scintilla_wrap.cpp +31 -7
- data/ext/fox16/table_wrap.cpp +31 -7
- data/ext/fox16/text_wrap.cpp +31 -7
- data/ext/fox16/treelist_wrap.cpp +300 -276
- data/ext/fox16/ui_wrap.cpp +385 -26
- data/lib/fox16/aliases.rb +3 -0
- data/lib/fox16/version.rb +1 -1
- data/rdoc-sources/FXFoldingList.rb +2 -2
- data/tests/TC_FXDirList.rb +1 -1
- data/tests/TC_FXGLViewer.rb +2 -0
- data/tests/TC_FXHeader.rb +1 -1
- data/tests/TC_FXIconList.rb +1 -1
- data/tests/TC_FXId.rb +1 -1
- data/tests/TC_FXList.rb +1 -1
- data/tests/TC_FXListBox.rb +1 -1
- data/tests/TC_FXMenuCommand.rb +0 -14
- data/tests/TC_FXTable.rb +0 -32
- data/tests/TC_FXTableItem.rb +1 -1
- data/tests/TC_FXTreeList.rb +1 -1
- data/tests/TC_FXTreeListBox.rb +1 -1
- metadata +5 -4
data/doc/ch03s04.html
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
<html><head>
|
2
2
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
3
|
-
<title>Adding a tool tip</title><meta name="generator" content="DocBook XSL Stylesheets V1.
|
3
|
+
<title>Adding a tool tip</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="tutorial1.html" title="Chapter 3. Hello, World!"><link rel="prev" href="ch03s03.html" title="Messages"><link rel="next" href="ch03s05.html" title="Adding an icon"></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">Adding a tool tip</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Hello, World!</th><td width="20%" align="right"> <a accesskey="n" href="ch03s05.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e846"></a>Adding a tool tip</h2></div></div></div><p>To wrap up this introduction, we'd like to add a few finishing
|
4
4
|
touches to the program. The first addition is to add a tool tip to the
|
5
5
|
button, such that when the mouse cursor hovers over the button for a short
|
6
6
|
while, it will pop up a little message describing what the button
|
7
|
-
does:</p><
|
7
|
+
does:</p><pre class="programlisting">require 'fox16'
|
8
8
|
|
9
9
|
include Fox
|
10
10
|
|
@@ -13,24 +13,24 @@ theApp = FXApp.new
|
|
13
13
|
theMainWindow = FXMainWindow.new(theApp, "Hello")
|
14
14
|
|
15
15
|
theButton = FXButton.new(theMainWindow, "Hello, World!")
|
16
|
-
<span class="bold"><
|
16
|
+
<span class="bold"><strong>theButton.tipText = "Push Me!"</strong></span>
|
17
17
|
theButton.connect(SEL_COMMAND) { exit }
|
18
18
|
|
19
|
-
<span class="bold"><
|
19
|
+
<span class="bold"><strong>FXToolTip.new(theApp)</strong></span>
|
20
20
|
|
21
21
|
theApp.create
|
22
22
|
|
23
23
|
theMainWindow.show
|
24
24
|
|
25
|
-
theApp.run</pre
|
26
|
-
tip text for the button using the <
|
25
|
+
theApp.run</pre><p>There are two changes involved here. The first is to set the tool
|
26
|
+
tip text for the button using the <code class="methodname">tipText</code>
|
27
27
|
accessor, and for this example we're setting the button's tip text to
|
28
28
|
"Push Me!". The second change is to create the (single)
|
29
|
-
<
|
30
|
-
this program shows the <
|
31
|
-
created after the <
|
29
|
+
<code class="classname">FXToolTip</code> instance for the application. Although
|
30
|
+
this program shows the <code class="classname">FXToolTip</code> instance being
|
31
|
+
created after the <code class="classname">FXButton</code>, it doesn't really
|
32
32
|
matter when you do it. You just want to have instantiated the
|
33
|
-
<
|
34
|
-
by calling <
|
33
|
+
<code class="classname">FXToolTip</code> before you drop into the main event loop
|
34
|
+
by calling <code class="methodname">FXApp#run</code>. If you run this version and
|
35
35
|
hover over the button for a second or so, you should see the tooltip pop
|
36
36
|
up:</p><div class="screenshot"><div class="mediaobject" align="center"><img src="images/hello-with-tooltip.png" align="middle"></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tutorial1.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch03s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Messages </td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top"> Adding an icon</td></tr></table></div></body></html>
|
data/doc/ch03s05.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>Adding an icon</title><meta name="generator" content="DocBook XSL Stylesheets V1.
|
3
|
+
<title>Adding an icon</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="tutorial1.html" title="Chapter 3. Hello, World!"><link rel="prev" href="ch03s04.html" title="Adding a tool tip"><link rel="next" href="clipboardtut.html" title="Chapter 4. Working With 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">Adding an icon</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s04.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Hello, World!</th><td width="20%" align="right"> <a accesskey="n" href="clipboardtut.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e883"></a>Adding an icon</h2></div></div></div><p>The final change is to add an icon to the button to make things a
|
4
4
|
little more festive. FOX supports all of the popular image file formats
|
5
5
|
(e.g. BMP, GIF, JPEG, PNG and TIFF) and you can use any of them as icons
|
6
6
|
on buttons and labels. For this example, we'll use the one of the "Powered
|
7
7
|
By Ruby" images created by Hal Fulton (and posted at the <a href="http://www.rubygarden.org/ruby?PoweredByRubyButtons" target="_top">Ruby Garden
|
8
|
-
Wiki</a>):</p><
|
8
|
+
Wiki</a>):</p><pre class="programlisting">require 'fox16'
|
9
9
|
|
10
10
|
include Fox
|
11
11
|
|
@@ -15,9 +15,9 @@ theMainWindow = FXMainWindow.new(theApp, "Hello")
|
|
15
15
|
|
16
16
|
theButton = FXButton.new(theMainWindow, "Hello, World!")
|
17
17
|
theButton.tipText = "Push Me!"
|
18
|
-
<span class="bold"><
|
18
|
+
<span class="bold"><strong>iconFile = File.open("pbr.jpg", "rb")
|
19
19
|
theButton.icon = FXJPGIcon.new(theApp, iconFile.read)
|
20
|
-
iconFile.close</
|
20
|
+
iconFile.close</strong></span>
|
21
21
|
theButton.connect(SEL_COMMAND) { exit }
|
22
22
|
|
23
23
|
FXToolTip.new(theApp)
|
@@ -26,22 +26,22 @@ theApp.create
|
|
26
26
|
|
27
27
|
theMainWindow.show
|
28
28
|
|
29
|
-
theApp.run</pre
|
29
|
+
theApp.run</pre><p>Here, <code class="filename">pbr.jpg</code> is the file name of the JPEG
|
30
30
|
image file. You want to be sure to open the file in
|
31
31
|
<span class="emphasis"><em>binary</em></span> mode (i.e. including the "b" mode flag),
|
32
32
|
because there is a difference on the Windows platform. Since it's a JPEG
|
33
|
-
image, we need to use the <
|
33
|
+
image, we need to use the <code class="classname">FXJPGIcon</code> class to
|
34
34
|
instantiate this icon. The first argument to
|
35
|
-
<
|
36
|
-
<
|
35
|
+
<code class="methodname">FXJPGIcon.new</code> is just a reference to the
|
36
|
+
<code class="classname">FXApp</code> instance, and the second argument is the
|
37
37
|
contents of the image file. We associate this icon object with our button
|
38
|
-
using the button's <
|
38
|
+
using the button's <code class="methodname">icon</code> accessor method. If you
|
39
39
|
run this example, you should see:</p><div class="screenshot"><div class="mediaobject" align="center"><img src="images/hello-with-icon-1.png" align="middle"></div></div><p>When you have both text and an icon displayed on a button (or its
|
40
|
-
superclass, <
|
40
|
+
superclass, <code class="classname">FXLabel</code>) the default positioning is to
|
41
41
|
display the icon to the left of the text. For this particular example,
|
42
42
|
however, it would probably be more appropriate to display the icon
|
43
43
|
<span class="emphasis"><em>above</em></span> the text. We can achieve this using the
|
44
|
-
button's <
|
44
|
+
button's <code class="methodname">iconPosition</code> accessor method:</p><pre class="programlisting">theButton.iconPosition = ICON_ABOVE_TEXT</pre><p>If you re-run the program after adding this line, you should
|
45
45
|
see:</p><div class="screenshot"><div class="mediaobject" align="center"><img src="images/hello-with-icon-2.png" align="middle"></div></div><p>The last change we're going to make is to make the icon transparent.
|
46
46
|
FOX allows you to specify that some regions of an icon should be treated
|
47
47
|
as "transparent", meaning that whatever's underneath them shows through.
|
@@ -52,9 +52,9 @@ theApp.run</pre></td></tr></table><p>Here, <tt class="filename">pbr.jpg</tt> is
|
|
52
52
|
it's part of the image information). You can also specify the transparency
|
53
53
|
color explicitly if you like.</p><p>For the icon we've chosen, it's pretty obvious that the transparency
|
54
54
|
color is white, but let's let FOX figure that out for us. We want to
|
55
|
-
activate two options for the icon:</p><div class="itemizedlist"><ul type="bullet"><li style="list-style-type: disc"><p>the <
|
55
|
+
activate two options for the icon:</p><div class="itemizedlist"><ul type="bullet"><li style="list-style-type: disc"><p>the <code class="constant">IMAGE_ALPHACOLOR</code> option, which tells
|
56
56
|
FOX that some regions of this image should be treated as transparent;
|
57
|
-
and,</p></li><li style="list-style-type: disc"><p>the <
|
57
|
+
and,</p></li><li style="list-style-type: disc"><p>the <code class="constant">IMAGE_ALPHAGUESS</code> option, which tells
|
58
58
|
FOX to guess the appropriate transparency color using the colors used
|
59
|
-
in the four corners of the image.</p></li></ul></div><p>To set these options, add this line to the program:</p><
|
59
|
+
in the four corners of the image.</p></li></ul></div><p>To set these options, add this line to the program:</p><pre class="programlisting">theButton.icon.options = IMAGE_ALPHACOLOR | IMAGE_ALPHAGUESS</pre><p>and then re-run the program after making this change to see the
|
60
60
|
final result:</p><div class="screenshot"><div class="mediaobject" align="center"><img src="images/hello-with-icon-3.png" align="middle"></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s04.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tutorial1.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="clipboardtut.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Adding a tool tip </td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 4. Working With the Clipboard</td></tr></table></div></body></html>
|
data/doc/ch04s02.html
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<html><head>
|
2
2
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
3
|
-
<title>Acquiring the Clipboard</title><meta name="generator" content="DocBook XSL Stylesheets V1.
|
4
|
-
the bottom of the main window for copying and pasting:</p><
|
3
|
+
<title>Acquiring 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="clipboardtut.html" title="Chapter 4. Working With the Clipboard"><link rel="prev" href="clipboardtut.html" title="Chapter 4. Working With the Clipboard"><link rel="next" href="ch04s03.html" title="Sending Data to 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">Acquiring the Clipboard</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="clipboardtut.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Working With the Clipboard</th><td width="20%" align="right"> <a accesskey="n" href="ch04s03.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1005"></a>Acquiring the Clipboard</h2></div></div></div><p>Let's begin by augmenting the GUI to include a row of buttons along
|
4
|
+
the bottom of the main window for copying and pasting:</p><pre class="programlisting">require 'rubygems'
|
5
5
|
require_gem 'fxruby'
|
6
6
|
require 'customer'
|
7
7
|
|
@@ -11,14 +11,14 @@ class ClipMainWindow < FXMainWindow
|
|
11
11
|
def initialize(anApp)
|
12
12
|
# Initialize base class first
|
13
13
|
super(anApp, "Clipboard Example", nil, nil, DECOR_ALL, 0, 0, 400, 300)
|
14
|
-
<span class="bold"><
|
14
|
+
<span class="bold"><strong>
|
15
15
|
# Horizontal frame contains buttons
|
16
16
|
buttons = FXHorizontalFrame.new(self, LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH)
|
17
|
-
</
|
17
|
+
</strong></span><span class="bold"><strong>
|
18
18
|
# Cut and paste buttons
|
19
19
|
copyButton = FXButton.new(buttons, "Copy")
|
20
20
|
pasteButton = FXButton.new(buttons, "Paste")
|
21
|
-
</
|
21
|
+
</strong></span>
|
22
22
|
# Place the list in a sunken frame
|
23
23
|
sunkenFrame = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK,
|
24
24
|
0, 0, 0, 0, 0, 0, 0, 0)
|
@@ -43,12 +43,12 @@ if __FILE__ == $0
|
|
43
43
|
theApp.run
|
44
44
|
end
|
45
45
|
end
|
46
|
-
</pre
|
46
|
+
</pre><p>Note that the lines which appear in bold face are those which have
|
47
47
|
been added (or changed) since the previous source code listing.</p><p>The clipboard is a kind of shared resource in the operating system.
|
48
48
|
Copying (or cutting) data to the clipboard begins with some window in your
|
49
49
|
application requesting "ownership" of the clipboard by calling the
|
50
|
-
<
|
51
|
-
handler for the "Copy" button press which does just that:</p><
|
50
|
+
<code class="methodname">acquireClipboard()</code> instance method. Let's add a
|
51
|
+
handler for the "Copy" button press which does just that:</p><pre class="programlisting"># User clicks Copy
|
52
52
|
copyButton.connect(SEL_COMMAND) do
|
53
53
|
customer = customerList.getItemData(customerList.currentItem)
|
54
54
|
types = [ FXWindow.stringType ]
|
@@ -56,17 +56,17 @@ copyButton.connect(SEL_COMMAND) do
|
|
56
56
|
@clippedCustomer = customer
|
57
57
|
end
|
58
58
|
end
|
59
|
-
</pre
|
59
|
+
</pre><p>The <code class="methodname">acquireClipboard()</code> method takes as its
|
60
60
|
input an array of drag types. A <span class="emphasis"><em>drag type</em></span> is just a
|
61
61
|
unique value, assigned by the window system, that identifies a particular
|
62
62
|
kind of data. In this case, we're using one of FOX's pre-registered drag
|
63
|
-
types (<
|
63
|
+
types (<code class="constant">stringType</code>) to indicate that we have some
|
64
64
|
string data to place on the clipboard. Later, we'll see how to register
|
65
|
-
customized, application-specific drag types as well.</p><p>The <
|
66
|
-
<
|
67
|
-
<
|
65
|
+
customized, application-specific drag types as well.</p><p>The <code class="methodname">acquireClipboard()</code> method returns
|
66
|
+
<code class="constant">true</code> on success; since we called
|
67
|
+
<code class="methodname">acquireClipboard()</code> on the main window, this means
|
68
68
|
that the main window is now the clipboard owner. At this time, we want to
|
69
69
|
save a reference to the currently selected customer in the
|
70
|
-
<
|
70
|
+
<code class="varname">@clippedCustomer</code> instance variable so that if its value
|
71
71
|
is requested later, we'll be able to return the
|
72
72
|
<span class="emphasis"><em>correct</em></span> customer's information.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="clipboardtut.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="clipboardtut.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch04s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 4. Working With the Clipboard </td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top"> Sending Data to the Clipboard</td></tr></table></div></body></html>
|
data/doc/ch04s03.html
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
<html><head>
|
2
2
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
3
|
-
<title>Sending Data to the Clipboard</title><meta name="generator" content="DocBook XSL Stylesheets V1.
|
3
|
+
<title>Sending Data to 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="clipboardtut.html" title="Chapter 4. Working With the Clipboard"><link rel="prev" href="ch04s02.html" title="Acquiring the Clipboard"><link rel="next" href="ch04s04.html" title="Pasting Data from 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">Sending Data to the Clipboard</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04s02.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Working With the Clipboard</th><td width="20%" align="right"> <a accesskey="n" href="ch04s04.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1054"></a>Sending Data to the Clipboard</h2></div></div></div><p>Whenever some other window requests the clipboard's contents (e.g.
|
4
4
|
as a result of a "paste" operation) FOX will send a
|
5
|
-
<
|
5
|
+
<code class="constant">SEL_CLIPBOARD_REQUEST</code> message to the current
|
6
6
|
clipboard owner. Remember, the clipboard owner is the window that called
|
7
|
-
<
|
7
|
+
<code class="methodname">acquireClipboard()</code>. For our example, the main
|
8
8
|
window is acting as the clipboard owner and so it needs to handle the
|
9
|
-
<
|
9
|
+
<code class="constant">SEL_CLIPBOARD_REQUEST</code> message:</p><pre class="programlisting"># Handle clipboard request
|
10
10
|
self.connect(SEL_CLIPBOARD_REQUEST) do
|
11
11
|
setDNDData(FROM_CLIPBOARD, FXWindow.stringType, Fox.fxencodeStringData(@clippedCustomer.to_s))
|
12
12
|
end
|
13
|
-
</pre
|
13
|
+
</pre><p>The <code class="methodname">setDNDData()</code> method takes three
|
14
14
|
arguments. The first argument tells FOX which kind of data transfer we're
|
15
15
|
trying to accomplish; as it turns out, this method can be used for
|
16
|
-
drag-and-drop (<
|
17
|
-
(<
|
18
|
-
argument to <
|
16
|
+
drag-and-drop (<code class="constant">FROM_DRAGNDROP</code>) and X11 selection
|
17
|
+
(<code class="constant">FROM_SELECTION</code>) data transfer as well. The second
|
18
|
+
argument to <code class="methodname">setDNDData()</code> is the drag type for the
|
19
19
|
data and the last argument is the data itself, a binary string.</p><p>If you're wondering why we need to call the
|
20
|
-
<
|
21
|
-
the string returned by the call to <
|
20
|
+
<code class="methodname">fxencodeStringData()</code> module method to preprocess
|
21
|
+
the string returned by the call to <code class="methodname">Customer#to_s</code>,
|
22
22
|
that's a reasonable thing to wonder about. In order for FOX to play nice
|
23
23
|
with other clipboard-aware applications, it must be able to store string
|
24
24
|
data on the clipboard in the format expected by those applications.
|
25
25
|
Unfortunately, that expected format is platform-dependent and does not
|
26
26
|
always correspond directly to the format that Ruby uses internally to
|
27
|
-
store its string data. The <
|
27
|
+
store its string data. The <code class="methodname">fxencodeStringData()</code>
|
28
28
|
method (and the corresponding
|
29
|
-
<
|
29
|
+
<code class="methodname">fxdecodeStringData()</code> method) provide you with a
|
30
30
|
platform-independent way of sending (or receiving) string data with the
|
31
|
-
<
|
31
|
+
<code class="constant">stringType</code> drag type.</p><p>If you run the program as it currently stands, you should now be
|
32
32
|
able to select a customer from the list, click the "Copy" button and then
|
33
33
|
paste the selected customer data (as a string) into some other
|
34
34
|
application. For example, if you're trying this tutorial on a Windows
|
35
35
|
machine, try pasting into a copy of Notepad or Microsoft Word. The pasted
|
36
|
-
text should look something like:</p><
|
37
|
-
</pre></
|
36
|
+
text should look something like:</p><pre class="programlisting">#<struct Struct::Customer name="Joe Smith", address="123 Maple, Anytown, NC", zip=12345>
|
37
|
+
</pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="clipboardtut.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch04s04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Acquiring the Clipboard </td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top"> Pasting Data from the Clipboard</td></tr></table></div></body></html>
|
data/doc/ch04s04.html
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
<html><head>
|
2
2
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
3
|
-
<title>Pasting Data from the Clipboard</title><meta name="generator" content="DocBook XSL Stylesheets V1.
|
3
|
+
<title>Pasting Data from 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="clipboardtut.html" title="Chapter 4. Working With the Clipboard"><link rel="prev" href="ch04s03.html" title="Sending Data to the Clipboard"><link rel="next" href="dragdroptut.html" title="Chapter 5. Drag and Drop"></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">Pasting Data from the Clipboard</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04s03.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Working With the Clipboard</th><td width="20%" align="right"> <a accesskey="n" href="dragdroptut.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1105"></a>Pasting Data from the Clipboard</h2></div></div></div><p>We've seen one side of the equation, copying string data to the
|
4
4
|
clipboard. But before we can "round-trip" that customer data and paste it
|
5
5
|
back into another copy of our customer list application, we're clearly
|
6
6
|
going to need to transfer the data in some more useful format. That is to
|
7
7
|
say, if we were to receive the customer data in the format that it's
|
8
|
-
currently stored on the clipboard:</p><
|
9
|
-
</pre
|
8
|
+
currently stored on the clipboard:</p><pre class="programlisting">#<struct Struct::Customer name="Joe Smith", address="123 Maple, Anytown, NC", zip=12345>
|
9
|
+
</pre><p>We'd have to parse that string and try to extract the relevant data
|
10
10
|
from it. We can do better than that. The approach we'll use instead is to
|
11
11
|
serialize and deserialize the objects using YAML. First, make sure that
|
12
|
-
the YAML module is loaded by adding this line:</p><
|
13
|
-
type for <
|
14
|
-
one line to our main window's <
|
15
|
-
method:</p><
|
12
|
+
the YAML module is loaded by adding this line:</p><pre class="programlisting">require 'yaml'</pre><p>somewhere near the top of the program. Next, register a custom drag
|
13
|
+
type for <code class="classname">Customer</code> objects. We can do that by adding
|
14
|
+
one line to our main window's <code class="methodname">create</code> instance
|
15
|
+
method:</p><pre class="programlisting">def create
|
16
16
|
super
|
17
|
-
<span class="bold"><
|
18
|
-
</
|
17
|
+
<span class="bold"><strong> @customerDragType = getApp().registerDragType("application/x-customer")
|
18
|
+
</strong></span> show(PLACEMENT_SCREEN)
|
19
19
|
end
|
20
|
-
</pre
|
20
|
+
</pre><p>Note that by convention, the name of the drag type is the MIME type
|
21
21
|
for the data, but any unique string will do. In our case, we'll use the
|
22
22
|
string "application/x-customer" to identify the drag type for our
|
23
|
-
YAML-serialized <
|
23
|
+
YAML-serialized <code class="classname">Customer</code> objects.</p><p>With that in place, we can now go back and slightly change some of
|
24
24
|
our previous code. When we acquire the clipboard, we'd now like to be able
|
25
25
|
to offer the selected customer's information either as plain text (i.e.
|
26
26
|
the previous format) <span class="emphasis"><em>or</em></span> as a YAML document, so we'll
|
27
27
|
include <span class="emphasis"><em>both</em></span> of these types in the array of drag
|
28
|
-
types passed to <
|
28
|
+
types passed to <code class="methodname">acquireClipboard()</code>:</p><pre class="programlisting"># User clicks Copy
|
29
29
|
copyButton.connect(SEL_COMMAND) do
|
30
30
|
customer = customerList.getItemData(customerList.currentItem)
|
31
|
-
<span class="bold"><
|
32
|
-
</
|
31
|
+
<span class="bold"><strong> types = [ FXWindow.stringType, @customerDragType ]
|
32
|
+
</strong></span> if acquireClipboard(types)
|
33
33
|
@clippedCustomer = customer
|
34
34
|
end
|
35
35
|
end
|
36
|
-
</pre
|
37
|
-
<
|
36
|
+
</pre><p>Similarly, when we're handling the
|
37
|
+
<code class="constant">SEL_CLIPBOARD_REQUEST</code> message, we now need to pay
|
38
38
|
attention to which drag type (i.e. which data format) the requestor
|
39
39
|
specified. We can do that by inspecting the
|
40
|
-
<
|
41
|
-
<
|
42
|
-
<
|
40
|
+
<code class="methodname">target</code> attribute of the
|
41
|
+
<code class="classname">FXEvent</code> instance passed along with the
|
42
|
+
<code class="constant">SEL_CLIPBOARD_REQUEST</code> message:</p><pre class="programlisting"># Handle clipboard request
|
43
43
|
self.connect(SEL_CLIPBOARD_REQUEST) do |sender, sel, event|
|
44
44
|
case event.target
|
45
45
|
when FXWindow.stringType
|
@@ -50,9 +50,9 @@ self.connect(SEL_CLIPBOARD_REQUEST) do |sender, sel, event|
|
|
50
50
|
# Ignore requests for unrecognized drag types
|
51
51
|
end
|
52
52
|
end
|
53
|
-
</pre
|
53
|
+
</pre><p>With these changes in place, we can now add a handler for the
|
54
54
|
"Paste" button which requests the clipboard data in YAML format,
|
55
|
-
deserializes it, and then adds an item to the customer list:</p><
|
55
|
+
deserializes it, and then adds an item to the customer list:</p><pre class="programlisting"># User clicks Paste
|
56
56
|
pasteButton.connect(SEL_COMMAND) do
|
57
57
|
data = getDNDData(FROM_CLIPBOARD, @customerDragType)
|
58
58
|
if data
|
@@ -60,13 +60,13 @@ pasteButton.connect(SEL_COMMAND) do
|
|
60
60
|
customerList.appendItem(customer.name, nil, customer)
|
61
61
|
end
|
62
62
|
end
|
63
|
-
</pre
|
64
|
-
inverse of the <
|
63
|
+
</pre><p>The <code class="methodname">getDNDData()</code> method used here is the
|
64
|
+
inverse of the <code class="methodname">setDNDData()</code> method we used
|
65
65
|
earlier to push data to some other application requesting our clipboard
|
66
|
-
data. As with <
|
67
|
-
<
|
68
|
-
we're performing (e.g. <
|
66
|
+
data. As with <code class="methodname">setDNDData()</code>, the arguments to
|
67
|
+
<code class="methodname">getDNDData()</code> indicate the kind of data transfer
|
68
|
+
we're performing (e.g. <code class="constant">FROM_CLIPBOARD</code>) and the drag
|
69
69
|
type for the data we're requesting. If some failure occurs (usually,
|
70
70
|
because the clipboard owner can't provide its data in the requested
|
71
|
-
format) <
|
72
|
-
<
|
71
|
+
format) <code class="methodname">getDNDData()</code> will simply return
|
72
|
+
<code class="constant">nil</code>.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s03.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="clipboardtut.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="dragdroptut.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Sending Data to the Clipboard </td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 5. Drag and Drop</td></tr></table></div></body></html>
|