Nokia N97 SDK
Example Applications Guide

guienginedocument.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : guienginedocument.cpp
00004 *  Part of     : GuiEngine
00005 *  Interface   :
00006 *  Description :
00007 *  Version     :
00008 *
00009 *  Copyright (c) 2004 - 2006 Nokia Corporation.
00010 *  This material, including documentation and any related
00011 *  computer programs, is protected by copyright controlled by
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 
00017 // INCLUDE FILES
00018 #include "GuiEngineAppUi.h"
00019 #include "GuiEngineDocument.h"
00020 #include "GuiEngineApplication.h"
00021 
00022 
00023 
00024 // ========================= MEMBER FUNCTIONS ==================================
00025 
00026 // -----------------------------------------------------------------------------
00027 // CGuiEngineDocument::CGuiEngineDocument()
00028 // C++ default constructor can NOT contain any code, that might leave.
00029 // -----------------------------------------------------------------------------
00030 //
00031 CGuiEngineDocument::CGuiEngineDocument( CEikApplication& aApp )
00032 : CEikDocument( aApp )
00033     {
00034     //  No implementation required
00035     }
00036 
00037 // -----------------------------------------------------------------------------
00038 // CGuiEngineDocument::NewL()
00039 // Two-phased constructor.
00040 // -----------------------------------------------------------------------------
00041 //
00042 CGuiEngineDocument* CGuiEngineDocument::NewL( CEikApplication& aApp )
00043     {
00044     CGuiEngineDocument* self = NewLC( aApp );
00045     CleanupStack::Pop( self );
00046     return self;
00047     }
00048 
00049 // -----------------------------------------------------------------------------
00050 // CGuiEngineDocument::NewLC()
00051 // Two-phased constructor.
00052 // -----------------------------------------------------------------------------
00053 //
00054 CGuiEngineDocument* CGuiEngineDocument::NewLC( CEikApplication& aApp )
00055     {
00056     CGuiEngineDocument* self = new ( ELeave ) CGuiEngineDocument( aApp );
00057     CleanupStack::PushL( self );
00058     self->ConstructL();
00059     return self;
00060     }
00061 
00062 // -----------------------------------------------------------------------------
00063 // CGuiEngineDocument::ConstructL()
00064 // Symbian 2nd phase constructor can leave.
00065 // -----------------------------------------------------------------------------
00066 //
00067 void CGuiEngineDocument::ConstructL()
00068     {
00069     iModel = CShapeListManager::NewL();
00070     }
00071 
00072 // -----------------------------------------------------------------------------
00073 // CGuiEngineDocument::~CGuiEngineDocument()
00074 // Destructor.
00075 // -----------------------------------------------------------------------------
00076 //
00077 CGuiEngineDocument::~CGuiEngineDocument()
00078     {
00079     delete iModel;
00080     iModel = NULL;
00081     }
00082 
00083 // -----------------------------------------------------------------------------
00084 // CGuiEngineDocument::CreateAppUiL()
00085 // Create the application user interface, and return a pointer to it;
00086 // the framework takes ownership of this object
00087 // -----------------------------------------------------------------------------
00088 //
00089 CEikAppUi* CGuiEngineDocument::CreateAppUiL()
00090     {
00091     return ( static_cast<CEikAppUi*>( new ( ELeave ) CGuiEngineAppUi( this ) ) );
00092     }
00093 
00094 // -----------------------------------------------------------------------------
00095 // CGuiEngineDocument::StoreL()
00096 // Store model information
00097 // -----------------------------------------------------------------------------
00098 //
00099 void CGuiEngineDocument::StoreL( CStreamStore& aStore,
00100                                  CStreamDictionary& aStreamDic ) const
00101     {
00102 
00103     //  Get the model to save itself to the store
00104     TStreamId modelStreamId = iModel->StoreL( aStore );
00105 
00106     //  Add an entry into the dictionary for the model data
00107     aStreamDic.AssignL( static_cast<CGuiEngineApplication*>
00108                                                 ( Application() )->EngineDllUid(), modelStreamId );
00109 
00110     // Now get the Ui to store itself to the store
00111     TStreamId uiStreamId = static_cast<CGuiEngineAppUi*>
00112                            ( iAppUi )->StoreL( aStore );
00113 
00114     //  Add an entry for it to the dictionary
00115     aStreamDic.AssignL( static_cast<CGuiEngineApplication*>
00116                             ( Application() )->AppDllUid(), uiStreamId );
00117     }
00118 
00119 
00120 // -----------------------------------------------------------------------------
00121 // CGuiEngineDocument::RestoreL()
00122 // Restore the model from the appropriate store stream.
00123 // -----------------------------------------------------------------------------
00124 //
00125 void CGuiEngineDocument::RestoreL( const CStreamStore& aStore,
00126                                    const CStreamDictionary& aStreamDic )
00127     {
00128 
00129     // Do not set this as the document's model yet.
00130     // That way, if the restore fails, we have still
00131     // got the old model.
00132 
00133     CShapeListManager* newModel = CShapeListManager::NewL();
00134     CleanupStack::PushL( newModel );
00135 
00136     //  Find the stream id for the model's data
00137     TStreamId modelStreamId = aStreamDic.At( static_cast<CGuiEngineApplication*>
00138                                                         ( Application() )->EngineDllUid() );
00139 
00140     //  Restore the model from that stream
00141     newModel->RestoreL( aStore, modelStreamId );
00142 
00143     //  Now get rid of the old model and set the new one as current
00144     delete iModel;
00145 
00146     iModel = newModel;
00147     CleanupStack::Pop( newModel );
00148 
00149     //  Just restored so can't have changed
00150     SetChanged( EFalse );
00151 
00152     // Now restore UI data
00153     TStreamId uiStreamId;
00154 
00155     uiStreamId = aStreamDic.At( static_cast<CGuiEngineApplication*>
00156                                 ( Application() )->AppDllUid() );
00157 
00158     ( static_cast<CGuiEngineAppUi*>( iAppUi ) )->RestoreL( aStore, uiStreamId );
00159     }
00160 
00161 // -----------------------------------------------------------------------------
00162 // CGuiEngineDocument::Model()
00163 // The model
00164 // -----------------------------------------------------------------------------
00165 //
00166 CShapeListManager* CGuiEngineDocument::Model()
00167     {
00168     return iModel;
00169     }
00170 
00171 // End of File

© Nokia 2009

Back to top