mshtml: Don't create element object for document node.
[wine] / dlls / wintab32 / wintab32.c
1 /*
2  * WinTab32 library
3  *
4  * Copyright 2003 CodeWeavers, Aric Stewart
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winerror.h"
28 #include "wintab.h"
29 #include "wintab_internal.h"
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(wintab32);
33
34 HWND hwndDefault = NULL;
35 static const WCHAR
36   WC_TABLETCLASSNAME[] = {'W','i','n','e','T','a','b','l','e','t','C','l','a','s','s',0};
37 CRITICAL_SECTION csTablet;
38
39 int (*pLoadTabletInfo)(HWND hwnddefault) = NULL;
40 int (*pGetCurrentPacket)(LPWTPACKET packet) = NULL;
41 int (*pAttachEventQueueToTablet)(HWND hOwner) = NULL;
42 UINT (*pWTInfoA)(UINT wCategory, UINT nIndex, LPVOID lpOutput) = NULL;
43
44 static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
45                                           LPARAM lParam);
46
47 static VOID TABLET_Register(void)
48 {
49     WNDCLASSW wndClass;
50     ZeroMemory(&wndClass, sizeof(WNDCLASSW));
51     wndClass.style = CS_GLOBALCLASS;
52     wndClass.lpfnWndProc = TABLET_WindowProc;
53     wndClass.cbClsExtra = 0;
54     wndClass.cbWndExtra = 0;
55     wndClass.hCursor = NULL;
56     wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
57     wndClass.lpszClassName = WC_TABLETCLASSNAME;
58     RegisterClassW(&wndClass);
59 }
60
61 static VOID TABLET_Unregister(void)
62 {
63     UnregisterClassW(WC_TABLETCLASSNAME, NULL);
64 }
65
66 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
67 {
68     static const WCHAR name[] = {'T','a','b','l','e','t',0};
69     HMODULE hx11drv;
70
71     TRACE("%p, %x, %p\n",hInstDLL,fdwReason,lpReserved);
72     switch (fdwReason)
73     {
74         case DLL_PROCESS_ATTACH:
75             TRACE("Initialization\n");
76             InitializeCriticalSection(&csTablet);
77             csTablet.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": csTablet");
78             hx11drv = GetModuleHandleA("winex11.drv");
79             if (hx11drv)
80             {
81                 pLoadTabletInfo = (void *)GetProcAddress(hx11drv, "LoadTabletInfo");
82                 pAttachEventQueueToTablet = (void *)GetProcAddress(hx11drv, "AttachEventQueueToTablet");
83                 pGetCurrentPacket = (void *)GetProcAddress(hx11drv, "GetCurrentPacket");
84                 pWTInfoA = (void *)GetProcAddress(hx11drv, "WTInfoA");
85                 TABLET_Register();
86                 hwndDefault = CreateWindowW(WC_TABLETCLASSNAME, name,
87                                 WS_POPUPWINDOW,0,0,0,0,0,0,hInstDLL,0);
88             }
89             else
90                 return FALSE;
91             break;
92         case DLL_PROCESS_DETACH:
93             TRACE("Detaching\n");
94             if (hwndDefault)
95             {
96                 DestroyWindow(hwndDefault);
97                 hwndDefault = 0;
98             }
99             TABLET_Unregister();
100             csTablet.DebugInfo->Spare[0] = 0;
101             DeleteCriticalSection(&csTablet);
102             break;
103     }
104     return TRUE;
105 }
106
107
108 /*
109  * The window proc for the default TABLET window
110  */
111 static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
112                                           LPARAM lParam)
113 {
114     TRACE("Incoming Message 0x%x  (0x%08x, 0x%08x)\n", uMsg, (UINT)wParam,
115            (UINT)lParam);
116
117     switch(uMsg)
118     {
119         case WM_NCCREATE:
120             return TRUE;
121
122         case WT_PACKET:
123             {
124                 WTPACKET packet;
125                 LPOPENCONTEXT handler;
126                 pGetCurrentPacket(&packet);
127                 handler = AddPacketToContextQueue(&packet,(HWND)lParam);
128                 if (handler && handler->context.lcOptions & CXO_MESSAGES)
129                     TABLET_PostTabletMessage(handler, _WT_PACKET(handler->context.lcMsgBase),
130                                 (WPARAM)packet.pkSerialNumber,
131                                 (LPARAM)handler->handle, FALSE);
132                 break;
133             }
134         case WT_PROXIMITY:
135             {
136                 WTPACKET packet;
137                 LPOPENCONTEXT handler;
138                 LPARAM prox;
139                 pGetCurrentPacket(&packet);
140                 handler = AddPacketToContextQueue(&packet,(HWND)lParam);
141                 if (handler)
142                 {
143                     prox = MAKELPARAM( wParam, 1 );
144                     TABLET_PostTabletMessage(handler, WT_PROXIMITY,
145                                         (WPARAM)handler->handle, (LPARAM)prox,
146                                         TRUE);
147                 }
148                 break;
149             }
150     }
151     return 0;
152 }