Thu, 03 Oct 2024 18:08:29 +0200
implement action_newfile
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2017 Olaf Wintermann. All rights reserved. |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <string.h> |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "../ui/window.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include "../ui/properties.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include "../common/context.h" |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
36 | #include "../common/menu.h" |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
37 | #include "../common/toolbar.h" |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
39 | #include <cx/mempool.h> |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include "menu.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #include "toolbar.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | #include "container.h" |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
44 | #include "headerbar.h" |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | static int nwindows = 0; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | static int window_default_width = 650; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | static int window_default_height = 550; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | void ui_exit_event(GtkWidget *widget, gpointer data) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | UiObject *obj = data; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | UiEvent ev; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | ev.window = obj->window; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | ev.document = obj->ctx->document; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | ev.obj = obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | ev.eventdata = NULL; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | ev.intval = 0; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | if(obj->ctx->close_callback) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | obj->ctx->close_callback(&ev, obj->ctx->close_data); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | // TODO: free UiObject |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | nwindows--; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | #ifdef UI_GTK2 |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | if(nwindows == 0) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | gtk_main_quit(); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | #endif |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
73 | static UiObject* create_window(const char *title, void *window_data, UiBool simple) { |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | CxMempool *mp = cxBasicMempoolCreate(256); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
76 | |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
77 | #ifdef UI_LIBADWAITA |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
78 | obj->widget = adw_application_window_new(ui_get_application()); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
79 | #elif !defined(UI_GTK2) |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | obj->widget = gtk_application_window_new(ui_get_application()); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | #else |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | obj->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | #endif |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
86 | obj->ctx = uic_context(obj, mp); |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | obj->window = window_data; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
89 | #if GTK_CHECK_VERSION(4, 0, 0) |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
90 | obj->ctx->action_map = G_ACTION_MAP(obj->widget); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
91 | #endif |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
92 | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | if(title != NULL) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | gtk_window_set_title(GTK_WINDOW(obj->widget), title); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | char *width = ui_get_property("ui.window.width"); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | char *height = ui_get_property("ui.window.height"); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | if(width && height) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | gtk_window_set_default_size( |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | GTK_WINDOW(obj->widget), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | atoi(width), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | atoi(height)); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | } else { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | gtk_window_set_default_size( |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | GTK_WINDOW(obj->widget), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | window_default_width, |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | window_default_height); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | g_signal_connect( |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | obj->widget, |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | "destroy", |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | G_CALLBACK(ui_exit_event), |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | obj); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | GtkWidget *vbox = ui_gtk_vbox_new(0); |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
118 | #ifdef UI_LIBADWAITA |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
119 | GtkWidget *toolbar_view = adw_toolbar_view_new(); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
120 | adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), toolbar_view); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
121 | adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(toolbar_view), vbox); |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
122 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
123 | GtkWidget *headerbar = adw_header_bar_new(); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
124 | adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(toolbar_view), headerbar); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
125 | |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
126 | if(!simple) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
127 | ui_fill_headerbar(obj, headerbar); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
128 | } |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
129 | #elif GTK_MAJOR_VERSION >= 4 |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
130 | WINDOW_SET_CONTENT(obj->widget, vbox); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
131 | #else |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | gtk_container_add(GTK_CONTAINER(obj->widget), vbox); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | if(!simple) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | // menu |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
136 | if(uic_get_menu_list()) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
137 | GtkWidget *mb = ui_create_menubar(obj); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
138 | if(mb) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
139 | gtk_box_pack_start(GTK_BOX(vbox), mb, FALSE, FALSE, 0); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
140 | } |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | // toolbar |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
144 | if(uic_toolbar_isenabled()) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
145 | GtkWidget *tb = ui_create_toolbar(obj); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
146 | if(tb) { |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
147 | gtk_box_pack_start(GTK_BOX(vbox), tb, FALSE, FALSE, 0); |
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
148 | } |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | } |
32 | 150 | |
151 | //GtkWidget *hb = ui_create_headerbar(obj); | |
152 | //gtk_window_set_titlebar(GTK_WINDOW(obj->widget), hb); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | } |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
154 | #endif |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | // window content |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | // the content has a (TODO: not yet) configurable frame |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
158 | // TODO: really? why |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
159 | /* |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | GtkWidget *frame = gtk_frame_new(NULL); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | // content vbox |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | GtkWidget *content_box = ui_gtk_vbox_new(0); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | gtk_container_add(GTK_CONTAINER(frame), content_box); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | obj->container = ui_box_container(obj, content_box); |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
168 | */ |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
169 | GtkWidget *content_box = ui_gtk_vbox_new(0); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
170 | BOX_ADD(GTK_BOX(vbox), content_box); |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
171 | obj->container = ui_box_container(obj, content_box, UI_CONTAINER_VBOX); |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | nwindows++; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | return obj; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | |
29
3fc287f06305
add minimal working download
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
178 | UiObject* ui_window(const char *title, void *window_data) { |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | return create_window(title, window_data, FALSE); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | |
32 | 182 | UiObject* ui_simple_window(const char *title, void *window_data) { |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | return create_window(title, window_data, TRUE); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | |
32 | 186 | void ui_window_size(UiObject *obj, int width, int height) { |
187 | gtk_window_set_default_size( | |
188 | GTK_WINDOW(obj->widget), | |
189 | width, | |
190 | height); | |
191 | } | |
192 | ||
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
193 | #ifdef UI_LIBADWAITA |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
194 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
195 | static void dialog_response(AdwAlertDialog *self, gchar *response, UiEventData *data) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
196 | UiEvent evt; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
197 | evt.obj = data->obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
198 | evt.document = evt.obj->ctx->document; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
199 | evt.window = evt.obj->window; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
200 | evt.eventdata = NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
201 | evt.intval = 0; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
202 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
203 | if(!strcmp(response, "btn1")) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
204 | evt.intval = 1; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
205 | } else if(!strcmp(response, "btn2")) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
206 | evt.intval = 2; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
207 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
208 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
209 | if(data->customdata) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
210 | GtkWidget *entry = data->customdata; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
211 | evt.eventdata = (void*)ENTRY_GET_TEXT(GTK_ENTRY(entry)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
212 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
213 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
214 | if(data->callback) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
215 | data->callback(&evt, data->userdata); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
216 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
217 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
218 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
219 | void ui_dialog_create(UiObject *parent, UiDialogArgs args) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
220 | AdwDialog *dialog = adw_alert_dialog_new(args.title, args.content); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
221 | UiEventData *event = malloc(sizeof(UiEventData)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
222 | event->callback = args.result; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
223 | event->userdata = args.resultdata; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
224 | event->customdata = NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
225 | event->value = 0; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
226 | event->obj = parent; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
227 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
228 | if(args.button1_label) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
229 | adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "btn1", args.button1_label); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
230 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
231 | if(args.button2_label) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
232 | adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "btn2", args.button2_label); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
233 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
234 | if(args.closebutton_label) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
235 | adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "close", args.closebutton_label); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
236 | adw_alert_dialog_set_close_response(ADW_ALERT_DIALOG(dialog), "close"); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
237 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
238 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
239 | GtkWidget *entry = NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
240 | if(args.input) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
241 | entry = gtk_entry_new(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
242 | adw_alert_dialog_set_extra_child(ADW_ALERT_DIALOG(dialog), entry); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
243 | event->customdata = entry; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
244 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
245 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
246 | g_signal_connect( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
247 | dialog, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
248 | "destroy", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
249 | G_CALLBACK(ui_destroy_userdata), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
250 | event); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
251 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
252 | g_signal_connect(dialog, "response", G_CALLBACK(dialog_response), event); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
253 | adw_dialog_present(dialog, parent->widget); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
254 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
255 | if(entry) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
256 | gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
257 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
258 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
259 | #else |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
260 | |
32 | 261 | static void ui_dialog_response (GtkDialog* self, gint response_id, gpointer user_data) { |
262 | UiEventData *data = user_data; | |
263 | UiEvent evt; | |
264 | evt.obj = data->obj; | |
265 | evt.document = evt.obj->ctx->document; | |
266 | evt.window = evt.obj->window; | |
267 | evt.eventdata = NULL; | |
268 | evt.intval = 0; | |
269 | ||
270 | if(data->customdata) { | |
271 | GtkWidget *entry = data->customdata; | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
272 | evt.eventdata = (void*)ENTRY_GET_TEXT(GTK_ENTRY(entry)); |
32 | 273 | |
274 | } | |
275 | ||
276 | if(response_id == 1 || response_id == 2) { | |
277 | evt.intval = response_id; | |
278 | } | |
279 | ||
280 | ||
281 | if(data->callback) { | |
282 | data->callback(&evt, data->userdata); | |
283 | } | |
284 | ||
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
285 | WINDOW_DESTROY(GTK_WIDGET(self)); |
32 | 286 | } |
287 | ||
288 | void ui_dialog_create(UiObject *parent, UiDialogArgs args) { | |
289 | GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new()); | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
290 | gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent->widget)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
291 | gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
292 | |
32 | 293 | GtkWidget *dialog_w = GTK_WIDGET(dialog); |
294 | if(args.title) { | |
295 | gtk_window_set_title(GTK_WINDOW(dialog), args.title); | |
296 | } | |
297 | if(args.button1_label) { | |
298 | gtk_dialog_add_button(dialog, args.button1_label, 1); | |
299 | } | |
300 | if(args.button2_label) { | |
301 | gtk_dialog_add_button(dialog, args.button2_label, 2); | |
302 | } | |
303 | if(args.closebutton_label) { | |
304 | gtk_dialog_add_button(dialog, args.closebutton_label, 0); | |
305 | } | |
306 | ||
307 | GtkWidget *content_area = gtk_dialog_get_content_area(dialog); | |
308 | if(args.content) { | |
309 | GtkWidget *label = gtk_label_new(args.content); | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
310 | BOX_ADD(content_area, label); |
32 | 311 | } |
312 | ||
313 | GtkWidget *textfield = NULL; | |
314 | if(args.input) { | |
315 | textfield = gtk_entry_new(); | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
316 | BOX_ADD(content_area, textfield); |
32 | 317 | } |
318 | ||
319 | UiEventData *event = malloc(sizeof(UiEventData)); | |
320 | event->obj = parent; | |
321 | event->callback = args.result; | |
322 | event->userdata = args.resultdata; | |
323 | event->value = 0; | |
324 | event->customdata = textfield; | |
325 | ||
326 | g_signal_connect(dialog_w, | |
327 | "response", | |
328 | G_CALLBACK(ui_dialog_response), | |
329 | event); | |
330 | ||
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
331 | WINDOW_SHOW(GTK_WIDGET(dialog_w)); |
32 | 332 | } |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
333 | #endif |
32 | 334 | |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
335 | |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
336 | #if GTK_MAJOR_VERSION >= 3 |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
337 | UiFileList listmodel2filelist(GListModel *selection) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
338 | UiFileList flist; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
339 | flist.files = NULL; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
340 | flist.nfiles = 0; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
341 | flist.nfiles = g_list_model_get_n_items(selection); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
342 | flist.files = calloc(flist.nfiles, sizeof(char*)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
343 | for(int i=0;i<flist.nfiles;i++) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
344 | GFile *file = g_list_model_get_item(selection, i); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
345 | char *path = g_file_get_path(file); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
346 | flist.files[i] = path ? strdup(path) : NULL; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
347 | g_object_unref(file); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
348 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
349 | return flist; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
350 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
351 | #endif |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
352 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
353 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
354 | #if GTK_CHECK_VERSION(4, 10, 0) |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
355 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
356 | #define UI_GTK_FILEDIALOG_OPEN 16 |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
357 | #define UI_GTK_FILEDIALOG_SAVE 32 |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
358 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
359 | static void filechooser_opened(GObject *source, GAsyncResult *result, void *data) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
360 | UiEventData *event = data; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
361 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
362 | GFile *file = NULL; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
363 | GListModel *selection = NULL; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
364 | GError *error = NULL; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
365 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
366 | int mode = event->value; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
367 | int multi = mode & UI_FILEDIALOG_SELECT_MULTI; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
368 | if((mode & UI_FILEDIALOG_SELECT_FOLDER) == UI_FILEDIALOG_SELECT_FOLDER) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
369 | if(multi) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
370 | selection = gtk_file_dialog_select_multiple_folders_finish(GTK_FILE_DIALOG(source), result, &error); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
371 | } else { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
372 | file = gtk_file_dialog_select_folder_finish(GTK_FILE_DIALOG(source), result, &error); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
373 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
374 | } else if((mode & UI_GTK_FILEDIALOG_OPEN) == UI_GTK_FILEDIALOG_OPEN) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
375 | if(multi) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
376 | selection = gtk_file_dialog_open_multiple_finish(GTK_FILE_DIALOG(source), result, &error); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
377 | } else { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
378 | file = gtk_file_dialog_open_finish(GTK_FILE_DIALOG(source), result, &error); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
379 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
380 | } else { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
381 | file = gtk_file_dialog_save_finish(GTK_FILE_DIALOG(source), result, &error); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
382 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
383 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
384 | UiEvent evt; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
385 | evt.obj = event->obj; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
386 | evt.document = evt.obj->ctx->document; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
387 | evt.window = evt.obj->window; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
388 | evt.intval = 0; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
389 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
390 | UiFileList flist; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
391 | flist.files = NULL; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
392 | flist.nfiles = 0; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
393 | evt.eventdata = &flist; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
394 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
395 | if(selection) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
396 | flist = listmodel2filelist(selection); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
397 | g_object_unref(selection); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
398 | } else if(file) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
399 | char *path = g_file_get_path(file); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
400 | if(path) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
401 | flist.nfiles = 1; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
402 | flist.files = calloc(flist.nfiles, sizeof(char*)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
403 | flist.files[0] = strdup(path); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
404 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
405 | g_object_unref(file); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
406 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
407 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
408 | if(event->callback) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
409 | event->callback(&evt, event->userdata); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
410 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
411 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
412 | for(int i=0;i<flist.nfiles;i++) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
413 | free(flist.files[i]); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
414 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
415 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
416 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
417 | static void ui_gtkfilechooser(UiObject *obj, GtkFileChooserAction action, unsigned int mode, const char *name, ui_callback file_selected_callback, void *cbdata) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
418 | if(action == GTK_FILE_CHOOSER_ACTION_OPEN) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
419 | mode |= UI_GTK_FILEDIALOG_OPEN; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
420 | } else { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
421 | mode |= UI_GTK_FILEDIALOG_SAVE; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
422 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
423 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
424 | UiEventData *event = malloc(sizeof(UiEventData)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
425 | event->callback = file_selected_callback; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
426 | event->userdata = cbdata; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
427 | event->customdata = NULL; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
428 | event->value = mode; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
429 | event->obj = obj; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
430 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
431 | GtkWindow *parent = GTK_WINDOW(gtk_widget_get_root(obj->widget)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
432 | GtkFileDialog *dialog = gtk_file_dialog_new(); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
433 | if(name) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
434 | gtk_file_dialog_set_initial_name(dialog, name); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
435 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
436 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
437 | int multi = mode & UI_FILEDIALOG_SELECT_MULTI; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
438 | if((mode & UI_FILEDIALOG_SELECT_FOLDER) == UI_FILEDIALOG_SELECT_FOLDER) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
439 | if(multi) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
440 | gtk_file_dialog_select_multiple_folders(dialog, parent, NULL, filechooser_opened, event); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
441 | } else { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
442 | gtk_file_dialog_select_folder(dialog, parent, NULL, filechooser_opened, event); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
443 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
444 | } else if(action == GTK_FILE_CHOOSER_ACTION_OPEN) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
445 | if(multi) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
446 | gtk_file_dialog_open_multiple(dialog, parent, NULL, filechooser_opened, event); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
447 | } else { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
448 | gtk_file_dialog_open(dialog, parent, NULL, filechooser_opened, event); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
449 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
450 | } else { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
451 | gtk_file_dialog_save(dialog, parent, NULL, filechooser_opened, event); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
452 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
453 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
454 | g_object_unref(dialog); |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
455 | } |
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
456 | #else |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
457 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
458 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
459 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
460 | static void filechooser_response(GtkDialog* self, gint response_id, UiEventData *data) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
461 | UiEvent evt; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
462 | evt.obj = data->obj; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
463 | evt.document = evt.obj->ctx->document; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
464 | evt.window = evt.obj->window; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
465 | evt.intval = 0; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
466 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
467 | UiFileList flist; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
468 | flist.files = NULL; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
469 | flist.nfiles = 0; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
470 | evt.eventdata = &flist; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
471 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
472 | if(response_id == GTK_RESPONSE_ACCEPT) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
473 | #if GTK_CHECK_VERSION(4, 0, 0) |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
474 | GListModel *selection = gtk_file_chooser_get_files(GTK_FILE_CHOOSER(self)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
475 | flist = flist = listmodel2filelist(selection); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
476 | g_object_unref(selection); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
477 | #else |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
478 | GSList *selection = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(self)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
479 | flist.nfiles = g_slist_length(selection); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
480 | flist.files = calloc(flist.nfiles, sizeof(char*)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
481 | int i = 0; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
482 | while(selection) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
483 | char *file = selection->data; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
484 | flist.files[i] = strdup(file); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
485 | g_free(file); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
486 | selection = selection->next; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
487 | i++; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
488 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
489 | g_slist_free(selection); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
490 | #endif |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
491 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
492 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
493 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
494 | if(data->callback) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
495 | data->callback(&evt, data->userdata); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
496 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
497 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
498 | for(int i=0;i<flist.nfiles;i++) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
499 | free(flist.files[i]); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
500 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
501 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
502 | WINDOW_DESTROY(GTK_WIDGET(self)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
503 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
504 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
505 | static void ui_gtkfilechooser(UiObject *obj, GtkFileChooserAction action, unsigned int mode, const char *name, ui_callback file_selected_callback, void *cbdata) { |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
506 | char *button; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
507 | char *title; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508 | |
32 | 509 | GtkWidget *dialog; |
510 | if((mode & UI_FILEDIALOG_SELECT_FOLDER) == UI_FILEDIALOG_SELECT_FOLDER) { | |
511 | dialog = gtk_file_chooser_dialog_new ( | |
512 | "Open Folder", | |
513 | GTK_WINDOW(obj->widget), | |
514 | GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, | |
515 | "Cancel", | |
516 | GTK_RESPONSE_CANCEL, | |
517 | "Select Folder", | |
518 | GTK_RESPONSE_ACCEPT, | |
519 | NULL); | |
520 | } else if(action == GTK_FILE_CHOOSER_ACTION_OPEN) { | |
521 | dialog = gtk_file_chooser_dialog_new ( | |
522 | "Select Folder", | |
523 | GTK_WINDOW(obj->widget), | |
524 | action, | |
525 | "Cancel", | |
526 | GTK_RESPONSE_CANCEL, | |
527 | "Open File", | |
528 | GTK_RESPONSE_ACCEPT, | |
529 | NULL); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
530 | } else { |
32 | 531 | dialog = gtk_file_chooser_dialog_new ( |
532 | "Save File", | |
533 | GTK_WINDOW(obj->widget), | |
534 | action, | |
535 | "Cancel", | |
536 | GTK_RESPONSE_CANCEL, | |
537 | "Save File", | |
538 | GTK_RESPONSE_ACCEPT, | |
539 | NULL); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
540 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
541 | |
32 | 542 | if((mode & UI_FILEDIALOG_SELECT_MULTI) == UI_FILEDIALOG_SELECT_MULTI) { |
543 | gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
544 | } |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
545 | |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
546 | UiEventData *event = malloc(sizeof(UiEventData)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
547 | event->obj = obj; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
548 | event->userdata = cbdata; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
549 | event->callback = file_selected_callback; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
550 | event->value = 0; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
551 | event->customdata = NULL; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
552 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
553 | g_signal_connect( |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
554 | dialog, |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
555 | "response", |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
556 | G_CALLBACK(filechooser_response), |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
557 | event); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
558 | g_signal_connect( |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
559 | dialog, |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
560 | "destroy", |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
561 | G_CALLBACK(ui_destroy_userdata), |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
562 | event); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
563 | |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
564 | |
32 | 565 | UiEvent evt; |
566 | evt.obj = obj; | |
567 | evt.document = evt.obj->ctx->document; | |
568 | evt.window = evt.obj->window; | |
569 | evt.intval = 0; | |
570 | ||
571 | UiFileList flist; | |
572 | flist.files = NULL; | |
573 | flist.nfiles = 0; | |
574 | evt.eventdata = &flist; | |
575 | ||
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
576 | gtk_widget_show(dialog); |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
577 | } |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
578 | #endif |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | |
32 | 580 | void ui_openfiledialog(UiObject *obj, unsigned int mode, ui_callback file_selected_callback, void *cbdata) { |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
581 | ui_gtkfilechooser(obj, GTK_FILE_CHOOSER_ACTION_OPEN, mode, NULL, file_selected_callback, cbdata); |
32 | 582 | } |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583 | |
32 | 584 | void ui_savefiledialog(UiObject *obj, const char *name, ui_callback file_selected_callback, void *cbdata) { |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
585 | ui_gtkfilechooser(obj, GTK_FILE_CHOOSER_ACTION_SAVE, 0, name, file_selected_callback, cbdata); |
32 | 586 | } |
587 |