wxruby 1.9.0-i686-linux

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.
Files changed (199) hide show
  1. data/lib/wx.rb +35 -0
  2. data/lib/wx/classes/app.rb +25 -0
  3. data/lib/wx/classes/artprovider.rb +31 -0
  4. data/lib/wx/classes/bitmap.rb +23 -0
  5. data/lib/wx/classes/choice.rb +4 -0
  6. data/lib/wx/classes/clientdc.rb +13 -0
  7. data/lib/wx/classes/colour.rb +47 -0
  8. data/lib/wx/classes/combobox.rb +4 -0
  9. data/lib/wx/classes/evthandler.rb +824 -0
  10. data/lib/wx/classes/font.rb +118 -0
  11. data/lib/wx/classes/grid.rb +130 -0
  12. data/lib/wx/classes/helpcontroller.rb +5 -0
  13. data/lib/wx/classes/htmlhelpcontroller.rb +5 -0
  14. data/lib/wx/classes/htmlwindow.rb +6 -0
  15. data/lib/wx/classes/icon.rb +14 -0
  16. data/lib/wx/classes/image.rb +14 -0
  17. data/lib/wx/classes/listbox.rb +4 -0
  18. data/lib/wx/classes/locale.rb +28 -0
  19. data/lib/wx/classes/object.rb +7 -0
  20. data/lib/wx/classes/paintdc.rb +12 -0
  21. data/lib/wx/classes/point.rb +5 -0
  22. data/lib/wx/classes/previewframe.rb +13 -0
  23. data/lib/wx/classes/rect.rb +5 -0
  24. data/lib/wx/classes/size.rb +5 -0
  25. data/lib/wx/classes/texturlevent.rb +6 -0
  26. data/lib/wx/classes/timer.rb +69 -0
  27. data/lib/wx/classes/window.rb +38 -0
  28. data/lib/wx/classes/xmlresource.rb +16 -0
  29. data/lib/wx/version.rb +3 -0
  30. data/lib/wxruby2.so +0 -0
  31. data/samples/SAMPLES-LICENSE.TXT +18 -0
  32. data/samples/aui/aui.rb +1352 -0
  33. data/samples/bigdemo/About.rbw +39 -0
  34. data/samples/bigdemo/ColorPanel.rbw +25 -0
  35. data/samples/bigdemo/GridSimple.rbw +80 -0
  36. data/samples/bigdemo/MDIDemo.rbw +59 -0
  37. data/samples/bigdemo/PopupMenu.rbw +151 -0
  38. data/samples/bigdemo/ShapedWindow.rbw +135 -0
  39. data/samples/bigdemo/Sizers.rbw +545 -0
  40. data/samples/bigdemo/bigdemo.rb +826 -0
  41. data/samples/bigdemo/demoTemplate.rbw +37 -0
  42. data/samples/bigdemo/helpfile.htb +0 -0
  43. data/samples/bigdemo/icons/Test 015.jpg +0 -0
  44. data/samples/bigdemo/icons/Test 015.png +0 -0
  45. data/samples/bigdemo/icons/choice.bmp +0 -0
  46. data/samples/bigdemo/icons/choice.xpm +27 -0
  47. data/samples/bigdemo/icons/combo.bmp +0 -0
  48. data/samples/bigdemo/icons/combo.xpm +27 -0
  49. data/samples/bigdemo/icons/copy.xpm +25 -0
  50. data/samples/bigdemo/icons/cut.xpm +24 -0
  51. data/samples/bigdemo/icons/gauge.bmp +0 -0
  52. data/samples/bigdemo/icons/gauge.xpm +27 -0
  53. data/samples/bigdemo/icons/help.xpm +25 -0
  54. data/samples/bigdemo/icons/list.bmp +0 -0
  55. data/samples/bigdemo/icons/list.xpm +27 -0
  56. data/samples/bigdemo/icons/mondrian.ico +0 -0
  57. data/samples/bigdemo/icons/mondrian.xpm +44 -0
  58. data/samples/bigdemo/icons/new.xpm +24 -0
  59. data/samples/bigdemo/icons/ogl.ico +0 -0
  60. data/samples/bigdemo/icons/ogl.xpm +45 -0
  61. data/samples/bigdemo/icons/open.xpm +26 -0
  62. data/samples/bigdemo/icons/paste.bmp +0 -0
  63. data/samples/bigdemo/icons/paste.xpm +38 -0
  64. data/samples/bigdemo/icons/pointy.png +0 -0
  65. data/samples/bigdemo/icons/preview.xpm +26 -0
  66. data/samples/bigdemo/icons/print.xpm +26 -0
  67. data/samples/bigdemo/icons/radio.bmp +0 -0
  68. data/samples/bigdemo/icons/radio.xpm +27 -0
  69. data/samples/bigdemo/icons/robert.xpm +415 -0
  70. data/samples/bigdemo/icons/ruby.png +0 -0
  71. data/samples/bigdemo/icons/sashtest.ico +0 -0
  72. data/samples/bigdemo/icons/save.xpm +25 -0
  73. data/samples/bigdemo/icons/smiles.bmp +0 -0
  74. data/samples/bigdemo/icons/smiles.xpm +39 -0
  75. data/samples/bigdemo/icons/smiley.ico +0 -0
  76. data/samples/bigdemo/icons/smiley.xpm +42 -0
  77. data/samples/bigdemo/icons/stattext.xpm +24 -0
  78. data/samples/bigdemo/icons/test2.bmp +0 -0
  79. data/samples/bigdemo/icons/test2.png +0 -0
  80. data/samples/bigdemo/icons/test2.xpm +79 -0
  81. data/samples/bigdemo/icons/text.bmp +0 -0
  82. data/samples/bigdemo/icons/text.xpm +27 -0
  83. data/samples/bigdemo/icons/tog1.bmp +0 -0
  84. data/samples/bigdemo/icons/tog1.xpm +38 -0
  85. data/samples/bigdemo/icons/tog2.bmp +0 -0
  86. data/samples/bigdemo/icons/tog2.xpm +38 -0
  87. data/samples/bigdemo/icons/wxwin.ico +0 -0
  88. data/samples/bigdemo/icons/wxwin16x16.png +0 -0
  89. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -0
  90. data/samples/bigdemo/icons/wxwin32x32.png +0 -0
  91. data/samples/bigdemo/icons/wxwin48x48.png +0 -0
  92. data/samples/bigdemo/run.rb +94 -0
  93. data/samples/bigdemo/tips.txt +7 -0
  94. data/samples/bigdemo/utils.rb +12 -0
  95. data/samples/bigdemo/wxArtProvider.rbw +285 -0
  96. data/samples/bigdemo/wxBitmapButton.rbw +64 -0
  97. data/samples/bigdemo/wxButton.rbw +66 -0
  98. data/samples/bigdemo/wxCalendarCtrl.rbw +72 -0
  99. data/samples/bigdemo/wxCheckBox.rbw +52 -0
  100. data/samples/bigdemo/wxCheckListBox.rbw +77 -0
  101. data/samples/bigdemo/wxChoice.rbw +49 -0
  102. data/samples/bigdemo/wxChoicebook.rbw +80 -0
  103. data/samples/bigdemo/wxColourDialog.rbw +34 -0
  104. data/samples/bigdemo/wxComboBox.rbw +79 -0
  105. data/samples/bigdemo/wxCursor.rbw +140 -0
  106. data/samples/bigdemo/wxDialog.rbw +92 -0
  107. data/samples/bigdemo/wxDirDialog.rbw +32 -0
  108. data/samples/bigdemo/wxDragImage.rbw +74 -0
  109. data/samples/bigdemo/wxFileDialog.rbw +39 -0
  110. data/samples/bigdemo/wxFileDialog_Save.rbw +38 -0
  111. data/samples/bigdemo/wxFindReplaceDialog.rbw +85 -0
  112. data/samples/bigdemo/wxFontDialog.rbw +176 -0
  113. data/samples/bigdemo/wxFrame.rbw +55 -0
  114. data/samples/bigdemo/wxGauge.rbw +73 -0
  115. data/samples/bigdemo/wxGenericDirCtrl.rbw +78 -0
  116. data/samples/bigdemo/wxGrid.rbw +68 -0
  117. data/samples/bigdemo/wxHtmlHelpController.rbw +57 -0
  118. data/samples/bigdemo/wxListBox.rbw +142 -0
  119. data/samples/bigdemo/wxListCtrl_virtual.rbw +109 -0
  120. data/samples/bigdemo/wxMDIWindows.rbw +52 -0
  121. data/samples/bigdemo/wxMenu.rbw +238 -0
  122. data/samples/bigdemo/wxMessageDialog.rbw +30 -0
  123. data/samples/bigdemo/wxMiniFrame.rbw +74 -0
  124. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +34 -0
  125. data/samples/bigdemo/wxNotebook.rbw +138 -0
  126. data/samples/bigdemo/wxProgressDialog.rbw +45 -0
  127. data/samples/bigdemo/wxRadioBox.rbw +74 -0
  128. data/samples/bigdemo/wxRadioButton.rbw +127 -0
  129. data/samples/bigdemo/wxSashWindow.rbw +155 -0
  130. data/samples/bigdemo/wxScrolledMessageDialog.rbw +59 -0
  131. data/samples/bigdemo/wxScrolledWindow.rbw +196 -0
  132. data/samples/bigdemo/wxSingleChoiceDialog.rbw +35 -0
  133. data/samples/bigdemo/wxSlider.rbw +44 -0
  134. data/samples/bigdemo/wxSpinButton.rbw +52 -0
  135. data/samples/bigdemo/wxSpinCtrl.rbw +53 -0
  136. data/samples/bigdemo/wxSplitterWindow.rbw +65 -0
  137. data/samples/bigdemo/wxStaticBitmap.rbw +53 -0
  138. data/samples/bigdemo/wxStaticText.rbw +57 -0
  139. data/samples/bigdemo/wxStatusBar.rbw +128 -0
  140. data/samples/bigdemo/wxTextCtrl.rbw +151 -0
  141. data/samples/bigdemo/wxTextEntryDialog.rbw +34 -0
  142. data/samples/bigdemo/wxToggleButton.rbw +51 -0
  143. data/samples/bigdemo/wxToolBar.rbw +133 -0
  144. data/samples/bigdemo/wxTreeCtrl.rbw +192 -0
  145. data/samples/calendar/calendar.rb +275 -0
  146. data/samples/caret/caret.rb +296 -0
  147. data/samples/caret/mondrian.xpm +44 -0
  148. data/samples/controls/controls.rb +1140 -0
  149. data/samples/controls/get_item_sample.rb +87 -0
  150. data/samples/controls/icons/choice.xpm +27 -0
  151. data/samples/controls/icons/combo.xpm +27 -0
  152. data/samples/controls/icons/gauge.xpm +27 -0
  153. data/samples/controls/icons/list.xpm +27 -0
  154. data/samples/controls/icons/radio.xpm +27 -0
  155. data/samples/controls/icons/stattext.xpm +24 -0
  156. data/samples/controls/icons/text.xpm +27 -0
  157. data/samples/controls/mondrian.ico +0 -0
  158. data/samples/controls/mondrian.xpm +44 -0
  159. data/samples/controls/test2.bmp +0 -0
  160. data/samples/dialogs/dialogs.rb +724 -0
  161. data/samples/dialogs/tips.txt +18 -0
  162. data/samples/etc/activation.rb +108 -0
  163. data/samples/etc/choice.rb +72 -0
  164. data/samples/etc/miniframe.rb +84 -0
  165. data/samples/etc/sash.rb +135 -0
  166. data/samples/etc/scrollwin.rb +116 -0
  167. data/samples/etc/system_settings.rb +258 -0
  168. data/samples/etc/wizard.rb +81 -0
  169. data/samples/grid/grid.rb +201 -0
  170. data/samples/html/html.rb +251 -0
  171. data/samples/images/Thumbs.db +0 -0
  172. data/samples/images/images.rb +48 -0
  173. data/samples/images/paperclip.png +0 -0
  174. data/samples/listbook/listbook.rb +183 -0
  175. data/samples/listbook/listbook.xrc +370 -0
  176. data/samples/mdi/mdi.rb +87 -0
  177. data/samples/minimal/minimal.rb +95 -0
  178. data/samples/minimal/mondrian.ico +0 -0
  179. data/samples/minimal/mondrian.xpm +44 -0
  180. data/samples/minimal/nothing.rb +46 -0
  181. data/samples/minimal/text.rb +35 -0
  182. data/samples/printing/mondrian.ico +0 -0
  183. data/samples/printing/mondrian.xpm +44 -0
  184. data/samples/printing/printing.rb +484 -0
  185. data/samples/text/mondrian.ico +0 -0
  186. data/samples/text/mondrian.xpm +44 -0
  187. data/samples/text/scintilla.rb +180 -0
  188. data/samples/text/textctrl.rb +124 -0
  189. data/samples/text/unicode.rb +238 -0
  190. data/samples/text/utf8.txt +15 -0
  191. data/samples/treectrl/icon1.xpm +79 -0
  192. data/samples/treectrl/icon2.xpm +53 -0
  193. data/samples/treectrl/icon3.xpm +79 -0
  194. data/samples/treectrl/icon4.xpm +43 -0
  195. data/samples/treectrl/icon5.xpm +79 -0
  196. data/samples/treectrl/treectrl.rb +1210 -0
  197. data/samples/xrc/samples.xrc +46 -0
  198. data/samples/xrc/xrc_sample.rb +107 -0
  199. metadata +264 -0
