1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
// -*- C++ -*-
//
// Package: TableWidget
// Class : FWTableWidget
//
// Implementation:
// <Notes on implementation>
//
// Original Author: Chris Jones
// Created: Mon Feb 2 16:45:42 EST 2009
//
// system include files
#include <iostream>
#include "TGScrollBar.h"
#include "TGTableLayout.h"
#include "TGResourcePool.h"
// user include files
#include "Fireworks/TableWidget/interface/FWTableWidget.h"
#include "Fireworks/TableWidget/interface/FWTableManagerBase.h"
#include "Fireworks/TableWidget/interface/FWTabularWidget.h"
#include "Fireworks/TableWidget/src/FWAdapterHeaderTableManager.h"
#include "Fireworks/TableWidget/src/FWAdapterRowHeaderTableManager.h"
//
// constants, enums and typedefs
//
static const UInt_t kRowOptions =
static_cast<UInt_t>(kLHintsExpandX) | static_cast<UInt_t>(kLHintsFillX) | static_cast<UInt_t>(kLHintsShrinkX);
static const UInt_t kColOptions =
static_cast<UInt_t>(kLHintsExpandY) | static_cast<UInt_t>(kLHintsFillY) | static_cast<UInt_t>(kLHintsShrinkY);
//
// static data member definitions
//
//
// constructors and destructor
//
FWTableWidget::FWTableWidget(FWTableManagerBase* iManager, const TGWindow* p)
: TGCompositeFrame(p),
m_bodyTable(iManager),
m_headerTable(iManager->hasLabelHeaders() ? new FWAdapterHeaderTableManager(iManager)
: static_cast<FWTableManagerBase*>(nullptr)),
m_rowHeaderTable(iManager->hasRowHeaders() ? new FWAdapterRowHeaderTableManager(iManager)
: static_cast<FWTableManagerBase*>(nullptr)),
m_header(nullptr),
m_rowHeader(nullptr),
m_showingVSlider(true),
m_showingHSlider(true),
m_sortedColumn(-1),
m_descendingSort(true),
m_forceLayout(false),
m_headerBackground(nullptr),
m_headerForeground(nullptr),
m_lineSeparator(nullptr) {
SetLayoutManager(new TGTableLayout(this, 3, 3));
if (nullptr != m_headerTable) {
m_header = new FWTabularWidget(m_headerTable, this);
AddFrame(m_header, new TGTableLayoutHints(1, 2, 0, 1, kLHintsTop | kLHintsLeft | kRowOptions));
if (m_bodyTable->cellDataIsSortable())
m_header->Connect("buttonReleased(Int_t,Int_t,Event_t*,Int_t,Int_t)",
"FWTableWidget",
this,
"buttonReleasedInHeader(Int_t,Int_t,Event_t*,Int_t,Int_t)");
}
m_body = new FWTabularWidget(iManager, this, GetWhiteGC()());
//m_body->SetBackgroundColor(kWidgetColor);
AddFrame(m_body, new TGTableLayoutHints(1, 2, 1, 2, kLHintsTop | kLHintsLeft | kRowOptions | kColOptions));
m_body->Connect("buttonReleased(Int_t,Int_t,Event_t*,Int_t,Int_t)",
"FWTableWidget",
this,
"buttonReleasedInBody(Int_t,Int_t,Event_t*,Int_t,Int_t)");
//set sizes
std::vector<unsigned int> columnWidths = m_body->widthOfTextInColumns();
if (nullptr != m_header) {
std::vector<unsigned int> headerWidths = m_header->widthOfTextInColumns();
for (std::vector<unsigned int>::iterator it = columnWidths.begin(),
itEnd = columnWidths.end(),
itHeader = headerWidths.begin();
it != itEnd;
++it, ++itHeader) {
if (*itHeader > *it) {
*it = *itHeader;
}
}
}
if (nullptr != m_header) {
m_header->setWidthOfTextInColumns(columnWidths);
}
m_body->setWidthOfTextInColumns(columnWidths);
if (m_rowHeaderTable) {
m_rowHeader = new FWTabularWidget(m_rowHeaderTable, this, GetWhiteGC()());
//m_rowHeader->SetBackgroundColor(kWidgetColor);
AddFrame(m_rowHeader, new TGTableLayoutHints(0, 1, 1, 2, kLHintsTop | kLHintsLeft | kColOptions));
m_rowHeader->Connect("buttonReleased(Int_t,Int_t,Event_t*,Int_t,Int_t)",
"FWTableWidget",
this,
"buttonReleasedInBody(Int_t,Int_t,Event_t*,Int_t,Int_t)");
m_rowHeader->Connect("buttonReleased(Int_t,Int_t,Event_t*,Int_t,Int_t)",
"FWTableWidget",
this,
"buttonReleasedInRowHeader(Int_t,Int_t,Event_t*,Int_t,Int_t)");
m_rowHeader->setWidthOfTextInColumns(m_rowHeader->widthOfTextInColumns());
}
m_hSlider = new TGHScrollBar(this);
AddFrame(m_hSlider, new TGTableLayoutHints(1, 2, 2, 3, kRowOptions));
m_hSlider->Connect("ProcessedEvent(Event_t*)", "FWTableWidget", this, "childrenEvent(Event_t *)");
m_vSlider = new TGVScrollBar(this);
m_vSlider->SetSmallIncrement(12);
AddFrame(m_vSlider, new TGTableLayoutHints(2, 3, 1, 2, kColOptions));
m_vSlider->Connect("ProcessedEvent(Event_t*)", "FWTableWidget", this, "childrenEvent(Event_t *)");
MapSubwindows();
Layout();
//HideFrame(m_hSlider);
//HideFrame(m_vSlider);
m_hSlider->Associate(this);
m_vSlider->Associate(this);
m_hSlider->SetEditDisabled(kEditDisable | kEditDisableGrab | kEditDisableBtnEnable);
m_vSlider->SetEditDisabled(kEditDisable | kEditDisableGrab | kEditDisableBtnEnable);
m_bodyTable->Connect("dataChanged()", "FWTableWidget", this, "dataChanged()");
}
// FWTableWidget::FWTableWidget(const FWTableWidget& rhs)
// {
// // do actual copying here;
// }
FWTableWidget::~FWTableWidget() {
if (nullptr != m_headerBackground) {
gClient->GetResourcePool()->GetGCPool()->FreeGC(m_headerBackground->GetGC());
}
if (nullptr != m_headerForeground) {
gClient->GetResourcePool()->GetGCPool()->FreeGC(m_headerForeground->GetGC());
}
if (nullptr != m_lineSeparator) {
gClient->GetResourcePool()->GetGCPool()->FreeGC(m_lineSeparator->GetGC());
}
}
//
// assignment operators
//
// const FWTableWidget& FWTableWidget::operator=(const FWTableWidget& rhs)
// {
// //An exception safe implementation is
// FWTableWidget temp(rhs);
// swap(rhs);
//
// return *this;
// }
//
// member functions
//
void FWTableWidget::sort(UInt_t iColumn, bool iDescendingSort) {
if (nullptr != m_headerTable) {
m_headerTable->sort(iColumn, iDescendingSort);
}
m_bodyTable->sort(iColumn, iDescendingSort);
m_sortedColumn = iColumn;
m_descendingSort = iDescendingSort;
//fClient->NeedRedraw(m_header);
//fClient->NeedRedraw(m_body);
}
void FWTableWidget::SetBackgroundColor(Pixel_t iColor) {
TGFrame::SetBackgroundColor(iColor);
if (m_rowHeaderTable) {
m_rowHeader->SetBackgroundColor(iColor);
fClient->NeedRedraw(m_rowHeader);
}
if (m_header) {
m_header->SetBackgroundColor(iColor);
fClient->NeedRedraw(m_header);
}
m_body->SetBackgroundColor(iColor);
fClient->NeedRedraw(m_body);
fClient->NeedRedraw(this);
}
void FWTableWidget::SetHeaderBackgroundColor(Pixel_t iColor) {
if (nullptr == m_headerBackground) {
GCValues_t t = *(gClient->GetResourcePool()->GetFrameGC()->GetAttributes());
m_headerBackground = gClient->GetResourcePool()->GetGCPool()->GetGC(&t, kTRUE);
}
m_headerBackground->SetForeground(iColor);
if (nullptr != m_header) {
m_header->setBackgroundAreaContext((*m_headerBackground)());
}
}
void FWTableWidget::SetHeaderForegroundColor(Pixel_t iColor) {
if (nullptr == m_headerForeground) {
GCValues_t t = *(gClient->GetResourcePool()->GetFrameGC()->GetAttributes());
m_headerForeground = gClient->GetResourcePool()->GetGCPool()->GetGC(&t, kTRUE);
}
m_headerForeground->SetForeground(iColor);
if (nullptr != m_header) {
m_header->setLineContext((*m_headerForeground)());
}
}
void FWTableWidget::SetLineSeparatorColor(Pixel_t iColor) {
if (nullptr == m_lineSeparator) {
GCValues_t t = *(gClient->GetResourcePool()->GetFrameGC()->GetAttributes());
m_lineSeparator = gClient->GetResourcePool()->GetGCPool()->GetGC(&t, kTRUE);
}
m_lineSeparator->SetForeground(iColor);
m_body->setLineContext((*m_lineSeparator)());
if (m_rowHeader) {
m_rowHeader->setLineContext((*m_lineSeparator)());
}
}
void FWTableWidget::Resize(UInt_t w, UInt_t h) {
handleResize(w, h);
TGCompositeFrame::Resize(w, h);
}
bool FWTableWidget::handleResize(UInt_t w, UInt_t h) {
//std::cout <<"Resize"<<std::endl;
bool redoLayout = false;
TGDimension def = m_body->GetDefaultSize();
UInt_t fullWidth = def.fWidth;
if (m_rowHeader) {
fullWidth += m_rowHeader->GetDefaultSize().fWidth;
}
UInt_t headerHeight = 0;
if (m_header) {
headerHeight = m_header->GetHeight();
}
UInt_t fullHeight = def.fHeight + headerHeight;
UInt_t sBarWidth = (h < fullHeight) ? m_vSlider->GetWidth() : 0;
UInt_t sBarHeight = (w < fullWidth) ? m_hSlider->GetHeight() : 0;
if (sBarWidth == 0 && sBarHeight > 0 && h < fullHeight + sBarHeight)
sBarWidth = m_vSlider->GetWidth();
else if (sBarHeight == 0 && sBarWidth > 0 && h < fullWidth + sBarWidth)
sBarHeight = m_hSlider->GetHeight();
fullWidth += sBarWidth;
fullHeight += sBarHeight;
if (w < fullWidth) {
if (!m_showingHSlider) {
ShowFrame(m_hSlider);
redoLayout = true;
m_showingHSlider = true;
}
m_hSlider->SetRange(fullWidth, w);
} else {
if (m_showingHSlider) {
HideFrame(m_hSlider);
m_hSlider->SetPosition(0);
m_showingHSlider = false;
redoLayout = true;
}
}
if (h < fullHeight) {
if (!m_showingVSlider) {
ShowFrame(m_vSlider);
m_showingVSlider = true;
redoLayout = true;
}
m_vSlider->SetRange(fullHeight, h);
} else {
if (m_showingVSlider) {
HideFrame(m_vSlider);
m_vSlider->SetPosition(0);
m_showingVSlider = false;
redoLayout = true;
}
}
if (redoLayout) {
Layout();
}
return redoLayout;
}
void FWTableWidget::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h) {
//std::cout <<"MoveResize"<<std::endl;
if (w != GetWidth() || h != GetHeight()) {
handleResize(w, h);
}
TGCompositeFrame::MoveResize(x, y, w, h);
}
Bool_t FWTableWidget::ProcessMessage(Long_t msg, Long_t parm1, Long_t) {
// Handle message generated by the canvas scrollbars.
switch (GET_MSG(msg)) {
case kC_HSCROLL:
switch (GET_SUBMSG(msg)) {
case kSB_SLIDERTRACK:
case kSB_SLIDERPOS:
m_body->setHorizontalOffset(parm1);
if (m_header) {
m_header->setHorizontalOffset(parm1);
}
break;
}
break;
case kC_VSCROLL:
switch (GET_SUBMSG(msg)) {
case kSB_SLIDERTRACK:
case kSB_SLIDERPOS:
m_body->setVerticalOffset(parm1);
if (m_rowHeader) {
m_rowHeader->setVerticalOffset(parm1);
}
break;
}
break;
default:
break;
}
return kTRUE;
}
void FWTableWidget::buttonReleasedInHeader(Int_t row, Int_t column, Event_t* event, Int_t, Int_t) {
Int_t btn = event->fCode;
Int_t keyMod = event->fState;
//Int_t keyMod = event->fState;
if (btn == kButton1 || btn == kButton3) {
if (m_sortedColumn == column) {
sort(column, !m_descendingSort);
} else {
sort(column, true);
}
}
columnClicked(column, btn, keyMod);
}
void FWTableWidget::buttonReleasedInBody(Int_t row, Int_t column, Event_t* event, Int_t iRelX, Int_t iRelY) {
Int_t btn = event->fCode;
Int_t keyMod = event->fState;
if (btn == kButton5) {
//should scroll down
if (m_vSlider) {
Int_t p = m_vSlider->GetPosition();
Int_t mx = m_vSlider->GetRange();
p += m_vSlider->GetSmallIncrement();
if (p > mx) {
p = mx;
}
m_vSlider->SetPosition(p);
}
return;
}
if (btn == kButton4) {
//should scroll up
if (m_vSlider) {
Int_t p = m_vSlider->GetPosition();
p -= m_vSlider->GetSmallIncrement();
if (0 > p) {
p = 0;
}
m_vSlider->SetPosition(p);
}
return;
}
if (btn != kButton1 && btn != kButton3) {
return;
}
if (row >= -1 and row < m_bodyTable->numberOfRows()) {
Int_t globalX, globalY;
Window_t childdum;
gVirtualX->TranslateCoordinates(
m_body->GetId(), gClient->GetDefaultRoot()->GetId(), event->fX, event->fY, globalX, globalY, childdum);
cellClicked(m_bodyTable->unsortedRowNumber(row), column, btn, keyMod, globalX, globalY);
rowClicked(m_bodyTable->unsortedRowNumber(row), btn, keyMod, globalX, globalY);
}
}
void FWTableWidget::cellClicked(Int_t row, Int_t column, Int_t btn, Int_t keyMod, Int_t iGlobalX, Int_t iGlobalY) {
keyMod = (keyMod & (kKeyShiftMask | kKeyControlMask));
//std::cout <<"rowClicked "<<row<<" "<<btn<<" "<<keyMod<<std::endl;
Long_t args[6];
args[0] = (Long_t)row;
args[1] = (Long_t)column;
args[2] = (Long_t)btn;
args[3] = (Long_t)keyMod;
args[4] = (Long_t)iGlobalX;
args[5] = (Long_t)iGlobalY;
Emit("cellClicked(Int_t,Int_t,Int_t,Int_t,Int_t,Int_t)", args);
}
void FWTableWidget::childrenEvent(Event_t*) { Clicked(); }
void FWTableWidget::Clicked() { Emit("Clicked()"); }
void FWTableWidget::rowClicked(Int_t row, Int_t btn, Int_t keyMod, Int_t iGlobalX, Int_t iGlobalY) {
keyMod = (keyMod & (kKeyShiftMask | kKeyControlMask));
//std::cout <<"rowClicked "<<row<<" "<<btn<<" "<<keyMod<<std::endl;
Long_t args[5];
args[0] = (Long_t)row;
args[1] = (Long_t)btn;
args[2] = (Long_t)keyMod;
args[3] = (Long_t)iGlobalX;
args[4] = (Long_t)iGlobalY;
Emit("rowClicked(Int_t,Int_t,Int_t,Int_t,Int_t)", args);
}
void FWTableWidget::columnClicked(Int_t column, Int_t btn, Int_t keyMod) {
keyMod = (keyMod & (kKeyShiftMask | kKeyControlMask));
//std::cout <<"rowClicked "<<row<<" "<<btn<<" "<<keyMod<<std::endl;
Long_t args[3];
args[0] = (Long_t)column;
args[1] = (Long_t)btn;
args[2] = (Long_t)keyMod;
Emit("columnClicked(Int_t,Int_t,Int_t)", args);
}
void FWTableWidget::dataChanged() {
bool needs_layout = m_forceLayout;
m_forceLayout = false;
m_body->dataChanged();
if (m_rowHeader) {
m_rowHeader->dataChanged();
m_rowHeader->setWidthOfTextInColumns(m_rowHeader->widthOfTextInColumns());
}
//set sizes
std::vector<unsigned int> columnWidths = m_body->widthOfTextInColumns();
if (m_header) {
// reset header back to its internal max rather than the last width
m_header->dataChanged();
std::vector<unsigned int> headerWidths = m_header->widthOfTextInColumns();
for (std::vector<unsigned int>::iterator it = columnWidths.begin(),
itEnd = columnWidths.end(),
itHeader = headerWidths.begin();
it != itEnd;
++it, ++itHeader) {
if (*itHeader > *it) {
*it = *itHeader;
}
}
m_header->setWidthOfTextInColumns(columnWidths);
}
m_body->setWidthOfTextInColumns(columnWidths);
//this updates sliders to match our new data
bool layoutDoneByhandleResize = handleResize(GetWidth(), GetHeight());
if (needs_layout && !layoutDoneByhandleResize) {
Layout();
}
gClient->NeedRedraw(m_body);
if (m_header)
gClient->NeedRedraw(m_header);
if (m_rowHeader)
gClient->NeedRedraw(m_rowHeader);
}
void FWTableWidget::buttonPressedInRowHeader(Int_t row, Int_t column, Event_t* event, Int_t relX, Int_t relY) {
Int_t btn = event->fCode;
if (btn != kButton1 && btn != kButton3) {
return;
}
m_bodyTable->buttonReleasedInRowHeader(row, event, relX, relY);
}
void FWTableWidget::buttonReleasedInRowHeader(Int_t row, Int_t column, Event_t* event, Int_t relX, Int_t relY) {
Int_t btn = event->fCode;
if (btn != kButton1 && btn != kButton3) {
return;
}
m_bodyTable->buttonReleasedInRowHeader(row, event, relX, relY);
}
//
// const member functions
//
TGDimension FWTableWidget::GetDefaultSize() const {
TGDimension returnValue;
if (m_header) {
returnValue.fHeight += m_header->GetDefaultHeight();
}
if (m_rowHeader) {
returnValue.fWidth += m_rowHeader->GetDefaultWidth();
}
returnValue = returnValue + m_body->GetDefaultSize();
returnValue.fHeight += m_hSlider->GetDefaultHeight();
returnValue.fWidth += m_vSlider->GetDefaultWidth();
return returnValue;
}
void FWTableWidget::disableGrowInWidth() {
m_body->disableGrowInWidth();
if (m_header)
m_header->disableGrowInWidth();
if (m_rowHeader)
m_rowHeader->disableGrowInWidth();
}
void FWTableWidget::DoRedraw() {
// override virtual TGFrame::DoRedraw() to prevent call of gVirtualX->ClearArea();
}
//
// static member functions
//
ClassImp(FWTableWidget);
|