cdk 0.9.0 → 0.10.0

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 (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,4 +1,4 @@
1
- require_relative 'cdk_objs'
1
+ require_relative '../cdk_objs'
2
2
 
3
3
  module CDK
4
4
  class MENU < CDK::CDKOBJS
@@ -69,7 +69,7 @@ module CDK
69
69
  (CDK::MENU::TITLELINES...subsize[x]).to_a.each do |y|
70
70
  y0 = y - CDK::MENU::TITLELINES
71
71
  sublist_len = []
72
- @sublist[x1][y0] = CDK.char2Chtype(menu_list[x][y],
72
+ @sublist[x1][y0] = char2Chtype(menu_list[x][y],
73
73
  sublist_len, [])
74
74
  @sublist_len[x1][y0] = sublist_len[0]
75
75
  max = [max, sublist_len[0]].max
@@ -82,7 +82,7 @@ module CDK
82
82
  end
83
83
 
84
84
  title_len = []
85
- @title[x1] = CDK.char2Chtype(menu_list[x][0], title_len, [])
85
+ @title[x1] = char2Chtype(menu_list[x][0], title_len, [])
86
86
  @title_len[x1] = title_len[0]
87
87
  @subsize[x1] = subsize[x] - CDK::MENU::TITLELINES
88
88
  @title_win[x1] = cdkscreen.window.subwin(CDK::MENU::TITLELINES,
@@ -185,7 +185,7 @@ module CDK
185
185
  # Draw the new sub-title.
186
186
  self.selectItem(@current_subtitle, 0)
187
187
 
188
- @pull_win[@current_title].wrefresh
188
+ wrefresh(@pull_win[@current_title])
189
189
  end
190
190
 
191
191
  @input_window = @title_win[@current_title]
@@ -214,7 +214,7 @@ module CDK
214
214
  def inject(input)
215
215
  pp_return = 1
216
216
  ret = -1
217
- complete = false
217
+ @complete = false
218
218
 
219
219
  # Set the exit type.
220
220
  self.setExitType(0)
@@ -231,7 +231,7 @@ module CDK
231
231
  if pp_return != 0
232
232
  # Check for key bindings.
233
233
  if self.checkBind(:MENU, input)
234
- complete = true
234
+ @complete = true
235
235
  else
236
236
  case input
237
237
  when Ncurses::KEY_LEFT
@@ -247,16 +247,16 @@ module CDK
247
247
  self.setExitType(input)
248
248
  @last_selection = @current_title * 100 + @current_subtitle
249
249
  ret = @last_selection
250
- complete = true
250
+ @complete = true
251
251
  when CDK::KEY_ESC
252
252
  self.cleanUpMenu
253
253
  self.setExitType(input)
254
254
  @last_selection = -1
255
255
  ret = @last_selection
256
- complete = true
256
+ @complete = true
257
257
  when Ncurses::ERR
258
258
  self.setExitType(input)
259
- complete = true
259
+ @complete = true
260
260
  when CDK::REFRESH
261
261
  self.erase
262
262
  self.refresh
@@ -264,12 +264,12 @@ module CDK
264
264
  end
265
265
 
266
266
  # Should we call a post-process?
267
- if !complete && !(@post_process_func.nil?)
267
+ if !@complete && !(@post_process_func.nil?)
268
268
  @post_process_func.call(:MENU, self, @post_process_data, input)
269
269
  end
270
270
  end
271
271
 
272
- if !complete
272
+ if !@complete
273
273
  self.setExitType(0)
274
274
  end
275
275
 
@@ -308,13 +308,13 @@ module CDK
308
308
  end
309
309
 
310
310
  self.selectItem(@current_subtitle, x0)
311
- @pull_win[@current_title].wrefresh
311
+ wrefresh(@pull_win[@current_title])
312
312
 
313
313
  # Highlight the title.
314
314
  Draw.writeChtypeAttrib(@title_win[@current_title], 0, 0,
315
315
  @title[@current_title], @title_attr, CDK::HORIZONTAL,
316
316
  0, @title_len[@current_title])
317
- @title_win[@current_title].wrefresh
317
+ wrefresh(@title_win[@current_title])
318
318
  end
319
319
 
320
320
  # Erase a menu item subwindow
@@ -323,7 +323,7 @@ module CDK
323
323
 
324
324
  # Redraw the sub-menu title.
325
325
  self.drawTitle(@current_title)
326
- @title_win[@current_title].wrefresh
326
+ wrefresh(@title_win[@current_title])
327
327
  end
328
328
 
329
329
  # Draw the menu.
@@ -331,7 +331,7 @@ module CDK
331
331
  # Draw in the menu titles.
332
332
  (0...@menu_items).each do |x|
333
333
  self.drawTitle(x)
334
- @title_win[x].wrefresh
334
+ wrefresh(@title_win[x])
335
335
  end
336
336
  end
337
337
 
@@ -373,9 +373,9 @@ module CDK
373
373
  if self.validCDKObject
374
374
  (0...@menu_items).each do |x|
375
375
  @title_win[x].werase
376
- @title_win[x].wrefresh
376
+ wrefresh(@title_win[x])
377
377
  @pull_win[x].werase
378
- @pull_win[x].wrefresh
378
+ wrefresh(@pull_win[x])
379
379
  end
380
380
  end
381
381
  end
@@ -420,7 +420,7 @@ module CDK
420
420
  def cleanUpMenu
421
421
  # Erase the sub-menu.
422
422
  self.eraseSubwin
423
- @pull_win[@current_title].wrefresh
423
+ wrefresh(@pull_win[@current_title])
424
424
 
425
425
  # Refresh the screen.
426
426
  @screen.refresh
@@ -64,7 +64,7 @@ module CDK
64
64
  # Rejustify the x and y positions if we need to.
65
65
  xtmp = [xplace]
66
66
  ytmp = [yplace]
67
- CDK.alignxy(cdkscreen.window, xtmp, ytmp, @box_width, @box_height)
67
+ alignxy(cdkscreen.window, xtmp, ytmp, @box_width, @box_height)
68
68
  xpos = xtmp[0]
69
69
  ypos = ytmp[0]
70
70
 
@@ -130,7 +130,7 @@ module CDK
130
130
  xpos = self.SCREEN_XPOS(0) + scrollbar_adj
131
131
 
132
132
  @input_window.wmove(ypos, xpos)
133
- @input_window.wrefresh
133
+ wrefresh(@input_window)
134
134
  end
135
135
 
136
136
  # This actually manages the radio widget.
@@ -167,7 +167,7 @@ module CDK
167
167
  def inject(input)
168
168
  pp_return = 1
169
169
  ret = -1
170
- complete = false
170
+ @complete = false
171
171
 
172
172
  # Set the exit type
173
173
  self.setExitType(0)
@@ -186,7 +186,7 @@ module CDK
186
186
  if pp_return != 0
187
187
  # Check for a predefined key binding.
188
188
  if self.checkBind(:RADIO, input)
189
- complete = true
189
+ @complete = true
190
190
  else
191
191
  case input
192
192
  when Ncurses::KEY_UP
@@ -214,14 +214,14 @@ module CDK
214
214
  when CDK::KEY_ESC
215
215
  self.setExitType(input)
216
216
  ret = -1
217
- complete = true
217
+ @complete = true
218
218
  when Ncurses::ERR
219
219
  self.setExitType(input)
220
- complete = true
220
+ @complete = true
221
221
  when CDK::KEY_TAB, CDK::KEY_RETURN, Ncurses::KEY_ENTER
222
222
  self.setExitType(input)
223
223
  ret = @selected_item
224
- complete = true
224
+ @complete = true
225
225
  when CDK::REFRESH
226
226
  @screen.erase
227
227
  @screen.refresh
@@ -229,12 +229,12 @@ module CDK
229
229
  end
230
230
 
231
231
  # Should we call a post-process?
232
- if !complete && !(@post_process_func.nil?)
232
+ if !@complete && !(@post_process_func.nil?)
233
233
  @post_process_func.call(:RADIO, self, @post_process_data, input)
234
234
  end
235
235
  end
236
236
 
237
- if !complete
237
+ if !@complete
238
238
  self.drawList(@box)
239
239
  self.setExitType(0)
240
240
  end
@@ -399,7 +399,7 @@ module CDK
399
399
 
400
400
  def getItems(list)
401
401
  (0...@list_size).each do |j|
402
- list << CDK.chtype2Char(@item[j])
402
+ list << chtype2Char(@item[j])
403
403
  end
404
404
  return @list_size
405
405
  end
@@ -484,14 +484,14 @@ module CDK
484
484
  (0...list_size).each do |j|
485
485
  lentmp = []
486
486
  postmp = []
487
- new_list << CDK.char2Chtype(list[j], lentmp, postmp)
487
+ new_list << char2Chtype(list[j], lentmp, postmp)
488
488
  new_len << lentmp[0]
489
489
  new_pos << postmp[0]
490
490
  if new_list[j].nil? || new_list[j].size == 0
491
491
  status = false
492
492
  break
493
493
  end
494
- new_pos[j] = CDK.justifyString(box_width, new_len[j], new_pos[j]) + 3
494
+ new_pos[j] = justify_string(box_width, new_len[j], new_pos[j]) + 3
495
495
  widest_item = [widest_item, new_len[j]].max
496
496
  end
497
497
  if status
@@ -1,4 +1,4 @@
1
- require_relative 'cdk_objs'
1
+ require_relative '../cdk_objs'
2
2
 
3
3
  module CDK
4
4
  class SCALE < CDK::CDKOBJS
@@ -37,7 +37,7 @@ module CDK
37
37
  # Translate the label string to a chtype array
38
38
  unless label.nil?
39
39
  label_len = []
40
- @label = CDK.char2Chtype(label, label_len, [])
40
+ @label = char2Chtype(label, label_len, [])
41
41
  @label_len = label_len[0]
42
42
  box_width = @label_len + field_width + 2
43
43
  end
@@ -57,7 +57,7 @@ module CDK
57
57
  # Rejustify the x and y positions if we need to.
58
58
  xtmp = [xplace]
59
59
  ytmp = [yplace]
60
- CDK.alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
60
+ alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
61
61
  xpos = xtmp[0]
62
62
  ypos = ytmp[0]
63
63
 
@@ -286,7 +286,7 @@ module CDK
286
286
  def inject(input)
287
287
  pp_return = 1
288
288
  ret = -1
289
- complete = false
289
+ @complete = false
290
290
 
291
291
  # Set the exit type.
292
292
  self.setExitType(0)
@@ -305,7 +305,7 @@ module CDK
305
305
  if pp_return != 0
306
306
  # Check for a key bindings.
307
307
  if self.checkBind(self.object_type, input)
308
- complete = true
308
+ @complete = true
309
309
  else
310
310
  case input
311
311
  when Ncurses::KEY_LEFT
@@ -327,13 +327,13 @@ module CDK
327
327
  when CDK::KEY_TAB, CDK::KEY_RETURN, Ncurses::KEY_ENTER
328
328
  self.setExitType(input)
329
329
  ret = @current
330
- complete = true
330
+ @complete = true
331
331
  when CDK::KEY_ESC
332
332
  self.setExitType(input)
333
- complete = true
333
+ @complete = true
334
334
  when Ncurses::ERR
335
335
  self.setExitType(input)
336
- complete = true
336
+ @complete = true
337
337
  when CDK::REFRESH
338
338
  @screen.erase
339
339
  @screen.refresh
@@ -363,13 +363,13 @@ module CDK
363
363
  self.limitCurrentValue
364
364
 
365
365
  # Should we call a post-process?
366
- if !complete && !(@post_process_func).nil?
366
+ if !@complete && !(@post_process_func).nil?
367
367
  @post_process_func.call(self.object_type, self,
368
368
  @post_process_data, input)
369
369
  end
370
370
  end
371
371
 
372
- if !complete
372
+ if !@complete
373
373
  self.drawField
374
374
  self.setExitType(0)
375
375
  end
@@ -403,9 +403,9 @@ module CDK
403
403
  unless @label_win.nil?
404
404
  Draw.writeChtype(@label_win, 0, 0, @label, CDK::HORIZONTAL,
405
405
  0, @label_len)
406
- @label_win.wrefresh
406
+ wrefresh(@label_win)
407
407
  end
408
- @win.wrefresh
408
+ wrefresh
409
409
 
410
410
  # Draw the field window.
411
411
  self.drawField
@@ -422,7 +422,7 @@ module CDK
422
422
  CDK::HORIZONTAL, 0, temp.size)
423
423
 
424
424
  self.moveToEditPosition(@field_edit)
425
- @field_win.wrefresh
425
+ wrefresh(@field_win)
426
426
  end
427
427
 
428
428
  # This sets the background attribute of teh widget.
@@ -2,6 +2,8 @@ require_relative 'scroller'
2
2
 
3
3
  module CDK
4
4
  class SCROLL < CDK::SCROLLER
5
+ include CommonControls
6
+
5
7
  attr_reader :item, :list_size, :current_item, :highlight
6
8
 
7
9
  def initialize (cdkscreen, xplace, yplace, splace, height, width, title,
@@ -64,7 +66,7 @@ module CDK
64
66
  # Rejustify the x and y positions if we need to.
65
67
  xtmp = [xpos]
66
68
  ytmp = [ypos]
67
- CDK.alignxy(cdkscreen.window, xtmp, ytmp, @box_width, @box_height)
69
+ alignxy(cdkscreen.window, xtmp, ytmp, @box_width, @box_height)
68
70
  xpos = xtmp[0]
69
71
  ypos = ytmp[0]
70
72
 
@@ -148,7 +150,7 @@ module CDK
148
150
  xpos = self.SCREEN_XPOS(0) + scrollbar_adj
149
151
 
150
152
  @input_window.wmove(ypos, xpos)
151
- @input_window.wrefresh
153
+ wrefresh(@input_window)
152
154
  end
153
155
 
154
156
  # This actually does all the 'real' work of managing the scrolling list.
@@ -186,7 +188,7 @@ module CDK
186
188
  def inject(input)
187
189
  pp_return = 1
188
190
  ret = -1
189
- complete = false
191
+ @complete = false
190
192
 
191
193
  # Set the exit type for the widget.
192
194
  self.setExitType(0)
@@ -205,7 +207,7 @@ module CDK
205
207
  # Check for a predefined key binding.
206
208
  if self.checkBind(:SCROLL, input) != false
207
209
  #self.checkEarlyExit
208
- complete = true
210
+ @complete = true
209
211
  else
210
212
  case input
211
213
  when Ncurses::KEY_UP
@@ -230,26 +232,28 @@ module CDK
230
232
  @left_char = 0
231
233
  when CDK::KEY_ESC
232
234
  self.setExitType(input)
233
- complete = true
235
+ @complete = true
234
236
  when Ncurses::ERR
235
237
  self.setExitType(input)
236
- complete = true
238
+ @complete = true
237
239
  when CDK::REFRESH
238
240
  @screen.erase
239
241
  @screen.refresh
240
242
  when CDK::KEY_TAB, Ncurses::KEY_ENTER, CDK::KEY_RETURN
241
- self.setExitType(input)
242
- ret = @current_item
243
- complete = true
243
+ if quit_on_enter?
244
+ self.setExitType(input)
245
+ ret = @current_item
246
+ @complete = true
247
+ end
244
248
  end
245
249
  end
246
250
 
247
- if !complete && !(@post_process_func.nil?)
251
+ if !@complete && !(@post_process_func.nil?)
248
252
  @post_process_func.call(:SCROLL, self, @post_process_data, input)
249
253
  end
250
254
  end
251
255
 
252
- if !complete
256
+ if !@complete
253
257
  self.drawList(@box)
254
258
  self.setExitType(0)
255
259
  end
@@ -361,7 +365,7 @@ module CDK
361
365
  end
362
366
 
363
367
  # Refresh the window
364
- @win.wrefresh
368
+ wrefresh
365
369
  end
366
370
 
367
371
  # This sets the background attribute of the widget.
@@ -422,11 +426,11 @@ module CDK
422
426
 
423
427
  item_len = []
424
428
  item_pos = []
425
- @item[which] = CDK.char2Chtype(value, item_len, item_pos)
429
+ @item[which] = char2Chtype(value, item_len, item_pos)
426
430
  @item_len[which] = item_len[0]
427
431
  @item_pos[which] = item_pos[0]
428
432
 
429
- @item_pos[which] = CDK.justifyString(@box_width,
433
+ @item_pos[which] = justify_string(@box_width,
430
434
  @item_len[which], @item_pos[which])
431
435
  return true
432
436
  end
@@ -492,7 +496,7 @@ module CDK
492
496
 
493
497
  def getItems(list)
494
498
  (0...@list_size).each do |x|
495
- list << CDK.chtype2Char(@item[x])
499
+ list << chtype2Char(@item[x])
496
500
  end
497
501
 
498
502
  return @list_size
@@ -601,12 +605,12 @@ module CDK
601
605
 
602
606
  def focus
603
607
  self.drawCurrent
604
- @list_win.wrefresh
608
+ wrefresh(@list_win)
605
609
  end
606
610
 
607
611
  def unfocus
608
612
  self.drawCurrent
609
- @list_win.wrefresh
613
+ wrefresh(@list_win)
610
614
  end
611
615
 
612
616
  def AvailableWidth
@@ -623,372 +627,5 @@ module CDK
623
627
  def WidestItem
624
628
  @max_left_char + self.AvailableWidth
625
629
  end
626
- end
627
-
628
- class BUTTON < CDK::CDKOBJS
629
- def initialize(cdkscreen, xplace, yplace, text, callback, box, shadow)
630
- super()
631
- parent_width = cdkscreen.window.getmaxx
632
- parent_height = cdkscreen.window.getmaxy
633
- box_width = 0
634
- xpos = xplace
635
- ypos = yplace
636
-
637
- self.setBox(box)
638
- box_height = 1 + 2 * @border_size
639
-
640
- # Translate the string to a chtype array.
641
- info_len = []
642
- info_pos = []
643
- @info = CDK.char2Chtype(text, info_len, info_pos)
644
- @info_len = info_len[0]
645
- @info_pos = info_pos[0]
646
- box_width = [box_width, @info_len].max + 2 * @border_size
647
-
648
- # Create the string alignments.
649
- @info_pos = CDK.justifyString(box_width - 2 * @border_size,
650
- @info_len, @info_pos)
651
-
652
- # Make sure we didn't extend beyond the dimensions of the window.
653
- box_width = if box_width > parent_width
654
- then parent_width
655
- else box_width
656
- end
657
- box_height = if box_height > parent_height
658
- then parent_height
659
- else box_height
660
- end
661
-
662
- # Rejustify the x and y positions if we need to.
663
- xtmp = [xpos]
664
- ytmp = [ypos]
665
- CDK.alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
666
- xpos = xtmp[0]
667
- ypos = ytmp[0]
668
-
669
- # Create the button.
670
- @screen = cdkscreen
671
- # ObjOf (button)->fn = &my_funcs;
672
- @parent = cdkscreen.window
673
- @win = Ncurses::WINDOW.new(box_height, box_width, ypos, xpos)
674
- @shadow_win = nil
675
- @xpos = xpos
676
- @ypos = ypos
677
- @box_width = box_width
678
- @box_height = box_height
679
- @callback = callback
680
- @input_window = @win
681
- @accepts_focus = true
682
- @shadow = shadow
683
-
684
- if @win.nil?
685
- self.destroy
686
- return nil
687
- end
688
-
689
- @win.keypad(true)
690
-
691
- # If a shadow was requested, then create the shadow window.
692
- if shadow
693
- @shadow_win = Ncurses::WINDOW.new(box_height, box_width,
694
- ypos + 1, xpos + 1)
695
- end
696
-
697
- # Register this baby.
698
- cdkscreen.register(:BUTTON, self)
699
- end
700
-
701
- # This was added for the builder.
702
- def activate(actions)
703
- self.draw(@box)
704
- ret = -1
705
-
706
- if actions.nil? || actions.size == 0
707
- while true
708
- input = self.getch([])
709
-
710
- # Inject the character into the widget.
711
- ret = self.inject(input)
712
- if @exit_type != :EARLY_EXIT
713
- return ret
714
- end
715
- end
716
- else
717
- # Inject each character one at a time.
718
- actions.each do |x|
719
- ret = self.inject(action)
720
- if @exit_type == :EARLY_EXIT
721
- return ret
722
- end
723
- end
724
- end
725
-
726
- # Set the exit type and exit
727
- self.setExitType(0)
728
- return -1
729
- end
730
-
731
- # This sets multiple attributes of the widget.
732
- def set(mesg, box)
733
- self.setMessage(mesg)
734
- self.setBox(box)
735
- end
736
-
737
- # This sets the information within the button.
738
- def setMessage(info)
739
- info_len = []
740
- info_pos = []
741
- @info = CDK.char2Chtype(info, info_len, info_pos)
742
- @info_len = info_len[0]
743
- @info_pos = CDK.justifyString(@box_width - 2 * @border_size,
744
- info_pos[0])
745
-
746
- # Redraw the button widget.
747
- self.erase
748
- self.draw(box)
749
- end
750
-
751
- def getMessage
752
- return @info
753
- end
754
-
755
- # This sets the background attribute of the widget.
756
- def setBKattr(attrib)
757
- @win.wbkgd(attrib)
758
- end
759
-
760
- def drawText
761
- box_width = @box_width
762
-
763
- # Draw in the message.
764
- (0...(box_width - 2 * @border_size)).each do |i|
765
- pos = @info_pos
766
- len = @info_len
767
- if i >= pos && (i - pos) < len
768
- c = @info[i - pos]
769
- else
770
- c = ' '
771
- end
772
-
773
- if @has_focus
774
- c = Ncurses::A_REVERSE | c
775
- end
776
-
777
- @win.mvwaddch(@border_size, i + @border_size, c)
778
- end
779
- end
780
-
781
- # This draws the button widget
782
- def draw(box)
783
- # Is there a shadow?
784
- unless @shadow_win.nil?
785
- Draw.drawShadow(@shadow_win)
786
- end
787
-
788
- # Box the widget if asked.
789
- if @box
790
- Draw.drawObjBox(@win, self)
791
- end
792
- self.drawText
793
- @win.wrefresh
794
- end
795
-
796
- # This erases the button widget.
797
- def erase
798
- if self.validCDKObject
799
- CDK.eraseCursesWindow(@win)
800
- CDK.eraseCursesWindow(@shadow_win)
801
- end
802
- end
803
-
804
- # This moves the button field to the given location.
805
- def move(xplace, yplace, relative, refresh_flag)
806
- current_x = @win.getbegx
807
- current_y = @win.getbegy
808
- xpos = xplace
809
- ypos = yplace
810
-
811
- # If this is a relative move, then we will adjust where we want
812
- # to move to.
813
- if relative
814
- xpos = @win.getbegx + xplace
815
- ypos = @win.getbegy + yplace
816
- end
817
-
818
- # Adjust the window if we need to.
819
- xtmp = [xpos]
820
- ytmp = [ypos]
821
- CDK.alignxy(@screen.window, xtmp, ytmp, @box_width, @box_height)
822
- xpos = xtmp[0]
823
- ypos = ytmp[0]
824
-
825
- # Get the difference
826
- xdiff = current_x - xpos
827
- ydiff = current_y - ypos
828
-
829
- # Move the window to the new location.
830
- CDK.moveCursesWindow(@win, -xdiff, -ydiff)
831
- CDK.moveCursesWindow(@shadow_win, -xdiff, -ydiff)
832
-
833
- # Thouch the windows so they 'move'.
834
- CDK::SCREEN.refreshCDKWindow(@screen.window)
835
-
836
- # Redraw the window, if they asked for it.
837
- if refresh_flag
838
- self.draw(@box)
839
- end
840
- end
841
-
842
- # This allows the user to use the cursor keys to adjust the
843
- # position of the widget.
844
- def position
845
- # Declare some variables
846
- orig_x = @win.getbegx
847
- orig_y = @win.getbegy
848
- key = 0
849
-
850
- # Let them move the widget around until they hit return
851
- while key != Ncurses::KEY_ENTER && key != CDK::KEY_RETURN
852
- key = self.getch([])
853
- if key == Ncurses::KEY_UP || key == '8'.ord
854
- if @win.getbegy > 0
855
- self.move(0, -1, true, true)
856
- else
857
- CDK.Beep
858
- end
859
- elsif key == Ncurses::KEY_DOWN || key == '2'.ord
860
- if @win.getbegy + @win.getmaxy < @screen.window.getmaxy - 1
861
- self.move(0, 1, true, true)
862
- else
863
- CDK.Beep
864
- end
865
- elsif key == Ncurses::KEY_LEFT || key == '4'.ord
866
- if @win.getbegx > 0
867
- self.move(-1, 0, true, true)
868
- else
869
- CDK.Beep
870
- end
871
- elsif key == Ncurses::KEY_RIGHT || key == '6'.ord
872
- if @win.getbegx + @win.getmaxx < @screen.window.getmaxx - 1
873
- self.move(1, 0, true, true)
874
- else
875
- CDK.Beep
876
- end
877
- elsif key == '7'.ord
878
- if @win.getbegy > 0 && @win.getbegx > 0
879
- self.move(-1, -1, true, true)
880
- else
881
- CDK.Beep
882
- end
883
- elsif key == '9'.ord
884
- if @win.getbegx + @win.getmaxx < @screen.window.getmaxx - 1 &&
885
- @win.getbegy > 0
886
- self.move(1, -1, true, true)
887
- else
888
- CDK.Beep
889
- end
890
- elsif key == '1'.ord
891
- if @win.getbegx > 0 &&
892
- @win.getbegx + @win.getmaxx < @screen.window.getmaxx - 1
893
- self.move(-1, 1, true, true)
894
- else
895
- CDK.Beep
896
- end
897
- elsif key == '3'.ord
898
- if @win.getbegx + @win.getmaxx < @screen.window.getmaxx - 1 &&
899
- @win.getbegy + @win.getmaxy < @screen.window.getmaxy - 1
900
- self.move(1, 1, true, true)
901
- else
902
- CDK.Beep
903
- end
904
- elsif key == '5'.ord
905
- self.move(CDK::CENTER, CDK::CENTER, false, true)
906
- elsif key == 't'.ord
907
- self.move(@win.getbegx, CDK::TOP, false, true)
908
- elsif key == 'b'.ord
909
- self.move(@win.getbegx, CDK::BOTTOM, false, true)
910
- elsif key == 'l'.ord
911
- self.move(CDK::LEFT, @win.getbegy, false, true)
912
- elsif key == 'r'
913
- self.move(CDK::RIGHT, @win.getbegy, false, true)
914
- elsif key == 'c'
915
- self.move(CDK::CENTER, @win.getbegy, false, true)
916
- elsif key == 'C'
917
- self.move(@win.getbegx, CDK::CENTER, false, true)
918
- elsif key == CDK::REFRESH
919
- @screen.erase
920
- @screen.refresh
921
- elsif key == CDK::KEY_ESC
922
- self.move(orig_x, orig_y, false, true)
923
- elsif key != CDK::KEY_RETURN && key != Ncurses::KEY_ENTER
924
- CDK.Beep
925
- end
926
- end
927
- end
928
-
929
- # This destroys the button object pointer.
930
- def destroy
931
- CDK.deleteCursesWindow(@shadow_win)
932
- CDK.deleteCursesWindow(@win)
933
-
934
- self.cleanBindings(:BUTTON)
935
-
936
- CDK::SCREEN.unregister(:BUTTON, self)
937
- end
938
-
939
- # This injects a single character into the widget.
940
- def inject(input)
941
- ret = -1
942
- complete = false
943
-
944
- self.setExitType(0)
945
-
946
- # Check a predefined binding.
947
- if self.checkBind(:BUTTON, input)
948
- complete = true
949
- else
950
- case input
951
- when CDK::KEY_ESC
952
- self.setExitType(input)
953
- complete = true
954
- when Ncurses::ERR
955
- self.setExitType(input)
956
- complete = true
957
- when ' '.ord, CDK::KEY_RETURN, Ncurses::KEY_ENTER
958
- unless @callback.nil?
959
- @callback.call(self)
960
- end
961
- self.setExitType(Ncurses::KEY_ENTER)
962
- ret = 0
963
- complete = true
964
- when CDK::REFRESH
965
- @screen.erase
966
- @screen.refresh
967
- else
968
- CDK.Beep
969
- end
970
- end
971
-
972
- unless complete
973
- self.setExitType(0)
974
- end
975
-
976
- @result_data = ret
977
- return ret
978
- end
979
-
980
- def focus
981
- self.drawText
982
- @win.wrefresh
983
- end
984
-
985
- def unfocus
986
- self.drawText
987
- @win.wrefresh
988
- end
989
-
990
- def object_type
991
- :BUTTON
992
- end
993
- end
994
- end
630
+ end # class SCROLL
631
+ end # module CDK