class Tk::ScrollFrame
Public Instance Methods
baseframe()
click to toggle source
DEFAULT_WIDTH = 200 DEFAULT_HEIGHT = 200
# File lib/a-tkcommons.rb, line 836 def baseframe #@frame @base end
bind(*args)
click to toggle source
forbid to change binding of @base frame
# File lib/a-tkcommons.rb, line 1046 def bind(*args) @frame.bind(*args) end
bind_append(*args)
click to toggle source
# File lib/a-tkcommons.rb, line 1049 def bind_append(*args) @frame.bind_append(*args) end
bind_remove(*args)
click to toggle source
# File lib/a-tkcommons.rb, line 1052 def bind_remove(*args) @frame.bind_remove(*args) end
bindinfo(*args)
click to toggle source
# File lib/a-tkcommons.rb, line 1055 def bindinfo(*args) @frame.bindinfo(*args) end
do_xscrollcommand(first,last)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
horizontal scrollbar : ON/OFF
# 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={})
click to toggle source
# 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)
click to toggle source
vertical scrollbar : ON/OFF
# 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?()
click to toggle source
# File lib/a-tkcommons.rb, line 952 def x_scrolled? TkWinfo.mapped?(@h_scroll) end
xview_moveto(_index)
click to toggle source
# File lib/a-tkcommons.rb, line 960 def xview_moveto(_index) @canvas.xview_moveto(_index) end
y_scrolled?()
click to toggle source
# File lib/a-tkcommons.rb, line 948 def y_scrolled? TkWinfo.mapped?(@v_scroll) end
yview_moveto(_index)
click to toggle source
# File lib/a-tkcommons.rb, line 956 def yview_moveto(_index) @canvas.yview_moveto(_index) end
Private Instance Methods
_reset_scrollregion(h_mod=nil, v_mod=nil)
click to toggle source
callback for Configure event
# File lib/a-tkcommons.rb, line 1005 def _reset_scrollregion(h_mod=nil, v_mod=nil) cx1, cy1, cx2, cy2 = @canvas.scrollregion x1, y1, x2, y2 = @cwin.bbox @canvas.scrollregion([x1, y1, x2, y2]) if h_mod.nil? && v_mod.nil? if x2 != cx2 && TkGrid.info(@h_scroll).size == 0 @frame.grid_propagate(true) @canvas.width = x2 Tk.update_idletasks @frame.grid_propagate(false) end if y2 != cy2 && TkGrid.info(@v_scroll).size == 0 @frame.grid_propagate(true) @canvas.height = y2 Tk.update_idletasks @frame.grid_propagate(false) end else @h_scroll.ungrid if h_mod == false @v_scroll.ungrid if v_mod == false h_flag = (TkGrid.info(@h_scroll).size == 0) v_flag = (TkGrid.info(@v_scroll).size == 0) @frame.grid_propagate(true) @canvas.width = (h_flag)? x2: @canvas.winfo_width @canvas.height = (v_flag)? y2: @canvas.winfo_height @h_scroll.grid('row'=>1, 'column'=>0, 'sticky'=>'ew') if h_mod @v_scroll.grid('row'=>0, 'column'=>1, 'sticky'=>'ns') if v_mod Tk.update_idletasks @frame.grid_propagate(false) end end