source: branches/gcc-kmk/src/user32/win32wndhandle.cpp@ 21687

Last change on this file since 21687 was 10544, checked in by sandervl, 21 years ago

update

File size: 4.3 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.20 2004-03-18 13:18:33 sandervl Exp $ */
2/*
3 * Win32 Handle Management Code for OS/2
4 *
5 *
6 * Copyright 1998 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 * TODO: Probably need to clean up the table when app closes
12 * (also store PID and remove all handles with PID of terminating app)
13 * TODO: a linear list might not be the optimal implementation. Look
14 * into using some sort of tree (not important)
15 *
16 * Project Odin Software License can be found in LICENSE.TXT
17 *
18 */
19
20#include <os2win.h>
21#include <vmutex.h>
22#include "win32wndhandle.h"
23#include <custombuild.h>
24
25#define DBG_LOCALLOG DBG_win32wndhandle
26#include "dbglocal.h"
27
28//******************************************************************************
29
30//Global DLL Data
31#pragma data_seg(_GLOBALDATA)
32ULONG WindowHandleTable[MAX_WINDOW_HANDLES] = {0};
33CRITICAL_SECTION_OS2 globalwhandlecritsect = {0};
34ULONG lastIndex = 0;
35#pragma data_seg()
36
37static char *pszWndHandleSemName = WINHANDLE_CRITSECTION_NAME;
38
39//******************************************************************************
40//******************************************************************************
41void WIN32API SetCustomWndHandleSemName(LPSTR pszSemName)
42{
43 pszWndHandleSemName = pszSemName;
44}
45//******************************************************************************
46//******************************************************************************
47void InitializeWindowHandles()
48{
49 if(globalwhandlecritsect.hevLock == 0) {
50 dprintf(("InitializeWindowHandles %x -> create shared critical section", &globalwhandlecritsect));
51 }
52 else {
53 dprintf(("InitializeWindowHandles %x -> access shared critical section", &globalwhandlecritsect));
54 }
55 DosAccessCriticalSection(&globalwhandlecritsect, pszWndHandleSemName);
56}
57//******************************************************************************
58//******************************************************************************
59void FinalizeWindowHandles()
60{
61 DosDeleteCriticalSection(&globalwhandlecritsect);
62}
63//******************************************************************************
64//******************************************************************************
65BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
66{
67 DosEnterCriticalSection(&globalwhandlecritsect);
68
69 //find next free handle
70 if(lastIndex >= MAX_WINDOW_HANDLES-1) {
71 lastIndex = 0;
72 }
73 for(int i=lastIndex;i<MAX_WINDOW_HANDLES;i++) {
74 if(WindowHandleTable[i] == 0) {
75 lastIndex = i;
76 break;
77 }
78 }
79 if(i == MAX_WINDOW_HANDLES) {
80 //oops, out of handles
81 DosLeaveCriticalSection(&globalwhandlecritsect);
82 dprintf(("ERROR: USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
83 DebugInt3();
84 return FALSE;
85 }
86 *hwnd = lastIndex+1; //we skip handle 0x68000000
87 *hwnd |= WNDHANDLE_MAGIC_HIGHWORD;
88 WindowHandleTable[lastIndex] = dwUserData;
89
90 lastIndex++;
91 DosLeaveCriticalSection(&globalwhandlecritsect);
92 dprintf2(("HwAllocateWindowHandle %x", *hwnd));
93 return TRUE;
94}
95//******************************************************************************
96//******************************************************************************
97void HwFreeWindowHandle(HWND hwnd)
98{
99 hwnd = hwnd - 1; //we skip handle 0x68000000
100 hwnd &= WNDHANDLE_MAGIC_MASK;
101 if(hwnd < MAX_WINDOW_HANDLES) {
102 DosEnterCriticalSection(&globalwhandlecritsect);
103 WindowHandleTable[hwnd] = 0;
104 DosLeaveCriticalSection(&globalwhandlecritsect);
105 }
106 dprintf2(("HwFreeWindowHandle %x", hwnd));
107}
108//******************************************************************************
109//******************************************************************************
110BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
111{
112 hwnd = hwnd - 1; //we skip handle 0x68000000
113 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
114 return FALSE; //unknown window (PM?)
115 }
116 hwnd &= WNDHANDLE_MAGIC_MASK;
117 if(hwnd < MAX_WINDOW_HANDLES) {
118 *pdwUserData = WindowHandleTable[hwnd];
119 return TRUE;
120 }
121 *pdwUserData = 0;
122 return FALSE;
123}
124//******************************************************************************
125//******************************************************************************
Note: See TracBrowser for help on using the repository browser.