Leaked source code of windows server 2003
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.

316 lines
11 KiB

  1. /**************************************************************************\
  2. * Module Name: softkbdc.h
  3. *
  4. * Copyright (c) 1985 - 2000, Microsoft Corporation
  5. *
  6. * Declaration of CSoftKbd
  7. *
  8. * History:
  9. * 28-March-2000 weibz Created
  10. \**************************************************************************/
  11. #ifndef __SOFTKBDC_H_
  12. #define __SOFTKBDC_H_
  13. #include "resource.h"
  14. #include <windows.h>
  15. #include "globals.h"
  16. #include "SoftKbd.h"
  17. #include "msxml.h"
  18. #include "helpers.h"
  19. #define MAX_KEY_NUM 256
  20. #define NON_KEYBOARD -1
  21. #define IdTimer_MonitorMouse 0x1000
  22. #define MONITORMOUSE_ELAPSE 8000
  23. // we assume no keyboard has more than 256 keys
  24. #define KID_ICON 0x100
  25. #define KID_CLOSE 0x101
  26. #define DWCOOKIE_SFTKBDWNDES 0x2000
  27. extern HINSTANCE g_hInst;
  28. #define LABEL_TEXT 1
  29. #define LABEL_PICTURE 2
  30. #define LABEL_DISP_ACTIVE 1
  31. #define LABEL_DISP_GRAY 2
  32. typedef struct tagActiveLabel { // label for current active state.
  33. KEYID keyId;
  34. WCHAR *lpLabelText;
  35. WORD LabelType;
  36. WORD LabelDisp;
  37. } ACTIVELABEL, *PACTIVELABEL;
  38. typedef struct tagKeyLabels { // labels for all states.
  39. KEYID keyId;
  40. WORD wNumModComb; // number of modifier combination states.
  41. BSTR *lppLabelText;
  42. WORD *lpLabelType;
  43. WORD *lpLabelDisp;
  44. // Every lppLabelText maps to one lpLabelType
  45. } KEYLABELS, *PKEYLABELS, FAR * LPKEYLABELS;
  46. typedef struct tagKeyMap {
  47. WORD wNumModComb; // number of modifier combination states.
  48. WORD wNumOfKeys;
  49. WCHAR wszResource[MAX_PATH]; // Keep the resource file path if
  50. // any key has picture as its label
  51. //
  52. KEYLABELS lpKeyLabels[MAX_KEY_NUM];
  53. HKL hKl;
  54. struct tagKeyMap *pNext;
  55. } KEYMAP, *PKEYMAP, FAR * LPKEYMAP;
  56. typedef struct tagKEYDES {
  57. KEYID keyId;
  58. WORD wLeft; // relative to the left-top point of the layout window described in KEYBOARD.
  59. WORD wTop;
  60. WORD wWidth;
  61. WORD wHeight;
  62. MODIFYTYPE tModifier;
  63. } KEYDES, FAR * LPKEYDES;
  64. typedef struct tagKbdLayout {
  65. WORD wLeft;
  66. WORD wTop;
  67. WORD wWidth;
  68. WORD wHeight;
  69. WORD wMarginWidth;
  70. WORD wMarginHeight;
  71. BOOL fStandard; // TRUE means this is a standard keyboard;
  72. // FALSE means a user-defined keyboard layout.
  73. WORD wNumberOfKeys;
  74. KEYDES lpKeyDes[MAX_KEY_NUM];
  75. } KBDLAYOUT, *PKBDLAYOUT, FAR * LPKBDLAYOUT;
  76. typedef struct tagKbdLayoutDes {
  77. DWORD wKbdLayoutID;
  78. WCHAR KbdLayoutDesFile[MAX_PATH];
  79. ISoftKeyboardEventSink *pskbes;
  80. // Soft Keyboard Event Sink should be per Soft Keyboard.
  81. WORD ModifierStatus; // Every bit stands for one modifier's status
  82. //
  83. // CapsLock bit 1
  84. // Shift bit 2
  85. // Ctrl bit 3
  86. // Alt bit 4
  87. // Kana bit 5
  88. // NumLock bit 6
  89. //
  90. // Etc.
  91. KBDLAYOUT kbdLayout;
  92. KEYMAP *lpKeyMapList;
  93. DWORD CurModiState;
  94. HKL CurhKl;
  95. struct tagKbdLayoutDes *pNext;
  96. } KBDLAYOUTDES, * PKBDLAYOUTDES, FAR * LPKBDLAYOUTDES;
  97. class CSoftkbdUIWnd;
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CSoftKbd
  100. class CSoftKbd :
  101. public CComObjectRoot_CreateInstance<CSoftKbd>,
  102. public ISoftKbd
  103. {
  104. public:
  105. CSoftKbd();
  106. ~CSoftKbd();
  107. BEGIN_COM_MAP_IMMX(CSoftKbd)
  108. COM_INTERFACE_ENTRY(ISoftKbd)
  109. END_COM_MAP_IMMX()
  110. // ISoftKbd
  111. public:
  112. STDMETHOD(Initialize)();
  113. STDMETHOD(EnumSoftKeyBoard)(/*[in]*/ LANGID langid, /*[out]*/ DWORD *lpdwKeyboard);
  114. STDMETHOD(SelectSoftKeyboard)(/*[in]*/ DWORD dwKeyboardId);
  115. STDMETHOD(CreateSoftKeyboardLayoutFromXMLFile)(/*[in, string]*/ WCHAR *lpszKeyboardDesFile, /*[in]*/ INT szFileStrLen, /*[out]*/ DWORD *pdwLayoutCookie);
  116. STDMETHOD(CreateSoftKeyboardLayoutFromResource)(/*[in]*/ WCHAR *lpszResFile, /*[in, string] */ WCHAR *lpszResType, /*[in, string] */ WCHAR *lpszXMLResString, /*[out] */ DWORD *lpdwLayoutCookie);
  117. STDMETHOD(ShowSoftKeyboard)(/*[in]*/ INT iShow);
  118. STDMETHOD(SetKeyboardLabelText)(/*[in]*/ HKL hKl );
  119. STDMETHOD(SetKeyboardLabelTextCombination)(/*[in]*/ DWORD nModifierCombination);
  120. STDMETHOD(CreateSoftKeyboardWindow)(/*[in]*/ HWND hOwner, /*in*/ TITLEBAR_TYPE Titlebar_type, /*[in]*/ INT xPos, /*[in]*/ INT yPos, /*[in]*/ INT width, /*[in]*/ INT height );
  121. STDMETHOD(DestroySoftKeyboardWindow)();
  122. STDMETHOD(GetSoftKeyboardPosSize)(/*[out]*/ POINT *lpStartPoint, /*[out]*/ WORD *lpwidth, /*[out]*/ WORD *lpheight);
  123. STDMETHOD(GetSoftKeyboardColors)(/*[in]*/ COLORTYPE colorType, /*[out]*/ COLORREF *lpColor);
  124. STDMETHOD(GetSoftKeyboardTypeMode)(/*[out]*/ TYPEMODE *lpTypeMode);
  125. STDMETHOD(GetSoftKeyboardTextFont)(/*[out]*/ LOGFONTW *pLogFont);
  126. STDMETHOD(SetSoftKeyboardPosSize)(/*[in]*/ POINT StartPoint, /*[in]*/ WORD width, /*[in]*/ WORD height);
  127. STDMETHOD(SetSoftKeyboardColors)(/*[in]*/ COLORTYPE colorType, /*[in]*/ COLORREF Color);
  128. STDMETHOD(SetSoftKeyboardTypeMode)(/*[in]*/ TYPEMODE TypeMode);
  129. STDMETHOD(SetSoftKeyboardTextFont)(/*[in]*/ LOGFONTW *pLogFont);
  130. STDMETHOD(ShowKeysForKeyScanMode)(/*[in]*/ KEYID *lpKeyID, /*[in]*/ INT iKeyNum, /*[in]*/ BOOL fHighL);
  131. STDMETHOD(AdviseSoftKeyboardEventSink)(/* [in]*/DWORD dwKeyboardId,/*[in] */REFIID riid, /*[in, iid_is(riid)] */IUnknown *punk, /*[out] */DWORD *pdwCookie);
  132. STDMETHOD(UnadviseSoftKeyboardEventSink)(/*[in] */DWORD dwCookie);
  133. // Following public functions will be called by CSoftkbdUIWnd.
  134. HRESULT _HandleKeySelection(KEYID keyId);
  135. HRESULT _HandleTitleBarEvent( DWORD dwId );
  136. KBDLAYOUTDES *_GetCurKbdLayout( ) { return _lpCurKbdLayout; }
  137. DWORD _GetCurKbdLayoutID( ) { return _wCurKbdLayoutID; }
  138. ACTIVELABEL *_GetCurLabel( ) { return _CurLabel; }
  139. RECT *_GetTitleBarRect( ) { return &_TitleBarRect; }
  140. ISoftKbdWindowEventSink *_GetSoftKbdWndES( ) { return _pskbdwndes; }
  141. private:
  142. KBDLAYOUTDES *_lpKbdLayoutDesList;
  143. KBDLAYOUTDES *_lpCurKbdLayout;
  144. DWORD _wCurKbdLayoutID;
  145. ACTIVELABEL _CurLabel[MAX_KEY_NUM];
  146. HWND _hOwner;
  147. CSoftkbdUIWnd *_pSoftkbdUIWnd;
  148. int _xReal;
  149. int _yReal;
  150. int _widthReal;
  151. int _heightReal;
  152. IXMLDOMDocument *_pDoc;
  153. COLORREF _color[Max_color_Type];
  154. INT _iShow;
  155. LOGFONTW *_plfTextFont;
  156. WORD _TitleButtonWidth;
  157. RECT _TitleBarRect;
  158. TITLEBAR_TYPE _TitleBar_Type;
  159. ISoftKbdWindowEventSink *_pskbdwndes;
  160. HRESULT _CreateStandardSoftKbdLayout(DWORD dwStdSoftKbdID, WCHAR *wszStdResStr );
  161. HRESULT _GenerateRealKbdLayout( );
  162. HRESULT _SetStandardLabelText(LPBYTE pKeyState, KBDLAYOUT *realKbdLayut,
  163. KEYMAP *lpKeyMapList, int iState);
  164. HRESULT _GenerateUSStandardLabel( );
  165. HRESULT _GenerateUSEnhanceLabel( );
  166. HRESULT _GenerateEuroStandardLabel( );
  167. HRESULT _GenerateEuroEnhanceLabel( );
  168. HRESULT _GenerateJpnStandardLabel( );
  169. HRESULT _GenerateJpnEnhanceLabel( );
  170. HRESULT _GenerateCurModiState(WORD *ModifierStatus, DWORD *CurModiState);
  171. HRESULT _GenerateMapDesFromSKD(BYTE *pMapTable, KEYMAP *lpKeyMapList);
  172. HRESULT _GenerateKeyboardLayoutFromSKD(BYTE *lpszKeyboardDes, DWORD dwKbdLayoutID, KBDLAYOUTDES **lppKbdLayout);
  173. HRESULT _LoadDocumentSync(BSTR pBURL, BOOL fFileName);
  174. HRESULT _ParseKeyboardLayout(BOOL fFileName, WCHAR *lpszKeyboardDesFile, DWORD dwKbdLayoutID, KBDLAYOUTDES **lppKbdLayout);
  175. HRESULT _ParseLayoutDescription(IXMLDOMNode *pLayoutChild, KBDLAYOUT *pLayout);
  176. HRESULT _ParseMappingDescription(IXMLDOMNode *pLabelChild, KEYMAP *lpKeyMapList);
  177. HRESULT _GetXMLNodeValueWORD(IXMLDOMNode *pNode, WORD *lpWord);
  178. HRESULT _ParseOneKeyInLayout(IXMLDOMNode *pNode, KEYDES *lpKeyDes);
  179. HRESULT _ParseOneKeyInLabel(IXMLDOMNode *pNode, KEYLABELS *lpKeyLabels);
  180. DWORD _UnicodeToUtf8(PWCHAR pwUnicode, DWORD cchUnicode, PCHAR pchResult, DWORD cchResult);
  181. DWORD _Utf8ToUnicode(PCHAR pchUtf8, DWORD cchUtf8, PWCHAR pwResult, DWORD cwResult);
  182. };
  183. //
  184. // Following are the definition for some XML node and attribute names.
  185. //
  186. #define xSOFTKBDDES L"softKbdDes"
  187. #define xSOFTKBDTYPE L"softkbdtype"
  188. #define xTCUSTOMIZED L"customized"
  189. #define xTSTANDARD L"standard"
  190. #define xWIDTH L"width"
  191. #define xHEIGHT L"height"
  192. #define xMARGIN_WIDTH L"margin_width"
  193. #define xMARGIN_HEIGHT L"margin_height"
  194. #define xKEYNUMBER L"keynumber"
  195. #define xKEY L"key"
  196. #define xMODIFIER L"modifier"
  197. #define xNONE L"none"
  198. #define xCAPSLOCK L"CapsLock"
  199. #define xSHIFT L"Shift"
  200. #define xCTRL L"Ctrl"
  201. #define xATL L"Alt"
  202. #define xKANA L"Kana"
  203. #define xALTGR L"AltGr"
  204. #define xNUMLOCK L"NumLock"
  205. #define xKEYID L"keyid"
  206. #define xLEFT L"left"
  207. #define xTOP L"top"
  208. #define xVALIDSTATES L"validstates"
  209. #define xKEYLABEL L"keylabel"
  210. #define xLABELTEXT L"labeltext"
  211. #define xLABELTYPE L"labeltype"
  212. #define xTEXT L"text"
  213. #define xLABELDISP L"labeldisp"
  214. #define xGRAY L"gray"
  215. #define xRESOURCEFILE L"resourcefile"
  216. //
  217. // Macros to simplify UTF8 conversions
  218. //
  219. #define UTF8_1ST_OF_2 0xc0 // 110x xxxx
  220. #define UTF8_1ST_OF_3 0xe0 // 1110 xxxx
  221. #define UTF8_1ST_OF_4 0xf0 // 1111 xxxx
  222. #define UTF8_TRAIL 0x80 // 10xx xxxx
  223. #define UTF8_2_MAX 0x07ff // max unicode character representable in
  224. // in two byte UTF8
  225. #define BIT7(ch) ((ch) & 0x80)
  226. #define BIT6(ch) ((ch) & 0x40)
  227. #define BIT5(ch) ((ch) & 0x20)
  228. #define BIT4(ch) ((ch) & 0x10)
  229. #define BIT3(ch) ((ch) & 0x08)
  230. #define LOW6BITS(ch) ((ch) & 0x3f)
  231. #define LOW5BITS(ch) ((ch) & 0x1f)
  232. #define LOW4BITS(ch) ((ch) & 0x0f)
  233. //
  234. // Surrogate pair support
  235. // Two unicode characters may be linked to form a surrogate pair.
  236. // And for some totally unknown reason, some person thought they
  237. // should travel in UTF8 as four bytes instead of six.
  238. // No one has any idea why this is true other than to complicate
  239. // the code.
  240. //
  241. #define HIGH_SURROGATE_START 0xd800
  242. #define HIGH_SURROGATE_END 0xdbff
  243. #define LOW_SURROGATE_START 0xdc00
  244. #define LOW_SURROGATE_END 0xdfff
  245. #endif //__SOFTKBDC_H_