]>
Commit | Line | Data |
---|---|---|
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 | |
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 | #ifdef __GNUG__ | |
20 | #pragma interface "listboxbase.h" | |
21 | #endif | |
22 | ||
23 | #include "wx/defs.h" | |
24 | ||
25 | #if wxUSE_LISTBOX | |
26 | ||
27 | #include "wx/ctrlsub.h" // base class | |
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 | ||
43 | class WXDLLEXPORT wxListBoxBase : public wxControlWithItems | |
44 | { | |
45 | public: | |
46 | // all generic methods are in wxControlWithItems, except for the following | |
47 | // ones which are not yet implemented by wxChoice/wxCombobox | |
48 | #ifdef __WXMAC_X__ | |
49 | virtual ~wxListBoxBase() {} // Added min for Mac X | |
50 | #endif | |
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 | ||
67 | // multiple selection logic | |
68 | virtual bool IsSelected(int n) const = 0; | |
69 | virtual void SetSelection(int n, bool select = TRUE) = 0; | |
70 | virtual void Select(int n) { SetSelection(n, TRUE); } | |
71 | void Deselect(int n) { SetSelection(n, FALSE); } | |
72 | ||
73 | virtual bool SetStringSelection(const wxString& s, bool select = TRUE); | |
74 | ||
75 | // works for single as well as multiple selection listboxes (unlike | |
76 | // GetSelection which only works for listboxes with single selection) | |
77 | virtual int GetSelections(wxArrayInt& aSelections) const = 0; | |
78 | ||
79 | // Set the specified item at the first visible item or scroll to max | |
80 | // range. | |
81 | void SetFirstItem(int n) { DoSetFirstItem(n); } | |
82 | void SetFirstItem(const wxString& s); | |
83 | ||
84 | // emulate selecting or deselecting the item event.GetInt() (depending on | |
85 | // event.GetExtraLong()) | |
86 | void Command(wxCommandEvent& event); | |
87 | ||
88 | // compatibility - these functions are deprecated, use the new ones | |
89 | // instead | |
90 | bool Selected(int n) const { return IsSelected(n); } | |
91 | ||
92 | protected: | |
93 | // NB: due to wxGTK implementation details, DoInsert() is implemented | |
94 | // using DoInsertItems() and not the other way round | |
95 | void DoInsert(const wxString& item, int pos) | |
96 | { InsertItems(1, &item, pos); } | |
97 | ||
98 | // to be implemented in derived classes | |
99 | virtual void DoInsertItems(const wxArrayString& items, int pos) = 0; | |
100 | virtual void DoSetItems(const wxArrayString& items, void **clientData) = 0; | |
101 | ||
102 | virtual void DoSetFirstItem(int n) = 0; | |
103 | }; | |
104 | ||
105 | // ---------------------------------------------------------------------------- | |
106 | // include the platform-specific class declaration | |
107 | // ---------------------------------------------------------------------------- | |
108 | ||
109 | #if defined(__WXMSW__) | |
110 | #include "wx/msw/listbox.h" | |
111 | #elif defined(__WXMOTIF__) | |
112 | #include "wx/motif/listbox.h" | |
113 | #elif defined(__WXGTK__) | |
114 | #include "wx/gtk/listbox.h" | |
115 | #elif defined(__WXQT__) | |
116 | #include "wx/qt/listbox.h" | |
117 | #elif defined(__WXMAC__) | |
118 | #include "wx/mac/listbox.h" | |
119 | #elif defined(__WXPM__) | |
120 | #include "wx/os2/listbox.h" | |
121 | #elif defined(__WXSTUBS__) | |
122 | #include "wx/stubs/listbox.h" | |
123 | #endif | |
124 | ||
125 | #endif // wxUSE_LISTBOX | |
126 | ||
127 | #endif | |
128 | // _WX_LISTBOX_H_BASE_ |