Class: CDK::SWINDOW

Inherits:
CDKOBJS show all
Defined in:
lib/cdk/components/swindow.rb

Instance Attribute Summary

Attributes included from HasTitle

#title_attrib

Attributes included from HasScreen

#is_visible, #screen, #screen_index

Attributes included from ExitConditions

#exit_type

Attributes included from Bindings

#binding_list

Attributes included from Focusable

#accepts_focus, #has_focus

Attributes included from Borders

#BXAttr, #HZChar, #LLChar, #LRChar, #ULChar, #URChar, #VTChar, #border_size, #box

Instance Method Summary collapse

Methods inherited from CDKOBJS

#setBackgroundColor, #timeout, #validCDKObject, #validObjType

Methods included from WindowHooks

#refreshData, #saveData

Methods included from WindowInput

#getc, #getch, #setPostProcess, #setPreProcess

Methods included from HasTitle

#cleanTitle, #drawTitle, #init_title, #setTitle

Methods included from HasScreen

#SCREEN_XPOS, #SCREEN_YPOS, #init_screen, #wrefresh

Methods included from ExitConditions

#init_exit_conditions, #resetExitType, #setExitType

Methods included from Bindings

#bind, #bindableObject, #checkBind, #cleanBindings, #init_bindings, #isBind, #unbind

Methods included from Focusable

#init_focus

Methods included from Borders

#getBox, #init_borders, #setBXattr, #setBox, #setHZchar, #setLLchar, #setLRchar, #setULchar, #setURchar, #setVTchar

Methods included from Movement

#move, #move_specific

Methods included from Converters

#char2Chtype, #charOf, #chtype2Char, #chtype2String, #decode_attribute, #encode_attribute

Methods included from Justifications

#justify_string

Methods included from Alignments

#alignxy

Constructor Details

#initialize(cdkscreen, xplace, yplace, height, width, title, save_lines, box, shadow) ⇒ SWINDOW

Returns a new instance of SWINDOW.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cdk/components/swindow.rb', line 5

def initialize(cdkscreen, xplace, yplace, height, width, title,
    save_lines, box, shadow)
  super()
  parent_width = cdkscreen.window.getmaxx
  parent_height = cdkscreen.window.getmaxy
  box_width = width
  box_height = height
  bindings = {
    CDK::BACKCHAR => Ncurses::KEY_PPAGE,
    'b'           => Ncurses::KEY_PPAGE,
    'B'           => Ncurses::KEY_PPAGE,
    CDK::FORCHAR  => Ncurses::KEY_NPAGE,
    ' '           => Ncurses::KEY_NPAGE,
    'f'           => Ncurses::KEY_NPAGE,
    'F'           => Ncurses::KEY_NPAGE,
    '|'           => Ncurses::KEY_HOME,
    '$'           => Ncurses::KEY_END,
  }

  self.setBox(box)

  # If the height is a negative value, the height will be
  # ROWS-height, otherwise the height will be the given height.
  box_height = CDK.setWidgetDimension(parent_height, height, 0)

  # If the width is a negative value, the width will be
  # COLS-width, otherwise the widget will be the given width.
  box_width = CDK.setWidgetDimension(parent_width, width, 0)
  box_width = self.setTitle(title, box_width)

  # Set the box height.
  box_height += @title_lines + 1

  # Make sure we didn't extend beyond the dimensions of the window.
  box_width = [box_width, parent_width].min
  box_height = [box_height, parent_height].min

  # Set the rest of the variables.
  @title_adj = @title_lines + 1

  # Rejustify the x and y positions if we need to.
  xtmp = [xplace]
  ytmp = [yplace]
  alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
  xpos = xtmp[0]
  ypos = ytmp[0]

  # Make the scrolling window.
  @win = Ncurses::WINDOW.new(box_height, box_width, ypos, xpos)
  if @win.nil?
    self.destroy
    return nil
  end
  @win.keypad(true)

  # Make the field window
  @field_win = @win.subwin(box_height - @title_lines - 2, box_width - 2,
      ypos + @title_lines + 1, xpos + 1)
  @field_win.keypad(true)

  # Set the rest of the variables
  @screen = cdkscreen
  @parent = cdkscreen.window
  @shadow_win = nil
  @box_height = box_height
  @box_width = box_width
  @view_size = box_height - @title_lines - 2
  @current_top = 0
  @max_top_line = 0
  @left_char = 0
  @max_left_char = 0
  @list_size = 0
  @widest_line = -1
  @save_lines = save_lines
  @accepts_focus = true
  @input_window = @win
  @shadow = shadow

  if !self.createList(save_lines)
    self.destroy
    return nil
  end

  # Do we need to create a shadow?
  if shadow
    @shadow_win = Ncurses::WINDOW.new(box_height, box_width,
        ypos + 1, xpos + 1)
  end

  # Create the key bindings
  bindings.each do |from, to|
    self.bind(:SWINDOW, from, :getc, to)
  end

  # Register this baby.
  cdkscreen.register(:SWINDOW, self)
