Program: bbtk
Module: $RCSfile: bbtkWxEditor.cxx,v $
Language: C++
- Date: $Date: 2008/03/18 15:31:51 $
- Version: $Revision: 1.3 $
+ Date: $Date: 2008/03/19 14:58:13 $
+ 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
void WxTextCtrlGettingKeyEvents::OnKeyUp(wxKeyEvent& event)
{
+ mWxEditor->OnKeyUp(event);
event.Skip();
}
void WxTextCtrlGettingKeyEvents::OnKeyDown(wxKeyEvent& event)
{
- mWxEditor->OnKeyPress(event);
+ mWxEditor->OnKeyDown(event);
event.Skip();
}
//================================================================
// sizer->AddGrowableCol(0);
// sizer->Add(mwxInputText,1,wxGROW);
- mwxInputText->SetFocus();
-
mwxOutputText =
new WxTextCtrlGettingKeyEvents(mwxSplit,
ID_OutputText,
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);
-
-
- SetSizer(sizer);
+ 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;
//================================================================
- void WxEditor::OnButtonOpen(wxCommandEvent& event) { Open(); }
+ void WxEditor::OnButtonOpen(wxCommandEvent& event)
+ {
+ Open();
+ mwxInputText->SetFocus();
+ }
void WxEditor::Open()
{
std::cout << "-------------- OPEN ---------------"<<std::endl;
{
mwxInputText->LoadFile(std2wx(filename));
mwxInputText->SetModified(false);
+ UpdatePosition();
}
//================================================================
//================================================================
- void WxEditor::OnButtonSave(wxCommandEvent& event) { Save(); }
+ void WxEditor::OnButtonSave(wxCommandEvent& event)
+ {
+ Save();
+ mwxInputText->SetFocus();
+ }
void WxEditor::Save()
{
std::cout << "-------------- SAVE ---------------"<<std::endl;
//================================================================
//================================================================
- void WxEditor::OnButtonQuit(wxCommandEvent& event) { Quit(); }
+ void WxEditor::OnButtonQuit(wxCommandEvent& event)
+ {
+ Quit();
+ mwxInputText->SetFocus();
+ }
void WxEditor::Quit()
{
std::cout << "-------------- QUIT ---------------"<<std::endl;
//================================================================
- void WxEditor::OnButtonRun(wxCommandEvent& event) { Run(); }
+ void WxEditor::OnButtonRun(wxCommandEvent& event)
+ {
+ Run();
+ mwxInputText->SetFocus();
+ }
void WxEditor::Run()
{
std::cout << "-------------- RUN ---------------"<<std::endl;
}
std::stringstream* buffer = new std::stringstream(bbtk::wx2std(mwxInputText->GetValue()));
- bool com = false;
- mInterpreter->InterpretLine("reset",com);
+ mInterpreter->InterpretLine("reset");
try
{
mInterpreter->InterpretBuffer(buffer);
//================================================================
//================================================================
- void WxEditor::OnButtonNew(wxCommandEvent& event) { New(); }
+ void WxEditor::OnButtonNew(wxCommandEvent& event)
+ {
+ New();
+ mwxInputText->SetFocus();
+ }
void WxEditor::New()
{
std::cout << "-------------- NEW ---------------" << std::endl;
AskSave();
mwxInputText->Clear();
+ UpdatePosition();
}
//================================================================
//================================================================
- void WxEditor::OnKeyPress(wxKeyEvent& event)
+ void WxEditor::UpdatePosition()
{
- long line, column, pos = mwxInputText->GetInsertionPoint();
- mwxInputText->PositionToXY(pos, &column, &line);
+ 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 (%ld char)",
- line,column,
+ sprintf(mess,"%ld:%ld/%ld:%ld",
+ line+1,column+1,
(long)mwxInputText->GetNumberOfLines(),
- (long)mwxInputText->GetLineLength(line),
- (long)mwxInputText->GetValue().length());
+ (long)mwxInputText->GetLineLength(line)+1);
+ // pos+1,
+ // (long)mwxInputText->GetValue().length())+1;
mwxPosition->SetLabel(wxString(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() )
{