#!/usr/local/wish -f
# Program: xfpixmap
# Tcl version: 6.6 (Tcl/Tk/XF)
# Tk version: 3.1
# XF version: $__lastrelease$
#


# procedure to show window ShowWindow.top0
proc ShowWindow.top0 { args} {
# xf ignore me 7

  # build widget .top0
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy .top0"
  } {
    catch "destroy .top0"
  }
  toplevel .top0 

  # Window manager configurations
  global tkVersion
  wm positionfrom .top0 ""
  wm sizefrom .top0 ""
  wm geometry .top0 314x252
  wm maxsize .top0 1000 1000
  wm minsize .top0 10 10
  wm title .top0 {tkxpm: picture list}


  # build widget .top0.frame
  frame .top0.frame     -relief {raised}

  # build widget .top0.frame.scrollbar1
  scrollbar .top0.frame.scrollbar1     -command {.top0.frame.canvas2 yview}    -relief {raised}

  # build widget .top0.frame.scrollbar3
  scrollbar .top0.frame.scrollbar3     -command {.top0.frame.canvas2 xview}    -orient {horizontal}    -relief {raised}

  # build widget .top0.frame.canvas2
  canvas .top0.frame.canvas2     -height {207}    -insertofftime {600}    -relief {raised}    -scrollregion {0c 0c 20c 60c}    -width {295}    -xscrollcommand {.top0.frame.scrollbar3 set}    -yscrollcommand {.top0.frame.scrollbar1 set}
  # build canvas items .top0.frame.canvas2
  # bindings
  bind .top0.frame.canvas2 <Button-1> {
    global fileNames
    global pictureCounter
    set selTag [lindex [%W gettags [%W find closest [%W canvasx %x] [%W canvasy %y]]] 0]
    if {"$selTag" != ""} {
      set pictureCounter [lsearch $fileNames $selTag]
      LoadFile $selTag
    }} 


  # pack widget .top0.frame
  pack append .top0.frame     .top0.frame.scrollbar1 {right frame center filly}     .top0.frame.canvas2 {top frame center expand fill}     .top0.frame.scrollbar3 {top frame center fillx} 

  # build widget .top0.frame1
  frame .top0.frame1     -borderwidth {2}    -relief {raised}

  # build widget .top0.frame1.menubutton0
  menubutton .top0.frame1.menubutton0     -menu {.top0.frame1.menubutton0.m}    -text {Misc}    -underline {0}

  # build widget .top0.frame1.menubutton0.m
  menu .top0.frame1.menubutton0.m 
  .top0.frame1.menubutton0.m add command    -command {NextPic}    -label {Next}    -underline {0}
  .top0.frame1.menubutton0.m add command    -command {PreviousPic}    -label {Previous}    -underline {0}
  .top0.frame1.menubutton0.m add separator
  .top0.frame1.menubutton0.m add command    -command {UpdateCurrentPixmap}    -label {Update}    -underline {0}
  .top0.frame1.menubutton0.m add separator
  .top0.frame1.menubutton0.m add command    -command {DestroyWindow.top0}    -label {Remove window}    -underline {0}

  # pack widget .top0.frame1
  pack append .top0.frame1     .top0.frame1.menubutton0 {left frame center} 

  # pack widget .top0
  pack append .top0     .top0.frame1 {top frame center fillx}     .top0.frame {top frame center expand fill} 

  if {"[info procs XFEdit]" != ""} {
    XFEditSetShowWindows
    XFMiscBindWidgetTree .top0
  }

  global tkVersion
  if {$tkVersion >= 3.0} {
    tk_menuBar .top0.frame1 .top0.frame1.menubutton0
  } {
    tk_menus .top0 .top0.frame1.menubutton0
  }
}

proc DestroyWindow.top0 {} {# xf ignore me 7
  if {"[info procs XFEdit]" != ""} {
    if {"[info commands .top0]" != ""} {
      global xfShowWindow.top0
      set xfShowWindow.top0 0
      XFEditSetPath .
      after 200 "XFSaveAsProc .top0; XFEditSetShowWindows"
    }
  } {
    catch "destroy .top0"
    update
  }
}


