2
# tkextlib/iwidgets/scrolledcanvas.rb
3
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
8
require 'tkextlib/iwidgets.rb'
12
class Scrolledcanvas < Tk::Iwidgets::Scrolledwidget
17
class Tk::Iwidgets::Scrolledcanvas
18
TkCommandNames = ['::iwidgets::scrolledcanvas'.freeze].freeze
19
WidgetClassName = 'Scrolledcanvas'.freeze
20
WidgetClassNames[WidgetClassName] = self
22
################################
25
super() << 'autoresize'
27
private :__boolval_optkeys
30
super() << 'textbackground'
32
private :__strval_optkeys
36
@canvas = component_widget('canvas')
39
def method_missing(id, *args)
40
if @canvas.methods.include?(id.id2name)
41
@canvas.__send__(id, *args)
47
################################
50
window(tk_call(@path, 'childsite'))
54
tk_call(@path, 'justify', dir)
58
##########################
59
include TkCanvasItemConfig
62
if tag.kind_of?(TkcItem) || tag.kind_of?(TkcTag)
64
elsif tag.kind_of?(Tk::Itk::Component)
67
tag # maybe an Array of configure paramters
72
# create a canvas item without creating a TkcItem object
73
def create(type, *args)
74
type.create(self, *args)
77
#######################
79
def addtag(tag, mode, *args)
80
tk_send_without_enc('addtag', tagid(tag), mode, *args)
83
def addtag_above(tagOrId, target)
84
addtag(tagOrId, 'above', tagid(target))
86
def addtag_all(tagOrId)
87
addtag(tagOrId, 'all')
89
def addtag_below(tagOrId, target)
90
addtag(tagOrId, 'below', tagid(target))
92
def addtag_closest(tagOrId, x, y, halo=None, start=None)
93
addtag(tagOrId, 'closest', x, y, halo, start)
95
def addtag_enclosed(tagOrId, x1, y1, x2, y2)
96
addtag(tagOrId, 'enclosed', x1, y1, x2, y2)
98
def addtag_overlapping(tagOrId, x1, y1, x2, y2)
99
addtag(tagOrId, 'overlapping', x1, y1, x2, y2)
101
def addtag_withtag(tagOrId, tag)
102
addtag(tagOrId, 'withtag', tagid(tag))
105
def bbox(tagOrId, *tags)
106
list(tk_send_without_enc('bbox', tagid(tagOrId),
107
*tags.collect{|t| tagid(t)}))
110
#def itembind(tag, context, cmd=Proc.new, *args)
111
# _bind([path, "bind", tagid(tag)], context, cmd, *args)
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?
121
_bind([path, "bind", tagid(tag)], context, cmd, *args)
125
#def itembind_append(tag, context, cmd=Proc.new, *args)
126
# _bind_append([path, "bind", tagid(tag)], context, cmd, *args)
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?
136
_bind_append([path, "bind", tagid(tag)], context, cmd, *args)
140
def itembind_remove(tag, context)
141
_bind_remove([path, "bind", tagid(tag)], context)
145
def itembindinfo(tag, context=nil)
146
_bindinfo([path, "bind", tagid(tag)], context)
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))
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))
158
def coords(tag, *args)
160
tk_split_list(tk_send_without_enc('coords', tagid(tag)))
162
tk_send_without_enc('coords', tagid(tag), *(args.flatten))
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))
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)
181
tk_send_without_enc('delete', *args.collect{|t| tagid(t)})
186
def dtag(tag, tag_to_del=None)
187
tk_send_without_enc('dtag', tagid(tag), tag_to_del)
191
def find(mode, *args)
192
list(tk_send_without_enc('find', mode, *args)).collect!{|id|
193
TkcItem.id2obj(self, id)
196
def find_above(target)
197
find('above', tagid(target))
202
def find_below(target)
203
find('below', tagid(target))
205
def find_closest(x, y, halo=None, start=None)
206
find('closest', x, y, halo, start)
208
def find_enclosed(x1, y1, x2, y2)
209
find('enclosed', x1, y1, x2, y2)
211
def find_overlapping(x1, y1, x2, y2)
212
find('overlapping', x1, y1, x2, y2)
214
def find_withtag(tag)
218
def itemfocus(tagOrId=nil)
220
tk_send_without_enc('focus', tagid(tagOrId))
223
ret = tk_send_without_enc('focus')
227
TkcItem.id2obj(self, ret)
233
list(tk_send_without_enc('gettags', tagid(tagOrId))).collect{|tag|
234
TkcTag.id2obj(self, tag)
238
def icursor(tagOrId, index)
239
tk_send_without_enc('icursor', tagid(tagOrId), index)
243
def index(tagOrId, idx)
244
number(tk_send_without_enc('index', tagid(tagOrId), idx))
247
def insert(tagOrId, index, string)
248
tk_send_without_enc('insert', tagid(tagOrId), index,
249
_get_eval_enc_str(string))
253
def lower(tag, below=nil)
255
tk_send_without_enc('lower', tagid(tag), tagid(below))
257
tk_send_without_enc('lower', tagid(tag))
263
tk_send_without_enc('move', tagid(tag), x, y)
268
tk_send("postscript", *hash_kv(keys))
271
def raise(tag, above=nil)
273
tk_send_without_enc('raise', tagid(tag), tagid(above))
275
tk_send_without_enc('raise', tagid(tag))
280
def scale(tag, x, y, xs, ys)
281
tk_send_without_enc('scale', tagid(tag), x, y, xs, ys)
286
tk_send_without_enc('scan', 'mark', x, y)
289
def scan_dragto(x, y)
290
tk_send_without_enc('scan', 'dragto', x, y)
294
def select(mode, *args)
295
r = tk_send_without_enc('select', mode, *args)
296
(mode == 'item')? TkcItem.id2obj(self, r): self
298
def select_adjust(tagOrId, index)
299
select('adjust', tagid(tagOrId), index)
304
def select_from(tagOrId, index)
305
select('from', tagid(tagOrId), index)
310
def select_to(tagOrId, index)
311
select('to', tagid(tagOrId), index)
315
TkcItem.type2class(tk_send('type', tagid(tag)))
320
list(tk_send_without_enc('xview'))
322
tk_send_without_enc('xview', *index)
326
def xview_moveto(*index)
327
xview('moveto', *index)
329
def xview_scroll(*index)
330
xview('scroll', *index)
335
list(tk_send_without_enc('yview'))
337
tk_send_without_enc('yview', *index)
341
def yview_moveto(*index)
342
yview('moveto', *index)
344
def yview_scroll(*index)
345
yview('scroll', *index)