summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk/text.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-12 15:25:49 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-12 15:25:49 +0000
commit7050e0c745982d4c8c5d7088df21b63fbfc172bc (patch)
tree7ff4193ecbd0de9f6d52bb230b3b5c826103ccff /ext/tk/lib/tk/text.rb
parent7d4fe15675ba17e775082965ebbea648b4753b58 (diff)
* ext/tcltklib/extconf.rb: [EXPERIMENTAL] MacOS X (darwin) support
* ext/tcltklib/tcltklib.c: fix thread trouble on callback proc, and eliminate warning about instance variable access * ext/tk/lib/tk/menubar.rb: improve supported menu_spec * ext/tk/lib/tk/menuspec.rb: [add] menu_spec support library * ext/tk/lib/tk/root.rb: add menu_spec support * ext/tk/lib/tk/text.rb: bug fix * ext/tk/lib/tk/toplevel.rb: add menu_spec support * ext/tk/sample/menubar?.rb: [add] sample of menu_spec usage git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk/text.rb')
-rw-r--r--ext/tk/lib/tk/text.rb80
1 files changed, 49 insertions, 31 deletions
diff --git a/ext/tk/lib/tk/text.rb b/ext/tk/lib/tk/text.rb
index b1e671e1e0..be3f814505 100644
--- a/ext/tk/lib/tk/text.rb
+++ b/ext/tk/lib/tk/text.rb
@@ -67,6 +67,11 @@ class TkText<TkTextWin
tk_send_without_enc('index', _get_eval_enc_str(index))
end
+ def get_displaychars(*index)
+ # Tk8.5 feature
+ get('-displaychars', *index)
+ end
+
def value
_fromUTF8(tk_send_without_enc('get', "1.0", "end - 1 char"))
end
@@ -326,9 +331,35 @@ class TkText<TkTextWin
end
def count(idx1, idx2, *opts)
- opts = opts.collect{|opt| '-' + opt.to_s}
- number(tk_send_without_enc('count', _get_eval_enc_str(idx1),
- _get_eval_enc_str(idx2), *opts))
+ # opts are Tk8.5 feature
+ cnt = 0
+ args = opts.collect{|opt|
+ str = opt.to_s
+ cnt += 1 if str != 'update'
+ '-' + str
+ }
+ args << _get_eval_enc_str(idx1) << _get_eval_enc_str(idx2)
+ if cnt <= 1
+ number(tk_send_without_enc('count', *opts))
+ else
+ list(tk_send_without_enc('count', *opts))
+ end
+ end
+
+ def count_info(idx1, idx2, update=true)
+ # Tk8.5 feature
+ opts = [
+ :chars, :displaychars, :displayindices, :displaylines,
+ :indices, :lines, :xpixels, :ypixels
+ ]
+ if update
+ lst = count(idx1, idx2, :update, *opts)
+ else
+ lst = count(idx1, idx2, *opts)
+ end
+ info = {}
+ opts.each_with_index{|key, idx| info[key] = lst[idx]}
+ info
end
def replace(idx1, idx2, *opts)
@@ -879,53 +910,40 @@ class TkText<TkTextWin
def tksearch(*args)
# call 'search' subcommand of text widget
# args ::= [<array_of_opts>] <pattern> <start_index> [<stop_index>]
- # <pattern> must be a regular expression of Tcl
- all_mode = false
- opts = args.shift
- if opts.kind_of?(Array)
- opts = opts.collect{|opt|
- opt = opt.to_s
- all_mode = true if opt == 'all'
- opt
- }
+ # If <pattern> is regexp, then it must be a regular expression of Tcl
+ if args[0].kind_of?(Array)
+ opts = args.shift.collect{|opt| '-' + opt.to_s }
else
- args.unshift(opts)
opts = []
end
opts << '--'
- if all_mode
- tk_split_simplelist(tk_send(*(opts + args)))
+ ret = tk_send('search', *(opts + args))
+ if ret == ""
+ nil
else
- tk_send(*(opts + args))
+ ret
end
end
def tksearch_with_count(*args)
# call 'search' subcommand of text widget
# args ::= [<array_of_opts>] <var> <pattern> <start_index> [<stop_index>]
- # <pattern> must be a regular expression of Tcl
- all_mode = false
- opts = args.shift
- if opts.kind_of?(Array)
- opts = opts.collect{|opt|
- opt = opt.to_s
- all_mode = true if opt == 'all'
- opt
- }
- var = args.shift
+ # If <pattern> is regexp, then it must be a regular expression of Tcl
+ if args[0].kind_of?(Array)
+ opts = args.shift.collect{|opt| '-' + opt.to_s }
else
- var = opts
opts = []
end
- opts << '-count' << var << '--'
+ opts << '-count' << args.shift << '--'
- if all_mode
- tk_split_simplelist(tk_send(*(opts + args)))
+ ret = tk_send('search', *(opts + args))
+ if ret == ""
+ nil
else
- tk_send(*(opts + args))
+ ret
end
end