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 #include "toolkit.h"
30 #include "Windows.h"
31
32 #include "window.h"
33
34 #include "../common/menu.h"
35 #include "../common/toolbar.h"
36 #include "../common/document.h"
37 #include "../common/properties.h"
38 #include "../common/app.h"
39
40 #include "../ui/widget.h"
41
42 #include <stdio.h>
43 #include <stdlib.h>
44
45 #include <commctrl.h>
46
47 static const char *application_name;
48
49 static HFONT ui_font =
NULL;
50
51 void ui_init(
const char *appname,
int argc,
char **argv) {
52 application_name = appname;
53
54 uic_init_global_context();
55 uic_menu_init();
56 uic_toolbar_init();
57 uic_load_app_properties();
58
59 INITCOMMONCONTROLSEX icex = {
60 sizeof(icex),
61 ICC_WIN95_CLASSES |
ICC_LISTVIEW_CLASSES |
ICC_TREEVIEW_CLASSES |
ICC_BAR_CLASSES |
ICC_TAB_CLASSES |
ICC_STANDARD_CLASSES |
ICC_USEREX_CLASSES
62 };
63 InitCommonControlsEx(&icex);
64
65 SetProcessDpiAwarenessContext(
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
66
67 NONCLIENTMETRICS ncm = {
sizeof(ncm) };
68 SystemParametersInfo(
SPI_GETNONCLIENTMETRICS,
sizeof(ncm), &ncm,
FALSE);
69 ui_font = CreateFontIndirect(&ncm.lfMessageFont);
70
71 ui_window_init();
72 }
73
74 HFONT ui_win32_get_font(
void) {
75 return ui_font;
76 }
77
78 void ui_win32_set_ui_font(
HWND control) {
79 if (ui_font) {
80 SendMessage(control,
WM_SETFONT, (
WPARAM)ui_font,
TRUE);
81 }
82 }
83
84 const char* ui_appname() {
85 return application_name;
86 }
87
88 void ui_main() {
89 uic_application_startup(
NULL);
90
91
92 MSG msg;
93 while (GetMessage(&msg,
NULL,
0,
0)) {
94 TranslateMessage(&msg);
95 DispatchMessage(&msg);
96 }
97
98 uic_application_exit(
NULL);
99 uic_store_app_properties();
100 }
101
102 void ui_show(UiObject *obj) {
103 ui_set_visible(obj->widget,
TRUE);
104 }
105
106 LRESULT CALLBACK ui_default_eventproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam) {
107 W32Widget *widget = (W32Widget*)GetWindowLongPtr(hwnd,
GWLP_USERDATA);
108 if (widget && widget->wclass->eventproc) {
109 if (widget->wclass->eventproc(widget, hwnd, uMsg, wParam, lParam)) {
110 return 1;
111 }
112 }
113
114 switch(uMsg) {
115 case WM_DESTROY: {
116 PostQuitMessage(
0);
117 break;
118 }
119 case WM_COMMAND: {
120 HWND hwndCtrl = (
HWND)lParam;
121 W32Widget *cmdWidget = (W32Widget*)GetWindowLongPtr(hwndCtrl,
GWLP_USERDATA);
122 if (cmdWidget && cmdWidget->wclass->eventproc) {
123 cmdWidget->wclass->eventproc(cmdWidget, hwnd, uMsg, wParam, lParam);
124 }
125 break;
126 }
127 case WM_NOTIFY: {
128 LPNMHDR hdr = (
LPNMHDR)lParam;
129 HWND hwndCtrl = hdr->hwndFrom;
130 W32Widget *cmdWidget = (W32Widget*)GetWindowLongPtr(hwndCtrl,
GWLP_USERDATA);
131 if (cmdWidget && cmdWidget->wclass->eventproc) {
132 cmdWidget->wclass->eventproc(cmdWidget, hwnd, uMsg, wParam, lParam);
133 }
134 break;
135 }
136 case WM_SIZE: {
137 int width =
LOWORD(lParam);
138 int height =
HIWORD(lParam);
139 if (widget && widget->layout) {
140 widget->layout(widget->layoutmanager, width, height);
141 }
142 break;
143 }
144 default:
break;
145 }
146 return DefWindowProc(hwnd, uMsg, wParam, lParam);;
147 }
148
149 void ui_call_mainthread(ui_threadfunc tf,
void* td) {
150
151 }
152