wxruby-ruby19 1.9.10-x86-mingw32

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