source: trunk/src/kernel32/atom.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 11.4 KB
RevLine 
[10251]1/* $Id: atom.cpp,v 1.13 2003-09-18 14:21:07 sandervl Exp $ */
[100]2
[4]3/*
4 * Win32 ATOM api functions
5 *
[6199]6 * Copyright 1998-2001 Sander van Leeuwen (sandervl@xs4all.nl)
[4]7 *
8 *
[6199]9 * TODO: DeleteAtom doesn't appear to work properly. FindAtom still works
10 * after deleting it.
11 *
[4]12 * Project Odin Software License can be found in LICENSE.TXT
13 *
14 */
[6199]15#define INCL_WIN
16#include <os2wrap.h>
17#include <win32api.h>
18#include <winconst.h>
19#include <unicode.h>
[3512]20#include <heapstring.h>
[6199]21#include <misc.h>
[4]22
[21916]23#ifdef __GNUC__
24#include <alloca.h>
25#endif
26
[10251]27#define DBG_LOCALLOG DBG_atom
[2802]28#include "dbglocal.h"
29
[6199]30// action codes for LookupAtom
31#define LOOKUP_FIND 0
32#define LOOKUP_ADD 1
33#define LOOKUP_DELETE 2
34#define LOOKUP_NOCASE 0x80000000
35
[21916]36extern "C" {
37
[6199]38ATOM APIENTRY LookupAtom(HATOMTBL hAtomTbl, PSZ psz, ULONG actionMask);
39
[6249]40inline ATOM _LookupAtom(HATOMTBL hAtomTbl, PSZ psz, ULONG actionMask)
41{
42 ATOM yyrc;
43 USHORT sel = RestoreOS2FS();
44
45 yyrc = LookupAtom(hAtomTbl, psz, actionMask);
46 SetFS(sel);
47
48 return yyrc;
49}
50
51#undef LookupAtom
52#define LookupAtom _LookupAtom
53
54
[6199]55HATOMTBL privateAtomTable = NULL;
56HATOMTBL systemAtomTable = NULL;
[4]57//******************************************************************************
58//******************************************************************************
[6199]59HATOMTBL inline getPrivateAtomTable()
[4]60{
[6199]61 if(privateAtomTable == NULL) {
[10251]62 privateAtomTable = WinCreateAtomTable(0, 37);
[6199]63 }
64 return privateAtomTable;
[4]65}
66//******************************************************************************
67//******************************************************************************
[6199]68HATOMTBL inline getSystemAtomTable()
[4]69{
[6199]70 if(systemAtomTable == NULL) {
[10251]71 systemAtomTable = WinQuerySystemAtomTable();
[6199]72 }
73 return systemAtomTable;
74}
75//******************************************************************************
76//******************************************************************************
77BOOL WIN32API InitAtomTable(DWORD numEntries)
78{
79 dprintf(("KERNEL32: InitAtomTable %d", numEntries));
[4]80
[6199]81 if(privateAtomTable == NULL) {
82 privateAtomTable = WinCreateAtomTable(0, numEntries);
83 }
84 return (privateAtomTable != NULL);
85}
86//******************************************************************************
87//******************************************************************************
88ATOM WIN32API FindAtomA( LPCSTR atomName)
[10251]89{
[6199]90 HATOMTBL atomTable = getPrivateAtomTable();
91 ATOM atom = 0;
[10251]92
[6199]93 if(HIWORD(atomName)) {
94 dprintf(("FindAtomA %s", atomName));
95 }
96 else dprintf(("FindAtomA %x", atomName));
97
98 if(atomTable != NULL) {
[10251]99 atom = LookupAtom(atomTable, HIWORD(atomName) ?
[6309]100 (PSZ) atomName : (PSZ) (LOWORD(atomName) | 0xFFFF0000),
101 LOOKUP_FIND | LOOKUP_NOCASE);
[6199]102 }
103 dprintf(("FindAtomA returned %x", atom));
104
105 if(!atom) {
106 SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: find real error
107 }
108 else SetLastError(ERROR_SUCCESS_W);
109 return atom;
110}
111//******************************************************************************
112//******************************************************************************
113ATOM WIN32API FindAtomW(LPCWSTR atomName)
114{
115 ATOM rc;
116 char *astring;
117
118 dprintf(("KERNEL32: FindAtomW"));
119 if(HIWORD(atomName))
[1275]120 {
[6199]121 astring = UnicodeToAsciiString((LPWSTR)atomName);
122 rc = FindAtomA(astring);
123 FreeAsciiString(astring);
[1275]124 }
[6199]125 else rc = FindAtomA((char*)atomName);
126
[4]127 return(rc);
128}
129//******************************************************************************
130//******************************************************************************
[6199]131ATOM WIN32API AddAtomA(LPCSTR atomName)
[4]132{
[6199]133 ATOM atom = 0;
134 HATOMTBL atomTable = getPrivateAtomTable();
[3512]135
[6199]136 if(atomTable != NULL)
137 {
[10251]138 atom = LookupAtom(atomTable, HIWORD(atomName) ?
[6309]139 (PSZ) atomName : (PSZ) (LOWORD(atomName) | 0xFFFF0000),
[6199]140 LOOKUP_ADD | LOOKUP_NOCASE);
[3512]141 }
[6199]142
143 if(HIWORD(atomName)) {
[10251]144 dprintf(("KERNEL32: AddAtomA %s returned %x", atomName, atom));
[6199]145 }
146 else dprintf(("KERNEL32: AddAtomA %x returned %x", atomName, atom));
147
148 if(!atom) {
149 SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: find real error
150 }
151 else SetLastError(ERROR_SUCCESS_W);
[3512]152 return atom;
[4]153}
154//******************************************************************************
155//******************************************************************************
[6199]156ATOM WIN32API AddAtomW(LPCWSTR atomName)
[4]157{
158 ATOM rc;
159 char *astring;
160
[6199]161 if(HIWORD(atomName) == 0) {
162 rc = AddAtomA((char*)atomName);
[3512]163 }
[1275]164 else
165 {
[6199]166 astring = UnicodeToAsciiString((LPWSTR)atomName);
[3512]167 rc = AddAtomA(astring);
[1275]168 FreeAsciiString(astring);
169 }
[4]170 return(rc);
171}
172//******************************************************************************
173//******************************************************************************
[6199]174UINT WIN32API GetAtomNameA( ATOM atom, LPSTR atomName, int nameLen)
[4]175{
[6199]176 UINT result = 0;
177 HATOMTBL atomTable = getPrivateAtomTable();
178
179 dprintf(("KERNEL32: GetAtomNameA %x %x %d", LOWORD(atom), atomName, nameLen));
180 if(atomTable != NULL)
181 result = (UINT)WinQueryAtomName( atomTable, LOWORD(atom), atomName, nameLen);
182
183 dprintf(("KERNEL32: GetAtomNameA returned %s", (result) ? atomName : NULL));
184
185 if(!result) {
186 SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: find real error
187 }
188 else SetLastError(ERROR_SUCCESS_W);
189 return (result);
[4]190}
191//******************************************************************************
192//******************************************************************************
[6199]193UINT WIN32API GetAtomNameW(ATOM atom, LPWSTR lpszBuffer, int cchBuffer)
[4]194{
195 char *astring;
[6199]196 UINT rc;
[4]197
[6199]198 dprintf(("KERNEL32: GetAtomNameW %x %x %d", atom, lpszBuffer, cchBuffer));
[10251]199 astring = (char *)alloca(cchBuffer * sizeof( WCHAR ));
[6199]200 if(astring == NULL) {
[10251]201 dprintf(("GlobalGetAtomNameW: alloca failed!!"));
202 DebugInt3();
203 return 0;
[6199]204 }
[10251]205 rc = GetAtomNameA(atom, astring, cchBuffer * sizeof( WCHAR ));
[6199]206 if(rc) {
[10251]207 lstrcpynAtoW(lpszBuffer, astring, cchBuffer);
[6199]208 }
209 else lpszBuffer[0] = 0; //necessary?
[10251]210 return lstrlenW( lpszBuffer );
[4]211}
212//******************************************************************************
213//******************************************************************************
[6199]214ATOM WIN32API DeleteAtom(ATOM atom)
[4]215{
[6199]216 HATOMTBL atomTable = getPrivateAtomTable();
217
218 dprintf(("DeleteAtom %x", atom));
219 if (atomTable != NULL) {
220 return (ATOM) LookupAtom(atomTable, (PSZ) MAKEULONG(atom, 0xFFFF),
221 LOOKUP_DELETE | LOOKUP_NOCASE);
222 }
223 return 0;
[4]224}
225//******************************************************************************
226//******************************************************************************
[6199]227ATOM WIN32API GlobalDeleteAtom(ATOM atom)
[4]228{
[6199]229 HATOMTBL atomTable = getSystemAtomTable();
230
231 dprintf(("KERNEL32: GlobalDeleteAtom %x", atom));
232 return (ATOM) LookupAtom(atomTable, (PSZ) MAKEULONG(atom, 0xFFFF),
233 LOOKUP_DELETE | LOOKUP_NOCASE);
[4]234}
235//******************************************************************************
236//******************************************************************************
[6199]237ATOM WIN32API GlobalAddAtomA(LPCSTR atomName)
[4]238{
[6199]239 ATOM atom = 0;
240 HATOMTBL atomTable = getSystemAtomTable();
[3512]241
[6199]242 if(atomTable != NULL)
243 {
[10251]244 atom = LookupAtom(atomTable, HIWORD(atomName) ?
[6309]245 (PSZ) atomName : (PSZ) (LOWORD(atomName) | 0xFFFF0000),
[6199]246 LOOKUP_ADD | LOOKUP_NOCASE);
[3512]247 }
[6199]248
249 if(HIWORD(atomName)) {
[10251]250 dprintf(("KERNEL32: GlobalAddAtomA %s returned %x", atomName, atom));
[6199]251 }
252 else dprintf(("KERNEL32: GlobalAddAtomA %x returned %x", atomName, atom));
253
254 if(!atom) {
255 SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: find real error
256 }
257 else SetLastError(ERROR_SUCCESS_W);
[3512]258 return atom;
[4]259}
260//******************************************************************************
261//******************************************************************************
[6199]262ATOM WIN32API GlobalAddAtomW(LPCWSTR atomName)
[4]263{
264 char *astring;
265 ATOM rc;
266
[6199]267 if(HIWORD(atomName) == 0)
[1275]268 {
[6199]269 rc = GlobalAddAtomA((char*)atomName);
[1275]270 }
271 else
272 {
[6199]273 astring = UnicodeToAsciiString((LPWSTR)atomName);
[3512]274 rc = GlobalAddAtomA(astring);
[1275]275 FreeAsciiString(astring);
276 }
[4]277 return(rc);
278}
279//******************************************************************************
280//******************************************************************************
[6199]281ATOM WIN32API GlobalFindAtomA( LPCSTR atomName)
[4]282{
[6199]283 HATOMTBL atomTable = getSystemAtomTable();
284 ATOM atom = 0;
285
286 if(HIWORD(atomName)) {
[7883]287 dprintf(("KERNEL32: GlobalFindAtomA %s", atomName));
[6199]288 }
[7883]289 else dprintf(("KERNEL32: GlobalFindAtomA %x", atomName));
[6199]290
[10251]291 atom = LookupAtom(atomTable, HIWORD(atomName) ?
[6309]292 (PSZ) atomName : (PSZ) (LOWORD(atomName) | 0xFFFF0000),
293 LOOKUP_FIND | LOOKUP_NOCASE);
[7883]294 dprintf(("KERNEL32: GlobalFindAtomA returned %x", atom));
[6199]295
296 if(!atom) {
297 SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: find real error
298 }
299 else SetLastError(ERROR_SUCCESS_W);
300
301 return atom;
[4]302}
303//******************************************************************************
304//******************************************************************************
[6199]305ATOM WIN32API GlobalFindAtomW(LPCWSTR atomName)
[4]306{
[6199]307 ATOM rc;
[4]308 char *astring;
309
[6199]310 dprintf(("KERNEL32: GlobalFindAtomW"));
311 if(HIWORD(atomName))
[1275]312 {
[6199]313 astring = UnicodeToAsciiString((LPWSTR)atomName);
314 rc = GlobalFindAtomA(astring);
315 FreeAsciiString(astring);
[1275]316 }
[6199]317 else rc = GlobalFindAtomA((char*)atomName);
318
[4]319 return(rc);
320}
321//******************************************************************************
322//******************************************************************************
[3512]323UINT WIN32API GlobalGetAtomNameA(ATOM atom, LPSTR lpszBuffer, int cchBuffer)
[4]324{
[6199]325 UINT result = 0;
326 HATOMTBL atomTable = getSystemAtomTable();
327
328 dprintf(("KERNEL32: GlobalGetAtomNameA %x %x %d", LOWORD(atom), lpszBuffer, cchBuffer));
329 if(atomTable != NULL)
330 result = (UINT)WinQueryAtomName( atomTable, LOWORD(atom), lpszBuffer, cchBuffer);
331
332 if(!result) {
333 SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: find real error
334 }
335 else SetLastError(ERROR_SUCCESS_W);
336
337 dprintf(("KERNEL32: GlobalGetAtomNameA returned %s", (result) ? lpszBuffer : NULL));
338 return (result);
[4]339}
340//******************************************************************************
341//******************************************************************************
[3512]342UINT WIN32API GlobalGetAtomNameW(ATOM atom, LPWSTR lpszBuffer, int cchBuffer)
[4]343{
344 char *astring;
[3512]345 UINT rc;
[4]346
[3512]347 dprintf(("KERNEL32: GlobalGetAtomNameW %x %x %d", atom, lpszBuffer, cchBuffer));
[10251]348 astring = (char *)alloca(cchBuffer * sizeof( WCHAR ));
[3512]349 if(astring == NULL) {
[10251]350 dprintf(("GlobalGetAtomNameW: alloca failed!!"));
351 DebugInt3();
352 return 0;
[3512]353 }
[10251]354 rc = GlobalGetAtomNameA(atom, astring, cchBuffer * sizeof( WCHAR ));
[3512]355 if(rc) {
[10251]356 lstrcpynAtoW(lpszBuffer, astring, cchBuffer);
[3512]357 }
358 else lpszBuffer[0] = 0; //necessary?
[10251]359 return lstrlenW( lpszBuffer );
[4]360}
[3512]361//******************************************************************************
362//******************************************************************************
[21916]363
364} // extern "C"
Note: See TracBrowser for help on using the repository browser.