CCoeControlArray Class Reference

#include <mw/coecontrolarray.h>

class CCoeControlArray : public CBase

Inherits from

Nested Classes and Structures

Detailed Description

Class that represents an array of controls.

The CCoeControlArray class is used to store the child controls of a container control. The method CCoeControl::InitComponentArrayL() must be used to create the array and the method CCoeControlArray& CCoeControl::Components() can be used to get this array.

Member Enumeration Documentation

Enum TEvent

Defines the possible events related to a change to the contents of the array.

EnumeratorValueDescription
EControlAdded

A control has been added to the array

EControlRemoved

A control has been removed from the array

Constructor & Destructor Documentation

~CCoeControlArray ( )

IMPORT_C~CCoeControlArray()

The destructor will delete the controls in the array only if the EControlsOwnedExternally flag is not set.

Member Function Documentation

AppendLC ( CCoeControl *, TInt )

IMPORT_C TCursorAppendLC(CCoeControl *aControl,
TIntaControlId =  KCoeNoControlId
)

Appends a control at the end of the array.

Parameters
aControlThe control to add
aControlIdThe id for the new control
Return Value
A cursor to the added control

At ( TInt )

IMPORT_C TCoeControlWithIdAt(TIntaIndex)

Gets the element at the given index.

Parameters
aIndexThe index of the control
Return Value
The control and its id

At ( TInt )

IMPORT_C const TCoeControlWithIdAt(TIntaIndex)const

Gets the element at the given index.

Parameters
aIndexThe index of the control
Return Value
The control and its id

Begin ( )

IMPORT_C TCursorBegin()const

Gets a cursor that points to the first element of the array. Note that if the array is empty this is actually equivalent to a call to End().

Return Value
A cursor that points to the first control in the array.

ControlById ( TInt )

T *ControlById(TIntaControlId)

Gets the control with the given id.

Parameters
aControlIdThe id of the desired control.
Return Value
The control with the given id.

ControlById ( TInt )

const T *ControlById(TIntaControlId)const

Gets the control with the given id.

Parameters
aControlIdThe id of the desired control.
Return Value
The control with the given id.

ControlsOwnedExternally ( )

IMPORT_C TBoolControlsOwnedExternally()const

This function checks if the controls are owned by the array or not. If the controls are owned by the array they will be deleted when the array is destroyed else they will not.

Return Value
ETrue if the array does NOT own the controls, EFalse if the array owns the controls.

Count ( )

IMPORT_C TIntCount()const

Gets the number of elements in the array.

Return Value
The number of elements in the array

End ( )

IMPORT_C TCursorEnd()const

Gets a cursor to the position right after the last element in the array. To get the last element use Prev(). This cursor is useful as argument to the insertion function to add the new control at the end of the array.

Return Value
A cursor that points right after the last element

Find ( const CCoeControl * )

IMPORT_C TCursorFind(const CCoeControl *aControl)const

Gets a cursor to the control, if the control is found in the array. Use the TCursor::IsValid function to check that the search found something or not.

Parameters
aControlThe control to find.
Return Value
A cursor to the control. This may be an invalid cursor if we didn't find the requested control. Use TCursor::IsValid() to check if the cursor is valid.

Find ( TInt )

IMPORT_C TCursorFind(TIntaControlId)const

Gets a cursor to the control, if the control with the given id is found in the array. Use the TCusror::IsValid function to check that the search found something or not.

Parameters
aControlIdThe id of the control to find.
Return Value
A cursor to the control. This may be an invalid cursor if we didn't find the requested control. Use TCursor::IsValid() to check if the cursor is valid.

Id ( const CCoeControl & )

IMPORT_C TIntId(const CCoeControl &aControl)const

Gets the id of the control.

Parameters
aControlThe control
Return Value
The id of the control or KErrNotFound if the control can't be found.

InsertAfterLC ( TInt, CCoeControl *, TInt )

IMPORT_C TCursorInsertAfterLC(TIntaInsertAfterId,
CCoeControl *aControl,
TIntaControlId =  KCoeNoControlId
)

Inserts a control after the control with the given id.

Each array has an owner (an instance of the CCoeControl class) which is the container of all the child controls. Each control has a parent and for the child controls this parent must be the container. This function will automatically update the parent of aControl.

The function will also result in the CCoeControl::HandleControlArrayEventL method being called on the owner of the array. The event being generated is EControlAdded.

