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