layouts/aknlayout2/src/AknLayout2Adaptation.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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 "AknLayout2AdaptationDataDef.h"
       
    20 #include <CdlEngine.h>
       
    21 
       
    22 #define AKNLAYOUT_DEFINE_BYTECODE(name,byte) const TUint8 name = byte;
       
    23 #include "AknLayoutByteCodes.h"
       
    24 
       
    25 enum TLayoutPanic
       
    26 	{
       
    27 	ENegativeOffset,
       
    28 	EOffsetOutOfRange,
       
    29 	EIllegalLineIndex,
       
    30 	EMultiLineOffsetOutOfRange,
       
    31 	EDecodeNotSupported
       
    32 	};
       
    33 
       
    34 void Panic(TLayoutPanic aCode)
       
    35 	{
       
    36 	_LIT(KLayoutPanic, "Layout panic");
       
    37 	User::Panic(KLayoutPanic, aCode);
       
    38 	}
       
    39 
       
    40 // local functions
       
    41 
       
    42 
       
    43 //
       
    44 // class AknLayoutAdaptationDecodeSupport
       
    45 //
       
    46 
       
    47 TUint16 AknLayoutAdaptationDecodeSupport::DecodeBytes(const TUint8*& aPtr)
       
    48 	{
       
    49 	TUint8 ch = *aPtr++;
       
    50 	switch (ch)
       
    51 		{
       
    52 		case KByteWord:
       
    53 			{
       
    54 			TUint16 high = *aPtr++;
       
    55 			TUint16 low = *aPtr++;
       
    56 			return TUint16((high<<8) | low);
       
    57 			}
       
    58 		case KByteEmpty:
       
    59 			return TUint16(ELayoutEmpty);
       
    60 		case KByteP1:
       
    61 			{
       
    62 			TInt8 offset = *aPtr++;
       
    63 			return TUint16(p+offset);
       
    64 			}
       
    65 		case KByteP2:
       
    66 			{
       
    67 			TInt16 high = *aPtr++;
       
    68 			TUint16 low = *aPtr++;
       
    69 			return TUint16(p+((high<<8) | low));
       
    70 			}
       
    71 		default:
       
    72 			return ch;
       
    73 		}
       
    74 	}
       
    75 
       
    76 const TUint* AknLayoutAdaptationDecodeSupport::DecodeTable(const TUint* aDataLookup, TInt aLineIndex)
       
    77 	{
       
    78 	const TUint* pApiId = aDataLookup + CdlEngine::LastApiId();
       
    79 	const TUint8* pLimits = (const TUint8*)(pApiId-1);
       
    80 	__ASSERT_ALWAYS(pLimits[1] <= aLineIndex && aLineIndex <= pLimits[0], Panic(EIllegalLineIndex));
       
    81 	return (TUint*)aDataLookup[(*pApiId) + aLineIndex];
       
    82 	}
       
    83 
       
    84 const TUint8* AknLayoutAdaptationDecodeSupport::DataPtr(const SImplData* aImplData)
       
    85 	{
       
    86 	return aImplData->iByteCodedData + aImplData->iDataLookup[CdlEngine::LastApiId()];
       
    87 	}
       
    88 
       
    89 void AknLayoutAdaptationDecodeSupport::DecodeMultiLineTextLine(
       
    90 	TAknTextLineLayout& aLine, const TUint* aDataLookup, const TUint8* aMultiInfo, TInt aNumParams, TInt aIndex1, TInt aIndex2, TInt aIndex3, TInt aIndex4, TInt aIndex_B)
       
    91     {
       
    92     // insert our desired index_B into the correct place
       
    93     TInt numberOfLines = DecodeNumberOfLinesShown(aMultiInfo, aIndex1, aIndex2, aIndex3, aIndex4, aIndex_B);
       
    94 	
       
    95     // now just call straight through to the adaptation layer
       
    96     switch(aNumParams)
       
    97 	    {
       
    98 	    case 0:	{aLine = ((TextLine0f_sig*)aDataLookup)(); break;}
       
    99 	    case 1:	{aLine = ((TextLine1f_sig*)aDataLookup)(aIndex1); break;}
       
   100 	    case 2:	{aLine = ((TextLine2f_sig*)aDataLookup)(aIndex1, aIndex2); break;}
       
   101 	    case 3:	{aLine = ((TextLine3f_sig*)aDataLookup)(aIndex1, aIndex2, aIndex3); break;}
       
   102         }
       
   103 
       
   104     aLine.iNumberOfLinesShown = numberOfLines;
       
   105     }
       
   106 
       
   107 
       
   108 TInt AknLayoutAdaptationDecodeSupport::DecodeNumberOfLinesShown(
       
   109 	const TUint8* aParamPtr, TInt& aIndex1, TInt& aIndex2, TInt& aIndex3, TInt& aIndex4, TInt aIndex_B)
       
   110 	{
       
   111 	// For multiline APIs, the parameter order may be changed
       
   112 	TInt numberOfLinesShownParamNumber = aParamPtr[0];
       
   113 	TInt numberOfLinesShown;
       
   114 	switch (numberOfLinesShownParamNumber)
       
   115 		{
       
   116 		case 0:
       
   117 			numberOfLinesShown = aIndex1;
       
   118 			break;
       
   119 		case 1:
       
   120 			numberOfLinesShown = aIndex2;
       
   121 			break;
       
   122 		case 2:
       
   123 			numberOfLinesShown = aIndex3;
       
   124 			break;
       
   125 		default:
       
   126 			numberOfLinesShown = aIndex4;
       
   127 			break;
       
   128 		}
       
   129 
       
   130 	// index_B will have been removed from the multiline API, so insert desired index_B where it
       
   131 	// would have been, and shift up the other parameters.
       
   132 	TInt indexBParamNumber = aParamPtr[1];
       
   133 	switch (indexBParamNumber)
       
   134 		{
       
   135 		case 0:
       
   136 			aIndex4 = aIndex3;
       
   137 			aIndex3 = aIndex2;
       
   138 			aIndex2 = aIndex1;
       
   139 			aIndex1 = aIndex_B;
       
   140 			break;
       
   141 		case 1:
       
   142 			aIndex4 = aIndex3;
       
   143 			aIndex3 = aIndex2;
       
   144 			aIndex2 = aIndex_B;
       
   145 			break;
       
   146 		case 2:
       
   147 			aIndex4 = aIndex3;
       
   148 			aIndex3 = aIndex_B;
       
   149 			break;
       
   150 		case 3:
       
   151 			aIndex4 = aIndex_B;
       
   152 			break;
       
   153 		default:
       
   154 			break;
       
   155 		}
       
   156 
       
   157 	return numberOfLinesShown;
       
   158 	}
       
   159 
       
   160 EXPORT_C void AknLayoutAdaptationDecodeSupport::MultiLineTextLine(
       
   161 	TAknTextLineLayout& aLine, const TUint* aDataLookup, TInt aNumParams, TInt aIndex1, TInt aIndex2, TInt aIndex3, TInt aIndex4)
       
   162 	{
       
   163 	TInt lastApiId = CdlEngine::LastApiId();
       
   164 	const TUint8* pMultiInfo = (const TUint8*)(aDataLookup + lastApiId);
       
   165     const TUint* data = (TUint*)aDataLookup[lastApiId - 1];
       
   166 
       
   167     // use index_B = 0 for our return value
       
   168     // and use index_B = 1 to calculate baseline skip
       
   169     TAknTextLineLayout line1;
       
   170     DecodeMultiLineTextLine(aLine, data, pMultiInfo, aNumParams, aIndex1, aIndex2, aIndex3, aIndex4, 0);
       
   171     DecodeMultiLineTextLine(line1, data, pMultiInfo, aNumParams, aIndex1, aIndex2, aIndex3, aIndex4, 1);
       
   172 
       
   173 	aLine.iBaselineSkip = aLine.iB - line1.iB;
       
   174 	}
       
   175 
       
   176 
       
   177 EXPORT_C void AknLayoutAdaptationDecodeSupport::MultiLineTextLine(
       
   178 	TAknTextLineLayout& /*aLine*/, const TUint* /*aDataLookup*/, const TRect& /*aRect*/, TInt /*aNumParams*/, TInt /*aIndex1*/, TInt /*aIndex2*/, TInt /*aIndex3*/, TInt /*aIndex4*/)
       
   179 	{
       
   180 	// no requirements for multiline texts that take a parent rect
       
   181 	Panic(EDecodeNotSupported);
       
   182 	}
       
   183 
       
   184 EXPORT_C void AknLayoutAdaptationDecodeSupport::WindowTable(
       
   185 	TAknWindowLineLayout& aLine, const TUint* aDataLookup, TInt aLineIndex, TInt aNumParams, TInt aIndex1, TInt aIndex2, TInt aIndex3, TInt /*aIndex4*/)
       
   186 	{
       
   187 	const TUint* data = DecodeTable(aDataLookup, aLineIndex);
       
   188 	switch(aNumParams)
       
   189 		{
       
   190 		case 0:	{aLine = ((WindowLine0f_sig*)data)(); break;}
       
   191 		case 1:	{aLine = ((WindowLine1f_sig*)data)(aIndex1); break;}
       
   192 		case 2: {aLine = ((WindowLine2f_sig*)data)(aIndex1, aIndex2); break;}
       
   193 		case 3: {aLine = ((WindowLine3f_sig*)data)(aIndex1, aIndex2, aIndex3); break;}
       
   194 		case 4: {/*aLine = ((WindowLine4f_sig*)data)(aIndex1, aIndex2, aIndex3, aIndex4);*/ Panic(EDecodeNotSupported); break;}
       
   195 		}
       
   196 	}
       
   197 
       
   198 EXPORT_C void AknLayoutAdaptationDecodeSupport::WindowTable(
       
   199 	TAknWindowLineLayout& aLine, const TUint* aDataLookup, TInt aLineIndex, const TRect& aRect, TInt aNumParams, TInt aIndex1, TInt aIndex2, TInt aIndex3, TInt /*aIndex4*/)
       
   200 	{
       
   201 	const TUint* data = DecodeTable(aDataLookup, aLineIndex);
       
   202 	switch(aNumParams)
       
   203 		{
       
   204 		case 0:	{aLine = ((WindowLine0t_sig*)data)(aRect); break;}
       
   205 		case 1:	{aLine = ((WindowLine1t_sig*)data)(aRect, aIndex1); break;}
       
   206 		case 2:	{aLine = ((WindowLine2t_sig*)data)(aRect, aIndex1, aIndex2); break;}
       
   207 		case 3: {aLine = ((WindowLine3t_sig*)data)(aRect, aIndex1, aIndex2, aIndex3); break;}
       
   208 		case 4:	{/*aLine = ((WindowLine4t_sig*)data)(aRect, aIndex1, aIndex2, aIndex3, aIndex4);*/ Panic(EDecodeNotSupported); break;}
       
   209 		}
       
   210 	}
       
   211 
       
   212 EXPORT_C void AknLayoutAdaptationDecodeSupport::TextTable(
       
   213 	TAknTextLineLayout& aLine, const TUint* aDataLookup, TInt aLineIndex, TInt aNumParams, TInt aIndex1, TInt aIndex2, TInt aIndex3, TInt aIndex4)
       
   214 	{
       
   215 	const TUint* data = DecodeTable(aDataLookup, aLineIndex);
       
   216 	switch(aNumParams)
       
   217 		{
       
   218 		case 0:	{aLine = ((TextLine0f_sig*)data)(); break;}
       
   219 		case 1:	{aLine = ((TextLine1f_sig*)data)(aIndex1); break;}
       
   220 		case 2: {aLine = ((TextLine2f_sig*)data)(aIndex1, aIndex2); break;}
       
   221 		case 3: {aLine = ((TextLine3f_sig*)data)(aIndex1, aIndex2, aIndex3); break;}
       
   222 		case 4: {aLine = ((TextLine4f_sig*)data)(aIndex1, aIndex2, aIndex3, aIndex4); break;}
       
   223 		}
       
   224 	}
       
   225 
       
   226 EXPORT_C void AknLayoutAdaptationDecodeSupport::TextTable(
       
   227 	TAknTextLineLayout& /*aLine*/, const TUint* /*aDataLookup*/, TInt /*aLineIndex*/, const TRect& /*aRect*/, TInt /*aNumParams*/, TInt /*aIndex1*/, TInt /*aIndex2*/, TInt /*aIndex3*/, TInt /*aIndex4*/)
       
   228 	{
       
   229 	// no requirements for text tables that take a parent rect
       
   230 	Panic(EDecodeNotSupported);
       
   231 	}
       
   232 
       
   233 EXPORT_C TAknLayoutTableLimits AknLayoutAdaptationDecodeSupport::TableLimits(const TUint* aDataLookup)
       
   234 	{
       
   235 	TUint8* encoded = (TUint8*)(aDataLookup + CdlEngine::LastApiId());
       
   236 	TAknLayoutTableLimits limits = { encoded[1], encoded[0] };
       
   237 	return limits;
       
   238 	}