wxruby3 0.9.0.pre.beta.10 → 0.9.0.pre.beta.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/INSTALL.md +85 -0
  3. data/README.md +2 -0
  4. data/assets/logo.png +0 -0
  5. data/assets/logo.svg +170 -0
  6. data/assets/logo.xcf +0 -0
  7. data/ext/wxruby3/include/wxruby-ScaledDC.h +549 -0
  8. data/ext/wxruby3/swig/wx.i +1 -1
  9. data/lib/wx/core/array_ext.rb +26 -0
  10. data/lib/wx/core/art_locator.rb +92 -0
  11. data/lib/wx/core/artprovider.rb +1 -1
  12. data/lib/wx/core/bitmap.rb +90 -53
  13. data/lib/wx/core/cursor.rb +12 -0
  14. data/lib/wx/core/data_object.rb +74 -6
  15. data/lib/wx/core/dataformat.rb +3 -1
  16. data/lib/wx/core/dc.rb +76 -52
  17. data/lib/wx/core/enum.rb +4 -0
  18. data/lib/wx/core/event.rb +38 -5
  19. data/lib/wx/core/evthandler.rb +64 -23
  20. data/lib/wx/core/icon.rb +50 -35
  21. data/lib/wx/core/id_helper.rb +32 -0
  22. data/lib/wx/core/image.rb +63 -53
  23. data/lib/wx/core/point.rb +35 -10
  24. data/lib/wx/core/real_point.rb +35 -10
  25. data/lib/wx/core/rect.rb +44 -9
  26. data/lib/wx/core/region_iterator.rb +37 -0
  27. data/lib/wx/core/size.rb +32 -5
  28. data/lib/wx/core/window.rb +8 -31
  29. data/lib/wx/doc/array_ext.rb +27 -0
  30. data/lib/wx/doc/art_locator.rb +57 -0
  31. data/lib/wx/doc/bitmap.rb +27 -0
  32. data/lib/wx/doc/clipboard.rb +12 -0
  33. data/lib/wx/doc/const.rb +77 -0
  34. data/lib/wx/doc/cursor.rb +16 -0
  35. data/lib/wx/doc/data_object.rb +103 -0
  36. data/lib/wx/doc/dc.rb +63 -46
  37. data/lib/wx/doc/event.rb +24 -0
  38. data/lib/wx/doc/events.rb +14 -0
  39. data/lib/wx/doc/evthandler.rb +24 -3
  40. data/lib/wx/doc/extra/00_starting.md +1 -1
  41. data/lib/wx/doc/extra/06_geometry.md +10 -4
  42. data/lib/wx/doc/extra/10_art.md +105 -0
  43. data/lib/wx/doc/gc_dc.rb +21 -0
  44. data/lib/wx/doc/gdi_common.rb +155 -6
  45. data/lib/wx/doc/graphics_context.rb +42 -0
  46. data/lib/wx/doc/icon.rb +18 -0
  47. data/lib/wx/doc/id_helper.rb +25 -0
  48. data/lib/wx/doc/image.rb +33 -0
  49. data/lib/wx/doc/region_iterator.rb +31 -0
  50. data/lib/wx/doc/scaled_dc.rb +17 -0
  51. data/lib/wx/doc/window.rb +18 -0
  52. data/lib/wx/global_const.rb +4 -3
  53. data/lib/wx/version.rb +1 -1
  54. data/lib/wx/wxruby/cmd/sampler.rb +3 -21
  55. data/rakelib/lib/config.rb +4 -4
  56. data/rakelib/lib/core/package.rb +6 -6
  57. data/rakelib/lib/core/spec.rb +2 -0
  58. data/rakelib/lib/director/art_provider.rb +2 -2
  59. data/rakelib/lib/director/busy_info.rb +9 -7
  60. data/rakelib/lib/director/clipboard.rb +1 -1
  61. data/rakelib/lib/director/colour_picker_ctrl.rb +1 -0
  62. data/rakelib/lib/director/data_object.rb +162 -0
  63. data/rakelib/lib/director/data_object_simple_base.rb +123 -0
  64. data/rakelib/lib/director/derived_dc.rb +134 -2
  65. data/rakelib/lib/director/dir_picker_ctrl.rb +1 -0
  66. data/rakelib/lib/director/event.rb +73 -8
  67. data/rakelib/lib/director/events.rb +19 -1
  68. data/rakelib/lib/director/file_picker_ctrl.rb +1 -0
  69. data/rakelib/lib/director/font_picker_ctrl.rb +1 -0
  70. data/rakelib/lib/director/gdicommon.rb +1 -3
  71. data/rakelib/lib/director/graphics_context.rb +89 -0
  72. data/rakelib/lib/director/help_controller.rb +2 -2
  73. data/rakelib/lib/director/html_data_object.rb +37 -0
  74. data/rakelib/lib/director/image.rb +55 -0
  75. data/rakelib/lib/director/region_iterator.rb +48 -0
  76. data/rakelib/lib/director/richtext_buffer.rb +1 -1
  77. data/rakelib/lib/director/richtext_buffer_data_object.rb +45 -0
  78. data/rakelib/lib/director/scroll_bar.rb +39 -0
  79. data/rakelib/lib/director/slider.rb +39 -0
  80. data/rakelib/lib/director/window.rb +36 -5
  81. data/rakelib/lib/director/window_disabler.rb +0 -7
  82. data/rakelib/lib/extractor/class.rb +1 -1
  83. data/rakelib/lib/extractor/function.rb +1 -1
  84. data/rakelib/lib/generate/doc.rb +26 -6
  85. data/rakelib/lib/specs/interfaces.rb +8 -1
  86. data/rakelib/lib/typemap/common.rb +1 -1
  87. data/rakelib/lib/typemap/data_object_data.rb +13 -4
  88. data/rakelib/lib/util/string.rb +29 -8
  89. data/samples/art/wxruby-128x128.png +0 -0
  90. data/samples/art/wxruby-256x256.png +0 -0
  91. data/samples/art/wxruby-64x64.png +0 -0
  92. data/samples/art/wxruby.ico +0 -0
  93. data/samples/art/wxruby.png +0 -0
  94. data/samples/drawing/graphics_drawing.rb +1 -2
  95. data/samples/propgrid/propgrid.rb +65 -65
  96. data/samples/sample.xpm +246 -470
  97. data/samples/treectrl/treectrl.rb +1 -1
  98. data/tests/art/my_art/sample.xpm +251 -0
  99. data/tests/art/sample3.xpm +251 -0
  100. data/tests/art/test_art/bitmap/sample.xpm +251 -0
  101. data/tests/art/test_art/bitmap/wxruby.bmp +0 -0
  102. data/tests/art/test_art/bitmap/wxruby.png +0 -0
  103. data/tests/art/test_art/bitmap/wxruby.xpm +251 -0
  104. data/tests/art/test_art/cursor/wxruby.bmp +0 -0
  105. data/tests/art/test_art/icon/sample.xpm +251 -0
  106. data/tests/art/test_art/icon/wxruby.ico +0 -0
  107. data/tests/art/test_art/icon/wxruby.png +0 -0
  108. data/tests/art/test_art/image/sample.xpm +251 -0
  109. data/tests/art/test_art/image/wxruby.jpg +0 -0
  110. data/tests/art/test_art/image/wxruby.png +0 -0
  111. data/tests/art/test_art/sample2.xpm +251 -0
  112. data/tests/lib/wxapp_runner.rb +64 -0
  113. data/tests/test_art.rb +91 -0
  114. data/tests/test_basic.rb +0 -5
  115. data/tests/test_clipboard.rb +149 -17
  116. data/tests/test_dc.rb +70 -0
  117. data/tests/test_dialog.rb +2 -13
  118. data/tests/test_event_handling.rb +2 -13
  119. data/tests/test_events.rb +14 -6
  120. data/tests/test_geometry.rb +67 -17
  121. data/tests/test_intl.rb +2 -15
  122. data/tests/test_item_data.rb +2 -15
  123. data/tests/test_variant.rb +1 -15
  124. data/tests/testapp.rb +0 -5
  125. data/tests/testapp_noframe.rb +0 -5
  126. metadata +56 -5
