* 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/trunk@7588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2004-12-17 07:31:51 +00:00
parent 3da93dd842
commit cb2349d653
10 changed files with 188 additions and 39 deletions

View File

@ -1,3 +1,39 @@
Fri Dec 17 16:28:12 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* 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
Fri Dec 17 13:33:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Dec 17 13:33:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/cgi/session.rb (CGI::Session#initialize): control adding * lib/cgi/session.rb (CGI::Session#initialize): control adding

View File

@ -2056,15 +2056,28 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
case $KCODE case $KCODE
when /^e/i # EUC when /^e/i # EUC
Tk.encoding = 'euc-jp' Tk.encoding = 'euc-jp'
Tk.encoding_system = 'euc-jp'
when /^s/i # SJIS when /^s/i # SJIS
begin
if Tk.encoding_system == 'cp932'
Tk.encoding = 'cp932'
else
Tk.encoding = 'shiftjis' Tk.encoding = 'shiftjis'
Tk.encoding_system = 'shiftjis'
end
rescue StandardError, NameError
Tk.encoding = 'shiftjis'
Tk.encoding_system = 'shiftjis'
end
when /^u/i # UTF8 when /^u/i # UTF8
Tk.encoding = 'utf-8' Tk.encoding = 'utf-8'
Tk.encoding_system = 'utf-8'
else # NONE else # NONE
begin begin
Tk.encoding = Tk.encoding_system Tk.encoding = Tk.encoding_system
rescue StandardError, NameError rescue StandardError, NameError
Tk.encoding = 'utf-8' Tk.encoding = 'utf-8'
Tk.encoding_system = 'utf-8'
end end
end end

View File

@ -8,7 +8,7 @@ end
######################## ########################
require 'tkutil' require 'tkutil'
require 'tk' # require 'tk'
######################## ########################

View File

@ -53,7 +53,8 @@ class TkFont
'-compound')) '-compound'))
else else
# unknown Tcl/Tk-JP # unknown Tcl/Tk-JP
platform = tk_call('set', 'tcl_platform(platform)') #platform = tk_call('set', 'tcl_platform(platform)')
platform = Tk::PLATFORM['platform']
case platform case platform
when 'unix' when 'unix'
ltn = {'family'=>'Helvetica'.freeze, ltn = {'family'=>'Helvetica'.freeze,
@ -79,7 +80,8 @@ class TkFont
else # not JAPANIZED_TK else # not JAPANIZED_TK
begin begin
platform = tk_call('set', 'tcl_platform(platform)') #platform = tk_call('set', 'tcl_platform(platform)')
platform = Tk::PLATFORM['platform']
case platform case platform
when 'unix' when 'unix'
ltn = {'family'=>'Helvetica'.freeze, ltn = {'family'=>'Helvetica'.freeze,

View File

@ -66,6 +66,64 @@ class TkText<TkTextWin
include TkTextTagConfig include TkTextTagConfig
include Scrollable 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 TkCommandNames = ['text'.freeze].freeze
WidgetClassName = 'Text'.freeze WidgetClassName = 'Text'.freeze
WidgetClassNames[WidgetClassName] = self WidgetClassNames[WidgetClassName] = self
@ -102,7 +160,8 @@ class TkText<TkTextWin
private :create_self private :create_self
def index(index) 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 end
def get_displaychars(*index) def get_displaychars(*index)
@ -757,23 +816,27 @@ class TkText<TkTextWin
_get_eval_enc_str(tag))) _get_eval_enc_str(tag)))
r = [] r = []
while key=l.shift while key=l.shift
r.push [key, l.shift] r.push [TkText::IndexString.new(key), TkText::IndexString.new(l.shift)]
end end
r r
end end
def tag_nextrange(tag, first, last=None) def tag_nextrange(tag, first, last=None)
tk_split_list(tk_send_without_enc('tag', 'nextrange', simplelist(tk_send_without_enc('tag', 'nextrange',
_get_eval_enc_str(tag), _get_eval_enc_str(tag),
_get_eval_enc_str(first), _get_eval_enc_str(first),
_get_eval_enc_str(last))) _get_eval_enc_str(last))).collect{|idx|
TkText::IndexString.new(idx)
}
end end
def tag_prevrange(tag, first, last=None) def tag_prevrange(tag, first, last=None)
tk_split_list(tk_send_without_enc('tag', 'prevrange', simplelist(tk_send_without_enc('tag', 'prevrange',
_get_eval_enc_str(tag), _get_eval_enc_str(tag),
_get_eval_enc_str(first), _get_eval_enc_str(first),
_get_eval_enc_str(last))) _get_eval_enc_str(last))).collect{|idx|
TkText::IndexString.new(idx)
}
end end
=begin =begin
@ -1016,7 +1079,7 @@ class TkText<TkTextWin
if ret == "" if ret == ""
nil nil
else else
ret TkText::IndexString.new(ret)
end end
end end
@ -1051,7 +1114,7 @@ class TkText<TkTextWin
if ret == "" if ret == ""
nil nil
else else
ret TkText::IndexString.new(ret)
end end
end end
@ -1173,6 +1236,11 @@ class TkText<TkTextWin
end end
def dump(type_info, *index, &block) 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 = type_info.collect{|inf| '-' + inf}
args << '-command' << block if block args << '-command' << block if block
str = tk_send('dump', *(args + index)) str = tk_send('dump', *(args + index))
@ -1226,6 +1294,8 @@ class TkText<TkTextWin
result.push tk_tcl2ruby(val) result.push tk_tcl2ruby(val)
when 'window' when 'window'
result.push tk_tcl2ruby(val) result.push tk_tcl2ruby(val)
when 'image'
result.push tk_tcl2ruby(val)
end end
i = idx + 1 i = idx + 1
end end
@ -1233,10 +1303,10 @@ class TkText<TkTextWin
# retrieve index # retrieve index
idx = str.index(/ /, i) idx = str.index(/ /, i)
if idx if idx
result.push str[i..(idx-1)] result.push(TkText::IndexString.new(str[i..(idx-1)]))
i = idx + 1 i = idx + 1
else else
result.push str[i..-1] result.push(TkText::IndexString.new(str[i..-1]))
break break
end end
end end

