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