1
1
// This file is part of BOINC.
2
2
// http://boinc.berkeley.edu
3
- // Copyright (C) 2015 University of California
3
+ // Copyright (C) 2022 University of California
4
4
//
5
5
// BOINC is free software; you can redistribute it and/or modify it
6
6
// under the terms of the GNU Lesser General Public License
@@ -132,7 +132,7 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
132
132
for (iIndex = 0 ; iIndex < iActualColumnCount; iIndex++) {
133
133
m_pParentView->m_iStdColWidthOrder [m_pParentView->m_iColumnIndexToColumnID [iIndex]] = GetColumnWidth (iIndex);
134
134
}
135
-
135
+
136
136
for (iIndex = 0 ; iIndex < iStdColumnCount; iIndex++) {
137
137
pConfig->SetPath (strBaseConfigLocation + m_pParentView->m_aStdColNameOrder ->Item (iIndex));
138
138
pConfig->Write (wxT (" Width" ), m_pParentView->m_iStdColWidthOrder [iIndex]);
@@ -158,9 +158,9 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
158
158
aOrder[i] = i;
159
159
}
160
160
#endif
161
-
161
+
162
162
strColumnOrder.Printf (wxT (" %s" ), pView->m_aStdColNameOrder ->Item (pView->m_iColumnIndexToColumnID [aOrder[0 ]]));
163
-
163
+
164
164
for (i = 1 ; i < iActualColumnCount; ++i)
165
165
{
166
166
strBuffer.Printf (wxT (" ;%s" ), pView->m_aStdColNameOrder ->Item (pView->m_iColumnIndexToColumnID [aOrder[i]]));
@@ -185,7 +185,7 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
185
185
strHiddenColumns += pView->m_aStdColNameOrder ->Item (i);
186
186
}
187
187
pConfig->Write (wxT (" HiddenColumns" ), strHiddenColumns);
188
-
188
+
189
189
return true ;
190
190
}
191
191
@@ -207,7 +207,6 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
207
207
// Cycle through the possible columns updating column widths
208
208
for (iIndex = 0 ; iIndex < iStdColumnCount; iIndex++) {
209
209
pConfig->SetPath (strBaseConfigLocation + m_pParentView->m_aStdColNameOrder ->Item (iIndex));
210
-
211
210
pConfig->Read (wxT (" Width" ), &iTempValue, -1 );
212
211
if (-1 != iTempValue) {
213
212
m_pParentView->m_iStdColWidthOrder [iIndex] = iTempValue;
@@ -240,48 +239,72 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
240
239
//
241
240
// This will also be triggered if the locale is changed, which will cause
242
241
// SetListColumnOrder() to be called again so the wxListCtrl will be set
243
- // up with the correctly labeled columns.
242
+ // up with the correctly labeled columns.
243
+ //
244
244
bool foundNewColumns = false ;
245
+ bool foundNewDefaultColumns = false ;
246
+ bool foundNewHiddenColumns = false ;
245
247
246
248
if (pConfig->Read (wxT (" HiddenColumns" ), &strHiddenColumns)) {
247
249
wxArrayString hiddenArray;
250
+ wxArrayString defaultArray;
248
251
TokenizedStringToArray (strHiddenColumns, " ;" , &hiddenArray);
249
252
int shownCount = orderArray.size ();
250
253
int hiddenCount = hiddenArray.size ();
251
254
int totalCount = pView->m_aStdColNameOrder ->size ();
252
- for (int i = 0 ; i < totalCount; ++i) {
255
+ for (int i = 0 ; i < totalCount; ++i) { // cycles through updated array of columns.
253
256
wxString columnNameToFind = pView->m_aStdColNameOrder ->Item (i);
254
257
bool found = false ;
255
- for (int j = 0 ; j < shownCount; ++j) {
258
+ for (int j = 0 ; j < shownCount; ++j) { // cycles through list of visible columns.
256
259
if (orderArray[j].IsSameAs (columnNameToFind)) {
257
260
found = true ;
258
261
break ;
259
262
}
260
263
}
261
264
if (found) continue ;
262
265
263
- for (int j = 0 ; j < hiddenCount; ++j) {
266
+ for (int j = 0 ; j < hiddenCount; ++j) { // cycles through the hidden columns.
264
267
if (hiddenArray[j].IsSameAs (columnNameToFind)) {
265
268
found = true ;
266
269
break ;
267
270
}
268
271
}
269
272
if (found) continue ;
270
-
271
- foundNewColumns = true ;
272
- orderArray.Add (columnNameToFind);
273
+
274
+ foundNewColumns = true ;
275
+ // If we got this far, then we know this column is new.
276
+ // Now it needs to be determined if the new column should be shown by default or not.
277
+ // Create array of default columns.
278
+ //
279
+ defaultArray.Clear ();
280
+ for (int k = 0 ; k < pView->m_iNumDefaultShownColumns ; ++k) {
281
+ defaultArray.Add (pView->m_aStdColNameOrder ->Item (pView->m_iDefaultShownColumns [k]));
282
+ }
283
+ for (int k = 0 ; k < defaultArray.GetCount (); ++k) {
284
+ if (defaultArray[k].IsSameAs (columnNameToFind)) {
285
+ orderArray.Add (columnNameToFind);
286
+ foundNewDefaultColumns = true ;
287
+ break ;
288
+ }
289
+ }
290
+ if (!foundNewDefaultColumns) {
291
+ hiddenArray.Add (columnNameToFind); // No need to order new hidden columns since they are hidden.
292
+ foundNewHiddenColumns = true ;
293
+ }
273
294
}
274
295
}
275
296
if (foundNewColumns) {
276
- bool wasInStandardOrder = IsColumnOrderStandard ();
277
- SetListColumnOrder (orderArray);
278
- if (wasInStandardOrder) SetStandardColumnOrder ();
297
+ if (foundNewDefaultColumns) {
298
+ bool wasInStandardOrder = IsColumnOrderStandard ();
299
+ SetListColumnOrder (orderArray);
300
+ if (wasInStandardOrder) SetStandardColumnOrder ();
301
+ }
279
302
}
280
303
} else {
281
304
// No "ColumnOrder" tag in pConfig
282
305
// Show all columns in default column order
283
306
wxASSERT (wxDynamicCast (pView, CBOINCBaseView));
284
-
307
+
285
308
SetDefaultColumnDisplay ();
286
309
}
287
310
@@ -295,7 +318,7 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
295
318
296
319
void CBOINCListCtrl::TokenizedStringToArray (wxString tokenized, char * delimiters, wxArrayString* array) {
297
320
wxString name;
298
-
321
+
299
322
array->Clear ();
300
323
wxStringTokenizer tok (tokenized, delimiters);
301
324
while (tok.HasMoreTokens ())
@@ -322,22 +345,22 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
322
345
int columnID = 0 ; // ID of column, e.g. COLUMN_PROJECT, COLUMN_STATUS, etc.
323
346
int sortColumnIndex = -1 ;
324
347
wxArrayInt aOrder (shownColCount);
325
-
348
+
326
349
CBOINCBaseView* pView = (CBOINCBaseView*)GetParent ();
327
350
wxASSERT (wxDynamicCast (pView, CBOINCBaseView));
328
-
351
+
329
352
pView->m_iColumnIndexToColumnID .Clear ();
330
353
for (i=colCount-1 ; i>=0 ; --i) {
331
354
DeleteColumn (i);
332
355
}
333
-
356
+
334
357
stdCount = pView->m_aStdColNameOrder ->GetCount ();
335
358
336
359
pView->m_iColumnIDToColumnIndex .Clear ();
337
360
for (columnID=0 ; columnID<stdCount; ++columnID) {
338
361
pView->m_iColumnIDToColumnIndex .Add (-1 );
339
362
}
340
-
363
+
341
364
for (columnID=0 ; columnID<stdCount; ++columnID) {
342
365
for (columnPosition=0 ; columnPosition<shownColCount; ++columnPosition) {
343
366
if (orderArray[columnPosition].IsSameAs (pView->m_aStdColNameOrder ->Item (columnID))) {
@@ -351,7 +374,7 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
351
374
}
352
375
}
353
376
}
354
-
377
+
355
378
// Prevent a crash bug if we just changed to a new locale.
356
379
//
357
380
// If a column has the same name in both the old and new locale, we guard against
@@ -369,7 +392,7 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
369
392
pView->m_iColumnIDToColumnIndex [columnID] = columnID;
370
393
}
371
394
}
372
-
395
+
373
396
// If sort column is now hidden, set the new first column as sort column
374
397
if (pView->m_iSortColumnID >= 0 ) {
375
398
sortColumnIndex = pView->m_iColumnIDToColumnIndex [pView->m_iSortColumnID ];
@@ -382,7 +405,7 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
382
405
pView->SetSortColumn (sortColumnIndex);
383
406
}
384
407
}
385
-
408
+
386
409
#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
387
410
colCount = GetColumnCount ();
388
411
if ((shownColCount > 0 ) && (shownColCount <= stdCount) && (colCount == shownColCount)) {
@@ -425,14 +448,14 @@ void CBOINCListCtrl::SetDefaultColumnDisplay() {
425
448
int i;
426
449
wxArrayString orderArray;
427
450
CBOINCBaseView* pView = (CBOINCBaseView*)GetParent ();
428
-
451
+
429
452
wxASSERT (wxDynamicCast (pView, CBOINCBaseView));
430
453
431
454
orderArray.Clear ();
432
455
for (i=0 ; i<pView->m_iNumDefaultShownColumns ; ++i) {
433
456
orderArray.Add (pView->m_aStdColNameOrder ->Item (pView->m_iDefaultShownColumns [i]));
434
457
}
435
-
458
+
436
459
SetListColumnOrder (orderArray);
437
460
SetStandardColumnOrder ();
438
461
}
@@ -479,11 +502,11 @@ void CBOINCListCtrl::DrawProgressBars()
479
502
wxRect r, rr;
480
503
int w = 0 , x = 0 , xx, yy, ww;
481
504
int progressColumn = -1 ;
482
-
505
+
483
506
if (m_pParentView->GetProgressColumn () >= 0 ) {
484
507
progressColumn = m_pParentView->m_iColumnIDToColumnIndex [m_pParentView->GetProgressColumn ()];
485
508
}
486
-
509
+
487
510
#if USE_NATIVE_LISTCONTROL
488
511
wxClientDC dc (this );
489
512
m_bProgressBarEventPending = false ;
@@ -498,10 +521,10 @@ void CBOINCListCtrl::DrawProgressBars()
498
521
499
522
int n = (int )m_iRowsNeedingProgressBars.GetCount ();
500
523
if (n <= 0 ) return ;
501
-
524
+
502
525
wxColour progressColor = wxTheColourDatabase->Find (wxT (" LIGHT BLUE" ));
503
526
wxBrush progressBrush (progressColor);
504
-
527
+
505
528
numItems = GetItemCount ();
506
529
if (numItems) {
507
530
topItem = GetTopItem (); // Doesn't work properly for Mac Native control in wxMac-2.8.7
@@ -517,20 +540,20 @@ void CBOINCListCtrl::DrawProgressBars()
517
540
x += GetColumnWidth (GetColumnIndexFromOrder (i));
518
541
}
519
542
w = GetColumnWidth (progressColumn);
520
-
543
+
521
544
#if USE_NATIVE_LISTCONTROL
522
545
x -= GetScrollPos (wxHORIZONTAL);
523
546
#else
524
547
CalcScrolledPosition (x, 0 , &x, &yy);
525
548
#endif
526
549
wxFont theFont = GetFont ();
527
550
dc.SetFont (theFont);
528
-
551
+
529
552
for (int i=0 ; i<n; ++i) {
530
553
row = m_iRowsNeedingProgressBars[i];
531
554
if (row < topItem) continue ;
532
555
if (row > (topItem + numVisibleItems -1 )) continue ;
533
-
556
+
534
557
535
558
GetItemRect (row, r);
536
559
#if ! USE_NATIVE_LISTCONTROL
@@ -543,9 +566,9 @@ void CBOINCListCtrl::DrawProgressBars()
543
566
544
567
wxString progressString = m_pParentView->GetProgressText (row);
545
568
dc.GetTextExtent (progressString, &xx, &yy);
546
-
569
+
547
570
r.y += (r.height - yy - 1 ) / 2 ;
548
-
571
+
549
572
// Adapted from ellipis code in wxRendererGeneric::DrawHeaderButtonContents()
550
573
if (xx > r.width ) {
551
574
int ellipsisWidth;
@@ -562,7 +585,7 @@ void CBOINCListCtrl::DrawProgressBars()
562
585
xx += ellipsisWidth;
563
586
}
564
587
}
565
-
588
+
566
589
dc.SetLogicalFunction (wxCOPY);
567
590
dc.SetBackgroundMode (wxSOLID);
568
591
dc.SetPen (progressColor);
@@ -610,7 +633,7 @@ void MyEvtHandler::OnPaint(wxPaintEvent & event)
610
633
611
634
void CBOINCListCtrl::PostDrawProgressBarEvent () {
612
635
if (m_bProgressBarEventPending) return ;
613
-
636
+
614
637
CDrawProgressBarEvent newEvent (wxEVT_DRAW_PROGRESSBAR, this );
615
638
AddPendingEvent (newEvent);
616
639
m_bProgressBarEventPending = true ;
@@ -676,7 +699,7 @@ void CBOINCListCtrl::OnMouseDown(wxMouseEvent& event) {
676
699
// on Mac, which is double-buffered to eliminate flicker.)
677
700
void CBOINCListCtrl::RefreshCell (int row, int col) {
678
701
wxRect r;
679
-
702
+
680
703
GetSubItemRect (row, col, r);
681
704
RefreshRect (r);
682
705
}
0 commit comments