]> git.saurik.com Git - wxWidgets.git/blob - include/wx/listbox.h
Comment-only update
[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 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_LISTBOX_H_BASE_
12 #define _WX_LISTBOX_H_BASE_
13
14 // ----------------------------------------------------------------------------
15 // headers
16 // ----------------------------------------------------------------------------
17
18 #include "wx/defs.h"
19
20 #if wxUSE_LISTBOX
21
22 #include "wx/ctrlsub.h" // base class
23
24 // forward declarations are enough here
25 class WXDLLIMPEXP_FWD_BASE wxArrayInt;
26 class WXDLLIMPEXP_FWD_BASE wxArrayString;
27
28 // ----------------------------------------------------------------------------
29 // global data
30 // ----------------------------------------------------------------------------
31
32 extern WXDLLIMPEXP_DATA_CORE(const char) wxListBoxNameStr[];
33
34 // ----------------------------------------------------------------------------
35 // wxListBox interface is defined by the class wxListBoxBase
36 // ----------------------------------------------------------------------------
37
38 class WXDLLIMPEXP_CORE wxListBoxBase : public wxControlWithItems
39 {
40 public:
41 wxListBoxBase() { }
42 virtual ~wxListBoxBase();
43
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); }
48
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);
55
56 virtual bool SetStringSelection(const wxString& s, bool select);
57 virtual bool SetStringSelection(const wxString& s)
58 {
59 return SetStringSelection(s, true);
60 }
61
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;
65
66 // set the specified item at the first visible item or scroll to max
67 // range.
68 void SetFirstItem(int n) { DoSetFirstItem(n); }
69 void SetFirstItem(const wxString& s);
70
71 // ensures that the given item is visible scrolling the listbox if
72 // necessary
73 virtual void EnsureVisible(int n);
74
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);
78
79 // return true if the listbox allows multiple selection
80 bool HasMultipleSelection() const
81 {
82 return (m_windowStyle & wxLB_MULTIPLE) ||
83 (m_windowStyle & wxLB_EXTENDED);
84 }
85
86 // override wxItemContainer::IsSorted
87 virtual bool IsSorted() const { return HasFlag( wxLB_SORT ); }
88
89 // emulate selecting or deselecting the item event.GetInt() (depending on
90 // event.GetExtraLong())
91 void Command(wxCommandEvent& event);
92
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)); }
96
97
98 protected:
99 virtual void DoSetFirstItem(int n) = 0;
100
101 virtual void DoSetSelection(int n, bool select) = 0;
102
103 // there is already wxWindow::DoHitTest() so call this one differently
104 virtual int DoListHitTest(const wxPoint& WXUNUSED(point)) const
105 { return wxNOT_FOUND; }
106
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);
111
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();
117
118 // Send a listbox (de)selection or double click event.
119 //
120 // Returns true if the event was processed.
121 bool SendEvent(wxEventType evtType, int item, bool selected);
122
123 // Array storing the indices of all selected items that we already notified
124 // the user code about for multi selection list boxes.
125 //
126 // For single selection list boxes, we reuse this array to store the single
127 // currently selected item, this is used by DoChangeSingleSelection().
128 //
129 // TODO-OPT: wxSelectionStore would be more efficient for big list boxes.
130 wxArrayInt m_oldSelections;
131
132 // Update m_oldSelections with currently selected items (does nothing in
133 // single selection mode on platforms other than MSW).
134 void UpdateOldSelections();
135
136 private:
137 wxDECLARE_NO_COPY_CLASS(wxListBoxBase);
138 };
139
140 // ----------------------------------------------------------------------------
141 // include the platform-specific class declaration
142 // ----------------------------------------------------------------------------
143
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"
160 #endif
161
162 #endif // wxUSE_LISTBOX
163
164 #endif
165 // _WX_LISTBOX_H_BASE_