diff options
Diffstat (limited to 'lib/tktext.rb')
-rw-r--r-- | lib/tktext.rb | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/lib/tktext.rb b/lib/tktext.rb new file mode 100644 index 0000000000..e7a2be950f --- /dev/null +++ b/lib/tktext.rb @@ -0,0 +1,160 @@ +# +# tktext.rb - Tk text classes +# $Date: 1995/12/07 08:37:10 $ +# by Yukihiro Matsumoto <matz@caelum.co.jp> + +require 'tk.rb' + +class TkText:TkTextWin + include Scrollable + def create_self + tk_call 'text', @path + @tags = {} + end + def index(index) + tk_send 'index', index + end + def value + tk_send 'get', "1.0", "end" + end + def value= (val) + tk_send 'delete', "1.0", 'end' + tk_send 'insert', "1.0", val + end + def _addcmd(cmd) + @cmdtbl.push id + end + def _addtag(cmd) + @cmdtbl.push id + end + private :_addcmd, :_addtag + def tag_names + tk_send('tag', 'names').collect{|elt| + if not @tags[elt] + elt + else + @tags[elt] + end + } + end + def window_names + tk_send('window', 'names').collect{|elt| + if not @tags[elt] + elt + else + @tags[elt] + end + } + end + + def destroy + for t in @tags + t.destroy + end + super + end + + def backspace + self.delete 'insert' + end + + def compare(idx1, op, idx2) + bool(tk_send('compare', idx1, op, idx2)) + end + + def debug + bool(tk_send('debug')) + end + def debug=(boolean) + tk_send 'debug', boolean + end + + def yview(*what) + tk_send 'yview', *what + end + def yview_pickplace(*what) + tk_send 'yview', '-pickplace', *what + end +end + +class TkTextTag:TkObject + $tk_text_tag = 'tag0000' + def initialize(parent) + if not parent.is_kind_of?(TkText) + fail format("%s need to be TkText", parent.inspect) + end + @t = parent + @path = parent.path + @id = $tk_text_tag + $tk_text_tag = $tk_text_tag.next + @t._addtag id, self + end + def id + return @id + end + + def add(*index) + tk_call path, 'tag', 'add', @id, *index + end + + def configure(slot, value) + tk_call path, 'tag', 'configure', id, "-#{slot}", value + end + + def bind(seq, cmd=Proc.new) + id = install_cmd(cmd) + tk_call path, 'tag', 'bind', tag, "<#{seq}>", id + @t._addcmd cmd + end + + def lower(below=None) + tk_call path, 'tag', 'lower', below + end + + def destroy + tk_call path, 'tag', 'delete', @id + end +end + +class TkTextMark:TkObject + $tk_text_mark = 'mark0000' + def initialize(parent, index) + if not parent.is_kind_of?(TkText) + fail format("%s need to be TkText", parent.inspect) + end + @t = parent + @path = parent.path + @id = $tk_text_mark + $tk_text_mark = $tk_text_mark.next + tk_call @t, 'set', @id, index + @t._addtag id, self + end + def id + return @id + end + + def set(where) + tk_call path, 'mark', 'unset', @id, where + end + + def unset + tk_call path, 'mark', 'unset', @id + end + alias destroy unset +end + +class TkTextWindow:TkObject + def initialize(parent, index, *args) + if not parent.is_kind_of?(TkText) + fail format("%s need to be TkText", parent.inspect) + end + @t = parent + @path = parent.path + @index = index + tk_call @path, 'window', 'create', index, *args + end + + def configure(slot, value) + tk_call path, 'window', 'configure', @index, "-#{slot}", value + end +end |