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 | fPic1 = fClient->GetPicture("tb_uplevel.xpm");
|
---|
108 | fPic2 = fClient->GetPicture("tb_list.xpm");
|
---|
109 | fPic3 = fClient->GetPicture("tb_details.xpm");
|
---|
110 |
|
---|
111 | fCdup = new TGPictureButton(frame, fPic1, M_PBUTTON_CDIR_UP);
|
---|
112 | fListMode = new TGPictureButton(frame, fPic2, M_PBUTTON_LIST_MODE);
|
---|
113 | fDetail = new TGPictureButton(frame, fPic3, M_PBUTTON_DETAIL_MODE);
|
---|
114 |
|
---|
115 | fCdup ->SetToolTipText("One Level up!");
|
---|
116 | fListMode->SetToolTipText("List Mode");
|
---|
117 | fDetail ->SetToolTipText("Details Mode");
|
---|
118 |
|
---|
119 | fListMode->SetState(kButtonUp);
|
---|
120 | fDetail ->SetState(kButtonEngaged);
|
---|
121 |
|
---|
122 | fListMode->AllowStayDown(kTRUE);
|
---|
123 | fDetail ->AllowStayDown(kTRUE);
|
---|
124 |
|
---|
125 | fDir ->Associate(this);
|
---|
126 | fCdup ->Associate(this);
|
---|
127 | fDetail ->Associate(this);
|
---|
128 | fListMode->Associate(this);
|
---|
129 |
|
---|
130 | fList->Add(fDir);
|
---|
131 | fList->Add(fCdup);
|
---|
132 | fList->Add(fListMode);
|
---|
133 | fList->Add(fDetail);
|
---|
134 |
|
---|
135 | //
|
---|
136 | // Layout Dir-Listbox and buttons
|
---|
137 | //
|
---|
138 | TGLayoutHints *laydir = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 5, 5, 5, 5);
|
---|
139 | TGLayoutHints *laybut = new TGLayoutHints(kLHintsLeft|kLHintsTop, 5, 5, 5, 5);
|
---|
140 |
|
---|
141 | fList->Add(laydir);
|
---|
142 | fList->Add(laybut);
|
---|
143 |
|
---|
144 | frame->AddFrame(fDir, laydir);
|
---|
145 | frame->AddFrame(fCdup, laybut);
|
---|
146 | frame->AddFrame(fListMode, laybut);
|
---|
147 | frame->AddFrame(fDetail, laybut);
|
---|
148 | }
|
---|
149 |
|
---|
150 | void MBrowser::CreateDirListBox(TGCompositeFrame *frame)
|
---|
151 | {
|
---|
152 | //
|
---|
153 | // Create file viewer (browser)
|
---|
154 | //
|
---|
155 | fFileView = new TGListView(frame, 540, 380);
|
---|
156 | fList->Add(fFileView);
|
---|
157 |
|
---|
158 | TGViewPort *port = fFileView->GetViewPort();
|
---|
159 | port->SetBackgroundColor(fgWhitePixel);
|
---|
160 |
|
---|
161 | fFileCont = new TGFileContainer(port, 100, 100, kVerticalFrame, fgWhitePixel);
|
---|
162 | fList->Add(fFileCont);
|
---|
163 |
|
---|
164 | fFileView->SetContainer(fFileCont);
|
---|
165 | fFileView->SetViewMode(kLVDetails);
|
---|
166 |
|
---|
167 | fFileCont->SetFilter("*");
|
---|
168 | fFileCont->Associate(this);
|
---|
169 | fFileCont->Sort(kSortByName);
|
---|
170 |
|
---|
171 | TGLayoutHints *layview = new TGLayoutHints(kLHintsTop|kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
|
---|
172 | fList->Add(layview);
|
---|
173 |
|
---|
174 | frame->AddFrame(fFileView, layview);
|
---|
175 | }
|
---|
176 |
|
---|
177 | void MBrowser::CreateTab1(TGCompositeFrame *frame)
|
---|
178 | {
|
---|
179 | //
|
---|
180 | // Create three frames for the first tab
|
---|
181 | //
|
---|
182 | TGCompositeFrame *tab1 = new TGCompositeFrame(frame, 100, 100, kHorizontalFrame);
|
---|
183 | TGCompositeFrame *tab1a = new TGCompositeFrame(frame, 100, 100, kHorizontalFrame);
|
---|
184 | TGCompositeFrame *tab1b = new TGCompositeFrame(frame, 100, 100, kVerticalFrame);
|
---|
185 |
|
---|
186 | TGLayoutHints *laytab1b = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
|
---|
187 | TGLayoutHints *laytab1 = new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5);
|
---|
188 |
|
---|
189 | fList->Add(laytab1b);
|
---|
190 | fList->Add(laytab1);
|
---|
191 |
|
---|
192 | frame->AddFrame(tab1a);
|
---|
193 | frame->AddFrame(tab1b, laytab1b);
|
---|
194 | frame->AddFrame(tab1, laytab1);
|
---|
195 |
|
---|
196 | fList->Add(tab1);
|
---|
197 | fList->Add(tab1a);
|
---|
198 | fList->Add(tab1b);
|
---|
199 |
|
---|
200 | CreateDirListMenu(tab1a);
|
---|
201 | CreateDirListBox(tab1b);
|
---|
202 | }
|
---|
203 |
|
---|
204 | void MBrowser::CreateLowerFrame(TGCompositeFrame *framelow)
|
---|
205 | {
|
---|
206 | //
|
---|
207 | // *********** Create Contents of frame low (downer part) **********
|
---|
208 | //
|
---|
209 |
|
---|
210 | //
|
---|
211 | // ----- Create Object holding the Tabs -----
|
---|
212 | //
|
---|
213 | TGTab *tabs = new TGTab(framelow, 400, 400);
|
---|
214 | fList->Add(tabs);
|
---|
215 |
|
---|
216 | TGLayoutHints *laytabs = new TGLayoutHints(kLHintsBottom|kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
|
---|
217 | fList->Add(laytabs);
|
---|
218 |
|
---|
219 | framelow->AddFrame(tabs, laytabs);
|
---|
220 |
|
---|
221 | //
|
---|
222 | // --- Create the first tab of the tabs ---
|
---|
223 | //
|
---|
224 | TGCompositeFrame *tf = tabs->AddTab("Input File");
|
---|
225 |
|
---|
226 | CreateTab1(tf);
|
---|
227 | }
|
---|
228 |
|
---|
229 | MBrowser::MBrowser(const TGWindow *main, const TGWindow *p,
|
---|
230 | const UInt_t w, const UInt_t h)
|
---|
231 | : TGTransientFrame(p?p:gClient->GetRoot(),
|
---|
232 | main?main:gClient->GetRoot(), w, h)
|
---|
233 | {
|
---|
234 | fInputFile[0] = '\0';
|
---|
235 |
|
---|
236 | fList = new TList;
|
---|
237 | fList->SetOwner();
|
---|
238 |
|
---|
239 | CreateMenuBar();
|
---|
240 |
|
---|
241 | TGLayoutHints *laylinesep = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
|
---|
242 | fList->Add(laylinesep);
|
---|
243 |
|
---|
244 | TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
|
---|
245 | fList->Add(linesep);
|
---|
246 | AddFrame(linesep, laylinesep);
|
---|
247 |
|
---|
248 |
|
---|
249 | //
|
---|
250 | // ---- Create the top window with a lot of buttons ----
|
---|
251 | //
|
---|
252 | TGCompositeFrame *frametop = new TGCompositeFrame(this, 300, 100, kVerticalFrame);
|
---|
253 | fList->Add(frametop);
|
---|
254 | AddFrame(frametop);
|
---|
255 |
|
---|
256 | linesep = new TGHorizontal3DLine(this);
|
---|
257 | fList->Add(linesep);
|
---|
258 | AddFrame(linesep, laylinesep);
|
---|
259 |
|
---|
260 | //
|
---|
261 | // ---- Create the low window with a tabs in it ----
|
---|
262 | //
|
---|
263 | TGLayoutHints *layframelow = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
|
---|
264 | fList->Add(layframelow);
|
---|
265 |
|
---|
266 | TGCompositeFrame *framelow = new TGCompositeFrame(this, 300, 100, kHorizontalFrame);
|
---|
267 | fList->Add(framelow);
|
---|
268 |
|
---|
269 | AddFrame(framelow, layframelow);
|
---|
270 |
|
---|
271 | CreateUpperFrame(frametop);
|
---|
272 | CreateLowerFrame(framelow);
|
---|
273 |
|
---|
274 | //
|
---|
275 | // Map the window, set up the layout, etc.
|
---|
276 | //
|
---|
277 | ChangeDir();
|
---|
278 | SetWMSizeHints(400, 350, 1000, 1000, 10, 10); // set the smallest and biggest size of the Main frame
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|
282 | // ======================================================================
|
---|
283 | // ======================================================================
|
---|
284 |
|
---|
285 | MBrowser::~MBrowser()
|
---|
286 | {
|
---|
287 | fClient->FreePicture(fPic1);
|
---|
288 | fClient->FreePicture(fPic2);
|
---|
289 | fClient->FreePicture(fPic3);
|
---|
290 |
|
---|
291 | delete fList;
|
---|
292 | }
|
---|
293 |
|
---|
294 | // ======================================================================
|
---|
295 | // ======================================================================
|
---|
296 |
|
---|
297 | void MBrowser::CloseWindow()
|
---|
298 | {
|
---|
299 | // Got close message for this MainFrame. Calls parent CloseWindow()
|
---|
300 | // (which destroys the window) and terminate the application.
|
---|
301 | // The close message is generated by the window manager when its close
|
---|
302 | // window menu item is selected.
|
---|
303 |
|
---|
304 | delete this;
|
---|
305 | }
|
---|
306 |
|
---|
307 |
|
---|
308 | // ======================================================================
|
---|
309 | // ======================================================================
|
---|
310 |
|
---|
311 | Bool_t MBrowser::InputFileSelected()
|
---|
312 | {
|
---|
313 | //
|
---|
314 | // Checks if there is a selected input root file
|
---|
315 | //
|
---|
316 | return fInputFile[0]!='\0';
|
---|
317 | }
|
---|
318 |
|
---|
319 |
|
---|
320 | // ======================================================================
|
---|
321 | // ======================================================================
|
---|
322 |
|
---|
323 | void MBrowser::DisplError(const char *txt)
|
---|
324 | {
|
---|
325 | Int_t retval;
|
---|
326 | new TGMsgBox(fClient->GetRoot(), this, "Error!", txt,
|
---|
327 | kMBIconExclamation, 4, &retval);
|
---|
328 | }
|
---|
329 |
|
---|
330 | void MBrowser::DisplWarning(const char *txt)
|
---|
331 | {
|
---|
332 | Int_t retval;
|
---|
333 | new TGMsgBox(fClient->GetRoot(), this, "Warning!", txt,
|
---|
334 | kMBIconExclamation, 4, &retval);
|
---|
335 | }
|
---|
336 |
|
---|
337 | void MBrowser::DisplInfo(const char *txt)
|
---|
338 | {
|
---|
339 | Int_t retval;
|
---|
340 | new TGMsgBox(fClient->GetRoot(), this, "Information!", txt,
|
---|
341 | kMBIconExclamation, 4, &retval);
|
---|
342 | }
|
---|
343 |
|
---|
344 | void MBrowser::ChangeDir(const char *txt)
|
---|
345 | {
|
---|
346 | fFileCont->ChangeDirectory(txt?txt:gSystem->WorkingDirectory());
|
---|
347 |
|
---|
348 | const char *dir = fFileCont->GetDirectory();
|
---|
349 | // const UInt_t num = fDir->GetSelected()+1;
|
---|
350 |
|
---|
351 | //
|
---|
352 | // FIXME: This is a big workaround!
|
---|
353 | //
|
---|
354 | fDir->InsertEntry(dir, -1/*num*/, -1);
|
---|
355 | fDir->Select(-1/*num*/);
|
---|
356 | }
|
---|
357 |
|
---|
358 | Bool_t MBrowser::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
|
---|
359 | {
|
---|
360 | // Process events generated by the buttons in the frame.
|
---|
361 |
|
---|
362 | switch (GET_MSG(msg))
|
---|
363 | {
|
---|
364 | case kC_COMMAND:
|
---|
365 | switch (GET_SUBMSG(msg))
|
---|
366 | {
|
---|
367 | case kCM_BUTTON:
|
---|
368 |
|
---|
369 | switch (parm1)
|
---|
370 | {
|
---|
371 | case M_PBUTTON_CDIR_UP :
|
---|
372 | //
|
---|
373 | // goto the parent directory
|
---|
374 | //
|
---|
375 | ChangeDir("..");
|
---|
376 | return kTRUE;
|
---|
377 |
|
---|
378 | case M_PBUTTON_LIST_MODE:
|
---|
379 | fFileView->SetViewMode(kLVList);
|
---|
380 | fDetail->SetState(kButtonUp) ;
|
---|
381 | return kTRUE;
|
---|
382 |
|
---|
383 | case M_PBUTTON_DETAIL_MODE:
|
---|
384 | fFileView->SetViewMode(kLVDetails);
|
---|
385 | fListMode->SetState(kButtonUp);
|
---|
386 | return kTRUE;
|
---|
387 | }
|
---|
388 | return kTRUE;
|
---|
389 |
|
---|
390 | case kCM_COMBOBOX:
|
---|
391 | //
|
---|
392 | // FIXME: Don't add the new entry to the list!
|
---|
393 | // But to do this we need the number of entries in the list.
|
---|
394 | //
|
---|
395 | if (parm1 == M_DIRBOX)
|
---|
396 | ChangeDir(((TGTextLBEntry*)fDir->GetSelectedEntry())->GetText()->GetString());
|
---|
397 | return kTRUE;
|
---|
398 |
|
---|
399 | case kCM_MENU:
|
---|
400 | if (parm1==M_FILE_CLOSE)
|
---|
401 | CloseWindow();
|
---|
402 | return kTRUE;
|
---|
403 | }
|
---|
404 | return kTRUE;
|
---|
405 |
|
---|
406 | case kC_CONTAINER:
|
---|
407 | switch (GET_SUBMSG(msg))
|
---|
408 | {
|
---|
409 |
|
---|
410 | // case kCT_ITEMCLICK:
|
---|
411 | // printf ("itemclick\n");
|
---|
412 | // break;
|
---|
413 |
|
---|
414 | case kCT_ITEMDBLCLICK:
|
---|
415 | //
|
---|
416 | // process the double click in the file view container
|
---|
417 | //
|
---|
418 |
|
---|
419 | if (parm1 != kButton1)
|
---|
420 | return kTRUE;
|
---|
421 |
|
---|
422 | if (fFileCont->NumSelected() != 1 )
|
---|
423 | return kTRUE;
|
---|
424 |
|
---|
425 | //
|
---|
426 | // one file selected
|
---|
427 | //
|
---|
428 | void *dummy = NULL;
|
---|
429 | const TGFileItem *item = (TGFileItem *)fFileCont->GetNextSelected(&dummy);
|
---|
430 |
|
---|
431 | const char *str = item->GetItemName()->GetString();
|
---|
432 |
|
---|
433 | //
|
---|
434 | // if the user choose a directory
|
---|
435 | // change to this directory
|
---|
436 | //
|
---|
437 | if (S_ISDIR(item->GetType()))
|
---|
438 | {
|
---|
439 | ChangeDir(str);
|
---|
440 | return kTRUE;
|
---|
441 | }
|
---|
442 |
|
---|
443 | //
|
---|
444 | // file is no directory, is a file
|
---|
445 | // determine the file type by extensions
|
---|
446 | //
|
---|
447 | const char *extension=strrchr(str, '.');
|
---|
448 |
|
---|
449 | if (!extension)
|
---|
450 | return kTRUE;
|
---|
451 |
|
---|
452 | const char *dir = fFileCont->GetDirectory();
|
---|
453 |
|
---|
454 | if (!strcasecmp(extension, ".ps")) // postscript file
|
---|
455 | {
|
---|
456 | char *cmd = new char[strlen(dir)+strlen(str)+40];
|
---|
457 | sprintf(cmd, "gv %s/%s &", dir, str);
|
---|
458 | gSystem->Exec(cmd);
|
---|
459 | delete cmd;
|
---|
460 | return kTRUE;
|
---|
461 | }
|
---|
462 |
|
---|
463 | if (!strcasecmp(extension, ".root"))
|
---|
464 | {
|
---|
465 | sprintf(fInputFile, "%s/%s", dir, str);
|
---|
466 | return kTRUE;
|
---|
467 | }
|
---|
468 | return kTRUE;
|
---|
469 | }
|
---|
470 | }
|
---|
471 | return kTRUE;
|
---|
472 | }
|
---|