+++ /dev/null
-/*=========================================================================
-
- Program: bbtk
- Module: $RCSfile: bbtkWxEditor.cxx,v $
- Language: C++
- Date: $Date: 2008/03/20 11:04:57 $
- Version: $Revision: 1.7 $
-
- Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
- l'Image). All rights reserved. See Doc/License.txt or
- http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notices for more information.
-
-=========================================================================*//**
- * \brief Short description in one line
- *
- * Long description which
- * can span multiple lines
- */
-/**
- * \file
- * \brief
- */
-/**
- * \class bbtk::
- * \brief
- */
-
-
-#ifdef _USE_WXWIDGETS_
-
-#include <iostream>
-#include "bbtkWxEditor.h"
-#include "bbtkWxBlackBox.h"
-#include "bbtkConfigurationFile.h"
-#include "bbtkWxStreamRedirector.h"
-
-
- #include "icons/cc_new.xpm"
- #include "icons/cc_open.xpm"
- #include "icons/cc_save.xpm"
- #include "icons/cc_run.xpm"
- #include "icons/cc_exit.xpm"
-// #include "icons/copy.xpm"
-// #include "icons/cut.xpm"
-// #include "icons/preview.xpm" // paste XPM
-// #include "icons/print.xpm"
-// #include "icons/help.xpm"
-
-
-
-namespace bbtk
-{
-
-
- //================================================================
- class WxTextCtrlGettingKeyEvents : public wxTextCtrl
- {
- public:
- WxTextCtrlGettingKeyEvents(wxWindow *parent, wxWindowID id, const wxString &value,
- const wxPoint &pos, const wxSize &size, int style = 0)
- : wxTextCtrl(parent, id, value, pos, size, style)
- {
- }
-
- void SetWxEditor(WxEditor* e) { mWxEditor = e; }
-
- void OnKeyDown(wxKeyEvent& event);
- void OnKeyUp(wxKeyEvent& event);
- void OnChar(wxKeyEvent& event);
- private :
- WxEditor* mWxEditor;
-
- DECLARE_EVENT_TABLE()
- };
-
- BEGIN_EVENT_TABLE(WxTextCtrlGettingKeyEvents, wxTextCtrl)
- EVT_KEY_DOWN(WxTextCtrlGettingKeyEvents::OnKeyDown)
- EVT_KEY_UP(WxTextCtrlGettingKeyEvents::OnKeyUp)
- EVT_CHAR(WxTextCtrlGettingKeyEvents::OnChar)
-
- END_EVENT_TABLE()
-
-
- void WxTextCtrlGettingKeyEvents::OnChar(wxKeyEvent& event)
- {
- event.Skip();
- }
-
- void WxTextCtrlGettingKeyEvents::OnKeyUp(wxKeyEvent& event)
- {
- mWxEditor->OnKeyUp(event);
- event.Skip();
- }
-
- void WxTextCtrlGettingKeyEvents::OnKeyDown(wxKeyEvent& event)
- {
- mWxEditor->OnKeyDown(event);
- event.Skip();
- }
- //================================================================
-
-
-
-
- //================================================================
- WxEditor::WxEditor( wxWindow *parent )
- : wxPanel(parent, -1)
- {
- mInterpreter = new bbtk::Interpreter();
- //mInterpreter->SetWxEditor(this);
- mInterpreter->SetCommandLine(true);
-
- //==============
- // Menu
- wxInitAllImageHandlers();
-
- /*
- wxMenu *menuFile = new wxMenu;
- menuFile->Append( ID_Menu_Quit, _T("&Quit") );
-
- wxMenu *menuAbout = new wxMenu;
- menuAbout->Append( ID_Menu_About, _T("&About...") );
-
- wxMenu *menuTools = new wxMenu;
- menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
- menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
- menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
- menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
- menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
-
-
- wxMenuBar *menuBar = new wxMenuBar;
- menuBar->Append( menuFile, _T("&File") );
- menuBar->Append( menuTools, _T("&Tools") );
- menuBar->Append( menuAbout, _T("About") );
-
- SetMenuBar( menuBar );
-
- CreateStatusBar();
- SetStatusText( _T("Welcome to bbi !") );
- */
-
- // wxFlexGridSizer *sizer= new wxFlexGridSizer(2);
- wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
- mwxSplit = new wxSplitterWindow(this,
- -1,
- wxDefaultPosition,
- wxDefaultSize,
- //wxSize(400,200),
- wxSP_3D |
- wxSP_LIVE_UPDATE );
- mwxInputText =
- new WxTextCtrlGettingKeyEvents(mwxSplit,
- ID_InputText,
- _T(""),
- wxDefaultPosition,
- wxDefaultSize,
- wxTE_MULTILINE
- // |wxTE_PROCESS_ENTER
- | wxTE_PROCESS_TAB
- // | wxWANTS_CHARS
- | wxTAB_TRAVERSAL
- );
- mwxInputText->SetWxEditor(this);
-
- wxFont* FixedFont = new wxFont(10,
- wxFONTFAMILY_MODERN,
- wxFONTSTYLE_NORMAL,
- wxFONTWEIGHT_NORMAL,
- false);
-
- mwxInputTextAttr = new wxTextAttr;
- mwxInputTextAttr->SetFont(*FixedFont);
-
- // sizer->AddGrowableCol(0);
- // sizer->Add(mwxInputText,1,wxGROW);
-
- mwxOutputText =
- new WxTextCtrlGettingKeyEvents(mwxSplit,
- ID_OutputText,
- _T(""),wxDefaultPosition,
- wxDefaultSize, //HistorySize,
- wxTE_READONLY |
- wxTE_MULTILINE );
-
- mwxOutputText->SetWxEditor(this);
-
- mwxOutputTextAttr = new wxTextAttr;
- mwxOutputTextAttr->SetFont(*FixedFont);
- mwxOutputText->Hide();
-
- // sizer->Add(mwxOutputText,1,wxGROW);
- sizer->Add(mwxSplit,1,wxGROW);
- mwxSplit->Initialize(mwxInputText);
-
- // 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_save(cc_save_xpm);
- mwxButtonSave = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSave,bmp_save);//_T("Save") );
- btnsSizer->Add( mwxButtonSave );
- wxBitmap bmp_run(cc_run_xpm);
- mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run);//_T("Run") );
- btnsSizer->Add( mwxButtonRun );
- wxBitmap bmp_quit(cc_exit_xpm);
- mwxButtonQuit = new wxBitmapButton( btnsCtrlPanel,ID_ButtonQuit,bmp_quit);//_T("Quit") );
- btnsSizer->Add( mwxButtonQuit );
-
-
- mwxPosition = new wxStaticText ( btnsCtrlPanel, -1, _T(""));
- btnsSizer->Add( mwxPosition );
-
-
- btnsCtrlPanel->SetSizer(btnsSizer);
- sizer->Add ( btnsCtrlPanel, 0, wxLEFT | wxRIGHT | wxBOTTOM //| wxGROW
- , 10 );
-
- // Redirection of std::cout and std::cerr to mwxOutputText and printf
- mRedirect_cout =
- new WxStreamRedirector(std::cout,mwxOutputText,*wxBLACK,true);
- mRedirect_cerr =
- new WxStreamRedirector(std::cerr,mwxOutputText,*wxGREEN,true);
-
- UpdatePosition();
- mwxInputText->SetFocus();
-
- SetSizer(sizer);
- SetAutoLayout(true);
- Layout();
- }
- //================================================================
-
- //================================================================
- WxEditor::~WxEditor()
- {
- delete mInterpreter;
- delete mRedirect_cout;
- delete mRedirect_cerr;
- }
- //================================================================
-
-
- //================================================================
- void WxEditor::OnButtonOpen(wxCommandEvent& event)
- {
- Open();
- mwxInputText->SetFocus();
- }
- void WxEditor::Open()
- {
- std::cout << "-------------- OPEN ---------------"<<std::endl;
- if (!AskSave()) {
- std::cout << "-------------- CANCELLED ---------------"<<std::endl;
- return;
- }
-
- wxFileDialog* fd = new wxFileDialog(this,_T("Open file"),_T(""),
- _T(""),_T("*.bbs"),
- wxOPEN | wxFILE_MUST_EXIST );
- fd->ShowModal();
-
- if (fd->GetReturnCode()==wxID_OK)
- {
- std::cout << "file [" << wx2std(fd->GetPath()) << "]" <<std::endl;
- mwxInputText->LoadFile(fd->GetPath());
- }
- else
- {
- std::cout << "-------------- CANCELLED ---------------"<<std::endl;
- }
- }
- //================================================================
-
- //================================================================
- void WxEditor::Open(const std::string& filename)
- {
- mwxInputText->LoadFile(std2wx(filename));
- mwxInputText->SetModified(false);
- UpdatePosition();
- }
- //================================================================
-
- //================================================================
- void WxEditor::OnButtonSave(wxCommandEvent& event)
- {
- Save();
- mwxInputText->SetFocus();
- }
- void WxEditor::Save()
- {
- std::cout << "-------------- SAVE ---------------"<<std::endl;
- wxFileDialog* fd = new wxFileDialog(this,_T("Save file"),_T(""),
- _T(""),_T("*.bbs"),
- wxSAVE | wxOVERWRITE_PROMPT );
- fd->ShowModal();
-
- if (fd->GetReturnCode()==wxID_OK)
- {
- std::cout << "file [" << wx2std(fd->GetPath()) << "]" <<std::endl;
- mwxInputText->SaveFile(fd->GetPath());
- mwxInputText->SetModified(false);
- }
- else
- {
- std::cout << "-------------- CANCELLED ---------------"<<std::endl;
- }
- }
- //================================================================
-
- //================================================================
- void WxEditor::OnButtonQuit(wxCommandEvent& event)
- {
- Quit();
- mwxInputText->SetFocus();
- }
- void WxEditor::Quit()
- {
- std::cout << "-------------- QUIT ---------------"<<std::endl;
- if (AskSave()) GetParent()->Close();
- }
- //================================================================
-
-
- //================================================================
- void WxEditor::OnButtonRun(wxCommandEvent& event)
- {
- Run();
- mwxInputText->SetFocus();
- }
- void WxEditor::Run()
- {
- std::cout << "-------------- RUN ---------------"<<std::endl;
-
- if (!mwxSplit->IsSplit())
- {
- int size = -100;
- int minsize = - (int)(mwxInputText->GetSize().GetHeight() / 2.);
- if (size<minsize) size = minsize;
- mwxSplit->SplitHorizontally( mwxInputText, mwxOutputText, size);
- }
-
- std::stringstream* buffer = new std::stringstream(bbtk::wx2std(mwxInputText->GetValue()));
- mInterpreter->InterpretLine("reset");
- try
- {
- mInterpreter->InterpretBuffer(buffer);
- }
- catch (...)
- {
- }
- }
- //================================================================
-
- //================================================================
- bool WxEditor::AskSave()
- {
- if (!mwxInputText->IsModified()) return true;
- wxMessageDialog* d = new wxMessageDialog(this,
- _T("Buffer modified. Save it ?"),
- _T("Save buffer"),
- wxYES_NO | wxCANCEL | wxICON_QUESTION);
- switch (d->ShowModal())
- {
- case wxID_YES : Save();
- case wxID_NO : return true;
- case wxID_CANCEL : return false;
- }
- }
-
-
- //================================================================
-
- //================================================================
- void WxEditor::OnButtonNew(wxCommandEvent& event)
- {
- New();
- mwxInputText->SetFocus();
- }
- void WxEditor::New()
- {
- std::cout << "-------------- NEW ---------------" << std::endl;
- AskSave();
- mwxInputText->Clear();
- UpdatePosition();
- }
- //================================================================
-
- //================================================================
- void WxEditor::UpdatePosition()
- {
-
- long line, column, pos;
- pos = mwxInputText->GetInsertionPoint();
- mwxInputText->PositionToXY(pos, &column, &line);
-
-
- // wxLogMessage(_T("Current position: %ld\nCurrent line, column: (%ld, %ld)\nNumber of lines: %ld\nCurrent line length: %ld\nTotal text length: %u (%ld)"),
-
-
- char mess[200];
- sprintf(mess,"%ld:%ld/%ld:%ld",
- line+1,column+1,
- (long)mwxInputText->GetNumberOfLines(),
- (long)mwxInputText->GetLineLength(line)+1);
- // pos+1,
- // (long)mwxInputText->GetValue().length())+1;
-
- mwxPosition->SetLabel(std2wx(mess));
- mwxPosition->Show();
-
- }
- //================================================================
- //================================================================
- void WxEditor::OnKeyUp(wxKeyEvent& event)
- {
- // std::cout << "U" << std::endl;
- UpdatePosition();
- }
- //================================================================
-
- //================================================================
- void WxEditor::OnKeyDown(wxKeyEvent& event)
- {
- // std::cout << "D" << std::endl;
- // std::cout << "Key="<<event.GetKeyCode()<<std::endl;
- if ( event.ControlDown() )
- {
- switch (event.GetKeyCode())
- {
- case 'n': case 'N' : New(); break;
- case 's': case 'S' : Save(); break;
- case 'o': case 'O' : Open(); break;
- case 'r': case 'R' : Run(); break;
- case 'q': case 'Q' : Quit(); break;
- }
- }
- /*
- // Command completion
- std::vector<std::string> commands;
- wxString sline( wx2std ( mwxTextCommand->GetValue() ) );
- int ind = sline.size();
- mInterpreter->FindCommandsWithPrefix( sline.c_str(),ind,commands);
- if (commands.size()==1)
- {
- std::string com = *commands.begin();
- for (; ind<com.size(); ++ind)
- {
- mwxTextCommand->TextAppend( std2wx ( com[ind]) );
- }
- mwxTextCommand->TextAppend(_T(" "));
- }
- else if (commands.size()>1)
- {
- std::vector<std::string>::iterator i;
- write(1,"\n",1);
- for (i=commands.begin();i!=commands.end();++i)
- {
- write(STDOUT_FILENO,(*i).c_str(),strlen((*i).c_str()));
- PrintChar(' ');
- }
- write(STDOUT_FILENO,"\n> ",3);
- //for (int j=0;j<ind;++j)
- //{
- write(STDOUT_FILENO,line,ind);
- // }
- }
- */
- }
- //================================================================
-
- //================================================================
- BEGIN_EVENT_TABLE(WxEditor, wxPanel)
- // EVT_CHAR(WxEditor::OnKeyPress)
- EVT_BUTTON(WxEditor::ID_ButtonNew, WxEditor::OnButtonNew)
- EVT_BUTTON(WxEditor::ID_ButtonOpen, WxEditor::OnButtonOpen)
- EVT_BUTTON(WxEditor::ID_ButtonSave, WxEditor::OnButtonSave)
- EVT_BUTTON(WxEditor::ID_ButtonRun, WxEditor::OnButtonRun)
- EVT_BUTTON(WxEditor::ID_ButtonQuit, WxEditor::OnButtonQuit)
- END_EVENT_TABLE()
- //================================================================
-
- void WxEditorWindow::WxGUICommandEnter(const std::string& s)
- {
- std::cout << "Command received : '"<<s<<"'"<<std::endl;
- }
-
- //================================================================
- WxEditorWindow::WxEditorWindow( wxWindow *parent, wxString title, wxSize size)
- : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
- {
-
-
- wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
-
- mEditor = new WxEditor(this);
- sizer->Add(mEditor,1,wxGROW);
-
- WxGUICommand* com = new WxGUICommand(this,this);
- sizer->Add(com);
-
- SetSizer(sizer);
-
- // Creates and sets the parent window of all bbtk windows
- wxWindow* top = new wxPanel(this,-1);
- top->Hide();
-
- Wx::SetTopWindow(top);
-
- SetAutoLayout(true);
- Layout();
- }
-
- WxEditorWindow::~WxEditorWindow()
- {
- }
-} // namespace bbtk
-
-
-#endif //_USE_WXWIDGETS_
--- /dev/null
+/*=========================================================================
+
+ Program: bbtk
+ Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
+ Language: C++
+ Date: $Date: 2008/03/21 11:46:41 $
+ Version: $Revision: 1.1 $
+
+ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+ l'Image). All rights reserved. See Doc/License.txt or
+ http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*//**
+ * \brief Short description in one line
+ *
+ * Long description which
+ * can span multiple lines
+ */
+/**
+ * \file
+ * \brief
+ */
+/**
+ * \class bbtk::
+ * \brief
+ */
+
+
+#ifdef _USE_WXWIDGETS_
+
+#include <iostream>
+#include "bbtkWxGUIScriptingInterface.h"
+#include "bbtkWxBlackBox.h"
+#include "bbtkConfigurationFile.h"
+#include "bbtkWxStreamRedirector.h"
+
+
+#include "icons/cc_run.xpm"
+
+namespace bbtk
+{
+
+ enum
+ {
+ ID_Menu_Quit = 1,
+ ID_Menu_About,
+ ID_Menu_EditConfig,
+ ID_Menu_CreatePackage,
+ ID_Menu_CreateBlackBox,
+ ID_Menu_ShowImageGraph,
+ ID_Menu_CreateIndex,
+ ID_Button_Run
+ };
+
+
+ //================================================================
+ WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent, wxString title, wxSize size)
+ : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
+ {
+// m_mgr = new wxAuiManager(this);
+ m_mgr.SetManagedWindow(this);
+
+ mInterpreter = new bbtk::Interpreter();
+ mInterpreter->SetUser(this);
+ mInterpreter->SetCommandLine(true);
+ //==============
+ // Menu
+ wxInitAllImageHandlers();
+
+ wxMenu *menuFile = new wxMenu;
+ menuFile->Append( ID_Menu_Quit, _T("&Quit") );
+
+ wxMenu *menuAbout = new wxMenu;
+ menuAbout->Append( ID_Menu_About, _T("&About...") );
+
+ wxMenu *menuTools = new wxMenu;
+ menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
+ menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
+ menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
+ menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
+ menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
+
+
+ wxMenuBar *menuBar = new wxMenuBar;
+ menuBar->Append( menuFile, _T("&File") );
+ menuBar->Append( menuTools, _T("&Tools") );
+ menuBar->Append( menuAbout, _T("About") );
+
+ SetMenuBar( menuBar );
+
+ CreateStatusBar();
+ SetStatusText( _T("Welcome to bbi !") );
+
+
+ /*
+ m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo().
+ Name(wxT("test4")).Caption(wxT("Pane Caption")).
+ Left());
+ */
+
+ //==============
+ // Notebook
+
+ // wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
+
+//EED wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
+// mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
+/*
+ mwxNotebook = new wxAuiNotebook(this,
+ -1,
+ wxPoint(0, 0),
+ wxSize(500,500),
+ wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
+
+ mwxPageCommand = new wxPanel(mwxNotebook,-1);
+ mwxPageHelp = new wxPanel(mwxNotebook,-1);
+
+
+ wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
+
+ mwxPageCommand->SetAutoLayout(true);
+ mwxPageCommand->SetSizer(cmdsizer);
+ cmdsizer->Fit(mwxPageCommand);
+ cmdsizer->SetSizeHints(mwxPageCommand);
+
+ wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
+
+ mwxPageHelp->SetAutoLayout(true);
+ mwxPageHelp->SetSizer(helpsizer);
+ helpsizer->Fit(mwxPageHelp);
+ helpsizer->SetSizeHints(mwxPageHelp);
+*/
+ mWxGUITextEditor = new WxGUITextEditor(this);
+ mWxGUITextEditor->SetFileNameFilter("*.bbs");
+
+ mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this, //mwxPageHelp,
+ //EED wxSize(1200,0));
+ wxSize(200,0));
+
+ // mWxGUIHtmlBrowser->SetSize(wxSize(800,1000));
+ // helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5 );
+ // helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0, wxEXPAND );
+
+ wxBitmap bmp_run(cc_run_xpm);
+ mwxButtonRun = new wxBitmapButton( this, ID_Button_Run,bmp_run);//_T("Run") );
+ // helpsizer->Add( mwxButtonRun, 0, wxALL, 5 );
+
+
+ //==============
+ // Command page
+ mWxGUIOutputMessages = new WxGUIOutputMessages(this);
+
+ mWxGUICommand = new WxGUICommand(this,this);
+
+ // mWxGUICommand->SetFocus();
+
+ // cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5);
+ // cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5);
+
+
+ // Creates and sets the parent window of all bbtk windows
+ wxWindow* top = new wxPanel(this,-1);//,_T("top"));
+ top->Hide();
+ Wx::SetTopWindow(top);
+
+
+ // Layout
+//EED SetSizer(sizer);
+/*
+ mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
+ mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
+*/
+
+ m_mgr.AddPane(mWxGUITextEditor,
+ wxAuiPaneInfo().Name(wxT("editor_content"))
+ .Top());
+ m_mgr.AddPane(mWxGUIOutputMessages,
+ wxAuiPaneInfo().Name(wxT("messages_content"))
+ .Caption(wxT("Messages"))
+ .Center());
+ m_mgr.AddPane(mWxGUIHtmlBrowser,
+ wxAuiPaneInfo().Name(wxT("browser_content"))
+ .Right());
+ m_mgr.AddPane(mWxGUICommand,
+ wxAuiPaneInfo().Name(wxT("command_content"))
+ .Bottom());
+ m_mgr.AddPane(mwxButtonRun,
+ wxAuiPaneInfo().Name(wxT("button_run_content")));
+
+
+//.PaneBorder(false));
+ m_mgr.Update();
+
+ SetAutoLayout(true);
+ Layout();
+// Refresh();
+// m_mgr.Update();
+ }
+ //================================================================
+
+ //================================================================
+ WxGUIScriptingInterface::~WxGUIScriptingInterface()
+ {
+ m_mgr.UnInit();
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUIScriptingInterface::Open(const std::string& filename)
+ {
+ mWxGUITextEditor->Open(filename);
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
+ {
+ std::string s("> ");
+ s += command + "\n";
+ mWxGUIOutputMessages->Print(s,wxRED);
+
+ if ( mInterpreter->InterpretLine( command ) ==
+ Interpreter::QUIT )
+ {
+ Close(true);
+ }
+ }
+ //================================================================
+
+ //================================================================
+ /// Runs the interpretation of a file
+ bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
+ {
+ if ( mInterpreter->InterpretFile(filename) ==
+ Interpreter::ERROR )
+ {
+ return false;
+ }
+ return true;
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUIScriptingInterface::OnButtonRun(wxCommandEvent& WXUNUSED(event))
+ {
+ wxString per = m_mgr.SavePerspective();
+ std::cout << per<< std::endl;
+
+// wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
+ std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
+ size_t s = filename.length();
+
+ Interpreter* I = new Interpreter;
+
+ if ((s>3) && (filename[s-1]=='s')
+ && (filename[s-2]=='b')
+ && (filename[s-3]=='b')
+ && (filename[s-4]=='.'))
+ {
+ std::string tmp("Executing ");
+ tmp += filename;
+ SetStatusText(std2wx(tmp));
+ I->InterpretFile(filename);
+ }
+ else
+ {
+ SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
+ }
+
+ delete I;
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
+ {
+ Close(true);
+ }
+ //================================================================
+
+
+ //================================================================
+ void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
+ {
+ m_mgr.Update();
+ Refresh();
+ wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
+ _T("About ..."), wxOK | wxICON_INFORMATION,
+ this);
+ }
+ //================================================================
+
+
+ //================================================================
+ void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
+ {
+ std::string commandStr;
+ std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
+#ifdef WIN32
+ commandStr = "notepad.exe ";
+#else
+ commandStr = "gedit ";
+#endif
+ commandStr = commandStr + configFile;
+ std::cout << "system: " << commandStr << std::endl;
+ system ( commandStr.c_str() );
+ }
+ //================================================================
+
+
+ //================================================================
+ void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
+ {
+printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 01 \n");
+ std::string command("toolsbbtk/appli/CreatePackage");
+printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 02 \n");
+
+ bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
+printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 03 \n");
+ Interpreter* I = new Interpreter;
+printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 04 \n");
+ I->InterpretFile(command);
+printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 05 \n");
+ delete I;
+printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n");
+ }
+ //================================================================
+
+
+ //================================================================
+ void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
+ {
+ std::string command("toolsbbtk/appli/CreateBlackBox");
+ bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
+ Interpreter* I = new Interpreter;
+ I->InterpretFile(command);
+ delete I;
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
+ {
+ std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
+
+#if defined(WIN32)
+ std::string strappli="start ";
+#else
+ std::string strappli="gnome-open ";
+#endif
+ std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
+ std::cout << "system: " << strcommand << std::endl;
+ system ( strcommand.c_str() );
+
+ }
+ //================================================================
+
+
+ //================================================================
+ void WxGUIScriptingInterface::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
+ {
+ std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
+ std::string filepath = doc_path+"/bbdoc/make-index.bbs";
+ Interpreter* I = new Interpreter;
+
+//EED std::cout << "bbi: include "<<filepath<<std::endl;
+//EED I->InterpretFile( filepath );
+
+ I->InterpretLine( "exec freeze");
+ I->InterpretLine( "include *");
+ I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
+ I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
+ I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
+ I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
+
+ delete I;
+ }
+ //================================================================
+
+
+ //================================================================
+ void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
+ {
+ std::string s(page);
+ // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
+ if (mWxGUIHtmlBrowser->GoTo(s))
+ {
+//EED mwxNotebook->ChangeSelection(1);
+ mwxNotebook->SetSelection(1);
+ }
+ else
+ {
+ // std::cout << "ERROR html"<<std::endl;
+ }
+ }
+ //================================================================
+
+
+ //================================================================
+ BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
+ EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
+ EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
+ EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
+ EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
+ EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
+ EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
+ EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
+ EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
+ END_EVENT_TABLE()
+ //================================================================
+
+} // namespace bbtk
+
+
+#endif //_USE_WXWIDGETS_
--- /dev/null
+/*=========================================================================
+
+ Program: bbtk
+ Module: $RCSfile: bbtkWxGUIScriptingInterface.h,v $
+ Language: C++
+ Date: $Date: 2008/03/21 11:46:41 $
+ Version: $Revision: 1.1 $
+
+ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+ l'Image). All rights reserved. See Doc/License.txt or
+ http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*//**
+ * \brief Short description in one line
+ *
+ * Long description which
+ * can span multiple lines
+ */
+/**
+ * \file
+ * \brief
+ */
+/**
+ * \class bbtk::
+ * \brief
+ */
+
+
+#ifdef _USE_WXWIDGETS_
+
+
+#ifndef __bbtkWxGUIScriptingInterface_h__
+#define __bbtkWxGUIScriptingInterface_h__
+
+#include <wx/aui/aui.h>
+#include "bbtkWx.h"
+#include <wx/notebook.h>
+#include <wx/html/htmlwin.h>
+
+
+#include "bbtkInterpreter.h"
+
+#include "bbtkWxGUITextEditor.h"
+#include "bbtkWxGUICommand.h"
+#include "bbtkWxGUIOutputMessages.h"
+#include "bbtkWxGUIHtmlBrowser.h"
+
+namespace bbtk
+{
+
+ /// A scripting interface window
+ class BBTK_EXPORT WxGUIScriptingInterface : public wxFrame,
+ public InterpreterUser,
+ public WxGUICommandUser
+ {
+ public:
+ WxGUIScriptingInterface( wxWindow *parent, wxString title, wxSize size);
+ ~WxGUIScriptingInterface();
+
+ /// Returns the Interpreter used
+ /// ONLY ONE FOR THE MOMENT BUT IN THE FUTURE CAN BE DIFFERENT
+ /// (DIFFERENT WORKSPACES)
+ Interpreter* GetInterpreter() { return mInterpreter; }
+ /// Returns the Interpreter used (const)
+ const Interpreter* GetInterpreter() const { return mInterpreter; }
+
+ /// Sets the inputs of the workspace :
+ /// the map is passed as is to the Executer
+ void SetInputs(const std::map<std::string,std::string>& m)
+ { mInterpreter->SetInputs(m); }
+
+ /// Puts the executer in "no exec" mode,
+ /// which creates but does not execute pipelines.
+ void SetNoExecMode(bool b) { mInterpreter->SetNoExecMode(b); }
+
+ void SetDialogMode(Interpreter::DialogModeType t)
+ { mInterpreter->SetDialogMode(t); }
+
+ /// Runs the interpretation of a file
+ /// Returns false on error
+ bool InterpretFile( const std::string& filename);
+
+ void Open(const std::string& filename);
+
+
+ void OnMenuQuit(wxCommandEvent& event);
+ void OnMenuAbout(wxCommandEvent& event);
+ void OnMenuEditConfig(wxCommandEvent& WXUNUSED(event));
+ void OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event));
+ void OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event));
+ void OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event));
+ void OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event));
+
+
+ void OnButtonRun(wxCommandEvent& WXUNUSED(event));
+
+ // Interpreter callbacks
+ bool InterpreterUserHasOwnHtmlPageViewer() { return true; }
+ void InterpreterUserViewHtmlPage(const std::string&);
+
+ // WxGUICommand callbacks
+ void WxGUICommandEnter(const std::string&);
+
+ private:
+ wxAuiManager m_mgr;
+ Interpreter* mInterpreter;
+
+
+//EED wxNotebook* mwxNotebook;
+ wxAuiNotebook* mwxNotebook;
+ wxPanel *mwxPageCommand, *mwxPageHelp;
+
+ WxGUICommand* mWxGUICommand;
+ WxGUIOutputMessages* mWxGUIOutputMessages;
+ WxGUIHtmlBrowser* mWxGUIHtmlBrowser;
+ WxGUITextEditor* mWxGUITextEditor;
+
+ wxButton* mwxButtonRun;
+
+ public:
+
+
+ DECLARE_EVENT_TABLE()
+
+ };
+
+
+} // namespace bbtk
+
+
+#endif // __bbtkWxGUIScriptingInterface_h__
+
+#endif //_USE_WXWIDGETS_
--- /dev/null
+/*=========================================================================
+
+ Program: bbtk
+ Module: $RCSfile: bbtkWxGUITextEditor.cxx,v $
+ Language: C++
+ Date: $Date: 2008/03/21 11:46:41 $
+ Version: $Revision: 1.1 $
+
+ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+ l'Image). All rights reserved. See Doc/License.txt or
+ http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*//**
+ * \brief Short description in one line
+ *
+ * Long description which
+ * can span multiple lines
+ */
+/**
+ * \file
+ * \brief
+ */
+/**
+ * \class bbtk::
+ * \brief
+ */
+
+
+#ifdef _USE_WXWIDGETS_
+
+#include <iostream>
+#include "bbtkWxGUITextEditor.h"
+#include "bbtkWxBlackBox.h"
+#include "bbtkConfigurationFile.h"
+
+#include "icons/cc_new.xpm"
+#include "icons/cc_open.xpm"
+#include "icons/cc_save.xpm"
+#include "icons/cc_run.xpm"
+#include "icons/cc_exit.xpm"
+
+
+namespace bbtk
+{
+
+
+ //================================================================
+ class WxTextCtrlGettingKeyEvents : public wxTextCtrl
+ {
+ public:
+ WxTextCtrlGettingKeyEvents(wxWindow *parent, wxWindowID id, const wxString &value,
+ const wxPoint &pos, const wxSize &size, int style = 0)
+ : wxTextCtrl(parent, id, value, pos, size, style)
+ {
+ }
+
+ void SetWxGUITextEditor(WxGUITextEditor* e)
+ { mWxGUITextEditor = e; }
+
+ void OnKeyDown(wxKeyEvent& event);
+ void OnKeyUp(wxKeyEvent& event);
+ void OnChar(wxKeyEvent& event);
+ private :
+ WxGUITextEditor* mWxGUITextEditor;
+
+ DECLARE_EVENT_TABLE()
+ };
+
+ BEGIN_EVENT_TABLE(WxTextCtrlGettingKeyEvents, wxTextCtrl)
+ EVT_KEY_DOWN(WxTextCtrlGettingKeyEvents::OnKeyDown)
+ EVT_KEY_UP(WxTextCtrlGettingKeyEvents::OnKeyUp)
+ EVT_CHAR(WxTextCtrlGettingKeyEvents::OnChar)
+ END_EVENT_TABLE()
+
+
+ void WxTextCtrlGettingKeyEvents::OnChar(wxKeyEvent& event)
+ {
+ event.Skip();
+ }
+
+ void WxTextCtrlGettingKeyEvents::OnKeyUp(wxKeyEvent& event)
+ {
+ mWxGUITextEditor->OnKeyUp(event);
+ event.Skip();
+ }
+
+ void WxTextCtrlGettingKeyEvents::OnKeyDown(wxKeyEvent& event)
+ {
+ mWxGUITextEditor->OnKeyDown(event);
+ event.Skip();
+ }
+ //================================================================
+
+
+ //================================================================
+ 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)
+ EVT_CLOSE(WxGUITextEditorPage::OnClose)
+ END_EVENT_TABLE()
+ */
+
+ //================================================================
+ WxGUITextEditorPage::WxGUITextEditorPage(wxWindow* parent,
+ WxGUITextEditor* editor)
+ : wxPanel(parent,-1),
+ mEditor(editor),
+ mName(""),
+ mAskFilename(true)
+ {
+ wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+ mwxInputText =
+ new WxTextCtrlGettingKeyEvents(this,
+ -1, //ID_InputText,
+ _T(""),
+ wxDefaultPosition,
+ wxDefaultSize,
+ wxTE_MULTILINE
+ // |wxTE_PROCESS_ENTER
+ | wxTE_PROCESS_TAB
+ // | wxWANTS_CHARS
+ | wxTAB_TRAVERSAL
+ );
+ mwxInputText->SetWxGUITextEditor(mEditor);
+
+ wxFont* FixedFont = new wxFont(10,
+ wxFONTFAMILY_MODERN,
+ wxFONTSTYLE_NORMAL,
+ wxFONTWEIGHT_NORMAL,
+ false);
+
+ mwxInputTextAttr = new wxTextAttr;
+ mwxInputTextAttr->SetFont(*FixedFont);
+
+ sizer->Add(mwxInputText,1,wxGROW);
+ SetSizer(sizer);
+ SetAutoLayout(true);
+ Layout();
+ }
+ //================================================================
+
+ //================================================================
+ WxGUITextEditorPage::~WxGUITextEditorPage()
+ {
+ }
+ //================================================================
+
+
+ //================================================================
+ void WxGUITextEditorPage::Load(const std::string& filename)
+ {
+ std::cout << "-------------- LOAD ---------------"<<std::endl;
+ std::cout << "'" << filename << "'"<<std::endl;
+ //std::string oldFilename = mFilename;
+ mName = filename;
+ mAskFilename = false;
+ mwxInputText->LoadFile(std2wx(mName));
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUITextEditorPage::Save(const std::string& filter)
+ {
+ std::cout << "-------------- SAVE ---------------"<<std::endl;
+ if (mAskFilename)
+ {
+ wxFileDialog* fd = new wxFileDialog(this,_T("Save file"),_T(""),
+ _T(""),std2wx(filter),
+ wxSAVE | wxOVERWRITE_PROMPT );
+ fd->ShowModal();
+
+ if (fd->GetReturnCode()==wxID_OK)
+ {
+ mName = wx2std(fd->GetPath());
+ mAskFilename = false;
+ }
+ else
+ {
+ std::cout << "-------------- CANCELLED ---------------"
+ <<std::endl;
+ return;
+ }
+ }
+ std::cout << "file [" << mName << "]" <<std::endl;
+ mwxInputText->SaveFile(mName);
+ mwxInputText->SetModified(false);
+ }
+ //================================================================
+
+ //================================================================
+ WxGUITextEditor::WxGUITextEditor( wxWindow *parent )
+ : wxPanel(parent, -1),
+ mFileNameFilter("*.*")
+ {
+ std::cout << "WxGUITextEditor::WxGUITextEditor"<<std::endl;
+ // mInterpreter = new bbtk::Interpreter();
+ //mInterpreter->SetWxGUITextEditor(this);
+ // mInterpreter->SetCommandLine(true);
+ m_mgr.SetManagedWindow(this);
+
+ //==============
+ // Menu
+ wxInitAllImageHandlers();
+
+
+ // wxFlexGridSizer *sizer= new wxFlexGridSizer(2);
+ wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+ mwxNotebook = new wxAuiNotebook(this,
+ -1,
+ wxPoint(0, 0),
+ wxSize(500,500),
+ wxAUI_NB_TAB_SPLIT
+ | wxAUI_NB_TAB_MOVE
+ | wxAUI_NB_TAB_EXTERNAL_MOVE
+ | wxAUI_NB_WINDOWLIST_BUTTON
+ |wxAUI_NB_SCROLL_BUTTONS
+ // | wxAUI_NB_CLOSE_BUTTON
+ | wxAUI_NB_CLOSE_ON_ACTIVE_TAB
+ //| 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);
+
+ 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_save(cc_save_xpm);
+ mwxButtonSave = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSave,bmp_save);//_T("Save") );
+ btnsSizer->Add( mwxButtonSave );
+
+ /*
+ wxBitmap bmp_run(cc_run_xpm);
+ mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run);//_T("Run") );
+ btnsSizer->Add( mwxButtonRun );
+ wxBitmap bmp_quit(cc_exit_xpm);
+ mwxButtonQuit = new wxBitmapButton( btnsCtrlPanel,ID_ButtonQuit,bmp_quit);//_T("Quit") );
+ btnsSizer->Add( mwxButtonQuit );
+ */
+
+ mwxPosition = new wxStaticText ( btnsCtrlPanel, -1, _T(""));
+ btnsSizer->Add( mwxPosition );
+
+ btnsCtrlPanel->SetSizer(btnsSizer);
+ sizer->Add ( btnsCtrlPanel, 0, wxLEFT | wxRIGHT | wxBOTTOM //| wxGROW
+ , 10 );
+
+
+ NewPage("");
+ UpdateInfo();
+
+ SetSizer(sizer);
+ SetAutoLayout(true);
+ Layout();
+ }
+ //================================================================
+
+ //================================================================
+ WxGUITextEditor::~WxGUITextEditor()
+ {
+ m_mgr.UnInit();
+ // delete mInterpreter;
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUITextEditor::NewPage(const std::string& filename)
+ {
+ WxGUITextEditorPage* page =
+ new WxGUITextEditorPage(mwxNotebook,this);
+ std::string name("untitled");
+ if (filename.size()!=0)
+ {
+ name = filename;
+ page->Load(name);
+ }
+ page->SetPageName(name);
+ mwxNotebook->AddPage(page,name,true);
+ FocusOnCurrentPage();
+ }
+ //================================================================
+
+ //================================================================
+ WxGUITextEditorPage* WxGUITextEditor::GetCurrentPage()
+ {
+ return (WxGUITextEditorPage*)
+ mwxNotebook->GetPage(mwxNotebook->GetSelection());
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUITextEditor::FocusOnCurrentPage()
+ {
+ if (mwxNotebook->GetPageCount()==0) return;
+ GetCurrentPage()->SetFocus();
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUITextEditor::OnButtonOpen(wxCommandEvent& event)
+ {
+ Open();
+ FocusOnCurrentPage();
+ }
+ void WxGUITextEditor::Open()
+ {
+ std::cout << "-------------- OPEN ---------------"<<std::endl;
+
+ wxFileDialog* fd = new wxFileDialog(this,_T("Open file"),_T(""),
+ _T(""),std2wx(mFileNameFilter),
+ wxOPEN | wxFILE_MUST_EXIST );
+ fd->ShowModal();
+
+ if (fd->GetReturnCode()==wxID_OK)
+ {
+ std::string filename = wx2std(fd->GetPath());
+ std::cout << "file [" << filename << "]" <<std::endl;
+ Open(filename);
+ }
+ else
+ {
+ std::cout << "-------------- CANCELLED ---------------"<<std::endl;
+ }
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUITextEditor::Open(const std::string& filename)
+ {
+ NewPage(filename);
+ UpdateInfo();
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUITextEditor::OnButtonSave(wxCommandEvent& event)
+ {
+ Save();
+ }
+ void WxGUITextEditor::Save()
+ {
+ std::cout << "-------------- SAVE ---------------"<<std::endl;
+ if (mwxNotebook->GetPageCount()==0) return;
+ GetCurrentPage()->Save(mFileNameFilter);
+ mwxNotebook->SetPageText(mwxNotebook->GetSelection(),
+ GetCurrentPage()->GetPageName());
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt)
+ {
+ std::cout << "-------------- CLOSE ---------------"<<std::endl;
+ if (mwxNotebook->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 : ;
+ }
+ }
+
+ }
+ //================================================================
+
+
+ /*
+ //================================================================
+ void WxGUITextEditor::OnButtonQuit(wxCommandEvent& event)
+ {
+ Quit();
+ FocusOnCurrentPage();
+ }
+ void WxGUITextEditor::Quit()
+ {
+ std::cout << "-------------- QUIT ---------------"<<std::endl;
+ if (AskSave()) GetParent()->Close();
+ }
+ //================================================================
+
+
+ //================================================================
+ void WxGUITextEditor::OnButtonRun(wxCommandEvent& event)
+ {
+ Run();
+ FocusOnCurrentPage();
+ }
+ void WxGUITextEditor::Run()
+ {
+ std::cout << "-------------- RUN ---------------"<<std::endl;
+
+ if (!mwxSplit->IsSplit())
+ {
+ int size = -100;
+ int minsize = - (int)(mwxInputText->GetSize().GetHeight() / 2.);
+ if (size<minsize) size = minsize;
+ mwxSplit->SplitHorizontally( mwxInputText, mwxOutputText, size);
+ }
+
+ std::stringstream* buffer = new std::stringstream(bbtk::wx2std(mwxInputText->GetValue()));
+ mInterpreter->InterpretLine("reset");
+ try
+ {
+ mInterpreter->InterpretBuffer(buffer);
+ }
+ catch (...)
+ {
+ }
+ }
+ //================================================================
+*/
+
+
+
+ //================================================================
+
+ //================================================================
+ void WxGUITextEditor::OnButtonNew(wxCommandEvent& event)
+ {
+ New();
+ FocusOnCurrentPage();
+ }
+ void WxGUITextEditor::New()
+ {
+ std::cout << "-------------- NEW ---------------" << std::endl;
+ NewPage("");
+ UpdateInfo();
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUITextEditor::UpdateInfo()
+ {
+ if (mwxNotebook->GetPageCount()==0) return;
+ WxTextCtrlGettingKeyEvents* text = GetCurrentPage()->GetTextCtrl();
+
+ long line, column, pos;
+ pos = text->GetInsertionPoint();
+ text->PositionToXY(pos, &column, &line);
+
+
+ // wxLogMessage(_T("Current position: %ld\nCurrent line, column: (%ld, %ld)\nNumber of lines: %ld\nCurrent line length: %ld\nTotal text length: %u (%ld)"),
+
+
+ char mess[200];
+ sprintf(mess,"%ld:%ld/%ld:%ld",
+ line+1,column+1,
+ (long)text->GetNumberOfLines(),
+ (long)text->GetLineLength(line)+1);
+ // pos+1,
+ // (long)mwxInputText->GetValue().length())+1;
+
+ mwxPosition->SetLabel(wxString(mess));
+ mwxPosition->Show();
+
+ if (text->IsModified())
+ {
+ std::string title("*");
+ title += GetCurrentPage()->GetPageName();
+ mwxNotebook->SetPageText(mwxNotebook->GetSelection(),title);
+ }
+ }
+ //================================================================
+ //================================================================
+ void WxGUITextEditor::OnKeyUp(wxKeyEvent& event)
+ {
+ // std::cout << "U" << std::endl;
+ UpdateInfo();
+ }
+ //================================================================
+
+ //================================================================
+ void WxGUITextEditor::OnKeyDown(wxKeyEvent& event)
+ {
+ // std::cout << "D" << std::endl;
+ // std::cout << "Key="<<event.GetKeyCode()<<std::endl;
+ if ( event.ControlDown() )
+ {
+ switch (event.GetKeyCode())
+ {
+ case 'n': case 'N' : New(); break;
+ case 's': case 'S' : Save(); break;
+ case 'o': case 'O' : Open(); break;
+ // case 'r': case 'R' : Run(); break;
+ // case 'q': case 'Q' : Quit(); break;
+ }
+ }
+ }
+ //================================================================
+
+ //================================================================
+ 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_ButtonSave, WxGUITextEditor::OnButtonSave)
+ // 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()
+ //================================================================
+
+
+
+
+
+ //================================================================
+ WxGUITextEditorWindow::WxGUITextEditorWindow( wxWindow *parent,
+ wxString title,
+ wxSize size)
+ : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
+ {
+
+
+ wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+ mEditor = new WxGUITextEditor(this);
+ sizer->Add(mEditor,1,wxGROW);
+
+ // WxGUICommand* com = new WxGUICommand(this,this);
+ // sizer->Add(com);
+
+ SetSizer(sizer);
+
+ // Creates and sets the parent window of all bbtk windows
+ wxWindow* top = new wxPanel(this,-1);
+ top->Hide();
+
+ Wx::SetTopWindow(top);
+
+ SetAutoLayout(true);
+ Layout();
+ }
+ //================================================================
+
+ //================================================================
+ WxGUITextEditorWindow::~WxGUITextEditorWindow()
+ {
+ }
+ //================================================================
+
+
+} // namespace bbtk
+
+
+#endif //_USE_WXWIDGETS_
/*=========================================================================
Program: bbtk
- Module: $RCSfile: bbtkWxEditor.h,v $
+ Module: $RCSfile: bbtkWxGUITextEditor.h,v $
Language: C++
- Date: $Date: 2008/03/20 09:51:29 $
- Version: $Revision: 1.5 $
+ Date: $Date: 2008/03/21 11:46:41 $
+ Version: $Revision: 1.1 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#ifdef _USE_WXWIDGETS_
-#ifndef __bbtkWxEditor_h__
-#define __bbtkWxEditor_h__
+#ifndef __bbtkWxGUITextEditor_h__
+#define __bbtkWxGUITextEditor_h__
#include "bbtkWx.h"
#include "bbtkInterpreter.h"
#include <wx/splitter.h>
+#include <wx/aui/aui.h>
#include "bbtkWxGUICommand.h"
namespace bbtk
{
- class WxStreamRedirector;
class WxTextCtrlGettingKeyEvents;
+ class WxGUITextEditorPage;
/// A bbs editor panel
- class BBTK_EXPORT WxEditor : public wxPanel
+ class BBTK_EXPORT WxGUITextEditor : public wxPanel
{
public:
- WxEditor( wxWindow *parent );
- ~WxEditor();
+ WxGUITextEditor( wxWindow *parent );
+ ~WxGUITextEditor();
void OnKeyDown(wxKeyEvent& event);
void OnKeyUp(wxKeyEvent& event);
void OnButtonNew(wxCommandEvent& event);
void OnButtonOpen(wxCommandEvent& event);
void OnButtonSave(wxCommandEvent& event);
- void OnButtonRun(wxCommandEvent& event);
- void OnButtonQuit(wxCommandEvent& event);
+ // void OnButtonRun(wxCommandEvent& event);
+ // void OnButtonQuit(wxCommandEvent& event);
+ void OnPageClose(wxAuiNotebookEvent& evt);
void New();
void Open();
void Open(const std::string& filename);
- bool AskSave();
void Save();
- void Run();
- void Quit();
+ // void Run();
+ // void Quit();
void HighlightSyntax();
- void UpdatePosition();
+ void UpdateInfo();
+ void NewPage(const std::string& filename);
+ WxGUITextEditorPage* GetCurrentPage();
+ void FocusOnCurrentPage();
+
+ void SetFileNameFilter(const std::string& filter)
+ { mFileNameFilter = filter; }
private:
- Interpreter* mInterpreter;
- wxSplitterWindow* mwxSplit;
- WxTextCtrlGettingKeyEvents* mwxInputText;
- wxTextAttr* mwxInputTextAttr;
- WxTextCtrlGettingKeyEvents* mwxOutputText;
- wxTextAttr* mwxOutputTextAttr;
+ wxAuiManager m_mgr;
+ wxAuiNotebook* mwxNotebook;
+
+ // Interpreter* mInterpreter;
+ // wxSplitterWindow* mwxSplit;
+
wxButton * mwxButtonNew;
wxButton * mwxButtonOpen;
wxButton * mwxButtonSave;
- wxButton * mwxButtonRun;
- wxButton * mwxButtonQuit;
+ // wxButton * mwxButtonRun;
+ // wxButton * mwxButtonQuit;
wxStaticText* mwxPosition;
- WxStreamRedirector* mRedirect_cout;
- WxStreamRedirector* mRedirect_cerr;
+
+ std::string mFileNameFilter;
+
public:
enum
{
- ID_InputText,
- ID_OutputText,
ID_ButtonNew,
ID_ButtonOpen,
- ID_ButtonSave,
- ID_ButtonRun,
- ID_ButtonQuit
+ ID_ButtonSave
+ // ID_ButtonRun,
+ // ID_ButtonQuit
};
DECLARE_EVENT_TABLE()
};
-
+
/// Editor in a frame
- class BBTK_EXPORT WxEditorWindow : public wxFrame, public WxGUICommandUser
+ class BBTK_EXPORT WxGUITextEditorWindow : public wxFrame
+ //, public WxGUICommandUser
{
public:
- WxEditorWindow( wxWindow *parent, wxString title, wxSize size);
- ~WxEditorWindow();
+ WxGUITextEditorWindow( wxWindow *parent, wxString title, wxSize size);
+ ~WxGUITextEditorWindow();
void Open(const std::string& filename) { mEditor->Open(filename); }
- void WxGUICommandEnter(const std::string& s);
+ // void WxGUICommandEnter(const std::string& s);
private :
- WxEditor* mEditor;
+ WxGUITextEditor* mEditor;
};
+
} // namespace bbtk
-#endif // __bbtkWxEditor_h__
+#endif // __bbtkWxGUITextEditor_h__
#endif //_USE_WXWIDGETS_