KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVLVEntry.cpp
1/*
2$Id: KVLVEntry.cpp,v 1.3 2009/04/28 09:11:29 franklan Exp $
3$Revision: 1.3 $
4$Date: 2009/04/28 09:11:29 $
5*/
6
7//Created by KVClassFactory on Wed Apr 9 13:55:03 2008
8//Author: franklan
9
10#include "KVLVEntry.h"
11#include "TInterpreter.h"
12#include "TMethodCall.h"
13#include "TGPicture.h"
14#include "TGResourcePool.h"
15#include "TGTextEntry.h"
16#include "TVirtualX.h"
17
19
20
23
24
27
29 UInt_t ncols, KVLVColumnData** coldata)
30 : TGLVEntry(cnt, TString(coldata[0]->GetDataString(obj)),
31 TString(obj->ClassName()), 0, kVerticalFrame, GetWhitePixel()), fDisconnectRefresh(kFALSE)
32{
33 // Default constructor
35 if (!fgGreyPixel) {
36 if (!fClient->GetColorByName("#f0f0f0", fgGreyPixel)) fgGreyPixel = 0;
38 }
39 fBGColor = -1;
40
41 fUserData = obj;
42 fSubnames = new TGString* [ncols];
43 fBoolean = new Bool_t [ncols];
44 for (int i = 0; i < (int)ncols - 1; i++) {
45 fSubnames[i] = new TGString(coldata[i + 1]->GetDataString(obj));
46 fBoolean[i] = coldata[i + 1]->IsBoolean();
47 }
48 fSubnames[ncols - 1] = 0;
49 fBoolean[ncols - 1] = kFALSE;
50 int j;
51 for (j = 0; fSubnames[j] != 0; ++j)
52 ;
53 fCtw = new int[j + 1];
54 fCtw[j] = 0;
55 for (int i = 0; fSubnames[i] != 0; ++i)
56 fCtw[i] = gVirtualX->TextWidth(fFontStruct, fSubnames[i]->GetString(),
57 fSubnames[i]->GetLength());
59
60 // to update display of object characteristics when object is changed,
61 // the object must have a "Connect" method (for signals-slots) and a "Modified"
62 // method which emits the "Modified" signal when object is changed.
63 // N.B. the object does not have to inherit from TQObject (can use RQ_OBJECT macro)
64 // the "Modified" signal is connected to the KVLVEntry::Refresh method
65 if (obj->IsA()->GetMethodAllAny("Modified") && obj->IsA()->GetMethodAllAny("Connect")) {
66 gInterpreter->Execute(obj, obj->IsA(), "Connect",
67 Form("\"Modified()\",\"KVLVEntry\",(KVLVEntry*)%ld,\"Refresh()\"", (ULong_t)this));
69 }
70
72 // objects of classes with a method "const Char_t* GetLVEntryColour()" will be displayed with
73 // the background colour returned by this method (either in hexadecimal format, i.e. "#f0f0f0"
74 // or by name, i.e. "pink")
75 if (obj->IsA()->GetMethodAllAny("GetLVEntryColour")) {
76
77 TMethodCall mt;
78 mt.InitWithPrototype(obj->IsA(), "GetLVEntryColour", "");
79 if (mt.IsValid()) {
80 if (mt.ReturnType() == TMethodCall::kString) {
81 Char_t* ret;
82 mt.Execute(obj, "", &ret);
83 if (fClient->GetColorByName(ret, fBGColor)) {
85 }
86 else {
87 Warning("KVLVEntry", "Unknown color %s requested for entry", ret);
88 }
89 }
90 else {
91 Warning("KVLVEntry", "Object of class %s has GetLVEntryColour() method with wrong return type",
92 obj->ClassName());
93 }
94 }
95 else {
96 Warning("KVLVEntry", "GetLVEntryColour() method not valid for class %s", obj->ClassName());
97 }
98 }
99}
100
101
102
106
107KVLVEntry::KVLVEntry(TObject* obj, const Char_t* objclass, const KVLVContainer* cnt, UInt_t ncols, KVLVColumnData** coldata)
108 : TGLVEntry(cnt, TString(coldata[0]->GetDataString(obj)),
109 TString(objclass), 0, kVerticalFrame, GetWhitePixel()), fDisconnectRefresh(kFALSE)
110{
111 // Exactly same as default constructor, but class of object used by TGLVEntry is given separately,
112 // not neccessarily the same as obj->ClassName()
113
115 if (!fgGreyPixel) {
116 if (!fClient->GetColorByName("#f0f0f0", fgGreyPixel)) fgGreyPixel = 0;
118 }
119 fBGColor = -1;
120
121 fUserData = obj;
122 fSubnames = new TGString* [ncols];
123 fBoolean = new Bool_t [ncols];
124 for (int i = 0; i < (int)ncols - 1; i++) {
125 fSubnames[i] = new TGString(coldata[i + 1]->GetDataString(obj));
126 fBoolean[i] = coldata[i + 1]->IsBoolean();
127 }
128 fSubnames[ncols - 1] = 0;
129 fBoolean[ncols - 1] = kFALSE;
130 int j;
131 for (j = 0; fSubnames[j] != 0; ++j)
132 ;
133 fCtw = new int[j + 1];
134 fCtw[j] = 0;
135 for (int i = 0; fSubnames[i] != 0; ++i)
136 fCtw[i] = gVirtualX->TextWidth(fFontStruct, fSubnames[i]->GetString(),
137 fSubnames[i]->GetLength());
139
140 // to update display of object characteristics when object is changed,
141 // the object must have a "Connect" method (for signals-slots) and a "Modified"
142 // method which emits the "Modified" signal when object is changed.
143 // N.B. the object does not have to inherit from TQObject (can use RQ_OBJECT macro)
144 // the "Modified" signal is connected to the KVLVEntry::Refresh method
145 if (obj->IsA()->GetMethodAllAny("Modified") && obj->IsA()->GetMethodAllAny("Connect")) {
146 gInterpreter->Execute(obj, obj->IsA(), "Connect",
147 Form("\"Modified()\",\"KVLVEntry\",(KVLVEntry*)%ld,\"Refresh()\"", (ULong_t)this));
149 }
150}
151
152
153
157
159{
160 // Dtor
161 // disconnect fUserData object's Modified signal from our Refresh method if connected
162 delete [] fBoolean;
164 TObject* obj = (TObject*)fUserData;
165 if (obj && obj->TestBit(kNotDeleted)) gInterpreter->Execute(obj, obj->IsA(), "Disconnect",
166 Form("\"Modified()\",(KVLVEntry*)%ld,\"Refresh()\"", (ULong_t)this));
167 }
168}
169
170
171
174
176{
177 // Update the object characteristics and ask for redraw
178
180 TObject* obj = (TObject*)fUserData;
181 SetItemName(cnt->fColData[0]->GetDataString(obj));
182 for (int i = 0; fSubnames[i] != 0; i++) fSubnames[i]->SetString(cnt->fColData[i + 1]->GetDataString(obj));
183 for (int i = 0; fSubnames[i] != 0; ++i)
184 fCtw[i] = gVirtualX->TextWidth(fFontStruct, fSubnames[i]->GetString(),
185 fSubnames[i]->GetLength());
187 TGPosition pos = cnt->GetPagePosition();
188 cnt->DrawRegion(GetX() - pos.fX, GetY() - pos.fY, GetWidth(), GetHeight());
189}
190
191
192
193
205
207{
208 // Draw list view item in other window.
209 // List view item is placed and layout in the container frame,
210 // but is drawn in viewport.
211 //
212 // This is a line for line copy of TGLVEntry::DrawCopy from ROOT v5.22/00,
213 // but we alternate the background colour between white and light grey, in
214 // order to make the list easier to read.
215 //
216 // If fColoured=kTRUE (i.e. if entry has a valid GetLVEntryColor method
217 // which returns a recognised color), the requested background color is used
218
220 if (!fColoured) {
221 if ((int)fBGColor == -1 || cnt->IsBeingSorted()) {
224 else
226 }
227 }
228
229 Int_t ix, iy, lx, ly;
230 Int_t max_ascent, max_descent;
231
232 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
234 fTHeight = max_ascent + max_descent;
235
236 if (fViewMode == kLVLargeIcons) {
237 ix = (fWidth - fCurrent->GetWidth()) >> 1;
238 iy = 0;
239 lx = (fWidth - fTWidth) >> 1;
240 ly = fHeight - (fTHeight + 1) - 2;
241 }
242 else {
243 ix = 0;
244 iy = (fHeight - fCurrent->GetHeight()) >> 1;
245 lx = fCurrent->GetWidth() + 2;
246 ly = (fHeight - (fTHeight + 1)) >> 1;
247 }
248
249 // if ((fChecked) && (fCheckMark)) {
250 // if (fViewMode == kLVLargeIcons) {
251 // fCheckMark->Draw(id, fNormGC, x + ix + 8, y + iy + 8);
252 // gVirtualX->SetForeground(fNormGC, fgWhitePixel);
253 // gVirtualX->FillRectangle(id, fNormGC, x + lx, y + ly, fTWidth, fTHeight + 1);
254 // gVirtualX->SetForeground(fNormGC, fgBlackPixel);
255 // }
256 // else {
257 // fCheckMark->Draw(id, fNormGC, x + ix, y + iy);
258 // gVirtualX->SetForeground(fNormGC, fgWhitePixel);
259 // gVirtualX->FillRectangle(id, fNormGC, x + lx, y + ly, fTWidth, fTHeight + 1);
260 // gVirtualX->SetForeground(fNormGC, fgBlackPixel);
261 // }
262 // }
263 // This if tries to print the elements with ... appened at the end if
264 // the widht of the string is longer than that of the column
265 if (fViewMode == kLVDetails && fSubnames && fCpos && fJmode && fCtw) {
266 TString tmpString = *fItemName;
267 Int_t ftmpWidth = gVirtualX->TextWidth(fFontStruct, tmpString,
268 tmpString.Length());
269 if (ftmpWidth > (fCpos[0] - lx)) {
270 for (Int_t j = fItemName->Length() - 1 ; j > 0; j--) {
271 tmpString = (*fItemName)(0, j) + "...";
272 ftmpWidth = gVirtualX->TextWidth(GetDefaultFontStruct(), tmpString,
273 tmpString.Length());
274 if (ftmpWidth <= (fCpos[0] - lx)) {
275 break;
276 }
277 }
278 }
279 if (fActive) {
280 if (fSelPic) fSelPic->Draw(id, fNormGC, x + ix, y + iy);
282 gVirtualX->FillRectangle(id, fNormGC, x + lx, y + ly, fCpos[0] - lx, fTHeight + 1);
284 }
285 else {
286 // inactive list items are drawn with alternating background colours: white, grey, white, grey, ...
287 fCurrent->Draw(id, fNormGC, x + ix, y + iy);
288 //gVirtualX->SetForeground(fNormGC, fgWhitePixel);
289 gVirtualX->SetForeground(fNormGC, fBGColor);// use current background colour
290 gVirtualX->FillRectangle(id, fNormGC, x + lx, y + ly, fCpos[0] - lx, fTHeight + 1);
291 gVirtualX->SetForeground(fNormGC, fgBlackPixel);
292 }
293 TGString tmpTGString(tmpString);
294 tmpTGString.Draw(id, fNormGC, x + lx, y + ly + max_ascent);
295 }
296 else {
297 if (fActive) {
298 if (fSelPic) fSelPic->Draw(id, fNormGC, x + ix, y + iy);
300 gVirtualX->FillRectangle(id, fNormGC, x + lx, y + ly, fTWidth, fTHeight + 1);
302 }
303 else {
304 fCurrent->Draw(id, fNormGC, x + ix, y + iy);
305 gVirtualX->SetForeground(fNormGC, fgWhitePixel);
306 gVirtualX->FillRectangle(id, fNormGC, x + lx, y + ly, fTWidth, fTHeight + 1);
307 gVirtualX->SetForeground(fNormGC, fgBlackPixel);
308 }
309 fItemName->Draw(id, fNormGC, x + lx, y + ly + max_ascent);
310 }
311 gVirtualX->SetForeground(fNormGC, fgBlackPixel);
312
313 if (fViewMode == kLVDetails) {
314 if (fSubnames && fCpos && fJmode && fCtw) {
315 int i;
316
317 // Again fixes the size of the strings
318 for (i = 0; fSubnames[i] != 0; ++i) {
319 TString tmpString = *fSubnames[i];
320 Int_t ftmpWidth = gVirtualX->TextWidth(fFontStruct, tmpString,
321 tmpString.Length());
322 if (ftmpWidth > (fCpos[i + 1] - fCpos[i])) {
323 for (int j = fSubnames[i]->Length() - 1 ; j > 0; j--) {
324 tmpString = (*fSubnames[i])(0, j) + "...";
325 ftmpWidth = gVirtualX->TextWidth(GetDefaultFontStruct(),
326 tmpString,
327 tmpString.Length());
328 if (ftmpWidth <= (fCpos[i + 1] - fCpos[i])) {
329 break;
330 }
331 }
332 }
333 if (fCpos[i] == 0)
334 break;
335 if (fJmode[i] == kTextRight)
336 lx = fCpos[i + 1] - ftmpWidth - 2;
337 else if (fJmode[i] == kTextCenterX)
338 lx = (fCpos[i] + fCpos[i + 1] - ftmpWidth) >> 1;
339 else // default to TEXT_LEFT
340 lx = fCpos[i] + 2;
341
342 //if (x + lx < 0) continue; // out of left boundary or mess in name
343 if (fActive) {
344 //if (fSelPic) fSelPic->Draw(id, fNormGC, x + ix, y + iy);
346 gVirtualX->FillRectangle(id, fNormGC, x + fCpos[i], y + ly, fCpos[i + 1] - fCpos[i], fTHeight + 1);
348 }
349 else {
350 // inactive list items are drawn with alternating background colours: white, grey, white, grey, ...
351 //fCurrent->Draw(id, fNormGC, x + ix, y + iy);
352 //gVirtualX->SetForeground(fNormGC, fgWhitePixel);
353 gVirtualX->SetForeground(fNormGC, fBGColor);// use current background colour
354 gVirtualX->FillRectangle(id, fNormGC, x + fCpos[i], y + ly, fCpos[i + 1] - fCpos[i], fTHeight + 1);
355 gVirtualX->SetForeground(fNormGC, fgBlackPixel);
356 }
357 if (fBoolean[i]) {
358 if (tmpString == "1" && fCheckMark) {
359 // boolean column data drawn with a tick mark
360 fCheckMark->Draw(id, fNormGC, x + lx, y + ly);
361 }
362 }
363 else {
364 TGString tmpTGString(tmpString);
365 tmpTGString.Draw(id, fNormGC, x + lx, y + ly + max_ascent);
366 }
367 }
368 }
369 }
370
371}
372
373
int Int_t
unsigned int UInt_t
unsigned long ULong_t
kVerticalFrame
ULong_t Pixel_t
ULongptr_t Handle_t
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
kLVDetails
kLVLargeIcons
kTextCenterX
kTextRight
#define gInterpreter
char * Form(const char *fmt,...)
#define gVirtualX
Utility class describing the data used to fill each column of the list view container.
virtual Bool_t IsBoolean() const
Extension of TGLVContainer for KVListView widget.
One item/line in a KVListView window.
Definition KVLVEntry.h:65
Bool_t * fBoolean
'IsBoolean' attribute of each column
Definition KVLVEntry.h:75
virtual void DrawCopy(Handle_t id, Int_t x, Int_t y)
Bool_t fEditMode
Definition KVLVEntry.h:68
KVLVEntry(TObject *obj, const KVLVContainer *cnt, UInt_t ncols, KVLVColumnData **coldata)
Default constructor.
Definition KVLVEntry.cpp:28
virtual void Refresh()
Update the object characteristics and ask for redraw.
Pixel_t fBGColor
background color of this item
Definition KVLVEntry.h:73
static Pixel_t fgBGColor
current background color for items
Definition KVLVEntry.h:71
static Pixel_t fgGreyPixel
light grey color used to distinguish adjacent list items
Definition KVLVEntry.h:72
virtual ~KVLVEntry()
Bool_t fDisconnectRefresh
disconnect object's Modified method from this object's Refresh when deleted
Definition KVLVEntry.h:77
Bool_t fColoured
=kTRUE if object has an associated color
Definition KVLVEntry.h:69
TMethod * GetMethodAllAny(const char *method)
const TGResourcePool * GetResourcePool() const
Bool_t GetColorByName(const char *name, Pixel_t &pixel) const
UInt_t fHeight
static Pixel_t fgDefaultSelectedBackground
Int_t GetX() const
UInt_t fWidth
UInt_t GetHeight() const
Int_t GetY() const
static Pixel_t fgWhitePixel
UInt_t GetWidth() const
static Pixel_t fgBlackPixel
const TGPicture * fCurrent
void * fUserData
UInt_t fTHeight
void SetItemName(const char *name)
TGString ** fSubnames
Int_t * fCpos
UInt_t fTWidth
Bool_t fActive
FontStruct_t fFontStruct
EListViewMode fViewMode
GContext_t fNormGC
TGString * fItemName
Int_t * fCtw
TGSelectedPicture * fSelPic
Int_t * fJmode
static FontStruct_t GetDefaultFontStruct()
const TGPicture * fCheckMark
TGClient * fClient
virtual void Draw(Handle_t id, GContext_t gc, Int_t x, Int_t y) const
UInt_t GetHeight() const
UInt_t GetWidth() const
Pixel_t GetSelectedFgndColor() const
Int_t GetLength() const
const char * GetString() const
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
virtual void SetWindowName(const char *name=nullptr)
const TGWindow * GetParent() const
EReturnType ReturnType()
void InitWithPrototype(const char *function, const char *proto, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
static const EReturnType kString
Bool_t IsValid() const
void Execute()
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual const char * ClassName() const
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual TClass * IsA() const
Ssiz_t Length() const
RooCmdArg ClassName(const char *name)
Double_t y[n]
Double_t x[n]
const char * cnt
ClassImp(TPyArg)