@@ -217,7 +217,10 @@ def _get_isMultiColumn(self):
217217 def _get_rowCount (self ):
218218 return watchdog .cancellableSendMessage (self .windowHandle , LVM_GETITEMCOUNT , 0 , 0 )
219219
220- def _get_columnCount (self ):
220+ columnCount : int
221+ """Typing information for auto-property: _get_columnCount"""
222+
223+ def _get_columnCount (self ) -> int :
221224 if not self .isMultiColumn :
222225 return 0
223226 headerHwnd = watchdog .cancellableSendMessage (self .windowHandle ,LVM_GETHEADER ,0 ,0 )
@@ -287,10 +290,27 @@ def _getColumnOrderArrayRaw(self, columnCount: int) -> Optional[ctypes.Array]:
287290 return self ._getColumnOrderArrayRawOutProc (columnCount )
288291 return self ._getColumnOrderArrayRawInProc (columnCount )
289292
290- _columnOrderArray : Optional [ctypes .Array ]
291-
292- def _get__columnOrderArray (self ) -> Optional [ctypes .Array ]:
293- return self ._getColumnOrderArrayRaw (self .columnCount )
293+ def _getMappedColumn (self , presentationIndex : int ) -> Optional [int ]:
294+ """
295+ Multi-column SysListViews can have their columns re-ordered.
296+ To keep a consistent internal mapping, a column order array is used
297+ to map a presentation index to a consistent internal index.
298+ For single-column SysListViews, the mapping is not necessary.
299+ If the column order array cannot be fetched from a multi-column SysListView,
300+ this returns None.
301+
302+ @param presentationIndex: One based index for the column as presented to the user.
303+ @return: The internal / logical column zero based index for the column.
304+ None if the mapped column cannot be determined.
305+ """
306+ if presentationIndex == 1 and self .columnCount == 1 :
307+ # Use an implied default column mapping for single column list views
308+ return 0
309+ columnOrderArray = self ._getColumnOrderArrayRaw (self .columnCount )
310+ if columnOrderArray is None :
311+ log .error ("Cannot fetch column as column order array is unknown" )
312+ return None
313+ return columnOrderArray [presentationIndex - 1 ]
294314
295315
296316class GroupingItem (Window ):
@@ -454,10 +474,10 @@ def _getColumnLocationRaw(self, index: int) -> Optional[RectLTRB]:
454474 return RectLTRB (left , top , right , bottom ).toScreen (self .windowHandle ).toLTWH ()
455475
456476 def _getColumnLocation (self , column : int ) -> Optional [RectLTRB ]:
457- if self .parent ._columnOrderArray is None :
458- log . debugWarning ( "Cannot fetch column location as column order array is unknown" )
477+ mappedColumn = self .parent ._getMappedColumn ( column )
478+ if mappedColumn is None :
459479 return None
460- return self ._getColumnLocationRaw (self . parent . _columnOrderArray [ column - 1 ] )
480+ return self ._getColumnLocationRaw (mappedColumn )
461481
462482 def _getColumnContentRawInProc (self , index : int ) -> Optional [str ]:
463483 """Retrieves text for a given column.
@@ -510,10 +530,10 @@ def _getColumnContentRaw(self, index: int) -> Optional[str]:
510530 return self ._getColumnContentRawInProc (index )
511531
512532 def _getColumnContent (self , column : int ) -> Optional [str ]:
513- if self .parent ._columnOrderArray is None :
514- log . debugWarning ( "Cannot fetch column content as column order array is unknown" )
533+ mappedColumn = self .parent ._getMappedColumn ( column )
534+ if mappedColumn is None :
515535 return None
516- return self ._getColumnContentRaw (self . parent . _columnOrderArray [ column - 1 ] )
536+ return self ._getColumnContentRaw (mappedColumn )
517537
518538 def _getColumnImageIDRaw (self , index ):
519539 processHandle = self .processHandle
@@ -530,10 +550,10 @@ def _getColumnImageIDRaw(self, index):
530550 return item .iImage
531551
532552 def _getColumnImageID (self , column ):
533- if self .parent ._columnOrderArray is None :
534- log . debugWarning ( "Cannot fetch column image ID as column order array is unknown" )
553+ mappedColumn = self .parent ._getMappedColumn ( column )
554+ if mappedColumn is None :
535555 return None
536- return self ._getColumnImageIDRaw (self . parent . _columnOrderArray [ column - 1 ] )
556+ return self ._getColumnImageIDRaw (mappedColumn )
537557
538558 def _getColumnHeaderRawOutProc (self , index : int ) -> Optional [str ]:
539559 """Retrieves text of the header for the given column.
@@ -584,10 +604,10 @@ def _getColumnHeaderRaw(self, index: int) -> Optional[str]:
584604 return self ._getColumnHeaderRawInProc (index )
585605
586606 def _getColumnHeader (self , column : int ) -> Optional [str ]:
587- if self .parent ._columnOrderArray is None :
588- log . debugWarning ( "Cannot fetch column header as column order array is unknown" )
607+ mappedColumn = self .parent ._getMappedColumn ( column )
608+ if mappedColumn is None :
589609 return None
590- return self ._getColumnHeaderRaw (self . parent . _columnOrderArray [ column - 1 ] )
610+ return self ._getColumnHeaderRaw (mappedColumn )
591611
592612 def _get_name (self ):
593613 parent = self .parent
0 commit comments