GetScrollPos for list box

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
gerryg
In need of some credit
In need of some credit
Posts: 9
Joined: Sun Aug 09, 2009 2:50 am

GetScrollPos for list box

Post by gerryg »

I have several simple list controls that I need to synchronize. If a selection's made in one, to make a selection in another and line them up in the display. While you can SetFirstItem() to set the first visible item, you cannot GetFirstItem. Nor does GetScrollPos() seem to work on a list box.

Is there any way in a list box to find the first visible item?
ilovasz
Earned a small fee
Earned a small fee
Posts: 21
Joined: Tue Jul 10, 2007 6:56 pm

Post by ilovasz »

Hi.

This one works with wxListBox

Code: Select all

wxString sel = m_LBSource->GetStringSelection();
int sp = m_LBSource->GetScrollPos( wxVERTICAL );
m_LBTarget->SetStringSelection( sel );
::SendMessage((HWND)m_LBTarget->GetHWND(), WM_VSCROLL, MAKELONG(SB_THUMBPOSITION, sp), NULL );
m_LBTarget->SetScrollPos( wxVERTICAL, sp, true );
LI
gerryg
In need of some credit
In need of some credit
Posts: 9
Joined: Sun Aug 09, 2009 2:50 am

Post by gerryg »

ilovasz wrote:Hi.

This one works with wxListBox

Code: Select all

int sp = m_LBSource->GetScrollPos( wxVERTICAL );
LI[/quote]

Hmmm...that was what I had tried before...
Using wxWidgets 2.8 on Ubuntu-64 Linux
Simple listbox as below, and that function asserts. I've got about 50 dialogs/50K lines of code ported and mostly workings. This is one of the few issues. If that works for you, what's different in your environment? I assume you are in Windows, but which wxWidgets version?

 wxListBox* list_box_1;

../src/gtk/window.cpp(4303): assert "sb" failed in GetScrollPos(): this window is not scrollable
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

wxListBox::HitTest( wxPoint(0,0) )
should return the first visible item.

http://docs.wxwidgets.org/stable/wx_wxl ... boxhittest
Use the source, Luke!
gerryg
In need of some credit
In need of some credit
Posts: 9
Joined: Sun Aug 09, 2009 2:50 am

Post by gerryg »

doublemax wrote:wxListBox::HitTest( wxPoint(0,0) )
should return the first visible item.

http://docs.wxwidgets.org/stable/wx_wxl ... boxhittest
Hmmm...I hadn't suspected that one; thank you.
Seems it does work, but only sometimes.

Looking more carefully, I see the listbox has a smooth scroll from the bar, instead of shifting a full line. So, I select a line and just use the keyboard down to shift by a full line each time. Going past the bottom, it then scrolls up three entries before the returned position changes, then saying index one, when it should be three. Down again to four at the top, and it returns a two.

So, now two issues. one is the wrong index returned by HitTest(). Second, the smooth scroll (instead of by-line) makes the top item ambiguous if you scroll half-way between two items.

No special options or fonts were used. The listbox code was generated by wxGlade.
ilovasz
Earned a small fee
Earned a small fee
Posts: 21
Joined: Tue Jul 10, 2007 6:56 pm

Post by ilovasz »

Hi.

Yes the above code only tested on Windows (that's my main dev platform).
Now I've tested on Fedora 11 (64 bit) with wxGTK-2.8.10 and unfortunately I've got the same error...
../src/gtk/window.cpp(4303): assert "sb" failed in GetScrollPos(): this window is not scrollable
A bug maybe?

LI
gerryg
In need of some credit
In need of some credit
Posts: 9
Joined: Sun Aug 09, 2009 2:50 am

Post by gerryg »

ilovasz wrote:Hi.

Yes the above code only tested on Windows (that's my main dev platform).
Now I've tested on Fedora 11 (64 bit) with wxGTK-2.8.10 and unfortunately I've got the same error...

A bug maybe?

LI
Yes, a platform dependency where I didn't expect it, as the first visible item should be a logical construct. I'd expect Fedora similar to Ubuntu. I'm just setting up for a Windows port using VisStudio 2008. I'll make a specific listbox test app and compare both platforms. If the SetFirstItem() works in both, I should be able to trace that to find the difference and maybe a workaround.
Update- On Ubuntu, wxListBox SetFirstItem(int) works at first, then fails for items further down the list, so this is more involved than I had hoped.
gerryg
In need of some credit
In need of some credit
Posts: 9
Joined: Sun Aug 09, 2009 2:50 am

Post by gerryg »

Okay, it took most of a day to move several wxWidget apps from Linux to XP/VisualStudio, but I can now compare the previous comments to the Windows implementation of wxWidgets.

Unlike on linux, the Windows listbox has a normal scroll by item, instead of a soft scroll.

On Linux, wxListBox::GetScrollPosition gave a runtime assert. On Windows, it worked.

Trying both wxListBox::GetScrollPosition() and HitTest(), both WORKED on Windows, while neither worked on Ubuntu-64. So this appears to be a bug in wxWidgets.

Any comments out there?
Post Reply