1 // This file is part of Golly.
2 // See docs/License.html for the copyright notice.
3 
4 #ifndef _WXMAIN_H_
5 #define _WXMAIN_H_
6 
7 #include "wx/splitter.h"   // for wxSplitterWindow, wxSplitterEvent
8 #include "wx/dirctrl.h"    // for wxGenericDirCtrl
9 #include "wx/treectrl.h"   // for wxTreeCtrl, wxTreeEvent
10 #include "wx/dataobj.h"    // for wxTextDataObject
11 
12 #include "bigint.h"        // for bigint
13 #include "lifealgo.h"      // for lifealgo
14 #include "writepattern.h"  // for pattern_format
15 #include "wxprefs.h"       // for MAX_RECENT
16 #include "wxalgos.h"       // for MAX_ALGOS, algo_type
17 #include "wxlayer.h"       // for MAX_LAYERS
18 
19 // Golly's main window:
20 class MainFrame : public wxFrame
21 {
22 public:
23     MainFrame();
24     ~MainFrame();
25 
26     // update functions
27     void UpdateEverything();
28     void UpdateUserInterface();
29     void UpdateToolBar();
30     void EnableAllMenus(bool enable);
31     void UpdateMenuItems();
32     void UpdatePatternAndStatus(bool update_now = false);
33     void UpdateStatus();
34     void UpdateMenuAccelerators();
35 
36     // clipboard functions
37     bool ClipboardHasText();
38     bool CopyTextToClipboard(const wxString& text);
39     bool GetTextFromClipboard(wxTextDataObject* data);
40     bool ClipboardContainsRule();
41     bool ClipboardContainsRLE3();
42     void OpenClipboard();
43     void RunClipboard();
44 
45     // file functions
46     void OpenFile(const wxString& path, bool remember = true);
47     void LoadPattern(const wxString& path, const wxString& newtitle,
48                      bool updatestatus = true, bool updateall = true);
49     void NewPattern(const wxString& title = _("untitled"));
50     void CreateUniverse();
51     void SetWindowTitle(const wxString& filename);
52     void OpenPattern();
53     void OpenScript();
54     void ToggleShowFiles();
55     void ChangeFileDir();
56     void SetFileDir(const wxString& newdir);
57     bool SavePattern();
58     bool SaveCurrentLayer();
59     const char* SaveFile(const wxString& path, const wxString& format, bool remember);
60     const char* WritePattern(const wxString& path, pattern_format format,
61                              output_compression compression,
62                              int top, int left, int bottom, int right);
63     void CheckBeforeRunning(const wxString& scriptpath, bool remember,
64                             const wxString& zippath);
65     bool ExtractZipEntry(const wxString& zippath,
66                          const wxString& entryname,
67                          const wxString& outfile);
68 #if wxUSE_DRAG_AND_DROP
69     wxDropTarget* NewDropTarget();
70 #endif
71 
72     // edit functions
73     void ToggleAllowUndo();
74     void RestorePattern(bigint& gen, const wxString& filename,
75                         bigint& x, bigint& y, int mag, int base, int expo);
76 
77     // prefs functions
78     void SetRandomFillPercentage();
79     void SetMinimumStepExponent();
80     void UpdateStepExponent();
81     void ShowPrefsDialog(const wxString& page = wxEmptyString);
82 
83     // control functions
84     void StartGenTimer();
85     void StartGenerating();
86     void StopGenerating();
87     void StartOrStop();
88     void Stop();
89     void FinishUp();
90     void GoFaster();
91     void GoSlower();
92     void DisplayTimingInfo();
93     void NextGeneration(bool useinc);
94     void ToggleAutoFit();
95     void ToggleHyperspeed();
96     void ToggleHashInfo();
97     void ToggleShowPopulation();
98     void SetStepExponent(int newexpo);
99     void SetGenIncrement();
100     bool SaveStartingPattern();
101     void ResetPattern(bool resetundo = true);
102     void SetGeneration();
103     const char* ChangeGenCount(const char* genstring, bool inundoredo = false);
104     void SetBaseStep();
105     void ClearOutsideGrid();
106     void ReduceCellStates(int newmaxstate);
107     void ShowRuleDialog();
108     void ConvertOldRules();
109     wxString CreateRuleFiles(const wxSortedArrayString& deprecated,
110                              const wxSortedArrayString& ziprules);
111     void ChangeAlgorithm(algo_type newalgotype,
112                          const wxString& newrule = wxEmptyString,
113                          bool inundoredo = false);
114 
115     // view functions
116     void ToggleStatusBar();
117     void ToggleExactNumbers();
118     void ToggleToolBar();
119     void ToggleScrollBars();
120     void ToggleFullScreen();
121     void ShowPatternInfo();
122     void ResizeSplitWindow(int wd, int ht);
123     void ResizeStatusBar(int wd, int ht);
124     void ResizeBigView();
125     wxWindow* RightPane();
126 
127     // layer functions
128     void SaveOverlay();
129     void ToggleOverlay();
130     void DeleteOverlay();
131     void UpdateLayerItem(int index);
132     void AppendLayerItem();
133     void RemoveLayerItem();
134 
135     // miscellaneous functions
136     void OnTreeClick(wxMouseEvent& event);
137     void EditFile(const wxString& filepath);
138     void QuitApp();
139 
140     bool generating;            // currently generating a pattern?
141     bool fullscreen;            // in full screen mode?
142     bool showbanner;            // showing banner message?
143     bool keepmessage;           // don't clear message created by script?
144     bool command_pending;       // user selected a command while generating?
145     bool draw_pending;          // user wants to draw while generating?
146     wxCommandEvent cmdevent;    // the pending command
147     wxMouseEvent mouseevent;    // the pending draw
148 
149     wxTimer* gentimer;          // timer for generating patterns
150     wxTimer* opentimer;         // timer for calling OpenFile from OnIdle
151 
152     // temporary files
153     wxString clipfile;          // name of temporary file for storing clipboard data
154     wxString luafile;           // name of temporary Lua script
155     wxString perlfile;          // name of temporary Perl script
156     wxString pythonfile;        // name of temporary Python script
157 
158     // store files passed via command line (processed in first OnIdle)
159     wxArrayString pendingfiles;
160 
161     bool infront;               // main window is active?
162 
163     // these scroll bars are needed to avoid bug in wxGLCanvas on Mac
164     // and to allow showing/hiding them on all platforms
165     wxScrollBar* hbar;
166     wxScrollBar* vbar;
167 
168 private:
169     // any class wishing to process wxWidgets events must use this macro
170     DECLARE_EVENT_TABLE()
171 
172     // event handlers
173     void OnMenu(wxCommandEvent& event);
174     void OnSetFocus(wxFocusEvent& event);
175     void OnActivate(wxActivateEvent& event);
176     void OnSize(wxSizeEvent& event);
177     void OnIdle(wxIdleEvent& event);
178     void OnDirTreeSelection(wxTreeEvent& event);
179     void OnSashDblClick(wxSplitterEvent& event);
180     void OnGenTimer(wxTimerEvent& event);
181     void OnOpenTimer(wxTimerEvent& event);
182     void OnClose(wxCloseEvent& event);
183     void OnScroll(wxScrollEvent& event);
184 
185     // file functions
186     bool LoadImage(const wxString& path);
187     wxString GetBaseName(const wxString& path);
188     void SaveSucceeded(const wxString& path);
189     void AddRecentPattern(const wxString& path);
190     void OpenRecentPattern(int id);
191     void ClearMissingPatterns();
192     void ClearAllPatterns();
193     void AddRecentScript(const wxString& path);
194     void OpenRecentScript(int id);
195     void ClearMissingScripts();
196     void ClearAllScripts();
197     wxString GetScriptFileName(const wxString& text);
198     void OpenZipFile(const wxString& path);
199 
200     // control functions
201     void DisplayPattern();
202     bool StepPattern();
203 
204     // miscellaneous functions
205     void CreateMenus();
206     void CreateToolbar();
207     void CreateDirControl();
208     void SimplifyTree(wxString& dir, wxTreeCtrl* treectrl, wxTreeItemId root);
209     void DoPendingAction(bool restart);
210 
211     // splittable window contains file directory in left pane
212     // and layer/edit/timeline bars plus viewport window in right pane
213     wxSplitterWindow* splitwin;
214     wxGenericDirCtrl* filectrl;
215 
216     int hypdown;                    // for hyperspeed
217     int minexpo;                    // currexpo at maximum delay (must be <= 0)
218     long begintime, endtime;        // for timing info
219     double begingen, endgen;        // ditto
220 };
221 
222 // ids for menu commands, etc
223 enum {
224     // File menu
225     // wxID_NEW,
226     // wxID_OPEN,
227     ID_OPEN_CLIP = wxID_HIGHEST + 1,
228     ID_OPEN_RECENT,
229     // last 2 items in Open Recent submenu
230     ID_CLEAR_MISSING_PATTERNS = ID_OPEN_RECENT + MAX_RECENT + 1,
231     ID_CLEAR_ALL_PATTERNS,
232     // wxID_SAVE,
233     ID_SAVE_XRLE,
234     ID_RUN_SCRIPT,
235     ID_RUN_CLIP,
236     ID_RUN_RECENT,
237     // last 2 items in Run Recent submenu
238     ID_CLEAR_MISSING_SCRIPTS = ID_RUN_RECENT + MAX_RECENT + 1,
239     ID_CLEAR_ALL_SCRIPTS,
240     ID_SHOW_FILES,
241     ID_FILE_DIR,
242     // wxID_PREFERENCES,
243     // wxID_EXIT,
244 
245     // Edit menu
246     // due to wxMac bugs we don't use wxID_UNDO/REDO/CUT/COPY/CLEAR/PASTE/SELECTALL
247     // (problems occur when info window or a modal dialog is active, and we can't
248     // change the Undo/Redo menu labels)
249     ID_UNDO,
250     ID_REDO,
251     ID_CUT,
252     ID_COPY,
253     ID_NO_UNDO,
254     ID_CLEAR,
255     ID_OUTSIDE,
256     ID_PASTE,
257     ID_PMODE,
258     ID_PLOCATION,
259     ID_PASTE_SEL,
260     ID_SELECTALL,
261     ID_REMOVE,
262     ID_SHRINK,
263     ID_SHRINKFIT,  // there's currently no menu item for "Shrink and Fit"
264     ID_RANDOM,
265     ID_FLIPTB,
266     ID_FLIPLR,
267     ID_ROTATEC,
268     ID_ROTATEA,
269     ID_CMODE,
270 
271     // Paste Location submenu
272     ID_PL_TL,
273     ID_PL_TR,
274     ID_PL_BR,
275     ID_PL_BL,
276     ID_PL_MID,
277 
278     // Paste Mode submenu
279     ID_PM_AND,
280     ID_PM_COPY,
281     ID_PM_OR,
282     ID_PM_XOR,
283 
284     // Cursor Mode submenu
285     ID_DRAW,
286     ID_PICK,
287     ID_SELECT,
288     ID_MOVE,
289     ID_ZOOMIN,
290     ID_ZOOMOUT,
291 
292     // Control menu
293     ID_START,
294     ID_NEXT,
295     ID_STEP,
296     ID_RESET,
297     ID_SETGEN,
298     ID_FASTER,
299     ID_SLOWER,
300     ID_SETBASE,
301     ID_AUTO,
302     ID_HYPER,
303     ID_HINFO,
304     ID_SHOW_POP,
305     ID_RECORD,
306     ID_DELTIME,
307     ID_SETALGO,
308     ID_SETRULE,
309     ID_CONVERT,
310 
311     // Set Algorithm submenu
312     ID_ALGO0,
313     ID_ALGOMAX = ID_ALGO0 + MAX_ALGOS - 1,
314 
315     // View menu
316     ID_FULL,
317     ID_FIT,
318     ID_FIT_SEL,
319     ID_MIDDLE,
320     ID_RESTORE00,
321     // wxID_ZOOM_IN,
322     // wxID_ZOOM_OUT,
323     ID_SET_SCALE,
324     ID_TOOL_BAR,
325     ID_LAYER_BAR,
326     ID_EDIT_BAR,
327     ID_ALL_STATES,
328     ID_STATUS_BAR,
329     ID_EXACT,
330     ID_GRID,
331     ID_ICONS,
332     ID_INVERT,
333     ID_SMARTSCALE,
334     ID_TIMELINE,
335     ID_SCROLL,
336     ID_INFO,
337 
338     // Set Scale submenu
339     ID_SCALE_1,
340     ID_SCALE_2,
341     ID_SCALE_4,
342     ID_SCALE_8,
343     ID_SCALE_16,
344     ID_SCALE_32,
345 
346     // Layer menu
347     ID_SAVE_OVERLAY,
348     ID_SHOW_OVERLAY,
349     ID_DEL_OVERLAY,
350     ID_ADD_LAYER,
351     ID_CLONE,
352     ID_DUPLICATE,
353     ID_DEL_LAYER,
354     ID_DEL_OTHERS,
355     ID_MOVE_LAYER,
356     ID_NAME_LAYER,
357     ID_SET_COLORS,
358     ID_SYNC_VIEW,
359     ID_SYNC_CURS,
360     ID_STACK,
361     ID_TILE,
362     ID_LAYER0,
363     ID_LAYERMAX = ID_LAYER0 + MAX_LAYERS - 1,
364 
365     // Help menu
366     ID_HELP_INDEX,
367     ID_HELP_INTRO,
368     ID_HELP_TIPS,
369     ID_HELP_ALGOS,
370     ID_HELP_KEYBOARD,
371     ID_HELP_MOUSE,
372     ID_HELP_LUA,
373     ID_HELP_OVERLAY,
374     ID_HELP_PYTHON,
375     ID_HELP_LEXICON,
376     ID_HELP_ARCHIVES,
377     ID_HELP_FILE,
378     ID_HELP_EDIT,
379     ID_HELP_CONTROL,
380     ID_HELP_VIEW,
381     ID_HELP_LAYER,
382     ID_HELP_HELP,
383     ID_HELP_REFS,
384     ID_HELP_FORMATS,
385     ID_HELP_BOUNDED,
386     ID_HELP_PROBLEMS,
387     ID_HELP_CHANGES,
388     ID_HELP_CREDITS,
389 
390     // these ids aren't associated with any menu item
391     ID_LOAD_LEXICON,    // for loading a lexicon pattern
392     ID_HELP_BUTT,       // for help button in tool bar
393     ID_OPENTIMER,       // for opentimer
394     ID_GENTIMER         // for gentimer
395 };
396 
397 #endif
398