Release 940420
[wine/multimedia.git] / misc / clipboard.c
blob17cca794ab60c23e68871056b7af4a38feb676db
1 /*
2 * 'Wine' Clipboard function handling
4 * Copyright 1994 Martin Ayotte
5 */
7 static char Copyright[] = "Copyright Martin Ayotte, 1994";
9 /*
10 #define DEBUG_CLIPBOARD
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <windows.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include "prototypes.h"
21 #include "heap.h"
22 #include "win.h"
24 typedef struct tagCLIPFORMAT {
25 WORD wFormatID;
26 WORD wRefCount;
27 LPSTR Name;
28 HANDLE hData;
29 DWORD BufSize;
30 void *PrevFormat;
31 void *NextFormat;
32 } CLIPFORMAT;
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);
63 #endif
64 return TRUE;
68 /**************************************************************************
69 * CloseClipboard [USER.138]
71 BOOL CloseClipboard()
73 if (hWndClipboardOwner == 0) return FALSE;
74 hWndClipboardOwner = 0;
75 #ifdef DEBUG_CLIPBOARD
76 printf("CloseClipboard(); !\n");
77 #endif
78 return TRUE;
82 /**************************************************************************
83 * EmptyClipboard [USER.139]
85 BOOL EmptyClipboard()
87 LPCLIPFORMAT lpFormat = ClipFormats;
88 if (hWndClipboardOwner == 0) return FALSE;
89 #ifdef DEBUG_CLIPBOARD
90 printf("EmptyClipboard(); !\n");
91 #endif
92 while(TRUE) {
93 if (lpFormat == NULL) break;
94 if (lpFormat->hData != 0) {
95 GlobalFree(lpFormat->hData);
96 lpFormat->hData = 0;
98 lpFormat = lpFormat->NextFormat;
100 return TRUE;
104 /**************************************************************************
105 * GetClipboardOwner [USER.140]
107 HWND GetClipboardOwner()
109 #ifdef DEBUG_CLIPBOARD
110 printf("GetClipboardOwner() = %04X !\n", hWndClipboardOwner);
111 #endif
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);
124 #endif
125 while(TRUE) {
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);
144 #endif
145 while(TRUE) {
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()
159 int FormatCount = 0;
160 LPCLIPFORMAT lpFormat = ClipFormats;
161 while(TRUE) {
162 if (lpFormat == NULL) break;
163 if (lpFormat->hData != 0) {
164 #ifdef DEBUG_CLIPBOARD
165 printf("CountClipboardFormats // Find Not Empty (%04X) !\n",
166 lpFormat->hData);
167 #endif
168 FormatCount++;
170 lpFormat = lpFormat->NextFormat;
172 #ifdef DEBUG_CLIPBOARD
173 printf("CountClipboardFormats() = %d !\n", FormatCount);
174 #endif
175 return 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);
187 #endif
188 if (wFormat == 0) {
189 if (lpFormat->hData != 0)
190 return lpFormat->wFormatID;
191 else
192 wFormat = lpFormat->wFormatID;
194 while(TRUE) {
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);
202 #endif
203 lpFormat = lpFormat->NextFormat;
204 while(TRUE) {
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);
212 #endif
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;
225 while(TRUE) {
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);
234 #endif
235 lpNewFormat->wFormatID = LastRegFormat;
236 lpNewFormat->wRefCount = 1;
237 lpNewFormat->Name = (LPSTR)malloc(strlen(FormatName) + 1);
238 if (lpNewFormat->Name == NULL) {
239 free(lpNewFormat);
240 return 0;
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);
259 #endif
260 while(TRUE) {
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);
268 #endif
269 maxlen = min(maxlen - 1, strlen(lpFormat->Name));
270 printf("GetClipboardFormat // maxlen=%d !\n", maxlen);
271 memcpy(retStr, lpFormat->Name, maxlen);
272 retStr[maxlen] = 0;
273 return maxlen;
277 /**************************************************************************
278 * SetClipboardViewer [USER.147]
280 HWND SetClipboardViewer(HWND hWnd)
282 #ifdef DEBUG_CLIPBOARD
283 printf("SetClipboardFormat(%04X) !\n", hWnd);
284 #endif
285 hWndViewer = hWnd;
289 /**************************************************************************
290 * GetClipboardViewer [USER.148]
292 HWND GetClipboardViewer()
294 #ifdef DEBUG_CLIPBOARD
295 printf("GetClipboardFormat() = %04X !\n", hWndViewer);
296 #endif
300 /**************************************************************************
301 * ChangeClipboardChain [USER.149]
303 BOOL ChangeClipboardChain(HWND hWnd, HWND hWndNext)
305 #ifdef DEBUG_CLIPBOARD
306 printf("ChangeClipboardChain(%04X, %04X) !\n", hWnd, hWndNext);
307 #endif
311 /**************************************************************************
312 * IsClipboardFormatAvailable [USER.193]
314 BOOL IsClipboardFormatAvailable(WORD wFormat)
316 LPCLIPFORMAT lpFormat = ClipFormats;
317 #ifdef DEBUG_CLIPBOARD
318 printf("IsClipboardFormatAvailable(%04X) !\n", wFormat);
319 #endif
320 while(TRUE) {
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);
336 #endif
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);
348 #endif