Parameters
aInsertAfterIdThe id of the control after which we want to insert the new control. If a control with this id can't be found in the array the function will leave with KErrNotFound.
aControlThe new control we want to add.
aControlIdThe id of the new control.
Return Value
A cursor to the added control
Leave Codes
KErrLockedif the array has been locked using the
KErrNotFoundif the array doesn't contain a control identified by aInsertAfterId.

InsertLC ( TCursor &, CCoeControl *, TInt )

IMPORT_C TCursorInsertLC(TCursor &aInsertAt,
CCoeControl *aControl,
TIntaControlId =  KCoeNoControlId
)

Inserts a control at the given position.

Each array has an owner (an instance of the CCoeControl class) which is the container of all the child controls. Each control has a parent and for the child controls this parent must be the container. This function will automatically update the parent of aControl.

The function will also result in the CCoeControl::HandleControlArrayEventL method being called on the owner of the array. The event being generated is EControlAdded.

Parameters
aInsertAtThe position at which we want to insert the new control.
aControlThe new control we want to add.
aControlIdThe id of the new control.
Return Value
A cursor to the added control
Leave Codes
KErrLockedif the array has been locked using the

IsArrayLocked ( )

IMPORT_C TBoolIsArrayLocked()const

Checks whether the array is locked or not. If an array is locked any attempt to add or remove controls will fail with KErrLocked.

Return Value
ETrue if the array is locked, EFalse otherwise

NewL ( CCoeControl & )

IMPORT_C CCoeControlArray *NewL(CCoeControl &aOwner)[static]

Creates a new CCoeControlArray.

Parameters
aOwnerThe control that owns the new array
Return Value
A new CCoeControlArray instance

Remove ( const CCoeControl * )

IMPORT_C TIntRemove(const CCoeControl *aControl)

Removes a control but does NOT delete the control itself. The ownership of the control is transferred to the caller.

The function will also result in the CCoeControl::HandleControlArrayEventL method being called on the owner of the array. The event being generated is EControlRemoved.

Parameters
aControlThe control to remove
Return Value
KErrNone if the control was removed successfully, KErrNotFound if the control could not be found.

Remove ( TCursor )

IMPORT_C CCoeControl *Remove(TCursoraRemoveAt)

Removes a control but does NOT delete the control itself. The ownership of the control is transferred to the caller.

The function will also result in the CCoeControl::HandleControlArrayEventL method being called on the owner of the array. The event being generated is EControlRemoved.

Parameters
aRemoveAtThe position of the control to remove
Return Value
A pointer to the control that has been removed. This can be used by the caller to delete the control.

RemoveById ( TInt )

IMPORT_C CCoeControl *RemoveById(TIntaControlId)

Removes a control but does NOT delete the control itself. The ownership of the control is transferred to the caller.

The function will also result in the CCoeControl::HandleControlArrayEventL method being called on the owner of the array. The event being generated is EControlRemoved.

Parameters
aControlIdThe id of the control to remove
Return Value
A pointer to the control that has been removed. This can be used by the caller to delete the control. The function returns NULL if no control with the given aControlId has been found.

Replace ( CCoeControl *, CCoeControl * )

IMPORT_C TIntReplace(CCoeControl *aOriginalControl,
CCoeControl *aNewControl
)

Replaces a control in the array with another control.

Parameters
aOriginalControlThe control that must be replaced
aNewControlThe new control
Return Value
A standard error code

Reset ( )

IMPORT_C voidReset()

Removes all the controls from the array but doesn't delete them.

ResetAndDestroy ( )

IMPORT_C voidResetAndDestroy()

Removes all the controls from the array and deletes them.

SetArrayLocked ( )

IMPORT_C voidSetArrayLocked()

Locks the array. If an array is locked any attempt to add or remove controls will fail with KErrLocked.

SetControlsOwnedExternally ( TBool )

IMPORT_C voidSetControlsOwnedExternally(TBoolaOwnedExternally)

Is used to set whether the array owns the controls or not. If the controls are owned by the array they will be deleted when the array is destroyed else they will not.

Parameters
aOwnedExternallyETrue if the controls are owned externally, EFalse if they are owned by the array.

Sort ( TLinearOrder< TCoeControlWithId > )

IMPORT_C voidSort(TLinearOrder< TCoeControlWithId >aOrder)

This function provides a pluggable implementation to sort the array of controls.

Parameters
aOrderThe user defined static method which implements the algorithm for sorting.

SortById ( )

IMPORT_C voidSortById()

Sorts the controls using their index as the key.