1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/tk/lib/tkentry.rb
nagai d8b02b5096 tk.rb :
* small bug fix
 * rename 'no_create' option to 'without_creating'
 * add TkWindow#pack_in,  TkWindow#grid_in,  TkWindow#place_in
 * add TkWindow#bind_class and TkWindow#database_class
   If defined specific_class (@db_class), bind_class returns @db_class.
   In other case, bind_class returns TkWinow#class().
   It is useful for binding.
   TkWindow#database_class is defined for querying the option database.
   It's same to TkWinfo.classname(self).
 * add TkBindTag.new_by_name and TkDatabaseClass for binding to database class
 * check varname whether already exsist or not. (TkVarAccess.new)
 * TkTextWin#bbox returns an array of four numbers
 * autoload TkDialog2, TkWarning2
 * scan event callback arguments and convert to proper type
 * TkBindTag.new accepts a block ( TkBindTag.new(context){callback} )
 * If given taglist, TkWindow#bindtags(taglist) returns taglist
 * add TkWindow#bindtags=(taglist)
 * Tk.focue and Tk.focus_lastfor return nil if there is no target widget.
 * Tk::Wm.client returns the argument string when setting name
 * TkGrid.columnconfiginfo and rowconfiginfo given a slot return a number.
 * TkWindow.grid_columnconfiginfo and grid_rowconfiginfo :: ditto
 * rename and define alias :: TkOption ==> TkOptionDB
 * define alias :: TkTimer ==> TkAfter
 * some instance methods change from public to private
 * some TkComm methods change to module functions
   (help to treat return values from Tk)
 * add support for -displayof option to some TkWinfo methods
 * bind, bind_append and bind_remove :: returns the target of event-binding
 * add Tk8.4 features
 * add TkPaneWindow

tkdialog.rb:
 * classes without showing at initialize : TkDialog2, TkWarning2
 * add show method to reuse TkDialog object
 * some instance methods change from public to private
 * add new features for configuration

tktext.rb :
 * small bug fix
 * some methods return self
 * add TkTextMark#+(mod) and TkTextMark#-(mod) (e.g. mark + '3 chars')
 * add some methods

tkcanvas.rb :
 * small bug fix
 * some methods return self

tkentry.rb :
 * some methods return self
 * TkEntry#bbox returns an array of four numbers
 * scan validatecommand arguments and convert to proper type

tkbgerror.rb :
 * support to define a error handler by user

tcltklib.rb :
 * reported by Ferenc Engard <engard@all.hu> on [ruby-talk:60759]

                                     ... and so on


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-06-18 19:46:20 +00:00

252 lines
5.3 KiB
Ruby

