cdk 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cdk.rb +7 -866
  3. data/lib/cdk/cdk_objs.rb +46 -423
  4. data/lib/cdk/components.rb +28 -0
  5. data/lib/cdk/{alphalist.rb → components/alphalist.rb} +9 -6
  6. data/lib/cdk/components/button.rb +405 -0
  7. data/lib/cdk/{buttonbox.rb → components/buttonbox.rb} +11 -11
  8. data/lib/cdk/{calendar.rb → components/calendar.rb} +13 -13
  9. data/lib/cdk/components/dialog.rb +343 -0
  10. data/lib/cdk/{dscale.rb → components/dscale.rb} +0 -0
  11. data/lib/cdk/{entry.rb → components/entry.rb} +18 -18
  12. data/lib/cdk/{fscale.rb → components/fscale.rb} +1 -1
  13. data/lib/cdk/{fselect.rb → components/fselect.rb} +16 -13
  14. data/lib/cdk/{fslider.rb → components/fslider.rb} +1 -1
  15. data/lib/cdk/components/graph.rb +386 -0
  16. data/lib/cdk/{histogram.rb → components/histogram.rb} +3 -3
  17. data/lib/cdk/{itemlist.rb → components/itemlist.rb} +14 -14
  18. data/lib/cdk/{label.rb → components/label.rb} +7 -7
  19. data/lib/cdk/{marquee.rb → components/marquee.rb} +7 -7
  20. data/lib/cdk/{matrix.rb → components/matrix.rb} +27 -27
  21. data/lib/cdk/{mentry.rb → components/mentry.rb} +18 -18
  22. data/lib/cdk/{menu.rb → components/menu.rb} +18 -18
  23. data/lib/cdk/{radio.rb → components/radio.rb} +12 -12
  24. data/lib/cdk/{scale.rb → components/scale.rb} +13 -13
  25. data/lib/cdk/{scroll.rb → components/scroll.rb} +23 -386
  26. data/lib/cdk/{scroller.rb → components/scroller.rb} +1 -1
  27. data/lib/cdk/{selection.rb → components/selection.rb} +14 -14
  28. data/lib/cdk/{slider.rb → components/slider.rb} +15 -15
  29. data/lib/cdk/{swindow.rb → components/swindow.rb} +14 -14
  30. data/lib/cdk/{template.rb → components/template.rb} +18 -18
  31. data/lib/cdk/{uscale.rb → components/uscale.rb} +0 -0
  32. data/lib/cdk/{uslider.rb → components/uslider.rb} +0 -0
  33. data/lib/cdk/{viewer.rb → components/viewer.rb} +88 -18
  34. data/lib/cdk/constants.rb +54 -0
  35. data/lib/cdk/display.rb +30 -35
  36. data/lib/cdk/draw.rb +4 -6
  37. data/lib/cdk/helpers/file.rb +43 -0
  38. data/lib/cdk/helpers/types.rb +13 -0
  39. data/lib/cdk/helpers/window.rb +64 -0
  40. data/lib/cdk/mixins/alignments.rb +55 -0
  41. data/lib/cdk/mixins/bindings.rb +73 -0
  42. data/lib/cdk/mixins/borders.rb +62 -0
  43. data/lib/cdk/mixins/common_controls.rb +14 -0
  44. data/lib/cdk/mixins/converters.rb +358 -0
  45. data/lib/cdk/mixins/exit_conditions.rb +31 -0
  46. data/lib/cdk/mixins/focusable.rb +17 -0
  47. data/lib/cdk/mixins/formattable.rb +15 -0
  48. data/lib/cdk/mixins/has_screen.rb +23 -0
  49. data/lib/cdk/mixins/has_title.rb +64 -0
  50. data/lib/cdk/mixins/justifications.rb +26 -0
  51. data/lib/cdk/mixins/list_support.rb +31 -0
  52. data/lib/cdk/mixins/movement.rb +140 -0
  53. data/lib/cdk/mixins/window_hooks.rb +18 -0
  54. data/lib/cdk/mixins/window_input.rb +61 -0
  55. data/lib/cdk/screen.rb +27 -3
  56. metadata +51 -29
  57. data/lib/cdk/dialog.rb +0 -727
