source: trunk/src/gdi32/objhandle.cpp@ 4755

Last change on this file since 4755 was 4755, checked in by sandervl, 25 years ago

handle management update

File size: 8.9 KB
Line 
1/* $Id: objhandle.cpp,v 1.7 2000-12-05 13:04:06 sandervl Exp $ */
2/*
3 * Win32 Handle Management Code for OS/2
4 *
5 *
6 * Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * TODO: The table should be dynamically increased when necessary
10 * This is just a quick and dirty implementation
11 *
12 * Project Odin Software License can be found in LICENSE.TXT
13 *
14 */
15
16#include <os2win.h>
17#include <stdlib.h>
18#include <string.h>
19#include <vmutex.h>
20#include <objhandle.h>
21#include <dcdata.h>
22#include <winuser32.h>
23#include "oslibgpi.h"
24#include "dibsect.h"
25#include "region.h"
26
27#define DBG_LOCALLOG DBG_objhandle
28#include "dbglocal.h"
29
30//******************************************************************************
31
32typedef struct {
33 ULONG dwUserData;
34 ObjectType type;
35} GdiObject;
36
37static GdiObject objHandleTable[MAX_OBJECT_HANDLES] = {0};
38static ULONG lowestFreeIndex = 0;
39static VMutex objTableMutex;
40
41//******************************************************************************
42//******************************************************************************
43BOOL ObjAllocateHandle(HANDLE *hObject, DWORD dwUserData, ObjectType type)
44{
45 objTableMutex.enter(VMUTEX_WAIT_FOREVER);
46 if(lowestFreeIndex == -1) {
47 //oops, out of handles
48 objTableMutex.leave();
49 dprintf(("ERROR: GDI: HwAllocateWindowHandle OUT OF GDI OBJECT HANDLES!!"));
50 DebugInt3();
51 return FALSE;
52 }
53 *hObject = lowestFreeIndex;
54 *hObject |= MAKE_HANDLE(type);
55 objHandleTable[lowestFreeIndex].dwUserData = dwUserData;
56 objHandleTable[lowestFreeIndex].type = type;
57
58 lowestFreeIndex = -1;
59
60 //find next free handle
61 for(int i=0;i<MAX_OBJECT_HANDLES;i++) {
62 if(objHandleTable[i].dwUserData == 0) {
63 lowestFreeIndex = i;
64 break;
65 }
66 }
67 objTableMutex.leave();
68 return TRUE;
69}
70//******************************************************************************
71//******************************************************************************
72void ObjFreeHandle(HANDLE hObject)
73{
74 hObject &= OBJHANDLE_MAGIC_MASK;
75 if(hObject < MAX_OBJECT_HANDLES) {
76 objTableMutex.enter(VMUTEX_WAIT_FOREVER);
77 objHandleTable[hObject].dwUserData = 0;
78 objHandleTable[hObject].type = GDIOBJ_NONE;
79 if(lowestFreeIndex == -1 || hObject < lowestFreeIndex)
80 lowestFreeIndex = hObject;
81
82 objTableMutex.leave();
83 }
84}
85//******************************************************************************
86//******************************************************************************
87DWORD ObjGetHandleData(HANDLE hObject, ObjectType type)
88{
89 hObject &= OBJHANDLE_MAGIC_MASK;
90 if(hObject < MAX_OBJECT_HANDLES && type == objHandleTable[hObject].type) {
91 return objHandleTable[hObject].dwUserData;
92 }
93 return HANDLE_OBJ_ERROR;
94}
95//******************************************************************************
96//******************************************************************************
97ObjectType ObjGetHandleType(HANDLE hObject)
98{
99 hObject &= OBJHANDLE_MAGIC_MASK;
100 if(hObject < MAX_OBJECT_HANDLES && objHandleTable[hObject].dwUserData != 0) {
101 return objHandleTable[hObject].type;
102 }
103 return GDIOBJ_NONE;
104}
105//******************************************************************************
106//******************************************************************************
107int WIN32API GetObjectA( HGDIOBJ hObject, int size, void *lpBuffer)
108{
109 int rc;
110
111 dprintf(("GDI32: GetObject %X %X %X\n", hObject, size, lpBuffer));
112 if(lpBuffer == NULL)
113 { //return required size if buffer pointer == NULL
114 int objtype = GetObjectType(hObject);
115 switch(objtype)
116 {
117 case OBJ_PEN:
118 return sizeof(LOGPEN);
119
120 case OBJ_EXTPEN:
121 return sizeof(EXTLOGPEN);
122
123 case OBJ_BRUSH:
124 return sizeof(LOGBRUSH);
125
126 case OBJ_PAL:
127 return sizeof(USHORT);
128
129 case OBJ_FONT:
130 return sizeof(LOGFONTA);
131
132 case OBJ_BITMAP:
133 return sizeof(BITMAP); //also default for dib sections??? (TODO: NEED TO CHECK THIS)
134
135 case OBJ_DC:
136 case OBJ_METADC:
137 case OBJ_REGION:
138 case OBJ_METAFILE:
139 case OBJ_MEMDC:
140 case OBJ_ENHMETADC:
141 case OBJ_ENHMETAFILE:
142 dprintf(("warning: GetObjectA not defined for object type %d", objtype));
143 return 0;
144 }
145 }
146 if(DIBSection::getSection() != NULL)
147 {
148 DIBSection *dsect = DIBSection::find(hObject);
149 if(dsect)
150 {
151 rc = dsect->GetDIBSection(size, lpBuffer);
152 if(rc == 0) {
153 SetLastError(ERROR_INVALID_PARAMETER);
154 return 0;
155 }
156 SetLastError(ERROR_SUCCESS);
157 return rc;
158 }
159 }
160
161 return O32_GetObject(hObject, size, lpBuffer);
162}
163//******************************************************************************
164//******************************************************************************
165int WIN32API GetObjectW( HGDIOBJ hObject, int size, void *lpBuffer)
166{
167 int ret, objtype;
168
169 dprintf(("GDI32: GetObjectW %X, %d %X", hObject, size, lpBuffer));
170 objtype = GetObjectType(hObject);
171
172 switch(objtype)
173 {
174 case OBJ_FONT:
175 {
176 LOGFONTA logfonta;
177
178 if(lpBuffer == NULL) {
179 return sizeof(LOGFONTW); //return required size if buffer pointer == NULL
180 }
181 ret = GetObjectA(hObject, sizeof(logfonta), (void *)&logfonta);
182 if(ret == sizeof(logfonta))
183 {
184 LOGFONTW *logfontw = (LOGFONTW *)lpBuffer;
185
186 if(size < sizeof(LOGFONTW)) {
187 dprintf(("GDI32: GetObjectW : buffer not big enough for LOGFONTW struct!!")); //is the correct? or copy only part?
188 return 0;
189 }
190 memcpy(logfontw, &logfonta, sizeof(LOGFONTA));
191 memset(logfontw->lfFaceName, 0, LF_FACESIZE);
192 AsciiToUnicodeN(logfonta.lfFaceName, logfontw->lfFaceName, LF_FACESIZE-1);
193
194 return sizeof(LOGFONTW);
195 }
196 return 0;
197 }
198 default:
199 return GetObjectA(hObject, size, lpBuffer);
200 }
201}
202//******************************************************************************
203//******************************************************************************
204HGDIOBJ WIN32API SelectObject(HDC hdc, HGDIOBJ hObj)
205{
206 HGDIOBJ rc;
207
208 dprintf2(("GDI32: SelectObject %x %x", hdc, hObj));
209
210 if(ObjGetHandleType(hObj) == GDIOBJ_REGION) {
211 //Return complexity here; not previously selected clip region
212 return (HGDIOBJ)SelectClipRgn(hdc, hObj);
213 }
214
215 if(DIBSection::getSection() != NULL)
216 {
217 DIBSection *dsect;
218
219 dsect = DIBSection::find(hdc);
220 if(dsect)
221 {
222 //remove previously selected dibsection
223 dsect->UnSelectDIBObject();
224 }
225 dsect = DIBSection::find((DWORD)hObj);
226 if(dsect)
227 {
228 dsect->SelectDIBObject(hdc);
229 }
230 }
231 rc = O32_SelectObject(hdc, hObj);
232 if(rc != 0 && DIBSection::getSection != NULL)
233 {
234 DIBSection *dsect = DIBSection::find((DWORD)rc);
235 if(dsect)
236 {
237 dsect->UnSelectDIBObject();
238 }
239 }
240#ifdef USING_OPEN32
241 if(O32_GetObjectType(hObj) == OBJ_BITMAP)
242 {
243 //SvL: Open32 messes up the height of the hdc (for windows)
244 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
245 if(pHps && pHps->hwnd) {
246 dprintf2(("change back origin"));
247 selectClientArea(pHps);
248 setPageXForm(pHps);
249 }
250 }
251#endif
252 dprintf2(("GDI32: SelectObject %x %x returned %x", hdc, hObj, rc));
253
254 return(rc);
255}
256//******************************************************************************
257//******************************************************************************
258DWORD WIN32API GetObjectType( HGDIOBJ hObj)
259{
260 dprintf2(("GDI32: GetObjectType\n"));
261 if(ObjGetHandleType(hObj) == GDIOBJ_REGION) {
262 SetLastError(ERROR_SUCCESS);
263 return OBJ_REGION;
264 }
265 return O32_GetObjectType(hObj);
266}
267//******************************************************************************
268//******************************************************************************
269BOOL WIN32API DeleteObject(HANDLE hObj)
270{
271 dprintf(("GDI32: DeleteObject %x", hObj));
272 if(ObjGetHandleType(hObj) == GDIOBJ_REGION) {
273 OSLibDeleteRegion(ObjGetHandleData(hObj, GDIOBJ_REGION));
274 ObjFreeHandle(hObj);
275 SetLastError(ERROR_SUCCESS);
276 return OBJ_REGION;
277 }
278 DIBSection::deleteSection((DWORD)hObj);
279 return O32_DeleteObject(hObj);
280}
281//******************************************************************************
282//******************************************************************************
283BOOL WIN32API SetObjectOwner( HGDIOBJ arg1, int arg2 )
284{
285 // Here is a guess for a undocumented entry
286 dprintf(("WARNING: GDI32: SetObjectOwner - stub (TRUE)\n"));
287 return TRUE;
288}
289//******************************************************************************
290//******************************************************************************
Note: See TracBrowser for help on using the repository browser.