|
1 | 1 | # -*- coding: UTF-8 -*- |
2 | | -#A part of NonVisual Desktop Access (NVDA) |
3 | | -#Copyright (C) 2016-2018 NV Access Limited, Derek Riemer |
4 | | -#This file is covered by the GNU General Public License. |
5 | | -#See the file COPYING for more details. |
| 2 | +# A part of NonVisual Desktop Access (NVDA) |
| 3 | +# Copyright (C) 2016-2021 NV Access Limited, Derek Riemer |
| 4 | +# This file is covered by the GNU General Public License. |
| 5 | +# See the file COPYING for more details. |
6 | 6 |
|
7 | | -from ctypes.wintypes import BOOL |
8 | | -from typing import Any, Tuple, Optional |
9 | 7 | import wx |
10 | | -from comtypes import GUID |
| 8 | +from wx.lib import scrolledpanel |
11 | 9 | from wx.lib.mixins import listctrl as listmix |
12 | 10 | from .dpiScalingHelper import DpiScalingHelperMixin |
13 | 11 | from . import guiHelper |
14 | | -import oleacc |
15 | 12 | import winUser |
16 | 13 | import winsound |
| 14 | +import math |
| 15 | + |
17 | 16 | from collections.abc import Callable |
18 | 17 |
|
19 | 18 | class AutoWidthColumnListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin): |
@@ -355,3 +354,37 @@ def onSliderChar(self, evt): |
355 | 354 | evt.Skip() |
356 | 355 | return |
357 | 356 | self.SetValue(newValue) |
| 357 | + |
| 358 | + |
| 359 | +class TabbableScrolledPanel(scrolledpanel.ScrolledPanel): |
| 360 | + """ |
| 361 | + This class was created to ensure a ScrolledPanel scrolls to nested children of the panel when navigating |
| 362 | + with tabs (#12224). A PR to wxPython implementing this fix can be tracked on |
| 363 | + https://github.com/wxWidgets/Phoenix/pull/1950 |
| 364 | + """ |
| 365 | + def GetChildRectRelativeToSelf(self, child: wx.Window) -> wx.Rect: |
| 366 | + """ |
| 367 | + window.GetRect returns the size of a window, and its position relative to its parent. |
| 368 | + When calculating ScrollChildIntoView, the position relative to its parent is not relevant unless the |
| 369 | + parent is the ScrolledPanel itself. Instead, calculate the position relative to scrolledPanel |
| 370 | + """ |
| 371 | + childRectRelativeToScreen = child.GetScreenRect() |
| 372 | + scrolledPanelScreenPosition = self.GetScreenPosition() |
| 373 | + return wx.Rect( |
| 374 | + childRectRelativeToScreen.x - scrolledPanelScreenPosition.x, |
| 375 | + childRectRelativeToScreen.y - scrolledPanelScreenPosition.y, |
| 376 | + childRectRelativeToScreen.width, |
| 377 | + childRectRelativeToScreen.height |
| 378 | + ) |
| 379 | + |
| 380 | + def ScrollChildIntoView(self, child: wx.Window) -> None: |
| 381 | + """ |
| 382 | + Overrides child.GetRect with `GetChildRectRelativeToSelf` before calling |
| 383 | + `super().ScrollChildIntoView`. `super().ScrollChildIntoView` incorrectly uses child.GetRect to |
| 384 | + navigate scrolling, which is relative to the parent, where it should instead be relative to this |
| 385 | + ScrolledPanel. |
| 386 | + """ |
| 387 | + oldChildGetRectFunction = child.GetRect |
| 388 | + child.GetRect = lambda: self.GetChildRectRelativeToSelf(child) |
| 389 | + super().ScrollChildIntoView(child) |
| 390 | + child.GetRect = oldChildGetRectFunction |
0 commit comments