]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: list.h | |
3 | // Purpose: wxList, wxStringList classes | |
4 | // Author: Julian Smart | |
fd3f686c | 5 | // Modified by: VZ at 16/11/98: WX_DECLARE_LIST() and typesafe lists added |
c801d85f KB |
6 | // Created: 29/01/98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Julian Smart | |
371a5b4e | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
fd3f686c VZ |
12 | /* |
13 | All this is quite ugly but serves two purposes: | |
14 | 1. Be almost 100% compatible with old, untyped, wxList class | |
15 | 2. Ensure compile-time type checking for the linked lists | |
16 | ||
17 | The idea is to have one base class (wxListBase) working with "void *" data, | |
18 | but to hide these untyped functions - i.e. make them protected, so they | |
19 | can only be used from derived classes which have inline member functions | |
20 | working with right types. This achieves the 2nd goal. As for the first one, | |
21 | we provide a special derivation of wxListBase called wxList which looks just | |
22 | like the old class. | |
23 | */ | |
24 | ||
34138703 JS |
25 | #ifndef _WX_LISTH__ |
26 | #define _WX_LISTH__ | |
c801d85f | 27 | |
af49c4b8 | 28 | #if defined(__GNUG__) && !defined(__APPLE__) |
0d3820b3 | 29 | #pragma interface "list.h" |
c801d85f KB |
30 | #endif |
31 | ||
fd3f686c VZ |
32 | // ----------------------------------------------------------------------------- |
33 | // headers | |
34 | // ----------------------------------------------------------------------------- | |
35 | ||
c801d85f KB |
36 | #include "wx/defs.h" |
37 | #include "wx/object.h" | |
3bef6c4c | 38 | #include "wx/string.h" |
c801d85f | 39 | |
bddd7a8d | 40 | class WXDLLIMPEXP_BASE wxObjectListNode; |
fd3f686c VZ |
41 | typedef wxObjectListNode wxNode; |
42 | ||
43 | // undef it to get rid of old, deprecated functions | |
44 | #define wxLIST_COMPATIBILITY | |
c801d85f | 45 | |
fd3f686c VZ |
46 | // ----------------------------------------------------------------------------- |
47 | // constants | |
48 | // ----------------------------------------------------------------------------- | |
49 | enum wxKeyType | |
50 | { | |
51 | wxKEY_NONE, | |
52 | wxKEY_INTEGER, | |
53 | wxKEY_STRING | |
54 | }; | |
55 | ||
56 | // ----------------------------------------------------------------------------- | |
57 | // types | |
58 | // ----------------------------------------------------------------------------- | |
59 | ||
60 | // type of compare function for list sort operation (as in 'qsort'): it should | |
61 | // return a negative value, 0 or positive value if the first element is less | |
62 | // than, equal or greater than the second | |
90350682 VZ |
63 | extern "C" |
64 | { | |
54da4255 | 65 | typedef int (* LINKAGEMODE wxSortCompareFunction)(const void *elem1, const void *elem2); |
90350682 | 66 | } |
fd3f686c VZ |
67 | |
68 | // | |
54da4255 | 69 | typedef int (* LINKAGEMODE wxListIterateFunction)(void *current); |
fd3f686c VZ |
70 | |
71 | // ----------------------------------------------------------------------------- | |
72 | // key stuff: a list may be optionally keyed on integer or string key | |
73 | // ----------------------------------------------------------------------------- | |
74 | ||
75 | union wxListKeyValue | |
c801d85f | 76 | { |
c801d85f | 77 | long integer; |
9d2f3c71 | 78 | wxChar *string; |
c801d85f KB |
79 | }; |
80 | ||
fd3f686c VZ |
81 | // a struct which may contain both types of keys |
82 | // | |
83 | // implementation note: on one hand, this class allows to have only one function | |
84 | // for any keyed operation instead of 2 almost equivalent. OTOH, it's needed to | |
85 | // resolve ambiguity which we would otherwise have with wxStringList::Find() and | |
86 | // wxList::Find(const char *). | |
bddd7a8d | 87 | class WXDLLIMPEXP_BASE wxListKey |
fd3f686c VZ |
88 | { |
89 | public: | |
90 | // implicit ctors | |
f2af4afb GD |
91 | wxListKey() : m_keyType(wxKEY_NONE) |
92 | { } | |
93 | wxListKey(long i) : m_keyType(wxKEY_INTEGER) | |
94 | { m_key.integer = i; } | |
95 | wxListKey(const wxChar *s) : m_keyType(wxKEY_STRING) | |
96 | { m_key.string = wxStrdup(s); } | |
97 | wxListKey(const wxString& s) : m_keyType(wxKEY_STRING) | |
98 | { m_key.string = wxStrdup(s.c_str()); } | |
fd3f686c VZ |
99 | |
100 | // accessors | |
101 | wxKeyType GetKeyType() const { return m_keyType; } | |
9d2f3c71 | 102 | const wxChar *GetString() const |
fd3f686c VZ |
103 | { wxASSERT( m_keyType == wxKEY_STRING ); return m_key.string; } |
104 | long GetNumber() const | |
105 | { wxASSERT( m_keyType == wxKEY_INTEGER ); return m_key.integer; } | |
106 | ||
6164d85e JS |
107 | // comparison |
108 | // Note: implementation moved to list.cpp to prevent BC++ inline | |
109 | // expansion warning. | |
110 | bool operator==(wxListKeyValue value) const ; | |
fd3f686c VZ |
111 | |
112 | // dtor | |
113 | ~wxListKey() | |
114 | { | |
115 | if ( m_keyType == wxKEY_STRING ) | |
116 | free(m_key.string); | |
117 | } | |
118 | ||
119 | private: | |
120 | wxKeyType m_keyType; | |
121 | wxListKeyValue m_key; | |
122 | }; | |
123 | ||
124 | // ----------------------------------------------------------------------------- | |
125 | // wxNodeBase class is a (base for) node in a double linked list | |
126 | // ----------------------------------------------------------------------------- | |
127 | ||
bddd7a8d | 128 | WXDLLIMPEXP_DATA_BASE(extern wxListKey) wxDefaultListKey; |
2432b92d | 129 | |
bddd7a8d | 130 | class WXDLLIMPEXP_BASE wxListBase; |
fbfb3fb3 | 131 | |
bddd7a8d | 132 | class WXDLLIMPEXP_BASE wxNodeBase |
fd3f686c VZ |
133 | { |
134 | friend class wxListBase; | |
135 | public: | |
136 | // ctor | |
137 | wxNodeBase(wxListBase *list = (wxListBase *)NULL, | |
138 | wxNodeBase *previous = (wxNodeBase *)NULL, | |
139 | wxNodeBase *next = (wxNodeBase *)NULL, | |
140 | void *data = NULL, | |
2432b92d | 141 | const wxListKey& key = wxDefaultListKey); |
fd3f686c VZ |
142 | |
143 | virtual ~wxNodeBase(); | |
144 | ||
f03fc89f | 145 | // FIXME no check is done that the list is really keyed on strings |
9d2f3c71 | 146 | const wxChar *GetKeyString() const { return m_key.string; } |
74e34480 | 147 | long GetKeyInteger() const { return m_key.integer; } |
fd3f686c | 148 | |
4fabb575 | 149 | // Necessary for some existing code |
9d2f3c71 | 150 | void SetKeyString(wxChar* s) { m_key.string = s; } |
4fabb575 JS |
151 | void SetKeyInteger(long i) { m_key.integer = i; } |
152 | ||
fd3f686c | 153 | #ifdef wxLIST_COMPATIBILITY |
b1d4dd7a RL |
154 | // compatibility methods, use Get* instead. |
155 | wxDEPRECATED( wxNode *Next() const ); | |
156 | wxDEPRECATED( wxNode *Previous() const ); | |
157 | wxDEPRECATED( wxObject *Data() const ); | |
fd3f686c VZ |
158 | #endif // wxLIST_COMPATIBILITY |
159 | ||
160 | protected: | |
161 | // all these are going to be "overloaded" in the derived classes | |
162 | wxNodeBase *GetNext() const { return m_next; } | |
163 | wxNodeBase *GetPrevious() const { return m_previous; } | |
164 | ||
165 | void *GetData() const { return m_data; } | |
166 | void SetData(void *data) { m_data = data; } | |
167 | ||
3c67202d | 168 | // get 0-based index of this node within the list or wxNOT_FOUND |
77c5eefb VZ |
169 | int IndexOf() const; |
170 | ||
fd3f686c VZ |
171 | virtual void DeleteData() { } |
172 | ||
173 | private: | |
174 | // optional key stuff | |
175 | wxListKeyValue m_key; | |
176 | ||
177 | void *m_data; // user data | |
178 | wxNodeBase *m_next, // next and previous nodes in the list | |
179 | *m_previous; | |
180 | ||
181 | wxListBase *m_list; // list we belong to | |
f2af4afb GD |
182 | |
183 | DECLARE_NO_COPY_CLASS(wxNodeBase) | |
fd3f686c VZ |
184 | }; |
185 | ||
186 | // ----------------------------------------------------------------------------- | |
187 | // a double-linked list class | |
188 | // ----------------------------------------------------------------------------- | |
f98bd52a | 189 | |
b1d4dd7a RL |
190 | class wxList; |
191 | ||
bddd7a8d | 192 | class WXDLLIMPEXP_BASE wxListBase : public wxObject |
fd3f686c | 193 | { |
bddd7a8d | 194 | friend class WXDLLIMPEXP_BASE wxNodeBase; // should be able to call DetachNode() |
bcaa23de | 195 | friend class wxHashTableBase; // should be able to call untyped Find() |
788722ac JS |
196 | private: |
197 | // common part of all ctors | |
198 | void Init(wxKeyType keyType = wxKEY_NONE); // Must be declared before it's used (for VC++ 1.5) | |
fd3f686c VZ |
199 | public: |
200 | // default ctor & dtor | |
f2af4afb GD |
201 | wxListBase(wxKeyType keyType = wxKEY_NONE) |
202 | { Init(keyType); } | |
fd3f686c VZ |
203 | virtual ~wxListBase(); |
204 | ||
205 | // accessors | |
206 | // count of items in the list | |
207 | size_t GetCount() const { return m_count; } | |
c801d85f | 208 | |
b79a8705 VZ |
209 | // return TRUE if this list is empty |
210 | bool IsEmpty() const { return m_count == 0; } | |
211 | ||
fd3f686c | 212 | // operations |
e146b8c8 | 213 | |
fd3f686c | 214 | // delete all nodes |
db9504c5 | 215 | void Clear(); |
e146b8c8 | 216 | |
fd3f686c VZ |
217 | // instruct it to destroy user data when deleting nodes |
218 | void DeleteContents(bool destroy) { m_destroy = destroy; } | |
219 | ||
907789a0 RR |
220 | // query if to delete |
221 | bool GetDeleteContents() const | |
222 | { return m_destroy; } | |
e146b8c8 | 223 | |
907789a0 RR |
224 | // get the keytype |
225 | wxKeyType GetKeyType() const | |
226 | { return m_keyType; } | |
227 | ||
228 | // set the keytype (required by the serial code) | |
229 | void SetKeyType(wxKeyType keyType) | |
230 | { wxASSERT( m_count==0 ); m_keyType = keyType; } | |
231 | ||
e146b8c8 | 232 | #ifdef wxLIST_COMPATIBILITY |
b1d4dd7a RL |
233 | // compatibility methods from old wxList |
234 | wxDEPRECATED( int Number() const ); // use GetCount instead. | |
235 | wxDEPRECATED( wxNode *First() const ); // use GetFirst | |
236 | wxDEPRECATED( wxNode *Last() const ); // use GetLast | |
237 | wxDEPRECATED( wxNode *Nth(size_t n) const ); // use Item | |
238 | ||
239 | // kludge for typesafe list migration in core classes. | |
240 | wxDEPRECATED( operator wxList&() const ); | |
e146b8c8 VZ |
241 | #endif // wxLIST_COMPATIBILITY |
242 | ||
fd3f686c | 243 | protected: |
a3ef5bf5 | 244 | |
fd3f686c VZ |
245 | // all methods here are "overloaded" in derived classes to provide compile |
246 | // time type checking | |
247 | ||
248 | // create a node for the list of this type | |
249 | virtual wxNodeBase *CreateNode(wxNodeBase *prev, wxNodeBase *next, | |
250 | void *data, | |
2432b92d | 251 | const wxListKey& key = wxDefaultListKey) = 0; |
fd3f686c | 252 | |
a3ef5bf5 JS |
253 | // Can't access these from derived classes otherwise (bug in Salford C++?) |
254 | #ifdef __SALFORDC__ | |
255 | public: | |
256 | #endif | |
257 | ||
fd3f686c VZ |
258 | // ctors |
259 | // from an array | |
260 | wxListBase(size_t count, void *elements[]); | |
261 | // from a sequence of objects | |
262 | wxListBase(void *object, ... /* terminate with NULL */); | |
263 | ||
a3ef5bf5 | 264 | protected: |
fd3f686c | 265 | // copy ctor and assignment operator |
6788ecb8 | 266 | wxListBase(const wxListBase& list) : wxObject() |
6108b321 | 267 | { Init(); DoCopy(list); } |
fd3f686c VZ |
268 | wxListBase& operator=(const wxListBase& list) |
269 | { Clear(); DoCopy(list); return *this; } | |
270 | ||
271 | // get list head/tail | |
272 | wxNodeBase *GetFirst() const { return m_nodeFirst; } | |
273 | wxNodeBase *GetLast() const { return m_nodeLast; } | |
274 | ||
275 | // by (0-based) index | |
276 | wxNodeBase *Item(size_t index) const; | |
277 | ||
278 | // get the list item's data | |
2b5f62a0 VZ |
279 | void *operator[](size_t n) const |
280 | { | |
281 | wxNodeBase *node = Item(n); | |
282 | ||
283 | return node ? node->GetData() : (wxNodeBase *)NULL; | |
284 | } | |
fd3f686c VZ |
285 | |
286 | // operations | |
287 | // append to end of list | |
890f8a7c RR |
288 | wxNodeBase *Prepend(void *object) |
289 | { return (wxNodeBase *)wxListBase::Insert(object); } | |
290 | // append to beginning of list | |
fd3f686c VZ |
291 | wxNodeBase *Append(void *object); |
292 | // insert a new item at the beginning of the list | |
a802c3a1 | 293 | wxNodeBase *Insert(void *object) { return Insert( (wxNodeBase*)NULL, object); } |
d8996187 VZ |
294 | // insert a new item at the given position |
295 | wxNodeBase *Insert(size_t pos, void *object) | |
296 | { return pos == GetCount() ? Append(object) | |
297 | : Insert(Item(pos), object); } | |
fd3f686c VZ |
298 | // insert before given node or at front of list if prev == NULL |
299 | wxNodeBase *Insert(wxNodeBase *prev, void *object); | |
300 | ||
301 | // keyed append | |
302 | wxNodeBase *Append(long key, void *object); | |
9d2f3c71 | 303 | wxNodeBase *Append(const wxChar *key, void *object); |
fd3f686c VZ |
304 | |
305 | // removes node from the list but doesn't delete it (returns pointer | |
306 | // to the node or NULL if it wasn't found in the list) | |
307 | wxNodeBase *DetachNode(wxNodeBase *node); | |
308 | // delete element from list, returns FALSE if node not found | |
309 | bool DeleteNode(wxNodeBase *node); | |
310 | // finds object pointer and deletes node (and object if DeleteContents | |
311 | // is on), returns FALSE if object not found | |
77c5eefb | 312 | bool DeleteObject(void *object); |
fd3f686c VZ |
313 | |
314 | // search (all return NULL if item not found) | |
315 | // by data | |
316 | wxNodeBase *Find(void *object) const; | |
317 | ||
318 | // by key | |
319 | wxNodeBase *Find(const wxListKey& key) const; | |
320 | ||
3c67202d | 321 | // get 0-based index of object or wxNOT_FOUND |
77c5eefb VZ |
322 | int IndexOf( void *object ) const; |
323 | ||
fd3f686c VZ |
324 | // this function allows the sorting of arbitrary lists by giving |
325 | // a function to compare two list elements. The list is sorted in place. | |
6164d85e | 326 | void Sort(const wxSortCompareFunction compfunc); |
fd3f686c VZ |
327 | |
328 | // functions for iterating over the list | |
329 | void *FirstThat(wxListIterateFunction func); | |
330 | void ForEach(wxListIterateFunction func); | |
331 | void *LastThat(wxListIterateFunction func); | |
e146b8c8 | 332 | |
fd3f686c VZ |
333 | private: |
334 | // helpers | |
fd3f686c VZ |
335 | // common part of copy ctor and assignment operator |
336 | void DoCopy(const wxListBase& list); | |
337 | // common part of all Append()s | |
338 | wxNodeBase *AppendCommon(wxNodeBase *node); | |
339 | // free node's data and node itself | |
340 | void DoDeleteNode(wxNodeBase *node); | |
341 | ||
342 | size_t m_count; // number of elements in the list | |
343 | bool m_destroy; // destroy user data when deleting list items? | |
344 | wxNodeBase *m_nodeFirst, // pointers to the head and tail of the list | |
345 | *m_nodeLast; | |
346 | ||
347 | wxKeyType m_keyType; // type of our keys (may be wxKEY_NONE) | |
348 | }; | |
349 | ||
350 | // ----------------------------------------------------------------------------- | |
351 | // macros for definition of "template" list type | |
352 | // ----------------------------------------------------------------------------- | |
353 | ||
354 | // and now some heavy magic... | |
355 | ||
356 | // declare a list type named 'name' and containing elements of type 'T *' | |
357 | // (as a by product of macro expansion you also get wx##name##Node | |
ce3ed50d | 358 | // wxNode-derived type) |
fd3f686c VZ |
359 | // |
360 | // implementation details: | |
ce3ed50d | 361 | // 1. We define _WX_LIST_ITEM_TYPE_##name typedef to save in it the item type |
fd3f686c VZ |
362 | // for the list of given type - this allows us to pass only the list name |
363 | // to WX_DEFINE_LIST() even if it needs both the name and the type | |
364 | // | |
ce3ed50d JS |
365 | // 2. We redefine all non-type-safe wxList functions with type-safe versions |
366 | // which don't take any space (everything is inline), but bring compile | |
fd3f686c | 367 | // time error checking. |
f03fc89f VZ |
368 | // |
369 | // 3. The macro which is usually used (WX_DECLARE_LIST) is defined in terms of | |
370 | // a more generic WX_DECLARE_LIST_2 macro which, in turn, uses the most | |
371 | // generic WX_DECLARE_LIST_3 one. The last macro adds a sometimes | |
372 | // interesting capability to store polymorphic objects in the list and is | |
373 | // particularly useful with, for example, "wxWindow *" list where the | |
374 | // wxWindowBase pointers are put into the list, but wxWindow pointers are | |
375 | // retrieved from it. | |
376 | ||
f6bcfd97 | 377 | #define WX_DECLARE_LIST_3(T, Tbase, name, nodetype, classexp) \ |
ba059d80 | 378 | typedef int (*wxSortFuncFor_##name)(const T **, const T **); \ |
fd3f686c | 379 | \ |
f6bcfd97 | 380 | classexp nodetype : public wxNodeBase \ |
fd3f686c VZ |
381 | { \ |
382 | public: \ | |
383 | nodetype(wxListBase *list = (wxListBase *)NULL, \ | |
384 | nodetype *previous = (nodetype *)NULL, \ | |
385 | nodetype *next = (nodetype *)NULL, \ | |
7f985bd3 | 386 | T *data = (T *)NULL, \ |
e146b8c8 | 387 | const wxListKey& key = wxDefaultListKey) \ |
fd3f686c VZ |
388 | : wxNodeBase(list, previous, next, data, key) { } \ |
389 | \ | |
390 | nodetype *GetNext() const \ | |
391 | { return (nodetype *)wxNodeBase::GetNext(); } \ | |
392 | nodetype *GetPrevious() const \ | |
393 | { return (nodetype *)wxNodeBase::GetPrevious(); } \ | |
394 | \ | |
395 | T *GetData() const \ | |
396 | { return (T *)wxNodeBase::GetData(); } \ | |
397 | void SetData(T *data) \ | |
398 | { wxNodeBase::SetData(data); } \ | |
399 | \ | |
400 | virtual void DeleteData(); \ | |
401 | }; \ | |
402 | \ | |
f6bcfd97 | 403 | classexp name : public wxListBase \ |
fd3f686c VZ |
404 | { \ |
405 | public: \ | |
e2a3cc0c VZ |
406 | typedef nodetype Node; \ |
407 | \ | |
fd3f686c VZ |
408 | name(wxKeyType keyType = wxKEY_NONE) : wxListBase(keyType) \ |
409 | { } \ | |
410 | name(size_t count, T *elements[]) \ | |
411 | : wxListBase(count, (void **)elements) { } \ | |
412 | \ | |
f6bcfd97 | 413 | name& operator=(const name& list) \ |
f2af4afb | 414 | { (void) wxListBase::operator=(list); return *this; } \ |
f6bcfd97 | 415 | \ |
fd3f686c VZ |
416 | nodetype *GetFirst() const \ |
417 | { return (nodetype *)wxListBase::GetFirst(); } \ | |
418 | nodetype *GetLast() const \ | |
419 | { return (nodetype *)wxListBase::GetLast(); } \ | |
420 | \ | |
421 | nodetype *Item(size_t index) const \ | |
422 | { return (nodetype *)wxListBase::Item(index); } \ | |
423 | \ | |
424 | T *operator[](size_t index) const \ | |
425 | { \ | |
426 | nodetype *node = Item(index); \ | |
7f985bd3 | 427 | return node ? (T*)(node->GetData()) : (T*)NULL; \ |
fd3f686c VZ |
428 | } \ |
429 | \ | |
f03fc89f | 430 | nodetype *Append(Tbase *object) \ |
fd3f686c | 431 | { return (nodetype *)wxListBase::Append(object); } \ |
f03fc89f | 432 | nodetype *Insert(Tbase *object) \ |
a802c3a1 | 433 | { return (nodetype *)Insert((nodetype*)NULL, object); } \ |
d8996187 VZ |
434 | nodetype *Insert(size_t pos, Tbase *object) \ |
435 | { return (nodetype *)wxListBase::Insert(pos, object); } \ | |
f03fc89f | 436 | nodetype *Insert(nodetype *prev, Tbase *object) \ |
fd3f686c VZ |
437 | { return (nodetype *)wxListBase::Insert(prev, object); } \ |
438 | \ | |
439 | nodetype *Append(long key, void *object) \ | |
440 | { return (nodetype *)wxListBase::Append(key, object); } \ | |
9d2f3c71 | 441 | nodetype *Append(const wxChar *key, void *object) \ |
fd3f686c VZ |
442 | { return (nodetype *)wxListBase::Append(key, object); } \ |
443 | \ | |
444 | nodetype *DetachNode(nodetype *node) \ | |
445 | { return (nodetype *)wxListBase::DetachNode(node); } \ | |
446 | bool DeleteNode(nodetype *node) \ | |
447 | { return wxListBase::DeleteNode(node); } \ | |
f03fc89f | 448 | bool DeleteObject(Tbase *object) \ |
fd3f686c VZ |
449 | { return wxListBase::DeleteObject(object); } \ |
450 | \ | |
f03fc89f | 451 | nodetype *Find(Tbase *object) const \ |
fd3f686c VZ |
452 | { return (nodetype *)wxListBase::Find(object); } \ |
453 | \ | |
454 | virtual nodetype *Find(const wxListKey& key) const \ | |
455 | { return (nodetype *)wxListBase::Find(key); } \ | |
456 | \ | |
f03fc89f | 457 | int IndexOf(Tbase *object) const \ |
77c5eefb VZ |
458 | { return wxListBase::IndexOf(object); } \ |
459 | \ | |
fd3f686c VZ |
460 | void Sort(wxSortFuncFor_##name func) \ |
461 | { wxListBase::Sort((wxSortCompareFunction)func); } \ | |
462 | \ | |
463 | protected: \ | |
ea48aff3 | 464 | virtual wxNodeBase *CreateNode(wxNodeBase *prev, wxNodeBase *next, \ |
fd3f686c | 465 | void *data, \ |
e146b8c8 | 466 | const wxListKey& key = wxDefaultListKey) \ |
fd3f686c VZ |
467 | { \ |
468 | return new nodetype(this, \ | |
469 | (nodetype *)prev, (nodetype *)next, \ | |
470 | (T *)data, key); \ | |
471 | } \ | |
385bcb35 | 472 | } |
fd3f686c | 473 | |
f6bcfd97 BP |
474 | #define WX_DECLARE_LIST_2(elementtype, listname, nodename, classexp) \ |
475 | WX_DECLARE_LIST_3(elementtype, elementtype, listname, nodename, classexp) | |
f03fc89f | 476 | |
fd3f686c VZ |
477 | #define WX_DECLARE_LIST(elementtype, listname) \ |
478 | typedef elementtype _WX_LIST_ITEM_TYPE_##listname; \ | |
f6bcfd97 BP |
479 | WX_DECLARE_LIST_2(elementtype, listname, wx##listname##Node, class) |
480 | ||
481 | #define WX_DECLARE_EXPORTED_LIST(elementtype, listname) \ | |
482 | typedef elementtype _WX_LIST_ITEM_TYPE_##listname; \ | |
483 | WX_DECLARE_LIST_2(elementtype, listname, wx##listname##Node, class WXDLLEXPORT) | |
fd3f686c | 484 | |
0b9ab0bd RL |
485 | #define WX_DECLARE_USER_EXPORTED_LIST(elementtype, listname, usergoo) \ |
486 | typedef elementtype _WX_LIST_ITEM_TYPE_##listname; \ | |
487 | WX_DECLARE_LIST_2(elementtype, listname, wx##listname##Node, class usergoo) | |
488 | ||
fd3f686c VZ |
489 | // this macro must be inserted in your program after |
490 | // #include <wx/listimpl.cpp> | |
491 | #define WX_DEFINE_LIST(name) "don't forget to include listimpl.cpp!" | |
492 | ||
0b9ab0bd RL |
493 | #define WX_DEFINE_EXPORTED_LIST(name) WX_DEFINE_LIST(name) |
494 | #define WX_DEFINE_USER_EXPORTED_LIST(name) WX_DEFINE_LIST(name) | |
495 | ||
496 | ||
fd3f686c VZ |
497 | // ============================================================================= |
498 | // now we can define classes 100% compatible with the old ones | |
499 | // ============================================================================= | |
500 | ||
e146b8c8 | 501 | // ---------------------------------------------------------------------------- |
f03fc89f | 502 | // commonly used list classes |
e146b8c8 VZ |
503 | // ---------------------------------------------------------------------------- |
504 | ||
fd3f686c VZ |
505 | #ifdef wxLIST_COMPATIBILITY |
506 | ||
b1d4dd7a RL |
507 | // define this to make a lot of noise about use of the old wxList classes. |
508 | //#define wxWARN_COMPAT_LIST_USE | |
509 | ||
fd3f686c VZ |
510 | // ----------------------------------------------------------------------------- |
511 | // wxList compatibility class: in fact, it's a list of wxObjects | |
512 | // ----------------------------------------------------------------------------- | |
513 | ||
bddd7a8d | 514 | WX_DECLARE_LIST_2(wxObject, wxObjectList, wxObjectListNode, class WXDLLIMPEXP_BASE); |
fd3f686c | 515 | |
bddd7a8d | 516 | class WXDLLIMPEXP_BASE wxList : public wxObjectList |
c801d85f | 517 | { |
fd3f686c | 518 | public: |
b1d4dd7a RL |
519 | #ifdef wxWARN_COMPAT_LIST_USE |
520 | wxDEPRECATED( wxList(int key_type = wxKEY_NONE) ); | |
521 | #else | |
522 | wxList(int key_type = wxKEY_NONE); | |
523 | #endif | |
524 | ||
799ea011 | 525 | // this destructor is required for Darwin |
f11bdd03 | 526 | ~wxList() { } |
fd3f686c | 527 | |
f6bcfd97 | 528 | wxList& operator=(const wxList& list) |
f2af4afb | 529 | { (void) wxListBase::operator=(list); return *this; } |
f6bcfd97 | 530 | |
fd3f686c | 531 | // compatibility methods |
3bef6c4c VZ |
532 | void Sort(wxSortCompareFunction compfunc) { wxListBase::Sort(compfunc); } |
533 | ||
fd3f686c | 534 | wxNode *Member(wxObject *object) const { return (wxNode *)Find(object); } |
f98bd52a VZ |
535 | |
536 | private: | |
537 | DECLARE_DYNAMIC_CLASS(wxList) | |
c801d85f KB |
538 | }; |
539 | ||
fd3f686c VZ |
540 | // ----------------------------------------------------------------------------- |
541 | // wxStringList class for compatibility with the old code | |
542 | // ----------------------------------------------------------------------------- | |
77c5eefb | 543 | |
bddd7a8d | 544 | WX_DECLARE_LIST_2(wxChar, wxStringListBase, wxStringListNode, class WXDLLIMPEXP_BASE); |
fd3f686c | 545 | |
bddd7a8d | 546 | class WXDLLIMPEXP_BASE wxStringList : public wxStringListBase |
c801d85f | 547 | { |
fd3f686c VZ |
548 | public: |
549 | // ctors and such | |
550 | // default | |
b1d4dd7a RL |
551 | #ifdef wxWARN_COMPAT_LIST_USE |
552 | wxDEPRECATED( wxStringList() ); | |
553 | wxDEPRECATED( wxStringList(const wxChar *first ...) ); | |
554 | #else | |
555 | wxStringList(); | |
9d2f3c71 | 556 | wxStringList(const wxChar *first ...); |
b1d4dd7a | 557 | #endif |
fd3f686c | 558 | |
db9504c5 VZ |
559 | // copying the string list: the strings are copied, too (extremely |
560 | // inefficient!) | |
6788ecb8 | 561 | wxStringList(const wxStringList& other) : wxStringListBase() { DeleteContents(TRUE); DoCopy(other); } |
db9504c5 VZ |
562 | wxStringList& operator=(const wxStringList& other) |
563 | { Clear(); DoCopy(other); return *this; } | |
564 | ||
fd3f686c VZ |
565 | // operations |
566 | // makes a copy of the string | |
f526f752 | 567 | wxNode *Add(const wxChar *s); |
890f8a7c RR |
568 | |
569 | // Append to beginning of list | |
f526f752 | 570 | wxNode *Prepend(const wxChar *s); |
fd3f686c | 571 | |
9d2f3c71 | 572 | bool Delete(const wxChar *s); |
fd3f686c | 573 | |
9d2f3c71 OK |
574 | wxChar **ListToArray(bool new_copies = FALSE) const; |
575 | bool Member(const wxChar *s) const; | |
fd3f686c VZ |
576 | |
577 | // alphabetic sort | |
578 | void Sort(); | |
579 | ||
db9504c5 VZ |
580 | private: |
581 | void DoCopy(const wxStringList&); // common part of copy ctor and operator= | |
f98bd52a VZ |
582 | |
583 | DECLARE_DYNAMIC_CLASS(wxStringList) | |
c801d85f KB |
584 | }; |
585 | ||
fd3f686c VZ |
586 | #endif // wxLIST_COMPATIBILITY |
587 | ||
c801d85f | 588 | #endif |
34138703 | 589 | // _WX_LISTH__ |