module TkScrollableWidget

Public Class Methods

extended(_widget) click to toggle source
# File lib/a-tkcommons.rb, line 2936
def self.extended(_widget)
  _widget.__initialize_scrolling(_widget)
end
included(_widget) click to toggle source
# File lib/a-tkcommons.rb, line 2940
def self.included(_widget)
  _widget.__initialize_scrolling(_widget)
end

Public Instance Methods

__initialize_scrolling(_widget=self) click to toggle source
# File lib/a-tkcommons.rb, line 2944
def __initialize_scrolling(_widget=self)
  @widget = _widget
  @parent = TkWinfo.parent(@widget)
  @scroll_width = Arcadia.style('scrollbar')['width'].to_i
  @x=0
  @y=0
  @v_scroll_on = false
  @h_scroll_on = false
  @v_scroll = Arcadia.wf.scrollbar(@parent,{'orient'=>'vertical'})
  @h_scroll = Arcadia.wf.scrollbar(@parent,{'orient'=>'horizontal'})
end
add_xscrollcommand(cmd=Proc.new) click to toggle source
# File lib/a-tkcommons.rb, line 2992
def add_xscrollcommand(cmd=Proc.new)
  @h_scroll_command = cmd
end
add_yscrollcommand(cmd=Proc.new) click to toggle source
# File lib/a-tkcommons.rb, line 2969
def add_yscrollcommand(cmd=Proc.new)
  @v_scroll_command = cmd
end
arm_scroll_binding() click to toggle source
# File lib/a-tkcommons.rb, line 3063
def arm_scroll_binding
  @widget.yscrollcommand(proc{|first,last|
    do_yscrollcommand(first,last)
  })
  @v_scroll.command(proc{|*args|
    @widget.yview *args
  })
  @widget.xscrollcommand(proc{|first,last|
    do_xscrollcommand(first,last)
  })
  @h_scroll.command(proc{|*args|
    @widget.xview *args
  })
end
call_after_next_show_h_scroll(_proc_to_call=nil) click to toggle source
# File lib/a-tkcommons.rb, line 2961
def call_after_next_show_h_scroll(_proc_to_call=nil)
  @h_proc = _proc_to_call
end
call_after_next_show_v_scroll(_proc_to_call=nil) click to toggle source
# File lib/a-tkcommons.rb, line 2965
def call_after_next_show_v_scroll(_proc_to_call=nil)
  @v_proc = _proc_to_call    
end
destroy() click to toggle source
# File lib/a-tkcommons.rb, line 2956
def destroy
  @h_scroll.destroy
  @v_scroll.destroy
end
disarm_scroll_binding() click to toggle source
# File lib/a-tkcommons.rb, line 3078
def disarm_scroll_binding
  @widget.yscrollcommand(proc{})
  @widget.xscrollcommand(proc{})
  @v_scroll.command(proc{}) if @v_scroll
  @h_scroll.command(proc{}) if @h_scroll
end
do_xscrollcommand(first,last) click to toggle source
# File lib/a-tkcommons.rb, line 2996
def do_xscrollcommand(first,last)
  if first != nil && last != nil
    delta = last.to_f - first.to_f
    if delta < 1 && delta > 0  && last != @last_x_last
      show_h_scroll
      begin
        @h_scroll.set(first,last) #if TkWinfo.mapped?(@h_scroll)
      rescue Exception => e
        Arcadia.runtime_error(e)
        #p "#{e.message}"
      end
    elsif  delta == 1 || delta == 0
      hide_h_scroll
    end
    @h_scroll_command.call(first,last) if !@h_scroll_command.nil?
    @last_x_last = last if last.to_f < 1
  end
  if @x_proc
    begin
      @x_proc.call
    ensure
      @x_proc=nil
    end
  end
