Refactor listbox event sending code to avoid duplication.

wxMSW wxListBox implementation contained the same code as the private
LBSendEvent() function in lboxcmn.cpp, so make this function a (protected)
member of wxListBoxBase and reuse it instead.

Also change its and CalcAndSendEvent() return type to bool to be able to
return whether the event was processed or not.

As the result of this refactoring, the "is selected" flag is now set correctly
for the selection events under MSW (it was always off before).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64496 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-06-05 22:57:53 +00:00
parent e052031692
commit 53f60d4ab6
3 changed files with 38 additions and 49 deletions

View File

@@ -96,10 +96,13 @@ public:
int HitTest(int x, int y) const { return DoListHitTest(wxPoint(x, y)); }
// For generating events in multiple and extended mode
// For generating events in multiple and extended mode: compare the current
// selections with the previously recorded ones (in m_oldSelections) and
// send the appropriate event if they differ, otherwise just return false.
bool CalcAndSendEvent();
wxArrayInt m_oldSelections;
void UpdateOldSelections();
void CalcAndSendEvent();
protected:
virtual void DoSetFirstItem(int n) = 0;
@@ -110,6 +113,11 @@ protected:
virtual int DoListHitTest(const wxPoint& WXUNUSED(point)) const
{ return wxNOT_FOUND; }
// Send a listbox (de)selection or double click event.
//
// Returns true if the event was processed.
bool SendEvent(wxEventType evtType, int item, bool selected);
private:
wxDECLARE_NO_COPY_CLASS(wxListBoxBase);
};