source: trunk/MagicSoft/Mars/mgui/MGPrototyp.cc@ 597

Last change on this file since 597 was 587, checked in by harald, 24 years ago
The integration of the class MGFadcDisp in the mars code. Now one is able to see at least the high gain samples with this gui. I hope that also Razmik is now able to look to the data.
File size: 12.2 KB
Line 
1#include "MGPrototyp.h"
2
3#include <TSystem.h> // gSystem
4
5#include <TGTab.h> // TGTab
6#include <TGMenu.h> // TGPopupMenu
7#include <TGButton.h> // TGTextButton
8#include <TGMsgBox.h> // TGMsgBox
9#include <TGListBox.h> // TGListBox
10#include <TGFSContainer.h> // TGFileContainer
11#include <TGSplitter.h> // TGHorizontal3DLine
12#include <TGTextEntry.h>
13#include <TGLabel.h> // TGLabel
14
15
16// FIXME: Move to MAGIC.h
17#define S_ISDIR(m) (((m)&(0170000)) == (0040000))
18
19ClassImp(MGPrototyp)
20
21enum CommandPrototyp {
22 M_FILE_CLOSE ,
23 M_BUTTON_ACTION,
24
25 M_FILERESET,
26 M_PBUTTON_CDIR_UP,
27 M_PBUTTON_LIST_MODE,
28 M_PBUTTON_DETAIL_MODE
29} ;
30
31
32MGPrototyp::MGPrototyp(const TGWindow *p, const TGWindow *main,
33 UInt_t w, UInt_t h )
34 : TGTransientFrame(p, main, w, h )
35{
36 //
37 // Main window to controll the october test
38 //
39
40 // set non-gui members to starting values
41
42 sprintf ( fInputFile, "\n" ) ;
43
44 //
45 // First create the MenuBar.
46 //
47
48 // Layout objects for menue.
49
50 fLayMenuBar = new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) ;
51 fLayMenuItem = new TGLayoutHints ( kLHintsTop | kLHintsLeft , 0, 4, 0, 0 ) ;
52
53 // crate the menu bar
54
55 fFileMenu = new TGPopupMenu ( fClient->GetRoot() ) ;
56 fFileMenu->AddEntry ("Close", M_FILE_CLOSE ) ;
57 fFileMenu->Associate(this) ;
58
59 // the button messages are handled by main frame (this)
60
61 fMenuBar = new TGMenuBar ( this, 1, 1, kHorizontalFrame ) ;
62 fMenuBar->AddPopup("File", fFileMenu, fLayMenuItem ) ;
63 AddFrame(fMenuBar, fLayMenuBar ) ;
64
65 fLineSep1 = new TGHorizontal3DLine(this) ;
66 AddFrame(fLineSep1, new TGLayoutHints(kLHintsTop | kLHintsExpandX) );
67
68
69 //
70 // Create the top window with a lot of buttons
71 //
72
73 fFrameTop = new TGCompositeFrame (this, 300,100, kVerticalFrame ) ;
74
75 fTop1 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
76
77 fButAction = new TGTextButton(fTop1, "ACTION", M_BUTTON_ACTION );
78 fButAction->Associate(this) ;
79 fTop1->AddFrame (fButAction, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 10, 5, 5) );
80
81 fFrameTop->AddFrame (fTop1, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
82
83 AddFrame(fFrameTop, new TGLayoutHints (kLHintsTop ) ) ;
84
85 // a line between top and low frame
86
87 fLineSep2 = new TGHorizontal3DLine(this) ;
88 AddFrame(fLineSep2, new TGLayoutHints(kLHintsTop | kLHintsExpandX) );
89
90 //
91 // Create the low window with a tabs in it
92 //
93
94 fFrameLow = new TGCompositeFrame (this, 300,100, kHorizontalFrame ) ;
95
96 fLayTab = new TGLayoutHints ( kLHintsExpandX , 5, 5, 5, 5 ) ;
97
98 // create the first tab
99
100 fTab = new TGTab ( fFrameLow, 400, 400 ) ;
101
102 TGCompositeFrame *tf = fTab->AddTab("Input File") ;
103
104 fTabF1 = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
105 // tf->AddFrame(fTabF1, fLayTab ) ;
106
107 fTabF1a = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
108 tf->AddFrame(fTabF1a, new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
109
110 fTabF1b = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
111 tf->AddFrame(fTabF1b, new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
112
113 fTabF1c = new TGCompositeFrame (tf, 100, 100, kVerticalFrame) ;
114 // tf->AddFrame(fTabF1c, new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 5, 5, 5, 5 ) ) ;
115 tf->AddFrame(fTabF1c, new TGLayoutHints ( kLHintsExpandX | kLHintsExpandY , 5, 5, 5, 5 ) ) ;
116
117 // the items in the first subframe
118
119 fLabFileName = new TGLabel(fTabF1a, new TGString("selected File:") );
120 fTabF1a->AddFrame( fLabFileName, new TGLayoutHints (kLHintsLeft, 10, 10, 10, 10)) ;
121
122 fTxtFileName = new TGTextEntry(fTabF1a, fTxtBufFileName = new TGTextBuffer(256) );
123 fTxtFileName->Resize(60, fTxtFileName->GetDefaultHeight());
124 fTabF1a->AddFrame(fTxtFileName, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5));
125
126 fButFileReset = new TGTextButton (fTabF1a, "Reset", M_FILERESET ) ;
127 fButFileReset->Associate(this) ;
128 fTabF1a->AddFrame (fButFileReset, new TGLayoutHints (kLHintsRight, 10, 10, 10, 10 ) ) ;
129
130
131
132 // the items in the second subfraem
133
134 fLabDir = new TGLabel(fTabF1b, new TGString("Directory:") );
135 fTabF1b->AddFrame( fLabDir, new TGLayoutHints (kLHintsLeft, 10, 10, 10, 10)) ;
136
137 fDir = new TGListBox(fTabF1b, -1) ;
138 fDir->Resize(350,20) ;
139 char temp[100] ;
140 // sprintf ( temp, "%s", START_DIRECTORY ) ;
141 sprintf ( temp, "%s", gSystem->WorkingDirectory() ) ;
142 fDir->AddEntry(temp, 1) ;
143 fTabF1b->AddFrame( fDir, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
144
145
146 fPicCdup = fClient->GetPicture("tb_uplevel.xpm") ;
147 fCdup = new TGPictureButton(fTabF1b, fPicCdup, M_PBUTTON_CDIR_UP ) ;
148 fCdup->SetToolTipText("One Level up!") ;
149 fCdup->Associate(this) ;
150 fTabF1b->AddFrame (fCdup, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
151
152 fPicList = fClient->GetPicture("tb_list.xpm") ;
153 fListMode = new TGPictureButton(fTabF1b, fPicList, M_PBUTTON_LIST_MODE ) ;
154 fListMode->SetToolTipText("List Mode") ;
155 fListMode->Associate(this) ;
156 fListMode->SetState(kButtonUp) ;
157 fListMode->AllowStayDown(kTRUE) ;
158 fListMode->AllowStayDown(kTRUE) ; fTabF1b->AddFrame (fListMode, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
159
160 fPicDetail = fClient->GetPicture("tb_details.xpm") ;
161 fDetail = new TGPictureButton(fTabF1b, fPicDetail, M_PBUTTON_DETAIL_MODE ) ;
162 fDetail->SetToolTipText("Details Mode") ;
163 fDetail->Associate(this) ;
164 fDetail->SetState(kButtonEngaged) ;
165 fDetail->AllowStayDown(kTRUE) ;
166 fTabF1b->AddFrame (fDetail, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
167
168 // the items in the third subframe
169
170 fFileView = new TGListView(fTabF1c, 540, 380 ) ;
171 fFileCont = new TGFileContainer(fFileView->GetViewPort(), 100, 100,
172 kVerticalFrame, fgWhitePixel) ;
173
174 fFileCont->Associate(this) ;
175 fFileView->GetViewPort()->SetBackgroundColor(fgWhitePixel) ;
176 fFileView->SetContainer(fFileCont) ;
177 fFileCont->SetFilter("*") ;
178 // fFileCont->ChangeDirectory(START_DIRECTORY) ;
179 fFileCont->ChangeDirectory(gSystem->WorkingDirectory()) ;
180 fFileView->SetViewMode(kLVDetails);
181 fFileCont->Sort(kSortByName) ;
182
183 fTabF1c->AddFrame(fFileView, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) ) ;
184
185 tf->AddFrame(fTabF1, fLayTab) ;
186
187 fFrameLow->AddFrame ( fTab, new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) );
188
189 AddFrame(fFrameLow, new TGLayoutHints (kLHintsExpandX|kLHintsExpandY) ) ;
190
191 //
192 // Map the window, set up the layout, etc.
193 //
194
195 SetWMSizeHints(200, 250, 1000, 1000, 10, 10 ) ; // set the smallest and biggest size of the Main frame
196
197 MapSubwindows();
198
199 Layout();
200
201 SetWindowName("Prototyp");
202 SetIconName("Prototyp");
203
204 MapWindow();
205
206}
207
208
209// ======================================================================
210// ======================================================================
211
212MGPrototyp::~MGPrototyp()
213{
214 //delete fPicCdup, fPicList, fPicDetail;
215 delete fLayTab;
216 delete fLayMenuBar;
217 delete fLayMenuItem;
218 delete fFileView;
219 delete fFileCont;
220 delete fCdup;
221 delete fListMode;
222 delete fDetail;
223 delete fDir ;
224 delete fLabDir ;
225
226 delete fButFileReset ;
227 delete fTxtFileName ;
228 delete fLabFileName ;
229
230 delete fTabF1c;
231 delete fTabF1b;
232 delete fTabF1a;
233 delete fTabF1;
234 delete fButAction;
235 delete fTop1;
236 delete fTab;
237
238 delete fFrameTop;
239 delete fFrameLow;
240 delete fLineSep2 ;
241 delete fLineSep1 ;
242
243 delete fFileMenu;
244 delete fMenuBar;
245
246}
247
248
249// ======================================================================
250// ======================================================================
251
252void MGPrototyp::CloseWindow()
253{
254 // Got close message for this MainFrame. Calls parent CloseWindow()
255 // (which destroys the window) and terminate the application.
256 // The close message is generated by the window manager when its close
257 // window menu item is selected.
258
259 delete this ;
260}
261
262
263// ======================================================================
264// ======================================================================
265
266Bool_t MGPrototyp::InputFileSelected()
267{
268 // Checks if there is a selected input root file
269
270 if ( strcmp ( fInputFile, "\n") == 0 )
271 {
272 return ( kFALSE ) ;
273 }
274
275 return (kTRUE) ;
276}
277
278
279// ======================================================================
280// ======================================================================
281
282Bool_t MGPrototyp::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
283{
284 // Process events generated by the buttons in the frame.
285
286 Int_t buttons = 4, retval = 0 ;
287 Char_t wort[100] ;
288 Char_t extens[5] ;
289 Char_t command[110] ;
290
291 TGFileItem *item ; // to process items in the file view container
292 void *np = NULL ; // null pointer
293
294 switch (GET_MSG(msg))
295 {
296 case kC_COMMAND:
297 switch (GET_SUBMSG(msg))
298 {
299 case kCM_BUTTON:
300
301 switch (parm1)
302 {
303
304 case M_BUTTON_ACTION:
305
306 if ( InputFileSelected() == kFALSE ) { // it is not selected
307
308 new TGMsgBox(fClient->GetRoot(), this, "ERROR!",
309 "No Input (root) File selected!", kMBIconExclamation, buttons, &retval);
310 break ;
311 }
312
313 new TGMsgBox(fClient->GetRoot(), this, "INFORMATION!",
314 "Put Intelligence here!!!", kMBIconExclamation, buttons, &retval);
315
316 break ;
317
318
319 case M_FILERESET:
320
321 sprintf ( fInputFile, "\n" ) ;
322 fTxtFileName->SetText( fInputFile ) ;
323
324 break;
325 case M_PBUTTON_CDIR_UP :
326
327 // goto the parent directory
328
329 gSystem->ChangeDirectory("..") ;
330 fDir->RemoveEntry(1) ;
331 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
332 fDir->AddEntry(wort,1) ;
333 fDir->MapSubwindows() ;
334 fDir->Layout() ;
335 fFileCont->ChangeDirectory( wort ) ;
336 fFileCont->DisplayDirectory() ;
337
338 break ;
339
340 case M_PBUTTON_LIST_MODE:
341 fFileView->SetViewMode(kLVList) ;
342 fDetail->SetState(kButtonUp) ;
343
344 break ;
345
346 case M_PBUTTON_DETAIL_MODE:
347 fFileView->SetViewMode(kLVDetails) ;
348 fListMode->SetState(kButtonUp) ;
349
350 break ;
351
352 default:
353 break ;
354 }
355
356 case kCM_MENU:
357
358 switch (parm1) {
359 case M_FILE_CLOSE:
360 CloseWindow() ;
361
362 break;
363 }
364 break ;
365
366 default:
367 break ;
368
369 }
370
371 case kC_CONTAINER:
372 switch (GET_SUBMSG(msg)) {
373
374 // case kCT_ITEMCLICK:
375 // printf ("itemclick\n");
376 // break;
377
378
379 case kCT_ITEMDBLCLICK:
380 //
381 // process the double click in the file view container
382 //
383
384 if ( parm1 == kButton1) {
385 if ( fFileCont->NumSelected() == 1 ) {
386 //
387 // one file selected
388 //
389 item = (TGFileItem *) fFileCont->GetNextSelected(&np) ;
390
391 if ( S_ISDIR(item->GetType()) ) // file is directory
392 {
393 // goto directory
394
395 sprintf (wort, "%s", item->GetItemName()->GetString()) ;
396 fFileCont->ChangeDirectory ( wort ) ;
397 gSystem->ChangeDirectory( wort ) ;
398
399 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
400 fDir->RemoveEntry(1) ;
401 fDir->AddEntry( wort, 1 ) ;
402 fDir->MapSubwindows() ;
403 fDir->Layout() ;
404 }
405 else // file is no directory, is a file
406 {
407 sprintf (wort, "%s", item->GetItemName()->GetString() ) ;
408
409 // determine the file type by extensions
410
411 for (Int_t i = 0 ; i<5; i++)
412 extens[i] = '\0' ;
413
414 for ( Int_t i=0; wort[i] != '\0'; i++) {
415 if ( wort[i] == '.') {
416 strncpy (extens, &wort[i+1], 4 ) ;
417 break ;
418 }
419 }
420
421 if ( ! strcmp(extens, "ps") ) { // postscript file
422 sprintf ( command, "gv %s/%s &",
423 gSystem->WorkingDirectory(),
424 wort ) ;
425 gSystem->Exec(command) ;
426 break ;
427 }
428 else if ( ! strcmp(extens, "root") ) { // root file
429 sprintf ( fInputFile, "%s/%s" , gSystem->WorkingDirectory(), wort ) ;
430 fTxtFileName->SetText( fInputFile ) ;
431
432 break ;
433 }
434
435 }
436 }
437 }
438 break;
439
440 default:
441 break ;
442 }
443
444
445
446 default:
447 break;
448 }
449 return kTRUE;
450}
Note: See TracBrowser for help on using the repository browser.