1
0

toolbarStatic.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "main.h"
  2. #include "./toolbarStatic.h"
  3. #include "./toolbar.h"
  4. #include <strsafe.h>
  5. #define SPACER_WIDTH_UNITS 6
  6. #define SPACER_WIDTH_PX 8
  7. ToolbarStatic::ToolbarStatic(LPCSTR pszName, UINT nStyle, INT nIcon, LPCWSTR pszText, LPCWSTR pszDescription) :
  8. ToolbarItem(pszName, nStyle, nIcon, pszText, pszDescription), spaceWidth(SPACER_WIDTH_PX)
  9. {
  10. }
  11. ToolbarItem* CALLBACK ToolbarStatic::CreateInstance(ToolbarItem::Template *item)
  12. {
  13. if (NULL == item)
  14. return NULL;
  15. return new ToolbarStatic( (NULL != item->name) ? item->name : TOOLCLS_STATIC,
  16. (item->style | styleStatic),
  17. item->iconId,
  18. item->text,
  19. item->description);
  20. }
  21. BOOL ToolbarStatic::AdjustRect(HWND hToolbar, RECT *proposedRect)
  22. {
  23. if (0 != (styleSpacer & style))
  24. {
  25. if (0 == (styleFlexible & style) ||
  26. (proposedRect->right - proposedRect->left) < spaceWidth)
  27. {
  28. proposedRect->right = proposedRect->left + spaceWidth;
  29. }
  30. return TRUE;
  31. }
  32. if (0 != (styleSeparator & style))
  33. {
  34. SIZE iconSize;
  35. if (!Toolbar_GetIconSize(hToolbar, iconId, &iconSize))
  36. ZeroMemory(&iconSize, sizeof(SIZE));
  37. if (0 == (styleFlexible & style) ||
  38. (proposedRect->right - proposedRect->left) < iconSize.cx)
  39. {
  40. proposedRect->right = proposedRect->left + iconSize.cx;
  41. }
  42. proposedRect->top += ((proposedRect->bottom - proposedRect->top) - iconSize.cy)/2;
  43. proposedRect->bottom = proposedRect->top + iconSize.cy;
  44. return TRUE;
  45. }
  46. return FALSE;
  47. }
  48. BOOL ToolbarStatic::Paint(HWND hToolbar, HDC hdc, const RECT *paintRect, UINT state)
  49. {
  50. if (0 != (styleSpacer & style))
  51. return FALSE;
  52. if (0 != (styleSeparator & style))
  53. {
  54. TOOLBARDRAWICONPARAM param;
  55. param.hdcDst = hdc;
  56. param.iconIndex = iconId;
  57. param.x = rect.left;
  58. param.y = rect.top;
  59. param.cx = rect.right - rect.left;
  60. param.cy = rect.bottom - rect.top;
  61. param.itemState = state;
  62. return Toolbar_DrawIcon(hToolbar, &param);
  63. }
  64. return FALSE;
  65. }
  66. INT ToolbarStatic::GetTip(LPTSTR pszBuffer, INT cchBufferMax)
  67. {
  68. return 0;
  69. }
  70. void ToolbarStatic::UpdateSkin(HWND hToolbar)
  71. {
  72. spaceWidth = SPACER_WIDTH_PX;
  73. HDC hdc = GetDCEx(hToolbar, NULL, DCX_CACHE | DCX_NORESETATTRS);
  74. if (NULL != hdc)
  75. {
  76. HFONT font = (HFONT)SendMessage(hToolbar, WM_GETFONT, 0, 0L);
  77. HFONT originalFont = (HFONT)SelectObject(hdc, font);
  78. TEXTMETRIC tm;
  79. if (GetTextMetrics(hdc, &tm))
  80. {
  81. spaceWidth = MulDiv(SPACER_WIDTH_UNITS, tm.tmAveCharWidth, 4);
  82. }
  83. SelectObject(hdc, originalFont);
  84. ReleaseDC(hToolbar, hdc);
  85. }
  86. }
  87. BOOL ToolbarStatic::FillMenuInfo(HWND hToolbar, MENUITEMINFO *pmii, LPWSTR pszBuffer, INT cchBufferMax)
  88. {
  89. if (0 != ((styleSpacer | styleSeparator) & style))
  90. {
  91. pmii->fMask = MIIM_FTYPE;
  92. pmii->fType = MFT_MENUBREAK;
  93. return TRUE;
  94. }
  95. return FALSE;
  96. }