wxruby 1.9.0-i386-mswin32 → 1.9.1-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/lib/wx.rb +42 -35
  2. data/lib/wx/accessors.rb +52 -0
  3. data/lib/wx/classes/evthandler.rb +36 -32
  4. data/lib/wx/classes/grid.rb +13 -13
  5. data/lib/wx/classes/point.rb +43 -0
  6. data/lib/wx/classes/size.rb +44 -0
  7. data/lib/wx/classes/styledtextctrl.rb +92 -0
  8. data/lib/wx/classes/textctrl.rb +14 -0
  9. data/lib/wx/classes/window.rb +4 -0
  10. data/lib/wx/keyword_ctors.rb +219 -0
  11. data/lib/wx/keyword_defs.rb +455 -0
  12. data/lib/wx/version.rb +1 -1
  13. data/lib/wxruby2.exp +0 -0
  14. data/lib/wxruby2.lib +0 -0
  15. data/lib/wxruby2.so +0 -0
  16. data/samples/SAMPLES-LICENSE.TXT +17 -17
  17. data/samples/aui/aui.rb +6 -5
  18. data/samples/bigdemo/About.rbw +39 -39
  19. data/samples/bigdemo/ColorPanel.rbw +25 -25
  20. data/samples/bigdemo/GridSimple.rbw +80 -80
  21. data/samples/bigdemo/MDIDemo.rbw +59 -59
  22. data/samples/bigdemo/PopupMenu.rbw +151 -151
  23. data/samples/bigdemo/Sizers.rbw +545 -545
  24. data/samples/bigdemo/bigdemo.rb +826 -826
  25. data/samples/bigdemo/demoTemplate.rbw +37 -37
  26. data/samples/bigdemo/icons/choice.xpm +27 -27
  27. data/samples/bigdemo/icons/combo.xpm +27 -27
  28. data/samples/bigdemo/icons/copy.xpm +25 -25
  29. data/samples/bigdemo/icons/cut.xpm +24 -24
  30. data/samples/bigdemo/icons/gauge.xpm +27 -27
  31. data/samples/bigdemo/icons/help.xpm +25 -25
  32. data/samples/bigdemo/icons/list.xpm +27 -27
  33. data/samples/bigdemo/icons/mondrian.xpm +44 -44
  34. data/samples/bigdemo/icons/new.xpm +24 -24
  35. data/samples/bigdemo/icons/ogl.ico +0 -0
  36. data/samples/bigdemo/icons/ogl.xpm +45 -45
  37. data/samples/bigdemo/icons/open.xpm +26 -26
  38. data/samples/bigdemo/icons/paste.xpm +38 -38
  39. data/samples/bigdemo/icons/preview.xpm +26 -26
  40. data/samples/bigdemo/icons/print.xpm +26 -26
  41. data/samples/bigdemo/icons/radio.xpm +27 -27
  42. data/samples/bigdemo/icons/robert.xpm +415 -415
  43. data/samples/bigdemo/icons/save.xpm +25 -25
  44. data/samples/bigdemo/icons/smiles.xpm +39 -39
  45. data/samples/bigdemo/icons/smiley.xpm +42 -42
  46. data/samples/bigdemo/icons/stattext.xpm +24 -24
  47. data/samples/bigdemo/icons/test2.bmp +0 -0
  48. data/samples/bigdemo/icons/test2.xpm +79 -79
  49. data/samples/bigdemo/icons/text.xpm +27 -27
  50. data/samples/bigdemo/icons/tog1.xpm +38 -38
  51. data/samples/bigdemo/icons/tog2.xpm +38 -38
  52. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -25
  53. data/samples/bigdemo/tips.txt +7 -7
  54. data/samples/bigdemo/utils.rb +11 -11
  55. data/samples/bigdemo/wxButton.rbw +66 -66
  56. data/samples/bigdemo/wxCalendarCtrl.rbw +72 -72
  57. data/samples/bigdemo/wxCheckBox.rbw +52 -52
  58. data/samples/bigdemo/wxCheckListBox.rbw +77 -77
  59. data/samples/bigdemo/wxChoice.rbw +49 -49
  60. data/samples/bigdemo/wxColourDialog.rbw +34 -34
  61. data/samples/bigdemo/wxComboBox.rbw +79 -79
  62. data/samples/bigdemo/wxDialog.rbw +92 -92
  63. data/samples/bigdemo/wxDirDialog.rbw +32 -32
  64. data/samples/bigdemo/wxFileDialog.rbw +39 -39
  65. data/samples/bigdemo/wxFileDialog_Save.rbw +38 -38
  66. data/samples/bigdemo/wxFindReplaceDialog.rbw +85 -85
  67. data/samples/bigdemo/wxFontDialog.rbw +176 -176
  68. data/samples/bigdemo/wxFrame.rbw +55 -55
  69. data/samples/bigdemo/wxGauge.rbw +73 -73
  70. data/samples/bigdemo/wxGrid.rbw +68 -68
  71. data/samples/bigdemo/wxListBox.rbw +142 -142
  72. data/samples/bigdemo/wxListCtrl_virtual.rbw +109 -109
  73. data/samples/bigdemo/wxMDIWindows.rbw +52 -52
  74. data/samples/bigdemo/wxMenu.rbw +238 -238
  75. data/samples/bigdemo/wxMessageDialog.rbw +30 -30
  76. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +34 -34
  77. data/samples/bigdemo/wxNotebook.rbw +138 -138
  78. data/samples/bigdemo/wxProgressDialog.rbw +45 -45
  79. data/samples/bigdemo/wxRadioBox.rbw +74 -74
  80. data/samples/bigdemo/wxRadioButton.rbw +127 -127
  81. data/samples/bigdemo/wxScrolledMessageDialog.rbw +59 -59
  82. data/samples/bigdemo/wxScrolledWindow.rbw +196 -196
  83. data/samples/bigdemo/wxSingleChoiceDialog.rbw +35 -35
  84. data/samples/bigdemo/wxSlider.rbw +44 -44
  85. data/samples/bigdemo/wxSpinButton.rbw +52 -52
  86. data/samples/bigdemo/wxSpinCtrl.rbw +53 -53
  87. data/samples/bigdemo/wxSplitterWindow.rbw +65 -65
  88. data/samples/bigdemo/wxStaticBitmap.rbw +53 -53
  89. data/samples/bigdemo/wxStaticText.rbw +57 -57
  90. data/samples/bigdemo/wxStatusBar.rbw +128 -128
  91. data/samples/bigdemo/wxTextCtrl.rbw +151 -151
  92. data/samples/bigdemo/wxTextEntryDialog.rbw +34 -34
  93. data/samples/bigdemo/wxToggleButton.rbw +51 -51
  94. data/samples/bigdemo/wxToolBar.rbw +133 -133
  95. data/samples/bigdemo/wxTreeCtrl.rbw +192 -192
  96. data/samples/calendar/calendar.rb +275 -275
  97. data/samples/caret/caret.rb +296 -296
  98. data/samples/caret/mondrian.xpm +44 -44
  99. data/samples/controls/controls.rb +1140 -1140
  100. data/samples/controls/get_item_sample.rb +87 -87
  101. data/samples/controls/icons/choice.xpm +27 -27
  102. data/samples/controls/icons/combo.xpm +27 -27
  103. data/samples/controls/icons/gauge.xpm +27 -27
  104. data/samples/controls/icons/list.xpm +27 -27
  105. data/samples/controls/icons/radio.xpm +27 -27
  106. data/samples/controls/icons/stattext.xpm +24 -24
  107. data/samples/controls/icons/text.xpm +27 -27
  108. data/samples/controls/mondrian.xpm +44 -44
  109. data/samples/dialogs/dialogs.rb +724 -724
  110. data/samples/dialogs/tips.txt +18 -18
  111. data/samples/etc/activation.rb +108 -108
  112. data/samples/etc/choice.rb +72 -72
  113. data/samples/etc/miniframe.rb +84 -84
  114. data/samples/etc/sash.rb +135 -135
  115. data/samples/etc/scrollwin.rb +116 -116
  116. data/samples/etc/system_settings.rb +258 -258
  117. data/samples/etc/wizard.rb +81 -81
  118. data/samples/event/event.rb +184 -0
  119. data/samples/images/images.rb +48 -48
  120. data/samples/listbook/listbook.rb +183 -183
  121. data/samples/listbook/listbook.xrc +370 -370
  122. data/samples/mdi/mdi.rb +87 -87
  123. data/samples/minimal/minimal.rb +83 -95
  124. data/samples/minimal/mondrian.png +0 -0
  125. data/samples/minimal/nothing.rb +46 -46
  126. data/samples/minimal/text.rb +35 -35
  127. data/samples/text/scintilla.rb +22 -28
  128. data/samples/text/textctrl.rb +124 -124
  129. data/samples/text/unicode.rb +238 -238
  130. data/samples/text/utf8.txt +14 -14
  131. data/samples/treectrl/treectrl.rb +1210 -1210
  132. data/samples/xrc/samples.xrc +46 -46
  133. data/samples/xrc/xrc_sample.rb +107 -107
  134. metadata +13 -5
  135. data/samples/minimal/mondrian.ico +0 -0
  136. data/samples/minimal/mondrian.xpm +0 -44
@@ -1,15 +1,15 @@
1
- Western European: ÀÉÎè
2
-
3
- Chinese (Simplified): 丁万不㐀㐁丣並
4
-
5
- Extended Latin: ĀčŁœ
6
-
7
- Japanese Hiragana: あきぐけ゚
8
-
9
- Arabic: ؟تص
10
-
11
- Cyrillic: ЀЋЖ
12
-
13
- Greek: Άαξ
14
-
1
+ Western European: ÀÉÎè
2
+
3
+ Chinese (Simplified): 丁万不㐀㐁丣並
4
+
5
+ Extended Latin: ĀčŁœ
6
+
7
+ Japanese Hiragana: あきぐけ゚
8
+
9
+ Arabic: ؟تص
10
+
11
+ Cyrillic: ЀЋЖ
12
+
13
+ Greek: Άαξ
14
+
15
15
  Korean: 了丫乖
