source: trunk/src/user32/win32wndhandle.cpp@ 10367

Last change on this file since 10367 was 10256, checked in by sandervl, 22 years ago

Updates

File size: 4.3 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.18 2003-10-02 10:36:00 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.hmtxLock == 0) {
50 dprintf(("InitializeWindowHandles -> create shared critical section"));
51 DosInitializeCriticalSection(&globalwhandlecritsect, pszWndHandleSemName);
52 }
53 else {
54 dprintf(("InitializeWindowHandles -> access shared critical section"));
55 DosAccessCriticalSection(&globalwhandlecritsect, pszWndHandleSemName);
56 }
57}
58//******************************************************************************
59//******************************************************************************
60void FinalizeWindowHandles()
61{
62 DosDeleteCriticalSection(&globalwhandlecritsect);
63}
64//******************************************************************************
65//******************************************************************************
66BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
67{
68 DosEnterCriticalSection(&globalwhandlecritsect);
69
70 //find next free handle
71 if(lastIndex >= MAX_WINDOW_HANDLES-1) {
72 lastIndex = 0;
73 }
74 for(int i=lastIndex;i<MAX_WINDOW_HANDLES;i++) {
75 if(WindowHandleTable[i] == 0) {
76 lastIndex = i;
77 break;
78 }
79 }
80 if(i == MAX_WINDOW_HANDLES) {
81 //oops, out of handles
82 DosLeaveCriticalSection(&globalwhandlecritsect);
83 dprintf(("ERROR: USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
84 DebugInt3();
85 return FALSE;
86 }
87 *hwnd = lastIndex+1; //we skip handle 0x68000000
88 *hwnd |= WNDHANDLE_MAGIC_HIGHWORD;
89 WindowHandleTable[lastIndex] = dwUserData;
90
91 lastIndex++;
92 DosLeaveCriticalSection(&globalwhandlecritsect);
93 dprintf2(("HwAllocateWindowHandle %x", *hwnd));
94 return TRUE;
95}
96//******************************************************************************
97//******************************************************************************
98void HwFreeWindowHandle(HWND hwnd)
99{
100 hwnd = hwnd - 1; //we skip handle 0x68000000
101 hwnd &= WNDHANDLE_MAGIC_MASK;
102 if(hwnd < MAX_WINDOW_HANDLES) {
103 DosEnterCriticalSection(&globalwhandlecritsect);
104 WindowHandleTable[hwnd] = 0;
105 DosLeaveCriticalSection(&globalwhandlecritsect);
106 }
107 dprintf2(("HwFreeWindowHandle %x", hwnd));
108}
109//******************************************************************************
110//******************************************************************************
111BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
112{
113 hwnd = hwnd - 1; //we skip handle 0x68000000
114 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
115 return FALSE; //unknown window (PM?)
116 }
117 hwnd &= WNDHANDLE_MAGIC_MASK;
118 if(hwnd < MAX_WINDOW_HANDLES) {
119 *pdwUserData = WindowHandleTable[hwnd];
120 return TRUE;
121 }
122 *pdwUserData = 0;
123 return FALSE;
124}
125//******************************************************************************
126//******************************************************************************
Note: See TracBrowser for help on using the repository browser.