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