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.

148 lines
3.3 KiB

  1. #include "traycmn.h"
  2. #include "trayreg.h"
  3. #include "strsafe.h"
  4. //
  5. // CNotificationItem - encapsulate the data needed to communicate between the tray
  6. // and the tray properties dialog
  7. //
  8. CNotificationItem::CNotificationItem()
  9. {
  10. _Init();
  11. }
  12. CNotificationItem::CNotificationItem(const NOTIFYITEM& no)
  13. {
  14. _Init();
  15. CopyNotifyItem(no);
  16. }
  17. CNotificationItem::CNotificationItem(const CNotificationItem& no)
  18. {
  19. _Init();
  20. CopyNotifyItem(no);
  21. }
  22. CNotificationItem::CNotificationItem(const TNPersistStreamData* ptnpd)
  23. {
  24. _Init();
  25. CopyPTNPD(ptnpd);
  26. }
  27. inline void CNotificationItem::_Init()
  28. {
  29. hIcon = NULL;
  30. pszExeName = NULL;
  31. pszIconText = NULL;
  32. guidItem = GUID_NULL;
  33. }
  34. void CNotificationItem::CopyNotifyItem(const NOTIFYITEM& no, BOOL bInsert /* = TRUE */)
  35. {
  36. hWnd = no.hWnd;
  37. uID = no.uID;
  38. if (bInsert)
  39. dwUserPref = no.dwUserPref;
  40. hIcon = CopyIcon(no.hIcon);
  41. SetExeName(no.pszExeName);
  42. SetIconText(no.pszIconText);
  43. memcpy(&guidItem, &(no.guidItem), sizeof(no.guidItem));
  44. }
  45. const CNotificationItem& CNotificationItem::operator=(const TNPersistStreamData* ptnpd)
  46. {
  47. if (ptnpd)
  48. {
  49. _Free();
  50. _Init();
  51. CopyPTNPD(ptnpd);
  52. }
  53. return *this;
  54. }
  55. const CNotificationItem& CNotificationItem::operator=(const CNotificationItem& ni)
  56. {
  57. _Free();
  58. _Init();
  59. CopyNotifyItem(ni, FALSE);
  60. return *this;
  61. }
  62. void CNotificationItem::CopyPTNPD(const TNPersistStreamData* ptnpd)
  63. {
  64. if (ptnpd)
  65. {
  66. hWnd = NULL; // ptnpd's dont have any hWnd
  67. uID = ptnpd->uID;
  68. dwUserPref = ptnpd->dwUserPref;
  69. hIcon = NULL; // TO DO : Save and load icon
  70. SetExeName(ptnpd->szExeName);
  71. SetIconText(ptnpd->szIconText);
  72. memcpy(&guidItem, &(ptnpd->guidItem), sizeof(ptnpd->guidItem));
  73. }
  74. }
  75. inline void CNotificationItem::CopyBuffer(LPCTSTR lpszSrc, LPTSTR * plpszDest)
  76. {
  77. if (*plpszDest)
  78. {
  79. delete[] *plpszDest;
  80. *plpszDest = NULL;
  81. }
  82. int nStringLen = (lpszSrc == NULL) ? 0 : lstrlen(lpszSrc);
  83. if (nStringLen)
  84. {
  85. *plpszDest = new TCHAR[(nStringLen+1)];
  86. if (*plpszDest)
  87. {
  88. if (SUCCEEDED(StringCchCopy(*plpszDest, nStringLen+1, lpszSrc)))
  89. return;
  90. else
  91. delete [] *plpszDest;
  92. }
  93. }
  94. *plpszDest = NULL;
  95. }
  96. inline void CNotificationItem::SetExeName(LPCTSTR lpszExeName)
  97. {
  98. CopyBuffer(lpszExeName, &pszExeName);
  99. }
  100. inline void CNotificationItem::SetIconText(LPCTSTR lpszIconText)
  101. {
  102. CopyBuffer(lpszIconText, &pszIconText);
  103. }
  104. CNotificationItem::~CNotificationItem()
  105. {
  106. _Free();
  107. }
  108. void CNotificationItem::_Free()
  109. {
  110. if (hIcon != NULL)
  111. DestroyIcon(hIcon);
  112. if (pszExeName)
  113. delete [] pszExeName;
  114. if (pszIconText)
  115. delete [] pszIconText;
  116. }
  117. BOOL CNotificationItem::operator==(CNotificationItem& ni) const
  118. {
  119. if (uID == ni.uID)
  120. {
  121. if ((hWnd != NULL && hWnd == ni.hWnd) ||
  122. (hWnd == NULL && pszExeName && lstrcmpi(pszExeName, ni.pszExeName) == 0))
  123. return TRUE;
  124. }
  125. return FALSE;
  126. }