2 # tkextlib/iwidgets/notebook.rb
3 # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
7 require 'tkextlib/iwidgets.rb'
11 class Notebook < Tk::Itk::Widget
16 class Tk::Iwidgets::Notebook
17 TkCommandNames = ['::iwidgets::notebook'.freeze].freeze
18 WidgetClassName = 'Notebook'.freeze
19 WidgetClassNames[WidgetClassName] = self
21 ####################################
23 include TkItemConfigMethod
25 def __item_cget_cmd(id)
26 [self.path, 'pagecget', id]
28 private :__item_cget_cmd
30 def __item_config_cmd(id)
31 [self.path, 'pageconfigure', id]
33 private :__item_config_cmd
36 if tagOrId.kind_of?(Tk::Itk::Component)
39 #_get_eval_string(tagOrId)
44 alias pagecget itemcget
45 alias pagecget_strict itemcget_strict
46 alias pageconfigure itemconfigure
47 alias pageconfiginfo itemconfiginfo
48 alias current_pageconfiginfo current_itemconfiginfo
50 private :itemcget, :itemcget_strict
51 private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
53 ####################################
58 private :__boolval_optkeys
61 window(tk_call(@path, 'add', *hash_kv(keys)))
65 list(tk_call(@path, 'childsite'))
69 if (new_idx = self.index(idx)) < 0
72 window(tk_call(@path, 'childsite', new_idx))
75 def delete(idx1, idx2=nil)
76 if (new_idx1 = self.index(idx1)) < 0
77 new_idx1 = tagid(idx1)
80 if (new_idx2 = self.index(idx2)) < 0
81 new_idx2 = tagid(idx2)
83 tk_call(@path, 'delete', new_idx1, new_idx2)
85 tk_call(@path, 'delete', new_idx1)
91 number(tk_call(@path, 'index', tagid(idx)))
94 def insert(idx, keys={})
95 if (new_idx = self.index(idx)) < 0
98 window(tk_call(@path, 'insert', new_idx, *hash_kv(keys)))
102 tk_call(@path, 'next')
107 tk_call(@path, 'prev')
112 if (new_idx = self.index(idx)) < 0
115 tk_call(@path, 'select', new_idx)
119 def scrollcommand(cmd=Proc.new)
120 configure_cmd 'scrollcommand', cmd
123 alias xscrollcommand scrollcommand
124 alias yscrollcommand scrollcommand
126 def xscrollbar(bar=nil)
129 @scrollbar.orient 'horizontal'
130 self.scrollcommand {|*arg| @scrollbar.set(*arg)}
131 @scrollbar.command {|*arg| self.xview(*arg)}
132 Tk.update # avoid scrollbar trouble
136 def yscrollbar(bar=nil)
139 @scrollbar.orient 'vertical'
140 self.scrollcommand {|*arg| @scrollbar.set(*arg)}
141 @scrollbar.command {|*arg| self.yview(*arg)}
142 Tk.update # avoid scrollbar trouble
146 alias scrollbar yscrollbar
150 idx = num_or_str(tk_send_without_enc('view'))
151 if idx.kind_of?(Fixnum) && idx < 0
157 tk_send_without_enc('view', *idxs)
164 def view_moveto(*idxs)
165 view('moveto', *idxs)
167 alias xview_moveto view_moveto
168 alias yview_moveto view_moveto
169 def view_scroll(index, what='pages')
170 view('scroll', index, what)
172 alias xview_scroll view_scroll
173 alias yview_scroll view_scroll