]>
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 | ||
12028905 | 19 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
2ee3ee1b VZ |
20 | #pragma interface "listboxbase.h" |
21 | #endif | |
22 | ||
23 | #include "wx/defs.h" | |
24 | ||
25 | #if wxUSE_LISTBOX | |
26 | ||
6c8a980f | 27 | #include "wx/ctrlsub.h" // base class |
2ee3ee1b VZ |
28 | |
29 | // forward declarations are enough here | |
62a9d04c VS |
30 | class WXDLLIMPEXP_BASE wxArrayInt; |
31 | class WXDLLIMPEXP_BASE wxArrayString; | |
2ee3ee1b VZ |
32 | |
33 | // ---------------------------------------------------------------------------- | |
34 | // global data | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
16cba29d | 37 | extern WXDLLEXPORT_DATA(const wxChar*) wxListBoxNameStr; |
2ee3ee1b VZ |
38 | |
39 | // ---------------------------------------------------------------------------- | |
40 | // wxListBox interface is defined by the class wxListBoxBase | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
6c8a980f | 43 | class WXDLLEXPORT wxListBoxBase : public wxControlWithItems |
2ee3ee1b VZ |
44 | { |
45 | public: | |
6463b9f5 | 46 | wxListBoxBase() { } |
799ea011 | 47 | virtual ~wxListBoxBase(); |
2ee3ee1b | 48 | |
fc7a2a60 | 49 | // all generic methods are in wxControlWithItems, except for the following |
43e8916f | 50 | // ones which are not yet implemented by wxChoice/wxComboBox |
2ee3ee1b VZ |
51 | void Insert(const wxString& item, int pos) |
52 | { DoInsert(item, pos); } | |
53 | void Insert(const wxString& item, int pos, void *clientData) | |
54 | { DoInsert(item, pos); SetClientData(pos, clientData); } | |
55 | void Insert(const wxString& item, int pos, wxClientData *clientData) | |
56 | { DoInsert(item, pos); SetClientObject(pos, clientData); } | |
57 | ||
58 | void InsertItems(int nItems, const wxString *items, int pos); | |
59 | void InsertItems(const wxArrayString& items, int pos) | |
60 | { DoInsertItems(items, pos); } | |
61 | ||
62 | void Set(int n, const wxString* items, void **clientData = NULL); | |
63 | void Set(const wxArrayString& items, void **clientData = NULL) | |
64 | { DoSetItems(items, clientData); } | |
65 | ||
6c8a980f | 66 | // multiple selection logic |
2ee3ee1b | 67 | virtual bool IsSelected(int n) const = 0; |
c6179a84 VZ |
68 | virtual void SetSelection(int n) { DoSetSelection(n, true); } |
69 | void SetSelection(int n, bool select) { DoSetSelection(n, select); } | |
70 | void Deselect(int n) { DoSetSelection(n, false); } | |
1e6feb95 | 71 | void DeselectAll(int itemToLeaveSelected = -1); |
2ee3ee1b | 72 | |
c6179a84 VZ |
73 | virtual bool SetStringSelection(const wxString& s, bool select); |
74 | virtual bool SetStringSelection(const wxString& s) | |
75 | { | |
76 | return SetStringSelection(s, true); | |
77 | } | |
2ee3ee1b | 78 | |
6c8a980f VZ |
79 | // works for single as well as multiple selection listboxes (unlike |
80 | // GetSelection which only works for listboxes with single selection) | |
81 | virtual int GetSelections(wxArrayInt& aSelections) const = 0; | |
2ee3ee1b | 82 | |
1e6feb95 | 83 | // set the specified item at the first visible item or scroll to max |
2ee3ee1b VZ |
84 | // range. |
85 | void SetFirstItem(int n) { DoSetFirstItem(n); } | |
86 | void SetFirstItem(const wxString& s); | |
87 | ||
1e6feb95 VZ |
88 | // ensures that the given item is visible scrolling the listbox if |
89 | // necessary | |
90 | virtual void EnsureVisible(int n); | |
91 | ||
92 | // a combination of Append() and EnsureVisible(): appends the item to the | |
93 | // listbox and ensures that it is visible i.e. not scrolled out of view | |
94 | void AppendAndEnsureVisible(const wxString& s); | |
95 | ||
f644b28c | 96 | // return true if the listbox allows multiple selection |
1e6feb95 VZ |
97 | bool HasMultipleSelection() const |
98 | { | |
99 | return (m_windowStyle & wxLB_MULTIPLE) || | |
100 | (m_windowStyle & wxLB_EXTENDED); | |
101 | } | |
102 | ||
f644b28c | 103 | // return true if this listbox is sorted |
1e6feb95 VZ |
104 | bool IsSorted() const { return (m_windowStyle & wxLB_SORT) != 0; } |
105 | ||
6c8a980f VZ |
106 | // emulate selecting or deselecting the item event.GetInt() (depending on |
107 | // event.GetExtraLong()) | |
108 | void Command(wxCommandEvent& event); | |
2ee3ee1b VZ |
109 | |
110 | // compatibility - these functions are deprecated, use the new ones | |
111 | // instead | |
112 | bool Selected(int n) const { return IsSelected(n); } | |
2ee3ee1b VZ |
113 | |
114 | protected: | |
115 | // NB: due to wxGTK implementation details, DoInsert() is implemented | |
116 | // using DoInsertItems() and not the other way round | |
243dbf1a VZ |
117 | virtual int DoInsert(const wxString& item, int pos) |
118 | { InsertItems(1, &item, pos); return pos; } | |
2ee3ee1b VZ |
119 | |
120 | // to be implemented in derived classes | |
2ee3ee1b VZ |
121 | virtual void DoInsertItems(const wxArrayString& items, int pos) = 0; |
122 | virtual void DoSetItems(const wxArrayString& items, void **clientData) = 0; | |
123 | ||
124 | virtual void DoSetFirstItem(int n) = 0; | |
fc7a2a60 | 125 | |
c6179a84 VZ |
126 | virtual void DoSetSelection(int n, bool select) = 0; |
127 | ||
128 | ||
fc7a2a60 | 129 | DECLARE_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" |
2049ba38 | 142 | #elif defined(__WXGTK__) |
2ee3ee1b | 143 | #include "wx/gtk/listbox.h" |
34138703 | 144 | #elif defined(__WXMAC__) |
2ee3ee1b | 145 | #include "wx/mac/listbox.h" |
1777b9bb | 146 | #elif defined(__WXPM__) |
2ee3ee1b | 147 | #include "wx/os2/listbox.h" |
e64df9bc DE |
148 | #elif defined(__WXCOCOA__) |
149 | #include "wx/cocoa/listbox.h" | |
c801d85f KB |
150 | #endif |
151 | ||
2ee3ee1b VZ |
152 | #endif // wxUSE_LISTBOX |
153 | ||
c801d85f | 154 | #endif |
34138703 | 155 | // _WX_LISTBOX_H_BASE_ |