Move Up:{ pic.up }
Move Down:{ pic.down }
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;MAIN DIALOG
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dialog jampv {
  title "Picture Viewer"
  size -1 -1 208 68
  option dbu
  tab "source", 1, -8 -16 219 158   
  list 5, 59 3 146 49, tab 1 size    
  button "Agg", 6, 108 57 15 8, tab 1
  button "Elim", 7, 124 57 15 8, tab 1
  button "list", 18, 140 57 15 8, tab 1
  tab "list", 10
  list 11, 119 20 85 35, tab 10 size
  text "Guardando:", 12, 58 6 22 8, tab 10
  edit "", 13, 79 3 125 10, tab 10 read autohs
  button "Guarda", 17, 188 57 15 8, tab 10
  text "Viual. Tipo:", 21, 58 27 28 8, tab 10
  check "", 22, 87 25 10 10, tab 10
  check "", 23, 87 37 10 10, tab 10
  text "Piccola", 220, 97 25 16 10, tab 10
  text "Grande", 230, 97 37 16 10, tab 10
  button "?", 3, 13 57 15 8
  button "X", 4, 29 57 15 8, cancel
  list 2, 3 3 50 50, size      
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;SMALL DIALOG
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dialog pv.sv {
  title "Piccola"
  size -1 -1 250 188
  option pixels
  icon 1, 0 0 250 188, %last.pic
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;LARGE DIALOG
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dialog pv.lv {
  title "Grande"
  size -1 -1 $window(-1).w $window(-1).h
  option pixels
  icon 1, 0 0 $window(-1).w $window(-1).h , %last.pic
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;OPENING DIALOG ALIASES
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias jampv { if (!$dialog(jampv)) { dialog -md jampv jampv |  if ( %cc181p == on ) { $tunder TDDialog $dialog(jampv).hwnd > 2 } } | else { dialog -ve jampv } }
alias pv.sv { if (!$dialog(pv.sv)) { dialog -md pv.sv pv.sv |  if ( %cc181p == on ) { $tunder TDDialog $dialog(pv.sv).hwnd > 10 } } } | else { dialog -ve pv.sv } }
alias pv.lv { if (!$dialog(pv.lv)) { dialog -md pv.lv pv.lv |  if ( %cc181p == on ) { $tunder TDDialog $dialog(pv.lv).hwnd > 10 } } } | else { dialog -ve pv.lv } }
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;DLL ALIASES
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias mdx { return $+(",$scriptdirdlls\mdx.dll,") }
alias mdx.init { dll $mdx SetMircVersion $version | dll $mdx MarkDialog $dname }
alias popread { return $dll($+(",$scriptdirdlls/popread.dll,"),popread,$script? $$1 ? $$2 ? $calc($mouse.dx - 24) ? $mouse.dy ) }
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ON LOAD/UNLOAD + menu controls
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

on *:unload:{ 
  unset %pic.view
  unset %last.pic
}

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;VIEWING PIC ALIASES
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~TREEVIEW RETURN ALIASE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;alias by Morphy
alias branch {
  var %d = $1
  var %i = $2
  if ($dialog(%d)) {
    var %b = $gettok($did(%d,%i,1),4-,32)
    var %n = $calc($numtok(%b,32) -1)
    if (%n = 0) did -i %d %i 1 cb root
    else { did -i %d %i 1 cb root $gettok(%b,1- $+ %n,32) }
    return $gettok($gettok($did(%d,%i,$gettok(%b,-1,32)),7-,32),1,9)
  }
}
alias current.view {
  var %file = $hget(system,last.pic) 
  return %file
}
alias view.p {
  var %source = $+(",$did(jampv,13).text,")
  var %file = $did(jampv,11).seltext
  var %pic = $findfile(%source,%file,1) 
  set %last.pic %pic
  if ( %pic.view == small ) { small.view }
  elseif ( %pic.view == large ) { large.view }
}
alias small.view { 
  if (!$dialog(pv.sv)) { dialog -md pv.sv pv.sv | if ( %cc181p == on ) { $tunder TDDialog $dialog(pv.sv).hwnd > 10 } } 
  else { did -g pv.sv 1 $+(",%last.pic,") } 
} 
alias large.view {   
  if (!$dialog(pv.lv)) { dialog -md pv.lv pv.lv | if ( %cc181p == on ) { $tunder TDDialog $dialog(pv.lv).hwnd > 10 } }  
  else { did -g pv.lv 1 $+(",%last.pic,") } 
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;HASH ALIASES
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias pic.hash.make {  
  hmake picture
  hload -i picture $+(",$scriptdirpicture.hsh,")
}
alias pic.hash.save { 
  hsave -io picture $+(",$scriptdirpicture.hsh,") 
  hfree picture
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;HELP ALIAS
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias get.pv.help { run $+(",$scriptdirhelp.htm,") }
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;WINDOW MOVE ALIASES
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias pic.down {
  var %pp = $did(jampv,11).sel
  if (%pp == $did(jampv,11).lines) { halt }
  else { var %pp = $calc($did(jampv,11).sel + 1) }
  did -c jampv 11 %pp
  view.p
}
alias pic.up {
  var %pp = $did(jampv,11).sel
  if (%pp == $did(jampv,11).lines) { halt }
  else { var %pp = $calc($did(jampv,11).sel - 1) }
  did -c jampv 11 %pp
  view.p
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;SOURCE ALIASES
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias add.p.s {
  var %i = $sdir="Immettere Fonte Directory"
  if ( $chr(32) isin %i ) { var %i = $replace(%i,$chr(32),$chr(45)) }
  var %count = $hget(picture,0).item
  inc %count
  hadd picture %count %i
  list.p.f
}
alias del.p.s {
  var %sel = $gettok($did(jampv,5).seltext,6-,32)
  var %sel.final = $gettok(%sel,1,32)
  var %i = 1
  while ( $hget(picture,%i).data ) {
    var %item = $hget(picture,%i).item
    var %source = $gettok($v1,1,32)
    if ( %source == %sel.final ) { hdel picture %item }
    inc %i
  }
  list.p.f
}
alias list.p.f {
  did -r jampv 5
  var %i = 1
  while ( $hget(picture,%i).data ) {
    var %source = $gettok($v1,1,32)
    var %number = $gettok($v1,2,32)
    if ( %number == $null ) { var %number = N/A }
    did -a jampv 5 %source $chr(9) %number
    inc %i
  }
}
alias p.list.f {
  var %source = $gettok($did(jampv,5).seltext,6-,32)
  var %p.source = $replace($remove($gettok(%source,1,32),0,+fs),$chr(45),$chr(32))
  did -ra jampv 13 %p.source
  did -f jampv 10
  did -r jampv 11
  var %jpg = $findfile(%p.source,*.jpg,0, did -a jampv 11 $nopath($1-)  ) 
  var %total = %jpg
  var %jpeg = $findfile(%p.source,*.jpeg,0, did -a jampv 11 $nopath($1-) ) 
  inc %total %jpeg
  var %bmp = $findfile(%p.source,*.bmp,0, did -a jampv 11 $nopath($1-) )
  inc %total %bmp
  var %png = $findfile(%p.source,*.png,0, did -a jampv 11 $nopath($1-)  )
  inc %total %png
  var %ico = $findfile(%p.source,*.ico,0, did -a jampv 11 $nopath($1-)  )
  inc %total %ico
  var %f.total = %total
  var %i = 1
  while ( $hget(picture,%i).data ) {
    var %info = $gettok($v1,1,32), %number = $hget(picture,%i).item
    if ( $replace(%info,$chr(45),$chr(32)) == %p.source ) { hadd picture %number %info %f.total }
    inc %i
  }
  list.p.f
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ON INIT EVENT (MAIN DIALOG)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on *:dialog:jampv:init:0:{
  mdx.init
  pic.hash.make
  dll $mdx SetControlMDX $dname 2 TreeView haslines linesatroot hasbuttons > $scriptdirdlls\views.mdx
  dll $mdx MarkDialog $dname $dialog($dname).hwnd
  if (%unome == 1) { 
    dll $mdx SetDialog $dname bgcolor $rgb(0,72,170) 
    dll $mdx  SetColor $dname 22,23,220,230,12,21 background $rgb(0,72,170)
    dll $mdx  SetColor $dname 22,23,220,230,12,21 textbg $rgb(0,72,170)
    dll $mdx  SetColor $dname 13 background $rgb(0,0,0)
    dll $mdx  SetColor $dname 13 textbg $rgb(0,0,0)
    dll $mdx  SetColor $dname 6,7,18,17,3,4 background $rgb(0,72,170)
    dll $mdx  SetColor 22,23,220,230,12,21,13 text $rgb(255,255,255)
  }
  if (%unome == 2) { 
    dll $mdx SetDialog $dname bgcolor $rgb(0,0,95) 
    dll $mdx  SetColor $dname 22,23,220,230,12,21 background $rgb(0,0,95)
    dll $mdx  SetColor $dname 22,23,220,230,12,21 textbg $rgb(0,0,95)
    dll $mdx  SetColor $dname 13 background $rgb(0,0,0)
    dll $mdx  SetColor $dname 13 textbg $rgb(0,0,0)
    dll $mdx  SetColor $dname 6,7,18,17,3,4 background $rgb(0,0,95)
    dll $mdx  SetColor 22,23,220,230,12,21,13 text $rgb(255,255,255)
  }
  did -a $dname 2 +eb Options
  did -i $dname 2 1 cb root last 1
  did -a $dname 2 +e Fonte
  did -a $dname 2 +e Lista
  dll $mdx SetControlMDX $dname 5 Listview report grid infotip > $scriptdirDLLS\views.mdx
  did -i $dname 5 1 headerdims 225 52
  did -i $dname 5 1 headertext Source $chr(9) Total
  list.p.f
  if ( %pic.view == small ) { did -c jampv 22 }
  elseif ( %pic.view == large ) { did -c jampv 23 }
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;SCLICKS EVENT
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on *:dialog:pv.sv:sclick:1:{ popread 1 2 }
on *:dialog:pv.lv:sclick:1:{ popread 1 2 }
on *:dialog:jampv:sclick:*:{
  if ( $did == 2 ) {
    var %i = $branch(jampv,2)
    if ( %i == Source ) { did -f jampv 1 }
    elseif ( %i == List ) { did -f jampv 10 }
  }
  if ( $did == 3 ) { get.pv.help }
  if ( $did == 4 ) { window -c @help | pic.hash.save }
  if ( $did == 6 ) { add.p.s }
  if ( $did == 7 ) { del.p.s }
  if ( $did == 17 ) { view.p }
  if ( $did == 18 ) { p.list.f }
  if ( $did == 22 ) { set %pic.view small | did -c jampv 22 | did -u jampv 23 }
  if ( $did == 23 ) { set %pic.view large | did -c jampv 23 | did -u jampv 22 }
}
