1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
# data file for the Fltk User Interface Designer (fluid)
version 1.0500
header_name {.h}
code_name {.cxx}
include_guard {}
comment {//
// FLUID template support for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
// https://www.fltk.org/bugs.php
//
} {in_source in_header
}
decl {\#include "Fluid.h"} {private local
}
decl {\#include "tools/filename.h"} {selected private local
}
decl {\#include <FL/Fl_Shared_Image.H>} {private local
}
decl {\#include <FL/fl_ask.H>} {private local
}
decl {\#include <FL/fl_string_functions.h>} {private local
}
decl {\#include "../src/flstring.h"} {private local
}
decl {\#include <stdio.h>} {private local
}
decl {\#include <stdlib.h>} {private local
}
decl {\#include <errno.h>} {private local
}
decl {\#include <zlib.h>} {private local
}
declblock {\#if defined(_WIN32) && !defined(__CYGWIN__)} {after {\#endif // _WIN32 && !__CYGWIN__}
} {
decl {\#include <io.h>} {private local
}
decl {\#else} {private local
}
decl {\#include <unistd.h>} {private local
}
}
Function {make_template_panel()} {open
} {
Fl_Window template_panel {
label {New/Save Template}
callback {Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
if (img) img->release();
template_preview->image(0);
template_browser->deselect();
template_name->value("");
template_instance->value("");
template_panel->hide();} open
xywh {478 284 460 355} type Double resizable modal visible
} {
Fl_Browser template_browser {
label {Available Templates:}
callback {if (Fl::event_clicks()) {
template_panel->hide();
return;
}
Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
if (img) img->release();
template_preview->image(0);
template_preview->redraw();
int item = template_browser->value();
if (item <= 1) template_instance->deactivate();
else template_instance->activate();
if (item < 1) {
template_submit->deactivate();
template_delete->deactivate();
return;
}
template_submit->activate();
const char *flfile = (const char *)template_browser->data(item);
if (!flfile) {
template_delete->deactivate();
return;
}
template_name->value(template_browser->text(item));
template_delete->activate();
char pngfile[1024], *ext;
strlcpy(pngfile, flfile, sizeof(pngfile));
if ((ext = strrchr(pngfile, '.')) == nullptr) return;
strcpy(ext, ".png");
img = Fl_Shared_Image::get(pngfile);
if (img) {
template_preview->image(img);
template_preview->redraw();
}}
xywh {10 28 180 250} type Hold labelfont 1 align 5 when 3
}
Fl_Box template_preview {
xywh {200 28 250 250} box THIN_DOWN_BOX align 80 resizable
}
Fl_Input template_name {
label {Template Name:}
callback {if (strlen(template_name->value())) {
template_submit->activate();
if (Fl::event_key() == FL_Enter) template_panel->hide();
} else template_submit->deactivate();}
xywh {198 288 252 25} labelfont 1 when 3 textfont 4
}
Fl_Input template_instance {
label {Instance Name:}
xywh {198 288 252 25} labelfont 1 textfont 4 hide
}
Fl_Group {} {open
xywh {10 323 440 25}
} {
Fl_Button template_delete {
label {Delete Template}
callback template_delete_cb
xywh {10 323 143 25}
}
Fl_Box {} {
xywh {153 323 126 25} resizable
}
Fl_Button {} {
label Cancel
callback {Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
if (img) img->release();
template_preview->image(0);
template_browser->deselect();
template_name->value("");
template_instance->value("");
template_panel->hide();}
xywh {289 323 72 25}
}
Fl_Return_Button template_submit {
label Save
callback {Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
if (img) img->release();
template_preview->image(0);
template_panel->hide();}
xywh {371 323 79 25}
}
}
}
}
Function {template_clear()} {return_type void
} {
code {int i;
void *filename;
for (i = 1; i <= template_browser->size(); i ++) {
if ((filename = template_browser->data(i)) != nullptr) free(filename);
}
template_browser->deselect();
template_browser->clear();} {}
}
Function {template_delete_cb(Fl_Button *, void *)} {open return_type void
} {
code {int item = template_browser->value();
if (item < 1) return;
const char *name = template_browser->text(item);
const char *flfile = (const char *)template_browser->data(item);
if (!flfile) return;
if (!fl_choice("Are you sure you want to delete the template \\"%s\\"?",
"Cancel", "Delete", 0, name)) return;
if (fl_unlink(flfile)) {
fl_alert("Unable to delete template \\"%s\\":\\n%s", name, strerror(errno));
return;
}
char pngfile[1024], *ext;
strlcpy(pngfile, flfile, sizeof(pngfile));
if ((ext = strrchr(pngfile, '.')) != nullptr) {
strcpy(ext, ".png");
fl_unlink(pngfile);
}
template_browser->remove(item);
template_browser->do_callback();} {}
}
data tmpl_FLTK_License_fl {private local filename {../templates/FLTK_License.fl} compressed
}
data tmpl_1of7GUIs_fl {private local filename {../templates/1of7GUIs.fl} compressed
}
Function {template_install(const char *path, const char *name, const uchar *inSrc, int inSrcLen, int inDstLen)} {open return_type void
} {
code {char filename[FL_PATH_MAX];
strcpy(filename, path);
strcat(filename, name);
FILE *f = fopen(filename, "wb");
if (!f) return;
uLong dstLen = inDstLen;
Bytef *dst = (Bytef*)::malloc(inDstLen);
if (uncompress(dst, &dstLen, (Bytef*)inSrc, (uLong)inSrcLen) != Z_OK) { /* error */ }
if (fwrite(dst, dstLen, 1, f) <= 0) { /* error */ }
fclose(f);} {}
}
Function {template_load()} {open return_type void
} {
code {int i;
char name[1024], filename[1400], path[1024], *ptr;
struct dirent **files;
int num_files;
Fluid.preferences.getUserdataPath(path, sizeof(path));
strlcat(path, "templates", sizeof(path));
fl_make_path(path);
int sample_templates_generated = 0;
Fluid.preferences.get("sample_templates_generated", sample_templates_generated, 0);
if (sample_templates_generated < 2) {
strcpy(filename, path);
strcat(filename, "/FLTK_License.fl");
FILE *f = fopen(filename, "wb");
if (f) {
fputs(
"\# data file for the Fltk User Interface Designer (fluid)\\nversion 1.0400\\nheader_name {.h}\\n"
"code_name {.cxx}\\ncomment {//\\n// @INSTANCE@ for the Fast Light Tool Kit (FLT"
"K).\\n//\\n// Copyright 1998-2023 by Bill Spitzak and others.\\n//\\n// This library is free sof"
"tware. Distribution and use rights are outlined in\\n// the file \\"COPYING\\" which should have "
"been included with this file. If this\\n// file is missing or damaged, see the license at:\\n"
"//\\n// https://www.fltk.org/COPYING.php\\n//\\n// Please see the following page on how to report "
"bugs and issues:\\n//\\n// https://www.fltk.org/bugs.php\\n//\\n} {selected in_source in_head"
"er\\n}\\n", f);
fclose(f);
}
template_install(path, "/FLTK_License.fl", tmpl_FLTK_License_fl, sizeof(tmpl_FLTK_License_fl), tmpl_FLTK_License_fl_size);
template_install(path, "/1of7GUIs.fl", tmpl_1of7GUIs_fl, sizeof(tmpl_1of7GUIs_fl), tmpl_1of7GUIs_fl_size);
sample_templates_generated = 2;
Fluid.preferences.set("sample_templates_generated", sample_templates_generated);
Fluid.preferences.flush();
}
num_files = fl_filename_list(path, &files);
for (i = 0; i < num_files; i ++) {
if (fl_filename_match(files[i]->d_name, "*.fl")) {
// Format the name as the filename with "_" replaced with " "
// and without the trailing ".fl"...
strlcpy(name, files[i]->d_name, sizeof(name));
*strstr(name, ".fl") = '\\0';
for (ptr = name; *ptr; ptr ++) {
if (*ptr == '_') *ptr = ' ';
}
// Add the template to the browser...
snprintf(filename, sizeof(filename), "%s/%s", path, files[i]->d_name);
template_browser->add(name, fl_strdup(filename));
}
free(files[i]);
}
if (num_files > 0) free(files);} {}
}
|