source: trunk/src/user32/win32wndhandle.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 4.5 KB
RevLine 
[10544]1/* $Id: win32wndhandle.cpp,v 1.20 2004-03-18 13:18:33 sandervl Exp $ */
[2469]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)
[8978]13 * TODO: a linear list might not be the optimal implementation. Look
14 * into using some sort of tree (not important)
[2469]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"
[8656]23#include <custombuild.h>
[2469]24
[2803]25#define DBG_LOCALLOG DBG_win32wndhandle
26#include "dbglocal.h"
27
[2469]28//******************************************************************************
29
[21916]30//
31// Global DLL Data (keep it in sync with globaldata.asm!)
32//
33extern ULONG WindowHandleTable[MAX_WINDOW_HANDLES]; // = {0}
34extern CRITICAL_SECTION_OS2 globalwhandlecritsect; // = {0}
35extern ULONG lastIndex; // = 0
[2469]36
[21916]37//******************************************************************************
38//******************************************************************************
[8656]39
[21916]40static const char *pszWndHandleSemName = WINHANDLE_CRITSECTION_NAME;
41
[2469]42//******************************************************************************
43//******************************************************************************
[8656]44void WIN32API SetCustomWndHandleSemName(LPSTR pszSemName)
45{
46 pszWndHandleSemName = pszSemName;
47}
48//******************************************************************************
49//******************************************************************************
[8202]50void InitializeWindowHandles()
51{
[10544]52 if(globalwhandlecritsect.hevLock == 0) {
[10379]53 dprintf(("InitializeWindowHandles %x -> create shared critical section", &globalwhandlecritsect));
[8202]54 }
55 else {
[10379]56 dprintf(("InitializeWindowHandles %x -> access shared critical section", &globalwhandlecritsect));
[8202]57 }
[10544]58 DosAccessCriticalSection(&globalwhandlecritsect, pszWndHandleSemName);
[8202]59}
60//******************************************************************************
61//******************************************************************************
[10256]62void FinalizeWindowHandles()
63{
64 DosDeleteCriticalSection(&globalwhandlecritsect);
65}
66//******************************************************************************
67//******************************************************************************
[2469]68BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
69{
[8202]70 DosEnterCriticalSection(&globalwhandlecritsect);
[4866]71
72 //find next free handle
73 if(lastIndex >= MAX_WINDOW_HANDLES-1) {
74 lastIndex = 0;
75 }
[21916]76 int i;
77 for(i=lastIndex;i<MAX_WINDOW_HANDLES;i++) {
[4866]78 if(WindowHandleTable[i] == 0) {
79 lastIndex = i;
80 break;
81 }
82 }
83 if(i == MAX_WINDOW_HANDLES) {
[2469]84 //oops, out of handles
[8202]85 DosLeaveCriticalSection(&globalwhandlecritsect);
[4866]86 dprintf(("ERROR: USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
[2469]87 DebugInt3();
88 return FALSE;
89 }
[8626]90 *hwnd = lastIndex+1; //we skip handle 0x68000000
[4866]91 *hwnd |= WNDHANDLE_MAGIC_HIGHWORD;
92 WindowHandleTable[lastIndex] = dwUserData;
[2469]93
[5685]94 lastIndex++;
[8202]95 DosLeaveCriticalSection(&globalwhandlecritsect);
[8210]96 dprintf2(("HwAllocateWindowHandle %x", *hwnd));
[2469]97 return TRUE;
98}
99//******************************************************************************
100//******************************************************************************
101void HwFreeWindowHandle(HWND hwnd)
102{
[8626]103 hwnd = hwnd - 1; //we skip handle 0x68000000
[2469]104 hwnd &= WNDHANDLE_MAGIC_MASK;
105 if(hwnd < MAX_WINDOW_HANDLES) {
[8202]106 DosEnterCriticalSection(&globalwhandlecritsect);
[2469]107 WindowHandleTable[hwnd] = 0;
[8202]108 DosLeaveCriticalSection(&globalwhandlecritsect);
[2469]109 }
[8210]110 dprintf2(("HwFreeWindowHandle %x", hwnd));
[2469]111}
112//******************************************************************************
113//******************************************************************************
114BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
115{
[8626]116 hwnd = hwnd - 1; //we skip handle 0x68000000
[2469]117 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
118 return FALSE; //unknown window (PM?)
119 }
120 hwnd &= WNDHANDLE_MAGIC_MASK;
121 if(hwnd < MAX_WINDOW_HANDLES) {
122 *pdwUserData = WindowHandleTable[hwnd];
123 return TRUE;
124 }
125 *pdwUserData = 0;
126 return FALSE;
127}
128//******************************************************************************
129//******************************************************************************
Note: See TracBrowser for help on using the repository browser.