@@ -0,0 +1,251 @@
1
+ /* XPM */
2
+ static char * sample2_xpm[] = {
3
+ "32 32 216 2",
4
+ " c None",
5
+ ". c #872C2C",
6
+ "+ c #A52827",
7
+ "@ c #A42828",
8
+ "# c #553131",
9
+ "$ c #7D2D2D",
10
+ "% c #3D3232",
11
+ "& c #535331",
12
+ "* c #AEAE26",
13
+ "= c #85852C",
14
+ "- c #ACAC26",
15
+ "; c #88882C",
16
+ "> c #9B2929",
17
+ ", c #A92626",
18
+ "' c #F10D0C",
19
+ ") c #B32424",
20
+ "! c #D91919",
21
+ "~ c #A52727",
22
+ "{ c #E51414",
23
+ "] c #DC1817",
24
+ "^ c #9F2828",
25
+ "/ c #A5A527",
26
+ "( c #F2F20B",
27
+ "_ c #FFFF00",
28
+ ": c #F1F10C",
29
+ "< c #AEAE25",
30
+ "[ c #E7E712",
31
+ "} c #BEBE22",
32
+ "| c #999929",
33
+ "1 c #DE1716",
34
+ "2 c #A82626",
35
+ "3 c #EF0E0D",
36
+ "4 c #CA1E1E",
37
+ "5 c #C42020",
38
+ "6 c #EC1010",
39
+ "7 c #9E2828",
40
+ "8 c #B12525",
41
+ "9 c #E91211",
42
+ "0 c #922A2A",
43
+ "a c #A8A827",
44
+ "b c #EFEF0D",
45
+ "c c #C5C520",
46
+ "d c #FBFB03",
47
+ "e c #A6A627",
48
+ "f c #FAFA04",
49
+ "g c #CACA1E",
50
+ "h c #DDDD18",
51
+ "i c #F8F806",
52
+ "j c #B8B823",
53
+ "k c #E3E315",
54
+ "l c #9E2929",
55
+ "m c #D01D1D",
56
+ "n c #B72423",
57
+ "o c #AD2625",
58
+ "p c #DD1817",
59
+ "q c #B22525",
60
+ "r c #D71A1A",
61
+ "s c #EBEB10",
62
+ "t c #B0B025",
63
+ "u c #C0C021",
64
+ "v c #E6E613",
65
+ "w c #97972A",
66
+ "x c #A22828",
67
+ "y c #BB2323",
68
+ "z c #B82424",
69
+ "A c #4A3232",
70
+ "B c #842D2D",
71
+ "C c #912B2B",
72
+ "D c #5B3131",
73
+ "E c #70702F",
74
+ "F c #C6C620",
75
+ "G c #8E8E2B",
76
+ "H c #9A9A29",
77
+ "I c #484832",
78
+ "J c #A4A428",
79
+ "K c #9D2828",
80
+ "L c #E61211",
81
+ "M c #E51212",
82
+ "N c #DF1615",
83
+ "O c #D21B1A",
84
+ "P c #423232",
85
+ "Q c #515131",
86
+ "R c #E4E412",
87
+ "S c #F3F307",
88
+ "T c #E2E213",
89
+ "U c #BEBE20",
90
+ "V c #ECEC0C",
91
+ "W c #B1B124",
92
+ "X c #999928",
93
+ "Y c #CF1D1D",
94
+ "Z c #CD1E1D",
95
+ "` c #D21C1C",
96
+ " . c #A42727",
97
+ ".. c #ED0F0F",
98
+ "+. c #7E2D2D",
99
+ "@. c #92922B",
100
+ "#. c #FDFD01",
101
+ "$. c #D1D11C",
102
+ "%. c #E5E513",
103
+ "&. c #643030",
104
+ "*. c #E61313",
105
+ "=. c #EE0F0E",
106
+ "-. c #A92726",
107
+ ";. c #C1C121",
108
+ ">. c #ADAD25",
109
+ ",. c #EEEE0E",
110
+ "'. c #5C5C31",
111
+ "). c #F00D0C",
112
+ "!. c #AA2726",
113
+ "~. c #AF2525",
114
+ "{. c #EA1110",
115
+ "]. c #32365A",
116
+ "^. c #333440",
117
+ "/. c #E2E215",
118
+ "(. c #F0F00D",
119
+ "_. c #C4C420",
120
+ ":. c #F5F508",
121
+ "<. c #BCBC22",
122
+ "[. c #FCFC02",
123
+ "}. c #8C8C2B",
124
+ "|. c #B92323",
125
+ "1. c #E51413",
126
+ "2. c #633030",
127
+ "3. c #313A74",
128
+ "4. c #2D43AE",
129
+ "5. c #2E40A2",
130
+ "6. c #313975",
131
+ "7. c #77772E",
132
+ "8. c #F7F706",
133
+ "9. c #CBCB1E",
134
+ "0. c #BABA23",
135
+ "a. c #D81919",
136
+ "b. c #A62727",
137
+ "c. c #D41B1B",
138
+ "d. c #C91F1E",
139
+ "e. c #8F2B2B",
140
+ "f. c #323553",
141
+ "g. c #2C45BA",
142
+ "h. c #284CE0",
143
+ "i. c #2A4AD5",
144
+ "j. c #2C46C0",
145
+ "k. c #A3A328",
146
+ "l. c #DEDE17",
147
+ "m. c #772E2E",
148
+ "n. c #EC100F",
149
+ "o. c #AB2626",
150
+ "p. c #B12524",
151
+ "q. c #2B47C8",
152
+ "r. c #2D43AF",
153
+ "s. c #2453FF",
154
+ "t. c #2552FA",
155
+ "u. c #2D44B6",
156
+ "v. c #2C45BE",
157
+ "w. c #BEBE21",
158
+ "x. c #BFBF22",
159
+ "y. c #B2B224",
160
+ "z. c #6B2F2F",
161
+ "A. c #C6201F",
162
+ "B. c #2F409F",
163
+ "C. c #2551F8",
164
+ "D. c #2C44B9",
165
+ "E. c #2452FC",
166
+ "F. c #2F3E92",
167
+ "G. c #585831",
168
+ "H. c #8E8E2A",
169
+ "I. c #79792D",
170
+ "J. c #5C3030",
171
+ "K. c #333333",
172
+ "L. c #313971",
173
+ "M. c #2551F5",
174
+ "N. c #2A49D0",
175
+ "O. c #284EE6",
176
+ "P. c #294BD9",
177
+ "Q. c #294CDD",
178
+ "R. c #2650F1",
179
+ "S. c #323761",
180
+ "T. c #606030",
181
+ "U. c #294CDE",
182
+ "V. c #2D42AD",
183
+ "W. c #2D43B3",
184
+ "X. c #2A4AD6",
185
+ "Y. c #2C45BD",
186
+ "Z. c #303B7C",
187
+ "`. c #2650F0",
188
+ " + c #2650F3",
189
+ ".+ c #2B46C3",
190
+ "++ c #284CDE",
191
+ "@+ c #2A49D1",
192
+ "#+ c #264FED",
193
+ "$+ c #31396F",
194
+ "%+ c #303D90",
195
+ "&+ c #2B47C6",
196
+ "*+ c #31386B",
197
+ "=+ c #2E41A7",
198
+ "-+ c #313A77",
199
+ ";+ c #303C86",
200
+ ">+ c #2551F7",
201
+ ",+ c #2D43B1",
202
+ "'+ c #2E41A6",
203
+ ")+ c #2552FB",
204
+ "!+ c #2552F9",
205
+ "~+ c #2552F8",
206
+ "{+ c #323765",
207
+ "]+ c #2B48CB",
208
+ "^+ c #2A49CF",
209
+ "/+ c #274EE7",
210
+ "(+ c #264FEE",
211
+ "_+ c #2D42AE",
212
+ ":+ c #2650F2",
213
+ "<+ c #294BDA",
214
+ "[+ c #2C46C1",
215
+ "}+ c #313A78",
216
+ "|+ c #2D42AA",
217
+ "1+ c #294BDC",
218
+ "2+ c #2B48CA",
219
+ "3+ c #2453FD",
220
+ " ",
221
+ " ",
222
+ " ",
223
+ " ",
224
+ " ",
225
+ " . + + @ # $ + + + % & * * * = & - * * ; ",
226
+ " > , ' ' ) ! ~ { ' ] ^ / ( _ : < [ } _ _ < | ",
227
+ " 1 2 3 4 5 ' 6 7 3 8 9 0 a b c d e f _ g h i j k ",
228
+ " l ' m n o ' ' ' p q ~ ' r s _ < t b _ _ _ < u v _ w ",
229
+ " x y z A z y y y y B C y y D E F F G H F F F F } I c F J ",
230
+ " K L L ^ M L L L L , N L O P Q R S T U S S S S V W S S X ",
231
+ " Y ' Z ` ' ' ' ' .' ..+. @.#._ < _ _ _ _ $.%._ $. ",
232
+ " &.*.=., ' ' ' ! 5 ' -. } _ ;.( _ _ _ >._ ,.'. ",
233
+ " C ).!.=.' ' ~.{.Z ].^. /.(._._ _ :.<.[.}. ",
234
+ " |.` Z ' ' ~ 1.2. 3.4.5.6. 7.8.>._ _ 9.s 0. ",
235
+ " a.b.' c.d.e. f.g.h.i.j. k.F ,._ < l. ",
236
+ " m. .n.o.p. q.r.s.t.u.v. w.x.( y.E ",
237
+ " z.A.$ B.C.D.s.s.r.E.F. G.H._.I. ",
238
+ " J.K. L.M.N.O.s.s.P.Q.R.S. K.T. ",
239
+ " K. U.s.V.s.s.s.E.W.s.X. ",
240
+ " g.s.M.Y.s.s.s.s.W.E.s.V. ",
241
+ " Z.`. +.+++ + + + +@+N. +#+$+ ",
242
+ " %+&+&+*+W.&+&+&+&+=+-+&+&+;+ ",
243
+ " 6.E.>+,+'+)+s.s.!+=+r.E.~+{+ ",
244
+ " ]+^+/+(+,+s.s._+:+Q.<+[+ ",
245
+ " }+|+s.s.1+q.2+Q.s.3+=+{+ ",
246
+ " 6._+_+_+$+$+_+_+_+*+ ",
247
+ " ",
248
+ " ",
249
+ " ",
250
+ " ",
251
+ " "};
@@ -0,0 +1,64 @@
1
+
2
+ require 'test/unit'
3
+ require 'test/unit/ui/console/testrunner'
4
+ require 'wx'
5
+
6
+ module Wx::SF
7
+
8
+ module Test
9
+
10
+ class App < Wx::App
11
+ def initialize(test_runner, start_mtd)
12
+ super()
13
+ @test_runner = test_runner
14
+ @start_mtd = start_mtd
15
+ end
16
+
17
+ def on_init
18
+ @result = @start_mtd.bind(@test_runner).call
19
+ false
20
+ end
21
+
22
+ attr_reader :result
23
+ end
24
+
25
+ if defined? ::IntelliJ
26
+ require 'test/unit/ui/teamcity/testrunner'
27
+ BaseRunner = ::Test::Unit::UI::TeamCity::TestRunner
28
+ else
29
+ BaseRunner = ::Test::Unit::UI::Console::TestRunner
30
+ end
31
+
32
+ class Runner < BaseRunner
33
+
34
+ org_start_mtd = instance_method :start
35
+ define_method :start do
36
+ (app = Wx::SF::Test::App.new(self, org_start_mtd)).run
37
+ app.result
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ module Test
47
+ module Unit
48
+ AutoRunner.register_runner(:wxapp) do |auto_runner|
49
+ Wx::SF::Test::Runner
50
+ end
51
+ AutoRunner.default_runner = :wxapp
52
+ if defined? ::IntelliJ
53
+ class AutoRunner
54
+ alias :wx_initialize :initialize
55
+ private :wx_initialize
56
+
57
+ def initialize(*args)
58
+ wx_initialize(*args)
59
+ @runner = AutoRunner.default_runner
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
data/tests/test_art.rb ADDED
@@ -0,0 +1,91 @@
1
+
2
+ require_relative './lib/wxapp_runner'
3
+
4
+ class TestArt < Test::Unit::TestCase
5
+
6
+ def test_icons
7
+ icons = []
8
+ assert_nothing_raised do
9
+ icons << Wx.Icon(:sample)
10
+ icons << Wx.Icon(:sample2)
11
+ icons << Wx.Icon(:sample3)
12
+ end
13
+ assert_all?(icons) { |ico| ico.instance_of?(Wx::Icon) }
14
+ assert_all?(icons) { |ico| ico.ok? }
15
+ icons.clear
16
+ assert_nothing_raised do
17
+ icons << Wx.Icon(:wxruby, Wx::BitmapType::BITMAP_TYPE_PNG)
18
+ end
19
+ assert_all?(icons) { |ico| ico.instance_of?(Wx::Icon) }
20
+ assert_all?(icons) { |ico| ico.ok? }
21
+ assert_raises(ArgumentError) do
22
+ Wx::Icon(:wxruby, Wx::BitmapType::BITMAP_TYPE_GIF)
23
+ end
24
+ end
25
+
26
+ def test_bitmap
27
+ bmps = []
28
+ assert_nothing_raised do
29
+ bmps << Wx.Bitmap(:wxruby)
30
+ bmps << Wx.Bitmap(:sample2)
31
+ bmps << Wx.Bitmap(:sample3)
32
+ end
33
+ assert_all?(bmps) { |bmp| bmp.instance_of?(Wx::Bitmap) }
34
+ assert_all?(bmps) { |bmp| bmp.ok? }
35
+ bmps.clear
36
+ assert_nothing_raised do
37
+ bmps << Wx.Bitmap(:wxruby, Wx::BitmapType::BITMAP_TYPE_PNG)
38
+ end
39
+ assert_all?(bmps) { |bmp| bmp.instance_of?(Wx::Bitmap) }
40
+ assert_all?(bmps) { |bmp| bmp.ok? }
41
+ assert_raises(ArgumentError) do
42
+ Wx::Bitmap(:wxruby, Wx::BitmapType::BITMAP_TYPE_GIF)
43
+ end
44
+ end
45
+
46
+ if Wx::PLATFORM == 'WXMSW'
47
+
48
+ def test_cursors
49
+ cursor = nil
50
+ assert_nothing_raised do
51
+ cursor = Wx.Cursor(:wxruby)
52
+ end
53
+ assert_instance_of(Wx::Cursor, cursor)
54
+ assert { cursor.ok? }
55
+ end
56
+
57
+ end
58
+
59
+ def test_image
60
+ imgs = []
61
+ assert_nothing_raised do
62
+ imgs << Wx.Image(:wxruby, Wx::BitmapType::BITMAP_TYPE_JPEG)
63
+ imgs << Wx.Image(:sample2)
64
+ imgs << Wx.Image(:sample3)
65
+ end
66
+ assert_all?(imgs) { |img| img.instance_of?(Wx::Image) }
67
+ assert_all?(imgs) { |img| img.ok? }
68
+ imgs.clear
69
+ assert_nothing_raised do
70
+ imgs << Wx.Image(:wxruby, Wx::BitmapType::BITMAP_TYPE_PNG)
71
+ end
72
+ assert_all?(imgs) { |img| img.instance_of?(Wx::Image) }
73
+ assert_all?(imgs) { |img| img.ok? }
74
+ assert_raises(ArgumentError) do
75
+ Wx::Image(:wxruby, Wx::BitmapType::BITMAP_TYPE_GIF)
76
+ end
77
+ end
78
+
79
+ def test_art
80
+ art = nil
81
+ assert_nothing_raised do
82
+ art = Wx::ArtLocator.find_art(:sample, art_section: 'my_art')
83
+ end
84
+ assert_not_nil(art)
85
+ assert { File.exist?(art) }
86
+ assert_equal('sample', File.basename(art, '.*'))
87
+ img = Wx::Image.new(art)
88
+ assert { img.ok? }
89
+ end
90
+
91
+ end
data/tests/test_basic.rb CHANGED
@@ -13,8 +13,3 @@ class BasicTests < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  end
16
-
17
- if $0 == __FILE__
18
- require 'test/unit/ui/console/testrunner'
19
- Test::Unit::UI::Console::TestRunner.run(BasicTests)
20
- end
@@ -1,6 +1,5 @@
1
- require 'test/unit'
2
- require 'test/unit/ui/console/testrunner'
3
- require 'wx'
1
+
2
+ require_relative './lib/wxapp_runner'
4
3
 
