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

« back to all changes in this revision

Viewing changes to ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.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/scrolledcanvas.rb
 
3
#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
 
4
#
 
5
 
 
6
require 'tk'
 
7
require 'tk/canvas'
 
8
require 'tkextlib/iwidgets.rb'
 
9
 
 
10
module Tk
 
11
  module Iwidgets
 
12
    class Scrolledcanvas < Tk::Iwidgets::Scrolledwidget
 
13
    end
 
14
  end
 
15
end
 
16
 
 
17
class Tk::Iwidgets::Scrolledcanvas
 
18
  TkCommandNames = ['::iwidgets::scrolledcanvas'.freeze].freeze
 
19
  WidgetClassName = 'Scrolledcanvas'.freeze
 
20
  WidgetClassNames[WidgetClassName] = self
 
21
 
 
22
  ################################
 
23
 
 
24
  def __boolval_optkeys
 
25
    super() << 'autoresize'
 
26
  end
 
27
  private :__boolval_optkeys
 
28
 
 
29
  def __strval_optkeys
 
30
    super() << 'textbackground'
 
31
  end
 
32
  private :__strval_optkeys
 
33
 
 
34
  def initialize(*args)
 
35
    super(*args)
 
36
    @canvas = component_widget('canvas')
 
37
  end
 
38
 
 
39
  def method_missing(id, *args)
 
40
    if @canvas.methods.include?(id.id2name)
 
41
      @canvas.__send__(id, *args)
 
42
    else
 
43
      super(id, *args)
 
44
    end
 
45
  end
 
46
 
 
47
  ################################
 
48
 
 
49
  def child_site
 
50
    window(tk_call(@path, 'childsite'))
 
51
  end
 
52
 
 
53
  def justify(dir)
 
54
    tk_call(@path, 'justify', dir)
 
55
    self
 
56
  end
 
57
 
 
58
  ##########################
 
59
  include TkCanvasItemConfig
 
60
 
 
61
  def tagid(tag)
 
62
    if tag.kind_of?(TkcItem) || tag.kind_of?(TkcTag)
 
63
      tag.id
 
64
    elsif tag.kind_of?(Tk::Itk::Component)
 
65
      tag.name
 
66
    else
 
67
      tag  # maybe an Array of configure paramters
 
68
    end
 
69
  end
 
70
  private :tagid
 
71
 
 
72
  # create a canvas item without creating a TkcItem object
 
73
  def create(type, *args)
 
74
    type.create(self, *args)
 
75
  end
 
76
 
 
77
  #######################
 
78
 
 
79
  def addtag(tag, mode, *args)
 
80
    tk_send_without_enc('addtag', tagid(tag), mode, *args)
 
81
    self
 
82
  end
 
83
  def addtag_above(tagOrId, target)
 
84
    addtag(tagOrId, 'above', tagid(target))
 
85
  end
 
86
  def addtag_all(tagOrId)
 
87
    addtag(tagOrId, 'all')
 
88
  end
 
89
  def addtag_below(tagOrId, target)
 
90
    addtag(tagOrId, 'below', tagid(target))
 
91
  end
 
92
  def addtag_closest(tagOrId, x, y, halo=None, start=None)
 
93
    addtag(tagOrId, 'closest', x, y, halo, start)
 
94
  end
 
95
  def addtag_enclosed(tagOrId, x1, y1, x2, y2)
 
96
    addtag(tagOrId, 'enclosed', x1, y1, x2, y2)
 
97
  end
 
98
  def addtag_overlapping(tagOrId, x1, y1, x2, y2)
 
99
    addtag(tagOrId, 'overlapping', x1, y1, x2, y2)
 
100
  end
 
101
  def addtag_withtag(tagOrId, tag)
 
102
    addtag(tagOrId, 'withtag', tagid(tag))
 
103
  end
 
104
 
 
105
  def bbox(tagOrId, *tags)
 
106
    list(tk_send_without_enc('bbox', tagid(tagOrId), 
 
107
                             *tags.collect{|t| tagid(t)}))
 
108
  end
 
109
 
 
110
  #def itembind(tag, context, cmd=Proc.new, *args)
 
111
  #  _bind([path, "bind", tagid(tag)], context, cmd, *args)
 
112
  #  self
 
113
  #end
 
