#include "uipriv_windows.hpp"
#define tabMargin 7
static void tabPageMargins(struct tabPage *tp, int *mx, int *my)
{
uiWindowsSizing sizing;
*mx = 0;
*my = 0;
if (!tp->margined)
return;
uiWindowsGetSizing(tp->hwnd, &sizing);
*mx = tabMargin;
*my = tabMargin;
uiWindowsSizingDlgUnitsToPixels(&sizing, mx, my);
}
static void tabPageRelayout(struct tabPage *tp)
{
RECT r;
int mx, my;
HWND child;
if (tp->child == NULL)
return;
uiWindowsEnsureGetClientRect(tp->hwnd, &r);
tabPageMargins(tp, &mx, &my);
r.left += mx;
r.top += my;
r.right -= mx;
r.bottom -= my;
child = (HWND) uiControlHandle(tp->child);
uiWindowsEnsureMoveWindowDuringResize(child, r.left, r.top, r.right - r.left, r.bottom - r.top);
}
static INT_PTR CALLBACK dlgproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
struct tabPage *tp;
LRESULT lResult;
if (uMsg == WM_INITDIALOG) {
tp = (struct tabPage *) lParam;
tp->hwnd = hwnd;
SetWindowLongPtrW(hwnd, DWLP_USER, (LONG_PTR) tp);
return TRUE;
}
if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) {
SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (LONG_PTR) lResult);
return TRUE;
}
if (uMsg == WM_WINDOWPOSCHANGED) {
tp = (struct tabPage *) GetWindowLongPtrW(hwnd, DWLP_USER);
tabPageRelayout(tp);
return FALSE;
}
if (uMsg == WM_PRINTCLIENT) {
SendMessageW(hwnd, WM_ERASEBKGND, wParam, lParam);
return FALSE;
}
return FALSE;
}
static const uint8_t data_rcTabPageDialog[] = {
0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x04, 0x00, 0x50,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00,
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static_assert(ARRAYSIZE(data_rcTabPageDialog) == 32, "wrong size for resource rcTabPageDialog");
struct tabPage *newTabPage(uiControl *child)
{
struct tabPage *tp;
HRESULT hr;
tp = uiprivNew(struct tabPage);
if (CreateDialogIndirectParamW(hInstance, (const DLGTEMPLATE *) data_rcTabPageDialog,
utilWindow, dlgproc, (LPARAM) tp) == NULL)
logLastError(L"error creating tab page");
tp->child = child;
if (tp->child != NULL) {
uiWindowsEnsureSetParentHWND((HWND) uiControlHandle(tp->child), tp->hwnd);
uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl(tp->child));
}
hr = EnableThemeDialogTexture(tp->hwnd, ETDT_ENABLE | ETDT_USETABTEXTURE | ETDT_ENABLETAB);
if (hr != S_OK)
logHRESULT(L"error setting tab page background", hr);
ShowWindow(tp->hwnd, SW_HIDE);
return tp;
}
void tabPageDestroy(struct tabPage *tp)
{
if (tp->child != NULL)
uiWindowsControlSetParentHWND(uiWindowsControl(tp->child), NULL);
uiWindowsEnsureDestroyWindow(tp->hwnd);
uiprivFree(tp);
}
void tabPageMinimumSize(struct tabPage *tp, int *width, int *height)
{
int mx, my;
*width = 0;
*height = 0;
if (tp->child != NULL)
uiWindowsControlMinimumSize(uiWindowsControl(tp->child), width, height);
tabPageMargins(tp, &mx, &my);
*width += 2 * mx;
*height += 2 * my;
}