home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
NOTEPAD2.ZIP
/
MCLIP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-08
|
3KB
|
137 lines
/************************************************************************\
* MCLIP.C -- Clipboard support routines for Multiline edit controls
*
* Created by Microsoft Corporation, 1989
*
* Routines used for cut, copy, clear, and paste for multiline edit controls
*
\************************************************************************/
#define INCL_WIN
#include <os2.h>
#include <string.h>
#include <opendlg.h>
#include "mle.h"
#include "mtypes.h"
#include "mfuncs.h"
/***********************************************************************
* Generally useful private definitions
***********************************************************************/
#define HABX ((HAB) NULL)
/* public function
*
* BOOL TxtClipCopy(PED ped, IPT iptFrom, IPT iptTo)
*
* Copy the given region of text to the clipboard in CF_TEXT format.
*/
public BOOL TxtClipCopy (PED ped, IPT iptFrom, IPT iptTo)
{
IPT cch;
SEL selData;
if (!WinOpenClipbrd (HABX) || !WinEmptyClipbrd (HABX))
return (FALSE);
// the clipboard must be able to hold all the text plus a final \0
cch = BufFormattedSize(ped, iptFrom, iptTo, MLE_CFTEXT);
if (cch > STORE_MAXSEG) {
WinCloseClipbrd (HABX);
return (FALSE);
}
if (DosAllocSeg ((USHORT) (cch+1), &selData, SEG_GIVEABLE) != 0) {
WinCloseClipbrd (HABX);
return (FALSE);
}
BufCopyOut(ped,iptFrom,MLE_CFTEXT,(PSZ)MAKEP(selData,0),
(OFFSET)cch);
*((PCHAR)MAKEP(selData,(USHORT)cch)) = '\0';
/*
* Put data in clipboard
*/
WinSetClipbrdData (HABX, (ULONG) selData, CF_TEXT, CFI_SELECTOR);
WinCloseClipbrd (HABX);
return (TRUE);
}
/* public function
*
* BOOL TxtClipCut(PED ped, IPT iptFrom, IPT iptTo)
*
* Cut the given region of text to the clipboard in CF_TEXT format.
*/
public BOOL TxtClipCut(PED ped, IPT iptFrom, IPT iptTo)
{
if (TxtClipCopy(ped,iptFrom,iptTo))
return(TxtClipClear(ped,iptFrom,iptTo));
else
return(FALSE);
}
/* public function
*
* BOOL TxtClipClear(PED ped, IPT iptFrom, IPT iptTo)
*
* Clear the given region.
*/
public BOOL TxtClipClear(PED ped, IPT iptFrom, IPT iptTo)
{
BOOL fRes;
RECTL rcl;
fRes = TxtChange(ped, iptFrom, iptTo, NULL, 0);
ZeroRect(rcl);
DispRefresh(ped, FALSE, rcl);
return(fRes);
}
/* public function
*
* BOOL TxtClipPaste(PED ped, IPT iptFrom, IPT iptTo)
*
* Pastes into the edit control, replacing the range specified.
*/
public BOOL TxtClipPaste(PED ped, IPT iptFrom, IPT iptTo)
{
SEL hData;
PCHAR pchClip;
IPT cch;
RECTL rcl;
if (!WinOpenClipbrd (HABX))
return (FALSE);
if (!(hData = (SEL) WinQueryClipbrdData (HABX, CF_TEXT))) {
WinCloseClipbrd (HABX);
return (FALSE);
}
pchClip = (PCHAR) MAKEP ((SEL)hData, 0);
/* Paste data into document */
cch = (IPT)lstrlen(pchClip);
BufCopyIn(ped, iptFrom, iptTo, pchClip, (OFFSET)cch);
/* Clean up & exit */
WinCloseClipbrd (HABX);
ZeroRect(rcl);
DispRefresh(ped, FALSE, rcl);
return (TRUE); /* succeeded */
}