[wx 2.8.4, GTK+ 2, g++] Problem updating value of wxSpinCtrl in wxSpinEvent

Kit kit at bishop.net.nz
Tue Jul 10 04:20:00 PDT 2007


Francesco Montorsi wrote:
> Francesco Montorsi ha scritto:
>> Frank Bennewitz ha scritto:
>>> Hi Francesco,
>>>
>>> I tried this:
>>>
>>> void MyFrame::OnGaussSpin(wxSpinEvent &event) {
>>>         //Hier muss die Behandlung der Werte rein: es dürfen nur 
>>> ungerade Integer sein.
>>>         wxSpinCtrl *m_pMySpinCtrl= 
>>> (wxSpinCtrl*)FindWindowById(PANEL_GAUSS_SPIN);
>>>     int val=event.GetPosition();
>>>       m_pMySpinCtrl->SetValue(val-2);
>>> }
>>>
>>> and it still doesn't work. The Problem is (I guess) that after 
>>> m_pMySpinCtrl->SetValue(val-2) is called, another EVT_SPINCTRL is fired
>> this is a "bug". Either in the documentation or in wxSpinCtrl.
>>
>> It should be fixed like we did for other controls adding an 
>> event-free function to wxSpinCtrl... (see the paragraph "user 
>> generated events vs programmatically generated events").
>
> A workaround for now is to use the wxEventBlocker class (but I'm not 
> sure if it's only in wxSVN or also in wx2.8)...
>
> HTH,
> Francesco
>
An alternate, though slightly clumsy work around is to maintain a flag 
in your own class:

class MyFrame : public wxFrame
{
        .....
private:
       bool      inSetSpin;   // Initialise this to false in your 
constructor
       ......
}

void MyFrame::OnGaussSpin(wxSpinEvent &event)
{
       if (!inSetSpin)
       {
            wxSpinCtrl *m_pMySpinCtrl= 
(wxSpinCtrl*)FindWindowById(PANEL_GAUSS_SPIN);
            int val=event.GetPosition();
            inSetSpin = true;
            m_pMySpinCtrl->SetValue(val-2);
            inSetSpin = false;
       }
}

Only problem is if you have more than one control for which the event 
procedure is used.  Then you have to get a bit more inventive along the 
same lines.

Best regards,
Kit






More information about the wx-users mailing list