1#
2#  tkextlib/tcllib/ctext.rb
3#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
4#
5#   * Part of tcllib extension
6#   * Overloads the text widget and provides new commands
7#
8
9require 'tk'
10require 'tk/text'
11require 'tkextlib/tcllib.rb'
12
13# TkPackage.require('ctext', '3.1')
14TkPackage.require('ctext')
15
16module Tk
17  module Tcllib
18    class CText < Tk::Text
19      PACKAGE_NAME = 'ctext'.freeze
20      def self.package_name
21        PACKAGE_NAME
22      end
23
24      def self.package_version
25        begin
26          TkPackage.require('ctext')
27        rescue
28          ''
29        end
30      end
31    end
32  end
33end
34
35class Tk::Tcllib::CText
36  TkCommandNames = ['ctext'.freeze].freeze
37  WidgetClassName = 'Ctext'.freeze
38  WidgetClassNames[WidgetClassName] ||= self
39
40  def create_self(keys)
41    if keys and keys != None
42      tk_call_without_enc(self.class::TkCommandNames[0], @path,
43                          *hash_kv(keys, true))
44    else
45      tk_call_without_enc(self.class::TkCommandNames[0], @path)
46    end
47  end
48  private :create_self
49
50  def __strval_optkeys
51    super() << 'linemapfg' << 'linemapbg' <<
52      'linemap_select_fg' << 'linemap_select_bg'
53  end
54  private :__strval_optkeys
55
56  def __boolval_optkeys
57    super() << 'highlight' << 'linemap_markable'
58  end
59  private :__boolval_optkeys
60
61  def append(*args)
62    tk_send('append', *args)
63  end
64
65  def copy
66    tk_send('copy')
67  end
68
69  def cut
70    tk_send('cut')
71  end
72
73  def fast_delete(*args)
74    tk_send('fastdelete', *args)
75  end
76
77  def fast_insert(*args)
78    tk_send('fastinsert', *args)
79  end
80
81  def highlight(*args)
82    tk_send('highlight', *args)
83  end
84
85  def paste
86    tk_send('paste')
87  end
88
89  def edit(*args)
90    tk_send('edit', *args)
91  end
92
93  def add_highlight_class(klass, col, *keywords)
94    tk_call('ctext::addHighlightClass', @path, klass, col, keywords.flatten)
95    self
96  end
97
98  def add_highlight_class_for_special_chars(klass, col, *chrs)
99    tk_call('ctext::addHighlightClassForSpecialChars',
100            @path, klass, col, chrs.join(''))
101    self
102  end
103
104  def add_highlight_class_for_regexp(klass, col, tcl_regexp)
105    tk_call('ctext::addHighlightClassForRegexp',
106            @path, klass, col, tcl_regexp)
107    self
108  end
109
110  def add_highlight_class_with_only_char_start(klass, col, chr)
111    tk_call('ctext::addHighlightClassWithOnlyCharStart',
112            @path, klass, col, chr)
113    self
114  end
115
116  def clear_highlight_classes
117    tk_call('ctext::clearHighlightClasses', @path)
118    self
119  end
120
121  def get_highlight_classes
122    tk_split_simplelist(tk_call('ctext::getHighlightClasses', @path))
123  end
124
125  def delete_highlight_class(klass)
126    tk_call('ctext::deleteHighlightClass', @path, klass)
127    self
128  end
129
130  def enable_C_comments
131    tk_call('ctext::enableComments', @path)
132    self
133  end
134
135  def disable_C_comments
136    tk_call('ctext::disableComments', @path)
137    self
138  end
139
140  def find_next_char(idx, chr)
141    tk_call('ctext::findNextChar', @path, idx, chr)
142  end
143
144  def find_next_space(idx)
145    tk_call('ctext::findNextSpace', @path, idx)
146  end
147
148  def find_previous_space(idx)
149    tk_call('ctext::findPreviousSpace', @path, idx)
150  end
151
152  def set_update_proc(cmd=Proc.new)
153    tk_call('proc', 'ctext::update', '', cmd)
154    self
155  end
156
157  def modified?(mode)
158    bool(tk_call('ctext::modified', @path, mode))
159  end
160end
161