1# 2# tkextlib/bwidget/dialog.rb 3# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) 4# 5 6require 'tk' 7require 'tk/frame' 8require 'tkextlib/bwidget.rb' 9require 'tkextlib/bwidget/buttonbox' 10 11module Tk 12 module BWidget 13 class Dialog < TkWindow 14 end 15 end 16end 17 18class Tk::BWidget::Dialog 19 TkCommandNames = ['Dialog'.freeze].freeze 20 WidgetClassName = 'Dialog'.freeze 21 WidgetClassNames[WidgetClassName] ||= self 22 23 include TkItemConfigMethod 24 25 def __numstrval_optkeys 26 super() << 'buttonwidth' 27 end 28 private :__numstrval_optkeys 29 30 def __strval_optkeys 31 super() << 'title' << 'geometry' 32 end 33 private :__strval_optkeys 34 35 def __boolval_optkeys 36 super() << 'transient' << 'homogeneous' 37 end 38 private :__boolval_optkeys 39 40 def initialize(parent=nil, keys=nil) 41 @relative = '' 42 if parent.kind_of?(Hash) 43 keys = _symbolkey2str(parent) 44 @relative = keys['parent'] if keys.key?('parent') 45 @relative = keys.delete('relative') if keys.key?('relative') 46 super(keys) 47 elsif keys 48 keys = _symbolkey2str(keys) 49 @relative = keys.delete('parent') if keys.key?('parent') 50 @relative = keys.delete('relative') if keys.key?('relative') 51 super(parent, keys) 52 else 53 super(parent) 54 end 55 end 56 57 def create_self(keys) 58 cmd = self.class::TkCommandNames[0] 59 if keys and keys != None 60 tk_call_without_enc(cmd, @path, '-parent', @relative, 61 *hash_kv(keys, true)) 62 else 63 tk_call_without_enc(cmd, @path, '-parent', @relative) 64 end 65 end 66 67 def cget_tkstring(slot) 68 if slot.to_s == 'relative' 69 super('parent') 70 else 71 super(slot) 72 end 73 end 74 def cget_strict(slot) 75 if slot.to_s == 'relative' 76 super('parent') 77 else 78 super(slot) 79 end 80 end 81 def cget(slot) 82 if slot.to_s == 'relative' 83 super('parent') 84 else 85 super(slot) 86 end 87 end 88 89 def configure(slot, value=None) 90 if slot.kind_of?(Hash) 91 slot = _symbolkey2str(slot) 92 slot['parent'] = slot.delete('relative') if slot.key?('relative') 93 super(slot) 94 else 95 if slot.to_s == 'relative' 96 super('parent', value) 97 else 98 super(slot, value) 99 end 100 end 101 end 102 103 def configinfo(slot=nil) 104 if slot 105 if slot.to_s == 'relative' 106 super('parent') 107 else 108 super(slot) 109 end 110 else 111 ret = super() 112 if TkComm::GET_CONFIGINFO_AS_ARRAY 113 ret << ['relative', 'parent'] 114 else 115 ret['relative'] = 'parent' 116 end 117 end 118 end 119 120 def tagid(tagOrId) 121 if tagOrId.kind_of?(Tk::BWidget::Button) 122 name = tagOrId[:name] 123 return index(name) unless name.empty? 124 end 125 if tagOrId.kind_of?(Tk::Button) 126 return index(tagOrId[:text]) 127 end 128 # index(tagOrId.to_s) 129 index(_get_eval_string(tagOrId)) 130 end 131 132 def add(keys={}, &b) 133 win = window(tk_send('add', *hash_kv(keys))) 134 if b 135 if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! 136 win.instance_exec(self, &b) 137 else 138 win.instance_eval(&b) 139 end 140 end 141 win 142 end 143 144 def get_frame(&b) 145 win = window(tk_send('getframe')) 146 if b 147 if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! 148 win.instance_exec(self, &b) 149 else 150 win.instance_eval(&b) 151 end 152 end 153 win 154 end 155 156 def get_buttonbox(&b) 157 win = window(@path + '.bbox') 158 if b 159 if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! 160 win.instance_exec(self, &b) 161 else 162 win.instance_eval(&b) 163 end 164 end 165 win 166 end 167 168 def draw(focus_win=None) 169 tk_send('draw', focus_win) 170 end 171 172 def enddialog(ret) 173 tk_send('enddialog', ret) 174 end 175 176 def index(idx) 177 get_buttonbox.index(idx) 178 end 179 180 def invoke(idx) 181 tk_send('invoke', tagid(idx)) 182 self 183 end 184 185 def set_focus(idx) 186 tk_send('setfocus', tagid(idx)) 187 self 188 end 189 190 def withdraw 191 tk_send('withdraw') 192 self 193 end 194end 195