diff options
| author | maxim nikonov <maxim.nikonov@hqo.co> | 2026-02-06 02:33:41 +0500 |
|---|---|---|
| committer | maxim nikonov <maxim.nikonov@hqo.co> | 2026-02-06 02:33:41 +0500 |
| commit | 43e0a37906afabb0b3b091b8d3eac9a910cae50c (patch) | |
| tree | d2a037c2bf0dc395fddb08e32ebfcf2795503b7c | |
| parent | 4ce4967c33d56e4b56d85d11fe0e0be91e159f5d (diff) | |
wip
70 files changed, 2336 insertions, 2410 deletions
| Binary files differ diff --git a/fluid/Fluid.cxx b/fluid/Fluid.cxx index 083d00257..7d838d11a 100644 --- a/fluid/Fluid.cxx +++ b/fluid/Fluid.cxx @@ -40,59 +40,55 @@ #include "widgets/Node_Browser.h" #include <FL/Fl.H> +#include <FL/Fl_Double_Window.H> #include <FL/fl_ask.H> -#ifdef __APPLE__ -#include <FL/platform.H> // for fl_open_callback -#endif #include <FL/Fl_Help_Dialog.H> #include <FL/Fl_PNG_Image.H> #include <FL/Fl_Native_File_Chooser.H> #include <FL/Fl_Printer.H> +#include <FL/Fl_File_Icon.H> #include <FL/fl_string_functions.h> -#include <locale.h> // setlocale().. +#include <locale.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> #include "../src/flstring.h" +#ifdef __APPLE__ +#include <FL/platform.H> +#endif + +#ifndef _WIN32 +#include <unistd.h> +#endif -fld::Application Fluid; -using namespace fld; +fld::Application Fluid; /** Timer to watch for external editor modifications. - - If one or more external editors open, check if their files were modified. - If so: reload to ram, update size/mtime records, and change fluid's - 'modified' state. */ static void external_editor_timer(void*) { int editors_open = ExternalCodeEditor::editors_open(); - if ( Fluid.debug_external_editor ) printf("--- TIMER --- External editors open=%d\n", editors_open); - if ( editors_open > 0 ) { - // Walk tree looking for files modified by external editors. + if (Fluid.debug_external_editor) printf("--- TIMER --- External editors open=%d\n", editors_open); + if (editors_open > 0) { int modified = 0; for (Node *p: Fluid.proj.tree.all_nodes()) { - if ( p->is_a(FLD_NODE_TYPE_Code) ) { + if (p->is_a(FLD_NODE_TYPE_Code)) { Code_Node *code = static_cast<Code_Node*>(p); - // Code changed by external editor? - if ( code->handle_editor_changes() ) { // updates ram, file size/mtime + if (code->handle_editor_changes()) { modified++; } - if ( code->is_editing() ) { // editor open? - code->reap_editor(); // Try to reap; maybe it recently closed + if (code->is_editing()) { + code->reap_editor(); } } } - if ( modified ) Fluid.proj.set_modflag(1); + if (modified) Fluid.proj.set_modflag(1); } - // Repeat timeout if editors still open - // The ExternalCodeEditor class handles start/stopping timer, we just - // repeat_timeout() if it's already on. NOTE: above code may have reaped - // only open editor, which would disable further timeouts. So *recheck* - // if editors still open, to ensure we don't accidentally re-enable them. - // - if ( ExternalCodeEditor::editors_open() ) { + if (ExternalCodeEditor::editors_open()) { Fl::repeat_timeout(2.0, external_editor_timer); } } @@ -100,36 +96,58 @@ static void external_editor_timer(void*) { /** Create the Fluid application. - This creates the basic app with an empty project and reads the Fluid - preferences database. */ -Application::Application() -: preferences( Fl_Preferences::USER_L, "fltk.org", "fluid" ) -{ } +fld::Application::Application() +: current_project_(new fld::Project()), + tmpdir_create_called(0), + preferences(Fl_Preferences::USER_L, "fltk.org", "fluid"), + layout_list(0), + batch_mode(0), + show_guides(1), + show_restricted(1), + show_ghosted_outline(1), + show_comments(1), + use_external_editor(0), + debug_external_editor(0), + main_window(0), + main_menubar(0), + save_item(0), + history_item(0), + widgetbin_item(0), + codeview_item(0), + overlay_item(0), + overlay_button(0), + guides_item(0), + restricted_item(0), + pasteoffset(0), + ipasteoffset(0), + help_dialog(0), + proj(*current_project_) +{ + launch_path_[0] = '\0'; + tmpdir_path_[0] = '\0'; + external_editor_command[0] = '\0'; +} /** - Start Fluid. - - Fluid can run in interactive mode with a full user interface to design new - user interfaces and write the C++ files to manage them, + Destructor. + */ +fld::Application::~Application() { + delete current_project_; +} - Fluid can run form the command line in batch mode to convert .fl design files - into C++ source and header files. In batch mode, no display is needed, - particularly no X11 connection will be attempted on Linux/Unix. - \param[in] argc number of arguments in the list - \param[in] argv pointer to an array of arguments - \return in batch mode, an error code will be returned via \c exit() . This - function return 1, if there was an error in the parameters list. - \todo On Windows, Fluid can under certain conditions open a dialog box, even - in batch mode. Is that intentional? Does it circumvent issues with Windows' - stderr and stdout? +/** + Start Fluid. */ -int Application::run(int argc,char **argv) { - setlocale(LC_ALL, ""); // enable multi-language errors in file chooser - setlocale(LC_NUMERIC, "C"); // make sure numeric values are written correctly - launch_path_ = end_with_slash(fl_getcwd_str()); // store the current path at launch +int fld::Application::run(int argc, char **argv) { + setlocale(LC_ALL, ""); + setlocale(LC_NUMERIC, "C"); + + // store the current path at launch + fl_getcwd(launch_path_, FL_PATH_MAX); + fld_end_with_slash(launch_path_, FL_PATH_MAX, launch_path_); int i = 1; if ((i = args.load(argc, argv)) == -1) @@ -140,8 +158,8 @@ int Application::run(int argc,char **argv) { ::exit(0); } - const char *c = nullptr; - if (args.autodoc_path.empty()) + const char *c = 0; + if (args.autodoc_path[0] == '\0') c = argv[i]; fl_register_images(); @@ -152,81 +170,76 @@ int Application::run(int argc,char **argv) { if (batch_mode) { proj.set_filename(c); } else { - // In GUI mode, filenames must always be absolute. - proj.set_filename(fl_filename_absolute_str(c)); + char abs_path[FL_PATH_MAX]; + fl_filename_absolute(abs_path, FL_PATH_MAX, c); + proj.set_filename(abs_path); } } if (!batch_mode) { #ifdef __APPLE__ fl_open_callback(apple_open_cb); -#endif // __APPLE__ +#endif Fl::visual((Fl_Mode)(FL_DOUBLE|FL_INDEX)); Fl_File_Icon::load_system_icons(); main_window->callback(exit_cb); - position_window(main_window,"main_window_pos", 1, 10, 30, FLD_WINWIDTH, FLD_WINHEIGHT ); + position_window(main_window, "main_window_pos", 1, 10, 30, FLD_WINWIDTH, FLD_WINHEIGHT); if (g_shell_config) { g_shell_config->read(preferences, FLD_TOOL_STORE_USER); g_shell_config->update_settings_dialog(); g_shell_config->rebuild_shell_menu(); } - Fluid.layout_list.read(preferences, FLD_TOOL_STORE_USER); - main_window->show(argc,argv); + layout_list->read(preferences, FLD_TOOL_STORE_USER); + main_window->show(argc, argv); toggle_widget_bin(); - toggle_codeview_cb(nullptr,nullptr); - if (!c && openlast_button->value() && history.abspath[0][0] && args.autodoc_path.empty()) { - // Open previous file when no file specified... + toggle_codeview_cb(0, 0); + if (!c && openlast_button->value() && history.abspath[0][0] && args.autodoc_path[0] == '\0') { open_project_file(history.abspath[0]); } } proj.undo.suspend(); - if (c && !fld::io::read_file(proj, c,0)) { + if (c && !fld::io::read_file(proj, c, 0)) { if (batch_mode) { - fprintf(stderr,"%s : %s\n", c, strerror(errno)); + fprintf(stderr, "%s : %s\n", c, strerror(errno)); exit(1); } fl_message("Can't read %s: %s", c, strerror(errno)); } proj.undo.resume(); - // command line args override code and header filenames from the project file - // in batch mode only if (batch_mode) { - if (!args.code_filename.empty()) { + if (args.code_filename[0]) { proj.code_file_set = 1; - proj.code_file_name = args.code_filename; + proj.set_code_file_name(args.code_filename); } - if (!args.header_filename.empty()) { + if (args.header_filename[0]) { proj.header_file_set = 1; - proj.header_file_name = args.header_filename; + proj.set_header_file_name(args.header_filename); } } - if (args.update_file) { // fluid -u + if (args.update_file) { fld::io::write_file(proj, c, 0); if (!args.compile_file) exit(0); } - if (args.compile_file) { // fluid -c[s] + if (args.compile_file) { if (args.compile_strings) proj.write_strings(); - write_code_files(); + write_code_files(0); exit(0); } - // don't lock up if inconsistent command line arguments were given if (batch_mode) exit(0); proj.set_modflag(0); proj.undo.clear(); - // Set (but do not start) timer callback for external editor updates ExternalCodeEditor::set_update_timer_callback(external_editor_timer); #ifndef NDEBUG - // check if the user wants FLUID to generate image for the user documentation - if (!args.autodoc_path.empty()) { + if (args.autodoc_path[0]) { run_autodoc(args.autodoc_path); proj.set_modflag(0, 0); quit(); @@ -243,33 +256,26 @@ int Application::run(int argc,char **argv) { /** - Exit Fluid; we hope you had a nice experience. - If the design was modified, a dialog will ask for confirmation. + Exit Fluid. */ -void Application::quit() { +void fld::Application::quit() { if (shell_command_running()) { int choice = fl_choice("Previous shell command still running!", - "Cancel", - "Exit", - nullptr); - if (choice == 0) { // user chose to cancel the exit operation - return; - } + "Cancel", "Exit", 0); + if (choice == 0) return; } flush_text_widgets(); - // verify user intention - if (confirm_project_clear() == false) + if (confirm_project_clear() == 0) return; - // Stop any external editor update timers ExternalCodeEditor::stop_update_timer(); - save_position(main_window,"main_window_pos"); + save_position(main_window, "main_window_pos"); if (widgetbin_panel) { - save_position(widgetbin_panel,"widgetbin_pos"); + save_position(widgetbin_panel, "widgetbin_pos"); delete widgetbin_panel; } if (codeview_panel) { @@ -278,12 +284,12 @@ void Application::quit() { svp.set("autoposition", cv_autoposition->value()); svp.set("tab", cv_tab->find(cv_tab->value())); svp.set("code_choice", cv_code_choice); - save_position(codeview_panel,"codeview_pos"); + save_position(codeview_panel, "codeview_pos"); delete codeview_panel; - codeview_panel = nullptr; + codeview_panel = 0; } if (shell_run_window) { - save_position(shell_run_window,"shell_run_Window_pos"); + save_position(shell_run_window, "shell_run_Window_pos"); } if (about_panel) @@ -293,13 +299,10 @@ void Application::quit() { if (g_shell_config) g_shell_config->write(preferences, FLD_TOOL_STORE_USER); - Fluid.layout_list.write(preferences, FLD_TOOL_STORE_USER); + layout_list->write(preferences, FLD_TOOL_STORE_USER); proj.undo.clear(); - // Destroy tree - // Doing so causes dtors to automatically close all external editors - // and cleans up editor tmp files. Then remove fluid tmpdir /last/. proj.reset(); ExternalCodeEditor::tmpdir_clear(); delete_tmpdir(); @@ -310,35 +313,27 @@ void Application::quit() { /** Return the working directory path at application launch. - \return a reference to the '/' terminated path. */ -const std::string &Application::launch_path() const { +const char *fld::Application::launch_path() const { return launch_path_; } /** Generate a path to a directory for temporary data storage. - \see delete_tmpdir(), get_tmpdir() - \todo remove duplicate API or reuse ExternalCodeEditor::create_tmpdir()! */ -void Application::create_tmpdir() { +void fld::Application::create_tmpdir() { if (tmpdir_create_called) return; - tmpdir_create_called = true; + tmpdir_create_called = 1; char buf[128]; + char path[FL_PATH_MAX]; + #ifdef _WIN32 - // The usual temp file locations on Windows are - // %system%\Windows\Temp - // %userprofiles%\AppData\Local - // usually resolving into - // C:/Windows/Temp/ - // C:\Users\<username>\AppData\Local\Temp - fl_snprintf(buf, sizeof(buf)-1, "fluid-%d/", (long)GetCurrentProcessId()); - std::string name = buf; - wchar_t tempdirW[FL_PATH_MAX+1]; - char tempdir[FL_PATH_MAX+1]; + fl_snprintf(buf, sizeof(buf) - 1, "fluid-%ld/", (long)GetCurrentProcessId()); + wchar_t tempdirW[FL_PATH_MAX + 1]; + char tempdir[FL_PATH_MAX + 1]; unsigned len = GetTempPathW(FL_PATH_MAX, tempdirW); if (len == 0) { strcpy(tempdir, "c:/windows/temp/"); @@ -346,38 +341,34 @@ void Application::create_tmpdir() { unsigned wn = fl_utf8fromwc(tempdir, FL_PATH_MAX, tempdirW, len); tempdir[wn] = 0; } - std::string path = tempdir; - end_with_slash(path); - path += name; - fl_make_path(path.c_str()); - if (fl_access(path.c_str(), 6) == 0) tmpdir_path = path; + fld_end_with_slash(path, FL_PATH_MAX, tempdir); + strlcat(path, buf, FL_PATH_MAX); + fl_make_path(path); + if (fl_access(path, 6) == 0) strlcpy(tmpdir_path_, path, FL_PATH_MAX); #else - fl_snprintf(buf, sizeof(buf)-1, "fluid-%d/", getpid()); - std::string name = buf; - auto path_temp = fl_getenv("TMPDIR"); - std::string path = path_temp ? path_temp : ""; - if (!path.empty()) { - end_with_slash(path); - path += name; - fl_make_path(path.c_str()); - if (fl_access(path.c_str(), 6) == 0) tmpdir_path = path; + fl_snprintf(buf, sizeof(buf) - 1, "fluid-%d/", getpid()); + const char *path_temp = fl_getenv("TMPDIR"); + if (path_temp && *path_temp) { + fld_end_with_slash(path, FL_PATH_MAX, path_temp); + strlcat(path, buf, FL_PATH_MAX); + fl_make_path(path); + if (fl_access(path, 6) == 0) strlcpy(tmpdir_path_, path, FL_PATH_MAX); } - if (tmpdir_path.empty()) { - path = std::string("/tmp/") + name; - fl_make_path(path.c_str()); - if (fl_access(path.c_str(), 6) == 0) tmpdir_path = path; + if (tmpdir_path_[0] == '\0') { + snprintf(path, FL_PATH_MAX, "/tmp/%s", buf); + fl_make_path(path); + if (fl_access(path, 6) == 0) strlcpy(tmpdir_path_, path, FL_PATH_MAX); } #endif - if (tmpdir_path.empty()) { - char pbuf[FL_PATH_MAX+1]; + if (tmpdir_path_[0] == '\0') { + char pbuf[FL_PATH_MAX + 1]; preferences.get_userdata_path(pbuf, FL_PATH_MAX); - path = std::string(pbuf); - end_with_slash(path); - path += name; - fl_make_path(path.c_str()); - if (fl_access(path.c_str(), 6) == 0) tmpdir_path = path; + fld_end_with_slash(path, FL_PATH_MAX, pbuf); + strlcat(path, buf, FL_PATH_MAX); + fl_make_path(path); + if (fl_access(path, 6) == 0) strlcpy(tmpdir_path_, path, FL_PATH_MAX); } - if (tmpdir_path.empty()) { + if (tmpdir_path_[0] == '\0') { if (batch_mode) { fprintf(stderr, "ERROR: Can't create directory for temporary data storage.\n"); } else { @@ -389,32 +380,30 @@ void Application::create_tmpdir() { /** Delete the temporary directory and all its contents. - \see create_tmpdir(), get_tmpdir() */ -void Application::delete_tmpdir() { - // was a temporary directory created +void fld::Application::delete_tmpdir() { if (!tmpdir_create_called) return; - if (tmpdir_path.empty()) + if (tmpdir_path_[0] == '\0') return; - // first delete all files that may still be left in the temp directory struct dirent **de; - int n_de = fl_filename_list(tmpdir_path.c_str(), &de); + int n_de = fl_filename_list(tmpdir_path_, &de); if (n_de >= 0) { - for (int i=0; i<n_de; i++) { - std::string path = tmpdir_path + de[i]->d_name; - fl_unlink(path.c_str()); + int i; + for (i = 0; i < n_de; i++) { + char filepath[FL_PATH_MAX]; + snprintf(filepath, FL_PATH_MAX, "%s%s", tmpdir_path_, de[i]->d_name); + fl_unlink(filepath); } fl_filename_free_list(&de, n_de); } - // then delete the directory itself - if (fl_rmdir(tmpdir_path.c_str()) < 0) { + if (fl_rmdir(tmpdir_path_) < 0) { if (batch_mode) { - fprintf(stderr, "WARNING: Can't delete tmpdir '%s': %s", tmpdir_path.c_str(), strerror(errno)); + fprintf(stderr, "WARNING: Can't delete tmpdir '%s': %s", tmpdir_path_, strerror(errno)); } else { - fl_alert("WARNING: Can't delete tmpdir '%s': %s", tmpdir_path.c_str(), strerror(errno)); + fl_alert("WARNING: Can't delete tmpdir '%s': %s", tmpdir_path_, strerror(errno)); } } } @@ -422,23 +411,18 @@ void Application::delete_tmpdir() { /** Return the path to a temporary directory for this instance of Fluid. - Fluid will do its best to clear and delete this directory when exiting. - \return the path to the temporary directory, ending in a '/', or and empty - string if no directory could be created. */ -const std::string &Application::get_tmpdir() { +const char *fld::Application::get_tmpdir() { if (!tmpdir_create_called) create_tmpdir(); - return tmpdir_path; + return tmpdir_path_; } /** Return the path and filename of a temporary file for cut or duplicated data. - \param[in] which 0 gets the cut/copy/paste buffer, 1 gets the duplication buffer - \return a pointer to a string in a static buffer */ -const char *Application::cutfname(int which) { +const char *fld::Application::cutfname(int which) { static char name[2][FL_PATH_MAX]; static char beenhere = 0; @@ -456,90 +440,69 @@ const char *Application::cutfname(int which) { /** Clear the current project and create a new, empty one. - - If the current project was modified, FLUID will give the user the opportunity - to save the old project first. - - \param[in] user_must_confirm if set, a confimation dialog is presented to the - user before resetting the project. Default is `true`. - \return false if the operation was canceled */ -bool Application::new_project(bool user_must_confirm) { - // verify user intention - if ((user_must_confirm) && (confirm_project_clear() == false)) - return false; +int fld::Application::new_project(int user_must_confirm) { + if ((user_must_confirm) && (confirm_project_clear() == 0)) + return 0; - // clear the current project proj.reset(); - proj.set_filename(nullptr); + proj.clear_filename(); proj.set_modflag(0, 0); widget_browser->rebuild(); proj.update_settings_dialog(); - // all is clear to continue - return true; + return 1; } /** - Open a file chooser and load an exiting project file. - - If the current project was modified, FLUID will give the user the opportunity - to save the old project first. + Open a file chooser and load an existing project file. + */ +int fld::Application::open_project_file(const char *filename_arg) { + if (confirm_project_clear() == 0) + return 0; - If no filename is given, FLUID will open a file chooser dialog. + char new_filename[FL_PATH_MAX]; + new_filename[0] = '\0'; - \param[in] filename_arg load from this file, or show file chooser if empty - \return false if the operation was canceled or failed otherwise - */ -bool Application::open_project_file(const std::string &filename_arg) { - // verify user intention - if (confirm_project_clear() == false) - return false; - - // ask for a filename if none was given - std::string new_filename = filename_arg; - if (new_filename.empty()) { - new_filename = open_project_filechooser("Open Project File"); - if (new_filename.empty()) { - return false; + if (!filename_arg || !*filename_arg) { + open_project_filechooser(new_filename, FL_PATH_MAX, "Open Project File"); + if (new_filename[0] == '\0') { + return 0; } + } else { + strlcpy(new_filename, filename_arg, FL_PATH_MAX); } - // clear the project and merge a file by the given name - new_project(false); - bool success = merge_project_file(new_filename); + new_project(0); + int success = merge_project_file(new_filename); if (success) mergeback_on_load(); return success; } /** - Load a project from the give file name and path. - - The project file is inserted at the currently selected type. + Load a project from the given file name and path. + */ +int fld::Application::merge_project_file(const char *filename_arg) { + int is_a_merge = (!proj.tree.empty()); + const char *title = is_a_merge ? "Merge Project File" : "Open Project File"; - If no filename is given, FLUID will open a file chooser dialog. + char new_filename[FL_PATH_MAX]; + new_filename[0] = '\0'; - \param[in] filename_arg path and name of the new project file - \return false if the operation failed - */ -bool Application::merge_project_file(const std::string &filename_arg) { - bool is_a_merge = (!proj.tree.empty()); - std::string title = is_a_merge ? "Merge Project File" : "Open Project File"; - - // ask for a filename if none was given - std::string new_filename = filename_arg; - if (new_filename.empty()) { - new_filename = open_project_filechooser(title); - if (new_filename.empty()) { - return false; + if (!filename_arg || !*filename_arg) { + open_project_filechooser(new_filename, FL_PATH_MAX, title); + if (new_filename[0] == '\0') { + return 0; } + } else { + strlcpy(new_filename, filename_arg, FL_PATH_MAX); } - const char *c = new_filename.c_str(); + const char *c = new_filename; const char *oldfilename = proj.proj_filename; - proj.proj_filename = nullptr; + proj.proj_filename = 0; proj.set_filename(c); if (is_a_merge) proj.undo.checkpoint(); proj.undo.suspend(); @@ -551,32 +514,26 @@ bool Application::merge_project_file(const std::string &filename_arg) { free((void *)proj.proj_filename); proj.proj_filename = oldfilename; if (main_window) proj.set_modflag(proj.modflag); - return false; + return 0; } proj.undo.resume(); widget_browser->rebuild(); if (is_a_merge) { - // Inserting a file; restore the original filename... proj.set_filename(oldfilename); proj.set_modflag(1); } else { - // Loaded a file; free the old filename... proj.set_modflag(0, 0); proj.undo.clear(); } if (oldfilename) free((void *)oldfilename); - return true; + return 1; } /** - Save the current design to the file given by \c filename. - If automatic, this overwrites an existing file. If interactive, if will - verify with the user. - \param[in] v if v is not nullptr, or no filename is set, open a filechooser. - if (v is (void*)2, don;t update the project filename ("save copy...") + Save the current design to the file given by filename. */ -void Application::save_project_file(void *v) { +void fld::Application::save_project_file(void *v) { flush_text_widgets(); Fl_Native_File_Chooser fnfc; const char *c = proj.proj_filename; @@ -586,25 +543,25 @@ void Application::save_project_file(void *v) { #ifndef __APPLE__ fnfc.options(Fl_Native_File_Chooser::NEW_FOLDER); #else - // Apple file choosers always ask to confirm - fnfc.options(Fl_Native_File_Chooser::NEW_FOLDER|Fl_Native_File_Chooser::SAVEAS_CONFIRM); + fnfc.options(Fl_Native_File_Chooser::NEW_FOLDER | Fl_Native_File_Chooser::SAVEAS_CONFIRM); #endif fnfc.filter("FLUID Files\t*.f[ld]"); if (proj.proj_filename) { - if (!proj.projectfile_path().empty()) - fnfc.directory(proj.projectfile_path().c_str()); - if (!proj.projectfile_name().empty()) - fnfc.preset_file(proj.projectfile_name().c_str()); + char proj_path[FL_PATH_MAX]; + proj.projectfile_path(proj_path, FL_PATH_MAX); + if (proj_path[0]) fnfc.directory(proj_path); + const char *proj_name = proj.projectfile_name(); + if (proj_name) fnfc.preset_file(proj_name); } fnfc.filter("Fluid Project\t*.fl\nAny\t*"); if (fnfc.show() != 0) return; c = fnfc.filename(); #ifndef __APPLE__ if (!fl_access(c, 0)) { - std::string basename = fl_filename_name_str(std::string(c)); + const char *basename = fl_filename_name(c); if (fl_choice("The file \"%s\" already exists.\n" "Do you want to replace it?", "Cancel", - "Replace", nullptr, basename.c_str()) == 0) return; + "Replace", 0, basename) == 0) return; } #endif if (v != (void *)2) proj.set_filename(c); @@ -622,13 +579,12 @@ void Application::save_project_file(void *v) { /** - Reload the file set by \c filename, replacing the current design. - If the design was modified, a dialog will ask for confirmation. + Reload the file set by filename, replacing the current design. */ -void Application::revert_project() { - if ( proj.modflag) { +void fld::Application::revert_project() { + if (proj.modflag) { if (!fl_choice("This user interface has been changed. Really revert?", - "Cancel", "Revert", nullptr)) return; + "Cancel", "Revert", 0)) return; } proj.undo.suspend(); if (!fld::io::read_file(proj, proj.proj_filename, 0)) { @@ -648,18 +604,11 @@ void Application::revert_project() { /** Open the template browser and load a new file from templates. - - If the current project was modified, FLUID will give the user the opportunity - to save the old project first. - - \return false if the operation was canceled or failed otherwise */ -bool Application::new_project_from_template() { - // clear the current project first - if (new_project() == false) - return false; +int fld::Application::new_project_from_template() { + if (new_project(1) == 0) + return 0; - // Setup the template panel... if (!template_panel) make_template_panel(); template_clear(); @@ -680,55 +629,46 @@ bool Application::new_project_from_template() { template_panel->label("New"); - //if ( template_browser->size() == 1 ) { // only one item? - template_browser->value(1); // select it + template_browser->value(1); template_browser->do_callback(); - //} - // Show the panel and wait for the user to do something... template_panel->show(); while (template_panel->shown()) Fl::wait(); - // See if the user chose anything... int item = template_browser->value(); - if (item < 1) return false; + if (item < 1) return 0; - // Load the template, if any... const char *tname = (const char *)template_browser->data(item); if (tname) { - // Grab the instance name... const char *iname = template_instance->value(); if (iname && *iname) { - // Copy the template to a temp file, then read it in... char line[1024], *ptr, *next; FILE *infile, *outfile; - if ((infile = fl_fopen(tname, "rb")) == nullptr) { + if ((infile = fl_fopen(tname, "rb")) == 0) { fl_alert("Error reading template file \"%s\":\n%s", tname, strerror(errno)); proj.set_modflag(0); proj.undo.clear(); - return false; + return 0; } - if ((outfile = fl_fopen(cutfname(1), "wb")) == nullptr) { + if ((outfile = fl_fopen(cutfname(1), "wb")) == 0) { fl_alert("Error writing buffer file \"%s\":\n%s", cutfname(1), strerror(errno)); fclose(infile); proj.set_modflag(0); proj.undo.clear(); - return false; + return 0; } while (fgets(line, sizeof(line), infile)) { - // Replace @INSTANCE@ with the instance name... - for (ptr = line; (next = strstr(ptr, "@INSTANCE@")) != nullptr; ptr = next + 10) { + for (ptr = line; (next = strstr(ptr, "@INSTANCE@")) != 0; ptr = next + 10) { fwrite(ptr, next - ptr, 1, outfile); fputs(iname, outfile); } - fputs(ptr, outfile); } @@ -740,7 +680,6 @@ bool Application::new_project_from_template() { fl_unlink(cutfname(1)); proj.undo.resume(); } else { - // No instance name, so read the template without replacements... proj.undo.suspend(); fld::io::read_file(proj, tname, 0); proj.undo.resume(); @@ -752,69 +691,66 @@ bool Application::new_project_from_template() { proj.set_modflag(0); proj.undo.clear(); - return true; + return 1; } /** Open the dialog to allow the user to print the current window. */ -void Application::print_snapshots() { +void fld::Application::print_snapshots() { int w, h, ww, hh; int frompage, topage; - int num_windows = 0; // Number of windows - Window_Node *windows[1000]; // Windows to print - int winpage; // Current window page + int num_windows = 0; + Window_Node *windows[1000]; + int winpage; Fl_Window *win; - for (auto w: proj.tree.all_widgets()) { - if (w->is_a(FLD_NODE_TYPE_Window)) { - Window_Node *win_t = static_cast<Window_Node*>(w); + for (Node *wn: proj.tree.all_nodes()) { + if (wn->is_a(FLD_NODE_TYPE_Window)) { + Window_Node *win_t = static_cast<Window_Node*>(wn); + Fl_Window *win_w = static_cast<Fl_Window*>(win_t->o); + if (!win_w->shown()) continue; windows[num_windows] = win_t; - Fl_Window *win = static_cast<Fl_Window*>(win_t->o); - if (!win->shown()) continue; - num_windows ++; + num_windows++; } } Fl_Printer printjob; - if ( printjob.start_job(num_windows, &frompage, &topage) ) return; + if (printjob.start_job(num_windows, &frompage, &topage)) return; int pagecount = 0; for (winpage = 0; winpage < num_windows; winpage++) { float scale = 1, scale_x = 1, scale_y = 1; - if (winpage+1 < frompage || winpage+1 > topage) continue; + if (winpage + 1 < frompage || winpage + 1 > topage) continue; printjob.start_page(); printjob.printable_rect(&w, &h); - // Get the time and date... - time_t curtime = time(nullptr); + time_t curtime = time(0); struct tm *curdate = localtime(&curtime); char date[1024]; strftime(date, sizeof(date), "%c", curdate); fl_font(FL_HELVETICA, 12); fl_color(FL_BLACK); - fl_draw(date, (w - (int)fl_width(date))/2, fl_height()); - sprintf(date, "%d/%d", ++pagecount, topage-frompage+1); + fl_draw(date, (w - (int)fl_width(date)) / 2, fl_height()); + sprintf(date, "%d/%d", ++pagecount, topage - frompage + 1); fl_draw(date, w - (int)fl_width(date), fl_height()); - // Get the base filename... - std::string basename = fl_filename_name_str(std::string(proj.proj_filename)); - fl_draw(basename.c_str(), 0, fl_height()); + const char *basename = fl_filename_name(proj.proj_filename); + if (basename) fl_draw(basename, 0, fl_height()); - // print centered and scaled to fit in the page win = (Fl_Window*)windows[winpage]->o; ww = win->decorated_w(); - if(ww > w) scale_x = float(w)/ww; + if (ww > w) scale_x = float(w) / ww; hh = win->decorated_h(); - if(hh > h) scale_y = float(h)/hh; + if (hh > h) scale_y = float(h) / hh; if (scale_x < scale) scale = scale_x; if (scale_y < scale) scale = scale_y; if (scale < 1) { printjob.scale(scale); printjob.printable_rect(&w, &h); } - printjob.origin(w/2, h/2); - printjob.print_window(win, -ww/2, -hh/2); + printjob.origin(w / 2, h / 2); + printjob.print_window(win, -ww / 2, -hh / 2); printjob.end_page(); } printjob.end_job(); @@ -823,66 +759,49 @@ void Application::print_snapshots() { /** Generate the C++ source and header filenames and write those files. - - This function creates the source filename by setting the file - extension to \c code_file_name and a header filename - with the extension \c header_file_name which are both - settable by the user. - - If the code filename has not been set yet, a "save file as" dialog will be - presented to the user. - - In batch_mode, the function will either be silent, or, if opening or writing - the files fails, write an error message to \c stderr and exit with exit code 1. - - In interactive mode, it will pop up an error message, or, if the user - hasn't disabled that, pop up a confirmation message. - - \param[in] dont_show_completion_dialog don't show the completion dialog - \return 1 if the operation failed, 0 if it succeeded */ -int Application::write_code_files(bool dont_show_completion_dialog) -{ - // -- handle user interface issues +int fld::Application::write_code_files(int dont_show_completion_dialog) { flush_text_widgets(); if (!proj.proj_filename) { - save_project_file(nullptr); + save_project_file(0); if (!proj.proj_filename) return 1; } - // -- generate the file names with absolute paths fld::io::Code_Writer f(proj); - std::string code_filename = proj.codefile_path() + proj.codefile_name(); - std::string header_filename = proj.headerfile_path() + proj.headerfile_name(); - // -- write the code and header files + char code_path[FL_PATH_MAX], code_name[FL_PATH_MAX]; + char header_path[FL_PATH_MAX], header_name[FL_PATH_MAX]; + proj.codefile_path(code_path, FL_PATH_MAX); + proj.codefile_name(code_name, FL_PATH_MAX); + proj.headerfile_path(header_path, FL_PATH_MAX); + proj.headerfile_name(header_name, FL_PATH_MAX); + + char code_filename[FL_PATH_MAX], header_filename[FL_PATH_MAX]; + snprintf(code_filename, FL_PATH_MAX, "%s%s", code_path, code_name); + snprintf(header_filename, FL_PATH_MAX, "%s%s", header_path, header_name); + if (!batch_mode) proj.enter_project_dir(); - int x = f.write_code(code_filename.c_str(), header_filename.c_str()); - std::string code_filename_rel = fl_filename_relative_str(code_filename); - std::string header_filename_rel = fl_filename_relative_str(header_filename); + int x = f.write_code(code_filename, header_filename); + + char code_filename_rel[FL_PATH_MAX], header_filename_rel[FL_PATH_MAX]; + fl_filename_relative(code_filename_rel, FL_PATH_MAX, code_filename); + fl_filename_relative(header_filename_rel, FL_PATH_MAX, header_filename); if (!batch_mode) proj.leave_project_dir(); - // -- print error message in batch mode or pop up an error or confirmation dialog box if (batch_mode) { if (!x) { fprintf(stderr, "%s and %s: %s\n", - code_filename_rel.c_str(), - header_filename_rel.c_str(), - strerror(errno)); + code_filename_rel, header_filename_rel, strerror(errno)); exit(1); } } else { if (!x) { fl_message("Can't write %s or %s: %s", - code_filename_rel.c_str(), - header_filename_rel.c_str(), - strerror(errno)); + code_filename_rel, header_filename_rel, strerror(errno)); } else { proj.set_modflag(-1, 0); - if (dont_show_completion_dialog==false && completion_button->value()) { - fl_message("Wrote %s and %s", - code_filename_rel.c_str(), - header_filename_rel.c_str()); + if (dont_show_completion_dialog == 0 && completion_button->value()) { + fl_message("Wrote %s and %s", code_filename_rel, header_filename_rel); } } } @@ -890,16 +809,13 @@ int Application::write_code_files(bool dont_show_completion_dialog) } -/** - User chose to cut the currently selected widgets. - */ -void Application::cut_selected() { +void fld::Application::cut_selected() { if (!proj.tree.current) { fl_beep(); return; } flush_text_widgets(); - if (!fld::io::write_file(proj, cutfname(),1)) { + if (!fld::io::write_file(proj, cutfname(), 1)) { fl_message("Can't write %s: %s", cutfname(), strerror(errno)); return; } @@ -914,10 +830,7 @@ void Application::cut_selected() { } -/** - User chose to copy the currently selected widgets. - */ -void Application::copy_selected() { +void fld::Application::copy_selected() { flush_text_widgets(); if (!proj.tree.current) { fl_beep(); @@ -925,32 +838,21 @@ void Application::copy_selected() { } flush_text_widgets(); ipasteoffset = 10; - if (!fld::io::write_file(proj, cutfname(),1)) { + if (!fld::io::write_file(proj, cutfname(), 1)) { fl_message("Can't write %s: %s", cutfname(), strerror(errno)); return; } } -/** - User chose to paste the widgets from the cut buffer. - - This function will paste the widgets in the cut buffer after the currently - selected widget. If the currently selected widget is a group widget and - it is not folded, the new widgets will be added inside the group. - */ -void Application::paste_from_clipboard() { +void fld::Application::paste_from_clipboard() { pasteoffset = ipasteoffset; proj.undo.checkpoint(); proj.undo.suspend(); Strategy strategy = Strategy::FROM_FILE_AFTER_CURRENT; if (proj.tree.current && proj.tree.current->can_have_children()) { if (proj.tree.current->folded_ == 0) { - // If the current widget is a group widget and it is not folded, - // add the new widgets inside the group. strategy = Strategy::FROM_FILE_AS_LAST_CHILD; - // The following alternative also works quite nicely - //strategy = Strategy::FROM_FILE_AS_FIRST_CHILD; } } if (!fld::io::read_file(proj, cutfname(), 1, strategy)) { @@ -965,28 +867,19 @@ void Application::paste_from_clipboard() { } -/** - Duplicate the selected widgets. - - This code is a bit complex because it needs to find the last selected - widget with the lowest level, so that the new widgets are inserted after - this one. - */ -void Application::duplicate_selected() { +void fld::Application::duplicate_selected() { if (!proj.tree.current) { fl_beep(); return; } - // flush the text widgets to make sure the user's changes are saved: flush_text_widgets(); - // find the last selected node with the lowest level: int lowest_level = 9999; - Node *new_insert = nullptr; + Node *new_insert = 0; if (proj.tree.current->selected) { - for (auto t: proj.tree.all_selected_nodes()) { - if (t->level <= lowest_level) { + for (Node *t: proj.tree.all_nodes()) { + if (t->selected && t->level <= lowest_level) { lowest_level = t->level; new_insert = t; } @@ -995,14 +888,12 @@ void Application::duplicate_selected() { if (new_insert) proj.tree.current = new_insert; - // write the selected widgets to a file: - if (!fld::io::write_file(proj, cutfname(1),1)) { + if (!fld::io::write_file(proj, cutfname(1), 1)) { fl_message("Can't write %s: %s", cutfname(1), strerror(errno)); return; } - // read the file and add the widgets after the current one: - pasteoffset = 0; + pasteoffset = 0; proj.undo.checkpoint(); proj.undo.suspend(); if (!fld::io::read_file(proj, cutfname(1), 1, Strategy::FROM_FILE_AFTER_CURRENT)) { @@ -1015,10 +906,7 @@ void Application::duplicate_selected() { } -/** - User chose to delete the currently selected widgets. - */ -void Application::delete_selected() { +void fld::Application::delete_selected() { if (!proj.tree.current) { fl_beep(); return; @@ -1034,10 +922,7 @@ void Application::delete_selected() { } -/** - Show the editor for the \c current Node. - */ -void Application::edit_selected() { +void fld::Application::edit_selected() { if (!proj.tree.current) { fl_message("Please select a widget"); return; @@ -1046,25 +931,18 @@ void Application::edit_selected() { } -/** - User wants to sort selected widgets by y coordinate. - */ -void Application::sort_selected() { +void fld::Application::sort_selected() { proj.undo.checkpoint(); - sort((Node*)nullptr); + sort((Node*)0); widget_browser->rebuild(); proj.set_modflag(1); } -/** - Show or hide the widget bin. - The state is stored in the app preferences. - */ -void Application::toggle_widget_bin() { +void fld::Application::toggle_widget_bin() { if (!widgetbin_panel) { make_widgetbin(); - if (!position_window(widgetbin_panel,"widgetbin_pos", 1, 320, 30)) return; + if (!position_window(widgetbin_panel, "widgetbin_pos", 1, 320, 30)) return; } if (widgetbin_panel->visible()) { @@ -1077,34 +955,26 @@ void Application::toggle_widget_bin() { } -/** - Open a dialog to show the HTML help page form the FLTK documentation folder. - \param[in] name name of the HTML help file. - */ -void Application::show_help(const char *name) { - const char *docdir; - char helpname[FL_PATH_MAX]; +void fld::Application::show_help(const char *name) { + const char *docdir; + char helpname[FL_PATH_MAX]; if (!help_dialog) help_dialog = new Fl_Help_Dialog(); - if ((docdir = fl_getenv("FLTK_DOCDIR")) == nullptr) { + if ((docdir = fl_getenv("FLTK_DOCDIR")) == 0) { docdir = FLTK_DOCDIR; } snprintf(helpname, sizeof(helpname), "%s/%s", docdir, name); - // make sure that we can read the file FILE *f = fopen(helpname, "rb"); if (f) { fclose(f); help_dialog->load(helpname); } else { - // if we can not read the file, we display the canned version instead - // or ask the native browser to open the page on www.fltk.org - if (strcmp(name, "fluid.html")==0) { + if (strcmp(name, "fluid.html") == 0) { if (!Fl_Shared_Image::find("embedded:/fluid_flow_chart_800.png")) new Fl_PNG_Image("embedded:/fluid_flow_chart_800.png", fluid_flow_chart_800_png, sizeof(fluid_flow_chart_800_png)); - help_dialog->value - ( + help_dialog->value( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" "<html><head><title>FLTK: Programming with FLUID</title></head><body>\n" "<h2>What is FLUID?</h2>\n" @@ -1129,11 +999,11 @@ void Application::show_help(const char *name) { "<p>More information is available online at <a href=" "\"https://www.fltk.org/doc-1.5/fluid.html\">https://www.fltk.org/</a>" "</body></html>" - ); - } else if (strcmp(name, "license.html")==0) { + ); + } else if (strcmp(name, "license.html") == 0) { fl_open_uri("https://www.fltk.org/doc-1.5/license.html"); return; - } else if (strcmp(name, "index.html")==0) { + } else if (strcmp(name, "index.html") == 0) { fl_open_uri("https://www.fltk.org/doc-1.5/index.html"); return; } else { @@ -1146,25 +1016,13 @@ void Application::show_help(const char *name) { } -/** - Open the "About" dialog. - */ -void Application::about() { -#if 1 +void fld::Application::about() { if (!about_panel) make_about_panel(); about_panel->show(); -#else - for (auto &n: proj.tree.all_nodes()) { - puts(n.name()); - } -#endif } -/** - Build the main app window and create a few other dialogs. - */ -void Application::make_main_window() { +void fld::Application::make_main_window() { if (!batch_mode) { preferences.get("show_guides", show_guides, 1); preferences.get("show_restricted", show_restricted, 1); @@ -1176,15 +1034,14 @@ void Application::make_main_window() { if (!main_window) { Fl_Widget *o; loadPixmaps(); - main_window = new Fl_Double_Window(FLD_WINWIDTH,FLD_WINHEIGHT,"fluid"); + main_window = new Fl_Double_Window(FLD_WINWIDTH, FLD_WINHEIGHT, "fluid"); main_window->box(FL_NO_BOX); - o = make_widget_browser(0,FLD_MENUHEIGHT,FLD_BROWSERWIDTH,FLD_BROWSERHEIGHT); + o = make_widget_browser(0, FLD_MENUHEIGHT, FLD_BROWSERWIDTH, FLD_BROWSERHEIGHT); o->box(FL_FLAT_BOX); o->tooltip("Double-click to view or change an item."); main_window->resizable(o); - main_menubar = new fld::widget::App_Menu_Bar(0,0,FLD_BROWSERWIDTH,FLD_MENUHEIGHT); + main_menubar = new fld::widget::App_Menu_Bar(0, 0, FLD_BROWSERWIDTH, FLD_MENUHEIGHT); main_menubar->menu(main_menu); - // quick access to all dynamic menu items save_item = (Fl_Menu_Item*)main_menubar->find_item(menu_file_save_cb); history_item = (Fl_Menu_Item*)main_menubar->find_item(menu_file_open_history_cb); widgetbin_item = (Fl_Menu_Item*)main_menubar->find_item(toggle_widgetbin_cb); @@ -1206,110 +1063,68 @@ void Application::make_main_window() { } -/** - Open a native file chooser to allow choosing a project file for reading. - - Path and filename are preset with the current project filename, if there - is one. - - \param title a text describing the action after selecting a file (load, merge, ...) - \return the file path and name, or an empty string if the operation was canceled - */ -std::string Application::open_project_filechooser(const std::string &title) { +void fld::Application::open_project_filechooser(char *result, int result_size, const char *title) { + result[0] = '\0'; Fl_Native_File_Chooser dialog; - dialog.title(title.c_str()); + dialog.title(title); dialog.type(Fl_Native_File_Chooser::BROWSE_FILE); dialog.filter("FLUID Files\t*.f[ld]\n"); if (proj.proj_filename) { - std::string current_project_file = proj.proj_filename; - dialog.directory(fl_filename_path_str(current_project_file).c_str()); - dialog.preset_file(fl_filename_name_str(current_project_file).c_str()); + char path[FL_PATH_MAX]; + fl_filename_path(path, FL_PATH_MAX, proj.proj_filename); + dialog.directory(path); + dialog.preset_file(fl_filename_name(proj.proj_filename)); } if (dialog.show() != 0) - return std::string(); - return std::string(dialog.filename()); + return; + strlcpy(result, dialog.filename(), result_size); } -/** - Give the user the opportunity to save a project before clearing it. - - If the project has unsaved changes, this function pops up a dialog, that - allows the user to save the project, continue without saving the project, - or to cancel the operation. - - If the user chooses to save, and no filename was set, a file dialog allows - the user to pick a name and location, or to cancel the operation. - - \return false if the user aborted the operation and the calling function - should abort as well - */ -bool Application::confirm_project_clear() { - if (proj.modflag == 0) return true; +int fld::Application::confirm_project_clear() { + if (proj.modflag == 0) return 1; switch (fl_choice("This project has unsaved changes. Do you want to save\n" "the project file before proceeding?", "Cancel", "Save", "Don't Save")) { - case 0 : /* Cancel */ - return false; - case 1 : /* Save */ - save_project_file(nullptr); - if (proj.modflag) return false; // user canceled the "Save As" dialog + case 0: + return 0; + case 1: + save_project_file(0); + if (proj.modflag) return 0; } - return true; + return 1; } -/** - Ensure that text widgets in the widget panel propagates apply current changes. - By temporarily clearing the text focus, all text widgets with changed text - will unfocus and call their respective callbacks, propagating those changes to - their data set. - */ -void Application::flush_text_widgets() { +void fld::Application::flush_text_widgets() { if (Fl::focus() && (Fl::focus()->top_window() == the_panel)) { Fl_Widget *old_focus = Fl::focus(); - Fl::focus(nullptr); // trigger callback of the widget that is losing focus + Fl::focus(0); Fl::focus(old_focus); } } -/** - Position the given window window based on entries in the app preferences. - Customisable by user; feature can be switched off. - The window is not shown or hidden by this function, but a value is returned - to indicate the state to the caller. - \param[in] w position this window - \param[in] prefsName name of the preferences item that stores the window settings - \param[in] Visible default value if window is hidden or shown - \param[in] X, Y, W, H default size and position if nothing is specified in the preferences - \return 1 if the caller should make the window visible, 0 if hidden. - */ -char Application::position_window(Fl_Window *w, const char *prefsName, int Visible, int X, int Y, int W, int H) { +char fld::Application::position_window(Fl_Window *w, const char *prefsName, int Visible, int X, int Y, int W, int H) { Fl_Preferences pos(preferences, prefsName); if (prevpos_button->value()) { pos.get("x", X, X); pos.get("y", Y, Y); - if ( W!=0 ) { + if (W != 0) { pos.get("w", W, W); pos.get("h", H, H); - w->resize( X, Y, W, H ); + w->resize(X, Y, W, H); + } else { + w->position(X, Y); } - else - w->position( X, Y ); } pos.get("visible", Visible, Visible); return Visible; } -/** - Save the position and visibility state of a window to the app preferences. - \param[in] w save this window data - \param[in] prefsName name of the preferences item that stores the window settings - */ -void Application::save_position(Fl_Window *w, const char *prefsName) { +void fld::Application::save_position(Fl_Window *w, const char *prefsName) { Fl_Preferences pos(preferences, prefsName); pos.set("x", w->x()); pos.set("y", w->y()); @@ -1319,74 +1134,31 @@ void Application::save_position(Fl_Window *w, const char *prefsName) { } -/** - Change the app's and hence preview the design's scheme. - - The scheme setting is stored in the app preferences - - in key \p 'scheme_name' since 1.4.0 - - in key \p 'scheme' (index: 0 - 4) in 1.3.x - - This callback is triggered by changing the scheme in the - Fl_Scheme_Choice widget (\p Edit/GUI Settings). - - \param[in] choice the calling widget - - \see init_scheme() for choice values and backwards compatibility - */ -void Application::set_scheme(const char *new_scheme) { +void fld::Application::set_scheme(const char *new_scheme) { if (batch_mode) return; - // set the new scheme only if the scheme was changed if (Fl::is_scheme(new_scheme)) return; Fl::scheme(new_scheme); preferences.set("scheme_name", new_scheme); - // Backwards compatibility: store 1.3 scheme index (1-4). - // We assume that index 0-3 (base, plastic, gtk+, gleam) are in the - // same order as in 1.3.x (index 1-4), higher values are ignored - int scheme_index = scheme_choice->value(); - if (scheme_index <= 3) // max. index for 1.3.x (Gleam) - preferences.set("scheme", scheme_index + 1); // compensate for different indexing + if (scheme_index <= 3) + preferences.set("scheme", scheme_index + 1); } -/** - Read Fluid's scheme preferences and set the app's scheme. - - Since FLTK 1.4.0 the scheme \b name is stored as a character string - with key "scheme_name" in the preference database. - - In FLTK 1.3.x the scheme preference was stored as an integer index - with key "scheme" in the database. The known schemes were hardcoded in - Fluid's sources (here for reference): - - | Index | 1.3 Scheme Name | Choice | 1.4 Scheme Name | - |-------|-----------------|-------|-----------------| - | 0 | Default (same as None) | n/a | n/a | - | 1 | None (same as Default) | 0 | base | - | 2 | Plastic | 1 | plastic | - | 3 | GTK+ | 2 | gtk+ | - | 4 | Gleam | 3 | gleam | - | n/a | n/a | 4 | oxy | - - The new Fluid tries to keep backwards compatibility and reads both - keys (\p scheme and \p scheme_name). If the latter is defined, it is used. - If not the old \p scheme (index) is used - but we need to subtract one to - get the new Fl_Scheme_Choice index (column "Choice" above). - */ -void Application::init_scheme() { - int scheme_index = 0; // scheme index for backwards compatibility (1.3.x) - char *scheme_name = nullptr; // scheme name since 1.4.0 - preferences.get("scheme_name", scheme_name, "XXX"); // XXX means: not set => fallback 1.3.x +void fld::Application::init_scheme() { + int scheme_index = 0; + char *scheme_name = 0; + preferences.get("scheme_name", scheme_name, "XXX"); if (!strcmp(scheme_name, "XXX")) { preferences.get("scheme", scheme_index, 0); if (scheme_index > 0) { scheme_index--; - scheme_choice->value(scheme_index); // set the choice value + scheme_choice->value(scheme_index); } if (scheme_index < 0) scheme_index = 0; @@ -1395,9 +1167,7 @@ void Application::init_scheme() { scheme_name = const_cast<char *>(scheme_choice->text(scheme_index)); preferences.set("scheme_name", scheme_name); } - // Set the new scheme only if it was not overridden by the -scheme - // command line option - if (Fl::scheme() == nullptr) { + if (Fl::scheme() == 0) { Fl::scheme(scheme_name); } free(scheme_name); @@ -1405,13 +1175,7 @@ void Application::init_scheme() { #ifdef __APPLE__ -/** - Handle app launch with an associated filename (macOS only). - Should there be a modified design already, Fluid asks for user confirmation. - \param[in] c the filename of the new design - */ -void Application::apple_open_cb(const char *c) { - Fluid.open_project_file(std::string(c)); +void fld::Application::apple_open_cb(const char *c) { + Fluid.open_project_file(c); } -#endif // __APPLE__ - +#endif diff --git a/fluid/Fluid.h b/fluid/Fluid.h index 1498760e3..4e5a053a4 100644 --- a/fluid/Fluid.h +++ b/fluid/Fluid.h @@ -27,8 +27,6 @@ #include <FL/Fl_Menu_Item.H> #include <FL/filename.H> -#include <string> - #define FLD_BROWSERWIDTH 300 #define FLD_BROWSERHEIGHT 500 #define FLD_WINWIDTH 300 @@ -58,13 +56,13 @@ class Project; class Application { /// Currently selected project. - Project *current_project_ = new Project(); + Project *current_project_; /// Working directory at application launch. - std::string launch_path_; + char launch_path_[FL_PATH_MAX]; /// Path to store temporary files during app run. - std::string tmpdir_path; + char tmpdir_path_[FL_PATH_MAX]; /// True if the temporary file path was already created. - bool tmpdir_create_called = false; + int tmpdir_create_called; // Generate a path to a directory for temporary data storage. void create_tmpdir(); // Delete the temporary directory and all its contents. @@ -78,85 +76,84 @@ public: // Member Variables /// Command line arguments app::Args args; /// List of available layouts - app::Layout_List layout_list; + app::Layout_List *layout_list; /// Set, if Fluid runs in batch mode, and no user interface is activated. - int batch_mode { 0 }; // fluid + any code generators (-u, -c, -cs) + int batch_mode; // TODO: make this into a class: app::Settings /// Show guides in the design window when positioning widgets, saved in app preferences. - int show_guides { 1 }; + int show_guides; /// Show areas of restricted use in overlay plane. /// Restricted areas are widget that overlap each other, widgets that are outside /// of their parent's bounds (except children of Scroll groups), and areas /// within an Fl_Tile that are not covered by children. - int show_restricted { 1 }; + int show_restricted; /// Show a ghosted outline for groups that have very little contrast. /// This makes groups with NO_BOX or FLAT_BOX better editable. - int show_ghosted_outline { 1 }; + int show_ghosted_outline; /// Show widget comments in the browser, saved in app preferences. - int show_comments { 1 }; + int show_comments; // TODO: make this into a class: app::External_Editor /// Use external editor for editing Code_Node, saved in app preferences. - int use_external_editor { 0 }; + int use_external_editor; /// Debugging help for external Code_Node editor. - int debug_external_editor { 0 }; + int debug_external_editor; /// Run this command to load an Code_Node into an external editor, save in app preferences. - // TODO: make this into a std::string - char external_editor_command[512] { }; + char external_editor_command[512]; // TODO: make this into a class: app::GUI - Fl_Window *main_window { nullptr }; + Fl_Window *main_window; static Fl_Menu_Item main_menu[]; - fld::widget::App_Menu_Bar *main_menubar { nullptr }; - Fl_Menu_Item *save_item { nullptr }; - Fl_Menu_Item *history_item { nullptr }; - Fl_Menu_Item *widgetbin_item { nullptr }; - Fl_Menu_Item *codeview_item { nullptr }; - Fl_Menu_Item *overlay_item { nullptr }; - Fl_Button *overlay_button { nullptr }; - Fl_Menu_Item *guides_item { nullptr }; - Fl_Menu_Item *restricted_item { nullptr }; + fld::widget::App_Menu_Bar *main_menubar; + Fl_Menu_Item *save_item; + Fl_Menu_Item *history_item; + Fl_Menu_Item *widgetbin_item; + Fl_Menu_Item *codeview_item; + Fl_Menu_Item *overlay_item; + Fl_Button *overlay_button; + Fl_Menu_Item *guides_item; + Fl_Menu_Item *restricted_item; /// Offset in pixels when adding widgets from an .fl file. - int pasteoffset { 0 }; - int ipasteoffset { 0 }; + int pasteoffset; + int ipasteoffset; /// FLUID-wide help dialog. - Fl_Help_Dialog *help_dialog { nullptr }; + Fl_Help_Dialog *help_dialog; public: // Methods // Create the Fluid application. Application(); /// Destructor. - ~Application() = default; + ~Application(); // Launch the application. - int run(int argc,char **argv); + int run(int argc, char **argv); // Quit the application and clean up. void quit(); - /// Quick access to the current project. Make sure it stays synched to current_project_. - Project &proj { *current_project_ }; + /// Quick access to the current project. + Project &proj; // Return the working directory path at application launch. - const std::string &launch_path() const; + const char *launch_path() const; // Return the path to a temporary directory for this instance of Fluid. - const std::string &get_tmpdir(); + const char *get_tmpdir(); // Return the path and filename of a temporary file for cut or duplicated data. const char *cutfname(int which = 0); // Clear the current project and create a new, empty one. - bool new_project(bool user_must_confirm = true); + int new_project(int user_must_confirm = 1); // Open a file chooser and load an exiting project file. - bool open_project_file(const std::string &filename_arg); + int open_project_file(const char *filename_arg); // Load a project from the give file name and path. - bool merge_project_file(const std::string &filename_arg); + int merge_project_file(const char *filename_arg); // Save the current design to the file given by \c filename. void save_project_file(void *arg); // Reload the file set by \c filename, replacing the current design. void revert_project(); // Open the template browser and load a new file from templates. - bool new_project_from_template(); + int new_project_from_template(); // Open the dialog to allow the user to print the current window. void print_snapshots(); // Generate the C++ source and header filenames and write those files. - int write_code_files(bool dont_show_completion_dialog=false); + int write_code_files(int dont_show_completion_dialog = 0); // User chose to cut the currently selected widgets. void cut_selected(); @@ -182,13 +179,14 @@ public: // Methods // Build the main app window and create a few other dialogs. void make_main_window(); // Open a native file chooser to allow choosing a project file for reading. - std::string open_project_filechooser(const std::string &title); + // Returns path in provided buffer, or empty string if cancelled. + void open_project_filechooser(char *result, int result_size, const char *title); // Give the user the opportunity to save a project before clearing it. - bool confirm_project_clear(); + int confirm_project_clear(); // Ensure that text widgets in the widget panel propagates apply current changes. void flush_text_widgets(); // Position the given window window based on entries in the app preferences. - char position_window(Fl_Window *w, const char *prefsName, int Visible, int X, int Y, int W=0, int H=0); + char position_window(Fl_Window *w, const char *prefsName, int Visible, int X, int Y, int W = 0, int H = 0); // Save the position and visibility state of a window to the app preferences. void save_position(Fl_Window *w, const char *prefsName); // Change the app's and hence preview the design's scheme. @@ -198,7 +196,7 @@ public: // Methods #ifdef __APPLE__ static void apple_open_cb(const char *c); -#endif // __APPLE__ +#endif }; } // namespace fld @@ -207,4 +205,3 @@ extern fld::Application Fluid; #endif // FLUID_FLUID_H - diff --git a/fluid/Project.cxx b/fluid/Project.cxx index 4545530a6..51cbbde27 100644 --- a/fluid/Project.cxx +++ b/fluid/Project.cxx @@ -15,34 +15,66 @@ // #include <errno.h> // strerror(errno) +#include <stdlib.h> // free, malloc +#include <string.h> // strdup, strlen, strcmp + #include "Project.h" +#include "Fluid.h" #include "io/String_Writer.h" #include "nodes/Node.h" #include "panels/settings_panel.h" #include "panels/codeview_panel.h" +#include "tools/filename.h" -using namespace fld; +#include <FL/fl_ask.H> +#include <FL/fl_utf8.h> // ---- project settings /** Initialize a new project. */ -Project::Project() { +fld::Project::Project() + : undo(*this), + tree(*this), + i18n(*this), + include_H_from_C(1), + use_FL_COMMAND(0), + utf8_in_src(0), + avoid_early_includes(0), + header_file_set(0), + code_file_set(0), + write_mergeback_data(0), + proj_filename(0), + header_file_name_(0), + code_file_name_(0), + include_guard_(0), + in_project_dir(0), + modflag(0), + modflag_c(0), + layout(app::default_layout_preset) +{ + app_work_dir_[0] = '\0'; + set_header_file_name(".h"); + set_code_file_name(".cxx"); + set_include_guard(""); } /** Clear all project resources. - Not implemented. */ -Project::~Project() { +fld::Project::~Project() { + if (header_file_name_) free(header_file_name_); + if (code_file_name_) free(code_file_name_); + if (include_guard_) free(include_guard_); + if (proj_filename) free((void*)proj_filename); } /** Reset all project setting to create a new empty project. */ -void Project::reset() { +void fld::Project::reset() { ::delete_all(); i18n.reset(); @@ -52,133 +84,207 @@ void Project::reset() { avoid_early_includes = 0; header_file_set = 0; code_file_set = 0; - header_file_name = ".h"; - code_file_name = ".cxx"; - include_guard = ""; + set_header_file_name(".h"); + set_code_file_name(".cxx"); + set_include_guard(""); write_mergeback_data = 0; } /** Tell the project and i18n tab of the settings dialog to refresh themselves. */ -void Project::update_settings_dialog() { +void fld::Project::update_settings_dialog() { if (settings_window) { w_settings_project_tab->do_callback(w_settings_project_tab, LOAD); w_settings_i18n_tab->do_callback(w_settings_i18n_tab, LOAD); } } +// Setters for string members + +void fld::Project::set_header_file_name(const char *name) { + if (header_file_name_) free(header_file_name_); + header_file_name_ = name ? strdup(name) : 0; +} + +void fld::Project::set_code_file_name(const char *name) { + if (code_file_name_) free(code_file_name_); + code_file_name_ = name ? strdup(name) : 0; +} + +void fld::Project::set_include_guard(const char *guard) { + if (include_guard_) free(include_guard_); + include_guard_ = guard ? strdup(guard) : 0; +} + /** Get the absolute path of the project file, for example `/Users/matt/dev/`. - \return the path ending in '/' + \param[out] buf buffer to store result (ends with '/') + \param[in] bufsize size of buffer */ -std::string Project::projectfile_path() const { - if (!proj_filename) return std::string{}; - return end_with_slash(fl_filename_absolute_str(fl_filename_path_str(proj_filename), Fluid.launch_path())); +void fld::Project::projectfile_path(char *buf, int bufsize) const { + buf[0] = '\0'; + if (!proj_filename) return; + + char path[FL_PATH_MAX]; + fl_filename_path(path, FL_PATH_MAX, proj_filename); + + char abs_path[FL_PATH_MAX]; + fl_filename_absolute(abs_path, FL_PATH_MAX, path, Fluid.launch_path()); + + fld_end_with_slash(buf, bufsize, abs_path); } /** Get the project file name including extension, for example `test.fl`. \return the file name without path */ -std::string Project::projectfile_name() const { - if (!proj_filename) return std::string{}; +const char *fld::Project::projectfile_name() const { + if (!proj_filename) return 0; return fl_filename_name(proj_filename); } /** Get the absolute path of the generated C++ code file, for example `/Users/matt/dev/src/`. - \return the path ending in '/' + \param[out] buf buffer to store result (ends with '/') + \param[in] bufsize size of buffer */ -std::string Project::codefile_path() const { - std::string path = fl_filename_path_str(code_file_name); - if (Fluid.batch_mode) - return end_with_slash(fl_filename_absolute_str(path, Fluid.launch_path())); - else - return end_with_slash(fl_filename_absolute_str(path, projectfile_path())); +void fld::Project::codefile_path(char *buf, int bufsize) const { + buf[0] = '\0'; + + char path[FL_PATH_MAX]; + fl_filename_path(path, FL_PATH_MAX, code_file_name_); + + char abs_path[FL_PATH_MAX]; + if (Fluid.batch_mode) { + fl_filename_absolute(abs_path, FL_PATH_MAX, path, Fluid.launch_path()); + } else { + char proj_path[FL_PATH_MAX]; + projectfile_path(proj_path, FL_PATH_MAX); + fl_filename_absolute(abs_path, FL_PATH_MAX, path, proj_path); + } + + fld_end_with_slash(buf, bufsize, abs_path); } /** Get the generated C++ code file name including extension, for example `test.cxx`. - \return the file name without path + \param[out] buf buffer to store result + \param[in] bufsize size of buffer */ -std::string Project::codefile_name() const { - std::string name = fl_filename_name_str(code_file_name); - if (name.empty()) { - if (!proj_filename) return std::string{}; - return fl_filename_setext_str(fl_filename_name(proj_filename), ".cxx"); +void fld::Project::codefile_name(char *buf, int bufsize) const { + buf[0] = '\0'; + + const char *name = fl_filename_name(code_file_name_); + if (!name || !*name) { + // No name specified, use project filename with .cxx extension + if (!proj_filename) return; + strlcpy(buf, fl_filename_name(proj_filename), bufsize); + fl_filename_setext(buf, bufsize, ".cxx"); } else if (name[0] == '.') { - if (!proj_filename) return std::string{}; - return fl_filename_setext_str(fl_filename_name(proj_filename), code_file_name); + // Only extension specified, use project filename with this extension + if (!proj_filename) return; + strlcpy(buf, fl_filename_name(proj_filename), bufsize); + fl_filename_setext(buf, bufsize, code_file_name_); } else { - return name; + strlcpy(buf, name, bufsize); } } /** Get the absolute path of the generated C++ header file, for example `/Users/matt/dev/src/`. - \return the path ending in '/' + \param[out] buf buffer to store result (ends with '/') + \param[in] bufsize size of buffer */ -std::string Project::headerfile_path() const { - std::string path = fl_filename_path_str(header_file_name); - if (Fluid.batch_mode) - return end_with_slash(fl_filename_absolute_str(path, Fluid.launch_path())); - else - return end_with_slash(fl_filename_absolute_str(path, projectfile_path())); +void fld::Project::headerfile_path(char *buf, int bufsize) const { + buf[0] = '\0'; + + char path[FL_PATH_MAX]; + fl_filename_path(path, FL_PATH_MAX, header_file_name_); + + char abs_path[FL_PATH_MAX]; + if (Fluid.batch_mode) { + fl_filename_absolute(abs_path, FL_PATH_MAX, path, Fluid.launch_path()); + } else { + char proj_path[FL_PATH_MAX]; + projectfile_path(proj_path, FL_PATH_MAX); + fl_filename_absolute(abs_path, FL_PATH_MAX, path, proj_path); + } + + fld_end_with_slash(buf, bufsize, abs_path); } /** - Get the generated C++ header file name including extension, for example `test.cxx`. - \return the file name without path + Get the generated C++ header file name including extension, for example `test.h`. + \param[out] buf buffer to store result + \param[in] bufsize size of buffer */ -std::string Project::headerfile_name() const { - std::string name = fl_filename_name_str(header_file_name); - if (name.empty()) { - if (!proj_filename) return std::string{}; - return fl_filename_setext_str(fl_filename_name_str(proj_filename), ".h"); +void fld::Project::headerfile_name(char *buf, int bufsize) const { + buf[0] = '\0'; + + const char *name = fl_filename_name(header_file_name_); + if (!name || !*name) { + // No name specified, use project filename with .h extension + if (!proj_filename) return; + strlcpy(buf, fl_filename_name(proj_filename), bufsize); + fl_filename_setext(buf, bufsize, ".h"); } else if (name[0] == '.') { - if (!proj_filename) return std::string{}; - return fl_filename_setext_str(fl_filename_name_str(proj_filename), header_file_name); + // Only extension specified, use project filename with this extension + if (!proj_filename) return; + strlcpy(buf, fl_filename_name(proj_filename), bufsize); + fl_filename_setext(buf, bufsize, header_file_name_); } else { - return name; + strlcpy(buf, name, bufsize); } } /** Get the absolute path of the generated i18n strings file, for example `/Users/matt/dev/`. - Although it may be more useful to put the text file into the same directory - with the source and header file, historically, the text is always saved with - the project file in interactive mode, and in the FLUID launch directory in - batch mode. - \return the path ending in '/' + \param[out] buf buffer to store result (ends with '/') + \param[in] bufsize size of buffer */ -std::string Project::stringsfile_path() const { - if (Fluid.batch_mode) - return Fluid.launch_path(); - else - return projectfile_path(); +void fld::Project::stringsfile_path(char *buf, int bufsize) const { + if (Fluid.batch_mode) { + strlcpy(buf, Fluid.launch_path(), bufsize); + } else { + projectfile_path(buf, bufsize); + } } /** Get the generated i18n text file name including extension, for example `test.po`. - \return the file name without path + \param[out] buf buffer to store result + \param[in] bufsize size of buffer */ -std::string Project::stringsfile_name() const { - if (!proj_filename) return std::string{}; +void fld::Project::stringsfile_name(char *buf, int bufsize) const { + buf[0] = '\0'; + if (!proj_filename) return; + + strlcpy(buf, fl_filename_name(proj_filename), bufsize); switch (i18n.type) { - default: return fl_filename_setext_str(fl_filename_name(proj_filename), ".txt"); - case FLD_I18N_TYPE_GNU: return fl_filename_setext_str(fl_filename_name(proj_filename), ".po"); - case FLD_I18N_TYPE_POSIX: return fl_filename_setext_str(fl_filename_name(proj_filename), ".msg"); + default: + fl_filename_setext(buf, bufsize, ".txt"); + break; + case FLD_I18N_TYPE_GNU: + fl_filename_setext(buf, bufsize, ".po"); + break; + case FLD_I18N_TYPE_POSIX: + fl_filename_setext(buf, bufsize, ".msg"); + break; } } /** Get the name of the project file without the filename extension. - \return the file name without path or extension + \param[out] buf buffer to store result + \param[in] bufsize size of buffer */ -std::string Project::basename() const { - if (!proj_filename) return std::string{}; - return fl_filename_setext_str(fl_filename_name(proj_filename), ""); +void fld::Project::basename(char *buf, int bufsize) const { + buf[0] = '\0'; + if (!proj_filename) return; + + strlcpy(buf, fl_filename_name(proj_filename), bufsize); + fl_filename_setext(buf, bufsize, ""); } @@ -198,36 +304,41 @@ std::string Project::basename() const { \see leave_project_dir(), pwd, in_project_dir */ -void Project::enter_project_dir() { - if (in_project_dir<0) { +void fld::Project::enter_project_dir() { + if (in_project_dir < 0) { fprintf(stderr, "** Fluid internal error: enter_project_dir() calls unmatched\n"); return; } in_project_dir++; // check if we are already in the project dir and do nothing if so - if (in_project_dir>1) return; + if (in_project_dir > 1) return; // check if there is an active project, and do nothing if there is none if (!proj_filename || !*proj_filename) { fprintf(stderr, "** Fluid internal error: enter_project_dir() no filename set\n"); return; } // store the current working directory for later - app_work_dir = fl_getcwd_str(); + fl_getcwd(app_work_dir_, FL_PATH_MAX); + // set the current directory to the path of our .fl file - std::string project_path = fl_filename_path_str(fl_filename_absolute_str(proj_filename)); - if (fl_chdir(project_path.c_str()) == -1) { + char abs_filename[FL_PATH_MAX]; + fl_filename_absolute(abs_filename, FL_PATH_MAX, proj_filename); + + char project_path[FL_PATH_MAX]; + fl_filename_path(project_path, FL_PATH_MAX, abs_filename); + + if (fl_chdir(project_path) == -1) { fprintf(stderr, "** Fluid internal error: enter_project_dir() can't chdir to %s: %s\n", - project_path.c_str(), strerror(errno)); + project_path, strerror(errno)); return; } - //fprintf(stderr, "chdir from %s to %s\n", app_work_dir.c_str(), fl_getcwd().c_str()); } /** Change the current working directory to the previous directory. \see enter_project_dir(), pwd, in_project_dir */ -void Project::leave_project_dir() { +void fld::Project::leave_project_dir() { if (in_project_dir == 0) { fprintf(stderr, "** Fluid internal error: leave_project_dir() calls unmatched\n"); return; @@ -236,27 +347,26 @@ void Project::leave_project_dir() { // still nested, stay in the project directory if (in_project_dir > 0) return; // no longer nested, return to the original, usually the application working directory - if (fl_chdir(app_work_dir.c_str()) < 0) { + if (fl_chdir(app_work_dir_) < 0) { fprintf(stderr, "** Fluid internal error: leave_project_dir() can't chdir back to %s : %s\n", - app_work_dir.c_str(), strerror(errno)); + app_work_dir_, strerror(errno)); } } /** - Alias for set_filename(""). - Instead, change proj_filename into a std::string and add clear_filename(). + Clear the project filename. */ -void Project::set_filename(std::nullptr_t) { - set_filename(std::string()); +void fld::Project::clear_filename() { + set_filename(0); } /** Set the filename of the current .fl design. - \param[in] c the new absolute filename and path + \param[in] c the new absolute filename and path (may be NULL to clear) */ -void Project::set_filename(const std::string &c) { +void fld::Project::set_filename(const char *c) { if (proj_filename) free((void *)proj_filename); - proj_filename = c.empty() ? nullptr : fl_strdup(c.c_str()); + proj_filename = (c && *c) ? strdup(c) : 0; if (proj_filename && !Fluid.batch_mode) Fluid.history.update(proj_filename); @@ -267,24 +377,32 @@ void Project::set_filename(const std::string &c) { /** Write the strings that are used in i18n. */ -void Project::write_strings() { +void fld::Project::write_strings() { Fluid.flush_text_widgets(); if (!proj_filename) { - Fluid.save_project_file(nullptr); + Fluid.save_project_file(0); if (!proj_filename) return; } - std::string filename = stringsfile_path() + stringsfile_name(); + + char path[FL_PATH_MAX]; + char name[FL_PATH_MAX]; + stringsfile_path(path, FL_PATH_MAX); + stringsfile_name(name, FL_PATH_MAX); + + char filename[FL_PATH_MAX]; + snprintf(filename, FL_PATH_MAX, "%s%s", path, name); + int x = fld::io::write_strings(*this, filename); if (Fluid.batch_mode) { if (x) { - fprintf(stderr, "%s : %s\n", filename.c_str(), strerror(errno)); + fprintf(stderr, "%s : %s\n", filename, strerror(errno)); exit(1); } } else { if (x) { - fl_message("Can't write %s: %s", filename.c_str(), strerror(errno)); + fl_message("Can't write %s: %s", filename, strerror(errno)); } else if (completion_button->value()) { - fl_message("Wrote %s", stringsfile_name().c_str()); + fl_message("Wrote %s", name); } } } @@ -307,31 +425,34 @@ void Project::write_strings() { \param[in] mfc default -1 to let \c mf control \c modflag_c, 0 to mark the code files current, 1 to mark it out of date. -2 to ignore changes to mf. */ -void Project::set_modflag(int mf, int mfc) { - const char *code_ext = nullptr; +void fld::Project::set_modflag(int mf, int mfc) { + const char *code_ext = 0; char new_title[FL_PATH_MAX]; // Update the modflag_c to the worst possible condition. We could be a bit // more graceful and compare modification times of the files, but C++ has // no API for that until C++17. - if (mf!=-1) { + if (mf != -1) { modflag = mf; - if (mfc==-1 && mf==1) + if (mfc == -1 && mf == 1) mfc = mf; } - if (mfc>=0) { + if (mfc >= 0) { modflag_c = mfc; } if (Fluid.main_window) { - std::string basename; - if (!proj_filename) basename = "Untitled.fl"; - else basename = fl_filename_name_str(std::string(proj_filename)); - code_ext = fl_filename_ext(code_file_name.c_str()); + const char *base; + if (!proj_filename) { + base = "Untitled.fl"; + } else { + base = fl_filename_name(proj_filename); + } + code_ext = fl_filename_ext(code_file_name_); char mod_star = modflag ? '*' : ' '; char mod_c_star = modflag_c ? '*' : ' '; snprintf(new_title, sizeof(new_title), "%s%c %s%c", - basename.c_str(), mod_star, code_ext, mod_c_star); + base, mod_star, code_ext, mod_c_star); const char *old_title = Fluid.main_window->label(); // only update the title if it actually changed if (!old_title || strcmp(old_title, new_title)) diff --git a/fluid/Project.h b/fluid/Project.h index d4d60daaa..f920c6ff3 100644 --- a/fluid/Project.h +++ b/fluid/Project.h @@ -22,7 +22,7 @@ #include "proj/i18n.h" #include "nodes/Tree.h" -#include <string> +#include <FL/filename.H> // ---- project class declaration @@ -41,49 +41,49 @@ class Project { public: // Member Variables // Undo actions for this Project. - proj::Undo undo { *this }; + proj::Undo undo; // Manage the node tree of the project. - node::Tree tree { *this }; + node::Tree tree; // Project internationalization. - proj::I18n i18n { *this }; + proj::I18n i18n; /// If set, generate code to include the header file form the c++ file - int include_H_from_C = 1; + int include_H_from_C; /// If set, handle keyboard shortcut Ctrl on macOS using Cmd instead - int use_FL_COMMAND = 0; + int use_FL_COMMAND; /// Clear if UTF-8 characters in statics texts are written as escape sequences - int utf8_in_src = 0; + int utf8_in_src; /// If set, <FL/Fl.H> will not be included from the header code before anything else - int avoid_early_includes = 0; + int avoid_early_includes; /// If set, command line overrides header file name in .fl file. - int header_file_set = 0; + int header_file_set; /// If set, command line overrides source code file name in .fl file. - int code_file_set = 0; + int code_file_set; /// later - int write_mergeback_data = 0; + int write_mergeback_data; /// Filename of the current .fl project file - const char *proj_filename { nullptr }; + const char *proj_filename; /// Hold the default extension for header files, or the entire filename if set via command line. - std::string header_file_name = ".h"; - /// Hold the default extension for source code files, or the entire filename if set via command line. - std::string code_file_name = ".cxx"; + char *header_file_name_; + /// Hold the default extension for source code files, or the entire filename if set via command line. + char *code_file_name_; /// Macro used in header file for #ifdef MACRO \n #defined MACRO \n ... \n #endif - std::string include_guard = ""; + char *include_guard_; /// Used as a counter to set the .fl project dir as the current directory. - int in_project_dir { 0 }; + int in_project_dir; /// Application work directory, stored here when temporarily changing to the source code directory. - std::string app_work_dir = ""; + char app_work_dir_[FL_PATH_MAX]; /// Set if the current design has been modified compared to the associated .fl design file. - int modflag { 0 }; + int modflag; /// Set if the code files are older than the current design. - int modflag_c { 0 }; + int modflag_c; /// Currently used layout preset. - app::Layout_Preset *layout { app::default_layout_preset }; + app::Layout_Preset *layout; public: // Methods Project(); @@ -91,21 +91,32 @@ public: // Methods void reset(); void update_settings_dialog(); - std::string projectfile_path() const; - std::string projectfile_name() const; - std::string codefile_path() const; - std::string codefile_name() const; - std::string headerfile_path() const; - std::string headerfile_name() const; - std::string stringsfile_path() const; - std::string stringsfile_name() const; - std::string basename() const; + // Getters for file name settings + const char *header_file_name() const { return header_file_name_; } + const char *code_file_name() const { return code_file_name_; } + const char *include_guard() const { return include_guard_; } + + // Setters for file name settings + void set_header_file_name(const char *name); + void set_code_file_name(const char *name); + void set_include_guard(const char *guard); + + // Path computation methods - fill provided buffer + void projectfile_path(char *buf, int bufsize) const; + const char *projectfile_name() const; + void codefile_path(char *buf, int bufsize) const; + void codefile_name(char *buf, int bufsize) const; + void headerfile_path(char *buf, int bufsize) const; + void headerfile_name(char *buf, int bufsize) const; + void stringsfile_path(char *buf, int bufsize) const; + void stringsfile_name(char *buf, int bufsize) const; + void basename(char *buf, int bufsize) const; void enter_project_dir(); void leave_project_dir(); - void set_filename(std::nullptr_t); - void set_filename(const std::string &c); + void clear_filename(); + void set_filename(const char *c); void write_strings(); void set_modflag(int mf, int mfc = -1); @@ -114,5 +125,3 @@ public: // Methods } // namespace fld #endif // FLUID_PROJECT_H - - diff --git a/fluid/app/Image_Asset.cxx b/fluid/app/Image_Asset.cxx index 09550fac0..cea3cc058 100644 --- a/fluid/app/Image_Asset.cxx +++ b/fluid/app/Image_Asset.cxx @@ -209,8 +209,8 @@ void Image_Asset::write_static_rgb(fld::io::Code_Writer& f, const char* idata_na */ void Image_Asset::write_static(fld::io::Code_Writer& f, int compressed) { if (!image_) return; - const char *idata_name = f.unique_id(this, "idata", fl_filename_name(filename()), nullptr); - initializer_function_ = f.unique_id(this, "image", fl_filename_name(filename()), nullptr); + const char *idata_name = f.unique_id(this, "idata", fl_filename_name(filename()), 0); + initializer_function_ = f.unique_id(this, "image", fl_filename_name(filename()), 0); if (is_animated_gif_) { // Write animated gif image data... @@ -309,8 +309,8 @@ void Image_Asset::write_static(fld::io::Code_Writer& f, int compressed) { } else { // if FLUID runs from the command line, make sure that the image is not // only loaded but also rasterized, so we can write the RGB image data - Fl_RGB_Image* rgb_image = nullptr; - Fl_SVG_Image* svg_image = nullptr; + Fl_RGB_Image* rgb_image = 0; + Fl_SVG_Image* svg_image = 0; if (image_->d()>0) rgb_image = (Fl_RGB_Image*)image_->image(); if (rgb_image) @@ -343,7 +343,7 @@ void Image_Asset::write_static(fld::io::Code_Writer& f, int compressed) { void Image_Asset::write_file_error(fld::io::Code_Writer& f, const char *fmt) { f.write_c("#warning Cannot read %s file \"%s\": %s\n", fmt, filename(), strerror(errno)); Fluid.proj.enter_project_dir(); - f.write_c("// Searching in path \"%s\"\n", fl_getcwd(nullptr, FL_PATH_MAX)); + f.write_c("// Searching in path \"%s\"\n", fl_getcwd(0, FL_PATH_MAX)); Fluid.proj.leave_project_dir(); } @@ -434,10 +434,10 @@ void Image_Asset::write_inline(fld::io::Code_Writer& f, int inactive) { If the image asset has already been loaded, it is returned from the cache. If the image asset has not been loaded, it is loaded from the file system. - If the image asset cannot be loaded, nullptr is returned. + If the image asset cannot be loaded, 0 is returned. \param iname The filename of the image asset to find. - \returns The image asset, or nullptr if it cannot be loaded. + \returns The image asset, or 0 if it cannot be loaded. */ Image_Asset* Image_Asset::find(const char *iname) { if (!iname || !*iname) return 0; @@ -553,12 +553,12 @@ Image_Asset::~Image_Asset() { .pgm, .png, .ppm, .xbm, .xpm, and .svg (and .svgz if zlib support is enabled). The function returns a pointer to an Image_Asset object that references the selected image. If the user cancels the file chooser or - selects a file that does not exist, the function returns nullptr. + selects a file that does not exist, the function returns 0. \param oldname The default filename to display in the file chooser. \return A pointer to an Image_Asset object that references the selected - image, or nullptr if the user cancels the file chooser or selects a file + image, or 0 if the user cancels the file chooser or selects a file that does not exist. The asset is automaticly added to the global image asset map. */ @@ -572,8 +572,8 @@ Image_Asset *ui_find_image(const char *oldname) { #endif "})", oldname,1); - fl_file_chooser_ok_label(nullptr); - Image_Asset *ret = (name && *name) ? Image_Asset::find(name) : nullptr; + fl_file_chooser_ok_label(0); + Image_Asset *ret = (name && *name) ? Image_Asset::find(name) : 0; Fluid.proj.leave_project_dir(); return ret; } diff --git a/fluid/app/Image_Asset.h b/fluid/app/Image_Asset.h index f5376beaa..fcc8fb31c 100644 --- a/fluid/app/Image_Asset.h +++ b/fluid/app/Image_Asset.h @@ -32,7 +32,7 @@ private: // member variables bool is_animated_gif_ = false; ///< It's an animated gif. std::string filename_ { }; ///< Relative path to the image file int refcount_ = 0; ///< Reference count - Fl_Shared_Image *image_ = nullptr; ///< The actual image as managed by FLTK + Fl_Shared_Image *image_ = 0; ///< The actual image as managed by FLTK std::string initializer_function_ { }; ///< The name of the initializer function private: // methods diff --git a/fluid/app/Menu.cxx b/fluid/app/Menu.cxx index ab03a822d..54db5801f 100644 --- a/fluid/app/Menu.cxx +++ b/fluid/app/Menu.cxx @@ -35,11 +35,8 @@ extern void layout_suite_marker(Fl_Widget *, void *user_data); extern void select_layout_preset_cb(Fl_Widget *, void *user_data); extern Fl_Menu_Item main_layout_submenu_[]; -using namespace fld; - - void write_cb(Fl_Widget *, void *) { - Fluid.write_code_files(); + Fluid.write_code_files(0); } void openwidget_cb(Fl_Widget *, void *) { Fluid.edit_selected(); } void copy_cb(Fl_Widget*, void*) { Fluid.copy_selected(); } @@ -59,13 +56,13 @@ void manual_cb(Fl_Widget *, void *) { Fluid.show_help("index.html"); } -static void menu_file_new_cb(Fl_Widget *, void *) { Fluid.new_project(); } +static void menu_file_new_cb(Fl_Widget *, void *) { Fluid.new_project(1); } static void menu_file_new_from_template_cb(Fl_Widget *, void *) { Fluid.new_project_from_template(); } static void menu_file_open_cb(Fl_Widget *, void *) { Fluid.open_project_file(""); } static void menu_file_insert_cb(Fl_Widget *, void *) { Fluid.merge_project_file(""); } void menu_file_save_cb(Fl_Widget *, void *arg) { Fluid.save_project_file(arg); } static void menu_file_print_cb(Fl_Widget *, void *arg) { Fluid.print_snapshots(); } -void menu_file_open_history_cb(Fl_Widget *, void *v) { Fluid.open_project_file(std::string((const char*)v)); } +void menu_file_open_history_cb(Fl_Widget *, void *v) { Fluid.open_project_file((const char*)v); } static void menu_layout_sync_resize_cb(Fl_Menu_ *m, void*) { if (m->mvalue()->value()) Fluid.proj.tree.allow_layout = 1; else Fluid.proj.tree.allow_layout = 0; } @@ -88,21 +85,21 @@ void toggle_widgetbin_cb(Fl_Widget *, void *) { Fluid.toggle_widget_bin(); } \todo Shortcuts are all over the place (Alt, Ctrl, Command, Shift-Ctrl, function keys), and there should be a help page listing all shortcuts. */ -Fl_Menu_Item Application::main_menu[] = { - {"&File",0,nullptr,nullptr,FL_SUBMENU}, +Fl_Menu_Item fld::Application::main_menu[] = { + {"&File",0,0,0,FL_SUBMENU}, {"&New", FL_COMMAND+'n', menu_file_new_cb}, {"&Open...", FL_COMMAND+'o', menu_file_open_cb}, - {"&Insert...", FL_COMMAND+'i', menu_file_insert_cb, nullptr, FL_MENU_DIVIDER}, - {"&Save", FL_COMMAND+'s', menu_file_save_cb, nullptr}, + {"&Insert...", FL_COMMAND+'i', menu_file_insert_cb, 0, FL_MENU_DIVIDER}, + {"&Save", FL_COMMAND+'s', menu_file_save_cb, 0}, {"Save &As...", FL_COMMAND+FL_SHIFT+'s', menu_file_save_cb, (void*)1}, {"Sa&ve A Copy...", 0, menu_file_save_cb, (void*)2}, - {"&Revert...", 0, menu_file_revert_cb, nullptr, FL_MENU_DIVIDER}, - {"New &From Template...", FL_COMMAND+'N', menu_file_new_from_template_cb, nullptr}, - {"Save As &Template...", 0, save_template_cb, nullptr, FL_MENU_DIVIDER}, + {"&Revert...", 0, menu_file_revert_cb, 0, FL_MENU_DIVIDER}, + {"New &From Template...", FL_COMMAND+'N', menu_file_new_from_template_cb, 0}, + {"Save As &Template...", 0, save_template_cb, 0, FL_MENU_DIVIDER}, {"&Print...", FL_COMMAND+'p', menu_file_print_cb}, - {"Write &Code", FL_COMMAND+FL_SHIFT+'c', write_cb, nullptr}, + {"Write &Code", FL_COMMAND+FL_SHIFT+'c', write_cb, 0}, {"MergeBack Code", FL_COMMAND+FL_SHIFT+'m', mergeback_cb, 0}, - {"&Write Strings", FL_COMMAND+FL_SHIFT+'w', write_strings_cb, nullptr, FL_MENU_DIVIDER}, + {"&Write Strings", FL_COMMAND+FL_SHIFT+'w', write_strings_cb, 0, FL_MENU_DIVIDER}, {Fluid.history.relpath[0], FL_COMMAND+'1', menu_file_open_history_cb, Fluid.history.abspath[0]}, {Fluid.history.relpath[1], FL_COMMAND+'2', menu_file_open_history_cb, Fluid.history.abspath[1]}, {Fluid.history.relpath[2], FL_COMMAND+'3', menu_file_open_history_cb, Fluid.history.abspath[2]}, @@ -114,67 +111,67 @@ Fl_Menu_Item Application::main_menu[] = { {Fluid.history.relpath[8], FL_COMMAND+'9', menu_file_open_history_cb, Fluid.history.abspath[8]}, {Fluid.history.relpath[9], 0, menu_file_open_history_cb, Fluid.history.abspath[9], FL_MENU_DIVIDER}, {"&Quit", FL_COMMAND+'q', exit_cb}, - {nullptr}, - {"&Edit",0,nullptr,nullptr,FL_SUBMENU}, + {0}, + {"&Edit",0,0,0,FL_SUBMENU}, {"&Undo", FL_COMMAND+'z', fld::proj::Undo::undo_cb}, - {"&Redo", FL_COMMAND+FL_SHIFT+'z', fld::proj::Undo::redo_cb, nullptr, FL_MENU_DIVIDER}, + {"&Redo", FL_COMMAND+FL_SHIFT+'z', fld::proj::Undo::redo_cb, 0, FL_MENU_DIVIDER}, {"C&ut", FL_COMMAND+'x', cut_cb}, {"&Copy", FL_COMMAND+'c', copy_cb}, {"&Paste", FL_COMMAND+'v', paste_cb}, {"Dup&licate", FL_COMMAND+'u', duplicate_cb}, - {"&Delete", FL_Delete, delete_cb, nullptr, FL_MENU_DIVIDER}, + {"&Delete", FL_Delete, delete_cb, 0, FL_MENU_DIVIDER}, {"Select &All", FL_COMMAND+'a', select_all_cb}, - {"Select &None", FL_COMMAND+FL_SHIFT+'a', select_none_cb, nullptr, FL_MENU_DIVIDER}, + {"Select &None", FL_COMMAND+FL_SHIFT+'a', select_none_cb, 0, FL_MENU_DIVIDER}, {"Pr&operties...", FL_F+1, openwidget_cb}, {"&Sort",0,sort_cb}, {"&Earlier", FL_F+2, earlier_cb}, {"&Later", FL_F+3, later_cb}, {"&Group", FL_F+7, group_cb}, - {"Ung&roup", FL_F+8, ungroup_cb,nullptr, FL_MENU_DIVIDER}, + {"Ung&roup", FL_F+8, ungroup_cb,0, FL_MENU_DIVIDER}, {"Hide O&verlays",FL_COMMAND+FL_SHIFT+'o',toggle_overlays}, {"Hide Guides",FL_COMMAND+FL_SHIFT+'g',toggle_guides}, {"Hide Restricted",FL_COMMAND+FL_SHIFT+'r',toggle_restricted}, {"Show Widget &Bin...",FL_ALT+'b',toggle_widgetbin_cb}, - {"Show Code View",FL_ALT+'c', (Fl_Callback*)toggle_codeview_cb, nullptr, FL_MENU_DIVIDER}, + {"Show Code View",FL_ALT+'c', (Fl_Callback*)toggle_codeview_cb, 0, FL_MENU_DIVIDER}, {"Settings...",FL_ALT+'p',show_settings_cb}, - {nullptr}, - {"&New", 0, nullptr, (void *)New_Menu, FL_SUBMENU_POINTER}, - {"&Layout",0,nullptr,nullptr,FL_SUBMENU}, - {"&Align",0,nullptr,nullptr,FL_SUBMENU}, + {0}, + {"&New", 0, 0, (void *)New_Menu, FL_SUBMENU_POINTER}, + {"&Layout",0,0,0,FL_SUBMENU}, + {"&Align",0,0,0,FL_SUBMENU}, {"&Left",0,(Fl_Callback *)align_widget_cb,(void*)10}, {"&Center",0,(Fl_Callback *)align_widget_cb,(void*)11}, {"&Right",0,(Fl_Callback *)align_widget_cb,(void*)12}, {"&Top",0,(Fl_Callback *)align_widget_cb,(void*)13}, {"&Middle",0,(Fl_Callback *)align_widget_cb,(void*)14}, {"&Bottom",0,(Fl_Callback *)align_widget_cb,(void*)15}, - {nullptr}, - {"&Space Evenly",0,nullptr,nullptr,FL_SUBMENU}, + {0}, + {"&Space Evenly",0,0,0,FL_SUBMENU}, {"&Across",0,(Fl_Callback *)align_widget_cb,(void*)20}, {"&Down",0,(Fl_Callback *)align_widget_cb,(void*)21}, - {nullptr}, - {"&Make Same Size",0,nullptr,nullptr,FL_SUBMENU}, + {0}, + {"&Make Same Size",0,0,0,FL_SUBMENU}, {"&Width",0,(Fl_Callback *)align_widget_cb,(void*)30}, {"&Height",0,(Fl_Callback *)align_widget_cb,(void*)31}, {"&Both",0,(Fl_Callback *)align_widget_cb,(void*)32}, - {nullptr}, - {"&Center In Group",0,nullptr,nullptr,FL_SUBMENU}, + {0}, + {"&Center In Group",0,0,0,FL_SUBMENU}, {"&Horizontal",0,(Fl_Callback *)align_widget_cb,(void*)40}, {"&Vertical",0,(Fl_Callback *)align_widget_cb,(void*)41}, - {nullptr}, - {"Synchronized Resize", 0, (Fl_Callback*)menu_layout_sync_resize_cb, nullptr, FL_MENU_TOGGLE|FL_MENU_DIVIDER }, - {"&Grid and Size Settings...",FL_COMMAND+'g',show_grid_cb, nullptr, FL_MENU_DIVIDER}, + {0}, + {"Synchronized Resize", 0, (Fl_Callback*)menu_layout_sync_resize_cb, 0, FL_MENU_TOGGLE|FL_MENU_DIVIDER }, + {"&Grid and Size Settings...",FL_COMMAND+'g',show_grid_cb, 0, FL_MENU_DIVIDER}, {"Presets", 0, layout_suite_marker, (void*)main_layout_submenu_, FL_SUBMENU_POINTER }, - {"Application", 0, select_layout_preset_cb, (void*)nullptr, FL_MENU_RADIO|FL_MENU_VALUE }, + {"Application", 0, select_layout_preset_cb, (void*)0, FL_MENU_RADIO|FL_MENU_VALUE }, {"Dialog", 0, select_layout_preset_cb, (void*)1, FL_MENU_RADIO }, {"Toolbox", 0, select_layout_preset_cb, (void*)2, FL_MENU_RADIO }, - {nullptr}, + {0}, {"&Shell", 0, Fd_Shell_Command_List::menu_marker, (void*)Fd_Shell_Command_List::default_menu, FL_SUBMENU_POINTER}, - {"&Help",0,nullptr,nullptr,FL_SUBMENU}, + {"&Help",0,0,0,FL_SUBMENU}, {"&Rapid development with FLUID...",0,help_cb}, - {"&FLTK Programmers Manual...",0,manual_cb, nullptr, FL_MENU_DIVIDER}, + {"&FLTK Programmers Manual...",0,manual_cb, 0, FL_MENU_DIVIDER}, {"&About FLUID...",0,about_cb}, - {nullptr}, -{nullptr}}; + {0}, +{0}}; /** Show or hide the code preview window. diff --git a/fluid/app/Snap_Action.cxx b/fluid/app/Snap_Action.cxx index 2ec7affad..51cdb9817 100644 --- a/fluid/app/Snap_Action.cxx +++ b/fluid/app/Snap_Action.cxx @@ -112,13 +112,13 @@ static Layout_Suite static_suite_list[] = { Fl_Menu_Item main_layout_submenu_[] = { { static_suite_list[0].menu_label, 0, select_layout_suite_cb, (void*)0, FL_MENU_RADIO|FL_MENU_VALUE }, { static_suite_list[1].menu_label, 0, select_layout_suite_cb, (void*)1, FL_MENU_RADIO }, - { nullptr } + { 0 } }; static Fl_Menu_Item static_choice_menu[] = { { static_suite_list[0].menu_label }, { static_suite_list[1].menu_label }, - { nullptr } + { 0 } }; @@ -131,17 +131,17 @@ void layout_suite_marker(Fl_Widget *, void *) { void select_layout_suite_cb(Fl_Widget *, void *user_data) { int index = (int)(fl_intptr_t)user_data; assert(index >= 0); - assert(index < Fluid.layout_list.list_size_); - Fluid.layout_list.current_suite(index); - Fluid.layout_list.update_dialogs(); + assert(index < Fluid.layout_list->list_size_); + Fluid.layout_list->current_suite(index); + Fluid.layout_list->update_dialogs(); } void select_layout_preset_cb(Fl_Widget *, void *user_data) { int index = (int)(fl_intptr_t)user_data; assert(index >= 0); assert(index < 3); - Fluid.layout_list.current_preset(index); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->current_preset(index); + Fluid.layout_list->update_dialogs(); } void edit_layout_preset_cb(Fl_Button *w, void *user_data) { @@ -149,10 +149,10 @@ void edit_layout_preset_cb(Fl_Button *w, void *user_data) { assert(index >= 0); assert(index < 3); if (user_data == LOAD) { - w->value(Fluid.layout_list.current_preset() == index); + w->value(Fluid.layout_list->current_preset() == index); } else { - Fluid.layout_list.current_preset(index); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->current_preset(index); + Fluid.layout_list->update_dialogs(); } } @@ -412,7 +412,7 @@ void Layout_Suite::update_label() { if (menu_label) ::free(menu_label); menu_label = fl_strdup(sym.c_str()); - Fluid.layout_list.update_menu_labels(); + Fluid.layout_list->update_menu_labels(); } /** @@ -425,7 +425,7 @@ void Layout_Suite::name(const char *n) { if (n) name_ = fl_strdup(n); else - name_ = nullptr; + name_ = 0; update_label(); } @@ -433,9 +433,9 @@ void Layout_Suite::name(const char *n) { Initialize the class for first use. */ void Layout_Suite::init() { - name_ = nullptr; - menu_label = nullptr; - layout[0] = layout[1] = layout[2] = nullptr; + name_ = 0; + menu_label = 0; + layout[0] = layout[1] = layout[2] = 0; storage_ = FLD_TOOL_STORE_INTERNAL; } @@ -630,7 +630,7 @@ Layout_List::~Layout_List() { Update the Setting dialog and menus to reflect the current Layout selection state. */ void Layout_List::update_dialogs() { - static Fl_Menu_Item *preset_menu = nullptr; + static Fl_Menu_Item *preset_menu = 0; if (!preset_menu) { preset_menu = (Fl_Menu_Item*)Fluid.main_menubar->find_item(select_layout_preset_cb); assert(preset_menu); @@ -665,7 +665,7 @@ void Layout_List::update_menu_labels() { */ int Layout_List::load(const std::string &filename) { remove_all(FLD_TOOL_STORE_FILE); - Fl_Preferences prefs(filename.c_str(), "layout.fluid.fltk.org", nullptr, Fl_Preferences::C_LOCALE); + Fl_Preferences prefs(filename.c_str(), "layout.fluid.fltk.org", 0, Fl_Preferences::C_LOCALE); read(prefs, FLD_TOOL_STORE_FILE); return 0; } @@ -675,7 +675,7 @@ int Layout_List::load(const std::string &filename) { */ int Layout_List::save(const std::string &filename) { assert(this); - Fl_Preferences prefs(filename.c_str(), "layout.fluid.fltk.org", nullptr, (Fl_Preferences::Root)(Fl_Preferences::C_LOCALE|Fl_Preferences::CLEAR)); + Fl_Preferences prefs(filename.c_str(), "layout.fluid.fltk.org", 0, (Fl_Preferences::Root)(Fl_Preferences::C_LOCALE|Fl_Preferences::CLEAR)); prefs.clear(); write(prefs, FLD_TOOL_STORE_FILE); return 0; @@ -829,7 +829,7 @@ void Layout_List::current_preset(int ix) { Allocate enough space for n entries in the list. */ void Layout_List::capacity(int n) { - static Fl_Menu_Item *suite_menu = nullptr; + static Fl_Menu_Item *suite_menu = 0; if (!suite_menu) suite_menu = (Fl_Menu_Item*)Fluid.main_menubar->find_item(layout_suite_marker); @@ -1467,11 +1467,11 @@ class Fd_Snap_Sibling : public Snap_Action { protected: Fl_Widget *best_match; public: - Fd_Snap_Sibling() : best_match(nullptr) { } + Fd_Snap_Sibling() : best_match(0) { } virtual int sibling_check(Snap_Data &d, Fl_Widget *s) = 0; void check(Snap_Data &d) override { clr(); - best_match = nullptr; + best_match = 0; if (!d.wgt) return; if (!d.wgt->parent->is_a(FLD_NODE_TYPE_Group)) return; int dsib_min = 1024; @@ -1707,7 +1707,7 @@ Snap_Action *Snap_Action::list[] = { &snap_widget_ideal_width, &snap_widget_ideal_height, - nullptr + 0 }; // ---- draw alignment marks ------------------------------------------- MARK: - diff --git a/fluid/app/args.cxx b/fluid/app/args.cxx index b9d958e8c..70faebafc 100644 --- a/fluid/app/args.cxx +++ b/fluid/app/args.cxx @@ -22,8 +22,21 @@ #include <FL/filename.H> #include <FL/fl_ask.H> -using namespace fld; -using namespace fld::app; +#include <string.h> +#include "../src/flstring.h" + + +fld::app::Args::Args() +: update_file(0), + compile_file(0), + compile_strings(0), + show_version(0) +{ + code_filename[0] = '\0'; + header_filename[0] = '\0'; + autodoc_path[0] = '\0'; +} + /** Load args from command line into variables. @@ -33,12 +46,12 @@ using namespace fld::app; \return 0 if the args were handled successfully, -1 if there was an error and the usage message was shown. */ -int Args::load(int argc,char **argv) { +int fld::app::Args::load(int argc, char **argv) { int i = 1; Fl::args_to_utf8(argc, argv); // for MSYS2/MinGW - if ( (Fl::args(argc,argv,i,arg_cb) == 0) // unsupported argument found - || (Fluid.batch_mode && (i != argc-1)) // .fl filename missing - || (!Fluid.batch_mode && (i < argc-1)) // more than one filename found + if ( (Fl::args(argc, argv, i, arg_cb) == 0) // unsupported argument found + || (Fluid.batch_mode && (i != argc - 1)) // .fl filename missing + || (!Fluid.batch_mode && (i < argc - 1)) // more than one filename found || (argv[i] && (argv[i][0] == '-'))) { // unknown option static const char *msg = "usage: %s <switches> name.fl\n" @@ -50,13 +63,12 @@ int Args::load(int argc,char **argv) { " --help : brief usage information\n" " --version, -v : print fluid version number\n" " -d : enable internal debugging\n"; - const char *app_name = nullptr; - if ( (argc > 0) && argv[0] && argv[0][0] ) + const char *app_name = 0; + if ((argc > 0) && argv[0] && argv[0][0]) app_name = fl_filename_name(argv[0]); - if ( !app_name || !app_name[0]) + if (!app_name || !app_name[0]) app_name = "fluid"; #ifdef _MSC_VER - // TODO: if this is fluid-cmd, use stderr and not fl_message fl_message(msg, app_name); #else fprintf(stderr, msg, app_name); @@ -67,7 +79,7 @@ int Args::load(int argc,char **argv) { } -int Args::arg_cb(int argc, char** argv, int& i) { +int fld::app::Args::arg_cb(int argc, char** argv, int& i) { return Fluid.args.arg(argc, argv, i); } @@ -79,11 +91,11 @@ int Args::arg_cb(int argc, char** argv, int& i) { \param[inout] i current argument index \return number of arguments used; if 0, the argument is not supported */ -int Args::arg(int argc, char** argv, int& i) { +int fld::app::Args::arg(int argc, char** argv, int& i) { if (argv[i][0] != '-') return 0; if (argv[i][1] == 'd' && !argv[i][2]) { - Fluid.debug_external_editor=1; + Fluid.debug_external_editor = 1; i++; return 1; } if (argv[i][1] == 'u' && !argv[i][2]) { @@ -96,7 +108,7 @@ int Args::arg(int argc, char** argv, int& i) { Fluid.batch_mode++; i++; return 1; } - if ((strcmp(argv[i], "-v")==0) || (strcmp(argv[i], "--version")==0)) { + if ((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--version") == 0)) { show_version = 1; i++; return 1; } @@ -106,31 +118,29 @@ int Args::arg(int argc, char** argv, int& i) { Fluid.batch_mode++; i++; return 1; } - if (argv[i][1] == 'o' && !argv[i][2] && i+1 < argc) { - code_filename = argv[i+1]; + if (argv[i][1] == 'o' && !argv[i][2] && i + 1 < argc) { + strlcpy(code_filename, argv[i + 1], FL_PATH_MAX); Fluid.batch_mode++; i += 2; return 2; } #ifndef NDEBUG - if ((i+1 < argc) && (strcmp(argv[i], "--autodoc") == 0)) { - autodoc_path = argv[i+1]; + if ((i + 1 < argc) && (strcmp(argv[i], "--autodoc") == 0)) { + strlcpy(autodoc_path, argv[i + 1], FL_PATH_MAX); i += 2; return 2; } #endif - if (strcmp(argv[i], "--help")==0) { + if (strcmp(argv[i], "--help") == 0) { return 0; } if (argv[i][1] == 'h' && !argv[i][2]) { - if ( (i+1 < argc) && (argv[i+1][0] != '-') ) { - header_filename = argv[i+1]; + if ((i + 1 < argc) && (argv[i + 1][0] != '-')) { + strlcpy(header_filename, argv[i + 1], FL_PATH_MAX); Fluid.batch_mode++; i += 2; return 2; } else { - // a lone "-h" without a filename will output the help string return 0; } } return 0; } - diff --git a/fluid/app/args.h b/fluid/app/args.h index 80dfa2290..1165c4f58 100644 --- a/fluid/app/args.h +++ b/fluid/app/args.h @@ -17,7 +17,7 @@ #ifndef FLUID_APP_ARGS_H #define FLUID_APP_ARGS_H -#include <string> +#include <FL/filename.H> namespace fld { namespace app { @@ -29,21 +29,21 @@ class Args { int arg(int argc, char** argv, int& i); public: /// Set, if Fluid was started with the command line argument -u - int update_file { 0 }; // fluid -u + int update_file; /// Set, if Fluid was started with the command line argument -c - int compile_file { 0 }; // fluid -c + int compile_file; /// Set, if Fluid was started with the command line argument -cs - int compile_strings { 0 }; // fluid -cs + int compile_strings; /// command line arguments that overrides the generate code file extension or name - std::string code_filename { }; // fluid -o filename + char code_filename[FL_PATH_MAX]; /// command line arguments that overrides the generate header file extension or name - std::string header_filename { }; // fluid -h filename + char header_filename[FL_PATH_MAX]; /// if set, generate images for automatic documentation in this directory - std::string autodoc_path { }; // fluid --autodoc path + char autodoc_path[FL_PATH_MAX]; /// Set, if Fluid was started with the command line argument -v - int show_version { 0 }; // fluid -v + int show_version; /// Constructor. - Args() = default; + Args(); // Load args from command line into variables. int load(int argc, char **argv); }; @@ -52,4 +52,3 @@ public: } // namespace fld #endif // FLUID_APP_ARGS_H - diff --git a/fluid/app/history.cxx b/fluid/app/history.cxx index 7eadb5469..91b2f0b99 100644 --- a/fluid/app/history.cxx +++ b/fluid/app/history.cxx @@ -17,11 +17,20 @@ #include "app/history.h" #include "Fluid.h" +#include "tools/filename.h" #include "../src/flstring.h" -using namespace fld; -using namespace fld::app; + +fld::app::History::History() { + int i, j; + for (i = 0; i < 10; i++) { + for (j = 0; j < FL_PATH_MAX; j++) { + abspath[i][j] = '\0'; + relpath[i][j] = '\0'; + } + } +} /** @@ -31,25 +40,23 @@ using namespace fld::app; It also computes and stores the relative filepaths for display in the main menu. */ -void History::load() { - int i; // Looping var - int max_files; +void fld::app::History::load() { + int i; + int max_files; Fluid.preferences.get("recent_files", max_files, 5); if (max_files > 10) max_files = 10; - for (i = 0; i < max_files; i ++) { - Fluid.preferences.get( Fl_Preferences::Name("file%d", i), abspath[i], "", sizeof(abspath[i])); + for (i = 0; i < max_files; i++) { + Fluid.preferences.get(Fl_Preferences::Name("file%d", i), abspath[i], "", sizeof(abspath[i])); if (abspath[i][0]) { - // Make a shortened version of the filename for the menu... - std::string fn = fl_filename_shortened(abspath[i], 48); - strncpy(relpath[i], fn.c_str(), sizeof(relpath[i]) - 1); + fl_filename_shortened(relpath[i], sizeof(relpath[i]), abspath[i], 48); if (i == 9) Fluid.history_item[i].flags = FL_MENU_DIVIDER; else Fluid.history_item[i].flags = 0; } else break; } - for (; i < 10; i ++) { + for (; i < 10; i++) { if (i) Fluid.history_item[i-1].flags |= FL_MENU_DIVIDER; Fluid.history_item[i].hide(); } @@ -64,19 +71,24 @@ void History::load() { \param[in] project_file path and filename of .fl project file, will be converted into an absolute file path based on the current working directory. */ -void History::update(std::string project_file) { - int i; // Looping var - int max_files; +void fld::app::History::update(const char *project_file) { + int i; + int max_files; + + if (!project_file || !project_file[0]) return; Fluid.preferences.get("recent_files", max_files, 5); if (max_files > 10) max_files = 10; - std::string absolute = fld::fix_separators(fl_filename_absolute_str(project_file)); - for (i = 0; i < max_files; i ++) + char absolute[FL_PATH_MAX]; + fl_filename_absolute(absolute, FL_PATH_MAX, project_file); + fld_fix_separators(absolute); + + for (i = 0; i < max_files; i++) #if defined(_WIN32) || defined(__APPLE__) - if (!strcasecmp(absolute.c_str(), abspath[i])) break; + if (!strcasecmp(absolute, abspath[i])) break; #else - if (!strcmp(absolute.c_str(), abspath[i])) break; + if (!strcmp(absolute, abspath[i])) break; #endif // _WIN32 || __APPLE__ // Does the first entry match? @@ -92,24 +104,22 @@ void History::update(std::string project_file) { memmove(relpath + 1, relpath, i * sizeof(relpath[0])); // Put the new file at the top... - strlcpy(abspath[0], absolute.c_str(), sizeof(abspath[0])); - std::string fn = fl_filename_shortened(absolute, 48); - strncpy(relpath[0], fn.c_str(), sizeof(relpath[0]) - 1); + strlcpy(abspath[0], absolute, sizeof(abspath[0])); + fl_filename_shortened(relpath[0], sizeof(relpath[0]), absolute, 48); // Update the menu items as needed... - for (i = 0; i < max_files; i ++) { - Fluid.preferences.set( Fl_Preferences::Name("file%d", i), abspath[i]); + for (i = 0; i < max_files; i++) { + Fluid.preferences.set(Fl_Preferences::Name("file%d", i), abspath[i]); if (abspath[i][0]) { if (i == 9) Fluid.history_item[i].flags = FL_MENU_DIVIDER; else Fluid.history_item[i].flags = 0; } else break; } - for (; i < 10; i ++) { - Fluid.preferences.set( Fl_Preferences::Name("file%d", i), ""); + for (; i < 10; i++) { + Fluid.preferences.set(Fl_Preferences::Name("file%d", i), ""); if (i) Fluid.history_item[i-1].flags |= FL_MENU_DIVIDER; Fluid.history_item[i].hide(); } Fluid.preferences.flush(); } - diff --git a/fluid/app/history.h b/fluid/app/history.h index e32723b4b..99200757a 100644 --- a/fluid/app/history.h +++ b/fluid/app/history.h @@ -17,8 +17,6 @@ #ifndef FLUID_APP_HISTORY_H #define FLUID_APP_HISTORY_H -#include <tools/filename.h> - #include <FL/filename.H> namespace fld { @@ -27,19 +25,18 @@ namespace app { class History { public: /// Stores the absolute filename of the last 10 project files, saved in app preferences. - char abspath[10][FL_PATH_MAX] { }; + char abspath[10][FL_PATH_MAX]; /// The list of filenames as displayed in the main menu. - char relpath[10][FL_PATH_MAX] { }; + char relpath[10][FL_PATH_MAX]; // Create the project file history. - History() = default; + History(); // Load the project history from the preferences database. void load(); // Add a new file to the project history using absolute paths. - void update(std::string project_file); + void update(const char *project_file); }; } // namespace app } // namespace fld #endif // FLUID_APP_HISTORY_H - diff --git a/fluid/app/shell_command.cxx b/fluid/app/shell_command.cxx index 05bc28ec0..0a9a04121 100644 --- a/fluid/app/shell_command.cxx +++ b/fluid/app/shell_command.cxx @@ -1,5 +1,5 @@ // -// Shell Command database coe for the Fast Light Tool Kit (FLTK). +// Shell Command database code for the Fast Light Tool Kit (FLTK). // // Copyright 1998-2025 by Bill Spitzak and others. // @@ -14,87 +14,6 @@ // https://www.fltk.org/bugs.php // -// in progress: -// FLUID comes with example shell commands to build the current project file -// and run the project. This is accomplished by calling `fltk-config` on the -// files generated by FLUID, and by calling the executable directly. -// -// If the user wants more complex commands, he can add or modify them in the -// "Shell" settings panel. Modified shell commands are saved with the .fl -// file. - -// The Shell panel has a list of shell commands in the upper half. Under the -// list are buttons to add, duplicate, and delete shell commands. A popup -// menu offers import and export functionality and a list of sample scripts. -// We may want to add up and down buttons, so the user can change the -// order of commands. - -// Selecting any shell command in the list fills in and activates a list of -// options in the lower half of the panel. Those settings are: -// - Name: the name of the shell command in the list -// - Label: the label in the pulldown menu (could be the same as name?) -// - Shortcut: shortcut key to launch the command -// - Storage: where to store this shell command -// - Condition: pulldown menu to make the entry conditional for various -// target platforms, for example, a "Windows only" entry would only be added -// to the Shell menu on a Windows machine. Other options could be: -// - Linux only, macOS only, never (to make a list header!?), inactive? -// - Command: a multiline input for the actual shell command -// - Variables: a pulldown menu that insert variable names like $<sourcefile> -// - options to save project, code, and strings before running -// - test-run button - -// TODO: add @APPDIR@? -// TODO: get a macro to find `fltk-config` @FLTK_CONFIG@ -// TODO: add an input field so the user can insert their preferred file and path for fltk-config (user setting) -// `fltk-config` is actually tricky to find -// for live builds, we could check the program launch directory -// if we know where build/Xcode/bin/Debug/fluid is, we -// may or may not find ./build/Xcode/fltk-config -// on macOS with homebrew, we find /opt/homebrew/bin/fltk-config but the user -// can set their own install path. -// We can query the shell path, but that requires knowing the users shell (echo $SHELL). -// We can run the shell as a login shell with `-l`, so the user $PTH is set: /bin/bash -l -c 'fltk-config' -// The shell should output the path of the fltk-config that it found and why it is using that one. -// This can also output the fltk-config version. -// TODO: add a bunch of sensible sample shell commands -// TODO: when this new feature is used for the very first time, import two or three samples as initial user setting -// TODO: make the settings dialog resizable -// TODO: make g_shell_config static, not a pointer, but don't load anything in batch mode - -// FEATURE: fld::Tool_Store icons are currently redundant with @file and @save and could be improved -// FEATURE: hostname, username, getenv support? -// FEATURE: add the files ./fluid.prefs and ./fluid.user.prefs as tool locations -// FEATURE: interpret compiler output, for example: clang, and highlight errors and warnings -// `.../shell_command.cxx:71:2: error: test` -// `71 | #error test` -// `clang++: error: no such file or directory: '.../shell_command.o'` -// would make the error message clickable in the shell window and could select the widget, -// open the matching editor in the widget panel, and highlight the line in SourceView. - -/* - Some ideas: - - default shell is in $SHELL on linux and macOS - - On macOS, we can write Apple Scripts: - - #!/usr/bin/env osascript - say "@BASENAME@" - - osascript <<EOD - say "spark" - EOD - - osascript <<EOD - tell application "Xcode" - build workspace document 1 - end tell - EOD - - powershell -c "$wshell = New-Object -ComObject wscript.shell; $wshell.SendKeys('^{ESCAPE}') - */ - #include "app/shell_command.h" #include "Fluid.h" @@ -109,17 +28,15 @@ #include <FL/fl_string_functions.h> #include <errno.h> +#include <string.h> -using namespace fld; - -static std::string fltk_config_cmd; static Fl_Process s_proc; /** See if shell command is running (public) */ -bool shell_command_running() { - return s_proc.desc() ? true : false; +int shell_command_running() { + return s_proc.desc() ? 1 : 0; } /** \class Fl_Process @@ -130,13 +47,13 @@ bool shell_command_running() { Create a process manager */ Fl_Process::Fl_Process() { + _fpt = 0; } /** Destroy the project manager. */ Fl_Process::~Fl_Process() { - // TODO: check what we need to do if a task is still running if (_fpt) close(); } @@ -150,13 +67,13 @@ Fl_Process::~Fl_Process() { FILE * Fl_Process::popen(const char *cmd, const char *mode) { #if defined(_WIN32) && !defined(__CYGWIN__) // PRECONDITIONS - if (!mode || !*mode || (*mode!='r' && *mode!='w') ) return nullptr; + if (!mode || !*mode || (*mode!='r' && *mode!='w') ) return 0; if (_fpt) close(); // close first before reuse ptmode = *mode; pin[0] = pin[1] = pout[0] = pout[1] = perr[0] = perr[1] = INVALID_HANDLE_VALUE; // stderr to stdout wanted ? - int fusion = (strstr(cmd,"2>&1") !=nullptr); + int fusion = (strstr(cmd,"2>&1") != 0); // Create windows pipes if (!createPipe(pin) || !createPipe(pout) || (!fusion && !createPipe(perr) ) ) @@ -170,8 +87,8 @@ FILE * Fl_Process::popen(const char *cmd, const char *mode) { si.hStdOutput = pout[1]; si.hStdError = fusion ? pout[1] : perr [1]; - if ( CreateProcess(nullptr, (LPTSTR) cmd,nullptr,nullptr,TRUE, - DETACHED_PROCESS,nullptr,nullptr, &si, &pi)) { + if ( CreateProcess(0, (LPTSTR) cmd, 0, 0, TRUE, + DETACHED_PROCESS, 0, 0, &si, &pi)) { // don't need theses handles inherited by child process: clean_close(pin[0]); clean_close(pout[1]); clean_close(perr[1]); HANDLE & h = *mode == 'r' ? pout[0] : pin[1]; @@ -198,13 +115,13 @@ int Fl_Process::close() { clean_close(perr[0]); clean_close(pin[1]); clean_close(pout[0]); - _fpt = nullptr; + _fpt = 0; return 0; } return -1; #else int ret = ::pclose(_fpt); - _fpt=nullptr; + _fpt = 0; return ret; #endif } @@ -223,16 +140,14 @@ FILE *Fl_Process::desc() const { \param[out] line buffer to receive the line \param[in] s size of the provided buffer - \return nullptr if an error occurred, otherwise a pointer to the string + \return 0 if an error occurred, otherwise a pointer to the string */ char *Fl_Process::get_line(char * line, size_t s) const { - return _fpt ? fgets(line, (int)s, _fpt) : nullptr; + return _fpt ? fgets(line, (int)s, _fpt) : 0; } // returns fileno(FILE*): // (file must be open, i.e. _fpt must be non-null) -// *FIXME* we should find a better solution for the 'fileno' issue -// non null if file is open int Fl_Process::get_fileno() const { #ifdef _MSC_VER return _fileno(_fpt); // suppress MSVC warning @@ -243,19 +158,19 @@ int Fl_Process::get_fileno() const { #if defined(_WIN32) && !defined(__CYGWIN__) -bool Fl_Process::createPipe(HANDLE * h, BOOL bInheritHnd) { +int Fl_Process::createPipe(HANDLE * h, BOOL bInheritHnd) { SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(sa); - sa.lpSecurityDescriptor = nullptr; + sa.lpSecurityDescriptor = 0; sa.bInheritHandle = bInheritHnd; - return CreatePipe (&h[0],&h[1],&sa,0) ? true : false; + return CreatePipe (&h[0],&h[1],&sa,0) ? 1 : 0; } FILE *Fl_Process::freeHandles() { clean_close(pin[0]); clean_close(pin[1]); clean_close(pout[0]); clean_close(pout[1]); clean_close(perr[0]); clean_close(perr[1]); - return nullptr; // convenient for error management + return 0; // convenient for error management } void Fl_Process::clean_close(HANDLE& h) { @@ -270,24 +185,23 @@ void Fl_Process::clean_close(HANDLE& h) { Prepare FLUID for running a shell command according to the command flags. \param[in] flags set various flags to save the project, code, and string before running the command - \return false if the previous command is still running + \return 0 if the previous command is still running */ -static bool prepare_shell_command(int flags) { -// settings_window->hide(); +static int prepare_shell_command(int flags) { if (s_proc.desc()) { fl_alert("Previous shell command still running!"); - return false; + return 0; } if (flags & Fd_Shell_Command::SAVE_PROJECT) { - Fluid.save_project_file(nullptr); + Fluid.save_project_file(0); } if (flags & Fd_Shell_Command::SAVE_SOURCECODE) { - Fluid.write_code_files(true); + Fluid.write_code_files(1); } if (flags & Fd_Shell_Command::SAVE_STRINGS) { Fluid.proj.write_strings(); } - return true; + return 1; } /** @@ -312,7 +226,7 @@ void shell_timer_cb(void*) { void shell_pipe_cb(FL_SOCKET, void*) { char line[1024]=""; // Line from command output... - if (s_proc.get_line(line, sizeof(line)) != nullptr) { + if (s_proc.get_line(line, sizeof(line)) != 0) { // Add the line to the output list... shell_run_terminal->append(line); } else { @@ -324,38 +238,77 @@ void shell_pipe_cb(FL_SOCKET, void*) { } } -/** Find the script `fltk-config` that most closely relates to this version of FLUID. - This is not implemented yet. +/** + Replace all occurrences of a macro with the given content. + + \param[inout] cmd buffer holding the command (must have enough space) + \param[in] cmd_size size of the command buffer + \param[in] macro the macro string to replace (e.g., "@BASENAME@") + \param[in] content the replacement string */ -//static void find_fltk_config() { -// -//} +static void expand_macro(char *cmd, int cmd_size, const char *macro, const char *content) { + char *pos; + int macro_len; + int content_len; + int tail_len; + + if (!cmd || !macro || !content) return; + macro_len = (int)strlen(macro); + content_len = (int)strlen(content); -static void expand_macro(std::string &cmd, const std::string ¯o, const std::string &content) { - for (int i=0;;) { - i = (int)cmd.find(macro, i); - if (i==(int)std::string::npos) break; - cmd.replace(i, macro.size(), content); + while ((pos = strstr(cmd, macro)) != 0) { + tail_len = (int)strlen(pos + macro_len); + if ((pos - cmd) + content_len + tail_len >= cmd_size - 1) { + // Not enough space, truncate + break; + } + memmove(pos + content_len, pos + macro_len, tail_len + 1); + memcpy(pos, content, content_len); } } -static void expand_macros(std::string &cmd) { - expand_macro(cmd, "@BASENAME@", Fluid.proj.basename()); - expand_macro(cmd, "@PROJECTFILE_PATH@", Fluid.proj.projectfile_path()); - expand_macro(cmd, "@PROJECTFILE_NAME@", Fluid.proj.projectfile_name()); - expand_macro(cmd, "@CODEFILE_PATH@", Fluid.proj.codefile_path()); - expand_macro(cmd, "@CODEFILE_NAME@", Fluid.proj.codefile_name()); - expand_macro(cmd, "@HEADERFILE_PATH@", Fluid.proj.headerfile_path()); - expand_macro(cmd, "@HEADERFILE_NAME@", Fluid.proj.headerfile_name()); - expand_macro(cmd, "@TEXTFILE_PATH@", Fluid.proj.stringsfile_path()); - expand_macro(cmd, "@TEXTFILE_NAME@", Fluid.proj.stringsfile_name()); -// TODO: implement finding the script `fltk-config` for all platforms -// if (cmd.find("@FLTK_CONFIG@") != std::string::npos) { -// find_fltk_config(); -// expand_macro(cmd, "@FLTK_CONFIG@", fltk_config_cmd.c_str()); -// } - if (cmd.find("@TMPDIR@") != std::string::npos) - expand_macro(cmd, "@TMPDIR@", Fluid.get_tmpdir()); +/** + Expand all known macros in the command string. + + \param[inout] cmd buffer holding the command + \param[in] cmd_size size of the command buffer + */ +static void expand_macros(char *cmd, int cmd_size) { + char buf[FL_PATH_MAX]; + + Fluid.proj.basename(buf, FL_PATH_MAX); + expand_macro(cmd, cmd_size, "@BASENAME@", buf); + + Fluid.proj.projectfile_path(buf, FL_PATH_MAX); + expand_macro(cmd, cmd_size, "@PROJECTFILE_PATH@", buf); + + { + const char *name = Fluid.proj.projectfile_name(); + expand_macro(cmd, cmd_size, "@PROJECTFILE_NAME@", name ? name : ""); + } + + Fluid.proj.codefile_path(buf, FL_PATH_MAX); + expand_macro(cmd, cmd_size, "@CODEFILE_PATH@", buf); + + Fluid.proj.codefile_name(buf, FL_PATH_MAX); + expand_macro(cmd, cmd_size, "@CODEFILE_NAME@", buf); + + Fluid.proj.headerfile_path(buf, FL_PATH_MAX); + expand_macro(cmd, cmd_size, "@HEADERFILE_PATH@", buf); + + Fluid.proj.headerfile_name(buf, FL_PATH_MAX); + expand_macro(cmd, cmd_size, "@HEADERFILE_NAME@", buf); + + Fluid.proj.stringsfile_path(buf, FL_PATH_MAX); + expand_macro(cmd, cmd_size, "@TEXTFILE_PATH@", buf); + + Fluid.proj.stringsfile_name(buf, FL_PATH_MAX); + expand_macro(cmd, cmd_size, "@TEXTFILE_NAME@", buf); + + if (strstr(cmd, "@TMPDIR@") != 0) { + const char *tmpdir = Fluid.get_tmpdir(); + expand_macro(cmd, cmd_size, "@TMPDIR@", tmpdir ? tmpdir : ""); + } } /** @@ -374,22 +327,26 @@ void show_terminal_window() { shell_run_window->show(); } +#define SHELL_CMD_BUF_SIZE 4096 + /** Prepare for and run a shell command. \param[in] cmd the command that is sent to `/bin/sh -c ...` or `cmd.exe` on Windows machines \param[in] flags various flags in preparation of the command */ -void run_shell_command(const std::string &cmd, int flags) { - if (cmd.empty()) { +void run_shell_command(const char *cmd, int flags) { + char expanded_cmd[SHELL_CMD_BUF_SIZE]; + + if (!cmd || !cmd[0]) { fl_alert("No shell command entered!"); return; } if (!prepare_shell_command(flags)) return; - std::string expanded_cmd = cmd; - expand_macros(expanded_cmd); + strlcpy(expanded_cmd, cmd, sizeof(expanded_cmd)); + expand_macros(expanded_cmd, sizeof(expanded_cmd)); if ( ((flags & Fd_Shell_Command::DONT_SHOW_TERMINAL) == 0) && (!shell_run_window->visible())) @@ -403,10 +360,10 @@ void run_shell_command(const std::string &cmd, int flags) { if (flags & Fd_Shell_Command::CLEAR_HISTORY) shell_run_terminal->printf("\033[3J"); shell_run_terminal->scrollbar->value(0); - shell_run_terminal->printf("\033[0;32m%s\033[0m\n", expanded_cmd.c_str()); - shell_run_window->label(expanded_cmd.c_str()); + shell_run_terminal->printf("\033[0;32m%s\033[0m\n", expanded_cmd); + shell_run_window->label(expanded_cmd); - if (s_proc.popen((char *)expanded_cmd.c_str()) == nullptr) { + if (s_proc.popen(expanded_cmd, "r") == 0) { shell_run_terminal->printf("\033[1;31mUnable to run shell command: %s\033[0m\n", strerror(errno)); shell_run_window->label("FLUID Shell"); @@ -421,15 +378,24 @@ void run_shell_command(const std::string &cmd, int flags) { Fl::add_fd(s_proc.get_fileno(), shell_pipe_cb); } +// Helper to duplicate a string safely +static char *dup_str(const char *s) { + return s ? strdup(s) : 0; +} + /** Create an empty shell command structure. */ Fd_Shell_Command::Fd_Shell_Command() -: shortcut(0), +: name(0), + label(0), + shortcut(0), storage(FLD_TOOL_STORE_USER), condition(0), + condition_data(0), + command(0), flags(0), - shell_menu_item_(nullptr) + shell_menu_item_(0) { } @@ -439,75 +405,94 @@ Fd_Shell_Command::Fd_Shell_Command() \param[in] rhs copy from this prototype */ Fd_Shell_Command::Fd_Shell_Command(const Fd_Shell_Command *rhs) -: name(rhs->name), - label(rhs->label), +: name(dup_str(rhs->name)), + label(dup_str(rhs->label)), shortcut(rhs->shortcut), storage(rhs->storage), condition(rhs->condition), - condition_data(rhs->condition_data), - command(rhs->command), + condition_data(dup_str(rhs->condition_data)), + command(dup_str(rhs->command)), flags(rhs->flags), - shell_menu_item_(nullptr) + shell_menu_item_(0) { } /** Create a default storage for a shell command and how it is accessible in FLUID. - \param[in] name is used as a stand-in for the command name and label + \param[in] in_name is used as a stand-in for the command name and label */ -Fd_Shell_Command::Fd_Shell_Command(const std::string &in_name) -: name(in_name), - label(in_name), +Fd_Shell_Command::Fd_Shell_Command(const char *in_name) +: name(dup_str(in_name)), + label(dup_str(in_name)), shortcut(0), storage(FLD_TOOL_STORE_USER), condition(Fd_Shell_Command::ALWAYS), - command("echo \"Hello, FLUID!\""), + condition_data(0), + command(strdup("echo \"Hello, FLUID!\"")), flags(Fd_Shell_Command::SAVE_PROJECT|Fd_Shell_Command::SAVE_SOURCECODE), - shell_menu_item_(nullptr) + shell_menu_item_(0) { } /** Create a storage for a shell command and how it is accessible in FLUID. - - \param[in] in_name name of this command in the command list in the settings panel - \param[in] in_label label text in the main pulldown menu - \param[in] in_shortcut a keyboard shortcut that will also appear in the main menu - \param[in] in_storage storage location for this command - \param[in] in_condition commands can be hidden for certain platforms by setting a condition - \param[in] in_condition_data more details for future conditions, i.e. per user, per host, etc. - \param[in] in_command the shell command that we want to run - \param[in] in_flags some flags to tell FLUID to save the project, code, or strings before running the command - */ -Fd_Shell_Command::Fd_Shell_Command(const std::string &in_name, - const std::string &in_label, + */ +Fd_Shell_Command::Fd_Shell_Command(const char *in_name, + const char *in_label, Fl_Shortcut in_shortcut, fld::Tool_Store in_storage, int in_condition, - const std::string &in_condition_data, - const std::string &in_command, + const char *in_condition_data, + const char *in_command, int in_flags) -: name(in_name), - label(in_label), +: name(dup_str(in_name)), + label(dup_str(in_label)), shortcut(in_shortcut), storage(in_storage), condition(in_condition), - condition_data(in_condition_data), - command(in_command), + condition_data(dup_str(in_condition_data)), + command(dup_str(in_command)), flags(in_flags), - shell_menu_item_(nullptr) + shell_menu_item_(0) { } /** - Run this command now. + Destructor - free all allocated strings. + */ +Fd_Shell_Command::~Fd_Shell_Command() { + if (name) free(name); + if (label) free(label); + if (condition_data) free(condition_data); + if (command) free(command); +} + +void Fd_Shell_Command::set_name(const char *s) { + if (name) free(name); + name = dup_str(s); +} + +void Fd_Shell_Command::set_label(const char *s) { + if (label) free(label); + label = dup_str(s); +} + +void Fd_Shell_Command::set_condition_data(const char *s) { + if (condition_data) free(condition_data); + condition_data = dup_str(s); +} + +void Fd_Shell_Command::set_command(const char *s) { + if (command) free(command); + command = dup_str(s); +} - Will open the Shell Panel and execute the command if no other command is - currently running. +/** + Run this command now. */ void Fd_Shell_Command::run() { - if (!command.empty()) + if (command && command[0]) run_shell_command(command, flags); } @@ -516,9 +501,9 @@ void Fd_Shell_Command::run() { */ void Fd_Shell_Command::update_shell_menu() { if (shell_menu_item_) { - const char *old_label = shell_menu_item_->label(); // can be nullptr - const char *new_label = label.c_str(); // never nullptr - if (!old_label || (old_label && strcmp(old_label, new_label))) { + const char *old_label = shell_menu_item_->label(); // can be 0 + const char *new_label = label ? label : ""; + if (!old_label || strcmp(old_label, new_label)) { if (old_label) ::free((void*)old_label); shell_menu_item_->label(fl_strdup(new_label)); } @@ -529,66 +514,75 @@ void Fd_Shell_Command::update_shell_menu() { /** Check if the set condition is met. - \return true if this command appears in the main menu + \return 1 if this command appears in the main menu */ -bool Fd_Shell_Command::is_active() { +int Fd_Shell_Command::is_active() { switch (condition) { - case ALWAYS: return true; - case NEVER: return false; + case ALWAYS: return 1; + case NEVER: return 0; #ifdef _WIN32 - case MAC_ONLY: return false; - case UX_ONLY: return false; - case WIN_ONLY: return true; - case MAC_AND_UX_ONLY: return false; + case MAC_ONLY: return 0; + case UX_ONLY: return 0; + case WIN_ONLY: return 1; + case MAC_AND_UX_ONLY: return 0; #elif defined(__APPLE__) - case MAC_ONLY: return true; - case UX_ONLY: return false; - case WIN_ONLY: return false; - case MAC_AND_UX_ONLY: return true; + case MAC_ONLY: return 1; + case UX_ONLY: return 0; + case WIN_ONLY: return 0; + case MAC_AND_UX_ONLY: return 1; #else - case MAC_ONLY: return false; - case UX_ONLY: return true; - case WIN_ONLY: return false; - case MAC_AND_UX_ONLY: return true; + case MAC_ONLY: return 0; + case UX_ONLY: return 1; + case WIN_ONLY: return 0; + case MAC_AND_UX_ONLY: return 1; #endif - case USER_ONLY: return false; // TODO: get user name - case HOST_ONLY: return false; // TODO: get host name + case USER_ONLY: return 0; // TODO: get user name + case HOST_ONLY: return 0; // TODO: get host name case ENV_ONLY: { - const char *value = fl_getenv(condition_data.c_str()); - if (value && *value) return true; - return false; + const char *value = condition_data ? fl_getenv(condition_data) : 0; + if (value && *value) return 1; + return 0; } } - return false; + return 0; } void Fd_Shell_Command::read(Fl_Preferences &prefs) { int tmp; char *str_ptr = 0; prefs.get("name", str_ptr, "<unnamed>"); - if (str_ptr) { name = str_ptr; free(str_ptr); str_ptr = 0; } + set_name(str_ptr); + if (str_ptr) { free(str_ptr); str_ptr = 0; } + prefs.get("label", str_ptr, "<no label>"); - if (str_ptr) { label = str_ptr; free(str_ptr); str_ptr = 0; } + set_label(str_ptr); + if (str_ptr) { free(str_ptr); str_ptr = 0; } + prefs.get("shortcut", tmp, 0); shortcut = (Fl_Shortcut)tmp; prefs.get("storage", tmp, -1); if (tmp != -1) storage = (fld::Tool_Store)tmp; prefs.get("condition", condition, ALWAYS); + prefs.get("condition_data", str_ptr, ""); - if (str_ptr) { condition_data = str_ptr; free(str_ptr); str_ptr = 0; } + set_condition_data(str_ptr); + if (str_ptr) { free(str_ptr); str_ptr = 0; } + prefs.get("command", str_ptr, ""); - if (str_ptr) { command = str_ptr; free(str_ptr); str_ptr = 0; } + set_command(str_ptr); + if (str_ptr) { free(str_ptr); str_ptr = 0; } + prefs.get("flags", flags, 0); } -void Fd_Shell_Command::write(Fl_Preferences &prefs, bool save_location) { - prefs.set("name", name.c_str()); - prefs.set("label", label.c_str()); +void Fd_Shell_Command::write(Fl_Preferences &prefs, int save_location) { + prefs.set("name", name ? name : ""); + prefs.set("label", label ? label : ""); if (shortcut != 0) prefs.set("shortcut", (int)shortcut); if (save_location) prefs.set("storage", (int)storage); if (condition != ALWAYS) prefs.set("condition", condition); - if (!condition_data.empty()) prefs.set("condition_data", condition_data.c_str()); - if (!command.empty()) prefs.set("command", command.c_str()); + if (condition_data && condition_data[0]) prefs.set("condition_data", condition_data); + if (command && command[0]) prefs.set("command", command); if (flags != 0) prefs.set("flags", flags); } @@ -600,17 +594,17 @@ void Fd_Shell_Command::read(class fld::io::Project_Reader *in) { c = in->read_word(1); if (strcmp(c, "}")==0) break; // end of command list else if (strcmp(c, "name")==0) - name = in->read_word(); + set_name(in->read_word()); else if (strcmp(c, "label")==0) - label = in->read_word(); + set_label(in->read_word()); else if (strcmp(c, "shortcut")==0) shortcut = in->read_int(); else if (strcmp(c, "condition")==0) condition = in->read_int(); else if (strcmp(c, "condition_data")==0) - condition_data = in->read_word(); + set_condition_data(in->read_word()); else if (strcmp(c, "command")==0) - command = in->read_word(); + set_command(in->read_word()); else if (strcmp(c, "flags")==0) flags = in->read_int(); else @@ -620,14 +614,14 @@ void Fd_Shell_Command::read(class fld::io::Project_Reader *in) { void Fd_Shell_Command::write(class fld::io::Project_Writer *out) { out->write_string("\n command {"); - out->write_string("\n name "); out->write_word(name); - out->write_string("\n label "); out->write_word(label); + out->write_string("\n name "); out->write_word(name ? name : ""); + out->write_string("\n label "); out->write_word(label ? label : ""); if (shortcut) out->write_string("\n shortcut %d", shortcut); if (condition) out->write_string("\n condition %d", condition); - if (!condition_data.empty()) { + if (condition_data && condition_data[0]) { out->write_string("\n condition_data "); out->write_word(condition_data); } - if (!command.empty()) { + if (command && command[0]) { out->write_string("\n command "); out->write_word(command); } if (flags) out->write_string("\n flags %d", flags); @@ -639,6 +633,10 @@ void Fd_Shell_Command::write(class fld::io::Project_Writer *out) { Manage a list of shell commands and their parameters. */ Fd_Shell_Command_List::Fd_Shell_Command_List() +: list(0), + list_size(0), + list_capacity(0), + shell_menu_(0) { } @@ -664,13 +662,14 @@ Fd_Shell_Command *Fd_Shell_Command_List::at(int index) const { */ void Fd_Shell_Command_List::clear() { if (list) { - for (int i=0; i<list_size; i++) { + int i; + for (i=0; i<list_size; i++) { delete list[i]; } ::free(list); list_size = 0; list_capacity = 0; - list = nullptr; + list = 0; } } @@ -678,7 +677,8 @@ void Fd_Shell_Command_List::clear() { remove all shell commands of the given storage location from the list. */ void Fd_Shell_Command_List::clear(fld::Tool_Store storage) { - for (int i=list_size-1; i>=0; i--) { + int i; + for (i=list_size-1; i>=0; i--) { if (list[i]->storage == storage) { remove(i); } @@ -689,6 +689,7 @@ void Fd_Shell_Command_List::clear(fld::Tool_Store storage) { Read shell configuration from a preferences group. */ void Fd_Shell_Command_List::read(Fl_Preferences &prefs, fld::Tool_Store storage) { + int i, n; // import the old shell commands from previous user settings if (&Fluid.preferences == &prefs) { int version; @@ -697,12 +698,12 @@ void Fd_Shell_Command_List::read(Fl_Preferences &prefs, fld::Tool_Store storage) int save_fl, save_code, save_strings; Fd_Shell_Command *cmd = new Fd_Shell_Command(); cmd->storage = FLD_TOOL_STORE_USER; - cmd->name = "Sample Shell Command"; - cmd->label = "Sample Shell Command"; + cmd->set_name("Sample Shell Command"); + cmd->set_label("Sample Shell Command"); cmd->shortcut = FL_ALT+'g'; char *cmd_str = 0; Fluid.preferences.get("shell_command", cmd_str, "echo \"Sample Shell Command\""); - if (cmd_str) { cmd->command = cmd_str; free(cmd_str); } + if (cmd_str) { cmd->set_command(cmd_str); free(cmd_str); } Fluid.preferences.get("shell_savefl", save_fl, 1); Fluid.preferences.get("shell_writecode", save_code, 1); Fluid.preferences.get("shell_writemsgs", save_strings, 0); @@ -715,8 +716,8 @@ void Fd_Shell_Command_List::read(Fl_Preferences &prefs, fld::Tool_Store storage) prefs.set("shell_commands_version", version); } Fl_Preferences shell_commands(prefs, "shell_commands"); - int n = shell_commands.groups(); - for (int i=0; i<n; i++) { + n = shell_commands.groups(); + for (i=0; i<n; i++) { Fl_Preferences cmd_prefs(shell_commands, Fl_Preferences::Name(i)); Fd_Shell_Command *cmd = new Fd_Shell_Command(); cmd->storage = FLD_TOOL_STORE_USER; @@ -729,13 +730,14 @@ void Fd_Shell_Command_List::read(Fl_Preferences &prefs, fld::Tool_Store storage) Write shell configuration to a preferences group. */ void Fd_Shell_Command_List::write(Fl_Preferences &prefs, fld::Tool_Store storage) { + int i, index; Fl_Preferences shell_commands(prefs, "shell_commands"); shell_commands.delete_all_groups(); - int index = 0; - for (int i=0; i<list_size; i++) { + index = 0; + for (i=0; i<list_size; i++) { if (list[i]->storage == FLD_TOOL_STORE_USER) { Fl_Preferences cmd(shell_commands, Fl_Preferences::Name(index++)); - list[i]->write(cmd); + list[i]->write(cmd, 0); } } } @@ -764,14 +766,14 @@ void Fd_Shell_Command_List::read(fld::io::Project_Reader *in) { Write shell configuration to a project file. */ void Fd_Shell_Command_List::write(fld::io::Project_Writer *out) { - int n_in_project_file = 0; - for (int i=0; i<list_size; i++) { + int i, n_in_project_file = 0; + for (i=0; i<list_size; i++) { if (list[i]->storage == FLD_TOOL_STORE_PROJECT) n_in_project_file++; } if (n_in_project_file > 0) { out->write_string("\nshell_commands {"); - for (int i=0; i<list_size; i++) { + for (i=0; i<list_size; i++) { if (list[i]->storage == FLD_TOOL_STORE_PROJECT) list[i]->write(out); } @@ -842,12 +844,14 @@ void menu_shell_customize_cb(Fl_Widget*, void*) { Rebuild the entire shell submenu from scratch and replace the old menu. */ void Fd_Shell_Command_List::rebuild_shell_menu() { - static Fl_Menu_Item *shell_submenu = nullptr; + static Fl_Menu_Item *shell_submenu = 0; + int i, j, num_active_items; + if (!shell_submenu) shell_submenu = (Fl_Menu_Item*)Fluid.main_menubar->find_item(menu_marker); - int i, j, num_active_items = 0; // count the active commands + num_active_items = 0; for (i=0; i<list_size; i++) { if (list[i]->is_active()) num_active_items++; } @@ -875,9 +879,9 @@ void Fd_Shell_Command_List::rebuild_shell_menu() { // free all resources from the old menu if (mi_old && (mi_old != default_menu)) { for (i=0; ; i++) { - const char *label = mi_old[i].label(); - if (!label) break; - ::free((void*)label); + const char *lbl = mi_old[i].label(); + if (!lbl) break; + ::free((void*)lbl); } ::free(mi_old); } @@ -896,7 +900,7 @@ void Fd_Shell_Command_List::update_settings_dialog() { */ Fl_Menu_Item Fd_Shell_Command_List::default_menu[] = { { "Customize...", FL_ALT+'x', menu_shell_customize_cb }, - { nullptr } + { 0 } }; /** @@ -908,12 +912,11 @@ void Fd_Shell_Command_List::menu_marker(Fl_Widget*, void*) { /** Export all selected shell commands to an external file. - - Verify that g_shell_config and w_settings_shell_list are not nullptr. Open a - file chooser and export all items that are selected in w_settings_shell_list - into an external file. */ void Fd_Shell_Command_List::export_selected() { + char path[FL_PATH_MAX]; + char preset[FL_PATH_MAX]; + if (!g_shell_config || (g_shell_config->list_size == 0)) return; if (!w_settings_shell_list) return; @@ -921,28 +924,37 @@ void Fd_Shell_Command_List::export_selected() { dialog.title("Export selected shell commands:"); dialog.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE); dialog.filter("FLUID Files\t*.flcmd\n"); - dialog.directory(Fluid.proj.projectfile_path().c_str()); - dialog.preset_file((Fluid.proj.basename() + ".flcmd").c_str()); + + Fluid.proj.projectfile_path(path, FL_PATH_MAX); + dialog.directory(path); + + Fluid.proj.basename(preset, FL_PATH_MAX); + strlcat(preset, ".flcmd", FL_PATH_MAX); + dialog.preset_file(preset); + if (dialog.show() != 0) return; - Fl_Preferences file(dialog.filename(), "flcmd.fluid.fltk.org", nullptr, (Fl_Preferences::Root)(Fl_Preferences::C_LOCALE|Fl_Preferences::CLEAR)); + Fl_Preferences file(dialog.filename(), "flcmd.fluid.fltk.org", 0, (Fl_Preferences::Root)(Fl_Preferences::C_LOCALE|Fl_Preferences::CLEAR)); Fl_Preferences shell_commands(file, "shell_commands"); - int i, index = 0, n = w_settings_shell_list->size(); + int i, index, n; + index = 0; + n = w_settings_shell_list->size(); for (i = 0; i < n; i++) { if (w_settings_shell_list->selected(i+1)) { Fl_Preferences cmd(shell_commands, Fl_Preferences::Name(index++)); - g_shell_config->list[i]->write(cmd, true); + g_shell_config->list[i]->write(cmd, 1); } } } /** Import shell commands from an external file and add them to the list. - - Verify that g_shell_config and w_settings_shell_list are not nullptr. Open a - file chooser and import all items. */ void Fd_Shell_Command_List::import_from_file() { + char path[FL_PATH_MAX]; + char preset[FL_PATH_MAX]; + int i, n; + if (!g_shell_config || (g_shell_config->list_size == 0)) return; if (!w_settings_shell_list) return; @@ -950,13 +962,19 @@ void Fd_Shell_Command_List::import_from_file() { dialog.title("Import shell commands:"); dialog.type(Fl_Native_File_Chooser::BROWSE_FILE); dialog.filter("FLUID Files\t*.flcmd\n"); - dialog.directory(Fluid.proj.projectfile_path().c_str()); - dialog.preset_file((Fluid.proj.basename() + ".flcmd").c_str()); + + Fluid.proj.projectfile_path(path, FL_PATH_MAX); + dialog.directory(path); + + Fluid.proj.basename(preset, FL_PATH_MAX); + strlcat(preset, ".flcmd", FL_PATH_MAX); + dialog.preset_file(preset); + if (dialog.show() != 0) return; - Fl_Preferences file(dialog.filename(), "flcmd.fluid.fltk.org", nullptr, Fl_Preferences::C_LOCALE); + Fl_Preferences file(dialog.filename(), "flcmd.fluid.fltk.org", 0, Fl_Preferences::C_LOCALE); Fl_Preferences shell_commands(file, "shell_commands"); - int i, n = shell_commands.groups(); + n = shell_commands.groups(); for (i = 0; i < n; i++) { Fl_Preferences cmd_prefs(shell_commands, Fl_Preferences::Name(i)); Fd_Shell_Command *cmd = new Fd_Shell_Command(); @@ -973,5 +991,4 @@ void Fd_Shell_Command_List::import_from_file() { /** A pointer to the list of shell commands if we are not in batch mode. */ -Fd_Shell_Command_List *g_shell_config = nullptr; - +Fd_Shell_Command_List *g_shell_config = 0; diff --git a/fluid/app/shell_command.h b/fluid/app/shell_command.h index b9e68ca15..716a87349 100644 --- a/fluid/app/shell_command.h +++ b/fluid/app/shell_command.h @@ -23,7 +23,6 @@ #include <stdio.h> #include <stdlib.h> -#include <string> #if defined(_WIN32) && !defined(__CYGWIN__) # include <direct.h> # include <windows.h> @@ -49,8 +48,8 @@ class Fl_Widget; class Fl_Preferences; void show_terminal_window(); -void run_shell_command(const std::string &cmd, int flags); -bool shell_command_running(void); +void run_shell_command(const char *cmd, int flags); +int shell_command_running(void); class Fl_Process { @@ -58,7 +57,7 @@ public: Fl_Process(); ~Fl_Process(); - FILE *popen(const char *cmd, const char *mode="r"); + FILE *popen(const char *cmd, const char *mode); int close(); FILE * desc() const; @@ -73,7 +72,7 @@ protected: PROCESS_INFORMATION pi; STARTUPINFO si; - static bool createPipe(HANDLE * h, BOOL bInheritHnd=TRUE); + static int createPipe(HANDLE * h, BOOL bInheritHnd); private: FILE * freeHandles(); @@ -81,7 +80,7 @@ private: #endif protected: - FILE * _fpt = nullptr; + FILE * _fpt; }; @@ -90,42 +89,51 @@ public: enum { ALWAYS, NEVER, MAC_ONLY, UX_ONLY, WIN_ONLY, MAC_AND_UX_ONLY, USER_ONLY, HOST_ONLY, ENV_ONLY }; // conditions enum { SAVE_PROJECT = 1, SAVE_SOURCECODE = 2, SAVE_STRINGS = 4, SAVE_ALL = 7, DONT_SHOW_TERMINAL = 8, CLEAR_TERMINAL = 16, CLEAR_HISTORY = 32 }; // flags + + char *name; + char *label; + Fl_Shortcut shortcut; + fld::Tool_Store storage; + int condition; + char *condition_data; + char *command; + int flags; + Fl_Menu_Item *shell_menu_item_; + Fd_Shell_Command(); Fd_Shell_Command(const Fd_Shell_Command *rhs); - Fd_Shell_Command(const std::string &in_name); - Fd_Shell_Command(const std::string &in_name, - const std::string &in_label, + Fd_Shell_Command(const char *in_name); + Fd_Shell_Command(const char *in_name, + const char *in_label, Fl_Shortcut in_shortcut, fld::Tool_Store in_storage, int in_condition, - const std::string &in_condition_data, - const std::string &in_command, + const char *in_condition_data, + const char *in_command, int in_flags); - std::string name { }; - std::string label { }; - Fl_Shortcut shortcut = 0; - fld::Tool_Store storage = FLD_TOOL_STORE_USER; - int condition = ALWAYS; // always, hide, windows only, linux only, mac only, user, machine - std::string condition_data { }; // user name, machine name - std::string command { }; - int flags = 0; // save_project, save_code, save_string, ... - Fl_Menu_Item *shell_menu_item_; + ~Fd_Shell_Command(); + + void set_name(const char *s); + void set_label(const char *s); + void set_condition_data(const char *s); + void set_command(const char *s); + void run(); void read(Fl_Preferences &prefs); - void write(Fl_Preferences &prefs, bool save_location = false); + void write(Fl_Preferences &prefs, int save_location); void read(class fld::io::Project_Reader*); void write(class fld::io::Project_Writer*); void update_shell_menu(); - bool is_active(); + int is_active(); }; class Fd_Shell_Command_List { public: - Fd_Shell_Command **list = nullptr; - int list_size = 0; - int list_capacity = 0; - Fl_Menu_Item *shell_menu_ = nullptr; + Fd_Shell_Command **list; + int list_size; + int list_capacity; + Fl_Menu_Item *shell_menu_; public: Fd_Shell_Command_List(); ~Fd_Shell_Command_List(); @@ -135,10 +143,6 @@ public: void remove(int index); void clear(); void clear(fld::Tool_Store store); -// void move_up(); -// void move_down(); -// int load(const std::string &filename); -// int save(const std::string &filename); void read(Fl_Preferences &prefs, fld::Tool_Store storage); void write(Fl_Preferences &prefs, fld::Tool_Store storage); void read(class fld::io::Project_Reader*); diff --git a/fluid/app/templates.cxx b/fluid/app/templates.cxx index 09fdc0220..8b9b69f2a 100644 --- a/fluid/app/templates.cxx +++ b/fluid/app/templates.cxx @@ -93,7 +93,7 @@ void fld::app::save_template() { if (!fl_access(filename, 0)) { if (fl_choice("The template \"%s\" already exists.\n" "Do you want to replace it?", "Cancel", - "Replace", nullptr, c) == 0) return; + "Replace", 0, c) == 0) return; } if (!fld::io::write_file(Fluid.proj, filename)) { @@ -117,7 +117,7 @@ void fld::app::save_template() { uchar *pixels; int w, h; - if ((pixels = wt->read_image(w, h)) == nullptr) return; + if ((pixels = wt->read_image(w, h)) == 0) return; // Save to a PNG file... strcpy(ext, ".png"); diff --git a/fluid/io/Code_Writer.cxx b/fluid/io/Code_Writer.cxx index 0998ed287..357db80dd 100644 --- a/fluid/io/Code_Writer.cxx +++ b/fluid/io/Code_Writer.cxx @@ -302,14 +302,14 @@ void Code_Writer::write_cstring(const char *s, int length) { } // if we are rendering to the source code preview window, and the text is // longer than four lines, we only render a placeholder. - if (write_codeview && ((s==nullptr) || (length>300))) { + if (write_codeview && ((s==0) || (length>300))) { if (length>=0) crc_printf("\" ... %d bytes of text... \"", length); else crc_puts("\" ... text... \""); return; } - if (length==-1 || s==nullptr) { + if (length==-1 || s==0) { crc_puts("\n#error string not found\n"); crc_puts("\" ... undefined size text... \""); return; @@ -639,7 +639,7 @@ Node* Code_Writer::write_code(Node* p) { } write_h("};\n"); - current_widget_class = nullptr; + current_widget_class = 0; } else { for (q = p->next; q && q->level > p->level;) q = write_code(q); // write all code that come after the children @@ -667,8 +667,8 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { write_codeview = to_codeview; unique_id_list.clear(); indentation = 0; - current_class = nullptr; - current_widget_class = nullptr; + current_class = 0; + current_widget_class = 0; if (!s) code_file = stdout; else { FILE *f = fl_fopen(s, "wb"); @@ -683,11 +683,16 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { } // Remember the last code file location for MergeBack if (s && proj_.write_mergeback_data && !to_codeview) { - std::string filename = proj_.projectfile_path() + proj_.projectfile_name(); - int i, n = (int)filename.size(); + char filename[FL_PATH_MAX]; + char path_buf[FL_PATH_MAX]; + int i, n; + proj_.projectfile_path(path_buf, FL_PATH_MAX); + const char *pname = proj_.projectfile_name(); + snprintf(filename, FL_PATH_MAX, "%s%s", path_buf, pname ? pname : ""); + n = (int)strlen(filename); for (i=0; i<n; i++) if (filename[i]=='\\') filename[i] = '/'; Fl_Preferences build_records(Fl_Preferences::USER_L, "fltk.org", "fluid-build"); - Fl_Preferences path(build_records, filename.c_str()); + Fl_Preferences path(build_records, filename); path.set("code", s); } // if the first entry in the Type tree is a comment, then it is probably @@ -723,16 +728,18 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { // // To make the include guard consistent across l=platforms, it can be // explicitly set by the user in the Project Settings. - std::string macro_name_str = proj_.include_guard; - if (macro_name_str.empty()) { - char macro_name[1024]; - char *mp = macro_name; - char *mp_end = macro_name + sizeof(macro_name) - 16; - std::string header_name; + char macro_name_str[1024]; + const char *guard = proj_.include_guard(); + if (guard && guard[0]) { + strlcpy(macro_name_str, guard, sizeof(macro_name_str)); + } else { + char *mp = macro_name_str; + char *mp_end = macro_name_str + sizeof(macro_name_str) - 16; + char header_name[FL_PATH_MAX]; const char* a = 0; if (write_codeview) { - header_name = proj_.headerfile_name(); - a = header_name.c_str(); + proj_.headerfile_name(header_name, FL_PATH_MAX); + a = header_name; } else { a = fl_filename_name(t); } @@ -755,10 +762,9 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { a += len; } *mp = 0; - macro_name_str = macro_name; } - fprintf(header_file, "#ifndef %s\n", macro_name_str.c_str()); - fprintf(header_file, "#define %s\n", macro_name_str.c_str()); + fprintf(header_file, "#ifndef %s\n", macro_name_str); + fprintf(header_file, "#define %s\n", macro_name_str); } if (proj_.avoid_early_includes==0) { @@ -767,10 +773,13 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { if (t && proj_.include_H_from_C) { if (to_codeview) { write_c("#include \"CodeView.h\"\n"); - } else if (proj_.header_file_name[0] == '.' && strchr(proj_.header_file_name.c_str(), '/') == nullptr) { - write_c("#include \"%s\"\n", fl_filename_name(t)); } else { - write_c("#include \"%s\"\n", proj_.header_file_name.c_str()); + const char *hfn = proj_.header_file_name(); + if (hfn && hfn[0] == '.' && strchr(hfn, '/') == 0) { + write_c("#include \"%s\"\n", fl_filename_name(t)); + } else { + write_c("#include \"%s\"\n", hfn ? hfn : ""); + } } } std::string loc_include, loc_conditional; @@ -798,7 +807,11 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { write_c("// Initialize I18N stuff now for menus...\n"); write_c("#%sinclude <locale.h>\n", indent()); write_c("static char *_locale = setlocale(LC_MESSAGES, \"\");\n"); - write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n", proj_.basename().c_str()); + { + char basename_buf[FL_PATH_MAX]; + proj_.basename(basename_buf, FL_PATH_MAX); + write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n", basename_buf); + } } } if (conditional) { @@ -851,10 +864,10 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { if (code_file != stdout) x = fclose(code_file); - code_file = nullptr; + code_file = 0; if (header_file != stdout) y = fclose(header_file); - header_file = nullptr; + header_file = 0; return x >= 0 && y >= 0; } @@ -883,7 +896,7 @@ void Code_Writer::write_public(int state) { Code_Writer::Code_Writer(Project &proj) : proj_ { proj } { - block_crc_ = crc32(0, nullptr, 0); + block_crc_ = crc32(0, 0, 0); } /** @@ -906,7 +919,7 @@ void Code_Writer::tag(proj::Mergeback::Tag prev_type, proj::Mergeback::Tag next_ if (proj_.write_mergeback_data) { Mergeback::print_tag(code_file, prev_type, next_type, uid, (uint32_t)block_crc_); } - block_crc_ = crc32(0, nullptr, 0); + block_crc_ = crc32(0, 0, 0); } /** diff --git a/fluid/io/Code_Writer.h b/fluid/io/Code_Writer.h index 9d52e0600..f2ca32a3e 100644 --- a/fluid/io/Code_Writer.h +++ b/fluid/io/Code_Writer.h @@ -88,9 +88,9 @@ private: Project &proj_; /// file pointer for the C++ code file - FILE *code_file = nullptr; + FILE *code_file = 0; /// file pointer for the C++ header file - FILE *header_file = nullptr; + FILE *header_file = 0; /// tree of unique but human-readable identifiers Fd_Id_Map unique_id_list; @@ -106,7 +106,7 @@ private: /// if set, we are at the start of a line and can ignore leading spaces in crc bool block_line_start_ = true; /// expanding buffer for vsnprintf - char *block_buffer_ = nullptr; + char *block_buffer_ = 0; /// size of expanding buffer for vsnprintf int block_buffer_size_ = 0; @@ -159,7 +159,7 @@ public: void tag(proj::Mergeback::Tag prev_type, proj::Mergeback::Tag next_type, unsigned short uid); - static unsigned long block_crc(const void *data, int n=-1, unsigned long in_crc=0, bool *inout_line_start=nullptr); + static unsigned long block_crc(const void *data, int n=-1, unsigned long in_crc=0, bool *inout_line_start=0); }; } // namespace io diff --git a/fluid/io/Project_Reader.cxx b/fluid/io/Project_Reader.cxx index e4eb65606..33dce126c 100644 --- a/fluid/io/Project_Reader.cxx +++ b/fluid/io/Project_Reader.cxx @@ -112,7 +112,7 @@ Project_Reader::~Project_Reader() /** Open an .fl file for reading. - \param[in] s filename, if nullptr, read from stdin instead + \param[in] s filename, if 0, read from stdin instead \return 0 if the operation failed, 1 if it succeeded */ int Project_Reader::open_read(const char *s) { @@ -137,7 +137,7 @@ int Project_Reader::open_read(const char *s) { int Project_Reader::close_read() { if (fin != stdin) { int x = fclose(fin); - fin = nullptr; + fin = 0; return x >= 0; } return 1; @@ -195,7 +195,7 @@ int Project_Reader::read_quoted() { // read whatever character is after a \ If this is the first call, also read the global settings for this design. - \param[in] p parent node or nullptr + \param[in] p parent node or 0 \param[in] merge if set, merge into existing design, else replace design \param[in] strategy add nodes after current or as last child \param[in] skip_options this is set if the options were already found in @@ -204,8 +204,8 @@ int Project_Reader::read_quoted() { // read whatever character is after a \ */ Node *Project_Reader::read_children(Node *p, int merge, Strategy strategy, char skip_options) { Fluid.proj.tree.current = p; - Node *last_child_read = nullptr; - Node *t = nullptr; + Node *last_child_read = 0; + Node *t = 0; for (;;) { const char *c = read_word(); REUSE_C: @@ -225,12 +225,12 @@ Node *Project_Reader::read_children(Node *p, int merge, Strategy strategy, char // this is the first word in a .fd file: if (!strcmp(c,"Magic:")) { read_fdesign(); - return nullptr; + return 0; } if (!strcmp(c,"version")) { c = read_word(); - read_version = strtod(c,nullptr); + read_version = strtod(c,0); if (read_version<=0 || read_version>double(FL_VERSION+0.00001)) read_error("unknown version '%s'",c); continue; @@ -266,24 +266,24 @@ Node *Project_Reader::read_children(Node *p, int merge, Strategy strategy, char goto CONTINUE; } if (!strcmp(c,"header_name")) { - if (!proj_.header_file_set) proj_.header_file_name = read_word(); + if (!proj_.header_file_set) proj_.set_header_file_name(read_word()); else read_word(); goto CONTINUE; } if (!strcmp(c,"code_name")) { - if (!proj_.code_file_set) proj_.code_file_name = read_word(); + if (!proj_.code_file_set) proj_.set_code_file_name(read_word()); else read_word(); goto CONTINUE; } if (!strcmp(c,"include_guard")) { - proj_.include_guard = read_word(); + proj_.set_include_guard(read_word()); goto CONTINUE; } if (!strcmp(c, "snap")) { - Fluid.layout_list.read(this); + Fluid.layout_list->read(this); goto CONTINUE; } @@ -400,11 +400,11 @@ int Project_Reader::read_project(const char *filename, int merge, Strategy strat proj_.reset(); read_children(Fluid.proj.tree.current, merge, strategy); // clear this - Fluid.proj.tree.current = nullptr; + Fluid.proj.tree.current = 0; // Force menu items to be rebuilt... for (o = Fluid.proj.tree.first; o; o = o->next) { if (o->is_a(FLD_NODE_TYPE_Menu_Manager_)) { - o->add_child(nullptr,nullptr); + o->add_child(0,0); } } for (o = Fluid.proj.tree.first; o; o = o->next) { @@ -418,7 +418,7 @@ int Project_Reader::read_project(const char *filename, int merge, Strategy strat g_shell_config->rebuild_shell_menu(); g_shell_config->update_settings_dialog(); } - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->update_dialogs(); proj_.update_settings_dialog(); int ret = close_read(); proj_.undo.resume(); @@ -452,7 +452,7 @@ void Project_Reader::read_error(const char *format, ...) { } /** - Return a word read from the .fl file, or nullptr at the EOF. + Return a word read from the .fl file, or 0 at the EOF. This will skip all comments (# to end of line), and evaluate all \\xxx sequences and use \\ at the end of line to remove the newline. @@ -476,7 +476,7 @@ const char *Project_Reader::read_word(int wantbrace) { for (;;) { x = nextchar(); if (x < 0 && feof(fin)) { // eof - return nullptr; + return 0; } else if (x == '#') { // comment do x = nextchar(); while (x >= 0 && x != '\n'); lineno++; @@ -622,7 +622,7 @@ static const char *class_matcher[] = { "2", "FL_BOX", // was FL_TEXT "62","FL_TIMER", "24","Fl_Value_Slider", - nullptr}; + 0}; /** @@ -684,9 +684,9 @@ static void forms_end(Fl_Group *g, int flip) { void Project_Reader::read_fdesign() { int fdesign_magic = atoi(read_word()); fdesign_flip = (fdesign_magic < 13000); - Widget_Node *window = nullptr; - Widget_Node *group = nullptr; - Widget_Node *widget = nullptr; + Widget_Node *window = 0; + Widget_Node *group = 0; + Widget_Node *widget = 0; if (!Fluid.proj.tree.current) { Node *t = add_new_widget_from_file("Function", Strategy::FROM_FILE_AS_LAST_CHILD); t->name("create_the_forms()"); @@ -714,9 +714,9 @@ void Project_Reader::read_fdesign() { Fl_Group* g = (Fl_Group*)(group->o); g->begin(); forms_end(g, fdesign_flip); - Fl_Group::current(nullptr); + Fl_Group::current(0); } - group = widget = nullptr; + group = widget = 0; Fluid.proj.tree.current = window; } else { for (int i = 0; class_matcher[i]; i += 2) diff --git a/fluid/io/Project_Reader.h b/fluid/io/Project_Reader.h index b25b04ead..fe66be689 100644 --- a/fluid/io/Project_Reader.h +++ b/fluid/io/Project_Reader.h @@ -43,13 +43,13 @@ protected: Project &proj_; /// Project input file - FILE *fin = nullptr; + FILE *fin = 0; /// Number of most recently read line int lineno = 0; /// Pointer to the file path and name (not copied!) - const char *fname = nullptr; + const char *fname = 0; /// Expanding buffer to store the most recently read word - char *buffer = nullptr; + char *buffer = 0; /// Exact size of the expanding buffer in bytes int buflen = 0; diff --git a/fluid/io/Project_Writer.cxx b/fluid/io/Project_Writer.cxx index 54af531e9..a3b878c3f 100644 --- a/fluid/io/Project_Writer.cxx +++ b/fluid/io/Project_Writer.cxx @@ -62,8 +62,8 @@ Project_Writer::~Project_Writer() /** Open the .fl design file for writing. - If the filename is nullptr, associate stdout instead. - \param[in] s the filename or nullptr for stdout + If the filename is 0, associate stdout instead. + \param[in] s the filename or 0 for stdout \return 1 if successful. 0 if the operation failed */ int Project_Writer::open_write(const char *s) { @@ -119,10 +119,10 @@ int Project_Writer::write_project(const char *filename, int selected_only, bool proj_.i18n.write(*this); if (!selected_only) { - write_string("\nheader_name"); write_word(proj_.header_file_name); - write_string("\ncode_name"); write_word(proj_.code_file_name); - write_string("\ninclude_guard"); write_word(proj_.include_guard); - Fluid.layout_list.write(this); + write_string("\nheader_name"); write_word(proj_.header_file_name()); + write_string("\ncode_name"); write_word(proj_.code_file_name()); + write_string("\ninclude_guard"); write_word(proj_.include_guard()); + Fluid.layout_list->write(this); if (g_shell_config) g_shell_config->write(this); if (proj_.write_mergeback_data) diff --git a/fluid/io/Project_Writer.h b/fluid/io/Project_Writer.h index c95c9f7cb..64769a762 100644 --- a/fluid/io/Project_Writer.h +++ b/fluid/io/Project_Writer.h @@ -40,7 +40,7 @@ protected: Project &proj_; // Project output file, always opened in "wb" mode - FILE *fout = nullptr; + FILE *fout = 0; /// If set, one space is written before text unless the format starts with a newline character int needspace = 0; /// Set if this file will be used in the codeview dialog diff --git a/fluid/io/String_Writer.cxx b/fluid/io/String_Writer.cxx index 6d7761a49..cf59935aa 100644 --- a/fluid/io/String_Writer.cxx +++ b/fluid/io/String_Writer.cxx @@ -77,8 +77,8 @@ int fld::io::write_strings(Project &proj, const std::string &filename) { write_escaped_strings(fp, w->label()); putc('\n', fp); } - if (!w->tooltip().empty()) { - write_escaped_strings(fp, w->tooltip().c_str()); + if (!(!w->tooltip() || !w->tooltip()[0])) { + write_escaped_strings(fp, w->tooltip()); putc('\n', fp); } } @@ -100,13 +100,13 @@ int fld::io::write_strings(Project &proj, const std::string &filename) { fputs("\"\n", fp); } - if (!w->tooltip().empty()) { + if (!(!w->tooltip() || !w->tooltip()[0])) { fputs("msgid \"", fp); - write_escaped_strings(fp, w->tooltip().c_str()); + write_escaped_strings(fp, w->tooltip()); fputs("\"\n", fp); fputs("msgstr \"", fp); - write_escaped_strings(fp, w->tooltip().c_str()); + write_escaped_strings(fp, w->tooltip()); fputs("\"\n", fp); } } @@ -128,9 +128,9 @@ int fld::io::write_strings(Project &proj, const std::string &filename) { fputs("\"\n", fp); } - if (!w->tooltip().empty()) { + if (!(!w->tooltip() || !w->tooltip()[0])) { fprintf(fp, "%d \"", i ++); - write_escaped_strings(fp, w->tooltip().c_str()); + write_escaped_strings(fp, w->tooltip()); fputs("\"\n", fp); } } diff --git a/fluid/nodes/Button_Node.cxx b/fluid/nodes/Button_Node.cxx index c1ac26e95..d989c527c 100644 --- a/fluid/nodes/Button_Node.cxx +++ b/fluid/nodes/Button_Node.cxx @@ -46,10 +46,10 @@ Button_Node Button_Node::prototype; static Fl_Menu_Item buttontype_menu[] = { - {"Normal", 0, nullptr, (void*)nullptr}, - {"Toggle", 0, nullptr, (void*)FL_TOGGLE_BUTTON}, - {"Radio", 0, nullptr, (void*)FL_RADIO_BUTTON}, - {nullptr} + {"Normal", 0, 0, (void*)0}, + {"Toggle", 0, 0, (void*)FL_TOGGLE_BUTTON}, + {"Radio", 0, 0, (void*)FL_RADIO_BUTTON}, + {0} }; Fl_Menu_Item *Button_Node::subtypes() { diff --git a/fluid/nodes/Function_Node.cxx b/fluid/nodes/Function_Node.cxx index 02f4d75ca..27e8c83de 100644 --- a/fluid/nodes/Function_Node.cxx +++ b/fluid/nodes/Function_Node.cxx @@ -42,14 +42,14 @@ using namespace fld::io; using namespace fld::proj; /// Set a current class, so that the code of the children is generated correctly. -Class_Node *current_class = nullptr; +Class_Node *current_class = 0; /** \brief Return 1 if the list contains a function with the given signature at the top level. Widget_Node uses this to check if a callback by a certain signature is already defined by the user within this file. If not, Widget_Node will generate an `extern $sig$;` statement. - \param[in] rtype return type, can be nullptr to avoid checking (not used by Widget_Node) + \param[in] rtype return type, can be 0 to avoid checking (not used by Widget_Node) \param[in] sig function signature \return 1 if found. */ @@ -76,7 +76,7 @@ static char buffer[128]; // for error messages This is used to find a matching " or ' in a string. \param[inout] c start searching here, return where we found \c type \param[in] type find this character - \return nullptr if the character was found, else a pointer to a static string + \return 0 if the character was found, else a pointer to a static string with an error message */ const char *_q_check(const char * & c, int type) { @@ -88,7 +88,7 @@ const char *_q_check(const char * & c, int type) { if (*c) c++; break; default: - if (*(c-1) == type) return nullptr; + if (*(c-1) == type) return 0; } } @@ -98,14 +98,14 @@ const char *_q_check(const char * & c, int type) { {, [, ", ', and ( are matched. \param[inout] c start searching here, return the end of the search \param[in] type find this character match - \return nullptr if the character was found, else a pointer to a static string + \return 0 if the character was found, else a pointer to a static string with an error message */ const char *_c_check(const char * & c, int type) { const char *d; for (;;) switch (*c++) { case 0: - if (!type) return nullptr; + if (!type) return 0; sprintf(buffer, "missing '%c'", type); return buffer; case '/': @@ -153,7 +153,7 @@ const char *_c_check(const char * & c, int type) { case ')': case ']': // UNEXPECTED: - if (type == *(c-1)) return nullptr; + if (type == *(c-1)) return 0; sprintf(buffer, "unexpected '%c'", *(c-1)); return buffer; } @@ -164,7 +164,7 @@ const char *_c_check(const char * & c, int type) { Make sure that {, ", ', and ( are matched. \param[in] c start searching here \param[in] type find this character match (default is 0) - \return nullptr if the character was found, else a pointer to a static string + \return 0 if the character was found, else a pointer to a static string with an error message \note This function checks every conceivable line of code, which is not always wanted. It can't differentiate characters in comments, and the @@ -436,7 +436,7 @@ void Function_Node::write_code1(fld::io::Code_Writer& f) { } if (havewidgets && child && !child->name()) - f.write_c("%s%s* w;\n", f.indent(1), subclassname(child).c_str()); + f.write_c("%s%s* w;\n", f.indent(1), subclassname(child)); f.indentation++; } @@ -478,7 +478,7 @@ int Function_Node::has_signature(const char *rtype, const char *sig) const { return 0; if (!name()) return 0; - if ( (rtype==nullptr || (return_type() == rtype)) && fl_filename_match(name(), sig)) { + if ( (rtype==0 || (return_type() == rtype)) && fl_filename_match(name(), sig)) { return 1; } return 0; @@ -515,7 +515,7 @@ Node *Code_Node::make(Strategy strategy) { } if (!p) { fl_message("Please select a function"); - return nullptr; + return 0; } Code_Node *o = new Code_Node(); o->name("printf(\"Hello, World!\\n\");"); @@ -591,7 +591,7 @@ int Code_Node::reap_editor() { current contents of editor file.. */ int Code_Node::handle_editor_changes() { - const char *newcode = nullptr; + const char *newcode = 0; switch ( editor_.handle_changes(&newcode) ) { case 1: { // (1)=changed name(newcode); // update value in ram @@ -636,7 +636,7 @@ Node *CodeBlock_Node::make(Strategy strategy) { } if (!p) { fl_message("Please select a function"); - return nullptr; + return 0; } CodeBlock_Node *o = new CodeBlock_Node(); o->name("if (test())"); @@ -950,11 +950,11 @@ void Data_Node::open() { Write the content of the external file inline into the source code. */ void Data_Node::write_code1(fld::io::Code_Writer& f) { - const char *message = nullptr; + const char *message = 0; const char *c = name(); if (!c) return; std::string fn = filename(); - char *data = nullptr; + char *data = 0; int nData = -1; int uncompressedDataSize = 0; // path should be set correctly already diff --git a/fluid/nodes/Function_Node.h b/fluid/nodes/Function_Node.h index e92f36f80..0ad4494f3 100644 --- a/fluid/nodes/Function_Node.h +++ b/fluid/nodes/Function_Node.h @@ -65,7 +65,7 @@ public: void write_code1(fld::io::Code_Writer& f) override; void write_code2(fld::io::Code_Writer& f) override; void open() override; - int ismain() {return name_ == nullptr;} + int ismain() {return name_ == 0;} const char *type_name() override {return "Function";} const char *title() override { return name() ? name() : "main()"; } int can_have_children() const override {return 1;} diff --git a/fluid/nodes/Grid_Node.cxx b/fluid/nodes/Grid_Node.cxx index 2304a7a10..d38bbd1ca 100644 --- a/fluid/nodes/Grid_Node.cxx +++ b/fluid/nodes/Grid_Node.cxx @@ -51,7 +51,7 @@ */ Fl_Grid_Proxy::Fl_Grid_Proxy(int X,int Y,int W,int H) : Fl_Grid(X,Y,W,H), - transient_(nullptr), + transient_(0), num_transient_(0), cap_transient_(0) { @@ -137,19 +137,19 @@ void Fl_Grid_Proxy::move_cell(Fl_Widget *in_child, int to_row, int to_col, int h } if ((to_row < 0) || (to_row+rowspan > rows())) return; if ((to_col < 0) || (to_col+colspan > cols())) return; - Fl_Grid::Cell *new_cell = nullptr; + Fl_Grid::Cell *new_cell = 0; if (how == 0) { // replace old occupant in cell, making that one homeless new_cell = widget(in_child, to_row, to_col, rowspan, colspan, align); } else if (how == 1) { // don't replace an old occupant, making ourselves homeless // todo: colspan, rowspan? - if (cell(to_row, to_col) == nullptr) { + if (cell(to_row, to_col) == 0) { new_cell = widget(in_child, to_row, to_col, rowspan, colspan, align); } else { if (old_cell) remove_cell(old_cell->row(), old_cell->col()); } } else if (how == 2) { Cell *current = cell(to_row, to_col); - if (current == nullptr) { + if (current == 0) { new_cell = widget(in_child, to_row, to_col, rowspan, colspan, align); } else { if (old_cell) remove_cell(old_cell->row(), old_cell->col()); @@ -240,7 +240,7 @@ void Fl_Grid_Proxy::transient_remove_(Fl_Widget *w) { /** Find a cell in the grid or in the transient cell list. \param[in] widget must be a child of the grid. - \return the cell, the transient cell, or nullptr if neither was found. + \return the cell, the transient cell, or 0 if neither was found. */ Fl_Grid_Proxy::Cell *Fl_Grid_Proxy::any_cell(Fl_Widget *widget) const { Cell *c = cell(widget); @@ -251,14 +251,14 @@ Fl_Grid_Proxy::Cell *Fl_Grid_Proxy::any_cell(Fl_Widget *widget) const { /** Find a cell in the transient cell list. \param[in] widget must be a child of the grid. - \return the transient cell, or nullptr if it was not found. + \return the transient cell, or 0 if it was not found. */ Fl_Grid_Proxy::Cell *Fl_Grid_Proxy::transient_cell(Fl_Widget *widget) const { for (int i=0; i<num_transient_; i++) { if (transient_[i].widget == widget) return transient_[i].cell; } - return nullptr; + return 0; } /** @@ -292,7 +292,7 @@ Grid_Node::Grid_Node() { Fl_Widget *Grid_Node::widget(int X,int Y,int W,int H) { Fl_Grid *g = new Fl_Grid_Proxy(X,Y,W,H); g->layout(3, 3); - Fl_Group::current(nullptr); + Fl_Group::current(0); return g; } @@ -678,7 +678,7 @@ void Grid_Node::child_resized(Widget_Node *child_type) { Fl_Grid *Grid_Node::selected() { if (current_widget && current_widget->is_a(FLD_NODE_TYPE_Grid)) return ((Fl_Grid*)((Grid_Node*)current_widget)->o); - return nullptr; + return 0; } /** @@ -689,7 +689,7 @@ Fl_Grid *Grid_Node::selected() { void Grid_Node::insert_child_at(Fl_Widget *child, int x, int y) { Fl_Grid_Proxy *grid = (Fl_Grid_Proxy*)o; int row = -1, col = -1, ml, mt, grg, gcg; - grid->margin(&ml, &mt, nullptr, nullptr); + grid->margin(&ml, &mt, 0, 0); grid->gap(&grg, &gcg); int x0 = grid->x() + Fl::box_dx(grid->box()) + ml; int y0 = grid->y() + Fl::box_dy(grid->box()) + mt; diff --git a/fluid/nodes/Group_Node.cxx b/fluid/nodes/Group_Node.cxx index 088e999aa..eb735cbeb 100644 --- a/fluid/nodes/Group_Node.cxx +++ b/fluid/nodes/Group_Node.cxx @@ -215,7 +215,7 @@ void Group_Node::write_code2(fld::io::Code_Writer& f) { // sure it is visible: void Group_Node::add_child(Node* cc, Node* before) { Widget_Node* c = (Widget_Node*)cc; - Fl_Widget* b = before ? ((Widget_Node*)before)->o : nullptr; + Fl_Widget* b = before ? ((Widget_Node*)before)->o : 0; ((Fl_Group*)o)->insert(*(c->o), b); o->redraw(); } @@ -233,7 +233,7 @@ void Group_Node::remove_child(Node* cc) { // move, don't change selected value: void Group_Node::move_child(Node* cc, Node* before) { Widget_Node* c = (Widget_Node*)cc; - Fl_Widget* b = before ? ((Widget_Node*)before)->o : nullptr; + Fl_Widget* b = before ? ((Widget_Node*)before)->o : 0; ((Fl_Group*)o)->insert(*(c->o), b); o->redraw(); } @@ -261,9 +261,9 @@ Pack_Node Pack_Node::prototype; // the "factory" const char pack_type_name[] = "Fl_Pack"; Fl_Menu_Item pack_type_menu[] = { - {"HORIZONTAL", 0, nullptr, (void*)Fl_Pack::HORIZONTAL}, - {"VERTICAL", 0, nullptr, (void*)Fl_Pack::VERTICAL}, - {nullptr} + {"HORIZONTAL", 0, 0, (void*)Fl_Pack::HORIZONTAL}, + {"VERTICAL", 0, 0, (void*)Fl_Pack::VERTICAL}, + {0} }; Fl_Widget *Pack_Node::enter_live_mode(int) { @@ -283,9 +283,9 @@ void Pack_Node::copy_properties() const char flex_type_name[] = "Fl_Flex"; Fl_Menu_Item flex_type_menu[] = { - {"HORIZONTAL", 0, nullptr, (void*)Fl_Flex::HORIZONTAL}, - {"VERTICAL", 0, nullptr, (void*)Fl_Flex::VERTICAL}, - {nullptr}}; + {"HORIZONTAL", 0, 0, (void*)Fl_Flex::HORIZONTAL}, + {"VERTICAL", 0, 0, (void*)Fl_Flex::VERTICAL}, + {0}}; Flex_Node Flex_Node::prototype; // the "factory" @@ -420,7 +420,7 @@ void Flex_Node::postprocess_read() } fixedSizeTupleSize = 0; delete[] fixedSizeTuple; - fixedSizeTuple = nullptr; + fixedSizeTuple = 0; } suspend_auto_layout = 0; } @@ -655,7 +655,7 @@ class Fl_Table_Proxy : public Fl_Table { } } public: - Fl_Table_Proxy(int x, int y, int w, int h, const char *l=nullptr) + Fl_Table_Proxy(int x, int y, int w, int h, const char *l=0) : Fl_Table(x, y, w, h, l) { end(); for ( int r=0; r<MAX_ROWS; r++ ) @@ -681,7 +681,7 @@ Fl_Widget *Table_Node::widget(int X,int Y,int W,int H) { void Table_Node::add_child(Node* cc, Node* before) { Widget_Node* c = (Widget_Node*)cc; - Fl_Widget* b = before ? ((Widget_Node*)before)->o : nullptr; + Fl_Widget* b = before ? ((Widget_Node*)before)->o : 0; if (((Fl_Table*)o)->children()==1) { // the FLuid_Table has one extra child fl_message("Inserting child widgets into an Fl_Table is not recommended.\n" "Please refer to the documentation on Fl_Table."); @@ -698,7 +698,7 @@ void Table_Node::remove_child(Node* cc) { void Table_Node::move_child(Node* cc, Node* before) { Widget_Node* c = (Widget_Node*)cc; - Fl_Widget* b = before ? ((Widget_Node*)before)->o : nullptr; + Fl_Widget* b = before ? ((Widget_Node*)before)->o : 0; ((Fl_Table*)o)->insert(*(c->o), b); o->redraw(); } @@ -750,7 +750,7 @@ void Fl_Tabs_Proxy::draw() { Node* Tabs_Node::click_test(int x, int y) { Fl_Tabs *t = (Fl_Tabs*)o; Fl_Widget *a = t->which(x,y); - if (!a) return nullptr; // didn't click on tab + if (!a) return 0; // didn't click on tab // changing the visible tab has an impact on the generated // source code, so mark this project as changed. int changed = (a!=t->value()); @@ -770,7 +770,7 @@ void Tabs_Node::remove_child(Node* cc) { if (cc->is_widget()) { Widget_Node* c = (Widget_Node*)cc; Fl_Tabs *t = (Fl_Tabs*)o; - if (t->value() == c->o) t->value(nullptr); + if (t->value() == c->o) t->value(0); } Group_Node::remove_child(cc); } @@ -792,13 +792,13 @@ Scroll_Node Scroll_Node::prototype; // the "factory" const char scroll_type_name[] = "Fl_Scroll"; Fl_Menu_Item scroll_type_menu[] = { - {"BOTH", 0, nullptr, nullptr/*(void*)Fl_Scroll::BOTH*/}, - {"HORIZONTAL", 0, nullptr, (void*)Fl_Scroll::HORIZONTAL}, - {"VERTICAL", 0, nullptr, (void*)Fl_Scroll::VERTICAL}, - {"HORIZONTAL_ALWAYS", 0, nullptr, (void*)Fl_Scroll::HORIZONTAL_ALWAYS}, - {"VERTICAL_ALWAYS", 0, nullptr, (void*)Fl_Scroll::VERTICAL_ALWAYS}, - {"BOTH_ALWAYS", 0, nullptr, (void*)Fl_Scroll::BOTH_ALWAYS}, - {nullptr}}; + {"BOTH", 0, 0, 0/*(void*)Fl_Scroll::BOTH*/}, + {"HORIZONTAL", 0, 0, (void*)Fl_Scroll::HORIZONTAL}, + {"VERTICAL", 0, 0, (void*)Fl_Scroll::VERTICAL}, + {"HORIZONTAL_ALWAYS", 0, 0, (void*)Fl_Scroll::HORIZONTAL_ALWAYS}, + {"VERTICAL_ALWAYS", 0, 0, (void*)Fl_Scroll::VERTICAL_ALWAYS}, + {"BOTH_ALWAYS", 0, 0, (void*)Fl_Scroll::BOTH_ALWAYS}, + {0}}; Fl_Widget *Scroll_Node::enter_live_mode(int) { Fl_Group *grp = new Fl_Scroll(o->x(), o->y(), o->w(), o->h()); diff --git a/fluid/nodes/Group_Node.h b/fluid/nodes/Group_Node.h index 52f31a907..71df8aa46 100644 --- a/fluid/nodes/Group_Node.h +++ b/fluid/nodes/Group_Node.h @@ -39,7 +39,7 @@ void ungroup_cb(Fl_Widget *, void *); */ class Fl_Group_Proxy : public Fl_Group { public: - Fl_Group_Proxy(int X,int Y,int W,int H) : Fl_Group(X, Y, W, H) { Fl_Group::current(nullptr); } + Fl_Group_Proxy(int X,int Y,int W,int H) : Fl_Group(X, Y, W, H) { Fl_Group::current(0); } void resize(int x, int y, int w, int h) override; void draw() override; }; @@ -54,7 +54,7 @@ public: const char *type_name() override {return "Fl_Group";} const char *alt_type_name() override {return "fltk::Group";} Fl_Widget *widget(int X,int Y,int W,int H) override { - Fl_Group_Proxy *g = new Fl_Group_Proxy(X,Y,W,H); Fl_Group::current(nullptr); return g;} + Fl_Group_Proxy *g = new Fl_Group_Proxy(X,Y,W,H); Fl_Group::current(0); return g;} Widget_Node *_make() override {return new Group_Node();} void write_code1(fld::io::Code_Writer& f) override; void write_code2(fld::io::Code_Writer& f) override; @@ -98,7 +98,7 @@ extern Fl_Menu_Item flex_type_menu[]; class Fl_Flex_Proxy : public Fl_Flex { public: - Fl_Flex_Proxy(int X,int Y,int W,int H) : Fl_Flex(X, Y, W, H) { Fl_Group::current(nullptr); } + Fl_Flex_Proxy(int X,int Y,int W,int H) : Fl_Flex(X, Y, W, H) { Fl_Group::current(0); } void resize(int x, int y, int w, int h) override; void draw() override; }; @@ -114,12 +114,12 @@ private: int *fixedSizeTuple; /* [ index, size, index2, size2, ... ] */ int suspend_auto_layout; public: - Flex_Node() : fixedSizeTupleSize(0), fixedSizeTuple(nullptr), suspend_auto_layout(0) { } + Flex_Node() : fixedSizeTupleSize(0), fixedSizeTuple(0), suspend_auto_layout(0) { } const char *type_name() override {return flex_type_name;} const char *alt_type_name() override {return "fltk::FlexGroup";} Widget_Node *_make() override { return new Flex_Node(); } Fl_Widget *widget(int X,int Y,int W,int H) override { - Fl_Flex *g = new Fl_Flex_Proxy(X,Y,W,H); Fl_Group::current(nullptr); return g;} + Fl_Flex *g = new Fl_Flex_Proxy(X,Y,W,H); Fl_Group::current(0); return g;} Type type() const override { return FLD_NODE_TYPE_Flex; } bool is_a(Type inType) const override { return (inType==FLD_NODE_TYPE_Flex) ? true : super::is_a(inType); } void write_properties(fld::io::Project_Writer &f) override; @@ -182,7 +182,7 @@ public: const char *type_name() override {return tabs_type_name;} const char *alt_type_name() override {return "fltk::TabGroup";} Fl_Widget *widget(int X,int Y,int W,int H) override { - Fl_Tabs_Proxy *g = new Fl_Tabs_Proxy(X,Y,W,H); Fl_Group::current(nullptr); return g;} + Fl_Tabs_Proxy *g = new Fl_Tabs_Proxy(X,Y,W,H); Fl_Group::current(0); return g;} Widget_Node *_make() override {return new Tabs_Node();} Node* click_test(int,int) override; void add_child(Node*, Node*) override; @@ -254,7 +254,7 @@ public: const char *type_name() override {return wizard_type_name;} const char *alt_type_name() override {return "fltk::WizardGroup";} Fl_Widget *widget(int X,int Y,int W,int H) override { - Fl_Wizard_Proxy *g = new Fl_Wizard_Proxy(X,Y,W,H); Fl_Group::current(nullptr); return g;} + Fl_Wizard_Proxy *g = new Fl_Wizard_Proxy(X,Y,W,H); Fl_Group::current(0); return g;} Widget_Node *_make() override {return new Wizard_Node();} Type type() const override { return FLD_NODE_TYPE_Wizard; } bool is_a(Type inType) const override { return (inType==FLD_NODE_TYPE_Wizard) ? true : super::is_a(inType); } diff --git a/fluid/nodes/Menu_Node.cxx b/fluid/nodes/Menu_Node.cxx index e0f1c11ee..b669c18e0 100644 --- a/fluid/nodes/Menu_Node.cxx +++ b/fluid/nodes/Menu_Node.cxx @@ -48,17 +48,17 @@ using namespace fld; using namespace fld::proj; Fl_Menu_Item menu_item_type_menu[] = { - {"Normal",0,nullptr,(void*)nullptr}, - {"Toggle",0,nullptr,(void*)FL_MENU_BOX}, - {"Radio",0,nullptr,(void*)FL_MENU_RADIO}, - {nullptr}}; + {"Normal",0,0,(void*)0}, + {"Toggle",0,0,(void*)FL_MENU_BOX}, + {"Radio",0,0,(void*)FL_MENU_RADIO}, + {0}}; static void delete_dependents(Fl_Menu_Item *m) { if (!m) return; int level = 0; for (;;m++) { - if (m->label()==nullptr) { + if (m->label()==0) { if (level==0) { break; } else { @@ -90,7 +90,7 @@ void Input_Choice_Node::build_menu() { } if (!n) { if (menusize) delete_menu((Fl_Menu_Item*)(w->menu())); - w->menu(nullptr); + w->menu(0); menusize = 0; } else { n++; // space for null at end of menu @@ -102,7 +102,7 @@ void Input_Choice_Node::build_menu() { if (menusize) delete_dependents((Fl_Menu_Item*)(w->menu())); } // Menus are already built during the .fl file reading process, so if the - // end of a menu list is not read yet, the end markers (label==nullptr) will + // end of a menu list is not read yet, the end markers (label==0) will // not be set, and deleting dependents will randomly free memory. // Clearing the array should avoid that. memset( (void*)w->menu(), 0, menusize * sizeof(Fl_Menu_Item) ); @@ -127,7 +127,7 @@ void Input_Choice_Node::build_menu() { m->labeltype(i->o->labeltype()); } m->shortcut(((Fl_Button*)(i->o))->shortcut()); - m->callback(nullptr,(void*)i); + m->callback(0,(void*)i); m->flags = i->flags() & ~FL_MENU_HEADLINE; m->labelfont(i->o->labelfont()); m->labelsize(i->o->labelsize()); @@ -136,7 +136,7 @@ void Input_Choice_Node::build_menu() { m++; int l1 = (q->next && q->next->is_a(FLD_NODE_TYPE_Menu_Item)) ? q->next->level : level; - while (lvl > l1) {m->label(nullptr); m++; lvl--;} + while (lvl > l1) {m->label(0); m++; lvl--;} lvl = l1; } } @@ -170,13 +170,13 @@ Node* Menu_Item_Node::make(int flags, Strategy strategy) { } if (!p) { fl_message("Please select a menu widget or a menu item"); - return nullptr; + return 0; } if (!o) { o = new Fl_Button(0,0,100,20); // create template widget } - Menu_Item_Node* t = nullptr; + Menu_Item_Node* t = 0; if (flags==FL_SUBMENU) { t = new Submenu_Node(); } else { @@ -326,8 +326,8 @@ void Menu_Item_Node::write_static(fld::io::Code_Writer& f) { f.write_h_once("extern void %s(Fl_Menu_*, %s);", callback(), user_data_type() ? user_data_type() : "void*"); for (int n=0; n < NUM_EXTRA_CODE; n++) { - if (!extra_code(n).empty() && isdeclare(extra_code(n).c_str())) - f.write_h_once("%s", extra_code(n).c_str()); + if (extra_code(n) && extra_code(n)[0] && isdeclare(extra_code(n))) + f.write_h_once("%s", extra_code(n)); } if (callback() && !is_name(callback()) && (callback()[0] != '[')) { // see if 'o' or 'v' used, to prevent unused argument warnings: @@ -376,8 +376,8 @@ void Menu_Item_Node::write_static(fld::io::Code_Writer& f) { // Find the Fl_Menu_ container for this menu item Node* t = parent; while (t->is_a(FLD_NODE_TYPE_Menu_Item)) t = t->parent; if (t) { - Widget_Node *tw = (t->is_widget()) ? static_cast<Widget_Node*>(t) : nullptr; - Node *q = nullptr; + Widget_Node *tw = (t->is_widget()) ? static_cast<Widget_Node*>(t) : 0; + Node *q = 0; // Generate code to call the callback if (tw->is_a(FLD_NODE_TYPE_Menu_Bar) && ((Menu_Bar_Node*)tw)->is_sys_menu_bar()) { // Fl_Sys_Menu_Bar removes itself from any parent on macOS, so we @@ -463,7 +463,7 @@ int Menu_Item_Node::flags() { if (!o->active()) i |= FL_MENU_INACTIVE; if (!o->visible()) i |= FL_MENU_INVISIBLE; if (can_have_children()) { - if (user_data() == nullptr) i |= FL_SUBMENU; + if (user_data() == 0) i |= FL_SUBMENU; else i |= FL_SUBMENU_POINTER; } if (hotspot()) i |= FL_MENU_DIVIDER; @@ -528,7 +528,7 @@ void Menu_Item_Node::write_item(fld::io::Code_Writer& f) { f.tag(FLD_MERGEBACK_TAG_WIDGET_CALLBACK, FLD_MERGEBACK_TAG_GENERIC, get_uid()); f.write_c("%s, ", f.indent_plus(1)); } else { - const char* k = is_name(callback()) ? nullptr : class_name(1); + const char* k = is_name(callback()) ? 0 : class_name(1); if (k) { f.write_c(" (Fl_Callback*)%s::%s,", k, callback_name(f)); } else { @@ -638,9 +638,9 @@ void Menu_Item_Node::write_code1(fld::io::Code_Writer& f) { } } for (int n=0; n < NUM_EXTRA_CODE; n++) { - if (!extra_code(n).empty() && !isdeclare(extra_code(n).c_str())) { + if (extra_code(n) && extra_code(n)[0] && !isdeclare(extra_code(n))) { start_menu_initialiser(f, menuItemInitialized, mname, i); - f.write_c("%s%s\n", f.indent(), extra_code(n).c_str()); + f.write_c("%s%s\n", f.indent(), extra_code(n)); } } if (menuItemInitialized) { @@ -669,7 +669,7 @@ void Menu_Base_Node::build_menu() { } if (!n) { if (menusize) delete_menu((Fl_Menu_Item*)(w->menu())); - w->menu(nullptr); + w->menu(0); menusize = 0; } else { n++; // space for null at end of menu @@ -681,7 +681,7 @@ void Menu_Base_Node::build_menu() { if (menusize) delete_dependents((Fl_Menu_Item*)(w->menu())); } // Menus are already built during the .fl file reading process, so if the - // end of a menu list is not read yet, the end markers (label==nullptr) will + // end of a menu list is not read yet, the end markers (label==0) will // not be set, and deleting dependents will randomly free memory. // Clearing the array should avoid that. memset( (void*)w->menu(), 0, menusize * sizeof(Fl_Menu_Item) ); @@ -706,7 +706,7 @@ void Menu_Base_Node::build_menu() { m->labeltype(i->o->labeltype()); } m->shortcut(((Fl_Button*)(i->o))->shortcut()); - m->callback(nullptr,(void*)i); + m->callback(0,(void*)i); m->flags = (i->flags() | i->o->type()) & ~FL_MENU_HEADLINE; m->labelfont(i->o->labelfont()); m->labelsize(i->o->labelsize()); @@ -715,7 +715,7 @@ void Menu_Base_Node::build_menu() { m++; int l1 = (q->next && q->next->is_a(FLD_NODE_TYPE_Menu_Item)) ? q->next->level : level; - while (lvl > l1) {m->label(nullptr); m++; lvl--;} + while (lvl > l1) {m->label(0); m++; lvl--;} lvl = l1; } } @@ -723,14 +723,14 @@ void Menu_Base_Node::build_menu() { } Node* Menu_Base_Node::click_test(int, int) { - if (selected) return nullptr; // let user move the widget + if (selected) return 0; // let user move the widget Fl_Menu_* w = (Fl_Menu_*)o; - if (!menusize) return nullptr; + if (!menusize) return 0; const Fl_Menu_Item* save = w->mvalue(); - w->value((Fl_Menu_Item*)nullptr); + w->value((Fl_Menu_Item*)0); Fl::pushed(w); w->handle(FL_PUSH); - Fl::focus(nullptr); + Fl::focus(0); const Fl_Menu_Item* m = w->mvalue(); if (m) { // restore the settings of toggles & radio items: @@ -762,21 +762,21 @@ void Menu_Base_Node::copy_properties() { //////////////////////////////////////////////////////////////// Fl_Menu_Item button_type_menu[] = { - {"normal",0,nullptr,(void*)nullptr}, - {"popup1",0,nullptr,(void*)Fl_Menu_Button::POPUP1}, - {"popup2",0,nullptr,(void*)Fl_Menu_Button::POPUP2}, - {"popup3",0,nullptr,(void*)Fl_Menu_Button::POPUP3}, - {"popup12",0,nullptr,(void*)Fl_Menu_Button::POPUP12}, - {"popup23",0,nullptr,(void*)Fl_Menu_Button::POPUP23}, - {"popup13",0,nullptr,(void*)Fl_Menu_Button::POPUP13}, - {"popup123",0,nullptr,(void*)Fl_Menu_Button::POPUP123}, - {nullptr}}; + {"normal",0,0,(void*)0}, + {"popup1",0,0,(void*)Fl_Menu_Button::POPUP1}, + {"popup2",0,0,(void*)Fl_Menu_Button::POPUP2}, + {"popup3",0,0,(void*)Fl_Menu_Button::POPUP3}, + {"popup12",0,0,(void*)Fl_Menu_Button::POPUP12}, + {"popup23",0,0,(void*)Fl_Menu_Button::POPUP23}, + {"popup13",0,0,(void*)Fl_Menu_Button::POPUP13}, + {"popup123",0,0,(void*)Fl_Menu_Button::POPUP123}, + {0}}; Menu_Button_Node Menu_Button_Node::prototype; //////////////////////////////////////////////////////////////// -Fl_Menu_Item dummymenu[] = {{"CHOICE"},{nullptr}}; +Fl_Menu_Item dummymenu[] = {{"CHOICE"},{0}}; Choice_Node Choice_Node::prototype; @@ -793,14 +793,14 @@ void Input_Choice_Node::copy_properties() { } Node* Input_Choice_Node::click_test(int, int) { - if (selected) return nullptr; // let user move the widget + if (selected) return 0; // let user move the widget Fl_Menu_* w = ((Fl_Input_Choice*)o)->menubutton(); - if (!menusize) return nullptr; + if (!menusize) return 0; const Fl_Menu_Item* save = w->mvalue(); - w->value((Fl_Menu_Item*)nullptr); + w->value((Fl_Menu_Item*)0); Fl::pushed(w); w->handle(FL_PUSH); - Fl::focus(nullptr); + Fl::focus(0); const Fl_Menu_Item* m = w->mvalue(); if (m) { // restore the settings of toggles & radio items: @@ -816,12 +816,12 @@ Node* Input_Choice_Node::click_test(int, int) { Menu_Bar_Node Menu_Bar_Node::prototype; Fl_Menu_Item menu_bar_type_menu[] = { - {"Fl_Menu_Bar",0,nullptr,(void*)nullptr}, - {"Fl_Sys_Menu_Bar",0,nullptr,(void*)1}, - {nullptr}}; + {"Fl_Menu_Bar",0,0,(void*)0}, + {"Fl_Sys_Menu_Bar",0,0,(void*)1}, + {0}}; Menu_Bar_Node::Menu_Bar_Node() -: _proxy_name(nullptr) +: _proxy_name(0) { } @@ -835,14 +835,16 @@ Menu_Bar_Node::~Menu_Bar_Node() { This test fails if subclass() is the name of a class that the user may have derived from Fl_Sys_Menu_Bar. */ -bool Menu_Bar_Node::is_sys_menu_bar() { - if (o->type()==1) return true; - return (subclass() == "Fl_Sys_Menu_Bar"); +int Menu_Bar_Node::is_sys_menu_bar() { + if (o->type()==1) return 1; + const char* sc = subclass(); + return (sc && strcmp(sc, "Fl_Sys_Menu_Bar") == 0); } -std::string Menu_Bar_Node::sys_menubar_name() const { - if (!subclass().empty()) - return subclass(); +const char* Menu_Bar_Node::sys_menubar_name() const { + const char* sc = subclass(); + if (sc && sc[0]) + return sc; else return "Fl_Sys_Menu_Bar"; } @@ -850,7 +852,7 @@ std::string Menu_Bar_Node::sys_menubar_name() const { const char *Menu_Bar_Node::sys_menubar_proxy_name() { if (!_proxy_name) _proxy_name = (char*)::malloc(128); - ::snprintf(_proxy_name, 63, "%s_Proxy", sys_menubar_name().c_str()); + ::snprintf(_proxy_name, 63, "%s_Proxy", sys_menubar_name()); return _proxy_name; } @@ -868,8 +870,8 @@ void Menu_Bar_Node::write_static(fld::io::Code_Writer& f) { " : %s(x, y, w, h, l) { }\n" " void *_parent_class;\n" "};\n", - sys_menubar_proxy_name(), sys_menubar_name().c_str(), - sys_menubar_proxy_name(), sys_menubar_name().c_str() + sys_menubar_proxy_name(), sys_menubar_name(), + sys_menubar_proxy_name(), sys_menubar_name() ); } } diff --git a/fluid/nodes/Menu_Node.h b/fluid/nodes/Menu_Node.h index 4bf27ed34..42484ed43 100644 --- a/fluid/nodes/Menu_Node.h +++ b/fluid/nodes/Menu_Node.h @@ -58,8 +58,8 @@ public: Node* make(Strategy strategy) override; Node* make(int flags, Strategy strategy); int is_button() const override {return 1;} // this gets shortcut to work - Fl_Widget* widget(int,int,int,int) override {return nullptr;} - Widget_Node* _make() override {return nullptr;} + Fl_Widget* widget(int,int,int,int) override {return 0;} + Widget_Node* _make() override {return 0;} virtual const char* menu_name(fld::io::Code_Writer& f, int& i); int flags(); void write_static(fld::io::Code_Writer& f) override; @@ -114,7 +114,7 @@ public: typedef Menu_Item_Node super; static Submenu_Node prototype; public: - Fl_Menu_Item* subtypes() override {return nullptr;} + Fl_Menu_Item* subtypes() override {return 0;} const char* type_name() override {return "Submenu";} const char* alt_type_name() override {return "fltk::ItemGroup";} int can_have_children() const override {return 1;} @@ -299,8 +299,8 @@ public: // void write_code2(fld::io::Code_Writer& f) override; Type type() const override { return FLD_NODE_TYPE_Menu_Bar; } bool is_a(Type inType) const override { return (inType==FLD_NODE_TYPE_Menu_Bar) ? true : super::is_a(inType); } - bool is_sys_menu_bar(); - std::string sys_menubar_name() const; + int is_sys_menu_bar(); + const char* sys_menubar_name() const; const char *sys_menubar_proxy_name(); protected: char *_proxy_name; diff --git a/fluid/nodes/Node.cxx b/fluid/nodes/Node.cxx index be54ce3a1..2971bad2d 100644 --- a/fluid/nodes/Node.cxx +++ b/fluid/nodes/Node.cxx @@ -151,16 +151,16 @@ void print_project_tree() { */ bool validate_project_tree() { // Validate `first` and `last` - if (Fluid.proj.tree.first == nullptr) { - if (Fluid.proj.tree.last == nullptr) { + if (Fluid.proj.tree.first == 0) { + if (Fluid.proj.tree.last == 0) { return true; } else { - fprintf(stderr, "ERROR: `first` is nullptr, but `last` is not!\n"); + fprintf(stderr, "ERROR: `first` is 0, but `last` is not!\n"); return false; } } - if (Fluid.proj.tree.last == nullptr) { - fprintf(stderr, "ERROR: `last` is nullptr, but `first` is not!\n"); + if (Fluid.proj.tree.last == 0) { + fprintf(stderr, "ERROR: `last` is 0, but `first` is not!\n"); return false; } // Validate the branch linkage, parent links, etc. @@ -242,9 +242,9 @@ bool validate_branch(class Node *root) { } // Validate the `parent` entry for (Node *p = t->prev; ; p = p->prev) { - if (p == nullptr) { - if (t->parent != nullptr) { - fprintf(stderr, "ERROR: `parent` pointer should be nullptr!\n"); + if (p == 0) { + if (t->parent != 0) { + fprintf(stderr, "ERROR: `parent` pointer should be 0!\n"); return false; } break; @@ -264,7 +264,7 @@ bool validate_branch(class Node *root) { #endif void select_all_cb(Fl_Widget *,void *) { - Node *p = Fluid.proj.tree.current ? Fluid.proj.tree.current->parent : nullptr; + Node *p = Fluid.proj.tree.current ? Fluid.proj.tree.current->parent : 0; if (in_this_only) { Node *t = p; for (; t && t != in_this_only; t = t->parent) {/*empty*/} @@ -288,7 +288,7 @@ void select_all_cb(Fl_Widget *,void *) { } void select_none_cb(Fl_Widget *,void *) { - Node *p = Fluid.proj.tree.current ? Fluid.proj.tree.current->parent : nullptr; + Node *p = Fluid.proj.tree.current ? Fluid.proj.tree.current->parent : 0; if (in_this_only) { Node *t = p; for (; t && t != in_this_only; t = t->parent) {/*empty*/} @@ -409,12 +409,12 @@ void delete_all(int selected_only) { widget_browser->hposition(0); widget_browser->vposition(0); } - Fluid.layout_list.remove_all(FLD_TOOL_STORE_PROJECT); - Fluid.layout_list.current_suite(0); - Fluid.layout_list.current_preset(0); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->remove_all(FLD_TOOL_STORE_PROJECT); + Fluid.layout_list->current_suite(0); + Fluid.layout_list->current_preset(0); + Fluid.layout_list->update_dialogs(); } - selection_changed(nullptr); + selection_changed(0); if (widget_browser) { if (selected_only) widget_browser->restore_scroll_position(); @@ -425,7 +425,7 @@ void delete_all(int selected_only) { /** Update a string. Replace a string pointer with new value, strips leading/trailing blanks. As a side effect, this call also sets the mod flags. - \param[in] n new string, can be nullptr + \param[in] n new string, can be 0 \param[out] p update this pointer, possibly reallocate memory \param[in] nostrip if set, do not strip leading and trailing spaces and tabs \return 1 if the string in p changed @@ -439,13 +439,13 @@ int storestring(const char *n, const char * & p, int nostrip) { const char *e = n + strlen(n); if (!nostrip) while (e > n && isspace((int)(unsigned char)*(e-1))) e--; length = int(e-n); - if (!length) n = nullptr; + if (!length) n = 0; } if (n == p) return 0; if (n && p && !strncmp(n,p,length) && !p[length]) return 0; if (p) free((void *)p); if (!n || !*n) { - p = nullptr; + p = 0; } else { char *q = (char *)malloc(length+1); strlcpy(q,n,length+1); @@ -457,7 +457,7 @@ int storestring(const char *n, const char * & p, int nostrip) { // C++11 version, still using the original to copy all the side effects. int storestring(const std::string& n, std::string& p, int nostrip) { - const char *buffer { nullptr }; + const char *buffer { 0 }; int ret = storestring(n.c_str(), buffer); if (buffer) { p = buffer; @@ -496,12 +496,12 @@ void update_visibility_flag(Node *p) { */ /** \var Node *Node::next Points to the next node in the doubly linked list. - If this is nullptr, we are at the end of the list. + If this is 0, we are at the end of the list. Used for simulating a tree structure via a doubly linked list. */ /** \var Node *Node::prev Link to the next node in the tree structure. - If this is nullptr, we are at the beginning of the list. + If this is 0, we are at the beginning of the list. Used for simulating a tree structure via a doubly linked list. */ @@ -509,21 +509,21 @@ void update_visibility_flag(Node *p) { Constructor and base for any node in the widget tree. */ Node::Node() : - name_(nullptr), - label_(nullptr), - callback_(nullptr), - user_data_(nullptr), - user_data_type_(nullptr), - comment_(nullptr), + name_(0), + label_(0), + callback_(0), + user_data_(0), + user_data_type_(0), + comment_(0), uid_(0), - parent(nullptr), + parent(0), new_selected(0), selected(0), folded_(0), visible(0), level(0), - next(nullptr), prev(nullptr), - factory(nullptr), + next(0), prev(0), + factory(0), code_static_start(-1), code_static_end(-1), code1_start(-1), code1_end(-1), code2_start(-1), code2_end(-1), @@ -549,9 +549,9 @@ Node::~Node() { if (next) next->prev = prev; // else last = prev; if (Fluid.proj.tree.last == this) Fluid.proj.tree.last = prev; if (Fluid.proj.tree.first == this) Fluid.proj.tree.first = next; - if (Fluid.proj.tree.current == this) Fluid.proj.tree.current = nullptr; - if (current_widget == this) current_widget = nullptr; - if (current_node == this) current_node = nullptr; + if (Fluid.proj.tree.current == this) Fluid.proj.tree.current = 0; + if (current_widget == this) current_widget = 0; + if (current_node == this) current_node = 0; if (parent) parent->remove_child(this); if (name_) free((void*)name_); if (label_) free((void*)label_); @@ -561,30 +561,30 @@ Node::~Node() { if (comment_) free((void*)comment_); } -// Return the previous sibling in the tree structure or nullptr. +// Return the previous sibling in the tree structure or 0. Node *Node::prev_sibling() { Node *n; for (n = prev; n && n->level > level; n = n->prev) ; if (n && (n->level == level)) return n; - return nullptr; + return 0; } -// Return the next sibling in the tree structure or nullptr. +// Return the next sibling in the tree structure or 0. Node *Node::next_sibling() { Node *n; for (n = next; n && n->level > level; n = n->next) ; if (n && (n->level == level)) return n; - return nullptr; + return 0; } -// Return the first child or nullptr +// Return the first child or 0 Node *Node::first_child() { Node *n = next; if (n->level > level) return n; - return nullptr; + return 0; } // Generate a descriptive text for this item, to put in browser & window titles @@ -597,28 +597,28 @@ const char* Node::title() { /** Return the window that contains this widget. - \return nullptr if this is not a widget. + \return 0 if this is not a widget. */ Window_Node *Node::window() { if (!is_widget()) - return nullptr; + return 0; for (Node *t = this; t; t=t->parent) if (t->is_a(FLD_NODE_TYPE_Window)) return (Window_Node*)t; - return nullptr; + return 0; } /** Return the group that contains this widget. - \return nullptr if this is not a widget. + \return 0 if this is not a widget. */ Group_Node *Node::group() { if (!is_widget()) - return nullptr; + return 0; for (Node *t = this; t; t=t->parent) if (t->is_a(FLD_NODE_TYPE_Group)) return (Group_Node*)t; - return nullptr; + return 0; } /** @@ -643,15 +643,15 @@ void Node::add(Node *anchor, Strategy strategy) { #endif #endif - Node *target = nullptr; // insert self before target node, if nullptr, insert last - Node *target_parent = nullptr; // this will be the new parent for branch + Node *target = 0; // insert self before target node, if 0, insert last + Node *target_parent = 0; // this will be the new parent for branch int target_level = 0; // adjust self to this new level // Find the node after our insertion position switch (strategy.placement()) { case Strategy::AS_FIRST_CHILD: default: - if (anchor == nullptr) { + if (anchor == 0) { target = Fluid.proj.tree.first; } else { target = anchor->next; @@ -660,7 +660,7 @@ void Node::add(Node *anchor, Strategy strategy) { } break; case Strategy::AS_LAST_CHILD: - if (anchor == nullptr) { + if (anchor == 0) { /* empty */ } else { for (target = anchor->next; target && target->level > anchor->level; target = target->next) {/*empty*/} @@ -669,7 +669,7 @@ void Node::add(Node *anchor, Strategy strategy) { } break; case Strategy::AFTER_CURRENT: - if (anchor == nullptr) { + if (anchor == 0) { target = Fluid.proj.tree.first; } else { for (target = anchor->next; target && target->level > anchor->level; target = target->next) {/*empty*/} @@ -695,14 +695,14 @@ void Node::add(Node *anchor, Strategy strategy) { t->parent = target_parent; } - // Now link ourselves and our children before 'target', or last, if 'target' is nullptr + // Now link ourselves and our children before 'target', or last, if 'target' is 0 if (target) { prev = target->prev; target->prev = end; end->next = target; } else { prev = Fluid.proj.tree.last; - end->next = nullptr; + end->next = 0; Fluid.proj.tree.last = end; } if (prev) { @@ -716,13 +716,13 @@ void Node::add(Node *anchor, Strategy strategy) { do { tp->ensure_unique_uid(); tp = tp->next; - } while (tp!=end && tp!=nullptr); + } while (tp!=end && tp!=0); } // Give the widgets in our tree a chance to update themselves for (Node *t = this; t && t!=end->next; t = t->next) { if (target_parent && (t->level == target_level)) - target_parent->add_child(t, nullptr); + target_parent->add_child(t, 0); update_visibility_flag(t); } @@ -769,7 +769,7 @@ void Node::insert(Node *g) { do { tp->ensure_unique_uid(); tp = tp->next; - } while (tp!=end && tp!=nullptr); + } while (tp!=end && tp!=0); } // tell parent that it has a new child, so it can update itself if (parent) parent->add_child(this, g); @@ -783,7 +783,7 @@ int Node::msgnum() { for (count = 0, p = this; p;) { if (p->label()) count ++; - if (p != this && p->is_widget() && !((Widget_Node *)p)->tooltip().empty()) count ++; + if (p != this && p->is_widget() && ((Widget_Node *)p)->tooltip() && ((Widget_Node *)p)->tooltip()[0]) count ++; if (p->prev) p = p->prev; else p = p->parent; @@ -799,7 +799,7 @@ int Node::msgnum() { the widget_browser, so \c Fluid.proj.tree.first and \c Fluid.proj.tree.last do not apply to it. - \return the node that follows this node after the operation; can be nullptr + \return the node that follows this node after the operation; can be 0 */ Node *Node::remove() { // find the last child of this node @@ -820,13 +820,13 @@ Node *Node::remove() { else Fluid.proj.tree.last = prev; Node *r = end->next; - prev = end->next = nullptr; + prev = end->next = 0; // allow the parent to update changes in the UI if (parent) parent->remove_child(this); - parent = nullptr; + parent = 0; // tell the widget_browser that we removed some nodes widget_browser->redraw(); - selection_changed(nullptr); + selection_changed(0); return r; } @@ -1130,7 +1130,7 @@ void Node::write_comment_inline_c(fld::io::Code_Writer& f, const char *pre) { if (comment() && *comment()) { const char *s = comment(); - if (strchr(s, '\n')==nullptr) { + if (strchr(s, '\n')==0) { // single line comment if (pre) f.write_c("%s", pre); f.write_c("// %s\n", s); @@ -1173,7 +1173,7 @@ void Node::write_comment_inline_c(fld::io::Code_Writer& f, const char *pre) \see leave_live_mode() */ Fl_Widget *Node::enter_live_mode(int) { - return nullptr; + return 0; } /** @@ -1199,7 +1199,7 @@ void Node::copy_properties() { */ int Node::user_defined(const char* cbname) const { for (Node* p = Fluid.proj.tree.first; p ; p = p->next) - if (p->is_a(FLD_NODE_TYPE_Function) && p->name() != nullptr) + if (p->is_a(FLD_NODE_TYPE_Function) && p->name() != 0) if (strncmp(p->name(), cbname, strlen(cbname)) == 0) if (p->name()[strlen(cbname)] == '(') return 1; @@ -1222,7 +1222,7 @@ const char *Node::callback_name(fld::io::Code_Writer& f) { \param need_nest if clear, search up one level to the first enclosing class. If set, recurse all the way up to the top node. \return the name of the enclosing class, or names of the enclosing classes - in a static buffe (don't call free), or nullptr if this Type is not inside a class + in a static buffe (don't call free), or 0 if this Type is not inside a class */ const char* Node::class_name(const int need_nest) const { Node* p = parent; @@ -1230,7 +1230,7 @@ const char* Node::class_name(const int need_nest) const { if (p->is_class()) { // see if we are nested in another class, we must fully-qualify name: // this is lame but works... - const char* q = nullptr; + const char* q = 0; if(need_nest) q=p->class_name(need_nest); if (q) { static char s[256]; @@ -1243,7 +1243,7 @@ const char* Node::class_name(const int need_nest) const { } p = p->parent; } - return nullptr; + return 0; } /** @@ -1297,7 +1297,7 @@ unsigned short Node::set_uid(unsigned short suggested_uid) { } } // we are done if we have not fund the suggested id anywhere else - if (tp==nullptr) { + if (tp==0) { break; } // try again with another random number diff --git a/fluid/nodes/Node.h b/fluid/nodes/Node.h index 1c94e493d..02338903f 100644 --- a/fluid/nodes/Node.h +++ b/fluid/nodes/Node.h @@ -167,7 +167,7 @@ protected: /** Label text of a widget. */ const char *label_; /** If it is just a word, it's the name of the callback function. Otherwise - it is the full callback C++ code. Can be nullptr. */ + it is the full callback C++ code. Can be 0. */ const char *callback_; /** Widget user data field as C++ text. */ const char *user_data_; @@ -243,7 +243,7 @@ public: const char *comment() { return comment_; } void comment(const char *); - virtual Node* click_test(int,int) { return nullptr; } + virtual Node* click_test(int,int) { return 0; } virtual void add_child(Node *, Node *beforethis) { (void)beforethis; } virtual void move_child(Node *, Node *beforethis) { (void)beforethis; } @@ -274,7 +274,7 @@ public: virtual void write_code2(fld::io::Code_Writer& f); // code and .h after children void write_comment_h(fld::io::Code_Writer& f, const char *ind=""); // write the commentary text into the header file void write_comment_c(fld::io::Code_Writer& f, const char *ind=""); // write the commentary text into the source file - void write_comment_inline_c(fld::io::Code_Writer& f, const char *ind=nullptr); // write the commentary text + void write_comment_inline_c(fld::io::Code_Writer& f, const char *ind=0); // write the commentary text // live mode virtual Fl_Widget *enter_live_mode(int top=0); // build widgets needed for live mode diff --git a/fluid/nodes/Tree.cxx b/fluid/nodes/Tree.cxx index 92b5e7506..a163c4181 100644 --- a/fluid/nodes/Tree.cxx +++ b/fluid/nodes/Tree.cxx @@ -89,13 +89,13 @@ Tree::Tree(Project &proj) Walk the tree and return the node with this uid. \param[in] uid any number between 0 and 65535 - \return the node with this uid, or nullptr if not found + \return the node with this uid, or 0 if not found */ Node *Tree::find_by_uid(unsigned short uid) { for (auto tp: all_nodes()) { if (tp->get_uid() == uid) return tp; } - return nullptr; + return 0; } @@ -103,7 +103,7 @@ Node *Tree::find_by_uid(unsigned short uid) { \param[in] text_type 0=source file, 1=header, 2=.fl project file \param[in] crsr cursor position in text - \return the node we found or nullptr + \return the node we found or 0 */ Node *Tree::find_in_text(int text_type, int crsr) { for (auto node: all_nodes()) { @@ -124,5 +124,5 @@ Node *Tree::find_in_text(int text_type, int crsr) { break; } } - return nullptr; + return 0; } diff --git a/fluid/nodes/Tree.h b/fluid/nodes/Tree.h index f494af651..f1a338630 100644 --- a/fluid/nodes/Tree.h +++ b/fluid/nodes/Tree.h @@ -31,7 +31,7 @@ class Tree { // A class that can iterate over the entire scene graph. class Iterator { - Node *type_ = nullptr; + Node *type_ = 0; bool only_selected_ = false; public: explicit Iterator(Node *t, bool only_selected); @@ -47,12 +47,12 @@ class Tree { public: Container(Tree &tree, bool only_selected) : tree_(tree), only_selected_(only_selected) { } Iterator begin() { return Iterator(tree_.first, only_selected_); } - Iterator end() { return Iterator(nullptr, only_selected_); } + Iterator end() { return Iterator(0, only_selected_); } }; // A class that iterate over the scene graph, but returns only nodes of type widget. class WIterator { - Node *type_ = nullptr; + Node *type_ = 0; bool only_selected_ = false; public: explicit WIterator(Node *t, bool only_selected); @@ -68,7 +68,7 @@ class Tree { public: WContainer(Tree &tree, bool only_selected) : tree_(tree), only_selected_(only_selected) { } WIterator begin() { return WIterator(tree_.first, only_selected_); } - WIterator end() { return WIterator(nullptr, only_selected_); } + WIterator end() { return WIterator(0, only_selected_); } }; /// Link Tree class to the project. @@ -76,10 +76,10 @@ class Tree { public: - Node *first = nullptr; - Node *last = nullptr; - Node *current = nullptr; // most recently picked object - Node *current_dnd = nullptr; + Node *first = 0; + Node *last = 0; + Node *current = 0; // most recently picked object + Node *current_dnd = 0; /// If this is greater zero, widgets will be allowed to lay out their children. int allow_layout = 0; @@ -87,7 +87,7 @@ public: Tree(Project &proj); - bool empty() { return first == nullptr; } + bool empty() { return first == 0; } // Iterators: `for (auto &n: tree.all_nodes()) { n.print(); } Container all_nodes() { return Container(*this, false); } diff --git a/fluid/nodes/Widget_Node.cxx b/fluid/nodes/Widget_Node.cxx index 929a88bf9..6f5a6a0fb 100644 --- a/fluid/nodes/Widget_Node.cxx +++ b/fluid/nodes/Widget_Node.cxx @@ -38,6 +38,7 @@ #include <FL/Fl_Spinner.H> #include <FL/Fl_Window.H> #include <FL/Fl_Flex.H> +#include <FL/filename.H> #include "../src/flstring.h" #include <stdio.h> @@ -70,16 +71,16 @@ int Widget_Node::is_public() const { return public_; } -std::string subclassname(Node* l) { +const char* subclassname(Node* l) { if (l->is_a(FLD_NODE_TYPE_Menu_Bar)) { - Menu_Bar_Node* mb = static_cast<Menu_Bar_Node*>(l); + Menu_Bar_Node* mb = (Menu_Bar_Node*)l; if (mb->is_sys_menu_bar()) return mb->sys_menubar_name(); } if (l->is_widget()) { Widget_Node* p = (Widget_Node*)l; - std::string c = p->subclass(); - if (!c.empty()) + const char* c = p->subclass(); + if (c && c[0]) return c; if (l->is_class()) return "Fl_Group"; @@ -118,7 +119,7 @@ Node* Widget_Node::make(Strategy strategy) { } if (!pp || !pp->is_true_widget() || !anchor->is_true_widget()) { fl_message("Please select a group widget or window"); - return nullptr; + return 0; } Widget_Node* p = (Widget_Node*)pp; @@ -170,7 +171,7 @@ Node* Widget_Node::make(Strategy strategy) { // Construct the Fl_Widget: t->o = widget(X,Y,W,H); if (strategy.source() == Strategy::FROM_FILE) - t->o->label(nullptr); + t->o->label(0); else if (t->o->label()) t->label(t->o->label()); // allow editing t->o->user_data((void*)t); @@ -199,7 +200,7 @@ void Widget_Node::setimage(Image_Asset* i) { o->image()->scale(iw, ih, 0, 1); } } else { - o->image(nullptr); + o->image(0); //scale_image_w_ = scale_image_h_ = 0; } redraw(); @@ -221,7 +222,7 @@ void Widget_Node::setinactive(Image_Asset* i) { o->deimage()->scale(iw, ih, 0, 1); } } else { - o->deimage(nullptr); + o->deimage(0); //scale_deimage_w_ = scale_deimage_h_ = 0; } redraw(); @@ -232,6 +233,32 @@ void Widget_Node::setlabel(const char* n) { redraw(); } +Widget_Node::Widget_Node() { + int i; + for (i = 0; i < NUM_EXTRA_CODE; i++) + extra_code_[i] = 0; + subclass_ = 0; + tooltip_ = 0; + image_name_ = 0; + inactive_name_ = 0; + hotspot_ = 0; + menu_headline_ = 0; + override_visible_ = 0; + live_widget = 0; + o = 0; + public_ = 1; + bind_image_ = 0; + compress_image_ = 1; + scale_image_w_ = 0; + scale_image_h_ = 0; + image = 0; + bind_deimage_ = 0; + compress_deimage_ = 1; + scale_deimage_w_ = 0; + scale_deimage_h_ = 0; + inactive = 0; +} + Widget_Node::~Widget_Node() { if (o) { Fl_Window* win = o->window(); @@ -243,34 +270,47 @@ Widget_Node::~Widget_Node() { image->dec_ref(); if (inactive) inactive->dec_ref(); + int i; + for (i = 0; i < NUM_EXTRA_CODE; i++) + if (extra_code_[i]) free(extra_code_[i]); + if (subclass_) free(subclass_); + if (tooltip_) free(tooltip_); + if (image_name_) free(image_name_); + if (inactive_name_) free(inactive_name_); } -void Widget_Node::extra_code(int m, const std::string& n) { - storestring(n, extra_code_[m]); +void Widget_Node::extra_code(int m, const char *n) { + if (extra_code_[m]) free(extra_code_[m]); + extra_code_[m] = (n && n[0]) ? fl_strdup(n) : 0; } -void Widget_Node::subclass(const std::string& n) { - if (storestring(n, subclass_) && visible) +void Widget_Node::subclass(const char *n) { + if (subclass_) free(subclass_); + subclass_ = (n && n[0]) ? fl_strdup(n) : 0; + if (visible) redraw_browser(); } -void Widget_Node::tooltip(const std::string& text) { - storestring(text, tooltip_); - if (text.empty()) { - o->tooltip(nullptr); +void Widget_Node::tooltip(const char *text) { + if (tooltip_) free(tooltip_); + tooltip_ = (text && text[0]) ? fl_strdup(text) : 0; + if (!text || !text[0]) { + o->tooltip(0); } else { - o->copy_tooltip(text.c_str()); + o->copy_tooltip(text); } } -void Widget_Node::image_name(const std::string& name) { - setimage(Image_Asset::find(name.c_str())); - storestring(name, image_name_); +void Widget_Node::image_name(const char *name) { + setimage(Image_Asset::find(name)); + if (image_name_) free(image_name_); + image_name_ = (name && name[0]) ? fl_strdup(name) : 0; } -void Widget_Node::inactive_name(const std::string& name) { - setinactive(Image_Asset::find(name.c_str())); - storestring(name, inactive_name_); +void Widget_Node::inactive_name(const char *name) { + setinactive(Image_Asset::find(name)); + if (inactive_name_) free(inactive_name_); + inactive_name_ = (name && name[0]) ? fl_strdup(name) : 0; } void Widget_Node::redraw() { @@ -282,7 +322,7 @@ void Widget_Node::redraw() { } while (t && t->is_a(FLD_NODE_TYPE_Menu_Item)); // kludge to cause build_menu to be called again: if (t) - t->add_child(nullptr, nullptr); + t->add_child(0, 0); } else { while (t->parent && t->parent->is_widget()) t = t->parent; @@ -293,7 +333,7 @@ void Widget_Node::redraw() { // the recursive part sorts all children, returns pointer to next: Node* sort(Node* parent) { Node* f; - Node* n = nullptr; + Node* n = 0; for (f = parent ? parent->next : Fluid.proj.tree.first; ; f = n) { if (!f || (parent && f->level <= parent->level)) break; @@ -322,7 +362,7 @@ Node* sort(Node* parent) { //////////////////////////////////////////////////////////////// // The control panels! -Fl_Window* the_panel = nullptr; +Fl_Window* the_panel = 0; // All the callbacks use the argument to indicate whether to load or store. // This avoids the need for pointers to all the widgets, and keeps the @@ -331,8 +371,8 @@ Fl_Window* the_panel = nullptr; // with any actual useful values for the argument. I also use this to // initialized parts of the widget that are nyi by fluid. -Node* current_node = nullptr; -Widget_Node* current_widget = nullptr; // one of the selected ones +Node* current_node = 0; +Widget_Node* current_widget = 0; // one of the selected ones void* const LOAD = (void *)"LOAD"; // "magic" pointer to indicate that we need to load values into the dialog int numselected = 0; // number selected int haderror = 0; @@ -569,7 +609,7 @@ fld::widget::Formula_Input_Vars widget_vars[] = { { "cy", vars_cy_cb }, { "cw", vars_cw_cb }, { "ch", vars_ch_cb }, - { nullptr } + { 0 } }; //////////////////////////////////////////////////////////////// @@ -608,86 +648,86 @@ int item_number(Fl_Menu_Item* m, const char* i) { #define ZERO_ENTRY 1000 Fl_Menu_Item boxmenu[] = { - {"NO_BOX",0,nullptr,(void *)ZERO_ENTRY}, - {"boxes",0,nullptr,nullptr,FL_SUBMENU}, - {"UP_BOX",0,nullptr,(void *)FL_UP_BOX}, - {"DOWN_BOX",0,nullptr,(void *)FL_DOWN_BOX}, - {"FLAT_BOX",0,nullptr,(void *)FL_FLAT_BOX}, - {"BORDER_BOX",0,nullptr,(void *)FL_BORDER_BOX}, - {"THIN_UP_BOX",0,nullptr,(void *)FL_THIN_UP_BOX}, - {"THIN_DOWN_BOX",0,nullptr,(void *)FL_THIN_DOWN_BOX}, - {"ENGRAVED_BOX",0,nullptr,(void *)FL_ENGRAVED_BOX}, - {"EMBOSSED_BOX",0,nullptr,(void *)FL_EMBOSSED_BOX}, - {"ROUND_UP_BOX",0,nullptr,(void *)FL_ROUND_UP_BOX}, - {"ROUND_DOWN_BOX",0,nullptr,(void *)FL_ROUND_DOWN_BOX}, - {"DIAMOND_UP_BOX",0,nullptr,(void *)FL_DIAMOND_UP_BOX}, - {"DIAMOND_DOWN_BOX",0,nullptr,(void *)FL_DIAMOND_DOWN_BOX}, - {"SHADOW_BOX",0,nullptr,(void *)FL_SHADOW_BOX}, - {"ROUNDED_BOX",0,nullptr,(void *)FL_ROUNDED_BOX}, - {"RSHADOW_BOX",0,nullptr,(void *)FL_RSHADOW_BOX}, - {"RFLAT_BOX",0,nullptr,(void *)FL_RFLAT_BOX}, - {"OVAL_BOX",0,nullptr,(void *)FL_OVAL_BOX}, - {"OSHADOW_BOX",0,nullptr,(void *)FL_OSHADOW_BOX}, - {"OFLAT_BOX",0,nullptr,(void *)FL_OFLAT_BOX}, - {"PLASTIC_UP_BOX",0,nullptr,(void *)FL_PLASTIC_UP_BOX}, - {"PLASTIC_DOWN_BOX",0,nullptr,(void *)FL_PLASTIC_DOWN_BOX}, - {"PLASTIC_THIN_UP_BOX",0,nullptr,(void *)FL_PLASTIC_THIN_UP_BOX}, - {"PLASTIC_THIN_DOWN_BOX",0,nullptr,(void *)FL_PLASTIC_THIN_DOWN_BOX}, - {"PLASTIC_ROUND_UP_BOX",0,nullptr,(void *)FL_PLASTIC_ROUND_UP_BOX}, - {"PLASTIC_ROUND_DOWN_BOX",0,nullptr,(void *)FL_PLASTIC_ROUND_DOWN_BOX}, - {"GTK_UP_BOX",0,nullptr,(void *)FL_GTK_UP_BOX}, - {"GTK_DOWN_BOX",0,nullptr,(void *)FL_GTK_DOWN_BOX}, - {"GTK_THIN_UP_BOX",0,nullptr,(void *)FL_GTK_THIN_UP_BOX}, - {"GTK_THIN_DOWN_BOX",0,nullptr,(void *)FL_GTK_THIN_DOWN_BOX}, - {"GTK_ROUND_UP_BOX",0,nullptr,(void *)FL_GTK_ROUND_UP_BOX}, - {"GTK_ROUND_DOWN_BOX",0,nullptr,(void *)FL_GTK_ROUND_DOWN_BOX}, - {"GLEAM_UP_BOX",0,nullptr,(void *)FL_GLEAM_UP_BOX}, - {"GLEAM_DOWN_BOX",0,nullptr,(void *)FL_GLEAM_DOWN_BOX}, - {"GLEAM_THIN_UP_BOX",0,nullptr,(void *)FL_GLEAM_THIN_UP_BOX}, - {"GLEAM_THIN_DOWN_BOX",0,nullptr,(void *)FL_GLEAM_THIN_DOWN_BOX}, - {"GLEAM_ROUND_UP_BOX",0,nullptr,(void *)FL_GLEAM_ROUND_UP_BOX}, - {"GLEAM_ROUND_DOWN_BOX",0,nullptr,(void *)FL_GLEAM_ROUND_DOWN_BOX}, - {"OXY_UP_BOX",0,nullptr,(void *)FL_OXY_UP_BOX}, - {"OXY_DOWN_BOX",0,nullptr,(void *)FL_OXY_DOWN_BOX}, - {"OXY_THIN_UP_BOX",0,nullptr,(void *)FL_OXY_THIN_UP_BOX}, - {"OXY_THIN_DOWN_BOX",0,nullptr,(void *)FL_OXY_THIN_DOWN_BOX}, - {"OXY_ROUND_UP_BOX",0,nullptr,(void *)FL_OXY_ROUND_UP_BOX}, - {"OXY_ROUND_DOWN_BOX",0,nullptr,(void *)FL_OXY_ROUND_DOWN_BOX}, - {"OXY_BUTTON_UP_BOX",0,nullptr,(void *)FL_OXY_BUTTON_UP_BOX}, - {"OXY_BUTTON_DOWN_BOX",0,nullptr,(void *)FL_OXY_BUTTON_DOWN_BOX}, - {nullptr}, - {"frames",0,nullptr,nullptr,FL_SUBMENU}, - {"UP_FRAME",0,nullptr,(void *)FL_UP_FRAME}, - {"DOWN_FRAME",0,nullptr,(void *)FL_DOWN_FRAME}, - {"THIN_UP_FRAME",0,nullptr,(void *)FL_THIN_UP_FRAME}, - {"THIN_DOWN_FRAME",0,nullptr,(void *)FL_THIN_DOWN_FRAME}, - {"ENGRAVED_FRAME",0,nullptr,(void *)FL_ENGRAVED_FRAME}, - {"EMBOSSED_FRAME",0,nullptr,(void *)FL_EMBOSSED_FRAME}, - {"BORDER_FRAME",0,nullptr,(void *)FL_BORDER_FRAME}, - {"SHADOW_FRAME",0,nullptr,(void *)FL_SHADOW_FRAME}, - {"ROUNDED_FRAME",0,nullptr,(void *)FL_ROUNDED_FRAME}, - {"OVAL_FRAME",0,nullptr,(void *)FL_OVAL_FRAME}, - {"PLASTIC_UP_FRAME",0,nullptr,(void *)FL_PLASTIC_UP_FRAME}, - {"PLASTIC_DOWN_FRAME",0,nullptr,(void *)FL_PLASTIC_DOWN_FRAME}, - {"GTK_UP_FRAME",0,nullptr,(void *)FL_GTK_UP_FRAME}, - {"GTK_DOWN_FRAME",0,nullptr,(void *)FL_GTK_DOWN_FRAME}, - {"GTK_THIN_UP_FRAME",0,nullptr,(void *)FL_GTK_THIN_UP_FRAME}, - {"GTK_THIN_DOWN_FRAME",0,nullptr,(void *)FL_GTK_THIN_DOWN_FRAME}, - {"GLEAM_UP_FRAME",0,nullptr,(void *)FL_GLEAM_UP_FRAME}, - {"GLEAM_DOWN_FRAME",0,nullptr,(void *)FL_GLEAM_DOWN_FRAME}, - {"OXY_UP_FRAME",0,nullptr,(void *)FL_OXY_UP_FRAME}, - {"OXY_DOWN_FRAME",0,nullptr,(void *)FL_OXY_DOWN_FRAME}, - {"OXY_THIN_UP_FRAME",0,nullptr,(void *)FL_OXY_THIN_UP_FRAME}, - {"OXY_THIN_DOWN_FRAME",0,nullptr,(void *)FL_OXY_THIN_DOWN_FRAME}, - {nullptr}, - {nullptr}}; + {"NO_BOX",0,0,(void *)ZERO_ENTRY}, + {"boxes",0,0,0,FL_SUBMENU}, + {"UP_BOX",0,0,(void *)FL_UP_BOX}, + {"DOWN_BOX",0,0,(void *)FL_DOWN_BOX}, + {"FLAT_BOX",0,0,(void *)FL_FLAT_BOX}, + {"BORDER_BOX",0,0,(void *)FL_BORDER_BOX}, + {"THIN_UP_BOX",0,0,(void *)FL_THIN_UP_BOX}, + {"THIN_DOWN_BOX",0,0,(void *)FL_THIN_DOWN_BOX}, + {"ENGRAVED_BOX",0,0,(void *)FL_ENGRAVED_BOX}, + {"EMBOSSED_BOX",0,0,(void *)FL_EMBOSSED_BOX}, + {"ROUND_UP_BOX",0,0,(void *)FL_ROUND_UP_BOX}, + {"ROUND_DOWN_BOX",0,0,(void *)FL_ROUND_DOWN_BOX}, + {"DIAMOND_UP_BOX",0,0,(void *)FL_DIAMOND_UP_BOX}, + {"DIAMOND_DOWN_BOX",0,0,(void *)FL_DIAMOND_DOWN_BOX}, + {"SHADOW_BOX",0,0,(void *)FL_SHADOW_BOX}, + {"ROUNDED_BOX",0,0,(void *)FL_ROUNDED_BOX}, + {"RSHADOW_BOX",0,0,(void *)FL_RSHADOW_BOX}, + {"RFLAT_BOX",0,0,(void *)FL_RFLAT_BOX}, + {"OVAL_BOX",0,0,(void *)FL_OVAL_BOX}, + {"OSHADOW_BOX",0,0,(void *)FL_OSHADOW_BOX}, + {"OFLAT_BOX",0,0,(void *)FL_OFLAT_BOX}, + {"PLASTIC_UP_BOX",0,0,(void *)FL_PLASTIC_UP_BOX}, + {"PLASTIC_DOWN_BOX",0,0,(void *)FL_PLASTIC_DOWN_BOX}, + {"PLASTIC_THIN_UP_BOX",0,0,(void *)FL_PLASTIC_THIN_UP_BOX}, + {"PLASTIC_THIN_DOWN_BOX",0,0,(void *)FL_PLASTIC_THIN_DOWN_BOX}, + {"PLASTIC_ROUND_UP_BOX",0,0,(void *)FL_PLASTIC_ROUND_UP_BOX}, + {"PLASTIC_ROUND_DOWN_BOX",0,0,(void *)FL_PLASTIC_ROUND_DOWN_BOX}, + {"GTK_UP_BOX",0,0,(void *)FL_GTK_UP_BOX}, + {"GTK_DOWN_BOX",0,0,(void *)FL_GTK_DOWN_BOX}, + {"GTK_THIN_UP_BOX",0,0,(void *)FL_GTK_THIN_UP_BOX}, + {"GTK_THIN_DOWN_BOX",0,0,(void *)FL_GTK_THIN_DOWN_BOX}, + {"GTK_ROUND_UP_BOX",0,0,(void *)FL_GTK_ROUND_UP_BOX}, + {"GTK_ROUND_DOWN_BOX",0,0,(void *)FL_GTK_ROUND_DOWN_BOX}, + {"GLEAM_UP_BOX",0,0,(void *)FL_GLEAM_UP_BOX}, + {"GLEAM_DOWN_BOX",0,0,(void *)FL_GLEAM_DOWN_BOX}, + {"GLEAM_THIN_UP_BOX",0,0,(void *)FL_GLEAM_THIN_UP_BOX}, + {"GLEAM_THIN_DOWN_BOX",0,0,(void *)FL_GLEAM_THIN_DOWN_BOX}, + {"GLEAM_ROUND_UP_BOX",0,0,(void *)FL_GLEAM_ROUND_UP_BOX}, + {"GLEAM_ROUND_DOWN_BOX",0,0,(void *)FL_GLEAM_ROUND_DOWN_BOX}, + {"OXY_UP_BOX",0,0,(void *)FL_OXY_UP_BOX}, + {"OXY_DOWN_BOX",0,0,(void *)FL_OXY_DOWN_BOX}, + {"OXY_THIN_UP_BOX",0,0,(void *)FL_OXY_THIN_UP_BOX}, + {"OXY_THIN_DOWN_BOX",0,0,(void *)FL_OXY_THIN_DOWN_BOX}, + {"OXY_ROUND_UP_BOX",0,0,(void *)FL_OXY_ROUND_UP_BOX}, + {"OXY_ROUND_DOWN_BOX",0,0,(void *)FL_OXY_ROUND_DOWN_BOX}, + {"OXY_BUTTON_UP_BOX",0,0,(void *)FL_OXY_BUTTON_UP_BOX}, + {"OXY_BUTTON_DOWN_BOX",0,0,(void *)FL_OXY_BUTTON_DOWN_BOX}, + {0}, + {"frames",0,0,0,FL_SUBMENU}, + {"UP_FRAME",0,0,(void *)FL_UP_FRAME}, + {"DOWN_FRAME",0,0,(void *)FL_DOWN_FRAME}, + {"THIN_UP_FRAME",0,0,(void *)FL_THIN_UP_FRAME}, + {"THIN_DOWN_FRAME",0,0,(void *)FL_THIN_DOWN_FRAME}, + {"ENGRAVED_FRAME",0,0,(void *)FL_ENGRAVED_FRAME}, + {"EMBOSSED_FRAME",0,0,(void *)FL_EMBOSSED_FRAME}, + {"BORDER_FRAME",0,0,(void *)FL_BORDER_FRAME}, + {"SHADOW_FRAME",0,0,(void *)FL_SHADOW_FRAME}, + {"ROUNDED_FRAME",0,0,(void *)FL_ROUNDED_FRAME}, + {"OVAL_FRAME",0,0,(void *)FL_OVAL_FRAME}, + {"PLASTIC_UP_FRAME",0,0,(void *)FL_PLASTIC_UP_FRAME}, + {"PLASTIC_DOWN_FRAME",0,0,(void *)FL_PLASTIC_DOWN_FRAME}, + {"GTK_UP_FRAME",0,0,(void *)FL_GTK_UP_FRAME}, + {"GTK_DOWN_FRAME",0,0,(void *)FL_GTK_DOWN_FRAME}, + {"GTK_THIN_UP_FRAME",0,0,(void *)FL_GTK_THIN_UP_FRAME}, + {"GTK_THIN_DOWN_FRAME",0,0,(void *)FL_GTK_THIN_DOWN_FRAME}, + {"GLEAM_UP_FRAME",0,0,(void *)FL_GLEAM_UP_FRAME}, + {"GLEAM_DOWN_FRAME",0,0,(void *)FL_GLEAM_DOWN_FRAME}, + {"OXY_UP_FRAME",0,0,(void *)FL_OXY_UP_FRAME}, + {"OXY_DOWN_FRAME",0,0,(void *)FL_OXY_DOWN_FRAME}, + {"OXY_THIN_UP_FRAME",0,0,(void *)FL_OXY_THIN_UP_FRAME}, + {"OXY_THIN_DOWN_FRAME",0,0,(void *)FL_OXY_THIN_DOWN_FRAME}, + {0}, + {0}}; const char* boxname(int i) { if (!i) i = ZERO_ENTRY; for (int j = 0; j < int(sizeof(boxmenu)/sizeof(*boxmenu)); j++) if (boxmenu[j].argument() == i) return boxmenu[j].label(); - return nullptr; + return 0; } int boxnumber(const char* i) { @@ -707,37 +747,37 @@ int boxnumber(const char* i) { Fl_Menu_Item whenmenu[] = { // set individual bits - {"FL_WHEN_CHANGED",0,nullptr,(void*)FL_WHEN_CHANGED, FL_MENU_TOGGLE}, - {"FL_WHEN_NOT_CHANGED",0,nullptr,(void*)FL_WHEN_NOT_CHANGED, FL_MENU_TOGGLE}, - {"FL_WHEN_RELEASE",0,nullptr,(void*)FL_WHEN_RELEASE, FL_MENU_TOGGLE}, - {"FL_WHEN_ENTER_KEY",0,nullptr,(void*)FL_WHEN_ENTER_KEY, FL_MENU_TOGGLE}, - {"FL_WHEN_CLOSED",0,nullptr,(void*)FL_WHEN_CLOSED, FL_MENU_TOGGLE|FL_MENU_DIVIDER}, + {"FL_WHEN_CHANGED",0,0,(void*)FL_WHEN_CHANGED, FL_MENU_TOGGLE}, + {"FL_WHEN_NOT_CHANGED",0,0,(void*)FL_WHEN_NOT_CHANGED, FL_MENU_TOGGLE}, + {"FL_WHEN_RELEASE",0,0,(void*)FL_WHEN_RELEASE, FL_MENU_TOGGLE}, + {"FL_WHEN_ENTER_KEY",0,0,(void*)FL_WHEN_ENTER_KEY, FL_MENU_TOGGLE}, + {"FL_WHEN_CLOSED",0,0,(void*)FL_WHEN_CLOSED, FL_MENU_TOGGLE|FL_MENU_DIVIDER}, // set bit combinations - {"FL_WHEN_NEVER",0,nullptr,(void*)FL_WHEN_NEVER}, - {"FL_WHEN_RELEASE_ALWAYS",0,nullptr,(void*)FL_WHEN_RELEASE_ALWAYS}, - {"FL_WHEN_ENTER_KEY_ALWAYS",0,nullptr,(void*)FL_WHEN_ENTER_KEY_ALWAYS}, - {"FL_WHEN_ENTER_KEY_CHANGED",0,nullptr,(void*)FL_WHEN_ENTER_KEY_CHANGED}, - {nullptr}}; + {"FL_WHEN_NEVER",0,0,(void*)FL_WHEN_NEVER}, + {"FL_WHEN_RELEASE_ALWAYS",0,0,(void*)FL_WHEN_RELEASE_ALWAYS}, + {"FL_WHEN_ENTER_KEY_ALWAYS",0,0,(void*)FL_WHEN_ENTER_KEY_ALWAYS}, + {"FL_WHEN_ENTER_KEY_CHANGED",0,0,(void*)FL_WHEN_ENTER_KEY_CHANGED}, + {0}}; static Fl_Menu_Item whensymbolmenu[] = { - /* 0 */ {"FL_WHEN_NEVER",0,nullptr,(void*)FL_WHEN_NEVER}, - /* 1 */ {"FL_WHEN_CHANGED",0,nullptr,(void*)FL_WHEN_CHANGED}, - /* 2 */ {"FL_WHEN_NOT_CHANGED",0,nullptr,(void*)FL_WHEN_NOT_CHANGED}, - /* 3 */ {"FL_WHEN_CHANGED | FL_WHEN_NOT_CHANGED",0,nullptr,(void*)(FL_WHEN_CHANGED|FL_WHEN_NOT_CHANGED)}, - /* 4 */ {"FL_WHEN_RELEASE",0,nullptr,(void*)FL_WHEN_RELEASE}, - /* 5 */ {"FL_WHEN_CHANGED | FL_WHEN_RELEASE",0,nullptr,(void*)(FL_WHEN_CHANGED|FL_WHEN_RELEASE)}, - /* 6 */ {"FL_WHEN_RELEASE_ALWAYS",0,nullptr,(void*)FL_WHEN_RELEASE_ALWAYS}, - /* 7 */ {"FL_WHEN_CHANGED | FL_WHEN_RELEASE_ALWAYS",0,nullptr,(void*)(FL_WHEN_CHANGED|FL_WHEN_RELEASE_ALWAYS)}, - /* 8 */ {"FL_WHEN_ENTER_KEY",0,nullptr,(void*)FL_WHEN_ENTER_KEY}, - /* 9 */ {"FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY",0,nullptr,(void*)(FL_WHEN_CHANGED|FL_WHEN_ENTER_KEY)}, - /* 10 */ {"FL_WHEN_ENTER_KEY_ALWAYS",0,nullptr,(void*)FL_WHEN_ENTER_KEY_ALWAYS}, - /* 11 */ {"FL_WHEN_ENTER_KEY_CHANGED",0,nullptr,(void*)FL_WHEN_ENTER_KEY_CHANGED}, - /* 12 */ {"FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY",0,nullptr,(void*)(FL_WHEN_RELEASE|FL_WHEN_ENTER_KEY)}, - /* 13 */ {"FL_WHEN_RELEASE | FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY",0,nullptr,(void*)(FL_WHEN_RELEASE|FL_WHEN_CHANGED|FL_WHEN_ENTER_KEY)}, - /* 14 */ {"FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY_ALWAYS",0,nullptr,(void*)(FL_WHEN_RELEASE|FL_WHEN_ENTER_KEY_ALWAYS)}, - /* 15 */ {"FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY_CHANGED",0,nullptr,(void*)(FL_WHEN_RELEASE|FL_WHEN_ENTER_KEY_CHANGED)}, - {nullptr} + /* 0 */ {"FL_WHEN_NEVER",0,0,(void*)FL_WHEN_NEVER}, + /* 1 */ {"FL_WHEN_CHANGED",0,0,(void*)FL_WHEN_CHANGED}, + /* 2 */ {"FL_WHEN_NOT_CHANGED",0,0,(void*)FL_WHEN_NOT_CHANGED}, + /* 3 */ {"FL_WHEN_CHANGED | FL_WHEN_NOT_CHANGED",0,0,(void*)(FL_WHEN_CHANGED|FL_WHEN_NOT_CHANGED)}, + /* 4 */ {"FL_WHEN_RELEASE",0,0,(void*)FL_WHEN_RELEASE}, + /* 5 */ {"FL_WHEN_CHANGED | FL_WHEN_RELEASE",0,0,(void*)(FL_WHEN_CHANGED|FL_WHEN_RELEASE)}, + /* 6 */ {"FL_WHEN_RELEASE_ALWAYS",0,0,(void*)FL_WHEN_RELEASE_ALWAYS}, + /* 7 */ {"FL_WHEN_CHANGED | FL_WHEN_RELEASE_ALWAYS",0,0,(void*)(FL_WHEN_CHANGED|FL_WHEN_RELEASE_ALWAYS)}, + /* 8 */ {"FL_WHEN_ENTER_KEY",0,0,(void*)FL_WHEN_ENTER_KEY}, + /* 9 */ {"FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY",0,0,(void*)(FL_WHEN_CHANGED|FL_WHEN_ENTER_KEY)}, + /* 10 */ {"FL_WHEN_ENTER_KEY_ALWAYS",0,0,(void*)FL_WHEN_ENTER_KEY_ALWAYS}, + /* 11 */ {"FL_WHEN_ENTER_KEY_CHANGED",0,0,(void*)FL_WHEN_ENTER_KEY_CHANGED}, + /* 12 */ {"FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY",0,0,(void*)(FL_WHEN_RELEASE|FL_WHEN_ENTER_KEY)}, + /* 13 */ {"FL_WHEN_RELEASE | FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY",0,0,(void*)(FL_WHEN_RELEASE|FL_WHEN_CHANGED|FL_WHEN_ENTER_KEY)}, + /* 14 */ {"FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY_ALWAYS",0,0,(void*)(FL_WHEN_RELEASE|FL_WHEN_ENTER_KEY_ALWAYS)}, + /* 15 */ {"FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY_CHANGED",0,0,(void*)(FL_WHEN_RELEASE|FL_WHEN_ENTER_KEY_CHANGED)}, + {0} }; // Return a text string representing the Fl_When value n @@ -765,7 +805,7 @@ void set_whenmenu(int n) { uchar Widget_Node::resizable() const { if (is_a(FLD_NODE_TYPE_Window)) - return ((Fl_Window*)o)->resizable() != nullptr; + return ((Fl_Window*)o)->resizable() != 0; Fl_Group* p = (Fl_Group*)o->parent(); if (p) return p->resizable() == o; @@ -787,10 +827,10 @@ void Widget_Node::resizable(uchar v) { if (!resizable()) return; if (is_a(FLD_NODE_TYPE_Window)) { - ((Fl_Window*)o)->resizable(nullptr); + ((Fl_Window*)o)->resizable(0); } else { Fl_Group* p = (Fl_Group*)o->parent(); - if (p) p->resizable(nullptr); + if (p) p->resizable(0); } } } @@ -816,11 +856,11 @@ Fl_Menu_Item fontmenu[] = { {"Terminal"}, {"Terminal Bold"}, {"Zapf Dingbats"}, - {nullptr} + {0} }; Fl_Menu_Item fontmenu_w_default[] = { - {"<default>", 0, nullptr, nullptr, FL_MENU_DIVIDER}, + {"<default>", 0, 0, 0, FL_MENU_DIVIDER}, {"Helvetica"}, {"Helvetica bold"}, {"Helvetica italic"}, @@ -837,7 +877,7 @@ Fl_Menu_Item fontmenu_w_default[] = { {"Terminal"}, {"Terminal Bold"}, {"Zapf Dingbats"}, - {nullptr} + {0} }; @@ -845,12 +885,12 @@ Fl_Menu_Item fontmenu_w_default[] = { extern const char* ui_find_image_name; Fl_Menu_Item labeltypemenu[] = { - {"NORMAL_LABEL",0,nullptr,(void*)nullptr}, - {"SHADOW_LABEL",0,nullptr,(void*)FL_SHADOW_LABEL}, - {"ENGRAVED_LABEL",0,nullptr,(void*)FL_ENGRAVED_LABEL}, - {"EMBOSSED_LABEL",0,nullptr,(void*)FL_EMBOSSED_LABEL}, - {"NO_LABEL",0,nullptr,(void*)(FL_NO_LABEL)}, - {nullptr}}; + {"NORMAL_LABEL",0,0,(void*)0}, + {"SHADOW_LABEL",0,0,(void*)FL_SHADOW_LABEL}, + {"ENGRAVED_LABEL",0,0,(void*)FL_ENGRAVED_LABEL}, + {"EMBOSSED_LABEL",0,0,(void*)FL_EMBOSSED_LABEL}, + {"NO_LABEL",0,0,(void*)(FL_NO_LABEL)}, + {0}}; void labeltype_cb(Fl_Choice* i, void* v) { if (v == LOAD) { @@ -884,21 +924,21 @@ void labeltype_cb(Fl_Choice* i, void* v) { //////////////////////////////////////////////////////////////// Fl_Menu_Item colormenu[] = { - { "Foreground Color", 0, nullptr, (void*)(fl_intptr_t)FL_FOREGROUND_COLOR, 0, 0, FL_HELVETICA, 11}, - { "Background Color", 0, nullptr, (void*)(fl_intptr_t)FL_BACKGROUND_COLOR, 0, 0, FL_HELVETICA, 11}, - { "Background Color 2", 0, nullptr, (void*)(fl_intptr_t)FL_BACKGROUND2_COLOR, 0, 0, FL_HELVETICA, 11}, - { "Selection Color", 0, nullptr, (void*)(fl_intptr_t)FL_SELECTION_COLOR, 0, 0, FL_HELVETICA, 11}, - { "Inactive Color", 0, nullptr, (void*)(fl_intptr_t)FL_INACTIVE_COLOR, FL_MENU_DIVIDER, 0, FL_HELVETICA, 11}, - { "Black", 0, nullptr, (void*)(fl_intptr_t)FL_BLACK, 0, 0, FL_HELVETICA, 11}, - { "White", 0, nullptr, (void*)(fl_intptr_t)FL_WHITE, FL_MENU_DIVIDER, 0, FL_HELVETICA, 11}, - { "Gray 0", 0, nullptr, (void*)(fl_intptr_t)FL_GRAY0, 0, 0, FL_HELVETICA, 11}, - { "Dark 3", 0, nullptr, (void*)(fl_intptr_t)FL_DARK3, 0, 0, FL_HELVETICA, 11}, - { "Dark 2", 0, nullptr, (void*)(fl_intptr_t)FL_DARK2, 0, 0, FL_HELVETICA, 11}, - { "Dark 1", 0, nullptr, (void*)(fl_intptr_t)FL_DARK1, 0, 0, FL_HELVETICA, 11}, - { "Light 1", 0, nullptr, (void*)(fl_intptr_t)FL_LIGHT1, 0, 0, FL_HELVETICA, 11}, - { "Light 2", 0, nullptr, (void*)(fl_intptr_t)FL_LIGHT2, 0, 0, FL_HELVETICA, 11}, - { "Light 3", 0, nullptr, (void*)(fl_intptr_t)FL_LIGHT3, 0, 0, FL_HELVETICA, 11}, - { nullptr } + { "Foreground Color", 0, 0, (void*)(fl_intptr_t)FL_FOREGROUND_COLOR, 0, 0, FL_HELVETICA, 11}, + { "Background Color", 0, 0, (void*)(fl_intptr_t)FL_BACKGROUND_COLOR, 0, 0, FL_HELVETICA, 11}, + { "Background Color 2", 0, 0, (void*)(fl_intptr_t)FL_BACKGROUND2_COLOR, 0, 0, FL_HELVETICA, 11}, + { "Selection Color", 0, 0, (void*)(fl_intptr_t)FL_SELECTION_COLOR, 0, 0, FL_HELVETICA, 11}, + { "Inactive Color", 0, 0, (void*)(fl_intptr_t)FL_INACTIVE_COLOR, FL_MENU_DIVIDER, 0, FL_HELVETICA, 11}, + { "Black", 0, 0, (void*)(fl_intptr_t)FL_BLACK, 0, 0, FL_HELVETICA, 11}, + { "White", 0, 0, (void*)(fl_intptr_t)FL_WHITE, FL_MENU_DIVIDER, 0, FL_HELVETICA, 11}, + { "Gray 0", 0, 0, (void*)(fl_intptr_t)FL_GRAY0, 0, 0, FL_HELVETICA, 11}, + { "Dark 3", 0, 0, (void*)(fl_intptr_t)FL_DARK3, 0, 0, FL_HELVETICA, 11}, + { "Dark 2", 0, 0, (void*)(fl_intptr_t)FL_DARK2, 0, 0, FL_HELVETICA, 11}, + { "Dark 1", 0, 0, (void*)(fl_intptr_t)FL_DARK1, 0, 0, FL_HELVETICA, 11}, + { "Light 1", 0, 0, (void*)(fl_intptr_t)FL_LIGHT1, 0, 0, FL_HELVETICA, 11}, + { "Light 2", 0, 0, (void*)(fl_intptr_t)FL_LIGHT2, 0, 0, FL_HELVETICA, 11}, + { "Light 3", 0, 0, (void*)(fl_intptr_t)FL_LIGHT3, 0, 0, FL_HELVETICA, 11}, + { 0 } }; void color_common(Fl_Color c) { @@ -956,24 +996,24 @@ static Fl_Button* relative(Fl_Widget* o, int i) { } static Fl_Menu_Item alignmenu[] = { - {"FL_ALIGN_CENTER",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_CENTER)}, - {"FL_ALIGN_TOP",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_TOP)}, - {"FL_ALIGN_BOTTOM",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_BOTTOM)}, - {"FL_ALIGN_LEFT",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_LEFT)}, - {"FL_ALIGN_RIGHT",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_RIGHT)}, - {"FL_ALIGN_INSIDE",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_INSIDE)}, - {"FL_ALIGN_CLIP",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_CLIP)}, - {"FL_ALIGN_WRAP",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_WRAP)}, - {"FL_ALIGN_TEXT_OVER_IMAGE",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_TEXT_OVER_IMAGE)}, - {"FL_ALIGN_TOP_LEFT",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_TOP_LEFT)}, - {"FL_ALIGN_TOP_RIGHT",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_TOP_RIGHT)}, - {"FL_ALIGN_BOTTOM_LEFT",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_BOTTOM_LEFT)}, - {"FL_ALIGN_BOTTOM_RIGHT",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_BOTTOM_RIGHT)}, - {"FL_ALIGN_LEFT_TOP",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_LEFT_TOP)}, - {"FL_ALIGN_RIGHT_TOP",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_RIGHT_TOP)}, - {"FL_ALIGN_LEFT_BOTTOM",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_LEFT_BOTTOM)}, - {"FL_ALIGN_RIGHT_BOTTOM",0,nullptr,(void*)(fl_intptr_t)(FL_ALIGN_RIGHT_BOTTOM)}, - {nullptr} + {"FL_ALIGN_CENTER",0,0,(void*)(fl_intptr_t)(FL_ALIGN_CENTER)}, + {"FL_ALIGN_TOP",0,0,(void*)(fl_intptr_t)(FL_ALIGN_TOP)}, + {"FL_ALIGN_BOTTOM",0,0,(void*)(fl_intptr_t)(FL_ALIGN_BOTTOM)}, + {"FL_ALIGN_LEFT",0,0,(void*)(fl_intptr_t)(FL_ALIGN_LEFT)}, + {"FL_ALIGN_RIGHT",0,0,(void*)(fl_intptr_t)(FL_ALIGN_RIGHT)}, + {"FL_ALIGN_INSIDE",0,0,(void*)(fl_intptr_t)(FL_ALIGN_INSIDE)}, + {"FL_ALIGN_CLIP",0,0,(void*)(fl_intptr_t)(FL_ALIGN_CLIP)}, + {"FL_ALIGN_WRAP",0,0,(void*)(fl_intptr_t)(FL_ALIGN_WRAP)}, + {"FL_ALIGN_TEXT_OVER_IMAGE",0,0,(void*)(fl_intptr_t)(FL_ALIGN_TEXT_OVER_IMAGE)}, + {"FL_ALIGN_TOP_LEFT",0,0,(void*)(fl_intptr_t)(FL_ALIGN_TOP_LEFT)}, + {"FL_ALIGN_TOP_RIGHT",0,0,(void*)(fl_intptr_t)(FL_ALIGN_TOP_RIGHT)}, + {"FL_ALIGN_BOTTOM_LEFT",0,0,(void*)(fl_intptr_t)(FL_ALIGN_BOTTOM_LEFT)}, + {"FL_ALIGN_BOTTOM_RIGHT",0,0,(void*)(fl_intptr_t)(FL_ALIGN_BOTTOM_RIGHT)}, + {"FL_ALIGN_LEFT_TOP",0,0,(void*)(fl_intptr_t)(FL_ALIGN_LEFT_TOP)}, + {"FL_ALIGN_RIGHT_TOP",0,0,(void*)(fl_intptr_t)(FL_ALIGN_RIGHT_TOP)}, + {"FL_ALIGN_LEFT_BOTTOM",0,0,(void*)(fl_intptr_t)(FL_ALIGN_LEFT_BOTTOM)}, + {"FL_ALIGN_RIGHT_BOTTOM",0,0,(void*)(fl_intptr_t)(FL_ALIGN_RIGHT_BOTTOM)}, + {0} }; void align_cb(Fl_Button* i, void* v) { @@ -1197,7 +1237,7 @@ void position_group_cb(Fl_Group* g, void* v) { // subtypes: -Fl_Menu_Item* Widget_Node::subtypes() { return nullptr; } +Fl_Menu_Item* Widget_Node::subtypes() { return 0; } //////////////////////////////////////////////////////////////// @@ -1241,9 +1281,9 @@ void leave_live_mode_cb(Fl_Widget*, void*); void live_mode_cb(Fl_Button* o, void *) { /// \todo live mode should end gracefully when the application quits /// or when the user closes the live widget - static Node* live_type = nullptr; - static Fl_Widget* live_widget = nullptr; - static Fl_Window* live_window = nullptr; + static Node* live_type = 0; + static Fl_Widget* live_widget = 0; + static Fl_Window* live_window = 0; if (!current_widget) { o->value(0); @@ -1257,11 +1297,11 @@ void live_mode_cb(Fl_Button* o, void *) { } if (o->value()) { if (numselected == 1) { - Fl_Group::current(nullptr); + Fl_Group::current(0); live_widget = current_widget->enter_live_mode(1); if (live_widget) { live_type = current_widget; - Fl_Group::current(nullptr); + Fl_Group::current(0); int w = live_widget->w(); int h = live_widget->h(); live_window = new Fl_Double_Window(w+20, h+55, "Fluid Live Resize"); @@ -1301,9 +1341,9 @@ void live_mode_cb(Fl_Button* o, void *) { live_window->hide(); Fl::delete_widget(live_window); } - live_type = nullptr; - live_widget = nullptr; - live_window = nullptr; + live_type = 0; + live_widget = 0; + live_window = 0; } } @@ -1313,7 +1353,7 @@ void load_panel() { // find all the Fl_Widget subclasses currently selected: numselected = 0; - current_widget = nullptr; + current_widget = 0; if (Fluid.proj.tree.current) { if (Fluid.proj.tree.current->is_a(FLD_NODE_TYPE_Data)) { current_node = Fluid.proj.tree.current; @@ -1348,7 +1388,7 @@ void load_panel() { tabs_wizard->value(func_tabs); numselected = 1; } else { - current_node = nullptr; + current_node = 0; if (Fluid.proj.tree.current->is_widget()) current_widget=(Widget_Node*)Fluid.proj.tree.current; for (Node* o = Fluid.proj.tree.first; o; o = o->next) { @@ -1429,10 +1469,10 @@ extern void update_codeview_position(); void selection_changed(Node* p) { // store all changes to the current selected objects: if (p && the_panel && the_panel->visible()) { - set_cb(nullptr,nullptr); + set_cb(0,0); // if there was an error, we try to leave the selected set unchanged: if (haderror) { - Node* q = nullptr; + Node* q = 0; for (Node* o = Fluid.proj.tree.first; o; o = o->next) { o->new_selected = o->selected; if (!q && o->selected) q = o; @@ -1444,7 +1484,7 @@ void selection_changed(Node* p) { } } // update the selected flags to new set: - Node* q = nullptr; + Node* q = 0; for (Node* o = Fluid.proj.tree.first; o; o = o->next) { o->selected = o->new_selected; if (!q && o->selected) q = o; @@ -1474,11 +1514,11 @@ int is_name(const char* c) { // number or a field or function. Return name() if not an array entry. const char* array_name(Widget_Node* o) { const char* c = o->name(); - if (!c) return nullptr; + if (!c) return 0; const char* d; for (d = c; *d != '['; d++) { if (!*d) return c; - if (ispunct(*d) && *d!='_') return nullptr; + if (ispunct(*d) && *d!='_') return 0; } int num = atoi(d+1); int sawthis = 0; @@ -1492,7 +1532,7 @@ const char* array_name(Widget_Node* o) { if (!e) continue; if (strncmp(c,e,d-c)) continue; int n1 = atoi(e+(d-c)+1); - if (n1 > num || (n1==num && sawthis)) return nullptr; + if (n1 > num || (n1==num && sawthis)) return 0; } static char buffer[128]; // MRS: we want strncpy() here... @@ -1512,14 +1552,17 @@ int isdeclare(const char* c) { } void Widget_Node::write_static(fld::io::Code_Writer& f) { - std::string t = subclassname(this); - if (subclass().empty() || (is_class() && (t.compare(0, 3, "Fl_")==0))) { + const char* t = subclassname(this); + const char* sc = subclass(); + if (!sc || !sc[0] || (is_class() && strncmp(t, "Fl_", 3)==0)) { f.write_h_once("#include <FL/Fl.H>"); - f.write_h_once("#include <FL/%s.H>", t.c_str()); + f.write_h_once("#include <FL/%s.H>", t); } - for (int n=0; n < NUM_EXTRA_CODE; n++) { - if (!extra_code(n).empty() && isdeclare(extra_code(n).c_str())) - f.write_h_once("%s", extra_code(n).c_str()); + int n; + for (n=0; n < NUM_EXTRA_CODE; n++) { + const char* ec = extra_code(n); + if (ec && ec[0] && isdeclare(ec)) + f.write_h_once("%s", ec); } if (callback() && is_name(callback())) { int write_extern_declaration = 1; @@ -1528,11 +1571,11 @@ void Widget_Node::write_static(fld::io::Code_Writer& f) { if (has_function("static void", buf)) write_extern_declaration = 0; } else { - if (has_toplevel_function(nullptr, buf)) + if (has_toplevel_function(0, buf)) write_extern_declaration = 0; } if (write_extern_declaration) - f.write_h_once("extern void %s(%s*, %s);", callback(), t.c_str(), + f.write_h_once("extern void %s(%s*, %s);", callback(), t, user_data_type() ? user_data_type() : "void*"); } const char* k = class_name(1); @@ -1540,9 +1583,9 @@ void Widget_Node::write_static(fld::io::Code_Writer& f) { if (c && !k && !is_class()) { f.write_c("\n"); if (!public_) f.write_c("static "); - else f.write_h("extern %s *%s;\n", t.c_str(), c); - if (strchr(c, '[') == nullptr) f.write_c("%s *%s=(%s *)0;\n", t.c_str(), c, t.c_str()); - else f.write_c("%s *%s={(%s *)0};\n", t.c_str(), c, t.c_str()); + else f.write_h("extern %s *%s;\n", t, c); + if (strchr(c, '[') == 0) f.write_c("%s *%s=(%s *)0;\n", t, c, t); + else f.write_c("%s *%s={(%s *)0};\n", t, c, t); } if (callback() && !is_name(callback()) && (callback()[0] != '[')) { // see if 'o' or 'v' used, to prevent unused argument warnings: @@ -1557,9 +1600,9 @@ void Widget_Node::write_static(fld::io::Code_Writer& f) { } const char* cn = callback_name(f); if (k) { - f.write_c("\nvoid %s::%s_i(%s*", k, cn, t.c_str()); + f.write_c("\nvoid %s::%s_i(%s*", k, cn, t); } else { - f.write_c("\nstatic void %s(%s*", cn, t.c_str()); + f.write_c("\nstatic void %s(%s*", cn, t); } if (use_o) f.write_c(" o"); const char* ut = user_data_type() ? user_data_type() : "void*"; @@ -1580,9 +1623,9 @@ void Widget_Node::write_static(fld::io::Code_Writer& f) { f.tag(FLD_MERGEBACK_TAG_WIDGET_CALLBACK, FLD_MERGEBACK_TAG_GENERIC, get_uid()); f.write_c("}\n"); if (k) { - f.write_c("void %s::%s(%s* o, %s v) {\n", k, cn, t.c_str(), ut); + f.write_c("void %s::%s(%s* o, %s v) {\n", k, cn, t, ut); f.write_c("%s((%s*)(o", f.indent(1), k); - Node* q = nullptr; + Node* q = 0; for (Node* p = parent; p && p->is_widget(); q = p, p = p->parent) f.write_c("->parent()"); if (!q || !q->is_a(FLD_NODE_TYPE_Widget_Class)) @@ -1601,20 +1644,20 @@ void Widget_Node::write_static(fld::io::Code_Writer& f) { } void Widget_Node::write_code1(fld::io::Code_Writer& f) { - std::string t = subclassname(this); + const char* t = subclassname(this); const char* c = array_name(this); if (c) { if (class_name(1)) { f.write_public(public_); - f.write_h("%s%s *%s;\n", f.indent(1), t.c_str(), c); + f.write_h("%s%s *%s;\n", f.indent(1), t, c); } } if (class_name(1) && callback() && !is_name(callback())) { const char* cn = callback_name(f); const char* ut = user_data_type() ? user_data_type() : "void*"; f.write_public(0); - f.write_h("%sinline void %s_i(%s*, %s);\n", f.indent(1), cn, t.c_str(), ut); - f.write_h("%sstatic void %s(%s*, %s);\n", f.indent(1), cn, t.c_str(), ut); + f.write_h("%sinline void %s_i(%s*, %s);\n", f.indent(1), cn, t, ut); + f.write_h("%sstatic void %s(%s*, %s);\n", f.indent(1), cn, t, ut); } // figure out if local variable will be used (prevent compiler warnings): int wused = !name() && is_a(FLD_NODE_TYPE_Window); @@ -1633,15 +1676,16 @@ void Widget_Node::write_code1(fld::io::Code_Writer& f) { } if (!f.varused) { - for (int n=0; n < NUM_EXTRA_CODE; n++) - if (!extra_code(n).empty() && !isdeclare(extra_code(n).c_str())) + int n; + for (n=0; n < NUM_EXTRA_CODE; n++) { + const char* ec = extra_code(n); + if (ec && ec[0] && !isdeclare(ec)) { int instring = 0; int inname = 0; int incomment = 0; int incppcomment = 0; - std::string code = extra_code(n); - for (ptr = code.c_str(); *ptr; ptr ++) { + for (ptr = ec; *ptr; ptr ++) { if (instring) { if (*ptr == '\\') ptr++; else if (*ptr == '\"') instring = 0; @@ -1673,27 +1717,28 @@ void Widget_Node::write_code1(fld::io::Code_Writer& f) { } } } + } } f.write_c("%s{ ", f.indent()); write_comment_inline_c(f); - if (f.varused) f.write_c("%s* o = ", t.c_str()); + if (f.varused) f.write_c("%s* o = ", t); if (name()) f.write_c("%s = ", name()); if (is_a(FLD_NODE_TYPE_Window)) { // Handle special case where user is faking a Fl_Group type as a window, // there is no 2-argument constructor in that case: - if (t.find("Window")==t.npos) - f.write_c("new %s(0, 0, %d, %d", t.c_str(), o->w(), o->h()); + if (strstr(t, "Window") == 0) + f.write_c("new %s(0, 0, %d, %d", t, o->w(), o->h()); else - f.write_c("new %s(%d, %d", t.c_str(), o->w(), o->h()); + f.write_c("new %s(%d, %d", t, o->w(), o->h()); } else if (is_a(FLD_NODE_TYPE_Menu_Bar) && ((Menu_Bar_Node*)this)->is_sys_menu_bar() && is_in_class()) { f.write_c("(%s*)new %s(%d, %d, %d, %d", - t.c_str(), ((Menu_Bar_Node*)this)->sys_menubar_proxy_name(), + t, ((Menu_Bar_Node*)this)->sys_menubar_proxy_name(), o->x(), o->y(), o->w(), o->h()); } else { - f.write_c("new %s(%d, %d, %d, %d", t.c_str(), o->x(), o->y(), o->w(), o->h()); + f.write_c("new %s(%d, %d, %d, %d", t, o->x(), o->y(), o->w(), o->h()); } if (label() && *label()) { f.write_c(", "); @@ -1727,7 +1772,7 @@ void Widget_Node::write_code1(fld::io::Code_Writer& f) { } void Widget_Node::write_color(fld::io::Code_Writer& f, const char* field, Fl_Color color) { - const char* color_name = nullptr; + const char* color_name = 0; switch (color) { case FL_FOREGROUND_COLOR: color_name = "FL_FOREGROUND_COLOR"; break; case FL_BACKGROUND2_COLOR: color_name = "FL_BACKGROUND2_COLOR"; break; @@ -1769,15 +1814,15 @@ void Widget_Node::write_widget_code(fld::io::Code_Writer& f) { Fl_Widget* tplate = ((Widget_Node*)factory)->o; const char* var = is_class() ? "this" : name() ? name() : "o"; - if (!tooltip().empty()) { + if (tooltip() && tooltip()[0]) { f.write_c("%s%s->tooltip(",f.indent(), var); switch (Fluid.proj.i18n.type) { case FLD_I18N_TYPE_NONE : /* None */ - f.write_cstring(tooltip().c_str()); + f.write_cstring(tooltip()); break; case FLD_I18N_TYPE_GNU : /* GNU gettext */ f.write_c("%s(", Fluid.proj.i18n.gnu_function.c_str()); - f.write_cstring(tooltip().c_str()); + f.write_cstring(tooltip()); f.write_c(")"); break; case FLD_I18N_TYPE_POSIX : /* POSIX catgets */ @@ -1785,7 +1830,7 @@ void Widget_Node::write_widget_code(fld::io::Code_Writer& f) { Fluid.proj.i18n.posix_file.empty() ? "_catalog" : Fluid.proj.i18n.posix_file.c_str(), Fluid.proj.i18n.posix_set.c_str(), msgnum() + 1); - f.write_cstring(tooltip().c_str()); + f.write_cstring(tooltip()); f.write_c(")"); break; } @@ -1796,7 +1841,7 @@ void Widget_Node::write_widget_code(fld::io::Code_Writer& f) { f.write_c("%s%s->type(%d);\n", f.indent(), var, ((Fl_Spinner*)o)->type()); else if (o->type() != tplate->type() && !is_a(FLD_NODE_TYPE_Window)) f.write_c("%s%s->type(%d);\n", f.indent(), var, o->type()); - if (o->box() != tplate->box() || !subclass().empty()) + if (o->box() != tplate->box() || subclass() && subclass()[0]) f.write_c("%s%s->box(FL_%s);\n", f.indent(), var, boxname(o->box())); // write shortcut command if needed @@ -1838,9 +1883,9 @@ void Widget_Node::write_widget_code(fld::io::Code_Writer& f) { if (b->down_box()) f.write_c("%s%s->down_box(FL_%s);\n", f.indent(), var, boxname(b->down_box())); } - if (o->color() != tplate->color() || !subclass().empty()) + if (o->color() != tplate->color() || subclass() && subclass()[0]) write_color(f, "color", o->color()); - if (o->selection_color() != tplate->selection_color() || !subclass().empty()) + if (o->selection_color() != tplate->selection_color() || subclass() && subclass()[0]) write_color(f, "selection_color", o->selection_color()); if (image) { image->write_code(f, bind_image_, var); @@ -1870,14 +1915,14 @@ void Widget_Node::write_widget_code(fld::io::Code_Writer& f) { f.write_c("%s->deimage()->data_h(), 0, 1);\n", var); } } - if (o->labeltype() != tplate->labeltype() || !subclass().empty()) + if (o->labeltype() != tplate->labeltype() || subclass() && subclass()[0]) f.write_c("%s%s->labeltype(FL_%s);\n", f.indent(), var, item_name(labeltypemenu, o->labeltype())); - if (o->labelfont() != tplate->labelfont() || !subclass().empty()) + if (o->labelfont() != tplate->labelfont() || subclass() && subclass()[0]) f.write_c("%s%s->labelfont(%d);\n", f.indent(), var, o->labelfont()); - if (o->labelsize() != tplate->labelsize() || !subclass().empty()) + if (o->labelsize() != tplate->labelsize() || subclass() && subclass()[0]) f.write_c("%s%s->labelsize(%d);\n", f.indent(), var, o->labelsize()); - if (o->labelcolor() != tplate->labelcolor() || !subclass().empty()) + if (o->labelcolor() != tplate->labelcolor() || subclass() && subclass()[0]) write_color(f, "labelcolor", o->labelcolor()); if (o->horizontal_label_margin() != tplate->horizontal_label_margin()) f.write_c("%s%s->horizontal_label_margin(%d);\n", f.indent(), var, o->horizontal_label_margin()); @@ -1946,7 +1991,7 @@ void Widget_Node::write_widget_code(fld::io::Code_Writer& f) { } else if (ud) { f.write_c("%s%s->user_data((void*)(%s));\n", f.indent(), var, ud); } - if (o->align() != tplate->align() || !subclass().empty()) { + if (o->align() != tplate->align() || subclass() && subclass()[0]) { int i = o->align(); f.write_c("%s%s->align(Fl_Align(%s", f.indent(), var, item_name(alignmenu, i & ~FL_ALIGN_INSIDE)); @@ -1954,7 +1999,7 @@ void Widget_Node::write_widget_code(fld::io::Code_Writer& f) { f.write_c("));\n"); } Fl_When ww = o->when(); - if (ww != tplate->when() || !subclass().empty()) + if (ww != tplate->when() || subclass() && subclass()[0]) f.write_c("%s%s->when(%s);\n", f.indent(), var, when_symbol_name(ww)); if (!o->visible() && o->parent()) f.write_c("%s%s->hide();\n", f.indent(), var); @@ -1974,13 +2019,13 @@ void Widget_Node::write_widget_code(fld::io::Code_Writer& f) { void Widget_Node::write_extra_code(fld::io::Code_Writer& f) { for (int n=0; n < NUM_EXTRA_CODE; n++) - if (!extra_code(n).empty() && !isdeclare(extra_code(n).c_str())) - f.write_c("%s%s\n", f.indent(), extra_code(n).c_str()); + if (extra_code(n) && extra_code(n)[0] && !isdeclare(extra_code(n))) + f.write_c("%s%s\n", f.indent(), extra_code(n)); } void Widget_Node::write_block_close(fld::io::Code_Writer& f) { f.indentation--; - f.write_c("%s} // %s* %s\n", f.indent(), subclassname(this).c_str(), + f.write_c("%s} // %s* %s\n", f.indent(), subclassname(this), name() ? name() : "o"); } @@ -1999,11 +2044,11 @@ void Widget_Node::write_properties(fld::io::Project_Writer &f) { case 1: break; case 2: f.write_string("protected"); break; } - if (!tooltip().empty()) { + if (tooltip() && tooltip()[0]) { f.write_string("tooltip"); f.write_word(tooltip()); } - if (!image_name().empty()) { + if (image_name() && image_name()[0]) { if (scale_image_w_ || scale_image_h_) f.write_string("scale_image {%d %d}", scale_image_w_, scale_image_h_); f.write_string("image"); @@ -2011,7 +2056,7 @@ void Widget_Node::write_properties(fld::io::Project_Writer &f) { f.write_string("compress_image %d", compress_image_); } if (bind_image_) f.write_string("bind_image 1"); - if (!inactive_name().empty()) { + if (inactive_name() && inactive_name()[0]) { if (scale_deimage_w_ || scale_deimage_h_) f.write_string("scale_deimage {%d %d}", scale_deimage_w_, scale_deimage_h_); f.write_string("deimage"); @@ -2113,12 +2158,12 @@ void Widget_Node::write_properties(fld::io::Project_Writer &f) { if (resizable()) f.write_string("resizable"); if (hotspot()) f.write_string(is_a(FLD_NODE_TYPE_Menu_Item) ? "divider" : "hotspot"); if (menu_headline()) f.write_string("headline"); - for (int n=0; n < NUM_EXTRA_CODE; n++) if (!extra_code(n).empty()) { + for (int n=0; n < NUM_EXTRA_CODE; n++) if (extra_code(n) && extra_code(n)[0]) { f.write_indent(level+1); f.write_string("code%d",n); - f.write_word(extra_code(n).c_str()); + f.write_word(extra_code(n)); } - if (!subclass().empty()) { + if (subclass() && subclass()[0]) { f.write_indent(level+1); f.write_string("class"); f.write_word(subclass()); @@ -2153,11 +2198,11 @@ void Widget_Node::read_property(fld::io::Project_Reader &f, const char* c) { image_name(f.read_word()); // starting in 2023, `image` is always followed by `compress_image` // the code below is for compatibility with older .fl files - std::string ext = fl_filename_ext_str(image_name()); - if ( (ext != ".jpg") - && (ext != ".png") - && (ext != ".svg") - && (ext != ".svgz")) + const char *ext = fl_filename_ext(image_name()); + if ( (strcmp(ext, ".jpg") != 0) + && (strcmp(ext, ".png") != 0) + && (strcmp(ext, ".svg") != 0) + && (strcmp(ext, ".svgz") != 0)) compress_image_ = 0; // if it is neither of those, default to uncompressed } else if (!strcmp(c,"bind_image")) { bind_image_ = (int)atol(f.read_word()); @@ -2172,11 +2217,11 @@ void Widget_Node::read_property(fld::io::Project_Reader &f, const char* c) { inactive_name(f.read_word()); // starting in 2023, `deimage` is always followed by `compress_deimage` // the code below is for compatibility with older .fl files - std::string ext = fl_filename_ext_str(inactive_name()); - if ( (ext != ".jpg") - && (ext != ".png") - && (ext != ".svg") - && (ext != ".svgz")) + const char *ext = fl_filename_ext(inactive_name()); + if ( (strcmp(ext, ".jpg") != 0) + && (strcmp(ext, ".png") != 0) + && (strcmp(ext, ".svg") != 0) + && (strcmp(ext, ".svgz") != 0)) compress_deimage_ = 0; // if it is neither of those, default to uncompressed } else if (!strcmp(c,"bind_deimage")) { bind_deimage_ = (int)atol(f.read_word()); @@ -2258,19 +2303,19 @@ void Widget_Node::read_property(fld::io::Project_Reader &f, const char* c) { } else if (!strcmp(c,"when")) { if (sscanf(f.read_word(),"%d",&x) == 1) o->when(x); } else if (!strcmp(c,"minimum")) { - if (is_a(FLD_NODE_TYPE_Valuator_)) ((Fl_Valuator*)o)->minimum(strtod(f.read_word(),nullptr)); - if (is_a(FLD_NODE_TYPE_Spinner)) ((Fl_Spinner*)o)->minimum(strtod(f.read_word(),nullptr)); + if (is_a(FLD_NODE_TYPE_Valuator_)) ((Fl_Valuator*)o)->minimum(strtod(f.read_word(),0)); + if (is_a(FLD_NODE_TYPE_Spinner)) ((Fl_Spinner*)o)->minimum(strtod(f.read_word(),0)); } else if (!strcmp(c,"maximum")) { - if (is_a(FLD_NODE_TYPE_Valuator_)) ((Fl_Valuator*)o)->maximum(strtod(f.read_word(),nullptr)); - if (is_a(FLD_NODE_TYPE_Spinner)) ((Fl_Spinner*)o)->maximum(strtod(f.read_word(),nullptr)); + if (is_a(FLD_NODE_TYPE_Valuator_)) ((Fl_Valuator*)o)->maximum(strtod(f.read_word(),0)); + if (is_a(FLD_NODE_TYPE_Spinner)) ((Fl_Spinner*)o)->maximum(strtod(f.read_word(),0)); } else if (!strcmp(c,"step")) { - if (is_a(FLD_NODE_TYPE_Valuator_)) ((Fl_Valuator*)o)->step(strtod(f.read_word(),nullptr)); - if (is_a(FLD_NODE_TYPE_Spinner)) ((Fl_Spinner*)o)->step(strtod(f.read_word(),nullptr)); + if (is_a(FLD_NODE_TYPE_Valuator_)) ((Fl_Valuator*)o)->step(strtod(f.read_word(),0)); + if (is_a(FLD_NODE_TYPE_Spinner)) ((Fl_Spinner*)o)->step(strtod(f.read_word(),0)); } else if (!strcmp(c,"value")) { - if (is_a(FLD_NODE_TYPE_Valuator_)) ((Fl_Valuator*)o)->value(strtod(f.read_word(),nullptr)); - if (is_a(FLD_NODE_TYPE_Spinner)) ((Fl_Spinner*)o)->value(strtod(f.read_word(),nullptr)); + if (is_a(FLD_NODE_TYPE_Valuator_)) ((Fl_Valuator*)o)->value(strtod(f.read_word(),0)); + if (is_a(FLD_NODE_TYPE_Spinner)) ((Fl_Spinner*)o)->value(strtod(f.read_word(),0)); } else if ( (!strcmp(c,"slider_size") || !strcmp(c,"size")) && is_a(FLD_NODE_TYPE_Slider)) { - ((Fl_Slider*)o)->slider_size(strtod(f.read_word(),nullptr)); + ((Fl_Slider*)o)->slider_size(strtod(f.read_word(),0)); } else if (!strcmp(c,"textfont")) { if (sscanf(f.read_word(),"%d",&x) == 1) {ft=(Fl_Font)x; textstuff(1,ft,s,cc);} } else if (!strcmp(c,"textsize")) { @@ -2290,7 +2335,7 @@ void Widget_Node::read_property(fld::io::Project_Reader &f, const char* c) { } else if (!strcmp(c,"class")) { subclass(f.read_word()); } else if (!strcmp(c,"shortcut")) { - int shortcut = (int)strtol(f.read_word(),nullptr,0); + int shortcut = (int)strtol(f.read_word(),0,0); if (is_button()) ((Fl_Button*)o)->shortcut(shortcut); else if (is_a(FLD_NODE_TYPE_Input)) ((Fl_Input_*)o)->shortcut(shortcut); else if (is_a(FLD_NODE_TYPE_Value_Input)) ((Fl_Value_Input*)o)->shortcut(shortcut); @@ -2312,24 +2357,24 @@ void Widget_Node::read_property(fld::io::Project_Reader &f, const char* c) { Fl_Menu_Item boxmenu1[] = { // these extra ones are for looking up fdesign saved strings: - {"NO_FRAME", 0,nullptr,(void *)FL_NO_BOX}, - {"ROUNDED3D_UPBOX", 0,nullptr,(void *)FL_ROUND_UP_BOX}, - {"ROUNDED3D_DOWNBOX", 0,nullptr,(void *)FL_ROUND_DOWN_BOX}, - {"OVAL3D_UPBOX", 0,nullptr,(void *)FL_ROUND_UP_BOX}, - {"OVAL3D_DOWNBOX", 0,nullptr,(void *)FL_ROUND_DOWN_BOX}, - {"0", 0,nullptr,(void *)ZERO_ENTRY}, - {"1", 0,nullptr,(void *)FL_UP_BOX}, - {"2", 0,nullptr,(void *)FL_DOWN_BOX}, - {"3", 0,nullptr,(void *)FL_FLAT_BOX}, - {"4", 0,nullptr,(void *)FL_BORDER_BOX}, - {"5", 0,nullptr,(void *)FL_SHADOW_BOX}, - {"6", 0,nullptr,(void *)FL_FRAME_BOX}, - {"7", 0,nullptr,(void *)FL_ROUNDED_BOX}, - {"8", 0,nullptr,(void *)FL_RFLAT_BOX}, - {"9", 0,nullptr,(void *)FL_RSHADOW_BOX}, - {"10", 0,nullptr,(void *)FL_UP_FRAME}, - {"11", 0,nullptr,(void *)FL_DOWN_FRAME}, - {nullptr}}; + {"NO_FRAME", 0,0,(void *)FL_NO_BOX}, + {"ROUNDED3D_UPBOX", 0,0,(void *)FL_ROUND_UP_BOX}, + {"ROUNDED3D_DOWNBOX", 0,0,(void *)FL_ROUND_DOWN_BOX}, + {"OVAL3D_UPBOX", 0,0,(void *)FL_ROUND_UP_BOX}, + {"OVAL3D_DOWNBOX", 0,0,(void *)FL_ROUND_DOWN_BOX}, + {"0", 0,0,(void *)ZERO_ENTRY}, + {"1", 0,0,(void *)FL_UP_BOX}, + {"2", 0,0,(void *)FL_DOWN_BOX}, + {"3", 0,0,(void *)FL_FLAT_BOX}, + {"4", 0,0,(void *)FL_BORDER_BOX}, + {"5", 0,0,(void *)FL_SHADOW_BOX}, + {"6", 0,0,(void *)FL_FRAME_BOX}, + {"7", 0,0,(void *)FL_ROUNDED_BOX}, + {"8", 0,0,(void *)FL_RFLAT_BOX}, + {"9", 0,0,(void *)FL_RSHADOW_BOX}, + {"10", 0,0,(void *)FL_UP_FRAME}, + {"11", 0,0,(void *)FL_DOWN_FRAME}, + {0}}; int lookup_symbol(const char *, int &, int numberok = 0); @@ -2425,7 +2470,7 @@ int Widget_Node::read_fdesign(const char* propname, const char* value) { } void leave_live_mode_cb(Fl_Widget*, void*) { - live_mode_cb(nullptr, nullptr); + live_mode_cb(0, 0); } Fl_Widget* Widget_Node::enter_live_mode(int) { @@ -2472,10 +2517,10 @@ void Widget_Node::copy_properties() { // copy all attributes common to all widget types Fl_Widget* w = live_widget; w->label(o->label()); - if (tooltip().empty()) - w->tooltip(nullptr); + if ((!tooltip() || !tooltip()[0])) + w->tooltip(0); else - w->copy_tooltip(tooltip().c_str()); + w->copy_tooltip(tooltip()); w->type(o->type()); w->box(o->box()); w->color(o->color()); diff --git a/fluid/nodes/Widget_Node.h b/fluid/nodes/Widget_Node.h index b2afa58a6..98a943333 100644 --- a/fluid/nodes/Widget_Node.h +++ b/fluid/nodes/Widget_Node.h @@ -19,7 +19,7 @@ #include "nodes/Node.h" -#include <string> +#include <FL/fl_string_functions.h> #define NUM_EXTRA_CODE 4 @@ -30,7 +30,7 @@ extern void* const LOAD; extern Node* current_node; // one of the selected ones extern Widget_Node* current_widget; // one of the selected ones -extern std::string subclassname(Node* l); +extern const char* subclassname(Node* l); extern int is_name(const char* c); void selection_changed(Node* new_current); Node* sort(Node* parent); @@ -47,19 +47,19 @@ class Widget_Node : public Node void setlabel(const char *) override; /// Additional code blocks that can be inserted in the generated code - std::string extra_code_[NUM_EXTRA_CODE]; + char *extra_code_[NUM_EXTRA_CODE]; /// User can call the ctor for a class that is derived from the node class - std::string subclass_; + char *subclass_; /// Keep a copy the tooltip here, also always updates the widget's tooltip - std::string tooltip_; + char *tooltip_; /// Image name or file name. - std::string image_name_; + char *image_name_; /// Name or file name of deactivated image - std::string inactive_name_; + char *inactive_name_; /// Set's a widget's hotspot, or adds a divider to a menu item - uchar hotspot_ = 0; + uchar hotspot_; /// On menu items, set the "headline" flag - bool menu_headline_ = false; + int menu_headline_; protected: @@ -67,7 +67,7 @@ protected: /// We can't open a window in batch mode, even if we want the "visible" flags /// set, so we need a second place to store this information while also /// disabling the output of the "hide" property by the Widget Type. - uchar override_visible_ = 0; + uchar override_visible_; void write_static(fld::io::Code_Writer& f) override; void write_code1(fld::io::Code_Writer& f) override; @@ -83,58 +83,58 @@ protected: public: /// Pointer to widget for interactive editing. - Fl_Widget* o = nullptr; + Fl_Widget* o; /// Widget access mode, 0=private, 1=public, 2=protected - int public_ = 1; + int public_; // ---- Image stuff /// Set the bind image flag for the active image - int bind_image_ = 0; + int bind_image_; /// Compress the active image when inlining into source code - int compress_image_ = 1; + int compress_image_; /// Scale the active image, great for hires screens - int scale_image_w_ = 0, scale_image_h_ = 0; + int scale_image_w_, scale_image_h_; /// Pointer to the shared image data of the active image - Image_Asset* image = nullptr; + Image_Asset* image; /// Set the bind image flag for the inactive image - int bind_deimage_ = 0; + int bind_deimage_; /// Compress the inactive image when inlining into source code - int compress_deimage_ = 1; + int compress_deimage_; /// Scale the inactive image - int scale_deimage_w_ = 0, scale_deimage_h_ = 0; + int scale_deimage_w_, scale_deimage_h_; /// Pointer to the shared image data of the inactive image - Image_Asset* inactive = nullptr; + Image_Asset* inactive; void setimage(Image_Asset *); - std::string image_name() const { return image_name_; } - void image_name(const std::string& name); + const char* image_name() const { return image_name_ ? image_name_ : ""; } + void image_name(const char *name); void setinactive(Image_Asset *); - std::string inactive_name() const { return inactive_name_; } - void inactive_name(const std::string& name); + const char* inactive_name() const { return inactive_name_ ? inactive_name_ : ""; } + void inactive_name(const char *name); - Widget_Node() = default; - ~Widget_Node() override; + Widget_Node(); + ~Widget_Node(); Node* make(Strategy strategy) override; void open() override; - const std::string& extra_code(int n) const { return extra_code_[n]; } - void extra_code(int n, const std::string& code); - std::string subclass() const { return subclass_; } - void subclass(const std::string& name); - std::string tooltip() const { return tooltip_; } - void tooltip(const std::string& text); + const char* extra_code(int n) const { return extra_code_[n] ? extra_code_[n] : ""; } + void extra_code(int n, const char *code); + const char* subclass() const { return subclass_ ? subclass_ : ""; } + void subclass(const char *name); + const char* tooltip() const { return tooltip_ ? tooltip_ : ""; } + void tooltip(const char *text); // Note: hotspot is misused by menu items to indicate a divider uchar hotspot() const { return hotspot_; } void hotspot(uchar v) { hotspot_ = v; } uchar resizable() const; void resizable(uchar v); - bool menu_headline() const { return menu_headline_; } - void menu_headline(bool v) { menu_headline_ = v; } + int menu_headline() const { return menu_headline_; } + void menu_headline(int v) { menu_headline_ = v; } virtual int textstuff(int what, Fl_Font &, int &, Fl_Color &); virtual Fl_Menu_Item* subtypes(); diff --git a/fluid/nodes/Window_Node.cxx b/fluid/nodes/Window_Node.cxx index 965d0e8d6..0c3b0f01c 100644 --- a/fluid/nodes/Window_Node.cxx +++ b/fluid/nodes/Window_Node.cxx @@ -115,9 +115,9 @@ void show_settings_cb(Fl_Widget *, void *) { //////////////////////////////////////////////////////////////// Fl_Menu_Item window_type_menu[] = { - {"Single",0,nullptr,(void*)FL_WINDOW}, - {"Double",0,nullptr,(void*)(FL_DOUBLE_WINDOW)}, - {nullptr}}; + {"Single",0,0,(void*)FL_WINDOW}, + {"Double",0,0,(void*)(FL_DOUBLE_WINDOW)}, + {0}}; static int overlays_invisible; @@ -132,7 +132,7 @@ public: Window_Node *window; int handle(int) override; Overlay_Window(int W,int H) : Fl_Overlay_Window(W,H) { - Fl_Group::current(nullptr); + Fl_Group::current(0); callback((Fl_Callback*)close_cb); } void resize(int,int,int,int) override; @@ -201,7 +201,7 @@ uchar *Overlay_Window::read_image(int &ww, int &hh) { draw(); // Read the screen image... - pixels = fl_read_image(nullptr, 0, 0, ww, hh); + pixels = fl_read_image(0, 0, 0, ww, hh); fl_end_offscreen(); @@ -242,12 +242,12 @@ Node *Window_Node::make(Strategy strategy) { } if (!p) { fl_message("Please select a function"); - return nullptr; + return 0; } Window_Node *myo = new Window_Node(); if (!this->o) {// template widget this->o = new Fl_Window(100,100); - Fl_Group::current(nullptr); + Fl_Group::current(0); } myo->factory = this; myo->drag = 0; @@ -265,7 +265,7 @@ Node *Window_Node::make(Strategy strategy) { void Window_Node::add_child(Node* cc, Node* before) { if (!cc->is_widget()) return; Widget_Node* c = (Widget_Node*)cc; - Fl_Widget* b = before ? ((Widget_Node*)before)->o : nullptr; + Fl_Widget* b = before ? ((Widget_Node*)before)->o : 0; ((Fl_Window*)o)->insert(*(c->o), b); o->redraw(); } @@ -281,7 +281,7 @@ void Window_Node::remove_child(Node* cc) { void Window_Node::move_child(Node* cc, Node* before) { Widget_Node* c = (Widget_Node*)cc; ((Fl_Window*)o)->remove(c->o); - Fl_Widget* b = before ? ((Widget_Node*)before)->o : nullptr; + Fl_Widget* b = before ? ((Widget_Node*)before)->o : 0; ((Fl_Window*)o)->insert(*(c->o), b); o->redraw(); } @@ -369,7 +369,7 @@ void Overlay_Window::resize(int X,int Y,int W,int H) { Fl_Widget* t = resizable(); if (Fluid.proj.tree.allow_layout == 0) { - resizable(nullptr); + resizable(0); } // do not set the mod flag if the window was not resized. In FLUID, all @@ -401,7 +401,7 @@ void Window_Node::newdx() { } if (Fluid.show_guides && (drag & (FD_DRAG|FD_TOP|FD_LEFT|FD_BOTTOM|FD_RIGHT))) { - Node *selection = nullptr; // special power for the first selected widget + Node *selection = 0; // special power for the first selected widget for (Node *q=next; q && q->level>level; q = q->next) { if (q->selected && q->is_true_widget()) { selection = q; @@ -591,7 +591,7 @@ void Window_Node::draw_overlay() { int mybx,myby,mybr,mybt; int mysx,mysy,mysr,myst; mybx = mysx = o->w(); myby = mysy = o->h(); mybr = mysr = 0; mybt = myst = 0; - Node *selection = nullptr; // special power for the first selected widget + Node *selection = 0; // special power for the first selected widget for (Node *q=next; q && q->level>level; q = q->next) if (q->selected && q->is_true_widget()) { if (!selection) selection = q; @@ -672,7 +672,7 @@ void Window_Node::fix_overlay() { // check if we must redraw any parent of tabs/wizard type void check_redraw_corresponding_parent(Node *s) { - Widget_Node * prev_parent = nullptr; + Widget_Node * prev_parent = 0; if( !s || !s->selected || !s->is_widget()) return; for (Node *i=s; i && i->parent; i=i->parent) { if (i->is_a(FLD_NODE_TYPE_Group) && prev_parent) { @@ -743,7 +743,7 @@ void toggle_guides(Fl_Widget *,void *) { This is called from the check button in the Settings dialog. */ void toggle_guides_cb(Fl_Check_Button *o, void *v) { - toggle_guides(nullptr, nullptr); + toggle_guides(0, 0); } /** @@ -789,7 +789,7 @@ void toggle_ghosted_outline_cb(Fl_Check_Button *,void *) { This is called from the check button in the Settings dialog. */ void toggle_restricted_cb(Fl_Check_Button *o, void *v) { - toggle_restricted(nullptr, nullptr); + toggle_restricted(0, 0); } extern void select(Node *,int); @@ -913,7 +913,7 @@ int Window_Node::popupx = 0x7FFFFFFF; // mark as invalid (MAXINT) int Window_Node::popupy = 0x7FFFFFFF; int Window_Node::handle(int event) { - static Node* selection = nullptr; + static Node* selection = 0; switch (event) { case FL_DND_ENTER: // printf("DND enter\n"); @@ -945,11 +945,11 @@ int Window_Node::handle(int event) { case FL_PASTE: // printf("DND paste\n"); { Node *prototype = typename_to_prototype(Fl::event_text()); - if (prototype==nullptr) { + if (prototype==0) { // it's not a FLUID type, so it could be the filename of an image const char *cfn = Fl::event_text(); // printf("DND is filename %s?\n", cfn); - if ((cfn == nullptr) || (*cfn == 0)) return 0; + if ((cfn == 0) || (*cfn == 0)) return 0; if (strlen(cfn) >= FL_PATH_MAX) return 0; char fn[FL_PATH_MAX+1]; // some platform prepend "file://" or "computer://" or similar text @@ -973,7 +973,7 @@ int Window_Node::handle(int event) { if (!img || (img->ld() < 0)) return 0; // ok, so it is an image - now add it as image() or deimage() to the widget // printf("DND check for target %s\n", fn); - Widget_Node *tgt = nullptr; + Widget_Node *tgt = 0; for (Node* i=next; i && i->level>level; i=i->next) { if (i->is_widget()) { Widget_Node* myo = (Widget_Node*)i; @@ -1022,7 +1022,7 @@ int Window_Node::handle(int event) { } popupx = 0x7FFFFFFF; popupy = 0x7FFFFFFF; // mark as invalid (MAXINT) - in_this_only = nullptr; + in_this_only = 0; widget_browser->display(Fluid.proj.tree.current); widget_browser->rebuild(); return 1; @@ -1039,7 +1039,7 @@ int Window_Node::handle(int event) { const Fl_Menu_Item* m = New_Menu->popup(mx,my,"New",myprev); if (m && m->callback()) {myprev = m; m->do_callback(this->o);} popupx = 0x7FFFFFFF; popupy = 0x7FFFFFFF; // mark as invalid (MAXINT) - in_this_only = nullptr; + in_this_only = 0; return 1; } // find the innermost item clicked on: @@ -1178,7 +1178,7 @@ int Window_Node::handle(int event) { return 1; case 'o': - toggle_overlays(nullptr, nullptr); + toggle_overlays(0, 0); break; default: @@ -1189,8 +1189,8 @@ int Window_Node::handle(int event) { in_this_only = this; // modifies how some menu items work. const Fl_Menu_Item* m = Fluid.main_menu->test_shortcut(); if (m && m->callback()) m->do_callback(this->o); - in_this_only = nullptr; - return (m != nullptr);} + in_this_only = 0; + return (m != 0);} default: return 0; @@ -1310,7 +1310,7 @@ int Window_Node::read_fdesign(const char* propname, const char* value) { Widget_Class_Node Widget_Class_Node::prototype; -Widget_Class_Node *current_widget_class = nullptr; +Widget_Class_Node *current_widget_class = 0; /** Create and add a new Widget Class node. @@ -1330,7 +1330,7 @@ Node *Widget_Class_Node::make(Strategy strategy) { if (!this->o) {// template widget this->o = new Fl_Window(100,100); - Fl_Group::current(nullptr); + Fl_Group::current(0); } myo->factory = this; myo->drag = 0; @@ -1369,7 +1369,7 @@ void Widget_Class_Node::read_property(fld::io::Project_Reader &f, const char *c) // This is useful for classes that contain a namespace component static const char *trimclassname(const char *n) { if (!n) - return nullptr; + return 0; const char *nn; while((nn = strstr(n, "::"))) { n = nn + 2; diff --git a/fluid/nodes/Window_Node.h b/fluid/nodes/Window_Node.h index 422326734..6403dd78e 100644 --- a/fluid/nodes/Window_Node.h +++ b/fluid/nodes/Window_Node.h @@ -72,8 +72,8 @@ protected: void setlabel(const char *) override; void write_code1(fld::io::Code_Writer& f) override; void write_code2(fld::io::Code_Writer& f) override; - Widget_Node *_make() override {return nullptr;} // we don't call this - Fl_Widget *widget(int,int,int,int) override {return nullptr;} + Widget_Node *_make() override {return 0;} // we don't call this + Fl_Widget *widget(int,int,int,int) override {return 0;} int recalc; // set by fix_overlay() void moveallchildren(int key=0); Type type() const override { return FLD_NODE_TYPE_Window; } @@ -92,7 +92,7 @@ public: numselected(0), recalc(0), modal(0), non_modal(0), - xclass(nullptr), + xclass(0), sr_min_w(0), sr_min_h(0), sr_max_w(0), sr_max_h(0) { } uchar modal, non_modal; @@ -134,7 +134,7 @@ public: static Widget_Class_Node prototype; protected: - Fl_Menu_Item* subtypes() override {return nullptr;} + Fl_Menu_Item* subtypes() override {return 0;} public: Widget_Class_Node() { diff --git a/fluid/nodes/factory.cxx b/fluid/nodes/factory.cxx index 90a1c4687..792a9ff72 100644 --- a/fluid/nodes/factory.cxx +++ b/fluid/nodes/factory.cxx @@ -89,11 +89,11 @@ // ---- Browser_Base ---- static Fl_Menu_Item browser_base_type_menu[] = { - {"No Select", 0, nullptr, (void*)nullptr}, - {"Select", 0, nullptr, (void*)FL_SELECT_BROWSER}, - {"Hold", 0, nullptr, (void*)FL_HOLD_BROWSER}, - {"Multi", 0, nullptr, (void*)FL_MULTI_BROWSER}, - {nullptr} + {"No Select", 0, 0, (void*)0}, + {"Select", 0, 0, (void*)FL_SELECT_BROWSER}, + {"Hold", 0, 0, (void*)FL_HOLD_BROWSER}, + {"Multi", 0, 0, (void*)FL_MULTI_BROWSER}, + {0} }; /** @@ -361,9 +361,9 @@ Valuator_Node Valuator_Node::prototype; // ---- Counter ---- static Fl_Menu_Item counter_type_menu[] = { - { "Normal", 0, nullptr, (void*)nullptr }, - { "Simple", 0, nullptr, (void*)FL_SIMPLE_COUNTER }, - { nullptr } + { "Normal", 0, 0, (void*)0 }, + { "Simple", 0, 0, (void*)FL_SIMPLE_COUNTER }, + { 0 } }; /** @@ -441,10 +441,10 @@ Adjuster_Node Adjuster_Node::prototype; // ---- Dial ---- static Fl_Menu_Item dial_type_menu[] = { - { "Dot", 0, nullptr, (void*)nullptr }, - { "Line", 0, nullptr, (void*)FL_LINE_DIAL }, - { "Fill", 0, nullptr, (void*)FL_FILL_DIAL }, - { nullptr } + { "Dot", 0, 0, (void*)0 }, + { "Line", 0, 0, (void*)FL_LINE_DIAL }, + { "Fill", 0, 0, (void*)FL_FILL_DIAL }, + { 0 } }; /** @@ -478,9 +478,9 @@ Dial_Node Dial_Node::prototype; // ---- Roller ---- static Fl_Menu_Item roller_type_menu[] = { - { "Vertical", 0, nullptr, (void*)nullptr }, - { "Horizontal", 0, nullptr, (void*)FL_HORIZONTAL }, - { nullptr } + { "Vertical", 0, 0, (void*)0 }, + { "Horizontal", 0, 0, (void*)FL_HORIZONTAL }, + { 0 } }; /** @@ -516,13 +516,13 @@ Roller_Node Roller_Node::prototype; // ---- Slider ---- static Fl_Menu_Item slider_type_menu[] = { - { "Vertical", 0, nullptr, (void*)nullptr }, - { "Horizontal", 0, nullptr, (void*)FL_HOR_SLIDER }, - { "Vert Fill", 0, nullptr, (void*)FL_VERT_FILL_SLIDER }, - { "Horz Fill", 0, nullptr, (void*)FL_HOR_FILL_SLIDER }, - { "Vert Knob", 0, nullptr, (void*)FL_VERT_NICE_SLIDER }, - { "Horz Knob", 0, nullptr, (void*)FL_HOR_NICE_SLIDER }, - { nullptr } + { "Vertical", 0, 0, (void*)0 }, + { "Horizontal", 0, 0, (void*)FL_HOR_SLIDER }, + { "Vert Fill", 0, 0, (void*)FL_VERT_FILL_SLIDER }, + { "Horz Fill", 0, 0, (void*)FL_HOR_FILL_SLIDER }, + { "Vert Knob", 0, 0, (void*)FL_VERT_NICE_SLIDER }, + { "Horz Knob", 0, 0, (void*)FL_HOR_NICE_SLIDER }, + { 0 } }; /** @@ -560,9 +560,9 @@ Slider_Node Slider_Node::prototype; // ---- Scrollbar ---- static Fl_Menu_Item scrollbar_type_menu[] = { - { "Vertical", 0, nullptr, (void*)nullptr }, - { "Horizontal", 0, nullptr, (void*)FL_HOR_SLIDER }, - { nullptr } + { "Vertical", 0, 0, (void*)0 }, + { "Horizontal", 0, 0, (void*)FL_HOR_SLIDER }, + { 0 } }; /** @@ -718,12 +718,12 @@ Value_Output_Node Value_Output_Node::prototype; // ---- Input ---- static Fl_Menu_Item input_type_menu[] = { - { "Normal", 0, nullptr, (void*)nullptr }, - { "Multiline", 0, nullptr, (void*)FL_MULTILINE_INPUT }, - { "Secret", 0, nullptr, (void*)FL_SECRET_INPUT }, - { "Int", 0, nullptr, (void*)FL_INT_INPUT }, - { "Float", 0, nullptr, (void*)FL_FLOAT_INPUT }, - {nullptr} + { "Normal", 0, 0, (void*)0 }, + { "Multiline", 0, 0, (void*)FL_MULTILINE_INPUT }, + { "Secret", 0, 0, (void*)FL_SECRET_INPUT }, + { "Int", 0, 0, (void*)FL_INT_INPUT }, + { "Float", 0, 0, (void*)FL_FLOAT_INPUT }, + {0} }; /** @@ -790,7 +790,7 @@ public: typedef Input_Node super; static File_Input_Node prototype; private: - Fl_Menu_Item *subtypes() override { return nullptr; } // Don't inherit. + Fl_Menu_Item *subtypes() override { return 0; } // Don't inherit. public: void ideal_size(int &w, int &h) override { auto layout = Fluid.proj.layout; @@ -816,9 +816,9 @@ File_Input_Node File_Input_Node::prototype; // ---- Output ---- static Fl_Menu_Item output_type_menu[] = { - { "Normal", 0, nullptr, (void*)FL_NORMAL_OUTPUT }, - { "Multiline", 0, nullptr, (void*)FL_MULTILINE_OUTPUT }, - { nullptr } + { "Normal", 0, 0, (void*)FL_NORMAL_OUTPUT }, + { "Multiline", 0, 0, (void*)FL_MULTILINE_OUTPUT }, + { 0 } }; /** @@ -936,7 +936,7 @@ Text_Editor_Node Text_Editor_Node::prototype; /** Use this terminal instead of Fl_Terminal to capture resize actions. */ class Fl_Terminal_Proxy : public Fl_Terminal { public: - Fl_Terminal_Proxy(int x, int y, int w, int h, const char *l=nullptr) + Fl_Terminal_Proxy(int x, int y, int w, int h, const char *l=0) : Fl_Terminal(x, y, w, h, l) { } void print_sample_text() { clear_screen_home(false); @@ -955,7 +955,7 @@ public: Fl_Font tfont_; int tsize_; Fl_Color tcolor_; - Fl_Batchmode_Terminal(int x, int y, int w, int h, const char *l=nullptr) + Fl_Batchmode_Terminal(int x, int y, int w, int h, const char *l=0) : Fl_Group(x, y, w, h, l) { // set the defaults that Fl_Terminal would set box(FL_DOWN_BOX); @@ -987,7 +987,7 @@ public: // Older .fl files with Fl_Simple_Terminal will create a Fl_Terminal instead. const char *alt_type_name() override { return "Fl_Simple_Terminal"; } Fl_Widget *widget(int x, int y, int w, int h) override { - Fl_Widget *ret = nullptr; + Fl_Widget *ret = 0; if (Fluid.batch_mode) { ret = new Fl_Batchmode_Terminal(x, y, w, h); } else { @@ -1123,9 +1123,9 @@ Progress_Node Progress_Node::prototype; // ---- Spinner ---- static Fl_Menu_Item spinner_type_menu[] = { - { "Integer", 0, nullptr, (void*)FL_INT_INPUT }, - { "Float", 0, nullptr, (void*)FL_FLOAT_INPUT }, - { nullptr } + { "Integer", 0, 0, (void*)FL_INT_INPUT }, + { "Float", 0, 0, (void*)FL_FLOAT_INPUT }, + { 0 } }; /** @@ -1273,7 +1273,7 @@ static Node *known_types[] = { lower case 't' in type. \param[in] strategy add after current or as last child \param[in] and_open if set to true, call open() on the widget after creating it - \return the newly created type or nullptr + \return the newly created type or 0 \see add_new_widget_from_file(const char*, int) add_new_widget_from_user(Node*, int) @@ -1403,7 +1403,7 @@ Node *add_new_widget_from_user(Node *inPrototype, Strategy strategy, bool and_op \param[in] inName find the right prototype by this name \param[in] strategy where to add the node \param[in] and_open if set to true, call open() on the widget after creating it - \return the newly created type or nullptr + \return the newly created type or 0 \see add_new_widget_from_file(const char*, int) add_new_widget_from_user(Node*, int) @@ -1414,14 +1414,14 @@ Node *add_new_widget_from_user(const char *inName, Strategy strategy, bool and_o if (prototype) return add_new_widget_from_user(prototype, strategy, and_open); else - return nullptr; + return 0; } /** Callback for all non-widget menu items. */ static void cbf(Fl_Widget *, void *v) { - Node *t = nullptr; + Node *t = 0; if (Fluid.proj.tree.current && Fluid.proj.tree.current->can_have_children()) t = ((Node*)v)->make(Strategy::AS_LAST_CHILD); else @@ -1436,7 +1436,7 @@ static void cbf(Fl_Widget *, void *v) { wants to create. */ static void cb(Fl_Widget *, void *v) { - Node *t = nullptr; + Node *t = 0; if (Fluid.proj.tree.current && Fluid.proj.tree.current->can_have_children()) t = add_new_widget_from_user((Node*)v, Strategy::AS_LAST_CHILD); else @@ -1449,7 +1449,7 @@ static void cb(Fl_Widget *, void *v) { defined further up in this file. */ Fl_Menu_Item New_Menu[] = { - {"Code",0,nullptr,nullptr,FL_SUBMENU}, + {"Code",0,0,0,FL_SUBMENU}, {"Function/Method",0,cbf,(void*)&Function_Node::prototype}, {"Code",0,cbf,(void*)&Code_Node::prototype}, {"Code Block",0,cbf,(void*)&CodeBlock_Node::prototype}, @@ -1459,70 +1459,70 @@ Fl_Menu_Item New_Menu[] = { {"Widget Class",0,cb,(void*)&Widget_Class_Node::prototype}, {"Comment",0,cbf,(void*)&Comment_Node::prototype}, {"Inlined Data",0,cbf,(void*)&Data_Node::prototype}, - {nullptr}, - {"Group",0,nullptr,nullptr,FL_SUBMENU}, - {nullptr,0,cb,(void*)&Window_Node::prototype}, - {nullptr,0,cb,(void*)&Group_Node::prototype}, - {nullptr,0,cb,(void*)&Pack_Node::prototype}, - {nullptr,0,cb,(void*)&Flex_Node::prototype}, - {nullptr,0,cb,(void*)&Tabs_Node::prototype}, - {nullptr,0,cb,(void*)&Scroll_Node::prototype}, - {nullptr,0,cb,(void*)&Tile_Node::prototype}, - {nullptr,0,cb,(void*)&Wizard_Node::prototype}, - {nullptr,0,cb,(void*)&Grid_Node::prototype}, - {nullptr}, - {"Buttons",0,nullptr,nullptr,FL_SUBMENU}, - {nullptr,0,cb,(void*)&Button_Node::prototype}, - {nullptr,0,cb,(void*)&Return_Button_Node::prototype}, - {nullptr,0,cb,(void*)&Light_Button_Node::prototype}, - {nullptr,0,cb,(void*)&Check_Button_Node::prototype}, - {nullptr,0,cb,(void*)&Repeat_Button_Node::prototype}, - {nullptr,0,cb,(void*)&Round_Button_Node::prototype}, - {nullptr}, - {"Valuators",0,nullptr,nullptr,FL_SUBMENU}, - {nullptr,0,cb,(void*)&Slider_Node::prototype}, - {nullptr,0,cb,(void*)&Scrollbar_Node::prototype}, - {nullptr,0,cb,(void*)&Value_Slider_Node::prototype}, - {nullptr,0,cb,(void*)&Adjuster_Node::prototype}, - {nullptr,0,cb,(void*)&Counter_Node::prototype}, - {nullptr,0,cb,(void*)&Spinner_Node::prototype}, - {nullptr,0,cb,(void*)&Dial_Node::prototype}, - {nullptr,0,cb,(void*)&Roller_Node::prototype}, - {nullptr,0,cb,(void*)&Value_Input_Node::prototype}, - {nullptr,0,cb,(void*)&Value_Output_Node::prototype}, - {nullptr}, - {"Text",0,nullptr,nullptr,FL_SUBMENU}, - {nullptr,0,cb,(void*)&Input_Node::prototype}, - {nullptr,0,cb,(void*)&Output_Node::prototype}, - {nullptr,0,cb,(void*)&Text_Editor_Node::prototype}, - {nullptr,0,cb,(void*)&Text_Display_Node::prototype}, - {nullptr,0,cb,(void*)&File_Input_Node::prototype}, - {nullptr,0,cb,(void*)&Terminal_Node::prototype}, - {nullptr}, - {"Menus",0,nullptr,nullptr,FL_SUBMENU}, - {nullptr,0,cb,(void*)&Menu_Bar_Node::prototype}, - {nullptr,0,cb,(void*)&Menu_Button_Node::prototype}, - {nullptr,0,cb,(void*)&Choice_Node::prototype}, - {nullptr,0,cb,(void*)&Input_Choice_Node::prototype}, - {nullptr,0,cb, (void*)&Submenu_Node::prototype}, - {nullptr,0,cb, (void*)&Menu_Item_Node::prototype}, + {0}, + {"Group",0,0,0,FL_SUBMENU}, + {0,0,cb,(void*)&Window_Node::prototype}, + {0,0,cb,(void*)&Group_Node::prototype}, + {0,0,cb,(void*)&Pack_Node::prototype}, + {0,0,cb,(void*)&Flex_Node::prototype}, + {0,0,cb,(void*)&Tabs_Node::prototype}, + {0,0,cb,(void*)&Scroll_Node::prototype}, + {0,0,cb,(void*)&Tile_Node::prototype}, + {0,0,cb,(void*)&Wizard_Node::prototype}, + {0,0,cb,(void*)&Grid_Node::prototype}, + {0}, + {"Buttons",0,0,0,FL_SUBMENU}, + {0,0,cb,(void*)&Button_Node::prototype}, + {0,0,cb,(void*)&Return_Button_Node::prototype}, + {0,0,cb,(void*)&Light_Button_Node::prototype}, + {0,0,cb,(void*)&Check_Button_Node::prototype}, + {0,0,cb,(void*)&Repeat_Button_Node::prototype}, + {0,0,cb,(void*)&Round_Button_Node::prototype}, + {0}, + {"Valuators",0,0,0,FL_SUBMENU}, + {0,0,cb,(void*)&Slider_Node::prototype}, + {0,0,cb,(void*)&Scrollbar_Node::prototype}, + {0,0,cb,(void*)&Value_Slider_Node::prototype}, + {0,0,cb,(void*)&Adjuster_Node::prototype}, + {0,0,cb,(void*)&Counter_Node::prototype}, + {0,0,cb,(void*)&Spinner_Node::prototype}, + {0,0,cb,(void*)&Dial_Node::prototype}, + {0,0,cb,(void*)&Roller_Node::prototype}, + {0,0,cb,(void*)&Value_Input_Node::prototype}, + {0,0,cb,(void*)&Value_Output_Node::prototype}, + {0}, + {"Text",0,0,0,FL_SUBMENU}, + {0,0,cb,(void*)&Input_Node::prototype}, + {0,0,cb,(void*)&Output_Node::prototype}, + {0,0,cb,(void*)&Text_Editor_Node::prototype}, + {0,0,cb,(void*)&Text_Display_Node::prototype}, + {0,0,cb,(void*)&File_Input_Node::prototype}, + {0,0,cb,(void*)&Terminal_Node::prototype}, + {0}, + {"Menus",0,0,0,FL_SUBMENU}, + {0,0,cb,(void*)&Menu_Bar_Node::prototype}, + {0,0,cb,(void*)&Menu_Button_Node::prototype}, + {0,0,cb,(void*)&Choice_Node::prototype}, + {0,0,cb,(void*)&Input_Choice_Node::prototype}, + {0,0,cb, (void*)&Submenu_Node::prototype}, + {0,0,cb, (void*)&Menu_Item_Node::prototype}, {"Checkbox Menu Item",0,cb, (void*)&Checkbox_Menu_Item_Node::prototype}, {"Radio Menu Item",0,cb, (void*)&Radio_Menu_Item_Node::prototype}, - {nullptr}, - {"Browsers",0,nullptr,nullptr,FL_SUBMENU}, - {nullptr,0,cb,(void*)&Browser_Node::prototype}, - {nullptr,0,cb,(void*)&Check_Browser_Node::prototype}, - {nullptr,0,cb,(void*)&File_Browser_Node::prototype}, - {nullptr,0,cb,(void*)&Tree_Node::prototype}, - {nullptr,0,cb,(void*)&Help_View_Node::prototype}, - {nullptr,0,cb,(void*)&Table_Node::prototype}, - {nullptr}, - {"Other",0,nullptr,nullptr,FL_SUBMENU}, - {nullptr,0,cb,(void*)&Box_Node::prototype}, - {nullptr,0,cb,(void*)&Clock_Node::prototype}, - {nullptr,0,cb,(void*)&Progress_Node::prototype}, - {nullptr}, - {nullptr}}; + {0}, + {"Browsers",0,0,0,FL_SUBMENU}, + {0,0,cb,(void*)&Browser_Node::prototype}, + {0,0,cb,(void*)&Check_Browser_Node::prototype}, + {0,0,cb,(void*)&File_Browser_Node::prototype}, + {0,0,cb,(void*)&Tree_Node::prototype}, + {0,0,cb,(void*)&Help_View_Node::prototype}, + {0,0,cb,(void*)&Table_Node::prototype}, + {0}, + {"Other",0,0,0,FL_SUBMENU}, + {0,0,cb,(void*)&Box_Node::prototype}, + {0,0,cb,(void*)&Clock_Node::prototype}, + {0,0,cb,(void*)&Progress_Node::prototype}, + {0}, + {0}}; #include <FL/Fl_Multi_Label.H> @@ -1532,8 +1532,8 @@ Fl_Menu_Item New_Menu[] = { The icon may be null. If ic is null only the text is assigned to the label and Fl_Multi_Label is not used. \param[in] mi pointer to tme menu item that will be modified - \param[in] ic icon for the menu, may be nullptr - \param[in] txt new label text, may *not* be nullptr, will not be copied + \param[in] ic icon for the menu, may be 0 + \param[in] txt new label text, may *not* be 0, will not be copied */ static void make_iconlabel(Fl_Menu_Item *mi, Fl_Image *ic, const char *txt) { @@ -1580,12 +1580,12 @@ void fill_in_New_Menu() { Find the correct prototype for a given type name. \param[in] inName a C string that must match type_name() or alt_type_name() of one of the known Node classes. - \return the matching prototype or nullptr + \return the matching prototype or 0 */ Node *typename_to_prototype(const char *inName) { - if (inName==nullptr || *inName==0) - return nullptr; + if (inName==0 || *inName==0) + return 0; for (unsigned i = 0; i < sizeof(known_types)/sizeof(*known_types); i++) { Node *prototype = known_types[i]; if (fl_ascii_strcasecmp(inName, prototype->type_name())==0) @@ -1593,7 +1593,7 @@ Node *typename_to_prototype(const char *inName) if (fl_ascii_strcasecmp(inName, prototype->alt_type_name())==0) return prototype; } - return nullptr; + return 0; } /** @@ -1605,7 +1605,7 @@ Node *typename_to_prototype(const char *inName) \param[in] inName a C string that described the type we want \param[in] strategy add after current or as last child - \return the node that was created or nullptr + \return the node that was created or 0 \see add_new_widget_from_file(const char*, int) add_new_widget_from_user(Node*, int) add_new_widget_from_user(const char*, int) @@ -1613,7 +1613,7 @@ Node *typename_to_prototype(const char *inName) Node *add_new_widget_from_file(const char *inName, Strategy strategy) { Node *prototype = typename_to_prototype(inName); if (!prototype) - return nullptr; + return 0; Node *new_node = prototype->make(strategy); return new_node; } diff --git a/fluid/panels/codeview_panel.cxx b/fluid/panels/codeview_panel.cxx index 3c46715bd..728ee986c 100644 --- a/fluid/panels/codeview_panel.cxx +++ b/fluid/panels/codeview_panel.cxx @@ -26,9 +26,9 @@ #include <FL/Fl_Tabs.H> #include <FL/Fl_Button.H> #include "../src/flstring.h" -static char *cv_source_filename = nullptr; -static char *cv_header_filename = nullptr; -static char *cv_design_filename = nullptr; +static char *cv_source_filename = 0; +static char *cv_header_filename = 0; +static char *cv_design_filename = 0; int cv_code_choice; extern void select_only(Node *o); extern void reveal_in_browser(Node *t); @@ -156,17 +156,17 @@ void update_codeview_cb(class Fl_Button*, void*) { if (!cv_source_filename) { cv_source_filename = (char*)malloc(FL_PATH_MAX); - fl_strlcpy(cv_source_filename, Fluid.get_tmpdir().c_str(), FL_PATH_MAX); + fl_strlcpy(cv_source_filename, Fluid.get_tmpdir(), FL_PATH_MAX); fl_strlcat(cv_source_filename, "codeview_tmp.cxx", FL_PATH_MAX); } if (!cv_header_filename) { cv_header_filename = (char*)malloc(FL_PATH_MAX); - fl_strlcpy(cv_header_filename, Fluid.get_tmpdir().c_str(), FL_PATH_MAX); + fl_strlcpy(cv_header_filename, Fluid.get_tmpdir(), FL_PATH_MAX); fl_strlcat(cv_header_filename, "codeview_tmp.h", FL_PATH_MAX); } if (!cv_design_filename) { cv_design_filename = (char*)malloc(FL_PATH_MAX); - fl_strlcpy(cv_design_filename, Fluid.get_tmpdir().c_str(), FL_PATH_MAX); + fl_strlcpy(cv_design_filename, Fluid.get_tmpdir(), FL_PATH_MAX); fl_strlcat(cv_design_filename, "codeview_tmp.fl", FL_PATH_MAX); } @@ -178,18 +178,20 @@ void update_codeview_cb(class Fl_Button*, void*) { } else if (cv_strings->visible_r()) { static const char *exts[] = { ".txt", ".po", ".msg" }; char fn[FL_PATH_MAX+1]; - fl_strlcpy(fn, Fluid.get_tmpdir().c_str(), FL_PATH_MAX); + fl_strlcpy(fn, Fluid.get_tmpdir(), FL_PATH_MAX); fl_strlcat(fn, "strings", FL_PATH_MAX); - fl_filename_setext(fn, FL_PATH_MAX, exts[static_cast<int>(Fluid.proj.i18n.type)]); + fl_filename_setext(fn, FL_PATH_MAX, exts[(int)(Fluid.proj.i18n.type)]); fld::io::write_strings(Fluid.proj, fn); int top = cv_strings->top_line(); cv_strings->buffer()->loadfile(fn); cv_strings->scroll(top, 0); } else if (cv_source->visible_r() || cv_header->visible_r()) { - std::string code_file_name_bak = Fluid.proj.code_file_name; - Fluid.proj.code_file_name = cv_source_filename; - std::string header_file_name_bak = Fluid.proj.header_file_name; - Fluid.proj.header_file_name = cv_header_filename; + char code_file_name_bak[FL_PATH_MAX]; + fl_strlcpy(code_file_name_bak, Fluid.proj.code_file_name(), FL_PATH_MAX); + Fluid.proj.set_code_file_name(cv_source_filename); + char header_file_name_bak[FL_PATH_MAX]; + fl_strlcpy(header_file_name_bak, Fluid.proj.header_file_name(), FL_PATH_MAX); + Fluid.proj.set_header_file_name(cv_header_filename); // generate the code and load the files fld::io::Code_Writer f(Fluid.proj); @@ -208,8 +210,8 @@ void update_codeview_cb(class Fl_Button*, void*) { update_codeview_position(); } - Fluid.proj.code_file_name = code_file_name_bak; - Fluid.proj.header_file_name = header_file_name_bak; + Fluid.proj.set_code_file_name(code_file_name_bak); + Fluid.proj.set_header_file_name(header_file_name_bak); } } @@ -284,7 +286,7 @@ Fl_Button *cv_find_text_case=(Fl_Button *)0; Fl_Input *cv_find_text=(Fl_Input *)0; static void cb_cv_find_text(Fl_Input* o, void*) { - Fl_Text_Display *e = nullptr; + Fl_Text_Display *e = 0; if (cv_source->visible_r()) { e = cv_source; } else if (cv_header->visible_r()) { @@ -305,7 +307,7 @@ static void cb_cv_find_text(Fl_Input* o, void*) { } static void cb_(Fl_Button*, void*) { - Fl_Text_Display *e = nullptr; + Fl_Text_Display *e = 0; if (cv_source->visible_r()) { e = cv_source; } else if (cv_header->visible_r()) { @@ -330,7 +332,7 @@ static void cb_(Fl_Button*, void*) { } static void cb_1(Fl_Button*, void*) { - Fl_Text_Display *e = nullptr; + Fl_Text_Display *e = 0; if (cv_source->visible_r()) { e = cv_source; } else if (cv_header->visible_r()) { @@ -356,7 +358,7 @@ static void cb_1(Fl_Button*, void*) { static void cb_Reveal(Fl_Button*, void*) { if (codeview_panel && codeview_panel->visible()) { - Node *node = nullptr; + Node *node = 0; if (cv_source->visible_r()) node = Fluid.proj.tree.find_in_text(0, cv_source->insert_position()); else if (cv_header->visible_r()) diff --git a/fluid/panels/settings_panel.cxx b/fluid/panels/settings_panel.cxx index e108e57e4..3b32fc665 100644 --- a/fluid/panels/settings_panel.cxx +++ b/fluid/panels/settings_panel.cxx @@ -24,7 +24,7 @@ #include <FL/fl_ask.H> #include "../src/flstring.h" #include <string.h> -using namespace fld::widget; + void scheme_cb(Fl_Scheme_Choice *, void *); int w_settings_shell_list_selected; @@ -371,10 +371,10 @@ Fl_Input *header_file_input=(Fl_Input *)0; static void cb_header_file_input(Fl_Input* o, void* v) { if (v == LOAD) { - o->value(Fluid.proj.header_file_name.c_str()); + o->value(Fluid.proj.header_file_name()); } else { - if (strcmp(Fluid.proj.header_file_name.c_str(), o->value())) { - Fluid.proj.header_file_name = o->value(); + if (strcmp(Fluid.proj.header_file_name(), o->value())) { + Fluid.proj.set_header_file_name(o->value()); Fluid.proj.set_modflag(1); } } @@ -384,10 +384,10 @@ Fl_Input *code_file_input=(Fl_Input *)0; static void cb_code_file_input(Fl_Input* o, void* v) { if (v == LOAD) { - o->value(Fluid.proj.code_file_name.c_str()); + o->value(Fluid.proj.code_file_name()); } else { - if (strcmp(Fluid.proj.code_file_name.c_str(), o->value())) { - Fluid.proj.code_file_name = o->value(); + if (strcmp(Fluid.proj.code_file_name(), o->value())) { + Fluid.proj.set_code_file_name(o->value()); Fluid.proj.set_modflag(1); } } @@ -410,10 +410,10 @@ Fl_Input *include_guard_input=(Fl_Input *)0; static void cb_include_guard_input(Fl_Input* o, void* v) { if (v == LOAD) { - o->value(Fluid.proj.include_guard.c_str()); + o->value(Fluid.proj.include_guard()); } else { - if (strcmp(Fluid.proj.include_guard.c_str(), o->value())) { - Fluid.proj.include_guard = o->value(); + if (strcmp(Fluid.proj.include_guard(), o->value())) { + Fluid.proj.set_include_guard(o->value()); Fluid.proj.set_modflag(1); } } @@ -510,11 +510,11 @@ Fl_Choice *layout_choice=(Fl_Choice *)0; static void cb_layout_choice(Fl_Choice* o, void* v) { if (v == LOAD) { - o->value(Fluid.layout_list.current_suite()); + o->value(Fluid.layout_list->current_suite()); } else { int index = o->value(); - Fluid.layout_list.current_suite(index); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->current_suite(index); + Fluid.layout_list->update_dialogs(); } } @@ -526,24 +526,25 @@ Fl_Menu_Item menu_layout_choice[] = { static void cb_2(Fl_Button*, void* v) { // Clone the current layout suite + char old_name[256]; if (v == LOAD) return; - std::string old_name = "Copy of "; - old_name.append(Fluid.layout_list[Fluid.layout_list.current_suite()].name_); - const char *new_name = fl_input("Enter a name for the new layout:", old_name.c_str()); - if (new_name == nullptr) + snprintf(old_name, sizeof(old_name), "Copy of %s", + (*Fluid.layout_list)[Fluid.layout_list->current_suite()].name_); + const char *new_name = fl_input("Enter a name for the new layout:", old_name); + if (new_name == 0) return; - Fluid.layout_list.add(new_name); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->add(new_name); + Fluid.layout_list->update_dialogs(); } Fl_Menu_Button *w_layout_menu=(Fl_Menu_Button *)0; static void cb_w_layout_menu(Fl_Menu_Button*, void* v) { if (v == LOAD) { - fld::app::Layout_Suite &suite = Fluid.layout_list[Fluid.layout_list.current_suite()]; + fld::app::Layout_Suite &suite = (*Fluid.layout_list)[Fluid.layout_list->current_suite()]; if (suite.storage_ == FLD_TOOL_STORE_INTERNAL) { w_layout_menu_rename->deactivate(); for (int i=1; i<4; i++) w_layout_menu_storage[i]->deactivate(); @@ -553,44 +554,44 @@ static void cb_w_layout_menu(Fl_Menu_Button*, void* v) { for (int i=1; i<4; i++) w_layout_menu_storage[i]->activate(); w_layout_menu_delete->activate(); } - w_layout_menu_storage[static_cast<int>(suite.storage_)]->setonly(menu_w_layout_menu); + w_layout_menu_storage[(int)(suite.storage_)]->setonly(menu_w_layout_menu); } } static void cb_w_layout_menu_rename(Fl_Menu_*, void*) { // Rename the current layout suite - std::string old_name = Fluid.layout_list[Fluid.layout_list.current_suite()].name_; - const char *new_name = fl_input("Enter a new name for the layout:", old_name.c_str()); - if (new_name == nullptr) + const char *old_name = (*Fluid.layout_list)[Fluid.layout_list->current_suite()].name_; + const char *new_name = fl_input("Enter a new name for the layout:", old_name); + if (new_name == 0) return; - Fluid.layout_list.rename(new_name); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->rename(new_name); + Fluid.layout_list->update_dialogs(); } static void cb_w_layout_menu_storage(Fl_Menu_*, void*) { - fld::app::Layout_Suite &suite = Fluid.layout_list[Fluid.layout_list.current_suite()]; + fld::app::Layout_Suite &suite = (*Fluid.layout_list)[Fluid.layout_list->current_suite()]; suite.storage(FLD_TOOL_STORE_INTERNAL); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->update_dialogs(); } static void cb_w_layout_menu_storage1(Fl_Menu_*, void*) { - fld::app::Layout_Suite &suite = Fluid.layout_list[Fluid.layout_list.current_suite()]; + fld::app::Layout_Suite &suite = (*Fluid.layout_list)[Fluid.layout_list->current_suite()]; suite.storage(FLD_TOOL_STORE_USER); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->update_dialogs(); } static void cb_w_layout_menu_storage2(Fl_Menu_*, void*) { - fld::app::Layout_Suite &suite = Fluid.layout_list[Fluid.layout_list.current_suite()]; + fld::app::Layout_Suite &suite = (*Fluid.layout_list)[Fluid.layout_list->current_suite()]; suite.storage(FLD_TOOL_STORE_PROJECT); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->update_dialogs(); } static void cb_w_layout_menu_storage3(Fl_Menu_*, void*) { - fld::app::Layout_Suite &suite = Fluid.layout_list[Fluid.layout_list.current_suite()]; + fld::app::Layout_Suite &suite = (*Fluid.layout_list)[Fluid.layout_list->current_suite()]; suite.storage(FLD_TOOL_STORE_FILE); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->update_dialogs(); } static void cb_w_layout_menu_load(Fl_Menu_*, void*) { @@ -603,33 +604,35 @@ static void cb_w_layout_menu_load(Fl_Menu_*, void*) { if (fnfc.show() != 0) return; const char *new_filename = fnfc.filename(); if (!new_filename) return; - Fluid.layout_list.load(new_filename); - //Fluid.layout_list.current_suite(n); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->load(new_filename); + //Fluid.layout_list->current_suite(n); + Fluid.layout_list->update_dialogs(); } static void cb_w_layout_menu_save(Fl_Menu_*, void*) { // Give the user a file chooser with a suggested name + char path[FL_PATH_MAX]; Fl_Native_File_Chooser fnfc; fnfc.title("Save Layout Settings:"); fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE); fnfc.options(Fl_Native_File_Chooser::SAVEAS_CONFIRM | Fl_Native_File_Chooser::USE_FILTER_EXT); fnfc.filter("FLUID Layouts\t*.fll\n"); - std::string filename = Fluid.layout_list.filename_; - fnfc.directory(fl_filename_path_str(filename).c_str()); - fnfc.preset_file(fl_filename_name_str(filename).c_str()); + const char *filename = Fluid.layout_list->filename_.c_str(); + fl_filename_path(path, FL_PATH_MAX, filename); + fnfc.directory(path); + fnfc.preset_file(fl_filename_name(filename)); if (fnfc.show() != 0) return; const char *new_filename = fnfc.filename(); if (!new_filename) return; - Fluid.layout_list.filename_ = new_filename; - Fluid.layout_list.save(new_filename); + Fluid.layout_list->filename_ = new_filename; + Fluid.layout_list->save(new_filename); } static void cb_w_layout_menu_delete(Fl_Menu_*, void*) { // remove the current suite - Fluid.layout_list.remove(Fluid.layout_list.current_suite()); - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->remove(Fluid.layout_list->current_suite()); + Fluid.layout_list->update_dialogs(); } Fl_Menu_Item menu_w_layout_menu[] = { @@ -894,7 +897,7 @@ static void cb_w_settings_shell_list(Fl_Browser* o, void* v) { w_settings_shell_list_selected = 0; for (int i=0; i<g_shell_config->list_size; i++) { Fd_Shell_Command *cmd = g_shell_config->list[i]; - o->add(cmd->name.c_str()); + o->add(cmd->name); if (cmd->storage == FLD_TOOL_STORE_USER) o->icon(i+1, w_settings_shell_fd_user->image()); else if (cmd->storage == FLD_TOOL_STORE_PROJECT) @@ -927,7 +930,7 @@ static void cb_a(Fl_Button*, void* v) { int selected = w_settings_shell_list_selected; Fd_Shell_Command *cmd = new Fd_Shell_Command("new shell command"); g_shell_config->insert(selected, cmd); - w_settings_shell_list->insert(selected+1, cmd->name.c_str()); + w_settings_shell_list->insert(selected+1, cmd->name); w_settings_shell_list->deselect(); w_settings_shell_list->value(selected+1); if (cmd->storage == FLD_TOOL_STORE_USER) { @@ -957,7 +960,7 @@ static void cb_w_settings_shell_dup(Fl_Button* o, void* v) { if (!selected) return; Fd_Shell_Command *cmd = new Fd_Shell_Command(g_shell_config->list[selected-1]); g_shell_config->insert(selected, cmd); - w_settings_shell_list->insert(selected+1, cmd->name.c_str()); + w_settings_shell_list->insert(selected+1, cmd->name); w_settings_shell_list->deselect(); w_settings_shell_list->value(selected+1); if (cmd->storage == FLD_TOOL_STORE_USER) { @@ -986,7 +989,7 @@ static void cb_w_settings_shell_remove(Fl_Button* o, void* v) { } else { if (!selected) return; int ret = fl_choice("Delete the shell command\n\"%s\"?\n\nThis can not be undone.", - "Delete", "Cancel", nullptr, g_shell_config->list[selected-1]->name.c_str()); + "Delete", "Cancel", 0, g_shell_config->list[selected-1]->name); if (ret==1) return; if (g_shell_config->at(selected-1)->storage == FLD_TOOL_STORE_PROJECT) Fluid.proj.set_modflag(1); g_shell_config->remove(selected-1); @@ -1064,14 +1067,14 @@ static void cb_Name(Fl_Input* o, void* v) { int selected = w_settings_shell_list_selected; if (v == LOAD) { if (selected) { - o->value(g_shell_config->list[selected-1]->name.c_str()); + o->value(g_shell_config->list[selected-1]->name); } else { o->value(""); } } else { if (selected) { Fd_Shell_Command *cmd = g_shell_config->list[selected-1]; - cmd->name = o->value(); + cmd->set_name(o->value()); w_settings_shell_list->text(selected, o->value()); if (cmd->storage == FLD_TOOL_STORE_PROJECT) Fluid.proj.set_modflag(1); } @@ -1082,14 +1085,14 @@ static void cb_Menu(Fl_Input* o, void* v) { int selected = w_settings_shell_list_selected; if (v == LOAD) { if (selected) { - o->value(g_shell_config->list[selected-1]->label.c_str()); + o->value(g_shell_config->list[selected-1]->label); } else { o->value(""); } } else { if (selected) { Fd_Shell_Command *cmd = g_shell_config->list[selected-1]; - cmd->label = o->value(); + cmd->set_label(o->value()); cmd->update_shell_menu(); if (cmd->storage == FLD_TOOL_STORE_PROJECT) Fluid.proj.set_modflag(1); } @@ -1134,7 +1137,7 @@ static void cb_Store(Fl_Choice* o, void* v) { fld::Tool_Store ts = (fld::Tool_Store)(o->mvalue()->argument()); if (cmd->storage == FLD_TOOL_STORE_PROJECT) Fluid.proj.set_modflag(1); cmd->storage = ts; - //w_settings_shell_list->text(selected, cmd->name.c_str()); + //w_settings_shell_list->text(selected, cmd->name); if (cmd->storage == FLD_TOOL_STORE_USER) w_settings_shell_list->icon(selected, w_settings_shell_fd_user->image()); else if (cmd->storage == FLD_TOOL_STORE_PROJECT) @@ -1194,14 +1197,16 @@ static void cb_w_settings_shell_command(Fl_Text_Editor* o, void* v) { int selected = w_settings_shell_list_selected; if (v == LOAD) { if (selected) { - o->buffer()->text(g_shell_config->list[selected-1]->command.c_str()); + o->buffer()->text(g_shell_config->list[selected-1]->command); } else { o->buffer()->text(""); } } else { if (selected) { Fd_Shell_Command *cmd = g_shell_config->list[selected-1]; - cmd->command = o->buffer()->text(); + char *txt = o->buffer()->text(); + cmd->set_command(txt); + free(txt); if (cmd->storage == FLD_TOOL_STORE_PROJECT) Fluid.proj.set_modflag(1); } } @@ -1226,7 +1231,7 @@ static void cb_w_settings_shell_text_macros(Fl_Menu_Button* o, void*) { int pos = w_settings_shell_command->insert_position(); w_settings_shell_command->buffer()->insert(pos, word); } - w_settings_shell_command->do_callback(w_settings_shell_command, (void*)nullptr); + w_settings_shell_command->do_callback(w_settings_shell_command, (void*)0); } } @@ -2446,18 +2451,18 @@ Fl_Choice *w_settings_user_commenttext=(Fl_Choice *)0; static void cb_Reset(Fl_Button* o, void* v) { if (v == LOAD) return; - Node_Browser::label_color = 72; - Node_Browser::label_font = FL_HELVETICA; - Node_Browser::class_color = FL_FOREGROUND_COLOR; - Node_Browser::class_font = FL_HELVETICA_BOLD; - Node_Browser::func_color = FL_FOREGROUND_COLOR; - Node_Browser::func_font = FL_HELVETICA; - Node_Browser::name_color = FL_FOREGROUND_COLOR; - Node_Browser::name_font = FL_HELVETICA; - Node_Browser::code_color = FL_FOREGROUND_COLOR; - Node_Browser::code_font = FL_HELVETICA; - Node_Browser::comment_color = FL_DARK_GREEN; - Node_Browser::comment_font = FL_DARK_GREEN; + fld::widget::Node_Browser::label_color = 72; + fld::widget::Node_Browser::label_font = FL_HELVETICA; + fld::widget::Node_Browser::class_color = FL_FOREGROUND_COLOR; + fld::widget::Node_Browser::class_font = FL_HELVETICA_BOLD; + fld::widget::Node_Browser::func_color = FL_FOREGROUND_COLOR; + fld::widget::Node_Browser::func_font = FL_HELVETICA; + fld::widget::Node_Browser::name_color = FL_FOREGROUND_COLOR; + fld::widget::Node_Browser::name_font = FL_HELVETICA; + fld::widget::Node_Browser::code_color = FL_FOREGROUND_COLOR; + fld::widget::Node_Browser::code_font = FL_HELVETICA; + fld::widget::Node_Browser::comment_color = FL_DARK_GREEN; + fld::widget::Node_Browser::comment_font = FL_DARK_GREEN; o->parent()->do_callback(o->parent(), LOAD); widget_browser->redraw(); widget_browser->save_prefs(); @@ -2466,7 +2471,7 @@ static void cb_Reset(Fl_Button* o, void* v) { static void cb_Close(Fl_Button*, void*) { if (g_shell_config) g_shell_config->write(Fluid.preferences, FLD_TOOL_STORE_USER); - Fluid.layout_list.write(Fluid.preferences, FLD_TOOL_STORE_USER); + Fluid.layout_list->write(Fluid.preferences, FLD_TOOL_STORE_USER); settings_window->hide(); } @@ -3422,17 +3427,17 @@ Fl_Double_Window* make_settings_window() { o->labelfont(1); o->labelsize(12); o->textsize(11); - o->callback((Fl_Callback*)cb_Comments, (void*)(&Node_Browser::label_font)); + o->callback((Fl_Callback*)cb_Comments, (void*)(&fld::widget::Node_Browser::label_font)); Fl_Group::current()->resizable(o); o->menu(fontmenu); } // Fl_Choice* o { Fl_Button* o = new Fl_Button(271, 112, 51, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&Node_Browser::label_color)); + o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&fld::widget::Node_Browser::label_color)); } // Fl_Button* o { Fl_Menu_Button* o = new Fl_Menu_Button(322, 112, 18, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&Node_Browser::label_color)); + o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&fld::widget::Node_Browser::label_color)); o->menu(colormenu); } // Fl_Menu_Button* o o->end(); @@ -3448,17 +3453,17 @@ Fl_Double_Window* make_settings_window() { o->labelfont(1); o->labelsize(12); o->textsize(11); - o->callback((Fl_Callback*)cb_Comments, (void*)(&Node_Browser::class_font)); + o->callback((Fl_Callback*)cb_Comments, (void*)(&fld::widget::Node_Browser::class_font)); Fl_Group::current()->resizable(o); o->menu(fontmenu); } // Fl_Choice* o { Fl_Button* o = new Fl_Button(271, 137, 51, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&Node_Browser::class_color)); + o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&fld::widget::Node_Browser::class_color)); } // Fl_Button* o { Fl_Menu_Button* o = new Fl_Menu_Button(322, 137, 18, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&Node_Browser::class_color)); + o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&fld::widget::Node_Browser::class_color)); o->menu(colormenu); } // Fl_Menu_Button* o o->end(); @@ -3474,17 +3479,17 @@ Fl_Double_Window* make_settings_window() { o->labelfont(1); o->labelsize(12); o->textsize(11); - o->callback((Fl_Callback*)cb_Comments, (void*)(&Node_Browser::func_font)); + o->callback((Fl_Callback*)cb_Comments, (void*)(&fld::widget::Node_Browser::func_font)); Fl_Group::current()->resizable(o); o->menu(fontmenu); } // Fl_Choice* o { Fl_Button* o = new Fl_Button(271, 162, 51, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&Node_Browser::func_color)); + o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&fld::widget::Node_Browser::func_color)); } // Fl_Button* o { Fl_Menu_Button* o = new Fl_Menu_Button(322, 162, 18, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&Node_Browser::func_color)); + o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&fld::widget::Node_Browser::func_color)); o->menu(colormenu); } // Fl_Menu_Button* o o->end(); @@ -3500,17 +3505,17 @@ Fl_Double_Window* make_settings_window() { o->labelfont(1); o->labelsize(12); o->textsize(11); - o->callback((Fl_Callback*)cb_Comments, (void*)(&Node_Browser::name_font)); + o->callback((Fl_Callback*)cb_Comments, (void*)(&fld::widget::Node_Browser::name_font)); Fl_Group::current()->resizable(o); o->menu(fontmenu); } // Fl_Choice* o { Fl_Button* o = new Fl_Button(271, 187, 51, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&Node_Browser::name_color)); + o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&fld::widget::Node_Browser::name_color)); } // Fl_Button* o { Fl_Menu_Button* o = new Fl_Menu_Button(322, 187, 18, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&Node_Browser::name_color)); + o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&fld::widget::Node_Browser::name_color)); o->menu(colormenu); } // Fl_Menu_Button* o o->end(); @@ -3526,17 +3531,17 @@ Fl_Double_Window* make_settings_window() { o->labelfont(1); o->labelsize(12); o->textsize(11); - o->callback((Fl_Callback*)cb_Comments, (void*)(&Node_Browser::code_font)); + o->callback((Fl_Callback*)cb_Comments, (void*)(&fld::widget::Node_Browser::code_font)); Fl_Group::current()->resizable(o); o->menu(fontmenu); } // Fl_Choice* o { Fl_Button* o = new Fl_Button(271, 212, 51, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&Node_Browser::code_color)); + o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&fld::widget::Node_Browser::code_color)); } // Fl_Button* o { Fl_Menu_Button* o = new Fl_Menu_Button(322, 212, 18, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&Node_Browser::code_color)); + o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&fld::widget::Node_Browser::code_color)); o->menu(colormenu); } // Fl_Menu_Button* o o->end(); @@ -3552,17 +3557,17 @@ Fl_Double_Window* make_settings_window() { w_settings_user_commenttext->labelfont(1); w_settings_user_commenttext->labelsize(12); w_settings_user_commenttext->textsize(11); - w_settings_user_commenttext->callback((Fl_Callback*)cb_Comments, (void*)(&Node_Browser::comment_font)); + w_settings_user_commenttext->callback((Fl_Callback*)cb_Comments, (void*)(&fld::widget::Node_Browser::comment_font)); Fl_Group::current()->resizable(w_settings_user_commenttext); o->menu(fontmenu); } // Fl_Choice* w_settings_user_commenttext { Fl_Button* o = new Fl_Button(271, 237, 51, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&Node_Browser::comment_color)); + o->callback((Fl_Callback*)cb_Color_Chip, (void*)(&fld::widget::Node_Browser::comment_color)); } // Fl_Button* o { Fl_Menu_Button* o = new Fl_Menu_Button(322, 237, 18, 20); o->labelsize(12); - o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&Node_Browser::comment_color)); + o->callback((Fl_Callback*)cb_Color_Choice, (void*)(&fld::widget::Node_Browser::comment_color)); o->menu(colormenu); } // Fl_Menu_Button* o o->end(); diff --git a/fluid/panels/template_panel.cxx b/fluid/panels/template_panel.cxx index 7c2a9ac2b..12800e09c 100644 --- a/fluid/panels/template_panel.cxx +++ b/fluid/panels/template_panel.cxx @@ -84,7 +84,7 @@ static void cb_template_browser(Fl_Browser*, void*) { char pngfile[1024], *ext; strlcpy(pngfile, flfile, sizeof(pngfile)); - if ((ext = strrchr(pngfile, '.')) == nullptr) return; + if ((ext = strrchr(pngfile, '.')) == 0) return; strcpy(ext, ".png"); img = Fl_Shared_Image::get(pngfile); @@ -183,7 +183,7 @@ void template_clear() { void *filename; for (i = 1; i <= template_browser->size(); i ++) { - if ((filename = template_browser->data(i)) != nullptr) free(filename); + if ((filename = template_browser->data(i)) != 0) free(filename); } template_browser->deselect(); @@ -208,7 +208,7 @@ void template_delete_cb(Fl_Button *, void *) { char pngfile[1024], *ext; strlcpy(pngfile, flfile, sizeof(pngfile)); - if ((ext = strrchr(pngfile, '.')) != nullptr) { + if ((ext = strrchr(pngfile, '.')) != 0) { strcpy(ext, ".png"); fl_unlink(pngfile); } diff --git a/fluid/panels/widget_panel.cxx b/fluid/panels/widget_panel.cxx index 195ddc533..897cec6cc 100644 --- a/fluid/panels/widget_panel.cxx +++ b/fluid/panels/widget_panel.cxx @@ -572,7 +572,7 @@ void run_image_panel() { Fl_Shared_Image *img = (Fl_Shared_Image*)image_panel_data->user_data(); if (img) { img->release(); - image_panel_data->user_data(nullptr); + image_panel_data->user_data(0); } //fl â–² ----------~~--~==~=-=-----------~-=~~==~=-=-=~--=~--=~ â–² fl// } @@ -629,7 +629,7 @@ static void cb_widget_image_input(Fl_Input* o, void* v) { if (v == LOAD) { if (current_widget->is_widget() && !current_widget->is_a(FLD_NODE_TYPE_Window)) { o->activate(); - o->value(((Widget_Node*)current_widget)->image_name().c_str()); + o->value(((Widget_Node*)current_widget)->image_name()); } else o->deactivate(); } else { int mod = 0; @@ -679,7 +679,7 @@ static void cb_widget_deimage_input(Fl_Input* o, void* v) { if (v == LOAD) { if (current_widget->is_widget() && !current_widget->is_a(FLD_NODE_TYPE_Window)) { o->activate(); - o->value(((Widget_Node*)current_widget)->inactive_name().c_str()); + o->value(((Widget_Node*)current_widget)->inactive_name()); } else o->deactivate(); } else { int mod = 0; @@ -1195,7 +1195,7 @@ static void cb_Left(Fl_Value_Input* o, void* v) { [](Fl_Flex *w, Fl_Value_Input* i) -> void { int v; - w->margin(&v, nullptr, nullptr, nullptr); + w->margin(&v, 0, 0, 0); i->value((double)v); }, [](Fl_Flex *w, int new_value) -> int @@ -1219,7 +1219,7 @@ static void cb_Top(Fl_Value_Input* o, void* v) { [](Fl_Flex *w, Fl_Value_Input* i) -> void { int v; - w->margin(nullptr, &v, nullptr, nullptr); + w->margin(0, &v, 0, 0); i->value((double)v); }, [](Fl_Flex *w, int new_value) @@ -1243,7 +1243,7 @@ static void cb_Right(Fl_Value_Input* o, void* v) { [](Fl_Flex *w, Fl_Value_Input* i) -> void { int v; - w->margin(nullptr, nullptr, &v, nullptr); + w->margin(0, 0, &v, 0); i->value((double)v); }, [](Fl_Flex *w, int new_value) -> int @@ -1267,7 +1267,7 @@ static void cb_Bottom(Fl_Value_Input* o, void* v) { [](Fl_Flex *w, Fl_Value_Input* i) -> void { int v; - w->margin(nullptr, nullptr, nullptr, &v); + w->margin(0, 0, 0, &v); i->value((double)v); }, [](Fl_Flex *w, int new_value) -> int @@ -1702,7 +1702,7 @@ static void cb_wp_gui_tooltip(Fl_Input* o, void* v) { if (v == LOAD) { if (current_widget->is_widget()) { o->activate(); - o->value(((Widget_Node*)current_widget)->tooltip().c_str()); + o->value(((Widget_Node*)current_widget)->tooltip()); } else { o->deactivate(); } @@ -2172,7 +2172,7 @@ static void cb_e(Fl_Input* o, void* v) { o->deactivate(); } else { o->activate(); - o->value(current_widget->subclass().c_str()); + o->value(current_widget->subclass()); } } else { int mod = 0; @@ -2189,8 +2189,8 @@ static void cb_e(Fl_Input* o, void* v) { static void cb_f(Fl_Choice* o, void* v) { //fl â–¼ ---------------------- callback ~~---=--=-=~=-=-~-~~~~ â–¼ fl// static Fl_Menu_Item empty_type_menu[] = { - {"Normal",0,nullptr,(void*)nullptr}, - {nullptr}}; + {"Normal",0,0,(void*)0}, + {0}}; if (v == LOAD) { Fl_Menu_Item* m = current_widget->subtypes(); @@ -2303,7 +2303,7 @@ static void cb_v_input(Fl_Input* o, void* v) { //fl â–¼ ---------------------- callback ~~-==~=~-~~==-=--~~--= â–¼ fl// int n = fl_int(o->user_data()); if (v == LOAD) { - o->value(current_widget->extra_code(n).c_str()); + o->value(current_widget->extra_code(n)); } else { int mod = 0; const char *c = o->value(); @@ -2453,7 +2453,7 @@ static void cb_14(Fl_Input_Choice* o, void* v) { const char *c = o->value(); const char *d = c_check(c); if (!*c) o->value(dflt); - else if (!strcmp(c,dflt)) c = nullptr; + else if (!strcmp(c,dflt)) c = 0; if (!d) { if (c && *c && c[strlen(c)-1] != '*' && strcmp(c,"long")) d = "must be pointer or long"; @@ -2631,7 +2631,7 @@ static void cb_fileopen(Fl_Button*, void* v) { if (v != LOAD) { Fluid.proj.enter_project_dir(); const char *fn = fl_file_chooser("Load Inline Data", - nullptr, wp_data_filename->value(), 1); + 0, wp_data_filename->value(), 1); Fluid.proj.leave_project_dir(); if (fn) { if (strcmp(fn, wp_data_filename->value())) { @@ -2754,7 +2754,7 @@ static void cb_comment_predefined_2(Fl_Menu_Button* o, void* v) { fl_message("Please select an entry from this menu first."); } else if (fl_choice("Are you sure that you want to delete the entry\n" "\"%s\"\nfrom the database?", "Cancel", "Delete", - nullptr, itempath)) { + 0, itempath)) { Fl_Preferences db(Fl_Preferences::USER_L, "fltk.org", "fluid_comments"); db.deleteEntry(itempath); o->remove(last_selected_item); @@ -2793,8 +2793,8 @@ static void cb_comment_load_2(Fl_Button*, void* v) { // load a comment from disk if (v != LOAD) { fl_file_chooser_ok_label("Load"); - const char *fname = fl_file_chooser("Pick a comment", nullptr, nullptr); - fl_file_chooser_ok_label(nullptr); + const char *fname = fl_file_chooser("Pick a comment", 0, 0); + fl_file_chooser_ok_label(0); if (fname) { if (comment_tabs_name->buffer()->loadfile(fname)) { fl_alert("Error loading file\n%s", fname); diff --git a/fluid/panels/widget_panel/Grid_Child_Tab.cxx b/fluid/panels/widget_panel/Grid_Child_Tab.cxx index d39f46477..674b17bd7 100644 --- a/fluid/panels/widget_panel/Grid_Child_Tab.cxx +++ b/fluid/panels/widget_panel/Grid_Child_Tab.cxx @@ -485,8 +485,8 @@ void Grid_Child_Tab::grid_child_cb(fld::widget::Formula_Input* i, void* v, int w case 9: v = cell->col(); break; case 10: v = cell->rowspan(); break; case 11: v = cell->colspan(); break; - case 12: cell->minimum_size(&v, nullptr); break; - case 13: cell->minimum_size(nullptr, &v); break; + case 12: cell->minimum_size(&v, 0); break; + case 13: cell->minimum_size(0, &v); break; } } i->value(v); @@ -495,7 +495,7 @@ void Grid_Child_Tab::grid_child_cb(fld::widget::Formula_Input* i, void* v, int w int v2 = -2, old_v = -2, v = i->value(); if (i==widget_grid_row_input) v2 = widget_grid_col_input->value(); if (i==widget_grid_col_input) v2 = widget_grid_row_input->value(); - Fl_Grid::Cell *new_cell = nullptr; + Fl_Grid::Cell *new_cell = 0; if (cell) { switch (what & 0x00ff) { case 8: old_v = cell->row(); v2 = cell->col(); break; diff --git a/fluid/panels/widget_panel/Grid_Tab.cxx b/fluid/panels/widget_panel/Grid_Tab.cxx index 756d957ac..4730f0789 100644 --- a/fluid/panels/widget_panel/Grid_Tab.cxx +++ b/fluid/panels/widget_panel/Grid_Tab.cxx @@ -109,11 +109,11 @@ void Grid_Tab::cb_Left_i(Fl_Value_Input* o, void* v) { if (!grid) return; int m = 0; if (v == LOAD) { - grid->margin(&m, nullptr, nullptr, nullptr); + grid->margin(&m, 0, 0, 0); o->value(m); } else { int m = (int)o->value(), old_m; - grid->margin(&old_m, nullptr, nullptr, nullptr); + grid->margin(&old_m, 0, 0, 0); if (m != old_m) { Fluid.proj.undo.checkpoint(); grid->margin(m, -1, -1, -1); @@ -131,11 +131,11 @@ void Grid_Tab::cb_Top_i(Fl_Value_Input* o, void* v) { if (!grid) return; int m = 0; if (v == LOAD) { - grid->margin(nullptr, &m, nullptr, nullptr); + grid->margin(0, &m, 0, 0); o->value(m); } else { int m = (int)o->value(), old_m; - grid->margin(nullptr, &old_m, nullptr, nullptr); + grid->margin(0, &old_m, 0, 0); if (m != old_m) { Fluid.proj.undo.checkpoint(); grid->margin(-1, m, -1, -1); @@ -153,11 +153,11 @@ void Grid_Tab::cb_Right_i(Fl_Value_Input* o, void* v) { if (!grid) return; int m = 0; if (v == LOAD) { - grid->margin(nullptr, nullptr, &m, nullptr); + grid->margin(0, 0, &m, 0); o->value(m); } else { int m = (int)o->value(), old_m; - grid->margin(nullptr, nullptr, &old_m, nullptr); + grid->margin(0, 0, &old_m, 0); if (m != old_m) { Fluid.proj.undo.checkpoint(); grid->margin(-1, -1, m, -1); @@ -175,11 +175,11 @@ void Grid_Tab::cb_Bottom_i(Fl_Value_Input* o, void* v) { if (!grid) return; int m = 0; if (v == LOAD) { - grid->margin(nullptr, nullptr, nullptr, &m); + grid->margin(0, 0, 0, &m); o->value(m); } else { int m = (int)o->value(), old_m; - grid->margin(nullptr, nullptr, nullptr, &old_m); + grid->margin(0, 0, 0, &old_m); if (m != old_m) { Fluid.proj.undo.checkpoint(); grid->margin(-1, -1, -1, m); @@ -197,7 +197,7 @@ void Grid_Tab::cb_Row_i(Fl_Value_Input* o, void* v) { if (!grid) return; if (v == LOAD) { int m = 0; - grid->gap(&m, nullptr); + grid->gap(&m, 0); o->value(m); } else { int m = (int)o->value(), old_m, m2; @@ -219,7 +219,7 @@ void Grid_Tab::cb_Col_i(Fl_Value_Input* o, void* v) { if (!grid) return; if (v == LOAD) { int m = 0; - grid->gap(nullptr, &m); + grid->gap(0, &m); o->value(m); } else { int m = (int)o->value(), old_m, m2; diff --git a/fluid/proj/mergeback.cxx b/fluid/proj/mergeback.cxx index 016732795..d19893042 100644 --- a/fluid/proj/mergeback.cxx +++ b/fluid/proj/mergeback.cxx @@ -114,7 +114,7 @@ int merge_back(Project &proj, const std::string &s, const std::string &p, Mergeb /** Allocate and initialize MergeBack class. */ Mergeback::Mergeback(Project &proj) : proj_(proj), - code(nullptr), + code(0), line_no(0), tag_error(0), num_changed_code(0), @@ -227,7 +227,7 @@ int Mergeback::ask_user_to_merge(const std::string &code_filename, const std::st msg += "\n\nClick Cancel to abort the MergeBack operation.\n" "Click Merge to merge all code changes back into\n" "the open project."; - int c = fl_choice(msg.c_str(), "Cancel", "Merge", nullptr, + int c = fl_choice(msg.c_str(), "Cancel", "Merge", 0, code_filename.c_str(), proj_filename.c_str(), num_changed_code, num_uid_not_found, num_changed_structure, num_possible_override); @@ -324,12 +324,12 @@ void Mergeback::print_trichar32(FILE *out, uint32_t value) { /** Check if a line contains the special MergeBack tag \param[in] line A line of NUL terminated text. - \return a pointer to the character after the tag, or nullptr if not found + \return a pointer to the character after the tag, or 0 if not found */ const char *Mergeback::find_mergeback_tag(const char *line) { const char *tag = strstr(line, "//fl "); if (tag) return tag + strlen("//fl "); - return nullptr; + return 0; } /** @@ -601,7 +601,7 @@ int Mergeback::merge_back(const std::string &s, const std::string &p, Task task) } } while (0); fclose(code); - code = nullptr; + code = 0; return ret; } @@ -639,8 +639,17 @@ int mergeback_code_files(Project &proj, Mergeback::Feedback feedback) return 0; } - std::string proj_filename = proj.projectfile_path() + proj.projectfile_name(); - std::string code_filename; + char proj_filename[FL_PATH_MAX]; + char code_filename[FL_PATH_MAX]; + char path_buf[FL_PATH_MAX]; + char name_buf[FL_PATH_MAX]; + int i, n; + + proj.projectfile_path(path_buf, FL_PATH_MAX); + const char *pname = proj.projectfile_name(); + snprintf(proj_filename, FL_PATH_MAX, "%s%s", path_buf, pname ? pname : ""); + + code_filename[0] = '\0'; #if 1 if (!Fluid.batch_mode) { // Depending on the workflow in interactive mode, an external copy of @@ -649,16 +658,19 @@ int mergeback_code_files(Project &proj, Mergeback::Feedback feedback) // matching a project, and uses that location instead. // TODO: this is not working as expected yet. Fl_Preferences build_records(Fl_Preferences::USER_L, "fltk.org", "fluid-build"); - Fl_Preferences path(build_records, proj_filename.c_str()); - int i, n = (int)proj_filename.size(); + n = (int)strlen(proj_filename); for (i=0; i<n; i++) if (proj_filename[i]=='\\') proj_filename[i] = '/'; + Fl_Preferences pathpref(build_records, proj_filename); char *code_fn_ptr = 0; - path.get("code", code_fn_ptr, ""); - if (code_fn_ptr) { code_filename = code_fn_ptr; free(code_fn_ptr); } + pathpref.get("code", code_fn_ptr, ""); + if (code_fn_ptr) { strlcpy(code_filename, code_fn_ptr, FL_PATH_MAX); free(code_fn_ptr); } } #endif - if (code_filename.empty()) - code_filename = proj.codefile_path() + proj.codefile_name(); + if (code_filename[0] == '\0') { + proj.codefile_path(path_buf, FL_PATH_MAX); + proj.codefile_name(name_buf, FL_PATH_MAX); + snprintf(code_filename, FL_PATH_MAX, "%s%s", path_buf, name_buf); + } if (!Fluid.batch_mode) proj.enter_project_dir(); int c = merge_back(proj, code_filename, proj_filename, FLD_MERGEBACK_TASK_INTERACTIVE); if (c>0) { @@ -673,7 +685,7 @@ int mergeback_code_files(Project &proj, Mergeback::Feedback feedback) if (c==0) fl_message("Comparing\n \"%s\"\nto\n \"%s\"\n\n" "MergeBack found no external modifications\n" "in the source code.", - code_filename.c_str(), proj_filename.c_str()); + code_filename, proj_filename); if (c==-2) fl_message("No corresponding source code file found."); } recursion_lock = false; @@ -695,7 +707,7 @@ static void deferred_mergeback_handler(void*) { static int app_event_handler(int event) { if (event == FL_APP_ACTIVATE) { - Fl::add_idle(deferred_mergeback_handler, nullptr); + Fl::add_idle(deferred_mergeback_handler, 0); } return 0; } diff --git a/fluid/rsrcs/pixmaps.cxx b/fluid/rsrcs/pixmaps.cxx index 486c98267..12fe28b0c 100644 --- a/fluid/rsrcs/pixmaps.cxx +++ b/fluid/rsrcs/pixmaps.cxx @@ -90,7 +90,7 @@ Fl_Pixmap *protected_pixmap; Fl_Pixmap *invisible_pixmap; Fl_Pixmap *compressed_pixmap; -Fl_Pixmap *pixmap[(int)FLD_NODE_TYPE_Max_] = { nullptr }; +Fl_Pixmap *pixmap[(int)FLD_NODE_TYPE_Max_] = { 0 }; /** Draw a zoom cross pointing in all four diagonal directions diff --git a/fluid/tools/ExternalCodeEditor_UNIX.cxx b/fluid/tools/ExternalCodeEditor_UNIX.cxx index 9e9ffd00e..60ed16814 100644 --- a/fluid/tools/ExternalCodeEditor_UNIX.cxx +++ b/fluid/tools/ExternalCodeEditor_UNIX.cxx @@ -27,7 +27,7 @@ using namespace fld; // Static local data static int L_editors_open = 0; // keep track of #editors open -static Fl_Timeout_Handler L_update_timer_cb = nullptr; // app's update timer callback +static Fl_Timeout_Handler L_update_timer_cb = 0; // app's update timer callback // [Static/Local] See if file exists static int is_file(const char *filename) { @@ -59,7 +59,7 @@ static int is_dir(const char *dirname) { */ ExternalCodeEditor::ExternalCodeEditor() { pid_ = -1; - filename_ = nullptr; + filename_ = 0; file_mtime_ = 0; file_size_ = 0; alert_pipe_[0] = alert_pipe_[1] = -1; @@ -75,7 +75,7 @@ ExternalCodeEditor::~ExternalCodeEditor() { printf("ExternalCodeEditor() DTOR CALLED (this=%p, pid=%ld)\n", (void*)this, (long)pid_); close_editor(); // close editor, delete tmp file - set_filename(nullptr); // free()s filename + set_filename(0); // free()s filename if (alert_pipe_open_) { Fl::remove_fd(alert_pipe_[0]); @@ -87,12 +87,12 @@ ExternalCodeEditor::~ExternalCodeEditor() { /** Set the filename for the file we wish to edit. Handles memory allocation/free. - If set to nullptr, frees memory. + If set to 0, frees memory. \param[in] val new filename */ void ExternalCodeEditor::set_filename(const char *val) { if ( filename_ ) free((void*)filename_); - filename_ = val ? fl_strdup(val) : nullptr; + filename_ = val ? fl_strdup(val) : 0; } /** @@ -121,7 +121,7 @@ void ExternalCodeEditor::close_editor() { switch ( fl_choice("Please close external editor\npid=%ld file=%s", "Force Close", // button 0 "Closed", // button 1 - nullptr, // button 2 + 0, // button 2 long(pid_), filename() ) ) { case 0: // Force Close kill_editor(); @@ -187,7 +187,7 @@ void ExternalCodeEditor::kill_editor() { \return -1 error getting file info (strerror() has reason) */ int ExternalCodeEditor::handle_changes(const char **code, int force) { - code[0] = nullptr; + code[0] = 0; if ( !is_editing() ) return 0; // Get current time/size info, see if file changed int changed = 0; @@ -247,7 +247,7 @@ int ExternalCodeEditor::remove_tmpfile() { return -1; } } - set_filename(nullptr); + set_filename(0); file_mtime_ = 0; file_size_ = 0; return 1; @@ -280,7 +280,7 @@ void ExternalCodeEditor::tmpdir_clear() { /** Creates temp dir (if doesn't exist) and returns the dirname as a static string. - \return nullptr on error, dialog shows reason. + \return 0 on error, dialog shows reason. */ const char* ExternalCodeEditor::create_tmpdir() { const char *dirname = tmpdir_name(); @@ -288,7 +288,7 @@ const char* ExternalCodeEditor::create_tmpdir() { if ( mkdir(dirname, 0777) < 0 ) { fl_alert("can't create directory '%s': %s", dirname, strerror(errno)); - return nullptr; + return 0; } } return dirname; @@ -296,13 +296,13 @@ const char* ExternalCodeEditor::create_tmpdir() { /** Returns temp filename in static buffer. - \return nullptr if can't, posts dialog explaining why. + \return 0 if can't, posts dialog explaining why. */ const char* ExternalCodeEditor::tmp_filename() { static char path[FL_PATH_MAX+1]; const char *tmpdir = create_tmpdir(); - if ( !tmpdir ) return nullptr; - const char *ext = Fluid.proj.code_file_name.c_str(); // e.g. ".cxx" + if ( !tmpdir ) return 0; + const char *ext = Fluid.proj.code_file_name(); // e.g. ".cxx" snprintf(path, FL_PATH_MAX, "%s/%p%s", tmpdir, (void*)this, ext); path[FL_PATH_MAX] = 0; return path; @@ -310,12 +310,12 @@ const char* ExternalCodeEditor::tmp_filename() { /** Save string 'code' to 'filename', returning file's mtime/size. - 'code' can be nullptr -- writes an empty file if so. + 'code' can be 0 -- writes an empty file if so. \return 0 on success \return -1 on error (posts dialog with reason) */ static int save_file(const char *filename, const char *code) { - if ( code == nullptr ) code = ""; // nullptr? write an empty file + if ( code == 0 ) code = ""; // 0? write an empty file int fd = open(filename, O_WRONLY|O_CREAT, 0666); if ( fd == -1 ) { fl_alert("ERROR: open() '%s': %s", filename, strerror(errno)); @@ -338,7 +338,7 @@ static int save_file(const char *filename, const char *code) { /** Convert string 's' to array of argv[], useful for execve(). - - 's' will be modified (words will be nullptr separated) + - 's' will be modified (words will be 0 separated) - argv[] will end up pointing to the words of 's' - Caller must free argv with: free(argv); \return -1 in case of memory allocation error @@ -348,14 +348,14 @@ static int make_args(char *s, // string containing words (gets trashed!) int *aargc, // pointer to argc char ***aargv) { // pointer to argv char *ss, **argv; - if ((argv=(char**)malloc(sizeof(char*) * (strlen(s)/2)))==nullptr) { + if ((argv=(char**)malloc(sizeof(char*) * (strlen(s)/2)))==0) { return -1; } int t; - for(t=0; (t==0)?(ss=strtok(s," \t")):(ss=strtok(nullptr," \t")); t++) { + for(t=0; (t==0)?(ss=strtok(s," \t")):(ss=strtok(0," \t")); t++) { argv[t] = ss; } - argv[t] = nullptr; + argv[t] = 0; aargv[0] = argv; aargc[0] = t; return(t); @@ -401,7 +401,7 @@ int ExternalCodeEditor::start_editor(const char *editor_cmd, // NOTE: no FLTK calls after a fork. Use a pipe to tell the app if the // command can't launch int nargs; - char **args = nullptr; + char **args = 0; if (make_args(cmd, &nargs, &args) > 0) { execvp(args[0], args); // run command - doesn't return if succeeds if (alert_pipe_open_) { @@ -428,7 +428,7 @@ int ExternalCodeEditor::start_editor(const char *editor_cmd, /** Try to reap external editor process. - If 'pid_reaped' not nullptr, returns PID of reaped editor. + If 'pid_reaped' not 0, returns PID of reaped editor. \return -2: editor not open \return -1: waitpid() failed (errno has reason) @@ -464,7 +464,7 @@ int ExternalCodeEditor::reap_editor(pid_t *pid_reaped) { Open external editor using 'editor_cmd' to edit 'code'. 'code' contains multiline code to be edited as a temp file. - 'code' can be nullptr -- edits an empty file if so. + 'code' can be 0 -- edits an empty file if so. \return 0 if succeeds \return -1 if can't open editor (already open, etc), diff --git a/fluid/tools/ExternalCodeEditor_UNIX.h b/fluid/tools/ExternalCodeEditor_UNIX.h index 2142d5a10..dfcc1e785 100644 --- a/fluid/tools/ExternalCodeEditor_UNIX.h +++ b/fluid/tools/ExternalCodeEditor_UNIX.h @@ -42,7 +42,7 @@ public: ExternalCodeEditor(); ~ExternalCodeEditor(); int is_editing(); - int reap_editor(pid_t *pid_reaped=nullptr); + int reap_editor(pid_t *pid_reaped=0); void close_editor(); const char *filename() { return filename_; } int open_editor(const char *editor_cmd, const char *code); diff --git a/fluid/tools/ExternalCodeEditor_WIN32.cxx b/fluid/tools/ExternalCodeEditor_WIN32.cxx index 64d791400..ea9178c63 100644 --- a/fluid/tools/ExternalCodeEditor_WIN32.cxx +++ b/fluid/tools/ExternalCodeEditor_WIN32.cxx @@ -33,12 +33,12 @@ using namespace fld; // Static local data static int L_editors_open = 0; // keep track of #editors open static Fl_Timeout_Handler L_update_timer_cb = 0; // app's update timer callback -static wchar_t *wbuf = nullptr; -static char *abuf = nullptr; +static wchar_t *wbuf = 0; +static char *abuf = 0; static wchar_t *utf8_to_wchar(const char *utf8, wchar_t *&wbuf, int lg = -1) { unsigned len = (lg >= 0) ? (unsigned)lg : (unsigned)strlen(utf8); - unsigned wn = fl_utf8toUtf16(utf8, len, nullptr, 0) + 1; // Query length + unsigned wn = fl_utf8toUtf16(utf8, len, 0, 0) + 1; // Query length wbuf = (wchar_t *)realloc(wbuf, sizeof(wchar_t) * wn); wn = fl_utf8toUtf16(utf8, len, (unsigned short *)wbuf, wn); // Convert string wbuf[wn] = 0; @@ -47,7 +47,7 @@ static wchar_t *utf8_to_wchar(const char *utf8, wchar_t *&wbuf, int lg = -1) { static char *wchar_to_utf8(const wchar_t *wstr, char *&utf8) { unsigned len = (unsigned)wcslen(wstr); - unsigned wn = fl_utf8fromwc(nullptr, 0, wstr, len) + 1; // query length + unsigned wn = fl_utf8fromwc(0, 0, wstr, len) + 1; // query length utf8 = (char *)realloc(utf8, wn); wn = fl_utf8fromwc(utf8, wn, wstr, len); // convert string utf8[wn] = 0; @@ -68,7 +68,7 @@ static const char *get_ms_errmsg() { DWORD msize = 0; // Get error message from Windows - msize = FormatMessageW(flags, 0, lastErr, langid, (LPWSTR)&mbuf, 0, nullptr); + msize = FormatMessageW(flags, 0, lastErr, langid, (LPWSTR)&mbuf, 0, 0); if ( msize == 0 ) { _snprintf(emsg, sizeof(emsg), "Error #%ld", (unsigned long)lastErr); } else { @@ -119,7 +119,7 @@ ExternalCodeEditor::~ExternalCodeEditor() { } // [Protected] Set the filename. Handles memory allocation/free -// If set to nullptr, frees memory. +// If set to 0, frees memory. // void ExternalCodeEditor::set_filename(const char *val) { if ( filename_ ) free((void*)filename_); @@ -252,10 +252,10 @@ int ExternalCodeEditor::handle_changes(const char **code, int force) { HANDLE fh = CreateFileW(wbuf, // file to read GENERIC_READ, // reading only FILE_SHARE_READ, // sharing -- allow read share; just getting file size - nullptr, // security + 0, // security OPEN_EXISTING, // create flags -- must exist 0, // misc flags - nullptr); // templates + 0); // templates if ( fh == INVALID_HANDLE_VALUE ) return -1; LARGE_INTEGER fsize; // Get file size @@ -368,7 +368,7 @@ void ExternalCodeEditor::tmpdir_clear() { } // [Protected] Creates temp dir (if doesn't exist) and returns the dirname -// as a static string. Returns nullptr on error, dialog shows reason. +// as a static string. Returns 0 on error, dialog shows reason. // const char* ExternalCodeEditor::create_tmpdir() { const char *dirname = tmpdir_name(); @@ -377,14 +377,14 @@ const char* ExternalCodeEditor::create_tmpdir() { if (CreateDirectoryW(wbuf, 0) == 0) { fl_alert("can't create directory '%s': %s", dirname, get_ms_errmsg()); - return nullptr; + return 0; } } return dirname; } // [Protected] Returns temp filename in static buffer. -// Returns nullptr if can't, posts dialog explaining why. +// Returns 0 if can't, posts dialog explaining why. // const char* ExternalCodeEditor::tmp_filename() { static char path[512]; @@ -397,7 +397,7 @@ const char* ExternalCodeEditor::tmp_filename() { } // [Static/Local] Save string 'code' to 'filename', returning file's mtime/size -// 'code' can be nullptr -- writes an empty file if so. +// 'code' can be 0 -- writes an empty file if so. // Returns: // 0 on success // -1 on error (posts dialog with reason) @@ -406,17 +406,17 @@ static int save_file(const char *filename, const char *code, FILETIME &file_mtime, // return these since in win32 it's.. LARGE_INTEGER &file_size) { // ..efficient to get while file open - if ( code == 0 ) code = ""; // nullptr? write an empty file + if ( code == 0 ) code = ""; // 0? write an empty file memset(&file_mtime, 0, sizeof(file_mtime)); memset(&file_size, 0, sizeof(file_size)); utf8_to_wchar(filename, wbuf); HANDLE fh = CreateFileW(wbuf, // filename GENERIC_WRITE, // write only 0, // sharing -- no share during write - nullptr, // security + 0, // security CREATE_ALWAYS, // create flags -- recreate FILE_ATTRIBUTE_NORMAL, // misc flags - nullptr); // templates + 0); // templates if ( fh == INVALID_HANDLE_VALUE ) { fl_alert("ERROR: couldn't create file '%s': %s", filename, get_ms_errmsg()); @@ -426,7 +426,7 @@ static int save_file(const char *filename, DWORD clen = (DWORD)strlen(code); DWORD count = 0; int ret = 0; - if ( WriteFile(fh, code, clen, &count, nullptr) == 0 ) { + if ( WriteFile(fh, code, clen, &count, 0) == 0 ) { fl_alert("ERROR: WriteFile() '%s': %s", filename, get_ms_errmsg()); ret = -1; // fallthru to CloseHandle() } else if ( count != clen ) { @@ -474,14 +474,14 @@ int ExternalCodeEditor::start_editor(const char *editor_cmd, _snprintf(cmd, sizeof(cmd), "%s %s", editor_cmd, filename); utf8_to_wchar(cmd, wbuf); // Start editor process - if (CreateProcessW(nullptr, // app name + if (CreateProcessW(0, // app name wbuf, // command to exec - nullptr, // secure attribs - nullptr, // thread secure attribs + 0, // secure attribs + 0, // thread secure attribs FALSE, // handle inheritance 0, // creation flags - nullptr, // environ block - nullptr, // current dir + 0, // environ block + 0, // current dir &sinfo, // startup info &pinfo_) == 0 ) { // process info fl_alert("CreateProcess() failed to start '%s': %s", @@ -512,7 +512,7 @@ void ExternalCodeEditor::reap_cleanup() { } // [Public] Try to reap external editor process -// If 'pid_reaped' not nullptr, returns PID of reaped editor. +// If 'pid_reaped' not 0, returns PID of reaped editor. // Returns: // -2 -- editor not open // -1 -- WaitForSingleObject() failed (get_ms_errmsg() has reason) @@ -548,7 +548,7 @@ int ExternalCodeEditor::reap_editor(DWORD *pid_reaped) { // [Public] Open external editor using 'editor_cmd' to edit 'code'. // // 'code' contains multiline code to be edited as a temp file. -// 'code' can be nullptr -- edits an empty file if so. +// 'code' can be 0 -- edits an empty file if so. // // Returns: // 0 if succeeds diff --git a/fluid/tools/ExternalCodeEditor_WIN32.h b/fluid/tools/ExternalCodeEditor_WIN32.h index 83c50a742..679e474c1 100644 --- a/fluid/tools/ExternalCodeEditor_WIN32.h +++ b/fluid/tools/ExternalCodeEditor_WIN32.h @@ -43,7 +43,7 @@ public: ExternalCodeEditor(); ~ExternalCodeEditor(); int is_editing(); - int reap_editor(DWORD *pid_reaped=nullptr); + int reap_editor(DWORD *pid_reaped=0); void close_editor(); const char *filename() { return filename_; } int open_editor(const char *editor_cmd, const char *code); diff --git a/fluid/tools/autodoc.cxx b/fluid/tools/autodoc.cxx index 51afe76c6..a59e08ab9 100644 --- a/fluid/tools/autodoc.cxx +++ b/fluid/tools/autodoc.cxx @@ -233,7 +233,7 @@ void blend_alpha_bottom(const Fl_RGB_Image *img, int dy) { created in FLTK resolution, even if the screen uses a higher resolution. \param[in] filename the snapshot will be written to this file in png format - \param[in] w draw a bounding box around all widgets in the nullptr terminated list + \param[in] w draw a bounding box around all widgets in the 0 terminated list \param[in] frame add a margin around the bounding box \param[in] blend add another margin around the bounding box that fades to full transparency \param[in] scale scale everything by this factor before saving it @@ -343,7 +343,7 @@ int fl_snapshot(const char *filename, Fl_Widget *w1, Fl_Widget *w2, const Fl_Rect &blend, double scale) { - Fl_Widget *ww[3] = { w1, w2, nullptr }; + Fl_Widget *ww[3] = { w1, w2, 0 }; return fl_snapshot(filename, ww, frame, blend, scale); } @@ -364,14 +364,18 @@ int fl_snapshot(const char *filename, Fl_Widget *w, const Fl_Rect &blend, double scale) { - Fl_Widget *ww[2] = { w, nullptr }; + Fl_Widget *ww[2] = { w, 0 }; return fl_snapshot(filename, ww, frame, blend, scale); } /** @} */ -void run_autodoc(const std::string &target_dir) { +// Helper macro to build snapshot path +#define SNAP_PATH(filename) (snprintf(snap_path, FL_PATH_MAX, "%s%s", target_dir, filename), snap_path) + +void run_autodoc(const char *target_dir) { + char snap_path[FL_PATH_MAX]; // A list of all the margins we will use later Fl_Margin win_margin(0, 0, 0, 0); Fl_Margin win_blend(10, 10, 10, 10); @@ -384,7 +388,7 @@ void run_autodoc(const std::string &target_dir) { // Fl::scheme("gtk+"); // Create a silly project that contains all widgets that we want to document - Fluid.new_project(false); + Fluid.new_project(0); /*Node *t_func = */ add_new_widget_from_user("Function", Strategy::AS_LAST_CHILD, false); Window_Node *t_win = (Window_Node*)add_new_widget_from_user("Fl_Window", Strategy::AS_LAST_CHILD, false); @@ -430,9 +434,9 @@ void run_autodoc(const std::string &target_dir) { // explain widget browser // explain widget browser entry Fluid.main_window->size(350, 320); - fl_snapshot((target_dir + "main_window.png").c_str(), Fluid.main_window, win_margin, win_blend); - fl_snapshot((target_dir + "main_menubar.png").c_str(), Fluid.main_menubar, row_margin, row_blend); - fl_snapshot((target_dir + "main_browser.png").c_str(), widget_browser, FL_SNAP_AREA_CLEAR, + fl_snapshot(SNAP_PATH("main_window.png"), Fluid.main_window, win_margin, win_blend); + fl_snapshot(SNAP_PATH("main_menubar.png"), Fluid.main_menubar, row_margin, row_blend); + fl_snapshot(SNAP_PATH("main_browser.png"), widget_browser, FL_SNAP_AREA_CLEAR, Fl_Rect(0, 30, FL_SNAP_TO_WINDOW, 100), row_blend, 2.0); @@ -454,7 +458,7 @@ void run_autodoc(const std::string &target_dir) { // list exceptions (subwindow, scroll) Fl::wait(0.2); Fl::flush(); - fl_snapshot((target_dir + "widgetbin_panel.png").c_str(), widgetbin_panel, win_margin, win_blend); + fl_snapshot(SNAP_PATH("widgetbin_panel.png"), widgetbin_panel, win_margin, win_blend); // ---- code view // explain functionality @@ -465,35 +469,35 @@ void run_autodoc(const std::string &target_dir) { codeview_panel->show(); Fl::wait(0.2); Fl::flush(); - update_codeview_cb(nullptr, nullptr); // must be visible on screen for this to work + update_codeview_cb(0, 0); // must be visible on screen for this to work cv_tab->value(cv_source_tab); codeview_panel->redraw(); Fl::flush(); - fl_snapshot((target_dir + "codeview_panel.png").c_str(), codeview_panel, win_margin, win_blend); - fl_snapshot((target_dir + "cv_find_row.png").c_str(), cv_find_row, row_margin, row_blend); - fl_snapshot((target_dir + "cv_settings_row.png").c_str(), cv_settings_row, row_margin, row_blend); + fl_snapshot(SNAP_PATH("codeview_panel.png"), codeview_panel, win_margin, win_blend); + fl_snapshot(SNAP_PATH("cv_find_row.png"), cv_find_row, row_margin, row_blend); + fl_snapshot(SNAP_PATH("cv_settings_row.png"), cv_settings_row, row_margin, row_blend); // ---- settings dialog // show and explain all tabs - fl_snapshot((target_dir + "w_settings.png").c_str(), settings_window, win_margin, win_blend); - fl_snapshot((target_dir + "w_settings_general_tab.png").c_str(), w_settings_general_tab, xtab_margin, row_blend); + fl_snapshot(SNAP_PATH("w_settings.png"), settings_window, win_margin, win_blend); + fl_snapshot(SNAP_PATH("w_settings_general_tab.png"), w_settings_general_tab, xtab_margin, row_blend); w_settings_tabs->value(w_settings_project_tab); - fl_snapshot((target_dir + "w_settings_project_tab.png").c_str(), w_settings_project_tab, xtab_margin, row_blend); + fl_snapshot(SNAP_PATH("w_settings_project_tab.png"), w_settings_project_tab, xtab_margin, row_blend); w_settings_tabs->value(w_settings_layout_tab); - fl_snapshot((target_dir + "w_settings_layout_tab.png").c_str(), w_settings_layout_tab, xtab_margin, row_blend); + fl_snapshot(SNAP_PATH("w_settings_layout_tab.png"), w_settings_layout_tab, xtab_margin, row_blend); w_settings_tabs->value(w_settings_shell_tab); w_settings_shell_list->value(1); w_settings_shell_list->do_callback(); - fl_snapshot((target_dir + "w_settings_shell_tab.png").c_str(), w_settings_shell_tab, xtab_margin, row_blend); + fl_snapshot(SNAP_PATH("w_settings_shell_tab.png"), w_settings_shell_tab, xtab_margin, row_blend); w_settings_tabs->value(w_settings_i18n_tab); i18n_type_chooser->value(1); i18n_type_chooser->do_callback(); - fl_snapshot((target_dir + "w_settings_i18n_gnu.png").c_str(), i18n_type_chooser, i18n_gnu_static_function_input, row_margin, row_blend); + fl_snapshot(SNAP_PATH("w_settings_i18n_gnu.png"), i18n_type_chooser, i18n_gnu_static_function_input, row_margin, row_blend); i18n_type_chooser->value(2); i18n_type_chooser->do_callback(); - fl_snapshot((target_dir + "w_settings_i18n_psx.png").c_str(), i18n_type_chooser, i18n_pos_set_input, row_margin, row_blend); + fl_snapshot(SNAP_PATH("w_settings_i18n_psx.png"), i18n_type_chooser, i18n_pos_set_input, row_margin, row_blend); w_settings_tabs->value(w_settings_user_tab); - fl_snapshot((target_dir + "w_settings_user_tab.png").c_str(), w_settings_user_tab, xtab_margin, row_blend); + fl_snapshot(SNAP_PATH("w_settings_user_tab.png"), w_settings_user_tab, xtab_margin, row_blend); // ---- dialog types @@ -505,33 +509,33 @@ void run_autodoc(const std::string &target_dir) { // -- FLD_NODE_TYPE_Function select_only(t_func); - fl_snapshot((target_dir + "function_panel.png").c_str(), func_tabs_main, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("function_panel.png"), func_tabs_main, tab_margin, row_blend); // -- FLD_NODE_TYPE_Code select_only(t_code); - fl_snapshot((target_dir + "code_panel.png").c_str(), code_tabs_main, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("code_panel.png"), code_tabs_main, tab_margin, row_blend); // -- FLD_NODE_TYPE_CodeBlock select_only(t_codeblock); - fl_snapshot((target_dir + "codeblock_panel.png").c_str(), declblock_tabs_main, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("codeblock_panel.png"), declblock_tabs_main, tab_margin, row_blend); // -- FLD_NODE_TYPE_Decl select_only(t_decl); - fl_snapshot((target_dir + "decl_panel.png").c_str(), decl_tabs_main, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("decl_panel.png"), decl_tabs_main, tab_margin, row_blend); // -- FLD_NODE_TYPE_DeclBlock select_only(t_declblock); - fl_snapshot((target_dir + "declblock_panel.png").c_str(), declblock_tabs_main, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("declblock_panel.png"), declblock_tabs_main, tab_margin, row_blend); // -- FLD_NODE_TYPE_Class select_only(t_class); - fl_snapshot((target_dir + "class_panel.png").c_str(), class_tabs_main, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("class_panel.png"), class_tabs_main, tab_margin, row_blend); // -- FLD_NODE_TYPE_Widget_Class is handled like Window_Node // -- FLD_NODE_TYPE_Comment select_only(t_comment); - fl_snapshot((target_dir + "comment_panel.png").c_str(), comment_tabs_comment, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("comment_panel.png"), comment_tabs_comment, tab_margin, row_blend); // ---- widget dialog t_win->open(); // open the window @@ -539,66 +543,66 @@ void run_autodoc(const std::string &target_dir) { select_only(t_win); // -- snapshot of the widget properties panel - fl_snapshot((target_dir + "widget_panel.png").c_str(), the_panel, win_margin, win_blend); - fl_snapshot((target_dir + "wLiveMode.png").c_str(), wLiveMode, row_margin, row_blend); + fl_snapshot(SNAP_PATH("widget_panel.png"), the_panel, win_margin, win_blend); + fl_snapshot(SNAP_PATH("wLiveMode.png"), wLiveMode, row_margin, row_blend); // -- snapshot of the GUI tab widget_tabs->value(wp_gui_tab); - fl_snapshot((target_dir + "wp_gui_tab.png").c_str(), wp_gui_tab, tab_margin, row_blend); - fl_snapshot((target_dir + "wp_gui_label.png").c_str(), wp_gui_label, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_tab.png"), wp_gui_tab, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_label.png"), wp_gui_label, row_margin, row_blend); select_only(t_btn); - fl_snapshot((target_dir + "wp_gui_image.png").c_str(), widget_image_input, widget_deimage_input, row_margin, row_blend); - fl_snapshot((target_dir + "wp_gui_alignment.png").c_str(), wp_gui_alignment, row_margin, row_blend); - fl_snapshot((target_dir + "wp_gui_size.png").c_str(), widget_x_input, xrow_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_image.png"), widget_image_input, widget_deimage_input, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_alignment.png"), wp_gui_alignment, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_size.png"), widget_x_input, xrow_margin, row_blend); select_only(t_sldr); - fl_snapshot((target_dir + "wp_gui_values.png").c_str(), wp_gui_values, xrow_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_values.png"), wp_gui_values, xrow_margin, row_blend); select_only(t_flxc); - fl_snapshot((target_dir + "wp_gui_flexp.png").c_str(), wp_gui_flexp, xrow_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_flexp.png"), wp_gui_flexp, xrow_margin, row_blend); select_only(t_flx); - fl_snapshot((target_dir + "wp_gui_margins.png").c_str(), wp_gui_margins, xrow_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_margins.png"), wp_gui_margins, xrow_margin, row_blend); select_only(t_win); - fl_snapshot((target_dir + "wp_gui_sizerange.png").c_str(), wp_gui_sizerange, xrow_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_sizerange.png"), wp_gui_sizerange, xrow_margin, row_blend); select_only(t_btn); - fl_snapshot((target_dir + "wp_gui_shortcut.png").c_str(), wp_gui_shortcut, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_shortcut.png"), wp_gui_shortcut, row_margin, row_blend); select_only(t_win); - fl_snapshot((target_dir + "wp_gui_xclass.png").c_str(), wp_gui_xclass, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_xclass.png"), wp_gui_xclass, row_margin, row_blend); select_only(t_btn); - fl_snapshot((target_dir + "wp_gui_attributes.png").c_str(), wp_gui_attributes, row_margin, row_blend); - fl_snapshot((target_dir + "wp_gui_tooltip.png").c_str(), wp_gui_tooltip, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_attributes.png"), wp_gui_attributes, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gui_tooltip.png"), wp_gui_tooltip, row_margin, row_blend); // -- snapshot of the style tab widget_tabs->value(wp_style_tab); select_only(t_inp); - fl_snapshot((target_dir + "wp_style_tab.png").c_str(), wp_style_tab, tab_margin, row_blend); - fl_snapshot((target_dir + "wp_style_label.png").c_str(), wp_style_label, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_style_tab.png"), wp_style_tab, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_style_label.png"), wp_style_label, row_margin, row_blend); select_only(t_btn); - fl_snapshot((target_dir + "wp_style_box.png").c_str(), wp_style_box, wp_style_downbox, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_style_box.png"), wp_style_box, wp_style_downbox, row_margin, row_blend); select_only(t_inp); - fl_snapshot((target_dir + "wp_style_text.png").c_str(), wp_style_text, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_style_text.png"), wp_style_text, row_margin, row_blend); // -- snapshot of the C++ tab widget_tabs->value(wp_cpp_tab); select_only(t_btn); - fl_snapshot((target_dir + "wp_cpp_tab.png").c_str(), wp_cpp_tab, tab_margin, row_blend); - fl_snapshot((target_dir + "wp_cpp_class.png").c_str(), wp_cpp_class, row_margin, row_blend); - fl_snapshot((target_dir + "wp_cpp_name.png").c_str(), wp_cpp_name, row_margin, row_blend); - fl_snapshot((target_dir + "v_input.png").c_str(), v_input[0], v_input[3], row_margin, row_blend); - fl_snapshot((target_dir + "wComment.png").c_str(), wComment, row_margin, row_blend); - fl_snapshot((target_dir + "wp_cpp_callback.png").c_str(), wCallback, w_when_box, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_cpp_tab.png"), wp_cpp_tab, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_cpp_class.png"), wp_cpp_class, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_cpp_name.png"), wp_cpp_name, row_margin, row_blend); + fl_snapshot(SNAP_PATH("v_input.png"), v_input[0], v_input[3], row_margin, row_blend); + fl_snapshot(SNAP_PATH("wComment.png"), wComment, row_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_cpp_callback.png"), wCallback, w_when_box, row_margin, row_blend); // -- snapshot of the Grid tab select_only(t_grd); widget_tabs->value(widget_tab_grid); - fl_snapshot((target_dir + "wp_grid_tab.png").c_str(), widget_tab_grid, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_grid_tab.png"), widget_tab_grid, tab_margin, row_blend); // -- snapshot of the Grid Child tab select_only(t_grdc); widget_tabs->value(widget_tab_grid_child); - fl_snapshot((target_dir + "wp_gridc_tab.png").c_str(), widget_tab_grid_child, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("wp_gridc_tab.png"), widget_tab_grid_child, tab_margin, row_blend); // -- FLD_NODE_TYPE_Data select_only(t_data); - fl_snapshot((target_dir + "data_panel.png").c_str(), data_tabs_data, tab_margin, row_blend); + fl_snapshot(SNAP_PATH("data_panel.png"), data_tabs_data, tab_margin, row_blend); } diff --git a/fluid/tools/autodoc.h b/fluid/tools/autodoc.h index 136a7e119..51a39724c 100644 --- a/fluid/tools/autodoc.h +++ b/fluid/tools/autodoc.h @@ -26,8 +26,6 @@ #include <FL/Fl_Window.H> #include <FL/Fl_Rect.H> -#include <string> - /** Class to initialize a Rect by providing the margin around a rect. */ class Fl_Margin : public Fl_Rect { public: @@ -53,7 +51,7 @@ extern const int FL_SNAP_TO_WINDOW; extern Fl_Widget *FL_SNAP_AREA_CLEAR; -extern void run_autodoc(const std::string &target_dir); +extern void run_autodoc(const char *target_dir); #endif diff --git a/fluid/tools/filename.cxx b/fluid/tools/filename.cxx index 72386f78b..1cecb387b 100644 --- a/fluid/tools/filename.cxx +++ b/fluid/tools/filename.cxx @@ -17,16 +17,6 @@ /** \file fluid/filename.cxx \brief File names and URI utility functions for FLUID only. - - This file defines all fl_filename* functions using std::string and also - includes the main header file <FL/filename.H>. - - \note This file contains some filename functions using std::string which - which are used in FLTK 1.4.x but will be removed in the next minor - or major release after 1.4.x (i.e. 1.5 or maybe 4.0). - - \note This entire file should become obsolete in 1.5 or higher, whatever - the next release after 1.4.x will be. We'll use std::string instead! */ #include "tools/filename.h" @@ -35,226 +25,149 @@ #include <FL/fl_utf8.h> #include <FL/Fl.H> #include "../src/flstring.h" -//#include <FL/fl_string_functions.h> -//#include "../src/flstring.h" -// -//#include <stdlib.h> -//#include <string> + +#include <string.h> /** Return a shortened filename for limited display width. - Replace the start uf a path with "~" if it matches the home directory. - If the remaining filename has more than the give number of characters, it will + Replace the start of a path with "~" if it matches the home directory. + If the remaining filename has more than the given number of characters, it will be shortened by replacing parts of the path with an ellipsis ("..."). The shortened name can no longer be used to open a file. This is purely to - make as much information visible while fitting into a give space. + make as much information visible while fitting into a given space. + \param[out] result buffer to store result + \param[in] result_size size of result buffer \param[in] filename absolute path and name, UTF-8 aware - \param[in[ max_chars maximum number of characters in result, including ellipsis - \return shortened file path and name + \param[in] max_chars maximum number of characters in result, including ellipsis + \return pointer to result buffer */ -std::string fl_filename_shortened(const std::string &filename, int max_chars) { +char *fl_filename_shortened(char *result, int result_size, const char *filename, int max_chars) { // Insert this as the ellipsis static const char *ell = "..."; static const int ell_bytes = 3; // Replace the start of a path with "~" if it matches the home directory - static std::string tilde = "~/"; - static std::string home; + static char home[FL_PATH_MAX] = ""; + static int home_len = -1; static int home_chars = -1; - if (home_chars==-1) { - home = fl_filename_expand_str(tilde); - home_chars = fl_utf_nb_char((const uchar*)home.c_str(), (int)home.size()); + + if (home_chars == -1) { + fl_filename_expand(home, FL_PATH_MAX, "~/"); + home_len = (int)strlen(home); + home_chars = fl_utf_nb_char((const unsigned char*)home, home_len); } - std::string homed_filename; -#if defined(_WIN32) || defined(__APPLE__) - bool starts_with_home = fl_utf_strncasecmp(home.c_str(), filename.c_str(), home_chars)==0; -#else - bool starts_with_home = ::strncmp(home.c_str(), filename.c_str(), home.size())==0; -#endif + + // Check if filename starts with home directory + char homed_filename[FL_PATH_MAX]; + int starts_with_home = (strncmp(home, filename, home_len) == 0); if (starts_with_home) { - homed_filename = tilde + filename.substr(home.size()); + snprintf(homed_filename, FL_PATH_MAX, "~/%s", filename + home_len); } else { - homed_filename = filename; + strlcpy(homed_filename, filename, FL_PATH_MAX); } - // C style pointer will stay valid until filename is modified. - const unsigned char *u8str = reinterpret_cast<const unsigned char *>(homed_filename.c_str()); - // Count the number of UTF-8 characters in the name. - int num_chars = fl_utf_nb_char(u8str, (int)homed_filename.size()); - if (num_chars+ell_bytes-1 > max_chars) { - // Create a new string by replacing characters in the middle. - int remove_chars = num_chars - max_chars + ell_bytes; - int left_chars = (max_chars - ell_bytes)/2; -// int right_chars = max_chars - left_chars - 3; -// int right_start_char = num_chars - right_chars; - // Convert character counts into byte counts. - int left_bytes = fl_utf8strlen(homed_filename.c_str(), left_chars); - int right_start_byte = fl_utf8strlen(homed_filename.c_str()+left_bytes, remove_chars) + left_bytes; - return homed_filename.substr(0, left_bytes) + ell + homed_filename.substr(right_start_byte); - } else { - // Nothing to change. - return homed_filename; - } -} -/** - Make sure that a path name ends with a forward slash. - \param[in] str directory or path name - \return a new string, ending with a '/' - */ -std::string fld::end_with_slash(const std::string &str) { - char last = str[str.size()-1]; - if (last !='/' && last != '\\') - return str + "/"; - else - return str; -} + // Count the number of UTF-8 characters in the name + int homed_len = (int)strlen(homed_filename); + int num_chars = fl_utf_nb_char((const unsigned char*)homed_filename, homed_len); -/** - Replace Windows '\\' directory separator with UNix '/' separators. - \param[in] fn a file path in Unix or Windows format - \return a copy of the file path in Unix format. - */ -std::string fld::fix_separators(const std::string &fn) { - std::string ret = fn; - for (size_t i=0; i<ret.size(); ++i) { - if (ret[i] == '\\') { - ret[i] = '/'; + if (num_chars + ell_bytes - 1 > max_chars) { + // Create a new string by replacing characters in the middle + int remove_chars = num_chars - max_chars + ell_bytes; + int left_chars = (max_chars - ell_bytes) / 2; + + // Convert character counts into byte counts + int left_bytes = fl_utf8strlen(homed_filename, left_chars); + int right_start_byte = fl_utf8strlen(homed_filename + left_bytes, remove_chars) + left_bytes; + + // Build result: left part + ellipsis + right part + if (left_bytes < result_size - 1) { + memcpy(result, homed_filename, left_bytes); + int pos = left_bytes; + int remaining = result_size - pos - 1; + if (remaining > ell_bytes) { + memcpy(result + pos, ell, ell_bytes); + pos += ell_bytes; + remaining = result_size - pos - 1; + int right_len = homed_len - right_start_byte; + if (right_len > remaining) right_len = remaining; + if (right_len > 0) { + memcpy(result + pos, homed_filename + right_start_byte, right_len); + pos += right_len; + } + } + result[pos] = '\0'; + } else { + strlcpy(result, homed_filename, result_size); } + } else { + // Nothing to change + strlcpy(result, homed_filename, result_size); } - return ret; -} - -// ---- FLUID-local wrapper functions for filename operations ---- -/** - Get current working directory as std::string. - \return current working directory path - */ -std::string fl_getcwd_str() { - char buf[FL_PATH_MAX]; - fl_getcwd(buf, FL_PATH_MAX); - return std::string(buf); + return result; } /** Get path component (directory) from a filename. + \param[out] result buffer to store result (ends with separator if path exists) + \param[in] result_size size of result buffer \param[in] filename the full path - \return directory portion ending with separator - */ -std::string fl_filename_path_str(const char *filename) { - if (!filename || !*filename) return std::string(); - const char *name = fl_filename_name(filename); - if (name == filename) return std::string(); - return std::string(filename, name - filename); -} - -std::string fl_filename_path_str(const std::string &filename) { - return fl_filename_path_str(filename.c_str()); -} - -/** - Make a filename absolute. - \param[in] from relative or absolute filename - \return absolute filename + \return pointer to result buffer */ -std::string fl_filename_absolute_str(const char *from) { - char buf[FL_PATH_MAX]; - fl_filename_absolute(buf, FL_PATH_MAX, from); - return std::string(buf); -} - -std::string fl_filename_absolute_str(const std::string &from) { - return fl_filename_absolute_str(from.c_str()); -} - -/** - Make a filename absolute relative to a given directory. - \param[in] from relative filename - \param[in] cwd current working directory to use as base - \return absolute filename - */ -std::string fl_filename_absolute_str(const char *from, const char *cwd) { - char buf[FL_PATH_MAX]; - fl_filename_absolute(buf, FL_PATH_MAX, from, cwd); - return std::string(buf); -} +char *fl_filename_path(char *result, int result_size, const char *filename) { + result[0] = '\0'; + if (!filename || !*filename) return result; -std::string fl_filename_absolute_str(const std::string &from, const std::string &cwd) { - return fl_filename_absolute_str(from.c_str(), cwd.c_str()); -} + const char *name = fl_filename_name(filename); + if (name == filename) return result; // no path component -/** - Make a filename relative to current directory. - \param[in] from absolute filename - \return relative filename - */ -std::string fl_filename_relative_str(const char *from) { - char buf[FL_PATH_MAX]; - fl_filename_relative(buf, FL_PATH_MAX, from); - return std::string(buf); -} + int path_len = (int)(name - filename); + if (path_len >= result_size) path_len = result_size - 1; + memcpy(result, filename, path_len); + result[path_len] = '\0'; -std::string fl_filename_relative_str(const std::string &from) { - return fl_filename_relative_str(from.c_str()); + return result; } /** - Get filename portion from a path. - \param[in] filename the full path - \return filename without directory + Make sure that a path name ends with a forward slash. + \param[out] result buffer to store result + \param[in] result_size size of result buffer + \param[in] path directory or path name + \return pointer to result buffer */ -std::string fl_filename_name_str(const char *filename) { - if (!filename) return std::string(); - return std::string(fl_filename_name(filename)); -} - -std::string fl_filename_name_str(const std::string &filename) { - return fl_filename_name_str(filename.c_str()); -} +char *fld_end_with_slash(char *result, int result_size, const char *path) { + if (!path || !*path) { + result[0] = '\0'; + return result; + } -/** - Change the extension of a filename. - \param[in] filename original filename - \param[in] ext new extension (including dot) - \return filename with new extension - */ -std::string fl_filename_setext_str(const char *filename, const char *ext) { - char buf[FL_PATH_MAX]; - if (!filename) return std::string(); - strlcpy(buf, filename, FL_PATH_MAX); - fl_filename_setext(buf, FL_PATH_MAX, ext); - return std::string(buf); -} + int len = (int)strlen(path); + char last = path[len - 1]; -std::string fl_filename_setext_str(const std::string &filename, const std::string &ext) { - return fl_filename_setext_str(filename.c_str(), ext.c_str()); -} + if (last == '/' || last == '\\') { + strlcpy(result, path, result_size); + } else { + snprintf(result, result_size, "%s/", path); + } -/** - Expand a filename with shell variables like ~ for home directory. - \param[in] from filename with possible shell expansions - \return expanded filename - */ -std::string fl_filename_expand_str(const std::string &from) { - char buf[FL_PATH_MAX]; - fl_filename_expand(buf, FL_PATH_MAX, from.c_str()); - return std::string(buf); + return result; } /** - Get the extension of a filename. - \param[in] filename the filename - \return extension including the dot, or empty string if no extension + Replace Windows '\\' directory separator with Unix '/' separators in-place. + \param[in,out] path a file path to modify + \return pointer to path */ -std::string fl_filename_ext_str(const char *filename) { - if (!filename) return std::string(); - const char *ext = fl_filename_ext(filename); - if (!ext) return std::string(); - return std::string(ext); -} - -std::string fl_filename_ext_str(const std::string &filename) { - return fl_filename_ext_str(filename.c_str()); +char *fld_fix_separators(char *path) { + if (!path) return path; + char *p; + for (p = path; *p; p++) { + if (*p == '\\') { + *p = '/'; + } + } + return path; } diff --git a/fluid/tools/filename.h b/fluid/tools/filename.h index 85e4a2844..376ab7641 100644 --- a/fluid/tools/filename.h +++ b/fluid/tools/filename.h @@ -23,35 +23,42 @@ #include <FL/filename.H> #include <FL/fl_utf8.h> -#include <string> - -std::string fl_filename_shortened(const std::string &filename, int maxchars); - -// Wrapper functions for filename operations returning std::string -// These are FLUID-local implementations of functions that were removed from core FLTK - -std::string fl_getcwd_str(); -std::string fl_filename_path_str(const char *filename); -std::string fl_filename_path_str(const std::string &filename); -std::string fl_filename_absolute_str(const char *from); -std::string fl_filename_absolute_str(const std::string &from); -std::string fl_filename_absolute_str(const char *from, const char *cwd); -std::string fl_filename_absolute_str(const std::string &from, const std::string &cwd); -std::string fl_filename_relative_str(const char *from); -std::string fl_filename_relative_str(const std::string &from); -std::string fl_filename_name_str(const char *filename); -std::string fl_filename_name_str(const std::string &filename); -std::string fl_filename_setext_str(const char *filename, const char *ext); -std::string fl_filename_setext_str(const std::string &filename, const std::string &ext); -std::string fl_filename_expand_str(const std::string &from); -std::string fl_filename_ext_str(const char *filename); -std::string fl_filename_ext_str(const std::string &filename); - -namespace fld { - -extern std::string end_with_slash(const std::string &fn); -extern std::string fix_separators(const std::string &fn); - -} // namespace fld + +/** + Return a shortened filename for limited display width. + Replaces path start with "~" if it matches home directory, and + shortens middle with "..." if needed. + \param[out] result buffer to store result + \param[in] result_size size of result buffer + \param[in] filename absolute path and name, UTF-8 aware + \param[in] max_chars maximum number of characters in result + \return pointer to result buffer + */ +char *fl_filename_shortened(char *result, int result_size, const char *filename, int max_chars); + +/** + Get path component (directory) from a filename. + \param[out] result buffer to store result (ends with separator) + \param[in] result_size size of result buffer + \param[in] filename the full path + \return pointer to result buffer + */ +char *fl_filename_path(char *result, int result_size, const char *filename); + +/** + Make sure that a path name ends with a forward slash. + \param[out] result buffer to store result + \param[in] result_size size of result buffer + \param[in] path directory or path name + \return pointer to result buffer + */ +char *fld_end_with_slash(char *result, int result_size, const char *path); + +/** + Replace Windows '\\' directory separator with Unix '/' separators in-place. + \param[in,out] path a file path to modify + \return pointer to path + */ +char *fld_fix_separators(char *path); #endif // FLUID_TOOLS_FILENAME_H diff --git a/fluid/widgets/App_Menu_Bar.cxx b/fluid/widgets/App_Menu_Bar.cxx index 5dc430c69..9cb3e2d15 100644 --- a/fluid/widgets/App_Menu_Bar.cxx +++ b/fluid/widgets/App_Menu_Bar.cxx @@ -43,7 +43,7 @@ App_Menu_Bar::App_Menu_Bar(int X, int Y, int W, int H, const char *L) */ int App_Menu_Bar::handle(int event) { - Fl_Menu_Item *mi = nullptr; + Fl_Menu_Item *mi = 0; if (event == FL_BEFORE_MENU) { mi = (Fl_Menu_Item*)find_item(mergeback_cb); if (mi && Fluid.proj.write_mergeback_data) diff --git a/fluid/widgets/App_Menu_Bar.h b/fluid/widgets/App_Menu_Bar.h index 62487334f..bda77031f 100644 --- a/fluid/widgets/App_Menu_Bar.h +++ b/fluid/widgets/App_Menu_Bar.h @@ -31,7 +31,7 @@ namespace widget { */ class App_Menu_Bar : public Fl_Menu_Bar { public: - App_Menu_Bar(int X, int Y, int W, int H, const char *L = nullptr); + App_Menu_Bar(int X, int Y, int W, int H, const char *L = 0); int handle(int event) override; }; diff --git a/fluid/widgets/Bin_Button.cxx b/fluid/widgets/Bin_Button.cxx index 29afddb9c..728bcc8ed 100644 --- a/fluid/widgets/Bin_Button.cxx +++ b/fluid/widgets/Bin_Button.cxx @@ -81,7 +81,7 @@ int fld::widget::Bin_Button::handle(int inEvent) */ int fld::widget::Bin_Window_Button::handle(int inEvent) { - static Fl_Window *drag_win = nullptr; + static Fl_Window *drag_win = 0; int ret = 0; switch (inEvent) { case FL_PUSH: @@ -107,7 +107,7 @@ int fld::widget::Bin_Window_Button::handle(int inEvent) case FL_RELEASE: if (drag_win) { Fl::delete_widget(drag_win); - drag_win = nullptr; + drag_win = 0; // create a new window here Node *prototype = typename_to_prototype((char*)user_data()); if (prototype) { diff --git a/fluid/widgets/Bin_Button.h b/fluid/widgets/Bin_Button.h index 342fe0eac..e04228c82 100644 --- a/fluid/widgets/Bin_Button.h +++ b/fluid/widgets/Bin_Button.h @@ -26,7 +26,7 @@ namespace widget { class Bin_Button : public Fl_Button { public: int handle(int) override; - Bin_Button(int X,int Y,int W,int H, const char* l = nullptr) : + Bin_Button(int X,int Y,int W,int H, const char* l = 0) : Fl_Button(X,Y,W,H,l) { } }; @@ -34,7 +34,7 @@ public: class Bin_Window_Button : public Fl_Button { public: int handle(int) override; - Bin_Window_Button(int X,int Y,int W,int H, const char* l = nullptr) : + Bin_Window_Button(int X,int Y,int W,int H, const char* l = 0) : Fl_Button(X,Y,W,H,l) { } }; diff --git a/fluid/widgets/Code_Editor.cxx b/fluid/widgets/Code_Editor.cxx index aa7c28751..583d07c5b 100644 --- a/fluid/widgets/Code_Editor.cxx +++ b/fluid/widgets/Code_Editor.cxx @@ -233,11 +233,11 @@ Code_Editor::Code_Editor(int X, int Y, int W, int H, const char *L) : */ Code_Editor::~Code_Editor() { Fl_Text_Buffer *buf = mStyleBuffer; - mStyleBuffer = nullptr; + mStyleBuffer = 0; delete buf; buf = mBuffer; - buffer(nullptr); + buffer(0); delete buf; } diff --git a/fluid/widgets/Code_Editor.h b/fluid/widgets/Code_Editor.h index fec57727c..3ee654da1 100644 --- a/fluid/widgets/Code_Editor.h +++ b/fluid/widgets/Code_Editor.h @@ -50,7 +50,7 @@ class Code_Editor : public Fl_Text_Editor { static int auto_indent(int, Code_Editor* e); public: - Code_Editor(int X, int Y, int W, int H, const char *L=nullptr); + Code_Editor(int X, int Y, int W, int H, const char *L=0); ~Code_Editor(); void textsize(Fl_Fontsize s); Fl_Fontsize textsize() const { return Fl_Text_Editor::textsize(); } diff --git a/fluid/widgets/Code_Viewer.h b/fluid/widgets/Code_Viewer.h index 4198fd433..976462ca1 100644 --- a/fluid/widgets/Code_Viewer.h +++ b/fluid/widgets/Code_Viewer.h @@ -37,7 +37,7 @@ namespace widget { */ class Code_Viewer : public Code_Editor { public: - Code_Viewer(int X, int Y, int W, int H, const char *L = nullptr); + Code_Viewer(int X, int Y, int W, int H, const char *L = 0); protected: void draw() override; diff --git a/fluid/widgets/Formula_Input.cxx b/fluid/widgets/Formula_Input.cxx index dadebe674..16bc2310a 100644 --- a/fluid/widgets/Formula_Input.cxx +++ b/fluid/widgets/Formula_Input.cxx @@ -209,7 +209,7 @@ int Formula_Input::handle(int event) { } /** Set the list of the available variables - \param vars array of variables, last entry `has name_` set to `nullptr` + \param vars array of variables, last entry `has name_` set to `0` \param user_data is forwarded to the Variable callback */ void Formula_Input::variables(Formula_Input_Vars *vars, void *user_data) { vars_ = vars; diff --git a/fluid/widgets/Formula_Input.h b/fluid/widgets/Formula_Input.h index 5df30b5af..5daa22bd9 100644 --- a/fluid/widgets/Formula_Input.h +++ b/fluid/widgets/Formula_Input.h @@ -29,7 +29,7 @@ typedef int (Fluid_Coord_Callback)(Formula_Input const *, void*); // Entry for a list of variables available to an input field. // Formula_Input::variables() expects an array of -// Formula_Input_Vars with the last entry's name_ set to nullptr. +// Formula_Input_Vars with the last entry's name_ set to 0. typedef struct Formula_Input_Vars { const char *name_; Fluid_Coord_Callback *callback_; @@ -38,9 +38,9 @@ typedef struct Formula_Input_Vars { // A text input widget that understands simple math. class Formula_Input : public Fl_Input { - Fl_Callback *user_callback_ { nullptr }; - Formula_Input_Vars *vars_ { nullptr }; - void *vars_user_data_ { nullptr }; + Fl_Callback *user_callback_ { 0 }; + Formula_Input_Vars *vars_ { 0 }; + void *vars_user_data_ { 0 }; static void callback_handler_cb(Formula_Input *This, void *v); void callback_handler(void *v); @@ -49,7 +49,7 @@ class Formula_Input : public Fl_Input int eval(const char *s) const; public: - Formula_Input(int x, int y, int w, int h, const char *l = nullptr); + Formula_Input(int x, int y, int w, int h, const char *l = 0); /** Return the text in the widget text field. */ const char *text() const { return Fl_Input::value(); } diff --git a/fluid/widgets/Node_Browser.cxx b/fluid/widgets/Node_Browser.cxx index 06804125d..cf036f9b7 100644 --- a/fluid/widgets/Node_Browser.cxx +++ b/fluid/widgets/Node_Browser.cxx @@ -28,7 +28,7 @@ // ---- global variables /// Global access to the widget browser. -fld::widget::Node_Browser *widget_browser = nullptr; +fld::widget::Node_Browser *widget_browser = 0; using namespace fld; using namespace fld::widget; @@ -81,7 +81,7 @@ Fl_Widget *make_widget_browser(int x,int y,int w,int h) { /** Make sure that the caller is visible in the widget browser. \param[in] caller scroll the browser in y so that caller - is visible (may be nullptr) + is visible (may be 0) */ void redraw_widget_browser(Node *caller) { @@ -165,7 +165,7 @@ static char *copy_trunc(char *p, const char *str, int maxl, int quote, int trunc { int size = 0; // truncated string size in characters int bs; // size of UTF-8 character in bytes - if (!p) return nullptr; // bad buffer + if (!p) return 0; // bad buffer if (!str) { // no input string if (quote) { *p++='"'; *p++='"'; } *p = 0; @@ -232,7 +232,7 @@ void *Node_Browser::item_first() const { /** Override the method to find the next item in the list of elements. \param l this item - \return the next item, irregardless of tree depth, or nullptr at the end + \return the next item, irregardless of tree depth, or 0 at the end */ void *Node_Browser::item_next(void *l) const { return ((Node*)l)->next; @@ -241,7 +241,7 @@ void *Node_Browser::item_next(void *l) const { /** Override the method to find the previous item in the list of elements. \param l this item - \return the previous item, irregardless of tree depth, or nullptr at the start + \return the previous item, irregardless of tree depth, or 0 at the start */ void *Node_Browser::item_prev(void *l) const { return ((Node*)l)->prev; @@ -531,7 +531,7 @@ int Node_Browser::handle(int e) { if (l) { X += 3 + 12*l->level - hposition(); if (l->can_have_children() && Fl::event_x()>X && Fl::event_x()<X+13) ; - else l = nullptr; + else l = 0; } if (l != pushedtitle) { if (pushedtitle) redraw_line(pushedtitle); diff --git a/fluid/widgets/Node_Browser.h b/fluid/widgets/Node_Browser.h index eec1e7960..1296c3108 100644 --- a/fluid/widgets/Node_Browser.h +++ b/fluid/widgets/Node_Browser.h @@ -32,7 +32,7 @@ class Node_Browser : public Fl_Browser_ ((Node_Browser *)o)->callback(); } - Node* pushedtitle { nullptr }; + Node* pushedtitle { 0 }; int saved_h_scroll_ { 0 }; int saved_v_scroll_ { 0 }; @@ -48,7 +48,7 @@ class Node_Browser : public Fl_Browser_ int incr_height() const override; public: - Node_Browser(int,int,int,int,const char * = nullptr); + Node_Browser(int,int,int,int,const char * = 0); int handle(int) override; void callback(); void save_scroll_position(); diff --git a/fluid/widgets/Style_Parser.h b/fluid/widgets/Style_Parser.h index 287ea6b21..fff38c529 100644 --- a/fluid/widgets/Style_Parser.h +++ b/fluid/widgets/Style_Parser.h @@ -24,8 +24,8 @@ namespace widget { // Class to manage style parsing, friend of Code_Editor class Style_Parser { public: - const char *tbuff { nullptr }; // text buffer - char *sbuff { nullptr }; // style buffer + const char *tbuff { 0 }; // text buffer + char *sbuff { 0 }; // style buffer int len { 0 }; // running length char style { 0 }; // current style char lwhite { 1 }; // leading white space (1=white, 0=past white) diff --git a/fluid/widgets/Text_Viewer.cxx b/fluid/widgets/Text_Viewer.cxx index 5ae821d6b..310fa6919 100644 --- a/fluid/widgets/Text_Viewer.cxx +++ b/fluid/widgets/Text_Viewer.cxx @@ -39,7 +39,7 @@ Text_Viewer::Text_Viewer(int X, int Y, int W, int H, const char *L) */ Text_Viewer::~Text_Viewer() { Fl_Text_Buffer *buf = mBuffer; - buffer(nullptr); + buffer(0); delete buf; } diff --git a/fluid/widgets/Text_Viewer.h b/fluid/widgets/Text_Viewer.h index 98fa9200f..ced32cd39 100644 --- a/fluid/widgets/Text_Viewer.h +++ b/fluid/widgets/Text_Viewer.h @@ -31,7 +31,7 @@ namespace widget { */ class Text_Viewer : public Fl_Text_Display { public: - Text_Viewer(int X, int Y, int W, int H, const char *L = nullptr); + Text_Viewer(int X, int Y, int W, int H, const char *L = 0); ~Text_Viewer(); void draw() override; |