114
  def itembind(tag, context, *args)
 
115
    # if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
 
116
    if TkComm._callback_entry?(args[0]) || !block_given?
 
117
      cmd = args.shift
 
118
    else
 
119
      cmd = Proc.new
 
120
    end
 
121
    _bind([path, "bind", tagid(tag)], context, cmd, *args)
 
122
    self
 
123
  end
 
124
 
 
125
  #def itembind_append(tag, context, cmd=Proc.new, *args)
 
126
  #  _bind_append([path, "bind", tagid(tag)], context, cmd, *args)
 
127
  #  self
 
128
  #end
 
129
  def itembind_append(tag, context, *args)
 
130
    # if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
 
131
    if TkComm._callback_entry?(args[0]) || !block_given?
 
132
      cmd = args.shift
 
133
    else
 
134
      cmd = Proc.new
 
135
    end
 
136
    _bind_append([path, "bind", tagid(tag)], context, cmd, *args)
 
137
    self
 
138
  end
 
139
 
 
140
  def itembind_remove(tag, context)
 
141
    _bind_remove([path, "bind", tagid(tag)], context)
 
142
    self
 
143
  end
 
144
 
 
145
  def itembindinfo(tag, context=nil)
 
146
    _bindinfo([path, "bind", tagid(tag)], context)
 
147
  end
 
148
 
 
149
  def canvasx(screen_x, *args)
 
150
    #tk_tcl2ruby(tk_send_without_enc('canvasx', screen_x, *args))
 
151
    number(tk_send_without_enc('canvasx', screen_x, *args))
 
152
  end
 
153
  def canvasy(screen_y, *args)
 
154
    #tk_tcl2ruby(tk_send_without_enc('canvasy', screen_y, *args))
 
155
    number(tk_send_without_enc('canvasy', screen_y, *args))
 
156
  end
 
157
 
 
158
  def coords(tag, *args)
 
159
    if args == []
 
160
      tk_split_list(tk_send_without_enc('coords', tagid(tag)))
 
161
    else
 
162
      tk_send_without_enc('coords', tagid(tag), *(args.flatten))
 
163
      self
 
164
    end
 
165
  end
 
166
 
 
167
  def dchars(tag, first, last=None)
 
168
    tk_send_without_enc('dchars', tagid(tag), 
 
169
                        _get_eval_enc_str(first), _get_eval_enc_str(last))
 
170
    self
 
171
  end
 
172
 
 
173
  def delete(*args)
 
174
    if TkcItem::CItemID_TBL[self.path]
 
175
      find('withtag', *args).each{|item| 
 
176
        if item.kind_of?(TkcItem)
 
177
          TkcItem::CItemID_TBL[self.path].delete(item.id)
 
178
        end
 
179
      }
 
180
    end
 
181
    tk_send_without_enc('delete', *args.collect{|t| tagid(t)})
 
182
    self
 
183
  end
 
184
  alias remove delete
 
185
 
 
186
  def dtag(tag, tag_to_del=None)
 
187
    tk_send_without_enc('dtag', tagid(tag), tag_to_del)
 
188
    self
 
189
  end
 
190
 
 
191
  def find(mode, *args)
 
192
    list(tk_send_without_enc('find', mode, *args)).collect!{|id| 
 
193
      TkcItem.id2obj(self, id)
 
194
    }
 
195
  end
 
196
  def find_above(target)
 
197
    find('above', tagid(target))
 
198
  end
 
199
  def find_all
 
200
    find('all')
 
201
  end
 
202
  def find_below(target)
 
203
    find('below', tagid(target))
 
204
  end
 
205
  def find_closest(x, y, halo=None, start=None)
 
206
    find('closest', x, y, halo, start)
 
207
  end
 
208
  def find_enclosed(x1, y1, x2, y2)
 
209
    find('enclosed', x1, y1, x2, y2)
 
210
  end
 
211
  def find_overlapping(x1, y1, x2, y2)
 
212
    find('overlapping', x1, y1, x2, y2)
 
213
  end
 
214
  def find_withtag(tag)
 
215
    find('withtag', tag)
 
216
  end
 
217
 
 
218
  def itemfocus(tagOrId=nil)
 
219
    if tagOrId
 
220
      tk_send_without_enc('focus', tagid(tagOrId))
 
221
      self
 
