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.

133 lines
4.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: dispobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // DispObj.cpp : Implementation of CMMCDisplayObject
  11. #include "stdafx.h"
  12. #include "cic.h"
  13. #include "DispObj.h"
  14. #include "mmc.h"
  15. #include <wtypes.h>
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CMMCDisplayObject
  18. CMMCDisplayObject::CMMCDisplayObject()
  19. {
  20. m_type = MMC_TASK_DISPLAY_UNINITIALIZED;
  21. m_bstrFontFamilyName =
  22. m_bstrURLtoEOT =
  23. m_bstrSymbolString =
  24. m_bstrMouseOffBitmap =
  25. m_bstrMouseOverBitmap = NULL;
  26. }
  27. CMMCDisplayObject::~CMMCDisplayObject()
  28. {
  29. if (m_bstrFontFamilyName) SysFreeString(m_bstrFontFamilyName);
  30. if (m_bstrURLtoEOT) SysFreeString(m_bstrURLtoEOT);
  31. if (m_bstrSymbolString) SysFreeString(m_bstrSymbolString);
  32. if (m_bstrMouseOffBitmap) SysFreeString(m_bstrMouseOffBitmap);
  33. if (m_bstrMouseOverBitmap) SysFreeString(m_bstrMouseOverBitmap);
  34. }
  35. STDMETHODIMP CMMCDisplayObject::get_DisplayObjectType(long* pVal)
  36. {
  37. *pVal = m_type;
  38. return S_OK;
  39. }
  40. STDMETHODIMP CMMCDisplayObject::get_FontFamilyName (BSTR* pVal)
  41. {
  42. if (m_bstrFontFamilyName)
  43. *pVal = SysAllocString ((const OLECHAR *)m_bstrFontFamilyName);
  44. return S_OK;
  45. }
  46. STDMETHODIMP CMMCDisplayObject::get_URLtoEOT (BSTR* pVal)
  47. {
  48. if (m_bstrURLtoEOT)
  49. *pVal = SysAllocString ((const OLECHAR *)m_bstrURLtoEOT);
  50. return S_OK;
  51. }
  52. STDMETHODIMP CMMCDisplayObject::get_SymbolString (BSTR* pVal)
  53. {
  54. if (m_bstrSymbolString)
  55. *pVal = SysAllocString ((const OLECHAR *)m_bstrSymbolString);
  56. return S_OK;
  57. }
  58. STDMETHODIMP CMMCDisplayObject::get_MouseOffBitmap (BSTR* pVal)
  59. {
  60. if (m_bstrMouseOffBitmap)
  61. *pVal = SysAllocString ((const OLECHAR *)m_bstrMouseOffBitmap);
  62. return S_OK;
  63. }
  64. STDMETHODIMP CMMCDisplayObject::get_MouseOverBitmap (BSTR* pVal)
  65. {
  66. if (m_bstrMouseOverBitmap)
  67. *pVal = SysAllocString ((const OLECHAR *)m_bstrMouseOverBitmap);
  68. return S_OK;
  69. }
  70. HRESULT CMMCDisplayObject::Init(MMC_TASK_DISPLAY_OBJECT* pdo)
  71. {
  72. _ASSERT (m_type == MMC_TASK_DISPLAY_UNINITIALIZED);
  73. if (m_type != MMC_TASK_DISPLAY_UNINITIALIZED)
  74. return E_UNEXPECTED; // only allowed in here once
  75. switch (m_type = pdo->eDisplayType) {
  76. default:
  77. case MMC_TASK_DISPLAY_UNINITIALIZED:
  78. // _ASSERT (0 && "uninitialized MMC_TASK_DISPLAY_OBJECT struct");
  79. return E_INVALIDARG;
  80. case MMC_TASK_DISPLAY_TYPE_SYMBOL: // fontname, EOT, symbols
  81. // all three fields MUST be filled out
  82. _ASSERT (pdo->uSymbol.szFontFamilyName && pdo->uSymbol.szURLtoEOT && pdo->uSymbol.szSymbolString);
  83. if (!(pdo->uSymbol.szFontFamilyName && pdo->uSymbol.szURLtoEOT && pdo->uSymbol.szSymbolString))
  84. return E_INVALIDARG;
  85. m_bstrFontFamilyName = SysAllocString (pdo->uSymbol.szFontFamilyName);
  86. m_bstrURLtoEOT = SysAllocString (pdo->uSymbol.szURLtoEOT);
  87. m_bstrSymbolString = SysAllocString (pdo->uSymbol.szSymbolString);
  88. if (m_bstrFontFamilyName && m_bstrURLtoEOT && m_bstrSymbolString)
  89. return S_OK;
  90. return E_OUTOFMEMORY;
  91. break;
  92. case MMC_TASK_DISPLAY_TYPE_VANILLA_GIF: // (GIF) index 0 is transparent
  93. case MMC_TASK_DISPLAY_TYPE_CHOCOLATE_GIF: // (GIF) index 1 is transparent
  94. case MMC_TASK_DISPLAY_TYPE_BITMAP: // non-transparent raster
  95. if ( pdo->uBitmap.szMouseOffBitmap &&
  96. pdo->uBitmap.szMouseOverBitmap ){
  97. // if they both exist, like they're supposed to
  98. m_bstrMouseOffBitmap = SysAllocString (pdo->uBitmap.szMouseOffBitmap);
  99. m_bstrMouseOverBitmap = SysAllocString (pdo->uBitmap.szMouseOverBitmap);
  100. } else if (pdo->uBitmap.szMouseOverBitmap) {
  101. // if only MouseOver image exists:
  102. // not too bad since it's probably color
  103. m_bstrMouseOffBitmap = SysAllocString (pdo->uBitmap.szMouseOverBitmap);
  104. m_bstrMouseOverBitmap = SysAllocString (pdo->uBitmap.szMouseOverBitmap);
  105. } else if (pdo->uBitmap.szMouseOffBitmap) {
  106. // if only MouseOff image exists:
  107. // they're being bad, but not too bad
  108. m_bstrMouseOffBitmap = SysAllocString (pdo->uBitmap.szMouseOffBitmap);
  109. m_bstrMouseOverBitmap = SysAllocString (pdo->uBitmap.szMouseOffBitmap);
  110. } else {
  111. // else they're really bad
  112. _ASSERT (0 && "MMC_TASK_DISPLAY_BITMAP uninitialized");
  113. return E_INVALIDARG;
  114. }
  115. if (m_bstrMouseOffBitmap && m_bstrMouseOverBitmap)
  116. return S_OK;
  117. return E_OUTOFMEMORY;
  118. break;
  119. }
  120. return E_UNEXPECTED; // can't get here
  121. }