5
4
  class TestTextData < Test::Unit::TestCase
6
5
  # Using an in-built class
@@ -31,7 +30,42 @@ class TestTextData < Test::Unit::TestCase
31
30
  Wx::Clipboard.open do | clip |
32
31
  clip.fetch td_3
33
32
  end
34
- assert_equal("", td_3.text)
33
+ assert_equal("", td_3.get_data_here)
34
+ end
35
+ end
36
+
37
+ if Wx.has_feature?(:USE_HTML) && Wx::WXWIDGETS_VERSION >= '3.3'
38
+ class TestHtmlData < Test::Unit::TestCase
39
+ # Using an in-built class
40
+ def test_text_data
41
+ td = Wx::HTMLDataObject.new('<html><body><h1>Header</h1></body></html>')
42
+ assert_equal('<html><body><h1>Header</h1></body></html>', td.html)
43
+
44
+ Wx::Clipboard.open do | clip |
45
+ assert clip.opened?
46
+ clip.clear
47
+ assert !clip.supported?(Wx::DF_BITMAP)
48
+ clip.place td
49
+ assert clip.supported?(Wx::DF_HTML)
50
+ assert !clip.supported?(Wx::DF_BITMAP)
51
+ end
52
+
53
+ td_2 = Wx::HTMLDataObject.new
54
+ Wx::Clipboard.open do | clip |
55
+ clip.fetch td_2
56
+ end
57
+ assert_equal('<html><body><h1>Header</h1></body></html>', td_2.html)
58
+
59
+ Wx::Clipboard.open do | clip |
60
+ clip.clear
61
+ end
62
+
63
+ td_3 = Wx::HTMLDataObject.new
64
+ Wx::Clipboard.open do | clip |
65
+ clip.fetch td_3
66
+ end
67
+ assert_equal('', td_3.get_data_here)
68
+ end
35
69
  end
