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