mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
3da93dd842
commit
cb2349d653
10 changed files with 188 additions and 39 deletions
36
ChangeLog
36
ChangeLog
|
@ -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>
|
||||
|
||||
* lib/cgi/session.rb (CGI::Session#initialize): control adding
|
||||
|
|
|
@ -2056,15 +2056,28 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
|
|||
case $KCODE
|
||||
when /^e/i # EUC
|
||||
Tk.encoding = 'euc-jp'
|
||||
Tk.encoding_system = 'euc-jp'
|
||||
when /^s/i # SJIS
|
||||
Tk.encoding = 'shiftjis'
|
||||
begin
|
||||
if Tk.encoding_system == 'cp932'
|
||||
Tk.encoding = 'cp932'
|
||||
else
|
||||
Tk.encoding = 'shiftjis'
|
||||
Tk.encoding_system = 'shiftjis'
|
||||
end
|
||||
rescue StandardError, NameError
|
||||
Tk.encoding = 'shiftjis'
|
||||
Tk.encoding_system = 'shiftjis'
|
||||
end
|
||||
when /^u/i # UTF8
|
||||
Tk.encoding = 'utf-8'
|
||||
Tk.encoding_system = 'utf-8'
|
||||
else # NONE
|
||||
begin
|
||||
Tk.encoding = Tk.encoding_system
|
||||
rescue StandardError, NameError
|
||||
Tk.encoding = 'utf-8'
|
||||
Tk.encoding_system = 'utf-8'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ end
|
|||
########################
|
||||
|
||||
require 'tkutil'
|
||||
require 'tk'
|
||||
# require 'tk'
|
||||
|
||||
########################
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue