Release 940804
[wine/gsoc-2012-control.git] / misc / property.c
blobb58d1731dd8c5854e35cb8ee0b9d3372c1b12f44
1 /*
2 * Windows Properties Functions
3 */
4 static char Copyright[] = "Copyright Martin Ayotte, 1994";
6 /*
7 #define DEBUG_PROP
8 */
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <unistd.h>
14 #include "windows.h"
15 #include "heap.h"
16 #include "win.h"
18 typedef struct tagPROPENTRY {
19 LPSTR PropName;
20 WORD Atom;
21 HANDLE hData;
22 struct tagPROPENTRY *lpPrevProp;
23 struct tagPROPENTRY *lpNextProp;
24 } PROPENTRY;
25 typedef PROPENTRY *LPPROPENTRY;
28 /*************************************************************************
29 * RemoveProp [USER.24]
31 HANDLE RemoveProp(HWND hWnd, LPSTR lpStr)
33 WND *wndPtr;
34 LPPROPENTRY lpProp;
35 HANDLE hOldData;
36 #ifdef DEBUG_PROP
37 if (((DWORD)lpStr & 0xFFFF0000) == 0L)
38 printf("RemoveProp(%04X, Atom %04X)\n", hWnd, LOWORD((DWORD)lpStr));
39 else
40 printf("RemoveProp(%04X, '%s')\n", hWnd, lpStr);
41 #endif
42 wndPtr = WIN_FindWndPtr(hWnd);
43 if (wndPtr == NULL) {
44 printf("RemoveProp // Bad Window handle !\n");
45 return FALSE;
47 lpProp = (LPPROPENTRY) GlobalLock(wndPtr->hProp);
48 if (lpProp == NULL) {
49 #ifdef DEBUG_PROP
50 printf("Property List Empty !\n");
51 #endif
52 return 0;
54 while (TRUE) {
55 if ((((DWORD)lpStr & 0xFFFF0000) == 0L &&
56 lpProp->Atom == LOWORD((DWORD)lpStr)) ||
57 (((DWORD)lpStr & 0xFFFF0000) != 0L &&
58 lpProp->PropName != NULL &&
59 strcmp(lpProp->PropName, lpStr) == 0)) {
60 #ifdef DEBUG_PROP
61 printf("RemoveProp // Property found ! hData=%04X\n", lpProp->hData);
62 #endif
63 hOldData = lpProp->hData;
64 if (lpProp->lpPrevProp != NULL)
65 lpProp->lpPrevProp->lpNextProp = lpProp->lpNextProp;
66 if (lpProp->lpNextProp != NULL)
67 lpProp->lpNextProp->lpPrevProp = lpProp->lpPrevProp;
68 if (lpProp->PropName != NULL) free(lpProp->PropName);
69 GlobalFree(lpProp);
70 GlobalUnlock(wndPtr->hProp);
71 return hOldData;
73 if (lpProp->lpNextProp == NULL) break;
74 lpProp = lpProp->lpNextProp;
76 GlobalUnlock(wndPtr->hProp);
77 #ifdef DEBUG_PROP
78 printf("RemoveProp // Property not found !\n");
79 #endif
80 return 0;
84 /*************************************************************************
85 * GetProp [USER.25]
87 HANDLE GetProp(HWND hWnd, LPSTR lpStr)
89 WND *wndPtr;
90 LPPROPENTRY lpProp;
91 #ifdef DEBUG_PROP
92 if (((DWORD)lpStr & 0xFFFF0000) == 0L)
93 printf("GetProp(%04X, Atom %04X)\n", hWnd, LOWORD((DWORD)lpStr));
94 else
95 printf("GetProp(%04X, '%s')\n", hWnd, lpStr);
96 #endif
97 wndPtr = WIN_FindWndPtr(hWnd);
98 if (wndPtr == NULL) {
99 printf("GetProp // Bad Window handle !\n");
100 return 0;
102 lpProp = (LPPROPENTRY) GlobalLock(wndPtr->hProp);
103 if (lpProp == NULL) {
104 #ifdef DEBUG_PROP
105 printf("Property List Empty !\n");
106 #endif
107 return 0;
109 while (TRUE) {
110 if ((((DWORD)lpStr & 0xFFFF0000) == 0L &&
111 lpProp->Atom == LOWORD((DWORD)lpStr)) ||
112 (((DWORD)lpStr & 0xFFFF0000) != 0L &&
113 lpProp->PropName != NULL &&
114 strcmp(lpProp->PropName, lpStr) == 0)) {
115 #ifdef DEBUG_PROP
116 printf("GetProp // Property found ! hData=%04X\n", lpProp->hData);
117 #endif
118 GlobalUnlock(wndPtr->hProp);
119 return lpProp->hData;
121 if (lpProp->lpNextProp == NULL) break;
122 lpProp = lpProp->lpNextProp;
124 #ifdef DEBUG_PROP
125 printf("GetProp // Property not found !\n");
126 #endif
127 GlobalUnlock(wndPtr->hProp);
128 return 0;
132 /*************************************************************************
133 * SetProp [USER.26]
135 BOOL SetProp(HWND hWnd, LPSTR lpStr, HANDLE hData)
137 WND *wndPtr;
138 HANDLE hNewProp;
139 LPPROPENTRY lpNewProp;
140 LPPROPENTRY lpProp;
141 #ifdef DEBUG_PROP
142 if (((DWORD)lpStr & 0xFFFF0000) == 0L)
143 printf("SetProp(%04X, Atom %04X, %04X)\n",
144 hWnd, LOWORD((DWORD)lpStr), hData);
145 else
146 printf("SetProp(%04X, '%s', %04X)\n", hWnd, lpStr, hData);
147 #endif
148 wndPtr = WIN_FindWndPtr(hWnd);
149 if (wndPtr == NULL) {
150 printf("SetProp // Bad Window handle !\n");
151 return FALSE;
153 lpProp = (LPPROPENTRY) GlobalLock(wndPtr->hProp);
154 if (lpProp != NULL) {
155 while (TRUE) {
156 if ((((DWORD)lpStr & 0xFFFF0000) == 0L &&
157 lpProp->Atom == LOWORD((DWORD)lpStr)) ||
158 (((DWORD)lpStr & 0xFFFF0000) != 0L &&
159 lpProp->PropName != NULL &&
160 strcmp(lpProp->PropName, lpStr) == 0)) {
161 #ifdef DEBUG_PROP
162 printf("SetProp // change already exinsting property !\n");
163 #endif
164 lpProp->hData = hData;
165 GlobalUnlock(wndPtr->hProp);
166 return TRUE;
168 if (lpProp->lpNextProp == NULL) break;
169 lpProp = lpProp->lpNextProp;
172 hNewProp = GlobalAlloc(GMEM_MOVEABLE, sizeof(PROPENTRY));
173 lpNewProp = (LPPROPENTRY) GlobalLock(hNewProp);
174 if (lpNewProp == NULL) {
175 printf("SetProp // Can't allocate Property entry !\n");
176 GlobalUnlock(wndPtr->hProp);
177 return FALSE;
179 #ifdef DEBUG_PROP
180 printf("SetProp // entry allocated %08X\n", lpNewProp);
181 #endif
182 if (lpProp == NULL) {
183 wndPtr->hProp = hNewProp;
184 lpNewProp->lpPrevProp = NULL;
185 #ifdef DEBUG_PROP
186 printf("SetProp // first entry \n");
187 #endif
189 else {
190 lpProp->lpNextProp = lpNewProp;
191 lpNewProp->lpPrevProp = lpProp;
193 lpNewProp->lpNextProp = NULL;
194 lpNewProp->hData = hData;
195 if (((DWORD)lpStr & 0xFFFF0000) == 0L) {
196 lpNewProp->PropName = NULL;
197 lpNewProp->Atom = LOWORD((DWORD)lpStr);
199 else {
200 lpNewProp->Atom = 0;
201 lpNewProp->PropName = malloc(strlen(lpStr) + 1);
202 if (lpNewProp->PropName == NULL) {
203 printf("SetProp // Can't allocate memory for Property Name !\n");
204 GlobalUnlock(wndPtr->hProp);
205 return FALSE;
207 strcpy(lpNewProp->PropName, lpStr);
209 GlobalUnlock(hNewProp);
210 GlobalUnlock(wndPtr->hProp);
211 return TRUE;
215 /*************************************************************************
216 * EnumProps [USER.27]
218 int EnumProps(HWND hWnd, FARPROC lpEnumFunc)
220 WND *wndPtr;
221 LPPROPENTRY lpProp;
222 LPSTR str;
223 int nRet;
224 printf("EnumProps(%04X, %08X)\n", hWnd, lpEnumFunc);
225 wndPtr = WIN_FindWndPtr(hWnd);
226 if (wndPtr == NULL) {
227 printf("EnumProps // Bad Window handle !\n");
228 return 0;
230 lpProp = (LPPROPENTRY) GlobalLock(wndPtr->hProp);
231 if (lpProp == NULL) {
232 printf("Property List Empty !\n");
233 return 0;
235 if (lpEnumFunc != NULL) return 0;
236 while (TRUE) {
237 printf("EnumProps // lpProp->Atom=%04X !\n", lpProp->Atom);
238 str = (LPSTR)MAKELONG(lpProp->Atom, 0);
239 if (lpProp->PropName != NULL) {
240 printf("EnumProps // lpProp->PropName='%s' !\n", lpProp->PropName);
241 str = lpProp->PropName;
243 #ifdef WINELIB
244 nRet = (*lpEnumFunc)((HWND)hWnd, (WORD)0,
245 (LPSTR)str, (HANDLE)lpProp->hData);
246 #else
247 nRet = CallBack16(lpEnumFunc, 4, (HANDLE)lpProp->hData,
248 (LPSTR)str, (WORD)0, (HWND)hWnd);
249 #endif
250 if (nRet == 0) break;
251 if (lpProp->lpNextProp == NULL) break;
252 lpProp = lpProp->lpNextProp;
254 GlobalUnlock(wndPtr->hProp);
255 return 0;