151 return create_window(title, window_data, FALSE); |
151 return create_window(title, window_data, FALSE); |
152 } |
152 } |
153 |
153 |
154 UiObject* ui_simplewindow(const char *title, void *window_data) { |
154 UiObject* ui_simplewindow(const char *title, void *window_data) { |
155 return create_window(title, window_data, TRUE); |
155 return create_window(title, window_data, TRUE); |
|
156 } |
|
157 |
|
158 static void ui_dialog_response (GtkDialog* self, gint response_id, gpointer user_data) { |
|
159 UiEventData *data = user_data; |
|
160 UiEvent evt; |
|
161 evt.obj = data->obj; |
|
162 evt.document = evt.obj->ctx->document; |
|
163 evt.window = evt.obj->window; |
|
164 evt.eventdata = NULL; |
|
165 evt.intval = 0; |
|
166 |
|
167 if(data->customdata) { |
|
168 GtkWidget *entry = data->customdata; |
|
169 evt.eventdata = (void*)gtk_entry_get_text(GTK_ENTRY(entry)); |
|
170 |
|
171 } |
|
172 |
|
173 if(response_id == 1 || response_id == 2) { |
|
174 evt.intval = response_id; |
|
175 } |
|
176 |
|
177 |
|
178 if(data->callback) { |
|
179 data->callback(&evt, data->userdata); |
|
180 } |
|
181 |
|
182 gtk_widget_destroy(GTK_WIDGET(self)); |
|
183 } |
|
184 |
|
185 void ui_dialog_create(UiObject *parent, UiDialogArgs args) { |
|
186 GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new()); |
|
187 GtkWidget *dialog_w = GTK_WIDGET(dialog); |
|
188 if(args.title) { |
|
189 gtk_window_set_title(GTK_WINDOW(dialog), args.title); |
|
190 } |
|
191 if(args.button1_label) { |
|
192 gtk_dialog_add_button(dialog, args.button1_label, 1); |
|
193 } |
|
194 if(args.button2_label) { |
|
195 gtk_dialog_add_button(dialog, args.button2_label, 2); |
|
196 } |
|
197 if(args.closebutton_label) { |
|
198 gtk_dialog_add_button(dialog, args.closebutton_label, 0); |
|
199 } |
|
200 |
|
201 GtkWidget *content_area = gtk_dialog_get_content_area(dialog); |
|
202 if(args.content) { |
|
203 GtkWidget *label = gtk_label_new(args.content); |
|
204 gtk_container_add(GTK_CONTAINER(content_area), label); |
|
205 } |
|
206 |
|
207 GtkWidget *textfield = NULL; |
|
208 if(args.input) { |
|
209 textfield = gtk_entry_new(); |
|
210 gtk_container_add(GTK_CONTAINER(content_area), textfield); |
|
211 } |
|
212 |
|
213 UiEventData *event = malloc(sizeof(UiEventData)); |
|
214 event->obj = parent; |
|
215 event->callback = args.result; |
|
216 event->userdata = args.resultdata; |
|
217 event->value = 0; |
|
218 event->customdata = textfield; |
|
219 |
|
220 g_signal_connect(dialog_w, |
|
221 "response", |
|
222 G_CALLBACK(ui_dialog_response), |
|
223 event); |
|
224 |
|
225 gtk_widget_show_all(GTK_WIDGET(dialog_w)); |
156 } |
226 } |
157 |
227 |
158 static char* ui_gtkfilechooser(UiObject *obj, GtkFileChooserAction action) { |
228 static char* ui_gtkfilechooser(UiObject *obj, GtkFileChooserAction action) { |
159 char *button; |
229 char *button; |
160 char *title; |
230 char *title; |