1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #ifndef __COECONTROLARRAY_H__
18 #define __COECONTROLARRAY_H__
20 #include <e32base.h> // class CBase
24 /** Default id for controls that have no associated id. This is equal
29 const TInt KCoeNoControlId = KErrNotFound;
31 /** Class that encapsulates a control and the identifier for that control.
33 Controls in a CCoeControlArray can be associated with an id. This class encapsulates the control and its id.
37 class TCoeControlWithId
40 TCoeControlWithId(TInt aControlId, CCoeControl* aControl = NULL);
43 CCoeControl* iControl;
44 /** The id of the control */
48 /** Class that represents an array of controls.
50 The CCoeControlArray class is used to store the child controls of a container control.
51 The method CCoeControl::InitComponentArrayL() must be used to create the array and the method
52 CCoeControlArray& CCoeControl::Components() can be used to get this array.
56 class CCoeControlArray : public CBase
59 /** This class is an iterator for the CCoeControlArray class.
63 class TCursor // robust iterator
66 template<typename T> T* Control();
67 template<typename T> const T* Control() const;
68 IMPORT_C TBool Prev();
69 IMPORT_C TBool Next();
70 IMPORT_C TBool IsValid() const;
72 IMPORT_C TBool operator==(const TCursor& aCursor) const;
73 IMPORT_C TBool operator!=(const TCursor& aCursor) const;
75 TCursor(const CCoeControlArray& aArray, TInt aIndex);
78 IMPORT_C CCoeControl* Ctrl() const;
79 void UpdateMemento() const;
80 void UpdateIndex() const;
82 const CCoeControlArray* iArray;
84 mutable TCoeControlWithId iMemento;
87 IMPORT_C static CCoeControlArray* NewL(CCoeControl& aOwner);
88 IMPORT_C ~CCoeControlArray();
89 IMPORT_C TInt Count() const;
90 IMPORT_C void Reset();
91 IMPORT_C void ResetAndDestroy();
92 IMPORT_C void SortById();
94 IMPORT_C TBool ControlsOwnedExternally() const;
95 IMPORT_C void SetControlsOwnedExternally(TBool aOwnedExternally);
97 IMPORT_C TBool IsArrayLocked() const;
98 IMPORT_C void SetArrayLocked();
100 template<typename T> T* ControlById(TInt aControlId);
101 template<typename T> const T* ControlById(TInt aControlId) const;
103 IMPORT_C TCursor Begin() const;
104 IMPORT_C TCursor End() const;
105 IMPORT_C TCursor Find(const CCoeControl* aControl) const;
106 IMPORT_C TCursor Find(TInt aControlId) const;
108 IMPORT_C TCursor AppendLC(CCoeControl* aControl, TInt aControlId = KCoeNoControlId);
109 IMPORT_C TCursor InsertAfterLC(TInt aInsertAfterId, CCoeControl* aControl, TInt aControlId = KCoeNoControlId);
110 IMPORT_C TCursor InsertLC(TCursor& aInsertAt, CCoeControl* aControl, TInt aControlId = KCoeNoControlId);
112 IMPORT_C TInt Remove(const CCoeControl* aControl);
113 IMPORT_C CCoeControl* Remove(TCursor aRemoveAt);
114 IMPORT_C CCoeControl* RemoveById(TInt aControlId);
116 IMPORT_C TInt Replace(CCoeControl* aOriginalControl, CCoeControl* aNewControl);
118 public: // internal use only
119 IMPORT_C TCoeControlWithId At(TInt aIndex);
120 IMPORT_C const TCoeControlWithId At(TInt aIndex) const;
121 IMPORT_C TInt Id(const CCoeControl& aControl) const;
122 IMPORT_C void Sort(TLinearOrder< TCoeControlWithId > aOrder);
124 /** Defines the possible events related to a change to the contents
128 /** A control has been added to the array */
130 /** A control has been removed from the array */
135 IMPORT_C CCoeControlArray(CCoeControl& aOwner);
136 TInt IndexById(TInt aControlId) const;
137 IMPORT_C CCoeControl* CtrlById(TInt aControlId) const;
142 RArray<TCoeControlWithId> iControls;
145 /** Gets the control.
146 @return The control at the current cursor position.
149 T* CCoeControlArray::TCursor::Control()
151 return static_cast<T*>(Ctrl());
154 /** Gets the control.
155 @return The control at the current cursor position.
158 const T* CCoeControlArray::TCursor::Control() const
160 return static_cast<T*>(Ctrl());
163 /** Gets the control with the given id.
164 @param aControlId The id of the desired control.
165 @return The control with the given id.
168 T* CCoeControlArray::ControlById(TInt aControlId)
170 return static_cast<T*>(CtrlById(aControlId));
173 /** Gets the control with the given id.
174 @param aControlId The id of the desired control.
175 @return The control with the given id.
178 const T* CCoeControlArray::ControlById(TInt aControlId) const
180 return static_cast<T*>(CtrlById(aControlId));
183 #endif //__COECONTROLARRAY_H__