KaliVeda
Toolkit for HIC analysis
KVListView.cpp
1 /*
2 $Id: KVListView.cpp,v 1.6 2009/04/28 09:11:29 franklan Exp $
3 $Revision: 1.6 $
4 $Date: 2009/04/28 09:11:29 $
5 */
6 
7 //Created by KVClassFactory on Wed Apr 9 11:51:38 2008
8 //Author: franklan
9 
10 #include "KVListView.h"
11 #include "TGButton.h"
12 #include "TVirtualX.h"
13 #include "TMath.h"
14 
16 
17 
18 
19 
25 KVListView::KVListView(TClass* obj_class, const TGWindow* p, UInt_t w, UInt_t h,
26  UInt_t options,
27  Pixel_t back)
28  : TGListView(p, w, h, options, back), nselected(0), fObjClass(obj_class)
29 {
30  // Create list view widget for objects of class obj_class.
31  // A KVLVContainer object is also created and set as the container in use.
32  // The view mode is set to kLVDetails (only one possible, no icons)
33  // Scrolling increments are set to 1 (vertical) & 19 (horizontal)
34 
35  SetContainer(new KVLVContainer(this, kHorizontalFrame, fgWhitePixel));
36  SetViewMode(kLVDetails);
37  SetIncrements(1, 19);
38  fMaxColumnSize = 100;
39  fContextMenu = new TContextMenu("fCurrentContext");
40  ((KVLVContainer*)GetContainer())->SetObjClass(fObjClass);
41 }
42 
43 
44 
47 
49 {
50  // Handle messages generated by the list view container
51  switch (GET_SUBMSG(msg)) {
52  case kCT_SELCHANGED:
53  // only emit signal if number selected has really changed
54  if ((int)parm2 != nselected) {
55  nselected = (int)parm2;
57  }
58  return kTRUE;
59  break;
60  default:
61  break;
62  }
63  return TGCanvas::ProcessMessage(msg, parm1, parm2);
64 }
65 
66 
67 
72 
74 {
75  // Connects the column header buttons (if defined) to the container's
76  // Sort(const Char_t*) method. Each button, when pressed, sends a "Clicked"
77  // signal which activates "Sort" with the name of the button/column as argument.
78 
79  TGTextButton** buttons = GetHeaderButtons();
80  if (buttons) {
81  for (int i = 0; i < (int)GetNumColumns(); i++) {
82  buttons[i]->Connect("Clicked()", "KVLVContainer",
83  GetContainer(), Form("Sort(=%d)", i));
84  }
85  }
86 }
87 
88 
89 
91 
93 {
94  TGListView::SetHeaders(ncolumns);
95  ((KVLVContainer*)GetContainer())->SetDataColumns(ncolumns);
96 }
97 
98 
99 
106 
107 void KVListView::SetDataColumn(Int_t index, const Char_t* name, const Char_t* method,
108  Int_t mode)
109 {
110  // Define column with index = 0, 1, ...
111  // name = name of column (shown in column header button)
112  // method = method to call to fill column with data (by default, "Getname")
113  // mode = text alignment for data in column (kTextCenterX [default], kTextLeft, kTextRight)
114  // column header name is always center aligned
116  ((KVLVContainer*)GetContainer())->SetDataColumn(index, fObjClass, name, method);
117 }
118 
119 
120 
124 
126 {
127  // Returns index of data column from its name.
128  // Return -1 if not found.
129 
130  for (Int_t idx = 0; idx < fNColumns - 1; idx++) {
131  if (fColHeader[idx]) {
132  if (fColNames[idx] == colname) return idx;
133  }
134  }
135  return -1;
136 }
137 
138 
139 
140 
145 
147 {
148  // Set default column width of the columns headers.
149  // Limit minimum size of a column to total width / number of columns
150  // If only one column it will span the whole viewport
151 
152  TGLVContainer* container = (TGLVContainer*) fVport->GetContainer();
153 
154  if (!container) {
155  KVError::Error(this, "SetDefaultColumnWidth", "no listview container set yet");
156  return;
157  }
158  container->ClearViewPort();
159  UInt_t minWidth = container->GetPageDimension().fWidth / (fNColumns - 1);
160 
161  for (int i = 0; i < fNColumns; ++i) {
162  if (fSplitHeader[i] == splitter) {
163  TString dt = fColHeader[i]->GetString();
164  UInt_t bsize = gVirtualX->TextWidth(fColHeader[i]->GetFontStruct(),
165  dt.Data(), dt.Length());
166  UInt_t w = TMath::Max(fColHeader[i]->GetDefaultWidth(), bsize + 20);
167  if (i == 0) {
168  //w = TMath::Max(fMaxSize.fWidth + 10, w);
169  w = TMath::Max(w, minWidth);
170  }
171  if (i > 0) {
172  w = TMath::Max(container->GetMaxSubnameWidth(i) + 40, (Int_t)w);
173  //printf("w=%ud\n",w);
174  //w = TMath::Min(w, fMaxColumnSize);
175  w = TMath::Max(w, minWidth);
176  }
177  fColHeader[i]->Resize(w, fColHeader[i]->GetHeight());
178  Layout();
179  }
180  }
181 }
182 
183 
184 
189 
191 {
192  // If list contains KVBase-derived objects, calling this method with yes=kTRUE
193  // will cause the string returned by the objects' KVBase::GetLabel() method
194  // to be used as the class name of the object
196 }
197 
198 
199 
200 
210 
211 void KVListView::SetDoubleClickAction(const char* receiver_class, void* receiver, const char* slot)
212 {
213  // Overrides the default 'double-click' action.
214  // By default, double-clicking on an object in the list will call the Browse(TBrowser*)
215  // method of the selected object.
216  // Use this method to override this behaviour.
217  // When an object is double-clicked the method 'slot' of the object 'receiver' of class
218  // 'receiver_class' will be called. The method in question must have the signature
219  // receiver_class::slot(TObject*)
220  // The address of the selected (T)object is passed as argument.
221 
222  ((KVLVContainer*)GetContainer())->SetDoubleClickAction(receiver_class, receiver, slot);
223 }
224 
225 
226 
235 
237 {
238  // The global context menu status (allowed or not allowed) is set by AllowContextMenu().
239  // If required, this can be overridden for specific classes by calling this
240  // method for each required class.
241  // In this case, any objects in the list of precisely this class (not derived classes)
242  // will have the opposite behaviour to that defined by AllowContextMenu(),
243  // i.e. if context menus are globally disabled, this method defines the classes for
244  // which a context menu is authorised, and vice-versa.
245 
247 }
248 
249 
int Int_t
unsigned int UInt_t
long Long_t
kHorizontalFrame
ULong_t Pixel_t
bool Bool_t
char Char_t
constexpr Bool_t kTRUE
kLVDetails
kTextCenterX
winID w
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char mode
char name[80]
char * Form(const char *fmt,...)
#define gVirtualX
kCT_SELCHANGED
Int_t GET_SUBMSG(Long_t val)
Extension of TGLVContainer for KVListView widget.
Enhanced version of ROOT TGListView widget.
Definition: KVListView.h:147
Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2) override
Handle messages generated by the list view container.
Definition: KVListView.cpp:48
virtual void ActivateSortButtons()
Definition: KVListView.cpp:73
virtual void SetDataColumns(Int_t ncolumns)
Definition: KVListView.cpp:92
void SetDoubleClickAction(const char *receiver_class, void *receiver, const char *slot)
Definition: KVListView.cpp:211
void AddContextMenuClassException(TClass *)
Definition: KVListView.cpp:236
virtual Int_t GetColumnNumber(const Char_t *colname)
Definition: KVListView.cpp:125
void SetDefaultColumnWidth(TGVFileSplitter *splitter) override
Definition: KVListView.cpp:146
virtual void SetDataColumn(Int_t index, const Char_t *name, const Char_t *method="", Int_t mode=kTextCenterX)
Definition: KVListView.cpp:107
void SetUseObjLabelAsRealClass(Bool_t yes=kTRUE)
Definition: KVListView.cpp:190
TGFrame * GetContainer() const
TGViewPort * fVport
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
virtual void ClearViewPort()
UInt_t fWidth
virtual UInt_t GetDefaultWidth() const
virtual void Resize(TGDimension size)
UInt_t GetHeight() const
virtual Int_t GetMaxSubnameWidth(Int_t idx) const
TGDimension GetPageDimension() const override
virtual void SetHeader(const char *s, Int_t hmode, Int_t cmode, Int_t idx)
void Layout() override
TGTextButton ** GetHeaderButtons()
Int_t fNColumns
virtual void SetHeaders(Int_t ncolumns)
UInt_t GetNumColumns()
TString * fColNames
virtual void SelectionChanged()
TGTextButton ** fColHeader
TGVFileSplitter ** fSplitHeader
TString GetString() const
TGFrame * GetContainer() const
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Ssiz_t Length() const
const char * Data() const
void Error(UserClass p, const char *location, const char *va_(fmt),...)
Definition: KVError.h:116
Double_t Max(Double_t a, Double_t b)
ClassImp(TPyArg)
double splitter