Opened 6 years ago

Closed 4 years ago

#4665 closed defect (fixed)

wxSearchCtrl events don't relay the string value

Reported by: ivansmirnov Owned by: vadz
Priority: low Milestone:
Component: GUI-generic Version: stable-latest
Keywords: wxSearchCtrl simple Cc: ivansmirnov
Blocked By: Blocking:
Patch: no

Description

I have a wxSearchCtrl that has all of these events hooked up:

EVT_TEXT_ENTER
EVT_TEXT
EVT_SEARCHCTRL_SEARCH_BTN

When my event handler fires, event.GetEventId() works correctly, but event.GetString() always returns an empty.

I would just assume that the wxCommandEvent being passed to my handlers would have the value from the wxSearchCtrl 's text box in it. That's wxTextCtrl handles these events.

Attachments (1)

searchctrl.patch download (445 bytes) - added by johnr 4 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 6 years ago by wojdyr

  • Component set to GUI-all
  • Keywords wxSearchCtrl added

what platform?

comment:2 Changed 4 years ago by johnr

I am guessing some of these ancillary ctrls aren't used as it appears no one notices they don't work properly. Still doesn't work for me on MSW with trunk and VC++. Not tried on any other platforms. I see it is in the widgets sample but at a quick look is not bound to any text events and I have lost too many hours this week on various components to do a patch on something that has languished for two years. A shame there isn't access to the wxTextCtrl or it would be usable via other means.

No offense intended as I am very appreciative of the voluntary work done by the devs but when I started using wxWidgets someone who had previously used wxWidgets said to me that the code was buggy and difficult to get any fixes/changes done.

comment:3 follow-up: Changed 4 years ago by vadz

  • Component changed from GUI-all to GUI-generic
  • Keywords simple added
  • Priority changed from normal to low
  • Status changed from new to confirmed
  • Version set to 2.9-svn

Looking at the code the text of the control is indeed not passed via the event but this is really not a big deal as you can always retrieve it from GetEventObjject() by just calling GetValue() on it (after a cast).

Anyhow, I agree that we should pass the text to be searched for in the event itself, there doesn't seem to be any reason not to.

comment:4 in reply to: ↑ 3 ; follow-up: Changed 4 years ago by johnr

Replying to vadz:

Looking at the code the text of the control is indeed not passed via the event but this is really not a big deal as you can always retrieve it from GetEventObjject() by just calling GetValue() on it (after a cast).

I tried several different cast types to wxTextCtrl* but all failed when it came to using GetValue(). I suppose because of the composite nature of the control. I did attempt a cast to wxSearchTextCtrl* but got compiler errors. Perhaps I missed something there given your comment.

Anyhow, I agree that we should pass the text to be searched for in the event itself, there doesn't seem to be any reason not to.

The event eventText passed to wxSearchTextCtrl::OnText(wxCommandEvent& eventText) always contains an empty string.

comment:5 in reply to: ↑ 4 Changed 4 years ago by johnr

In the absence of any other workable solution other than rolling my own ctrl, I ended up adding a
wxTextCtrl* GetTextCtrl()
method to srchctlg.h wxSearchCtrl.

I need to store a pointer so another generic routine can use GetValue().

comment:6 Changed 4 years ago by vadz

I still don't understand what the problem is. The following patch seems to work just fine to me:

  • samples/widgets/searchctrl.cpp

    a b protected: 
    8484    void OnToggleCancelButton(wxCommandEvent&); 
    8585    void OnToggleSearchMenu(wxCommandEvent&); 
    8686 
     87    void OnSearch(wxCommandEvent& event); 
     88 
    8789    wxMenu* CreateTestMenu(); 
    8890     
    8991    // (re)create the control 
    BEGIN_EVENT_TABLE(SearchCtrlWidgetsPage, WidgetsPage) 
    111113    EVT_CHECKBOX(ID_SEARCH_CB, SearchCtrlWidgetsPage::OnToggleSearchButton) 
    112114    EVT_CHECKBOX(ID_CANCEL_CB, SearchCtrlWidgetsPage::OnToggleCancelButton) 
    113115    EVT_CHECKBOX(ID_MENU_CB, SearchCtrlWidgetsPage::OnToggleSearchMenu) 
     116 
     117    EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearch) 
    114118END_EVENT_TABLE() 
    115119 
    116120// ============================================================================ 
    void SearchCtrlWidgetsPage::OnToggleSearchMenu(wxCommandEvent&) 
    222226        m_srchCtrl->SetMenu(NULL); 
    223227} 
    224228 
     229void SearchCtrlWidgetsPage::OnSearch(wxCommandEvent& event) 
     230{ 
     231    wxSearchCtrl * const 
     232        s = static_cast<wxSearchCtrl *>(event.GetEventObject()); 
     233    wxLogMessage("Search button: search for \"%s\".", s->GetValue()); 
     234} 
    225235 
    226236#endif  //  wxUSE_SEARCHCTRL 

Do you have any problems with it? If so, under what platform?

comment:7 follow-up: Changed 4 years ago by vadz

  • Owner set to vadz
  • Status changed from confirmed to accepted

Oh well, after all it's so simple to provide the string in the event itself that I'll just do it. I can't commit my changes now but they will be in svn in a couple of days.

comment:8 in reply to: ↑ 7 Changed 4 years ago by johnr

Replying to vadz:
As is often the case, the problem was a misunderstanding and I was hoping to cast to or retrieve the wxTextCtrl to suit my database wrapping code. That code I have now modified to accept a string directly. Apologies for any time lost.

Oh well, after all it's so simple to provide the string in the event itself that I'll just do it. I can't commit my changes now but they will be in svn in a couple of days.

Thanks! Patch tested on msw and attached if that helps.

Changed 4 years ago by johnr

comment:9 Changed 4 years ago by VZ

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [64886]) Set the string to search for in wxSearchCtrl events.

It's more convenient to have the string to search for directly in the event
object than to retrieve it from wxSearchCtrl itself as it had to be done
before.

Closes #4665.

Note: See TracTickets for help on using tickets.