ui/gtk/window.c

changeset 46
31bc86844659
parent 45
ab71409644b0
child 51
e324291ca9f8
equal deleted inserted replaced
45:ab71409644b0 46:31bc86844659
188 GTK_WINDOW(obj->widget), 188 GTK_WINDOW(obj->widget),
189 width, 189 width,
190 height); 190 height);
191 } 191 }
192 192
193 #ifdef UI_LIBADWAITA
194
195 static void dialog_response(AdwAlertDialog *self, gchar *response, UiEventData *data) {
196 UiEvent evt;
197 evt.obj = data->obj;
198 evt.document = evt.obj->ctx->document;
199 evt.window = evt.obj->window;
200 evt.eventdata = NULL;
201 evt.intval = 0;
202
203 if(!strcmp(response, "btn1")) {
204 evt.intval = 1;
205 } else if(!strcmp(response, "btn2")) {
206 evt.intval = 2;
207 }
208
209 if(data->customdata) {
210 GtkWidget *entry = data->customdata;
211 evt.eventdata = (void*)ENTRY_GET_TEXT(GTK_ENTRY(entry));
212 }
213
214 if(data->callback) {
215 data->callback(&evt, data->userdata);
216 }
217 }
218
219 void ui_dialog_create(UiObject *parent, UiDialogArgs args) {
220 AdwDialog *dialog = adw_alert_dialog_new(args.title, args.content);
221 UiEventData *event = malloc(sizeof(UiEventData));
222 event->callback = args.result;
223 event->userdata = args.resultdata;
224 event->customdata = NULL;
225 event->value = 0;
226 event->obj = parent;
227
228 if(args.button1_label) {
229 adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "btn1", args.button1_label);
230 }
231 if(args.button2_label) {
232 adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "btn2", args.button2_label);
233 }
234 if(args.closebutton_label) {
235 adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "close", args.closebutton_label);
236 adw_alert_dialog_set_close_response(ADW_ALERT_DIALOG(dialog), "close");
237 }
238
239 GtkWidget *entry = NULL;
240 if(args.input) {
241 entry = gtk_entry_new();
242 adw_alert_dialog_set_extra_child(ADW_ALERT_DIALOG(dialog), entry);
243 event->customdata = entry;
244 }
245
246 g_signal_connect(
247 dialog,
248 "destroy",
249 G_CALLBACK(ui_destroy_userdata),
250 event);
251
252 g_signal_connect(dialog, "response", G_CALLBACK(dialog_response), event);
253 adw_dialog_present(dialog, parent->widget);
254
255 if(entry) {
256 gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry));
257 }
258 }
259 #else
260
193 static void ui_dialog_response (GtkDialog* self, gint response_id, gpointer user_data) { 261 static void ui_dialog_response (GtkDialog* self, gint response_id, gpointer user_data) {
194 UiEventData *data = user_data; 262 UiEventData *data = user_data;
195 UiEvent evt; 263 UiEvent evt;
196 evt.obj = data->obj; 264 evt.obj = data->obj;
197 evt.document = evt.obj->ctx->document; 265 evt.document = evt.obj->ctx->document;
217 WINDOW_DESTROY(GTK_WIDGET(self)); 285 WINDOW_DESTROY(GTK_WIDGET(self));
218 } 286 }
219 287
220 void ui_dialog_create(UiObject *parent, UiDialogArgs args) { 288 void ui_dialog_create(UiObject *parent, UiDialogArgs args) {
221 GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new()); 289 GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new());
290 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent->widget));
291 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
292
222 GtkWidget *dialog_w = GTK_WIDGET(dialog); 293 GtkWidget *dialog_w = GTK_WIDGET(dialog);
223 if(args.title) { 294 if(args.title) {
224 gtk_window_set_title(GTK_WINDOW(dialog), args.title); 295 gtk_window_set_title(GTK_WINDOW(dialog), args.title);
225 } 296 }
226 if(args.button1_label) { 297 if(args.button1_label) {
257 G_CALLBACK(ui_dialog_response), 328 G_CALLBACK(ui_dialog_response),
258 event); 329 event);
259 330
260 WINDOW_SHOW(GTK_WIDGET(dialog_w)); 331 WINDOW_SHOW(GTK_WIDGET(dialog_w));
261 } 332 }
333 #endif
262 334
263 335
264 #if GTK_MAJOR_VERSION >= 3 336 #if GTK_MAJOR_VERSION >= 3
265 UiFileList listmodel2filelist(GListModel *selection) { 337 UiFileList listmodel2filelist(GListModel *selection) {
266 UiFileList flist; 338 UiFileList flist;

mercurial