end

Instance Method Details

#activate(actions) ⇒ Object

This allows the user to play inside the scrolling window.



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/cdk/components/swindow.rb', line 299

def activate(actions)
  # Draw the scrolling list.
  self.draw(@box)

  if actions.nil? || actions.size == 0
    while true
      input = self.getch([])

      # inject the character into the widget.
      self.inject(input)
      if @exit_type != :EARLY_EXIT
        return
      end
    end
  else
    #Inject each character one at a time
    actions.each do |action|
      self.inject(action)
      if @exit_type != :EARLY_EXIT
        return
      end
    end
  end

  # Set the exit type and return.
  self.setExitType(0)
end

#add(list, insert_pos) ⇒ Object

This adds a line to the scrolling window.



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/cdk/components/swindow.rb', line 150

def add(list, insert_pos)
  # If we are at the maximum number of save lines erase the first
  # position and bump everything up one spot
  if @list_size == @save_lines and @list_size > 0
    @list = @list[1..-1]
    @list_pos = @list_pos[1..-1]
    @list_len = @list_len[1..-1]
    @list_size -= 1
  end

  # Determine where the line is being added.
  if insert_pos == CDK::TOP
    # We need to 'bump' everything down one line...
    @list = [@list[0]] + @list
    @list_pos = [@list_pos[0]] + @list_pos
    @list_len = [@list_len[0]] + @list_len

    # Add it into the scrolling window.
    self.setupLine(list, 0)

    # set some variables.
    @current_top = 0
    if @list_size < @save_lines
      @list_size += 1
    end

    # Set the maximum top line.
    @max_top_line = @list_size - @view_size
    @max_top_line = [@max_top_line, 0].max

    @max_left_char = @widest_line - (@box_width - 2)
  else
    # Add to the bottom.
    @list += ['']
    @list_pos += [0]
    @list_len += [0]
    self.setupLine(list, @list_size)
    
    @max_left_char = @widest_line - (@box_width - 2)

    # Increment the item count and zero out the next row.
    if @list_size < @save_lines
      @list_size += 1
      self.freeLine(@list_size)
    end

    # Set the maximum top line.
    if @list_size <= @view_size
      @max_top_line = 0
      @current_top = 0
    else
      @max_top_line = @list_size - @view_size
      @current_top = @max_top_line
    end
  end

  # Draw in the list.
  self.drawList(@box)
end

#cleanObject

This removes all the lines inside the scrolling window.



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/cdk/components/swindow.rb', line 238

def clean
  # Clean up the memory used...
  (0...@list_size).each do |x|
    self.freeLine(x)
  end

  # Reset some variables.
  @list_size = 0
  @max_left_char = 0
  @widest_line = 0
  @current_top = 0
  @max_top_line = 0

  # Redraw the window.
  self.draw(@box)
end

