stctest.cpp 27 KB

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