OSDN Git Service

ruby-1.9.1-rc1
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / ext / tk / lib / tkextlib / iwidgets / tabnotebook.rb
1 #
2 #  tkextlib/iwidgets/tabnotebook.rb
3 #                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
4 #
5
6 require 'tk'
7 require 'tkextlib/iwidgets.rb'
8
9 module Tk
10   module Iwidgets
11     class Tabnotebook < Tk::Itk::Widget
12     end
13   end
14 end
15
16 class Tk::Iwidgets::Tabnotebook
17   TkCommandNames = ['::iwidgets::tabnotebook'.freeze].freeze
18   WidgetClassName = 'Tabnotebook'.freeze
19   WidgetClassNames[WidgetClassName] = self
20
21   ####################################
22
23   include TkItemConfigMethod
24
25   def __item_cget_cmd(id)
26     [self.path, 'pagecget', id]
27   end
28   private :__item_cget_cmd
29
30   def __item_config_cmd(id)
31     [self.path, 'pageconfigure', id]
32   end
33   private :__item_config_cmd
34
35   def __item_strval_optkeys(id)
36     super(id) << 'tabbackground' << 'tabforeground'
37   end
38   private :__item_strval_optkeys
39
40   def tagid(tagOrId)
41     if tagOrId.kind_of?(Tk::Itk::Component)
42       tagOrId.name
43     else
44       #_get_eval_string(tagOrId)
45       tagOrId
46     end
47   end
48
49   alias pagecget itemcget
50   alias pagecget_strict itemcget_strict
51   alias pageconfigure itemconfigure
52   alias pageconfiginfo itemconfiginfo
53   alias current_pageconfiginfo current_itemconfiginfo
54
55   private :itemcget, :itemcget_strict
56   private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
57
58   ####################################
59
60   def __boolval_optkeys
61     super() << 'auto' << 'equaltabs' << 'raiseselect' << 'tabborders'
62   end
63   private :__boolval_optkeys
64
65   def __strval_optkeys
66     super() << 'backdrop' << 'tabbackground' << 'tabforeground'
67   end
68   private :__strval_optkeys
69
70   def initialize(*args)
71     super(*args)
72     @tabset = self.component_widget('tabset')
73   end
74
75   def add(keys={})
76     window(tk_call(@path, 'add', *hash_kv(keys)))
77   end
78
79   def child_site_list
80     list(tk_call(@path, 'childsite'))
81   end
82
83   def child_site(idx)
84     window(tk_call(@path, 'childsite', index(idx)))
85   end
86
87   def delete(idx1, idx2=nil)
88     if idx2
89       tk_call(@path, 'delete', index(idx1), index(idx2))
90     else
91       tk_call(@path, 'delete', index(idx1))
92     end
93     self
94   end
95
96   def index(idx)
97     #number(tk_call(@path, 'index', tagid(idx)))
98     @tabset.index(tagid(idx))
99   end
100
101   def insert(idx, keys={})
102     window(tk_call(@path, 'insert', index(idx), *hash_kv(keys)))
103   end
104
105   def next
106     tk_call(@path, 'next')
107     self
108   end
109
110   def prev
111     tk_call(@path, 'prev')
112     self
113   end
114
115   def select(idx)
116     tk_call(@path, 'select', index(idx))
117     self
118   end
119
120   def show_tab(idx)
121     @tabset.show_tab(idx)
122     self
123   end
124
125   def scrollcommand(cmd=Proc.new)
126     configure_cmd 'scrollcommand', cmd
127     self
128   end
129   alias xscrollcommand scrollcommand
130   alias yscrollcommand scrollcommand
131
132   def xscrollbar(bar=nil)
133     if bar
134       @scrollbar = bar
135       @scrollbar.orient 'horizontal'
136       self.scrollcommand {|*arg| @scrollbar.set(*arg)}
137       @scrollbar.command {|*arg| self.xview(*arg)}
138       Tk.update  # avoid scrollbar trouble
139     end
140     @scrollbar
141   end
142   def yscrollbar(bar=nil)
143     if bar
144       @scrollbar = bar
145       @scrollbar.orient 'vertical'
146       self.scrollcommand {|*arg| @scrollbar.set(*arg)}
147       @scrollbar.command {|*arg| self.yview(*arg)}
148       Tk.update  # avoid scrollbar trouble
149     end
150     @scrollbar
151   end
152   alias scrollbar yscrollbar
153
154   def view(*index)
155     if index.size == 0
156       idx = num_or_str(tk_send_without_enc('view'))
157       if idx.kind_of?(Fixnum) && idx < 0
158         nil
159       else
160         idx
161       end
162     else
163       tk_send_without_enc('view', *index)
164       self
165     end
166   end
167   alias xview view
168   alias yview view
169
170   def view_moveto(*index)
171     view('moveto', *index)
172   end
173   alias xview_moveto view_moveto
174   alias yview_moveto view_moveto
175   def view_scroll(index, what='pages')
176     view('scroll', index, what)
177   end
178   alias xview_scroll view_scroll
179   alias yview_scroll view_scroll
180 end