Mon, 11 Nov 2024 20:45:34 +0100
fix text/image preview loading
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 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include "display.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "container.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include "../common/context.h" |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include "../common/object.h" |
32 | 36 | #include "../ui/display.h" |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
38 | #include <cx/printf.h> |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
39 | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | static void set_alignment(GtkWidget *widget, float xalign, float yalign) { |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
41 | #if GTK_MAJOR_VERSION >= 4 || (GTK_MAJOR_VERSION >= 3 && GTK_MINOR_VERSION >= 16) |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | gtk_label_set_xalign(GTK_LABEL(widget), xalign); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | gtk_label_set_yalign(GTK_LABEL(widget), yalign); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #else |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | gtk_misc_set_alignment(GTK_MISC(widget), xalign, yalign); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | #endif |
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 | |
32 | 49 | UIWIDGET ui_label_create(UiObject *obj, UiLabelArgs args) { |
50 | UiObject* current = uic_current_obj(obj); | |
51 | ||
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
52 | const char *css_class = NULL; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
53 | char *markup = NULL; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
54 | if(args.label) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
55 | #if GTK_MAJOR_VERSION < 3 |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
56 | switch(args.style) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
57 | case UI_LABEL_STYLE_DEFAULT: break; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
58 | case UI_LABEL_STYLE_TITLE: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
59 | cxmutstr m = cx_asprintf("<b>%s</b>", args.label); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
60 | markup = m.ptr; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
61 | args.label = NULL; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
62 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
63 | case UI_LABEL_STYLE_SUBTITLE: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
64 | break; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
65 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
66 | case UI_LABEL_STYLE_DIM: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
67 | break; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
68 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
69 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
70 | # else |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
71 | switch(args.style) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
72 | case UI_LABEL_STYLE_DEFAULT: break; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
73 | case UI_LABEL_STYLE_TITLE: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
74 | css_class = "ui_label_title"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
75 | break; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
76 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
77 | case UI_LABEL_STYLE_SUBTITLE: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
78 | css_class = "subtitle"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
79 | break; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
80 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
81 | case UI_LABEL_STYLE_DIM: { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
82 | css_class = "dim-label"; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
83 | break; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
84 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
85 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
86 | # endif |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
87 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
88 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
89 | |
32 | 90 | GtkWidget *widget = gtk_label_new(args.label); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
91 | if(markup) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
92 | gtk_label_set_markup(GTK_LABEL(widget), markup); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
93 | free(markup); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
94 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
95 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
96 | if(css_class) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
97 | WIDGET_ADD_CSS_CLASS(widget, css_class); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
98 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
99 | |
32 | 100 | switch(args.align) { |
101 | case UI_ALIGN_DEFAULT: break; | |
102 | case UI_ALIGN_LEFT: set_alignment(widget, 0, .5); break; | |
103 | case UI_ALIGN_RIGHT: set_alignment(widget, 1, .5); break; | |
104 | case UI_ALIGN_CENTER: break; // TODO | |
105 | } | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
107 | |
32 | 108 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING); |
109 | if(var) { | |
110 | UiString* value = (UiString*)var->value; | |
111 | value->obj = widget; | |
112 | value->get = ui_label_get; | |
113 | value->set = ui_label_set; | |
114 | } | |
115 | ||
116 | UI_APPLY_LAYOUT1(current, args); | |
117 | current->container->add(current->container, widget, FALSE); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | return widget; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | |
32 | 122 | UIWIDGET ui_llabel_create(UiObject* obj, UiLabelArgs args) { |
123 | args.align = UI_ALIGN_LEFT; | |
124 | return ui_label_create(obj, args); | |
125 | } | |
126 | ||
127 | UIWIDGET ui_rlabel_create(UiObject* obj, UiLabelArgs args) { | |
128 | args.align = UI_ALIGN_RIGHT; | |
129 | return ui_label_create(obj, args); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | |
32 | 132 | char* ui_label_get(UiString *s) { |
133 | if(s->value.ptr) { | |
134 | s->value.free(s->value.ptr); | |
135 | } | |
136 | s->value.ptr = g_strdup(gtk_label_get_text(GTK_LABEL(s->obj))); | |
137 | s->value.free = (ui_freefunc)g_free; | |
138 | return s->value.ptr; | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | |
32 | 141 | void ui_label_set(UiString *s, const char *value) { |
142 | gtk_label_set_text(GTK_LABEL(s->obj), value); | |
143 | if(s->value.ptr) { | |
144 | s->value.free(s->value.ptr); | |
145 | s->value.ptr = NULL; | |
146 | s->value.free = NULL; | |
147 | } | |
148 | } | |
149 | ||
150 | UIWIDGET ui_space_deprecated(UiObject *obj) { | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | GtkWidget *widget = gtk_label_new(""); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | UiContainer *ct = uic_get_current_container(obj); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | ct->add(ct, widget, TRUE); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | return widget; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | |
32 | 158 | UIWIDGET ui_separator_deprecated(UiObject *obj) { |
44
473954dc6b74
update toolkit: gtk4 improvements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
159 | #if GTK_MAJOR_VERSION >= 3 |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | GtkWidget *widget = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | #else |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | GtkWidget *widget = gtk_hseparator_new(); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | #endif |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | UiContainer *ct = uic_get_current_container(obj); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | ct->add(ct, widget, FALSE); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | return widget; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | /* ------------------------- progress bar ------------------------- */ |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
172 | typedef struct UiProgressBarRange { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
173 | double min; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
174 | double max; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
175 | } UiProgressBarRange; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
176 | |
32 | 177 | UIWIDGET ui_progressbar_create(UiObject *obj, UiProgressbarArgs args) { |
178 | UiObject* current = uic_current_obj(obj); | |
179 | ||
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | GtkWidget *progressbar = gtk_progress_bar_new(); |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
181 | if(args.max > args.min) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
182 | UiProgressBarRange *range = malloc(sizeof(UiProgressBarRange)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
183 | range->min = args.min; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
184 | range->max = args.max; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
185 | g_signal_connect( |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
186 | progressbar, |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
187 | "destroy", |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
188 | G_CALLBACK(ui_destroy_userdata), |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
189 | range); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
190 | g_object_set_data(G_OBJECT(progressbar), "ui_range", range); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
191 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
192 | |
32 | 193 | |
194 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_DOUBLE); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | if(var && var->value) { |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | UiDouble *value = var->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | value->get = ui_progressbar_get; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | value->set = ui_progressbar_set; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | value->obj = progressbar; |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
200 | ui_progressbar_set(value, value->value); |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | |
32 | 203 | UI_APPLY_LAYOUT1(current, args); |
204 | current->container->add(current->container, progressbar, FALSE); | |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | return progressbar; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | double ui_progressbar_get(UiDouble *d) { |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
210 | UiProgressBarRange *range = g_object_get_data(d->obj, "ui_range"); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
211 | double fraction = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(d->obj)); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
212 | if(range) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
213 | fraction = range->min + (range->max - range->min) * fraction; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
214 | } |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
215 | d->value = fraction; |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | return d->value; |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | } |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | void ui_progressbar_set(UiDouble *d, double value) { |
45
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
220 | d->value = value; |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
221 | UiProgressBarRange *range = g_object_get_data(d->obj, "ui_range"); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
222 | if(range) { |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
223 | value = (value - range->min) / (range->max - range->min); |
ab71409644b0
update toolkit, fix download/upload progressbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
224 | } |
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(d->obj), value); |
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | } |
32 | 227 | |
228 | ||
229 | /* ------------------------- progress spinner ------------------------- */ | |
230 | ||
231 | UIWIDGET ui_progressspinner_create(UiObject* obj, UiProgressbarSpinnerArgs args) { | |
232 | UiObject* current = uic_current_obj(obj); | |
233 | ||
234 | GtkWidget *spinner = gtk_spinner_new(); | |
235 | ||
236 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); | |
237 | if(var && var->value) { | |
238 | UiInteger *value = var->value; | |
239 | value->get = ui_spinner_get; | |
240 | value->set = ui_spinner_set; | |
241 | value->obj = spinner; | |
242 | ui_spinner_set(value, value->value); | |
243 | } | |
244 | ||
245 | UI_APPLY_LAYOUT1(current, args); | |
246 | current->container->add(current->container, spinner, FALSE); | |
247 | ||
248 | return spinner; | |
249 | } | |
250 | ||
251 | int64_t ui_spinner_get(UiInteger *i) { | |
252 | return i->value; | |
253 | } | |
254 | ||
255 | void ui_spinner_set(UiInteger *i, int64_t value) { | |
256 | i->value = value; | |
257 | if(i->obj) { | |
258 | GtkSpinner *spinner = GTK_SPINNER(i->obj); | |
259 | if(value != 0) { | |
260 | gtk_spinner_start(spinner); | |
261 | } else { | |
262 | gtk_spinner_stop(spinner); | |
263 | } | |
264 | } | |
265 | } |