]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUITextEditor.cxx
Feature #1774
[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         wxFileDialog* fd = new wxFileDialog(this,_T("Save file"),_T(""),
231                                             _T(""),std2wx(filter),
232                                             wxSAVE | wxOVERWRITE_PROMPT );
233         int result_fd = fd->ShowModal();
234     
235         // This line is need it by windows // EED
236         fd->SetReturnCode( result_fd );
237
238         if (fd->GetReturnCode()==wxID_OK)
239           {
240             mName = wx2std(fd->GetPath());
241             mAskFilename = false;
242           }
243         else 
244           {
245             //      std::cout << "-------------- CANCELLED ---------------"
246             //                <<std::endl;
247             return;
248           } 
249       }
250     //    std::cout << "file [" << mName << "]" <<std::endl;
251 //    mwxInputText->SaveFile(std2wx(mName));
252         SaveFile(mName);
253     mwxInputText->SetModified(false);
254   }
255   //================================================================
256   
257
258         //================================================================
259         void WxGUITextEditorPage::SaveFile(const std::string& filename)
260         {
261                 mwxInputText->SaveFile( std2wx(filename) );
262         }
263         //================================================================
264         
265         
266
267
268
269
270
271
272
273
274
275
276   //================================================================
277   // WxGUITextEditor
278   //================================================================
279
280
281   //================================================================
282   WxGUITextEditor::WxGUITextEditor( wxWindow *parent,
283                                     WxGUITextEditorUser* user )
284     : wxPanel(parent, -1),
285       mUser(user),
286       mFileNameFilter("*.*")
287   {
288   //  m_mgr.SetManagedWindow(this);
289                     //    wxInitAllImageHandlers();
290      
291         //  std::cout << "WxGUITextEditor::WxGUITextEditor"<<std::endl;
292
293       wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
294
295     mwxNotebook = new wxNotebook(this,-1,
296                 wxDefaultPosition, wxDefaultSize, 
297                 wxNB_TOP 
298
299                 
300                 );
301                 
302    sizer->Add(mwxNotebook,1,wxGROW);
303
304                 
305                 /*
306    mwxNotebook =                new wxAuiNotebook(this,  
307                                     -1,
308                                     wxPoint(0, 0),
309                                     wxSize(500,500),
310                                     wxAUI_NB_TAB_SPLIT 
311                                     | wxAUI_NB_TAB_MOVE
312                                     | wxAUI_NB_TAB_EXTERNAL_MOVE
313                                     | wxAUI_NB_WINDOWLIST_BUTTON
314                                     |wxAUI_NB_SCROLL_BUTTONS
315                                     // | wxAUI_NB_CLOSE_BUTTON 
316                                     | wxAUI_NB_CLOSE_ON_ACTIVE_TAB
317                                     //| wxAUI_NB_CLOSE_ON_ALL_TABS
318                                     | wxNO_BORDER);
319     
320     m_mgr.AddPane(mwxNotebook,
321                   wxAuiPaneInfo().Name(wxT("notebook"))
322                   .Caption(wxT(""))
323                   .CaptionVisible(false)
324                   .MinimizeButton(false)
325                   .MaximizeButton(false)
326                   .CloseButton(false)
327                   //              .Dockable(false).Float()
328                   .Center()
329                   .MinSize(wxSize(100,50))
330                   );   
331 */
332  
333     /*   
334     wxBitmap bmp_new(cc_new_xpm);
335     wxBitmap bmp_open(cc_open_xpm);
336     wxBitmap bmp_close(cc_stop_xpm);
337     wxBitmap bmp_save(cc_save_xpm);
338     wxBitmap bmp_saveas(cc_save_as_xpm);
339     wxBitmap bmp_run(cc_run_xpm);
340     */
341     wxBitmap bmp_new(new_xpm);
342     wxBitmap bmp_open(fileopen_xpm);
343     wxBitmap bmp_close(eldel_xpm);
344     wxBitmap bmp_save(filesave_xpm);
345     wxBitmap bmp_saveas(filesaveas_xpm);
346     wxBitmap bmp_run(wxart_run_xpm);
347     wxBitmap bmp_runbbi(wxart_runbbi_xpm);
348     wxBitmap bmp_graphsimple(wxart_graphsimple_xpm);
349         wxBitmap bmp_graphdetail(wxart_graphdetail_xpm);
350
351     mwxToolBar = new wxToolBar(this, wxID_ANY, 
352                                wxDefaultPosition, wxDefaultSize,
353                                wxTB_FLAT | wxTB_NODIVIDER);
354     
355     mwxToolBar->AddTool(ID_ButtonNew, _T("New"),
356                      bmp_new, wxNullBitmap, wxITEM_NORMAL,
357                      _T("New file"), _T("Create a new file"));
358     mwxToolBar->AddTool(ID_ButtonOpen, _T("Open"),
359                      bmp_open, wxNullBitmap, wxITEM_NORMAL,
360                      _T("Open file"), _T("This is help for new file tool"));
361     mwxToolBar->AddTool(ID_ButtonClose, _T("Close"),
362                      bmp_close, wxNullBitmap, wxITEM_NORMAL,
363                      _T("Close file"), _T("Close current file"));
364     mwxToolBar->AddTool(ID_ButtonSave, _T("New"),
365                      bmp_save, wxNullBitmap, wxITEM_NORMAL,
366                      _T("Save file"), _T("Save current file"));
367     mwxToolBar->AddTool(ID_ButtonSaveAs, _T("New"),
368                      bmp_saveas, wxNullBitmap, wxITEM_NORMAL,
369                      _T("Save file as"), _T("Save current file as"));
370     mwxToolBar->AddTool(ID_ButtonRun, _T("Run"),
371                      bmp_run, wxNullBitmap, wxITEM_NORMAL,
372                      _T("Run file"), _T("Run current file"));
373
374           
375         mwxToolBar->AddTool(ID_ButtonGraphSimple, _T("Graph (simple)"),
376                                                   bmp_graphsimple, wxNullBitmap, wxITEM_NORMAL,
377                                                   _T("Graph simple"), _T("Simple graph of actual script"));
378
379         mwxToolBar->AddTool(ID_ButtonGraphDetail, _T("Graph (detail)"),
380                                                   bmp_graphdetail, wxNullBitmap, wxITEM_NORMAL,
381                                                   _T("Graph (detail)"), _T("Detail graph of actual script"));
382           
383         mwxToolBar->AddTool(ID_ButtonRunBBI, _T("Run external bbi "),
384                                                   bmp_runbbi, wxNullBitmap, wxITEM_NORMAL,
385                                                   _T("Run external bbi"), _T("Run external bbi"));
386           
387           
388           
389     mwxToolBar->AddSeparator();
390     mwxPosition = new wxStaticText ( mwxToolBar, -1, _T(""));
391     mwxToolBar->AddControl(mwxPosition);
392     mwxToolBar->Realize();
393
394           sizer->Add(mwxToolBar,0,wxGROW);
395
396         /*
397     m_mgr.AddPane(mwxToolBar, 
398                   wxAuiPaneInfo().Name(wxT("toolBar"))
399                   .Caption(wxT(""))
400                   .ToolbarPane()
401                   .Bottom()
402                   .MinSize(wxSize(100,50))
403                   .LeftDockable(false).RightDockable(false)
404                   );   
405 */
406   SetSizer(sizer);
407   
408     
409 //    m_mgr.Update();
410     SetAutoLayout(true);
411     Layout();
412
413     NewPage("");
414     UpdateInfo();
415
416   }
417   //================================================================
418   
419   //================================================================
420   WxGUITextEditor::~WxGUITextEditor()
421   {
422   //  m_mgr.UnInit();
423
424     //    delete mInterpreter;
425   }
426   //================================================================
427
428   //================================================================
429   void WxGUITextEditor::NewPage(const std::string& filename)
430   {
431    WxGUITextEditorPage* page = 
432       new WxGUITextEditorPage(mwxNotebook,this);
433     std::string name("untitled");
434     if (filename.size()!=0) 
435       {
436         name = filename;
437         page->Load(name);
438       }
439     page->SetPageName(name);
440     std::string fname = Utilities::get_file_name(name);
441     mwxNotebook->AddPage(page,std2wx(fname),true);
442     FocusOnCurrentPage();
443   }
444   //================================================================
445
446   //================================================================
447   WxGUITextEditorPage* WxGUITextEditor::GetCurrentPage()
448   {
449     return (WxGUITextEditorPage*)
450       mwxNotebook->GetPage(mwxNotebook->GetSelection());
451   }
452   //================================================================
453
454   //================================================================
455   void WxGUITextEditor::FocusOnCurrentPage()
456   {
457     if (mwxNotebook->GetPageCount()==0) return;
458     GetCurrentPage()->SetFocus();    
459   }
460   //================================================================
461
462   //================================================================  
463   void WxGUITextEditor::OnToolLeftClick(wxCommandEvent& event)
464   {
465     switch (event.GetId())
466       {
467       case ID_ButtonNew :
468         New(); 
469         FocusOnCurrentPage();
470         break;
471       case ID_ButtonOpen :
472         Open(); 
473         FocusOnCurrentPage();
474         break;
475       case ID_ButtonClose :
476         CloseCurrentPage();
477         break;
478       case ID_ButtonSave :
479         SaveCurrentPage();
480         break;
481       case ID_ButtonSaveAs :
482         if (mwxNotebook->GetPageCount()==0) break;  
483         GetCurrentPage()->SetAskFilename(true);
484         SaveCurrentPage();
485         break;
486       case ID_ButtonRun :
487         if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
488           mUser->WxGUITextEditorRun();
489         FocusOnCurrentPage();
490         break;
491                           
492                   case ID_ButtonGraphSimple :
493                           if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
494                                   mUser->WxGUITextEditorGraphSimple();
495                           FocusOnCurrentPage();
496                           break;
497
498                   case ID_ButtonGraphDetail :
499                           if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
500                                   mUser->WxGUITextEditorGraphDetail();
501                           FocusOnCurrentPage();
502                           break;
503                           
504                   case ID_ButtonRunBBI :
505                           if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
506                                   mUser->WxGUITextEditorRunBBI();
507                           FocusOnCurrentPage();
508                           break;
509                           
510       }
511   }
512   //================================================================  
513
514   //================================================================  
515   void WxGUITextEditor::OnToolRightClick(wxCommandEvent& event)
516   {
517   }
518   //================================================================  
519
520   //================================================================  
521   void WxGUITextEditor::New()
522   {
523     NewPage("");
524     UpdateInfo();
525   }
526   //================================================================
527
528   //================================================================  
529   void WxGUITextEditor::Open()
530   {
531     //    std::cout << "-------------- OPEN ---------------"<<std::endl;
532
533     wxFileDialog* fd = new wxFileDialog(this,_T("Open file"),_T(""),
534                                         _T(""),std2wx(mFileNameFilter),
535                                         wxOPEN | wxFILE_MUST_EXIST );
536     int result_fd = fd->ShowModal();
537
538         // This line is need it by windows //EED
539         fd->SetReturnCode( result_fd );
540
541     if (fd->GetReturnCode()==wxID_OK)
542       {
543         std::string filename = wx2std(fd->GetPath());
544         std::cout << "file [" << filename << "]" <<std::endl;
545         Open(filename);
546       }
547     else 
548       {
549         //      std::cout << "-------------- CANCELLED ---------------"<<std::endl;
550       }
551   }
552   //================================================================  
553   
554   //================================================================  
555   void WxGUITextEditor::Open(const std::string& filename)
556   {
557     NewPage(filename);
558     UpdateInfo();
559   }
560   //================================================================  
561
562
563   //================================================================  
564   bool WxGUITextEditor::CloseCurrentPage()
565   {
566     if (mwxNotebook->GetPageCount()==0) return true;
567
568     if (GetCurrentPage()->IsModified()) 
569       {
570         wxString mess = std2wx(GetCurrentPage()->GetPageName());
571         mess += _T(" modified. Save it ?");
572         wxMessageDialog* d = 
573           new wxMessageDialog(this,
574                               mess, 
575                               _T("Save buffer"), 
576                               wxYES_NO | wxCANCEL | wxICON_QUESTION);
577         switch (d->ShowModal())
578           {
579           case wxID_CANCEL : 
580             return false;
581             break;
582           case wxID_YES : 
583             GetCurrentPage()->Save(mFileNameFilter); 
584             break;
585           case wxID_NO : ;
586           }       
587       } 
588     mwxNotebook->DeletePage(mwxNotebook->GetSelection());
589     FocusOnCurrentPage();
590     return true;
591   }
592   //================================================================  
593
594   //================================================================  
595   bool WxGUITextEditor::CloseAllPages()
596   {
597     bool ok = true;
598     while (mwxNotebook->GetPageCount()!=0)
599       {
600         if (!CloseCurrentPage()) 
601           {
602             ok = false;
603             break;
604           }
605       }
606     return ok;
607   }
608   //================================================================  
609
610   //================================================================  
611   void WxGUITextEditor::SaveCurrentPage()
612   {
613     if (mwxNotebook->GetPageCount()==0) return;  
614     GetCurrentPage()->Save(mFileNameFilter);
615     mwxNotebook->SetPageText(mwxNotebook->GetSelection(),
616                              std2wx(GetCurrentPage()->GetPageName()));
617   }
618   //================================================================  
619
620
621   //================================================================  
622   void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt)
623   {
624     if (!CloseCurrentPage()) evt.Veto();
625   }
626   //================================================================
627
628
629
630   /*
631   //================================================================  
632   void WxGUITextEditor::OnButtonQuit(wxCommandEvent& event) 
633   { 
634     Quit(); 
635     FocusOnCurrentPage();
636   }
637   void WxGUITextEditor::Quit()
638   {
639     std::cout << "-------------- QUIT ---------------"<<std::endl;
640     if (AskSave()) GetParent()->Close();
641   }
642   //================================================================  
643   */
644
645   //================================================================  
646
647   /*
648   void WxGUITextEditor::Run()
649   {
650     std::cout << "-------------- RUN ---------------"<<std::endl;
651
652     if (!mwxSplit->IsSplit()) 
653       {
654         int size = -100;
655         int minsize = - (int)(mwxInputText->GetSize().GetHeight() / 2.);
656         if (size<minsize) size = minsize;
657         mwxSplit->SplitHorizontally( mwxInputText, mwxOutputText, size);
658       }
659
660     std::stringstream* buffer = new std::stringstream(bbtk::wx2std(mwxInputText->GetValue()));
661     mInterpreter->InterpretLine("reset");
662     try 
663       {
664         mInterpreter->InterpretBuffer(buffer);
665       }
666     catch (...)
667       {
668       }
669   } 
670   //================================================================  
671 */
672   
673  
674   
675   //================================================================
676   
677
678   //================================================================
679   void WxGUITextEditor::UpdateInfo()
680   {
681     if (mwxNotebook->GetPageCount()==0) return;
682     WxTextCtrlGettingKeyEvents* text = GetCurrentPage()->GetTextCtrl();
683     
684     long line, column, pos;
685     pos = text->GetInsertionPoint();
686     text->PositionToXY(pos, &column, &line);
687     
688     
689     //                wxLogMessage(_T("Current position: %ld\nCurrent line, column: (%ld, %ld)\nNumber of lines: %ld\nCurrent line length: %ld\nTotal text length: %u (%ld)"),
690     
691     
692     char mess[200];
693     sprintf(mess,"%ld:%ld/%ld:%ld",
694             line+1,column+1,
695             (long)text->GetNumberOfLines(),
696             (long)text->GetLineLength(line)+1);
697     //       pos+1,
698     //       (long)mwxInputText->GetValue().length())+1;
699     
700    // mwxPosition->SetLabel(wxString(mess));
701     mwxPosition->SetLabel(std2wx(mess));    
702     mwxPosition->Show();
703     
704     if (text->IsModified()) 
705       {
706         std::string title("*");
707         title += GetCurrentPage()->GetPageName();
708         mwxNotebook->SetPageText(mwxNotebook->GetSelection(),std2wx(title));
709       }
710   }
711   //================================================================
712   //================================================================
713   void WxGUITextEditor::OnKeyUp(wxKeyEvent& event)
714   {
715   //    std::cout << "U" << std::endl;
716     UpdateInfo();
717   }
718   //================================================================
719
720   //================================================================
721   void WxGUITextEditor::OnKeyDown(wxKeyEvent& event)
722   {
723      //   std::cout << "D" << std::endl;
724     // std::cout << "Key="<<event.GetKeyCode()<<std::endl;
725     if ( event.ControlDown() )
726       {
727         switch (event.GetKeyCode())
728           {
729           case 'n': case 'N' : New(); break;
730           case 's': case 'S' : SaveCurrentPage(); break;
731           case 'o': case 'O' : Open(); break;
732             //    case 'r': case 'R' : Run(); break;
733             //    case 'q': case 'Q' : Quit(); break;
734           }
735       }
736   }
737   //================================================================
738   
739   //================================================================  
740   BEGIN_EVENT_TABLE(WxGUITextEditor, wxPanel)
741     EVT_MENU(wxID_ANY,  WxGUITextEditor::OnToolLeftClick)
742     EVT_TOOL_RCLICKED(wxID_ANY,  WxGUITextEditor::OnToolRightClick)
743     EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, WxGUITextEditor::OnPageClose)
744     END_EVENT_TABLE()
745   //================================================================
746     
747
748
749
750   
751   //================================================================
752   WxGUITextEditorWindow::WxGUITextEditorWindow( wxWindow *parent, 
753                                                     wxString title, 
754                                                     wxSize size)
755     : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
756   {     
757     
758     
759     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
760
761     mEditor = new WxGUITextEditor(this);
762     sizer->Add(mEditor,1,wxGROW);
763     
764     //    WxGUICommand* com = new WxGUICommand(this,this);
765     //    sizer->Add(com);
766     
767     SetSizer(sizer);
768
769     // parent window of all bbtk windows will be a child of this
770     //    Wx::SetTopWindowParent(this);
771     Wx::SetTopWindow(this);
772     // Add the method OnWxSignal as a Wx::Signal observer 
773     //bbtkAddWxSignalObserver(WxGUITextEditorWindow::OnWxSignal);
774     
775    
776     SetAutoLayout(true);
777     Layout();
778   }
779   //================================================================
780
781   //================================================================
782   WxGUITextEditorWindow::~WxGUITextEditorWindow()
783   {
784   }
785   //================================================================
786
787
788 } // namespace bbtk
789
790
791 #endif //_USE_WXWIDGETS_