1 /* Public Domain Curses */
5 RCSID("$Id: pdcclip.c,v 1.33 2008/07/14 04:24:51 wmcbrine Exp $")
7 /*man-start**************************************************************
12 int PDC_getclipboard(char **contents, long *length);
13 int PDC_setclipboard(const char *contents, long length);
14 int PDC_freeclipboard(char *contents);
15 int PDC_clearclipboard(void);
18 PDC_getclipboard() gets the textual contents of the system's
19 clipboard. This function returns the contents of the clipboard
20 in the contents argument. It is the responsibilitiy of the
21 caller to free the memory returned, via PDC_freeclipboard().
22 The length of the clipboard contents is returned in the length
25 PDC_setclipboard copies the supplied text into the system's
26 clipboard, emptying the clipboard prior to the copy.
28 PDC_clearclipboard() clears the internal clipboard.
31 indicator of success/failure of call.
32 PDC_CLIP_SUCCESS the call was successful
33 PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for
34 the clipboard contents
35 PDC_CLIP_EMPTY the clipboard contains no text
36 PDC_CLIP_ACCESS_ERROR no clipboard support
38 Portability X/Open BSD SYS V
39 PDC_getclipboard - - -
40 PDC_setclipboard - - -
41 PDC_freeclipboard - - -
42 PDC_clearclipboard - - -
44 **man-end****************************************************************/
46 int PDC_getclipboard(char **contents
, long *length
)
57 PDC_LOG(("PDC_getclipboard() - called\n"));
60 DosGetInfoBlocks(&ptib
, &ppib
);
62 hab
= WinInitialize(0);
63 hmq
= WinCreateMsgQueue(hab
, 0);
65 if (!WinOpenClipbrd(hab
))
67 WinDestroyMsgQueue(hmq
);
69 return PDC_CLIP_ACCESS_ERROR
;
74 ulRet
= WinQueryClipbrdData(hab
, CF_TEXT
);
78 len
= strlen((char *)ulRet
);
79 *contents
= malloc(len
+ 1);
82 rc
= PDC_CLIP_MEMORY_ERROR
;
85 strcpy((char *)*contents
, (char *)ulRet
);
87 rc
= PDC_CLIP_SUCCESS
;
92 WinDestroyMsgQueue(hmq
);
97 return PDC_CLIP_ACCESS_ERROR
;
101 int PDC_setclipboard(const char *contents
, long length
)
108 PSZ szTextOut
= NULL
;
111 PDC_LOG(("PDC_setclipboard() - called\n"));
114 DosGetInfoBlocks(&ptib
, &ppib
);
115 ppib
->pib_ultype
= 3;
116 hab
= WinInitialize(0);
118 if (!WinOpenClipbrd(hab
))
121 return PDC_CLIP_ACCESS_ERROR
;
124 rc
= PDC_CLIP_MEMORY_ERROR
;
126 ulRC
= DosAllocSharedMem((PVOID
)&szTextOut
, NULL
, length
+ 1,
127 PAG_WRITE
| PAG_COMMIT
| OBJ_GIVEABLE
);
131 strcpy(szTextOut
, contents
);
132 WinEmptyClipbrd(hab
);
134 if (WinSetClipbrdData(hab
, (ULONG
)szTextOut
, CF_TEXT
, CFI_POINTER
))
135 rc
= PDC_CLIP_SUCCESS
;
138 DosFreeMem(szTextOut
);
139 rc
= PDC_CLIP_ACCESS_ERROR
;
143 WinCloseClipbrd(hab
);
148 return PDC_CLIP_ACCESS_ERROR
;
152 int PDC_freeclipboard(char *contents
)
154 PDC_LOG(("PDC_freeclipboard() - called\n"));
159 return PDC_CLIP_SUCCESS
;
162 int PDC_clearclipboard(void)
169 PDC_LOG(("PDC_clearclipboard() - called\n"));
172 DosGetInfoBlocks(&ptib
, &ppib
);
173 ppib
->pib_ultype
= 3;
174 hab
= WinInitialize(0);
176 WinEmptyClipbrd(hab
);
178 WinCloseClipbrd(hab
);
181 return PDC_CLIP_SUCCESS
;
183 return PDC_CLIP_ACCESS_ERROR
;