home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 25 / IOPROG_25.ISO / SOFT / C5FOLDEE.ZIP / SAMPLES / VIEWER.PRG < prev   
Encoding:
Text File  |  1997-08-07  |  5.6 KB  |  287 lines

  1. #include "fivewin.ch"
  2. #include "directry.ch"
  3.  
  4. #define MAXWIDTH  180
  5. #define MAXHEIGHT 180
  6.  
  7. function Viewer()
  8.  
  9. Local oViewer
  10. Local cVar1 , cVar2 := ""
  11.  
  12. Local aItems1 := {}, aItems2 := {}
  13. Local aFiles := {}
  14. Local oFont
  15. local n, nLen
  16.  
  17. Public oLbx1, oLbx2, oBmp
  18. Public aSelItems := {}
  19.  
  20. Public cUnidad := CurDrive()
  21. Public cPath := cUnidad + ":\" + Curdir (CurDrive())
  22. Public cDrives := aDrives()
  23.  
  24.  
  25. aItems1  := Filldir ()
  26.  
  27. nLen := Len( cDrives )
  28.  
  29. if nLen == 0
  30.    quit
  31. endif
  32.  
  33. for n := 1 to nLen
  34.     aadd( aItems1, "[-" + substr( cDrives,n,1) + "-]" )
  35. next
  36.  
  37. cVar1 := aItems1[1]
  38.  
  39.   DEFINE FONT oFont NAME "Ms Sans Serif" SIZE 0,-10
  40.   ACTIVATE FONT oFont
  41.  
  42.   DEFINE DIALOG oViewer NAME "BMPVIEWER" FONT oFont
  43.  
  44.  
  45.           REDEFINE  LISTBOX oLbx1              ;
  46.                     VAR cVar1                  ;
  47.                     ID 101                     ;
  48.                     ITEMS aItems1              ;
  49.                     OF oViewer                 ;
  50.                     COLOR CLR_BLACK, CLR_WHITE ;
  51.                     ON DBLCLICK Pulsado ( oLbx1, , oLbx2 ) ;
  52.                     MULTISEL
  53.  
  54.                          oLbx1:bKeyDown :=  {|nKey| Pulsado ( oLbx1, nKey )}
  55.                          oLbx1:bRClicked := {|nRow,nCol| MenuTool(nROw,nCol,oLbx1)}
  56.  
  57.            REDEFINE LISTBOX oLbx2                          ;
  58.                     VAR cVar2                              ;
  59.                     ID 102                                 ;
  60.                     ITEMS aItems2                          ;
  61.                     SIZE  128,  184                        ;
  62.                     OF oViewer                             ;
  63.                     COLOR CLR_BLACK, CLR_WHITE             ;
  64.                     ON DBLCLICK Pulsado ( oLbx1, , oLbx2 ) ;
  65.                     ON CHANGE if ( UPPER(right(oLbx2:GetSelText(),3 )) == "BMP", Pulsado( oLbx1,,oLbx2 ),.t.)
  66.  
  67.  
  68.            REDEFINE BITMAP oBmp FILE " "       ;
  69.                     ID 103                     ;
  70.                     OF oViewer                 ;
  71.                     NOBORDER
  72.  
  73.  
  74.  
  75.  
  76.   ACTIVATE DIALOG oViewer CENTERED
  77.  
  78.   RELEASE FONT oFont
  79.  
  80.  
  81.   Return nil
  82.  
  83.  
  84.  
  85. Function filldir ( cSort, lFiles )
  86.  
  87. Local aDir
  88. Local aFiles1 := {}
  89. Local aFiles2 := {}
  90.  
  91. Local n, nLen
  92.  
  93. DEFAULT cSort := "name", lFiles := .f.
  94.  
  95.  
  96. aDir := DIRECTORY (cPath + "\" + "*.*","D" )
  97.  
  98. IF !empty ( aDir )
  99.  
  100.    nLen := Len (aDir)
  101.  
  102.    For n := 1 to nLen
  103.        aDir [n][1] := iif ( aDir[n,F_ATTR] != "D", Lower (aDir[n,1]), aDir [n,1] )
  104.    next
  105.  
  106.    If cSort == "name"
  107.       aDir := ASORT (aDir, iif(aDir[1][1] == ".",3,1) ,, { |x,y| x[1] < y[1] }  )
  108.    else
  109.       aDir := ASORT (aDir, iif(aDir[1][1] == ".",3,1) ,, { |x,y| cFileExt(x[1])+cFileName(x[1]) < cFileExt(y[1])+cFileName(y[1]) } )
  110.    endif
  111.  
  112.    If !lFiles
  113.       AEVAL ( aDir, {|aFichero,n|  iif ( aDir[n][5] == "D",aadd( aFiles1, aFichero[F_NAME] ), )  } )
  114.    else
  115.       AEVAL ( aDir, {|aFichero,n|  iif ( aDir[n][5] != "D",aadd( aFiles1, aFichero[F_NAME] ), )  } )
  116.    endif
  117.  
  118.  
  119.  
  120. endif
  121.  
  122.  
  123. Return  aFiles1
  124.  
  125. ****************************************
  126. Function Pulsado ( oLbx1, nKey , oLbx2, nListbox )
  127. ****************************************
  128. Local cAuxPath, aAux := {}, aFiles := {}
  129. Local cItem  := ""
  130. Local cItem2 := ""
  131.  
  132. If nKey != nil
  133.    if ! (nKey == VK_RETURN .or. nKey == VK_SPACE)
  134.       Return nil
  135.    endif
  136. endif
  137.  
  138.  
  139. cItem :=  alltrim ( oLbx1:GetItem (oLbx1:GetPos()) )
  140. cItem2 := alltrim ( oLbx2:GetItem (oLbx2:GetPos()) )
  141.  
  142.  
  143. cExt = RIGHT (cItem2, 3)
  144.  
  145.  
  146. DO CASE
  147.    CASE cExt == "bmp"
  148.  
  149.         oBmp:LoadBMP( cPath + "\" + cItem2 )
  150.  
  151.         if oBmp:nWidth > MAXWIDTH .or. ;
  152.            oBmp:nHeight > MAXHEIGHT
  153.            oBmp:lStretch := .t.
  154.         else
  155.            oBmp:lStretch := .f.
  156.         endif
  157.  
  158.         Return nil
  159.  
  160. *   CASE cExt == "exe"
  161. *
  162. *        winexec( cPath + "\" + cItem )
  163. *        Return nil
  164.  
  165.    CASE cItem == ".."
  166.  
  167.         cAuxPath :=  substr ( cPath, 1, RAT ("\",cPath) - 1 )
  168.  
  169.         cPath := cAuxPath
  170.  
  171.  
  172.    CASE ISUPPER ( SUBSTR ( cItem, 1, 1) )
  173.  
  174.  
  175.         cAuxPath :=  cPath + "\"+ cItem
  176.  
  177.         cPath := cAuxPath
  178.  
  179.  
  180.  
  181.    CASE SUBSTR(cItem,1,1) == "["
  182.  
  183.         // voy a cambiar a una unidad
  184.  
  185.         cUnidad := SUBSTR(cItem,3,1)
  186.  
  187.         cPath := cUnidad + ":"
  188.  
  189.  
  190. ENDCASE
  191.  
  192. aAux   := FillDir ()
  193. aFiles := FillDir (,.t.)
  194.  
  195. if !Empty (aAux)
  196.  
  197.    For n := 1 to Len ( cDrives )
  198.       aadd( aAux, "[-" + substr( cDrives,n,1) + "-]" )
  199.    next
  200.  
  201.    oLbx1:SetItems ( aAux )
  202.    oLbx2:SetItems ( aFiles )
  203.  
  204. else
  205.    MsgStop ("Drive not ready!")
  206. endif
  207.  
  208.  
  209. *oWnd:Say (20,20,cPath + SPACE (100) )
  210.  
  211.  
  212. Return nil
  213.  
  214. Function MenuTool(nX,nY,oLbx)
  215. Local n, cAux := ""
  216.  
  217. Local oMenu
  218.  
  219. MENU oMenu POPUP
  220.  
  221.    MENUITEM "Copy"   ACTION ( ASIZE(aSelItems,0), aeval(oLbx:GetSelItem(),{|x|aadd(aSelItems,oLbx:GetItem( x ))}))
  222.  
  223.    if !empty (aSelItems)
  224.       MENUITEM "Paste"  ACTION wqout (aSelItems)
  225.    endif
  226.  
  227.    SEPARATOR
  228.  
  229.    MENUITEM "Ord Nombre" ACTION SortDir ("name")
  230.    MENUITEM "Ord Tipo"   ACTION SortDir ("ext")
  231.  
  232.    SEPARATOR
  233.  
  234.    MENUITEM "Borrar"
  235.    SEPARATOR
  236.  
  237.    for n = 1 to Len (cDrives)
  238.  
  239.       cAux := "ChanDriv("+substr( cDrives,n,1)+")"
  240.  
  241.       MENUITEM "[-" + substr( cDrives,n,1) + "-]" ACTION &caux
  242.    next
  243.  
  244.  
  245.  
  246. ENDMENU
  247.  
  248. ACTIVATE POPUP oMenu AT nX,nY OF oLbx
  249.  
  250.  
  251. Return nil
  252.  
  253.  
  254. Function sortdir ( cPor )
  255. Local n
  256.  
  257.  
  258. aAux := FillDir ( cPor )
  259.  
  260. if !Empty (aAux)
  261.  
  262.    For n := 1 to Len ( cDrives )
  263.       aadd( aAux, "[-" + substr( cDrives,n,1) + "-]" )
  264.    next
  265.  
  266.    oLbx1:SetItems ( aAux )
  267. else
  268.    MsgStop ("Unidad no disponible")
  269. endif
  270.  
  271.  
  272. oWnd:Say (20,20,cPath + SPACE (100) )
  273.  
  274.  
  275. Return nil
  276.  
  277.  
  278.  
  279.  
  280. function chandriv (c)
  281. ? c
  282. return nil
  283.  
  284.  
  285.  
  286.  
  287.