#include "wx/univ/inphand.h"
#include "wx/univ/theme.h"
+// ----------------------------------------------------------------------------
+// wxStdListboxInputHandler: handles mouse and kbd in a single or multi
+// selection listbox
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxStdListboxInputHandler : public wxStdInputHandler
+{
+public:
+ // if pressing the mouse button in a multiselection listbox should toggle
+ // the item under mouse immediately, then specify true as the second
+ // parameter (this is the standard behaviour, under GTK the item is toggled
+ // only when the mouse is released in the multi selection listbox)
+ wxStdListboxInputHandler(wxInputHandler *inphand,
+ bool toggleOnPressAlways = true);
+
+ // base class methods
+ virtual bool HandleKey(wxInputConsumer *consumer,
+ const wxKeyEvent& event,
+ bool pressed);
+ virtual bool HandleMouse(wxInputConsumer *consumer,
+ const wxMouseEvent& event);
+ virtual bool HandleMouseMove(wxInputConsumer *consumer,
+ const wxMouseEvent& event);
+
+protected:
+ // return the item under mouse, 0 if the mouse is above the listbox or
+ // GetCount() if it is below it
+ int HitTest(const wxListBox *listbox, const wxMouseEvent& event);
+
+ // parts of HitTest(): first finds the pseudo (because not in range) index
+ // of the item and the second one adjusts it if necessary - that is if the
+ // third one returns false
+ int HitTestUnsafe(const wxListBox *listbox, const wxMouseEvent& event);
+ int FixItemIndex(const wxListBox *listbox, int item);
+ bool IsValidIndex(const wxListBox *listbox, int item);
+
+ // init m_btnCapture and m_actionMouse
+ wxControlAction SetupCapture(wxListBox *lbox,
+ const wxMouseEvent& event,
+ int item);
+
+ wxRenderer *m_renderer;
+
+ // the button which initiated the mouse capture (currently 0 or 1)
+ int m_btnCapture;
+
+ // the action to perform when the mouse moves while we capture it
+ wxControlAction m_actionMouse;
+
+ // the ctor parameter toggleOnPressAlways (see comments near it)
+ bool m_toggleOnPressAlways;
+
+ // do we track the mouse outside the window when it is captured?
+ bool m_trackMouseOutside;
+};
+
// ============================================================================
// implementation of wxListBox
// ============================================================================
Set(n, choices);
- SetBestSize(size);
+ SetInitialSize(size);
CreateInputHandler(wxINP_HANDLER_LISTBOX);
m_updateScrollbarX = true;
}
// or also decreased if the old string was the longest one
- else if ( n == m_maxWidthItem )
+ else if ( n == (unsigned int)m_maxWidthItem )
{
RefreshHorzScrollbar();
}
{
m_current = -1;
}
- else if ( n < m_current )
+ else if ( (int)n < m_current )
{
m_current--;
}
unsigned int count = m_selections.GetCount();
for ( unsigned int item = 0; item < count; item++ )
{
- if ( m_selections[item] == n )
+ if ( m_selections[item] == (int)n )
{
// remember to delete it later
index = item;
}
- else if ( m_selections[item] > n )
+ else if ( m_selections[item] > (int)n )
{
// to account for the index shift
m_selections[item]--;
m_updateScrollbarY = true;
// finally, if the longest item was deleted the scrollbar may disappear
- if ( n == m_maxWidthItem )
+ if ( (int)n == m_maxWidthItem )
{
RefreshHorzScrollbar();
}
{
if ( select )
{
- if ( m_selections.Index(n) == wxNOT_FOUND )
+ if ( n == wxNOT_FOUND )
+ {
+ if ( !HasMultipleSelection() )
+ {
+ // selecting wxNOT_FOUND is documented to deselect all items
+ DeselectAll();
+ return;
+ }
+ }
+ else if ( m_selections.Index(n) == wxNOT_FOUND )
{
if ( !HasMultipleSelection() )
{
return true;
}
+/* static */
+wxInputHandler *wxListBox::GetStdInputHandler(wxInputHandler *handlerDef)
+{
+ static wxStdListboxInputHandler s_handler(handlerDef);
+
+ return &s_handler;
+}
+
// ============================================================================
// implementation of wxStdListboxInputHandler
// ============================================================================
break;
case WXK_PAGEUP:
-
- case WXK_PRIOR:
action = wxACTION_LISTBOX_PAGEUP;
break;
case WXK_PAGEDOWN:
-
- case WXK_NEXT:
action = wxACTION_LISTBOX_PAGEDOWN;
break;