wxruby3 0.9.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/INSTALL.md +23 -1
  3. data/README.md +12 -26
  4. data/ext/mkrf_conf_ext.rb +11 -7
  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/doc/app.rb +97 -41
  15. data/lib/wx/doc/bitmap.rb +4 -0
  16. data/lib/wx/doc/client_dc.rb +2 -2
  17. data/lib/wx/doc/clipboard.rb +1 -1
  18. data/lib/wx/doc/colour.rb +12 -0
  19. data/lib/wx/doc/const.rb +16 -0
  20. data/lib/wx/doc/cursor.rb +4 -0
  21. data/lib/wx/doc/dc_overlay.rb +34 -0
  22. data/lib/wx/doc/enum.rb +7 -1
  23. data/lib/wx/doc/event_blocker.rb +1 -1
  24. data/lib/wx/doc/evthandler.rb +25 -3
  25. data/lib/wx/doc/functions.rb +3 -6
  26. data/lib/wx/doc/gc_dc.rb +13 -4
  27. data/lib/wx/doc/geometry.rb +136 -0
  28. data/lib/wx/doc/graphics_context.rb +25 -7
  29. data/lib/wx/doc/icon.rb +4 -0
  30. data/lib/wx/doc/image.rb +56 -0
  31. data/lib/wx/doc/list_ctrl.rb +6 -6
  32. data/lib/wx/doc/memory_dc.rb +2 -11
  33. data/lib/wx/doc/mirror_dc.rb +1 -1
  34. data/lib/wx/doc/pen.rb +26 -0
  35. data/lib/wx/doc/persistence_manager.rb +1 -1
  36. data/lib/wx/doc/persistent_object.rb +1 -1
  37. data/lib/wx/doc/pg/property_grid_interface.rb +3 -3
  38. data/lib/wx/doc/prt/printer_dc.rb +2 -2
  39. data/lib/wx/doc/region_iterator.rb +1 -1
  40. data/lib/wx/doc/scaled_dc.rb +1 -1
  41. data/lib/wx/doc/screen_dc.rb +1 -1
  42. data/lib/wx/doc/svg_file_dc.rb +1 -1
  43. data/lib/wx/doc/textctrl.rb +1 -1
  44. data/lib/wx/doc/tree_ctrl.rb +2 -2
  45. data/lib/wx/doc/validator.rb +6 -6
  46. data/lib/wx/doc/variant.rb +2 -2
  47. data/lib/wx/doc/window.rb +5 -4
  48. data/lib/wx/grid/keyword_defs.rb +1 -1
  49. data/lib/wx/html/keyword_defs.rb +3 -3
  50. data/lib/wx/keyword_defs.rb +76 -71
  51. data/lib/wx/pg/keyword_defs.rb +2 -2
  52. data/lib/wx/pg/pg_property.rb +12 -0
  53. data/lib/wx/rbn/keyword_defs.rb +1 -1
  54. data/lib/wx/rtc/keyword_defs.rb +1 -1
  55. data/lib/wx/stc/keyword_defs.rb +1 -1
  56. data/lib/wx/version.rb +1 -1
  57. data/lib/wx/wxruby/cmd/setup.rb +3 -0
  58. data/rakelib/configure.rb +7 -0
  59. data/rakelib/gem.rake +2 -1
  60. data/rakelib/gem.rb +3 -2
  61. data/rakelib/lib/config/linux.rb +1 -1
  62. data/rakelib/lib/config/unixish.rb +6 -7
  63. data/rakelib/lib/config.rb +25 -4
  64. data/rakelib/lib/core/include/enum.inc +31 -1
  65. data/rakelib/lib/director/affine_matrix.rb +51 -0
  66. data/rakelib/lib/director/app.rb +29 -13
  67. data/rakelib/lib/director/art_provider.rb +4 -0
  68. data/rakelib/lib/director/cursor.rb +6 -2
  69. data/rakelib/lib/director/dc.rb +1 -6
  70. data/rakelib/lib/director/derived_dc.rb +88 -31
  71. data/rakelib/lib/director/dialog.rb +0 -8
  72. data/rakelib/lib/director/geometry.rb +142 -0
  73. data/rakelib/lib/director/graphics_context.rb +3 -2
  74. data/rakelib/lib/director/graphics_object.rb +18 -25
  75. data/rakelib/lib/director/image.rb +59 -0
  76. data/rakelib/lib/director/menu.rb +2 -3
  77. data/rakelib/lib/director/menu_bar.rb +0 -3
  78. data/rakelib/lib/director/pen.rb +1 -1
  79. data/rakelib/lib/director/richtext_ctrl.rb +1 -1
  80. data/rakelib/lib/director/system_settings.rb +1 -1
  81. data/rakelib/lib/director/window.rb +4 -3
  82. data/rakelib/lib/extractor/function.rb +1 -1
  83. data/rakelib/lib/generate/doc/animation_ctrl.yaml +10 -0
  84. data/rakelib/lib/generate/doc/banner_window.yaml +35 -0
  85. data/rakelib/lib/generate/doc/graphics_context.yaml +12 -0
  86. data/rakelib/lib/generate/doc/graphics_object.yaml +12 -0
  87. data/rakelib/lib/generate/doc/grid_ctrl.yaml +25 -0
  88. data/rakelib/lib/generate/doc/header_ctrl.yaml +91 -0
  89. data/rakelib/lib/generate/doc/icon.yaml +10 -0
  90. data/rakelib/lib/generate/doc/info_bar.yaml +27 -0
  91. data/rakelib/lib/generate/doc/log.yaml +1 -1
  92. data/rakelib/lib/generate/doc/media_ctrl.yaml +27 -0
  93. data/rakelib/lib/generate/doc/persistent_window.yaml +22 -0
  94. data/rakelib/lib/generate/doc/pg_editor.yaml +1 -1
  95. data/rakelib/lib/generate/doc/pg_property.yaml +4 -4
  96. data/rakelib/lib/generate/doc/rearrange_list.yaml +14 -0
  97. data/rakelib/lib/generate/doc/ribbon_panel.yaml +15 -0
  98. data/rakelib/lib/generate/doc/rich_text_formatting_dialog.yaml +26 -0
  99. data/rakelib/lib/generate/doc/text_ctrl.yaml +1 -1
  100. data/rakelib/lib/generate/doc/wizard.yaml +27 -0
  101. data/rakelib/lib/generate/doc.rb +4 -4
  102. data/rakelib/lib/generate/interface.rb +1 -1
  103. data/rakelib/lib/specs/interfaces.rb +3 -0
  104. data/rakelib/lib/swig_runner.rb +24 -3
  105. data/rakelib/lib/typemap/points_list.rb +8 -2
  106. data/rakelib/lib/typemap/richtext.rb +17 -0
  107. data/rakelib/yard/templates/default/fulldoc/html/setup.rb +3 -3
  108. data/samples/dialogs/wizard.rb +20 -19
  109. data/samples/drawing/art/drawing/image.bmp +0 -0
  110. data/samples/drawing/art/drawing/mask.bmp +0 -0
  111. data/samples/drawing/art/drawing/pat35.bmp +0 -0
  112. data/samples/drawing/art/drawing/pat36.bmp +0 -0
  113. data/samples/drawing/art/drawing/pat4.bmp +0 -0
  114. data/samples/drawing/art/drawing/smile.xpm +42 -0
  115. data/samples/drawing/drawing.rb +2276 -0
  116. data/samples/drawing/tn_drawing.png +0 -0
  117. data/samples/html/html.rb +1 -1
  118. data/samples/propgrid/propgrid.rb +1 -1
  119. data/samples/propgrid/propgrid_minimal.rb +1 -1
  120. data/samples/propgrid/sample_props.rb +1 -1
  121. data/samples/sampler/editor.rb +13 -11
  122. data/samples/sampler.rb +14 -10
  123. data/samples/text/richtext.rb +53 -0
  124. data/samples/text/scintilla.rb +1 -1
  125. data/samples/text/unicode.rb +4 -4
  126. data/tests/test_ext_controls.rb +12 -5
  127. data/tests/test_std_controls.rb +12 -12
  128. metadata +30 -30
  129. data/lib/wx/doc/extra/00_starting.md +0 -154
  130. data/lib/wx/doc/extra/01_packages.md +0 -180
  131. data/lib/wx/doc/extra/02_lifecycles.md +0 -166
  132. data/lib/wx/doc/extra/03_dialogs.md +0 -57
  133. data/lib/wx/doc/extra/04_enums.md +0 -143
  134. data/lib/wx/doc/extra/05_event-handling.md +0 -191
  135. data/lib/wx/doc/extra/06_geometry.md +0 -62
  136. data/lib/wx/doc/extra/07_colour_and_font.md +0 -52
  137. data/lib/wx/doc/extra/08_extensions.md +0 -144
  138. data/lib/wx/doc/extra/09_exceptions.md +0 -54
  139. data/lib/wx/doc/extra/10_art.md +0 -111
  140. data/lib/wx/doc/extra/11_drawing_and_dc.md +0 -62
  141. data/lib/wx/doc/extra/12_client_data.md +0 -89
  142. data/lib/wx/doc/extra/13_validators.md +0 -139
  143. data/lib/wx/doc/extra/14_config.md +0 -101
  144. data/lib/wx/doc/extra/15_persistence.md +0 -148
  145. data/samples/sampler/back.xpm +0 -21
  146. data/samples/sampler/copy.xpm +0 -44
  147. data/samples/sampler/cut.xpm +0 -46
  148. data/samples/sampler/filesave.xpm +0 -42
  149. data/samples/sampler/find.xpm +0 -62
  150. data/samples/sampler/findrepl.xpm +0 -63
  151. data/samples/sampler/forward.xpm +0 -21
  152. data/samples/sampler/paste.xpm +0 -46
  153. data/samples/sampler/redo.xpm +0 -58
  154. data/samples/sampler/undo.xpm +0 -58
