Class: Tk::ScrollFrame

Inherits:
TkFrame
  • Object
show all
Includes:
TkComposite
Defined in:
lib/a-tkcommons.rb

Instance Method Summary collapse

Instance Method Details

#baseframeObject

DEFAULT_WIDTH = 200

DEFAULT_HEIGHT = 200

836
837
838
839
# File 'lib/a-tkcommons.rb', line 836

def baseframe
  #@frame
  @base
end

#bind(*args) ⇒ Object

forbid to change binding of @base frame


1046
1047
1048
# File 'lib/a-tkcommons.rb', line 1046

def bind(*args)
  @frame.bind(*args)
end

#bind_append(*args) ⇒ Object


1049
1050
1051
# File 'lib/a-tkcommons.rb', line 1049

def bind_append(*args)
  @frame.bind_append(*args)
end

#bind_remove(*args) ⇒ Object


1052
1053
1054
# File 'lib/a-tkcommons.rb', line 1052

def bind_remove(*args)
  @frame.bind_remove(*args)
end

#bindinfo(*args) ⇒ Object


1055
1056
1057
# File 'lib/a-tkcommons.rb', line 1055

def bindinfo(*args)
  @frame.bindinfo(*args)
end

#do_xscrollcommand(first, last) ⇒ Object


984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
# File 'lib/a-tkcommons.rb', line 984

def do_xscrollcommand(first,last)
  if first != nil && last != nil
    delta = last.to_f - first.to_f
    if delta != @last_x_delta
      if delta < 1 && delta > 0.2 && last != @last_x_last
        hscroll(true)
      begin
        @h_scroll.set(first,last) if TkWinfo.mapped?(@h_scroll)
      rescue Exception => e
        Arcadia.runtime_error(e)
      end
      elsif delta == 1 || delta == 0
        hscroll(false)
      end
    end
    @last_x_last = last if last.to_f < 1
    @last_x_delta = delta
  end    
end

#do_yscrollcommand(first, last) ⇒ Object


964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
# File 'lib/a-tkcommons.rb', line 964

def do_yscrollcommand(first,last)
  if first != nil && last != nil
    delta = last.to_f - first.to_f
    if delta != @last_y_delta
      if delta < 1 && delta > 0 && last != @last_y_last
        vscroll(true)
      begin
        @v_scroll.set(first,last) if TkWinfo.mapped?(@v_scroll)
      rescue Exception => e
        Arcadia.runtime_error(e)
      end
      elsif delta == 1 || delta == 0
        vscroll(false)
      end
    end
    @last_y_last = last if last.to_f < 1
    @last_y_delta = delta
  end    
end

#hscroll(mode) ⇒ Object

horizontal scrollbar : ON/OFF


1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
# File 'lib/a-tkcommons.rb', line 1085

def hscroll(mode)
  Tk.update_idletasks
  st = TkGrid.info(@h_scroll)
  if mode && st.size == 0 then
    _reset_scrollregion(true, nil)
  elsif !mode && st.size != 0 then
    _reset_scrollregion(false, nil)
  else
    _reset_scrollregion(nil, nil)
  end
  self
end

#initialize_composite(keys = {}) ⇒ Object


841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
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
937
938
939
940
941
942
943
944
945
# File 'lib/a-tkcommons.rb', line 841

def initialize_composite(keys={})
  #@frame.configure(:width=>DEFAULT_WIDTH, :height=>DEFAULT_HEIGHT)

  # create scrollbars
