Program: bbtk
Module: $RCSfile: bbtkWxGUITextEditor.cxx,v $
Language: C++
- Date: $Date: 2008/03/21 11:46:41 $
- Version: $Revision: 1.1 $
+ Date: $Date: 2008/03/26 14:57:01 $
+ Version: $Revision: 1.5 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#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_down.xpm"
+#include "../data/icons/wxart_eldel.xpm"
namespace bbtk
{
//================================================================
- //================================================================
- class WxGUITextEditorPage : public wxPanel
- {
- public:
- WxGUITextEditorPage(wxWindow* parent, WxGUITextEditor* editor);
- ~WxGUITextEditorPage();
-
- void SetPageName(const std::string& name) { mName = name; }
- const std::string& GetPageName() const { return mName; }
-
- bool AskFilename() const { return mAskFilename; }
-
- WxTextCtrlGettingKeyEvents* GetTextCtrl() { return mwxInputText; }
-
- void Load(const std::string& filename);
- void Save(const std::string& filter);
-
- bool IsModified() { return mwxInputText->IsModified(); }
-
- private:
- WxGUITextEditor* mEditor;
- WxTextCtrlGettingKeyEvents* mwxInputText;
- wxTextAttr* mwxInputTextAttr;
- std::string mName;
- bool mAskFilename;
-
- /*
- enum
- {
- ID_InputText
- };
- */
- //DECLARE_EVENT_TABLE();
-
- } ;
- //================================================================
//================================================================
/* BEGIN_EVENT_TABLE(WxGUITextEditorPage, wxPanel)
}
//================================================================
+ bool WxGUITextEditorPage::IsModified()
+ { return mwxInputText->IsModified(); }
+
+ std::string WxGUITextEditorPage::GetText()
+ {
+ return wx2std(GetTextCtrl()->GetValue());
+ }
//================================================================
void WxGUITextEditorPage::Load(const std::string& filename)
}
}
std::cout << "file [" << mName << "]" <<std::endl;
- mwxInputText->SaveFile(mName);
+ mwxInputText->SaveFile(std2wx(mName));
mwxInputText->SetModified(false);
}
//================================================================
//================================================================
- WxGUITextEditor::WxGUITextEditor( wxWindow *parent )
+ WxGUITextEditor::WxGUITextEditor( wxWindow *parent,
+ WxGUITextEditorUser* user )
: wxPanel(parent, -1),
+ mUser(user),
mFileNameFilter("*.*")
{
std::cout << "WxGUITextEditor::WxGUITextEditor"<<std::endl;
// BUTTONS
wxPanel *btnsCtrlPanel = new wxPanel(this,-1);
wxBoxSizer *btnsSizer = new wxBoxSizer(wxHORIZONTAL);
-
+
+ /*
wxBitmap bmp_new(cc_new_xpm);
- mwxButtonNew = new wxBitmapButton( btnsCtrlPanel,ID_ButtonNew,bmp_new);//_T("New") );
- btnsSizer->Add( mwxButtonNew );
wxBitmap bmp_open(cc_open_xpm);
- mwxButtonOpen = new wxBitmapButton( btnsCtrlPanel,ID_ButtonOpen,bmp_open);//,_T("Open") );
- btnsSizer->Add( mwxButtonOpen );
+ wxBitmap bmp_close(cc_stop_xpm);
wxBitmap bmp_save(cc_save_xpm);
- mwxButtonSave = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSave,bmp_save);//_T("Save") );
+ wxBitmap bmp_saveas(cc_save_as_xpm);
+ wxBitmap bmp_run(cc_run_xpm);
+ */
+ wxBitmap bmp_new(new_xpm);
+ wxBitmap bmp_open(fileopen_xpm);
+ wxBitmap bmp_close(eldel_xpm);
+ wxBitmap bmp_save(filesave_xpm);
+ 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 );
- /*
- wxBitmap bmp_run(cc_run_xpm);
- mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run);//_T("Run") );
+ 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 );
WxGUITextEditor::~WxGUITextEditor()
{
m_mgr.UnInit();
+
// delete mInterpreter;
}
//================================================================
}
//================================================================
+ //================================================================
+ void WxGUITextEditor::OnButtonClose(wxCommandEvent& event)
+ {
+ CloseCurrentPage();
+ }
+ //================================================================
+
+ //================================================================
+ bool WxGUITextEditor::CloseCurrentPage()
+ {
+ std::cout << "-------------- CLOSE ---------------"<<std::endl;
+ if (mwxNotebook->GetPageCount()==0) return true;
+ if (GetCurrentPage()->IsModified())
+ {
+ wxString mess = std2wx(GetCurrentPage()->GetPageName());
+ mess += _T(" modified. Save it ?");
+ wxMessageDialog* d =
+ new wxMessageDialog(this,
+ mess,
+ _T("Save buffer"),
+ wxYES_NO | wxCANCEL | wxICON_QUESTION);
+ switch (d->ShowModal())
+ {
+ case wxID_CANCEL :
+ return false;
+ break;
+ case wxID_YES :
+ GetCurrentPage()->Save(mFileNameFilter);
+ break;
+ case wxID_NO : ;
+ }
+ }
+ mwxNotebook->DeletePage(mwxNotebook->GetSelection());
+ FocusOnCurrentPage();
+ return true;
+ }
+ //================================================================
+
+ //================================================================
+ bool WxGUITextEditor::CloseAllPages()
+ {
+ bool ok = true;
+ while (mwxNotebook->GetPageCount()!=0)
+ {
+ if (!CloseCurrentPage())
+ {
+ ok = false;
+ break;
+ }
+ }
+ return ok;
+ }
+ //================================================================
+
//================================================================
void WxGUITextEditor::OnButtonSave(wxCommandEvent& event)
{
- Save();
+ SaveCurrentPage();
}
- void WxGUITextEditor::Save()
+ void WxGUITextEditor::SaveCurrentPage()
{
- std::cout << "-------------- SAVE ---------------"<<std::endl;
if (mwxNotebook->GetPageCount()==0) return;
GetCurrentPage()->Save(mFileNameFilter);
mwxNotebook->SetPageText(mwxNotebook->GetSelection(),
}
//================================================================
+ //================================================================
+ void WxGUITextEditor::OnButtonSaveAs(wxCommandEvent& event)
+ {
+ if (mwxNotebook->GetPageCount()==0) return;
+ GetCurrentPage()->SetAskFilename(true);
+ SaveCurrentPage();
+ }
+ //================================================================
+
//================================================================
void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt)
{
std::cout << "-------------- CLOSE ---------------"<<std::endl;
+ if (!CloseCurrentPage()) evt.Veto();
+
+ /*
if (mwxNotebook->GetPageCount()==0) return;
if (GetCurrentPage()->IsModified())
{
case wxID_NO : ;
}
}
-
+ */
}
//================================================================
+
/*
//================================================================
void WxGUITextEditor::OnButtonQuit(wxCommandEvent& event)
if (AskSave()) GetParent()->Close();
}
//================================================================
-
+ */
//================================================================
void WxGUITextEditor::OnButtonRun(wxCommandEvent& event)
{
- Run();
+ if ((mUser!=0) && (mwxNotebook->GetPageCount()>0))
+ mUser->WxGUITextEditorRun();
FocusOnCurrentPage();
}
+
+ /*
void WxGUITextEditor::Run()
{
std::cout << "-------------- RUN ---------------"<<std::endl;
switch (event.GetKeyCode())
{
case 'n': case 'N' : New(); break;
- case 's': case 'S' : Save(); break;
+ case 's': case 'S' : SaveCurrentPage(); break;
case 'o': case 'O' : Open(); break;
// case 'r': case 'R' : Run(); break;
// case 'q': case 'Q' : Quit(); break;
// 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_ButtonRun, WxGUITextEditor::OnButtonRun)
+ EVT_BUTTON(WxGUITextEditor::ID_ButtonSaveAs, WxGUITextEditor::OnButtonSaveAs)
+ EVT_BUTTON(WxGUITextEditor::ID_ButtonRun, WxGUITextEditor::OnButtonRun)
// EVT_BUTTON(WxGUITextEditor::ID_ButtonQuit, WxGUITextEditor::OnButtonQuit)
EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, WxGUITextEditor::OnPageClose)
END_EVENT_TABLE()