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