epoc32/include/app/cpbkviewstate.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 1 666f914201fb
child 4 837f303aceeb
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
/*
williamr@2
     2
* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     3
* All rights reserved.
williamr@2
     4
* This component and the accompanying materials are made available
williamr@2
     5
* 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
     6
* which accompanies this distribution, and is available
williamr@2
     7
* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     8
*
williamr@2
     9
* Initial Contributors:
williamr@2
    10
* Nokia Corporation - initial contribution.
williamr@2
    11
*
williamr@2
    12
* Contributors:
williamr@2
    13
*
williamr@2
    14
* Description: 
williamr@2
    15
*     View states.
williamr@2
    16
*
williamr@2
    17
*/
williamr@2
    18
williamr@2
    19
williamr@2
    20
#ifndef __CPbkViewState_H__
williamr@2
    21
#define __CPbkViewState_H__
williamr@2
    22
williamr@2
    23
//  INCLUDES
williamr@2
    24
#include <e32base.h>    // CBase
williamr@2
    25
#include <cntdef.h>     // TContactItemId, CContactIdArray
williamr@2
    26
williamr@2
    27
// FORWARD DECLARATIONS
williamr@2
    28
class RReadStream;
williamr@2
    29
class RWriteStream;
williamr@2
    30
class CPbkFieldDataArray;
williamr@2
    31
williamr@2
    32
// CLASS DECLARATION
williamr@2
    33
williamr@2
    34
/**
williamr@2
    35
 * Generic Phonebook view state class. Class can be used to pass parameters
williamr@2
    36
 * the Phonebook application when launching the application with the symbian
williamr@2
    37
 * view launching mechanism.
williamr@2
    38
 */
williamr@2
    39
