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