ui/server/window.c

changeset 982
9102a53c5385
parent 981
1d47e71f26b6
child 984
2cf5e6d55013
equal deleted inserted replaced
981:1d47e71f26b6 982:9102a53c5385
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "window.h" 29 #include "window.h"
30 30
31 #include "../common/object.h"
32
33 #include <cx/buffer.h>
34
35 static UiObject* create_window(const char *title, UiBool simple, UiBool sidebar, UiBool splitview) {
36 UiObject *obj = uic_object_new_toplevel();
37 const CxAllocator *a = obj->ctx->allocator;
38
39 UiWindow *window = cxZalloc(a, sizeof(UiWindow));
40 window->widget.obj = ui_create_server_object(obj->ctx);
41 window->widget.children = cxLinkedListCreate(a, NULL, CX_STORE_POINTERS);
42 window->widget.serialize = (ui_serialize_func)ui_window_serialize;
43 window->title = cx_strdup_a(a, title);
44
45 obj->widget = (UiWidget*)window;
46 ui_reg_widget(obj->widget);
47
48 return obj;
49 }
50
51 UiObject *ui_window(const char *title, void *window_data) {
52 return create_window(title, FALSE, FALSE, FALSE);
53 }
54
55 UiObject *ui_sidebar_window(const char *title, void *window_data) {
56 return create_window(title, FALSE, TRUE, FALSE);
57 }
58
59 UiObject *ui_splitview_window(const char *title, UiBool sidebar) {
60 return create_window(title, FALSE, sidebar, TRUE);
61 }
62
63 UiObject *ui_simple_window(const char *title, void *window_data) {
64 return create_window(title, TRUE, FALSE, FALSE);
65 }
66
67
68 cxmutstr ui_window_serialize(UiWindow *w) {
69 CxBuffer buf;
70 cxBufferInit(&buf, NULL, 1024, NULL, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_FREE_CONTENTS);
71
72 cxBufferPutString(&buf, "{\"type\":");
73 switch(w->type) {
74 case UI_WINDOW_MAIN: cxBufferPutString(&buf, "\"window\""); break;
75 case UI_WINDOW_SIMPLE: cxBufferPutString(&buf, "\"simple_window\""); break;
76 case UI_WINDOW_SIDEBAR: cxBufferPutString(&buf, "\"sidebar_window\""); break;
77 case UI_WINDOW_SPLITVIEW: cxBufferPutString(&buf, "\"splitview_window\""); break;
78 }
79
80 cxmutstr obj_id = w->widget.obj->id;
81 cxmutstr id = w->widget.id;
82
83 cxBufferPutString(&buf, " obj_id=\"");
84 cxBufferWrite(obj_id.ptr, 1, obj_id.length, &buf);
85 cxBufferPutString(&buf, "\"");
86
87 cxBufferPutString(&buf, " id=\"");
88 cxBufferWrite(id.ptr, 1, id.length, &buf);
89 cxBufferPutString(&buf, "\"");
90
91 if(w->title.ptr) {
92 cxBufferPutString(&buf, " title=\"");
93 cxBufferWrite(w->title.ptr, 1, w->title.length, &buf);
94 cxBufferPutString(&buf, "\"");
95 }
96
97
98 cxBufferPutString(&buf, "}\n");
99
100 return cx_mutstrn(buf.space, buf.size);
101 }
102
103

mercurial