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