wxruby 1.9.9-x86-mingw32 → 1.9.10-x86-mingw32

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