Update contrib.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
30 _LIT(KWordApplication, "WORD.APP");
34 // Provides restoration support for objects embedded within embedded word documents
36 class TWordModelStoreResolver : public MRichTextStoreResolver
39 TWordModelStoreResolver(const CStreamStore& aStore);
41 // from MRichTextStoreResolver
42 const CStreamStore& StreamStoreL(TInt aPos)const;
44 const CStreamStore& iStore;
48 TWordModelStoreResolver::TWordModelStoreResolver(const CStreamStore& aStore)
53 const CStreamStore& TWordModelStoreResolver::StreamStoreL(TInt /*aPos*/)const
61 CWordModelHeaderV2::CWordModelHeaderV2(CWordModel* aModel)
68 void CWordModelHeaderV2::SetFactory(MApaModelHeaderFactory* aFactory)
71 delete iHeaderFactory;
72 iHeaderFactory = aFactory;
76 EXPORT_C CWordModelHeaderV2::~CWordModelHeaderV2()
79 This deletes the wrapped word engine. */
83 delete iHeaderFactory;
87 EXPORT_C void CWordModelHeaderV2::StoreL(CStreamStore& aStore,CStreamDictionary& aDict)const
88 /** Stores the wrapped word engine.
90 @param aStore Store to write to
91 @param aDict Stream dictionary to write to */
92 {iModel->StoreL(aStore,aDict,NULL);}
95 EXPORT_C void CWordModelHeaderV2::RestoreL(const CStreamStore& aStore,const CStreamDictionary& aDict)
96 /** Restores the wrapped word engine.
98 @param aStore Store to read from.
99 @param aDict Stream dictionary to read from. */
103 iModel->RestoreL(aStore,aDict,NULL);
104 iResolver = new(ELeave) TWordModelStoreResolver(aStore);
108 EXPORT_C TApaAppIdentifier CWordModelHeaderV2::AppId()const
109 /** Gets an application identifier.
111 @return Word processor application identifier */
112 {return (TApaAppIdentifier(KUidWordApp, KWordApplication()));}
115 EXPORT_C void CWordModelHeaderV2::DetachFromStoreL(CPicture::TDetach aDegree)
116 /** Calls DetachFromStoreL() on the engine's components (text, header, and footer).
118 DetachFromStoreL() sets how pictures are stored.
120 @param aDegree Picture storage option */
122 // Set a picture factory and store resolver if necessary, to support embedded objects
124 TApaModelDoorFactory factory(iHeaderFactory);
125 if ( !(iModel->Text()->PictureFactory() && iModel->Text()->StoreResolver()) )
127 iModel->Text()->SetPictureFactory(&factory,iResolver);
130 iModel->Text()->DetachFromStoreL(aDegree);
131 CRichText* text=iModel->PrintSetup()->Header()->Text();
133 text->DetachFromStoreL(aDegree);
134 text=iModel->PrintSetup()->Footer()->Text();
136 text->DetachFromStoreL(aDegree);
137 // finally, null our reference to the departing store
139 iModel->Text()->SetPictureFactory(NULL,NULL);
145 EXPORT_C CWordModel* CWordModelHeaderV2::Model()
146 /** Gets the wrapped word engine.
148 @return The wrapped word engine */
152 EXPORT_C TWordModelHeaderFactoryV2::TWordModelHeaderFactoryV2(const TFileName& aPrintDriverPath)
153 : iPrintDriverPath(CONST_CAST(TFileName&,aPrintDriverPath))
154 /** Constructor, specifying printer driver path.
156 @param aPrintDriverPath Printer driver path */
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.
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 */
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);
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
191 CWordModelHeaderV3::CWordModelHeaderV3(CWordModel* aModel) : iModel(aModel)
196 // Set header factory. Takes ownership of aFactory
197 void CWordModelHeaderV3::SetFactory(MApaModelHeaderFactory* aFactory)
199 delete iHeaderFactory;
200 iHeaderFactory = aFactory;
203 EXPORT_C CWordModelHeaderV3::~CWordModelHeaderV3()
206 This deletes the wrapped word engine. */
210 delete iHeaderFactory;
213 EXPORT_C void CWordModelHeaderV3::StoreL(CStreamStore& aStore,CStreamDictionary& aDict)const
214 /** Stores the wrapped word engine.
216 @param aStore Store to write to
217 @param aDict Stream dictionary to write to */
219 iModel->StoreL(aStore,aDict,NULL);
222 EXPORT_C void CWordModelHeaderV3::RestoreL(const CStreamStore& aStore,const CStreamDictionary& aDict)
223 /** Restores the wrapped word engine.
225 @param aStore Store to read from.
226 @param aDict Stream dictionary to read from. */
230 iModel->RestoreMinimalL(aStore,aDict,NULL);
231 iResolver = new(ELeave) TWordModelStoreResolver(aStore);
234 EXPORT_C TApaAppIdentifier CWordModelHeaderV3::AppId()const
235 /** Gets an application identifier.
237 @return Word processor application identifier */
239 return (TApaAppIdentifier(KUidWordApp,KWordApplication()));
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).
249 DetachFromStoreL() sets how pictures are stored.
251 @param aDegree Picture storage option */
254 TApaModelDoorFactory factory(iHeaderFactory);
255 if ( !(iModel->Text()->PictureFactory() && iModel->Text()->StoreResolver()) )
257 iModel->Text()->SetPictureFactory(&factory,iResolver);
260 iModel->Text()->DetachFromStoreL(aDegree);
261 // finally, null our reference to the departing store
263 iModel->Text()->SetPictureFactory(NULL,NULL);
268 EXPORT_C CWordModel* CWordModelHeaderV3::Model()
269 /** Gets the wrapped word engine.
271 @return The wrapped word engine */
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()
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.
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 */
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);
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);