williamr@2: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // 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 williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: williamr@2: #ifndef __COECONTROLARRAY_H__ williamr@2: #define __COECONTROLARRAY_H__ williamr@2: williamr@2: #include // class CBase williamr@2: williamr@2: class CCoeControl; williamr@2: williamr@2: /** Default id for controls that have no associated id. This is equal williamr@2: to KErrNotFound williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TInt KCoeNoControlId = KErrNotFound; williamr@2: williamr@2: /** Class that encapsulates a control and the identifier for that control. williamr@2: williamr@2: Controls in a CCoeControlArray can be associated with an id. This class encapsulates the control and its id. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: class TCoeControlWithId williamr@2: { williamr@2: public: williamr@2: TCoeControlWithId(TInt aControlId, CCoeControl* aControl = NULL); williamr@2: public: williamr@2: /** The control */ williamr@2: CCoeControl* iControl; williamr@2: /** The id of the control */ williamr@2: TInt iId; williamr@2: }; williamr@2: williamr@2: /** Class that represents an array of controls. williamr@2: williamr@2: The CCoeControlArray class is used to store the child controls of a container control. williamr@2: The method CCoeControl::InitComponentArrayL() must be used to create the array and the method williamr@2: CCoeControlArray& CCoeControl::Components() can be used to get this array. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: class CCoeControlArray : public CBase williamr@2: { williamr@2: public: williamr@2: /** This class is an iterator for the CCoeControlArray class. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class TCursor // robust iterator williamr@2: { williamr@2: public: williamr@2: template T* Control(); williamr@2: template const T* Control() const; williamr@2: IMPORT_C TBool Prev(); williamr@2: IMPORT_C TBool Next(); williamr@2: IMPORT_C TBool IsValid() const; williamr@2: williamr@2: IMPORT_C TBool operator==(const TCursor& aCursor) const; williamr@2: IMPORT_C TBool operator!=(const TCursor& aCursor) const; williamr@2: public: williamr@2: TCursor(const CCoeControlArray& aArray, TInt aIndex); williamr@2: TInt Index() const; williamr@2: private: williamr@2: IMPORT_C CCoeControl* Ctrl() const; williamr@2: void UpdateMemento() const; williamr@2: void UpdateIndex() const; williamr@2: private: williamr@2: const CCoeControlArray* iArray; williamr@2: mutable TInt iIndex; williamr@2: mutable TCoeControlWithId iMemento; williamr@2: }; williamr@2: public: williamr@2: IMPORT_C static CCoeControlArray* NewL(CCoeControl& aOwner); williamr@2: IMPORT_C ~CCoeControlArray(); williamr@2: IMPORT_C TInt Count() const; williamr@2: IMPORT_C void Reset(); williamr@2: IMPORT_C void ResetAndDestroy(); williamr@2: IMPORT_C void SortById(); williamr@2: williamr@2: IMPORT_C TBool ControlsOwnedExternally() const; williamr@2: IMPORT_C void SetControlsOwnedExternally(TBool aOwnedExternally); williamr@2: williamr@2: IMPORT_C TBool IsArrayLocked() const; williamr@2: IMPORT_C void SetArrayLocked(); williamr@2: williamr@2: template T* ControlById(TInt aControlId); williamr@2: template const T* ControlById(TInt aControlId) const; williamr@2: williamr@2: IMPORT_C TCursor Begin() const; williamr@2: IMPORT_C TCursor End() const; williamr@2: IMPORT_C TCursor Find(const CCoeControl* aControl) const; williamr@2: IMPORT_C TCursor Find(TInt aControlId) const; williamr@2: williamr@2: IMPORT_C TCursor AppendLC(CCoeControl* aControl, TInt aControlId = KCoeNoControlId); williamr@2: IMPORT_C TCursor InsertAfterLC(TInt aInsertAfterId, CCoeControl* aControl, TInt aControlId = KCoeNoControlId); williamr@2: IMPORT_C TCursor InsertLC(TCursor& aInsertAt, CCoeControl* aControl, TInt aControlId = KCoeNoControlId); williamr@2: williamr@2: IMPORT_C TInt Remove(const CCoeControl* aControl); williamr@2: IMPORT_C CCoeControl* Remove(TCursor aRemoveAt); williamr@2: IMPORT_C CCoeControl* RemoveById(TInt aControlId); williamr@2: public: williamr@2: IMPORT_C TInt Replace(CCoeControl* aOriginalControl, CCoeControl* aNewControl); williamr@2: williamr@2: public: // internal use only williamr@2: IMPORT_C TCoeControlWithId At(TInt aIndex); williamr@2: IMPORT_C const TCoeControlWithId At(TInt aIndex) const; williamr@2: IMPORT_C TInt Id(const CCoeControl& aControl) const; williamr@2: IMPORT_C void Sort(TLinearOrder< TCoeControlWithId > aOrder); williamr@2: public: williamr@2: /** Defines the possible events related to a change to the contents williamr@2: of the array. */ williamr@2: enum TEvent williamr@2: { williamr@2: /** A control has been added to the array */ williamr@2: EControlAdded, williamr@2: /** A control has been removed from the array */ williamr@2: EControlRemoved williamr@2: }; williamr@2: williamr@2: private: williamr@2: IMPORT_C CCoeControlArray(CCoeControl& aOwner); williamr@2: TInt IndexById(TInt aControlId) const; williamr@2: IMPORT_C CCoeControl* CtrlById(TInt aControlId) const; williamr@2: williamr@2: private: williamr@2: CCoeControl& iOwner; williamr@2: TInt iFlags; williamr@2: RArray iControls; williamr@2: }; williamr@2: williamr@2: /** Gets the control. williamr@2: @return The control at the current cursor position. williamr@2: */ williamr@2: template williamr@2: T* CCoeControlArray::TCursor::Control() williamr@2: { williamr@2: return static_cast(Ctrl()); williamr@2: } williamr@2: williamr@2: /** Gets the control. williamr@2: @return The control at the current cursor position. williamr@2: */ williamr@2: template williamr@2: const T* CCoeControlArray::TCursor::Control() const williamr@2: { williamr@2: return static_cast(Ctrl()); williamr@2: } williamr@2: williamr@2: /** Gets the control with the given id. williamr@2: @param aControlId The id of the desired control. williamr@2: @return The control with the given id. williamr@2: */ williamr@2: template williamr@2: T* CCoeControlArray::ControlById(TInt aControlId) williamr@2: { williamr@2: return static_cast(CtrlById(aControlId)); williamr@2: } williamr@2: williamr@2: /** Gets the control with the given id. williamr@2: @param aControlId The id of the desired control. williamr@2: @return The control with the given id. williamr@2: */ williamr@2: template williamr@2: const T* CCoeControlArray::ControlById(TInt aControlId) const williamr@2: { williamr@2: return static_cast(CtrlById(aControlId)); williamr@2: } williamr@2: williamr@2: #endif //__COECONTROLARRAY_H__