Re[2]: wxComboBox gives wrong selection

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re[2]: wxComboBox gives wrong selection

Vadim Zeitlin-3
On Tue, 10 Jan 2006 22:26:24 -0400 Danny Scott <[hidden email]> wrote:

DS> >  And I'd like to know how to exactly reproduce this problem please. As
DS> > usual, a patch to the controls sample would be the best.
...
DS> I modified samples/controls.cpp
DS>
DS> void MyPanel::OnCombo( wxCommandEvent &event )
DS> {
DS>     wxLogMessage(_T("EVT_COMBOBOX: item %d/%d (event/control), string
DS> \"%s\"/\"%s\""),
DS>                  (int)event.GetInt(),
DS>                  m_combo->GetSelection(),
DS>                  event.GetString().c_str(),
DS>                  m_combo->GetStringSelection().c_str());
DS> int nSel = m_combo->GetSelection();
DS>     wxLogMessage(_T("EVT_COMBOBOX: item %d/%d (event/control), string
DS> \"%s\"/\"%s\""),
DS>                  (int)nSel,
DS>                  m_combo->GetSelection(),
DS>                  event.GetString().c_str(),
DS>                  m_combo->GetStringSelection().c_str());
DS> }

 Sorry it's really not clear what have you modified (which is why I had
written that a patch would be best). AFAICS you just execute exacty the
same data twice, what's the point of doing it?

DS> With the int wxComboBox::GetSelection() const function modified to
DS>
DS> int wxComboBox::GetSelection() const
DS> {
DS>     // if the popup is currently opened, use the selection as it had
DS> been
DS>     // before it dropped down
DS>     return g_SelectionBeforePopup != wxID_NONE ? GetCurrentSelection()
DS>                                                : g_SelectionBeforePopup;
DS> }

 Err, this is clear wrong. GetSelection() should never return wxID_NONE.


 To summarize, I still don't know what the bug is nor how to reproduce it.
The controls sample seems to work just fine for me, whether I use the
keyboard or the mouse.

 Regards,
VZ


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Re[2]: wxComboBox gives wrong selection

Danny Scott
I have rebuilt wx with the stock

int wxComboBox::GetSelection() const
{
    // if the popup is currently opened, use the selection as it had been
    // before it dropped down
    return g_SelectionBeforePopup == wxID_NONE ? GetCurrentSelection()
                                               : g_SelectionBeforePopup;
}

I just noticed that the controls sample includes both the results from event.GetInt() and combobox->GetSelection(), so you don't have to change the sample.

When I run the controls sample and select the third line in the combobox sample, the complete output is:

This is the log window.
Book selection is being changed from 0 to 2 (current page from book is 0)
Book selection is now 2 (from book: 2)
04:26:57 PM: MyComboBox::OnFocusGot
04:26:57 PM: EVT_IDLE: combobox selection changed from -1 to 0
04:26:59 PM: EVT_COMBOBOX: item 2/0 (event/control), string "really"/"really"
04:26:59 PM: MyComboBox::OnFocusGot
04:26:59 PM: EVT_IDLE: combobox selection changed from 0 to 2

I would expect the line
04:26:59 PM: EVT_COMBOBOX: item 2/0 (event/control), string "really"/"really"

to have the same results (that is 2/2, not 2/0).

Next, I put focus in the combo box and pressed the down arrow key. The following output is produced:

04:32:09 PM: MyComboBox::OnFocusGot
04:32:12 PM: MyComboBox::OnKeyDown
04:32:12 PM: MyComboBox::OnChar
04:32:12 PM: EVT_TEXT for the combobox: "" (event) or "" (control).
04:32:12 PM: EVT_TEXT for the combobox: "wonderful" (event) or "wonderful" (control).
04:32:12 PM: EVT_COMBOBOX: item 3/3 (event/control), string "wonderful"/"wonderful"
04:32:12 PM: EVT_TEXT for the combobox: "wonderful" (event) or "wonderful" (control).
04:32:12 PM: EVT_IDLE: combobox selection changed from 2 to 3
04:32:12 PM: MyComboBox::OnKeyUp

Note that the line
04:32:12 PM: EVT_COMBOBOX: item 3/3 (event/control), string "wonderful"/"wonderful"
produces the expected results.

This means that when the EVT_COMBOBOX handler is called as the result of a selection by mouse, the g_SelectionBeforePopup value is NOT wxID_NONE, so the return value of GetSelection() is the value in g_SelectionBeforePopup.

When  the EVT_COMBOBOX handler is called as the result of a selection by keyboard, the g_SelectionBeforePopup value is wxID_NONE, so the return value of GetSelection() is the value returned by GetCurrentSelection().

I have run the example with a break in the wxComboBox::GetSelection function, and regardless of using the keyboard or the mouse, it only gets called once, and if it is only called once it should return the value from wxComboBox::GetCurrentSelection().

I apologize for not sending you the diff before, but I only added the single line and made it bold.

Thanks
Danny

Reply | Threaded
Open this post in threaded view
|

Re[4]: wxComboBox gives wrong selection

Vadim Zeitlin-3
On Sun, 15 Jan 2006 16:48:45 -0400 Danny Scott <[hidden email]> wrote:

DS> When I run the controls sample and select the third line in the combobox
DS> sample, the complete output is:
DS>
DS> This is the log window.
DS> Book selection is being changed from 0 to 2 (current page from book is
DS> 0)
DS> Book selection is now 2 (from book: 2)
DS> 04:26:57 PM: MyComboBox::OnFocusGot
DS> 04:26:57 PM: EVT_IDLE: combobox selection changed from -1 to 0
DS> 04:26:59 PM: EVT_COMBOBOX: item 2/0 (event/control), string
DS> "really"/"really"
DS> 04:26:59 PM: MyComboBox::OnFocusGot
DS> 04:26:59 PM: EVT_IDLE: combobox selection changed from 0 to 2
DS>
DS> I would expect the line
DS> 04:26:59 PM: EVT_COMBOBOX: item 2/0 (event/control), string
DS> "really"/"really"
DS>
DS> to have the same results (that is 2/2, not 2/0).

 Indeed, I didn't notice this discrepancy somehow, sorry. This is fixed
now, it was just a stupid mistake in gtk_popup_hide_callback() code.

DS> I apologize for not sending you the diff before, but I only added the
DS> single line and made it bold.

 The problem is that I couldn't understand why did you make this change (as
GetSelection() was already called anyhow) and so I reread it several times
trying to understand what I was missing.

 Regards,
VZ


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]