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.

140 lines
4.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000
  6. //
  7. // File: cpduihlp.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __CONTROLPANEL_DUIHELPERS_H
  11. #define __CONTROLPANEL_DUIHELPERS_H
  12. #include "cpviewp.h"
  13. namespace CPL {
  14. HRESULT Dui_FindDescendent(DUI::Element *pe, LPCWSTR pszDescendent, DUI::Element **ppeDescendent);
  15. HRESULT Dui_GetStyleSheet(DUI::Parser *pParser, LPCWSTR pszSheet, DUI::Value **ppvSheet);
  16. HRESULT Dui_SetElementText(DUI::Element *peElement, LPCWSTR pszText);
  17. HRESULT Dui_SetDescendentElementText(DUI::Element *peElement, LPCWSTR pszDescendent, LPCWSTR pszText);
  18. HRESULT Dui_SetDescendentElementIcon(DUI::Element *peElement, LPCWSTR pszDescendent, HICON hIcon);
  19. HRESULT Dui_CreateElement(DUI::Parser *pParser, LPCWSTR pszTemplate, DUI::Element *peSubstitute, DUI::Element **ppe);
  20. HRESULT Dui_CreateElementWithStyle(DUI::Parser *pParser, LPCWSTR pszTemplate, LPCWSTR pszStyleSheet, DUI::Element **ppe);
  21. HRESULT Dui_DestroyDescendentElement(DUI::Element *pe, LPCWSTR pszDescendent);
  22. HRESULT Dui_CreateString(LPCWSTR pszText, DUI::Value **ppvString);
  23. HRESULT Dui_CreateGraphic(HICON hIcon, DUI::Value **ppValue);
  24. HRESULT Dui_GetElementExtent(DUI::Element *pe, SIZE *pext);
  25. HRESULT Dui_GetElementRootHWND(DUI::Element *pe, HWND *phwnd);
  26. HRESULT Dui_SetElementIcon(DUI::Element *pe, HICON hIcon);
  27. HRESULT Dui_MapElementPointToRootHWND(DUI::Element *pe, const POINT& ptElement, POINT *pptRoot, HWND *phwndRoot = NULL);
  28. HRESULT Dui_SetElementProperty_Int(DUI::Element *pe, DUI::PropertyInfo *ppi, int i);
  29. HRESULT Dui_SetElementProperty_String(DUI::Element *pe, DUI::PropertyInfo *ppi, LPCWSTR psz);
  30. HRESULT Dui_CreateParser(const char *pszUiFile, int cchUiFile, HINSTANCE hInstance, DUI::Parser **ppParser);
  31. inline HRESULT
  32. Dui_SetValue(
  33. DUI::Element *pe,
  34. DUI::PropertyInfo *ppi,
  35. DUI::Value *pv
  36. )
  37. {
  38. return pe->SetValue(ppi, PI_Local, pv);
  39. }
  40. #define Dui_SetElementProperty(pe, prop, pv) Dui_SetValue((pe), DUI::Element::##prop, (pv))
  41. #define Dui_SetElementPropertyInt(pe, prop, i) Dui_SetElementProperty_Int((pe), DUI::Element::##prop, (i))
  42. #define Dui_SetElementPropertyString(pe, prop, s) Dui_SetElementProperty_String((pe), DUI::Element::##prop, (s))
  43. inline HRESULT
  44. Dui_SetElementStyleSheet(
  45. DUI::Element *pe,
  46. DUI::Value *pvSheet
  47. )
  48. {
  49. return Dui_SetElementProperty(pe, SheetProp, pvSheet);
  50. }
  51. struct ATOMINFO
  52. {
  53. LPCWSTR pszName;
  54. ATOM *pAtom;
  55. };
  56. HRESULT Dui_AddAtom(LPCWSTR pszName, ATOM *pAtom);
  57. HRESULT Dui_DeleteAtom(ATOM atom);
  58. HRESULT Dui_AddOrDeleteAtoms(struct ATOMINFO *pAtomInfo, UINT cEntries, bool bAdd);
  59. inline HRESULT Dui_AddAtoms(struct ATOMINFO *pAtomInfo, UINT cEntries)
  60. {
  61. return Dui_AddOrDeleteAtoms(pAtomInfo, cEntries, true);
  62. }
  63. inline HRESULT Dui_DeleteAtoms(struct ATOMINFO *pAtomInfo, UINT cEntries)
  64. {
  65. return Dui_AddOrDeleteAtoms(pAtomInfo, cEntries, true);
  66. }
  67. //
  68. // This is a simple smart-pointer class for DUI::Value pointers.
  69. // It's important that the referenced DUI::Value object be released when the
  70. // pointer is no longer needed. Use of this class ensures proper cleanup
  71. // when the object goes out of scope.
  72. //
  73. class CDuiValuePtr
  74. {
  75. public:
  76. CDuiValuePtr(DUI::Value *pv = NULL)
  77. : m_pv(pv),
  78. m_bOwns(true) { }
  79. CDuiValuePtr(const CDuiValuePtr& rhs)
  80. : m_bOwns(false),
  81. m_pv(NULL) { Attach(rhs.Detach()); }
  82. CDuiValuePtr& operator = (const CDuiValuePtr& rhs);
  83. ~CDuiValuePtr(void)
  84. { _Release(); }
  85. DUI::Value *Detach(void) const;
  86. void Attach(DUI::Value *pv);
  87. DUI::Value **operator & ()
  88. { ASSERTMSG(NULL == m_pv, "Attempt to overwrite non-NULL pointer value");
  89. m_bOwns = true;
  90. return &m_pv;
  91. }
  92. operator !() const
  93. { return NULL == m_pv; }
  94. bool IsNULL(void) const
  95. { return NULL == m_pv; }
  96. operator const DUI::Value*() const
  97. { return m_pv; }
  98. operator DUI::Value*()
  99. { return m_pv; }
  100. private:
  101. mutable DUI::Value *m_pv;
  102. mutable bool m_bOwns;
  103. void _Release(void);
  104. void _ReleaseAndReset(void);
  105. };
  106. } // namespace CPL
  107. #endif // __CONTROLPANEL_DUIHELPERS_H