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 <sys/stat.h> // S_ISDIR
|
---|
39 |
|
---|
40 | #include <iostream.h>
|
---|
41 |
|
---|
42 | ClassImp(MBrowser);
|
---|
43 |
|
---|
44 | enum {
|
---|
45 | M_FILE_CLOSE = 0x1000,
|
---|
46 | M_PBUTTON_CDIR_UP = 0x1001,
|
---|
47 | M_PBUTTON_LIST_MODE = 0x1002,
|
---|
48 | M_PBUTTON_DETAIL_MODE = 0x1003,
|
---|
49 | M_DIRBOX = 0x1004
|
---|
50 | };
|
---|
51 |
|
---|
52 |
|
---|
53 | MBrowser::MBrowser(const TGWindow *main, const TGWindow *p,
|
---|
54 | const UInt_t w, const UInt_t h)
|
---|
55 | : TGTransientFrame(p?p:gClient->GetRoot(),
|
---|
56 | main?main:gClient->GetRoot(), w, h)
|
---|
57 | {
|
---|
58 |
|
---|
59 | //
|
---|
60 | // Main window to controll the october test
|
---|
61 | //
|
---|
62 |
|
---|
63 | // set non-gui members to starting values
|
---|
64 |
|
---|
65 | fInputFile[0] = '\0';
|
---|
66 |
|
---|
67 | //
|
---|
68 | // First create the MenuBar.
|
---|
69 | //
|
---|
70 |
|
---|
71 | // Layout objects for menue.
|
---|
72 |
|
---|
73 | fLayMenuBar = new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) ;
|
---|
74 | fLayMenuItem = new TGLayoutHints ( kLHintsTop | kLHintsLeft , 0, 4, 0, 0 ) ;
|
---|
75 |
|
---|
76 | // crate the menu bar
|
---|
77 |
|
---|
78 | fFileMenu = new TGPopupMenu ( fClient->GetRoot() ) ;
|
---|
79 | fFileMenu->AddEntry ("Close", M_FILE_CLOSE ) ;
|
---|
80 | fFileMenu->Associate(this) ;
|
---|
81 |
|
---|
82 | // the button messages are handled by main frame (this)
|
---|
83 |
|
---|
84 | fMenuBar = new TGMenuBar ( this, 1, 1, kHorizontalFrame ) ;
|
---|
85 | fMenuBar->AddPopup("File", fFileMenu, fLayMenuItem ) ;
|
---|
86 | AddFrame(fMenuBar, fLayMenuBar ) ;
|
---|
87 |
|
---|
88 | //
|
---|
89 | // Create the top window with a lot of buttons
|
---|
90 | //
|
---|
91 | fFrameTop = new TGCompositeFrame (this, 300,100, kVerticalFrame ) ;
|
---|
92 |
|
---|
93 | fTop1 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
|
---|
94 | fTop2 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
|
---|
95 | fTop3 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
|
---|
96 |
|
---|
97 | fFrameTop->AddFrame (fTop1, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
|
---|
98 | fFrameTop->AddFrame (fTop2, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
|
---|
99 | fFrameTop->AddFrame (fTop3, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
|
---|
100 | AddFrame(fFrameTop, new TGLayoutHints (kLHintsTop ) ) ;
|
---|
101 |
|
---|
102 | //
|
---|
103 | // Create the low window with a tabs in it
|
---|
104 | //
|
---|
105 | fFrameLow = new TGCompositeFrame (this, 300,100, kHorizontalFrame ) ;
|
---|
106 |
|
---|
107 | fLayTab = new TGLayoutHints ( kLHintsExpandX , 5, 5, 5, 5 ) ;
|
---|
108 |
|
---|
109 | // create the first tab
|
---|
110 |
|
---|
111 | fTab = new TGTab ( fFrameLow, 400, 400 ) ;
|
---|
112 |
|
---|
113 | TGCompositeFrame *tf = fTab->AddTab("Input File") ;
|
---|
114 |
|
---|
115 | fTabF1 = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
|
---|
116 | fTabF1a = new TGCompositeFrame(tf, 100, 100, kHorizontalFrame);
|
---|
117 | fTabF1b = new TGCompositeFrame(tf, 100, 100, kVerticalFrame);
|
---|
118 |
|
---|
119 | tf->AddFrame(fTabF1a, new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
|
---|
120 | tf->AddFrame(fTabF1b, new TGLayoutHints ( kLHintsExpandX | kLHintsExpandY , 5, 5, 5, 5 ) ) ;
|
---|
121 |
|
---|
122 | fDir = new TGComboBox(fTabF1a, M_DIRBOX);
|
---|
123 | fDir->Resize(350, 20) ;
|
---|
124 | fDir->Associate(this);
|
---|
125 |
|
---|
126 | fPicCdup = fClient->GetPicture("tb_uplevel.xpm");
|
---|
127 | fPicList = fClient->GetPicture("tb_list.xpm");
|
---|
128 | fPicDetail = fClient->GetPicture("tb_details.xpm") ;
|
---|
129 |
|
---|
130 | fCdup = new TGPictureButton(fTabF1a, fPicCdup, M_PBUTTON_CDIR_UP ) ;
|
---|
131 | fCdup->SetToolTipText("One Level up!") ;
|
---|
132 | fCdup->Associate(this) ;
|
---|
133 |
|
---|
134 | fListMode = new TGPictureButton(fTabF1a, fPicList, M_PBUTTON_LIST_MODE);
|
---|
135 | fListMode->SetToolTipText("List Mode") ;
|
---|
136 | fListMode->Associate(this);
|
---|
137 | fListMode->SetState(kButtonUp);
|
---|
138 | fListMode->AllowStayDown(kTRUE);
|
---|
139 |
|
---|
140 | fDetail = new TGPictureButton(fTabF1a, fPicDetail, M_PBUTTON_DETAIL_MODE ) ;
|
---|
141 | fDetail->SetToolTipText("Details Mode") ;
|
---|
142 | fDetail->Associate(this) ;
|
---|
143 | fDetail->SetState(kButtonEngaged) ;
|
---|
144 | fDetail->AllowStayDown(kTRUE) ;
|
---|
145 |
|
---|
146 | fTabF1a->AddFrame(fDir, new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 5, 5, 5, 5)) ;
|
---|
147 | fTabF1a->AddFrame(fCdup, new TGLayoutHints(kLHintsLeft|kLHintsTop, 5, 5, 5, 5));
|
---|
148 | fTabF1a->AddFrame(fListMode, new TGLayoutHints(kLHintsLeft|kLHintsTop, 5, 5, 5, 5));
|
---|
149 | fTabF1a->AddFrame(fDetail, new TGLayoutHints(kLHintsLeft|kLHintsTop, 5, 5, 5, 5));
|
---|
150 |
|
---|
151 | fFileView = new TGListView(fTabF1b, 540, 380 ) ;
|
---|
152 | fFileCont = new TGFileContainer(fFileView->GetViewPort(), 100, 100,
|
---|
153 | kVerticalFrame, fgWhitePixel) ;
|
---|
154 |
|
---|
155 | fFileCont->Associate(this) ;
|
---|
156 | fFileView->GetViewPort()->SetBackgroundColor(fgWhitePixel) ;
|
---|
157 | fFileView->SetContainer(fFileCont) ;
|
---|
158 | fFileCont->SetFilter("*") ;
|
---|
159 | // fFileCont->ChangeDirectory(gSystem->WorkingDirectory()) ;
|
---|
160 | fFileView->SetViewMode(kLVDetails);
|
---|
161 | fFileCont->Sort(kSortByName) ;
|
---|
162 |
|
---|
163 | fTabF1b->AddFrame(fFileView, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) ) ;
|
---|
164 |
|
---|
165 | tf->AddFrame(fTabF1, fLayTab) ;
|
---|
166 |
|
---|
167 | fFrameLow->AddFrame ( fTab, new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) );
|
---|
168 |
|
---|
169 | AddFrame(fFrameLow, new TGLayoutHints (kLHintsExpandX|kLHintsExpandY) ) ;
|
---|
170 |
|
---|
171 | ChangeDir();
|
---|
172 | //
|
---|
173 | // Map the window, set up the layout, etc.
|
---|
174 | //
|
---|
175 |
|
---|
176 | SetWMSizeHints(400, 350, 1000, 1000, 10, 10 ) ; // set the smallest and biggest size of the Main frame
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | // ======================================================================
|
---|
181 | // ======================================================================
|
---|
182 |
|
---|
183 | MBrowser::~MBrowser()
|
---|
184 | {
|
---|
185 | //delete fPicCdup, fPicList, fPicDetail;
|
---|
186 | delete fLayTab;
|
---|
187 | delete fLayMenuBar;
|
---|
188 | delete fLayMenuItem;
|
---|
189 | delete fFileView;
|
---|
190 | delete fFileCont;
|
---|
191 | delete fCdup;
|
---|
192 | delete fListMode;
|
---|
193 | delete fDetail;
|
---|
194 | delete fDir ;
|
---|
195 | delete fTabF1b;
|
---|
196 | delete fTabF1a;
|
---|
197 | delete fTabF1;
|
---|
198 | delete fTop3;
|
---|
199 | delete fTop2;
|
---|
200 | delete fTop1;
|
---|
201 | delete fTab;
|
---|
202 | delete fFrameTop;
|
---|
203 | delete fFrameLow;
|
---|
204 | delete fFileMenu;
|
---|
205 | delete fMenuBar;
|
---|
206 |
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|
210 | // ======================================================================
|
---|
211 | // ======================================================================
|
---|
212 |
|
---|
213 | void MBrowser::CloseWindow()
|
---|
214 | {
|
---|
215 | // Got close message for this MainFrame. Calls parent CloseWindow()
|
---|
216 | // (which destroys the window) and terminate the application.
|
---|
217 | // The close message is generated by the window manager when its close
|
---|
218 | // window menu item is selected.
|
---|
219 |
|
---|
220 | delete this ;
|
---|
221 | }
|
---|
222 |
|
---|
223 |
|
---|
224 | // ======================================================================
|
---|
225 | // ======================================================================
|
---|
226 |
|
---|
227 | Bool_t MBrowser::InputFileSelected()
|
---|
228 | {
|
---|
229 | //
|
---|
230 | // Checks if there is a selected input root file
|
---|
231 | //
|
---|
232 | return fInputFile[0]!='\0';
|
---|
233 | }
|
---|
234 |
|
---|
235 |
|
---|
236 | // ======================================================================
|
---|
237 | // ======================================================================
|
---|
238 |
|
---|
239 | void MBrowser::DisplError(const char *txt)
|
---|
240 | {
|
---|
241 | Int_t retval;
|
---|
242 | new TGMsgBox(fClient->GetRoot(), this, "Error!", txt,
|
---|
243 | kMBIconExclamation, 4, &retval);
|
---|
244 | }
|
---|
245 |
|
---|
246 | void MBrowser::DisplWarning(const char *txt)
|
---|
247 | {
|
---|
248 | Int_t retval;
|
---|
249 | new TGMsgBox(fClient->GetRoot(), this, "Warning!", txt,
|
---|
250 | kMBIconExclamation, 4, &retval);
|
---|
251 | }
|
---|
252 |
|
---|
253 | void MBrowser::DisplInfo(const char *txt)
|
---|
254 | {
|
---|
255 | Int_t retval;
|
---|
256 | new TGMsgBox(fClient->GetRoot(), this, "Information!", txt,
|
---|
257 | kMBIconExclamation, 4, &retval);
|
---|
258 | }
|
---|
259 |
|
---|
260 | void MBrowser::ChangeDir(const char *txt)
|
---|
261 | {
|
---|
262 | fFileCont->ChangeDirectory(txt?txt:gSystem->WorkingDirectory());
|
---|
263 |
|
---|
264 | const char *dir = fFileCont->GetDirectory();
|
---|
265 | // const UInt_t num = fDir->GetSelected()+1;
|
---|
266 |
|
---|
267 | //
|
---|
268 | // FIXME: This is a big workaround!
|
---|
269 | //
|
---|
270 | fDir->InsertEntry(dir, -1/*num*/, -1);
|
---|
271 | fDir->Select(-1/*num*/);
|
---|
272 | }
|
---|
273 |
|
---|
274 | Bool_t MBrowser::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
|
---|
275 | {
|
---|
276 | // Process events generated by the buttons in the frame.
|
---|
277 |
|
---|
278 | switch (GET_MSG(msg))
|
---|
279 | {
|
---|
280 | case kC_COMMAND:
|
---|
281 | switch (GET_SUBMSG(msg))
|
---|
282 | {
|
---|
283 | case kCM_BUTTON:
|
---|
284 |
|
---|
285 | switch (parm1)
|
---|
286 | {
|
---|
287 | case M_PBUTTON_CDIR_UP :
|
---|
288 | //
|
---|
289 | // goto the parent directory
|
---|
290 | //
|
---|
291 | ChangeDir("..");
|
---|
292 | return kTRUE;
|
---|
293 |
|
---|
294 | case M_PBUTTON_LIST_MODE:
|
---|
295 | fFileView->SetViewMode(kLVList) ;
|
---|
296 | fDetail->SetState(kButtonUp) ;
|
---|
297 | return kTRUE;
|
---|
298 |
|
---|
299 | case M_PBUTTON_DETAIL_MODE:
|
---|
300 | fFileView->SetViewMode(kLVDetails) ;
|
---|
301 | fListMode->SetState(kButtonUp) ;
|
---|
302 | return kTRUE;
|
---|
303 | }
|
---|
304 | return kTRUE;
|
---|
305 |
|
---|
306 | case kCM_COMBOBOX:
|
---|
307 | //
|
---|
308 | // FIXME: Don't add the new entry to the list!
|
---|
309 | // But to do this we need the number of entries in the list.
|
---|
310 | //
|
---|
311 | if (parm1 == M_DIRBOX)
|
---|
312 | ChangeDir(((TGTextLBEntry*)fDir->GetSelectedEntry())->GetText()->GetString());
|
---|
313 | return kTRUE;
|
---|
314 |
|
---|
315 | case kCM_MENU:
|
---|
316 | if (parm1==M_FILE_CLOSE)
|
---|
317 | CloseWindow();
|
---|
318 | return kTRUE;
|
---|
319 | }
|
---|
320 | return kTRUE;
|
---|
321 |
|
---|
322 | case kC_CONTAINER:
|
---|
323 | switch (GET_SUBMSG(msg)) {
|
---|
324 |
|
---|
325 | // case kCT_ITEMCLICK:
|
---|
326 | // printf ("itemclick\n");
|
---|
327 | // break;
|
---|
328 |
|
---|
329 | case kCT_ITEMDBLCLICK:
|
---|
330 | //
|
---|
331 | // process the double click in the file view container
|
---|
332 | //
|
---|
333 |
|
---|
334 | if (parm1 != kButton1)
|
---|
335 | return kTRUE;
|
---|
336 |
|
---|
337 | if (fFileCont->NumSelected() != 1 )
|
---|
338 | return kTRUE;
|
---|
339 |
|
---|
340 | //
|
---|
341 | // one file selected
|
---|
342 | //
|
---|
343 | void *dummy = NULL;
|
---|
344 | const TGFileItem *item = (TGFileItem *)fFileCont->GetNextSelected(&dummy);
|
---|
345 |
|
---|
346 | const char *str = item->GetItemName()->GetString();
|
---|
347 |
|
---|
348 | //
|
---|
349 | // if the user choose a directory
|
---|
350 | // change to this directory
|
---|
351 | //
|
---|
352 | if (S_ISDIR(item->GetType()))
|
---|
353 | {
|
---|
354 | ChangeDir(str);
|
---|
355 | return kTRUE;
|
---|
356 | }
|
---|
357 |
|
---|
358 | //
|
---|
359 | // file is no directory, is a file
|
---|
360 | // determine the file type by extensions
|
---|
361 | //
|
---|
362 | const char *extension=strrchr(str, '.');
|
---|
363 |
|
---|
364 | if (!extension)
|
---|
365 | return kTRUE;
|
---|
366 |
|
---|
367 | const char *dir = fFileCont->GetDirectory();
|
---|
368 |
|
---|
369 | if (!strcasecmp(extension, ".ps")) // postscript file
|
---|
370 | {
|
---|
371 | char *cmd = new char[strlen(dir)+strlen(str)+40];
|
---|
372 | sprintf(cmd, "gv %s/%s &", dir, str);
|
---|
373 | gSystem->Exec(cmd);
|
---|
374 | delete cmd;
|
---|
375 | return kTRUE;
|
---|
376 | }
|
---|
377 |
|
---|
378 | if (!strcasecmp(extension, ".root"))
|
---|
379 | {
|
---|
380 | sprintf(fInputFile, "%s/%s", dir, str);
|
---|
381 | return kTRUE;
|
---|
382 | }
|
---|
383 | return kTRUE;
|
---|
384 | }
|
---|
385 | }
|
---|
386 | return kTRUE;
|
---|
387 | }
|
---|