File indexing completed on 2025-01-18 10:10:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef ROOT7_RDrawable
0010 #define ROOT7_RDrawable
0011
0012 #include <memory>
0013 #include <string>
0014 #include <vector>
0015
0016 #include <ROOT/RAttrMap.hxx>
0017 #include <ROOT/RStyle.hxx>
0018
0019 namespace ROOT {
0020 namespace Experimental {
0021
0022 class RMenuItems;
0023 class RPadBase;
0024 class RAttrBase;
0025 class RDisplayItem;
0026 class RDrawableDisplayItem;
0027 class RIndirectDisplayItem;
0028 class RLegend;
0029 class RCanvas;
0030 class RChangeAttrRequest;
0031 class RDrawableMenuRequest;
0032 class RDrawableExecRequest;
0033
0034 namespace Internal {
0035
0036
0037
0038
0039
0040
0041
0042
0043 class RIOSharedBase {
0044 public:
0045 virtual const void *GetIOPtr() const = 0;
0046 virtual bool HasShared() const = 0;
0047 virtual void *MakeShared() = 0;
0048 virtual void SetShared(void *shared) = 0;
0049 virtual ~RIOSharedBase() = default;
0050 };
0051
0052 using RIOSharedVector_t = std::vector<RIOSharedBase *>;
0053
0054 template<class T>
0055 class RIOShared final : public RIOSharedBase {
0056 std::shared_ptr<T> fShared;
0057 T* fIO{nullptr};
0058 public:
0059 const void *GetIOPtr() const final { return fIO; }
0060 bool HasShared() const final { return fShared.get() != nullptr; }
0061 void *MakeShared() final { fShared.reset(fIO); return &fShared; }
0062 void SetShared(void *shared) final { fShared = *((std::shared_ptr<T> *) shared); }
0063
0064 RIOShared() = default;
0065
0066 RIOShared(const std::shared_ptr<T> &ptr) : RIOSharedBase()
0067 {
0068 fShared = ptr;
0069 fIO = ptr.get();
0070 }
0071
0072 RIOShared &operator=(const std::shared_ptr<T> &ptr)
0073 {
0074 fShared = ptr;
0075 fIO = ptr.get();
0076 return *this;
0077 }
0078
0079 operator bool() const { return !!fShared || !!fIO; }
0080
0081 const T *get() const { return fShared ? fShared.get() : fIO; }
0082 T *get() { return fShared ? fShared.get() : fIO; }
0083
0084 const T *operator->() const { return get(); }
0085 T *operator->() { return get(); }
0086
0087 std::shared_ptr<T> get_shared() const { return fShared; }
0088
0089 void reset() { fShared.reset(); fIO = nullptr; }
0090
0091
0092 void reset_io() { fIO = nullptr; }
0093
0094
0095 void restore_io() { fIO = fShared.get(); }
0096 };
0097
0098 }
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 class RDrawable {
0109
0110 friend class RPadBase;
0111 friend class RCanvas;
0112 friend class RAttrBase;
0113 friend class RStyle;
0114 friend class RLegend;
0115 friend class RDrawableDisplayItem;
0116 friend class RIndirectDisplayItem;
0117 friend class RChangeAttrRequest;
0118 friend class RDrawableMenuRequest;
0119 friend class RDrawableExecRequest;
0120
0121 public:
0122
0123 using Version_t = uint64_t;
0124
0125 class RDisplayContext {
0126 RCanvas *fCanvas{nullptr};
0127 RPadBase *fPad{nullptr};
0128 RDrawable *fDrawable{nullptr};
0129 Version_t fLastVersion{0};
0130 unsigned fIndex{0};
0131 unsigned fConnId{0};
0132 bool fMainConn{false};
0133
0134 public:
0135
0136 RDisplayContext() = default;
0137
0138 RDisplayContext(RCanvas *canv, RPadBase *pad, Version_t vers = 0) :
0139 fCanvas(canv), fPad(pad), fLastVersion(vers)
0140 {
0141 }
0142
0143
0144 void SetCanvas(RCanvas *canv) { fCanvas = canv; }
0145
0146 void SetPad(RPadBase *pad) { fPad = pad; }
0147
0148 void SetDrawable(RDrawable *dr, unsigned indx)
0149 {
0150 fDrawable = dr;
0151 fIndex = indx;
0152 }
0153
0154 void SetConnection(unsigned connid, bool ismain)
0155 {
0156 fConnId = connid;
0157 fMainConn = ismain;
0158 }
0159
0160 RCanvas *GetCanvas() const { return fCanvas; }
0161 RPadBase *GetPad() const { return fPad; }
0162 RDrawable *GetDrawable() const { return fDrawable; }
0163 unsigned GetIndex() const { return fIndex; }
0164
0165 Version_t GetLastVersion() const { return fLastVersion; }
0166
0167 unsigned GetConnId() const { return fConnId; }
0168 bool IsMainConn() const { return fMainConn; }
0169 };
0170
0171 private:
0172 RAttrMap fAttr;
0173 std::weak_ptr<RStyle> fStyle;
0174 const char *fCssType{nullptr};
0175 std::string fCssClass;
0176 std::string fId;
0177 Version_t fVersion{1};
0178
0179 protected:
0180
0181 virtual void CollectShared(Internal::RIOSharedVector_t &) {}
0182
0183 virtual bool IsFrameRequired() const { return false; }
0184
0185 RAttrMap &GetAttrMap() { return fAttr; }
0186 const RAttrMap &GetAttrMap() const { return fAttr; }
0187
0188 bool MatchSelector(const std::string &selector) const;
0189
0190 virtual std::unique_ptr<RDisplayItem> Display(const RDisplayContext &);
0191
0192 void SetCssType(const char *csstype) { fCssType = csstype; }
0193
0194 virtual void OnDisplayItemDestroyed(RDisplayItem *) const {}
0195
0196 virtual void SetDrawableVersion(Version_t vers) { fVersion = vers; }
0197 Version_t GetVersion() const { return fVersion; }
0198
0199 virtual void PopulateMenu(RMenuItems &);
0200
0201 virtual void Execute(const std::string &);
0202
0203 RDrawable(const RDrawable &) = delete;
0204 RDrawable &operator=(const RDrawable &) = delete;
0205
0206 public:
0207
0208 explicit RDrawable(const char *csstype) : fCssType(csstype) {}
0209
0210 virtual ~RDrawable();
0211
0212 virtual void UseStyle(const std::shared_ptr<RStyle> &style) { fStyle = style; }
0213 void ClearStyle() { UseStyle(nullptr); }
0214
0215 const char *GetCssType() const { return fCssType; }
0216
0217 void SetCssClass(const std::string &cl) { fCssClass = cl; }
0218 const std::string &GetCssClass() const { return fCssClass; }
0219
0220 void SetId(const std::string &id) { fId = id; }
0221 const std::string &GetId() const { return fId; }
0222 };
0223
0224
0225
0226
0227 template <class DRAWABLE, std::enable_if_t<std::is_base_of<RDrawable, DRAWABLE>{}>* = nullptr>
0228 inline auto GetDrawable(const std::shared_ptr<DRAWABLE> &drawable)
0229 {
0230 return drawable;
0231 }
0232
0233 }
0234 }
0235
0236 #endif