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
@@ -1,36 +1,54 @@
1
+ require_relative './mixins/alignments'
2
+ require_relative './mixins/justifications'
3
+ require_relative './mixins/converters'
4
+ require_relative './mixins/movement'
5
+ require_relative './mixins/borders'
6
+ require_relative './mixins/focusable'
7
+ require_relative './mixins/bindings'
8
+ require_relative './mixins/exit_conditions'
9
+ require_relative './mixins/has_screen'
10
+ require_relative './mixins/has_title'
11
+ require_relative './mixins/window_input'
12
+ require_relative './mixins/window_hooks'
13
+ require_relative './mixins/common_controls'
14
+ require_relative './mixins/formattable'
15
+
1
16
  module CDK
2
17
  class CDKOBJS
3
- attr_accessor :screen_index, :screen, :has_focus, :is_visible, :box
4
- attr_accessor :ULChar, :URChar, :LLChar, :LRChar, :HZChar, :VTChar, :BXAttr
5
- attr_reader :binding_list, :accepts_focus, :exit_type, :border_size
18
+ include Alignments
19
+ include Justifications
20
+ include Converters
21
+ include Movement
22
+ include Borders
23
+ include Focusable
24
+ include Bindings
25
+ include ExitConditions
26
+ include HasScreen
27
+ include HasTitle
28
+ include WindowInput
29
+ include WindowHooks
6
30
 
7
31
  @@g_paste_buffer = ''
8
32
 
9
33
  def initialize
10
- @has_focus = true
11
- @is_visible = true
12
-
13
34
  CDK::ALL_OBJECTS << self
14
35
 
15
- # set default line-drawing characters
16
- @ULChar = Ncurses::ACS_ULCORNER
17
- @URChar = Ncurses::ACS_URCORNER
18
- @LLChar = Ncurses::ACS_LLCORNER
19
- @LRChar = Ncurses::ACS_LRCORNER
20
- @HZChar = Ncurses::ACS_HLINE
21
- @VTChar = Ncurses::ACS_VLINE
22
- @BXAttr = Ncurses::A_NORMAL
23
-
24
- # set default exit-types
25
- @exit_type = :NEVER_ACTIVATED
26
- @early_exit = :NEVER_ACTIVATED
36
+ init_title
37
+ init_borders
38
+ init_focus
39
+ init_bindings
40
+ init_exit_conditions
41
+ init_screen
42
+ end
27
43
 
28
- @accepts_focus = false
44
+ ###
29
45
 
30
- # Bound functions
31
- @binding_list = {}
46
+ def timeout(v)
47
+ @input_window.timeout(v) if @input_window
32
48
  end
33
49
 
50
+ ###
51
+
34
52
  def object_type
35
53
  # no type by default
36
54
  :NULL
@@ -41,129 +59,15 @@ module CDK
41
59
  true
42
60
  end
43
61
 
44
- def SCREEN_XPOS(n)
45
- n + @border_size
46
- end
47
-
48
- def SCREEN_YPOS(n)
49
- n + @border_size + @title_lines
50
- end
51
-
52
- def draw(a)
53
- end
54
-
55
- def erase
56
- end
57
-
58
- def move(xplace, yplace, relative, refresh_flag)
59
- self.move_specific(xplace, yplace, relative, refresh_flag,
60
- [@win, @shadow_win], [])
61
- end
62
-
63
- def move_specific(xplace, yplace, relative, refresh_flag,
64
- windows, subwidgets)
65
- current_x = @win.getbegx
66
- current_y = @win.getbegy
67
- xpos = xplace
68
- ypos = yplace
69
-
70
- # If this is a relative move, then we will adjust where we want
71
- # to move to.
72
- if relative
73
- xpos = @win.getbegx + xplace
74
- ypos = @win.getbegy + yplace
75
- end
76
-
77
- # Adjust the window if we need to
78
- xtmp = [xpos]
79
- ytmp = [ypos]
80
- CDK.alignxy(@screen.window, xtmp, ytmp, @box_width, @box_height)
81
- xpos = xtmp[0]
82
- ypos = ytmp[0]
83
-
84
- # Get the difference
85
- xdiff = current_x - xpos
86
- ydiff = current_y - ypos
87
-
88
- # Move the window to the new location.
89
- windows.each do |window|
90
- CDK.moveCursesWindow(window, -xdiff, -ydiff)
91
- end
92
-
93
- subwidgets.each do |subwidget|
94
- subwidget.move(xplace, yplace, relative, false)
95
- end
96
-
97
- # Touch the windows so they 'move'
98
- CDK::SCREEN.refreshCDKWindow(@screen.window)
99
-
100
- # Redraw the window, if they asked for it
101
- if refresh_flag
102
- self.draw(@box)
62
+ def validCDKObject
63
+ result = false
64
+ if CDK::ALL_OBJECTS.include?(self)
65
+ result = self.validObjType(self.object_type)
103
66
  end
