iup-ffi 0.12.0

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 (64) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.txt +21 -0
  3. data/README.rdoc +348 -0
  4. data/lib/iup-ffi-plain.rb +9 -0
  5. data/lib/iup-ffi.rb +76 -0
  6. data/lib/plain/iupcdlib.rb +107 -0
  7. data/lib/plain/iupcontrolslib.rb +24 -0
  8. data/lib/plain/iupimglib.rb +14 -0
  9. data/lib/plain/iupimlib.rb +16 -0
  10. data/lib/plain/iuplib.rb +209 -0
  11. data/lib/plain/scintilla-lib.rb +15 -0
  12. data/lib/wrapped/attribute-builders.rb +105 -0
  13. data/lib/wrapped/attribute-reference.rb +27 -0
  14. data/lib/wrapped/background-box.rb +33 -0
  15. data/lib/wrapped/button.rb +108 -0
  16. data/lib/wrapped/callback-setter.rb +78 -0
  17. data/lib/wrapped/canvas.rb +467 -0
  18. data/lib/wrapped/colourbar.rb +94 -0
  19. data/lib/wrapped/colourdialog.rb +63 -0
  20. data/lib/wrapped/common-attributes.rb +64 -0
  21. data/lib/wrapped/constants.rb +953 -0
  22. data/lib/wrapped/dial.rb +87 -0
  23. data/lib/wrapped/dialog.rb +176 -0
  24. data/lib/wrapped/dialogs.rb +106 -0
  25. data/lib/wrapped/drag-drop-attributes.rb +57 -0
  26. data/lib/wrapped/dynamic-fill-methods.rb +27 -0
  27. data/lib/wrapped/expander.rb +65 -0
  28. data/lib/wrapped/filedialog.rb +93 -0
  29. data/lib/wrapped/fill.rb +26 -0
  30. data/lib/wrapped/fontdialog.rb +42 -0
  31. data/lib/wrapped/frame.rb +47 -0
  32. data/lib/wrapped/gridbox.rb +94 -0
  33. data/lib/wrapped/hbox.rb +49 -0
  34. data/lib/wrapped/image-attributes.rb +27 -0
  35. data/lib/wrapped/image.rb +118 -0
  36. data/lib/wrapped/internal-drag-drop-attributes.rb +21 -0
  37. data/lib/wrapped/iup-global.rb +51 -0
  38. data/lib/wrapped/label.rb +98 -0
  39. data/lib/wrapped/link.rb +59 -0
  40. data/lib/wrapped/list.rb +353 -0
  41. data/lib/wrapped/matrix.rb +233 -0
  42. data/lib/wrapped/menu.rb +50 -0
  43. data/lib/wrapped/menuitem.rb +80 -0
  44. data/lib/wrapped/messagedialog.rb +51 -0
  45. data/lib/wrapped/progressbar.rb +48 -0
  46. data/lib/wrapped/progressdialog.rb +111 -0
  47. data/lib/wrapped/radio.rb +43 -0
  48. data/lib/wrapped/scintilla.rb +277 -0
  49. data/lib/wrapped/scrollbar-attributes.rb +141 -0
  50. data/lib/wrapped/scrollbox.rb +147 -0
  51. data/lib/wrapped/separator.rb +11 -0
  52. data/lib/wrapped/splitbox.rb +48 -0
  53. data/lib/wrapped/stretchbox.rb +42 -0
  54. data/lib/wrapped/submenu.rb +34 -0
  55. data/lib/wrapped/tabs.rb +149 -0
  56. data/lib/wrapped/text.rb +225 -0
  57. data/lib/wrapped/timer.rb +42 -0
  58. data/lib/wrapped/toggle.rb +98 -0
  59. data/lib/wrapped/tree.rb +465 -0
  60. data/lib/wrapped/val.rb +97 -0
  61. data/lib/wrapped/vbox.rb +51 -0
  62. data/lib/wrapped/widget.rb +137 -0
  63. data/lib/wrapped/zbox.rb +54 -0
  64. metadata +124 -0
