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
@@ -0,0 +1,289 @@
|
|
1
|
+
module RNDK
|
2
|
+
module Traverse
|
3
|
+
def Traverse.resetRNDKScreen(screen)
|
4
|
+
refreshDataRNDKScreen(screen)
|
5
|
+
end
|
6
|
+
|
7
|
+
def Traverse.exitOKRNDKScreen(screen)
|
8
|
+
screen.exit_status = RNDK::Screen::EXITOK
|
9
|
+
end
|
10
|
+
|
11
|
+
def Traverse.exitCancelRNDKScreen(screen)
|
12
|
+
screen.exit_status = RNDK::Screen::EXITCANCEL
|
13
|
+
end
|
14
|
+
|
15
|
+
def Traverse.exitOKRNDKScreenOf(obj)
|
16
|
+
exitOKRNDKScreen(obj.screen)
|
17
|
+
end
|
18
|
+
|
19
|
+
def Traverse.exitCancelRNDKScreenOf(obj)
|
20
|
+
exitCancelRNDKScreen(obj.screen)
|
21
|
+
end
|
22
|
+
|
23
|
+
def Traverse.resetRNDKScreenOf(obj)
|
24
|
+
resetRNDKScreen(obj.screen)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the object on which the focus lies.
|
28
|
+
def Traverse.getRNDKFocusCurrent(screen)
|
29
|
+
result = nil
|
30
|
+
n = screen.object_focus
|
31
|
+
|
32
|
+
if n >= 0 && n < screen.object_count
|
33
|
+
result = screen.object[n]
|
34
|
+
end
|
35
|
+
|
36
|
+
return result
|
37
|
+
end
|
38
|
+
|
39
|
+
# Set focus to the next object, returning it.
|
40
|
+
def Traverse.setRNDKFocusNext(screen)
|
41
|
+
result = nil
|
42
|
+
curobj = nil
|
43
|
+
n = getFocusIndex(screen)
|
44
|
+
first = n
|
45
|
+
|
46
|
+
while true
|
47
|
+
n+= 1
|
48
|
+
if n >= screen.object_count
|
49
|
+
n = 0
|
50
|
+
end
|
51
|
+
curobj = screen.object[n]
|
52
|
+
if !(curobj.nil?) && curobj.accepts_focus
|
53
|
+
result = curobj
|
54
|
+
break
|
55
|
+
else
|
56
|
+
if n == first
|
57
|
+
break
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
setFocusIndex(screen, if !(result.nil?) then n else -1 end)
|
63
|
+
return result
|
64
|
+
end
|
65
|
+
|
66
|
+
# Set focus to the previous object, returning it.
|
67
|
+
def Traverse.setRNDKFocusPrevious(screen)
|
68
|
+
result = nil
|
69
|
+
curobj = nil
|
70
|
+
n = getFocusIndex(screen)
|
71
|
+
first = n
|
72
|
+
|
73
|
+
while true
|
74
|
+
n -= 1
|
75
|
+
if n < 0
|
76
|
+
n = screen.object_count - 1
|
77
|
+
end
|
78
|
+
curobj = screen.object[n]
|
79
|
+
if !(curobj.nil?) && curobj.accepts_focus
|
80
|
+
result = curobj
|
81
|
+
break
|
82
|
+
elsif n == first
|
83
|
+
break
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
setFocusIndex(screen, if !(result.nil?) then n else -1 end)
|
88
|
+
return result
|
89
|
+
end
|
90
|
+
|
91
|
+
# Set focus to a specific object, returning it.
|
92
|
+
# If the object cannot be found, return nil.
|
93
|
+
def Traverse.setRNDKFocusCurrent(screen, newobj)
|
94
|
+
result = nil
|
95
|
+
curobj = nil
|
96
|
+
n = getFocusIndex(screen)
|
97
|
+
first = n
|
98
|
+
|
99
|
+
while true
|
100
|
+
n += 1
|
101
|
+
if n >= screen.object_count
|
102
|
+
n = 0
|
103
|
+
end
|
104
|
+
|
105
|
+
curobj = screen.object[n]
|
106
|
+
if curobj == newobj
|
107
|
+
result = curobj
|
108
|
+
break
|
109
|
+
elsif n == first
|
110
|
+
break
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
setFocusIndex(screen, if !(result.nil?) then n else -1 end)
|
115
|
+
return result
|
116
|
+
end
|
117
|
+
|
118
|
+
# Set focus to the first object in the screen.
|
119
|
+
def Traverse.setRNDKFocusFirst(screen)
|
120
|
+
setFocusIndex(screen, screen.object_count - 1)
|
121
|
+
return switchFocus(setRNDKFocusNext(screen), nil)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Set focus to the last object in the screen.
|
125
|
+
def Traverse.setRNDKFocusLast(screen)
|
126
|
+
setFocusIndex(screen, 0)
|
127
|
+
return switchFocus(setRNDKFocusPrevious(screen), nil)
|
128
|
+
end
|
129
|
+
|
130
|
+
def Traverse.traverseRNDKOnce(screen, curobj, key_code,
|
131
|
+
function_key, func_menu_key)
|
132
|
+
case key_code
|
133
|
+
when Ncurses::KEY_BTAB
|
134
|
+
switchFocus(setRNDKFocusPrevious(screen), curobj)
|
135
|
+
when RNDK::KEY_TAB
|
136
|
+
switchFocus(setRNDKFocusNext(screen), curobj)
|
137
|
+
when RNDK.KEY_F(10)
|
138
|
+
# save data and exit
|
139
|
+
exitOKRNDKScreen(screen)
|
140
|
+
when RNDK.CTRL('X')
|
141
|
+
exitCancelRNDKScreen(screen)
|
142
|
+
when RNDK.CTRL('R')
|
143
|
+
# reset data to defaults
|
144
|
+
resetRNDKScreen(screen)
|
145
|
+
setFocus(curobj)
|
146
|
+
when RNDK::REFRESH
|
147
|
+
# redraw screen
|
148
|
+
screen.refresh
|
149
|
+
setFocus(curobj)
|
150
|
+
else
|
151
|
+
# not everyone wants menus, so we make them optional here
|
152
|
+
if !(func_menu_key.nil?) &&
|
153
|
+
(func_menu_key.call(key_code, function_key))
|
154
|
+
# find and enable drop down menu
|
155
|
+
screen.object.each do |object|
|
156
|
+
if !(object.nil?) && object.object_type == :MENU
|
157
|
+
Traverse.handleMenu(screen, object, curobj)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
else
|
161
|
+
curobj.inject(key_code)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Traverse the widgets on a screen.
|
167
|
+
def Traverse.traverseRNDKScreen(screen)
|
168
|
+
result = 0
|
169
|
+
curobj = setRNDKFocusFirst(screen)
|
170
|
+
|
171
|
+
unless curobj.nil?
|
172
|
+
refreshDataRNDKScreen(screen)
|
173
|
+
|
174
|
+
screen.exit_status = RNDK::Screen::NOEXIT
|
175
|
+
|
176
|
+
while !((curobj = getRNDKFocusCurrent(screen)).nil?) &&
|
177
|
+
screen.exit_status == RNDK::Screen::NOEXIT
|
178
|
+
function = []
|
179
|
+
key = curobj.getch(function)
|
180
|
+
|
181
|
+
# TODO look at more direct way to do this
|
182
|
+
check_menu_key = lambda do |key_code, function_key|
|
183
|
+
Traverse.checkMenuKey(key_code, function_key)
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
Traverse.traverseRNDKOnce(screen, curobj, key,
|
188
|
+
function[0], check_menu_key)
|
189
|
+
end
|
190
|
+
|
191
|
+
if screen.exit_status == RNDK::Screen::EXITOK
|
192
|
+
saveDataRNDKScreen(screen)
|
193
|
+
result = 1
|
194
|
+
end
|
195
|
+
end
|
196
|
+
return result
|
197
|
+
end
|
198
|
+
|
199
|
+
private
|
200
|
+
|
201
|
+
def Traverse.limitFocusIndex(screen, value)
|
202
|
+
if value >= screen.object_count || value < 0
|
203
|
+
0
|
204
|
+
else
|
205
|
+
value
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def Traverse.getFocusIndex(screen)
|
210
|
+
return limitFocusIndex(screen, screen.object_focus)
|
211
|
+
end
|
212
|
+
|
213
|
+
def Traverse.setFocusIndex(screen, value)
|
214
|
+
screen.object_focus = limitFocusIndex(screen, value)
|
215
|
+
end
|
216
|
+
|
217
|
+
def Traverse.unsetFocus(obj)
|
218
|
+
Ncurses.curs_set(0)
|
219
|
+
unless obj.nil?
|
220
|
+
obj.has_focus = false
|
221
|
+
obj.unfocus
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def Traverse.setFocus(obj)
|
226
|
+
unless obj.nil?
|
227
|
+
obj.has_focus = true
|
228
|
+
obj.focus
|
229
|
+
end
|
230
|
+
Ncurses.curs_set(1)
|
231
|
+
end
|
232
|
+
|
233
|
+
def Traverse.switchFocus(newobj, oldobj)
|
234
|
+
if oldobj != newobj
|
235
|
+
Traverse.unsetFocus(oldobj)
|
236
|
+
Traverse.setFocus(newobj)
|
237
|
+
end
|
238
|
+
return newobj
|
239
|
+
end
|
240
|
+
|
241
|
+
def Traverse.checkMenuKey(key_code, function_key)
|
242
|
+
key_code == RNDK::KEY_ESC && !function_key
|
243
|
+
end
|
244
|
+
|
245
|
+
def Traverse.handleMenu(screen, menu, oldobj)
|
246
|
+
done = false
|
247
|
+
|
248
|
+
switchFocus(menu, oldobj)
|
249
|
+
while !done
|
250
|
+
key = menu.getch([])
|
251
|
+
|
252
|
+
case key
|
253
|
+
when RNDK::KEY_TAB
|
254
|
+
done = true
|
255
|
+
when RNDK::KEY_ESC
|
256
|
+
# cleanup the menu
|
257
|
+
menu.inject(key)
|
258
|
+
done = true
|
259
|
+
else
|
260
|
+
done = (menu.inject(key) >= 0)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
if (newobj = Traverse.getRNDKFocusCurrent(screen)).nil?
|
265
|
+
newobj = Traverse.setRNDKFocusNext(screen)
|
266
|
+
end
|
267
|
+
|
268
|
+
return switchFocus(newobj, menu)
|
269
|
+
end
|
270
|
+
|
271
|
+
# Save data in widgets on a screen
|
272
|
+
def Traverse.saveDataRNDKScreen(screen)
|
273
|
+
screen.object.each do |object|
|
274
|
+
unless object.nil?
|
275
|
+
object.saveData
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
# Refresh data in widgets on a screen
|
281
|
+
def Traverse.refreshDataRNDKScreen(screen)
|
282
|
+
screen.object.each do |object|
|
283
|
+
unless object.nil?
|
284
|
+
object.refreshData
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
@@ -0,0 +1,506 @@
|
|
1
|
+
require 'rndk'
|
2
|
+
|
3
|
+
module RNDK
|
4
|
+
|
5
|
+
# Wrapper on common functionality between all RNDK Widgets.
|
6
|
+
#
|
7
|
+
class Widget
|
8
|
+
attr_accessor :screen_index, :screen, :has_focus, :is_visible, :box
|
9
|
+
attr_accessor :ULChar, :URChar, :LLChar, :LRChar, :HZChar, :VTChar, :BXAttr
|
10
|
+
attr_reader :binding_list, :accepts_focus, :exit_type, :border_size
|
11
|
+
|
12
|
+
@@g_paste_buffer = ''
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@has_focus = true
|
16
|
+
@is_visible = true
|
17
|
+
|
18
|
+
RNDK::ALL_OBJECTS << self
|
19
|
+
|
20
|
+
# set default line-drawing characters
|
21
|
+
@ULChar = Ncurses::ACS_ULCORNER
|
22
|
+
@URChar = Ncurses::ACS_URCORNER
|
23
|
+
@LLChar = Ncurses::ACS_LLCORNER
|
24
|
+
@LRChar = Ncurses::ACS_LRCORNER
|
25
|
+
@HZChar = Ncurses::ACS_HLINE
|
26
|
+
@VTChar = Ncurses::ACS_VLINE
|
27
|
+
@BXAttr = Ncurses::A_NORMAL
|
28
|
+
|
29
|
+
# set default exit-types
|
30
|
+
@exit_type = :NEVER_ACTIVATED
|
31
|
+
@early_exit = :NEVER_ACTIVATED
|
32
|
+
|
33
|
+
@accepts_focus = false
|
34
|
+
|
35
|
+
# Bound functions
|
36
|
+
@binding_list = {}
|
37
|
+
end
|
38
|
+
|
39
|
+
def object_type
|
40
|
+
# no type by default
|
41
|
+
:NULL
|
42
|
+
end
|
43
|
+
|
44
|
+
def validObjType(type)
|
45
|
+
# dummy version for now
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def Screen_XPOS(n)
|
50
|
+
n + @border_size
|
51
|
+
end
|
52
|
+
|
53
|
+
def Screen_YPOS(n)
|
54
|
+
n + @border_size + @title_lines
|
55
|
+
end
|
56
|
+
|
57
|
+
def draw(a)
|
58
|
+
end
|
59
|
+
|
60
|
+
def erase
|
61
|
+
end
|
62
|
+
|
63
|
+
def move(xplace, yplace, relative, refresh_flag)
|
64
|
+
self.move_specific(xplace, yplace, relative, refresh_flag, [@win, @shadow_win], [])
|
65
|
+
end
|
66
|
+
|
67
|
+
def move_specific(xplace, yplace, relative, refresh_flag, windows, subwidgets)
|
68
|
+
current_x = Ncurses.getbegx(@win)
|
69
|
+
current_y = Ncurses.getbegy(@win)
|
70
|
+
xpos = xplace
|
71
|
+
ypos = yplace
|
72
|
+
|
73
|
+
# If this is a relative move, then we will adjust where we want
|
74
|
+
# to move to.
|
75
|
+
if relative
|
76
|
+
xpos = Ncurses.getbegx(@win) + xplace
|
77
|
+
ypos = Ncurses.getbegy(@win) + yplace
|
78
|
+
end
|
79
|
+
|
80
|
+
# Adjust the window if we need to
|
81
|
+
xtmp = [xpos]
|
82
|
+
ytmp = [ypos]
|
83
|
+
RNDK.alignxy(@screen.window, xtmp, ytmp, @box_width, @box_height)
|
84
|
+
xpos = xtmp[0]
|
85
|
+
ypos = ytmp[0]
|
86
|
+
|
87
|
+
# Get the difference
|
88
|
+
xdiff = current_x - xpos
|
89
|
+
ydiff = current_y - ypos
|
90
|
+
|
91
|
+
# Move the window to the new location.
|
92
|
+
windows.each do |window|
|
93
|
+
RNDK.moveCursesWindow(window, -xdiff, -ydiff)
|
94
|
+
end
|
95
|
+
|
96
|
+
subwidgets.each do |subwidget|
|
97
|
+
subwidget.move(xplace, yplace, relative, false)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Touch the windows so they 'move'
|
101
|
+
RNDK::Screen.refresh_window(@screen.window)
|
102
|
+
|
103
|
+
# Redraw the window, if they asked for it
|
104
|
+
if refresh_flag
|
105
|
+
self.draw(@box)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def inject(a)
|
110
|
+
end
|
111
|
+
|
112
|
+
def setBox(box)
|
113
|
+
@box = box
|
114
|
+
@border_size = if @box then 1 else 0 end
|
115
|
+
end
|
116
|
+
|
117
|
+
def getBox
|
118
|
+
return @box
|
119
|
+
end
|
120
|
+
|
121
|
+
def focus
|
122
|
+
end
|
123
|
+
|
124
|
+
def unfocus
|
125
|
+
end
|
126
|
+
|
127
|
+
def saveData
|
128
|
+
end
|
129
|
+
|
130
|
+
def refreshData
|
131
|
+
end
|
132
|
+
|
133
|
+
def destroy
|
134
|
+
end
|
135
|
+
|
136
|
+
# Set the object's upper-left-corner line-drawing character.
|
137
|
+
def setULchar(ch)
|
138
|
+
@ULChar = ch
|
139
|
+
end
|
140
|
+
|
141
|
+
# Set the object's upper-right-corner line-drawing character.
|
142
|
+
def setURchar(ch)
|
143
|
+
@URChar = ch
|
144
|
+
end
|
145
|
+
|
146
|
+
# Set the object's lower-left-corner line-drawing character.
|
147
|
+
def setLLchar(ch)
|
148
|
+
@LLChar = ch
|
149
|
+
end
|
150
|
+
|
151
|
+
# Set the object's upper-right-corner line-drawing character.
|
152
|
+
def setLRchar(ch)
|
153
|
+
@LRChar = ch
|
154
|
+
end
|
155
|
+
|
156
|
+
# Set the object's horizontal line-drawing character
|
157
|
+
def setHZchar(ch)
|
158
|
+
@HZChar = ch
|
159
|
+
end
|
160
|
+
|
161
|
+
# Set the object's vertical line-drawing character
|
162
|
+
def setVTchar(ch)
|
163
|
+
@VTChar = ch
|
164
|
+
end
|
165
|
+
|
166
|
+
# Set the object's box-attributes.
|
167
|
+
def setBXattr(ch)
|
168
|
+
@BXAttr = ch
|
169
|
+
end
|
170
|
+
|
171
|
+
# This sets the background color of the widget.
|
172
|
+
def setBackgroundColor(color)
|
173
|
+
return if color.nil? || color == ''
|
174
|
+
|
175
|
+
junk1 = []
|
176
|
+
junk2 = []
|
177
|
+
|
178
|
+
# Convert the value of the environment variable to a chtype
|
179
|
+
holder = RNDK.char2Chtype(color, junk1, junk2)
|
180
|
+
|
181
|
+
# Set the widget's background color
|
182
|
+
self.SetBackAttrObj(holder[0])
|
183
|
+
end
|
184
|
+
|
185
|
+
# Set the widget's title.
|
186
|
+
def setTitle (title, box_width)
|
187
|
+
if !title.nil?
|
188
|
+
temp = title.split("\n")
|
189
|
+
@title_lines = temp.size
|
190
|
+
|
191
|
+
if box_width >= 0
|
192
|
+
max_width = 0
|
193
|
+
temp.each do |line|
|
194
|
+
len = []
|
195
|
+
align = []
|
196
|
+
holder = RNDK.char2Chtype(line, len, align)
|
197
|
+
max_width = [len[0], max_width].max
|
198
|
+
end
|
199
|
+
box_width = [box_width, max_width + 2 * @border_size].max
|
200
|
+
else
|
201
|
+
box_width = -(box_width - 1)
|
202
|
+
end
|
203
|
+
|
204
|
+
# For each line in the title convert from string to chtype array
|
205
|
+
title_width = box_width - (2 * @border_size)
|
206
|
+
@title = []
|
207
|
+
@title_pos = []
|
208
|
+
@title_len = []
|
209
|
+
(0...@title_lines).each do |x|
|
210
|
+
len_x = []
|
211
|
+
pos_x = []
|
212
|
+
@title << RNDK.char2Chtype(temp[x], len_x, pos_x)
|
213
|
+
@title_len.concat(len_x)
|
214
|
+
@title_pos << RNDK.justifyString(title_width, len_x[0], pos_x[0])
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
return box_width
|
219
|
+
end
|
220
|
+
|
221
|
+
# Draw the widget's title
|
222
|
+
def drawTitle(win)
|
223
|
+
(0...@title_lines).each do |x|
|
224
|
+
Draw.writeChtype(@win, @title_pos[x] + @border_size,
|
225
|
+
x + @border_size, @title[x], RNDK::HORIZONTAL, 0,
|
226
|
+
@title_len[x])
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# Remove storage for the widget's title.
|
231
|
+
def cleanTitle
|
232
|
+
@title_lines = ''
|
233
|
+
end
|
234
|
+
|
235
|
+
# Set data for preprocessing
|
236
|
+
def setPreProcess (fn, data)
|
237
|
+
@pre_process_func = fn
|
238
|
+
@pre_process_data = data
|
239
|
+
end
|
240
|
+
|
241
|
+
# Set data for postprocessing
|
242
|
+
def setPostProcess (fn, data)
|
243
|
+
@post_process_func = fn
|
244
|
+
@post_process_data = data
|
245
|
+
end
|
246
|
+
|
247
|
+
# Set the object's exit-type based on the input.
|
248
|
+
# The .exitType field should have been part of the Widget struct, but it
|
249
|
+
# is used too pervasively in older applications to move (yet).
|
250
|
+
def setExitType(ch)
|
251
|
+
case ch
|
252
|
+
when Ncurses::ERR
|
253
|
+
@exit_type = :ERROR
|
254
|
+
when RNDK::KEY_ESC
|
255
|
+
@exit_type = :ESCAPE_HIT
|
256
|
+
when RNDK::KEY_TAB, Ncurses::KEY_ENTER, RNDK::KEY_RETURN
|
257
|
+
@exit_type = :NORMAL
|
258
|
+
when 0
|
259
|
+
@exit_type = :EARLY_EXIT
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def validRNDKObject
|
264
|
+
result = false
|
265
|
+
if RNDK::ALL_OBJECTS.include?(self)
|
266
|
+
result = self.validObjType(self.object_type)
|
267
|
+
end
|
268
|
+
result
|
269
|
+
end
|
270
|
+
|
271
|
+
def getc
|
272
|
+
rndktype = self.object_type
|
273
|
+
test = self.bindableObject(rndktype)
|
274
|
+
result = Ncurses.wgetch @input_window
|
275
|
+
|
276
|
+
if result >= 0 && !(test.nil?) && test.binding_list.include?(result) &&
|
277
|
+
test.binding_list[result][0] == :getc
|
278
|
+
result = test.binding_list[result][1]
|
279
|
+
elsif test.nil? || !(test.binding_list.include?(result)) ||
|
280
|
+
test.binding_list[result][0].nil?
|
281
|
+
case result
|
282
|
+
when "\r".ord, "\n".ord
|
283
|
+
result = Ncurses::KEY_ENTER
|
284
|
+
when "\t".ord
|
285
|
+
result = RNDK::KEY_TAB
|
286
|
+
when RNDK::DELETE
|
287
|
+
result = Ncurses::KEY_DC
|
288
|
+
when "\b".ord
|
289
|
+
result = Ncurses::KEY_BACKSPACE
|
290
|
+
when RNDK::BEGOFLINE
|
291
|
+
result = Ncurses::KEY_HOME
|
292
|
+
when RNDK::ENDOFLINE
|
293
|
+
result = Ncurses::KEY_END
|
294
|
+
when RNDK::FORCHAR
|
295
|
+
result = Ncurses::KEY_RIGHT
|
296
|
+
when RNDK::BACKCHAR
|
297
|
+
result = Ncurses::KEY_LEFT
|
298
|
+
when RNDK::NEXT
|
299
|
+
result = RNDK::KEY_TAB
|
300
|
+
when RNDK::PREV
|
301
|
+
result = Ncurses::KEY_BTAB
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
return result
|
306
|
+
end
|
307
|
+
|
308
|
+
def getch(function_key)
|
309
|
+
key = self.getc
|
310
|
+
function_key << (key >= Ncurses::KEY_MIN && key <= Ncurses::KEY_MAX)
|
311
|
+
return key
|
312
|
+
end
|
313
|
+
|
314
|
+
def bindableObject(rndktype)
|
315
|
+
if rndktype != self.object_type
|
316
|
+
return nil
|
317
|
+
elsif [:FSELECT, :ALPHALIST].include?(self.object_type)
|
318
|
+
return @entry_field
|
319
|
+
else
|
320
|
+
return self
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
def bind(type, key, function, data)
|
325
|
+
obj = self.bindableObject(type)
|
326
|
+
if key.ord < Ncurses::KEY_MAX && !(obj.nil?)
|
327
|
+
if key.ord != 0
|
328
|
+
obj.binding_list[key.ord] = [function, data]
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
def unbind(type, key)
|
334
|
+
obj = self.bindableObject(type)
|
335
|
+
unless obj.nil?
|
336
|
+
obj.binding_list.delete(key)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def cleanBindings(type)
|
341
|
+
obj = self.bindableObject(type)
|
342
|
+
if !(obj.nil?) && !(obj.binding_list.nil?)
|
343
|
+
obj.binding_list.clear
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
# Checks to see if the binding for the key exists:
|
348
|
+
# If it does then it runs the command and returns its value, normally true
|
349
|
+
# If it doesn't it returns a false. This way we can 'overwrite' coded
|
350
|
+
# bindings.
|
351
|
+
def checkBind(type, key)
|
352
|
+
obj = self.bindableObject(type)
|
353
|
+
if !(obj.nil?) && obj.binding_list.include?(key)
|
354
|
+
function = obj.binding_list[key][0]
|
355
|
+
data = obj.binding_list[key][1]
|
356
|
+
|
357
|
+
if function == :getc
|
358
|
+
return data
|
359
|
+
else
|
360
|
+
return function.call(type, obj, data, key)
|
361
|
+
end
|
362
|
+
end
|
363
|
+
return false
|
364
|
+
end
|
365
|
+
|
366
|
+
# Checks to see if the binding for the key exists.
|
367
|
+
def isBind(type, key)
|
368
|
+
result = false
|
369
|
+
obj = self.bindableObject(type)
|
370
|
+
unless obj.nil?
|
371
|
+
result = obj.binding_list.include?(key)
|
372
|
+
end
|
373
|
+
|
374
|
+
return result
|
375
|
+
end
|
376
|
+
|
377
|
+
# Allows the user to move the Widget around the screen
|
378
|
+
# via the cursor/keypad keys.
|
379
|
+
#
|
380
|
+
# The following key bindings can be used to move the
|
381
|
+
# Widget around the screen:
|
382
|
+
#
|
383
|
+
# Up Arrow:: Moves the widget up one row.
|
384
|
+
# Down Arrow:: Moves the widget down one row.
|
385
|
+
# Left Arrow:: Moves the widget left one column
|
386
|
+
# Right Arrow:: Moves the widget right one column
|
387
|
+
# 1:: Moves the widget down one row and left one column.
|
388
|
+
# 2:: Moves the widget down one row.
|
389
|
+
# 3:: Moves the widget down one row and right one column.
|
390
|
+
# 4:: Moves the widget left one column.
|
391
|
+
# 5:: Centers the widget both vertically and horizontally.
|
392
|
+
# 6:: Moves the widget right one column
|
393
|
+
# 7:: Moves the widget up one row and left one column.
|
394
|
+
# 8:: Moves the widget up one row.
|
395
|
+
# 9:: Moves the widget up one row and right one column.
|
396
|
+
# t:: Moves the widget to the top of the screen.
|
397
|
+
# b:: Moves the widget to the bottom of the screen.
|
398
|
+
# l:: Moves the widget to the left of the screen.
|
399
|
+
# r:: Moves the widget to the right of the screen.
|
400
|
+
# c:: Centers the widget between the left and right of the window.
|
401
|
+
# C:: Centers the widget between the top and bottom of the window.
|
402
|
+
# Escape:: Returns the widget to its original position.
|
403
|
+
# Return:: Exits the function and leaves the Widget where it was.
|
404
|
+
#
|
405
|
+
def position(win)
|
406
|
+
parent = @screen.window
|
407
|
+
orig_x = Ncurses.getbegx win
|
408
|
+
orig_y = Ncurses.getbegy win
|
409
|
+
beg_x = Ncurses.getbegx parent
|
410
|
+
beg_y = Ncurses.getbegy parent
|
411
|
+
end_x = beg_x + Ncurses.getmaxx(@screen.window)
|
412
|
+
end_y = beg_y + Ncurses.getmaxy(@screen.window)
|
413
|
+
|
414
|
+
loop do
|
415
|
+
key = self.getch([])
|
416
|
+
|
417
|
+
# Let them move the widget around until they hit return.
|
418
|
+
break if [RNDK::KEY_RETURN, Ncurses::KEY_ENTER].include? key
|
419
|
+
|
420
|
+
case key
|
421
|
+
when Ncurses::KEY_UP, '8'.ord
|
422
|
+
if Ncurses.getbegy(win) > beg_y
|
423
|
+
self.move(0, -1, true, true)
|
424
|
+
else
|
425
|
+
RNDK.beep
|
426
|
+
end
|
427
|
+
when Ncurses::KEY_DOWN, '2'.ord
|
428
|
+
if (Ncurses.getbegy(win) + Ncurses.getmaxy(win)) < end_y
|
429
|
+
self.move(0, 1, true, true)
|
430
|
+
else
|
431
|
+
RNDK.beep
|
432
|
+
end
|
433
|
+
when Ncurses::KEY_LEFT, '4'.ord
|
434
|
+
if Ncurses.getbegx(win) > beg_x
|
435
|
+
self.move(-1, 0, true, true)
|
436
|
+
else
|
437
|
+
RNDK.beep
|
438
|
+
end
|
439
|
+
when Ncurses::KEY_RIGHT, '6'.ord
|
440
|
+
if (Ncurses.getbegx(win) + Ncurses.getmaxx(win)) < end_x
|
441
|
+
self.move(1, 0, true, true)
|
442
|
+
else
|
443
|
+
RNDK.beep
|
444
|
+
end
|
445
|
+
when '7'.ord
|
446
|
+
if Ncurses.getbegy(win) > beg_y && Ncurses.getbegx(win) > beg_x
|
447
|
+
self.move(-1, -1, true, true)
|
448
|
+
else
|
449
|
+
RNDK.beep
|
450
|
+
end
|
451
|
+
when '9'.ord
|
452
|
+
if (Ncurses.getbegx(win) + Ncurses.getmaxx(win)) < end_x && Ncurses.getbegy(win) > beg_y
|
453
|
+
self.move(1, -1, true, true)
|
454
|
+
else
|
455
|
+
RNDK.beep
|
456
|
+
end
|
457
|
+
when '1'.ord
|
458
|
+
if Ncurses.getbegx(win) > beg_x && (Ncurses.getbegy(win) + Ncurses.getmaxy(win)) < end_y
|
459
|
+
self.move(-1, 1, true, true)
|
460
|
+
else
|
461
|
+
RNDK.beep
|
462
|
+
end
|
463
|
+
when '3'.ord
|
464
|
+
if (Ncurses.getbegx(win) + Ncurses.getmaxx(win)) < end_x &&
|
465
|
+
(Ncurses.getbegy(win) + Ncurses.getmaxy(win)) < end_y
|
466
|
+
self.move(1, 1, true, true)
|
467
|
+
else
|
468
|
+
RNDK.beep
|
469
|
+
end
|
470
|
+
|
471
|
+
when '5'.ord
|
472
|
+
self.move(RNDK::CENTER, RNDK::CENTER, false, true)
|
473
|
+
|
474
|
+
when 't'.ord
|
475
|
+
self.move(Ncurses.getbegx(win), RNDK::TOP, false, true)
|
476
|
+
|
477
|
+
when 'b'.ord
|
478
|
+
self.move(Ncurses.getbegx(win), RNDK::BOTTOM, false, true)
|
479
|
+
|
480
|
+
when 'l'.ord
|
481
|
+
self.move(RNDK::LEFT, Ncurses.getbegy(win), false, true)
|
482
|
+
|
483
|
+
when 'r'.ord
|
484
|
+
self.move(RNDK::RIGHT, Ncurses.getbegy(win), false, true)
|
485
|
+
|
486
|
+
when 'c'.ord
|
487
|
+
self.move(RNDK::CENTER, Ncurses.getbegy(win), false, true)
|
488
|
+
|
489
|
+
when 'C'.ord
|
490
|
+
self.move(Ncurses.getbegx(win), RNDK::CENTER, false, true)
|
491
|
+
|
492
|
+
when RNDK::REFRESH
|
493
|
+
@screen.erase
|
494
|
+
@screen.refresh
|
495
|
+
|
496
|
+
when RNDK::KEY_ESC
|
497
|
+
self.move(orig_x, orig_y, false, true)
|
498
|
+
else
|
499
|
+
RNDK.beep
|
500
|
+
end
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|