textrendering/word/SRC/WNGDOOR.CPP
changeset 0 1fb32624e06b
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32base.h>
       
    21 #include <txtrich.h>
       
    22 #include <prnsetup.h>
       
    23 #include <apamdr.h>
       
    24 #include <apparc.h>
       
    25 #include "txtmrtsr.h"
       
    26 
       
    27 #include "WNGDOOR.H"
       
    28 #include "WNGMODEL.H"
       
    29 
       
    30 _LIT(KWordApplication, "WORD.APP");
       
    31 
       
    32 
       
    33 //
       
    34 // Provides restoration support for objects embedded within embedded word documents
       
    35 //
       
    36 class TWordModelStoreResolver : public MRichTextStoreResolver
       
    37 	{
       
    38 public:
       
    39 	TWordModelStoreResolver(const CStreamStore& aStore);
       
    40 	//
       
    41 	// from MRichTextStoreResolver
       
    42 	const CStreamStore& StreamStoreL(TInt aPos)const;
       
    43 private:
       
    44 	const CStreamStore& iStore;
       
    45 	};
       
    46 
       
    47 
       
    48 TWordModelStoreResolver::TWordModelStoreResolver(const CStreamStore& aStore)
       
    49 	:iStore(aStore)
       
    50 	{}
       
    51 
       
    52 
       
    53 const CStreamStore& TWordModelStoreResolver::StreamStoreL(TInt /*aPos*/)const
       
    54 	{
       
    55 	return iStore;
       
    56 	}
       
    57 
       
    58 //
       
    59 //
       
    60 
       
    61 CWordModelHeaderV2::CWordModelHeaderV2(CWordModel* aModel)
       
    62 // C'tor
       
    63 //
       
    64 	: iModel(aModel)
       
    65 	{}
       
    66 
       
    67 
       
    68 void CWordModelHeaderV2::SetFactory(MApaModelHeaderFactory* aFactory)
       
    69 // takes ownership
       
    70 	{
       
    71 	delete iHeaderFactory;
       
    72 	iHeaderFactory = aFactory;
       
    73 	}
       
    74 
       
    75 
       
    76 EXPORT_C CWordModelHeaderV2::~CWordModelHeaderV2()
       
    77 /** Destructor.
       
    78 
       
    79 This deletes the wrapped word engine. */
       
    80 	{
       
    81 	delete iModel;
       
    82 	delete iResolver;
       
    83 	delete iHeaderFactory;
       
    84 	}
       
    85 
       
    86 
       
    87 EXPORT_C void CWordModelHeaderV2::StoreL(CStreamStore& aStore,CStreamDictionary& aDict)const
       
    88 /** Stores the wrapped word engine.
       
    89 
       
    90 @param aStore Store to write to
       
    91 @param aDict Stream dictionary to write to */
       
    92 	{iModel->StoreL(aStore,aDict,NULL);}
       
    93 
       
    94 
       
    95 EXPORT_C void CWordModelHeaderV2::RestoreL(const CStreamStore& aStore,const CStreamDictionary& aDict)
       
    96 /** Restores the wrapped word engine.
       
    97 
       
    98 @param aStore Store to read from.
       
    99 @param aDict Stream dictionary to read from. */
       
   100 	{
       
   101 	delete iResolver;
       
   102 	iResolver=NULL;
       
   103 	iModel->RestoreL(aStore,aDict,NULL);
       
   104 	iResolver = new(ELeave) TWordModelStoreResolver(aStore);
       
   105 	}
       
   106 
       
   107 
       
   108 EXPORT_C TApaAppIdentifier CWordModelHeaderV2::AppId()const
       
   109 /** Gets an application identifier.
       
   110 
       
   111 @return Word processor application identifier */
       
   112 	{return (TApaAppIdentifier(KUidWordApp, KWordApplication()));}
       
   113 
       
   114 
       
   115 EXPORT_C void CWordModelHeaderV2::DetachFromStoreL(CPicture::TDetach aDegree)
       
   116 /** Calls DetachFromStoreL() on the engine's components (text, header, and footer).
       
   117 
       
   118 DetachFromStoreL() sets how pictures are stored.
       
   119 
       
   120 @param aDegree Picture storage option */
       
   121 	{
       
   122 	// Set a picture factory and store resolver if necessary, to support embedded objects
       
   123 	TBool set=EFalse;
       
   124 	TApaModelDoorFactory factory(iHeaderFactory);
       
   125 	if ( !(iModel->Text()->PictureFactory() && iModel->Text()->StoreResolver()) )
       
   126 		{
       
   127 		iModel->Text()->SetPictureFactory(&factory,iResolver);
       
   128 		set=ETrue;
       
   129 		}
       
   130 	iModel->Text()->DetachFromStoreL(aDegree);
       
   131 	CRichText* text=iModel->PrintSetup()->Header()->Text();
       
   132 	if (text)
       
   133 		text->DetachFromStoreL(aDegree);
       
   134 	text=iModel->PrintSetup()->Footer()->Text();
       
   135 	if (text)
       
   136 		text->DetachFromStoreL(aDegree);
       
   137 	// finally, null our reference to the departing store
       
   138 	if (set)
       
   139 		iModel->Text()->SetPictureFactory(NULL,NULL);
       
   140 	delete iResolver;
       
   141 	iResolver = NULL;
       
   142 	}
       
   143 
       
   144 
       
   145 EXPORT_C CWordModel* CWordModelHeaderV2::Model()
       
   146 /** Gets the wrapped word engine.
       
   147 
       
   148 @return The wrapped word engine */
       
   149 	{return iModel;}
       
   150 
       
   151 
       
   152 EXPORT_C TWordModelHeaderFactoryV2::TWordModelHeaderFactoryV2(const TFileName& aPrintDriverPath)
       
   153 : iPrintDriverPath(CONST_CAST(TFileName&,aPrintDriverPath))
       
   154 /** Constructor, specifying printer driver path.
       
   155 
       
   156 @param aPrintDriverPath Printer driver path */
       
   157 	{}
       
   158 
       
   159 
       
   160 EXPORT_C CApaModelHeader* TWordModelHeaderFactoryV2::NewHeaderL(const CStreamStore& aStore,
       
   161 													const CStreamDictionary& aDict,
       
   162 													const TApaAppIdentifier& aAppId)const
       
   163 /** Creates a new word processor engine application wrapper.
       
   164 
       
   165 @param aStore Store from which to restore word processor engine
       
   166 @param aDict Stream dictionary from which to restore word processor engine
       
   167 @param aAppId Word processor application identifier
       
   168 @return New word processor engine application wrapper */
       
   169 	{
       
   170 	if (aAppId.iAppUid!=KUidWordApp)
       
   171 		User::Leave(KErrNotSupported);
       
   172 	CWordModel* model=CWordModel::NewL(NULL,NULL,iPrintDriverPath);
       
   173 	CleanupStack::PushL(model);
       
   174 	CWordModelHeaderV2* header = new(ELeave) CWordModelHeaderV2(model);
       
   175 	CleanupStack::Pop(); // model - the header has taken ownership
       
   176 	CleanupStack::PushL(header);
       
   177 	// set the factory
       
   178 	TWordModelHeaderFactoryV2* factory=new(ELeave) TWordModelHeaderFactoryV2(iPrintDriverPath);
       
   179 	header->SetFactory(factory); // takes ownership of factory
       
   180 	// restore the header
       
   181 	header->RestoreL(aStore,aDict);
       
   182 	CleanupStack::Pop();  // header
       
   183 	return (header);
       
   184 	}
       
   185 
       
   186 
       
   187 
       
   188 
       
   189 
       
   190 
       
   191 CWordModelHeaderV3::CWordModelHeaderV3(CWordModel* aModel) : iModel(aModel)
       
   192 	{
       
   193 	}
       
   194 
       
   195 
       
   196 // Set header factory. Takes ownership of aFactory
       
   197 void CWordModelHeaderV3::SetFactory(MApaModelHeaderFactory* aFactory)
       
   198 	{
       
   199 	delete iHeaderFactory;
       
   200 	iHeaderFactory = aFactory;
       
   201 	}
       
   202 
       
   203 EXPORT_C CWordModelHeaderV3::~CWordModelHeaderV3()
       
   204 /** Destructor.
       
   205 
       
   206 This deletes the wrapped word engine. */
       
   207 	{
       
   208 	delete iModel;
       
   209 	delete iResolver;
       
   210 	delete iHeaderFactory;
       
   211 	}
       
   212 
       
   213 EXPORT_C void CWordModelHeaderV3::StoreL(CStreamStore& aStore,CStreamDictionary& aDict)const
       
   214 /** Stores the wrapped word engine.
       
   215 
       
   216 @param aStore Store to write to
       
   217 @param aDict Stream dictionary to write to */
       
   218 	{
       
   219 	iModel->StoreL(aStore,aDict,NULL);
       
   220 	}
       
   221 
       
   222 EXPORT_C void CWordModelHeaderV3::RestoreL(const CStreamStore& aStore,const CStreamDictionary& aDict)
       
   223 /** Restores the wrapped word engine.
       
   224 
       
   225 @param aStore Store to read from.
       
   226 @param aDict Stream dictionary to read from. */
       
   227 	{
       
   228 	delete iResolver;
       
   229 	iResolver=NULL;
       
   230 	iModel->RestoreMinimalL(aStore,aDict,NULL);
       
   231 	iResolver = new(ELeave) TWordModelStoreResolver(aStore);
       
   232 	}
       
   233 
       
   234 EXPORT_C TApaAppIdentifier CWordModelHeaderV3::AppId()const
       
   235 /** Gets an application identifier.
       
   236 
       
   237 @return Word processor application identifier */
       
   238 	{
       
   239 	return (TApaAppIdentifier(KUidWordApp,KWordApplication()));
       
   240 	}
       
   241 
       
   242 
       
   243 /* Propogate the detach from store to all components. 
       
   244 Header and footer information is not detached.
       
   245 Set a picture factory and store resolver if necessary, to support embedded objects */
       
   246 EXPORT_C void CWordModelHeaderV3::DetachFromStoreL(CPicture::TDetach aDegree)
       
   247 /** Calls DetachFromStoreL() on the engine's components (text, header, and footer).
       
   248 
       
   249 DetachFromStoreL() sets how pictures are stored.
       
   250 
       
   251 @param aDegree Picture storage option */
       
   252 	{
       
   253 	TBool set=EFalse;
       
   254 	TApaModelDoorFactory factory(iHeaderFactory);
       
   255 	if ( !(iModel->Text()->PictureFactory() && iModel->Text()->StoreResolver()) )
       
   256 		{
       
   257 		iModel->Text()->SetPictureFactory(&factory,iResolver);
       
   258 		set=ETrue;
       
   259 		}
       
   260 	iModel->Text()->DetachFromStoreL(aDegree);
       
   261 	// finally, null our reference to the departing store
       
   262 	if (set)
       
   263 		iModel->Text()->SetPictureFactory(NULL,NULL);
       
   264 	delete iResolver;
       
   265 	iResolver = NULL;
       
   266 	}
       
   267 
       
   268 EXPORT_C CWordModel* CWordModelHeaderV3::Model()
       
   269 /** Gets the wrapped word engine.
       
   270 
       
   271 @return The wrapped word engine */
       
   272 	{return iModel;}
       
   273 
       
   274 
       
   275 
       
   276 
       
   277 
       
   278 /* Construtor
       
   279 This is exported rather than being inline to allow people to instantiate 
       
   280 this class without generating a v-table */
       
   281 EXPORT_C TWordModelHeaderFactoryV3::TWordModelHeaderFactoryV3()
       
   282 /** Constructor. */
       
   283 	{
       
   284 	}
       
   285 
       
   286 
       
   287 // This is called by ETEXT when detaching the picture from the CRichText object
       
   288 EXPORT_C CApaModelHeader* TWordModelHeaderFactoryV3::NewHeaderL(const CStreamStore& aStore,
       
   289 																const CStreamDictionary& aDict,
       
   290 																const TApaAppIdentifier& aAppId)const
       
   291 /** Creates a new word processor engine application wrapper.
       
   292 
       
   293 @param aStore Store from which to restore word processor engine
       
   294 @param aDict Stream dictionary from which to restore word processor engine
       
   295 @param aAppId Word processor application identifier
       
   296 @return New word processor engine application wrapper */
       
   297 	{
       
   298 	if (aAppId.iAppUid!=KUidWordApp)
       
   299 		User::Leave(KErrNotSupported);
       
   300 	CWordModel* model=CWordModel::NewL( NULL, NULL, KDefaultPrinterDriverPath );
       
   301 	CleanupStack::PushL(model);
       
   302 	CWordModelHeaderV3* header = new(ELeave) CWordModelHeaderV3(model);
       
   303 	CleanupStack::Pop(model); // header takes ownership of model
       
   304 	CleanupStack::PushL(header);
       
   305 	// set the factory
       
   306 	TWordModelHeaderFactoryV3* factory=new(ELeave) TWordModelHeaderFactoryV3();
       
   307 	header->SetFactory(factory); // header takes ownership of factory
       
   308 	// restore the header
       
   309 	header->RestoreL(aStore,aDict);
       
   310 	CleanupStack::Pop(header);  
       
   311 	return (header);
       
   312 	}