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.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/COPYING +137 -0
- data/Gemfile +4 -0
- data/README.md +100 -0
- data/Rakefile +3 -0
- data/TODO +68 -0
- data/demos/appointment.rb +346 -0
- data/demos/clock.rb +56 -0
- data/examples/01-hello-world.rb +56 -0
- data/examples/05-position-widget.rb +108 -0
- data/lib/rndk.rb +912 -0
- data/lib/rndk/alphalist.rb +572 -0
- data/lib/rndk/button.rb +370 -0
- data/lib/rndk/buttonbox.rb +359 -0
- data/lib/rndk/calendar.rb +766 -0
- data/lib/rndk/core/display.rb +63 -0
- data/lib/rndk/core/draw.rb +238 -0
- data/lib/rndk/core/quick_widgets.rb +106 -0
- data/lib/rndk/core/screen.rb +269 -0
- data/lib/rndk/core/traverse.rb +289 -0
- data/lib/rndk/core/widget.rb +506 -0
- data/lib/rndk/dialog.rb +367 -0
- data/lib/rndk/dscale.rb +13 -0
- data/lib/rndk/entry.rb +575 -0
- data/lib/rndk/fscale.rb +61 -0
- data/lib/rndk/fselect.rb +940 -0
- data/lib/rndk/fslider.rb +80 -0
- data/lib/rndk/graph.rb +401 -0
- data/lib/rndk/histogram.rb +412 -0
- data/lib/rndk/itemlist.rb +474 -0
- data/lib/rndk/label.rb +218 -0
- data/lib/rndk/marquee.rb +244 -0
- data/lib/rndk/matrix.rb +1189 -0
- data/lib/rndk/mentry.rb +619 -0
- data/lib/rndk/menu.rb +478 -0
- data/lib/rndk/radio.rb +538 -0
- data/lib/rndk/scale.rb +538 -0
- data/lib/rndk/scroll.rb +633 -0
- data/lib/rndk/scroller.rb +183 -0
- data/lib/rndk/selection.rb +630 -0
- data/lib/rndk/slider.rb +545 -0
- data/lib/rndk/swindow.rb +766 -0
- data/lib/rndk/template.rb +560 -0
- data/lib/rndk/uscale.rb +14 -0
- data/lib/rndk/uslider.rb +14 -0
- data/lib/rndk/version.rb +6 -0
- data/lib/rndk/viewer.rb +825 -0
- data/rndk.gemspec +35 -0
- metadata +141 -0
data/lib/rndk/button.rb
ADDED
@@ -0,0 +1,370 @@
|
|
1
|
+
require 'rndk'
|
2
|
+
|
3
|
+
module RNDK
|
4
|
+
class BUTTON < RNDK::Widget
|
5
|
+
def initialize(rndkscreen, xplace, yplace, text, callback, box, shadow)
|
6
|
+
super()
|
7
|
+
parent_width = Ncurses.getmaxx(rndkscreen.window)
|
8
|
+
parent_height = Ncurses.getmaxy(rndkscreen.window)
|
9
|
+
box_width = 0
|
10
|
+
xpos = xplace
|
11
|
+
ypos = yplace
|
12
|
+
|
13
|
+
self.setBox(box)
|
14
|
+
box_height = 1 + 2 * @border_size
|
15
|
+
|
16
|
+
# Translate the string to a chtype array.
|
17
|
+
info_len = []
|
18
|
+
info_pos = []
|
19
|
+
@info = RNDK.char2Chtype(text, info_len, info_pos)
|
20
|
+
@info_len = info_len[0]
|
21
|
+
@info_pos = info_pos[0]
|
22
|
+
box_width = [box_width, @info_len].max + 2 * @border_size
|
23
|
+
|
24
|
+
# Create the string alignments.
|
25
|
+
@info_pos = RNDK.justifyString(box_width - 2 * @border_size,
|
26
|
+
@info_len, @info_pos)
|
27
|
+
|
28
|
+
# Make sure we didn't extend beyond the dimensions of the window.
|
29
|
+
box_width = if box_width > parent_width
|
30
|
+
then parent_width
|
31
|
+
else box_width
|
32
|
+
end
|
33
|
+
box_height = if box_height > parent_height
|
34
|
+
then parent_height
|
35
|
+
else box_height
|
36
|
+
end
|
37
|
+
|
38
|
+
# Rejustify the x and y positions if we need to.
|
39
|
+
xtmp = [xpos]
|
40
|
+
ytmp = [ypos]
|
41
|
+
RNDK.alignxy(rndkscreen.window, xtmp, ytmp, box_width, box_height)
|
42
|
+
xpos = xtmp[0]
|
43
|
+
ypos = ytmp[0]
|
44
|
+
|
45
|
+
# Create the button.
|
46
|
+
@screen = rndkscreen
|
47
|
+
# ObjOf (button)->fn = &my_funcs;
|
48
|
+
@parent = rndkscreen.window
|
49
|
+
@win = Ncurses.newwin(box_height, box_width, ypos, xpos)
|
50
|
+
@shadow_win = nil
|
51
|
+
@xpos = xpos
|
52
|
+
@ypos = ypos
|
53
|
+
@box_width = box_width
|
54
|
+
@box_height = box_height
|
55
|
+
@callback = callback
|
56
|
+
@input_window = @win
|
57
|
+
@accepts_focus = true
|
58
|
+
@shadow = shadow
|
59
|
+
|
60
|
+
if @win.nil?
|
61
|
+
self.destroy
|
62
|
+
return nil
|
63
|
+
end
|
64
|
+
|
65
|
+
Ncurses.keypad(@win, true)
|
66
|
+
|
67
|
+
# If a shadow was requested, then create the shadow window.
|
68
|
+
if shadow
|
69
|
+
@shadow_win = Ncurses.newwin(box_height, box_width,
|
70
|
+
ypos + 1, xpos + 1)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Register this baby.
|
74
|
+
rndkscreen.register(:BUTTON, self)
|
75
|
+
end
|
76
|
+
|
77
|
+
# This was added for the builder.
|
78
|
+
def activate(actions)
|
79
|
+
self.draw(@box)
|
80
|
+
ret = -1
|
81
|
+
|
82
|
+
if actions.nil? || actions.size == 0
|
83
|
+
while true
|
84
|
+
input = self.getch([])
|
85
|
+
|
86
|
+
# Inject the character into the widget.
|
87
|
+
ret = self.inject(input)
|
88
|
+
if @exit_type != :EARLY_EXIT
|
89
|
+
return ret
|
90
|
+
end
|
91
|
+
end
|
92
|
+
else
|
93
|
+
# Inject each character one at a time.
|
94
|
+
actions.each do |x|
|
95
|
+
ret = self.inject(action)
|
96
|
+
if @exit_type == :EARLY_EXIT
|
97
|
+
return ret
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Set the exit type and exit
|
103
|
+
self.setExitType(0)
|
104
|
+
return -1
|
105
|
+
end
|
106
|
+
|
107
|
+
# This sets multiple attributes of the widget.
|
108
|
+
def set(mesg, box)
|
109
|
+
self.setMessage(mesg)
|
110
|
+
self.setBox(box)
|
111
|
+
end
|
112
|
+
|
113
|
+
# This sets the information within the button.
|
114
|
+
def setMessage(info)
|
115
|
+
info_len = []
|
116
|
+
info_pos = []
|
117
|
+
@info = RNDK.char2Chtype(info, info_len, info_pos)
|
118
|
+
@info_len = info_len[0]
|
119
|
+
@info_pos = RNDK.justifyString(@box_width - 2 * @border_size,
|
120
|
+
info_pos[0])
|
121
|
+
|
122
|
+
# Redraw the button widget.
|
123
|
+
self.erase
|
124
|
+
self.draw(box)
|
125
|
+
end
|
126
|
+
|
127
|
+
def getMessage
|
128
|
+
return @info
|
129
|
+
end
|
130
|
+
|
131
|
+
# This sets the background attribute of the widget.
|
132
|
+
def setBKattr(attrib)
|
133
|
+
Ncurses.wbkgd(@win, attrib)
|
134
|
+
end
|
135
|
+
|
136
|
+
def drawText
|
137
|
+
box_width = @box_width
|
138
|
+
|
139
|
+
# Draw in the message.
|
140
|
+
(0...(box_width - 2 * @border_size)).each do |i|
|
141
|
+
pos = @info_pos
|
142
|
+
len = @info_len
|
143
|
+
if i >= pos && (i - pos) < len
|
144
|
+
c = @info[i - pos]
|
145
|
+
else
|
146
|
+
c = ' '
|
147
|
+
end
|
148
|
+
|
149
|
+
if @has_focus
|
150
|
+
c = Ncurses::A_REVERSE | c
|
151
|
+
end
|
152
|
+
|
153
|
+
Ncurses.mvwaddch(@win, @border_size, i + @border_size, c)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# This draws the button widget
|
158
|
+
def draw(box)
|
159
|
+
# Is there a shadow?
|
160
|
+
unless @shadow_win.nil?
|
161
|
+
Draw.drawShadow(@shadow_win)
|
162
|
+
end
|
163
|
+
|
164
|
+
# Box the widget if asked.
|
165
|
+
if @box
|
166
|
+
Draw.drawObjBox(@win, self)
|
167
|
+
end
|
168
|
+
self.drawText
|
169
|
+
Ncurses.wrefresh @win
|
170
|
+
end
|
171
|
+
|
172
|
+
# This erases the button widget.
|
173
|
+
def erase
|
174
|
+
if self.validRNDKObject
|
175
|
+
RNDK.eraseCursesWindow(@win)
|
176
|
+
RNDK.eraseCursesWindow(@shadow_win)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# This moves the button field to the given location.
|
181
|
+
def move(xplace, yplace, relative, refresh_flag)
|
182
|
+
current_x = Ncurses.getbegx(@win)
|
183
|
+
current_y = Ncurses.getbegy(@win)
|
184
|
+
xpos = xplace
|
185
|
+
ypos = yplace
|
186
|
+
|
187
|
+
# If this is a relative move, then we will adjust where we want
|
188
|
+
# to move to.
|
189
|
+
if relative
|
190
|
+
xpos = Ncurses.getbegx(@win) + xplace
|
191
|
+
ypos = Ncurses.getbegy(@win) + yplace
|
192
|
+
end
|
193
|
+
|
194
|
+
# Adjust the window if we need to.
|
195
|
+
xtmp = [xpos]
|
196
|
+
ytmp = [ypos]
|
197
|
+
RNDK.alignxy(@screen.window, xtmp, ytmp, @box_width, @box_height)
|
198
|
+
xpos = xtmp[0]
|
199
|
+
ypos = ytmp[0]
|
200
|
+
|
201
|
+
# Get the difference
|
202
|
+
xdiff = current_x - xpos
|
203
|
+
ydiff = current_y - ypos
|
204
|
+
|
205
|
+
# Move the window to the new location.
|
206
|
+
RNDK.moveCursesWindow(@win, -xdiff, -ydiff)
|
207
|
+
RNDK.moveCursesWindow(@shadow_win, -xdiff, -ydiff)
|
208
|
+
|
209
|
+
# Thouch the windows so they 'move'.
|
210
|
+
RNDK::Screen.refresh_window(@screen.window)
|
211
|
+
|
212
|
+
# Redraw the window, if they asked for it.
|
213
|
+
if refresh_flag
|
214
|
+
self.draw(@box)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# This allows the user to use the cursor keys to adjust the
|
219
|
+
# position of the widget.
|
220
|
+
def position
|
221
|
+
# Declare some variables
|
222
|
+
orig_x = Ncurses.getbegx(@win)
|
223
|
+
orig_y = Ncurses.getbegy(@win)
|
224
|
+
key = 0
|
225
|
+
|
226
|
+
# Let them move the widget around until they hit return
|
227
|
+
while key != Ncurses::KEY_ENTER && key != RNDK::KEY_RETURN
|
228
|
+
key = self.getch([])
|
229
|
+
if key == Ncurses::KEY_UP || key == '8'.ord
|
230
|
+
if Ncurses.getbegy(@win) > 0
|
231
|
+
self.move(0, -1, true, true)
|
232
|
+
else
|
233
|
+
RNDK.beep
|
234
|
+
end
|
235
|
+
elsif key == Ncurses::KEY_DOWN || key == '2'.ord
|
236
|
+
if Ncurses.getbegy(@win) + Ncurses.getmaxy(@win) < Ncurses.getmaxy(@screen.window) - 1
|
237
|
+
self.move(0, 1, true, true)
|
238
|
+
else
|
239
|
+
RNDK.beep
|
240
|
+
end
|
241
|
+
elsif key == Ncurses::KEY_LEFT || key == '4'.ord
|
242
|
+
if Ncurses.getbegx(@win) > 0
|
243
|
+
self.move(-1, 0, true, true)
|
244
|
+
else
|
245
|
+
RNDK.beep
|
246
|
+
end
|
247
|
+
elsif key == Ncurses::KEY_RIGHT || key == '6'.ord
|
248
|
+
if Ncurses.getbegx(@win) + @win.getmaxx < Ncurses.getmaxx(@screen.window) - 1
|
249
|
+
self.move(1, 0, true, true)
|
250
|
+
else
|
251
|
+
RNDK.beep
|
252
|
+
end
|
253
|
+
elsif key == '7'.ord
|
254
|
+
if Ncurses.getbegy(@win) > 0 && Ncurses.getbegx(@win) > 0
|
255
|
+
self.move(-1, -1, true, true)
|
256
|
+
else
|
257
|
+
RNDK.beep
|
258
|
+
end
|
259
|
+
elsif key == '9'.ord
|
260
|
+
if Ncurses.getbegx(@win) + @win.getmaxx < Ncurses.getmaxx(@screen.window) - 1 &&
|
261
|
+
Ncurses.getbegy(@win) > 0
|
262
|
+
self.move(1, -1, true, true)
|
263
|
+
else
|
264
|
+
RNDK.beep
|
265
|
+
end
|
266
|
+
elsif key == '1'.ord
|
267
|
+
if Ncurses.getbegx(@win) > 0 &&
|
268
|
+
Ncurses.getbegx(@win) + @win.getmaxx < Ncurses.getmaxx(@screen.window) - 1
|
269
|
+
self.move(-1, 1, true, true)
|
270
|
+
else
|
271
|
+
RNDK.beep
|
272
|
+
end
|
273
|
+
elsif key == '3'.ord
|
274
|
+
if Ncurses.getbegx(@win) + @win.getmaxx < Ncurses.getmaxx(@screen.window) - 1 &&
|
275
|
+
Ncurses.getbegy(@win) + Ncurses.getmaxy(@win) < Ncurses.getmaxy(@screen.window) - 1
|
276
|
+
self.move(1, 1, true, true)
|
277
|
+
else
|
278
|
+
RNDK.beep
|
279
|
+
end
|
280
|
+
elsif key == '5'.ord
|
281
|
+
self.move(RNDK::CENTER, RNDK::CENTER, false, true)
|
282
|
+
elsif key == 't'.ord
|
283
|
+
self.move(Ncurses.getbegx(@win), RNDK::TOP, false, true)
|
284
|
+
elsif key == 'b'.ord
|
285
|
+
self.move(Ncurses.getbegx(@win), RNDK::BOTTOM, false, true)
|
286
|
+
elsif key == 'l'.ord
|
287
|
+
self.move(RNDK::LEFT, Ncurses.getbegy(@win), false, true)
|
288
|
+
elsif key == 'r'
|
289
|
+
self.move(RNDK::RIGHT, Ncurses.getbegy(@win), false, true)
|
290
|
+
elsif key == 'c'
|
291
|
+
self.move(RNDK::CENTER, Ncurses.getbegy(@win), false, true)
|
292
|
+
elsif key == 'C'
|
293
|
+
self.move(Ncurses.getbegx(@win), RNDK::CENTER, false, true)
|
294
|
+
elsif key == RNDK::REFRESH
|
295
|
+
@screen.erase
|
296
|
+
@screen.refresh
|
297
|
+
elsif key == RNDK::KEY_ESC
|
298
|
+
self.move(orig_x, orig_y, false, true)
|
299
|
+
elsif key != RNDK::KEY_RETURN && key != Ncurses::KEY_ENTER
|
300
|
+
RNDK.beep
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
# This destroys the button object pointer.
|
306
|
+
def destroy
|
307
|
+
RNDK.deleteCursesWindow(@shadow_win)
|
308
|
+
RNDK.deleteCursesWindow(@win)
|
309
|
+
|
310
|
+
self.cleanBindings(:BUTTON)
|
311
|
+
|
312
|
+
RNDK::Screen.unregister(:BUTTON, self)
|
313
|
+
end
|
314
|
+
|
315
|
+
# This injects a single character into the widget.
|
316
|
+
def inject(input)
|
317
|
+
ret = -1
|
318
|
+
complete = false
|
319
|
+
|
320
|
+
self.setExitType(0)
|
321
|
+
|
322
|
+
# Check a predefined binding.
|
323
|
+
if self.checkBind(:BUTTON, input)
|
324
|
+
complete = true
|
325
|
+
else
|
326
|
+
case input
|
327
|
+
when RNDK::KEY_ESC
|
328
|
+
self.setExitType(input)
|
329
|
+
complete = true
|
330
|
+
when Ncurses::ERR
|
331
|
+
self.setExitType(input)
|
332
|
+
complete = true
|
333
|
+
when ' '.ord, RNDK::KEY_RETURN, Ncurses::KEY_ENTER
|
334
|
+
unless @callback.nil?
|
335
|
+
@callback.call(self)
|
336
|
+
end
|
337
|
+
self.setExitType(Ncurses::KEY_ENTER)
|
338
|
+
ret = 0
|
339
|
+
complete = true
|
340
|
+
when RNDK::REFRESH
|
341
|
+
@screen.erase
|
342
|
+
@screen.refresh
|
343
|
+
else
|
344
|
+
RNDK.beep
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
unless complete
|
349
|
+
self.setExitType(0)
|
350
|
+
end
|
351
|
+
|
352
|
+
@result_data = ret
|
353
|
+
return ret
|
354
|
+
end
|
355
|
+
|
356
|
+
def focus
|
357
|
+
self.drawText
|
358
|
+
Ncurses.wrefresh @win
|
359
|
+
end
|
360
|
+
|
361
|
+
def unfocus
|
362
|
+
self.drawText
|
363
|
+
Ncurses.wrefresh @win
|
364
|
+
end
|
365
|
+
|
366
|
+
def object_type
|
367
|
+
:BUTTON
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
@@ -0,0 +1,359 @@
|
|
1
|
+
require 'rndk'
|
2
|
+
|
3
|
+
module RNDK
|
4
|
+
class BUTTONBOX < RNDK::Widget
|
5
|
+
attr_reader :current_button
|
6
|
+
|
7
|
+
def initialize(rndkscreen, x_pos, y_pos, height, width, title, rows, cols,
|
8
|
+
buttons, button_count, highlight, box, shadow)
|
9
|
+
super()
|
10
|
+
parent_width = Ncurses.getmaxx(rndkscreen.window)
|
11
|
+
parent_height = Ncurses.getmaxy(rndkscreen.window)
|
12
|
+
col_width = 0
|
13
|
+
current_button = 0
|
14
|
+
@button = []
|
15
|
+
@button_len = []
|
16
|
+
@button_pos = []
|
17
|
+
@column_widths = []
|
18
|
+
|
19
|
+
if button_count <= 0
|
20
|
+
self.destroy
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
|
24
|
+
self.setBox(box)
|
25
|
+
|
26
|
+
# Set some default values for the widget.
|
27
|
+
@row_adjust = 0
|
28
|
+
@col_adjust = 0
|
29
|
+
|
30
|
+
# If the height is a negative value, the height will be
|
31
|
+
# ROWS-height, otherwise the height will be the given height.
|
32
|
+
box_height = RNDK.setWidgetDimension(parent_height, height, rows + 1)
|
33
|
+
|
34
|
+
# If the width is a negative value, the width will be
|
35
|
+
# COLS-width, otherwise the width will be the given width.
|
36
|
+
box_width = RNDK.setWidgetDimension(parent_width, width, 0)
|
37
|
+
|
38
|
+
box_width = self.setTitle(title, box_width)
|
39
|
+
|
40
|
+
# Translate the buttons string to a chtype array
|
41
|
+
(0...button_count).each do |x|
|
42
|
+
button_len = []
|
43
|
+
@button << RNDK.char2Chtype(buttons[x], button_len ,[])
|
44
|
+
@button_len << button_len[0]
|
45
|
+
end
|
46
|
+
|
47
|
+
# Set the button positions.
|
48
|
+
(0...cols).each do |x|
|
49
|
+
max_col_width = -2**31
|
50
|
+
|
51
|
+
# Look for the widest item in this column.
|
52
|
+
(0...rows).each do |y|
|
53
|
+
if current_button < button_count
|
54
|
+
max_col_width = [@button_len[current_button], max_col_width].max
|
55
|
+
current_button += 1
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Keep the maximum column width for this column.
|
60
|
+
@column_widths << max_col_width
|
61
|
+
col_width += max_col_width
|
62
|
+
end
|
63
|
+
box_width += 1
|
64
|
+
|
65
|
+
# Make sure we didn't extend beyond the dimensions of the window.
|
66
|
+
box_width = [box_width, parent_width].min
|
67
|
+
box_height = [box_height, parent_height].min
|
68
|
+
|
69
|
+
# Now we have to readjust the x and y positions
|
70
|
+
xtmp = [x_pos]
|
71
|
+
ytmp = [y_pos]
|
72
|
+
RNDK.alignxy(rndkscreen.window, xtmp, ytmp, box_width, box_height)
|
73
|
+
xpos = xtmp[0]
|
74
|
+
ypos = ytmp[0]
|
75
|
+
|
76
|
+
# Set up the buttonbox box attributes.
|
77
|
+
@screen = rndkscreen
|
78
|
+
@parent = rndkscreen.window
|
79
|
+
@win = Ncurses.newwin(box_height, box_width, ypos, xpos)
|
80
|
+
@shadow_win = nil
|
81
|
+
@button_count = button_count
|
82
|
+
@current_button = 0
|
83
|
+
@rows = rows
|
84
|
+
@cols = [button_count, cols].min
|
85
|
+
@box_height = box_height
|
86
|
+
@box_width = box_width
|
87
|
+
@highlight = highlight
|
88
|
+
@accepts_focus = true
|
89
|
+
@input_window = @win
|
90
|
+
@shadow = shadow
|
91
|
+
@button_attrib = Ncurses::A_NORMAL
|
92
|
+
|
93
|
+
# Set up the row adjustment.
|
94
|
+
if box_height - rows - @title_lines > 0
|
95
|
+
@row_adjust = (box_height - rows - @title_lines) / @rows
|
96
|
+
end
|
97
|
+
|
98
|
+
# Set the col adjustment
|
99
|
+
if box_width - col_width > 0
|
100
|
+
@col_adjust = ((box_width - col_width) / @cols) - 1
|
101
|
+
end
|
102
|
+
|
103
|
+
# If we couldn't create the window, we should return a null value.
|
104
|
+
if @win.nil?
|
105
|
+
self.destroy
|
106
|
+
return nil
|
107
|
+
end
|
108
|
+
Ncurses.keypad(@win, true)
|
109
|
+
|
110
|
+
# Was there a shadow?
|
111
|
+
if shadow
|
112
|
+
@shadow_win = Ncurses.newwin(box_height, box_width,
|
113
|
+
ypos + 1, xpos + 1)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Register this baby.
|
117
|
+
rndkscreen.register(:BUTTONBOX, self)
|
118
|
+
end
|
119
|
+
|
120
|
+
# This activates the widget.
|
121
|
+
def activate(actions)
|
122
|
+
# Draw the buttonbox box.
|
123
|
+
self.draw(@box)
|
124
|
+
|
125
|
+
if actions.nil? || actions.size == 0
|
126
|
+
while true
|
127
|
+
input = self.getch([])
|
128
|
+
|
129
|
+
# Inject the characer into the widget.
|
130
|
+
ret = self.inject(input)
|
131
|
+
if @exit_type != :EARLY_EXIT
|
132
|
+
return ret
|
133
|
+
end
|
134
|
+
end
|
135
|
+
else
|
136
|
+
# Inject each character one at a time.
|
137
|
+
actions.each do |action|
|
138
|
+
ret = self.inject(action)
|
139
|
+
if @exit_type != :EARLY_EXIT
|
140
|
+
return ret
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Set the exit type and exit
|
146
|
+
self.setExitType(0)
|
147
|
+
return -1
|
148
|
+
end
|
149
|
+
|
150
|
+
# This injects a single character into the widget.
|
151
|
+
def inject(input)
|
152
|
+
first_button = 0
|
153
|
+
last_button = @button_count - 1
|
154
|
+
pp_return = 1
|
155
|
+
ret = -1
|
156
|
+
complete = false
|
157
|
+
|
158
|
+
# Set the exit type
|
159
|
+
self.setExitType(0)
|
160
|
+
|
161
|
+
unless @pre_process_func.nil?
|
162
|
+
pp_return = @pre_process_func.call(:BUTTONBOX, self,
|
163
|
+
@pre_process_data, input)
|
164
|
+
end
|
165
|
+
|
166
|
+
# Should we continue?
|
167
|
+
if pp_return != 0
|
168
|
+
# Check for a key binding.
|
169
|
+
if self.checkBind(:BUTTONBOX, input)
|
170
|
+
complete = true
|
171
|
+
else
|
172
|
+
case input
|
173
|
+
when Ncurses::KEY_LEFT, Ncurses::KEY_BTAB, Ncurses::KEY_BACKSPACE
|
174
|
+
if @current_button - @rows < first_button
|
175
|
+
@current_button = last_button
|
176
|
+
else
|
177
|
+
@current_button -= @rows
|
178
|
+
end
|
179
|
+
when Ncurses::KEY_RIGHT, RNDK::KEY_TAB, ' '.ord
|
180
|
+
if @current_button + @rows > last_button
|
181
|
+
@current_button = first_button
|
182
|
+
else
|
183
|
+
@current_button += @rows
|
184
|
+
end
|
185
|
+
when Ncurses::KEY_UP
|
186
|
+
if @current_button -1 < first_button
|
187
|
+
@current_button = last_button
|
188
|
+
else
|
189
|
+
@current_button -= 1
|
190
|
+
end
|
191
|
+
when Ncurses::KEY_DOWN
|
192
|
+
if @current_button + 1 > last_button
|
193
|
+
@current_button = first_button
|
194
|
+
else
|
195
|
+
@current_button += 1
|
196
|
+
end
|
197
|
+
when RNDK::REFRESH
|
198
|
+
@screen.erase
|
199
|
+
@screen.refresh
|
200
|
+
when RNDK::KEY_ESC
|
201
|
+
self.setExitType(input)
|
202
|
+
complete = true
|
203
|
+
when Ncurses::ERR
|
204
|
+
self.setExitType(input)
|
205
|
+
complete = true
|
206
|
+
when RNDK::KEY_RETURN, Ncurses::KEY_ENTER
|
207
|
+
self.setExitType(input)
|
208
|
+
ret = @current_button
|
209
|
+
complete = true
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
if !complete && !(@post_process_func.nil?)
|
214
|
+
@post_process_func.call(:BUTTONBOX, self, @post_process_data,
|
215
|
+
input)
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
unless complete
|
221
|
+
self.drawButtons
|
222
|
+
self.setExitType(0)
|
223
|
+
end
|
224
|
+
|
225
|
+
@result_data = ret
|
226
|
+
return ret
|
227
|
+
end
|
228
|
+
|
229
|
+
# This sets multiple attributes of the widget.
|
230
|
+
def set(highlight, box)
|
231
|
+
self.setHighlight(highlight)
|
232
|
+
self.setBox(box)
|
233
|
+
end
|
234
|
+
|
235
|
+
# This sets the highlight attribute for the buttonboxes
|
236
|
+
def setHighlight(highlight)
|
237
|
+
@highlight = highlight
|
238
|
+
end
|
239
|
+
|
240
|
+
def getHighlight
|
241
|
+
return @highlight
|
242
|
+
end
|
243
|
+
|
244
|
+
# This sets th background attribute of the widget.
|
245
|
+
def setBKattr(attrib)
|
246
|
+
Ncurses.wbkgd(@win, attrib)
|
247
|
+
end
|
248
|
+
|
249
|
+
# This draws the buttonbox box widget.
|
250
|
+
def draw(box)
|
251
|
+
# Is there a shadow?
|
252
|
+
unless @shadow_win.nil?
|
253
|
+
Draw.drawShadow(@shadow_win)
|
254
|
+
end
|
255
|
+
|
256
|
+
# Box the widget if they asked.
|
257
|
+
if box
|
258
|
+
Draw.drawObjBox(@win, self)
|
259
|
+
end
|
260
|
+
|
261
|
+
# Draw in the title if there is one.
|
262
|
+
self.drawTitle @win
|
263
|
+
|
264
|
+
# Draw in the buttons.
|
265
|
+
self.drawButtons
|
266
|
+
end
|
267
|
+
|
268
|
+
# This draws the buttons on the button box widget.
|
269
|
+
def drawButtons
|
270
|
+
row = @title_lines + 1
|
271
|
+
col = @col_adjust / 2
|
272
|
+
current_button = 0
|
273
|
+
cur_row = -1
|
274
|
+
cur_col = -1
|
275
|
+
|
276
|
+
# Draw the buttons.
|
277
|
+
while current_button < @button_count
|
278
|
+
(0...@cols).each do |x|
|
279
|
+
row = @title_lines + @border_size
|
280
|
+
|
281
|
+
(0...@rows).each do |y|
|
282
|
+
attr = @button_attrib
|
283
|
+
if current_button == @current_button
|
284
|
+
attr = @highlight
|
285
|
+
cur_row = row
|
286
|
+
cur_col = col
|
287
|
+
end
|
288
|
+
Draw.writeChtypeAttrib(@win,
|
289
|
+
col,
|
290
|
+
row,
|
291
|
+
@button[current_button],
|
292
|
+
attr,
|
293
|
+
RNDK::HORIZONTAL,
|
294
|
+
0,
|
295
|
+
@button_len[current_button])
|
296
|
+
row += (1 + @row_adjust)
|
297
|
+
current_button += 1
|
298
|
+
end
|
299
|
+
col += @column_widths[x] + @col_adjust + @border_size
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
if cur_row >= 0 && cur_col >= 0
|
304
|
+
Ncurses.wmove(@win, cur_row, cur_col)
|
305
|
+
end
|
306
|
+
Ncurses.wrefresh @win
|
307
|
+
end
|
308
|
+
|
309
|
+
# This erases the buttonbox box from the screen.
|
310
|
+
def erase
|
311
|
+
if self.validRNDKObject
|
312
|
+
RNDK.eraseCursesWindow @win
|
313
|
+
RNDK.eraseCursesWindow @shadow_win
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
# This destroys the widget
|
318
|
+
def destroy
|
319
|
+
self.cleanTitle
|
320
|
+
|
321
|
+
RNDK.deleteCursesWindow @shadow_win
|
322
|
+
RNDK.deleteCursesWindow @win
|
323
|
+
|
324
|
+
self.cleanBindings(:BUTTONBOX)
|
325
|
+
|
326
|
+
RNDK::Screen.unregister(:BUTTONBOX, self)
|
327
|
+
end
|
328
|
+
|
329
|
+
def setCurrentButton(button)
|
330
|
+
if button >= 0 && button < @button_count
|
331
|
+
@current_button = button
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
def getCurrentButton
|
336
|
+
@current_button
|
337
|
+
end
|
338
|
+
|
339
|
+
def getButtonCount
|
340
|
+
@button_count
|
341
|
+
end
|
342
|
+
|
343
|
+
def focus
|
344
|
+
self.draw(@box)
|
345
|
+
end
|
346
|
+
|
347
|
+
def unfocus
|
348
|
+
self.draw(@box)
|
349
|
+
end
|
350
|
+
|
351
|
+
def object_type
|
352
|
+
:BUTTONBOX
|
353
|
+
end
|
354
|
+
|
355
|
+
def position
|
356
|
+
super(@win)
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|