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,27 @@
1
+ # A set of buttons and controls attached to one edge of a Wx::Frame
2
+ class Wx::ToolBar
3
+ # Generic method to add items, supporting positional and named
4
+ # arguments
5
+ ADD_ITEM_PARAMS = [ Wx::Parameter[ :position, -1 ],
6
+ Wx::Parameter[ :id, -1 ],
7
+ Wx::Parameter[ :label, "" ],
8
+ Wx::Parameter[ :bitmap2, Wx::NULL_BITMAP ],
9
+ Wx::Parameter[ :kind, Wx::ITEM_NORMAL ],
10
+ Wx::Parameter[ :short_help, "" ],
11
+ Wx::Parameter[ :long_help, "" ],
12
+ Wx::Parameter[ :client_data, nil ] ]
13
+
14
+ def add_item(bitmap, *mixed_args)
15
+ args = Wx::args_as_list(ADD_ITEM_PARAMS, *mixed_args)
16
+
17
+ pos = args.shift
18
+ args.insert(2, bitmap)
19
+
20
+ # Call add_tool to append if default position
21
+ if pos == -1
22
+ add_tool(*args)
23
+ else
24
+ insert_tool(pos, *args)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ class Wx::ToolBarTool
2
+ alias :id :get_id
3
+ alias :wx_id :get_id
4
+ end
@@ -0,0 +1,44 @@
1
+ # Hierarchical control with items
2
+ class Wx::TreeCtrl
3
+ # Make these ruby enumerables so find, find_all, map etc are available
4
+ include Enumerable
5
+ # Iterate over all items
6
+ alias :each :traverse
7
+
8
+ # Return the children of +parent+ as an array of TreeItemIDs.
9
+ def get_children(parent)
10
+ kids = [ get_first_child(parent) ]
11
+ return [] if kids[0].zero?
12
+
13
+ while kid = get_next_sibling(kids.last) and not kid.zero?
14
+ kids << kid
15
+ end
16
+ kids
17
+ end
18
+
19
+ # Returns a Wx::Rect corresponding to the edges of an individual tree
20
+ # item, including the button, identified by id. The standard wxWidgets
21
+ # API for getting the pixel location of an item is unrubyish, using an
22
+ # input/output parameter. But since the underlying get_bounding_rect
23
+ # method works, it's easier to fix the API in Ruby than adding more to
24
+ # the already-toxic swig interface TreeCtrl.i file.
25
+ def get_item_rect(tree_item_id)
26
+ rect = Wx::Rect.new
27
+ if get_bounding_rect(tree_item_id, rect, false)
28
+ return rect
29
+ else
30
+ return nil
31
+ end
32
+ end
33
+
34
+ # Returns a Wx::Rect corresponding to the edges of an individual tree
35
+ # item's text label. See above.
36
+ def get_label_rect(tree_item_id)
37
+ rect = Wx::Rect.new
38
+ if get_bounding_rect(tree_item_id, rect, true)
39
+ return rect
40
+ else
41
+ nil
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,6 @@
1
+ # Just a shortcut version for creating a vertical box sizer
2
+ class Wx::VBoxSizer < Wx::BoxSizer
3
+ def initialize
4
+ super(Wx::VERTICAL)
5
+ end
6
+ end
@@ -0,0 +1,89 @@
1
+ # Copyright 2004-2007 by Kevin Smith
2
+ # released under the MIT-style wxruby2 license
3
+
4
+ # The base class for all things displayed on screen
5
+ class Wx::Window
6
+
7
+ # Ruby's Object#id is deprecated and will be removed in 1.9; therefore
8
+ # for classes inheriting from Wx::Window, the id method returns the
9
+ # wxRuby Window id
10
+ alias :id :get_id
11
+ # In case a more explicit option is preferred.
12
+ alias :wx_id :get_id
13
+
14
+ # The name of Wx::Window#raise conflicts with Ruby's core Kernel#raise
15
+ # method. This can cause unexpected errors when undecorated #raise is
16
+ # used inside a Window method. For wxRuby 2.0 it's too late to remove
17
+ # Window#raise completely, but for now, offer alternatives to
18
+ # raise/lower that could replace them in future versions.
19
+ alias :bring_to_front :raise
20
+ alias :send_to_back :lower
21
+
22
+ # Recursively searches all windows below +self+ and returns the first
23
+ # window which has the id +an_id+. This corresponds to the find_window
24
+ # method method in WxWidgets when called with an integer.
25
+ def find_window_by_id(an_id)
26
+ Wx::Window.find_window_by_id(an_id, self)
27
+ end
28
+
29
+ # Searches all windows below +self+ and returns the first window which
30
+ # has the name +a_name+ This corresponds to the find_window method method
31
+ # in WxWidgets when called with an string.
32
+ def find_window_by_name(a_name)
33
+ Wx::Window.find_window_by_name(a_name, self)
34
+ end
35
+
36
+ # Searches all windows below +self+ and returns the first window which
37
+ # has the label +a_label+.
38
+ def find_window_by_label(a_label)
39
+ Wx:Window.find_window_by_label(a_label, self)
40
+ end
41
+
42
+ alias :__old_evt_paint :evt_paint
43
+ # This modified version of evt_paint sets a variable indicating that a
44
+ # paint event is being handled just before running the event
45
+ # handler. This ensures that any call to Window#paint within the
46
+ # handler will supply a Wx::PaintDC (see swig/Window.i).
47
+ def evt_paint(meth = nil, &block)
48
+ paint_proc = acquire_handler(meth, block)
49
+ wrapped_block = proc do | event |
50
+ instance_variable_set("@__painting__", true)
51
+ paint_proc.call(event)
52
+ remove_instance_variable("@__painting__")
53
+ end
54
+ __old_evt_paint(&wrapped_block)
55
+ end
56
+
57
+ # Provides bufferd drawing facility to reduce flicker for complex
58
+ # drawing commands. Works similar to BufferedDC and BufferedPaintDC in
59
+ # the wxWidgets API, by doing drawing on an in-memory Bitmap, then
60
+ # copying the result in bulk to the screen.
61
+ #
62
+ # The method may be passed an existing Wx::Bitmap as the +buffer+,
63
+ # otherwise one will be created.
64
+ #
65
+ # Works like wxAutoBufferedDC in that additional buffering will only
66
+ # be done on platforms that do not already natively support buffering
67
+ # for the standard PaintDC / ClientDC - Windows, in particular.
68
+ def paint_buffered(buffer = nil)
69
+ # OS X and GTK do double-buffering natively
70
+ if self.double_buffered?
71
+ paint { | dc | yield dc }
72
+ else
73
+ # client_size is the window area available for drawing upon
74
+ c_size = client_size
75
+ # Create an in-memory buffer if none supplied
76
+ buffer ||= Wx::Bitmap.new(c_size.width, c_size.height)
77
+ buffer.draw do | mem_dc |
78
+ mem_dc.background = Wx::TRANSPARENT_BRUSH
79
+ mem_dc.clear
80
+ # Yield the bitmap for the user code to draw upon
81
+ yield mem_dc
82
+ paint do | dc |
83
+ # Copy the buffer to the window
84
+ dc.blit(0, 0, c_size.width, c_size.height, mem_dc, 0, 0)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,54 @@
1
+ class Wx::XmlResource
2
+ # XRC_NO_SUBCLASSING should always be in place in wxRuby - we can't
3
+ # currently link directly to wxRuby subclasses.
4
+ class << self
5
+ wx_get = self.instance_method(:get)
6
+ define_method(:get) do
7
+ res = wx_get.bind(self).call
8
+ res.flags |= Wx::XRC_NO_SUBCLASSING
9
+ res
10
+ end
11
+ end
12
+
13
+ # WxRuby already has all XRC handlers built in so there's no way to
14
+ # control init_all_handlers to reduce binary size. So save users
15
+ # having to call it.
16
+ wx_init = self.instance_method(:initialize)
17
+ define_method(:initialize) do | *args |
18
+ result = wx_init.bind(self).call(*args)
19
+ result.flags |= Wx::XRC_NO_SUBCLASSING
20
+ result.init_all_handlers
21
+ end
22
+
23
+ # The standard .load method returns a boolean indicating success or
24
+ # failure. Failure might result from bad XML, or a non-existent
25
+ # file. In ruby, in these circumstances, it's more natural to raise an
26
+ # Exception than expect the user to test the return value.
27
+ wx_load = self.instance_method(:load)
28
+ define_method(:load) do | fname |
29
+ result = wx_load.bind(self).call(fname)
30
+ if not result
31
+ Kernel.raise( RuntimeError,
32
+ "Failed to load XRC from '#{fname}'; " +
33
+ "check the file exists and is valid XML")
34
+ end
35
+ fname
36
+ end
37
+
38
+ # Returns a Wx::Wizard object from the element named +name+ in the
39
+ # loaded XRC file. The Wizard will have the parent +parent+.
40
+ #
41
+ # This method is not available in wxWidgets, but is here for
42
+ # completeness and also to document how to use load_object (see
43
+ # below).
44
+ def load_wizard(parent, name)
45
+ wiz = Wx::Wizard.new()
46
+ load_wizard_subclass(wiz, parent, name)
47
+ wiz
48
+ end
49
+
50
+ # Completes the loading of a incomplete instance of Wx::Wizard.
51
+ def load_wizard_subclass(wizard, parent, name)
52
+ load_object(wizard, parent, name, "wxWizard")
53
+ end
54
+ end
data/lib/wx/helpers.rb ADDED
@@ -0,0 +1,45 @@
1
+ # Various non-GUI helper functions
2
+ module Wx
3
+ # A named parameter in a Wx named-arg parameter list
4
+ Parameter = Struct.new( :name, :default )
5
+
6
+ # Convert mixed positional / named args into a list to be passed to
7
+ # an underlying API method. +param_spec+ is an Array of Parameter
8
+ # structs containing the keyword name and default value for each
9
+ # possible argument. +mixed_args+ is an array which may optionally end
10
+ # with a set of named arguments
11
+ def self.args_as_list(param_spec, *mixed_args)
12
+ # get keyword arguments from mixed args if supplied, else empty
13
+ kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
14
+ out_args = []
15
+ param_spec.each_with_index do | param, i |
16
+ if arg = mixed_args[i] # use the supplied list arg
17
+ out_args << arg
18
+ elsif kwa.key?(param.name) # use the keyword arg
19
+ out_args << kwa[param.name]
20
+ else # use the default argument
21
+ out_args << param.default
22
+ end
23
+ end
24
+ out_args
25
+ rescue
26
+ Kernel.raise ArgumentError,
27
+ "Bad arg composition of #{mixed_args.inspect}"
28
+ end
29
+
30
+ # Given an integer constant +int_const+, returns an array Wx constant
31
+ # names which have this value. If a string +prefix+ is supplied, find
32
+ # only constants whose names begin with this prefix. For example,
33
+ # passing "EVT" would return only constants with a name like
34
+ # Wx::EVT_XXX
35
+ #
36
+ # This is primarily useful for debugging, when an unknown constant is
37
+ # returned, eg as an event type id.
38
+ def self.find_const(sought, prefix = "")
39
+ consts = constants.grep(/\A#{prefix}/)
40
+ consts.find_all do | c |
41
+ c_val = const_get(c)
42
+ c_val.instance_of?(Fixnum) and c_val == sought
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,204 @@
1
+ # = WxRuby Extensions - Keyword Constructors
2
+ #
3
+ # The *Keyword Constructors* extension allows the use of Ruby hash-style
4
+ # keyword arguments in constructors of common WxWidgets Windows, Frame,
5
+ # Dialog and Control classes.
6
+ #
7
+ # == Introduction
8
+ #
9
+ # Building a GUI in WxWidgets involves lots of calls to +new+, but
10
+ # these methods often have long parameter lists. Often the default
11
+ # values for many of these parameters are correct. For example, if
12
+ # you're using a sizer-based layout, you usually don't want to specify a
13
+ # size for widgets, but you still have to type
14
+ #
15
+ # Wx::TreeCtrl.new( parent, -1, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE,
16
+ # Wx::NO_BUTTONS )
17
+ #
18
+ # just to create a standard TreeCtrl with the 'no buttons' style. If you
19
+ # want to specify the 'NO BUTTONS' style, you can't avoid all the typing
20
+ # of DEFAULT_POSITION etc.
21
+ #
22
+ # == Basic Keyword Constructors
23
+ #
24
+ # With keyword_constructors, you could write the above as
25
+ #
26
+ # TreeCtrl.new(parent, :style => Wx::NO_BUTTONS)
27
+ #
28
+ # And it will assume you want the default id (-1), and the default size
29
+ # and position. If you want to specify an explicit size, you can do so:
30
+ #
31
+ # TreeCtrl.new(parent, :size => Wx::Size.new(100, 300))
32
+ #
33
+ # For brevity, this module also allows you to specify positions and
34
+ # sizes using a a two-element array:
35
+ #
36
+ # TreeCtrl.new(parent, :size => [100, 300])
37
+ #
38
+ # Similarly with position:
39
+ #
40
+ # TreeCtrl.new(parent, :pos => Wx::Point.new(5, 25))
41
+ #
42
+ # TreeCtrl.new(parent, :pos => [5, 25])
43
+ #
44
+ # You can have multiple keyword arguments:
45
+ #
46
+ # TreeCtrl.new(parent, :pos => [5, 25], :size => [100, 300] )
47
+ #
48
+ # == No ID required
49
+ #
50
+ # As with position and size, you usually don't want to deal with
51
+ # assigning unique ids to every widget and frame you create - it's a C++
52
+ # hangover that often seems clunky in Ruby. The *Event Connectors*
53
+ # extension allows you to set up event handling without having to use
54
+ # ids, and if no :id argument is supplied to a constructor, the default
55
+ # (-1) will be passed.
56
+ #
57
+ # There are occasions when a specific ID does need to be used - for
58
+ # example, to tell WxWidgets that a button is a 'stock' item, so that it
59
+ # can be displayed using platform-standard text and icon. To do this,
60
+ # simply pass an :id argument to the constructor - here, the system's
61
+ # standard 'preview' button
62
+ #
63
+ # Wx::Button.new(parent, :id => Wx::ID_PREVIEW)
64
+ #
65
+ # == Class-specific arguments
66
+ #
67
+ # The arguments :size, :pos and :style are common to many WxWidgets
68
+ # window classes. The +new+ methods of these classes also have
69
+ # parameters that are specific to those classes; for example, the text
70
+ # label on a button, or the initial value of a text control.
71
+ #
72
+ # Wx::Button.new(parent, :label => 'press me')
73
+ # Wx::TextCtrl.new(parent, :value => 'type some text here')
74
+ #
75
+ # The keyword names of these arguments can be found by looking at the
76
+ # WxRuby documentation, in the relevant class's +new+ method. You can
77
+ # also get a string description of the class's +new+ method parameters
78
+ # within Ruby by doing:
79
+ #
80
+ # puts Wx::TextCtrl.describe_constructor()
81
+ #
82
+ # This will print a list of the argument names expected by the class's
83
+ # +new+ method, and the correct type for them.
84
+ #
85
+ # == Mixing positional and keyword arguments
86
+ #
87
+ # To support existing code, and to avoid forcing the use of more verbose
88
+ # keyword-style arguments where they're not desired, you can mix
89
+ # positional and keyword arguments, omitting or including +id+s as
90
+ # desired.
91
+ #
92
+ # Wx::Button.new(parent, 'press me', :style => Wx::BU_RIGHT)
93
+
94
+ module Wx
95
+ module KeywordConstructor
96
+ module ClassMethods
97
+
98
+ # Common Wx constructor argument keywords, with their default values.
99
+ STANDARD_DEFAULTS = {
100
+ :id => -1,
101
+ :size => Wx::DEFAULT_SIZE,
102
+ :pos => Wx::DEFAULT_POSITION,
103
+ :style => 0,
104
+ :title => '',
105
+ :validator => Wx::DEFAULT_VALIDATOR,
106
+ :choices => [] # for Choice, ComboBox etc
107
+ }
108
+
109
+ attr_writer :param_spec
110
+ def param_spec
111
+ @param_spec ||= []
112
+ end
113
+
114
+ # Adds a list of named parameters *params* to the parameter
115
+ # specification for this Wx class's constructor. Each parameter
116
+ # should be specified as a either a common known symbol, such as
117
+ # +:size+ or +:pos:+ or +:style:+ (corresponding to the common
118
+ # constructor arguments in WxWidgets API), or a single-key with the
119
+ # key the name of the argument, and the value a default value.
120
+ #
121
+ # Parameters should be specified in the order they occur in the Wx
122
+ # API constructor
123
+ def wx_ctor_params(*params)
124
+ self.param_spec += params.map do | param |
125
+ param.kind_of?(Hash) ?
126
+ Parameter[ param.keys.first, param.values.first ] :
127
+ Parameter[ param, STANDARD_DEFAULTS[param] ]
128
+ end
129
+ end
130
+
131
+ def args_as_list(*mixed_args)
132
+ Wx::args_as_list(param_spec, *mixed_args)
133
+ end
134
+
135
+ def args_as_hash(*mixed_args)
136
+ kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
137
+ param_spec.zip(mixed_args) do | param, arg |
138
+ kwa[param.name] = arg if arg
139
+ end
140
+ kwa
141
+ end
142
+
143
+ def describe_constructor()
144
+ param_spec.inject("") do | desc, param |
145
+ desc << ":#{param.name} => (#{param.default.class.name})\n"
146
+ end
147
+ end
148
+ end
149
+
150
+ def self.included(klass)
151
+ klass.extend ClassMethods
152
+ klass.module_eval do
153
+
154
+ alias :pre_wx_kwctor_init :initialize
155
+
156
+ # The new definition of initialize; accepts a parent arg
157
+ # mixed_args, which may zero or more position args, optionally
158
+ # terminated with hash keyword args, and an optional block
159
+ def initialize(parent = :default_ctor, *mixed_args, &block)
160
+ # allow zero-args ctor for use with XRC
161
+ if parent == :default_ctor
162
+ pre_wx_kwctor_init()
163
+ return
164
+ end
165
+
166
+ real_args = [ parent ] + self.class.args_as_list(*mixed_args)
167
+ begin
168
+ pre_wx_kwctor_init(*real_args)
169
+ rescue => err
170
+ msg = "Error initializing #{self.inspect}\n"+
171
+ " : #{err.message} \n" +
172
+ "Correct parameters for #{self.class.name}.new are:\n" +
173
+ self.class.describe_constructor()
174
+
175
+ new_err = err.class.new(msg)
176
+ new_err.set_backtrace(caller)
177
+ Kernel.raise new_err
178
+ end
179
+
180
+ # If a block was given, pass the newly created Window instance
181
+ # into it; use block
182
+ if block
183
+ if block.arity == -1 or block.arity == 0
184
+ self.instance_eval(&block)
185
+ elsif block.arity == 1
186
+ block.call(self)
187
+ else
188
+ Kernel.raise ArgumentError,
189
+ "Block to initialize accepts zero or one arg"
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ # Any class inheriting from a class including this module must have
196
+ # its own copy of the param_spec
197
+ def klass.inherited(sub_klass)
198
+ sub_klass.instance_variable_set(:@param_spec,
199
+ instance_variable_get(:@param_spec) )
200
+ end
201
+ end
202
+ end
203
+ end
204
+