~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to ext/tk/lib/tkextlib/iwidgets/entryfield.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
#  tkextlib/iwidgets/entryfield.rb
 
3
#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
 
4
#
 
5
 
 
6
require 'tk'
 
7
require 'tkextlib/iwidgets.rb'
 
8
 
 
9
module Tk
 
10
  module Iwidgets
 
11
    class  Entryfield < Tk::Iwidgets::Labeledwidget
 
12
    end
 
13
  end
 
14
end
 
15
 
 
16
class Tk::Iwidgets::Entryfield
 
17
  TkCommandNames = ['::iwidgets::entryfield'.freeze].freeze
 
18
  WidgetClassName = 'Entryfield'.freeze
 
19
  WidgetClassNames[WidgetClassName] = self
 
20
 
 
21
  def __font_optkeys
 
22
    super() << 'textfont'
 
23
  end
 
24
  private :__font_optkeys
 
25
 
 
26
  ####################################
 
27
 
 
28
  include Tk::ValidateConfigure
 
29
 
 
30
  class EntryfieldValidate < TkValidateCommand
 
31
    #class CalCmdArgs < TkUtil::CallbackSubst
 
32
    class ValidateArgs < TkUtil::CallbackSubst
 
33
      KEY_TBL  = [ 
 
34
        [ ?c, ?s, :char ], 
 
35
        [ ?P, ?s, :post ], 
 
36
        [ ?S, ?s, :current ], 
 
37
        [ ?W, ?w, :widget ], 
 
38
        nil
 
39
      ]
 
40
      PROC_TBL = [ 
 
41
        [ ?s, TkComm.method(:string) ], 
 
42
        [ ?w, TkComm.method(:window) ], 
 
43
        nil
 
44
      ]
 
45
      _setup_subst_table(KEY_TBL, PROC_TBL);
 
46
    end
 
47
 
 
48
    def self._config_keys
 
49
      ['validate', 'invalid']
 
50
    end
 
51
  end
 
52
 
 
53
  def __validation_class_list
 
54
    super() << EntryfieldValidate
 
55
  end
 
56
 
 
57
  Tk::ValidateConfigure.__def_validcmd(binding, EntryfieldValidate)
 
58
=begin
 
59
  def validate(cmd = Proc.new, args = nil)
 
60
    if cmd.kind_of?(ValidateCmd)
 
61
      configure('validate', cmd)
 
62
    elsif args
 
63
      configure('validate', [cmd, args])
 
64
    else
 
65
      configure('validate', cmd)
 
66
    end
 
67
  end
 
68
 
 
69
  def invalid(cmd = Proc.new, args = nil)
 
70
    if cmd.kind_of?(ValidateCmd)
 
71
      configure('invalid', cmd)
 
72
    elsif args
 
73
      configure('invalid', [cmd, args])
 
74
    else
 
75
      configure('invalid', cmd)
 
76
    end
 
77
  end
 
78
=end
 
79
 
 
80
  ####################################
 
81
 
 
82
  def clear
 
83
    tk_call(@path, 'clear')
 
84
    self
 
85
  end
 
86
 
 
87
  def delete(first, last=None)
 
88
    tk_send_without_enc('delete', first, last)
 
89
    self
 
90
  end
 
91
 
 
92
  def value
 
93
    _fromUTF8(tk_send_without_enc('get'))
 
94
  end
 
95
  def value= (val)
 
96
    tk_send_without_enc('delete', 0, 'end')
 
97
    tk_send_without_enc('insert', 0, _get_eval_enc_str(val))
 
98
    val
 
99
  end
 
100
  alias get value
 
101
  alias set value=
 
102
 
 
103
  def cursor=(index)
 
104
    tk_send_without_enc('icursor', index)
 
105
    #self
 
106
    index
 
107
  end
 
108
  alias icursor cursor=
 
109
 
 
110
  def index(index)
 
111
    number(tk_send_without_enc('index', index))
 
112
  end
 
113
 
 
114
  def insert(pos,text)
 
115
    tk_send_without_enc('insert', pos, _get_eval_enc_str(text))
 
116
    self
 
117
  end
 
118
 
 
119
  def mark(pos)
 
120
    tk_send_without_enc('scan', 'mark', pos)
 
121
    self
 
122
  end
 
123
  def dragto(pos)
 
124
    tk_send_without_enc('scan', 'dragto', pos)
 
125
    self
 
126
  end
 
127
  def selection_adjust(index)
 
128
    tk_send_without_enc('selection', 'adjust', index)
 
129
    self
 
130
  end
 
131
  def selection_clear
 
132
    tk_send_without_enc('selection', 'clear')
 
133
    self
 
134
  end
 
135
  def selection_from(index)
 
136
    tk_send_without_enc('selection', 'from', index)
 
137
    self
 
138
  end
 
139
  def selection_present()
 
140
    bool(tk_send_without_enc('selection', 'present'))
 
141
  end
 
142
  def selection_range(s, e)
 
143
    tk_send_without_enc('selection', 'range', s, e)
 
144
    self
 
145
  end
 
146
  def selection_to(index)
 
147
    tk_send_without_enc('selection', 'to', index)
 
148
    self
 
149
  end
 
150
 
 
151
  # based on tk/scrollable.rb
 
152
  def xview(*index)
 
153
    if index.size == 0
 
154
      list(tk_send_without_enc('xview'))
 
155
    else
 
156
      tk_send_without_enc('xview', *index)
 
157
      self
 
158
    end
 
159
  end
 
160
  def xview_moveto(*index)
 
161
    xview('moveto', *index)
 
162
  end
 
163
  def xview_scroll(*index)
 
164
    xview('scroll', *index)
 
165
  end
 
166
end