smsprotocols/smsstack/ems/src/EMSFormatIE.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 /*
       
     2 * Copyright (c) 2009 Sony Ericsson Mobile Communications AB
       
     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 * Sony Ericsson Mobile Communications AB - initial contribution.
       
    11 * Nokia Corporation - additional changes.
       
    12 * 
       
    13 * Contributors:
       
    14 * 
       
    15 * Description:
       
    16 * Implements the Enhanced SMS Format Information Element.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  *  @file
       
    23  *  
       
    24  *  Implements  CEmsFormatIE  class
       
    25  */
       
    26 
       
    27 #include <emsformatie.h>
       
    28 
       
    29 /**
       
    30  *  Creates a default ems format object.
       
    31  *  
       
    32  *  @return CEmsFormatIE* newly created object
       
    33  */
       
    34 EXPORT_C CEmsFormatIE* CEmsFormatIE::NewL()
       
    35 /**
       
    36  *  @capability None
       
    37  */
       
    38 	{
       
    39 	CEmsFormatIE* self = new (ELeave) CEmsFormatIE();
       
    40 	self->SetAlignment(ELangDepend);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 /**
       
    45  *  Creates an exact copy of the object.
       
    46  *  
       
    47  *  @return CEmsFormatIE* Newly created object.
       
    48  */
       
    49 EXPORT_C CEmsInformationElement* CEmsFormatIE::DuplicateL() const
       
    50 /**
       
    51  *  @capability None
       
    52  */
       
    53 	{
       
    54 	CEmsFormatIE* copy = new (ELeave) CEmsFormatIE();
       
    55 	CleanupStack::PushL(copy);
       
    56 	copy->CopyL(*this);
       
    57 	CleanupStack::Pop(copy);
       
    58 	return copy;
       
    59 	}
       
    60 
       
    61 EXPORT_C void CEmsFormatIE::SetBold(TBool aBold)
       
    62 /**
       
    63  *  @capability None
       
    64  */
       
    65 	{
       
    66 	iFormat=(TUint8)(aBold? iFormat|EBold: iFormat&(~EBold));
       
    67 	}
       
    68 
       
    69 EXPORT_C TBool CEmsFormatIE::Bold() const
       
    70 /**
       
    71  *  @capability None
       
    72  */
       
    73 	{
       
    74 	return (EBold&iFormat)?ETrue:EFalse;
       
    75 	}
       
    76 
       
    77 EXPORT_C void CEmsFormatIE::SetItalic(TBool aItalic)
       
    78 /**
       
    79  *  @capability None
       
    80  */
       
    81 	{
       
    82 	iFormat=(TUint8)(aItalic? iFormat|EItalic: iFormat&(~EItalic));
       
    83 	}
       
    84 
       
    85 EXPORT_C TBool CEmsFormatIE::Italic() const
       
    86 /**
       
    87  *  @capability None
       
    88  */
       
    89 	{
       
    90 	return (EItalic&iFormat)?ETrue:EFalse;
       
    91 	}
       
    92 
       
    93 EXPORT_C void CEmsFormatIE::SetUnderline(TBool aUnderline)
       
    94 /**
       
    95  *  @capability None
       
    96  */
       
    97 	{
       
    98 	iFormat=(TUint8)(aUnderline? iFormat|EUnderline: iFormat&(~EUnderline));
       
    99 	}
       
   100 
       
   101 EXPORT_C TBool CEmsFormatIE::Underline() const
       
   102 /**
       
   103  *  @capability None
       
   104  */
       
   105 	{
       
   106 	return (EUnderline&iFormat)?ETrue:EFalse;
       
   107 	}
       
   108 
       
   109 EXPORT_C void CEmsFormatIE::SetStrikethrough(TBool aStrikethrough)
       
   110 /**
       
   111  *  @capability None
       
   112  */
       
   113 	{
       
   114 	iFormat=(TUint8)(aStrikethrough? iFormat|EStrikethrough: iFormat&(~EStrikethrough));
       
   115 	}
       
   116 
       
   117 EXPORT_C TBool CEmsFormatIE::Strikethrough() const
       
   118 /**
       
   119  *  @capability None
       
   120  */
       
   121 	 {
       
   122 	return (EStrikethrough&iFormat)?ETrue:EFalse;
       
   123 	}
       
   124 
       
   125 EXPORT_C void CEmsFormatIE::SetAlignment(TAlignment aAlignment)
       
   126 /**
       
   127  *  @capability None
       
   128  */
       
   129 	{
       
   130 	iFormat=(TUint8)(iFormat&~EAlignmentMask);
       
   131 	iFormat=(TUint8)(iFormat|aAlignment);
       
   132 	}
       
   133 
       
   134 EXPORT_C CEmsFormatIE::TAlignment CEmsFormatIE::Alignment() const
       
   135 /**
       
   136  *  @capability None
       
   137  */
       
   138 	{
       
   139 	return (TAlignment)(EAlignmentMask&iFormat);
       
   140 	}
       
   141 
       
   142 EXPORT_C void CEmsFormatIE::SetFontSize(TFontSize aSize)
       
   143 /**
       
   144  *  @capability None
       
   145  */
       
   146 	{
       
   147 	iFormat=(TUint8)(iFormat&~EFontSizeMask);
       
   148 	iFormat=(TUint8)(iFormat|(aSize<<2));
       
   149 	}
       
   150 
       
   151 EXPORT_C CEmsFormatIE::TFontSize CEmsFormatIE::FontSize() const
       
   152 /**
       
   153  *  @capability None
       
   154  */
       
   155 	{
       
   156 	return (TFontSize)((EFontSizeMask&iFormat)>>2);
       
   157 	}
       
   158 
       
   159 
       
   160 EXPORT_C void  CEmsFormatIE::SetFormatLength(TUint aLength)
       
   161 /**
       
   162  *  @capability None
       
   163  */
       
   164 	{
       
   165 	iFormatLength = aLength;
       
   166 	}
       
   167 
       
   168 EXPORT_C TUint CEmsFormatIE::FormatLength() const
       
   169 /**
       
   170  *  @capability None
       
   171  */
       
   172 	{
       
   173 	return iFormatLength;
       
   174 	}
       
   175 
       
   176 
       
   177 CEmsFormatIE::CEmsFormatIE() :CEmsInformationElement(CSmsInformationElement::ESmsEnhancedTextFormatting),iFormat(0){iEncodedBodyLength=EEnhancedFormatSizeV4;}
       
   178 
       
   179 /**
       
   180  *  Encodes the format object into its raw format. (no IE id)
       
   181  *  
       
   182  *  @param aPtr the buffer to be used which is to contain the data
       
   183  *  @param aIsForSerialisation boolean to indicate if it is for serialisation or encoding
       
   184  */
       
   185 void CEmsFormatIE::EncodeBodyL(TPtr8 aPtr, TBool aIsForSerialisation) const
       
   186 	{
       
   187 	// This is the only information element which needs to check the
       
   188 	// aIsForSerialisation flag. If it is for PDU encoding, the
       
   189 	// length field is only 8 bits. Otherwise it is 16. (This is
       
   190 	// because format objects when inserted can extend over a PDU
       
   191 	// boundary, but are split on encoding)
       
   192 	if (aIsForSerialisation)
       
   193 		{
       
   194 		aPtr.Append(HI_BYTE(iFormatLength));
       
   195 		}
       
   196 
       
   197 	aPtr.Append(LO_BYTE(iFormatLength));
       
   198 	aPtr.Append(iFormat);
       
   199 	}
       
   200 
       
   201 /**
       
   202  *  Decodes the raw data out of an information element into this class.
       
   203  *  
       
   204  *  @param aPtr The raw predefined animation data
       
   205  *  @param aIsFromSerialisation boolean to indicate if it is from serialisation
       
   206  *  @leave KErrargument If the size of the data does not match what is expected.
       
   207  */
       
   208 void CEmsFormatIE::DecodeBodyL(const TPtrC8 aPtr, TBool aIsFromSerialisation)
       
   209 	{
       
   210 	__ASSERT_ALWAYS((aPtr.Length() >= EEnhancedFormatSizeV4), User::Leave(KErrArgument));
       
   211 
       
   212 	// index into byte array we are currently looking at
       
   213 	TInt pos = 0;
       
   214 	iFormatLength = 0;
       
   215 
       
   216 	if (aIsFromSerialisation)
       
   217 		{
       
   218 		iFormatLength = static_cast<TUint>(aPtr[pos] * 256);
       
   219 		++pos;
       
   220 		}
       
   221 	iFormatLength += static_cast<TUint>(aPtr[pos]);
       
   222 	++pos;
       
   223 	iFormat=aPtr[pos];
       
   224 	}
       
   225 
       
   226 TInt CEmsFormatIE::SerialisedBodyLength() const
       
   227 	{
       
   228 	// extra byte required for 16-bit length field when serialised
       
   229 	return iEncodedBodyLength + 1;
       
   230 	}
       
   231 
       
   232 EXPORT_C void CEmsFormatIE::CopyL(const CEmsFormatIE& aSrc)
       
   233 /**
       
   234  *  @capability None
       
   235  */
       
   236 	{
       
   237 	CEmsInformationElement::CopyL(aSrc);
       
   238 	iFormatLength = aSrc.iFormatLength;
       
   239 	iFormat=aSrc.iFormat;
       
   240 	}