1 ///////////////////////////////////////////////////////////////////////////////
2 // Name:        MadEditFrame.h
3 // Description: Main frame of MadEdit
4 // Author:      madedit@gmail.com
5 // Licence:     GPL
6 ///////////////////////////////////////////////////////////////////////////////
7 
8 #ifndef _MADEDITFRAME_H_
9 #define _MADEDITFRAME_H_
10 
11 #include <wx/wxprec.h>
12 #ifdef __BORLANDC__
13         #pragma hdrstop
14 #endif
15 #ifndef WX_PRECOMP
16         #include <wx/wx.h>
17 #endif
18 
19 //Do not add custom headers.
20 //wx-dvcpp designer will remove them
21 ////Header Include Start
22 #include <wx/menu.h>
23 #include <wx/toolbar.h>
24 #include <wx/statusbr.h>
25 ////Header Include End
26 
27 #include <wx/frame.h>
28 #include <wx/docview.h>
29 #include <wx/fileconf.h>
30 #include <wx/hashset.h>
31 #include <wx/imaglist.h>
32 #include <wx/treectrl.h>
33 
34 #include <wx/aui/aui.h> // wxAUI
35 
36 
37 ////Dialog Style Start
38 #undef MadEditFrame_STYLE
39 #define MadEditFrame_STYLE wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX
40 ////Dialog Style End
41 
42 
43 class wxMadAuiNotebook;
44 class wxAuiNotebookEvent;
45 class MadEdit;
46 
47 class MadEditFrame : public wxFrame
48 {
49 private:
50     DECLARE_EVENT_TABLE()
51 public:
52     MadEditFrame( wxWindow *parent, wxWindowID id = 1, const wxString &title = wxT("MadEdit"),
53         const wxPoint& pos = wxDefaultPosition,
54         const wxSize& size = wxDefaultSize,
55         long style = MadEditFrame_STYLE);
56     virtual ~MadEditFrame();
57 public:
58   //Do not add custom Control Declarations here.
59   //wx-devcpp will remove them. Try adding the custom code
60   //after the block.
61   ////GUI Control Declaration Start
62 		wxMenuBar *WxMenuBar1;
63 		wxToolBar *WxToolBar1;
64 		wxStatusBar *WxStatusBar1;
65   ////GUI Control Declaration End
66 public:
67 	//Note: if you receive any error with these enums, then you need to
68     //change your old form code that are based on the #define control ids.
69 	//It may replace a numeric value in the enums names.
70 	enum {
71 ////GUI Enum Control ID Start
72 			ID_WXTOOLBAR1 = 1005,
73 			ID_WXSTATUSBAR1 = 1003,
74 ////GUI Enum Control ID End
75 
76     ID_NOTEBOOK, // for wxAuiNotebook m_Notebook
77     ID_OUTPUTNOTEBOOK,
78     ID_FINDINFILESRESULTS,
79 
80     ID_DUMMY_VALUE_ //Dont Delete this DummyValue
81    }; //End of Enum
82 
83 public:
84     wxMadAuiNotebook *m_Notebook;
85     int           m_NewFileCount;
86     wxConfigBase  *m_Config;
87     wxImageList   *m_ImageList;
88     wxFileHistory *m_RecentFiles;
89     wxFileHistory *m_RecentEncodings;
90     wxFileHistory *m_RecentFonts;
91 
92     wxAuiManager m_AuiManager; // wxAUI
93     wxAuiNotebook *m_InfoNotebook; //
94     wxTreeCtrl *m_FindInFilesResults;
95 
96     void OnUpdateUI_MenuFile_CheckCount(wxUpdateUIEvent& event);
97     void OnUpdateUI_MenuFileReload(wxUpdateUIEvent& event);
98     void OnUpdateUI_MenuFileRecentFiles(wxUpdateUIEvent& event);
99 
100     void OnUpdateUI_MenuEditUndo(wxUpdateUIEvent& event);
101     void OnUpdateUI_MenuEditRedo(wxUpdateUIEvent& event);
102     void OnUpdateUI_MenuEdit_CheckSelection(wxUpdateUIEvent& event);
103     void OnUpdateUI_MenuEdit_CheckSelSize(wxUpdateUIEvent& event);
104     void OnUpdateUI_MenuEditCopy(wxUpdateUIEvent& event);
105     void OnUpdateUI_MenuEditPaste(wxUpdateUIEvent& event);
106     void OnUpdateUI_Menu_CheckSize(wxUpdateUIEvent& event);
107     void OnUpdateUI_MenuEditDeleteLine(wxUpdateUIEvent& event);
108     void OnUpdateUI_MenuEditInsertTabChar(wxUpdateUIEvent& event);
109     void OnUpdateUI_MenuEditInsertDateTime(wxUpdateUIEvent& event);
110 
111     void OnUpdateUI_Menu_CheckTextFile(wxUpdateUIEvent& event);
112 
113     void OnUpdateUI_MenuEditCopyAsHexString(wxUpdateUIEvent& event);
114     void OnUpdateUI_MenuIndent(wxUpdateUIEvent& event);
115     void OnUpdateUI_MenuComment(wxUpdateUIEvent& event);
116 
117     void OnUpdateUI_MenuSearchGoTo(wxUpdateUIEvent& event);
118     void OnUpdateUI_MenuSearchGoToBrace(wxUpdateUIEvent& event);
119 
120     void OnUpdateUI_MenuViewEncoding(wxUpdateUIEvent& event);
121     void OnUpdateUI_MenuViewSyntax(wxUpdateUIEvent& event);
122     void OnUpdateUI_MenuViewFontName(wxUpdateUIEvent& event);
123     void OnUpdateUI_MenuViewFontSize(wxUpdateUIEvent& event);
124     void OnUpdateUI_MenuViewSetFont(wxUpdateUIEvent& event);
125     void OnUpdateUI_MenuViewFixedWidthMode(wxUpdateUIEvent& event);
126     void OnUpdateUI_MenuViewTabColumn(wxUpdateUIEvent& event);
127     void OnUpdateUI_MenuViewLineSpacing(wxUpdateUIEvent& event);
128     void OnUpdateUI_MenuViewNoWrap(wxUpdateUIEvent& event);
129     void OnUpdateUI_MenuViewWrapByWindow(wxUpdateUIEvent& event);
130     void OnUpdateUI_MenuViewWrapByColumn(wxUpdateUIEvent& event);
131     void OnUpdateUI_MenuViewDisplayLineNumber(wxUpdateUIEvent& event);
132     void OnUpdateUI_MenuViewShowEndOfLine(wxUpdateUIEvent& event);
133     void OnUpdateUI_MenuViewShowTabChar(wxUpdateUIEvent& event);
134     void OnUpdateUI_MenuViewShowSpaceChar(wxUpdateUIEvent& event);
135     void OnUpdateUI_MenuViewMarkActiveLine(wxUpdateUIEvent& event);
136     void OnUpdateUI_MenuViewMarkBracePair(wxUpdateUIEvent& event);
137     void OnUpdateUI_MenuViewTextMode(wxUpdateUIEvent& event);
138     void OnUpdateUI_MenuViewColumnMode(wxUpdateUIEvent& event);
139     void OnUpdateUI_MenuViewHexMode(wxUpdateUIEvent& event);
140 
141     void OnUpdateUI_MenuToolsByteOrderMark(wxUpdateUIEvent& event);
142     void OnUpdateUI_MenuToolsNewLineChar(wxUpdateUIEvent& event);
143     void OnUpdateUI_MenuToolsInsertNewLineChar(wxUpdateUIEvent& event);
144     void OnUpdateUI_MenuToolsConvertNL(wxUpdateUIEvent& event);
145     void OnUpdateUI_MenuToolsConvertEncoding(wxUpdateUIEvent& event);
146 
147     void OnUpdateUI_MenuWindow_CheckCount(wxUpdateUIEvent& event);
148 
149     void OnFileNew(wxCommandEvent& event);
150     void OnFileOpen(wxCommandEvent& event);
151     void OnFileSave(wxCommandEvent& event);
152     void OnFileSaveAs(wxCommandEvent& event);
153     void OnFileSaveAll(wxCommandEvent& event);
154     void OnFileReload(wxCommandEvent& event);
155     void OnFileClose(wxCommandEvent& event);
156     void OnFileCloseAll(wxCommandEvent& event);
157     void OnFilePageSetup(wxCommandEvent& event);
158     void OnFilePrintPreview(wxCommandEvent& event);
159     void OnFilePrint(wxCommandEvent& event);
160     void OnFileRecentFile(wxCommandEvent& event);
161     void OnFileExit(wxCommandEvent& event);
162 
163     void OnEditUndo(wxCommandEvent& event);
164     void OnEditRedo(wxCommandEvent& event);
165     void OnEditCut(wxCommandEvent& event);
166     void OnEditCopy(wxCommandEvent& event);
167     void OnEditPaste(wxCommandEvent& event);
168     void OnEditDelete(wxCommandEvent& event);
169     void OnEditCutLine(wxCommandEvent& event);
170     void OnEditDeleteLine(wxCommandEvent& event);
171     void OnEditSelectAll(wxCommandEvent& event);
172     void OnEditInsertTabChar(wxCommandEvent& event);
173     void OnEditInsertDateTime(wxCommandEvent& event);
174 
175     void OnEditSortAscending(wxCommandEvent& event);
176     void OnEditSortDescending(wxCommandEvent& event);
177     void OnEditSortAscendingCase(wxCommandEvent& event);
178     void OnEditSortDescendingCase(wxCommandEvent& event);
179     void OnEditSortByOptions(wxCommandEvent& event);
180     void OnEditSortOptions(wxCommandEvent& event);
181 
182     void OnEditCopyAsHexString(wxCommandEvent& event);
183     void OnEditCopyAsHexStringWithSpace(wxCommandEvent& event);
184     void OnEditIncIndent(wxCommandEvent& event);
185     void OnEditDecIndent(wxCommandEvent& event);
186     void OnEditComment(wxCommandEvent& event);
187     void OnEditUncomment(wxCommandEvent& event);
188     void OnEditWordWrapToNewLine(wxCommandEvent& event);
189     void OnEditNewLineToWordWrap(wxCommandEvent& event);
190     void OnEditToUpperCase(wxCommandEvent& event);
191     void OnEditToLowerCase(wxCommandEvent& event);
192     void OnEditInvertCase(wxCommandEvent& event);
193     void OnEditToHalfWidth(wxCommandEvent& event);
194     void OnEditToHalfWidthByOptions(wxCommandEvent& event);
195     void OnEditToFullWidth(wxCommandEvent& event);
196     void OnEditToFullWidthByOptions(wxCommandEvent& event);
197     void OnEditTabToSpace(wxCommandEvent& event);
198     void OnEditSpaceToTab(wxCommandEvent& event);
199     void OnEditTrimTrailingSpaces(wxCommandEvent& event);
200 
201     void OnSearchFind(wxCommandEvent& event);
202     void OnSearchFindNext(wxCommandEvent& event);
203     void OnSearchFindPrevious(wxCommandEvent& event);
204     void OnSearchReplace(wxCommandEvent& event);
205     void OnSearchFindInFiles(wxCommandEvent& event);
206     void OnSearchShowFindInFilesResults(wxCommandEvent& event);
207     void OnSearchGoToLine(wxCommandEvent& event);
208     void OnSearchGoToPosition(wxCommandEvent& event);
209     void OnSearchGoToLeftBrace(wxCommandEvent& event);
210     void OnSearchGoToRightBrace(wxCommandEvent& event);
211 
212     void OnViewEncoding(wxCommandEvent& event);
213     void OnViewRecentEncoding(wxCommandEvent& event);
214     void OnViewSyntax(wxCommandEvent& event);
215     void OnViewFontName(wxCommandEvent& event);
216     void OnViewRecentFont(wxCommandEvent& event);
217     void OnViewFontSize(wxCommandEvent& event);
218     void OnViewSetFont(wxCommandEvent& event);
219     void OnViewFixedWidthMode(wxCommandEvent& event);
220     void OnViewTabColumn(wxCommandEvent& event);
221     void OnViewLineSpacing(wxCommandEvent& event);
222     void OnViewNoWrap(wxCommandEvent& event);
223     void OnViewWrapByWindow(wxCommandEvent& event);
224     void OnViewWrapByColumn(wxCommandEvent& event);
225     void OnViewDisplayLineNumber(wxCommandEvent& event);
226     void OnViewShowEndOfLine(wxCommandEvent& event);
227     void OnViewShowTabChar(wxCommandEvent& event);
228     void OnViewShowSpaceChar(wxCommandEvent& event);
229     void OnViewMarkActiveLine(wxCommandEvent& event);
230     void OnViewMarkBracePair(wxCommandEvent& event);
231     void OnViewTextMode(wxCommandEvent& event);
232     void OnViewColumnMode(wxCommandEvent& event);
233     void OnViewHexMode(wxCommandEvent& event);
234 
235     void OnToolsOptions(wxCommandEvent& event);
236     void OnToolsHighlighting(wxCommandEvent& event);
237 #ifdef __WXMSW__
238     void OnToolsFileAssociation(wxCommandEvent& event);
239 #endif
240     void OnToolsToggleBOM(wxCommandEvent& event);
241     void OnToolsConvertToDOS(wxCommandEvent& event);
242     void OnToolsConvertToMAC(wxCommandEvent& event);
243     void OnToolsConvertToUNIX(wxCommandEvent& event);
244     void OnToolsInsertDOS(wxCommandEvent& event);
245     void OnToolsInsertMAC(wxCommandEvent& event);
246     void OnToolsInsertUNIX(wxCommandEvent& event);
247     void OnToolsConvertEncoding(wxCommandEvent& event);
248     void OnToolsSimp2TradChinese(wxCommandEvent& event);
249     void OnToolsTrad2SimpChinese(wxCommandEvent& event);
250     void OnToolsKanji2TradChinese(wxCommandEvent& event);
251     void OnToolsKanji2SimpChinese(wxCommandEvent& event);
252     void OnToolsChinese2Kanji(wxCommandEvent& event);
253     void OnToolsSimp2TradClipboard(wxCommandEvent& event);
254     void OnToolsTrad2SimpClipboard(wxCommandEvent& event);
255     void OnToolsKanji2TradClipboard(wxCommandEvent& event);
256     void OnToolsKanji2SimpClipboard(wxCommandEvent& event);
257     void OnToolsChinese2KanjiClipboard(wxCommandEvent& event);
258     void OnToolsWordCount(wxCommandEvent& event);
259 
260     void OnWindowToggleWindow(wxCommandEvent& event);
261     void OnWindowPreviousWindow(wxCommandEvent& event);
262     void OnWindowNextWindow(wxCommandEvent& event);
263 
264     void OnHelpAbout(wxCommandEvent& event);
265 
266 private:
267     bool m_PageClosing; // prevent from reentry of CloseFile(), OnNotebookPageClosing()
268 public:
269     int OpenedFileCount();
270     void OpenFile(const wxString &filename, bool mustExist); // if filename is empty, open a new file
271     void CloseFile(int pageId);
272     void CloseAllFiles(bool force);
273     void MadEditFrameKeyDown(wxKeyEvent& event);
274     void SetPageFocus(int pageId);
275     MadEdit *GetEditByFileName(const wxString &filename, int &id);
276     void ResetAcceleratorTable();
277 
278 protected:
279     void MadEditFrameClose(wxCloseEvent& event);
280     void CreateGUIControls(void);
281 
282 	void OnNotebookPageChanging(wxAuiNotebookEvent& event);
283     void OnNotebookPageChanged(wxAuiNotebookEvent& event);
284     void OnNotebookPageClosing(wxAuiNotebookEvent& event);
285     void OnNotebookPageClosed(bool bZeroPage=false);//wxAuiNotebookEvent& event); //wxAUI doesn't support this event
286 
287     void OnSize(wxSizeEvent &evt);
288     //void OnChar(wxKeyEvent& evt);
289     void OnActivate(wxActivateEvent &evt);
290 
291     bool QueryCloseFile(int idx);
292     bool QueryCloseAllFiles();
293 
294     void LoadMenuKeys(wxConfigBase *config);
295     wxString GetMenuKey(const wxString &menu, const wxString &defaultkey);
296 
297     void OnInfoNotebookSize(wxSizeEvent &evt);
298     void OnFindInFilesResultsDClick(wxMouseEvent& event);
299 
300 #ifdef __WXMSW__
301     WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
302 #endif
303 
304 public:
305     void ResetFindInFilesResults();
306     void AddItemToFindInFilesResults(const wxString &text, size_t index, const wxString &filename, int pageid, const wxFileOffset &begpos, wxFileOffset &endpos);
307 
308 };
309 
310 enum { // menu id
311     menuNew = wxID_NEW,
312     menuOpen = wxID_OPEN,
313     menuSave = wxID_SAVE,
314     menuSaveAs = wxID_SAVEAS,
315     menuClose = wxID_CLOSE,
316     menuCloseAll = wxID_CLOSE_ALL,
317     menuPageSetup = wxID_PRINT_SETUP,
318     menuPrintPreview = wxID_PREVIEW,
319     menuPrint = wxID_PRINT,
320     menuExit = wxID_EXIT,
321     menuUndo = wxID_UNDO,
322     menuRedo = wxID_REDO,
323     menuCut = wxID_CUT,
324     menuCopy = wxID_COPY,
325     menuPaste = wxID_PASTE,
326     menuDelete = wxID_DELETE,
327     menuSelectAll = wxID_SELECTALL,
328     menuFind = wxID_FIND,
329     menuReplace = wxID_REPLACE,
330     menuAbout = wxID_ABOUT,
331 
332     // file
333     menuSaveAll = 1100,
334     menuReload,
335     menuRecentFiles,
336 
337     // edit
338     menuCutLine,
339     menuDeleteLine,
340     menuInsertTabChar,
341     menuInsertDateTime,
342     menuSort,
343     menuSortAscending,
344     menuSortDescending,
345     menuSortAscendingCase,
346     menuSortDescendingCase,
347     menuSortByOptions,
348     menuSortOptions,
349     menuAdvanced,
350     menuCopyAsHexString,
351     menuCopyAsHexStringWithSpace,
352     menuIncreaseIndent,
353     menuDecreaseIndent,
354     menuComment,
355     menuUncomment,
356     menuWordWrapToNewLine,
357     menuNewLineToWordWrap,
358     menuToUpperCase,
359     menuToLowerCase,
360     menuInvertCase,
361     menuToHalfWidth,
362     menuToHalfWidthByOptions,
363     menuToFullWidth,
364     menuToFullWidthByOptions,
365     menuTabToSpace,
366     menuSpaceToTab,
367     menuTrimTrailingSpaces,
368 
369     // search
370     menuFindNext,
371     menuFindPrevious,
372     menuFindInFiles,
373     menuShowFindInFilesResults,
374     menuGoToLine,
375     menuGoToPosition,
376     menuLeftBrace,
377     menuRightBrace,
378 
379     // view
380     menuEncoding,
381     menuAllEncodings,
382     menuEncoding1,
383     menuEncoding99 = menuEncoding1 + 98,
384 
385     menuRecentEncoding1,
386     menuRecentEncoding9 = menuRecentEncoding1 + 8,
387 
388     menuSyntax,
389     menuSyntax1,
390     menuSyntax199 = menuSyntax1 + 198,
391 
392     menuFontName,
393     menuFontName1,
394     menuFontName999 = menuFontName1 + 998,
395 
396     menuFont0, //[@]
397     menuFont1, //[ABCDE]
398     menuFont2, //[FGHIJ]
399     menuFont3, //[KLMNO]
400     menuFont4, //[PQRST]
401     menuFont5, //[UVWXYZ]
402     menuFont6, //[Other]
403 
404     menuRecentFonts,
405     menuRecentFont1,
406     menuRecentFont9 = menuRecentFont1 + 8,
407 
408     menuFontSize,
409     menuFontSize1,
410     menuFontSize99 = menuFontSize1 + 98,
411 
412     menuSetFont,
413     menuFixedWidthMode,
414 
415     menuTabColumn,
416     menuTabColumn1,
417     menuTabColumn16 = menuTabColumn1 + 15,
418 
419     menuLineSpacing,
420     menuLineSpacing100,
421     menuLineSpacing250 = menuLineSpacing100 + 30,
422 
423     menuNoWrap,
424     menuWrapByWindow,
425     menuWrapByColumn,
426     menuDisplayLineNumber,
427     menuShowEndOfLine,
428     menuShowTabChar,
429     menuShowSpaceChar,
430     menuMarkActiveLine,
431     menuMarkBracePair,
432     menuTextMode,
433     menuColumnMode,
434     menuHexMode,
435 
436     // tools
437     menuOptions,
438     menuHighlighting,
439 #ifdef __WXMSW__
440     menuFileAssociation,
441 #endif
442     menuPlugins,
443     menuByteOrderMark,
444     menuToggleBOM,
445     menuNewLineChar,
446     menuConvertToDOS,
447     menuConvertToMAC,
448     menuConvertToUNIX,
449     menuInsertNewLineChar,
450     menuInsertDOS,
451     menuInsertMAC,
452     menuInsertUNIX,
453     menuConvertEncoding,
454     menuConvertChineseChar,
455     menuSimp2TradChinese,
456     menuTrad2SimpChinese,
457     menuKanji2TradChinese,
458     menuKanji2SimpChinese,
459     menuChinese2Kanji,
460     menuSimp2TradClipboard,
461     menuTrad2SimpClipboard,
462     menuKanji2TradClipboard,
463     menuKanji2SimpClipboard,
464     menuChinese2KanjiClipboard,
465     menuWordCount,
466 
467     // window
468     menuToggleWindow,
469     menuPreviousWindow,
470     menuNextWindow
471 };
472 
473 extern MadEditFrame *g_MainFrame;
474 extern void OnReceiveMessage(const wchar_t *msg, size_t size);
475 
476 #endif
477 
478