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