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.

146 lines
3.1 KiB

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