1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/tk/lib/tk.rb: add new methods (TkScrollbar#assign, assign_list)

* ext/tk/sample/tkmultilistframe.rb: use TkScrollbar#assign method


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2003-12-20 15:15:51 +00:00
parent a679f1861f
commit 342aba0b84
2 changed files with 78 additions and 0 deletions

View file

@ -5107,6 +5107,15 @@ class TkScrollbar<TkWindow
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
@assigned = []
@scroll_proc = proc{|*args|
if self.orient == 'horizontal'
@assigned.each{|w| w.xview(*args)}
else # 'vertical'
@assigned.each{|w| w.yview(*args)}
end
}
if keys and keys != None
tk_call 'scrollbar', @path, *hash_kv(keys)
else
@ -5115,6 +5124,32 @@ class TkScrollbar<TkWindow
end
private :create_self
def assign(*wins)
begin
self.command(@scroll_proc) if self.cget('command').cmd != @scroll_proc
rescue Exception
self.command(@scroll_proc)
end
orient = self.orient
wins.each{|w|
@assigned << w unless @assigned.index(w)
if orient == 'horizontal'
w.xscrollcommand proc{|first, last| self.set(first, last)}
else # 'vertical'
w.yscrollcommand proc{|first, last| self.set(first, last)}
end
}
self
end
def assigned_list
begin
return @assigned.dup if self.cget('command').cmd == @scroll_proc
rescue Exception
end
fail RuntimeError, "not depend on the assigned_list"
end
def delta(deltax=None, deltay=None)
number(tk_send('delta', deltax, deltay))
end
@ -5146,6 +5181,24 @@ class TkScrollbar<TkWindow
end
end
class TkXScrollbar<TkScrollbar
def create_self(keys)
keys = {} unless keys
keys['orient'] = 'horizontal'
super(keys)
end
private :create_self
end
class TkYScrollbar<TkScrollbar
def create_self(keys)
keys = {} unless keys
keys['orient'] = 'vertical'
super(keys)
end
private :create_self
end
class TkTextWin<TkWindow
def create_self
fail RuntimeError, "TkTextWin is an abstract class"

View file

@ -50,14 +50,24 @@ class TkMultiListFrame < TkListbox
@h_l_thick = 0
# virtical scrollbar
=begin
@v_scroll = TkScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick,
'borderwidth'=>@scrbar_border,
'orient'=>'vertical', 'width'=>@scrbar_width)
=end
@v_scroll = TkYScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick,
'borderwidth'=>@scrbar_border,
'width'=>@scrbar_width)
# horizontal scrollbar
=begin
@h_scroll = TkScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick,
'borderwidth'=>@scrbar_border,
'orient'=>'horizontal', 'width'=>@scrbar_width)
=end
@h_scroll = TkXScrollbar.new(@frame, 'highlightthickness'=>@h_l_thick,
'borderwidth'=>@scrbar_border,
'width'=>@scrbar_width)
# create base flames
@c_title = TkCanvas.new(@frame, 'highlightthickness'=>@h_l_thick,
@ -118,18 +128,27 @@ class TkMultiListFrame < TkListbox
# scrollbar field
f = TkFrame.new(@f_hscr, 'width'=>width)
base << f
=begin
@hscr_list << TkScrollbar.new(f, 'orient'=>'horizontal',
'width'=>@scrbar_width,
'borderwidth'=>@scrbar_border,
'highlightthickness'=>@h_l_thick
).pack('fill'=>'x', 'anchor'=>'w')
=end
@hscr_list << TkXScrollbar.new(f, 'width'=>@scrbar_width,
'borderwidth'=>@scrbar_border,
'highlightthickness'=>@h_l_thick
).pack('fill'=>'x', 'anchor'=>'w')
f.place('relx'=>@rel_list[idx], 'y'=>0, 'anchor'=>'nw', 'width'=>1,
'relwidth'=>@rel_list[idx+1] - @rel_list[idx])
=begin
@lbox_list[idx].xscrollcommand proc{|first, last|
@hscr_list[idx].set first, last
}
@hscr_list[idx].command proc{|*args| @lbox_list[idx].xview *args}
=end
@lbox_list[idx].xscrollbar(@hscr_list[idx])
# add new base
@base_list << base
@ -163,14 +182,18 @@ class TkMultiListFrame < TkListbox
@f_hscr.height hscr_height
# set control procedure for virtical scroll
=begin
@lbox_list.each{|lbox|
lbox.yscrollcommand proc{|first, last|
@v_scroll.set first, last
}
}
@v_scroll.command proc{|*args| @lbox_list.each{|lbox| lbox.yview *args} }
=end
@v_scroll.assign(*@lbox_list)
# set control procedure for horizoncal scroll
=begin
@c_title.xscrollcommand proc{|first, last|
@h_scroll.set first, last
}
@ -185,6 +208,8 @@ class TkMultiListFrame < TkListbox
@c_lbox.xview *args
@c_hscr.xview *args if @show_each_hscr
}
=end
@h_scroll.assign(@c_title, @c_lbox, @c_hscr)
# binding for listboxes
@mode = {}