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