32 #include "RConfigure.h"
41 const TGFont *TGTreeLBEntry::fgDefaultFont = 0;
42 TGGC *TGTreeLBEntry::fgDefaultGC = 0;
55 static struct Lbc_t gLbc[32];
57 ClassImp(TGTreeLBEntry);
58 ClassImp(TGFSComboBox);
64 TGTreeLBEntry::TGTreeLBEntry(
const TGWindow *p, TGString *text,
65 const TGPicture *pic, Int_t
id, TGString *path,
66 GContext_t norm, FontStruct_t font, UInt_t options,
68 TGLBEntry(p, id, options, back)
71 Error(
"TGTreeLBEntry",
"icon not found for entry %s", text->GetString());
84 int max_ascent, max_descent;
86 fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
87 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
88 fTHeight = max_ascent + max_descent;
95 TGTreeLBEntry::~TGTreeLBEntry()
105 void TGTreeLBEntry::Activate(Bool_t a)
107 if (fActive == a)
return;
111 fSelPic =
new TGSelectedPicture(fClient, fPic);
113 if (fSelPic)
delete fSelPic;
122 void TGTreeLBEntry::DrawCopy(Handle_t
id, Int_t x, Int_t y)
127 iy = y + ((fHeight - fPic->GetHeight()) >> 1);
128 lx = x + (int)(fPic->GetWidth() + 4);
129 ly = y + (int)((fHeight - (fTHeight+1)) >> 1);
132 if (fSelPic) fSelPic->Draw(
id, fNormGC, ix, iy);
133 gVirtualX->SetForeground(fNormGC, fgDefaultSelectedBackground);
134 gVirtualX->FillRectangle(
id, fNormGC, lx-2, ly, fWidth-(lx-x), fTHeight+1);
135 gVirtualX->SetForeground(fNormGC, fClient->GetResourcePool()->GetSelectedFgndColor());
137 fPic->Draw(
id, fNormGC, ix, iy);
138 gVirtualX->SetForeground(fNormGC, fgWhitePixel);
139 gVirtualX->FillRectangle(
id, fNormGC, lx-2, ly, fWidth-(lx-x), fTHeight+1);
140 gVirtualX->SetForeground(fNormGC, fgBlackPixel);
143 int max_ascent, max_descent;
144 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
146 fText->Draw(
id, fNormGC, lx, ly + max_ascent);
152 void TGTreeLBEntry::DoRedraw()
160 TGDimension TGTreeLBEntry::GetDefaultSize()
const
162 TGDimension isize(fPic->GetWidth(), fPic->GetHeight());
163 TGDimension lsize(fTWidth, fTHeight+1);
165 return TGDimension(isize.fWidth + lsize.fWidth + 4,
166 TMath::Max(isize.fHeight, lsize.fHeight) + 2);
172 void TGTreeLBEntry::Update(TGLBEntry *e)
174 TGTreeLBEntry *te = (TGTreeLBEntry *) e;
176 if (fText)
delete fText;
177 fText =
new TGString(te->GetText());
178 fPic = te->GetPicture();
179 fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
180 gVirtualX->ClearWindow(fId);
181 fClient->NeedRedraw(
this);
187 FontStruct_t TGTreeLBEntry::GetDefaultFontStruct()
190 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
191 return fgDefaultFont->GetFontStruct();
197 const TGGC &TGTreeLBEntry::GetDefaultGC()
200 fgDefaultGC =
new TGGC(*gClient->GetResourcePool()->GetFrameGC());
208 TGFSComboBox::TGFSComboBox(
const TGWindow *parent, Int_t
id, UInt_t options,
210 TGComboBox(parent, id, options | kOwnBackground, back)
213 const TGPicture *pic;
216 SetTopEntry(
new TGTreeLBEntry(
this,
new TGString(
"Current dir"),
217 fClient->GetPicture(
"folder_t.xpm"), 0),
218 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 4, 0, 0, 0));
220 fListBox->GetContainer()->AddInput(kButtonPressMask | kButtonReleaseMask |
225 const char *homeDir = gSystem->HomeDirectory();
227 const char *rootSys = gSystem->Getenv(
"ROOTSYS");
233 TList *volumes = gSystem->GetVolumes(
"all");
234 TList *curvol = gSystem->GetVolumes(
"cur");
236 const char *curdrive =
"";
237 if (volumes && curvol) {
238 TNamed *named = (TNamed *)curvol->At(0);
240 curdrive = named->GetName();
241 infos = named->GetTitle();
242 gLbc[idx].fName = StrDup(infos.Data());
243 gLbc[idx].fPath = StrDup(Form(
"%s\\", curdrive));
244 if (infos.Contains(
"Removable"))
245 gLbc[idx].fPixmap = StrDup(
"fdisk_t.xpm");
246 else if (infos.Contains(
"Local"))
247 gLbc[idx].fPixmap = StrDup(
"hdisk_t.xpm");
248 else if (infos.Contains(
"CD"))
249 gLbc[idx].fPixmap = StrDup(
"cdrom_t.xpm");
250 else if (infos.Contains(
"Network"))
251 gLbc[idx].fPixmap = StrDup(
"netdisk_t.xpm");
253 gLbc[idx].fPixmap = StrDup(
"hdisk_t.xpm");
254 gLbc[idx].fId = 1000;
255 gLbc[idx].fIndent = 0;
256 gLbc[idx].fFlags = 0;
260 gLbc[idx].fName = StrDup(
"Root");
261 gLbc[idx].fPath = StrDup(
"/");
262 gLbc[idx].fPixmap = StrDup(
"hdisk_t.xpm");
263 gLbc[idx].fId = 1000;
264 gLbc[idx].fIndent = 1;
265 gLbc[idx].fFlags = 0;
270 gLbc[idx].fName = StrDup(
"Root");
271 gLbc[idx].fPath = StrDup(
"/");
272 gLbc[idx].fPixmap = StrDup(
"hdisk_t.xpm");
273 gLbc[idx].fId = 1000;
274 gLbc[idx].fIndent = 1;
275 gLbc[idx].fFlags = 0;
277 gLbc[idx].fName = StrDup(
"Floppy");
278 gLbc[idx].fPath = StrDup(
"/floppy");
279 gLbc[idx].fPixmap = StrDup(
"fdisk_t.xpm");
280 gLbc[idx].fId = 2000;
281 gLbc[idx].fIndent = 1;
282 gLbc[idx].fFlags = 0;
284 gLbc[idx].fName = StrDup(
"CD-ROM");
285 gLbc[idx].fPath = StrDup(
"/cdrom");
286 gLbc[idx].fPixmap = StrDup(
"cdrom_t.xpm");
287 gLbc[idx].fId = 3000;
288 gLbc[idx].fIndent = 1;
289 gLbc[idx].fFlags = 0;
292 gLbc[idx].fName = StrDup(
"Home");
293 gLbc[idx].fPath = StrDup(
"$HOME");
294 gLbc[idx].fPixmap = StrDup(
"home_t.xpm");
295 gLbc[idx].fId = (idx+1) * 1000;
296 gLbc[idx].fIndent = 1;
297 gLbc[idx].fFlags = 0;
300 gLbc[idx].fName = StrDup(
"RootSys");
301 gLbc[idx].fPath = StrDup(
"$ROOTSYS");
303 gLbc[idx].fName = StrDup(ROOTPREFIX);
304 gLbc[idx].fPath = StrDup(ROOTPREFIX);
306 gLbc[idx].fPixmap = StrDup(
"root_t.xpm");
307 gLbc[idx].fId = (idx+1) * 1000;
308 gLbc[idx].fIndent = 1;
309 gLbc[idx].fFlags = 0;
312 if (volumes && curvol) {
315 while ((drive = (TNamed *)next())) {
316 if (!strcmp(drive->GetName(), curdrive))
318 infos = drive->GetTitle();
319 gLbc[idx].fName = StrDup(drive->GetTitle());
320 gLbc[idx].fPath = StrDup(Form(
"%s\\", drive->GetName()));
321 if (infos.Contains(
"Removable"))
322 gLbc[idx].fPixmap = StrDup(
"fdisk_t.xpm");
323 else if (infos.Contains(
"Local"))
324 gLbc[idx].fPixmap = StrDup(
"hdisk_t.xpm");
325 else if (infos.Contains(
"CD"))
326 gLbc[idx].fPixmap = StrDup(
"cdrom_t.xpm");
327 else if (infos.Contains(
"Network"))
328 gLbc[idx].fPixmap = StrDup(
"netdisk_t.xpm");
330 gLbc[idx].fPixmap = StrDup(
"hdisk_t.xpm");
331 gLbc[idx].fId = (idx+1) * 1000;
332 gLbc[idx].fIndent = 0;
333 gLbc[idx].fFlags = 0;
341 gLbc[idx].fPixmap = 0;
342 gLbc[idx].fId = (idx+1) * 1000;
343 gLbc[idx].fIndent = 0;
344 gLbc[idx].fFlags = 0;
346 for (i = 0; gLbc[i].fPath != 0; ++i) {
347 if (strstr(gLbc[i].fPath,
"$HOME") != 0) {
349 int hlen = strlen(homeDir);
350 int blen = hlen + strlen(gLbc[i].fPath) - 3;
352 strlcpy(p, homeDir, blen);
353 strlcat(p, &gLbc[i].fPath[5], blen-strlen(&gLbc[i].fPath[5]));
354 delete [] gLbc[i].fPath;
367 if (strstr(gLbc[i].fPath,
"$ROOTSYS") != 0) {
371 int hlen = strlen(rootSys);
376 int blen = hlen + strlen(gLbc[i].fPath) - plen + 1;
378 strlcpy(p, rootSys, blen);
379 strlcat(p, &(gLbc[i].fPath[plen]), blen-strlen(&gLbc[i].fPath[plen]));
381 int npos = hlen + strlen(&(gLbc[i].fPath[plen]));
383 delete [] gLbc[i].fPath;
390 if (gSystem->AccessPathName(gLbc[i].fPath, kFileExists) == 0)
396 for (i = 0; gLbc[i].fName != 0; ++i) {
397 if (gLbc[i].fFlags) {
398 indent = 4 + (gLbc[i].fIndent * 10);
399 pic = fClient->GetPicture(gLbc[i].fPixmap);
400 if (!pic) Error(
"TGFSComboBox",
"pixmap not found: %s", gLbc[i].fPixmap);
401 AddEntry(
new TGTreeLBEntry(fListBox->GetContainer(),
402 new TGString(gLbc[i].fName), pic, gLbc[i].fId,
403 new TGString(gLbc[i].fPath)),
404 new TGLayoutHints(kLHintsExpandX | kLHintsTop, indent, 0, 0, 0));
413 void TGFSComboBox::Update(
const char *path)
415 char dirname[1024], mpath[1024];
416 const char *tailpath = 0;
417 int i, indent_lvl = 0, afterID = -1, sel = -1;
421 for (i = 0; gLbc[i].fPath != 0; ++i)
422 RemoveEntries(gLbc[i].fId+1, gLbc[i+1].fId-1);
425 for (i = 0; gLbc[i].fName != 0; ++i) {
426 if (gLbc[i].fFlags) {
427 int slen = strlen(gLbc[i].fPath);
428 if (strncmp(path, gLbc[i].fPath, slen) == 0) {
430 sel = afterID = gLbc[i].fId;
431 indent_lvl = gLbc[i].fIndent + 1;
432 if ((len > 0) && ((path[slen] ==
'\\') || (path[slen] ==
'/') ||
434 tailpath = path + slen;
435 strlcpy(mpath, gLbc[i].fPath, 1024);
442 if (tailpath && *tailpath) {
443 if ((*tailpath ==
'/') || (*tailpath ==
'\\')) ++tailpath;
447 const char *semi = strchr(tailpath,
'/');
448 if (semi == 0) semi = strchr(tailpath,
'\\');
450 strlcpy(dirname, tailpath, 1024);
451 picname =
"ofolder_t.xpm";
453 strlcpy(dirname, tailpath, (semi-tailpath)+1);
454 picname =
"folder_t.xpm";
456 if ((mpath[strlen(mpath)-1] !=
'/') &&
457 (mpath[strlen(mpath)-1] !=
'\\')) {
458 strlcat(mpath,
"/", 1024-strlen(mpath));
460 strlcat(mpath, dirname, 1024-strlen(mpath));
461 int indent = 4 + (indent_lvl * 10);
462 const TGPicture *pic = fClient->GetPicture(picname);
463 if (!pic) Error(
"Update",
"pixmap not found: %s", picname);
464 InsertEntry(
new TGTreeLBEntry(fListBox->GetContainer(),
465 new TGString(dirname), pic, afterID+1,
466 new TGString(mpath)),
467 new TGLayoutHints(kLHintsExpandX | kLHintsTop,
472 if (semi == 0)
break;
476 if (sel > 0) Select(sel);
482 void TGFSComboBox::SavePrimitive(std::ostream &out, Option_t *option )
484 if (fBackground != GetWhitePixel()) SaveUserColor(out, option);
486 out << std::endl <<
" // file system combo box" << std::endl;
487 out <<
" TGFSComboBox *";
488 out << GetName() <<
" = new TGFSComboBox(" << fParent->GetName()
490 if (fBackground == GetWhitePixel()) {
491 if (GetOptions() == (kHorizontalFrame | kSunkenFrame | kDoubleBorder)) {
492 out <<
");" << std::endl;
494 out <<
"," << GetOptionString() <<
");" << std::endl;
497 out <<
"," << GetOptionString() <<
",ucolor);" << std::endl;
499 if (option && strstr(option,
"keep_names"))
500 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
502 out <<
" " << GetName() <<
"->Resize(" << GetWidth() <<
","
503 << GetHeight() <<
");" << std::endl;
504 out <<
" " << GetName() <<
"->Select(" << GetSelected() <<
");" << std::endl;