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_BASE wxArrayInt
;
27 class WXDLLIMPEXP_BASE wxArrayString
;
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 extern WXDLLEXPORT_DATA(const wxChar
) wxListBoxNameStr
[];
35 // ----------------------------------------------------------------------------
36 // wxListBox interface is defined by the class wxListBoxBase
37 // ----------------------------------------------------------------------------
39 class WXDLLEXPORT wxListBoxBase
: public wxControlWithItems
43 virtual ~wxListBoxBase();
45 // all generic methods are in wxControlWithItems, except for the following
46 // ones which are not yet implemented by wxChoice/wxComboBox
47 void Insert(const wxString
& item
, unsigned int pos
)
48 { DoInsert(item
, pos
); }
49 void Insert(const wxString
& item
, unsigned int pos
, void *clientData
)
50 { DoInsert(item
, pos
); SetClientData(pos
, clientData
); }
51 void Insert(const wxString
& item
, unsigned int pos
, wxClientData
*clientData
)
52 { DoInsert(item
, pos
); SetClientObject(pos
, clientData
); }
54 void InsertItems(unsigned int nItems
, const wxString
*items
, unsigned int pos
);
55 void InsertItems(const wxArrayString
& items
, unsigned int pos
)
56 { DoInsertItems(items
, pos
); }
58 void Set(int n
, const wxString
* items
, void **clientData
= NULL
);
59 void Set(const wxArrayString
& items
, void **clientData
= NULL
)
60 { DoSetItems(items
, clientData
); }
62 // multiple selection logic
63 virtual bool IsSelected(int n
) const = 0;
64 virtual void SetSelection(int n
) { DoSetSelection(n
, true); }
65 void SetSelection(int n
, bool select
) { DoSetSelection(n
, select
); }
66 void Deselect(int n
) { DoSetSelection(n
, false); }
67 void DeselectAll(int itemToLeaveSelected
= -1);
69 virtual bool SetStringSelection(const wxString
& s
, bool select
);
70 virtual bool SetStringSelection(const wxString
& s
)
72 return SetStringSelection(s
, true);
75 // works for single as well as multiple selection listboxes (unlike
76 // GetSelection which only works for listboxes with single selection)
77 virtual int GetSelections(wxArrayInt
& aSelections
) const = 0;
79 // set the specified item at the first visible item or scroll to max
81 void SetFirstItem(int n
) { DoSetFirstItem(n
); }
82 void SetFirstItem(const wxString
& s
);
84 // ensures that the given item is visible scrolling the listbox if
86 virtual void EnsureVisible(int n
);
88 // a combination of Append() and EnsureVisible(): appends the item to the
89 // listbox and ensures that it is visible i.e. not scrolled out of view
90 void AppendAndEnsureVisible(const wxString
& s
);
92 // return true if the listbox allows multiple selection
93 bool HasMultipleSelection() const
95 return (m_windowStyle
& wxLB_MULTIPLE
) ||
96 (m_windowStyle
& wxLB_EXTENDED
);
99 // return true if this listbox is sorted
100 bool IsSorted() const { return (m_windowStyle
& wxLB_SORT
) != 0; }
102 // emulate selecting or deselecting the item event.GetInt() (depending on
103 // event.GetExtraLong())
104 void Command(wxCommandEvent
& event
);
106 // returns the item number at a point or wxNOT_FOUND
107 int HitTest(const wxPoint
& point
) const { return DoListHitTest(point
); }
109 #if WXWIN_COMPATIBILITY_2_6
110 // compatibility - these functions are deprecated, use the new ones
112 wxDEPRECATED( bool Selected(int n
) const );
113 #endif // WXWIN_COMPATIBILITY_2_6
116 // NB: due to wxGTK implementation details, DoInsert() is implemented
117 // using DoInsertItems() and not the other way round
118 virtual int DoInsert(const wxString
& item
, unsigned int pos
)
119 { InsertItems(1, &item
, pos
); return pos
; }
121 // to be implemented in derived classes
122 virtual void DoInsertItems(const wxArrayString
& items
, unsigned int pos
) = 0;
123 virtual void DoSetItems(const wxArrayString
& items
, void **clientData
) = 0;
125 virtual void DoSetFirstItem(int n
) = 0;
127 virtual void DoSetSelection(int n
, bool select
) = 0;
129 // there is already wxWindow::DoHitTest() so call this one differently
130 virtual int DoListHitTest(const wxPoint
& WXUNUSED(point
)) const
131 { return wxNOT_FOUND
; }
134 DECLARE_NO_COPY_CLASS(wxListBoxBase
)
137 #if WXWIN_COMPATIBILITY_2_6
138 inline bool wxListBoxBase::Selected(int n
) const { return IsSelected(n
); }
139 #endif // WXWIN_COMPATIBILITY_2_6
141 // ----------------------------------------------------------------------------
142 // include the platform-specific class declaration
143 // ----------------------------------------------------------------------------
145 #if defined(__WXUNIVERSAL__)
146 #include "wx/univ/listbox.h"
147 #elif defined(__WXMSW__)
148 #include "wx/msw/listbox.h"
149 #elif defined(__WXMOTIF__)
150 #include "wx/motif/listbox.h"
151 #elif defined(__WXGTK20__)
152 #include "wx/gtk/listbox.h"
153 #elif defined(__WXGTK__)
154 #include "wx/gtk1/listbox.h"
155 #elif defined(__WXMAC__)
156 #include "wx/mac/listbox.h"
157 #elif defined(__WXPM__)
158 #include "wx/os2/listbox.h"
159 #elif defined(__WXCOCOA__)
160 #include "wx/cocoa/listbox.h"
163 #endif // wxUSE_LISTBOX
166 // _WX_LISTBOX_H_BASE_