wxruby3 0.9.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/INSTALL.md +183 -42
  3. data/README.md +40 -48
  4. data/ext/mkrf_conf_ext.rb +72 -0
  5. data/lib/wx/core/app.rb +16 -0
  6. data/lib/wx/core/colour.rb +36 -28
  7. data/lib/wx/core/const.rb +19 -0
  8. data/lib/wx/core/enum.rb +17 -1
  9. data/lib/wx/core/geometry.rb +121 -0
  10. data/lib/wx/core/graphics_pen_info.rb +18 -0
  11. data/lib/wx/core/image.rb +49 -0
  12. data/lib/wx/core/menu_bar.rb +11 -0
  13. data/lib/wx/core/paintdc.rb +9 -3
  14. data/lib/wx/core/secret_store.rb +38 -0
  15. data/lib/wx/doc/app.rb +97 -41
  16. data/lib/wx/doc/bitmap.rb +4 -0
  17. data/lib/wx/doc/client_dc.rb +2 -2
  18. data/lib/wx/doc/clipboard.rb +1 -1
  19. data/lib/wx/doc/colour.rb +12 -0
  20. data/lib/wx/doc/const.rb +16 -0
  21. data/lib/wx/doc/cursor.rb +4 -0
  22. data/lib/wx/doc/dc_overlay.rb +34 -0
  23. data/lib/wx/doc/enum.rb +7 -1
  24. data/lib/wx/doc/event_blocker.rb +1 -1
  25. data/lib/wx/doc/evthandler.rb +25 -3
  26. data/lib/wx/doc/functions.rb +3 -6
  27. data/lib/wx/doc/gc_dc.rb +13 -4
  28. data/lib/wx/doc/geometry.rb +136 -0
  29. data/lib/wx/doc/graphics_context.rb +25 -7
  30. data/lib/wx/doc/icon.rb +4 -0
  31. data/lib/wx/doc/image.rb +56 -0
  32. data/lib/wx/doc/list_ctrl.rb +6 -6
  33. data/lib/wx/doc/memory_dc.rb +2 -11
  34. data/lib/wx/doc/mirror_dc.rb +1 -1
  35. data/lib/wx/doc/pen.rb +26 -0
  36. data/lib/wx/doc/persistence_manager.rb +1 -1
  37. data/lib/wx/doc/persistent_object.rb +1 -1
  38. data/lib/wx/doc/pg/property_grid_interface.rb +3 -3
  39. data/lib/wx/doc/prt/printer_dc.rb +2 -2
  40. data/lib/wx/doc/region_iterator.rb +1 -1
  41. data/lib/wx/doc/scaled_dc.rb +1 -1
  42. data/lib/wx/doc/screen_dc.rb +1 -1
  43. data/lib/wx/doc/secret_store.rb +55 -0
  44. data/lib/wx/doc/svg_file_dc.rb +1 -1
  45. data/lib/wx/doc/textctrl.rb +1 -1
  46. data/lib/wx/doc/tree_ctrl.rb +2 -2
  47. data/lib/wx/doc/validator.rb +6 -6
  48. data/lib/wx/doc/variant.rb +2 -2
  49. data/lib/wx/doc/window.rb +5 -4
  50. data/lib/wx/grid/keyword_defs.rb +1 -1
  51. data/lib/wx/html/keyword_defs.rb +3 -3
  52. data/lib/wx/keyword_defs.rb +76 -71
  53. data/lib/wx/pg/keyword_defs.rb +2 -2
  54. data/lib/wx/pg/pg_property.rb +12 -0
  55. data/lib/wx/rbn/keyword_defs.rb +1 -1
  56. data/lib/wx/rtc/keyword_defs.rb +1 -1
  57. data/lib/wx/stc/keyword_defs.rb +1 -1
  58. data/lib/wx/version.rb +1 -1
  59. data/lib/wx/wxruby/base.rb +3 -5
  60. data/lib/wx/wxruby/cmd/check.rb +182 -0
  61. data/lib/wx/wxruby/cmd/sampler.rb +1 -1
  62. data/lib/wx/wxruby/cmd/setup.rb +9 -3
  63. data/lib/wx/wxruby/cmd/test.rb +1 -1
  64. data/rakelib/configure.rb +67 -52
  65. data/rakelib/gem.rake +97 -66
  66. data/rakelib/gem.rb +294 -41
  67. data/rakelib/install.rb +3 -3
  68. data/rakelib/lib/config/{cygwin.rb → freebsd.rb} +1 -1
  69. data/rakelib/lib/config/linux.rb +4 -2
  70. data/rakelib/lib/config/macosx.rb +42 -11
  71. data/rakelib/lib/config/mingw.rb +2 -2
  72. data/rakelib/lib/config/pkgman/{base.rb → linux.rb} +36 -61
  73. data/rakelib/lib/config/pkgman/macosx.rb +17 -78
  74. data/rakelib/lib/config/unixish.rb +17 -8
  75. data/rakelib/lib/config/{netbsd.rb → unknown.rb} +3 -2
  76. data/rakelib/lib/config.rb +74 -33
  77. data/rakelib/lib/core/include/enum.inc +31 -1
  78. data/rakelib/lib/director/affine_matrix.rb +51 -0
  79. data/rakelib/lib/director/app.rb +29 -13
  80. data/rakelib/lib/director/art_provider.rb +4 -0
  81. data/rakelib/lib/director/aui_manager.rb +1 -1
  82. data/rakelib/lib/director/cursor.rb +6 -2
  83. data/rakelib/lib/director/dc.rb +1 -6
  84. data/rakelib/lib/director/derived_dc.rb +88 -31
  85. data/rakelib/lib/director/geometry.rb +142 -0
  86. data/rakelib/lib/director/graphics_context.rb +3 -2
  87. data/rakelib/lib/director/graphics_object.rb +18 -25
  88. data/rakelib/lib/director/grid_ctrl.rb +2 -2
  89. data/rakelib/lib/director/image.rb +59 -0
  90. data/rakelib/lib/director/menu.rb +2 -3
  91. data/rakelib/lib/director/menu_bar.rb +0 -3
  92. data/rakelib/lib/director/pen.rb +1 -1
  93. data/rakelib/lib/director/richtext_composite_object.rb +2 -4
  94. data/rakelib/lib/director/richtext_ctrl.rb +1 -1
  95. data/rakelib/lib/director/secret_store.rb +117 -0
  96. data/rakelib/lib/director/system_settings.rb +1 -1
  97. data/rakelib/lib/director/tree_event.rb +2 -2
  98. data/rakelib/lib/director/window.rb +4 -3
  99. data/rakelib/lib/extractor/function.rb +1 -1
  100. data/rakelib/lib/generate/doc/animation_ctrl.yaml +10 -0
  101. data/rakelib/lib/generate/doc/banner_window.yaml +35 -0
  102. data/rakelib/lib/generate/doc/graphics_context.yaml +12 -0
  103. data/rakelib/lib/generate/doc/graphics_object.yaml +12 -0
  104. data/rakelib/lib/generate/doc/grid_ctrl.yaml +25 -0
  105. data/rakelib/lib/generate/doc/header_ctrl.yaml +91 -0
  106. data/rakelib/lib/generate/doc/icon.yaml +10 -0
  107. data/rakelib/lib/generate/doc/info_bar.yaml +27 -0
  108. data/rakelib/lib/generate/doc/log.yaml +1 -1
  109. data/rakelib/lib/generate/doc/media_ctrl.yaml +27 -0
  110. data/rakelib/lib/generate/doc/persistent_window.yaml +22 -0
  111. data/rakelib/lib/generate/doc/pg_editor.yaml +1 -1
  112. data/rakelib/lib/generate/doc/pg_property.yaml +4 -4
  113. data/rakelib/lib/generate/doc/rearrange_list.yaml +14 -0
  114. data/rakelib/lib/generate/doc/ribbon_panel.yaml +15 -0
  115. data/rakelib/lib/generate/doc/rich_text_formatting_dialog.yaml +26 -0
  116. data/rakelib/lib/generate/doc/secret_store.yaml +55 -0
  117. data/rakelib/lib/generate/doc/text_ctrl.yaml +1 -1
  118. data/rakelib/lib/generate/doc/wizard.yaml +27 -0
  119. data/rakelib/lib/generate/doc.rb +5 -5
  120. data/rakelib/lib/generate/interface.rb +1 -1
  121. data/rakelib/lib/specs/interfaces.rb +4 -0
  122. data/rakelib/lib/swig_runner.rb +24 -3
  123. data/rakelib/lib/typemap/common.rb +10 -0
  124. data/rakelib/lib/typemap/points_list.rb +8 -2
  125. data/rakelib/lib/typemap/richtext.rb +17 -0
  126. data/rakelib/prepost.rake +8 -1
  127. data/rakelib/yard/templates/default/fulldoc/html/css/wxruby3.css +4 -0
  128. data/rakelib/yard/templates/default/fulldoc/html/setup.rb +3 -3
  129. data/samples/dialogs/wizard.rb +20 -19
  130. data/samples/drawing/art/drawing/image.bmp +0 -0
  131. data/samples/drawing/art/drawing/mask.bmp +0 -0
  132. data/samples/drawing/art/drawing/pat35.bmp +0 -0
  133. data/samples/drawing/art/drawing/pat36.bmp +0 -0
  134. data/samples/drawing/art/drawing/pat4.bmp +0 -0
  135. data/samples/drawing/art/drawing/smile.xpm +42 -0
  136. data/samples/drawing/drawing.rb +2276 -0
  137. data/samples/drawing/tn_drawing.png +0 -0
  138. data/samples/html/html.rb +1 -1
  139. data/samples/propgrid/propgrid.rb +1 -1
  140. data/samples/propgrid/propgrid_minimal.rb +1 -1
  141. data/samples/propgrid/sample_props.rb +1 -1
  142. data/samples/sampler/editor.rb +13 -11
  143. data/samples/sampler/sample.rb +2 -0
  144. data/samples/sampler.rb +14 -10
  145. data/samples/text/richtext.rb +53 -0
  146. data/samples/text/scintilla.rb +1 -1
  147. data/samples/text/unicode.rb +4 -4
  148. data/tests/lib/wxapp_runner.rb +1 -1
  149. data/tests/test_config.rb +7 -4
  150. data/tests/test_ext_controls.rb +12 -5
  151. data/tests/test_secret_store.rb +83 -0
  152. data/tests/test_std_controls.rb +12 -12
  153. metadata +66 -47
  154. data/lib/wx/doc/extra/00_starting.md +0 -154
  155. data/lib/wx/doc/extra/01_packages.md +0 -180
  156. data/lib/wx/doc/extra/02_lifecycles.md +0 -166
  157. data/lib/wx/doc/extra/03_dialogs.md +0 -57
  158. data/lib/wx/doc/extra/04_enums.md +0 -143
  159. data/lib/wx/doc/extra/05_event-handling.md +0 -191
  160. data/lib/wx/doc/extra/06_geometry.md +0 -62
  161. data/lib/wx/doc/extra/07_colour_and_font.md +0 -52
  162. data/lib/wx/doc/extra/08_extensions.md +0 -144
  163. data/lib/wx/doc/extra/09_exceptions.md +0 -54
  164. data/lib/wx/doc/extra/10_art.md +0 -111
  165. data/lib/wx/doc/extra/11_drawing_and_dc.md +0 -62
  166. data/lib/wx/doc/extra/12_client_data.md +0 -89
  167. data/lib/wx/doc/extra/13_validators.md +0 -139
  168. data/lib/wx/doc/extra/14_config.md +0 -101
  169. data/lib/wx/doc/extra/15_persistence.md +0 -148
  170. data/rakefile +0 -14
  171. data/rakelib/lib/config/pkgman/arch.rb +0 -53
  172. data/rakelib/lib/config/pkgman/debian.rb +0 -66
  173. data/rakelib/lib/config/pkgman/rhel.rb +0 -54
  174. data/rakelib/lib/config/pkgman/suse.rb +0 -54
  175. data/samples/sampler/back.xpm +0 -21
  176. data/samples/sampler/copy.xpm +0 -44
  177. data/samples/sampler/cut.xpm +0 -46
  178. data/samples/sampler/filesave.xpm +0 -42
  179. data/samples/sampler/find.xpm +0 -62
  180. data/samples/sampler/findrepl.xpm +0 -63
  181. data/samples/sampler/forward.xpm +0 -21
  182. data/samples/sampler/paste.xpm +0 -46
  183. data/samples/sampler/redo.xpm +0 -58
  184. data/samples/sampler/undo.xpm +0 -58
