/* * LogEntryFrame.cpp * * Created on: Mar 22, 2016 * Author: Hovanes Egiyan */ #include "LogEntryFrame.hh" using namespace std; ClassImp(LogEntryFrame) LogEntryFrame::LogEntryFrame( const UInt_t w, const UInt_t h, TGTextBuffer& tBuf ) : TGTransientFrame( gClient->GetRoot(), gClient->GetRoot(), w, h, kVerticalFrame), lefTextBox(0), lefTextBuffer(tBuf) { SetBackgroundColor(0x202020); SetWindowName( "Log Entry Text"); SetName("Log Entry Text"); this->Connect("CloseWindow()", "LogEntryFrame", this, "CloseWindow()"); this->DontCallClose(); // use hierarchical cleaning this->SetCleanup(kDeepCleanup); // Create the text entry box in a separate frame TGHorizontalFrame* textFrame = new TGHorizontalFrame( this, w, h ); textFrame->SetBackgroundColor(0xFFFFFF); this->AddFrame( textFrame, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2) ); lefTextBox = new TGTextEdit( textFrame, 500, 200, kSunkenFrame | kDoubleBorder ); textFrame->AddFrame( lefTextBox, new TGLayoutHints( kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3) ); lefTextBox->SetText( new TGText( "Put your comment here ..." ) ); // Make the OK and Cancel buttons in a separate frame TGHorizontalFrame* buttonFrame = new TGHorizontalFrame( this, w, h/30 ); buttonFrame->SetBackgroundColor(0xAFA788); TGTextButton* logButton = new TGTextButton(buttonFrame, "&Submit"); logButton->Connect("Clicked()", "LogEntryFrame", this, "DoOK()"); logButton->SetWidth(100); logButton->SetMinWidth(100); buttonFrame->AddFrame( logButton, new TGLayoutHints( kLHintsBottom | kLHintsCenterX, 5, 5, 3, 4) ); TGTextButton* closeButton = new TGTextButton(buttonFrame, "&Cancel"); closeButton->Connect("Clicked()", "LogEntryFrame", this, "CloseWindow()"); closeButton->SetWidth(100); closeButton->SetMinWidth(100); buttonFrame->AddFrame( closeButton, new TGLayoutHints( kLHintsBottom | kLHintsCenterX, 5, 5, 3, 4) ); this->AddFrame( buttonFrame, new TGLayoutHints( kLHintsExpandX, 2, 2, 2, 2) ); MapSubwindows(); Resize(GetDefaultSize()); MapWindow(); lefTextBox->SelectAll(); lefTextBox->SetFocus(); return; } LogEntryFrame::~LogEntryFrame() { cout << "LogEntryFrame Destructor called" << endl; return; } void LogEntryFrame::CloseWindow() { cout << "Called LogEntryFrame::CloseWindow" << endl; lefTextBuffer.AddText( 0, "" ); TGTransientFrame::CloseWindow(); throw runtime_error( "Canceled log entry" ); return; } void LogEntryFrame::DoOK() { TGText* currentText = lefTextBox->GetText(); string textThatFits = string( currentText->AsString().Data() ).substr( 0, lefTextBuffer.GetBufferLength() ); lefTextBuffer.AddText( 0, textThatFits.c_str() ); TGTransientFrame::CloseWindow(); return; } void LogEntryFrame::SetTitle() { cout << "Called LogEntryFrame::SetTitle()" << endl; return; }