2 * 'Wine' Clipboard function handling
4 * Copyright 1994 Martin Ayotte
7 static char Copyright
[] = "Copyright Martin Ayotte, 1994";
10 #define DEBUG_CLIPBOARD
16 #include <sys/types.h>
20 #include "prototypes.h"
24 typedef struct tagCLIPFORMAT
{
33 typedef CLIPFORMAT FAR
* LPCLIPFORMAT
;
35 static HWND hWndClipboardOwner
= 0;
36 static HWND hWndViewer
= 0;
37 static WORD LastRegFormat
= 0xC000;
39 CLIPFORMAT ClipFormats
[12] = {
40 { CF_TEXT
, 1, "Text", (HANDLE
)NULL
, 0, NULL
, &ClipFormats
[1] },
41 { CF_BITMAP
, 1, "Bitmap", (HANDLE
)NULL
, 0, &ClipFormats
[0], &ClipFormats
[2] },
42 { CF_METAFILEPICT
, 1, "MetaFile Picture", (HANDLE
)NULL
, 0, &ClipFormats
[1], &ClipFormats
[3] },
43 { CF_SYLK
, 1, "Sylk", (HANDLE
)NULL
, 0, &ClipFormats
[2], &ClipFormats
[4] },
44 { CF_DIF
, 1, "DIF", (HANDLE
)NULL
, 0, &ClipFormats
[3], &ClipFormats
[5] },
45 { CF_TIFF
, 1, "TIFF", (HANDLE
)NULL
, 0, &ClipFormats
[4], &ClipFormats
[6] },
46 { CF_OEMTEXT
, 1, "OEM Text", (HANDLE
)NULL
, 0, &ClipFormats
[5], &ClipFormats
[7] },
47 { CF_DIB
, 1, "DIB", (HANDLE
)NULL
, 0, &ClipFormats
[6], &ClipFormats
[8] },
48 { CF_PALETTE
, 1, "Palette", (HANDLE
)NULL
, 0, &ClipFormats
[7], &ClipFormats
[9] },
49 { CF_PENDATA
, 1, "PenData", (HANDLE
)NULL
, 0, &ClipFormats
[8], &ClipFormats
[10] },
50 { CF_RIFF
, 1, "RIFF", (HANDLE
)NULL
, 0, &ClipFormats
[9], &ClipFormats
[11] },
51 { CF_WAVE
, 1, "Wave", (HANDLE
)NULL
, 0, &ClipFormats
[10], NULL
}
54 /**************************************************************************
55 * OpenClipboard [USER.137]
57 BOOL
OpenClipboard(HWND hWnd
)
59 if (hWndClipboardOwner
!= 0) return FALSE
;
60 hWndClipboardOwner
= hWnd
;
61 #ifdef DEBUG_CLIPBOARD
62 printf("OpenClipboard(%04X); !\n", hWnd
);
68 /**************************************************************************
69 * CloseClipboard [USER.138]
73 if (hWndClipboardOwner
== 0) return FALSE
;
74 hWndClipboardOwner
= 0;
75 #ifdef DEBUG_CLIPBOARD
76 printf("CloseClipboard(); !\n");
82 /**************************************************************************
83 * EmptyClipboard [USER.139]
87 LPCLIPFORMAT lpFormat
= ClipFormats
;
88 if (hWndClipboardOwner
== 0) return FALSE
;
89 #ifdef DEBUG_CLIPBOARD
90 printf("EmptyClipboard(); !\n");
93 if (lpFormat
== NULL
) break;
94 if (lpFormat
->hData
!= 0) {
95 GlobalFree(lpFormat
->hData
);
98 lpFormat
= lpFormat
->NextFormat
;
104 /**************************************************************************
105 * GetClipboardOwner [USER.140]
107 HWND
GetClipboardOwner()
109 #ifdef DEBUG_CLIPBOARD
110 printf("GetClipboardOwner() = %04X !\n", hWndClipboardOwner
);
112 return hWndClipboardOwner
;
116 /**************************************************************************
117 * SetClipboardData [USER.141]
119 HANDLE
SetClipboardData(WORD wFormat
, HANDLE hData
)
121 LPCLIPFORMAT lpFormat
= ClipFormats
;
122 #ifdef DEBUG_CLIPBOARD
123 printf("SetClipboardDate(%04X, %04X) !\n", wFormat
, hData
);
126 if (lpFormat
== NULL
) return 0;
127 if (lpFormat
->wFormatID
== wFormat
) break;
128 lpFormat
= lpFormat
->NextFormat
;
130 if (lpFormat
->hData
!= 0) GlobalFree(lpFormat
->hData
);
131 lpFormat
->hData
= hData
;
132 return lpFormat
->hData
;
136 /**************************************************************************
137 * GetClipboardData [USER.142]
139 HANDLE
GetClipboardData(WORD wFormat
)
141 LPCLIPFORMAT lpFormat
= ClipFormats
;
142 #ifdef DEBUG_CLIPBOARD
143 printf("GetClipboardData(%04X) !\n", wFormat
);
146 if (lpFormat
== NULL
) return 0;
147 if (lpFormat
->wFormatID
== wFormat
) break;
148 lpFormat
= lpFormat
->NextFormat
;
150 return lpFormat
->hData
;
154 /**************************************************************************
155 * CountClipboardFormats [USER.143]
157 int CountClipboardFormats()
160 LPCLIPFORMAT lpFormat
= ClipFormats
;
162 if (lpFormat
== NULL
) break;
163 if (lpFormat
->hData
!= 0) {
164 #ifdef DEBUG_CLIPBOARD
165 printf("CountClipboardFormats // Find Not Empty (%04X) !\n",
170 lpFormat
= lpFormat
->NextFormat
;
172 #ifdef DEBUG_CLIPBOARD
173 printf("CountClipboardFormats() = %d !\n", FormatCount
);
179 /**************************************************************************
180 * EnumClipboardFormats [USER.144]
182 WORD
EnumClipboardFormats(WORD wFormat
)
184 LPCLIPFORMAT lpFormat
= ClipFormats
;
185 #ifdef DEBUG_CLIPBOARD
186 printf("EnumClipboardFormats(%04X) !\n", wFormat
);
189 if (lpFormat
->hData
!= 0)
190 return lpFormat
->wFormatID
;
192 wFormat
= lpFormat
->wFormatID
;
195 if (lpFormat
== NULL
) return 0;
196 if (lpFormat
->wFormatID
== wFormat
) break;
197 lpFormat
= lpFormat
->NextFormat
;
199 #ifdef DEBUG_CLIPBOARD
200 printf("EnumClipboardFormats // Find Last (%04X) !\n",
201 lpFormat
->wFormatID
);
203 lpFormat
= lpFormat
->NextFormat
;
205 if (lpFormat
== NULL
) return 0;
206 if (lpFormat
->hData
!= 0) break;
207 lpFormat
= lpFormat
->NextFormat
;
209 #ifdef DEBUG_CLIPBOARD
210 printf("EnumClipboardFormats // Find Not Empty Id=%04X hData=%04X !\n",
211 lpFormat
->wFormatID
, lpFormat
->hData
);
213 return lpFormat
->wFormatID
;
217 /**************************************************************************
218 * RegisterClipboardFormat [USER.145]
220 WORD
RegisterClipboardFormat(LPCSTR FormatName
)
222 LPCLIPFORMAT lpNewFormat
;
223 LPCLIPFORMAT lpFormat
= ClipFormats
;
224 if (FormatName
== NULL
) return 0;
226 if (lpFormat
->NextFormat
== NULL
) break;
227 lpFormat
= lpFormat
->NextFormat
;
229 lpNewFormat
= (LPCLIPFORMAT
)malloc(sizeof(CLIPFORMAT
));
230 if (lpNewFormat
== NULL
) return 0;
231 lpFormat
->NextFormat
= lpNewFormat
;
232 #ifdef DEBUG_CLIPBOARD
233 printf("RegisterClipboardFormat('%s') !\n", FormatName
);
235 lpNewFormat
->wFormatID
= LastRegFormat
;
236 lpNewFormat
->wRefCount
= 1;
237 lpNewFormat
->Name
= (LPSTR
)malloc(strlen(FormatName
) + 1);
238 if (lpNewFormat
->Name
== NULL
) {
242 strcpy(lpNewFormat
->Name
, FormatName
);
243 lpNewFormat
->hData
= 0;
244 lpNewFormat
->BufSize
= 0;
245 lpNewFormat
->PrevFormat
= lpFormat
;
246 lpNewFormat
->NextFormat
= NULL
;
247 return LastRegFormat
++;
251 /**************************************************************************
252 * GetClipboardFormatName [USER.146]
254 int GetClipboardFormatName(WORD wFormat
, LPSTR retStr
, short maxlen
)
256 LPCLIPFORMAT lpFormat
= ClipFormats
;
257 #ifdef DEBUG_CLIPBOARD
258 printf("GetClipboardFormat(%04X, %08X, %d) !\n", wFormat
, retStr
, maxlen
);
261 if (lpFormat
== NULL
) return 0;
262 if (lpFormat
->wFormatID
== wFormat
) break;
263 lpFormat
= lpFormat
->NextFormat
;
265 if (lpFormat
->Name
== NULL
) return 0;
266 #ifdef DEBUG_CLIPBOARD
267 printf("GetClipboardFormat // Name='%s' !\n", lpFormat
->Name
);
269 maxlen
= min(maxlen
- 1, strlen(lpFormat
->Name
));
270 printf("GetClipboardFormat // maxlen=%d !\n", maxlen
);
271 memcpy(retStr
, lpFormat
->Name
, maxlen
);
277 /**************************************************************************
278 * SetClipboardViewer [USER.147]
280 HWND
SetClipboardViewer(HWND hWnd
)
282 #ifdef DEBUG_CLIPBOARD
283 printf("SetClipboardFormat(%04X) !\n", hWnd
);
289 /**************************************************************************
290 * GetClipboardViewer [USER.148]
292 HWND
GetClipboardViewer()
294 #ifdef DEBUG_CLIPBOARD
295 printf("GetClipboardFormat() = %04X !\n", hWndViewer
);
300 /**************************************************************************
301 * ChangeClipboardChain [USER.149]
303 BOOL
ChangeClipboardChain(HWND hWnd
, HWND hWndNext
)
305 #ifdef DEBUG_CLIPBOARD
306 printf("ChangeClipboardChain(%04X, %04X) !\n", hWnd
, hWndNext
);
311 /**************************************************************************
312 * IsClipboardFormatAvailable [USER.193]
314 BOOL
IsClipboardFormatAvailable(WORD wFormat
)
316 LPCLIPFORMAT lpFormat
= ClipFormats
;
317 #ifdef DEBUG_CLIPBOARD
318 printf("IsClipboardFormatAvailable(%04X) !\n", wFormat
);
321 if (lpFormat
== NULL
) return FALSE
;
322 if (lpFormat
->wFormatID
== wFormat
) break;
323 lpFormat
= lpFormat
->NextFormat
;
325 return (lpFormat
->hData
!= 0);
329 /**************************************************************************
330 * GetOpenClipboardWindow [USER.248]
332 HWND
GetOpenClipboardWindow()
334 #ifdef DEBUG_CLIPBOARD
335 printf("GetOpenClipboardWindow() = %04X !\n", hWndClipboardOwner
);
337 return hWndClipboardOwner
;
341 /**************************************************************************
342 * GetPriorityClipboardFormat [USER.402]
344 int GetPriorityClipboardFormat(WORD FAR
*lpPriorityList
, short nCount
)
346 #ifdef DEBUG_CLIPBOARD
347 printf("GetPriorityClipboardFormat(%08X, %d) !\n", lpPriorityList
, nCount
);