Skip to content

Commit 2044a35

Browse files
committed
FLTK: fix file save as handling
1 parent 7896575 commit 2044a35

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function buildSDL() {
205205
PACKAGE_CFLAGS="${PACKAGE_CFLAGS} ${FONTCONFIG_CFLAGS}"
206206

207207
dnl backlinking support for modules
208-
PACKAGE_LIBS="${PACKAGE_LIBS} -ldl"
208+
PACKAGE_LIBS="${PACKAGE_LIBS} -ldl -no-pie"
209209
PACKAGE_LIBS="${PACKAGE_LIBS} ${FONTCONFIG_LIBS}"
210210
PACKAGE_LIBS="-static-libgcc ${PACKAGE_LIBS} `sdl2-config --static-libs` `freetype-config --libs`"
211211
esac
@@ -344,7 +344,7 @@ function buildFLTK() {
344344

345345
FLTK_CXXFLAGS="${PACKAGE_CFLAGS} `fltk-config --cxxflags`"
346346
FLTK_CXXFLAGS="${FLTK_CXXFLAGS} -fno-exceptions -fno-rtti -std=c++11 -Wno-unknown-pragmas"
347-
PACKAGE_LIBS="${PACKAGE_LIBS} `fltk-config --ldstaticflags --use-images`"
347+
PACKAGE_LIBS="${PACKAGE_LIBS} `fltk-config --ldstaticflags --use-images` -no-pie"
348348

349349
dnl do not depend on cygwin.dll under cygwin build
350350
case "${host_os}" in

src/platform/fltk/EditorWidget.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,6 @@ bool EditorWidget::checkSave(bool discard) {
629629
} else {
630630
r = fl_choice(msg, "Save", "Cancel", NULL, NULL);
631631
}
632-
fprintf(stderr, "selected %d\n", r);
633632
if (r == 0) {
634633
// save selected
635634
save_file();

src/platform/fltk/FileWidget.cxx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void FileWidget::fileOpen(EditorWidget *_saveEditorAs) {
266266
//
267267
void FileWidget::openPath(const char *newPath, StringList *recentPaths) {
268268
if (newPath && access(newPath, R_OK) == 0) {
269-
strcpy(_path, newPath);
269+
strlcpy(_path, newPath, PATH_MAX);
270270
} else {
271271
getcwd(_path, sizeof(_path));
272272
}
@@ -285,7 +285,7 @@ void FileWidget::openPath(const char *newPath, StringList *recentPaths) {
285285
void FileWidget::changeDir(const char *target) {
286286
char newPath[PATH_MAX + 1];
287287

288-
strcpy(newPath, _path);
288+
strlcpy(newPath, _path, PATH_MAX);
289289

290290
// file browser window
291291
if (strcmp(target, "..") == 0) {
@@ -299,9 +299,9 @@ void FileWidget::changeDir(const char *target) {
299299
} else {
300300
// go down a level
301301
if (newPath[strlen(newPath) - 1] != '/') {
302-
strcat(newPath, "/");
302+
strlcat(newPath, "/", PATH_MAX);
303303
}
304-
strcat(newPath, target);
304+
strlcat(newPath, target, PATH_MAX);
305305
}
306306
setDir(newPath);
307307
}
@@ -311,7 +311,7 @@ void FileWidget::changeDir(const char *target) {
311311
//
312312
void FileWidget::setDir(const char *target) {
313313
if (chdir(target) == 0) {
314-
strcpy(_path, target);
314+
strlcpy(_path, target, PATH_MAX);
315315
displayPath();
316316
} else {
317317
fl_message("Invalid path '%s'", target);
@@ -365,10 +365,10 @@ void FileWidget::displayPath() {
365365
if (_saveEditorAs) {
366366
const char *path = _saveEditorAs->getFilename();
367367
const char *slash = strrchr(path, '/');
368-
html.append("<b>Save ").append(slash ? slash + 1 : path).append(" as:<br>")
368+
html.append("<b>Save ").append(slash ? slash + 1 : path).append(" as:<font size=3><br>")
369369
.append("<input size=220 type=text value='").append(slash ? slash + 1 : path)
370370
.append("' name=saveas>&nbsp;<input type=button onclick='")
371-
.append(CMD_SAVE_AS).append("' value='Save As'><br><br>");
371+
.append(CMD_SAVE_AS).append("' value='Save As'><br><font size=2>");
372372
}
373373

374374
_recentPaths->sort(stringCompare);
@@ -433,7 +433,7 @@ void FileWidget::enterPath() {
433433
const char *newPath = fl_input("Enter path:", _path);
434434
if (newPath != 0) {
435435
if (chdir(newPath) == 0) {
436-
strcpy(_path, newPath);
436+
strlcpy(_path, newPath, PATH_MAX);
437437
displayPath();
438438
} else {
439439
fl_message("Invalid path '%s'", newPath);
@@ -497,23 +497,26 @@ void FileWidget::saveAs() {
497497
// substitute ~ for $HOME contents
498498
const char *home = dev_getenv("HOME");
499499
if (home) {
500-
strcpy(savepath, home);
500+
strlcpy(savepath, home, PATH_MAX);
501501
} else {
502502
savepath[0] = 0;
503503
}
504-
strcat(savepath, enteredPath + 1);
504+
strlcat(savepath, enteredPath + 1, PATH_MAX);
505505
} else if (enteredPath[0] == '/' || enteredPath[1] == ':') {
506506
// absolute path given
507-
strcpy(savepath, enteredPath);
507+
strlcpy(savepath, enteredPath, PATH_MAX);
508508
} else {
509-
strcpy(savepath, _path);
510-
strcat(savepath, "/");
511-
strcat(savepath, enteredPath);
509+
strlcpy(savepath, _path, PATH_MAX);
510+
strlcat(savepath, "/", PATH_MAX);
511+
strlcat(savepath, enteredPath, PATH_MAX);
512+
}
513+
if (strcasecmp(savepath + strlen(savepath) - 4, ".bas") != 0) {
514+
strlcat(savepath, ".bas", PATH_MAX);
512515
}
513516
const char *msg = "%s\n\nFile already exists.\nDo you want to replace it?";
514517
if (access(savepath, 0) != 0 || fl_choice(msg, "Yes", "No", 0, savepath) == 0) {
515518
_saveEditorAs->doSaveFile(savepath);
516-
}
519+
}
517520
}
518521
}
519522
}

src/platform/fltk/HelpView.cxx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ const char *aboutText =
3030
const char CMD_LEVEL1_OPEN = '+';
3131
const char CMD_LEVEL2_OPEN = '!';
3232
const char CMD_MORE = '^';
33-
const char LEVEL1_OPEN[] = "+ ";
34-
const char LEVEL2_OPEN[] = " + ";
35-
const char LEVEL1_CLOSE[] = " - ";
36-
const char LEVEL2_CLOSE[] = " - ";
3733

3834
HelpView *helpView;
3935

src/platform/fltk/HelpWidget.cxx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ void createDropList(InputNode *node, strlib::List<String *> *options) {
14461446

14471447
void InputNode::update(strlib::List<NamedInput *> *names, Properties<String *> *env, Attributes *a) {
14481448
Fl_Valuator *valuator;
1449-
Fl_Input *input;
1449+
Fl_Input *input = NULL;
14501450
Fl_Color color;
14511451
strlib::String *name = a->getName();
14521452
strlib::String *value = a->getValue();
@@ -1490,7 +1490,6 @@ void InputNode::update(strlib::List<NamedInput *> *names, Properties<String *> *
14901490
}
14911491
break;
14921492
case ID_TEXTBOX:
1493-
button->box(FL_NO_BOX);
14941493
input = (Fl_Input *)button;
14951494
if (value && value->length()) {
14961495
input->value(value->c_str());
@@ -1523,17 +1522,11 @@ void InputNode::update(strlib::List<NamedInput *> *names, Properties<String *> *
15231522
// set colors
15241523
color = getColor(a->getBgColor(), 0);
15251524
if (color) {
1526-
button->color(color); // background
1527-
} else {
1528-
button->color(BUTTON_COLOR);
1525+
button->color(color);
15291526
}
15301527
color = getColor(a->getFgColor(), 0);
15311528
if (color) {
1532-
button->labelcolor(color); // foreground
1533-
button->color(color);
1534-
} else {
1535-
button->labelcolor(ANCHOR_COLOR);
1536-
button->color(ANCHOR_COLOR);
1529+
button->labelcolor(color);
15371530
}
15381531

15391532
// set alignment
@@ -1587,6 +1580,10 @@ void InputNode::display(Display *out) {
15871580
button->size(4 + (fl_width("$") * cols), button->h());
15881581
height = 4 + (fl_height() + fl_descent() * rows);
15891582
break;
1583+
case ID_TEXTBOX:
1584+
((Fl_Input *)button)->textfont(out->font);
1585+
((Fl_Input *)button)->textsize(out->fontSize);
1586+
break;
15901587
default:
15911588
break;
15921589
}
@@ -1598,7 +1595,7 @@ void InputNode::display(Display *out) {
15981595
button->labelfont(out->font);
15991596
button->labelsize(out->fontSize);
16001597
if (button->y() + button->h() < out->y2 && button->y() >= 0) {
1601-
button->clear_visible();
1598+
button->set_visible();
16021599
} else {
16031600
// draw a fake control in case partially visible
16041601
fl_color(button->color());
@@ -1862,6 +1859,11 @@ void HelpWidget::resize(int x, int y, int w, int h) {
18621859
}
18631860

18641861
void HelpWidget::draw() {
1862+
if (damage() == FL_DAMAGE_CHILD) {
1863+
Fl_Group::draw();
1864+
return;
1865+
}
1866+
18651867
int vscroll = -scrollbar->value();
18661868
Display out;
18671869
out.uline = false;
@@ -2008,7 +2010,7 @@ void HelpWidget::draw() {
20082010
for (int n = 0; n < numchildren; n++) {
20092011
Fl_Widget &w = *child(n);
20102012
if (&w != scrollbar) {
2011-
update_child(w);
2013+
draw_child(w);
20122014
}
20132015
}
20142016
fl_pop_clip();

0 commit comments

Comments
 (0)