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
25Web-based implementation for TControlBar class
26
27*/
28
29using namespace std::string_literals;
30
31////////////////////////////////////////////////////////////////////////////////
32/// Constructor
33
35 : TControlBarImp(bar, title, x, y)
36{
37}
38
39//////////////////////////////////////////////////////////////////////////////////////////////////
40/// Send initial message with buttons configuration
41
42void TWebControlBar::SendInitMsg(unsigned connid)
43{
44 if (!fWindow)
45 return;
46
47 auto lst = fControlBar->GetListOfButtons();
48
49 std::vector<std::string> btns;
50
52 btns.emplace_back("horizontal");
53 else
54 btns.emplace_back("vertical");
55
56 btns.emplace_back(fControlBar->GetName());
57
58 TIter iter(lst);
59 while (auto btn = iter()) {
60 btns.emplace_back(btn->GetName());
61 btns.emplace_back(btn->GetTitle());
62 }
63
64 if (btns.size() == 0)
65 return;
66
67 std::string buf = "BTNS:";
68 buf.append(TBufferJSON::ToJSON(&btns).Data());
69
70 fWindow->Send(connid, buf);
71}
72
73//////////////////////////////////////////////////////////////////////////////////////////
74/// Handle data from web browser
75/// Returns kFALSE if message was not processed
76
77Bool_t TWebControlBar::ProcessData(unsigned connid, const std::string &arg)
78{
79 if (arg.empty())
80 return kTRUE;
81
82 if (arg.compare(0, 6, "CLICK:") == 0) {
83 auto id = std::stoi(arg.substr(6));
84
85 auto lst = fControlBar->GetListOfButtons();
86
87 auto btn = dynamic_cast<TControlBarButton *>(lst->At(id));
88
89 if (btn) {
90 printf("Click btn %s act %s\n", btn->GetName(), btn->GetAction());
91 btn->Action();
92 }
93
94 } else {
95 printf("Get msg %s from conn %u\n", arg.c_str(), connid);
96 }
97
98 return kTRUE;
99}
100
101//////////////////////////////////////////////////////////////////////////////////////////
102/// Hide control bar
103
105{
106 if (fWindow)
107 fWindow->CloseConnections();
108}
109
110
111//////////////////////////////////////////////////////////////////////////////////////////
112/// Show canvas in browser window
113
115{
116 if (gROOT->IsWebDisplayBatch())
117 return;
118
119 if (!fWindow) {
121
122 fWindow->SetConnLimit(1); // configure connections limit
123
124 fWindow->SetDefaultPage("file:rootui5sys/canv/ctrlbar.html");
125
126 fWindow->SetCallBacks(
127 // connection
128 [this](unsigned connid) {
129 SendInitMsg(connid);
130 },
131 // data
132 [this](unsigned connid, const std::string &arg) {
133 ProcessData(connid, arg);
134 });
135 }
136
138 args.SetWidgetKind("TControlBar");
139
140 auto lst = fControlBar->GetListOfButtons();
141 int nbtns = 0, maxlen = 0, totallen = 0;
142 TIter iter(lst);
143 while (auto btn = iter()) {
144 nbtns++;
145 int len = strlen(btn->GetName());
146 totallen += len;
147 if (len > maxlen)
148 maxlen = len;
149 }
150
151 int w = 100, h = 50;
152
153 if (nbtns > 0) {
155 w = totallen*10 + nbtns*20;
156 h = 35;
157 } else {
158 w = maxlen*10 + 10;
159 h = nbtns*30 + 30;
160 }
161 }
162 fWindow->SetGeometry(w, h);
163
164 fWindow->Show(args);
165}
166
167
168//////////////////////////////////////////////////////////////////////////////////////////////////
169/// Static method to create TWebControlBar instance
170/// Used by plugin manager
171
173{
174 return new TWebControlBar(bar, title, x, y);
175}
176
#define h(i)
Definition RSha256.hxx:106
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
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:407
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