@@ -1,144 +0,0 @@
1
- <!--
2
- # @markup markdown
3
- # @title 8. wxRuby Extensions
4
- -->
5
-
6
- # 8. wxRuby Extensions
7
-
8
- ## Keyword Constructors
9
-
10
- The **Keyword Constructors** extension allows the use of Ruby hash-style
11
- keyword arguments in constructors of common WxWidgets Windows, Frame,
12
- Dialog and Control classes.
13
-
14
- ### Introduction
15
-
16
- Building a GUI in WxWidgets involves lots of calls to +new+, but
17
- these methods often have long parameter lists. Often the default
18
- values for many of these parameters are correct. For example, if
19
- you're using a sizer-based layout, you usually don't want to specify a
20
- size for widgets, but you still have to type
21
-
22
- Wx::TreeCtrl.new( parent, -1, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::NO_BUTTONS )
23
-
24
- just to create a standard TreeCtrl with the 'no buttons' style. If you
25
- want to specify the 'NO BUTTONS' style, you can't avoid all the typing
26
- of DEFAULT_POSITION etc.
27
-
28
- ### Basic Keyword Constructors
29
-
30
- With keyword_constructors, you could write the above as
31
-
32
- TreeCtrl.new(parent, :style => Wx::NO_BUTTONS)
33
-
34
- And it will assume you want the default id (-1), and the default size
35
- and position. If you want to specify an explicit size, you can do so:
36
-
37
- TreeCtrl.new(parent, :size => Wx::Size.new(100, 300))
38
-
39
- For brevity, this module also allows you to specify positions and
40
- sizes using a a two-element array:
41
-
42
- TreeCtrl.new(parent, :size => [100, 300])
43
-
44
- Similarly with position:
45
-
46
- TreeCtrl.new(parent, :pos => Wx::Point.new(5, 25))
47
-
48
- TreeCtrl.new(parent, :pos => [5, 25])
49
-
50
- You can have multiple keyword arguments:
51
-
52
- TreeCtrl.new(parent, :pos => [5, 25], :size => [100, 300] )
53
-
54
- ### No ID required
55
-
56
- As with position and size, you usually don't want to deal with
57
- assigning unique ids to every widget and frame you create - it's a C++
58
- hangover that often seems clunky in Ruby. The **Event Connectors**
59
- extension allows you to set up event handling without having to use
60
- ids, and if no `:id` argument is supplied to a constructor, the default
61
- (-1) will be passed.
62
-
63
- There are occasions when a specific ID does need to be used - for
64
- example, to tell WxWidgets that a button is a 'stock' item, so that it
65
- can be displayed using platform-standard text and icon. To do this,
66
- simply pass an :id argument to the constructor - here, the system's
67
- standard 'preview' button
68
-
69
- Wx::Button.new(parent, :id => Wx::ID_PREVIEW)
70
-
71
- ### Class-specific arguments
72
-
73
- The arguments `:size`, `:pos` and `:style` are common to many WxWidgets
74
- window classes. The `new` methods of these classes also have
75
- parameters that are specific to those classes; for example, the text
76
- label on a button, or the initial value of a text control.
77
-
78
- Wx::Button.new(parent, :label => 'press me')
79
- Wx::TextCtrl.new(parent, :value => 'type some text here')
80
-
81
- The keyword names of these arguments can be found by looking at the
82
- WxRuby documentation, in the relevant class's +new+ method. You can
83
- also get a string description of the class's +new+ method parameters
84
- within Ruby by doing:
85
-
86
- puts Wx::TextCtrl.describe_constructor()
87
-
88
- This will print a list of the argument names expected by the class's
89
- +new+ method, and the correct type for them.
90
-
91
- ### Mixing positional and keyword arguments
92
-
93
- To support existing code, and to avoid forcing the use of more verbose
94
- keyword-style arguments where they're not desired, you can mix
95
- positional and keyword arguments, omitting or including `id`s as
96
- desired.
97
-
98
- Wx::Button.new(parent, 'press me', :style => Wx::BU_RIGHT)
99
-
100
- ### Handling complex defaults or version differences
101
-
102
- To support complex (context dependent) defaults and/or auto conversion
103
- of arguments for backwards compatibility the keyword constructors
104
- extension allows the definition of lambdas or procs to be associated
105
- with a parameter specification.
106
-
107
- ## Ruby-style accessors
108
-
109
- The wxWidgets API, in typical C++ style, has lots of accessor methods like
110
-
111
- - `GetPosition()`
112
- - `SetSize(a_size)`
113
- - `IsChecked()`
114
- - `CanUndo()`
115
- - `HasStyle(a_style)`
116
-
117
- which in wxRuby are mapped to Ruby methods like `get_position`, `set_size` etc.
118
-
119
- In Ruby however these kind of methods that set, get or query attributes or state are normally simply called
120
- by the attribute name or, in other cases, by a predicate method like:
121
-
122
- ```ruby
123
- pos = frame.position
124
- frame.size = a_size
125
- item.checked?
126
- control.can_undo?
127
- window.has_style?(a_style)
128
- ```
129
-
130
- With wxRuby3 (most of) the API methods that begin with *get_*, *set_*, *is_*, *can_* and *has_* are identified
131
- and the wxRuby API will have Ruby-style accessor aliases defined for those (appropriately decorated as needed).
132
- Note that if you are calling a *'setter'* method on `self`, you must explicitly send the message to `self` like:
133
-
134
- ```ruby
135
- # set's self size to be 100px by 100px
136
- self.size = Wx::Size.new(100, 100)
137
- ```
138
-
139
- since this will not work as you expect it to:
140
-
141
- ```ruby
142
- # only sets the value of a local variable 'size'
143
- size = Wx::Size.new
144
- ```
@@ -1,54 +0,0 @@
1
- <!--
2
- # @markup markdown
3
- # @title 9. wxRuby Exception Handling
4
- -->
5
-
6
- # 9. wxRuby Exception Handling
7
-
8
- The wxRuby library should (!) be completely exception safe, i.e. Ruby code raising an exception should not leak into
9
- the wrapped wxWidgets C++ code and cause unexpected exception handling or (worse) segmentation faults and should be
10
- handled in ways expected of Ruby applications.
11
-
12
- As the wxWidgets library does not use exceptions for it's public API any raised exceptions should come either from the
13
- wxRuby wrapper code (signalling mostly typical Ruby-ish error situations like ArgumentError, TypeError and such) or from
14
- your own Ruby application code.
15
-
16
- Any exceptions raised from wxRuby wrapper code signal coding errors that need to be rectified.
17
-
18
- As far as handling application code exceptions is concerned the same advice applies as for wxWidgets itself; do **NOT**
19
- let exceptions escape your event handlers meaning that if you can reasonably expect application code to raise exceptions
20
- you should make sure to catch any such exceptions within the context of the event handler like:
21
-
22
- ```ruby
23
- class MyForm < Wx::Frame
24
-
25
- def initialize(title)
26
- super(nil, title: title)
27
-
28
- # initialize frame elements
29
- # ...
30
-
31
- # setup event handlers
32
- evt_menu MY_MENU_ID, :on_my_menu_item
33
-
34
- # ...
35
- end
36
-
37
- def on_my_menu_item(evt)
38
- begin
39
- # execute some application code
40
- # ...
41
- rescue SomeException => ex
42
- # handle exception
43
- end
44
- end
45
-
46
- #...
47
-
48
- end
49
- ```
50
-
51
- In wxRuby event handler code is executed in an exception safe way which will capture any leaking exceptions. As wxRuby
52
- however has no idea why this exception was raised and how to handle it, the result will be an exit of the main event loop
53
- of the running {Wx::App} instance and re-raising the exception to be handled by Ruby like any unhandled application
54
- exception.
@@ -1,111 +0,0 @@
1
- <!--
2
- # @markup markdown
3
- # @title 10. wxRuby Locating and loading art
4
- -->
5
-
6
- # 10. wxRuby Locating and loading art
7
-
8
- ## Introduction
9
-
10
- With C++ wxWidgets applications art (icons, bitmaps, cursors, images) can be loaded in a variety
11
- of ways from embedded resources (platform specific binary resources or embedded XPM files) or from
12
- binary datasets retrieved from some data source.
13
-
14
- With wxRuby that is for various reasons not a viable option so we are left with the option to
15
- load art from files. In and of itself that option is not really too bad but for the issue of locating
16
- the art files.
17
- Art that is part of the application's design will preferably be stored with the source code but there
18
- is not standard for this nor is there any standard support for locating those files from the application
19
- code like there is for `require`-s of other code modules.
20
-
21
- The wxRuby framework provides a convenience module {Wx::ArtLocator} to assist in that respect.
22
- {Wx::ArtLocator} aims on the one side to standardize folder structures for storing art files and on the
23
- other side to provide runtime support for locating those files from code.
24
-
25
- The main locator method provided is:
26
-
27
- ```ruby
28
- module Wx::Locator
29
- def self.find_art(art_name, art_type: nil, art_path: nil, art_section: nil, bmp_type: nil)
30
- # ...
31
- end
32
- end
33
- ```
34
-
35
- The 'art_name' argument should provide the base name for matching art files and can be specified as either
36
- String or Symbol.
37
-
38
- ## Storage locations
39
-
40
- Wx::ArtLocator defines a standardized directory structure that is assumed to be used for application art
41
- file storage.
42
- Working from a certain (application defined) base search path ('art_path' argument) this structure looks like this:
43
-
44
- <art_path>
45
- \art
46
- \<art_section>
47
- \<art_type>
48
-
49
- Where '<art_path>' is an application supplied search path, 'art' is the default name for Art folders (this can be overridden by an application specific name),
50
- '<art_section>' is an application defined id allowing sub-categorizing art and '<art_type>' is the type of art indicator
51
- (which can be 'icon', 'bitmap', 'cursor', 'image').
52
- Art files can be located at any level in this hierarchy and all sub levels in this hierarchy are optional.
53
- When locating files the art locator will test a file's existence at all levels starting with the
54
- deepest level working it's way up returning the absolute path of the first file found this way.
55
-
56
- So locating an art file would involve testing for the file at the following paths:
57
- 1. \<art_path>/art/<art_section>/<art_type>/
58
- 2. \<art_path>/art/<art_section>/
59
- 3. \<art_path>/art/
60
- 4. \<art_path>/
61
-
62
- The first location can be skipped by specifying `nil` for 'art_type'.
63
-
64
- ## Bitmap types
65
-
66
- Based on platform and specified '<art_type>' (and optionally a specific {Wx::BitmapType}) art files with a specific
67
- range of extensions will be tested in a specific order.
68
- For example for locating an `:icon` (<art_type>) on platform 'WXGTK' the locator will test the preferred extension
69
- '.xpm' followed by any of supported extensions of all other supported bitmap types.
70
- For platform 'WXMSW' however the same search would test only the extensions '.ico' and '.xpm' (in that
71
- order).
72
- Specifying a specific {Wx::BitmapType} for a search will restrict the search to testing only the extensions supported
73
- for the specified {Wx::BitmapType}.
74
-
75
- ## Search paths
76
-
77
- To prevent having to specify base search path for every location request {Wx::Locator} provides 2 options.
78
-
79
- When an explicit specification of a base search path ('art_path) is omitted from a location request the locator
80
- will determine one by using `Kernel#caller_locations` to extract the absolute path for the source file containing
81
- the caller's code. The result of `File.dirname(src_path)` is than used as base search path.
82
- If 'art_section' is also omitted the result of `File.basename(src_path, '.*')` will be used instead.
83
-
84
- This means that calling {Wx::ArtLocator.find_art} from some code in file `/some/lib/path/to/ruby/code.rb` without
85
- specifying both 'art_path' and 'art_section' would result in looking for an art file with the base search path
86
- being `/some/lib/path/to/ruby/` and using `code` as 'art_section'.
87
-
88
- It is also possible to add 'application global' search paths with the method {Wx::ArtLocator.add_search_path}.
89
- Search paths added in this way will be tested after failing to find any matching art file at the initial 'art_path'
90
- location. The same location steps apply to these search paths as with the initial 'art_path' (see above).
91
-
92
- ## Convenience methods
93
-
94
- Based on the {Wx::ArtLocator} implementation wxRuby additionally provides a number of convenience methods to
95
- easily create Icons, Bitmaps, Cursors and Images from simple ids (symbols):
96
-
97
- - {Wx.Bitmap}
98
- - {Wx.Cursor}
99
- - {Wx.Icon}
100
- - {Wx.Image}
101
-
102
- These methods mimic the ease of use of the `wxICON` and `wxBITMAP` macros used with C++ wxWidgets such that
103
- creating an {Wx::Icon} instance could be as easy as:
104
-
105
- ```ruby
106
- frame.icon = Wx.Icon(:sample)
107
- ```
108
-
109
- As these methods apply the same search path 'automagic' as `Wx::ArtLocator.find_art` (see [Search paths](#Search-paths))
110
- this would search for an art file with base name 'sample' and an appropriate extension (like '.xpm' for the 'WXGTK' platform)
111
- in a location starting at the directory in which the caller's code is stored (applying the steps described above).
@@ -1,62 +0,0 @@
1
- <!--
2
- # @markup markdown
3
- # @title 11. wxRuby Drawing and Device Contexts
4
- -->
5
-
6
- # 11. wxRuby Drawing and Device Contexts (DC)
7
-
8
- In wxRuby the Wx::DC class family provides functionality for drawing to windows, bitmaps, printers etc.
9
-
10
- What most of these classes have in common is that actual drawing output is buffered until the time the
11
- device context object is destroyed.
12
- For this reason the common practice in wxWidgets C++ code would be to create temporary DC objects on the
13
- stack and draw on them while they are in scope (for several classes it is even strongly advised to never create
14
- them any other way and to never keep objects alive out of scope). When leaving the scope these object would than be
15
- automatically destroyed and any buffered output flushed to the final target.
16
-
17
- In Ruby this approach is impossible as Ruby is a purely dynamic language and does not support **this kind** of scope bound
18
- life cycles. Any DC object created would have to be dynamically created and due to the properties of the GC driven
19
- life cycles could well be kept alive beyond the scope of it's creation. This will not always cause problems but could
20
- and does not really have an upside.
21
-
22
- To prevent confusion and potential problems wxRuby defines all {Wx::DC} derived classes to be abstract classes that
23
- cannot be instantiated using `new`. Rather all {Wx::DC} derived classes provide `::draw_on` factory methods to create
24
- temporary dc objects that will be passed on to blocks given and will only exist for the duration of the execution of
25
- the block. This will guarantee proper DC cleanup when leaving it's usage scope.
26
-
27
- > Note that it is a **BAD** idea to think about storing the dc reference provided to the block for later access!
28
-
29
- A typical usage of a `::draw_on` method would be:
30
-
31
- ```ruby
32
- myTestBitmap1x = Wx::Bitmap.new(60, 15, 32)
33
- Wx::MemoryDC.draw_on(myTestBitmap1x) do |mdc|
34
- mdc.set_background(Wx::WHITE_BRUSH)
35
- mdc.clear
36
- mdc.set_pen(Wx::BLACK_PEN)
37
- mdc.set_brush(Wx::WHITE_BRUSH)
38
- mdc.draw_rectangle(0, 0, 60, 15)
39
- mdc.draw_line(0, 0, 59, 14)
40
- mdc.set_text_foreground(Wx::BLACK)
41
- mdc.draw_text("x1", 0, 0)
42
- end
43
- ```
44
-
45
- ## Windows, Wx::PaintDC and Wx::AutoBufferedPaintDC
46
-
47
- The {Wx::PaintDC} and {Wx::AutoBufferedPaintDC} classes provide `::draw_on` methods just like all other DC classes but
48
- this is mostly to be consistent.
49
-
50
- In this case it is recommended to instead use the {Wx::Window#paint} or {Wx::Window#paint_buffered} methods as these
51
- provide some optimizations with regard to automatically detecting if the methods are called inside `Wx::EVT_PAINT`
52
- handlers (which should normally be the case) or not.
53
-
54
- So the typical way to do buffered painting inside a windows `Wx::EVT_PAINT` handler would be something like:
55
-
56
- ```ruby
57
- def on_paint(_event)
58
- self.paint_buffered do |dc|
59
- # ... do some drawing ...
60
- end
61
- end
62
- ```
@@ -1,89 +0,0 @@
1
- <!--
2
- # @markup markdown
3
- # @title 12. Client/User data with wxRuby
4
- -->
5
-
6
- # 12. Client/User data with wxRuby
7
-
8
- ## Introduction
9
-
10
- The wxWidgets library has widespread support for attaching arbitrary client (or user) data to GUI elements like
11
- windows (all event handlers actually), window items, sizer items etc.
12
- To cater to various C++ use cases in most instances this support covers both specific wxWidgets defined types (like
13
- wxClientData and wxObject instances) and untyped data pointers (represented as `void *`) with subtle but essential
14
- differences.
15
-
16
- wxRuby implements a fully compatible version of this support.
17
-
18
- ## Everything is an Object
19
-
20
- As Ruby does not do untyped data (everything is an Object), and having two different options is confusing anyway,
21
- wxRuby provides only a single option and more or less unifies the interface across the entire library.
22
- In Ruby anywhere the original wxWidgets library supports some type of client (or user) data attachment wxRuby will
23
- support the attachment of any arbitrary Ruby `Object` by either the method `#set_client_object` (where C++ supports
24
- `SetClientData` and `SetClientObject`) or `#set_user_data` (where C++ supports `SetUserData`). Data retrieval
25
- is supported by complementary `#get_client_object` or `#get_user_data` methods in all cases.
26
- Wherever C++ supports `SetClientObject` wxRuby also provides the method aliases `#set_client_data` and `#get_client_data`.
27
-
28
- Another difference with C++ is that for typed client data in wxWidgets developers could leverage object destruction as
29
- callback trigger (through the implementation of virtual destructors) to handle any required 'unlinking' logic. This
30
- obviously does not apply to untyped data (one of the 'subtle' differences).
31
- As Ruby does not provide any usable object destruction hooks this does not work there.
32
- Ruby however has 'Duck-typing' which is what wxRuby uses to provide support for a unlinking callback 'hook' for attached
33
- client data.
34
-
35
- > Any attached Ruby Object implementing (responding to) the method `#client_data_unlinked` will have that method called after the
36
- > attached object has been detached from the element it was attached to (either because of data replacement or element
37
- > deletion).
38
-
39
- Regard the following example.
40
-
41
- ```ruby
42
- frame = Wx::Frame.new(nil, Wx::ID_ANY)
43
-
44
- # attach a hash with user data
45
- frame.set_client_data({ text: 'A string', float: 3.14 })
46
-
47
- # ... do something with frame
48
-
49
- # replace the user data
50
- frame.set_client_data([1,2,3,4])
51
-
52
- # ... do something else with frame
53
- ```
54
-
55
- In this case standard Ruby object are attached. After attachment the object can be retrieved using a call to `get_client_data`
56
- anywhere access to the frame instance is available.
57
-
58
- Using a specially derived (or adapted) object a developer can handle specific logic after the object has been unlinked
59
- like in this example:
60
-
61
- ```ruby
62
- # define a user data class
63
- class MyUserData
64
- def initialize(payload)
65
- @payload = payload
66
- end
67
- attr_reader :payload
68
-
69
- def client_data_unlinked
70
- # handle some logic
71
- end
72
- end
73
-
74
- # ...
75
-
76
- # attach data to some window
77
- win.set_client_data(MyUserData.new(some_payload_data))
78
-
79
- # ...
80
-
81
- # reset user data for some reason (will call MyUserData#client_data_unlinked after replacement)
82
- win.set_client_data(nil)
83
- ```
84
-
85
- # CommandEvent data
86
-
87
- wxRuby also fully supports the propagation of attached client data to Wx::CommandEvent objects (see
88
- {Wx::CommandEvent#get_client_object} and {Wx::CommandEvent#set_client_object}).
89
- As mentioned above wxRuby provides the method aliases `#set_client_data` and `#get_client_data` here also.
@@ -1,139 +0,0 @@
1
- <!--
2
- # @markup markdown
3
- # @title 13. Validators and data binding
4
- -->
5
-
6
- # 13. Validators and data binding
7
-
8
- ## Introduction
9
-
10
- wxRuby fully supports validator classes offering input validation and/or data binding and/or event filtering.
11
-
12
- ## Validation
13
-
14
- The base Wx::Validator class defines the method {Wx::Validator#validate} which is called when validation of the
15
- value or content of the associated window is required.
16
-
17
- The implementation of this method should (somehow) retrieve the value of the associated window and validate that
18
- value, returning `true` if valid or `false` otherwise. The default implementation always returns `false`.
19
-
20
- An example would be:
21
-
22
- ```ruby
23
- # define custom validator
24
- class MyTextValidator < Wx::Validator
25
-
26
- def validate(_parent)
27
- txt = get_window.value
28
- # validate that the control text starts with a capital if not empty
29
- txt.empty? || (?A..?Z).include?(txt[0])
30
- end
31
-
32
- end
33
-
34
- # ...
35
-
36
- # assign custom validator to text control
37
- text = Wx::TextCtrl.new(parent, MY_TEXT_ID)
38
- text.set_validator(MyTextValidator.new)
39
- ```
40
-
41
- The derived, specialized, validator classes {Wx::TextValidator}, {Wx::IntegerValidator}, {Wx::IntegerValidator} and
42
- {Wx::FloatValidator} all have implementations that can be configured through specific options and do not
43
- normally require an override to be defined.
44
-
45
- Examples of using the standard validators would be:
46
-
47
- ```ruby
48
- text = Wx::TextCtrl.new(parent, MY_TEXT_ID)
49
-
50
- # accept only hexadecimal characters
51
- text.set_validator(Wx::TextValidator.new(Wx::TextValidatorStyle::FILTER_XDIGITS))
52
-
53
- # or only numbers between -20 and 20
54
- text.set_validator(Wx::IntegerValidator.new(-20, 20))
55
- ```
56
-
57
- ## Event filtering
58
-
59
- All validator classes are event handlers and can have event handling routines defined (see
60
- [Event Handling](05_event-handling.md)).
61
- When processing events the core implementation will allow any validator associated with a window to handle an event
62
- before the associated window itself thereby allowing it to filter events (see {Wx::EvtHandler#process_event} for more
63
- details).
64
-
65
- The standard specialized validators use this functionality to filter entry of allowable characters (by handling
66
- Wx::EVT_CHAR events).
67
-
68
- ## Data binding
69
-
70
- Data binding concerns the transfer of a validator's associated window's value to or from a user definable storage (a
71
- variable, memory cache entry, persistent storage ...).
72
-
73
- To integrate with the core C++ implementation but allow for Ruby specific differences the scheme implemented for this
74
- differs somewhat (in naming and functionality) from the original wxWidgets interface.
75
-
76
- The responsibilities of the standard wxRuby interface for handling validator data binding is distributed over 2 base
77
- methods and a mixin module.
78
-
79
- - The protected {Wx::Validator#do_transfer_from_window} and {Wx::Validator#do_transfer_to_window} methods are
80
- responsible for collecting and transferring data from/to the associated window (possibly applying conversions).<br>
81
- <br>
82
- These methods have default implementations in all of the derived validator classes and should not be overridden for
83
- specializations of these as they will be ignored.<br>
84
- Overriding these methods is necessary to implement data binding for any user defined specialization of the base
85
- {Wx::Validator} class.<br>
86
- <br>
87
- - The methods the {Wx::Validator::Binding} mixin module provide the means to store data after collection from or retrieve data
88
- before transfer to the associated window.<br>
89
- <br>
90
- The methods {Wx::Validator::Binding#on_transfer_from_window} and {Wx::Validator::Binding#on_transfer_to_window} provide
91
- the means to specify user defined binding handlers for storing the data transferred from the associated window or retrieving the
92
- data to transfer to the associated window. Like with event handling the handlers can be specified using a `String` or
93
- `Symbol`, a `Proc` or a `Method`.<br>
94
- <br>
95
- The methods {Wx::Validator::Binding#do_on_transfer_from_window} and {Wx::Validator::Binding#do_on_transfer_to_window} by
96
- default call the binding handlers if defined.
97
- These methods can be overridden to create derived validator classes with dedicated data binding functionality like
98
- with {Wx::GenericValidator}.
99
-
100
- An example of a custom validator providing data binding would be:
101
-
102
- ```ruby
103
- class MyTextValidator < Wx::Validator
104
-
105
- def do_transfer_from_window
106
- get_window.get_value
107
- end
108
-
109
- def do_transfer_to_window(val)
110
- get_window.set_value(val)
111
- true
112
- end
113
-
114
- end
115
-
116
- # ...
117
-
118
- # use custom validator
119
- @data = nil # attribute to store data
120
- text.set_validator(MyTextValidator.new)
121
- text.get_validator.on_transfer_to_window { @data }
122
- text.get_validator.on_transfer_from_window { |v| @data = v }
123
- ```
124
-
125
- All derived, specialized, validators implement a dedicated value cache which can be accessed through the `#value` attribute
126
- accessor. Through this accessor the data collected from the associated window can get retrieved or the data to be transferred
127
- to the associated window set.
128
- With these classes it is therefor not necessary to define binding handlers. Defining binding handlers can however still be
129
- useful to implement a custom, persistent, storage solution.
130
-
131
- ### Wx::GenericValidator
132
-
133
- The {Wx::GenericValidator} class provides an extendable standard implementation for data binding in combination with a
134
- large collection of controls (see class documentation).
135
- The implementation provides a standard accessor {Wx::GenericValidator#value} to get the data value collected
136
- from the associated window or set the data to transfer to the associated window.
137
-
138
- To add support for any control unsupported by the standard implementation the method {Wx::GenericValidator.define_handler}
139
- is provided (see documentation for an example).