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