1 #
2 # tk/scrollbox.rb - Tk Listbox with Scrollbar
3 # as an example of Composite Widget
4 # by Yukihiro Matsumoto <matz@netlab.co.jp>
5 #
6 require 'tk'
7 require 'tk/listbox'
8
9 class TkScrollbox<Tk::Listbox
10 include TkComposite
11 def initialize_composite(keys=nil)
12 #list = Tk::Listbox.new(@frame)
13 # -> use current TkListbox class
14 list = TkListbox.new(@frame)
15 #scroll = Tk::Scrollbar.new(@frame)
16 # -> use current TkScrollbar class
17 scroll = TkScrollbar.new(@frame)
18 @path = list.path
19
20 =begin
21 list.configure 'yscroll', scroll.path+" set"
22 list.pack 'side'=>'left','fill'=>'both','expand'=>'yes'
23 scroll.configure 'command', list.path+" yview"
24 scroll.pack 'side'=>'right','fill'=>'y'
25 =end
26 list.yscrollbar(scroll)
27 list.pack('side'=>'left','fill'=>'both','expand'=>'yes')
28 scroll.pack('side'=>'right','fill'=>'y')
29
30 delegate('DEFAULT', list)
31 delegate('foreground', list)
32 delegate('background', list, scroll)
33 delegate('borderwidth', @frame)
34 delegate('relief', @frame)
35
36 configure keys if keys
37 end
38 private :initialize_composite
39 end