36
70
  end
37
71
 
@@ -66,6 +100,37 @@ class TestBitmapData < Test::Unit::TestCase
66
100
  end
67
101
 
68
102
  class TestDataObjectComposite < Test::Unit::TestCase
103
+ MY_INT_ARRAY_FORMAT = Wx::DataFormat.new('application/int_array_format')
104
+
105
+ class MySimpleIntArrayObject < Wx::DataObjectSimpleBase
106
+ def initialize(arr = nil)
107
+ super(MY_INT_ARRAY_FORMAT)
108
+ self.array = arr
109
+ end
110
+
111
+ def array
112
+ @arr
113
+ end
114
+
115
+ def array=(arr)
116
+ @arr = (arr || []).collect { |e| e.to_i }
117
+ end
118
+
119
+ # The default will do in this case but otherwise something like this:
120
+ # def _get_data_size
121
+ # @arr ? @arr.pack('i*').bytesize : 0
122
+ # end
123
+
124
+ def _get_data
125
+ @arr ? @arr.pack('i*') : nil
126
+ end
127
+
128
+ def _set_data(data)
129
+ @arr = data ? data.unpack('i*') : []
130
+ true
131
+ end
132
+ end
133
+
69
134
  def test_data_object_composite
70
135
  d_obj = Wx::DataObjectComposite.new
