4 * Copyright 2003 CodeWeavers, Aric Stewart
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.
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.
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
31 #include "wintab_internal.h"
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wintab32
);
37 HWND hwndDefault
= NULL
;
39 WC_TABLETCLASSNAME
[] = {'W','i','n','e','T','a','b','l','e','t','C','l','a','s','s',0};
40 static CRITICAL_SECTION_DEBUG csTablet_debug
=
43 { &csTablet_debug
.ProcessLocksList
, &csTablet_debug
.ProcessLocksList
},
44 0, 0, { (DWORD_PTR
)(__FILE__
": csTablet") }
46 CRITICAL_SECTION csTablet
= { &csTablet_debug
, -1, 0, 0, 0, 0 };
48 int (CDECL
*pLoadTabletInfo
)(HWND hwnddefault
) = NULL
;
49 int (CDECL
*pGetCurrentPacket
)(LPWTPACKET packet
) = NULL
;
50 int (CDECL
*pAttachEventQueueToTablet
)(HWND hOwner
) = NULL
;
51 UINT (CDECL
*pWTInfoW
)(UINT wCategory
, UINT nIndex
, LPVOID lpOutput
) = NULL
;
53 static LRESULT WINAPI
TABLET_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
,
56 static VOID
TABLET_Register(void)
59 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
60 wndClass
.style
= CS_GLOBALCLASS
;
61 wndClass
.lpfnWndProc
= TABLET_WindowProc
;
62 wndClass
.cbClsExtra
= 0;
63 wndClass
.cbWndExtra
= 0;
64 wndClass
.hCursor
= NULL
;
65 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
66 wndClass
.lpszClassName
= WC_TABLETCLASSNAME
;
67 RegisterClassW(&wndClass
);
70 static VOID
TABLET_Unregister(void)
72 UnregisterClassW(WC_TABLETCLASSNAME
, NULL
);
75 static HMODULE
load_graphics_driver(void)
77 static const WCHAR display_device_guid_propW
[] = {
78 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
79 'd','e','v','i','c','e','_','g','u','i','d',0 };
80 static const WCHAR key_pathW
[] = {
81 'S','y','s','t','e','m','\\',
82 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
83 'C','o','n','t','r','o','l','\\',
84 'V','i','d','e','o','\\','{',0};
85 static const WCHAR displayW
[] = {'}','\\','0','0','0','0',0};
86 static const WCHAR driverW
[] = {'G','r','a','p','h','i','c','s','D','r','i','v','e','r',0};
92 WCHAR key
[(sizeof(key_pathW
) + sizeof(displayW
)) / sizeof(WCHAR
) + 40];
93 UINT guid_atom
= HandleToULong( GetPropW( GetDesktopWindow(), display_device_guid_propW
));
95 if (!guid_atom
) return 0;
96 memcpy( key
, key_pathW
, sizeof(key_pathW
) );
97 if (!GlobalGetAtomNameW( guid_atom
, key
+ strlenW(key
), 40 )) return 0;
98 strcatW( key
, displayW
);
99 if (RegOpenKeyW( HKEY_LOCAL_MACHINE
, key
, &hkey
)) return 0;
101 if (!RegQueryValueExW( hkey
, driverW
, NULL
, NULL
, (BYTE
*)path
, &size
)) ret
= LoadLibraryW( path
);
103 TRACE( "%s %p\n", debugstr_w(path
), ret
);
107 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
109 static const WCHAR name
[] = {'T','a','b','l','e','t',0};
111 TRACE("%p, %x, %p\n",hInstDLL
,fdwReason
,lpReserved
);
114 case DLL_PROCESS_ATTACH
:
115 TRACE("Initialization\n");
116 DisableThreadLibraryCalls(hInstDLL
);
118 hwndDefault
= CreateWindowW(WC_TABLETCLASSNAME
, name
,
119 WS_POPUPWINDOW
,0,0,0,0,0,0,hInstDLL
,0);
122 HMODULE module
= load_graphics_driver();
123 pLoadTabletInfo
= (void *)GetProcAddress(module
, "LoadTabletInfo");
124 pAttachEventQueueToTablet
= (void *)GetProcAddress(module
, "AttachEventQueueToTablet");
125 pGetCurrentPacket
= (void *)GetProcAddress(module
, "GetCurrentPacket");
126 pWTInfoW
= (void *)GetProcAddress(module
, "WTInfoW");
131 case DLL_PROCESS_DETACH
:
132 if (lpReserved
) break;
133 TRACE("Detaching\n");
134 if (hwndDefault
) DestroyWindow(hwndDefault
);
136 DeleteCriticalSection(&csTablet
);
144 * The window proc for the default TABLET window
146 static LRESULT WINAPI
TABLET_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
,
149 TRACE("Incoming Message 0x%x (0x%08x, 0x%08x)\n", uMsg
, (UINT
)wParam
,
160 LPOPENCONTEXT handler
;
161 if (pGetCurrentPacket
)
163 pGetCurrentPacket(&packet
);
164 handler
= AddPacketToContextQueue(&packet
,(HWND
)lParam
);
165 if (handler
&& handler
->context
.lcOptions
& CXO_MESSAGES
)
166 TABLET_PostTabletMessage(handler
, _WT_PACKET(handler
->context
.lcMsgBase
),
167 (WPARAM
)packet
.pkSerialNumber
,
168 (LPARAM
)handler
->handle
, FALSE
);
175 LPOPENCONTEXT handler
;
176 if (pGetCurrentPacket
)
178 pGetCurrentPacket(&packet
);
179 handler
= AddPacketToContextQueue(&packet
,(HWND
)wParam
);
181 TABLET_PostTabletMessage(handler
, WT_PROXIMITY
,
182 (WPARAM
)handler
->handle
, lParam
, TRUE
);