Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:59

0001 // @(#)root/gui:$Id$
0002 // Author: Fons Rademakers   12/01/98
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
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;          ///< message id of listbox entry
0028    Pixel_t    fBkcolor;          ///< entry background color
0029    Bool_t     fActive;           ///< true if entry is active
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 *) { }  // this is needed on TGComboBoxes :(
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)  // Basic listbox entry
0045 };
0046 
0047 
0048 class TGTextLBEntry : public TGLBEntry {
0049 
0050 protected:
0051    TGString     *fText;           ///< entry text string
0052    UInt_t        fTWidth;         ///< text width
0053    UInt_t        fTHeight;        ///< text height
0054    Bool_t        fTextChanged;    ///< true if text has been changed
0055    GContext_t    fNormGC;         ///< text drawing graphics context
0056    FontStruct_t  fFontStruct;     ///< font used to draw string
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)  // Text listbox entry
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;       ///< line width
0105    Style_t     fLineStyle;       ///< line style
0106    UInt_t      fLineLength;      ///< line length
0107    TGGC       *fLineGC;          ///< line graphics context
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)  // Line width listbox entry
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;    // icon
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)  // Icon + text listbox entry
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;    ///< last active listbox entry in single selection listbox
0173    TGListBox      *fListBox;       ///< list box which contains this container
0174    Bool_t          fMultiSelect;   ///< true if multi selection is switched on
0175    Int_t           fChangeStatus;  ///< defines the changes (select or unselect) while the mouse
0176                                    ///< moves over a multi selectable list box
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)  // Listbox container
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;       ///< maximum height of single entry
0229    Bool_t           fIntegralHeight;  ///< true if height should be multiple of fItemVsize
0230    TGLBContainer   *fLbc;             ///< listbox container
0231    TGViewPort      *fVport;           ///< listbox viewport (see TGCanvas.h)
0232    TGVScrollBar    *fVScrollbar;      ///< vertical scrollbar
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");             //*MENU*
0254    virtual void RemoveEntry(Int_t id = -1);                    //*MENU*
0255    void         RemoveAll() override;                          //*MENU*
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); }      //*TOGGLE* *GETTER=GetMultipleSelections
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);   //*MENU*icon=bld_sortup.png*
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);   //*SIGNAL*
0295    virtual void Selected(Int_t id) { Emit("Selected(Int_t)", id); } //*SIGNAL*
0296    virtual void Selected(const char *txt) { Emit("Selected(char*)", txt); } //*SIGNAL
0297    virtual void DoubleClicked(Int_t widgetId, Int_t id);   //*SIGNAL*
0298    virtual void DoubleClicked(Int_t id) { Emit("DoubleClicked(Int_t)", id); } //*SIGNAL*
0299    virtual void DoubleClicked(const char *txt) { Emit("DoubleClicked(char*)", txt); } //*SIGNAL
0300    virtual void SelectionChanged() { Emit("SelectionChanged()"); } //*SIGNAL*
0301 
0302    ClassDefOverride(TGListBox,0)  // Listbox widget
0303 };
0304 
0305 #endif