mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-08-17 08:53:06 +08:00
Improve code finding native spin control in wxNotebook
Simply use Win32 FindWindowEx() instead of enumerating child windows with a loop. Also extract this code into a reusable function. No real changes yet. See #26685.
This commit is contained in:
committed by
Vadim Zeitlin
parent
589b622899
commit
5ea5e65a59
@@ -202,6 +202,9 @@ private:
|
||||
// It has the same semantics as HitTest().
|
||||
int MSWHitTestLeftRight(const wxPoint& pt, long *flags) const;
|
||||
|
||||
// Subclass the spin button if it exists.
|
||||
void MSWSubclassSpin();
|
||||
|
||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxNotebook);
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
};
|
||||
|
||||
+19
-25
@@ -980,6 +980,24 @@ wxNotebookSpinBtnWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
void wxNotebook::MSWSubclassSpin()
|
||||
{
|
||||
if ( !m_hasSubclassedUpdown )
|
||||
{
|
||||
// Find the spin button.
|
||||
HWND hwndSpin = FindWindowExA(m_hWnd, nullptr, UPDOWN_CLASSA, nullptr);
|
||||
if ( hwndSpin )
|
||||
{
|
||||
// Subclass the spin button.
|
||||
if ( !gs_wndprocNotebookSpinBtn )
|
||||
gs_wndprocNotebookSpinBtn = wxGetWindowProc(hwndSpin);
|
||||
|
||||
wxSetWindowProc(hwndSpin, wxNotebookSpinBtnWndProc);
|
||||
m_hasSubclassedUpdown = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT APIENTRY
|
||||
wxNotebookWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
@@ -1528,31 +1546,7 @@ void wxNotebook::OnSize(wxSizeEvent& event)
|
||||
false);
|
||||
}
|
||||
|
||||
// subclass the spin control used by the notebook to scroll pages to
|
||||
// prevent it from flickering on resize
|
||||
if ( !m_hasSubclassedUpdown )
|
||||
{
|
||||
// iterate over all child windows to find spin button
|
||||
for ( HWND child = ::GetWindow(GetHwnd(), GW_CHILD);
|
||||
child;
|
||||
child = ::GetWindow(child, GW_HWNDNEXT) )
|
||||
{
|
||||
wxWindow *childWindow = wxFindWinFromHandle((WXHWND)child);
|
||||
|
||||
// see if it exists, if no wxWindow found then assume it's the spin
|
||||
// btn
|
||||
if ( !childWindow )
|
||||
{
|
||||
// subclass the spin button to override WM_ERASEBKGND
|
||||
if ( !gs_wndprocNotebookSpinBtn )
|
||||
gs_wndprocNotebookSpinBtn = wxGetWindowProc(child);
|
||||
|
||||
wxSetWindowProc(child, wxNotebookSpinBtnWndProc);
|
||||
m_hasSubclassedUpdown = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
MSWSubclassSpin();
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user