00001 /* 00002 * ============================================================================ 00003 * Name : CPbkViewState from CPbkViewState.h 00004 * Part of : PbkView.dll 00005 * 00006 * Description: 00007 * View states. 00008 * Version: 00009 * 00010 * Copyright (C) 2002 Nokia Corporation. 00011 * This material, including documentation and any related 00012 * computer programs, is protected by copyright controlled by 00013 * Nokia Corporation. All rights are reserved. Copying, 00014 * including reproducing, storing, adapting or translating, any 00015 * or all of this material requires the prior written consent of 00016 * Nokia Corporation. This material also contains confidential 00017 * information which may not be disclosed to others without the 00018 * prior written consent of Nokia Corporation. 00019 * ============================================================================ 00020 */ 00021 00022 #ifndef __CPbkViewState_H__ 00023 #define __CPbkViewState_H__ 00024 00025 // INCLUDES 00026 #include <e32base.h> // CBase 00027 #include <cntdef.h> // TContactItemId, CContactIdArray 00028 00029 // FORWARD DECLARATIONS 00030 class RReadStream; 00031 class RWriteStream; 00032 class CPbkFieldDataArray; 00033 00034 // CLASS DECLARATION 00035 00041 class CPbkViewState : public CBase 00042 { 00043 public: // Types 00044 enum TDataType 00045 { 00046 EEnd = 0, 00047 EFocusedContactId, 00048 ETopContactId, 00049 EMarkedContactIds, 00050 EFocusedFieldIndex, 00051 ETopFieldIndex, 00052 EFieldDataArray, 00053 EParentContactId, 00054 EFlags 00055 }; 00056 00057 enum TFlags 00058 { 00060 ENullFlags = 0, 00062 EFocusFirst = 0x0001, 00064 EFocusLast = 0x0002, 00066 EInitialized = 0x0004, 00068 ESendToBackground = 0x0008 00069 }; 00070 00071 public: // Constructors and destructor 00075 IMPORT_C static CPbkViewState* NewL(); 00076 00081 IMPORT_C static CPbkViewState* NewLC(); 00082 00088 IMPORT_C static CPbkViewState* NewL(RReadStream& aStream); 00089 00096 IMPORT_C static CPbkViewState* NewLC(RReadStream& aStream); 00097 00103 IMPORT_C static CPbkViewState* NewL(const TDesC8& aBuf); 00104 00111 IMPORT_C static CPbkViewState* NewLC(const TDesC8& aBuf); 00112 00116 ~CPbkViewState(); 00117 00118 public: // Getters 00122 IMPORT_C static TUid Uid(); 00123 00128 IMPORT_C TContactItemId FocusedContactId() const; 00129 00134 IMPORT_C TContactItemId TopContactId() const; 00135 00140 IMPORT_C const CContactIdArray* MarkedContactIds() const; 00141 00147 IMPORT_C CContactIdArray* MarkedContactIds(); 00148 00154 IMPORT_C TInt FocusedFieldIndex() const; 00155 00161 IMPORT_C TInt TopFieldIndex() const; 00162 00167 IMPORT_C CPbkFieldDataArray* FieldDataArray() const; 00168 00173 IMPORT_C TContactItemId ParentContactId() const; 00174 00179 IMPORT_C TUint Flags() const; 00180 00181 public: // Setters 00186 IMPORT_C void SetFocusedContactId(TContactItemId aId); 00187 00192 IMPORT_C void SetTopContactId(TContactItemId aId); 00193 00199 IMPORT_C void SetMarkedContactIds(CContactIdArray* aArray); 00200 00206 IMPORT_C void SetFocusedFieldIndex(TInt aIndex); 00207 00213 IMPORT_C void SetTopFieldIndex(TInt aIndex); 00214 00220 IMPORT_C void SetFieldDataArray(CPbkFieldDataArray* aFieldDataArray); 00221 00225 IMPORT_C void Reset(); 00226 00231 IMPORT_C void SetParentContactId(TContactItemId aParentContactId); 00232 00237 IMPORT_C void SetFlags(TUint aFlags); 00238 00248 /*IMPORT_C*/ void MergeViewState(CPbkViewState& aOtherState); 00249 00250 public: // Stream support 00256 IMPORT_C HBufC8* PackL() const; 00257 00263 IMPORT_C HBufC8* PackLC() const; 00264 00271 IMPORT_C void UnpackL(const TDesC8& aPack); 00272 00278 IMPORT_C void ExternalizeL(RWriteStream& aStream) const; 00279 00285 IMPORT_C void InternalizeL(RReadStream& aStream); 00286 00287 public: // Support functions 00288 IMPORT_C TBool operator==(const CPbkViewState& aRhs) const; 00289 00290 private: // Implementation 00291 CPbkViewState(); 00292 00293 private: // data 00295 TContactItemId iFocusedContactId; 00297 TContactItemId iTopContactId; 00299 TInt iFocusedFieldIndex; 00301 TInt iTopFieldIndex; 00303 CContactIdArray* iMarkedContactIds; 00305 CPbkFieldDataArray* iFieldDataArray; 00307 TContactItemId iParentContactId; 00309 TUint iFlags; 00310 00311 private: // const static data 00312 static const TUid KUid; 00313 }; 00314 00315 00316 /* 00317 ** View state binary stream format ** 00318 00319 - View parameter UID is 0x101f4ccf 00320 00321 - Format of the stream in (slightly freeform) BNF: 00322 00323 <stream> ::= <command>+ 00324 <command> ::= Int8(opcode) parameters 00325 <opcode> ::= EEnd | EFocusedContactId | ETopContactId | EMarkedContactIds | 00326 EFocusedFieldIndex | ETopFieldIndex | EFieldDataArray 00327 <command> ::= EEnd // no further commands are read after EEnd. EEnd is not mandatory in a stream. 00328 <command> ::= EFocusedContactId Int32(TContactItemId) 00329 <command> ::= ETopContactId Int32(TContactItemId) 00330 <command> ::= EMarkedContactIds (Int32(count) { Int32(TContactItemId) }) // count is count TContactItemIds 00331 <command> ::= EFocusedFieldIndex Int32(index) 00332 <command> ::= ETopFieldIndex Int32(index) 00333 <command> ::= EFieldDataArray <contactdata> 00334 <command> ::= EParentContactId Int32(TContactItemId) 00335 00336 <contactdata> ::= Int32(count) { fielddata } // count is count of fieldatas 00337 <fielddata> ::= <fieldtype> data 00338 <fieldtype> ::= ETypeText | ETypeTime 00339 <fielddata> ::= ETypeText (Int32(length) text) // length is length of text in chars, text is unicode 00340 <fielddata> ::= ETypeTime (Int32(high) Int32(low)) // high and low words of a TTime's internal Int64 00341 00342 Constants: 00343 EEnd = 0, 00344 EFocusedContactId = 1, 00345 ETopContactId = 2, 00346 EMarkedContactIds = 3, 00347 EFocusedFieldIndex = 4, 00348 ETopFieldIndex = 5, 00349 EFieldDataArray = 6, 00350 EParentContactId = 7 00351 00352 - Example: 00353 Activate Phonebook's contact info view to show contact with id 5 and field 00354 at index 3 focused: 00355 00356 // Write parameters in a buffer 00357 TBuf8<16> param; 00358 RDesWriteStream stream(param); 00359 stream.PushL(); 00360 param.WriteInt8L(1); // opcode EFocusedContactId 00361 param.WriteInt32L(5); // Contact id 5 00362 param.WriteInt8L(4); // opcode EFocusedFieldIndex 00363 param.WriteInt32L(3); // field index 3 00364 stream.CommitL(); 00365 CleanupStack::PopAndDestroy(); // stream 00366 00367 // Make view id with Phonebook's app UID3 and Contact Info View's id 00368 const TVwsViewId viewId(0x101f4cce, 4); 00369 00370 // Activate the view 00371 AppUi()->ActivateViewL(viewId, TUid::Uid(0x101f4ccf), param); 00372 00373 00374 - Same example as above, now using CPbkViewState: 00375 00376 #include <CPbkViewState.h> // need also to add PbkView.lib into projects .mmp 00377 #include <PbkUID.h> // Phonebook UIDs 00378 00379 CPbkViewState* pbkViewParam = CPbkViewState::NewLC(); 00380 pbkViewParam->SetFocusedContactId(5); 00381 pbkViewParam->SetFocusedFieldIndex(3); 00382 HBufC8* paramBuf = pbkViewParam->PackLC(); 00383 00384 // Make view id with Phonebook's app UID3 and Contact Info View's id 00385 const TVwsViewId viewId(KPbkUID3, 4); 00386 00387 // Activate the view 00388 AppUi()->ActivateViewL(viewId, CPbkViewState::Uid(), *paramBuf); 00389 00390 // Cleanup 00391 CleanupStack::PopAndDestroy(2); // paramBuf, pbkViewParam 00392 00393 - The latter example is cleaner, but using CPbkViewState from your 00394 application means that your application will have a dependency to 00395 CPbkViewState.h and PbkView.lib at compile time and to PbkView.dll at 00396 run time. 00397 00398 */ 00399 00400 // __CPbkViewState_H__ 00401 #endif 00402 00403 // End of File