67
+ return result
104
68
  end
105
69
 
106
- def inject(a)
107
- end
108
-
109
- def setBox(box)
110
- @box = box
111
- @border_size = if @box then 1 else 0 end
112
- end
113
-
114
- def getBox
115
- return @box
116
- end
117
-
118
- def focus
119
- end
120
-
121
- def unfocus
122
- end
123
-
124
- def saveData
125
- end
126
-
127
- def refreshData
128
- end
129
-
130
- def destroy
131
- end
132
-
133
- # Set the object's upper-left-corner line-drawing character.
134
- def setULchar(ch)
135
- @ULChar = ch
136
- end
137
-
138
- # Set the object's upper-right-corner line-drawing character.
139
- def setURchar(ch)
140
- @URChar = ch
141
- end
142
-
143
- # Set the object's lower-left-corner line-drawing character.
144
- def setLLchar(ch)
145
- @LLChar = ch
146
- end
147
-
148
- # Set the object's upper-right-corner line-drawing character.
149
- def setLRchar(ch)
150
- @LRChar = ch
151
- end
152
-
153
- # Set the object's horizontal line-drawing character
154
- def setHZchar(ch)
155
- @HZChar = ch
156
- end
157
-
158
- # Set the object's vertical line-drawing character
159
- def setVTchar(ch)
160
- @VTChar = ch
161
- end
162
-
163
- # Set the object's box-attributes.
164
- def setBXattr(ch)
165
- @BXAttr = ch
166
- end
70
+ ###
167
71
 
168
72
  # This sets the background color of the widget.
169
73
  def setBackgroundColor(color)
@@ -173,291 +77,10 @@ module CDK
173
77
  junk2 = []
174
78
 
175
79
  # Convert the value of the environment variable to a chtype
176
- holder = CDK.char2Chtype(color, junk1, junk2)
80
+ holder = char2Chtype(color, junk1, junk2)
177
81
 
178
82
  # Set the widget's background color
179
83
  self.setBKattr(holder[0])
180
84
  end