class CPbkViewState : public CBase
williamr@2
    40
    {
williamr@2
    41
    public:  // Types
williamr@2
    42
        enum TDataType
williamr@2
    43
            {
williamr@2
    44
            EEnd = 0,
williamr@2
    45
            EFocusedContactId,
williamr@2
    46
            ETopContactId,
williamr@2
    47
            EMarkedContactIds,
williamr@2
    48
            EFocusedFieldIndex,
williamr@2
    49
            ETopFieldIndex,
williamr@2
    50
            EFieldDataArray,
williamr@2
    51
            EParentContactId,
williamr@2
    52
            EFlags
williamr@2
    53
            };
williamr@2
    54
williamr@2
    55
        enum TFlags
williamr@2
    56
            {
williamr@2
    57
            /// Reset flags
williamr@2
    58
            ENullFlags = 0,
williamr@2
    59
            /// Focus the first item in list views
williamr@2
    60
            EFocusFirst  = 0x0001,
williamr@2
    61
            /// Focus the last item in list views
williamr@2
    62
            EFocusLast   = 0x0002,
williamr@2
    63
            /// Reset state to the view's initial state
williamr@2
    64
            EInitialized = 0x0004,
williamr@2
    65
            /// Send application to background
williamr@2
    66
            ESendToBackground = 0x0008
williamr@2
    67
            };
williamr@2
    68
williamr@2
    69
    public:  // Constructors and destructor
williamr@2
    70
        /**
williamr@2
    71
         * Creates and returns a new instance of this class.
williamr@2
    72
         */
williamr@2
    73
        IMPORT_C static CPbkViewState* NewL();
williamr@2
    74
williamr@2
    75
        /**
williamr@2
    76
         * Like NewL(), but leaves the object on the cleanup stack
williamr@2
    77
         * @see NewL
williamr@2
    78
         */
williamr@2
    79
        IMPORT_C static CPbkViewState* NewLC();
williamr@2
    80
        
williamr@2
    81
        /**
williamr@2
    82
         * Creates and returns a new instance of this class initialized
williamr@2
    83
         * from aStream.
williamr@2
    84
         * @param aStream   A view state stream to internalize.
williamr@2
    85
         */
williamr@2
    86
        IMPORT_C static CPbkViewState* NewL(RReadStream& aStream);
williamr@2
    87
        
williamr@2
    88
        /**
williamr@2
    89
         * Like NewL(RReadStream& aStream) but leaves the object on
williamr@2
    90
         * the cleanup stack.
williamr@2
    91
         * @see NewL(RReadStream& aStream)
williamr@2
    92
         * @param aStream   A view state stream to internalize.
williamr@2
    93
         */
williamr@2
    94
        IMPORT_C static CPbkViewState* NewLC(RReadStream& aStream);
williamr@2
    95
        
williamr@2
    96
        /**
williamr@2
    97
         * Creates and returns a new instance of this class initialized
williamr@2
    98
         * from aBuf.
williamr@2
    99
         * @param aBuf   A view state buffer to internalize.
williamr@2
   100
         */
williamr@2
   101
        IMPORT_C static CPbkViewState* NewL(const TDesC8& aBuf);
williamr@2
   102
        
williamr@2
   103
        /**
williamr@2
   104
         * Like NewL(const TDesC8& aBuf) but leaves the object on
williamr@2
   105
         * the cleanup stack.
williamr@2
   106
         * @see NewL(const TDesC8& aBuf)
williamr@2
   107
         * @param aBuf   A view state buffer to internalize.
williamr@2
   108
         */
williamr@2
   109
        IMPORT_C static CPbkViewState* NewLC(const TDesC8& aBuf);
williamr@2
   110
williamr@2
   111
        /**
williamr@2
   112
         * Destructor.
williamr@2
   113
         */
williamr@2
   114
        ~CPbkViewState();
williamr@2
   115
williamr@2
   116
    public:  // Getters
williamr@2
   117
        /**
williamr@2
   118
         * Returns the message uid for use with view server messages.
williamr@2
   119
         */
williamr@2
   120
        IMPORT_C static TUid Uid();
williamr@2
   121
williamr@2
   122
        /**
williamr@2
   123
         * Returns id of the focused contact.
williamr@2
   124
         * @return  Contact item id of the focused contact, KNullContactId if not set.
williamr@2
   125
         */
williamr@2
   126
        IMPORT_C TContactItemId FocusedContactId() const;
williamr@2
   127
williamr@2
   128
        /**
williamr@2
   129
         * Returns id of the topmost contact.
williamr@2
   130
         * @return  Contact item id of the top contact, KNullContactId if not set.
williamr@2
   131
         */
williamr@2
   132
        IMPORT_C TContactItemId TopContactId() const;
williamr@2
   133
williamr@2
   134
        /**
williamr@2
   135
         * Returns const array of marked contacts ids, NULL if not set. 
williamr@2
   136
         * @return  Contact id array of the marked contacts, NULL if not set.
williamr@2
   137
         */
williamr@2
   138
        IMPORT_C const CContactIdArray* MarkedContactIds() const;
williamr@2
   139
williamr@2
   140
        /**
williamr@2
   141
         * Returns array of marked contacts ids, NULL if not set. Owmership not
williamr@2
   142
         * transferred.
williamr@2
   143
         * @return  Contact id array of the marked contacts, NULL if not set.
williamr@2
   144
         */
williamr@2
   145
        IMPORT_C CContactIdArray* MarkedContactIds();
williamr@2
   146
williamr@2
   147
        /**
williamr@2
   148
         * Returns index of the focused field (field is from FocusedContactId()), 
williamr@2
   149
         * -1 when no field focused.
williamr@2
   150
         * @return  Index of the focused field, -1 if no field is focused.
williamr@2
   151
         */
williamr@2
   152
        IMPORT_C TInt FocusedFieldIndex() const;
williamr@2
   153
williamr@2
   154
        /**
williamr@2
   155
         * Returns index of the topmost field (field is from FocusedContactId()), 
williamr@2
   156
         * -1 when no topmost field.
williamr@2
   157
         * @return  Index of the topmost field, -1 if no topmost field.
williamr@2
   158
         */
williamr@2
   159
        IMPORT_C TInt TopFieldIndex() const;
williamr@2
   160
williamr@2
   161
        /**
williamr@2
   162
         * Returns field data array, NULL if not set.
williamr@2
   163
         * @return Field data array object, NULL if not set.
williamr@2
   164
         */
williamr@2
   165
        IMPORT_C CPbkFieldDataArray* FieldDataArray() const;
williamr@2
   166
williamr@2
   167
        /**
williamr@2
   168
         * Returns the focused contact id's parent, KNullContactId if not set.
williamr@2
   169
         * @return Focused contact id's parent, KNullContactId if not set.
williamr@2
   170
         */
williamr@2
   171
        IMPORT_C TContactItemId ParentContactId() const; 
williamr@2
   172
williamr@2
   173
        /**
williamr@2
   174
         * Returns the view state flags. See CPbkViewState::TFlags.
williamr@2
   175
         * @return  View state object flags
williamr@2
   176
         */
williamr@2
   177
        IMPORT_C TUint Flags() const;
williamr@2
   178
williamr@2
   179
    public:  // Setters
williamr@2
   180
        /**
williamr@2
   181
         * Sets id of the focused contact to aId.
williamr@2
   182
         * @param aId   Sets the focused contact id.
williamr@2
   183
         */
williamr@2
   184
        IMPORT_C void SetFocusedContactId(TContactItemId aId);
williamr@2
   185
williamr@2
   186
        /**
williamr@2
   187
         * Sets id of the topmost contact to aId.
williamr@2
   188
         * @param aId   Sets the topmost contact id.
williamr@2
   189
         */
williamr@2
   190
        IMPORT_C void SetTopContactId(TContactItemId aId);
williamr@2
   191
williamr@2
   192
        /**
williamr@2
   193
         * Sets the array of marked contact ids to aArray. Destroys previous
williamr@2
   194
		 * array and takes ownership of aArray.
williamr@2
   195
         * @param aArray    Sets the marked contact ids.
williamr@2
   196
         */
williamr@2
   197
        IMPORT_C void SetMarkedContactIds(CContactIdArray* aArray);
williamr@2
   198
williamr@2
   199
        /**
williamr@2
   200
         * Sets index of the focused field to aIndex (field from
williamr@2
   201
		 * FocusedContactId()), -1 when no field focused.
williamr@2
   202
         * @param aIndex    Sets focused field index.
williamr@2
   203
         */
williamr@2
   204
        IMPORT_C void SetFocusedFieldIndex(TInt aIndex);
williamr@2
   205
williamr@2
   206
        /**
williamr@2
   207
         * Sets index of the topmost field to aIndex (field from
williamr@2
   208
		 * FocusedContactId()), -1 when no topmost field.
williamr@2
   209
         * @param aIndex    Sets the topmost field index.
williamr@2
   210
         */
williamr@2
   211
        IMPORT_C void SetTopFieldIndex(TInt aIndex);
williamr@2
   212
williamr@2
   213
        /**
williamr@2
   214
         * Sets field data array to aArray. Destroys previous array
williamr@2
   215
         * and takes ownership of aArray.
williamr@2
   216
         * @param aFieldDataArray   Sets the field data array.
williamr@2
   217
         */
williamr@2
   218
        IMPORT_C void SetFieldDataArray(CPbkFieldDataArray* aFieldDataArray);
williamr@2
   219
williamr@2
   220
        /**
williamr@2
   221
         * Reset this state to empty.
williamr@2
   222
         */
williamr@2
   223
        IMPORT_C void Reset();
williamr@2
   224
williamr@2
   225
        /**
williamr@2
   226
         * Sets the focused contact ids parent contact id.
williamr@2
   227
         * @param aParentContactId  Sets the contact ids parent id.
williamr@2
   228
         */
williamr@2
   229
        IMPORT_C void SetParentContactId(TContactItemId aParentContactId);
williamr@2
   230
williamr@2
   231
        /**
williamr@2
   232
         * Sets the view state flags.
williamr@2
   233
         * @param aFlags    Sets the view state parameters. See CPbkViewState::TFlags.
williamr@2
   234
         */
williamr@2
   235
        IMPORT_C void SetFlags(TUint aFlags);
williamr@2
   236
williamr@2
   237
        /**
williamr@2
   238
         * Merges another view state to this view state by setting values from the
williamr@2
   239
         * parameter and overriding any previous values in this state.
williamr@2
   240
         *
williamr@2
   241
         * @param aOtherState   The state to merge to this state. The 
williamr@2
   242
         *                      properties which have a value in aOtherState
williamr@2
   243
         *                      override properties in this object. The aOtherState
williamr@2
   244
         *                      object may be modified by this function.
williamr@2
   245
         */
williamr@2
   246
        /*IMPORT_C*/ void MergeViewState(CPbkViewState& aOtherState);
williamr@2
   247
williamr@2
   248
    public:  // Stream support
williamr@2
   249
        /**
williamr@2
   250
         * Packages and returns this object in a buffer. Caller is responsible
williamr@2
   251
         * of deleting the buffer.
williamr@2
   252
         * @return  Packaged state in a buffer.
williamr@2
   253
         */
williamr@2
   254
        IMPORT_C HBufC8* PackL() const;
williamr@2
   255
williamr@2
   256
        /**
williamr@2
   257
         * Like PackL, but leaves the buffer on the cleanup stack.
williamr@2
   258
         * @see PackL
williamr@2
   259
         * @return Packaged state in a buffer.
williamr@2
   260
         */
williamr@2
   261
        IMPORT_C HBufC8* PackLC() const;
williamr@2
   262
williamr@2
   263
        /**
williamr@2
   264
         * Sets this state from aPack previously created with PackL.
williamr@2
   265
         * @see PackL
williamr@2
   266
         * @see PackLC
williamr@2
   267
         * @param aPack Previously packaged state.
williamr@2
   268
         */
williamr@2
   269
        IMPORT_C void UnpackL(const TDesC8& aPack);
williamr@2
   270
williamr@2
   271
        /**
williamr@2
   272
         * Externalizes this object to aStream.
williamr@2
   273
         * @see InternalizeL
williamr@2
   274
         * @param aSteam    Stream where to externalize this objects state.
williamr@2
   275
         */
williamr@2
   276
        IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
williamr@2
   277
williamr@2
   278
        /**
williamr@2
   279
         * Internalizes this object from aStream.
williamr@2
   280
         * @see ExternalizeL
williamr@2
   281
         * @param aStream   A stream from where this objects state can be internalized from.
williamr@2
   282
         */
williamr@2
   283
        IMPORT_C void InternalizeL(RReadStream& aStream);
williamr@2
   284
williamr@2
   285
    public: // Support functions
williamr@2
   286
        IMPORT_C TBool operator==(const CPbkViewState& aRhs) const; 
williamr@2
   287
williamr@2
   288
    private:  // Implementation
williamr@2
   289
        CPbkViewState();
williamr@2
   290
williamr@2
   291
    private:  // data
williamr@2
   292
        /// Own: Id of the focused contact
williamr@2
   293
        TContactItemId iFocusedContactId;
williamr@2
   294
        /// Own: Id of the topmost contact
williamr@2
   295
        TContactItemId iTopContactId;
williamr@2
   296
        /// Own: Index of the focused field
williamr@2
   297
        TInt iFocusedFieldIndex;
williamr@2
   298
        /// Own: Index of the top field
williamr@2
   299
        TInt iTopFieldIndex;
williamr@2
   300
        /// Own: Array of marked contacts
williamr@2
   301
        CContactIdArray* iMarkedContactIds;
williamr@2
   302
        /// Own: Field data array
williamr@2
   303
        CPbkFieldDataArray* iFieldDataArray;
williamr@2
   304
        /// Own: Id of the focused contacts parent
williamr@2
   305
        TContactItemId iParentContactId;
williamr@2
   306
        /// Own: Flags
williamr@2
   307
        TUint iFlags;
williamr@2
   308
williamr@2
   309
    private:  // const static data
williamr@2
   310
        static const TUid KUid;
williamr@2
   311
    };
