Logo ROOT   6.08/07
Reference Guide
TGListTree.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id: 2897f2e70909348e1e18681c5c7b0aee8c027744 $
2 // Author: Fons Rademakers 25/02/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 /**************************************************************************
12 
13  This source is based on Xclass95, a Win95-looking GUI toolkit.
14  Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15 
16  Xclass95 is free software; you can redistribute it and/or
17  modify it under the terms of the GNU Library General Public
18  License as published by the Free Software Foundation; either
19  version 2 of the License, or (at your option) any later version.
20 
21 **************************************************************************/
22 
23 //////////////////////////////////////////////////////////////////////////
24 // //
25 // TGListTree and TGListTreeItem //
26 // //
27 // A list tree is a widget that can contain a number of items //
28 // arranged in a tree structure. The items are represented by small //
29 // folder icons that can be either open or closed. //
30 // //
31 // The TGListTree is user callable. The TGListTreeItem is a service //
32 // class of the list tree. //
33 // //
34 // A list tree can generate the following events: //
35 // kC_LISTTREE, kCT_ITEMCLICK, which button, location (y<<16|x). //
36 // kC_LISTTREE, kCT_ITEMDBLCLICK, which button, location (y<<16|x). //
37 // //
38 //////////////////////////////////////////////////////////////////////////
39 
40 #include <stdlib.h>
41 
42 #include "TROOT.h"
43 #include "TClass.h"
44 #include "TGListTree.h"
45 #include "TGPicture.h"
46 #include "TGCanvas.h"
47 #include "TGScrollBar.h"
48 #include "TGToolTip.h"
49 #include "KeySymbols.h"
50 #include "TGTextEditDialogs.h"
51 #include "TGResourcePool.h"
52 #include "TGMsgBox.h"
53 #include "TError.h"
54 #include "TColor.h"
55 #include "TSystem.h"
56 #include "TString.h"
57 #include "TObjString.h"
58 #include "TGDNDManager.h"
59 #include "TBufferFile.h"
60 #include "Riostream.h"
61 #include "RConfigure.h"
62 
74 
75 
79 
80 /******************************************************************************/
81 /******************************************************************************/
82 // TGListTreeItem
83 /******************************************************************************/
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Constructor.
87 
89  fClient(client),
90  fParent (0), fFirstchild(0), fLastchild (0), fPrevsibling(0),
91  fNextsibling(0),fOpen (kFALSE), fDNDState (0),
92  fY (0), fXtext (0), fYtext(0), fHeight(0)
93 {
94 }
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// Return width of item's icon.
98 
100 {
101  const TGPicture *pic = GetPicture();
102  return (pic) ? pic->GetWidth() : 0;
103 }
104 
105 /******************************************************************************/
106 /******************************************************************************/
107 // TGListTreeItemStd
108 /******************************************************************************/
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Create list tree item.
112 
114  const TGPicture *opened,
115  const TGPicture *closed,
116  Bool_t checkbox) :
117  TGListTreeItem(client)
118 {
119  fText = name;
120  fCheckBox = checkbox;
121  fChecked = kTRUE;
122 
123  if (!opened)
124  opened = TGListTree::GetOpenPic();
125  else
126  ((TGPicture *)opened)->AddReference();
127 
128  if (!closed)
129  closed = TGListTree::GetClosedPic();
130  else
131  ((TGPicture *)closed)->AddReference();
132 
133  fOpenPic = opened;
134  fClosedPic = closed;
135 
138 
139  fActive = kFALSE;
140 
141  fOwnsData = kFALSE;
142  fUserData = 0;
143 
144  fHasColor = kFALSE;
145  fColor = 0;
146  fDNDState = 0;
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Delete list tree item.
151 
153 {
154  if (fOwnsData && fUserData) {
155  TObject *obj = static_cast<TObject *>(fUserData);
156  delete dynamic_cast<TObject *>(obj);
157  }
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Return color for marking items that are active or selected.
166 
168 {
170 }
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Add all child items of 'item' into the list 'checked'.
174 
176 {
177  TGListTreeItem *item = this;
178 
179  while (item) {
180  if (item->IsChecked()) {
181  return kTRUE;
182  }
183  if (item->GetFirstChild()) {
184  if (item->GetFirstChild()->HasCheckedChild())
185  return kTRUE;
186  }
187  if (!first)
188  item = item->GetNextSibling();
189  else
190  break;
191  }
192  return kFALSE;
193 }
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// Add all child items of 'item' into the list 'checked'.
197 
199 {
200  TGListTreeItem *item = this;
201 
202  while (item) {
203  if (!item->IsChecked()) {
204  return kTRUE;
205  }
206  if (item->GetFirstChild()) {
207  if (item->GetFirstChild()->HasUnCheckedChild())
208  return kTRUE;
209  }
210  if (!first)
211  item = item->GetNextSibling();
212  else
213  break;
214  }
215  return kFALSE;
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Update the state of the node 'item' according to the children states.
220 
222 {
223  if ((!fChecked && HasCheckedChild(kTRUE)) ||
225  SetCheckBoxPictures(gClient->GetPicture("checked_dis_t.xpm"),
226  gClient->GetPicture("unchecked_dis_t.xpm"));
227  }
228  else {
229  SetCheckBoxPictures(gClient->GetPicture("checked_t.xpm"),
230  gClient->GetPicture("unchecked_t.xpm"));
231  }
232 }
233 
234 ////////////////////////////////////////////////////////////////////////////////
235 /// Set all child items of this one checked if state=kTRUE,
236 /// unchecked if state=kFALSE.
237 
239 {
240  if (state) {
241  if (!IsChecked())
242  CheckItem();
243  } else {
244  if (IsChecked())
245  Toggle();
246  }
247  CheckChildren(GetFirstChild(), state);
248  UpdateState();
249 }
250 
251 ////////////////////////////////////////////////////////////////////////////////
252 /// Set all child items of 'item' checked if state=kTRUE;
253 /// unchecked if state=kFALSE.
254 
256 {
257  if (!item) return;
258 
259  while (item) {
260  if (state){
261  if (!item->IsChecked())
262  item->CheckItem();
263  } else {
264  if (item->IsChecked())
265  item->Toggle();
266  }
267  if (item->GetFirstChild()) {
268  CheckChildren(item->GetFirstChild(), state);
269  }
270  item->UpdateState();
271  item = item->GetNextSibling();
272  }
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// Set a check box on the tree node.
277 
279 {
280  fCheckBox = on;
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 /// Change list tree check item icons.
285 
287  const TGPicture *unchecked)
288 {
291 
292  if (!checked) {
293  ::Warning("TGListTreeItem::SetCheckBoxPictures", "checked picture not specified, defaulting to checked_t");
294  checked = fClient->GetPicture("checked_t.xpm");
295  } else
296  ((TGPicture *)checked)->AddReference();
297 
298  if (!unchecked) {
299  ::Warning("TGListTreeItem::SetCheckBoxPictures", "unchecked picture not specified, defaulting to unchecked_t");
300  unchecked = fClient->GetPicture("unchecked_t.xpm");
301  } else
302  ((TGPicture *)unchecked)->AddReference();
303 
304  fCheckedPic = checked;
305  fUncheckedPic = unchecked;
306 }
307 
308 ////////////////////////////////////////////////////////////////////////////////
309 /// Change list tree item icons.
310 
311 void TGListTreeItemStd::SetPictures(const TGPicture *opened, const TGPicture *closed)
312 {
315 
316  if (!opened) {
317  ::Warning("TGListTreeItem::SetPictures", "opened picture not specified, defaulting to ofolder_t");
318  opened = fClient->GetPicture("ofolder_t.xpm");
319  } else
320  ((TGPicture *)opened)->AddReference();
321 
322  if (!closed) {
323  ::Warning("TGListTreeItem::SetPictures", "closed picture not specified, defaulting to folder_t");
324  closed = fClient->GetPicture("folder_t.xpm");
325  } else
326  ((TGPicture *)closed)->AddReference();
327 
328  fOpenPic = opened;
329  fClosedPic = closed;
330 }
331 
332 
333 /******************************************************************************/
334 /******************************************************************************/
335 // TGListTree
336 /******************************************************************************/
337 
338 ////////////////////////////////////////////////////////////////////////////////
339 /// Create a list tree widget.
340 
342  ULong_t back) :
343  TGContainer(p, w, h, options, back)
344 {
345  fMsgWindow = p;
346  fCanvas = 0;
347  fTip = 0;
348  fTipItem = 0;
349  fAutoTips = kFALSE;
352  fBdown = kFALSE;
356  fDropItem = 0;
357  fLastEventState = 0;
358 
361 
362  fActiveGC = GetActiveGC()();
363  fDrawGC = GetDrawGC()();
364  fLineGC = GetLineGC()();
366  fColorGC = GetColorGC()();
367 
369  fDefw = fDefh = 1;
370 
371  fHspacing = 2;
372  fVspacing = 2; // 0;
373  fIndent = 3; // 0;
374  fMargin = 2;
375 
376  fXDND = fYDND = 0;
377  fDNDData.fData = 0;
378  fDNDData.fDataLength = 0;
379  fDNDData.fDataType = 0;
380  fBuf = 0;
381 
385 
386  gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
388  kNone, kNone);
389 
392  SetWindowName();
393 
394  fDNDTypeList = new Atom_t[3];
395  fDNDTypeList[0] = gVirtualX->InternAtom("application/root", kFALSE);
396  fDNDTypeList[1] = gVirtualX->InternAtom("text/uri-list", kFALSE);
397  fDNDTypeList[2] = 0;
398  gVirtualX->SetDNDAware(fId, fDNDTypeList);
401 }
402 
403 ////////////////////////////////////////////////////////////////////////////////
404 /// Create a list tree widget.
405 
407  TGContainer(p, options, back)
408 {
409  fMsgWindow = p;
410  fTip = 0;
411  fTipItem = 0;
412  fAutoTips = kFALSE;
415  fBdown = kFALSE;
419  fDropItem = 0;
420  fLastEventState = 0;
421 
424 
425  fActiveGC = GetActiveGC()();
426  fDrawGC = GetDrawGC()();
427  fLineGC = GetLineGC()();
429  fColorGC = GetColorGC()();
430 
432  fDefw = fDefh = 1;
433 
434  fHspacing = 2;
435  fVspacing = 2; // 0;
436  fIndent = 3; // 0;
437  fMargin = 2;
438 
439  fXDND = fYDND = 0;
440  fDNDData.fData = 0;
441  fDNDData.fDataLength = 0;
442  fDNDData.fDataType = 0;
443  fBuf = 0;
444 
448 
449  gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
451  kNone, kNone);
452 
455  SetWindowName();
456 
457  fDNDTypeList = new Atom_t[3];
458  fDNDTypeList[0] = gVirtualX->InternAtom("application/root", kFALSE);
459  fDNDTypeList[1] = gVirtualX->InternAtom("text/uri-list", kFALSE);
460  fDNDTypeList[2] = 0;
461  gVirtualX->SetDNDAware(fId, fDNDTypeList);
464 }
465 
466 ////////////////////////////////////////////////////////////////////////////////
467 /// Delete list tree widget.
468 
470 {
471  TGListTreeItem *item, *sibling;
472 
473  delete [] fDNDTypeList;
474  delete fTip;
475 
476  item = fFirst;
477  while (item) {
478  PDeleteChildren(item);
479  sibling = item->fNextsibling;
480  delete item;
481  item = sibling;
482  }
483 }
484 
485 //--- text utility functions
486 
487 ////////////////////////////////////////////////////////////////////////////////
488 /// Returns height of currently used font.
489 
491 {
492  if (!fgDefaultFont)
493  fgDefaultFont = gClient->GetResourcePool()->GetIconFont();
494  return fgDefaultFont->TextHeight();
495 }
496 
497 ////////////////////////////////////////////////////////////////////////////////
498 /// Returns ascent of currently used font.
499 
501 {
503  if (!fgDefaultFont)
504  fgDefaultFont = gClient->GetResourcePool()->GetIconFont();
506  return m.fAscent;
507 }
508 
509 ////////////////////////////////////////////////////////////////////////////////
510 /// Returns text width relative to currently used font.
511 
513 {
514  if (!fgDefaultFont)
515  fgDefaultFont = gClient->GetResourcePool()->GetIconFont();
516  return fgDefaultFont->TextWidth(c);
517 }
518 
519 //---- highlighting utilities
520 
521 ////////////////////////////////////////////////////////////////////////////////
522 /// Highlight tree item.
523 
525 {
526  if (item) {
527  if ((item == fSelected) && !state) {
528  fSelected = 0;
529  if (draw) DrawItemName(fId, item);
530  } else if (state != item->IsActive()) { // !!!! leave active alone ...
531  item->SetActive(state);
532  if (draw) DrawItemName(fId, item);
533  }
534  }
535 }
536 
537 ////////////////////////////////////////////////////////////////////////////////
538 /// Higlight item children.
539 
541 {
542  while (item) {
543  HighlightItem(item, state, draw);
544  if (item->fFirstchild)
545  HighlightChildren(item->fFirstchild, state, (item->IsOpen()) ? draw : kFALSE);
546  item = item->fNextsibling;
547  }
548 }
549 
550 ////////////////////////////////////////////////////////////////////////////////
551 /// Unselect all items.
552 
554 {
555  ClearViewPort();
557 }
558 
559 ////////////////////////////////////////////////////////////////////////////////
560 /// Handle button events in the list tree.
561 
563 {
564  TGListTreeItem *item;
565 
566  if (fTip) fTip->Hide();
567 
568  Int_t page = 0;
569  if (event->fCode == kButton4 || event->fCode == kButton5) {
570  if (!fCanvas) return kTRUE;
571  if (fCanvas->GetContainer()->GetHeight()) {
572 // page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
573 // fCanvas->GetViewPort()->GetHeight()) /
574 // fCanvas->GetContainer()->GetHeight());
575  // choose page size either 1/5 of viewport or 5 lines (90)
576  Int_t r = fCanvas->GetViewPort()->GetHeight() / 5;
577  page = TMath::Min(r, 90);
578  }
579  }
580 
581  if (event->fCode == kButton4) {
582  //scroll up
583  Int_t newpos = fCanvas->GetVsbPosition() - page;
584  if (newpos < 0) newpos = 0;
585  fCanvas->SetVsbPosition(newpos);
586  return kTRUE;
587  }
588  if (event->fCode == kButton5) {
589  // scroll down
590  Int_t newpos = fCanvas->GetVsbPosition() + page;
591  fCanvas->SetVsbPosition(newpos);
592  return kTRUE;
593  }
594 
595  if (event->fType == kButtonPress) {
596  if ((item = FindItem(event->fY)) != 0) {
597  if (event->fCode == kButton1) {
598  Int_t minx, maxx;
599  Int_t minxchk = 0, maxxchk = 0;
600  if (item->HasCheckBox() && item->GetCheckBoxPicture()) {
601  minxchk = (item->fXtext - item->GetCheckBoxPicture()->GetWidth());
602  maxxchk = (item->fXtext - 4);
603  maxx = maxxchk - Int_t(item->GetPicWidth()) - 8;
604  minx = minxchk - Int_t(item->GetPicWidth()) - 16;
605  }
606  else {
607  maxx = (item->fXtext - Int_t(item->GetPicWidth())) - 8;
608  minx = (item->fXtext - Int_t(item->GetPicWidth())) - 16;
609  }
610  if ((item->HasCheckBox()) && (event->fX < maxxchk) &&
611  (event->fX > minxchk))
612  {
613  ToggleItem(item);
614  if (fCheckMode == kRecursive) {
615  CheckAllChildren(item, item->IsChecked());
616  }
617  UpdateChecked(item, kTRUE);
618  Checked((TObject *)item->GetUserData(), item->IsChecked());
619  return kTRUE;
620  }
621  if ((event->fX < maxx) && (event->fX > minx)) {
622  item->SetOpen(!item->IsOpen());
623  ClearViewPort();
624  return kTRUE;
625  }
626  }
627  // DND specific
628  if (event->fCode == kButton1) {
629  fXDND = event->fX;
630  fYDND = event->fY;
631  fBdown = kTRUE;
632  }
633  if (!fUserControlled) {
636  //item->fActive = kTRUE; // this is done below w/redraw
637  fCurrent = fSelected = item;
638  HighlightItem(item, kTRUE, kTRUE);
640  event->fCode, (event->fYRoot << 16) | event->fXRoot);
641  }
642  else {
643  fCurrent = fSelected = item;
644  ClearViewPort();
645  }
646  Clicked(item, event->fCode);
647  Clicked(item, event->fCode, event->fXRoot, event->fYRoot);
648  Clicked(item, event->fCode, event->fState, event->fXRoot, event->fYRoot);
649  }
650  }
651  if (event->fType == kButtonRelease) {
652  fBdown = kFALSE;
653  }
654  return kTRUE;
655 }
656 
657 ////////////////////////////////////////////////////////////////////////////////
658 /// Handle double click event in the list tree (only for kButton1).
659 
661 {
662  TGListTreeItem *item = 0;
663 
664  if (event->fCode == kButton4 || event->fCode == kButton5) {
665  return kFALSE;
666  }
667  // If fDisableOpen is set, only send message and emit signals.
668  // It allows user to customize handling of double click events.
669  if (fDisableOpen && event->fCode == kButton1 && (item = FindItem(event->fY)) != 0) {
671  event->fCode, (event->fYRoot << 16) | event->fXRoot);
672  DoubleClicked(item, event->fCode);
673  DoubleClicked(item, event->fCode, event->fXRoot, event->fYRoot);
674  return kTRUE;
675  }
676  item = FindItem(event->fY);
677 
678  // Otherwise, just use default behaviour (open item).
679  if (event->fCode == kButton1 && item) {
680  ClearViewPort();
681  item->SetOpen(!item->IsOpen());
682  if (!fUserControlled) {
683  if (item != fSelected) { // huh?!
684  if (fSelected) fSelected->SetActive(kFALSE); // !!!!
686  HighlightItem(item, kTRUE, kTRUE);
687  }
688  }
690  event->fCode, (event->fYRoot << 16) | event->fXRoot);
691  DoubleClicked(item, event->fCode);
692  DoubleClicked(item, event->fCode, event->fXRoot, event->fYRoot);
693  }
694  if (!fUserControlled)
695  fSelected = item;
696  return kTRUE;
697 }
698 
699 ////////////////////////////////////////////////////////////////////////////////
700 /// Handle mouse crossing event.
701 
703 {
704  if (event->fType == kLeaveNotify) {
705  if (fTip) {
706  fTip->Hide();
707  fTipItem = 0;
708  }
709  if (!fUserControlled) {
710  if (fCurrent)
711  DrawOutline(fId, fCurrent, 0xffffff, kTRUE);
712  if (fBelowMouse)
713  DrawOutline(fId, fBelowMouse, 0xffffff, kTRUE);
714  fCurrent = 0;
715  }
716  if (fBelowMouse) {
717  fBelowMouse = 0;
718  MouseOver(0);
719  MouseOver(0, event->fState);
720  }
721  }
722  ClearViewPort();
723  return kTRUE;
724 }
725 
726 ////////////////////////////////////////////////////////////////////////////////
727 /// Handle dragging position events.
728 
730  Int_t /*xroot*/, Int_t /*yroot*/)
731 {
732  static TGListTreeItem *olditem = 0;
733  TGListTreeItem *item;
734  if ((item = FindItem(y)) != 0) {
735  if (item->IsDNDTarget()) {
736  fDropItem = item;
737  if (olditem)
738  HighlightItem(olditem, kFALSE, kTRUE);
739  HighlightItem(item, kTRUE, kTRUE);
740  olditem = item;
741  return action;
742  }
743  }
744  fDropItem = 0;
745  if (olditem) {
746  HighlightItem(olditem, kFALSE, kTRUE);
747  olditem = 0;
748  }
749  return kNone;
750 }
751 
752 ////////////////////////////////////////////////////////////////////////////////
753 /// Handle drag enter events.
754 
756 {
757  Atom_t ret = kNone;
758  for (int i = 0; typelist[i] != kNone; ++i) {
759  if (typelist[i] == fDNDTypeList[0])
760  ret = fDNDTypeList[0];
761  if (typelist[i] == fDNDTypeList[1])
762  ret = fDNDTypeList[1];
763  }
764  return ret;
765 }
766 
767 ////////////////////////////////////////////////////////////////////////////////
768 /// Handle drag leave events.
769 
771 {
772  return kTRUE;
773 }
774 
775 ////////////////////////////////////////////////////////////////////////////////
776 /// Handle drop events.
777 
779 {
780  DataDropped(fDropItem, data);
782  //ClearHighlighted();
783  return kTRUE;
784 }
785 
786 ////////////////////////////////////////////////////////////////////////////////
787 /// Emit DataDropped() signal.
788 
790 {
791  Long_t args[2];
792 
793  args[0] = (Long_t)item;
794  args[1] = (Long_t)data;
795 
796  Emit("DataDropped(TGListTreeItem*,TDNDData*)", args);
797 }
798 
799 ////////////////////////////////////////////////////////////////////////////////
800 /// Handle mouse motion event. Used to set tool tip, to emit
801 /// MouseOver() signal and for DND handling.
802 
804 {
805  TGListTreeItem *item;
806  TGPosition pos = GetPagePosition();
807 
808  if (gDNDManager->IsDragging()) {
809  gDNDManager->Drag(event->fXRoot, event->fYRoot,
811  } else if ((item = FindItem(event->fY)) != 0) {
812  if (!fUserControlled) {
813  if (fCurrent)
814  DrawOutline(fId, fCurrent, 0xffffff, kTRUE);
815  if (fBelowMouse)
816  DrawOutline(fId, fBelowMouse, 0xffffff, kTRUE);
817  DrawOutline(fId, item);
818  fCurrent = item;
819  }
820  if (item != fBelowMouse) {
821  fBelowMouse = item;
823  MouseOver(fBelowMouse, event->fState);
824  }
825 
826  if (item->HasCheckBox() && item->GetCheckBoxPicture()) {
827  if ((event->fX < (item->fXtext - 4) &&
828  (event->fX > (item->fXtext - (Int_t)item->GetCheckBoxPicture()->GetWidth()))))
829  {
830  gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kPointer));
831  return kTRUE;
832  }
833  else {
834  gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kHand));
835  }
836  }
837  if (!gDNDManager->IsDragging()) {
838  if (fBdown && ((abs(event->fX - fXDND) > 2) || (abs(event->fY - fYDND) > 2))) {
839  if (gDNDManager && item->IsDNDSource()) {
840  if (!fBuf) fBuf = new TBufferFile(TBuffer::kWrite);
841  fBuf->Reset();
842  // !!!!! Here check virtual Bool_t HandlesDragAndDrop()
843  // and let the item handle this.
844  if (item->GetUserData()) {
845  TObject *obj = static_cast<TObject *>(item->GetUserData());
846  if (dynamic_cast<TObject *>(obj)) {
847  TObjString *ostr = dynamic_cast<TObjString *>(obj);
848  if (ostr) {
849  TString& str = ostr->String();
850  if (str.BeginsWith("file://")) {
852  fDNDData.fData = (void *)strdup(str.Data());
853  fDNDData.fDataLength = str.Length()+1;
854  }
855  }
856  else {
858  fBuf->WriteObject((TObject *)item->GetUserData());
859  fDNDData.fData = fBuf->Buffer();
861  }
862  }
863  }
864  else {
866  TString str = TString::Format("file://%s/%s\r\n",
868  item->GetText());
869  fDNDData.fData = (void *)strdup(str.Data());
870  fDNDData.fDataLength = str.Length()+1;
871  }
872  if (item->GetPicture()) {
873  TString xmpname = item->GetPicture()->GetName();
874  if (xmpname.EndsWith("_t.xpm"))
875  xmpname.ReplaceAll("_t.xpm", "_s.xpm");
876  if (xmpname.EndsWith("_t.xpm__16x16"))
877  xmpname.ReplaceAll("_t.xpm__16x16", "_s.xpm");
878  const TGPicture *pic = fClient->GetPicture(xmpname.Data());
879  if (!pic) pic = item->GetPicture();
880  if (pic) SetDragPixmap(pic);
881  }
882  gDNDManager->StartDrag(this, event->fXRoot, event->fYRoot);
883  }
884  }
885  }
886  if (gDNDManager->IsDragging()) {
887  gDNDManager->Drag(event->fXRoot, event->fYRoot,
889  } else {
890  if (fTipItem == item) return kTRUE;
891  if (!fUserControlled) { // !!!! what is this? It was called above once?
892  MouseOver(item);
893  MouseOver(item, event->fState);
894  }
895  gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kHand));
896  }
897 
898  if (fTip)
899  fTip->Hide();
900 
901  if (item->GetTipTextLength() > 0) {
902 
903  SetToolTipText(item->GetTipText(), item->fXtext,
904  item->fY - pos.fY + item->fHeight, 1000);
905 
906  } else if (fAutoTips && item->GetUserData()) {
907  // must derive from TObject (in principle user can put pointer
908  // to anything in user data field). Add check.
909  TObject *obj = (TObject *)item->GetUserData();
910  if (obj && obj->IsA()->IsTObject()) {
911  SetToolTipText(obj->GetTitle(), item->fXtext,
912  item->fY - pos.fY + item->fHeight, 1000);
913  }
914  }
915  fTipItem = item;
916  } else {
917  if (fBelowMouse) {
918  fBelowMouse = 0;
920  MouseOver(fBelowMouse, event->fState);
921  }
922  gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kPointer));
923  }
924  return kTRUE;
925 }
926 
927 ////////////////////////////////////////////////////////////////////////////////
928 /// The key press event handler converts a key press to some line editor
929 /// action.
930 
932 {
933  char input[10];
934  UInt_t keysym;
935  TGListTreeItem *item = 0;
936 
937  fLastEventState = event->fState;
938  if (fTip) fTip->Hide();
939 
940  if (event->fType == kGKeyPress) {
941  gVirtualX->LookupString(event, input, sizeof(input), keysym);
942 
943  if (!event->fState && (EKeySym)keysym == kKey_Escape) {
945  }
946 
947  item = fCurrent;
948  if (!item) return kFALSE;
949 
951  KeyPressed(item, keysym, event->fState);
952 
954  return kTRUE;
955 
956  switch ((EKeySym)keysym) {
957  case kKey_Enter:
958  case kKey_Return:
959  event->fType = kButtonPress;
960  event->fCode = kButton1;
961 
962  if (fSelected == item) {
963  // treat 'Enter' and 'Return' as a double click
964  ClearViewPort();
965  item->SetOpen(!item->IsOpen());
966  DoubleClicked(item, 1);
967  } else {
968  // treat 'Enter' and 'Return' as a click
971  ClearViewPort();
972  fSelected = item;
974  HighlightItem(item, kTRUE, kTRUE);
975  Clicked(item, 1);
976  Clicked(item, 1, event->fXRoot, event->fYRoot);
977  Clicked(item, 1, event->fState, event->fXRoot, event->fYRoot);
978  }
979  break;
980  case kKey_Space:
981  if (item->HasCheckBox()) {
982  ToggleItem(item);
983  if (fCheckMode == kRecursive) {
984  CheckAllChildren(item, item->IsChecked());
985  }
986  UpdateChecked(item, kTRUE);
987  Checked((TObject *)item->GetUserData(), item->IsChecked());
988  }
989  break;
990  case kKey_F3:
991  Search(kFALSE);
992  break;
993  case kKey_F5:
994  Layout();
995  break;
996  case kKey_F7:
997  Search();
998  break;
999  case kKey_Left:
1000  ClearViewPort();
1001  item->SetOpen(kFALSE);
1002  break;
1003  case kKey_Right:
1004  ClearViewPort();
1005  item->SetOpen(kTRUE);
1006  break;
1007  case kKey_Up:
1008  LineUp(event->fState & kKeyShiftMask);
1009  break;
1010  case kKey_Down:
1011  LineDown(event->fState & kKeyShiftMask);
1012  break;
1013  case kKey_PageUp:
1014  PageUp(event->fState & kKeyShiftMask);
1015  break;
1016  case kKey_PageDown:
1017  PageDown(event->fState & kKeyShiftMask);
1018  break;
1019  case kKey_Home:
1020  Home(event->fState & kKeyShiftMask);
1021  break;
1022  case kKey_End:
1023  End(event->fState & kKeyShiftMask);
1024  break;
1025  default:
1026  break;
1027  }
1028  if (event->fState & kKeyControlMask) { // Ctrl key modifier pressed
1029  switch((EKeySym)keysym & ~0x20) { // treat upper and lower the same
1030  case kKey_F:
1031  Search();
1032  break;
1033  case kKey_G:
1034  Search(kFALSE);
1035  break;
1036  default:
1037  return kTRUE;
1038  }
1039  }
1040 
1041  }
1042  return kTRUE;
1043 }
1044 
1045 ////////////////////////////////////////////////////////////////////////////////
1046 /// Signal emitted when pointer is over entry.
1047 
1049 {
1050  Emit("MouseOver(TGListTreeItem*)", (Long_t)entry);
1051 }
1052 
1053 ////////////////////////////////////////////////////////////////////////////////
1054 /// Signal emitted when pointer is over entry.
1055 
1057 {
1058  Long_t args[2];
1059  args[0] = (Long_t)entry;
1060  args[1] = mask;
1061  Emit("MouseOver(TGListTreeItem*,UInt_t)", args);
1062 }
1063 
1064 ////////////////////////////////////////////////////////////////////////////////
1065 /// Signal emitted when keyboard key pressed
1066 ///
1067 /// entry - selected item
1068 /// keysym - defined in "KeySymbols.h"
1069 /// mask - modifier key mask, defined in "GuiTypes.h"
1070 ///
1071 /// const Mask_t kKeyShiftMask = BIT(0);
1072 /// const Mask_t kKeyLockMask = BIT(1);
1073 /// const Mask_t kKeyControlMask = BIT(2);
1074 /// const Mask_t kKeyMod1Mask = BIT(3); // typically the Alt key
1075 /// const Mask_t kButton1Mask = BIT(8);
1076 /// const Mask_t kButton2Mask = BIT(9);
1077 /// const Mask_t kButton3Mask = BIT(10);
1078 /// const Mask_t kButton4Mask = BIT(11);
1079 /// const Mask_t kButton5Mask = BIT(12);
1080 /// const Mask_t kAnyModifier = BIT(15);
1081 
1083 {
1084  Long_t args[3];
1085  args[0] = (Long_t)entry;
1086  args[1] = (Long_t)keysym;
1087  args[2] = (Long_t)mask;
1088  Emit("KeyPressed(TGListTreeItem*,ULong_t,ULong_t)", args);
1089  SendMessage(fMsgWindow, MK_MSG(kC_LISTTREE, kCT_KEY), keysym, mask);
1090 }
1091 
1092 ////////////////////////////////////////////////////////////////////////////////
1093 /// Emit ReturnPressed() signal.
1094 
1096 {
1097  Emit("ReturnPressed(TGListTreeItem*)", (Long_t)entry);
1098 }
1099 
1100 ////////////////////////////////////////////////////////////////////////////////
1101 /// Emit Checked() signal.
1102 
1104 {
1105  Long_t args[2];
1106 
1107  args[0] = (Long_t)entry;
1108  args[1] = on;
1109 
1110  Emit("Checked(TObject*,Bool_t)", args);
1111 }
1112 
1113 ////////////////////////////////////////////////////////////////////////////////
1114 /// Emit Clicked() signal.
1115 
1117 {
1118  Long_t args[2];
1119 
1120  args[0] = (Long_t)entry;
1121  args[1] = btn;
1122 
1123  Emit("Clicked(TGListTreeItem*,Int_t)", args);
1124 }
1125 
1126 ////////////////////////////////////////////////////////////////////////////////
1127 /// Emit Clicked() signal.
1128 
1130 {
1131  Long_t args[4];
1132 
1133  args[0] = (Long_t)entry;
1134  args[1] = btn;
1135  args[2] = x;
1136  args[3] = y;
1137 
1138  Emit("Clicked(TGListTreeItem*,Int_t,Int_t,Int_t)", args);
1139 }
1140 
1141 ////////////////////////////////////////////////////////////////////////////////
1142 /// Emit Clicked() signal.
1143 
1145 {
1146  Long_t args[5];
1147 
1148  args[0] = (Long_t)entry;
1149  args[1] = btn;
1150  args[2] = mask;
1151  args[3] = x;
1152  args[4] = y;
1153 
1154  Emit("Clicked(TGListTreeItem*,Int_t,UInt_t,Int_t,Int_t)", args);
1155 }
1156 
1157 ////////////////////////////////////////////////////////////////////////////////
1158 /// Emit DoubleClicked() signal.
1159 
1161 {
1162  Long_t args[2];
1163 
1164  args[0] = (Long_t)entry;
1165  args[1] = btn;
1166 
1167  Emit("DoubleClicked(TGListTreeItem*,Int_t)", args);
1168 }
1169 
1170 ////////////////////////////////////////////////////////////////////////////////
1171 /// Emit DoubleClicked() signal.
1172 
1174 {
1175  Long_t args[4];
1176 
1177  args[0] = (Long_t)entry;
1178  args[1] = btn;
1179  args[2] = x;
1180  args[3] = y;
1181 
1182  Emit("DoubleClicked(TGListTreeItem*,Int_t,Int_t,Int_t)", args);
1183 }
1184 
1185 ////////////////////////////////////////////////////////////////////////////////
1186 /// Move content to the top.
1187 
1188 void TGListTree::Home(Bool_t /*select*/)
1189 {
1190  if (fCanvas) fCanvas->SetVsbPosition(0);
1191 }
1192 
1193 ////////////////////////////////////////////////////////////////////////////////
1194 /// Move content to the bottom.
1195 
1196 void TGListTree::End(Bool_t /*select*/)
1197 {
1199 }
1200 
1201 ////////////////////////////////////////////////////////////////////////////////
1202 /// Move content one page up.
1203 
1204 void TGListTree::PageUp(Bool_t /*select*/)
1205 {
1206  if (!fCanvas) return;
1207 
1208  TGDimension dim = GetPageDimension();
1209 
1210  Int_t newpos = fCanvas->GetVsbPosition() - dim.fHeight;
1211  if (newpos<0) newpos = 0;
1212 
1213  fCanvas->SetVsbPosition(newpos);
1214 }
1215 
1216 ////////////////////////////////////////////////////////////////////////////////
1217 /// Move content one page down.
1218 
1220 {
1221  if (!fCanvas) return;
1222 
1223  TGDimension dim = GetPageDimension();
1224 
1225  Int_t newpos = fCanvas->GetVsbPosition() + dim.fHeight;
1226 
1227  fCanvas->SetVsbPosition(newpos);
1228 }
1229 
1230 ////////////////////////////////////////////////////////////////////////////////
1231 /// Move content one item-size up.
1232 
1233 void TGListTree::LineUp(Bool_t /*select*/)
1234 {
1235  Int_t height = 0;
1236  if (!fCurrent) return;
1237 
1238  TGDimension dim = GetPageDimension();
1239  TGPosition pos = GetPagePosition();
1240  const TGPicture *pic1 = fCurrent->GetPicture();
1241  if (pic1) height = pic1->GetHeight() + fVspacing;
1242  else height = fVspacing + 16;
1243  Int_t findy = (fCurrent->fY - height) + (fMargin - pos.fY);
1244  TGListTreeItem *next = FindItem(findy);
1245  if (next && (next != fCurrent)) {
1246  DrawOutline(fId, fCurrent, 0xffffff, kTRUE);
1247  if (findy <= 2*height) {
1248  Int_t newpos = fCanvas->GetVsbPosition() - height;
1249  if (newpos<0) newpos = 0;
1250  fCanvas->SetVsbPosition(newpos);
1251  }
1252  DrawOutline(fId, next);
1253  fCurrent = next;
1254  }
1255 }
1256 
1257 ////////////////////////////////////////////////////////////////////////////////
1258 /// Move content one item-size down.
1259 
1261 {
1262  Int_t height;
1263  if (!fCurrent) return;
1264 
1265  TGDimension dim = GetPageDimension();
1266  TGPosition pos = GetPagePosition();
1267  const TGPicture *pic1 = fCurrent->GetPicture();
1268  if (pic1) height = pic1->GetHeight() + fVspacing;
1269  else height = fVspacing + 16;
1270  Int_t findy = (fCurrent->fY + height) + (fMargin - pos.fY);
1271  TGListTreeItem *next = FindItem(findy);
1272  if (next && (next != fCurrent)) {
1273  DrawOutline(fId, fCurrent, 0xffffff, kTRUE);
1274  if (findy >= ((Int_t)dim.fHeight - 2*height)) {
1275  Int_t newpos = fCanvas->GetVsbPosition() + height;
1276  if (newpos<0) newpos = 0;
1277  fCanvas->SetVsbPosition(newpos);
1278  }
1279  DrawOutline(fId, next);
1280  fCurrent = next;
1281  }
1282 }
1283 
1284 ////////////////////////////////////////////////////////////////////////////////
1285 /// Move content to position of item. If item is 0, move to position
1286 /// of currently selected item.
1287 
1289 {
1290  TGListTreeItem *it = item;
1291 
1292  if (!it) it = fSelected;
1293  if (!it) {
1294  HighlightItem(fFirst); // recursive call of this function
1295  return;
1296  }
1297 
1298  Int_t y = 0;
1299  Int_t yparent = 0;
1300  Int_t vh = 0;
1301  Int_t v = 0;
1302 
1303  if (it) {
1304  y = it->fY;
1305  if (it->GetParent()) yparent = it->GetParent()->fY;
1306  }
1307 
1308  if (y==0) y = yparent; // item->fY not initiated yet
1309 
1310  if (fCanvas->GetVScrollbar()->IsMapped()) {
1312 
1313  if (y<fCanvas->GetVScrollbar()->GetPosition()) {
1314  v = TMath::Max(0,y-(Int_t)fViewPort->GetHeight()/2);
1315  fCanvas->SetVsbPosition(v);
1316  } else if (y+(Int_t)it->fHeight>vh) {
1318  y+(Int_t)it->fHeight-(Int_t)fViewPort->GetHeight()/2);
1319  if (v<0) v = 0;
1320  fCanvas->SetVsbPosition(v);
1321  }
1322  }
1323 }
1324 
1325 ////////////////////////////////////////////////////////////////////////////////
1326 /// Invokes search dialog. Looks for item with the entered name.
1327 
1329 {
1330  Int_t ret = 0;
1331  char msg[256];
1332  static TString buf;
1333 
1334  TGSearchType *srch = new TGSearchType;
1335  srch->fBuffer = (char *)StrDup(buf.Data());
1336 
1337  TGListTreeItem *item;
1338  if (close || buf.IsNull())
1339  new TGSearchDialog(fClient->GetDefaultRoot(), fCanvas, 400, 150, srch, &ret);
1340  else if (!buf.IsNull()) ret = 1;
1341 
1342  if (ret) {
1343  item = FindItemByPathname(srch->fBuffer);
1344  if (!item) {
1345  snprintf(msg, 255, "Couldn't find \"%s\"", srch->fBuffer);
1346  gVirtualX->Bell(20);
1347  new TGMsgBox(fClient->GetDefaultRoot(), fCanvas, "Container", msg,
1349  } else {
1350  ClearHighlighted();
1351  HighlightItem(item);
1352  }
1353  }
1354  buf = srch->fBuffer;
1355  delete srch;
1356 }
1357 
1358 //---- drawing functions
1359 
1360 ////////////////////////////////////////////////////////////////////////////////
1361 /// Redraw list tree.
1362 
1364 {
1365  static GContext_t gcBg = 0;
1366 
1367  // sanity checks
1368  if (y > (Int_t)fViewPort->GetHeight()) {
1369  return;
1370  }
1371 
1372  y = y < 0 ? 0 : y;
1373  UInt_t w = fViewPort->GetWidth();
1374 
1375  // more sanity checks
1376  if (((Int_t)w < 1) || (w > 32768) || ((Int_t)h < 1)) {
1377  return;
1378  }
1379 
1380  Pixmap_t pixmap = gVirtualX->CreatePixmap(fId, w, fViewPort->GetHeight());
1381 
1382  if (!gcBg) {
1383  GCValues_t gcValues;
1384  gcValues.fForeground = fBackground;
1385  gcValues.fForeground = fBackground;
1386  gcValues.fGraphicsExposures = kTRUE;
1388  gcBg = gVirtualX->CreateGC(fId, &gcValues);
1389  }
1390 
1391  gVirtualX->SetForeground(gcBg, fBackground);
1392  gVirtualX->FillRectangle(pixmap, gcBg, 0, 0, w, fViewPort->GetHeight());
1393 
1394  Draw(pixmap, 0, fViewPort->GetHeight());
1395 
1396  gVirtualX->CopyArea(pixmap, fId, gcBg, 0, y, w, fViewPort->GetHeight(), 0, y);
1397 
1398  gVirtualX->DeletePixmap(pixmap);
1399  gVirtualX->Update(kFALSE);
1400 }
1401 
1402 ////////////////////////////////////////////////////////////////////////////////
1403 /// Draw list tree widget.
1404 
1405 void TGListTree::Draw(Handle_t id, Int_t yevent, Int_t hevent)
1406 {
1407  TGListTreeItem *item;
1408  Int_t x, y, xbranch;
1409  UInt_t width, height, old_width, old_height;
1410 
1411  // Overestimate the expose region to be sure to draw an item that gets
1412  // cut by the region
1413  fExposeTop = yevent - FontHeight();
1414  fExposeBottom = yevent + hevent + FontHeight();
1415  old_width = fDefw;
1416  old_height = fDefh;
1417  fDefw = fDefh = 1;
1418 
1419  TGPosition pos = GetPagePosition();
1420  x = 2-pos.fX;
1421  y = fMargin;
1422  item = fFirst;
1423 
1424  while (item) {
1425  xbranch = -1;
1426 
1427  DrawItem(id, item, x, y, &xbranch, &width, &height);
1428 
1429  width += pos.fX + x + fHspacing + fMargin;
1430 
1431  if (width > fDefw) fDefw = width;
1432 
1433  y += height + fVspacing;
1434  if (item->fFirstchild && item->IsOpen()) {
1435  y = DrawChildren(id, item->fFirstchild, x, y, xbranch);
1436  }
1437 
1438  item = item->fNextsibling;
1439  }
1440 
1441  fDefh = y + fMargin;
1442 
1443  if ((old_width != fDefw) || (old_height != fDefh)) {
1444  fCanvas->Layout();
1445  }
1446 }
1447 
1448 ////////////////////////////////////////////////////////////////////////////////
1449 /// Draw children of item in list tree.
1450 
1452  Int_t x, Int_t y, Int_t xroot)
1453 {
1454  UInt_t width, height;
1455  Int_t xbranch;
1456  TGPosition pos = GetPagePosition();
1457 
1458  x += fIndent + (Int_t)item->fParent->GetPicWidth();
1459  while (item) {
1460  xbranch = xroot;
1461 
1462  DrawItem(id, item, x, y, &xbranch, &width, &height);
1463 
1464  width += pos.fX + x + fHspacing + fMargin;
1465  if (width > fDefw) fDefw = width;
1466 
1467  y += height + fVspacing;
1468  if ((item->fFirstchild) && (item->IsOpen())) {
1469  y = DrawChildren(id, item->fFirstchild, x, y, xbranch);
1470  }
1471 
1472  item = item->fNextsibling;
1473  }
1474  return y;
1475 }
1476 
1477 ////////////////////////////////////////////////////////////////////////////////
1478 /// Draw list tree item.
1479 
1481  Int_t *xroot, UInt_t *retwidth, UInt_t *retheight)
1482 {
1483  Int_t xpic1, ypic1, xbranch, ybranch, xtext, ytext = 0, xline, yline, xc;
1484  Int_t xpic2 = 0;
1485  UInt_t height;
1486  const TGPicture *pic1 = item->GetPicture();
1487  const TGPicture *pic2 = item->GetCheckBoxPicture();
1488 
1489  // Compute the height of this line
1490  height = FontHeight();
1491 
1492  xline = 0;
1493  xpic1 = x;
1494  xtext = x + fHspacing + (Int_t)item->GetPicWidth();
1495  if (pic2) {
1496  if (pic2->GetHeight() > height) {
1497  ytext = y + (Int_t)((pic2->GetHeight() - height) >> 1);
1498  height = pic2->GetHeight();
1499  } else {
1500  ytext = y;
1501  }
1502  if (pic1) xpic2 = xpic1 + pic1->GetWidth() + 1;
1503  else xpic2 = xpic1 + 1;
1504  xtext += pic2->GetWidth();
1505  } else {
1506  ypic1 = y;
1507  xline = 0;
1508  }
1509  if (pic1) {
1510  if (pic1->GetHeight() > height) {
1511  ytext = y + (Int_t)((pic1->GetHeight() - height) >> 1);
1512  height = pic1->GetHeight();
1513  ypic1 = y;
1514  } else {
1515 #ifdef R__HAS_COCOA
1516  if (!pic2)//DO NOT MODIFY ytext, it WAS ADJUSTED already!
1517 #endif
1518  ytext = y;
1519  ypic1 = y + (Int_t)((height - pic1->GetHeight()) >> 1);
1520  }
1521  xbranch = xpic1 + (Int_t)(pic1->GetWidth() >> 1);
1522  ybranch = ypic1 + (Int_t)pic1->GetHeight();
1523  yline = ypic1 + (Int_t)(pic1->GetHeight() >> 1);
1524  if (xline == 0) xline = xpic1;
1525  } else {
1526  if (xline == 0) xline = xpic1;
1527  ypic1 = ytext = y;
1528  xbranch = xpic1 + (Int_t)(item->GetPicWidth() >> 1);
1529  yline = ybranch = ypic1 + (Int_t)(height >> 1);
1530  yline = ypic1 + (Int_t)(height >> 1);
1531  }
1532 
1533  // height must be even, otherwise our dashed line wont appear properly
1534  //++height; height &= ~1;
1535 
1536  // Save the basic graphics info for use by other functions
1537  item->fY = y;
1538  item->fXtext = xtext;
1539  item->fYtext = ytext;
1540  item->fHeight = height;
1541 
1542  // projected coordinates
1543  TGPosition pos = GetPagePosition();
1544  TGDimension dim = GetPageDimension();
1545  Int_t yp = y - pos.fY;
1546  Int_t ylinep = yline - pos.fY;
1547  Int_t ybranchp = ybranch - pos.fY;
1548  Int_t ypicp = ypic1 - pos.fY;
1549 
1550  if ((yp >= fExposeTop) && (yp <= (Int_t)dim.fHeight))
1551  {
1552  DrawItemName(id, item);
1553  if (*xroot >= 0) {
1554  xc = *xroot;
1555 
1556  if (item->fNextsibling) {
1557  gVirtualX->DrawLine(id, fLineGC, xc, yp, xc, yp+height);
1558  } else {
1559  gVirtualX->DrawLine(id, fLineGC, xc, yp, xc, ylinep);
1560  }
1561 
1562  TGListTreeItem *p = item->fParent;
1563  while (p) {
1564  xc -= (fIndent + (Int_t)item->GetPicWidth());
1565  if (p->fNextsibling) {
1566  gVirtualX->DrawLine(id, fLineGC, xc, yp, xc, yp+height);
1567  }
1568  p = p->fParent;
1569  }
1570  gVirtualX->DrawLine(id, fLineGC, *xroot, ylinep, xpic1, ylinep);
1571  DrawNode(id, item, *xroot, yline);
1572  }
1573  if (item->IsOpen() && item->fFirstchild) {
1574  gVirtualX->DrawLine(id, fLineGC, xbranch, ybranchp, xbranch,
1575  yp+height);
1576  }
1577  if (pic1)
1578  pic1->Draw(id, fDrawGC, xpic1, ypicp);
1579  if (pic2)
1580  pic2->Draw(id, fDrawGC, xpic2, ypicp);
1581  }
1582 
1583  *xroot = xbranch;
1584  *retwidth = TextWidth(item->GetText()) + item->GetPicWidth();
1585  *retheight = height;
1586 }
1587 
1588 ////////////////////////////////////////////////////////////////////////////////
1589 /// Draw a outline of color 'col' around an item.
1590 
1592  Bool_t clear)
1593 {
1594  TGPosition pos = GetPagePosition();
1595  TGDimension dim = GetPageDimension();
1596 
1597  if (clear) {
1598  gVirtualX->SetForeground(fDrawGC, fCanvas->GetContainer()->GetBackground());
1599  //ClearViewPort(); // time consuming!!!
1600  }
1601  else
1602  gVirtualX->SetForeground(fDrawGC, col);
1603 
1604 #ifdef R__HAS_COCOA
1605  gVirtualX->DrawRectangle(id, fDrawGC, 1, item->fY - pos.fY, dim.fWidth-2, item->fHeight + 1);
1606 #else
1607  gVirtualX->DrawRectangle(id, fDrawGC, 1, item->fYtext-pos.fY-2,
1608  dim.fWidth-3, FontHeight()+4);
1609 #endif
1610  gVirtualX->SetForeground(fDrawGC, fgBlackPixel);
1611 }
1612 
1613 ////////////////////////////////////////////////////////////////////////////////
1614 /// Draw active item with its active color.
1615 
1617 {
1618  UInt_t width;
1619  TGPosition pos = GetPagePosition();
1620  TGDimension dim = GetPageDimension();
1621 
1622  width = dim.fWidth-2;
1623  gVirtualX->SetForeground(fDrawGC, item->GetActiveColor());
1624 
1625 #ifdef R__HAS_COCOA
1626  gVirtualX->FillRectangle(id, fDrawGC, 1, item->fY - pos.fY, width, item->fHeight + 1);
1627 #else
1628  gVirtualX->FillRectangle(id, fDrawGC, 1, item->fYtext-pos.fY-1, width,
1629  FontHeight()+3);
1630 #endif
1631  gVirtualX->SetForeground(fDrawGC, fgBlackPixel);
1632  gVirtualX->DrawString(id, fActiveGC, item->fXtext,
1633  item->fYtext - pos.fY + FontAscent(),
1634  item->GetText(), item->GetTextLength());
1635 }
1636 
1637 ////////////////////////////////////////////////////////////////////////////////
1638 /// Draw name of list tree item.
1639 
1641 {
1642  TGPosition pos = GetPagePosition();
1643  TGDimension dim = GetPageDimension();
1644 
1645  if (item->IsActive()) {
1646  DrawActive(id, item);
1647  }
1648  else { // if (!item->IsActive() && (item != fSelected)) {
1649  gVirtualX->FillRectangle(id, fHighlightGC, item->fXtext,
1650  item->fYtext-pos.fY, dim.fWidth-item->fXtext-2,
1651  FontHeight()+1);
1652  gVirtualX->DrawString(id, fDrawGC,
1653  item->fXtext, item->fYtext-pos.fY + FontAscent(),
1654  item->GetText(), item->GetTextLength());
1655  }
1656  if (item == fCurrent) {
1657  DrawOutline(id, item);
1658  }
1659 
1660  if (fColorMode != 0 && item->HasColor()) {
1661  UInt_t width = TextWidth(item->GetText());
1662  gVirtualX->SetForeground(fColorGC, TColor::Number2Pixel(item->GetColor()));
1663  if (fColorMode & kColorUnderline) {
1664  Int_t y = item->fYtext-pos.fY + FontAscent() + 2;
1665  gVirtualX->DrawLine(id, fColorGC, item->fXtext, y,
1666  item->fXtext + width, y);
1667  }
1668  if (fColorMode & kColorBox) {
1669  Int_t x = item->fXtext + width + 4;
1670  Int_t y = item->fYtext - pos.fY + 3;
1671  Int_t h = FontAscent() - 4;
1672  gVirtualX->FillRectangle(id, fColorGC, x, y, h, h);
1673  gVirtualX->DrawRectangle(id, fDrawGC, x, y, h, h);
1674  }
1675  }
1676 }
1677 
1678 ////////////////////////////////////////////////////////////////////////////////
1679 /// Draw node (little + in box).
1680 
1682 {
1683  TGPosition pos = GetPagePosition();
1684  Int_t yp = y - pos.fY;
1685 
1686  if (item->fFirstchild) {
1687  gVirtualX->DrawLine(id, fHighlightGC, x, yp-2, x, yp+2);
1688  gVirtualX->SetForeground(fHighlightGC, fgBlackPixel);
1689  gVirtualX->DrawLine(id, fHighlightGC, x-2, yp, x+2, yp);
1690  if (!item->IsOpen())
1691  gVirtualX->DrawLine(id, fHighlightGC, x, yp-2, x, yp+2);
1692  gVirtualX->SetForeground(fHighlightGC, fGrayPixel);
1693  gVirtualX->DrawLine(id, fHighlightGC, x-4, yp-4, x+4, yp-4);
1694  gVirtualX->DrawLine(id, fHighlightGC, x+4, yp-4, x+4, yp+4);
1695  gVirtualX->DrawLine(id, fHighlightGC, x-4, yp+4, x+4, yp+4);
1696  gVirtualX->DrawLine(id, fHighlightGC, x-4, yp-4, x-4, yp+4);
1697  gVirtualX->SetForeground(fHighlightGC, fgWhitePixel);
1698  }
1699 }
1700 
1701 ////////////////////////////////////////////////////////////////////////////////
1702 /// Set tool tip text associated with this item. The delay is in
1703 /// milliseconds (minimum 250). To remove tool tip call method with
1704 /// delayms = 0. To change delayms you first have to call this method
1705 /// with delayms=0.
1706 
1707 void TGListTree::SetToolTipText(const char *text, Int_t x, Int_t y, Long_t delayms)
1708 {
1709  if (delayms == 0) {
1710  delete fTip;
1711  fTip = 0;
1712  return;
1713  }
1714 
1715  if (text && strlen(text)) {
1716  if (!fTip)
1717  fTip = new TGToolTip(fClient->GetDefaultRoot(), this, text, delayms);
1718  else
1719  fTip->SetText(text);
1720  fTip->SetPosition(x, y);
1721  fTip->Reset();
1722  }
1723 }
1724 
1725 ////////////////////////////////////////////////////////////////////////////////
1726 /// This function removes the specified item from the linked list.
1727 /// It does not do anything with the data contained in the item, though.
1728 
1730 {
1731  ClearViewPort();
1732 
1733  // Disentangle from front (previous-sibling, parent's first child)
1734  if (item->fPrevsibling) {
1735  item->fPrevsibling->fNextsibling = item->fNextsibling;
1736  } else {
1737  if (item->fParent)
1738  item->fParent->fFirstchild = item->fNextsibling;
1739  else
1740  fFirst = item->fNextsibling;
1741  }
1742  // Disentangle from end (next-sibling, parent's last child)
1743  if (item->fNextsibling) {
1744  item->fNextsibling->fPrevsibling = item->fPrevsibling;
1745  } else {
1746  if (item->fParent)
1747  item->fParent->fLastchild = item->fPrevsibling;
1748  else
1749  fLast = item->fPrevsibling;
1750  }
1751 }
1752 
1753 ////////////////////////////////////////////////////////////////////////////////
1754 /// Delete given item. Takes care of list-tree state members
1755 /// fSelected, fCurrent and fBelowMouse.
1756 
1758 {
1759  if (fSelected == item) {
1760  fSelected = 0;
1761  }
1762  if (fCurrent == item) {
1763  DrawOutline(fId, fCurrent, 0xffffff, kTRUE);
1764  fCurrent = item->GetPrevSibling();
1765  if (! fCurrent) {
1766  fCurrent = item->GetNextSibling();
1767  if (! fCurrent)
1768  fCurrent = item->GetParent();
1769  }
1770  }
1771  if (fBelowMouse == item) {
1772  DrawOutline(fId, fBelowMouse, 0xffffff, kTRUE);
1773  fBelowMouse = 0;
1774  MouseOver(0);
1776  }
1777 
1778  delete item;
1779 }
1780 
1781 ////////////////////////////////////////////////////////////////////////////////
1782 /// Recursively delete all children of an item.
1783 
1785 {
1786  TGListTreeItem *child = item->fFirstchild;
1787 
1788  while (child) {
1789  TGListTreeItem *next = child->fNextsibling;
1790  PDeleteChildren(child);
1791  PDeleteItem(child);
1792  child = next;
1793  }
1794 
1795  item->fFirstchild = item->fLastchild = 0;
1796 }
1797 
1798 ////////////////////////////////////////////////////////////////////////////////
1799 /// Insert child in list.
1800 
1802 {
1803  TGListTreeItem *i;
1804 
1805  item->fParent = parent;
1806  item->fNextsibling = item->fPrevsibling = 0;
1807 
1808  if (parent) {
1809 
1810  if (parent->fFirstchild) {
1811  if (parent->fLastchild) {
1812  i = parent->fLastchild;
1813  }
1814  else {
1815  i = parent->fFirstchild;
1816  while (i->fNextsibling) i = i->fNextsibling;
1817  }
1818  i->fNextsibling = item;
1819  item->fPrevsibling = i;
1820  } else {
1821  parent->fFirstchild = item;
1822  }
1823  parent->fLastchild = item;
1824 
1825  } else { // if parent == 0, this is a top level entry
1826 
1827  if (fFirst) {
1828  if (fLast) {
1829  i = fLast;
1830  }
1831  else {
1832  i = fFirst;
1833  while (i->fNextsibling) i = i->fNextsibling;
1834  }
1835  i->fNextsibling = item;
1836  item->fPrevsibling = i;
1837  } else {
1838  fFirst = item;
1839  }
1840  fLast = item;
1841  }
1842  if (item->HasCheckBox())
1843  UpdateChecked(item);
1844 }
1845 
1846 ////////////////////////////////////////////////////////////////////////////////
1847 /// Insert a list of ALREADY LINKED children into another list
1848 
1850 {
1851  TGListTreeItem *next, *newnext;
1852 
1853  //while (item) {
1854  // next = item->fNextsibling;
1855  // InsertChild(parent, item);
1856  // item = next;
1857  //}
1858  //return;
1859 
1860  // Save the reference for the next item in the new list
1861  next = item->fNextsibling;
1862 
1863  // Insert the first item in the new list into the existing list
1864  InsertChild(parent, item);
1865 
1866  // The first item is inserted, with its prev and next siblings updated
1867  // to fit into the existing list. So, save the existing list reference
1868  newnext = item->fNextsibling;
1869 
1870  // Now, mark the first item's next sibling to point back to the new list
1871  item->fNextsibling = next;
1872 
1873  // Mark the parents of the new list to the new parent. The order of the
1874  // rest of the new list should be OK, and the second item should still
1875  // point to the first, even though the first was reparented.
1876  while (item->fNextsibling) {
1877  item->fParent = parent;
1878  item = item->fNextsibling;
1879  }
1880 
1881  // Fit the end of the new list back into the existing list
1882  item->fNextsibling = newnext;
1883  if (newnext)
1884  newnext->fPrevsibling = item;
1885 }
1886 
1887 ////////////////////////////////////////////////////////////////////////////////
1888 /// Search child item.
1889 
1891  TGListTreeItem **finditem)
1892 {
1893  UInt_t height;
1894  const TGPicture *pic;
1895 
1896  while (item) {
1897  // Select the pixmap to use
1898  pic = item->GetPicture();
1899 
1900  // Compute the height of this line
1901  height = FontHeight();
1902  if (pic && pic->GetHeight() > height)
1903  height = pic->GetHeight();
1904 
1905  if ((findy >= y) && (findy <= y + (Int_t)height)) {
1906  *finditem = item;
1907  return -1;
1908  }
1909 
1910  y += (Int_t)height + fVspacing;
1911  if (item->fFirstchild && item->IsOpen()) {
1912  y = SearchChildren(item->fFirstchild, y, findy, finditem);
1913  if (*finditem) return -1;
1914  }
1915 
1916  item = item->fNextsibling;
1917  }
1918 
1919  return y;
1920 }
1921 
1922 ////////////////////////////////////////////////////////////////////////////////
1923 /// Find item at postion findy.
1924 
1926 {
1927  Int_t y;
1928  UInt_t height;
1929  TGListTreeItem *item, *finditem;
1930  const TGPicture *pic;
1931  TGPosition pos = GetPagePosition();
1932 
1933  y = fMargin - pos.fY;
1934  item = fFirst;
1935  finditem = 0;
1936  while (item && !finditem) {
1937  // Select the pixmap to use
1938  pic = item->GetPicture();
1939 
1940  // Compute the height of this line
1941  height = FontHeight();
1942  if (pic && (pic->GetHeight() > height))
1943  height = pic->GetHeight();
1944 
1945  if ((findy >= y) && (findy <= y + (Int_t)height))
1946  return item;
1947 
1948  y += (Int_t)height + fVspacing;
1949  if ((item->fFirstchild) && (item->IsOpen())) {
1950  y = SearchChildren(item->fFirstchild, y, findy, &finditem);
1951  //if (finditem) return finditem;
1952  }
1953  item = item->fNextsibling;
1954  }
1955 
1956  return finditem;
1957 }
1958 
1959 //----- Public Functions
1960 
1961 ////////////////////////////////////////////////////////////////////////////////
1962 /// Add given item to list tree.
1963 
1965 {
1966  InsertChild(parent, item);
1967 
1968  if ((parent == 0) || (parent && parent->IsOpen()))
1969  ClearViewPort();
1970 }
1971 
1972 ////////////////////////////////////////////////////////////////////////////////
1973 /// Add item to list tree. Returns new item.
1974 
1976  const TGPicture *open, const TGPicture *closed,
1977  Bool_t checkbox)
1978 {
1979  TGListTreeItem *item;
1980 
1981  item = new TGListTreeItemStd(fClient, string, open, closed, checkbox);
1982  InsertChild(parent, item);
1983 
1984  if ((parent == 0) || (parent && parent->IsOpen()))
1985  ClearViewPort();
1986  return item;
1987 }
1988 
1989 ////////////////////////////////////////////////////////////////////////////////
1990 /// Add item to list tree. If item with same userData already exists
1991 /// don't add it. Returns new item.
1992 
1994  void *userData, const TGPicture *open,
1995  const TGPicture *closed,
1996  Bool_t checkbox)
1997 {
1998  TGListTreeItem *item = FindChildByData(parent, userData);
1999  if (!item) {
2000  item = AddItem(parent, string, open, closed, checkbox);
2001  if (item) item->SetUserData(userData);
2002  }
2003 
2004  return item;
2005 }
2006 
2007 ////////////////////////////////////////////////////////////////////////////////
2008 /// Rename item in list tree.
2009 
2010 void TGListTree::RenameItem(TGListTreeItem *item, const char *string)
2011 {
2012  if (item) {
2013  item->Rename(string);
2014  }
2015 
2016  DoRedraw();
2017 }
2018 
2019 ////////////////////////////////////////////////////////////////////////////////
2020 /// Delete item from list tree.
2021 
2023 {
2024  if (!fUserControlled)
2025  fCurrent = fBelowMouse = 0;
2026 
2027  PDeleteChildren(item);
2028  RemoveReference(item);
2029  PDeleteItem(item);
2030 
2031  fClient->NeedRedraw(this);
2032 
2033  return 1;
2034 }
2035 
2036 ////////////////////////////////////////////////////////////////////////////////
2037 /// Open item in list tree (i.e. show child items).
2038 
2040 {
2041  if (item) {
2042  item->SetOpen(kTRUE);
2043  DoRedraw(); // force layout
2044  AdjustPosition(item);
2045  }
2046 }
2047 
2048 ////////////////////////////////////////////////////////////////////////////////
2049 /// Close item in list tree (i.e. hide child items).
2050 
2052 {
2053  if (item) {
2054  item->SetOpen(kFALSE);
2055  DoRedraw(); // force layout
2056  AdjustPosition(item);
2057  }
2058 }
2059 
2060 ////////////////////////////////////////////////////////////////////////////////
2061 /// Delete item with fUserData == ptr. Search tree downwards starting
2062 /// at item.
2063 
2065 {
2066  if (item && ptr) {
2067  if (item->GetUserData() == ptr) {
2068  DeleteItem(item);
2069  } else {
2070  if (item->IsOpen() && item->fFirstchild) {
2071  RecursiveDeleteItem(item->fFirstchild, ptr);
2072  }
2073  RecursiveDeleteItem(item->fNextsibling, ptr);
2074  }
2075  }
2076  return 1;
2077 }
2078 
2079 ////////////////////////////////////////////////////////////////////////////////
2080 /// Set tooltip text for this item. By default an item for which the
2081 /// userData is a pointer to an TObject the TObject::GetTitle() will
2082 /// be used to get the tip text.
2083 
2084 void TGListTree::SetToolTipItem(TGListTreeItem *item, const char *string)
2085 {
2086  if (item) {
2087  item->SetTipText(string);
2088  }
2089 }
2090 
2091 ////////////////////////////////////////////////////////////////////////////////
2092 /// Delete children of item from list.
2093 
2095 {
2096  if (!fUserControlled)
2097  fCurrent = fBelowMouse = 0;
2098 
2099  PDeleteChildren(item);
2100 
2101  DoRedraw();
2102 
2103  return 1;
2104 }
2105 
2106 ////////////////////////////////////////////////////////////////////////////////
2107 /// Make newparent the new parent of item.
2108 
2110 {
2111  // Remove the item from its old location.
2112  RemoveReference(item);
2113 
2114  // The item is now unattached. Reparent it.
2115  InsertChild(newparent, item);
2116 
2117  DoRedraw();
2118 
2119  return 1;
2120 }
2121 
2122 ////////////////////////////////////////////////////////////////////////////////
2123 /// Make newparent the new parent of the children of item.
2124 
2126  TGListTreeItem *newparent)
2127 {
2129 
2130  if (item->fFirstchild) {
2131  first = item->fFirstchild;
2132  item->fFirstchild = 0;
2133 
2134  InsertChildren(newparent, first);
2135 
2136  DoRedraw();
2137  return 1;
2138  }
2139  return 0;
2140 }
2141 
2142 ////////////////////////////////////////////////////////////////////////////////
2143 
2144 extern "C"
2145 Int_t Compare(const void *item1, const void *item2)
2146 {
2147  return strcmp((*((TGListTreeItem **) item1))->GetText(),
2148  (*((TGListTreeItem **) item2))->GetText());
2149 }
2150 
2151 ////////////////////////////////////////////////////////////////////////////////
2152 /// Sort items starting with item.
2153 
2155 {
2156  TGListTreeItem *first, *parent, **list;
2157  size_t i, count;
2158 
2159  // Get first child in list;
2160  while (item->fPrevsibling) item = item->fPrevsibling;
2161 
2162  first = item;
2163  parent = first->fParent;
2164 
2165  // Count the children
2166  count = 1;
2167  while (item->fNextsibling) item = item->fNextsibling, count++;
2168  if (count <= 1) return 1;
2169 
2170  list = new TGListTreeItem* [count];
2171  list[0] = first;
2172  count = 1;
2173  while (first->fNextsibling) {
2174  list[count] = first->fNextsibling;
2175  count++;
2176  first = first->fNextsibling;
2177  }
2178 
2179  ::qsort(list, count, sizeof(TGListTreeItem*), ::Compare);
2180 
2181  list[0]->fPrevsibling = 0;
2182  for (i = 0; i < count; i++) {
2183  if (i < count - 1)
2184  list[i]->fNextsibling = list[i + 1];
2185  if (i > 0)
2186  list[i]->fPrevsibling = list[i - 1];
2187  }
2188  list[count - 1]->fNextsibling = 0;
2189  if (parent) {
2190  parent->fFirstchild = list[0];
2191  parent->fLastchild = list[count-1];
2192  }
2193  else {
2194  fFirst = list[0];
2195  fLast = list[count-1];
2196  }
2197 
2198  delete [] list;
2199 
2200  DoRedraw();
2201 
2202  return 1;
2203 }
2204 
2205 ////////////////////////////////////////////////////////////////////////////////
2206 /// Sort siblings of item.
2207 
2209 {
2210  return Sort(item);
2211 }
2212 
2213 ////////////////////////////////////////////////////////////////////////////////
2214 /// Sort children of item.
2215 
2217 {
2219 
2220  if (item) {
2221  first = item->fFirstchild;
2222  if (first) {
2223  SortSiblings(first);
2224  }
2225  } else {
2226  if (fFirst) {
2227  first = fFirst->fFirstchild;
2228  if (first) {
2229  SortSiblings(first);
2230  }
2231  }
2232  }
2233  DoRedraw();
2234  return 1;
2235 }
2236 
2237 ////////////////////////////////////////////////////////////////////////////////
2238 /// Find sibling of item by name.
2239 
2241 {
2242  // Get first child in list
2243  if (item) {
2244  while (item->fPrevsibling) {
2245  item = item->fPrevsibling;
2246  }
2247 
2248  while (item) {
2249  if (strcmp(item->GetText(), name) == 0) {
2250  return item;
2251  }
2252  item = item->fNextsibling;
2253  }
2254  return item;
2255  }
2256  return 0;
2257 }
2258 
2259 ////////////////////////////////////////////////////////////////////////////////
2260 /// Find sibling of item by userData.
2261 
2263 {
2264  // Get first child in list
2265  if (item) {
2266  while (item->fPrevsibling) {
2267  item = item->fPrevsibling;
2268  }
2269 
2270  while (item) {
2271  if (item->GetUserData() == userData) {
2272  return item;
2273  }
2274  item = item->fNextsibling;
2275  }
2276  return item;
2277  }
2278  return 0;
2279 }
2280 
2281 ////////////////////////////////////////////////////////////////////////////////
2282 /// Find child of item by name.
2283 
2285 {
2286  // Get first child in list
2287  if (item && item->fFirstchild) {
2288  item = item->fFirstchild;
2289  } else if (!item && fFirst) {
2290  item = fFirst;
2291  } else {
2292  item = 0;
2293  }
2294 
2295  while (item) {
2296  if (strcmp(item->GetText(), name) == 0) {
2297  return item;
2298  }
2299  item = item->fNextsibling;
2300  }
2301  return 0;
2302 }
2303 
2304 ////////////////////////////////////////////////////////////////////////////////
2305 /// Find child of item by userData.
2306 
2308 {
2309  // Get first child in list
2310  if (item && item->fFirstchild) {
2311  item = item->fFirstchild;
2312  } else if (!item && fFirst) {
2313  item = fFirst;
2314  } else {
2315  item = 0;
2316  }
2317 
2318  while (item) {
2319  if (item->GetUserData() == userData) {
2320  return item;
2321  }
2322  item = item->fNextsibling;
2323  }
2324  return 0;
2325 }
2326 
2327 ////////////////////////////////////////////////////////////////////////////////
2328 /// Find item by pathname. Pathname is in the form of /xx/yy/zz. If zz
2329 /// in path /xx/yy is found it returns item, 0 otherwise.
2330 
2332 {
2333  if (!path || !*path) return 0;
2334 
2335  const char *p = path, *s;
2336  char dirname[1024];
2337  TGListTreeItem *item = 0;
2338  item = FindChildByName(item, "/");
2339  if (!gVirtualX->InheritsFrom("TGX11")) {
2340  // on Windows, use the current drive instead of root (/)
2341  TList *curvol = gSystem->GetVolumes("cur");
2342  if (curvol) {
2343  TNamed *drive = (TNamed *)curvol->At(0);
2344  item = FindChildByName(0, TString::Format("%s\\", drive->GetName()));
2345  }
2346  }
2347  TGListTreeItem *diritem = 0;
2348  TString fulldir;
2349 
2350  while (1) {
2351  while (*p && *p == '/') p++;
2352  if (!*p) break;
2353 
2354  s = strchr(p, '/');
2355 
2356  if (!s) {
2357  strlcpy(dirname, p, 1024);
2358  } else {
2359  strlcpy(dirname, p, (s-p)+1);
2360  }
2361 
2362  item = FindChildByName(item, dirname);
2363 
2364  if (!diritem && dirname[0]) {
2365  fulldir += "/";
2366  fulldir += dirname;
2367 
2368  if ((diritem=FindChildByName(0, fulldir.Data()))) {
2369  if (!s || !s[0]) return diritem;
2370  p = ++s;
2371  item = diritem;
2372  continue;
2373  }
2374  }
2375 
2376  if (!s || !s[0]) return item;
2377  p = ++s;
2378  }
2379  return 0;
2380 }
2381 
2382 ////////////////////////////////////////////////////////////////////////////////
2383 /// Highlight item.
2384 
2386 {
2388  HighlightItem(item, kTRUE, kFALSE);
2389  AdjustPosition(item);
2390 }
2391 
2392 ////////////////////////////////////////////////////////////////////////////////
2393 /// Un highlight items.
2394 
2396 {
2398 }
2399 
2400 ////////////////////////////////////////////////////////////////////////////////
2401 /// Get pathname from item. Use depth to limit path name to last
2402 /// depth levels. By default depth is not limited.
2403 
2405 {
2406  char tmppath[1024];
2407 
2408  *path = '\0';
2409  while (item) {
2410  snprintf(tmppath, 1023, "/%s%s", item->GetText(), path);
2411  strlcpy(path, tmppath, 1024);
2412  item = item->fParent;
2413  if (--depth == 0 && item) {
2414  snprintf(tmppath, 1023, "...%s", path);
2415  strlcpy(path, tmppath, 1024);
2416  return;
2417  }
2418  }
2419 }
2420 
2421 ////////////////////////////////////////////////////////////////////////////////
2422 /// Return gray draw color in use.
2423 
2425 {
2426  static Bool_t init = kFALSE;
2427  if (!init) {
2428  if (!gClient->GetColorByName("#808080", fgGrayPixel))
2430  init = kTRUE;
2431  }
2432  return fgGrayPixel;
2433 }
2434 
2435 ////////////////////////////////////////////////////////////////////////////////
2436 /// Return default font structure in use.
2437 
2439 {
2440  if (!fgDefaultFont)
2441  fgDefaultFont = gClient->GetResourcePool()->GetIconFont();
2442  return fgDefaultFont->GetFontStruct();
2443 }
2444 
2445 ////////////////////////////////////////////////////////////////////////////////
2446 /// Return default graphics context in use.
2447 
2449 {
2450  if (!fgActiveGC) {
2451  GCValues_t gcv;
2452 
2455  gcv.fLineStyle = kLineSolid;
2456  gcv.fLineWidth = 0;
2457  gcv.fFillStyle = kFillSolid;
2460  const TGGC *selgc = gClient->GetResourcePool()->GetSelectedGC();
2461  if (selgc)
2462  gcv.fForeground = selgc->GetForeground();
2463  else
2464  gcv.fForeground = fgWhitePixel;
2465  fgActiveGC = gClient->GetGC(&gcv, kTRUE);
2466  }
2467  return *fgActiveGC;
2468 }
2469 
2470 ////////////////////////////////////////////////////////////////////////////////
2471 /// Return default graphics context in use.
2472 
2474 {
2475  if (!fgDrawGC) {
2476  GCValues_t gcv;
2477 
2480  gcv.fLineStyle = kLineSolid;
2481  gcv.fLineWidth = 0;
2482  gcv.fFillStyle = kFillSolid;
2484  gcv.fBackground = fgWhitePixel;
2485  gcv.fForeground = fgBlackPixel;
2486 
2487  fgDrawGC = gClient->GetGC(&gcv, kTRUE);
2488  }
2489  return *fgDrawGC;
2490 }
2491 
2492 ////////////////////////////////////////////////////////////////////////////////
2493 /// Return graphics context in use for line drawing.
2494 
2496 {
2497  if (!fgLineGC) {
2498  GCValues_t gcv;
2499 
2502  gcv.fLineStyle = kLineOnOffDash;
2503  gcv.fLineWidth = 0;
2504  gcv.fFillStyle = kFillSolid;
2506  gcv.fBackground = fgWhitePixel;
2507  gcv.fForeground = GetGrayPixel();
2508 
2509  fgLineGC = gClient->GetGC(&gcv, kTRUE);
2510  fgLineGC->SetDashOffset(0);
2511  fgLineGC->SetDashList("\x1\x1", 2);
2512  }
2513  return *fgLineGC;
2514 }
2515 
2516 ////////////////////////////////////////////////////////////////////////////////
2517 /// Return graphics context for highlighted frame background.
2518 
2520 {
2521  if (!fgHighlightGC) {
2522  GCValues_t gcv;
2523 
2526  gcv.fLineStyle = kLineSolid;
2527  gcv.fLineWidth = 0;
2528  gcv.fFillStyle = kFillSolid;
2531  gcv.fForeground = fgWhitePixel;
2532 
2533  fgHighlightGC = gClient->GetGC(&gcv, kTRUE);
2534  }
2535  return *fgHighlightGC;
2536 }
2537 
2538 ////////////////////////////////////////////////////////////////////////////////
2539 /// Return graphics context for highlighted frame background.
2540 
2542 {
2543  if (!fgColorGC) {
2544  GCValues_t gcv;
2545 
2548  gcv.fLineStyle = kLineSolid;
2549  gcv.fLineWidth = 1;
2550  gcv.fFillStyle = kFillSolid;
2552  gcv.fForeground = fgWhitePixel;
2553 
2554  fgColorGC = gClient->GetGC(&gcv, kTRUE);
2555  }
2556  return *fgColorGC;
2557 }
2558 
2559 ////////////////////////////////////////////////////////////////////////////////
2560 /// Returns the icon used by items in open state.
2561 
2563 {
2564  if (!fgOpenPic)
2565  fgOpenPic = gClient->GetPicture("ofolder_t.xpm");
2566  ((TGPicture *)fgOpenPic)->AddReference();
2567  return fgOpenPic;
2568 }
2569 
2570 ////////////////////////////////////////////////////////////////////////////////
2571 /// Returns the icon used by items in closed state.
2572 
2574 {
2575  if (!fgClosedPic)
2576  fgClosedPic = gClient->GetPicture("folder_t.xpm");
2577  ((TGPicture *)fgClosedPic)->AddReference();
2578  return fgClosedPic;
2579 }
2580 
2581 ////////////////////////////////////////////////////////////////////////////////
2582 /// Returns the icon used for checked checkbox.
2583 
2585 {
2586  if (!fgCheckedPic)
2587  fgCheckedPic = gClient->GetPicture("checked_t.xpm");
2588  ((TGPicture *)fgCheckedPic)->AddReference();
2589  return fgCheckedPic;
2590 }
2591 
2592 ////////////////////////////////////////////////////////////////////////////////
2593 /// Returns the icon used for unchecked checkbox.
2594 
2596 {
2597  if (!fgUncheckedPic)
2598  fgUncheckedPic = gClient->GetPicture("unchecked_t.xpm");
2599  ((TGPicture *)fgUncheckedPic)->AddReference();
2600  return fgUncheckedPic;
2601 }
2602 
2603 ////////////////////////////////////////////////////////////////////////////////
2604 /// Save a list tree widget as a C++ statements on output stream out.
2605 
2606 void TGListTree::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2607 {
2608  if (fBackground != GetWhitePixel()) SaveUserColor(out, option);
2609 
2610  out << std::endl << " // list tree" << std::endl;
2611  out << " TGListTree *";
2612 
2614  out << GetName() << " = new TGListTree(" << GetCanvas()->GetName();
2615  } else {
2616  out << GetName() << " = new TGListTree(" << fParent->GetName();
2617  out << "," << GetWidth() << "," << GetHeight();
2618  }
2619 
2620  if (fBackground == GetWhitePixel()) {
2621  if (GetOptions() == kSunkenFrame) {
2622  out <<");" << std::endl;
2623  } else {
2624  out << "," << GetOptionString() <<");" << std::endl;
2625  }
2626  } else {
2627  out << "," << GetOptionString() << ",ucolor);" << std::endl;
2628  }
2629  if (option && strstr(option, "keep_names"))
2630  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
2631 
2632  out << std::endl;
2633 
2634  static Int_t n = 0;
2635 
2636  TGListTreeItem *current;
2637  current = GetFirstItem();
2638 
2639  out << " const TGPicture *popen; //used for list tree items" << std::endl;
2640  out << " const TGPicture *pclose; //used for list tree items" << std::endl;
2641  out << std::endl;
2642 
2643  while (current) {
2644  out << " TGListTreeItem *item" << n << " = " << GetName() << "->AddItem(";
2645  current->SavePrimitive(out, TString::Format("%d",n), n);
2646  if (current->IsOpen())
2647  out << " " << GetName() << "->OpenItem(item" << n << ");" << std::endl;
2648  else
2649  out << " " << GetName() << "->CloseItem(item" << n << ");" << std::endl;
2650 
2651  if (current == fSelected)
2652  out << " " << GetName() << "->SetSelected(item" << n << ");" << std::endl;
2653 
2654  n++;
2655  if (current->fFirstchild) {
2656  SaveChildren(out, current->fFirstchild, n);
2657  }
2658  current = current->fNextsibling;
2659  }
2660 
2661  out << std::endl;
2662 }
2663 
2664 ////////////////////////////////////////////////////////////////////////////////
2665 /// Save child items as a C++ statements on output stream out.
2666 
2667 void TGListTree::SaveChildren(std::ostream &out, TGListTreeItem *item, Int_t &n)
2668 {
2669  Int_t p = n-1;
2670  while (item) {
2671  out << " TGListTreeItem *item" << n << " = " << GetName() << "->AddItem(";
2672  item->SavePrimitive(out, TString::Format("%d",p),n);
2673  n++;
2674  if (item->fFirstchild) {
2675  SaveChildren(out, item->fFirstchild, n);
2676  }
2677  item = item->fNextsibling;
2678  }
2679 }
2680 
2681 ////////////////////////////////////////////////////////////////////////////////
2682 /// Save a list tree item attributes as a C++ statements on output stream.
2683 
2684 void TGListTreeItemStd::SavePrimitive(std::ostream &out, Option_t *option, Int_t n)
2685 {
2686  static const TGPicture *oldopen=0;
2687  static const TGPicture *oldclose=0;
2688  static const TGPicture *oldcheck=0;
2689  static const TGPicture *olduncheck=0;
2690  static Bool_t makecheck = kTRUE;
2691  static Bool_t makeuncheck = kTRUE;
2692  static Color_t oldcolor = -1;
2693 
2694  char quote = '"';
2695  TString s = TString::Format("%d", n);
2696 
2697  if (!fParent)
2698  out << "NULL,";
2699  else
2700  out << "item" << option << ",";
2701  TString text = GetText();
2702  text.ReplaceAll('\\', "\\\\");
2703  text.ReplaceAll("\"", "\\\"");
2704  out << quote << text << quote;
2705  out << ");" << std::endl;
2706 
2707  if (oldopen != fOpenPic) {
2708  oldopen = fOpenPic;
2709  out << " popen = gClient->GetPicture(" << quote
2710  << gSystem->ExpandPathName(gSystem->UnixPathName(fOpenPic->GetName()))
2711  << quote << ");" << std::endl;
2712  }
2713  if (oldclose != fClosedPic) {
2714  oldclose = fClosedPic;
2715  out << " pclose = gClient->GetPicture(" << quote
2716  << gSystem->ExpandPathName(gSystem->UnixPathName(fClosedPic->GetName()))
2717  << quote << ");" << std::endl;
2718  }
2719  out << " item" << s.Data() << "->SetPictures(popen, pclose);" << std::endl;
2720  if (HasCheckBox()) {
2721  if (fCheckedPic && makecheck) {
2722  out << " const TGPicture *pcheck; //used for checked items" << std::endl;
2723  makecheck = kFALSE;
2724  }
2725  if (fUncheckedPic && makeuncheck) {
2726  out << " const TGPicture *puncheck; //used for unchecked items" << std::endl;
2727  makeuncheck = kFALSE;
2728  }
2729  out << " item" << s.Data() << "->CheckItem();" << std::endl;
2730  if (fCheckedPic && oldcheck != fCheckedPic) {
2731  oldcheck = fCheckedPic;
2732  out << " pcheck = gClient->GetPicture(" << quote
2733  << gSystem->ExpandPathName(gSystem->UnixPathName(fCheckedPic->GetName()))
2734  << quote << ");" << std::endl;
2735  }
2736  if (fUncheckedPic && olduncheck != fUncheckedPic) {
2737  olduncheck = fUncheckedPic;
2738  out << " puncheck = gClient->GetPicture(" << quote
2739  << gSystem->ExpandPathName(gSystem->UnixPathName(fUncheckedPic->GetName()))
2740  << quote << ");" << std::endl;
2741  }
2742  out << " item" << s.Data() << "->SetCheckBoxPictures(pcheck, puncheck);" << std::endl;
2743  out << " item" << s.Data() << "->SetCheckBox(kTRUE);" << std::endl;
2744  }
2745  if (fHasColor) {
2746  if (oldcolor != fColor) {
2747  oldcolor = fColor;
2748  out << " item" << s.Data() << "->SetColor(" << fColor << ");" << std::endl;
2749  }
2750  }
2751  if (fTipText.Length() > 0) {
2752  TString tiptext = GetTipText();
2753  tiptext.ReplaceAll('\\', "\\\\");
2754  tiptext.ReplaceAll("\n", "\\n");
2755  tiptext.ReplaceAll("\"", "\\\"");
2756  out << " item" << s.Data() << "->SetTipText(" << quote
2757  << tiptext << quote << ");" << std::endl;
2758  }
2759 
2760 }
2761 
2762 ////////////////////////////////////////////////////////////////////////////////
2763 /// Set check button state for the node 'item'.
2764 
2766 {
2767  item->CheckItem(check);
2768 }
2769 
2770 ////////////////////////////////////////////////////////////////////////////////
2771 /// Set check button state for the node 'item'.
2772 
2774 {
2775  item->SetCheckBox(on);
2776 }
2777 
2778 ////////////////////////////////////////////////////////////////////////////////
2779 /// Toggle check button state of the node 'item'.
2780 
2782 {
2783  item->Toggle();
2784 }
2785 
2786 ////////////////////////////////////////////////////////////////////////////////
2787 /// Update the state of the node 'item' according to the children states.
2788 
2790 {
2791  if (fAutoCheckBoxPic == kFALSE) return;
2792 
2793  TGListTreeItem *parent;
2794  TGListTreeItem *current;
2795  current = item->GetFirstChild();
2796  parent = current ? current : item;
2797  // recursively check parent/children status
2798  while (parent && parent->HasCheckBox()) {
2799  if ((!parent->IsChecked() && parent->HasCheckedChild(kTRUE)) ||
2800  (parent->IsChecked() && parent->HasUnCheckedChild(kTRUE))) {
2801  parent->SetCheckBoxPictures(fClient->GetPicture("checked_dis_t.xpm"),
2802  fClient->GetPicture("unchecked_dis_t.xpm"));
2803  }
2804  else {
2805  parent->SetCheckBoxPictures(fClient->GetPicture("checked_t.xpm"),
2806  fClient->GetPicture("unchecked_t.xpm"));
2807  }
2808  parent = parent->GetParent();
2809  if (parent && fCheckMode == kRecursive) {
2810  if (!parent->IsChecked() && parent->GetFirstChild() &&
2811  !parent->GetFirstChild()->HasUnCheckedChild()) {
2812  parent->SetCheckBoxPictures(fClient->GetPicture("checked_t.xpm"),
2813  fClient->GetPicture("unchecked_t.xpm"));
2814  parent->CheckItem(kTRUE);
2815  }
2816  else if (parent->IsChecked() && parent->GetFirstChild() &&
2817  !parent->GetFirstChild()->HasCheckedChild()) {
2818  parent->SetCheckBoxPictures(fClient->GetPicture("checked_t.xpm"),
2819  fClient->GetPicture("unchecked_t.xpm"));
2820  parent->CheckItem(kFALSE);
2821  }
2822  }
2823  }
2824  if (redraw) {
2825  ClearViewPort();
2826  }
2827 }
2828 
2829 ////////////////////////////////////////////////////////////////////////////////
2830 /// Find item with fUserData == ptr. Search tree downwards starting
2831 /// at item.
2832 
2834 {
2835  TGListTreeItem *fitem;
2836  if (item && ptr) {
2837  if (item->GetUserData() == ptr)
2838  return item;
2839  else {
2840  if (item->fFirstchild) {
2841  fitem = FindItemByObj(item->fFirstchild, ptr);
2842  if (fitem) return fitem;
2843  }
2844  return FindItemByObj(item->fNextsibling, ptr);
2845  }
2846  }
2847  return 0;
2848 }
2849 
2850 ////////////////////////////////////////////////////////////////////////////////
2851 /// Add all checked list tree items of this list tree into
2852 /// the list 'checked'. This list is not adopted and must
2853 /// be deleted by the user later.
2854 
2856 {
2857  if (!checked || !fFirst) return;
2858  TGListTreeItem *current = fFirst;
2859  if (current->IsChecked()) {
2860  checked->Add(new TObjString(current->GetText()));
2861  }
2862  while(current) {
2863  if (current->GetFirstChild())
2864  GetCheckedChildren(checked, current->GetFirstChild());
2865  current = current->GetNextSibling();
2866  }
2867 }
2868 
2869 ////////////////////////////////////////////////////////////////////////////////
2870 /// Add all child items of 'item' into the list 'checked'.
2871 
2873 {
2874  if (!checked || !item) return;
2875 
2876  while (item) {
2877  if (item->IsChecked()) {
2878  checked->Add(new TObjString(item->GetText()));
2879  }
2880  if (item->GetFirstChild()) {
2881  GetCheckedChildren(checked, item->GetFirstChild());
2882  }
2883  item = item->GetNextSibling();
2884  }
2885 }
2886 
2887 ////////////////////////////////////////////////////////////////////////////////
2888 /// Check all child items of 'item' and 'item' itself according
2889 /// to the state value: kTRUE means check all, kFALSE - uncheck all.
2890 
2892 {
2893  if (item)
2894  item->CheckAllChildren(state);
2895 }
2896 
TGClient * fClient
Definition: TGListTree.h:58
virtual void SetPictures(const TGPicture *opened, const TGPicture *closed)
Change list tree item icons.
Definition: TGListTree.cxx:311
TGListTreeItem * fFirstchild
Definition: TGListTree.h:60
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TGToolTip * fTip
Definition: TGListTree.h:250
Int_t fLineStyle
Definition: GuiTypes.h:231
Handle_t FontStruct_t
Definition: GuiTypes.h:40
const TGWindow * fParent
Definition: TGWindow.h:43
virtual ~TGListTreeItemStd()
Delete list tree item.
Definition: TGListTree.cxx:152
GContext_t fHighlightGC
Definition: TGListTree.h:244
static const TGGC & GetHighlightGC()
Return graphics context for highlighted frame background.
Int_t fDataLength
Definition: TGDNDManager.h:80
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a list tree widget as a C++ statements on output stream out.
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket...
Definition: TBufferFile.h:51
virtual UInt_t GetOptions() const
Definition: TGFrame.h:260
virtual void * GetUserData() const =0
TGListTreeItem * FindChildByData(TGListTreeItem *item, void *userData)
Find child of item by userData.
Int_t TextHeight() const
Definition: TGFont.h:207
TGListTreeItem * FindItemByObj(TGListTreeItem *item, void *ptr)
Find item with fUserData == ptr.
Int_t fY
Definition: TGDimension.h:53
const char * GetName() const
Returns name of object.
Definition: TGPicture.h:72
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:866
Int_t DeleteItem(TGListTreeItem *item)
Delete item from list tree.
virtual void SetCheckBox(Bool_t=kTRUE)
Definition: TGListTree.h:109
void InsertChildren(TGListTreeItem *parent, TGListTreeItem *item)
Insert a list of ALREADY LINKED children into another list.
Collectable string class.
Definition: TObjString.h:32
FontH_t fFont
Definition: GuiTypes.h:243
Bool_t IsDNDTarget() const
Definition: TGListTree.h:134
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition: TGFrame.cxx:321
return c
virtual Bool_t HasColor() const =0
const char Option_t
Definition: RtypesCore.h:62
const Mask_t kKeyShiftMask
Definition: GuiTypes.h:196
virtual void SetVsbPosition(Int_t newPos)
Set position of vertical scrollbar.
Definition: TGCanvas.cxx:2405
virtual Bool_t HasUnCheckedChild(Bool_t=kFALSE)
Definition: TGListTree.h:119
static const TGPicture * GetOpenPic()
Returns the icon used by items in open state.
void Reset()
Reset tool tip popup delay timer.
Definition: TGToolTip.cxx:259
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
void DrawItem(Handle_t id, TGListTreeItem *item, Int_t x, Int_t y, Int_t *xroot, UInt_t *retwidth, UInt_t *retheight)
Draw list tree item.
UInt_t fHeight
Definition: TGListTree.h:73
static TGGC * fgDrawGC
Definition: TGListTree.h:270
TBufferFile * fBuf
Definition: TGListTree.h:252
void SetText(const char *new_text)
Set new tool tip text.
Definition: TGToolTip.cxx:386
UInt_t GetHeight() const
Definition: TGFrame.h:288
Bool_t fBdown
Definition: TGCanvas.h:73
TH1 * h
Definition: legend2.C:5
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:691
void ReturnPressed(TGFrame *)
Signal emitted when Return/Enter key pressed.
Definition: TGListTree.h:316
void LineDown(Bool_t select=kFALSE)
Move content one item-size down.
const Mask_t kLeaveWindowMask
Definition: GuiTypes.h:169
static const TGGC & GetLineGC()
Return graphics context in use for line drawing.
TDNDData fDNDData
Definition: TGListTree.h:253
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Redraw list tree.
const TGPicture * fUncheckedPic
Definition: TGListTree.h:159
void Draw(Handle_t id, Int_t yevent, Int_t hevent)
Draw list tree widget.
Int_t TextWidth(const char *c)
Returns text width relative to currently used font.
Definition: TGListTree.cxx:512
Int_t fExposeBottom
Definition: TGListTree.h:249
static const TGPicture * GetUncheckedPic()
Returns the icon used for unchecked checkbox.
void DoubleClicked(TGFrame *, Int_t)
Emit DoubleClicked() signal.
Definition: TGListTree.h:319
Int_t fY
Definition: GuiTypes.h:179
Handle_t GContext_t
Definition: GuiTypes.h:39
Basic string class.
Definition: TString.h:137
Pixel_t fBackground
Definition: TGFrame.h:158
#define gClient
Definition: TGClient.h:174
virtual void SavePrimitive(std::ostream &, Option_t *, Int_t)
Definition: TGListTree.h:141
static Pixel_t fgWhitePixel
Definition: TGFrame.h:166
const Mask_t kGCLineStyle
Definition: GuiTypes.h:292
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
int Int_t
Definition: RtypesCore.h:41
Int_t DeleteChildren(TGListTreeItem *item)
Delete children of item from list.
GContext_t fDrawGC
Definition: TGListTree.h:242
bool Bool_t
Definition: RtypesCore.h:59
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
const Bool_t kFALSE
Definition: Rtypes.h:92
static Pixel_t fgDefaultSelectedBackground
Definition: TGFrame.h:165
virtual Bool_t HasCheckedChild(Bool_t first=kFALSE)
Add all child items of &#39;item&#39; into the list &#39;checked&#39;.
Definition: TGListTree.cxx:175
void Hide()
Hide tool tip window.
Definition: TGToolTip.cxx:246
TGCanvas * fCanvas
Definition: TGCanvas.h:53
static const TGPicture * fgCheckedPic
Definition: TGListTree.h:276
virtual void CheckAllChildren(Bool_t state=kTRUE)
Set all child items of this one checked if state=kTRUE, unchecked if state=kFALSE.
Definition: TGListTree.cxx:238
Int_t fFillStyle
Definition: GuiTypes.h:235
TGFrame * GetContainer() const
Definition: TGCanvas.h:228
UInt_t GetWidth() const
Definition: TGFrame.h:287
const char * Class
Definition: TXMLSetup.cxx:64
Bool_t HandleDNDLeave()
Handle drag leave events.
Definition: TGListTree.cxx:770
const TGWindow * fMsgWindow
Definition: TGCanvas.h:54
virtual Bool_t HasUnCheckedChild(Bool_t first=kFALSE)
Add all child items of &#39;item&#39; into the list &#39;checked&#39;.
Definition: TGListTree.cxx:198
void RemoveReference(TGListTreeItem *item)
This function removes the specified item from the linked list.
UInt_t GetHeight() const
Definition: TGPicture.h:74
void PDeleteChildren(TGListTreeItem *item)
Recursively delete all children of an item.
virtual void SavePrimitive(std::ostream &out, Option_t *option, Int_t n)
Save a list tree item attributes as a C++ statements on output stream.
Bool_t IsDragging() const
Definition: TGDNDManager.h:177
const TGPicture * fCheckedPic
Definition: TGListTree.h:158
virtual Int_t GetTipTextLength() const =0
GContext_t fActiveGC
Definition: TGListTree.h:241
static Atom_t GetDNDActionCopy()
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition: TSystem.cxx:1037
Atom_t * fDNDTypeList
Definition: TGListTree.h:254
virtual const TGPicture * GetPicture() const =0
R__EXTERN TGDNDManager * gDNDManager
Definition: TGDNDManager.h:205
virtual TGPosition GetPagePosition() const
Returns page position.
Definition: TGCanvas.cxx:734
Int_t Length() const
Definition: TBuffer.h:96
void Draw(Option_t *="")
Default Draw method for all objects.
Definition: TGPicture.h:67
virtual TGDimension GetPageDimension() const
Returns page dimension.
Definition: TGCanvas.cxx:748
void SetDNDTarget(Bool_t onoff)
Definition: TGFrame.h:333
const Mask_t kPointerMotionMask
Definition: GuiTypes.h:164
virtual void CheckItem(Bool_t=kTRUE)=0
TGListTreeItem * FindChildByName(TGListTreeItem *item, const char *name)
Find child of item by name.
virtual void Checked(TObject *obj, Bool_t check)
Emit Checked() signal.
static const TGPicture * GetClosedPic()
Returns the icon used by items in closed state.
void Clicked(TGFrame *, Int_t)
Emit Clicked() signal.
Definition: TGListTree.h:317
Double_t x[n]
Definition: legend1.C:17
void SetToolTipText(const char *text, Int_t x, Int_t y, Long_t delayms)
Set tool tip text associated with this item.
Int_t fIndent
Definition: TGListTree.h:238
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2335
ULong_t Pixel_t
Definition: GuiTypes.h:41
void HighlightChildren(TGListTreeItem *item, Bool_t state, Bool_t draw)
Higlight item children.
Definition: TGListTree.cxx:540
virtual void SetActive(Bool_t)
Definition: TGListTree.h:90
void DrawItemName(Handle_t id, TGListTreeItem *item)
Draw name of list tree item.
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual void SetUserData(void *, Bool_t=kFALSE)
Definition: TGListTree.h:100
virtual void DrawOutline(Handle_t id, TGListTreeItem *item, Pixel_t col=0xbbbbbb, Bool_t clear=kFALSE)
Draw a outline of color &#39;col&#39; around an item.
Bool_t EndDrag()
End dragging.
void SetToolTipItem(TGListTreeItem *item, const char *string)
Set tooltip text for this item.
virtual Bool_t HasCheckedChild(Bool_t=kFALSE)
Definition: TGListTree.h:118
UInt_t fLastEventState
Definition: TGListTree.h:261
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:306
Int_t SortSiblings(TGListTreeItem *item)
Sort siblings of item.
virtual Bool_t IsActive() const =0
FontStruct_t fFont
Definition: TGListTree.h:245
Handle_t Atom_t
Definition: GuiTypes.h:38
ULong_t fForeground
Definition: GuiTypes.h:228
Int_t TextWidth(const char *string, Int_t numChars=-1) const
A wrapper function for the more complicated interface of MeasureChars.
Definition: TGFont.cxx:563
const Mask_t kGCFont
Definition: GuiTypes.h:301
char * Buffer() const
Definition: TBuffer.h:93
void AdjustPosition()
Move content to position of highlighted/activated frame.
Definition: TGListTree.h:376
Int_t fXRoot
Definition: GuiTypes.h:180
static TGGC * fgHighlightGC
Definition: TGListTree.h:272
TGListTreeItem * fFirst
Definition: TGListTree.h:231
virtual TGVScrollBar * GetVScrollbar() const
returns pointer to vert. scroll bar
Definition: TGCanvas.cxx:1750
const Mask_t kGCLineWidth
Definition: GuiTypes.h:291
static Pixel_t fgBlackPixel
Definition: TGFrame.h:167
TGListTreeItem * FindSiblingByData(TGListTreeItem *item, void *userData)
Find sibling of item by userData.
virtual Int_t GetPosition() const
Definition: TGScrollBar.h:134
EColorMarkupMode fColorMode
Definition: TGListTree.h:263
void * fData
Definition: TGDNDManager.h:79
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2221
const Mask_t kGCGraphicsExposures
Definition: GuiTypes.h:303
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:627
static const TGPicture * fgClosedPic
Definition: TGListTree.h:275
virtual void SetSmallIncrement(Int_t increment)
Definition: TGScrollBar.h:155
virtual Pixel_t GetActiveColor() const =0
TGListTreeItem * GetPrevSibling() const
Definition: TGListTree.h:82
virtual void Toggle()
Definition: TGListTree.h:196
GContext_t fLineGC
Definition: TGListTree.h:243
TGListTreeItem * FindItem(Int_t findy)
Find item at postion findy.
void SetPosition(Int_t x, Int_t y)
Set popup position within specified frame (as specified in the ctor).
Definition: TGToolTip.cxx:405
static Pixel_t GetGrayPixel()
Return gray draw color in use.
UInt_t fHeight
Definition: TGDimension.h:32
TGViewPort * GetViewPort() const
Definition: TGCanvas.h:229
Bool_t fAutoTips
Definition: TGListTree.h:256
void InsertChild(TGListTreeItem *parent, TGListTreeItem *item)
Insert child in list.
short Color_t
Definition: RtypesCore.h:79
TGListTreeItem * fPrevsibling
Definition: TGListTree.h:62
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:561
virtual void SetCheckBox(Bool_t on=kTRUE)
Set a check box on the tree node.
Definition: TGListTree.cxx:278
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
Definition: TGListTree.cxx:702
TGListTreeItemStd(const TGListTreeItemStd &)
static const TGFont * fgDefaultFont
Definition: TGListTree.h:268
A doubly linked list.
Definition: TList.h:47
virtual Color_t GetColor() const =0
void GetCheckedChildren(TList *checked, TGListTreeItem *item)
Add all child items of &#39;item&#39; into the list &#39;checked&#39;.
void UnselectAll(Bool_t draw)
Unselect all items.
Definition: TGListTree.cxx:553
const Mask_t kButtonPressMask
Definition: GuiTypes.h:162
void OpenItem(TGListTreeItem *item)
Open item in list tree (i.e. show child items).
virtual void SetTipText(const char *)
Definition: TGListTree.h:98
const Mask_t kKeyPressMask
Definition: GuiTypes.h:160
static const TGGC & GetActiveGC()
Return default graphics context in use.
Bool_t fGraphicsExposures
Definition: GuiTypes.h:245
static const TGPicture * GetCheckedPic()
Returns the icon used for checked checkbox.
Pixel_t fGrayPixel
Definition: TGListTree.h:240
UInt_t fWidth
Definition: TGDimension.h:31
virtual void SetCheckBoxPictures(const TGPicture *, const TGPicture *)
Definition: TGListTree.h:106
void PDeleteItem(TGListTreeItem *item)
Delete given item.
static const TGGC & GetDrawGC()
Return default graphics context in use.
TGListTreeItem * fSelected
Definition: TGListTree.h:233
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Bool_t IsDNDSource() const
Definition: TGListTree.h:133
void CheckAllChildren(TGListTreeItem *item, Bool_t state)
Check all child items of &#39;item&#39; and &#39;item&#39; itself according to the state value: kTRUE means check all...
UInt_t fDefh
Definition: TGListTree.h:247
TRandom2 r(17)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
Time_t fTime
Definition: GuiTypes.h:178
Pixel_t GetForeground() const
Definition: TGGC.h:86
SVector< double, 2 > v
Definition: Dict.h:5
EGEventType fType
Definition: GuiTypes.h:176
TGListTreeItem * GetNextSibling() const
Definition: TGListTree.h:83
TGListTreeItem * fLastchild
Definition: TGListTree.h:61
TGCanvas * GetCanvas() const
Definition: TGCanvas.h:111
virtual Bool_t HasCheckBox() const =0
Int_t fYDND
Definition: TGCanvas.h:72
void GetPathnameFromItem(TGListTreeItem *item, char *path, Int_t depth=0)
Get pathname from item.
void AddItem(TGListTreeItem *parent, TGListTreeItem *item)
Add given item to list tree.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:488
virtual void SetDragPixmap(const TGPicture *pic)
Set drag window pixmaps and hotpoint.
Definition: TGCanvas.cxx:1077
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
TGListTreeItem * fParent
Definition: TGListTree.h:59
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
virtual void SetOpen(Bool_t o)
Definition: TGListTree.h:86
void GetChecked(TList *checked)
Add all checked list tree items of this list tree into the list &#39;checked&#39;.
virtual const char * GetText() const =0
unsigned int UInt_t
Definition: RtypesCore.h:42
TMarker * m
Definition: textangle.C:8
static TGGC * fgLineGC
Definition: TGListTree.h:271
void ClearHighlighted()
Un highlight items.
const Handle_t kNone
Definition: GuiTypes.h:89
Ssiz_t Length() const
Definition: TString.h:390
virtual void CheckItem(Bool_t checked=kTRUE)
Definition: TGListTree.h:195
Int_t DrawChildren(Handle_t id, TGListTreeItem *item, Int_t x, Int_t y, Int_t xroot)
Draw children of item in list tree.
Bool_t fDisableOpen
Definition: TGListTree.h:258
Int_t fYRoot
Definition: GuiTypes.h:180
void PageDown(Bool_t select=kFALSE)
Move content one page down.
virtual void UpdateState()
Update the state of the node &#39;item&#39; according to the children states.
Definition: TGListTree.cxx:221
virtual Pixel_t GetBackground() const
Definition: TGFrame.h:255
TGListTree(const TGListTree &)
virtual void Toggle()
Definition: TGListTree.h:112
virtual Int_t Compare(const TObject *obj) const
Compare abstract method.
Definition: TObject.cxx:219
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:311
GContext_t fColorGC
Definition: TGListTree.h:265
Int_t fX
Definition: TGDimension.h:52
virtual Bool_t HandleButton(Event_t *event)
Handle button events in the list tree.
Definition: TGListTree.cxx:562
virtual void SetCheckBoxPictures(const TGPicture *checked, const TGPicture *unchecked)
Change list tree check item icons.
Definition: TGListTree.cxx:286
virtual ~TGListTree()
Delete list tree widget.
Definition: TGListTree.cxx:469
Atom_t fDataType
Definition: TGDNDManager.h:77
Int_t FontHeight()
Returns height of currently used font.
Definition: TGListTree.cxx:490
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event.
Definition: TGListTree.cxx:803
virtual Pixel_t GetActiveColor() const
Return color for marking items that are active or selected.
Definition: TGListTree.cxx:167
void Warning(const char *location, const char *msgfmt,...)
Int_t SortChildren(TGListTreeItem *item)
Sort children of item.
TGListTreeItem * fDropItem
Definition: TGListTree.h:255
TString & String()
Definition: TObjString.h:52
void Rename(const char *new_name)
Definition: TGListTree.h:92
#define gVirtualX
Definition: TVirtualX.h:362
Bool_t HandleDNDDrop(TDNDData *data)
Handle drop events.
Definition: TGListTree.cxx:778
virtual void ClearViewPort()
Clear view port and redraw full content.
Definition: TGCanvas.cxx:888
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2514
Bool_t fAutoCheckBoxPic
Definition: TGListTree.h:257
EKeySym
Definition: KeySymbols.h:27
TGListTreeItem * fCurrent
Definition: TGListTree.h:234
TGListTreeItem * fLast
Definition: TGListTree.h:232
virtual Int_t GetTextLength() const =0
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:1916
long Long_t
Definition: RtypesCore.h:50
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:168
TGListTreeItem * GetParent() const
Definition: TGListTree.h:79
Int_t fXDND
Definition: TGCanvas.h:72
Bool_t fEventHandled
Definition: TGListTree.h:260
ULong_t fBackground
Definition: GuiTypes.h:229
virtual void Layout()
Layout container entries.
Definition: TGListTree.h:311
#define ClassImp(name)
Definition: Rtypes.h:279
const Mask_t kGCFillStyle
Definition: GuiTypes.h:295
static Int_t init()
TText * text
virtual UInt_t GetPicWidth() const
Return width of item&#39;s icon.
Definition: TGListTree.cxx:99
UInt_t fDefw
Definition: TGListTree.h:246
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:163
UInt_t fCode
Definition: GuiTypes.h:181
TGListTreeItem * GetFirstChild() const
Definition: TGListTree.h:80
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition: TGClient.cxx:287
virtual void DrawActive(Handle_t id, TGListTreeItem *item)
Draw active item with its active color.
void Search(Bool_t close=kTRUE)
Invokes search dialog. Looks for item with the entered name.
virtual const TGPicture * GetCheckBoxPicture() const =0
Definition: TGFont.h:155
unsigned long ULong_t
Definition: RtypesCore.h:51
Int_t fDNDState
Definition: TGListTree.h:67
TGListTreeItem * FindSiblingByName(TGListTreeItem *item, const char *name)
Find sibling of item by name.
FontStruct_t GetFontStruct() const
Definition: TGFont.h:199
Double_t y[n]
Definition: legend1.C:17
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition: TGWindow.cxx:180
void PageUp(Bool_t select=kFALSE)
Move content one page up.
UInt_t GetWidth() const
Definition: TGPicture.h:73
const Mask_t kGCForeground
Definition: GuiTypes.h:289
UInt_t fHeight
Definition: TGFrame.h:151
virtual void WriteObject(const TObject *obj)
Write object to I/O buffer.
Int_t ReparentChildren(TGListTreeItem *item, TGListTreeItem *newparent)
Make newparent the new parent of the children of item.
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle double click event in the list tree (only for kButton1).
Definition: TGListTree.cxx:660
ECheckMode fCheckMode
Definition: TGListTree.h:264
Atom_t HandleDNDEnter(Atom_t *typelist)
Handle drag enter events.
Definition: TGListTree.cxx:755
static const TGPicture * fgOpenPic
Definition: TGListTree.h:274
const TGWindow * GetParent() const
Definition: TGWindow.h:87
Bool_t fUserControlled
Definition: TGListTree.h:259
TGListTreeItem * fBelowMouse
Definition: TGListTree.h:235
Bool_t IsNull() const
Definition: TString.h:387
Handle_t fId
Definition: TGObject.h:40
virtual void CheckAllChildren(Bool_t=kTRUE)
Definition: TGListTree.h:116
TGViewPort * fViewPort
Definition: TGCanvas.h:52
Int_t fMargin
Definition: TGListTree.h:239
void SetCheckBox(TGListTreeItem *item, Bool_t on=kTRUE)
Set check button state for the node &#39;item&#39;.
Bool_t Drag(Int_t x_root, Int_t y_root, Atom_t action, Time_t timestamp)
Process drag event.
virtual Bool_t IsOpen() const
Definition: TGListTree.h:85
Mother of all ROOT objects.
Definition: TObject.h:37
Int_t Sort(TGListTreeItem *item)
Sort items starting with item.
Int_t SearchChildren(TGListTreeItem *item, Int_t y, Int_t findy, TGListTreeItem **finditem)
Search child item.
void ToggleItem(TGListTreeItem *item)
Toggle check button state of the node &#39;item&#39;.
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:460
Int_t Reparent(TGListTreeItem *item, TGListTreeItem *newparent)
Make newparent the new parent of item.
Mask_t fMask
Definition: GuiTypes.h:252
virtual void Layout()
Create layout for canvas.
Definition: TGCanvas.cxx:2226
void KeyPressed(TGFrame *, UInt_t, UInt_t)
Signal emitted when keyboard key pressed.
Definition: TGListTree.h:321
TGListTreeItem * FindItemByPathname(const char *path)
Find item by pathname.
virtual Bool_t IsChecked() const
Definition: TGListTree.h:197
Int_t fVspacing
Definition: TGListTree.h:237
virtual void Add(TObject *obj)
Definition: TList.h:81
void AddReference()
Definition: TRefCnt.h:42
virtual Bool_t IsChecked() const =0
TGClient * fClient
Definition: TGObject.h:41
virtual void UpdateState()
Definition: TGListTree.h:120
static Pixel_t fgGrayPixel
Definition: TGListTree.h:267
const Mask_t kGCBackground
Definition: GuiTypes.h:290
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
Int_t fHspacing
Definition: TGListTree.h:236
Handle_t Pixmap_t
Definition: GuiTypes.h:31
TGListTreeItem * fNextsibling
Definition: TGListTree.h:63
Int_t fLineWidth
Definition: GuiTypes.h:230
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:232
virtual TList * GetVolumes(Option_t *) const
Definition: TSystem.h:445
void CloseItem(TGListTreeItem *item)
Close item in list tree (i.e. hide child items).
#define snprintf
Definition: civetweb.c:822
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
Int_t fAscent
Definition: TGFont.h:68
Atom_t HandleDNDPosition(Int_t x, Int_t y, Atom_t action, Int_t xroot, Int_t yroot)
Handle dragging position events.
Definition: TGListTree.cxx:729
UInt_t fState
Definition: GuiTypes.h:182
UInt_t fEditDisabled
Definition: TGWindow.h:47
Int_t FontAscent()
Returns ascent of currently used font.
Definition: TGListTree.cxx:500
static const TGGC & GetColorGC()
Return graphics context for highlighted frame background.
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition: TGFrame.cxx:2433
virtual void DoRedraw()
Redraw content of container in the viewport region.
Definition: TGCanvas.cxx:797
void SetDashOffset(Int_t v)
Patterned/dashed line offset.
Definition: TGGC.cxx:475
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2460
void GetFontMetrics(FontMetrics_t *m) const
Get font metrics.
Definition: TGFont.cxx:274
void SaveChildren(std::ostream &out, TGListTreeItem *item, Int_t &n)
Save child items as a C++ statements on output stream out.
void Reset()
Definition: TBufferFile.h:98
TGListTreeItem * fTipItem
Definition: TGListTree.h:251
void CheckItem(TGListTreeItem *item, Bool_t check=kTRUE)
Set check button state for the node &#39;item&#39;.
Bool_t StartDrag(TGFrame *src, Int_t x_root, Int_t y_root, Window_t grabWin=kNone)
Start dragging.
const Mask_t kKeyControlMask
Definition: GuiTypes.h:198
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1244
static const TGPicture * fgUncheckedPic
Definition: TGListTree.h:277
Definition: first.py:1
const TGPicture * fOpenPic
Definition: TGListTree.h:156
void HighlightItem(TGListTreeItem *item)
Highlight item.
TGListTreeItem * GetFirstItem() const
Definition: TGListTree.h:402
const Bool_t kTRUE
Definition: Rtypes.h:91
const Mask_t kAnyModifier
Definition: GuiTypes.h:211
virtual Int_t GetVsbPosition() const
Get position of vertical scrollbar.
Definition: TGCanvas.cxx:2381
Definition: TGGC.h:35
const Int_t n
Definition: legend1.C:16
TGVScrollBar * GetVScrollbar() const
Definition: TGCanvas.h:231
Int_t fX
Definition: GuiTypes.h:179
virtual void UpdateChecked(TGListTreeItem *item, Bool_t redraw=kFALSE)
Update the state of the node &#39;item&#39; according to the children states.
virtual void MouseOver(TGListTreeItem *entry)
Signal emitted when pointer is over entry.
static TGGC * fgColorGC
Definition: TGListTree.h:273
Int_t fExposeTop
Definition: TGListTree.h:248
static Pixel_t GetDefaultSelectedBackground()
Get default selected frame background.
Definition: TGFrame.cxx:678
char name[80]
Definition: TGX11.cxx:109
void DrawNode(Handle_t id, TGListTreeItem *item, Int_t x, Int_t y)
Draw node (little + in box).
Int_t RecursiveDeleteItem(TGListTreeItem *item, void *userData)
Delete item with fUserData == ptr.
void RenameItem(TGListTreeItem *item, const char *string)
Rename item in list tree.
void Home(Bool_t select=kFALSE)
Move content to the top.
void SetDashList(const char v[], Int_t len)
Set dash pattern. First use SetDashOffset() if not 0.
Definition: TGGC.cxx:486
virtual Bool_t HandleKey(Event_t *event)
The key press event handler converts a key press to some line editor action.
Definition: TGListTree.cxx:931
void LineUp(Bool_t select=kFALSE)
Move content one item-size up.
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:118
virtual void CheckChildren(TGListTreeItem *item, Bool_t state)
Set all child items of &#39;item&#39; checked if state=kTRUE; unchecked if state=kFALSE.
Definition: TGListTree.cxx:255
Definition: TGMsgBox.h:52
virtual const char * GetTipText() const =0
const TGPicture * fClosedPic
Definition: TGListTree.h:157
void End(Bool_t select=kFALSE)
Move content to the bottom.
virtual void DataDropped(TGListTreeItem *item, TDNDData *data)
Emit DataDropped() signal.
Definition: TGListTree.cxx:789
static TGGC * fgActiveGC
Definition: TGListTree.h:269
const char * Data() const
Definition: TString.h:349
FontH_t GetFontHandle() const
Definition: TGFont.h:198
ULong_t Handle_t
Definition: GuiTypes.h:27