ui/win32/window.c

changeset 115
e57ca2747782
parent 113
dde28a806552
equal deleted inserted replaced
114:3da24640513a 115:e57ca2747782
37 #include <stdbool.h> 37 #include <stdbool.h>
38 #include <stdio.h> 38 #include <stdio.h>
39 #include <stdlib.h> 39 #include <stdlib.h>
40 40
41 #include "win32.h" 41 #include "win32.h"
42 #include "menu.h"
42 43
43 static W32WidgetClass w32_toplevel_widget_class = { 44 static W32WidgetClass w32_toplevel_widget_class = {
44 .eventproc = ui_window_widget_event, 45 .eventproc = ui_window_widget_event,
45 .show = ui_window_widget_show, 46 .show = ui_window_widget_show,
46 .enable = NULL, 47 .enable = NULL,
52 53
53 static const char *mainWindowClass = "UiMainWindow"; 54 static const char *mainWindowClass = "UiMainWindow";
54 55
55 56
56 void ui_window_init(void) { 57 void ui_window_init(void) {
57 hInstance = GetModuleHandle(NULL); 58 hInstance = GetModuleHandle(NULL);
58 59
59 WNDCLASSEX wc = { sizeof(WNDCLASSEX) }; 60 WNDCLASSEX wc = { sizeof(WNDCLASSEX) };
60 wc.lpfnWndProc = ui_default_eventproc; 61 wc.lpfnWndProc = ui_default_eventproc;
61 wc.hInstance = hInstance; 62 wc.hInstance = hInstance;
62 wc.lpszClassName = mainWindowClass; 63 wc.lpszClassName = mainWindowClass;
63 wc.hCursor = LoadCursor(NULL, IDC_ARROW); 64 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
64 wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); 65 wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
67 MessageBox(NULL, "RegisterClassEx failed", "Error", MB_ICONERROR); 68 MessageBox(NULL, "RegisterClassEx failed", "Error", MB_ICONERROR);
68 exit(-1); 69 exit(-1);
69 } 70 }
70 } 71 }
71 72
72 static UiObject* create_window(const char *title, void *window_data, bool simple) { 73 static UiObject* create_window(const char *title, bool simple) {
73 UiObject *obj = uic_object_new_toplevel(); 74 UiObject *obj = uic_object_new_toplevel();
74 obj->window = window_data;
75 75
76 HWND hwnd = CreateWindowExA( 76 HWND hwnd = CreateWindowExA(
77 0, 77 0,
78 "UiMainWindow", 78 "UiMainWindow",
79 title, 79 title,
80 WS_OVERLAPPEDWINDOW, 80 WS_OVERLAPPEDWINDOW,
81 CW_USEDEFAULT, 81 CW_USEDEFAULT,
82 CW_USEDEFAULT, 82 CW_USEDEFAULT,
83 800, 83 800,
84 600, 84 600,
85 NULL, 85 NULL,
86 NULL, 86 NULL,
87 hInstance, 87 hInstance,
88 NULL); 88 NULL);
89
90 if (!simple) {
91 HMENU menubar = ui_create_main_menu(obj);
92 if (menubar) {
93 SetMenu(hwnd, menubar);
94 }
95 }
89 96
90 UpdateWindow(hwnd); 97 UpdateWindow(hwnd);
91 98
92 UiContainerX *container = ui_box_container_create(obj, hwnd, UI_BOX_VERTICAL, 0, INSETS_ZERO); 99 UiContainerX *container = ui_box_container_create(obj, hwnd, UI_BOX_VERTICAL, 0, INSETS_ZERO);
93 uic_object_push_container(obj, container); 100 uic_object_push_container(obj, container);
94 UiBoxContainer *box = (UiBoxContainer*)container; 101 UiBoxContainer *box = (UiBoxContainer*)container;
95 102
96 UiWindow *widget = w32_widget_create(&w32_toplevel_widget_class, hwnd, sizeof(UiWindow)); 103 UiWindow *widget = w32_widget_create(&w32_toplevel_widget_class, hwnd, sizeof(UiWindow));
97 widget->obj = obj; 104 widget->obj = obj;
98 widget->widget.layout = (W32LayoutFunc)ui_grid_layout; 105 widget->widget.layout = (W32LayoutFunc)ui_grid_layout;
99 widget->widget.layoutmanager = box->layout; 106 widget->widget.layoutmanager = box->layout;
100 obj->widget = (W32Widget*)widget; 107 obj->widget = (W32Widget*)widget;
101 obj->ref = 1; 108 obj->ref = 1;
102 109
103 return obj; 110 return obj;
104 } 111 }
105 112
106 UiObject *ui_window(const char *title, void *window_data) { 113 UiObject *ui_window(const char *title) {
107 return create_window(title, window_data, FALSE); 114 return create_window(title, FALSE);
108 } 115 }
109 116
117 UiObject *ui_simple_window(const char *title) {
118 return create_window(title, TRUE);
119 }
110 120
111 void ui_window_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 121 int ui_window_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
112 //UiWindow *window = (UiWindow*)widget; 122 //UiWindow *window = (UiWindow*)widget;
123 return 0;
113 } 124 }
114 125
115 void ui_window_widget_show(W32Widget *w, BOOLEAN show) { 126 void ui_window_widget_show(W32Widget *w, BOOLEAN show) {
116 ShowWindow(w->hwnd, show ? SW_SHOWNORMAL : SW_HIDE); 127 ShowWindow(w->hwnd, show ? SW_SHOWNORMAL : SW_HIDE);
117 } 128 }

mercurial