1# 2# tk/entry.rb - Tk entry classes 3# by Yukihiro Matsumoto <matz@caelum.co.jp> 4 5require 'tk' 6require 'tk/label' 7require 'tk/scrollable' 8require 'tk/validation' 9 10class Tk::Entry<Tk::Label 11 include X_Scrollable 12 include TkValidation 13 14 TkCommandNames = ['entry'.freeze].freeze 15 WidgetClassName = 'Entry'.freeze 16 WidgetClassNames[WidgetClassName] ||= self 17 18 #def create_self(keys) 19 # super(__conv_vcmd_on_hash_kv(keys)) 20 #end 21 #private :create_self 22 23 def __strval_optkeys 24 super() + ['show', 'disabledbackground', 'readonlybackground'] 25 end 26 private :__strval_optkeys 27 28 def bbox(index) 29 list(tk_send_without_enc('bbox', index)) 30 end 31 def cursor 32 number(tk_send_without_enc('index', 'insert')) 33 end 34 alias icursor cursor 35 def cursor=(index) 36 tk_send_without_enc('icursor', index) 37 #self 38 index 39 end 40 alias icursor= cursor= 41 def index(idx) 42 number(tk_send_without_enc('index', idx)) 43 end 44 def insert(pos,text) 45 tk_send_without_enc('insert', pos, _get_eval_enc_str(text)) 46 self 47 end 48 def delete(first, last=None) 49 tk_send_without_enc('delete', first, last) 50 self 51 end 52 def mark(pos) 53 tk_send_without_enc('scan', 'mark', pos) 54 self 55 end 56 def dragto(pos) 57 tk_send_without_enc('scan', 'dragto', pos) 58 self 59 end 60 def selection_adjust(index) 61 tk_send_without_enc('selection', 'adjust', index) 62 self 63 end 64 def selection_clear 65 tk_send_without_enc('selection', 'clear') 66 self 67 end 68 def selection_from(index) 69 tk_send_without_enc('selection', 'from', index) 70 self 71 end 72 def selection_present() 73 bool(tk_send_without_enc('selection', 'present')) 74 end 75 def selection_range(s, e) 76 tk_send_without_enc('selection', 'range', s, e) 77 self 78 end 79 def selection_to(index) 80 tk_send_without_enc('selection', 'to', index) 81 self 82 end 83 84 def invoke_validate 85 bool(tk_send_without_enc('validate')) 86 end 87 def validate(mode = nil) 88 if mode 89 configure 'validate', mode 90 else 91 invoke_validate 92 end 93 end 94 95 def value 96 _fromUTF8(tk_send_without_enc('get')) 97 end 98 def value= (val) 99 tk_send_without_enc('delete', 0, 'end') 100 tk_send_without_enc('insert', 0, _get_eval_enc_str(val)) 101 val 102 end 103 alias get value 104 alias set value= 105 106 def [](*args) 107 self.value[*args] 108 end 109 def []=(*args) 110 val = args.pop 111 str = self.value 112 str[*args] = val 113 self.value = str 114 val 115 end 116end 117 118#TkEntry = Tk::Entry unless Object.const_defined? :TkEntry 119#Tk.__set_toplevel_aliases__(:Tk, Tk::Entry, :TkEntry) 120Tk.__set_loaded_toplevel_aliases__('tk/entry.rb', :Tk, Tk::Entry, :TkEntry) 121