bbtkWxGUITextEditor.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkWxGUITextEditor.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2009/12/04 10:48:34 $
00006   Version:   $Revision: 1.21 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00031 
00048 #ifdef _USE_WXWIDGETS_
00049 
00050 #include <iostream>     
00051 #include "bbtkWxGUITextEditor.h"
00052 #include "bbtkWxBlackBox.h"
00053 #include "bbtkConfigurationFile.h"
00054 #include "bbtkUtilities.h"
00055 
00056 //#include "icons/cc_new.xpm"
00057 //#include "icons/cc_open.xpm"
00058 //#include "icons/cc_stop.xpm"
00059 //#include "icons/cc_save.xpm"
00060 //#include "icons/cc_save_as.xpm"
00061 //#include "icons/cc_run.xpm"
00062 //#include "icons/cc_exit.xpm"
00063 
00064 #include "../data/icons/wxart_new.xpm"
00065 #include "../data/icons/wxart_fileopen.xpm"
00066 #include "../data/icons/wxart_filesave.xpm"
00067 #include "../data/icons/wxart_filesaveas.xpm"
00068 //#include "../data/icons/wxart_exefile.xpm"
00069 //#include "../data/icons/wxart_delete.xpm"
00070 //#include "../data/icons/wxart_down.xpm"
00071 #include "../data/icons/wxart_run.xpm"
00072 #include "../data/icons/wxart_runbbi.xpm"
00073 #include "../data/icons/wxart_graphsimple.xpm"
00074 #include "../data/icons/wxart_graphdetail.xpm"
00075 #include "../data/icons/wxart_eldel.xpm"
00076 
00077 namespace bbtk
00078 {
00079 
00080 
00081   //================================================================
00082   class WxTextCtrlGettingKeyEvents : public wxTextCtrl
00083   {
00084   public:
00085     WxTextCtrlGettingKeyEvents(wxWindow *parent, wxWindowID id, const wxString &value,
00086                                const wxPoint &pos, const wxSize &size, int style = 0)
00087       : wxTextCtrl(parent, id, value, pos, size, style)
00088     {
00089     }
00090     
00091     void SetWxGUITextEditor(WxGUITextEditor* e) 
00092     { mWxGUITextEditor = e; }
00093     
00094     void OnKeyDown(wxKeyEvent& event);
00095     void OnKeyUp(wxKeyEvent& event);
00096     void OnChar(wxKeyEvent& event);
00097   private :
00098     WxGUITextEditor* mWxGUITextEditor;
00099     
00100     DECLARE_EVENT_TABLE()
00101       };
00102   
00103   BEGIN_EVENT_TABLE(WxTextCtrlGettingKeyEvents, wxTextCtrl)
00104     EVT_KEY_DOWN(WxTextCtrlGettingKeyEvents::OnKeyDown)
00105     EVT_KEY_UP(WxTextCtrlGettingKeyEvents::OnKeyUp)
00106     EVT_CHAR(WxTextCtrlGettingKeyEvents::OnChar)
00107     END_EVENT_TABLE()
00108     
00109     
00110     void WxTextCtrlGettingKeyEvents::OnChar(wxKeyEvent& event)
00111   {
00112     event.Skip();
00113   }
00114   
00115   void WxTextCtrlGettingKeyEvents::OnKeyUp(wxKeyEvent& event)
00116   {
00117     mWxGUITextEditor->OnKeyUp(event);
00118     event.Skip();
00119   }
00120   
00121   void WxTextCtrlGettingKeyEvents::OnKeyDown(wxKeyEvent& event)
00122   {
00123     mWxGUITextEditor->OnKeyDown(event);
00124     event.Skip();
00125   }
00126   //================================================================
00127   
00128   
00129   //================================================================  
00130   /*  BEGIN_EVENT_TABLE(WxGUITextEditorPage, wxPanel)
00131     EVT_CLOSE(WxGUITextEditorPage::OnClose)
00132     END_EVENT_TABLE()
00133   */
00134  
00135   //================================================================
00136   WxGUITextEditorPage::WxGUITextEditorPage(wxWindow* parent,
00137                                                WxGUITextEditor* editor)
00138     : wxPanel(parent,-1),
00139       mEditor(editor),
00140       mName(""),
00141       mAskFilename(true)
00142   {  
00143 
00144           //      std::cout << "WxGUITextEditorPage::WxGUITextEditorPage("<<mName<<")"<<std::endl;
00145 
00146     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00147  
00148     mwxInputText = 
00149                 
00150       new WxTextCtrlGettingKeyEvents(this,
00151                                      -1, //ID_InputText,
00152                                      _T(""),
00153                                      wxDefaultPosition,
00154                                      wxDefaultSize,
00155                                      wxTE_MULTILINE 
00156                                      //    |wxTE_PROCESS_ENTER
00157                                      //| wxTE_PROCESS_TAB 
00158                                      //             | wxWANTS_CHARS 
00159                                     // |  wxTAB_TRAVERSAL
00160                                      );
00161     mwxInputText->SetWxGUITextEditor(mEditor);
00162     /*
00163         new wxTextCtrl(this,-1,_T(""),
00164                 wxDefaultPosition,
00165                                              wxDefaultSize,
00166                                              wxTE_MULTILINE 
00167                                              //    |wxTE_PROCESS_ENTER
00168                                         //       | wxTE_PROCESS_TAB 
00169                                 //                  | wxWANTS_CHARS 
00170                                  //    |  wxTAB_TRAVERSAL
00171                                      );
00172                                          */
00173     mFixedFont = new wxFont(10,
00174                                    wxFONTFAMILY_MODERN,
00175                                    wxFONTSTYLE_NORMAL,
00176                                    wxFONTWEIGHT_NORMAL,
00177                                    false);
00178     
00179     mwxInputTextAttr = new wxTextAttr;
00180     mwxInputTextAttr->SetFont(*mFixedFont);
00181    
00182     sizer->Add(mwxInputText,1,wxGROW);
00183     SetSizer(sizer);
00184     SetAutoLayout(true);
00185     Layout();
00186   }
00187   //================================================================
00188 
00189   //================================================================
00190   WxGUITextEditorPage::~WxGUITextEditorPage()
00191   {
00192           delete mwxInputTextAttr;
00193           delete mFixedFont;
00194   }
00195   //================================================================
00196 
00197   bool WxGUITextEditorPage::IsModified()
00198    { return mwxInputText->IsModified(); }
00199 
00200   std::string WxGUITextEditorPage::GetText()
00201   {
00202     return wx2std(GetTextCtrl()->GetValue());
00203   }
00204 
00205   //================================================================
00206   void WxGUITextEditorPage::Load(const std::string& filename)
00207   {
00208     //    std::cout << "-------------- LOAD ---------------"<<std::endl;
00209     //    std::cout << "'" << filename << "'"<<std::endl;
00210     //std::string oldFilename = mFilename;
00211     mName = filename;
00212     mAskFilename = false;
00213     mwxInputText->LoadFile(std2wx(mName));
00214   }
00215   //================================================================
00216 
00217   //================================================================
00218   void WxGUITextEditorPage::Save(const std::string& filter)
00219   {
00220     //    std::cout << "-------------- SAVE ---------------"<<std::endl;
00221     if (mAskFilename)
00222       {
00223         wxFileDialog* fd = new wxFileDialog(this,_T("Save file"),_T(""),
00224                                             _T(""),std2wx(filter),
00225                                             wxSAVE | wxOVERWRITE_PROMPT );
00226         int result_fd = fd->ShowModal();
00227     
00228         // This line is need it by windows // EED
00229         fd->SetReturnCode( result_fd );
00230 
00231         if (fd->GetReturnCode()==wxID_OK)
00232           {
00233             mName = wx2std(fd->GetPath());
00234             mAskFilename = false;
00235           }
00236         else 
00237           {
00238             //      std::cout << "-------------- CANCELLED ---------------"
00239             //                <<std::endl;
00240             return;
00241           } 
00242       }
00243     //    std::cout << "file [" << mName << "]" <<std::endl;
00244 //    mwxInputText->SaveFile(std2wx(mName));
00245         SaveFile(mName);
00246     mwxInputText->SetModified(false);
00247   }
00248   //================================================================
00249   
00250 
00251         //================================================================
00252         void WxGUITextEditorPage::SaveFile(const std::string& filename)
00253         {
00254                 mwxInputText->SaveFile( std2wx(filename) );
00255         }
00256         //================================================================
00257         
00258         
00259 
00260 
00261 
00262 
00263 
00264 
00265 
00266 
00267 
00268 
00269   //================================================================
00270   // WxGUITextEditor
00271   //================================================================
00272 
00273 
00274   //================================================================
00275   WxGUITextEditor::WxGUITextEditor( wxWindow *parent,
00276                                     WxGUITextEditorUser* user )
00277     : wxPanel(parent, -1),
00278       mUser(user),
00279       mFileNameFilter("*.*")
00280   {
00281   //  m_mgr.SetManagedWindow(this);
00282                     //    wxInitAllImageHandlers();
00283      
00284         //  std::cout << "WxGUITextEditor::WxGUITextEditor"<<std::endl;
00285 
00286       wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00287 
00288     mwxNotebook = new wxNotebook(this,-1,
00289                 wxDefaultPosition, wxDefaultSize, 
00290                 wxNB_TOP 
00291 
00292                 
00293                 );
00294                 
00295    sizer->Add(mwxNotebook,1,wxGROW);
00296 
00297                 
00298                 /*
00299    mwxNotebook =                new wxAuiNotebook(this,  
00300                                     -1,
00301                                     wxPoint(0, 0),
00302                                     wxSize(500,500),
00303                                     wxAUI_NB_TAB_SPLIT 
00304                                     | wxAUI_NB_TAB_MOVE
00305                                     | wxAUI_NB_TAB_EXTERNAL_MOVE
00306                                     | wxAUI_NB_WINDOWLIST_BUTTON
00307                                     |wxAUI_NB_SCROLL_BUTTONS
00308                                     // | wxAUI_NB_CLOSE_BUTTON 
00309                                     | wxAUI_NB_CLOSE_ON_ACTIVE_TAB
00310                                     //| wxAUI_NB_CLOSE_ON_ALL_TABS
00311                                     | wxNO_BORDER);
00312     
00313     m_mgr.AddPane(mwxNotebook,
00314                   wxAuiPaneInfo().Name(wxT("notebook"))
00315                   .Caption(wxT(""))
00316                   .CaptionVisible(false)
00317                   .MinimizeButton(false)
00318                   .MaximizeButton(false)
00319                   .CloseButton(false)
00320                   //              .Dockable(false).Float()
00321                   .Center()
00322                   .MinSize(wxSize(100,50))
00323                   );   
00324 */
00325  
00326     /*   
00327     wxBitmap bmp_new(cc_new_xpm);
00328     wxBitmap bmp_open(cc_open_xpm);
00329     wxBitmap bmp_close(cc_stop_xpm);
00330     wxBitmap bmp_save(cc_save_xpm);
00331     wxBitmap bmp_saveas(cc_save_as_xpm);
00332     wxBitmap bmp_run(cc_run_xpm);
00333     */
00334     wxBitmap bmp_new(new_xpm);
00335     wxBitmap bmp_open(fileopen_xpm);
00336     wxBitmap bmp_close(eldel_xpm);
00337     wxBitmap bmp_save(filesave_xpm);
00338     wxBitmap bmp_saveas(filesaveas_xpm);
00339     wxBitmap bmp_run(wxart_run_xpm);
00340     wxBitmap bmp_runbbi(wxart_runbbi_xpm);
00341     wxBitmap bmp_graphsimple(wxart_graphsimple_xpm);
00342         wxBitmap bmp_graphdetail(wxart_graphdetail_xpm);
00343 
00344     mwxToolBar = new wxToolBar(this, wxID_ANY, 
00345                                wxDefaultPosition, wxDefaultSize,
00346                                wxTB_FLAT | wxTB_NODIVIDER);
00347     
00348     mwxToolBar->AddTool(ID_ButtonNew, _T("New"),
00349                      bmp_new, wxNullBitmap, wxITEM_NORMAL,
00350                      _T("New file"), _T("Create a new file"));
00351     mwxToolBar->AddTool(ID_ButtonOpen, _T("Open"),
00352                      bmp_open, wxNullBitmap, wxITEM_NORMAL,
00353                      _T("Open file"), _T("This is help for new file tool"));
00354     mwxToolBar->AddTool(ID_ButtonClose, _T("Close"),
00355                      bmp_close, wxNullBitmap, wxITEM_NORMAL,
00356                      _T("Close file"), _T("Close current file"));
00357     mwxToolBar->AddTool(ID_ButtonSave, _T("New"),
00358                      bmp_save, wxNullBitmap, wxITEM_NORMAL,
00359                      _T("Save file"), _T("Save current file"));
00360     mwxToolBar->AddTool(ID_ButtonSaveAs, _T("New"),
00361                      bmp_saveas, wxNullBitmap, wxITEM_NORMAL,
00362                      _T("Save file as"), _T("Save current file as"));
00363     mwxToolBar->AddTool(ID_ButtonRun, _T("Run"),
00364                      bmp_run, wxNullBitmap, wxITEM_NORMAL,
00365                      _T("Run file"), _T("Run current file"));
00366 
00367           
00368         mwxToolBar->AddTool(ID_ButtonGraphSimple, _T("Graph (simple)"),
00369                                                   bmp_graphsimple, wxNullBitmap, wxITEM_NORMAL,
00370                                                   _T("Graph simple"), _T("Simple graph of actual script"));
00371 
00372         mwxToolBar->AddTool(ID_ButtonGraphDetail, _T("Graph (detail)"),
00373                                                   bmp_graphdetail, wxNullBitmap, wxITEM_NORMAL,
00374                                                   _T("Graph (detail)"), _T("Detail graph of actual script"));
00375           
00376         mwxToolBar->AddTool(ID_ButtonRunBBI, _T("Run external bbi "),
00377                                                   bmp_runbbi, wxNullBitmap, wxITEM_NORMAL,
00378                                                   _T("Run external bbi"), _T("Run external bbi"));
00379           
00380           
00381           
00382     mwxToolBar->AddSeparator();
00383     mwxPosition = new wxStaticText ( mwxToolBar, -1, _T(""));
00384     mwxToolBar->AddControl(mwxPosition);
00385     mwxToolBar->Realize();
00386 
00387           sizer->Add(mwxToolBar,0,wxGROW);
00388 
00389         /*
00390     m_mgr.AddPane(mwxToolBar, 
00391                   wxAuiPaneInfo().Name(wxT("toolBar"))
00392                   .Caption(wxT(""))
00393                   .ToolbarPane()
00394                   .Bottom()
00395                   .MinSize(wxSize(100,50))
00396                   .LeftDockable(false).RightDockable(false)
00397                   );   
00398 */
00399   SetSizer(sizer);
00400   
00401     
00402 //    m_mgr.Update();
00403     SetAutoLayout(true);
00404     Layout();
00405 
00406     NewPage("");
00407     UpdateInfo();
00408 
00409   }
00410   //================================================================
00411   
00412   //================================================================
00413   WxGUITextEditor::~WxGUITextEditor()
00414   {
00415   //  m_mgr.UnInit();
00416 
00417     //    delete mInterpreter;
00418   }
00419   //================================================================
00420 
00421   //================================================================
00422   void WxGUITextEditor::NewPage(const std::string& filename)
00423   {
00424    WxGUITextEditorPage* page = 
00425       new WxGUITextEditorPage(mwxNotebook,this);
00426     std::string name("untitled");
00427     if (filename.size()!=0) 
00428       {
00429         name = filename;
00430         page->Load(name);
00431       }
00432     page->SetPageName(name);
00433     std::string fname = Utilities::get_file_name(name);
00434     mwxNotebook->AddPage(page,std2wx(fname),true);
00435     FocusOnCurrentPage();
00436   }
00437   //================================================================
00438 
00439   //================================================================
00440   WxGUITextEditorPage* WxGUITextEditor::GetCurrentPage()
00441   {
00442     return (WxGUITextEditorPage*)
00443       mwxNotebook->GetPage(mwxNotebook->GetSelection());
00444   }
00445   //================================================================
00446 
00447   //================================================================
00448   void WxGUITextEditor::FocusOnCurrentPage()
00449   {
00450     if (mwxNotebook->GetPageCount()==0) return;
00451     GetCurrentPage()->SetFocus();    
00452   }
00453   //================================================================
00454 
00455   //================================================================  
00456   void WxGUITextEditor::OnToolLeftClick(wxCommandEvent& event)
00457   {
00458     switch (event.GetId())
00459       {
00460       case ID_ButtonNew :
00461         New(); 
00462         FocusOnCurrentPage();
00463         break;
00464       case ID_ButtonOpen :
00465         Open(); 
00466         FocusOnCurrentPage();
00467         break;
00468       case ID_ButtonClose :
00469         CloseCurrentPage();
00470         break;
00471       case ID_ButtonSave :
00472         SaveCurrentPage();
00473         break;
00474       case ID_ButtonSaveAs :
00475         if (mwxNotebook->GetPageCount()==0) break;  
00476         GetCurrentPage()->SetAskFilename(true);
00477         SaveCurrentPage();
00478         break;
00479       case ID_ButtonRun :
00480         if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
00481           mUser->WxGUITextEditorRun();
00482         FocusOnCurrentPage();
00483         break;
00484                           
00485                   case ID_ButtonGraphSimple :
00486                           if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
00487                                   mUser->WxGUITextEditorGraphSimple();
00488                           FocusOnCurrentPage();
00489                           break;
00490 
00491                   case ID_ButtonGraphDetail :
00492                           if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
00493                                   mUser->WxGUITextEditorGraphDetail();
00494                           FocusOnCurrentPage();
00495                           break;
00496                           
00497                   case ID_ButtonRunBBI :
00498                           if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
00499                                   mUser->WxGUITextEditorRunBBI();
00500                           FocusOnCurrentPage();
00501                           break;
00502                           
00503       }
00504   }
00505   //================================================================  
00506 
00507   //================================================================  
00508   void WxGUITextEditor::OnToolRightClick(wxCommandEvent& event)
00509   {
00510   }
00511   //================================================================  
00512 
00513   //================================================================  
00514   void WxGUITextEditor::New()
00515   {
00516     NewPage("");
00517     UpdateInfo();
00518   }
00519   //================================================================
00520 
00521   //================================================================  
00522   void WxGUITextEditor::Open()
00523   {
00524     //    std::cout << "-------------- OPEN ---------------"<<std::endl;
00525 
00526     wxFileDialog* fd = new wxFileDialog(this,_T("Open file"),_T(""),
00527                                         _T(""),std2wx(mFileNameFilter),
00528                                         wxOPEN | wxFILE_MUST_EXIST );
00529     int result_fd = fd->ShowModal();
00530 
00531         // This line is need it by windows //EED
00532         fd->SetReturnCode( result_fd );
00533 
00534     if (fd->GetReturnCode()==wxID_OK)
00535       {
00536         std::string filename = wx2std(fd->GetPath());
00537         std::cout << "file [" << filename << "]" <<std::endl;
00538         Open(filename);
00539       }
00540     else 
00541       {
00542         //      std::cout << "-------------- CANCELLED ---------------"<<std::endl;
00543       }
00544   }
00545   //================================================================  
00546   
00547   //================================================================  
00548   void WxGUITextEditor::Open(const std::string& filename)
00549   {
00550     NewPage(filename);
00551     UpdateInfo();
00552   }
00553   //================================================================  
00554 
00555 
00556   //================================================================  
00557   bool WxGUITextEditor::CloseCurrentPage()
00558   {
00559     if (mwxNotebook->GetPageCount()==0) return true;
00560 
00561     if (GetCurrentPage()->IsModified()) 
00562       {
00563         wxString mess = std2wx(GetCurrentPage()->GetPageName());
00564         mess += _T(" modified. Save it ?");
00565         wxMessageDialog* d = 
00566           new wxMessageDialog(this,
00567                               mess, 
00568                               _T("Save buffer"), 
00569                               wxYES_NO | wxCANCEL | wxICON_QUESTION);
00570         switch (d->ShowModal())
00571           {
00572           case wxID_CANCEL : 
00573             return false;
00574             break;
00575           case wxID_YES : 
00576             GetCurrentPage()->Save(mFileNameFilter); 
00577             break;
00578           case wxID_NO : ;
00579           }       
00580       } 
00581     mwxNotebook->DeletePage(mwxNotebook->GetSelection());
00582     FocusOnCurrentPage();
00583     return true;
00584   }
00585   //================================================================  
00586 
00587   //================================================================  
00588   bool WxGUITextEditor::CloseAllPages()
00589   {
00590     bool ok = true;
00591     while (mwxNotebook->GetPageCount()!=0)
00592       {
00593         if (!CloseCurrentPage()) 
00594           {
00595             ok = false;
00596             break;
00597           }
00598       }
00599     return ok;
00600   }
00601   //================================================================  
00602 
00603   //================================================================  
00604   void WxGUITextEditor::SaveCurrentPage()
00605   {
00606     if (mwxNotebook->GetPageCount()==0) return;  
00607     GetCurrentPage()->Save(mFileNameFilter);
00608     mwxNotebook->SetPageText(mwxNotebook->GetSelection(),
00609                              std2wx(GetCurrentPage()->GetPageName()));
00610   }
00611   //================================================================  
00612 
00613 
00614   //================================================================  
00615   void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt)
00616   {
00617     if (!CloseCurrentPage()) evt.Veto();
00618   }
00619   //================================================================
00620 
00621 
00622 
00623   /*
00624   //================================================================  
00625   void WxGUITextEditor::OnButtonQuit(wxCommandEvent& event) 
00626   { 
00627     Quit(); 
00628     FocusOnCurrentPage();
00629   }
00630   void WxGUITextEditor::Quit()
00631   {
00632     std::cout << "-------------- QUIT ---------------"<<std::endl;
00633     if (AskSave()) GetParent()->Close();
00634   }
00635   //================================================================  
00636   */
00637 
00638   //================================================================  
00639 
00640   /*
00641   void WxGUITextEditor::Run()
00642   {
00643     std::cout << "-------------- RUN ---------------"<<std::endl;
00644 
00645     if (!mwxSplit->IsSplit()) 
00646       {
00647         int size = -100;
00648         int minsize = - (int)(mwxInputText->GetSize().GetHeight() / 2.);
00649         if (size<minsize) size = minsize;
00650         mwxSplit->SplitHorizontally( mwxInputText, mwxOutputText, size);
00651       }
00652 
00653     std::stringstream* buffer = new std::stringstream(bbtk::wx2std(mwxInputText->GetValue()));
00654     mInterpreter->InterpretLine("reset");
00655     try 
00656       {
00657         mInterpreter->InterpretBuffer(buffer);
00658       }
00659     catch (...)
00660       {
00661       }
00662   } 
00663   //================================================================  
00664 */
00665   
00666  
00667   
00668   //================================================================
00669   
00670 
00671   //================================================================
00672   void WxGUITextEditor::UpdateInfo()
00673   {
00674     if (mwxNotebook->GetPageCount()==0) return;
00675     WxTextCtrlGettingKeyEvents* text = GetCurrentPage()->GetTextCtrl();
00676     
00677     long line, column, pos;
00678     pos = text->GetInsertionPoint();
00679     text->PositionToXY(pos, &column, &line);
00680     
00681     
00682     //                wxLogMessage(_T("Current position: %ld\nCurrent line, column: (%ld, %ld)\nNumber of lines: %ld\nCurrent line length: %ld\nTotal text length: %u (%ld)"),
00683     
00684     
00685     char mess[200];
00686     sprintf(mess,"%ld:%ld/%ld:%ld",
00687             line+1,column+1,
00688             (long)text->GetNumberOfLines(),
00689             (long)text->GetLineLength(line)+1);
00690     //       pos+1,
00691     //       (long)mwxInputText->GetValue().length())+1;
00692     
00693    // mwxPosition->SetLabel(wxString(mess));
00694     mwxPosition->SetLabel(std2wx(mess));    
00695     mwxPosition->Show();
00696     
00697     if (text->IsModified()) 
00698       {
00699         std::string title("*");
00700         title += GetCurrentPage()->GetPageName();
00701         mwxNotebook->SetPageText(mwxNotebook->GetSelection(),std2wx(title));
00702       }
00703   }
00704   //================================================================
00705   //================================================================
00706   void WxGUITextEditor::OnKeyUp(wxKeyEvent& event)
00707   {
00708   //    std::cout << "U" << std::endl;
00709     UpdateInfo();
00710   }
00711   //================================================================
00712 
00713   //================================================================
00714   void WxGUITextEditor::OnKeyDown(wxKeyEvent& event)
00715   {
00716      //   std::cout << "D" << std::endl;
00717     // std::cout << "Key="<<event.GetKeyCode()<<std::endl;
00718     if ( event.ControlDown() )
00719       {
00720         switch (event.GetKeyCode())
00721           {
00722           case 'n': case 'N' : New(); break;
00723           case 's': case 'S' : SaveCurrentPage(); break;
00724           case 'o': case 'O' : Open(); break;
00725             //    case 'r': case 'R' : Run(); break;
00726             //    case 'q': case 'Q' : Quit(); break;
00727           }
00728       }
00729   }
00730   //================================================================
00731   
00732   //================================================================  
00733   BEGIN_EVENT_TABLE(WxGUITextEditor, wxPanel)
00734     EVT_MENU(wxID_ANY,  WxGUITextEditor::OnToolLeftClick)
00735     EVT_TOOL_RCLICKED(wxID_ANY,  WxGUITextEditor::OnToolRightClick)
00736     EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, WxGUITextEditor::OnPageClose)
00737     END_EVENT_TABLE()
00738   //================================================================
00739     
00740 
00741 
00742 
00743   
00744   //================================================================
00745   WxGUITextEditorWindow::WxGUITextEditorWindow( wxWindow *parent, 
00746                                                     wxString title, 
00747                                                     wxSize size)
00748     : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
00749   {     
00750     
00751     
00752     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00753 
00754     mEditor = new WxGUITextEditor(this);
00755     sizer->Add(mEditor,1,wxGROW);
00756     
00757     //    WxGUICommand* com = new WxGUICommand(this,this);
00758     //    sizer->Add(com);
00759     
00760     SetSizer(sizer);
00761 
00762     // parent window of all bbtk windows will be a child of this
00763     //    Wx::SetTopWindowParent(this);
00764     Wx::SetTopWindow(this);
00765     // Add the method OnWxSignal as a Wx::Signal observer 
00766     //bbtkAddWxSignalObserver(WxGUITextEditorWindow::OnWxSignal);
00767     
00768    
00769     SetAutoLayout(true);
00770     Layout();
00771   }
00772   //================================================================
00773 
00774   //================================================================
00775   WxGUITextEditorWindow::~WxGUITextEditorWindow()
00776   {
00777   }
00778   //================================================================
00779 
00780 
00781 } // namespace bbtk
00782 
00783 
00784 #endif //_USE_WXWIDGETS_

Generated on Thu May 31 14:12:04 2012 for BBTK by  doxygen 1.5.7.1