rndk 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -4
- data/TODO +21 -1
- data/demos/appointment.rb +279 -299
- data/demos/clock.rb +13 -8
- data/demos/rss-reader.rb +84 -0
- data/examples/01-hello-world.rb +13 -11
- data/examples/02-colors.rb +14 -21
- data/examples/03-markup.rb +7 -7
- data/examples/04-quick-widgets.rb +2 -2
- data/examples/05-position-widget.rb +50 -31
- data/examples/06-callbacks.rb +77 -0
- data/examples/07-traverse.rb +90 -0
- data/examples/10-all-widgets.rb +165 -0
- data/examples/calendar.rb +20 -32
- data/examples/entry.rb +15 -20
- data/examples/label.rb +11 -11
- data/examples/scroll.rb +16 -60
- data/examples/slider.rb +18 -19
- data/examples/viewer.rb +65 -0
- data/lib/rndk.rb +28 -7
- data/lib/rndk/alphalist.rb +309 -313
- data/lib/rndk/button.rb +239 -157
- data/lib/rndk/buttonbox.rb +136 -103
- data/lib/rndk/calendar.rb +246 -203
- data/lib/rndk/core/color.rb +63 -13
- data/lib/rndk/core/display.rb +1 -1
- data/lib/rndk/core/draw.rb +11 -11
- data/lib/rndk/core/markup.rb +21 -21
- data/lib/rndk/core/quick_widgets.rb +75 -96
- data/lib/rndk/core/screen.rb +145 -102
- data/lib/rndk/core/traverse.rb +150 -136
- data/lib/rndk/core/utils.rb +5 -6
- data/lib/rndk/core/widget.rb +207 -191
- data/lib/rndk/core/widget_bind.rb +108 -0
- data/lib/rndk/dialog.rb +88 -56
- data/lib/rndk/entry.rb +79 -64
- data/lib/rndk/fscale.rb +38 -20
- data/lib/rndk/fslider.rb +38 -23
- data/lib/rndk/graph.rb +92 -53
- data/lib/rndk/itemlist.rb +80 -62
- data/lib/rndk/label.rb +111 -77
- data/lib/rndk/radio.rb +138 -128
- data/lib/rndk/scale.rb +123 -122
- data/lib/rndk/scroll.rb +444 -391
- data/lib/rndk/scroller.rb +21 -21
- data/lib/rndk/slider.rb +149 -140
- data/lib/rndk/template.rb +74 -61
- data/lib/rndk/version.rb +1 -1
- data/lib/rndk/viewer.rb +499 -298
- metadata +8 -14
- data/demos/fileview.rb +0 -141
- data/lib/rndk/dscale.rb +0 -13
- data/lib/rndk/fselect.rb +0 -938
- data/lib/rndk/histogram.rb +0 -412
- data/lib/rndk/marquee.rb +0 -244
- data/lib/rndk/matrix.rb +0 -1189
- data/lib/rndk/mentry.rb +0 -619
- data/lib/rndk/menu.rb +0 -478
- data/lib/rndk/selection.rb +0 -630
- data/lib/rndk/swindow.rb +0 -766
- data/lib/rndk/uscale.rb +0 -14
- data/lib/rndk/uslider.rb +0 -14
data/lib/rndk/selection.rb
DELETED
@@ -1,630 +0,0 @@
|
|
1
|
-
require 'rndk/scroller'
|
2
|
-
|
3
|
-
module RNDK
|
4
|
-
# TODO This Widget's very buggy! Somehow improve it later!
|
5
|
-
class SELECTION < SCROLLER
|
6
|
-
attr_reader :selections
|
7
|
-
|
8
|
-
def initialize(rndkscreen, xplace, yplace, splace, height, width, title,
|
9
|
-
list, list_size, choices, choice_count, highlight, box, shadow)
|
10
|
-
super()
|
11
|
-
widest_item = -1
|
12
|
-
parent_width = Ncurses.getmaxx(rndkscreen.window)
|
13
|
-
parent_height = Ncurses.getmaxy(rndkscreen.window)
|
14
|
-
box_width = width
|
15
|
-
bindings = {
|
16
|
-
RNDK::BACKCHAR => Ncurses::KEY_PPAGE,
|
17
|
-
RNDK::FORCHAR => Ncurses::KEY_NPAGE,
|
18
|
-
'g' => Ncurses::KEY_HOME,
|
19
|
-
'1' => Ncurses::KEY_HOME,
|
20
|
-
'G' => Ncurses::KEY_END,
|
21
|
-
'<' => Ncurses::KEY_HOME,
|
22
|
-
'>' => Ncurses::KEY_END,
|
23
|
-
}
|
24
|
-
|
25
|
-
if choice_count <= 0
|
26
|
-
self.destroy
|
27
|
-
return nil
|
28
|
-
end
|
29
|
-
|
30
|
-
@choice = []
|
31
|
-
@choicelen = []
|
32
|
-
|
33
|
-
self.set_box(box)
|
34
|
-
|
35
|
-
# If the height is a negative value, the height will be ROWS-height,
|
36
|
-
# otherwise the height will be the given height.
|
37
|
-
box_height = RNDK.setWidgetDimension(parent_height, height, 0)
|
38
|
-
|
39
|
-
# If the width is a negative value, the width will be COLS-width,
|
40
|
-
# otherwise the width will be the given width
|
41
|
-
box_width = RNDK.setWidgetDimension(parent_width, width, 0)
|
42
|
-
box_width = self.set_title(title, box_width)
|
43
|
-
|
44
|
-
# Set the box height.
|
45
|
-
if @title_lines > box_height
|
46
|
-
box_height = @title_lines = [list_size, 8].min, + 2 * border_size
|
47
|
-
end
|
48
|
-
|
49
|
-
@maxchoicelen = 0
|
50
|
-
|
51
|
-
# Adjust the box width if there is a scroll bar.
|
52
|
-
if splace == RNDK::LEFT || splace == RNDK::RIGHT
|
53
|
-
box_width += 1
|
54
|
-
@scrollbar = true
|
55
|
-
else
|
56
|
-
@scrollbar = false
|
57
|
-
end
|
58
|
-
|
59
|
-
# Make sure we didn't extend beyond the dimensions of the window.
|
60
|
-
@box_width = [box_width, parent_width].min
|
61
|
-
@box_height = [box_height, parent_height].min
|
62
|
-
|
63
|
-
self.setViewSize(list_size)
|
64
|
-
|
65
|
-
# Rejustify the x and y positions if we need to.
|
66
|
-
xtmp = [xplace]
|
67
|
-
ytmp = [yplace]
|
68
|
-
RNDK.alignxy(rndkscreen.window, xtmp, ytmp, @box_width, @box_height)
|
69
|
-
xpos = xtmp[0]
|
70
|
-
ypos = ytmp[0]
|
71
|
-
|
72
|
-
# Make the selection window.
|
73
|
-
@win = Ncurses.newwin(@box_height, @box_width, ypos, xpos)
|
74
|
-
|
75
|
-
# Is the window nil?
|
76
|
-
if @win.nil?
|
77
|
-
self.destroy
|
78
|
-
return nil
|
79
|
-
end
|
80
|
-
|
81
|
-
# Turn the keypad on for this window.
|
82
|
-
Ncurses.keypad(@win, true)
|
83
|
-
|
84
|
-
# Create the scrollbar window.
|
85
|
-
if splace == RNDK::RIGHT
|
86
|
-
@scrollbar_win = Ncurses.subwin(@win, self.maxViewSize, 1,
|
87
|
-
self.Screen_YPOS(ypos), xpos + @box_width - @border_size - 1)
|
88
|
-
elsif splace == RNDK::LEFT
|
89
|
-
@scrollbar_win = Ncurses.subwin(@win, self.maxViewSize, 1,
|
90
|
-
self.Screen_YPOS(ypos), self.Screen_XPOS(ypos))
|
91
|
-
else
|
92
|
-
@scrollbar_win = nil
|
93
|
-
end
|
94
|
-
|
95
|
-
# Set the rest of the variables
|
96
|
-
@screen = rndkscreen
|
97
|
-
@parent = rndkscreen.window
|
98
|
-
@scrollbar_placement = splace
|
99
|
-
@max_left_char = 0
|
100
|
-
@left_char = 0
|
101
|
-
@highlight = highlight
|
102
|
-
@choice_count = choice_count
|
103
|
-
@accepts_focus = true
|
104
|
-
@input_window = @win
|
105
|
-
@shadow = shadow
|
106
|
-
|
107
|
-
self.setCurrentItem(0)
|
108
|
-
|
109
|
-
# Each choice has to be converted from string to chtype array
|
110
|
-
(0...choice_count).each do |j|
|
111
|
-
choicelen = []
|
112
|
-
@choice << RNDK.char2Chtype(choices[j], choicelen, [])
|
113
|
-
@choicelen << choicelen[0]
|
114
|
-
@maxchoicelen = [@maxchoicelen, choicelen[0]].max
|
115
|
-
end
|
116
|
-
|
117
|
-
# Each item in the needs to be converted to chtype array
|
118
|
-
widest_item = self.createList(list, list_size)
|
119
|
-
if widest_item > 0
|
120
|
-
self.updateViewWidth(widest_item)
|
121
|
-
elsif list_size > 0
|
122
|
-
self.destroy
|
123
|
-
return nil
|
124
|
-
end
|
125
|
-
|
126
|
-
# Do we need to create a shadow.
|
127
|
-
if shadow
|
128
|
-
@shadow_win = Ncurses.newwin(box_height, box_width,
|
129
|
-
ypos + 1, xpos + 1)
|
130
|
-
end
|
131
|
-
|
132
|
-
# Setup the key bindings
|
133
|
-
bindings.each do |from, to|
|
134
|
-
self.bind(:SELECTION, from, :getc, to)
|
135
|
-
end
|
136
|
-
|
137
|
-
# Register this baby.
|
138
|
-
rndkscreen.register(:SELECTION, self)
|
139
|
-
end
|
140
|
-
|
141
|
-
# Put the cursor on the currently-selected item.
|
142
|
-
def fixCursorPosition
|
143
|
-
scrollbar_adj = if @scrollbar_placement == RNDK::LEFT
|
144
|
-
then 1
|
145
|
-
else 0
|
146
|
-
end
|
147
|
-
ypos = self.Screen_YPOS(@current_item - @current_top)
|
148
|
-
xpos = self.Screen_XPOS(0) + scrollbar_adj
|
149
|
-
|
150
|
-
Ncurses.wmove(@input_window, ypos, xpos)
|
151
|
-
Ncurses.wrefresh @input_window
|
152
|
-
end
|
153
|
-
|
154
|
-
# This actually manages the selection widget
|
155
|
-
def activate(actions)
|
156
|
-
# Draw the selection list
|
157
|
-
self.draw(@box)
|
158
|
-
|
159
|
-
if actions.nil? || actions.size == 0
|
160
|
-
while true
|
161
|
-
self.fixCursorPosition
|
162
|
-
input = self.getch([])
|
163
|
-
|
164
|
-
# Inject the character into the widget.
|
165
|
-
ret = self.inject(input)
|
166
|
-
if @exit_type != :EARLY_EXIT
|
167
|
-
return ret
|
168
|
-
end
|
169
|
-
end
|
170
|
-
else
|
171
|
-
# Inject each character one at a time.
|
172
|
-
actions.each do |action|
|
173
|
-
ret = self.inject(action)
|
174
|
-
if @exit_type != :EARLY_EXIT
|
175
|
-
return ret
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# Set the exit type and return.
|
181
|
-
self.set_exit_type(0)
|
182
|
-
return 0
|
183
|
-
end
|
184
|
-
|
185
|
-
# This injects a single characer into the widget.
|
186
|
-
def inject(input)
|
187
|
-
pp_return = 1
|
188
|
-
ret = -1
|
189
|
-
complete = false
|
190
|
-
|
191
|
-
# Set the exit type
|
192
|
-
self.set_exit_type(0)
|
193
|
-
|
194
|
-
# Draw the widget list.
|
195
|
-
self.drawList(@box)
|
196
|
-
|
197
|
-
# Check if there is a pre-process function to be called.
|
198
|
-
unless @pre_process_func.nil?
|
199
|
-
pp_return = @pre_process_func.call(:SELECTION, self,
|
200
|
-
@pre_process_data, input)
|
201
|
-
end
|
202
|
-
|
203
|
-
# Should we continue?
|
204
|
-
if pp_return != 0
|
205
|
-
# Check for a predefined binding.
|
206
|
-
if self.checkBind(:SELECTION, input)
|
207
|
-
complete = true
|
208
|
-
else
|
209
|
-
case input
|
210
|
-
when Ncurses::KEY_UP
|
211
|
-
self.KEY_UP
|
212
|
-
when Ncurses::KEY_DOWN
|
213
|
-
self.KEY_DOWN
|
214
|
-
when Ncurses::KEY_RIGHT
|
215
|
-
self.KEY_RIGHT
|
216
|
-
when Ncurses::KEY_LEFT
|
217
|
-
self.KEY_LEFT
|
218
|
-
when Ncurses::KEY_PPAGE
|
219
|
-
self.KEY_PPAGE
|
220
|
-
when Ncurses::KEY_NPAGE
|
221
|
-
self.KEY_NPAGE
|
222
|
-
when Ncurses::KEY_HOME
|
223
|
-
self.KEY_HOME
|
224
|
-
when Ncurses::KEY_END
|
225
|
-
self.KEY_END
|
226
|
-
when '$'.ord
|
227
|
-
@left_char = @max_left_char
|
228
|
-
when '|'
|
229
|
-
@left_char = 0
|
230
|
-
when ' '.ord
|
231
|
-
if @mode[@current_item] == 0
|
232
|
-
if @selections[@current_item] == @choice_count - 1
|
233
|
-
@selections[@current_item] = 0
|
234
|
-
else
|
235
|
-
@selections[@current_item] += 1
|
236
|
-
end
|
237
|
-
else
|
238
|
-
RNDK.beep
|
239
|
-
end
|
240
|
-
when RNDK::KEY_ESC
|
241
|
-
self.set_exit_type(input)
|
242
|
-
complete = true
|
243
|
-
when Ncurses::ERR
|
244
|
-
self.set_exit_type(input)
|
245
|
-
complete = true
|
246
|
-
when Ncurses::KEY_ENTER, RNDK::KEY_TAB, RNDK::KEY_RETURN
|
247
|
-
self.set_exit_type(input)
|
248
|
-
ret = 1
|
249
|
-
complete = true
|
250
|
-
when RNDK::REFRESH
|
251
|
-
@screen.erase
|
252
|
-
@screen.refresh
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
# Should we call a post-process?
|
257
|
-
if !complete && !(@post_process_func.nil?)
|
258
|
-
@post_process_func.call(:SELECTION, self, @post_process_data, input)
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
unless complete
|
263
|
-
self.drawList(@box)
|
264
|
-
self.set_exit_type(0)
|
265
|
-
end
|
266
|
-
|
267
|
-
@result_data = ret
|
268
|
-
self.fixCursorPosition
|
269
|
-
return ret
|
270
|
-
end
|
271
|
-
|
272
|
-
# This moves the selection field to the given location.
|
273
|
-
def move(xplace, yplace, relative, refresh_flag)
|
274
|
-
windows = [@win, @scrollbar_win, @shadow_win]
|
275
|
-
self.move_specific(xplace, yplace, relative, refresh_flag,
|
276
|
-
windows, [])
|
277
|
-
end
|
278
|
-
|
279
|
-
# This function draws the selection list.
|
280
|
-
def draw(box)
|
281
|
-
# Draw in the shadow if we need to.
|
282
|
-
unless @shadow_win.nil?
|
283
|
-
Draw.drawShadow(@shadow_win)
|
284
|
-
end
|
285
|
-
|
286
|
-
self.drawTitle(@win)
|
287
|
-
|
288
|
-
# Redraw the list
|
289
|
-
self.drawList(box)
|
290
|
-
end
|
291
|
-
|
292
|
-
# This function draws the selection list window.
|
293
|
-
def drawList(box)
|
294
|
-
scrollbar_adj = if @scrollbar_placement == LEFT then 1 else 0 end
|
295
|
-
screen_pos = 0
|
296
|
-
sel_item = -1
|
297
|
-
|
298
|
-
# If there is to be a highlight, assign it now
|
299
|
-
if @has_focus
|
300
|
-
sel_item = @current_item
|
301
|
-
end
|
302
|
-
|
303
|
-
# draw the list...
|
304
|
-
j = 0
|
305
|
-
while j < @view_size && (j + @current_top) < @list_size
|
306
|
-
k = j + @current_top
|
307
|
-
if k < @list_size
|
308
|
-
screen_pos = self.ScreenPOS(k, scrollbar_adj)
|
309
|
-
ypos = self.Screen_YPOS(j)
|
310
|
-
xpos = self.Screen_XPOS(0)
|
311
|
-
|
312
|
-
# Draw the empty line.
|
313
|
-
Draw.writeBlanks(@win, xpos, ypos, RNDK::HORIZONTAL, 0, Ncurses.getmaxx(@win))
|
314
|
-
|
315
|
-
# Draw the selection item.
|
316
|
-
Draw.writeChtypeAttrib(@win,
|
317
|
-
if screen_pos >= 0 then screen_pos else 1 end,
|
318
|
-
ypos, @item[k],
|
319
|
-
if k == sel_item then @highlight else Ncurses::A_NORMAL end,
|
320
|
-
RNDK::HORIZONTAL,
|
321
|
-
if screen_pos >= 0 then 0 else 1 - screen_pos end,
|
322
|
-
@item_len[k])
|
323
|
-
|
324
|
-
# Draw the choice value
|
325
|
-
Draw.writeChtype(@win, xpos + scrollbar_adj, ypos,
|
326
|
-
@choice[@selections[k]], RNDK::HORIZONTAL, 0,
|
327
|
-
@choicelen[@selections[k]])
|
328
|
-
end
|
329
|
-
j += 1
|
330
|
-
end
|
331
|
-
|
332
|
-
# Determine where the toggle is supposed to be.
|
333
|
-
if @scrollbar
|
334
|
-
@toggle_pos = (@current_item * @step).floor
|
335
|
-
@toggle_pos = [@toggle_pos, Ncurses.getmaxy(@scrollbar_win) - 1].min
|
336
|
-
|
337
|
-
Ncurses.mvwvline(@scrollbar_win,
|
338
|
-
0,
|
339
|
-
0,
|
340
|
-
Ncurses::ACS_CKBOARD,
|
341
|
-
Ncurses.getmaxy(@scrollbar_win))
|
342
|
-
|
343
|
-
Ncurses.mvwvline(@scrollbar_win,
|
344
|
-
@toggle_pos,
|
345
|
-
0,
|
346
|
-
' '.ord | Ncurses::A_REVERSE, @toggle_size)
|
347
|
-
end
|
348
|
-
|
349
|
-
# Box it if needed
|
350
|
-
if @box
|
351
|
-
Draw.drawObjBox(@win, self)
|
352
|
-
end
|
353
|
-
|
354
|
-
self.fixCursorPosition
|
355
|
-
end
|
356
|
-
|
357
|
-
# This sets the background attribute of the widget.
|
358
|
-
def set_bg_attrib(attrib)
|
359
|
-
Ncurses.wbkgd(@win, attrib)
|
360
|
-
unless @scrollbar_win.nil?
|
361
|
-
Ncurses.wbkgd(@scrollbar_win, attrib)
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
def destroyInfo
|
366
|
-
@item = []
|
367
|
-
end
|
368
|
-
|
369
|
-
# This function destroys the selection list.
|
370
|
-
def destroy
|
371
|
-
self.cleanTitle
|
372
|
-
self.destroyInfo
|
373
|
-
|
374
|
-
# Clean up the windows.
|
375
|
-
RNDK.window_delete(@scrollbar_win)
|
376
|
-
RNDK.window_delete(@shadow_win)
|
377
|
-
RNDK.window_delete(@win)
|
378
|
-
|
379
|
-
# Clean up the key bindings
|
380
|
-
self.clean_bindings(:SELECTION)
|
381
|
-
|
382
|
-
# Unregister this object.
|
383
|
-
RNDK::Screen.unregister(:SELECTION, self)
|
384
|
-
end
|
385
|
-
|
386
|
-
# This function erases the selection list from the screen.
|
387
|
-
def erase
|
388
|
-
if self.valid_widget?
|
389
|
-
RNDK.window_erase(@win)
|
390
|
-
RNDK.window_erase(@shadow_win)
|
391
|
-
end
|
392
|
-
end
|
393
|
-
|
394
|
-
# This function sets a couple of the selection list attributes
|
395
|
-
def set(highlight, choices, box)
|
396
|
-
self.setChoices(choices)
|
397
|
-
self.set_highlight(highlight)
|
398
|
-
self.set_box(box)
|
399
|
-
end
|
400
|
-
|
401
|
-
# This sets the selection list items.
|
402
|
-
def setItems(list, list_size)
|
403
|
-
widest_item = self.createList(list, list_size)
|
404
|
-
if widest_item <= 0
|
405
|
-
return
|
406
|
-
end
|
407
|
-
|
408
|
-
# Clean up the display
|
409
|
-
(0...@view_size).each do |j|
|
410
|
-
Draw.writeBlanks(@win,
|
411
|
-
self.Screen_XPOS(0),
|
412
|
-
self.Screen_YPOS(j),
|
413
|
-
RNDK::HORIZONTAL,
|
414
|
-
0,
|
415
|
-
Ncurses.getmaxx(@win))
|
416
|
-
end
|
417
|
-
|
418
|
-
self.setViewSize(list_size)
|
419
|
-
self.setCurrentItem(0)
|
420
|
-
|
421
|
-
self.updateViewWidth(widest_item)
|
422
|
-
end
|
423
|
-
|
424
|
-
def getItems(list)
|
425
|
-
@item.each do |item|
|
426
|
-
list << RNDK.chtype2Char(item)
|
427
|
-
end
|
428
|
-
return @list_size
|
429
|
-
end
|
430
|
-
|
431
|
-
def setSelectionTitle(title)
|
432
|
-
# Make sure the title isn't nil
|
433
|
-
if title.nil?
|
434
|
-
return
|
435
|
-
end
|
436
|
-
|
437
|
-
self.set_title(title, -(@box_width + 1))
|
438
|
-
|
439
|
-
self.setViewSize(@list_size)
|
440
|
-
end
|
441
|
-
|
442
|
-
def getTitle
|
443
|
-
return RNDK.chtype2Char(@title)
|
444
|
-
end
|
445
|
-
|
446
|
-
# This sets the highlight bar.
|
447
|
-
def set_highlight(highlight)
|
448
|
-
@highlight = highlight
|
449
|
-
end
|
450
|
-
|
451
|
-
def getHighlight
|
452
|
-
@highlight
|
453
|
-
end
|
454
|
-
|
455
|
-
# This sets the default choices for the selection list.
|
456
|
-
def setChoices(choices)
|
457
|
-
# Set the choice values in the selection list.
|
458
|
-
(0...@list_size).each do |j|
|
459
|
-
if choices[j] < 0
|
460
|
-
@selections[j] = 0
|
461
|
-
elsif choices[j] > @choice_count
|
462
|
-
@selections[j] = @choice_count - 1
|
463
|
-
else
|
464
|
-
@selections[j] = choices[j]
|
465
|
-
end
|
466
|
-
end
|
467
|
-
end
|
468
|
-
|
469
|
-
def getChoices
|
470
|
-
@selections
|
471
|
-
end
|
472
|
-
|
473
|
-
# This sets a single item's choice value.
|
474
|
-
def setChoice(index, choice)
|
475
|
-
correct_choice = choice
|
476
|
-
correct_index = index
|
477
|
-
|
478
|
-
# Verify that the choice value is in range.
|
479
|
-
if choice < 0
|
480
|
-
correct_choice = 0
|
481
|
-
elsif choice > @choice_count
|
482
|
-
correct_choice = @choice_count - 1
|
483
|
-
end
|
484
|
-
|
485
|
-
# make sure the index isn't out of range.
|
486
|
-
if index < 0
|
487
|
-
correct_index = 0
|
488
|
-
elsif index > @list_size
|
489
|
-
correct_index = @list_size - 1
|
490
|
-
end
|
491
|
-
|
492
|
-
# Set the choice value.
|
493
|
-
@selections[correct_index] = correct_choice
|
494
|
-
end
|
495
|
-
|
496
|
-
def getChoice(index)
|
497
|
-
# Make sure the index isn't out of range.
|
498
|
-
if index < 0
|
499
|
-
return @selections[0]
|
500
|
-
elsif index > list_size
|
501
|
-
return @selections[@list_size - 1]
|
502
|
-
else
|
503
|
-
return @selections[index]
|
504
|
-
end
|
505
|
-
end
|
506
|
-
|
507
|
-
# This sets the modes of the items in the selection list. Currently
|
508
|
-
# there are only two: editable=0 and read-only=1
|
509
|
-
def setModes(modes)
|
510
|
-
# set the modes
|
511
|
-
(0...@list_size).each do |j|
|
512
|
-
@mode[j] = modes[j]
|
513
|
-
end
|
514
|
-
end
|
515
|
-
|
516
|
-
def getModes
|
517
|
-
return @mode
|
518
|
-
end
|
519
|
-
|
520
|
-
# This sets a single mode of an item in the selection list.
|
521
|
-
def setMode(index, mode)
|
522
|
-
# Make sure the index isn't out of range.
|
523
|
-
if index < 0
|
524
|
-
@mode[0] = mode
|
525
|
-
elsif index > @list_size
|
526
|
-
@mode[@list_size - 1] = mode
|
527
|
-
else
|
528
|
-
@mode[index] = mode
|
529
|
-
end
|
530
|
-
end
|
531
|
-
|
532
|
-
def getMode(index)
|
533
|
-
# Make sure the index isn't out of range
|
534
|
-
if index < 0
|
535
|
-
return @mode[0]
|
536
|
-
elsif index > list_size
|
537
|
-
return @mode[@list_size - 1]
|
538
|
-
else
|
539
|
-
return @mode[index]
|
540
|
-
end
|
541
|
-
end
|
542
|
-
|
543
|
-
def getCurrent
|
544
|
-
return @current_item
|
545
|
-
end
|
546
|
-
|
547
|
-
# methods for generic type methods
|
548
|
-
def focus
|
549
|
-
self.drawList(@box)
|
550
|
-
end
|
551
|
-
|
552
|
-
def unfocus
|
553
|
-
self.drawList(@box)
|
554
|
-
end
|
555
|
-
|
556
|
-
def createList(list, list_size)
|
557
|
-
status = 0
|
558
|
-
widest_item = 0
|
559
|
-
|
560
|
-
if list_size >= 0
|
561
|
-
new_list = []
|
562
|
-
new_len = []
|
563
|
-
new_pos = []
|
564
|
-
|
565
|
-
box_width = self.AvailableWidth
|
566
|
-
adjust = @maxchoicelen + @border_size
|
567
|
-
|
568
|
-
status = 1
|
569
|
-
(0...list_size).each do |j|
|
570
|
-
lentmp = []
|
571
|
-
postmp = []
|
572
|
-
new_list << RNDK.char2Chtype(list[j], lentmp, postmp)
|
573
|
-
new_len << lentmp[0]
|
574
|
-
new_pos << postmp[0]
|
575
|
-
#if new_list[j].size == 0
|
576
|
-
if new_list[j].nil?
|
577
|
-
status = 0
|
578
|
-
break
|
579
|
-
end
|
580
|
-
new_pos[j] =
|
581
|
-
RNDK.justifyString(box_width, new_len[j], new_pos[j]) + adjust
|
582
|
-
widest_item = [widest_item, new_len[j]].max
|
583
|
-
end
|
584
|
-
|
585
|
-
if status
|
586
|
-
self.destroyInfo
|
587
|
-
|
588
|
-
@item = new_list
|
589
|
-
@item_pos = new_pos
|
590
|
-
@item_len = new_len
|
591
|
-
@selections = [0] * list_size
|
592
|
-
@mode = [0] * list_size
|
593
|
-
end
|
594
|
-
else
|
595
|
-
self.destroyInfo
|
596
|
-
end
|
597
|
-
|
598
|
-
return (if status then widest_item else 0 end)
|
599
|
-
end
|
600
|
-
|
601
|
-
# Determine how many characters we can shift to the right
|
602
|
-
# before all the items have been scrolled off the screen.
|
603
|
-
def AvailableWidth
|
604
|
-
@box_width - 2 * @border_size - @maxchoicelen
|
605
|
-
end
|
606
|
-
|
607
|
-
def updateViewWidth(widest)
|
608
|
-
@max_left_char = if @box_width > widest
|
609
|
-
then 0
|
610
|
-
else widest - self.AvailableWidth
|
611
|
-
end
|
612
|
-
end
|
613
|
-
|
614
|
-
def WidestItem
|
615
|
-
@max_left_char + self.AvailableWidth
|
616
|
-
end
|
617
|
-
|
618
|
-
def ScreenPOS(n, scrollbar_adj)
|
619
|
-
@item_pos[n] - @left_char + scrollbar_adj
|
620
|
-
end
|
621
|
-
|
622
|
-
def position
|
623
|
-
super(@win)
|
624
|
-
end
|
625
|
-
|
626
|
-
def object_type
|
627
|
-
:SELECTION
|
628
|
-
end
|
629
|
-
end
|
630
|
-
end
|