Class: RubyCurses::Widget

Inherits:
Object
  • Object
show all
Includes:
DSL, Io, ConfigSetup, EventHandler, Utils
Defined in:
lib/rbcurse/rwidget.rb

Overview

Basic widget class. NOTE: I may soon remove the config hash. I don’t use it and its just making things heavy. Unless someone convinces me otherwise.

Constant Summary

Constants included from Io

Io::ERROR_COLOR_PAIR, Io::FOOTER_COLOR_PAIR, Io::LINEONE, Io::MAIN_WINDOW_COLOR_PAIR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Io

#askchoice, #askyesno, #askyesnocancel, #clear_error, #clear_this, #get_string, #newaskyesno, #old_print_header, #old_print_top_right, #print_action, #print_error, #print_footer_help, #print_header, #print_headers, #print_help, #print_help_page, #print_in_middle, #print_key_labels, #print_key_labels_row, #print_screen_labels, #print_status, #print_this, #print_top_right, #rbgetstr

Methods included from Utils

#_process_key, #bind_key, #clean_string!, #keycode_tos, #repeatm, #wrap_text

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Methods included from DSL

#OLD_method_missing

Constructor Details

#initialize(form, aconfig = {}, &block) ⇒ Widget

Returns a new instance of Widget.



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/rbcurse/rwidget.rb', line 406

def initialize form, aconfig={}, &block
  @form = form
  @bgcolor ||=  "black" # 0
  @row_offset = @col_offset = 0
  @ext_row_offset = @ext_col_offset = 0 # 2010-02-07 20:18 
  @state = :NORMAL
  @color ||= "white" # $datacolor
  @attr = nil
  @handler = {}
  @event_args = {}
  config_setup aconfig # @config.each_pair { |k,v| variable_set(k,v) }
  instance_eval &block if block_given?
  #    @id = form.add_widget(self) if !form.nil? and form.respond_to? :add_widget
  set_form(form) unless form.nil? 
end

Instance Attribute Details

#col_offsetObject (readonly)

where should the cursor be placed to start with



382
383
384
# File 'lib/rbcurse/rwidget.rb', line 382

def col_offset
  @col_offset
end

#cols_pannedObject

moved from form, how many cols scrolled.panned 2010-02-11 15:26



404
405
406
# File 'lib/rbcurse/rwidget.rb', line 404

def cols_panned
  @cols_panned
end

#configObject (readonly)

COULD GET AXED SOON NOTE



379
380
381
# File 'lib/rbcurse/rwidget.rb', line 379

def config
  @config
end

#curposObject

cursor position inside object - column, not row.



378
379
380
# File 'lib/rbcurse/rwidget.rb', line 378

def curpos
  @curpos
end

#ext_col_offsetObject

tired of getting the cursor wrong and guessing, i am now going to try to get absolute coordinates - 2010-02-07 20:17 this should be updated by parent.



401
402
403
# File 'lib/rbcurse/rwidget.rb', line 401

def ext_col_offset
  @ext_col_offset
end

#ext_row_offsetObject

tired of getting the cursor wrong and guessing, i am now going to try to get absolute coordinates - 2010-02-07 20:17 this should be updated by parent.



401
402
403
# File 'lib/rbcurse/rwidget.rb', line 401

def ext_row_offset
  @ext_row_offset
end

#formObject

made accessor 2008-11-27 22:32 so menu can set



380
381
382
# File 'lib/rbcurse/rwidget.rb', line 380

def form
  @form
end

#idObject

, :zorder



377
378
379
# File 'lib/rbcurse/rwidget.rb', line 377

def id
  @id
end

#parent_componentObject

I think parent_form was not a good idea since i can’t add parent widget offsets + thus we should use parent_comp and push up.



398
399
400
# File 'lib/rbcurse/rwidget.rb', line 398

def parent_component
  @parent_component
end

#row_offsetObject (readonly)

where should the cursor be placed to start with