71
136
  d_txt = Wx::TextDataObject.new
@@ -80,6 +145,9 @@ class TestDataObjectComposite < Test::Unit::TestCase
80
145
  assert_equal( 2, d_txt.get_format_count(Wx::DataObject::Direction::Get) )
81
146
  assert_equal( 3, d_obj.get_format_count(Wx::DataObject::Direction::Get) )
82
147
  end
148
+ d_txt = nil
149
+
150
+ GC.start
83
151
 
84
152
  d_bmp = Wx::BitmapDataObject.new(bmp)
85
153
  Wx::Clipboard.open do | clip |
@@ -87,6 +155,8 @@ class TestDataObjectComposite < Test::Unit::TestCase
87
155
  clip.place d_bmp
88
156
  end
89
157
 
158
+ GC.start
159
+
90
160
  Wx::Clipboard.open do | clip |
91
161
  assert !clip.supported?( Wx::DF_TEXT )
92
162
  assert clip.supported?( Wx::DF_BITMAP )
@@ -94,6 +164,8 @@ class TestDataObjectComposite < Test::Unit::TestCase
94
164
  clip.fetch d_obj
95
165
  end
96
166
 
167
+ GC.start
168
+
97
169
  if Wx::PLATFORM == 'WXMSW'
98
170
  assert_equal d_obj.received_format.get_type, Wx::DF_DIB.get_type
