]> git.saurik.com Git - wxWidgets.git/blob - samples/stc/stctest.cpp
Use wxDELETE() and wxDELETEA() when possible.
[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 #ifndef __WXMSW__
43 #include "../sample.xpm"
44 #endif
45
46 //----------------------------------------------------------------------------
47 // resources
48 //----------------------------------------------------------------------------
49
50 // the application icon (under Windows and OS/2 it is in resources)
51 #if !defined(__WXMSW__) && !defined(__WXPM__)
52 #include "../sample.xpm"
53 #endif
54
55 //============================================================================
56 // declarations
57 //============================================================================
58
59 #define APP_NAME wxT("STC-Test")
60 #define APP_DESCR _("See http://wxguide.sourceforge.net/")
61
62 #define APP_MAINT wxT("Otto Wyss")
63 #define APP_VENDOR wxT("wxWidgets")
64 #define APP_COPYRIGTH wxT("(C) 2003 Otto Wyss")
65 #define APP_LICENCE wxT("wxWidgets")
66
67 #define APP_VERSION wxT("0.1.alpha")
68 #define APP_BUILD __DATE__
69
70 #define APP_WEBSITE wxT("http://www.wxWidgets.org")
71 #define APP_MAIL wxT("mailto://???")
72
73 #define NONAME _("<untitled>")
74
75 class AppBook;
76
77
78 //----------------------------------------------------------------------------
79 //! global application name
80 wxString *g_appname = NULL;
81
82 #if wxUSE_PRINTING_ARCHITECTURE
83
84 //! global print data, to remember settings during the session
85 wxPrintData *g_printData = (wxPrintData*) NULL;
86 wxPageSetupData *g_pageSetupData = (wxPageSetupData*) NULL;
87
88 #endif // wxUSE_PRINTING_ARCHITECTURE
89
90
91 class AppFrame;
92
93 //----------------------------------------------------------------------------
94 //! application APP_VENDOR-APP_NAME.
95 class App: public wxApp {
96 friend class AppFrame;
97
98 public:
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
109 wxFrame* MinimalEditor();
110 protected:
111 void OnMinimalEditor(wxCommandEvent&);
112 DECLARE_EVENT_TABLE()
113 };
114
115 // created dynamically by wxWidgets
116 DECLARE_APP (App);
117
118 //----------------------------------------------------------------------------
119 //! frame of the application APP_VENDOR-APP_NAME.
120 class AppFrame: public wxFrame {
121 friend class App;
122 friend class AppBook;
123 friend class AppAbout;
124
125 public:
126 //! constructor
127 AppFrame (const wxString &title);
128
129 //! destructor
130 ~AppFrame ();
131
132 //! event handlers
133 //! common
134 void OnClose (wxCloseEvent &event);
135 void OnAbout (wxCommandEvent &event);
136 void OnExit (wxCommandEvent &event);
137 void OnTimerEvent (wxTimerEvent &event);
138 //! file
139 void OnFileNew (wxCommandEvent &event);
140 void OnFileNewFrame (wxCommandEvent &event);
141 void OnFileOpen (wxCommandEvent &event);
142 void OnFileOpenFrame (wxCommandEvent &event);
143 void OnFileSave (wxCommandEvent &event);
144 void OnFileSaveAs (wxCommandEvent &event);
145 void OnFileClose (wxCommandEvent &event);
146 //! properties
147 void OnProperties (wxCommandEvent &event);
148 //! print
149 void OnPrintSetup (wxCommandEvent &event);
150 void OnPrintPreview (wxCommandEvent &event);
151 void OnPrint (wxCommandEvent &event);
152 //! edit events
153 void OnEdit (wxCommandEvent &event);
154
155 private:
156 // edit object
157 Edit *m_edit;
158 void FileOpen (wxString fname);
159
160 //! creates the application menu bar
161 wxMenuBar *m_menuBar;
162 void CreateMenu ();
163
164 // print preview position and size
165 wxRect DeterminePrintSize ();
166
167 DECLARE_EVENT_TABLE()
168 };
169
170 //----------------------------------------------------------------------------
171 //! about box of the application APP_VENDOR-APP_NAME
172 class AppAbout: public wxDialog {
173
174 public:
175 //! constructor
176 AppAbout (wxWindow *parent,
177 int milliseconds = 0,
178 long style = 0);
179
180 //! destructor
181 ~AppAbout ();
182
183 // event handlers
184 void OnTimerEvent (wxTimerEvent &event);
185
186 private:
187 // timer
188 wxTimer *m_timer;
189
190 DECLARE_EVENT_TABLE()
191 };
192
193
194 //============================================================================
195 // implementation
196 //============================================================================
197
198 IMPLEMENT_APP (App)
199
200
201 BEGIN_EVENT_TABLE(App, wxApp)
202 EVT_MENU(myID_WINDOW_MINIMAL, App::OnMinimalEditor)
203 END_EVENT_TABLE()
204
205 //----------------------------------------------------------------------------
206 // App
207 //----------------------------------------------------------------------------
208
209 bool App::OnInit () {
210
211 wxInitAllImageHandlers();
212
213 // set application and vendor name
214 SetAppName (APP_NAME);
215 SetVendorName (APP_VENDOR);
216 g_appname = new wxString ();
217 g_appname->Append (APP_VENDOR);
218 g_appname->Append (wxT("-"));
219 g_appname->Append (APP_NAME);
220
221 #if wxUSE_PRINTING_ARCHITECTURE
222 // initialize print data and setup
223 g_printData = new wxPrintData;
224 g_pageSetupData = new wxPageSetupDialogData;
225 #endif // wxUSE_PRINTING_ARCHITECTURE
226
227 // create application frame
228 m_frame = new AppFrame (*g_appname);
229
230 // open application frame
231 m_frame->Layout ();
232 m_frame->Show (true);
233 SetTopWindow (m_frame);
234
235 return true;
236 }
237
238 int App::OnExit () {
239
240 // delete global appname
241 delete g_appname;
242
243 #if wxUSE_PRINTING_ARCHITECTURE
244 // delete global print data and setup
245 if (g_printData) delete g_printData;
246 if (g_pageSetupData) delete g_pageSetupData;
247 #endif // wxUSE_PRINTING_ARCHITECTURE
248
249 return 0;
250 }
251
252 //----------------------------------------------------------------------------
253 // AppFrame
254 //----------------------------------------------------------------------------
255
256 BEGIN_EVENT_TABLE (AppFrame, wxFrame)
257 // common
258 EVT_CLOSE ( AppFrame::OnClose)
259 // file
260 EVT_MENU (wxID_OPEN, AppFrame::OnFileOpen)
261 EVT_MENU (wxID_SAVE, AppFrame::OnFileSave)
262 EVT_MENU (wxID_SAVEAS, AppFrame::OnFileSaveAs)
263 EVT_MENU (wxID_CLOSE, AppFrame::OnFileClose)
264 // properties
265 EVT_MENU (myID_PROPERTIES, AppFrame::OnProperties)
266 // print and exit
267 EVT_MENU (wxID_PRINT_SETUP, AppFrame::OnPrintSetup)
268 EVT_MENU (wxID_PREVIEW, AppFrame::OnPrintPreview)
269 EVT_MENU (wxID_PRINT, AppFrame::OnPrint)
270 EVT_MENU (wxID_EXIT, AppFrame::OnExit)
271 // edit
272 EVT_MENU (wxID_CLEAR, AppFrame::OnEdit)
273 EVT_MENU (wxID_CUT, AppFrame::OnEdit)
274 EVT_MENU (wxID_COPY, AppFrame::OnEdit)
275 EVT_MENU (wxID_PASTE, AppFrame::OnEdit)
276 EVT_MENU (myID_INDENTINC, AppFrame::OnEdit)
277 EVT_MENU (myID_INDENTRED, AppFrame::OnEdit)
278 EVT_MENU (wxID_SELECTALL, AppFrame::OnEdit)
279 EVT_MENU (myID_SELECTLINE, AppFrame::OnEdit)
280 EVT_MENU (wxID_REDO, AppFrame::OnEdit)
281 EVT_MENU (wxID_UNDO, AppFrame::OnEdit)
282 // find
283 EVT_MENU (wxID_FIND, AppFrame::OnEdit)
284 EVT_MENU (myID_FINDNEXT, AppFrame::OnEdit)
285 EVT_MENU (myID_REPLACE, AppFrame::OnEdit)
286 EVT_MENU (myID_REPLACENEXT, AppFrame::OnEdit)
287 EVT_MENU (myID_BRACEMATCH, AppFrame::OnEdit)
288 EVT_MENU (myID_GOTO, AppFrame::OnEdit)
289 // view
290 EVT_MENU_RANGE (myID_HILIGHTFIRST, myID_HILIGHTLAST,
291 AppFrame::OnEdit)
292 EVT_MENU (myID_DISPLAYEOL, AppFrame::OnEdit)
293 EVT_MENU (myID_INDENTGUIDE, AppFrame::OnEdit)
294 EVT_MENU (myID_LINENUMBER, AppFrame::OnEdit)
295 EVT_MENU (myID_LONGLINEON, AppFrame::OnEdit)
296 EVT_MENU (myID_WHITESPACE, AppFrame::OnEdit)
297 EVT_MENU (myID_FOLDTOGGLE, AppFrame::OnEdit)
298 EVT_MENU (myID_OVERTYPE, AppFrame::OnEdit)
299 EVT_MENU (myID_READONLY, AppFrame::OnEdit)
300 EVT_MENU (myID_WRAPMODEON, AppFrame::OnEdit)
301 // extra
302 EVT_MENU (myID_CHANGELOWER, AppFrame::OnEdit)
303 EVT_MENU (myID_CHANGEUPPER, AppFrame::OnEdit)
304 EVT_MENU (myID_CONVERTCR, AppFrame::OnEdit)
305 EVT_MENU (myID_CONVERTCRLF, AppFrame::OnEdit)
306 EVT_MENU (myID_CONVERTLF, AppFrame::OnEdit)
307 EVT_MENU (myID_CHARSETANSI, AppFrame::OnEdit)
308 EVT_MENU (myID_CHARSETMAC, AppFrame::OnEdit)
309 // help
310 EVT_MENU (wxID_ABOUT, AppFrame::OnAbout)
311 END_EVENT_TABLE ()
312
313 AppFrame::AppFrame (const wxString &title)
314 : wxFrame ((wxFrame *)NULL, wxID_ANY, title, wxDefaultPosition, wxSize(750,550),
315 wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
316 {
317 SetIcon(wxICON(sample));
318
319 // initialize important variables
320 m_edit = NULL;
321
322 // set icon and background
323 SetTitle (*g_appname);
324 SetBackgroundColour (wxT("WHITE"));
325
326 // about box shown for 1 seconds
327 AppAbout dlg(this, 1000);
328
329 // create menu
330 m_menuBar = new wxMenuBar;
331 CreateMenu ();
332
333 // open first page
334 m_edit = new Edit (this, wxID_ANY);
335 m_edit->SetFocus();
336
337 FileOpen (wxT("stctest.cpp"));
338 }
339
340 AppFrame::~AppFrame () {
341 }
342
343 // common event handlers
344 void AppFrame::OnClose (wxCloseEvent &event) {
345 wxCommandEvent evt;
346 OnFileClose (evt);
347 if (m_edit && m_edit->Modified()) {
348 if (event.CanVeto()) event.Veto (true);
349 return;
350 }
351 Destroy();
352 }
353
354 void AppFrame::OnAbout (wxCommandEvent &WXUNUSED(event)) {
355 AppAbout dlg(this);
356 }
357
358 void AppFrame::OnExit (wxCommandEvent &WXUNUSED(event)) {
359 Close (true);
360 }
361
362 // file event handlers
363 void AppFrame::OnFileOpen (wxCommandEvent &WXUNUSED(event)) {
364 if (!m_edit) return;
365 #if wxUSE_FILEDLG
366 wxString fname;
367 wxFileDialog dlg (this, wxT("Open file"), wxEmptyString, wxEmptyString, wxT("Any file (*)|*"),
368 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR);
369 if (dlg.ShowModal() != wxID_OK) return;
370 fname = dlg.GetPath ();
371 FileOpen (fname);
372 #endif // wxUSE_FILEDLG
373 }
374
375 void AppFrame::OnFileSave (wxCommandEvent &WXUNUSED(event)) {
376 if (!m_edit) return;
377 if (!m_edit->Modified()) {
378 wxMessageBox (_("There is nothing to save!"), _("Save file"),
379 wxOK | wxICON_EXCLAMATION);
380 return;
381 }
382 m_edit->SaveFile ();
383 }
384
385 void AppFrame::OnFileSaveAs (wxCommandEvent &WXUNUSED(event)) {
386 if (!m_edit) return;
387 #if wxUSE_FILEDLG
388 wxString filename = wxEmptyString;
389 wxFileDialog dlg (this, wxT("Save file"), wxEmptyString, wxEmptyString, wxT("Any file (*)|*"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
390 if (dlg.ShowModal() != wxID_OK) return;
391 filename = dlg.GetPath();
392 m_edit->SaveFile (filename);
393 #endif // wxUSE_FILEDLG
394 }
395
396 void AppFrame::OnFileClose (wxCommandEvent &WXUNUSED(event)) {
397 if (!m_edit) return;
398 if (m_edit->Modified()) {
399 if (wxMessageBox (_("Text is not saved, save before closing?"), _("Close"),
400 wxYES_NO | wxICON_QUESTION) == wxYES) {
401 m_edit->SaveFile();
402 if (m_edit->Modified()) {
403 wxMessageBox (_("Text could not be saved!"), _("Close abort"),
404 wxOK | wxICON_EXCLAMATION);
405 return;
406 }
407 }
408 }
409 m_edit->SetFilename (wxEmptyString);
410 m_edit->ClearAll();
411 m_edit->SetSavePoint();
412 }
413
414 // properties event handlers
415 void AppFrame::OnProperties (wxCommandEvent &WXUNUSED(event)) {
416 if (!m_edit) return;
417 EditProperties dlg(m_edit, 0);
418 }
419
420 // print event handlers
421 void AppFrame::OnPrintSetup (wxCommandEvent &WXUNUSED(event)) {
422 #if wxUSE_PRINTING_ARCHITECTURE
423 (*g_pageSetupData) = * g_printData;
424 wxPageSetupDialog pageSetupDialog(this, g_pageSetupData);
425 pageSetupDialog.ShowModal();
426 (*g_printData) = pageSetupDialog.GetPageSetupData().GetPrintData();
427 (*g_pageSetupData) = pageSetupDialog.GetPageSetupData();
428 #endif // wxUSE_PRINTING_ARCHITECTURE
429 }
430
431 void AppFrame::OnPrintPreview (wxCommandEvent &WXUNUSED(event)) {
432 #if wxUSE_PRINTING_ARCHITECTURE
433 wxPrintDialogData printDialogData( *g_printData);
434 wxPrintPreview *preview =
435 new wxPrintPreview (new EditPrint (m_edit),
436 new EditPrint (m_edit),
437 &printDialogData);
438 if (!preview->Ok()) {
439 delete preview;
440 wxMessageBox (_("There was a problem with previewing.\n\
441 Perhaps your current printer is not correctly?"),
442 _("Previewing"), wxOK);
443 return;
444 }
445 wxRect rect = DeterminePrintSize();
446 wxPreviewFrame *frame = new wxPreviewFrame (preview, this, _("Print Preview"));
447 frame->SetSize (rect);
448 frame->Centre(wxBOTH);
449 frame->Initialize();
450 frame->Show(true);
451 #endif // wxUSE_PRINTING_ARCHITECTURE
452 }
453
454 void AppFrame::OnPrint (wxCommandEvent &WXUNUSED(event)) {
455 #if wxUSE_PRINTING_ARCHITECTURE
456 wxPrintDialogData printDialogData( *g_printData);
457 wxPrinter printer (&printDialogData);
458 EditPrint printout (m_edit);
459 if (!printer.Print (this, &printout, true)) {
460 if (wxPrinter::GetLastError() == wxPRINTER_ERROR) {
461 wxMessageBox (_("There was a problem with printing.\n\
462 Perhaps your current printer is not correctly?"),
463 _("Previewing"), wxOK);
464 return;
465 }
466 }
467 (*g_printData) = printer.GetPrintDialogData().GetPrintData();
468 #endif // wxUSE_PRINTING_ARCHITECTURE
469 }
470
471 // edit events
472 void AppFrame::OnEdit (wxCommandEvent &event) {
473 if (m_edit) m_edit->GetEventHandler()->ProcessEvent (event);
474 }
475
476 // private functions
477 void AppFrame::CreateMenu ()
478 {
479 // File menu
480 wxMenu *menuFile = new wxMenu;
481 menuFile->Append (wxID_OPEN, _("&Open ..\tCtrl+O"));
482 menuFile->Append (wxID_SAVE, _("&Save\tCtrl+S"));
483 menuFile->Append (wxID_SAVEAS, _("Save &as ..\tCtrl+Shift+S"));
484 menuFile->Append (wxID_CLOSE, _("&Close\tCtrl+W"));
485 menuFile->AppendSeparator();
486 menuFile->Append (myID_PROPERTIES, _("Proper&ties ..\tCtrl+I"));
487 menuFile->AppendSeparator();
488 menuFile->Append (wxID_PRINT_SETUP, _("Print Set&up .."));
489 menuFile->Append (wxID_PREVIEW, _("Print Pre&view\tCtrl+Shift+P"));
490 menuFile->Append (wxID_PRINT, _("&Print ..\tCtrl+P"));
491 menuFile->AppendSeparator();
492 menuFile->Append (wxID_EXIT, _("&Quit\tCtrl+Q"));
493
494 // Edit menu
495 wxMenu *menuEdit = new wxMenu;
496 menuEdit->Append (wxID_UNDO, _("&Undo\tCtrl+Z"));
497 menuEdit->Append (wxID_REDO, _("&Redo\tCtrl+Shift+Z"));
498 menuEdit->AppendSeparator();
499 menuEdit->Append (wxID_CUT, _("Cu&t\tCtrl+X"));
500 menuEdit->Append (wxID_COPY, _("&Copy\tCtrl+C"));
501 menuEdit->Append (wxID_PASTE, _("&Paste\tCtrl+V"));
502 menuEdit->Append (wxID_CLEAR, _("&Delete\tDel"));
503 menuEdit->AppendSeparator();
504 menuEdit->Append (wxID_FIND, _("&Find\tCtrl+F"));
505 menuEdit->Enable (wxID_FIND, false);
506 menuEdit->Append (myID_FINDNEXT, _("Find &next\tF3"));
507 menuEdit->Enable (myID_FINDNEXT, false);
508 menuEdit->Append (myID_REPLACE, _("&Replace\tCtrl+H"));
509 menuEdit->Enable (myID_REPLACE, false);
510 menuEdit->Append (myID_REPLACENEXT, _("Replace &again\tShift+F4"));
511 menuEdit->Enable (myID_REPLACENEXT, false);
512 menuEdit->AppendSeparator();
513 menuEdit->Append (myID_BRACEMATCH, _("&Match brace\tCtrl+M"));
514 menuEdit->Append (myID_GOTO, _("&Goto\tCtrl+G"));
515 menuEdit->Enable (myID_GOTO, false);
516 menuEdit->AppendSeparator();
517 menuEdit->Append (myID_INDENTINC, _("&Indent increase\tTab"));
518 menuEdit->Append (myID_INDENTRED, _("I&ndent reduce\tShift+Tab"));
519 menuEdit->AppendSeparator();
520 menuEdit->Append (wxID_SELECTALL, _("&Select all\tCtrl+A"));
521 menuEdit->Append (myID_SELECTLINE, _("Select &line\tCtrl+L"));
522
523 // hilight submenu
524 wxMenu *menuHilight = new wxMenu;
525 int Nr;
526 for (Nr = 0; Nr < g_LanguagePrefsSize; Nr++) {
527 menuHilight->Append (myID_HILIGHTFIRST + Nr,
528 g_LanguagePrefs [Nr].name);
529 }
530
531 // charset submenu
532 wxMenu *menuCharset = new wxMenu;
533 menuCharset->Append (myID_CHARSETANSI, _("&ANSI (Windows)"));
534 menuCharset->Append (myID_CHARSETMAC, _("&MAC (Macintosh)"));
535
536 // View menu
537 wxMenu *menuView = new wxMenu;
538 menuView->Append (myID_HILIGHTLANG, _("&Hilight language .."), menuHilight);
539 menuView->AppendSeparator();
540 menuView->AppendCheckItem (myID_FOLDTOGGLE, _("&Toggle current fold\tCtrl+T"));
541 menuView->AppendCheckItem (myID_OVERTYPE, _("&Overwrite mode\tIns"));
542 menuView->AppendCheckItem (myID_WRAPMODEON, _("&Wrap mode\tCtrl+U"));
543 menuView->AppendSeparator();
544 menuView->AppendCheckItem (myID_DISPLAYEOL, _("Show line &endings"));
545 menuView->AppendCheckItem (myID_INDENTGUIDE, _("Show &indent guides"));
546 menuView->AppendCheckItem (myID_LINENUMBER, _("Show line &numbers"));
547 menuView->AppendCheckItem (myID_LONGLINEON, _("Show &long line marker"));
548 menuView->AppendCheckItem (myID_WHITESPACE, _("Show white&space"));
549 menuView->AppendSeparator();
550 menuView->Append (myID_USECHARSET, _("Use &code page of .."), menuCharset);
551
552 // change case submenu
553 wxMenu *menuChangeCase = new wxMenu;
554 menuChangeCase->Append (myID_CHANGEUPPER, _("&Upper case"));
555 menuChangeCase->Append (myID_CHANGELOWER, _("&Lower case"));
556
557 // convert EOL submenu
558 wxMenu *menuConvertEOL = new wxMenu;
559 menuConvertEOL->Append (myID_CONVERTCR, _("CR (&Linux)"));
560 menuConvertEOL->Append (myID_CONVERTCRLF, _("CR+LF (&Windows)"));
561 menuConvertEOL->Append (myID_CONVERTLF, _("LF (&Macintosh)"));
562
563 // Extra menu
564 wxMenu *menuExtra = new wxMenu;
565 menuExtra->AppendCheckItem (myID_READONLY, _("&Readonly mode"));
566 menuExtra->AppendSeparator();
567 menuExtra->Append (myID_CHANGECASE, _("Change &case to .."), menuChangeCase);
568 menuExtra->AppendSeparator();
569 menuExtra->Append (myID_CONVERTEOL, _("Convert line &endings to .."), menuConvertEOL);
570
571 // Window menu
572 wxMenu *menuWindow = new wxMenu;
573 menuWindow->Append (myID_PAGEPREV, _("&Previous\tCtrl+Shift+Tab"));
574 menuWindow->Append (myID_PAGENEXT, _("&Next\tCtrl+Tab"));
575 menuWindow->Append(myID_WINDOW_MINIMAL, _("&Minimal editor"));
576
577 // Help menu
578 wxMenu *menuHelp = new wxMenu;
579 menuHelp->Append (wxID_ABOUT, _("&About ..\tShift+F1"));
580
581 // construct menu
582 m_menuBar->Append (menuFile, _("&File"));
583 m_menuBar->Append (menuEdit, _("&Edit"));
584 m_menuBar->Append (menuView, _("&View"));
585 m_menuBar->Append (menuExtra, _("E&xtra"));
586 m_menuBar->Append (menuWindow, _("&Window"));
587 m_menuBar->Append (menuHelp, _("&Help"));
588 SetMenuBar (m_menuBar);
589 }
590
591 void AppFrame::FileOpen (wxString fname)
592 {
593 wxFileName w(fname); w.Normalize(); fname = w.GetFullPath();
594 m_edit->LoadFile (fname);
595 }
596
597 wxRect AppFrame::DeterminePrintSize () {
598
599 wxSize scr = wxGetDisplaySize();
600
601 // determine position and size (shifting 16 left and down)
602 wxRect rect = GetRect();
603 rect.x += 16;
604 rect.y += 16;
605 rect.width = wxMin (rect.width, (scr.x - rect.x));
606 rect.height = wxMin (rect.height, (scr.x - rect.y));
607
608 return rect;
609 }
610
611
612 //----------------------------------------------------------------------------
613 // AppAbout
614 //----------------------------------------------------------------------------
615
616 BEGIN_EVENT_TABLE (AppAbout, wxDialog)
617 EVT_TIMER (myID_ABOUTTIMER, AppAbout::OnTimerEvent)
618 END_EVENT_TABLE ()
619
620 AppAbout::AppAbout (wxWindow *parent,
621 int milliseconds,
622 long style)
623 : wxDialog (parent, wxID_ANY, wxEmptyString,
624 wxDefaultPosition, wxDefaultSize,
625 style | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
626
627 // set timer if any
628 m_timer = NULL;
629 if (milliseconds > 0) {
630 m_timer = new wxTimer (this, myID_ABOUTTIMER);
631 m_timer->Start (milliseconds, wxTIMER_ONE_SHOT);
632 }
633
634 // sets the application title
635 SetTitle (_("About .."));
636
637 // about info
638 wxGridSizer *aboutinfo = new wxGridSizer (2, 0, 2);
639 aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Written by: ")),
640 0, wxALIGN_LEFT);
641 aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_MAINT),
642 1, wxEXPAND | wxALIGN_LEFT);
643 aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Version: ")),
644 0, wxALIGN_LEFT);
645 aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_VERSION),
646 1, wxEXPAND | wxALIGN_LEFT);
647 aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Licence type: ")),
648 0, wxALIGN_LEFT);
649 aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_LICENCE),
650 1, wxEXPAND | wxALIGN_LEFT);
651 aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Copyright: ")),
652 0, wxALIGN_LEFT);
653 aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_COPYRIGTH),
654 1, wxEXPAND | wxALIGN_LEFT);
655
656 // about icontitle//info
657 wxBoxSizer *aboutpane = new wxBoxSizer (wxHORIZONTAL);
658 wxBitmap bitmap = wxBitmap(wxICON (sample));
659 aboutpane->Add (new wxStaticBitmap (this, wxID_ANY, bitmap),
660 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 20);
661 aboutpane->Add (aboutinfo, 1, wxEXPAND);
662 aboutpane->Add (60, 0);
663
664 // about complete
665 wxBoxSizer *totalpane = new wxBoxSizer (wxVERTICAL);
666 totalpane->Add (0, 20);
667 wxStaticText *appname = new wxStaticText(this, wxID_ANY, *g_appname);
668 appname->SetFont (wxFont (24, wxDEFAULT, wxNORMAL, wxBOLD));
669 totalpane->Add (appname, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 40);
670 totalpane->Add (0, 10);
671 totalpane->Add (aboutpane, 0, wxEXPAND | wxALL, 4);
672 totalpane->Add (new wxStaticText(this, wxID_ANY, APP_DESCR),
673 0, wxALIGN_CENTER | wxALL, 10);
674 wxButton *okButton = new wxButton (this, wxID_OK, _("OK"));
675 okButton->SetDefault();
676 totalpane->Add (okButton, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT | wxBOTTOM, 10);
677
678 SetSizerAndFit (totalpane);
679
680 CenterOnScreen();
681 ShowModal();
682 }
683
684 AppAbout::~AppAbout () {
685 wxDELETE(m_timer);
686 }
687
688 //----------------------------------------------------------------------------
689 // event handlers
690 void AppAbout::OnTimerEvent (wxTimerEvent &WXUNUSED(event)) {
691 wxDELETE(m_timer);
692 EndModal (wxID_OK);
693 }
694
695 /////////////////////////////////////////////////////////////////////////////
696 // Minimal editor added by Troels K 2008-04-08
697 // Thanks to geralds for SetLexerXml() - http://wxforum.shadonet.com/viewtopic.php?t=7155
698
699 class MinimalEditor : public wxStyledTextCtrl
700 {
701 enum
702 {
703 margin_id_lineno,
704 margin_id_fold,
705 };
706
707 public:
708 MinimalEditor(wxWindow* parent, wxWindowID id = wxID_ANY) : wxStyledTextCtrl(parent, id)
709 {
710 SetLexerXml();
711
712 SetProperty(wxT("fold"), wxT("1"));
713 SetProperty(wxT("fold.comment"), wxT("1"));
714 SetProperty(wxT("fold.compact"), wxT("1"));
715 SetProperty(wxT("fold.preprocessor"), wxT("1"));
716 SetProperty(wxT("fold.html"), wxT("1"));
717 SetProperty(wxT("fold.html.preprocessor"), wxT("1"));
718
719 SetMarginType(margin_id_lineno, wxSTC_MARGIN_NUMBER);
720 SetMarginWidth(margin_id_lineno, 32);
721
722 MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUS, wxT("WHITE"), wxT("BLACK"));
723 MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUS, wxT("WHITE"), wxT("BLACK"));
724 MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, wxT("WHITE"), wxT("BLACK"));
725 MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_BOXPLUSCONNECTED, wxT("WHITE"), wxT("BLACK"));
726 MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_BOXMINUSCONNECTED, wxT("WHITE"), wxT("BLACK"));
727 MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, wxT("WHITE"), wxT("BLACK"));
728 MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, wxT("WHITE"), wxT("BLACK"));
729
730 SetMarginMask(margin_id_fold, wxSTC_MASK_FOLDERS);
731 SetMarginWidth(margin_id_fold, 32);
732 SetMarginSensitive(margin_id_fold, true);
733
734 SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED);
735
736 SetTabWidth(4);
737 SetUseTabs(false);
738 SetWrapMode(wxSTC_WRAP_WORD);
739 SetWrapVisualFlags(wxSTC_WRAPVISUALFLAG_END);
740 }
741 virtual bool SetFont(const wxFont& font)
742 {
743 StyleSetFont(wxSTC_STYLE_DEFAULT, (wxFont&)font);
744 return wxStyledTextCtrl::SetFont(font);
745 }
746 void SetLexerXml()
747 {
748 SetLexer(wxSTC_LEX_XML);
749 StyleSetForeground(wxSTC_H_DEFAULT, *wxBLACK);
750 StyleSetForeground(wxSTC_H_TAG, *wxBLUE);
751 StyleSetForeground(wxSTC_H_TAGUNKNOWN, *wxBLUE);
752 StyleSetForeground(wxSTC_H_ATTRIBUTE, *wxRED);
753 StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN, *wxRED);
754 StyleSetBold(wxSTC_H_ATTRIBUTEUNKNOWN, true);
755 StyleSetForeground(wxSTC_H_NUMBER, *wxBLACK);
756 StyleSetForeground(wxSTC_H_DOUBLESTRING, *wxBLACK);
757 StyleSetForeground(wxSTC_H_SINGLESTRING, *wxBLACK);
758 StyleSetForeground(wxSTC_H_OTHER, *wxBLUE);
759 StyleSetForeground(wxSTC_H_COMMENT, wxTheColourDatabase->Find(wxT("GREY")));
760 StyleSetForeground(wxSTC_H_ENTITY, *wxRED);
761 StyleSetBold(wxSTC_H_ENTITY, true);
762 StyleSetForeground(wxSTC_H_TAGEND, *wxBLUE);
763 StyleSetForeground(wxSTC_H_XMLSTART, *wxBLUE);
764 StyleSetForeground(wxSTC_H_XMLEND, *wxBLUE);
765 StyleSetForeground(wxSTC_H_CDATA, *wxRED);
766 }
767 protected:
768 void OnMarginClick(wxStyledTextEvent&);
769 void OnText(wxStyledTextEvent&);
770 DECLARE_EVENT_TABLE()
771 };
772
773 BEGIN_EVENT_TABLE(MinimalEditor, wxStyledTextCtrl)
774 EVT_STC_MARGINCLICK(wxID_ANY, MinimalEditor::OnMarginClick)
775 EVT_STC_CHANGE(wxID_ANY, MinimalEditor::OnText)
776 END_EVENT_TABLE()
777
778 void MinimalEditor::OnMarginClick(wxStyledTextEvent &event)
779 {
780 if (event.GetMargin() == margin_id_fold)
781 {
782 int lineClick = LineFromPosition(event.GetPosition());
783 int levelClick = GetFoldLevel(lineClick);
784 if ((levelClick & wxSTC_FOLDLEVELHEADERFLAG) > 0)
785 {
786 ToggleFold(lineClick);
787 }
788 }
789 }
790
791 void MinimalEditor::OnText(wxStyledTextEvent& event)
792 {
793 wxLogDebug(wxT("Modified"));
794 event.Skip();
795 }
796
797 class MinimalEditorFrame : public wxFrame
798 {
799 public:
800 MinimalEditorFrame() : wxFrame(NULL, wxID_ANY, _("Minimal Editor"))
801 {
802 MinimalEditor* editor = new MinimalEditor(this);
803 editor->SetFont(wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT));
804 wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
805 sizer->Add(editor, 1, wxEXPAND);
806 SetSizer(sizer);
807 editor->SetText(
808 "<xml>\n"
809 " <text>\n"
810 " This is xml with syntax highlighting, line numbers, folding, word wrap and context menu\n"
811 " </text>\n"
812 "</xml>"
813 );
814 }
815 };
816
817 wxFrame* App::MinimalEditor()
818 {
819 MinimalEditorFrame* frame = new MinimalEditorFrame;
820 frame->Show();
821 return frame;
822 }
823
824 void App::OnMinimalEditor(wxCommandEvent& WXUNUSED(event))
825 {
826 MinimalEditor();
827 }
828