]> git.saurik.com Git - wxWidgets.git/blob - include/wx/listbox.h
Bring osx class naming into line with the other ports.
[wxWidgets.git] / include / wx / listbox.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/listbox.h
3 // Purpose: wxListBox class interface
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 22.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_LISTBOX_H_BASE_
13 #define _WX_LISTBOX_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/defs.h"
20
21 #if wxUSE_LISTBOX
22
23 #include "wx/ctrlsub.h" // base class
24
25 // forward declarations are enough here
26 class WXDLLIMPEXP_FWD_BASE wxArrayInt;
27 class WXDLLIMPEXP_FWD_BASE wxArrayString;
28
29 // ----------------------------------------------------------------------------
30 // global data
31 // ----------------------------------------------------------------------------
32
33 extern WXDLLIMPEXP_DATA_CORE(const char) wxListBoxNameStr[];
34
35 // ----------------------------------------------------------------------------
36 // wxListBox interface is defined by the class wxListBoxBase
37 // ----------------------------------------------------------------------------
38
39 class WXDLLIMPEXP_CORE wxListBoxBase : public wxControlWithItems
40 {
41 public:
42 wxListBoxBase() { }
43 virtual ~wxListBoxBase();
44
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); }
49
50 // multiple selection logic
51 virtual bool IsSelected(int n) const = 0;
52 virtual void SetSelection(int n);
53 void SetSelection(int n, bool select) { DoSetSelection(n, select); }
54 void Deselect(int n) { DoSetSelection(n, false); }
55 void DeselectAll(int itemToLeaveSelected = -1);
56
57 virtual bool SetStringSelection(const wxString& s, bool select);
58 virtual bool SetStringSelection(const wxString& s)
59 {
60 return SetStringSelection(s, true);
61 }
62
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;
66
67 // set the specified item at the first visible item or scroll to max
68 // range.
69 void SetFirstItem(int n) { DoSetFirstItem(n); }
70 void SetFirstItem(const wxString& s);
71
72 // ensures that the given item is visible scrolling the listbox if
73 // necessary
74 virtual void EnsureVisible(int n);
75
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);
79
80 // return true if the listbox allows multiple selection
81 bool HasMultipleSelection() const
82 {
83 return (m_windowStyle & wxLB_MULTIPLE) ||
84 (m_windowStyle & wxLB_EXTENDED);
85 }
86
87 // override wxItemContainer::IsSorted
88 virtual bool IsSorted() const { return HasFlag( wxLB_SORT ); }
89
90 // emulate selecting or deselecting the item event.GetInt() (depending on
91 // event.GetExtraLong())
92 void Command(wxCommandEvent& event);
93
94 // return the index of the item at this position or wxNOT_FOUND
95 int HitTest(const wxPoint& point) const { return DoListHitTest(point); }
96 int HitTest(int x, int y) const { return DoListHitTest(wxPoint(x, y)); }
97
98
99 protected:
100 virtual void DoSetFirstItem(int n) = 0;
101
102 virtual void DoSetSelection(int n, bool select) = 0;
103
104 // there is already wxWindow::DoHitTest() so call this one differently
105 virtual int DoListHitTest(const wxPoint& WXUNUSED(point)) const
106 { return wxNOT_FOUND; }
107
108 // Helper for the code generating events in single selection mode: updates
109 // m_oldSelections and return true if the selection really changed.
110 // Otherwise just returns false.
111 bool DoChangeSingleSelection(int item);
112
113 // Helper for generating events in multiple and extended mode: compare the
114 // current selections with the previously recorded ones (in
115 // m_oldSelections) and send the appropriate event if they differ,
116 // otherwise just return false.
117 bool CalcAndSendEvent();
118
119 // Send a listbox (de)selection or double click event.
120 //
121 // Returns true if the event was processed.
122 bool SendEvent(wxEventType evtType, int item, bool selected);
123
124 // Array storing the indices of all selected items that we already notified
125 // the user code about for multi selection list boxes.
126 //
127 // For single selection list boxes, we reuse this array to store the single
128 // currently selected item, this is used by DoChangeSingleSelection().
129 //
130 // TODO-OPT: wxSelectionStore would be more efficient for big list boxes.
131 wxArrayInt m_oldSelections;
132
133 // Update m_oldSelections with currently selected items (does nothing in
134 // single selection mode on platforms other than MSW).
135 void UpdateOldSelections();
136
137 private:
138 wxDECLARE_NO_COPY_CLASS(wxListBoxBase);
139 };
140
141 // ----------------------------------------------------------------------------
142 // include the platform-specific class declaration
143 // ----------------------------------------------------------------------------
144
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/osx/listbox.h"
157 #elif defined(__WXPM__)
158 #include "wx/os2/listbox.h"
159 #elif defined(__WXCOCOA__)
160 #include "wx/cocoa/listbox.h"
161 #endif
162
163 #endif // wxUSE_LISTBOX
164
165 #endif
166 // _WX_LISTBOX_H_BASE_