@@ -0,0 +1,353 @@
1
+ module Iup
2
+
3
+ # A List control presents a list of options to the user.
4
+ # The list may be visible, or a hidden, drop-down list.
5
+ # Optionally, items may be editable.
6
+ #
7
+ # Note that lists are indexed from 1.
8
+ #
9
+ # == Attributes
10
+ #
11
+ # autohide:: If set, scrollbars are only shown if necessary, values 'yes' / 'no'.
12
+ # canfocus:: If set, the control can gain focus, values 'yes' / 'no'.
13
+ # count:: <b>read-only</b> returns the number of items in the list.
14
+ # dragdroplist:: If yes, enables drag and drop between lists: 'yes' / 'no'.
15
+ # dropdown:: 'yes' / 'no', if set, only the selected item is visible.
16
+ # editbox:: 'yes' / 'no', if set adds an editable box to the list.
17
+ # expand:: Allows list to fill available space in indicated direction.
18
+ # Values 'no' / 'horizontal' / 'vertical' / 'yes'.
19
+ # multiple:: If set, allows selection of multiple items: values 'yes' / 'no'.
20
+ # Only available if editbox = dropdown = no.
21
+ # position:: <b>read-only</b> returns position in pixels within client window
22
+ # as "x,y".
23
+ # rastersize:: Size of the list, in pixels, value as "widthxheight".
24
+ # removeitem:: n / 'all', removes item n or all items from the list.
25
+ # screenposition:: <b>read-only</b> returns position in pixels on screen
26
+ # as "x,y".
27
+ # showdragdrop:: If set, enables internal drag/drop: values 'yes' / 'no'.
28
+ # showdropdown:: <b>write-only</b> Shows the dropdown list, if dropdown=yes.
29
+ # sort:: Forces items to be sorted alphabetically.
30
+ # Insert/append operations will ignore the index number.
31
+ # spacing:: Space between items, value as a number.
32
+ # tip:: Tooltip string.
33
+ # visiblecolumns:: The minimum number of visible columns, defaults to 5.
34
+ # visiblelines:: The minimum number of visible lines, when dropdown=no.
35
+ #
36
+ # == Attributes (with editbox set)
37
+ #
38
+ # append:: <b>write-only</b> appends given string to end of text.
39
+ # caret:: 'col', in single-line mode, or 'lin,col' in multi-line mode.
40
+ # caretpos:: Index of character of the insertion point.
41
+ # clipboard:: 'clear' / 'copy' / 'cut' / 'paste', <b>write-only</b> access the
42
+ # clipboard with the current selection.
43
+ # insert:: <b>write-only</b> Places a given string at current caret position,
44
+ # overwriting any current selection.
45
+ # mask:: Defines a mask to filter text input.
46
+ # nc:: Maximum number of characters allowed for keyboard input (0 allows an indefinite number).
47
+ # padding:: Margin in x and y directions, value as "mxn".
48
+ # readonly:: If set, prevents the user changing contents: values 'yes' / 'no'.
49
+ # scrollto:: <b>write-only</b>
50
+ # 'col' Scrolls to make given column number visible,
51
+ # in single-line mode.
52
+ # 'lin/col' Scrolls to make line and column number visible,
53
+ # in multi-line mode.
54
+ # scrolltopos:: <b>write-only</b> Scrolls to make character 'number' visible.
55
+ # selectedtext:: Reads or overwrites the current selection.
56
+ # Does nothing if no text is selected.
57
+ # selection:: Selects text as 'col1:col2' (single-line) / 'lin1,col1:lin2,col2' (multi-line) / 'all' / 'none'.
58
+ # selectionpos:: Selects text between character positions: 'pos1:pos2' / 'all' / 'none'.
59
+ #
60
+ class List < Widget
61
+ include DragDropAttributes
62
+ include InternalDragDropAttributes
63
+
64
+ # Creates an instance of the list.
65
+ # All options are set through the _block_.
66
+ def initialize &block
67
+ @handle = IupLib.IupList nil
68
+
69
+ # run any provided block on instance, to set up further attributes
70
+ self.instance_eval &block if block_given?
71
+ end
72
+
73
+ # -- attributes
74
+
75
+ define_writeonly :append
76
+
77
+ # Adds given item to end of list.
78
+ # text:: required text label
79
+ # image:: optional image reference / name.
80
+ def appenditem text, image=nil
81
+ IupLib.IupSetAttribute 'APPENDITEM', text
82
+ case image
83
+ when NilClass
84
+ ;
85
+ when String
86
+ IupLib.SetAttibute @handle, "IMAGE#{count}", image
87
+ when ImageWidget
88
+ image_name = IupLib.IupGetName(name).first
89
+ if image_name.nil? or image_name.empty?
90
+ image_name = SecureRandom.uuid
91
+ image.assign_handle image_name
92
+ end
93
+ IupLib.IupSetAttribute @handle, "IMAGE#{count}", image_name
94
+ end
95
+ end
96
+
97
+ define_attribute :autohide
98
+ define_attribute :canfocus
99
+ define_attribute :caret
100
+ define_attribute :caretpos
101
+ define_attribute :clipboard
102
+ define_readonly :count
103
+ define_attribute :dragdroplist
104
+ define_attribute :dropdown
105
+ define_attribute :editbox
106
+ define_attribute :expand
107
+ define_writeonly :insert
108
+
109
+ # insert item at given index
110
+ # index:: index to add item (1-indexed)
111
+ # text:: required text label
112
+ # image:: optional image reference / name.
113
+ def insertitem index, text, image=nil
114
+ IupLib.IupSetAttribute @handle, "INSERTITEM#{index}", text
115
+ case image
116
+ when NilClass
117
+ ;
118
+ when String
119
+ IupLib.IupSetAttibute @handle, "IMAGE#{index}", image
120
+ when ImageWidget
121
+ image_name = IupLib.IupGetName(name).first
122
+ if image_name.nil? or image_name.empty?
123
+ image_name = SecureRandom.uuid
124
+ image.assign_handle image_name
125
+ end
126
+ IupLib.IupSetAttribute @handle, "IMAGE#{index}", image_name
127
+ end
128
+ end
129
+
130
+ # If text / image are set, adds a new item to the list.
131
+ # Otherwise, retrieves item at the given index.
132
+ # index:: index to item (1-indexed)
133
+ # text:: optional text label
134
+ # image:: optional image reference / name.
135
+ def item index, text=nil, image=nil
136
+ if text.nil?
137
+ IupLib.IupGetAttribute(@handle, index.to_s).first
138
+ else
139
+ IupLib.IupSetAttribute @handle, index.to_s, text
140
+ case image
141
+ when NilClass
142
+ ;
143
+ when String
144
+ IupLib.IupSetAttribute @handle, "IMAGE#{index}", image
145
+ when ImageWidget
146
+ image_name = IupLib.IupGetName(image.handle).first
147
+ if image_name.nil? or image_name.empty?
148
+ image_name = SecureRandom.uuid
149
+ image.assign_handle image_name
150
+ end
151
+ IupLib.IupSetAttribute @handle, "IMAGE#{index}", image_name
152
+ end
153
+ text
154
+ end
155
+ end
156
+
157
+ define_attribute :mask
158
+ define_attribute :multiple
159
+ define_attribute :nc
160
+ define_attribute :padding
161
+ define_readonly :position
162
+ define_attribute :rastersize
163
+ define_attribute :readonly
164
+ define_attribute :removeitem
165
+ define_readonly :screenposition
166
+ define_attribute :scrollbar
167
+ define_attribute :scrollto
168
+ define_attribute :scrolltopos
169
+ define_attribute :selectedtext
170
+ define_attribute :selection
171
+ define_attribute :selectionpos
172
+ define_attribute :showdragdrop
173
+ define_attribute :showdropdown
174
+ define_attribute :showimage
175
+ define_attribute :sort
176
+ define_attribute :spacing
177
+ define_attribute :tip
178
+
179
+ # If val is:
180
+ # string:: when editbox is set, sets/gets the text entered by user.
181
+ # nil or an integer:: when dropdown = 'yes' or multiple = 'no',
182
+ # sets/gets index of selected items.
183
+ #
184
+ # When list is multiple, val is converted to/from array of indices from/to +/-
185
+ #
186
+ def value val=nil
187
+ if val.nil?
188
+ item_str = IupLib.IupGetAttribute(@handle, 'VALUE').first
189
+ if multiple == 'YES'
190
+ result = []
191
+ item_str.split('').each_with_index do |item, index|
192
+ result << index+1 if item == '+'
193
+ end
194
+ return result
195
+ else
196
+ return item_str
197
+ end
198
+ else
199
+ if multiple == 'YES'
200
+ result = ""
201
+ count.to_i.times do |i|
202
+ if val.include?(i+1)
203
+ result << '+'
204
+ else
205
+ result << '-'
206
+ end
207
+ end
208
+ IupLib.IupSetAttribute @handle, 'VALUE', result
209
+ else
210
+ IupLib.IupSetAttribute @handle, 'VALUE', val.to_s
211
+ end
212
+ end
213
+ end
214
+
215
+ define_attribute :visiblecolumns
216
+ define_attribute :visiblelines
217
+
218
+ # -- callbacks
219
+
220
+ # Action generated when the state of an item in the list is changed.
221
+ # action takes a 3-argument callback: text, item, state
222
+ def action callback
223
+ unless callback.arity == 3
224
+ raise ArgumentError, 'action callback must take 3 arguments: (text, item, state)'
225
+ end
226
+ cb = Proc.new do |ih, text, item, state|
227
+ callback.call text, item, state
228
+ end
229
+ define_callback cb, 'ACTION', :sii_i
230
+ end
231
+
232
+ include ButtonCallback
233
+
234
+ # Action generated when the caret/cursor position is changed. Valid only when EDITBOX=YES.
235
+ # caret_cb takes a callback which accepts 3 arguments (line, column, position) of caret
236
+ def caret_cb callback
237
+ unless callback.arity == 3
238
+ raise ArgumentError, 'caret_cb callback must take 3 arguments: (line, column, position)'
239
+ end
240
+ cb = Proc.new do |ih, lin, col, pos|
241
+ callback.call lin, col, pos
242
+ end
243
+ define_callback cb, 'CARET_CB', :iii_i
244
+ end
245
+
246
+ # Action generated when the user double click an item. Called only when DROPDOWN=NO.
247
+ # dblclick_cb takes a callback which accepts 2 arguments (index, text)
248
+ def dblclick_cb callback
249
+ unless callback.arity == 2
250
+ raise ArgumentError, 'dblclick_cb callback must take 2 arguments: index, text'
251
+ end
252
+ cb = Proc.new do |ih, index, text|
253
+ callback.call index, text
254
+ end
255
+ define_callback cb, 'DBLCLICK_CB', :is_i
256
+ end
257
+
258
+ # Action generated when an internal drag and drop is executed. Only active if SHOWDRAGDROP=YES.
259
+ # dragdrop_cb takes a callback which accepts 4 arguments (drag_id, drop_id, isshift, iscontrol)
260
+ # drag_id:: is an integer index of dragged item
261
+ # drop_id:: is an integer index of drop location
262
+ # isshift:: boolean flag for if shift key held
263
+ # iscontrol:: boolean flag for if control key held
264
+ # callback should return Iup::CONTINUE for item to be moved/copied.
265
+ def dragdrop_cb callback
266
+ unless callback.arity == 4
267
+ raise ArgumentError, 'dragdrop_cb callback must take 4 arguments: (drag_id, drop_id, isshift, iscontrol)'
268
+ end
269
+ cb = Proc.new do |ih, drag_id, drop_id, isshift, iscontrol|
270
+ callback.call drag_id.to_i, drop_id.to_i, (isshift != 0), (iscontrol != 0)
271
+ end
272
+ define_callback cb, 'DRAGDROP_CB', :iiii_i
273
+ end
274
+
275
+ # Action generated when the list of a dropdown is shown or hidden. Called only when DROPDOWN=YES.
276
+ # dropdown_cb takes a 1-argument callback, shown is a boolean, true if dropdown visible.
277
+ # dropdown_cb is only called if dropdown=yes
278
+ def dropdown_cb callback
279
+ unless callback.arity == 1
280
+ raise ArgumentError, 'dropdown_cb callback must take 1 argument, shown'
281
+ end
282
+ cb = Proc.new do |ih, state|
283
+ callback.call (state == 1)
284
+ end
285
+ define_callback cb, 'DROPDOWN_CB', :i_i
286
+ end
287
+
288
+ # Action generated when the text in the text box is manually changed by the user, but
289
+ # before its value is actually updated. Valid only when EDITBOX=YES.
290
+ # edit_cb takes a 2-argument callback, the character typed, and the new text value
291
+ def edit_cb callback
292
+ unless callback.arity == 2
293
+ raise ArgumentError, 'edit_cb callback must take 2 arguments: (character, new_value)'
294
+ end
295
+ cb = Proc.new do |ih, c, text|
296
+ callback.call c, text
297
+ end
298
+ define_callback cb, 'EDIT_CB', :is_i
299
+ end
300
+
301
+ # Action generated when the mouse is moved.
302
+ # Callback takes 3 arguments: (x, y, state)
303
+ # x:: x position of mouse
304
+ # y:: y position of mouse
305
+ # state:: status of mouse buttons and certain keyboard keys at the moment the event was generated.
306
+ #--
307
+ # TODO: include functions, as in button_cb
308
+ #
309
+ def motion_cb callback
310
+ unless callback.arity == 3
311
+ raise ArgumentError, 'motion_cb callback must take 3 arguments: (x, y, state)'
312
+ end
313
+ cb = Proc.new do |ih, x, y, state|
314
+ callback.call x, y, state
315
+ end
316
+ define_callback cb, 'MOTION_CB', :iis_i
317
+ end
318
+
319
+ # Action generated when the state of an item in the multiple selection list is changed. But
320
+ # it is called only when the interaction is over.
321
+ # callback called with two arrays:
322
+ # * indices of selected items
323
+ # * indices of deselected items
324
+ def multiselect_cb callback
325
+ unless callback.arity == 2
326
+ raise ArgumentError, 'multiselect_cb callback must take 2 arguments, the array of selected and array of deselected items'
327
+ end
328
+ cb = Proc.new do |ih, val_ptr|
329
+ val = FFI::Pointer.new(val_ptr).read_string
330
+ selected = []
331
+ deselected = []
332
+ val.split('').each_with_index do |item, index|
333
+ selected << index+1 if item == '+'
334
+ deselected << index+1 if item == '-'
335
+ end
336
+ callback.call selected, deselected
337
+ end
338
+ define_callback cb, 'MULTISELECT_CB', :s_i
339
+ end
340
+
341
+ # Called after the value was interactively changed by the user. Called when
342
+ # the selection is changed or when the text is edited.
343
+ def valuechanged_cb callback
344
+ unless callback.arity.zero?
345
+ raise ArgumentError, 'valuechanged_cb callback must take 0 arguments'
346
+ end
347
+ cb = Proc.new do |ih|
348
+ callback.call
349
+ end
350
+ define_callback cb, 'VALUECHANGED_CB', :plain
351
+ end
352
+ end
353
+ end
@@ -0,0 +1,233 @@
1
+ module Iup
2
+
3
+ # Matrix
4
+ #
5
+ class Matrix < Widget
6
+ def initialize &block
7
+ open_controls
8
+ @handle = ControlsLib.IupMatrix ""
9
+
10
+ # run any provided block on instance, to set up further attributes
11
+ self.instance_eval &block if block_given?
12
+ end
13
+
14
+ # get value of cell
15
+ def get lin, col
16
+ IupLib.IupGetAttribute(@handle, "#{lin}:#{col}").first
17
+ end
18
+
19
+ # set value of cell
20
+ def set lin, col, value
21
+ IupLib.IupSetAttribute @handle, "#{lin}:#{col}", value
22
+ end
23
+
24
+ # -- attributes
25
+
26
+ # general attributes
27
+
28
+ define_attribute :cursor
29
+ define_attribute :dropimage
30
+ define_attribute :focuscell
31
+ define_attribute :flat
32
+ define_attribute :flatscrollbar
33
+ define_attribute :hidefocus
34
+ define_attribute :hiddentextmarks
35
+ define_attribute :hlcolor
36
+ define_attribute :origin
37
+ define_attribute :originoffset
38
+ define_attribute :readonly
39
+ define_attribute :showfillvalue
40
+ define_attribute :togglecentered
41
+ define_attribute :toggleimageon
42
+ define_attribute :toggleimageoff
43
+ define_attribute :typecolorinactive
44
+
45
+ define_attribute :expand
46
+ define_readonly :position
47
+ define_attribute :rastersize
48
+ define_readonly :screenposition
49
+ define_attribute :tip
50
+
51
+ # cell attributes (no redraw)
52
+
53
+ def bgcolor_column col, colour
54
+ IupLib.IupSetAttribute @handle, "BGCOLOR*:#{col}", colour
55
+ end
56
+ def bgcolor_line lin, colour
57
+ IupLib.IupSetAttribute @handle, "BGCOLOR#{lin}:*", colour
58
+ end
59
+ def bgcolor_cell col, lin, colour
60
+ IupLib.IupSetAttribute @handle, "BGCOLOR#{lin}:#{col}", colour
61
+ end
62
+
63
+ # size attributes
64
+ define_attribute :limitexpand
65
+ define_attribute :resizematrix
66
+ define_attribute :resizedrag
67
+ define_attribute :usetitlesize
68
+
69
+ # column size attributes
70
+
71
+ # RASTERWIDTHn, defines column width in pixels
72
+ def rasterwidth n, num_pixels
73
+ IupLib.IupSetAttribute @handle, "RASTERWIDTH#{n}", num_pixels.to_s
74
+ end
75
+
76
+ # WIDTHn, defines column width in SIZE units
77
+ def width n, size
78
+ IupLib.IupSetAttribute @handle, "WIDTH#{n}", size.to_s
79
+ end
80
+
81
+ define_attribute :widthdef
82
+
83
+ # MINCOLWIDTHn, defines column width in SIZE units
84
+ def mincolwidth n, size
85
+ IupLib.IupSetAttribute @handle, "MINCOLWIDTH#{n}", size.to_s
86
+ end
87
+
88
+ # line size attributes
89
+
90
+ # HEIGHTn, defines line height in SIZE units
91
+ def height n, size
92
+ IupLib.IupSetAttribute @handle, "HEIGHT#{n}", size.to_s
93
+ end
94
+
95
+ define_attribute :heightdef
96
+
97
+ # RASTERHEIGHTn, defines line height in pixels
98
+ def rasterheight n, num_pixels
99
+ IupLib.IupSetAttribute @handle, "RASTERHEIGHT#{n}", num_pixels.to_s
100
+ end
101
+
102
+ # number of cells attributes
103
+ define_writeonly :addcol
104
+ define_writeonly :addlin
105
+ define_writeonly :delcol
106
+ define_writeonly :dellin
107
+ define_attribute :numcol
108
+ define_attribute :numcol_visible
109
+ define_attribute :numcol_noscroll
110
+ define_attribute :numlin
111
+ define_attribute :numlin_visible
112
+ define_attribute :numlin_noscroll
113
+ define_attribute :noscrollastitle
114
+
115
+ # action attributes
116
+
117
+ def redraw # TODO - values
118
+ IupLib.IupSetAttribute @handle, 'redraw', 'all'
119
+ end
120
+
121
+ define_writeonly :fittosize
122
+
123
+ # canvas attributes
124
+ define_attribute :border
125
+ define_attribute :scrollbar
126
+
127
+ # -- callbacks
128
+
129
+ # Action generated when a keyboard event occurs
130
+ # returns IUP_DEFAULT to validate the key, IUP_IGNORE to ignore,
131
+ # IUP_CONTINUE forwards the key, or identifier of the key to be treated
132
+ def action_cb callback
133
+ unless callback.arity == 5
134
+ raise ArgumentError, 'action_cb callback must take 5 arguments: (key, lin, col, edition, value)'
135
+ end
136
+ cb = Proc.new do |ih, key, lin, col, edition, value|
137
+ callback.call key, lin, col, edition, value
138
+ end
139
+ define_callback cb, 'ACTION_CB', :i_s
140
+ end
141
+
142
+ # Action generated when any mouse button is pressed over a cell.
143
+ def click_cb callback
144
+ unless callback.arity == 3
145
+ raise ArgumentError, 'click_cb callback must take 3 arguments: (lin, col, status)'
146
+ end
147
+ cb = Proc.new do |ih, lin, col, status|
148
+ callback.call lin, col, status
149
+ end
150
+ define_callback cb, 'CLICK_CB', :i_s
151
+ end
152
+
153
+ # Action generated when a column is interactively resized.
154
+ def colresize_cb callback
155
+ unless callback.arity == 1
156
+ raise ArgumentError, 'colresize_cb callback must take 1 argument: (col)'
157
+ end
158
+ cb = Proc.new do |ih, col|
159
+ callback.call col
160
+ end
161
+ define_callback cb, 'COLRESIZE_CB', :i_s
162
+ end
163
+
164
+ # Action generated when any mouse button is released over a cell.
165
+ def release_cb callback
166
+ unless callback.arity == 3
167
+ raise ArgumentError, 'release_cb callback must take 3 arguments: (lin, col, status)'
168
+ end
169
+ cb = Proc.new do |ih, lin, col, status|
170
+ callback.call lin, col, status
171
+ end
172
+ define_callback cb, 'RELEASE_CB', :i_s
173
+ end
174
+
175
+ # Action generated after the element size has been updated, but
176
+ # before the cells are refreshed.
177
+ def resizematrix_cb callback
178
+ unless callback.arity == 2
179
+ raise ArgumentError, 'resizematrix_cb callback must take 2 arguments: (width, height)'
180
+ end
181
+ cb = Proc.new do |ih, width, height|
182
+ callback.call width, height
183
+ end
184
+ define_callback cb, 'RESIZEMATRIX_CB', :i_s
185
+ end
186
+
187
+ # Action generated when mouse has moved over the matrix.
188
+ def mousemove_cb callback
189
+ unless callback.arity == 2
190
+ raise ArgumentError, 'mousemove_cb callback must take 2 arguments: (lin, col)'
191
+ end
192
+ cb = Proc.new do |ih, lin, col|
193
+ callback.call lin, col
194
+ end
195
+ define_callback cb, 'MOUSEMOVE_CB', :i_s
196
+ end
197
+
198
+ # Action generated when matrix cell is selected, matrix gets focus etc.
199
+ def enteritem_cb callback
200
+ unless callback.arity == 2
201
+ raise ArgumentError, 'enteritem_cb callback must take 2 arguments: (lin, col)'
202
+ end
203
+ cb = Proc.new do |ih, lin, col|
204
+ callback.call lin, col
205
+ end
206
+ define_callback cb, 'ENTERITEM_CB', :i_s
207
+ end
208
+
209
+ # Action generated when cell is no longer current cell.
210
+ def leaveitem_cb callback
211
+ unless callback.arity == 2
212
+ raise ArgumentError, 'leaveitem_cb callback must take 2 arguments: (lin, col)'
213
+ end
214
+ cb = Proc.new do |ih, lin, col|
215
+ callback.call lin, col
216
+ end
217
+ define_callback cb, 'LEAVEITEM_CB', :i_s
218
+ end
219
+
220
+ # Action generated when matrix is scrolled.
221
+ def scrolltop_cb callback
222
+ unless callback.arity == 2
223
+ raise ArgumentError, 'scrolltop_cb callback must take 2 arguments: (lin, col)'
224
+ end
225
+ cb = Proc.new do |ih, lin, col|
226
+ callback.call lin, col
227
+ end
228
+ define_callback cb, 'SCROLLTOP_CB', :i_s
229
+ end
230
+
231
+
232
+ end
233
+ end
@@ -0,0 +1,50 @@
1
+ module Iup
2
+
3
+ # A Menu is a collection of menu items, submenus, and separators.
4
+ #
5
+ # For example, the following menu has the items: Open, Save, ----, Undo, Exit
6
+ # The Undo item is greyed out as it is inactive, and the Exit item, when clicked,
7
+ # will close the dialog. Notice how the File menu, which contains these items,
8
+ # is a submenu of the main menu.
9
+ #
10
+ # mainloop do
11
+ # item_open = MenuItem.new 'Open'
12
+ # item_save = MenuItem.new 'Save'
13
+ # item_undo = MenuItem.new 'Undo' do
14
+ # active 'NO'
15
+ # end
16
+ # item_exit = MenuItem.new 'Exit', ->{ CLOSE }
17
+ # file_menu = Menu.new item_open, item_save, Separator.new, item_undo, item_exit
18
+ # menu = Menu.new SubMenu.new('File', file_menu)
19
+ #
20
+ # Dialog.new Canvas.new do
21
+ # menu menu
22
+ # size '200x100'
23
+ # title 'Menu Example'
24
+ # end.show
25
+ # end
26
+ #
27
+ # == Attributes
28
+ #
29
+ # radio:: If set, makes children act as a radio group. Values 'yes' / 'no'.
30
+ # wid:: <b>read-only</b> Native widget identifier.
31
+ #
32
+ class Menu < Widget
33
+
34
+ # Creates instance of a menu.
35
+ #
36
+ # *widgets:: one or more menu items, sub menus or separators.
37
+ # block:: optional block to set up menu's attributes.
38
+ def initialize *widgets, &block
39
+ @handle = IupLib.IupMenu *widget_list(widgets)
40
+
41
+ # run any provided block on instance, to set up further attributes
42
+ self.instance_eval &block if block_given?
43
+ end
44
+
45
+ # -- attributes
46
+
47
+ define_attribute :radio
48
+ define_readonly :wid
49
+ end
50
+ end