#createList(list_size) ⇒ Object



733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# File 'lib/cdk/components/swindow.rb', line 733

def createList(list_size)
  status = false

  if list_size >= 0
    new_list = []
    new_pos = []
    new_len = []

    status = true
    self.destroyInfo

    @list = new_list
    @list_pos = new_pos
    @list_len = new_len
  else
    self.destroyInfo
    status = false
  end
  return status
end

#destroyObject

This function destroys the scrolling window widget.



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'lib/cdk/components/swindow.rb', line 510

def destroy
  self.destroyInfo

  self.cleanTitle

  # Delete the windows.
  CDK.deleteCursesWindow(@shadow_win)
  CDK.deleteCursesWindow(@field_win)
  CDK.deleteCursesWindow(@win)

  # Clean the key bindings.
  self.cleanBindings(:SWINDOW)

  # Unregister this object.
  CDK::SCREEN.unregister(:SWINDOW, self)
end

#destroyInfoObject

Free any storage associated with the info-list.



503
504
505
506
507
# File 'lib/cdk/components/swindow.rb', line 503

def destroyInfo
  @list = []
  @list_pos = []
  @list_len = []
end

#draw(box) ⇒ Object

This function draws the swindow window widget.



446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/cdk/components/swindow.rb', line 446

def draw(box)
  # Do we need to draw in the shadow.
  unless @shadow_win.nil?
    Draw.drawShadow(@shadow_win)
  end

  # Box the widget if needed
  if box
    Draw.drawObjBox(@win, self)
  end

  self.drawTitle(@win)

  wrefresh

  # Draw in the list.
  self.drawList(box)
end

#drawList(box) ⇒ Object

This draws in the contents of the scrolling window



466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/cdk/components/swindow.rb', line 466

def drawList(box)
  # Determine the last line to draw.
  if @list_size < @view_size
    last_line = @list_size
  else
    last_line = @view_size
  end

  # Erase the scrolling window.
  @field_win.werase

  # Start drawing in each line.
  (0...last_line).each do |x|
    screen_pos = @list_pos[x + @current_top] - @left_char

    # Write in the correct line.
    if screen_pos >= 0
      Draw.writeChtype(@field_win, screen_pos, x,
          @list[x + @current_top], CDK::HORIZONTAL, 0,
          @list_len[x + @current_top])
    else
      Draw.writeChtype(@field_win, 0, x, @list[x + @current_top],
          CDK::HORIZONTAL, @left_char - @list_pos[x + @current_top],
          @list_len[x + @current_top])
    end
  end

  wrefresh(@field_win)
end

#dump(filename) ⇒ Object

This actually dumps the information from the scrolling window to a file.



706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# File 'lib/cdk/components/swindow.rb', line 706

def dump(filename)
  # Try to open the file.
  #if ((outputFile = fopen (filename, "w")) == 0)
  #{
  #  return -1;
  #}
  output_file = File.new(filename, 'w')

  # Start writing out the file.
  @list.each do |item|
    raw_line = chtype2Char(item)
    output_file << "%s\n" % raw_line
  end

  # Close the file and return the number of lines written.
  output_file.close
  return @list_size
end

#eraseObject

This function erases the scrolling window widget.



528
529
530
531
532
533
# File 'lib/cdk/components/swindow.rb', line 528

def erase
  if self.validCDKObject
    CDK.eraseCursesWindow(@win)
    CDK.eraseCursesWindow(@shadow_win)
  end
end

#exec(command, insert_pos) ⇒ Object

This execs a command and redirects the output to the scrolling window.



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
# File 'lib/cdk/components/swindow.rb', line 536

def exec(command, insert_pos)
  count = -1
  Ncurses.endwin

  # Try to open the command.
  # XXX This especially needs exception handling given how Ruby
  # implements popen
  unless (ps = IO.popen(command.split, 'r')).nil?
    # Start reading.
    until (temp = ps.gets).nil?
      if temp.size != 0 && temp[-1] == '\n'
        temp = temp[0...-1]
      end
      # Add the line to the scrolling window.
      self.add(temp, insert_pos)
      count += 1
    end

    # Close the pipe
    ps.close
  end
  return count