end
do_yscrollcommand(first,last) click to toggle source
# File lib/a-tkcommons.rb, line 2973
def do_yscrollcommand(first,last)
  if first != nil && last != nil
    delta = last.to_f - first.to_f
    if delta < 1 && delta > 0 && last != @last_y_last
      show_v_scroll
      begin
        @v_scroll.set(first,last) #if TkWinfo.mapped?(@v_scroll)
      rescue Exception => e
        Arcadia.runtime_error(e)
        #p "#{e.message}"
      end
    elsif delta == 1 || delta == 0
      hide_v_scroll
    end
    @v_scroll_command.call(first,last) if !@v_scroll_command.nil?
    @last_y_last = last if last.to_f < 1
  end    
end
hide() click to toggle source
# File lib/a-tkcommons.rb, line 3056
def hide
  disarm_scroll_binding
  @widget.unplace if widget_manager == 'place'
  @v_scroll.unpack
  @h_scroll.unpack
end
hide_h_scroll() click to toggle source
# File lib/a-tkcommons.rb, line 3141
def hide_h_scroll
  if @h_scroll_on
    begin
      @widget.place('height' => 0) if widget_manager == 'place'
      @h_scroll.unpack
      @h_scroll_on = false
    rescue RuntimeError => e
      Arcadia.runtime_error(e)
      #p "RuntimeError : #{e.message}"
    end
  end
end
hide_v_scroll() click to toggle source
# File lib/a-tkcommons.rb, line 3127
def hide_v_scroll
  if @v_scroll_on
    begin
      @widget.place('width' => 0) if widget_manager == 'place'
      @v_scroll.unpack
      @v_scroll_on = false
    rescue RuntimeError => e
      Arcadia.runtime_error(e)
      #p "RuntimeError : #{e.message}"
    end

  end
end
show(_x=0,_y=0,_w=nil,_h=nil,_border_mode='inside') click to toggle source
# File lib/a-tkcommons.rb, line 3022
def show(_x=0,_y=0,_w=nil,_h=nil,_border_mode='inside')
  @x=_x
  @y=_y
  _w != nil ? @w=_w : @w=-@x
  _h != nil ? @h=_h : @h=-@y
  @widget.place(
    'x'=>@x,
    'y'=>@y,
    'width' => @w,
    'height' => @h,
    'relheight'=>1,
    'relwidth'=>1,
    'bordermode'=>_border_mode
  )
  @widget.raise
  @widget_manager = 'place'
  if @v_scroll_on
    show_v_scroll(true)
  end
  if @h_scroll_on
    show_h_scroll(true)
  end
  begin
    arm_scroll_binding
  rescue  Exception => e
    Arcadia.runtime_error(e)
    #p "#{e.message}"
  end
end
show_h_scroll(_force=false) click to toggle source
# File lib/a-tkcommons.rb, line 3106
def show_h_scroll(_force=false)
  if _force || !@h_scroll_on
    begin
      @widget.place('height' => -@scroll_width-@y) if widget_manager == 'place'
      @h_scroll.pack('side' => 'bottom', 'fill' => 'x')
      @h_scroll_on = true
      @h_scroll.raise
      if @h_proc
        begin
          @h_proc.call
        ensure
          @h_proc=nil
        end
      end
    rescue RuntimeError => e
      #p "RuntimeError : #{e.message}"
      Arcadia.runtime_error(e)
    end
  end
end
show_v_scroll(_force=false) click to toggle source
# File lib/a-tkcommons.rb, line 3085
def show_v_scroll(_force=false)
  if _force || !@v_scroll_on
    begin
      @widget.place('width' => -@scroll_width-@x) if widget_manager == 'place'
      @v_scroll.pack('side' => 'right', 'fill' => 'y')
      @v_scroll_on = true
      @v_scroll.raise
      if @v_proc
        begin
          @v_proc.call
        ensure
          @v_proc=nil
        end
      end
    rescue RuntimeError => e
      #p "RuntimeError : #{e.message}"
      Arcadia.runtime_error(e)
    end
  end
end
widget_manager() click to toggle source
# File lib/a-tkcommons.rb, line 3052
def widget_manager
  defined?(@widget_manager)? @widget_manager : nil
end