home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MODEM / UWPC201.ZIP / UW-SRC.ZIP / DIALOG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-03  |  8.7 KB  |  295 lines

  1. //-------------------------------------------------------------------------
  2. //
  3. // DIALOG.CPP - Declarations for creating dialog boxes.
  4. // 
  5. //  This file is part of UW/PC - a multi-window comms package for the PC.
  6. //  Copyright (C) 1990-1991  Rhys Weatherley
  7. //
  8. //  This program is free software; you can redistribute it and/or modify
  9. //  it under the terms of the GNU General Public License as published by
  10. //  the Free Software Foundation; either version 1, or (at your option)
  11. //  any later version.
  12. //
  13. //  This program is distributed in the hope that it will be useful,
  14. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. //  GNU General Public License for more details.
  17. //
  18. //  You should have received a copy of the GNU General Public License
  19. //  along with this program; if not, write to the Free Software
  20. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. //
  22. // Revision History:
  23. // ================
  24. //
  25. //  Version  DD/MM/YY  By  Description
  26. //  -------  --------  --  --------------------------------------
  27. //    1.0    14/04/91  RW  Original Version of DIALOG.CPP
  28. //
  29. // You may contact the author by:
  30. // =============================
  31. //
  32. //  e-mail: rhys@cs.uq.oz.au
  33. //    mail: Rhys Weatherley
  34. //          5 Horizon Drive
  35. //          Jamboree Heights
  36. //          Queensland 4074
  37. //        Australia
  38. //
  39. //-------------------------------------------------------------------------
  40.  
  41. #include "dialog.h"        // Declarations for this module.
  42. #include "client.h"        // Client processing routines.
  43. #include "screen.h"        // Screen processing routines.
  44. #include "uw.h"            // UW Protocol accessing routines.
  45. #include "display.h"        // Display handling routines.
  46. #include "keys.h"        // Keypress declarations.
  47. #include "config.h"        // Configuration routines.
  48. #include <string.h>        // String handling routines.
  49.  
  50. #pragma    warn    -par
  51.  
  52. #define    ATTR(x)        (HardwareScreen.attributes[(x)])
  53. #define    DRAW(x,y,pair)    HardwareScreen.draw (x,y,pair,1)
  54. #define    LINES        (HardwareScreen.height - 1)
  55. #define    COLS        (HardwareScreen.width)
  56.  
  57. #define    BOX_TL        213
  58. #define    BOX_TR        184
  59. #define    BOX_HORZ    205
  60. #define    BOX_BL        212
  61. #define    BOX_BR        190
  62. #define    BOX_VERT    179
  63.  
  64. UWDialogBox::UWDialogBox (UWDisplay *wind,int x1,int y1,int x2,int y2) :
  65.     UWClient (wind)
  66. {
  67.   int temp;
  68.   unsigned attr;
  69.   UWMaster.install (this);        // Install a new client.
  70.   dx1 = x1;
  71.   dy1 = y1;
  72.   dx2 = x2;
  73.   dy2 = y2;
  74.   HardwareScreen.shape ((CursorShapes)UWConfig.CursorSize);
  75.   HardwareScreen.mark (x1,y1,x2,y2);
  76.   HardwareScreen.scroll (x1,y1,x2,y2,0,ATTR(ATTR_NORMAL));
  77.   attr = ATTR(ATTR_HIGHLIGHT) << 8;    // Draw a box around dialog area.
  78.   DRAW (x1,y1,BOX_TL | attr);
  79.   DRAW (x2,y1,BOX_TR | attr);
  80.   DRAW (x1,y2,BOX_BL | attr);
  81.   DRAW (x2,y2,BOX_BR | attr);
  82.   for (temp = x1 + 1;temp < x2;++temp)
  83.     {
  84.       DRAW (temp,y1,BOX_HORZ | attr);
  85.       DRAW (temp,y2,BOX_HORZ | attr);
  86.     }
  87.   for (temp = y1 + 1;temp < y2;++temp)
  88.     {
  89.       DRAW (x1,temp,BOX_VERT | attr);
  90.       DRAW (x2,temp,BOX_VERT | attr);
  91.     }
  92.   cleared = 0;
  93. } // UWDialogBox::UWDialogBox //
  94.  
  95. UWDialogBox::~UWDialogBox (void)
  96. {
  97.   if (!cleared)
  98.     HardwareScreen.clearmark ();
  99. } // UWDialogBox::~UWDialogBox //
  100.  
  101. // Terminate this dialog box and return to the previously
  102. // active client in this window.
  103. void    UWDialogBox::terminate (void)
  104. {
  105.   HardwareScreen.clearmark ();
  106.   cleared = 1;
  107.   window -> top (1);        // Restore top-most window (this one).
  108.   UWMaster.remove ();        // Remove this client from client stack.
  109. } // UWDialogBox::terminate //
  110.  
  111. // Show a string on the screen in the dialog box.
  112. void    UWDialogBox::showstring (int x,int y,char *str)
  113. {
  114.   unsigned attr;
  115.   attr = ATTR(ATTR_NORMAL) << 8;
  116.   while (*str)
  117.     HardwareScreen.draw (x++,y,((*str++) & 255) | attr,1);
  118. } // UWDialogBox::showstring //
  119.  
  120. void    UWDialogBox::key (int keypress)
  121. {
  122.   terminate ();            // Dummy for now.
  123. } // UWDialogBox::key //
  124.  
  125. //
  126. // Declare the text of the help box.
  127. //
  128. static    char *HelpBox[] =
  129.      {"ALT-B - Send a BREAK pulse",
  130.       "ALT-C - Cut to clipboard",
  131.       "ALT-D - Send the dialing string",
  132.       "ALT-E - Exit a UW session",
  133. #ifdef    DOOBERY
  134.       "ALT-F - Send \"uwftp^M\" to host",
  135. #endif
  136.       "ALT-H - Hangup the modem",
  137.       "ALT-I - Send modem init string",
  138.       "ALT-J - Jump to DOS",
  139.       "ALT-K - Kill current window",
  140.       "ALT-L - Capture ON/OFF",
  141. #ifdef    DOOBERY
  142.       "ALT-M - Send \"uwmail^M\" to host",
  143. #endif
  144.       "ALT-N - Create a new window",
  145.       "ALT-P - Paste from clipboard",
  146.       "ALT-Q - Quit the program",
  147.       "ALT-R - Download (receive) a file",
  148.       "ALT-S - Upload (send) a file",
  149.       "ALT-T - Send \"stty\" string",
  150.       "ALT-U - Send \"uw^M\" to host",
  151.       "ALT-W - Cycle to the next window",
  152.       "ALT-X - Exit the program",
  153.       "ALT-Z - This help information",
  154.       "ALT-n - Go to window \"n\" (1-7)",
  155.       " [Press any key to continue]"
  156.      };
  157. #define    HELP_WIDTH    33
  158. #define    HELP_HEIGHT    21
  159.  
  160. UWHelpBox::UWHelpBox (UWDisplay *wind) :
  161.     UWDialogBox (wind,(COLS - HELP_WIDTH - 4) / 2,
  162.               (LINES - HELP_HEIGHT - 2) / 2,
  163.               ((COLS - HELP_WIDTH - 4) / 2) + HELP_WIDTH + 3,
  164.               ((LINES - HELP_HEIGHT - 2) / 2) + HELP_HEIGHT + 1)
  165. {
  166.   int line;
  167.   for (line = 0;line < HELP_HEIGHT;++line)
  168.     showstring (dx1 + 2,dy1 + 1 + line,HelpBox[line]);
  169. }
  170.  
  171. // Create a query dialog box.  If "answers" is NULL,
  172. // then the default answer string "yYnN\033" is used.
  173. UWQueryBox::UWQueryBox (UWDisplay *wind,char *query,int qlen,char *answers) :
  174.     UWDialogBox (wind,(COLS - qlen - 4) / 2,
  175.               LINES / 2 - 2,
  176.               (COLS - qlen - 4) / 2 + qlen + 3,
  177.               LINES / 2 + 2)
  178. {
  179.   showstring (dx1 + 2,dy1 + 2,query);
  180.   if (!answers)
  181.     answers = "yYnN\033";
  182.   anschars = answers;
  183. } // UWQueryBox::UWQueryBox //
  184.  
  185. void    UWQueryBox::key    (int keypress)
  186. {
  187.   int index=0;
  188.   while (anschars[index] && anschars[index] != keypress)
  189.     ++index;
  190.   if (anschars[index])
  191.     process (index);        // Process the received key.
  192. } // UWQueryBox::key //
  193.  
  194. // Process the character provided by the user if it
  195. // is in the answer string.  The string index is provided.
  196. void    UWQueryBox::process (int index)
  197. {
  198.   terminate ();            // Just terminate box in this class.
  199. } // UWQueryBox::process //
  200.  
  201. // Create a editing dialog box to get a string //
  202. UWEditBox::UWEditBox (UWDisplay *wind,char *prompt,int editsize) :
  203.     UWDialogBox (wind,(COLS - (editsize + 2) - 4) / 2,
  204.               LINES / 2 - 3,
  205.               (COLS - (editsize + 2) - 4) / 2 + editsize + 5,
  206.               LINES / 2 + 2)
  207. {
  208.   showstring (dx1 + 2,dy1 + 2,prompt);
  209.   showstring (dx1 + 2,dy1 + 3,"\020");
  210.   size = editsize;
  211.   posn = 0;
  212.   HardwareScreen.cursor (dx1 + 4 + posn,dy1 + 3);
  213.   HardwareScreen.shape ((CursorShapes)UWConfig.CursorSize);
  214.   buffer[0] = '\0';
  215.   length = 0;
  216. } // UWEditBox::UWEditBox //
  217.  
  218. void    UWEditBox::key (int keypress)
  219. {
  220.   int temp,ch,save;
  221.   switch (keypress)
  222.     {
  223.       case 033:    // Fall through to CR handling code //
  224.       case '\r':process (keypress == 033);
  225.         break;
  226.       case 8:    if (posn <= 0)
  227.                 break;
  228.         --posn;
  229.         // Fall through to character delete code //
  230.       case CURSOR_DEL:
  231.               if (!buffer[posn])    // Abort if at end of string.
  232.           break;
  233.               temp = posn;
  234.               while (temp < (length - 1))
  235.           {
  236.             buffer[temp] = buffer[temp + 1];
  237.             ++temp;
  238.           }
  239.         buffer[temp] = '\0';
  240.         --length;
  241.         showstring (dx1 + 4 + posn,dy1 + 3,buffer + posn);
  242.         showstring (dx1 + 4 + length,dy1 + 3," ");
  243.         break;
  244.       case CURSOR_LEFT:
  245.               if (posn > 0)
  246.           --posn;
  247.         break;
  248.       case CURSOR_RIGHT:
  249.               if (buffer[posn])
  250.           ++posn;
  251.         break;
  252.       case CURSOR_HOME:
  253.               posn = 0;
  254.         break;
  255.       case CURSOR_END:
  256.               posn = length;
  257.         break;
  258.       case 030:    for (temp = 0;temp < length;++temp)
  259.                 showstring (dx1 + 4 + temp,dy1 + 3," ");
  260.         length = 0;
  261.         posn = 0;
  262.         buffer[0] = '\0';
  263.         break;
  264.       default:    if (keypress >= ' ' && keypress <= 255)
  265.                 {
  266.             if (length >= size)
  267.               break;        // String is at the maximum size.
  268.             ch = keypress;
  269.             temp = posn;
  270.             while (buffer[temp])
  271.               {
  272.                 // Swap characters until at the end of the line //
  273.                 save = buffer[temp];
  274.             buffer[temp++] = ch;
  275.             ch = save;
  276.               }
  277.             buffer[temp] = ch;
  278.             buffer[temp + 1] = '\0';
  279.             showstring (dx1 + 4 + posn,dy1 + 3,buffer + posn);
  280.             ++length;
  281.             ++posn;
  282.           }
  283.         break;
  284.     }
  285.   if (!cleared)        // Reset the cursor position if necessary.
  286.     HardwareScreen.cursor (dx1 + 4 + posn,dy1 + 3);
  287. } // UWEditBox::key //
  288.  
  289. // Process a fully entered line.  If 'esc' is non-zero
  290. // then the ESC key was pressed to abort the editing.
  291. void    UWEditBox::process (int esc)
  292. {
  293.   terminate ();        // Just terminate the box in this class.
  294. } // UWEditBox::process //
  295.