1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxListBox class interface
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_LISTBOX_H_BASE_
13 #define _WX_LISTBOX_H_BASE_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
23 #include "wx/ctrlsub.h" // base class
25 // forward declarations are enough here
26 class WXDLLIMPEXP_FWD_BASE wxArrayInt
;
27 class WXDLLIMPEXP_FWD_BASE wxArrayString
;
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 extern WXDLLEXPORT_DATA(const char) wxListBoxNameStr
[];
35 // ----------------------------------------------------------------------------
36 // wxListBox interface is defined by the class wxListBoxBase
37 // ----------------------------------------------------------------------------
39 class WXDLLEXPORT wxListBoxBase
: public wxControlWithItems
43 virtual ~wxListBoxBase();
45 void InsertItems(unsigned int nItems
, const wxString
*items
, unsigned int pos
)
46 { Insert(nItems
, items
, pos
); }
47 void InsertItems(const wxArrayString
& items
, unsigned int pos
)
48 { Insert(items
, pos
); }
50 // multiple selection logic
51 virtual bool IsSelected(int n
) const = 0;
52 virtual void SetSelection(int n
) { DoSetSelection(n
, true); }
53 void SetSelection(int n
, bool select
) { DoSetSelection(n
, select
); }
54 void Deselect(int n
) { DoSetSelection(n
, false); }
55 void DeselectAll(int itemToLeaveSelected
= -1);
57 virtual bool SetStringSelection(const wxString
& s
, bool select
);
58 virtual bool SetStringSelection(const wxString
& s
)
60 return SetStringSelection(s
, true);
63 // works for single as well as multiple selection listboxes (unlike
64 // GetSelection which only works for listboxes with single selection)
65 virtual int GetSelections(wxArrayInt
& aSelections
) const = 0;
67 // set the specified item at the first visible item or scroll to max
69 void SetFirstItem(int n
) { DoSetFirstItem(n
); }
70 void SetFirstItem(const wxString
& s
);
72 // ensures that the given item is visible scrolling the listbox if
74 virtual void EnsureVisible(int n
);
76 // a combination of Append() and EnsureVisible(): appends the item to the
77 // listbox and ensures that it is visible i.e. not scrolled out of view
78 void AppendAndEnsureVisible(const wxString
& s
);
80 // return true if the listbox allows multiple selection
81 bool HasMultipleSelection() const
83 return (m_windowStyle
& wxLB_MULTIPLE
) ||
84 (m_windowStyle
& wxLB_EXTENDED
);
87 // override wxItemContainer::IsSorted
88 virtual bool IsSorted() const { return HasFlag( wxLB_SORT
); }
90 // emulate selecting or deselecting the item event.GetInt() (depending on
91 // event.GetExtraLong())
92 void Command(wxCommandEvent
& event
);
94 // returns the item number at a point or wxNOT_FOUND
95 int HitTest(const wxPoint
& point
) const { return DoListHitTest(point
); }
97 #if WXWIN_COMPATIBILITY_2_6
98 // compatibility - these functions are deprecated, use the new ones
100 wxDEPRECATED( bool Selected(int n
) const );
101 #endif // WXWIN_COMPATIBILITY_2_6
104 virtual void DoSetFirstItem(int n
) = 0;
106 virtual void DoSetSelection(int n
, bool select
) = 0;
108 // there is already wxWindow::DoHitTest() so call this one differently
109 virtual int DoListHitTest(const wxPoint
& WXUNUSED(point
)) const
110 { return wxNOT_FOUND
; }
113 DECLARE_NO_COPY_CLASS(wxListBoxBase
)
116 #if WXWIN_COMPATIBILITY_2_6
117 inline bool wxListBoxBase::Selected(int n
) const { return IsSelected(n
); }
118 #endif // WXWIN_COMPATIBILITY_2_6
120 // ----------------------------------------------------------------------------
121 // include the platform-specific class declaration
122 // ----------------------------------------------------------------------------
124 #if defined(__WXUNIVERSAL__)
125 #include "wx/univ/listbox.h"
126 #elif defined(__WXMSW__)
127 #include "wx/msw/listbox.h"
128 #elif defined(__WXMOTIF__)
129 #include "wx/motif/listbox.h"
130 #elif defined(__WXGTK20__)
131 #include "wx/gtk/listbox.h"
132 #elif defined(__WXGTK__)
133 #include "wx/gtk1/listbox.h"
134 #elif defined(__WXMAC__)
135 #include "wx/mac/listbox.h"
136 #elif defined(__WXPM__)
137 #include "wx/os2/listbox.h"
138 #elif defined(__WXCOCOA__)
139 #include "wx/cocoa/listbox.h"
142 #endif // wxUSE_LISTBOX
145 // _WX_LISTBOX_H_BASE_