X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkWxGUITextEditor.cxx;h=b6cb137344c2b460eaddc79d18236532608c6be3;hb=9e2b6d4716a5d12f39d8dde0a2d719fe961bdd2c;hp=4f3d99e83ecb167f8bf2755e1862139f31255d3a;hpb=174ea6d71477e40679f4fd71952e3f2a03416098;p=bbtk.git diff --git a/kernel/src/bbtkWxGUITextEditor.cxx b/kernel/src/bbtkWxGUITextEditor.cxx index 4f3d99e..b6cb137 100644 --- a/kernel/src/bbtkWxGUITextEditor.cxx +++ b/kernel/src/bbtkWxGUITextEditor.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkWxGUITextEditor.cxx,v $ Language: C++ - Date: $Date: 2008/04/24 10:11:28 $ - Version: $Revision: 1.10 $ + Date: $Date: 2008/09/10 07:25:23 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -38,20 +38,20 @@ #include "bbtkConfigurationFile.h" #include "bbtkUtilities.h" -#include "icons/cc_new.xpm" -#include "icons/cc_open.xpm" -#include "icons/cc_stop.xpm" -#include "icons/cc_save.xpm" -#include "icons/cc_save_as.xpm" -#include "icons/cc_run.xpm" -#include "icons/cc_exit.xpm" +//#include "icons/cc_new.xpm" +//#include "icons/cc_open.xpm" +//#include "icons/cc_stop.xpm" +//#include "icons/cc_save.xpm" +//#include "icons/cc_save_as.xpm" +//#include "icons/cc_run.xpm" +//#include "icons/cc_exit.xpm" #include "../data/icons/wxart_new.xpm" #include "../data/icons/wxart_fileopen.xpm" #include "../data/icons/wxart_filesave.xpm" #include "../data/icons/wxart_filesaveas.xpm" -#include "../data/icons/wxart_exefile.xpm" -#include "../data/icons/wxart_delete.xpm" +//#include "../data/icons/wxart_exefile.xpm" +//#include "../data/icons/wxart_delete.xpm" #include "../data/icons/wxart_down.xpm" #include "../data/icons/wxart_eldel.xpm" @@ -189,8 +189,11 @@ namespace bbtk wxFileDialog* fd = new wxFileDialog(this,_T("Save file"),_T(""), _T(""),std2wx(filter), wxSAVE | wxOVERWRITE_PROMPT ); - fd->ShowModal(); + int result_fd = fd->ShowModal(); + // This line is need it by windows // EED + fd->SetReturnCode( result_fd ); + if (fd->GetReturnCode()==wxID_OK) { mName = wx2std(fd->GetPath()); @@ -209,6 +212,32 @@ namespace bbtk } //================================================================ + + + + + + + + + + + + + + + + + + + + + + //================================================================ + // WxGUITextEditor + //================================================================ + + //================================================================ WxGUITextEditor::WxGUITextEditor( wxWindow *parent, WxGUITextEditorUser* user ) @@ -216,20 +245,10 @@ namespace bbtk mUser(user), mFileNameFilter("*.*") { - // std::cout << "WxGUITextEditor::WxGUITextEditor"<SetWxGUITextEditor(this); - // mInterpreter->SetCommandLine(true); m_mgr.SetManagedWindow(this); - //============== - // Menu - wxInitAllImageHandlers(); - - - // wxFlexGridSizer *sizer= new wxFlexGridSizer(2); - wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); - + // wxInitAllImageHandlers(); + mwxNotebook = new wxAuiNotebook(this, -1, wxPoint(0, 0), @@ -244,11 +263,18 @@ namespace bbtk //| wxAUI_NB_CLOSE_ON_ALL_TABS | wxNO_BORDER); - sizer->Add(mwxNotebook,1,wxGROW); - - // BUTTONS - wxPanel *btnsCtrlPanel = new wxPanel(this,-1); - wxBoxSizer *btnsSizer = new wxBoxSizer(wxHORIZONTAL); + m_mgr.AddPane(mwxNotebook, + wxAuiPaneInfo().Name(wxT("notebook")) + .Caption(wxT("")) + .CaptionVisible(false) + .MinimizeButton(false) + .MaximizeButton(false) + .CloseButton(false) + // .Dockable(false).Float() + .Center() + .MinSize(wxSize(100,50)) + ); + /* wxBitmap bmp_new(cc_new_xpm); @@ -265,45 +291,47 @@ namespace bbtk wxBitmap bmp_saveas(filesaveas_xpm); wxBitmap bmp_run(down_xpm); - - wxSize btn_size(32,32); - mwxButtonNew = new wxBitmapButton( btnsCtrlPanel,ID_ButtonNew,bmp_new - ,wxDefaultPosition, btn_size); - btnsSizer->Add( mwxButtonNew ); - - mwxButtonOpen = new wxBitmapButton( btnsCtrlPanel,ID_ButtonOpen,bmp_open ,wxDefaultPosition, btn_size);//,_T("Open") ); - btnsSizer->Add( mwxButtonOpen ); - - mwxButtonClose = new wxBitmapButton( btnsCtrlPanel,ID_ButtonClose,bmp_close ,wxDefaultPosition, btn_size);//,_T("Open") ); - btnsSizer->Add( mwxButtonClose ); - - mwxButtonSave = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSave,bmp_save ,wxDefaultPosition, btn_size);//_T("Save") ); - btnsSizer->Add( mwxButtonSave ); - - mwxButtonSaveAs = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSaveAs,bmp_saveas ,wxDefaultPosition, btn_size);//_T("Save") ); - btnsSizer->Add( mwxButtonSaveAs ); - - - mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run ,wxDefaultPosition, btn_size);//_T("Run") ); - btnsSizer->Add( mwxButtonRun ); - /* - wxBitmap bmp_quit(cc_exit_xpm); - mwxButtonQuit = new wxBitmapButton( btnsCtrlPanel,ID_ButtonQuit,bmp_quit);//_T("Quit") ); - btnsSizer->Add( mwxButtonQuit ); - */ + mwxToolBar = new wxToolBar(this, wxID_ANY, + wxDefaultPosition, wxDefaultSize, + wxTB_FLAT | wxTB_NODIVIDER); - mwxPosition = new wxStaticText ( btnsCtrlPanel, -1, _T("")); - btnsSizer->Add( mwxPosition ); - - btnsCtrlPanel->SetSizer(btnsSizer); - sizer->Add ( btnsCtrlPanel, 0, wxLEFT | wxRIGHT | wxBOTTOM //| wxGROW - , 10 ); - + mwxToolBar->AddTool(ID_ButtonNew, _T("New"), + bmp_new, wxNullBitmap, wxITEM_NORMAL, + _T("New file"), _T("Create a new file")); + mwxToolBar->AddTool(ID_ButtonOpen, _T("Open"), + bmp_open, wxNullBitmap, wxITEM_NORMAL, + _T("Open file"), _T("This is help for new file tool")); + mwxToolBar->AddTool(ID_ButtonClose, _T("Close"), + bmp_close, wxNullBitmap, wxITEM_NORMAL, + _T("Close file"), _T("Close current file")); + mwxToolBar->AddTool(ID_ButtonSave, _T("New"), + bmp_save, wxNullBitmap, wxITEM_NORMAL, + _T("Save file"), _T("Save current file")); + mwxToolBar->AddTool(ID_ButtonSaveAs, _T("New"), + bmp_saveas, wxNullBitmap, wxITEM_NORMAL, + _T("Save file as"), _T("Save current file as")); + mwxToolBar->AddTool(ID_ButtonRun, _T("Run"), + bmp_run, wxNullBitmap, wxITEM_NORMAL, + _T("Run file"), _T("Run current file")); + + mwxToolBar->AddSeparator(); + mwxPosition = new wxStaticText ( mwxToolBar, -1, _T("")); + mwxToolBar->AddControl(mwxPosition); + mwxToolBar->Realize(); + + m_mgr.AddPane(mwxToolBar, + wxAuiPaneInfo().Name(wxT("toolBar")) + .Caption(wxT("")) + .ToolbarPane() + .Bottom() + .MinSize(wxSize(100,50)) + .LeftDockable(false).RightDockable(false) + ); NewPage(""); UpdateInfo(); - SetSizer(sizer); + m_mgr.Update(); SetAutoLayout(true); Layout(); } @@ -353,11 +381,53 @@ namespace bbtk //================================================================ //================================================================ - void WxGUITextEditor::OnButtonOpen(wxCommandEvent& event) - { - Open(); - FocusOnCurrentPage(); - } + void WxGUITextEditor::OnToolLeftClick(wxCommandEvent& event) + { + switch (event.GetId()) + { + case ID_ButtonNew : + New(); + FocusOnCurrentPage(); + break; + case ID_ButtonOpen : + Open(); + FocusOnCurrentPage(); + break; + case ID_ButtonClose : + CloseCurrentPage(); + break; + case ID_ButtonSave : + SaveCurrentPage(); + break; + case ID_ButtonSaveAs : + if (mwxNotebook->GetPageCount()==0) break; + GetCurrentPage()->SetAskFilename(true); + SaveCurrentPage(); + break; + case ID_ButtonRun : + if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) + mUser->WxGUITextEditorRun(); + FocusOnCurrentPage(); + break; + } + } + //================================================================ + + //================================================================ + void WxGUITextEditor::OnToolRightClick(wxCommandEvent& event) + { + } + //================================================================ + + //================================================================ + void WxGUITextEditor::New() + { + NewPage(""); + UpdateInfo(); + } + //================================================================ + + //================================================================ void WxGUITextEditor::Open() { // std::cout << "-------------- OPEN ---------------"<ShowModal(); - + int result_fd = fd->ShowModal(); + + // This line is need it by windows //EED + fd->SetReturnCode( result_fd ); + if (fd->GetReturnCode()==wxID_OK) { std::string filename = wx2std(fd->GetPath()); @@ -388,18 +461,12 @@ namespace bbtk } //================================================================ - //================================================================ - void WxGUITextEditor::OnButtonClose(wxCommandEvent& event) - { - CloseCurrentPage(); - } - //================================================================ //================================================================ bool WxGUITextEditor::CloseCurrentPage() { - // std::cout << "-------------- CLOSE ---------------"<GetPageCount()==0) return true; + if (GetCurrentPage()->IsModified()) { wxString mess = std2wx(GetCurrentPage()->GetPageName()); @@ -443,10 +510,6 @@ namespace bbtk //================================================================ //================================================================ - void WxGUITextEditor::OnButtonSave(wxCommandEvent& event) - { - SaveCurrentPage(); - } void WxGUITextEditor::SaveCurrentPage() { if (mwxNotebook->GetPageCount()==0) return; @@ -456,42 +519,11 @@ namespace bbtk } //================================================================ - //================================================================ - void WxGUITextEditor::OnButtonSaveAs(wxCommandEvent& event) - { - if (mwxNotebook->GetPageCount()==0) return; - GetCurrentPage()->SetAskFilename(true); - SaveCurrentPage(); - } - //================================================================ //================================================================ void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt) { - // std::cout << "-------------- CLOSE ---------------"<GetPageCount()==0) return; - if (GetCurrentPage()->IsModified()) - { - wxMessageDialog* d = - new wxMessageDialog(this, - _T("Buffer modified. Save it ?"), - _T("Save buffer"), - wxYES_NO | wxCANCEL | wxICON_QUESTION); - switch (d->ShowModal()) - { - case wxID_CANCEL : - evt.Veto(); - break; - case wxID_YES : - GetCurrentPage()->Save(mFileNameFilter); - break; - case wxID_NO : ; - } - } - */ } //================================================================ @@ -513,12 +545,6 @@ namespace bbtk */ //================================================================ - void WxGUITextEditor::OnButtonRun(wxCommandEvent& event) - { - if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) - mUser->WxGUITextEditorRun(); - FocusOnCurrentPage(); - } /* void WxGUITextEditor::Run() @@ -550,19 +576,6 @@ namespace bbtk //================================================================ - //================================================================ - void WxGUITextEditor::OnButtonNew(wxCommandEvent& event) - { - New(); - FocusOnCurrentPage(); - } - void WxGUITextEditor::New() - { - /// std::cout << "-------------- NEW ---------------" << std::endl; - NewPage(""); - UpdateInfo(); - } - //================================================================ //================================================================ void WxGUITextEditor::UpdateInfo() @@ -627,14 +640,8 @@ namespace bbtk //================================================================ BEGIN_EVENT_TABLE(WxGUITextEditor, wxPanel) - // EVT_CHAR(WxGUITextEditor::OnKeyPress) - EVT_BUTTON(WxGUITextEditor::ID_ButtonNew, WxGUITextEditor::OnButtonNew) - EVT_BUTTON(WxGUITextEditor::ID_ButtonOpen, WxGUITextEditor::OnButtonOpen) - EVT_BUTTON(WxGUITextEditor::ID_ButtonClose, WxGUITextEditor::OnButtonClose) - EVT_BUTTON(WxGUITextEditor::ID_ButtonSave, WxGUITextEditor::OnButtonSave) - EVT_BUTTON(WxGUITextEditor::ID_ButtonSaveAs, WxGUITextEditor::OnButtonSaveAs) - EVT_BUTTON(WxGUITextEditor::ID_ButtonRun, WxGUITextEditor::OnButtonRun) - // EVT_BUTTON(WxGUITextEditor::ID_ButtonQuit, WxGUITextEditor::OnButtonQuit) + EVT_MENU(wxID_ANY, WxGUITextEditor::OnToolLeftClick) + EVT_TOOL_RCLICKED(wxID_ANY, WxGUITextEditor::OnToolRightClick) EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, WxGUITextEditor::OnPageClose) END_EVENT_TABLE() //================================================================ @@ -661,8 +668,8 @@ namespace bbtk SetSizer(sizer); - // Creates the parent window of all bbtk windows as a child of this - Wx::CreateTopWindow(this); + // parent window of all bbtk windows will be a child of this + Wx::SetTopWindowParent(this); // Add the method OnWxSignal as a Wx::Signal observer //bbtkAddWxSignalObserver(WxGUITextEditorWindow::OnWxSignal);