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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
|
#include "customGrid.h"
#include "globalFunctions.h"
#include "resources.h"
#include <wx/dc.h>
#include "../algorithm.h"
#include "resources.h"
using namespace xmlAccess;
const unsigned int MIN_ROW_COUNT = 15;
//class containing pure grid data: basically the same as wxGridStringTable, but adds cell formatting
class CustomGridTable : public wxGridTableBase
{
public:
CustomGridTable() :
wxGridTableBase(),
lightBlue(80, 110, 255),
lightGrey(212, 208, 200),
gridRefUI(NULL),
gridData(NULL),
lastNrRows(0),
lastNrCols(0) {}
virtual ~CustomGridTable() {}
void setGridDataTable(GridView* gridRefUI, FileCompareResult* gridData)
{
this->gridRefUI = gridRefUI;
this->gridData = gridData;
}
//###########################################################################
//grid standard input output methods, redirected directly to gridData to improve performance
virtual int GetNumberRows()
{
if (gridRefUI)
return std::max(gridRefUI->size(), MIN_ROW_COUNT);
else
return 0; //grid is initialized with zero number of rows
}
virtual int GetNumberCols() //virtual used by middle grid!
{
return columnPositions.size();
}
virtual bool IsEmptyCell( int row, int col )
{
return (GetValue(row, col) == wxEmptyString);
}
virtual wxString GetValue(int row, int col) = 0;
virtual void SetValue(int row, int col, const wxString& value)
{
assert (false); //should not be used, since values are retrieved directly from gridRefUI
}
virtual void Clear()
{
assert (false); // we don't want to use this, since the visible grid is directly connected to gridRefUI}
}
virtual bool InsertRows(size_t pos = 0, size_t numRows = 1)
{
assert (false); // we don't want to use this, since the visible grid is directly connected to gridRefUI}
return true;
}
virtual bool AppendRows(size_t numRows = 1)
{
assert (false); // we don't want to use this, since the visible grid is directly connected to gridRefUI}
return true;
}
virtual bool DeleteRows(size_t pos = 0, size_t numRows = 1)
{
assert (false); // we don't want to use this, since the visible grid is directly connected to gridRefUI}
return true;
}
//update dimensions of grid: no need for InsertRows, AppendRows, DeleteRows anymore!!!
void updateGridSizes()
{
if (gridRefUI)
{
const int currentNrRows = GetNumberRows();
if (lastNrRows < currentNrRows)
{
if (GetView())
{
wxGridTableMessage msg(this,
wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
currentNrRows - lastNrRows);
GetView()->ProcessTableMessage( msg );
}
}
else if (lastNrRows > currentNrRows)
{
if (GetView())
{
wxGridTableMessage msg(this,
wxGRIDTABLE_NOTIFY_ROWS_DELETED,
0,
lastNrRows - currentNrRows);
GetView()->ProcessTableMessage( msg );
}
}
lastNrRows = currentNrRows;
}
const int currentNrCols = GetNumberCols();
if (lastNrCols < currentNrCols)
{
if (GetView())
{
wxGridTableMessage msg(this,
wxGRIDTABLE_NOTIFY_COLS_APPENDED,
currentNrCols - lastNrCols);
GetView()->ProcessTableMessage( msg );
}
}
else if (lastNrCols > currentNrCols)
{
if (GetView())
{
wxGridTableMessage msg(this,
wxGRIDTABLE_NOTIFY_COLS_DELETED,
0,
lastNrCols - currentNrCols);
GetView()->ProcessTableMessage( msg );
}
}
lastNrCols = currentNrCols;
}
//###########################################################################
virtual wxString GetColLabelValue( int col )
{
return CustomGrid::getTypeName(getTypeAtPos(col));
}
virtual wxGridCellAttr* GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind)
{
const wxColour& color = getRowColor(row);
//add color to some rows
wxGridCellAttr* result = wxGridTableBase::GetAttr(row, col, kind);
if (result)
{
if (result->GetBackgroundColour() == color)
{
return result;
}
else //grid attribute might be referenced by other nodes, so clone it!
{
wxGridCellAttr* attr = result->Clone(); //attr has ref-count 1
result->DecRef();
result = attr;
}
}
else
result = new wxGridCellAttr; //created with ref-count 1
result->SetBackgroundColour(color);
return result;
}
void setupColumns(const std::vector<xmlAccess::XmlGlobalSettings::ColumnTypes>& positions)
{
columnPositions = positions;
updateGridSizes(); //add or remove columns
}
XmlGlobalSettings::ColumnTypes getTypeAtPos(unsigned pos) const
{
if (pos < columnPositions.size())
return columnPositions[pos];
else
return XmlGlobalSettings::ColumnTypes(1000);
}
protected:
virtual const wxColour& getRowColor(int row) = 0; //rows that are filtered out are shown in different color
std::vector<xmlAccess::XmlGlobalSettings::ColumnTypes> columnPositions;
wxColour lightBlue;
wxColour lightGrey;
GridView* gridRefUI; //(very fast) access to underlying grid data :)
FileCompareResult* gridData;
int lastNrRows;
int lastNrCols;
};
class CustomGridTableLeft : public CustomGridTable
{
public:
CustomGridTableLeft() : CustomGridTable() {}
~CustomGridTableLeft() {}
virtual const wxColour& getRowColor(int row) //rows that are filtered out are shown in different color
{
if (gridRefUI && unsigned(row) < gridRefUI->size())
{
const FileCompareLine cmpLine = (*gridData)[(*gridRefUI)[row]];
//mark filtered rows
if (!cmpLine.selectedForSynchronization)
return lightBlue;
//mark directories
else if (cmpLine.fileDescrLeft.objType == FileDescrLine::TYPE_DIRECTORY)
return lightGrey;
else
return *wxWHITE;
}
return *wxWHITE;
}
//virtual impl.
wxString GetValue(int row, int col)
{
if (gridRefUI)
{
if (unsigned(row) < gridRefUI->size())
{
const FileCompareLine& gridLine = (*gridData)[(*gridRefUI)[row]];
if (gridLine.fileDescrLeft.objType == FileDescrLine::TYPE_DIRECTORY)
{
switch (getTypeAtPos(col))
{
case XmlGlobalSettings::FILENAME: //filename
return wxEmptyString;
case XmlGlobalSettings::REL_PATH: //relative path
return gridLine.fileDescrLeft.relativeName.c_str();
case XmlGlobalSettings::SIZE: //file size
return _("<Directory>");
case XmlGlobalSettings::DATE: //date
return wxEmptyString;
}
}
else if (gridLine.fileDescrLeft.objType == FileDescrLine::TYPE_FILE)
{
switch (getTypeAtPos(col))
{
case XmlGlobalSettings::FILENAME: //filename
return gridLine.fileDescrLeft.relativeName.AfterLast(GlobalResources::FILE_NAME_SEPARATOR).c_str();
case XmlGlobalSettings::REL_PATH: //relative path
return gridLine.fileDescrLeft.relativeName.BeforeLast(GlobalResources::FILE_NAME_SEPARATOR).c_str();
case XmlGlobalSettings::SIZE: //file size
{
wxString fileSize = gridLine.fileDescrLeft.fileSize.ToString(); //tmp string
return globalFunctions::includeNumberSeparator(fileSize);
}
case XmlGlobalSettings::DATE: //date
return FreeFileSync::utcTimeToLocalString(gridLine.fileDescrLeft.lastWriteTimeRaw);
}
}
}
}
//if data is not found:
return wxEmptyString;
}
};
class CustomGridTableMiddle : public CustomGridTable
{
public:
CustomGridTableMiddle() : CustomGridTable()
{
lastNrCols = 1; //ensure CustomGridTable::updateGridSizes() is working correctly
}
~CustomGridTableMiddle() {}
//virtual impl.
int GetNumberCols()
{
return 1;
}
int selectedForSynchronization(const unsigned int row) // 0 == false, 1 == true, -1 == not defined
{
if (gridRefUI && row < gridRefUI->size())
{
const FileCompareLine cmpLine = (*gridData)[(*gridRefUI)[row]];
if (cmpLine.selectedForSynchronization)
return 1;
else
return 0;
}
return -1;
}
//virtual impl.
const wxColour& getRowColor(int row) //rows that are filtered out are shown in different color
{
if (gridRefUI && unsigned(row) < gridRefUI->size())
{
const FileCompareLine cmpLine = (*gridData)[(*gridRefUI)[row]];
//mark filtered rows
if (!cmpLine.selectedForSynchronization)
return lightBlue;
else
return *wxWHITE;
}
return *wxWHITE;
}
//virtual impl.
wxString GetValue(int row, int col)
{
if (gridRefUI)
{
if (unsigned(row) < gridRefUI->size())
{
const FileCompareLine& gridLine = (*gridData)[(*gridRefUI)[row]];
switch (gridLine.cmpResult)
{
case FILE_LEFT_SIDE_ONLY:
return wxT("<|");
case FILE_RIGHT_SIDE_ONLY:
return wxT("|>");
case FILE_RIGHT_NEWER:
return wxT(">>");
case FILE_LEFT_NEWER:
return wxT("<<");
case FILE_DIFFERENT:
return wxT("!=");
case FILE_EQUAL:
return wxT("==");
default:
assert (false);
return wxEmptyString;
}
}
}
//if data is not found:
return wxEmptyString;
}
};
class CustomGridTableRight : public CustomGridTable
{
public:
CustomGridTableRight() : CustomGridTable() {}
~CustomGridTableRight() {}
//virtual impl.
const wxColour& getRowColor(int row) //rows that are filtered out are shown in different color
{
if (gridRefUI && unsigned(row) < gridRefUI->size())
{
const FileCompareLine cmpLine = (*gridData)[(*gridRefUI)[row]];
//mark filtered rows
if (!cmpLine.selectedForSynchronization)
return lightBlue;
//mark directories
else if (cmpLine.fileDescrRight.objType == FileDescrLine::TYPE_DIRECTORY)
return lightGrey;
else
return *wxWHITE;
}
return *wxWHITE;
}
//virtual impl.
wxString GetValue(int row, int col)
{
if (gridRefUI)
{
if (unsigned(row) < gridRefUI->size())
{
const FileCompareLine& gridLine = (*gridData)[(*gridRefUI)[row]];
if (gridLine.fileDescrRight.objType == FileDescrLine::TYPE_DIRECTORY)
{
switch (getTypeAtPos(col))
{
case XmlGlobalSettings::FILENAME: //filename
return wxEmptyString;
case XmlGlobalSettings::REL_PATH: //relative path
return gridLine.fileDescrRight.relativeName.c_str();
case XmlGlobalSettings::SIZE: //file size
return _("<Directory>");
case XmlGlobalSettings::DATE: //date
return wxEmptyString;
}
}
else if (gridLine.fileDescrRight.objType == FileDescrLine::TYPE_FILE)
{
switch (getTypeAtPos(col))
{
case XmlGlobalSettings::FILENAME: //filename
return gridLine.fileDescrRight.relativeName.AfterLast(GlobalResources::FILE_NAME_SEPARATOR).c_str();
case XmlGlobalSettings::REL_PATH: //relative path
return gridLine.fileDescrRight.relativeName.BeforeLast(GlobalResources::FILE_NAME_SEPARATOR).c_str();
case XmlGlobalSettings::SIZE: //file size
{
wxString fileSize = gridLine.fileDescrRight.fileSize.ToString(); //tmp string
return globalFunctions::includeNumberSeparator(fileSize);
}
case XmlGlobalSettings::DATE: //date
return FreeFileSync::utcTimeToLocalString(gridLine.fileDescrRight.lastWriteTimeRaw);
}
}
}
}
//if data is not found:
return wxEmptyString;
}
};
//########################################################################################################
CustomGrid::CustomGrid(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name) :
wxGrid(parent, id, pos, size, style, name),
scrollbarsEnabled(true),
m_gridLeft(NULL), m_gridRight(NULL), m_gridMiddle(NULL),
gridDataTable(NULL),
currentSortColumn(-1),
sortMarker(NULL)
{
//set color of selections
wxColour darkBlue(40, 35, 140);
SetSelectionBackground(darkBlue);
SetSelectionForeground(*wxWHITE);
}
void CustomGrid::initSettings(bool enableScrollbars,
CustomGrid* gridLeft,
CustomGrid* gridRight,
CustomGrid* gridMiddle,
GridView* gridRefUI,
FileCompareResult* gridData)
{
scrollbarsEnabled = enableScrollbars;
//these grids will scroll together
assert(gridLeft && gridRight && gridMiddle);
m_gridLeft = gridLeft;
m_gridRight = gridRight;
m_gridMiddle = gridMiddle;
//set underlying grid data
assert(gridDataTable);
gridDataTable->setGridDataTable(gridRefUI, gridData);
}
//overwrite virtual method to finally get rid of the scrollbars
void CustomGrid::SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh)
{
if (scrollbarsEnabled)
wxWindow::SetScrollbar(orientation, position, thumbSize, range, refresh);
else
wxWindow::SetScrollbar(orientation, 0, 0, 0, refresh);
}
//workaround: ensure that all grids are properly aligned: add some extra window space to grids that have no horizontal scrollbar
void CustomGrid::adjustGridHeights() //m_gridLeft, m_gridRight, m_gridMiddle are not NULL in this context
{
int y1 = 0;
int y2 = 0;
int y3 = 0;
int dummy = 0;
m_gridLeft->GetViewStart(&dummy, &y1);
m_gridRight->GetViewStart(&dummy, &y2);
m_gridMiddle->GetViewStart(&dummy, &y3);
if (y1 != y2 || y2 != y3)
{
int yMax = std::max(y1, std::max(y2, y3));
if (::leadGrid == m_gridLeft) //do not handle case (y1 == yMax) here!!! Avoid back coupling!
m_gridLeft->SetMargins(0, 0);
else if (y1 < yMax)
m_gridLeft->SetMargins(0, 50);
if (::leadGrid == m_gridRight)
m_gridRight->SetMargins(0, 0);
else if (y2 < yMax)
m_gridRight->SetMargins(0, 50);
if (::leadGrid == m_gridMiddle)
m_gridMiddle->SetMargins(0, 0);
else if (y3 < yMax)
m_gridMiddle->SetMargins(0, 50);
m_gridLeft->ForceRefresh();
m_gridRight->ForceRefresh();
m_gridMiddle->ForceRefresh();
}
}
void CustomGrid::updateGridSizes()
{
assert(gridDataTable);
gridDataTable->updateGridSizes();
}
void CustomGrid::setSortMarker(const int sortColumn, const wxBitmap* bitmap)
{
currentSortColumn = sortColumn;
sortMarker = bitmap;
}
void CustomGrid::DrawColLabel(wxDC& dc, int col)
{
wxGrid::DrawColLabel(dc, col);
if (col == currentSortColumn)
dc.DrawBitmap(*sortMarker, GetColRight(col) - 16 - 2, 2, true); //respect 2-pixel border
}
void CustomGrid::setColumnAttributes(const xmlAccess::XmlGlobalSettings::ColumnAttributes& attr)
{
//remove special alignment for column "size"
for (int i = 0; i < GetNumberCols(); ++i)
if (getTypeAtPos(i) == XmlGlobalSettings::SIZE)
{
wxGridCellAttr* cellAttributes = GetOrCreateCellAttr(0, i);
cellAttributes->SetAlignment(wxALIGN_LEFT,wxALIGN_CENTRE);
SetColAttr(i, cellAttributes);
break;
}
//----------------------------------------------------------------------------------
setSortMarker(-1); //clear sorting marker
columnSettings.clear();
if (attr.size() == 0)
{ //default settings:
xmlAccess::XmlGlobalSettings::ColumnAttrib newEntry;
newEntry.type = xmlAccess::XmlGlobalSettings::FILENAME;
newEntry.visible = true;
newEntry.position = 0;
newEntry.width = 138;
columnSettings.push_back(newEntry);
newEntry.type = xmlAccess::XmlGlobalSettings::REL_PATH;
newEntry.position = 1;
newEntry.width = 118;
columnSettings.push_back(newEntry);
newEntry.type = xmlAccess::XmlGlobalSettings::SIZE;
newEntry.position = 2;
newEntry.width = 67;
columnSettings.push_back(newEntry);
newEntry.type = xmlAccess::XmlGlobalSettings::DATE;
newEntry.position = 3;
newEntry.width = 113;
columnSettings.push_back(newEntry);
}
else
{
for (unsigned int i = 0; i < COLUMN_TYPE_COUNT; ++i)
{
XmlGlobalSettings::ColumnAttrib newEntry;
if (i < attr.size())
newEntry = attr[i];
else
{
newEntry.type = xmlAccess::XmlGlobalSettings::FILENAME;
newEntry.visible = true;
newEntry.position = i;
newEntry.width = 100;
}
columnSettings.push_back(newEntry);
}
sort(columnSettings.begin(), columnSettings.end(), xmlAccess::sortByType);
for (unsigned int i = 0; i < COLUMN_TYPE_COUNT; ++i) //just be sure that each type exists only once
columnSettings[i].type = XmlGlobalSettings::ColumnTypes(i);
sort(columnSettings.begin(), columnSettings.end(), xmlAccess::sortByPositionOnly);
for (unsigned int i = 0; i < COLUMN_TYPE_COUNT; ++i) //just be sure that positions are numbered correctly
columnSettings[i].position = i;
sort(columnSettings.begin(), columnSettings.end(), xmlAccess::sortByPositionAndVisibility);
}
std::vector<XmlGlobalSettings::ColumnTypes> newPositions;
for (unsigned int i = 0; i < columnSettings.size() && columnSettings[i].visible; ++i) //hidden columns are sorted to the end of vector!
newPositions.push_back(columnSettings[i].type);
//set column positions
assert(gridDataTable);
gridDataTable->setupColumns(newPositions);
//set column width (set them after setupColumns!)
for (unsigned int i = 0; i < newPositions.size(); ++i)
SetColSize(i, columnSettings[i].width);
//--------------------------------------------------------------------------------------------------------
//set special alignment for column "size"
for (int i = 0; i < GetNumberCols(); ++i)
if (getTypeAtPos(i) == XmlGlobalSettings::SIZE)
{
wxGridCellAttr* cellAttributes = GetOrCreateCellAttr(0, i);
cellAttributes->SetAlignment(wxALIGN_RIGHT,wxALIGN_CENTRE);
SetColAttr(i, cellAttributes); //make filesize right justified on grids
break;
}
ClearSelection();
ForceRefresh();
}
xmlAccess::XmlGlobalSettings::ColumnAttributes CustomGrid::getColumnAttributes()
{
sort(columnSettings.begin(), columnSettings.end(), xmlAccess::sortByPositionAndVisibility);
xmlAccess::XmlGlobalSettings::ColumnAttributes output;
xmlAccess::XmlGlobalSettings::ColumnAttrib newEntry;
for (unsigned int i = 0; i < columnSettings.size(); ++i)
{
newEntry = columnSettings[i];
if (newEntry.visible) //hidden columns are sorted to the end of vector!
newEntry.width = GetColSize(i);
output.push_back(newEntry);
}
return output;
}
XmlGlobalSettings::ColumnTypes CustomGrid::getTypeAtPos(unsigned pos) const
{
assert(gridDataTable);
return gridDataTable->getTypeAtPos(pos);
}
wxString CustomGrid::getTypeName(XmlGlobalSettings::ColumnTypes colType)
{
switch (colType)
{
case XmlGlobalSettings::FILENAME:
return _("Filename");
case XmlGlobalSettings::REL_PATH:
return _("Relative path");
case XmlGlobalSettings::SIZE:
return _("Size");
case XmlGlobalSettings::DATE:
return _("Date");
default:
return wxEmptyString;
}
}
//############################################################################################
//CustomGrid specializations
CustomGridLeft::CustomGridLeft(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name) :
CustomGrid(parent, id, pos, size, style, name) {}
bool CustomGridLeft::CreateGrid(int numRows, int numCols, wxGrid::wxGridSelectionModes selmode)
{
//use custom wxGridTableBase class for management of large sets of formatted data.
//This is done in CreateGrid instead of SetTable method since source code is generated and wxFormbuilder invokes CreatedGrid by default.
gridDataTable = new CustomGridTableLeft();
SetTable(gridDataTable, true, wxGrid::wxGridSelectRows); //give ownership to wxGrid: gridDataTable is deleted automatically in wxGrid destructor
return true;
}
//this method is called when grid view changes: useful for parallel updating of multiple grids
void CustomGridLeft::DoPrepareDC(wxDC& dc)
{
wxScrollHelper::DoPrepareDC(dc);
int x, y = 0;
if (this == ::leadGrid) //avoid back coupling
{
GetViewStart(&x, &y);
m_gridMiddle->Scroll(-1, y); //scroll in y-direction only
m_gridRight->Scroll(x, y);
adjustGridHeights(); //keep here to ensure m_gridLeft, m_gridRight, m_gridMiddle != NULL
}
}
//----------------------------------------------------------------------------------------
CustomGridMiddle::CustomGridMiddle(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name) :
CustomGrid(parent, id, pos, size, style, name) {}
bool CustomGridMiddle::CreateGrid(int numRows, int numCols, wxGrid::wxGridSelectionModes selmode)
{
CustomGridTableMiddle* newTable = new CustomGridTableMiddle();
gridDataTable = newTable;
SetTable(gridDataTable, true, wxGrid::wxGridSelectRows); //give ownership to wxGrid: gridDataTable is deleted automatically in wxGrid destructor
//display checkboxes (representing bool values) if row is enabled for synchronization
SetDefaultRenderer(new GridCellRendererAddCheckbox(newTable)); //SetDefaultRenderer takes ownership!
return true;
}
//this method is called when grid view changes: useful for parallel updating of multiple grids
void CustomGridMiddle::DoPrepareDC(wxDC& dc)
{
wxScrollHelper::DoPrepareDC(dc);
int x, y = 0;
if (this == ::leadGrid) //avoid back coupling
{
GetViewStart(&x, &y);
m_gridLeft->Scroll(-1, y);
m_gridRight->Scroll(-1, y);
adjustGridHeights(); //keep here to ensure m_gridLeft, m_gridRight, m_gridMiddle != NULL
}
}
void CustomGridMiddle::GridCellRendererAddCheckbox::Draw(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
const wxRect& rect,
int row, int col,
bool isSelected)
{
const int selected = m_gridDataTable->selectedForSynchronization(row);
if (selected < 0) //no valid row
{
wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
return;
}
const int shift = std::min(11 + 3, rect.GetWidth()); //11 is width of checkbox image
wxRect rectShrinked(rect);
//clean first block of rect that will receive image of checkbox
rectShrinked.SetWidth(shift);
dc.SetPen(*wxWHITE_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(rectShrinked);
//print image into first block
rectShrinked.SetX(1);
if (selected > 0)
dc.DrawLabel(wxEmptyString, *globalResource.bitmapCheckBoxTrue, rectShrinked, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
else //if (selected == 0) -> redundant
dc.DrawLabel(wxEmptyString, *globalResource.bitmapCheckBoxFalse, rectShrinked, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
//print second block (default): display compare result
rectShrinked.SetWidth(rect.GetWidth() - shift);
rectShrinked.SetX(shift);
wxGridCellStringRenderer::Draw(grid, attr, dc, rectShrinked, row, col, isSelected);
}
//----------------------------------------------------------------------------------------
CustomGridRight::CustomGridRight(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name) :
CustomGrid(parent, id, pos, size, style, name) {}
bool CustomGridRight::CreateGrid(int numRows, int numCols, wxGrid::wxGridSelectionModes selmode)
{
gridDataTable = new CustomGridTableRight();
SetTable(gridDataTable, true, wxGrid::wxGridSelectRows); //give ownership to wxGrid: gridDataTable is deleted automatically in wxGrid destructor
return true;
}
//this method is called when grid view changes: useful for parallel updating of multiple grids
void CustomGridRight::DoPrepareDC(wxDC& dc)
{
wxScrollHelper::DoPrepareDC(dc);
int x, y = 0;
if (this == ::leadGrid) //avoid back coupling
{
GetViewStart(&x, &y);
m_gridLeft->Scroll(x, y);
m_gridMiddle->Scroll(-1, y);
adjustGridHeights(); //keep here to ensure m_gridLeft, m_gridRight, m_gridMiddle != NULL
}
}
|