]>
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$ | |
8 | // Copyright: (c) wxWindows team | |
6c8a980f | 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 | ||
19 | #ifdef __GNUG__ | |
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 | |
30 | class WXDLLEXPORT wxArrayInt; | |
31 | class WXDLLEXPORT wxArrayString; | |
32 | ||
33 | // ---------------------------------------------------------------------------- | |
34 | // global data | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | WXDLLEXPORT_DATA(extern const wxChar*) wxListBoxNameStr; | |
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: | |
6c8a980f VZ |
46 | // all generic methods are in wxControlWithItems, except for the following |
47 | // ones which are not yet implemented by wxChoice/wxCombobox | |
03e11df5 GD |
48 | #ifdef __WXMAC_X__ |
49 | virtual ~wxListBoxBase() {} // Added min for Mac X | |
50 | #endif | |
2ee3ee1b VZ |
51 | |
52 | void Insert(const wxString& item, int pos) | |
53 | { DoInsert(item, pos); } | |
54 | void Insert(const wxString& item, int pos, void *clientData) | |
55 | { DoInsert(item, pos); SetClientData(pos, clientData); } | |
56 | void Insert(const wxString& item, int pos, wxClientData *clientData) | |
57 | { DoInsert(item, pos); SetClientObject(pos, clientData); } | |
58 | ||
59 | void InsertItems(int nItems, const wxString *items, int pos); | |
60 | void InsertItems(const wxArrayString& items, int pos) | |
61 | { DoInsertItems(items, pos); } | |
62 | ||
63 | void Set(int n, const wxString* items, void **clientData = NULL); | |
64 | void Set(const wxArrayString& items, void **clientData = NULL) | |
65 | { DoSetItems(items, clientData); } | |
66 | ||
6c8a980f | 67 | // multiple selection logic |
2ee3ee1b VZ |
68 | virtual bool IsSelected(int n) const = 0; |
69 | virtual void SetSelection(int n, bool select = TRUE) = 0; | |
6c8a980f | 70 | virtual void Select(int n) { SetSelection(n, TRUE); } |
2ee3ee1b | 71 | void Deselect(int n) { SetSelection(n, FALSE); } |
1e6feb95 | 72 | void DeselectAll(int itemToLeaveSelected = -1); |
2ee3ee1b | 73 | |
6c8a980f | 74 | virtual bool SetStringSelection(const wxString& s, bool select = TRUE); |
2ee3ee1b | 75 | |
6c8a980f VZ |
76 | // works for single as well as multiple selection listboxes (unlike |
77 | // GetSelection which only works for listboxes with single selection) | |
78 | virtual int GetSelections(wxArrayInt& aSelections) const = 0; | |
2ee3ee1b | 79 | |
1e6feb95 | 80 | // set the specified item at the first visible item or scroll to max |
2ee3ee1b VZ |
81 | // range. |
82 | void SetFirstItem(int n) { DoSetFirstItem(n); } | |
83 | void SetFirstItem(const wxString& s); | |
84 | ||
1e6feb95 VZ |
85 | // ensures that the given item is visible scrolling the listbox if |
86 | // necessary | |
87 | virtual void EnsureVisible(int n); | |
88 | ||
89 | // a combination of Append() and EnsureVisible(): appends the item to the | |
90 | // listbox and ensures that it is visible i.e. not scrolled out of view | |
91 | void AppendAndEnsureVisible(const wxString& s); | |
92 | ||
93 | // return TRUE if the listbox allows multiple selection | |
94 | bool HasMultipleSelection() const | |
95 | { | |
96 | return (m_windowStyle & wxLB_MULTIPLE) || | |
97 | (m_windowStyle & wxLB_EXTENDED); | |
98 | } | |
99 | ||
100 | // return TRUE if this listbox is sorted | |
101 | bool IsSorted() const { return (m_windowStyle & wxLB_SORT) != 0; } | |
102 | ||
6c8a980f VZ |
103 | // emulate selecting or deselecting the item event.GetInt() (depending on |
104 | // event.GetExtraLong()) | |
105 | void Command(wxCommandEvent& event); | |
2ee3ee1b VZ |
106 | |
107 | // compatibility - these functions are deprecated, use the new ones | |
108 | // instead | |
109 | bool Selected(int n) const { return IsSelected(n); } | |
2ee3ee1b VZ |
110 | |
111 | protected: | |
112 | // NB: due to wxGTK implementation details, DoInsert() is implemented | |
113 | // using DoInsertItems() and not the other way round | |
114 | void DoInsert(const wxString& item, int pos) | |
115 | { InsertItems(1, &item, pos); } | |
116 | ||
117 | // to be implemented in derived classes | |
2ee3ee1b VZ |
118 | virtual void DoInsertItems(const wxArrayString& items, int pos) = 0; |
119 | virtual void DoSetItems(const wxArrayString& items, void **clientData) = 0; | |
120 | ||
121 | virtual void DoSetFirstItem(int n) = 0; | |
2ee3ee1b VZ |
122 | }; |
123 | ||
124 | // ---------------------------------------------------------------------------- | |
125 | // include the platform-specific class declaration | |
126 | // ---------------------------------------------------------------------------- | |
127 | ||
1e6feb95 VZ |
128 | #if defined(__WXUNIVERSAL__) |
129 | #include "wx/univ/listbox.h" | |
130 | #elif defined(__WXMSW__) | |
2ee3ee1b | 131 | #include "wx/msw/listbox.h" |
2049ba38 | 132 | #elif defined(__WXMOTIF__) |
2ee3ee1b | 133 | #include "wx/motif/listbox.h" |
2049ba38 | 134 | #elif defined(__WXGTK__) |
2ee3ee1b | 135 | #include "wx/gtk/listbox.h" |
b4e76e0d | 136 | #elif defined(__WXQT__) |
2ee3ee1b | 137 | #include "wx/qt/listbox.h" |
34138703 | 138 | #elif defined(__WXMAC__) |
2ee3ee1b | 139 | #include "wx/mac/listbox.h" |
1777b9bb | 140 | #elif defined(__WXPM__) |
2ee3ee1b | 141 | #include "wx/os2/listbox.h" |
34138703 | 142 | #elif defined(__WXSTUBS__) |
2ee3ee1b | 143 | #include "wx/stubs/listbox.h" |
c801d85f KB |
144 | #endif |
145 | ||
2ee3ee1b VZ |
146 | #endif // wxUSE_LISTBOX |
147 | ||
c801d85f | 148 | #endif |
34138703 | 149 | // _WX_LISTBOX_H_BASE_ |