61 #include "RConfigure.h"
63 Pixel_t TGListTree::fgGrayPixel = 0;
64 const TGFont *TGListTree::fgDefaultFont = 0;
65 TGGC *TGListTree::fgActiveGC = 0;
66 TGGC *TGListTree::fgDrawGC = 0;
67 TGGC *TGListTree::fgLineGC = 0;
68 TGGC *TGListTree::fgHighlightGC = 0;
69 TGGC *TGListTree::fgColorGC = 0;
70 const TGPicture *TGListTree::fgOpenPic = 0;
71 const TGPicture *TGListTree::fgClosedPic = 0;
72 const TGPicture *TGListTree::fgCheckedPic = 0;
73 const TGPicture *TGListTree::fgUncheckedPic = 0;
76 ClassImp(TGListTreeItem);
77 ClassImp(TGListTreeItemStd);
88 TGListTreeItem::TGListTreeItem(TGClient *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)
99 UInt_t TGListTreeItem::GetPicWidth()
const
101 const TGPicture *pic = GetPicture();
102 return (pic) ? pic->GetWidth() : 0;
113 TGListTreeItemStd::TGListTreeItemStd(TGClient *client,
const char *name,
114 const TGPicture *opened,
115 const TGPicture *closed,
117 TGListTreeItem(client)
120 fCheckBox = checkbox;
124 opened = TGListTree::GetOpenPic();
126 ((TGPicture *)opened)->AddReference();
129 closed = TGListTree::GetClosedPic();
131 ((TGPicture *)closed)->AddReference();
136 fCheckedPic = TGListTree::GetCheckedPic();
137 fUncheckedPic = TGListTree::GetUncheckedPic();
152 TGListTreeItemStd::~TGListTreeItemStd()
154 if (fOwnsData && fUserData) {
155 TObject *obj =
static_cast<TObject *
>(fUserData);
156 delete dynamic_cast<TObject *
>(obj);
158 fClient->FreePicture(fOpenPic);
159 fClient->FreePicture(fClosedPic);
160 fClient->FreePicture(fCheckedPic);
161 fClient->FreePicture(fUncheckedPic);
167 Pixel_t TGListTreeItemStd::GetActiveColor()
const
169 return TGFrame::GetDefaultSelectedBackground();
175 Bool_t TGListTreeItemStd::HasCheckedChild(Bool_t first)
177 TGListTreeItem *item =
this;
180 if (item->IsChecked()) {
183 if (item->GetFirstChild()) {
184 if (item->GetFirstChild()->HasCheckedChild())
188 item = item->GetNextSibling();
198 Bool_t TGListTreeItemStd::HasUnCheckedChild(Bool_t first)
200 TGListTreeItem *item =
this;
203 if (!item->IsChecked()) {
206 if (item->GetFirstChild()) {
207 if (item->GetFirstChild()->HasUnCheckedChild())
211 item = item->GetNextSibling();
221 void TGListTreeItemStd::UpdateState()
223 if ((!fChecked && HasCheckedChild(kTRUE)) ||
224 (fChecked && HasUnCheckedChild(kTRUE))) {
225 SetCheckBoxPictures(gClient->GetPicture(
"checked_dis_t.xpm"),
226 gClient->GetPicture(
"unchecked_dis_t.xpm"));
229 SetCheckBoxPictures(gClient->GetPicture(
"checked_t.xpm"),
230 gClient->GetPicture(
"unchecked_t.xpm"));
238 void TGListTreeItemStd::CheckAllChildren(Bool_t state)
247 CheckChildren(GetFirstChild(), state);
255 void TGListTreeItemStd::CheckChildren(TGListTreeItem *item, Bool_t state)
261 if (!item->IsChecked())
264 if (item->IsChecked())
267 if (item->GetFirstChild()) {
268 CheckChildren(item->GetFirstChild(), state);
271 item = item->GetNextSibling();
278 void TGListTreeItemStd::SetCheckBox(Bool_t on)
286 void TGListTreeItemStd::SetCheckBoxPictures(
const TGPicture *checked,
287 const TGPicture *unchecked)
289 fClient->FreePicture(fCheckedPic);
290 fClient->FreePicture(fUncheckedPic);
293 ::Warning(
"TGListTreeItem::SetCheckBoxPictures",
"checked picture not specified, defaulting to checked_t");
294 checked = fClient->GetPicture(
"checked_t.xpm");
296 ((TGPicture *)checked)->AddReference();
299 ::Warning(
"TGListTreeItem::SetCheckBoxPictures",
"unchecked picture not specified, defaulting to unchecked_t");
300 unchecked = fClient->GetPicture(
"unchecked_t.xpm");
302 ((TGPicture *)unchecked)->AddReference();
304 fCheckedPic = checked;
305 fUncheckedPic = unchecked;
311 void TGListTreeItemStd::SetPictures(
const TGPicture *opened,
const TGPicture *closed)
313 fClient->FreePicture(fOpenPic);
314 fClient->FreePicture(fClosedPic);
317 ::Warning(
"TGListTreeItem::SetPictures",
"opened picture not specified, defaulting to ofolder_t");
318 opened = fClient->GetPicture(
"ofolder_t.xpm");
320 ((TGPicture *)opened)->AddReference();
323 ::Warning(
"TGListTreeItem::SetPictures",
"closed picture not specified, defaulting to folder_t");
324 closed = fClient->GetPicture(
"folder_t.xpm");
326 ((TGPicture *)closed)->AddReference();
341 TGListTree::TGListTree(TGWindow *p, UInt_t w, UInt_t h, UInt_t options,
343 TGContainer(p, w, h, options, back)
350 fAutoCheckBoxPic = kTRUE;
351 fDisableOpen = kFALSE;
353 fUserControlled = kFALSE;
354 fEventHandled = kFALSE;
355 fExposeTop = fExposeBottom = 0;
359 fGrayPixel = GetGrayPixel();
360 fFont = GetDefaultFontStruct();
362 fActiveGC = GetActiveGC()();
363 fDrawGC = GetDrawGC()();
364 fLineGC = GetLineGC()();
365 fHighlightGC = GetHighlightGC()();
366 fColorGC = GetColorGC()();
368 fFirst = fLast = fSelected = fCurrent = fBelowMouse = 0;
378 fDNDData.fDataLength = 0;
379 fDNDData.fDataType = 0;
382 fColorMode = kDefault;
383 fCheckMode = kSimple;
384 if (fCanvas) fCanvas->GetVScrollbar()->SetSmallIncrement(20);
386 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
387 kButtonPressMask | kButtonReleaseMask,
390 AddInput(kPointerMotionMask | kEnterWindowMask |
391 kLeaveWindowMask | kKeyPressMask);
394 fDNDTypeList =
new Atom_t[3];
395 fDNDTypeList[0] = gVirtualX->InternAtom(
"application/root", kFALSE);
396 fDNDTypeList[1] = gVirtualX->InternAtom(
"text/uri-list", kFALSE);
398 gVirtualX->SetDNDAware(fId, fDNDTypeList);
400 fEditDisabled = kEditDisable | kEditDisableGrab | kEditDisableBtnEnable;
406 TGListTree::TGListTree(TGCanvas *p,UInt_t options,ULong_t back) :
407 TGContainer(p, options, back)
413 fAutoCheckBoxPic = kTRUE;
414 fDisableOpen = kFALSE;
416 fUserControlled = kFALSE;
417 fEventHandled = kFALSE;
418 fExposeTop = fExposeBottom = 0;
422 fGrayPixel = GetGrayPixel();
423 fFont = GetDefaultFontStruct();
425 fActiveGC = GetActiveGC()();
426 fDrawGC = GetDrawGC()();
427 fLineGC = GetLineGC()();
428 fHighlightGC = GetHighlightGC()();
429 fColorGC = GetColorGC()();
431 fFirst = fLast = fSelected = fCurrent = fBelowMouse = 0;
441 fDNDData.fDataLength = 0;
442 fDNDData.fDataType = 0;
445 fColorMode = kDefault;
446 fCheckMode = kSimple;
447 if (fCanvas) fCanvas->GetVScrollbar()->SetSmallIncrement(20);
449 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
450 kButtonPressMask | kButtonReleaseMask,
453 AddInput(kPointerMotionMask | kEnterWindowMask |
454 kLeaveWindowMask | kKeyPressMask);
457 fDNDTypeList =
new Atom_t[3];
458 fDNDTypeList[0] = gVirtualX->InternAtom(
"application/root", kFALSE);
459 fDNDTypeList[1] = gVirtualX->InternAtom(
"text/uri-list", kFALSE);
461 gVirtualX->SetDNDAware(fId, fDNDTypeList);
463 fEditDisabled = kEditDisable | kEditDisableGrab | kEditDisableBtnEnable;
469 TGListTree::~TGListTree()
471 TGListTreeItem *item, *sibling;
473 delete [] fDNDTypeList;
478 PDeleteChildren(item);
479 sibling = item->fNextsibling;
490 Int_t TGListTree::FontHeight()
493 fgDefaultFont = gClient->GetResourcePool()->GetIconFont();
494 return fgDefaultFont->TextHeight();
500 Int_t TGListTree::FontAscent()
504 fgDefaultFont = gClient->GetResourcePool()->GetIconFont();
505 fgDefaultFont->GetFontMetrics(&m);
512 Int_t TGListTree::TextWidth(
const char *c)
515 fgDefaultFont = gClient->GetResourcePool()->GetIconFont();
516 return fgDefaultFont->TextWidth(c);
524 void TGListTree::HighlightItem(TGListTreeItem *item, Bool_t state, Bool_t draw)
527 if ((item == fSelected) && !state) {
529 if (draw) DrawItemName(fId, item);
530 }
else if (state != item->IsActive()) {
531 item->SetActive(state);
532 if (draw) DrawItemName(fId, item);
540 void TGListTree::HighlightChildren(TGListTreeItem *item, Bool_t state, Bool_t draw)
543 HighlightItem(item, state, draw);
544 if (item->fFirstchild)
545 HighlightChildren(item->fFirstchild, state, (item->IsOpen()) ? draw : kFALSE);
546 item = item->fNextsibling;
553 void TGListTree::UnselectAll(Bool_t draw)
556 HighlightChildren(fFirst, kFALSE, draw);
562 Bool_t TGListTree::HandleButton(Event_t *event)
564 TGListTreeItem *item;
566 if (fTip) fTip->Hide();
569 if (event->fCode == kButton4 || event->fCode == kButton5) {
570 if (!fCanvas)
return kTRUE;
571 if (fCanvas->GetContainer()->GetHeight()) {
576 Int_t r = fCanvas->GetViewPort()->GetHeight() / 5;
577 page = TMath::Min(r, 90);
581 if (event->fCode == kButton4) {
583 Int_t newpos = fCanvas->GetVsbPosition() - page;
584 if (newpos < 0) newpos = 0;
585 fCanvas->SetVsbPosition(newpos);
588 if (event->fCode == kButton5) {
590 Int_t newpos = fCanvas->GetVsbPosition() + page;
591 fCanvas->SetVsbPosition(newpos);
595 if (event->fType == kButtonPress) {
596 if ((item = FindItem(event->fY)) != 0) {
597 if (event->fCode == kButton1) {
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;
607 maxx = (item->fXtext - Int_t(item->GetPicWidth())) - 8;
608 minx = (item->fXtext - Int_t(item->GetPicWidth())) - 16;
610 if ((item->HasCheckBox()) && (event->fX < maxxchk) &&
611 (
event->fX > minxchk))
614 if (fCheckMode == kRecursive) {
615 CheckAllChildren(item, item->IsChecked());
617 UpdateChecked(item, kTRUE);
618 Checked((TObject *)item->GetUserData(), item->IsChecked());
621 if ((event->fX < maxx) && (
event->fX > minx)) {
622 item->SetOpen(!item->IsOpen());
628 if (event->fCode == kButton1) {
633 if (!fUserControlled) {
634 if (fSelected) fSelected->SetActive(kFALSE);
637 fCurrent = fSelected = item;
638 HighlightItem(item, kTRUE, kTRUE);
639 SendMessage(fMsgWindow, MK_MSG(kC_LISTTREE, kCT_ITEMCLICK),
640 event->fCode, (event->fYRoot << 16) | event->fXRoot);
643 fCurrent = fSelected = item;
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);
651 if (event->fType == kButtonRelease) {
660 Bool_t TGListTree::HandleDoubleClick(Event_t *event)
662 TGListTreeItem *item = 0;
664 if (event->fCode == kButton4 || event->fCode == kButton5) {
669 if (fDisableOpen && event->fCode == kButton1 && (item = FindItem(event->fY)) != 0) {
670 SendMessage(fMsgWindow, MK_MSG(kC_LISTTREE, kCT_ITEMDBLCLICK),
671 event->fCode, (event->fYRoot << 16) | event->fXRoot);
672 DoubleClicked(item, event->fCode);
673 DoubleClicked(item, event->fCode, event->fXRoot, event->fYRoot);
676 item = FindItem(event->fY);
679 if (event->fCode == kButton1 && item) {
681 item->SetOpen(!item->IsOpen());
682 if (!fUserControlled) {
683 if (item != fSelected) {
684 if (fSelected) fSelected->SetActive(kFALSE);
686 HighlightItem(item, kTRUE, kTRUE);
689 SendMessage(fMsgWindow, MK_MSG(kC_LISTTREE, kCT_ITEMDBLCLICK),
690 event->fCode, (event->fYRoot << 16) | event->fXRoot);
691 DoubleClicked(item, event->fCode);
692 DoubleClicked(item, event->fCode, event->fXRoot, event->fYRoot);
694 if (!fUserControlled)
702 Bool_t TGListTree::HandleCrossing(Event_t *event)
704 if (event->fType == kLeaveNotify) {
709 if (!fUserControlled) {
711 DrawOutline(fId, fCurrent, 0xffffff, kTRUE);
713 DrawOutline(fId, fBelowMouse, 0xffffff, kTRUE);
719 MouseOver(0, event->fState);
729 Atom_t TGListTree::HandleDNDPosition(Int_t , Int_t y, Atom_t action,
732 static TGListTreeItem *olditem = 0;
733 TGListTreeItem *item;
734 if ((item = FindItem(y)) != 0) {
735 if (item->IsDNDTarget()) {
738 HighlightItem(olditem, kFALSE, kTRUE);
739 HighlightItem(item, kTRUE, kTRUE);
746 HighlightItem(olditem, kFALSE, kTRUE);
755 Atom_t TGListTree::HandleDNDEnter(Atom_t *typelist)
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];
770 Bool_t TGListTree::HandleDNDLeave()
778 Bool_t TGListTree::HandleDNDDrop(TDNDData *data)
780 DataDropped(fDropItem, data);
781 HighlightItem(fDropItem, kFALSE, kTRUE);
789 void TGListTree::DataDropped(TGListTreeItem *item, TDNDData *data)
793 args[0] = (Long_t)item;
794 args[1] = (Long_t)data;
796 Emit(
"DataDropped(TGListTreeItem*,TDNDData*)", args);
803 Bool_t TGListTree::HandleMotion(Event_t *event)
805 TGListTreeItem *item;
806 TGPosition pos = GetPagePosition();
808 if (gDNDManager->IsDragging()) {
809 gDNDManager->Drag(event->fXRoot, event->fYRoot,
810 TGDNDManager::GetDNDActionCopy(), event->fTime);
811 }
else if ((item = FindItem(event->fY)) != 0) {
812 if (!fUserControlled) {
814 DrawOutline(fId, fCurrent, 0xffffff, kTRUE);
816 DrawOutline(fId, fBelowMouse, 0xffffff, kTRUE);
817 DrawOutline(fId, item);
820 if (item != fBelowMouse) {
822 MouseOver(fBelowMouse);
823 MouseOver(fBelowMouse, event->fState);
826 if (item->HasCheckBox() && item->GetCheckBoxPicture()) {
827 if ((event->fX < (item->fXtext - 4) &&
828 (event->fX > (item->fXtext - (Int_t)item->GetCheckBoxPicture()->GetWidth()))))
830 gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kPointer));
834 gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kHand));
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);
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);
849 TString& str = ostr->String();
850 if (str.BeginsWith(
"file://")) {
851 fDNDData.fDataType = fDNDTypeList[1];
852 fDNDData.fData = (
void *)strdup(str.Data());
853 fDNDData.fDataLength = str.Length()+1;
857 fDNDData.fDataType = fDNDTypeList[0];
858 fBuf->WriteObject((TObject *)item->GetUserData());
859 fDNDData.fData = fBuf->Buffer();
860 fDNDData.fDataLength = fBuf->Length();
865 fDNDData.fDataType = fDNDTypeList[1];
866 TString str = TString::Format(
"file://%s/%s\r\n",
867 gSystem->UnixPathName(gSystem->WorkingDirectory()),
869 fDNDData.fData = (
void *)strdup(str.Data());
870 fDNDData.fDataLength = str.Length()+1;
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);
882 gDNDManager->StartDrag(
this, event->fXRoot, event->fYRoot);
886 if (gDNDManager->IsDragging()) {
887 gDNDManager->Drag(event->fXRoot, event->fYRoot,
888 TGDNDManager::GetDNDActionCopy(), event->fTime);
890 if (fTipItem == item)
return kTRUE;
891 if (!fUserControlled) {
893 MouseOver(item, event->fState);
895 gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kHand));
901 if (item->GetTipTextLength() > 0) {
903 SetToolTipText(item->GetTipText(), item->fXtext,
904 item->fY - pos.fY + item->fHeight, 1000);
906 }
else if (fAutoTips && item->GetUserData()) {
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);
919 MouseOver(fBelowMouse);
920 MouseOver(fBelowMouse, event->fState);
922 gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kPointer));
931 Bool_t TGListTree::HandleKey(Event_t *event)
935 TGListTreeItem *item = 0;
937 fLastEventState =
event->fState;
938 if (fTip) fTip->Hide();
940 if (event->fType == kGKeyPress) {
941 gVirtualX->LookupString(event, input,
sizeof(input), keysym);
943 if (!event->fState && (EKeySym)keysym == kKey_Escape) {
944 if (gDNDManager->IsDragging()) gDNDManager->EndDrag();
948 if (!item)
return kFALSE;
950 fEventHandled = kFALSE;
951 KeyPressed(item, keysym, event->fState);
953 if (fUserControlled && fEventHandled)
956 switch ((EKeySym)keysym) {
959 event->fType = kButtonPress;
960 event->fCode = kButton1;
962 if (fSelected == item) {
965 item->SetOpen(!item->IsOpen());
966 DoubleClicked(item, 1);
969 if (fSelected) fSelected->SetActive(kFALSE);
973 fSelected->SetActive(kTRUE);
974 HighlightItem(item, kTRUE, kTRUE);
976 Clicked(item, 1, event->fXRoot, event->fYRoot);
977 Clicked(item, 1, event->fState, event->fXRoot, event->fYRoot);
981 if (item->HasCheckBox()) {
983 if (fCheckMode == kRecursive) {
984 CheckAllChildren(item, item->IsChecked());
986 UpdateChecked(item, kTRUE);
987 Checked((TObject *)item->GetUserData(), item->IsChecked());
1001 item->SetOpen(kFALSE);
1005 item->SetOpen(kTRUE);
1008 LineUp(event->fState & kKeyShiftMask);
1011 LineDown(event->fState & kKeyShiftMask);
1014 PageUp(event->fState & kKeyShiftMask);
1017 PageDown(event->fState & kKeyShiftMask);
1020 Home(event->fState & kKeyShiftMask);
1023 End(event->fState & kKeyShiftMask);
1028 if (event->fState & kKeyControlMask) {
1029 switch((EKeySym)keysym & ~0x20) {
1048 void TGListTree::MouseOver(TGListTreeItem *entry)
1050 Emit(
"MouseOver(TGListTreeItem*)", (Long_t)entry);
1056 void TGListTree::MouseOver(TGListTreeItem *entry, UInt_t mask)
1059 args[0] = (Long_t)entry;
1061 Emit(
"MouseOver(TGListTreeItem*,UInt_t)", args);
1082 void TGListTree::KeyPressed(TGListTreeItem *entry, UInt_t keysym, UInt_t mask)
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);
1095 void TGListTree::ReturnPressed(TGListTreeItem *entry)
1097 Emit(
"ReturnPressed(TGListTreeItem*)", (Long_t)entry);
1103 void TGListTree::Checked(TObject *entry, Bool_t on)
1107 args[0] = (Long_t)entry;
1110 Emit(
"Checked(TObject*,Bool_t)", args);
1116 void TGListTree::Clicked(TGListTreeItem *entry, Int_t btn)
1120 args[0] = (Long_t)entry;
1123 Emit(
"Clicked(TGListTreeItem*,Int_t)", args);
1129 void TGListTree::Clicked(TGListTreeItem *entry, Int_t btn, Int_t x, Int_t y)
1133 args[0] = (Long_t)entry;
1138 Emit(
"Clicked(TGListTreeItem*,Int_t,Int_t,Int_t)", args);
1144 void TGListTree::Clicked(TGListTreeItem *entry, Int_t btn, UInt_t mask, Int_t x, Int_t y)
1148 args[0] = (Long_t)entry;
1154 Emit(
"Clicked(TGListTreeItem*,Int_t,UInt_t,Int_t,Int_t)", args);
1160 void TGListTree::DoubleClicked(TGListTreeItem *entry, Int_t btn)
1164 args[0] = (Long_t)entry;
1167 Emit(
"DoubleClicked(TGListTreeItem*,Int_t)", args);
1173 void TGListTree::DoubleClicked(TGListTreeItem *entry, Int_t btn, Int_t x, Int_t y)
1177 args[0] = (Long_t)entry;
1182 Emit(
"DoubleClicked(TGListTreeItem*,Int_t,Int_t,Int_t)", args);
1188 void TGListTree::Home(Bool_t )
1190 if (fCanvas) fCanvas->SetVsbPosition(0);
1196 void TGListTree::End(Bool_t )
1198 if (fCanvas) fCanvas->SetVsbPosition((Int_t)fHeight);
1204 void TGListTree::PageUp(Bool_t )
1206 if (!fCanvas)
return;
1208 TGDimension dim = GetPageDimension();
1210 Int_t newpos = fCanvas->GetVsbPosition() - dim.fHeight;
1211 if (newpos<0) newpos = 0;
1213 fCanvas->SetVsbPosition(newpos);
1219 void TGListTree::PageDown(Bool_t )
1221 if (!fCanvas)
return;
1223 TGDimension dim = GetPageDimension();
1225 Int_t newpos = fCanvas->GetVsbPosition() + dim.fHeight;
1227 fCanvas->SetVsbPosition(newpos);
1233 void TGListTree::LineUp(Bool_t )
1236 if (!fCurrent)
return;
1238 TGPosition pos = GetPagePosition();
1239 const TGPicture *pic1 = fCurrent->GetPicture();
1240 if (pic1) height = pic1->GetHeight() + fVspacing;
1241 else height = fVspacing + 16;
1242 Int_t findy = (fCurrent->fY - height) + (fMargin - pos.fY);
1243 TGListTreeItem *next = FindItem(findy);
1244 if (next && (next != fCurrent)) {
1245 DrawOutline(fId, fCurrent, 0xffffff, kTRUE);
1246 if (findy <= 2*height) {
1247 Int_t newpos = fCanvas->GetVsbPosition() - height;
1248 if (newpos<0) newpos = 0;
1249 fCanvas->SetVsbPosition(newpos);
1251 DrawOutline(fId, next);
1259 void TGListTree::LineDown(Bool_t )
1262 if (!fCurrent)
return;
1264 TGDimension dim = GetPageDimension();
1265 TGPosition pos = GetPagePosition();
1266 const TGPicture *pic1 = fCurrent->GetPicture();
1267 if (pic1) height = pic1->GetHeight() + fVspacing;
1268 else height = fVspacing + 16;
1269 Int_t findy = (fCurrent->fY + height) + (fMargin - pos.fY);
1270 TGListTreeItem *next = FindItem(findy);
1271 if (next && (next != fCurrent)) {
1272 DrawOutline(fId, fCurrent, 0xffffff, kTRUE);
1273 if (findy >= ((Int_t)dim.fHeight - 2*height)) {
1274 Int_t newpos = fCanvas->GetVsbPosition() + height;
1275 if (newpos<0) newpos = 0;
1276 fCanvas->SetVsbPosition(newpos);
1278 DrawOutline(fId, next);
1287 void TGListTree::AdjustPosition(TGListTreeItem *item)
1289 TGListTreeItem *it = item;
1291 if (!it) it = fSelected;
1293 HighlightItem(fFirst);
1304 if (it->GetParent()) yparent = it->GetParent()->fY;
1307 if (y==0) y = yparent;
1309 if (fCanvas->GetVScrollbar()->IsMapped()) {
1310 vh = fCanvas->GetVScrollbar()->GetPosition()+(Int_t)fViewPort->GetHeight();
1312 if (y<fCanvas->GetVScrollbar()->GetPosition()) {
1313 v = TMath::Max(0,y-(Int_t)fViewPort->GetHeight()/2);
1314 fCanvas->SetVsbPosition(v);
1315 }
else if (y+(Int_t)it->fHeight>vh) {
1316 v = TMath::Min((Int_t)GetHeight()-(Int_t)fViewPort->GetHeight(),
1317 y+(Int_t)it->fHeight-(Int_t)fViewPort->GetHeight()/2);
1319 fCanvas->SetVsbPosition(v);
1327 void TGListTree::Search(Bool_t close)
1333 TGSearchType *srch =
new TGSearchType;
1334 srch->fBuffer = (
char *)StrDup(buf.Data());
1336 TGListTreeItem *item;
1337 if (close || buf.IsNull())
1338 new TGSearchDialog(fClient->GetDefaultRoot(), fCanvas, 400, 150, srch, &ret);
1339 else if (!buf.IsNull()) ret = 1;
1342 item = FindItemByPathname(srch->fBuffer);
1344 snprintf(msg, 255,
"Couldn't find \"%s\"", srch->fBuffer);
1345 gVirtualX->Bell(20);
1346 new TGMsgBox(fClient->GetDefaultRoot(), fCanvas,
"Container", msg,
1347 kMBIconExclamation, kMBOk, 0);
1350 HighlightItem(item);
1353 buf = srch->fBuffer;
1362 void TGListTree::DrawRegion(Int_t , Int_t y, UInt_t , UInt_t h)
1364 static GContext_t gcBg = 0;
1367 if (y > (Int_t)fViewPort->GetHeight()) {
1372 UInt_t w = fViewPort->GetWidth();
1375 if (((Int_t)w < 1) || (w > 32768) || ((Int_t)h < 1)) {
1379 Pixmap_t pixmap = gVirtualX->CreatePixmap(fId, w, fViewPort->GetHeight());
1382 GCValues_t gcValues;
1383 gcValues.fForeground = fBackground;
1384 gcValues.fForeground = fBackground;
1385 gcValues.fGraphicsExposures = kTRUE;
1386 gcValues.fMask = kGCForeground | kGCBackground | kGCGraphicsExposures;
1387 gcBg = gVirtualX->CreateGC(fId, &gcValues);
1390 gVirtualX->SetForeground(gcBg, fBackground);
1391 gVirtualX->FillRectangle(pixmap, gcBg, 0, 0, w, fViewPort->GetHeight());
1393 Draw(pixmap, 0, fViewPort->GetHeight());
1395 gVirtualX->CopyArea(pixmap, fId, gcBg, 0, y, w, fViewPort->GetHeight(), 0, y);
1397 gVirtualX->DeletePixmap(pixmap);
1398 gVirtualX->Update(kFALSE);
1404 void TGListTree::Draw(Handle_t
id, Int_t yevent, Int_t hevent)
1406 TGListTreeItem *item;
1407 Int_t x, y, xbranch;
1408 UInt_t width, height, old_width, old_height;
1412 fExposeTop = yevent - FontHeight();
1413 fExposeBottom = yevent + hevent + FontHeight();
1418 TGPosition pos = GetPagePosition();
1426 DrawItem(
id, item, x, y, &xbranch, &width, &height);
1428 width += pos.fX + x + fHspacing + fMargin;
1430 if (width > fDefw) fDefw = width;
1432 y += height + fVspacing;
1433 if (item->fFirstchild && item->IsOpen()) {
1434 y = DrawChildren(
id, item->fFirstchild, x, y, xbranch);
1437 item = item->fNextsibling;
1440 fDefh = y + fMargin;
1442 if ((old_width != fDefw) || (old_height != fDefh)) {
1450 Int_t TGListTree::DrawChildren(Handle_t
id, TGListTreeItem *item,
1451 Int_t x, Int_t y, Int_t xroot)
1453 UInt_t width, height;
1455 TGPosition pos = GetPagePosition();
1457 x += fIndent + (Int_t)item->fParent->GetPicWidth();
1461 DrawItem(
id, item, x, y, &xbranch, &width, &height);
1463 width += pos.fX + x + fHspacing + fMargin;
1464 if (width > fDefw) fDefw = width;
1466 y += height + fVspacing;
1467 if ((item->fFirstchild) && (item->IsOpen())) {
1468 y = DrawChildren(
id, item->fFirstchild, x, y, xbranch);
1471 item = item->fNextsibling;
1479 void TGListTree::DrawItem(Handle_t
id, TGListTreeItem *item, Int_t x, Int_t y,
1480 Int_t *xroot, UInt_t *retwidth, UInt_t *retheight)
1482 Int_t xpic1, ypic1, xbranch, ybranch, xtext, ytext = 0, xline, yline, xc;
1485 const TGPicture *pic1 = item->GetPicture();
1486 const TGPicture *pic2 = item->GetCheckBoxPicture();
1489 height = FontHeight();
1493 xtext = x + fHspacing + (Int_t)item->GetPicWidth();
1495 if (pic2->GetHeight() > height) {
1496 ytext = y + (Int_t)((pic2->GetHeight() - height) >> 1);
1497 height = pic2->GetHeight();
1501 if (pic1) xpic2 = xpic1 + pic1->GetWidth() + 1;
1502 else xpic2 = xpic1 + 1;
1503 xtext += pic2->GetWidth();
1509 if (pic1->GetHeight() > height) {
1510 ytext = y + (Int_t)((pic1->GetHeight() - height) >> 1);
1511 height = pic1->GetHeight();
1518 ypic1 = y + (Int_t)((height - pic1->GetHeight()) >> 1);
1520 xbranch = xpic1 + (Int_t)(pic1->GetWidth() >> 1);
1521 ybranch = ypic1 + (Int_t)pic1->GetHeight();
1522 yline = ypic1 + (Int_t)(pic1->GetHeight() >> 1);
1523 if (xline == 0) xline = xpic1;
1525 if (xline == 0) xline = xpic1;
1527 xbranch = xpic1 + (Int_t)(item->GetPicWidth() >> 1);
1528 yline = ybranch = ypic1 + (Int_t)(height >> 1);
1529 yline = ypic1 + (Int_t)(height >> 1);
1537 item->fXtext = xtext;
1538 item->fYtext = ytext;
1539 item->fHeight = height;
1542 TGPosition pos = GetPagePosition();
1543 TGDimension dim = GetPageDimension();
1544 Int_t yp = y - pos.fY;
1545 Int_t ylinep = yline - pos.fY;
1546 Int_t ybranchp = ybranch - pos.fY;
1547 Int_t ypicp = ypic1 - pos.fY;
1549 if ((yp >= fExposeTop) && (yp <= (Int_t)dim.fHeight))
1551 DrawItemName(
id, item);
1555 if (item->fNextsibling) {
1556 gVirtualX->DrawLine(
id, fLineGC, xc, yp, xc, yp+height);
1558 gVirtualX->DrawLine(
id, fLineGC, xc, yp, xc, ylinep);
1561 TGListTreeItem *p = item->fParent;
1563 xc -= (fIndent + (Int_t)item->GetPicWidth());
1564 if (p->fNextsibling) {
1565 gVirtualX->DrawLine(
id, fLineGC, xc, yp, xc, yp+height);
1569 gVirtualX->DrawLine(
id, fLineGC, *xroot, ylinep, xpic1, ylinep);
1570 DrawNode(
id, item, *xroot, yline);
1572 if (item->IsOpen() && item->fFirstchild) {
1573 gVirtualX->DrawLine(
id, fLineGC, xbranch, ybranchp, xbranch,
1577 pic1->Draw(
id, fDrawGC, xpic1, ypicp);
1579 pic2->Draw(
id, fDrawGC, xpic2, ypicp);
1583 *retwidth = TextWidth(item->GetText()) + item->GetPicWidth();
1584 *retheight = height;
1590 void TGListTree::DrawOutline(Handle_t
id, TGListTreeItem *item, Pixel_t col,
1593 TGPosition pos = GetPagePosition();
1594 TGDimension dim = GetPageDimension();
1597 gVirtualX->SetForeground(fDrawGC, fCanvas->GetContainer()->GetBackground());
1601 gVirtualX->SetForeground(fDrawGC, col);
1604 gVirtualX->DrawRectangle(
id, fDrawGC, 1, item->fY - pos.fY, dim.fWidth-2, item->fHeight + 1);
1606 gVirtualX->DrawRectangle(
id, fDrawGC, 1, item->fYtext-pos.fY-2,
1607 dim.fWidth-3, FontHeight()+4);
1609 gVirtualX->SetForeground(fDrawGC, fgBlackPixel);
1615 void TGListTree::DrawActive(Handle_t
id, TGListTreeItem *item)
1618 TGPosition pos = GetPagePosition();
1619 TGDimension dim = GetPageDimension();
1621 width = dim.fWidth-2;
1622 gVirtualX->SetForeground(fDrawGC, item->GetActiveColor());
1625 gVirtualX->FillRectangle(
id, fDrawGC, 1, item->fY - pos.fY, width, item->fHeight + 1);
1627 gVirtualX->FillRectangle(
id, fDrawGC, 1, item->fYtext-pos.fY-1, width,
1630 gVirtualX->SetForeground(fDrawGC, fgBlackPixel);
1631 gVirtualX->DrawString(
id, fActiveGC, item->fXtext,
1632 item->fYtext - pos.fY + FontAscent(),
1633 item->GetText(), item->GetTextLength());
1639 void TGListTree::DrawItemName(Handle_t
id, TGListTreeItem *item)
1641 TGPosition pos = GetPagePosition();
1642 TGDimension dim = GetPageDimension();
1644 if (item->IsActive()) {
1645 DrawActive(
id, item);
1648 gVirtualX->FillRectangle(
id, fHighlightGC, item->fXtext,
1649 item->fYtext-pos.fY, dim.fWidth-item->fXtext-2,
1651 gVirtualX->DrawString(
id, fDrawGC,
1652 item->fXtext, item->fYtext-pos.fY + FontAscent(),
1653 item->GetText(), item->GetTextLength());
1655 if (item == fCurrent) {
1656 DrawOutline(
id, item);
1659 if (fColorMode != 0 && item->HasColor()) {
1660 UInt_t width = TextWidth(item->GetText());
1661 gVirtualX->SetForeground(fColorGC, TColor::Number2Pixel(item->GetColor()));
1662 if (fColorMode & kColorUnderline) {
1663 Int_t y = item->fYtext-pos.fY + FontAscent() + 2;
1664 gVirtualX->DrawLine(
id, fColorGC, item->fXtext, y,
1665 item->fXtext + width, y);
1667 if (fColorMode & kColorBox) {
1668 Int_t x = item->fXtext + width + 4;
1669 Int_t y = item->fYtext - pos.fY + 3;
1670 Int_t h = FontAscent() - 4;
1671 gVirtualX->FillRectangle(
id, fColorGC, x, y, h, h);
1672 gVirtualX->DrawRectangle(
id, fDrawGC, x, y, h, h);
1680 void TGListTree::DrawNode(Handle_t
id, TGListTreeItem *item, Int_t x, Int_t y)
1682 TGPosition pos = GetPagePosition();
1683 Int_t yp = y - pos.fY;
1685 if (item->fFirstchild) {
1686 gVirtualX->DrawLine(
id, fHighlightGC, x, yp-2, x, yp+2);
1687 gVirtualX->SetForeground(fHighlightGC, fgBlackPixel);
1688 gVirtualX->DrawLine(
id, fHighlightGC, x-2, yp, x+2, yp);
1689 if (!item->IsOpen())
1690 gVirtualX->DrawLine(
id, fHighlightGC, x, yp-2, x, yp+2);
1691 gVirtualX->SetForeground(fHighlightGC, fGrayPixel);
1692 gVirtualX->DrawLine(
id, fHighlightGC, x-4, yp-4, x+4, yp-4);
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->SetForeground(fHighlightGC, fgWhitePixel);
1706 void TGListTree::SetToolTipText(
const char *text, Int_t x, Int_t y, Long_t delayms)
1714 if (text && strlen(text)) {
1716 fTip =
new TGToolTip(fClient->GetDefaultRoot(),
this, text, delayms);
1718 fTip->SetText(text);
1719 fTip->SetPosition(x, y);
1728 void TGListTree::RemoveReference(TGListTreeItem *item)
1733 if (item->fPrevsibling) {
1734 item->fPrevsibling->fNextsibling = item->fNextsibling;
1737 item->fParent->fFirstchild = item->fNextsibling;
1739 fFirst = item->fNextsibling;
1742 if (item->fNextsibling) {
1743 item->fNextsibling->fPrevsibling = item->fPrevsibling;
1746 item->fParent->fLastchild = item->fPrevsibling;
1748 fLast = item->fPrevsibling;
1756 void TGListTree::PDeleteItem(TGListTreeItem *item)
1758 if (fSelected == item) {
1761 if (fCurrent == item) {
1762 DrawOutline(fId, fCurrent, 0xffffff, kTRUE);
1763 fCurrent = item->GetPrevSibling();
1765 fCurrent = item->GetNextSibling();
1767 fCurrent = item->GetParent();
1770 if (fBelowMouse == item) {
1771 DrawOutline(fId, fBelowMouse, 0xffffff, kTRUE);
1774 MouseOver(0,fLastEventState);
1783 void TGListTree::PDeleteChildren(TGListTreeItem *item)
1785 TGListTreeItem *child = item->fFirstchild;
1788 TGListTreeItem *next = child->fNextsibling;
1789 PDeleteChildren(child);
1794 item->fFirstchild = item->fLastchild = 0;
1800 void TGListTree::InsertChild(TGListTreeItem *parent, TGListTreeItem *item)
1804 item->fParent = parent;
1805 item->fNextsibling = item->fPrevsibling = 0;
1809 if (parent->fFirstchild) {
1810 if (parent->fLastchild) {
1811 i = parent->fLastchild;
1814 i = parent->fFirstchild;
1815 while (i->fNextsibling) i = i->fNextsibling;
1817 i->fNextsibling = item;
1818 item->fPrevsibling = i;
1820 parent->fFirstchild = item;
1822 parent->fLastchild = item;
1832 while (i->fNextsibling) i = i->fNextsibling;
1834 i->fNextsibling = item;
1835 item->fPrevsibling = i;
1841 if (item->HasCheckBox())
1842 UpdateChecked(item);
1848 void TGListTree::InsertChildren(TGListTreeItem *parent, TGListTreeItem *item)
1850 TGListTreeItem *next, *newnext;
1860 next = item->fNextsibling;
1863 InsertChild(parent, item);
1867 newnext = item->fNextsibling;
1870 item->fNextsibling = next;
1875 while (item->fNextsibling) {
1876 item->fParent = parent;
1877 item = item->fNextsibling;
1881 item->fNextsibling = newnext;
1883 newnext->fPrevsibling = item;
1889 Int_t TGListTree::SearchChildren(TGListTreeItem *item, Int_t y, Int_t findy,
1890 TGListTreeItem **finditem)
1893 const TGPicture *pic;
1897 pic = item->GetPicture();
1900 height = FontHeight();
1901 if (pic && pic->GetHeight() > height)
1902 height = pic->GetHeight();
1904 if ((findy >= y) && (findy <= y + (Int_t)height)) {
1909 y += (Int_t)height + fVspacing;
1910 if (item->fFirstchild && item->IsOpen()) {
1911 y = SearchChildren(item->fFirstchild, y, findy, finditem);
1912 if (*finditem)
return -1;
1915 item = item->fNextsibling;
1924 TGListTreeItem *TGListTree::FindItem(Int_t findy)
1928 TGListTreeItem *item, *finditem;
1929 const TGPicture *pic;
1930 TGPosition pos = GetPagePosition();
1932 y = fMargin - pos.fY;
1935 while (item && !finditem) {
1937 pic = item->GetPicture();
1940 height = FontHeight();
1941 if (pic && (pic->GetHeight() > height))
1942 height = pic->GetHeight();
1944 if ((findy >= y) && (findy <= y + (Int_t)height))
1947 y += (Int_t)height + fVspacing;
1948 if ((item->fFirstchild) && (item->IsOpen())) {
1949 y = SearchChildren(item->fFirstchild, y, findy, &finditem);
1952 item = item->fNextsibling;
1963 void TGListTree::AddItem(TGListTreeItem *parent, TGListTreeItem *item)
1965 InsertChild(parent, item);
1967 if ((parent == 0) || (parent && parent->IsOpen()))
1974 TGListTreeItem *TGListTree::AddItem(TGListTreeItem *parent,
const char *
string,
1975 const TGPicture *open,
const TGPicture *closed,
1978 TGListTreeItem *item;
1980 item =
new TGListTreeItemStd(fClient,
string, open, closed, checkbox);
1981 InsertChild(parent, item);
1983 if ((parent == 0) || (parent && parent->IsOpen()))
1992 TGListTreeItem *TGListTree::AddItem(TGListTreeItem *parent,
const char *
string,
1993 void *userData,
const TGPicture *open,
1994 const TGPicture *closed,
1997 TGListTreeItem *item = FindChildByData(parent, userData);
1999 item = AddItem(parent,
string, open, closed, checkbox);
2000 if (item) item->SetUserData(userData);
2009 void TGListTree::RenameItem(TGListTreeItem *item,
const char *
string)
2012 item->Rename(
string);
2021 Int_t TGListTree::DeleteItem(TGListTreeItem *item)
2023 if (!fUserControlled)
2024 fCurrent = fBelowMouse = 0;
2026 PDeleteChildren(item);
2027 RemoveReference(item);
2030 fClient->NeedRedraw(
this);
2038 void TGListTree::OpenItem(TGListTreeItem *item)
2041 item->SetOpen(kTRUE);
2043 AdjustPosition(item);
2050 void TGListTree::CloseItem(TGListTreeItem *item)
2053 item->SetOpen(kFALSE);
2055 AdjustPosition(item);
2063 Int_t TGListTree::RecursiveDeleteItem(TGListTreeItem *item,
void *ptr)
2066 if (item->GetUserData() == ptr) {
2069 if (item->IsOpen() && item->fFirstchild) {
2070 RecursiveDeleteItem(item->fFirstchild, ptr);
2072 RecursiveDeleteItem(item->fNextsibling, ptr);
2083 void TGListTree::SetToolTipItem(TGListTreeItem *item,
const char *
string)
2086 item->SetTipText(
string);
2093 Int_t TGListTree::DeleteChildren(TGListTreeItem *item)
2095 if (!fUserControlled)
2096 fCurrent = fBelowMouse = 0;
2098 PDeleteChildren(item);
2108 Int_t TGListTree::Reparent(TGListTreeItem *item, TGListTreeItem *newparent)
2111 RemoveReference(item);
2114 InsertChild(newparent, item);
2124 Int_t TGListTree::ReparentChildren(TGListTreeItem *item,
2125 TGListTreeItem *newparent)
2127 TGListTreeItem *first;
2129 if (item->fFirstchild) {
2130 first = item->fFirstchild;
2131 item->fFirstchild = 0;
2133 InsertChildren(newparent, first);
2144 Int_t Compare(
const void *item1,
const void *item2)
2146 return strcmp((*((TGListTreeItem **) item1))->GetText(),
2147 (*((TGListTreeItem **) item2))->GetText());
2153 Int_t TGListTree::Sort(TGListTreeItem *item)
2155 TGListTreeItem *first, *parent, **list;
2159 while (item->fPrevsibling) item = item->fPrevsibling;
2162 parent = first->fParent;
2166 while (item->fNextsibling) item = item->fNextsibling, count++;
2167 if (count <= 1)
return 1;
2169 list =
new TGListTreeItem* [count];
2172 while (first->fNextsibling) {
2173 list[count] = first->fNextsibling;
2175 first = first->fNextsibling;
2178 ::qsort(list, count,
sizeof(TGListTreeItem*), ::Compare);
2180 list[0]->fPrevsibling = 0;
2181 for (i = 0; i < count; i++) {
2183 list[i]->fNextsibling = list[i + 1];
2185 list[i]->fPrevsibling = list[i - 1];
2187 list[count - 1]->fNextsibling = 0;
2189 parent->fFirstchild = list[0];
2190 parent->fLastchild = list[count-1];
2194 fLast = list[count-1];
2207 Int_t TGListTree::SortSiblings(TGListTreeItem *item)
2215 Int_t TGListTree::SortChildren(TGListTreeItem *item)
2217 TGListTreeItem *first;
2220 first = item->fFirstchild;
2222 SortSiblings(first);
2226 first = fFirst->fFirstchild;
2228 SortSiblings(first);
2239 TGListTreeItem *TGListTree::FindSiblingByName(TGListTreeItem *item,
const char *name)
2243 while (item->fPrevsibling) {
2244 item = item->fPrevsibling;
2248 if (strcmp(item->GetText(), name) == 0) {
2251 item = item->fNextsibling;
2261 TGListTreeItem *TGListTree::FindSiblingByData(TGListTreeItem *item,
void *userData)
2265 while (item->fPrevsibling) {
2266 item = item->fPrevsibling;
2270 if (item->GetUserData() == userData) {
2273 item = item->fNextsibling;
2283 TGListTreeItem *TGListTree::FindChildByName(TGListTreeItem *item,
const char *name)
2286 if (item && item->fFirstchild) {
2287 item = item->fFirstchild;
2288 }
else if (!item && fFirst) {
2295 if (strcmp(item->GetText(), name) == 0) {
2298 item = item->fNextsibling;
2306 TGListTreeItem *TGListTree::FindChildByData(TGListTreeItem *item,
void *userData)
2309 if (item && item->fFirstchild) {
2310 item = item->fFirstchild;
2311 }
else if (!item && fFirst) {
2318 if (item->GetUserData() == userData) {
2321 item = item->fNextsibling;
2330 TGListTreeItem *TGListTree::FindItemByPathname(
const char *path)
2332 if (!path || !*path)
return 0;
2334 const char *p = path, *s;
2336 TGListTreeItem *item = 0;
2337 item = FindChildByName(item,
"/");
2338 if (!gVirtualX->InheritsFrom(
"TGX11")) {
2340 TList *curvol = gSystem->GetVolumes(
"cur");
2342 TNamed *drive = (TNamed *)curvol->At(0);
2343 item = FindChildByName(0, TString::Format(
"%s\\", drive->GetName()));
2346 TGListTreeItem *diritem = 0;
2350 while (*p && *p ==
'/') p++;
2356 strlcpy(dirname, p, 1024);
2358 strlcpy(dirname, p, (s-p)+1);
2361 item = FindChildByName(item, dirname);
2363 if (!diritem && dirname[0]) {
2367 if ((diritem=FindChildByName(0, fulldir.Data()))) {
2368 if (!s || !s[0])
return diritem;
2375 if (!s || !s[0])
return item;
2384 void TGListTree::HighlightItem(TGListTreeItem *item)
2386 UnselectAll(kFALSE);
2387 HighlightItem(item, kTRUE, kFALSE);
2388 AdjustPosition(item);
2394 void TGListTree::ClearHighlighted()
2396 UnselectAll(kFALSE);
2403 void TGListTree::GetPathnameFromItem(TGListTreeItem *item,
char *path, Int_t depth)
2409 snprintf(tmppath, 1023,
"/%s%s", item->GetText(), path);
2410 strlcpy(path, tmppath, 1024);
2411 item = item->fParent;
2412 if (--depth == 0 && item) {
2413 snprintf(tmppath, 1023,
"...%s", path);
2414 strlcpy(path, tmppath, 1024);
2423 Pixel_t TGListTree::GetGrayPixel()
2425 static Bool_t init = kFALSE;
2427 if (!gClient->GetColorByName(
"#808080", fgGrayPixel))
2428 fgGrayPixel = fgBlackPixel;
2437 FontStruct_t TGListTree::GetDefaultFontStruct()
2440 fgDefaultFont = gClient->GetResourcePool()->GetIconFont();
2441 return fgDefaultFont->GetFontStruct();
2447 const TGGC &TGListTree::GetActiveGC()
2452 gcv.fMask = kGCLineStyle | kGCLineWidth | kGCFillStyle |
2453 kGCForeground | kGCBackground | kGCFont;
2454 gcv.fLineStyle = kLineSolid;
2456 gcv.fFillStyle = kFillSolid;
2457 gcv.fFont = fgDefaultFont->GetFontHandle();
2458 gcv.fBackground = fgDefaultSelectedBackground;
2459 const TGGC *selgc = gClient->GetResourcePool()->GetSelectedGC();
2461 gcv.fForeground = selgc->GetForeground();
2463 gcv.fForeground = fgWhitePixel;
2464 fgActiveGC = gClient->GetGC(&gcv, kTRUE);
2472 const TGGC &TGListTree::GetDrawGC()
2477 gcv.fMask = kGCLineStyle | kGCLineWidth | kGCFillStyle |
2478 kGCForeground | kGCBackground | kGCFont;
2479 gcv.fLineStyle = kLineSolid;
2481 gcv.fFillStyle = kFillSolid;
2482 gcv.fFont = fgDefaultFont->GetFontHandle();
2483 gcv.fBackground = fgWhitePixel;
2484 gcv.fForeground = fgBlackPixel;
2486 fgDrawGC = gClient->GetGC(&gcv, kTRUE);
2494 const TGGC &TGListTree::GetLineGC()
2499 gcv.fMask = kGCLineStyle | kGCLineWidth | kGCFillStyle |
2500 kGCForeground | kGCBackground | kGCFont;
2501 gcv.fLineStyle = kLineOnOffDash;
2503 gcv.fFillStyle = kFillSolid;
2504 gcv.fFont = fgDefaultFont->GetFontHandle();
2505 gcv.fBackground = fgWhitePixel;
2506 gcv.fForeground = GetGrayPixel();
2508 fgLineGC = gClient->GetGC(&gcv, kTRUE);
2509 fgLineGC->SetDashOffset(0);
2510 fgLineGC->SetDashList(
"\x1\x1", 2);
2518 const TGGC &TGListTree::GetHighlightGC()
2520 if (!fgHighlightGC) {
2523 gcv.fMask = kGCLineStyle | kGCLineWidth | kGCFillStyle |
2524 kGCForeground | kGCBackground | kGCFont;
2525 gcv.fLineStyle = kLineSolid;
2527 gcv.fFillStyle = kFillSolid;
2528 gcv.fFont = fgDefaultFont->GetFontHandle();
2529 gcv.fBackground = fgDefaultSelectedBackground;
2530 gcv.fForeground = fgWhitePixel;
2532 fgHighlightGC = gClient->GetGC(&gcv, kTRUE);
2534 return *fgHighlightGC;
2540 const TGGC &TGListTree::GetColorGC()
2545 gcv.fMask = kGCLineStyle | kGCLineWidth | kGCFillStyle |
2546 kGCForeground | kGCBackground;
2547 gcv.fLineStyle = kLineSolid;
2549 gcv.fFillStyle = kFillSolid;
2550 gcv.fBackground = fgDefaultSelectedBackground;
2551 gcv.fForeground = fgWhitePixel;
2553 fgColorGC = gClient->GetGC(&gcv, kTRUE);
2561 const TGPicture *TGListTree::GetOpenPic()
2564 fgOpenPic = gClient->GetPicture(
"ofolder_t.xpm");
2565 ((TGPicture *)fgOpenPic)->AddReference();
2572 const TGPicture *TGListTree::GetClosedPic()
2575 fgClosedPic = gClient->GetPicture(
"folder_t.xpm");
2576 ((TGPicture *)fgClosedPic)->AddReference();
2583 const TGPicture *TGListTree::GetCheckedPic()
2586 fgCheckedPic = gClient->GetPicture(
"checked_t.xpm");
2587 ((TGPicture *)fgCheckedPic)->AddReference();
2588 return fgCheckedPic;
2594 const TGPicture *TGListTree::GetUncheckedPic()
2596 if (!fgUncheckedPic)
2597 fgUncheckedPic = gClient->GetPicture(
"unchecked_t.xpm");
2598 ((TGPicture *)fgUncheckedPic)->AddReference();
2599 return fgUncheckedPic;
2605 void TGListTree::SavePrimitive(std::ostream &out, Option_t *option )
2607 if (fBackground != GetWhitePixel()) SaveUserColor(out, option);
2609 out << std::endl <<
" // list tree" << std::endl;
2610 out <<
" TGListTree *";
2612 if ((fParent->GetParent())->InheritsFrom(TGCanvas::Class())) {
2613 out << GetName() <<
" = new TGListTree(" << GetCanvas()->GetName();
2615 out << GetName() <<
" = new TGListTree(" << fParent->GetName();
2616 out <<
"," << GetWidth() <<
"," << GetHeight();
2619 if (fBackground == GetWhitePixel()) {
2620 if (GetOptions() == kSunkenFrame) {
2621 out <<
");" << std::endl;
2623 out <<
"," << GetOptionString() <<
");" << std::endl;
2626 out <<
"," << GetOptionString() <<
",ucolor);" << std::endl;
2628 if (option && strstr(option,
"keep_names"))
2629 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
2635 TGListTreeItem *current;
2636 current = GetFirstItem();
2638 out <<
" const TGPicture *popen; //used for list tree items" << std::endl;
2639 out <<
" const TGPicture *pclose; //used for list tree items" << std::endl;
2643 out <<
" TGListTreeItem *item" << n <<
" = " << GetName() <<
"->AddItem(";
2644 current->SavePrimitive(out, TString::Format(
"%d",n), n);
2645 if (current->IsOpen())
2646 out <<
" " << GetName() <<
"->OpenItem(item" << n <<
");" << std::endl;
2648 out <<
" " << GetName() <<
"->CloseItem(item" << n <<
");" << std::endl;
2650 if (current == fSelected)
2651 out <<
" " << GetName() <<
"->SetSelected(item" << n <<
");" << std::endl;
2654 if (current->fFirstchild) {
2655 SaveChildren(out, current->fFirstchild, n);
2657 current = current->fNextsibling;
2666 void TGListTree::SaveChildren(std::ostream &out, TGListTreeItem *item, Int_t &n)
2670 out <<
" TGListTreeItem *item" << n <<
" = " << GetName() <<
"->AddItem(";
2671 item->SavePrimitive(out, TString::Format(
"%d",p),n);
2673 if (item->fFirstchild) {
2674 SaveChildren(out, item->fFirstchild, n);
2676 item = item->fNextsibling;
2683 void TGListTreeItemStd::SavePrimitive(std::ostream &out, Option_t *option, Int_t n)
2685 static const TGPicture *oldopen=0;
2686 static const TGPicture *oldclose=0;
2687 static const TGPicture *oldcheck=0;
2688 static const TGPicture *olduncheck=0;
2689 static Bool_t makecheck = kTRUE;
2690 static Bool_t makeuncheck = kTRUE;
2691 static Color_t oldcolor = -1;
2694 TString s = TString::Format(
"%d", n);
2699 out <<
"item" << option <<
",";
2700 TString text = GetText();
2701 text.ReplaceAll(
'\\',
"\\\\");
2702 text.ReplaceAll(
"\"",
"\\\"");
2703 out << quote << text << quote;
2704 out <<
");" << std::endl;
2706 if (oldopen != fOpenPic) {
2708 out <<
" popen = gClient->GetPicture(" << quote
2709 << gSystem->ExpandPathName(gSystem->UnixPathName(fOpenPic->GetName()))
2710 << quote <<
");" << std::endl;
2712 if (oldclose != fClosedPic) {
2713 oldclose = fClosedPic;
2714 out <<
" pclose = gClient->GetPicture(" << quote
2715 << gSystem->ExpandPathName(gSystem->UnixPathName(fClosedPic->GetName()))
2716 << quote <<
");" << std::endl;
2718 out <<
" item" << s.Data() <<
"->SetPictures(popen, pclose);" << std::endl;
2719 if (HasCheckBox()) {
2720 if (fCheckedPic && makecheck) {
2721 out <<
" const TGPicture *pcheck; //used for checked items" << std::endl;
2724 if (fUncheckedPic && makeuncheck) {
2725 out <<
" const TGPicture *puncheck; //used for unchecked items" << std::endl;
2726 makeuncheck = kFALSE;
2728 out <<
" item" << s.Data() <<
"->CheckItem();" << std::endl;
2729 if (fCheckedPic && oldcheck != fCheckedPic) {
2730 oldcheck = fCheckedPic;
2731 out <<
" pcheck = gClient->GetPicture(" << quote
2732 << gSystem->ExpandPathName(gSystem->UnixPathName(fCheckedPic->GetName()))
2733 << quote <<
");" << std::endl;
2735 if (fUncheckedPic && olduncheck != fUncheckedPic) {
2736 olduncheck = fUncheckedPic;
2737 out <<
" puncheck = gClient->GetPicture(" << quote
2738 << gSystem->ExpandPathName(gSystem->UnixPathName(fUncheckedPic->GetName()))
2739 << quote <<
");" << std::endl;
2741 out <<
" item" << s.Data() <<
"->SetCheckBoxPictures(pcheck, puncheck);" << std::endl;
2742 out <<
" item" << s.Data() <<
"->SetCheckBox(kTRUE);" << std::endl;
2745 if (oldcolor != fColor) {
2747 out <<
" item" << s.Data() <<
"->SetColor(" << fColor <<
");" << std::endl;
2750 if (fTipText.Length() > 0) {
2751 TString tiptext = GetTipText();
2752 tiptext.ReplaceAll(
'\\',
"\\\\");
2753 tiptext.ReplaceAll(
"\n",
"\\n");
2754 tiptext.ReplaceAll(
"\"",
"\\\"");
2755 out <<
" item" << s.Data() <<
"->SetTipText(" << quote
2756 << tiptext << quote <<
");" << std::endl;
2764 void TGListTree::CheckItem(TGListTreeItem *item, Bool_t check)
2766 item->CheckItem(check);
2772 void TGListTree::SetCheckBox(TGListTreeItem *item, Bool_t on)
2774 item->SetCheckBox(on);
2780 void TGListTree::ToggleItem(TGListTreeItem *item)
2788 void TGListTree::UpdateChecked(TGListTreeItem *item, Bool_t redraw)
2790 if (fAutoCheckBoxPic == kFALSE)
return;
2792 TGListTreeItem *parent;
2793 TGListTreeItem *current;
2794 current = item->GetFirstChild();
2795 parent = current ? current : item;
2797 while (parent && parent->HasCheckBox()) {
2798 if ((!parent->IsChecked() && parent->HasCheckedChild(kTRUE)) ||
2799 (parent->IsChecked() && parent->HasUnCheckedChild(kTRUE))) {
2800 parent->SetCheckBoxPictures(fClient->GetPicture(
"checked_dis_t.xpm"),
2801 fClient->GetPicture(
"unchecked_dis_t.xpm"));
2804 parent->SetCheckBoxPictures(fClient->GetPicture(
"checked_t.xpm"),
2805 fClient->GetPicture(
"unchecked_t.xpm"));
2807 parent = parent->GetParent();
2808 if (parent && fCheckMode == kRecursive) {
2809 if (!parent->IsChecked() && parent->GetFirstChild() &&
2810 !parent->GetFirstChild()->HasUnCheckedChild()) {
2811 parent->SetCheckBoxPictures(fClient->GetPicture(
"checked_t.xpm"),
2812 fClient->GetPicture(
"unchecked_t.xpm"));
2813 parent->CheckItem(kTRUE);
2815 else if (parent->IsChecked() && parent->GetFirstChild() &&
2816 !parent->GetFirstChild()->HasCheckedChild()) {
2817 parent->SetCheckBoxPictures(fClient->GetPicture(
"checked_t.xpm"),
2818 fClient->GetPicture(
"unchecked_t.xpm"));
2819 parent->CheckItem(kFALSE);
2832 TGListTreeItem *TGListTree::FindItemByObj(TGListTreeItem *item,
void *ptr)
2834 TGListTreeItem *fitem;
2836 if (item->GetUserData() == ptr)
2839 if (item->fFirstchild) {
2840 fitem = FindItemByObj(item->fFirstchild, ptr);
2841 if (fitem)
return fitem;
2843 return FindItemByObj(item->fNextsibling, ptr);
2854 void TGListTree::GetChecked(TList *checked)
2856 if (!checked || !fFirst)
return;
2857 TGListTreeItem *current = fFirst;
2858 if (current->IsChecked()) {
2859 checked->Add(
new TObjString(current->GetText()));
2862 if (current->GetFirstChild())
2863 GetCheckedChildren(checked, current->GetFirstChild());
2864 current = current->GetNextSibling();
2871 void TGListTree::GetCheckedChildren(TList *checked, TGListTreeItem *item)
2873 if (!checked || !item)
return;
2876 if (item->IsChecked()) {
2877 checked->Add(
new TObjString(item->GetText()));
2879 if (item->GetFirstChild()) {
2880 GetCheckedChildren(checked, item->GetFirstChild());
2882 item = item->GetNextSibling();
2890 void TGListTree::CheckAllChildren(TGListTreeItem *item, Bool_t state)
2893 item->CheckAllChildren(state);