ui/gtk/container.c

changeset 52
25e5390cce41
parent 33
458831c574f4
child 59
eb6611be50c7
equal deleted inserted replaced
51:42506e19eb6b 52:25e5390cce41
99 99
100 100
101 void ui_box_add(UiContainer *ct, GtkWidget *widget) { 101 void ui_box_add(UiContainer *ct, GtkWidget *widget) {
102 gtk_box_pack_start(GTK_BOX(ct->widget), widget, TRUE, TRUE, 0); 102 gtk_box_pack_start(GTK_BOX(ct->widget), widget, TRUE, TRUE, 0);
103 } 103 }
104
105
106
107
108 static void page_change(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer data) {
109 GQuark q = g_quark_from_static_string("ui.tab.object");
110 UiObject *tab = g_object_get_qdata(G_OBJECT(page), q);
111 if(!tab) {
112 return;
113 }
114
115 printf("page_change: %d\n", page_num);
116 UiContext *ctx = tab->ctx;
117 ctx->parent->set_document(ctx->parent, ctx->document);
118 }
119
120 UiTabbedPane* ui_tabbed_document_view(UiObject *obj) {
121 GtkWidget *tabview = gtk_notebook_new();
122 gtk_notebook_set_show_border(GTK_NOTEBOOK(tabview), FALSE);
123
124 g_signal_connect(
125 tabview,
126 "switch-page",
127 G_CALLBACK(page_change),
128 NULL);
129
130 UiContainer *ct = uic_get_current_container(obj);
131 ct->add(ct, tabview);
132
133 UiTabbedPane *tabbedpane = ui_malloc(obj->ctx, sizeof(UiTabbedPane));
134 tabbedpane->ctx = uic_current_obj(obj)->ctx;
135 tabbedpane->widget = tabview;
136 tabbedpane->document = NULL;
137
138 return tabbedpane;
139 }
140
141 UiObject* ui_document_tab(UiTabbedPane *view) {
142 GtkWidget *frame = gtk_alignment_new(0.5, 0.5, 1, 1);
143 // TODO: label
144 gtk_notebook_append_page(GTK_NOTEBOOK(view->widget), frame, NULL);
145
146 UiObject *tab = ui_malloc(view->ctx, sizeof(UiObject));
147 tab->widget = NULL; // initialization for uic_context()
148 tab->ctx = uic_context(tab, view->ctx->mempool);
149 tab->ctx->parent = view->ctx;
150 tab->ctx->set_document = ui_tab_set_document;
151 tab->ctx->detach_document = ui_tab_detach_document;
152 tab->widget = frame;
153 tab->window = view->ctx->obj->window;
154 tab->container = ui_frame_container(tab, frame);
155 tab->next = NULL;
156
157 GQuark q = g_quark_from_static_string("ui.tab.object");
158 g_object_set_qdata(G_OBJECT(frame), q, tab);
159
160 return tab;
161 }
162
163 void ui_tab_set_document(UiContext *ctx, void *document) {
164 if(ctx->parent->document) {
165 //ctx->parent->detach_document(ctx->parent, ctx->parent->document);
166 }
167 uic_context_set_document(ctx, document);
168 //uic_context_set_document(ctx->parent, document);
169 //ctx->parent->document = document;
170 }
171
172 void ui_tab_detach_document(UiContext *ctx, void *document) {
173 uic_context_detach_document(ctx->parent, document);
174 }

mercurial