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

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