222
    else
 
223
      ret = tk_send_without_enc('focus')
 
224
      if ret == ""
 
225
        nil
 
226
      else
 
227
        TkcItem.id2obj(self, ret)
 
228
      end
 
229
    end
 
230
  end
 
231
 
 
232
  def gettags(tagOrId)
 
233
    list(tk_send_without_enc('gettags', tagid(tagOrId))).collect{|tag|
 
234
      TkcTag.id2obj(self, tag)
 
235
    }
 
236
  end
 
237
 
 
238
  def icursor(tagOrId, index)
 
239
    tk_send_without_enc('icursor', tagid(tagOrId), index)
 
240
    self
 
241
  end
 
242
 
 
243
  def index(tagOrId, idx)
 
244
    number(tk_send_without_enc('index', tagid(tagOrId), idx))
 
245
  end
 
246
 
 
247
  def insert(tagOrId, index, string)
 
248
    tk_send_without_enc('insert', tagid(tagOrId), index, 
 
249
                        _get_eval_enc_str(string))
 
250
    self
 
251
  end
 
252
 
 
253
  def lower(tag, below=nil)
 
254
    if below
 
255
      tk_send_without_enc('lower', tagid(tag), tagid(below))
 
256
    else
 
257
      tk_send_without_enc('lower', tagid(tag))
 
258
    end
 
259
    self
 
260
  end
 
261
 
 
262
  def move(tag, x, y)
 
263
    tk_send_without_enc('move', tagid(tag), x, y)
 
264
    self
 
265
  end
 
266
 
 
267
  def postscript(keys)
 
268
    tk_send("postscript", *hash_kv(keys))
 
269
  end
 
270
 
 
271
  def raise(tag, above=nil)
 
272
    if above
 
273
      tk_send_without_enc('raise', tagid(tag), tagid(above))
 
274
    else
 
275
      tk_send_without_enc('raise', tagid(tag))
 
276
    end
 
277
    self
 
278
  end
 
279
 
 
280
  def scale(tag, x, y, xs, ys)
 
281
    tk_send_without_enc('scale', tagid(tag), x, y, xs, ys)
 
282
    self
 
283
  end
 
284
 
 
285
  def scan_mark(x, y)
 
286
    tk_send_without_enc('scan', 'mark', x, y)
 
287
    self
 
288
  end
 
289
  def scan_dragto(x, y)
 
290
    tk_send_without_enc('scan', 'dragto', x, y)
 
291
    self
 
292
  end
 
293
 
 
294
  def select(mode, *args)
 
295
    r = tk_send_without_enc('select', mode, *args)
 
296
    (mode == 'item')? TkcItem.id2obj(self, r): self
 
297
  end
 
298
  def select_adjust(tagOrId, index)
 
299
    select('adjust', tagid(tagOrId), index)
 
300
  end
 
301
  def select_clear
 
302
    select('clear')
 
303
  end
 
304
  def select_from(tagOrId, index)
 
305
    select('from', tagid(tagOrId), index)
 
306
  end
 
307
  def select_item
 
308
    select('item')
 
309
  end
 
310
  def select_to(tagOrId, index)
 
311
    select('to', tagid(tagOrId), index)
 
312
  end
 
313
 
 
314
  def itemtype(tag)
 
315
    TkcItem.type2class(tk_send('type', tagid(tag)))
 
316
  end
 
317
 
 
318
  def xview(*index)
 
319
    if index.size == 0
 
320
      list(tk_send_without_enc('xview'))
 
321
    else
 
322
      tk_send_without_enc('xview', *index)
 
323
      self
 
324
    end
 
325
  end
 
326
  def xview_moveto(*index)
 
327
    xview('moveto', *index)
 
328
  end
 
329
  def xview_scroll(*index)
 
330
    xview('scroll', *index)
 
331
  end
 
332
 
 
333
  def yview(*index)
 
334
    if index.size == 0
 
335
      list(tk_send_without_enc('yview'))
 
336
    else
 
337
      tk_send_without_enc('yview', *index)
 
338
      self
 
339
    end
 
340
  end
 
341
  def yview_moveto(*index)
 
342
    yview('moveto', *index)
 
343
  end
 
344
  def yview_scroll(*index)
 
345
    yview('scroll', *index)
 
346
  end
 
347
end