localisation/apparchitecture/apparc/APAMDR.CPP
branchSymbian3
changeset 57 b8d18c84f71c
parent 6 c108117318cb
equal deleted inserted replaced
56:aa99f2208aad 57:b8d18c84f71c
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 //
    14 // apamdr.cpp
    15 
    15 //
       
    16 
       
    17 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    18 #if !defined(__APA_INTERNAL_H__)
       
    19 #include "apainternal.h"
       
    20 #endif
       
    21 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
    16 #include "APASTD.H" // Panics etc.
    22 #include "APASTD.H" // Panics etc.
    17 #include <apadbase.h>
    23 
    18 #include <apamdr.h>
    24 #include <apamdr.h>
    19 #include <apparc.h>
    25 
    20 #include <apgdoor.h>
    26 #include <apgdoor.h>
    21 
    27 #include <s32mem.h>		// class TBufBuf
    22 #include <s32stor.h>
    28 
    23 #include <s32file.h>
    29 const TInt KHugeGranularity = 4096; // 4k granularity for the door's host buffer
    24 #include <s32std.h>
    30 
    25 #include <s32mem.h>
    31 //
    26 
       
    27 #ifdef _UNICODE
       
    28 #define KUidApaDoorBaseStream KUidApaDoorBaseStream16
       
    29 #else
       
    30 #define KUidApaDoorBaseStream KUidApaDoorBaseStream8
       
    31 #endif
       
    32 
       
    33 #ifdef _UNICODE
       
    34 const TUid KUidApaDoorBaseStream16={0x10003A36};
       
    35 #else
       
    36 const TUid KUidApaDoorBaseStream8={0x10000146};
       
    37 #endif
       
    38 const TInt KHugeGranularity=4096; // 4k granularity for the door's host buffer
       
    39 
       
    40 ////////////////////////////////////
       
    41 // HBufBuf
    32 // HBufBuf
    42 ////////////////////////////////////
    33 //
    43 
    34 
    44 class HBufBuf : public TBufBuf
    35 class HBufBuf : public TBufBuf
    45 	{
    36 	{
    46 public:
    37 public:
    47 	static HBufBuf* NewL(CBufBase& aBuf,TInt aPos,TInt aMode=ERead|EWrite);
    38 	static HBufBuf* NewL(CBufBase& aBuf,TInt aPos,TInt aMode=ERead|EWrite);
    48 private:
    39 private:
    49 	void DoRelease();
    40 	void DoRelease();
    50 	};
    41 	};
    51 
    42 
    52 
       
    53 HBufBuf* HBufBuf::NewL(CBufBase& aBuf,TInt aPos,TInt aMode)
    43 HBufBuf* HBufBuf::NewL(CBufBase& aBuf,TInt aPos,TInt aMode)
    54 //
    44 //
    55 // Create a pre-set buffer stream buffer.
    45 // Create a pre-set buffer stream buffer.
    56 //
    46 //
    57 	{
    47 	{
    58 	HBufBuf* buf=new(ELeave) HBufBuf;
    48 	HBufBuf* buf=new(ELeave) HBufBuf;
    59 	buf->Set(aBuf,aPos,aMode);
    49 	buf->Set(aBuf,aPos,aMode);
    60 	return buf;
    50 	return buf;
    61 	}
    51 	}
    62 
    52 
    63 
       
    64 void HBufBuf::DoRelease()
    53 void HBufBuf::DoRelease()
    65 //
    54 //
    66 // Finished with this stream buffer.
    55 // Finished with this stream buffer.
    67 //
    56 //
    68 	{
    57 	{
    69 	delete this;
    58 	delete this;
    70 	}
    59 	}
    71 
    60 
    72 
    61 //
    73 ////////////////////////////////////
       
    74 // CApaDoorBase
       
    75 ////////////////////////////////////
       
    76 
       
    77 EXPORT_C CApaDoorBase::CApaDoorBase()
       
    78 	{
       
    79 	}
       
    80 
       
    81 EXPORT_C void CApaDoorBase::ExternalizeBaseStreamL(CStreamStore& aStore,CStreamDictionary& aStreamDict)const
       
    82 /** Externalises the information contained in this base class to a stream in the 
       
    83 specified store.
       
    84 
       
    85 The resulting stream ID is associated with an internal UID, and placed in 
       
    86 the specified stream dictionary.
       
    87 
       
    88 @publishedAll
       
    89 @released
       
    90 @param aStore The store to contain the stream.
       
    91 @param aStreamDict The stream dictionary to contain the stream ID (and an associated 
       
    92 internal UID). */
       
    93 	{
       
    94 	RStoreWriteStream stream;
       
    95 	TStreamId id=stream.CreateLC(aStore);
       
    96 	//
       
    97 	// write the format
       
    98 	if (iFormat==ETemporarilyIconic)
       
    99 		stream.WriteInt8L(EGlassDoor);
       
   100 	else
       
   101 		stream.WriteInt8L(iFormat);
       
   102 	//
       
   103 	// write the size
       
   104 	TSize size;
       
   105 	if (iFormat==ETemporarilyIconic)
       
   106 		size = GlassDoorSize();
       
   107 	else
       
   108 		GetSizeInTwips(size);
       
   109 	stream<< size;
       
   110 	// 
       
   111 	// write the source and close
       
   112 	stream<< iSource;
       
   113 	stream.CommitL();
       
   114 	CleanupStack::PopAndDestroy(); // stream
       
   115 	aStreamDict.AssignL(KUidApaDoorBaseStream,id);
       
   116 	}
       
   117 
       
   118 
       
   119 
       
   120 EXPORT_C TSize CApaDoorBase::InternalizeBaseStreamL(const CStreamStore& aStore,const CStreamDictionary& aStreamDict)
       
   121 /** Internalises the information for this base class from a stream in the specified 
       
   122 store, and returns the size of the icon or glass door.
       
   123 
       
   124 The stream ID is extracted from the specified stream dictionary. The UID associated 
       
   125 with the stream ID is the same as that used when externalising.
       
   126 
       
   127 @publishedAll 
       
   128 @released
       
   129 @param aStore The store containing the stream.
       
   130 @param aStreamDict The steam dictionary containing the stream ID.
       
   131 @return The size of the icon or glass door, in twips. */
       
   132 	{
       
   133 	TStreamId id=aStreamDict.At(KUidApaDoorBaseStream);
       
   134 	if (id==KNullStreamId)
       
   135 		User::Leave(KErrCorrupt); //  there is no base stream - the file is not valid (used to panic EPanicNoBaseDoorStream)
       
   136 	RStoreReadStream stream;
       
   137 	stream.OpenLC(aStore,id);
       
   138 	iFormat = (TFormat)stream.ReadInt8L();
       
   139 	__ASSERT_DEBUG(iFormat==EIconic || iFormat==EGlassDoor,Panic(EDPanicIllegalDoorFormat));
       
   140 	TSize size;
       
   141 	stream>> size;
       
   142 	stream>> iSource;
       
   143 	CleanupStack::PopAndDestroy(); // stream
       
   144 	return size;
       
   145 	}
       
   146 
       
   147 // Virtual functions from CPicture
       
   148 
       
   149 EXPORT_C TStreamId CApaDoorBase::StoreL(CStreamStore& aStore) const
       
   150 /** Stores the Embedded Document to the specified store.
       
   151 
       
   152 @publishedAll 
       
   153 @released
       
   154 @param aStore The store containing the stream.
       
   155 @return The ID of the (head) stream used to store the Embedded Document */
       
   156 	{
       
   157 	return CPicture::StoreL(aStore);
       
   158 	}
       
   159 
       
   160 EXPORT_C void CApaDoorBase::SetScaleFactor(TInt aScaleFactorWidth,TInt aScaleFactorHeight)
       
   161 /** Sets the Embedded Document's scale factors
       
   162 
       
   163 @publishedAll 
       
   164 @released
       
   165 @param aScaleFactorWidth The width scale factor, in percent
       
   166 @param aScaleFactorHeight The height scale factor, in percent
       
   167 */
       
   168 	{
       
   169 	CPicture::SetScaleFactor(aScaleFactorWidth, aScaleFactorHeight);
       
   170 	}
       
   171 
       
   172 EXPORT_C void CApaDoorBase::SetCropInTwips(const TMargins& aMargins)
       
   173 /** Sets the cropping margins of a Embedded Document in twips.
       
   174 These are relative to the original unscaled size of the Embedded Document.
       
   175 
       
   176 @publishedAll 
       
   177 @released
       
   178 @param aMargins The cropping margins of the Embedded Document, in twips
       
   179 */	
       
   180 	{
       
   181 	CPicture::SetCropInTwips(aMargins);
       
   182 	}
       
   183 	
       
   184 EXPORT_C TPictureCapability CApaDoorBase::Capability() const
       
   185 /** Gets the Embedded Document's capabilities.
       
   186 These include whether it is scalable and croppable.
       
   187 
       
   188 @publishedAll 
       
   189 @released
       
   190 @return The capabilities of the Embedded Document
       
   191 */
       
   192 	{
       
   193 	return CPicture::Capability();
       
   194 	}
       
   195 	
       
   196 EXPORT_C void CApaDoorBase::GetCropInTwips(TMargins& aMargins) const 
       
   197 /** Gets the cropping margins of a Embedded Document in twips.
       
   198 These margins are relative to the original unscaled size of the Embedded Document.
       
   199 
       
   200 @publishedAll 
       
   201 @released
       
   202 @param aMargins The cropping margins of the Embedded Document, in twips 
       
   203 */
       
   204 	{
       
   205 	CPicture::GetCropInTwips(aMargins);
       
   206 	}
       
   207 
       
   208 EXPORT_C TInt CApaDoorBase::ScaleFactorWidth() const
       
   209 /** Gets the Embedded Document's width scale factor.
       
   210 
       
   211 @publishedAll 
       
   212 @released
       
   213 @return The width scale factor, in percent
       
   214 */	
       
   215 	{
       
   216 	return CPicture::ScaleFactorWidth();
       
   217 	}
       
   218 
       
   219 EXPORT_C TInt CApaDoorBase::ScaleFactorHeight() const
       
   220 /** Gets the Embedded Document height scale factor.
       
   221 
       
   222 @publishedAll 
       
   223 @released
       
   224 @return The height scale factor, in percent
       
   225 */
       
   226 	{
       
   227 	return CPicture::ScaleFactorHeight();
       
   228 	}
       
   229 
       
   230 EXPORT_C TBool CApaDoorBase::LineBreakPossible(TUint aClass,TBool aBeforePicture,TBool aHaveSpaces) const
       
   231 /** States whether a line break is possible, either before or after an Embedded Document.
       
   232 The default implementation returns ETrue, implying that there is a break opportunity both before and after the Embedded Document, whether or not a space is present.
       
   233 This may be overridden for special types of Embedded Documents.
       
   234 
       
   235 @publishedAll 
       
   236 @released
       
   237 @param aClass The line breaking class of the adjacent character
       
   238 @param aBeforePicture ETrue, if the adjacent character is before the Embedded Document; EFalse, if the adjacent character is afterwards
       
   239 @param aHaveSpaces ETrue, if spaces occur between the adjacent character and the Embedded Document; EFalse, otherwise
       
   240 @return ETrue, if a line break is possible; EFalse, otherwise. 
       
   241 */	
       
   242 	{
       
   243 	return CPicture::LineBreakPossible(aClass, aBeforePicture, aHaveSpaces);
       
   244 	}
       
   245 
       
   246 EXPORT_C TBool CApaDoorBase::NativePixelSize(TSize& aPixelSize)
       
   247 /** Returns the native pixel size of the bitmap. 
       
   248 
       
   249 Derived classes might be implemented as bitmaps, in that case it might be interesting to know this.
       
   250 @publishedAll 
       
   251 @released
       
   252 @param aPixelSize The pixel size
       
   253 @return TBool ETrue, if the derived classes are implemented as bitmaps; EFalse, otherwise.
       
   254 */	
       
   255 	{
       
   256 	return CPicture::NativePixelSize(aPixelSize);
       
   257 	}
       
   258 
       
   259 /** Reserved for future use */
       
   260 EXPORT_C void CApaDoorBase::CApaDoorBase_Reserved1()
       
   261 	{
       
   262 	}
       
   263 
       
   264 /** Reserved for future use */
       
   265 EXPORT_C void CApaDoorBase::CApaDoorBase_Reserved2()
       
   266 	{
       
   267 	}
       
   268 
       
   269 ///////////////////////////////////
       
   270 // TApaModelDoorFactory
    62 // TApaModelDoorFactory
   271 ///////////////////////////////////
    63 //
   272 
    64 
   273 EXPORT_C TApaModelDoorFactory::TApaModelDoorFactory(const MApaModelHeaderFactory* aFactory)
    65 EXPORT_C TApaModelDoorFactory::TApaModelDoorFactory(const MApaModelHeaderFactory* aFactory)
   274 	:iHeaderFactory(aFactory)
    66 	:iHeaderFactory(aFactory)
   275 /** Constructs a door factory object.
    67 /** Constructs a door factory object.
   276 
    68 
   308 	TStreamId id = aPictureHeader.iPicture.AsId();
   100 	TStreamId id = aPictureHeader.iPicture.AsId();
   309 	aPictureHeader.iPicture = CApaModelDoor::NewL(aPictureStore,id,iHeaderFactory);
   101 	aPictureHeader.iPicture = CApaModelDoor::NewL(aPictureStore,id,iHeaderFactory);
   310 	}
   102 	}
   311 
   103 
   312 
   104 
   313 ///////////////////////////////////
   105 //
   314 // CApaModelDoor
   106 // CApaModelDoor
   315 ///////////////////////////////////
   107 //
   316 
   108 
   317 
   109 
   318 EXPORT_C CApaModelDoor* CApaModelDoor::NewL(CApaModelHeader* aHeader)
   110 EXPORT_C CApaModelDoor* CApaModelDoor::NewL(CApaModelHeader* aHeader)
   319 /** Creates a model door object.
   111 /** Creates a model door object.
   320 
   112 
   362 	return self;
   154 	return self;
   363 	}
   155 	}
   364 
   156 
   365 
   157 
   366 CApaModelDoor::CApaModelDoor()
   158 CApaModelDoor::CApaModelDoor()
   367 	{__DECLARE_NAME(_S("CApaModelDoor"));}
   159 	{}
   368 
   160 
   369 
   161 
   370 CApaModelDoor::CApaModelDoor(CApaModelHeader* aHeader)
   162 CApaModelDoor::CApaModelDoor(CApaModelHeader* aHeader)
   371 	:iModelHeader(aHeader)
   163 	:iModelHeader(aHeader)
   372 	{}
   164 	{}