ui/win32/window.c

changeset 986
6f7600c2b9e1
parent 954
07c1effb2a31
equal deleted inserted replaced
985:93f07ccfd997 986:6f7600c2b9e1
53 53
54 static const char *mainWindowClass = "UiMainWindow"; 54 static const char *mainWindowClass = "UiMainWindow";
55 55
56 56
57 void ui_window_init(void) { 57 void ui_window_init(void) {
58 hInstance = GetModuleHandle(NULL); 58 hInstance = GetModuleHandle(NULL);
59 59
60 WNDCLASSEX wc = { sizeof(WNDCLASSEX) }; 60 WNDCLASSEX wc = { sizeof(WNDCLASSEX) };
61 wc.lpfnWndProc = ui_default_eventproc; 61 wc.lpfnWndProc = ui_default_eventproc;
62 wc.hInstance = hInstance; 62 wc.hInstance = hInstance;
63 wc.lpszClassName = mainWindowClass; 63 wc.lpszClassName = mainWindowClass;
64 wc.hCursor = LoadCursor(NULL, IDC_ARROW); 64 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
65 wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); 65 wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
68 MessageBox(NULL, "RegisterClassEx failed", "Error", MB_ICONERROR); 68 MessageBox(NULL, "RegisterClassEx failed", "Error", MB_ICONERROR);
69 exit(-1); 69 exit(-1);
70 } 70 }
71 } 71 }
72 72
73 static UiObject* create_window(const char *title, void *window_data, bool simple) { 73 static UiObject* create_window(const char *title, bool simple) {
74 UiObject *obj = uic_object_new_toplevel(); 74 UiObject *obj = uic_object_new_toplevel();
75 obj->window = window_data;
76 75
77 HWND hwnd = CreateWindowExA( 76 HWND hwnd = CreateWindowExA(
78 0, 77 0,
79 "UiMainWindow", 78 "UiMainWindow",
80 title, 79 title,
81 WS_OVERLAPPEDWINDOW, 80 WS_OVERLAPPEDWINDOW,
82 CW_USEDEFAULT, 81 CW_USEDEFAULT,
83 CW_USEDEFAULT, 82 CW_USEDEFAULT,
84 800, 83 800,
85 600, 84 600,
86 NULL, 85 NULL,
87 NULL, 86 NULL,
88 hInstance, 87 hInstance,
89 NULL); 88 NULL);
90 89
91 if (!simple) { 90 if (!simple) {
92 HMENU menubar = ui_create_main_menu(obj); 91 HMENU menubar = ui_create_main_menu(obj);
93 if (menubar) { 92 if (menubar) {
94 SetMenu(hwnd, menubar); 93 SetMenu(hwnd, menubar);
95 } 94 }
96 } 95 }
97 96
98 UpdateWindow(hwnd); 97 UpdateWindow(hwnd);
99 98
100 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);
101 uic_object_push_container(obj, container); 100 uic_object_push_container(obj, container);
102 UiBoxContainer *box = (UiBoxContainer*)container; 101 UiBoxContainer *box = (UiBoxContainer*)container;
103 102
104 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));
105 widget->obj = obj; 104 widget->obj = obj;
106 widget->widget.layout = (W32LayoutFunc)ui_grid_layout; 105 widget->widget.layout = (W32LayoutFunc)ui_grid_layout;
107 widget->widget.layoutmanager = box->layout; 106 widget->widget.layoutmanager = box->layout;
108 obj->widget = (W32Widget*)widget; 107 obj->widget = (W32Widget*)widget;
109 obj->ref = 1; 108 obj->ref = 1;
110 109
111 return obj; 110 return obj;
112 } 111 }
113 112
114 UiObject *ui_window(const char *title, void *window_data) { 113 UiObject *ui_window(const char *title) {
115 return create_window(title, window_data, FALSE); 114 return create_window(title, window_data, FALSE);
116 } 115 }
117 116
118 UiObject *ui_simple_window(const char *title, void *window_data) { 117 UiObject *ui_simple_window(const char *title) {
119 return create_window(title, window_data, TRUE); 118 return create_window(title, window_data, TRUE);
120 } 119 }
121 120
122 int 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) {
123 //UiWindow *window = (UiWindow*)widget; 122 //UiWindow *window = (UiWindow*)widget;
124 return 0; 123 return 0;
125 } 124 }
126 125
127 void ui_window_widget_show(W32Widget *w, BOOLEAN show) { 126 void ui_window_widget_show(W32Widget *w, BOOLEAN show) {
128 ShowWindow(w->hwnd, show ? SW_SHOWNORMAL : SW_HIDE); 127 ShowWindow(w->hwnd, show ? SW_SHOWNORMAL : SW_HIDE);
129 } 128 }

mercurial