Moved mode setting out of .spec file into Makefile.
[wine/gsoc_dplay.git] / tools / wineconf.libs / dirbrowser.tcl
blob64a68ca9ce525751a77b08e982ee5dfeb2df3c6c
1 # Copyright 1999 Jean-Louis Thirot
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 proc TkW:dirbrowse {pattern patternF mode} {
19 # input arg: initial pattern mode (File or Folder
20 # returns selected folders as a global SelectFolder
21 # or selected file as a global: SelectFile
22 # variable: SelectFolder
24 # You can use WAITbrowse in the calling app to wait
25 # for dirbrowse to exit (set to 0 on exit, or -1 on CANCEL)
26 global WAITbrowse
27 global SelectFolder
28 global SelectFile
29 if {![info exists SelectFile]} {set SelectFile ""}
30 if {![info exists SelectFolder]} {set SelectFolder [pwd]}
31 global ndirs nfiles;set ndirs 0;set nfiles 0
32 global ModeBrowse Restore;set Restore $SelectFolder
33 global FTPcd
34 if {$mode == "local"} {set FTPcd 1} {set FTPcd 0}
35 set ModeBrowse $mode
36 global DIRBROWSE WinBrowse
37 ###################
38 # CREATING WIDGETS
39 ###################
40 if {$mode != "local" } {
41 toplevel .dirbrowse -class Toplevel \
42 -background #feffff
43 wm focusmodel .dirbrowse passive
44 wm geometry .dirbrowse 464x296
45 wm maxsize .dirbrowse 1265 994
46 wm minsize .dirbrowse 1 1
47 wm overrideredirect .dirbrowse 0
48 wm resizable .dirbrowse 1 1
49 wm deiconify .dirbrowse
50 wm title .dirbrowse "TkWine: $DIRBROWSE"
51 set WinBrowse dirbrowse
52 } else {
53 set WinBrowse ftp.browsers.local
54 #frame .$WinBrowse -background #feffff -height 300 -width 464
57 # Lang globals:
58 global FolderSelection OK CANCEL FILTERFOLD FILTERFILES
59 global RESCAN VIEW HELP
60 # Other globals:
61 global BrowsePattern;set BrowsePattern $pattern
62 global BrowsePatternF;set BrowsePatternF $patternF
63 global dirscroll MouseY
66 # label and entrybox for selection:
67 label .$WinBrowse.foldselLab \
68 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
69 -relief groove -text $FolderSelection
70 entry .$WinBrowse.foldsel \
71 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
72 -textvariable SelectFolder
73 if {$ModeBrowse == "File"} {
74 .$WinBrowse.foldsel configure -textvar SelectFile
76 # frame for display of currently available folders:
77 frame .$WinBrowse.dirframe \
78 -borderwidth 1 -height 30 -relief sunken -width 30 \
79 -background #dddddd
80 scrollbar .$WinBrowse.dirframe_scr -width 10
81 frame .$WinBrowse.fileframe \
82 -borderwidth 1 -height 30 -relief sunken -width 30
83 scrollbar .$WinBrowse.fileframe_scr -width 10
84 # label/entry for pattern
85 label .$WinBrowse.patternLab \
86 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
87 -relief groove -text $FILTERFOLD
88 entry .$WinBrowse.patternF \
89 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
90 -textvariable BrowsePatternF
91 label .$WinBrowse.patternLabF \
92 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
93 -relief groove -text $FILTERFILES
94 entry .$WinBrowse.pattern \
95 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
96 -textvariable BrowsePattern
97 frame .$WinBrowse.fra25 \
98 -borderwidth 1 -height 30 -relief sunken -width 30
99 menubutton .$WinBrowse.fra25.men26 \
100 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
101 -menu .$WinBrowse.fra25.men26.m -padx 4 -pady 3 -relief ridge -text $VIEW
102 menu .$WinBrowse.fra25.men26.m \
103 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*
104 button .$WinBrowse.fra25.but28 \
105 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* -padx 9 \
106 -pady 3 -relief ridge -text $HELP
107 button .$WinBrowse.butOK \
108 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* -padx 9 \
109 -pady 3 -text $OK \
110 -command {destroy .$WinBrowse
111 set WAITbrowse 0
112 return "$SelectFolder $SelectFile"
114 button .$WinBrowse.butCANCEL \
115 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* -padx 9 \
116 -pady 3 -text $CANCEL \
117 -command {destroy .$WinBrowse
118 set WAITbrowse -1
119 return "$SelectFolder $SelectFile"
121 button .$WinBrowse.butRESCAN \
122 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* -padx 9 \
123 -pady 3 -text $RESCAN -command {TkW:DisplayCurrentDir $BrowsePattern}
124 ###################
125 # SETTING GEOMETRY
126 ###################
127 global YHeight;set YHeight 170
128 if {$mode !="local" && $mode != "remote"} {
129 place .$WinBrowse.foldselLab \
130 -x 47 -y 270 -width 78 -height 20 -anchor nw -bordermode ignore
131 place .$WinBrowse.foldsel \
132 -x 148 -y 268 -width 290 -height 24 -anchor nw -bordermode ignore
133 place .$WinBrowse.dirframe \
134 -x 5 -y 90 -width 145 -height $YHeight -anchor nw -bordermode ignore
135 place .$WinBrowse.dirframe_scr -x 150 -y 90 -width 17 -height $YHeight
136 place .$WinBrowse.fileframe \
137 -x 180 -y 90 -width 175 -height 170 -anchor nw -bordermode ignore
138 place .$WinBrowse.fileframe_scr -x 355 -y 90 -width 17 -height $YHeight
139 place .$WinBrowse.patternLab \
140 -x 27 -y 60 -width 143 -height 20 -anchor nw -bordermode ignore
141 place .$WinBrowse.pattern \
142 -x 190 -y 58 -width 150 -height 24 -anchor nw -bordermode ignore
143 place .$WinBrowse.patternLabF \
144 -x 27 -y 35 -width 143 -height 20 -anchor nw -bordermode ignore
145 place .$WinBrowse.patternF \
146 -x 190 -y 32 -width 150 -height 24 -anchor nw -bordermode ignore
147 place .$WinBrowse.fra25 \
148 -x 0 -y 1 -width 455 -height 25 -anchor nw -bordermode ignore
149 place .$WinBrowse.fra25.men26 \
150 -x -1 -y 0 -width 67 -height 24 -anchor nw -bordermode ignore
151 place .$WinBrowse.fra25.but28 \
152 -x 397 -y -3 -width 60 -height 28 -anchor nw -bordermode ignore
153 place .$WinBrowse.butOK \
154 -x 380 -y 115 -width 77 -height 28 -anchor nw -bordermode ignore
155 place .$WinBrowse.butCANCEL \
156 -x 380 -y 155 -width 77 -height 28 -anchor nw -bordermode ignore
157 place .$WinBrowse.butRESCAN \
158 -x 380 -y 195 -width 77 -height 28 -anchor nw -bordermode ignore
159 } else {
160 # case of ftp filebrowser ....
162 bind .$WinBrowse.pattern <Return> {.$WinBrowse.butRESCAN invoke}
163 bind .$WinBrowse.patternF <Return> {.$WinBrowse.butRESCAN invoke}
165 place .$WinBrowse.pattern -x 0 -y 3 -width 145 -height 25
166 place .$WinBrowse.patternF -x 163 -y 3 -width 145 -height 25
168 place .$WinBrowse.dirframe -x 0 -y 28 -width 145 -height $YHeight
169 place .$WinBrowse.dirframe_scr -x 145 -y 28 -width 17 -height $YHeight
170 place .$WinBrowse.fileframe -x 163 -y 28 -width 145 -height $YHeight
171 place .$WinBrowse.fileframe_scr -x 308 -y 28 -width 17 -height $YHeight
175 # binding the scrollbar:
176 bind .$WinBrowse.dirframe_scr <ButtonPress> { TkW:ScrollDirs %x %y }
177 bind .$WinBrowse.dirframe_scr <ButtonRelease> { set dirscroll no; grab release .$WinBrowse.dirframe_scr }
178 bind .$WinBrowse.dirframe_scr <Motion> { set MouseY %y }
180 bind .$WinBrowse.fileframe_scr <ButtonPress> { TkW:ScrollFiles %x %y }
181 bind .$WinBrowse.fileframe_scr <ButtonRelease> { set filescroll no; grab release .$WinBrowse.fileframe_scr }
182 bind .$WinBrowse.fileframe_scr <Motion> { set MouseY %y }
184 global TKW
185 image create photo "fold" -file \
186 $TKW/shared/icons/smalls/small_folder_yellow.gif
187 image create photo "unknown" -file \
188 $TKW/shared/icons/smalls/unknown.gif
189 image create photo "execfile" -file \
190 $TKW/shared/icons/smalls/exec.gif
191 image create photo "imgfile" -file \
192 $TKW/shared/icons/smalls/xpaint.gif
193 image create photo "htmlfile" -file \
194 $TKW/shared/icons/smalls/html.gif
195 #image create photo "up" -file $TKW/shared/icons/up.gif
196 TkW:DisplayCurrentDir $BrowsePattern
199 proc TkW:DisplayCurrentDir {BrowsePattern} {
201 global ndirs nfiles Ybase dirlist filelist FYbase specialwhere
202 global FYbase BrowsePatternF ModeBrowse
203 DestroyDirs
204 set ndirs 0
205 set dirlist ""
206 set filelist ""
208 # First we get the directory list:
210 if {$ModeBrowse != "remote"} {
211 set fileList ""
212 set fileList [glob -nocomplain [pwd]/$BrowsePattern]
213 set fileList "$fileList [glob -nocomplain [pwd]/.$BrowsePattern]"
214 set UpLevel 0
215 foreach i $fileList {
216 if {[file tail $i] == ".."} {set UpLevel 1}
217 if { [file isdir $i] } { set dirlist "$dirlist \"$i\"" }
219 set fileList ""
220 set fileList [glob -nocomplain [pwd]/$BrowsePatternF]
221 set fileList "$fileList [glob -nocomplain [pwd]/.$BrowsePatternF]"
222 foreach i $fileList {
223 if { ![file isdir $i] } { set filelist "$filelist \"$i\"" }
225 if {$UpLevel == 0} {set dirlist ".. $dirlist"}
226 set dirlist [lsort $dirlist]
227 set filelist [lsort $filelist]
228 } else {set filelist ""; set dirlist ".."}
229 set Ybase 5
230 set FYbase 5
231 TkW:ShowDirs
232 TkW:ShowFiles
235 proc TkW:ShowDirs {} {
236 global dirlist ndirs
237 DestroyDirs
238 set ndirs 0
239 set showedIn 0
240 set showedbelow 0
241 set showedabove 0
242 foreach i $dirlist {
243 set inout [TkW:showdir $i]
244 if {$inout == 0} {set showedIn [expr $showedIn + 1]}
245 if {$inout == -1} {set showedabove [expr $showedabove + 1]}
246 if {$inout == 1} {set showedbelow [expr $showedbelow + 1]}
248 # Scrollbars management:
249 TkW:DirBrowseScroll [expr (100.*$showedabove/$ndirs)/100.] \
250 [expr 1. - (100.*$showedbelow/$ndirs)/100.]
251 update
254 proc TkW:DirBrowseScroll { y1 y2} {
255 global SliderY1 SliderY2 WinBrowse
256 set SliderY1 $y1
257 set SliderY2 $y2
258 .$WinBrowse.dirframe_scr set $y1 $y2
260 proc TkW:FileBrowseScroll { y1 y2} {
261 global FSliderY1 FSliderY2 WinBrowse
262 set FSliderY1 $y1
263 set FSliderY2 $y2
264 .$WinBrowse.fileframe_scr set $y1 $y2
266 proc TkW:hilightFold {y} {
268 global YDIRS ndirs DIRS SelectNum WinBrowse
269 global SelectFolder BrowsePattern FTPcd
271 if { $y > $YDIRS($ndirs)} {set num $ndirs} else {
272 set i 1
273 set ok 0
274 while {$ok == 0} {
275 if {
276 $YDIRS($i) < $y &&\
277 $y <= $YDIRS([expr $i + 1])} {
278 set num $i
279 set ok 1
280 } else { set i [expr $i + 1] }
285 if {$SelectFolder == $DIRS($num)} {
286 cd $SelectFolder
287 if {$FTPcd == 1} {FTP_Lcd $SelectFolder}
288 set SelectFolder [pwd]
289 TkW:DisplayCurrentDir $BrowsePattern
290 unset SelectNum
291 } else {
292 .$WinBrowse.dirframe.label$num configure -background #ffffff
293 set SelectFolder $DIRS($num)
294 if {[info exists SelectNum]} {
295 .$WinBrowse.dirframe.label$SelectNum configure \
296 -background #dddddd
298 set SelectNum $num
301 update
304 proc TkW:showdir {fulldirname} {
305 global TKW ndirs Ybase YHeight YDIRS DIRS Ydecal ModeBrowse WinBrowse
306 set Ydecal 20
307 set dirname [file tail $fulldirname]
308 if {$dirname == "."} return
309 set Y [expr $Ybase + $ndirs * $Ydecal]
310 set In 0
311 if {$Y < 0 } {set In -1}
312 if {$Y > [expr $YHeight - $Ydecal]} { set In 1 }
315 set ndirs [expr $ndirs + 1]
316 set YDIRS($ndirs) $Y
317 set DIRS($ndirs) $fulldirname
318 label .$WinBrowse.dirframe.icon$ndirs -image fold
319 label .$WinBrowse.dirframe.label$ndirs -text $dirname\
320 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*
322 if {$In == 0} {
323 place .$WinBrowse.dirframe.icon$ndirs -x 5 -y $Y
324 place .$WinBrowse.dirframe.label$ndirs -x 30 -y $Y
327 #dirframe bindings
328 bind .$WinBrowse.dirframe.icon$ndirs <Button-1> {
329 set Y [expr %Y - [winfo rooty .$WinBrowse.dirframe] -$Ybase]
330 TkW:hilightFold $Y
332 #dirframe bindings
333 bind .$WinBrowse.dirframe.label$ndirs <ButtonPress-1> {
334 set Y [expr %Y - [winfo rooty .$WinBrowse.dirframe] -$Ybase]
335 TkW:hilightFold $Y
337 return $In
340 proc TkW:ScrollDirs {X Y} {
342 global Ybase Ydecal ndirs dirscroll global nextLoop MouseY WinBrowse
343 global SliderY1 SliderY2 YHeight Nabove Nbelow
345 set MinBase [expr -$Ydecal * ($ndirs - [expr $YHeight/$Ydecal])]
346 set Slider1 $SliderY1
347 set Slider2 $SliderY2
348 set MaxSlide1 [expr 1-($SliderY2-$SliderY1)]
349 set MinSlide2 [expr $SliderY2-$SliderY1]
350 switch [.$WinBrowse.dirframe_scr identify $X $Y] {
352 {arrow1} { set dirscroll UP; set modeUP 1}
353 {arrow2} { set dirscroll DOWN;set modeDOWN 1}
354 {slider} {set dirscroll SLIDER}
355 {trough1} {set dirscroll UP; set modeUP page}
356 {trough2} {set dirscroll DOWN;set modeDOWN page}
358 while {$dirscroll == "UP"} {
359 if {$modeUP == "1"} {set XUP 1} {
360 set XUP [expr ($YHeight/$Ydecal ) -1]
362 set Ybase [expr $Ybase + $XUP * $Ydecal]
363 if {$Ybase > $Ydecal} {
364 set Ybase 5
365 set dirscroll no
366 set Slider1 0
367 set Slider2 $MinSlide2
369 TkW:ReShowDirs
370 TkW:DirBrowseScroll [expr (100.*$Nabove/$ndirs)/100.] \
371 [expr 1. - (100.*$Nbelow/$ndirs)/100.]
372 set nextLoop 0
373 after 30 {set nextLoop 1}
374 while {$nextLoop == 0} {update}
375 set Slider1 $SliderY1
376 set Slider2 $SliderY2
378 while {$dirscroll == "DOWN"} {
379 if {$modeDOWN == "1"} {set XDOWN 1} {
380 set XDOWN [expr ($YHeight/$Ydecal ) -1]
382 set Ybase [expr $Ybase - $XDOWN * $Ydecal]
383 if {$Ybase < $MinBase} {
384 set Ybase $MinBase
385 set dirscroll no
386 set Slider2 1
387 set Slider1 $MaxSlide1
389 TkW:ReShowDirs
390 TkW:DirBrowseScroll [expr (100.*$Nabove/$ndirs)/100.] \
391 [expr 1. - (100.*$Nbelow/$ndirs)/100.]
392 set nextLoop 0
393 after 30 {set nextLoop 1}
394 while {$nextLoop == 0} {update}
395 set Slider1 $SliderY1
396 set Slider2 $SliderY2
398 while {$dirscroll == "SLIDER"} {
399 set nextLoop 0
400 after 20 {set nextLoop 1}
401 while {$nextLoop == 0} {
402 set Delta [expr (100.*($MouseY - $Y)/$YHeight)/100. ]
403 set Slider1 [expr $SliderY1 +$Delta]
404 set Slider2 [expr $SliderY2 +$Delta]
405 if {$Slider2 > 1} {
406 set Slider2 1
407 set Slider1 $MaxSlide1
409 if {$Slider1 < 0} {
410 set Slider1 0
411 set Slider2 $MinSlide2
413 .$WinBrowse.dirframe_scr set $Slider1 $Slider2
414 set Ybase [expr 5 - $Slider1 * $ndirs *$Ydecal]
415 TkW:ReShowDirs
416 update
419 set SliderY1 $Slider1
420 set SliderY2 $Slider2
422 proc TkW:ScrollFiles {X Y} {
424 global FYbase Ydecal nfiles filescroll nextLoop MouseY WinBrowse
425 global FSliderY1 FSliderY2 YHeight NFabove NFbelow
427 set MinBase [expr -$Ydecal * ($nfiles - [expr $YHeight/$Ydecal])]
428 set FSlider1 $FSliderY1
429 set FSlider2 $FSliderY2
430 set MaxSlide1 [expr 1-($FSliderY2-$FSliderY1)]
431 set MinSlide2 [expr $FSliderY2-$FSliderY1]
432 switch [.$WinBrowse.fileframe_scr identify $X $Y] {
434 {arrow1} { set filescroll UP; set modeUP 1}
435 {arrow2} { set filescroll DOWN;set modeDOWN 1}
436 {slider} {set filescroll SLIDER}
437 {trough1} {set filescroll UP; set modeUP page}
438 {trough2} {set filescroll DOWN;set modeDOWN page}
440 while {$filescroll == "UP"} {
441 if {$modeUP == "1"} {set XUP 1} {
442 set XUP [expr ($YHeight/$Ydecal ) -1]
444 set FYbase [expr $FYbase + $XUP * $Ydecal]
445 if {$FYbase > $Ydecal} {
446 set FYbase 5
447 set filescroll no
448 set FSlider1 0
449 set FSlider2 $MinSlide2
451 TkW:ReShowFiles
452 if {$nfiles != 0} {
453 TkW:FileBrowseScroll [expr (100.*$NFabove/$nfiles)/100.] \
454 [expr 1. - (100.*$NFbelow/$nfiles)/100.]
455 } else {
456 TkW:FileBrowseScroll 0 1
458 set nextLoop 0
459 after 30 {set nextLoop 1}
460 while {$nextLoop == 0} {update}
461 set FSlider1 $FSliderY1
462 set FSlider2 $FSliderY2
464 while {$filescroll == "DOWN"} {
465 if {$modeDOWN == "1"} {set XDOWN 1} {
466 set XDOWN [expr ($YHeight/$Ydecal ) -1]
468 set FYbase [expr $FYbase - $XDOWN * $Ydecal]
469 if {$FYbase < $MinBase} {
470 set FYbase $MinBase
471 set filescroll no
472 set FSlider2 1
473 set FSlider1 $MaxSlide1
475 TkW:ReShowFiles
476 if {$nfiles != 0} {
477 TkW:FileBrowseScroll [expr (100.*$NFabove/$nfiles)/100.] \
478 [expr 1. - (100.*$NFbelow/$nfiles)/100.]
479 } else {
480 TkW:FileBrowseScroll 0 1
482 set nextLoop 0
483 after 30 {set nextLoop 1}
484 while {$nextLoop == 0} {update}
485 set FSlider1 $FSliderY1
486 set FSlider2 $FSliderY2
488 while {$filescroll == "SLIDER"} {
489 set nextLoop 0
490 after 20 {set nextLoop 1}
491 while {$nextLoop == 0} {
492 set Delta [expr (100.*($MouseY - $Y)/$YHeight)/100. ]
493 set FSlider1 [expr $FSliderY1 +$Delta]
494 set FSlider2 [expr $FSliderY2 +$Delta]
495 if {$FSlider2 > 1} {
496 set FSlider2 1
497 set FSlider1 $MaxSlide1
499 if {$FSlider1 < 0} {
500 set FSlider1 0
501 set FSlider2 $MinSlide2
503 .$WinBrowse.fileframe_scr set $FSlider1 $FSlider2
504 set FYbase [expr 5 - $FSlider1 * $nfiles *$Ydecal]
505 TkW:ReShowFiles
506 update
509 set FSliderY1 $FSlider1
510 set FSliderY2 $FSlider2
513 proc TkW:ReShowDirs {} {
514 global dirlist Ybase Ydecal ndirs YHeight WinBrowse
515 global Nabove Nbelow
516 set n 0
517 set Nabove 0
518 set Nbelow 0
519 foreach i $dirlist {
520 set dirname [file tail $i]
521 if {$dirname != "."} {
522 set Y0 [expr $Ybase + $n * $Ydecal]
523 if {$Y0 < -5} {set Nabove [expr $Nabove + 1]}
524 if {$Y0 > [expr $YHeight - $Ydecal]} { set Nbelow [expr $Nbelow + 1]}
525 set n [expr $n + 1]
526 place .$WinBrowse.dirframe.icon$n -x 5 -y $Y0
527 place .$WinBrowse.dirframe.label$n -x 30 -y $Y0
531 proc TkW:ReShowFiles {} {
532 global filelist FYbase Ydecal nfiles YHeight WinBrowse
533 global NFabove NFbelow
534 set n 0
535 set NFabove 0
536 set NFbelow 0
537 foreach i $filelist {
538 set filename [file tail $i]
539 if {$filename != "."} {
540 set Y0 [expr $FYbase + $n * $Ydecal]
541 if {$Y0 < -5} {set NFabove [expr $NFabove + 1]}
542 if {$Y0 > [expr $YHeight - $Ydecal]} { set NFbelow [expr $NFbelow + 1]}
543 set n [expr $n + 1]
544 place .$WinBrowse.fileframe.icon$n -x 5 -y $Y0
545 place .$WinBrowse.fileframe.label$n -x 30 -y $Y0
550 proc TkW:ShowFiles {} {
551 global filelist nfiles
552 DestroyFiles
553 set nfiles 0
554 set FshowedIn 0
555 set NFbelow 0
556 set NFabove 0
557 foreach i $filelist {
558 set inout [TkW:showfile $i]
559 if {$inout == 0} {set FshowedIn [expr $FshowedIn + 1]}
560 if {$inout == -1} {set NFabove [expr $NFabove + 1]}
561 if {$inout == 1} {set NFbelow [expr $NFbelow + 1]}
563 # Scrollbar management:
564 if {$nfiles != 0} {
565 TkW:FileBrowseScroll [expr (100.*$NFabove/$nfiles)/100.] \
566 [expr 1. - (100.*$NFbelow/$nfiles)/100.]
567 } else {
568 TkW:FileBrowseScroll 0 1
572 proc TkW:showfile {fullfilename} {
573 global TKW nfiles FYbase YHeight YFILES Ydecal FILES
574 set Y [expr $FYbase + $nfiles * $Ydecal]
575 set In 0
576 if {$Y < 0 } {set In -1}
577 if {$Y > [expr $YHeight - $Ydecal]} { set In 1 }
580 set nfiles [expr $nfiles + 1]
581 set YFILES($nfiles) $Y
582 set FILES($nfiles) $fullfilename
583 createPlaceFileIcon $nfiles $Y
584 return $In
586 proc createPlaceFileIcon {n Y} {
587 global FILES ModeBrowse WinBrowse
588 set fullfilename $FILES($n)
589 set icon unknown
590 if {[file executable $fullfilename]} {set icon execfile}
591 if {[file extension $fullfilename] == ".html"} {set icon htmlfile}
592 if {[file extension $fullfilename] == ".htm"} {set icon htmlfile}
593 if {[file extension $fullfilename] == ".gif"} {set icon imgfile}
594 if {[file extension $fullfilename] == ".jpg"} {set icon imgfile}
595 set filename [file tail $fullfilename]
596 label .$WinBrowse.fileframe.icon$n -image $icon
597 label .$WinBrowse.fileframe.label$n -text $filename\
598 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*\
599 -background #dddddd
601 place .$WinBrowse.fileframe.icon$n -x 5 -y $Y
602 place .$WinBrowse.fileframe.label$n -x 30 -y $Y
604 if {$ModeBrowse == "File"} {
605 #fileframe bindings
606 bind .$WinBrowse.fileframe.icon$n <Button-1> {
607 set Y [expr %Y - [winfo rooty .$WinBrowse.fileframe] -$FYbase]
608 TkW:hilightFile $Y
610 bind .$WinBrowse.fileframe.icon$n <Double-Button-1> {
611 destroy .$WinBrowse
612 set WAITbrowse 0
613 return "$SelectFolder $SelectFile"
615 #fileframe bindings
616 bind .$WinBrowse.fileframe.label$n <ButtonPress-1> {
617 set Y [expr %Y - [winfo rooty .$WinBrowse.fileframe] -$FYbase]
618 TkW:hilightFile $Y
620 bind .$WinBrowse.fileframe.label$n <Double-Button-1> {
621 destroy .$WinBrowse
622 set WAITbrowse 0
623 return "$SelectFolder $SelectFile"
628 proc DestroyDirs {} {
629 global ndirs WinBrowse
631 for {set i 1} {$i <= $ndirs} {set i [expr $i + 1 ]} {
632 if {[winfo exists .$WinBrowse.dirframe.icon$i]} {
633 destroy .$WinBrowse.dirframe.icon$i
634 destroy .$WinBrowse.dirframe.label$i
638 proc DestroyFiles {} {
639 global nfiles WinBrowse
641 for {set i 1} {$i <= $nfiles} {set i [expr $i + 1 ]} {
642 if {[winfo exists .$WinBrowse.fileframe.icon$i]} {
643 destroy .$WinBrowse.fileframe.icon$i
644 destroy .$WinBrowse.fileframe.label$i
649 proc TkW:hilightFile {y} {
651 global YFILES nfiles FILES SelectNumF WinBrowse
652 global SelectFile BrowsePattern
654 if { $y > $YFILES($nfiles)} {set num $nfiles} else {
655 set i 1
656 set ok 0
657 while {$ok == 0} {
658 if {
659 $YFILES($i) < $y &&\
660 $y <= $YFILES([expr $i + 1])} {
661 set num $i
662 set ok 1
663 } else { set i [expr $i + 1] }
668 if {$SelectFile == $FILES($num)} {
669 return
670 } else {
671 .$WinBrowse.fileframe.label$num configure -background #ffffff
672 set SelectFile $FILES($num)
673 if {[info exists SelectNumF]} {
674 .$WinBrowse.fileframe.label$SelectNumF configure -background #dddddd
676 set SelectNumF $num
679 update