From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/Plugins/Library/ml_disc/infoBox.cpp | 145 ++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 Src/Plugins/Library/ml_disc/infoBox.cpp (limited to 'Src/Plugins/Library/ml_disc/infoBox.cpp') diff --git a/Src/Plugins/Library/ml_disc/infoBox.cpp b/Src/Plugins/Library/ml_disc/infoBox.cpp new file mode 100644 index 00000000..23ea2313 --- /dev/null +++ b/Src/Plugins/Library/ml_disc/infoBox.cpp @@ -0,0 +1,145 @@ +#include "main.h" +#include ".\infoBox.h" + + +MLInfoBox::MLInfoBox(void) +{ + oldWndProc = NULL; + m_hwnd = NULL; + bodyBrush = NULL; + headerBrush = NULL; + headerText[0] = 0; + + SetColors(RGB(0,0,0), RGB(255,255,255), RGB(0,60,0)); + + SetRect(&rcBody, 0,0,0,0); + + drawHeader = TRUE; + SetRect(&rcHeader, 0,0,0,20); // default height + + headerFont = NULL; + +} +MLInfoBox::~MLInfoBox(void) +{ + SetWindowLong(m_hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)oldWndProc); + oldWndProc = NULL; + + if (headerBrush) DeleteObject(headerBrush); + headerBrush = NULL; + + if (bodyBrush) DeleteObject(bodyBrush); + bodyBrush = NULL; + + if (headerFont) DeleteObject(headerFont); + headerFont = NULL; + +} + +void MLInfoBox::SetColors(COLORREF bodyBG, COLORREF headerFG, COLORREF headerBG) +{ + this->bodyBG = bodyBG; + this->headerFG = headerFG; + this->headerBG = headerBG; + + if (headerBrush) DeleteObject(headerBrush); + headerBrush = NULL; + headerBrush = CreateSolidBrush(headerBG); + + if (bodyBrush) DeleteObject(bodyBrush); + bodyBrush = NULL; + bodyBrush = CreateSolidBrush(bodyBG); + +} + +void MLInfoBox::Init(HWND hwnd) +{ + m_hwnd = hwnd; + + HDC hdc = GetDC(hwnd); + long lfHeight; + lfHeight = -MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72); + headerFont = CreateFontW(lfHeight, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Arial"); + ReleaseDC(hwnd, hdc); + + SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONGX86)(LONG_PTR)this); + oldWndProc= (WNDPROC)(LONG_PTR)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)newWndProc); + RECT rc; + GetWindowRect(hwnd, &rc); + SetSize(rc.right - rc.left, rc.bottom - rc.top); +} + +void MLInfoBox::SetSize(int cx, int cy) +{ + int offset = 0; + if (drawHeader) + { + SetRect(&rcHeader, 0,0, cx, rcHeader.bottom); + offset = rcHeader.bottom; + } + SetRect(&rcBody, 0, offset, cx, cy); +} +LRESULT CALLBACK MLInfoBox::newWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam) +{ + MLInfoBox *box = (MLInfoBox*)(LONG_PTR)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + + switch(uMsg) + { + case WM_SIZE: + if (SIZE_MINIMIZED != wParam) + { + box->SetSize(LOWORD(lParam), HIWORD(lParam)); + } + break; + case WM_ERASEBKGND: + { + HDC hdc = GetDC(hwndDlg); + SetTextColor(hdc, box->headerFG); + SetBkColor(hdc, box->headerBG); + RECT txtRect; + SetRect(&txtRect, box->rcHeader.left + 8, box->rcHeader.top + 2, box->rcHeader.right -2, box->rcHeader.bottom -2); + HFONT oldFont = (HFONT)SelectObject(hdc, box->headerFont); + GetWindowTextW(hwndDlg, box->headerText, CAPTION_LENGTH); + DrawTextW(hdc, box->headerText, -1, &txtRect, DT_VCENTER | DT_LEFT | DT_SINGLELINE); + SelectObject(hdc, oldFont); + ReleaseDC(hwndDlg, hdc); + } + return TRUE; + + + break; + case WM_PAINT: + { + PAINTSTRUCT pt; + HDC hdc = BeginPaint(hwndDlg, &pt); + RECT drawRect ; + if(box->drawHeader && IntersectRect(&drawRect, &box->rcHeader, &pt.rcPaint)) + { + FillRect(hdc, &drawRect, box->headerBrush); + + SetTextColor(hdc, box->headerFG); + SetBkColor(hdc, box->headerBG); + SetRect(&drawRect, box->rcHeader.left + 8, box->rcHeader.top + 2, box->rcHeader.right -2, box->rcHeader.bottom -2); + HFONT oldFont = (HFONT)SelectObject(hdc, box->headerFont); + GetWindowTextW(hwndDlg, box->headerText, CAPTION_LENGTH); + DrawTextW(hdc, box->headerText, -1, &drawRect, DT_VCENTER | DT_LEFT | DT_SINGLELINE); + SelectObject(hdc, oldFont); + ValidateRect(hwndDlg, &drawRect); + } + + + if(IntersectRect(&drawRect, &box->rcBody, &pt.rcPaint)) + { + FillRect(hdc, &drawRect, box->bodyBrush); + ValidateRect(hwndDlg, &drawRect); + } + + EndPaint(hwndDlg, &pt); + } + break; + } + + return CallWindowProc(box->oldWndProc, hwndDlg, uMsg, wParam, lParam); +} + + \ No newline at end of file -- cgit