Ticket #3224: 3224EnsureVisible.patch

File 3224EnsureVisible.patch, 1.9 KB (added by RIVDSL, 3 years ago)

Implementation patch

  • include/wx/msw/listbox.h

     
    9393    int HitTest(const wxPoint& pt) const { return DoHitTestList(pt); }
    9494    int HitTest(wxCoord x, wxCoord y) const { return DoHitTestList(wxPoint(x, y)); }
    9595
     96    virtual void EnsureVisible(int n);
     97       
    9698    // ownerdrawn wxListBox and wxCheckListBox support
    9799#if wxUSE_OWNER_DRAWN
    98100    // override base class virtuals
  • src/msw/listbox.cpp

     
    221221// implementation of wxListBoxBase methods
    222222// ----------------------------------------------------------------------------
    223223
     224void wxListBox::EnsureVisible(int N)
     225{
     226    wxCHECK_RET( IsValid(N),
     227                 wxT("invalid index in wxListBox::EnsureVisible") );
     228
     229        // when item is before the first visible item, make the item the first visible item
     230        int firstItem = SendMessage(GetHwnd(), LB_GETTOPINDEX, (WPARAM)0, (LPARAM)0);
     231        if ( N <= firstItem )
     232        {
     233                DoSetFirstItem(N);
     234                return;
     235        }
     236
     237        // retrieve item height in order to compute last visible item and scroll amount
     238        int itemHeight = SendMessage(GetHwnd(), LB_GETITEMHEIGHT, (WPARAM)0, (LPARAM)0);
     239        if ( itemHeight == LB_ERR || itemHeight == 0)
     240                return;
     241
     242        // compute the amount of fully visible items
     243        int countVisible = GetClientSize().y / itemHeight;
     244        if (countVisible <= 0)
     245                countVisible = 1;
     246
     247        // when item is before the last fully visible item, it is already visible       
     248        int lastItem = firstItem + countVisible - 1;
     249        if ( N <= lastItem )
     250                return;
     251
     252        // make the item the last visible item by setting the first visible item accordingly
     253        DoSetFirstItem(N - countVisible + 1);
     254}
     255
    224256void wxListBox::DoSetFirstItem(int N)
    225257{
    226258    wxCHECK_RET( IsValid(N),