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