diff --git a/fluid/Fd_Snap_Action.cxx b/fluid/Fd_Snap_Action.cxx index 729daad67e..b4d245e135 100644 --- a/fluid/Fd_Snap_Action.cxx +++ b/fluid/Fd_Snap_Action.cxx @@ -119,10 +119,6 @@ Fd_Layout_List g_layout_list; // ---- Callbacks ------------------------------------------------------ MARK: - -void layout_suite_marker(Fl_Widget *, void *) { - // intentionally left empty -} - void select_layout_suite_cb(Fl_Widget *, void *user_data) { int index = (int)(fl_intptr_t)user_data; assert(index >= 0); @@ -131,11 +127,6 @@ void select_layout_suite_cb(Fl_Widget *, void *user_data) { g_layout_list.update_dialogs(); } -void select_layout_preset_cb(Fl_Widget *, void *user_data) { - int index = (int)(fl_intptr_t)user_data; - select_layout_preset(index); -} - void select_layout_preset(int index) { assert(index >= 0); assert(index < 3); diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx index 7bf69be7d0..7955197dee 100644 --- a/fluid/Fl_Function_Type.cxx +++ b/fluid/Fl_Function_Type.cxx @@ -19,6 +19,7 @@ #include "fluid.h" #include "application/application.h" #include "project/project.h" +#include "ui/main_panel.h" #include "Fl_Window_Type.h" #include "Fl_Group_Type.h" #include "widget_browser.h" @@ -668,7 +669,7 @@ void Fl_Code_Type::open() { void Fl_Code_Type::write(fluid::stream::ProjectWriter &f) { // External editor changes? If so, load changes into ram, update mtime/size if ( handle_editor_changes() == 1 ) { - main_window->redraw(); // tell fluid to redraw; edits may affect tree's contents + fluid::ui::main_panel.main_window->redraw(); // tell fluid to redraw; edits may affect tree's contents } Fl_Type::write(f); } @@ -679,7 +680,7 @@ void Fl_Code_Type::write(fluid::stream::ProjectWriter &f) { void Fl_Code_Type::write_code1(fluid::stream::CodeWriter& f) { // External editor changes? If so, load changes into ram, update mtime/size if ( handle_editor_changes() == 1 ) { - main_window->redraw(); // tell fluid to redraw; edits may affect tree's contents + fluid::ui::main_panel.main_window->redraw(); // tell fluid to redraw; edits may affect tree's contents } f.tag(FD_TAG_GENERIC, 0); f.write_c_indented(name(), 0, '\n'); diff --git a/fluid/Fl_Window_Type.cxx b/fluid/Fl_Window_Type.cxx index 52ff93b832..c092facd4d 100644 --- a/fluid/Fl_Window_Type.cxx +++ b/fluid/Fl_Window_Type.cxx @@ -189,8 +189,6 @@ void Overlay_Window::draw() { } } -extern Fl_Window *main_window; - // Read an image of the overlay window // TODO: is this actually called from anywhere? uchar *Overlay_Window::read_image(int &ww, int &hh) { @@ -219,7 +217,7 @@ uchar *Overlay_Window::read_image(int &ww, int &hh) { // Cleanup and return... fl_delete_offscreen(offscreen); - main_window->make_current(); + fluid::ui::main_panel.main_window->make_current(); return pixels; } @@ -346,9 +344,9 @@ uchar *Fl_Window_Type::read_image(int &ww, int &hh) { void Fl_Window_Type::ideal_size(int &w, int &h) { w = 480; h = 320; - if (main_window) { + if (fluid::ui::main_panel.main_window) { int sx, sy, sw, sh; - Fl_Window *win = main_window; + Fl_Window *win = fluid::ui::main_panel.main_window; int screen = Fl::screen_num(win->x(), win->y()); Fl::screen_work_area(sx, sy, sw, sh, screen); w = std::min(w, sw*3/4); h = std::min(h, sh*3/4); @@ -727,8 +725,6 @@ void Fl_Window_Type::draw_overlay() { } } -extern Fl_Menu_Item Main_Menu[]; - // Calculate new bounding box of selected widgets: void Fl_Window_Type::fix_overlay() { fluid::ui::main_panel.overlay_item->label("Hide O&verlays"); @@ -880,7 +876,6 @@ extern void deselect(); extern Fl_Type* in_this_only; extern void fix_group_size(Fl_Type *t); -extern Fl_Menu_Item Main_Menu[]; extern Fl_Menu_Item New_Menu[]; /** @@ -1270,7 +1265,7 @@ int Fl_Window_Type::handle(int event) { case FL_SHORTCUT: { in_this_only = this; // modifies how some menu items work. - const Fl_Menu_Item* m = Main_Menu->test_shortcut(); + const Fl_Menu_Item* m = fluid::ui::main_panel.main_menubar->test_shortcut(); if (m && m->callback()) m->do_callback(this->o); in_this_only = 0; return (m != 0);} diff --git a/fluid/align_widget.cxx b/fluid/align_widget.cxx index 07bfa20182..0abb9cc74d 100644 --- a/fluid/align_widget.cxx +++ b/fluid/align_widget.cxx @@ -35,7 +35,6 @@ void align_widget_cb(Fl_Widget*, void *how_ptr) { - Fluid.project.undo.checkpoint(); const int max = 32768, min = -32768; int left, right, top, bot, wdt, hgt, n; Fl_Type *o; diff --git a/fluid/autodoc.cxx b/fluid/autodoc.cxx index 90c988ce3c..709b5f3b1e 100644 --- a/fluid/autodoc.cxx +++ b/fluid/autodoc.cxx @@ -20,6 +20,7 @@ #include "fluid.h" #include "application/application.h" #include "project/project.h" +#include "ui/main_panel.h" #include "factory.h" #include "widget_browser.h" #include "widget_panel.h" @@ -416,9 +417,9 @@ void run_autodoc(const Fl_String &target_dir) { // explain menubar? // explain widget browser // explain widget browser entry - main_window->size(350, 320); - fl_snapshot((target_dir + "main_window.png").c_str(), main_window, win_margin, win_blend); - fl_snapshot((target_dir + "main_menubar.png").c_str(), main_menubar, row_margin, row_blend); + fluid::ui::main_panel.main_window->size(350, 320); + fl_snapshot((target_dir + "main_window.png").c_str(), fluid::ui::main_panel.main_window, win_margin, win_blend); + fl_snapshot((target_dir + "main_menubar.png").c_str(), fluid::ui::main_panel.main_menubar, row_margin, row_blend); fl_snapshot((target_dir + "main_browser.png").c_str(), widget_browser, FL_SNAP_AREA_CLEAR, Fl_Rect(0, 30, FL_SNAP_TO_WINDOW, 100), row_blend, 2.0); diff --git a/fluid/factory.cxx b/fluid/factory.cxx index 9dabc1f299..6db9d5edfb 100644 --- a/fluid/factory.cxx +++ b/fluid/factory.cxx @@ -27,6 +27,7 @@ #include "fluid.h" #include "application/application.h" #include "project/project.h" +#include "ui/main_panel.h" #include "Fl_Group_Type.h" #include "Fl_Grid_Type.h" #include "Fl_Menu_Type.h" @@ -1303,9 +1304,9 @@ Fl_Type *add_new_widget_from_user(Fl_Type *inPrototype, Strategy strategy, bool int x = 0, y = 0, w = 480, h = 320; Fl_Window_Type *wt = (Fl_Window_Type *)t; wt->ideal_size(w, h); - if (main_window) { + if (fluid::ui::main_panel.main_window) { int sx, sy, sw, sh; - Fl_Window *win = main_window; + Fl_Window *win = fluid::ui::main_panel.main_window; int screen = Fl::screen_num(win->x(), win->y()); Fl::screen_work_area(sx, sy, sw, sh, screen); x = sx + sw/2 - w/2; diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx index aed94a3a55..19f4b047c4 100644 --- a/fluid/fluid.cxx +++ b/fluid/fluid.cxx @@ -84,14 +84,6 @@ using namespace fluid; /// FLUID-wide help dialog. static Fl_Help_Dialog *help_dialog = NULL; -//-> application::ui -/// Main app window menu bar. -Fl_Menu_Bar *main_menubar = NULL; - -//-> application::ui -/// Main app window. -Fl_Window *main_window; - //-> application /// Fluid application preferences, always accessible, will be flushed when app closes. Fl_Preferences fluid_prefs(Fl_Preferences::USER_L, "fltk.org", "fluid"); @@ -101,33 +93,8 @@ Fl_Preferences fluid_prefs(Fl_Preferences::USER_L, "fltk.org", "fluid"); /// \todo Details unclear. int reading_file = 0; -//-> application::ui -/// First Menuitem that shows the .fl design file history. -// Fl_Menu_Item *history_item = NULL; - -//-> application::ui -/// Menuitem to show or hide the widget bin, label will change if bin is visible. -// Fl_Menu_Item *widgetbin_item = NULL; - -//-> application::ui -/// Menuitem to show or hide the code view, label will change if view is visible. -// Fl_Menu_Item *codeview_item = NULL; - -//-> application::ui -/// Menuitem to show or hide the editing overlay, label will change if overlay visibility changes. -// Fl_Menu_Item *overlay_item = NULL; - -//-> application::ui -/// Menuitem to show or hide the editing guides, label will change if overlay visibility changes. -// Fl_Menu_Item *guides_item = NULL; - -//-> application::ui -/// Menuitem to show or hide the restricted area overlys, label will change if overlay visibility changes. -// Fl_Menu_Item *restricted_item = NULL; - //////////////////////////////////////////////////////////////// - /// Global reference to FLUID application fluid::Application Fluid; @@ -256,19 +223,14 @@ static void external_editor_timer(void*) { \param[in] v v is (void *)1 for "Save As...", and (void *)2 for "Save a Copy..." */ -void fluid::Callbacks::save(Fl_Widget *, void *v) { - Fluid.project.save(v != NULL, v != (void *)2); -} +// void fluid::Callbacks::save(Fl_Widget *, void *v) { +// Fluid.project.save(v != NULL, v != (void *)2); +// } -//-> application::callbacks /** Save a design template. \todo We should document the concept of templates. */ -void save_template_cb(Fl_Widget *, void *) { - save_as_template(); -} - void save_as_template() { // Setup the template panel... if (!template_panel) make_template_panel(); @@ -375,19 +337,11 @@ void save_as_template() { #endif // HAVE_LIBPNG && HAVE_LIBZ } -void revert_cb(Fl_Widget *,void *) { - Fluid.project.revert(); -} - //-> application::callbacks /** Exit Fluid; we hope you had a nice experience. If the design was modified, a dialog will ask for confirmation. */ -void exit_cb(Fl_Widget *,void *) { - quit_fluid(); -} - void quit_fluid() { if (shell_command_running()) { int choice = fl_choice("Previous shell command still running!", @@ -408,7 +362,7 @@ void quit_fluid() { // Stop any external editor update timers ExternalCodeEditor::stop_update_timer(); - save_position(main_window,"main_window_pos"); + save_position(fluid::ui::main_panel.main_window,"main_window_pos"); if (widgetbin_panel) { save_position(widgetbin_panel,"widgetbin_pos"); @@ -568,15 +522,6 @@ void apple_open_cb(const char *c) { } #endif // __APPLE__ - -//-> application::callbacks -/** - Callback to write C++ code and header files. - */ -void write_cb(Fl_Widget *, void *) { - Fluid.project.write_code_files(); -} - /** Merge the possibly modified content of code files back into the project. */ @@ -616,22 +561,6 @@ int mergeback_code_files() return c; } -void mergeback_cb(Fl_Widget *, void *) { - mergeback_code_files(); -} - -void write_strings_cb(Fl_Widget *, void *) { - Fluid.project.write_strings(); -} - -//-> application::callbacks -/** - Show the editor for the \c current Fl_Type. - */ -void openwidget_cb(Fl_Widget *, void *) { - open_widget_panel(); -} - void open_widget_panel() { if (!Fl_Type::current) { fl_message("Please select a widget"); @@ -640,44 +569,6 @@ void open_widget_panel() { Fl_Type::current->open(); } -void copy_cb(Fl_Widget*, void*) { - Fluid.project.copy(); -} - -/** - User chose to cut the currently selected widgets. - */ -void cut_cb(Fl_Widget *, void *) { - Fluid.project.cut(); -} - -void delete_cb(Fl_Widget *, void *) { - Fluid.project.user_delete(); -} - -void paste_cb(Fl_Widget*, void*) { - Fluid.project.paste(); -} - -/** - 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 duplicate_cb(Fl_Widget*, void*) { - Fluid.project.duplicate(); -} - -//-> application::callbacks -/** - User wants to sort selected widgets by y coordinate. - */ -static void sort_cb(Fl_Widget *,void *) { - sort_selected(); -} - void sort_selected() { Fluid.project.undo.checkpoint(); sort((Fl_Type*)NULL); @@ -685,14 +576,6 @@ void sort_selected() { Fluid.project.set_modflag(1); } -//-> application::callbacks -/** - Open the "About" dialog. - */ -void about_cb(Fl_Widget *, void *) { - fluid::ui::about_panel.show(); -} - //-> application::ui /** Open a dialog to show the HTML help page form the FLTK documentation folder. @@ -762,32 +645,8 @@ void show_help(const char *name) { help_dialog->show(); } -//-> application::callbacks -/** - User wants help on Fluid. - */ -void help_cb(Fl_Widget *, void *) { - show_help("fluid.html"); -} - -//-> application::callbacks -/** - User wants to see the Fluid manual. - */ -void manual_cb(Fl_Widget *, void *) { - show_help("index.html"); -} - // ---- Printing -//-> application::callbacks -/** - Open the dialog to allow the user to print the current window. - */ -void print_menu_cb(Fl_Widget *, void *) { - print_windows(); -} - void print_windows() { int w, h, ww, hh; int frompage, topage; @@ -850,130 +709,9 @@ void print_windows() { // ---- Main menu bar -extern void select_layout_preset_cb(Fl_Widget *, void *user_data); -extern void layout_suite_marker(Fl_Widget *, void *user_data); - -static void menu_file_new_cb(Fl_Widget *, void *) { Fluid.new_project(); } -static void menu_file_new_from_template_cb(Fl_Widget *, void *) { new_project_from_template(); } -static void menu_file_open_cb(Fl_Widget *, void *) { Fluid.open_project_from_file(""); } -static void menu_file_insert_cb(Fl_Widget *, void *) { Fluid.project.merge_project_file(""); } -static void menu_file_open_history_cb(Fl_Widget *, void *v) { - Fluid.open_project_from_file(Fl_String((const char*)v)); -} void menu_layout_sync_resize_cb(Fl_Menu_ *m, void*) { if (m->mvalue()->value()) Fl_Type::allow_layout = 1; else Fl_Type::allow_layout = 0; } -static void undo_cb(Fl_Widget *, void *) { - Fluid.project.undo.undo(); -} -static void redo_cb(Fl_Widget *, void *) { - Fluid.project.undo.redo(); -} - - -//-> application::ui -/** - This is the main Fluid menu. - - Design history is manipulated right inside this menu structure. - Some menu items change or deactivate correctly, but most items just trigger - various callbacks. - - \c New_Menu creates new widgets and is explained in detail in another location. - - \see New_Menu - \todo This menu needs some major modernization. Menus are too long and their - sorting is not always obvious. - \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 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, 0, FL_MENU_DIVIDER}, - {"&Save", FL_COMMAND+'s', fluid::Callbacks::save, 0}, - {"Save &As...", FL_COMMAND+FL_SHIFT+'s', fluid::Callbacks::save, (void*)1}, - {"Sa&ve A Copy...", 0, fluid::Callbacks::save, (void*)2}, - {"&Revert...", 0, 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', print_menu_cb}, - {"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, 0, FL_MENU_DIVIDER}, - {Fluid.history.short_path[0], FL_COMMAND+'1', menu_file_open_history_cb, Fluid.history.full_path[0]}, - {Fluid.history.short_path[1], FL_COMMAND+'2', menu_file_open_history_cb, Fluid.history.full_path[1]}, - {Fluid.history.short_path[2], FL_COMMAND+'3', menu_file_open_history_cb, Fluid.history.full_path[2]}, - {Fluid.history.short_path[3], FL_COMMAND+'4', menu_file_open_history_cb, Fluid.history.full_path[3]}, - {Fluid.history.short_path[4], FL_COMMAND+'5', menu_file_open_history_cb, Fluid.history.full_path[4]}, - {Fluid.history.short_path[5], FL_COMMAND+'6', menu_file_open_history_cb, Fluid.history.full_path[5]}, - {Fluid.history.short_path[6], FL_COMMAND+'7', menu_file_open_history_cb, Fluid.history.full_path[6]}, - {Fluid.history.short_path[7], FL_COMMAND+'8', menu_file_open_history_cb, Fluid.history.full_path[7]}, - {Fluid.history.short_path[8], FL_COMMAND+'9', menu_file_open_history_cb, Fluid.history.full_path[8]}, - {Fluid.history.short_path[9], 0, menu_file_open_history_cb, Fluid.history.full_path[9], FL_MENU_DIVIDER}, - {"&Quit", FL_COMMAND+'q', exit_cb}, - {0}, -{"&Edit",0,0,0,FL_SUBMENU}, - {"&Undo", FL_COMMAND+'z', undo_cb}, - {"&Redo", FL_COMMAND+FL_SHIFT+'z', 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, 0, FL_MENU_DIVIDER}, - {"Select &All", FL_COMMAND+'a', select_all_cb}, - {"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,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, 0, FL_MENU_DIVIDER}, - {"Settings...",FL_ALT+'p',show_settings_cb}, - {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}, - {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}, - {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}, - {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}, - {0}, - {"Synchronized Resize", 0, (Fl_Callback*)menu_layout_sync_resize_cb, NULL, FL_MENU_TOGGLE|FL_MENU_DIVIDER }, - {"&Grid and Size Settings...",FL_COMMAND+'g',show_grid_cb, NULL, FL_MENU_DIVIDER}, - {"Presets", 0, layout_suite_marker, (void*)main_layout_submenu_, FL_SUBMENU_POINTER }, - {"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 }, - {0}, -{"&Shell", 0, Fd_Shell_Command_List::menu_marker, (void*)Fd_Shell_Command_List::default_menu, FL_SUBMENU_POINTER}, -{"&Help",0,0,0,FL_SUBMENU}, - {"&Rapid development with FLUID...",0,help_cb}, - {"&FLTK Programmers Manual...",0,manual_cb, 0, FL_MENU_DIVIDER}, - {"&About FLUID...",0,about_cb}, - {0}, -{0}}; //-> application::callbacks /** @@ -1080,9 +818,6 @@ void toggle_widgetbin() { fluid::ui::main_panel.widgetbin_item->label("Hide Widget &Bin"); } } -void toggle_widgetbin_cb(Fl_Widget *, void *) { - toggle_widgetbin(); -} //-> application::callbacks /** @@ -1113,33 +848,13 @@ void make_main_window() { make_shell_window(); } - if (!main_window) { + if (!fluid::ui::main_panel.main_window) { Fl_Widget *o; loadPixmaps(); -#if 0 - main_window = new Fl_Double_Window(WINWIDTH,WINHEIGHT,"fluid"); - main_window->box(FL_NO_BOX); - o = make_widget_browser(0,MENUHEIGHT,BROWSERWIDTH,BROWSERHEIGHT); - o->box(FL_FLAT_BOX); - o->tooltip("Double-click to view or change an item."); - main_window->resizable(o); - main_menubar = new Fl_Menu_Bar(0,0,BROWSERWIDTH,MENUHEIGHT); - main_menubar->menu(Main_Menu); - // quick access to all dynamic menu items - // 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); - // codeview_item = (Fl_Menu_Item*)main_menubar->find_item((Fl_Callback*)toggle_codeview_cb); - // overlay_item = (Fl_Menu_Item*)main_menubar->find_item((Fl_Callback*)toggle_overlays); - // guides_item = (Fl_Menu_Item*)main_menubar->find_item((Fl_Callback*)toggle_guides); - // restricted_item = (Fl_Menu_Item*)main_menubar->find_item((Fl_Callback*)toggle_restricted); - main_menubar->global(); -#else fluid::ui::main_panel.build(); - main_window = fluid::ui::main_panel.panel_window; widget_browser = fluid::ui::main_panel.widget_browser; -#endif fill_in_New_Menu(); - main_window->end(); + fluid::ui::main_panel.main_window->end(); } if (!Fluid.batch_mode) { @@ -1199,14 +914,14 @@ int main(int argc,char **argv) { setlocale(LC_NUMERIC, "C"); // make sure numeric values are written correctly Fluid.launch_path = end_with_slash(fl_getcwd()); // store the current path at launch - int project_index = Fluid.args.read(argc, argv); - if (project_index == -1) { + int project_arg_index = Fluid.args.read(argc, argv); + if (project_arg_index == -1) { return 1; } const char *c = NULL; if (Fluid.args.autodoc_path.empty()) - c = argv[project_index]; + c = argv[project_arg_index]; fl_register_images(); @@ -1219,17 +934,16 @@ int main(int argc,char **argv) { #endif // __APPLE__ 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, WINWIDTH, WINHEIGHT ); + position_window(fluid::ui::main_panel.main_window,"main_window_pos", 1, 10, 30, WINWIDTH, WINHEIGHT ); if (g_shell_config) { g_shell_config->read(fluid_prefs, Fd_Tool_Store::USER); g_shell_config->update_settings_dialog(); g_shell_config->rebuild_shell_menu(); } g_layout_list.read(fluid_prefs, Fd_Tool_Store::USER); - main_window->show(argc, argv); - toggle_widgetbin_cb(0,0); - toggle_codeview_cb(0,0); + fluid::ui::main_panel.main_window->show(argc, argv); + toggle_widgetbin(); + codeview_toggle_visibility(); if (!c && openlast_button->value() && Fluid.history.full_path[0][0] && Fluid.args.autodoc_path.empty()) { // Open previous file when no file specified... Fluid.open_project_from_file(Fluid.history.full_path[0]); @@ -1302,7 +1016,7 @@ int main(int argc,char **argv) { Fl::run(); #else while (!quit_flag) Fl::wait(); - if (quit_flag) exit_cb(0,0); + if (quit_flag) quit_fluid(); #endif // _WIN32 Fluid.project.undo.clear(); diff --git a/fluid/fluid.h b/fluid/fluid.h index f1a82a87fa..8d2c0934fa 100644 --- a/fluid/fluid.h +++ b/fluid/fluid.h @@ -52,19 +52,10 @@ enum class Fd_Tool_Store { // ---- global variables extern Fl_Preferences fluid_prefs; -extern Fl_Menu_Item Main_Menu[]; -extern Fl_Menu_Bar *main_menubar; -extern Fl_Window *main_window; extern int reading_file; -// extern Fl_Menu_Item *history_item; -// extern Fl_Menu_Item *widgetbin_item; -// extern Fl_Menu_Item *codeview_item; -// extern Fl_Menu_Item *overlay_item; extern Fl_Button *overlay_button; -// extern Fl_Menu_Item *guides_item; -// extern Fl_Menu_Item *restricted_item; extern Fl_Check_Button *guides_button; extern Fl_Menu_Item main_layout_submenu_[]; @@ -84,11 +75,6 @@ namespace fluid { class Application; class Project; -class Callbacks { -public: - static void save(Fl_Widget *, void *v); -}; - }; // namespace FLUID extern fluid::Application Fluid; @@ -100,15 +86,10 @@ extern void flush_text_widgets(); // ---- public callback functions -extern void save_template_cb(Fl_Widget *, void *); void save_as_template(); -extern void revert_cb(Fl_Widget *,void *); -extern void exit_cb(Fl_Widget *,void *); void quit_fluid(); -extern void write_strings_cb(Fl_Widget *, void *); extern void align_widget_cb(Fl_Widget *, void *); -extern void toggle_widgetbin_cb(Fl_Widget *, void *); void toggle_widgetbin(); int mergeback_code_files(); void open_widget_panel(); diff --git a/fluid/function_panel.cxx b/fluid/function_panel.cxx index dbf78af7c5..7a266fcf67 100644 --- a/fluid/function_panel.cxx +++ b/fluid/function_panel.cxx @@ -773,11 +773,8 @@ void type_make_cb(Fl_Widget*,void*d) { Fl_Window *widgetbin_panel=(Fl_Window *)0; -static void cb_widgetbin_panel(Fl_Window* o, void* v) { - if (Fl::event()==FL_SHORTCUT && Fl::event_key()==FL_Escape) - exit_cb((Fl_Widget*)o, v); - else - toggle_widgetbin_cb((Fl_Widget*)o, v); +static void cb_widgetbin_panel(Fl_Window*, void*) { + toggle_widgetbin(); } Fl_Window* make_widgetbin() { diff --git a/fluid/function_panel.fl b/fluid/function_panel.fl index 55feaa85e5..3ba4bfae46 100644 --- a/fluid/function_panel.fl +++ b/fluid/function_panel.fl @@ -598,10 +598,7 @@ Function {make_widgetbin()} {open } { Fl_Window widgetbin_panel { label {Widget Bin} - callback {if (Fl::event()==FL_SHORTCUT && Fl::event_key()==FL_Escape) - exit_cb((Fl_Widget*)o, v); -else - toggle_widgetbin_cb((Fl_Widget*)o, v);} open + callback {toggle_widgetbin();} open selected xywh {395 227 600 102} type Single align 80 non_modal visible } { Fl_Group {} { diff --git a/fluid/project/project.cxx b/fluid/project/project.cxx index 3c9c1ae208..0a422d2f35 100644 --- a/fluid/project/project.cxx +++ b/fluid/project/project.cxx @@ -16,6 +16,7 @@ #include "project/project.h" #include "application/application.h" +#include "ui/main_panel.h" #include "fluid.h" #include "streams/project_reader.h" #include "streams/project_writer.h" @@ -87,7 +88,7 @@ bool Project::confirm_clear() { case 0 : /* Cancel */ return false; case 1 : /* Save */ - fluid::Callbacks::save(NULL, NULL); + save(false, true); if (modflag) return false; // user canceled the "Save As" dialog } return true; @@ -223,7 +224,7 @@ int Project::write_code_files(bool dont_show_completion_dialog) // -- handle user interface issues flush_text_widgets(); if (!filename) { - fluid::Callbacks::save(0,0); + save(false, true); if (!filename) return 1; } @@ -348,7 +349,7 @@ void Project::set_filename(const char *c) { After saving, it updates the filename and modification flags if update_filename is true. - "Save" sets ask_for_filename and update_filename to false. + "Save" sets ask_for_filename to false and update_filename to true. "Save As..." sets ask_for_filename and update_filename to true. "Save a Copy..." sets ask_for_filename to true and update_filename to false. @@ -496,7 +497,7 @@ void Project::set_modflag(int mf, int mfc) { modflag_c = mfc; } - if (main_window) { + if (fluid::ui::main_panel.main_window) { Fl_String basename; if (!Fluid.project.filename) basename = "Untitled.fl"; else basename = fl_filename_name(Fl_String(Fluid.project.filename)); @@ -505,10 +506,10 @@ void Project::set_modflag(int mf, int mfc) { 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); - const char *old_title = main_window->label(); + const char *old_title = fluid::ui::main_panel.main_window->label(); // only update the title if it actually changed if (!old_title || strcmp(old_title, new_title)) - main_window->copy_label(new_title); + fluid::ui::main_panel.main_window->copy_label(new_title); } // if the UI was modified in any way, update the Code View panel if (codeview_panel && codeview_panel->visible() && cv_autorefresh->value()) @@ -605,6 +606,13 @@ void Project::cut() { widget_browser->rebuild(); } +/** + 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 Project::duplicate() { if (!Fl_Type::current) { fl_beep(); @@ -653,7 +661,7 @@ void Project::duplicate() { void Project::write_strings() { flush_text_widgets(); if (!Fluid.project.filename) { - fluid::Callbacks::save(0,0); + save(false, true); if (!Fluid.project.filename) return; } Fl_String filename = Fluid.project.stringsfile_path() + Fluid.project.stringsfile_name(); diff --git a/fluid/project/undo.cxx b/fluid/project/undo.cxx index 1b37faacef..7ed2fe1085 100644 --- a/fluid/project/undo.cxx +++ b/fluid/project/undo.cxx @@ -115,10 +115,6 @@ void project::Undo::redo() { project.set_modflag(current != last_saved); widget_browser->rebuild(); project.update_settings_dialog(); - - // Update undo/redo menu items... - // if (current >= last) Main_Menu[redo_item].deactivate(); - // Main_Menu[undo_item].activate(); } @@ -167,9 +163,6 @@ void project::Undo::undo() { // Update modified flag... project.set_modflag(current != last_saved); - // Update undo/redo menu items... - // if (current <= 0) Main_Menu[undo_item].deactivate(); - // Main_Menu[redo_item].activate(); widget_browser->rebuild(); project.update_settings_dialog(); project.undo.resume(); @@ -213,10 +206,6 @@ void project::Undo::checkpoint() { current ++; last = current; if (current > max_undo) max_undo = current; - - // Enable the Undo and disable the Redo menu items... - // Main_Menu[undo_item].activate(); - // Main_Menu[redo_item].deactivate(); } // Clear undo buffer @@ -232,10 +221,6 @@ void project::Undo::clear() { current = last = max_undo = 0; if (project.modflag) last_saved = -1; else last_saved = 0; - - // Disable the Undo and Redo menu items... - // Main_Menu[undo_item].deactivate(); - // Main_Menu[redo_item].deactivate(); } // Resume undo checkpoints diff --git a/fluid/shell_command.cxx b/fluid/shell_command.cxx index 74ef0d1431..622f272c68 100644 --- a/fluid/shell_command.cxx +++ b/fluid/shell_command.cxx @@ -307,13 +307,13 @@ static bool prepare_shell_command(int flags) { return false; } if (flags & Fd_Shell_Command::SAVE_PROJECT) { - fluid::Callbacks::save(0, 0); + Fluid.project.save(false, true); } if (flags & Fd_Shell_Command::SAVE_SOURCECODE) { Fluid.project.write_code_files(true); } if (flags & Fd_Shell_Command::SAVE_STRINGS) { - write_strings_cb(0, 0); + Fluid.project.write_strings(); } return true; } diff --git a/fluid/ui/main_panel.cxx b/fluid/ui/main_panel.cxx index 3872ec1de6..89df2296a6 100644 --- a/fluid/ui/main_panel.cxx +++ b/fluid/ui/main_panel.cxx @@ -27,8 +27,17 @@ using namespace fluid::ui; void show_help(const char *name); +void MainPanel::cb_main_window_i(Fl_Double_Window*, void*) { +//~fl~0~0000~b0a14477~~ + quit_fluid(); +//~fl~3~0f48~69468f9f~~ +} +void MainPanel::cb_main_window(Fl_Double_Window* o, void* v) { + ((MainPanel*)(o->user_data()))->cb_main_window_i(o,v); +} + void MainPanel::cb_New_i(Fl_Menu_*, void*) { -//~fl~0~0000~2bff1c37~~ +//~fl~0~0000~ce60c4f9~~ Fluid.new_project(); //~fl~2~5023~e4c3136e~~ } @@ -552,11 +561,11 @@ Fl_Menu_Item* MainPanel::preset_menu = MainPanel::menu_main_menubar + 78; Fl_Menu_Item* MainPanel::shell_submenu = MainPanel::menu_main_menubar + 82; Fl_Double_Window* MainPanel::make_panel() { - { panel_window = new Fl_Double_Window(300, 525, "FLUID"); - panel_window->color(FL_BACKGROUND2_COLOR); - panel_window->selection_color(FL_DARK1); - panel_window->user_data((void*)(this)); - panel_window->hotspot(panel_window); + { main_window = new Fl_Double_Window(300, 525, "FLUID"); + main_window->color(FL_BACKGROUND2_COLOR); + main_window->selection_color(FL_DARK1); + main_window->callback((Fl_Callback*)cb_main_window, (void*)(this)); + main_window->hotspot(main_window); { main_menubar = new Fl_Menu_Bar(0, 0, 300, 25); { Fl_Menu_Item* o = &menu_main_menubar[4]; o->label(Fluid.history.short_path[0]); @@ -603,20 +612,19 @@ Fl_Double_Window* MainPanel::make_panel() { widget_browser->when(FL_WHEN_RELEASE_ALWAYS); Fl_Group::current()->resizable(widget_browser); } // Widget_Browser* widget_browser - panel_window->set_non_modal(); - panel_window->size_range(280, 200); - panel_window->end(); - } // Fl_Double_Window* panel_window - return panel_window; + main_window->size_range(280, 200); + main_window->end(); + } // Fl_Double_Window* main_window + return main_window; } /** Constructor */ MainPanel::MainPanel() { -//~fl~0~0000~42a49a03~~ - panel_window = nullptr; -//~fl~1~f9d7~89162831~~ +//~fl~0~0000~2c43afec~~ + main_window = nullptr; +//~fl~1~f9d7~deac3c13~~ } /** @@ -624,8 +632,8 @@ MainPanel::MainPanel() { */ MainPanel::~MainPanel() { //~fl~0~0000~08914570~~ - delete panel_window; -//~fl~1~c8a2~d7fec351~~ + delete main_window; +//~fl~1~c8a2~4bd6d899~~ } /** @@ -633,10 +641,10 @@ MainPanel::~MainPanel() { */ void MainPanel::build() { //~fl~0~0000~e34a750b~~ - if (panel_window == nullptr) { + if (main_window == nullptr) { make_panel(); } -//~fl~1~5ddf~3b33627a~~ +//~fl~1~5ddf~444c7294~~ } /** @@ -645,8 +653,8 @@ void MainPanel::build() { void MainPanel::show() { //~fl~0~0000~d600e79d~~ build(); - panel_window->show(); -//~fl~1~d9d1~94ddffa5~~ + main_window->show(); +//~fl~1~d9d1~653b75be~~ } /** @@ -654,9 +662,9 @@ void MainPanel::show() { */ void MainPanel::hide() { //~fl~0~0000~e29f0ce0~~ - if (panel_window) { - panel_window->hide(); + if (main_window) { + main_window->hide(); } -//~fl~1~08be~da452744~~ +//~fl~1~08be~7d15f02b~~ } MainPanel fluid::ui::main_panel; diff --git a/fluid/ui/main_panel.fl b/fluid/ui/main_panel.fl index 54995056d9..69dcba157a 100644 --- a/fluid/ui/main_panel.fl +++ b/fluid/ui/main_panel.fl @@ -68,9 +68,10 @@ declblock {namespace fluid \{} {uid 962d open public map 1 after {\}} } { Function {make_panel()} {uid 6499 open private } { - Fl_Window panel_window {uid 0f48 - label FLUID open - xywh {389 91 300 525} type Double color 7 selection_color 47 resizable hotspot non_modal size_range {280 200 0 0} visible + Fl_Window main_window {uid 0f48 + label FLUID + callback {quit_fluid();} open selected + xywh {389 91 300 525} type Double color 7 selection_color 47 resizable hotspot size_range {280 200 0 0} visible } { Fl_Menu_Bar main_menubar {uid ee62 open xywh {0 0 300 25} @@ -500,7 +501,7 @@ declblock {namespace fluid \{} {uid 962d open public map 1 after {\}} } } } - Fl_Browser widget_browser {uid 7b19 selected + Fl_Browser widget_browser {uid 7b19 xywh {0 25 300 500} box FLAT_BOX resizable code0 {\#include "widget_browser.h"} class Widget_Browser @@ -510,19 +511,19 @@ declblock {namespace fluid \{} {uid 962d open public map 1 after {\}} Function {MainPanel()} {uid 689a comment Constructor open } { - code {panel_window = nullptr;} {uid f9d7 + code {main_window = nullptr;} {uid f9d7 } } Function {~MainPanel() override} {uid 86cc comment {Virtual destructor.} open } { - code {delete panel_window;} {uid c8a2 + code {delete main_window;} {uid c8a2 } } Function {build() override} {uid 678c comment {Build the panel, don't show it yet.} open return_type void } { - code {if (panel_window == nullptr) { + code {if (main_window == nullptr) { make_panel(); }} {uid 5ddf } @@ -531,14 +532,14 @@ declblock {namespace fluid \{} {uid 962d open public map 1 after {\}} comment {Build if needed and show the panel.} open return_type void } { code {build(); -panel_window->show();} {uid d9d1 +main_window->show();} {uid d9d1 } } Function {hide() override} {uid 2fd1 comment {Hide the panel and retain for later.} open return_type void } { - code {if (panel_window) { - panel_window->hide(); + code {if (main_window) { + main_window->hide(); }} {uid 08be } } diff --git a/fluid/ui/main_panel.h b/fluid/ui/main_panel.h index 339d9ad7a6..bea26caa83 100644 --- a/fluid/ui/main_panel.h +++ b/fluid/ui/main_panel.h @@ -41,7 +41,11 @@ namespace ui { class MainPanel : Panel { Fl_Double_Window* make_panel(); public: - Fl_Double_Window *panel_window; + Fl_Double_Window *main_window; +private: + inline void cb_main_window_i(Fl_Double_Window*, void*); + static void cb_main_window(Fl_Double_Window*, void*); +public: Fl_Menu_Bar *main_menubar; static Fl_Menu_Item menu_main_menubar[]; private: