#include "alfpriv.h" TCHAR *_alf_panelClass = NULL; typedef struct { ALFLayout layout; const ALFPanelVTable *vtbl; void *closure; } ALFPanelPriv; static void ALF_Panel_IntializePriv(ALFPanelPriv *priv) { ALF_Layout_Init(&priv->layout); } static void ALF_Panel_ClearPriv(ALFPanelPriv *priv) { ALF_Layout_Clear(&priv->layout); } static void ALF_Panel_InternalDefPaint(ALFPanelPriv *priv, HWND hwnd, HDC dc, RECT *r) { if (priv->layout.bgcolor == ALF_COLOR_TRANSPARENT) { ALF_Compat_DrawThemeParentBackground(hwnd, dc, r); } else { ALF_FillRect(dc, r, priv->layout.bgcolor); } } void ALF_Panel_DefPaint(HWND panel, HDC hDC, RECT *rcPaint) { ALFPanelPriv *priv = (ALFPanelPriv*)GetWindowLongPtr(panel, 0); ALF_Panel_InternalDefPaint(priv, panel, hDC, rcPaint); } static void ALF_Panel_Paint(ALFPanelPriv *priv, HWND hwnd, HDC dc, RECT *r) { if (priv->vtbl && priv->vtbl->paint) { priv->vtbl->paint(priv->closure, hwnd, dc, r); } else { ALF_Panel_InternalDefPaint(priv, hwnd, dc, r); } } void ALF_Panel_SetVTable(HWND panel, const ALFPanelVTable *vtbl, void *closure) { ALFPanelSetVtblParams p = { vtbl, closure }; SendMessage(panel, ALF_WM_PANEL_SETVTABLE, 0, (LPARAM)&p); } LRESULT ALF_Panel_DefWindowProc(HWND window, UINT msg, WPARAM wparam, LPARAM lparam) { ALFPanelPriv *priv = (ALFPanelPriv *)GetWindowLongPtr(window, 0); if (msg == WM_DESTROY) { if (priv->vtbl && priv->vtbl->destroy) priv->vtbl->destroy(priv->closure, window); } if (msg == WM_ERASEBKGND) { return TRUE; } if (msg == WM_PRINTCLIENT) { RECT r = { 0, 0, 0, 0 }; GetClientRect(window, &r); ALF_Panel_Paint(priv, window, (HDC)wparam, &r); return TRUE; } if (msg == WM_PAINT) { PAINTSTRUCT ps; HDC dc = BeginPaint(window, &ps); ALF_Panel_Paint(priv, window, dc, &ps.rcPaint); EndPaint(window, &ps); return 0; } if (msg == ALF_WM_PANEL_SETVTABLE) { const ALFPanelSetVtblParams *params = (const ALFPanelSetVtblParams *)lparam; if (!params) return FALSE; priv->vtbl = params->vtbl; priv->closure = params->closure; if (priv->vtbl->attachvtbl) { priv->vtbl->attachvtbl(priv->closure, window); } return TRUE; } if (ALF_ShouldMessageBubble(window, msg, wparam, lparam)) return SendMessage(GetParent(window), msg, wparam, lparam); if (msg == WM_SIZE) { ALF_Layout_Apply(&priv->layout, window); } LRESULT ret = 0; if (ALF_Layout_HandleMessage(&priv->layout, window, msg, wparam, lparam, &ret)) return ret; return DefWindowProc(window, msg, wparam, lparam); } static LRESULT WINAPI ALF__PanelWindowProc(HWND window, UINT msg, WPARAM wparam, LPARAM lparam) { if (msg == WM_NCCREATE) { ALFPanelPriv *p = ALF_New(ALFPanelPriv, 1); ALF_Panel_IntializePriv(p); SetWindowLongPtr(window, 0, (LONG_PTR)p); } ALFPanelPriv *priv = (ALFPanelPriv *)GetWindowLongPtr(window, 0); if (msg == WM_NCDESTROY) { ALF_Panel_ClearPriv(priv); ALF_Free(priv); priv = NULL; SetWindowLongPtr(window, 0, 0); } if (priv) { if (priv->vtbl && priv->vtbl->message) { return priv->vtbl->message(priv->closure, window, msg, wparam, lparam); } else { return ALF_Panel_DefWindowProc(window, msg, wparam, lparam); } } else { return DefWindowProc(window, msg, wparam, lparam); } } void ALF_RegisterPanelClass(void) { WNDCLASS cls; ZeroMemory(&cls, sizeof(cls)); TCHAR classNameBuf[256]; ALF_BuildUniqueName(classNameBuf, TEXT("ALFPanel."), (ULONG_PTR)&_alf_panelClass); cls.hInstance = ALF_HINSTANCE; cls.hCursor = LoadCursor(NULL, (LPTSTR)IDC_ARROW); cls.lpszClassName = classNameBuf; cls.cbWndExtra = sizeof(void*); cls.lpfnWndProc = ALF__PanelWindowProc; ATOM classatom = RegisterClass(&cls); if (!classatom) MessageBox(NULL, TEXT("FATAL: Could not register panel class"), NULL, MB_OK); _alf_panelClass = MAKEINTATOM(classatom); } HWND ALF_CreatePanelWindow(HWND parent, WORD id) { return CreateWindowEx(WS_EX_CONTROLPARENT, _alf_panelClass, TEXT(""), WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, 0, 0, 0, 0, parent, (HMENU)(int)id, ALF_HINSTANCE, NULL); } HWND ALF_AddPanel(HWND parent, WORD id, int x, int y) { HWND hwndPanel = ALF_CreatePanelWindow(parent, id); ALF_AddWidget(parent, x, y, hwndPanel, 0, 0, ALF_LAYOUT_SIZE_QUERY | ALF_LAYOUT_INHERITFONT | ALF_LAYOUT_INHERITBGCOLOR | ALF_LAYOUT_SENDBGCHANGE | ALF_LAYOUT_SENDDPICHANGE); return hwndPanel; }