home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / DIALOG.C < prev    next >
Text File  |  1995-11-20  |  69KB  |  1,431 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   dialog.c                                                                */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*   Common Cua routines to paint, remove and process keys and mouse events  */
  8. /* for pulldowns, popups and dialogs.                                        */
  9. /*                                                                           */
  10. /*...Release 1.01 (04/03/92)                                                 */
  11. /*...                                                                        */
  12. /*... 05/08/92  701   Srinivas  Cua Interface.                               */
  13. /*... 07/20/92  701   Selwyn    Revision.                                    */
  14. /*...                                                                        */
  15. /*...Release 1.02 (10/22/92)                                                 */
  16. /*...                                                                        */
  17. /*... 02/11/93  812   Selwyn    Wrong cursor position in callstack dialog.   */
  18. /*... 04/15/93  821   Selwyn    Changes in processing clicks on buttons.     */
  19. /*... 12/09/93  909   Joe       Fix for not erasing pulldowns in 132x60 mode.*/
  20. /*****************************************************************************/
  21. #include "all.h"
  22.  
  23. extern uchar   * _Seg16 VideoPtr;       /* -> to logical video buffer        */
  24. extern uchar    hiatt[];                /* attributes string for highlight.  */
  25. extern uchar    VideoAtr;               /* default logical video attribute.  */
  26. extern uchar    ScrollShade1[];         /* attribute string for scroll bar.  */
  27. extern uchar    ScrollShade2[];         /* attribute string for scroll bar.  */
  28. extern uchar    ClearField[];           /* attrib str for clearing fields.   */
  29. extern uchar    hilite[];               /* attrib str to highlight fields.   */
  30. extern uchar    badhilite[];            /* attrib str to highlight bad fields*/
  31. extern uchar    normal[];               /* attrib str to disp normal fields. */
  32. extern uchar    badnormal[];            /* attrib str to disp bad fields.    */
  33. extern uchar    Shadow[];               /* attrib str for shadowing around   */
  34. extern uchar    InScrollMode;           /* flag to tell we are in scrollmode */
  35. extern VIOCURSORINFO  NormalCursor;     /* make underscore flashing cursor   */
  36. extern KEY2FUNC defk2f[];               /* keys to functions map.            */
  37. extern CmdParms cmd;
  38. extern uint     VideoCols;              /* # of columns per screen           */
  39.  
  40. #define ON   1
  41. #define OFF  0
  42.  
  43. static PEVENT Event;
  44. static UINT   MouseState;
  45.  
  46. /*****************************************************************************/
  47. /* Strings used to display a pulldown.                                       */
  48. /*****************************************************************************/
  49. static uchar barstr[]    =  {V_BAR,0};
  50. static uchar UpArrow[]   =  {UPARROW,0};
  51. static uchar DnArrow[]   =  {DNARROW,0};
  52.  
  53. /*****************************************************************************/
  54. /* Strings used to display a pop up.                                         */
  55. /*****************************************************************************/
  56. static uchar toppop[]  =  {TL_CORNER,RepCnt(1),H_BAR,TR_CORNER,0};
  57. static uchar botpop[]  =  {BL_CORNER,RepCnt(1),H_BAR,BR_CORNER,0};
  58. static uchar poptll[]  =  {L_JUNCTION,RepCnt(1),H_BAR,0};
  59. static uchar poptlr[]  =  {RepCnt(1),H_BAR,R_JUNCTION,0};
  60.  
  61. /*****************************************************************************/
  62. /*  Windowsv()                                                               */
  63. /*                                                                           */
  64. /* Description:                                                              */
  65. /*                                                                           */
  66. /*     save area of screen about to be used by a pulldown or popup.          */
  67. /*                                                                           */
  68. /* Parameters:                                                               */
  69. /*                                                                           */
  70. /*   int x           x coordinate of top left corner                         */
  71. /*   int y           y coordinate of top left corner                         */
  72. /*   int rows        # of rows in window                                     */
  73. /*   int cols        # of columns in window                                  */
  74. /*   char *ptr       -> to save area                                         */
  75. /*                                                                           */
  76. /* Return:                                                                   */
  77. /*   None                                                                    */
  78. /*****************************************************************************/
  79. void windowsv(int x,int y,int rows,int cols,char *ptr)
  80. {
  81.   int i;
  82.  
  83.   for (i = 0 ; i < rows ; i++)
  84.   {
  85.     memcpy(ptr,VideoPtr+((VideoCols * (y + i)) + x) * 2,cols << 1);     /*909*/
  86.     ptr += cols * 2;
  87.   }
  88. }
  89.  
  90. /*****************************************************************************/
  91. /*  Windowrst()                                                              */
  92. /*                                                                           */
  93. /* Description:                                                              */
  94. /*                                                                           */
  95. /*     Restore screen area behind a pulldown or popup.                       */
  96. /*                                                                           */
  97. /* Parameters:                                                               */
  98. /*                                                                           */
  99. /*   int x           x coordinate of top left corner                         */
  100. /*   int y           y coordinate of top left corner                         */
  101. /*   int rows        # of rows in window                                     */
  102. /*   int cols        # of columns in window                                  */
  103. /*   char *ptr       -> to save area                                         */
  104. /*                                                                           */
  105. /* Return:                                                                   */
  106. /*   None                                                                    */
  107. /*****************************************************************************/
  108. void windowrst(int x,int y,int rows,int cols,char *ptr)
  109. {
  110.   int i;
  111.  
  112.   for (i = 0 ; i < rows ; i++)
  113.   {
  114.     memcpy(VideoPtr + ((VideoCols * (y + i)) + x) * 2,ptr,cols << 1);   /*909*/
  115.     ptr += cols * 2;
  116.   }
  117.   VioShowBuf(VideoCols*2*y,VideoCols*2*rows,0);                         /*909*/
  118. }
  119.  
  120. /*****************************************************************************/
  121. /*  DisplayDialog()                                                          */
  122. /*                                                                           */
  123. /* Description:                                                              */
  124. /*                                                                           */
  125. /*     Displays a dialog window along with buttons and scroll bar.           */
  126. /*                                                                           */
  127. /* Parameters:                                                               */
  128. /*                                                                           */
  129. /*   DIALOGSHELL *ptr     ->  pointer to a dialog shell structure            */
  130. /*                                                                           */
  131. /* Return:                                                                   */
  132. /*   None                                                                    */
  133. /*****************************************************************************/
  134. void DisplayDialog(DIALOGSHELL *ptr, int ScrollBar )
  135. {
  136.   int     i;                            /* counter                           */
  137.   int     tlen;                         /* title length                      */
  138.   BUTTON *ButtonPtr;                    /* -> to button struture.            */
  139.  
  140.   /***************************************************************************/
  141.   /* Get the Screen Access to write.                                         */
  142.   /***************************************************************************/
  143.   GetScrAccess();
  144.  
  145.   /***************************************************************************/
  146.   /* Allocate the memory required to save the screen that will be covered by */
  147.   /* Dialog and save the screen area which will be covered.                  */
  148.   /***************************************************************************/
  149.   ptr->SaveArea = Talloc(ptr->length * ptr->width * 2);
  150.   windowsv(ptr->col,ptr->row,ptr->length,ptr->width,ptr->SaveArea);
  151.  
  152.   /***************************************************************************/
  153.   /* - set the default video attribute.                                      */
  154.   /* - initialize color attribute for the clear cell.                        */
  155.   /***************************************************************************/
  156.   VideoAtr     = vaMenuBar;
  157.   ClearField[1] = (uchar)ptr->width;
  158.  
  159.   /***************************************************************************/
  160.   /* clear the screen area covered by the popup.                             */
  161.   /***************************************************************************/
  162.   for (i=0;i<ptr->length;i++)
  163.     putrc(ptr->row+i,ptr->col,ClearField);
  164.  
  165.   /***************************************************************************/
  166.   /* Put the length into topline string and then display the top line.       */
  167.   /***************************************************************************/
  168.   toppop[2] = (uchar)(ptr->width - 2);
  169.   putrc(ptr->row,ptr->col,toppop);
  170.  
  171.   /***************************************************************************/
  172.   /* display the title line in reverse video.                                */
  173.   /***************************************************************************/
  174.   tlen = strlen(ptr->title);
  175.   poptll[2] = (char) ((ptr->width - tlen - 2) >> 1);
  176.   poptlr[1] = (char) (ptr->width - tlen - poptll[2] - 2);
  177.   putrc(ptr->row+1,ptr->col,poptll);
  178.   VideoAtr = vaMenuCsr;
  179.   putrc(ptr->row+1,ptr->col + poptll[2] + 1,ptr->title);
  180.   VideoAtr = vaMenuBar;
  181.   putrc(ptr->row+1,ptr->col + poptll[2] + tlen + 1,poptlr);
  182.  
  183.   /***************************************************************************/
  184.   /* draw the sides of pop up window.                                        */
  185.   /***************************************************************************/
  186.   for(i = 2 ; i < (ptr->length - 1) ; i++)
  187.   {
  188.     putrc(ptr->row+i,ptr->col,barstr);
  189.     putrc(ptr->row+i,ptr->col+ptr->width-1,barstr);
  190.   }
  191.  
  192.   /***************************************************************************/
  193.   /* Put the scroll bar.                                                     */
  194.   /***************************************************************************/
  195.   if( ScrollBar )
  196.   {
  197.     putrc(ptr->row+UPARROWROWOFFSET,
  198.           ptr->col+ptr->width-SCROLLBARCOLOFFSET,UpArrow);
  199.     for(i = 3 ; i < (ptr->length - ptr->NoOfButtonRows-DNARROWROWOFFSET) ; i++)
  200.       putrc(ptr->row+i,ptr->col+ptr->width-SCROLLBARCOLOFFSET,ScrollShade1);
  201.     putrc(ptr->row+ptr->length-ptr->NoOfButtonRows-DNARROWROWOFFSET,
  202.             ptr->col+ptr->width-SCROLLBARCOLOFFSET,DnArrow);
  203.   }
  204.   /***************************************************************************/
  205.   /* Put length into botline string and then display the bottom line.        */
  206.   /***************************************************************************/
  207.   botpop[2] = (char) (ptr->width - 2);
  208.   putrc(ptr->row+ptr->length - 1,ptr->col,botpop);
  209.  
  210.   /***************************************************************************/
  211.   /* draw the buttons on the pop up.                                         */
  212.   /***************************************************************************/
  213.   ButtonPtr = ptr->Buttons;
  214.   for (i = 0 ; i < ptr->NoOfButtons ; i++)
  215.   {
  216.     putrc(ButtonPtr->row,ButtonPtr->col-1,"<");
  217.     putrc(ButtonPtr->row,ButtonPtr->col,ButtonPtr->Name);
  218.     putrc(ButtonPtr->row,ButtonPtr->col+ButtonPtr->length,">");
  219.     ButtonPtr++;
  220.   }
  221.  
  222.   /***************************************************************************/
  223.   /* Reset the video attributes to that of window.                           */
  224.   /***************************************************************************/
  225.   VideoAtr = vaMenuBar;
  226. }
  227.  
  228. /*****************************************************************************/
  229. /*  RemoveDialog()                                                           */
  230. /*                                                                           */
  231. /* Description:                                                              */
  232. /*                                                                           */
  233. /*     Removes a Dialog window from the screen.                              */
  234. /*                                                                           */
  235. /* Parameters:                                                               */
  236. /*                                                                           */
  237. /*   DIALOGSHELL *ptr     ->  pointer to a dialog shell structure            */
  238. /*                                                                           */
  239. /* Return:                                                                   */
  240. /*   None                                                                    */
  241. /*****************************************************************************/
  242. void RemoveDialog(DIALOGSHELL *ptr)
  243. {
  244.   /***************************************************************************/
  245.   /* - set the default video attribute.                                      */
  246.   /***************************************************************************/
  247.   VideoAtr = vaMenuBar;
  248.  
  249.   /***************************************************************************/
  250.   /* Restore the screen area covered by the pop up window.                   */
  251.   /* Release the memory allocated for screen save area.                      */
  252.   /***************************************************************************/
  253.   windowrst(ptr->col,ptr->row,ptr->length,ptr->width,ptr->SaveArea);
  254.   Tfree(ptr->SaveArea);
  255.  
  256.   /***************************************************************************/
  257.   /* Reset the Screen Access to write.                                       */
  258.   /***************************************************************************/
  259.   SetScrAccess();
  260. }
  261.  
  262. /*****************************************************************************/
  263. /*  VerfiyMousePtrinDialogButtons()                                          */
  264. /*                                                                           */
  265. /* Description:                                                              */
  266. /*                                                                           */
  267. /*   Check if the mouseclick is within the context of current dialog buttons */
  268. /* if it is map click to the key value associated with the button & ret 1    */
  269. /*                                                                           */
  270. /* Parameters:                                                               */
  271. /*                                                                           */
  272. /*   DIALOGSHELL *shell     -> to a dialog shell structure.                  */
  273. /*   uint        *Key       -> to mapped key stroke.                         */
  274. /*                                                                           */
  275. /* Return:                                                                   */
  276. /*   TRUE if the click is within the dialog or else FALSE                    */
  277. /*****************************************************************************/
  278. uchar  VerifyMouseinDialogButtons (DIALOGSHELL *shell,uint *Key)
  279. {
  280.   BUTTON *ButtonPtr;                    /* -> to button struture.            */
  281.   int     i;
  282.  
  283.   Event = GetCurrentEvent();
  284.   /***************************************************************************/
  285.   /* Is click on the buttons row of the popup window.                        */
  286.   /***************************************************************************/
  287.   if ( (Event->Row >= (shell->row + shell->length - shell->NoOfButtonRows - 1)) &&
  288.        (Event->Row <= (shell->row + shell->length - 1)) )
  289.   {
  290.      ButtonPtr = shell->Buttons;
  291.      for (i = 0 ; i < shell->NoOfButtons ; i++)
  292.      {
  293.        /**********************************************************************/
  294.        /* check if the click is in the button if yes return true and stuff   */
  295.        /* in the key associated with that button.                            */
  296.        /**********************************************************************/
  297.        if ( (Event->Row == ButtonPtr->row) &&
  298.             (Event->Col >= ButtonPtr->col-1) &&
  299.             (Event->Col <= ButtonPtr->col+ButtonPtr->length))
  300.        {
  301.           *Key = ButtonPtr->Key;
  302.           return(TRUE);
  303.        }
  304.        ButtonPtr++;
  305.      }
  306.   }
  307.   return(FALSE);
  308. }
  309.  
  310. /*****************************************************************************/
  311. /*                                                                           */
  312. /* GetEventPositionInDialog()                                                */
  313. /*                                                                           */
  314. /* Description:                                                              */
  315. /*                                                                           */
  316. /* Checks if the current event has occurred in the dialog scrollbar, dialog  */
  317. /* display area, dialog buttons or outside the dialog and returns the        */
  318. /* corresponding code.                                                       */
  319. /*                                                                           */
  320. /* Parameters:                                                               */
  321. /*                                                                           */
  322. /*   shell         input  - Pointer to DIALOGSHELL structure.                */
  323. /*   ptr           input  - Pointer to DIALOGCHOICE structure.               */
  324. /*   key           output - If the event is in the dialog buutons then the   */
  325. /*                          key corresponding to the button is returned in   */
  326. /*                          this uint *.                                     */
  327. /* Return:                                                                   */
  328. /*                                                                           */
  329. /*   SCROLLBAR_UPARROW      Event in scrollbar on the Up  arrow.            */
  330. /*   SCROLLBAR_DNARROW      Event in scrollbar on the Down  arrow.          */
  331. /*   SCROLLBAR_ABOVE_SLIDER Event in scrollbar above the slider.             */
  332. /*   SCROLLBAR_BELOW_SLIDER Event in scrollbar below the slider.             */
  333. /*   SCROLLBAR_ON_SLIDER    Event in scrollbar on the slider.                */
  334. /*   BUTTONS                Event in dialog buttons.                         */
  335. /*   DISPLAY_AREA           Event in the display area of the dialog.         */
  336. /*   OUTSIDE_DIALOG         Event outside the dialog.                        */
  337. /*                                                                           */
  338. /*****************************************************************************/
  339. uint GetEventPositionInDialog( DIALOGSHELL *shell, DIALOGCHOICE *ptr,
  340.                                uint *key, uchar ScrollBar )
  341. {
  342.   Event = GetCurrentEvent();
  343.   /***************************************************************************/
  344.   /* Is the click within the row and column boundries of the Dialog          */
  345.   /***************************************************************************/
  346.   if( ( Event->Row >= shell->row ) &&
  347.       ( Event->Row <= (shell->row + shell->length + 1) ) &&
  348.       ( Event->Col >= shell->col ) &&
  349.       ( Event->Col <= (shell->col + shell->width) ) )
  350.   {
  351.     if( (Event->Col == (shell->col + shell->width - SCROLLBARCOLOFFSET)) &&
  352.         ScrollBar )
  353.     {
  354.       if( Event->Row == (shell->row + UPARROWROWOFFSET) )
  355.         return( SCROLLBAR_UPARROW );
  356.  
  357.       if( Event->Row ==
  358.         (shell->row + shell->length - shell->NoOfButtonRows - DNARROWROWOFFSET))
  359.         return( SCROLLBAR_DNARROW );
  360.  
  361.       if( ( Event->Row >= (shell->row + UPARROWROWOFFSET +1) ) &&
  362.           ( Event->Row <= (shell->row+shell->length - shell->NoOfButtonRows -
  363.                            DNARROWROWOFFSET - 1) ) )
  364.       {
  365.         if( Event->Row < ptr->SliderStartRow )
  366.           return( SCROLLBAR_ABOVE_SLIDER );
  367.  
  368.         if( Event->Row > ptr->SliderStartRow + ptr->SliderSize )
  369.           return( SCROLLBAR_BELOW_SLIDER );
  370.  
  371.         return( SCROLLBAR_ON_SLIDER );
  372.       }
  373.     }
  374.     else
  375.     {
  376.       if( VerifyMouseinDialogButtons( shell, key ) )
  377.         return( BUTTONS );
  378.  
  379.       if( (Event->Row >= shell->row + shell->SkipLines) &&
  380.           (Event->Row <  shell->row + shell->SkipLines + ptr->MaxRows) )
  381.         return( DISPLAY_AREA );
  382.       return( ON_TITLE );
  383.     }
  384.   }
  385.   return( OUTSIDE_DIALOG );
  386. }
  387.  
  388. /*****************************************************************************/
  389. /*                                                                           */
  390. /* ProcessDialog()                                                           */
  391. /*                                                                           */
  392. /* Description:                                                              */
  393. /*                                                                           */
  394. /* This is the common function to process all the dialogs. It uses two       */
  395. /* fuctions in the shell structure. The two functions are                    */
  396. /*                                                                           */
  397. /*   1. Display function to display the elements in the display area of the  */
  398. /*      dialog.                                                              */
  399. /*   2. Dialog function which will process various events that occur in the  */
  400. /*      dialog.                                                              */
  401. /*                                                                           */
  402. /* This function also maintains the scrollbar display. As and when an event  */
  403. /* occurs in the dialog, it sends messages to the dialog function and calls  */
  404. /* the display functions to refresh the display area.                        */
  405. /*                                                                           */
  406. /* Parameters:                                                               */
  407. /*                                                                           */
  408. /*   shell         input  - Pointer to DIALOGSHELL structure.                */
  409. /*   ptr           input  - Pointer to DIALOGCHOICE structure.               */
  410. /*   Scrollbar     input  - Indicates whether the dialog needs a scrollbar.  */
  411. /*   ParamBlock    i/o    - Void pointer which will be passed on to the      */
  412. /*                          dialog function to facilitate parameter passing  */
  413. /*                          between the caller of the dialog and the dialog  */
  414. /*                          function.                                        */
  415. /*                                                                           */
  416. /* Assumptions:                                                              */
  417. /*                                                                           */
  418. /* This functions assumes that the two function pointers are set in the      */
  419. /* dialog shell parameter passed to it.                                      */
  420. /*                                                                           */
  421. /* Return:                                                                   */
  422. /*                                                                           */
  423. /*          None.                                                            */
  424. /*****************************************************************************/
  425. uint  ProcessDialog( DIALOGSHELL *shell, DIALOGCHOICE *ptr, uchar ScrollBar,
  426.                      void *ParamBlock )
  427. {
  428.   int    CurHighFldNo;
  429.   int    NewHighFldNo;
  430.   int    SelectIndex;
  431.   uint   key;
  432.   uint   ButtonKey;                                                     /*821*/
  433.   int    OldSkipRows;
  434.   uint   NoOfSliderPos;
  435.   uint   Resolution;
  436.   uint   i, rc;
  437.   uchar  PositionTable[10];
  438.   int    PositionTbPtr;
  439.   uchar  InDragMode;
  440.   uint   WaitTime;
  441.   uint   SliderDrag;
  442.   uint   EventPosition;
  443.   EVENT  Dummy;
  444.  
  445.   /***************************************************************************/
  446.   /* - set default video attribute.                                          */
  447.   /***************************************************************************/
  448.   VideoAtr = vaMenuBar;
  449.  
  450.   /***************************************************************************/
  451.   /* - Init the select Index and higlight indexs.                            */
  452.   /* - set the fld type and field column position.                           */
  453.   /* - set the cursor type.                                                  */
  454.   /***************************************************************************/
  455.   InDragMode    = FALSE;
  456.   CurHighFldNo  = 1;
  457.   NewHighFldNo  = 1;
  458.   SelectIndex   = 1;
  459.   PositionTbPtr = 0;
  460.  
  461.   VioSetCurType( &NormalCursor, 0 );
  462.  
  463.   /***************************************************************************/
  464.   /* - Send INIT_DIALOG message to the dialog function.                      */
  465.   /***************************************************************************/
  466.   Dummy.Value = INIT_DIALOG;
  467.   ptr->SkipRows = 0;                                                    /*812*/
  468.   shell->CurrentField = CurHighFldNo;
  469.   rc = (*(shell->DialogFunction))( shell, ptr, &Dummy, ParamBlock );
  470.   if( rc )
  471.     return( rc );
  472.  
  473.   if( (shell->CurrentField < ptr->SkipRows) ||
  474.       (shell->CurrentField > (ptr->MaxRows + ptr->SkipRows)) )
  475.   {
  476.     ptr->SkipRows = shell->CurrentField - 1;
  477.     ptr->SkipRows = min( ptr->SkipRows, (int)(ptr->entries - ptr->MaxRows) );
  478.     ptr->SkipRows = (ptr->SkipRows < 0) ? 0 : ptr->SkipRows;
  479.     CurHighFldNo  = shell->CurrentField - ptr->SkipRows;
  480.     NewHighFldNo  = shell->CurrentField - ptr->SkipRows;
  481.     SelectIndex   = shell->CurrentField;
  482.   }
  483.   else
  484.     SelectIndex = CurHighFldNo = NewHighFldNo = shell->CurrentField;
  485.  
  486.   /***************************************************************************/
  487.   /* If scrollbar is present calculate the various scrollbar attributes.     */
  488.   /***************************************************************************/
  489.   if( ScrollBar == TRUE )
  490.   {
  491.     /*************************************************************************/
  492.     /* Calculate the slider row.                                             */
  493.     /*************************************************************************/
  494.     ptr->SliderStartRow = shell->row + UPARROWROWOFFSET + 1;
  495.  
  496.     /*************************************************************************/
  497.     /* Calculate the Slider Size.                                            */
  498.     /*  RoundUp((Page Size / Total Entries) * No of Chars in Scroll Bar)     */
  499.     /*************************************************************************/
  500.     ptr->SliderSize = (uint)( (ptr->MaxRows * ptr->MaxRows) / ptr->entries )
  501.                       + 1;
  502.     if( ptr->SliderSize > ptr->MaxRows )
  503.        ptr->SliderSize = ptr->MaxRows;
  504.  
  505.     /*************************************************************************/
  506.     /* Calculate the Resolution.                                             */
  507.     /*  RoundUp(Total Entries / Page Size)                                   */
  508.     /*************************************************************************/
  509.     Resolution = (uint)( ptr->entries / ptr->MaxRows );
  510.  
  511.     /*************************************************************************/
  512.     /* Calculate the Slider Positions.                                       */
  513.     /*  No of Chars in Scroll Bar - Slider Size + 1                          */
  514.     /*  Build the scroll bar slider vs skip entries map.                     */
  515.     /*************************************************************************/
  516.     NoOfSliderPos = ptr->MaxRows - ptr->SliderSize + 1;
  517.     for( i = 0; i < NoOfSliderPos; i++ )
  518.       PositionTable[i] = 1 + ( i * Resolution );
  519.  
  520.    if( ptr->SkipRows )
  521.    {
  522.       for( i = 0; i < NoOfSliderPos; i++ )
  523.       {
  524.         if( i != (NoOfSliderPos - 1) )
  525.         {
  526.           if( ((ptr->SkipRows+1) >= (int)PositionTable[i]) &&
  527.               ((ptr->SkipRows+1) < (int)PositionTable[i+1]) )
  528.           {
  529.              PositionTbPtr = i;
  530.              ptr->SliderStartRow = shell->row+UPARROWROWOFFSET + 1 + i;
  531.              break;
  532.           }
  533.         }
  534.         else
  535.         {
  536.           if( (ptr->SkipRows+1) >= (int)PositionTable[i] )
  537.           {
  538.             PositionTbPtr = i;
  539.             ptr->SliderStartRow = shell->row+UPARROWROWOFFSET + 1 + i;
  540.             break;
  541.           }
  542.         }
  543.       }
  544.     }
  545.   }
  546.  
  547.   /***************************************************************************/
  548.   /* Display the color entries in the dialog box.                            */
  549.   /***************************************************************************/
  550.  
  551.   /***************************************************************************/
  552.   /* - Call display function to display elements in the display area.        */
  553.   /***************************************************************************/
  554.   (*(shell->Display))( shell, ptr );
  555.  
  556.   /***************************************************************************/
  557.   /* - Display the field cursor in the current field.                        */
  558.   /* - If scrollbar is present display the slider in the scrollbar.          */
  559.   /***************************************************************************/
  560.   putrc( shell->row + shell->SkipLines + CurHighFldNo - 1, shell->col + 1,
  561.          hilite );
  562.   if( ScrollBar == TRUE )
  563.   {
  564.     for( i = 0; i < ptr->SliderSize; i++ )
  565.       putrc( ptr->SliderStartRow + i, shell->col + shell->width -
  566.              SCROLLBARCOLOFFSET, ScrollShade2 );
  567.   }
  568.  
  569.   WaitTime = SEM_INDEFINITE_WAIT;
  570.  
  571.   for( ;; )
  572.   {
  573.     /*************************************************************************/
  574.     /* - Get an event.                                                       */
  575.     /*************************************************************************/
  576.     Event = GetEvent( WaitTime );
  577.  
  578.     /*************************************************************************/
  579.     /* Switch based on the type of the event.                                */
  580.     /*************************************************************************/
  581.     switch( Event->Type )
  582.     {
  583.       case TYPE_MOUSE_EVENT:
  584.       {
  585.         EventPosition = GetEventPositionInDialog( shell, ptr, &key, ScrollBar );
  586.         switch( Event->Value )
  587.         {
  588.           /*******************************************************************/
  589.           /* If the event is a left button down event.                       */
  590.           /*******************************************************************/
  591.           case EVENT_BUTTON_1_DOWN:
  592.           {
  593.             /*****************************************************************/
  594.             /* - Set the state of the button to Button Pressed.              */
  595.             /*   (The state will be over written at some places).            */
  596.             /*****************************************************************/
  597.             MouseState = STATE_BUTTON_PRESSED;
  598.             switch( EventPosition )
  599.             {
  600.               case SCROLLBAR_UPARROW:
  601.               {
  602.                 /*************************************************************/
  603.                 /* If the event was on the scrollbar up  arrow or on the    */
  604.                 /* down  arrow.                                             */
  605.                 /*  - Set mouse state to continuous press (the user might).  */
  606.                 /*  - Set the wait time to Initial wait (500ms) if it is a   */
  607.                 /*    real button one down event or if it is a fake event    */
  608.                 /*    set wait time to wait between two fake events (50ms).  */
  609.                 /*  - Set the key to scroll up or scroll down for futher     */
  610.                 /*    processing below.                                      */
  611.                 /*************************************************************/
  612.                 MouseState = STATE_CONTINUOUS_PRESS;
  613.                 key = SCROLLUP;
  614.                 if( Event->FakeEvent == TRUE )
  615.                   WaitTime = SCROLL_REGULAR_WAIT;
  616.                 else
  617.                   WaitTime = SCROLL_INITIAL_WAIT;
  618.                 break;
  619.               }
  620.  
  621.               case SCROLLBAR_DNARROW:
  622.               {
  623.                 MouseState = STATE_CONTINUOUS_PRESS;
  624.                 key = SCROLLDOWN;
  625.                 if( Event->FakeEvent == TRUE )
  626.                   WaitTime = SCROLL_REGULAR_WAIT;
  627.                 else
  628.                   WaitTime = SCROLL_INITIAL_WAIT;
  629.                 break;
  630.               }
  631.  
  632.               case SCROLLBAR_ABOVE_SLIDER:
  633.               {
  634.                 /*************************************************************/
  635.                 /* If the event was on the scrollbar above or below the      */
  636.                 /* slider                                                    */
  637.                 /*  -  Set key to page up or page down for further processing*/
  638.                 /*     below.                                                */
  639.                 /*************************************************************/
  640.                 key = PGUP;
  641.                 break;
  642.               }
  643.  
  644.               case SCROLLBAR_BELOW_SLIDER:
  645.               {
  646.                 key = PGDN;
  647.                 break;
  648.               }
  649.  
  650.               case SCROLLBAR_ON_SLIDER:
  651.               {
  652.                 /*************************************************************/
  653.                 /* If the event was on the scrollbar slider                  */
  654.                 /*  - Set mouse state to continuous press (the user might).  */
  655.                 /*  - Set the slider drag flag.                              */
  656.                 /*  - Set key to scroll bar for further processing below.    */
  657.                 /*************************************************************/
  658.                 MouseState = STATE_CONTINUOUS_PRESS;
  659.                 SliderDrag = ON;
  660.                 key = SCROLLBAR;
  661.                 break;
  662.               }
  663.  
  664.               case BUTTONS:
  665.                 /*************************************************************/
  666.                 /* If the button down event was on any of the dialog buttons */
  667.                 /* save the "button key" so that we can check when the user  */
  668.                 /* lets up on the button.                                    */
  669.                 /*************************************************************/
  670.                 ButtonKey = key;                                        /*821*/
  671.                 continue;                                               /*821*/
  672.  
  673.               case DISPLAY_AREA:
  674.               {
  675.                 /*************************************************************/
  676.                 /* If the event was on the display area of the dialog        */
  677.                 /*  - Calculate the new field to be high lighted.            */
  678.                 /*  - Set key to mouse pick and break for further processing.*/
  679.                 /*************************************************************/
  680.                 NewHighFldNo = (uint)Event->Row - shell->row -
  681.                                      shell->SkipLines + 1;
  682.                 key = MOUSEPICK;
  683.                 break;
  684.               }
  685.  
  686.               default:
  687.                 continue;
  688.             }
  689.             break;
  690.           }
  691.  
  692.           case EVENT_BUTTON_1_DOWN_MOVE:
  693.           {
  694.             /*****************************************************************/
  695.             /* If the event is a left button down move event.                */
  696.             /*****************************************************************/
  697.             switch( EventPosition )
  698.             {
  699.               case SCROLLBAR_UPARROW:
  700.               {
  701.                 /*************************************************************/
  702.                 /* If the user is still holding the mouse button 1 down      */
  703.                 /*  - Set key to scroll up / scroll down.                    */
  704.                 /*  - Set wait time to wait between two fake events (50ms).  */
  705.                 /*  - Change the event value to button down, so that the     */
  706.                 /*    subsequent fake events will be treated as button down  */
  707.                 /*    events until the user lets up the button.              */
  708.                 /*  - Break for further processing below.                    */
  709.                 /* Else                                                      */
  710.                 /*  - Set the mouse state to button move and continue for    */
  711.                 /*    further processing.                                    */
  712.                 /*************************************************************/
  713.                 if( MouseState == STATE_CONTINUOUS_PRESS )
  714.                 {
  715.                   key = SCROLLUP;
  716.                   WaitTime = SCROLL_REGULAR_WAIT;
  717.                   Event->Value = EVENT_BUTTON_1_DOWN;
  718.                 }
  719.                 else
  720.                   MouseState = STATE_BUTTON_MOVE;
  721.                 break;
  722.               }
  723.  
  724.               case SCROLLBAR_DNARROW:
  725.               {
  726.                 if( MouseState == STATE_CONTINUOUS_PRESS )
  727.                 {
  728.                   key = SCROLLDOWN;
  729.                   WaitTime = SCROLL_REGULAR_WAIT;
  730.                   Event->Value = EVENT_BUTTON_1_DOWN;
  731.                 }
  732.                 else
  733.                   MouseState = STATE_BUTTON_MOVE;
  734.                 break;
  735.               }
  736.  
  737.               case SCROLLBAR_ON_SLIDER:
  738.               {
  739.                 /*************************************************************/
  740.                 /* If the mouse drag is on the slider of the scrollbar, check*/
  741.                 /* if the user has already picked up (a button down) the     */
  742.                 /* slider and still holding on to it (continuous press state)*/
  743.                 /*  - Set the key value as scroll bar and mouse state        */
  744.                 /*  - Break for further processing below.                    */
  745.                 /* Else                                                      */
  746.                 /*  - Continue for there is no processing needs to be done.  */
  747.                 /*************************************************************/
  748.                 if( SliderDrag == ON && MouseState == STATE_CONTINUOUS_PRESS )
  749.                 {
  750.                   key = SCROLLBAR;
  751.                   break;
  752.                 }
  753.                 else
  754.                   continue;
  755.               }
  756.  
  757.               case DISPLAY_AREA:
  758.               {
  759.                 /*************************************************************/
  760.                 /* If the user has picked up the slider, or the Up or Down   */
  761.                 /* arrows in the scroll bar (clicks on the above, holds the  */
  762.                 /* button and moves), dont do any processing continue for the*/
  763.                 /* next event as nothing is to be done until he lets of the  */
  764.                 /* mouse button.                                             */
  765.                 /*************************************************************/
  766.                 if( MouseState == STATE_CONTINUOUS_PRESS )
  767.                   continue;
  768.  
  769.                 /*************************************************************/
  770.                 /* If the mouse state was button released, calculate the new */
  771.                 /* field row to be highlited, set the key to mouse pick and  */
  772.                 /* break for further processing below.                       */
  773.                 /* Else                                                      */
  774.                 /*  It might be a button release event, so reset the wait    */
  775.                 /*  time and continue for the next event.                    */
  776.                 /*************************************************************/
  777.                 if( MouseState == STATE_BUTTON_RELEASED )
  778.                 {
  779.                   NewHighFldNo = (uint)Event->Row - shell->row -
  780.                                        shell->SkipLines + 1;
  781.                   key = MOUSEPICK;
  782.                 }
  783.                 else
  784.                 {
  785.                   MouseState = STATE_BUTTON_MOVE;
  786.                   WaitTime   = SEM_INDEFINITE_WAIT;
  787.                   continue;
  788.                 }
  789.  
  790.                 MouseState = STATE_BUTTON_MOVE;
  791.                 break;
  792.               }
  793.  
  794.               default:
  795.               {
  796.                 /*************************************************************/
  797.                 /* The event has occured outside the dialog. If the user is  */
  798.                 /* still holding the button while he has picked up something */
  799.                 /* (as explained above) dont do anything continue for the    */
  800.                 /* next event, else set mouse state and wait time and        */
  801.                 /* continue.                                                 */
  802.                 /*************************************************************/
  803.                 if( MouseState == STATE_CONTINUOUS_PRESS )
  804.                   continue;
  805.  
  806.                 MouseState = STATE_BUTTON_MOVE;
  807.                 WaitTime = SEM_INDEFINITE_WAIT;
  808.                 continue;
  809.               }
  810.             }
  811.             break;
  812.           }
  813.  
  814.           case EVENT_NO_BUTTONS_DOWN:
  815.           case EVENT_NO_BUTTONS_DOWN_MOVE:
  816.           {
  817.             /*****************************************************************/
  818.             /* If the user lets of the button outside the dialog box beep.   */
  819.             /* - Reset the variables and then continue.                      */
  820.             /*****************************************************************/
  821. #if 0
  822.             if( EventPosition == OUTSIDE_DIALOG )
  823.               beep();
  824. #endif
  825.             /*****************************************************************/
  826.             /* If the user has let up on the mouse button on a dialog button */
  827.             /* check if he has already clicked on that button. If they match */
  828.             /* break for further processing doen below. If not continue.     */
  829.             /*****************************************************************/
  830.             if( EventPosition == BUTTONS )                              /*821*/
  831.               if( ButtonKey == key )                                    /*821*/
  832.                 break;                                                  /*821*/
  833.  
  834.             ButtonKey  = 0;                                             /*821*/
  835.             MouseState = STATE_BUTTON_RELEASED;
  836.             SliderDrag = OFF;
  837.             InDragMode = FALSE;
  838.             WaitTime = SEM_INDEFINITE_WAIT;
  839.             continue;
  840.           }
  841.  
  842.           default:
  843.           {
  844.             /*****************************************************************/
  845.             /* Ideally, should not enter this code.                          */
  846.             /*****************************************************************/
  847.             WaitTime = SEM_INDEFINITE_WAIT;
  848.             continue;
  849.           }
  850.         }
  851.         break;
  852.       }
  853.  
  854.       case TYPE_KBD_EVENT:
  855.       {
  856.         /*********************************************************************/
  857.         /* If it is keyboard event, set the key value and break for further  */
  858.         /* processing below.                                                 */
  859.         /*********************************************************************/
  860.         key = Event->Value;
  861.         break;
  862.       }
  863.     }
  864.  
  865.     /*************************************************************************/
  866.     /* - Set the wait time appropriately. (It does not look that clean to do */
  867.     /*   this here, anyway it works and should try to clean later).          */
  868.     /*************************************************************************/
  869.     if( EventPosition != SCROLLBAR_UPARROW &&
  870.         EventPosition != SCROLLBAR_DNARROW &&
  871.         MouseState    != STATE_CONTINUOUS_PRESS )
  872.       WaitTime = SEM_INDEFINITE_WAIT;
  873.  
  874.     /*************************************************************************/
  875.     /* If the dialog has the length of its hilite bar as 0, the dialog       */
  876.     /* contains text (help dialog), so map up arrow key and down arrow key   */
  877.     /* as scroll up and scroll down.                                         */
  878.     /*************************************************************************/
  879.     if( (normal[1] == 0) && (hilite[1] == 0) )
  880.     {
  881.       if( key == UP )
  882.         key = SCROLLUP;
  883.       else
  884.       if( key == DOWN )
  885.         key = SCROLLDOWN;
  886.     }
  887.  
  888.     switch( key )
  889.     {
  890.       case UP:
  891.       {
  892.         SelectIndex--;
  893.         if( SelectIndex < 1 )
  894.         {
  895.            /******************************************************************/
  896.            /* If we are going above the top reset the index and continue.    */
  897.            /******************************************************************/
  898.            SelectIndex = 1;
  899.            continue;
  900.         }
  901.         else
  902.         {
  903.           /*******************************************************************/
  904.           /* - Change the highlight row position.                            */
  905.           /* - If the highlight row position is going above the window, then */
  906.           /*   we need to scroll the display. Anchor to the top of the win.  */
  907.           /*******************************************************************/
  908.           NewHighFldNo = CurHighFldNo - 1;
  909.           if( NewHighFldNo < 1 )
  910.           {
  911.             NewHighFldNo++;
  912.             ptr->SkipRows--;
  913.             ptr->SkipRows = (ptr->SkipRows < 0) ? 0 : ptr->SkipRows;
  914.             (*(shell->Display))( shell, ptr );
  915.           }
  916.           shell->CurrentField = NewHighFldNo;
  917.           Dummy = *Event;
  918.           Dummy.Value = key;
  919.           (*(shell->DialogFunction))( shell, ptr, &Dummy, ParamBlock );
  920.         }
  921.         break;
  922.       }
  923.  
  924.       case SCROLLUP:
  925.       {
  926.         /*********************************************************************/
  927.         /* If there are no rows to scroll up continue.                       */
  928.         /*********************************************************************/
  929.         if( ptr->SkipRows == 0 )
  930.            continue;
  931.         /*********************************************************************/
  932.         /* Scroll the window.                                                */
  933.         /*********************************************************************/
  934.         ptr->SkipRows--;
  935.         (*(shell->Display))( shell, ptr );
  936.         /*********************************************************************/
  937.         /* - Calculate the HighLight row position. It should keep following  */
  938.         /*   the current selection. If it goes beyond the window ground it   */
  939.         /*   to the bottom of the window and adjust the SelectIndex.         */
  940.         /*********************************************************************/
  941.         NewHighFldNo = SelectIndex - ptr->SkipRows;
  942.         if( NewHighFldNo > ptr->MaxRows )
  943.         {
  944.           NewHighFldNo = ptr->MaxRows;
  945.           SelectIndex--;
  946.         }
  947.         else
  948.         {
  949.           shell->CurrentField = NewHighFldNo;
  950.           Dummy = *Event;
  951.           Dummy.Value = key;
  952.           (*(shell->DialogFunction))( shell, ptr, &Dummy, ParamBlock );
  953.         }
  954.         break;
  955.       }
  956.  
  957.       case SCROLLDOWN:
  958.       {
  959.         /*********************************************************************/
  960.         /* If there are no rows to scroll down continue.                     */
  961.         /*********************************************************************/
  962.         if( (ptr->SkipRows + ptr->MaxRows) >= ptr->entries )
  963.            continue;
  964.         /*********************************************************************/
  965.         /* Scroll the window.                                                */
  966.         /*********************************************************************/
  967.         ptr->SkipRows++;
  968.         ptr->SkipRows = min(ptr->SkipRows,(int)(ptr->entries-ptr->MaxRows));
  969.         ptr->SkipRows = (ptr->SkipRows < 0) ? 0 : ptr->SkipRows;
  970.         (*(shell->Display))( shell, ptr );
  971.         /*********************************************************************/
  972.         /* - Calculate the HighLight row position. It should keep following  */
  973.         /*   the current selection. If it goes above the window ground it    */
  974.         /*   to the top of the window and adjust the SelectIndex.            */
  975.         /*********************************************************************/
  976.         NewHighFldNo = SelectIndex - ptr->SkipRows;
  977.         if( NewHighFldNo < 1 )
  978.         {
  979.           NewHighFldNo = 1;
  980.           SelectIndex++;
  981.         }
  982.         else
  983.         {
  984.           shell->CurrentField = NewHighFldNo;
  985.           Dummy = *Event;
  986.           Dummy.Value = key;
  987.           (*(shell->DialogFunction))( shell, ptr, &Dummy, ParamBlock );
  988.         }
  989.         break;
  990.       }
  991.  
  992.       case PGUP:
  993.       {
  994.         /*********************************************************************/
  995.         /* If there are no rows to scroll up continue.                       */
  996.         /*********************************************************************/
  997.         if( ptr->SkipRows == 0 )
  998.            continue;
  999.         OldSkipRows = ptr->SkipRows;
  1000.         /*********************************************************************/
  1001.         /* - Scroll the window.                                              */
  1002.         /* - CalCulate the select index.                                     */
  1003.         /*********************************************************************/
  1004.         ptr->SkipRows -= ptr->MaxRows;
  1005.         ptr->SkipRows  = (ptr->SkipRows < 0) ? 0 : ptr->SkipRows;
  1006.         SelectIndex    = (SelectIndex - (OldSkipRows - ptr->SkipRows));
  1007.         (*(shell->Display))( shell, ptr );
  1008.         shell->CurrentField = NewHighFldNo;
  1009.         Dummy = *Event;
  1010.         Dummy.Value = key;
  1011.         (*(shell->DialogFunction))( shell, ptr, &Dummy, ParamBlock );
  1012.         break;
  1013.       }
  1014.  
  1015.       case DOWN:
  1016.       {
  1017.         SelectIndex++;
  1018.         if( SelectIndex > ptr->entries )
  1019.         {
  1020.           /******************************************************************/
  1021.           /* If we are going below the botom reset the index and conitnue.  */
  1022.           /******************************************************************/
  1023.           SelectIndex = ptr->entries;
  1024.           continue;
  1025.         }
  1026.         else
  1027.         {
  1028.           /*******************************************************************/
  1029.           /* - Change the highlight row position.                            */
  1030.           /* - If the highlight row position is going below the window, then */
  1031.           /*   we need to scroll the display. Anchor to the bottom of the    */
  1032.           /*   window.                                                       */
  1033.           /*******************************************************************/
  1034.           NewHighFldNo = CurHighFldNo + 1;
  1035.           if( (NewHighFldNo > ptr->MaxRows) || (NewHighFldNo > ptr->entries) )
  1036.           {
  1037.             SelectIndex = min(SelectIndex,ptr->entries);
  1038.             NewHighFldNo--;
  1039.             ptr->SkipRows++;
  1040.             ptr->SkipRows = min(ptr->SkipRows,(int)(ptr->entries-ptr->MaxRows));
  1041.             ptr->SkipRows = (ptr->SkipRows < 0) ? 0 : ptr->SkipRows;
  1042.             (*(shell->Display))( shell, ptr );
  1043.           }
  1044.           shell->CurrentField = NewHighFldNo;
  1045.           Dummy = *Event;
  1046.           Dummy.Value = key;
  1047.           (*(shell->DialogFunction))( shell, ptr, &Dummy, ParamBlock );
  1048.         }
  1049.         break;
  1050.       }
  1051.  
  1052.       case PGDN:
  1053.       {
  1054.         /*********************************************************************/
  1055.         /* If there are no rows to scroll down continue.                     */
  1056.         /*********************************************************************/
  1057.         if( (ptr->SkipRows + ptr->MaxRows) >= ptr->entries )
  1058.            continue;
  1059.         /*********************************************************************/
  1060.         /* - Scroll the window.                                              */
  1061.         /* - CalCulate the select index.                                     */
  1062.         /*********************************************************************/
  1063.         OldSkipRows = ptr->SkipRows;
  1064.         ptr->SkipRows += ptr->MaxRows;
  1065.         ptr->SkipRows = min(ptr->SkipRows,(int)(ptr->entries-ptr->MaxRows));
  1066.         ptr->SkipRows = (ptr->SkipRows < 0) ? 0 : ptr->SkipRows;
  1067.         SelectIndex =  (SelectIndex + (ptr->SkipRows - OldSkipRows));
  1068.         (*(shell->Display))( shell, ptr );
  1069.         shell->CurrentField = NewHighFldNo;
  1070.         Dummy = *Event;
  1071.         Dummy.Value = key;
  1072.         (*(shell->DialogFunction))( shell, ptr, &Dummy, ParamBlock );
  1073.         break;
  1074.       }
  1075.  
  1076.       case SCROLLBAR:
  1077.       {
  1078.         int RowsToSkip;
  1079.         int SkipRows;
  1080.         static ushort MarkedMouseRow;
  1081.         SkipRows = ptr->SkipRows;
  1082.  
  1083.         if( Event->Value != EVENT_BUTTON_1_DOWN_MOVE )
  1084.         {
  1085.           /*******************************************************************/
  1086.           /* If the click is on the slider itself continue. If yes take a    */
  1087.           /* snap shot of mouse row and go into drag mode.                   */
  1088.           /*******************************************************************/
  1089.           if( ((uint)Event->Row >= ptr->SliderStartRow) &&
  1090.               ((uint)Event->Row <= (ptr->SliderStartRow + ptr->SliderSize - 1)) )
  1091.           {
  1092.             MarkedMouseRow = Event->Row;
  1093.             InDragMode = TRUE;
  1094.             continue;
  1095.           }
  1096.  
  1097.           /*******************************************************************/
  1098.           /* If the mouse position is below slider its a page down.          */
  1099.           /*******************************************************************/
  1100.           if( (uint)Event->Row > (ptr->SliderStartRow + ptr->SliderSize - 1) )
  1101.             RowsToSkip = ptr->MaxRows;
  1102.  
  1103.           /*******************************************************************/
  1104.           /* If the mouse position is above slider its a page up.            */
  1105.           /*******************************************************************/
  1106.           if( (uint)Event->Row < ptr->SliderStartRow )
  1107.              RowsToSkip = -(int)ptr->MaxRows;
  1108.         }
  1109.         else
  1110.         {
  1111.           if( InDragMode == TRUE )
  1112.           {
  1113.             /****************************************************************/
  1114.             /* If we are in drag mode determine on which side we are moving */
  1115.             /* and depending on direction determine the position table ptr. */
  1116.             /* Handle the boundries of the position table.                  */
  1117.             /****************************************************************/
  1118.             if( Event->Row > MarkedMouseRow )
  1119.               PositionTbPtr++;
  1120.             if( Event->Row < MarkedMouseRow )
  1121.               PositionTbPtr--;
  1122.             if( Event->Row == MarkedMouseRow )
  1123.               continue;
  1124.  
  1125.             MarkedMouseRow = Event->Row;
  1126.             if( PositionTbPtr < 0 )
  1127.               PositionTbPtr = 0;
  1128.             if( PositionTbPtr > (NoOfSliderPos - 1) )
  1129.               PositionTbPtr = NoOfSliderPos - 1;
  1130.           }
  1131.           else
  1132.             continue;
  1133.           /*******************************************************************/
  1134.           /* get the number of rows to skip from the postion table.          */
  1135.           /*******************************************************************/
  1136.           RowsToSkip = PositionTable[PositionTbPtr] - 1;
  1137.           SkipRows = 0;
  1138.         }
  1139.         /*********************************************************************/
  1140.         /*    Calculate the new number of rows to be skipped. Adjust it with */
  1141.         /*  respect to the boundries.                                        */
  1142.         /*********************************************************************/
  1143.         if( RowsToSkip > 0 )
  1144.         {
  1145.           SkipRows += RowsToSkip;
  1146.           SkipRows = min(SkipRows,(int)(ptr->entries-ptr->MaxRows));
  1147.           SkipRows = (SkipRows < 0) ? 0 : SkipRows;
  1148.         }
  1149.         else
  1150.         {
  1151.           SkipRows -= (-RowsToSkip);
  1152.           SkipRows  = (SkipRows < 0) ? 0 : SkipRows;
  1153.         }
  1154.  
  1155.         /*********************************************************************/
  1156.         /* If New number of rows to skip is same as old one simply conintue. */
  1157.         /*********************************************************************/
  1158.         if( SkipRows == ptr->SkipRows )
  1159.            continue;
  1160.         else
  1161.         {
  1162.           /******************************************************************/
  1163.           /* - Calculate the Highlight row no.                              */
  1164.           /* - Put in the new skip rows value into the structure.           */
  1165.           /******************************************************************/
  1166.           NewHighFldNo = SelectIndex - SkipRows;
  1167.           ptr->SkipRows = SkipRows;
  1168.         }
  1169.  
  1170.         if( NewHighFldNo < 1 )
  1171.         {
  1172.           /******************************************************************/
  1173.           /*   If the highlight row is going above the window, reset it to  */
  1174.           /* top of window and adjust the select index.                     */
  1175.           /******************************************************************/
  1176.           NewHighFldNo = 1;
  1177.           SelectIndex = ptr->SkipRows + 1;
  1178.         }
  1179.  
  1180.         if( NewHighFldNo > ptr->MaxRows )
  1181.         {
  1182.           /******************************************************************/
  1183.           /*   If the highlight row is going below the window, reset it to  */
  1184.           /* bot of window and adjust the select index.                     */
  1185.           /******************************************************************/
  1186.           NewHighFldNo = ptr->MaxRows;
  1187.           SelectIndex = ptr->SkipRows + ptr->MaxRows;
  1188.         }
  1189.  
  1190.         /*********************************************************************/
  1191.         /* scroll the window.                                                */
  1192.         /*********************************************************************/
  1193.         (*(shell->Display))( shell, ptr );
  1194.         shell->CurrentField = NewHighFldNo;
  1195.         Dummy = *Event;
  1196.         Dummy.Value = key;
  1197.         (*(shell->DialogFunction))( shell, ptr, &Dummy, ParamBlock );
  1198.       }
  1199.       break;
  1200.  
  1201.       case MOUSEPICK:
  1202.       {
  1203.         uint  NewSelectIndex;
  1204.  
  1205.         NewSelectIndex = SelectIndex - (CurHighFldNo - NewHighFldNo);
  1206.  
  1207.         /*********************************************************************/
  1208.         /* If the new selected item is same as the old one and we are in     */
  1209.         /* attribute field simply continue.                                  */
  1210.         /*********************************************************************/
  1211.  
  1212.         if( NewSelectIndex <= ptr->entries )
  1213.           SelectIndex = NewSelectIndex;
  1214.         else
  1215.           NewHighFldNo = CurHighFldNo;
  1216.       }                                 /* Intentional fall-through          */
  1217.       goto casedefault;
  1218. casedefault:
  1219.  
  1220.       default:
  1221.       {
  1222.         uint retcode;
  1223.  
  1224.         Dummy = *Event;
  1225.         Dummy.Value = key;
  1226.         shell->CurrentField = NewHighFldNo;
  1227.  
  1228.         retcode = (*(shell->DialogFunction))( shell, ptr, &Dummy , ParamBlock );
  1229.         if( retcode )
  1230.           return( retcode );
  1231.         break;
  1232.       }
  1233.     }
  1234.  
  1235.     if( ScrollBar == TRUE )
  1236.     {
  1237.       for( i = 0; i < NoOfSliderPos; i++ )
  1238.       {
  1239.         if( i != (NoOfSliderPos - 1) )
  1240.         {
  1241.           if( ((ptr->SkipRows+1) >= (int)PositionTable[i]) &&
  1242.               ((ptr->SkipRows+1) < (int)PositionTable[i+1]) )
  1243.           {
  1244.              PositionTbPtr = i;
  1245.              ptr->NewSliderStartRow = shell->row+UPARROWROWOFFSET + 1 + i;
  1246.              break;
  1247.           }
  1248.         }
  1249.         else
  1250.         {
  1251.           if( (ptr->SkipRows+1) >= (int)PositionTable[i] )
  1252.           {
  1253.             PositionTbPtr = i;
  1254.             ptr->NewSliderStartRow = shell->row+UPARROWROWOFFSET + 1 + i;
  1255.             break;
  1256.           }
  1257.         }
  1258.       }
  1259.  
  1260.       if( ptr->NewSliderStartRow != ptr->SliderStartRow )
  1261.       {
  1262.         for( i = 0; i < ptr->SliderSize; i++ )
  1263.           putrc( ptr->SliderStartRow + i,
  1264.                  shell->col + shell->width - SCROLLBARCOLOFFSET,
  1265.                  ScrollShade1 );
  1266.         ptr->SliderStartRow = ptr->NewSliderStartRow;
  1267.         for( i = 0; i < ptr->SliderSize; i++ )
  1268.           putrc( ptr->SliderStartRow + i,
  1269.                  shell->col + shell->width - SCROLLBARCOLOFFSET,
  1270.                  ScrollShade2 );
  1271.       }
  1272.     }
  1273.  
  1274.     if( CurHighFldNo != NewHighFldNo )
  1275.     {
  1276.       putrc( shell->row + shell->SkipLines + CurHighFldNo - 1, shell->col + 1,
  1277.              normal );
  1278.       CurHighFldNo = NewHighFldNo;
  1279.     }
  1280.     putrc( shell->row + shell->SkipLines + CurHighFldNo - 1, shell->col + 1,
  1281.            hilite );
  1282.   }
  1283. }
  1284.  
  1285. /*****************************************************************************/
  1286. /* ProcessYesNoBox()                                                         */
  1287. /*                                                                           */
  1288. /* Description:                                                              */
  1289. /*                                                                           */
  1290. /*  Handle a simple box with a yes/no response.                              */
  1291. /*                                                                           */
  1292. /*                                                                           */
  1293. /* Parameters:                                                               */
  1294. /*                                                                           */
  1295. /*   shell         Pointer to DIALOGSHELL structure.                         */
  1296. /*   ptr           Pointer to DIALOGCHOICE structure.                        */
  1297. /*                                                                           */
  1298. /* Assumptions:                                                              */
  1299. /*                                                                           */
  1300. /* Return:                                                                   */
  1301. /*                                                                           */
  1302. /*   key                                                                     */
  1303. /*                                                                           */
  1304. /*****************************************************************************/
  1305. UINT  ProcessYesNoBox( DIALOGSHELL *shell, DIALOGCHOICE *ptr )
  1306. {
  1307.  UINT   key;
  1308.  UINT   ButtonKey;
  1309.  UINT   WaitTime;
  1310.  UINT   EventPosition;
  1311.  
  1312.  /****************************************************************************/
  1313.  /* - set default video attribute.                                           */
  1314.  /****************************************************************************/
  1315.  VideoAtr = vaMenuBar;
  1316.  
  1317.  /****************************************************************************/
  1318.  /* - Call display function to display elements in the display area.         */
  1319.  /****************************************************************************/
  1320.  (*(shell->Display))( shell, ptr );
  1321.  
  1322.  WaitTime = SEM_INDEFINITE_WAIT;
  1323.  
  1324.  for( ;; )
  1325.  {
  1326.   /**************************************************************************/
  1327.   /* - Get an event.                                                        */
  1328.   /**************************************************************************/
  1329.   Event = GetEvent( WaitTime );
  1330.  
  1331.   /**************************************************************************/
  1332.   /* Switch based on the type of the event.                                 */
  1333.   /**************************************************************************/
  1334.   switch( Event->Type )
  1335.   {
  1336.    case TYPE_MOUSE_EVENT:
  1337.    {
  1338.     EventPosition = GetEventPositionInDialog( shell, ptr, &key, FALSE );
  1339.     switch( Event->Value )
  1340.     {
  1341.      /************************************************************************/
  1342.      /* If the event is a left button down event.                            */
  1343.      /************************************************************************/
  1344.      case EVENT_BUTTON_1_DOWN:
  1345.      {
  1346.       /***********************************************************************/
  1347.       /* - Set the state of the button to Button Pressed.                    */
  1348.       /*   (The state will be over written at some places).                  */
  1349.       /***********************************************************************/
  1350.       MouseState = STATE_BUTTON_PRESSED;
  1351.  
  1352.       /***********************************************************************/
  1353.       /* If the button down event was on any of the dialog buttons           */
  1354.       /* save the "button key" so that we can check when the user            */
  1355.       /* lets up on the button.                                              */
  1356.       /***********************************************************************/
  1357.       if( EventPosition == BUTTONS )
  1358.        ButtonKey = key;
  1359.       continue;
  1360.      }
  1361.    /*break;*/
  1362.  
  1363.      case EVENT_BUTTON_1_DOWN_MOVE:
  1364.      {
  1365.       MouseState = STATE_BUTTON_MOVE;
  1366.       WaitTime   = SEM_INDEFINITE_WAIT;
  1367.       continue;
  1368.      }
  1369.    /*break;*/
  1370.  
  1371.      case EVENT_NO_BUTTONS_DOWN:
  1372.      case EVENT_NO_BUTTONS_DOWN_MOVE:
  1373.      {
  1374.       /***********************************************************************/
  1375.       /* If the user has let up on the mouse button on a dialog button       */
  1376.       /* check if he has already clicked on that button. If they match       */
  1377.       /* break for further processing down below. If not continue.           */
  1378.       /***********************************************************************/
  1379.       if( EventPosition == BUTTONS )
  1380.       {
  1381.        if( ButtonKey == key )
  1382.          break;
  1383.       }
  1384.  
  1385.       ButtonKey  = 0;
  1386.       MouseState = STATE_BUTTON_RELEASED;
  1387.       WaitTime   = SEM_INDEFINITE_WAIT;
  1388.       continue;
  1389.      }
  1390.   /* break;*/
  1391.  
  1392.      default:
  1393.      {
  1394.       /***********************************************************************/
  1395.       /* Ideally, should not enter this code.                                */
  1396.       /***********************************************************************/
  1397.       WaitTime = SEM_INDEFINITE_WAIT;
  1398.       continue;
  1399.      }
  1400.   /* break; */
  1401.     }
  1402.    }
  1403.    break;
  1404.  
  1405.    case TYPE_KBD_EVENT:
  1406.    {
  1407.     /*************************************************************************/
  1408.     /* If it is keyboard event, set the key value and break for further      */
  1409.     /* processing below.                                                     */
  1410.     /*************************************************************************/
  1411.     key = Event->Value;
  1412.     break;
  1413.    }
  1414.   }
  1415.  
  1416.   switch( key )
  1417.   {
  1418.    case key_y:
  1419.    case key_Y:
  1420.    case key_n:
  1421.    case key_N:
  1422.    case ENTER:
  1423.    case ESC:
  1424.     return(key);
  1425.  
  1426.    default:
  1427.     break;
  1428.   }
  1429.  }
  1430. }
  1431.