lafagnosticuifoundation/cone/inc/coecontrolarray.h
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 #ifndef __COECONTROLARRAY_H__
       
    18 #define __COECONTROLARRAY_H__
       
    19 
       
    20 #include <e32base.h>	// class CBase
       
    21 
       
    22 class CCoeControl;
       
    23 
       
    24 /** Default id for controls that have no associated id. This is equal
       
    25 to KErrNotFound
       
    26 @publishedAll 
       
    27 @released 
       
    28 */
       
    29 const TInt KCoeNoControlId = KErrNotFound;
       
    30 
       
    31 /** Class that encapsulates a control and the identifier for that control.
       
    32 
       
    33 Controls in a CCoeControlArray can be associated with an id. This class encapsulates the control and its id.
       
    34 
       
    35 @publishedAll 
       
    36 @released */
       
    37 class TCoeControlWithId
       
    38 	{
       
    39 public:
       
    40 	TCoeControlWithId(TInt aControlId, CCoeControl* aControl = NULL);
       
    41 public:
       
    42 	/** The control */
       
    43 	CCoeControl* iControl;
       
    44 	/** The id of the control */
       
    45 	TInt iId;
       
    46 	};
       
    47 
       
    48 /** Class that represents an array of controls.
       
    49 
       
    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.
       
    53 
       
    54 @publishedAll 
       
    55 @released */
       
    56 class CCoeControlArray : public CBase
       
    57 	{
       
    58 public:
       
    59 	/** This class is an iterator for the CCoeControlArray class.
       
    60 	@publishedAll 
       
    61 	@released 
       
    62 	*/
       
    63 	class TCursor	// robust iterator
       
    64 		{
       
    65 	public:	
       
    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;
       
    71 		
       
    72 		IMPORT_C TBool operator==(const TCursor& aCursor) const;
       
    73 		IMPORT_C TBool operator!=(const TCursor& aCursor) const;
       
    74 	public:
       
    75 		TCursor(const CCoeControlArray& aArray, TInt aIndex);
       
    76 		TInt Index() const;
       
    77 	private:
       
    78 		IMPORT_C CCoeControl* Ctrl() const;	
       
    79 		void UpdateMemento() const;
       
    80 		void UpdateIndex() const;
       
    81 	private:
       
    82 		const CCoeControlArray* iArray;
       
    83 		mutable TInt iIndex;
       
    84 		mutable TCoeControlWithId iMemento;
       
    85 		};
       
    86 public:
       
    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();
       
    93 	
       
    94 	IMPORT_C TBool ControlsOwnedExternally() const;
       
    95 	IMPORT_C void SetControlsOwnedExternally(TBool aOwnedExternally);
       
    96 			
       
    97 	IMPORT_C TBool IsArrayLocked() const;
       
    98 	IMPORT_C void SetArrayLocked();
       
    99 	
       
   100 	template<typename T> T* ControlById(TInt aControlId);
       
   101 	template<typename T> const T* ControlById(TInt aControlId) const;
       
   102 		
       
   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;
       
   107 
       
   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);
       
   111 	
       
   112 	IMPORT_C TInt Remove(const CCoeControl* aControl);
       
   113 	IMPORT_C CCoeControl* Remove(TCursor aRemoveAt);
       
   114 	IMPORT_C CCoeControl* RemoveById(TInt aControlId);
       
   115 public:	
       
   116 	IMPORT_C TInt Replace(CCoeControl* aOriginalControl, CCoeControl* aNewControl);
       
   117 	
       
   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);
       
   123 public:
       
   124 	/** Defines the possible events related to a change to the contents
       
   125 	of the array. */
       
   126 	enum TEvent
       
   127 		{
       
   128 		/** A control has been added to the array */
       
   129 		EControlAdded,	
       
   130 		/** A control has been removed from the array */
       
   131 		EControlRemoved
       
   132 		};
       
   133 
       
   134 private:
       
   135 	IMPORT_C CCoeControlArray(CCoeControl& aOwner);
       
   136 	TInt IndexById(TInt aControlId) const;
       
   137 	IMPORT_C CCoeControl* CtrlById(TInt aControlId) const;
       
   138 
       
   139 private:
       
   140 	CCoeControl& iOwner;
       
   141 	TInt iFlags;
       
   142 	RArray<TCoeControlWithId> iControls;
       
   143 	};
       
   144 
       
   145 /**	Gets the control.
       
   146 @return The control at the current cursor position. 
       
   147 */
       
   148 template<typename T>
       
   149 T* CCoeControlArray::TCursor::Control()
       
   150 	{
       
   151 	return static_cast<T*>(Ctrl());
       
   152 	}
       
   153 
       
   154 /**	Gets the control.
       
   155 @return The control at the current cursor position. 
       
   156 */
       
   157 template<typename T>
       
   158 const T* CCoeControlArray::TCursor::Control() const
       
   159 	{
       
   160 	return static_cast<T*>(Ctrl());
       
   161 	}
       
   162 
       
   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.
       
   166 */
       
   167 template<typename T>
       
   168 T* CCoeControlArray::ControlById(TInt aControlId)
       
   169 	{
       
   170 	return static_cast<T*>(CtrlById(aControlId));
       
   171 	}
       
   172 
       
   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.
       
   176 */
       
   177 template<typename T>
       
   178 const T* CCoeControlArray::ControlById(TInt aControlId) const
       
   179 	{
       
   180 	return static_cast<T*>(CtrlById(aControlId));
       
   181 	}
       
   182 
       
   183 #endif //__COECONTROLARRAY_H__