// implementation of class ConfigEditorDlg
// M. Pallavicini - created 31/12/2001
//
#include "ConfigEditorDlg.hh"
#include "EusoApplication.hh"
ClassImp(ConfigEditorDlg)
//______________________________________________________________________________
ConfigEditorDlg::ConfigEditorDlg(EusoApplication *app, const char* fn, TGWindow *main) :
TGTransientFrame(gClient->GetRoot(),main,500,600) {
if (!fn) {
fprintf(stdout,"Error in ConfigEditorDlg: invalid file namen");
strcpy(fname,"");
return;
}
theApp = app;
strcpy(fname,fn);
fEdit = new TGTextEdit( this, 500, 600, kSunkenFrame|kDoubleBorder);
fL1 = new TGLayoutHints( kLHintsBottom | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 3,3,3,3);
AddFrame( fEdit, fL1 );
fFrame = new TGHorizontalFrame(this,260,20,kFixedWidth);
fL2 = new TGLayoutHints( kLHintsTop|kLHintsLeft|kLHintsExpandX,2,2,2,2);
fSave = new TGTextButton( this, " &Save ",EDIT_SAVE_BUTTON);
fFrame->AddFrame( fSave, fL2 );
fSave->Associate( this );
fSaveAs = new TGTextButton( this, "Save&As",EDIT_SAVEAS_BUTTON);
fFrame->AddFrame( fSaveAs, fL2 );
fSaveAs->Associate( this );
fMem = new TGTextButton( this, "&Memory",EDIT_MEMORY_BUTTON);
fFrame->AddFrame( fMem, fL2 );
fMem->Associate( this );
fCancel = new TGTextButton( this, "&Cancel",EDIT_CANCEL_BUTTON);
fFrame->AddFrame( fCancel, fL2 );
fCancel->Associate( this );
fL3 = new TGLayoutHints( kLHintsBottom|kLHintsRight,3,3,3,3);
//AddFrame( fSave, fL2 );
//AddFrame( fSaveAs, fL2 );
//AddFrame( fFrame, fL2 );
//AddFrame( fMem, fL3 );
//AddFrame( fCancel, fL3 );
//fL3 = new TGLayoutHints( kLHintsBottom|kLHintsLeft,0,0,1,1);
AddFrame( fFrame, fL3 );
char str[1000];
sprintf(str,"Edit config file: %s",fname);
SetWindowName( str );
SetIconName( str );
fEdit->LoadFile( fname );
MapSubwindows();
Resize( GetDefaultSize() );
Window_t wd;
int ax,ay;
gVirtualX->TranslateCoordinates( main->GetId(), GetParent()->GetId(),
(((TGFrame*)main)->GetWidth()-500)>>1,
(((TGFrame*)main)->GetWidth()-600)>>1, ax, ay, wd );
Move(ax,ay);
SetWMPosition( ax, ay );
MapWindow();
}
//______________________________________________________________________________
ConfigEditorDlg::~ConfigEditorDlg() {
delete fEdit;
delete fSave;
delete fSaveAs;
delete fMem;
delete fCancel;
delete fL1;
delete fL2;
theApp->SetLock( false );
}
//______________________________________________________________________________
void
ConfigEditorDlg::CloseWindow() {
delete this;
}
//______________________________________________________________________________
Bool_t
ConfigEditorDlg::ProcessMessage(Long_t msg, Long_t p1, Long_t p2) {
switch( GET_MSG(msg) ) {
case kC_COMMAND:
switch(GET_SUBMSG(msg)) {
case kCM_BUTTON:
switch(p1) {
case EDIT_SAVE_BUTTON: // modify existing file
fEdit->SaveFile( fname, kFALSE );
delete this;
break;
case EDIT_SAVEAS_BUTTON: // crate a new param file asking user for a file name
fEdit->SaveFile( 0, kTRUE );
delete this;
break;
case EDIT_MEMORY_BUTTON: // load params in ram without changing files
// to be done....
// delete this;
break;
case EDIT_CANCEL_BUTTON: // exit with no saving
delete this;
break;
}
break;
default:
break;
}
break;
case kC_TEXTVIEW:
break;
default:
break;
}
return kTRUE;
}