summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-17 07:31:51 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-17 07:31:51 +0000
commitab65368c288992e00568aabb550284db64b11d31 (patch)
treea689baeebc8d0de7bc5952c74ac6f9773bdae6a2 /ext/tk/lib/tk
parent93291de5aa9378d089d01555507e4dd828f70dcb (diff)
* ext/tk/lib/tk.rb: fix bug on setting up system encoding
* ext/tk/lib/tk/event.rb: fix error on require process * ext/tk/lib/font.rb: fix abnormal termination error on Windows * ext/tk/lib/tk/virtevent.rb: TkVirtualEvent::PreDefVirtEvent.new() accepts event-sequence arguments * ext/tk/lib/text.rb: fail to dump embedded images * ext/tk/lib/text.rb: tag_nextrange and tag_prevrange returns wrong types of values * ext/tk/lib/texttag.rb: nextrange and prevrange returns wrong types of values * ext/tk/lib/text.rb: add TkText::IndexModMethods module and TkText::IndexString class to treat text index modifiers * ext/tk/lib/texttag.rb: use TkText::IndexModMethods module * ext/tk/lib/textmark.rb: ditto * ext/tk/lib/textimage.rb: ditto * ext/tk/lib/textwindow.rb: ditto * ext/tk/lib/textimage.rb: wrong gravity of text mark for embedded image * ext/tk/lib/textwindow.rb: wrong gravity of text mark for embedded window git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk')
-rw-r--r--ext/tk/lib/tk/event.rb2
-rw-r--r--ext/tk/lib/tk/font.rb6
-rw-r--r--ext/tk/lib/tk/text.rb98
-rw-r--r--ext/tk/lib/tk/textimage.rb16
-rw-r--r--ext/tk/lib/tk/textmark.rb10
-rw-r--r--ext/tk/lib/tk/texttag.rb27
-rw-r--r--ext/tk/lib/tk/textwindow.rb14
-rw-r--r--ext/tk/lib/tk/virtevent.rb3
8 files changed, 138 insertions, 38 deletions
diff --git a/ext/tk/lib/tk/event.rb b/ext/tk/lib/tk/event.rb
index 5af0fcd44d..dd01ba6309 100644
--- a/ext/tk/lib/tk/event.rb
+++ b/ext/tk/lib/tk/event.rb
@@ -8,7 +8,7 @@ end
########################
require 'tkutil'
-require 'tk'
+# require 'tk'
########################
diff --git a/ext/tk/lib/tk/font.rb b/ext/tk/lib/tk/font.rb
index 1e314e5bb9..790537ef8d 100644
--- a/ext/tk/lib/tk/font.rb
+++ b/ext/tk/lib/tk/font.rb
@@ -53,7 +53,8 @@ class TkFont
'-compound'))
else
# unknown Tcl/Tk-JP
- platform = tk_call('set', 'tcl_platform(platform)')
+ #platform = tk_call('set', 'tcl_platform(platform)')
+ platform = Tk::PLATFORM['platform']
case platform
when 'unix'
ltn = {'family'=>'Helvetica'.freeze,
@@ -79,7 +80,8 @@ class TkFont
else # not JAPANIZED_TK
begin
- platform = tk_call('set', 'tcl_platform(platform)')
+ #platform = tk_call('set', 'tcl_platform(platform)')
+ platform = Tk::PLATFORM['platform']
case platform
when 'unix'
ltn = {'family'=>'Helvetica'.freeze,
diff --git a/ext/tk/lib/tk/text.rb b/ext/tk/lib/tk/text.rb
index a79f50616a..f99337b3e9 100644
--- a/ext/tk/lib/tk/text.rb
+++ b/ext/tk/lib/tk/text.rb
@@ -66,6 +66,64 @@ class TkText<TkTextWin
include TkTextTagConfig
include Scrollable
+ #######################################
+
+ module IndexModMethods
+ def chars(mod)
+ fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
+ if mod < 0
+ TkText::IndexString.new(id + ' ' << mod.to_s << ' chars')
+ else
+ TkText::IndexString.new(id + ' + ' << mod.to_s << ' chars')
+ end
+ end
+ alias char chars
+
+ def lines(mod)
+ fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
+ if mod < 0
+ TkText::IndexString.new(id + ' ' << mod.to_s << ' lines')
+ else
+ TkText::IndexString.new(id + ' + ' << mod.to_s << ' lines')
+ end
+ end
+ alias line lines
+
+ def linestart
+ TkText::IndexString.new(id + ' linestart')
+ end
+ def lineend
+ TkText::IndexString.new(id + ' lineend')
+ end
+
+ def wordstart
+ TkText::IndexString.new(id + ' wordstart')
+ end
+ def wordend
+ TkText::IndexString.new(id + ' wordend')
+ end
+ end
+
+ class IndexString < String
+ include IndexModMethods
+
+ def self.new(str)
+ if str.kind_of?(String)
+ super(str)
+ elsif str.kind_of?(Symbol)
+ super(str.to_s)
+ else
+ str
+ end
+ end
+
+ def id
+ self
+ end
+ end
+
+ #######################################
+
TkCommandNames = ['text'.freeze].freeze
WidgetClassName = 'Text'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -102,7 +160,8 @@ class TkText<TkTextWin
private :create_self
def index(index)
- tk_send_without_enc('index', _get_eval_enc_str(index))
+ TkText::IndexString.new(tk_send_without_enc('index',
+ _get_eval_enc_str(index)))
end
def get_displaychars(*index)
@@ -757,23 +816,27 @@ class TkText<TkTextWin
_get_eval_enc_str(tag)))
r = []
while key=l.shift
- r.push [key, l.shift]
+ r.push [TkText::IndexString.new(key), TkText::IndexString.new(l.shift)]
end
r
end
def tag_nextrange(tag, first, last=None)
- tk_split_list(tk_send_without_enc('tag', 'nextrange',
- _get_eval_enc_str(tag),
- _get_eval_enc_str(first),
- _get_eval_enc_str(last)))
+ simplelist(tk_send_without_enc('tag', 'nextrange',
+ _get_eval_enc_str(tag),
+ _get_eval_enc_str(first),
+ _get_eval_enc_str(last))).collect{|idx|
+ TkText::IndexString.new(idx)
+ }
end
def tag_prevrange(tag, first, last=None)
- tk_split_list(tk_send_without_enc('tag', 'prevrange',
- _get_eval_enc_str(tag),
- _get_eval_enc_str(first),
- _get_eval_enc_str(last)))
+ simplelist(tk_send_without_enc('tag', 'prevrange',
+ _get_eval_enc_str(tag),
+ _get_eval_enc_str(first),
+ _get_eval_enc_str(last))).collect{|idx|
+ TkText::IndexString.new(idx)
+ }
end
=begin
@@ -1016,7 +1079,7 @@ class TkText<TkTextWin
if ret == ""
nil
else
- ret
+ TkText::IndexString.new(ret)
end
end
@@ -1051,7 +1114,7 @@ class TkText<TkTextWin
if ret == ""
nil
else
- ret
+ TkText::IndexString.new(ret)
end
end
@@ -1173,6 +1236,11 @@ class TkText<TkTextWin
end
def dump(type_info, *index, &block)
+ if type_info.kind_of?(Symbol)
+ type_info = [ type_info.to_s ]
+ elsif type_info.kind_of?(String)
+ type_info = [ type_info ]
+ end
args = type_info.collect{|inf| '-' + inf}
args << '-command' << block if block
str = tk_send('dump', *(args + index))
@@ -1226,6 +1294,8 @@ class TkText<TkTextWin
result.push tk_tcl2ruby(val)
when 'window'
result.push tk_tcl2ruby(val)
+ when 'image'
+ result.push tk_tcl2ruby(val)
end
i = idx + 1
end
@@ -1233,10 +1303,10 @@ class TkText<TkTextWin
# retrieve index
idx = str.index(/ /, i)
if idx
- result.push str[i..(idx-1)]
+ result.push(TkText::IndexString.new(str[i..(idx-1)]))
i = idx + 1
else
- result.push str[i..-1]
+ result.push(TkText::IndexString.new(str[i..-1]))
break
end
end
diff --git a/ext/tk/lib/tk/textimage.rb b/ext/tk/lib/tk/textimage.rb
index bd92387e3c..982cb2ecf9 100644
--- a/ext/tk/lib/tk/textimage.rb
+++ b/ext/tk/lib/tk/textimage.rb
@@ -5,12 +5,14 @@ require 'tk'
require 'tk/text'
class TkTextImage<TkObject
+ include TkText::IndexModMethods
+
def initialize(parent, index, keys)
#unless parent.kind_of?(TkText)
# fail ArguemntError, "expect TkText for 1st argument"
#end
@t = parent
- if index == 'end'
+ if index == 'end' || index == :end
@path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars'))
elsif index.kind_of? TkTextMark
if tk_call_without_enc(@t.path,'index',index.path) == tk_call_without_enc(@t.path,'index','end')
@@ -27,7 +29,15 @@ class TkTextImage<TkObject
@path.gravity = 'left'
@index = @path.path
@id = tk_call_without_enc(@t.path, 'image', 'create', @index,
- *hash_kv(keys, true))
+ *hash_kv(keys, true)).freeze
+ @path.gravity = 'right'
+ end
+
+ def id
+ TkText::IndexString.new(@id)
+ end
+ def mark
+ @path
end
def [](slot)
@@ -59,7 +69,7 @@ class TkTextImage<TkObject
end
def image
- img = tk_call_without_enc(@t.path, 'image', 'configure', @index, '-image')
+ img = tk_call_without_enc(@t.path, 'image', 'cget', @index, '-image')
TkImage::Tk_IMGTBL[img]? TkImage::Tk_IMGTBL[img] : img
end
diff --git a/ext/tk/lib/tk/textmark.rb b/ext/tk/lib/tk/textmark.rb
index fbe57a4cc3..9dff764eca 100644
--- a/ext/tk/lib/tk/textmark.rb
+++ b/ext/tk/lib/tk/textmark.rb
@@ -5,6 +5,8 @@ require 'tk'
require 'tk/text'
class TkTextMark<TkObject
+ include TkText::IndexModMethods
+
TMarkID_TBL = TkCore::INTERP.create_table
Tk_TextMark_ID = ['mark'.freeze, '00000'.taint].freeze
@@ -23,7 +25,7 @@ class TkTextMark<TkObject
@parent = @t = parent
@tpath = parent.path
# @path = @id = Tk_TextMark_ID.join('')
- @path = @id = Tk_TextMark_ID.join(TkCore::INTERP._ip_id_)
+ @path = @id = Tk_TextMark_ID.join(TkCore::INTERP._ip_id_).freeze
TMarkID_TBL[@id] = self
TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
TMarkID_TBL[@tpath][@id] = self
@@ -34,7 +36,7 @@ class TkTextMark<TkObject
end
def id
- @id
+ TkText::IndexString.new(@id)
end
def exist?
@@ -46,10 +48,10 @@ class TkTextMark<TkObject
end
def +(mod)
- @id + ' + ' + mod
+ TkText::IndexString.new(@id + ' + ' + mod)
end
def -(mod)
- @id + ' - ' + mod
+ TkText::IndexString.new(@id + ' - ' + mod)
end
def set(where)
diff --git a/ext/tk/lib/tk/texttag.rb b/ext/tk/lib/tk/texttag.rb
index a80f4780c0..1e3a2d7e41 100644
--- a/ext/tk/lib/tk/texttag.rb
+++ b/ext/tk/lib/tk/texttag.rb
@@ -7,6 +7,7 @@ require 'tk/tagfont'
class TkTextTag<TkObject
include TkTreatTagFont
+ include TkText::IndexModMethods
TTagID_TBL = TkCore::INTERP.create_table
Tk_TextTag_ID = ['tag'.freeze, '00000'.taint].freeze
@@ -26,7 +27,7 @@ class TkTextTag<TkObject
@parent = @t = parent
@tpath = parent.path
# @path = @id = Tk_TextTag_ID.join('')
- @path = @id = Tk_TextTag_ID.join(TkCore::INTERP._ip_id_)
+ @path = @id = Tk_TextTag_ID.join(TkCore::INTERP._ip_id_).freeze
# TTagID_TBL[@id] = self
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
TTagID_TBL[@tpath][@id] = self
@@ -46,7 +47,7 @@ class TkTextTag<TkObject
end
def id
- @id
+ TkText::IndexString.new(@id)
end
def exist?
@@ -58,11 +59,11 @@ class TkTextTag<TkObject
end
def first
- @id + '.first'
+ TkText::IndexString.new(@id + '.first')
end
def last
- @id + '.last'
+ TkText::IndexString.new(@id + '.last')
end
def add(*indices)
@@ -81,21 +82,25 @@ class TkTextTag<TkObject
l = tk_split_simplelist(tk_call_without_enc(@t.path, 'tag', 'ranges', @id))
r = []
while key=l.shift
- r.push [key, l.shift]
+ r.push [TkText::IndexString.new(key), TkText::IndexString.new(l.shift)]
end
r
end
def nextrange(first, last=None)
- tk_split_list(tk_call_without_enc(@t.path, 'tag', 'nextrange', @id,
- _get_eval_enc_str(first),
- _get_eval_enc_str(last)))
+ simplelist(tk_call_without_enc(@t.path, 'tag', 'nextrange', @id,
+ _get_eval_enc_str(first),
+ _get_eval_enc_str(last))).collect{|idx|
+ TkText::IndexString.new(idx)
+ }
end
def prevrange(first, last=None)
- tk_split_list(tk_call_without_enc(@t.path, 'tag', 'prevrange', @id,
- _get_eval_enc_str(first),
- _get_eval_enc_str(last)))
+ simplelist(tk_call_without_enc(@t.path, 'tag', 'prevrange', @id,
+ _get_eval_enc_str(first),
+ _get_eval_enc_str(last))).collect{|idx|
+ TkText::IndexString.new(idx)
+ }
end
def [](key)
diff --git a/ext/tk/lib/tk/textwindow.rb b/ext/tk/lib/tk/textwindow.rb
index c53cbe1a70..7c97313582 100644
--- a/ext/tk/lib/tk/textwindow.rb
+++ b/ext/tk/lib/tk/textwindow.rb
@@ -5,12 +5,14 @@ require 'tk'
require 'tk/text'
class TkTextWindow<TkObject
- def initialize(parent, index, keys)
+ include TkText::IndexModMethods
+
+ def initialize(parent, index, keys = {})
#unless parent.kind_of?(TkText)
# fail ArguemntError, "expect TkText for 1st argument"
#end
@t = parent
- if index == 'end'
+ if index == 'end' || index == :end
@path = TkTextMark.new(@t, tk_call_without_enc(@t.path, 'index',
'end - 1 chars'))
elsif index.kind_of?(TkTextMark)
@@ -49,6 +51,14 @@ class TkTextWindow<TkObject
end
tk_call_without_enc(@t.path, 'window', 'create', @index,
*hash_kv(keys, true))
+ @path.gravity = 'right'
+ end
+
+ def id
+ TkText::IndexString.new(_epath(@id))
+ end
+ def mark
+ @path
end
def [](slot)
diff --git a/ext/tk/lib/tk/virtevent.rb b/ext/tk/lib/tk/virtevent.rb
index c82cfe46e8..a1a94d3c55 100644
--- a/ext/tk/lib/tk/virtevent.rb
+++ b/ext/tk/lib/tk/virtevent.rb
@@ -15,9 +15,10 @@ class TkVirtualEvent<TkObject
TkCore::INTERP.init_ip_env{ TkVirtualEventTBL.clear }
class PreDefVirtEvent<self
- def initialize(event)
+ def initialize(event, *sequences)
@path = @id = event
TkVirtualEvent::TkVirtualEventTBL[@id] = self
+ add(*sequences)
end
end