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.

134 lines
3.9 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_DestroyDescendentElement(DUI::Element *pe, LPCWSTR pszDescendent);
  21. HRESULT Dui_CreateString(LPCWSTR pszText, DUI::Value **ppvString);
  22. HRESULT Dui_CreateGraphic(HICON hIcon, DUI::Value **ppValue);
  23. HRESULT Dui_GetElementExtent(DUI::Element *pe, SIZE *pext);
  24. HRESULT Dui_GetElementRootHWND(DUI::Element *pe, HWND *phwnd);
  25. HRESULT Dui_SetElementIcon(DUI::Element *pe, HICON hIcon);
  26. HRESULT Dui_MapElementPointToRootHWND(DUI::Element *pe, const POINT& ptElement, POINT *pptRoot, HWND *phwndRoot = NULL);
  27. HRESULT Dui_CreateParser(const char *pszUiFile, int cchUiFile, HINSTANCE hInstance, DUI::Parser **ppParser);
  28. inline HRESULT
  29. Dui_SetValue(
  30. DUI::Element *pe,
  31. DUI::PropertyInfo *ppi,
  32. DUI::Value *pv
  33. )
  34. {
  35. return pe->SetValue(ppi, PI_Local, pv);
  36. }
  37. #define Dui_SetElementProperty(pe, prop, pv) Dui_SetValue((pe), DUI::Element::##prop, (pv))
  38. inline HRESULT
  39. Dui_SetElementStyleSheet(
  40. DUI::Element *pe,
  41. DUI::Value *pvSheet
  42. )
  43. {
  44. return Dui_SetElementProperty(pe, SheetProp, pvSheet);
  45. }
  46. struct ATOMINFO
  47. {
  48. LPCWSTR pszName;
  49. ATOM *pAtom;
  50. };
  51. HRESULT Dui_AddAtom(LPCWSTR pszName, ATOM *pAtom);
  52. HRESULT Dui_DeleteAtom(ATOM atom);
  53. HRESULT Dui_AddOrDeleteAtoms(struct ATOMINFO *pAtomInfo, UINT cEntries, bool bAdd);
  54. inline HRESULT Dui_AddAtoms(struct ATOMINFO *pAtomInfo, UINT cEntries)
  55. {
  56. return Dui_AddOrDeleteAtoms(pAtomInfo, cEntries, true);
  57. }
  58. inline HRESULT Dui_DeleteAtoms(struct ATOMINFO *pAtomInfo, UINT cEntries)
  59. {
  60. return Dui_AddOrDeleteAtoms(pAtomInfo, cEntries, true);
  61. }
  62. //
  63. // This is a simple smart-pointer class for DUI::Value pointers.
  64. // It's important that the referenced DUI::Value object be released when the
  65. // pointer is no longer needed. Use of this class ensures proper cleanup
  66. // when the object goes out of scope.
  67. //
  68. class CDuiValuePtr
  69. {
  70. public:
  71. CDuiValuePtr(DUI::Value *pv = NULL)
  72. : m_pv(pv),
  73. m_bOwns(true) { }
  74. CDuiValuePtr(const CDuiValuePtr& rhs)
  75. : m_bOwns(false),
  76. m_pv(NULL) { Attach(rhs.Detach()); }
  77. CDuiValuePtr& operator = (const CDuiValuePtr& rhs);
  78. ~CDuiValuePtr(void)
  79. { _Release(); }
  80. DUI::Value *Detach(void) const;
  81. void Attach(DUI::Value *pv);
  82. DUI::Value **operator & ()
  83. { ASSERTMSG(NULL == m_pv, "Attempt to overwrite non-NULL pointer value");
  84. m_bOwns = true;
  85. return &m_pv;
  86. }
  87. operator !() const
  88. { return NULL == m_pv; }
  89. bool IsNULL(void) const
  90. { return NULL == m_pv; }
  91. operator const DUI::Value*() const
  92. { return m_pv; }
  93. operator DUI::Value*()
  94. { return m_pv; }
  95. private:
  96. mutable DUI::Value *m_pv;
  97. mutable bool m_bOwns;
  98. void _Release(void);
  99. };
  100. } // namespace CPL
  101. #endif // __CONTROLPANEL_DUIHELPERS_H