@@ -1,1210 +1,1210 @@
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
-
16
- # This sample shows off the features of the TreeCtrl widget. The actual
17
- # features vary somewhat across platforms; for example, the button
18
- # styles and connecting lines between items are not available on OS X.
19
- # Also, some items remain to be implemented - for example, setting item
20
- # icons and item data.
21
-
22
- # Just some event ids for the numerous menu items
23
- TreeTest_TogButtons,
24
- TreeTest_TogTwist,
25
- TreeTest_TogLines,
26
- TreeTest_TogEdit,
27
- TreeTest_TogHideRoot,
28
- TreeTest_TogRootLines,
29
- TreeTest_TogBorder,
30
- TreeTest_TogFullHighlight,
31
- TreeTest_SetFgColour,
32
- TreeTest_SetBgColour,
33
- TreeTest_ResetStyle,
34
- TreeTest_Dump,
35
- TreeTest_DumpSelected,
36
- TreeTest_Count,
37
- TreeTest_CountRec,
38
- TreeTest_Sort,
39
- TreeTest_SortRev,
40
- TreeTest_SetBold,
41
- TreeTest_ClearBold,
42
- TreeTest_Rename,
43
- TreeTest_Delete,
44
- TreeTest_DeleteChildren,
45
- TreeTest_DeleteAll,
46
- TreeTest_Recreate,
47
- TreeTest_ToggleImages,
48
- TreeTest_ToggleButtons,
49
- TreeTest_SetImageSize,
50
- TreeTest_ToggleSel,
51
- TreeTest_CollapseAndReset,
52
- TreeTest_EnsureVisible,
53
- TreeTest_AddItem,
54
- TreeTest_InsertItem,
55
- TreeTest_IncIndent,
56
- TreeTest_DecIndent,
57
- TreeTest_IncSpacing,
58
- TreeTest_DecSpacing,
59
- TreeTest_ToggleIcon,
60
- TreeTest_Select,
61
- TreeTest_Unselect = (Wx::ID_HIGHEST..Wx::ID_HIGHEST+39).to_a
62
- TreeTest_Ctrl = 1000
63
-
64
- TreeCtrlIcon_File,
65
- TreeCtrlIcon_FileSelected,
66
- TreeCtrlIcon_Folder,
67
- TreeCtrlIcon_FolderSelected,
68
- TreeCtrlIcon_FolderOpened = 0,1,2,3,4
69
-
70
- class MyTreeCtrl < Wx::TreeCtrl
71
- def initialize(parent, id,pos, size,style)
72
- super(parent, id, pos, size, style)
73
-
74
- @reverse_sort = false
75
-
76
- create_image_list
77
-
78
- # add some items to the tree
79
- add_test_items_to_tree(5, 2)
80
-
81
- # TreeCtrl supports a large number of different events...
82
- evt_tree_begin_drag(TreeTest_Ctrl) { | e | on_begin_drag(e) }
83
- evt_tree_begin_rdrag(TreeTest_Ctrl) { | e | on_begin_rdrag(e) }
84
- evt_tree_end_drag(TreeTest_Ctrl) { | e | on_end_drag(e) }
85
- evt_tree_begin_label_edit(TreeTest_Ctrl) { | e | on_begin_label_edit(e) }
86
- evt_tree_end_label_edit(TreeTest_Ctrl) { | e | on_end_label_edit(e) }
87
- evt_tree_delete_item(TreeTest_Ctrl) { | e | on_delete_item(e) }
88
- evt_tree_set_info(TreeTest_Ctrl) { | e | on_set_info(e) }
89
- evt_tree_item_expanded(TreeTest_Ctrl) { | e | on_item_expanded(e) }
90
- evt_tree_item_expanding(TreeTest_Ctrl) { | e | on_item_expanding(e) }
91
- evt_tree_item_collapsed(TreeTest_Ctrl) { | e | on_item_collapsed(e) }
92
- evt_tree_item_collapsing(TreeTest_Ctrl) { | e | on_item_collapsing(e) }
93
- evt_tree_item_right_click(TreeTest_Ctrl) { | e | on_item_right_click(e) }
94
-
95
- evt_right_up { | e | on_rmouse_up(e) }
96
- evt_tree_sel_changed(TreeTest_Ctrl) { | e | on_sel_changed(e) }
97
- evt_tree_sel_changing(TreeTest_Ctrl) { | e | on_sel_changing(e) }
98
- evt_tree_key_down(TreeTest_Ctrl) { | e | on_tree_key_down(e) }
99
- evt_tree_item_activated(TreeTest_Ctrl) { | e | on_item_activated(e) }
100
- evt_right_dclick { | e | on_rmouse_dclick(event) }
101
-
102
- end
103
-
104
- def show_info(id)
105
- Wx::log_message("Item '%s': %sselected, %sexpanded, %sbold,\n" +
106
- "%d children (%d immediately under selected item).",
107
- get_item_text( id ),
108
- bool_to_str( is_selected( id ) ),
109
- bool_to_str( is_expanded( id ) ),
110
- bool_to_str( is_bold( id ) ),
111
- get_children_count( id ),
112
- get_children_count(id, false) )
113
- end
114
-
115
- def bool_to_str(bool)
116
- bool ? " " : "not "
117
- end
118
-
119
- def do_sort_children(item, reverse = false)
120
- @reverse_sort = reverse
121
- sort_children(item)
122
- end
123
-
124
- def do_ensure_visible()
125
- ensure_visible(@last_item)
126
- end
127
-
128
- def image_size()
129
- return @image_size
130
- end
131
-
132
- def is_test_item(item)
133
- # the test item is the first child folder
134
- return get_item_parent(item) == get_root_item() && !get_prev_sibling(item)
135
- end
136
-
137
- def create_image_list
138
- @imageSize = 16
139
-
140
- # Make an image list containing small icons
141
- images = Wx::ImageList.new(32, 32, true)
142
- # should correspond to TreeCtrlIcon_xxx enum
143
- Wx::BusyCursor.busy do
144
- icons = (1 .. 5).map do | i |
145
- icon_file = File.join(File.dirname(__FILE__), "icon#{i}.xpm")
146
- # Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_XPM, 16, 16)
147
- Wx::Bitmap.new(icon_file, Wx::BITMAP_TYPE_XPM)
148
- end
149
- icons.each { | ic | images.add(ic) }
150
- set_image_list(images)
151
- end
152
- end
153
-
154
- def unset_image_list
155
- set_image_list(nil)
156
- end
157
-
158
- def create_buttons_image_list()
159
- # Make an image list containing small icons
160
- images = Wx::ImageList.new(16, 16, true)
161
-
162
- # should correspond to TreeCtrlIcon_xxx enum
163
- Wx::BusyCursor.busy do |x|
164
- icons = [
165
- Wx::Icon.new("icon3.xpm"), # closed
166
- Wx::Icon.new("icon3.xpm"), # closed, selected
167
- Wx::Icon.new("icon5.xpm"), # open
168
- Wx::Icon.new("icon5.xpm")] # open, selected
169
-
170
- icons.each do | ic |
171
- orig_size = ic.get_width()
172
- if size == orig_size
173
- images.add(ic)
174
- else
175
- resized = ic.convert_to_image().rescale(size, size)
176
- images.add( Wx::Bitmap.new(resized) )
177
- end
178
- end
179
-
180
- set_buttons_image_list(images)
181
- end
182
- end
183
-
184
- def on_compare_items(item1,item2)
185
- if @reverse_sort
186
- # just exchange 1st and 2nd items
187
- return super(item2, item1)
188
- else
189
- return super(item1, item2)
190
- end
191
- end
192
-
193
- def add_items_recursively(parent_id, num_children, depth, folder)
194
- if depth > 0
195
- has_children = depth > 1
196
-
197
- for n in 0 ... num_children
198
- # at depth 1 elements won't have any more children
199
- if has_children
200
- str = sprintf("%s child %d", "Folder", n + 1)
201
- else
202
- str = sprintf("%s child %d.%d", "File", folder, n + 1)
203
- end
204
- # here we pass to append_item() normal and selected item images (we
205
- # suppose that selected image follows the normal one in the enum)
206
- if Wx::get_app.show_images()
207
- image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder
208
- imageSel = image + 1
209
- else
210
- image = imageSel = -1
211
- end
212
- id = append_item(parent_id, str, image, imageSel)
213
-
214
- # and now we also set the expanded one (only for the folders)
215
- if has_children && Wx::get_app.show_images()
216
- set_item_image(id, TreeCtrlIcon_FolderOpened,
217
- Wx::TREE_ITEM_ICON_EXPANDED)
218
- end
219
-
220
- # remember the last child for OnEnsureVisible()
221
- if ! has_children && n == num_children - 1
222
- @last_item = id
223
- end
224
-
225
- add_items_recursively(id, num_children, depth - 1, n + 1)
226
- end
227
- end
228
- end
229
-
230
- def add_test_items_to_tree(num_children,depth)
231
- image = Wx::get_app.show_images ? TreeCtrlIcon_Folder : -1
232
- root_id = add_root("Root",image, image)
233
- if image != -1
234
- set_item_image(root_id, TreeCtrlIcon_FolderOpened,
235
- Wx::TREE_ITEM_ICON_EXPANDED)
236
- end
237
-
238
- add_items_recursively(root_id, num_children, depth, 0)
239
-
240
- # set some colours/fonts for testing
241
- # note that font sizes can also be varied, but only on platforms
242
- # that use the generic TreeCtrl - OS X and GTK, and only if
243
- # Wx::TR_HAS_VARIABLE_ROW_HEIGHT style was used in the constructor
244
- font = get_font
245
- font.set_style(Wx::FONTSTYLE_ITALIC)
246
- set_item_font(root_id, font)
247
-
248
- id,cookie = get_first_child(root_id)
249
- set_item_text_colour(id, Wx::BLUE)
250
-
251
- id,cookie = get_next_child(root_id,cookie)
252
- id,cookie = get_next_child(root_id,cookie)
253
- if Wx::PLATFORM == "WXMSW"
254
- set_item_text_colour(id, Wx::RED)
255
- set_item_background_colour(id, Wx::LIGHT_GREY)
256
- end
257
- end
258
-
259
- def get_items_recursively(parent_id, cookie)
260
- if cookie == -1
261
- id, cookie = get_first_child(parent_id)
262
- else
263
- id, cookie = get_next_child(parent_id, cookie)
264
- end
265
- if not id.nonzero?
266
- return nil
267
- end
268
-
269
- text = get_item_text(id)
270
- Wx::log_message(text)
271
-
272
- if item_has_children(id)
273
- get_items_recursively(id,-1)
274
- end
275
- get_items_recursively(parent_id, cookie)
276
- end
277
-
278
- def do_toggle_icon(item)
279
- old_img = get_item_image(item)
280
- if old_img == TreeCtrlIcon_Folder
281
- new_img = TreeCtrlIcon_File
282
- else
283
- new_img = TreeCtrlIcon_Folder
284
- end
285
-
286
- set_item_image(item, new_img)
287
- end
288
-
289
- def on_begin_rdrag(event)
290
- Wx::log_message("OnBeginRDrag")
291
- event.skip()
292
- end
293
-
294
- def on_delete_item(event)
295
- Wx::log_message("OnDeleteItem")
296
- event.skip()
297
- end
298
-
299
- def on_get_info(event)
300
- Wx::log_message("OnGetInfo")
301
- event.skip()
302
- end
303
-
304
- def on_set_info(event)
305
- Wx::log_message("OnSetInfo")
306
- event.skip()
307
- end
308
-
309
- def on_item_expanded(event)
310
- Wx::log_message("OnItemExpanded")
311
- event.skip()
312
- end
313
-
314
- def on_item_expanding(event)
315
- Wx::log_message("OnItemExpanding")
316
- event.skip()
317
- end
318
-
319
- def on_item_collapsed(event)
320
- Wx::log_message("OnItemCollapsed")
321
- event.skip()
322
- end
323
-
324
- def on_sel_changed(event)
325
- Wx::log_message("OnSelChanged")
326
- event.skip()
327
- end
328
-
329
- def on_sel_changing(event)
330
- Wx::log_message("OnSelChanging")
331
- event.skip()
332
- end
333
-
334
- def log_key_event(name,event)
335
- keycode = event.get_key_code()
336
-
337
- case keycode
338
- when Wx::K_BACK
339
- key = "BACK"
340
- when Wx::K_TAB
341
- key = "TAB"
342
- when Wx::K_RETURN
343
- key = "RETURN"
344
- when Wx::K_ESCAPE
345
- key = "ESCAPE"
346
- when Wx::K_SPACE
347
- key = "SPACE"
348
- when Wx::K_DELETE
349
- key = "DELETE"
350
- when Wx::K_START
351
- key = "START"
352
- when Wx::K_LBUTTON
353
- key = "LBUTTON"
354
- when Wx::K_RBUTTON
355
- key = "RBUTTON"
356
- when Wx::K_CANCEL
357
- key = "CANCEL"
358
- when Wx::K_MBUTTON
359
- key = "MBUTTON"
360
- when Wx::K_CLEAR
361
- key = "CLEAR"
362
- when Wx::K_SHIFT
363
- key = "SHIFT"
364
- when Wx::K_ALT
365
- key = "ALT"
366
- when Wx::K_CONTROL
367
- key = "CONTROL"
368
- when Wx::K_MENU
369
- key = "MENU"
370
- when Wx::K_PAUSE
371
- key = "PAUSE"
372
- when Wx::K_CAPITAL
373
- key = "CAPITAL"
374
- when Wx::K_PRIOR
375
- key = "PRIOR"
376
- when Wx::K_NEXT
377
- key = "NEXT"
378
- when Wx::K_END
379
- key = "END"
380
- when Wx::K_HOME
381
- key = "HOME"
382
- when Wx::K_LEFT
383
- key = "LEFT"
384
- when Wx::K_UP
385
- key = "UP"
386
- when Wx::K_RIGHT
387
- key = "RIGHT"
388
- when Wx::K_DOWN
389
- key = "DOWN"
390
- when Wx::K_SELECT
391
- key = "SELECT"
392
- when Wx::K_PRINT
393
- key = "PRINT"
394
- when Wx::K_EXECUTE
395
- key = "EXECUTE"
396
- when Wx::K_SNAPSHOT
397
- key = "SNAPSHOT"
398
- when Wx::K_INSERT
399
- key = "INSERT"
400
- when Wx::K_HELP
401
- key = "HELP"
402
- when Wx::K_NUMPAD0
403
- key = "NUMPAD0"
404
- when Wx::K_NUMPAD1
405
- key = "NUMPAD1"
406
- when Wx::K_NUMPAD2
407
- key = "NUMPAD2"
408
- when Wx::K_NUMPAD3
409
- key = "NUMPAD3"
410
- when Wx::K_NUMPAD4
411
- key = "NUMPAD4"
412
- when Wx::K_NUMPAD5
413
- key = "NUMPAD5"
414
- when Wx::K_NUMPAD6
415
- key = "NUMPAD6"
416
- when Wx::K_NUMPAD7
417
- key = "NUMPAD7"
418
- when Wx::K_NUMPAD8
419
- key = "NUMPAD8"
420
- when Wx::K_NUMPAD9
421
- key = "NUMPAD9"
422
- when Wx::K_MULTIPLY
423
- key = "MULTIPLY"
424
- when Wx::K_ADD
425
- key = "ADD"
426
- when Wx::K_SEPARATOR
427
- key = "SEPARATOR"
428
- when Wx::K_SUBTRACT
429
- key = "SUBTRACT"
430
- when Wx::K_DECIMAL
431
- key = "DECIMAL"
432
- when Wx::K_DIVIDE
433
- key = "DIVIDE"
434
- when Wx::K_F1
435
- key = "F1"
436
- when Wx::K_F2
437
- key = "F2"
438
- when Wx::K_F3
439
- key = "F3"
440
- when Wx::K_F4
441
- key = "F4"
442
- when Wx::K_F5
443
- key = "F5"
444
- when Wx::K_F6
445
- key = "F6"
446
- when Wx::K_F7
447
- key = "F7"
448
- when Wx::K_F8
449
- key = "F8"
450
- when Wx::K_F9
451
- key = "F9"
452
- when Wx::K_F10
453
- key = "F10"
454
- when Wx::K_F11
455
- key = "F11"
456
- when Wx::K_F12
457
- key = "F12"
458
- when Wx::K_F13
459
- key = "F13"
460
- when Wx::K_F14
461
- key = "F14"
462
- when Wx::K_F15
463
- key = "F15"
464
- when Wx::K_F16
465
- key = "F16"
466
- when Wx::K_F17
467
- key = "F17"
468
- when Wx::K_F18
469
- key = "F18"
470
- when Wx::K_F19
471
- key = "F19"
472
- when Wx::K_F20
473
- key = "F20"
474
- when Wx::K_F21
475
- key = "F21"
476
- when Wx::K_F22
477
- key = "F22"
478
- when Wx::K_F23
479
- key = "F23"
480
- when Wx::K_F24
481
- key = "F24"
482
- when Wx::K_NUMLOCK
483
- key = "NUMLOCK"
484
- when Wx::K_SCROLL
485
- key = "SCROLL"
486
- when Wx::K_PAGEUP
487
- key = "PAGEUP"
488
- when Wx::K_PAGEDOWN
489
- key = "PAGEDOWN"
490
- when Wx::K_NUMPAD_SPACE
491
- key = "NUMPAD_SPACE"
492
- when Wx::K_NUMPAD_TAB
493
- key = "NUMPAD_TAB"
494
- when Wx::K_NUMPAD_ENTER
495
- key = "NUMPAD_ENTER"
496
- when Wx::K_NUMPAD_F1
497
- key = "NUMPAD_F1"
498
- when Wx::K_NUMPAD_F2
499
- key = "NUMPAD_F2"
500
- when Wx::K_NUMPAD_F3
501
- key = "NUMPAD_F3"
502
- when Wx::K_NUMPAD_F4
503
- key = "NUMPAD_F4"
504
- when Wx::K_NUMPAD_HOME
505
- key = "NUMPAD_HOME"
506
- when Wx::K_NUMPAD_LEFT
507
- key = "NUMPAD_LEFT"
508
- when Wx::K_NUMPAD_UP
509
- key = "NUMPAD_UP"
510
- when Wx::K_NUMPAD_RIGHT
511
- key = "NUMPAD_RIGHT"
512
- when Wx::K_NUMPAD_DOWN
513
- key = "NUMPAD_DOWN"
514
- when Wx::K_NUMPAD_PRIOR
515
- key = "NUMPAD_PRIOR"
516
- when Wx::K_NUMPAD_PAGEUP
517
- key = "NUMPAD_PAGEUP"
518
- when Wx::K_NUMPAD_PAGEDOWN
519
- key = "NUMPAD_PAGEDOWN"
520
- when Wx::K_NUMPAD_END
521
- key = "NUMPAD_END"
522
- when Wx::K_NUMPAD_BEGIN
523
- key = "NUMPAD_BEGIN"
524
- when Wx::K_NUMPAD_INSERT
525
- key = "NUMPAD_INSERT"
526
- when Wx::K_NUMPAD_DELETE
527
- key = "NUMPAD_DELETE"
528
- when Wx::K_NUMPAD_EQUAL
529
- key = "NUMPAD_EQUAL"
530
- when Wx::K_NUMPAD_MULTIPLY
531
- key = "NUMPAD_MULTIPLY"
532
- when Wx::K_NUMPAD_ADD
533
- key = "NUMPAD_ADD"
534
- when Wx::K_NUMPAD_SEPARATOR
535
- key = "NUMPAD_SEPARATOR"
536
- when Wx::K_NUMPAD_SUBTRACT
537
- key = "NUMPAD_SUBTRACT"
538
- when Wx::K_NUMPAD_DECIMAL
539
- key = "NUMPAD_DECIMAL"
540
- else
541
- if keycode >= 32 && keycode <127
542
- key = sprintf("'%s'", keycode.chr)
543
- elsif keycode > 0 && keycode < 27
544
- key = sprintf("Ctrl-%c", ?A + keycode - 1)
545
- else
546
- key = sprintf("unknown (%d)", keycode)
547
- end
548
- end
549
-
550
- Wx::log_message( "%s event: %s (flags = %s%s%s%s)",
551
- name, key,
552
- event.control_down() ? 'C' : '-',
553
- event.alt_down() ? 'A' : '-',
554
- event.shift_down() ? 'S' : '-',
555
- event.meta_down() ? 'M' : '-')
556
- end
557
-
558
- def on_tree_key_down(event)
559
- log_key_event("Tree key down ", event.get_key_event())
560
-
561
- event.skip()
562
- end
563
-
564
- def on_begin_drag(event)
565
- # need to explicitly allow drag
566
- if event.get_item() != get_root_item()
567
- @dragged_item = event.get_item()
568
- Wx::log_message("OnBeginDrag: started dragging %s",
569
- get_item_text(@dragged_item))
570
- event.allow()
571
- else
572
- Wx::log_message("OnBeginDrag: selected item can't be dragged.")
573
- end
574
- end
575
-
576
- def on_end_drag(event)
577
- src_item = @dragged_item
578
- dest_item = event.get_item()
579
- @dragged_item = 0
580
-
581
- if dest_item.nonzero? && ! item_has_children(dest_item)
582
- # copy to the parent then
583
- dest_item = get_item_parent(dest_item)
584
- end
585
-
586
- unless dest_item.nonzero?()
587
- Wx::log_message("OnEndDrag: can't drop here.")
588
- return nil
589
- end
590
-
591
- text = get_item_text(src_item)
592
- Wx::log_message("OnEndDrag: '%s' copied to '%s'.",
593
- text, get_item_text(dest_item))
594
-
595
- # just do append here - we could also insert it just before/after the item
596
- # on which it was dropped, but self requires slightly more work... we also
597
- # completely ignore the client data and icon of the old item but could
598
- # copy them as well.
599
- #
600
- # Finally, we only copy one item here but we might copy the entire tree if
601
- # we were dragging a folder.
602
- image = Wx::get_app().show_images() ? TreeCtrlIcon_File : -1
603
- append_item(dest_item, text, image)
604
- end
605
-
606
- def on_begin_label_edit(event)
607
- Wx::log_message("OnBeginLabelEdit")
608
-
609
- # for testing, prevent self item's label editing
610
- item_id = event.get_item()
611
- if is_test_item(item_id)
612
- message_box("The demo prevents you editing this item.")
613
- event.veto()
614
- end
615
- end
616
-
617
- def on_end_label_edit(event)
618
- Wx::log_message("OnEndLabelEdit")
619
- if event.is_edit_cancelled
620
- Wx::log_message("Label edit was cancelled by user")
621
- return
622
- end
623
-
624
- # For a demo, don't allow anything except letters in the labels
625
- if event.get_label =~ /[^\w.]/
626
- msg = "Only letters, numbers and full stops are allowed in the label."
627
- message_box(msg)
628
- Wx::log_message("Label edit was cancelled by demo")
629
- event.veto()
630
- end
631
- end
632
-
633
- def on_item_collapsing(event)
634
- Wx::log_message("OnItemCollapsing")
635
-
636
- # for testing, prevent the user from collapsing the first child folder
637
- item_id = event.get_item()
638
- if is_test_item(item_id)
639
- message_box("You can't collapse self item.")
640
-
641
- event.veto()
642
- end
643
- end
644
-
645
- # show some info about activated item
646
- def on_item_activated(event)
647
- if item_id = event.get_item()
648
- show_info(item_id)
649
- end
650
- Wx::log_message("OnItemActivated")
651
- end
652
-
653
- def on_item_right_click(event)
654
- show_popup_menu(event.get_item(), event.get_point())
655
- end
656
-
657
- def on_rmouse_up(event)
658
- pos = event.get_position()
659
- item = hit_test(pos)
660
- show_popup_menu(item, pos)
661
- end
662
-
663
- def show_popup_menu(id, pos)
664
- title = ""
665
- if id.nonzero?
666
- title << "Menu for " << get_item_text(id)
667
- else
668
- title = "Menu for no particular item"
669
- end
670
-
671
- menu = Wx::Menu.new(title)
672
- menu.append(Wx::ID_ABOUT, "&About...")
673
- menu.append(TreeTest_Dump, "&Dump")
674
- popup_menu(menu, pos)
675
- end
676
-
677
- def on_rmouse_dclick(event)
678
- id = hit_test(event.get_position())
679
- if not id
680
- Wx::log_message("No item under mouse")
681
- else
682
- item = get_item_text(id)
683
- if item
684
- Wx::log_message("Item '%s' under mouse", item)
685
- end
686
- end
687
- end
688
- end
689
-
690
-
691
- class MyFrame < Wx::Frame
692
- def initialize(title, x, y, w, h)
693
- super(nil, -1, title, Wx::Point.new(x, y), Wx::Size.new(w, h))
694
- @treectrl = nil
695
- @textctrl = nil
696
- @s_num = 0
697
-
698
- # This reduces flicker effects - even better would be to define
699
- # OnEraseBackground to do nothing. When the tree control's scrollbars are
700
- # show or hidden, the frame is sent a background erase event.
701
- set_background_colour(Wx::Colour.new(255, 255, 255))
702
-
703
- # Make a menubar
704
- file_menu = Wx::Menu.new
705
- style_menu = Wx::Menu.new
706
- tree_menu = Wx::Menu.new
707
- item_menu = Wx::Menu.new
708
-
709
- file_menu.append(Wx::ID_ABOUT, "&About...")
710
- file_menu.append_separator()
711
- file_menu.append(Wx::ID_EXIT, "E&xit\tAlt-X")
712
-
713
- style_menu.append(TreeTest_TogButtons,
714
- "Toggle &normal buttons", "", Wx::ITEM_CHECK)
715
- style_menu.append(TreeTest_TogTwist,
716
- "Toggle &twister buttons", "", Wx::ITEM_CHECK)
717
- style_menu.append(TreeTest_ToggleButtons,
718
- "Toggle image &buttons", "", Wx::ITEM_CHECK)
719
- style_menu.append_separator()
720
- style_menu.append(TreeTest_TogLines,
721
- "Toggle &connecting lines", "", Wx::ITEM_CHECK)
722
- style_menu.append(TreeTest_TogRootLines,
723
- "Toggle &lines at root", "", Wx::ITEM_CHECK)
724
- style_menu.append(TreeTest_TogHideRoot,
725
- "Toggle &hidden root", "", Wx::ITEM_CHECK)
726
- style_menu.append(TreeTest_TogBorder,
727
- "Toggle &item border", "", Wx::ITEM_CHECK)
728
- style_menu.append(TreeTest_TogFullHighlight,
729
- "Toggle &full row highlight", "", Wx::ITEM_CHECK)
730
- style_menu.append(TreeTest_TogEdit,
731
- "Toggle &editing allowed", "", Wx::ITEM_CHECK)
732
- style_menu.append(TreeTest_ToggleSel,
733
- "Toggle multiple &selection", "", Wx::ITEM_CHECK)
734
- style_menu.append(TreeTest_ToggleImages,
735
- "Toggle show ima&ges", "", Wx::ITEM_CHECK)
736
- style_menu.append(TreeTest_SetImageSize, "Set image si&ze...")
737
- style_menu.append_separator()
738
- style_menu.append(TreeTest_SetFgColour, "Set &foreground colour...")
739
- style_menu.append(TreeTest_SetBgColour, "Set &background colour...")
740
- style_menu.append_separator()
741
- style_menu.append(TreeTest_ResetStyle, "&Reset to default\tF10")
742
-
743
- tree_menu.append(TreeTest_Recreate, "&Recreate the tree")
744
- tree_menu.append(TreeTest_CollapseAndReset, "C&ollapse and reset")
745
- tree_menu.append_separator()
746
- tree_menu.append(TreeTest_AddItem, "Append a &new item")
747
- tree_menu.append(TreeTest_InsertItem, "&Insert a new item")
748
- tree_menu.append(TreeTest_Delete, "&Delete selected item")
749
- tree_menu.append(TreeTest_DeleteChildren, "Delete &children")
750
- tree_menu.append(TreeTest_DeleteAll, "Delete &all items")
751
- tree_menu.append_separator()
752
- tree_menu.append(TreeTest_Count, "Count children of current item")
753
- tree_menu.append(TreeTest_CountRec, "Recursively count children of current item")
754
- tree_menu.append_separator()
755
- tree_menu.append(TreeTest_Sort, "Sort children")
756
- tree_menu.append(TreeTest_SortRev, "Reverse sort children")
757
- tree_menu.append_separator()
758
- tree_menu.append(TreeTest_EnsureVisible, "Make the last item &visible")
759
- tree_menu.append_separator()
760
- tree_menu.append(TreeTest_IncIndent, "Increase indentation\tAlt-I")
761
- tree_menu.append(TreeTest_DecIndent, "Reduce indentation\tAlt-R")
762
- tree_menu.append_separator()
763
- tree_menu.append(TreeTest_IncSpacing, "Increase spacing\tCtrl-I")
764
- tree_menu.append(TreeTest_DecSpacing, "Reduce spacing\tCtrl-R")
765
-
766
- item_menu.append(TreeTest_Dump, "&Dump item children")
767
- item_menu.append(TreeTest_Rename, "&Rename item...")
768
-
769
- item_menu.append_separator()
770
- item_menu.append(TreeTest_SetBold, "Make item &bold")
771
- item_menu.append(TreeTest_ClearBold, "Make item &not bold")
772
- item_menu.append_separator()
773
- item_menu.append(TreeTest_ToggleIcon, "Toggle the item's &icon")
774
-
775
- item_menu.append_separator()
776
- item_menu.append(TreeTest_DumpSelected, "Dump selected items\tAlt-D")
777
- item_menu.append(TreeTest_Select, "Select current item\tAlt-S")
778
- item_menu.append(TreeTest_Unselect, "Unselect everything\tAlt-U")
779
-
780
- menu_bar = Wx::MenuBar.new
781
- menu_bar.append(file_menu, "&File")
782
- menu_bar.append(style_menu, "&Style")
783
- menu_bar.append(tree_menu, "&Tree")
784
- menu_bar.append(item_menu, "&Item")
785
- set_menu_bar(menu_bar)
786
-
787
-
788
- # create the controls
789
- @textctrl = Wx::TextCtrl.new(self, -1, "",
790
- Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE,
791
- Wx::TE_MULTILINE|Wx::SUNKEN_BORDER)
792
-
793
- create_tree_with_default_style()
794
-
795
- menu_bar.check(TreeTest_ToggleImages, true)
796
-
797
- # create a status bar with 3 panes
798
- create_status_bar(3)
799
- set_status_text("", 0)
800
-
801
- # set our text control as the log target
802
- logWindow = Wx::LogTextCtrl.new(@textctrl)
803
- Wx::Log::set_active_target(logWindow)
804
-
805
- evt_size {|event| on_size(event) }
806
-
807
- evt_menu(Wx::ID_EXIT) {|event| on_quit(event) }
808
- evt_menu(Wx::ID_ABOUT) {|event| on_about(event) }
809
-
810
- evt_menu(TreeTest_TogButtons) {|event| on_tog_buttons(event) }
811
- evt_menu(TreeTest_TogTwist) {|event| on_tog_twist(event) }
812
- evt_menu(TreeTest_TogLines) {|event| on_tog_lines(event) }
813
- evt_menu(TreeTest_TogEdit) {|event| on_tog_edit(event) }
814
- evt_menu(TreeTest_TogHideRoot) {|event| on_tog_hide_root(event) }
815
- evt_menu(TreeTest_TogRootLines) {|event| on_tog_root_lines(event) }
816
- evt_menu(TreeTest_TogBorder) {|event| on_tog_border(event) }
817
- evt_menu(TreeTest_TogFullHighlight) {|event| on_tog_full_highlight(event) }
818
- evt_menu(TreeTest_SetFgColour) {|event| on_set_fg_colour(event) }
819
- evt_menu(TreeTest_SetBgColour) {|event| on_set_bg_colour(event) }
820
- evt_menu(TreeTest_ResetStyle) {|event| on_reset_style(event) }
821
-
822
- evt_menu(TreeTest_Dump) {|event| on_dump(event) }
823
- evt_menu(TreeTest_DumpSelected) {|event| on_dump_selected(event) }
824
- evt_menu(TreeTest_Select) {|event| on_select(event) }
825
- evt_menu(TreeTest_Unselect) {|event| on_unselect(event) }
826
- evt_menu(TreeTest_ToggleSel) {|event| on_toggle_sel(event) }
827
- evt_menu(TreeTest_Rename) {|event| on_rename(event) }
828
- evt_menu(TreeTest_Count) {|event| on_count(event) }
829
- evt_menu(TreeTest_CountRec) {|event| on_count_rec(event) }
830
- evt_menu(TreeTest_Sort) {|event| on_sort(event) }
831
- evt_menu(TreeTest_SortRev) {|event| on_sort_rev(event) }
832
- evt_menu(TreeTest_SetBold) {|event| on_set_bold(event) }
833
- evt_menu(TreeTest_ClearBold) {|event| on_clear_bold(event) }
834
- evt_menu(TreeTest_Delete) {|event| on_delete(event) }
835
- evt_menu(TreeTest_DeleteChildren) {|event| on_delete_children(event) }
836
- evt_menu(TreeTest_DeleteAll) {|event| on_delete_all(event) }
837
- evt_menu(TreeTest_Recreate) {|event| on_recreate(event) }
838
- evt_menu(TreeTest_ToggleImages) {|event| on_toggle_images(event) }
839
- evt_menu(TreeTest_ToggleButtons) {|event| on_toggle_buttons(event) }
840
- evt_menu(TreeTest_SetImageSize) {|event| on_set_image_size(event) }
841
- evt_menu(TreeTest_CollapseAndReset) {|event| on_collapse_and_reset(event) }
842
- evt_menu(TreeTest_EnsureVisible) {|event| on_ensure_visible(event) }
843
- evt_menu(TreeTest_AddItem) {|event| on_add_item(event) }
844
- evt_menu(TreeTest_InsertItem) {|event| on_insert_item(event) }
845
- evt_menu(TreeTest_IncIndent) {|event| on_inc_indent(event) }
846
- evt_menu(TreeTest_DecIndent) {|event| on_dec_indent(event) }
847
- evt_menu(TreeTest_IncSpacing) {|event| on_inc_spacing(event) }
848
- evt_menu(TreeTest_DecSpacing) {|event| on_dec_spacing(event) }
849
- evt_menu(TreeTest_ToggleIcon) {|event| on_toggle_icon(event) }
850
-
851
- evt_close {|event| on_close(event) }
852
- end
853
-
854
- def create_tree_with_default_style()
855
-
856
- style = Wx::TR_DEFAULT_STYLE|Wx::TR_EDIT_LABELS|
857
- Wx::TR_TWIST_BUTTONS|Wx::TR_ROW_LINES|Wx::TR_FULL_ROW_HIGHLIGHT
858
-
859
- create_tree(style|Wx::SUNKEN_BORDER)
860
-
861
- # as we don't know what Wx::TR_DEFAULT_STYLE could contain, test for
862
- # everything
863
- mbar = get_menu_bar()
864
- mbar.check(TreeTest_TogButtons, (style & Wx::TR_HAS_BUTTONS) != 0)
865
- mbar.check(TreeTest_TogButtons, (style & Wx::TR_TWIST_BUTTONS) != 0)
866
- mbar.check(TreeTest_TogLines, (style & Wx::TR_NO_LINES) == 0)
867
- mbar.check(TreeTest_TogRootLines, (style & Wx::TR_LINES_AT_ROOT) != 0)
868
- mbar.check(TreeTest_TogHideRoot, (style & Wx::TR_HIDE_ROOT) != 0)
869
- mbar.check(TreeTest_TogEdit, (style & Wx::TR_EDIT_LABELS) != 0)
870
- mbar.check(TreeTest_TogBorder, (style & Wx::TR_ROW_LINES) != 0)
871
- mbar.check(TreeTest_TogFullHighlight, (style & Wx::TR_FULL_ROW_HIGHLIGHT) != 0)
872
- end
873
-
874
- def create_tree(style)
875
- @treectrl = MyTreeCtrl.new(self, TreeTest_Ctrl,
876
- Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE,
877
- style)
878
- resize()
879
- end
880
-
881
- def tog_style(id,flag)
882
-
883
- style = @treectrl.get_window_style_flag() ^ flag
884
-
885
- # most treectrl styles can't be changed on the fly using the native
886
- # control and the tree must be recreated
887
- @treectrl.destroy
888
- create_tree(style)
889
- get_menu_bar().check(id, (style & flag) != 0)
890
- end
891
-
892
- def on_tog_buttons(event)
893
- tog_style(event.get_id(), Wx::TR_HAS_BUTTONS)
894
- end
895
-
896
- def on_tog_twist(event)
897
- tog_style(event.get_id(), Wx::TR_TWIST_BUTTONS)
898
- end
899
-
900
- def on_tog_lines(event)
901
- tog_style(event.get_id(), Wx::TR_NO_LINES)
902
- end
903
-
904
- def on_tog_edit(event)
905
- tog_style(event.get_id(), Wx::TR_EDIT_LABELS)
906
- end
907
-
908
- def on_tog_hide_root(event)
909
- tog_style(event.get_id(), Wx::TR_HIDE_ROOT)
910
- end
911
-
912
- def on_tog_root_lines(event)
913
- tog_style(event.get_id(), Wx::TR_LINES_AT_ROOT)
914
- end
915
-
916
- def on_tog_border(event)
917
- tog_style(event.get_id(), Wx::TR_ROW_LINES)
918
- end
919
-
920
- def on_tog_full_highlight(event)
921
- tog_style(event.get_id(), Wx::TR_FULL_ROW_HIGHLIGHT)
922
- end
923
-
924
- def on_reset_style(event)
925
- create_tree_with_default_style()
926
- end
927
-
928
- def on_set_bold(event)
929
- do_set_bold(true)
930
- end
931
-
932
- def on_clear_bold(event)
933
- do_set_bold(false)
934
- end
935
-
936
- def on_sort(event)
937
- do_sort()
938
- end
939
-
940
- def on_sort_rev(event)
941
- do_sort(true)
942
- end
943
-
944
- def on_size(event)
945
- if @treectrl && @textctrl
946
- resize()
947
- end
948
-
949
- event.skip()
950
- end
951
-
952
- def resize()
953
- my_size = get_client_size()
954
- tree_size = Wx::Size.new(my_size.x, 2*my_size.y/3)
955
- @treectrl.set_size( tree_size )
956
- @textctrl.set_dimensions(0, 2*my_size.y/3, my_size.x, my_size.y/3)
957
- end
958
-
959
- def on_close(event)
960
- Wx::Log::set_active_target(nil)
961
- destroy()
962
- end
963
-
964
- def on_quit(event)
965
- close(true)
966
- end
967
-
968
- def on_about(event)
969
- Wx::message_box("Tree test sample\n" +
970
- "(c) Julian Smart 1997, Vadim Zeitlin 1998",
971
- "About tree test",
972
- Wx::OK|Wx::ICON_INFORMATION, self)
973
- end
974
-
975
- def check_item(item)
976
- unless item.nonzero?
977
- message_box("Please select some item first!",
978
- "Tree sample error",
979
- Wx::OK|Wx::ICON_EXCLAMATION, self)
980
- return false
981
- end
982
- true
983
- end
984
-
985
- def on_rename(event)
986
- item = @treectrl.get_selection()
987
-
988
- return nil unless check_item( item )
989
-
990
- # TODO demonstrate creating a custom edit control...
991
- @treectrl.edit_label(item)
992
- end
993
-
994
- def on_count(event)
995
- item = @treectrl.get_selection()
996
-
997
- return nil unless check_item( item )
998
-
999
- i = @treectrl.get_children_count( item, false )
1000
-
1001
- Wx::log_message("%d children", i)
1002
- end
1003
-
1004
- def on_count_rec(event)
1005
- item = @treectrl.get_selection()
1006
- return nil unless check_item( item )
1007
- Wx::log_message("%d children", @treectrl.get_children_count( item ))
1008
- end
1009
-
1010
- def do_sort(reverse = false)
1011
- item = @treectrl.get_selection()
1012
- return nil unless check_item( item )
1013
- @treectrl.do_sort_children(item, reverse)
1014
- end
1015
-
1016
- def on_dump(event)
1017
- root = @treectrl.get_selection()
1018
-
1019
- return nil unless check_item( root )
1020
-
1021
- @treectrl.get_items_recursively(root, -1)
1022
- end
1023
-
1024
- def on_toggle_sel(event)
1025
- tog_style(event.get_id(), Wx::TR_MULTIPLE)
1026
- end
1027
-
1028
- def on_dump_selected(event)
1029
- if ( @treectrl.get_window_style & Wx::TR_MULTIPLE ) == 0
1030
- item_id = @treectrl.get_selection
1031
- if item_id.nonzero?
1032
- Wx::log_message("<TreeItem '%s'>",
1033
- @treectrl.get_item_text(item_id))
1034
- else
1035
- Wx::log_message("No tree item selected")
1036
- end
1037
- else
1038
- Wx::log_message("NOT IMPLEMENTED: Multiple selections not available")
1039
- # Requires Wx::List - Ruby Array typemap, pointer handling, 29/08/2006
1040
- # Currently raises incorrect number of args, 1 for 0
1041
- # selected = @treectrl.get_selections()
1042
- # selected_items.each do | item_id |
1043
- # Wx::log_message("\t%s", @treectrl.get_item_text(item_id))
1044
- # end
1045
- end
1046
- end
1047
-
1048
- def on_select(event)
1049
- @treectrl.select_item(@treectrl.get_selection())
1050
- end
1051
-
1052
- def on_unselect(event)
1053
- @treectrl.unselect_all()
1054
- end
1055
-
1056
- def do_set_bold(bold = true)
1057
- item = @treectrl.get_selection()
1058
-
1059
- return nil unless check_item( item )
1060
-
1061
- @treectrl.set_item_bold(item, bold)
1062
- end
1063
-
1064
- def on_delete(event)
1065
- item = @treectrl.get_selection()
1066
-
1067
- return nil unless check_item( item )
1068
-
1069
- @treectrl.delete(item)
1070
- end
1071
-
1072
- def on_delete_children(event)
1073
- item = @treectrl.get_selection()
1074
-
1075
- return nil unless check_item( item )
1076
-
1077
- @treectrl.delete_children(item)
1078
- end
1079
-
1080
- def on_delete_all(event)
1081
- @treectrl.delete_all_items()
1082
- end
1083
-
1084
- def on_recreate(event)
1085
- on_delete_all(event)
1086
- @treectrl.add_test_items_to_tree(5, 2)
1087
- end
1088
-
1089
- def on_set_image_size(event)
1090
- size = get_number_from_user("Enter the size for the images to use",
1091
- "Size: ",
1092
- "TreeCtrl sample",
1093
- @treectrl.image_size())
1094
- if size == -1
1095
- return nil
1096
- end
1097
-
1098
- @treectrl.create_image_list(size)
1099
- Wx::get_app.show_images = true
1100
- end
1101
-
1102
- def on_toggle_images(event)
1103
- if Wx::get_app.show_images
1104
- @treectrl.unset_image_list
1105
- Wx::get_app.show_images = false
1106
- else
1107
- @treectrl.create_image_list
1108
- Wx::get_app.show_images = true
1109
- end
1110
- end
1111
-
1112
- def on_toggle_buttons(event)
1113
- end
1114
-
1115
- def on_collapse_and_reset(event)
1116
- @treectrl.collapse_and_reset(@treectrl.get_root_item())
1117
- end
1118
-
1119
- def on_ensure_visible(event)
1120
- @treectrl.do_ensure_visible()
1121
- end
1122
-
1123
- def on_insert_item(event)
1124
- image = Wx::get_app.show_images() ? TreeCtrlIcon_File : -1
1125
- @treectrl.insert_item(@treectrl.get_root_item(), -1, "2nd item", image)
1126
- end
1127
-
1128
- def on_add_item(event)
1129
- @s_num += 1
1130
- text = sprintf("Item #%d", @s_num)
1131
- @treectrl.append_item(@treectrl.get_root_item(), text)
1132
- end
1133
-
1134
- def on_inc_indent(event)
1135
- indent = @treectrl.get_indent()
1136
- if indent < 100
1137
- @treectrl.set_indent( indent+5 )
1138
- end
1139
- end
1140
-
1141
- def on_dec_indent(event)
1142
- indent = @treectrl.get_indent()
1143
- if indent > 10
1144
- @treectrl.set_indent( indent-5 )
1145
- end
1146
- end
1147
-
1148
- def on_inc_spacing(event)
1149
- indent = @treectrl.get_spacing()
1150
- if indent < 100
1151
- @treectrl.set_spacing( indent+5 )
1152
- end
1153
- end
1154
-
1155
- def on_dec_spacing(event)
1156
- indent = @treectrl.get_spacing()
1157
- if indent > 10
1158
- @treectrl.set_spacing( indent-5 )
1159
- end
1160
- end
1161
-
1162
- def on_toggle_icon(event)
1163
- item = @treectrl.get_selection()
1164
- return nil unless check_item( item )
1165
- @treectrl.do_toggle_icon(item)
1166
- end
1167
-
1168
- # TODO
1169
- def on_set_fg_colour(event)
1170
- Wx::log_message('NOT IMPLEMENTED')
1171
- return
1172
- col = Wx::get_colour_from_user(self, @treectrl.get_foreground_colour())
1173
- if col.is_ok
1174
- @treectrl.set_foreground_colour(col)
1175
- end
1176
- end
1177
-
1178
- # TODO
1179
- def on_set_bg_colour(event)
1180
- Wx::log_message('NOT IMPLEMENTED')
1181
- return
1182
- col = Wx::get_colour_from_user(self, @treectrl.get_background_colour())
1183
- if col.is_ok
1184
- @treectrl.set_background_colour(col)
1185
- end
1186
- end
1187
-
1188
- end
1189
-
1190
- class MyApp < Wx::App
1191
- attr_accessor :show_images, :show_buttons
1192
- def initialize
1193
- self.show_images = true
1194
- self.show_buttons = false
1195
- super
1196
- end
1197
-
1198
- def on_init
1199
- # Create the main frame window
1200
- frame = MyFrame.new("TreeCtrl Test", 50, 50, 450, 600)
1201
-
1202
- # show the frame
1203
- frame.show(true)
1204
- # set_top_window(frame)
1205
-
1206
- end
1207
- end
1208
-
1209
- a = MyApp.new
1210
- a.main_loop()
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
+
16
+ # This sample shows off the features of the TreeCtrl widget. The actual
17
+ # features vary somewhat across platforms; for example, the button
18
+ # styles and connecting lines between items are not available on OS X.
19
+ # Also, some items remain to be implemented - for example, setting item
20
+ # icons and item data.
21
+
22
+ # Just some event ids for the numerous menu items
23
+ TreeTest_TogButtons,
24
+ TreeTest_TogTwist,
25
+ TreeTest_TogLines,
26
+ TreeTest_TogEdit,
27
+ TreeTest_TogHideRoot,
28
+ TreeTest_TogRootLines,
29
+ TreeTest_TogBorder,
30
+ TreeTest_TogFullHighlight,
31
+ TreeTest_SetFgColour,
32
+ TreeTest_SetBgColour,
33
+ TreeTest_ResetStyle,
34
+ TreeTest_Dump,
35
+ TreeTest_DumpSelected,
36
+ TreeTest_Count,
37
+ TreeTest_CountRec,
38
+ TreeTest_Sort,
39
+ TreeTest_SortRev,
40
+ TreeTest_SetBold,
41
+ TreeTest_ClearBold,
42
+ TreeTest_Rename,
43
+ TreeTest_Delete,
44
+ TreeTest_DeleteChildren,
45
+ TreeTest_DeleteAll,
46
+ TreeTest_Recreate,
47
+ TreeTest_ToggleImages,
48
+ TreeTest_ToggleButtons,
49
+ TreeTest_SetImageSize,
50
+ TreeTest_ToggleSel,
51
+ TreeTest_CollapseAndReset,
52
+ TreeTest_EnsureVisible,
53
+ TreeTest_AddItem,
54
+ TreeTest_InsertItem,
55
+ TreeTest_IncIndent,
56
+ TreeTest_DecIndent,
57
+ TreeTest_IncSpacing,
58
+ TreeTest_DecSpacing,
59
+ TreeTest_ToggleIcon,
60
+ TreeTest_Select,
61
+ TreeTest_Unselect = (Wx::ID_HIGHEST..Wx::ID_HIGHEST+39).to_a
62
+ TreeTest_Ctrl = 1000
63
+
64
+ TreeCtrlIcon_File,
65
+ TreeCtrlIcon_FileSelected,
66
+ TreeCtrlIcon_Folder,
67
+ TreeCtrlIcon_FolderSelected,
68
+ TreeCtrlIcon_FolderOpened = 0,1,2,3,4
69
+
70
+ class MyTreeCtrl < Wx::TreeCtrl
71
+ def initialize(parent, id,pos, size,style)
72
+ super(parent, id, pos, size, style)
73
+
74
+ @reverse_sort = false
75
+
76
+ create_image_list
77
+
78
+ # add some items to the tree
79
+ add_test_items_to_tree(5, 2)
80
+
81
+ # TreeCtrl supports a large number of different events...
82
+ evt_tree_begin_drag(TreeTest_Ctrl) { | e | on_begin_drag(e) }
83
+ evt_tree_begin_rdrag(TreeTest_Ctrl) { | e | on_begin_rdrag(e) }
84
+ evt_tree_end_drag(TreeTest_Ctrl) { | e | on_end_drag(e) }
85
+ evt_tree_begin_label_edit(TreeTest_Ctrl) { | e | on_begin_label_edit(e) }
86
+ evt_tree_end_label_edit(TreeTest_Ctrl) { | e | on_end_label_edit(e) }
87
+ evt_tree_delete_item(TreeTest_Ctrl) { | e | on_delete_item(e) }
88
+ evt_tree_set_info(TreeTest_Ctrl) { | e | on_set_info(e) }
89
+ evt_tree_item_expanded(TreeTest_Ctrl) { | e | on_item_expanded(e) }
90
+ evt_tree_item_expanding(TreeTest_Ctrl) { | e | on_item_expanding(e) }
91
+ evt_tree_item_collapsed(TreeTest_Ctrl) { | e | on_item_collapsed(e) }
92
+ evt_tree_item_collapsing(TreeTest_Ctrl) { | e | on_item_collapsing(e) }
93
+ evt_tree_item_right_click(TreeTest_Ctrl) { | e | on_item_right_click(e) }
94
+
95
+ evt_right_up { | e | on_rmouse_up(e) }
96
+ evt_tree_sel_changed(TreeTest_Ctrl) { | e | on_sel_changed(e) }
97
+ evt_tree_sel_changing(TreeTest_Ctrl) { | e | on_sel_changing(e) }
98
+ evt_tree_key_down(TreeTest_Ctrl) { | e | on_tree_key_down(e) }
99
+ evt_tree_item_activated(TreeTest_Ctrl) { | e | on_item_activated(e) }
100
+ evt_right_dclick { | e | on_rmouse_dclick(event) }
101
+
102
+ end
103
+
104
+ def show_info(id)
105
+ Wx::log_message("Item '%s': %sselected, %sexpanded, %sbold,\n" +
106
+ "%d children (%d immediately under selected item).",
107
+ get_item_text( id ),
108
+ bool_to_str( is_selected( id ) ),
109
+ bool_to_str( is_expanded( id ) ),
110
+ bool_to_str( is_bold( id ) ),
111
+ get_children_count( id ),
112
+ get_children_count(id, false) )
113
+ end
114
+
115
+ def bool_to_str(bool)
116
+ bool ? " " : "not "
117
+ end
118
+
119
+ def do_sort_children(item, reverse = false)
120
+ @reverse_sort = reverse
121
+ sort_children(item)
122
+ end
123
+
124
+ def do_ensure_visible()
125
+ ensure_visible(@last_item)
126
+ end
127
+
128
+ def image_size()
129
+ return @image_size
130
+ end
131
+
132
+ def is_test_item(item)
133
+ # the test item is the first child folder
134
+ return get_item_parent(item) == get_root_item() && !get_prev_sibling(item)
135
+ end
136
+
137
+ def create_image_list
138
+ @imageSize = 16
139
+
140
+ # Make an image list containing small icons
141
+ images = Wx::ImageList.new(32, 32, true)
142
+ # should correspond to TreeCtrlIcon_xxx enum
143
+ Wx::BusyCursor.busy do
144
+ icons = (1 .. 5).map do | i |
145
+ icon_file = File.join(File.dirname(__FILE__), "icon#{i}.xpm")
146
+ # Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_XPM, 16, 16)
147
+ Wx::Bitmap.new(icon_file, Wx::BITMAP_TYPE_XPM)
148
+ end
149
+ icons.each { | ic | images.add(ic) }
150
+ set_image_list(images)
151
+ end
152
+ end
153
+
154
+ def unset_image_list
155
+ set_image_list(nil)
156
+ end
157
+
158
+ def create_buttons_image_list()
159
+ # Make an image list containing small icons
160
+ images = Wx::ImageList.new(16, 16, true)
161
+
162
+ # should correspond to TreeCtrlIcon_xxx enum
163
+ Wx::BusyCursor.busy do |x|
164
+ icons = [
165
+ Wx::Icon.new("icon3.xpm"), # closed
166
+ Wx::Icon.new("icon3.xpm"), # closed, selected
167
+ Wx::Icon.new("icon5.xpm"), # open
168
+ Wx::Icon.new("icon5.xpm")] # open, selected
169
+
170
+ icons.each do | ic |
171
+ orig_size = ic.get_width()
172
+ if size == orig_size
173
+ images.add(ic)
174
+ else
175
+ resized = ic.convert_to_image().rescale(size, size)
176
+ images.add( Wx::Bitmap.new(resized) )
177
+ end
178
+ end
179
+
180
+ set_buttons_image_list(images)
181
+ end
182
+ end
183
+
184
+ def on_compare_items(item1,item2)
185
+ if @reverse_sort
186
+ # just exchange 1st and 2nd items
187
+ return super(item2, item1)
188
+ else
189
+ return super(item1, item2)
190
+ end
191
+ end
192
+
193
+ def add_items_recursively(parent_id, num_children, depth, folder)
194
+ if depth > 0
195
+ has_children = depth > 1
196
+
197
+ for n in 0 ... num_children
198
+ # at depth 1 elements won't have any more children
199
+ if has_children
200
+ str = sprintf("%s child %d", "Folder", n + 1)
201
+ else
202
+ str = sprintf("%s child %d.%d", "File", folder, n + 1)
203
+ end
204
+ # here we pass to append_item() normal and selected item images (we
205
+ # suppose that selected image follows the normal one in the enum)
206
+ if Wx::get_app.show_images()
207
+ image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder
208
+ imageSel = image + 1
209
+ else
210
+ image = imageSel = -1
211
+ end
212
+ id = append_item(parent_id, str, image, imageSel)
213
+
214
+ # and now we also set the expanded one (only for the folders)
215
+ if has_children && Wx::get_app.show_images()
216
+ set_item_image(id, TreeCtrlIcon_FolderOpened,
217
+ Wx::TREE_ITEM_ICON_EXPANDED)
218
+ end
219
+
220
+ # remember the last child for OnEnsureVisible()
221
+ if ! has_children && n == num_children - 1
222
+ @last_item = id
223
+ end
224
+
225
+ add_items_recursively(id, num_children, depth - 1, n + 1)
226
+ end
227
+ end
228
+ end
229
+
230
+ def add_test_items_to_tree(num_children,depth)
231
+ image = Wx::get_app.show_images ? TreeCtrlIcon_Folder : -1
232
+ root_id = add_root("Root",image, image)
233
+ if image != -1
234
+ set_item_image(root_id, TreeCtrlIcon_FolderOpened,
235
+ Wx::TREE_ITEM_ICON_EXPANDED)
236
+ end
237
+
238
+ add_items_recursively(root_id, num_children, depth, 0)
239
+
240
+ # set some colours/fonts for testing
241
+ # note that font sizes can also be varied, but only on platforms
242
+ # that use the generic TreeCtrl - OS X and GTK, and only if
243
+ # Wx::TR_HAS_VARIABLE_ROW_HEIGHT style was used in the constructor
244
+ font = get_font
245
+ font.set_style(Wx::FONTSTYLE_ITALIC)
246
+ set_item_font(root_id, font)
247
+
248
+ id,cookie = get_first_child(root_id)
249
+ set_item_text_colour(id, Wx::BLUE)
250
+
251
+ id,cookie = get_next_child(root_id,cookie)
252
+ id,cookie = get_next_child(root_id,cookie)
253
+ if Wx::PLATFORM == "WXMSW"
254
+ set_item_text_colour(id, Wx::RED)
255
+ set_item_background_colour(id, Wx::LIGHT_GREY)
256
+ end
257
+ end
258
+
259
+ def get_items_recursively(parent_id, cookie)
260
+ if cookie == -1
261
+ id, cookie = get_first_child(parent_id)
262
+ else
263
+ id, cookie = get_next_child(parent_id, cookie)
264
+ end
265
+ if not id.nonzero?
266
+ return nil
267
+ end
268
+
269
+ text = get_item_text(id)
270
+ Wx::log_message(text)
271
+
272
+ if item_has_children(id)
273
+ get_items_recursively(id,-1)
274
+ end
275
+ get_items_recursively(parent_id, cookie)
276
+ end
277
+
278
+ def do_toggle_icon(item)
279
+ old_img = get_item_image(item)
280
+ if old_img == TreeCtrlIcon_Folder
281
+ new_img = TreeCtrlIcon_File
282
+ else
283
+ new_img = TreeCtrlIcon_Folder
284
+ end
285
+
286
+ set_item_image(item, new_img)
287
+ end
288
+
289
+ def on_begin_rdrag(event)
290
+ Wx::log_message("OnBeginRDrag")
291
+ event.skip()
292
+ end
293
+
294
+ def on_delete_item(event)
295
+ Wx::log_message("OnDeleteItem")
296
+ event.skip()
297
+ end
298
+
299
+ def on_get_info(event)
300
+ Wx::log_message("OnGetInfo")
301
+ event.skip()
302
+ end
303
+
304
+ def on_set_info(event)
305
+ Wx::log_message("OnSetInfo")
306
+ event.skip()
307
+ end
308
+
309
+ def on_item_expanded(event)
310
+ Wx::log_message("OnItemExpanded")
311
+ event.skip()
312
+ end
313
+
314
+ def on_item_expanding(event)
315
+ Wx::log_message("OnItemExpanding")
316
+ event.skip()
317
+ end
318
+
319
+ def on_item_collapsed(event)
320
+ Wx::log_message("OnItemCollapsed")
321
+ event.skip()
322
+ end
323
+
324
+ def on_sel_changed(event)
325
+ Wx::log_message("OnSelChanged")
326
+ event.skip()
327
+ end
328
+
329
+ def on_sel_changing(event)
330
+ Wx::log_message("OnSelChanging")
331
+ event.skip()
332
+ end
333
+
334
+ def log_key_event(name,event)
335
+ keycode = event.get_key_code()
336
+
337
+ case keycode
338
+ when Wx::K_BACK
339
+ key = "BACK"
340
+ when Wx::K_TAB
341
+ key = "TAB"
342
+ when Wx::K_RETURN
343
+ key = "RETURN"
344
+ when Wx::K_ESCAPE
345
+ key = "ESCAPE"
346
+ when Wx::K_SPACE
347
+ key = "SPACE"
348
+ when Wx::K_DELETE
349
+ key = "DELETE"
350
+ when Wx::K_START
351
+ key = "START"
352
+ when Wx::K_LBUTTON
353
+ key = "LBUTTON"
354
+ when Wx::K_RBUTTON
355
+ key = "RBUTTON"
356
+ when Wx::K_CANCEL
357
+ key = "CANCEL"
358
+ when Wx::K_MBUTTON
359
+ key = "MBUTTON"
360
+ when Wx::K_CLEAR
361
+ key = "CLEAR"
362
+ when Wx::K_SHIFT
363
+ key = "SHIFT"
364
+ when Wx::K_ALT
365
+ key = "ALT"
366
+ when Wx::K_CONTROL
367
+ key = "CONTROL"
368
+ when Wx::K_MENU
369
+ key = "MENU"
370
+ when Wx::K_PAUSE
371
+ key = "PAUSE"
372
+ when Wx::K_CAPITAL
373
+ key = "CAPITAL"
374
+ when Wx::K_PRIOR
375
+ key = "PRIOR"
376
+ when Wx::K_NEXT
377
+ key = "NEXT"
378
+ when Wx::K_END
379
+ key = "END"
380
+ when Wx::K_HOME
381
+ key = "HOME"
382
+ when Wx::K_LEFT
383
+ key = "LEFT"
384
+ when Wx::K_UP
385
+ key = "UP"
386
+ when Wx::K_RIGHT
387
+ key = "RIGHT"
388
+ when Wx::K_DOWN
389
+ key = "DOWN"
390
+ when Wx::K_SELECT
391
+ key = "SELECT"
392
+ when Wx::K_PRINT
393
+ key = "PRINT"
394
+ when Wx::K_EXECUTE
395
+ key = "EXECUTE"
396
+ when Wx::K_SNAPSHOT
397
+ key = "SNAPSHOT"
398
+ when Wx::K_INSERT
399
+ key = "INSERT"
400
+ when Wx::K_HELP
401
+ key = "HELP"
402
+ when Wx::K_NUMPAD0
403
+ key = "NUMPAD0"
404
+ when Wx::K_NUMPAD1
405
+ key = "NUMPAD1"
406
+ when Wx::K_NUMPAD2
407
+ key = "NUMPAD2"
408
+ when Wx::K_NUMPAD3
409
+ key = "NUMPAD3"
410
+ when Wx::K_NUMPAD4
411
+ key = "NUMPAD4"
412
+ when Wx::K_NUMPAD5
413
+ key = "NUMPAD5"
414
+ when Wx::K_NUMPAD6
415
+ key = "NUMPAD6"
416
+ when Wx::K_NUMPAD7
417
+ key = "NUMPAD7"
418
+ when Wx::K_NUMPAD8
419
+ key = "NUMPAD8"
420
+ when Wx::K_NUMPAD9
421
+ key = "NUMPAD9"
422
+ when Wx::K_MULTIPLY
423
+ key = "MULTIPLY"
424
+ when Wx::K_ADD
425
+ key = "ADD"
426
+ when Wx::K_SEPARATOR
427
+ key = "SEPARATOR"
428
+ when Wx::K_SUBTRACT
429
+ key = "SUBTRACT"
430
+ when Wx::K_DECIMAL
431
+ key = "DECIMAL"
432
+ when Wx::K_DIVIDE
433
+ key = "DIVIDE"
434
+ when Wx::K_F1
435
+ key = "F1"
436
+ when Wx::K_F2
437
+ key = "F2"
438
+ when Wx::K_F3
439
+ key = "F3"
440
+ when Wx::K_F4
441
+ key = "F4"
442
+ when Wx::K_F5
443
+ key = "F5"
444
+ when Wx::K_F6
445
+ key = "F6"
446
+ when Wx::K_F7
447
+ key = "F7"
448
+ when Wx::K_F8
449
+ key = "F8"
450
+ when Wx::K_F9
451
+ key = "F9"
452
+ when Wx::K_F10
453
+ key = "F10"
454
+ when Wx::K_F11
455
+ key = "F11"
456
+ when Wx::K_F12
457
+ key = "F12"
458
+ when Wx::K_F13
459
+ key = "F13"
460
+ when Wx::K_F14
461
+ key = "F14"
462
+ when Wx::K_F15
463
+ key = "F15"
464
+ when Wx::K_F16
465
+ key = "F16"
466
+ when Wx::K_F17
467
+ key = "F17"
468
+ when Wx::K_F18
469
+ key = "F18"
470
+ when Wx::K_F19
471
+ key = "F19"
472
+ when Wx::K_F20
473
+ key = "F20"
474
+ when Wx::K_F21
475
+ key = "F21"
476
+ when Wx::K_F22
477
+ key = "F22"
478
+ when Wx::K_F23
479
+ key = "F23"
480
+ when Wx::K_F24
481
+ key = "F24"
482
+ when Wx::K_NUMLOCK
483
+ key = "NUMLOCK"
484
+ when Wx::K_SCROLL
485
+ key = "SCROLL"
486
+ when Wx::K_PAGEUP
487
+ key = "PAGEUP"
488
+ when Wx::K_PAGEDOWN
489
+ key = "PAGEDOWN"
490
+ when Wx::K_NUMPAD_SPACE
491
+ key = "NUMPAD_SPACE"
492
+ when Wx::K_NUMPAD_TAB
493
+ key = "NUMPAD_TAB"
494
+ when Wx::K_NUMPAD_ENTER
495
+ key = "NUMPAD_ENTER"
496
+ when Wx::K_NUMPAD_F1
497
+ key = "NUMPAD_F1"
498
+ when Wx::K_NUMPAD_F2
499
+ key = "NUMPAD_F2"
500
+ when Wx::K_NUMPAD_F3
501
+ key = "NUMPAD_F3"
502
+ when Wx::K_NUMPAD_F4
503
+ key = "NUMPAD_F4"
504
+ when Wx::K_NUMPAD_HOME
505
+ key = "NUMPAD_HOME"
506
+ when Wx::K_NUMPAD_LEFT
507
+ key = "NUMPAD_LEFT"
508
+ when Wx::K_NUMPAD_UP
509
+ key = "NUMPAD_UP"
510
+ when Wx::K_NUMPAD_RIGHT
511
+ key = "NUMPAD_RIGHT"
512
+ when Wx::K_NUMPAD_DOWN
513
+ key = "NUMPAD_DOWN"
514
+ when Wx::K_NUMPAD_PRIOR
515
+ key = "NUMPAD_PRIOR"
516
+ when Wx::K_NUMPAD_PAGEUP
517
+ key = "NUMPAD_PAGEUP"
518
+ when Wx::K_NUMPAD_PAGEDOWN
519
+ key = "NUMPAD_PAGEDOWN"
520
+ when Wx::K_NUMPAD_END
521
+ key = "NUMPAD_END"
522
+ when Wx::K_NUMPAD_BEGIN
523
+ key = "NUMPAD_BEGIN"
524
+ when Wx::K_NUMPAD_INSERT
525
+ key = "NUMPAD_INSERT"
526
+ when Wx::K_NUMPAD_DELETE
527
+ key = "NUMPAD_DELETE"
528
+ when Wx::K_NUMPAD_EQUAL
529
+ key = "NUMPAD_EQUAL"
530
+ when Wx::K_NUMPAD_MULTIPLY
531
+ key = "NUMPAD_MULTIPLY"
532
+ when Wx::K_NUMPAD_ADD
533
+ key = "NUMPAD_ADD"
534
+ when Wx::K_NUMPAD_SEPARATOR
535
+ key = "NUMPAD_SEPARATOR"
536
+ when Wx::K_NUMPAD_SUBTRACT
537
+ key = "NUMPAD_SUBTRACT"
538
+ when Wx::K_NUMPAD_DECIMAL
539
+ key = "NUMPAD_DECIMAL"
540
+ else
541
+ if keycode >= 32 && keycode <127
542
+ key = sprintf("'%s'", keycode.chr)
543
+ elsif keycode > 0 && keycode < 27
544
+ key = sprintf("Ctrl-%c", ?A + keycode - 1)
545
+ else
546
+ key = sprintf("unknown (%d)", keycode)
547
+ end
548
+ end
549
+
550
+ Wx::log_message( "%s event: %s (flags = %s%s%s%s)",
551
+ name, key,
552
+ event.control_down() ? 'C' : '-',
553
+ event.alt_down() ? 'A' : '-',
554
+ event.shift_down() ? 'S' : '-',
555
+ event.meta_down() ? 'M' : '-')
556
+ end
557
+
558
+ def on_tree_key_down(event)
559
+ log_key_event("Tree key down ", event.get_key_event())
560
+
561
+ event.skip()
562
+ end
563
+
564
+ def on_begin_drag(event)
565
+ # need to explicitly allow drag
566
+ if event.get_item() != get_root_item()
567
+ @dragged_item = event.get_item()
568
+ Wx::log_message("OnBeginDrag: started dragging %s",
569
+ get_item_text(@dragged_item))
570
+ event.allow()
571
+ else
572
+ Wx::log_message("OnBeginDrag: selected item can't be dragged.")
573
+ end
574
+ end
575
+
576
+ def on_end_drag(event)
577
+ src_item = @dragged_item
578
+ dest_item = event.get_item()
579
+ @dragged_item = 0
580
+
581
+ if dest_item.nonzero? && ! item_has_children(dest_item)
582
+ # copy to the parent then
583
+ dest_item = get_item_parent(dest_item)
584
+ end
585
+
586
+ unless dest_item.nonzero?()
587
+ Wx::log_message("OnEndDrag: can't drop here.")
588
+ return nil
589
+ end
590
+
591
+ text = get_item_text(src_item)
592
+ Wx::log_message("OnEndDrag: '%s' copied to '%s'.",
593
+ text, get_item_text(dest_item))
594
+
595
+ # just do append here - we could also insert it just before/after the item
596
+ # on which it was dropped, but self requires slightly more work... we also
597
+ # completely ignore the client data and icon of the old item but could
598
+ # copy them as well.
599
+ #
600
+ # Finally, we only copy one item here but we might copy the entire tree if
601
+ # we were dragging a folder.
602
+ image = Wx::get_app().show_images() ? TreeCtrlIcon_File : -1
603
+ append_item(dest_item, text, image)
604
+ end
605
+
606
+ def on_begin_label_edit(event)
607
+ Wx::log_message("OnBeginLabelEdit")
608
+
609
+ # for testing, prevent self item's label editing
610
+ item_id = event.get_item()
611
+ if is_test_item(item_id)
612
+ message_box("The demo prevents you editing this item.")
613
+ event.veto()
614
+ end
615
+ end
616
+
617
+ def on_end_label_edit(event)
618
+ Wx::log_message("OnEndLabelEdit")
619
+ if event.is_edit_cancelled
620
+ Wx::log_message("Label edit was cancelled by user")
621
+ return
622
+ end
623
+
624
+ # For a demo, don't allow anything except letters in the labels
625
+ if event.get_label =~ /[^\w.]/
626
+ msg = "Only letters, numbers and full stops are allowed in the label."
627
+ message_box(msg)
628
+ Wx::log_message("Label edit was cancelled by demo")
629
+ event.veto()
630
+ end
631
+ end
632
+
633
+ def on_item_collapsing(event)
634
+ Wx::log_message("OnItemCollapsing")
635
+
636
+ # for testing, prevent the user from collapsing the first child folder
637
+ item_id = event.get_item()
638
+ if is_test_item(item_id)
639
+ message_box("You can't collapse self item.")
640
+
641
+ event.veto()
642
+ end
643
+ end
644
+
645
+ # show some info about activated item
646
+ def on_item_activated(event)
647
+ if item_id = event.get_item()
648
+ show_info(item_id)
649
+ end
650
+ Wx::log_message("OnItemActivated")
651
+ end
652
+
653
+ def on_item_right_click(event)
654
+ show_popup_menu(event.get_item(), event.get_point())
655
+ end
656
+
657
+ def on_rmouse_up(event)
658
+ pos = event.get_position()
659
+ item = hit_test(pos)
660
+ show_popup_menu(item, pos)
661
+ end
662
+
663
+ def show_popup_menu(id, pos)
664
+ title = ""
665
+ if id.nonzero?
666
+ title << "Menu for " << get_item_text(id)
667
+ else
668
+ title = "Menu for no particular item"
669
+ end
670
+
671
+ menu = Wx::Menu.new(title)
672
+ menu.append(Wx::ID_ABOUT, "&About...")
673
+ menu.append(TreeTest_Dump, "&Dump")
674
+ popup_menu(menu, pos)
675
+ end
676
+
677
+ def on_rmouse_dclick(event)
678
+ id = hit_test(event.get_position())
679
+ if not id
680
+ Wx::log_message("No item under mouse")
681
+ else
682
+ item = get_item_text(id)
683
+ if item
684
+ Wx::log_message("Item '%s' under mouse", item)
685
+ end
686
+ end
687
+ end
688
+ end
689
+
690
+
691
+ class MyFrame < Wx::Frame
692
+ def initialize(title, x, y, w, h)
693
+ super(nil, -1, title, Wx::Point.new(x, y), Wx::Size.new(w, h))
694
+ @treectrl = nil
695
+ @textctrl = nil
696
+ @s_num = 0
697
+
698
+ # This reduces flicker effects - even better would be to define
699
+ # OnEraseBackground to do nothing. When the tree control's scrollbars are
700
+ # show or hidden, the frame is sent a background erase event.
701
+ set_background_colour(Wx::Colour.new(255, 255, 255))
702
+
703
+ # Make a menubar
704
+ file_menu = Wx::Menu.new
705
+ style_menu = Wx::Menu.new
706
+ tree_menu = Wx::Menu.new
707
+ item_menu = Wx::Menu.new
708
+
709
+ file_menu.append(Wx::ID_ABOUT, "&About...")
710
+ file_menu.append_separator()
711
+ file_menu.append(Wx::ID_EXIT, "E&xit\tAlt-X")
712
+
713
+ style_menu.append(TreeTest_TogButtons,
714
+ "Toggle &normal buttons", "", Wx::ITEM_CHECK)
715
+ style_menu.append(TreeTest_TogTwist,
716
+ "Toggle &twister buttons", "", Wx::ITEM_CHECK)
717
+ style_menu.append(TreeTest_ToggleButtons,
718
+ "Toggle image &buttons", "", Wx::ITEM_CHECK)
719
+ style_menu.append_separator()
720
+ style_menu.append(TreeTest_TogLines,
721
+ "Toggle &connecting lines", "", Wx::ITEM_CHECK)
722
+ style_menu.append(TreeTest_TogRootLines,
723
+ "Toggle &lines at root", "", Wx::ITEM_CHECK)
724
+ style_menu.append(TreeTest_TogHideRoot,
725
+ "Toggle &hidden root", "", Wx::ITEM_CHECK)
726
+ style_menu.append(TreeTest_TogBorder,
727
+ "Toggle &item border", "", Wx::ITEM_CHECK)
728
+ style_menu.append(TreeTest_TogFullHighlight,
729
+ "Toggle &full row highlight", "", Wx::ITEM_CHECK)
730
+ style_menu.append(TreeTest_TogEdit,
731
+ "Toggle &editing allowed", "", Wx::ITEM_CHECK)
732
+ style_menu.append(TreeTest_ToggleSel,
733
+ "Toggle multiple &selection", "", Wx::ITEM_CHECK)
734
+ style_menu.append(TreeTest_ToggleImages,
735
+ "Toggle show ima&ges", "", Wx::ITEM_CHECK)
736
+ style_menu.append(TreeTest_SetImageSize, "Set image si&ze...")
737
+ style_menu.append_separator()
738
+ style_menu.append(TreeTest_SetFgColour, "Set &foreground colour...")
739
+ style_menu.append(TreeTest_SetBgColour, "Set &background colour...")
740
+ style_menu.append_separator()
741
+ style_menu.append(TreeTest_ResetStyle, "&Reset to default\tF10")
742
+
743
+ tree_menu.append(TreeTest_Recreate, "&Recreate the tree")
744
+ tree_menu.append(TreeTest_CollapseAndReset, "C&ollapse and reset")
745
+ tree_menu.append_separator()
746
+ tree_menu.append(TreeTest_AddItem, "Append a &new item")
747
+ tree_menu.append(TreeTest_InsertItem, "&Insert a new item")
748
+ tree_menu.append(TreeTest_Delete, "&Delete selected item")
749
+ tree_menu.append(TreeTest_DeleteChildren, "Delete &children")
750
+ tree_menu.append(TreeTest_DeleteAll, "Delete &all items")
751
+ tree_menu.append_separator()
752
+ tree_menu.append(TreeTest_Count, "Count children of current item")
753
+ tree_menu.append(TreeTest_CountRec, "Recursively count children of current item")
754
+ tree_menu.append_separator()
755
+ tree_menu.append(TreeTest_Sort, "Sort children")
756
+ tree_menu.append(TreeTest_SortRev, "Reverse sort children")
757
+ tree_menu.append_separator()
758
+ tree_menu.append(TreeTest_EnsureVisible, "Make the last item &visible")
759
+ tree_menu.append_separator()
760
+ tree_menu.append(TreeTest_IncIndent, "Increase indentation\tAlt-I")
761
+ tree_menu.append(TreeTest_DecIndent, "Reduce indentation\tAlt-R")
762
+ tree_menu.append_separator()
763
+ tree_menu.append(TreeTest_IncSpacing, "Increase spacing\tCtrl-I")
764
+ tree_menu.append(TreeTest_DecSpacing, "Reduce spacing\tCtrl-R")
765
+
766
+ item_menu.append(TreeTest_Dump, "&Dump item children")
767
+ item_menu.append(TreeTest_Rename, "&Rename item...")
768
+
769
+ item_menu.append_separator()
770
+ item_menu.append(TreeTest_SetBold, "Make item &bold")
771
+ item_menu.append(TreeTest_ClearBold, "Make item &not bold")
772
+ item_menu.append_separator()
773
+ item_menu.append(TreeTest_ToggleIcon, "Toggle the item's &icon")
774
+
775
+ item_menu.append_separator()
776
+ item_menu.append(TreeTest_DumpSelected, "Dump selected items\tAlt-D")
777
+ item_menu.append(TreeTest_Select, "Select current item\tAlt-S")
778
+ item_menu.append(TreeTest_Unselect, "Unselect everything\tAlt-U")
779
+
780
+ menu_bar = Wx::MenuBar.new
781
+ menu_bar.append(file_menu, "&File")
782
+ menu_bar.append(style_menu, "&Style")
783
+ menu_bar.append(tree_menu, "&Tree")
784
+ menu_bar.append(item_menu, "&Item")
785
+ set_menu_bar(menu_bar)
786
+
787
+
788
+ # create the controls
789
+ @textctrl = Wx::TextCtrl.new(self, -1, "",
790
+ Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE,
791
+ Wx::TE_MULTILINE|Wx::SUNKEN_BORDER)
792
+
793
+ create_tree_with_default_style()
794
+
795
+ menu_bar.check(TreeTest_ToggleImages, true)
796
+
797
+ # create a status bar with 3 panes
798
+ create_status_bar(3)
799
+ set_status_text("", 0)
800
+
801
+ # set our text control as the log target
802
+ logWindow = Wx::LogTextCtrl.new(@textctrl)
803
+ Wx::Log::set_active_target(logWindow)
804
+
805
+ evt_size {|event| on_size(event) }
806
+
807
+ evt_menu(Wx::ID_EXIT) {|event| on_quit(event) }
808
+ evt_menu(Wx::ID_ABOUT) {|event| on_about(event) }
809
+
810
+ evt_menu(TreeTest_TogButtons) {|event| on_tog_buttons(event) }
811
+ evt_menu(TreeTest_TogTwist) {|event| on_tog_twist(event) }
812
+ evt_menu(TreeTest_TogLines) {|event| on_tog_lines(event) }
813
+ evt_menu(TreeTest_TogEdit) {|event| on_tog_edit(event) }
814
+ evt_menu(TreeTest_TogHideRoot) {|event| on_tog_hide_root(event) }
815
+ evt_menu(TreeTest_TogRootLines) {|event| on_tog_root_lines(event) }
816
+ evt_menu(TreeTest_TogBorder) {|event| on_tog_border(event) }
817
+ evt_menu(TreeTest_TogFullHighlight) {|event| on_tog_full_highlight(event) }
818
+ evt_menu(TreeTest_SetFgColour) {|event| on_set_fg_colour(event) }
819
+ evt_menu(TreeTest_SetBgColour) {|event| on_set_bg_colour(event) }
820
+ evt_menu(TreeTest_ResetStyle) {|event| on_reset_style(event) }
821
+
822
+ evt_menu(TreeTest_Dump) {|event| on_dump(event) }
823
+ evt_menu(TreeTest_DumpSelected) {|event| on_dump_selected(event) }
824
+ evt_menu(TreeTest_Select) {|event| on_select(event) }
825
+ evt_menu(TreeTest_Unselect) {|event| on_unselect(event) }
826
+ evt_menu(TreeTest_ToggleSel) {|event| on_toggle_sel(event) }
827
+ evt_menu(TreeTest_Rename) {|event| on_rename(event) }
828
+ evt_menu(TreeTest_Count) {|event| on_count(event) }
829
+ evt_menu(TreeTest_CountRec) {|event| on_count_rec(event) }
830
+ evt_menu(TreeTest_Sort) {|event| on_sort(event) }
831
+ evt_menu(TreeTest_SortRev) {|event| on_sort_rev(event) }
832
+ evt_menu(TreeTest_SetBold) {|event| on_set_bold(event) }
833
+ evt_menu(TreeTest_ClearBold) {|event| on_clear_bold(event) }
834
+ evt_menu(TreeTest_Delete) {|event| on_delete(event) }
835
+ evt_menu(TreeTest_DeleteChildren) {|event| on_delete_children(event) }
836
+ evt_menu(TreeTest_DeleteAll) {|event| on_delete_all(event) }
837
+ evt_menu(TreeTest_Recreate) {|event| on_recreate(event) }
838
+ evt_menu(TreeTest_ToggleImages) {|event| on_toggle_images(event) }
839
+ evt_menu(TreeTest_ToggleButtons) {|event| on_toggle_buttons(event) }
840
+ evt_menu(TreeTest_SetImageSize) {|event| on_set_image_size(event) }
841
+ evt_menu(TreeTest_CollapseAndReset) {|event| on_collapse_and_reset(event) }
842
+ evt_menu(TreeTest_EnsureVisible) {|event| on_ensure_visible(event) }
843
+ evt_menu(TreeTest_AddItem) {|event| on_add_item(event) }
844
+ evt_menu(TreeTest_InsertItem) {|event| on_insert_item(event) }
845
+ evt_menu(TreeTest_IncIndent) {|event| on_inc_indent(event) }
846
+ evt_menu(TreeTest_DecIndent) {|event| on_dec_indent(event) }
847
+ evt_menu(TreeTest_IncSpacing) {|event| on_inc_spacing(event) }
848
+ evt_menu(TreeTest_DecSpacing) {|event| on_dec_spacing(event) }
849
+ evt_menu(TreeTest_ToggleIcon) {|event| on_toggle_icon(event) }
850
+
851
+ evt_close {|event| on_close(event) }
852
+ end
853
+
854
+ def create_tree_with_default_style()
855
+
856
+ style = Wx::TR_DEFAULT_STYLE|Wx::TR_EDIT_LABELS|
857
+ Wx::TR_TWIST_BUTTONS|Wx::TR_ROW_LINES|Wx::TR_FULL_ROW_HIGHLIGHT
858
+
859
+ create_tree(style|Wx::SUNKEN_BORDER)
860
+
861
+ # as we don't know what Wx::TR_DEFAULT_STYLE could contain, test for
862
+ # everything
863
+ mbar = get_menu_bar()
864
+ mbar.check(TreeTest_TogButtons, (style & Wx::TR_HAS_BUTTONS) != 0)
865
+ mbar.check(TreeTest_TogButtons, (style & Wx::TR_TWIST_BUTTONS) != 0)
866
+ mbar.check(TreeTest_TogLines, (style & Wx::TR_NO_LINES) == 0)
867
+ mbar.check(TreeTest_TogRootLines, (style & Wx::TR_LINES_AT_ROOT) != 0)
868
+ mbar.check(TreeTest_TogHideRoot, (style & Wx::TR_HIDE_ROOT) != 0)
869
+ mbar.check(TreeTest_TogEdit, (style & Wx::TR_EDIT_LABELS) != 0)
870
+ mbar.check(TreeTest_TogBorder, (style & Wx::TR_ROW_LINES) != 0)
871
+ mbar.check(TreeTest_TogFullHighlight, (style & Wx::TR_FULL_ROW_HIGHLIGHT) != 0)
872
+ end
873
+
874
+ def create_tree(style)
875
+ @treectrl = MyTreeCtrl.new(self, TreeTest_Ctrl,
876
+ Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE,
877
+ style)
878
+ resize()
879
+ end
880
+
881
+ def tog_style(id,flag)
882
+
883
+ style = @treectrl.get_window_style_flag() ^ flag
884
+
885
+ # most treectrl styles can't be changed on the fly using the native
886
+ # control and the tree must be recreated
887
+ @treectrl.destroy
888
+ create_tree(style)
889
+ get_menu_bar().check(id, (style & flag) != 0)
890
+ end
891
+
892
+ def on_tog_buttons(event)
893
+ tog_style(event.get_id(), Wx::TR_HAS_BUTTONS)
894
+ end
895
+
896
+ def on_tog_twist(event)
897
+ tog_style(event.get_id(), Wx::TR_TWIST_BUTTONS)
898
+ end
899
+
900
+ def on_tog_lines(event)
901
+ tog_style(event.get_id(), Wx::TR_NO_LINES)
902
+ end
903
+
904
+ def on_tog_edit(event)
905
+ tog_style(event.get_id(), Wx::TR_EDIT_LABELS)
906
+ end
907
+
908
+ def on_tog_hide_root(event)
909
+ tog_style(event.get_id(), Wx::TR_HIDE_ROOT)
910
+ end
911
+
912
+ def on_tog_root_lines(event)
913
+ tog_style(event.get_id(), Wx::TR_LINES_AT_ROOT)
914
+ end
915
+
916
+ def on_tog_border(event)
917
+ tog_style(event.get_id(), Wx::TR_ROW_LINES)
918
+ end
919
+
920
+ def on_tog_full_highlight(event)
921
+ tog_style(event.get_id(), Wx::TR_FULL_ROW_HIGHLIGHT)
922
+ end
923
+
924
+ def on_reset_style(event)
925
+ create_tree_with_default_style()
926
+ end
927
+
928
+ def on_set_bold(event)
929
+ do_set_bold(true)
930
+ end
931
+
932
+ def on_clear_bold(event)
933
+ do_set_bold(false)
934
+ end
935
+
936
+ def on_sort(event)
937
+ do_sort()
938
+ end
939
+
940
+ def on_sort_rev(event)
941
+ do_sort(true)
942
+ end
943
+
944
+ def on_size(event)
945
+ if @treectrl && @textctrl
946
+ resize()
947
+ end
948
+
949
+ event.skip()
950
+ end
951
+
952
+ def resize()
953
+ my_size = get_client_size()
954
+ tree_size = Wx::Size.new(my_size.x, 2*my_size.y/3)
955
+ @treectrl.set_size( tree_size )
956
+ @textctrl.set_dimensions(0, 2*my_size.y/3, my_size.x, my_size.y/3)
957
+ end
958
+
959
+ def on_close(event)
960
+ Wx::Log::set_active_target(nil)
961
+ destroy()
962
+ end
963
+
964
+ def on_quit(event)
965
+ close(true)
966
+ end
967
+
968
+ def on_about(event)
969
+ Wx::message_box("Tree test sample\n" +
970
+ "(c) Julian Smart 1997, Vadim Zeitlin 1998",
971
+ "About tree test",
972
+ Wx::OK|Wx::ICON_INFORMATION, self)
973
+ end
974
+
975
+ def check_item(item)
976
+ unless item.nonzero?
977
+ message_box("Please select some item first!",
978
+ "Tree sample error",
979
+ Wx::OK|Wx::ICON_EXCLAMATION, self)
980
+ return false
981
+ end
982
+ true
983
+ end
984
+
985
+ def on_rename(event)
986
+ item = @treectrl.get_selection()
987
+
988
+ return nil unless check_item( item )
989
+
990
+ # TODO demonstrate creating a custom edit control...
991
+ @treectrl.edit_label(item)
992
+ end
993
+
994
+ def on_count(event)
995
+ item = @treectrl.get_selection()
996
+
997
+ return nil unless check_item( item )
998
+
999
+ i = @treectrl.get_children_count( item, false )
1000
+
1001
+ Wx::log_message("%d children", i)
1002
+ end
1003
+
1004
+ def on_count_rec(event)
1005
+ item = @treectrl.get_selection()
1006
+ return nil unless check_item( item )
1007
+ Wx::log_message("%d children", @treectrl.get_children_count( item ))
1008
+ end
1009
+
1010
+ def do_sort(reverse = false)
1011
+ item = @treectrl.get_selection()
1012
+ return nil unless check_item( item )
1013
+ @treectrl.do_sort_children(item, reverse)
1014
+ end
1015
+
1016
+ def on_dump(event)
1017
+ root = @treectrl.get_selection()
1018
+
1019
+ return nil unless check_item( root )
1020
+
1021
+ @treectrl.get_items_recursively(root, -1)
1022
+ end
1023
+
1024
+ def on_toggle_sel(event)
1025
+ tog_style(event.get_id(), Wx::TR_MULTIPLE)
1026
+ end
1027
+
1028
+ def on_dump_selected(event)
1029
+ if ( @treectrl.get_window_style & Wx::TR_MULTIPLE ) == 0
1030
+ item_id = @treectrl.get_selection
1031
+ if item_id.nonzero?
1032
+ Wx::log_message("<TreeItem '%s'>",
1033
+ @treectrl.get_item_text(item_id))
1034
+ else
1035
+ Wx::log_message("No tree item selected")
1036
+ end
1037
+ else
1038
+ Wx::log_message("NOT IMPLEMENTED: Multiple selections not available")
1039
+ # Requires Wx::List - Ruby Array typemap, pointer handling, 29/08/2006
1040
+ # Currently raises incorrect number of args, 1 for 0
1041
+ # selected = @treectrl.get_selections()
1042
+ # selected_items.each do | item_id |
1043
+ # Wx::log_message("\t%s", @treectrl.get_item_text(item_id))
1044
+ # end
1045
+ end
1046
+ end
1047
+
1048
+ def on_select(event)
1049
+ @treectrl.select_item(@treectrl.get_selection())
1050
+ end
1051
+
1052
+ def on_unselect(event)
1053
+ @treectrl.unselect_all()
1054
+ end
1055
+
1056
+ def do_set_bold(bold = true)
1057
+ item = @treectrl.get_selection()
1058
+
1059
+ return nil unless check_item( item )
1060
+
1061
+ @treectrl.set_item_bold(item, bold)
1062
+ end
1063
+
1064
+ def on_delete(event)
1065
+ item = @treectrl.get_selection()
1066
+
1067
+ return nil unless check_item( item )
1068
+
1069
+ @treectrl.delete(item)
1070
+ end
1071
+
1072
+ def on_delete_children(event)
1073
+ item = @treectrl.get_selection()
1074
+
1075
+ return nil unless check_item( item )
1076
+
1077
+ @treectrl.delete_children(item)
1078
+ end
1079
+
1080
+ def on_delete_all(event)
1081
+ @treectrl.delete_all_items()
1082
+ end
1083
+
1084
+ def on_recreate(event)
1085
+ on_delete_all(event)
1086
+ @treectrl.add_test_items_to_tree(5, 2)
1087
+ end
1088
+
1089
+ def on_set_image_size(event)
1090
+ size = get_number_from_user("Enter the size for the images to use",
1091
+ "Size: ",
1092
+ "TreeCtrl sample",
1093
+ @treectrl.image_size())
1094
+ if size == -1
1095
+ return nil
1096
+ end
1097
+
1098
+ @treectrl.create_image_list(size)
1099
+ Wx::get_app.show_images = true
1100
+ end
1101
+
1102
+ def on_toggle_images(event)
1103
+ if Wx::get_app.show_images
1104
+ @treectrl.unset_image_list
1105
+ Wx::get_app.show_images = false
1106
+ else
1107
+ @treectrl.create_image_list
1108
+ Wx::get_app.show_images = true
1109
+ end
1110
+ end
1111
+
1112
+ def on_toggle_buttons(event)
1113
+ end
1114
+
1115
+ def on_collapse_and_reset(event)
1116
+ @treectrl.collapse_and_reset(@treectrl.get_root_item())
1117
+ end
1118
+
1119
+ def on_ensure_visible(event)
1120
+ @treectrl.do_ensure_visible()
1121
+ end
1122
+
1123
+ def on_insert_item(event)
1124
+ image = Wx::get_app.show_images() ? TreeCtrlIcon_File : -1
1125
+ @treectrl.insert_item(@treectrl.get_root_item(), -1, "2nd item", image)
1126
+ end
1127
+
1128
+ def on_add_item(event)
1129
+ @s_num += 1
1130
+ text = sprintf("Item #%d", @s_num)
1131
+ @treectrl.append_item(@treectrl.get_root_item(), text)
1132
+ end
1133
+
1134
+ def on_inc_indent(event)
1135
+ indent = @treectrl.get_indent()
1136
+ if indent < 100
1137
+ @treectrl.set_indent( indent+5 )
1138
+ end
1139
+ end
1140
+
1141
+ def on_dec_indent(event)
1142
+ indent = @treectrl.get_indent()
1143
+ if indent > 10
1144
+ @treectrl.set_indent( indent-5 )
1145
+ end
1146
+ end
1147
+
1148
+ def on_inc_spacing(event)
1149
+ indent = @treectrl.get_spacing()
1150
+ if indent < 100
1151
+ @treectrl.set_spacing( indent+5 )
1152
+ end
1153
+ end
1154
+
1155
+ def on_dec_spacing(event)
1156
+ indent = @treectrl.get_spacing()
1157
+ if indent > 10
1158
+ @treectrl.set_spacing( indent-5 )
1159
+ end
1160
+ end
1161
+
1162
+ def on_toggle_icon(event)
1163
+ item = @treectrl.get_selection()
1164
+ return nil unless check_item( item )
1165
+ @treectrl.do_toggle_icon(item)
1166
+ end
1167
+
1168
+ # TODO
1169
+ def on_set_fg_colour(event)
1170
+ Wx::log_message('NOT IMPLEMENTED')
1171
+ return
1172
+ col = Wx::get_colour_from_user(self, @treectrl.get_foreground_colour())
1173
+ if col.is_ok
1174
+ @treectrl.set_foreground_colour(col)
1175
+ end
1176
+ end
1177
+
1178
+ # TODO
1179
+ def on_set_bg_colour(event)
1180
+ Wx::log_message('NOT IMPLEMENTED')
1181
+ return
1182
+ col = Wx::get_colour_from_user(self, @treectrl.get_background_colour())
1183
+ if col.is_ok
1184
+ @treectrl.set_background_colour(col)
1185
+ end
1186
+ end
1187
+
1188
+ end
1189
+
1190
+ class MyApp < Wx::App
1191
+ attr_accessor :show_images, :show_buttons
1192
+ def initialize
1193
+ self.show_images = true
1194
+ self.show_buttons = false
1195
+ super
1196
+ end
1197
+
1198
+ def on_init
1199
+ # Create the main frame window
1200
+ frame = MyFrame.new("TreeCtrl Test", 50, 50, 450, 600)
1201
+
1202
+ # show the frame
1203
+ frame.show(true)
1204
+ # set_top_window(frame)
1205
+
1206
+ end
1207
+ end
1208
+
1209
+ a = MyApp.new
1210
+ a.main_loop()