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.

272 lines
9.2 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994-1995 **
  4. //*********************************************************************
  5. //
  6. // CLSUTIL.H - header file for utility C++ classes
  7. //
  8. // HISTORY:
  9. //
  10. // 12/07/94 jeremys Borrowed from WNET common library
  11. //
  12. #ifndef _CLSUTIL_H_
  13. #define _CLSUTIL_H_
  14. /*************************************************************************
  15. NAME: BUFFER_BASE
  16. SYNOPSIS: Base class for transient buffer classes
  17. INTERFACE: BUFFER_BASE()
  18. Construct with optional size of buffer to allocate.
  19. Resize()
  20. Resize buffer to specified size. Returns TRUE if
  21. successful.
  22. QuerySize()
  23. Return the current size of the buffer in bytes.
  24. QueryPtr()
  25. Return a pointer to the buffer.
  26. PARENT: None
  27. USES: None
  28. CAVEATS: This is an abstract class, which unifies the interface
  29. of BUFFER, GLOBAL_BUFFER, etc.
  30. NOTES: In standard OOP fashion, the buffer is deallocated in
  31. the destructor.
  32. HISTORY:
  33. 03/24/93 gregj Created base class
  34. **************************************************************************/
  35. class BUFFER_BASE
  36. {
  37. protected:
  38. UINT _cb;
  39. virtual BOOL Alloc( UINT cbBuffer ) = 0;
  40. virtual BOOL Realloc( UINT cbBuffer ) = 0;
  41. public:
  42. BUFFER_BASE()
  43. { _cb = 0; } // buffer not allocated yet
  44. ~BUFFER_BASE()
  45. { _cb = 0; } // buffer size no longer valid
  46. BOOL Resize( UINT cbNew );
  47. UINT QuerySize() const { return _cb; };
  48. };
  49. #define GLOBAL_BUFFER BUFFER
  50. /*************************************************************************
  51. NAME: BUFFER
  52. SYNOPSIS: Wrapper class for new and delete
  53. INTERFACE: BUFFER()
  54. Construct with optional size of buffer to allocate.
  55. Resize()
  56. Resize buffer to specified size. Only works if the
  57. buffer hasn't been allocated yet.
  58. QuerySize()
  59. Return the current size of the buffer in bytes.
  60. QueryPtr()
  61. Return a pointer to the buffer.
  62. PARENT: BUFFER_BASE
  63. USES: operator new, operator delete
  64. CAVEATS:
  65. NOTES: In standard OOP fashion, the buffer is deallocated in
  66. the destructor.
  67. HISTORY:
  68. 03/24/93 gregj Created
  69. **************************************************************************/
  70. class BUFFER : public BUFFER_BASE
  71. {
  72. protected:
  73. TCHAR *_lpBuffer;
  74. virtual BOOL Alloc( UINT cbBuffer );
  75. virtual BOOL Realloc( UINT cbBuffer );
  76. public:
  77. BUFFER( UINT cbInitial=0 );
  78. ~BUFFER();
  79. BOOL Resize( UINT cbNew );
  80. TCHAR * QueryPtr() const { return (TCHAR *)_lpBuffer; }
  81. operator TCHAR *() const { return (TCHAR *)_lpBuffer; }
  82. };
  83. class RegEntry
  84. {
  85. public:
  86. RegEntry(const TCHAR *pszSubKey, HKEY hkey = HKEY_CURRENT_USER, REGSAM regsam = KEY_READ|KEY_WRITE);
  87. ~RegEntry();
  88. long GetError() { return _error; }
  89. long SetValue(const TCHAR *pszValue, const TCHAR *string);
  90. long SetValue(const TCHAR *pszValue, unsigned long dwNumber);
  91. TCHAR * GetString(const TCHAR *pszValue, TCHAR *string, unsigned long length);
  92. long GetNumber(const TCHAR *pszValue, long dwDefault = 0);
  93. long DeleteValue(const TCHAR *pszValue);
  94. long FlushKey();
  95. long MoveToSubKey(const TCHAR *pszSubKeyName);
  96. HKEY GetKey() { return _hkey; }
  97. private:
  98. HKEY _hkey;
  99. long _error;
  100. BOOL bhkeyValid;
  101. };
  102. class RegEnumValues
  103. {
  104. public:
  105. RegEnumValues(RegEntry *pRegEntry);
  106. ~RegEnumValues();
  107. long Next();
  108. TCHAR * GetName() {return pchName;}
  109. DWORD GetType() {return dwType;}
  110. LPBYTE GetData() {return pbValue;}
  111. DWORD GetDataLength() {return dwDataLength;}
  112. long GetError() { return _error; }
  113. private:
  114. RegEntry * pRegEntry;
  115. DWORD iEnum;
  116. DWORD cEntries;
  117. TCHAR * pchName;
  118. LPBYTE pbValue;
  119. DWORD dwType;
  120. DWORD dwDataLength;
  121. DWORD cMaxValueName;
  122. DWORD cMaxData;
  123. LONG _error;
  124. };
  125. /*************************************************************************
  126. NAME: WAITCURSOR
  127. SYNOPSIS: Sets the cursor to an hourclass until object is destructed
  128. **************************************************************************/
  129. class WAITCURSOR
  130. {
  131. private:
  132. HCURSOR m_curOld;
  133. HCURSOR m_curNew;
  134. public:
  135. WAITCURSOR() { m_curNew = ::LoadCursor( NULL, IDC_WAIT ); m_curOld = ::SetCursor( m_curNew ); }
  136. ~WAITCURSOR() { ::SetCursor( m_curOld ); }
  137. };
  138. /*************************************************************************
  139. NAME: CAccessibleWrapper
  140. SYNOPSIS: Sets the cursor to an hourclass until object is destructed
  141. **************************************************************************/
  142. // Generic CAccessibleWrapper class - just calls through on all methods.
  143. // Add overriding behavior in classes derived from this.
  144. class CAccessibleWrapper: public IAccessible,
  145. public IOleWindow,
  146. public IEnumVARIANT
  147. {
  148. // We need to do our own refcounting for this wrapper object
  149. ULONG m_ref;
  150. // Need ptr to the IAccessible - also keep around ptrs to EnumVar and
  151. // OleWindow as part of this object, so we can filter those interfaces
  152. // and trap their QI's...
  153. // (We leave pEnumVar and OleWin as NULL until we need them)
  154. IAccessible * m_pAcc;
  155. IEnumVARIANT * m_pEnumVar;
  156. IOleWindow * m_pOleWin;
  157. public:
  158. CAccessibleWrapper( IAccessible * pAcc );
  159. virtual ~CAccessibleWrapper();
  160. // IUnknown
  161. // (We do our own ref counting)
  162. virtual STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
  163. virtual STDMETHODIMP_(ULONG) AddRef();
  164. virtual STDMETHODIMP_(ULONG) Release();
  165. // IDispatch
  166. virtual STDMETHODIMP GetTypeInfoCount(UINT* pctinfo);
  167. virtual STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo);
  168. virtual STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames,
  169. LCID lcid, DISPID* rgdispid);
  170. virtual STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
  171. DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo,
  172. UINT* puArgErr);
  173. // IAccessible
  174. virtual STDMETHODIMP get_accParent(IDispatch ** ppdispParent);
  175. virtual STDMETHODIMP get_accChildCount(long* pChildCount);
  176. virtual STDMETHODIMP get_accChild(VARIANT varChild, IDispatch ** ppdispChild);
  177. virtual STDMETHODIMP get_accName(VARIANT varChild, BSTR* pszName);
  178. virtual STDMETHODIMP get_accValue(VARIANT varChild, BSTR* pszValue);
  179. virtual STDMETHODIMP get_accDescription(VARIANT varChild, BSTR* pszDescription);
  180. virtual STDMETHODIMP get_accRole(VARIANT varChild, VARIANT *pvarRole);
  181. virtual STDMETHODIMP get_accState(VARIANT varChild, VARIANT *pvarState);
  182. virtual STDMETHODIMP get_accHelp(VARIANT varChild, BSTR* pszHelp);
  183. virtual STDMETHODIMP get_accHelpTopic(BSTR* pszHelpFile, VARIANT varChild, long* pidTopic);
  184. virtual STDMETHODIMP get_accKeyboardShortcut(VARIANT varChild, BSTR* pszKeyboardShortcut);
  185. virtual STDMETHODIMP get_accFocus(VARIANT * pvarFocusChild);
  186. virtual STDMETHODIMP get_accSelection(VARIANT * pvarSelectedChildren);
  187. virtual STDMETHODIMP get_accDefaultAction(VARIANT varChild, BSTR* pszDefaultAction);
  188. virtual STDMETHODIMP accSelect(long flagsSel, VARIANT varChild);
  189. virtual STDMETHODIMP accLocation(long* pxLeft, long* pyTop, long* pcxWidth, long* pcyHeight, VARIANT varChild);
  190. virtual STDMETHODIMP accNavigate(long navDir, VARIANT varStart, VARIANT * pvarEndUpAt);
  191. virtual STDMETHODIMP accHitTest(long xLeft, long yTop, VARIANT * pvarChildAtPoint);
  192. virtual STDMETHODIMP accDoDefaultAction(VARIANT varChild);
  193. virtual STDMETHODIMP put_accName(VARIANT varChild, BSTR szName);
  194. virtual STDMETHODIMP put_accValue(VARIANT varChild, BSTR pszValue);
  195. // IEnumVARIANT
  196. virtual STDMETHODIMP Next(ULONG celt, VARIANT* rgvar, ULONG * pceltFetched);
  197. virtual STDMETHODIMP Skip(ULONG celt);
  198. virtual STDMETHODIMP Reset(void);
  199. virtual STDMETHODIMP Clone(IEnumVARIANT ** ppenum);
  200. // IOleWindow
  201. virtual STDMETHODIMP GetWindow(HWND* phwnd);
  202. virtual STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
  203. };
  204. #endif // _CLSUTIL_H_