#include "toolkit.h"
#include "Windows.h"
#include "window.h"
#include "../common/menu.h"
#include "../common/toolbar.h"
#include "../common/document.h"
#include "../common/properties.h"
#include "../common/app.h"
#include "../ui/widget.h"
#include <stdio.h>
#include <stdlib.h>
#include <commctrl.h>
static const char *application_name;
static HFONT ui_font =
NULL;
void ui_init(
const char *appname,
int argc,
char **argv) {
application_name = appname;
uic_init_global_context();
uic_menu_init();
uic_toolbar_init();
uic_load_app_properties();
INITCOMMONCONTROLSEX icex = {
sizeof(icex),
ICC_WIN95_CLASSES |
ICC_LISTVIEW_CLASSES |
ICC_TREEVIEW_CLASSES |
ICC_BAR_CLASSES |
ICC_TAB_CLASSES |
ICC_STANDARD_CLASSES |
ICC_USEREX_CLASSES
};
InitCommonControlsEx(&icex);
SetProcessDpiAwarenessContext(
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
NONCLIENTMETRICS ncm = {
sizeof(ncm) };
SystemParametersInfo(
SPI_GETNONCLIENTMETRICS,
sizeof(ncm), &ncm,
FALSE);
ui_font = CreateFontIndirect(&ncm.lfMessageFont);
ui_window_init();
}
HFONT ui_win32_get_font(
void) {
return ui_font;
}
void ui_win32_set_ui_font(
HWND control) {
if (ui_font) {
SendMessage(control,
WM_SETFONT, (
WPARAM)ui_font,
TRUE);
}
}
const char* ui_appname() {
return application_name;
}
void ui_main() {
uic_application_startup(
NULL);
MSG msg;
while (GetMessage(&msg,
NULL,
0,
0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
uic_application_exit(
NULL);
uic_store_app_properties();
}
void ui_show(UiObject *obj) {
ui_set_visible(obj->widget,
TRUE);
}
LRESULT CALLBACK ui_default_eventproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam) {
W32Widget *widget = (W32Widget*)GetWindowLongPtr(hwnd,
GWLP_USERDATA);
if (widget && widget->wclass->eventproc) {
if (widget->wclass->eventproc(widget, hwnd, uMsg, wParam, lParam)) {
return 1;
}
}
switch(uMsg) {
case WM_DESTROY: {
PostQuitMessage(
0);
break;
}
case WM_COMMAND: {
HWND hwndCtrl = (
HWND)lParam;
W32Widget *cmdWidget = (W32Widget*)GetWindowLongPtr(hwndCtrl,
GWLP_USERDATA);
if (cmdWidget && cmdWidget->wclass->eventproc) {
cmdWidget->wclass->eventproc(cmdWidget, hwnd, uMsg, wParam, lParam);
}
break;
}
case WM_NOTIFY: {
LPNMHDR hdr = (
LPNMHDR)lParam;
HWND hwndCtrl = hdr->hwndFrom;
W32Widget *cmdWidget = (W32Widget*)GetWindowLongPtr(hwndCtrl,
GWLP_USERDATA);
if (cmdWidget && cmdWidget->wclass->eventproc) {
cmdWidget->wclass->eventproc(cmdWidget, hwnd, uMsg, wParam, lParam);
}
break;
}
case WM_SIZE: {
int width =
LOWORD(lParam);
int height =
HIWORD(lParam);
if (widget && widget->layout) {
widget->layout(widget->layoutmanager, width, height);
}
break;
}
default:
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);;
}
void ui_call_mainthread(ui_threadfunc tf,
void* td) {
}