end

#focusObject



725
726
727
# File 'lib/cdk/components/swindow.rb', line 725

def focus
  self.draw(@box)
end

#freeLine(x) ⇒ Object



143
144
145
146
147
# File 'lib/cdk/components/swindow.rb', line 143

def freeLine(x)
#  if x < @list_size
#    @list[x] = 0
#  end
end

#getContents(size) ⇒ Object



138
139
140
141
# File 'lib/cdk/components/swindow.rb', line 138

def getContents(size)
  size << @list_size
  return @list
end

#inject(input) ⇒ Object

This injects a single character into the widget.



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/cdk/components/swindow.rb', line 328

def inject(input)
  pp_return = 1
  ret = -1
  @complete = false

  # Set the exit type.
  self.setExitType(0)

  # Draw the window....
  self.draw(@box)

  # Check if there is a pre-process function to be called.
  unless @pre_process_func.nil?
    # Call the pre-process function.
    pp_return = @pre_process_func.call(:SWINDOW, self,
        @pre_process_data, input)
  end

  # Should we continue?
  if pp_return != 0
    # Check for a key binding.
    if self.checkBind(:SWINDOW, input)
      @complete = true
    else
      case input
      when Ncurses::KEY_UP
        if @current_top > 0
          @current_top -= 1
        else
          CDK.Beep
        end
      when Ncurses::KEY_DOWN
        if @current_top >= 0 && @current_top < @max_top_line
          @current_top += 1
        else
          CDK.Beep
        end
      when Ncurses::KEY_RIGHT
        if @left_char < @max_left_char
          @left_char += 1
        else
          CDK.Beep
        end
      when Ncurses::KEY_LEFT
        if @left_char > 0
          @left_char -= 1
        else
          CDK.Beep
        end
      when Ncurses::KEY_PPAGE
        if @current_top != 0
          if @current_top >= @view_size
            @current_top = @current_top - (@view_size - 1)
          else
            @current_top = 0
          end
        else
          CDK.Beep
        end
      when Ncurses::KEY_NPAGE
        if @current_top != @max_top_line
          if @current_top + @view_size < @max_top_line
            @current_top = @current_top + (@view_size - 1)
          else
            @current_top = @max_top_line
          end
        else
          CDK.Beep
        end
      when Ncurses::KEY_HOME
        @left_char = 0
      when Ncurses::KEY_END
        @left_char = @max_left_char + 1
      when 'g'.ord, '1'.ord, '<'.ord
        @current_top = 0
      when 'G'.ord, '>'.ord
        @current_top = @max_top_line
      when 'l'.ord, 'L'.ord
        self.loadInformation
      when 's'.ord, 'S'.ord
        self.saveInformation
      when CDK::KEY_TAB, CDK::KEY_RETURN, Ncurses::KEY_ENTER
        self.setExitType(input)
        ret = 1
        @complete = true
      when CDK::KEY_ESC
        self.setExitType(input)
        @complete = true
      when Ncurses::ERR
        self.setExitType(input)
        @complete = true
      when CDK::REFRESH
        @screen.erase
        @screen.refresh
      end
    end

    # Should we call a post-process?
    if !@complete && !(@post_process_func.nil?)
      @post_process_func.call(:SWINDOW, self, @post_process_data, input)
    end
  end

  if !@complete
    self.drawList(@box)
    self.setExitType(0)
  end

  @return_data = ret
  return ret
end

#jumpToLine(line) ⇒ Object

This jumps to a given line.



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/cdk/components/swindow.rb', line 211

