skinneddivider.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "./skinneddivider.h"
  2. #include "../winamp/wa_dlg.h"
  3. #include "./skinning.h"
  4. SkinnedDivider::SkinnedDivider(void) : SkinnedWnd(FALSE)
  5. {
  6. callback = NULL;
  7. userParam = 0L;
  8. clickoffs = 0;
  9. }
  10. SkinnedDivider::~SkinnedDivider(void)
  11. {
  12. }
  13. BOOL SkinnedDivider::Attach(HWND hwndDivider)
  14. {
  15. if(!SkinnedWnd::Attach(hwndDivider)) return FALSE;
  16. SetType(SKINNEDWND_TYPE_DIVIDER);
  17. SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
  18. return TRUE;
  19. }
  20. BOOL SkinnedDivider::OnMediaLibraryIPC(INT msg, INT_PTR param, LRESULT *pResult)
  21. {
  22. switch(msg)
  23. {
  24. case ML_IPC_SKINNEDDIVIDER_SETCALLBACK:
  25. if ( 0 != param)
  26. {
  27. callback = ((MLDIVIDERCALLBACK*)param)->fnCallback;
  28. userParam = ((MLDIVIDERCALLBACK*)param)->userParam;
  29. }
  30. else { callback = NULL; userParam= 0L;}
  31. return TRUE;
  32. }
  33. return __super::OnMediaLibraryIPC(msg, param, pResult);
  34. }
  35. void SkinnedDivider::OnPaint(void)
  36. {
  37. PAINTSTRUCT ps;
  38. RECT rc, rh;
  39. HDC hdc = BeginPaint(hwnd, &ps);
  40. GetClientRect(hwnd, &rc);
  41. SetBkColor(hdc, WADlg_getColor(WADLG_WNDBG));
  42. if (SWDIV_NOHILITE & style)
  43. {
  44. ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, L"", 0, NULL);
  45. }
  46. else
  47. {
  48. int l;
  49. HPEN pen = (HPEN)MlStockObjects_Get(HILITE_PEN),
  50. penOld = (HPEN)SelectObject(hdc, pen);
  51. if (SWDIV_VERT & style)
  52. {
  53. l = (rc.right - rc.left)/2 - 1;
  54. SetRect(&rh, ps.rcPaint.left, ps.rcPaint.top, l, ps.rcPaint.bottom);
  55. if (rh.left < rh.right) ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rh, L"", 0, 0);
  56. SetRect(&rh, l + 1, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
  57. if (rh.left < rh.right) ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rh, L"", 0, 0);
  58. MoveToEx(hdc, l, rc.top, NULL);
  59. LineTo(hdc, l, rc.bottom);
  60. }
  61. else
  62. {
  63. l = (rc.bottom - rc.top)/2 - 1;
  64. SetRect(&rh, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, l);
  65. if (rh.top < rh.bottom) ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rh, L"", 0, 0);
  66. SetRect(&rh, ps.rcPaint.left, l + 1, ps.rcPaint.right, ps.rcPaint.bottom);
  67. if (rh.left < rh.right) ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rh, L"", 0, 0);
  68. MoveToEx(hdc, rc.left, l, NULL);
  69. LineTo(hdc, rc.right, l);
  70. }
  71. SelectObject(hdc, penOld);
  72. }
  73. EndPaint(hwnd, &ps);
  74. }
  75. LRESULT SkinnedDivider::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  76. {
  77. switch(uMsg)
  78. {
  79. case WM_NCHITTEST: return HTCLIENT;
  80. case WM_ERASEBKGND: return 0;
  81. case WM_PAINT: OnPaint(); return 0;
  82. case WM_LBUTTONDOWN:
  83. clickoffs = (SWDIV_VERT & style) ? LOWORD(lParam) : HIWORD(lParam);
  84. SetCapture(hwnd);
  85. break;
  86. case WM_LBUTTONUP:
  87. ReleaseCapture();
  88. clickoffs = 0;
  89. break;
  90. case WM_SETCURSOR:
  91. SetCursor(LoadCursor(NULL, (SWDIV_VERT & style) ? IDC_SIZEWE : IDC_SIZENS));
  92. return TRUE;
  93. case WM_MOUSEMOVE:
  94. if (GetCapture() == hwnd)
  95. {
  96. RECT rw;
  97. BOOL vert = (SWDIV_VERT & style);
  98. GetWindowRect(hwnd, &rw);
  99. GetCursorPos(((LPPOINT)&rw) + 1);
  100. (SWDIV_VERT & style) ? rw.right -= clickoffs : rw.bottom -= clickoffs;
  101. if ((vert && rw.left != rw.right) || (!vert && rw.top != rw.bottom))
  102. {
  103. MapWindowPoints(HWND_DESKTOP, GetParent(hwnd), ((LPPOINT)&rw) + 1, 1);
  104. if (callback) callback(hwnd, (vert) ? rw.right : rw.bottom, userParam);
  105. }
  106. }
  107. break;
  108. }
  109. return __super::WindowProc(uMsg, wParam, lParam);
  110. }