1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/mw/coecontrolarray.h Wed Mar 31 12:27:01 2010 +0100
1.3 @@ -0,0 +1,183 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +
1.20 +#ifndef __COECONTROLARRAY_H__
1.21 +#define __COECONTROLARRAY_H__
1.22 +
1.23 +#include <e32base.h> // class CBase
1.24 +
1.25 +class CCoeControl;
1.26 +
1.27 +/** Default id for controls that have no associated id. This is equal
1.28 +to KErrNotFound
1.29 +@publishedAll
1.30 +@released
1.31 +*/
1.32 +const TInt KCoeNoControlId = KErrNotFound;
1.33 +
1.34 +/** Class that encapsulates a control and the identifier for that control.
1.35 +
1.36 +Controls in a CCoeControlArray can be associated with an id. This class encapsulates the control and its id.
1.37 +
1.38 +@publishedAll
1.39 +@released */
1.40 +class TCoeControlWithId
1.41 + {
1.42 +public:
1.43 + TCoeControlWithId(TInt aControlId, CCoeControl* aControl = NULL);
1.44 +public:
1.45 + /** The control */
1.46 + CCoeControl* iControl;
1.47 + /** The id of the control */
1.48 + TInt iId;
1.49 + };
1.50 +
1.51 +/** Class that represents an array of controls.
1.52 +
1.53 +The CCoeControlArray class is used to store the child controls of a container control.
1.54 +The method CCoeControl::InitComponentArrayL() must be used to create the array and the method
1.55 +CCoeControlArray& CCoeControl::Components() can be used to get this array.
1.56 +
1.57 +@publishedAll
1.58 +@released */
1.59 +class CCoeControlArray : public CBase
1.60 + {
1.61 +public:
1.62 + /** This class is an iterator for the CCoeControlArray class.
1.63 + @publishedAll
1.64 + @released
1.65 + */
1.66 + class TCursor // robust iterator
1.67 + {
1.68 + public:
1.69 + template<typename T> T* Control();
1.70 + template<typename T> const T* Control() const;
1.71 + IMPORT_C TBool Prev();
1.72 + IMPORT_C TBool Next();
1.73 + IMPORT_C TBool IsValid() const;
1.74 +
1.75 + IMPORT_C TBool operator==(const TCursor& aCursor) const;
1.76 + IMPORT_C TBool operator!=(const TCursor& aCursor) const;
1.77 + public:
1.78 + TCursor(const CCoeControlArray& aArray, TInt aIndex);
1.79 + TInt Index() const;
1.80 + private:
1.81 + IMPORT_C CCoeControl* Ctrl() const;
1.82 + void UpdateMemento() const;
1.83 + void UpdateIndex() const;
1.84 + private:
1.85 + const CCoeControlArray* iArray;
1.86 + mutable TInt iIndex;
1.87 + mutable TCoeControlWithId iMemento;
1.88 + };
1.89 +public:
1.90 + IMPORT_C static CCoeControlArray* NewL(CCoeControl& aOwner);
1.91 + IMPORT_C ~CCoeControlArray();
1.92 + IMPORT_C TInt Count() const;
1.93 + IMPORT_C void Reset();
1.94 + IMPORT_C void ResetAndDestroy();
1.95 + IMPORT_C void SortById();
1.96 +
1.97 + IMPORT_C TBool ControlsOwnedExternally() const;
1.98 + IMPORT_C void SetControlsOwnedExternally(TBool aOwnedExternally);
1.99 +
1.100 + IMPORT_C TBool IsArrayLocked() const;
1.101 + IMPORT_C void SetArrayLocked();
1.102 +
1.103 + template<typename T> T* ControlById(TInt aControlId);
1.104 + template<typename T> const T* ControlById(TInt aControlId) const;
1.105 +
1.106 + IMPORT_C TCursor Begin() const;
1.107 + IMPORT_C TCursor End() const;
1.108 + IMPORT_C TCursor Find(const CCoeControl* aControl) const;
1.109 + IMPORT_C TCursor Find(TInt aControlId) const;
1.110 +
1.111 + IMPORT_C TCursor AppendLC(CCoeControl* aControl, TInt aControlId = KCoeNoControlId);
1.112 + IMPORT_C TCursor InsertAfterLC(TInt aInsertAfterId, CCoeControl* aControl, TInt aControlId = KCoeNoControlId);
1.113 + IMPORT_C TCursor InsertLC(TCursor& aInsertAt, CCoeControl* aControl, TInt aControlId = KCoeNoControlId);
1.114 +
1.115 + IMPORT_C TInt Remove(const CCoeControl* aControl);
1.116 + IMPORT_C CCoeControl* Remove(TCursor aRemoveAt);
1.117 + IMPORT_C CCoeControl* RemoveById(TInt aControlId);
1.118 +public:
1.119 + IMPORT_C TInt Replace(CCoeControl* aOriginalControl, CCoeControl* aNewControl);
1.120 +
1.121 +public: // internal use only
1.122 + IMPORT_C TCoeControlWithId At(TInt aIndex);
1.123 + IMPORT_C const TCoeControlWithId At(TInt aIndex) const;
1.124 + IMPORT_C TInt Id(const CCoeControl& aControl) const;
1.125 + IMPORT_C void Sort(TLinearOrder< TCoeControlWithId > aOrder);
1.126 +public:
1.127 + /** Defines the possible events related to a change to the contents
1.128 + of the array. */
1.129 + enum TEvent
1.130 + {
1.131 + /** A control has been added to the array */
1.132 + EControlAdded,
1.133 + /** A control has been removed from the array */
1.134 + EControlRemoved
1.135 + };
1.136 +
1.137 +private:
1.138 + IMPORT_C CCoeControlArray(CCoeControl& aOwner);
1.139 + TInt IndexById(TInt aControlId) const;
1.140 + IMPORT_C CCoeControl* CtrlById(TInt aControlId) const;
1.141 +
1.142 +private:
1.143 + CCoeControl& iOwner;
1.144 + TInt iFlags;
1.145 + RArray<TCoeControlWithId> iControls;
1.146 + };
1.147 +
1.148 +/** Gets the control.
1.149 +@return The control at the current cursor position.
1.150 +*/
1.151 +template<typename T>
1.152 +T* CCoeControlArray::TCursor::Control()
1.153 + {
1.154 + return static_cast<T*>(Ctrl());
1.155 + }
1.156 +
1.157 +/** Gets the control.
1.158 +@return The control at the current cursor position.
1.159 +*/
1.160 +template<typename T>
1.161 +const T* CCoeControlArray::TCursor::Control() const
1.162 + {
1.163 + return static_cast<T*>(Ctrl());
1.164 + }
1.165 +
1.166 +/** Gets the control with the given id.
1.167 +@param aControlId The id of the desired control.
1.168 +@return The control with the given id.
1.169 +*/
1.170 +template<typename T>
1.171 +T* CCoeControlArray::ControlById(TInt aControlId)
1.172 + {
1.173 + return static_cast<T*>(CtrlById(aControlId));
1.174 + }
1.175 +
1.176 +/** Gets the control with the given id.
1.177 +@param aControlId The id of the desired control.
1.178 +@return The control with the given id.
1.179 +*/
1.180 +template<typename T>
1.181 +const T* CCoeControlArray::ControlById(TInt aControlId) const
1.182 + {
1.183 + return static_cast<T*>(CtrlById(aControlId));
1.184 + }
1.185 +
1.186 +#endif //__COECONTROLARRAY_H__