1 //////////////////////////////////////////////////////////////////////////////
2 // File: contrib/samples/stc/stctest.cpp
3 // Purpose: STC test application
4 // Maintainer: Otto Wyss
6 // Copyright: (c) wxGuide
7 // Licence: wxWindows licence
8 //////////////////////////////////////////////////////////////////////////////
10 //----------------------------------------------------------------------------
12 //----------------------------------------------------------------------------
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
21 // for all others, include the necessary headers (this file is usually all you
22 // need because it includes almost all 'standard' 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
36 //! application headers
37 #include "defsext.h" // Additional definitions
38 #include "edit.h" // Edit module
39 #include "prefs.h" // Prefs
41 //----------------------------------------------------------------------------
43 //----------------------------------------------------------------------------
45 // the application icon (under Windows and OS/2 it is in resources)
46 #ifndef wxHAS_IMAGES_IN_RESOURCES
47 #include "../sample.xpm"
50 //============================================================================
52 //============================================================================
54 #define APP_NAME wxT("STC-Test")
55 #define APP_DESCR _("See http://wxguide.sourceforge.net/")
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")
62 #define APP_VERSION wxT("0.1.alpha")
63 #define APP_BUILD __DATE__
65 #define APP_WEBSITE wxT("http://www.wxWidgets.org")
66 #define APP_MAIL wxT("mailto://???")
68 #define NONAME _("<untitled>")
73 //----------------------------------------------------------------------------
74 //! global application name
75 wxString
*g_appname
= NULL
;
77 #if wxUSE_PRINTING_ARCHITECTURE
79 //! global print data, to remember settings during the session
80 wxPrintData
*g_printData
= (wxPrintData
*) NULL
;
81 wxPageSetupDialogData
*g_pageSetupData
= (wxPageSetupDialogData
*) NULL
;
83 #endif // wxUSE_PRINTING_ARCHITECTURE
88 //----------------------------------------------------------------------------
89 //! application APP_VENDOR-APP_NAME.
90 class App
: public wxApp
{
91 friend class AppFrame
;
94 //! the main function called durning application start
95 virtual bool OnInit ();
97 //! application exit function
98 virtual int OnExit ();
104 wxFrame
* MinimalEditor();
106 void OnMinimalEditor(wxCommandEvent
&);
107 DECLARE_EVENT_TABLE()
110 // created dynamically by wxWidgets
113 //----------------------------------------------------------------------------
114 //! frame of the application APP_VENDOR-APP_NAME.
115 class AppFrame
: public wxFrame
{
117 friend class AppBook
;
118 friend class AppAbout
;
122 AppFrame (const wxString
&title
);
129 void OnClose (wxCloseEvent
&event
);
130 void OnAbout (wxCommandEvent
&event
);
131 void OnExit (wxCommandEvent
&event
);
132 void OnTimerEvent (wxTimerEvent
&event
);
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
);
142 void OnProperties (wxCommandEvent
&event
);
144 void OnPrintSetup (wxCommandEvent
&event
);
145 void OnPrintPreview (wxCommandEvent
&event
);
146 void OnPrint (wxCommandEvent
&event
);
148 void OnEdit (wxCommandEvent
&event
);
153 void FileOpen (wxString fname
);
155 //! creates the application menu bar
156 wxMenuBar
*m_menuBar
;
159 // print preview position and size
160 wxRect
DeterminePrintSize ();
162 DECLARE_EVENT_TABLE()
165 //----------------------------------------------------------------------------
166 //! about box of the application APP_VENDOR-APP_NAME
167 class AppAbout
: public wxDialog
{
171 AppAbout (wxWindow
*parent
,
172 int milliseconds
= 0,
179 void OnTimerEvent (wxTimerEvent
&event
);
185 DECLARE_EVENT_TABLE()
189 //============================================================================
191 //============================================================================
196 BEGIN_EVENT_TABLE(App
, wxApp
)
197 EVT_MENU(myID_WINDOW_MINIMAL
, App::OnMinimalEditor
)
200 //----------------------------------------------------------------------------
202 //----------------------------------------------------------------------------
204 bool App::OnInit () {
206 wxInitAllImageHandlers();
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
);
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
222 // create application frame
223 m_frame
= new AppFrame (*g_appname
);
225 // open application frame
227 m_frame
->Show (true);
234 // delete global appname
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
246 //----------------------------------------------------------------------------
248 //----------------------------------------------------------------------------
250 BEGIN_EVENT_TABLE (AppFrame
, wxFrame
)
252 EVT_CLOSE ( AppFrame::OnClose
)
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
)
259 EVT_MENU (myID_PROPERTIES
, AppFrame::OnProperties
)
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
,
278 EVT_MENU (wxID_ABOUT
, AppFrame::OnAbout
)
281 AppFrame::AppFrame (const wxString
&title
)
282 : wxFrame ((wxFrame
*)NULL
, wxID_ANY
, title
, wxDefaultPosition
, wxSize(750,550),
283 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
285 SetIcon(wxICON(sample
));
287 // initialize important variables
290 // set icon and background
291 SetTitle (*g_appname
);
292 SetBackgroundColour (wxT("WHITE"));
295 m_menuBar
= new wxMenuBar
;
299 m_edit
= new Edit (this, wxID_ANY
);
302 FileOpen (wxT("stctest.cpp"));
305 AppFrame::~AppFrame () {
308 // common event handlers
309 void AppFrame::OnClose (wxCloseEvent
&event
) {
312 if (m_edit
&& m_edit
->Modified()) {
313 if (event
.CanVeto()) event
.Veto (true);
319 void AppFrame::OnAbout (wxCommandEvent
&WXUNUSED(event
)) {
323 void AppFrame::OnExit (wxCommandEvent
&WXUNUSED(event
)) {
327 // file event handlers
328 void AppFrame::OnFileOpen (wxCommandEvent
&WXUNUSED(event
)) {
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 ();
337 #endif // wxUSE_FILEDLG
340 void AppFrame::OnFileSave (wxCommandEvent
&WXUNUSED(event
)) {
342 if (!m_edit
->Modified()) {
343 wxMessageBox (_("There is nothing to save!"), _("Save file"),
344 wxOK
| wxICON_EXCLAMATION
);
350 void AppFrame::OnFileSaveAs (wxCommandEvent
&WXUNUSED(event
)) {
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
361 void AppFrame::OnFileClose (wxCommandEvent
&WXUNUSED(event
)) {
363 if (m_edit
->Modified()) {
364 if (wxMessageBox (_("Text is not saved, save before closing?"), _("Close"),
365 wxYES_NO
| wxICON_QUESTION
) == wxYES
) {
367 if (m_edit
->Modified()) {
368 wxMessageBox (_("Text could not be saved!"), _("Close abort"),
369 wxOK
| wxICON_EXCLAMATION
);
374 m_edit
->SetFilename (wxEmptyString
);
376 m_edit
->SetSavePoint();
379 // properties event handlers
380 void AppFrame::OnProperties (wxCommandEvent
&WXUNUSED(event
)) {
382 EditProperties
dlg(m_edit
, 0);
385 // print event handlers
386 void 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
396 void 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
),
403 if (!preview
->IsOk()) {
405 wxMessageBox (_("There was a problem with previewing.\n\
406 Perhaps your current printer is not correctly?"),
407 _("Previewing"), wxOK
);
410 wxRect rect
= DeterminePrintSize();
411 wxPreviewFrame
*frame
= new wxPreviewFrame (preview
, this, _("Print Preview"));
412 frame
->SetSize (rect
);
413 frame
->Centre(wxBOTH
);
416 #endif // wxUSE_PRINTING_ARCHITECTURE
419 void 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
);
432 (*g_printData
) = printer
.GetPrintDialogData().GetPrintData();
433 #endif // wxUSE_PRINTING_ARCHITECTURE
437 void AppFrame::OnEdit (wxCommandEvent
&event
) {
438 if (m_edit
) m_edit
->GetEventHandler()->ProcessEvent (event
);
442 void AppFrame::CreateMenu ()
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"));
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"));
489 wxMenu
*menuHilight
= new wxMenu
;
491 for (Nr
= 0; Nr
< g_LanguagePrefsSize
; Nr
++) {
492 menuHilight
->Append (myID_HILIGHTFIRST
+ Nr
,
493 g_LanguagePrefs
[Nr
].name
);
497 wxMenu
*menuCharset
= new wxMenu
;
498 menuCharset
->Append (myID_CHARSETANSI
, _("&ANSI (Windows)"));
499 menuCharset
->Append (myID_CHARSETMAC
, _("&MAC (Macintosh)"));
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
);
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"));
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");
531 // change case submenu
532 wxMenu
*menuChangeCase
= new wxMenu
;
533 menuChangeCase
->Append (myID_CHANGEUPPER
, _("&Upper case"));
534 menuChangeCase
->Append (myID_CHANGELOWER
, _("&Lower case"));
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)"));
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
);
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"));
557 wxMenu
*menuHelp
= new wxMenu
;
558 menuHelp
->Append (wxID_ABOUT
, _("&About ..\tShift+F1"));
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
);
570 m_menuBar
->Check(myID_ANNOTATION_STYLE_BOXED
, true);
573 void AppFrame::FileOpen (wxString fname
)
575 wxFileName
w(fname
); w
.Normalize(); fname
= w
.GetFullPath();
576 m_edit
->LoadFile (fname
);
577 m_edit
->SelectNone();
580 wxRect
AppFrame::DeterminePrintSize () {
582 wxSize scr
= wxGetDisplaySize();
584 // determine position and size (shifting 16 left and down)
585 wxRect rect
= GetRect();
588 rect
.width
= wxMin (rect
.width
, (scr
.x
- rect
.x
));
589 rect
.height
= wxMin (rect
.height
, (scr
.x
- rect
.y
));
595 //----------------------------------------------------------------------------
597 //----------------------------------------------------------------------------
599 BEGIN_EVENT_TABLE (AppAbout
, wxDialog
)
600 EVT_TIMER (myID_ABOUTTIMER
, AppAbout::OnTimerEvent
)
603 AppAbout::AppAbout (wxWindow
*parent
,
606 : wxDialog (parent
, wxID_ANY
, wxEmptyString
,
607 wxDefaultPosition
, wxDefaultSize
,
608 style
| wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
) {
612 if (milliseconds
> 0) {
613 m_timer
= new wxTimer (this, myID_ABOUTTIMER
);
614 m_timer
->Start (milliseconds
, wxTIMER_ONE_SHOT
);
617 // sets the application title
618 SetTitle (_("About .."));
621 wxGridSizer
*aboutinfo
= new wxGridSizer (2, 0, 2);
622 aboutinfo
->Add (new wxStaticText(this, wxID_ANY
, _("Written by: ")),
624 aboutinfo
->Add (new wxStaticText(this, wxID_ANY
, APP_MAINT
),
625 1, wxEXPAND
| wxALIGN_LEFT
);
626 aboutinfo
->Add (new wxStaticText(this, wxID_ANY
, _("Version: ")),
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: ")),
632 aboutinfo
->Add (new wxStaticText(this, wxID_ANY
, APP_LICENCE
),
633 1, wxEXPAND
| wxALIGN_LEFT
);
634 aboutinfo
->Add (new wxStaticText(this, wxID_ANY
, _("Copyright: ")),
636 aboutinfo
->Add (new wxStaticText(this, wxID_ANY
, APP_COPYRIGTH
),
637 1, wxEXPAND
| wxALIGN_LEFT
);
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);
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);
661 SetSizerAndFit (totalpane
);
667 AppAbout::~AppAbout () {
671 //----------------------------------------------------------------------------
673 void AppAbout::OnTimerEvent (wxTimerEvent
&WXUNUSED(event
)) {
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
682 class MinimalEditor
: public wxStyledTextCtrl
691 MinimalEditor(wxWindow
* parent
, wxWindowID id
= wxID_ANY
) : wxStyledTextCtrl(parent
, id
)
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"));
702 SetMarginType(margin_id_lineno
, wxSTC_MARGIN_NUMBER
);
703 SetMarginWidth(margin_id_lineno
, 32);
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"));
713 SetMarginMask(margin_id_fold
, wxSTC_MASK_FOLDERS
);
714 SetMarginWidth(margin_id_fold
, 32);
715 SetMarginSensitive(margin_id_fold
, true);
717 SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED
| wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED
);
721 SetWrapMode(wxSTC_WRAP_WORD
);
722 SetWrapVisualFlags(wxSTC_WRAPVISUALFLAG_END
);
724 virtual bool SetFont(const wxFont
& font
)
726 StyleSetFont(wxSTC_STYLE_DEFAULT
, (wxFont
&)font
);
727 return wxStyledTextCtrl::SetFont(font
);
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
);
751 void OnMarginClick(wxStyledTextEvent
&);
752 void OnText(wxStyledTextEvent
&);
753 DECLARE_EVENT_TABLE()
756 BEGIN_EVENT_TABLE(MinimalEditor
, wxStyledTextCtrl
)
757 EVT_STC_MARGINCLICK(wxID_ANY
, MinimalEditor::OnMarginClick
)
758 EVT_STC_CHANGE(wxID_ANY
, MinimalEditor::OnText
)
761 void MinimalEditor::OnMarginClick(wxStyledTextEvent
&event
)
763 if (event
.GetMargin() == margin_id_fold
)
765 int lineClick
= LineFromPosition(event
.GetPosition());
766 int levelClick
= GetFoldLevel(lineClick
);
767 if ((levelClick
& wxSTC_FOLDLEVELHEADERFLAG
) > 0)
769 ToggleFold(lineClick
);
774 void MinimalEditor::OnText(wxStyledTextEvent
& event
)
776 wxLogDebug(wxT("Modified"));
780 class MinimalEditorFrame
: public wxFrame
783 MinimalEditorFrame() : wxFrame(NULL
, wxID_ANY
, _("Minimal Editor"))
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
);
793 " This is xml with syntax highlighting, line numbers, folding, word wrap and context menu\n"
800 wxFrame
* App::MinimalEditor()
802 MinimalEditorFrame
* frame
= new MinimalEditorFrame
;
807 void App::OnMinimalEditor(wxCommandEvent
& WXUNUSED(event
))