1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
#
# Demo: Help contents
#
def demoHelpContents(t)
height = t.font.metrics(:linespace)
height = 18 if height < 18
t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
:itemheight=>height, :selectmode=>:browse)
init_pics('help-*')
if $Version_1_1_OrLater
t.column_create(:text=>'Help Contents')
else # TreeCtrl 1.0
t.column_configure(0, :text=>'Help Contents')
end
# Define a new item state
t.state_define('mouseover')
t.element_create('e1', :image, :image=>@images['help-page'])
t.element_create('e2', :image, :image=>[
@images['help-book-open'], ['open'],
@images['help-book-closed'], [],
])
t.element_create('e3', :text,
:font=>[t.font.dup.underline(true), ['mouseover']],
:fill=>[
@SystemHighlightText, ['selected', 'focus'],
'blue', ['mouseover']
])
t.element_create('e4', :rect, :showfocus=>true,
:fill=>[@SystemHighlight, ['selected', 'focus']])
# book
s = t.style_create('s1')
t.style_elements(s, ['e4', 'e1', 'e3'])
t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns)
t.style_layout(s, 'e3', :expand=>:ns)
t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)
# page
s = t.style_create('s2')
t.style_elements(s, ['e4', 'e2', 'e3'])
t.style_layout(s, 'e2', :padx=>[0,4], :expand=>:ns)
t.style_layout(s, 'e3', :expand=>:ns)
t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)
parentList = [:root, '', '', '', '', '', '']
parent = :root
[
[0, 's1', "Welcome to Help"],
[0, 's2', "Introducing Windows 98"],
[1, 's2', "How to Use Help"],
[2, 's1', "Find a topic"],
[2, 's1', "Get more out of help"],
[1, 's2', "Register Your Software"],
[2, 's1', "Registering Windows 98 online"],
[1, 's2', "What's New in Windows 98"],
[2, 's1', "Innovative, easy-to-use features"],
[2, 's1', "Improved reliability"],
[2, 's1', "A faster operating system"],
[2, 's1', "True Web integration"],
[2, 's1', "More entertaining and fun"],
[1, 's2', "If You're New to Windows 98"],
[2, 's2', "Tips for Macintosh Users"],
[3, 's1', "Why does the mouse have two buttons?"]
].each{|depth, style, text|
item = t.item_create
t.item_style_set(item, 0, style)
t.item_element_configure(item, 0, 'e3', :text=>text)
if $Version_1_1_OrLater
t.item_collapse(item)
else # TreeCtrl 1.0
t.collapse(item)
end
t.item_lastchild(parentList[depth], item)
depth += 1
parentList[depth] = item
}
treeCtrlHelp = TkBindTag.new
treeCtrlHelp.bind('Double-ButtonPress-1',
proc{|w, x, y|
if w.identify(x, y)[0] == 'header'
Tk::TreeCtrl::BindCallback.doubleButton1(w, x, y)
else
helpButton1(w, x, y)
end
Tk.callback_break
}, '%W %x %y')
treeCtrlHelp.bind('ButtonPress-1',
proc{|w, x, y|
helpButton1(w, x, y)
Tk.callback_break
}, '%W %x %y')
treeCtrlHelp.bind('Button1-Motion',
proc{|w, x, y|
helpMotion1(w, x, y)
Tk.callback_break
}, '%W %x %y')
treeCtrlHelp.bind('Button1-Leave',
proc{|w, x, y|
helpLeave1(w, x, y)
Tk.callback_break
}, '%W %x %y')
treeCtrlHelp.bind('ButtonRelease-1',
proc{|w, x, y|
helpRelease1(w, x, y)
Tk.callback_break
}, '%W %x %y')
treeCtrlHelp.bind('Motion', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y')
treeCtrlHelp.bind('Leave', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y')
treeCtrlHelp.bind('KeyPress-Return',
proc{|w, x, y|
if w.selection_get.length == 1
if $Version_1_1_OrLater
w.item_toggle(w.selection_get[0])
else # TreeCtrl 1.0
w.toggle(w.selection_get[0])
end
end
Tk.callback_break
}, '%W %x %y')
@Priv[:help, :prev] = ''
t.bindtags = [ t, treeCtrlHelp, Tk::TreeCtrl, t.winfo_toplevel, :all ]
end
# This is an alternate implementation that does not define a new item state
# to change the appearance of the item under the cursor.
def demoHelpContents2(t)
height = t.font.metrics(:linespace)
height = 18 if height < 18
t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
:itemheight=>height, :selectmode=>:browse)
init_pics('help-*')
if $Version_1_1_OrLater
t.column_create(:text=>'Help Contents')
else # TreeCtrl 1.0
t.column_configure(0, :text=>'Help Contents')
end
t.element_create('e1', :image, :image=>@images['help-page'])
t.element_create('e2', :image, :image=>[
@images['help-book-open'], ['open'],
@images['help-book-closed'], [],
])
t.element_create('e3', :text,
:fill=>[
@SystemHighlightText, ['selected', 'focus'],
'blue', []
])
t.element_create('e4', :rect, :showfocus=>true,
:fill=>[@SystemHighligh, ['selected', 'focus']])
t.element_create('e5', :text, :font=>t.font.dup.underline(true),
:fill=>[
@SystemHighlightText, ['selected', 'focus'],
'blue', []
])
# book
s = t.style_create('s1')
t.style_elements(s, ['e4', 'e1', 'e3'])
t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns)
t.style_layout(s, 'e3', :expand=>:ns)
t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)
# page
s = t.style_create('s2')
t.style_elements(s, ['e4', 'e2', 'e3'])
t.style_layout(s, 'e2', :padx=>[0,4], :expand=>:ns)
t.style_layout(s, 'e3', :expand=>:ns)
t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)
# book (focus)
s = t.style_create('s1.f')
t.style_elements(s, ['e4', 'e1', 'e5'])
t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns)
t.style_layout(s, 'e5', :expand=>:ns)
t.style_layout(s, 'e4', :union=>['e5'], :iexpand=>:ns, :ipadx=>2)
# page (focus)
s = t.style_create('s2')
t.style_elements(s, ['e4', 'e2', 'e5'])
t.style_layout(s, 'e2', :padx=>[0,4], :expand=>:ns)
t.style_layout(s, 'e5', :expand=>:ns)
t.style_layout(s, 'e4', :union=>['e5'], :iexpand=>:ns, :ipadx=>2)
parentList = [:root, '', '', '', '', '', '']
parent = :root
[
[0, 's1', "Welcome to Help"],
[0, 's2', "Introducing Windows 98"],
[1, 's2', "How to Use Help"],
[2, 's1' "Find a topic"],
[2, 's1', "Get more out of help"],
[1, 's2', "Register Your Software"],
[2, 's1', "Registering Windows 98 online"],
[1, 's2', "What's New in Windows 98"],
[2, 's1', "Innovative, easy-to-use features"],
[2, 's1', "Improved reliability"],
[2, 's1', "A faster operating system"],
[2, 's1', "True Web integration"],
[2, 's1', "More entertaining and fun"],
[1, 's2', "If You're New to Windows 98"],
[2, 's2', "Tips for Macintosh Users"],
[3, 's1', "Why does the mouse have two buttons?"]
].each{|depth, style, text|
item = t.item_create
t.item_style_set(item, 0, style)
t.item_element_configure(item, 0, 'e3', :text=>text)
if $Version_1_1_OrLater
t.item_collapse(item)
else # TreeCtrl 1.0
t.collapse(item)
end
t.item_lastchild(parentList[depth], item)
depth += 1
parentList[depth] = item
}
treeCtrlHelp = TkBindTag.new
treeCtrlHelp.bind('Double-ButtonPress-1',
proc{|w, x, y|
if w.identify(x, y)[0] == 'header'
Tk::TreeCtrl::BindCallback.doubleButton1(w, x, y)
else
helpButton1(w, x, y)
end
Tk.callback_break
}, '%W %x %y')
treeCtrlHelp.bind('ButtonPress-1',
proc{|w, x, y|
helpButton1(w, x, y)
Tk.callback_break
}, '%W %x %y')
treeCtrlHelp.bind('Button1-Motion',
proc{|w, x, y|
helpMotion1(w, x, y)
Tk.callback_break
}, '%W %x %y')
treeCtrlHelp.bind('Button1-Leave',
proc{|w, x, y|
helpLeave1(w, x, y)
Tk.callback_break
}, '%W %x %y')
treeCtrlHelp.bind('ButtonRelease-1',
proc{|w, x, y|
helpRelease1(w, x, y)
Tk.callback_break
}, '%W %x %y')
treeCtrlHelp.bind('Motion', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y')
treeCtrlHelp.bind('Leave', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y')
treeCtrlHelp.bind('KeyPress-Return',
proc{|w, x, y|
if w.selection_get.length == 1
w.item_toggle(w.selection_get[0])
end
Tk.callback_break
}, '%W %x %y')
@Priv[:help, :prev] = ''
t.bindtags = [ t, treeCtrlHelp, Tk::TreeCtrl, t.winfo_toplevel, :all ]
end
def helpButton1(w, x, y)
w.set_focus
id = w.identify(x, y)
@Priv['buttonMode'] = ''
if id[0] == 'header'
Tk::TreeCtrl::BindCallback.buttonPress1(w, x, y)
elsif id[0] == 'item'
item = id[1]
# didn't click an element
return if id.length != 6
if w.selection_includes(item)
w.toggle(item)
return
end
if w.selection_get.length > 0
item2 = w.selection_get[0]
if $Version_1_1_OrLater
w.item_collapse(item2)
else # TreeCtrl 1.0
w.collapse(item2)
end
w.item_ancestors(item2).each{|i|
if $Version_1_1_OrLater
w.item_collapse(i) if w.compare(item, '!=', i)
else # TreeCtrl 1.0
w.collapse(i) if w.compare(item, '!=', i)
end
}
end
w.activate(item)
if $Version_1_1_OrLater
w.item_ancestors(item).each{|i|
w.item_expand(i)
}
w.item_toggle(item)
else # TreeCtrl 1.0
w.expand(*(w.item_ancestors(item)))
w.toggle(item)
end
w.selection_modify(item, :all)
end
end
def helpMotion1(w, x, y)
case @Priv['buttonMode']
when 'resize', 'header'
Tk::TreeCtrl::BindCallback.motion1(w, x, y)
end
end
def helpLeave1(w, x, y)
# This is called when I do ButtonPress-1 on Unix for some reason,
# and buttonMode is undefined.
return unless @Priv.exist?('buttonMode')
case @Priv['buttonMode']
when 'header'
w.column_configure(@Priv['column'], :sunken=>false)
end
end
def helpRelease1(w, x, y)
case @Priv['buttonMode']
when 'resize', 'header'
Tk::TreeCtrl::BindCallback.release1(w, x, y)
end
@Priv['buttonMode'] = ''
end
def helpMotion(w, x, y)
id = w.identify(x, y)
if id.empty?
elsif id[0] == 'header'
elsif id[0] == 'item'
item = id[1]
if id.length == 6
if @Priv[:help, :prev] != TkComm._get_eval_string(item)
if @Priv[:help, :prev] != ''
w.item_state_set(@Priv[:help, :prev], '!mouseover')
end
w.item_state_set(item, 'mouseover')
@Priv[:help, :prev] = item
end
return
end
end
if @Priv[:help, :prev] != ''
w.item_state_set(@Priv[:help, :prev], '!mouseover')
@Priv[:help, :prev] = ''
end
end
# Alternate implementation doesn't rely on mouseover state
def helpMotion2(w, x, y)
id = w.identify(x, y)
if id[0] == 'header'
elsif !id.empty?
item = id[1]
if id.kength == 6
if @Priv[:help, :prev] != TkComm._get_eval_string(item)
if @Priv[:help, :prev] != ''
style = w.item_style_set(@Priv[:help, :prev], 0)
style.sub!(/\.f$/, '')
w.item_style_map(@Priv[:help, :prev], 0, style, ['e5', 'e3'])
end
style = w.item_style_set(item, 0)
w.item_style_map(item, 0, style + '.f', ['e3', 'e5'])
@Priv[:help, :prev] = item
end
return
end
end
if @Priv[:help, :prev] != ''
style = w.item_style_set(@Priv[:help, :prev], 0)
style.sub!(/\.f$/, '')
w.item_style_map(@Priv[:help, :prev], 0, style, ['e5', 'e3'])
@Priv[:help, :prev] = ''
end
end
|