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

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