| 39 #include <stdlib.h> |
39 #include <stdlib.h> |
| 40 |
40 |
| 41 #include "win32.h" |
41 #include "win32.h" |
| 42 |
42 |
| 43 static W32WidgetClass w32_toplevel_widget_class = { |
43 static W32WidgetClass w32_toplevel_widget_class = { |
| |
44 .eventproc = ui_window_widget_event, |
| 44 .show = ui_window_widget_show, |
45 .show = ui_window_widget_show, |
| 45 .enable = NULL, |
46 .enable = NULL, |
| 46 .get_preferred_size = NULL, |
47 .get_preferred_size = NULL, |
| 47 .destroy = w32_widget_default_destroy |
48 .destroy = w32_widget_default_destroy |
| 48 }; |
49 }; |
| 50 static HINSTANCE hInstance; |
51 static HINSTANCE hInstance; |
| 51 |
52 |
| 52 static const char *mainWindowClass = "UiMainWindow"; |
53 static const char *mainWindowClass = "UiMainWindow"; |
| 53 |
54 |
| 54 LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { |
55 LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { |
| |
56 W32Widget *widget = (W32Widget*)GetWindowLongPtr(hwnd, GWLP_USERDATA); |
| |
57 if (widget && widget->wclass->eventproc) { |
| |
58 widget->wclass->eventproc(widget, hwnd, uMsg, wParam, lParam); |
| |
59 } |
| 55 switch(uMsg) { |
60 switch(uMsg) { |
| 56 case WM_DESTROY: |
61 case WM_DESTROY: |
| 57 PostQuitMessage(0); |
62 PostQuitMessage(0); |
| 58 break; |
63 break; |
| 59 default: |
64 default: |
| 96 hInstance, |
101 hInstance, |
| 97 NULL); |
102 NULL); |
| 98 |
103 |
| 99 UpdateWindow(hwnd); |
104 UpdateWindow(hwnd); |
| 100 |
105 |
| 101 W32Widget *widget = w32_widget_new(&w32_toplevel_widget_class, hwnd); |
106 // TODO: switch to box container |
| 102 obj->widget = widget; |
107 UiContainerX *container = ui_grid_container_create(obj, hwnd, 0, 0, INSETS_ZERO); |
| |
108 uic_object_push_container(obj, container); |
| |
109 |
| |
110 UiWindow *widget = w32_widget_create(&w32_toplevel_widget_class, hwnd, sizeof(UiWindow)); |
| |
111 widget->obj = obj; |
| |
112 widget->container = (UiGridLayoutContainer *)container; |
| |
113 obj->widget = (W32Widget*)widget; |
| 103 obj->ref = 1; |
114 obj->ref = 1; |
| 104 |
|
| 105 // TODO: switch to box container |
|
| 106 UiContainerX *container = ui_grid_container_create(obj, hwnd, 0, 0, 0, 0); |
|
| 107 uic_object_push_container(obj, container); |
|
| 108 |
115 |
| 109 return obj; |
116 return obj; |
| 110 } |
117 } |
| 111 |
118 |
| 112 UiObject *ui_window(const char *title, void *window_data) { |
119 UiObject *ui_window(const char *title, void *window_data) { |
| 113 return create_window(title, window_data, FALSE); |
120 return create_window(title, window_data, FALSE); |
| 114 } |
121 } |
| 115 |
122 |
| |
123 |
| |
124 void ui_window_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { |
| |
125 UiWindow *window = (UiWindow*)widget; |
| |
126 switch (uMsg) { |
| |
127 case WM_SIZE: { |
| |
128 int width = LOWORD(lParam); |
| |
129 int height = HIWORD(lParam); |
| |
130 ui_grid_layout(window->container->layout, width, height); |
| |
131 break; |
| |
132 } |
| |
133 } |
| |
134 } |
| |
135 |
| 116 void ui_window_widget_show(W32Widget *w, BOOLEAN show) { |
136 void ui_window_widget_show(W32Widget *w, BOOLEAN show) { |
| 117 ShowWindow(w->hwnd, show ? SW_SHOWNORMAL : SW_HIDE); |
137 ShowWindow(w->hwnd, show ? SW_SHOWNORMAL : SW_HIDE); |
| 118 } |
138 } |