williamr@2
   312
williamr@2
   313
williamr@2
   314
/*
williamr@2
   315
   ** View state binary stream format **
williamr@2
   316
   
williamr@2
   317
    - View parameter UID is 0x101f4ccf
williamr@2
   318
williamr@2
   319
    - Format of the stream in (slightly freeform) BNF:
williamr@2
   320
williamr@2
   321
    <stream>  ::= <command>+
williamr@2
   322
    <command> ::= Int8(opcode) parameters
williamr@2
   323
    <opcode>  ::= EEnd | EFocusedContactId | ETopContactId | EMarkedContactIds |
williamr@2
   324
                  EFocusedFieldIndex | ETopFieldIndex | EFieldDataArray
williamr@2
   325
    <command> ::= EEnd  // no further commands are read after EEnd. EEnd is not mandatory in a stream.
williamr@2
   326
    <command> ::= EFocusedContactId Int32(TContactItemId)
williamr@2
   327
    <command> ::= ETopContactId Int32(TContactItemId)
williamr@2
   328
    <command> ::= EMarkedContactIds (Int32(count) { Int32(TContactItemId) })  // count is count TContactItemIds
williamr@2
   329
    <command> ::= EFocusedFieldIndex Int32(index)
williamr@2
   330
    <command> ::= ETopFieldIndex Int32(index)
williamr@2
   331
    <command> ::= EFieldDataArray <contactdata>
williamr@2
   332
    <command> ::= EParentContactId Int32(TContactItemId)
williamr@2
   333
williamr@2
   334
    <contactdata> ::= Int32(count) { fielddata }  // count is count of fieldatas
williamr@2
   335
    <fielddata> ::= <fieldtype> data
williamr@2
   336
    <fieldtype> ::= ETypeText | ETypeTime
williamr@2
   337
    <fielddata> ::= ETypeText (Int32(length) text)  // length is length of text in chars, text is unicode
williamr@2
   338
    <fielddata> ::= ETypeTime (Int32(high) Int32(low))  // high and low words of a TTime's internal Int64
williamr@2
   339
williamr@2
   340
    Constants:
williamr@2
   341
        EEnd = 0,
williamr@2
   342
        EFocusedContactId = 1,
williamr@2
   343
        ETopContactId = 2,
williamr@2
   344
        EMarkedContactIds = 3,
williamr@2
   345
        EFocusedFieldIndex = 4,
williamr@2
   346
        ETopFieldIndex = 5,
williamr@2
   347
        EFieldDataArray = 6,
williamr@2
   348
        EParentContactId = 7
williamr@2
   349
williamr@2
   350
    - Example:
williamr@2
   351
    Activate Phonebook's contact info view to show contact with id 5 and field 
williamr@2
   352
    at index 3 focused:
williamr@2
   353
williamr@2
   354
    // Write parameters in a buffer
williamr@2
   355
    TBuf8<16> param;
williamr@2
   356
    RDesWriteStream stream(param);
williamr@2
   357
    stream.PushL();
williamr@2
   358
    param.WriteInt8L(1);  // opcode EFocusedContactId
williamr@2
   359
    param.WriteInt32L(5);  // Contact id 5
williamr@2
   360
    param.WriteInt8L(4);  // opcode EFocusedFieldIndex
williamr@2
   361
    param.WriteInt32L(3);  // field index 3
williamr@2
   362
    stream.CommitL();
williamr@2
   363
    CleanupStack::PopAndDestroy();  // stream
williamr@2
   364
williamr@2
   365
    // Make view id with Phonebook's app UID3 and Contact Info View's id
williamr@2
   366
    const TVwsViewId viewId(0x101f4cce, 4);
williamr@2
   367
williamr@2
   368
    // Activate the view
williamr@2
   369
    AppUi()->ActivateViewL(viewId, TUid::Uid(0x101f4ccf), param);
williamr@2
   370
williamr@2
   371
williamr@2
   372
    - Same example as above, now using CPbkViewState:
williamr@2
   373
williamr@2
   374
    #include <CPbkViewState.h>  // need also to add PbkView.lib into projects .mmp
williamr@2
   375
    #include <PbkUID.h> // Phonebook UIDs
williamr@2
   376
williamr@2
   377
    CPbkViewState* pbkViewParam = CPbkViewState::NewLC();
williamr@2
   378
    pbkViewParam->SetFocusedContactId(5);
williamr@2
   379
    pbkViewParam->SetFocusedFieldIndex(3);
williamr@2
   380
    HBufC8* paramBuf = pbkViewParam->PackLC();
williamr@2
   381
    
williamr@2
   382
    // Make view id with Phonebook's app UID3 and Contact Info View's id
williamr@2
   383
    const TVwsViewId viewId(KPbkUID3, 4);
williamr@2
   384
williamr@2
   385
    // Activate the view
williamr@2
   386
    AppUi()->ActivateViewL(viewId, CPbkViewState::Uid(), *paramBuf);
williamr@2
   387
williamr@2
   388
    // Cleanup
williamr@2
   389
    CleanupStack::PopAndDestroy(2);  // paramBuf, pbkViewParam
williamr@2
   390
williamr@2
   391
    - The latter example is cleaner, but using CPbkViewState from your 
williamr@2
   392
    application means that your application will have a dependency to 
williamr@2
   393
    CPbkViewState.h and PbkView.lib at compile time and to PbkView.dll at
williamr@2
   394
    run time.
williamr@2
   395
williamr@2
   396
*/
williamr@2
   397
williamr@2
   398
#endif // __CPbkViewState_H__
williamr@2
   399
            
williamr@2
   400
// End of File