Symbian3/SDK/Source/GUID-F9471A5D-D239-5B24-A116-2B5B2C1F5C61.dita
changeset 0 89d6a7a84779
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Symbian3/SDK/Source/GUID-F9471A5D-D239-5B24-A116-2B5B2C1F5C61.dita	Thu Jan 21 18:18:20 2010 +0000
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
+<!-- This component and the accompanying materials are made available under the terms of the License 
+"Eclipse Public License v1.0" which accompanies this distribution, 
+and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
+<!-- Initial Contributors:
+    Nokia Corporation - initial contribution.
+Contributors: 
+-->
+<!DOCTYPE concept
+  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
+<concept xml:lang="en" id="GUID-F9471A5D-D239-5B24-A116-2B5B2C1F5C61"><title>Restoring Pictures Tutorial</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>Pictures can be restored in two different ways. One way is to restore the picture header and restore the data immediately afterwards. The other way is to restore the picture header and defer the loading of the picture data until a later time. </p> <p>This second way is commonly used when loading rich text documents that include pictures. Using a deferred loading scheme, pictures that occur towards the end of a document need not be loaded until they are needed to be displayed, thus economizing on memory use. </p> <section><title>Restoring the picture header</title> <p>This fragment assumes that the picture header is stored in the root stream of the store, making it easy to restore: </p> <codeblock id="GUID-44712CF8-FBB7-5898-B1F9-C43BB82C17EC" xml:space="preserve">// The file used in the example
+_LIT(KFileName,"C:\\grpict.dat");
+    
+// Open the direct file store
+CDirectFileStore* store = CDirectFileStore::OpenLC(fsSession,KFileName,EFileRead);
+    
+// Read the header stream
+RStoreReadStream stream;
+stream.OpenLC(*store,store-&gt;Root());
+TPictureHeader header;
+header.InternalizeL(stream);</codeblock> <codeblock id="GUID-8F9F9D3D-36E7-534A-BA05-5FF545487DDB" xml:space="preserve">// Close store
+CleanupStack::PopAndDestroy(2); // stream, store</codeblock> <ol id="GUID-A3461FFF-48C2-5447-AA8E-E23C3E9696B7"><li id="GUID-12F9B67D-4A85-5648-89BB-B3CA41DCFBC1"><p>Open the direct file store containing the picture. </p> </li> <li id="GUID-F43C5DEB-BFB9-5076-BCEC-61495B3F326A"><p>Open the root stream of the store, and InternalizeL the picture header. </p> </li> <li id="GUID-5E9FDE2A-4E64-5262-92E9-B15870C6D5AD"><p>Close the stream and store. </p> </li> </ol> </section> <section><title>Restoring the picture data: an example of a MPictureFactory-derived class</title> <p>To restore the picture data itself, it must have an associated entry in a picture factory. The picture factory ensures that the picture data in the store is restored to the correct picture type, which is specified by a UID in the picture header. A picture factory can allow a number of different types of picture to be restored, calling the correct constructor for the class indicated by the UID. In the following example code the picture factory allows only pictures of type <codeph>CSmileyPicture</codeph> to be restored, and panics if the picture data in the store is of another type. </p> <p><b>Restoring the picture </b> </p> <codeblock id="GUID-F05D870C-C1D6-5D04-81AE-703F50054191" xml:space="preserve">// The file used in the example
+_LIT(KFileName,"C:\\grpict.dat");
+    
+// Open the direct file store
+CDirectFileStore* store = CDirectFileStore::OpenLC(fsSession,KFileName,EFileRead);
+    
+// Read the picture
+TExamplePictureFactory factory;
+TPictureHeader header;
+factory.NewPictureL(header,*store);
+iPicture = (CSmileyPicture *) header.iPicture.AsPtr();
+    
+// Close store
+CleanupStack::PopAndDestroy();</codeblock> <p><b>Picture factory </b> </p> <codeblock id="GUID-578BC9C7-9D62-5ADF-A2B5-6601588FE384" xml:space="preserve">class TExamplePictureFactory: public MPictureFactory
+    {
+public:
+    void NewPictureL(TPictureHeader&amp; aHeader,
+            const CStreamStore&amp; aDeferredPictureStore) const;
+    };
+</codeblock> <codeblock id="GUID-C5CCB0B1-3D13-581E-8990-15084212BFB3" xml:space="preserve">void TExamplePictureFactory::NewPictureL(TPictureHeader&amp; aHeader,
+            const CStreamStore&amp; aDeferredPictureStore) const
+    {
+    if (aHeader.iPictureType == KUidExampleSmileyPicture)
+        {
+            // Restore new picture from store into 
+            // the TSwizzle, which changes from
+            // stream id to pointer.
+            // Construct CSmileyPicture object and 
+            // restore from stream.
+        if (aHeader.iPicture.IsId())
+            aHeader.iPicture = CSmileyPicture::NewL(aDeferredPictureStore,aHeader.iPicture.AsId());
+        }
+    else
+        {
+            // Leave
+        User::Leave(KErrNoMemory);
+        }
+    }</codeblock> </section> </conbody><related-links><link href="GUID-520AC2F0-009E-51F3-A661-3B6E949F1423.dita"><linktext>Picture Tutorials</linktext> </link> <link href="GUID-5CEE36FC-C5A9-5C4E-9DBC-9C7B5B44EA2F.dita"><linktext>Picture Concepts</linktext> </link> </related-links></concept>
\ No newline at end of file