1#
2#  tkextlib/bwidget/mainframe.rb
3#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
4#
5
6require 'tk'
7require 'tk/frame'
8require 'tkextlib/bwidget.rb'
9require 'tkextlib/bwidget/progressbar'
10
11module Tk
12  module BWidget
13    class MainFrame < TkWindow
14    end
15  end
16end
17
18class Tk::BWidget::MainFrame
19  TkCommandNames = ['MainFrame'.freeze].freeze
20  WidgetClassName = 'MainFrame'.freeze
21  WidgetClassNames[WidgetClassName] ||= self
22
23  def __strval_optkeys
24    super() << 'progressfg'
25  end
26  private :__strval_optkeys
27
28  def __tkvariable_optkeys
29    super() << 'progressvar'
30  end
31  private :__tkvariable_optkeys
32
33  def __val2ruby_optkeys  # { key=>proc, ... }
34    # The method is used to convert a opt-value to a ruby's object.
35    # When get the value of the option "key", "proc.call(value)" is called.
36    {
37      'menu'=>proc{|v| simplelist(v).collect!{|elem| simplelist(v)}}
38    }
39  end
40  private :__val2ruby_optkeys
41
42  def add_indicator(keys={}, &b)
43    win = window(tk_send('addindicator', *hash_kv(keys)))
44    if b
45      if TkCore::WITH_RUBY_VM  ### Ruby 1.9 !!!!
46        win.instance_exec(self, &b)
47      else
48        win.instance_eval(&b)
49      end
50    end
51    win
52  end
53
54  def add_toolbar(&b)
55    win = window(tk_send('addtoolbar'))
56    if b
57      if TkCore::WITH_RUBY_VM  ### Ruby 1.9 !!!!
58        win.instance_exec(self, &b)
59      else
60        win.instance_eval(&b)
61      end
62    end
63    win
64  end
65
66  def get_frame(&b)
67    win = window(tk_send('getframe'))
68    if b
69      if TkCore::WITH_RUBY_VM  ### Ruby 1.9 !!!!
70        win.instance_exec(self, &b)
71      else
72        win.instance_eval(&b)
73      end
74    end
75    win
76  end
77
78  def get_indicator(idx, &b)
79    win = window(tk_send('getindicator', idx))
80    if b
81      if TkCore::WITH_RUBY_VM  ### Ruby 1.9 !!!!
82        win.instance_exec(self, &b)
83      else
84        win.instance_eval(&b)
85      end
86    end
87    win
88  end
89
90  def get_menu(menu_id, &b)
91    win = window(tk_send('getmenu', menu_id))
92    if b
93      if TkCore::WITH_RUBY_VM  ### Ruby 1.9 !!!!
94        win.instance_exec(self, &b)
95      else
96        win.instance_eval(&b)
97      end
98    end
99    win
100  end
101
102  def get_toolbar(idx, &b)
103    win = window(tk_send('gettoolbar', idx))
104    if b
105      if TkCore::WITH_RUBY_VM  ### Ruby 1.9 !!!!
106        win.instance_exec(self, &b)
107      else
108        win.instance_eval(&b)
109      end
110    end
111    win
112  end
113
114  def get_menustate(tag)
115    tk_send('getmenustate', tag) # return state name string
116  end
117
118  def set_menustate(tag, state)
119    tk_send('setmenustate', tag, state)
120    self
121  end
122
123  def show_statusbar(name)
124    tk_send('showstatusbar', name)
125    self
126  end
127
128  def show_toolbar(idx, mode)
129    tk_send('showtoolbar', idx, mode)
130    self
131  end
132end
133