11// This file is part of BOINC.
22// http://boinc.berkeley.edu
3- // Copyright (C) 2015 University of California
3+ // Copyright (C) 2022 University of California
44//
55// BOINC is free software; you can redistribute it and/or modify it
66// under the terms of the GNU Lesser General Public License
@@ -132,7 +132,7 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
132132 for (iIndex = 0 ; iIndex < iActualColumnCount; iIndex++) {
133133 m_pParentView->m_iStdColWidthOrder [m_pParentView->m_iColumnIndexToColumnID [iIndex]] = GetColumnWidth (iIndex);
134134 }
135-
135+
136136 for (iIndex = 0 ; iIndex < iStdColumnCount; iIndex++) {
137137 pConfig->SetPath (strBaseConfigLocation + m_pParentView->m_aStdColNameOrder ->Item (iIndex));
138138 pConfig->Write (wxT (" Width" ), m_pParentView->m_iStdColWidthOrder [iIndex]);
@@ -158,9 +158,9 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
158158 aOrder[i] = i;
159159 }
160160#endif
161-
161+
162162 strColumnOrder.Printf (wxT (" %s" ), pView->m_aStdColNameOrder ->Item (pView->m_iColumnIndexToColumnID [aOrder[0 ]]));
163-
163+
164164 for (i = 1 ; i < iActualColumnCount; ++i)
165165 {
166166 strBuffer.Printf (wxT (" ;%s" ), pView->m_aStdColNameOrder ->Item (pView->m_iColumnIndexToColumnID [aOrder[i]]));
@@ -185,7 +185,7 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
185185 strHiddenColumns += pView->m_aStdColNameOrder ->Item (i);
186186 }
187187 pConfig->Write (wxT (" HiddenColumns" ), strHiddenColumns);
188-
188+
189189 return true ;
190190}
191191
@@ -207,7 +207,6 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
207207 // Cycle through the possible columns updating column widths
208208 for (iIndex = 0 ; iIndex < iStdColumnCount; iIndex++) {
209209 pConfig->SetPath (strBaseConfigLocation + m_pParentView->m_aStdColNameOrder ->Item (iIndex));
210-
211210 pConfig->Read (wxT (" Width" ), &iTempValue, -1 );
212211 if (-1 != iTempValue) {
213212 m_pParentView->m_iStdColWidthOrder [iIndex] = iTempValue;
@@ -240,48 +239,72 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
240239 //
241240 // This will also be triggered if the locale is changed, which will cause
242241 // 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+ //
244244 bool foundNewColumns = false ;
245+ bool foundNewDefaultColumns = false ;
246+ bool foundNewHiddenColumns = false ;
245247
246248 if (pConfig->Read (wxT (" HiddenColumns" ), &strHiddenColumns)) {
247249 wxArrayString hiddenArray;
250+ wxArrayString defaultArray;
248251 TokenizedStringToArray (strHiddenColumns, " ;" , &hiddenArray);
249252 int shownCount = orderArray.size ();
250253 int hiddenCount = hiddenArray.size ();
251254 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.
253256 wxString columnNameToFind = pView->m_aStdColNameOrder ->Item (i);
254257 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.
256259 if (orderArray[j].IsSameAs (columnNameToFind)) {
257260 found = true ;
258261 break ;
259262 }
260263 }
261264 if (found) continue ;
262265
263- for (int j = 0 ; j < hiddenCount; ++j) {
266+ for (int j = 0 ; j < hiddenCount; ++j) { // cycles through the hidden columns.
264267 if (hiddenArray[j].IsSameAs (columnNameToFind)) {
265268 found = true ;
266269 break ;
267270 }
268271 }
269272 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+ }
273294 }
274295 }
275296 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+ }
279302 }
280303 } else {
281304 // No "ColumnOrder" tag in pConfig
282305 // Show all columns in default column order
283306 wxASSERT (wxDynamicCast (pView, CBOINCBaseView));
284-
307+
285308 SetDefaultColumnDisplay ();
286309 }
287310
@@ -295,7 +318,7 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
295318
296319void CBOINCListCtrl::TokenizedStringToArray (wxString tokenized, char * delimiters, wxArrayString* array) {
297320 wxString name;
298-
321+
299322 array->Clear ();
300323 wxStringTokenizer tok (tokenized, delimiters);
301324 while (tok.HasMoreTokens ())
@@ -322,22 +345,22 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
322345 int columnID = 0 ; // ID of column, e.g. COLUMN_PROJECT, COLUMN_STATUS, etc.
323346 int sortColumnIndex = -1 ;
324347 wxArrayInt aOrder (shownColCount);
325-
348+
326349 CBOINCBaseView* pView = (CBOINCBaseView*)GetParent ();
327350 wxASSERT (wxDynamicCast (pView, CBOINCBaseView));
328-
351+
329352 pView->m_iColumnIndexToColumnID .Clear ();
330353 for (i=colCount-1 ; i>=0 ; --i) {
331354 DeleteColumn (i);
332355 }
333-
356+
334357 stdCount = pView->m_aStdColNameOrder ->GetCount ();
335358
336359 pView->m_iColumnIDToColumnIndex .Clear ();
337360 for (columnID=0 ; columnID<stdCount; ++columnID) {
338361 pView->m_iColumnIDToColumnIndex .Add (-1 );
339362 }
340-
363+
341364 for (columnID=0 ; columnID<stdCount; ++columnID) {
342365 for (columnPosition=0 ; columnPosition<shownColCount; ++columnPosition) {
343366 if (orderArray[columnPosition].IsSameAs (pView->m_aStdColNameOrder ->Item (columnID))) {
@@ -351,7 +374,7 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
351374 }
352375 }
353376 }
354-
377+
355378 // Prevent a crash bug if we just changed to a new locale.
356379 //
357380 // 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) {
369392 pView->m_iColumnIDToColumnIndex [columnID] = columnID;
370393 }
371394 }
372-
395+
373396 // If sort column is now hidden, set the new first column as sort column
374397 if (pView->m_iSortColumnID >= 0 ) {
375398 sortColumnIndex = pView->m_iColumnIDToColumnIndex [pView->m_iSortColumnID ];
@@ -382,7 +405,7 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
382405 pView->SetSortColumn (sortColumnIndex);
383406 }
384407 }
385-
408+
386409#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
387410 colCount = GetColumnCount ();
388411 if ((shownColCount > 0 ) && (shownColCount <= stdCount) && (colCount == shownColCount)) {
@@ -425,14 +448,14 @@ void CBOINCListCtrl::SetDefaultColumnDisplay() {
425448 int i;
426449 wxArrayString orderArray;
427450 CBOINCBaseView* pView = (CBOINCBaseView*)GetParent ();
428-
451+
429452 wxASSERT (wxDynamicCast (pView, CBOINCBaseView));
430453
431454 orderArray.Clear ();
432455 for (i=0 ; i<pView->m_iNumDefaultShownColumns ; ++i) {
433456 orderArray.Add (pView->m_aStdColNameOrder ->Item (pView->m_iDefaultShownColumns [i]));
434457 }
435-
458+
436459 SetListColumnOrder (orderArray);
437460 SetStandardColumnOrder ();
438461}
@@ -479,11 +502,11 @@ void CBOINCListCtrl::DrawProgressBars()
479502 wxRect r, rr;
480503 int w = 0 , x = 0 , xx, yy, ww;
481504 int progressColumn = -1 ;
482-
505+
483506 if (m_pParentView->GetProgressColumn () >= 0 ) {
484507 progressColumn = m_pParentView->m_iColumnIDToColumnIndex [m_pParentView->GetProgressColumn ()];
485508 }
486-
509+
487510#if USE_NATIVE_LISTCONTROL
488511 wxClientDC dc (this );
489512 m_bProgressBarEventPending = false ;
@@ -498,10 +521,10 @@ void CBOINCListCtrl::DrawProgressBars()
498521
499522 int n = (int )m_iRowsNeedingProgressBars.GetCount ();
500523 if (n <= 0 ) return ;
501-
524+
502525 wxColour progressColor = wxTheColourDatabase->Find (wxT (" LIGHT BLUE" ));
503526 wxBrush progressBrush (progressColor);
504-
527+
505528 numItems = GetItemCount ();
506529 if (numItems) {
507530 topItem = GetTopItem (); // Doesn't work properly for Mac Native control in wxMac-2.8.7
@@ -517,20 +540,20 @@ void CBOINCListCtrl::DrawProgressBars()
517540 x += GetColumnWidth (GetColumnIndexFromOrder (i));
518541 }
519542 w = GetColumnWidth (progressColumn);
520-
543+
521544#if USE_NATIVE_LISTCONTROL
522545 x -= GetScrollPos (wxHORIZONTAL);
523546#else
524547 CalcScrolledPosition (x, 0 , &x, &yy);
525548#endif
526549 wxFont theFont = GetFont ();
527550 dc.SetFont (theFont);
528-
551+
529552 for (int i=0 ; i<n; ++i) {
530553 row = m_iRowsNeedingProgressBars[i];
531554 if (row < topItem) continue ;
532555 if (row > (topItem + numVisibleItems -1 )) continue ;
533-
556+
534557
535558 GetItemRect (row, r);
536559#if ! USE_NATIVE_LISTCONTROL
@@ -543,9 +566,9 @@ void CBOINCListCtrl::DrawProgressBars()
543566
544567 wxString progressString = m_pParentView->GetProgressText (row);
545568 dc.GetTextExtent (progressString, &xx, &yy);
546-
569+
547570 r.y += (r.height - yy - 1 ) / 2 ;
548-
571+
549572 // Adapted from ellipis code in wxRendererGeneric::DrawHeaderButtonContents()
550573 if (xx > r.width ) {
551574 int ellipsisWidth;
@@ -562,7 +585,7 @@ void CBOINCListCtrl::DrawProgressBars()
562585 xx += ellipsisWidth;
563586 }
564587 }
565-
588+
566589 dc.SetLogicalFunction (wxCOPY);
567590 dc.SetBackgroundMode (wxSOLID);
568591 dc.SetPen (progressColor);
@@ -610,7 +633,7 @@ void MyEvtHandler::OnPaint(wxPaintEvent & event)
610633
611634void CBOINCListCtrl::PostDrawProgressBarEvent () {
612635 if (m_bProgressBarEventPending) return ;
613-
636+
614637 CDrawProgressBarEvent newEvent (wxEVT_DRAW_PROGRESSBAR, this );
615638 AddPendingEvent (newEvent);
616639 m_bProgressBarEventPending = true ;
@@ -676,7 +699,7 @@ void CBOINCListCtrl::OnMouseDown(wxMouseEvent& event) {
676699// on Mac, which is double-buffered to eliminate flicker.)
677700void CBOINCListCtrl::RefreshCell (int row, int col) {
678701 wxRect r;
679-
702+
680703 GetSubItemRect (row, col, r);
681704 RefreshRect (r);
682705}
0 commit comments