@@ -1,143 +0,0 @@
1
- <!--
2
- # @markup markdown
3
- # @title 4. wxRuby Enum values
4
- -->
5
-
6
- # 4. wxRuby Enum values
7
-
8
- The wxWidget library liberally mixes integer constants and enum values for things like IDs, style flags
9
- and option flags and such without much consistency.<br>
10
- In previous wxRuby versions these were all mapped to integer constants which had 2 distinct disadvantages.
11
-
12
- - **loss of scoping**<br>
13
- Integer constants for enum values would all be declared in the enclosing scope for the enum declaration loosing
14
- the naming scope which originally existed in C++ (excepting anonymous enums).
15
-
16
- - **loss of type-safety**<br>
17
- Constants for enum values with identical integer values are indistinguishable from each other.
18
-
19
- The wxRuby3 project attempts to provide a solution to that by introducing the `Wx::Enum` class which
20
- is used as a base class for mapping all (named) wxWidget enums to Ruby.
21
- The reference documentation for the `Wx::Enum` class can be found [here](https://mcorino.github.io/wxRuby3/Wx/Enum.html).
22
-
23
- Any named wxWidget enum is mapped to a similarly named (Rubified C++ name) derived Enum class with each enum value
24
- defined as a constant of the enum class referencing an instance of the enum class with the corresponding
25
- integer value like for example the 'wxSystemFont' enum which is defined in wxRuby as:
26
-
27
- ```ruby
28
- module Wx
29
- class SystemFont < Wx::Enum
30
-
31
- # Original equipment manufacturer dependent fixed-pitch font.
32
- #
33
- SYS_OEM_FIXED_FONT = Wx::SystemFont.new(10)
34
-
35
- # Windows fixed-pitch (monospaced) font.
36
- #
37
- SYS_ANSI_FIXED_FONT = Wx::SystemFont.new(11)
38
-
39
- # Windows variable-pitch (proportional) font.
40
- #
41
- SYS_ANSI_VAR_FONT = Wx::SystemFont.new(12)
42
-
43
- # System font.
44
- #
45
- SYS_SYSTEM_FONT = Wx::SystemFont.new(13)
46
-
47
- # Device-dependent font.
48
- #
49
- SYS_DEVICE_DEFAULT_FONT = Wx::SystemFont.new(14)
50
-
51
- # Default font for user interface objects such as menus and dialog boxes.
52
- #
53
- SYS_DEFAULT_GUI_FONT = Wx::SystemFont.new(17)
54
-
55
- end # SystemFont
56
- end
57
- ```
58
-
59
- or the 'wxBorder' enum which is defined in wxRuby as:
60
-
61
- ```ruby
62
- module Wx
63
- # Border flags for {Wx::Window}.
64
- class Border < Wx::Enum
65
-
66
- # This is different from {Wx::Border::BORDER_NONE} as by default the controls do have a border.
67
- #
68
- BORDER_DEFAULT = Wx::Border.new(0)
69
-
70
- #
71
- #
72
- BORDER_NONE = Wx::Border.new(2097152)
73
-
74
- #
75
- #
76
- BORDER_STATIC = Wx::Border.new(16777216)
77
-
78
- #
79
- #
80
- BORDER_SIMPLE = Wx::Border.new(33554432)
81
-
82
- #
83
- #
84
- BORDER_RAISED = Wx::Border.new(67108864)
85
-
86
- #
87
- #
88
- BORDER_SUNKEN = Wx::Border.new(134217728)
89
-
90
- #
91
- #
92
- BORDER_DOUBLE = Wx::Border.new(268435456)
93
-
94
- #
95
- #
96
- BORDER_THEME = Wx::Border.new(268435456)
97
-
98
- #
99
- #
100
- BORDER_MASK = Wx::Border.new(522190848)
101
-
102
- end # Border
103
- end
104
- ```
105
-
106
- Enum instances are interchangeable with integer constants in wxRuby with respect to arithmetic or logical
107
- operations. This make it possible to use enum values to construct integer bitflag arguments like:
108
-
109
- ```ruby
110
- Wx::TextCtrl.new(pane, Wx::ID_ANY, sample_desc.description, style: Wx::TE_MULTILINE|Wx::TE_READONLY|Wx::BORDER_NONE)
111
- ```
112
-
113
- where `Wx::ID_ANY` is a `Wx::StandardID` enum instance passed to provide an integer argument value, `Wx::TE_MULTILINE`
114
- and `Wx::TE_READONLY` are simple integer constants and `Wx::BORDER_NONE` is a `Wx::Border` enum instance.
115
-
116
- In other cases however enum values can provide just the right kind of type safety where explicit enum values are
117
- expected like for example with:
118
-
119
- ```ruby
120
- Wx::Font.new(36, Wx::FONTFAMILY_SWISS, Wx::FONTSTYLE_NORMAL, Wx::FONTWEIGHT_NORMAL)
121
- ```
122
-
123
- where the `Wx::Font` constructor definition is:
124
-
125
- > initialize(pointSize, family, style, weight, underline = false, faceName = `Wx::EMPTY_STRING`, encoding = `Wx::FONTENCODING_DEFAULT`) ⇒ `Wx::Font`
126
-
127
- with the following parameter specification:
128
-
129
- > - pointSize (`Integer`)
130
- > - family (`Wx::FontFamily`)
131
- > - style (`Wx::FontStyle`)
132
- > - weight (`Wx::FontWeight`)
133
- > - underline (`true`, `false`) (defaults to: `false`)
134
- > - faceName (`String`) (defaults to: `Wx::EMPTY_STRING`)
135
- > - encoding (`Wx::FontEncoding`) (defaults to: `Wx::FONTENCODING_DEFAULT`)
136
-
137
- In this case the constructor explicitly expects specific enum value types for *family*, *style* and *weigth* and
138
- providing the integer literal value `74` instead of `Wx::FONTFAMILY_SWISS` (or any other constant representing the same
139
- integer value) will not work (raises an exception) although the integer values for the two are equal.
140
-
141
- As you have probably noticed it is not required to use the full naming for an enum instance constant (like
142
- `Wx::FontFamily::FONTFAMILY_SWISS`). All enum value constants are accessible from the naming scope where the enum class
143
- to which they belong has been declared.
@@ -1,191 +0,0 @@
1
- <!--
2
- # @markup markdown
3
- # @title 5. wxRuby Event Handling
4
- -->
5
-
6
- # 5. wxRuby Event Handling
7
-
8
- ## Introduction
9
-
10
- Event handling is the core of runtime code execution in event based frameworks like wxWidgets which means it needs to
11
- be fully supported by wxRuby. Fortunately it is.<br>
12
- As Ruby is a fully dynamic language though the statically declared event tables typical for wxWidgets application are not.<br>
13
- Instead wxRuby offers a dynamic solution that is just as easy to use and even offers more flexibility in a typical Ruby-way.
14
-
15
- ## Event handlers
16
-
17
- Instead of the `EVT_XXX` event handler declaration macros used in wxWidgets wxRuby provides similarly named event handler
18
- definition methods for each of the known event declarations which are inherited by **all** classes derived from {Wx::
19
- EvtHandler}
20
- (which includes all window classes, the {Wx::App} class and {Wx::Timer} as well as various other classes).<br>
21
-
22
- Naming is (mostly) identical but rubified. So `EVT_MENU` becomes `evt_menu`, `EVT_IDLE` becomes `evt_idle`, `EVT_UPDATE_UI`
23
- becomes `evt_update_ui` etc.
24
-
25
- Like the event handler macros some of these methods require a single (window) id (like `evt_menu`) or a range of of ids
26
- (specified through a first and last id like for `evt_update_ui_range`) and some require only a handler definition (like
27
- `evt_idle`).
28
-
29
- Event handler setup is typically something done during the initialization of an event handler object (like a window) but
30
- this is not required. As all event handlers are assigned dynamically in wxRuby you can setup (some) event handlers at a
31
- later moment. You could also disconnect earlier activated handlers at any time (see {Wx::EvtHandler#disconnect}).
32
-
33
- In case of some frame class `MyForm` including a menu a wxWidgets static event handling table like:
34
-
35
- ```c++
36
- wxBEGIN_EVENT_TABLE(MyForm, wxFrame)
37
- EVT_IDLE(MyForm::OnIdle)
38
- EVT_MOVE(MyForm::OnMove)
39
- EVT_SIZE(MyForm::OnResize)
40
-
41
- EVT_MENU( wxID_ABOUT, MyForm::OnAbout )
42
- EVT_MENU( wxID_EXIT, MyForm::OnCloseClick )
43
- wxEND_EVENT_TABLE()
44
- ```
45
-
46
- could translate to event handler initializations in wxRuby like this:
47
-
48
- ```ruby
49
- class MyForm < Wx::Frame
50
-
51
- def initialize(title)
52
- super(nil, title: title)
53
-
54
- # initialize frame elements
55
- # ...
56
-
57
- # setup event handlers
58
- evt_idle do |evt|
59
- # do something
60
- evt.skip
61
- end
62
- evt_move :on_move
63
-
64
- evt_size method(:on_size)
65
-
66
- evt_menu(Wx::ID_ABOUT, Proc.new { on_about })
67
- evt_menu(Wx::ID_EXIT) { close(false) }
68
- end
69
-
70
- def on_idle(evt)
71
- #...
72
- end
73
-
74
- def on_move(evt)
75
- #...
76
- end
77
-
78
- def on_resize(evt)
79
- #...
80
- end
81
-
82
- def on_about
83
- #...
84
- end
85
-
86
- end
87
- ```
88
-
89
- As you can see there are multiple options for specifying the actual handler. Any event handler definition method will
90
- accept either a `Symbol` (or `String`) specifying a method of the receiver (the event handler instance), a `Proc` object
91
- (or lambda) or a `Method` object.
92
-
93
- Event handler methods are not required to declare the single event object argument. The event handler definition method
94
- will take care of checking and handling method arity.
95
-
96
- ## Custom Events
97
-
98
- Custom event definitions are fully supported in wxRuby including the definition of new event types.
99
-
100
- New event classes can be registered with {Wx::EvtHandler#register_class} which returns the new event type for the event
101
- class like this:
102
-
103
- ```ruby
104
- # A custom type of event associated with a target control. Note that for
105
- # user-defined controls, the associated event should inherit from
106
- # Wx::CommandEvent rather than Wx::Event.
107
- class ProgressUpdateEvent < Wx::CommandEvent
108
- # Create a new unique constant identifier, associate this class
109
- # with events of that identifier and create an event handler definition method 'evt_update_progress'
110
- # for setting up this handler.
111
- EVT_UPDATE_PROGRESS = Wx::EvtHandler.register_class(self, nil, 'evt_update_progress', 0)
112
-
113
- def initialize(value, gauge)
114
- # The constant id is the arg to super
115
- super(EVT_UPDATE_PROGRESS)
116
- # simply use instance variables to store custom event associated data
117
- @value = value
118
- @gauge = gauge
119
- end
120
-
121
- attr_reader :value, :gauge
122
- end
123
- ```
124
-
125
- Check the reference documentation [here](https://mcorino.github.io/wxRuby3/Wx/EvtHandler.html) for more information.
126
-
127
- ## Event processing
128
-
129
- In wxRuby overruling the normal chain of event handling has been limited to being able to override the default
130
- {Wx::EvtHandler#try_before} and {Wx::EvtHandler#try_after} methods. These are the advised interception points for events
131
- when you really need to do this.<br>
132
- Overriding {Wx::EvtHandler#process_event} is not considered to be efficient (or desired)
133
- for wxRuby applications and has therefor been blocked.
134
-
135
- ## Event insertion
136
-
137
- Use of {Wx::EvtHandler#process_event} or {Wx::EvtHandler#queue_event} and {Wx::EvtHandler#add_pending_event} in wxRuby to
138
- trigger event processing of user generated (possibly custom) events is fully supported.
139
-
140
- As with wxWidgets {Wx::EvtHandler#process_event} will trigger immediate processing of the given event, not returning before
141
- this has finished.<br>
142
- {Wx::EvtHandler#queue_event} and {Wx::EvtHandler#add_pending_event} on the other hand will post (append) the given event
143
- to the event queue and return immediately after that is done. The event will than be processed after any other events in
144
- the queue. Unlike in wxWidgets in wxRuby there is no practical difference between `queue_event` and `add_pending_event`.
145
-
146
- ## Asynchronous execution
147
-
148
- In addition to {Wx::EvtHandler#queue_event} and {Wx::EvtHandler#add_pending_event} to trigger asynchronous processing
149
- wxRuby also supports {Wx::EvtHandler#call_after}.
150
-
151
- This method provides the means to trigger asynchronous execution of arbitrary code and because it has been rubified is
152
- easy and powerful to use. Like with event handler definition this method accepts a `Symbol` or `String` (identifying a
153
- method of the receiver), a `Proc` object (or lambda), a `Method` object or a block. Unlike an event handler method no
154
- event object will be passed but rather any arguments passed to the `call_after` method in addition to the 'handler'.
155
-
156
- Given an event handler object `call_after` could be used like:
157
-
158
- ```ruby
159
- # sync call to method of event handler (no args)
160
- evt_handler.call_after :async_method
161
-
162
- # async call of lambda (single arg)
163
- evt_handler.call_after(->(txt) { Wx.log_info(txt) }, "Hello")
164
-
165
- # async call of block
166
- evt_handler.call_after('Call nr. %d', 1) { |fmt, num| Wx.log_info(fmt, num) }
167
- ```
168
-
169
- ## Event life cycles!
170
-
171
- Like in C++ the wxRuby Event objects passed to the event handlers are (in general) references to **temporary** objects
172
- which are only safe to access within the execution scope of the event handler that received the reference.
173
- If you *need* (really?) to store a reference to such an object do so to a cloned version (see {Wx::Event#clone}) and **not**
174
- to the original object otherwise you **will** run into 'Object already deleted' exceptions.
175
-
176
- Only user defined events instantiated in Ruby code (or cloned Event objects) will be subject to Ruby's normal life cycle
177
- rules (GC).
178
- This means that when you instantiate a user defined event and pass it to {Wx::EvtHandler#process_event} it would be possible
179
- to directly store the reference to such an Event object passed to it's event handler. You have to **know** for sure though
180
- (see below). So, in case of doubt (or to be safe) use {Wx::Event#clone}.
181
-
182
- Another 'feature' to be aware of is the fact that when passing an (user instantiated) Event object to {Wx::
183
- EvtHandler#queue_event}
184
- or {Wx::EvtHandler#add_pending_event} the Ruby event instance is unlinked from it's C++ counterpart (or in the case of user
185
- defined events a cloned instance is associated with it's C++ counterpart) before being queued and the C++ side now takes ownership
186
- (and will delete the Event object when handled).
187
- As a result this means that even in the case of a user defined Event object any event handler triggered by a asynchronously
188
- processed event will be handling a temporary Event object.
189
- Additionally this also means that any Event object passed to {Wx::EvtHandler#queue_event} or {Wx::
190
- EvtHandler#add_pending_event}
191
- is essentially invalidated after these methods return and should not be referenced anymore.
@@ -1,62 +0,0 @@
1
- <!--
2
- # @markup markdown
3
- # @title 6. wxRuby geometry classes
4
- -->
5
-
6
- # 6. wxRuby Geometry classes
7
-
8
- ## Size (Wx::Size) and position (Wx::Point and Wx::RealPoint)
9
-
10
- The wxWidgets API has a lot methods that require either `wxSize`, `wxPoint` or both type of value as argument. Although
11
- this can be specified in C++ still relatively concise like
12
- ```ruby
13
- new wxFrame(nullptr, -1, "title", wxPoint(0,0), wxSize(500,400))
14
- ```
15
- in Ruby this expands to the more verbose
16
- ```ruby
17
- Wx::Frame.new(nil, -1, 'title', Wx::Point.new(0,0), Wx::Size.new(500,400))
18
- ```
19
- which starts to feel awkward to specify what are in essence just pairs of integers.
20
-
21
- To provide a simpler, more compact and more Ruby-like, alternative the wxRuby API therefor supports specifying arrays
22
- of integer (or float in case of {Wx::RealPoint}) pairs in (almost) all cases where {Wx::Size} or {Wx::Point}
23
- (or {Wx::RealPoint}) is expected. So the following code is equivalent to the previous code:
24
- ```ruby
25
- Wx::Frame.new(nil, -1, 'title', [0,0], [500,400])
26
- ```
27
-
28
- In addition {Wx::Size}, {Wx::Point} and {Wx::RealPoint} support parallel assignment semantics such that you can write code like
29
- ```ruby
30
- win.paint do | dc |
31
- # ...
32
- x, y = win.get_position
33
- dc.draw_circle(x, y, 4)
34
- dc.draw_rectangle(x-4, y-4, 8, 8)
35
- end
36
- ```
37
- instead of
38
- ```ruby
39
- win.paint do | dc |
40
- # ...
41
- pos = win.get_position
42
- dc.draw_circle(pos.x, pos.y, 4)
43
- dc.draw_rectangle(pos.x-4, pos.y-4, 8, 8)
44
- end
45
- ```
46
-
47
- Instances of these classes can also be converted (back) to arrays with their `#to_ary` methods.
48
-
49
- Lastly wxRuby also extends the standard Ruby Array class with conversion methods to explicitly convert
50
- arrays to {Wx::Size}, {Wx::Point} or {Wx::RealPoint}; respectively the `#to_size`, `#to_point` and `#to_real_point`
51
- methods.
52
-
53
- ## Areas (Wx::Rect)
54
-
55
- Like {Wx::Size} and {Wx::Point} wxRuby supports parallel assignment for {Wx::Rect} such that you can write code like
56
- ```ruby
57
- x, y, width, height = win.get_client_rect
58
- ```
59
-
60
- Providing arrays of integers as alternative for `Wx::Rect` arguments is not supported as specifying `[0, 0, 20, 40]` is
61
- ambiguous. This could either mean a rectangle with origin `x=0,y=0` and size `width=20,height=40` (`Wx::Rect.new(0,0,20,40)`)
62
- or a rectangle from origin top left `x=0,y=0` to point bottom right `x=20,y=40` (`Wx::Rect.new(Wx::Point.new(0,0), Wx::Point.new(20,40))`).
@@ -1,52 +0,0 @@
1
- <!--
2
- # @markup markdown
3
- # @title 7. wxRuby Colour and Font
4
- -->
5
-
6
- # 6. wxRuby Colour and Font
7
-
8
- ## Introduction
9
-
10
- The wxWidgets API makes use of typical C++ features to support automatic conversion of certain types providing
11
- user friendly options for argument specifications. This way for example a developer does not need to explicitly
12
- declare a colour object construction where a colour instance value is expected but rather can specify a simple string
13
- constant like:
14
-
15
- ```C++
16
- wxPen pen;
17
- pen.SetColour("CYAN"); // instead of pen.SetColour(wxColour("CYAN"));
18
- ```
19
-
20
- For the wxRuby API similar support has been achieved for various much used argument types.
21
-
22
- ## Colour
23
-
24
- Wherever a {Wx::Colour} object is expected as an argument wxRuby supports the specification of `String` or `Symbol`
25
- values as a developer friendly alternative. This way the following code is equivalent:
26
-
27
- ```ruby
28
- pen = Wx::Pen.new
29
- pen.set_colour(Wx::Colour.new("CYAN"))
30
-
31
- pen = Wx::Pen.new
32
- pen.set_colour("CYAN")
33
-
34
- pen = Wx::Pen.new
35
- pen.set_colour(:CYAN)
36
- ```
37
-
38
- ## Font
39
-
40
- Wherever a {Wx::Font} object is expected as an argument wxRuby supports the specification of a {Wx::FontInfo} object.
41
- This way the following code is equivalent:
42
-
43
- ```ruby
44
- title = Wx::StaticText.new(self, -1, "Title")
45
- title.set_font(Wx::Font.new(18, Wx::FontFamily::FONTFAMILY_SWISS, Wx::FontStyle::FONTSTYLE_NORMAL, Wx::FontWeight::FONTWEIGHT_BOLD))
46
-
47
- title = Wx::StaticText.new(self, -1, "Title")
48
- title.set_font(Wx::FontInfo.new(18)
49
- .family(Wx::FontFamily::FONTFAMILY_SWISS)
50
- .style(Wx::FontStyle::FONTSTYLE_NORMAL)
51
- .bold())
52
- ```
@@ -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.