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