@@ -0,0 +1,28 @@
1
+ require_relative 'components/alphalist'
2
+ require_relative 'components/buttonbox'
3
+ require_relative 'components/calendar'
4
+ require_relative 'components/dialog'
5
+ require_relative 'components/graph'
6
+ require_relative 'components/dscale'
7
+ require_relative 'components/entry'
8
+ require_relative 'components/fscale'
9
+ require_relative 'components/fslider'
10
+ require_relative 'components/fselect'
11
+ require_relative 'components/histogram'
12
+ require_relative 'components/itemlist'
13
+ require_relative 'components/label'
14
+ require_relative 'components/marquee'
15
+ require_relative 'components/matrix'
16
+ require_relative 'components/mentry'
17
+ require_relative 'components/menu'
18
+ require_relative 'components/radio'
19
+ require_relative 'components/scale'
20
+ require_relative 'components/scroll'
21
+ require_relative 'components/button'
22
+ require_relative 'components/selection'
23
+ require_relative 'components/slider'
24
+ require_relative 'components/swindow'
25
+ require_relative 'components/template'
26
+ require_relative 'components/uscale'
27
+ require_relative 'components/uslider'
28
+ require_relative 'components/viewer'
@@ -1,7 +1,10 @@
1
- require_relative 'cdk_objs'
1
+ require_relative '../cdk_objs'
2
+ require_relative '../mixins/list_support'
2
3
 
3
4
  module CDK
4
5
  class ALPHALIST < CDK::CDKOBJS
6
+ include ListSupport
7
+
5
8
  attr_reader :scroll_field, :entry_field, :list
6
9
 
