wxruby 1.9.6-x86-mingw32

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 (236) 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.so +0 -0
  58. data/samples/SAMPLES-LICENSE.TXT +18 -0
  59. data/samples/aui/aui.rb +1356 -0
  60. data/samples/bigdemo/About.rbw +39 -0
  61. data/samples/bigdemo/ColorPanel.rbw +23 -0
  62. data/samples/bigdemo/GridSimple.rbw +78 -0
  63. data/samples/bigdemo/MDIDemo.rbw +57 -0
  64. data/samples/bigdemo/PopupMenu.rbw +149 -0
  65. data/samples/bigdemo/ShapedWindow.rbw +131 -0
  66. data/samples/bigdemo/Sizers.rbw +543 -0
  67. data/samples/bigdemo/bigdemo.rb +823 -0
  68. data/samples/bigdemo/demoTemplate.rbw +33 -0
  69. data/samples/bigdemo/helpfile.htb +0 -0
  70. data/samples/bigdemo/icons/Test 015.jpg +0 -0
  71. data/samples/bigdemo/icons/Test 015.png +0 -0
  72. data/samples/bigdemo/icons/choice.bmp +0 -0
  73. data/samples/bigdemo/icons/choice.xpm +27 -0
  74. data/samples/bigdemo/icons/combo.bmp +0 -0
  75. data/samples/bigdemo/icons/combo.xpm +27 -0
  76. data/samples/bigdemo/icons/copy.xpm +25 -0
  77. data/samples/bigdemo/icons/cut.xpm +24 -0
  78. data/samples/bigdemo/icons/gauge.bmp +0 -0
  79. data/samples/bigdemo/icons/gauge.xpm +27 -0
  80. data/samples/bigdemo/icons/help.xpm +25 -0
  81. data/samples/bigdemo/icons/list.bmp +0 -0
  82. data/samples/bigdemo/icons/list.xpm +27 -0
  83. data/samples/bigdemo/icons/mondrian.ico +0 -0
  84. data/samples/bigdemo/icons/mondrian.xpm +44 -0
  85. data/samples/bigdemo/icons/new.xpm +24 -0
  86. data/samples/bigdemo/icons/ogl.ico +0 -0
  87. data/samples/bigdemo/icons/ogl.xpm +45 -0
  88. data/samples/bigdemo/icons/open.xpm +26 -0
  89. data/samples/bigdemo/icons/paste.bmp +0 -0
  90. data/samples/bigdemo/icons/paste.xpm +38 -0
  91. data/samples/bigdemo/icons/pointy.png +0 -0
  92. data/samples/bigdemo/icons/preview.xpm +26 -0
  93. data/samples/bigdemo/icons/print.xpm +26 -0
  94. data/samples/bigdemo/icons/radio.bmp +0 -0
  95. data/samples/bigdemo/icons/radio.xpm +27 -0
  96. data/samples/bigdemo/icons/robert.xpm +415 -0
  97. data/samples/bigdemo/icons/ruby.png +0 -0
  98. data/samples/bigdemo/icons/sashtest.ico +0 -0
  99. data/samples/bigdemo/icons/save.xpm +25 -0
  100. data/samples/bigdemo/icons/smiles.bmp +0 -0
  101. data/samples/bigdemo/icons/smiles.xpm +39 -0
  102. data/samples/bigdemo/icons/smiley.ico +0 -0
  103. data/samples/bigdemo/icons/smiley.xpm +42 -0
  104. data/samples/bigdemo/icons/stattext.xpm +24 -0
  105. data/samples/bigdemo/icons/test2.bmp +0 -0
  106. data/samples/bigdemo/icons/test2.png +0 -0
  107. data/samples/bigdemo/icons/test2.xpm +79 -0
  108. data/samples/bigdemo/icons/text.bmp +0 -0
  109. data/samples/bigdemo/icons/text.xpm +27 -0
  110. data/samples/bigdemo/icons/tog1.bmp +0 -0
  111. data/samples/bigdemo/icons/tog1.xpm +38 -0
  112. data/samples/bigdemo/icons/tog2.bmp +0 -0
  113. data/samples/bigdemo/icons/tog2.xpm +38 -0
  114. data/samples/bigdemo/icons/wxwin.ico +0 -0
  115. data/samples/bigdemo/icons/wxwin16x16.png +0 -0
  116. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -0
  117. data/samples/bigdemo/icons/wxwin32x32.png +0 -0
  118. data/samples/bigdemo/icons/wxwin48x48.png +0 -0
  119. data/samples/bigdemo/run.rb +90 -0
  120. data/samples/bigdemo/tips.txt +7 -0
  121. data/samples/bigdemo/utils.rb +12 -0
  122. data/samples/bigdemo/wxArtProvider.rbw +281 -0
  123. data/samples/bigdemo/wxBitmapButton.rbw +65 -0
  124. data/samples/bigdemo/wxButton.rbw +64 -0
  125. data/samples/bigdemo/wxCalendarCtrl.rbw +60 -0
  126. data/samples/bigdemo/wxCheckBox.rbw +50 -0
  127. data/samples/bigdemo/wxCheckListBox.rbw +75 -0
  128. data/samples/bigdemo/wxChoice.rbw +47 -0
  129. data/samples/bigdemo/wxChoicebook.rbw +78 -0
  130. data/samples/bigdemo/wxColourDialog.rbw +31 -0
  131. data/samples/bigdemo/wxComboBox.rbw +77 -0
  132. data/samples/bigdemo/wxCursor.rbw +136 -0
  133. data/samples/bigdemo/wxDialog.rbw +74 -0
  134. data/samples/bigdemo/wxDirDialog.rbw +29 -0
  135. data/samples/bigdemo/wxDragImage.rbw +70 -0
  136. data/samples/bigdemo/wxFileDialog.rbw +37 -0
  137. data/samples/bigdemo/wxFileDialog_Save.rbw +35 -0
  138. data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -0
  139. data/samples/bigdemo/wxFontDialog.rbw +173 -0
  140. data/samples/bigdemo/wxFrame.rbw +53 -0
  141. data/samples/bigdemo/wxGauge.rbw +71 -0
  142. data/samples/bigdemo/wxGenericDirCtrl.rbw +74 -0
  143. data/samples/bigdemo/wxGrid.rbw +66 -0
  144. data/samples/bigdemo/wxHtmlHelpController.rbw +52 -0
  145. data/samples/bigdemo/wxListBox.rbw +140 -0
  146. data/samples/bigdemo/wxListCtrl_virtual.rbw +107 -0
  147. data/samples/bigdemo/wxMDIWindows.rbw +50 -0
  148. data/samples/bigdemo/wxMenu.rbw +236 -0
  149. data/samples/bigdemo/wxMessageDialog.rbw +27 -0
  150. data/samples/bigdemo/wxMiniFrame.rbw +70 -0
  151. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -0
  152. data/samples/bigdemo/wxNotebook.rbw +136 -0
  153. data/samples/bigdemo/wxProgressDialog.rbw +43 -0
  154. data/samples/bigdemo/wxRadioBox.rbw +72 -0
  155. data/samples/bigdemo/wxRadioButton.rbw +125 -0
  156. data/samples/bigdemo/wxSashWindow.rbw +141 -0
  157. data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -0
  158. data/samples/bigdemo/wxScrolledWindow.rbw +199 -0
  159. data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -0
  160. data/samples/bigdemo/wxSlider.rbw +42 -0
  161. data/samples/bigdemo/wxSpinButton.rbw +50 -0
  162. data/samples/bigdemo/wxSpinCtrl.rbw +51 -0
  163. data/samples/bigdemo/wxSplitterWindow.rbw +63 -0
  164. data/samples/bigdemo/wxStaticBitmap.rbw +51 -0
  165. data/samples/bigdemo/wxStaticText.rbw +55 -0
  166. data/samples/bigdemo/wxStatusBar.rbw +126 -0
  167. data/samples/bigdemo/wxTextCtrl.rbw +149 -0
  168. data/samples/bigdemo/wxTextEntryDialog.rbw +31 -0
  169. data/samples/bigdemo/wxToggleButton.rbw +49 -0
  170. data/samples/bigdemo/wxToolBar.rbw +131 -0
  171. data/samples/bigdemo/wxTreeCtrl.rbw +190 -0
  172. data/samples/calendar/calendar.rb +271 -0
  173. data/samples/caret/caret.rb +282 -0
  174. data/samples/caret/mondrian.xpm +44 -0
  175. data/samples/controls/controls.rb +1136 -0
  176. data/samples/controls/get_item_sample.rb +87 -0
  177. data/samples/controls/icons/choice.xpm +27 -0
  178. data/samples/controls/icons/combo.xpm +27 -0
  179. data/samples/controls/icons/gauge.xpm +27 -0
  180. data/samples/controls/icons/list.xpm +27 -0
  181. data/samples/controls/icons/radio.xpm +27 -0
  182. data/samples/controls/icons/stattext.xpm +24 -0
  183. data/samples/controls/icons/text.xpm +27 -0
  184. data/samples/controls/mondrian.ico +0 -0
  185. data/samples/controls/mondrian.xpm +44 -0
  186. data/samples/controls/test2.bmp +0 -0
  187. data/samples/dialogs/dialogs.rb +723 -0
  188. data/samples/dialogs/tips.txt +18 -0
  189. data/samples/drawing/graphics_drawing.rb +235 -0
  190. data/samples/drawing/images.rb +37 -0
  191. data/samples/drawing/paperclip.png +0 -0
  192. data/samples/etc/activation.rb +102 -0
  193. data/samples/etc/choice.rb +67 -0
  194. data/samples/etc/miniframe.rb +79 -0
  195. data/samples/etc/sash.rb +130 -0
  196. data/samples/etc/scrollwin.rb +110 -0
  197. data/samples/etc/system_settings.rb +252 -0
  198. data/samples/etc/threaded.rb +72 -0
  199. data/samples/etc/wizard.rb +74 -0
  200. data/samples/event/event.rb +182 -0
  201. data/samples/grid/grid.rb +198 -0
  202. data/samples/grid/gridtablebase.rb +134 -0
  203. data/samples/html/html.rb +262 -0
  204. data/samples/listbook/listbook.rb +174 -0
  205. data/samples/listbook/listbook.xrc +370 -0
  206. data/samples/mdi/mdi.rb +82 -0
  207. data/samples/media/mediactrl.rb +167 -0
  208. data/samples/minimal/minimal.rb +77 -0
  209. data/samples/minimal/mondrian.ico +0 -0
  210. data/samples/minimal/mondrian.png +0 -0
  211. data/samples/minimal/nothing.rb +16 -0
  212. data/samples/opengl/cube.rb +117 -0
  213. data/samples/printing/mondrian.ico +0 -0
  214. data/samples/printing/mondrian.xpm +44 -0
  215. data/samples/printing/printing.rb +310 -0
  216. data/samples/sockets/SocketPackets.rb +27 -0
  217. data/samples/sockets/res/message-new.png +0 -0
  218. data/samples/sockets/res/user.png +0 -0
  219. data/samples/sockets/wxClient.rb +395 -0
  220. data/samples/sockets/wxServer.rb +422 -0
  221. data/samples/sockets/wxSocketGUI.rb +97 -0
  222. data/samples/text/mondrian.ico +0 -0
  223. data/samples/text/mondrian.xpm +44 -0
  224. data/samples/text/scintilla.rb +169 -0
  225. data/samples/text/textctrl.rb +113 -0
  226. data/samples/text/unicode.rb +242 -0
  227. data/samples/text/utf8.txt +15 -0
  228. data/samples/treectrl/icon1.xpm +79 -0
  229. data/samples/treectrl/icon2.xpm +53 -0
  230. data/samples/treectrl/icon3.xpm +79 -0
  231. data/samples/treectrl/icon4.xpm +43 -0
  232. data/samples/treectrl/icon5.xpm +79 -0
  233. data/samples/treectrl/treectrl.rb +1174 -0
  234. data/samples/xrc/samples.xrc +46 -0
  235. data/samples/xrc/xrc_sample.rb +96 -0
  236. metadata +313 -0