# procedure to show window .
proc ShowWindow. {args} {# xf ignore me 7

  # Window manager configurations
  global tkVersion
  wm positionfrom . user
  wm sizefrom . ""
  wm geometry . 424x480
  wm maxsize . 1024 1024
  wm minsize . 0 0
  wm title . {tkxpm: tkxpm.xpm}


  # build widget .frame
  frame .frame \
    -relief {raised}

  # build widget .frame.scrollbar1
  scrollbar .frame.scrollbar1 \
    -command {.frame.canvas2 yview} \
    -relief {raised}

  # build widget .frame.scrollbar3
  scrollbar .frame.scrollbar3 \
    -command {.frame.canvas2 xview} \
    -orient {horizontal} \
    -relief {raised}

  # build widget .frame.canvas2
  canvas .frame.canvas2 \
    -height {207} \
    -insertofftime {600} \
    -relief {raised} \
    -scrollregion {0c 0c 40c 40c} \
    -width {295} \
    -xscrollcommand {.frame.scrollbar3 set} \
    -yscrollcommand {.frame.scrollbar1 set}
  # build canvas items .frame.canvas2
  set xfTmpTag [.frame.canvas2 create rectangle 2 2 12 12]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel0-0} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 12 2 22 12]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel0-1} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 22 2 32 12]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel0-2} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 32 2 42 12]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel0-3} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 2 12 12 22]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel1-0} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 12 12 22 22]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel1-1} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 22 12 32 22]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel1-2} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 32 12 42 22]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel1-3} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 2 22 12 32]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel2-0} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 12 22 22 32]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel2-1} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 22 22 32 32]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel2-2} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 32 22 42 32]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel2-3} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 2 32 12 42]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel3-0} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 12 32 22 42]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel3-1} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 22 32 32 42]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel3-2} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 32 32 42 42]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel3-3} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 42 2 52 12]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel0-4} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 52 2 62 12]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel0-5} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 62 2 72 12]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel0-6} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 72 2 82 12]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel0-7} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 82 2 92 12]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel0-8} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 92 2 102 12]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel0-9} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 42 12 52 22]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel1-4} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 52 12 62 22]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel1-5} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 62 12 72 22]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel1-6} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 72 12 82 22]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel1-7} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 82 12 92 22]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel1-8} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 92 12 102 22]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel1-9} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 42 22 52 32]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel2-4} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 52 22 62 32]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel2-5} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 62 22 72 32]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel2-6} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 72 22 82 32]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel2-7} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 82 22 92 32]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel2-8} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 92 22 102 32]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel2-9} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 42 32 52 42]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel3-4} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 52 32 62 42]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel3-5} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 62 32 72 42]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel3-6} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 72 32 82 42]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel3-7} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 82 32 92 42]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel3-8} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 92 32 102 42]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel3-9} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 42 42 52 52]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel4-4} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 52 42 62 52]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel4-5} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 62 42 72 52]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel4-6} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 72 42 82 52]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel4-7} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 82 42 92 52]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel4-8} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 92 42 102 52]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel4-9} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 42 52 52 62]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel5-4} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 52 52 62 62]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel5-5} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 62 52 72 62]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel5-6} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 72 52 82 62]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel5-7} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 82 52 92 62]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel5-8} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 92 52 102 62]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel5-9} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 42 62 52 72]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel6-4} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 52 62 62 72]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel6-5} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 62 62 72 72]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel6-6} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 72 62 82 72]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel6-7} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 82 62 92 72]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel6-8} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 92 62 102 72]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel6-9} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 42 72 52 82]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel7-4} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 52 72 62 82]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel7-5} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 62 72 72 82]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel7-6} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 72 72 82 82]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel7-7} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 82 72 92 82]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel7-8} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 92 72 102 82]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel7-9} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 42 82 52 92]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel8-4} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 52 82 62 92]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel8-5} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 62 82 72 92]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel8-6} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 72 82 82 92]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel8-7} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 82 82 92 92]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel8-8} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 92 82 102 92]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel8-9} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 42 92 52 102]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel9-4} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 52 92 62 102]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel9-5} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 62 92 72 102]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel9-6} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 72 92 82 102]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel9-7} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 82 92 92 102]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel9-8} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 92 92 102 102]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel9-9} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 2 42 12 52]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel4-0} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 12 42 22 52]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel4-1} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 22 42 32 52]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel4-2} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 32 42 42 52]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel4-3} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 2 52 12 62]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel5-0} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 12 52 22 62]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel5-1} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 22 52 32 62]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel5-2} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 32 52 42 62]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel5-3} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 2 62 12 72]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel6-0} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 12 62 22 72]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel6-1} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 22 62 32 72]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel6-2} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 32 62 42 72]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel6-3} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 2 72 12 82]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel7-0} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 12 72 22 82]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel7-1} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 22 72 32 82]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel7-2} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 32 72 42 82]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel7-3} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 2 82 12 92]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel8-0} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 12 82 22 92]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel8-1} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 22 82 32 92]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel8-2} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 32 82 42 92]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel8-3} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 2 92 12 102]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel9-0} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 12 92 22 102]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel9-1} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 22 92 32 102]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel9-2} \
    -width {0}
  set xfTmpTag [.frame.canvas2 create rectangle 32 92 42 102]
  .frame.canvas2 itemconfigure $xfTmpTag \
    -fill {#3abdbc} \
    -tags {pixel9-3} \
    -width {0}
  # bindings
  bind .frame.canvas2 <B1-Motion> {
    global currentColor
    set selTag [lindex [%W gettags [%W find closest [%W canvasx %x] [%W canvasy %y]]] 0]
    %W itemconfig $selTag -fill "$currentColor"}
  bind .frame.canvas2 <B2-Motion> {
    global currentTransparentColor
    set selTag [lindex [%W gettags [%W find closest [%W canvasx %x] [%W canvasy %y]]] 0]
    %W itemconfig $selTag -fill "$currentTransparentColor"}
  bind .frame.canvas2 <Button-1> {
    global currentColor
    global fillMode
    set selTag [lindex [%W gettags [%W find closest [%W canvasx %x] [%W canvasy %y]]] 0]
    if {$fillMode == 0} {
      %W itemconfig $selTag -fill "$currentColor"
    } {
      Fill %W $selTag}}
  bind .frame.canvas2 <Button-2> {
    global currentTransparentColor
    set selTag [lindex [%W gettags [%W find closest [%W canvasx %x] [%W canvasy %y]]] 0]
    %W itemconfig $selTag -fill "$currentTransparentColor"}
  bind .frame.canvas2 <Button-3> {
    global currentColor
    global currentColorButton
    set selTag [lindex [%W gettags [%W find closest [%W canvasx %x] [%W canvasy %y]]] 0]
    set currentColor [lindex [%W itemconfig $selTag -fill] 4]
    for {set counter 0} {$counter < 36} {incr counter} {
      if {"$currentColor" != "[lindex [[SymbolicName Color$counter] config -foreground] 4]"} {
        set currentColorButton $counter
        .frame1.frame5.label0 config -foreground $currentColor
      }
    }}
  bind .frame.canvas2 <Shift-Button-1> {
    global currentColor
    global currentColorButton
    if {$currentColorButton == 35} {
      set currentColorButton 0
    } {
      incr currentColorButton
    }
    set currentColor [lindex [[SymbolicName Color$currentColorButton] config -foreground] 4]
    set selTag [lindex [%W gettags [%W find closest [%W canvasx %x] [%W canvasy %y]]] 0]
    %W itemconfig $selTag -fill "$currentColor"
    .frame1.frame5.label0 config -foreground $currentColor}

  # pack widget .frame
  pack append .frame \
    .frame.scrollbar1 {right frame center filly} \
    .frame.canvas2 {top frame center expand fill} \
    .frame.scrollbar3 {top frame center fillx} 

  # build widget .frame0
  frame .frame0 \
    -borderwidth {2} \
    -relief {raised}

  # build widget .frame0.menubutton2
  menubutton .frame0.menubutton2 \
    -menu {.frame0.menubutton2.m} \
    -text {File} \
    -underline {0}

  # build widget .frame0.menubutton2.m
  menu .frame0.menubutton2.m 
  .frame0.menubutton2.m add command \
    -command {set loadFile [FSBox]
if {"$loadFile" != ""} {
  LoadFile $loadFile
}} \
    -label {Load...} \
    -underline {0}
  .frame0.menubutton2.m add command \
    -command {global fileName
if {"$fileName" != ""} {
  SaveFile $fileName
} {
  AlertBox {No filename specified}
}} \
    -label {Save} \
    -underline {0}
  .frame0.menubutton2.m add command \
    -command {global fileName
set saveFile [FSBox]
if {"$saveFile" != ""} {
  set fileName $saveFile
  wm title . "tkxpm: $fileName"
  SaveFile $fileName
}} \
    -label {Save as...} \
    -underline {5}
  .frame0.menubutton2.m add separator
  .frame0.menubutton2.m add command \
    -command {ShowWindow.top0
SetPictures
UpdateCurrentPixmap} \
    -label {Picture list} \
    -underline {0}
  .frame0.menubutton2.m add separator
  .frame0.menubutton2.m add command \
    -command {
QuitProgram} \
    -label {Quit} \
    -underline {0}

  # build widget .frame0.menubutton3
  menubutton .frame0.menubutton3 \
    -menu {.frame0.menubutton3.m} \
    -text {Options} \
    -underline {0}

  # build widget .frame0.menubutton3.m
  menu .frame0.menubutton3.m 
  .frame0.menubutton3.m add checkbutton \
    -label {One picture} \
    -variable {onePicture}

  # pack widget .frame0
  pack append .frame0 \
    .frame0.menubutton2 {left frame center} \
    .frame0.menubutton3 {left frame center} 

  # build widget .frame1
  frame .frame1 \
    -borderwidth {2} \
    -relief {raised}

  # build widget .frame1.frame0
  frame .frame1.frame0 \
    -borderwidth {2} \
    -relief {sunken}

  # build widget .frame1.frame0.frame1
  frame .frame1.frame0.frame1 \
    -relief {raised}

  # build widget .frame1.frame0.frame1.button4
  button .frame1.frame0.frame1.button4 \
    -bitmap {@Button01} \
    -command {ChangeArea 1} \
    -height {17} \
    -text {} \
    -width {17}

  # build widget .frame1.frame0.frame1.button5
  button .frame1.frame0.frame1.button5 \
    -bitmap {@Button02} \
    -command {ChangeArea 2} \
    -height {17} \
    -text {} \
    -width {17}

  # build widget .frame1.frame0.frame1.button6
  button .frame1.frame0.frame1.button6 \
    -bitmap {@Button03} \
    -command {ChangeArea 3} \
    -height {17} \
    -text {} \
    -width {17}

  # pack widget .frame1.frame0.frame1
  pack append .frame1.frame0.frame1 \
    .frame1.frame0.frame1.button4 {left frame center padx 3 pady 3 expand fill} \
    .frame1.frame0.frame1.button5 {left frame center padx 3 pady 3 expand fill} \
    .frame1.frame0.frame1.button6 {left frame center padx 3 pady 3 expand fill} 

  # build widget .frame1.frame0.frame2
  frame .frame1.frame0.frame2 \
    -relief {raised}

  # build widget .frame1.frame0.frame2.button7
  button .frame1.frame0.frame2.button7 \
    -bitmap {@Button04} \
    -command {ChangeArea 4} \
    -height {17} \
    -text {} \
    -width {17}

  # build widget .frame1.frame0.frame2.button8
  button .frame1.frame0.frame2.button8 \
    -bitmap {@Button05} \
    -command {ChangeArea 5} \
    -height {17} \
    -text {} \
    -width {17}

  # build widget .frame1.frame0.frame2.button9
  button .frame1.frame0.frame2.button9 \
    -bitmap {@Button06} \
    -command {ChangeArea 6} \
    -height {17} \
    -text {} \
    -width {17}

  # pack widget .frame1.frame0.frame2
  pack append .frame1.frame0.frame2 \
    .frame1.frame0.frame2.button7 {left frame center padx 3 pady 3 expand fill} \
    .frame1.frame0.frame2.button8 {left frame center padx 3 pady 3 expand fill} \
    .frame1.frame0.frame2.button9 {left frame center padx 3 pady 3 expand fill} 

  # build widget .frame1.frame0.frame3
  frame .frame1.frame0.frame3 \
    -relief {raised}

  # build widget .frame1.frame0.frame3.button10
  button .frame1.frame0.frame3.button10 \
    -bitmap {@Button07} \
    -command {ChangeArea 7} \
    -height {17} \
    -text {} \
    -width {17}

  # build widget .frame1.frame0.frame3.button11
  button .frame1.frame0.frame3.button11 \
    -bitmap {@Button08} \
    -command {ChangeArea 8} \
    -height {17} \
    -text {} \
    -width {17}

  # build widget .frame1.frame0.frame3.button12
  button .frame1.frame0.frame3.button12 \
    -bitmap {@Button09} \
    -command {ChangeArea 9} \
    -height {17} \
    -text {} \
    -width {17}

  # pack widget .frame1.frame0.frame3
  pack append .frame1.frame0.frame3 \
    .frame1.frame0.frame3.button10 {left frame center padx 3 pady 3 expand fill} \
    .frame1.frame0.frame3.button11 {left frame center padx 3 pady 3 expand fill} \
    .frame1.frame0.frame3.button12 {left frame center padx 3 pady 3 expand fill} 

  # pack widget .frame1.frame0
  pack append .frame1.frame0 \
    .frame1.frame0.frame1 {top frame center expand fill} \
    .frame1.frame0.frame2 {top frame center expand fill} \
    .frame1.frame0.frame3 {top frame center expand fill} 

  # build widget .frame1.frame1
  frame .frame1.frame1 \
    -borderwidth {2} \
    -relief {sunken}

  # build widget .frame1.frame1.button4
  button .frame1.frame1.button4 \
    -command {ClearArea} \
    -text {Clear}

  # build widget .frame1.frame1.button5
  checkbutton .frame1.frame1.button5 \
    -text {Fill} \
    -variable {fillMode}

  # pack widget .frame1.frame1
  pack append .frame1.frame1 \
    .frame1.frame1.button4 {top frame center fillx} \
    .frame1.frame1.button5 {top frame center fillx} 

  # build widget .frame1.frame3
  frame .frame1.frame3 \
    -borderwidth {2} \
    -relief {sunken}

  # build widget .frame1.frame3.button4
  button .frame1.frame3.button4 \
    -command {SetRaster} \
    -text {Set raster}

  # build widget .frame1.frame3.scale6
  scale .frame1.frame3.scale6 \
    -from {4} \
    -label {Width:} \
    -length {79} \
    -orient {horizontal} \
    -relief {raised} \
    -sliderlength {14} \
    -width {8}
  # bindings
  bind .frame1.frame3.scale6 <Key-Down> {.frame1.frame3.scale6 set [expr [.frame1.frame3.scale6 get]-1]}
  bind .frame1.frame3.scale6 <Key-Left> {.frame1.frame3.scale6 set [expr [.frame1.frame3.scale6 get]-1]}
  bind .frame1.frame3.scale6 <Key-Next> {.frame1.frame3.scale6 set [expr [.frame1.frame3.scale6 get]+10]}
  bind .frame1.frame3.scale6 <Key-Prior> {.frame1.frame3.scale6 set [expr [.frame1.frame3.scale6 get]-10]}
  bind .frame1.frame3.scale6 <Key-Right> {.frame1.frame3.scale6 set [expr [.frame1.frame3.scale6 get]+1]}
  bind .frame1.frame3.scale6 <Key-Up> {.frame1.frame3.scale6 set [expr [.frame1.frame3.scale6 get]+1]}
  bind .frame1.frame3.scale6 <Shift-Button-1> {focus .frame1.frame3.scale6}

  # build widget .frame1.frame3.scale7
  scale .frame1.frame3.scale7 \
    -from {4} \
    -label {Height:} \
    -length {71} \
    -orient {horizontal} \
    -relief {raised} \
    -sliderlength {14} \
    -width {8}
  # bindings
  bind .frame1.frame3.scale7 <Key-Down> {.frame1.frame3.scale7 set [expr [.frame1.frame3.scale7 get]-1]}
  bind .frame1.frame3.scale7 <Key-Left> {.frame1.frame3.scale7 set [expr [.frame1.frame3.scale7 get]-1]}
  bind .frame1.frame3.scale7 <Key-Next> {.frame1.frame3.scale7 set [expr [.frame1.frame3.scale7 get]+10]}
  bind .frame1.frame3.scale7 <Key-Prior> {.frame1.frame3.scale7 set [expr [.frame1.frame3.scale7 get]-10]}
  bind .frame1.frame3.scale7 <Key-Right> {.frame1.frame3.scale7 set [expr [.frame1.frame3.scale7 get]+1]}
  bind .frame1.frame3.scale7 <Key-Up> {.frame1.frame3.scale7 set [expr [.frame1.frame3.scale7 get]+1]}
  bind .frame1.frame3.scale7 <Shift-Button-1> {focus .frame1.frame3.scale7}

  # build widget .frame1.frame3.scale8
  scale .frame1.frame3.scale8 \
    -from {1} \
    -label {Size:} \
    -length {50} \
    -orient {horizontal} \
    -relief {raised} \
    -sliderlength {14} \
    -to {30} \
    -width {8}
  # bindings
  bind .frame1.frame3.scale8 <Key-Down> {.frame1.frame3.scale8 set [expr [.frame1.frame3.scale8 get]-1]}
  bind .frame1.frame3.scale8 <Key-Left> {.frame1.frame3.scale8 set [expr [.frame1.frame3.scale8 get]-1]}
  bind .frame1.frame3.scale8 <Key-Next> {.frame1.frame3.scale8 set [expr [.frame1.frame3.scale8 get]+10]}
  bind .frame1.frame3.scale8 <Key-Prior> {.frame1.frame3.scale8 set [expr [.frame1.frame3.scale8 get]-10]}
  bind .frame1.frame3.scale8 <Key-Right> {.frame1.frame3.scale8 set [expr [.frame1.frame3.scale8 get]+1]}
  bind .frame1.frame3.scale8 <Key-Up> {.frame1.frame3.scale8 set [expr [.frame1.frame3.scale8 get]+1]}
  bind .frame1.frame3.scale8 <Shift-Button-1> {focus .frame1.frame3.scale8}

  # pack widget .frame1.frame3
  pack append .frame1.frame3 \
    .frame1.frame3.button4 {top frame center fillx} \
    .frame1.frame3.scale6 {top frame center fillx} \
    .frame1.frame3.scale7 {top frame center fillx} \
    .frame1.frame3.scale8 {top frame center fillx} 

  # build widget .frame1.frame5
  frame .frame1.frame5 \
    -borderwidth {2} \
    -relief {sunken}

  # build widget .frame1.frame5.button1
  button .frame1.frame5.button1 \
    -command {SetTransparentColor} \
    -foreground {#3abdbc} \
    -text {Transparent}

  # build widget .frame1.frame5.frame0
  frame .frame1.frame5.frame0 \
    -relief {raised}

  # build widget .frame1.frame5.frame0.button1
  button .frame1.frame5.frame0.button1 \
    -activebackground {black} \
    -activeforeground {pink} \
    -background {pink} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 30
set currentColor [lindex [.frame1.frame5.frame0.button1 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {pink} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame0.button2
  button .frame1.frame5.frame0.button2 \
    -activebackground {black} \
    -activeforeground {LightPink} \
    -background {LightPink} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 31
set currentColor [lindex [.frame1.frame5.frame0.button2 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {LightPink} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame0.button3
  button .frame1.frame5.frame0.button3 \
    -activebackground {black} \
    -activeforeground {HotPink} \
    -background {HotPink} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 32
set currentColor [lindex [.frame1.frame5.frame0.button3 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {HotPink} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame0.button4
  button .frame1.frame5.frame0.button4 \
    -activebackground {black} \
    -activeforeground {DeepPink1} \
    -background {DeepPink1} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 33
set currentColor [lindex [.frame1.frame5.frame0.button4 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {DeepPink1} \
    -height {7} \
    -text {button4} \
    -width {7}

  # build widget .frame1.frame5.frame0.button5
  button .frame1.frame5.frame0.button5 \
    -activebackground {black} \
    -activeforeground {DeepPink3} \
    -background {DeepPink3} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 34
set currentColor [lindex [.frame1.frame5.frame0.button5 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {DeepPink3} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame0.button6
  button .frame1.frame5.frame0.button6 \
    -activebackground {black} \
    -activeforeground {DeepPink4} \
    -background {DeepPink4} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 35
set currentColor [lindex [.frame1.frame5.frame0.button6 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {DeepPink4} \
    -height {7} \
    -text {} \
    -width {7}

  # pack widget .frame1.frame5.frame0
  pack append .frame1.frame5.frame0 \
    .frame1.frame5.frame0.button1 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame0.button2 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame0.button3 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame0.button4 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame0.button5 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame0.button6 {left frame center padx 2 pady 2} 

  # build widget .frame1.frame5.frame10
  frame .frame1.frame5.frame10 \
    -relief {raised}

  # build widget .frame1.frame5.frame10.button17
  button .frame1.frame5.frame10.button17 \
    -activebackground {black} \
    -activeforeground {yellow1} \
    -background {yellow1} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 24
set currentColor [lindex [.frame1.frame5.frame10.button17 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {yellow1} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame10.button18
  button .frame1.frame5.frame10.button18 \
    -activebackground {black} \
    -activeforeground {yellow3} \
    -background {yellow3} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 25
set currentColor [lindex [.frame1.frame5.frame10.button18 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {yellow3} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame10.button19
  button .frame1.frame5.frame10.button19 \
    -activebackground {black} \
    -activeforeground {GreenYellow} \
    -background {GreenYellow} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 26
set currentColor [lindex [.frame1.frame5.frame10.button19 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {GreenYellow} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame10.button20
  button .frame1.frame5.frame10.button20 \
    -activebackground {black} \
    -activeforeground {green} \
    -background {green} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 27
set currentColor [lindex [.frame1.frame5.frame10.button20 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {green} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame10.button37
  button .frame1.frame5.frame10.button37 \
    -activebackground {black} \
    -activeforeground {LimeGreen} \
    -background {LimeGreen} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 28
set currentColor [lindex [.frame1.frame5.frame10.button37 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {LimeGreen} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame10.button8
  button .frame1.frame5.frame10.button8 \
    -activebackground {black} \
    -activeforeground {ForestGreen} \
    -background {ForestGreen} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 29
set currentColor [lindex [.frame1.frame5.frame10.button8 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {ForestGreen} \
    -height {7} \
    -text {} \
    -width {7}

  # pack widget .frame1.frame5.frame10
  pack append .frame1.frame5.frame10 \
    .frame1.frame5.frame10.button17 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame10.button18 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame10.button19 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame10.button20 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame10.button37 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame10.button8 {left frame center padx 2 pady 2} 

  # build widget .frame1.frame5.frame11
  frame .frame1.frame5.frame11 \
    -relief {raised}

  # build widget .frame1.frame5.frame11.button21
  button .frame1.frame5.frame11.button21 \
    -activebackground {black} \
    -activeforeground {orange1} \
    -background {orange1} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 12
set currentColor [lindex [.frame1.frame5.frame11.button21 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {orange1} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame11.button22
  button .frame1.frame5.frame11.button22 \
    -activebackground {black} \
    -activeforeground {DarkOrange1} \
    -background {DarkOrange1} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 13
set currentColor [lindex [.frame1.frame5.frame11.button22 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {DarkOrange1} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame11.button23
  button .frame1.frame5.frame11.button23 \
    -activebackground {black} \
    -activeforeground {coral1} \
    -background {coral1} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 14
set currentColor [lindex [.frame1.frame5.frame11.button23 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {coral1} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame11.button24
  button .frame1.frame5.frame11.button24 \
    -activebackground {black} \
    -activeforeground {red} \
    -background {red} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 15
set currentColor [lindex [.frame1.frame5.frame11.button24 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {red} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame11.button36
  button .frame1.frame5.frame11.button36 \
    -activebackground {black} \
    -activeforeground {firebrick2} \
    -background {firebrick2} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 16
set currentColor [lindex [.frame1.frame5.frame11.button36 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {firebrick2} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame11.button9
  button .frame1.frame5.frame11.button9 \
    -activebackground {black} \
    -activeforeground {firebrick4} \
    -background {firebrick4} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 17
set currentColor [lindex [.frame1.frame5.frame11.button9 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {firebrick4} \
    -height {7} \
    -text {} \
    -width {7}

  # pack widget .frame1.frame5.frame11
  pack append .frame1.frame5.frame11 \
    .frame1.frame5.frame11.button21 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame11.button22 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame11.button23 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame11.button24 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame11.button36 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame11.button9 {left frame center padx 2 pady 2} 

  # build widget .frame1.frame5.frame12
  frame .frame1.frame5.frame12 \
    -relief {raised}

  # build widget .frame1.frame5.frame12.button10
  button .frame1.frame5.frame12.button10 \
    -activebackground {black} \
    -activeforeground {navy} \
    -background {navy} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 23
set currentColor [lindex [.frame1.frame5.frame12.button10 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {navy} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame12.button25
  button .frame1.frame5.frame12.button25 \
    -activebackground {black} \
    -activeforeground {LightSkyBlue1} \
    -background {LightSkyBlue1} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 18
set currentColor [lindex [.frame1.frame5.frame12.button25 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {LightSkyBlue1} \
    -height {7} \
    -width {7}

  # build widget .frame1.frame5.frame12.button26
  button .frame1.frame5.frame12.button26 \
    -activebackground {black} \
    -activeforeground {SteelBlue1} \
    -background {SteelBlue1} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 19
set currentColor [lindex [.frame1.frame5.frame12.button26 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {SteelBlue1} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame12.button27
  button .frame1.frame5.frame12.button27 \
    -activebackground {black} \
    -activeforeground {DodgerBlue3} \
    -background {DodgerBlue3} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 20
set currentColor [lindex [.frame1.frame5.frame12.button27 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {DodgerBlue3} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame12.button28
  button .frame1.frame5.frame12.button28 \
    -activebackground {black} \
    -activeforeground {blue3} \
    -background {blue3} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 21
set currentColor [lindex [.frame1.frame5.frame12.button28 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {blue3} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame12.button35
  button .frame1.frame5.frame12.button35 \
    -activebackground {black} \
    -activeforeground {blue4} \
    -background {blue4} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 22
set currentColor [lindex [.frame1.frame5.frame12.button35 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {blue4} \
    -height {7} \
    -text {} \
    -width {7}

  # pack widget .frame1.frame5.frame12
  pack append .frame1.frame5.frame12 \
    .frame1.frame5.frame12.button25 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame12.button26 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame12.button27 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame12.button28 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame12.button35 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame12.button10 {left frame center padx 2 pady 2} 

  # build widget .frame1.frame5.frame29
  frame .frame1.frame5.frame29 \
    -relief {raised}

  # build widget .frame1.frame5.frame29.button11
  button .frame1.frame5.frame29.button11 \
    -activebackground {black} \
    -activeforeground {black} \
    -background {black} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 11
set currentColor [lindex [.frame1.frame5.frame29.button11 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {black} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame29.button30
  button .frame1.frame5.frame29.button30 \
    -activebackground {black} \
    -activeforeground {gray40} \
    -background {gray40} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 6
set currentColor [lindex [.frame1.frame5.frame29.button30 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {gray40} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame29.button31
  button .frame1.frame5.frame29.button31 \
    -activebackground {black} \
    -activeforeground {gray30} \
    -background {gray30} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 7
set currentColor [lindex [.frame1.frame5.frame29.button31 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {gray30} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame29.button32
  button .frame1.frame5.frame29.button32 \
    -activebackground {black} \
    -activeforeground {gray20} \
    -background {gray20} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 8
set currentColor [lindex [.frame1.frame5.frame29.button32 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {gray20} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame29.button33
  button .frame1.frame5.frame29.button33 \
    -activebackground {black} \
    -activeforeground {gray10} \
    -background {gray10} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 9
set currentColor [lindex [.frame1.frame5.frame29.button33 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {gray10} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame29.button34
  button .frame1.frame5.frame29.button34 \
    -activebackground {black} \
    -activeforeground {gray1} \
    -background {gray1} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 10
set currentColor [lindex [.frame1.frame5.frame29.button34 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {gray1} \
    -height {7} \
    -text {} \
    -width {7}

  # pack widget .frame1.frame5.frame29
  pack append .frame1.frame5.frame29 \
    .frame1.frame5.frame29.button30 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame29.button31 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame29.button32 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame29.button33 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame29.button34 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame29.button11 {left frame center padx 2 pady 2} 

  # build widget .frame1.frame5.frame9
  frame .frame1.frame5.frame9 \
    -relief {raised}

  # build widget .frame1.frame5.frame9.button13
  button .frame1.frame5.frame9.button13 \
    -activebackground {black} \
    -activeforeground {white} \
    -background {white} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 0
set currentColor [lindex [.frame1.frame5.frame9.button13 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {white} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame9.button14
  button .frame1.frame5.frame9.button14 \
    -activebackground {black} \
    -activeforeground {gray90} \
    -background {gray90} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 1
set currentColor [lindex [.frame1.frame5.frame9.button14 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {gray90} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame9.button15
  button .frame1.frame5.frame9.button15 \
    -activebackground {black} \
    -activeforeground {gray80} \
    -background {gray80} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 2
set currentColor [lindex [.frame1.frame5.frame9.button15 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {gray80} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame9.button16
  button .frame1.frame5.frame9.button16 \
    -activebackground {black} \
    -activeforeground {gray70} \
    -background {gray70} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 3
set currentColor [lindex [.frame1.frame5.frame9.button16 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {gray70} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame9.button38
  button .frame1.frame5.frame9.button38 \
    -activebackground {black} \
    -activeforeground {gray60} \
    -background {gray60} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 4
set currentColor [lindex [.frame1.frame5.frame9.button38 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {gray60} \
    -height {7} \
    -text {} \
    -width {7}

  # build widget .frame1.frame5.frame9.button7
  button .frame1.frame5.frame9.button7 \
    -activebackground {black} \
    -activeforeground {gray50} \
    -background {gray50} \
    -bitmap {gray50} \
    -command {global currentColor
global currentColorButton
set currentColorButton 5
set currentColor [lindex [.frame1.frame5.frame9.button7 config -foreground] 4]
.frame1.frame5.label0 config -foreground $currentColor} \
    -foreground {gray50} \
    -height {7} \
    -text {} \
    -width {7}

  # pack widget .frame1.frame5.frame9
  pack append .frame1.frame5.frame9 \
    .frame1.frame5.frame9.button13 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame9.button14 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame9.button15 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame9.button16 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame9.button38 {left frame center padx 2 pady 2} \
    .frame1.frame5.frame9.button7 {left frame center padx 2 pady 2} 

  # build widget .frame1.frame5.label0
  button .frame1.frame5.label0 \
    -command {SetNewColor} \
    -foreground {white} \
    -text {white} \
    -textvariable {currentColor} \
    -width {11}

  # pack widget .frame1.frame5
  pack append .frame1.frame5 \
    .frame1.frame5.label0 {top frame center fillx} \
    .frame1.frame5.frame9 {top frame center} \
    .frame1.frame5.frame29 {top frame center} \
    .frame1.frame5.frame11 {top frame center} \
    .frame1.frame5.frame12 {top frame center} \
    .frame1.frame5.frame10 {top frame center} \
    .frame1.frame5.frame0 {top frame center} \
    .frame1.frame5.button1 {top frame center fillx} 

  # pack widget .frame1
  pack append .frame1 \
    .frame1.frame5 {bottom frame center} \
    .frame1.frame0 {bottom frame center fill} \
    .frame1.frame1 {top frame center expand fill} \
    .frame1.frame3 {bottom frame center fillx} 

  # pack widget .
  pack append . \
    .frame0 {top frame center fillx} \
    .frame {right frame center expand fill} \
    .frame1 {left frame center filly} 

  if {"[info procs XFEdit]" != ""} {
    XFEditSetShowWindows
    XFMiscBindWidgetTree .xfFSBox
  }

  global tkVersion
  if {$tkVersion >= 3.0} {
    tk_menuBar .frame0 .frame0.menubutton2 .frame0.menubutton3
  } {
    tk_menus . .frame0.menubutton2 .frame0.menubutton3
  }
}


# Procedure: AlertBox
proc AlertBox { {alertBoxMessage "Alert message"} {alertBoxCommand ""} {alertBoxGeometry "350x150"} {alertBoxTitle "Alert box"} args} {
# xf ignore me 5
##########
# Procedure: AlertBox
# Description: show alert box
# Arguments: {alertBoxMessage} - the text to display
#            {alertBoxCommand} - the command to call after ok
#            {alertBoxGeometry} - the geometry for the window
#            {alertBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          AlertBoxFile - to open and read a file automatically
#          AlertBoxFd - to read from an already opened filedescriptor
##########
#
# global alertBox(activeBackground) - active background color
# global alertBox(activeForeground) - active foreground color
# global alertBox(after) - destroy alert box after n seconds
# global alertBox(anchor) - anchor for message box
# global alertBox(background) - background color
# global alertBox(font) - message font
# global alertBox(foreground) - foreground color
# global alertBox(justify) - justify for message box
# global alertBox(toplevelName) - the toplevel name

  global alertBox

  # show alert box
  if {[llength $args] > 0} {
    eval AlertBoxInternal "\{$alertBoxMessage\}" "\{$alertBoxCommand\}" "\{$alertBoxGeometry\}" "\{$alertBoxTitle\}" $args
  } {
    AlertBoxInternal $alertBoxMessage $alertBoxCommand $alertBoxGeometry $alertBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $alertBox(toplevelName)
    tkwait window $alertBox(toplevelName)

    return $alertBox(button)
  }
}


# Procedure: AlertBoxInternal
proc AlertBoxInternal { alertBoxMessage alertBoxCommand alertBoxGeometry alertBoxTitle args} {
# xf ignore me 6
  global alertBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  if {"$alertBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$alertBox(activeBackground)\" "
  }
  if {"$alertBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$alertBox(activeForeground)\" "
  }
  if {"$alertBox(background)" != ""} {
    append tmpButtonOpt "-background \"$alertBox(background)\" "
    append tmpFrameOpt "-background \"$alertBox(background)\" "
    append tmpMessageOpt "-background \"$alertBox(background)\" "
  }
  if {"$alertBox(font)" != ""} {
    append tmpButtonOpt "-font \"$alertBox(font)\" "
    append tmpMessageOpt "-font \"$alertBox(font)\" "
  }
  if {"$alertBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$alertBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$alertBox(foreground)\" "
  }

  # start build of toplevel
  if {"[info commands XFDestroy]" != ""} {
    catch {XFDestroy $alertBox(toplevelName)}
  } {
    catch {destroy $alertBox(toplevelName)}
  }
  toplevel $alertBox(toplevelName)     -borderwidth 0
  catch "$alertBox(toplevelName) config $tmpFrameOpt"
  if {[catch "wm geometry $alertBox(toplevelName) $alertBoxGeometry"]} {
    wm geometry $alertBox(toplevelName) 350x150
  }
  wm title $alertBox(toplevelName) $alertBoxTitle
  wm maxsize $alertBox(toplevelName) 1000 1000
  wm minsize $alertBox(toplevelName) 100 100
  # end build of toplevel

  message $alertBox(toplevelName).message1     -anchor "$alertBox(anchor)"     -justify "$alertBox(justify)"     -relief raised     -text "$alertBoxMessage"
  catch "$alertBox(toplevelName).message1 config $tmpMessageOpt"

  set xfTmpWidth     [string range $alertBoxGeometry 0 [expr [string first x $alertBoxGeometry]-1]]
  if {"$xfTmpWidth" != ""} {
    # set message size
    catch "$alertBox(toplevelName).message1 configure       -width [expr $xfTmpWidth-10]"
  } {
    $alertBox(toplevelName).message1 configure       -aspect 1500
  }

  frame $alertBox(toplevelName).frame1     -borderwidth 0     -relief raised
  catch "$alertBox(toplevelName).frame1 config $tmpFrameOpt"

  set alertBoxCounter 0
  set buttonNum [llength $args]
  if {$buttonNum > 0} {
    while {$alertBoxCounter < $buttonNum} {
      button $alertBox(toplevelName).frame1.button$alertBoxCounter         -text "[lindex $args $alertBoxCounter]"         -command "
          global alertBox
          set alertBox(button) $alertBoxCounter
          if {\"\[info commands XFDestroy\]\" != \"\"} {
            catch {XFDestroy $alertBox(toplevelName)}
          } {
            catch {destroy $alertBox(toplevelName)}
          }"
      catch "$alertBox(toplevelName).frame1.button$alertBoxCounter config $tmpButtonOpt"

      pack append $alertBox(toplevelName).frame1                   $alertBox(toplevelName).frame1.button$alertBoxCounter {left fillx expand}

      incr alertBoxCounter
    }
  } {
    button $alertBox(toplevelName).frame1.button0       -text "OK"       -command "
        global alertBox
        set alertBox(button) 0
        if {\"\[info commands XFDestroy\]\" != \"\"} {
          catch {XFDestroy $alertBox(toplevelName)}
        } {
          catch {destroy $alertBox(toplevelName)}
        }
        $alertBoxCommand"
    catch "$alertBox(toplevelName).frame1.button0 config $tmpButtonOpt"

    pack append $alertBox(toplevelName).frame1                 $alertBox(toplevelName).frame1.button0 {left fillx expand}
  }

  # packing
  pack append $alertBox(toplevelName)               $alertBox(toplevelName).frame1 {bottom fill}               $alertBox(toplevelName).message1 {top fill expand}

  if {$alertBox(after) != 0} {
    after [expr $alertBox(after)*1000]       "catch \"$alertBox(toplevelName).frame1.button0 invoke\""
  }
}


# Procedure: Alias
proc Alias { args} {
# xf ignore me 7
##########
# Procedure: Alias
# Description: establish an alias for a procedure
# Arguments: args - no argument means that a list of all aliases
#                   is returned. Otherwise the first parameter is
#                   the alias name, and the second parameter is
#                   the procedure that is aliased.
# Returns: nothing, the command that is bound to the alias or a
#          list of all aliases - command pairs. 
# Sideeffects: internalAliasList is updated, and the alias
#              proc is inserted
##########
  global internalAliasList

  if {[llength $args] == 0} {
    return $internalAliasList
  } {
    if {[llength $args] == 1} {
      set xfTmpIndex [lsearch $internalAliasList "[lindex $args 0] *"]
      if {$xfTmpIndex != -1} {
        return [lindex [lindex $internalAliasList $xfTmpIndex] 1]
      }
    } {
      if {[llength $args] == 2} {
        eval "proc [lindex $args 0] {args} {#xf ignore me 4
return \[eval \"[lindex $args 1] \$args\"\]}"
        set xfTmpIndex [lsearch $internalAliasList "[lindex $args 0] *"]
        if {$xfTmpIndex != -1} {
          set internalAliasList [lreplace $internalAliasList $xfTmpIndex $xfTmpIndex "[lindex $args 0] [lindex $args 1]"]
        } {
          lappend internalAliasList "[lindex $args 0] [lindex $args 1]"
        }
      } {
        error "Alias: wrong number or args: $args"
      }
    }
  }
}


# Procedure: ChangeArea
proc ChangeArea { type} {
  global currentHeight
  global currentTransparentColor
  global currentWidth

  set tmpCanvas [SymbolicName drawSpace]
  case $type in {
    {1} {
      set counter [expr $currentWidth-1]
      for {set counterW 0} {$counterW < [expr $currentWidth/2]} {incr counterW} {
        for {set counterH 0} {$counterH < $currentHeight} {incr counterH} {
          set tmpColor1 [lindex [$tmpCanvas itemconfig "pixel$counterH-$counterW" -fill] 4]
          set tmpColor2 [lindex [$tmpCanvas itemconfig "pixel$counterH-$counter" -fill] 4]
          $tmpCanvas itemconfig "pixel$counterH-$counterW"             -fill "$tmpColor2"
          $tmpCanvas itemconfig "pixel$counterH-$counter"             -fill "$tmpColor1"
        }
        incr counter -1
        update
      }
    }
    {2} {
      for {set counterH 0} {$counterH < [expr $currentHeight-1]} {incr counterH} {
        for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
          set tmpColor [lindex [$tmpCanvas itemconfig "pixel[expr $counterH+1]-$counterW" -fill] 4]
          $tmpCanvas itemconfig "pixel$counterH-$counterW"             -fill "$tmpColor"
        }
        update
      }
      for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
        $tmpCanvas itemconfig "pixel[expr $currentHeight-1]-$counterW"           -fill "$currentTransparentColor"
      }
      update
    }
    {3} {
      set counter [expr $currentHeight-1]
      for {set counterH 0} {$counterH < [expr $currentHeight/2]} {incr counterH} {
        for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
          set tmpColor1 [lindex [$tmpCanvas itemconfig "pixel$counterH-$counterW" -fill] 4]
          set tmpColor2 [lindex [$tmpCanvas itemconfig "pixel$counter-$counterW" -fill] 4]
          $tmpCanvas itemconfig "pixel$counterH-$counterW"             -fill "$tmpColor2"
          $tmpCanvas itemconfig "pixel$counter-$counterW"             -fill "$tmpColor1"
        }
        incr counter -1
        update
      }
    }
    {4} {
      for {set counterH 0} {$counterH < $currentHeight} {incr counterH} {
        for {set counterW 0} {$counterW < [expr $currentWidth-1]} {incr counterW} {
          set tmpColor [lindex [$tmpCanvas itemconfig "pixel$counterH-[expr $counterW+1]" -fill] 4]
          $tmpCanvas itemconfig "pixel$counterH-$counterW"             -fill "$tmpColor"
        }
        $tmpCanvas itemconfig "pixel$counterH-[expr $currentWidth-1]"           -fill "$currentTransparentColor"
        update
      }
    }
    {5} {
      set dist2 [expr ($currentWidth/2)+($currentWidth%2)]
      set dist1 [expr ($currentHeight/2)+($currentHeight%2)]
      for {set counterH 0} {$counterH < [expr $currentHeight/2]} {incr counterH} {
        for {set counterW 0} {$counterW < [expr $currentWidth/2]} {incr counterW} {
          set tmpColor1 [lindex [$tmpCanvas itemconfig "pixel$counterH-$counterW" -fill] 4]
          set tmpColor2 [lindex [$tmpCanvas itemconfig "pixel[expr $counterH+$dist1]-[expr $counterW+$dist2]" -fill] 4]
          $tmpCanvas itemconfig "pixel$counterH-$counterW"             -fill "$tmpColor2"
          $tmpCanvas itemconfig "pixel[expr $counterH+$dist1]-[expr $counterW+$dist2]"             -fill "$tmpColor1"
        }
        update
      }
      for {set counterH [expr ($currentHeight/2)+($currentHeight%2)]} {$counterH < $currentHeight} {incr counterH} {
        for {set counterW 0} {$counterW < [expr $currentWidth/2]} {incr counterW} {
          set tmpColor1 [lindex [$tmpCanvas itemconfig "pixel$counterH-$counterW" -fill] 4]
          set tmpColor2 [lindex [$tmpCanvas itemconfig "pixel[expr $counterH-$dist1]-[expr $counterW+$dist2]" -fill] 4]
          $tmpCanvas itemconfig "pixel$counterH-$counterW"             -fill "$tmpColor2"
          $tmpCanvas itemconfig "pixel[expr $counterH-$dist1]-[expr $counterW+$dist2]"             -fill "$tmpColor1"
        }
        update
      }
    }
    {6} {
      for {set counterH 0} {$counterH < $currentHeight} {incr counterH} {
        for {set counterW [expr $currentWidth-1]} {$counterW >= 0} {incr counterW -1} {
          set tmpColor [lindex [$tmpCanvas itemconfig "pixel$counterH-[expr $counterW-1]" -fill] 4]
          $tmpCanvas itemconfig "pixel$counterH-$counterW"             -fill "$tmpColor"
        }
        $tmpCanvas itemconfig "pixel$counterH-0"           -fill "$currentTransparentColor"
        update
      }
    }
    {7} {
      set dist2 [expr ($currentWidth/2)+($currentWidth%2)]
      set dist1 [expr ($currentHeight/2)+($currentHeight%2)]
      for {set counterH 0} {$counterH < [expr $currentHeight/2]} {incr counterH} {
        for {set counterW 0} {$counterW < [expr $currentWidth/2]} {incr counterW} {
          set tmpColor1 [lindex [$tmpCanvas itemconfig "pixel$counterH-$counterW" -fill] 4]
          set tmpColor2 [lindex [$tmpCanvas itemconfig "pixel$counterH-[expr $counterW+$dist2]" -fill] 4]
          set tmpColor3 [lindex [$tmpCanvas itemconfig "pixel[expr $counterH+$dist1]-$counterW" -fill] 4]
          set tmpColor4 [lindex [$tmpCanvas itemconfig "pixel[expr $counterH+$dist1]-[expr $counterW+$dist2]" -fill] 4]
          $tmpCanvas itemconfig "pixel$counterH-[expr $counterW+$dist2]"             -fill "$tmpColor4"
          $tmpCanvas itemconfig "pixel[expr $counterH+$dist1]-[expr $counterW+$dist2]"             -fill "$tmpColor3"
          $tmpCanvas itemconfig "pixel$counterH-$counterW"             -fill "$tmpColor2"
          $tmpCanvas itemconfig "pixel[expr $counterH+$dist1]-$counterW"             -fill "$tmpColor1"
        }
        update
      }
    }
    {8} {
      for {set counterH [expr $currentHeight-1]} {$counterH >= 0} {incr counterH -1} {
        for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
          set tmpColor [lindex [$tmpCanvas itemconfig "pixel[expr $counterH-1]-$counterW" -fill] 4]
          $tmpCanvas itemconfig "pixel$counterH-$counterW"             -fill "$tmpColor"
        }
        update
      }
      for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
        $tmpCanvas itemconfig "pixel0-$counterW"           -fill "$currentTransparentColor"
      }
      update
    }
    {9} {
      set dist2 [expr ($currentWidth/2)+($currentWidth%2)]
      set dist1 [expr ($currentHeight/2)+($currentHeight%2)]
      for {set counterH 0} {$counterH < [expr $currentHeight/2]} {incr counterH} {
        for {set counterW 0} {$counterW < [expr $currentWidth/2]} {incr counterW} {
          set tmpColor1 [lindex [$tmpCanvas itemconfig "pixel$counterH-$counterW" -fill] 4]
          set tmpColor2 [lindex [$tmpCanvas itemconfig "pixel$counterH-[expr $counterW+$dist2]" -fill] 4]
          set tmpColor3 [lindex [$tmpCanvas itemconfig "pixel[expr $counterH+$dist1]-$counterW" -fill] 4]
          set tmpColor4 [lindex [$tmpCanvas itemconfig "pixel[expr $counterH+$dist1]-[expr $counterW+$dist2]" -fill] 4]
          $tmpCanvas itemconfig "pixel[expr $counterH+$dist1]-$counterW"             -fill "$tmpColor4"
          $tmpCanvas itemconfig "pixel$counterH-$counterW"             -fill "$tmpColor3"
          $tmpCanvas itemconfig "pixel[expr $counterH+$dist1]-[expr $counterW+$dist2]"             -fill "$tmpColor2"
          $tmpCanvas itemconfig "pixel$counterH-[expr $counterW+$dist2]"             -fill "$tmpColor1"
        }
        update
      }
    }
  }
}


# Procedure: ClearArea
proc ClearArea {} {
  global currentHeight
  global currentWidth
  global currentTransparentColor

  set tmpCanvas [SymbolicName drawSpace]
  for {set counterH 0} {$counterH < $currentHeight} {incr counterH} {
    for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
      $tmpCanvas itemconfig "pixel$counterH-$counterW"         -fill "$currentTransparentColor"
    }
  }
}


# Procedure: ColorBox
proc ColorBox { {colorBoxFileColor "/usr/local/lib/xf/lib/Colors"} {colorBoxMessage "Color"} {colorBoxEntryW ""} {colorBoxTargetW ""}} {
# xf ignore me 5
##########
# Procedure: ColorBox
# Description: select a color
# Arguments: {colorBoxFileColor} - the color file with all colornames
#            {colorBoxMessage} - a message to display
#            {colorBoxEntryW} - the widget name for the resulting color name
#            {colorBoxTargetW} - the widget we configure
# Returns: colorname, or nothing
# Sideeffects: none
##########
# 
# global colorBox(activeBackground) - active background color
# global colorBox(activeForeground) - active foreground color
# global colorBox(background) - background color
# global colorBox(font) - text font
# global colorBox(foreground) - foreground color
# global colorBox(palette) - a palette of colors
# global colorBox(scrollActiveForeground) - scrollbar active background color
# global colorBox(scrollBackground) - scrollbar background color
# global colorBox(scrollForeground) - scrollbar foreground color
# global colorBox(scrollSide) - side where scrollbar is located

  global colorBox

  set colorBox(colorName) ""
  set colorBox(paletteNr) 0

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  set tmpScaleOpt ""
  set tmpScrollOpt ""
  if {"$colorBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$colorBox(activeBackground)\" "
  }
  if {"$colorBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$colorBox(activeForeground)\" "
  }
  if {"$colorBox(background)" != ""} {
    append tmpButtonOpt "-background \"$colorBox(background)\" "
    append tmpFrameOpt "-background \"$colorBox(background)\" "
    append tmpMessageOpt "-background \"$colorBox(background)\" "
    append tmpScaleOpt "-background \"$colorBox(background)\" "
  }
  if {"$colorBox(font)" != ""} {
    append tmpButtonOpt "-font \"$colorBox(font)\" "
    append tmpMessageOpt "-font \"$colorBox(font)\" "
  }
  if {"$colorBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$colorBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$colorBox(foreground)\" "
    append tmpScaleOpt "-foreground \"$colorBox(foreground)\" "
  }
  if {"$colorBox(scrollActiveForeground)" != ""} {
    append tmpScaleOpt "-activeforeground \"$colorBox(scrollActiveForeground)\" "
    append tmpScrollOpt "-activeforeground \"$colorBox(scrollActiveForeground)\" "
  }
  if {"$colorBox(scrollBackground)" != ""} {
    append tmpScrollOpt "-background \"$colorBox(scrollBackground)\" "
  }
  if {"$colorBox(scrollForeground)" != ""} {
    append tmpScrollOpt "-foreground \"$colorBox(scrollForeground)\" "
  }

  # get color file name
  if {!([file exists $colorBoxFileColor] &&
        [file readable $colorBoxFileColor])} {
    set colorBoxFileColor ""
  }
  if {"$colorBoxFileColor" == ""} {
    global env
    if {[info exists env(XF_COLOR_FILE)]} {
      if {[file exists $env(XF_COLOR_FILE)] &&
          [file readable $env(XF_COLOR_FILE)]} {
        set colorBoxFileColor $env(XF_COLOR_FILE)
      }
    }
  }
  if {"$colorBoxMessage" == ""} {
    set colorBoxMessage "Color"
  }

  # save the the current widget color
  if {"$colorBoxTargetW" != ""} {
    if {[catch "$colorBoxTargetW config -[string tolower $colorBoxMessage]" result]} {
      set colorBoxSavedColor ""
    } {
      set colorBoxSavedColor [lindex $result 4]
    }
  } {
    set colorBoxSavedColor ""
  }

  # look if there is already a color window
  if {"[info commands .colorBox]" == ""} {
    # build widget structure

    # start build of toplevel
    if {"[info commands XFDestroy]" != ""} {
      catch {XFDestroy .colorBox}
    } {
      catch {destroy .colorBox}
    }
    toplevel .colorBox       -borderwidth 0
    catch ".colorBox config $tmpFrameOpt"
    wm geometry .colorBox 400x250
    wm title .colorBox {Color box}
    wm maxsize .colorBox 1000 1000
    wm minsize .colorBox 100 100
    # end build of toplevel

    set colorBox(oldWidget) $colorBoxEntryW

    frame .colorBox.frame1       -borderwidth 0       -relief raised
    catch ".colorBox.frame1 config $tmpFrameOpt"
 
    button .colorBox.frame1.ok       -text "OK"
    catch ".colorBox.frame1.ok config $tmpButtonOpt"

    button .colorBox.frame1.cancel       -text "Cancel"
    catch ".colorBox.frame1.cancel config $tmpButtonOpt"

    frame .colorBox.frame2       -borderwidth 0       -relief raised
    catch ".colorBox.frame2 config $tmpFrameOpt"
 
    radiobutton .colorBox.frame2.rgb       -command "ColorBoxShowSlides $colorBoxMessage \"$colorBoxTargetW\""       -text "RGB"       -variable colorBox(type)
    catch ".colorBox.frame2.rgb config $tmpButtonOpt"

    radiobutton .colorBox.frame2.hsv       -command "ColorBoxShowSlides $colorBoxMessage \"$colorBoxTargetW\""       -text "HSV"       -variable colorBox(type)
    catch ".colorBox.frame2.hsv config $tmpButtonOpt"

    radiobutton .colorBox.frame2.list       -command "ColorBoxShowSlides $colorBoxMessage \"$colorBoxTargetW\""       -text "List"       -variable colorBox(type)
    catch ".colorBox.frame2.list config $tmpButtonOpt"

    frame .colorBox.palette       -borderwidth 0       -relief raised
    catch ".colorBox.palette config $tmpFrameOpt"
 
    set counter 0
    foreach element $colorBox(palette) {
      button .colorBox.palette.palette$counter         -command "ColorBoxSetPalette $colorBoxMessage \"$colorBoxTargetW\" $counter"                -width 3
      catch ".colorBox.palette.palette$counter config         -activebackground \"$element\"         -background \"$element\""

      pack append .colorBox.palette .colorBox.palette.palette$counter {left fill expand}
      incr counter
    }

    scale .colorBox.red       -background "red"       -from 0       -label "Red"       -orient horizontal       -relief raised       -sliderlength 15       -to 255       -width 8
    catch ".colorBox.red config $tmpScaleOpt"

    scale .colorBox.green       -background "green"       -from 0       -label "Green"       -orient horizontal       -relief raised       -sliderlength 15       -to 255       -width 8
    catch ".colorBox.green config $tmpScaleOpt"

    scale .colorBox.blue       -background "blue"       -from 0       -label "Blue"       -orient horizontal       -relief raised       -sliderlength 15       -to 255       -width 8
    catch ".colorBox.blue config $tmpScaleOpt"

    scale .colorBox.h       -from 0       -label "Hue"       -orient horizontal       -relief raised       -sliderlength 15       -to 1000       -width 8
    catch ".colorBox.h config $tmpScaleOpt"

   scale .colorBox.s      -from 0      -label "Saturation * 100"      -orient horizontal      -relief raised      -sliderlength 15      -to 1000      -width 8
    catch ".colorBox.s config $tmpScaleOpt"

    scale .colorBox.v       -from 0       -label "Value"       -orient horizontal       -relief raised       -sliderlength 15       -to 1000       -width 8
    catch ".colorBox.v config $tmpScaleOpt"

    label .colorBox.demo       -relief raised       -text "This text shows the results :-)"
    catch ".colorBox.demo config $tmpMessageOpt"

    frame .colorBox.current       -borderwidth 0       -relief raised
    catch ".colorBox.current config $tmpFrameOpt"

    label .colorBox.current.labelcurrent       -relief raised
    catch ".colorBox.current.labelcurrent config $tmpMessageOpt"

    entry .colorBox.current.current       -relief raised
    catch ".colorBox.current.current config $tmpMessageOpt"

    frame .colorBox.colors       -borderwidth 0       -relief raised
    catch ".colorBox.colors config $tmpFrameOpt"

    scrollbar .colorBox.colors.vscroll       -relief raised       -command ".colorBox.colors.colors yview"
    catch ".colorBox.colors.vscroll config $tmpScrollOpt"

    scrollbar .colorBox.colors.hscroll       -orient horiz       -relief raised       -command ".colorBox.colors.colors xview"
    catch ".colorBox.colors.hscroll config $tmpScrollOpt"

    listbox .colorBox.colors.colors       -exportselection false       -relief raised       -xscrollcommand ".colorBox.colors.hscroll set"       -yscrollcommand ".colorBox.colors.vscroll set"
    catch ".colorBox.colors.colors config $tmpMessageOpt"

    # read color file
    if {"$colorBoxFileColor" != ""} {
      if {[catch "open $colorBoxFileColor r" colorInFile]} {
        set colorBoxFileColor ""
        if {"[info commands AlertBox]" != ""} {
          AlertBox "$colorInFile"
        } {
          puts stderr "$colorInFile"
        }
      } {
        set colorReadList [read $colorInFile]
        close $colorInFile
        foreach colorLine [split $colorReadList "\n"] {
          if {"[string trim $colorLine]" != ""} {
            set colorNewLine [lrange $colorLine 3 end]
            append colorNewLine " " [format #%02x [lindex $colorLine 0]]
            append colorNewLine [format %02x [lindex $colorLine 1]]
            append colorNewLine [format %02x [lindex $colorLine 2]]
            .colorBox.colors.colors insert end $colorNewLine
          }
        }
      }
    }

    # bindings
    bind .colorBox.colors.colors <ButtonPress-1> "
      ColorBoxSelectColor %W $colorBoxMessage \"$colorBoxTargetW\" %y"
    bind .colorBox.colors.colors <Button1-Motion> "
      ColorBoxSelectColor %W $colorBoxMessage \"$colorBoxTargetW\" %y"
    bind .colorBox.colors.colors <Shift-ButtonPress-1> "
      ColorBoxSelectColor %W $colorBoxMessage \"$colorBoxTargetW\" %y"
    bind .colorBox.colors.colors <Shift-Button1-Motion> "
      ColorBoxSelectColor %W $colorBoxMessage \"$colorBoxTargetW\" %y"
  } {
    if {"[winfo class $colorBox(oldWidget)]" == "Text"} {
      catch "$colorBox(oldWidget) delete 1.0 end"
      catch "$colorBox(oldWidget) insert 1.0 [.colorBox.current.current get]"
    } {
      if {"[winfo class $colorBox(oldWidget)]" == "Entry"} {
        catch "$colorBox(oldWidget) delete 0 end"
        catch "$colorBox(oldWidget) insert 0 [.colorBox.current.current get]"
      }
    }

    set colorBox(oldWidget) $colorBoxEntryW
  }
   
  .colorBox.frame1.ok config     -command "
      global colorBox
      set colorBox(colorName) \[.colorBox.current.current get\]
      if {\"$colorBoxEntryW\" != \"\"} {
        if {\"\[winfo class $colorBoxEntryW\]\" == \"Text\"} {
          catch \"$colorBoxEntryW delete 1.0 end\"
          catch \"$colorBoxEntryW insert 1.0 \\\"\$colorBox(colorName)\\\"\"
        } {
          if {\"\[winfo class $colorBoxEntryW\]\" == \"Entry\"} {
            catch \"$colorBoxEntryW delete 0 end\"
            catch \"$colorBoxEntryW insert 0 \\\"\$colorBox(colorName)\\\"\"
          }
        }
      }
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy .colorBox}
      } {
        catch {destroy .colorBox}
      }"

  .colorBox.frame1.cancel config     -command "
      global colorBox
      set colorBox(colorName) {}
      if {\"$colorBoxTargetW\" != \"\"} {
        catch \"$colorBoxTargetW config -\[string tolower $colorBoxMessage\] $colorBoxSavedColor\"
      }
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy .colorBox}
      } {
        catch {destroy .colorBox}
      }"

  .colorBox.red config     -command "ColorBoxSetRGBColor $colorBoxMessage \"$colorBoxTargetW\""

  .colorBox.green config     -command "ColorBoxSetRGBColor $colorBoxMessage \"$colorBoxTargetW\""

  .colorBox.blue config     -command "ColorBoxSetRGBColor $colorBoxMessage \"$colorBoxTargetW\""

  .colorBox.h config     -command "ColorBoxSetHSVColor $colorBoxMessage \"$colorBoxTargetW\""

  .colorBox.s config     -command "ColorBoxSetHSVColor $colorBoxMessage \"$colorBoxTargetW\""

  .colorBox.v config     -command "ColorBoxSetHSVColor $colorBoxMessage \"$colorBoxTargetW\""

  .colorBox.current.labelcurrent config     -text "$colorBoxMessage:"

  # bindings
  bind .colorBox.current.current <Return> "
    ColorBoxSetPaletteList \[.colorBox.current.current get\]
    ColorBoxSetColor $colorBoxMessage \"$colorBoxTargetW\" text \[.colorBox.current.current get\]"

  bind .colorBox.colors.colors <Double-1> "
    ColorBoxSelectColor %W $colorBoxMessage \"$colorBoxTargetW\" %y
    global colorBox
    set colorBox(colorName) \[.colorBox.current.current get\]
    if {\"$colorBoxEntryW\" != \"\"} {
      if {\"\[winfo class $colorBoxEntryW\]\" == \"Text\"} {
        catch \"$colorBoxEntryW delete 1.0 end\"
        catch \"$colorBoxEntryW insert 1.0 \\\"\$colorBox(colorName)\\\"\"
      } {
        if {\"\[winfo class $colorBoxEntryW\]\" == \"Entry\"} {
          catch \"$colorBoxEntryW delete 0 end\"
          catch \"$colorBoxEntryW insert 0 \\\"\$colorBox(colorName)\\\"\"
        }
      }
    }
    if {\"\[info commands XFDestroy\]\" != \"\"} {
      catch {XFDestroy .colorBox}
    } {
      catch {destroy .colorBox}
    }"

  # set up current value
  .colorBox.current.current delete 0 end
  if {"$colorBoxEntryW" != ""} {
    if {"[winfo class $colorBoxEntryW]" == "Text"} {
      .colorBox.current.current insert 0 [$colorBoxEntryW get 1.0 end]
    } {
      if {"[winfo class $colorBoxEntryW]" == "Entry"} {
        .colorBox.current.current insert 0 [$colorBoxEntryW get]
      }
    }
  }
  if {"[.colorBox.current.current get]" != ""} {
    ColorBoxSetColor $colorBoxMessage $colorBoxTargetW text [.colorBox.current.current get]
  }
    
  # packing
  pack append .colorBox.frame1               .colorBox.frame1.ok {left fill expand}               .colorBox.frame1.cancel {left fill expand}
  pack append .colorBox.frame2               .colorBox.frame2.rgb {left fill expand}               .colorBox.frame2.hsv {left fill expand}               .colorBox.frame2.list {left fill expand}
  pack append .colorBox.current               .colorBox.current.labelcurrent {left}               .colorBox.current.current {left fill expand}
  pack append .colorBox.colors               .colorBox.colors.vscroll "$colorBox(scrollSide) filly"               .colorBox.colors.hscroll {bottom fillx}               .colorBox.colors.colors {left fill expand}

  ColorBoxShowSlides $colorBoxMessage $colorBoxTargetW

  catch "wm deiconify .colorBox"

  if {"$colorBoxEntryW" == ""} {
    # wait for the box to be destroyed
    update idletask
    grab .colorBox
    tkwait window .colorBox

    return $colorBox(colorName)
  }
}


# Procedure: ColorBoxHSVToRGB
proc ColorBoxHSVToRGB { colorBoxHue colorBoxSat colorBoxValue} {
# xf ignore me 6
# The HSV <-> RGB converting routines are from the
# tcolor demo that is part of the demo site of Tk.

  set colorBoxV [format %.0f [expr 65535.0*$colorBoxValue]]
  if {$colorBoxSat == 0} {
    return "$colorBoxV $colorBoxV $colorBoxV"
  } else {
    set colorBoxHue [expr $colorBoxHue*6.0]
    if {$colorBoxHue >= 6.0} {
      set colorBoxHue 0.0
    }
    scan $colorBoxHue. %d i
    set colorBoxF [expr $colorBoxHue-$i]
    set colorBoxP [format %.0f [expr {65535.0*$colorBoxValue*(1 - $colorBoxSat)}]]
    set colorBoxQ [format %.0f [expr {65535.0*$colorBoxValue*(1 - ($colorBoxSat*$colorBoxF))}]]
    set colorBoxT [format %.0f [expr {65535.0*$colorBoxValue*(1 - ($colorBoxSat*(1 - $colorBoxF)))}]]
    case $i       0 {return "$colorBoxV $colorBoxT $colorBoxP"}       1 {return "$colorBoxQ $colorBoxV $colorBoxP"}       2 {return "$colorBoxP $colorBoxV $colorBoxT"}       3 {return "$colorBoxP $colorBoxQ $colorBoxV"}       4 {return "$colorBoxT $colorBoxP $colorBoxV"}       5 {return "$colorBoxV $colorBoxP $colorBoxQ"}
    error "i value $i is out of range"
  }
}


# Procedure: ColorBoxRGBToHSV
proc ColorBoxRGBToHSV { colorBoxRed colorBoxGreen colorBoxBlue} {
# xf ignore me 6
# The HSV <-> RGB converting routines are from the
# tcolor demo that is part of the demo site of Tk.

  if {$colorBoxRed > $colorBoxGreen} {
    set colorBoxMax $colorBoxRed.0
    set colorBoxMin $colorBoxGreen.0
  } else {
    set colorBoxMax $colorBoxGreen.0
    set colorBoxMin $colorBoxRed.0
  }
  if {$colorBoxBlue > $colorBoxMax} {
    set colorBoxMax $colorBoxBlue.0
  } else {
    if {$colorBoxBlue < $colorBoxMin} {
      set colorBoxMin $colorBoxBlue.0
    }
  }
  set range [expr $colorBoxMax-$colorBoxMin]
  if {$colorBoxMax == 0} {
    set colorBoxSat 0
  } else {
    set colorBoxSat [expr {($colorBoxMax-$colorBoxMin)/$colorBoxMax}]
  }
  if {$colorBoxSat == 0} {
    set colorBoxHue 0
  } else {
    set colorBoxRC [expr {($colorBoxMax - $colorBoxRed)/$range}]
    set colorBoxGC [expr {($colorBoxMax - $colorBoxGreen)/$range}]
    set colorBoxBC [expr {($colorBoxMax - $colorBoxBlue)/$range}]
    if {$colorBoxRed == $colorBoxMax} {
      set colorBoxHue [expr {.166667*($colorBoxBC - $colorBoxGC)}]
    } else {
      if {$colorBoxGreen == $colorBoxMax} {
        set colorBoxHue [expr {.166667*(2 + $colorBoxRC - $colorBoxBC)}]
      } else {
        set colorBoxHue [expr {.166667*(4 + $colorBoxGC - $colorBoxRC)}]
      }
    }
  }
  return [list $colorBoxHue $colorBoxSat [expr {$colorBoxMax/65535}]]
}


# Procedure: ColorBoxSelectColor
proc ColorBoxSelectColor { colorW colorBoxMessage colorBoxTargetW colorY} {
# xf ignore me 6

  set colorNearest [$colorW nearest $colorY]
  if {$colorNearest >= 0} {
    $colorW select from $colorNearest
    $colorW select to $colorNearest
    set colorTmpValue [$colorW get $colorNearest]
    set colorCurrentColor [lrange $colorTmpValue 0           [expr [llength $colorTmpValue]-2]]
    set colorCurrentValue [lrange $colorTmpValue           [expr [llength $colorTmpValue]-1] end]

    scan [string range $colorCurrentValue 1 2] "%x" colorBoxValue
    .colorBox.red set $colorBoxValue
    scan [string range $colorCurrentValue 3 4] "%x" colorBoxValue
    .colorBox.green set $colorBoxValue
    scan [string range $colorCurrentValue 5 6] "%x" colorBoxValue
    .colorBox.blue set $colorBoxValue

    .colorBox.current.current delete 0 end
    .colorBox.current.current insert 0 $colorCurrentColor
    ColorBoxSetColor $colorBoxMessage $colorBoxTargetW list $colorCurrentColor
    ColorBoxSetPaletteList $colorCurrentColor
  }
}


# Procedure: ColorBoxSetColor
proc ColorBoxSetColor { colorBoxMessage colorBoxTargetW colorBoxType colorBoxValue} {
# xf ignore me 6
  global colorBox

  .colorBox.red config     -command "NoFunction"
  .colorBox.green config     -command "NoFunction"
  .colorBox.blue config     -command "NoFunction"
  .colorBox.h config     -command "NoFunction"
  .colorBox.s config     -command "NoFunction"
  .colorBox.v config     -command "NoFunction"

  set colorBoxSetColor ""
  if {"$colorBoxValue" != ""} {
    if {"$colorBoxType" != "text"} {
      .colorBox.current.current delete 0 end
      .colorBox.current.current insert 0 $colorBoxValue
    }
    if {[string match "*oreground*" $colorBoxMessage]} {
      catch ".colorBox.demo config -foreground $colorBoxValue"
    } {
      catch ".colorBox.demo config -background $colorBoxValue"
    }
    if {"$colorBoxTargetW" != ""} {
      catch "$colorBoxTargetW config -[string tolower $colorBoxMessage]         $colorBoxValue"
    }
  }
  case $colorBoxType in {
    {text palette} {
      if {[string match "*oreground*" $colorBoxMessage]} {
        set red [expr [lindex [winfo rgb .colorBox.demo [lindex [.colorBox.demo config -foreground] 4]] 0]/256]
        set green [expr [lindex [winfo rgb .colorBox.demo [lindex [.colorBox.demo config -foreground] 4]] 1]/256]
        set blue [expr [lindex [winfo rgb .colorBox.demo [lindex [.colorBox.demo config -foreground] 4]] 2]/256]
      } {
        set red [expr [lindex [winfo rgb .colorBox.demo [lindex [.colorBox.demo config -background] 4]] 0]/256]
        set green [expr [lindex [winfo rgb .colorBox.demo [lindex [.colorBox.demo config -background] 4]] 1]/256]
        set blue [expr [lindex [winfo rgb .colorBox.demo [lindex [.colorBox.demo config -background] 4]] 2]/256]
      }
      if {"$colorBox(type)" == "rgb"} {
        .colorBox.red set $red
        .colorBox.green set $green
        .colorBox.blue set $blue
      } {
        if {"$colorBox(type)" == "hsv"} {
          set colorBoxHSV [ColorBoxRGBToHSV [expr $red*256] [expr $green*256] [expr $blue*256]]
          .colorBox.h set [format %.0f [expr [lindex $colorBoxHSV 0]*1000.0]]
          .colorBox.s set [format %.0f [expr [lindex $colorBoxHSV 1]*1000.0]]
          .colorBox.v set [format %.0f [expr [lindex $colorBoxHSV 2]*1000.0]]
        }
      }
    }
  }
  .colorBox.red config     -command "ColorBoxSetRGBColor $colorBoxMessage \"$colorBoxTargetW\""
  .colorBox.green config     -command "ColorBoxSetRGBColor $colorBoxMessage \"$colorBoxTargetW\""
  .colorBox.blue config     -command "ColorBoxSetRGBColor $colorBoxMessage \"$colorBoxTargetW\""
  .colorBox.h config     -command "ColorBoxSetHSVColor $colorBoxMessage \"$colorBoxTargetW\""
  .colorBox.s config     -command "ColorBoxSetHSVColor $colorBoxMessage \"$colorBoxTargetW\""
  .colorBox.v config     -command "ColorBoxSetHSVColor $colorBoxMessage \"$colorBoxTargetW\""
}


# Procedure: ColorBoxSetHSVColor
proc ColorBoxSetHSVColor { colorBoxMessage colorBoxTargetW colorBoxValue} {
# xf ignore me 6
  global colorBox

  set colorBoxRGB [ColorBoxHSVToRGB [expr [.colorBox.h get]/1000.0] [expr [.colorBox.s get]/1000.0] [expr [.colorBox.v get]/1000.0]]
  ColorBoxSetColor $colorBoxMessage $colorBoxTargetW hsv     [format #%04x%04x%04x [lindex $colorBoxRGB 0] [lindex $colorBoxRGB 1] [lindex $colorBoxRGB 2]]
  ColorBoxSetPaletteList [format #%04x%04x%04x [lindex $colorBoxRGB 0] [lindex $colorBoxRGB 1] [lindex $colorBoxRGB 2]]
}


# Procedure: ColorBoxSetPalette
proc ColorBoxSetPalette { colorBoxMessage colorBoxTargetW colorBoxElement} {
# xf ignore me 6
  global colorBox

  set colorBox(paletteNr) $colorBoxElement
  ColorBoxSetColor $colorBoxMessage $colorBoxTargetW palette     [lindex [.colorBox.palette.palette$colorBoxElement config -background] 4]
}


# Procedure: ColorBoxSetPaletteList
proc ColorBoxSetPaletteList { colorBoxValue} {
# xf ignore me 6
  global colorBox

  catch ".colorBox.palette.palette$colorBox(paletteNr) config       -activebackground $colorBoxValue"
  catch ".colorBox.palette.palette$colorBox(paletteNr) config       -background $colorBoxValue"
  set colorBox(palette)     [lreplace $colorBox(palette) $colorBox(paletteNr) $colorBox(paletteNr)       $colorBoxValue]
}


# Procedure: ColorBoxSetRGBColor
proc ColorBoxSetRGBColor { colorBoxMessage colorBoxTargetW colorBoxValue} {
# xf ignore me 6
  global colorBox

  ColorBoxSetColor $colorBoxMessage $colorBoxTargetW rgb     [format #%02x%02x%02x [.colorBox.red get]       [.colorBox.green get] [.colorBox.blue get]]
  ColorBoxSetPaletteList [format #%02x%02x%02x [.colorBox.red get]     [.colorBox.green get] [.colorBox.blue get]]
}


# Procedure: ColorBoxShowSlides
proc ColorBoxShowSlides { colorBoxMessage colorBoxTargetW} {
# xf ignore me 6
  global colorBox

  catch "pack unpack .colorBox.frame1"
  catch "pack unpack .colorBox.frame2"
  catch "pack unpack .colorBox.current"
  catch "pack unpack .colorBox.demo"
  catch "pack unpack .colorBox.h"
  catch "pack unpack .colorBox.s"
  catch "pack unpack .colorBox.v"
  catch "pack unpack .colorBox.red"
  catch "pack unpack .colorBox.green"
  catch "pack unpack .colorBox.blue"
  catch "pack unpack .colorBox.colors"
  case $colorBox(type) in {
    {rgb} {
      pack append .colorBox                   .colorBox.frame1 {bottom fillx}                   .colorBox.frame2 {bottom fillx}                   .colorBox.current {bottom fillx}                   .colorBox.palette {bottom fillx}                   .colorBox.red {top fillx}                   .colorBox.green {top fillx}                   .colorBox.blue {top fillx}                   .colorBox.demo {bottom fill expand}
    }
    {hsv} {
      pack append .colorBox                   .colorBox.frame1 {bottom fillx}                   .colorBox.frame2 {bottom fillx}                   .colorBox.current {bottom fillx}                   .colorBox.palette {bottom fillx}                   .colorBox.h {top fillx}                   .colorBox.s {top fillx}                   .colorBox.v {top fillx}                   .colorBox.demo {bottom fill expand}
    }
    {list} {
      pack append .colorBox                   .colorBox.frame1 {bottom fillx}                   .colorBox.frame2 {bottom fillx}                   .colorBox.current {bottom fillx}                   .colorBox.palette {bottom fillx}                   .colorBox.demo {bottom fillx}                   .colorBox.colors {top fill expand}
    }
  }
  if {[string match "*oreground*" $colorBoxMessage]} {
    ColorBoxSetColor $colorBoxMessage $colorBoxTargetW text       [lindex [.colorBox.demo config -foreground] 4]
  } {
    ColorBoxSetColor $colorBoxMessage $colorBoxTargetW text       [lindex [.colorBox.demo config -background] 4]
  }
}


# Procedure: FSBox
proc FSBox { {fsBoxMessage "Select file:"} {fsBoxFileName ""} {fsBoxActionOk ""} {fsBoxActionCancel ""}} {
# xf ignore me 5
##########
# Procedure: FSBox
# Description: show file selector box
# Arguments: fsBoxMessage - the text to display
#            fsBoxFileName - a file name that should be selected
#            fsBoxActionOk - the action that should be performed on ok
#            fsBoxActionCancel - the action that should be performed on cancel
# Returns: the filename that was selected, or nothing
# Sideeffects: none
##########
# 
# global fsBox(activeBackground) - active background color
# global fsBox(activeForeground) - active foreground color
# global fsBox(background) - background color
# global fsBox(font) - text font
# global fsBox(foreground) - foreground color
# global fsBox(extensions) - scan directory for extensions
# global fsBox(scrollActiveForeground) - scrollbar active background color
# global fsBox(scrollBackground) - scrollbar background color
# global fsBox(scrollForeground) - scrollbar foreground color
# global fsBox(scrollSide) - side where scrollbar is located

  global fsBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  set tmpScaleOpt ""
  set tmpScrollOpt ""
  if {"$fsBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$fsBox(activeBackground)\" "
  }
  if {"$fsBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$fsBox(activeForeground)\" "
  }
  if {"$fsBox(background)" != ""} {
    append tmpButtonOpt "-background \"$fsBox(background)\" "
    append tmpFrameOpt "-background \"$fsBox(background)\" "
    append tmpMessageOpt "-background \"$fsBox(background)\" "
  }
  if {"$fsBox(font)" != ""} {
    append tmpButtonOpt "-font \"$fsBox(font)\" "
    append tmpMessageOpt "-font \"$fsBox(font)\" "
  }
  if {"$fsBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$fsBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$fsBox(foreground)\" "
  }
  if {"$fsBox(scrollActiveForeground)" != ""} {
    append tmpScrollOpt "-activeforeground \"$fsBox(scrollActiveForeground)\" "
  }
  if {"$fsBox(scrollBackground)" != ""} {
    append tmpScrollOpt "-background \"$fsBox(scrollBackground)\" "
  }
  if {"$fsBox(scrollForeground)" != ""} {
    append tmpScrollOpt "-foreground \"$fsBox(scrollForeground)\" "
  }

  if {[file exists [file tail $fsBoxFileName]] &&
      [IsAFile [file tail $fsBoxFileName]]} {
    set fsBox(name) [file tail $fsBoxFileName]
  } {
    set fsBox(name) ""
  }
  if {[file exists $fsBoxFileName] && [IsADir $fsBoxFileName]} {
    set fsBox(path) $fsBoxFileName
  } {
    if {"[file rootname $fsBoxFileName]" != "."} {
      set fsBox(path) [file rootname $fsBoxFileName]
    }
  }
  if {$fsBox(showPixmap)} {
    set fsBox(path) [string trimleft $fsBox(path) @]
  }
  if {"$fsBox(path)" != "" && [file exists $fsBox(path)] &&
      [IsADir $fsBox(path)]} {
    set fsBox(internalPath) $fsBox(path)
  } {
    if {"$fsBox(internalPath)" == "" ||
        ![file exists $fsBox(internalPath)]} {
      set fsBox(internalPath) [pwd]
    }
  }
  # build widget structure

  # start build of toplevel
  if {"[info commands XFDestroy]" != ""} {
    catch {XFDestroy .fsBox}
  } {
    catch {destroy .fsBox}
  }
  toplevel .fsBox     -borderwidth 0
  catch ".fsBox config $tmpFrameOpt"
  wm geometry .fsBox 350x300 
  wm title .fsBox {File select box}
  wm maxsize .fsBox 1000 1000
  wm minsize .fsBox 100 100
  # end build of toplevel

  label .fsBox.message1     -anchor c     -relief raised     -text "$fsBoxMessage"
  catch ".fsBox.message1 config $tmpMessageOpt"

  frame .fsBox.frame1     -borderwidth 0     -relief raised
  catch ".fsBox.frame1 config $tmpFrameOpt"

  button .fsBox.frame1.ok     -text "OK"     -command "
      global fsBox
      set fsBox(name) \[.fsBox.file.file get\]
      if {$fsBox(showPixmap)} {
        set fsBox(path) @\[.fsBox.path.path get\]
      } {
        set fsBox(path) \[.fsBox.path.path get\]
      }
      set fsBox(internalPath) \[.fsBox.path.path get\]
      $fsBoxActionOk
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy .fsBox}
      } {
        catch {destroy .fsBox}
      }"
  catch ".fsBox.frame1.ok config $tmpButtonOpt"

  button .fsBox.frame1.rescan     -text "Rescan"     -command {
      global fsBox
      FSBoxFSShow [.fsBox.path.path get]         [.fsBox.pattern.pattern get] $fsBox(all)}
  catch ".fsBox.frame1.rescan config $tmpButtonOpt"

  button .fsBox.frame1.cancel     -text "Cancel"     -command "
      global fsBox
      set fsBox(name) {}
      set fsBox(path) {}
      $fsBoxActionCancel
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy .fsBox}
      } {
        catch {destroy .fsBox}
      }"
  catch ".fsBox.frame1.cancel config $tmpButtonOpt"

  if {$fsBox(showPixmap)} {
    frame .fsBox.frame2       -borderwidth 0       -relief raised
    catch ".fsBox.frame2 config $tmpFrameOpt"

    scrollbar .fsBox.frame2.scrollbar3       -command {.fsBox.frame2.canvas2 xview}       -orient {horizontal}       -relief {raised}
    catch ".fsBox.frame2.scrollbar3 config $tmpScrollOpt"

    scrollbar .fsBox.frame2.scrollbar1       -command {.fsBox.frame2.canvas2 yview}       -relief {raised}
    catch ".fsBox.frame2.scrollbar1 config $tmpScrollOpt"

    canvas .fsBox.frame2.canvas2       -confine {true}       -relief {raised}       -scrollregion {0c 0c 20c 20c}       -width {100}       -xscrollcommand {.fsBox.frame2.scrollbar3 set}       -yscrollcommand {.fsBox.frame2.scrollbar1 set}
    catch ".fsBox.frame2.canvas2 config $tmpFrameOpt"

    .fsBox.frame2.canvas2 addtag currentBitmap withtag [.fsBox.frame2.canvas2 create bitmap 5 5 -anchor nw]
  }

  frame .fsBox.path     -borderwidth 0     -relief raised
  catch ".fsBox.path config $tmpFrameOpt"

  frame .fsBox.path.paths     -borderwidth 2     -relief raised
  catch ".fsBox.path.paths config $tmpFrameOpt"

  menubutton .fsBox.path.paths.paths     -borderwidth 0     -menu ".fsBox.path.paths.paths.menu"     -relief flat     -text "Pathname:"
  catch ".fsBox.path.paths.paths config $tmpButtonOpt"

  menu .fsBox.path.paths.paths.menu
  catch ".fsBox.path.paths.paths.menu config $tmpButtonOpt"

  .fsBox.path.paths.paths.menu add command      -label "[string trimright $fsBox(internalPath) {/@}]"      -command "
       global fsBox
       FSBoxFSShow \[.fsBox.path.path get\]          \[.fsBox.pattern.pattern get\] \$fsBox(all)
       .fsBox.path.path delete 0 end
       .fsBox.path.path insert 0 [string trimright $fsBox(internalPath) {/@}]"

  entry .fsBox.path.path     -relief raised
  catch ".fsBox.path.path config $tmpMessageOpt"

  if {![IsADir $fsBox(internalPath)]} {
    set $fsBox(internalPath) [pwd]
  }
  .fsBox.path.path insert 0 $fsBox(internalPath)

  frame .fsBox.pattern     -borderwidth 0     -relief raised
  catch ".fsBox.pattern config $tmpFrameOpt"

  frame .fsBox.pattern.patterns     -borderwidth 2     -relief raised
  catch ".fsBox.pattern.patterns config $tmpFrameOpt"

  menubutton .fsBox.pattern.patterns.patterns     -borderwidth 0     -menu ".fsBox.pattern.patterns.patterns.menu"     -relief flat     -text "Selection pattern:"
  catch ".fsBox.pattern.patterns.patterns config $tmpButtonOpt"

  menu .fsBox.pattern.patterns.patterns.menu
  catch ".fsBox.pattern.patterns.patterns.menu config $tmpButtonOpt"

  .fsBox.pattern.patterns.patterns.menu add checkbutton     -label "Scan extensions"     -variable fsBoxExtensions     -command {
      global fsBox
      FSBoxFSShow [.fsBox.path.path get]         [.fsBox.pattern.pattern get] $fsBox(all)}

  entry .fsBox.pattern.pattern     -relief raised
  catch ".fsBox.pattern.pattern config $tmpMessageOpt"

  .fsBox.pattern.pattern insert 0 $fsBox(pattern)
  
  frame .fsBox.files     -borderwidth 0     -relief raised
  catch ".fsBox.files config $tmpFrameOpt"

  scrollbar .fsBox.files.vscroll     -relief raised     -command ".fsBox.files.files yview"
  catch ".fsBox.files.vscroll config $tmpScrollOpt"

  scrollbar .fsBox.files.hscroll     -orient horiz     -relief raised     -command ".fsBox.files.files xview"
  catch ".fsBox.files.hscroll config $tmpScrollOpt"

  listbox .fsBox.files.files     -exportselection false     -relief raised     -xscrollcommand ".fsBox.files.hscroll set"     -yscrollcommand ".fsBox.files.vscroll set"
  catch ".fsBox.files.files config $tmpMessageOpt"

  frame .fsBox.file     -borderwidth 0     -relief raised
  catch ".fsBox.file config $tmpFrameOpt"

  label .fsBox.file.labelfile     -relief raised     -text "Filename:"
  catch ".fsBox.file.labelfile config $tmpMessageOpt"

  entry .fsBox.file.file     -relief raised
  catch ".fsBox.file.file config $tmpMessageOpt"

  .fsBox.file.file delete 0 end
  .fsBox.file.file insert 0 $fsBox(name)
  
  checkbutton .fsBox.pattern.all     -offvalue 0     -onvalue 1     -text "Show all files"     -variable fsBox(all)     -command {
      global fsBox
      FSBoxFSShow [.fsBox.path.path get]         [.fsBox.pattern.pattern get] $fsBox(all)}
  catch ".fsBox.pattern.all config $tmpButtonOpt"

  FSBoxFSShow $fsBox(internalPath) $fsBox(pattern) $fsBox(all)

  # bindings
  bind .fsBox.files.files <Double-Button-1> "
    FSBoxFSFileSelectDouble %W $fsBox(showPixmap) \{$fsBoxActionOk\} %y"
  bind .fsBox.files.files <ButtonPress-1> "
    FSBoxFSFileSelect %W $fsBox(showPixmap) %y"
  bind .fsBox.files.files <Button1-Motion> "
    FSBoxFSFileSelect %W $fsBox(showPixmap) %y"
  bind .fsBox.files.files <Shift-Button1-Motion> "
    FSBoxFSFileSelect %W $fsBox(showPixmap) %y"
  bind .fsBox.files.files <Shift-ButtonPress-1> "
    FSBoxFSFileSelect %W $fsBox(showPixmap) %y"

  bind .fsBox.path.path <Tab> {
    FSBoxFSNameComplete path}
  bind .fsBox.path.path <Return> {
    global tkVersion
    global fsBox
    FSBoxFSShow [.fsBox.path.path get]       [.fsBox.pattern.pattern get] $fsBox(all)
    FSBoxFSInsertPath
    if {$tkVersion >= 3.0} {
      .fsBox.file.file icursor end
    } {
      .fsBox.file.file cursor end
    }
    focus .fsBox.file.file}
  catch "bind .fsBox.path.path <Up> {}"
  bind .fsBox.path.path <Down> {
    global tkVersion
    if {$tkVersion >= 3.0} {
      .fsBox.file.file icursor end
    } {
      .fsBox.file.file cursor end
    }
    focus .fsBox.file.file}

  bind .fsBox.file.file <Tab> {
    FSBoxFSNameComplete file}
  bind .fsBox.file.file <Return> "
    global fsBox
    set fsBox(name) \[.fsBox.file.file get\]
    if {$fsBox(showPixmap)} {
      set fsBox(path) @\[.fsBox.path.path get\]
    } {
      set fsBox(path) \[.fsBox.path.path get\]
    }
    set fsBox(internalPath) \[.fsBox.path.path get\]
    $fsBoxActionOk
    if {\"\[info commands XFDestroy\]\" != \"\"} {
      catch {XFDestroy .fsBox}
    } {
      catch {destroy .fsBox}
    }"
  bind .fsBox.file.file <Up> {
    global tkVersion
    if {$tkVersion >= 3.0} {
      .fsBox.path.path icursor end
    } {
      .fsBox.path.path cursor end
    }
    focus .fsBox.path.path}
  bind .fsBox.file.file <Down> {
    global tkVersion
    if {$tkVersion >= 3.0} {
      .fsBox.pattern.pattern icursor end
    } {
      .fsBox.pattern.pattern cursor end
    }
    focus .fsBox.pattern.pattern}

  bind .fsBox.pattern.pattern <Return> {
    global fsBox
    FSBoxFSShow [.fsBox.path.path get]       [.fsBox.pattern.pattern get] $fsBox(all)}
  bind .fsBox.pattern.pattern <Up> {
    global tkVersion
    if {$tkVersion >= 3.0} {
      .fsBox.file.file icursor end
    } {
      .fsBox.file.file cursor end
    }
    focus .fsBox.file.file}
  catch "bind .fsBox.pattern.pattern <Down> {}"

  # packing
  pack append .fsBox.files               .fsBox.files.vscroll "$fsBox(scrollSide) filly"               .fsBox.files.hscroll {bottom fillx}               .fsBox.files.files {left fill expand}
  pack append .fsBox.file               .fsBox.file.labelfile {left}               .fsBox.file.file {left fill expand}
  pack append .fsBox.frame1               .fsBox.frame1.ok {left fill expand}               .fsBox.frame1.rescan {left fill expand}               .fsBox.frame1.cancel {left fill expand}
  pack append .fsBox.path.paths               .fsBox.path.paths.paths {left}
  pack append .fsBox.pattern.patterns               .fsBox.pattern.patterns.patterns {left}
  pack append .fsBox.path               .fsBox.path.paths {left}               .fsBox.path.path {left fill expand}
  pack append .fsBox.pattern               .fsBox.pattern.patterns {left}               .fsBox.pattern.all {right fill}               .fsBox.pattern.pattern {left fill expand}
  if {$fsBox(showPixmap)} {
    pack append .fsBox.frame2                 .fsBox.frame2.scrollbar1 {left filly}                 .fsBox.frame2.canvas2 {top expand fill}                 .fsBox.frame2.scrollbar3 {top fillx} 

    pack append .fsBox                 .fsBox.message1 {top fill}                 .fsBox.frame1 {bottom fill}                 .fsBox.pattern {bottom fill}                 .fsBox.file {bottom fill}                 .fsBox.path {bottom fill}                 .fsBox.frame2 {right fill}                 .fsBox.files {left fill expand}
  } {
    pack append .fsBox                 .fsBox.message1 {top fill}                 .fsBox.frame1 {bottom fill}                 .fsBox.pattern {bottom fill}                 .fsBox.file {bottom fill}                 .fsBox.path {bottom fill}                 .fsBox.files {left fill expand}
  }

  if {"$fsBoxActionOk" == "" && "$fsBoxActionCancel" == ""} {
    # wait for the box to be destroyed
    update idletask
    grab .fsBox
    tkwait window .fsBox

    if {"[string trim $fsBox(path)]" != "" ||
        "[string trim $fsBox(name)]" != ""} {
      if {"[string trimleft [string trim $fsBox(name)] /]" == ""} {
        return [string trimright [string trim $fsBox(path)] /]
      } {
        return [string trimright [string trim $fsBox(path)] /]/[string trimleft [string trim $fsBox(name)] /]
      }
    }
  }
}


# Procedure: FSBoxBindSelectOne
proc FSBoxBindSelectOne { fsBoxW fsBoxY} {
# xf ignore me 6

  set fsBoxNearest [$fsBoxW nearest $fsBoxY]
  if {$fsBoxNearest >= 0} {
    $fsBoxW select from $fsBoxNearest
    $fsBoxW select to $fsBoxNearest
  }
}


# Procedure: FSBoxFSFileSelect
proc FSBoxFSFileSelect { fsBoxW fsBoxShowPixmap fsBoxY} {
# xf ignore me 6
  global fsBox

  FSBoxBindSelectOne $fsBoxW $fsBoxY
  set fsBoxNearest [$fsBoxW nearest $fsBoxY]
  if {$fsBoxNearest >= 0} {
    set fsBoxTmpEntry [$fsBoxW get $fsBoxNearest]
    if {"[string index $fsBoxTmpEntry           [expr [string length $fsBoxTmpEntry]-1]]" == "/" ||
        "[string index $fsBoxTmpEntry           [expr [string length $fsBoxTmpEntry]-1]]" == "@"} {
      set fsBoxFileName [string range $fsBoxTmpEntry 0             [expr [string length $fsBoxTmpEntry]-2]]
      if {![IsADir [string trimright $fsBox(internalPath)/$fsBoxFileName @]] &&
          ![IsASymlink [string trimright $fsBox(internalPath)/$fsBoxFileName @]]} {
        set fsBoxFileName $fsBoxTmpEntry
      }
    } {
      if {"[string index $fsBoxTmpEntry             [expr [string length $fsBoxTmpEntry]-1]]" == "*"} {
        set fsBoxFileName [string range $fsBoxTmpEntry 0           [expr [string length $fsBoxTmpEntry]-2]]
        if {![file executable $fsBox(internalPath)/$fsBoxFileName]} {
          set fsBoxFileName $fsBoxTmpEntry
        }
      } {
        set fsBoxFileName $fsBoxTmpEntry
      }
    }
    if {![IsADir [string trimright $fsBox(internalPath)/$fsBoxFileName @]]} {
      set fsBox(name) $fsBoxFileName
      .fsBox.file.file delete 0 end
      .fsBox.file.file insert 0 $fsBox(name)
      if {$fsBoxShowPixmap} {
        catch ".fsBox.frame2.canvas2 itemconfigure currentBitmap -bitmap \"@$fsBox(internalPath)/$fsBox(name)\""
      }
    }
  }
}


# Procedure: FSBoxFSFileSelectDouble
proc FSBoxFSFileSelectDouble { fsBoxW fsBoxShowPixmap fsBoxAction fsBoxY} {
# xf ignore me 6
  global fsBox

  FSBoxBindSelectOne $fsBoxW $fsBoxY
  set fsBoxNearest [$fsBoxW nearest $fsBoxY]
  if {$fsBoxNearest >= 0} {
    set fsBoxTmpEntry [$fsBoxW get $fsBoxNearest]
    if {"$fsBoxTmpEntry" == "../"} {
      set fsBoxTmpEntry [string trimright [string trim $fsBox(internalPath)] "@/"]
      if {"$fsBoxTmpEntry" == ""} {
        return
      }
      FSBoxFSShow [file dirname $fsBoxTmpEntry]         [.fsBox.pattern.pattern get] $fsBox(all)
      .fsBox.path.path delete 0 end
      .fsBox.path.path insert 0 $fsBox(internalPath)
    } {
      if {"[string index $fsBoxTmpEntry             [expr [string length $fsBoxTmpEntry]-1]]" == "/" ||
          "[string index $fsBoxTmpEntry             [expr [string length $fsBoxTmpEntry]-1]]" == "@"} {
        set fsBoxFileName [string range $fsBoxTmpEntry 0               [expr [string length $fsBoxTmpEntry]-2]]
        if {![IsADir [string trimright $fsBox(internalPath)/$fsBoxFileName @]] &&
            ![IsASymlink [string trimright $fsBox(internalPath)/$fsBoxFileName @]]} {
          set fsBoxFileName $fsBoxTmpEntry
        }
      } {
        if {"[string index $fsBoxTmpEntry               [expr [string length $fsBoxTmpEntry]-1]]" == "*"} {
          set fsBoxFileName [string range $fsBoxTmpEntry 0                 [expr [string length $fsBoxTmpEntry]-2]]
          if {![file executable $fsBox(internalPath)/$fsBoxFileName]} {
            set fsBoxFileName $fsBoxTmpEntry
          }
        } {
          set fsBoxFileName $fsBoxTmpEntry
        }
      }
      if {[IsADir [string trimright $fsBox(internalPath)/$fsBoxFileName @]]} {
        set fsBox(internalPath) "[string trimright $fsBox(internalPath) {/@}]/$fsBoxFileName"
        FSBoxFSShow $fsBox(internalPath)           [.fsBox.pattern.pattern get] $fsBox(all)
        .fsBox.path.path delete 0 end
        .fsBox.path.path insert 0 $fsBox(internalPath)
      } {
        set fsBox(name) $fsBoxFileName
        if {$fsBoxShowPixmap} {
          set fsBox(path) @$fsBox(internalPath)
        } {
          set fsBox(path) $fsBox(internalPath)
        }
        if {"$fsBoxAction" != ""} {
          eval "global fsBox; $fsBoxAction"
        }
        if {"[info commands XFDestroy]" != ""} {
          catch {XFDestroy .fsBox}
        } {
          catch {destroy .fsBox}
        }
      }
    }
  }
}


# Procedure: FSBoxFSInsertPath
proc FSBoxFSInsertPath {} {
# xf ignore me 6
  global fsBox

  set fsBoxLast [.fsBox.path.paths.paths.menu index last]
  set fsBoxNewEntry [string trimright [.fsBox.path.path get] "/@"]
  for {set fsBoxCounter 0} {$fsBoxCounter <= $fsBoxLast} {incr fsBoxCounter 1} {
    if {"$fsBoxNewEntry" ==           "[lindex [.fsBox.path.paths.paths.menu entryconfigure                     $fsBoxCounter -label] 4]"} {
      return
    }
  }
  if {$fsBoxLast < 9} {
    .fsBox.path.paths.paths.menu add command       -label "$fsBoxNewEntry"       -command "
        global fsBox
        FSBoxFSShow $fsBoxNewEntry           \[.fsBox.pattern.pattern get\] \$fsBox(all)
        .fsBox.path.path delete 0 end
        .fsBox.path.path insert 0 $fsBoxNewEntry"
  } {
    for {set fsBoxCounter 0} {$fsBoxCounter < $fsBoxLast} {incr fsBoxCounter 1} {
      .fsBox.path.paths.paths.menu entryconfigure         $fsBoxCounter -label           [lindex [.fsBox.path.paths.paths.menu entryconfigure             [expr $fsBoxCounter+1] -label] 4]
      .fsBox.path.paths.paths.menu entryconfigure $fsBoxCounter         -command "
          global fsBox
          FSBoxFSShow [lindex [.fsBox.path.paths.paths.menu entryconfigure             [expr $fsBoxCounter+1] -label] 4]             \[.fsBox.pattern.pattern get\] \$fsBox(all)
          .fsBox.path.path delete 0 end
          .fsBox.path.path insert 0 [lindex             [.fsBox.path.paths.paths.menu entryconfigure               [expr $fsBoxCounter+1] -label] 4]"
    }
    .fsBox.path.paths.paths.menu entryconfigure $fsBoxLast       -label "$fsBoxNewEntry"
    .fsBox.path.paths.paths.menu entryconfigure $fsBoxCounter       -command "
        global fsBox
        FSBoxFSShow \[.fsBox.path.path get\]           \[.fsBox.pattern.pattern get\] \$fsBox(all)
        .fsBox.path.path delete 0 end
        .fsBox.path.path insert 0 $fsBoxNewEntry"
  }
}


# Procedure: FSBoxFSNameComplete
proc FSBoxFSNameComplete { fsBoxType} {
# xf ignore me 6
  global tkVersion
  global fsBox

  set fsBoxNewFile ""
  if {"$fsBoxType" == "path"} {
    set fsBoxDirName [file dirname [.fsBox.path.path get]]
    set fsBoxFileName [file tail [.fsBox.path.path get]]
  } {
    set fsBoxDirName [file dirname [.fsBox.path.path get]/]
    set fsBoxFileName [file tail [.fsBox.file.file get]]
  }

  set fsBoxNewFile ""
  if {[IsADir [string trimright $fsBoxDirName @]]} {
    catch "glob -nocomplain $fsBoxDirName/${fsBoxFileName}*" fsBoxResult
    foreach fsBoxCounter $fsBoxResult {
      if {"$fsBoxNewFile" == ""} {
        set fsBoxNewFile [file tail $fsBoxCounter]
      } {
        if {"[string index [file tail $fsBoxCounter] 0]" !=
            "[string index $fsBoxNewFile 0]"} {
          set fsBoxNewFile ""
          break
        }
        set fsBoxCounter1 0
        set fsBoxTmpFile1 $fsBoxNewFile
        set fsBoxTmpFile2 [file tail $fsBoxCounter]
        set fsBoxLength1 [string length $fsBoxTmpFile1]
        set fsBoxLength2 [string length $fsBoxTmpFile2]
        set fsBoxNewFile ""
        if {$fsBoxLength1 > $fsBoxLength2} {
          set fsBoxLength1 $fsBoxLength2
        }
        while {$fsBoxCounter1 < $fsBoxLength1} {
          if {"[string index $fsBoxTmpFile1 $fsBoxCounter1]" ==                 "[string index $fsBoxTmpFile2 $fsBoxCounter1]"} {
            append fsBoxNewFile [string index $fsBoxTmpFile1 $fsBoxCounter1]
          } {
            break
          }
          incr fsBoxCounter1 1
        }
      }
    }
  }
  if {"$fsBoxNewFile" != ""} {
    if {[IsADir [string trimright $fsBoxDirName/$fsBoxNewFile @]] ||
        ![IsAFile [string trimright $fsBoxDirName/$fsBoxNewFile @]]} {
      if {[IsADir [string trimright $fsBoxDirName/$fsBoxNewFile @]]} {
        if {"$fsBoxDirName" == "/"} {
          .fsBox.path.path delete 0 end
          .fsBox.path.path insert 0 "/[string trimright [string trim $fsBoxNewFile /] @]/"
        } {
          .fsBox.path.path delete 0 end
          .fsBox.path.path insert 0 "[string trimright $fsBoxDirName /]/[string trimright [string trim $fsBoxNewFile /] @]/"
        }
        FSBoxFSShow [.fsBox.path.path get]           [.fsBox.pattern.pattern get] $fsBox(all)
        FSBoxFSInsertPath
      } {
        .fsBox.path.path delete 0 end
        .fsBox.path.path insert 0 "[string trimright $fsBoxDirName /]/[string trimright [string trim $fsBoxNewFile /] @]"
      }
    } {
      .fsBox.path.path delete 0 end
      .fsBox.path.path insert 0 "[string trimright $fsBoxDirName {@/}]/"
      .fsBox.file.file delete 0 end
      .fsBox.file.file insert 0 $fsBoxNewFile
      if {$tkVersion >= 3.0} {
        .fsBox.file.file icursor end
      } {
        .fsBox.file.file cursor end
      }
      focus .fsBox.file.file
    }
  }
}


# Procedure: FSBoxFSShow
proc FSBoxFSShow { fsBoxPath fsBoxPattern fsBoxAll} {
# xf ignore me 6
  global fsBox

  set tmpButtonOpt ""
  if {"$fsBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$fsBox(activeBackground)\" "
  }
  if {"$fsBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$fsBox(activeForeground)\" "
  }
  if {"$fsBox(background)" != ""} {
    append tmpButtonOpt "-background \"$fsBox(background)\" "
  }
  if {"$fsBox(font)" != ""} {
    append tmpButtonOpt "-font \"$fsBox(font)\" "
  }
  if {"$fsBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$fsBox(foreground)\" "
  }

  set fsBox(pattern) $fsBoxPattern
  if {[file exists $fsBoxPath] && [file readable $fsBoxPath] &&
      [IsADir $fsBoxPath]} {
    set fsBox(internalPath) $fsBoxPath
  } {
    if {[file exists $fsBoxPath] && [file readable $fsBoxPath] &&
        [IsAFile $fsBoxPath]} {
      set fsBox(internalPath) [file dirname $fsBoxPath]
      .fsBox.file.file delete 0 end
      .fsBox.file.file insert 0 [file tail $fsBoxPath]
      set fsBoxPath $fsBox(internalPath)
    } {
      while {"$fsBoxPath" != "" && "$fsBoxPath" != "/" &&
             ![file isdirectory $fsBoxPath]} {
        set fsBox(internalPath) [file dirname $fsBoxPath]
         set fsBoxPath $fsBox(internalPath)
      }
    }
  }
  if {"$fsBoxPath" == ""} {
    set fsBoxPath "/"
    set fsBox(internalPath) "/"
  }
  .fsBox.path.path delete 0 end
  .fsBox.path.path insert 0 $fsBox(internalPath)

  if {[.fsBox.files.files size] > 0} {
    .fsBox.files.files delete 0 end
  }
  if {$fsBoxAll} {
    if {[catch "exec ls -F -a $fsBoxPath" fsBoxResult]} {
      puts stderr "$fsBoxResult"
    }
  } {
    if {[catch "exec ls -F $fsBoxPath" fsBoxResult]} {
      puts stderr "$fsBoxResult"
    }
  }
  set fsBoxElementList [lsort $fsBoxResult]

  foreach fsBoxCounter [winfo children .fsBox.pattern.patterns.patterns] {
    if {[string length [info commands XFDestroy]] > 0} {
      catch {XFDestroy $fsBoxCounter}
    } {
      catch {destroy $fsBoxCounter}
    }
  }
  menu .fsBox.pattern.patterns.patterns.menu
  catch ".fsBox.pattern.patterns.patterns.menu config $tmpButtonOpt"

  if {$fsBox(extensions)} {
    .fsBox.pattern.patterns.patterns.menu add command       -label "*"       -command {
        global fsBox
        set fsBox(pattern) "*"
        .fsBox.pattern.pattern delete 0 end
        .fsBox.pattern.pattern insert 0 $fsBox(pattern)
        FSBoxFSShow [.fsBox.path.path get] $fsBox(pattern)           $fsBox(all)}
  }

  if {"$fsBoxPath" != "/"} {
    .fsBox.files.files insert end "../"
  }
  foreach fsBoxCounter $fsBoxElementList {
    if {[string match $fsBoxPattern $fsBoxCounter] ||
        [IsADir [string trimright $fsBoxPath/$fsBoxCounter "/@"]]} {
      if {"$fsBoxCounter" != "../" &&
          "$fsBoxCounter" != "./"} {
        .fsBox.files.files insert end $fsBoxCounter
      }
    }

    if {$fsBox(extensions)} {
      catch "file rootname $fsBoxCounter" fsBoxRootName
      catch "file extension $fsBoxCounter" fsBoxExtension
      set fsBoxExtension [string trimright $fsBoxExtension "/*@"]
      if {"$fsBoxExtension" != "" && "$fsBoxRootName" != ""} {
        set fsBoxInsert 1
        set fsBoxLast [.fsBox.pattern.patterns.patterns.menu index last]
        for {set fsBoxCounter1 0} {$fsBoxCounter1 <= $fsBoxLast} {incr fsBoxCounter1 1} {
          if {"*$fsBoxExtension" ==                 "[lindex [.fsBox.pattern.patterns.patterns.menu entryconfigure                         $fsBoxCounter1 -label] 4]"} {
            set fsBoxInsert 0
          }
        }
	if {$fsBoxInsert} {
          .fsBox.pattern.patterns.patterns.menu add command             -label "*$fsBoxExtension"             -command "
              global fsBox
              set fsBox(pattern) \"*$fsBoxExtension\"
              .fsBox.pattern.pattern delete 0 end
              .fsBox.pattern.pattern insert 0 \$fsBox(pattern)
              FSBoxFSShow \[.fsBox.path.path get\] \$fsBox(pattern)                 \$fsBox(all)"
        }
      }
    }
  }
  if {$fsBox(extensions)} {
    .fsBox.pattern.patterns.patterns.menu add separator
  }
  if {$fsBox(extensions) || 
      "[.fsBox.pattern.patterns.patterns.menu index last]" == "none"} {
    .fsBox.pattern.patterns.patterns.menu add checkbutton       -label "Scan extensions"       -variable "fsBox(extensions)"       -command {
        global fsBox
        FSBoxFSShow [.fsBox.path.path get]           [.fsBox.pattern.pattern get] $fsBox(all)}
  }
}


# Procedure: Fill
proc Fill { widget tag} {
  global currentColor
  global currentHeight
  global currentWidth

  set startY [string range $tag 5 [expr [string first - $tag]-1]]
  set startX [string range $tag [expr [string first - $tag]+1] end]
  set oldColor [lindex [$widget itemconfigure $tag -fill] 4]
  FillIt $widget $oldColor $startY $startX
  .frame1.frame1.button5 deselect
}


# Procedure: FillIt
proc FillIt { widget oldColor yPos xPos} {
  global currentColor
  global currentHeight
  global currentWidth

  lappend itemList "pixel$yPos-$xPos"
  lappend setList "pixel$yPos-$xPos"
  while {1} {
    if {[llength $itemList] == 0} {
      break
    }
    set tag [lindex $itemList 0]
    set yPos [string range $tag 5 [expr [string first - $tag]-1]]
    set xPos [string range $tag [expr [string first - $tag]+1] end]
    set itemList [lrange $itemList 1 end]
    if {"[lindex [$widget itemconfigure "pixel$yPos-$xPos" -fill] 4]" == "$oldColor"} {
      catch "$widget itemconfigure \"pixel$yPos-$xPos\" -fill $currentColor"
      update
    } {
      continue
    }
    if {$xPos > 0} {
      if {"[lindex [$widget itemconfigure "pixel$yPos-[expr $xPos-1]" -fill] 4]" == "$oldColor"} {
        if {[lsearch $setList "pixel$yPos-[expr $xPos-1]"] == -1} {
          lappend itemList "pixel$yPos-[expr $xPos-1]"
          lappend setList "pixel$yPos-[expr $xPos-1]"
	}
      }
    }
    if {$xPos < $currentWidth} {
      if {"[lindex [$widget itemconfigure "pixel$yPos-[expr $xPos+1]" -fill] 4]" == "$oldColor"} {
        if {[lsearch $setList "pixel$yPos-[expr $xPos+1]"] == -1} {
          lappend itemList "pixel$yPos-[expr $xPos+1]"
          lappend setList "pixel$yPos-[expr $xPos+1]"
	}
      }
    }
    if {$yPos > 0} {
      if {"[lindex [$widget itemconfigure "pixel[expr $yPos-1]-$xPos" -fill] 4]" == "$oldColor"} {
        if {[lsearch $setList "pixel[expr $yPos-1]-$xPos"] == -1} {
          lappend itemList "pixel[expr $yPos-1]-$xPos"
          lappend setList "pixel[expr $yPos-1]-$xPos"
	}
      }
    }
    if {$yPos < $currentHeight} {
      if {"[lindex [$widget itemconfigure "pixel[expr $yPos+1]-$xPos" -fill] 4]" == "$oldColor"} {
        if {[lsearch $setList "pixel[expr $yPos+1]-$xPos"] == -1} {
          lappend itemList "pixel[expr $yPos+1]-$xPos"
          lappend setList "pixel[expr $yPos+1]-$xPos"
	}
      }
    }
  }
}


# Procedure: GetSelection
if {"[info procs GetSelection]" == ""} {
proc GetSelection {} {
# xf ignore me 7
##########
# Procedure: GetSelection
# Description: get current selection
# Arguments: none
# Returns: none
# Sideeffects: none
##########

  # the save way
  set xfSelection ""
  catch "selection get" xfSelection
  if {"$xfSelection" == "selection doesn't exist or form \"STRING\" not defined"} {
    return ""
  } {
    return $xfSelection
  }
}
}


# Procedure: IsADir
proc IsADir { pathName} {
# xf ignore me 5
##########
# Procedure: IsADir
# Description: check if name is a directory (including symbolic links)
# Arguments: pathName - the path to check
# Returns: 1 if its a directory, otherwise 0
# Sideeffects: none
##########

  if {[file isdirectory $pathName]} {
    return 1
  } {
    catch "file type $pathName" fileType
    if {"$fileType" == "link"} {
      if {[catch "file readlink $pathName" linkName]} {
        return 0
      }
      catch "file type $linkName" fileType
      while {"$fileType" == "link"} {
        if {[catch "file readlink $linkName" linkName]} {
          return 0
        }
        catch "file type $linkName" fileType
      }
      return [file isdirectory $linkName]
    }
  }
  return 0
}


# Procedure: IsAFile
proc IsAFile { fileName} {
# xf ignore me 5
##########
# Procedure: IsAFile
# Description: check if filename is a file (including symbolic links)
# Arguments: fileName - the filename to check
# Returns: 1 if its a file, otherwise 0
# Sideeffects: none
##########

  if {[file isfile $fileName]} {
    return 1
  } {
    catch "file type $fileName" fileType
    if {"$fileType" == "link"} {
      if {[catch "file readlink $fileName" linkName]} {
        return 0
      }
      catch "file type $linkName" fileType
      while {"$fileType" == "link"} {
        if {[catch "file readlink $linkName" linkName]} {
          return 0
        }
        catch "file type $linkName" fileType
      }
      return [file isfile $linkName]
    }
  }
  return 0
}


# Procedure: IsASymlink
proc IsASymlink { fileName} {
# xf ignore me 5
##########
# Procedure: IsASymlink
# Description: check if filename is a symbolic link
# Arguments: fileName - the path/filename to check
# Returns: none
# Sideeffects: none
##########

  catch "file type $fileName" fileType
  if {"$fileType" == "link"} {
    return 1
  }
  return 0
}


# Procedure: LoadFile
proc LoadFile { loadFile} {

  if {"$loadFile" == "tkxpm.xpm" ||
      ([file exists $loadFile] &&
       [file readable $loadFile] &&
       "[file type $loadFile]" == "file")} {
    if {[catch "pinfo get @$loadFile"]} {
      AlertBox "Error when reading: $loadFile"
      return
    }
    set tmpCanvas [SymbolicName drawSpace]
    set pixmapData [lindex [pinfo data @$loadFile xpm3] 1]
    set tmpWidth [lindex [lindex $pixmapData 0] 0]
    set tmpHeight [lindex [lindex $pixmapData 0] 1]
    set tmpColorNumber [lindex [lindex $pixmapData 0] 2]
    set tmpCharPerPixel [lindex [lindex $pixmapData 0] 3]
    if {$tmpColorNumber > 38} {
      puts stderr "Too many colors in picture for tkxpm."
      return
    }
    .frame1.frame3.scale6 set $tmpWidth
    .frame1.frame3.scale7 set $tmpHeight
    SetRaster

    set colorCounter 0
    while {$colorCounter < $tmpColorNumber} {
      set line [lindex $pixmapData [expr $colorCounter+1]]
      set matchVar ""
      if {[regexp {[ 	]c #[a-zA-Z0-9]*} $line matchVar] == 0} {
        if {[regexp {[ 	]c [a-zA-Z0-9]*} $line matchVar] == 0} {
          if {[regexp {[ 	]m #[a-zA-Z0-9]*} $line matchVar] == 0} {
            if {[regexp {[ 	]m [a-zA-Z0-9]*} $line matchVar] == 0} {
              puts stderr "XPM Format error"
              return
            }
          }
        }
      }
      set tmpColor [string range [string trim $matchVar] 2 end]
      if {$colorCounter < 36} {
        if {"[string range $matchVar 3 end]" == "none" ||
            "[string range $matchVar 3 end]" == "None"} {
          set "colors([string range $line 0 [expr $tmpCharPerPixel-1]])" {#3abdbc}
          [SymbolicName TransparentColor] config -foreground {#3abdbc}
          set currentTransparentColor {#3abdbc}
        } {
          set "colors([string range $line 0 [expr $tmpCharPerPixel-1]])" "$tmpColor"
          [SymbolicName Color$colorCounter] config -activeforeground "$tmpColor"
          [SymbolicName Color$colorCounter] config -background "$tmpColor"
          [SymbolicName Color$colorCounter] config -foreground "$tmpColor"
        }
      } {
        if {$colorCounter == 36} {
          set "colors([string range $line 0 [expr $tmpCharPerPixel-1]])" "$tmpColor"
          [SymbolicName TransparentColor] config -foreground "$tmpColor"
          set currentTransparentColor "$tmpColor"
        } {
          if {"[string range $matchVar 3 end]" == "none" ||
              "[string range $matchVar 3 end]" == "None"} {
            set "colors([string range $line 0 [expr $tmpCharPerPixel-1]])" {#3abdbc}
            [SymbolicName TransparentColor] config -foreground {#3abdbc}
            set currentTransparentColor {#3abdbc}
          }
        }
      }
      incr colorCounter
    }

    set counterH 0
    while {$counterH < $tmpHeight} {
      set line [lindex $pixmapData [expr $counterH+$colorCounter+1]]
      set counter 0
      set counterW 0
      set length [string length $line]
      while {$counter < $length} {
        set tmpPixel [string range $line $counter [expr $counter+$tmpCharPerPixel-1]]
        $tmpCanvas itemconfig "pixel$counterH-$counterW" -fill "[set colors($tmpPixel)]"
        incr counterW
        incr counter $tmpCharPerPixel
      }
      incr counterH
    }
    set fileName $loadFile
    wm title . "tkxpm: $fileName"
    set currentColor [lindex [[SymbolicName Color0] config -foreground] 4]
    .frame1.frame5.label0 config -foreground $currentColor
  } {
    AlertBox "Not a pixmap file: $loadFile"
  }
}


# Procedure: MenuPopupAdd
if {"[info procs MenuPopupAdd]" == ""} {
proc MenuPopupAdd { xfW xfButton xfMenu {xfModifier ""} {xfCanvasTag ""}} {
# xf ignore me 7
# the popup menu handling is from (I already gave up with popup handling :-):
#
# Copyright 1991,1992 by James Noble.
# Everyone is granted permission to copy, modify and redistribute.
# This notice must be preserved on all copies or derivates.
#
##########
# Procedure: MenuPopupAdd
# Description: attach a popup menu to widget
# Arguments: xfW - the widget
#            xfButton - the button we use
#            xfMenu - the menu to attach
#            {xfModifier} - a optional modifier
#            {xfCanvasTag} - a canvas tagOrId
# Returns: none
# Sideeffects: none
##########

  if {"$xfModifier" != ""} {
    set xfPressModifier "$xfModifier-"
    set xfMoveModifier "$xfModifier-"
    set xfReleaseModifier "Any-"
  } {
    set xfPressModifier ""
    set xfMoveModifier ""
    set xfReleaseModifier ""
  }

  if {"$xfCanvasTag" == ""} {
    if {[catch "bind $xfW \"<${xfPressModifier}ButtonPress-$xfButton>\"                   \"$xfMenu post %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    if {[catch "bind $xfW \"<${xfMoveModifier}B$xfButton-Motion>\"                   \"MenuPopupHandle $xfMenu %W %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    # we need these to counteract the effects of passive grabs :-(
    if {[catch "bind $xfW \"<${xfReleaseModifier}ButtonRelease-$xfButton>\"                   \"$xfMenu invoke active; $xfMenu unpost\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
  } {
    if {[catch "$xfW bind $xfCanvasTag \"<${xfPressModifier}ButtonPress-$xfButton>\"                   \"$xfMenu post %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    if {[catch "$xfW bind $xfCanvasTag \"<${xfMoveModifier}B$xfButton-Motion>\"                   \"MenuPopupHandle $xfMenu %W %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    # we need these to counteract the effects of passive grabs :-(
    if {[catch "$xfW bind $xfCanvasTag \"<${xfReleaseModifier}ButtonRelease-$xfButton>\"                   \"$xfMenu invoke active; $xfMenu unpost\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
  }
}
}


# Procedure: MenuPopupHandle
if {"[info procs MenuPopupHandle]" == ""} {
proc MenuPopupHandle { xfMenu xfW xfX xfY} {
# xf ignore me 7
##########
# Procedure: MenuPopupHandle
# Description: handle the popup menus
# Arguments: xfMenu - the menu to attach
#            xfW - the widget
#            xfX - the root x coordinate
#            xfY - the root x coordinate
# Returns: none
# Sideeffects: none
##########

  if {"[info commands $xfMenu]" != "" && [winfo ismapped $xfMenu]} {
    set xfPopMinX [winfo rootx $xfMenu]
    set xfPopMaxX [expr $xfPopMinX+[winfo width $xfMenu]]
    if {($xfX >= $xfPopMinX) &&  ($xfX <= $xfPopMaxX)} {
      $xfMenu activate @[expr $xfY-[winfo rooty $xfMenu]]
    } {
      $xfMenu activate none
    }
  }
}
}


# Procedure: NextPic
proc NextPic {} {
  global fileNames
  global onePicture
  global pictureCounter
  
  if {$onePicture == 1} {
    if {$pictureCounter < [expr [llength $fileNames]-1]} {
      incr pictureCounter
    } {
      set pictureCounter 0
    }
    SetPictures
  }
}


# Procedure: NoFunction
if {"[info procs NoFunction]" == ""} {
proc NoFunction { args} {
# xf ignore me 7
##########
# Procedure: NoFunction
# Description: do nothing
# Arguments: args - any kind of arguments
# Returns: none
# Sideeffects: none
##########
}
}


# Procedure: PreviousPic
proc PreviousPic {} {
  global fileNames
  global onePicture
  global pictureCounter
  
  if {$onePicture == 1} {
    if {$pictureCounter > 0} {
      incr pictureCounter -1
    } {
      set pictureCounter [expr [llength $fileNames]-1]
    }
    SetPictures
  }
}


# Procedure: QuitProgram
proc QuitProgram {} {

  if {"[info commands ClientShutdown]" != ""} {
    wm withdraw .
  } {
    catch "destroy ."
    catch "exit 0"
  }
}


# Procedure: SN
if {"[info procs SN]" == ""} {
proc SN { {xfName ""}} {
# xf ignore me 7
##########
# Procedure: SN
# Description: map a symbolic name to the widget path
# Arguments: xfName
# Returns: the symbolic name
# Sideeffects: none
##########

  SymbolicName $xfName
}
}


# Procedure: SaveFile
proc SaveFile { saveFile} {
  global fileNames
  global pictureCounter

  if {"$saveFile" == "tkxpm.xpm" ||
      "[file tail $saveFile]" == "tkxpm.xpm"} {
    AlertBox "tkxpm.xpm is not allowed as filename!"
    return
  }
  set currentPicture [lindex $fileNames $pictureCounter]
  UpdatePixmap $currentPicture
  pinfo save @$currentPicture $saveFile xpm3
}


# Procedure: SetNewColor
proc SetNewColor {} {
  global currentColor
  global currentColorButton
  global currentHeight
  global currentWidth

  set oldColor [lindex [[SymbolicName Color$currentColorButton] config -activeforeground] 4]
  set newColor [ColorBox /usr/local/lib/tk/xf/lib/Colors]
  if {"$newColor" != ""} {
    catch "[SymbolicName Color$currentColorButton] config -activeforeground $newColor"
    catch "[SymbolicName Color$currentColorButton] config -background $newColor"
    catch "[SymbolicName Color$currentColorButton] config -foreground $newColor"
    set currentColor [lindex [[SymbolicName Color$currentColorButton] config -activeforeground] 4]

    if {"$newColor" != "$oldColor"} {
      set tmpCanvas [SymbolicName drawSpace]
      .frame1.frame5.label0 config -foreground $currentColor
      for {set counterH 0} {$counterH < $currentHeight} {incr counterH} {
        for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
          set tmpColor [lindex [$tmpCanvas itemconfig "pixel$counterH-$counterW" -fill] 4]
          if {"$tmpColor" == "$oldColor"} {
            catch "$tmpCanvas itemconfig \"pixel$counterH-$counterW\" -fill $newColor"
          }
        }
      }
    }
  }
}


# Procedure: SetPictures
proc SetPictures {} {
  global fileNames
  global onePicture
  global pictureCounter
  
  [SymbolicName Pictures] delete all
  if {$onePicture == 1} {
    if {"[lindex $fileNames $pictureCounter]" != ""} {
      if {[catch "[SymbolicName Pictures] create bitmap 10 10 -anchor nw -bitmap @[lindex $fileNames $pictureCounter]" canvasID]} {
        puts stderr "$canvasID"
      }
      [SymbolicName Pictures] addtag "[lindex $fileNames $pictureCounter]" withtag $canvasID
    }
  } {
    set width 500
    set xpos 10
    set ypos 10
    set maxWidth 0
    set tmpWidth 0
    set tmpHeight 0
    foreach file $fileNames {
      if {[catch "[SymbolicName Pictures] create bitmap $xpos $ypos -anchor nw -bitmap @$file" canvasID]} {
        puts stderr "$canvasID"
        return
      } {
        set tmpWidth [pinfo width @$file]
        set tmpHeight [pinfo height @$file]
        [SymbolicName Pictures] addtag "$file" withtag $canvasID
        if {$tmpWidth > $maxWidth} {
          set maxWidth $tmpWidth
        }
        if {$xpos + $tmpWidth > $width} {
          incr ypos [expr $maxWidth+10]
          set maxWidth 0
          set xpos 10
        } {
          incr xpos [expr $tmpWidth+10]
        }
      }
    }
  }
}


# Procedure: SetRaster
proc SetRaster {} {
  global currentHeight
  global currentTransparentColor
  global currentWidth
  global itemSize

  set tmpCanvas [SymbolicName drawSpace]
  if {"[info command $tmpCanvas]" == ""} {
    return
  }

  set newWidth [.frame1.frame3.scale6 get]
  set newHeight [.frame1.frame3.scale7 get]
  set newSize [.frame1.frame3.scale8 get]
  if {$currentWidth != $newWidth} {
    if {$currentWidth > $newWidth} {
      for {set counterH 0} {$counterH < $currentHeight} {incr counterH} {
        for {set counterW $newWidth} {$counterW < $currentWidth} {incr counterW} {
          $tmpCanvas delete "pixel$counterH-$counterW"
        }
      }
    } {
      for {set counterH 0} {$counterH < $newHeight} {incr counterH} {
        for {set counterW $currentWidth} {$counterW < $newWidth} {incr counterW} {
          if {"[$tmpCanvas find withtag pixel$counterH-$counterW]" != ""} {
            continue
          }
          if {$newSize < 6} {
            $tmpCanvas create rectangle [expr (($counterW*$newSize)+2)] [expr (($counterH*$newSize)+2)] [expr (($counterW*$newSize)+2+$newSize)] [expr (($counterH*$newSize)+2+$newSize)] -outline "" -fill "$currentTransparentColor" -width 0 -tags "pixel$counterH-$counterW"
          } {
            $tmpCanvas create rectangle [expr (($counterW*$newSize)+2)] [expr (($counterH*$newSize)+2)] [expr (($counterW*$newSize)+2+$newSize)] [expr (($counterH*$newSize)+2+$newSize)] -fill "$currentTransparentColor" -width 0 -tags "pixel$counterH-$counterW"
          }
        }
      }
    }
  }

  if {$currentHeight != $newHeight} {
    if {$currentHeight > $newHeight} {
      for {set counterH $newHeight} {$counterH < $currentHeight} {incr counterH} {
        for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
          $tmpCanvas delete "pixel$counterH-$counterW"
        }
      }
    } {
      for {set counterH $currentHeight} {$counterH < $newHeight} {incr counterH} {
        for {set counterW 0} {$counterW < $newWidth} {incr counterW} {
          if {"[$tmpCanvas find withtag pixel$counterH-$counterW]" != ""} {
            continue
          }
          if {$newSize < 6} {
            $tmpCanvas create rectangle [expr (($counterW*$newSize)+2)] [expr (($counterH*$newSize)+2)] [expr (($counterW*$newSize)+2+$newSize)] [expr (($counterH*$newSize)+2+$newSize)] -outline "" -fill "$currentTransparentColor" -width 0 -tags "pixel$counterH-$counterW"
          } {
            $tmpCanvas create rectangle [expr (($counterW*$newSize)+2)] [expr (($counterH*$newSize)+2)] [expr (($counterW*$newSize)+2+$newSize)] [expr (($counterH*$newSize)+2+$newSize)] -fill "$currentTransparentColor" -width 0 -tags "pixel$counterH-$counterW"
          }
        }
      }
    }
  }

  if {$itemSize != $newSize} {
    set itemSize $newSize
    for {set counterH 0} {$counterH < $currentHeight} {incr counterH} {
      for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
        if {$itemSize < 6} {
          $tmpCanvas itemconfig "pixel$counterH-$counterW"           -outline ""
          $tmpCanvas coords "pixel$counterH-$counterW"           [expr (($counterW*$itemSize)+2)]             [expr (($counterH*$itemSize)+2)]               [expr (($counterW*$itemSize)+2+$itemSize)]                 [expr (($counterH*$itemSize)+2+$itemSize)]
        } {
          $tmpCanvas itemconfig "pixel$counterH-$counterW"           -outline "black"
          $tmpCanvas coords "pixel$counterH-$counterW"           [expr (($counterW*$itemSize)+2)]             [expr (($counterH*$itemSize)+2)]               [expr (($counterW*$itemSize)+2+$itemSize)]                 [expr (($counterH*$itemSize)+2+$itemSize)]
        }
      }
    }
  }
  set currentWidth $newWidth
  set currentHeight $newHeight
}


# Procedure: SetTransparentColor
proc SetTransparentColor {} {
  global currentTransparentColor
  global currentHeight
  global currentWidth

  set oldColor [lindex [[SymbolicName TransparentColor] config -foreground] 4]
  set newColor [ColorBox /usr/local/lib/tk/xf/lib/Colors]
  if {"$newColor" != ""} {
    catch "[SymbolicName TransparentColor] config -foreground $newColor"
    set currentTransparentColor [lindex [[SymbolicName TransparentColor] config -foreground] 4]

    if {"$newColor" != "$oldColor"} {
      set tmpCanvas [SymbolicName drawSpace]
      for {set counterH 0} {$counterH < $currentHeight} {incr counterH} {
        for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
          set tmpColor [lindex [$tmpCanvas itemconfig "pixel$counterH-$counterW" -fill] 4]
          if {"$tmpColor" == "$oldColor"} {
            catch "$tmpCanvas itemconfig \"pixel$counterH-$counterW\" -fill $newColor"
          }
        }
      }
    }
  }
}


# Procedure: SymbolicName
if {"[info procs SymbolicName]" == ""} {
proc SymbolicName { {xfName ""}} {
# xf ignore me 7
##########
# Procedure: SymbolicName
# Description: map a symbolic name to the widget path
# Arguments: xfName
# Returns: the symbolic name
# Sideeffects: none
##########

  global symbolicName

  if {"$xfName" != ""} {
    set xfArrayName ""
    append xfArrayName symbolicName ( $xfName )
    if {![catch "set \"$xfArrayName\"" xfValue]} {
      return $xfValue
    } {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "Unknown symbolic name:\n$xfName"
      } {
        puts stderr "XF error: unknown symbolic name:\n$xfName"
      }
    }
  }
  return ""
}
}


# Procedure: Unalias
proc Unalias { aliasName} {
# xf ignore me 7
##########
# Procedure: Unalias
# Description: remove an alias for a procedure
# Arguments: aliasName - the alias name to remove
# Returns: none
# Sideeffects: internalAliasList is updated, and the alias
#              proc is removed
##########
  global internalAliasList

  set xfIndex [lsearch $internalAliasList "$aliasName *"]
  if {$xfIndex != -1} {
    rename $aliasName ""
    set internalAliasList [lreplace $internalAliasList $xfIndex $xfIndex]
  }
}


# Procedure: UpdateCurrentPixmap
proc UpdateCurrentPixmap {} {
  global fileNames
  global pictureCounter

  set currentPicture [lindex $fileNames $pictureCounter]
  UpdatePixmap $currentPicture
}


# Procedure: UpdatePixmap
proc UpdatePixmap { currentPicture} {
  global currentHeight
  global currentTransparentColor
  global currentWidth
  
  if {"$currentPicture" != ""} {
    set tmpCanvas [SymbolicName drawSpace]
    set pixmapData "\{$currentWidth $currentHeight 0 xpm3\} \{"
    append pixmapData "\{$currentWidth $currentHeight 37 3 \} "
    for {set counter 0} {$counter < 36} {incr counter} {
      if {$counter < 10} {
        set colors([lindex [[SymbolicName Color$counter] config -foreground] 4]) "0$counter"
        append pixmapData "\{0$counter  c [lindex [[SymbolicName Color$counter] config -foreground] 4] s [lindex [[SymbolicName Color$counter] config -foreground] 4]\} "
      } {
        set colors([lindex [[SymbolicName Color$counter] config -foreground] 4]) "$counter"
        append pixmapData "\{$counter  c [lindex [[SymbolicName Color$counter] config -foreground] 4] s [lindex [[SymbolicName Color$counter] config -foreground] 4]\} "
      }
    }
    append pixmapData "\{36  c none s mask\} "

    for {set counterH 0} {$counterH < $currentHeight} {incr counterH} {
      set line "\{"
      for {set counterW 0} {$counterW < $currentWidth} {incr counterW} {
        set tmpColor [lindex [$tmpCanvas itemconfig "pixel$counterH-$counterW" -fill] 4]
        if {[string compare $tmpColor $currentTransparentColor] == 0} {
          append line "36 "
        } {
          append line "[set colors($tmpColor)] "
        }
      }
      append line "\} "
      append pixmapData $line
    }
    append pixmapData "\}"
    pinfo undefine @$currentPicture
    pinfo define @$currentPicture $pixmapData

    if {"[info commands [SymbolicName Pictures]]" != ""} {
      foreach counter [[SymbolicName Pictures] find all] {
        if {[catch "[SymbolicName Pictures] itemconfig $counter -bitmap" errorCode]} {
          puts stdout $errorCode
          return
        } {
          set bitmapName [lindex $errorCode 4]
          if {"$bitmapName" == "UndefinedBitmap"} {
            if {[catch "[SymbolicName Pictures] itemconfig $counter -bitmap @$currentPicture" errorCode]} {
              puts stdout $errorCode
              return
            }
          }
        }
      }
    }
  }
}



# module load procedure
proc XFLocalIncludeModule {{moduleName ""}} {
  global env
  global xfLoadInfo
  global xfLoadPath
  global xfStatus

  foreach p [split $xfLoadPath :] {
    if {[file exists "$p/$moduleName"]} {
      if {![file readable "$p/$moduleName"]} {
        puts stderr "Cannot read $p/$moduleName (permission denied)"
        continue
      }
      if {$xfLoadInfo} {
        puts stdout "Loading $p/$moduleName..."
      }
      source "$p/$moduleName"
      return 1
    }
    # first see if we have a load command
    if {[info exists env(XF_VERSION_SHOW)]} {
      set xfCommand $env(XF_VERSION_SHOW)
      regsub -all {\$xfFileName} $xfCommand $p/$moduleName xfCommand
      if {$xfLoadInfo} {
        puts stdout "Loading $p/$moduleName...($xfCommand)"
      }
      if {[catch "$xfCommand" contents]} {
        continue
      } {
        eval $contents
        return 1
      }
    }
    # are we able to load versions from wish ?
    if {[catch "afbind $p/$moduleName" aso]} {
      # try to use xf version load command
      global xfVersion
      if {[info exists xfVersion(showDefault)]} {
        set xfCommand $xfVersion(showDefault)
      } {
	# our last hope
        set xfCommand "vcat -q $p/$moduleName"
      }
      regsub -all {\$xfFileName} $xfCommand $p/$moduleName xfCommand
      if {$xfLoadInfo} {
        puts stdout "Loading $p/$moduleName...($xfCommand)"
      }
      if {[catch "$xfCommand" contents]} {
        continue
      } {
        eval $contents
        return 1
      }
    } {
      # yes we can load versions directly
      if {[catch "$aso open r" inFile]} {
        puts stderr "Cannot open $p/[$aso attr af_bound] (permission denied)"
        continue
      }
      if {$xfLoadInfo} {
        puts stdout "Loading $p/[$aso attr af_bound]..."
      }
      if {[catch "read \{$inFile\}" contents]} {
        puts stderr "Cannot read $p/[$aso attr af_bound] (permission denied)"
        close $inFile
        continue
      }
      close $inFile
      eval $contents
      return 1
    }
  }
  puts stderr "Cannot load module $moduleName -- check your xf load path"
  catch "destroy ."
  catch "exit 0"
}

# application parsing procedure
proc XFLocalParseAppDefs {xfAppDefFile} {
  global xfAppDefaults

  # basically from: Michael Moore
  if {[file exists $xfAppDefFile] &&
      [file readable $xfAppDefFile] &&
      "[file type $xfAppDefFile]" == "link"} {
    catch "file type $xfAppDefFile" xfType
    while {"$xfType" == "link"} {
      if {[catch "file readlink $xfAppDefFile" xfAppDefFile]} {
        return
      }
      catch "file type $xfAppDefFile" xfType
    }
  }
  if {!("$xfAppDefFile" != "" &&
        [file exists $xfAppDefFile] &&
        [file readable $xfAppDefFile] &&
        "[file type $xfAppDefFile]" == "file")} {
    return
  }
  if {![catch "open $xfAppDefFile r" xfResult]} {
    set xfAppFileContents [read $xfResult]
    close $xfResult
    foreach line [split $xfAppFileContents "\n"] {
      # backup indicates how far to backup.  It applies to the
      # situation where a resource name ends in . and when it
      # ends in *.  In the second case you want to keep the *
      # in the widget name for pattern matching, but you want
      # to get rid of the . if it is the end of the name. 
      set backup -2  
      set line [string trim $line]
      if {[string index $line 0] == "#" || "$line" == ""} {
        # skip comments and empty lines
        continue
      }
      set list [split $line ":"]
      set resource [string trim [lindex $list 0]]
      set i [string last "." $resource]
      set j [string last "*" $resource]
      if {$j > $i} { 
        set i $j
        set backup -1
      }
      incr i
      set name [string range $resource $i end]
      incr i $backup
      set widname [string range $resource 0 $i]
      set value [string trim [lindex $list 1]]
      if {"$widname" != "" && "$widname" != "*"} {
        # insert the widget and resourcename to the application
        # defaults list.
        set xfAppDefaults($widname:[string tolower $name]) $value
      }
    }
  }
}

# application loading procedure
proc XFLocalLoadAppDefs {xfClasses {xfPriority "startupFile"} {xfAppDefFile ""}} {
  global env

  if {"$xfAppDefFile" == ""} {
    set xfFileList ""
    if {[info exists env(XUSERFILESEARCHPATH)]} {
      append xfFileList [split $env(XUSERFILESEARCHPATH) :]
    }
    if {[info exists env(XAPPLRESDIR)]} {
      append xfFileList [split $env(XAPPLRESDIR) :]
    }
    if {[info exists env(XFILESEARCHPATH)]} {
      append xfFileList [split $env(XFILESEARCHPATH) :]
    }
    append xfFileList " /usr/lib/X11/app-defaults"
    append xfFileList " /usr/X11/lib/X11/app-defaults"

    foreach xfCounter1 $xfClasses {
      foreach xfCounter2 $xfFileList {
        set xfPathName $xfCounter2
        if {[regsub -all "%N" "$xfPathName" "$xfCounter1" xfResult]} {
          set xfPathName $xfResult
        }
        if {[regsub -all "%T" "$xfPathName" "app-defaults" xfResult]} {
          set xfPathName $xfResult
        }
        if {[regsub -all "%S" "$xfPathName" "" xfResult]} {
          set xfPathName $xfResult
        }
        if {[regsub -all "%C" "$xfPathName" "" xfResult]} {
          set xfPathName $xfResult
        }
        if {[file exists $xfPathName] &&
            [file readable $xfPathName] &&
            ("[file type $xfPathName]" == "file" ||
             "[file type $xfPathName]" == "link")} {
          catch "option readfile $xfPathName $xfPriority"
          if {"[info commands XFParseAppDefs]" != ""} {
            XFParseAppDefs $xfPathName
          } {
            if {"[info commands XFLocalParseAppDefs]" != ""} {
              XFLocalParseAppDefs $xfPathName
            }
          }
        } {
          if {[file exists $xfCounter2/$xfCounter1] &&
              [file readable $xfCounter2/$xfCounter1] &&
              ("[file type $xfCounter2/$xfCounter1]" == "file" ||
               "[file type $xfCounter2/$xfCounter1]" == "link")} {
            catch "option readfile $xfCounter2/$xfCounter1 $xfPriority"
            if {"[info commands XFParseAppDefs]" != ""} {
              XFParseAppDefs $xfCounter2/$xfCounter1
            } {
              if {"[info commands XFLocalParseAppDefs]" != ""} {
                XFLocalParseAppDefs $xfCounter2/$xfCounter1
              }
            }
          }
        }
      }
    }
  } {
    # load a specific application defaults file
    if {[file exists $xfAppDefFile] &&
        [file readable $xfAppDefFile] &&
        ("[file type $xfAppDefFile]" == "file" ||
         "[file type $xfAppDefFile]" == "link")} {
      catch "option readfile $xfAppDefFile $xfPriority"
      if {"[info commands XFParseAppDefs]" != ""} {
        XFParseAppDefs $xfAppDefFile
      } {
        if {"[info commands XFLocalParseAppDefs]" != ""} {
          XFLocalParseAppDefs $xfAppDefFile
        }
      }
    }
  }
}

# application setting procedure
proc XFLocalSetAppDefs {{xfWidgetPath "."}} {
  global xfAppDefaults

  if {![info exists xfAppDefaults]} {
    return
  }
  foreach xfCounter [array names xfAppDefaults] {
    if {[string match "${xfWidgetPath}*" $xfCounter]} {
      set widname [string range $xfCounter 0 [expr [string first : $xfCounter]-1]]
      set name [string range $xfCounter [expr [string first : $xfCounter]+1] end]
      # Now lets see how many tcl commands match the name
      # pattern specified.
      set widlist [info command $widname]
      if {"$widlist" != ""} {
        foreach widget $widlist {
          # make sure this command is a widget.
          if {![catch "winfo id $widget"]} {
            catch "$widget configure -[string tolower $name] $xfAppDefaults($xfCounter)" 
          }
        }
      }
    }
  }
}


# predefine pixmaps
if {"[info commands pinfo]" != ""} {
  pinfo define @Button01 {{18 18 0 xpm3} {{18 18 2 1} { 	c None} {.	c #000000000000} {                  } {            .     } {            ..    } {            ...   } {   .......... ..  } {  .            .. } { .             .. } { ............ ..  } { .  .       ...   } { .  .       ..    } { .  .       .     } { .  .             } { .  .             } { ..........       } { .       .        } {  .      .        } {   ........       } {                  } }}
  pinfo define @Button02 {{18 18 0 xpm3} {{18 18 2 1} { 	c None} {.	c #000000000000} {                  } {        ..        } {       ....       } {      ..  ..      } {     ..    ..     } {    ....  ....    } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       ....       } {       .  .       } {                  } }}
  pinfo define @Button03 {{18 18 0 xpm3} {{18 18 2 1} { 	c None} {.	c #000000000000} {                  } {     ..           } {    ....          } {   ..  ..         } {  ..    ..        } { ....  ....       } {    .  .          } {    .  .     .  . } {    .  .     .... } {    .  .     .  . } {    .  .     .  . } {    .  .     .  . } {    .  .     .  . } {    .  .......  . } {    .  .     .  . } {     . .     . .  } {      .........   } {                  } }}
  pinfo define @Button04 {{18 18 0 xpm3} {{18 18 2 1} { 	c None} {.	c #000000000000} {                  } {                  } {                  } {                  } {     .            } {    ..            } {   ...            } {  .. ............ } { ..            .  } { ..            .  } {  .. ............ } {   ...            } {    ..            } {     .            } {                  } {                  } {                  } {                  } }}
  pinfo define @Button05 {{18 18 0 xpm3} {{18 18 2 1} { 	c None} {.	c #000000000000} {                  } { ......    ...... } { ..  .      .  .. } { .   .      .   . } { .    .    .    . } { ...   .  .   ... } { .  .   ..   .  . } {     .      .     } {      .    .      } {      .    .      } {     .      .     } { .  .   ..   .  . } { ...   .  .   ... } { .    .    .    . } { .   .      .   . } { ..  .      .  .. } { ......    ...... } {                  } }}
  pinfo define @Button06 {{18 18 0 xpm3} {{18 18 2 1} { 	c None} {.	c #000000000000} {                  } {                  } {                  } {                  } {            .     } {            ..    } {            ...   } { ............ ..  } {  .            .. } {  .            .. } { ............ ..  } {            ...   } {            ..    } {            .     } {                  } {                  } {                  } {                  } }}
  pinfo define @Button07 {{18 18 0 xpm3} {{18 18 2 1} { 	c None} {.	c #000000000000} {                  } {     .            } {    ..            } {   ...            } {  .. ..........   } { ..            .  } { ..             . } {  .. ............ } {   ...       .  . } {    ..       .  . } {     .       .  . } {             .  . } {             .  . } {             .  . } {             .  . } {             .... } {             .  . } {                  } }}
  pinfo define @Button08 {{18 18 0 xpm3} {{18 18 2 1} { 	c None} {.	c #000000000000} {                  } {       .  .       } {       ....       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {       .  .       } {    ....  ....    } {     ..    ..     } {      ..  ..      } {       ....       } {        ..        } {                  } }}
  pinfo define @Button09 {{18 18 0 xpm3} {{18 18 2 1} { 	c None} {.	c #000000000000} {                  } {            .     } {            ..    } {            ...   } {   .......... ..  } {  .            .. } { .             .. } { ............ ..  } { .  .       ...   } { .  .       ..    } { .  .       .     } { .  .             } { .  .             } { .  .             } { .  .             } { ....             } { .  .             } {                  } }}
}



# startup source
proc StartupSrc {args} {
  if {"[info commands pinfo]" == ""} {
    puts stderr "This wish does not support pixmaps!"
    catch "destroy ."
    catch "exit 1"
  }
}


# end source
proc EndSrc {} {
  global argc
  global argv
  global bitmapButtons
  global currentColor
  global currentHeight
  global currentWidth
  global fileName
  global fileNames
  global fsBoxFSPath
  global itemSize
  global onePicture
  global xfLoadPath

  set itemSize 10
  set fsBoxFSPath [pwd]
  set bitmapButtons {}
  set fileName {}
  set fileNames {}
  set localCurrentWidth 10
  set localCurrentHeight 10

  if {[string match "*xpm3 *" [pinfo formats all]] != 1} {
    puts stderr "This wish does not support xpm 3 format!"
    catch "destroy ."
    catch "exit 1"
  }

  for {set counter 0} {$counter < $argc} {incr counter 1} {
    case [string tolower [lindex $argv $counter]] in {
      {-size} {
        incr counter 1
        set localCurrentWidth [string range [lindex $argv $counter] 0 [expr [string first x [lindex $argv $counter]]-1]]
        set localCurrentHeight [string range [lindex $argv $counter] [expr [string first x [lindex $argv $counter]]+1] end]
        if {"$currentWidth" == ""} {
          set localCurrentWidth 10
        }
        if {"$currentHeight" == ""} {
          set localCurrentHeight 10
        }
      }
      {-onepicture} {
        set onePicture 1
      }
      {-multipicture} {
        set onePicture 0
      }
      {default} {
        append fileNames "[lindex $argv $counter] "
      }
    }
  }
  
  set currentColor [lindex [[SymbolicName Color0] config -foreground] 4]

  .frame1.frame3.scale8 set $itemSize

  update idletask
  if {[llength $fileNames] == 0} {
    set fileName tkxpm.xpm
    set fileNames tkxpm.xpm
    set pixmapData "\{$localCurrentWidth $localCurrentHeight 0\}"
    pinfo define @tkxpm.xpm $pixmapData
  } {
    if {[llength $fileNames] == 1} {
      set fileName [lindex $fileNames 0]
    } {
      if {[llength $fileNames] > 1} {
        set fileName [lindex $fileNames 0]
        ShowWindow.top0
        SetPictures
      }
    }
  }
  .frame1.frame3.scale6 set $localCurrentWidth
  .frame1.frame3.scale7 set $localCurrentHeight
  if {"$fileName" != "" && "$fileName" != "tkxpm.xpm"} {
    LoadFile $fileName
  } {
    SetRaster
    wm title . "tkxpm: $fileName"
  }

  if {"[info commands ClientLogin]" != ""} {
    ClientLogin tkxpm
  }
}

# startup source
StartupSrc

# initialize global variables
global {alertBox}
set {alertBox(activeBackground)} {}
set {alertBox(activeForeground)} {}
set {alertBox(after)} {0}
set {alertBox(anchor)} {nw}
set {alertBox(background)} {}
set {alertBox(button)} {0}
set {alertBox(font)} {}
set {alertBox(foreground)} {}
set {alertBox(justify)} {center}
set {alertBox(toplevelName)} {.alertBox}
global {bitmapButtons}
set {bitmapButtons} {}
global {button5}
set {button5} {0}
global {colorBox}
set {colorBox(activeBackground)} {}
set {colorBox(activeForeground)} {}
set {colorBox(background)} {}
set {colorBox(colorName)} {}
set {colorBox(font)} {}
set {colorBox(foreground)} {}
set {colorBox(palette)} {white black gray50 blue red green yellow orange}
set {colorBox(paletteNr)} {0}
set {colorBox(scrollActiveForeground)} {}
set {colorBox(scrollBackground)} {}
set {colorBox(scrollForeground)} {}
set {colorBox(scrollSide)} {left}
set {colorBox(type)} {rgb}
global {currentColor}
set {currentColor} {white}
global {currentColorButton}
set {currentColorButton} {0}
global {currentHeight}
set {currentHeight} {10}
global {currentTransparentColor}
set {currentTransparentColor} {#3abdbc}
global {currentWidth}
set {currentWidth} {10}
global {fileName}
set {fileName} {tkxpm.xpm}
global {fileNames}
set {fileNames} {tkxpm.xpm}
global {fillMode}
set {fillMode} {0}
global {fsBox}
set {fsBox(activeBackground)} {}
set {fsBox(activeForeground)} {}
set {fsBox(all)} {0}
set {fsBox(background)} {}
set {fsBox(button)} {0}
set {fsBox(extensions)} {0}
set {fsBox(font)} {}
set {fsBox(foreground)} {}
set {fsBox(internalPath)} {/home/garfield/development/xf/xfpixmap}
set {fsBox(name)} {}
set {fsBox(path)} {/home/garfield/development/xf/xfpixmap}
set {fsBox(pattern)} {*}
set {fsBox(scrollActiveForeground)} {}
set {fsBox(scrollBackground)} {}
set {fsBox(scrollForeground)} {}
set {fsBox(scrollSide)} {left}
set {fsBox(showPixmap)} {0}
global {fsBoxFSPath}
set {fsBoxFSPath} {/home/garfield/development/xf/xfpixmap}
global {itemSize}
set {itemSize} {10}
global {newColor}
set {newColor} {}
global {onePicture}
set {onePicture} {0}
global {pictureCounter}
set {pictureCounter} {0}
global {saveFile}
set {saveFile} {}
global {selTag}
set {selTag} {pixel39-0}

# please don't modify the following
# variables. They are needed by xf.
global {autoLoadList}
set {autoLoadList(main.tcl)} {0}
global {internalAliasList}
set {internalAliasList} {}
global {moduleList}
set {moduleList(alertBox.tcl)} { AlertBox AlertBoxInternal}
set {moduleList(colorBox.tcl)} { ColorBox ColorBoxSelectColor ColorBoxSetColor ColorBoxSetHSVColor ColorBoxSetPalette ColorBoxSetPaletteList ColorBoxSetRGBColor ColorBoxShowSlides ColorBoxHSVToRGB ColorBoxRGBToHSV}
set {moduleList(extrnl.tcl)} { Alias GetSelection MenuPopupAdd MenuPopupHandle NoFunction SN SymbolicName Unalias}
set {moduleList(fnctns.tcl)} { ChangeArea ClearArea Fill FillIt LoadFile NextPic PreviousPic QuitProgram SaveFile SetNewColor SetPictures SetRaster SetTransparentColor UpdatePixmap UpdateCurrentPixmap}
set {moduleList(fsBox.tcl)} { FSBox FSBoxBindSelectOne FSBoxFSFileSelect FSBoxFSFileSelectDouble FSBoxFSInsertPath FSBoxFSNameComplete FSBoxFSShow IsADir IsAFile IsASymlink}
set {moduleList(interface.tcl)} { . .top0}
set {moduleList(main.tcl)} {}
global {preloadList}
set {preloadList(@Button01)} {}
set {preloadList(@Button02)} {}
set {preloadList(@Button03)} {}
set {preloadList(@Button04)} {}
set {preloadList(@Button05)} {}
set {preloadList(@Button06)} {}
set {preloadList(@Button07)} {}
set {preloadList(@Button08)} {}
set {preloadList(@Button09)} {}
set {preloadList(xfInternal)} {}
global {symbolicName}
set {symbolicName(Color0)} {.frame1.frame5.frame9.button13}
set {symbolicName(Color1)} {.frame1.frame5.frame9.button14}
set {symbolicName(Color10)} {.frame1.frame5.frame29.button34}
set {symbolicName(Color11)} {.frame1.frame5.frame29.button11}
set {symbolicName(Color12)} {.frame1.frame5.frame11.button21}
set {symbolicName(Color13)} {.frame1.frame5.frame11.button22}
set {symbolicName(Color14)} {.frame1.frame5.frame11.button23}
set {symbolicName(Color15)} {.frame1.frame5.frame11.button24}
set {symbolicName(Color16)} {.frame1.frame5.frame11.button36}
set {symbolicName(Color17)} {.frame1.frame5.frame11.button9}
set {symbolicName(Color18)} {.frame1.frame5.frame12.button25}
set {symbolicName(Color19)} {.frame1.frame5.frame12.button26}
set {symbolicName(Color2)} {.frame1.frame5.frame9.button15}
set {symbolicName(Color20)} {.frame1.frame5.frame12.button27}
set {symbolicName(Color21)} {.frame1.frame5.frame12.button28}
set {symbolicName(Color22)} {.frame1.frame5.frame12.button35}
set {symbolicName(Color23)} {.frame1.frame5.frame12.button10}
set {symbolicName(Color24)} {.frame1.frame5.frame10.button17}
set {symbolicName(Color25)} {.frame1.frame5.frame10.button18}
set {symbolicName(Color26)} {.frame1.frame5.frame10.button19}
set {symbolicName(Color27)} {.frame1.frame5.frame10.button20}
set {symbolicName(Color28)} {.frame1.frame5.frame10.button37}
set {symbolicName(Color29)} {.frame1.frame5.frame10.button8}
set {symbolicName(Color3)} {.frame1.frame5.frame9.button16}
set {symbolicName(Color30)} {.frame1.frame5.frame0.button1}
set {symbolicName(Color31)} {.frame1.frame5.frame0.button2}
set {symbolicName(Color32)} {.frame1.frame5.frame0.button3}
set {symbolicName(Color33)} {.frame1.frame5.frame0.button4}
set {symbolicName(Color34)} {.frame1.frame5.frame0.button5}
set {symbolicName(Color35)} {.frame1.frame5.frame0.button6}
set {symbolicName(Color4)} {.frame1.frame5.frame9.button38}
set {symbolicName(Color5)} {.frame1.frame5.frame9.button7}
set {symbolicName(Color6)} {.frame1.frame5.frame29.button30}
set {symbolicName(Color7)} {.frame1.frame5.frame29.button31}
set {symbolicName(Color8)} {.frame1.frame5.frame29.button32}
set {symbolicName(Color9)} {.frame1.frame5.frame29.button33}
set {symbolicName(ColorTransparent)} {.frame1.frame5.button3}
set {symbolicName(Pictures)} {.top0.frame.canvas2}
set {symbolicName(TransparentColor)} {.frame1.frame5.button1}
set {symbolicName(drawSpace)} {.frame.canvas2}
set {symbolicName(root)} {.}
global {xfWmSetPosition}
set {xfWmSetPosition} {}
global {xfWmSetSize}
set {xfWmSetSize} {.top0 .}
global {xfAppDefToplevels}
set {xfAppDefToplevels} {}

# display/remove toplevel windows.
ShowWindow.

global xfShowWindow.top0
set xfShowWindow.top0 0

# load default bindings.
if {[info exists env(XF_BIND_FILE)] &&
    "[info procs XFShowHelp]" == ""} {
  source $env(XF_BIND_FILE)
}

# parse and apply application defaults.
XFLocalLoadAppDefs Main
XFLocalSetAppDefs

# end source
EndSrc

# eof
#

