ddraw/tests: Add basic tests for DrawIndexedPrimitiveStrided.
[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 static CRITICAL_SECTION_DEBUG csTablet_debug =
38 {
39     0, 0, &csTablet,
40     { &csTablet_debug.ProcessLocksList, &csTablet_debug.ProcessLocksList },
41       0, 0, { (DWORD_PTR)(__FILE__ ": csTablet") }
42 };
43 CRITICAL_SECTION csTablet = { &csTablet_debug, -1, 0, 0, 0, 0 };
44
45 int  (CDECL *pLoadTabletInfo)(HWND hwnddefault) = NULL;
46 int  (CDECL *pGetCurrentPacket)(LPWTPACKET packet) = NULL;
47 int  (CDECL *pAttachEventQueueToTablet)(HWND hOwner) = NULL;
48 UINT (CDECL *pWTInfoW)(UINT wCategory, UINT nIndex, LPVOID lpOutput) = NULL;
49
50 static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
51                                           LPARAM lParam);
52
53 static VOID TABLET_Register(void)
54 {
55     WNDCLASSW wndClass;
56     ZeroMemory(&wndClass, sizeof(WNDCLASSW));
57     wndClass.style = CS_GLOBALCLASS;
58     wndClass.lpfnWndProc = TABLET_WindowProc;
59     wndClass.cbClsExtra = 0;
60     wndClass.cbWndExtra = 0;
61     wndClass.hCursor = NULL;
62     wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
63     wndClass.lpszClassName = WC_TABLETCLASSNAME;
64     RegisterClassW(&wndClass);
65 }
66
67 static VOID TABLET_Unregister(void)
68 {
69     UnregisterClassW(WC_TABLETCLASSNAME, NULL);
70 }
71
72 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
73 {
74     static const WCHAR name[] = {'T','a','b','l','e','t',0};
75     HMODULE hx11drv;
76
77     TRACE("%p, %x, %p\n",hInstDLL,fdwReason,lpReserved);
78     switch (fdwReason)
79     {
80         case DLL_PROCESS_ATTACH:
81             TRACE("Initialization\n");
82             DisableThreadLibraryCalls(hInstDLL);
83             hx11drv = GetModuleHandleA("winex11.drv");
84             if (hx11drv)
85             {
86                 pLoadTabletInfo = (void *)GetProcAddress(hx11drv, "LoadTabletInfo");
87                 pAttachEventQueueToTablet = (void *)GetProcAddress(hx11drv, "AttachEventQueueToTablet");
88                 pGetCurrentPacket = (void *)GetProcAddress(hx11drv, "GetCurrentPacket");
89                 pWTInfoW = (void *)GetProcAddress(hx11drv, "WTInfoW");
90                 TABLET_Register();
91                 hwndDefault = CreateWindowW(WC_TABLETCLASSNAME, name,
92                                 WS_POPUPWINDOW,0,0,0,0,0,0,hInstDLL,0);
93             }
94             else
95                 return FALSE;
96             break;
97         case DLL_PROCESS_DETACH:
98             TRACE("Detaching\n");
99             if (hwndDefault)
100             {
101                 DestroyWindow(hwndDefault);
102                 hwndDefault = 0;
103             }
104             TABLET_Unregister();
105             DeleteCriticalSection(&csTablet);
106             break;
107     }
108     return TRUE;
109 }
110
111
112 /*
113  * The window proc for the default TABLET window
114  */
115 static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
116                                           LPARAM lParam)
117 {
118     TRACE("Incoming Message 0x%x  (0x%08x, 0x%08x)\n", uMsg, (UINT)wParam,
119            (UINT)lParam);
120
121     switch(uMsg)
122     {
123         case WM_NCCREATE:
124             return TRUE;
125
126         case WT_PACKET:
127             {
128                 WTPACKET packet;
129                 LPOPENCONTEXT handler;
130                 if (pGetCurrentPacket)
131                 {
132                     pGetCurrentPacket(&packet);
133                     handler = AddPacketToContextQueue(&packet,(HWND)lParam);
134                     if (handler && handler->context.lcOptions & CXO_MESSAGES)
135                        TABLET_PostTabletMessage(handler, _WT_PACKET(handler->context.lcMsgBase),
136                                    (WPARAM)packet.pkSerialNumber,
137                                    (LPARAM)handler->handle, FALSE);
138                 }
139                 break;
140             }
141         case WT_PROXIMITY:
142             {
143                 WTPACKET packet;
144                 LPOPENCONTEXT handler;
145                 if (pGetCurrentPacket)
146                 {
147                     pGetCurrentPacket(&packet);
148                     handler = AddPacketToContextQueue(&packet,(HWND)wParam);
149                     if (handler)
150                         TABLET_PostTabletMessage(handler, WT_PROXIMITY,
151                                                 (WPARAM)handler->handle, lParam, TRUE);
152                 }
153                 break;
154             }
155     }
156     return 0;
157 }