#    @h_scroll = TkScrollbar.new(@frame, 'orient'=>'horizontal')
#    @v_scroll = TkScrollbar.new(@frame, 'orient'=>'vertical')

  @v_scroll = Arcadia.wf.scrollbar(@frame,{'orient'=>'vertical'})
  @h_scroll = Arcadia.wf.scrollbar(@frame,{'orient'=>'horizontal'})


  # create a canvas widget
  @canvas = TkCanvas.new(@frame, 
                         :borderwidth=>0, :selectborderwidth=>0, 
                         :highlightthickness=>0)

  # allignment
  TkGrid.rowconfigure(@frame, 0, 'weight'=>1, 'minsize'=>0)
  TkGrid.columnconfigure(@frame, 0, 'weight'=>1, 'minsize'=>0)
  @canvas.grid('row'=>0, 'column'=>0, 'sticky'=>'news')
  @frame.grid_propagate(false)

  # assign scrollbars
  @canvas.xscrollbar(@h_scroll)
  @canvas.yscrollbar(@v_scroll)

  # convert hash keys
  keys = _symbolkey2str(keys)

  # check options for the frame
  framekeys = {}
  if keys.key?('classname')
     keys['class'] = keys.delete('classname')
  end
  if @classname = keys.delete('class')
    framekeys['class'] = @classname
  end
  if @colormap  = keys.delete('colormap')
    framekeys['colormap'] = @colormap
  end
  if @container = keys.delete('container')
    framekeys['container'] = @container
  end
  if @visual    = keys.delete('visual')
    framekeys['visual'] = @visual
  end
  if @classname.kind_of? TkBindTag
    @db_class = @classname
    @classname = @classname.id
  elsif @classname
    @db_class = TkDatabaseClass.new(@classname)
  else
    @db_class = self.class
    @classname = @db_class::WidgetClassName
  end

  # create base frame
  @base = TkFrame.new(@canvas, framekeys)

  # embed base frame
  @cwin = TkcWindow.new(@canvas, [0, 0], :window=>@base, :anchor=>'nw')
  @canvas.scrollregion(@cwin.bbox)

  # binding to reset scrollregion
  @base.bind('Configure'){_reset_scrollregion(nil, nil) }

  # set default receiver of method calls
  @path = @base.path

  # scrollbars ON
  vscroll(keys.delete('vscroll'){true})
  hscroll(keys.delete('hscroll'){true})

  # please check the differences of the following definitions
#    option_methods(
#      :scrollbarwidth
#    )

  # set receiver widgets for configure methods (with alias)
  delegate_alias('scrollbarrelief', 'relief', @h_scroll, @v_scroll)

  # set receiver widgets for configure methods
  delegate('DEFAULT', @base)
  delegate('background', @frame, @base, @canvas, @h_scroll, @v_scroll)
  delegate('width', @frame)
  delegate('height', @frame)
  delegate('activebackground', @h_scroll, @v_scroll)
  delegate('troughcolor', @h_scroll, @v_scroll)
  delegate('repeatdelay', @h_scroll, @v_scroll)
  delegate('repeatinterval', @h_scroll, @v_scroll)
  delegate('borderwidth', @frame)
  delegate('relief', @frame)

  # do configure
  configure keys unless keys.empty?

  @canvas.yscrollcommand(proc{|first,last|
    do_yscrollcommand(first,last)
  })

  @canvas.xscrollcommand(proc{|first,last|
    do_xscrollcommand(first,last)
  })

end

#vscroll(mode) ⇒ Object

vertical scrollbar : ON/OFF


1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
# File 'lib/a-tkcommons.rb', line 1070

def vscroll(mode)
  Tk.update_idletasks
  st = TkGrid.info(@v_scroll)
  if mode && st.size == 0 then
#      @v_scroll.grid('row'=>0, 'column'=>1, 'sticky'=>'ns')
    _reset_scrollregion(nil, true)
  elsif !mode && st.size != 0 then
    _reset_scrollregion(nil, false)
  else
    _reset_scrollregion(nil, nil)
  end
  self
end

#x_scrolled?Boolean

Returns:

  • (Boolean)

952
953
954
# File 'lib/a-tkcommons.rb', line 952

def x_scrolled?
  TkWinfo.mapped?(@h_scroll)
end

#xview_moveto(_index) ⇒ Object


960
961
962
# File 'lib/a-tkcommons.rb', line 960

def xview_moveto(_index)
  @canvas.xview_moveto(_index) 
end

#y_scrolled?Boolean

Returns:

  • (Boolean)

948
949
950
# File 'lib/a-tkcommons.rb', line 948

def y_scrolled?
  TkWinfo.mapped?(@v_scroll)
end

#yview_moveto(_index) ⇒ Object


956
957
958
# File 'lib/a-tkcommons.rb', line 956

def yview_moveto(_index)
  @canvas.yview_moveto(_index) 
end