// Author: Sergey Linev, GSI 7/12/2016 /************************************************************************* * Copyright (C) 1995-2023, Rene Brun and Fons Rademakers. * * All rights reserved. * * * * For the licensing terms see $ROOTSYS/LICENSE. * * For the list of contributors see $ROOTSYS/README/CREDITS. * *************************************************************************/ #ifndef ROOT_TWebCanvas #define ROOT_TWebCanvas #include "TCanvasImp.h" #include "TString.h" #include "TList.h" #include "TWebPadOptions.h" #include #include #include #include #include #include class TPad; class TPadWebSnapshot; class TWebPS; class TObjLink; class TExec; class TWebCanvasTimer; class TWebCanvas : public TCanvasImp { friend class TWebCanvasTimer; public: /// Function type for signals, invoked when canvas drawing or update is completed using UpdatedSignal_t = std::function; /// Function type for pad-related signals - like activate pad signal using PadSignal_t = std::function; /// Function type for pad-click signals using PadClickedSignal_t = std::function; /// Function type for signals, invoked when object is selected using ObjectSelectSignal_t = std::function; protected: /// Function called when pad painting produced using PadPaintingReady_t = std::function; struct WebConn { unsigned fConnId{0}; /// fCtrl; /// fSend; /// fWebConn; /// fPadsStatus; /// fWindow; ///!< configured display Bool_t fReadOnly{kFALSE}; /// fCustomClasses; /// fWindowGeometry; /// 1) && (fWebConn[1].fConnId == connid); } Bool_t IsFirstDrawn() const { return (fWebConn.size() > 1) && (fWebConn[1].fDrawVersion > 0); } void ShowCmd(const std::string &arg, Bool_t show); void AssignStatusBits(UInt_t bits); virtual Bool_t ProcessData(unsigned connid, const std::string &arg); virtual Bool_t DecodePadOptions(const std::string &, bool process_execs = false); virtual Bool_t CanCreateObject(const std::string &) { return !IsReadOnly() && fCanCreateObjects; } TPad *ProcessObjectOptions(TWebObjectOptions &item, TPad *pad, int idcnt = 1); TObject *FindPrimitive(const std::string &id, int idcnt = 1, TPad *pad = nullptr, TObjLink **objlnk = nullptr, TPad **objpad = nullptr); void ProcessExecs(TPad *pad, TExec *extra = nullptr); void ProcessLinesForObject(TObject *obj, const std::string &lines); public: TWebCanvas(TCanvas *c, const char *name, Int_t x, Int_t y, UInt_t width, UInt_t height, Bool_t readonly = kTRUE); ~TWebCanvas() override; void ShowWebWindow(const ROOT::RWebDisplayArgs &user_args = ""); const std::shared_ptr &GetWebWindow() const { return fWindow; } virtual Bool_t IsReadOnly() const { return fReadOnly; } Int_t InitWindow() override; void Close() override; void Show() override; UInt_t GetWindowGeometry(Int_t &x, Int_t &y, UInt_t &w, UInt_t &h) override; void ShowMenuBar(Bool_t show = kTRUE) override { ShowCmd("Menu", show); } void ShowStatusBar(Bool_t show = kTRUE) override { ShowCmd("StatusBar", show); } void ShowEditor(Bool_t show = kTRUE) override { ShowCmd("Editor", show); } void ShowToolBar(Bool_t show = kTRUE) override { ShowCmd("ToolBar", show); } void ShowToolTips(Bool_t show = kTRUE) override { ShowCmd("ToolTips", show); } // web-canvas specific methods void ActivateInEditor(TPad *pad, TObject *obj); void ForceUpdate() override; void SetWindowPosition(Int_t x, Int_t y) override; void SetWindowSize(UInt_t w, UInt_t h) override; void SetWindowTitle(const char *newTitle) override; void SetCanvasSize(UInt_t w, UInt_t h) override; void Iconify() override; void RaiseWindow() override; /* virtual void SetStatusText(const char *text = 0, Int_t partidx = 0); virtual void ReallyDelete(); */ Bool_t HasEditor() const override; Bool_t HasMenuBar() const override; Bool_t HasStatusBar() const override; Bool_t HasToolBar() const override { return kFALSE; } Bool_t HasToolTips() const override; void SetUpdatedHandler(UpdatedSignal_t func) { fUpdatedSignal = func; } void SetActivePadChangedHandler(PadSignal_t func) { fActivePadChangedSignal = func; } void SetPadClickedHandler(PadClickedSignal_t func) { fPadClickedSignal = func; } void SetPadDblClickedHandler(PadClickedSignal_t func) { fPadDblClickedSignal = func; } void SetObjSelectHandler(ObjectSelectSignal_t func) { fObjSelectSignal = func; } void SetCanCreateObjects(Bool_t on = kTRUE) { fCanCreateObjects = on; } Bool_t GetCanCreateObjects() const { return fCanCreateObjects; } void SetStyleDelivery(Int_t val) { fStyleDelivery = val; } Int_t GetStyleDelivery() const { return fStyleDelivery; } void SetPaletteDelivery(Int_t val) { fPaletteDelivery = val; } Int_t GetPaletteDelivery() const { return fPaletteDelivery; } void SetPrimitivesMerge(Int_t cnt) { fPrimitivesMerge = cnt; } Int_t GetPrimitivesMerge() const { return fPrimitivesMerge; } void SetLongerPolling(Bool_t on) { fLongerPolling = on; } Bool_t GetLongerPolling() const { return fLongerPolling; } void SetCustomScripts(const std::string &src); void AddCustomClass(const std::string &clname, bool with_derived = false); bool IsCustomClass(const TClass *cl) const; void SetAsyncMode(Bool_t on = kTRUE) { fAsyncMode = on; } Bool_t IsAsyncMode() const { return fAsyncMode; } Bool_t IsFixedSize() const { return fFixedSize; } static TString CreatePadJSON(TPad *pad, Int_t json_compression = 0, Bool_t batchmode = kFALSE); static TString CreateCanvasJSON(TCanvas *c, Int_t json_compression = 0, Bool_t batchmode = kFALSE); static Int_t StoreCanvasJSON(TCanvas *c, const char *filename, const char *option = ""); static bool ProduceImage(TPad *pad, const char *filename, Int_t width = 0, Int_t height = 0); static bool ProduceImages(std::vector pads, const char *filename, Int_t width = 0, Int_t height = 0); static TCanvasImp *NewCanvas(TCanvas *c, const char *name, Int_t x, Int_t y, UInt_t width, UInt_t height); ClassDefOverride(TWebCanvas, 0) // Web-based implementation for TCanvasImp }; #endif