]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/arrimpl.cpp
Support using GetTextExtent() with empty string to get descent in wxOSX.
[wxWidgets.git] / include / wx / arrimpl.cpp
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/arrimpl.cpp
3// Purpose: helper file for implementation of dynamic lists
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 16.10.97
7// RCS-ID: $Id$
8// Copyright: (c) 1997 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12/*****************************************************************************
13 * Purpose: implements methods of "template" class declared in *
14 * DECLARE_OBJARRAY macro and which couldn't be implemented inline *
15 * (because they need the full definition of type T in scope) *
16 * *
17 * Usage: 1) #include dynarray.h *
18 * 2) WX_DECLARE_OBJARRAY *
19 * 3) #include arrimpl.cpp *
20 * 4) WX_DEFINE_OBJARRAY *
21 *****************************************************************************/
22
23// needed to resolve the conflict between global T and macro parameter T
24
25#define _WX_ERROR_REMOVE2(x) wxT("bad index in ") wxT(#x) wxT("::RemoveAt()")
26
27// macro implements remaining (not inline) methods of template list
28// (it's private to this file)
29#undef _DEFINE_OBJARRAY
30#define _DEFINE_OBJARRAY(T, name) \
31name::~name() \
32{ \
33 Empty(); \
34} \
35 \
36void name::DoCopy(const name& src) \
37{ \
38 for ( size_t ui = 0; ui < src.size(); ui++ ) \
39 Add(src[ui]); \
40} \
41 \
42name& name::operator=(const name& src) \
43{ \
44 Empty(); \
45 DoCopy(src); \
46 \
47 return *this; \
48} \
49 \
50name::name(const name& src) : wxArrayPtrVoid() \
51{ \
52 DoCopy(src); \
53} \
54 \
55void name::DoEmpty() \
56{ \
57 for ( size_t ui = 0; ui < size(); ui++ ) \
58 delete (T*)base_array::operator[](ui); \
59} \
60 \
61void name::RemoveAt(size_t uiIndex, size_t nRemove) \
62{ \
63 wxCHECK_RET( uiIndex < size(), _WX_ERROR_REMOVE2(name) ); \
64 \
65 for (size_t i = 0; i < nRemove; i++ ) \
66 delete (T*)base_array::operator[](uiIndex + i); \
67 \
68 base_array::erase(begin() + uiIndex, begin() + uiIndex + nRemove); \
69} \
70 \
71void name::Add(const T& item, size_t nInsert) \
72{ \
73 if (nInsert == 0) \
74 return; \
75 T* pItem = new T(item); \
76 size_t nOldSize = size(); \
77 if ( pItem != NULL ) \
78 base_array::insert(end(), nInsert, pItem); \
79 for (size_t i = 1; i < nInsert; i++) \
80 base_array::operator[](nOldSize + i) = new T(item); \
81} \
82 \
83void name::Insert(const T& item, size_t uiIndex, size_t nInsert) \
84{ \
85 if (nInsert == 0) \
86 return; \
87 T* pItem = new T(item); \
88 if ( pItem != NULL ) \
89 base_array::insert(begin() + uiIndex, nInsert, pItem); \
90 for (size_t i = 1; i < nInsert; i++) \
91 base_array::operator[](uiIndex + i) = new T(item); \
92} \
93 \
94int name::Index(const T& item, bool bFromEnd) const \
95{ \
96 if ( bFromEnd ) { \
97 if ( size() > 0 ) { \
98 size_t ui = size() - 1; \
99 do { \
100 if ( (T*)base_array::operator[](ui) == &item ) \
101 return static_cast<int>(ui); \
102 ui--; \
103 } \
104 while ( ui != 0 ); \
105 } \
106 } \
107 else { \
108 for( size_t ui = 0; ui < size(); ui++ ) { \
109 if( (T*)base_array::operator[](ui) == &item ) \
110 return static_cast<int>(ui); \
111 } \
112 } \
113 \
114 return wxNOT_FOUND; \
115}
116
117// redefine the macro so that now it will generate the class implementation
118// old value would provoke a compile-time error if this file is not included
119#undef WX_DEFINE_OBJARRAY
120#define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_wxObjArray##name, name)