99
171
  d_bmp = d_obj.get_object(Wx::DF_DIB)
@@ -112,6 +184,8 @@ class TestDataObjectComposite < Test::Unit::TestCase
112
184
  clip.place d_txt
113
185
  end
114
186
 
187
+ GC.start
188
+
115
189
  d_obj_2 = Wx::DataObjectComposite.new
116
190
  d_txt = Wx::TextDataObject.new
117
191
  d_obj_2.add d_txt
@@ -125,6 +199,8 @@ class TestDataObjectComposite < Test::Unit::TestCase
125
199
  clip.fetch d_obj_2
126
200
  end
127
201
 
202
+ GC.start
203
+
128
204
  assert_equal d_obj_2.received_format.get_type, d_txt.get_preferred_format(Wx::DataObject::Direction::Set).get_type
129
205
  if Wx::PLATFORM == 'WXMSW'
130
206
  d_txt = d_obj_2.get_object(Wx::DF_UNICODETEXT)
@@ -132,11 +208,58 @@ class TestDataObjectComposite < Test::Unit::TestCase
132
208
  d_txt = d_obj_2.get_object(Wx::DF_TEXT)
133
209
  end
134
210
  assert_equal d_txt.text, 'THE TEXT'
211
+
212
+ GC.start
213
+
214
+ d_obj_2 = Wx::DataObjectComposite.new
215
+ d_obj_2.add Wx::TextDataObject.new
216
+ d_obj_2.add MySimpleIntArrayObject.new([1,2,3,4,5])
217
+ if Wx::PLATFORM == 'WXMSW'
218
+ assert_equal( 2, d_obj_2.get_format_count(Wx::DataObject::Direction::Get) )
219
+ else
220
+ assert_equal( 3, d_obj_2.get_format_count(Wx::DataObject::Direction::Get) )
221
+ end
222
+
223
+ Wx::Clipboard.open do | clip |
224
+ clip.clear
225
+ clip.place d_obj_2
226
+ end
227
+
228
+ GC.start
229
+
230
+ d_iarr = MySimpleIntArrayObject.new
231
+ Wx::Clipboard.open do | clip |
232
+ assert clip.supported?(MY_INT_ARRAY_FORMAT)
233
+ clip.fetch d_iarr
234
+ end
235
+
236
+ assert_equal([1,2,3,4,5], d_iarr.array)
135
237
  end
