williamr@2
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
2 |
// All rights reserved.
|
williamr@2
|
3 |
// This component and the accompanying materials are made available
|
williamr@4
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
williamr@2
|
5 |
// which accompanies this distribution, and is available
|
williamr@4
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@2
|
7 |
//
|
williamr@2
|
8 |
// Initial Contributors:
|
williamr@2
|
9 |
// Nokia Corporation - initial contribution.
|
williamr@2
|
10 |
//
|
williamr@2
|
11 |
// Contributors:
|
williamr@2
|
12 |
//
|
williamr@2
|
13 |
// Description:
|
williamr@2
|
14 |
//
|
williamr@2
|
15 |
|
williamr@2
|
16 |
|
williamr@2
|
17 |
#ifndef __COECONTROLARRAY_H__
|
williamr@2
|
18 |
#define __COECONTROLARRAY_H__
|
williamr@2
|
19 |
|
williamr@2
|
20 |
#include <e32base.h> // class CBase
|
williamr@2
|
21 |
|
williamr@2
|
22 |
class CCoeControl;
|
williamr@2
|
23 |
|
williamr@2
|
24 |
/** Default id for controls that have no associated id. This is equal
|
williamr@2
|
25 |
to KErrNotFound
|
williamr@2
|
26 |
@publishedAll
|
williamr@2
|
27 |
@released
|
williamr@2
|
28 |
*/
|
williamr@2
|
29 |
const TInt KCoeNoControlId = KErrNotFound;
|
williamr@2
|
30 |
|
williamr@2
|
31 |
/** Class that encapsulates a control and the identifier for that control.
|
williamr@2
|
32 |
|
williamr@2
|
33 |
Controls in a CCoeControlArray can be associated with an id. This class encapsulates the control and its id.
|
williamr@2
|
34 |
|
williamr@2
|
35 |
@publishedAll
|
williamr@2
|
36 |
@released */
|
williamr@2
|
37 |
class TCoeControlWithId
|
williamr@2
|
38 |
{
|
williamr@2
|
39 |
public:
|
williamr@2
|
40 |
TCoeControlWithId(TInt aControlId, CCoeControl* aControl = NULL);
|
williamr@2
|
41 |
public:
|
williamr@2
|
42 |
/** The control */
|
williamr@2
|
43 |
CCoeControl* iControl;
|
williamr@2
|
44 |
/** The id of the control */
|
williamr@2
|
45 |
TInt iId;
|
williamr@2
|
46 |
};
|
williamr@2
|
47 |
|
williamr@2
|
48 |
/** Class that represents an array of controls.
|
williamr@2
|
49 |
|
williamr@2
|
50 |
The CCoeControlArray class is used to store the child controls of a container control.
|
williamr@2
|
51 |
The method CCoeControl::InitComponentArrayL() must be used to create the array and the method
|
williamr@2
|
52 |
CCoeControlArray& CCoeControl::Components() can be used to get this array.
|
williamr@2
|
53 |
|
williamr@2
|
54 |
@publishedAll
|
williamr@2
|
55 |
@released */
|
williamr@2
|
56 |
class CCoeControlArray : public CBase
|
williamr@2
|
57 |
{
|
williamr@2
|
58 |
public:
|
williamr@2
|
59 |
/** This class is an iterator for the CCoeControlArray class.
|
williamr@2
|
60 |
@publishedAll
|
williamr@2
|
61 |
@released
|
williamr@2
|
62 |
*/
|
williamr@2
|
63 |
class TCursor // robust iterator
|
williamr@2
|
64 |
{
|
williamr@2
|
65 |
public:
|
williamr@2
|
66 |
template<typename T> T* Control();
|
williamr@2
|
67 |
template<typename T> const T* Control() const;
|
williamr@2
|
68 |
IMPORT_C TBool Prev();
|
williamr@2
|
69 |
IMPORT_C TBool Next();
|
williamr@2
|
70 |
IMPORT_C TBool IsValid() const;
|
williamr@2
|
71 |
|
williamr@2
|
72 |
IMPORT_C TBool operator==(const TCursor& aCursor) const;
|
williamr@2
|
73 |
IMPORT_C TBool operator!=(const TCursor& aCursor) const;
|
williamr@2
|
74 |
public:
|
williamr@2
|
75 |
TCursor(const CCoeControlArray& aArray, TInt aIndex);
|
williamr@2
|
76 |
TInt Index() const;
|
williamr@2
|
77 |
private:
|
williamr@2
|
78 |
IMPORT_C CCoeControl* Ctrl() const;
|
williamr@2
|
79 |
void UpdateMemento() const;
|
williamr@2
|
80 |
void UpdateIndex() const;
|
williamr@2
|
81 |
private:
|
williamr@2
|
82 |
const CCoeControlArray* iArray;
|
williamr@2
|
83 |
mutable TInt iIndex;
|
williamr@2
|
84 |
mutable TCoeControlWithId iMemento;
|
williamr@2
|
85 |
};
|
williamr@2
|
86 |
public:
|
williamr@2
|
87 |
IMPORT_C static CCoeControlArray* NewL(CCoeControl& aOwner);
|
williamr@2
|
88 |
IMPORT_C ~CCoeControlArray();
|
williamr@2
|
89 |
IMPORT_C TInt Count() const;
|
williamr@2
|
90 |
IMPORT_C void Reset();
|
williamr@2
|
91 |
IMPORT_C void ResetAndDestroy();
|
williamr@2
|
92 |
IMPORT_C void SortById();
|
williamr@2
|
93 |
|
williamr@2
|
94 |
IMPORT_C TBool ControlsOwnedExternally() const;
|
williamr@2
|
95 |
IMPORT_C void SetControlsOwnedExternally(TBool aOwnedExternally);
|
williamr@2
|
96 |
|
williamr@2
|
97 |
IMPORT_C TBool IsArrayLocked() const;
|
williamr@2
|
98 |
IMPORT_C void SetArrayLocked();
|
williamr@2
|
99 |
|
williamr@2
|
100 |
template<typename T> T* ControlById(TInt aControlId);
|
williamr@2
|
101 |
template<typename T> const T* ControlById(TInt aControlId) const;
|
williamr@2
|
102 |
|
williamr@2
|
103 |
IMPORT_C TCursor Begin() const;
|
williamr@2
|
104 |
IMPORT_C TCursor End() const;
|
williamr@2
|
105 |
IMPORT_C TCursor Find(const CCoeControl* aControl) const;
|
williamr@2
|
106 |
IMPORT_C TCursor Find(TInt aControlId) const;
|
williamr@2
|
107 |
|
williamr@2
|
108 |
IMPORT_C TCursor AppendLC(CCoeControl* aControl, TInt aControlId = KCoeNoControlId);
|
williamr@2
|
109 |
IMPORT_C TCursor InsertAfterLC(TInt aInsertAfterId, CCoeControl* aControl, TInt aControlId = KCoeNoControlId);
|
williamr@2
|
110 |
IMPORT_C TCursor InsertLC(TCursor& aInsertAt, CCoeControl* aControl, TInt aControlId = KCoeNoControlId);
|
williamr@2
|
111 |
|
williamr@2
|
112 |
IMPORT_C TInt Remove(const CCoeControl* aControl);
|
williamr@2
|
113 |
IMPORT_C CCoeControl* Remove(TCursor aRemoveAt);
|
williamr@2
|
114 |
IMPORT_C CCoeControl* RemoveById(TInt aControlId);
|
williamr@2
|
115 |
public:
|
williamr@2
|
116 |
IMPORT_C TInt Replace(CCoeControl* aOriginalControl, CCoeControl* aNewControl);
|
williamr@2
|
117 |
|
williamr@2
|
118 |
public: // internal use only
|
williamr@2
|
119 |
IMPORT_C TCoeControlWithId At(TInt aIndex);
|
williamr@2
|
120 |
IMPORT_C const TCoeControlWithId At(TInt aIndex) const;
|
williamr@2
|
121 |
IMPORT_C TInt Id(const CCoeControl& aControl) const;
|
williamr@2
|
122 |
IMPORT_C void Sort(TLinearOrder< TCoeControlWithId > aOrder);
|
williamr@2
|
123 |
public:
|
williamr@2
|
124 |
/** Defines the possible events related to a change to the contents
|
williamr@2
|
125 |
of the array. */
|
williamr@2
|
126 |
enum TEvent
|
williamr@2
|
127 |
{
|
williamr@2
|
128 |
/** A control has been added to the array */
|
williamr@2
|
129 |
EControlAdded,
|
williamr@2
|
130 |
/** A control has been removed from the array */
|
williamr@2
|
131 |
EControlRemoved
|
williamr@2
|
132 |
};
|
williamr@2
|
133 |
|
williamr@2
|
134 |
private:
|
williamr@2
|
135 |
IMPORT_C CCoeControlArray(CCoeControl& aOwner);
|
williamr@2
|
136 |
TInt IndexById(TInt aControlId) const;
|
williamr@2
|
137 |
IMPORT_C CCoeControl* CtrlById(TInt aControlId) const;
|
williamr@2
|
138 |
|
williamr@2
|
139 |
private:
|
williamr@2
|
140 |
CCoeControl& iOwner;
|
williamr@2
|
141 |
TInt iFlags;
|
williamr@2
|
142 |
RArray<TCoeControlWithId> iControls;
|
williamr@2
|
143 |
};
|
williamr@2
|
144 |
|
williamr@2
|
145 |
/** Gets the control.
|
williamr@2
|
146 |
@return The control at the current cursor position.
|
williamr@2
|
147 |
*/
|
williamr@2
|
148 |
template<typename T>
|
williamr@2
|
149 |
T* CCoeControlArray::TCursor::Control()
|
williamr@2
|
150 |
{
|
williamr@2
|
151 |
return static_cast<T*>(Ctrl());
|
williamr@2
|
152 |
}
|
williamr@2
|
153 |
|
williamr@2
|
154 |
/** Gets the control.
|
williamr@2
|
155 |
@return The control at the current cursor position.
|
williamr@2
|
156 |
*/
|
williamr@2
|
157 |
template<typename T>
|
williamr@2
|
158 |
const T* CCoeControlArray::TCursor::Control() const
|
williamr@2
|
159 |
{
|
williamr@2
|
160 |
return static_cast<T*>(Ctrl());
|
williamr@2
|
161 |
}
|
williamr@2
|
162 |
|
williamr@2
|
163 |
/** Gets the control with the given id.
|
williamr@2
|
164 |
@param aControlId The id of the desired control.
|
williamr@2
|
165 |
@return The control with the given id.
|
williamr@2
|
166 |
*/
|
williamr@2
|
167 |
template<typename T>
|
williamr@2
|
168 |
T* CCoeControlArray::ControlById(TInt aControlId)
|
williamr@2
|
169 |
{
|
williamr@2
|
170 |
return static_cast<T*>(CtrlById(aControlId));
|
williamr@2
|
171 |
}
|
williamr@2
|
172 |
|
williamr@2
|
173 |
/** Gets the control with the given id.
|
williamr@2
|
174 |
@param aControlId The id of the desired control.
|
williamr@2
|
175 |
@return The control with the given id.
|
williamr@2
|
176 |
*/
|
williamr@2
|
177 |
template<typename T>
|
williamr@2
|
178 |
const T* CCoeControlArray::ControlById(TInt aControlId) const
|
williamr@2
|
179 |
{
|
williamr@2
|
180 |
return static_cast<T*>(CtrlById(aControlId));
|
williamr@2
|
181 |
}
|
williamr@2
|
182 |
|
williamr@2
|
183 |
#endif //__COECONTROLARRAY_H__
|