wxruby 1.9.6-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. data/LICENSE +53 -0
  2. data/README +297 -0
  3. data/lib/wx/accessors.rb +52 -0
  4. data/lib/wx/classes/acceleratortable.rb +28 -0
  5. data/lib/wx/classes/animation.rb +18 -0
  6. data/lib/wx/classes/app.rb +45 -0
  7. data/lib/wx/classes/artprovider.rb +31 -0
  8. data/lib/wx/classes/bitmap.rb +28 -0
  9. data/lib/wx/classes/busycursor.rb +12 -0
  10. data/lib/wx/classes/checklistbox.rb +45 -0
  11. data/lib/wx/classes/choice.rb +4 -0
  12. data/lib/wx/classes/clientdc.rb +13 -0
  13. data/lib/wx/classes/clipboard.rb +16 -0
  14. data/lib/wx/classes/colour.rb +47 -0
  15. data/lib/wx/classes/combobox.rb +4 -0
  16. data/lib/wx/classes/commandevent.rb +7 -0
  17. data/lib/wx/classes/controlwithitems.rb +10 -0
  18. data/lib/wx/classes/dc.rb +57 -0
  19. data/lib/wx/classes/event.rb +5 -0
  20. data/lib/wx/classes/evthandler.rb +921 -0
  21. data/lib/wx/classes/font.rb +118 -0
  22. data/lib/wx/classes/functions.rb +44 -0
  23. data/lib/wx/classes/gauge.rb +12 -0
  24. data/lib/wx/classes/grid.rb +138 -0
  25. data/lib/wx/classes/helpcontroller.rb +5 -0
  26. data/lib/wx/classes/htmlhelpcontroller.rb +5 -0
  27. data/lib/wx/classes/htmlwindow.rb +14 -0
  28. data/lib/wx/classes/icon.rb +21 -0
  29. data/lib/wx/classes/iconbundle.rb +3 -0
  30. data/lib/wx/classes/image.rb +31 -0
  31. data/lib/wx/classes/imagelist.rb +3 -0
  32. data/lib/wx/classes/listbox.rb +4 -0
  33. data/lib/wx/classes/listctrl.rb +21 -0
  34. data/lib/wx/classes/locale.rb +28 -0
  35. data/lib/wx/classes/mediactrl.rb +22 -0
  36. data/lib/wx/classes/menu.rb +62 -0
  37. data/lib/wx/classes/menuitem.rb +7 -0
  38. data/lib/wx/classes/object.rb +7 -0
  39. data/lib/wx/classes/paintdc.rb +12 -0
  40. data/lib/wx/classes/point.rb +48 -0
  41. data/lib/wx/classes/previewframe.rb +13 -0
  42. data/lib/wx/classes/rect.rb +10 -0
  43. data/lib/wx/classes/size.rb +49 -0
  44. data/lib/wx/classes/sound.rb +23 -0
  45. data/lib/wx/classes/styledtextctrl.rb +92 -0
  46. data/lib/wx/classes/textctrl.rb +14 -0
  47. data/lib/wx/classes/texturlevent.rb +6 -0
  48. data/lib/wx/classes/timer.rb +94 -0
  49. data/lib/wx/classes/toolbartool.rb +4 -0
  50. data/lib/wx/classes/treectrl.rb +44 -0
  51. data/lib/wx/classes/window.rb +82 -0
  52. data/lib/wx/classes/xmlresource.rb +37 -0
  53. data/lib/wx/keyword_ctors.rb +222 -0
  54. data/lib/wx/keyword_defs.rb +492 -0
  55. data/lib/wx/version.rb +3 -0
  56. data/lib/wx.rb +42 -0
  57. data/lib/wxruby2.exp +0 -0
  58. data/lib/wxruby2.lib +0 -0
  59. data/lib/wxruby2.so +0 -0
  60. data/lib/wxruby2.so.manifest +13 -0
  61. data/samples/SAMPLES-LICENSE.TXT +18 -0
  62. data/samples/aui/aui.rb +1356 -0
  63. data/samples/bigdemo/About.rbw +39 -0
  64. data/samples/bigdemo/ColorPanel.rbw +23 -0
  65. data/samples/bigdemo/GridSimple.rbw +78 -0
  66. data/samples/bigdemo/MDIDemo.rbw +57 -0
  67. data/samples/bigdemo/PopupMenu.rbw +149 -0
  68. data/samples/bigdemo/ShapedWindow.rbw +131 -0
  69. data/samples/bigdemo/Sizers.rbw +543 -0
  70. data/samples/bigdemo/bigdemo.rb +823 -0
  71. data/samples/bigdemo/demoTemplate.rbw +33 -0
  72. data/samples/bigdemo/helpfile.htb +0 -0
  73. data/samples/bigdemo/icons/Test 015.jpg +0 -0
  74. data/samples/bigdemo/icons/Test 015.png +0 -0
  75. data/samples/bigdemo/icons/choice.bmp +0 -0
  76. data/samples/bigdemo/icons/choice.xpm +27 -0
  77. data/samples/bigdemo/icons/combo.bmp +0 -0
  78. data/samples/bigdemo/icons/combo.xpm +27 -0
  79. data/samples/bigdemo/icons/copy.xpm +25 -0
  80. data/samples/bigdemo/icons/cut.xpm +24 -0
  81. data/samples/bigdemo/icons/gauge.bmp +0 -0
  82. data/samples/bigdemo/icons/gauge.xpm +27 -0
  83. data/samples/bigdemo/icons/help.xpm +25 -0
  84. data/samples/bigdemo/icons/list.bmp +0 -0
  85. data/samples/bigdemo/icons/list.xpm +27 -0
  86. data/samples/bigdemo/icons/mondrian.ico +0 -0
  87. data/samples/bigdemo/icons/mondrian.xpm +44 -0
  88. data/samples/bigdemo/icons/new.xpm +24 -0
  89. data/samples/bigdemo/icons/ogl.ico +0 -0
  90. data/samples/bigdemo/icons/ogl.xpm +45 -0
  91. data/samples/bigdemo/icons/open.xpm +26 -0
  92. data/samples/bigdemo/icons/paste.bmp +0 -0
  93. data/samples/bigdemo/icons/paste.xpm +38 -0
  94. data/samples/bigdemo/icons/pointy.png +0 -0
  95. data/samples/bigdemo/icons/preview.xpm +26 -0
  96. data/samples/bigdemo/icons/print.xpm +26 -0
  97. data/samples/bigdemo/icons/radio.bmp +0 -0
  98. data/samples/bigdemo/icons/radio.xpm +27 -0
  99. data/samples/bigdemo/icons/robert.xpm +415 -0
  100. data/samples/bigdemo/icons/ruby.png +0 -0
  101. data/samples/bigdemo/icons/sashtest.ico +0 -0
  102. data/samples/bigdemo/icons/save.xpm +25 -0
  103. data/samples/bigdemo/icons/smiles.bmp +0 -0
  104. data/samples/bigdemo/icons/smiles.xpm +39 -0
  105. data/samples/bigdemo/icons/smiley.ico +0 -0
  106. data/samples/bigdemo/icons/smiley.xpm +42 -0
  107. data/samples/bigdemo/icons/stattext.xpm +24 -0
  108. data/samples/bigdemo/icons/test2.bmp +0 -0
  109. data/samples/bigdemo/icons/test2.png +0 -0
  110. data/samples/bigdemo/icons/test2.xpm +79 -0
  111. data/samples/bigdemo/icons/text.bmp +0 -0
  112. data/samples/bigdemo/icons/text.xpm +27 -0
  113. data/samples/bigdemo/icons/tog1.bmp +0 -0
  114. data/samples/bigdemo/icons/tog1.xpm +38 -0
  115. data/samples/bigdemo/icons/tog2.bmp +0 -0
  116. data/samples/bigdemo/icons/tog2.xpm +38 -0
  117. data/samples/bigdemo/icons/wxwin.ico +0 -0
  118. data/samples/bigdemo/icons/wxwin16x16.png +0 -0
  119. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -0
  120. data/samples/bigdemo/icons/wxwin32x32.png +0 -0
  121. data/samples/bigdemo/icons/wxwin48x48.png +0 -0
  122. data/samples/bigdemo/run.rb +90 -0
  123. data/samples/bigdemo/tips.txt +7 -0
  124. data/samples/bigdemo/utils.rb +12 -0
  125. data/samples/bigdemo/wxArtProvider.rbw +281 -0
  126. data/samples/bigdemo/wxBitmapButton.rbw +65 -0
  127. data/samples/bigdemo/wxButton.rbw +64 -0
  128. data/samples/bigdemo/wxCalendarCtrl.rbw +60 -0
  129. data/samples/bigdemo/wxCheckBox.rbw +50 -0
  130. data/samples/bigdemo/wxCheckListBox.rbw +75 -0
  131. data/samples/bigdemo/wxChoice.rbw +47 -0
  132. data/samples/bigdemo/wxChoicebook.rbw +78 -0
  133. data/samples/bigdemo/wxColourDialog.rbw +31 -0
  134. data/samples/bigdemo/wxComboBox.rbw +77 -0
  135. data/samples/bigdemo/wxCursor.rbw +136 -0
  136. data/samples/bigdemo/wxDialog.rbw +74 -0
  137. data/samples/bigdemo/wxDirDialog.rbw +29 -0
  138. data/samples/bigdemo/wxDragImage.rbw +70 -0
  139. data/samples/bigdemo/wxFileDialog.rbw +37 -0
  140. data/samples/bigdemo/wxFileDialog_Save.rbw +35 -0
  141. data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -0
  142. data/samples/bigdemo/wxFontDialog.rbw +173 -0
  143. data/samples/bigdemo/wxFrame.rbw +53 -0
  144. data/samples/bigdemo/wxGauge.rbw +71 -0
  145. data/samples/bigdemo/wxGenericDirCtrl.rbw +74 -0
  146. data/samples/bigdemo/wxGrid.rbw +66 -0
  147. data/samples/bigdemo/wxHtmlHelpController.rbw +52 -0
  148. data/samples/bigdemo/wxListBox.rbw +140 -0
  149. data/samples/bigdemo/wxListCtrl_virtual.rbw +107 -0
  150. data/samples/bigdemo/wxMDIWindows.rbw +50 -0
  151. data/samples/bigdemo/wxMenu.rbw +236 -0
  152. data/samples/bigdemo/wxMessageDialog.rbw +27 -0
  153. data/samples/bigdemo/wxMiniFrame.rbw +70 -0
  154. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -0
  155. data/samples/bigdemo/wxNotebook.rbw +136 -0
  156. data/samples/bigdemo/wxProgressDialog.rbw +43 -0
  157. data/samples/bigdemo/wxRadioBox.rbw +72 -0
  158. data/samples/bigdemo/wxRadioButton.rbw +125 -0
  159. data/samples/bigdemo/wxSashWindow.rbw +141 -0
  160. data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -0
  161. data/samples/bigdemo/wxScrolledWindow.rbw +199 -0
  162. data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -0
  163. data/samples/bigdemo/wxSlider.rbw +42 -0
  164. data/samples/bigdemo/wxSpinButton.rbw +50 -0
  165. data/samples/bigdemo/wxSpinCtrl.rbw +51 -0
  166. data/samples/bigdemo/wxSplitterWindow.rbw +63 -0
  167. data/samples/bigdemo/wxStaticBitmap.rbw +51 -0
  168. data/samples/bigdemo/wxStaticText.rbw +55 -0
  169. data/samples/bigdemo/wxStatusBar.rbw +126 -0
  170. data/samples/bigdemo/wxTextCtrl.rbw +149 -0
  171. data/samples/bigdemo/wxTextEntryDialog.rbw +31 -0
  172. data/samples/bigdemo/wxToggleButton.rbw +49 -0
  173. data/samples/bigdemo/wxToolBar.rbw +131 -0
  174. data/samples/bigdemo/wxTreeCtrl.rbw +190 -0
  175. data/samples/calendar/calendar.rb +271 -0
  176. data/samples/caret/caret.rb +282 -0
  177. data/samples/caret/mondrian.xpm +44 -0
  178. data/samples/controls/controls.rb +1136 -0
  179. data/samples/controls/get_item_sample.rb +87 -0
  180. data/samples/controls/icons/choice.xpm +27 -0
  181. data/samples/controls/icons/combo.xpm +27 -0
  182. data/samples/controls/icons/gauge.xpm +27 -0
  183. data/samples/controls/icons/list.xpm +27 -0
  184. data/samples/controls/icons/radio.xpm +27 -0
  185. data/samples/controls/icons/stattext.xpm +24 -0
  186. data/samples/controls/icons/text.xpm +27 -0
  187. data/samples/controls/mondrian.ico +0 -0
  188. data/samples/controls/mondrian.xpm +44 -0
  189. data/samples/controls/test2.bmp +0 -0
  190. data/samples/dialogs/dialogs.rb +723 -0
  191. data/samples/dialogs/tips.txt +18 -0
  192. data/samples/drawing/graphics_drawing.rb +235 -0
  193. data/samples/drawing/images.rb +37 -0
  194. data/samples/drawing/paperclip.png +0 -0
  195. data/samples/etc/activation.rb +102 -0
  196. data/samples/etc/choice.rb +67 -0
  197. data/samples/etc/miniframe.rb +79 -0
  198. data/samples/etc/sash.rb +130 -0
  199. data/samples/etc/scrollwin.rb +110 -0
  200. data/samples/etc/system_settings.rb +252 -0
  201. data/samples/etc/threaded.rb +72 -0
  202. data/samples/etc/wizard.rb +74 -0
  203. data/samples/event/event.rb +182 -0
  204. data/samples/grid/grid.rb +198 -0
  205. data/samples/grid/gridtablebase.rb +134 -0
  206. data/samples/html/html.rb +262 -0
  207. data/samples/listbook/listbook.rb +174 -0
  208. data/samples/listbook/listbook.xrc +370 -0
  209. data/samples/mdi/mdi.rb +82 -0
  210. data/samples/media/mediactrl.rb +167 -0
  211. data/samples/minimal/minimal.rb +77 -0
  212. data/samples/minimal/mondrian.ico +0 -0
  213. data/samples/minimal/mondrian.png +0 -0
  214. data/samples/minimal/nothing.rb +16 -0
  215. data/samples/opengl/cube.rb +117 -0
  216. data/samples/printing/mondrian.ico +0 -0
  217. data/samples/printing/mondrian.xpm +44 -0
  218. data/samples/printing/printing.rb +310 -0
  219. data/samples/sockets/SocketPackets.rb +27 -0
  220. data/samples/sockets/res/message-new.png +0 -0
  221. data/samples/sockets/res/user.png +0 -0
  222. data/samples/sockets/wxClient.rb +395 -0
  223. data/samples/sockets/wxServer.rb +422 -0
  224. data/samples/sockets/wxSocketGUI.rb +97 -0
  225. data/samples/text/mondrian.ico +0 -0
  226. data/samples/text/mondrian.xpm +44 -0
  227. data/samples/text/scintilla.rb +169 -0
  228. data/samples/text/textctrl.rb +113 -0
  229. data/samples/text/unicode.rb +242 -0
  230. data/samples/text/utf8.txt +15 -0
  231. data/samples/treectrl/icon1.xpm +79 -0
  232. data/samples/treectrl/icon2.xpm +53 -0
  233. data/samples/treectrl/icon3.xpm +79 -0
  234. data/samples/treectrl/icon4.xpm +43 -0
  235. data/samples/treectrl/icon5.xpm +79 -0
  236. data/samples/treectrl/treectrl.rb +1174 -0
  237. data/samples/xrc/samples.xrc +46 -0
  238. data/samples/xrc/xrc_sample.rb +96 -0
  239. metadata +316 -0
@@ -0,0 +1,1174 @@
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