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