home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 12 / slist.prg < prev    next >
Text File  |  1992-03-08  |  4KB  |  108 lines

  1. *********************************************************************
  2. * SLIST.PRG - Modified version of the output from FoxPro's screen
  3. *             builder
  4. *********************************************************************
  5. PARAMETER aAvail, aSelected, cTitle
  6. IF EMPTY(cTitle)          && Supply default title
  7.    cTitle="Make Your Selections and Place Them In Any Order"
  8. ENDIF
  9.  
  10. DEFINE WINDOW wpicklist FROM INT((SROW()-19)/2),INT((SCOL()-58)/2) ;
  11.  TO INT((SROW()-19)/2)+18,INT((SCOL()-58)/2)+57 TITLE cTitle ;
  12.       FLOAT NOCLOSE SHADOW DOUBLE COLOR SCHEME 5
  13.  
  14. nBarctr = 0               && BAR index counter, never decrements
  15.                           &&  as the popup is relative
  16. nSelected = 0             && counter for the Selected array
  17. nAvail = ALEN(aAvail)     && number of items in the Available array
  18. nAvailpos = 1             && initial/current position of bar in Available list
  19. nSelpos = 0               && initial/current position of bar in Selected list
  20. cOKCancel = ""            && return value of OK and Cancel buttons
  21. DEFINE POPUP pSelected RELATIVE MOVER SCROLL MARGIN MARK ""
  22.  
  23. ACTIVATE WINDOW wpicklist NOSHOW
  24.  
  25. @ 0,7 SAY "Available"
  26. @ 0,39 SAY "Selected"
  27.  
  28. @ 1,1 GET nAvailpos PICTURE "@&N" FROM aAvail RANGE 1, nAvail ;
  29.    SIZE 16,22 DEFAULT 1 VALID fnAdd(nAvailpos) COLOR SCHEME 6
  30.  
  31. @ 1,33 GET nSelpos PICTURE "@&N" POPUP pSelected SIZE 16,22 ;
  32.    DEFAULT " " VALID fnRemove(nSelpos) DISABLE COLOR SCHEME 6
  33.  
  34. @ 11,24 GET cOKCancel PICTURE "@*VT \!\<OK;\?\<Cancel" ;
  35.    SIZE 1,8,1 DEFAULT 1
  36.  
  37. ACTIVATE WINDOW wpicklist
  38. READ CYCLE SHOW Slist_SHOW()
  39. RELEASE WINDOW wpicklist
  40.  
  41. * Post-READ Cleanup code
  42. nSelected = 0
  43. IF cOkcancel = "OK"
  44.    *
  45.    * Build Selected array with prompts from the Selected box
  46.    *
  47.    nSelected = CNTBAR('pSelected')
  48.    FOR n = 1 TO nSelected
  49.      * GETBAR() returns the next bar number, PRMBAR() its prompt
  50.      aSelected(n) = PRMBAR('pSelected',GETBAR('pSelected',n))
  51.    ENDFOR
  52. ENDIF
  53. RETURN (nSelected)                   && Return number of items selected
  54. *
  55. * FUNCTION Slist_SHOW - Called to enable or disable controls
  56. *
  57. FUNCTION Slist_SHOW
  58. IF nSelected  > 0                    && If Selected items exist,
  59.    SHOW GET nSelpos ENABLE           && enable the Selected listbox
  60.    SHOW GET cOkcancel,1 ENABLE
  61. ELSE
  62.    SHOW GET nSelpos DISABLE          && Otherwise disable it
  63.    SHOW GET cOkcancel,1 DISABLE
  64. ENDIF
  65. IF nAvail > 0                        && If Available items exist,
  66.    SHOW GET nAvailpos ENABLE         && enable the Available listbox
  67. ELSE
  68.    SHOW GET nAvailpos DISABLE        && Otherwise disable it
  69. ENDIF
  70. RETURN .T.
  71. *
  72. * FUNCTION fnAdd - Add an item to the Selected list
  73. *
  74. FUNCTION fnAdd                       && Add an item to Selected list
  75. PARAMETER nPicked
  76. nSelected = nSelected + 1            && Update selected array counter
  77. nSelpos = nSelected                  && Set current pos of bar in selected
  78.                                      &&   to the last item in list
  79. nBarctr = nBarctr + 1                && Relative, it never decrements
  80. * Define a new bar with prompt
  81. * from Available list
  82. DEFINE BAR (nBarctr) OF pSelected PROMPT aAvail(nPicked)
  83. IF nPicked = nAvail                  && If item picked is the last one
  84.    nAvailpos = nAvail - 1            && Make (last - one) the current item
  85. ENDIF
  86. =ADEL(aAvail, nPicked)               && Delete current item from Available
  87. nAvail = nAvail - 1                  && Decrement the Available counter
  88. IF nAvail = 0                        && If there is none left
  89.    _curobj = 2                       && put cursor on the OK button.
  90. ENDIF
  91. SHOW GETS                            && Update screen
  92. RETURN .F.
  93. *
  94. * FUNCTION fnRemove - Remove an item from the Selected list
  95. *
  96. FUNCTION fnRemove                    && Remove item from Selected list
  97. PARAMETER nPicked
  98. nSelected = nSelected - 1            && Decrement counter
  99. nAvailpos = MAX(nAvailpos, 1)        && Get current position
  100. nAvail = nAvail + 1                  && Increment it
  101. =AINS(aAvail, nAvailpos)             && Make space and put it back
  102. aAvail(nAvailpos) = PRMBAR('pSelected',GETBAR('pSelected',nPicked))
  103. =ASORT(aAvail, 1, nAvail)            && Sort the array
  104. nSelpos = MIN(nSelpos, nSelected)    && Update the Selected position
  105. RELEASE BAR (GETBAR('pSelected',nPicked)) OF pSelected
  106. SHOW GETS
  107. RETURN .F.
  108.