#
# tkentry.rb - Tk entry classes
# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
require 'tk.rb'
class TkEntry<TkLabel
include Scrollable
WidgetClassName = 'Entry'.freeze
WidgetClassNames[WidgetClassName] = self
class ValidateCmd
include TkComm
class ValidateArgs
VARG_KEY = 'disvPSVW'
VARG_TYPE = 'nnsssssw'
def self.scan_args(arg_str, arg_val)
arg_cnv = []
arg_str.strip.split(/\s+/).each_with_index{|kwd,idx|
if kwd =~ /^%(.)$/
if num = VARG_KEY.index($1)
case VARG_TYPE[num]
when ?n
arg_cnv << TkComm::number(arg_val[idx])
when ?s
arg_cnv << TkComm::string(arg_val[idx])
when ?w
arg_cnv << TkComm::window(arg_val[idx])
else
arg_cnv << arg_val[idx]
end
else
arg_cnv << arg_val[idx]
end
else
arg_cnv << arg_val[idx]
end
}
arg_cnv
end
def initialize(d,i,s,v,pp,ss,vv,ww)
@action = d
@index = i
@current = s
@type = v
@value = pp
@string = ss
@triggered = vv
@widget = ww
end
attr :action
attr :index
attr :current
attr :type
attr :value
attr :string
attr :triggered
attr :widget
end
def initialize(cmd = Proc.new, args=nil)
if args
@id =
install_cmd(proc{|*arg|
TkUtil.eval_cmd(cmd, ValidateArgs.scan_args(args, arg))
}) + " " + args
else
args = ' %d %i %s %v %P %S %V %W'
@id =
install_cmd(proc{|*arg|
TkUtil.eval_cmd(
cmd,
ValidateArgs.new(ValidateArgs.scan_args(args, arg))
)
}) + args
end
end
def to_eval
@id
end
end
def create_self(keys)
if keys and keys != None
tk_call 'entry', @path, *hash_kv(keys)
else
tk_call 'entry', @path
end
end
def configure(slot, value=None)
if slot.kind_of? Hash
slot = _symbolkey2str(slot)
if slot['vcmd'].kind_of? Array
cmd, *args = slot['vcmd']
slot['vcmd'] = ValidateCmd.new(cmd, args.join(' '))
elsif slot['vcmd'].kind_of? Proc
slot['vcmd'] = ValidateCmd.new(slot['vcmd'])
end
if slot['validatecommand'].kind_of? Array
cmd, *args = slot['validatecommand']
slot['validatecommand'] = ValidateCmd.new(cmd, args.join(' '))
elsif slot['validatecommand'].kind_of? Proc
slot['validatecommand'] = ValidateCmd.new(slot['validatecommand'])
end
if slot['invcmd'].kind_of? Array
cmd, *args = slot['invcmd']
slot['invcmd'] = ValidateCmd.new(cmd, args.join(' '))
elsif slot['invcmd'].kind_of? Proc
slot['invcmd'] = ValidateCmd.new(slot['invcmd'])
end
if slot['invalidcommand'].kind_of? Array
cmd, *args = slot['invalidcommand']
slot['invalidcommand'] = ValidateCmd.new(cmd, args.join(' '))
elsif slot['invalidcommand'].kind_of? Proc
slot['invalidcommand'] = ValidateCmd.new(slot['invalidcommand'])
end
super(slot)
else
if (slot == 'vcmd' || slot == :vcmd ||
slot == 'validatecommand' || slot == :validatecommand ||
slot == 'invcmd' || slot == :invcmd ||
slot == 'invalidcommand' || slot == :invalidcommand)
if value.kind_of? Array
cmd, *args = value
value = ValidateCmd.new(cmd, args.join(' '))
elsif value.kind_of? Proc
value = ValidateCmd.new(value)
end
end
super(slot, value)
end
self
end
def cursor
number(tk_send('index', 'insert'))
end
def cursor=(index)
tk_send 'icursor', index
self
end
def index(index)
number(tk_send('index', index))
end
def insert(pos,text)
tk_send 'insert', pos, text
self
end
def mark(pos)
tk_send 'scan', 'mark', pos
self
end
def dragto(pos)
tk_send 'scan', 'dragto', pos
self
end
def selection_adjust(index)
tk_send 'selection', 'adjust', index
self
end
def selection_clear
tk_send 'selection', 'clear'
self
end
def selection_from(index)
tk_send 'selection', 'from', index
self
end
def selection_present()
bool(tk_send('selection', 'present'))
end
def selection_range(s, e)
tk_send 'selection', 'range', s, e
self
end
def selection_to(index)
tk_send 'selection', 'to', index
self
end
def validate(mode = nil)
if mode
configure 'validate', mode
else
bool(tk_send('validate'))
end
end
def validatecommand(cmd = ValidateCmd.new, args = nil)
if cmd.kind_of?(ValidateCmd)
configure('validatecommand', cmd)
else
configure('validatecommand', ValidateCmd.new(cmd, args))
end
end
alias vcmd validatecommand
def invalidcommand(cmd = ValidateCmd.new, args = nil)
if cmd.kind_of?(ValidateCmd)
configure('invalidcommand', cmd)
else
configure('invalidcommand', ValidateCmd.new(cmd, args))
end
end
alias invcmd invalidcommand
def value
tk_send 'get'
end
def value= (val)
tk_send 'delete', 0, 'end'
tk_send 'insert', 0, val
end
end
class TkSpinbox<TkEntry
WidgetClassName = 'Spinbox'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
if keys and keys != None
tk_call 'spinbox', @path, *hash_kv(keys)
else
tk_call 'spinbox', @path
end
end
def identify(x, y)
tk_send 'identify', x, y
end
def spinup
tk_send 'invoke', 'spinup'
self
end
def spindown
tk_send 'invoke', 'spindown'
self
end
def set(str)
tk_send 'set', str
end
end