136
238
  end
137
239
 
138
240
  class TestDataObject < Test::Unit::TestCase
139
241
  MY_CUSTOM_FORMAT = Wx::DataFormat.new('text/custom_format')
242
+ MY_CUSTOM_TEXT = Wx::DataFormat.new('text/custom_text')
243
+
244
+ class MySimpleDataObject < Wx::DataObjectSimpleBase
245
+ def initialize
246
+ super(MY_CUSTOM_TEXT)
247
+ @data = ''
248
+ end
249
+
250
+ def _get_data_size
251
+ @data.bytesize
252
+ end
253
+
254
+ def _get_data
255
+ @data
256
+ end
257
+
258
+ def _set_data(data)
259
+ @data = data ? data : ''
260
+ true
261
+ end
262
+ end
140
263
 
141
264
  class MyBasicDataObject < Wx::DataObject
142
265
  attr_reader :my_data
@@ -187,9 +310,9 @@ class TestDataObject < Test::Unit::TestCase
187
310
  def get_data_size(format)
188
311
  case format.get_type
189
312
  when Wx::DataFormatId::DF_TEXT
190
- get_as_text.to_s.size
313
+ get_as_text.to_s.bytesize
191
314
  when MY_CUSTOM_FORMAT.get_type
192
- get_formatted.to_s.size
315
+ get_formatted.to_s.bytesize
193
316
  else