View File

@ -5,12 +5,14 @@ require 'tk'
require 'tk/text' require 'tk/text'
class TkTextImage<TkObject class TkTextImage<TkObject
include TkText::IndexModMethods
def initialize(parent, index, keys) def initialize(parent, index, keys)
#unless parent.kind_of?(TkText) #unless parent.kind_of?(TkText)
# fail ArguemntError, "expect TkText for 1st argument" # fail ArguemntError, "expect TkText for 1st argument"
#end #end
@t = parent @t = parent
if index == 'end' if index == 'end' || index == :end
@path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars')) @path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars'))
elsif index.kind_of? TkTextMark elsif index.kind_of? TkTextMark
if tk_call_without_enc(@t.path,'index',index.path) == tk_call_without_enc(@t.path,'index','end') 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' @path.gravity = 'left'
@index = @path.path @index = @path.path
@id = tk_call_without_enc(@t.path, 'image', 'create', @index, @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 end
def [](slot) def [](slot)
@ -59,7 +69,7 @@ class TkTextImage<TkObject
end end
def image 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 TkImage::Tk_IMGTBL[img]? TkImage::Tk_IMGTBL[img] : img
end end

View File

@ -5,6 +5,8 @@ require 'tk'
require 'tk/text' require 'tk/text'
class TkTextMark<TkObject class TkTextMark<TkObject
include TkText::IndexModMethods
TMarkID_TBL = TkCore::INTERP.create_table TMarkID_TBL = TkCore::INTERP.create_table
Tk_TextMark_ID = ['mark'.freeze, '00000'.taint].freeze Tk_TextMark_ID = ['mark'.freeze, '00000'.taint].freeze
@ -23,7 +25,7 @@ class TkTextMark<TkObject
@parent = @t = parent @parent = @t = parent
@tpath = parent.path @tpath = parent.path
# @path = @id = Tk_TextMark_ID.join('') # @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[@id] = self
TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath] TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
TMarkID_TBL[@tpath][@id] = self TMarkID_TBL[@tpath][@id] = self
@ -34,7 +36,7 @@ class TkTextMark<TkObject
end end
def id def id
@id TkText::IndexString.new(@id)
end end
def exist? def exist?
@ -46,10 +48,10 @@ class TkTextMark<TkObject
end end
def +(mod) def +(mod)
@id + ' + ' + mod TkText::IndexString.new(@id + ' + ' + mod)
end end
def -(mod) def -(mod)
@id + ' - ' + mod TkText::IndexString.new(@id + ' - ' + mod)
end end
def set(where) def set(where)

View File

