]> git.saurik.com Git - wxWidgets.git/blob - samples/stc/stctest.cpp
removed contrib files from the scripts
[wxWidgets.git] / samples / stc / stctest.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 // File: contrib/samples/stc/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 class AppFrame;
89
90 //----------------------------------------------------------------------------
91 //! application APP_VENDOR-APP_NAME.
92 class App: public wxApp {
93 friend class AppFrame;
94
95 public:
96 //! the main function called durning application start
97 virtual bool OnInit ();
98
99 //! application exit function
100 virtual int OnExit ();
101
102 private:
103 //! frame window
104 AppFrame* m_frame;
105
106 };
107
108 // created dynamically by wxWidgets
109 DECLARE_APP (App);
110
111 //----------------------------------------------------------------------------
112 //! frame of the application APP_VENDOR-APP_NAME.
113 class AppFrame: public wxFrame {
114 friend class App;
115 friend class AppBook;
116 friend class AppAbout;
117
118 public:
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);
147
148 private:
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
160 DECLARE_EVENT_TABLE()
161 };
162
163 //----------------------------------------------------------------------------
164 //! about box of the application APP_VENDOR-APP_NAME
165 class AppAbout: public wxDialog {
166
167 public:
168 //! constructor
169 AppAbout (wxWindow *parent,
170 int milliseconds = 0,
171 long style = 0);
172
173 //! destructor
174 ~AppAbout ();
175
176 // event handlers
177 void OnTimerEvent (wxTimerEvent &event);
178
179 private:
180 // timer
181 wxTimer *m_timer;
182
183 DECLARE_EVENT_TABLE()
184 };
185
186
187 //============================================================================
188 // implementation
189 //============================================================================
190
191 IMPLEMENT_APP (App)
192
193 //----------------------------------------------------------------------------
194 // App
195 //----------------------------------------------------------------------------
196
197 bool App::OnInit () {
198
199 wxInitAllImageHandlers();
200
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);
208
209 #if wxUSE_PRINTING_ARCHITECTURE
210 // initialize print data and setup
211 g_printData = new wxPrintData;
212 g_pageSetupData = new wxPageSetupDialogData;
213 #endif // wxUSE_PRINTING_ARCHITECTURE
214
215 // create application frame
216 m_frame = new AppFrame (*g_appname);
217
218 // open application frame
219 m_frame->Layout ();
220 m_frame->Show (true);
221 SetTopWindow (m_frame);
222
223 return true;
224 }
225
226 int App::OnExit () {
227
228 // delete global appname
229 delete g_appname;
230
231 #if wxUSE_PRINTING_ARCHITECTURE
232 // delete global print data and setup
233 if (g_printData) delete g_printData;
234 if (g_pageSetupData) delete g_pageSetupData;
235 #endif // wxUSE_PRINTING_ARCHITECTURE
236
237 return 0;
238 }
239
240 //----------------------------------------------------------------------------
241 // AppFrame
242 //----------------------------------------------------------------------------
243
244 BEGIN_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)
299 END_EVENT_TABLE ()
300
301 AppFrame::AppFrame (const wxString &title)
302 : wxFrame ((wxFrame *)NULL, wxID_ANY, title, wxDefaultPosition, wxSize(750,550),
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
314 AppAbout dlg(this, 1000);
315
316 // create menu
317 m_menuBar = new wxMenuBar;
318 CreateMenu ();
319
320 // open first page
321 m_edit = new Edit (this, wxID_ANY);
322 m_edit->SetFocus();
323
324 FileOpen (_T("stctest.cpp"));
325 }
326
327 AppFrame::~AppFrame () {
328 }
329
330 // common event handlers
331 void 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();
339 }
340
341 void AppFrame::OnAbout (wxCommandEvent &WXUNUSED(event)) {
342 AppAbout dlg(this);
343 }
344
345 void AppFrame::OnExit (wxCommandEvent &WXUNUSED(event)) {
346 Close (true);
347 }
348
349 // file event handlers
350 void AppFrame::OnFileOpen (wxCommandEvent &WXUNUSED(event)) {
351 if (!m_edit) return;
352 #if wxUSE_FILEDLG
353 wxString fname;
354 wxFileDialog dlg (this, _T("Open file"), wxEmptyString, wxEmptyString, _T("Any file (*)|*"),
355 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR);
356 if (dlg.ShowModal() != wxID_OK) return;
357 fname = dlg.GetPath ();
358 FileOpen (fname);
359 #endif // wxUSE_FILEDLG
360 }
361
362 void 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 }
371
372 void AppFrame::OnFileSaveAs (wxCommandEvent &WXUNUSED(event)) {
373 if (!m_edit) return;
374 #if wxUSE_FILEDLG
375 wxString filename = wxEmptyString;
376 wxFileDialog dlg (this, _T("Save file"), wxEmptyString, wxEmptyString, _T("Any file (*)|*"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
377 if (dlg.ShowModal() != wxID_OK) return;
378 filename = dlg.GetPath();
379 m_edit->SaveFile (filename);
380 #endif // wxUSE_FILEDLG
381 }
382
383 void 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 }
394 }
395 }
396 m_edit->SetFilename (wxEmptyString);
397 m_edit->ClearAll();
398 m_edit->SetSavePoint();
399 }
400
401 // properties event handlers
402 void AppFrame::OnProperties (wxCommandEvent &WXUNUSED(event)) {
403 if (!m_edit) return;
404 EditProperties dlg(m_edit, 0);
405 }
406
407 // print event handlers
408 void AppFrame::OnPrintSetup (wxCommandEvent &WXUNUSED(event)) {
409 #if wxUSE_PRINTING_ARCHITECTURE
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();
415 #endif // wxUSE_PRINTING_ARCHITECTURE
416 }
417
418 void AppFrame::OnPrintPreview (wxCommandEvent &WXUNUSED(event)) {
419 #if wxUSE_PRINTING_ARCHITECTURE
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);
438 #endif // wxUSE_PRINTING_ARCHITECTURE
439 }
440
441 void AppFrame::OnPrint (wxCommandEvent &WXUNUSED(event)) {
442 #if wxUSE_PRINTING_ARCHITECTURE
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;
452 }
453 }
454 (*g_printData) = printer.GetPrintDialogData().GetPrintData();
455 #endif // wxUSE_PRINTING_ARCHITECTURE
456 }
457
458 // edit events
459 void AppFrame::OnEdit (wxCommandEvent &event) {
460 if (m_edit) m_edit->ProcessEvent (event);
461 }
462
463 // private functions
464 void AppFrame::CreateMenu ()
465 {
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"));
505 menuEdit->Append (myID_INDENTRED, _("I&ndent reduce\tBackspace"));
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);
575 }
576
577 void AppFrame::FileOpen (wxString fname)
578 {
579 wxFileName w(fname); w.Normalize(); fname = w.GetFullPath();
580 m_edit->LoadFile (fname);
581 }
582
583 wxRect 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
602 BEGIN_EVENT_TABLE (AppAbout, wxDialog)
603 EVT_TIMER (myID_ABOUTTIMER, AppAbout::OnTimerEvent)
604 END_EVENT_TABLE ()
605
606 AppAbout::AppAbout (wxWindow *parent,
607 int milliseconds,
608 long style)
609 : wxDialog (parent, wxID_ANY, wxEmptyString,
610 wxDefaultPosition, wxDefaultSize,
611 style | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
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);
625 aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Written by: ")),
626 0, wxALIGN_LEFT);
627 aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_MAINT),
628 1, wxEXPAND | wxALIGN_LEFT);
629 aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Version: ")),
630 0, wxALIGN_LEFT);
631 aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_VERSION),
632 1, wxEXPAND | wxALIGN_LEFT);
633 aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Licence type: ")),
634 0, wxALIGN_LEFT);
635 aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_LICENCE),
636 1, wxEXPAND | wxALIGN_LEFT);
637 aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Copyright: ")),
638 0, wxALIGN_LEFT);
639 aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_COPYRIGTH),
640 1, wxEXPAND | wxALIGN_LEFT);
641
642 // about icontitle//info
643 wxBoxSizer *aboutpane = new wxBoxSizer (wxHORIZONTAL);
644 wxBitmap bitmap = wxBitmap(wxICON (mondrian));
645 aboutpane->Add (new wxStaticBitmap (this, wxID_ANY, bitmap),
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);
653 wxStaticText *appname = new wxStaticText(this, wxID_ANY, *g_appname);
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);
658 totalpane->Add (new wxStaticText(this, wxID_ANY, APP_DESCR),
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
666 CenterOnScreen();
667 ShowModal();
668 }
669
670 AppAbout::~AppAbout () {
671 if (m_timer) {
672 delete m_timer;
673 m_timer = NULL;
674 }
675 }
676
677 //----------------------------------------------------------------------------
678 // event handlers
679 void AppAbout::OnTimerEvent (wxTimerEvent &WXUNUSED(event)) {
680 if (m_timer) delete m_timer;
681 m_timer = NULL;
682 EndModal (wxID_OK);
683 }