7
10
  def initialize(cdkscreen, xplace, yplace, height, width, title, label,
@@ -35,14 +38,14 @@ module CDK
35
38
  # Translate the label string to a chtype array
36
39
  if label.size > 0
37
40
  lentmp = []
38
- chtype_label = CDK.char2Chtype(label, lentmp, [])
41
+ chtype_label = char2Chtype(label, lentmp, [])
39
42
  label_len = lentmp[0]
40
43
  end
41
44
 
42
45
  # Rejustify the x and y positions if we need to.
43
46
  xtmp = [xplace]
44
47
  ytmp = [yplace]
45
- CDK.alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
48
+ alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
46
49
  xpos = xtmp[0]
47
50
  ypos = ytmp[0]
48
51
 
@@ -96,7 +99,7 @@ module CDK
96
99
  alphalist.injectMyScroller(key)
97
100
 
98
101
  # Set the value in the entry field.
99
- current = CDK.chtype2Char(scrollp.item[scrollp.current_item])
102
+ current = chtype2Char(scrollp.item[scrollp.current_item])
100
103
  entry.setValue(current)
101
104
  entry.draw(entry.box)
102
105
  return true
@@ -118,7 +121,7 @@ module CDK
118
121
  end
119
122
 
120
123
  # Look for a unique word match.
121
- index = CDK.searchList(alphalist.list, alphalist.list.size, entry.info)
124
+ index = search_list(alphalist.list, alphalist.list.size, entry.info)
122
125
 
123
126
  # if the index is less than zero, return we didn't find a match
124
127
  if index < 0
@@ -227,7 +230,7 @@ module CDK
227
230
 
228
231
  if pattern.size == 0
229
232
  empty = true
230
- elsif (index = CDK.searchList(alphalist.list,
233
+ elsif (index = search_list(alphalist.list,
231
234
  alphalist.list.size, pattern)) >= 0
232
235
  # XXX: original uses n scroll downs/ups for <10 positions change
233
236
  scrollp.setPosition(index)
@@ -0,0 +1,405 @@
1
+ require_relative '../cdk_objs'
2
+
3
+ module CDK
4
+ class BUTTON < CDK::CDKOBJS
5
+ include Formattable
6
+
7
+ def initialize(cdkscreen, xplace, yplace, text, callback, box, shadow)
8
+ super()
9
+ parent_width = cdkscreen.window.getmaxx
10
+ parent_height = cdkscreen.window.getmaxy
11
+ box_width = 0
12
+ xpos = xplace
13
+ ypos = yplace
14
+
15
+ self.setBox(box)
16
+ box_height = 1 + 2 * @border_size
17
+
18
+ # Translate the string to a chtype array.
19
+ info_len = []
20
+ info_pos = []
21
+
22
+ if skip_formatting?
23
+ @info = text
24
+ @info_len = @info.size
25
+ @info_pos = 0
26
+
27
+ else
28
+ @orig_text = text
29
+ @info = char2Chtype(text, info_len, info_pos)
30
+ @info_len = info_len[0]
31
+ @info_pos = info_pos[0]
32
+ end
33
+
34
+ box_width = [box_width, @info_len].max + 2 * @border_size
35
+
36
+ # Create the string alignments.
37
+ @info_pos = justify_string(box_width - 2 * @border_size,
38
+ @info_len, @info_pos)
39
+
40
+ # Make sure we didn't extend beyond the dimensions of the window.
41
+ box_width = if box_width > parent_width
42
+ then parent_width
43
+ else box_width
44
+ end
45
+ box_height = if box_height > parent_height
46
+ then parent_height
47
+ else box_height
48
+ end
49
+
50
+ # Rejustify the x and y positions if we need to.
51
+ xtmp = [xpos]
52
+ ytmp = [ypos]
53
+ alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
54
+ xpos = xtmp[0]
55
+ ypos = ytmp[0]
56
+
57
+ # Create the button.
58
+ @screen = cdkscreen
59
+ # ObjOf (button)->fn = &my_funcs;
60
+ @parent = cdkscreen.window
61
+ @win = Ncurses::WINDOW.new(box_height, box_width, ypos, xpos)
62
+ @shadow_win = nil
63
+ @xpos = xpos
64
+ @ypos = ypos
65
+ @box_width = box_width
66
+ @box_height = box_height
67
+ @callback = callback
68
+ @input_window = @win
69
+ @accepts_focus = true
70
+ @shadow = shadow
71
+
72
+ if @win.nil?
73
+ self.destroy
74
+ return nil
75
+ end
76
+
77
+ @win.keypad(true)
78
+
79
+ # If a shadow was requested, then create the shadow window.
80
+ if shadow
81
+ @shadow_win = Ncurses::WINDOW.new(box_height, box_width,
82
+ ypos + 1, xpos + 1)
83
+ end
84
+
85
+ # Register this baby.
86
+ cdkscreen.register(:BUTTON, self)
87
+ end
88
+
89
+ def skip_formatting=(b)
90
+ super
91
+
92
+ if skip_formatting?
93
+ @info = @orig_text
94
+ @info_len = @info.size
95
+ @info_pos = 0
96
+ end
97
+ end
98
+
99
+ # This was added for the builder.
100
+ def activate(actions)
101
+ self.draw(@box)
102
+ ret = -1
103
+
104
+ if actions.nil? || actions.size == 0
105
+ while true
106
+ input = self.getch([])
107
+
108
+ # Inject the character into the widget.
109
+ ret = self.inject(input)
110
+ if @exit_type != :EARLY_EXIT
111
+ return ret
112
+ end
113
+ end
114
+ else
115
+ # Inject each character one at a time.
116
+ actions.each do |x|
117
+ ret = self.inject(x)
118
+ if @exit_type == :EARLY_EXIT
119
+ return ret
120
+ end
121
+ end
122
+ end
123
+
124
+ # Set the exit type and exit
125
+ self.setExitType(0)
126
+ return -1
127
+ end
128
+
129
+ # This sets multiple attributes of the widget.
130
+ def set(mesg, box)
131
+ self.setMessage(mesg)
132
+ self.setBox(box)
133
+ end
134
+
135
+ # This sets the information within the button.
136
+ def setMessage(info)
137
+ info_len = []
138
+ info_pos = []
139
+ if skip_formatting?
140
+ @info = info
141
+ @info_len = info.size
142
+ @info_pos = 0
143
+ else
144
+ @orig_text = info
145
+ @info = char2Chtype(info, info_len, info_pos)
146
+ @info_len = info_len[0]
147
+ @info_pos = justify_string(@box_width - 2 * @border_size,
148
+ @info_len, @info_pos)
149
+ end
150
+
151
+ # Redraw the button widget.
152
+ self.erase
153
+ self.draw(box)
154
+ end
155
+
156
+ def getMessage
157
+ return @info
158
+ end
159
+
160
+ # This sets the background attribute of the widget.
161
+ def setBKattr(attrib)
162
+ @win.wbkgd(attrib)
163
+ end
164
+
165
+ def drawText
166
+ # XXX : so we can draw unicode
167
+ if skip_formatting?
168
+ @win.mvaddstr(@border_size, @border_size, @info)
169
+ return
170
+ end
171
+
172
+ box_width = @box_width
173
+
174
+ # Draw in the message.
175
+ (0...(box_width - 2 * @border_size)).each do |i|
176
+ pos = @info_pos
177
+ len = @info_len
178
+ if i >= pos && (i - pos) < len
179
+ c = @info[i - pos]
180
+ else
181
+ c = ' '
182
+ end
183
+
184
+ if @has_focus
185
+ c = Ncurses::A_REVERSE | c
186
+ end
187
+
188
+ @win.mvwaddch(@border_size, i + @border_size, c)
189
+ end
190
+ end
191
+
192
+ # This draws the button widget
193
+ def draw(box)
194
+ # Is there a shadow?
195
+ unless @shadow_win.nil?
196
+ Draw.drawShadow(@shadow_win)
197
+ end
198
+
199
+ # Box the widget if asked.
200
+ if @box
201
+ Draw.drawObjBox(@win, self)
202
+ end
203
+ self.drawText
204
+ wrefresh
205
+ end
206
+
207
+ # This erases the button widget.
208
+ def erase
209
+ if self.validCDKObject
210
+ CDK.eraseCursesWindow(@win)
211
+ CDK.eraseCursesWindow(@shadow_win)
212
+ end
213
+ end
214
+
215
+ # This moves the button field to the given location.
216
+ def move(xplace, yplace, relative, refresh_flag)
217
+ current_x = @win.getbegx
218
+ current_y = @win.getbegy
219
+ xpos = xplace
220
+ ypos = yplace
221
+
222
+ # If this is a relative move, then we will adjust where we want
223
+ # to move to.
224
+ if relative
225
+ xpos = @win.getbegx + xplace
226
+ ypos = @win.getbegy + yplace
227
+ end
228
+
229
+ # Adjust the window if we need to.
230
+ xtmp = [xpos]
231
+ ytmp = [ypos]
232
+ alignxy(@screen.window, xtmp, ytmp, @box_width, @box_height)
233
+ xpos = xtmp[0]
234
+ ypos = ytmp[0]
235
+
236
+ # Get the difference
237
+ xdiff = current_x - xpos
238
+ ydiff = current_y - ypos
239
+
240
+ # Move the window to the new location.
241
+ CDK.moveCursesWindow(@win, -xdiff, -ydiff)
242
+ CDK.moveCursesWindow(@shadow_win, -xdiff, -ydiff)
243
+
244
+ # Thouch the windows so they 'move'.
245
+ CDK::SCREEN.refreshCDKWindow(@screen.window)
246
+
247
+ # Redraw the window, if they asked for it.
248
+ if refresh_flag
249
+ self.draw(@box)
250
+ end
251
+ end
252
+
253
+ # This allows the user to use the cursor keys to adjust the
254
+ # position of the widget.
255
+ def position
256
+ # Declare some variables
257
+ orig_x = @win.getbegx
258
+ orig_y = @win.getbegy
259
+ key = 0
260
+
261
+ # Let them move the widget around until they hit return
262
+ while key != Ncurses::KEY_ENTER && key != CDK::KEY_RETURN
263
+ key = self.getch([])
264
+ if key == Ncurses::KEY_UP || key == '8'.ord
265
+ if @win.getbegy > 0
266
+ self.move(0, -1, true, true)
267
+ else
268
+ CDK.Beep
269
+ end
270
+ elsif key == Ncurses::KEY_DOWN || key == '2'.ord
271
+ if @win.getbegy + @win.getmaxy < @screen.window.getmaxy - 1
272
+ self.move(0, 1, true, true)
273
+ else
274
+ CDK.Beep
275
+ end
276
+ elsif key == Ncurses::KEY_LEFT || key == '4'.ord
277
+ if @win.getbegx > 0
278
+ self.move(-1, 0, true, true)
279
+ else
280
+ CDK.Beep
281
+ end
282
+ elsif key == Ncurses::KEY_RIGHT || key == '6'.ord
283
+ if @win.getbegx + @win.getmaxx < @screen.window.getmaxx - 1
284
+ self.move(1, 0, true, true)
285
+ else
286
+ CDK.Beep
287
+ end
288
+ elsif key == '7'.ord
289
+ if @win.getbegy > 0 && @win.getbegx > 0
290
+ self.move(-1, -1, true, true)
291
+ else
292
+ CDK.Beep
293
+ end
294
+ elsif key == '9'.ord
295
+ if @win.getbegx + @win.getmaxx < @screen.window.getmaxx - 1 &&
296
+ @win.getbegy > 0
297
+ self.move(1, -1, true, true)
298
+ else
299
+ CDK.Beep
300
+ end
301
+ elsif key == '1'.ord
302
+ if @win.getbegx > 0 &&
303
+ @win.getbegx + @win.getmaxx < @screen.window.getmaxx - 1
304
+ self.move(-1, 1, true, true)
305
+ else
306
+ CDK.Beep
307
+ end
308
+ elsif key == '3'.ord
309
+ if @win.getbegx + @win.getmaxx < @screen.window.getmaxx - 1 &&
310
+ @win.getbegy + @win.getmaxy < @screen.window.getmaxy - 1
311
+ self.move(1, 1, true, true)
312
+ else
313
+ CDK.Beep
314
+ end
315
+ elsif key == '5'.ord
316
+ self.move(CDK::CENTER, CDK::CENTER, false, true)
317
+ elsif key == 't'.ord
318
+ self.move(@win.getbegx, CDK::TOP, false, true)
319
+ elsif key == 'b'.ord
320
+ self.move(@win.getbegx, CDK::BOTTOM, false, true)
321
+ elsif key == 'l'.ord
322
+ self.move(CDK::LEFT, @win.getbegy, false, true)
323
+ elsif key == 'r'
324
+ self.move(CDK::RIGHT, @win.getbegy, false, true)
325
+ elsif key == 'c'
326
+ self.move(CDK::CENTER, @win.getbegy, false, true)
327
+ elsif key == 'C'
328
+ self.move(@win.getbegx, CDK::CENTER, false, true)
329
+ elsif key == CDK::REFRESH
330
+ @screen.erase
331
+ @screen.refresh
332
+ elsif key == CDK::KEY_ESC
333
+ self.move(orig_x, orig_y, false, true)
334
+ elsif key != CDK::KEY_RETURN && key != Ncurses::KEY_ENTER
335
+ CDK.Beep
336
+ end
337
+ end
338
+ end
339
+
340
+ # This destroys the button object pointer.
341
+ def destroy
342
+ CDK.deleteCursesWindow(@shadow_win)
343
+ CDK.deleteCursesWindow(@win)
344
+
345
+ self.cleanBindings(:BUTTON)
346
+
347
+ CDK::SCREEN.unregister(:BUTTON, self)
348
+ end
349
+
350
+ # This injects a single character into the widget.
351
+ def inject(input)
352
+ ret = -1
353
+ @complete = false
354
+
355
+ self.setExitType(0)
356
+
357
+ # Check a predefined binding.
358
+ if self.checkBind(:BUTTON, input)
359
+ @complete = true
360
+ else
361
+ case input
362
+ when CDK::KEY_ESC
363
+ self.setExitType(input)
364
+ @complete = true
365
+ when Ncurses::ERR
366
+ self.setExitType(input)
367
+ @complete = true
368
+ when ' '.ord, CDK::KEY_RETURN, Ncurses::KEY_ENTER
369
+ unless @callback.nil?
370
+ @callback.call(self)
371
+ end
372
+ self.setExitType(Ncurses::KEY_ENTER)
373
+ ret = 0
374
+ @complete = true
375
+ when CDK::REFRESH
376
+ @screen.erase
377
+ @screen.refresh
378
+ else
379
+ CDK.Beep
380
+ end
381
+ end
382
+
383
+ unless @complete
384
+ self.setExitType(0)
385
+ end
386
+
387
+ @result_data = ret
388
+ return ret
389
+ end
390
+
391
+ def focus
392
+ self.drawText
393
+ wrefresh
394
+ end
395
+
396
+ def unfocus
397
+ self.drawText
398
+ wrefresh
399
+ end
400
+
401
+ def object_type
402
+ :BUTTON
403
+ end
404
+ end # class BUTTON
405
+ end # module CDK