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 |
|
---|
45 | ClassImp(MBrowser);
|
---|
46 |
|
---|
47 | enum {
|
---|
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 |
|
---|
55 | void 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 |
|
---|
80 | void 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 |
|
---|
99 | void 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 |
|
---|
166 | void 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 |
|
---|
193 | void 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 |
|
---|
222 | TGCompositeFrame *MBrowser::CreateNewTab(const char *name)
|
---|
223 | {
|
---|
224 | return fTabs->AddTab(name);
|
---|
225 | }
|
---|
226 |
|
---|
227 | void 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 |
|
---|
250 | MBrowser::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->SetOwner();
|
---|
258 |
|
---|
259 | CreateMenuBar();
|
---|
260 |
|
---|
261 | TGLayoutHints *laylinesep = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
|
---|
262 | fList->Add(laylinesep);
|
---|
263 |
|
---|
264 | TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
|
---|
265 | fList->Add(linesep);
|
---|
266 | AddFrame(linesep, laylinesep);
|
---|
267 |
|
---|
268 |
|
---|
269 | //
|
---|
270 | // ---- Create the top window with a lot of buttons ----
|
---|
271 | //
|
---|
272 | TGCompositeFrame *frametop = new TGCompositeFrame(this, 300, 100, kVerticalFrame);
|
---|
273 | fList->Add(frametop);
|
---|
274 | AddFrame(frametop);
|
---|
275 |
|
---|
276 | linesep = new TGHorizontal3DLine(this);
|
---|
277 | fList->Add(linesep);
|
---|
278 | AddFrame(linesep, laylinesep);
|
---|
279 |
|
---|
280 | //
|
---|
281 | // ---- Create the low window with a tabs in it ----
|
---|
282 | //
|
---|
283 | TGLayoutHints *layframelow = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
|
---|
284 | fList->Add(layframelow);
|
---|
285 |
|
---|
286 | TGCompositeFrame *framelow = new TGCompositeFrame(this, 300, 100, kHorizontalFrame);
|
---|
287 | fList->Add(framelow);
|
---|
288 |
|
---|
289 | AddFrame(framelow, layframelow);
|
---|
290 |
|
---|
291 | CreateUpperFrame(frametop);
|
---|
292 | CreateLowerFrame(framelow);
|
---|
293 |
|
---|
294 | //
|
---|
295 | // Map the window, set up the layout, etc.
|
---|
296 | //
|
---|
297 | ChangeDir();
|
---|
298 | SetWMSizeHints(400, 350, 1000, 1000, 10, 10); // set the smallest and biggest size of the Main frame
|
---|
299 | }
|
---|
300 |
|
---|
301 |
|
---|
302 | // ======================================================================
|
---|
303 | // ======================================================================
|
---|
304 |
|
---|
305 | MBrowser::~MBrowser()
|
---|
306 | {
|
---|
307 | fClient->FreePicture(fPic1);
|
---|
308 | fClient->FreePicture(fPic2);
|
---|
309 | fClient->FreePicture(fPic3);
|
---|
310 | }
|
---|
311 |
|
---|
312 | // ======================================================================
|
---|
313 | // ======================================================================
|
---|
314 |
|
---|
315 | void MBrowser::CloseWindow()
|
---|
316 | {
|
---|
317 | // Got close message for this MainFrame. Calls parent CloseWindow()
|
---|
318 | // (which destroys the window) and terminate the application.
|
---|
319 | // The close message is generated by the window manager when its close
|
---|
320 | // window menu item is selected.
|
---|
321 |
|
---|
322 | delete this;
|
---|
323 | }
|
---|
324 |
|
---|
325 |
|
---|
326 | // ======================================================================
|
---|
327 | // ======================================================================
|
---|
328 |
|
---|
329 | Bool_t MBrowser::InputFileSelected()
|
---|
330 | {
|
---|
331 | //
|
---|
332 | // Checks if there is a selected input root file
|
---|
333 | //
|
---|
334 | return fInputFile[0]!='\0';
|
---|
335 | }
|
---|
336 |
|
---|
337 |
|
---|
338 | // ======================================================================
|
---|
339 | // ======================================================================
|
---|
340 |
|
---|
341 | void MBrowser::DisplError(const char *txt)
|
---|
342 | {
|
---|
343 | Int_t retval;
|
---|
344 | new TGMsgBox(fClient->GetRoot(), this, "Error!", txt,
|
---|
345 | kMBIconExclamation, 4, &retval);
|
---|
346 | }
|
---|
347 |
|
---|
348 | void MBrowser::DisplWarning(const char *txt)
|
---|
349 | {
|
---|
350 | Int_t retval;
|
---|
351 | new TGMsgBox(fClient->GetRoot(), this, "Warning!", txt,
|
---|
352 | kMBIconExclamation, 4, &retval);
|
---|
353 | }
|
---|
354 |
|
---|
355 | void MBrowser::DisplInfo(const char *txt)
|
---|
356 | {
|
---|
357 | Int_t retval;
|
---|
358 | new TGMsgBox(fClient->GetRoot(), this, "Information!", txt,
|
---|
359 | kMBIconExclamation, 4, &retval);
|
---|
360 | }
|
---|
361 |
|
---|
362 | void MBrowser::ChangeDir(const char *txt)
|
---|
363 | {
|
---|
364 | fFileCont->ChangeDirectory(txt?txt:gSystem->WorkingDirectory());
|
---|
365 |
|
---|
366 | const char *dir = fFileCont->GetDirectory();
|
---|
367 | // const UInt_t num = fDir->GetSelected()+1;
|
---|
368 |
|
---|
369 | //
|
---|
370 | // FIXME: This is a big workaround!
|
---|
371 | //
|
---|
372 | fDir->InsertEntry(dir, -1/*num*/, -1);
|
---|
373 | fDir->Select(-1/*num*/);
|
---|
374 | }
|
---|
375 |
|
---|
376 | Bool_t MBrowser::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
|
---|
377 | {
|
---|
378 | // Process events generated by the buttons in the frame.
|
---|
379 |
|
---|
380 | switch (GET_MSG(msg))
|
---|
381 | {
|
---|
382 | case kC_COMMAND:
|
---|
383 | switch (GET_SUBMSG(msg))
|
---|
384 | {
|
---|
385 | case kCM_BUTTON:
|
---|
386 |
|
---|
387 | switch (parm1)
|
---|
388 | {
|
---|
389 | case M_PBUTTON_CDIR_UP :
|
---|
390 | //
|
---|
391 | // goto the parent directory
|
---|
392 | //
|
---|
393 | ChangeDir("..");
|
---|
394 | return kTRUE;
|
---|
395 |
|
---|
396 | case M_PBUTTON_LIST_MODE:
|
---|
397 | fFileView->SetViewMode(kLVList);
|
---|
398 | fDetail->SetState(kButtonUp) ;
|
---|
399 | return kTRUE;
|
---|
400 |
|
---|
401 | case M_PBUTTON_DETAIL_MODE:
|
---|
402 | fFileView->SetViewMode(kLVDetails);
|
---|
403 | fListMode->SetState(kButtonUp);
|
---|
404 | return kTRUE;
|
---|
405 | }
|
---|
406 | return kTRUE;
|
---|
407 |
|
---|
408 | case kCM_COMBOBOX:
|
---|
409 | //
|
---|
410 | // FIXME: Don't add the new entry to the list!
|
---|
411 | // But to do this we need the number of entries in the list.
|
---|
412 | //
|
---|
413 | if (parm1 == M_DIRBOX)
|
---|
414 | ChangeDir(((TGTextLBEntry*)fDir->GetSelectedEntry())->GetText()->GetString());
|
---|
415 | return kTRUE;
|
---|
416 |
|
---|
417 | case kCM_MENU:
|
---|
418 | if (parm1==M_FILE_CLOSE)
|
---|
419 | CloseWindow();
|
---|
420 | return kTRUE;
|
---|
421 | }
|
---|
422 | return kTRUE;
|
---|
423 |
|
---|
424 | case kC_CONTAINER:
|
---|
425 | switch (GET_SUBMSG(msg))
|
---|
426 | {
|
---|
427 |
|
---|
428 | // case kCT_ITEMCLICK:
|
---|
429 | // printf ("itemclick\n");
|
---|
430 | // break;
|
---|
431 |
|
---|
432 | case kCT_ITEMDBLCLICK:
|
---|
433 | //
|
---|
434 | // process the double click in the file view container
|
---|
435 | //
|
---|
436 |
|
---|
437 | if (parm1 != kButton1)
|
---|
438 | return kTRUE;
|
---|
439 |
|
---|
440 | if (fFileCont->NumSelected() != 1 )
|
---|
441 | return kTRUE;
|
---|
442 |
|
---|
443 | //
|
---|
444 | // one file selected
|
---|
445 | //
|
---|
446 | void *dummy = NULL;
|
---|
447 | const TGFileItem *item = (TGFileItem *)fFileCont->GetNextSelected(&dummy);
|
---|
448 |
|
---|
449 | const char *str = item->GetItemName()->GetString();
|
---|
450 |
|
---|
451 | //
|
---|
452 | // if the user choose a directory
|
---|
453 | // change to this directory
|
---|
454 | //
|
---|
455 | if (S_ISDIR(item->GetType()))
|
---|
456 | {
|
---|
457 | ChangeDir(str);
|
---|
458 | return kTRUE;
|
---|
459 | }
|
---|
460 |
|
---|
461 | //
|
---|
462 | // file is no directory, is a file
|
---|
463 | // determine the file type by extensions
|
---|
464 | //
|
---|
465 | const char *extension=strrchr(str, '.');
|
---|
466 |
|
---|
467 | if (!extension)
|
---|
468 | return kTRUE;
|
---|
469 |
|
---|
470 | const char *dir = fFileCont->GetDirectory();
|
---|
471 |
|
---|
472 | if (!strcasecmp(extension, ".ps")) // postscript file
|
---|
473 | {
|
---|
474 | char *cmd = new char[strlen(dir)+strlen(str)+40];
|
---|
475 | sprintf(cmd, "gv %s/%s &", dir, str);
|
---|
476 | gSystem->Exec(cmd);
|
---|
477 | delete cmd;
|
---|
478 | return kTRUE;
|
---|
479 | }
|
---|
480 |
|
---|
481 | if (!strcasecmp(extension, ".root"))
|
---|
482 | {
|
---|
483 | sprintf(fInputFile, "%s/%s", dir, str);
|
---|
484 | return kTRUE;
|
---|
485 | }
|
---|
486 | return kTRUE;
|
---|
487 | }
|
---|
488 | }
|
---|
489 | return kTRUE;
|
---|
490 | }
|
---|