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