181
-
182
- # Set the widget's title.
183
- def setTitle (title, box_width)
184
- if !title.nil?
185
- temp = title.split("\n")
186
- @title_lines = temp.size
187
-
188
- if box_width >= 0
189
- max_width = 0
190
- temp.each do |line|
191
- len = []
192
- align = []
193
- holder = CDK.char2Chtype(line, len, align)
194
- max_width = [len[0], max_width].max
195
- end
196
- box_width = [box_width, max_width + 2 * @border_size].max
197
- else
198
- box_width = -(box_width - 1)
199
- end
200
-
201
- # For each line in the title convert from string to chtype array
202
- title_width = box_width - (2 * @border_size)
203
- @title = []
204
- @title_pos = []
205
- @title_len = []
206
- (0...@title_lines).each do |x|
207
- len_x = []
208
- pos_x = []
209
- @title << CDK.char2Chtype(temp[x], len_x, pos_x)
210
- @title_len.concat(len_x)
211
- @title_pos << CDK.justifyString(title_width, len_x[0], pos_x[0])
212
- end
213
- end
214
-
215
- return box_width
216
- end
217
-
218
- # Draw the widget's title
219
- def drawTitle(win)
220
- (0...@title_lines).each do |x|
221
- Draw.writeChtype(@win, @title_pos[x] + @border_size,
222
- x + @border_size, @title[x], CDK::HORIZONTAL, 0,
223
- @title_len[x])
224
- end
225
- end
226
-
227
- # Remove storage for the widget's title.
228
- def cleanTitle
229
- @title_lines = ''
230
- end
231
-
232
- # Set data for preprocessing
233
- def setPreProcess (fn, data)
234
- @pre_process_func = fn
235
- @pre_process_data = data
236
- end
237
-
238
- # Set data for postprocessing
239
- def setPostProcess (fn, data)
240
- @post_process_func = fn
241
- @post_process_data = data
242
- end
243
-
244
- # Set the object's exit-type based on the input.
245
- # The .exitType field should have been part of the CDKOBJS struct, but it
246
- # is used too pervasively in older applications to move (yet).
247
- def setExitType(ch)
248
- case ch
249
- when Ncurses::ERR
250
- @exit_type = :ERROR
251
- when CDK::KEY_ESC
252
- @exit_type = :ESCAPE_HIT
253
- when CDK::KEY_TAB, Ncurses::KEY_ENTER, CDK::KEY_RETURN
254
- @exit_type = :NORMAL
255
- when 0
256
- @exit_type = :EARLY_EXIT
257
- end
258
- end
259
-
260
- def validCDKObject
261
- result = false
262
- if CDK::ALL_OBJECTS.include?(self)
263
- result = self.validObjType(self.object_type)
264
- end
265
- return result
266
- end
267
-
268
- def getc
269
- cdktype = self.object_type
270
- test = self.bindableObject(cdktype)
271
- result = @input_window.wgetch
272
-
273
- if result >= 0 && !(test.nil?) && test.binding_list.include?(result) &&
274
- test.binding_list[result][0] == :getc
275
- result = test.binding_list[result][1]
276
- elsif test.nil? || !(test.binding_list.include?(result)) ||
277
- test.binding_list[result][0].nil?
278
- case result
279
- when "\r".ord, "\n".ord
280
- result = Ncurses::KEY_ENTER
281
- when "\t".ord
282
- result = CDK::KEY_TAB
283
- when CDK::DELETE
284
- result = Ncurses::KEY_DC
285
- when "\b".ord
286
- result = Ncurses::KEY_BACKSPACE
287
- when CDK::BEGOFLINE
288
- result = Ncurses::KEY_HOME
289
- when CDK::ENDOFLINE
290
- result = Ncurses::KEY_END
291
- when CDK::FORCHAR
292
- result = Ncurses::KEY_RIGHT
293
- when CDK::BACKCHAR
294
- result = Ncurses::KEY_LEFT
295
- when CDK::NEXT
296
- result = CDK::KEY_TAB
297
- when CDK::PREV
298
- result = Ncurses::KEY_BTAB
299
- end
300
- end
301
-
302
- return result
303
- end
304
-
305
- def getch(function_key)
306
- key = self.getc
307
- function_key << (key >= Ncurses::KEY_MIN && key <= Ncurses::KEY_MAX)
308
- return key
309
- end
310
-
311
- def bindableObject(cdktype)
312
- if cdktype != self.object_type
313
- return nil
314
- elsif [:FSELECT, :ALPHALIST].include?(self.object_type)
315
- return @entry_field
316
- else
317
- return self
318
- end
319
- end
320
-
321
- def bind(type, key, function, data)
322
- obj = self.bindableObject(type)
323
- if key.ord < Ncurses::KEY_MAX && !(obj.nil?)
324
- if key.ord != 0
325
- obj.binding_list[key.ord] = [function, data]
326
- end
327
- end
328
- end
329
-
330
- def unbind(type, key)
331
- obj = self.bindableObject(type)
332
- unless obj.nil?
333
- obj.binding_list.delete(key)
334
- end
335
- end
336
-
337
- def cleanBindings(type)
338
- obj = self.bindableObject(type)
339
- if !(obj.nil?) && !(obj.binding_list.nil?)
340
- obj.binding_list.clear
341
- end
342
- end
343
-
344
- # This checks to see if the binding for the key exists:
345
- # If it does then it runs the command and returns its value, normally true
346
- # If it doesn't it returns a false. This way we can 'overwrite' coded
347
- # bindings.
348
- def checkBind(type, key)
349
- obj = self.bindableObject(type)
350
- if !(obj.nil?) && obj.binding_list.include?(key)
351
- function = obj.binding_list[key][0]
352
- data = obj.binding_list[key][1]
353
-
354
- if function == :getc
355
- return data
356
- else
357
- return function.call(type, obj, data, key)
358
- end
359
- end
360
- return false
361
- end
362
-
363
- # This checks to see if the binding for the key exists.
364
- def isBind(type, key)
365
- result = false
366
- obj = self.bindableObject(type)
367
- unless obj.nil?
368
- result = obj.binding_list.include?(key)
369
- end
370
-
371
- return result
372
- end
373
-
374
- # This allows the user to use the cursor keys to adjust the
375
- # postion of the widget.
376
- def position(win)
377
- parent = @screen.window
378
- orig_x = win.getbegx
379
- orig_y = win.getbegy
380
- beg_x = parent.getbegx
381
- beg_y = parent.getbegy
382
- end_x = beg_x + @screen.window.getmaxx
383
- end_y = beg_y + @screen.window.getmaxy
384
-
385
- # Let them move the widget around until they hit return.
386
- while !([CDK::KEY_RETURN, Ncurses::KEY_ENTER].include?(
387
- key = self.getch([])))
388
- case key
389
- when Ncurses::KEY_UP, '8'.ord
390
- if win.getbegy > beg_y
391
- self.move(0, -1, true, true)
392
- else
393
- CDK.Beep
394
- end
395
- when Ncurses::KEY_DOWN, '2'.ord
396
- if (win.getbegy + win.getmaxy) < end_y
397
- self.move(0, 1, true, true)
398
- else
399
- CDK.Beep
400
- end
401
- when Ncurses::KEY_LEFT, '4'.ord
402
- if win.getbegx > beg_x
403
- self.move(-1, 0, true, true)
404
- else
405
- CDK.Beep
406
- end
407
- when Ncurses::KEY_RIGHT, '6'.ord
408
- if (win.getbegx + win.getmaxx) < end_x
409
- self.move(1, 0, true, true)
410
- else
411
- CDK.Beep
412
- end
413
- when '7'.ord
414
- if win.getbegy > beg_y && win.getbegx > beg_x
415
- self.move(-1, -1, true, true)
416
- else
417
- CDK.Beep
418
- end
419
- when '9'.ord
420
- if (win.getbegx + win.getmaxx) < end_x && win.getbegy > beg_y
421
- self.move(1, -1, true, true)
422
- else
423
- CDK.Beep
424
- end
425
- when '1'.ord
426
- if win.getbegx > beg_x && (win.getbegy + win.getmaxy) < end_y
427
- self.move(-1, 1, true, true)
428
- else
429
- CDK.Beep
430
- end
431
- when '3'.ord
432
- if (win.getbegx + win.getmaxx) < end_x &&
433
- (win.getbegy + win.getmaxy) < end_y
434
- self.move(1, 1, true, true)
435
- else
436
- CDK.Beep
437
- end
438
- when '5'.ord
439
- self.move(CDK::CENTER, CDK::CENTER, false, true)
440
- when 't'.ord
441
- self.move(win.getbegx, CDK::TOP, false, true)
442
- when 'b'.ord
443
- self.move(win.getbegx, CDK::BOTTOM, false, true)
444
- when 'l'.ord
445
- self.move(CDK::LEFT, win.getbegy, false, true)
446
- when 'r'.ord
447
- self.move(CDK::RIGHT, win.getbegy, false, true)
448
- when 'c'.ord
449
- self.move(CDK::CENTER, win.getbegy, false, true)
450
- when 'C'.ord
451
- self.move(win.getbegx, CDK::CENTER, false, true)
452
- when CDK::REFRESH
453
- @screen.erase
454
- @screen.refresh
455
- when CDK::KEY_ESC
456
- self.move(orig_x, orig_y, false, true)
457
- else
458
- CDK.Beep
459
- end
460
- end
461
- end
462
85
  end
463
86
  end