def jumpToLine(line)
  # Make sure the line is in bounds.
  if line == CDK::BOTTOM || line >= @list_size
    # We are moving to the last page.
    @current_top = @list_size - @view_size
  elsif line == TOP || line <= 0
    # We are moving to the top of the page.
    @current_top = 0
  else
    # We are moving in the middle somewhere.
    if @view_size + line < @list_size
      @current_top = line
    else
      @current_top = @list_size - @view_size
    end
  end

  # A little sanity check to make sure we don't do something silly
  if @current_top < 0
    @current_top = 0
  end

  # Redraw the window.
  self.draw(@box)
end

#loadInformationObject

This function allows the user to load new information into the scrolling window.



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
# File 'lib/cdk/components/swindow.rb', line 621

def loadInformation
  # Create the file selector to choose the file.
  fselect = CDK::FSELECT.new(@screen, CDK::CENTER, CDK::CENTER, 20, 55,
      '<C>Load Which File', 'FIlename', Ncurses::A_NORMAL, '.',
      Ncurses::A_REVERSE, '</5>', '</48>', '</N>', '</N>', true, false)

  # Get the filename to load.
  filename = fselect.activate([])

  # Make sure they selected a file.
  if fselect.exit_type == :ESCAPE_HIT
    # Popup a message.
    mesg = [
        '<C></B/5>Load Canceled.',
        ' ',
        '<C>Press any key to continue.',
    ]
    @screen.popupLabel(mesg, 3)

    # Clean up and exit
    fselect.destroy
    return
  end

  # Copy the filename and destroy the file selector.
  filename = fselect.pathname
  fselect.destroy

  # Maybe we should check before nuking all the information in the
  # scrolling window...
  if @list_size > 0
    # Create the dialog message.
    mesg = [
        '<C></B/5>Save Information First',
        '<C>There is information in the scrolling window.',
        '<C>Do you want to save it to a file first?',
    ]
    button = ['(Yes)', '(No)']

    # Create the dialog widget.
    dialog = CDK::DIALOG.new(@screen, CDK::CENTER, CDK::CENTER,
        mesg, 3, button, 2, Ncurses.COLOR_PAIR(2) | Ncurses::A_REVERSE,
        true, true, false)

    # Activate the widet.
    answer = dialog.activate([])
    dialog.destroy

    # Check the answer.
    if (answer == -1 || answer == 0)
      # Save the information.
      self.saveInformation
    end
  end

  # Open the file and read it in.
  f = File.open(filename)
  file_info = f.readlines.map do |line|
    if line.size > 0 && line[-1] == "\n"
      line[0...-1]
    else
      line
    end
  end.compact

  # TODO error handling
  # if (lines == -1)
  # {
  #   /* The file read didn't work. */
  #   showMessage2 (swindow,
  #                 "<C></B/16>Error",
  #                 "<C>Could not read the file",
  #                 filename);
  #   freeChar (filename);
  #   return;
  # }

  # Clean out the scrolling window.
  self.clean

  # Set the new information in the scrolling window.
  self.set(file_info, file_info.size, @box)
end

#object_typeObject



758
759
760
# File 'lib/cdk/components/swindow.rb', line 758

def object_type
  :SWINDOW
end

#positionObject



754
755
756
# File 'lib/cdk/components/swindow.rb', line 754

def position
  super(@win)
end

#saveInformationObject

This function allows the user to dump the information from the scrolling window to a file.



573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# File 'lib/cdk/components/swindow.rb', line 573

