*/}}
1
0

pktdef.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*----------------------------------------------------------------------------s
  2. NAME
  3. PKTDEF.H
  4. PURPOSE
  5. Used to help construct a Wintab PACKETDATA definition the application
  6. uses to specify what data to receive in a Wintab data packet
  7. COPYRIGHT
  8. This file is Copyright (c) Wacom Company, Ltd. 2020 All Rights Reserved
  9. with portions copyright 1991-1998 by LCS/Telegraphics.
  10. The text and information contained in this file may be freely used,
  11. copied, or distributed without compensation or licensing restrictions.
  12. ---------------------------------------------------------------------------- */
  13. #pragma once
  14. /*------------------------------------------------------------------------------
  15. How to use pktdef.h:
  16. 1. Include wintab.h
  17. 2. if using just one packet format:
  18. a. Define PACKETDATA and PACKETMODE as or'ed combinations of WTPKT bits
  19. (use the PK_* identifiers).
  20. b. Include pktdef.h.
  21. c. The generated structure typedef will be called PACKET. Use PACKETDATA
  22. and PACKETMODE to fill in the LOGCONTEXT structure.
  23. 3. If using multiple packet formats, for each one:
  24. a. Define PACKETNAME. Its text value will be a prefix for this packet's
  25. parameters and names.
  26. b. Define <PACKETNAME>PACKETDATA and <PACKETNAME>PACKETMODE similar to
  27. 2.a. above.
  28. c. Include pktdef.h.
  29. d. The generated structure typedef will be called
  30. <PACKETNAME>PACKET. Compare with 2.c. above and example #2 below.
  31. 4. If using extension data for extensions that report thier data in the packet,
  32. do the following additional steps for each extension:
  33. a. Before including pktdef.h, define <PACKETNAME>PACKET<EXTENSION>
  34. as either PKEXT_ABSOLUTE or PKEXT_RELATIVE.
  35. b. The generated structure typedef will contain a field for the
  36. extension data.
  37. c. Scan the WTI_EXTENSION categories to find the extension's
  38. packet mask bit.
  39. d. OR the packet mask bit with <PACKETNAME>PACKETDATA and use the
  40. result in the lcPktData field of the LOGCONTEXT structure.
  41. e. If <PACKETNAME>PACKET<EXTENSION> was PKEXT_RELATIVE, OR the
  42. packet mask bit with <PACKETNAME>PACKETMODE and use the result
  43. in the lcPktMode field of the LOGCONTEXT structure.
  44. 5. If using extension data for extensions that report thier data in the extensions packet,
  45. do the following additional steps for each extension:
  46. a. Before including pktdef.h, define <PACKETNAME>PACKET<EXTENSION> as PKEXT_ABSOLUTE.
  47. b. The generated extension structure typedef will contain a field for the
  48. extension data.
  49. c. Call WTExtSet to activate the extention. Use the context id in the WT_PACKETEXT
  50. message to retrieve the extension data <PACKETNAME>PACKETEXT.
  51. Example #1. -- single packet format
  52. #include <wintab.h>
  53. #define PACKETDATA PK_X | PK_Y | PK_BUTTONS /@ x, y, buttons @/
  54. #define PACKETMODE PK_BUTTONS /@ buttons relative mode @/
  55. #include <pktdef.h>
  56. ...
  57. lc.lcPktData = PACKETDATA;
  58. lc.lcPktMode = PACKETMODE;
  59. Example #2. -- multiple formats
  60. #include <wintab.h>
  61. #define PACKETNAME MOE
  62. #define MOEPACKETDATA PK_X | PK_Y | PK_BUTTONS /@ x, y, buttons @/
  63. #define MOEPACKETMODE PK_BUTTONS /@ buttons relative mode @/
  64. #include <pktdef.h>
  65. #define PACKETNAME LARRY
  66. #define LARRYPACKETDATA PK_Y | PK_Z | PK_BUTTONS /@ y, z, buttons @/
  67. #define LARRYPACKETMODE PK_BUTTONS /@ buttons relative mode @/
  68. #include <pktdef.h>
  69. #define PACKETNAME CURLY
  70. #define CURLYPACKETDATA PK_X | PK_Z | PK_BUTTONS /@ x, z, buttons @/
  71. #define CURLYPACKETMODE PK_BUTTONS /@ buttons relative mode @/
  72. #include <pktdef.h>
  73. ...
  74. lcMOE.lcPktData = MOEPACKETDATA;
  75. lcMOE.lcPktMode = MOEPACKETMODE;
  76. ...
  77. lcLARRY.lcPktData = LARRYPACKETDATA;
  78. lcLARRY.lcPktMode = LARRYPACKETMODE;
  79. ...
  80. lcCURLY.lcPktData = CURLYPACKETDATA;
  81. lcCURLY.lcPktMode = CURLYPACKETMODE;
  82. Example #3. -- extension packet data "XFOO".
  83. #include <wintab.h>
  84. #define PACKETDATA PK_X | PK_Y | PK_BUTTONS /@ x, y, buttons @/
  85. #define PACKETMODE PK_BUTTONS /@ buttons relative mode @/
  86. #define PACKETXFOO PKEXT_ABSOLUTE /@ XFOO absolute mode @/
  87. #include <pktdef.h>
  88. ...
  89. UINT ScanExts(UINT wTag)
  90. {
  91. UINT i;
  92. UINT wScanTag;
  93. /@ scan for wTag's info category. @/
  94. for (i = 0; WTInfo(WTI_EXTENSIONS + i, EXT_TAG, &wScanTag); i++) {
  95. if (wTag == wScanTag) {
  96. /@ return category offset from WTI_EXTENSIONS. @/
  97. return i;
  98. }
  99. }
  100. /@ return error code. @/
  101. return 0xFFFF;
  102. }
  103. ...
  104. lc.lcPktData = PACKETDATA;
  105. lc.lcPktMode = PACKETMODE;
  106. #ifdef PACKETXFOO
  107. categoryXFOO = ScanExts(WTX_XFOO);
  108. WTInfo(WTI_EXTENSIONS + categoryXFOO, EXT_MASK, &maskXFOO);
  109. lc.lcPktData |= maskXFOO;
  110. #if PACKETXFOO == PKEXT_RELATIVE
  111. lc.lcPktMode |= maskXFOO;
  112. #endif
  113. #endif
  114. WTOpen(hWnd, &lc, TRUE);
  115. ------------------------------------------------------------------------------*/
  116. #ifdef __cplusplus
  117. extern "C" {
  118. #endif /* __cplusplus */
  119. #ifndef PACKETNAME
  120. /* if no packet name prefix */
  121. #define __PFX(x) x
  122. #define __IFX(x,y) x ## y
  123. #else
  124. /* add prefixes and infixes to packet format names */
  125. #define __PFX(x) __PFX2(PACKETNAME,x)
  126. #define __PFX2(p,x) __PFX3(p,x)
  127. #define __PFX3(p,x) p ## x
  128. #define __IFX(x,y) __IFX2(x,PACKETNAME,y)
  129. #define __IFX2(x,i,y) __IFX3(x,i,y)
  130. #define __IFX3(x,i,y) x ## i ## y
  131. #endif
  132. #define __SFX2(x,s) __SFX3(x,s)
  133. #define __SFX3(x,s) x ## s
  134. #define __TAG __IFX(tag,PACKET)
  135. #define __TYPES __PFX(PACKET), * __IFX(P,PACKET), NEAR * __IFX(NP,PACKET), FAR * __IFX(LP,PACKET)
  136. #define __TAGE __IFX(tag,PACKETEXT)
  137. #define __TYPESE __PFX(PACKETEXT), * __IFX(P,PACKETEXT), NEAR * __IFX(NP,PACKETEXT), FAR * __IFX(LP,PACKETEXT)
  138. #define __DATA (__PFX(PACKETDATA))
  139. #define __MODE (__PFX(PACKETMODE))
  140. #define __EXT(x) __SFX2(__PFX(PACKET),x)
  141. typedef struct __TAG {
  142. #if (__DATA & PK_CONTEXT)
  143. HCTX pkContext;
  144. #endif
  145. #if (__DATA & PK_STATUS)
  146. UINT pkStatus;
  147. #endif
  148. #if (__DATA & PK_TIME)
  149. DWORD pkTime;
  150. #endif
  151. #if (__DATA & PK_CHANGED)
  152. WTPKT pkChanged;
  153. #endif
  154. #if (__DATA & PK_SERIAL_NUMBER)
  155. UINT pkSerialNumber;
  156. #endif
  157. #if (__DATA & PK_CURSOR)
  158. UINT pkCursor;
  159. #endif
  160. #if (__DATA & PK_BUTTONS)
  161. DWORD pkButtons;
  162. #endif
  163. #if (__DATA & PK_X)
  164. LONG pkX;
  165. #endif
  166. #if (__DATA & PK_Y)
  167. LONG pkY;
  168. #endif
  169. #if (__DATA & PK_Z)
  170. LONG pkZ;
  171. #endif
  172. #if (__DATA & PK_NORMAL_PRESSURE)
  173. #if (__MODE & PK_NORMAL_PRESSURE)
  174. /* relative */
  175. int pkNormalPressure;
  176. #else
  177. /* absolute */
  178. UINT pkNormalPressure;
  179. #endif
  180. #endif
  181. #if (__DATA & PK_TANGENT_PRESSURE)
  182. #if (__MODE & PK_TANGENT_PRESSURE)
  183. /* relative */
  184. int pkTangentPressure;
  185. #else
  186. /* absolute */
  187. UINT pkTangentPressure;
  188. #endif
  189. #endif
  190. #if (__DATA & PK_ORIENTATION)
  191. ORIENTATION pkOrientation;
  192. #endif
  193. #if (__DATA & PK_ROTATION)
  194. ROTATION pkRotation; /* 1.1 */
  195. #endif
  196. #ifndef NOWTEXTENSIONS
  197. /* extensions begin here. */
  198. #if (__EXT(FKEYS) == PKEXT_RELATIVE) || (__EXT(FKEYS) == PKEXT_ABSOLUTE)
  199. UINT pkFKeys;
  200. #endif
  201. #if (__EXT(TILT) == PKEXT_RELATIVE) || (__EXT(TILT) == PKEXT_ABSOLUTE)
  202. TILT pkTilt;
  203. #endif
  204. #endif
  205. } __TYPES;
  206. #ifndef NOWTEXTENSIONS
  207. typedef struct __TAGE {
  208. EXTENSIONBASE pkBase;
  209. #if (__EXT(EXPKEYS) == PKEXT_RELATIVE) || (__EXT(EXPKEYS) == PKEXT_ABSOLUTE)
  210. EXPKEYSDATA pkExpKeys; /* 1.4 */
  211. #endif
  212. #if (__EXT(TOUCHSTRIP) == PKEXT_RELATIVE) || (__EXT(TOUCHSTRIP) == PKEXT_ABSOLUTE)
  213. SLIDERDATA pkTouchStrip; /* 1.4 */
  214. #endif
  215. #if (__EXT(TOUCHRING) == PKEXT_RELATIVE) || (__EXT(TOUCHRING) == PKEXT_ABSOLUTE)
  216. SLIDERDATA pkTouchRing; /* 1.4 */
  217. #endif
  218. } __TYPESE;
  219. #endif
  220. #undef PACKETNAME
  221. #undef __TAG
  222. #undef __TAGE
  223. #undef __TAG2
  224. #undef __TYPES
  225. #undef __TYPESE
  226. #undef __TYPES2
  227. #undef __DATA
  228. #undef __MODE
  229. #undef __PFX
  230. #undef __PFX2
  231. #undef __PFX3
  232. #undef __IFX
  233. #undef __IFX2
  234. #undef __IFX3
  235. #undef __SFX2
  236. #undef __SFX3
  237. #ifdef __cplusplus
  238. }
  239. #endif /* __cplusplus */