382
383
384
# File 'lib/rbcurse/rwidget.rb', line 382

def row_offset
  @row_offset
end

#rows_pannedObject

attr_accessor :manages_cursor # does this widget manage cursor, or should form handle it 2010-02-07 20:54



403
404
405
# File 'lib/rbcurse/rwidget.rb', line 403

def rows_panned
  @rows_panned
end

#should_create_bufferObject

2010-01-05 13:27 create buffer conditionally, if enclosing component asks. Needs to be passed down + to further children or editor components. Default false.



394
395
396
# File 'lib/rbcurse/rwidget.rb', line 394

def should_create_buffer
  @should_create_buffer
end

#stateObject

normal, selected, highlighted



381
382
383
# File 'lib/rbcurse/rwidget.rb', line 381

def state
  @state
end

Instance Method Details

#buffer_to_screen(screen = nil, pminrow = 0, pmincol = 0) ⇒ Object

copy the buffer to the screen, or given window/pad.

Relevant only in double_buffered case since pad has to be written
to screen. Should be called only by outer form, not by widgets as a widget
could be inside another widget.
Somewhere we need to clear screen if scrolling.???
aka b2s

Parameters:

  • screen (Window, #get_window, nil) (defaults to: nil)

    to write to, if nil then write to phys screen

Returns:

  • 0 - copy success, -1 copy failure, 1 - did nothing, usually since buffer_modified false



725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
# File 'lib/rbcurse/rwidget.rb', line 725

def buffer_to_screen(screen=nil, pminrow=0, pmincol=0)
  raise "deprecated b2s "
  return 1 unless @is_double_buffered and @buffer_modified
  # screen is nil when form calls this to write to physical screen
  $log.debug " screen inside buffer_to_screen b2s :#{screen} "
  $log.error "ERROR !I have moved away fomr this method. Your program is broken and will not be working"
  ## 2010-01-03 19:38 i think its wrong to put the pad onto the screen
  ##+ since wrefreshing the window will cause this to be overwriting
  ##+ so i put current window here.
  if screen == nil
    #$log.debug " XXX calling graphic.wrefresh 2010-01-03 12:27 (parent_buffer was nil) "
    $log.debug " XXX 2010-01-03 20:47 now copying pad #{@graphic} onto form.window"
    ret = @graphic.wrefresh
   ## 2010-01-03 20:45 rather than writing to phys screen, i write to forms window
   ##+ so later updates to that window do not overwrite this widget.
   ## We need to check this out with scrollpane and splitpane.
    #ret = @graphic.copywin(@form.window.get_window, 0, 0, @row, @col, @row+@height-1, @col+@width-1,0)
  else
  # screen is passed when a parent object calls this to copy child buffer to itself
    @graphic.set_backing_window(screen)
    $log.debug "   #{@name} #{@graphic} calling copy pad to win COPY"
    ret = @graphic.copy_pad_to_win
  end
  @buffer_modified = false
  return ret
end

#buffer_to_windowObject

copy buffer onto window RFED16 added 2010-02-12 14:42 0 simpler buffer management



940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
# File 'lib/rbcurse/rwidget.rb', line 940

def buffer_to_window
  if @is_double_buffered and @buffer_modified
    raise " #{@name} @buffer_params not passed. Use set_buffering()" unless @buffer_params
    # we are notchecking for TV's width exceedingg, could get -1 if TV exceeds parent/
     $log.debug "RFED16 paint  #{@name} calling b2s #{@graphic}  "
     # TODO need to call set_screen_row_col (top, left), set_pad_top_left (pminrow, pmaxrow), set_screen_max_row_col
     if false
       # boh these print the pad behind 0,0, later scroll etc cover it and show bars.
       # adding window was giving error
         ret = buffer_to_screen #@target_window.get_window
         #ret = @graphic.wrefresh
     else
        # ext gives me parents offset. often the row would be zero, so we still need one extra
         r1 = @ext_row_offset # XXX NO, i should use top and left 
         c1 = @ext_col_offset  
         r = @graphic.top # 2010-02-12 21:12 TRYING THIS.
         c = @graphic.left
         maxr = @buffer_params[:bottom]
         maxc = @buffer_params[:right]
         r = @buffer_params[:screen_top] || 0
         c = @buffer_params[:screen_left] || 0
         $log.debug " b2w #{r1} #{c1} , #{r} #{c} "
         ## sadly this is bypassing the method that does this stuff in Pad. We need to assimilate it back, so not so much work here
         pminr = @graphic.pminrow
         pminc = @graphic.pmincol
         border_width = 0 # 2 #XXX  2010-02-15 23:40 2 to 0
         $log.debug " #{@name} ret = @graphic.copywin(@target_window.get_window, #{pminr}, #{pminc}, #{r}, #{c}, #{r}+#{maxr} - #{border_width}, #{c} + #{maxc} - #{border_width} ,0)"
         # this print the view at 0,0, byt covers the scrllare, bars not shown.
         # this can crash if textview is smaller than container dimension
         # can crash/give -1 when panning, giong beyond pad size XXX
         ret = @graphic.copywin(@target_window.get_window, pminr, pminc, r, c, r+maxr-border_width, c+maxc-border_width,0)
         if ret == -1
           $log.debug " copywin #{@name} h #{@height} w #{@width} "
           if @height <= maxr-border_width
             $log.warn " h #{@height} is <= :bottom #{maxr} "
           end
           if @width <= maxc-border_width
             $log.warn " h #{@width} is <= :right #{maxc} "
           end
           $log.warn "ERROR !!! copywin returns -1 check Target: #{@target_window}, #{@target_window.get_window} " if ret == -1
         end
     end
     $log.debug " copywin ret --> #{ret} "
     #
 end
end

#create_bufferbuffer

creates a buffer for the widget to write to.

This is typically called in the constructor. Sometimes, the constructor
does not have a height or width, since the object will be resized based on parents
size, as in splitpane
Please use this only if embedding this object in another object/s that would wish
to crop this. Otherwise, you could have many pads in your app.
Sets @graphic which can be used in place of @form.window

NOTE: 2010-01-12 11:14 there are some parent widgets that may want this w to have a larger top and left. Setting it later, means that the first repaint can be off.

Returns:

  • (buffer)

    returns pad created

Since:

  • 0.1.3



665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/rbcurse/rwidget.rb', line 665

def create_buffer()
  $log.debug " #{self.class}  CB called with #{@should_create_buffer} H: #{@height} W #{@width}  "
  if @should_create_buffer
     @height or $log.warn " CB height is nil, setting to 1. This may not be what you want"
    mheight = @height ||  1 # some widgets don't have height XXX
    mwidth  = @width ||  30 # some widgets don't have width as yet
    mrow    = @row || 0
    mcol    = @col || 0
    layout  = { :height => mheight, :width => mwidth, :top => mrow, :left => mcol }
    $log.debug "  cb .. #{@name} create_buffer #{mrow} #{mcol} #{mheight} #{mwidth}"
    @screen_buffer = VER::Pad.create_with_layout(layout)
    @is_double_buffered = true # will be checked prior to blitting
    @buffer_modified = true # set this in repaint 
    @repaint_all = true # added 2010-01-08 19:02 
  else
    ## NOTE: if form has not been set, you could run into problems
    ## Typically a form MUST be set by now, unless you are buffering, in which
    ##+ case it should go in above block.
    @screen_buffer = @form.window if @form
  end

  @graphic = @screen_buffer # use buffer for writing, not screen window
  return @screen_buffer
end

#destroyObject



496
497
498
499
500
501
# File 'lib/rbcurse/rwidget.rb', line 496

def destroy
  $log.debug "DESTROY : widget #{@name} "
  panel = @window.panel
  Ncurses::Panel.del_panel(panel) if !panel.nil?   
  @window.delwin if !@window.nil?
end

#destroy_bufferObject

destroys screen_buffer if present

Returns:

Since:

  • 0.1.3



767
768
769
770
771
# File 'lib/rbcurse/rwidget.rb', line 767

def destroy_buffer()
    if @screen_buffer != nil
        @screen_buffer.destroy # ??? 
    end
end

#focusObject

moves focus to this field XXX we must look into running on_leave of previous field



574
575
576
577
578
579
# File 'lib/rbcurse/rwidget.rb', line 574

def focus
  return if !@focusable
  if @form.validate_field != -1
    @form.select_field @id
  end
end

#get_bufferscreen_buffer?

returns screen_buffer or nil

Returns:

  • (screen_buffer, nil)

    screen_buffer earlier created

Since:

  • 0.1.3



757
758
759
# File 'lib/rbcurse/rwidget.rb', line 757

def get_buffer()
  @screen_buffer
end

#get_color(default = $datacolor, _color = @color, _bgcolor = @bgcolor) ⇒ Object



580
581
582
583
584
585
586
587
# File 'lib/rbcurse/rwidget.rb', line 580

def get_color default=$datacolor, _color=@color, _bgcolor=@bgcolor
  if _bgcolor.is_a? String and _color.is_a? String
    acolor = ColorMap.get_color(_color, _bgcolor)
  else
    acolor = default
  end
  return acolor
end

#get_preferred_sizeObject

Since:

  • 0.1.3



648
649
650
# File 'lib/rbcurse/rwidget.rb', line 648

def get_preferred_size
  return @preferred_height, @preferred_width
end

#getvalueObject

return the value of the widget.

In cases where selection is possible, should return selected value/s


470
471
472
# File 'lib/rbcurse/rwidget.rb', line 470

def getvalue
  @text_variable && @text_variable.value || @text
end

#getvalue_for_paintObject

Am making a separate method since often value for print differs from actual value



475
476
477
# File 'lib/rbcurse/rwidget.rb', line 475

def getvalue_for_paint
  getvalue
end

#handle_key(ch) ⇒ Object

to be added at end of handle_key of widgets so instlalled actions can be checked



643
644
645
646
# File 'lib/rbcurse/rwidget.rb', line 643

def handle_key(ch)
  ret = process_key ch, self
  return :UNHANDLED if ret == :UNHANDLED
end

#height(*val) ⇒ val

getter and setter for height - 2009-10-30 12:25 Using dsl_property style SO WE’ve finally succumbed and added height to widget

Parameters:

  • height (val, nil)

    to set

Returns:

  • (val)

    earlier height if nil param

Since:

  • 0.1.3



821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
# File 'lib/rbcurse/rwidget.rb', line 821

def height(*val)
  #$log.debug " inside XXX height() #{val[0]}"
  if val.empty?
    return @height
  else
    #$log.debug " inside #{@name} height()"
    oldvalue = @height || 0 # is this default okay, else later nil cries
    @height = val.size == 1 ? val[0] : val
    newvalue = @height
    @config["height"]=@height
    if oldvalue != newvalue
      fire_property_change("height", oldvalue, newvalue)
      $log.debug " widget #{@name} setting repaint_all to true"
      @repaint_all=true
    end
    # XXX this troubles me a lot. gets fired more than we would like
    # XXX When both h and w change then happens 2 times.
    if is_double_buffered? and newvalue != oldvalue
      $log.debug " #{@name} h calling resize of screen buffer with #{newvalue}"
      @screen_buffer.resize(newvalue, 0)
    end
  end
end

#height=(val) ⇒ Object



844
845
846
# File 'lib/rbcurse/rwidget.rb', line 844

def height=val
  height(val)
end

#hideObject



558
559
560
# File 'lib/rbcurse/rwidget.rb', line 558

def hide
  @visible = false
end

#init_varsObject



421
422
423
424
425
426
# File 'lib/rbcurse/rwidget.rb', line 421

def init_vars
  # just in case anyone does a super. Not putting anything here
  # since i don't want anyone accidentally overriding
  @buffer_modified = false 
  #@manages_cursor = false # form should manage it, I will pass row and col to it. XXX ?
end

#is_double_buffered?true, false

Does the widget buffer its output in a pad

Returns:

  • (true, false)

    comment



778
779
780
# File 'lib/rbcurse/rwidget.rb', line 778

def is_double_buffered?()
  @is_double_buffered
end

#modified?Boolean

modified

typically read will be overridden to check if value changed from what it was on enter. getter and setter for modified (added 2009-01-18 12:31 )

Returns:

  • (Boolean)


432
433
434
# File 'lib/rbcurse/rwidget.rb', line 432

def modified?
  @modified
end

#move(row, col) ⇒ Object



567
568
569
570
# File 'lib/rbcurse/rwidget.rb', line 567

def move row, col
  @row = row
  @col = col
end

#OLDbind_key(keycode, *args, &blk) ⇒ Object

bind an action to a key, required if you create a button which has a hotkey or a field to be focussed on a key, or any other user defined action based on key e.g. bind_key ?C-x, object, block added 2009-01-06 19:13 since widgets need to handle keys properly

2010-02-24 12:43 trying to take in multiple key bindings, TODO unbind
TODO add symbol so easy to map from config file or mapping file


595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
# File 'lib/rbcurse/rwidget.rb', line 595

def OLDbind_key keycode, *args, &blk
  @key_handler ||= {}
  if !block_given?
    blk = args.pop
    raise "If block not passed, last arg should be a method symbol" if !blk.is_a? Symbol
    $log.debug " #{@name} bind_key received a symbol #{blk} "
  end
  case keycode
  when String
    $log.debug "Widg String called bind_key BIND #{keycode} #{keycode_tos(keycode)}  "
    keycode = keycode.getbyte(0) #if keycode.class==String ##    1.9 2009-10-05 19:40 
    @key_handler[keycode] = blk
  when Array
    # for starters lets try with 2 keys only
    a0 = keycode[0]
    a0 = keycode[0].getbyte(0) if keycode[0].class == String
    a1 = keycode[1]
    a1 = keycode[1].getbyte(0) if keycode[1].class == String
    @key_handler[a0] ||= OrderedHash.new
    @key_handler[a0][a1] = blk
  else
    @key_handler[keycode] = blk
  end
  @key_args ||= {}
  @key_args[keycode] = args
end

#on_enterObject

got left out by mistake 2008-11-26 20:20



453
454
455
# File 'lib/rbcurse/rwidget.rb', line 453

def on_enter
  fire_handler :ENTER, self
end

#on_leaveObject

got left out by mistake 2008-11-26 20:20



457
458
459
# File 'lib/rbcurse/rwidget.rb', line 457

def on_leave
  fire_handler :LEAVE, self
end

#override_graphic(gr) ⇒ Object

When an enclosing component creates a pad (buffer) and the child component + should write onto the same pad, then the enclosing component should override + the default graphic of child. This applies mainly to editor components in + listboxes and tables. added 2010-01-05 15:25

Parameters:

  • graphic

    graphic object to use for writing contents

See Also:

  • in rlistbox.


865
866
867
# File 'lib/rbcurse/rwidget.rb', line 865

def override_graphic gr
  @graphic = gr
end

#printstring(win, r, c, string, color, att = Ncurses::A_NORMAL) ⇒ Object

Deprecated.

pls call windows method



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/rbcurse/rwidget.rb', line 503

def printstring(win, r,c,string, color, att = Ncurses::A_NORMAL)

  att = Ncurses::A_NORMAL if att.nil?
  case att.to_s.downcase
  when 'underline'
    att = Ncurses::A_UNDERLINE
    $log.debug "UL att #{att}"
  when 'bold'
    att = Ncurses::A_BOLD
  when 'blink'
    att = Ncurses::A_BLINK
  when 'reverse'
    att = Ncurses::A_REVERSE
  else
    att = Ncurses::A_NORMAL
  end
  #$log.debug "att #{att}"

  #att = bold ? Ncurses::A_BLINK|Ncurses::A_BOLD : Ncurses::A_NORMAL
  #     att = bold ? Ncurses::A_BOLD : Ncurses::A_NORMAL
  win.attron(Ncurses.COLOR_PAIR(color) | att)
  win.mvprintw(r, c, "%s", string);
  win.attroff(Ncurses.COLOR_PAIR(color) | att)
end

#process_key(keycode, object) ⇒ Object

e.g. process_key ch, self returns UNHANDLED if no block for it after form handles basic keys, it gives unhandled key to current field, if current field returns unhandled, then it checks this map. added 2009-01-06 19:13 since widgets need to handle keys properly added 2009-01-18 12:58 returns ret val of blk.call so that if block does not handle, the key can still be handled e.g. table last row, last col does not handle, so it will auto go to next field

2010-02-24 13:45 handles 2 key combinations, copied from Form, must be identical in logic
except maybe for window pointer. TODO not tested


638
639
640
# File 'lib/rbcurse/rwidget.rb', line 638

def process_key keycode, object
  return _process_key keycode, object, @graphic
end

#removeObject



564
565
566
# File 'lib/rbcurse/rwidget.rb', line 564

def remove
  @form.remove_widget(self)
end

#repaintObject

default repaint method. Called by form for all widgets.



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/rbcurse/rwidget.rb', line 480

def repaint
    r,c = rowcol
    $log.debug("widget repaint : r:#{r} c:#{c} col:#{@color}" )
    value = getvalue_for_paint
    len = @display_length || value.length
    if @bgcolor.is_a? String and @color.is_a? String
      acolor = ColorMap.get_color(@color, @bgcolor)
    else
      acolor = $datacolor
    end
    @graphic.printstring r, c, "%-*s" % [len, value], acolor, @attr
    # next line should be in same color but only have @att so we can change att is nec
    #@form.window.mvchgat(y=r, x=c, max=len, Ncurses::A_NORMAL, @bgcolor, nil)
    @buffer_modified = true # required for form to call buffer_to_screen
end

#repaint_all(tf = true) ⇒ Object



852
853
854
855
# File 'lib/rbcurse/rwidget.rb', line 852

def repaint_all(tf=true)
  @repaint_all = tf
  @repaint_required = tf
end

#repaint_required(tf = true) ⇒ Object

to give simple access to other components, (eg, parent) to tell a comp to either paint its data, or to paint all - borders, headers, footers due to a big change (ht/width)



849
850
851
# File 'lib/rbcurse/rwidget.rb', line 849

def repaint_required(tf=true)
  @repaint_required = tf
end

#rowcolObject

row and col is where a widget starts. offsets usually take into account borders. the offsets typically are where the cursor should be positioned inside, upon on_enter.

Returns:

  • row and col of a widget where painting data actually starts



464
465
466
467
# File 'lib/rbcurse/rwidget.rb', line 464

def rowcol
# $log.debug "widgte rowcol : #{@row+@row_offset}, #{@col+@col_offset}"
  return @row+@row_offset, @col+@col_offset
end

#safe_create_bufferObject

checks if buffer not created already, and figures out dimensions. Preferable to use this instead of directly using create_buffer.



695
696
697
698
699
700
701
702
703
704
705
706
# File 'lib/rbcurse/rwidget.rb', line 695

def safe_create_buffer
  if @screen_buffer == nil
    if @height == nil
      @height = @preferred_height || @min_height
    end
    if @width == nil
      @width = @preferred_width || @min_width
    end
    create_buffer
  end
  return @screen_buffer
end

#set_buffer_modified(tf = true) ⇒ Object

Inform the system that the buffer has been modified and should be blitted over the screen or copied to parent.



710
711
712
# File 'lib/rbcurse/rwidget.rb', line 710

def set_buffer_modified(tf=true)
  @buffer_modified = tf
end

#set_buffering(params) ⇒ Object

move from TextView parameters relating to buffering - new 2010-02-12 12:09 RFED16 I am merging so i can call multiple times WARNING NOTE : this does not set Pad’s top and left since Pad may not be created yet, or at all



911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
# File 'lib/rbcurse/rwidget.rb', line 911

def set_buffering params
  @buffer_params ||= {}
  #@should_create_buffer = params[:should_create_buffer] || true
  @target_window ||= params[:target_window]
  # trying out, 2010-02-12 19:40 sometimes no form even with parent.
  @form = params[:form] unless @form
  ## XXX trying this out.
  # what if container does not ask child to buffer, as in splitpane
  # then graphic could be nil
  if @graphic.nil? # and should_create_buffer not set or false XXX
    @graphic = @target_window
  end
  $log.debug " set_buffering #{@name} got target window #{@target_window}, #{@graphic} - THIS DOES NOT UPDATE PAD ... sr:#{params[:screen_top]} sc:#{params[:screen_left]} top:#{params[:top]} left:#{params[:left]} bot:#{params[:bottom]} rt:#{params[:right]} "
  # @top = params[:top]
  # @left = params[:left]
  # @bottom = params[:bottom]
  # @right = params[:right]
  # offsets ?
  # warning, this does not touch @top and left of Pad, often pad will bot yet be created
  @buffer_params.merge!(params)
  if !@screen_buffer.nil?
    # update Pad since some folks take from there such as print_border
    @screen_buffer.top = params[:screen_top] if !params[:screen_top].nil?
    @screen_buffer.left = params[:screen_left] if !params[:screen_left].nil?
  end
end

#set_form(form) ⇒ Object

in those rare cases where we create widget without a form, and later give it to some other program which sets the form. Dirty, we should perhaps create widgets without forms, and add explicitly.



530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/rbcurse/rwidget.rb', line 530

def set_form form
  raise "Form is nil in set_form" if form.nil?
  @form = form
  @id = form.add_widget(self) if !form.nil? and form.respond_to? :add_widget
  # 2009-10-29 15:04 use form.window, unless buffer created
  # should not use form.window so explicitly everywhere.
  # added 2009-12-27 20:05 BUFFERED in case child object needs a form.
  # We don;t wish to overwrite the graphic object
  if @graphic.nil?
    $log.debug " setting graphic to form window for #{self.class}, #{form} "
    @graphic = form.window unless form.nil? # use screen for writing, not buffer
  end
end

#set_form_col(col1 = @curpos) ⇒ Object

set cursor on correct column, widget Ideally, this should be overriden, as it is not likely to be correct.



551
552
553
554
555
556
557
# File 'lib/rbcurse/rwidget.rb', line 551

def set_form_col col1=@curpos
  @curpos = col1 || 0 # 2010-01-14 21:02 
  #@form.col = @col + @col_offset + @curpos
  c = @col + @col_offset + @curpos
  $log.debug " #{@name} widget WARNING super set_form_col #{c}, #{@form} "
  setrowcol nil, c
end

#set_form_rowObject

puts cursor on correct row.



544
545
546
547
548
# File 'lib/rbcurse/rwidget.rb', line 544

def set_form_row
  raise "empty todo widget"
#  @form.row = @row + 1 + @winrow
  @form.row = @row + 1 
end

#set_modified(tf = true) ⇒ Object Also known as: modified



435
436
437
438
# File 'lib/rbcurse/rwidget.rb', line 435

def set_modified tf=true
  @modified = tf
  @form.modified = true if tf
end

#setformrowcol(r, c) ⇒ Object

passing a cursor up and adding col and row offsets Added 2010-01-13 13:27 I am checking this out. I would rather pass the value down and store it than do this recursive call + for each cursor display

See Also:



874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
# File 'lib/rbcurse/rwidget.rb', line 874

def setformrowcol r, c
      @form.row = r unless r.nil?
      @form.col = c unless c.nil?
      # this is stupid, going through this route i was losing windows top and left
      # And this could get repeated if there are mult objects. 
   if !@parent_component.nil? and @parent_component != self
      r+= @parent_component.form.window.top unless  r.nil?
      c+= @parent_component.form.window.left unless c.nil?
      $log.debug " (#{@name}) calling parents setformrowcol #{r}, #{c} pa: #{@parent_component.name} self: #{name}, #{self.class}, poff #{@parent_component.row_offset}, #{@parent_component.col_offset}, top:#{@form.window.left} left:#{@form.window.left} "
      @parent_component.setformrowcol r, c
   else
      # no more parents, now set form
      $log.debug " name NO MORE parents setting #{r}, #{c}    in #{@form} "
      @form.setrowcol r, c
   end
end

#setrowcol(r, c) ⇒ Object

widget: i am putting one extra level of indirection so i can switch here between form#setrowcol and setformrowcol, since i am not convinced either are giving the accurate result. i am not sure what the issue is.



893
894
895
896
897
898
899
900
901
902
903
904
905
# File 'lib/rbcurse/rwidget.rb', line 893

def setrowcol r, c
    # 2010-02-07 21:32 is this where i should add ext_offsets
   #$log.debug " #{@name}  w.setrowcol #{r} + #{@ext_row_offset}, #{c} + #{@ext_col_offset}  "
   # commented off 2010-02-15 18:22 
   #r += @ext_row_offset unless r.nil?
   #c += @ext_col_offset unless c.nil?
   if @form
     @form.setrowcol r, c
   else
     @parent_component.setrowcol r, c
   end
   #setformrowcol r,c 
end

#showObject



561
562
563
# File 'lib/rbcurse/rwidget.rb', line 561

def show
  @visible = true
end

#text_variable(*val) ⇒ Object

getter and setter for text_variable



442
443
444
445
446
447
448
449
450
# File 'lib/rbcurse/rwidget.rb', line 442

def text_variable(*val)
  if val.empty?
    @text_variable
  else
    @text_variable = val[0] 
    $log.debug " GOING TO CALL ADD DELPENDENT #{self}"
    @text_variable.add_dependent(self)
  end
end

#unbind_key(keycode) ⇒ Object

remove a binding that you don’t want



623
624
625
626
# File 'lib/rbcurse/rwidget.rb', line 623

def unbind_key keycode
  @key_args.delete keycode unless @key_args.nil?
  @key_handler.delete keycode unless @key_handler.nil?
end

#width(*val) ⇒ val

getter and setter for width - 2009-10-29 22:45 Using dsl_property style

Parameters:

  • value (val, nil)

    to set

Returns:

  • (val)

    earlier value if nil param

Since:

  • 0.1.3



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# File 'lib/rbcurse/rwidget.rb', line 790

def width(*val)
  #$log.debug " inside XXX width() #{val[0]}"
  if val.empty?
    return @width
  else
    #$log.debug " inside XXX width()"
    oldvalue = @width || 0 # is this default okay, else later nil cries
    @width = val.size == 1 ? val[0] : val
    newvalue = @width
    @config["width"]=@width
    if oldvalue != newvalue
      fire_property_change("width", oldvalue, newvalue)
      repaint_all(true)  # added 2010-01-08 18:51 so widgets can redraw everything.
    end
    if is_double_buffered? and newvalue != oldvalue
      $log.debug " #{@name} w calling resize of screen buffer with #{newvalue}. WARNING: does not change buffering_params"
      @screen_buffer.resize(0, newvalue)
    end
  end
end

#width=(val) ⇒ Object



810
811
812
# File 'lib/rbcurse/rwidget.rb', line 810

def width=val
  width(val)
end