summaryrefslogtreecommitdiffstats
path: root/demos/firefox.tcl
blob: f310e9885d745edd7504d433f92cecfbb3e71633 (plain)
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
proc DemoFirefoxPrivacy {} {

	set T .f2.f1.t

	#
	# Configure the treectrl widget
	#

	$T configure -showroot no -showbuttons yes -showlines no \
		-selectmode extended -xscrollincrement 20 -showheader yes

	# Hide the borders because child windows appear on top of them
	$T configure -borderwidth 0 -highlightthickness 0

	#
	# Create columns
	#

	# Create 2 new images for the buttona arrow
	if {[lsearch -exact [image names] arrow-up] == -1} {

		set color #ACA899 ; # WinXP arrow color

		set img arrow-down
		image create photo $img
		$img put [list [string repeat "$color " 9]] -to 0 0
		$img put [list [string repeat "$color " 7]] -to 1 1
		$img put [list [string repeat "$color " 5]] -to 2 2
		$img put [list [string repeat "$color " 3]] -to 3 3
		$img put [list [string repeat "$color " 1]] -to 4 4

		set img arrow-up
		image create photo $img
		$img put [list [string repeat "$color " 1]] -to 4 0
		$img put [list [string repeat "$color " 3]] -to 3 1
		$img put [list [string repeat "$color " 5]] -to 2 2
		$img put [list [string repeat "$color " 7]] -to 1 3
		$img put [list [string repeat "$color " 9]] -to 0 4
	}

	$T column create -expand yes -arrowimage {arrow-down !up arrow-up {}} \
		-arrow up -arrowpadx {10 2} -textlines 0 \
		-text "This is a multi-line column title\nwith an image for the arrow"

	# This binding toggles the sort arrow
	$T notify bind $T <Header-invoke> {
		if {[%T column cget %C -arrow] eq "up"} {
			%T column configure %C -arrow down
		} else {
			%T column configure %C -arrow up
		}
	}

	#
	# Create elements
	#

	$T element create eWindow window
	$T element create eText1 text -font [list "[$T cget -font] bold"]
	$T element create eText2 text

	#
	# Create styles using the elements
	#

	set S [$T style create styCategory -orient horizontal]
	$T style elements $S {eText1 eWindow}
	$T style layout $S eText1 -expand ns
	$T style layout $S eWindow -expand nws -padx 10 -pady 6

	set S [$T style create styFrame -orient horizontal]
	$T style elements $S eWindow
	$T style layout $S eWindow -iexpand e -squeeze x

	#
	# Create items and assign styles
	#

	foreach category {
		"History"
		"Saved Form Information"
		"Saved Passwords"
		"Download Manager History"
		"Cookies"
		"Cache"} {
		set I [$T item create -button yes]
		$T item style set $I 0 styCategory
		$T item element configure $I 0 eText1 -text $category
		set b [button $T.b$I -text "Clear" -command "" -width 11]
		$T item element configure $I 0 eWindow -window $b
		$T item lastchild root $I
	}

	set bg [$T cget -background]
	set textBg $bg

	# History
	set I [$T item create]
	$T item style set $I 0 styFrame
	set f [frame $T.f$I -borderwidth 0 -background $bg]
	label $f.l1 -background $bg -text "Remember visited pages for the last"
	entry $f.e1 -width 6 -background $bg
	$f.e1 insert end 20
	label $f.l2 -background $bg -text "days" -background $bg
	pack $f.l1 -side left
	pack $f.e1 -side left -padx 8
	pack $f.l2 -side left
	$T item element configure $I 0 eWindow -window $f
	$T item lastchild [$T index "root child 0"] $I

	# Saved Form Information
	set I [$T item create]
	$T item style set $I 0 styFrame
	set f [frame $T.f$I -borderwidth 0 -background $bg]
	text $f.t1 -background $textBg -borderwidth 0 -width 10 -height 1 -wrap word -cursor ""
	$f.t1 insert end "Information entered in web page forms and the Search Bar is saved to make filling out forms and searching faster."
	bindtags $f.t1 TextWrapBindTag
	checkbutton $f.cb1 -background $bg -text "Save information I enter in web page forms and the Search Bar"
	$f.cb1 select
	pack $f.t1 -side top -anchor w -fill x -padx {0 10} -pady {0 4}
	pack $f.cb1 -side top -anchor w
	$T item element configure $I 0 eWindow -window $f
	$T item lastchild [$T index "root child 1"] $I

	# Saved Passwords
	set I [$T item create]
	$T item style set $I 0 styFrame
	set f [frame $T.f$I -borderwidth 0 -background $bg]

	set fLeft [frame $f.fLeft -borderwidth 0 -background $bg]
	text $fLeft.t1 -background $textBg -borderwidth 0 -width 10 -height 1 -wrap word -cursor ""
	$fLeft.t1 insert end "Login information for web pages can be kept in the Password Manager so that you do not need to re-enter your login details every time you visit."
	bindtags $fLeft.t1 TextWrapBindTag
	checkbutton $fLeft.cb1 -background $bg -text "Remember Passwords"
	$fLeft.cb1 select
	pack $fLeft.t1 -side top -expand yes -fill x -pady {0 4}
	pack $fLeft.cb1 -side top -anchor w

	set fRight [frame $f.fRight -borderwidth 0 -background $bg]
	button $fRight.b1 -text "View Saved Passwords"
	button $fRight.b2 -text "Change Master Password..."
	pack $fRight.b1 -side top -expand yes -fill x
	pack $fRight.b2 -side top -expand yes -fill x -pady {8 0}
	pack $fLeft -side left -expand yes -fill x
	pack $fRight -side right -padx 14 -anchor n
	$T item element configure $I 0 eWindow -window $f
	$T item lastchild [$T index "root child 2"] $I

	# Download Manager History
	set I [$T item create]
	$T item style set $I 0 styFrame
	set f [frame $T.f$I -borderwidth 0 -background $bg]
	text $f.t1 -background $textBg -borderwidth 0 -width 10 -height 1 -wrap word -cursor ""
	$f.t1 insert end "The Download Manager keeps track of recently downloaded files."
	bindtags $f.t1 TextWrapBindTag

	set f1 [frame $f.f1 -borderwidth 0 -background $bg]
	label $f1.l1 -background $bg -text "Remove files from the Download Manager:"
	menubutton $f1.mb1 -indicatoron yes -menu $f1.mb1.m -text Manually \
		-width [string length "Upon successful download"] -justify left
	set m [menu $f1.mb1.m -tearoff no]
	foreach label {
		"Upon successful download"
		"When firefox exits"
		Manually} {
		$m add command -label $label -command [list $f1.mb1 configure -text $label]
	}
	pack $f1.l1 -side left
	pack $f1.mb1 -side left -padx {8 10}
	pack $f.t1 -side top -expand yes -fill x -padx {0 10}
	pack $f1 -side top -anchor w
	$T item element configure $I 0 eWindow -window $f
	$T item lastchild [$T index "root child 3"] $I

	# Cookies
	set I [$T item create]
	$T item style set $I 0 styFrame
	set f [frame $T.f$I -borderwidth 0 -background $bg]
	text $f.t1 -background $textBg -borderwidth 0 -width 10 -height 1 -wrap word -cursor ""
	$f.t1 insert end "Cookies are pieces of information stored by web pages on your computer. They are used to remember login information and other data."
	bindtags $f.t1 TextWrapBindTag

	set fLeft [frame $f.fLeft -borderwidth 0 -background $bg]
	checkbutton $fLeft.cb1 -background $bg -text "Allow sites to set cookies"
	$fLeft.cb1 select
	checkbutton $fLeft.cb2 -background $bg -text "for the originating web site only"
	pack $fLeft.cb1 -side top -anchor w
	pack $fLeft.cb2 -side top -anchor w -padx {20 0}

	set fRight [frame $f.fRight -borderwidth 0 -background $bg]
	button $fRight.b1 -text "Exceptions"
	button $fRight.b2 -text "View Cookies"
	pack $fRight.b1 -side left -padx {0 10}
	pack $fRight.b2 -side left

	set f1 [frame $fLeft.f1 -borderwidth 0 -background $bg]
	label $f1.l1 -background $bg -text "Keep Cookies:"
	menubutton $f1.mb1 -indicatoron yes -menu $f1.mb1.m -text "until they expire" \
		-width [string length "until I close Firefox"] -justify left
	set m [menu $f1.mb1.m -tearoff no]
	foreach label {
		"until they expire"
		"until I close Firefox"
		"ask me every time"} {
		$m add command -label $label -command [list $f1.mb1 configure -text $label]
	}
	pack $f1.l1 -side left
	pack $f1.mb1 -side left -padx {8 0}
	pack $f1 -side top -anchor w

	pack $f.t1 -side top -expand yes -fill x -padx {0 10} -pady {0 8}
	pack $fLeft -side left -expand yes -fill x
	pack $fRight -side right -padx 14 -anchor n
	$T item element configure $I 0 eWindow -window $f
	$T item lastchild [$T index "root child 4"] $I

	# Cache
	set I [$T item create]
	$T item style set $I 0 styFrame
	set f [frame $T.f$I -borderwidth 0 -background $bg]
	text $f.t1 -background $textBg -borderwidth 0 -width 10 -height 1 -wrap word -cursor ""
	$f.t1 insert end "Pages you view are stored in the cache for quicker viewing later on."
	bindtags $f.t1 TextWrapBindTag
	set f1 [frame $f.f1 -borderwidth 0 -background $bg]
	label $f1.l1 -background $bg -text "Use up to:"
	entry $f1.e1 -width 10 -background $bg
	$f1.e1 insert end 50000
	label $f1.l2 -background $bg -text "KB of disk space for the cache." -background $bg
	pack $f1.l1 -side left
	pack $f1.e1 -side left -padx 8
	pack $f1.l2 -side left
	pack $f.t1 -side top -expand yes -fill x -padx {0 10}
	pack $f1 -side top -anchor w
	$T item element configure $I 0 eWindow -window $f
	$T item lastchild [$T index "root child 5"] $I

	# This binding configures the -height option of a Text widget to the
	# number of lines it is displaying
	bind TextWrapBindTag <Configure> {
		scan [textlayout [%W cget -font] [%W get 1.0 "end - 1 chars"] -width %w] "%%d %%d" width height
		%W configure -height [expr {$height / [font metrics [%W cget -font] -linespace]}]
	}

	# This binding collapses all items before expanding a new one
	$T notify bind $T <Expand-before> {
		%T collapse all
	}
	$T item collapse all

	return
}