OSDN Git Service

ruby-1.9.1-rc1
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / ext / tk / lib / tkextlib / iwidgets / notebook.rb
1 #
2 #  tkextlib/iwidgets/notebook.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 Notebook < Tk::Itk::Widget
12     end
13   end
14 end
15
16 class Tk::Iwidgets::Notebook
17   TkCommandNames = ['::iwidgets::notebook'.freeze].freeze
18   WidgetClassName = 'Notebook'.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 tagid(tagOrId)
36     if tagOrId.kind_of?(Tk::Itk::Component)
37       tagOrId.name
38     else
39       #_get_eval_string(tagOrId)
40       tagOrId
41     end
42   end
43
44   alias pagecget itemcget
45   alias pagecget_strict itemcget_strict
46   alias pageconfigure itemconfigure
47   alias pageconfiginfo itemconfiginfo
48   alias current_pageconfiginfo current_itemconfiginfo
49
50   private :itemcget, :itemcget_strict
51   private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
52
53   ####################################
54
55   def __boolval_optkeys
56     super() << 'auto'
57   end
58   private :__boolval_optkeys
59
60   def add(keys={})
61     window(tk_call(@path, 'add', *hash_kv(keys)))
62   end
63
64   def child_site_list
65     list(tk_call(@path, 'childsite'))
66   end
67
68   def child_site(idx)
69     if (new_idx = self.index(idx)) < 0
70       new_idx = tagid(idx)
71     end
72     window(tk_call(@path, 'childsite', new_idx))
73   end
74
75   def delete(idx1, idx2=nil)
76     if (new_idx1 = self.index(idx1)) < 0
77       new_idx1 = tagid(idx1)
78     end
79     if idx2
80       if (new_idx2 = self.index(idx2)) < 0
81         new_idx2 = tagid(idx2)
82       end
83       tk_call(@path, 'delete', new_idx1, new_idx2)
84     else
85       tk_call(@path, 'delete', new_idx1)
86     end
87     self
88   end
89
90   def index(idx)
91     number(tk_call(@path, 'index', tagid(idx)))
92   end
93
94   def insert(idx, keys={})
95     if (new_idx = self.index(idx)) < 0
96       new_idx = tagid(idx)
97     end
98     window(tk_call(@path, 'insert', new_idx, *hash_kv(keys)))
99   end
100
101   def next
102     tk_call(@path, 'next')
103     self
104   end
105
106   def prev
107     tk_call(@path, 'prev')
108     self
109   end
110
111   def select(idx)
112     if (new_idx = self.index(idx)) < 0
113       new_idx = tagid(idx)
114     end
115     tk_call(@path, 'select', new_idx)
116     self
117   end
118
119   def scrollcommand(cmd=Proc.new)
120     configure_cmd 'scrollcommand', cmd
121     self
122   end
123   alias xscrollcommand scrollcommand
124   alias yscrollcommand scrollcommand
125
126   def xscrollbar(bar=nil)
127     if bar
128       @scrollbar = bar
129       @scrollbar.orient 'horizontal'
130       self.scrollcommand {|*arg| @scrollbar.set(*arg)}
131       @scrollbar.command {|*arg| self.xview(*arg)}
132       Tk.update  # avoid scrollbar trouble
133     end
134     @scrollbar
135   end
136   def yscrollbar(bar=nil)
137     if bar
138       @scrollbar = bar
139       @scrollbar.orient 'vertical'
140       self.scrollcommand {|*arg| @scrollbar.set(*arg)}
141       @scrollbar.command {|*arg| self.yview(*arg)}
142       Tk.update  # avoid scrollbar trouble
143     end
144     @scrollbar
145   end
146   alias scrollbar yscrollbar
147
148   def view(*idxs)
149     if idxs.size == 0
150       idx = num_or_str(tk_send_without_enc('view'))
151       if idx.kind_of?(Fixnum) && idx < 0
152         nil
153       else
154         idx
155       end
156     else
157       tk_send_without_enc('view', *idxs)
158       self
159     end
160   end
161   alias xview view
162   alias yview view
163
164   def view_moveto(*idxs)
165     view('moveto', *idxs)
166   end
167   alias xview_moveto view_moveto
168   alias yview_moveto view_moveto
169   def view_scroll(index, what='pages')
170     view('scroll', index, what)
171   end
172   alias xview_scroll view_scroll
173   alias yview_scroll view_scroll
174 end