1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#if defined(Hiro_Viewport)
namespace hiro {
auto pViewport::construct() -> void {
hwnd = CreateWindow(L"hiroWidget", L"",
WS_CHILD | WS_DISABLED,
0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0);
pWidget::construct();
}
auto pViewport::destruct() -> void {
DestroyWindow(hwnd);
}
auto pViewport::handle() const -> uintptr_t {
return (uintptr_t)hwnd;
}
auto pViewport::setDroppable(bool droppable) -> void {
DragAcceptFiles(hwnd, droppable);
}
auto pViewport::setFocusable(bool focusable) -> void {
//handled by windowProc()
}
//
auto pViewport::doMouseLeave() -> void {
return self().doMouseLeave();
}
auto pViewport::doMouseMove(s32 x, s32 y) -> void {
return self().doMouseMove({x, y});
}
auto pViewport::windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> maybe<LRESULT> {
if(msg == WM_DROPFILES) {
if(auto paths = DropPaths(wparam)) self().doDrop(paths);
return false;
}
if(msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN || msg == WM_KEYUP || msg == WM_SYSKEYUP) {
if(self().focusable()) return true;
}
if(msg == WM_ERASEBKGND) {
return false;
}
if(msg == WM_PAINT) {
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
auto brush = CreateSolidBrush(RGB(0, 0, 0));
RECT rc{};
GetClientRect(hwnd, &rc);
FillRect(ps.hdc, &rc, brush);
DeleteObject(brush);
EndPaint(hwnd, &ps);
return true;
}
if(msg == WM_GETDLGCODE) {
return DLGC_STATIC | DLGC_WANTCHARS;
}
if(msg == WM_LBUTTONDOWN) {
if(self().focusable()) setFocused();
}
return pWidget::windowProc(hwnd, msg, wparam, lparam);
}
}
#endif
|