@@ -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,190 @@
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
+
83
+ 0.upto(15) do |x|
84
+ child = @tree.append_item(@root, "Item " + x.to_s())
85
+ @tree.set_item_image(child, fldridx, Wx::TREE_ITEM_ICON_NORMAL)
86
+ @tree.set_item_image(child, fldropenidx, Wx::TREE_ITEM_ICON_EXPANDED)
87
+ 0.upto(4) do |y|
88
+ last = @tree.append_item(child, "item " + x.to_s() + "-" + (?a + y).chr)
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() + "-" + (?a + y).chr + "-" + 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
+ end
97
+ end
98
+
99
+ @tree.expand(@root)
100
+ evt_tree_item_expanded(tID) {|event| on_item_expanded(event)}
101
+ evt_tree_item_collapsed(tID) {|event| on_item_collapsed(event)}
102
+ evt_tree_sel_changed(tID) {|event| on_sel_changed(event)}
103
+ evt_tree_begin_label_edit(tID) {|event| on_begin_edit(event)}
104
+ evt_tree_end_label_edit(tID) {|event| on_end_edit(event)}
105
+ evt_tree_item_activated(tID) {|event| on_activate(event)}
106
+
107
+
108
+ end
109
+
110
+
111
+ def on_begin_edit(event)
112
+ @log.write_text("on_begin_edit")
113
+ # show how to prevent edit
114
+ if @tree.get_item_text(event.get_item()) == "The Root Item"
115
+ @log.write_text("You can't edit this one...")
116
+
117
+ # Let's just see what's visible of its children
118
+ cookie = 0
119
+ root = event.get_item()
120
+ child, cookie = @tree.get_first_child(root)
121
+ while child != nil
122
+ @log.write_text("Child [" + @tree.get_item_text(child) + "] visible = " + @tree.is_visible(child).to_s())
123
+ child,cookie = @tree.get_next_child(root, cookie)
124
+ end
125
+ event.veto()
126
+ end
127
+ end
128
+
129
+ def on_end_edit(event)
130
+ @log.write_text("on_end_edit")
131
+ #show how to reject edit, we'll not allow any digits
132
+ nums = ("0".."9").to_a()
133
+ x = event.get_label()
134
+ x.each_byte do |byte|
135
+ if nums.include?(byte.chr())
136
+ @log.write_text("You can't enter digits...")
137
+ event.veto()
138
+ return
139
+ end
140
+ end
141
+ end
142
+
143
+ def on_size(event)
144
+ size = get_client_size()
145
+ @tree.set_dimensions(0,0,size.x, size.y)
146
+ end
147
+
148
+ def on_item_expanded(event)
149
+ item = event.get_item()
150
+ @log.write_text("on_item_expanded: " + @tree.get_item_text(item))
151
+ end
152
+
153
+ def on_item_collapsed(event)
154
+ item = event.get_item()
155
+ @log.write_text("on_item_collapsed: " + @tree.get_item_text(item))
156
+ end
157
+
158
+ def on_sel_changed(event)
159
+ @item = event.get_item()
160
+ if @item.nonzero?
161
+ @log.write_text("on_sel_changed: " + @tree.get_item_text(@item))
162
+ # if Wx::PLATFORM == "WXMSW"
163
+ #@log.write_text("BoundingRect: " + @tree.get_bounding_rect(@item))
164
+ #end
165
+ end
166
+ event.skip()
167
+ end
168
+
169
+ def on_activate(event)
170
+ @log.write_text("on_activate: " + @tree.get_item_text(@item))
171
+ end
172
+ end
173
+
174
+ module Demo
175
+ def Demo.run(frame, nb, log)
176
+ win = TestTreeCtrlPanel.new(nb, log)
177
+ return win
178
+ end
179
+
180
+ def Demo.overview
181
+ return ""
182
+ end
183
+ end
184
+
185
+
186
+ if __FILE__ == $0
187
+ run_solo_lib = File.join( File.dirname(__FILE__), 'run.rb')
188
+ load run_solo_lib
189
+ run File.basename($0)
190
+ end
@@ -0,0 +1,271 @@
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
+ include Wx
12
+
13
+ require 'date'
14
+
15
+
16
+ Calendar_File_About = ID_ABOUT
17
+ Calendar_File_Quit = ID_EXIT
18
+ Calendar_Cal_Monday = 200
19
+ Calendar_Cal_Holidays = 201
20
+ Calendar_Cal_Special = 202
21
+ Calendar_Cal_Month = 203
22
+ Calendar_Cal_Year = 204
23
+ Calendar_Cal_SeqMonth = 205
24
+ Calendar_Cal_SurroundWeeks = 206
25
+
26
+
27
+ def format_date(d)
28
+ return "#{d.year}-#{d.mon}-#{d.day}"
29
+ end
30
+
31
+ class MyCalendar < CalendarCtrl
32
+ def initialize(parent, display_frame, initial_date, calendar_flags)
33
+ super(parent, -1,
34
+ initial_date,
35
+ DEFAULT_POSITION,
36
+ DEFAULT_SIZE,
37
+ calendar_flags | RAISED_BORDER)
38
+
39
+ @display = display_frame
40
+ @date = initial_date
41
+ @weekday_names = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
42
+
43
+ id = get_id
44
+ evt_calendar(id) {|event| on_calendar(event)}
45
+ evt_calendar_month(id) {on_cal_month_change}
46
+ evt_calendar_year(id) {on_cal_year_change}
47
+ evt_calendar_sel_changed(id) {|event| on_calendar_change(event)}
48
+ evt_calendar_weekday_clicked(id) {|event| on_calendar_weekday_click(event)}
49
+ end
50
+
51
+ def on_calendar(event)
52
+ @date = event.get_date
53
+ @display.set_date(@date)
54
+ end
55
+
56
+ def on_calendar_change(event)
57
+ @date = event.get_date
58
+ log_status("Selected date: #{format_date(@date)}")
59
+ end
60
+
61
+ def on_cal_month_change
62
+ log_status("Calendar month changed")
63
+ end
64
+
65
+ def on_cal_year_change
66
+ log_status("Calendar year changed")
67
+ end
68
+
69
+ def on_calendar_weekday_click(event)
70
+ wday = event.get_week_day
71
+ log_status("Clicked on #{@weekday_names[wday]}")
72
+ end
73
+
74
+ attr_reader :date
75
+ end
76
+
77
+ class MyFrame < Frame
78
+ def initialize(title)
79
+ super(nil, -1, title)
80
+ @panel = Wx::Panel.new(self)
81
+ add_menu_bar
82
+ add_status_bar
83
+
84
+ @calendar_flags = CAL_MONDAY_FIRST | CAL_SHOW_HOLIDAYS
85
+
86
+ now = DateTime.now
87
+ @calendar = MyCalendar.new(@panel, self, now, @calendar_flags)
88
+
89
+ @sizer = BoxSizer.new(VERTICAL)
90
+ configure_window
91
+
92
+ evt_menu(Calendar_File_Quit) {on_quit}
93
+ evt_menu(Calendar_File_About) {on_about}
94
+
95
+ evt_menu(Calendar_Cal_Monday) {|event| on_cal_monday(event)}
96
+ evt_menu(Calendar_Cal_Holidays) {|event| on_cal_holidays(event)}
97
+ evt_menu(Calendar_Cal_Special) {|event| on_cal_special(event)}
98
+
99
+ evt_menu(Calendar_Cal_Month) {|event| on_cal_allow_month(event)}
100
+ evt_menu(Calendar_Cal_Year) {|event| on_cal_allow_year(event)}
101
+
102
+ evt_menu(Calendar_Cal_SeqMonth) {|event| on_cal_seq_month(event)}
103
+ evt_menu(Calendar_Cal_SurroundWeeks) {|event| on_cal_show_surrounding_weeks(event)}
104
+
105
+ evt_update_ui(Calendar_Cal_Year) {|event| on_allow_year_update(event)}
106
+ end
107
+
108
+ def add_menu_bar
109
+ # create a menu bar
110
+ menu_file = Menu.new
111
+
112
+ menu_file.append(Calendar_File_About, "&About...\tCtrl-A", "Show about dialog")
113
+ menu_file.append_separator()
114
+ menu_file.append(Calendar_File_Quit, "E&xit\tAlt-X", "Quit self program")
115
+
116
+ menu_cal = Menu.new
117
+ menu_cal.append(Calendar_Cal_Monday,
118
+ "Monday &first weekday\tCtrl-F",
119
+ "Toggle between Mon and Sun as the first week day",
120
+ ITEM_CHECK)
121
+ menu_cal.append(Calendar_Cal_Holidays, "Show &holidays\tCtrl-H",
122
+ "Toggle highlighting the holidays",
123
+ ITEM_CHECK)
124
+ menu_cal.append(Calendar_Cal_Special, "Highlight &special dates\tCtrl-S",
125
+ "Test custom highlighting",
126
+ ITEM_CHECK)
127
+ menu_cal.append(Calendar_Cal_SurroundWeeks,
128
+ "Show s&urrounding weeks\tCtrl-W",
129
+ "Show the neighbouring weeks in the prev/next month",
130
+ ITEM_CHECK)
131
+ menu_cal.append_separator()
132
+ menu_cal.append(Calendar_Cal_SeqMonth,
133
+ "To&ggle month selector style\tCtrl-G",
134
+ "Use another style for the calendar controls",
135
+ ITEM_CHECK)
136
+ menu_cal.append(Calendar_Cal_Month, "&Month can be changed\tCtrl-M",
137
+ "Allow changing the month in the calendar",
138
+ ITEM_CHECK)
139
+ menu_cal.append(Calendar_Cal_Year, "&Year can be changed\tCtrl-Y",
140
+ "Allow changing the year in the calendar",
141
+ ITEM_CHECK)
142
+
143
+ # now append the freshly created menu to the menu bar...
144
+ menu_bar = MenuBar.new
145
+ menu_bar.append(menu_file, "&File")
146
+ menu_bar.append(menu_cal, "&Calendar")
147
+
148
+ menu_bar.check(Calendar_Cal_Monday, TRUE)
149
+ menu_bar.check(Calendar_Cal_Holidays, TRUE)
150
+ menu_bar.check(Calendar_Cal_Month, TRUE)
151
+ menu_bar.check(Calendar_Cal_Year, TRUE)
152
+
153
+ # ... and attach self menu bar to the frame
154
+ set_menu_bar(menu_bar)
155
+ end
156
+
157
+ def add_status_bar
158
+ # create a status bar just for fun (by default with 1 pane only)
159
+ create_status_bar
160
+ set_status_text("Welcome to Windows!")
161
+ end
162
+
163
+ def configure_window
164
+ @sizer.add(@calendar, 0, Wx::ALIGN_CENTRE|Wx::ALL, 5)
165
+ @sizer.set_size_hints(@panel)
166
+ layout
167
+ @panel.set_sizer(@sizer)
168
+ end
169
+
170
+ def on_quit
171
+ # true is to force the frame to close
172
+ close(true)
173
+ end
174
+
175
+ def on_about
176
+ message_box("wxRuby CalendarCtrl sample\nby Kevin Smith\n" +
177
+ "based on the wxWidgets version by Vadim Zeitlin",
178
+ "About Calendar", OK | ICON_INFORMATION, self)
179
+ end
180
+
181
+ def on_cal_monday(event)
182
+ enable = get_menu_bar().is_checked(event.get_id())
183
+ toggle_cal_style(enable, CAL_MONDAY_FIRST)
184
+ end
185
+
186
+ def on_cal_holidays(event)
187
+ enable = get_menu_bar().is_checked(event.get_id())
188
+ @calendar.enable_holiday_display(enable)
189
+ end
190
+
191
+ def on_cal_special(event)
192
+ highlight_special(get_menu_bar().is_checked(event.get_id()))
193
+ end
194
+
195
+ def on_cal_allow_month(event)
196
+ allow = get_menu_bar().is_checked(event.get_id())
197
+ @calendar.enable_month_change(allow)
198
+ end
199
+
200
+ def on_cal_allow_year(event)
201
+ allow = get_menu_bar().is_checked(event.get_id())
202
+ @calendar.enable_year_change(allow)
203
+ end
204
+
205
+ def on_cal_seq_month(event)
206
+ allow = get_menu_bar().is_checked(event.get_id())
207
+ toggle_cal_style(allow, CAL_SEQUENTIAL_MONTH_SELECTION)
208
+ end
209
+
210
+ def on_cal_show_surrounding_weeks(event)
211
+ allow = get_menu_bar().is_checked(event.get_id())
212
+ toggle_cal_style(allow, CAL_SHOW_SURROUNDING_WEEKS)
213
+ end
214
+
215
+ def on_allow_year_update(event)
216
+ event.enable( get_menu_bar().is_checked(Calendar_Cal_Month))
217
+ end
218
+
219
+ def toggle_cal_style(on,flag)
220
+ style = @calendar.get_window_style_flag
221
+ date = @calendar.date
222
+ @sizer.detach(@calendar)
223
+ @calendar.destroy
224
+ if on
225
+ style |= flag
226
+ else
227
+ style &= ~flag
228
+ end
229
+ @calendar = MyCalendar.new(@panel, self, date, style)
230
+ @sizer.add(@calendar, 0, Wx::ALIGN_CENTRE|Wx::ALL, 5)
231
+ @panel.layout
232
+ end
233
+
234
+ def highlight_special(on)
235
+ if on
236
+ attr_red_circle = CalendarDateAttr.new(CAL_BORDER_ROUND, RED)
237
+ attr_green_square = CalendarDateAttr.new(CAL_BORDER_SQUARE, GREEN)
238
+ # This wraps correctly, but causes problems because the colour is freed
239
+ # when the attribute is reset.
240
+ #
241
+ # attr_header_like = CalendarDateAttr.new(BLUE, LIGHT_GREY)
242
+
243
+ @calendar.set_attr(17, attr_red_circle)
244
+ @calendar.set_attr(29, attr_green_square)
245
+ # @calendar.set_attr(13, attr_header_like)
246
+ else
247
+ @calendar.reset_attr(17)
248
+ @calendar.reset_attr(29)
249
+ # @calendar.reset_attr(13)
250
+ end
251
+ @calendar.refresh()
252
+ end
253
+
254
+ def set_date(d)
255
+ str = "%s-%s-%s" % [ d.year, d.mon, d.day ]
256
+ Wx::MessageDialog.new( self, "The selected date is #{str}",
257
+ "Date chosen" ).show_modal
258
+ end
259
+
260
+ end
261
+
262
+
263
+ class RbApp < App
264
+ def on_init()
265
+ frame = MyFrame.new("Calendar Windows sample")
266
+ frame.show(true)
267
+ end
268
+ end
269
+
270
+ a = RbApp.new
271
+ a.main_loop()