Debian Codegraph @

phoenix/windows/widget/widget.cpp

raw
1 namespace phoenix {
2
3 bool pWidget::focused() {
4 return GetFocus() == hwnd;
5 }
6
7 Size pWidget::minimumSize() {
8 return {0, 0};
9 }
10
11 void pWidget::setEnabled(bool enabled) {
12 if(!widget.parent()) enabled = false;
13 if(widget.state.abstract) enabled = false;
14 if(!widget.enabledToAll()) enabled = false;
15 EnableWindow(hwnd, enabled);
16 }
17
18 void pWidget::setFocused() {
19 SetFocus(hwnd);
20 }
21
22 void pWidget::setFont(string font) {
23 if(hfont) DeleteObject(hfont);
24 hfont = pFont::create(font);
25 SendMessage(hwnd, WM_SETFONT, (WPARAM)hfont, 0);
26 }
27
28 void pWidget::setGeometry(Geometry geometry) {
29 if(GetParentWidget(&sizable)) {
30 Position displacement = GetParentWidget(&sizable)->state.geometry.position();
31 geometry.x -= displacement.x;
32 geometry.y -= displacement.y;
33 }
34 SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, geometry.height, SWP_NOZORDER);
35 if(widget.onSize) widget.onSize();
36 }
37
38 void pWidget::setVisible(bool visible) {
39 if(!widget.parent()) visible = false;
40 if(widget.state.abstract) visible = false;
41 if(!widget.visibleToAll()) visible = false;
42 ShowWindow(hwnd, visible ? SW_SHOWNORMAL : SW_HIDE);
43 }
44
45 void pWidget::constructor() {
46 hfont = pFont::create(Font::sans(8));
47 if(widget.state.abstract) {
48 hwnd = CreateWindow(L"phoenix_label", L"",
49 WS_CHILD,
50 0, 0, 0, 0, parentHwnd, (HMENU)id, GetModuleHandle(0), 0);
51 SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&widget);
52 }
53 }
54
55 void pWidget::destructor() {
56 if(widget.state.abstract) {
57 DestroyWindow(hwnd);
58 }
59 }
60
61 void pWidget::orphan() {
62 destructor();
63 constructor();
64 }
65
66 void pWidget::setDefaultFont() {
67 string description = widget.state.font;
68 if(description.empty()) description = Font::sans(8);
69 hfont = pFont::create(description);
70 SendMessage(hwnd, WM_SETFONT, (WPARAM)hfont, 0);
71 }
72
73 //calling Widget::setParent destroys widget and re-creates it:
74 //need to re-apply visiblity and enabled status; called by each subclassed setParent() function
75 //constructors are called top-down, so set each widget to the top of the z-order (so children appear on top of parents)
76 void pWidget::synchronize() {
77 widget.setEnabled(widget.enabled());
78 widget.setVisible(widget.visible());
79 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
80 }
81
82 }