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

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   popup.c                                                                 */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*   Common Cua routines to handle popups.                                   */
  8. /*                                                                           */
  9. /*...Release 1.01 (07/20/92)                                                 */
  10. /*...                                                                        */
  11. /*... 07/20/92  701   Joe       Cua Interface.                               */
  12. /*... 12/10/93  910   Joe       Clear fields on cursor sensitive prompting.  */
  13. /*****************************************************************************/
  14. #include "all.h"
  15. #include "popups.h"
  16.  
  17. extern uchar    hiatt[];                /* attributes string for highlight.  */
  18. extern uchar    VideoAtr;               /* default logical video attribute.  */
  19. extern uchar    ScrollShade1[];         /* attribute string for scroll bar.  */
  20. extern uchar    ScrollShade2[];         /* attribute string for scroll bar.  */
  21. extern uchar    ClearField[];           /* attrib str for clearing fields.   */
  22. extern uchar    hilite[];               /* attrib str to highlight fields.   */
  23. extern uchar    badhilite[];            /* attrib str to highlight bad fields*/
  24. extern uchar    normal[];               /* attrib str to disp normal fields. */
  25. extern uchar    badnormal[];            /* attrib str to disp bad fields.    */
  26. extern uchar    Shadow[];               /* attrib str for shadowing around   */
  27. extern uchar    InScrollMode;           /* flag to tell we are in scrollmode */
  28. extern KEY2FUNC defk2f[];               /* keys to functions map.            */
  29.  
  30.  
  31. static BUTTON PopButton[] =
  32. {
  33.  {
  34.   POP_BTN_ROW         ,
  35.   POP_BTN_ENTER_COL   ,
  36.   POP_BTN_ENTER_WIDTH ,
  37.   POP_BTN_ENTER_TEXT  ,
  38.   POP_BTN_ENTER_KEY
  39.  },
  40.  {
  41.   POP_BTN_ROW         ,
  42.   POP_BTN_CANCEL_COL  ,
  43.   POP_BTN_CANCEL_WIDTH,
  44.   POP_BTN_CANCEL_TEXT ,
  45.   POP_BTN_CANCEL_KEY
  46.  },
  47.  {
  48.   POP_BTN_ROW         ,
  49.   POP_BTN_HELP_COL    ,
  50.   POP_BTN_HELP_WIDTH  ,
  51.   POP_BTN_HELP_TEXT   ,
  52.   POP_BTN_HELP_KEY
  53.  }
  54. };
  55.  
  56. static POPUPSHELL Popup = {
  57.                            POP_START_ROW   ,
  58.                            POP_START_COL   ,
  59.                            POP_LEN         ,
  60.                            POP_WIDTH       ,
  61.                            POP_BUTTONS     ,
  62.                            NULL            ,
  63.                            NULL            ,
  64.                            0               ,
  65.                            &PopButton[0]
  66.                           };
  67.  
  68. /*****************************************************************************/
  69. /* Strings used to display a pulldown.                                       */
  70. /*****************************************************************************/
  71. static UCHAR barstr[]    =  {V_BAR,0};
  72.  
  73. /*****************************************************************************/
  74. /* Strings used to display a pop up.                                         */
  75. /*****************************************************************************/
  76. static UCHAR toppop[]  =  {TL_CORNER,RepCnt(1),H_BAR,TR_CORNER,0};
  77. static UCHAR botpop[]  =  {BL_CORNER,RepCnt(1),H_BAR,BR_CORNER,0};
  78. static UCHAR poptll[]  =  {L_JUNCTION,RepCnt(1),H_BAR,0};
  79. static UCHAR poptlr[]  =  {RepCnt(1),H_BAR,R_JUNCTION,0};
  80.  
  81. /*****************************************************************************/
  82. /*  DisplayPop()                                                             */
  83. /*                                                                           */
  84. /* Description:                                                              */
  85. /*                                                                           */
  86. /*     Displays a pop up window with title and buttons.                      */
  87. /*                                                                           */
  88. /* Parameters:                                                               */
  89. /*                                                                           */
  90. /*   POPUPSHELL *ptr   ->  to a popup shell structure.                       */
  91. /*                                                                           */
  92. /* Return:                                                                   */
  93. /*   None                                                                    */
  94. /*****************************************************************************/
  95. void DisplayPop(POPUPSHELL *ptr )
  96. {                                       /*                                   */
  97.   int    i;                             /* counter                           */
  98.   int    tlen;                          /* title length                      */
  99.   BUTTON *ButtonPtr;                    /* -> to button struture.            */
  100.  
  101.   /***************************************************************************/
  102.   /* Get the Screen Access to write.                                         */
  103.   /***************************************************************************/
  104.   GetScrAccess();
  105.  
  106.   /***************************************************************************/
  107.   /* - set the default video attribute.                                      */
  108.   /* - initialize color attribute for the clear cell.                        */
  109.   /***************************************************************************/
  110.   VideoAtr      = vaMenuBar;
  111.   ClearField[1] = (uchar)ptr->width;
  112.  
  113.   /***************************************************************************/
  114.   /* clear the screen area covered by the popup.                             */
  115.   /***************************************************************************/
  116.   for (i=0;i<ptr->length;i++)
  117.     putrc(ptr->row+i,ptr->col,ClearField);
  118.  
  119.   /***************************************************************************/
  120.   /* Put the length into topline string and then display the top line.       */
  121.   /***************************************************************************/
  122.   toppop[2] = (uchar)(ptr->width - 2);
  123.   putrc(ptr->row,ptr->col,toppop);
  124.  
  125.   /***************************************************************************/
  126.   /* display the title line in reverse video.                                */
  127.   /***************************************************************************/
  128.   tlen = strlen(ptr->title);
  129.   poptll[2] = (char) ((ptr->width - tlen - 2) >> 1);
  130.   poptlr[1] = (char) (ptr->width - tlen - poptll[2] - 2);
  131.   putrc(ptr->row+1,ptr->col,poptll);
  132.   VideoAtr = vaMenuCsr;
  133.   putrc(ptr->row+1,ptr->col + poptll[2] + 1,ptr->title);
  134.   VideoAtr = vaMenuBar;
  135.   putrc(ptr->row+1,ptr->col + poptll[2] + tlen + 1,poptlr);
  136.  
  137.   /***************************************************************************/
  138.   /* draw the sides of pop up window.                                        */
  139.   /***************************************************************************/
  140.   for(i = 2 ; i < (ptr->length - 1) ; i++)
  141.   {
  142.     putrc(ptr->row+i,ptr->col,barstr);
  143.     putrc(ptr->row+i,ptr->col+ptr->width-1,barstr);
  144.   }
  145.  
  146.   /***************************************************************************/
  147.   /* put the instructions into the popup.                                    */
  148.   /***************************************************************************/
  149.   if (ptr->instructions)
  150.     putrc(ptr->row + 3,
  151.           ptr->col + ((ptr->width - strlen(ptr->instructions)) >> 1),
  152.           ptr->instructions);
  153.  
  154.   /***************************************************************************/
  155.   /* Put length into botline string and then display the bottom line.        */
  156.   /***************************************************************************/
  157.   botpop[2] = (char) (ptr->width - 2);
  158.   putrc(ptr->row+ptr->length - 1,ptr->col,botpop);
  159.  
  160.   /***************************************************************************/
  161.   /* draw the buttons on the pop up.                                         */
  162.   /***************************************************************************/
  163.   ButtonPtr = ptr->Buttons;
  164.   for (i = 0 ; i < ptr->NoOfButtons ; i++)
  165.   {
  166.     putrc(ButtonPtr->row,ButtonPtr->col-1,"<");
  167.     putrc(ButtonPtr->row,ButtonPtr->col,ButtonPtr->Name);
  168.     putrc(ButtonPtr->row,ButtonPtr->col+ButtonPtr->length,">");
  169.     ButtonPtr++;
  170.   }
  171.  
  172.   /***************************************************************************/
  173.   /* Reset the video attributes to that of window and show the mouse         */
  174.   /***************************************************************************/
  175.   VideoAtr = vaMenuBar;
  176.   /***************************************************************************/
  177.   /* Restore Screen Access to write.                                         */
  178.   /***************************************************************************/
  179.   SetScrAccess();
  180. }
  181.  
  182. /*****************************************************************************/
  183. /*  GetPopStr()                                                              */
  184. /*                                                                           */
  185. /* Description:                                                              */
  186. /*                                                                           */
  187. /*   Gets a user input string from a pop up window and returns either an     */
  188. /* ENTER or an ESCAPE key                                                    */
  189. /*                                                                           */
  190. /* Parameters:                                                               */
  191. /*                                                                           */
  192. /*   POPUPSHELL  *shell     -> to a popup shell structure.                   */
  193. /*   uint         row       row for user input                               */
  194. /*   uint         col       column to start on                               */
  195. /*   uint         length    length of input field                            */
  196. /*   uchar       *str       -> to entered string                             */
  197. /*                                                                           */
  198. /* Return:                                                                   */
  199. /*   The key code by which we are exiting.                                   */
  200. /*****************************************************************************/
  201. uint GetPopStr(POPUPSHELL *shell,uint row,uint col,
  202.                uint length,uchar *str)
  203. {
  204.   uint cursor;                          /* cursor location in input field    */
  205.   uint key;                             /* key pressed to end input          */
  206.   uint help;                            /* help index.                       */
  207.  
  208.   /***************************************************************************/
  209.   /*  - put brackets around the input field.                                 */
  210.   /*  - put the initial string in the input field.                           */
  211.   /***************************************************************************/
  212.   putrc(row,col,"[");
  213.   putrc(row,col + length - 1,"]");
  214.  
  215.   for(;;)
  216.   {
  217.     cursor = strlen( str );
  218.     /*************************************************************************/
  219.     /* get the string from the user.                                         */
  220.     /*************************************************************************/
  221.     key = GetString(row,col+1,PROMAX,length-2,&cursor,str,0,shell);     /*910*/
  222.  
  223.     switch( key )
  224.     {
  225.       /** Enter and Escape return the pressed key to caller **/
  226.       case ENTER:
  227.       case PADENTER:
  228.       case ESC:
  229.       /***********************************************************************/
  230.       /* On a Enter and Escape key return the key and leading blank stripped */
  231.       /* string.                                                             */
  232.       /***********************************************************************/
  233.         stripblk(str);
  234.         return(key);
  235.  
  236.       case F1:
  237.       /***********************************************************************/
  238.       /* process the help key and then get input again.                      */
  239.       /***********************************************************************/
  240.       {
  241.         uchar  *HelpMsg;
  242.  
  243.         help = shell->help;
  244.         HelpMsg = GetHelpMsg( help, NULL,0 );
  245.         CuaShowHelpBox( HelpMsg );
  246.         break;
  247.       }
  248.  
  249.       default:
  250.       /***********************************************************************/
  251.       /* unknown keys, beep and then try again.                              */
  252.       /***********************************************************************/
  253.         beep();
  254.         break;
  255.     }
  256.   }
  257. }
  258.  
  259. /*****************************************************************************/
  260. /*  StripBlk()                                                               */
  261. /*                                                                           */
  262. /* Description:                                                              */
  263. /*                                                                           */
  264. /*   Removes leading blanks from a string                                    */
  265. /*                                                                           */
  266. /* Parameters:                                                               */
  267. /*                                                                           */
  268. /*   uchar       *str       -> to string to be striped of leading blanks     */
  269. /*                                                                           */
  270. /* Return:                                                                   */
  271. /*   None                                                                    */
  272. /*****************************************************************************/
  273. void stripblk (uchar *str)
  274. {                                       /*                                   */
  275.   uint   i;                             /* counter                           */
  276.   uint   len;                           /* string length                     */
  277.   uchar *ptr;                           /* work pointer                      */
  278.  
  279.   /***************************************************************************/
  280.   /* If 1st char is not a blank, there are no leading blanks so return.      */
  281.   /***************************************************************************/
  282.   if (*str != ' ')
  283.     return;
  284.  
  285.   /***************************************************************************/
  286.   /* get pointer to the 1st non blank character.                             */
  287.   /***************************************************************************/
  288.   ptr = str;
  289.   while (*ptr == ' ')
  290.     ptr++;
  291.   len = strlen(ptr) + 1;
  292.  
  293.   /***************************************************************************/
  294.   /* copy the string back into the same string from starting.                */
  295.   /***************************************************************************/
  296.   for (i=0;i<len;i++)
  297.     *(str+i) = *ptr++;
  298. }
  299.  
  300.  
  301. /*****************************************************************************/
  302. /* GetButtonPtr()                                                         910*/
  303. /*                                                                           */
  304. /* Description:                                                              */
  305. /*                                                                           */
  306. /*   Get a ptr to the button structure for the given popup and mouse         */
  307. /*   event.                                                                  */
  308. /*                                                                           */
  309. /* Parameters:                                                               */
  310. /*                                                                           */
  311. /*   shell       -> to a popup shell structure.                              */
  312. /*   Event       mouse event.                                                */
  313. /*                                                                           */
  314. /* Return:                                                                   */
  315. /*                                                                           */
  316. /*   ButtonPtr   -> to a button structure.                                   */
  317. /*   NULL           if the mouse event did not occur in the <>s.             */
  318. /*                                                                           */
  319. /*****************************************************************************/
  320. BUTTON *GetButtonPtr(POPUPSHELL *shell, PEVENT Event)
  321. {
  322.   BUTTON *ButtonPtr;
  323.   int     i;
  324.  
  325.   /***************************************************************************/
  326.   /* Is click on the buttons row of the popup window.                        */
  327.   /***************************************************************************/
  328.   ButtonPtr = shell->Buttons;
  329.   for (i = 0 ; i < shell->NoOfButtons ; i++)
  330.   {
  331.     /*************************************************************************/
  332.     /* check if the click is in the button if yes return true and stuff      */
  333.     /* in the key associated with that button.                               */
  334.     /*************************************************************************/
  335.     if ( (Event->Row == ButtonPtr->row) &&
  336.          (Event->Col >= ButtonPtr->col-1) &&
  337.          (Event->Col <= ButtonPtr->col+ButtonPtr->length))
  338.        return(ButtonPtr);
  339.     ButtonPtr++;
  340.   }
  341.   return(NULL);
  342. }
  343.  
  344. /*****************************************************************************/
  345. /* GetPopArea()                                                              */
  346. /*                                                                           */
  347. /* Description:                                                              */
  348. /*                                                                           */
  349. /*   Get the piece of the screen that the popup will overlay.                */
  350. /*                                                                           */
  351. /* Parameters:                                                               */
  352. /*                                                                           */
  353. /*   SaveArea   -> to buffer to put the stuff in.                            */
  354. /*                                                                           */
  355. /* Return                                                                    */
  356. /*                                                                           */
  357. /*   none                                                                    */
  358. /*                                                                           */
  359. /*****************************************************************************/
  360. void GetPopArea( char *SaveArea )
  361. {
  362.  windowsv(Popup.col,Popup.row,Popup.length,Popup.width,SaveArea);
  363. }
  364.  
  365. /*****************************************************************************/
  366. /* PutPopArea()                                                              */
  367. /*                                                                           */
  368. /* Description:                                                              */
  369. /*                                                                           */
  370. /*   Restore the piece of the screen grabbed previously.                     */
  371. /*                                                                           */
  372. /* Parameters:                                                               */
  373. /*                                                                           */
  374. /*   SaveArea   -> to buffer to put the stuff in.                            */
  375. /*                                                                           */
  376. /* Return                                                                    */
  377. /*                                                                           */
  378. /*   none                                                                    */
  379. /*                                                                           */
  380. /*****************************************************************************/
  381. void PutPopArea( char *SaveArea )
  382. {
  383.  windowrst(Popup.col,Popup.row,Popup.length,Popup.width,SaveArea);
  384. }
  385.