Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

691 lines
15 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. tabsrv.h
  5. Abstract:
  6. This module contains private definitions of the TabletPC Listener
  7. Service.
  8. Author:
  9. Michael Tsang (MikeTs) 01-Jun-2000
  10. Environment:
  11. User mode
  12. Revision History:
  13. --*/
  14. #ifndef _TABSRV_H
  15. #define _TABSRV_H
  16. //
  17. // Constants
  18. //
  19. #define STR_TABSRV_NAME MODNAME
  20. #define STR_REGPATH_TABSRVPARAM "System\\CurrentControlSet\\Services\\TabSrv\\Parameters";
  21. #define STR_LINEARITY_MAP "LinearityMap"
  22. // gdwfTabSrv flags
  23. #define TSF_RPCTHREAD 0x00000001
  24. #define TSF_SUPERTIPTHREAD 0x00000002
  25. #define TSF_DIGITHREAD 0x00000004
  26. #define TSF_MOUSETHREAD 0x00000008
  27. #define TSF_BUTTONTHREAD 0x00000010
  28. #define TSF_ALLTHREAD (TSF_RPCTHREAD | \
  29. TSF_SUPERTIPTHREAD | \
  30. TSF_DIGITHREAD | \
  31. TSF_MOUSETHREAD | \
  32. TSF_BUTTONTHREAD)
  33. #define TSF_TERMINATE 0x00000020
  34. #define TSF_HAS_LINEAR_MAP 0x00000040
  35. #define TSF_PORTRAIT_MODE 0x00000080
  36. #define TSF_SUPERTIP_MINIMIZED_BEFORE 0x00000100
  37. #define TSF_SUPERTIP_OPENED 0x00000200
  38. #define TSF_SUPERTIP_SENDINK 0x00000400
  39. #define TSF_TASKBAR_CREATED 0x00000800
  40. #define TSF_TRAYICON_CREATED 0x00001000
  41. #define TSF_PORTRAIT_MODE2 0x40000000
  42. #define TSF_DEBUG_MODE 0x80000000
  43. // dwfThread flags
  44. #define THREADF_ENABLED 0x00000001
  45. #define THREADF_RESTARTABLE 0x00000002
  46. #define THREADF_SDT_POSTMSG 0x00000004
  47. #define THREADF_SDT_SETEVENT 0x00000008
  48. #define THREADF_DESKTOP_WINLOGON 0x00000010
  49. // HID USAGE DIGITIZER defines (BUGBUG: move to ddk\inc\hidusage.h someday?)
  50. #define HID_USAGE_DIGITIZER_PEN ((USAGE)0x02)
  51. #define HID_USAGE_DIGITIZER_IN_RANGE ((USAGE)0x32)
  52. #define HID_USAGE_DIGITIZER_TIP_SWITCH ((USAGE)0x42)
  53. #define HID_USAGE_DIGITIZER_BARREL_SWITCH ((USAGE)0x44)
  54. #define HID_USAGE_CONSUMERCTRL ((USAGE)0x01)
  55. // gdwPenState values
  56. #define PENSTATE_NORMAL 0x00000000
  57. #define PENSTATE_PENDOWN 0x00000001
  58. #define PENSTATE_LEFTUP_PENDING 0x00000002
  59. #define PENSTATE_PRESSHOLD 0x00000003
  60. #define PENSTATE_RIGHTDRAG 0x00000004
  61. #define MAX_RESTARTS 5
  62. #define MAX_NORMALIZED_X 65535
  63. #define MAX_NORMALIZED_Y 65535
  64. #define NUM_PIXELS_LONG 1024
  65. #define NUM_PIXELS_SHORT 768
  66. #define TIMERID_PRESSHOLD 1
  67. #define TIMEOUT_LEFTCLICK 20 //20 msec.
  68. #define TIMEOUT_BALLOON_TIP (10*1000) //10 sec.
  69. // Button constants
  70. #define BUTTONSTATE_BUTTON_1 0x00000004
  71. #define BUTTONSTATE_BUTTON_2 0x00000002
  72. #define BUTTONSTATE_BUTTON_3 0x00000001
  73. #define BUTTONSTATE_BUTTON_4 0x00000010
  74. #define BUTTONSTATE_BUTTON_5 0x00000008
  75. #define BUTTONSTATE_DEFHOTKEY (BUTTONSTATE_BUTTON_1 | BUTTONSTATE_BUTTON_5)
  76. // Gesture related constants
  77. #define WM_GESTURE (WM_APP)
  78. #define WM_SUPERTIP_NOTIFY (WM_APP + 1)
  79. #define WM_SUPERTIP_INIT (WM_APP + 2)
  80. #define TIP_SWITCH (1) // bit flag in wButtonState
  81. #define BARREL_SWITCH (2) // bit flag in wButtonState
  82. #define DEF_RADIUS 200 // The pen must have been outside sqrt(Radius) for a while
  83. #define DEF_MINOUTPTS 6
  84. #define DEF_MAXTIMETOINSPECT 800
  85. #define DEF_ASPECTRATIO 3
  86. #define DEF_CHECKTIME 400
  87. #define DEF_PTSTOEXAMINE 4
  88. #define DEF_STOPDIST 50 // The pen is considered stopped if all points during the last STOPTIME ms
  89. // are within this distance of the current point.
  90. #define DEF_STOPTIME 200
  91. #define DEF_PRESSHOLD_TIME 500
  92. #define DEF_HOLD_TOLERANCE 3
  93. //
  94. // Macros
  95. //
  96. #define InitializeListHead(lh) ((lh)->Flink = (lh)->Blink = (lh))
  97. #define IsListEmpty(lh) ((lh)->Flink == (lh))
  98. #define RemoveHeadList(lh) (lh)->Flink; \
  99. {RemoveEntryList((lh)->Flink)}
  100. #define RemoveEntryList(e) { \
  101. (e)->Blink->Flink = (e)->Flink; \
  102. (e)->Flink->Blink = (e)->Blink; \
  103. }
  104. #define InsertTailList(lh,e) { \
  105. (e)->Flink = (lh); \
  106. (e)->Blink = (lh)->Blink; \
  107. (lh)->Blink->Flink = (e); \
  108. (lh)->Blink = (e); \
  109. }
  110. #define SET_SERVICE_STATUS(s) if (ghServStatus) { \
  111. gServStatus.dwCurrentState = s; \
  112. SetServiceStatus(ghServStatus, \
  113. &gServStatus); \
  114. }
  115. #define TABSRVERR(p) { \
  116. TRACEERROR(p); \
  117. TabSrvLogError p; \
  118. }
  119. #define SWAPBUTTONS(c,e1,e2) (((c) == 0)? (e1): (e2))
  120. #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
  121. #define SCREEN_TO_NORMAL_X(x) ((((x) - glVirtualDesktopLeft)* \
  122. (MAX_NORMALIZED_X + 1) + \
  123. (MAX_NORMALIZED_X + 1)/2)/ \
  124. gcxScreen)
  125. #define SCREEN_TO_NORMAL_Y(y) ((((y) - glVirtualDesktopTop)* \
  126. (MAX_NORMALIZED_Y + 1) + \
  127. (MAX_NORMALIZED_Y + 1) /2)/ \
  128. gcyScreen)
  129. #define NORMAL_TO_SCREEN_X(x) (((x)*gcxScreen + gcxScreen/2)/ \
  130. (MAX_NORMALIZED_X + 1) + \
  131. glVirtualDesktopLeft)
  132. #define NORMAL_TO_SCREEN_Y(y) (((y)*gcyScreen + gcyScreen/2)/ \
  133. (MAX_NORMALIZED_Y + 1) + \
  134. glVirtualDesktopTop)
  135. //
  136. // Type definitions
  137. //
  138. typedef struct _PEN_TILT
  139. {
  140. LONG dx;
  141. LONG dy;
  142. } PEN_TILT, *PPEN_TILT;
  143. typedef struct _CONFIG
  144. {
  145. GESTURE_SETTINGS GestureSettings;
  146. PEN_TILT PenTilt;
  147. LINEAR_MAP LinearityMap;
  148. BUTTON_SETTINGS ButtonSettings;
  149. } CONFIG, *PCONFIG;
  150. typedef unsigned (__stdcall *PFNTHREAD)(void *);
  151. typedef struct _TSTHREAD
  152. {
  153. PFNTHREAD pfnThread;
  154. PSZ pszThreadName;
  155. DWORD dwThreadTag;
  156. DWORD dwfThread;
  157. DWORD dwcRestartTries;
  158. PVOID pvSDTParam;
  159. HANDLE hThread;
  160. int iThreadStatus;
  161. PVOID pvParam;
  162. } TSTHREAD, *PTSTHREAD;
  163. typedef struct _DEVICE_DATA
  164. {
  165. USAGE UsagePage;
  166. USAGE Usage;
  167. HANDLE hStopDeviceEvent;
  168. HANDLE hDevice;
  169. ULONG dwcButtons;
  170. PUSAGE pDownButtonUsages;
  171. PHIDP_PREPARSED_DATA pPreParsedData;
  172. HIDP_CAPS hidCaps;
  173. } DEVICE_DATA, *PDEVICE_DATA;
  174. typedef struct _DIGITIZER_DATA
  175. {
  176. WORD wButtonState;
  177. WORD wX;
  178. WORD wY;
  179. DWORD dwTime;
  180. } DIGITIZER_DATA, *PDIGITIZER_DATA;
  181. typedef struct _DIGIRECT
  182. {
  183. USHORT wx0;
  184. USHORT wy0;
  185. USHORT wx1;
  186. USHORT wy1;
  187. } DIGIRECT, *PDIGIRECT;
  188. typedef struct _NOTIFYCLIENT
  189. {
  190. DWORD dwSig;
  191. LIST_ENTRY list;
  192. EVTNOTIFY Event;
  193. HWND hwnd;
  194. UINT uiMsg;
  195. } NOTIFYCLIENT, *PNOTIFYCLIENT;
  196. #define SIG_NOTIFYCLIENT 'tnlC'
  197. //
  198. // Global data
  199. //
  200. extern HMODULE ghMod;
  201. extern DWORD gdwfTabSrv;
  202. extern LIST_ENTRY glistNotifyClients;
  203. extern HANDLE ghDesktopSwitchEvent;
  204. extern HANDLE ghmutNotifyList;
  205. extern HANDLE ghHotkeyEvent;
  206. extern HANDLE ghRefreshEvent;
  207. extern HANDLE ghRPCServerThread;
  208. extern HWND ghwndSuperTIP;
  209. extern HWND ghwndMouse;
  210. extern HWND ghwndSuperTIPInk;
  211. extern HCURSOR ghcurPressHold;
  212. extern HCURSOR ghcurNormal;
  213. extern UINT guimsgSuperTIPInk;
  214. #ifdef DRAW_INK
  215. extern HWND ghwndDrawInk;
  216. #endif
  217. extern ISuperTip *gpISuperTip;
  218. extern ITellMe *gpITellMe;
  219. extern int gcxScreen, gcyScreen;
  220. extern int gcxPrimary, gcyPrimary;
  221. extern LONG glVirtualDesktopLeft,
  222. glVirtualDesktopRight,
  223. glVirtualDesktopTop,
  224. glVirtualDesktopBottom;
  225. extern LONG glLongOffset, glShortOffset;
  226. extern int giButtonsSwapped;
  227. extern ULONG gdwMinX, gdwMaxX, gdwRngX;
  228. extern ULONG gdwMinY, gdwMaxY, gdwRngY;
  229. extern int gixIndex, giyIndex;
  230. extern INPUT gInput;
  231. extern DWORD gdwPenState;
  232. extern DWORD gdwPenDownTime;
  233. extern LONG glPenDownX;
  234. extern LONG glPenDownY;
  235. extern DWORD gdwPenUpTime;
  236. extern LONG glPenUpX;
  237. extern LONG glPenUpY;
  238. extern WORD gwLastButtons;
  239. extern CONFIG gConfig;
  240. extern TSTHREAD gTabSrvThreads[];
  241. extern TCHAR gtszTabSrvTitle[];
  242. extern TCHAR gtszTabSrvName[];
  243. extern TCHAR gtszGestureSettings[];
  244. extern TCHAR gtszButtonSettings[];
  245. extern TCHAR gtszPenTilt[];
  246. extern TCHAR gtszLinearityMap[];
  247. extern TCHAR gtszRegPath[];
  248. extern TCHAR gtszInputDesktop[];
  249. extern SERVICE_STATUS_HANDLE ghServStatus;
  250. extern SERVICE_STATUS gServStatus;
  251. extern DIGITIZER_DATA gLastRawDigiReport;
  252. extern DEVICE_DATA gdevDigitizer;
  253. extern DEVICE_DATA gdevButtons;
  254. #ifdef DEBUG
  255. extern NAMETABLE ServiceControlNames[];
  256. extern NAMETABLE ConsoleControlNames[];
  257. #endif
  258. //
  259. // Function prototypes
  260. //
  261. // tabsrv.cpp
  262. VOID
  263. InstallTabSrv(
  264. VOID
  265. );
  266. VOID
  267. SetTabSrvConfig(
  268. IN SC_HANDLE hService
  269. );
  270. VOID
  271. RemoveTabSrv(
  272. VOID
  273. );
  274. VOID
  275. StartTabSrv(
  276. VOID
  277. );
  278. VOID
  279. StopTabSrv(
  280. VOID
  281. );
  282. VOID WINAPI
  283. TabSrvServiceHandler(
  284. IN DWORD dwControl
  285. );
  286. #ifdef ALLOW_DEBUG
  287. BOOL WINAPI
  288. TabSrvConsoleHandler(
  289. IN DWORD dwControl
  290. );
  291. #endif
  292. VOID WINAPI
  293. TabSrvMain(
  294. IN DWORD icArgs,
  295. IN LPTSTR *aptszArgs
  296. );
  297. VOID
  298. InitConfigFromReg(
  299. VOID
  300. );
  301. BOOL
  302. InitThreads(
  303. IN PTSTHREAD pThreads,
  304. IN int nThreads
  305. );
  306. PTSTHREAD
  307. FindThread(
  308. IN DWORD dwThreadTag
  309. );
  310. VOID
  311. WaitForTermination(
  312. VOID
  313. );
  314. VOID
  315. TabSrvTerminate(
  316. IN BOOL fTerminate
  317. );
  318. VOID
  319. TabSrvLogError(
  320. IN LPTSTR ptszFormat,
  321. ...
  322. );
  323. LONG
  324. ReadConfig(
  325. IN LPCTSTR lptstrValueName,
  326. OUT LPBYTE lpbData,
  327. IN DWORD dwcb
  328. );
  329. LONG
  330. WriteConfig(
  331. IN LPCTSTR lptstrValueName,
  332. IN DWORD dwType,
  333. IN LPBYTE lpbData,
  334. IN DWORD dwcb
  335. );
  336. LONG
  337. GetRegValueString(
  338. IN HKEY hkeyTopLevel,
  339. IN LPCTSTR pszSubKey,
  340. IN LPCTSTR pszValueName,
  341. OUT LPTSTR pszValueString,
  342. IN OUT LPDWORD lpdwcb
  343. );
  344. BOOL
  345. SwitchThreadToInputDesktop(
  346. IN PTSTHREAD pThread
  347. );
  348. BOOL
  349. GetInputDesktopName(
  350. OUT LPTSTR pszDesktopName,
  351. IN DWORD dwcbLen
  352. );
  353. BOOL
  354. SendAltCtrlDel(
  355. VOID
  356. );
  357. VOID
  358. NotifyClient(
  359. IN EVTNOTIFY Event,
  360. IN WPARAM wParam,
  361. IN LPARAM lParam
  362. );
  363. BOOL
  364. ImpersonateCurrentUser(
  365. VOID
  366. );
  367. BOOL
  368. RunProcessAsUser(
  369. IN LPTSTR pszCmd
  370. );
  371. // tabdev.cpp
  372. unsigned __stdcall
  373. DeviceThread(
  374. IN PVOID param
  375. );
  376. BOOL
  377. OpenTabletDevice(
  378. IN OUT PDEVICE_DATA pDevData
  379. );
  380. VOID
  381. CloseTabletDevice(
  382. IN PDEVICE_DATA pDevData
  383. );
  384. PSP_DEVICE_INTERFACE_DETAIL_DATA
  385. GetDeviceInterfaceDetail(
  386. IN HDEVINFO hDevInfo,
  387. IN PSP_DEVICE_INTERFACE_DATA pDevInterface
  388. );
  389. BOOL
  390. GetDeviceData(
  391. IN LPCTSTR pszDevPath,
  392. OUT PDEVICE_DATA pDevData
  393. );
  394. BOOL
  395. ReadReportOverlapped(
  396. IN PDEVICE_DATA pDevData,
  397. OUT LPVOID lpvBuffer,
  398. OUT LPDWORD lpdwcBytesRead,
  399. IN LPOVERLAPPED lpOverlapped
  400. );
  401. // digidev.cpp
  402. BOOL
  403. GetMinMax(
  404. IN USAGE UsagePage,
  405. IN USAGE Usage,
  406. OUT PULONG pulMin,
  407. OUT PULONG pulMax
  408. );
  409. VOID
  410. ProcessDigitizerReport(
  411. IN PCHAR pBuff
  412. );
  413. VOID
  414. AdjustLinearity(
  415. IN OUT PUSHORT pwX,
  416. IN OUT PUSHORT pwY
  417. );
  418. LRESULT
  419. ProcessMouseEvent(
  420. IN LONG x,
  421. IN LONG y,
  422. IN WORD wButtons,
  423. IN DWORD dwTime,
  424. IN BOOL fLowLevelMouse
  425. );
  426. VOID
  427. PressHoldMode(
  428. IN BOOL fEnable
  429. );
  430. VOID
  431. SetPressHoldCursor(
  432. IN BOOL fPressHold
  433. );
  434. LPTSTR
  435. MakeFileName(
  436. IN OUT LPTSTR pszFile
  437. );
  438. BOOL
  439. CanDoPressHold(
  440. IN LONG x,
  441. IN LONG y
  442. );
  443. // buttons.cpp
  444. VOID
  445. ProcessButtonsReport(
  446. IN PCHAR pBuff
  447. );
  448. VOID
  449. CALLBACK
  450. ButtonTimerProc(
  451. IN HWND hwnd,
  452. IN UINT uMsg,
  453. IN UINT_PTR idEvent,
  454. IN DWORD dwTime
  455. );
  456. BOOL
  457. DoButtonAction(
  458. IN BUTTON_ACTION Action,
  459. IN DWORD dwButtonTag,
  460. IN BOOL fButtonDown
  461. );
  462. BOOL
  463. DoInvokeNoteBook(
  464. VOID
  465. );
  466. VOID
  467. UpdateButtonRepeatRate(
  468. VOID
  469. );
  470. #ifdef MOUSE_THREAD
  471. // mouse.cpp
  472. unsigned __stdcall
  473. MouseThread(
  474. IN PVOID param
  475. );
  476. VOID
  477. DoLowLevelMouse(
  478. IN PTSTHREAD pThread
  479. );
  480. LRESULT CALLBACK
  481. LowLevelMouseProc(
  482. IN int nCode,
  483. IN WPARAM wParam,
  484. IN LPARAM lParam
  485. );
  486. LRESULT CALLBACK
  487. MouseWndProc(
  488. IN HWND hwnd,
  489. IN UINT uiMsg,
  490. IN WPARAM wParam,
  491. IN LPARAM lParam
  492. );
  493. #endif
  494. // butdev.cpp
  495. unsigned __stdcall
  496. ButtonsThread(
  497. PVOID param
  498. );
  499. // gesture.cpp
  500. int
  501. RecognizeGesture(
  502. IN LONG x,
  503. IN LONG y,
  504. IN WORD wButtons,
  505. IN DWORD dwTime,
  506. IN BOOL fLowLevelMouse
  507. );
  508. int
  509. Recognize(
  510. IN POINT& pt,
  511. IN DWORD dwTime
  512. );
  513. void
  514. AddItem(
  515. IN POINT& pt,
  516. IN DWORD dwTime
  517. );
  518. bool
  519. penStopped(
  520. IN POINT& pt,
  521. IN DWORD dwTime,
  522. IN int ci,
  523. IN int li
  524. );
  525. bool
  526. checkEarlierPoints(
  527. IN POINT& pt,
  528. IN DWORD dwTime,
  529. IN int ci,
  530. IN int li
  531. );
  532. int
  533. dist(
  534. IN POINT& pt,
  535. IN int index
  536. );
  537. VOID
  538. DoGestureAction(
  539. IN GESTURE_ACTION Action,
  540. IN LONG x,
  541. IN LONG y
  542. );
  543. // tsrpc.cpp
  544. unsigned __stdcall
  545. RPCServerThread(
  546. IN PVOID param
  547. );
  548. // Supertip.cpp
  549. unsigned __stdcall
  550. SuperTIPThread(
  551. IN PVOID param
  552. );
  553. LRESULT CALLBACK
  554. SuperTIPWndProc(
  555. IN HWND hwnd,
  556. IN UINT uiMsg,
  557. IN WPARAM wParam,
  558. IN LPARAM lParam
  559. );
  560. #if 0
  561. VOID
  562. EnumDisplayModes(
  563. VOID
  564. );
  565. #endif
  566. VOID
  567. UpdateRotation(
  568. VOID
  569. );
  570. BOOL CALLBACK
  571. MonitorEnumProc(
  572. IN HMONITOR hMon,
  573. IN HDC hdcMon,
  574. IN LPRECT lprcMon,
  575. IN LPARAM dwData
  576. );
  577. BOOL
  578. CreateTrayIcon(
  579. IN HWND hwnd,
  580. IN UINT umsgTray,
  581. IN HICON hIcon,
  582. IN LPCTSTR ptszTip
  583. );
  584. BOOL
  585. DestroyTrayIcon(
  586. IN HWND hwnd,
  587. IN UINT umsgTray,
  588. IN HICON hIcon
  589. );
  590. BOOL SetBalloonToolTip(
  591. IN HWND hwnd,
  592. IN UINT umsgTray,
  593. IN LPCTSTR ptszTitle,
  594. IN LPCTSTR ptszTip,
  595. IN UINT uTimeout,
  596. IN DWORD dwInfoFlags
  597. );
  598. #endif //ifndef _TABSRV_H