File indexing completed on 2025-01-18 10:11:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGListBox
0013 #define ROOT_TGListBox
0014
0015
0016 #include "TGFrame.h"
0017 #include "TGCanvas.h"
0018 #include "TGScrollBar.h"
0019
0020 class TGListBox;
0021 class TList;
0022
0023
0024 class TGLBEntry : public TGFrame {
0025
0026 protected:
0027 Int_t fEntryId;
0028 Pixel_t fBkcolor;
0029 Bool_t fActive;
0030
0031 void DoRedraw() override { }
0032
0033 public:
0034 TGLBEntry(const TGWindow *p = nullptr, Int_t id = -1, UInt_t options = kHorizontalFrame,
0035 Pixel_t back = GetWhitePixel());
0036
0037 void Activate(Bool_t a) override;
0038 virtual void Toggle();
0039 virtual void Update(TGLBEntry *) { }
0040 Int_t EntryId() const { return fEntryId; }
0041 Bool_t IsActive() const override { return fActive; }
0042 void SetBackgroundColor(Pixel_t col) override { TGFrame::SetBackgroundColor(col); fBkcolor = col; }
0043
0044 ClassDefOverride(TGLBEntry,0)
0045 };
0046
0047
0048 class TGTextLBEntry : public TGLBEntry {
0049
0050 protected:
0051 TGString *fText;
0052 UInt_t fTWidth;
0053 UInt_t fTHeight;
0054 Bool_t fTextChanged;
0055 GContext_t fNormGC;
0056 FontStruct_t fFontStruct;
0057
0058 void DoRedraw() override;
0059
0060 static const TGFont *fgDefaultFont;
0061 static TGGC *fgDefaultGC;
0062
0063 private:
0064 TGTextLBEntry(const TGTextLBEntry &) = delete;
0065 TGTextLBEntry &operator=(const TGTextLBEntry &) = delete;
0066
0067 public:
0068 static FontStruct_t GetDefaultFontStruct();
0069 static const TGGC &GetDefaultGC();
0070
0071 TGTextLBEntry(const TGWindow *p = nullptr, TGString *s = nullptr, Int_t id = -1,
0072 GContext_t norm = GetDefaultGC()(),
0073 FontStruct_t font = GetDefaultFontStruct(),
0074 UInt_t options = kHorizontalFrame,
0075 Pixel_t back = GetWhitePixel());
0076 ~TGTextLBEntry() override;
0077
0078 TGDimension GetDefaultSize() const override { return TGDimension(fTWidth, fTHeight+1); }
0079 const TGString *GetText() const { return fText; }
0080 void SetText(TGString *new_text);
0081 const char *GetTitle() const override { return fText->Data(); }
0082 virtual void SetTitle(const char *text) { *fText = text; }
0083
0084 void DrawCopy(Handle_t id, Int_t x, Int_t y) override;
0085 void Update(TGLBEntry *e) override
0086 { SetText(new TGString(((TGTextLBEntry *)e)->GetText())); }
0087
0088 GContext_t GetNormGC() const { return fNormGC; }
0089 FontStruct_t GetFontStruct() const { return fFontStruct; }
0090
0091 void SavePrimitive(std::ostream &out, Option_t * = "") override;
0092
0093 ClassDefOverride(TGTextLBEntry,0)
0094 };
0095
0096
0097 class TGLineLBEntry : public TGTextLBEntry {
0098
0099 private:
0100 TGLineLBEntry(const TGLineLBEntry&) = delete;
0101 TGLineLBEntry operator=(const TGLineLBEntry&) = delete;
0102
0103 protected:
0104 UInt_t fLineWidth;
0105 Style_t fLineStyle;
0106 UInt_t fLineLength;
0107 TGGC *fLineGC;
0108
0109 void DoRedraw() override;
0110
0111 public:
0112 TGLineLBEntry(const TGWindow *p = nullptr, Int_t id = -1, const char *str = nullptr,
0113 UInt_t w = 0, Style_t s = 0,
0114 UInt_t options = kHorizontalFrame,
0115 Pixel_t back = GetWhitePixel());
0116 ~TGLineLBEntry() override;
0117
0118 TGDimension GetDefaultSize() const override
0119 { return TGDimension(fTWidth, fTHeight+1); }
0120 virtual Int_t GetLineWidth() const { return fLineWidth; }
0121 virtual void SetLineWidth(Int_t width);
0122 Style_t GetLineStyle() const { return fLineStyle; }
0123 virtual void SetLineStyle(Style_t style);
0124 TGGC *GetLineGC() const { return fLineGC; }
0125 void Update(TGLBEntry *e) override;
0126 void DrawCopy(Handle_t id, Int_t x, Int_t y) override;
0127
0128 ClassDefOverride(TGLineLBEntry, 0)
0129 };
0130
0131
0132 class TGIconLBEntry : public TGTextLBEntry {
0133
0134 private:
0135 TGIconLBEntry(const TGIconLBEntry&) = delete;
0136 TGIconLBEntry operator=(const TGIconLBEntry&) = delete;
0137
0138 protected:
0139 const TGPicture *fPicture;
0140
0141 void DoRedraw() override;
0142
0143 public:
0144 TGIconLBEntry(const TGWindow *p = nullptr, Int_t id = -1, const char *str = nullptr,
0145 const TGPicture *pic = nullptr,
0146 UInt_t w = 0, Style_t s = 0,
0147 UInt_t options = kHorizontalFrame,
0148 Pixel_t back = GetWhitePixel());
0149 ~TGIconLBEntry() override;
0150
0151 TGDimension GetDefaultSize() const override
0152 { return TGDimension(fTWidth, fTHeight+1); }
0153 const TGPicture *GetPicture() const { return fPicture; }
0154 virtual void SetPicture(const TGPicture *pic = nullptr);
0155
0156 void Update(TGLBEntry *e) override;
0157 void DrawCopy(Handle_t id, Int_t x, Int_t y) override;
0158
0159 ClassDefOverride(TGIconLBEntry, 0)
0160 };
0161
0162
0163 class TGLBContainer : public TGContainer {
0164
0165 friend class TGListBox;
0166
0167 private:
0168 TGLBContainer(const TGLBContainer&) = delete;
0169 TGLBContainer operator=(const TGLBContainer&) = delete;
0170
0171 protected:
0172 TGLBEntry *fLastActive;
0173 TGListBox *fListBox;
0174 Bool_t fMultiSelect;
0175 Int_t fChangeStatus;
0176
0177
0178 void OnAutoScroll() override;
0179 void DoRedraw() override;
0180
0181 public:
0182 TGLBContainer(const TGWindow *p = nullptr, UInt_t w = 1, UInt_t h = 1,
0183 UInt_t options = kSunkenFrame,
0184 Pixel_t back = GetDefaultFrameBackground());
0185 ~TGLBContainer() override;
0186
0187 virtual void AddEntry(TGLBEntry *lbe, TGLayoutHints *lhints);
0188 virtual void AddEntrySort(TGLBEntry *lbe, TGLayoutHints *lhints);
0189 virtual void InsertEntry(TGLBEntry *lbe, TGLayoutHints *lhints, Int_t afterID);
0190 virtual void RemoveEntry(Int_t id);
0191 virtual void RemoveEntries(Int_t from_ID, Int_t to_ID);
0192 void RemoveAll() override;
0193
0194 void ActivateItem(TGFrameElement *el) override;
0195 void Associate(const TGWindow *w) override { fMsgWindow = w; }
0196 virtual void SetListBox(TGListBox *lb) { fListBox = lb; }
0197 TGListBox *GetListBox() const { return fListBox; }
0198 Bool_t HandleButton(Event_t *event) override;
0199 Bool_t HandleDoubleClick(Event_t *event) override;
0200 Bool_t HandleMotion(Event_t *event) override;
0201 virtual Int_t GetSelected() const;
0202 virtual Bool_t GetSelection(Int_t id);
0203 virtual Int_t GetPos(Int_t id);
0204 TGLBEntry *GetSelectedEntry() const { return fLastActive; }
0205 virtual void GetSelectedEntries(TList *selected);
0206 virtual TGLBEntry *Select(Int_t id, Bool_t sel);
0207 virtual TGLBEntry *Select(Int_t id);
0208
0209 TGVScrollBar *GetVScrollbar() const override;
0210 void SetVsbPosition(Int_t newPos) override;
0211 void Layout() override;
0212 UInt_t GetDefaultWidth() const override { return fWidth; }
0213
0214 virtual void SetMultipleSelections(Bool_t multi);
0215 virtual Bool_t GetMultipleSelections() const { return fMultiSelect; }
0216
0217 ClassDefOverride(TGLBContainer,0)
0218 };
0219
0220
0221 class TGListBox : public TGCompositeFrame, public TGWidget {
0222
0223 private:
0224 TGListBox(const TGListBox&) = delete;
0225 TGListBox operator=(const TGListBox&) = delete;
0226
0227 protected:
0228 UInt_t fItemVsize;
0229 Bool_t fIntegralHeight;
0230 TGLBContainer *fLbc;
0231 TGViewPort *fVport;
0232 TGVScrollBar *fVScrollbar;
0233
0234 void SetContainer(TGFrame *f) { fVport->SetContainer(f); }
0235
0236 virtual void InitListBox();
0237
0238 public:
0239 TGListBox(const TGWindow *p = nullptr, Int_t id = -1,
0240 UInt_t options = kSunkenFrame | kDoubleBorder,
0241 Pixel_t back = GetWhitePixel());
0242 ~TGListBox() override;
0243
0244 virtual void AddEntry(TGString *s, Int_t id);
0245 virtual void AddEntry(const char *s, Int_t id);
0246 virtual void AddEntry(TGLBEntry *lbe, TGLayoutHints *lhints);
0247 virtual void AddEntrySort(TGString *s, Int_t id);
0248 virtual void AddEntrySort(const char *s, Int_t id);
0249 virtual void AddEntrySort(TGLBEntry *lbe, TGLayoutHints *lhints);
0250 virtual void InsertEntry(TGString *s, Int_t id, Int_t afterID);
0251 virtual void InsertEntry(const char *s , Int_t id, Int_t afterID);
0252 virtual void InsertEntry(TGLBEntry *lbe, TGLayoutHints *lhints, Int_t afterID);
0253 virtual void NewEntry(const char *s = "Entry");
0254 virtual void RemoveEntry(Int_t id = -1);
0255 void RemoveAll() override;
0256 virtual void RemoveEntries(Int_t from_ID, Int_t to_ID);
0257 void ChangeBackground(Pixel_t back) override;
0258 virtual void SetTopEntry(Int_t id = -1);
0259 virtual void SetMultipleSelections(Bool_t multi = kTRUE)
0260 { fLbc->SetMultipleSelections(multi); }
0261 virtual Bool_t GetMultipleSelections() const
0262 { return fLbc->GetMultipleSelections(); }
0263 virtual Int_t GetNumberOfEntries() const
0264 { return fLbc->GetList()->GetSize(); }
0265 virtual TGLBEntry *GetEntry(Int_t id) const;
0266 virtual TGLBEntry *FindEntry(const char *s) const;
0267 virtual TGFrame *GetContainer() const { return fVport->GetContainer(); }
0268 virtual TGViewPort *GetViewPort() const { return fVport; }
0269 virtual TGScrollBar *GetScrollBar() const { return fVScrollbar; }
0270 virtual TGVScrollBar *GetVScrollbar() const { return fVScrollbar; }
0271
0272 void DrawBorder() override;
0273 void Resize(UInt_t w, UInt_t h) override;
0274 void Resize(TGDimension size) override { Resize(size.fWidth, size.fHeight); }
0275 void MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h) override;
0276 void Layout() override;
0277 void SetLayoutManager(TGLayoutManager *) override {}
0278 virtual void SortByName(Bool_t ascend = kTRUE);
0279 virtual void IntegralHeight(Bool_t mode) { fIntegralHeight = mode; }
0280 TGDimension GetDefaultSize() const override;
0281
0282 Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override;
0283
0284 virtual TGLBEntry *Select(Int_t id, Bool_t sel = kTRUE)
0285 { return fLbc->Select(id, sel); }
0286 virtual Int_t GetSelected() const;
0287 virtual Bool_t GetSelection(Int_t id) { return fLbc->GetSelection(id); }
0288 virtual TGLBEntry *GetSelectedEntry() const { return fLbc->GetSelectedEntry(); }
0289 virtual void GetSelectedEntries(TList *selected);
0290 UInt_t GetItemVsize() const { return fItemVsize; }
0291
0292 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0293
0294 virtual void Selected(Int_t widgetId, Int_t id);
0295 virtual void Selected(Int_t id) { Emit("Selected(Int_t)", id); }
0296 virtual void Selected(const char *txt) { Emit("Selected(char*)", txt); }
0297 virtual void DoubleClicked(Int_t widgetId, Int_t id);
0298 virtual void DoubleClicked(Int_t id) { Emit("DoubleClicked(Int_t)", id); }
0299 virtual void DoubleClicked(const char *txt) { Emit("DoubleClicked(char*)", txt); }
0300 virtual void SelectionChanged() { Emit("SelectionChanged()"); }
0301
0302 ClassDefOverride(TGListBox,0)
0303 };
0304
0305 #endif