| 1 | /* $Id: win32wbaseprop.cpp,v 1.1 2000-05-05 11:32:38 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Window properties
|
|---|
| 4 | *
|
|---|
| 5 | * Ported Wine code (win\property.c):
|
|---|
| 6 | * Copyright 1995, 1996 Alexandre Julliard
|
|---|
| 7 | *
|
|---|
| 8 | * TODO: Not thread safe!!
|
|---|
| 9 | *
|
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 11 | *
|
|---|
| 12 | */
|
|---|
| 13 | #include <string.h>
|
|---|
| 14 | #include <user32.h>
|
|---|
| 15 | #include <heapstring.h>
|
|---|
| 16 | #include <misc.h>
|
|---|
| 17 | #include "win32wbase.h"
|
|---|
| 18 |
|
|---|
| 19 | #define DBG_LOCALLOG DBG_win32wbaseprop
|
|---|
| 20 | #include "dbglocal.h"
|
|---|
| 21 |
|
|---|
| 22 | /***********************************************************************
|
|---|
| 23 | * PROP_FindProp
|
|---|
| 24 | */
|
|---|
| 25 | PROPERTY *Win32BaseWindow::findWindowProperty(LPCSTR str)
|
|---|
| 26 | {
|
|---|
| 27 | PROPERTY *prop;
|
|---|
| 28 | ATOM atom;
|
|---|
| 29 |
|
|---|
| 30 | if (HIWORD(str))
|
|---|
| 31 | {
|
|---|
| 32 | atom = GlobalFindAtomA(str);
|
|---|
| 33 | for (prop = propertyList; prop; prop = prop->next)
|
|---|
| 34 | {
|
|---|
| 35 | if (HIWORD(prop->string))
|
|---|
| 36 | {
|
|---|
| 37 | if (!lstrcmpiA( prop->string, str )) goto END;
|
|---|
| 38 | }
|
|---|
| 39 | else if (LOWORD(prop->string) == atom) goto END;
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
| 42 | else /* atom */
|
|---|
| 43 | {
|
|---|
| 44 | atom = LOWORD(str);
|
|---|
| 45 | for (prop = propertyList; (prop); prop = prop->next)
|
|---|
| 46 | {
|
|---|
| 47 | if (HIWORD(prop->string))
|
|---|
| 48 | {
|
|---|
| 49 | if (GlobalFindAtomA( prop->string ) == atom) goto END;
|
|---|
| 50 | }
|
|---|
| 51 | else if (LOWORD(prop->string) == atom) goto END;
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 | if(HIWORD(str)) {
|
|---|
| 55 | dprintf2(("Property %s for window %x NOT FOUND!", str, getWindowHandle()));
|
|---|
| 56 | }
|
|---|
| 57 | else dprintf2(("Property %x for window %x NOT FOUND!", str, getWindowHandle()));
|
|---|
| 58 |
|
|---|
| 59 | prop = NULL;
|
|---|
| 60 | END:
|
|---|
| 61 | return prop;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /***********************************************************************
|
|---|
| 65 | * GetPropA (USER32.281)
|
|---|
| 66 | */
|
|---|
| 67 | HANDLE Win32BaseWindow::getProp(LPCSTR str)
|
|---|
| 68 | {
|
|---|
| 69 | PROPERTY *prop = findWindowProperty(str);
|
|---|
| 70 |
|
|---|
| 71 | if(HIWORD(str)) {
|
|---|
| 72 | dprintf2(("GetProp %x %s %x", getWindowHandle, str, prop ? prop->handle : 0));
|
|---|
| 73 | }
|
|---|
| 74 | else dprintf2(("GetProp %x %x %x", getWindowHandle, str, prop ? prop->handle : 0));
|
|---|
| 75 |
|
|---|
| 76 | return prop ? prop->handle : 0;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | /***********************************************************************
|
|---|
| 80 | * SetPropA (USER32.497)
|
|---|
| 81 | */
|
|---|
| 82 | BOOL Win32BaseWindow::setProp(LPCSTR str, HANDLE handle)
|
|---|
| 83 | {
|
|---|
| 84 | PROPERTY *prop;
|
|---|
| 85 |
|
|---|
| 86 | if (HIWORD(str)) {
|
|---|
| 87 | dprintf2(("SetProp %x %s %x", getWindowHandle, str, handle));
|
|---|
| 88 | }
|
|---|
| 89 | else dprintf2(("SetProp %x %x %x", getWindowHandle, str, handle));
|
|---|
| 90 |
|
|---|
| 91 | if (!(prop = findWindowProperty(str)))
|
|---|
| 92 | {
|
|---|
| 93 | /* We need to create it */
|
|---|
| 94 | if (!(prop = (PROPERTY *)HeapAlloc(GetProcessHeap(), 0, sizeof(*prop) )))
|
|---|
| 95 | {
|
|---|
| 96 | dprintf(("setProp: malloc failed!!"));
|
|---|
| 97 | return FALSE;
|
|---|
| 98 | }
|
|---|
| 99 | if(HIWORD(str))
|
|---|
| 100 | {
|
|---|
| 101 | if (!(prop->string = HEAP_strdupA(GetProcessHeap(), 0, str)))
|
|---|
| 102 | {
|
|---|
| 103 | HeapFree( GetProcessHeap(), 0, prop );
|
|---|
| 104 | return FALSE;
|
|---|
| 105 | }
|
|---|
| 106 | }
|
|---|
| 107 | else prop->string = (char *)str; //atom
|
|---|
| 108 |
|
|---|
| 109 | prop->next = propertyList;
|
|---|
| 110 | propertyList = prop;
|
|---|
| 111 | }
|
|---|
| 112 | prop->handle = handle;
|
|---|
| 113 | return TRUE;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /***********************************************************************
|
|---|
| 117 | * RemovePropA (USER32.442)
|
|---|
| 118 | */
|
|---|
| 119 | HANDLE Win32BaseWindow::removeProp(LPCSTR str)
|
|---|
| 120 | {
|
|---|
| 121 | ATOM atom;
|
|---|
| 122 | HANDLE handle;
|
|---|
| 123 | PROPERTY **pprop, *prop;
|
|---|
| 124 |
|
|---|
| 125 | if (HIWORD(str)) {
|
|---|
| 126 | dprintf2(("RemoveProp %x %s", getWindowHandle(), str ));
|
|---|
| 127 | }
|
|---|
| 128 | else dprintf2(("RemoveProp %x %x", getWindowHandle(), str ));
|
|---|
| 129 |
|
|---|
| 130 | if (HIWORD(str))
|
|---|
| 131 | {
|
|---|
| 132 | atom = GlobalFindAtomA( str );
|
|---|
| 133 | for (pprop=(PROPERTY**)&propertyList; (*pprop); pprop = &(*pprop)->next)
|
|---|
| 134 | {
|
|---|
| 135 | if (HIWORD((*pprop)->string))
|
|---|
| 136 | {
|
|---|
| 137 | if (!lstrcmpiA( (*pprop)->string, str )) break;
|
|---|
| 138 | }
|
|---|
| 139 | else if (LOWORD((*pprop)->string) == atom) break;
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 | else /* atom */
|
|---|
| 143 | {
|
|---|
| 144 | atom = LOWORD(str);
|
|---|
| 145 | for (pprop=(PROPERTY**)&propertyList; (*pprop); pprop = &(*pprop)->next)
|
|---|
| 146 | {
|
|---|
| 147 | if (HIWORD((*pprop)->string))
|
|---|
| 148 | {
|
|---|
| 149 | if (GlobalFindAtomA( (*pprop)->string ) == atom) break;
|
|---|
| 150 | }
|
|---|
| 151 | else if (LOWORD((*pprop)->string) == atom) break;
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 | if (!*pprop) return 0;
|
|---|
| 155 |
|
|---|
| 156 | prop = *pprop;
|
|---|
| 157 | handle = prop->handle;
|
|---|
| 158 | *pprop = prop->next;
|
|---|
| 159 | if(HIWORD(prop->string))
|
|---|
| 160 | HeapFree(GetProcessHeap(), 0, prop->string);
|
|---|
| 161 | HeapFree( GetProcessHeap(), 0, prop );
|
|---|
| 162 | return handle;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | /***********************************************************************
|
|---|
| 166 | * PROPERTY_RemoveWindowProps
|
|---|
| 167 | *
|
|---|
| 168 | * Remove all properties of a window.
|
|---|
| 169 | */
|
|---|
| 170 | void Win32BaseWindow::removeWindowProps()
|
|---|
| 171 | {
|
|---|
| 172 | PROPERTY *prop, *next;
|
|---|
| 173 |
|
|---|
| 174 | for (prop = propertyList; (prop); prop = next)
|
|---|
| 175 | {
|
|---|
| 176 | next = prop->next;
|
|---|
| 177 | if(HIWORD(prop->string))
|
|---|
| 178 | HeapFree(GetProcessHeap(), 0, prop->string);
|
|---|
| 179 | HeapFree(GetProcessHeap(), 0, prop);
|
|---|
| 180 | }
|
|---|
| 181 | propertyList = NULL;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | /***********************************************************************
|
|---|
| 185 | * EnumPropsExA (USER32.187)
|
|---|
| 186 | */
|
|---|
| 187 | INT Win32BaseWindow::enumPropsExA(PROPENUMPROCEXA func, LPARAM lParam)
|
|---|
| 188 | {
|
|---|
| 189 | PROPERTY *prop, *next;
|
|---|
| 190 | INT ret = -1;
|
|---|
| 191 |
|
|---|
| 192 | dprintf(("EnumPropsExA %x %x %x", getWindowHandle, func, lParam));
|
|---|
| 193 |
|
|---|
| 194 | for (prop = propertyList; (prop); prop = next)
|
|---|
| 195 | {
|
|---|
| 196 | /* Already get the next in case the callback */
|
|---|
| 197 | /* function removes the current property. */
|
|---|
| 198 | next = prop->next;
|
|---|
| 199 |
|
|---|
| 200 | if(HIWORD(prop->string)) {
|
|---|
| 201 | dprintf2(("EnumPropsExA: Callback: handle=%08x str=%s", prop->handle, prop->string));
|
|---|
| 202 | }
|
|---|
| 203 | else dprintf2(("EnumPropsExA: Callback: handle=%08x str=%x", prop->handle, prop->string));
|
|---|
| 204 |
|
|---|
| 205 | ret = func( getWindowHandle(), prop->string, prop->handle, lParam );
|
|---|
| 206 | if (!ret) break;
|
|---|
| 207 | }
|
|---|
| 208 | return ret;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 | /***********************************************************************
|
|---|
| 213 | * EnumPropsExW (USER32.188)
|
|---|
| 214 | */
|
|---|
| 215 | INT Win32BaseWindow::enumPropsExW(PROPENUMPROCEXW func, LPARAM lParam)
|
|---|
| 216 | {
|
|---|
| 217 | PROPERTY *prop, *next;
|
|---|
| 218 | INT ret = -1;
|
|---|
| 219 |
|
|---|
| 220 | dprintf(("EnumPropsExW %x %x %x", getWindowHandle, func, lParam));
|
|---|
| 221 |
|
|---|
| 222 | for (prop = propertyList; (prop); prop = next)
|
|---|
| 223 | {
|
|---|
| 224 | /* Already get the next in case the callback */
|
|---|
| 225 | /* function removes the current property. */
|
|---|
| 226 | next = prop->next;
|
|---|
| 227 |
|
|---|
| 228 | if(HIWORD(prop->string)) {
|
|---|
| 229 | dprintf2(("EnumPropsExW: Callback: handle=%08x str=%s", prop->handle, prop->string));
|
|---|
| 230 | }
|
|---|
| 231 | else dprintf2(("EnumPropsExW: Callback: handle=%08x str=%x", prop->handle, prop->string));
|
|---|
| 232 |
|
|---|
| 233 | if (HIWORD(prop->string))
|
|---|
| 234 | {
|
|---|
| 235 | LPWSTR str = HEAP_strdupAtoW( GetProcessHeap(), 0, prop->string );
|
|---|
| 236 | ret = func( getWindowHandle(), str, prop->handle, lParam );
|
|---|
| 237 | HeapFree( GetProcessHeap(), 0, str );
|
|---|
| 238 | }
|
|---|
| 239 | else
|
|---|
| 240 | ret = func( getWindowHandle(), (LPCWSTR)(UINT)LOWORD( prop->string ),
|
|---|
| 241 | prop->handle, lParam );
|
|---|
| 242 | if (!ret) break;
|
|---|
| 243 | }
|
|---|
| 244 | return ret;
|
|---|
| 245 | }
|
|---|
| 246 | //******************************************************************************
|
|---|
| 247 | //******************************************************************************
|
|---|