#include "pdcos2.h"
int PDC_getclipboard(char **contents, long *length)
{
#ifndef EMXVIDEO
HMQ hmq;
HAB hab;
PTIB ptib;
PPIB ppib;
ULONG ulRet;
long len;
int rc;
#endif
PDC_LOG(("PDC_getclipboard() - called\n"));
#ifndef EMXVIDEO
DosGetInfoBlocks(&ptib, &ppib);
ppib->pib_ultype = 3;
hab = WinInitialize(0);
hmq = WinCreateMsgQueue(hab, 0);
if (!WinOpenClipbrd(hab))
{
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
return PDC_CLIP_ACCESS_ERROR;
}
rc = PDC_CLIP_EMPTY;
ulRet = WinQueryClipbrdData(hab, CF_TEXT);
if (ulRet)
{
len = strlen((char *)ulRet);
*contents = malloc(len + 1);
if (!*contents)
rc = PDC_CLIP_MEMORY_ERROR;
else
{
strcpy((char *)*contents, (char *)ulRet);
*length = len;
rc = PDC_CLIP_SUCCESS;
}
}
WinCloseClipbrd(hab);
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
return rc;
#else
return PDC_CLIP_ACCESS_ERROR;
#endif
}
int PDC_setclipboard(const char *contents, long length)
{
#ifndef EMXVIDEO
HAB hab;
PTIB ptib;
PPIB ppib;
ULONG ulRC;
PSZ szTextOut = NULL;
int rc;
#endif
PDC_LOG(("PDC_setclipboard() - called\n"));
#ifndef EMXVIDEO
DosGetInfoBlocks(&ptib, &ppib);
ppib->pib_ultype = 3;
hab = WinInitialize(0);
if (!WinOpenClipbrd(hab))
{
WinTerminate(hab);
return PDC_CLIP_ACCESS_ERROR;
}
rc = PDC_CLIP_MEMORY_ERROR;
ulRC = DosAllocSharedMem((PVOID)&szTextOut, NULL, length + 1,
PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE);
if (ulRC == 0)
{
strcpy(szTextOut, contents);
WinEmptyClipbrd(hab);
if (WinSetClipbrdData(hab, (ULONG)szTextOut, CF_TEXT, CFI_POINTER))
rc = PDC_CLIP_SUCCESS;
else
{
DosFreeMem(szTextOut);
rc = PDC_CLIP_ACCESS_ERROR;
}
}
WinCloseClipbrd(hab);
WinTerminate(hab);
return rc;
#else
return PDC_CLIP_ACCESS_ERROR;
#endif
}
int PDC_freeclipboard(char *contents)
{
PDC_LOG(("PDC_freeclipboard() - called\n"));
if (contents)
free(contents);
return PDC_CLIP_SUCCESS;
}
int PDC_clearclipboard(void)
{
#ifndef EMXVIDEO
HAB hab;
PTIB ptib;
PPIB ppib;
#endif
PDC_LOG(("PDC_clearclipboard() - called\n"));
#ifndef EMXVIDEO
DosGetInfoBlocks(&ptib, &ppib);
ppib->pib_ultype = 3;
hab = WinInitialize(0);
WinEmptyClipbrd(hab);
WinCloseClipbrd(hab);
WinTerminate(hab);
return PDC_CLIP_SUCCESS;
#else
return PDC_CLIP_ACCESS_ERROR;
#endif
}