1 | // implementation of class ConfigEditorDlg |
---|
2 | // M. Pallavicini - created 31/12/2001 |
---|
3 | // |
---|
4 | |
---|
5 | #include "ConfigEditorDlg.hh" |
---|
6 | #include "SimuApplication.hh" |
---|
7 | |
---|
8 | ClassImp(ConfigEditorDlg) |
---|
9 | |
---|
10 | //______________________________________________________________________________ |
---|
11 | ConfigEditorDlg::ConfigEditorDlg(SimuApplication *app, const char* fn, TGWindow *main) : |
---|
12 | TGTransientFrame(gClient->GetRoot(),main,500,600) { |
---|
13 | |
---|
14 | if (!fn) { |
---|
15 | fprintf(stdout,"Error in ConfigEditorDlg: invalid file name\n"); |
---|
16 | strcpy(fname,""); |
---|
17 | return; |
---|
18 | } |
---|
19 | theApp = app; |
---|
20 | strcpy(fname,fn); |
---|
21 | fEdit = new TGTextEdit( this, 500, 600, kSunkenFrame|kDoubleBorder); |
---|
22 | fL1 = new TGLayoutHints( kLHintsBottom | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 3,3,3,3); |
---|
23 | AddFrame( fEdit, fL1 ); |
---|
24 | |
---|
25 | fFrame = new TGHorizontalFrame(this,260,20,kFixedWidth); |
---|
26 | fL2 = new TGLayoutHints( kLHintsTop|kLHintsLeft|kLHintsExpandX,2,2,2,2); |
---|
27 | fSave = new TGTextButton( this, " &Save ",EDIT_SAVE_BUTTON); |
---|
28 | fFrame->AddFrame( fSave, fL2 ); |
---|
29 | fSave->Associate( this ); |
---|
30 | fSaveAs = new TGTextButton( this, "Save&As",EDIT_SAVEAS_BUTTON); |
---|
31 | fFrame->AddFrame( fSaveAs, fL2 ); |
---|
32 | fSaveAs->Associate( this ); |
---|
33 | fMem = new TGTextButton( this, "&Memory",EDIT_MEMORY_BUTTON); |
---|
34 | fFrame->AddFrame( fMem, fL2 ); |
---|
35 | fMem->Associate( this ); |
---|
36 | fCancel = new TGTextButton( this, "&Cancel",EDIT_CANCEL_BUTTON); |
---|
37 | fFrame->AddFrame( fCancel, fL2 ); |
---|
38 | fCancel->Associate( this ); |
---|
39 | |
---|
40 | fL3 = new TGLayoutHints( kLHintsBottom|kLHintsRight,3,3,3,3); |
---|
41 | //AddFrame( fSave, fL2 ); |
---|
42 | //AddFrame( fSaveAs, fL2 ); |
---|
43 | //AddFrame( fFrame, fL2 ); |
---|
44 | //AddFrame( fMem, fL3 ); |
---|
45 | //AddFrame( fCancel, fL3 ); |
---|
46 | |
---|
47 | //fL3 = new TGLayoutHints( kLHintsBottom|kLHintsLeft,0,0,1,1); |
---|
48 | AddFrame( fFrame, fL3 ); |
---|
49 | |
---|
50 | char str[1000]; |
---|
51 | sprintf(str,"Edit config file: %s",fname); |
---|
52 | SetWindowName( str ); |
---|
53 | SetIconName( str ); |
---|
54 | |
---|
55 | fEdit->LoadFile( fname ); |
---|
56 | |
---|
57 | MapSubwindows(); |
---|
58 | Resize( GetDefaultSize() ); |
---|
59 | Window_t wd; |
---|
60 | int ax,ay; |
---|
61 | gVirtualX->TranslateCoordinates( main->GetId(), GetParent()->GetId(), |
---|
62 | (((TGFrame*)main)->GetWidth()-500)>>1, |
---|
63 | (((TGFrame*)main)->GetWidth()-600)>>1, ax, ay, wd ); |
---|
64 | Move(ax,ay); |
---|
65 | SetWMPosition( ax, ay ); |
---|
66 | MapWindow(); |
---|
67 | } |
---|
68 | |
---|
69 | //______________________________________________________________________________ |
---|
70 | ConfigEditorDlg::~ConfigEditorDlg() { |
---|
71 | delete fEdit; |
---|
72 | delete fSave; |
---|
73 | delete fSaveAs; |
---|
74 | delete fMem; |
---|
75 | delete fCancel; |
---|
76 | delete fL1; |
---|
77 | delete fL2; |
---|
78 | theApp->SetLock( false ); |
---|
79 | } |
---|
80 | |
---|
81 | //______________________________________________________________________________ |
---|
82 | void |
---|
83 | ConfigEditorDlg::CloseWindow() { |
---|
84 | delete this; |
---|
85 | } |
---|
86 | |
---|
87 | //______________________________________________________________________________ |
---|
88 | Bool_t |
---|
89 | ConfigEditorDlg::ProcessMessage(Long_t msg, Long_t p1, Long_t p2) { |
---|
90 | switch( GET_MSG(msg) ) { |
---|
91 | case kC_COMMAND: |
---|
92 | switch(GET_SUBMSG(msg)) { |
---|
93 | case kCM_BUTTON: |
---|
94 | switch(p1) { |
---|
95 | case EDIT_SAVE_BUTTON: // modify existing file |
---|
96 | fEdit->SaveFile( fname, kFALSE ); |
---|
97 | delete this; |
---|
98 | break; |
---|
99 | case EDIT_SAVEAS_BUTTON: // crate a new param file asking user for a file name |
---|
100 | fEdit->SaveFile( 0, kTRUE ); |
---|
101 | delete this; |
---|
102 | break; |
---|
103 | case EDIT_MEMORY_BUTTON: // load params in ram without changing files |
---|
104 | // to be done.... |
---|
105 | // delete this; |
---|
106 | break; |
---|
107 | case EDIT_CANCEL_BUTTON: // exit with no saving |
---|
108 | delete this; |
---|
109 | break; |
---|
110 | } |
---|
111 | break; |
---|
112 | default: |
---|
113 | break; |
---|
114 | } |
---|
115 | break; |
---|
116 | case kC_TEXTVIEW: |
---|
117 | break; |
---|
118 | default: |
---|
119 | break; |
---|
120 | } |
---|
121 | return kTRUE; |
---|
122 | } |
---|
123 | |
---|