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