iup-ffi 0.13.0-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENCE.md +21 -0
- data/README.md +139 -0
- data/lib/iup-ffi-plain.rb +51 -0
- data/lib/iup-ffi.rb +70 -0
- data/lib/library/linux/libcd.so +0 -0
- data/lib/library/linux/libim.so +0 -0
- data/lib/library/linux/libiup.so +0 -0
- data/lib/library/linux/libiup_scintilla.so +0 -0
- data/lib/library/linux/libiupcd.so +0 -0
- data/lib/library/linux/libiupcontrols.so +0 -0
- data/lib/library/linux/libiupim.so +0 -0
- data/lib/library/linux/libiupimglib.so +0 -0
- data/lib/plain/iupcdlib.rb +158 -0
- data/lib/plain/iupcontrolslib.rb +28 -0
- data/lib/plain/iupimglib.rb +15 -0
- data/lib/plain/iupimlib.rb +18 -0
- data/lib/plain/iuplib.rb +354 -0
- data/lib/plain/scintilla-lib.rb +17 -0
- data/lib/wrapped/attribute-builders.rb +93 -0
- data/lib/wrapped/attribute-reference.rb +27 -0
- data/lib/wrapped/background-box.rb +37 -0
- data/lib/wrapped/button.rb +152 -0
- data/lib/wrapped/callback-setter.rb +78 -0
- data/lib/wrapped/canvas.rb +698 -0
- data/lib/wrapped/colorbar.rb +212 -0
- data/lib/wrapped/colordialog.rb +121 -0
- data/lib/wrapped/common-attributes.rb +34 -0
- data/lib/wrapped/constants.rb +504 -0
- data/lib/wrapped/dial.rb +129 -0
- data/lib/wrapped/dialog.rb +309 -0
- data/lib/wrapped/drag-drop-attributes.rb +98 -0
- data/lib/wrapped/dynamic-fill-methods.rb +22 -0
- data/lib/wrapped/expander.rb +128 -0
- data/lib/wrapped/filedialog.rb +168 -0
- data/lib/wrapped/fill.rb +29 -0
- data/lib/wrapped/fontdialog.rb +71 -0
- data/lib/wrapped/frame.rb +70 -0
- data/lib/wrapped/gridbox.rb +188 -0
- data/lib/wrapped/hbox.rb +90 -0
- data/lib/wrapped/image-attributes.rb +58 -0
- data/lib/wrapped/image.rb +178 -0
- data/lib/wrapped/iup-global.rb +46 -0
- data/lib/wrapped/label.rb +110 -0
- data/lib/wrapped/link.rb +54 -0
- data/lib/wrapped/list.rb +567 -0
- data/lib/wrapped/matrix.rb +575 -0
- data/lib/wrapped/menu.rb +91 -0
- data/lib/wrapped/menuitem.rb +150 -0
- data/lib/wrapped/messagedialog.rb +127 -0
- data/lib/wrapped/progressbar.rb +91 -0
- data/lib/wrapped/progressdialog.rb +85 -0
- data/lib/wrapped/radio.rb +74 -0
- data/lib/wrapped/scintilla.rb +1112 -0
- data/lib/wrapped/scrollbar-attributes.rb +178 -0
- data/lib/wrapped/scrollbox.rb +40 -0
- data/lib/wrapped/separator.rb +24 -0
- data/lib/wrapped/splitbox.rb +114 -0
- data/lib/wrapped/stretchbox.rb +70 -0
- data/lib/wrapped/submenu.rb +58 -0
- data/lib/wrapped/tabs.rb +223 -0
- data/lib/wrapped/text.rb +382 -0
- data/lib/wrapped/timer.rb +82 -0
- data/lib/wrapped/toggle.rb +150 -0
- data/lib/wrapped/tree.rb +612 -0
- data/lib/wrapped/val.rb +162 -0
- data/lib/wrapped/vbox.rb +93 -0
- data/lib/wrapped/widget.rb +282 -0
- data/lib/wrapped/zbox.rb +80 -0
- metadata +131 -0
data/lib/wrapped/list.rb
ADDED
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# Convenience function to show a modal dialog to select an
|
|
4
|
+
# item from a list.
|
|
5
|
+
#
|
|
6
|
+
# * +title+ - title for dialog
|
|
7
|
+
# * +items+ - list of items (strings) to display
|
|
8
|
+
#
|
|
9
|
+
# Returns selected item, or +nil+ if cancel clicked.
|
|
10
|
+
#
|
|
11
|
+
# selection = Iup.listdialog('select one', ['C', 'Java', 'Ruby', 'Scheme'])
|
|
12
|
+
# puts "Return #{selection}"
|
|
13
|
+
#
|
|
14
|
+
# Also see: +List+
|
|
15
|
+
def self.listdialog(title, items)
|
|
16
|
+
strptrs = []
|
|
17
|
+
strptrs << nil
|
|
18
|
+
|
|
19
|
+
items_ptr = FFI::MemoryPointer.new(:pointer, items.length)
|
|
20
|
+
items.each_with_index do |item, i|
|
|
21
|
+
items_ptr[i].put_pointer(0, FFI::MemoryPointer.from_string(item))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
code = IupLib.IupListDialog(1, title, items.length, items_ptr, 1, 1, 10, nil)
|
|
25
|
+
|
|
26
|
+
return (code == -1 ? nil : items[code])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# A dynamic control presenting a list of options to the user.
|
|
30
|
+
# The list may be visible, or a hidden, drop-down list.
|
|
31
|
+
# Optionally, items may be editable.
|
|
32
|
+
#
|
|
33
|
+
# === Example
|
|
34
|
+
#
|
|
35
|
+
# (1) Simple list, responding to double-click selection:
|
|
36
|
+
#
|
|
37
|
+
# Iup::List.new do |l|
|
|
38
|
+
# l.item(1, "Java")
|
|
39
|
+
# l.item(2, "Ruby")
|
|
40
|
+
# l.item(3, "Scheme")
|
|
41
|
+
# l.spacing = 4
|
|
42
|
+
# l.size = "80x100"
|
|
43
|
+
# l.dblclick_cb = ->(index, text) {
|
|
44
|
+
# puts "DBL CLICK ON #{index} with #{text}"
|
|
45
|
+
# Iup::DEFAULT
|
|
46
|
+
# }
|
|
47
|
+
# end
|
|
48
|
+
#
|
|
49
|
+
# (2) Dropdown list, responding to changes in value:
|
|
50
|
+
#
|
|
51
|
+
# Iup::List.new do |l|
|
|
52
|
+
# l.item(1, "Java")
|
|
53
|
+
# l.item(2, "Ruby")
|
|
54
|
+
# l.item(3, "Scheme")
|
|
55
|
+
# l.spacing = 4
|
|
56
|
+
# l.dropdown = 'yes'
|
|
57
|
+
# l.valuechanged_cb = ->{
|
|
58
|
+
# puts "New value index is #{l.value}, text is #{l.item(l.value)}"
|
|
59
|
+
# Iup::DEFAULT
|
|
60
|
+
# }
|
|
61
|
+
# end
|
|
62
|
+
#
|
|
63
|
+
# Note that the C implementation of Iup's list is 1-indexed: this
|
|
64
|
+
# is preserved in the wrapped version, for consistency.
|
|
65
|
+
#
|
|
66
|
+
class List < Iup::Widget
|
|
67
|
+
include DragDropAttributes
|
|
68
|
+
|
|
69
|
+
# Creates a new instance.
|
|
70
|
+
# If a block is given, the new instance is yielded to it.
|
|
71
|
+
def initialize
|
|
72
|
+
@handle = IupLib.IupList(nil)
|
|
73
|
+
|
|
74
|
+
# run any provided block on instance, to set up further attributes
|
|
75
|
+
yield self if block_given?
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# -- attributes
|
|
79
|
+
|
|
80
|
+
##
|
|
81
|
+
# :attr_writer: append
|
|
82
|
+
# (with editbox set) appends given string to end of list.
|
|
83
|
+
define_writer :append
|
|
84
|
+
|
|
85
|
+
# Adds given item to end of list.
|
|
86
|
+
# * +text+ - required text label
|
|
87
|
+
# * +image+ - optional image reference / name.
|
|
88
|
+
def appenditem(text, image=nil)
|
|
89
|
+
IupLib.IupSetAttribute(@handle, 'APPENDITEM', text)
|
|
90
|
+
case image
|
|
91
|
+
when NilClass
|
|
92
|
+
;
|
|
93
|
+
when String
|
|
94
|
+
IupLib.SetAttibute(@handle, "IMAGE#{count}", image)
|
|
95
|
+
when ImageWidget
|
|
96
|
+
image_name = IupLib.IupGetName(name).first
|
|
97
|
+
if image_name.nil? or image_name.empty?
|
|
98
|
+
image_name = SecureRandom.uuid
|
|
99
|
+
image.assign_handle image_name
|
|
100
|
+
end
|
|
101
|
+
IupLib.IupSetAttribute(@handle, "IMAGE#{count}", image_name)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
##
|
|
106
|
+
# :attr: autohide
|
|
107
|
+
# If set, scrollbars are only shown if necessary, values 'yes' / 'no'.
|
|
108
|
+
define_attribute :autohide
|
|
109
|
+
|
|
110
|
+
##
|
|
111
|
+
# :attr: canfocus
|
|
112
|
+
# If set, the control can gain focus, values 'yes' / 'no'.
|
|
113
|
+
define_attribute :canfocus
|
|
114
|
+
|
|
115
|
+
##
|
|
116
|
+
# :attr: caret
|
|
117
|
+
# (with editbox set) 'col', in single-line mode, or 'lin,col' in multi-line mode.
|
|
118
|
+
define_attribute :caret
|
|
119
|
+
|
|
120
|
+
##
|
|
121
|
+
# :attr: caretpos
|
|
122
|
+
# (with editbox set) Index of character of the insertion point.
|
|
123
|
+
define_attribute :caretpos
|
|
124
|
+
|
|
125
|
+
##
|
|
126
|
+
# :attr_writer: clipboard
|
|
127
|
+
# (with editbox set) 'clear' / 'copy' / 'cut' / 'paste'.
|
|
128
|
+
# Access the clipboard with the current selection.
|
|
129
|
+
define_writer :clipboard
|
|
130
|
+
|
|
131
|
+
##
|
|
132
|
+
# :attr_reader: count
|
|
133
|
+
# Returns the number of items in the list.
|
|
134
|
+
define_reader :count
|
|
135
|
+
|
|
136
|
+
##
|
|
137
|
+
# :attr: dragdroplist
|
|
138
|
+
# If yes, enables drag and drop between lists: 'yes' / 'no'.
|
|
139
|
+
define_attribute :dragdroplist
|
|
140
|
+
|
|
141
|
+
##
|
|
142
|
+
# :attr: dropfilestarget
|
|
143
|
+
# Enable or disable the drop of files: 'no' / 'yes'.
|
|
144
|
+
# Automatically set to 'yes' if +dropfiles_cb+ is defined when list is
|
|
145
|
+
# mapped.
|
|
146
|
+
define_attribute :dropfilestarget
|
|
147
|
+
|
|
148
|
+
##
|
|
149
|
+
# :attr: dropdown
|
|
150
|
+
# 'yes' / 'no', if set, only the selected item is visible.
|
|
151
|
+
define_attribute :dropdown
|
|
152
|
+
|
|
153
|
+
##
|
|
154
|
+
# :attr: editbox
|
|
155
|
+
# 'yes' / 'no', if set adds an editable box to the list.
|
|
156
|
+
define_attribute :editbox
|
|
157
|
+
|
|
158
|
+
##
|
|
159
|
+
# :attr: expand
|
|
160
|
+
# Allows list to fill available space in indicated direction.
|
|
161
|
+
# Values 'no' / 'horizontal' / 'vertical' / 'yes'.
|
|
162
|
+
define_attribute :expand
|
|
163
|
+
|
|
164
|
+
##
|
|
165
|
+
# :attr_writer: insert
|
|
166
|
+
# (with editbox set) Places a given string at current caret position,
|
|
167
|
+
# overwriting any current selection.
|
|
168
|
+
define_writer :insert
|
|
169
|
+
|
|
170
|
+
# Insert item at given index.
|
|
171
|
+
# * +index+ - index to place item (1-indexed)
|
|
172
|
+
# * +text+ - required text label
|
|
173
|
+
# * +image+ - optional image reference / name.
|
|
174
|
+
def insertitem(index, text, image=nil)
|
|
175
|
+
IupLib.IupSetAttribute @handle, "INSERTITEM#{index}", text
|
|
176
|
+
case image
|
|
177
|
+
when NilClass
|
|
178
|
+
;
|
|
179
|
+
when String
|
|
180
|
+
IupLib.IupSetAttibute @handle, "IMAGE#{index}", image
|
|
181
|
+
when ImageWidget
|
|
182
|
+
image_name = IupLib.IupGetName(name).first
|
|
183
|
+
if image_name.nil? or image_name.empty?
|
|
184
|
+
image_name = SecureRandom.uuid
|
|
185
|
+
image.assign_handle image_name
|
|
186
|
+
end
|
|
187
|
+
IupLib.IupSetAttribute @handle, "IMAGE#{index}", image_name
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# :call-seq:
|
|
192
|
+
# list.item(index) # retrieves item
|
|
193
|
+
# list.item(index, text) # sets text
|
|
194
|
+
# list.item(index, text, image) # sets text and image
|
|
195
|
+
#
|
|
196
|
+
# Accesses given index position.
|
|
197
|
+
# * +index+ - index of item (1-indexed)
|
|
198
|
+
# * +text+ - text label (+nil+ to retrieve)
|
|
199
|
+
# * +image+ - optional image reference / name.
|
|
200
|
+
def item(index, text=nil, image=nil)
|
|
201
|
+
if text.nil?
|
|
202
|
+
IupLib.IupGetAttribute(@handle, index.to_s).first
|
|
203
|
+
else
|
|
204
|
+
IupLib.IupSetAttribute(@handle, index.to_s, text)
|
|
205
|
+
case image
|
|
206
|
+
when NilClass
|
|
207
|
+
;
|
|
208
|
+
when String
|
|
209
|
+
IupLib.IupSetAttribute(@handle, "IMAGE#{index}", image)
|
|
210
|
+
when ImageWidget
|
|
211
|
+
IupLib.IupSetAttributeHandle(@handle, "IMAGE#{index}", image.handle)
|
|
212
|
+
end
|
|
213
|
+
text
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
##
|
|
218
|
+
# :attr: mask
|
|
219
|
+
# (with editbox set) Defines a mask to filter text input.
|
|
220
|
+
# See {pre-defined masks}[../Iup.html#Masks].
|
|
221
|
+
define_attribute :mask
|
|
222
|
+
|
|
223
|
+
##
|
|
224
|
+
# :attr: multiple
|
|
225
|
+
# If set, allows selection of multiple items: values 'yes' / 'no'.
|
|
226
|
+
# Only available if editbox = dropdown = no.
|
|
227
|
+
define_attribute :multiple
|
|
228
|
+
|
|
229
|
+
##
|
|
230
|
+
# :attr: nc
|
|
231
|
+
# (with editbox set) Maximum number of characters allowed for keyboard
|
|
232
|
+
# input (0 allows an indefinite number).
|
|
233
|
+
define_attribute :nc
|
|
234
|
+
|
|
235
|
+
##
|
|
236
|
+
# :attr: padding
|
|
237
|
+
# (with editbox set) Margin in x and y directions, value as "mxn".
|
|
238
|
+
define_attribute :padding
|
|
239
|
+
|
|
240
|
+
##
|
|
241
|
+
# :attr_reader: position
|
|
242
|
+
# returns position in pixels within client window as "x,y".
|
|
243
|
+
define_reader :position
|
|
244
|
+
|
|
245
|
+
##
|
|
246
|
+
# :attr: rastersize
|
|
247
|
+
# Size of the list, in pixels, value as "widthxheight".
|
|
248
|
+
define_attribute :rastersize
|
|
249
|
+
|
|
250
|
+
##
|
|
251
|
+
# :attr: readonly
|
|
252
|
+
# (with editbox set) If set, prevents the user changing contents: values
|
|
253
|
+
# 'yes' / 'no'.
|
|
254
|
+
define_attribute :readonly
|
|
255
|
+
|
|
256
|
+
# Removes given item from the list:
|
|
257
|
+
# * +list+ - index of item to remove (1-indexed), or 'all', to remove all items.
|
|
258
|
+
def removeitem item
|
|
259
|
+
IupLib.IupSetAttribute(@handle, "REMOVEITEM", item.to_s)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
##
|
|
263
|
+
# :attr_reader: screenposition
|
|
264
|
+
# returns position in pixels on screen as "x,y".
|
|
265
|
+
define_reader :screenposition
|
|
266
|
+
|
|
267
|
+
##
|
|
268
|
+
# :attr: scrollbar
|
|
269
|
+
# When in multiline mode, enables a scrollbar.
|
|
270
|
+
# Values 'vertical' / 'horizontal' / 'yes' / 'no'.
|
|
271
|
+
define_attribute :scrollbar
|
|
272
|
+
|
|
273
|
+
##
|
|
274
|
+
# :attr_writer: scrollto
|
|
275
|
+
# (with editbox set) 'col' Scrolls to make given column number visible, in
|
|
276
|
+
# single-line mode.
|
|
277
|
+
# 'lin/col' Scrolls to make line and column number visible, in multi-line
|
|
278
|
+
# mode.
|
|
279
|
+
define_writer :scrollto
|
|
280
|
+
|
|
281
|
+
##
|
|
282
|
+
# :attr_writer: scrolltopos
|
|
283
|
+
# (with editbox set) Scrolls to make character 'number' visible.
|
|
284
|
+
define_writer :scrolltopos
|
|
285
|
+
|
|
286
|
+
##
|
|
287
|
+
# :attr: selectedtext
|
|
288
|
+
# (with editbox set) Reads or overwrites the current selection.
|
|
289
|
+
# Does nothing if no text is selected.
|
|
290
|
+
define_attribute :selectedtext
|
|
291
|
+
|
|
292
|
+
##
|
|
293
|
+
# :attr: selection
|
|
294
|
+
# (with editbox set) Selects text as 'col1:col2' (single-line) /
|
|
295
|
+
# 'lin1,col1:lin2,col2' (multi-line) / 'all' / 'none'.
|
|
296
|
+
define_attribute :selection
|
|
297
|
+
|
|
298
|
+
##
|
|
299
|
+
# :attr: selectionpos
|
|
300
|
+
# (with editbox set) Selects text between character positions: 'pos1:pos2'
|
|
301
|
+
# / 'all' / 'none'.
|
|
302
|
+
define_attribute :selectionpos
|
|
303
|
+
|
|
304
|
+
##
|
|
305
|
+
# :attr: showdragdrop
|
|
306
|
+
# If set, enables internal drag/drop: values 'yes' / 'no'.
|
|
307
|
+
define_attribute :showdragdrop
|
|
308
|
+
|
|
309
|
+
##
|
|
310
|
+
# :attr_writer: showdropdown
|
|
311
|
+
# Shows the dropdown list, if dropdown=yes.
|
|
312
|
+
define_writer :showdropdown
|
|
313
|
+
|
|
314
|
+
define_attribute :showimage
|
|
315
|
+
|
|
316
|
+
##
|
|
317
|
+
# :attr: sort
|
|
318
|
+
# Forces items to be sorted alphabetically.
|
|
319
|
+
# Insert/append operations will ignore the index number.
|
|
320
|
+
define_attribute :sort
|
|
321
|
+
|
|
322
|
+
##
|
|
323
|
+
# :attr: spacing
|
|
324
|
+
# Space between items, value as a number.
|
|
325
|
+
define_attribute :spacing
|
|
326
|
+
|
|
327
|
+
##
|
|
328
|
+
# :attr: tip
|
|
329
|
+
# Tooltip string.
|
|
330
|
+
define_attribute :tip
|
|
331
|
+
|
|
332
|
+
##
|
|
333
|
+
# :attr: value
|
|
334
|
+
# If val is:
|
|
335
|
+
# * +string+ - when editbox is set, sets/gets the text entered by user.
|
|
336
|
+
# * +nil+ / integer - when dropdown = 'yes' or multiple = 'no', sets/gets index of selected items.
|
|
337
|
+
#
|
|
338
|
+
# When list is multiple, val is converted to/from array of indices from/to +/-
|
|
339
|
+
|
|
340
|
+
# --
|
|
341
|
+
def value
|
|
342
|
+
item_str = IupLib.IupGetAttribute(@handle, 'VALUE').first
|
|
343
|
+
if multiple == 'YES'
|
|
344
|
+
result = []
|
|
345
|
+
item_str.split('').each_with_index do |item, index|
|
|
346
|
+
result << index+1 if item == '+'
|
|
347
|
+
end
|
|
348
|
+
return result
|
|
349
|
+
else
|
|
350
|
+
return item_str
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
def value= val # :nodoc:
|
|
355
|
+
if multiple == 'YES'
|
|
356
|
+
result = ""
|
|
357
|
+
count.to_i.times do |i|
|
|
358
|
+
if val.include?(i+1)
|
|
359
|
+
result << '+'
|
|
360
|
+
else
|
|
361
|
+
result << '-'
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
IupLib.IupSetAttribute(@handle, 'VALUE', result)
|
|
365
|
+
else
|
|
366
|
+
IupLib.IupSetAttribute(@handle, 'VALUE', val.to_s)
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
##
|
|
371
|
+
# :attr: visiblecolumns
|
|
372
|
+
# The minimum number of visible columns, defaults to 5.
|
|
373
|
+
define_attribute :visiblecolumns
|
|
374
|
+
|
|
375
|
+
##
|
|
376
|
+
# :attr: visiblelines
|
|
377
|
+
# The minimum number of visible lines, when dropdown=no.
|
|
378
|
+
define_attribute :visiblelines
|
|
379
|
+
|
|
380
|
+
# :section: Callbacks
|
|
381
|
+
|
|
382
|
+
##
|
|
383
|
+
# :attr_writer: action
|
|
384
|
+
# Callback called when the state of an item in the list is changed.
|
|
385
|
+
# Callback must respond to +call+ and takes a 3-argument callback: (text,
|
|
386
|
+
# item, state)
|
|
387
|
+
# * +text+ - text of the changed item
|
|
388
|
+
# * +item+ - index of changed item (1-indexed)
|
|
389
|
+
# * +state+ - 1 if selected; 0 if deselected
|
|
390
|
+
|
|
391
|
+
# --
|
|
392
|
+
def action= callback
|
|
393
|
+
unless callback.arity == 3
|
|
394
|
+
raise ArgumentError, 'action callback must take 3 arguments: (text, item, state)'
|
|
395
|
+
end
|
|
396
|
+
cb = Proc.new do |ih, text, item, state|
|
|
397
|
+
callback.call text, item, state
|
|
398
|
+
end
|
|
399
|
+
define_callback cb, 'ACTION', :sii_i
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
include ButtonCallback
|
|
403
|
+
|
|
404
|
+
##
|
|
405
|
+
# :attr_writer: caret_cb
|
|
406
|
+
# Callback called when the caret/cursor position is changed. Valid only when EDITBOX=YES.
|
|
407
|
+
# Callback must respond to +call+ and takes a callback which accepts 3
|
|
408
|
+
# arguments (line, column, position) of caret
|
|
409
|
+
# * +line+ - line number (1-indexed)
|
|
410
|
+
# * +column+ - column number (1-indexed)
|
|
411
|
+
# * +position+ - character position (0-indexed)
|
|
412
|
+
|
|
413
|
+
# --
|
|
414
|
+
def caret_cb= callback
|
|
415
|
+
unless callback.arity == 3
|
|
416
|
+
raise ArgumentError, 'caret_cb callback must take 3 arguments: (line, column, position)'
|
|
417
|
+
end
|
|
418
|
+
cb = Proc.new do |ih, lin, col, pos|
|
|
419
|
+
callback.call lin, col, pos
|
|
420
|
+
end
|
|
421
|
+
define_callback cb, 'CARET_CB', :iii_i
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
##
|
|
425
|
+
# :attr_writer: dblclick_cb
|
|
426
|
+
# Callback called when the user double click an item. Called only when DROPDOWN=NO.
|
|
427
|
+
# Callback must respond to +call+ and takes a callback which accepts 2
|
|
428
|
+
# arguments (index, text)
|
|
429
|
+
# * +index+ - index of selected item (1-indexed)
|
|
430
|
+
# * +text+ - text of selected item
|
|
431
|
+
|
|
432
|
+
# --
|
|
433
|
+
def dblclick_cb= callback
|
|
434
|
+
unless callback.arity == 2
|
|
435
|
+
raise ArgumentError, 'dblclick_cb callback must take 2 arguments: index, text'
|
|
436
|
+
end
|
|
437
|
+
cb = Proc.new do |ih, index, text|
|
|
438
|
+
callback.call index, text
|
|
439
|
+
end
|
|
440
|
+
define_callback cb, 'DBLCLICK_CB', :is_i
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
##
|
|
444
|
+
# :attr_writer: dragdrop_cb
|
|
445
|
+
# Callback called when an internal drag and drop is executed. Only active
|
|
446
|
+
# if SHOWDRAGDROP=YES.
|
|
447
|
+
# Callback must respond to +call+ and takes a callback which accepts 4
|
|
448
|
+
# arguments (drag_id, drop_id, isshift, iscontrol)
|
|
449
|
+
# * +drag_id+ - is an integer index of dragged item
|
|
450
|
+
# * +drop_id+ - is an integer index of drop location
|
|
451
|
+
# * +isshift+ - boolean flag for if shift key held
|
|
452
|
+
# * +iscontrol+ - boolean flag for if control key held
|
|
453
|
+
# Callback should return Iup::CONTINUE for item to be moved/copied.
|
|
454
|
+
|
|
455
|
+
# --
|
|
456
|
+
def dragdrop_cb= callback
|
|
457
|
+
unless callback.arity == 4
|
|
458
|
+
raise ArgumentError, 'dragdrop_cb callback must take 4 arguments: (drag_id, drop_id, isshift, iscontrol)'
|
|
459
|
+
end
|
|
460
|
+
cb = Proc.new do |ih, drag_id, drop_id, isshift, iscontrol|
|
|
461
|
+
callback.call drag_id.to_i, drop_id.to_i, (isshift != 0), (iscontrol != 0)
|
|
462
|
+
end
|
|
463
|
+
define_callback cb, 'DRAGDROP_CB', :iiii_i
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
##
|
|
467
|
+
# :attr_writer: dropdown_cb
|
|
468
|
+
# Callback called when the list of a dropdown is shown or hidden. Called
|
|
469
|
+
# only when DROPDOWN=YES.
|
|
470
|
+
# Callback must respond to +call+ and takes a 1-argument callback: (state)
|
|
471
|
+
# * +state+ - a boolean, true/false if dropdown visible/hidden.
|
|
472
|
+
|
|
473
|
+
# --
|
|
474
|
+
def dropdown_cb= callback
|
|
475
|
+
unless callback.arity == 1
|
|
476
|
+
raise ArgumentError, 'dropdown_cb callback must take 1 argument, shown'
|
|
477
|
+
end
|
|
478
|
+
cb = Proc.new do |ih, state|
|
|
479
|
+
callback.call (state == 1)
|
|
480
|
+
end
|
|
481
|
+
define_callback cb, 'DROPDOWN_CB', :i_i
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
##
|
|
485
|
+
# :attr_writer: edit_cb
|
|
486
|
+
# Callback called when the text in the text box is manually changed by the
|
|
487
|
+
# user, but before its value is actually updated. Valid only when
|
|
488
|
+
# EDITBOX=YES.
|
|
489
|
+
# Callback must respond to +call+ and takes a 2-argument callback: (character, new_value)
|
|
490
|
+
# * +character+ - the character typed
|
|
491
|
+
# * +new_value+ - the new text value
|
|
492
|
+
|
|
493
|
+
# --
|
|
494
|
+
def edit_cb= callback
|
|
495
|
+
unless callback.arity == 2
|
|
496
|
+
raise ArgumentError, 'edit_cb callback must take 2 arguments: (character, new_value)'
|
|
497
|
+
end
|
|
498
|
+
cb = Proc.new do |ih, c, text|
|
|
499
|
+
callback.call c, text
|
|
500
|
+
end
|
|
501
|
+
define_callback cb, 'EDIT_CB', :is_i
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
##
|
|
505
|
+
# :attr_writer: motion_cb
|
|
506
|
+
# Callback called when the mouse is moved.
|
|
507
|
+
# Callback must respond to +call+ and takes 3 arguments: (x, y, state)
|
|
508
|
+
# * +x+ - x position of mouse
|
|
509
|
+
# * +y+ - y position of mouse
|
|
510
|
+
# * +state+ - status of mouse buttons and certain keyboard keys at the moment the event was generated.
|
|
511
|
+
|
|
512
|
+
#--
|
|
513
|
+
def motion_cb= callback
|
|
514
|
+
unless callback.arity == 3
|
|
515
|
+
raise ArgumentError, 'motion_cb callback must take 3 arguments: (x, y, state)'
|
|
516
|
+
end
|
|
517
|
+
cb = Proc.new do |ih, x, y, state|
|
|
518
|
+
callback.call x, y, state
|
|
519
|
+
end
|
|
520
|
+
define_callback cb, 'MOTION_CB', :iis_i
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
##
|
|
524
|
+
# :attr_writer: multiselect_cb
|
|
525
|
+
# Callback called when the state of an item in the multiple selection list
|
|
526
|
+
# is changed. But it is called only when the interaction is over.
|
|
527
|
+
# Callback must respond to +call+ and is called with two arrays: (selected, deselected)
|
|
528
|
+
# * +selected+ - indices of selected items
|
|
529
|
+
# * +deselected+ - indices of deselected items
|
|
530
|
+
|
|
531
|
+
# --
|
|
532
|
+
def multiselect_cb= callback
|
|
533
|
+
unless callback.arity == 2
|
|
534
|
+
raise ArgumentError, 'multiselect_cb callback must take 2 arguments, the array of selected and array of deselected items'
|
|
535
|
+
end
|
|
536
|
+
cb = Proc.new do |ih, val_ptr|
|
|
537
|
+
val = FFI::Pointer.new(val_ptr).read_string
|
|
538
|
+
selected = []
|
|
539
|
+
deselected = []
|
|
540
|
+
val.split('').each_with_index do |item, index|
|
|
541
|
+
selected << index+1 if item == '+'
|
|
542
|
+
deselected << index+1 if item == '-'
|
|
543
|
+
end
|
|
544
|
+
callback.call selected, deselected
|
|
545
|
+
end
|
|
546
|
+
define_callback cb, 'MULTISELECT_CB', :s_i
|
|
547
|
+
end
|
|
548
|
+
|
|
549
|
+
##
|
|
550
|
+
# :attr_writer: valuechanged_cb
|
|
551
|
+
# Called after the value was interactively changed by the user. Called when
|
|
552
|
+
# the selection is changed or when the text is edited.
|
|
553
|
+
# Callback must respond to +call+ and takes no arguments.
|
|
554
|
+
|
|
555
|
+
# --
|
|
556
|
+
def valuechanged_cb= callback
|
|
557
|
+
unless callback.arity.zero?
|
|
558
|
+
raise ArgumentError, 'valuechanged_cb callback must take 0 arguments'
|
|
559
|
+
end
|
|
560
|
+
cb = Proc.new do |ih|
|
|
561
|
+
callback.call
|
|
562
|
+
end
|
|
563
|
+
define_callback cb, 'VALUECHANGED_CB', :plain
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
end
|
|
567
|
+
end
|