def saveInformation
  # Create the entry field to get the filename.
  entry = CDK::ENTRY.new(@screen, CDK::CENTER, CDK::CENTER,
      '<C></B/5>Enter the filename of the save file.',
      'Filename: ', Ncurses::A_NORMAL, '_'.ord, :MIXED,
      20, 1, 256, true, false)

  # Get the filename.
  filename = entry.activate([])

  # Did they hit escape?
  if entry.exit_type == :ESCAPE_HIT
    # Popup a message.
    mesg = [
        '<C></B/5>Save Canceled.',
        '<C>Escape hit. Scrolling window information not saved.',
        ' ',
        '<C>Press any key to continue.'
    ]
    @screen.popupLabel(mesg, 4)

    # Clean up and exit.
    entry.destroy
  end

  # Write the contents of the scrolling window to the file.
  lines_saved = self.dump(filename)

  # Was the save successful?
  if lines_saved == -1
    # Nope, tell 'em
    self.showMessage2('<C></B/16>Error', '<C>Could not save to the file.',
        filename)
  else
    # Yep, let them know how many lines were saved.
    self.showMessage2('<C></B/5>Save Successful',
        '<C>There were %d lines saved to the file' % [lines_saved],
        filename)
  end

  # Clean up and exit.
  entry.destroy
  @screen.erase
  @screen.draw
end

#set(list, lines, box) ⇒ Object

This sets the lines and the box attribute of the scrolling window.



104
105
106
107
# File 'lib/cdk/components/swindow.rb', line 104

def set(list, lines, box)
  self.setContents(list, lines)
  self.setBox(box)
end

#setBKattr(attrib) ⇒ Object

This sets the background attribute of the widget.



497
498
499
500
# File 'lib/cdk/components/swindow.rb', line 497

def setBKattr(attrib)
  @win.wbkgd(attrib)
  @field_win.wbkgd(attrib)
end

#setContents(list, list_size) ⇒ Object

This sets all the lines inside the scrolling window.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/cdk/components/swindow.rb', line 119

def setContents(list, list_size)
  # First let's clean all the lines in the window.
  self.clean
  self.createList(list_size)

  # Now let's set all the lines inside the window.
  (0...list_size).each do |x|
    self.setupLine(list[x], x)
  end

  # Set some more important members of the scrolling window.
  @list_size = list_size
  @max_top_line = @list_size - @view_size
  @max_top_line = [@max_top_line, 0].max
  @max_left_char = @widest_line - (@box_width - 2)
  @current_top = 0
  @left_char = 0
end

#setupLine(list, x) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/cdk/components/swindow.rb', line 109

def setupLine(list, x)
  list_len = []
  list_pos = []
  @list[x] = char2Chtype(list, list_len, list_pos)
  @list_len[x] = list_len[0]
  @list_pos[x] = justify_string(@box_width, list_len[0], list_pos[0])
  @widest_line = [@widest_line, @list_len[x]].max
end

#showMessage2(msg, msg2, filename) ⇒ Object



560
561
562
563
564
565
566
567
568
569
# File 'lib/cdk/components/swindow.rb', line 560

def showMessage2(msg, msg2, filename)
  mesg = [
      msg,
      msg2,
      "<C>(%s)" % [filename],
      ' ',
      '<C> Press any key to continue.',
  ]
  @screen.popupLabel(mesg, mesg.size)
end

#trim(begin_line, end_line) ⇒ Object

This trims lines from the scrolling window.



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/cdk/components/swindow.rb', line 256

def trim(begin_line, end_line)
  # Check the value of begin_line
  if begin_line < 0
    start = 0
  elsif begin_line >= @list_size
    start = @list_size - 1
  else
    start = begin_line
  end

  # Check the value of end_line
  if end_line < 0
    finish = 0
  elsif end_line >= @list_size
    finish = @list_size - 1
  else
    finish = end_line
  end

  # Make sure the start is lower than the end.
  if start > finish
    return
  end

  # Start nuking elements from the window
  (start..finish).each do |x|
    self.freeLine(x)

    if x < list_size - 1
      @list[x] = @list[x + 1]
      @list_pos[x] = @list_pos[x + 1]
      @list_len[x] = @list_len[x + 1]
    end
  end

  # Adjust the item count correctly.
  @list_size = @list_size - (end_line - begin_line) - 1

  # Redraw the window.
  self.draw(@box)
end

#unfocusObject



729
730
731
# File 'lib/cdk/components/swindow.rb', line 729

def unfocus
  self.draw(@box)
end