194
317
  0
195
318
  end
@@ -208,17 +331,35 @@ class TestDataObject < Test::Unit::TestCase
208
331
  end
209
332
  end
210
333
 
334
+ def test_simple_data_obj
335
+ d_obj = MySimpleDataObject.new
336
+ d_obj.set_data('Simple Data')
337
+ assert_equal( 1, d_obj.get_format_count )
338
+ assert_equal('Simple Data', d_obj.get_data_here )
339
+
340
+ Wx::Clipboard.open do | clip |
341
+ clip.place d_obj
342
+ end
343
+
344
+ d_obj2 = MySimpleDataObject.new
345
+ Wx::Clipboard.open do | clip |
346
+ assert clip.supported?( d_obj2.get_format )
347
+ clip.fetch d_obj2
348
+ end
349
+ assert_equal('Simple Data', d_obj2.get_data_here )
350
+ end
351
+
211
352
  def test_data_obj
212
353
  d_obj = MyBasicDataObject.new
213
354
  d_obj.set_data(Wx::DF_TEXT, 'HELLO')
214
- assert_equal( 2, d_obj.get_format_count(0) )
355
+ assert_equal( 2, d_obj.get_format_count(Wx::DataObject::Direction::Get) )
215
356
  assert_equal('HELLO', d_obj.get_data_here(Wx::DF_TEXT) )
216
357
  assert_equal('<b>HELLO</b>', d_obj.get_data_here(MY_CUSTOM_FORMAT) )
217
358
 
218
359
  Wx::Clipboard.open do | clip |
219
360
  clip.place d_obj
220
361
  end
221
-
362
+
222
363
  d_obj_2 = MyBasicDataObject.new
223
364
  Wx::Clipboard.open do | clip |
224
365
  assert clip.supported?( Wx::DF_TEXT )
@@ -230,12 +371,3 @@ class TestDataObject < Test::Unit::TestCase
230
371
  assert_equal('HELLO', d_obj_2.get_data_here(Wx::DF_TEXT) )
231
372
  end
232
373
  end
233
-
234
- Wx::App.run do
235
- # Must run whilst App is alive
236
- Test::Unit::UI::Console::TestRunner.run(TestTextData)
237
- Test::Unit::UI::Console::TestRunner.run(TestBitmapData)
238
- Test::Unit::UI::Console::TestRunner.run(TestDataObjectComposite)
239
- Test::Unit::UI::Console::TestRunner.run(TestDataObject)
240
- false
241
- end