Module: TkScrollableWidget

Defined in:
lib/a-tkcommons.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(_widget) ⇒ Object



2936
2937
2938
# File 'lib/a-tkcommons.rb', line 2936

def self.extended(_widget)
  _widget.__initialize_scrolling(_widget)
end

.included(_widget) ⇒ Object



2940
2941
2942
# File 'lib/a-tkcommons.rb', line 2940

def self.included(_widget)
  _widget.__initialize_scrolling(_widget)
end

Instance Method Details

#__initialize_scrolling(_widget = self) ⇒ Object



2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
# 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) ⇒ Object



2992
2993
2994
# File 'lib/a-tkcommons.rb', line 2992

def add_xscrollcommand(cmd=Proc.new)
  @h_scroll_command = cmd
end

#add_yscrollcommand(cmd = Proc.new) ⇒ Object



2969
2970
2971
# File 'lib/a-tkcommons.rb', line 2969

def add_yscrollcommand(cmd=Proc.new)
  @v_scroll_command = cmd
end

#arm_scroll_bindingObject



3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
# 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) ⇒ Object



2961
2962
2963
# 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) ⇒ Object



2965
2966
2967
# File 'lib/a-tkcommons.rb', line 2965

def call_after_next_show_v_scroll(_proc_to_call=nil)
  @v_proc = _proc_to_call    
end

#destroyObject



2956
2957
2958
2959
# File 'lib/a-tkcommons.rb', line 2956

def destroy
  @h_scroll.destroy
  @v_scroll.destroy
end

#disarm_scroll_bindingObject



3078
3079
3080
3081
3082
3083
# 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) ⇒ Object



2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
# 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) ⇒ Object



2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
# 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

#hideObject



3056
3057
3058
3059
3060
3061
# 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_scrollObject



3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
# 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_scrollObject



3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
# 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') ⇒ Object



3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
# 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) ⇒ Object



3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
# 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) ⇒ Object



3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
# 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_managerObject



3052
3053
3054
# File 'lib/a-tkcommons.rb', line 3052

def widget_manager
  defined?(@widget_manager)? @widget_manager : nil
end