]>
Commit | Line | Data |
---|---|---|
2ee3ee1b VZ |
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$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
2ee3ee1b VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_LISTBOX_H_BASE_ |
13 | #define _WX_LISTBOX_H_BASE_ | |
c801d85f | 14 | |
2ee3ee1b VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
2ee3ee1b VZ |
19 | #include "wx/defs.h" |
20 | ||
21 | #if wxUSE_LISTBOX | |
22 | ||
6c8a980f | 23 | #include "wx/ctrlsub.h" // base class |
2ee3ee1b VZ |
24 | |
25 | // forward declarations are enough here | |
b5dbe15d VS |
26 | class WXDLLIMPEXP_FWD_BASE wxArrayInt; |
27 | class WXDLLIMPEXP_FWD_BASE wxArrayString; | |
2ee3ee1b VZ |
28 | |
29 | // ---------------------------------------------------------------------------- | |
30 | // global data | |
31 | // ---------------------------------------------------------------------------- | |
32 | ||
53a2db12 | 33 | extern WXDLLIMPEXP_DATA_CORE(const char) wxListBoxNameStr[]; |
2ee3ee1b VZ |
34 | |
35 | // ---------------------------------------------------------------------------- | |
36 | // wxListBox interface is defined by the class wxListBoxBase | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
53a2db12 | 39 | class WXDLLIMPEXP_CORE wxListBoxBase : public wxControlWithItems |
2ee3ee1b VZ |
40 | { |
41 | public: | |
6463b9f5 | 42 | wxListBoxBase() { } |
799ea011 | 43 | virtual ~wxListBoxBase(); |
2ee3ee1b | 44 | |
a236aa20 VZ |
45 | void InsertItems(unsigned int nItems, const wxString *items, unsigned int pos) |
46 | { Insert(nItems, items, pos); } | |
aa61d352 | 47 | void InsertItems(const wxArrayString& items, unsigned int pos) |
a236aa20 | 48 | { Insert(items, pos); } |
2ee3ee1b | 49 | |
6c8a980f | 50 | // multiple selection logic |
2ee3ee1b | 51 | virtual bool IsSelected(int n) const = 0; |
c6179a84 VZ |
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); } | |
1e6feb95 | 55 | void DeselectAll(int itemToLeaveSelected = -1); |
2ee3ee1b | 56 | |
c6179a84 VZ |
57 | virtual bool SetStringSelection(const wxString& s, bool select); |
58 | virtual bool SetStringSelection(const wxString& s) | |
59 | { | |
60 | return SetStringSelection(s, true); | |
61 | } | |
2ee3ee1b | 62 | |
6c8a980f VZ |
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; | |
2ee3ee1b | 66 | |
1e6feb95 | 67 | // set the specified item at the first visible item or scroll to max |
2ee3ee1b VZ |
68 | // range. |
69 | void SetFirstItem(int n) { DoSetFirstItem(n); } | |
70 | void SetFirstItem(const wxString& s); | |
71 | ||
1e6feb95 VZ |
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 | ||
f644b28c | 80 | // return true if the listbox allows multiple selection |
1e6feb95 VZ |
81 | bool HasMultipleSelection() const |
82 | { | |
83 | return (m_windowStyle & wxLB_MULTIPLE) || | |
84 | (m_windowStyle & wxLB_EXTENDED); | |
85 | } | |
86 | ||
a236aa20 VZ |
87 | // override wxItemContainer::IsSorted |
88 | virtual bool IsSorted() const { return HasFlag( wxLB_SORT ); } | |
1e6feb95 | 89 | |
6c8a980f VZ |
90 | // emulate selecting or deselecting the item event.GetInt() (depending on |
91 | // event.GetExtraLong()) | |
92 | void Command(wxCommandEvent& event); | |
2ee3ee1b | 93 | |
0a03dc7a | 94 | // return the index of the item at this position or wxNOT_FOUND |
8243a339 | 95 | int HitTest(const wxPoint& point) const { return DoListHitTest(point); } |
0a03dc7a VZ |
96 | int HitTest(int x, int y) const { return DoListHitTest(wxPoint(x, y)); } |
97 | ||
8243a339 | 98 | |
53f60d4a VZ |
99 | // For generating events in multiple and extended mode: compare the current |
100 | // selections with the previously recorded ones (in m_oldSelections) and | |
101 | // send the appropriate event if they differ, otherwise just return false. | |
102 | bool CalcAndSendEvent(); | |
103 | ||
2ee3ee1b | 104 | protected: |
2ee3ee1b | 105 | virtual void DoSetFirstItem(int n) = 0; |
fc7a2a60 | 106 | |
c6179a84 VZ |
107 | virtual void DoSetSelection(int n, bool select) = 0; |
108 | ||
c00fed0e VZ |
109 | // there is already wxWindow::DoHitTest() so call this one differently |
110 | virtual int DoListHitTest(const wxPoint& WXUNUSED(point)) const | |
111 | { return wxNOT_FOUND; } | |
112 | ||
53f60d4a VZ |
113 | // Send a listbox (de)selection or double click event. |
114 | // | |
115 | // Returns true if the event was processed. | |
116 | bool SendEvent(wxEventType evtType, int item, bool selected); | |
117 | ||
c07b0669 VZ |
118 | // Array storing the indices of all selected items that we already notified |
119 | // the user code about for multi selection list boxes. | |
120 | // | |
121 | // TODO-OPT: wxSelectionStore would be more efficient for big list boxes. | |
122 | wxArrayInt m_oldSelections; | |
123 | ||
124 | // Update m_oldSelections with currently selected items (does nothing in | |
a614ffae | 125 | // single selection mode on platforms other than MSW). |
c07b0669 VZ |
126 | void UpdateOldSelections(); |
127 | ||
a236aa20 | 128 | private: |
c0c133e1 | 129 | wxDECLARE_NO_COPY_CLASS(wxListBoxBase); |
2ee3ee1b VZ |
130 | }; |
131 | ||
132 | // ---------------------------------------------------------------------------- | |
133 | // include the platform-specific class declaration | |
134 | // ---------------------------------------------------------------------------- | |
135 | ||
1e6feb95 VZ |
136 | #if defined(__WXUNIVERSAL__) |
137 | #include "wx/univ/listbox.h" | |
138 | #elif defined(__WXMSW__) | |
2ee3ee1b | 139 | #include "wx/msw/listbox.h" |
2049ba38 | 140 | #elif defined(__WXMOTIF__) |
2ee3ee1b | 141 | #include "wx/motif/listbox.h" |
1be7a35c | 142 | #elif defined(__WXGTK20__) |
2ee3ee1b | 143 | #include "wx/gtk/listbox.h" |
1be7a35c MR |
144 | #elif defined(__WXGTK__) |
145 | #include "wx/gtk1/listbox.h" | |
34138703 | 146 | #elif defined(__WXMAC__) |
ef0e9220 | 147 | #include "wx/osx/listbox.h" |
1777b9bb | 148 | #elif defined(__WXPM__) |
2ee3ee1b | 149 | #include "wx/os2/listbox.h" |
e64df9bc DE |
150 | #elif defined(__WXCOCOA__) |
151 | #include "wx/cocoa/listbox.h" | |
c801d85f KB |
152 | #endif |
153 | ||
2ee3ee1b VZ |
154 | #endif // wxUSE_LISTBOX |
155 | ||
c801d85f | 156 | #endif |
34138703 | 157 | // _WX_LISTBOX_H_BASE_ |