1
0

toolbarItem.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "main.h"
  2. #include "./toolbarItem.h"
  3. #include "./toolbar.h"
  4. #include "./graphics.h"
  5. #include "./resource.h"
  6. #include "../Plugins/General/gen_ml/ml_ipc_0313.h"
  7. #include <strsafe.h>
  8. ToolbarItem::ToolbarItem(LPCSTR pszName, UINT nStyle, INT nIcon, LPCWSTR pszText, LPCWSTR pszDescription)
  9. : ref(1), name(NULL), style(nStyle), iconId(nIcon), text(NULL), description(NULL)
  10. {
  11. name = Plugin_CopyAnsiString(pszName);
  12. text = Plugin_DuplicateResString(pszText);
  13. description = Plugin_DuplicateResString(pszDescription);
  14. }
  15. ToolbarItem::~ToolbarItem()
  16. {
  17. Plugin_FreeAnsiString(name);
  18. Plugin_FreeResString(text);
  19. Plugin_FreeResString(description);
  20. }
  21. ULONG ToolbarItem::AddRef()
  22. {
  23. return InterlockedIncrement((LONG*)&ref);
  24. }
  25. ULONG ToolbarItem::Release()
  26. {
  27. if (0 == ref) return ref;
  28. LONG r = InterlockedDecrement((LONG*)&ref);
  29. if (0 == r) delete(this);
  30. return r;
  31. }
  32. LPCSTR ToolbarItem::GetName()
  33. {
  34. return name;
  35. }
  36. UINT ToolbarItem::GetStyle()
  37. {
  38. return style;
  39. }
  40. void ToolbarItem::SetStyle(HWND hToolbar, UINT newStyle, UINT styleMask)
  41. {
  42. UINT styleNew = (style & ~styleMask) | (newStyle & styleMask);
  43. if (style != styleNew)
  44. {
  45. style = styleNew;
  46. if (NULL != hToolbar && 0 == (stateHidden & style))
  47. InvalidateRect(hToolbar, &rect, FALSE);
  48. }
  49. }
  50. BOOL ToolbarItem::SetRect(const RECT *prc)
  51. {
  52. return CopyRect(&rect, prc);
  53. }
  54. BOOL ToolbarItem::GetRect(RECT *prc)
  55. {
  56. return CopyRect(prc, &rect);
  57. }
  58. BOOL ToolbarItem::OffsetRect(INT dx, INT dy)
  59. {
  60. return ::OffsetRect(&rect, dx, dy);
  61. }
  62. BOOL ToolbarItem::SetRectEmpty()
  63. {
  64. return ::SetRectEmpty(&rect);
  65. }
  66. BOOL ToolbarItem::IsRectEmpty()
  67. {
  68. return ::IsRectEmpty(&rect);
  69. }
  70. BOOL ToolbarItem::PtInRect(POINT pt)
  71. {
  72. return ::PtInRect(&rect, pt);
  73. }
  74. BOOL ToolbarItem::PtInItem(POINT pt)
  75. {
  76. return (pt.x >= rect.left && pt.x < rect.right && rect.bottom != rect.top);
  77. }
  78. BOOL ToolbarItem::IntersectRect(RECT *prcDst, const RECT *prcSrc)
  79. {
  80. return ::IntersectRect(prcDst, &rect, prcSrc);
  81. }
  82. BOOL ToolbarItem::IsEqual(LPCSTR pszName, INT cchName)
  83. {
  84. return (NULL != name && CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, NORM_IGNORECASE, pszName, cchName, name, -10));
  85. }
  86. BOOL ToolbarItem::SetDescription(HWND hToolbar, LPCWSTR pszDescription)
  87. {
  88. Plugin_FreeResString(description);
  89. description = Plugin_DuplicateResString(pszDescription);
  90. return TRUE;
  91. }
  92. HRESULT ToolbarItem::GetText(LPWSTR pszBuffer, UINT cchBufferMax)
  93. {
  94. return Plugin_CopyResString(pszBuffer, cchBufferMax, text);
  95. }
  96. HRESULT ToolbarItem::GetDescription(LPWSTR pszBuffer, UINT cchBufferMax)
  97. {
  98. return Plugin_CopyResString(pszBuffer, cchBufferMax, description);
  99. }