home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / NOTEPAD2.ZIP / MCLIP.C < prev    next >
C/C++ Source or Header  |  1989-02-08  |  3KB  |  137 lines

  1. /************************************************************************\
  2. * MCLIP.C -- Clipboard support routines for Multiline edit controls
  3. *
  4. * Created by Microsoft Corporation, 1989
  5. *
  6. * Routines used for cut, copy, clear, and paste for multiline edit controls
  7. *
  8. \************************************************************************/
  9.  
  10. #define INCL_WIN
  11. #include <os2.h>
  12. #include <string.h>
  13. #include <opendlg.h>
  14. #include "mle.h"
  15. #include "mtypes.h"
  16. #include "mfuncs.h"
  17.  
  18. /***********************************************************************
  19. * Generally useful private definitions
  20. ***********************************************************************/
  21.  
  22. #define HABX ((HAB) NULL)
  23.  
  24. /* public function
  25.  *
  26.  * BOOL TxtClipCopy(PED ped, IPT iptFrom, IPT iptTo)
  27.  *
  28.  * Copy the given region of text to the clipboard in CF_TEXT format.
  29.  */
  30. public BOOL TxtClipCopy (PED ped, IPT iptFrom, IPT iptTo)
  31. {
  32.         IPT cch;
  33.         SEL selData;
  34.  
  35.         if (!WinOpenClipbrd (HABX) || !WinEmptyClipbrd (HABX))
  36.                 return (FALSE);
  37.  
  38.         // the clipboard must be able to hold all the text plus a final \0
  39.  
  40.         cch = BufFormattedSize(ped, iptFrom, iptTo, MLE_CFTEXT);
  41.  
  42.         if (cch > STORE_MAXSEG) {
  43.                 WinCloseClipbrd (HABX);
  44.                 return (FALSE);
  45.         }
  46.  
  47.         if (DosAllocSeg ((USHORT) (cch+1), &selData, SEG_GIVEABLE) != 0) {
  48.                 WinCloseClipbrd (HABX);
  49.                 return (FALSE);
  50.         }
  51.  
  52.         BufCopyOut(ped,iptFrom,MLE_CFTEXT,(PSZ)MAKEP(selData,0),
  53.                 (OFFSET)cch);
  54.         *((PCHAR)MAKEP(selData,(USHORT)cch)) = '\0';
  55.  
  56.         /*
  57.          *  Put data in clipboard
  58.          */
  59.  
  60.         WinSetClipbrdData (HABX, (ULONG) selData, CF_TEXT, CFI_SELECTOR);
  61.         WinCloseClipbrd (HABX);
  62.         return (TRUE);
  63. }
  64.  
  65.  
  66. /* public function
  67.  *
  68.  * BOOL TxtClipCut(PED ped, IPT iptFrom, IPT iptTo)
  69.  *
  70.  * Cut the given region of text to the clipboard in CF_TEXT format.
  71.  */
  72. public BOOL TxtClipCut(PED ped, IPT iptFrom, IPT iptTo)
  73. {
  74.     if (TxtClipCopy(ped,iptFrom,iptTo))
  75.         return(TxtClipClear(ped,iptFrom,iptTo));
  76.     else
  77.         return(FALSE);
  78.     }
  79.  
  80. /* public function
  81.  *
  82.  * BOOL TxtClipClear(PED ped, IPT iptFrom, IPT iptTo)
  83.  *
  84.  * Clear the given region.
  85.  */
  86. public BOOL TxtClipClear(PED ped, IPT iptFrom, IPT iptTo)
  87. {
  88.     BOOL fRes;
  89.     RECTL rcl;
  90.  
  91.     fRes = TxtChange(ped, iptFrom, iptTo, NULL, 0);
  92.     ZeroRect(rcl);
  93.     DispRefresh(ped, FALSE, rcl);
  94.     return(fRes);
  95. }
  96.  
  97.  
  98. /* public function
  99.  *
  100.  * BOOL TxtClipPaste(PED ped, IPT iptFrom, IPT iptTo)
  101.  *
  102.  * Pastes into the edit control, replacing the range specified.
  103.  */
  104. public BOOL TxtClipPaste(PED ped, IPT iptFrom, IPT iptTo)
  105. {
  106.     SEL      hData;
  107.     PCHAR    pchClip;
  108.     IPT      cch;
  109.     RECTL    rcl;
  110.  
  111.     if (!WinOpenClipbrd (HABX))
  112.         return (FALSE);
  113.  
  114.     if (!(hData = (SEL) WinQueryClipbrdData (HABX, CF_TEXT))) {
  115.         WinCloseClipbrd (HABX);
  116.         return (FALSE);
  117.         }
  118.  
  119.     pchClip = (PCHAR) MAKEP ((SEL)hData, 0);
  120.  
  121.  
  122.     /* Paste data into document */
  123.  
  124.     cch = (IPT)lstrlen(pchClip);
  125.  
  126.     BufCopyIn(ped, iptFrom, iptTo, pchClip, (OFFSET)cch);
  127.  
  128.     /*  Clean up & exit */
  129.  
  130.     WinCloseClipbrd (HABX);
  131.  
  132.     ZeroRect(rcl);
  133.     DispRefresh(ped, FALSE, rcl);
  134.  
  135.     return (TRUE);              /* succeeded */
  136. }
  137.