@ -7,6 +7,7 @@ require 'tk/tagfont'
class TkTextTag<TkObject class TkTextTag<TkObject
include TkTreatTagFont include TkTreatTagFont
include TkText::IndexModMethods
TTagID_TBL = TkCore::INTERP.create_table TTagID_TBL = TkCore::INTERP.create_table
Tk_TextTag_ID = ['tag'.freeze, '00000'.taint].freeze Tk_TextTag_ID = ['tag'.freeze, '00000'.taint].freeze
@ -26,7 +27,7 @@ class TkTextTag<TkObject
@parent = @t = parent @parent = @t = parent
@tpath = parent.path @tpath = parent.path
# @path = @id = Tk_TextTag_ID.join('') # @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[@id] = self
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath] TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
TTagID_TBL[@tpath][@id] = self TTagID_TBL[@tpath][@id] = self
@ -46,7 +47,7 @@ class TkTextTag<TkObject
end end
def id def id
@id TkText::IndexString.new(@id)
end end
def exist? def exist?
@ -58,11 +59,11 @@ class TkTextTag<TkObject
end end
def first def first
@id + '.first' TkText::IndexString.new(@id + '.first')
end end
def last def last
@id + '.last' TkText::IndexString.new(@id + '.last')
end end
def add(*indices) def add(*indices)
@ -81,21 +82,25 @@ class TkTextTag<TkObject
l = tk_split_simplelist(tk_call_without_enc(@t.path, 'tag', 'ranges', @id)) l = tk_split_simplelist(tk_call_without_enc(@t.path, 'tag', 'ranges', @id))
r = [] r = []
while key=l.shift while key=l.shift
r.push [key, l.shift] r.push [TkText::IndexString.new(key), TkText::IndexString.new(l.shift)]
end end
r r
end end
def nextrange(first, last=None) def nextrange(first, last=None)
tk_split_list(tk_call_without_enc(@t.path, 'tag', 'nextrange', @id, simplelist(tk_call_without_enc(@t.path, 'tag', 'nextrange', @id,
_get_eval_enc_str(first), _get_eval_enc_str(first),
_get_eval_enc_str(last))) _get_eval_enc_str(last))).collect{|idx|
TkText::IndexString.new(idx)
}
end end
def prevrange(first, last=None) def prevrange(first, last=None)
tk_split_list(tk_call_without_enc(@t.path, 'tag', 'prevrange', @id, simplelist(tk_call_without_enc(@t.path, 'tag', 'prevrange', @id,
_get_eval_enc_str(first), _get_eval_enc_str(first),
_get_eval_enc_str(last))) _get_eval_enc_str(last))).collect{|idx|
TkText::IndexString.new(idx)
}
end end
def [](key) def [](key)

View File

@ -5,12 +5,14 @@ require 'tk'
require 'tk/text' require 'tk/text'
class TkTextWindow<TkObject class TkTextWindow<TkObject
def initialize(parent, index, keys) include TkText::IndexModMethods
def initialize(parent, index, keys = {})
#unless parent.kind_of?(TkText) #unless parent.kind_of?(TkText)
# fail ArguemntError, "expect TkText for 1st argument" # fail ArguemntError, "expect TkText for 1st argument"
#end #end
@t = parent @t = parent
if index == 'end' if index == 'end' || index == :end
@path = TkTextMark.new(@t, tk_call_without_enc(@t.path, 'index', @path = TkTextMark.new(@t, tk_call_without_enc(@t.path, 'index',
'end - 1 chars')) 'end - 1 chars'))
elsif index.kind_of?(TkTextMark) elsif index.kind_of?(TkTextMark)
@ -49,6 +51,14 @@ class TkTextWindow<TkObject
end end
tk_call_without_enc(@t.path, 'window', 'create', @index, tk_call_without_enc(@t.path, 'window', 'create', @index,
*hash_kv(keys, true)) *hash_kv(keys, true))
@path.gravity = 'right'
end
def id
TkText::IndexString.new(_epath(@id))
end
def mark
@path
end end
def [](slot) def [](slot)

View File

@ -15,9 +15,10 @@ class TkVirtualEvent<TkObject
TkCore::INTERP.init_ip_env{ TkVirtualEventTBL.clear } TkCore::INTERP.init_ip_env{ TkVirtualEventTBL.clear }
class PreDefVirtEvent<self class PreDefVirtEvent<self
def initialize(event) def initialize(event, *sequences)
@path = @id = event @path = @id = event
TkVirtualEvent::TkVirtualEventTBL[@id] = self TkVirtualEvent::TkVirtualEventTBL[@id] = self
add(*sequences)
end end
end end