source: trunk/MagicSoft/Mars/mmain/MBrowser.cc@ 972

Last change on this file since 972 was 952, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 13.2 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
19! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26#include "MBrowser.h"
27
28#include <TSystem.h> // gSystem
29
30#include <TGTab.h> // TGTab
31#include <TGMenu.h> // TGPopupMenu
32#include <TGButton.h> // TGTextButton
33#include <TGMsgBox.h> // TGMsgBox
34#include <TGListBox.h> // TGListBox
35#include <TGComboBox.h> // TGComboBox
36#include <TGFSContainer.h> // TGFileContainer
37
38#include <TG3DLine.h> // TGHorizontal3DLine
39 // use TGSplitter.h for root<3.00
40
41#include <sys/stat.h> // S_ISDIR
42
43#include <iostream.h>
44
45ClassImp(MBrowser);
46
47enum {
48 M_FILE_CLOSE = 0x1000,
49 M_PBUTTON_CDIR_UP = 0x1001,
50 M_PBUTTON_LIST_MODE = 0x1002,
51 M_PBUTTON_DETAIL_MODE = 0x1003,
52 M_DIRBOX = 0x1004
53};
54
55void MBrowser::CreateMenuBar()
56{
57 //
58 // crate the menu bar
59 //
60 TGPopupMenu *filemenu = new TGPopupMenu(gClient->GetRoot());
61 filemenu->AddEntry("Close", M_FILE_CLOSE);
62 //filemenu->Associate(this);
63 fList->Add(filemenu);
64
65 //
66 // the button messages are handled by main frame (this)
67 //
68 TGLayoutHints *laymenubar = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 2, 2, 2, 2);
69 TGLayoutHints *laymenuitem = new TGLayoutHints(kLHintsTop|kLHintsLeft, 0, 4, 0, 0);
70
71 fList->Add(laymenubar);
72 fList->Add(laymenuitem);
73
74 TGMenuBar *menubar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
75 menubar->AddPopup("File", filemenu, laymenuitem);
76 AddFrame(menubar, laymenubar);
77 fList->Add(menubar);
78}
79
80void MBrowser::CreateUpperFrame(TGCompositeFrame *frametop)
81{
82
83 //
84 // *********** Create Contents of frame top (upper part) **********
85 //
86 fTop1 = new TGHorizontalFrame(frametop, 300, 100);
87 fTop2 = new TGHorizontalFrame(frametop, 300, 100);
88 fTop3 = new TGHorizontalFrame(frametop, 300, 100);
89
90 frametop->AddFrame(fTop1);
91 frametop->AddFrame(fTop2);
92 frametop->AddFrame(fTop3);
93
94 fList->Add(fTop1);
95 fList->Add(fTop2);
96 fList->Add(fTop3);
97}
98
99void MBrowser::CreateDirListMenu(TGCompositeFrame *frame)
100{
101 //
102 // Create Dir-Listbox and buttons in first frame
103 //
104 fDir = new TGComboBox(frame, M_DIRBOX);
105 fDir->Resize(350, 20);
106
107 //
108 // Get the three picturs from the system (must be deleted by FreePicture)
109 //
110 fPic1 = fClient->GetPicture("tb_uplevel.xpm");
111 fPic2 = fClient->GetPicture("tb_list.xpm");
112 fPic3 = fClient->GetPicture("tb_details.xpm");
113
114 //
115 // Create the corresponding picture buttons
116 //
117 fCdup = new TGPictureButton(frame, fPic1, M_PBUTTON_CDIR_UP);
118 fListMode = new TGPictureButton(frame, fPic2, M_PBUTTON_LIST_MODE);
119 fDetail = new TGPictureButton(frame, fPic3, M_PBUTTON_DETAIL_MODE);
120
121 //
122 // setup the buttons
123 //
124 fCdup ->SetToolTipText("One Level up!");
125 fListMode->SetToolTipText("List Mode");
126 fDetail ->SetToolTipText("Details Mode");
127
128 fListMode->SetState(kButtonUp);
129 fDetail ->SetState(kButtonEngaged);
130
131 fListMode->AllowStayDown(kTRUE);
132 fDetail ->AllowStayDown(kTRUE);
133
134 //
135 // send messages to 'this' object
136 //
137 fDir ->Associate(this);
138 fCdup ->Associate(this);
139 fDetail ->Associate(this);
140 fListMode->Associate(this);
141
142 //
143 // Add to list for 'automatic' deletion
144 //
145 fList->Add(fDir);
146 fList->Add(fCdup);
147 fList->Add(fListMode);
148 fList->Add(fDetail);
149
150 //
151 // Layout Dir-Listbox and buttons in one row (frame)
152 //
153 // - layout:
154 // alignment: top, left
155 // padding: 5, 5, 5, 5
156 //
157 TGLayoutHints *layout = new TGLayoutHints(kLHintsNormal, 5, 5, 5, 5);
158 fList->Add(layout);
159
160 frame->AddFrame(fDir, layout);
161 frame->AddFrame(fCdup, layout);
162 frame->AddFrame(fListMode, layout);
163 frame->AddFrame(fDetail, layout);
164}
165
166void MBrowser::CreateDirListBox(TGCompositeFrame *frame)
167{
168 //
169 // Create file viewer (browser)
170 //
171 fFileView = new TGListView(frame, 540, 380);
172 fList->Add(fFileView);
173
174 TGViewPort *port = fFileView->GetViewPort();
175 port->SetBackgroundColor(fgWhitePixel);
176
177 fFileCont = new TGFileContainer(port, 100, 100, kVerticalFrame, fgWhitePixel);
178 fList->Add(fFileCont);
179
180 fFileView->SetContainer(fFileCont);
181 fFileView->SetViewMode(kLVDetails);
182
183 fFileCont->SetFilter("*");
184 fFileCont->Associate(this);
185 fFileCont->Sort(kSortByName);
186
187 TGLayoutHints *layview = new TGLayoutHints(kLHintsTop|kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
188 fList->Add(layview);
189
190 frame->AddFrame(fFileView, layview);
191}
192
193void MBrowser::CreateTab1()
194{
195 TGCompositeFrame *frame = CreateNewTab("Input File");
196
197 //
198 // Create three frames for the first tab
199 //
200 TGCompositeFrame *tab1 = new TGCompositeFrame(frame, 100, 100, kHorizontalFrame);
201 TGCompositeFrame *tab1a = new TGCompositeFrame(frame, 100, 100, kHorizontalFrame);
202 TGCompositeFrame *tab1b = new TGCompositeFrame(frame, 100, 100, kVerticalFrame);
203
204 TGLayoutHints *laytab1b = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
205 TGLayoutHints *laytab1 = new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5);
206
207 fList->Add(laytab1b);
208 fList->Add(laytab1);
209
210 frame->AddFrame(tab1a);
211 frame->AddFrame(tab1b, laytab1b);
212 frame->AddFrame(tab1, laytab1);
213
214 fList->Add(tab1);
215 fList->Add(tab1a);
216 fList->Add(tab1b);
217
218 CreateDirListMenu(tab1a);
219 CreateDirListBox(tab1b);
220}
221
222TGCompositeFrame *MBrowser::CreateNewTab(const char *name)
223{
224 return fTabs->AddTab(name);
225}
226
227void MBrowser::CreateLowerFrame(TGCompositeFrame *framelow)
228{
229 //
230 // *********** Create Contents of frame low (downer part) **********
231 //
232
233 //
234 // ----- Create Object holding the Tabs -----
235 //
236 fTabs = new TGTab(framelow, 400, 400);
237 fList->Add(fTabs);
238
239 TGLayoutHints *laytabs = new TGLayoutHints(kLHintsBottom|kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
240 fList->Add(laytabs);
241
242 framelow->AddFrame(fTabs, laytabs);
243
244 //
245 // --- Create the first tab of the tabs ---
246 //
247 CreateTab1();
248}
249
250MBrowser::MBrowser(const TGWindow *main, const TGWindow *p,
251 const UInt_t w, const UInt_t h)
252: TGTransientFrame(p?p:gClient->GetRoot(),
253 main?main:gClient->GetRoot(), w, h)
254{
255 fInputFile[0] = '\0';
256
257 fList = new TList;
258 fList->SetOwner();
259
260 CreateMenuBar();
261
262 TGLayoutHints *laylinesep = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
263 fList->Add(laylinesep);
264
265 TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
266 fList->Add(linesep);
267 AddFrame(linesep, laylinesep);
268
269
270 //
271 // ---- Create the top window with a lot of buttons ----
272 //
273 TGCompositeFrame *frametop = new TGCompositeFrame(this, 300, 100, kVerticalFrame);
274 fList->Add(frametop);
275 AddFrame(frametop);
276
277 linesep = new TGHorizontal3DLine(this);
278 fList->Add(linesep);
279 AddFrame(linesep, laylinesep);
280
281 //
282 // ---- Create the low window with a tabs in it ----
283 //
284 TGLayoutHints *layframelow = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
285 fList->Add(layframelow);
286
287 TGCompositeFrame *framelow = new TGCompositeFrame(this, 300, 100, kHorizontalFrame);
288 fList->Add(framelow);
289
290 AddFrame(framelow, layframelow);
291
292 CreateUpperFrame(frametop);
293 CreateLowerFrame(framelow);
294
295 //
296 // Map the window, set up the layout, etc.
297 //
298 ChangeDir();
299 SetWMSizeHints(400, 350, 1000, 1000, 10, 10); // set the smallest and biggest size of the Main frame
300}
301
302
303// ======================================================================
304// ======================================================================
305
306MBrowser::~MBrowser()
307{
308 fClient->FreePicture(fPic1);
309 fClient->FreePicture(fPic2);
310 fClient->FreePicture(fPic3);
311
312 delete fList;
313}
314
315// ======================================================================
316// ======================================================================
317
318void MBrowser::CloseWindow()
319{
320 // Got close message for this MainFrame. Calls parent CloseWindow()
321 // (which destroys the window) and terminate the application.
322 // The close message is generated by the window manager when its close
323 // window menu item is selected.
324
325 delete this;
326}
327
328
329// ======================================================================
330// ======================================================================
331
332Bool_t MBrowser::InputFileSelected()
333{
334 //
335 // Checks if there is a selected input root file
336 //
337 return fInputFile[0]!='\0';
338}
339
340
341// ======================================================================
342// ======================================================================
343
344void MBrowser::DisplError(const char *txt)
345{
346 Int_t retval;
347 new TGMsgBox(fClient->GetRoot(), this, "Error!", txt,
348 kMBIconExclamation, 4, &retval);
349}
350
351void MBrowser::DisplWarning(const char *txt)
352{
353 Int_t retval;
354 new TGMsgBox(fClient->GetRoot(), this, "Warning!", txt,
355 kMBIconExclamation, 4, &retval);
356}
357
358void MBrowser::DisplInfo(const char *txt)
359{
360 Int_t retval;
361 new TGMsgBox(fClient->GetRoot(), this, "Information!", txt,
362 kMBIconExclamation, 4, &retval);
363}
364
365void MBrowser::ChangeDir(const char *txt)
366{
367 fFileCont->ChangeDirectory(txt?txt:gSystem->WorkingDirectory());
368
369 const char *dir = fFileCont->GetDirectory();
370 // const UInt_t num = fDir->GetSelected()+1;
371
372 //
373 // FIXME: This is a big workaround!
374 //
375 fDir->InsertEntry(dir, -1/*num*/, -1);
376 fDir->Select(-1/*num*/);
377}
378
379Bool_t MBrowser::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
380{
381 // Process events generated by the buttons in the frame.
382
383 switch (GET_MSG(msg))
384 {
385 case kC_COMMAND:
386 switch (GET_SUBMSG(msg))
387 {
388 case kCM_BUTTON:
389
390 switch (parm1)
391 {
392 case M_PBUTTON_CDIR_UP :
393 //
394 // goto the parent directory
395 //
396 ChangeDir("..");
397 return kTRUE;
398
399 case M_PBUTTON_LIST_MODE:
400 fFileView->SetViewMode(kLVList);
401 fDetail->SetState(kButtonUp) ;
402 return kTRUE;
403
404 case M_PBUTTON_DETAIL_MODE:
405 fFileView->SetViewMode(kLVDetails);
406 fListMode->SetState(kButtonUp);
407 return kTRUE;
408 }
409 return kTRUE;
410
411 case kCM_COMBOBOX:
412 //
413 // FIXME: Don't add the new entry to the list!
414 // But to do this we need the number of entries in the list.
415 //
416 if (parm1 == M_DIRBOX)
417 ChangeDir(((TGTextLBEntry*)fDir->GetSelectedEntry())->GetText()->GetString());
418 return kTRUE;
419
420 case kCM_MENU:
421 if (parm1==M_FILE_CLOSE)
422 CloseWindow();
423 return kTRUE;
424 }
425 return kTRUE;
426
427 case kC_CONTAINER:
428 switch (GET_SUBMSG(msg))
429 {
430
431 // case kCT_ITEMCLICK:
432 // printf ("itemclick\n");
433 // break;
434
435 case kCT_ITEMDBLCLICK:
436 //
437 // process the double click in the file view container
438 //
439
440 if (parm1 != kButton1)
441 return kTRUE;
442
443 if (fFileCont->NumSelected() != 1 )
444 return kTRUE;
445
446 //
447 // one file selected
448 //
449 void *dummy = NULL;
450 const TGFileItem *item = (TGFileItem *)fFileCont->GetNextSelected(&dummy);
451
452 const char *str = item->GetItemName()->GetString();
453
454 //
455 // if the user choose a directory
456 // change to this directory
457 //
458 if (S_ISDIR(item->GetType()))
459 {
460 ChangeDir(str);
461 return kTRUE;
462 }
463
464 //
465 // file is no directory, is a file
466 // determine the file type by extensions
467 //
468 const char *extension=strrchr(str, '.');
469
470 if (!extension)
471 return kTRUE;
472
473 const char *dir = fFileCont->GetDirectory();
474
475 if (!strcasecmp(extension, ".ps")) // postscript file
476 {
477 char *cmd = new char[strlen(dir)+strlen(str)+40];
478 sprintf(cmd, "gv %s/%s &", dir, str);
479 gSystem->Exec(cmd);
480 delete cmd;
481 return kTRUE;
482 }
483
484 if (!strcasecmp(extension, ".root"))
485 {
486 sprintf(fInputFile, "%s/%s", dir, str);
487 return kTRUE;
488 }
489 return kTRUE;
490 }
491 }
492 return kTRUE;
493}
Note: See TracBrowser for help on using the repository browser.