5 * Created by Toshi Nagata on 08/10/24.
6 * Copyright 2008 Toshi Nagata. All rights reserved.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation version 2 of the License.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
23 #include "wx/docview.h"
24 #include "wx/docmdi.h"
25 #include "wx/hashmap.h"
26 #include "wx/process.h"
29 #if defined(__WXMSW__)
30 #include "wx/snglinst.h"
33 #include "MyDocManager.h"
37 #if defined(__WXMSW__)
44 class wxProgressDialog;
48 class GlobalParameterFrame;
49 class GlobalParameterFilesFrame;
53 #if defined(__WXOSX_COCOA__)
54 #define wxTOGGLEBUTTON_STYLE wxBORDER_SIMPLE
56 #define wxTOGGLEBUTTON_STYLE 0
59 #if wxCHECK_VERSION(3,1,0)
60 #define FromFrameDIP(frame, x) frame->FromDIP(x)
61 #define ToFrameDIP(frame, x) frame->ToDIP(x)
63 #define FromFrameDIP(frame, x) (x)
64 #define ToFrameDIP(frame, x) (x)
67 #define FromDCDIP FromFrameDIP
68 #define ToDCDIP ToFrameDIP
71 myMenuID_MyFirstMenuItem = 12000,
72 myMenuID_Import = 12001,
73 myMenuID_Export = 12002,
74 myMenuID_ExportGraphic = 12003,
75 myMenuID_SelectFragment = 12004,
76 myMenuID_SelectReverse = 12005,
78 myMenuID_CreateNewAtom = 12010,
79 myMenuID_CreateNewParameter = 12011,
80 myMenuID_CreateNewVdwParameter = 12012,
81 myMenuID_CreateNewBondParameter = 12013,
82 myMenuID_CreateNewAngleParameter = 12014,
83 myMenuID_CreateNewDihedralParameter = 12015,
84 myMenuID_CreateNewImproperParameter = 12016,
85 myMenuID_CreateNewVdwPairParameter = 12017,
86 myMenuID_CreateNewVdwCutoffParameter = 12018,
87 myMenuID_CreatePiAnchor = 12019,
89 myMenuID_AddHydrogen = 12030,
90 myMenuID_AddHydrogenSp3 = 12031,
91 myMenuID_AddHydrogenSp2 = 12032,
92 myMenuID_AddHydrogenLinear = 12033,
93 myMenuID_AddHydrogenPyramidal = 12034,
94 myMenuID_AddHydrogenBent = 12035,
96 myMenuID_FitToScreen = 12050,
97 myMenuID_CenterSelection = 12051,
99 myMenuID_ShowAllAtoms = 12060,
100 myMenuID_HideSelected = 12061,
101 myMenuID_HideUnselected = 12062,
102 myMenuID_HideReverse = 12063,
104 myMenuID_MolecularDynamics = 12070,
105 myMenuID_Minimize = 12071,
106 myMenuID_StopMDRun = 12072,
108 myMenuID_ViewGlobalParameters = 12080,
109 myMenuID_ViewParameterFilesList = 12081,
111 myMenuID_BringAllWindowsToFront = 12090,
113 myMenuID_ExecuteScript = 12100,
114 myMenuID_OpenConsoleWindow = 12101,
115 myMenuID_EmptyConsoleWindow = 12102,
117 myMenuID_PredefinedFragment = 12200,
118 myMenuID_MyLastFragment = 12999,
120 // The ID of script menu has "1000 * depth" offset
121 myMenuID_CustomScript = 13000,
123 myMenuID_MyLastMenuItem = 29999,
125 myMenuID_Internal_CheckIfAllWindowsAreGone = 30000
129 myMenuIndex_File = 0,
130 myMenuIndex_Edit = 1,
131 myMenuIndex_Show = 2,
132 myMenuIndex_MMMD = 3,
133 myMenuIndex_Script = 4
136 // Global Setting Keys
137 extern const char *gSettingQuitOnCloseLastWindow;
139 WX_DECLARE_STRING_HASH_MAP( wxString, MyStringHash );
141 // A support class for wxProcess
142 // When the process terminates, the exit status is kept inside the object
143 class wxBetterProcess : public wxProcess
146 wxBetterProcess(wxEvtHandler *parent, int id) : wxProcess(parent, id)
149 m_terminated = false;
150 m_killSignal = wxSIGNONE;
152 wxBetterProcess(int flags) : wxProcess(flags)
155 m_terminated = false;
156 m_killSignal = wxSIGNONE;
158 virtual ~wxBetterProcess() {}
159 virtual void OnTerminate(int pid, int status);
160 wxKillError KillProcess(wxSignal sig = wxSIGTERM, int flags = wxKILL_NOCHILDREN);
161 int PutLine(wxString str);
162 int GetLine(wxString &outStr);
163 int GetLineSub(wxString &outStr, wxInputStream *stream, wxMemoryBuffer &mbuf);
164 int GetErrorLine(wxString &outStr);
166 bool IsTerminated() { return m_terminated; }
167 int GetStatus() { return m_status; }
168 int GetKillSignal() { return m_killSignal; }
173 wxMemoryBuffer m_stdout;
174 wxMemoryBuffer m_stderr;
175 wxMemoryBuffer m_stdin;
178 #if wxCHECK_VERSION(3,1,0)
179 #define wxExecuteArgv(_argv, _flags, _process) wxExecute(_argv, _flags, _process)
181 #define wxExecuteArgv(_argv, _flags, _process) wxExecute((char **)(_argv), _flags, _process)
184 // Define a new application
185 class MyApp: public wxApp
189 virtual bool Initialize(int& argc, wxChar **argv);
193 ConsoleFrame *GetConsoleFrame() { return consoleFrame; }
195 void ShowProgressPanel(const char *mes);
196 void HideProgressPanel();
197 void SetProgressValue(double dval);
198 void SetProgressMessage(const char *mes);
200 // ProgressFrame *GetProgressFrame() { return m_progressFrame; }
202 MyDocManager *DocManager() { return m_docManager; }
204 wxMenuBar *CreateMenuBar(int kind, wxMenu **out_file_history_menu = NULL, wxMenu **out_edit_menu = NULL);
206 wxString InitResourcePath(int& argc, wxChar **argv);
208 static wxString FindResourcePath();
209 static wxString DefaultSettingsPath();
211 void LoadDefaultSettings();
212 void SaveDefaultSettings();
213 void SetDefaultSetting(const wxString& key, const wxString& value);
214 wxString& GetDefaultSetting(const wxString& key);
216 int LookupScriptMenu(const char *title);
217 int RegisterScriptMenu(const char *title);
218 void UpdateScriptMenu(wxMenuBar *mbar);
219 void OnScriptMenuModified(wxCommandEvent& event);
220 void OnScriptMenuSelected(wxCommandEvent& event);
221 void UpdatePredefinedFragmentMenu(wxMenuBar *mbar);
222 void OnFragmentMenuSelected(wxCommandEvent& event);
224 void OnUpdateUI(wxUpdateUIEvent &event);
225 void OnExecuteScript(wxCommandEvent &event);
226 void OnOpenConsoleWindow(wxCommandEvent &event);
227 void OnEmptyConsoleWindow(wxCommandEvent &event);
228 void OnViewGlobalParameters(wxCommandEvent &event);
229 void OnViewParameterFilesList(wxCommandEvent &event);
230 void OnBringAllWindowsToFront(wxCommandEvent &event);
232 // void OnEndProcess(wxProcessEvent &event);
233 int CallSubProcess(const char **argv, const char *procname, int (*callback)(void *) = NULL, void *callback_data = NULL, FILE *fpout = NULL, FILE *fperr = NULL, int *exitstatus_p = NULL, int *pid_p = NULL);
235 void OnActivate(wxActivateEvent &event);
237 void RequestOpenFilesByEvent(wxString& files);
238 void OnOpenFilesByEvent(wxCommandEvent& event);
240 bool OnOpenFiles(const wxString &files);
242 MyListCtrl *GetGlobalParameterListCtrl();
244 #if defined(__WXMAC__)
245 virtual void MacNewFile();
246 virtual void MacOpenFile(const wxString &fileName);
247 virtual void MacOpenFiles(const wxArrayString &fileNames);
250 void EnableTimerForDocument(MyDocument *doc);
251 void DisableTimerForDocument(MyDocument *doc);
252 void TimerInvoked(wxTimerEvent &event);
254 void CheckIfAllWindowsAreGoneHandler(wxCommandEvent &event);
255 void CheckIfAllWindowsAreGone(wxTopLevelWindow *frame);
257 void OnHelp(wxCommandEvent& event);
259 int FilterEvent(wxEvent &event);
262 MyDocManager* m_docManager;
263 wxProgressDialog *m_progressDialog;
264 // bool m_progressCanceled;
265 // int m_progressValue;
266 MyStringHash m_defaultSettings;
268 // For CallSubProcess()
269 wxBetterProcess *m_process;
270 // bool m_processTerminated;
271 // int m_processExitCode;
273 ConsoleFrame *consoleFrame;
274 GlobalParameterFrame *parameterFrame;
275 GlobalParameterFilesFrame *parameterFilesFrame;
277 int countNonCustomScriptMenu;
279 char **scriptMenuTitles;
280 int *scriptMenuPositions;
281 bool scriptMenuModifiedEventPosted;
283 int m_CountNamedFragments;
284 char **m_NamedFragments;
286 int m_CountTimerDocs;
287 MyDocument **m_TimerDocs;
290 wxString *m_pendingFilesToOpen; /* Files to be processed by OnOpenFilesByEvent() */
292 wxTopLevelWindow *m_frameToBeDestroyed; /* Used in CheckIfAllWindowsAreGone() */
294 wxString m_resourcePath;
296 #if defined(__WXMSW__)
298 wxSingleInstanceChecker *m_checker;
299 wxString *m_ipcServiceName;
305 DECLARE_EVENT_TABLE()
311 class AboutDialog: public wxDialog
313 DECLARE_CLASS(AboutDialog)
316 void OnOKPressed(wxCommandEvent &event);
318 DECLARE_EVENT_TABLE()
321 // Define a new frame
322 class MyFrame: public wxDocParentFrame
324 DECLARE_CLASS(MyFrame)
328 MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size, long type);
330 void OnAbout(wxCommandEvent& event);
333 DECLARE_EVENT_TABLE()
336 extern MyFrame *GetMainFrame(void);
337 extern bool singleWindowMode;
339 #endif /* __MyApp_H__ */