libui/windows/control.cpp

109 lines
2.9 KiB
C++
Raw Normal View History

// 16 august 2015
#include "uipriv_windows.hpp"
void uiWindowsControlSyncEnableState(uiWindowsControl *c, int enabled)
{
(*(c->SyncEnableState))(c, enabled);
}
void uiWindowsControlSetParentHWND(uiWindowsControl *c, HWND parent)
{
(*(c->SetParentHWND))(c, parent);
}
void uiWindowsControlMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *height)
{
(*(c->MinimumSize))(c, width, height);
}
void uiWindowsControlMinimumSizeChanged(uiWindowsControl *c)
{
(*(c->MinimumSizeChanged))(c);
}
void uiWindowsControlLayoutRect(uiWindowsControl *c, RECT *r)
{
(*(c->LayoutRect))(c, r);
}
2016-04-27 16:51:33 -05:00
void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *c, LONG_PTR *controlID, HWND *insertAfter)
{
(*(c->AssignControlIDZOrder))(c, controlID, insertAfter);
}
HWND uiWindowsEnsureCreateControlHWND(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, HINSTANCE hInstance, LPVOID lpParam, BOOL useStandardControlFont)
{
HWND hwnd;
2015-09-02 17:26:48 -05:00
// don't let using the arrow keys in a uiRadioButtons leave the radio buttons
if ((dwStyle & WS_TABSTOP) != 0)
dwStyle |= WS_GROUP;
hwnd = CreateWindowExW(dwExStyle,
lpClassName, lpWindowName,
dwStyle | WS_CHILD | WS_VISIBLE,
0, 0,
// use a nonzero initial size just in case some control breaks with a zero initial size
100, 100,
utilWindow, NULL, hInstance, lpParam);
if (hwnd == NULL) {
logLastError(L"error creating window");
// TODO return a decoy window
}
if (useStandardControlFont)
SendMessageW(hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE);
return hwnd;
}
// choose a value distinct from uiWindowSignature
#define uiWindowsControlSignature 0x4D53576E
uiWindowsControl *uiWindowsAllocControl(size_t n, uint32_t typesig, const char *typenamestr)
{
return uiWindowsControl(uiAllocControl(n, uiWindowsControlSignature, typesig, typenamestr));
}
BOOL uiWindowsShouldStopSyncEnableState(uiWindowsControl *c, BOOL enabled)
{
int ce;
ce = uiControlEnabled(uiControl(c));
// only stop if we're going from disabled back to enabled; don't stop under any other condition
// (if we stop when going from enabled to disabled then enabled children of a disabled control won't get disabled at the OS level)
if (!ce && enabled)
return TRUE;
return FALSE;
}
2016-04-27 16:51:33 -05:00
void uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl *c)
{
LONG_PTR controlID;
HWND insertAfter;
controlID = 100;
insertAfter = NULL;
uiWindowsControlAssignControlIDZOrder(c, &controlID, &insertAfter);
2016-04-27 16:51:33 -05:00
}
BOOL uiWindowsControlTooSmall(uiWindowsControl *c)
{
RECT r;
intmax_t width, height;
uiWindowsControlLayoutRect(c, &r);
uiWindowsControlMinimumSize(c, &width, &height);
if ((r.right - r.left) < width)
return TRUE;
if ((r.bottom - r.top) < height)
return TRUE;
return FALSE;
}
void uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl *c)
{
uiControl *parent;
parent = uiControlParent(uiControl(c));
if (parent != NULL)
uiWindowsControlMinimumSizeChanged(uiWindowsControl(parent));
}