@@ -0,0 +1,296 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2006 Kevin B. Smith
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+
5
+ begin
6
+ require 'wx'
7
+ rescue LoadError => no_wx_err
8
+ begin
9
+ require 'rubygems'
10
+ require 'wx'
11
+ rescue LoadError
12
+ raise no_wx_err
13
+ end
14
+ end
15
+ include Wx
16
+
17
+ # menu items
18
+ Caret_Quit = ID_EXIT
19
+ Caret_About = ID_ABOUT
20
+ Caret_set_blink_time = 3
21
+ Caret_Move = 4
22
+
23
+ # controls start here (the numbers are, of course, arbitrary)
24
+ Caret_Text = 1000
25
+
26
+
27
+ # MyCanvas is a canvas on which you can type
28
+ class MyCanvas < ScrolledWindow
29
+ def initialize(parent)
30
+ super(parent, -1,
31
+ DEFAULT_POSITION, DEFAULT_SIZE,
32
+ SUNKEN_BORDER )
33
+
34
+ set_background_colour(WHITE)
35
+
36
+ @font = Font.new(12, FONTFAMILY_TELETYPE,
37
+ FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL)
38
+
39
+ @x_caret = @y_caret =
40
+ @x_chars = @y_chars = 0
41
+
42
+ @x_margin = @y_margin = 5
43
+ @text = nil
44
+
45
+ create_caret
46
+
47
+ evt_paint {on_paint}
48
+ evt_size {|event| on_size(event)}
49
+ evt_char {|event| on_char(event)}
50
+ end
51
+
52
+ def [](x,y)
53
+ @text[x + @x_chars * y,1]
54
+ end
55
+
56
+ def []=(x,y,z)
57
+ @text[x + @x_chars * y,1] = z
58
+ end
59
+
60
+ # caret movement
61
+ def home_pos
62
+ @x_caret = 0
63
+ end
64
+
65
+ def end_pos
66
+ @x_caret = @x_chars - 1
67
+ end
68
+
69
+ def first_line
70
+ @y_caret = 0
71
+ end
72
+
73
+ def last_line
74
+ @y_caret = @y_chars - 1
75
+ end
76
+
77
+ def prev_char
78
+ if @x_caret == 0
79
+ end_pos
80
+ prev_line
81
+ else
82
+ @x_caret -= 1
83
+ end
84
+ end
85
+
86
+ def next_char
87
+ @x_caret += 1
88
+ if @x_caret == @x_chars
89
+ home_pos
90
+ next_line
91
+ end
92
+ end
93
+
94
+ def prev_line
95
+ if @y_caret == 0
96
+ last_line
97
+ else
98
+ @y_caret -= 1
99
+ end
100
+ end
101
+
102
+ def next_line
103
+ @y_caret += 1
104
+ if @y_caret == @y_chars
105
+ first_line
106
+ end
107
+ end
108
+
109
+ def create_caret
110
+ paint do | dc |
111
+ dc.set_font(@font)
112
+ @height_char = dc.get_char_height
113
+ @width_char = dc.get_char_width
114
+
115
+ caret = Caret.new(self, Size.new(@width_char, @height_char))
116
+ set_caret(caret)
117
+
118
+ caret.move(Point.new(@x_margin, @y_margin))
119
+ caret.show
120
+ end
121
+ end
122
+
123
+ def move_caret(x,y)
124
+ @x_caret = x
125
+ @y_caret = y
126
+
127
+ do_move_caret
128
+ end
129
+
130
+ def do_move_caret
131
+ log_status("Caret is at (%d, %d)", @x_caret, @y_caret)
132
+
133
+ get_caret.move_xy(@x_margin + @x_caret * @width_char,
134
+ @y_margin + @y_caret * @height_char)
135
+ end
136
+
137
+ def on_size(event)
138
+ @x_chars = (event.get_size.x - 2*@x_margin) / @width_char
139
+ @y_chars = (event.get_size.y - 2*@y_margin) / @height_char
140
+ if @x_chars <= 0
141
+ @x_chars = 1
142
+ end
143
+ if @y_chars <= 0
144
+ @y_chars = 1
145
+ end
146
+ if @x_caret >= @x_chars
147
+ @x_caret = @x_chars-1
148
+ end
149
+ if @y_caret >= @y_chars
150
+ @y_caret = @y_chars-1
151
+ end
152
+
153
+ @text = " " * @x_chars * @y_chars
154
+
155
+ frame = get_parent
156
+ if frame && frame.get_status_bar
157
+ msg = sprintf("Panel size is (%d, %d)", @x_chars, @y_chars)
158
+ frame.set_status_text(msg, 1)
159
+ frame.refresh
160
+ end
161
+ event.skip
162
+ end
163
+
164
+ def on_paint
165
+ caret = get_caret
166
+ if caret
167
+ caret.hide
168
+ end
169
+
170
+ paint do | dc |
171
+ dc.clear
172
+ dc.set_font(@font)
173
+
174
+ for y in 0 ... @y_chars
175
+ line = @text[@x_chars * y,@x_chars]
176
+ dc.draw_text( line, @x_margin, @y_margin + y * @height_char )
177
+ end
178
+ end
179
+
180
+ if caret
181
+ caret.show
182
+ end
183
+
184
+ end
185
+
186
+ def on_char(event)
187
+ case event.key_code
188
+ when K_LEFT, K_BACK
189
+ prev_char
190
+ when K_RIGHT
191
+ next_char
192
+ when K_UP
193
+ prev_line
194
+ when K_DOWN
195
+ next_line
196
+ when K_HOME
197
+ home_pos
198
+ when K_END
199
+ end_pos
200
+ when K_RETURN
201
+ home_pos
202
+ next_line
203
+ else
204
+ ch = event.key_code
205
+ if !event.alt_down and (ch >= K_SPACE) and (ch < K_DELETE)
206
+ self[@x_caret, @y_caret] = ch.chr
207
+ refresh
208
+ next_char
209
+ else
210
+ event.skip
211
+ end
212
+ end
213
+ do_move_caret
214
+ end
215
+
216
+ end
217
+
218
+ class MyFrame < Frame
219
+ def initialize(title,pos,size)
220
+ super(nil, -1, title, pos, size)
221
+ # set the frame icon
222
+ icon_file = File.join(File.dirname(__FILE__), 'mondrian.xpm')
223
+ set_icon(Icon.new(icon_file, BITMAP_TYPE_XPM))
224
+
225
+ # create a menu bar
226
+ menu_file = Menu.new
227
+
228
+ menu_file.append(Caret_set_blink_time, "&Blink time...\tCtrl-B")
229
+ menu_file.append(Caret_Move, "&Move caret\tCtrl-C")
230
+ menu_file.append_separator
231
+ menu_file.append(Caret_About, "&About...\tCtrl-A", "Show about dialog")
232
+ menu_file.append_separator
233
+ menu_file.append(Caret_Quit, "E&xit\tAlt-X", "Quit self program")
234
+
235
+ # now append the freshly created menu to the menu bar...
236
+ menu_bar = MenuBar.new
237
+ menu_bar.append(menu_file, "&File")
238
+
239
+ # ... and attach self menu bar to the frame
240
+ set_menu_bar(menu_bar)
241
+
242
+ @canvas = MyCanvas.new(self)
243
+
244
+ # This is required to set focus so that key events are directed to
245
+ # this Window, on Linux/GTK in particular
246
+ @canvas.set_focus
247
+
248
+ # create a status bar just for fun (by default with 1 pane only)
249
+ create_status_bar(2)
250
+ set_status_text("Welcome to Windows!")
251
+
252
+ evt_menu(Caret_Quit) {on_quit}
253
+ evt_menu(Caret_About) {on_about}
254
+ evt_menu(Caret_set_blink_time) {on_set_blink_time}
255
+ evt_menu(Caret_Move) {on_caret_move}
256
+ end
257
+
258
+ def on_quit
259
+ # true is to force the frame to close
260
+ close(true)
261
+ end
262
+
263
+ def on_about
264
+ message_box("The caret Windows sample, adapted for WxRuby",
265
+ "About Caret", OK | ICON_INFORMATION, self)
266
+ end
267
+
268
+ def on_caret_move
269
+ @canvas.move_caret(10, 10)
270
+ end
271
+
272
+ def on_set_blink_time
273
+ blink_time = get_number_from_user(
274
+ "The caret blink time is the time between two blinks",
275
+ "Time in milliseconds:",
276
+ "Caret sample",
277
+ Caret::get_blink_time, 0, 10000,
278
+ self)
279
+ if blink_time != -1
280
+ Caret::set_blink_time(blink_time)
281
+ @canvas.create_caret
282
+ log_status(self,"Blink time set to %d milliseconds.", blink_time)
283
+ end
284
+ end
285
+ end
286
+
287
+ class CaretApp < App
288
+ def on_init
289
+ frame = MyFrame.new("Caret Windows sample",
290
+ Point.new(50, 50), Size.new(450, 340))
291
+ frame.show(true)
292
+ end
293
+ end
294
+
295
+ a = CaretApp.new
296
+ a.main_loop
@@ -0,0 +1,44 @@
1
+ /* XPM */
2
+ static char *mondrian_xpm[] = {
3
+ /* columns rows colors chars-per-pixel */
4
+ "32 32 6 1",
5
+ " c Black",
6
+ ". c Blue",
7
+ "X c #00bf00",
8
+ "o c Red",
9
+ "O c Yellow",
10
+ "+ c Gray100",
11
+ /* pixels */
12
+ " ",
13
+ " oooooo +++++++++++++++++++++++ ",
14
+ " oooooo +++++++++++++++++++++++ ",
15
+ " oooooo +++++++++++++++++++++++ ",
16
+ " oooooo +++++++++++++++++++++++ ",
17
+ " oooooo +++++++++++++++++++++++ ",
18
+ " oooooo +++++++++++++++++++++++ ",
19
+ " oooooo +++++++++++++++++++++++ ",
20
+ " ",
21
+ " ++++++ ++++++++++++++++++ .... ",
22
+ " ++++++ ++++++++++++++++++ .... ",
23
+ " ++++++ ++++++++++++++++++ .... ",
24
+ " ++++++ ++++++++++++++++++ .... ",
25
+ " ++++++ ++++++++++++++++++ .... ",
26
+ " ++++++ ++++++++++++++++++ ",
27
+ " ++++++ ++++++++++++++++++ ++++ ",
28
+ " ++++++ ++++++++++++++++++ ++++ ",
29
+ " ++++++ ++++++++++++++++++ ++++ ",
30
+ " ++++++ ++++++++++++++++++ ++++ ",
31
+ " ++++++ ++++++++++++++++++ ++++ ",
32
+ " ++++++ ++++++++++++++++++ ++++ ",
33
+ " ++++++ ++++++++++++++++++ ++++ ",
34
+ " ++++++ ++++++++++++++++++ ++++ ",
35
+ " ++++++ ++++++++++++++++++ ++++ ",
36
+ " ++++++ ++++ ",
37
+ " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
38
+ " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
39
+ " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
40
+ " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
41
+ " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
42
+ " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
43
+ " "
44
+ };
@@ -0,0 +1,1140 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2006 Kevin B. Smith
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+
5
+ begin
6
+ require 'wx'
7
+ rescue LoadError => no_wx_err
8
+ begin
9
+ require 'rubygems'
10
+ require 'wx'
11
+ rescue LoadError
12
+ raise no_wx_err
13
+ end
14
+ end
15
+ include Wx
16
+
17
+ CONTROLS_QUIT = ID_EXIT
18
+ CONTROLS_TEXT = 101
19
+ CONTROLS_ABOUT = ID_ABOUT
20
+ CONTROLS_CLEAR_LOG = 103
21
+ # tooltip menu
22
+ CONTROLS_SET_TOOLTIP_DELAY = 200
23
+ CONTROLS_ENABLE_TOOLTIPS = 201
24
+ # panel menu
25
+ CONTROLS_ENABLE_ALL = 202
26
+
27
+
28
+ ID_NOTEBOOK = 1000
29
+
30
+ ID_LISTBOX = 130
31
+ ID_LISTBOX_SEL_NUM = 131
32
+ ID_LISTBOX_SEL_STR = 132
33
+ ID_LISTBOX_CLEAR = 133
34
+ ID_LISTBOX_APPEND = 134
35
+ ID_LISTBOX_DELETE = 135
36
+ ID_LISTBOX_FONT = 136
37
+ ID_LISTBOX_ENABLE = 137
38
+ ID_LISTBOX_SORTED = 138
39
+
40
+ ID_CHOICE = 120
41
+ ID_CHOICE_SEL_NUM = 121
42
+ ID_CHOICE_SEL_STR = 122
43
+ ID_CHOICE_CLEAR = 123
44
+ ID_CHOICE_APPEND = 124
45
+ ID_CHOICE_DELETE = 125
46
+ ID_CHOICE_FONT = 126
47
+ ID_CHOICE_ENABLE = 127
48
+ ID_CHOICE_SORTED = 128
49
+
50
+ ID_COMBO = 140
51
+ ID_COMBO_SEL_NUM = 141
52
+ ID_COMBO_SEL_STR = 142
53
+ ID_COMBO_CLEAR = 143
54
+ ID_COMBO_APPEND = 144
55
+ ID_COMBO_DELETE = 145
56
+ ID_COMBO_FONT = 146
57
+ ID_COMBO_ENABLE = 147
58
+
59
+ ID_RADIOBOX = 160
60
+ ID_RADIOBOX_SEL_NUM = 161
61
+ ID_RADIOBOX_SEL_STR = 162
62
+ ID_RADIOBOX_FONT = 163
63
+ ID_RADIOBOX_ENABLE = 164
64
+
65
+ ID_RADIOBUTTON_1 = 166
66
+ ID_RADIOBUTTON_2 = 167
67
+
68
+ ID_SET_FONT = 170
69
+
70
+ ID_GAUGE = 180
71
+ ID_SLIDER = 181
72
+
73
+ ID_SPIN = 182
74
+ ID_BTNPROGRESS = 183
75
+ ID_BUTTON_LABEL = 184
76
+ ID_SPINCTRL = 185
77
+
78
+ ID_BUTTON_TEST1 = 190
79
+ ID_BUTTON_TEST2 = 191
80
+ ID_BITMAP_BTN = 192
81
+
82
+ ID_CHANGE_COLOUR = 200
83
+
84
+ ID_SIZER_CHECK1 = 201
85
+ ID_SIZER_CHECK2 = 202
86
+ ID_SIZER_CHECK3 = 203
87
+ ID_SIZER_CHECK4 = 204
88
+ ID_SIZER_CHECK14 = 205
89
+ ID_SIZER_CHECKBIG = 206
90
+
91
+ Image_List, Image_Choice, Image_Combo, Image_Text, Image_Radio, Image_Gauge, Image_Max = (0..6).to_a
92
+
93
+
94
+ # a button which intercepts double clicks (for testing...)
95
+ class MyButton < Button
96
+ def initialize(parent,id,label = EmptyString,pos = DEFAULT_POSITION,size = DEFAULT_SIZE)
97
+ super(parent,id,label,pos,size)
98
+
99
+ evt_left_dclick {|event| onDClick(event)}
100
+ end
101
+
102
+ def onDClick(event)
103
+ log_message("MyButton::OnDClick")
104
+ event.skip()
105
+ end
106
+
107
+ end
108
+
109
+ # a combo which intercepts chars (to test Windows behaviour)
110
+ class MyComboBox < ComboBox
111
+ def initialize(parent,id,value = EmptyString,
112
+ pos = DEFAULT_POSITION,
113
+ size = DEFAULT_SIZE,
114
+ choices = [],
115
+ style = 0)
116
+ super(parent, id, value, pos, size, choices)#, style)
117
+
118
+ evt_char {|event| onChar(event)}
119
+ evt_key_down {|event| onKeyDown(event)}
120
+ evt_key_up {|event| onKeyUp(event)}
121
+
122
+ evt_set_focus {|event| onFocusGot(event)}
123
+ end
124
+
125
+ def onChar(event)
126
+ log_message("MyComboBox::OnChar")
127
+ if event.key_code() == ?w
128
+ log_message("MyComboBox: 'w' will be ignored.")
129
+ else
130
+ event.skip()
131
+ end
132
+ end
133
+
134
+ def onKeyDown(event)
135
+ log_message("MyComboBox::OnKeyDown")
136
+ if event.key_code() == ?w
137
+ log_message("MyComboBox: 'w' will be ignored.")
138
+ else
139
+ event.skip()
140
+ end
141
+ end
142
+
143
+ def onKeyUp(event)
144
+ #log_message("MyComboBox::OnKeyUp")
145
+ event.skip()
146
+ end
147
+
148
+ def onFocusGot(event)
149
+ #log_message("MyComboBox::OnFocusGot")
150
+ event.skip()
151
+ end
152
+
153
+ end
154
+
155
+ # a radiobox which handles focus set/kill (for testing)
156
+ class MyRadioBox < RadioBox
157
+ def initialize(parent,
158
+ id,title = EmptyString,
159
+ pos = DEFAULT_POSITION,
160
+ size = DEFAULT_SIZE,
161
+ choices = [],
162
+ majorDim = 1,
163
+ style = RA_HORIZONTAL)
164
+ super(parent, id, title, pos, size, choices, majorDim,style)
165
+ set_foreground_colour(RED)
166
+
167
+ evt_set_focus {|event| onFocusGot(event)}
168
+ evt_kill_focus {|event| onFocusLost(event)}
169
+
170
+ end
171
+
172
+ def onFocusGot(event)
173
+ log_message("MyRadioBox::OnFocusGot")
174
+ event.skip()
175
+ end
176
+
177
+ def onFocusLost(event)
178
+ log_message("MyRadioBox::OnFocusLost")
179
+ event.skip()
180
+ end
181
+
182
+ end
183
+
184
+
185
+ class MyPanel < Panel
186
+
187
+ # delete Log::set_active_target(@m_logTargetOld)
188
+ # delete @m_notebook.GetImageList()
189
+ attr_reader :m_text,:m_logTargetOld
190
+
191
+ def initialize(frame,x,y,w,h)
192
+ super( frame, -1, Point.new(x, y), Size.new(w, h) )
193
+
194
+ @s_colOld = NULL_COLOUR
195
+
196
+ @m_text = TextCtrl.new(self, -1, "This is the log window.\n",
197
+ Point.new(0, 250), Size.new(100, 50), TE_MULTILINE)
198
+ @m_text.set_background_colour(Colour.new("wheat"))
199
+
200
+ #@m_logTargetOld = Log::set_active_target(LogTextCtrl.new(@m_text))
201
+
202
+ @m_notebook = Wx::Notebook.new(self, ID_NOTEBOOK)
203
+
204
+ choices = [
205
+ "This",
206
+ "is one of my",
207
+ "really",
208
+ "wonderful",
209
+ "examples."
210
+ ]
211
+
212
+ # fill the image list
213
+
214
+ imagelist = ImageList.new(16, 16)
215
+
216
+ imagelist.add( Bitmap.new( local_icon_file("list.xpm"),
217
+ Wx::BITMAP_TYPE_XPM))
218
+ imagelist.add( Bitmap.new( local_icon_file("choice.xpm"),
219
+ Wx::BITMAP_TYPE_XPM))
220
+ imagelist.add( Bitmap.new( local_icon_file("combo.xpm"),
221
+ Wx::BITMAP_TYPE_XPM))
222
+ imagelist.add( Bitmap.new( local_icon_file("text.xpm"),
223
+ Wx::BITMAP_TYPE_XPM))
224
+ imagelist.add( Bitmap.new( local_icon_file("radio.xpm"),
225
+ Wx::BITMAP_TYPE_XPM))
226
+ imagelist.add( Bitmap.new( local_icon_file("gauge.xpm"),
227
+ Wx::BITMAP_TYPE_XPM))
228
+
229
+ @m_notebook.set_image_list(imagelist)
230
+
231
+ panel = Panel.new(@m_notebook)
232
+ @m_listbox = ListBox.new( panel, ID_LISTBOX,
233
+ Point.new(10,10), Size.new(120,70),
234
+ choices, LB_ALWAYS_SB )
235
+
236
+ @m_listboxSorted = ListBox.new( panel, ID_LISTBOX_SORTED,
237
+ Point.new(10,90), Size.new(120,70),
238
+ choices, LB_SORT )
239
+
240
+
241
+ @m_listbox.set_cursor(CROSS_CURSOR)
242
+
243
+ @m_listbox.set_tool_tip( "This is a list box" )
244
+
245
+
246
+ @m_lbSelectNum = Button.new( panel, ID_LISTBOX_SEL_NUM, "Select #&2", Point.new(180,30), Size.new(140,30) )
247
+ @m_lbSelectThis = Button.new( panel, ID_LISTBOX_SEL_STR, "&Select 'This'", Point.new(340,30), Size.new(140,30) )
248
+ Button.new( panel, ID_LISTBOX_CLEAR, "&clear", Point.new(180,80), Size.new(140,30) )
249
+ MyButton.new( panel, ID_LISTBOX_APPEND, "&append 'Hi!'", Point.new(340,80), Size.new(140,30) )
250
+ Button.new( panel, ID_LISTBOX_DELETE, "D&elete selected item", Point.new(180,130), Size.new(140,30) )
251
+ button = MyButton.new( panel, ID_LISTBOX_FONT, "Set &Italic font", Point.new(340,130), Size.new(140,30) )
252
+
253
+ button.set_default()
254
+
255
+ button.set_foreground_colour(BLUE)
256
+
257
+ button.set_tool_tip( "Press here to set italic font" )
258
+
259
+ @m_checkbox = CheckBox.new( panel, ID_LISTBOX_ENABLE, "&Disable", Point.new(20,170) )
260
+ @m_checkbox.set_value(FALSE)
261
+ @m_checkbox.set_tool_tip( "Click here to disable the listbox" )
262
+ @m_toggle_color = CheckBox.new( panel, ID_CHANGE_COLOUR, "&Toggle colour",
263
+ Point.new(110,170) )
264
+ panel.set_cursor(Cursor.new(CURSOR_HAND))
265
+ @m_notebook.add_page(panel, "ListBox", TRUE, Image_List)
266
+
267
+ panel = Panel.new(@m_notebook)
268
+ @m_choice = Choice.new( panel, ID_CHOICE, Point.new(10,10), Size.new(120,-1), choices )
269
+ @m_choiceSorted = Choice.new( panel, ID_CHOICE_SORTED, Point.new(10,70), Size.new(120,-1),
270
+ choices, CB_SORT )
271
+
272
+ @m_choice.set_selection(2)
273
+ @m_choice.set_background_colour(Colour.new("red"))
274
+ Button.new( panel, ID_CHOICE_SEL_NUM, "Select #&2", Point.new(180,30), Size.new(140,30) )
275
+ Button.new( panel, ID_CHOICE_SEL_STR, "&Select 'This'", Point.new(340,30), Size.new(140,30) )
276
+ Button.new( panel, ID_CHOICE_CLEAR, "&clear", Point.new(180,80), Size.new(140,30) )
277
+ Button.new( panel, ID_CHOICE_APPEND, "&append 'Hi!'", Point.new(340,80), Size.new(140,30) )
278
+ Button.new( panel, ID_CHOICE_DELETE, "D&elete selected item", Point.new(180,130), Size.new(140,30) )
279
+ Button.new( panel, ID_CHOICE_FONT, "Set &Italic font", Point.new(340,130), Size.new(140,30) )
280
+ CheckBox.new( panel, ID_CHOICE_ENABLE, "&Disable", Point.new(20,130), Size.new(140,30) )
281
+
282
+ @m_notebook.add_page(panel, "Choice", FALSE, Image_Choice)
283
+
284
+ panel = Panel.new(@m_notebook)
285
+ StaticBox.new( panel, -1, "&Box around combobox",
286
+ Point.new(5, 5), Size.new(150, 100))
287
+ @m_combo = MyComboBox.new( panel, ID_COMBO, "This",
288
+ Point.new(20,25), Size.new(120, -1),
289
+ choices,PROCESS_ENTER)
290
+ # CB_READONLY | PROCESS_ENTER)
291
+
292
+ @m_combo.set_tool_tip("This is a natural\ncombobox - can you believe me?")
293
+
294
+ Button.new( panel, ID_COMBO_SEL_NUM, "Select #&2", Point.new(180,30), Size.new(140,30) )
295
+ Button.new( panel, ID_COMBO_SEL_STR, "&Select 'This'", Point.new(340,30), Size.new(140,30) )
296
+ Button.new( panel, ID_COMBO_CLEAR, "&clear", Point.new(180,80), Size.new(140,30) )
297
+ Button.new( panel, ID_COMBO_APPEND, "&append 'Hi!'", Point.new(340,80), Size.new(140,30) )
298
+ Button.new( panel, ID_COMBO_DELETE, "D&elete selected item", Point.new(180,130), Size.new(140,30) )
299
+ Button.new( panel, ID_COMBO_FONT, "Set &Italic font", Point.new(340,130), Size.new(140,30) )
300
+ CheckBox.new( panel, ID_COMBO_ENABLE, "&Disable", Point.new(20,130), Size.new(140,30) )
301
+ @m_notebook.add_page(panel, "ComboBox", FALSE, Image_Combo)
302
+
303
+ choices2 = ["First", "Second"]
304
+ # "Third",
305
+ #"Fourth", "Fifth", "Sixth",
306
+ #"Seventh", "Eighth", "Nineth", "Tenth" */
307
+
308
+ panel = Panel.new(@m_notebook)
309
+ MyRadioBox.new( panel, ID_RADIOBOX, "&That", Point.new(10,160), Size.new(-1,-1), choices2, 1, RA_SPECIFY_ROWS )
310
+ @m_radio = RadioBox.new( panel, ID_RADIOBOX, "T&his", Point.new(10,10), Size.new(-1,-1), choices, 1, RA_SPECIFY_COLS )
311
+ @m_radio.set_foreground_colour(RED)
312
+
313
+ @m_radio.set_tool_tip("Ever seen a radiobox?")
314
+
315
+ Button.new( panel, ID_RADIOBOX_SEL_NUM, "Select #&2", Point.new(180,30), Size.new(140,30) )
316
+ Button.new( panel, ID_RADIOBOX_SEL_STR, "&Select 'This'", Point.new(180,80), Size.new(140,30) )
317
+ @m_fontButton = Button.new( panel, ID_SET_FONT, "Set &more Italic font", Point.new(340,30), Size.new(140,30) )
318
+ Button.new( panel, ID_RADIOBOX_FONT, "Set &Italic font", Point.new(340,80), Size.new(140,30) )
319
+ CheckBox.new( panel, ID_RADIOBOX_ENABLE, "&Disable", Point.new(340,130), DEFAULT_SIZE )
320
+ rb = RadioButton.new( panel, ID_RADIOBUTTON_1, "Radiobutton1", Point.new(210,170), DEFAULT_SIZE, RB_GROUP )
321
+ rb.set_value( FALSE )
322
+ RadioButton.new( panel, ID_RADIOBUTTON_2, "&Radiobutton2", Point.new(340,170), DEFAULT_SIZE )
323
+ @m_notebook.add_page(panel, "RadioBox", FALSE, Image_Radio)
324
+
325
+ panel = Panel.new(@m_notebook)
326
+ StaticBox.new( panel, -1, "&Gauge and Slider", Point.new(10,10), Size.new(222,130) )
327
+ @m_gauge = Gauge.new( panel, -1, 200, Point.new(18,50), Size.new(155, 30), GA_HORIZONTAL|NO_BORDER )
328
+ @m_gauge.set_background_colour(GREEN)
329
+ @m_gauge.set_foreground_colour(RED)
330
+ @m_gaugeVert = Gauge.new( panel, -1, 100,
331
+ Point.new(195,35), Size.new(30, 90),
332
+ GA_VERTICAL | GA_SMOOTH | NO_BORDER )
333
+ @m_slider = Slider.new( panel, ID_SLIDER, 0, 0, 200, Point.new(18,90), Size.new(155,-1),
334
+ SL_AUTOTICKS | SL_LABELS )
335
+ @m_slider.set_tick_freq(40, 0)
336
+ @m_slider.set_tool_tip("This is a sliding slider")
337
+
338
+ StaticBox.new( panel, -1, "&Explanation",
339
+ Point.new(230,10), Size.new(270,130),
340
+ ALIGN_CENTER )
341
+
342
+ StaticText.new( panel, -1,
343
+ "In order see the gauge (aka progress bar)\n"+
344
+ "control do something you have to drag the\n"+
345
+ "handle of the slider to the right.\n"+
346
+ "\n"+
347
+ "This is also supposed to demonstrate how\n"+
348
+ "to use static controls.\n",
349
+ Point.new(250,25),
350
+ Size.new(240, 110))
351
+ initialSpinValue = -5
352
+ s = initialSpinValue.to_s
353
+ @m_spintext = TextCtrl.new( panel, -1, s, Point.new(20,160), Size.new(80,-1) )
354
+ @m_spinbutton = SpinButton.new( panel, ID_SPIN, Point.new(103,160), Size.new(80, -1) )
355
+ @m_spinbutton.set_range(-40,30)
356
+ @m_spinbutton.set_value(initialSpinValue)
357
+
358
+ @m_btnProgress = Button.new( panel, ID_BTNPROGRESS, "&Show progress dialog",
359
+ Point.new(300, 160) )
360
+
361
+ @m_spinctrl = SpinCtrl.new( panel, ID_SPINCTRL, "", Point.new(200, 160), Size.new(80, -1) )
362
+ @m_spinctrl.set_range(10,30)
363
+ @m_spinctrl.set_value(15)
364
+
365
+ @m_notebook.add_page(panel, "Gauge", FALSE, Image_Gauge)
366
+
367
+ panel = Panel.new(@m_notebook)
368
+
369
+ icon = ArtProvider::get_icon(ART_INFORMATION)
370
+ StaticBitmap.new( panel, -1, icon, Point.new(10, 10) )
371
+
372
+ bitmap = Bitmap.new( 100, 100 )
373
+ bitmap.draw do | dc |
374
+ dc.clear()
375
+ dc.set_pen(GREEN_PEN)
376
+ dc.draw_ellipse(5, 5, 90, 90)
377
+ dc.draw_text("Bitmap", 30, 40)
378
+ end
379
+
380
+ BitmapButton.new(panel, ID_BITMAP_BTN, bitmap, Point.new(100, 20))
381
+
382
+ # test for masked bitmap display
383
+ bitmap = Bitmap.new( File.join(File.dirname(__FILE__), "test2.bmp"),
384
+ BITMAP_TYPE_BMP)
385
+ if bitmap.is_ok()
386
+ bitmap.set_mask(Mask.new(bitmap, BLUE))
387
+ StaticBitmap.new(panel, -1, bitmap, Point.new(300, 120))
388
+ end
389
+ # bmp1 = ArtProvider::get_bitmap(ART_INFORMATION)
390
+ # bmp2 = ArtProvider::get_bitmap(ART_WARNING)
391
+ # bmp3 = ArtProvider::get_bitmap(ART_QUESTION)
392
+ # bmpBtn = BitmapButton.new(panel, -1,
393
+ # bmp1,
394
+ # Point.new(30, 70))
395
+
396
+ # bmpBtn.set_bitmap_selected(bmp2)
397
+ # bmpBtn.set_bitmap_focus(bmp3)
398
+ ToggleButton.new(panel, ID_BUTTON_LABEL,
399
+ "&Toggle label", Point.new(250, 20))
400
+ @m_label = StaticText.new(panel, -1, "Label with some long text",
401
+ Point.new(250, 60), DEFAULT_SIZE,
402
+ ALIGN_RIGHT)
403
+ @m_label.set_foreground_colour(BLUE )
404
+
405
+ @m_notebook.add_page(panel, "BitmapXXX")
406
+
407
+ # sizer
408
+
409
+ panel = Panel.new(@m_notebook)
410
+ panel.set_auto_layout( TRUE )
411
+
412
+ sizer = BoxSizer.new( VERTICAL )
413
+
414
+ csizer =
415
+ StaticBoxSizer.new(StaticBox.new(panel, -1, "Show Buttons"),
416
+ HORIZONTAL )
417
+
418
+ check1 = CheckBox.new(panel, ID_SIZER_CHECK1, "1")
419
+ check1.set_value(TRUE)
420
+ csizer.add(check1)
421
+ check2 = CheckBox.new(panel, ID_SIZER_CHECK2, "2")
422
+ check2.set_value(TRUE)
423
+ csizer.add(check2)
424
+ check3 = CheckBox.new(panel, ID_SIZER_CHECK3, "3")
425
+ check3.set_value(TRUE)
426
+ csizer.add(check3)
427
+ check4 = CheckBox.new(panel, ID_SIZER_CHECK4, "4")
428
+ check4.set_value(TRUE)
429
+ csizer.add(check4)
430
+ check14 = CheckBox.new(panel, ID_SIZER_CHECK14, "1-4")
431
+ check14.set_value(TRUE)
432
+ csizer.add(check14)
433
+ checkBig = CheckBox.new(panel, ID_SIZER_CHECKBIG, "Big")
434
+ checkBig.set_value(TRUE)
435
+ csizer.add(checkBig)
436
+
437
+ sizer.add(csizer)
438
+
439
+ @m_hsizer = BoxSizer.new( HORIZONTAL )
440
+
441
+ @m_buttonSizer = BoxSizer.new(VERTICAL)
442
+
443
+ @m_sizerBtn1 = Button.new(panel, -1, "Test Button &1" )
444
+ @m_buttonSizer.add( @m_sizerBtn1, 0, ALL, 10 )
445
+ @m_sizerBtn2 = Button.new(panel, -1, "Test Button &2" )
446
+ @m_buttonSizer.add( @m_sizerBtn2, 0, ALL, 10 )
447
+ @m_sizerBtn3 = Button.new(panel, -1, "Test Button &3" )
448
+ @m_buttonSizer.add( @m_sizerBtn3, 0, ALL, 10 )
449
+ @m_sizerBtn4 = Button.new(panel, -1, "Test Button &4" )
450
+ @m_buttonSizer.add( @m_sizerBtn4, 0, ALL, 10 )
451
+
452
+ @m_hsizer.add(@m_buttonSizer)
453
+ @m_hsizer.add( 20,20, 1 )
454
+ @m_bigBtn = Button.new(panel, -1, "Multiline\nbutton" )
455
+ @m_hsizer.add( @m_bigBtn , 3, GROW|ALL, 10 )
456
+
457
+ sizer.add(@m_hsizer, 1, GROW)
458
+
459
+ panel.set_sizer( sizer )
460
+
461
+ @m_notebook.add_page(panel, "Sizer")
462
+
463
+ evt_size {|event| onSize(event) }
464
+ evt_notebook_page_changing(ID_NOTEBOOK) {|event| onPageChanging(event) }
465
+ evt_notebook_page_changed(ID_NOTEBOOK) {|event| onPageChanged(event) }
466
+ evt_listbox(ID_LISTBOX) {|event| onListBox(event) }
467
+ evt_listbox(ID_LISTBOX_SORTED) {|event| onListBox(event) }
468
+ evt_listbox_dclick(ID_LISTBOX) {|event| onListBoxDoubleClick(event) }
469
+ evt_button(ID_LISTBOX_SEL_NUM) {|event| onListBoxButtons(event) }
470
+ evt_button(ID_LISTBOX_SEL_STR) {|event| onListBoxButtons(event) }
471
+ evt_button(ID_LISTBOX_CLEAR) {|event| onListBoxButtons(event) }
472
+ evt_button(ID_LISTBOX_APPEND) {|event| onListBoxButtons(event) }
473
+ evt_button(ID_LISTBOX_DELETE) {|event| onListBoxButtons(event) }
474
+ evt_button(ID_LISTBOX_FONT) {|event| onListBoxButtons(event) }
475
+ evt_checkbox(ID_LISTBOX_ENABLE) {|event| onListBoxButtons(event) }
476
+ evt_choice(ID_CHOICE) {|event| onChoice(event) }
477
+ evt_choice(ID_CHOICE_SORTED) {|event| onChoice(event) }
478
+ evt_button(ID_CHOICE_SEL_NUM) {|event| onChoiceButtons(event) }
479
+ evt_button(ID_CHOICE_SEL_STR) {|event| onChoiceButtons(event) }
480
+ evt_button(ID_CHOICE_CLEAR) {|event| onChoiceButtons(event) }
481
+ evt_button(ID_CHOICE_APPEND) {|event| onChoiceButtons(event) }
482
+ evt_button(ID_CHOICE_DELETE) {|event| onChoiceButtons(event) }
483
+ evt_button(ID_CHOICE_FONT) {|event| onChoiceButtons(event) }
484
+ evt_checkbox(ID_CHOICE_ENABLE) {|event| onChoiceButtons(event) }
485
+ evt_combobox(ID_COMBO) {|event| onCombo(event) }
486
+ evt_text(ID_COMBO) {|event| onComboTextChanged(event) }
487
+ evt_text_enter(ID_COMBO) {|event| onComboTextEnter(event) }
488
+ evt_button(ID_COMBO_SEL_NUM) {|event| onComboButtons(event) }
489
+ evt_button(ID_COMBO_SEL_STR) {|event| onComboButtons(event) }
490
+ evt_button(ID_COMBO_CLEAR) {|event| onComboButtons(event) }
491
+ evt_button(ID_COMBO_APPEND) {|event| onComboButtons(event) }
492
+ evt_button(ID_COMBO_DELETE) {|event| onComboButtons(event) }
493
+ evt_button(ID_COMBO_FONT) {|event| onComboButtons(event) }
494
+ evt_checkbox(ID_COMBO_ENABLE) {|event| onComboButtons(event) }
495
+ evt_radiobox(ID_RADIOBOX) {|event| onRadio(event) }
496
+ evt_button(ID_RADIOBOX_SEL_NUM) {|event| onRadioButtons(event) }
497
+ evt_button(ID_RADIOBOX_SEL_STR) {|event| onRadioButtons(event) }
498
+ evt_button(ID_RADIOBOX_FONT) {|event| onRadioButtons(event) }
499
+ evt_checkbox(ID_RADIOBOX_ENABLE) {|event| onRadioButtons(event) }
500
+ evt_button(ID_SET_FONT) {|event| onSetFont(event) }
501
+ evt_slider(ID_SLIDER) {|event| onSliderupdate(event) }
502
+ evt_spin(ID_SPIN) {|event| onSpinupdate(event) }
503
+ evt_spin_up(ID_SPIN) {|event| onSpinUp(event) }
504
+ evt_spin_down(ID_SPIN) {|event| onSpinDown(event) }
505
+ evt_update_ui(ID_BTNPROGRESS) {|event| onupdateShowProgress(event) }
506
+ evt_button(ID_BTNPROGRESS) {|event| onShowProgress(event) }
507
+ evt_spinctrl(ID_SPINCTRL) {|event| onSpinCtrl(event) }
508
+ evt_spin_up(ID_SPINCTRL) {|event| onSpinCtrlUp(event) }
509
+ evt_spin_down(ID_SPINCTRL) {|event| onSpinCtrlDown(event) }
510
+ evt_text(ID_SPINCTRL) {|event| onSpinCtrlText(event) }
511
+ if (RUBY_PLATFORM =~ /mswin/)
512
+ evt_togglebutton(ID_BUTTON_LABEL) {|event| onupdateLabel(event) }
513
+ end
514
+ evt_checkbox(ID_CHANGE_COLOUR) {|event| onChangeColour(event) }
515
+ evt_button(ID_BUTTON_TEST1) {|event| onTestButton(event) }
516
+ evt_button(ID_BUTTON_TEST2) {|event| onTestButton(event) }
517
+ evt_button(ID_BITMAP_BTN) {|event| onBmpButton(event) }
518
+
519
+ evt_checkbox(ID_SIZER_CHECK1) {|event| onSizerCheck(event) }
520
+ evt_checkbox(ID_SIZER_CHECK2) {|event| onSizerCheck(event) }
521
+ evt_checkbox(ID_SIZER_CHECK3) {|event| onSizerCheck(event) }
522
+ evt_checkbox(ID_SIZER_CHECK4) {|event| onSizerCheck(event) }
523
+ evt_checkbox(ID_SIZER_CHECK14) {|event| onSizerCheck(event) }
524
+ evt_checkbox(ID_SIZER_CHECKBIG) {|event| onSizerCheck(event) }
525
+
526
+ end
527
+
528
+ # utility function to find an icon relative to this ruby script
529
+ def local_icon_file(icon_name)
530
+ File.join( File.dirname(__FILE__), 'icons', icon_name)
531
+ end
532
+
533
+
534
+ def onSize(event)
535
+ size = get_client_size()
536
+ x = size.get_width
537
+ y = size.get_height
538
+ if @m_notebook
539
+ @m_notebook.set_dimensions( 2, 2, x-4, y*2/3-4 )
540
+ end
541
+ if @m_text
542
+ @m_text.set_dimensions( 2, y*2/3+2, x-4, y/3-4 )
543
+ end
544
+ end
545
+
546
+ def onPageChanging(event)
547
+
548
+ selOld = event.get_old_selection()
549
+ if selOld == 2
550
+ if message_box("This demonstrates how a program may prevent the\n"+
551
+ "page change from taking place - if you select\n"+
552
+ "[No] the current page will stay the third one\n",
553
+ "Control sample",
554
+ ICON_QUESTION | YES_NO, self) != YES
555
+ event.veto()
556
+ return nil
557
+ end
558
+ end
559
+ @m_text << "Notebook selection is being changed from " << selOld \
560
+ << " to " << event.get_selection() \
561
+ << " (current page from notebook is " \
562
+ << @m_notebook.get_selection() << ")\n"
563
+ end
564
+
565
+ def onPageChanged(event)
566
+ @m_text << "Notebook selection is now " << event.get_selection() \
567
+ << " (from notebook: " << @m_notebook.get_selection() \
568
+ << ")\n"
569
+ end
570
+
571
+ def onTestButton(event)
572
+ log_message("Button %s clicked.",
573
+ event.get_id() == ID_BUTTON_TEST1 ? '1' : '2')
574
+ end
575
+
576
+ def onBmpButton(event)
577
+ log_message("Bitmap button clicked.")
578
+ end
579
+
580
+ def onChangeColour(event)
581
+ # test panel colour changing and propagation to the subcontrols
582
+ if @s_colOld.is_ok()
583
+
584
+ set_background_colour(@s_colOld)
585
+ @s_colOld = NULL_COLOUR
586
+
587
+ @m_lbSelectThis.set_foreground_colour(Colour.new("red"))
588
+ @m_lbSelectThis.set_background_colour(Colour.new("white"))
589
+ else
590
+ @s_colOld = Colour.new("red")
591
+ set_background_colour(Colour.new("white"))
592
+
593
+ @m_lbSelectThis.set_foreground_colour(Colour.new("white"))
594
+ @m_lbSelectThis.set_background_colour(Colour.new("red"))
595
+ end
596
+
597
+ @m_lbSelectThis.refresh()
598
+ refresh()
599
+ end
600
+
601
+ def onListBox(event)
602
+ # GetParent().Move(100, 100)
603
+ if event.get_int() == -1
604
+ @m_text.append_text( "ListBox has no selections anymore\n" )
605
+ return Qnil
606
+ end
607
+
608
+ listbox = (event.get_id() == ID_LISTBOX) ? @m_listbox : @m_listboxSorted
609
+
610
+ @m_text.append_text( "ListBox event selection string is: '" )
611
+ @m_text.append_text( event.get_string() )
612
+ @m_text.append_text( "'\n" )
613
+ @m_text.append_text( "ListBox control selection string is: '" )
614
+ @m_text.append_text( listbox.get_string_selection() )
615
+ @m_text.append_text( "'\n" )
616
+
617
+ # NOTE: get_client_data and set_client_data have been removed from wxRuby 0.4
618
+ # because they could cause crashes
619
+ # obj = event.get_client_data()
620
+ # @m_text.append_text( "ListBox event client data string is: '" )
621
+ # if obj
622
+ # @m_text.append_text( obj )
623
+ # else
624
+ # @m_text.append_text( "none" )
625
+ # end
626
+
627
+ # @m_text.append_text( "'\n" )
628
+ # @m_text.append_text( "ListBox control client data string is: '" )
629
+ # obj = listbox.get_client_data(listbox.get_selection())
630
+ # if obj
631
+ # @m_text.append_text( obj )
632
+ # else
633
+ # @m_text.append_text( "none" )
634
+ # end
635
+ # @m_text.append_text( "'\n" )
636
+ end
637
+
638
+ def onListBoxDoubleClick(event)
639
+ @m_text.append_text( "ListBox double click string is: " )
640
+ @m_text.append_text( event.get_string() )
641
+ @m_text.append_text( "\n" )
642
+ end
643
+
644
+ def onListBoxButtons(event)
645
+ case event.get_id()
646
+ when ID_LISTBOX_ENABLE
647
+ @m_text.append_text("Checkbox clicked.\n")
648
+ if event.get_int() != 0
649
+ @m_checkbox.set_tool_tip( "Click to enable listbox" )
650
+ @m_toggle_color.enable(false)
651
+ else
652
+ @m_checkbox.set_tool_tip( "Click to disable listbox" )
653
+ @m_toggle_color.enable(true)
654
+ end
655
+ @m_listbox.enable( event.get_int() == 0 )
656
+ @m_lbSelectThis.enable( event.get_int() == 0 )
657
+ @m_lbSelectNum.enable( event.get_int() == 0 )
658
+ @m_listboxSorted.enable( event.get_int() == 0 )
659
+ #w = Window::find_window_by_id(ID_CHANGE_COLOUR)
660
+ #if(w)
661
+ # w.enable( event.get_int() == 0 )
662
+ #else
663
+ # puts("Window ID_CHANGE_COLOR not found")
664
+ #end
665
+ when ID_LISTBOX_SEL_NUM
666
+ @m_listbox.set_selection( 2 )
667
+ @m_listboxSorted.set_selection( 2 )
668
+ @m_lbSelectThis.warp_pointer( 40, 14 )
669
+ when ID_LISTBOX_SEL_STR
670
+ @m_listbox.set_string_selection( "This" )
671
+ @m_listboxSorted.set_string_selection( "This" )
672
+ @m_lbSelectNum.warp_pointer( 40, 14 )
673
+ when ID_LISTBOX_CLEAR
674
+ @m_listbox.clear()
675
+ @m_listboxSorted.clear()
676
+ when ID_LISTBOX_APPEND
677
+ @m_listbox.append( "Hi!" )
678
+ @m_listboxSorted.append( "Hi!" )
679
+ when ID_LISTBOX_DELETE
680
+ idx = @m_listbox.get_selection()
681
+ if idx != NOT_FOUND
682
+ @m_listbox.delete( idx )
683
+ end
684
+ idx = @m_listboxSorted.get_selection()
685
+ if idx != NOT_FOUND
686
+ @m_listboxSorted.delete( idx )
687
+ end
688
+ when ID_LISTBOX_FONT
689
+ @m_listbox.set_font( ITALIC_FONT )
690
+ @m_listboxSorted.set_font( ITALIC_FONT )
691
+ @m_checkbox.set_font( ITALIC_FONT )
692
+ end
693
+ end
694
+
695
+
696
+ def onChoice(event)
697
+
698
+ choice = (event.get_id() == ID_CHOICE) ? @m_choice : @m_choiceSorted
699
+
700
+ @m_text.append_text( "Choice event selection string is: '" )
701
+ @m_text.append_text( event.get_string() )
702
+ @m_text.append_text( "'\n" )
703
+ @m_text.append_text( "Choice control selection string is: '" )
704
+ @m_text.append_text( choice.get_string_selection() )
705
+ @m_text.append_text( "'\n" )
706
+
707
+ # NOTE: get_client_data and set_client_data have been removed from wxRuby 0.4
708
+ # because they could cause crashes
709
+ # obj = event.get_client_data()
710
+ # @m_text.append_text( "Choice event client data string is: '" )
711
+
712
+ # if obj
713
+ # @m_text.append_text( obj )
714
+ # else
715
+ # @m_text.append_text( "none" )
716
+ # end
717
+
718
+ # @m_text.append_text( "'\n" )
719
+ # @m_text.append_text( "Choice control client data string is: '" )
720
+
721
+ # obj = choice.get_client_data(choice.get_selection())
722
+ # if obj
723
+ # @m_text.append_text( obj )
724
+ # else
725
+ # @m_text.append_text( "none" )
726
+ # end
727
+ # @m_text.append_text( "'\n" )
728
+ end
729
+
730
+ def onChoiceButtons(event)
731
+ case event.get_id()
732
+ when ID_CHOICE_ENABLE
733
+ @m_choice.enable( event.get_int() == 0 )
734
+ @m_choiceSorted.enable( event.get_int() == 0 )
735
+ when ID_CHOICE_SEL_NUM
736
+ @m_choice.set_selection( 2 )
737
+ @m_choiceSorted.set_selection( 2 )
738
+ when ID_CHOICE_SEL_STR
739
+ @m_choice.set_string_selection( "This" )
740
+ @m_choiceSorted.set_string_selection( "This" )
741
+ when ID_CHOICE_CLEAR
742
+ @m_choice.clear()
743
+ @m_choiceSorted.clear()
744
+ when ID_CHOICE_APPEND
745
+ @m_choice.append( "Hi!" )
746
+ @m_choiceSorted.append( "Hi!" )
747
+ when ID_CHOICE_DELETE
748
+ idx = @m_choice.get_selection()
749
+ if idx != NOT_FOUND
750
+ @m_choice.delete( idx )
751
+ end
752
+ idx = @m_choiceSorted.get_selection()
753
+ if idx != NOT_FOUND
754
+ @m_choiceSorted.delete( idx )
755
+ end
756
+ when ID_CHOICE_FONT
757
+ @m_choice.set_font( ITALIC_FONT )
758
+ @m_choiceSorted.set_font( ITALIC_FONT )
759
+ end
760
+ end
761
+
762
+ def onCombo(event)
763
+ @m_text.append_text( "ComboBox event selection string is: " )
764
+ @m_text.append_text( event.get_string() )
765
+ @m_text.append_text( "\n" )
766
+ @m_text.append_text( "ComboBox control selection string is: " )
767
+ @m_text.append_text( @m_combo.get_string_selection() )
768
+ @m_text.append_text( "\n" )
769
+ end
770
+
771
+ def onComboTextChanged(event)
772
+ str = sprintf( "Text in the combobox changed: now is '%s'.",
773
+ event.get_string())
774
+ log_message( str )
775
+ end
776
+
777
+ def onComboTextEnter(event)
778
+ log_message("Enter pressed in the combobox: value is '%s'.",
779
+ @m_combo.get_value())
780
+ end
781
+
782
+ def onComboButtons(event)
783
+ case event.get_id()
784
+ when ID_COMBO_ENABLE
785
+ @m_combo.enable( event.get_int() == 0 )
786
+ when ID_COMBO_SEL_NUM
787
+ @m_combo.set_selection( 2 )
788
+ when ID_COMBO_SEL_STR
789
+ @m_combo.set_string_selection( "This" )
790
+ when ID_COMBO_CLEAR
791
+ @m_combo.clear()
792
+ when ID_COMBO_APPEND
793
+ @m_combo.append( "Hi!" )
794
+ when ID_COMBO_DELETE
795
+ idx = @m_combo.get_selection()
796
+ @m_combo.delete( idx )
797
+ when ID_COMBO_FONT
798
+ @m_combo.set_font( ITALIC_FONT )
799
+ end
800
+ end
801
+
802
+ def onRadio(event)
803
+ @m_text.append_text( "RadioBox selection string is: " )
804
+ @m_text.append_text( event.get_string() )
805
+ @m_text.append_text( "\n" )
806
+ end
807
+
808
+ def onRadioButtons(event)
809
+ case event.get_id()
810
+ when ID_RADIOBOX_ENABLE
811
+ @m_radio.enable( event.get_int() == 0 )
812
+ when ID_RADIOBOX_SEL_NUM
813
+ @m_radio.set_selection( 2 )
814
+ when ID_RADIOBOX_SEL_STR
815
+ @m_radio.set_string_selection( "This" )
816
+ when ID_RADIOBOX_FONT
817
+ @m_radio.set_foreground_colour(GREEN)
818
+ @m_radio.set_font( ITALIC_FONT )
819
+ end
820
+ end
821
+
822
+ def onSetFont(event)
823
+ @m_fontButton.set_font( ITALIC_FONT )
824
+ @m_text.set_font( ITALIC_FONT )
825
+ end
826
+
827
+ def onupdateLabel(event)
828
+ @m_label.set_label(event.get_int() != 0 ? "Very very very very very long text." : "Shorter text.")
829
+ end
830
+
831
+ def onSliderupdate(event)
832
+ @m_gauge.set_value( @m_slider.get_value() )
833
+ @m_gaugeVert.set_value( @m_slider.get_value() / 2 )
834
+ end
835
+
836
+
837
+ def onSpinCtrlText(event)
838
+ if @m_spinctrl
839
+ s = sprintf( "Spin ctrl text changed: now %d (from event: %s)\n",
840
+ @m_spinctrl.get_value(), event.get_string() )
841
+ @m_text.append_text(s)
842
+ end
843
+ end
844
+
845
+ def onSpinCtrl(event)
846
+ if @m_spinctrl
847
+ s = sprintf( "Spin ctrl changed: now %d (from event: %d)\n",
848
+ @m_spinctrl.get_value(), event.get_int() )
849
+ @m_text.append_text(s)
850
+ end
851
+ end
852
+
853
+ def onSpinCtrlUp(event)
854
+ if @m_spinctrl
855
+ @m_text.append_text( sprintf(
856
+ "Spin up: %d (from event: %d)\n",
857
+ @m_spinctrl.get_value(), event.get_int() ) )
858
+ end
859
+ end
860
+
861
+ def onSpinCtrlDown(event)
862
+ if @m_spinctrl
863
+ @m_text.append_text( sprintf(
864
+ "Spin down: %d (from event: %d)\n",
865
+ @m_spinctrl.get_value(), event.get_int() ) )
866
+ end
867
+ end
868
+
869
+
870
+ def onSpinUp(event)
871
+ value = sprintf( "Spin control up: current = %d\n",
872
+ @m_spinbutton.get_value())
873
+
874
+ if event.get_position() > 17
875
+ value += "Preventing the spin button from going above 17.\n"
876
+ event.veto()
877
+ end
878
+
879
+ @m_text.append_text(value)
880
+ end
881
+
882
+ def onSpinDown(event)
883
+ value = sprintf( "Spin control down: current = %d\n",
884
+ @m_spinbutton.get_value())
885
+
886
+ if event.get_position() < -17
887
+ value += "Preventing the spin button from going below -17.\n"
888
+ event.veto()
889
+ end
890
+
891
+ @m_text.append_text(value)
892
+ end
893
+
894
+ def onSpinupdate(event)
895
+ value = sprintf( "%d", event.get_position() )
896
+ @m_spintext.set_value( value )
897
+
898
+ value = sprintf( "Spin control range: (%d, %d), current = %d\n",
899
+ @m_spinbutton.get_min(), @m_spinbutton.get_max(),
900
+ @m_spinbutton.get_value())
901
+
902
+ @m_text.append_text(value)
903
+ end
904
+
905
+ def onupdateShowProgress(event)
906
+ event.enable( @m_spinbutton.get_value() > 0 )
907
+ end
908
+
909
+ def onShowProgress(event)
910
+ max = @m_spinbutton.get_value()
911
+ if max <= 0
912
+ log_error("You must set positive range!")
913
+ return nil
914
+ end
915
+
916
+ dialog = ProgressDialog.new("Progress dialog example",
917
+ "An informative message",
918
+ max, # range
919
+ self, # parent
920
+ PD_CAN_ABORT |
921
+ PD_AUTO_HIDE |
922
+ PD_APP_MODAL |
923
+ PD_ELAPSED_TIME |
924
+ PD_ESTIMATED_TIME |
925
+ PD_REMAINING_TIME)
926
+
927
+ cont = TRUE
928
+ 0.upto(max) {|i|
929
+ break if !cont
930
+ sleep(1)
931
+ if i == max
932
+ cont = dialog.update(i, "That's all, folks!")
933
+ elsif i == max / 2
934
+ cont = dialog.update(i, "Only a half left (very long message)!")
935
+ else
936
+ cont = dialog.update(i)
937
+ end
938
+ }
939
+ dialog.destroy()
940
+ if !cont
941
+ @m_text << "Progress dialog aborted!\n"
942
+ else
943
+ @m_text << "Countdown from " << max << " finished.\n"
944
+ end
945
+ end
946
+
947
+ def onSizerCheck(event)
948
+ case event.get_id()
949
+ when ID_SIZER_CHECK1
950
+ @m_buttonSizer.show(@m_sizerBtn1, event.is_checked())
951
+ @m_buttonSizer.layout()
952
+ when ID_SIZER_CHECK2
953
+ @m_buttonSizer.show(@m_sizerBtn2, event.is_checked())
954
+ @m_buttonSizer.layout()
955
+ when ID_SIZER_CHECK3
956
+ @m_buttonSizer.show(@m_sizerBtn3, event.is_checked())
957
+ @m_buttonSizer.layout()
958
+ when ID_SIZER_CHECK4
959
+ @m_buttonSizer.show(@m_sizerBtn4, event.is_checked())
960
+ @m_buttonSizer.layout()
961
+ when ID_SIZER_CHECK14
962
+ @m_hsizer.show(@m_buttonSizer, event.is_checked())
963
+ @m_hsizer.layout()
964
+ when ID_SIZER_CHECKBIG
965
+ @m_hsizer.show(@m_bigBtn, event.is_checked())
966
+ @m_hsizer.layout()
967
+ end
968
+ end
969
+ end
970
+
971
+
972
+ class MyFrame < Frame
973
+ def initialize(title,x,y)
974
+ super(nil, -1, title, Point.new(x, y), Size.new(500, 430))
975
+
976
+ @s_delay = 5000
977
+ @s_enabled = TRUE
978
+ @s_enable2 = TRUE
979
+ @s_windowFocus = nil
980
+ mondrian_icon =
981
+ case Wx::PLATFORM
982
+ when "WXMSW"
983
+ Icon.new( File.join( File.dirname(__FILE__), "mondrian.ico"),
984
+ Wx::BITMAP_TYPE_ICO )
985
+ else
986
+ Icon.new( File.join( File.dirname(__FILE__), "mondrian.xpm"),
987
+ Wx::BITMAP_TYPE_XPM )
988
+ end
989
+
990
+ set_icon(mondrian_icon)
991
+
992
+ file_menu = Menu.new
993
+
994
+ file_menu.append(CONTROLS_CLEAR_LOG, "&clear log\tCtrl-L")
995
+ file_menu.append_separator()
996
+ file_menu.append(CONTROLS_ABOUT, "&About\tF1")
997
+ file_menu.append_separator()
998
+ file_menu.append(CONTROLS_QUIT, "E&xit\tAlt-X", "Quit controls sample")
999
+
1000
+ menu_bar = MenuBar.new
1001
+ menu_bar.append(file_menu, "&File")
1002
+
1003
+ tooltip_menu = Menu.new
1004
+ tooltip_menu.append(CONTROLS_SET_TOOLTIP_DELAY, "Set &delay\tCtrl-D")
1005
+ tooltip_menu.append_separator()
1006
+ tooltip_menu.append(CONTROLS_ENABLE_TOOLTIPS, "&Toggle tooltips\tCtrl-T",
1007
+ "enable/disable tooltips", ITEM_CHECK)
1008
+ tooltip_menu.check(CONTROLS_ENABLE_TOOLTIPS, TRUE)
1009
+ menu_bar.append(tooltip_menu, "&Tooltips")
1010
+
1011
+ panel_menu = Menu.new
1012
+ panel_menu.append(CONTROLS_ENABLE_ALL, "&Disable all\tCtrl-E",
1013
+ "enable/disable all panel controls", ITEM_CHECK)
1014
+ menu_bar.append(panel_menu, "&Panel")
1015
+
1016
+ set_menu_bar(menu_bar)
1017
+
1018
+ create_status_bar(2)
1019
+
1020
+ @m_panel = MyPanel.new( self, 10, 10, 300, 100 )
1021
+
1022
+ set_size_hints( 500, 425 )
1023
+
1024
+ evt_menu(CONTROLS_QUIT) {|event| onQuit(event) }
1025
+ evt_menu(CONTROLS_ABOUT) {|event| onAbout(event) }
1026
+ evt_menu(CONTROLS_CLEAR_LOG) {|event| onClearLog(event) }
1027
+ evt_menu(CONTROLS_SET_TOOLTIP_DELAY) {|event| onSetTooltipDelay(event) }
1028
+ evt_menu(CONTROLS_ENABLE_TOOLTIPS) {|event| onToggleTooltips(event) }
1029
+ evt_menu(CONTROLS_ENABLE_ALL) {|event| onenableAll(event) }
1030
+
1031
+ evt_size() {|event| onSize(event) }
1032
+ evt_move() {|event| onMove(event) }
1033
+ evt_idle() {|event| onIdle(event) }
1034
+ evt_close() {|event| onClose(event) }
1035
+ end
1036
+
1037
+ def onClose(event)
1038
+ Log::set_active_target(@m_panel.m_logTargetOld)
1039
+ destroy()
1040
+ end
1041
+
1042
+ def onQuit(event)
1043
+ close(TRUE)
1044
+ end
1045
+
1046
+ def onAbout(event)
1047
+ BusyCursor.busy do
1048
+ dialog = MessageDialog.new(self, "This is a control sample", "About Controls", OK)
1049
+ dialog.show_modal()
1050
+ end
1051
+ end
1052
+
1053
+ def onClearLog(event)
1054
+ @m_panel.m_text.clear()
1055
+ end
1056
+
1057
+ def onSetTooltipDelay(event)
1058
+ delay = @s_delay.to_s
1059
+
1060
+ delay = get_text_from_user("Enter delay (in milliseconds)",
1061
+ "Set tooltip delay",
1062
+ delay,
1063
+ self)
1064
+ if !delay
1065
+ return Qnil # cancelled
1066
+ end
1067
+
1068
+ @s_delay = delay.to_i
1069
+
1070
+ ToolTip::set_delay(@s_delay)
1071
+
1072
+ log_status(self, "Tooltip delay set to %d milliseconds", @s_delay)
1073
+ end
1074
+
1075
+ def onToggleTooltips(event)
1076
+ @s_enabled = ! @s_enabled
1077
+ ToolTip::enable(@s_enabled)
1078
+ log_status(self, "Tooltips %sabled", @s_enabled ? "en" : "dis" )
1079
+ end
1080
+
1081
+ def onenableAll(event)
1082
+ @s_enable2 = ! @s_enable2
1083
+ @m_panel.enable(@s_enable2)
1084
+ end
1085
+
1086
+ def onMove(event)
1087
+ update_status_bar(event.get_position(), get_size())
1088
+ event.skip()
1089
+ end
1090
+
1091
+ def onSize(event)
1092
+ update_status_bar(get_position(), event.get_size())
1093
+ event.skip()
1094
+ end
1095
+
1096
+ def onIdle(event)
1097
+
1098
+ # track the window which has the focus in the status bar
1099
+ focus = Window::find_focus()
1100
+ if focus && (focus != @s_windowFocus)
1101
+ @s_windowFocus = focus
1102
+ msg = sprintf( "Focus: %s, HWND = %08x",
1103
+ @s_windowFocus.wx_class,
1104
+ @s_windowFocus.get_handle )
1105
+ set_status_text(msg)
1106
+ end
1107
+ end
1108
+
1109
+ def GetPanel()
1110
+ @m_panel
1111
+ end
1112
+
1113
+ def update_status_bar(pos,size)
1114
+ if get_status_bar()
1115
+ sizeAll = get_size()
1116
+ sizeCl = get_client_size()
1117
+ msg = sprintf("pos=(%d, %d), size=%dx%d or %dx%d (client=%dx%d)",
1118
+ pos.x, pos.y,
1119
+ size.x, size.y,
1120
+ sizeAll.x, sizeAll.y,
1121
+ sizeCl.x, sizeCl.y)
1122
+ set_status_text(msg, 1)
1123
+ end
1124
+ end
1125
+
1126
+ end
1127
+
1128
+ class MyApp < App
1129
+ def on_init()
1130
+ # parse the cmd line
1131
+ x = 50
1132
+ y = 50
1133
+ # Create the main frame window
1134
+ frame = MyFrame.new("Controls Windows App", x, y)
1135
+ frame.show(TRUE)
1136
+ end
1137
+ end
1138
+
1139
+ a = MyApp.new
1140
+ a.main_loop