makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / wintab32 / wintab32.c
blob98ce2bc17393d2de3f49dfaf2a47f080db221b12
1 /*
2 * WinTab32 library
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winreg.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winerror.h"
29 #define NOFIX32
30 #include "wintab.h"
31 #include "wintab_internal.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(wintab32);
36 HWND hwndDefault = NULL;
37 static const WCHAR
38 WC_TABLETCLASSNAME[] = {'W','i','n','e','T','a','b','l','e','t','C','l','a','s','s',0};
39 static CRITICAL_SECTION_DEBUG csTablet_debug =
41 0, 0, &csTablet,
42 { &csTablet_debug.ProcessLocksList, &csTablet_debug.ProcessLocksList },
43 0, 0, { (DWORD_PTR)(__FILE__ ": csTablet") }
45 CRITICAL_SECTION csTablet = { &csTablet_debug, -1, 0, 0, 0, 0 };
47 int (CDECL *pLoadTabletInfo)(HWND hwnddefault) = NULL;
48 int (CDECL *pGetCurrentPacket)(LPWTPACKET packet) = NULL;
49 int (CDECL *pAttachEventQueueToTablet)(HWND hOwner) = NULL;
50 UINT (CDECL *pWTInfoW)(UINT wCategory, UINT nIndex, LPVOID lpOutput) = NULL;
52 static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
53 LPARAM lParam);
55 static VOID TABLET_Register(void)
57 WNDCLASSW wndClass;
58 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
59 wndClass.style = CS_GLOBALCLASS;
60 wndClass.lpfnWndProc = TABLET_WindowProc;
61 wndClass.cbClsExtra = 0;
62 wndClass.cbWndExtra = 0;
63 wndClass.hCursor = NULL;
64 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
65 wndClass.lpszClassName = WC_TABLETCLASSNAME;
66 RegisterClassW(&wndClass);
69 static VOID TABLET_Unregister(void)
71 UnregisterClassW(WC_TABLETCLASSNAME, NULL);
74 static HMODULE load_graphics_driver(void)
76 static const WCHAR display_device_guid_propW[] = {
77 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
78 'd','e','v','i','c','e','_','g','u','i','d',0 };
79 static const WCHAR key_pathW[] = {
80 'S','y','s','t','e','m','\\',
81 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
82 'C','o','n','t','r','o','l','\\',
83 'V','i','d','e','o','\\','{',0};
84 static const WCHAR displayW[] = {'}','\\','0','0','0','0',0};
85 static const WCHAR driverW[] = {'G','r','a','p','h','i','c','s','D','r','i','v','e','r',0};
87 HMODULE ret = 0;
88 HKEY hkey;
89 DWORD size;
90 WCHAR path[MAX_PATH];
91 WCHAR key[ARRAY_SIZE(key_pathW) + ARRAY_SIZE(displayW) + 40];
92 UINT guid_atom = HandleToULong( GetPropW( GetDesktopWindow(), display_device_guid_propW ));
94 if (!guid_atom) return 0;
95 memcpy( key, key_pathW, sizeof(key_pathW) );
96 if (!GlobalGetAtomNameW( guid_atom, key + lstrlenW(key), 40 )) return 0;
97 lstrcatW( key, displayW );
98 if (RegOpenKeyW( HKEY_LOCAL_MACHINE, key, &hkey )) return 0;
99 size = sizeof(path);
100 if (!RegQueryValueExW( hkey, driverW, NULL, NULL, (BYTE *)path, &size )) ret = LoadLibraryW( path );
101 RegCloseKey( hkey );
102 TRACE( "%s %p\n", debugstr_w(path), ret );
103 return ret;
106 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
108 static const WCHAR name[] = {'T','a','b','l','e','t',0};
110 TRACE("%p, %x, %p\n",hInstDLL,fdwReason,lpReserved);
111 switch (fdwReason)
113 case DLL_PROCESS_ATTACH:
114 TRACE("Initialization\n");
115 DisableThreadLibraryCalls(hInstDLL);
116 TABLET_Register();
117 hwndDefault = CreateWindowW(WC_TABLETCLASSNAME, name,
118 WS_POPUPWINDOW,0,0,0,0,0,0,hInstDLL,0);
119 if (hwndDefault)
121 HMODULE module = load_graphics_driver();
122 pLoadTabletInfo = (void *)GetProcAddress(module, "LoadTabletInfo");
123 pAttachEventQueueToTablet = (void *)GetProcAddress(module, "AttachEventQueueToTablet");
124 pGetCurrentPacket = (void *)GetProcAddress(module, "GetCurrentPacket");
125 pWTInfoW = (void *)GetProcAddress(module, "WTInfoW");
127 else
128 return FALSE;
129 break;
130 case DLL_PROCESS_DETACH:
131 if (lpReserved) break;
132 TRACE("Detaching\n");
133 if (hwndDefault) DestroyWindow(hwndDefault);
134 TABLET_Unregister();
135 DeleteCriticalSection(&csTablet);
136 break;
138 return TRUE;
143 * The window proc for the default TABLET window
145 static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
146 LPARAM lParam)
148 TRACE("Incoming Message 0x%x (0x%08x, 0x%08x)\n", uMsg, (UINT)wParam,
149 (UINT)lParam);
151 switch(uMsg)
153 case WM_NCCREATE:
154 return TRUE;
156 case WT_PACKET:
158 WTPACKET packet;
159 LPOPENCONTEXT handler;
160 if (pGetCurrentPacket)
162 pGetCurrentPacket(&packet);
163 handler = AddPacketToContextQueue(&packet,(HWND)lParam);
164 if (handler && handler->context.lcOptions & CXO_MESSAGES)
165 TABLET_PostTabletMessage(handler, _WT_PACKET(handler->context.lcMsgBase),
166 (WPARAM)packet.pkSerialNumber,
167 (LPARAM)handler->handle, FALSE);
169 break;
171 case WT_PROXIMITY:
173 WTPACKET packet;
174 LPOPENCONTEXT handler;
175 if (pGetCurrentPacket)
177 pGetCurrentPacket(&packet);
178 handler = AddPacketToContextQueue(&packet,(HWND)wParam);
179 if (handler)
180 TABLET_PostTabletMessage(handler, WT_PROXIMITY,
181 (WPARAM)handler->handle, lParam, TRUE);
183 break;
186 return 0;