wxruby-ruby19 1.9.8-x86-linux → 1.9.10-x86-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +234 -220
@@ -0,0 +1,131 @@
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
+
11
+
12
+ class TestToolBar < Wx::Frame
13
+ # returns a Bitmap icon object
14
+ def xpm_bitmap(base_name)
15
+
16
+ xpm_file = File.join( File.dirname(__FILE__), 'icons', base_name )
17
+ Wx::Bitmap.new(xpm_file, Wx::BITMAP_TYPE_XPM)
18
+ end
19
+
20
+ def initialize(parent, log)
21
+ super(parent, -1, "Test ToolBar", Wx::DEFAULT_POSITION, Wx::Size.new(500,300))
22
+ @log = log
23
+ @timer = nil
24
+ evt_close {|event| on_close_window(event)}
25
+
26
+ Wx::Window.new(self, -1).set_background_colour(Wx::WHITE)
27
+
28
+ tb = create_tool_bar(Wx::TB_HORIZONTAL | Wx::NO_BORDER | Wx::TB_FLAT | Wx::TB_TEXT)
29
+
30
+ create_status_bar()
31
+ tb.add_tool(10, "New", xpm_bitmap('new.xpm'), "Long help for New")
32
+ evt_tool(10) {|event| on_tool_click(event)}
33
+ evt_tool_rclicked(10) {|event| on_tool_rclick(event)}
34
+
35
+ tb.add_tool(20, "Open", xpm_bitmap('open.xpm'), "Long help for Open")
36
+ evt_tool(20) {|event| on_tool_click(event)}
37
+ evt_tool_rclicked(20) {|event| on_tool_rclick(event)}
38
+
39
+ tb.add_separator()
40
+
41
+ tb.add_tool(30, "Copy", xpm_bitmap('copy.xpm'), "Long help for Copy")
42
+ evt_tool(30) {|event| on_tool_click(event)}
43
+ evt_tool_rclicked(30) {|event| on_tool_rclick(event)}
44
+
45
+ tb.add_tool(40, "Paste", xpm_bitmap('paste.xpm'), "Long help for Paste")
46
+ evt_tool(40) {|event| on_tool_click(event)}
47
+ evt_tool_rclicked(40) {|event| on_tool_rclick(event)}
48
+
49
+ tb.add_separator()
50
+
51
+ tb.add_check_tool(50, "", xpm_bitmap('tog1.xpm'),
52
+ Wx::NULL_BITMAP, "Toggle this")
53
+ evt_tool(50) {|event| on_tool_click(event)}
54
+
55
+ evt_tool_enter(-1) {|event| on_tool_enter(event)}
56
+ evt_tool_rclicked(-1) {|event| on_tool_rclick(event)}
57
+ evt_timer(5000) {|event| on_clear_sb(event)}
58
+
59
+ tb.add_separator()
60
+ cbID = 5000
61
+ choices = ["", "This", "is a", "wxComboBox"]
62
+
63
+ tb.add_control(Wx::ComboBox.new(tb, cbID, "", Wx::DEFAULT_POSITION, Wx::Size.new(150,-1), choices,
64
+ Wx::CB_DROPDOWN))
65
+ evt_combobox(cbID) {|event| on_combo(event)}
66
+ tb.add_control(Wx::TextCtrl.new(tb, -1, "ToolBar controls!!", Wx::DEFAULT_POSITION, Wx::Size.new(150,-1)))
67
+
68
+ tb.realize()
69
+ end
70
+
71
+ def on_tool_click(event)
72
+ @log.write_text("tool " + event.get_id().to_s() + " clicked")
73
+ tb = get_tool_bar()
74
+ tb.enable_tool(10, tb.get_tool_enabled(10) ? false : true)
75
+ end
76
+
77
+ def on_tool_rclick(event)
78
+ @log.write_text("tool " + event.get_id().to_s() + " right-clicked")
79
+ end
80
+
81
+ def on_combo(event)
82
+ @log.write_text("combobox item selected " + event.get_string())
83
+ end
84
+
85
+ def on_tool_enter(event)
86
+ @log.write_text("on_tool_enter: " + event.get_id().to_s + ", " + event.get_int().to_s())
87
+ if @timer == nil
88
+ @timer = Wx::Timer.new(self, 5000)
89
+ end
90
+ if @timer != nil
91
+ @timer.stop()
92
+ end
93
+ @timer.start(2000)
94
+ @timer.stop()
95
+ @timer.start(2000)
96
+ event.skip()
97
+ end
98
+
99
+ def on_clear_sb(event) # called for the timer event handler
100
+ set_status_text("")
101
+ @timer.stop()
102
+ @timer = nil
103
+ end
104
+
105
+ def on_close_window(event)
106
+ if @timer != nil
107
+ @timer.stop()
108
+ @timer = nil
109
+ end
110
+ destroy()
111
+ end
112
+ end
113
+
114
+ module Demo
115
+ def Demo.run(frame,nb,log)
116
+ win = TestToolBar.new(frame, log)
117
+ frame.otherWin = win
118
+ win.show()
119
+ end
120
+
121
+ def Demo.overview
122
+ "A toolbar is that familiar little rectangular strip below the menubar that hosts various 'buttons', which are usually shortcuts to menu commands."
123
+ end
124
+ end
125
+
126
+
127
+ if __FILE__ == $0
128
+ run_solo_lib = File.join( File.dirname(__FILE__), 'run.rb')
129
+ load run_solo_lib
130
+ run File.basename($0)
131
+ end
@@ -0,0 +1,191 @@
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
+
11
+
12
+ class MyTreeCtrl < Wx::TreeCtrl
13
+ def initialize(parent, id, pos, size, style, log)
14
+ super(parent,id,pos,size,style)
15
+ @log = log
16
+
17
+ evt_left_dclick {|event| on_left_dclick(event)}
18
+ evt_right_down {|event| on_right_click(event)}
19
+ evt_right_up {|event| on_right_up(event)}
20
+ end
21
+
22
+ def on_left_dclick(event)
23
+ pt = Wx::Point.new(event.get_x(), event.get_y())
24
+
25
+ end
26
+
27
+ def on_right_click(event)
28
+ pt = Wx::Point.new(event.get_x(), event.get_y())
29
+ id = hit_test(pt)
30
+ if id
31
+ @log.write_text("on_right_click: ")# + @tree.get_item_text(id))
32
+ end
33
+ end
34
+
35
+ def on_right_up(event)
36
+ pt = Wx::Point.new(event.get_x(), event.get_y())
37
+ id = hit_test(pt)
38
+ if id
39
+ @log.write_text("on_right_up: ")#+ @tree.get_item_text(id) + " (manually starting label edit)")
40
+ end
41
+ end
42
+
43
+ def on_compare_items(item1, item2)
44
+ t1 = get_item_text(item1)
45
+ t2 = get_item_text(item2)
46
+ @log.write_text('compare: ' + t1 + ' <> ' + t2)
47
+ if t1 < t2 then return -1 end
48
+ if t1 == t2 then return 0 end
49
+ return 1
50
+ end
51
+ end
52
+
53
+ class TestTreeCtrlPanel < Wx::Panel
54
+ def initialize(parent, log)
55
+ # Use the WANTS_CHARS style so the panel doesn't eat the Return key
56
+ super(parent, -1, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::WANTS_CHARS)
57
+ evt_size {|event| on_size(event)}
58
+
59
+ @log = log
60
+ tID = 5000
61
+
62
+ @tree = MyTreeCtrl.new(self, tID, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::TR_HAS_BUTTONS | Wx::TR_EDIT_LABELS, @log)
63
+
64
+ isz = Wx::Size.new(16,16)
65
+ il = Wx::ImageList.new(16,16)
66
+ bm = Wx::Bitmap.new
67
+ bm.copy_from_icon(Wx::ArtProvider::get_icon(Wx::ART_FOLDER, Wx::ART_OTHER, isz))
68
+ fldridx = il.add(bm)
69
+ bm.copy_from_icon(Wx::ArtProvider::get_icon(Wx::ART_FILE_OPEN, Wx::ART_OTHER, isz))
70
+ fldropenidx = il.add(bm)
71
+ bm.copy_from_icon(Wx::ArtProvider::get_icon(Wx::ART_FILE_OPEN, Wx::ART_OTHER, isz))
72
+ fileidx = il.add(bm)
73
+ bmp_file = File.join(File.dirname(__FILE__), 'icons', 'wxwin16x16.xpm')
74
+ smileidx = il.add(Wx::Bitmap.new(bmp_file))
75
+
76
+ @tree.set_image_list(il)
77
+ @il = il
78
+
79
+ @root = @tree.add_root("The Root Item")
80
+ @tree.set_item_image(@root, fldridx, Wx::TREE_ITEM_ICON_NORMAL)
81
+ @tree.set_item_image(@root, fldropenidx, Wx::TREE_ITEM_ICON_EXPANDED)
82
+ 0.upto(15) do |x|
83
+ child = @tree.append_item(@root, "Item " + x.to_s())
84
+ @tree.set_item_image(child, fldridx, Wx::TREE_ITEM_ICON_NORMAL)
85
+ @tree.set_item_image(child, fldropenidx, Wx::TREE_ITEM_ICON_EXPANDED)
86
+ character = "a"
87
+ 0.upto(4) do |y|
88
+ last = @tree.append_item(child, "item " + x.to_s() + "-" + character)
89
+ @tree.set_item_image(last, fldridx, Wx::TREE_ITEM_ICON_NORMAL)
90
+ @tree.set_item_image(last, fldropenidx, Wx::TREE_ITEM_ICON_EXPANDED)
91
+ 0.upto(4) do |z|
92
+ item = @tree.append_item(last, "item " + x.to_s() + "-" + character + "-" + z.to_s())
93
+ @tree.set_item_image(item, fileidx, Wx::TREE_ITEM_ICON_NORMAL)
94
+ @tree.set_item_image(item, smileidx, Wx::TREE_ITEM_ICON_SELECTED)
95
+ end
96
+ character.succ!
97
+ end
98
+ end
99
+
100
+ @tree.expand(@root)
101
+ evt_tree_item_expanded(tID) {|event| on_item_expanded(event)}
102
+ evt_tree_item_collapsed(tID) {|event| on_item_collapsed(event)}
103
+ evt_tree_sel_changed(tID) {|event| on_sel_changed(event)}
104
+ evt_tree_begin_label_edit(tID) {|event| on_begin_edit(event)}
105
+ evt_tree_end_label_edit(tID) {|event| on_end_edit(event)}
106
+ evt_tree_item_activated(tID) {|event| on_activate(event)}
107
+
108
+
109
+ end
110
+
111
+
112
+ def on_begin_edit(event)
113
+ @log.write_text("on_begin_edit")
114
+ # show how to prevent edit
115
+ if @tree.get_item_text(event.get_item()) == "The Root Item"
116
+ @log.write_text("You can't edit this one...")
117
+
118
+ # Let's just see what's visible of its children
119
+ cookie = 0
120
+ root = event.get_item()
121
+ child, cookie = @tree.get_first_child(root)
122
+ while child != nil
123
+ @log.write_text("Child [" + @tree.get_item_text(child) + "] visible = " + @tree.is_visible(child).to_s())
124
+ child,cookie = @tree.get_next_child(root, cookie)
125
+ end
126
+ event.veto()
127
+ end
128
+ end
129
+
130
+ def on_end_edit(event)
131
+ @log.write_text("on_end_edit")
132
+ #show how to reject edit, we'll not allow any digits
133
+ nums = ("0".."9").to_a()
134
+ x = event.get_label()
135
+ x.each_byte do |byte|
136
+ if nums.include?(byte.chr())
137
+ @log.write_text("You can't enter digits...")
138
+ event.veto()
139
+ return
140
+ end
141
+ end
142
+ end
143
+
144
+ def on_size(event)
145
+ size = get_client_size()
146
+ @tree.set_dimensions(0,0,size.x, size.y)
147
+ end
148
+
149
+ def on_item_expanded(event)
150
+ item = event.get_item()
151
+ @log.write_text("on_item_expanded: " + @tree.get_item_text(item))
152
+ end
153
+
154
+ def on_item_collapsed(event)
155
+ item = event.get_item()
156
+ @log.write_text("on_item_collapsed: " + @tree.get_item_text(item))
157
+ end
158
+
159
+ def on_sel_changed(event)
160
+ @item = event.get_item()
161
+ if @item.nonzero?
162
+ @log.write_text("on_sel_changed: " + @tree.get_item_text(@item))
163
+ # if Wx::PLATFORM == "WXMSW"
164
+ #@log.write_text("BoundingRect: " + @tree.get_bounding_rect(@item))
165
+ #end
166
+ end
167
+ event.skip()
168
+ end
169
+
170
+ def on_activate(event)
171
+ @log.write_text("on_activate: " + @tree.get_item_text(@item))
172
+ end
173
+ end
174
+
175
+ module Demo
176
+ def Demo.run(frame, nb, log)
177
+ win = TestTreeCtrlPanel.new(nb, log)
178
+ return win
179
+ end
180
+
181
+ def Demo.overview
182
+ return ""
183
+ end
184
+ end
185
+
186
+
187
+ if __FILE__ == $0
188
+ run_solo_lib = File.join( File.dirname(__FILE__), 'run.rb')
189
+ load run_solo_lib
190
+ run File.basename($0)
191
+ end
@@ -0,0 +1,256 @@
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
+ include Wx
11
+
12
+ Calendar_Cal_Monday = 200
13
+ Calendar_Cal_Holidays = 201
14
+ Calendar_Cal_Special = 202
15
+ Calendar_Cal_Month = 203
16
+ Calendar_Cal_Year = 204
17
+ Calendar_Cal_SeqMonth = 205
18
+ Calendar_Cal_SurroundWeeks = 206
19
+
20
+
21
+ class MyCalendar < CalendarCtrl
22
+ def initialize(parent, display_frame, initial_date, calendar_flags)
23
+ super( parent,
24
+ :date => initial_date,
25
+ :style => calendar_flags | RAISED_BORDER)
26
+
27
+ @display = display_frame
28
+ @date = initial_date
29
+ @weekday_names = %w|Sun Mon Tue Wed Thu Fri Sat|
30
+
31
+ evt_calendar self, :on_calendar
32
+ evt_calendar_month self, :on_cal_month_change
33
+ evt_calendar_year self, :on_cal_year_change
34
+ evt_calendar_sel_changed self, :on_calendar_change
35
+ evt_calendar_weekday_clicked self, :on_calendar_weekday_click
36
+ end
37
+
38
+ def on_calendar(event)
39
+ @display.date = event.date
40
+ end
41
+
42
+ def on_calendar_change(event)
43
+ @date = event.date
44
+ log_status("Selected date: #{@date.strftime('%Y-%M-%D')}")
45
+ end
46
+
47
+ def on_cal_month_change
48
+ log_status("Calendar month changed")
49
+ end
50
+
51
+ def on_cal_year_change
52
+ log_status("Calendar year changed")
53
+ end
54
+
55
+ def on_calendar_weekday_click(event)
56
+ wday = event.week_day
57
+ log_status("Clicked on #{@weekday_names[wday]}")
58
+ end
59
+
60
+ attr_reader :date
61
+ end
62
+
63
+ class MyFrame < Frame
64
+ def initialize(title)
65
+ super(nil, -1, title)
66
+ @panel = Wx::Panel.new(self)
67
+ add_menu_bar
68
+ add_status_bar
69
+
70
+ @calendar_flags = CAL_MONDAY_FIRST | CAL_SHOW_HOLIDAYS
71
+
72
+ @calendar = MyCalendar.new(@panel, self, Time.now, @calendar_flags)
73
+
74
+ @sizer = BoxSizer.new(VERTICAL)
75
+ configure_window
76
+
77
+ evt_menu Wx::ID_EXIT, :on_quit
78
+ evt_menu Wx::ID_ABOUT, :on_about
79
+
80
+ evt_menu Calendar_Cal_Monday, :on_cal_monday
81
+ evt_menu Calendar_Cal_Holidays, :on_cal_holidays
82
+ evt_menu Calendar_Cal_Special, :on_cal_special
83
+
84
+ evt_menu Calendar_Cal_Month, :on_cal_allow_month
85
+ evt_menu Calendar_Cal_Year, :on_cal_allow_year
86
+
87
+ evt_menu Calendar_Cal_SeqMonth, :on_cal_seq_month
88
+ evt_menu Calendar_Cal_SurroundWeeks, :on_cal_show_surrounding_weeks
89
+
90
+ evt_update_ui Calendar_Cal_Year, :on_allow_year_update
91
+ end
92
+
93
+ def add_menu_bar
94
+ # create a menu bar
95
+ menu_file = Menu.new
96
+
97
+ menu_file.append(Wx::ID_ABOUT, "&About...\tCtrl-A", "Show about dialog")
98
+ menu_file.append_separator
99
+ menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit self program")
100
+
101
+ menu_cal = Menu.new
102
+ menu_cal.append(Calendar_Cal_Monday,
103
+ "Monday &first weekday\tCtrl-F",
104
+ "Toggle between Mon and Sun as the first week day",
105
+ ITEM_CHECK)
106
+ menu_cal.append(Calendar_Cal_Holidays, "Show &holidays\tCtrl-H",
107
+ "Toggle highlighting the holidays",
108
+ ITEM_CHECK)
109
+ menu_cal.append(Calendar_Cal_Special, "Highlight &special dates\tCtrl-S",
110
+ "Test custom highlighting",
111
+ ITEM_CHECK)
112
+ menu_cal.append(Calendar_Cal_SurroundWeeks,
113
+ "Show s&urrounding weeks\tCtrl-W",
114
+ "Show the neighbouring weeks in the prev/next month",
115
+ ITEM_CHECK)
116
+ menu_cal.append_separator
117
+ menu_cal.append(Calendar_Cal_SeqMonth,
118
+ "To&ggle month selector style\tCtrl-G",
119
+ "Use another style for the calendar controls",
120
+ ITEM_CHECK)
121
+ menu_cal.append(Calendar_Cal_Month, "&Month can be changed\tCtrl-M",
122
+ "Allow changing the month in the calendar",
123
+ ITEM_CHECK)
124
+ menu_cal.append(Calendar_Cal_Year, "&Year can be changed\tCtrl-Y",
125
+ "Allow changing the year in the calendar",
126
+ ITEM_CHECK)
127
+
128
+ # now append the freshly created menu to the menu bar...
129
+ menu_bar = MenuBar.new
130
+ menu_bar.append(menu_file, "&File")
131
+ menu_bar.append(menu_cal, "&Calendar")
132
+
133
+ menu_bar.check(Calendar_Cal_Monday, TRUE)
134
+ menu_bar.check(Calendar_Cal_Holidays, TRUE)
135
+ menu_bar.check(Calendar_Cal_Month, TRUE)
136
+ menu_bar.check(Calendar_Cal_Year, TRUE)
137
+
138
+ # ... and attach self menu bar to the frame
139
+ self.menu_bar = menu_bar
140
+ end
141
+
142
+ def add_status_bar
143
+ # create a status bar just for fun (by default with 1 pane only)
144
+ create_status_bar
145
+ set_status_text("Welcome to Windows!")
146
+ end
147
+
148
+ def configure_window
149
+ @sizer.add(@calendar, 0, Wx::ALIGN_CENTRE|Wx::ALL, 5)
150
+ @sizer.size_hints = @panel
151
+ layout
152
+ @panel.sizer = @sizer
153
+ end
154
+
155
+ def on_quit
156
+ # true is to force the frame to close
157
+ close(true)
158
+ end
159
+
160
+ def on_about
161
+ message_box("wxRuby CalendarCtrl sample\nby Kevin Smith\n" +
162
+ "based on the wxWidgets version by Vadim Zeitlin",
163
+ "About Calendar", OK | ICON_INFORMATION, self)
164
+ end
165
+
166
+ def on_cal_monday(event)
167
+ enable = get_menu_bar().is_checked(event.get_id())
168
+ toggle_cal_style(enable, CAL_MONDAY_FIRST)
169
+ end
170
+
171
+ def on_cal_holidays(event)
172
+ enable = get_menu_bar().is_checked(event.get_id())
173
+ @calendar.enable_holiday_display(enable)
174
+ end
175
+
176
+ def on_cal_special(event)
177
+ highlight_special(get_menu_bar().is_checked(event.get_id()))
178
+ end
179
+
180
+ def on_cal_allow_month(event)
181
+ allow = get_menu_bar().is_checked(event.get_id())
182
+ @calendar.enable_month_change(allow)
183
+ end
184
+
185
+ def on_cal_allow_year(event)
186
+ allow = get_menu_bar().is_checked(event.get_id())
187
+ @calendar.enable_year_change(allow)
188
+ end
189
+
190
+ def on_cal_seq_month(event)
191
+ allow = get_menu_bar().is_checked(event.get_id())
192
+ toggle_cal_style(allow, CAL_SEQUENTIAL_MONTH_SELECTION)
193
+ end
194
+
195
+ def on_cal_show_surrounding_weeks(event)
196
+ allow = get_menu_bar().is_checked(event.get_id())
197
+ toggle_cal_style(allow, CAL_SHOW_SURROUNDING_WEEKS)
198
+ end
199
+
200
+ def on_allow_year_update(event)
201
+ event.enable( get_menu_bar().is_checked(Calendar_Cal_Month))
202
+ end
203
+
204
+ def toggle_cal_style(on,flag)
205
+ style = @calendar.get_window_style_flag
206
+ date = @calendar.date
207
+ @sizer.detach(@calendar)
208
+ @calendar.destroy
209
+ if on
210
+ style |= flag
211
+ else
212
+ style &= ~flag
213
+ end
214
+ @calendar = MyCalendar.new(@panel, self, date, style)
215
+ @sizer.add(@calendar, 0, Wx::ALIGN_CENTRE|Wx::ALL, 5)
216
+ @panel.layout
217
+ end
218
+
219
+ def highlight_special(on)
220
+ if on
221
+ attr_red_circle = CalendarDateAttr.new(CAL_BORDER_ROUND, RED)
222
+ attr_green_square = CalendarDateAttr.new(CAL_BORDER_SQUARE, GREEN)
223
+ # This wraps correctly, but causes problems because the colour is freed
224
+ # when the attribute is reset.
225
+ #
226
+ # attr_header_like = CalendarDateAttr.new(BLUE, LIGHT_GREY)
227
+
228
+ @calendar.set_attr(17, attr_red_circle)
229
+ @calendar.set_attr(29, attr_green_square)
230
+ # @calendar.set_attr(13, attr_header_like)
231
+ else
232
+ @calendar.reset_attr(17)
233
+ @calendar.reset_attr(29)
234
+ # @calendar.reset_attr(13)
235
+ end
236
+ @calendar.refresh()
237
+ end
238
+
239
+ def set_date(d)
240
+ str = "%s-%s-%s" % [ d.year, d.mon, d.day ]
241
+ Wx::MessageDialog.new( self, "The selected date is #{str}",
242
+ "Date chosen" ).show_modal
243
+ end
244
+
245
+ end
246
+
247
+
248
+ class RbApp < App
249
+ def on_init()
250
+ frame = MyFrame.new("Calendar Windows sample")
251
+ frame.show(true)
252
+ end
253
+ end
254
+
255
+ a = RbApp.new
256
+ a.main_loop()