Skip to content

Commit

Permalink
Basic C++17 changes for main.h
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasWM committed Nov 12, 2024
1 parent 4242320 commit b063524
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 184 deletions.
58 changes: 30 additions & 28 deletions fluid/Fd_Snap_Action.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <string.h>
#include <assert.h>

#include <algorithm> // min, max

// TODO: warning if the user wants to change builtin layouts
// TODO: move panel to global settings panel (move load & save to main pulldown, or to toolbox?)
// INFO: how about a small tool box for quick preset selection and disabling of individual snaps?
Expand Down Expand Up @@ -90,8 +92,8 @@ static Fd_Layout_Preset grid_tool = {
};

static Fd_Layout_Suite static_suite_list[] = {
{ (char*)"FLTK", (char*)"@fd_beaker FLTK", { &fltk_app, &fltk_dlg, &fltk_tool }, FD_STORE_INTERNAL },
{ (char*)"Grid", (char*)"@fd_beaker Grid", { &grid_app, &grid_dlg, &grid_tool }, FD_STORE_INTERNAL }
{ (char*)"FLTK", (char*)"@fd_beaker FLTK", { &fltk_app, &fltk_dlg, &fltk_tool }, Fd_Tool_Store::INTERNAL },
{ (char*)"Grid", (char*)"@fd_beaker Grid", { &grid_app, &grid_dlg, &grid_tool }, Fd_Tool_Store::INTERNAL }
};

