-
-
Notifications
You must be signed in to change notification settings - Fork 625
/
sysListView32.py
659 lines (592 loc) · 23.8 KB
/
sysListView32.py
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
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2006-2022 NV Access Limited, Peter Vágner, Leonard de Ruijter, Cyrille Bougot
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
import time
from ctypes import *
import ctypes
from ctypes.wintypes import *
from comtypes import BSTR
import NVDAHelper
import watchdog
import controlTypes
import api
import eventHandler
import winKernel
from . import IAccessible, List
from ..window import Window
from NVDAObjects.behaviors import RowWithoutCellObjects, RowWithFakeNavigation
import config
from config.configFlags import ReportTableHeaders
from locationHelper import RectLTRB
from logHandler import log
from typing import Optional
#Window messages
LVM_FIRST=0x1000
LVM_GETITEMW=LVM_FIRST+75
LVM_GETITEMSTATE=LVM_FIRST+44
LVM_GETFOCUSEDGROUP=LVM_FIRST+93
LVM_GETITEMCOUNT=LVM_FIRST+4
LVM_GETITEM=LVM_FIRST+75
LVN_GETDISPINFO=0xFFFFFF4F
LVM_GETITEMTEXTW=LVM_FIRST+115
LVM_GETHEADER=LVM_FIRST+31
LVM_GETCOLUMNORDERARRAY=LVM_FIRST+59
LVM_GETCOLUMNW=LVM_FIRST+95
LVM_GETSELECTEDCOUNT =(LVM_FIRST+50)
LVNI_SELECTED =2
LVM_GETNEXTITEM =(LVM_FIRST+12)
LVM_GETVIEW=LVM_FIRST+143
LV_VIEW_DETAILS=0x0001
LVM_GETSUBITEMRECT=LVM_FIRST+56
LV_VIEW_TILE=0x0004
#item mask flags
LVIF_TEXT=0x01
LVIF_IMAGE=0x02
LVIF_PARAM=0x04
LVIF_STATE=0x08
LVIF_INDENT=0x10
LVIF_GROUPID=0x100
LVIF_COLUMNS=0x200
#GETSUBITEMRECT flags
# Returns the bounding rectangle of the entire item, including the icon and label
LVIR_BOUNDS = 0
# Returns the bounding rectangle of the icon or small icon.
LVIR_ICON = 1
# Returns the bounding rectangle of the entire item, including the icon and label.
# This is identical to LVIR_BOUNDS.
LVIR_LABEL = 2
#Item states
LVIS_FOCUSED=0x01
LVIS_SELECTED=0x02
LVIS_STATEIMAGEMASK=0xF000
LVS_REPORT=0x0001
LVS_TYPEMASK=0x0003
LVS_OWNERDRAWFIXED=0x0400
#column mask flags
LVCF_FMT=1
LVCF_WIDTH=2
LVCF_TEXT=4
LVCF_SUBITEM=8
LVCF_IMAGE=16
LVCF_ORDER=32
# The size of a buffer to hold text for listview items and columns etc
# #7828: Windows headers define this as 260 characters. However this is not long enough for modern Twitter clients that need at least 280 characters.
# Therefore, round it up to the nearest power of 2
CBEMAXSTRLEN=512
# listview header window messages
HDM_FIRST=0x1200
HDM_GETITEMCOUNT=HDM_FIRST
class LVITEM(Structure):
_fields_=[
('mask',c_uint),
('iItem',c_int),
('iSubItem',c_int),
('state',c_uint),
('stateMask',c_uint),
('pszText',c_void_p),
('cchTextMax',c_int),
('iImage',c_int),
('lParam',LPARAM),
('iIndent',c_int),
('iGroupID',c_int),
('cColumns',c_uint),
('puColumns',c_uint),
('piColFmt',POINTER(c_int)),
('iGroup',c_int),
]
class LVITEM64(Structure):
_fields_=[
('mask',c_uint),
('iItem',c_int),
('iSubItem',c_int),
('state',c_uint),
('stateMask',c_uint),
('pszText',c_ulonglong),
('cchTextMax',c_int),
('iImage',c_int),
('lParam',c_ulonglong),
('iIndent',c_int),
('iGroupID',c_int),
('cColumns',c_uint),
('puColumns',c_uint),
('piColFmt',c_ulonglong),
('iGroup',c_int),
]
class LVCOLUMN(Structure):
_fields_=[
('mask',c_uint),
('fmt',c_int),
('cx',c_int),
('pszText',c_void_p),
('cchTextMax',c_int),
('iSubItem',c_int),
('iImage',c_int),
('iOrder',c_int),
('cxMin',c_int),
('cxDefault',c_int),
('cxIdeal',c_int),
]
class LVCOLUMN64(Structure):
_fields_=[
('mask',c_uint),
('fmt',c_int),
('cx',c_int),
('pszText',c_ulonglong),
('cchTextMax',c_int),
('iSubItem',c_int),
('iImage',c_int),
('iOrder',c_int),
('cxMin',c_int),
('cxDefault',c_int),
('cxIdeal',c_int),
]
class AutoFreeBSTR(BSTR):
"""A BSTR that *always* frees itself on deletion.
A BSTR (Basic string or binary string) is a string data type that is used by COM,
Automation, and Interop functions.
AutoFreeBSTR is useful where another library allocates (SysAllocString/SysAllocStringLen)
and you want to ensure that it will be deallocated (SysFreeString).
@note The conditions requiring the use of this class are not clear.
The current usage is considered legacy.
@note The BSTR (base class) from comtypes will free the string when it
is from an outparam (indicating that memory was allocated in the library).
@warning Don't use this unless you are certain about taking ownership of the memory.
@warning Deprecated, may be removed in future versions.
"""
_needsfree=True
class List(List):
def getListGroupInfo(self,groupIndex):
header=AutoFreeBSTR()
footer=AutoFreeBSTR()
state=c_int()
if watchdog.cancellableExecute(NVDAHelper.localLib.nvdaInProcUtils_sysListView32_getGroupInfo,self.appModule.helperLocalBindingHandle,self.windowHandle,groupIndex,byref(header),byref(footer),byref(state))!=0:
return None
return dict(header=header.value,footer=footer.value,state=state.value,groupIndex=groupIndex)
def _get_name(self):
name=super(List,self)._get_name()
if not name:
name=super(IAccessible,self)._get_name()
return name
def event_gainFocus(self):
#See if this object is the focus and the focus is on a group item.
#if so, then morph this object to a groupingItem object
if self is api.getFocusObject():
groupIndex=watchdog.cancellableSendMessage(self.windowHandle,LVM_GETFOCUSEDGROUP,0,0)
if groupIndex>=0:
info=self.getListGroupInfo(groupIndex)
if info is not None:
ancestors=api.getFocusAncestors()
if api.getFocusDifferenceLevel()==len(ancestors)-1:
self.event_focusEntered()
groupingObj=GroupingItem(windowHandle=self.windowHandle,parentNVDAObject=self,groupInfo=info)
return eventHandler.queueEvent("gainFocus",groupingObj)
return super(List,self).event_gainFocus()
def _get_isMultiColumn(self):
view = watchdog.cancellableSendMessage(self.windowHandle, LVM_GETVIEW, 0, 0)
if view in (LV_VIEW_DETAILS, LV_VIEW_TILE):
return True
elif view == 0:
# #2673: This could indicate that LVM_GETVIEW is not supported (comctl32 < 6.0).
# Unfortunately, it could also indicate LV_VIEW_ICON.
# Hopefully, no one sets LVS_REPORT and then LV_VIEW_ICON.
return self.windowStyle & LVS_TYPEMASK == LVS_REPORT
return False
def _get_rowCount(self):
return watchdog.cancellableSendMessage(self.windowHandle, LVM_GETITEMCOUNT, 0, 0)
columnCount: int
"""Typing information for auto-property: _get_columnCount"""
def _get_columnCount(self) -> int:
if not self.isMultiColumn:
return 0
headerHwnd= watchdog.cancellableSendMessage(self.windowHandle,LVM_GETHEADER,0,0)
count = watchdog.cancellableSendMessage(headerHwnd, HDM_GETITEMCOUNT, 0, 0)
if not count:
return 1
return count
def _getColumnOrderArrayRawInProc(self, columnCount: int) -> Optional[ctypes.Array]:
"""Retrieves a list of column indexes for a given list control.
See `_getColumnOrderArrayRaw` for more comments.
Note that this method operates in process and cannot be used in situations where NVDA cannot inject
i.e when running as a Windows Store application or when no focus event was received on startup.
"""
columnOrderArray = (ctypes.c_int * columnCount)()
res = watchdog.cancellableExecute(
NVDAHelper.localLib.nvdaInProcUtils_sysListView32_getColumnOrderArray,
self.appModule.helperLocalBindingHandle,
self.windowHandle,
columnCount,
columnOrderArray
)
if res:
return None
return columnOrderArray
def _getColumnOrderArrayRawOutProc(self, columnCount: int) -> Optional[ctypes.Array]:
"""Retrieves a list of column indexes for a given list control.
See `_getColumnOrderArrayRaw` for more comments.
Note that this method operates out of process and has to reserve memory inside a given application.
As a consequence it may fail when reserved memory is above the range available
for 32-bit processes.
Use only when in process injection is not possible.
"""
coa = (ctypes.c_int * columnCount)()
processHandle=self.processHandle
internalCoa=winKernel.virtualAllocEx(processHandle,None,sizeof(coa),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE)
try:
winKernel.writeProcessMemory(processHandle,internalCoa,byref(coa),sizeof(coa),None)
# The meaning of the return value depends on the message sent, for LVM_GETCOLUMNORDERARRAY,
# it returns nonzero if successful, or 0 otherwise.
# https://docs.microsoft.com/en-us/windows/win32/controls/lvm-getcolumnorderarray#return-value
res = watchdog.cancellableSendMessage(
self.windowHandle,
LVM_GETCOLUMNORDERARRAY,
columnCount,
internalCoa
)
if res:
winKernel.readProcessMemory(processHandle,internalCoa,byref(coa),sizeof(coa),None)
else:
coa = None
log.debugWarning(
f"LVM_GETCOLUMNORDERARRAY failed for list. "
f"Windows Error: {ctypes.GetLastError()}, Handle: {self.windowHandle}"
)
finally:
winKernel.virtualFreeEx(processHandle,internalCoa,0,winKernel.MEM_RELEASE)
return coa
def _getColumnOrderArrayRaw(self, columnCount: int) -> Optional[ctypes.Array]:
"""Retrieves an array of column indexes for a given list.
The indexes are placed in order in which columns are displayed on screen from left to right.
Note that when columns are reordered the indexes remain the same - only their order differs.
"""
if self.appModule.helperLocalBindingHandle is None:
return self._getColumnOrderArrayRawOutProc(columnCount)
return self._getColumnOrderArrayRawInProc(columnCount)
def _getMappedColumn(self, presentationIndex: int) -> Optional[int]:
"""
Multi-column SysListViews can have their columns re-ordered.
To keep a consistent internal mapping, a column order array is used
to map a presentation index to a consistent internal index.
For single-column SysListViews, the mapping is not necessary.
If the column order array cannot be fetched from a multi-column SysListView,
this returns None.
@param presentationIndex: One based index for the column as presented to the user.
@return: The internal / logical column zero based index for the column.
None if the mapped column cannot be determined.
"""
if presentationIndex == 1 and self.columnCount == 1:
# Use an implied default column mapping for single column list views
return 0
columnOrderArray = self._getColumnOrderArrayRaw(self.columnCount)
if columnOrderArray is None:
log.error("Cannot fetch column as column order array is unknown")
return None
return columnOrderArray[presentationIndex - 1]
class GroupingItem(Window):
def __init__(self,windowHandle=None,parentNVDAObject=None,groupInfo=None):
super(GroupingItem,self).__init__(windowHandle=windowHandle)
self.parent=parentNVDAObject
self.groupInfo=groupInfo
def _isEqual(self,other):
return isinstance(other,self.__class__) and self.groupInfo==other.groupInfo
def _set_groupInfo(self,info):
self._groupInfoTime=time.time()
self._groupInfo=info
for gesture in ("kb:leftArrow", "kb:rightArrow"):
self.bindGesture(gesture, "collapseOrExpand")
def _get_groupInfo(self):
now=time.time()
if (now-self._groupInfoTime)>0.25:
self._groupInfoTime=now
self._groupInfo=self.parent.getListGroupInfo(self._groupInfo['groupIndex'])
return self._groupInfo
def _get_name(self):
return self.groupInfo['header']
role = controlTypes.Role.GROUPING
def _get_value(self):
return self.groupInfo['footer']
def _get_states(self):
states=set()
if self.groupInfo['state']&1:
states.add(controlTypes.State.COLLAPSED)
else:
states.add(controlTypes.State.EXPANDED)
return states
def script_collapseOrExpand(self,gesture):
gesture.send()
eventHandler.queueEvent("stateChange",self)
CHAR_LTR_MARK = u'\u200E'
CHAR_RTL_MARK = u'\u200F'
class ListItemWithoutColumnSupport(IAccessible):
def initOverlayClass(self):
if self.appModule.is64BitProcess:
self.LVITEM = LVITEM64
self.LVCOLUMN = LVCOLUMN64
else:
self.LVITEM = LVITEM
self.LVCOLUMN = LVCOLUMN
description = None
def _get_value(self):
value=super(ListItemWithoutColumnSupport,self)._get_description()
if (not value or value.isspace()) and self.windowStyle & LVS_OWNERDRAWFIXED:
value=self.displayText
if not value:
return None
#Some list view items in Windows Vista and later can contain annoying left-to-right and right-to-left indicator characters which really should not be there.
return value.replace(CHAR_LTR_MARK,'').replace(CHAR_RTL_MARK,'')
def _get_positionInfo(self):
index=self.IAccessibleChildID
totalCount=watchdog.cancellableSendMessage(self.windowHandle,LVM_GETITEMCOUNT,0,0)
return dict(indexInGroup=index,similarItemsInGroup=totalCount)
def event_stateChange(self):
if self.hasFocus:
super(ListItemWithoutColumnSupport,self).event_stateChange()
class ListItem(RowWithFakeNavigation, RowWithoutCellObjects, ListItemWithoutColumnSupport):
parent: List
def _getColumnLocationRawInProc(self, index: int) -> ctypes.wintypes.RECT:
"""Retrieves rectangle containing coordinates for a given column.
Note that this method operates in process and cannot be used in situations where NVDA cannot inject
i.e when running as a Windows Store application or when no focus event was received on startup.
"""
item = self.IAccessibleChildID - 1
subItem = index
rect = ctypes.wintypes.RECT()
if watchdog.cancellableExecute(
NVDAHelper.localLib.nvdaInProcUtils_sysListView32_getColumnLocation,
self.appModule.helperLocalBindingHandle,
self.windowHandle,
item,
subItem,
ctypes.byref(rect)
) != 0:
return None
return rect
def _getColumnLocationRawOutProc(self, index: int) -> ctypes.wintypes.RECT:
"""Retrieves rectangle containing coordinates for a given column.
Note that this method operates out of process and has to reserve memory inside a given application.
As a consequence it may fail when reserved memory is above the range available
for 32-bit processes.
Use only when in process injection is not possible.
"""
processHandle=self.processHandle
# LVM_GETSUBITEMRECT requires a pointer to a RECT structure that will receive the subitem bounding rectangle information.
localRect=RECT(
# Returns the bounding rectangle of the entire item, including the icon and label.
left=LVIR_LABEL,
# According to Microsoft, top should be the one-based index of the subitem.
# However, indexes coming from LVM_GETCOLUMNORDERARRAY are zero based.
top=index
)
internalRect=winKernel.virtualAllocEx(processHandle,None,sizeof(localRect),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE)
try:
winKernel.writeProcessMemory(processHandle,internalRect,byref(localRect),sizeof(localRect),None)
res = watchdog.cancellableSendMessage(
self.windowHandle,
LVM_GETSUBITEMRECT,
self.IAccessibleChildID - 1,
internalRect
)
if res:
winKernel.readProcessMemory(
processHandle,
internalRect,
ctypes.byref(localRect),
ctypes.sizeof(localRect),
None
)
finally:
winKernel.virtualFreeEx(processHandle,internalRect,0,winKernel.MEM_RELEASE)
if res == 0:
log.debugWarning(f"LVM_GETSUBITEMRECT failed for index {index} in list")
return None
return localRect
def _getColumnLocationRaw(self, index: int) -> Optional[RectLTRB]:
if not self.appModule.helperLocalBindingHandle:
rect = self._getColumnLocationRawOutProc(index)
else:
rect = self._getColumnLocationRawInProc(index)
if rect is None:
return None
# #8268: this might be a malformed rectangle
# (i.e. with a left coordinate that is greater than the right coordinate).
# This happens in Becky! Internet Mail,
# as well in applications that expose zero width columns.
left = rect.left
top = rect.top
right = rect.right
bottom = rect.bottom
if left > right:
left = right
if top > bottom:
top = bottom
return RectLTRB(left, top, right, bottom).toScreen(self.windowHandle).toLTWH()
def _getColumnLocation(self, column: int) -> Optional[RectLTRB]:
mappedColumn = self.parent._getMappedColumn(column)
if mappedColumn is None:
return None
return self._getColumnLocationRaw(mappedColumn)
def _getColumnContentRawInProc(self, index: int) -> Optional[str]:
"""Retrieves text for a given column.
Note that this method operates in process and cannot be used in situations where NVDA cannot inject
i.e when running as a Windows Store application or when no focus event was received on startup.
"""
item = self.IAccessibleChildID - 1
subItem = index
text = AutoFreeBSTR()
if watchdog.cancellableExecute(
NVDAHelper.localLib.nvdaInProcUtils_sysListView32_getColumnContent,
self.appModule.helperLocalBindingHandle,
self.windowHandle,
item,
subItem,
ctypes.byref(text)
) != 0:
return None
return text.value
def _getColumnContentRawOutProc(self, index: int) -> Optional[str]:
"""Retrieves text for a given column.
Note that this method operates out of process and has to reserve memory inside a given application.
As a consequence it may fail when reserved memory is above the range available
for 32-bit processes.
Use only when in process injection is not possible.
"""
buffer=None
processHandle=self.processHandle
internalItem=winKernel.virtualAllocEx(processHandle,None,sizeof(self.LVITEM),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE)
try:
internalText=winKernel.virtualAllocEx(processHandle,None,CBEMAXSTRLEN*2,winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE)
try:
item=self.LVITEM(iItem=self.IAccessibleChildID-1,mask=LVIF_TEXT|LVIF_COLUMNS,iSubItem=index,pszText=internalText,cchTextMax=CBEMAXSTRLEN)
winKernel.writeProcessMemory(processHandle,internalItem,byref(item),sizeof(self.LVITEM),None)
len = watchdog.cancellableSendMessage(self.windowHandle,LVM_GETITEMTEXTW, (self.IAccessibleChildID-1), internalItem)
if len:
winKernel.readProcessMemory(processHandle,internalItem,byref(item),sizeof(self.LVITEM),None)
buffer=create_unicode_buffer(len)
winKernel.readProcessMemory(processHandle,item.pszText,buffer,sizeof(buffer),None)
finally:
winKernel.virtualFreeEx(processHandle,internalText,0,winKernel.MEM_RELEASE)
finally:
winKernel.virtualFreeEx(processHandle,internalItem,0,winKernel.MEM_RELEASE)
return buffer.value if buffer else None
def _getColumnContentRaw(self, index: int) -> Optional[str]:
if not self.appModule.helperLocalBindingHandle:
return self._getColumnContentRawOutProc(index)
return self._getColumnContentRawInProc(index)
def _getColumnContent(self, column: int) -> Optional[str]:
mappedColumn = self.parent._getMappedColumn(column)
if mappedColumn is None:
return None
return self._getColumnContentRaw(mappedColumn)
def _getColumnImageIDRaw(self, index):
processHandle=self.processHandle
internalItem=winKernel.virtualAllocEx(processHandle,None,sizeof(self.LVITEM),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE)
try:
item=self.LVITEM(iItem=self.IAccessibleChildID-1,mask=LVIF_IMAGE|LVIF_COLUMNS,iSubItem=index)
winKernel.writeProcessMemory(processHandle,internalItem,byref(item),sizeof(self.LVITEM),None)
item.mask=LVIF_IMAGE|LVIF_COLUMNS
winKernel.writeProcessMemory(processHandle,internalItem,byref(item),sizeof(self.LVITEM),None)
watchdog.cancellableSendMessage(self.windowHandle,LVM_GETITEMW, 0, internalItem)
winKernel.readProcessMemory(processHandle,internalItem,byref(item),sizeof(item),None)
finally:
winKernel.virtualFreeEx(processHandle,internalItem,0,winKernel.MEM_RELEASE)
return item.iImage
def _getColumnImageID(self, column):
mappedColumn = self.parent._getMappedColumn(column)
if mappedColumn is None:
return None
return self._getColumnImageIDRaw(mappedColumn)
def _getColumnHeaderRawOutProc(self, index: int) -> Optional[str]:
"""Retrieves text of the header for the given column.
Note that this method operates out of process and has to reserve memory inside a given application.
As a consequence it may fail when reserved memory is above the range available
for 32-bit processes.
Use only when in process injection is not possible.
"""
buffer=None
processHandle=self.processHandle
internalColumn=winKernel.virtualAllocEx(processHandle,None,sizeof(self.LVCOLUMN),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE)
try:
internalText=winKernel.virtualAllocEx(processHandle,None,CBEMAXSTRLEN*2,winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE)
try:
column=self.LVCOLUMN(mask=LVCF_TEXT,iSubItem=index,pszText=internalText,cchTextMax=CBEMAXSTRLEN)
winKernel.writeProcessMemory(processHandle,internalColumn,byref(column),sizeof(self.LVCOLUMN),None)
res = watchdog.cancellableSendMessage(self.windowHandle,LVM_GETCOLUMNW, index, internalColumn)
if res:
winKernel.readProcessMemory(processHandle,internalColumn,byref(column),sizeof(self.LVCOLUMN),None)
buffer=create_unicode_buffer(column.cchTextMax)
winKernel.readProcessMemory(processHandle,column.pszText,buffer,sizeof(buffer),None)
finally:
winKernel.virtualFreeEx(processHandle,internalText,0,winKernel.MEM_RELEASE)
finally:
winKernel.virtualFreeEx(processHandle,internalColumn,0,winKernel.MEM_RELEASE)
return buffer.value if buffer else None
def _getColumnHeaderRawInProc(self, index: int) -> Optional[str]:
"""Retrieves text of the header for the given column.
Note that this method operates in process and cannot be used in situations where NVDA cannot inject
i.e when running as a Windows Store application or when no focus event was received on startup.
"""
subItem = index
text = AutoFreeBSTR()
if watchdog.cancellableExecute(
NVDAHelper.localLib.nvdaInProcUtils_sysListView32_getColumnHeader,
self.appModule.helperLocalBindingHandle,
self.windowHandle,
subItem,
ctypes.byref(text)
) != 0:
return None
return text.value
def _getColumnHeaderRaw(self, index: int) -> Optional[str]:
if not self.appModule.helperLocalBindingHandle:
return self._getColumnHeaderRawOutProc(index)
return self._getColumnHeaderRawInProc(index)
def _getColumnHeader(self, column: int) -> Optional[str]:
mappedColumn = self.parent._getMappedColumn(column)
if mappedColumn is None:
return None
return self._getColumnHeaderRaw(mappedColumn)
def _get_name(self):
parent = self.parent
if not isinstance(parent, List) or not parent.isMultiColumn or self._shouldDisableMultiColumn:
name = super(ListItem, self).name
if name:
return name
elif self.windowStyle & LVS_OWNERDRAWFIXED:
return self.displayText
return name
textList = []
for col in range(1, self.childCount + 1):
location = self._getColumnLocation(col)
if location and location.width == 0:
continue
content = self._getColumnContent(col)
if not content:
continue
if config.conf["documentFormatting"]["reportTableHeaders"] in (
ReportTableHeaders.ROWS_AND_COLUMNS,
ReportTableHeaders.COLUMNS,
) and col != 1:
header = self._getColumnHeader(col)
else:
header = None
if header:
textList.append("%s: %s" % (header, content))
else:
textList.append(content)
name = "; ".join(textList)
# Some list view items in Windows Vista and later can contain annoying left-to-right and right-to-left
# indicator characters which really should not be there.
return name.replace(CHAR_LTR_MARK,'').replace(CHAR_RTL_MARK,'')
value = None
def _get__shouldDisableMultiColumn(self):
if self.windowStyle & LVS_OWNERDRAWFIXED:
# This is owner drawn, but there may still be column content.
# accDescription will be empty if there is no column content,
# in which case multi-column support must be disabled.
ret = not super(ListItemWithoutColumnSupport, self).description
if ret:
self.childCount = 0
else:
ret = False
self._shouldDisableMultiColumn = ret
return ret