home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MODEM / UWPC201.ZIP / UW-SRC.ZIP / CLIPBD.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-31  |  7.0 KB  |  232 lines

  1. //-------------------------------------------------------------------------
  2. //
  3. // CLIPBD.CPP - Clipboard processing routines for UW/PC.
  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    08/06/91  RW  Original Version of CLIPBD.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 "clipbd.h"        // Declarations for this module.
  42. #include "client.h"        // Client processing declarations.
  43. #include "display.h"        // Display processing routines.
  44. #include "keys.h"        // Keyboard declarations.
  45. #include "uw.h"            // Master protocol routines.
  46. #include "mouse.h"        // Mouse handling routines.
  47. #include <dos.h>        // "delay" is defined here.
  48.  
  49. //
  50. // Define the global data for the clipboard.
  51. //
  52. #define    CLIPBOARD_SIZE    (81 * 24)
  53. static    char    Clipboard[CLIPBOARD_SIZE];
  54. static    int    ClipLength=0;    // Length of the clipboard.
  55. static    int    ClipActive=0;    // Non-zero for an active clipboard.
  56. static    int    ClipPosn;    // Current paste position.
  57.  
  58. UWCutToClipboard::UWCutToClipboard (UWDisplay *wind,int mouse,int x,int y) :
  59.     UWClient (wind)
  60. {
  61.   UWMaster.install (this);    // Install this client in the client stack.
  62.   usemouse = mouse;        // Save the mouse usage flag for later.
  63.   if (usemouse)
  64.     {
  65.       x1 = x;                // Start at current mouse position.
  66.       y1 = y;
  67.       corner = 1;
  68.     } /* then */
  69.    else
  70.     {
  71.       x1 = (window -> width) / 2;    // Start at screen middle for keyboard.
  72.       y1 = (window -> height) / 2;
  73.       corner = 0;
  74.     } /* else */
  75.   x2 = x1;
  76.   y2 = y1;
  77.   window -> markcut (x1,y1,x2,y2); // Mark the original cut position.
  78. } // UWCutToClipboard::UWCutToClipboard //
  79.  
  80. UWCutToClipboard::~UWCutToClipboard (void)
  81. {
  82.   if (corner != -1)
  83.     window -> markcut (x1,y1,x2,y2); // Remove the mark from the screen.
  84. } // ~UWCutToClipboard::UWCutToClipboard //
  85.  
  86. void    UWCutToClipboard::key (int keypress)
  87. {
  88.   int changex=0;
  89.   int changey=0;
  90.   if (usemouse)            // Ignore keyboard if using the mouse.
  91.     return;
  92.   switch (keypress)
  93.     {
  94.       case 033: window -> markcut (x1,y1,x2,y2);
  95.               corner = -1;
  96.               UWMaster.remove (); break;
  97.       case 13:    if (corner == 0)
  98.                 ++corner;        // Move to the other corner.
  99.          else
  100.           {
  101.             // Copy the screen data to the clipboard and exit //
  102.             ClipLength = window -> copycut (x1,y1,x2,y2,Clipboard);
  103.             window -> markcut (x1,y1,x2,y2);
  104.             corner = -1;
  105.             UWMaster.remove (); break;
  106.           }
  107.         break;
  108.       case CURSOR_UP:
  109.               if (y2 > 0)
  110.           changey = -1;
  111.         break;
  112.       case CURSOR_DOWN:
  113.               if (y2 < (window -> height - 1))
  114.           changey = 1;
  115.         break;
  116.       case CURSOR_LEFT:
  117.               if (x2 > 0)
  118.           changex = -1;
  119.         break;
  120.       case CURSOR_RIGHT:
  121.               if (x2 < (window -> width - 1))
  122.           changex = 1;
  123.         break;
  124.       default:    defkey (keypress);
  125.               break;
  126.     }
  127.   if (changex || changey)
  128.     {
  129.       if (corner == 0)
  130.         {
  131.           window -> markcut (x1,y1,x2,y2);    // Remove the current mark.
  132.           x2 += changex;            // Move the amount required.
  133.           y2 += changey;
  134.       x1 = x2;
  135.           y1 = y2;
  136.           window -> markcut (x1,y1,x2,y2);    // Set the new mark.
  137.     }
  138.        else
  139.         {
  140.       // We just want to mark/unmark the sides that change //
  141.       if (changex > 0 && x2 >= x1)
  142.         window -> markcut (x2 + 1,y1,x2 + changex,y2);
  143.        else if (changex > 0 && x2 < x1)
  144.         window -> markcut (x2,y1,x2 + changex - 1,y2);
  145.        else if (changex < 0 && x2 > x1)
  146.         window -> markcut (x2,y1,x2 + changex + 1,y2);
  147.        else if (changex < 0 && x2 <= x1)
  148.         window -> markcut (x2 + changex,y1,x2 - 1,y2);
  149.       x2 += changex;
  150.       if (changey > 0 && y2 >= y1)
  151.         window -> markcut (x1,y2 + 1,x2,y2 + changey);
  152.        else if (changey > 0 && y2 < y1)
  153.         window -> markcut (x1,y2,x2,y2 + changey - 1);
  154.        else if (changey < 0 && y2 > y1)
  155.         window -> markcut (x1,y2,x2,y2 + changey + 1);
  156.        else if (changey < 0 && y2 <= y1)
  157.         window -> markcut (x1,y2 + changey,x2,y2 - 1);
  158.       y2 += changey;
  159.     }
  160.     }
  161. } // UWCutToClipboard::key //
  162.  
  163. void    UWCutToClipboard::remote (int ch)
  164. {
  165.   window -> markcut (x1,y1,x2,y2);    // Remove the current mark.
  166.   if (underneath)
  167.     underneath -> remote (ch);
  168.   window -> markcut (x1,y1,x2,y2);    // Put the mark back.
  169. } // UWCutToClipboard::remote //
  170.  
  171. void    UWCutToClipboard::mouse (int x,int y,int buttons)
  172. {
  173.   if (!usemouse)
  174.     return;                // Not using the mouse - ignore.
  175.   if (buttons & MOUSE_LEFT)
  176.     {
  177.       // Move the bottom right corner to the mouse position */
  178.       if (y >= window -> height)
  179.     y = (window -> height) - 1;
  180.       window -> markcut (x1,y1,x2,y2);
  181.       x2 = x;
  182.       y2 = y;
  183.       window -> markcut (x1,y1,x2,y2);
  184.     } /* then */
  185.    else
  186.     {
  187.       // Copy the screen data to the clipboard and exit //
  188.       ClipLength = window -> copycut (x1,y1,x2,y2,Clipboard);
  189.       window -> markcut (x1,y1,x2,y2);
  190.       corner = -1;
  191.       UWMaster.remove ();
  192.     } /* else */
  193. } // UWCutToClipboard::mouse //
  194.  
  195. UWPasteFromClipboard::UWPasteFromClipboard (UWDisplay *wind)
  196.     : UWClient (wind)
  197. {
  198.   UWMaster.install (this);
  199.   if (ClipActive)
  200.     UWMaster.remove ();
  201.    else
  202.     {
  203.       ClipPosn = 0;
  204.       ClipActive = 1;
  205.     }
  206. } // UWPasteFromClipboard::UWPasteFromClipboard //
  207.  
  208. UWPasteFromClipboard::~UWPasteFromClipboard (void)
  209. {
  210.   if (ClipActive)
  211.     ClipActive = 0;
  212. } // ~UWPasteFromClipboard::UWPasteFromClipboard //
  213.  
  214. void    UWPasteFromClipboard::tick (void)
  215. {
  216.   int ch;
  217.   if (!ClipActive)
  218.     return;            // Ignore the paste - not active.
  219.   if (ClipPosn < ClipLength)
  220.     {
  221.       ch = Clipboard[ClipPosn++];
  222.       send (ch);        // Send pasted character to remote.
  223.       if (ch == '\r')
  224.         DELAY_FUNC (10);    // Give a delay between lines.
  225.     }
  226.    else
  227.     {
  228.       UWMaster.remove ();    // Remove the client - end of paste.
  229.       ClipActive = 0;
  230.     }
  231. } // UWPasteFromClipboard::tick //
  232.