Fl_Menu_Item main_layout_submenu_[] = {
Expand Down Expand Up @@ -390,10 +392,10 @@ void Fd_Layout_Suite::read(Fd_Project_Reader *in) {
void Fd_Layout_Suite::update_label() {
Fl_String sym;
switch (storage_) {
case FD_STORE_INTERNAL: sym.assign("@fd_beaker "); break;
case FD_STORE_USER: sym.assign("@fd_user "); break;
case FD_STORE_PROJECT: sym.assign("@fd_project "); break;
case FD_STORE_FILE: sym.assign("@fd_file "); break;
case Fd_Tool_Store::INTERNAL: sym.assign("@fd_beaker "); break;
case Fd_Tool_Store::USER: sym.assign("@fd_user "); break;
case Fd_Tool_Store::PROJECT: sym.assign("@fd_project "); break;
case Fd_Tool_Store::FILE: sym.assign("@fd_file "); break;
}
sym.append(name_);
if (menu_label)
Expand Down Expand Up @@ -423,14 +425,14 @@ void Fd_Layout_Suite::init() {
name_ = NULL;
menu_label = NULL;
layout[0] = layout[1] = layout[2] = NULL;
storage_ = FD_STORE_INTERNAL;
storage_ = Fd_Tool_Store::INTERNAL;
}

/**
Free all allocated resources.
*/
Fd_Layout_Suite::~Fd_Layout_Suite() {
if (storage_ == FD_STORE_INTERNAL) return;
if (storage_ == Fd_Tool_Store::INTERNAL) return;
if (name_) ::free(name_);
for (int i = 0; i < 3; ++i) {
delete layout[i];
Expand Down Expand Up @@ -606,7 +608,7 @@ Fd_Layout_List::~Fd_Layout_List() {
::free(choice_menu_);
for (int i = 0; i < list_size_; i++) {
Fd_Layout_Suite &suite = list_[i];
if (suite.storage_ != FD_STORE_INTERNAL)
if (suite.storage_ != Fd_Tool_Store::INTERNAL)
suite.~Fd_Layout_Suite();
}
::free(list_);
Expand Down Expand Up @@ -651,9 +653,9 @@ void Fd_Layout_List::update_menu_labels() {
Load all user layouts from the FLUID user preferences.
*/
int Fd_Layout_List::load(const Fl_String &filename) {
remove_all(FD_STORE_FILE);
remove_all(Fd_Tool_Store::FILE);
Fl_Preferences prefs(filename.c_str(), "layout.fluid.fltk.org", NULL, Fl_Preferences::C_LOCALE);
read(prefs, FD_STORE_FILE);
read(prefs, Fd_Tool_Store::FILE);
return 0;
}

Expand All @@ -664,7 +666,7 @@ int Fd_Layout_List::save(const Fl_String &filename) {
assert(this);
Fl_Preferences prefs(filename.c_str(), "layout.fluid.fltk.org", NULL, (Fl_Preferences::Root)(Fl_Preferences::C_LOCALE|Fl_Preferences::CLEAR));
prefs.clear();
write(prefs, FD_STORE_FILE);
write(prefs, Fd_Tool_Store::FILE);
return 0;
}

Expand Down Expand Up @@ -719,7 +721,7 @@ void Fd_Layout_List::write(Fd_Project_Writer *out) {
if ((current_suite()==0) && (current_preset()==0)) {
int nSuite = 0;
for (int i=0; i<list_size_; i++) {
if (list_[i].storage_ == FD_STORE_PROJECT) nSuite++;
if (list_[i].storage_ == Fd_Tool_Store::PROJECT) nSuite++;
}
if (nSuite == 0) return;
}
Expand All @@ -728,7 +730,7 @@ void Fd_Layout_List::write(Fd_Project_Writer *out) {
out->write_string(" current_preset %d\n", current_preset());
for (int i=0; i<list_size_; i++) {
Fd_Layout_Suite &suite = list_[i];
if (suite.storage_ == FD_STORE_PROJECT)
if (suite.storage_ == Fd_Tool_Store::PROJECT)
suite.write(out);
}
out->write_string("}");
Expand All @@ -755,7 +757,7 @@ void Fd_Layout_List::read(Fd_Project_Reader *in) {
} else if (!strcmp(key, "suite")) {
int n = add(in->filename_name());
list_[n].read(in);
list_[n].storage(FD_STORE_PROJECT);
list_[n].storage(Fd_Tool_Store::PROJECT);
} else if (!strcmp(key, "}")) {
break;
} else {
Expand Down Expand Up @@ -861,8 +863,8 @@ int Fd_Layout_List::add(const char *name) {
::memcpy(new_suite.layout[i], old_suite.layout[i], sizeof(Fd_Layout_Preset));
}
Fd_Tool_Store new_storage = old_suite.storage_;
if (new_storage == FD_STORE_INTERNAL)
new_storage = FD_STORE_USER;
if (new_storage == Fd_Tool_Store::INTERNAL)
new_storage = Fd_Tool_Store::USER;
new_suite.storage(new_storage);
main_menu_[n].label(new_suite.menu_label);
main_menu_[n].callback(main_menu_[0].callback());
Expand Down Expand Up @@ -903,7 +905,7 @@ void Fd_Layout_List::remove(int ix) {

/**
Remove all Suites that use the given storage attribute.
\param[in] storage storage attribute, see FD_STORE_INTERNAL, etc.
\param[in] storage storage attribute, see Fd_Tool_Store::INTERNAL, etc.
*/
void Fd_Layout_List::remove_all(Fd_Tool_Store storage) {
for (int i=list_size_-1; i>=0; --i) {
Expand Down Expand Up @@ -1105,8 +1107,8 @@ void Fd_Snap_Action::better_size(int &w, int &h) {
x_min = x_inc;
y_min = y_inc;
}
int ww = fd_max(w - x_min, 0); w = (w - ww + x_inc - 1) / x_inc; w = w * x_inc; w = w + ww;
int hh = fd_max(h - y_min, 0); h = (h - hh + y_inc - 1) / y_inc; h = h * y_inc; h = h + hh;
int ww = std::max(w - x_min, 0); w = (w - ww + x_inc - 1) / x_inc; w = w * x_inc; w = w + ww;
int hh = std::max(h - y_min, 0); h = (h - hh + y_inc - 1) / y_inc; h = h * y_inc; h = h + hh;
}


Expand Down Expand Up @@ -1495,8 +1497,8 @@ class Fd_Snap_Siblings_Left : public Fd_Snap_Sibling {
public:
Fd_Snap_Siblings_Left() { type = 1; mask = FD_LEFT|FD_DRAG; }
int sibling_check(Fd_Snap_Data &d, Fl_Widget *s) FL_OVERRIDE {
return fd_min(check_x_(d, d.bx, s->x()+s->w()),
check_x_(d, d.bx, s->x()+s->w()+layout->widget_gap_x) );
return std::min(check_x_(d, d.bx, s->x()+s->w()),
check_x_(d, d.bx, s->x()+s->w()+layout->widget_gap_x) );
}
void draw(Fd_Snap_Data &d) FL_OVERRIDE {
if (best_match) draw_right_brace(best_match);
Expand All @@ -1520,8 +1522,8 @@ class Fd_Snap_Siblings_Right : public Fd_Snap_Sibling {
public:
Fd_Snap_Siblings_Right() { type = 1; mask = FD_RIGHT|FD_DRAG; }
int sibling_check(Fd_Snap_Data &d, Fl_Widget *s) FL_OVERRIDE {
return fd_min(check_x_(d, d.br, s->x()),
check_x_(d, d.br, s->x()-layout->widget_gap_x));
return std::min(check_x_(d, d.br, s->x()),
check_x_(d, d.br, s->x()-layout->widget_gap_x));
}
void draw(Fd_Snap_Data &d) FL_OVERRIDE {
if (best_match) draw_left_brace(best_match);
Expand All @@ -1545,8 +1547,8 @@ class Fd_Snap_Siblings_Top : public Fd_Snap_Sibling {
public:
Fd_Snap_Siblings_Top() { type = 2; mask = FD_TOP|FD_DRAG; }
int sibling_check(Fd_Snap_Data &d, Fl_Widget *s) FL_OVERRIDE {
return fd_min(check_y_(d, d.by, s->y()+s->h()),
check_y_(d, d.by, s->y()+s->h()+layout->widget_gap_y));
return std::min(check_y_(d, d.by, s->y()+s->h()),
check_y_(d, d.by, s->y()+s->h()+layout->widget_gap_y));
}
void draw(Fd_Snap_Data &d) FL_OVERRIDE {
if (best_match) draw_bottom_brace(best_match);
Expand All @@ -1570,8 +1572,8 @@ class Fd_Snap_Siblings_Bottom : public Fd_Snap_Sibling {
public:
Fd_Snap_Siblings_Bottom() { type = 2; mask = FD_BOTTOM|FD_DRAG; }
int sibling_check(Fd_Snap_Data &d, Fl_Widget *s) FL_OVERRIDE {
return fd_min(check_y_(d, d.bt, s->y()),
check_y_(d, d.bt, s->y()-layout->widget_gap_y));
return std::min(check_y_(d, d.bt, s->y()),
check_y_(d, d.bt, s->y()-layout->widget_gap_y));
}
void draw(Fd_Snap_Data &d) FL_OVERRIDE {
if (best_match) draw_top_brace(best_match);
Expand Down
2 changes: 1 addition & 1 deletion fluid/Fd_Snap_Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Fd_Layout_Suite {
char *name_; ///< name of the suite
char *menu_label; ///< label text used in pulldown menu
Fd_Layout_Preset *layout[3]; ///< presets for application, dialog, and toolbox windows
Fd_Tool_Store storage_; ///< storage location (see FD_STORE_INTERNAL, etc.)
Fd_Tool_Store storage_; ///< storage location (see Fd_Tool_Store::INTERNAL, etc.)
void write(Fl_Preferences &prefs);
void read(Fl_Preferences &prefs);
void write(Fd_Project_Writer*);
Expand Down
16 changes: 8 additions & 8 deletions fluid/Fl_Menu_Type.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,13 @@ void Fl_Menu_Item_Type::write_item(Fd_Code_Writer& f) {
f.write_c(" {");
if (label() && label()[0])
switch (g_project.i18n_type) {
case FD_I18N_GNU:
case Fd_I18n_Type::GNU:
// we will call i18n when the menu is instantiated for the first time
f.write_c("%s(", g_project.i18n_gnu_static_function.c_str());
f.write_cstring(label());
f.write_c(")");
break;
case FD_I18N_POSIX:
case Fd_I18n_Type::POSIX:
// fall through: strings can't be translated before a catalog is chosen
default:
f.write_cstring(label());
Expand Down Expand Up @@ -588,12 +588,12 @@ void Fl_Menu_Item_Type::write_code1(Fd_Code_Writer& f) {
f.write_c("%sml->labela = (char*)", f.indent());
image->write_inline(f);
f.write_c(";\n");
if (g_project.i18n_type==FD_I18N_NONE) {
if (g_project.i18n_type==Fd_I18n_Type::NONE) {
f.write_c("%sml->labelb = o->label();\n", f.indent());
} else if (g_project.i18n_type==FD_I18N_GNU) {
} else if (g_project.i18n_type==Fd_I18n_Type::GNU) {
f.write_c("%sml->labelb = %s(o->label());\n",
f.indent(), g_project.i18n_gnu_function.c_str());
} else if (g_project.i18n_type==FD_I18N_POSIX) {
} else if (g_project.i18n_type==Fd_I18n_Type::POSIX) {
f.write_c("%sml->labelb = catgets(%s,%s,i+%d,o->label());\n",
f.indent(),
g_project.i18n_pos_file.empty() ? "_catalog" : g_project.i18n_pos_file.c_str(),
Expand All @@ -606,17 +606,17 @@ void Fl_Menu_Item_Type::write_code1(Fd_Code_Writer& f) {
image->write_code(f, 0, "o");
}
}
if (g_project.i18n_type && label() && label()[0]) {
if ( (g_project.i18n_type!=Fd_I18n_Type::NONE) && label() && label()[0]) {
Fl_Labeltype t = o->labeltype();
if (image) {
// label was already copied a few lines up
} else if ( t==FL_NORMAL_LABEL || t==FL_SHADOW_LABEL
|| t==FL_ENGRAVED_LABEL || t==FL_EMBOSSED_LABEL) {
start_menu_initialiser(f, menuItemInitialized, mname, i);
if (g_project.i18n_type==FD_I18N_GNU) {
if (g_project.i18n_type==Fd_I18n_Type::GNU) {
f.write_c("%so->label(%s(o->label()));\n",
f.indent(), g_project.i18n_gnu_function.c_str());
} else if (g_project.i18n_type==FD_I18N_POSIX) {
} else if (g_project.i18n_type==Fd_I18n_Type::POSIX) {
f.write_c("%so->label(catgets(%s,%s,i+%d,o->label()));\n",
f.indent(),
g_project.i18n_pos_file.empty() ? "_catalog" : g_project.i18n_pos_file.c_str(),
Expand Down
4 changes: 2 additions & 2 deletions fluid/Fl_Type.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,13 @@ void delete_all(int selected_only) {
if(!selected_only) {
// reset the setting for the external shell command
if (g_shell_config) {
g_shell_config->clear(FD_STORE_PROJECT);
g_shell_config->clear(Fd_Tool_Store::PROJECT);
g_shell_config->rebuild_shell_menu();
g_shell_config->update_settings_dialog();
}
widget_browser->hposition(0);
widget_browser->vposition(0);
g_layout_list.remove_all(FD_STORE_PROJECT);
g_layout_list.remove_all(Fd_Tool_Store::PROJECT);
g_layout_list.current_suite(0);
g_layout_list.current_preset(0);
g_layout_list.update_dialogs();
Expand Down
12 changes: 6 additions & 6 deletions fluid/Fl_Widget_Type.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3096,15 +3096,15 @@ void Fl_Widget_Type::write_code1(Fd_Code_Writer& f) {
if (label() && *label()) {
f.write_c(", ");
switch (g_project.i18n_type) {
case FD_I18N_NONE : /* None */
case Fd_I18n_Type::NONE : /* None */
f.write_cstring(label());
break;
case FD_I18N_GNU : /* GNU gettext */
case Fd_I18n_Type::GNU : /* GNU gettext */
f.write_c("%s(", g_project.i18n_gnu_function.c_str());
f.write_cstring(label());
f.write_c(")");
break;
case FD_I18N_POSIX : /* POSIX catgets */
case Fd_I18n_Type::POSIX : /* POSIX catgets */
f.write_c("catgets(%s,%s,%d,",
g_project.i18n_pos_file.empty() ? "_catalog" : g_project.i18n_pos_file.c_str(),
g_project.i18n_pos_set.c_str(), msgnum());
Expand Down Expand Up @@ -3170,15 +3170,15 @@ void Fl_Widget_Type::write_widget_code(Fd_Code_Writer& f) {
if (tooltip() && *tooltip()) {
f.write_c("%s%s->tooltip(",f.indent(), var);
switch (g_project.i18n_type) {
case FD_I18N_NONE : /* None */
case Fd_I18n_Type::NONE : /* None */
f.write_cstring(tooltip());
break;
case FD_I18N_GNU : /* GNU gettext */
case Fd_I18n_Type::GNU : /* GNU gettext */
f.write_c("%s(", g_project.i18n_gnu_function.c_str());
f.write_cstring(tooltip());
f.write_c(")");
break;
case FD_I18N_POSIX : /* POSIX catgets */
case Fd_I18n_Type::POSIX : /* POSIX catgets */
f.write_c("catgets(%s,%s,%d,",
g_project.i18n_pos_file.empty() ? "_catalog" : g_project.i18n_pos_file.c_str(),
g_project.i18n_pos_set.c_str(),
Expand Down
20 changes: 11 additions & 9 deletions fluid/Fl_Window_Type.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include <stdlib.h>
#include <stdio.h>

#include <algorithm> // min, max

extern Fl_Window *the_panel;
extern void draw_width(int x, int y, int r, Fl_Align a);
extern void draw_height(int x, int y, int b, Fl_Align a);
Expand All @@ -70,22 +72,22 @@ static void update_xywh() {

void i18n_type_cb(Fl_Choice *c, void *v) {
if (v == LOAD) {
c->value(g_project.i18n_type);
c->value(static_cast<int>(g_project.i18n_type));
} else {
undo_checkpoint();
g_project.i18n_type = static_cast<Fd_I18n_Type>(c->value());
set_modflag(1);
}
switch (g_project.i18n_type) {
case FD_I18N_NONE : /* None */
case Fd_I18n_Type::NONE : /* None */
i18n_gnu_group->hide();
i18n_posix_group->hide();
break;
case FD_I18N_GNU : /* GNU gettext */
case Fd_I18n_Type::GNU : /* GNU gettext */
i18n_gnu_group->show();
i18n_posix_group->hide();
break;
case FD_I18N_POSIX : /* POSIX cat */
case Fd_I18n_Type::POSIX : /* POSIX cat */
i18n_gnu_group->hide();
i18n_posix_group->show();
break;
Expand Down Expand Up @@ -333,7 +335,7 @@ void Fl_Window_Type::ideal_size(int &w, int &h) {
Fl_Window *win = main_window;
int screen = Fl::screen_num(win->x(), win->y());
Fl::screen_work_area(sx, sy, sw, sh, screen);
w = fd_min(w, sw*3/4); h = fd_min(h, sh*3/4);
w = std::min(w, sw*3/4); h = std::min(h, sh*3/4);
}
Fd_Snap_Action::better_size(w, h);
}
Expand Down Expand Up @@ -586,10 +588,10 @@ void Fl_Window_Type::draw_overlaps() {
if (p->level==q->level && p->is_true_widget()) {
Fl_Widget_Type *wp = (Fl_Widget_Type*)p;
if (wp->o->visible()) {
int px = fd_max(x, wp->o->x());
int py = fd_max(y, wp->o->y());
int pr = fd_min(r, wp->o->x() + wp->o->w());
int pb = fd_min(b, wp->o->y() + wp->o->h());
int px = std::max(x, wp->o->x());
int py = std::max(y, wp->o->y());
int pr = std::min(r, wp->o->x() + wp->o->w());
int pb = std::min(b, wp->o->y() + wp->o->h());
if (pr > px && pb > py)
fd_hatch(px, py, pr-px, pb-py);
}
Expand Down
Loading

0 comments on commit b063524

Please sign in to comment.