1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxListBox class interface
4 // Author: Vadim Zeitlin
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_LISTBOX_H_BASE_
12 #define _WX_LISTBOX_H_BASE_
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
22 #include "wx/ctrlsub.h" // base class
24 // forward declarations are enough here
25 class WXDLLIMPEXP_FWD_BASE wxArrayInt
;
26 class WXDLLIMPEXP_FWD_BASE wxArrayString
;
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 extern WXDLLIMPEXP_DATA_CORE(const char) wxListBoxNameStr
[];
34 // ----------------------------------------------------------------------------
35 // wxListBox interface is defined by the class wxListBoxBase
36 // ----------------------------------------------------------------------------
38 class WXDLLIMPEXP_CORE wxListBoxBase
: public wxControlWithItems
42 virtual ~wxListBoxBase();
44 void InsertItems(unsigned int nItems
, const wxString
*items
, unsigned int pos
)
45 { Insert(nItems
, items
, pos
); }
46 void InsertItems(const wxArrayString
& items
, unsigned int pos
)
47 { Insert(items
, pos
); }
49 // multiple selection logic
50 virtual bool IsSelected(int n
) const = 0;
51 virtual void SetSelection(int n
);
52 void SetSelection(int n
, bool select
) { DoSetSelection(n
, select
); }
53 void Deselect(int n
) { DoSetSelection(n
, false); }
54 void DeselectAll(int itemToLeaveSelected
= -1);
56 virtual bool SetStringSelection(const wxString
& s
, bool select
);
57 virtual bool SetStringSelection(const wxString
& s
)
59 return SetStringSelection(s
, true);
62 // works for single as well as multiple selection listboxes (unlike
63 // GetSelection which only works for listboxes with single selection)
64 virtual int GetSelections(wxArrayInt
& aSelections
) const = 0;
66 // set the specified item at the first visible item or scroll to max
68 void SetFirstItem(int n
) { DoSetFirstItem(n
); }
69 void SetFirstItem(const wxString
& s
);
71 // ensures that the given item is visible scrolling the listbox if
73 virtual void EnsureVisible(int n
);
75 // a combination of Append() and EnsureVisible(): appends the item to the
76 // listbox and ensures that it is visible i.e. not scrolled out of view
77 void AppendAndEnsureVisible(const wxString
& s
);
79 // return true if the listbox allows multiple selection
80 bool HasMultipleSelection() const
82 return (m_windowStyle
& wxLB_MULTIPLE
) ||
83 (m_windowStyle
& wxLB_EXTENDED
);
86 // override wxItemContainer::IsSorted
87 virtual bool IsSorted() const { return HasFlag( wxLB_SORT
); }
89 // emulate selecting or deselecting the item event.GetInt() (depending on
90 // event.GetExtraLong())
91 void Command(wxCommandEvent
& event
);
93 // return the index of the item at this position or wxNOT_FOUND
94 int HitTest(const wxPoint
& point
) const { return DoListHitTest(point
); }
95 int HitTest(int x
, int y
) const { return DoListHitTest(wxPoint(x
, y
)); }
99 virtual void DoSetFirstItem(int n
) = 0;
101 virtual void DoSetSelection(int n
, bool select
) = 0;
103 // there is already wxWindow::DoHitTest() so call this one differently
104 virtual int DoListHitTest(const wxPoint
& WXUNUSED(point
)) const
105 { return wxNOT_FOUND
; }
107 // Helper for the code generating events in single selection mode: updates
108 // m_oldSelections and return true if the selection really changed.
109 // Otherwise just returns false.
110 bool DoChangeSingleSelection(int item
);
112 // Helper for generating events in multiple and extended mode: compare the
113 // current selections with the previously recorded ones (in
114 // m_oldSelections) and send the appropriate event if they differ,
115 // otherwise just return false.
116 bool CalcAndSendEvent();
118 // Send a listbox (de)selection or double click event.
120 // Returns true if the event was processed.
121 bool SendEvent(wxEventType evtType
, int item
, bool selected
);
123 // Array storing the indices of all selected items that we already notified
124 // the user code about for multi selection list boxes.
126 // For single selection list boxes, we reuse this array to store the single
127 // currently selected item, this is used by DoChangeSingleSelection().
129 // TODO-OPT: wxSelectionStore would be more efficient for big list boxes.
130 wxArrayInt m_oldSelections
;
132 // Update m_oldSelections with currently selected items (does nothing in
133 // single selection mode on platforms other than MSW).
134 void UpdateOldSelections();
137 wxDECLARE_NO_COPY_CLASS(wxListBoxBase
);
140 // ----------------------------------------------------------------------------
141 // include the platform-specific class declaration
142 // ----------------------------------------------------------------------------
144 #if defined(__WXUNIVERSAL__)
145 #include "wx/univ/listbox.h"
146 #elif defined(__WXMSW__)
147 #include "wx/msw/listbox.h"
148 #elif defined(__WXMOTIF__)
149 #include "wx/motif/listbox.h"
150 #elif defined(__WXGTK20__)
151 #include "wx/gtk/listbox.h"
152 #elif defined(__WXGTK__)
153 #include "wx/gtk1/listbox.h"
154 #elif defined(__WXMAC__)
155 #include "wx/osx/listbox.h"
156 #elif defined(__WXPM__)
157 #include "wx/os2/listbox.h"
158 #elif defined(__WXCOCOA__)
159 #include "wx/cocoa/listbox.h"
162 #endif // wxUSE_LISTBOX
165 // _WX_LISTBOX_H_BASE_