home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / cuaclip.zip / DEMO.PRG < prev    next >
Text File  |  1993-06-01  |  8KB  |  377 lines

  1. /************************************************************************
  2. *  LB_Demo.PRG - Demo for the List Box GET reader.
  3. *
  4. *  Copyright (c) 1990-1993 Delcom-Deltranik Int'l Software Engineering
  5. *
  6. *  Author: Dave Rooney
  7. *  Date  : March 16, 1993
  8. *
  9. ************************************************************************/
  10.  
  11. #include "CUAClip.ch"
  12. #include "Mouse.ch"
  13. #include "Set.ch"
  14. #include "Directry.ch"
  15. #include "Inkey.ch"
  16.  
  17.  
  18. STATIC aFiles,        ; // Array of files for the unprocessed list
  19.          aUpload          // Array of files to be uploaded
  20.  
  21. FUNCTION LB_Demo ( cFileSpec )
  22.  
  23. LOCAL cDOSScreen,    ; // Screen on entry
  24.         cOldColor,     ; // Colour on entry
  25.         nCursor,       ; // Cursor on entry
  26.         cScreen,       ; // Screen behind dialog box
  27.         cListClr,      ; // Button GET colour string
  28.         cButtonClr,    ; // Button GET colour string
  29.         aDir,          ; // Directory info array
  30.         cToAdd,        ; // Name of file to be added
  31.         cToRemove,     ; // Name of file to be removed
  32.         GetList,       ; // Getlist array
  33.         lProceed,      ; // .T. if proceeding
  34.         i                // Loop counter
  35.  
  36. DEFAULT cFileSpec TO "*.*"
  37.  
  38. cDOSScreen := SAVESCREEN()
  39. cOldColor  := SETCOLOR("W+/W")
  40. nCursor    := SETCURSOR(0)
  41. aUpload    := {}
  42. GetList    := {}
  43. lProceed   := .F.
  44. aDir       := DIRECTORY( cFileSpec )
  45. aFiles     := ARRAY( LEN( aDir ))
  46. cButtonClr := "W+/B, W+/R"
  47.  
  48. FOR i := 0 TO MAXROW()
  49.   @ i, 0 SAY PADR( REPLICATE( CHR( 254 ), ( i - 1 ) % 14 + 1 ) + ;
  50.         " CUA-Clip Interface Library Version 1.1b ", ;
  51.         80, CHR( 254 ) )
  52. NEXT i
  53.  
  54. //
  55. // Mouse setup...
  56. //
  57. InitMouse()
  58. SetMousePos( INT( MAXROW() / 2 ), INT( MAXCOL() / 2 ))
  59.  
  60. SetMouse( MOUSE_ON )
  61.  
  62. //
  63. // Clipper settings...
  64. //
  65. SET CENTURY OFF
  66. SET( _SET_BELL, .F. )
  67. SET( _SET_CONFIRM, .F. )
  68. SET( _SET_DATEFORMAT, "YY.MM.DD" )     // Standard ANSI format.
  69. SET( _SET_DELETED, .T. )
  70. SET( _SET_ESCAPE, .T. )
  71. SET( _SET_EXACT, .F. )
  72. SET( _SET_EXCLUSIVE, .F. )
  73. SET( _SET_MESSAGE, 0 )
  74. SET( _SET_MCENTER, .T. )
  75. SET( _SET_SCOREBOARD, .F. )
  76. SET( _SET_SOFTSEEK, .F. )
  77. SET( _SET_WRAP, .T. )
  78.  
  79. SETBLINK(.F.)
  80.  
  81. //
  82. // CUA-Clip library settings...
  83. //
  84. WindowsComp( .T. )
  85.  
  86. SetFlushKey( K_F10 )
  87. SetListKey( K_F5 )
  88.  
  89. SetMenuColor("N/BG,W+/B,N+/BG,R/BG,W+/B")
  90. SetPullColor("N/BG,W+/B,N+/BG,R/BG,W+/B")
  91.  
  92. //
  93. // Colours for the list box:
  94. //
  95. // 1 - Border & background colour - GET unselected
  96. // 2 - Border & background colour - GET selected
  97. // 3 - Border & background colour - WHEN condition is .F.
  98. // 4 - Unselected data items - GET selected
  99. // 5 - Selected data items - GET selected
  100. // 6 - Unselected data items - GET unselected
  101. // 7 - Selected data items - GET unselected
  102. //
  103. //           1     2     3     4     5     6     7
  104. SetLBColor("N/W*, B/W*, N/W*, W+/W, W+/R, N/W*, W/N")
  105.  
  106. //
  107. // Load the files array...
  108. //
  109. FOR i := 1 TO LEN( aDir )
  110.     aFiles[i] := PADR( aDir[ i, 1 ], 15 )
  111. NEXT
  112.  
  113. cScreen := ShadowBox( 3, 13, 21, 67, SPACE(8), "B/BG", .T. )
  114.  
  115. @ 3,13 SAY PADC( "Export", 55 ) COLOR "W+/B"
  116.  
  117. @ 4,15 SAY PADC( "Unprocessed", 18 ) COLOR "B/BG"
  118. @ 4,47 SAY PADC( "To Upload", 18 ) COLOR "B/BG"
  119.  
  120. @ 5,15 LISTBOX cToAdd TO 16,33 WITH aFiles ;
  121.         WHEN !EMPTY( aFiles ) ;
  122.         ACTION AddFile( cToAdd )
  123.  
  124. @ 18,16 BUTTON PADC( "Select All", 15 ) ;
  125.         WHEN !EMPTY( aFiles ) ;
  126.         ACTION AddAll() ;
  127.         COLOR cButtonClr
  128.  
  129. @ 5,47 LISTBOX cToRemove TO 16,65 WITH aUpload ;
  130.         WHEN !EMPTY( aUpload ) ;
  131.         ACTION RemoveFile( cToRemove )
  132.  
  133. @ 18,48 BUTTON PADC( "Remove All", 15 ) ;
  134.         WHEN !EMPTY( aUpload ) ;
  135.         ACTION RemoveAll() ;
  136.         COLOR cButtonClr
  137.  
  138. @ 20,27 BUTTON " Upload " ;
  139.         WHEN !EMPTY( aUpload ) ;
  140.         ACTION ( lProceed := .T. ) ;
  141.         COLOR cButtonClr
  142.  
  143. @ 20,44 BUTTON " Cancel " ;
  144.         ACTION !( lProceed := .F. ) ;
  145.         COLOR cButtonClr
  146.  
  147. READMODAL( GetList )
  148.  
  149. KillBox( cScreen )
  150.  
  151. IF lProceed .AND. !EMPTY( aUpload )
  152.     //
  153.     // Perform the Export...
  154.     //
  155.     Exporting( aUpload )
  156. ENDIF
  157.  
  158. //
  159. // Reset the environment...
  160. //
  161. SetMouse( MOUSE_OFF )
  162.  
  163. RESTSCREEN(,,,, cDOSScreen )
  164. SETCOLOR( cOldColor )
  165. SETCURSOR( nCursor )
  166. SETPOS( MAXROW() - 1, 0 )
  167. ?
  168.  
  169. QUIT
  170.  
  171. RETURN NIL
  172. //
  173. // EOP: Export
  174. //
  175.  
  176.  
  177. ***************************
  178. **   FUNCTION Exporting  **
  179. *****************************************************************************
  180. //
  181. //  This function performs the export.
  182. //
  183. //  Parameters: aUpload - The array of file names to be exported.
  184. //
  185. //     Returns: NIL
  186. //
  187.  
  188. STATIC FUNCTION Exporting ( aUpload )
  189.  
  190. LOCAL cScreen,       ; // Screen on entry
  191.         cOldColor,     ; // Colour on entry
  192.         nMouse,        ; // Mouse on entry
  193.         nTotFiles,     ; // Total number of files to be uploaded
  194.         nPercent,      ; // Percentage complete
  195.         i, j             // Loop counters
  196.  
  197. cOldColor := SETCOLOR()
  198.  
  199. cScreen := ShadowBox( 5, 18, 10, 62, SPACE(8), "B/BG", .T. )
  200.  
  201. @ 5,18 SAY PADC( "Exporting", 45 ) COLOR "W+/B"
  202. @ 7,20 SAY "Exporting:" COLOR "B/BG"
  203. @ 9,20 SAY REPLICATE( "░", 35 ) COLOR "W+/BG"
  204.  
  205. nTotFiles := LEN( aUpload )
  206.  
  207. FOR i := 1 TO nTotFiles
  208.     @ 7,31 SAY PADR( aUpload[i], 20 ) COLOR "N/BG"
  209.  
  210.     //
  211.     // Your export code here...
  212.     //
  213.  
  214.     //
  215.     // Update progress gauge...
  216.     //
  217.     nPercent := INT(( i / nTotFiles ) * 100 )
  218.  
  219.     @ 9,20 SAY REPLICATE( "█", INT(( i / nTotFiles ) * 35 )) COLOR "W+/BG"
  220.     @ 9,57 SAY STR( nPercent, 3 ) + "%" COLOR "N/BG"
  221.  
  222.     INKEY( 0.35 )    // ...for effect!
  223. NEXT
  224.  
  225. SETCOLOR( "W+/BG" )
  226. @ 7,20 SAY PADR( "Complete. Press any key...", 40 )
  227.  
  228. TONE( 250, 1 )
  229.  
  230. InterruptKey(0)
  231.  
  232. KillBox( cScreen )
  233.  
  234. //
  235. // Reset the environment...
  236. //
  237. SETCOLOR( cOldColor )
  238.  
  239. RETURN NIL
  240. //
  241. // EOP: Exporting
  242. //
  243.  
  244.  
  245. *************************
  246. **   FUNCTION AddFile  **
  247. *****************************************************************************
  248. //
  249. //  This function adds the specified file to the upload list.
  250. //
  251. //  Parameters: cFile - The name of the file to be uploaded.
  252. //
  253. //     Returns: Always returns .T.
  254. //
  255.  
  256. STATIC FUNCTION AddFile ( cFile )
  257.  
  258. LOCAL nPos     // Position in aFiles of the selection
  259.  
  260. //
  261. // Add the file to the upload list...
  262. //
  263. AADD( aUpload, cFile )
  264.  
  265. // ...and remove it from the unprocessed list.
  266. IF ( nPos := ASCAN( aFiles, cFile )) > 0
  267.     ADEL( aFiles, nPos )
  268.     ASIZE( aFiles, LEN( aFiles ) - 1 )
  269. ENDIF
  270.  
  271. Monitor()
  272.  
  273. RETURN .F.
  274. //
  275. // EOP: AddFile
  276. //
  277.  
  278.  
  279. ****************************
  280. **   FUNCTION RemoveFile  **
  281. *****************************************************************************
  282. //
  283. //  This function removes the specified file to the upload list.
  284. //
  285. //  Parameters: cFile - The name of the file to be removed from the list.
  286. //
  287. //     Returns: Always returns .F.
  288. //
  289.  
  290. STATIC FUNCTION RemoveFile ( cFile )
  291.  
  292. LOCAL nPos     // Position in aFiles of the selection
  293.  
  294. //
  295. // Add the file to the unprocessed list...
  296. //
  297. AADD( aFiles, cFile )
  298.  
  299. // ...and remove it from the unprocessed list.
  300. IF ( nPos := ASCAN( aUpload, cFile )) > 0
  301.     ADEL( aUpload, nPos )
  302.     ASIZE( aUpload, LEN( aUpload ) - 1 )
  303. ENDIF
  304.  
  305. Monitor()
  306.  
  307. RETURN .F.
  308. //
  309. // EOP: RemoveFile
  310. //
  311.  
  312.  
  313. ************************
  314. **   FUNCTION AddAll  **
  315. *****************************************************************************
  316. //
  317. //  This function adds all files in the unprocessed list to the
  318. //  upload list.
  319. //
  320. //  Parameters: None.
  321. //
  322. //     Returns: Always returns .F.
  323. //
  324.  
  325. STATIC FUNCTION AddAll
  326.  
  327. LOCAL i     // Loop counter
  328.  
  329. FOR i := 1 TO LEN( aFiles )
  330.     //
  331.     // Add the file to the upload list...
  332.     //
  333.     AADD( aUpload, aFiles[i] )
  334. NEXT
  335.  
  336. ASIZE( aFiles, 0 )
  337.  
  338. Monitor()
  339.  
  340. RETURN .F.
  341. //
  342. // EOP: AddAll
  343. //
  344.  
  345.  
  346. ***************************
  347. **   FUNCTION RemoveAll  **
  348. *****************************************************************************
  349. //
  350. //  This function removes all files from the upload list, and places
  351. //  them in the unprocessed list.
  352. //
  353. //  Parameters: None.
  354. //
  355. //     Returns: Always returns .F.
  356. //
  357.  
  358. STATIC FUNCTION RemoveAll
  359.  
  360. LOCAL i     // Loop counter
  361.  
  362. FOR i := 1 TO LEN( aUpload )
  363.     //
  364.     // Add the file to the unprocessed list...
  365.     //
  366.     AADD( aFiles, aUpload[i] )
  367. NEXT
  368.  
  369. ASIZE( aUpload, 0 )
  370.  
  371. Monitor()
  372.  
  373. RETURN .F.
  374. //
  375. // EOP: RemoveAll
  376. //
  377.