1 | /* $Id: objhandle.cpp,v 1.3 2000-09-07 22:14:51 phaller 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 | /*****************************************************************************
|
---|
17 | * Includes *
|
---|
18 | *****************************************************************************/
|
---|
19 |
|
---|
20 | #include <odin.h>
|
---|
21 | #include <odinwrap.h>
|
---|
22 | #include <os2sel.h>
|
---|
23 |
|
---|
24 |
|
---|
25 | #include <os2win.h>
|
---|
26 | #include <vmutex.h>
|
---|
27 | #include <objhandle.h>
|
---|
28 | #include "dibsect.h"
|
---|
29 | #include "region.h"
|
---|
30 |
|
---|
31 | #define DBG_LOCALLOG DBG_objhandle
|
---|
32 | #include "dbglocal.h"
|
---|
33 |
|
---|
34 | //******************************************************************************
|
---|
35 |
|
---|
36 | /*****************************************************************************
|
---|
37 | * Defines *
|
---|
38 | *****************************************************************************/
|
---|
39 |
|
---|
40 | ODINDEBUGCHANNEL(GDI32-REGION)
|
---|
41 |
|
---|
42 |
|
---|
43 | static ULONG objHandleTable[MAX_OBJECT_HANDLES] = {0};
|
---|
44 | static ULONG lowestFreeIndex = 0;
|
---|
45 | static VMutex objTableMutex;
|
---|
46 |
|
---|
47 | //******************************************************************************
|
---|
48 | //******************************************************************************
|
---|
49 | BOOL ObjAllocateHandle(HANDLE *hObject, DWORD dwUserData, ObjectType type)
|
---|
50 | {
|
---|
51 | objTableMutex.enter(VMUTEX_WAIT_FOREVER);
|
---|
52 | if(lowestFreeIndex == -1) {
|
---|
53 | //oops, out of handles
|
---|
54 | dprintf(("ERROR: GDI: HwAllocateWindowHandle OUT OF GDI OBJECT HANDLES!!"));
|
---|
55 | objTableMutex.leave();
|
---|
56 | DebugInt3();
|
---|
57 | return FALSE;
|
---|
58 | }
|
---|
59 | *hObject = lowestFreeIndex;
|
---|
60 | *hObject |= MAKE_HANDLE(type);
|
---|
61 | objHandleTable[lowestFreeIndex] = dwUserData;
|
---|
62 |
|
---|
63 | lowestFreeIndex = -1;
|
---|
64 |
|
---|
65 | //find next free handle
|
---|
66 | for(int i=0;i<MAX_OBJECT_HANDLES;i++) {
|
---|
67 | if(objHandleTable[i] == 0) {
|
---|
68 | lowestFreeIndex = i;
|
---|
69 | break;
|
---|
70 | }
|
---|
71 | }
|
---|
72 | objTableMutex.leave();
|
---|
73 | return TRUE;
|
---|
74 | }
|
---|
75 | //******************************************************************************
|
---|
76 | //******************************************************************************
|
---|
77 | void ObjFreeHandle(HANDLE hObject)
|
---|
78 | {
|
---|
79 | hObject &= OBJHANDLE_MAGIC_MASK;
|
---|
80 | if(hObject < MAX_OBJECT_HANDLES) {
|
---|
81 | objTableMutex.enter(VMUTEX_WAIT_FOREVER);
|
---|
82 | objHandleTable[hObject] = 0;
|
---|
83 | if(lowestFreeIndex == -1 || hObject < lowestFreeIndex)
|
---|
84 | lowestFreeIndex = hObject;
|
---|
85 |
|
---|
86 | objTableMutex.leave();
|
---|
87 | }
|
---|
88 | }
|
---|
89 | //******************************************************************************
|
---|
90 | //******************************************************************************
|
---|
91 | DWORD ObjGetHandleData(HANDLE hObject)
|
---|
92 | {
|
---|
93 | switch(GET_OBJTYPE(hObject))
|
---|
94 | {
|
---|
95 | case GDIOBJ_REGION:
|
---|
96 | break;
|
---|
97 | //case GDIOBJ_BITMAP
|
---|
98 | //case GDIOBJ_BRUSH
|
---|
99 | //case GDIOBJ_PALETTE
|
---|
100 | //case GDIOBJ_FONT
|
---|
101 | default:
|
---|
102 | return HANDLE_OBJ_ERROR;
|
---|
103 | }
|
---|
104 |
|
---|
105 | hObject &= OBJHANDLE_MAGIC_MASK;
|
---|
106 | if(hObject < MAX_OBJECT_HANDLES) {
|
---|
107 | return objHandleTable[hObject];
|
---|
108 | }
|
---|
109 | return HANDLE_OBJ_ERROR;
|
---|
110 | }
|
---|
111 | //******************************************************************************
|
---|
112 | //******************************************************************************
|
---|
113 | ObjectType ObjGetHandleType(HANDLE hObject)
|
---|
114 | {
|
---|
115 | switch(GET_OBJTYPE(hObject))
|
---|
116 | {
|
---|
117 | case GDIOBJ_REGION:
|
---|
118 | return GDIOBJ_REGION;
|
---|
119 | //case GDIOBJ_BITMAP
|
---|
120 | //case GDIOBJ_BRUSH
|
---|
121 | //case GDIOBJ_PALETTE
|
---|
122 | //case GDIOBJ_FONT
|
---|
123 | default:
|
---|
124 | return GDIOBJ_ERROR;
|
---|
125 | }
|
---|
126 | }
|
---|
127 | //******************************************************************************
|
---|
128 | //******************************************************************************
|
---|
129 | int WIN32API GetObjectA( HGDIOBJ hObject, int size, void *lpBuffer)
|
---|
130 | {
|
---|
131 | int rc;
|
---|
132 |
|
---|
133 | if(size == 0 || lpBuffer == NULL) {
|
---|
134 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
135 | return 0;
|
---|
136 | }
|
---|
137 |
|
---|
138 | if(ObjGetHandleType(hObject) == GDIOBJ_REGION) {
|
---|
139 | SetLastError(ERROR_SUCCESS);
|
---|
140 | return 0;
|
---|
141 | }
|
---|
142 | dprintf(("GDI32: GetObject %X %X %X\n", hObject, size, lpBuffer));
|
---|
143 | if(DIBSection::getSection() != NULL)
|
---|
144 | {
|
---|
145 | DIBSection *dsect = DIBSection::find(hObject);
|
---|
146 | if(dsect)
|
---|
147 | {
|
---|
148 | rc = dsect->GetDIBSection(size, lpBuffer);
|
---|
149 | if(rc == 0) {
|
---|
150 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
151 | return 0;
|
---|
152 | }
|
---|
153 | SetLastError(ERROR_SUCCESS);
|
---|
154 | return rc;
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | return O32_GetObject(hObject, size, lpBuffer);
|
---|
159 | }
|
---|
160 | //******************************************************************************
|
---|
161 | //******************************************************************************
|
---|
162 | int WIN32API GetObjectW( HGDIOBJ arg1, int arg2, void * arg3)
|
---|
163 | {
|
---|
164 | dprintf(("GDI32: GetObjectW %X, %d %X not complete!", arg1, arg2, arg3));
|
---|
165 | return GetObjectA(arg1, arg2, arg3);
|
---|
166 | }
|
---|
167 | //******************************************************************************
|
---|
168 | //******************************************************************************
|
---|
169 | HGDIOBJ WIN32API SelectObject(HDC hdc, HGDIOBJ hObj)
|
---|
170 | {
|
---|
171 | HGDIOBJ rc;
|
---|
172 |
|
---|
173 | dprintf2(("GDI32: SelectObject %x %x", hdc, hObj));
|
---|
174 |
|
---|
175 | if(ObjGetHandleType(hObj) == GDIOBJ_REGION) {
|
---|
176 | //Return complexity here; not previously selected clip region
|
---|
177 | return (HGDIOBJ)SelectClipRgn(hdc, hObj);
|
---|
178 | }
|
---|
179 |
|
---|
180 | if(DIBSection::getSection() != NULL)
|
---|
181 | {
|
---|
182 | DIBSection *dsect;
|
---|
183 |
|
---|
184 | dsect = DIBSection::find(hdc);
|
---|
185 | if(dsect)
|
---|
186 | {
|
---|
187 | //remove previously selected dibsection
|
---|
188 | dsect->UnSelectDIBObject();
|
---|
189 | }
|
---|
190 | dsect = DIBSection::find((DWORD)hObj);
|
---|
191 | if(dsect)
|
---|
192 | {
|
---|
193 | dsect->SelectDIBObject(hdc);
|
---|
194 | }
|
---|
195 | }
|
---|
196 | rc = O32_SelectObject(hdc, hObj);
|
---|
197 | if(rc != 0 && DIBSection::getSection != NULL)
|
---|
198 | {
|
---|
199 | DIBSection *dsect = DIBSection::find((DWORD)rc);
|
---|
200 | if(dsect)
|
---|
201 | {
|
---|
202 | dsect->UnSelectDIBObject();
|
---|
203 | }
|
---|
204 | }
|
---|
205 | return(rc);
|
---|
206 | }
|
---|
207 | //******************************************************************************
|
---|
208 | //******************************************************************************
|
---|
209 | DWORD WIN32API GetObjectType( HGDIOBJ hObj)
|
---|
210 | {
|
---|
211 | dprintf2(("GDI32: GetObjectType\n"));
|
---|
212 | if(ObjGetHandleType(hObj) == GDIOBJ_REGION) {
|
---|
213 | SetLastError(ERROR_SUCCESS);
|
---|
214 | return OBJ_REGION;
|
---|
215 | }
|
---|
216 | return O32_GetObjectType(hObj);
|
---|
217 | }
|
---|
218 | //******************************************************************************
|
---|
219 | //******************************************************************************
|
---|
220 | ODINFUNCTION1(BOOL, DeleteObject,
|
---|
221 | HANDLE, hObj)
|
---|
222 | {
|
---|
223 | if(ObjGetHandleType(hObj) == GDIOBJ_REGION)
|
---|
224 | {
|
---|
225 | OSLibDeleteRegion(ObjGetHandleData(hObj));
|
---|
226 | ObjFreeHandle(hObj);
|
---|
227 | SetLastError(ERROR_SUCCESS);
|
---|
228 | return OBJ_REGION;
|
---|
229 | }
|
---|
230 | DIBSection::deleteSection((DWORD)hObj);
|
---|
231 | return O32_DeleteObject(hObj);
|
---|
232 | }
|
---|
233 | //******************************************************************************
|
---|
234 | //******************************************************************************
|
---|
235 | BOOL WIN32API SetObjectOwner( HGDIOBJ arg1, int arg2 )
|
---|
236 | {
|
---|
237 | // Here is a guess for a undocumented entry
|
---|
238 | dprintf(("WARNING: GDI32: SetObjectOwner - stub (TRUE)\n"));
|
---|
239 | return TRUE;
|
---|
240 | }
|
---|
241 | //******************************************************************************
|
---|
242 | //******************************************************************************
|
---|