1 | // This file is part of SmallBASIC |
2 | // |
3 | // Copyright(C) 2001-2020 Chris Warren-Smith. |
4 | // |
5 | // This program is distributed under the terms of the GPL v2.0 or later |
6 | // Download the GNU Public License (GPL) from www.gnu.org |
7 | // |
8 | |
9 | #ifndef MAIN_WINDOW_H |
10 | #define MAIN_WINDOW_H |
11 | |
12 | #include <stdint.h> |
13 | #include <FL/Fl_Double_Window.H> |
14 | #include <FL/Fl_Group.H> |
15 | #include <FL/Fl_Value_Input.H> |
16 | #include <FL/Fl_Menu_Bar.H> |
17 | #include <FL/Fl_Tabs.H> |
18 | #include "platform/fltk/display.h" |
19 | #include "platform/fltk/runtime.h" |
20 | #include "platform/fltk/EditorWidget.h" |
21 | #include "platform/fltk/HelpView.h" |
22 | #include "platform/fltk/Profile.h" |
23 | #include "platform/fltk/utils.h" |
24 | |
25 | enum ExecState { |
26 | init_state, |
27 | edit_state, |
28 | run_state, |
29 | modal_state, |
30 | break_state, |
31 | quit_state |
32 | }; |
33 | |
34 | enum GroupWidgetEnum { |
35 | gw_editor, |
36 | gw_output, |
37 | gw_help, |
38 | gw_file |
39 | }; |
40 | |
41 | struct MainWindow; |
42 | extern MainWindow *wnd; |
43 | extern ExecState runMode; |
44 | |
45 | #ifdef CALLBACK_METHOD |
46 | #undef CALLBACK_METHOD |
47 | #endif |
48 | |
49 | #define CALLBACK_METHOD(FN) \ |
50 | void FN(Fl_Widget *w=0, void *v=0); \ |
51 | static void FN ## _cb(Fl_Widget *w, void *v) { \ |
52 | wnd->FN(w, v); \ |
53 | } |
54 | |
55 | struct BaseWindow : public Fl_Double_Window { |
56 | BaseWindow(int w, int h, Runtime *mainSystem = NULL) |
57 | : Fl_Double_Window(w, h, "SmallBASIC" ), _mainSystem(mainSystem) {} |
58 | virtual ~BaseWindow() {}; |
59 | int handle(int e); |
60 | bool handleKeyEvent(); |
61 | private: Runtime *_mainSystem; // for hidden ide mode |
62 | }; |
63 | |
64 | struct MainWindow : public BaseWindow { |
65 | MainWindow(int w, int h); |
66 | virtual ~MainWindow(); |
67 | |
68 | bool basicMain(EditorWidget *editWidget, const char *filename, bool toolExec); |
69 | bool isBreakExec(void); // whether BREAK mode has been entered |
70 | bool isRunning(void); // whether a program is running |
71 | bool isEdit(); // whether a program is currently being edited |
72 | bool isIdeHidden(); // whether to run without the IDE displayed |
73 | bool isInteractive(); // whether to run without an interface |
74 | bool isModal(); // whether a modal gui loop is active |
75 | void busyMessage(); |
76 | int handle(int e); |
77 | void loadHelp(const char *path); |
78 | void loadIcon(); |
79 | void pathMessage(const char *file); |
80 | void resize(int x, int y, int w, int h); |
81 | void resizeDisplay(int x, int y, int w, int h); |
82 | void resizeTabs(int fontSize); |
83 | void saveEditConfig(EditorWidget *editWidget); |
84 | void scanPlugIns(Fl_Menu_Bar *); |
85 | void scanRecentFiles(Fl_Menu_Bar *); |
86 | void setBreak(); |
87 | void setModal(bool modal); |
88 | void setTitle(Fl_Window *widget, const char *filename); |
89 | void showEditTab(EditorWidget *editWidget); |
90 | void statusMsg(RunMessage runMessage, const char *filename); |
91 | void updateConfig(EditorWidget *current); |
92 | void updateEditTabName(EditorWidget *editWidget); |
93 | |
94 | Fl_Group *createEditor(const char *title); |
95 | EditorWidget *getEditor(Fl_Group *group); |
96 | EditorWidget *getEditor(const char *fullPath); |
97 | EditorWidget *getEditor(bool select = false); |
98 | void editFile(const char *filePath); |
99 | Fl_Group *getSelectedTab(); |
100 | Fl_Group *getNextTab(Fl_Group *current); |
101 | Fl_Group *getPrevTab(Fl_Group *current); |
102 | Fl_Group *selectTab(const char *label); |
103 | Fl_Group *findTab(const char *label); |
104 | Fl_Group *findTab(GroupWidgetEnum groupWidget); |
105 | GroupWidgetEnum getGroupWidget(Fl_Group *group) { |
106 | return (GroupWidgetEnum) (intptr_t) group->user_data(); |
107 | } |
108 | bool logPrint(); |
109 | FILE *openConfig(const char *fileName, const char *flags = "w" ); |
110 | TtyWidget *tty(); |
111 | void exit(int code) { delete this; ::exit(code); } |
112 | |
113 | CALLBACK_METHOD(close_tab); |
114 | CALLBACK_METHOD(close_other_tabs); |
115 | CALLBACK_METHOD(copy_text); |
116 | CALLBACK_METHOD(cut_text); |
117 | CALLBACK_METHOD(editor_plugin); |
118 | CALLBACK_METHOD(export_file); |
119 | CALLBACK_METHOD(font_size_decr); |
120 | CALLBACK_METHOD(font_size_incr); |
121 | CALLBACK_METHOD(help_about); |
122 | CALLBACK_METHOD(help_app); |
123 | CALLBACK_METHOD(help_contents); |
124 | CALLBACK_METHOD(help_contents_brief); |
125 | CALLBACK_METHOD(help_contents_anchor); |
126 | CALLBACK_METHOD(help_home); |
127 | CALLBACK_METHOD(hide_ide); |
128 | CALLBACK_METHOD(load_file); |
129 | CALLBACK_METHOD(new_file); |
130 | CALLBACK_METHOD(next_tab); |
131 | CALLBACK_METHOD(open_file); |
132 | CALLBACK_METHOD(paste_text); |
133 | CALLBACK_METHOD(prev_tab); |
134 | CALLBACK_METHOD(quit); |
135 | CALLBACK_METHOD(restart_run); |
136 | CALLBACK_METHOD(run); |
137 | CALLBACK_METHOD(run_samples); |
138 | CALLBACK_METHOD(run_break); |
139 | CALLBACK_METHOD(run_selection); |
140 | CALLBACK_METHOD(run_live); |
141 | CALLBACK_METHOD(save_file_as); |
142 | CALLBACK_METHOD(set_options); |
143 | CALLBACK_METHOD(set_theme); |
144 | CALLBACK_METHOD(tool_plugin); |
145 | |
146 | HelpView *getHelp(); |
147 | Fl_Group *createTab(GroupWidgetEnum groupWidgetEnum, const char *label = NULL); |
148 | |
149 | strlib::String _siteHome; |
150 | strlib::String _exportFile; |
151 | |
152 | // display system |
153 | GraphicsWidget *_out; |
154 | Runtime *_runtime; |
155 | |
156 | // main output |
157 | Fl_Group *_outputGroup; |
158 | |
159 | EditorWidget *_runEditWidget; |
160 | |
161 | // tab parent |
162 | Fl_Tabs *_tabGroup; |
163 | |
164 | // configuration |
165 | Profile *_profile; |
166 | |
167 | // the system menu |
168 | Fl_Menu_Bar *_menuBar; |
169 | }; |
170 | |
171 | #endif |
172 | |