1#
2#  tkextlib/blt/htext.rb
3#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
4#
5
6require 'tk'
7require 'tk/itemconfig.rb'
8require 'tkextlib/blt.rb'
9
10module Tk::BLT
11  class Htext<TkWindow
12    Htext_Var = TkVarAccess.new_hash('htext')
13    Htext_Widget = TkVarAccess.new('htext(widget)', :window)
14    Htext_File = TkVarAccess.new('htext(file)')
15    Htext_Line = TkVarAccess.new('htext(line)')
16
17    include TkItemConfigMethod
18    include Scrollable
19
20    TkCommandNames = ['::blt::htext'.freeze].freeze
21    WidgetClassName = 'Htext'.freeze
22    WidgetClassNames[WidgetClassName] ||= self
23
24    alias window_cget_tkstring itemcget_tkstring
25    alias window_cget itemcget
26    alias window_cget_strict itemcget_strict
27    alias window_configure itemconfigure
28    alias window_configuinfo itemconfiginfo
29    alias current_window_configuinfo current_itemconfiginfo
30
31    def __strval_optkeys
32      super() << 'filename'
33    end
34  private :__strval_optkeys
35
36    def append(win, keys={})
37      tk_send('append', _epath(win), keys)
38      self
39    end
40
41    def goto_line(idx)
42      tk_send_without_enc('gotoline', idx)
43      self
44    end
45    def current_line
46      number(tk_send_without_enc('gotoline'))
47    end
48
49    def index(str)
50      number(tk_send('index', str))
51    end
52
53    def line_pos(str)
54      tk_send('linepos', str)
55    end
56
57    def range(from=None, to=None)
58      tk_send_without_enc('range', from, to)
59    end
60
61    def scan_mark(pos)
62      tk_send_without_enc('scan', 'mark', pos)
63      self
64    end
65
66    def scan_dragto(pos)
67      tk_send_without_enc('scan', 'dragto', pos)
68      self
69    end
70
71    def search(pat, from=None, to=None)
72      num = number(tk_send('search', pat, from, to))
73      (num < 0)? nil: num
74    end
75
76    def selection_adjust(index)
77      tk_send_without_enc('selection', 'adjust', index)
78      self
79    end
80    def selection_clear()
81      tk_send_without_enc('selection', 'clear')
82      self
83    end
84    def selection_from(index)
85      tk_send_without_enc('selection', 'from', index)
86      self
87    end
88    def selection_line(index)
89      tk_send_without_enc('selection', 'line', index)
90      self
91    end
92    def selection_present()
93      bool(tk_send_without_enc('selection', 'present'))
94    end
95    def selection_range(first, last)
96      tk_send_without_enc('selection', 'range', first, last)
97      self
98    end
99    def selection_to(index)
100      tk_send_without_enc('selection', 'to', index)
101      self
102    end
103    def selection_word(index)
104      tk_send_without_enc('selection', 'word', index)
105      self
106    end
107
108    def windows(pat=None)
109      list(tk_send('windows', pat))
110    end
111  end
112end
113