Page 1 of 1

GetScrollPos for list box

Posted: Mon Aug 10, 2009 5:41 pm
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?

Posted: Tue Aug 11, 2009 7:51 pm
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

Posted: Wed Aug 12, 2009 9:31 pm
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

Posted: Thu Aug 13, 2009 12:12 am
by doublemax
wxListBox::HitTest( wxPoint(0,0) )
should return the first visible item.

http://docs.wxwidgets.org/stable/wx_wxl ... boxhittest

Posted: Thu Aug 13, 2009 3:37 am
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.

Posted: Thu Aug 13, 2009 8:39 am
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

Posted: Thu Aug 13, 2009 2:27 pm
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.

Posted: Sat Aug 15, 2009 4:17 am
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?