]>
Commit | Line | Data |
---|---|---|
1 | ////////////////////////////////////////////////////////////////////////////// | |
2 | // File: stctest.cpp | |
3 | // Purpose: STC test application | |
4 | // Maintainer: Otto Wyss | |
5 | // Created: 2003-09-01 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) wxGuide | |
8 | // Licence: wxWindows licence | |
9 | ////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | //---------------------------------------------------------------------------- | |
12 | // headers | |
13 | //---------------------------------------------------------------------------- | |
14 | ||
15 | // For compilers that support precompilation, includes <wx/wx.h>. | |
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
22 | // for all others, include the necessary headers (this file is usually all you | |
23 | // need because it includes almost all 'standard' wxWidgets headers) | |
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/wx.h" | |
26 | #endif | |
27 | ||
28 | //! wxWidgets headers | |
29 | #include "wx/config.h" // configuration support | |
30 | #include "wx/filedlg.h" // file dialog support | |
31 | #include "wx/filename.h" // filename support | |
32 | #include "wx/notebook.h" // notebook support | |
33 | #include "wx/settings.h" // system settings | |
34 | #include "wx/string.h" // strings support | |
35 | #include "wx/image.h" // images support | |
36 | ||
37 | //! application headers | |
38 | #include "defsext.h" // Additional definitions | |
39 | #include "edit.h" // Edit module | |
40 | #include "prefs.h" // Prefs | |
41 | ||
42 | ||
43 | //---------------------------------------------------------------------------- | |
44 | // resources | |
45 | //---------------------------------------------------------------------------- | |
46 | ||
47 | // the application icon (under Windows and OS/2 it is in resources) | |
48 | #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__) | |
49 | #include "mondrian.xpm" | |
50 | #endif | |
51 | ||
52 | //============================================================================ | |
53 | // declarations | |
54 | //============================================================================ | |
55 | ||
56 | #define APP_NAME _T("STC-Test") | |
57 | #define APP_DESCR _("See http://wxguide.sourceforge.net/") | |
58 | ||
59 | #define APP_MAINT _T("Otto Wyss") | |
60 | #define APP_VENDOR _T("wxWidgets") | |
61 | #define APP_COPYRIGTH _T("(C) 2003 Otto Wyss") | |
62 | #define APP_LICENCE _T("wxWidgets") | |
63 | ||
64 | #define APP_VERSION _T("0.1.alpha") | |
65 | #define APP_BUILD __DATE__ | |
66 | ||
67 | #define APP_WEBSITE _T("http://www.wxWidgets.org") | |
68 | #define APP_MAIL _T("mailto://???") | |
69 | ||
70 | #define NONAME _("<untitled>") | |
71 | ||
72 | class AppBook; | |
73 | ||
74 | ||
75 | //---------------------------------------------------------------------------- | |
76 | //! global application name | |
77 | wxString *g_appname = NULL; | |
78 | ||
79 | #if wxUSE_PRINTING_ARCHITECTURE | |
80 | ||
81 | //! global print data, to remember settings during the session | |
82 | wxPrintData *g_printData = (wxPrintData*) NULL; | |
83 | wxPageSetupData *g_pageSetupData = (wxPageSetupData*) NULL; | |
84 | ||
85 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
86 | ||
87 | ||
88 | //---------------------------------------------------------------------------- | |
89 | //! application APP_VENDOR-APP_NAME. | |
90 | class App: public wxApp { | |
91 | friend class AppFrame; | |
92 | ||
93 | public: | |
94 | //! the main function called durning application start | |
95 | virtual bool OnInit (); | |
96 | ||
97 | //! application exit function | |
98 | virtual int OnExit (); | |
99 | ||
100 | private: | |
101 | //! frame window | |
102 | AppFrame* m_frame; | |
103 | ||
104 | }; | |
105 | ||
106 | // created dynamically by wxWidgets | |
107 | DECLARE_APP (App); | |
108 | ||
109 | //---------------------------------------------------------------------------- | |
110 | //! frame of the application APP_VENDOR-APP_NAME. | |
111 | class AppFrame: public wxFrame { | |
112 | friend class App; | |
113 | friend class AppBook; | |
114 | friend class AppAbout; | |
115 | ||
116 | public: | |
117 | //! constructor | |
118 | AppFrame (const wxString &title); | |
119 | ||
120 | //! destructor | |
121 | ~AppFrame (); | |
122 | ||
123 | //! event handlers | |
124 | //! common | |
125 | void OnClose (wxCloseEvent &event); | |
126 | void OnAbout (wxCommandEvent &event); | |
127 | void OnExit (wxCommandEvent &event); | |
128 | void OnTimerEvent (wxTimerEvent &event); | |
129 | //! file | |
130 | void OnFileNew (wxCommandEvent &event); | |
131 | void OnFileNewFrame (wxCommandEvent &event); | |
132 | void OnFileOpen (wxCommandEvent &event); | |
133 | void OnFileOpenFrame (wxCommandEvent &event); | |
134 | void OnFileSave (wxCommandEvent &event); | |
135 | void OnFileSaveAs (wxCommandEvent &event); | |
136 | void OnFileClose (wxCommandEvent &event); | |
137 | //! properties | |
138 | void OnProperties (wxCommandEvent &event); | |
139 | ||
140 | void OnPrintSetup (wxCommandEvent &event); | |
141 | void OnPrintPreview (wxCommandEvent &event); | |
142 | void OnPrint (wxCommandEvent &event); | |
143 | //! edit events | |
144 | void OnEdit (wxCommandEvent &event); | |
145 | ||
146 | private: | |
147 | // edit object | |
148 | Edit *m_edit; | |
149 | void FileOpen (wxString fname); | |
150 | ||
151 | //! creates the application menu bar | |
152 | wxMenuBar *m_menuBar; | |
153 | void CreateMenu (); | |
154 | ||
155 | // print preview position and size | |
156 | wxRect DeterminePrintSize (); | |
157 | ||
158 | DECLARE_EVENT_TABLE() | |
159 | }; | |
160 | ||
161 | //---------------------------------------------------------------------------- | |
162 | //! about box of the application APP_VENDOR-APP_NAME | |
163 | class AppAbout: public wxDialog { | |
164 | ||
165 | public: | |
166 | //! constructor | |
167 | AppAbout (wxWindow *parent, | |
168 | int milliseconds = 0, | |
169 | long style = 0); | |
170 | ||
171 | //! destructor | |
172 | ~AppAbout (); | |
173 | ||
174 | // event handlers | |
175 | void OnTimerEvent (wxTimerEvent &event); | |
176 | ||
177 | private: | |
178 | // timer | |
179 | wxTimer *m_timer; | |
180 | ||
181 | DECLARE_EVENT_TABLE() | |
182 | }; | |
183 | ||
184 | ||
185 | //============================================================================ | |
186 | // implementation | |
187 | //============================================================================ | |
188 | ||
189 | IMPLEMENT_APP (App) | |
190 | ||
191 | //---------------------------------------------------------------------------- | |
192 | // App | |
193 | //---------------------------------------------------------------------------- | |
194 | ||
195 | bool App::OnInit () { | |
196 | ||
197 | wxInitAllImageHandlers(); | |
198 | ||
199 | // set application and vendor name | |
200 | SetAppName (APP_NAME); | |
201 | SetVendorName (APP_VENDOR); | |
202 | g_appname = new wxString (); | |
203 | g_appname->Append (APP_VENDOR); | |
204 | g_appname->Append (_T("-")); | |
205 | g_appname->Append (APP_NAME); | |
206 | ||
207 | #if wxUSE_PRINTING_ARCHITECTURE | |
208 | // initialize print data and setup | |
209 | g_printData = new wxPrintData; | |
210 | g_pageSetupData = new wxPageSetupDialogData; | |
211 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
212 | ||
213 | // create application frame | |
214 | m_frame = new AppFrame (*g_appname); | |
215 | ||
216 | // open application frame | |
217 | m_frame->Layout (); | |
218 | m_frame->Show (true); | |
219 | SetTopWindow (m_frame); | |
220 | ||
221 | return true; | |
222 | } | |
223 | ||
224 | int App::OnExit () { | |
225 | ||
226 | // delete global appname | |
227 | delete g_appname; | |
228 | ||
229 | #if wxUSE_PRINTING_ARCHITECTURE | |
230 | // delete global print data and setup | |
231 | if (g_printData) delete g_printData; | |
232 | if (g_pageSetupData) delete g_pageSetupData; | |
233 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
234 | ||
235 | return 0; | |
236 | } | |
237 | ||
238 | //---------------------------------------------------------------------------- | |
239 | // AppFrame | |
240 | //---------------------------------------------------------------------------- | |
241 | ||
242 | BEGIN_EVENT_TABLE (AppFrame, wxFrame) | |
243 | // common | |
244 | EVT_CLOSE ( AppFrame::OnClose) | |
245 | // file | |
246 | EVT_MENU (wxID_OPEN, AppFrame::OnFileOpen) | |
247 | EVT_MENU (wxID_SAVE, AppFrame::OnFileSave) | |
248 | EVT_MENU (wxID_SAVEAS, AppFrame::OnFileSaveAs) | |
249 | EVT_MENU (wxID_CLOSE, AppFrame::OnFileClose) | |
250 | // properties | |
251 | EVT_MENU (myID_PROPERTIES, AppFrame::OnProperties) | |
252 | // print and exit | |
253 | EVT_MENU (wxID_PRINT_SETUP, AppFrame::OnPrintSetup) | |
254 | EVT_MENU (wxID_PREVIEW, AppFrame::OnPrintPreview) | |
255 | EVT_MENU (wxID_PRINT, AppFrame::OnPrint) | |
256 | EVT_MENU (wxID_EXIT, AppFrame::OnExit) | |
257 | // edit | |
258 | EVT_MENU (wxID_CLEAR, AppFrame::OnEdit) | |
259 | EVT_MENU (wxID_CUT, AppFrame::OnEdit) | |
260 | EVT_MENU (wxID_COPY, AppFrame::OnEdit) | |
261 | EVT_MENU (wxID_PASTE, AppFrame::OnEdit) | |
262 | EVT_MENU (myID_INDENTINC, AppFrame::OnEdit) | |
263 | EVT_MENU (myID_INDENTRED, AppFrame::OnEdit) | |
264 | EVT_MENU (wxID_SELECTALL, AppFrame::OnEdit) | |
265 | EVT_MENU (myID_SELECTLINE, AppFrame::OnEdit) | |
266 | EVT_MENU (wxID_REDO, AppFrame::OnEdit) | |
267 | EVT_MENU (wxID_UNDO, AppFrame::OnEdit) | |
268 | // find | |
269 | EVT_MENU (wxID_FIND, AppFrame::OnEdit) | |
270 | EVT_MENU (myID_FINDNEXT, AppFrame::OnEdit) | |
271 | EVT_MENU (myID_REPLACE, AppFrame::OnEdit) | |
272 | EVT_MENU (myID_REPLACENEXT, AppFrame::OnEdit) | |
273 | EVT_MENU (myID_BRACEMATCH, AppFrame::OnEdit) | |
274 | EVT_MENU (myID_GOTO, AppFrame::OnEdit) | |
275 | // view | |
276 | EVT_MENU_RANGE (myID_HILIGHTFIRST, myID_HILIGHTLAST, | |
277 | AppFrame::OnEdit) | |
278 | EVT_MENU (myID_DISPLAYEOL, AppFrame::OnEdit) | |
279 | EVT_MENU (myID_INDENTGUIDE, AppFrame::OnEdit) | |
280 | EVT_MENU (myID_LINENUMBER, AppFrame::OnEdit) | |
281 | EVT_MENU (myID_LONGLINEON, AppFrame::OnEdit) | |
282 | EVT_MENU (myID_WHITESPACE, AppFrame::OnEdit) | |
283 | EVT_MENU (myID_FOLDTOGGLE, AppFrame::OnEdit) | |
284 | EVT_MENU (myID_OVERTYPE, AppFrame::OnEdit) | |
285 | EVT_MENU (myID_READONLY, AppFrame::OnEdit) | |
286 | EVT_MENU (myID_WRAPMODEON, AppFrame::OnEdit) | |
287 | // extra | |
288 | EVT_MENU (myID_CHANGELOWER, AppFrame::OnEdit) | |
289 | EVT_MENU (myID_CHANGEUPPER, AppFrame::OnEdit) | |
290 | EVT_MENU (myID_CONVERTCR, AppFrame::OnEdit) | |
291 | EVT_MENU (myID_CONVERTCRLF, AppFrame::OnEdit) | |
292 | EVT_MENU (myID_CONVERTLF, AppFrame::OnEdit) | |
293 | EVT_MENU (myID_CHARSETANSI, AppFrame::OnEdit) | |
294 | EVT_MENU (myID_CHARSETMAC, AppFrame::OnEdit) | |
295 | // help | |
296 | EVT_MENU (wxID_ABOUT, AppFrame::OnAbout) | |
297 | END_EVENT_TABLE () | |
298 | ||
299 | AppFrame::AppFrame (const wxString &title) | |
300 | : wxFrame ((wxFrame *)NULL, wxID_ANY, title, wxDefaultPosition, wxSize(750,550), | |
301 | wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) { | |
302 | ||
303 | // intitialize important variables | |
304 | m_edit = NULL; | |
305 | ||
306 | // set icon and background | |
307 | SetTitle (*g_appname); | |
308 | SetIcon (wxICON (mondrian)); | |
309 | SetBackgroundColour (_T("WHITE")); | |
310 | ||
311 | // about box shown for 1 seconds | |
312 | AppAbout dlg(this, 1000); | |
313 | ||
314 | // create menu | |
315 | m_menuBar = new wxMenuBar; | |
316 | CreateMenu (); | |
317 | ||
318 | // open first page | |
319 | m_edit = new Edit (this, wxID_ANY); | |
320 | m_edit->SetFocus(); | |
321 | ||
322 | FileOpen (_T("stctest.cpp")); | |
323 | } | |
324 | ||
325 | AppFrame::~AppFrame () { | |
326 | } | |
327 | ||
328 | // common event handlers | |
329 | void AppFrame::OnClose (wxCloseEvent &event) { | |
330 | wxCommandEvent evt; | |
331 | OnFileClose (evt); | |
332 | if (m_edit && m_edit->Modified()) { | |
333 | if (event.CanVeto()) event.Veto (true); | |
334 | return; | |
335 | } | |
336 | Destroy(); | |
337 | } | |
338 | ||
339 | void AppFrame::OnAbout (wxCommandEvent &WXUNUSED(event)) { | |
340 | AppAbout dlg(this); | |
341 | } | |
342 | ||
343 | void AppFrame::OnExit (wxCommandEvent &WXUNUSED(event)) { | |
344 | Close (true); | |
345 | } | |
346 | ||
347 | // file event handlers | |
348 | void AppFrame::OnFileOpen (wxCommandEvent &WXUNUSED(event)) { | |
349 | if (!m_edit) return; | |
350 | #if wxUSE_FILEDLG | |
351 | wxString fname; | |
352 | wxFileDialog dlg (this, _T("Open file"), wxEmptyString, wxEmptyString, _T("Any file (*)|*"), | |
353 | wxOPEN | wxFILE_MUST_EXIST | wxCHANGE_DIR); | |
354 | if (dlg.ShowModal() != wxID_OK) return; | |
355 | fname = dlg.GetPath (); | |
356 | FileOpen (fname); | |
357 | #endif // wxUSE_FILEDLG | |
358 | } | |
359 | ||
360 | void AppFrame::OnFileSave (wxCommandEvent &WXUNUSED(event)) { | |
361 | if (!m_edit) return; | |
362 | if (!m_edit->Modified()) { | |
363 | wxMessageBox (_("There is nothing to save!"), _("Save file"), | |
364 | wxOK | wxICON_EXCLAMATION); | |
365 | return; | |
366 | } | |
367 | m_edit->SaveFile (); | |
368 | } | |
369 | ||
370 | void AppFrame::OnFileSaveAs (wxCommandEvent &WXUNUSED(event)) { | |
371 | if (!m_edit) return; | |
372 | #if wxUSE_FILEDLG | |
373 | wxString filename = wxEmptyString; | |
374 | wxFileDialog dlg (this, _T("Save file"), wxEmptyString, wxEmptyString, _T("Any file (*)|*"), wxSAVE|wxOVERWRITE_PROMPT); | |
375 | if (dlg.ShowModal() != wxID_OK) return; | |
376 | filename = dlg.GetPath(); | |
377 | m_edit->SaveFile (filename); | |
378 | #endif // wxUSE_FILEDLG | |
379 | } | |
380 | ||
381 | void AppFrame::OnFileClose (wxCommandEvent &WXUNUSED(event)) { | |
382 | if (!m_edit) return; | |
383 | if (m_edit->Modified()) { | |
384 | if (wxMessageBox (_("Text is not saved, save before closing?"), _("Close"), | |
385 | wxYES_NO | wxICON_QUESTION) == wxYES) { | |
386 | m_edit->SaveFile(); | |
387 | if (m_edit->Modified()) { | |
388 | wxMessageBox (_("Text could not be saved!"), _("Close abort"), | |
389 | wxOK | wxICON_EXCLAMATION); | |
390 | return; | |
391 | } | |
392 | } | |
393 | } | |
394 | m_edit->SetFilename (wxEmptyString); | |
395 | m_edit->ClearAll(); | |
396 | m_edit->SetSavePoint(); | |
397 | } | |
398 | ||
399 | // properties event handlers | |
400 | void AppFrame::OnProperties (wxCommandEvent &WXUNUSED(event)) { | |
401 | if (!m_edit) return; | |
402 | EditProperties dlg(m_edit, 0); | |
403 | } | |
404 | ||
405 | // print event handlers | |
406 | void AppFrame::OnPrintSetup (wxCommandEvent &WXUNUSED(event)) { | |
407 | #if wxUSE_PRINTING_ARCHITECTURE | |
408 | (*g_pageSetupData) = * g_printData; | |
409 | wxPageSetupDialog pageSetupDialog(this, g_pageSetupData); | |
410 | pageSetupDialog.ShowModal(); | |
411 | (*g_printData) = pageSetupDialog.GetPageSetupData().GetPrintData(); | |
412 | (*g_pageSetupData) = pageSetupDialog.GetPageSetupData(); | |
413 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
414 | } | |
415 | ||
416 | void AppFrame::OnPrintPreview (wxCommandEvent &WXUNUSED(event)) { | |
417 | #if wxUSE_PRINTING_ARCHITECTURE | |
418 | wxPrintDialogData printDialogData( *g_printData); | |
419 | wxPrintPreview *preview = | |
420 | new wxPrintPreview (new EditPrint (m_edit), | |
421 | new EditPrint (m_edit), | |
422 | &printDialogData); | |
423 | if (!preview->Ok()) { | |
424 | delete preview; | |
425 | wxMessageBox (_("There was a problem with previewing.\n\ | |
426 | Perhaps your current printer is not correctly?"), | |
427 | _("Previewing"), wxOK); | |
428 | return; | |
429 | } | |
430 | wxRect rect = DeterminePrintSize(); | |
431 | wxPreviewFrame *frame = new wxPreviewFrame (preview, this, _("Print Preview")); | |
432 | frame->SetSize (rect); | |
433 | frame->Centre(wxBOTH); | |
434 | frame->Initialize(); | |
435 | frame->Show(true); | |
436 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
437 | } | |
438 | ||
439 | void AppFrame::OnPrint (wxCommandEvent &WXUNUSED(event)) { | |
440 | #if wxUSE_PRINTING_ARCHITECTURE | |
441 | wxPrintDialogData printDialogData( *g_printData); | |
442 | wxPrinter printer (&printDialogData); | |
443 | EditPrint printout (m_edit); | |
444 | if (!printer.Print (this, &printout, true)) { | |
445 | if (wxPrinter::GetLastError() == wxPRINTER_ERROR) { | |
446 | wxMessageBox (_("There was a problem with printing.\n\ | |
447 | Perhaps your current printer is not correctly?"), | |
448 | _("Previewing"), wxOK); | |
449 | return; | |
450 | } | |
451 | } | |
452 | (*g_printData) = printer.GetPrintDialogData().GetPrintData(); | |
453 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
454 | } | |
455 | ||
456 | // edit events | |
457 | void AppFrame::OnEdit (wxCommandEvent &event) { | |
458 | if (m_edit) m_edit->ProcessEvent (event); | |
459 | } | |
460 | ||
461 | // private functions | |
462 | void AppFrame::CreateMenu () | |
463 | { | |
464 | // File menu | |
465 | wxMenu *menuFile = new wxMenu; | |
466 | menuFile->Append (wxID_OPEN, _("&Open ..\tCtrl+O")); | |
467 | menuFile->Append (wxID_SAVE, _("&Save\tCtrl+S")); | |
468 | menuFile->Append (wxID_SAVEAS, _("Save &as ..\tCtrl+Shift+S")); | |
469 | menuFile->Append (wxID_CLOSE, _("&Close\tCtrl+W")); | |
470 | menuFile->AppendSeparator(); | |
471 | menuFile->Append (myID_PROPERTIES, _("Proper&ties ..\tCtrl+I")); | |
472 | menuFile->AppendSeparator(); | |
473 | menuFile->Append (wxID_PRINT_SETUP, _("Print Set&up ..")); | |
474 | menuFile->Append (wxID_PREVIEW, _("Print Pre&view\tCtrl+Shift+P")); | |
475 | menuFile->Append (wxID_PRINT, _("&Print ..\tCtrl+P")); | |
476 | menuFile->AppendSeparator(); | |
477 | menuFile->Append (wxID_EXIT, _("&Quit\tCtrl+Q")); | |
478 | ||
479 | // Edit menu | |
480 | wxMenu *menuEdit = new wxMenu; | |
481 | menuEdit->Append (wxID_UNDO, _("&Undo\tCtrl+Z")); | |
482 | menuEdit->Append (wxID_REDO, _("&Redo\tCtrl+Shift+Z")); | |
483 | menuEdit->AppendSeparator(); | |
484 | menuEdit->Append (wxID_CUT, _("Cu&t\tCtrl+X")); | |
485 | menuEdit->Append (wxID_COPY, _("&Copy\tCtrl+C")); | |
486 | menuEdit->Append (wxID_PASTE, _("&Paste\tCtrl+V")); | |
487 | menuEdit->Append (wxID_CLEAR, _("&Delete\tDel")); | |
488 | menuEdit->AppendSeparator(); | |
489 | menuEdit->Append (wxID_FIND, _("&Find\tCtrl+F")); | |
490 | menuEdit->Enable (wxID_FIND, false); | |
491 | menuEdit->Append (myID_FINDNEXT, _("Find &next\tF3")); | |
492 | menuEdit->Enable (myID_FINDNEXT, false); | |
493 | menuEdit->Append (myID_REPLACE, _("&Replace\tCtrl+H")); | |
494 | menuEdit->Enable (myID_REPLACE, false); | |
495 | menuEdit->Append (myID_REPLACENEXT, _("Replace &again\tShift+F4")); | |
496 | menuEdit->Enable (myID_REPLACENEXT, false); | |
497 | menuEdit->AppendSeparator(); | |
498 | menuEdit->Append (myID_BRACEMATCH, _("&Match brace\tCtrl+M")); | |
499 | menuEdit->Append (myID_GOTO, _("&Goto\tCtrl+G")); | |
500 | menuEdit->Enable (myID_GOTO, false); | |
501 | menuEdit->AppendSeparator(); | |
502 | menuEdit->Append (myID_INDENTINC, _("&Indent increase\tTab")); | |
503 | menuEdit->Append (myID_INDENTRED, _("I&ndent reduce\tBksp")); | |
504 | menuEdit->AppendSeparator(); | |
505 | menuEdit->Append (wxID_SELECTALL, _("&Select all\tCtrl+A")); | |
506 | menuEdit->Append (myID_SELECTLINE, _("Select &line\tCtrl+L")); | |
507 | ||
508 | // hilight submenu | |
509 | wxMenu *menuHilight = new wxMenu; | |
510 | int Nr; | |
511 | for (Nr = 0; Nr < g_LanguagePrefsSize; Nr++) { | |
512 | menuHilight->Append (myID_HILIGHTFIRST + Nr, | |
513 | g_LanguagePrefs [Nr].name); | |
514 | } | |
515 | ||
516 | // charset submenu | |
517 | wxMenu *menuCharset = new wxMenu; | |
518 | menuCharset->Append (myID_CHARSETANSI, _("&ANSI (Windows)")); | |
519 | menuCharset->Append (myID_CHARSETMAC, _("&MAC (Macintosh)")); | |
520 | ||
521 | // View menu | |
522 | wxMenu *menuView = new wxMenu; | |
523 | menuView->Append (myID_HILIGHTLANG, _("&Hilight language .."), menuHilight); | |
524 | menuView->AppendSeparator(); | |
525 | menuView->AppendCheckItem (myID_FOLDTOGGLE, _("&Toggle current fold\tCtrl+T")); | |
526 | menuView->AppendCheckItem (myID_OVERTYPE, _("&Overwrite mode\tIns")); | |
527 | menuView->AppendCheckItem (myID_WRAPMODEON, _("&Wrap mode\tCtrl+U")); | |
528 | menuView->AppendSeparator(); | |
529 | menuView->AppendCheckItem (myID_DISPLAYEOL, _("Show line &endings")); | |
530 | menuView->AppendCheckItem (myID_INDENTGUIDE, _("Show &indent guides")); | |
531 | menuView->AppendCheckItem (myID_LINENUMBER, _("Show line &numbers")); | |
532 | menuView->AppendCheckItem (myID_LONGLINEON, _("Show &long line marker")); | |
533 | menuView->AppendCheckItem (myID_WHITESPACE, _("Show white&space")); | |
534 | menuView->AppendSeparator(); | |
535 | menuView->Append (myID_USECHARSET, _("Use &code page of .."), menuCharset); | |
536 | ||
537 | // change case submenu | |
538 | wxMenu *menuChangeCase = new wxMenu; | |
539 | menuChangeCase->Append (myID_CHANGEUPPER, _("&Upper case")); | |
540 | menuChangeCase->Append (myID_CHANGELOWER, _("&Lower case")); | |
541 | ||
542 | // convert EOL submenu | |
543 | wxMenu *menuConvertEOL = new wxMenu; | |
544 | menuConvertEOL->Append (myID_CONVERTCR, _("CR (&Linux)")); | |
545 | menuConvertEOL->Append (myID_CONVERTCRLF, _("CR+LF (&Windows)")); | |
546 | menuConvertEOL->Append (myID_CONVERTLF, _("LF (&Macintosh)")); | |
547 | ||
548 | // Extra menu | |
549 | wxMenu *menuExtra = new wxMenu; | |
550 | menuExtra->AppendCheckItem (myID_READONLY, _("&Readonly mode")); | |
551 | menuExtra->AppendSeparator(); | |
552 | menuExtra->Append (myID_CHANGECASE, _("Change &case to .."), menuChangeCase); | |
553 | menuExtra->AppendSeparator(); | |
554 | menuExtra->Append (myID_CONVERTEOL, _("Convert line &endings to .."), menuConvertEOL); | |
555 | ||
556 | // Window menu | |
557 | wxMenu *menuWindow = new wxMenu; | |
558 | menuWindow->Append (myID_PAGEPREV, _("&Previous\tCtrl+Shift+Tab")); | |
559 | menuWindow->Append (myID_PAGENEXT, _("&Next\tCtrl+Tab")); | |
560 | ||
561 | // Help menu | |
562 | wxMenu *menuHelp = new wxMenu; | |
563 | menuHelp->Append (wxID_ABOUT, _("&About ..\tShift+F1")); | |
564 | ||
565 | // construct menu | |
566 | m_menuBar->Append (menuFile, _("&File")); | |
567 | m_menuBar->Append (menuEdit, _("&Edit")); | |
568 | m_menuBar->Append (menuView, _("&View")); | |
569 | m_menuBar->Append (menuExtra, _("E&xtra")); | |
570 | m_menuBar->Append (menuWindow, _("&Window")); | |
571 | m_menuBar->Append (menuHelp, _("&Help")); | |
572 | SetMenuBar (m_menuBar); | |
573 | } | |
574 | ||
575 | void AppFrame::FileOpen (wxString fname) | |
576 | { | |
577 | wxFileName w(fname); w.Normalize(); fname = w.GetFullPath(); | |
578 | m_edit->LoadFile (fname); | |
579 | } | |
580 | ||
581 | wxRect AppFrame::DeterminePrintSize () { | |
582 | ||
583 | wxSize scr = wxGetDisplaySize(); | |
584 | ||
585 | // determine position and size (shifting 16 left and down) | |
586 | wxRect rect = GetRect(); | |
587 | rect.x += 16; | |
588 | rect.y += 16; | |
589 | rect.width = wxMin (rect.width, (scr.x - rect.x)); | |
590 | rect.height = wxMin (rect.height, (scr.x - rect.y)); | |
591 | ||
592 | return rect; | |
593 | } | |
594 | ||
595 | ||
596 | //---------------------------------------------------------------------------- | |
597 | // AppAbout | |
598 | //---------------------------------------------------------------------------- | |
599 | ||
600 | BEGIN_EVENT_TABLE (AppAbout, wxDialog) | |
601 | EVT_TIMER (myID_ABOUTTIMER, AppAbout::OnTimerEvent) | |
602 | END_EVENT_TABLE () | |
603 | ||
604 | AppAbout::AppAbout (wxWindow *parent, | |
605 | int milliseconds, | |
606 | long style) | |
607 | : wxDialog (parent, wxID_ANY, wxEmptyString, | |
608 | wxDefaultPosition, wxDefaultSize, | |
609 | style | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { | |
610 | ||
611 | // set timer if any | |
612 | m_timer = NULL; | |
613 | if (milliseconds > 0) { | |
614 | m_timer = new wxTimer (this, myID_ABOUTTIMER); | |
615 | m_timer->Start (milliseconds, wxTIMER_ONE_SHOT); | |
616 | } | |
617 | ||
618 | // sets the application title | |
619 | SetTitle (_("About ..")); | |
620 | ||
621 | // about info | |
622 | wxGridSizer *aboutinfo = new wxGridSizer (2, 0, 2); | |
623 | aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Written by: ")), | |
624 | 0, wxALIGN_LEFT); | |
625 | aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_MAINT), | |
626 | 1, wxEXPAND | wxALIGN_LEFT); | |
627 | aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Version: ")), | |
628 | 0, wxALIGN_LEFT); | |
629 | aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_VERSION), | |
630 | 1, wxEXPAND | wxALIGN_LEFT); | |
631 | aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Licence type: ")), | |
632 | 0, wxALIGN_LEFT); | |
633 | aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_LICENCE), | |
634 | 1, wxEXPAND | wxALIGN_LEFT); | |
635 | aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Copyright: ")), | |
636 | 0, wxALIGN_LEFT); | |
637 | aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_COPYRIGTH), | |
638 | 1, wxEXPAND | wxALIGN_LEFT); | |
639 | ||
640 | // about icontitle//info | |
641 | wxBoxSizer *aboutpane = new wxBoxSizer (wxHORIZONTAL); | |
642 | wxBitmap bitmap = wxBitmap(wxICON (mondrian)); | |
643 | aboutpane->Add (new wxStaticBitmap (this, wxID_ANY, bitmap), | |
644 | 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 20); | |
645 | aboutpane->Add (aboutinfo, 1, wxEXPAND); | |
646 | aboutpane->Add (60, 0); | |
647 | ||
648 | // about complete | |
649 | wxBoxSizer *totalpane = new wxBoxSizer (wxVERTICAL); | |
650 | totalpane->Add (0, 20); | |
651 | wxStaticText *appname = new wxStaticText(this, wxID_ANY, *g_appname); | |
652 | appname->SetFont (wxFont (24, wxDEFAULT, wxNORMAL, wxBOLD)); | |
653 | totalpane->Add (appname, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 40); | |
654 | totalpane->Add (0, 10); | |
655 | totalpane->Add (aboutpane, 0, wxEXPAND | wxALL, 4); | |
656 | totalpane->Add (new wxStaticText(this, wxID_ANY, APP_DESCR), | |
657 | 0, wxALIGN_CENTER | wxALL, 10); | |
658 | wxButton *okButton = new wxButton (this, wxID_OK, _("OK")); | |
659 | okButton->SetDefault(); | |
660 | totalpane->Add (okButton, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT | wxBOTTOM, 10); | |
661 | ||
662 | SetSizerAndFit (totalpane); | |
663 | ||
664 | CenterOnScreen(); | |
665 | ShowModal(); | |
666 | } | |
667 | ||
668 | AppAbout::~AppAbout () { | |
669 | if (m_timer) { | |
670 | delete m_timer; | |
671 | m_timer = NULL; | |
672 | } | |
673 | } | |
674 | ||
675 | //---------------------------------------------------------------------------- | |
676 | // event handlers | |
677 | void AppAbout::OnTimerEvent (wxTimerEvent &WXUNUSED(event)) { | |
678 | if (m_timer) delete m_timer; | |
679 | m_timer = NULL; | |
680 | EndModal (wxID_OK); | |
681 | } |