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.

264 lines
7.0 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: configwnd.h
  3. //
  4. // Desc: CConfigWnd is derived from CFlexWnd. It implements the top-level
  5. // UI window which all other windows are descendents of.
  6. //
  7. // Functionalities handled by CConfigWnd are device tabs, Reset, Ok,
  8. // and Cancel buttons.
  9. //
  10. // Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  11. //-----------------------------------------------------------------------------
  12. #ifndef __CONFIGWND_H__
  13. #define __CONFIGWND_H__
  14. #define PAGETYPE IDIDeviceActionConfigPage
  15. //@@BEGIN_MSINTERNAL
  16. #ifdef DDKBUILD
  17. #define NUMBUTTONS 4
  18. #else
  19. #define NUMBUTTONS 3
  20. #endif
  21. /*
  22. //@@END_MSINTERNAL
  23. #define NUMBUTTONS 3
  24. //@@BEGIN_MSINTERNAL
  25. */
  26. //@@END_MSINTERNAL
  27. class CMouseTrap : public CFlexWnd
  28. {
  29. HWND m_hParent;
  30. public:
  31. CMouseTrap() : m_hParent(NULL) { }
  32. HWND Create(HWND hParent = NULL, BOOL bInRenderMode = TRUE);
  33. protected:
  34. virtual BOOL OnEraseBkgnd(HDC hDC) {return TRUE;}
  35. virtual void OnPaint(HDC hDC) {}
  36. virtual void OnRender(BOOL bInternalCall = FALSE) {}
  37. };
  38. // Each device is represented by an ELEMENT object that is managed by
  39. // CConfigWnd.
  40. struct ELEMENT {
  41. ELEMENT() : nCurUser(-1), pPage(NULL), lpDID(NULL) {tszCaption[0] = 0;}
  42. // everything's cleaned up in CConfigWnd::ClearElement();
  43. DIDEVICEINSTANCEW didi;
  44. PAGETYPE *pPage;
  45. HWND hWnd;
  46. BOOL bCalc;
  47. RECT rect, textrect;
  48. TCHAR tszCaption[MAX_PATH];
  49. LPDIRECTINPUTDEVICE8W lpDID;
  50. // the map of acfors contains an acfor for each genre/username
  51. // that has been used so far on this device. the dword represents
  52. // the genre username as follows: the hiword is the index of the
  53. // genre per uiglobals. the loword is the index of the username
  54. // per uiglobals.
  55. CMap<DWORD, DWORD &, LPDIACTIONFORMATW, LPDIACTIONFORMATW &> AcForMap;
  56. #define MAP2GENRE(m) (int(((m) & 0xffff0000) >> 16))
  57. #define MAP2USER(m) (int((m) & 0x0000ffff))
  58. #define GENREUSER2MAP(g,u) \
  59. ( \
  60. ((((DWORD)(nGenre)) & 0xffff) << 16) | \
  61. (((DWORD)(nUser)) & 0xffff) \
  62. )
  63. // this function simply returns the corresponding entry in the
  64. // map if it already exists. otherwise, it creates a copy for
  65. // this entry from the masteracfor and calls buildactionmap on
  66. // it with the appropriate username.
  67. // bHwDefault flag is added to properly support Reset button. BuildActionMap must be
  68. // called with the flag to get hardware default mapping, so we need this parameter.
  69. LPDIACTIONFORMATW GetAcFor(int nGenre, int nUser, BOOL bHwDefault = FALSE);
  70. // we need to keep track of the current user per-element
  71. int nCurUser;
  72. // we need a pointer to the uiglobals in order to correspond
  73. // user indexes to the actual string
  74. CUIGlobals *pUIGlobals;
  75. // this function will be called in CConfigWnd::ClearElement to
  76. // free all the actionformats from the map
  77. void FreeMap();
  78. // Applies all the acfor's in the map
  79. void Apply();
  80. };
  81. typedef CArray<ELEMENT, ELEMENT &> ELEMENTARRAY;
  82. // CConfigWnd needs to expose methods for child windows to notify it.
  83. class CConfigWnd : public CFlexWnd, public IDIConfigUIFrameWindow
  84. {
  85. public:
  86. CConfigWnd(CUIGlobals &uig);
  87. ~CConfigWnd();
  88. BOOL Create(HWND hParent);
  89. static void SetForegroundWindow();
  90. LPDIRECTINPUTDEVICE8W RenewDevice(GUID &GuidInstance);
  91. BOOL EnumDeviceCallback(const DIDEVICEINSTANCEW *lpdidi);
  92. void EnumDeviceCallbackAssignUser(const DIDEVICEINSTANCEW *lpdidi, DWORD *pdwOwner);
  93. CUIGlobals &m_uig;
  94. // IDIConfigUIFrameWindow implementation...
  95. // Reset Entire Configuration
  96. STDMETHOD (Reset) ();
  97. // Assignment Querying. GuidInstance is the guid of the device initiating the query.
  98. STDMETHOD (QueryActionAssignedAnywhere) (GUID GuidInstance, int i);
  99. // Genre Control
  100. STDMETHOD_(int, GetNumGenres) ();
  101. STDMETHOD (SetCurGenre) (int i);
  102. STDMETHOD_(int, GetCurGenre) ();
  103. // User Control
  104. STDMETHOD_(int, GetNumUsers) ();
  105. STDMETHOD (SetCurUser) (int nPage, int nUser);
  106. STDMETHOD_(int, GetCurUser) (int nPage);
  107. // ActionFormat Access
  108. STDMETHOD (GetActionFormatFromInstanceGuid) (LPDIACTIONFORMATW *lplpAcFor, REFGUID);
  109. // Main HWND Access
  110. STDMETHOD_(HWND, GetMainHWND) ();
  111. protected:
  112. // overrides
  113. virtual void OnRender(BOOL bInternalCall = FALSE);
  114. virtual LRESULT OnCreate(LPCREATESTRUCT lpCreateStruct);
  115. virtual void OnPaint(HDC hDC);
  116. virtual void OnMouseOver(POINT point, WPARAM fwKeys);
  117. virtual void OnClick(POINT point, WPARAM fwKeys, BOOL bLeft);
  118. virtual void OnDestroy();
  119. virtual LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  120. private:
  121. #define CFGWND_INIT_REINIT 1
  122. #define CFGWND_INIT_RESET 2
  123. BOOL Init(DWORD dwInitFlags = 0);
  124. DWORD m_dwInitFlags;
  125. BOOL m_bCreated;
  126. int AddToList(const DIDEVICEINSTANCEW *lpdidi, BOOL bReset = FALSE);
  127. void ClearList();
  128. void PlacePages();
  129. void GetPageRect(RECT &rect, BOOL bTemp = FALSE);
  130. void Render(BOOL bInternalCall = FALSE);
  131. ELEMENTARRAY m_Element;
  132. ELEMENT m_InvalidElement;
  133. int m_CurSel;
  134. int GetNumElements();
  135. ELEMENT &GetElement(int i);
  136. void ClearElement(int i, BOOL bReset = FALSE);
  137. void ClearElement(ELEMENT &e, BOOL bReset = FALSE);
  138. BOOL m_bScrollTabs, m_bScrollTabsLeft, m_bScrollTabsRight;
  139. int m_nLeftTab;
  140. RECT m_rectSTLeft, m_rectSTRight;
  141. void ScrollTabs(int);
  142. LPDIRECTINPUTDEVICE8W CreateDevice(GUID &guid);
  143. BOOL m_bNeedRedraw;
  144. CFlexMsgBox m_MsgBox;
  145. LPDIACTIONFORMATW GetCurAcFor(ELEMENT &e);
  146. int m_nCurGenre;
  147. IClassFactory *m_pPageFactory;
  148. HINSTANCE m_hPageFactoryInst;
  149. PAGETYPE *CreatePageObject(int nPage, const ELEMENT &e, HWND &refhChildWnd);
  150. void DestroyPageObject(PAGETYPE *&pPage);
  151. LPDIRECTINPUT8W m_lpDI;
  152. RECT m_rectTopGradient, m_rectBottomGradient;
  153. CBitmap *m_pbmTopGradient, *m_pbmBottomGradient;
  154. BOOL m_bHourGlass; // Set when the cursor should be an hourglass
  155. typedef struct BUTTON {
  156. BUTTON() {CopyStr(tszCaption, _T(""), MAX_PATH);}
  157. RECT rect;
  158. TCHAR tszCaption[MAX_PATH];
  159. SIZE textsize;
  160. RECT textrect;
  161. } BUTTON;
  162. BUTTON m_Button[NUMBUTTONS];
  163. enum {
  164. BUTTON_RESET = 0,
  165. BUTTON_CANCEL,
  166. BUTTON_OK,
  167. //@@BEGIN_MSINTERNAL
  168. #ifdef DDKBUILD
  169. BUTTON_LAYOUT
  170. #endif
  171. //@@END_MSINTERNAL
  172. };
  173. SIZE GetTextSize(LPCTSTR tszText);
  174. void CalcTabs();
  175. void CalcButtons();
  176. void InitGradients();
  177. void SelTab(int);
  178. void FireButton(int);
  179. void ShowPage(int);
  180. void HidePage(int);
  181. HDC GetRenderDC();
  182. void ReleaseRenderDC(HDC &phDC);
  183. void Create3DBitmap();
  184. void Copy3DBitmapToSurface3D();
  185. void CallRenderCallback();
  186. IDirectDrawSurface *m_pSurface;
  187. IDirect3DSurface8 *m_pSurface3D;
  188. D3DFORMAT m_SurfFormat;
  189. UINT m_uiPixelSize; // Size of a pixel in byte for the format we are using
  190. CBitmap *m_pbmPointerEraser;
  191. CBitmap *m_pbm3D;
  192. LPVOID m_p3DBits;
  193. BOOL m_bRender3D;
  194. POINT m_ptTest;
  195. void MapBitmaps(HDC);
  196. BOOL m_bBitmapsMapped;
  197. BOOL m_bAllowEditLayout;
  198. BOOL m_bEditLayout;
  199. void ToggleLayoutEditting();
  200. CMouseTrap m_MouseTrap;
  201. // Timer
  202. static void CALLBACK TimerProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
  203. HRESULT Apply();
  204. // GuidInstance is the guid of the device initiating the query.
  205. BOOL IsActionAssignedAnywhere(GUID GuidInstance, int nActionIndex);
  206. void Unacquire();
  207. void Reacquire();
  208. };
  209. #endif //__CONFIGWND_H__