Warning, file /include/root/TGListTree.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGListTree
0013 #define ROOT_TGListTree
0014
0015
0016 #include "TGCanvas.h"
0017 #include "TGWidget.h"
0018 #include "TGDNDManager.h"
0019
0020 class TGPicture;
0021 class TGToolTip;
0022 class TGCanvas;
0023 class TList;
0024 class TBufferFile;
0025
0026 class TGListTreeItem
0027 {
0028 friend class TGListTree;
0029
0030 private:
0031 TGListTreeItem(const TGListTreeItem&) = delete;
0032 TGListTreeItem& operator=(const TGListTreeItem&) = delete;
0033
0034 protected:
0035 TGClient *fClient;
0036 TGListTreeItem *fParent;
0037 TGListTreeItem *fFirstchild;
0038 TGListTreeItem *fLastchild;
0039 TGListTreeItem *fPrevsibling;
0040 TGListTreeItem *fNextsibling;
0041
0042 Bool_t fOpen;
0043
0044 Int_t fDNDState;
0045
0046
0047
0048 Int_t fY;
0049 Int_t fXtext;
0050 Int_t fYtext;
0051 UInt_t fHeight;
0052
0053
0054 public:
0055 TGListTreeItem(TGClient *client = gClient);
0056 virtual ~TGListTreeItem() {}
0057
0058 TGListTreeItem *GetParent() const { return fParent; }
0059 TGListTreeItem *GetFirstChild() const { return fFirstchild; }
0060 TGListTreeItem *GetLastChild() const { return fLastchild; }
0061 TGListTreeItem *GetPrevSibling() const { return fPrevsibling; }
0062 TGListTreeItem *GetNextSibling() const { return fNextsibling; }
0063
0064 virtual Bool_t IsOpen() const { return fOpen; }
0065 virtual void SetOpen(Bool_t o) { fOpen = o; }
0066
0067 virtual Bool_t IsActive() const = 0;
0068 virtual Pixel_t GetActiveColor() const = 0;
0069 virtual void SetActive(Bool_t) {}
0070
0071 void Rename(const char* new_name) { SetText(new_name); }
0072 virtual const char *GetText() const = 0;
0073 virtual Int_t GetTextLength() const = 0;
0074 virtual const char *GetTipText() const = 0;
0075 virtual Int_t GetTipTextLength() const = 0;
0076 virtual void SetText(const char *) {}
0077 virtual void SetTipText(const char *) {}
0078
0079 virtual void SetUserData(void *, Bool_t=kFALSE) {}
0080 virtual void *GetUserData() const = 0;
0081
0082 virtual const TGPicture*GetPicture() const = 0;
0083 virtual void SetPictures(const TGPicture*, const TGPicture*) {}
0084 virtual const TGPicture*GetCheckBoxPicture() const = 0;
0085 virtual void SetCheckBoxPictures(const TGPicture*, const TGPicture*) {}
0086 virtual UInt_t GetPicWidth() const;
0087
0088 virtual void SetCheckBox(Bool_t=kTRUE) {}
0089 virtual Bool_t HasCheckBox() const = 0;
0090 virtual void CheckItem(Bool_t=kTRUE) = 0;
0091 virtual void Toggle() { SetCheckBox( ! IsChecked()); }
0092 virtual Bool_t IsChecked() const = 0;
0093
0094
0095 virtual void CheckAllChildren(Bool_t=kTRUE) {}
0096 virtual void CheckChildren(TGListTreeItem*, Bool_t) {}
0097 virtual Bool_t HasCheckedChild(Bool_t=kFALSE) { return kTRUE; }
0098 virtual Bool_t HasUnCheckedChild(Bool_t=kFALSE) { return kTRUE; }
0099 virtual void UpdateState() {}
0100
0101
0102 virtual Bool_t HasColor() const = 0;
0103 virtual Color_t GetColor() const = 0;
0104 virtual void SetColor(Color_t) {}
0105 virtual void ClearColor() {}
0106
0107
0108 void SetDNDSource(Bool_t onoff)
0109 { if (onoff) fDNDState |= kIsDNDSource; else fDNDState &= ~kIsDNDSource; }
0110 void SetDNDTarget(Bool_t onoff)
0111 { if (onoff) fDNDState |= kIsDNDTarget; else fDNDState &= ~kIsDNDTarget; }
0112 Bool_t IsDNDSource() const { return fDNDState & kIsDNDSource; }
0113 Bool_t IsDNDTarget() const { return fDNDState & kIsDNDTarget; }
0114
0115
0116 virtual Bool_t HandlesDragAndDrop() const { return kFALSE; }
0117 virtual void HandleDrag() {}
0118 virtual void HandleDrop() {}
0119
0120 virtual void SavePrimitive(std::ostream&, Option_t*, Int_t) {}
0121
0122 ClassDef(TGListTreeItem,0)
0123 };
0124
0125
0126 class TGListTreeItemStd : public TGListTreeItem
0127 {
0128 private:
0129 Bool_t fActive;
0130 Bool_t fCheckBox;
0131 Bool_t fChecked;
0132 Bool_t fOwnsData;
0133 TString fText;
0134 TString fTipText;
0135 const TGPicture *fOpenPic;
0136 const TGPicture *fClosedPic;
0137 const TGPicture *fCheckedPic;
0138 const TGPicture *fUncheckedPic;
0139 void *fUserData;
0140
0141 Bool_t fHasColor;
0142 Color_t fColor;
0143
0144 TGListTreeItemStd(const TGListTreeItemStd&) = delete;
0145 TGListTreeItemStd& operator=(const TGListTreeItemStd&) = delete;
0146
0147 public:
0148 TGListTreeItemStd(TGClient *fClient = gClient, const char *name = nullptr,
0149 const TGPicture *opened = nullptr, const TGPicture *closed = nullptr,
0150 Bool_t checkbox = kFALSE);
0151 ~TGListTreeItemStd() override;
0152
0153 Pixel_t GetActiveColor() const override;
0154 Bool_t IsActive() const override { return fActive; }
0155 void SetActive(Bool_t a) override { fActive = a; }
0156
0157 const char *GetText() const override { return fText.Data(); }
0158 Int_t GetTextLength() const override { return fText.Length(); }
0159 const char *GetTipText() const override { return fTipText.Data(); }
0160 Int_t GetTipTextLength() const override { return fTipText.Length(); }
0161 void SetText(const char *text) override { fText = text; }
0162 void SetTipText(const char *tip) override { fTipText = tip; }
0163
0164 void SetUserData(void *userData, Bool_t own = kFALSE) override { fUserData = userData; fOwnsData=own; }
0165 void *GetUserData() const override { return fUserData; }
0166
0167 const TGPicture *GetPicture() const override { return fOpen ? fOpenPic : fClosedPic; }
0168 const TGPicture *GetCheckBoxPicture() const override { return fCheckBox ? (fChecked ? fCheckedPic : fUncheckedPic) : nullptr; }
0169 void SetPictures(const TGPicture *opened, const TGPicture *closed) override;
0170 void SetCheckBoxPictures(const TGPicture *checked, const TGPicture *unchecked) override;
0171
0172 void SetCheckBox(Bool_t on = kTRUE) override;
0173 Bool_t HasCheckBox() const override { return fCheckBox; }
0174 void CheckItem(Bool_t checked = kTRUE) override { fChecked = checked; }
0175 void Toggle() override { fChecked = !fChecked; }
0176 Bool_t IsChecked() const override { return fChecked; }
0177
0178 void CheckAllChildren(Bool_t state = kTRUE) override;
0179 void CheckChildren(TGListTreeItem *item, Bool_t state) override;
0180 Bool_t HasCheckedChild(Bool_t first=kFALSE) override;
0181 Bool_t HasUnCheckedChild(Bool_t first=kFALSE) override;
0182 void UpdateState() override;
0183
0184 Bool_t HasColor() const override { return fHasColor; }
0185 Color_t GetColor() const override { return fColor; }
0186 void SetColor(Color_t color) override { fHasColor = true;fColor = color; }
0187 void ClearColor() override { fHasColor = false; }
0188
0189 void SavePrimitive(std::ostream &out, Option_t *option, Int_t n) override;
0190
0191 ClassDefOverride(TGListTreeItemStd,0)
0192 };
0193
0194
0195 class TGListTree : public TGContainer {
0196
0197 public:
0198
0199 enum EColorMarkupMode {
0200 kDefault = 0,
0201 kColorUnderline = BIT(0),
0202 kColorBox = BIT(1)
0203 };
0204 enum ECheckMode {
0205 kSimple = BIT(2),
0206 kRecursive = BIT(3)
0207 };
0208
0209 protected:
0210 TGListTreeItem *fFirst;
0211 TGListTreeItem *fLast;
0212 TGListTreeItem *fSelected;
0213 TGListTreeItem *fCurrent;
0214 TGListTreeItem *fBelowMouse;
0215 Int_t fHspacing;
0216 Int_t fVspacing;
0217 Int_t fIndent;
0218 Int_t fMargin;
0219 Pixel_t fGrayPixel;
0220 GContext_t fActiveGC;
0221 GContext_t fDrawGC;
0222 GContext_t fLineGC;
0223 GContext_t fHighlightGC;
0224 FontStruct_t fFont;
0225 UInt_t fDefw;
0226 UInt_t fDefh;
0227 Int_t fExposeTop;
0228 Int_t fExposeBottom;
0229 TGToolTip *fTip;
0230 TGListTreeItem *fTipItem;
0231 TBufferFile *fBuf;
0232 TDNDData fDNDData;
0233 Atom_t *fDNDTypeList;
0234 TGListTreeItem *fDropItem;
0235 Bool_t fAutoTips;
0236 Bool_t fAutoCheckBoxPic;
0237 Bool_t fDisableOpen;
0238 Bool_t fUserControlled;
0239 Bool_t fEventHandled;
0240 UInt_t fLastEventState;
0241
0242 EColorMarkupMode fColorMode;
0243 ECheckMode fCheckMode;
0244 GContext_t fColorGC;
0245
0246 static Pixel_t fgGrayPixel;
0247 static const TGFont *fgDefaultFont;
0248 static TGGC *fgActiveGC;
0249 static TGGC *fgDrawGC;
0250 static TGGC *fgLineGC;
0251 static TGGC *fgHighlightGC;
0252 static TGGC *fgColorGC;
0253 static const TGPicture *fgOpenPic;
0254 static const TGPicture *fgClosedPic;
0255 static const TGPicture *fgCheckedPic;
0256 static const TGPicture *fgUncheckedPic;
0257
0258 static Pixel_t GetGrayPixel();
0259 static FontStruct_t GetDefaultFontStruct();
0260 static const TGGC &GetActiveGC();
0261 static const TGGC &GetDrawGC();
0262 static const TGGC &GetLineGC();
0263 static const TGGC &GetHighlightGC();
0264 static const TGGC &GetColorGC();
0265
0266 void Draw(Handle_t id, Int_t yevent, Int_t hevent);
0267 void Draw(Option_t * ="") override { MayNotUse("Draw(Option_t*)"); }
0268 Int_t DrawChildren(Handle_t id, TGListTreeItem *item, Int_t x, Int_t y, Int_t xroot);
0269 void DrawItem(Handle_t id, TGListTreeItem *item, Int_t x, Int_t y, Int_t *xroot,
0270 UInt_t *retwidth, UInt_t *retheight);
0271 void DrawItemName(Handle_t id, TGListTreeItem *item);
0272 void DrawNode(Handle_t id, TGListTreeItem *item, Int_t x, Int_t y);
0273 virtual void UpdateChecked(TGListTreeItem *item, Bool_t redraw = kFALSE);
0274
0275 void SaveChildren(std::ostream &out, TGListTreeItem *item, Int_t &n);
0276 void RemoveReference(TGListTreeItem *item);
0277 void PDeleteItem(TGListTreeItem *item);
0278 void PDeleteChildren(TGListTreeItem *item);
0279 void InsertChild(TGListTreeItem *parent, TGListTreeItem *item);
0280 void InsertChildren(TGListTreeItem *parent, TGListTreeItem *item);
0281 Int_t SearchChildren(TGListTreeItem *item, Int_t y, Int_t findy,
0282 TGListTreeItem **finditem);
0283 TGListTreeItem *FindItem(Int_t findy);
0284 void *FindItem(const TString& name,
0285 Bool_t direction = kTRUE,
0286 Bool_t caseSensitive = kTRUE,
0287 Bool_t beginWith = kFALSE) override
0288 { return TGContainer::FindItem(name, direction, caseSensitive, beginWith); }
0289
0290 void Layout() override {}
0291
0292 void OnMouseOver(TGFrame*) override { }
0293 void CurrentChanged(Int_t , Int_t ) override { }
0294 void CurrentChanged(TGFrame *) override { }
0295 void ReturnPressed(TGFrame*) override { }
0296 void Clicked(TGFrame *, Int_t ) override { }
0297 void Clicked(TGFrame *, Int_t , Int_t , Int_t ) override { }
0298 void DoubleClicked(TGFrame *, Int_t ) override { }
0299 void DoubleClicked(TGFrame *, Int_t , Int_t , Int_t ) override { }
0300 void KeyPressed(TGFrame *, UInt_t , UInt_t ) override { }
0301
0302 private:
0303 TGListTree(const TGListTree&) = delete;
0304 TGListTree& operator=(const TGListTree&) = delete;
0305
0306 public:
0307 TGListTree(TGWindow *p = nullptr, UInt_t w = 1, UInt_t h = 1,
0308 UInt_t options = 0, Pixel_t back = GetWhitePixel());
0309 TGListTree(TGCanvas *p, UInt_t options, Pixel_t back = GetWhitePixel());
0310
0311 ~TGListTree() override;
0312
0313 Bool_t HandleButton(Event_t *event) override;
0314 Bool_t HandleDoubleClick(Event_t *event) override;
0315 Bool_t HandleCrossing(Event_t *event) override;
0316 Bool_t HandleMotion(Event_t *event) override;
0317 Bool_t HandleKey(Event_t *event) override;
0318
0319 virtual void SetCanvas(TGCanvas *canvas) { fCanvas = canvas; }
0320 void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h) override;
0321
0322 virtual void DrawOutline(Handle_t id, TGListTreeItem *item, Pixel_t col=0xbbbbbb,
0323 Bool_t clear=kFALSE);
0324 virtual void DrawActive(Handle_t id, TGListTreeItem *item);
0325
0326 TGDimension GetDefaultSize() const override
0327 { return TGDimension(fDefw, fDefh); }
0328
0329 void AddItem(TGListTreeItem *parent, TGListTreeItem *item);
0330 TGListTreeItem *AddItem(TGListTreeItem *parent, const char *string,
0331 const TGPicture *open = nullptr,
0332 const TGPicture *closed = nullptr,
0333 Bool_t checkbox = kFALSE);
0334 TGListTreeItem *AddItem(TGListTreeItem *parent, const char *string,
0335 void *userData, const TGPicture *open = nullptr,
0336 const TGPicture *closed = nullptr,
0337 Bool_t checkbox = kFALSE);
0338 void RenameItem(TGListTreeItem *item, const char *string);
0339 Int_t DeleteItem(TGListTreeItem *item);
0340 void OpenItem(TGListTreeItem *item);
0341 void CloseItem(TGListTreeItem *item);
0342 void CheckItem(TGListTreeItem *item, Bool_t check = kTRUE);
0343 void SetCheckBox(TGListTreeItem *item, Bool_t on = kTRUE);
0344 void ToggleItem(TGListTreeItem *item);
0345 Int_t RecursiveDeleteItem(TGListTreeItem *item, void *userData);
0346
0347 Int_t DeleteChildren(TGListTreeItem *item);
0348 Int_t Reparent(TGListTreeItem *item, TGListTreeItem *newparent);
0349 Int_t ReparentChildren(TGListTreeItem *item, TGListTreeItem *newparent);
0350 void SetToolTipItem(TGListTreeItem *item, const char *string);
0351 void SetAutoTips(Bool_t on = kTRUE) { fAutoTips = on; }
0352 void SetAutoCheckBoxPic(Bool_t on) { fAutoCheckBoxPic = on; }
0353 void SetSelected(TGListTreeItem *item) { fSelected = item; }
0354 void AdjustPosition(TGListTreeItem *item);
0355 void AdjustPosition() override { TGContainer::AdjustPosition(); }
0356
0357
0358 void Home(Bool_t select = kFALSE) override;
0359 void End(Bool_t select = kFALSE) override;
0360 void PageUp(Bool_t select = kFALSE) override;
0361 void PageDown(Bool_t select = kFALSE) override;
0362 void LineUp(Bool_t select = kFALSE) override;
0363 void LineDown(Bool_t select = kFALSE) override;
0364 void Search(Bool_t close = kTRUE) override;
0365
0366 Int_t Sort(TGListTreeItem *item);
0367 Int_t SortSiblings(TGListTreeItem *item);
0368 Int_t SortChildren(TGListTreeItem *item);
0369 void HighlightItem(TGListTreeItem *item);
0370 void ClearHighlighted();
0371 void GetPathnameFromItem(TGListTreeItem *item, char *path, Int_t depth = 0);
0372 void UnselectAll(Bool_t draw);
0373 void SetToolTipText(const char *text, Int_t x, Int_t y, Long_t delayms);
0374 void HighlightItem(TGListTreeItem *item, Bool_t state, Bool_t draw);
0375 void HighlightChildren(TGListTreeItem *item, Bool_t state, Bool_t draw);
0376 void DisableOpen(Bool_t disable = kTRUE) { fDisableOpen = disable;}
0377 void GetChecked(TList *checked);
0378 void GetCheckedChildren(TList *checked, TGListTreeItem *item);
0379 void CheckAllChildren(TGListTreeItem *item, Bool_t state);
0380
0381 TGListTreeItem *GetFirstItem() const { return fFirst; }
0382 TGListTreeItem *GetSelected() const { return fSelected; }
0383 TGListTreeItem *GetCurrent() const { return fCurrent; }
0384 TGListTreeItem *GetBelowMouse() const { return fBelowMouse; }
0385 TGListTreeItem *FindSiblingByName(TGListTreeItem *item, const char *name);
0386 TGListTreeItem *FindSiblingByData(TGListTreeItem *item, void *userData);
0387 TGListTreeItem *FindChildByName(TGListTreeItem *item, const char *name);
0388 TGListTreeItem *FindChildByData(TGListTreeItem *item, void *userData);
0389 TGListTreeItem *FindItemByPathname(const char *path);
0390 TGListTreeItem *FindItemByObj(TGListTreeItem *item, void *ptr);
0391
0392 void AddItem(const char *string) { AddItem(fSelected, string); }
0393 void AddRoot(const char *string) { AddItem(nullptr, string); }
0394 Int_t DeleteSelected() { return fSelected ? DeleteItem(fSelected) : 0; }
0395 void RenameSelected(const char *string) { if (fSelected) RenameItem(fSelected, string); }
0396
0397 virtual void MouseOver(TGListTreeItem *entry);
0398 virtual void MouseOver(TGListTreeItem *entry, UInt_t mask);
0399 virtual void KeyPressed(TGListTreeItem *entry, UInt_t keysym, UInt_t mask);
0400 virtual void ReturnPressed(TGListTreeItem *entry);
0401 virtual void Clicked(TGListTreeItem *entry, Int_t btn);
0402 virtual void Clicked(TGListTreeItem *entry, Int_t btn, Int_t x, Int_t y);
0403 virtual void Clicked(TGListTreeItem *entry, Int_t btn, UInt_t mask, Int_t x, Int_t y);
0404 virtual void DoubleClicked(TGListTreeItem *entry, Int_t btn);
0405 virtual void DoubleClicked(TGListTreeItem *entry, Int_t btn, Int_t x, Int_t y);
0406 virtual void Checked(TObject *obj, Bool_t check);
0407 virtual void DataDropped(TGListTreeItem *item, TDNDData *data);
0408
0409
0410 Int_t FontHeight();
0411 Int_t FontAscent();
0412 Int_t TextWidth(const char *c);
0413
0414 static const TGPicture *GetOpenPic();
0415 static const TGPicture *GetClosedPic();
0416 static const TGPicture *GetCheckedPic();
0417 static const TGPicture *GetUncheckedPic();
0418
0419
0420 void SetUserControl(Bool_t ctrl=kTRUE) { fUserControlled = ctrl; }
0421 Bool_t HasUserControl() const { return fUserControlled; }
0422 void SetEventHandled(Bool_t eh=kTRUE) { fEventHandled = eh; }
0423 Bool_t IsEventHandled() const { return fEventHandled; }
0424
0425 Bool_t HandleDNDDrop(TDNDData *data) override;
0426 Atom_t HandleDNDPosition(Int_t x, Int_t y, Atom_t action,
0427 Int_t xroot, Int_t yroot) override;
0428 Atom_t HandleDNDEnter(Atom_t * typelist) override;
0429 Bool_t HandleDNDLeave() override;
0430
0431 TDNDData *GetDNDData(Atom_t) override { return &fDNDData; }
0432
0433 EColorMarkupMode GetColorMode() const { return fColorMode; }
0434 void SetColorMode(EColorMarkupMode colorMode) { fColorMode = colorMode; }
0435
0436 ECheckMode GetCheckMode() const { return fCheckMode; }
0437 void SetCheckMode(ECheckMode mode) { fCheckMode = mode; }
0438
0439 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0440
0441 ClassDefOverride(TGListTree,0)
0442 };
0443
0444 #endif