Fix horizontal scrollbar handling for wxCheckListBox in wxMSW
The scrollbar wasn't shown when the control became only slightly more narrow than its contents, resulting in truncation of the rightmost part of the strings shown in it. Fix this by accounting for the check box explicitly in wxListBox SetHorizontalExtent() method using the new MSWGetFullItemSize() helper which is also used to avoid code duplication between wxCheckListBox MSWOnMeasure() and DoGetBestClientSize() methods. Closes #18377.
This commit is contained in:
@@ -65,6 +65,8 @@ public:
|
|||||||
virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item) wxOVERRIDE;
|
virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item) wxOVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual wxSize MSWGetFullItemSize(int w, int h) const wxOVERRIDE;
|
||||||
|
|
||||||
// pressing space or clicking the check box toggles the item
|
// pressing space or clicking the check box toggles the item
|
||||||
void OnKeyDown(wxKeyEvent& event);
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
void OnLeftClick(wxMouseEvent& event);
|
void OnLeftClick(wxMouseEvent& event);
|
||||||
|
@@ -174,6 +174,13 @@ protected:
|
|||||||
// this can't be called DoHitTest() because wxWindow already has this method
|
// this can't be called DoHitTest() because wxWindow already has this method
|
||||||
virtual int DoHitTestList(const wxPoint& point) const;
|
virtual int DoHitTestList(const wxPoint& point) const;
|
||||||
|
|
||||||
|
// This is a hook for wxCheckListBox, which uses it to add the checkbox
|
||||||
|
// width to the item width and to make it at least as tall as the checkbox.
|
||||||
|
virtual wxSize MSWGetFullItemSize(int w, int h) const
|
||||||
|
{
|
||||||
|
return wxSize(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
// free memory (common part of Clear() and dtor)
|
// free memory (common part of Clear() and dtor)
|
||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
|
@@ -246,15 +246,10 @@ bool wxCheckListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
|
|||||||
{
|
{
|
||||||
MEASUREITEMSTRUCT *pStruct = (MEASUREITEMSTRUCT *)item;
|
MEASUREITEMSTRUCT *pStruct = (MEASUREITEMSTRUCT *)item;
|
||||||
|
|
||||||
wxSize size = wxRendererNative::Get().GetCheckBoxSize(this);
|
const wxSize size = MSWGetFullItemSize(pStruct->itemWidth,
|
||||||
size.x += 2 * CHECKMARK_EXTRA_SPACE;
|
pStruct->itemHeight);
|
||||||
size.y += 2 * CHECKMARK_EXTRA_SPACE;
|
pStruct->itemWidth = size.x;
|
||||||
|
pStruct->itemHeight = size.y;
|
||||||
// add place for the check mark
|
|
||||||
pStruct->itemWidth += size.GetWidth();
|
|
||||||
|
|
||||||
if ( pStruct->itemHeight < static_cast<unsigned int>(size.GetHeight()) )
|
|
||||||
pStruct->itemHeight = size.GetHeight();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -422,20 +417,25 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxSize wxCheckListBox::MSWGetFullItemSize(int w, int h) const
|
||||||
|
{
|
||||||
|
wxSize size = wxRendererNative::Get().GetCheckBoxSize(const_cast<wxCheckListBox*>(this));
|
||||||
|
size.x += 2 * CHECKMARK_EXTRA_SPACE;
|
||||||
|
size.y += 2 * CHECKMARK_EXTRA_SPACE;
|
||||||
|
|
||||||
|
w += size.GetWidth();
|
||||||
|
if ( h < size.GetHeight() )
|
||||||
|
h = size.GetHeight();
|
||||||
|
|
||||||
|
return wxSize(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
wxSize wxCheckListBox::DoGetBestClientSize() const
|
wxSize wxCheckListBox::DoGetBestClientSize() const
|
||||||
{
|
{
|
||||||
wxSize best = wxListBox::DoGetBestClientSize();
|
wxSize best = wxListBox::DoGetBestClientSize();
|
||||||
|
|
||||||
// add room for the checkbox
|
// add room for the checkbox
|
||||||
wxSize size = wxRendererNative::Get().GetCheckBoxSize(const_cast<wxCheckListBox*>(this));
|
return MSWGetFullItemSize(best.x, best.y);
|
||||||
size.x += 2 * CHECKMARK_EXTRA_SPACE;
|
|
||||||
size.y += 2 * CHECKMARK_EXTRA_SPACE;
|
|
||||||
|
|
||||||
best.x += size.GetWidth();
|
|
||||||
if ( best.y < size.GetHeight() )
|
|
||||||
best.y = size.GetHeight();
|
|
||||||
|
|
||||||
return best;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_CHECKLISTBOX
|
#endif // wxUSE_CHECKLISTBOX
|
||||||
|
@@ -596,7 +596,10 @@ void wxListBox::SetHorizontalExtent(const wxString& s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( largestExtent )
|
if ( largestExtent )
|
||||||
|
{
|
||||||
|
largestExtent = MSWGetFullItemSize(largestExtent, 0 /* height */).x;
|
||||||
SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(largestExtent), 0L);
|
SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(largestExtent), 0L);
|
||||||
|
}
|
||||||
//else: it shouldn't change
|
//else: it shouldn't change
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user