rndk 0.0.1

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 (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/COPYING +137 -0
  4. data/Gemfile +4 -0
  5. data/README.md +100 -0
  6. data/Rakefile +3 -0
  7. data/TODO +68 -0
  8. data/demos/appointment.rb +346 -0
  9. data/demos/clock.rb +56 -0
  10. data/examples/01-hello-world.rb +56 -0
  11. data/examples/05-position-widget.rb +108 -0
  12. data/lib/rndk.rb +912 -0
  13. data/lib/rndk/alphalist.rb +572 -0
  14. data/lib/rndk/button.rb +370 -0
  15. data/lib/rndk/buttonbox.rb +359 -0
  16. data/lib/rndk/calendar.rb +766 -0
  17. data/lib/rndk/core/display.rb +63 -0
  18. data/lib/rndk/core/draw.rb +238 -0
  19. data/lib/rndk/core/quick_widgets.rb +106 -0
  20. data/lib/rndk/core/screen.rb +269 -0
  21. data/lib/rndk/core/traverse.rb +289 -0
  22. data/lib/rndk/core/widget.rb +506 -0
  23. data/lib/rndk/dialog.rb +367 -0
  24. data/lib/rndk/dscale.rb +13 -0
  25. data/lib/rndk/entry.rb +575 -0
  26. data/lib/rndk/fscale.rb +61 -0
  27. data/lib/rndk/fselect.rb +940 -0
  28. data/lib/rndk/fslider.rb +80 -0
  29. data/lib/rndk/graph.rb +401 -0
  30. data/lib/rndk/histogram.rb +412 -0
  31. data/lib/rndk/itemlist.rb +474 -0
  32. data/lib/rndk/label.rb +218 -0
  33. data/lib/rndk/marquee.rb +244 -0
  34. data/lib/rndk/matrix.rb +1189 -0
  35. data/lib/rndk/mentry.rb +619 -0
  36. data/lib/rndk/menu.rb +478 -0
  37. data/lib/rndk/radio.rb +538 -0
  38. data/lib/rndk/scale.rb +538 -0
  39. data/lib/rndk/scroll.rb +633 -0
  40. data/lib/rndk/scroller.rb +183 -0
  41. data/lib/rndk/selection.rb +630 -0
  42. data/lib/rndk/slider.rb +545 -0
  43. data/lib/rndk/swindow.rb +766 -0
  44. data/lib/rndk/template.rb +560 -0
  45. data/lib/rndk/uscale.rb +14 -0
  46. data/lib/rndk/uslider.rb +14 -0
  47. data/lib/rndk/version.rb +6 -0
  48. data/lib/rndk/viewer.rb +825 -0
  49. data/rndk.gemspec +35 -0
  50. metadata +141 -0
@@ -0,0 +1,183 @@
1
+ require 'rndk'
2
+ module RNDK
3
+ class SCROLLER < RNDK::Widget
4
+ def initialize
5
+ super()
6
+ end
7
+
8
+ def KEY_UP
9
+ if @list_size > 0
10
+ if @current_item > 0
11
+ if @current_high == 0
12
+ if @current_top != 0
13
+ @current_top -= 1
14
+ @current_item -= 1
15
+ else
16
+ RNDK.beep
17
+ end
18
+ else
19
+ @current_item -= 1
20
+ @current_high -= 1
21
+ end
22
+ else
23
+ RNDK.beep
24
+ end
25
+ else
26
+ RNDK.beep
27
+ end
28
+ end
29
+
30
+ def KEY_DOWN
31
+ if @list_size > 0
32
+ if @current_item < @list_size - 1
33
+ if @current_high == @view_size - 1
34
+ if @current_top < @max_top_item
35
+ @current_top += 1
36
+ @current_item += 1
37
+ else
38
+ RNDK.beep
39
+ end
40
+ else
41
+ @current_item += 1
42
+ @current_high += 1
43
+ end
44
+ else
45
+ RNDK.beep
46
+ end
47
+ else
48
+ RNDK.beep
49
+ end
50
+ end
51
+
52
+ def KEY_LEFT
53
+ if @list_size > 0
54
+ if @left_char == 0
55
+ RNDK.beep
56
+ else
57
+ @left_char -= 1
58
+ end
59
+ else
60
+ RNDK.beep
61
+ end
62
+ end
63
+
64
+ def KEY_RIGHT
65
+ if @list_size > 0
66
+ if @left_char >= @max_left_char
67
+ RNDK.beep
68
+ else
69
+ @left_char += 1
70
+ end
71
+ else
72
+ RNDK.beep
73
+ end
74
+ end
75
+
76
+ def KEY_PPAGE
77
+ if @list_size > 0
78
+ if @current_top > 0
79
+ if @current_top >= @view_size - 1
80
+ @current_top -= @view_size - 1
81
+ @current_item -= @view_size - 1
82
+ else
83
+ self.KEY_HOME
84
+ end
85
+ else
86
+ RNDK.beep
87
+ end
88
+ else
89
+ RNDK.beep
90
+ end
91
+ end
92
+
93
+ def KEY_NPAGE
94
+ if @list_size > 0
95
+ if @current_top < @max_top_item
96
+ if @current_top + @view_size - 1 <= @max_top_item
97
+ @current_top += @view_size - 1
98
+ @current_item += @view_size - 1
99
+ else
100
+ @current_top = @max_top_item
101
+ @current_item = @last_item
102
+ @current_high = @view_size - 1
103
+ end
104
+ else
105
+ RNDK.beep
106
+ end
107
+ else
108
+ RNDK.beep
109
+ end
110
+ end
111
+
112
+ def KEY_HOME
113
+ @current_top = 0
114
+ @current_item = 0
115
+ @current_high = 0
116
+ end
117
+
118
+ def KEY_END
119
+ if @max_top_item == -1
120
+ @current_top = 0
121
+ @current_item = @last_item - 1
122
+ else
123
+ @current_top = @max_top_item
124
+ @current_item = @last_item
125
+ end
126
+ @current_high = @view_size - 1
127
+ end
128
+
129
+ def maxViewSize
130
+ return @box_height - (2 * @border_size + @title_lines)
131
+ end
132
+
133
+ # Set variables that depend upon the list_size
134
+ def setViewSize(list_size)
135
+ @view_size = self.maxViewSize
136
+ @list_size = list_size
137
+ @last_item = list_size - 1
138
+ @max_top_item = list_size - @view_size
139
+
140
+ if list_size < @view_size
141
+ @view_size = list_size
142
+ @max_top_item = 0
143
+ end
144
+
145
+ if @list_size > 0 && self.maxViewSize > 0
146
+ @step = 1.0 * self.maxViewSize / @list_size
147
+ @toggle_size = if @list_size > self.maxViewSize
148
+ then 1
149
+ else @step.ceil
150
+ end
151
+ else
152
+ @step = 1
153
+ @toggle_size = 1
154
+ end
155
+ end
156
+
157
+ def setPosition(item)
158
+ if item <= 0
159
+ self.KEY_HOME
160
+ elsif item > @list_size - 1
161
+ @current_top = @max_top_item
162
+ @current_item = @list_size - 1
163
+ @current_high = @view_size - 1
164
+ elsif item >= @current_top && item < @current_top + @view_size
165
+ @current_item = item
166
+ @current_high = item - @current_top
167
+ else
168
+ @current_top = item - (@view_size - 1)
169
+ @current_item = item
170
+ @current_high = @view_size - 1
171
+ end
172
+ end
173
+
174
+ # Get/Set the current item number of the scroller.
175
+ def getCurrentItem
176
+ @current_item
177
+ end
178
+
179
+ def setCurrentItem(item)
180
+ self.setPosition(item);
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,630 @@
1
+ require 'rndk/scroller'
2
+
3
+ module RNDK
4
+ # TODO This Widget's very buggy! Somehow improve it later!
5
+ class SELECTION < RNDK::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.setBox(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.setTitle(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.setExitType(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.setExitType(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.setExitType(input)
242
+ complete = true
243
+ when Ncurses::ERR
244
+ self.setExitType(input)
245
+ complete = true
246
+ when Ncurses::KEY_ENTER, RNDK::KEY_TAB, RNDK::KEY_RETURN
247
+ self.setExitType(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.setExitType(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 setBKattr(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.deleteCursesWindow(@scrollbar_win)
376
+ RNDK.deleteCursesWindow(@shadow_win)
377
+ RNDK.deleteCursesWindow(@win)
378
+
379
+ # Clean up the key bindings
380
+ self.cleanBindings(: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.validRNDKObject
389
+ RNDK.eraseCursesWindow(@win)
390
+ RNDK.eraseCursesWindow(@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.setHighlight(highlight)
398
+ self.setBox(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.setTitle(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 setHighlight(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