home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / visilotu.zip / RENFLD.PRG < prev    next >
Text File  |  1995-08-31  |  9KB  |  353 lines

  1. !.HEADER
  2. ! Program Name     - RENFLD.PRG
  3. ! Program Function - Program Task for the Sample Lotus Notes Query application
  4. !                    This program provides a dialog allowing the user to 
  5. !                    modify the names of the Visualizer columns to be created
  6. !                    when querying the Lotus Notes database.
  7. !  
  8. ! Called by        - LNQMAIN.PRG
  9. ! Calls            - <none>
  10. !.spec winsize MAX MAX
  11. !.spec textcol 0 17
  12. !.HEADER
  13. !
  14. ! DEFINITION
  15. ! Some ASL commands can be placed outside of the normal block
  16. ! structure. This block is provided to allow such commands to
  17. ! be accomodated
  18. !
  19. ! Assign boolean variables
  20. !
  21. DECLARE TASK NUMERIC yes = 1
  22. DECLARE TASK NUMERIC no  = 0
  23. !
  24. DECLARE TASK CHAR[4] ThisTask = A.System.ThisTask
  25. !
  26. ! ON SELECT
  27. ! This block is triggered whenever the user selects a control
  28. ! or menu entry.
  29. !
  30. ON SELECT
  31. DO
  32.   CASE A.System.Object
  33.     !
  34.     WHEN "T.W_renfld.STD_PUSH"
  35.     DO
  36.       CASE A.System.Boxnumber
  37.         WHEN 1                                    ! button marked 'Rename'
  38.         DO
  39.           !
  40.           ! need to validate names
  41.  
  42.  
  43.           DEFINE (?pNewNames)[0]                  ! reset the caller's vector
  44.           COPY NewNames,(?pNewNames)              ! and copy ours into it
  45.  
  46.           LET T..W_RenFld'VISIBLE = No
  47.  
  48.         END
  49.         !
  50.         WHEN 2                                    ! button marked 'Clear'
  51.         DO
  52.           !
  53.           DEFINE NewNames[0]                      ! reset our vector
  54.           COPY (?pNewNames),NewNames              ! and copy caller's
  55.  
  56.         END
  57.         !
  58.         WHEN 3                                    ! button marked 'Cancel'
  59.         DO
  60.           LET T..W_RenFld'VISIBLE = No
  61.  
  62.         END
  63.         !
  64.         WHEN 4                                    ! button marked 'Help'
  65.         DO
  66.           ! help button
  67.           NOTHING
  68.         END
  69.         !
  70.       END
  71.     END
  72.     !
  73.     WHEN "T.W_renfld.LIST1"
  74.     DO
  75.       ! list box set for single select mode
  76.     END
  77.   END
  78. END
  79. !
  80. ! ON DATA
  81. ! This block responds to controls which can accept data entry.
  82. ! It is executed whenever the cursor leaves the control after
  83. ! data has been changed. This is normally used to provide input
  84. ! validation.
  85. !
  86. ON DATA
  87. DO
  88.   CASE A.System.Object
  89.     !
  90.     WHEN "T.W_RenFld.LIST1"
  91.     DO
  92.       IF A.System.PositionY = 0
  93.         RETURN
  94.  
  95.       LET ValidName = Valid_ASL_Name(A.System.BoxValue)
  96.  
  97.       IF ValidName \=""
  98.       DO
  99.         ERROR 10001,ValidName
  100.  
  101.         LET ValidNames = No
  102.  
  103.         CALL T.W_RenFld.LIST1'REFRESH()
  104.         RETURN
  105.       END
  106.  
  107.  
  108.       LET AlreadyExists = FIND(NewNames,A.System.BoxValue)
  109.  
  110.       IF AlreadyExists > 0 & A.System.BoxNumber \= AlreadyExists
  111.       DO
  112.         ERROR 10001,STRING(
  113.          "The column ^ already exists. The new name has been reset.",
  114.          A.System.BoxValue)
  115.  
  116.         CALL T.W_RenFld.LIST1'REFRESH()
  117.         RETURN
  118.       END
  119.  
  120.       LET NewNames[A.System.BoxNumber] =
  121.        A.System.BoxValue
  122.  
  123.       CALL T.W_RenFld.LIST1'UNLOCK(A.System.BoxNumber)
  124.  
  125.     END
  126.   END
  127. END
  128. !
  129. ! ON START
  130. ! This block is executed when the program is initially invoked.
  131. ! It is normally used to initialize variables needed during
  132. ! program execution and to open the main window of the
  133. ! application.
  134. !
  135. ON START(pOldNames,pNewNames,pSelected,pOwnerWindow)
  136. DO
  137.   DECLARE GLOBAL POINTER pOldNames                  ! pointer to Original column names vector
  138.   DECLARE GLOBAL POINTER pNewNames                  ! pointer to Modified column names vector
  139.   DECLARE GLOBAL POINTER pSelected                  ! pointer to vector for ordering of columns
  140.   DECLARE GLOBAL POINTER pOwnerWindow               ! pointer to ownerwindow
  141.   !
  142.   ! Open the object store holding the user library
  143.   !
  144.   OPEN OBJECTSTORE MyLib,
  145.    NAME ="UserLib.A95",
  146.    LOCATION = S.Control.Path
  147.  
  148.  
  149.   LET ValidNames = Yes
  150.   !
  151.   ! Call procedure to define data for list control(s)
  152.   !
  153.   CALL List_Define
  154.  
  155.   COPY (?pNewNames),NewNames                      ! copy vectors from caller
  156.   COPY (?pOldNames),OldNames
  157.   !
  158.   OPEN WINDOW W_renfld, , "I.Windows.renfld",
  159.    VISIBLE     = No,
  160.    OWNERWINDOW = (?pOwnerWindow)
  161.  
  162.   !
  163.   ! assign the default push button
  164.   !
  165.   LET T.W_renfld.STD_PUSH[0]'DEFAULT = 1
  166.   !
  167.   ! assign the help button
  168.   !
  169.   LET T.W_renfld.STD_PUSH[0]'HELPBUTTON = 4
  170.   !
  171.   ! assign the column titles for list controlLIST1
  172.   MODIFY T.W_renfld.LIST1,
  173.    COLTITLE1="Title_1",
  174.    ORDERDATA = pSelected                          ! set order for columns in listbox
  175.  
  176.   LET T..W_renfld'VISIBLE=Yes
  177.  
  178. END
  179. !
  180. ! ON QUIT
  181. ! This block is executed when the user uses Close in the
  182. ! system menu.
  183. ! For a secondary window this would imply, 'shut the window'.
  184. ! For a primary window the implication is, 'close the
  185. ! Application'.
  186. !
  187. ON QUIT
  188. DO
  189.   CASE A.System.Object
  190.  
  191.     WHEN "T..W_renfld"                            ! primary window
  192.       LET T..W_RenFld'VISIBLE = No
  193.  
  194.     OTHERWISE
  195.       SHUT ?A.System.Object
  196.  
  197.   END
  198. END
  199. !
  200. ! ON ENTER
  201. ! This block is executed when the user hits the enter key.
  202. ! This is normally coded to be equivalent to selecting
  203. ! the default push button (often the OK button).
  204. !
  205. ON ENTER
  206. DO
  207.   IF A.System.Object = "T..W_renfld"
  208.   DO
  209.     LET A.System.BoxNumber = T.W_renfld.Std_Push[0]'DEFAULT
  210.     LET A.System.Object = POINTER(T.W_renfld.Std_Push[0])
  211.     RUN PROGRAM ThisTask, SELECT
  212.   END
  213. END
  214. !
  215. ! ERROR event
  216. ! This block is executed when there is a run-time error.
  217. ! You can trap errors here or allow the error message provided
  218. ! to identify the error and stop the program.
  219. !
  220.  
  221. ON ERROR
  222. DO
  223.   DECLARE CHAR[7] ans
  224.   DECLARE NUMERIC i
  225.   !
  226.   ! Message to identify failing module and line
  227.   !
  228.   LET ans = DIALOG("FTB7004", 0,
  229.    A.System.ErrorModule,
  230.    A.System.ErrorLine)
  231.  
  232.   DO i = 1 : A.System.ErrorNumber[0]'ENTRIES
  233.     IF ans = "CANCEL"
  234.       TERMINATE
  235.       !
  236.       ! Display system message corresponding to error
  237.       !
  238.     LET ans = DIALOG ("FTB" || A.System.Errornumber[i], 0,
  239.      A.System.ErrorInfo[i])
  240.   END
  241.  
  242.   STOP
  243. END
  244. !
  245. ! ON STOP
  246. ! This block is executed when the program is terminated.
  247. ! You should use the block to carry out any housekeeping
  248. ! required before closing
  249. !
  250. ON STOP
  251. DO
  252.   !
  253.   STOP
  254. END
  255. !
  256. ! Construct the arrays needed to support list controls
  257. !
  258. PROCEDURE List_Define
  259. DO
  260.   !
  261.   ! Define data to handle list 'T.W_renfld.LIST1'
  262.   !
  263.   DEFINE RColumns[0]                              ! REFERENCE vector
  264.   DEFINE RLayout[0]                               ! EXPRESSION vector
  265.   !
  266.   ! fill the EXPRESSION vector
  267.   !
  268.   INSERT RLayout[0]="WIDTH=100 SEPARATOR=YES JUST=LEFT READONLY=YES"
  269.   INSERT RLayout[0]="WIDTH=100 SEPARATOR=YES JUST=LEFT READONLY=NO"
  270.   !
  271.   ! Initialise the referred vectors. These are the vectors
  272.   ! which will contain the data to be displayed
  273.   !
  274.   DEFINE OldName[0]
  275.   DEFINE NewName[0]
  276.   !
  277.   ! fill the REFERENCE vector to point to these vectors
  278.   !
  279.   INSERT RColumns[0] = "OldNames"
  280.   INSERT RColumns[0] = "NewNames"
  281.   !
  282.   ! create and fill the titles vector
  283.   !
  284.   DEFINE Title_1[0]
  285.   INSERT Title_1[0] = "Old name"
  286.   INSERT Title_1[0] = "New name"
  287. END
  288. !
  289. ! ON OPEN
  290. ! The OPEN event is signalled whenever the user 'double clicks'
  291. ! or opens a LIST control
  292. !
  293. ON OPEN
  294. DO
  295.   IF A.System.Object = "T.W_renfld.LIST1"
  296.   DO
  297.     !
  298.   END
  299. END
  300. ! Add your code for this Event below.
  301.  
  302. ON QUEUE
  303. DO
  304.   DEFINE NewNames[0]
  305.   DEFINE OldNames[0]
  306.  
  307.   COPY (?pNewNames),NewNames                      ! copy vectors from caller
  308.   COPY (?pOldNames),OldNames
  309.  
  310.  
  311.   LET T..W_RenFld'VISIBLE = Yes
  312. END
  313. !
  314. ! User specified procedures may have up to 20 passed parameters.
  315. ! Procedures may be called as functions (using the RETURN
  316. ! facility to return a value) or may be called as normal
  317. ! procedures.
  318. !
  319. PROCEDURE Valid_ASL_Name(pName)
  320. DO
  321.   DECLARE LOCAL NULL CHARACTER[*] pName
  322.   DECLARE LOCAL CHARACTER[*]      MsgText
  323.   DECLARE LOCAL CHARACTER[37]     ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
  324.  
  325.   CASE
  326.     WHEN LENGTH(pName) > 20
  327.       LET MsgText = STRING(
  328.        "The variable name ^ is too long.",
  329.        pName)
  330.  
  331.     WHEN SCAN(pName,ValidChars,,,"\=","1")>0
  332.       LET MsgText = STRING(
  333.        "The variable name ^ contains invalid characters and has been reset.",
  334.        pName,)
  335.  
  336.     WHEN NOVALUE(pName)
  337.     DO
  338.       LET MsgText = "Blank column names are not allowed and has been reset."
  339.     END
  340.  
  341.     OTHERWISE
  342.       LET MsgText = ""
  343.   END
  344.  
  345.   RETURN MsgText
  346. END
  347.