| 1 |
|
| 2 |
|
| 3 |
#include "pdcos2.h" |
| 4 |
|
| 5 |
RCSID("$Id: pdcclip.c,v 1.33 2008/07/14 04:24:51 wmcbrine Exp $") |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
int PDC_getclipboard(char **contents, long *length) |
| 47 |
{ |
| 48 |
#ifndef EMXVIDEO |
| 49 |
HMQ hmq; |
| 50 |
HAB hab; |
| 51 |
PTIB ptib; |
| 52 |
PPIB ppib; |
| 53 |
ULONG ulRet; |
| 54 |
long len; |
| 55 |
int rc; |
| 56 |
#endif |
| 57 |
PDC_LOG(("PDC_getclipboard() - called\n")); |
| 58 |
|
| 59 |
#ifndef EMXVIDEO |
| 60 |
DosGetInfoBlocks(&ptib, &ppib); |
| 61 |
ppib->pib_ultype = 3; |
| 62 |
hab = WinInitialize(0); |
| 63 |
hmq = WinCreateMsgQueue(hab, 0); |
| 64 |
|
| 65 |
if (!WinOpenClipbrd(hab)) |
| 66 |
{ |
| 67 |
WinDestroyMsgQueue(hmq); |
| 68 |
WinTerminate(hab); |
| 69 |
return PDC_CLIP_ACCESS_ERROR; |
| 70 |
} |
| 71 |
|
| 72 |
rc = PDC_CLIP_EMPTY; |
| 73 |
|
| 74 |
ulRet = WinQueryClipbrdData(hab, CF_TEXT); |
| 75 |
|
| 76 |
if (ulRet) |
| 77 |
{ |
| 78 |
len = strlen((char *)ulRet); |
| 79 |
*contents = malloc(len + 1); |
| 80 |
|
| 81 |
if (!*contents) |
| 82 |
rc = PDC_CLIP_MEMORY_ERROR; |
| 83 |
else |
| 84 |
{ |
| 85 |
strcpy((char *)*contents, (char *)ulRet); |
| 86 |
*length = len; |
| 87 |
rc = PDC_CLIP_SUCCESS; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
WinCloseClipbrd(hab); |
| 92 |
WinDestroyMsgQueue(hmq); |
| 93 |
WinTerminate(hab); |
| 94 |
|
| 95 |
return rc; |
| 96 |
#else |
| 97 |
return PDC_CLIP_ACCESS_ERROR; |
| 98 |
#endif |
| 99 |
} |
| 100 |
|
| 101 |
int PDC_setclipboard(const char *contents, long length) |
| 102 |
{ |
| 103 |
#ifndef EMXVIDEO |
| 104 |
HAB hab; |
| 105 |
PTIB ptib; |
| 106 |
PPIB ppib; |
| 107 |
ULONG ulRC; |
| 108 |
PSZ szTextOut = NULL; |
| 109 |
int rc; |
| 110 |
#endif |
| 111 |
PDC_LOG(("PDC_setclipboard() - called\n")); |
| 112 |
|
| 113 |
#ifndef EMXVIDEO |
| 114 |
DosGetInfoBlocks(&ptib, &ppib); |
| 115 |
ppib->pib_ultype = 3; |
| 116 |
hab = WinInitialize(0); |
| 117 |
|
| 118 |
if (!WinOpenClipbrd(hab)) |
| 119 |
{ |
| 120 |
WinTerminate(hab); |
| 121 |
return PDC_CLIP_ACCESS_ERROR; |
| 122 |
} |
| 123 |
|
| 124 |
rc = PDC_CLIP_MEMORY_ERROR; |
| 125 |
|
| 126 |
ulRC = DosAllocSharedMem((PVOID)&szTextOut, NULL, length + 1, |
| 127 |
PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE); |
| 128 |
|
| 129 |
if (ulRC == 0) |
| 130 |
{ |
| 131 |
strcpy(szTextOut, contents); |
| 132 |
WinEmptyClipbrd(hab); |
| 133 |
|
| 134 |
if (WinSetClipbrdData(hab, (ULONG)szTextOut, CF_TEXT, CFI_POINTER)) |
| 135 |
rc = PDC_CLIP_SUCCESS; |
| 136 |
else |
| 137 |
{ |
| 138 |
DosFreeMem(szTextOut); |
| 139 |
rc = PDC_CLIP_ACCESS_ERROR; |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
WinCloseClipbrd(hab); |
| 144 |
WinTerminate(hab); |
| 145 |
|
| 146 |
return rc; |
| 147 |
#else |
| 148 |
return PDC_CLIP_ACCESS_ERROR; |
| 149 |
#endif |
| 150 |
} |
| 151 |
|
| 152 |
int PDC_freeclipboard(char *contents) |
| 153 |
{ |
| 154 |
PDC_LOG(("PDC_freeclipboard() - called\n")); |
| 155 |
|
| 156 |
if (contents) |
| 157 |
free(contents); |
| 158 |
|
| 159 |
return PDC_CLIP_SUCCESS; |
| 160 |
} |
| 161 |
|
| 162 |
int PDC_clearclipboard(void) |
| 163 |
{ |
| 164 |
#ifndef EMXVIDEO |
| 165 |
HAB hab; |
| 166 |
PTIB ptib; |
| 167 |
PPIB ppib; |
| 168 |
#endif |
| 169 |
PDC_LOG(("PDC_clearclipboard() - called\n")); |
| 170 |
|
| 171 |
#ifndef EMXVIDEO |
| 172 |
DosGetInfoBlocks(&ptib, &ppib); |
| 173 |
ppib->pib_ultype = 3; |
| 174 |
hab = WinInitialize(0); |
| 175 |
|
| 176 |
WinEmptyClipbrd(hab); |
| 177 |
|
| 178 |
WinCloseClipbrd(hab); |
| 179 |
WinTerminate(hab); |
| 180 |
|
| 181 |
return PDC_CLIP_SUCCESS; |
| 182 |
#else |
| 183 |
return PDC_CLIP_ACCESS_ERROR; |
| 184 |
#endif |
| 185 |
} |