]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUITextEditor.cxx
#3127 BBTK Feature New Normal - branch changeWx28to30 compilation with wxWidgets3
[bbtk.git] / kernel / src / bbtkWxGUITextEditor.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkWxGUITextEditor.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.22 $
34 =========================================================================*/
35
36
37
38
39 /**
40  * \brief Short description in one line
41  * 
42  * Long description which 
43  * can span multiple lines
44  */
45 /**
46  * \file 
47  * \brief 
48  */
49 /**
50  * \class bbtk::
51  * \brief 
52  */
53
54
55 #ifdef _USE_WXWIDGETS_
56
57 #include <iostream>     
58 #include "bbtkWxGUITextEditor.h"
59 #include "bbtkWxBlackBox.h"
60 #include "bbtkConfigurationFile.h"
61 #include "bbtkUtilities.h"
62
63 //#include "icons/cc_new.xpm"
64 //#include "icons/cc_open.xpm"
65 //#include "icons/cc_stop.xpm"
66 //#include "icons/cc_save.xpm"
67 //#include "icons/cc_save_as.xpm"
68 //#include "icons/cc_run.xpm"
69 //#include "icons/cc_exit.xpm"
70
71 #include "../data/icons/wxart_new.xpm"
72 #include "../data/icons/wxart_fileopen.xpm"
73 #include "../data/icons/wxart_filesave.xpm"
74 #include "../data/icons/wxart_filesaveas.xpm"
75 //#include "../data/icons/wxart_exefile.xpm"
76 //#include "../data/icons/wxart_delete.xpm"
77 //#include "../data/icons/wxart_down.xpm"
78 #include "../data/icons/wxart_run.xpm"
79 #include "../data/icons/wxart_runbbi.xpm"
80 #include "../data/icons/wxart_graphsimple.xpm"
81 #include "../data/icons/wxart_graphdetail.xpm"
82 #include "../data/icons/wxart_eldel.xpm"
83
84 namespace bbtk
85 {
86
87
88   //================================================================
89   class WxTextCtrlGettingKeyEvents : public wxTextCtrl
90   {
91   public:
92     WxTextCtrlGettingKeyEvents(wxWindow *parent, wxWindowID id, const wxString &value,
93                                const wxPoint &pos, const wxSize &size, int style = 0)
94       : wxTextCtrl(parent, id, value, pos, size, style)
95     {
96     }
97     
98     void SetWxGUITextEditor(WxGUITextEditor* e) 
99     { mWxGUITextEditor = e; }
100     
101     void OnKeyDown(wxKeyEvent& event);
102     void OnKeyUp(wxKeyEvent& event);
103     void OnChar(wxKeyEvent& event);
104   private :
105     WxGUITextEditor* mWxGUITextEditor;
106     
107     DECLARE_EVENT_TABLE()
108       };
109   
110   BEGIN_EVENT_TABLE(WxTextCtrlGettingKeyEvents, wxTextCtrl)
111     EVT_KEY_DOWN(WxTextCtrlGettingKeyEvents::OnKeyDown)
112     EVT_KEY_UP(WxTextCtrlGettingKeyEvents::OnKeyUp)
113     EVT_CHAR(WxTextCtrlGettingKeyEvents::OnChar)
114     END_EVENT_TABLE()
115     
116     
117     void WxTextCtrlGettingKeyEvents::OnChar(wxKeyEvent& event)
118   {
119     event.Skip();
120   }
121   
122   void WxTextCtrlGettingKeyEvents::OnKeyUp(wxKeyEvent& event)
123   {
124     mWxGUITextEditor->OnKeyUp(event);
125     event.Skip();
126   }
127   
128   void WxTextCtrlGettingKeyEvents::OnKeyDown(wxKeyEvent& event)
129   {
130     mWxGUITextEditor->OnKeyDown(event);
131     event.Skip();
132   }
133   //================================================================
134   
135   
136   //================================================================  
137   /*  BEGIN_EVENT_TABLE(WxGUITextEditorPage, wxPanel)
138     EVT_CLOSE(WxGUITextEditorPage::OnClose)
139     END_EVENT_TABLE()
140   */
141  
142   //================================================================
143   WxGUITextEditorPage::WxGUITextEditorPage(wxWindow* parent,
144                                                WxGUITextEditor* editor)
145     : wxPanel(parent,-1),
146       mEditor(editor),
147       mName(""),
148       mAskFilename(true)
149   {  
150
151           //      std::cout << "WxGUITextEditorPage::WxGUITextEditorPage("<<mName<<")"<<std::endl;
152
153     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
154  
155     mwxInputText = 
156                 
157       new WxTextCtrlGettingKeyEvents(this,
158                                      -1, //ID_InputText,
159                                      _T(""),
160                                      wxDefaultPosition,
161                                      wxDefaultSize,
162                                      wxTE_MULTILINE 
163                                      //    |wxTE_PROCESS_ENTER
164                                      //| wxTE_PROCESS_TAB 
165                                      //             | wxWANTS_CHARS 
166                                     // |  wxTAB_TRAVERSAL
167                                      );
168     mwxInputText->SetWxGUITextEditor(mEditor);
169     /*
170         new wxTextCtrl(this,-1,_T(""),
171                 wxDefaultPosition,
172                                              wxDefaultSize,
173                                              wxTE_MULTILINE 
174                                              //    |wxTE_PROCESS_ENTER
175                                         //       | wxTE_PROCESS_TAB 
176                                 //                  | wxWANTS_CHARS 
177                                  //    |  wxTAB_TRAVERSAL
178                                      );
179                                          */
180     mFixedFont = new wxFont(10,
181                                    wxFONTFAMILY_MODERN,
182                                    wxFONTSTYLE_NORMAL,
183                                    wxFONTWEIGHT_NORMAL,
184                                    false);
185     
186     mwxInputTextAttr = new wxTextAttr;
187     mwxInputTextAttr->SetFont(*mFixedFont);
188    
189     sizer->Add(mwxInputText,1,wxGROW);
190     SetSizer(sizer);
191     SetAutoLayout(true);
192     Layout();
193   }
194   //================================================================
195
196   //================================================================
197   WxGUITextEditorPage::~WxGUITextEditorPage()
198   {
199           delete mwxInputTextAttr;
200           delete mFixedFont;
201   }
202   //================================================================
203
204   bool WxGUITextEditorPage::IsModified()
205    { return mwxInputText->IsModified(); }
206
207   std::string WxGUITextEditorPage::GetText()
208   {
209     return wx2std(GetTextCtrl()->GetValue());
210   }
211
212   //================================================================
213   void WxGUITextEditorPage::Load(const std::string& filename)
214   {
215     //    std::cout << "-------------- LOAD ---------------"<<std::endl;
216     //    std::cout << "'" << filename << "'"<<std::endl;
217     //std::string oldFilename = mFilename;
218     mName = filename;
219     mAskFilename = false;
220     mwxInputText->LoadFile(std2wx(mName));
221   }
222   //================================================================
223
224   //================================================================
225   void WxGUITextEditorPage::Save(const std::string& filter)
226   {
227     //    std::cout << "-------------- SAVE ---------------"<<std::endl;
228     if (mAskFilename)
229       {
230
231 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
232 #if wxMAJOR_VERSION <= 2
233         wxFileDialog* fd = new wxFileDialog(this,_T("Save file"),_T(""),
234                                             _T(""),std2wx(filter),
235                                             wxSAVE | wxOVERWRITE_PROMPT );
236 #else
237         wxFileDialog* fd = new wxFileDialog(this,_T("Save file"),_T(""),
238                                             _T(""),std2wx(filter),
239                                             wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
240 #endif
241
242         int result_fd = fd->ShowModal();
243     
244         // This line is need it by windows // EED
245         fd->SetReturnCode( result_fd );
246
247         if (fd->GetReturnCode()==wxID_OK)
248           {
249             mName = wx2std(fd->GetPath());
250             mAskFilename = false;
251           }
252         else 
253           {
254             //      std::cout << "-------------- CANCELLED ---------------"
255             //                <<std::endl;
256             return;
257           } 
258       }
259     //    std::cout << "file [" << mName << "]" <<std::endl;
260 //    mwxInputText->SaveFile(std2wx(mName));
261         SaveFile(mName);
262     mwxInputText->SetModified(false);
263   }
264   //================================================================
265   
266
267         //================================================================
268         void WxGUITextEditorPage::SaveFile(const std::string& filename)
269         {
270                 mwxInputText->SaveFile( std2wx(filename) );
271         }
272         //================================================================
273         
274         
275
276
277
278
279
280
281
282
283
284
285   //================================================================
286   // WxGUITextEditor
287   //================================================================
288
289
290   //================================================================
291   WxGUITextEditor::WxGUITextEditor( wxWindow *parent,
292                                     WxGUITextEditorUser* user )
293     : wxPanel(parent, -1),
294       mUser(user),
295       mFileNameFilter("*.*")
296   {
297   //  m_mgr.SetManagedWindow(this);
298                     //    wxInitAllImageHandlers();
299      
300         //  std::cout << "WxGUITextEditor::WxGUITextEditor"<<std::endl;
301
302       wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
303
304     mwxNotebook = new wxNotebook(this,-1,
305                 wxDefaultPosition, wxDefaultSize, 
306                 wxNB_TOP 
307
308                 
309                 );
310                 
311    sizer->Add(mwxNotebook,1,wxGROW);
312
313                 
314                 /*
315    mwxNotebook =                new wxAuiNotebook(this,  
316                                     -1,
317                                     wxPoint(0, 0),
318                                     wxSize(500,500),
319                                     wxAUI_NB_TAB_SPLIT 
320                                     | wxAUI_NB_TAB_MOVE
321                                     | wxAUI_NB_TAB_EXTERNAL_MOVE
322                                     | wxAUI_NB_WINDOWLIST_BUTTON
323                                     |wxAUI_NB_SCROLL_BUTTONS
324                                     // | wxAUI_NB_CLOSE_BUTTON 
325                                     | wxAUI_NB_CLOSE_ON_ACTIVE_TAB
326                                     //| wxAUI_NB_CLOSE_ON_ALL_TABS
327                                     | wxNO_BORDER);
328     
329     m_mgr.AddPane(mwxNotebook,
330                   wxAuiPaneInfo().Name(wxT("notebook"))
331                   .Caption(wxT(""))
332                   .CaptionVisible(false)
333                   .MinimizeButton(false)
334                   .MaximizeButton(false)
335                   .CloseButton(false)
336                   //              .Dockable(false).Float()
337                   .Center()
338                   .MinSize(wxSize(100,50))
339                   );   
340 */
341  
342     /*   
343     wxBitmap bmp_new(cc_new_xpm);
344     wxBitmap bmp_open(cc_open_xpm);
345     wxBitmap bmp_close(cc_stop_xpm);
346     wxBitmap bmp_save(cc_save_xpm);
347     wxBitmap bmp_saveas(cc_save_as_xpm);
348     wxBitmap bmp_run(cc_run_xpm);
349     */
350     wxBitmap bmp_new(new_xpm);
351     wxBitmap bmp_open(fileopen_xpm);
352     wxBitmap bmp_close(eldel_xpm);
353     wxBitmap bmp_save(filesave_xpm);
354     wxBitmap bmp_saveas(filesaveas_xpm);
355     wxBitmap bmp_run(wxart_run_xpm);
356     wxBitmap bmp_runbbi(wxart_runbbi_xpm);
357     wxBitmap bmp_graphsimple(wxart_graphsimple_xpm);
358         wxBitmap bmp_graphdetail(wxart_graphdetail_xpm);
359
360     mwxToolBar = new wxToolBar(this, wxID_ANY, 
361                                wxDefaultPosition, wxDefaultSize,
362                                wxTB_FLAT | wxTB_NODIVIDER);
363     
364     mwxToolBar->AddTool(ID_ButtonNew, _T("New"),
365                      bmp_new, wxNullBitmap, wxITEM_NORMAL,
366                      _T("New file"), _T("Create a new file"));
367     mwxToolBar->AddTool(ID_ButtonOpen, _T("Open"),
368                      bmp_open, wxNullBitmap, wxITEM_NORMAL,
369                      _T("Open file"), _T("This is help for new file tool"));
370     mwxToolBar->AddTool(ID_ButtonClose, _T("Close"),
371                      bmp_close, wxNullBitmap, wxITEM_NORMAL,
372                      _T("Close file"), _T("Close current file"));
373     mwxToolBar->AddTool(ID_ButtonSave, _T("New"),
374                      bmp_save, wxNullBitmap, wxITEM_NORMAL,
375                      _T("Save file"), _T("Save current file"));
376     mwxToolBar->AddTool(ID_ButtonSaveAs, _T("New"),
377                      bmp_saveas, wxNullBitmap, wxITEM_NORMAL,
378                      _T("Save file as"), _T("Save current file as"));
379     mwxToolBar->AddTool(ID_ButtonRun, _T("Run"),
380                      bmp_run, wxNullBitmap, wxITEM_NORMAL,
381                      _T("Run file"), _T("Run current file"));
382
383           
384         mwxToolBar->AddTool(ID_ButtonGraphSimple, _T("Graph (simple)"),
385                                                   bmp_graphsimple, wxNullBitmap, wxITEM_NORMAL,
386                                                   _T("Graph simple"), _T("Simple graph of actual script"));
387
388         mwxToolBar->AddTool(ID_ButtonGraphDetail, _T("Graph (detail)"),
389                                                   bmp_graphdetail, wxNullBitmap, wxITEM_NORMAL,
390                                                   _T("Graph (detail)"), _T("Detail graph of actual script"));
391           
392         mwxToolBar->AddTool(ID_ButtonRunBBI, _T("Run external bbi "),
393                                                   bmp_runbbi, wxNullBitmap, wxITEM_NORMAL,
394                                                   _T("Run external bbi"), _T("Run external bbi"));
395           
396           
397           
398     mwxToolBar->AddSeparator();
399     mwxPosition = new wxStaticText ( mwxToolBar, -1, _T(""));
400     mwxToolBar->AddControl(mwxPosition);
401     mwxToolBar->Realize();
402
403           sizer->Add(mwxToolBar,0,wxGROW);
404
405         /*
406     m_mgr.AddPane(mwxToolBar, 
407                   wxAuiPaneInfo().Name(wxT("toolBar"))
408                   .Caption(wxT(""))
409                   .ToolbarPane()
410                   .Bottom()
411                   .MinSize(wxSize(100,50))
412                   .LeftDockable(false).RightDockable(false)
413                   );   
414 */
415   SetSizer(sizer);
416   
417     
418 //    m_mgr.Update();
419     SetAutoLayout(true);
420     Layout();
421
422     NewPage("");
423     UpdateInfo();
424
425   }
426   //================================================================
427   
428   //================================================================
429   WxGUITextEditor::~WxGUITextEditor()
430   {
431   //  m_mgr.UnInit();
432
433     //    delete mInterpreter;
434   }
435   //================================================================
436
437   //================================================================
438   void WxGUITextEditor::NewPage(const std::string& filename)
439   {
440    WxGUITextEditorPage* page = 
441       new WxGUITextEditorPage(mwxNotebook,this);
442     std::string name("untitled");
443     if (filename.size()!=0) 
444       {
445         name = filename;
446         page->Load(name);
447       }
448     page->SetPageName(name);
449     std::string fname = Utilities::get_file_name(name);
450     mwxNotebook->AddPage(page,std2wx(fname),true);
451     FocusOnCurrentPage();
452   }
453   //================================================================
454
455   //================================================================
456   WxGUITextEditorPage* WxGUITextEditor::GetCurrentPage()
457   {
458     return (WxGUITextEditorPage*)
459       mwxNotebook->GetPage(mwxNotebook->GetSelection());
460   }
461   //================================================================
462
463   //================================================================
464   void WxGUITextEditor::FocusOnCurrentPage()
465   {
466     if (mwxNotebook->GetPageCount()==0) return;
467     GetCurrentPage()->SetFocus();    
468   }
469   //================================================================
470
471   //================================================================  
472   void WxGUITextEditor::OnToolLeftClick(wxCommandEvent& event)
473   {
474     switch (event.GetId())
475       {
476       case ID_ButtonNew :
477         New(); 
478         FocusOnCurrentPage();
479         break;
480       case ID_ButtonOpen :
481         Open(); 
482         FocusOnCurrentPage();
483         break;
484       case ID_ButtonClose :
485         CloseCurrentPage();
486         break;
487       case ID_ButtonSave :
488         SaveCurrentPage();
489         break;
490       case ID_ButtonSaveAs :
491         if (mwxNotebook->GetPageCount()==0) break;  
492         GetCurrentPage()->SetAskFilename(true);
493         SaveCurrentPage();
494         break;
495       case ID_ButtonRun :
496         if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
497           mUser->WxGUITextEditorRun();
498         FocusOnCurrentPage();
499         break;
500                           
501                   case ID_ButtonGraphSimple :
502                           if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
503                                   mUser->WxGUITextEditorGraphSimple();
504                           FocusOnCurrentPage();
505                           break;
506
507                   case ID_ButtonGraphDetail :
508                           if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
509                                   mUser->WxGUITextEditorGraphDetail();
510                           FocusOnCurrentPage();
511                           break;
512                           
513                   case ID_ButtonRunBBI :
514                           if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
515                                   mUser->WxGUITextEditorRunBBI();
516                           FocusOnCurrentPage();
517                           break;
518                           
519       }
520   }
521   //================================================================  
522
523   //================================================================  
524   void WxGUITextEditor::OnToolRightClick(wxCommandEvent& event)
525   {
526   }
527   //================================================================  
528
529   //================================================================  
530   void WxGUITextEditor::New()
531   {
532     NewPage("");
533     UpdateInfo();
534   }
535   //================================================================
536
537   //================================================================  
538   void WxGUITextEditor::Open()
539   {
540     //    std::cout << "-------------- OPEN ---------------"<<std::endl;
541
542 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
543 #if wxMAJOR_VERSION <= 2
544     wxFileDialog* fd = new wxFileDialog(this,_T("Open file"),_T(""),
545                                         _T(""),std2wx(mFileNameFilter),
546                                         wxOPEN | wxFILE_MUST_EXIST );
547 #else
548     wxFileDialog* fd = new wxFileDialog(this,_T("Open file"),_T(""),
549                                         _T(""),std2wx(mFileNameFilter),
550                                         wxFD_OPEN | wxFD_FILE_MUST_EXIST );
551 #endif
552     int result_fd = fd->ShowModal();
553
554         // This line is need it by windows //EED
555         fd->SetReturnCode( result_fd );
556
557     if (fd->GetReturnCode()==wxID_OK)
558       {
559         std::string filename = wx2std(fd->GetPath());
560         std::cout << "file [" << filename << "]" <<std::endl;
561         Open(filename);
562       }
563     else 
564       {
565         //      std::cout << "-------------- CANCELLED ---------------"<<std::endl;
566       }
567   }
568   //================================================================  
569   
570   //================================================================  
571   void WxGUITextEditor::Open(const std::string& filename)
572   {
573     NewPage(filename);
574     UpdateInfo();
575   }
576   //================================================================  
577
578
579   //================================================================  
580   bool WxGUITextEditor::CloseCurrentPage()
581   {
582     if (mwxNotebook->GetPageCount()==0) return true;
583
584     if (GetCurrentPage()->IsModified()) 
585       {
586         wxString mess = std2wx(GetCurrentPage()->GetPageName());
587         mess += _T(" modified. Save it ?");
588         wxMessageDialog* d = 
589           new wxMessageDialog(this,
590                               mess, 
591                               _T("Save buffer"), 
592                               wxYES_NO | wxCANCEL | wxICON_QUESTION);
593         switch (d->ShowModal())
594           {
595           case wxID_CANCEL : 
596             return false;
597             break;
598           case wxID_YES : 
599             GetCurrentPage()->Save(mFileNameFilter); 
600             break;
601           case wxID_NO : ;
602           }       
603       } 
604     mwxNotebook->DeletePage(mwxNotebook->GetSelection());
605     FocusOnCurrentPage();
606     return true;
607   }
608   //================================================================  
609
610   //================================================================  
611   bool WxGUITextEditor::CloseAllPages()
612   {
613     bool ok = true;
614     while (mwxNotebook->GetPageCount()!=0)
615       {
616         if (!CloseCurrentPage()) 
617           {
618             ok = false;
619             break;
620           }
621       }
622     return ok;
623   }
624   //================================================================  
625
626   //================================================================  
627   void WxGUITextEditor::SaveCurrentPage()
628   {
629     if (mwxNotebook->GetPageCount()==0) return;  
630     GetCurrentPage()->Save(mFileNameFilter);
631     mwxNotebook->SetPageText(mwxNotebook->GetSelection(),
632                              std2wx(GetCurrentPage()->GetPageName()));
633   }
634   //================================================================  
635
636
637   //================================================================  
638   void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt)
639   {
640     if (!CloseCurrentPage()) evt.Veto();
641   }
642   //================================================================
643
644
645
646   /*
647   //================================================================  
648   void WxGUITextEditor::OnButtonQuit(wxCommandEvent& event) 
649   { 
650     Quit(); 
651     FocusOnCurrentPage();
652   }
653   void WxGUITextEditor::Quit()
654   {
655     std::cout << "-------------- QUIT ---------------"<<std::endl;
656     if (AskSave()) GetParent()->Close();
657   }
658   //================================================================  
659   */
660
661   //================================================================  
662
663   /*
664   void WxGUITextEditor::Run()
665   {
666     std::cout << "-------------- RUN ---------------"<<std::endl;
667
668     if (!mwxSplit->IsSplit()) 
669       {
670         int size = -100;
671         int minsize = - (int)(mwxInputText->GetSize().GetHeight() / 2.);
672         if (size<minsize) size = minsize;
673         mwxSplit->SplitHorizontally( mwxInputText, mwxOutputText, size);
674       }
675
676     std::stringstream* buffer = new std::stringstream(bbtk::wx2std(mwxInputText->GetValue()));
677     mInterpreter->InterpretLine("reset");
678     try 
679       {
680         mInterpreter->InterpretBuffer(buffer);
681       }
682     catch (...)
683       {
684       }
685   } 
686   //================================================================  
687 */
688   
689  
690   
691   //================================================================
692   
693
694   //================================================================
695   void WxGUITextEditor::UpdateInfo()
696   {
697     if (mwxNotebook->GetPageCount()==0) return;
698     WxTextCtrlGettingKeyEvents* text = GetCurrentPage()->GetTextCtrl();
699     
700     long line, column, pos;
701     pos = text->GetInsertionPoint();
702     text->PositionToXY(pos, &column, &line);
703     
704     
705     //                wxLogMessage(_T("Current position: %ld\nCurrent line, column: (%ld, %ld)\nNumber of lines: %ld\nCurrent line length: %ld\nTotal text length: %u (%ld)"),
706     
707     
708     char mess[200];
709     sprintf(mess,"%ld:%ld/%ld:%ld",
710             line+1,column+1,
711             (long)text->GetNumberOfLines(),
712             (long)text->GetLineLength(line)+1);
713     //       pos+1,
714     //       (long)mwxInputText->GetValue().length())+1;
715     
716    // mwxPosition->SetLabel(wxString(mess));
717     mwxPosition->SetLabel(std2wx(mess));    
718     mwxPosition->Show();
719     
720     if (text->IsModified()) 
721       {
722         std::string title("*");
723         title += GetCurrentPage()->GetPageName();
724         mwxNotebook->SetPageText(mwxNotebook->GetSelection(),std2wx(title));
725       }
726   }
727   //================================================================
728   //================================================================
729   void WxGUITextEditor::OnKeyUp(wxKeyEvent& event)
730   {
731   //    std::cout << "U" << std::endl;
732     UpdateInfo();
733   }
734   //================================================================
735
736   //================================================================
737   void WxGUITextEditor::OnKeyDown(wxKeyEvent& event)
738   {
739      //   std::cout << "D" << std::endl;
740     // std::cout << "Key="<<event.GetKeyCode()<<std::endl;
741     if ( event.ControlDown() )
742       {
743         switch (event.GetKeyCode())
744           {
745           case 'n': case 'N' : New(); break;
746           case 's': case 'S' : SaveCurrentPage(); break;
747           case 'o': case 'O' : Open(); break;
748             //    case 'r': case 'R' : Run(); break;
749             //    case 'q': case 'Q' : Quit(); break;
750           }
751       }
752   }
753   //================================================================
754   
755   //================================================================  
756   BEGIN_EVENT_TABLE(WxGUITextEditor, wxPanel)
757     EVT_MENU(wxID_ANY,  WxGUITextEditor::OnToolLeftClick)
758     EVT_TOOL_RCLICKED(wxID_ANY,  WxGUITextEditor::OnToolRightClick)
759     EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, WxGUITextEditor::OnPageClose)
760     END_EVENT_TABLE()
761   //================================================================
762     
763
764
765
766   
767   //================================================================
768   WxGUITextEditorWindow::WxGUITextEditorWindow( wxWindow *parent, 
769                                                     wxString title, 
770                                                     wxSize size)
771     : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
772   {     
773     
774     
775     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
776
777     mEditor = new WxGUITextEditor(this);
778     sizer->Add(mEditor,1,wxGROW);
779     
780     //    WxGUICommand* com = new WxGUICommand(this,this);
781     //    sizer->Add(com);
782     
783     SetSizer(sizer);
784
785     // parent window of all bbtk windows will be a child of this
786     //    Wx::SetTopWindowParent(this);
787     Wx::SetTopWindow(this);
788     // Add the method OnWxSignal as a Wx::Signal observer 
789     //bbtkAddWxSignalObserver(WxGUITextEditorWindow::OnWxSignal);
790     
791    
792     SetAutoLayout(true);
793     Layout();
794   }
795   //================================================================
796
797   //================================================================
798   WxGUITextEditorWindow::~WxGUITextEditorWindow()
799   {
800   }
801   //================================================================
802
803
804 } // namespace bbtk
805
806
807 #endif //_USE_WXWIDGETS_