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