Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TWebControlBar.cxx
Go to the documentation of this file.
1// Author: Sergey Linev, GSI 15/12/2022
2
3/*************************************************************************
4 * Copyright (C) 1995-2022, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include "TWebControlBar.h"
12
13#include "TROOT.h"
14#include "TBufferJSON.h"
15#include "TControlBar.h"
16#include "TControlBarButton.h"
17#include "TList.h"
18
19#include <vector>
20#include <string>
21
22/** \class TWebControlBar
23\ingroup webgui6
24\ingroup webwidgets
25
26\brief Web-based implementation for TControlBar class
27
28*/
29
30using namespace std::string_literals;
31
32////////////////////////////////////////////////////////////////////////////////
33/// Constructor
34
36 : TControlBarImp(bar, title, x, y)
37{
38}
39
40//////////////////////////////////////////////////////////////////////////////////////////////////
41/// Send initial message with buttons configuration
42
43void TWebControlBar::SendInitMsg(unsigned connid)
44{
45 if (!fWindow)
46 return;
47
48 auto lst = fControlBar->GetListOfButtons();
49
50 std::vector<std::string> btns;
51
53 btns.emplace_back("horizontal");
54 else
55 btns.emplace_back("vertical");
56
57 btns.emplace_back(fControlBar->GetName());
58
59 TIter iter(lst);
60 while (auto btn = iter()) {
61 btns.emplace_back(btn->GetName());
62 btns.emplace_back(btn->GetTitle());
63 }
64
65 if (btns.size() == 0)
66 return;
67
68 std::string buf = "BTNS:";
69 buf.append(TBufferJSON::ToJSON(&btns).Data());
70
71 fWindow->Send(connid, buf);
72}
73
74//////////////////////////////////////////////////////////////////////////////////////////
75/// Handle data from web browser
76/// Returns kFALSE if message was not processed
77
78Bool_t TWebControlBar::ProcessData(unsigned connid, const std::string &arg)
79{
80 if (arg.empty())
81 return kTRUE;
82
83 if (arg.compare(0, 6, "CLICK:") == 0) {
84 auto id = std::stoi(arg.substr(6));
85
86 auto lst = fControlBar->GetListOfButtons();
87
88 auto btn = dynamic_cast<TControlBarButton *>(lst->At(id));
89
90 if (btn) {
91 printf("Click btn %s act %s\n", btn->GetName(), btn->GetAction());
92 btn->Action();
93 }
94
95 } else {
96 printf("Get msg %s from conn %u\n", arg.c_str(), connid);
97 }
98
99 return kTRUE;
100}
101
102//////////////////////////////////////////////////////////////////////////////////////////
103/// Hide control bar
104
106{
107 if (fWindow)
108 fWindow->CloseConnections();
109}
110
111
112//////////////////////////////////////////////////////////////////////////////////////////
113/// Show canvas in browser window
114
116{
117 if (gROOT->IsWebDisplayBatch())
118 return;
119
120 if (!fWindow) {
122
123 fWindow->SetConnLimit(1); // configure connections limit
124
125 fWindow->SetDefaultPage("file:rootui5sys/canv/ctrlbar.html");
126
127 fWindow->SetCallBacks(
128 // connection
129 [this](unsigned connid) {
130 SendInitMsg(connid);
131 },
132 // data
133 [this](unsigned connid, const std::string &arg) {
134 ProcessData(connid, arg);
135 });
136 }
137
139 args.SetWidgetKind("TControlBar");
140
141 auto lst = fControlBar->GetListOfButtons();
142 int nbtns = 0, maxlen = 0, totallen = 0;
143 TIter iter(lst);
144 while (auto btn = iter()) {
145 nbtns++;
146 int len = strlen(btn->GetName());
147 totallen += len;
148 if (len > maxlen)
149 maxlen = len;
150 }
151
152 int w = 100, h = 50;
153
154 if (nbtns > 0) {
156 w = totallen*10 + nbtns*20;
157 h = 35;
158 } else {
159 w = maxlen*10 + 10;
160 h = nbtns*30 + 30;
161 }
162 }
163 fWindow->SetGeometry(w, h);
164
165 fWindow->Show(args);
166}
167
168
169//////////////////////////////////////////////////////////////////////////////////////////////////
170/// Static method to create TWebControlBar instance
171/// Used by plugin manager
172
174{
175 return new TWebControlBar(bar, title, x, y);
176}
177
#define h(i)
Definition RSha256.hxx:106
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
#define gROOT
Definition TROOT.h:406
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
RWebDisplayArgs & SetWidgetKind(const std::string &kind)
set widget kind
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
Definition TBufferJSON.h:75
This class defines the control bar buttons.
ABC describing GUI independent control bar.
TControlBar * fControlBar
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition TControlBar.h:26
Int_t GetOrientation() const
Definition TControlBar.h:60
TList * GetListOfButtons() const
Definition TControlBar.h:57
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Web-based implementation for TControlBar class.
TWebControlBar(TControlBar *bar, const char *title, Int_t x, Int_t y)
Constructor.
std::shared_ptr< ROOT::RWebWindow > fWindow
void Hide() override
Hide control bar.
Bool_t ProcessData(unsigned connid, const std::string &arg)
Handle data from web browser Returns kFALSE if message was not processed.
void Show() override
Show canvas in browser window.
void SendInitMsg(unsigned connid)
!< configured display
static TControlBarImp * NewControlBar(TControlBar *bar, const char *title, Int_t x, Int_t y)
Static method to create TWebControlBar instance Used by plugin manager.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17