# HG changeset patch # User Dremov Kirill (Nokia-D-MSW/Tampere) # Date 1261034058 -7200 # Node ID f58d6ec98e8817d13218ec1ef2b178c3c36b4f8c Revision: 200949 Kit: 200951 diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/binary/AknLayoutCompiler.exe Binary file aknlayoutcompiler/binary/AknLayoutCompiler.exe has changed diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/cdl/MasterLayoutPack.cdl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/cdl/MasterLayoutPack.cdl Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,17 @@ +// MasterLayoutPack.cdl - Acts as a layout index for a whole layout DLL. + +Name: MasterLayoutPack +Version: 1.0 +UID: 0x101feb1b + +%% C++ + +#include +#include + +%% API + +TCdlArray sizes; +TCdlArray variants; +TCdlArray zooms; +TCdlArray*> contents; diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/group/AknLayoutCompiler.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/group/AknLayoutCompiler.mmp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,106 @@ +/* +* Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include + +TARGET AknLayoutCompiler.exe +TARGETTYPE EXE + +SYSTEMINCLUDE . +SYSTEMINCLUDE ../inc +SYSTEMINCLUDE ../../inc +SYSTEMINCLUDE ../../inc/arabica + +MW_LAYER_SYSTEMINCLUDE + +// These options enable exception handling and set the warning level to 3 for command +// line builds. STL code generates too many warnings at level 4, but is clean at +// level 3. Also require RTTI. +option MSVC /GX /W3 /GR + +SOURCEPATH ../src + +source CppWriter.cpp +source Extract.cpp +source HtmlParse.cpp +source Layout.cpp +source AknLayoutCompiler.cpp +source LayoutCompilerErr.cpp +source LayoutParse.cpp +source LayoutWriter.cpp +source WriterBase.cpp +source Lay2Cdl.cpp +source Cdl2Lag.cpp +source LayCdl2Inst.cpp +source LayCdlCheck.cpp +source LayoutPack.cpp +source LayCdl2InstO.cpp +source MakeLayConvTest.cpp +source LayScale.cpp +source AdaptationLayerTemplate.cpp +source Lay2LayPerf.cpp +source LayPerfWriter.cpp +source coreparser.cpp +source formulaparser.cpp +source formulatree.cpp + +#ifdef RD_XML_PARSER_TOOLCHAIN +source SaxErrorHandler.cpp +source MLCompData.cpp +source MLCompDataParse.cpp +source MLCompData2Cdl.cpp +source MLCompCdl2InstO.cpp +source MLAttributes.cpp +source MLAttributesParse.cpp +source MLCompData2LayPerf.cpp +source MLCompDataLayPerfWriter.cpp +source MLEqCompData.cpp +source MLEqCompDataParse.cpp +source MLEqCompData2DHuiML.cpp +#endif + +source ZoomLevelNames.cpp +source MasterLayoutPack.cpp + +#ifndef SBSV2 + start CW32 + win32_library /epoc32/release/cwtools/rel/CdlCompilerToolkit.lib + end + + start VC32 + win32_library /epoc32/release/tools/rel/CdlCompilerToolkit.lib + end +#else + START TOOLS + #if defined(CW32) + win32_library /epoc32/release/cwtools/rel/CdlCompilerToolkit.lib + #elif defined(VC32) + win32_library /epoc32/release/tools/rel/CdlCompilerToolkit.lib + #endif + END +#endif + +start TOOLS +#ifdef RD_XML_PARSER_TOOLCHAIN +win32_library /epoc32/release/tools/rel/Arabica.lib +win32_library /epoc32/release/tools/rel/xerces-c_2.lib +#endif +win32_library Advapi32.lib +end + + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/group/bld.inf Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Build information file for project AknLayoutCompiler +* +*/ + + +#include + +PRJ_PLATFORMS +TOOLS CWTOOLS + +PRJ_EXPORTS + +../binary/AknLayoutCompiler.exe /epoc32/tools/AknLayoutCompiler.exe + +PRJ_MMPFILES + +#if defined(TOOLS) || defined(CWTOOLS) + +/* + * NOTICE! AknLayoutCompiler is not compiled any more during usual build. + * It is just exported from ../binary directory. + * If you really want compile AknLayoutCompiler from sources you need to + * uncomment below line, build this project and copy + * /epoc32/tools/AknLayoutCompiler.exe to ../binary directory and + * put the binary to version control. + */ +// AknLayoutCompiler.mmp + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/AdaptationLayerTemplate.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/AdaptationLayerTemplate.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef ADAPTATIONLAYERTEMPLATE_H +#define ADAPTATIONLAYERTEMPLATE_H + +#include +#include +#include +#include "Layout.h" +using namespace std; + +#include +#include +#include +using namespace CdlCompilerToolkit; + + +class AdaptationLayerTemplate : public CCdlTkSourceFileWriter + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + ~AdaptationLayerTemplate(); + +private: + AdaptationLayerTemplate(TLayout& aLayout, CCdlTkInterface& aLayIface, CCdlTkInterface& aScaleIface, CCdlTkInstance& aInstance, string& aExisting); + + CCdlTkInstance& Instance(); + string FwdDeclName(); + void Process(); + +private: + void AddTableToInstance(TLayoutTable& aTable); + void AddLineToInstance(TLayoutLine& aLine); + bool HasApi(const string& aName); + CCdlTkImplementation& FindImp(const string& aName); + void SetFuncLine(CCdlTkImplementation& aImp, TLayoutLine& aLine); + pair GetApiMatch(const string& aName); + +private: + CCdlTkInterface& iLayIface; + CCdlTkInterface& iScaleIface; + TLayout& iLayout; + CCdlTkInstance& iInstance; + string& iExisting; + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/Cdl2Lag.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/Cdl2Lag.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef CDL2LAG_H +#define CDL2LAG_H + +#include +#include +#include +#include +using namespace CdlCompilerToolkit; +using namespace std; + +/** +* CdlToLag +* Generates a LAG file macro API to access a CDL API +*/ +class CdlToLag + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + +private: + CdlToLag(ofstream& aLag, const string& aLagName); + + void Start(); + void AddInterface(CCdlTkInterface& aInterface); + void Finish(); + + void WriteHeader(); + void WriteMacro(CCdlTkApi& aApi); + void WriteFooter(); + void WriteInclude(); + +private: + ofstream& iLag; + string iLagName; + CCdlTkInterface* iInterface; + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/CodeGenConsts.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/CodeGenConsts.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,89 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef CODEGENCONSTS_H +#define CODEGENCONSTS_H + +#include +using namespace std; + +// includes +const string KIncludeLayoutInstanceHeaderScalableDef("#include "); +// directories +const string KDirEpocSysHeader("\\epoc32\\include\\"); +const string KDirDomainSysHeader("\\epoc32\\include\\platform\\mw\\"); + +// parameter namesy +const string KParamNameBase("aIndex_"); +const string KParamNameB(KParamNameBase + "B"); +const string KParamNameL(KParamNameBase + "l"); +const string KParamNameR(KParamNameBase + "r"); +const string KParamNameNumberOfLinesShown("aNumberOfLinesShown"); +const string KParamParentRect("aParentRect"); +const string KParamLineIndex("aLineIndex"); +const string KParamComponentId("aComponentId"); +const string KParamOptionIndex("aVariety"); +const string KParamRowIndex("aRow"); +const string KParamColIndex("aCol"); + +// types +const string KTypeTextLineLayout("TAknTextLineLayout"); +const string KTypeWindowLineLayout("TAknWindowLineLayout"); +const string KTypeLayoutTableLimits("TAknLayoutTableLimits"); +const string KTypeMultiLineTextLayout("TAknMultiLineTextLayout"); +const string KTypeRect("const TRect&"); +const string KTypeInt("TInt"); + +const string KTypeScreenComponentLayout("TAknScreenComponentLayout"); +const string KTypeContainerComponentLayout("TAknContainerComponentLayout"); +const string KTypePaneComponentLayout("TAknPaneComponentLayout"); +const string KTypeGraphicComponentLayout("TAknGraphicComponentLayout"); + +const string KTypeWindowComponentLayout("TAknWindowComponentLayout"); +const string KTypeTextComponentLayout("TAknTextComponentLayout"); +const string KTypeComponentTableLimits("TAknComponentTableLimits"); + +const string KTypeLayoutScalableTableLimits("TAknLayoutScalableTableLimits"); +const string KTypeLayoutScalableParameterLimits("TAknLayoutScalableParameterLimits"); + +const string KTypeLayoutScalableComponentType("TAknLayoutScalableComponentType"); + +// function names +const string KFuncMultiline("Multiline_"); +const string KFuncLimitsSuffix("_Limits"); +const string KFuncParamLimitsSuffix("_ParamLimits"); + +const string KFuncWindowLine("WindowLine"); +const string KFuncTextLine("TextLine"); +const string KFuncWindowTable("WindowTable"); +const string KFuncTextTable("TextTable"); +const string KFuncTableLimits("TableLimits"); +const string KFuncParamLimits("ParameterLimits"); +const string KFuncParamLimitsTable("ParameterLimitsTable"); + +const string KFuncGetComponentTypeById("GetComponentTypeById"); +const string KFuncGetParamLimitsById("GetParamLimitsById"); +const string KFuncGetWindowComponentById("GetWindowComponentById"); +const string KFuncGetTextComponentById("GetTextComponentById"); + + +// zoom +const string KDefaultZoomInstanceName("Normal"); + + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/CoreParser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/CoreParser.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,125 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#ifndef COREPARSER_H +#define COREPARSER_H + +#include +#include +#include + +class Parser; + +class ParseResult + { +public: + ParseResult(); + static ParseResult Fail(); + + bool Matched() const; + +public: + int iRuleId; + int iStart; + int iEnd; + std::deque iChildren; + }; + + +class Parser + { +public: + Parser(const char* aMatch); + static Parser EOS(); + static Parser Int(); + static Parser Real(); + static const Parser& Nul(); + + ParseResult Parse(const std::string& aString) const; + + int Id() const; + void SetId(int aId); + + Parser(); + Parser(const Parser& aOther); + ~Parser(); + const Parser& operator=(const Parser& aOther); + +private: + friend Parser operator|(const Parser& aFirst, const Parser& aRest); + friend Parser operator>>(const Parser& aFirst, const Parser& aRest); + friend Parser operator*(const Parser& aSub); + + enum T0Op + { + EExact, + EEos, + EInt, + EReal, + ENul, + ELast0 + }; + enum T1Op + { + EMult = ELast0, + ELast1 + }; + enum T2Op + { + ESeq = ELast1, + EAlt + }; + + Parser(T0Op aOp); + Parser(T1Op aOp, const Parser& aSub); + Parser(T2Op aOp, const Parser& aFirst, const Parser& aRest); + + struct Step + { + Step(const Parser* aRule, int aPos, int aParent) + : iRule(aRule), iStep(0), iPos(aPos), iParent(aParent) + { + iResult.iStart = aPos; + } + const Parser* iRule; + int iStep; + ParseResult iResult; + int iPos; + int iParent; + }; + + enum TMatchRes + { + EFail, + EPass, + EContinue + }; + + TMatchRes ParseStep(int aStep, const std::string& aString, int aPos, std::vector& aStack) const; + +private: + int iOp; + const char* iMatch; + const Parser* iSub1; + const Parser* iSub2; + int iId; + }; + +Parser operator|(const Parser& aFirst, const Parser& aRest); +Parser operator>>(const Parser& aFirst, const Parser& aRest); +//Parser operator*(const Parser& aSub); + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/CppWriter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/CppWriter.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,192 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef CPPWRITER_H +#define CPPWRITER_H + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) +#include +#include +#include +#include "WriterBase.h" +using namespace std; + + + + +/** +* TValuesCppWriter +* Write out layout cell values for AknLayout.dll +*/ +class TValuesCppWriter + { +public: + TValuesCppWriter(TValues& aValues) : iValues(aValues) {} + void WriteCpp(ostream& aCpp); + +private: + TValues& iValues; + }; + + +/** +* TLayoutLineCppWriter +* Base class for writing out a layout line for AknLayout.dll +*/ +class TLayoutLineCppWriter + { +public: + TLayoutLineCppWriter(TLayoutLine& aLine) : iLine(aLine) {} + void WriteCpp(ostream& aCpp); + virtual string Name()=0; + virtual void WriteMacro(ostream& aLag) = 0; + virtual void FillParamLists(vector& aDef, vector& aCtor) = 0; + + void WriteCppData(ostream& aCpp); + int WriteParamList(ostream& aLag, const vector& aParams); + +protected: + virtual void WriteLineClassName(ostream& aCpp) = 0; + virtual void WriteVarCppData(ostream& aCpp) = 0; + virtual void WriteFixedCppData(ostream& aCpp) = 0; + + int ValCount(); + +protected: + TLayoutLine& iLine; + }; + +/** +* TWindowLineCppWriter +* Write out a window line for AknLayout.dll +*/ +class TWindowLineCppWriter : public TLayoutLineCppWriter + { +public: + TWindowLineCppWriter(TLayoutLine& aLine) : TLayoutLineCppWriter(aLine) {} + void WriteMacro(ostream& aLag); + string Name(); + void FillParamLists(vector& aDef, vector& aCtor); + +private: + void WriteVarCppData(ostream& aCpp); + void WriteFixedCppData(ostream& aCpp); + void WriteLineClassName(ostream& aCpp); + }; + +/** +* TTextLineCppWriter +* Write out a text line for AknLayout.dll +*/ +class TTextLineCppWriter : public TLayoutLineCppWriter + { +public: + TTextLineCppWriter(TLayoutLine& aLine) : TLayoutLineCppWriter(aLine) {} + void WriteMacro(ostream& aLag); + string Name(); + void FillParamLists(vector& aDef, vector& aCtor); + +private: + void WriteVarCppData(ostream& aCpp); + void WriteFixedCppData(ostream& aCpp); + void WriteLineClassName(ostream& aCpp); + + // Specific to text + void WriteMultiLineTextParamList(ostream& aLag, const vector& aParams); + +private: + bool iBaseLineVariation; + }; + + +/** +* TLayoutTableCppWriter +* Write out a layout table for AknLayout.dll +*/ +class TLayoutTableCppWriter + { +public: + TLayoutTableCppWriter(TLayoutTable& aTable) : iTable(aTable) {} + void WriteCppLineData(ostream& aCpp); + void WriteCppTableData(ostream& aCpp); + void WriteLag(ostream& aLag); + void WriteLagSubTable(const TLayoutTable::TLayoutSubTable& aSubTable, int aCount, ostream& aLag); + static TLayoutLineCppWriter* CreateLayoutLineCppWriter(TLayoutLine& aData, TLayoutTable& iTable); + +private: + TLayoutTable& iTable; + }; + + +/** +* TLayoutCppWriter +* Write out a layout for AknLayout.dll +*/ +class TLayoutCppWriter + { +public: + TLayoutCppWriter(TLayout& aLayout) : iLayout(aLayout) {} + void WriteCppLineData(ostream& aCpp); + void WriteCppTableData(ostream& aCpp); + void WriteLag(ostream& aLag); + +private: + TLayout& iLayout; + }; + + +/** +* TLayoutLineTable +* Represents and writes a table of layout lines for AknLayout.dll +*/ +class TLayoutLineTable : public vector + { +public: + void WriteCpp(ostream& aCpp); + void WriteLag(ostream& aLag); + }; + + +/** +* TCppWriter +* Write the source code for AknLayout.dll +*/ +class TCppWriter : public TLayWriterBase + { +public: + TCppWriter(TLayout& aLayout, const std::string& aName); + void Write(const std::string& aLayName); + +private: + void Output(const string& aCpp, const string& aLag, const string& aLayName); + + void WriteCppHeader(ostream& aCpp); + void WriteCppFooter(ostream& aCpp, const string& aLayName); + void WriteLagHeader(ostream& aLag); + + void BuildLayoutLineTable(); + +private: + TLayoutLineTable iLineTable; + string iShortName; + }; + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/Extract.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/Extract.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef EXTRACT_H +#define EXTRACT_H + +#include +#include +#include +using namespace std; + +/** +* LayoutExtract +* Layout compiler process for extracting a layout from an HTML file +*/ +class LayoutExtract + { +public: + int Extract(const vector& args); + static void ShowHelp(ostream& stream); + +private: + void ParseArgs(const vector& args); + +private: + string iDocName; + string iLayoutName; + string iMergeName; + }; + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/FormulaParser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/FormulaParser.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef FORMULA_PARSER_H +#define FORMULA_PARSER_H + +#include +#include +#include "coreParser.h" +using namespace std; + +enum TFormulaParserIds + { + cell_name_ParserId=1, + parent_ParserId, + parent_cell_ParserId, + table_cell_ParserId, + comp_cell_ParserId, + abs_cell_ParserId, + units_ParserId, + constant_ParserId, + attribute_ParserId, + mystery_ParserId, + func_ParserId, + group_ParserId, + term_ParserId, + expression_ParserId, + comp_group_ParserId, + comp_ParserId, + conditional_ParserId, + }; + +ParseResult ParseFormula(const string& aFormula); + +#endif \ No newline at end of file diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/FormulaTree.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/FormulaTree.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,83 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#ifndef FORMULATREE_H +#define FORMULATREE_H + +#include +#include +using namespace std; + +class ParseResult; + +class FormulaTreeNode + { +public: + enum TNodeType + { + EReal=1, // Real() = the number + EInt, // Int() = the number + ECell, // Char() = cell name + EParent, // nothing special + EParentCell, // Char() = parent cell name + ETableCell, // Real() = target table + EComponent, // Real() = component id, [0] = cell name + EAbsolute, // Text() = whole thing, [0], [1] = real components, [2] = cell name + EUnits, // Real() = units + EConstant, // Real() = constant + EAttribute, // Int() = attribute + EMystery, // Text() = whole thing, [0], [1] = int components + EFunction, // Text() = function name, [0] = parameter + EArithmetic, // Char() = arithmetic operator, [0], [1] = sub expressions + ECondition, // Text() = comparison operator, [0], [1] = sub expressions + EConditional // no content, [0] = condition, [1] = then expression, [2] = else expression + }; + +public: + static FormulaTreeNode* Parse(const string& aFormula); + virtual ~FormulaTreeNode(); + + int Size() const; + FormulaTreeNode& operator[](int aIndex); + const FormulaTreeNode& operator[](int aIndex) const; + + TNodeType Type() const; + + string Text() const; + char Char() const; + int Int() const; + double Real() const; + + FormulaTreeNode(const FormulaTreeNode& aOther); + static void Print(const FormulaTreeNode& aNode); + +private: + FormulaTreeNode(TNodeType aType, const string& aSource, int aStart, int aLen); + static FormulaTreeNode* NewTree(const ParseResult& aParse, const string& aFormula); + const FormulaTreeNode& operator=(const FormulaTreeNode& aOther); + +public: + vector iSubNodes; + +private: + const string& iSource; + int iStart; + int iLen; + TNodeType iType; + }; + + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/HtmlParse.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/HtmlParse.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef HTMLPARSE_H +#define HTMLPARSE_H + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) +#include +#include +#include +#include "layout.h" +using namespace std; + +/** +* THtmlParseLayoutTable +* Parse a layout table from an HTML version of a LAF spec +*/ +class THtmlParseLayoutTable : public TLayoutTable + { +private: + typedef vector Row; + +public: + THtmlParseLayoutTable(TLayout* aTables); + ~THtmlParseLayoutTable(); + + bool Read(istream& in); + +private: + bool SearchForTableStart(); + void ExtractTitle(const string& aText); + void ExtractTable(); + + string Next(); + bool IsToken(const string& aText); + void PutBack(const string& aText); + char Get(); + void PutBack(char aChar); + bool Eof(); + + int GetVal(const string& aText, const string& aField); + + bool IsWindowTable(); + bool IsTextTable(); + + string StripTo(const string& aText, const string& aValid); + string UnHtml(const string& aText); + char HtmlChar(const string& aText); + string CleanMultiCell(const string& aText); + Row MakeParamTable(const Row& row, int start, int num); + string ConvertToAknName(const string& aText); + string SplitMultiCell(const string& aCell, const string& aValid); + string CleanCell(const string& cell, const Row& row); + + void AddRow(Row& row); + void AddColumnNameRow(Row& row); + void AddLineRow(const Row& row); + void AddTitleRow(const Row& row); + +private: + istream* iIn; + string iPutBack; + }; + + +/** +* THtmlParseLayout +* Parse the entire layout from an HTML version of a LAF spec +*/ +class THtmlParseLayout : public TLayout + { +public: + void Parse(istream &aIn); + }; + + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/Lay2Cdl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/Lay2Cdl.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef LAY2CDL_H +#define LAY2CDL_H + +#include +#include +#include +#include "Layout.h" +using namespace std; + +#include +using namespace CdlCompilerToolkit; + + +/** +* LayoutToCdl +* Generate a CDL interface for a layout +*/ +class LayoutToCdl + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + static auto_ptr LayoutToInterface(const TLayout& aLayout); + static void AddTableToInterface(CCdlTkInterface& aInterface, TLayoutTable& aTable); + static void AddWindowLineToInterface(CCdlTkInterface& aInterface, TLayoutLine& aLine); + static void AddTextLineToInterface(CCdlTkInterface& aInterface, TLayoutLine& aLine); + static string TableApiName(TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum); + static string LineApiName(TLayoutLine& aLine); + static void AddTableLimitsToInterface(CCdlTkInterface& aInterface, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum); + static void AddSubTableToInterface(const string& aType, CCdlTkInterface& aInterface, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum); + static void AddParamsToFunc(TLayoutLine& aLine, CCdlTkFunctionApi& aFunc); + static string InterfaceName(const string& aFileName); + static void SetHeaders(CCdlTkInterface& aInterface, const string& aCdlName, int aUid); +private: + static CCdlTkApi* CreateGenericApi(CCdlTkInterface& aInterface, TLayoutLine& aLine); + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/Lay2LayPerf.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/Lay2LayPerf.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef LAY2LAYPERF_H +#define LAY2LAYPERF_H + +#include +#include +#include +#include "Layout.h" +using namespace std; + +#include +using namespace CdlCompilerToolkit; + + +/** +* LayoutToLayPerf +* Compiler mode for rescaling a layout +*/ +class LayoutToLayPerf + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + static string InterfaceName(const string& aFileName); + +private: + LayoutToLayPerf(const string& aCdlName, TLayout& aSourceLayout, const string& aDestLayoutName); + void WriteLayout(); + +private: + TLayout& iLayout; + string iDestLayoutName; + string iCdlName; + }; + + +#endif // LAY2LAYPERF_H diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/Lay2MLInst.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/Lay2MLInst.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef LAY2MLINST_H +#define LAY2MLINST_H + +#include +#include +#include +#include "Layout.h" +#include "MLInst.h" + +using namespace std; + +class LayoutToMLInst + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + static string InterfaceName(const string& aFileName); + static auto_ptr LayoutToInst(const TLayout& aLayout); + static void AddTableToInst(TMLInst& aInst, TLayoutTable& aTable); + static void AddWindowLineToInstTable(TMLInstTable& aInstTable, TLayoutLine& aLine); + static void AddTextLineToInstTable(TMLInstTable& aInstTable, TLayoutLine& aLine); + static void AddParamToLine(TMLInstLine& aInstLine, TValues& aValue); + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/LayCdl2Inst.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/LayCdl2Inst.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef LAYCDL2INST_H +#define LAYCDL2INST_H + +#include +#include +#include +#include "Layout.h" +using namespace std; + +#include +#include +#include +using namespace CdlCompilerToolkit; + + +/** +* CLayoutToInst +* Generate customisation instance for a set of layouts which use a particular CDL +* interface (unoptimised) +*/ +class CLayoutToInst : public CCdlTkSourceFileWriter + { +public: + CLayoutToInst(CLayoutToInst* aBase, CCdlTkInterface& aInterface, auto_ptr& aLayout, const string& aInstName); + ~CLayoutToInst(); + + CCdlTkInstance& Instance(); + string FwdDeclName(); + void Process(); + +private: + void AddTableToInstance(TLayoutTable& aTable); + void AddWindowLineToInstance(TLayoutLine& aLine); + void AddTextLineToInstance(TLayoutLine& aLine); + void AddTableLimitsToInstance(TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aTableNum); + void AddSubTableToInstance(const string& aType, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aTableNum); + bool HasApi(const string& aName); + CCdlTkImplementation& FindImp(const string& aName); + void SetDataLine(CCdlTkImplementation& aImp, TLayoutLine& aLine, const string& aType, const string aOutputOrder[], int aOutputOrderSize); + void SetFuncLine(CCdlTkImplementation& aImp, TLayoutLine& aLine, const string& aType, const string aOutputOrder[], int aOutputOrderSize, const string& aPreExtra, const string& aPostExtra); + void MirrorParamNames(std::string& aNames); + void AddFwdRefToInstance(const string& aName, bool aCast); + +private: + CLayoutToInst* iBase; + CCdlTkInterface& iInterface; + TLayout* iLayoutPtr; + TLayout& iLayout; + CCdlTkInstance* iInstance; + std::string iInstName; + }; + +class LayoutAndCdlToCdlInstance + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + static void CheckLayoutAgainstInterface(const TLayout& aLayout, const CCdlTkInterface& aIface); + + LayoutAndCdlToCdlInstance(CCdlTkInterface& aInterface); + ~LayoutAndCdlToCdlInstance(); + + void AddLayout(auto_ptr& aLayout, const string& aInstName); + void WriteInstances(); + +private: + typedef vector CLayouts; + CLayouts iLayouts; + CCdlTkInterface& iInterface; + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/LayCdl2InstO.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/LayCdl2InstO.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,129 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef LAYCDL2INSTO_H +#define LAYCDL2INSTO_H + +#include +#include +#include +#include "Layout.h" +using namespace std; + +#include +#include +#include +using namespace CdlCompilerToolkit; + +class CLayoutInstOpt; +class CLayoutInstOptImpl; +typedef vector CLayoutInstOptImpls; + +/** +* SImplFunc +* This class represents a layout data decompression function local to a layout instance. +* These functions will call the corresponding DLL wide function for decompression. +*/ +struct SImplFunc + { + enum TFuncType + { + EWindowLine, + ETextLine, + EMultilineTextLine, + ETableLimits, + EWindowTable, + ETextTable + }; + TFuncType iType; + int iParams; + bool iParent; + string iDefn; + string iPtrRef; + + SImplFunc(TFuncType aType, int aParams, bool aParent, string aDefn, string aPtrRef) + : iType(aType), iParams(aParams), iParent(aParent), iDefn(aDefn), iPtrRef(aPtrRef) + {} + }; + + +/** +* CAllFuncs +* This represents a collection of all the SImplFunc objects that a layout instance may need +*/ +class CAllFuncs : public vector + { +public: + CAllFuncs(int aMaxParams); + +private: + void AddLineFunc(SImplFunc::TFuncType aType, int aParams, bool aParent, const string& aReturn, const string& aFuncName); + void AddTableFunc(SImplFunc::TFuncType aType, int aParams, bool aParent, const string& aReturn, const string& aFuncName); + }; + + +class CInstanceList + { +public: + // ProcessOptions will remove "-i" from aArgs, if it appears at position [2]. + void ProcessOptions(vector& aArgs); + bool IsInstanceOk(const string& aInstance) const; +private: + set iInstances; + bool iLoaded; + }; + +/** +* LayoutCdlInstanceOpt +* Generate a set of optimised layout instances for a number of layouts with a common +* CDL interface +*/ +class LayoutCdlInstanceOpt + { +private: + typedef vector CLayouts; + +public: + static int Process(vector& args); + static void ShowHelp(ostream& stream); + + CCdlTkInterface& Interface(); + CLayouts& Layouts(); + CLayoutInstOptImpl* FindSimilarImpl(TLayoutLine& aLine); + int FindSimilarBytes(CLayoutInstOptImpl* aImpl); + void AddImpl(CLayoutInstOptImpl* aImpl); + +private: + LayoutCdlInstanceOpt(CCdlTkInterface& aIface); + ~LayoutCdlInstanceOpt(); + + void AddLayout(auto_ptr& aLayout, const string& aInstName); + void Process(); + void WriteInstances(); + void ProcessCommonImpl(); + bool LinesAreEqual(TLayoutLine& aLine1, TLayoutLine& aLine2); + +private: + CLayouts iLayouts; + CCdlTkInterface& iInterface; + CLayoutInstOptImpls iImpls; + int iByteCodeIndex; + vector iBytesAggregated; + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/LayCdlCheck.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/LayCdlCheck.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef LAYCDLCHECK_H +#define LAYCDLCHECK_H + +#include +#include +#include +#include "Layout.h" +using namespace std; + +#include +#include +#include +using namespace CdlCompilerToolkit; + +/** +* LayCdlCheck +* Check the interface which could be use with a layout against one specified in a CDL file +*/ +class LayCdlCheck + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + + LayCdlCheck(TLayout& aLayout, CCdlTkInterface& aInterface, CCdlTkInterface& aExcluded, const string& aOpt); + ~LayCdlCheck(); + void Process(); + + void Compare(vector& aGood, vector& aOnlyLay, vector& aOnlyCdl, vector& aParamMismatch); + void Report(const string& aTitle, vector& aApi); + bool HasOpt(char c); + +private: + TLayout& iLayout; + CCdlTkInterface& iInterface; + CCdlTkInterface& iExcluded; + CCdlTkInterface* iLayoutInterface; // owned + string iOpt; + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/LayPerfWriter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/LayPerfWriter.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef LAYPERFWRITER_H +#define LAYPERFWRITER_H + +#include "WriterBase.h" + +/** +* TLayPerfTableWriter +* Writes a layout table in .lay format +*/ +class TLayPerfTableWriter + { +public: + TLayPerfTableWriter(TLayoutTable& aTable, string& aInterfaceName, int aTableId); + ~TLayPerfTableWriter(); + + void Write(ostream& out); + static void WriteCell(ostream& out, TValues& values); + +private: + bool IsWindowTable(); + void WriteWindowTable(ostream& out); + void WriteWindowLine(ostream& out, TLayoutLine& line); + void BuildGenericLine(TLayoutLine& aLine, const string* aKParams, int aCount, string& aParams, string& aLimits); + bool IsTextTable(); + void WriteTextTable(ostream& out); + void WriteTextLine(ostream& out, TLayoutLine& line); + +private: + TLayoutTable& iTable; + string iInterfaceName; + int iTableId; + }; + +/** +* TLayPerfWriter +* Writes a layout in .lay format +*/ +class TLayPerfWriter : public TLayWriterBase + { +public: + TLayPerfWriter(TLayout& aLayout, const std::string& aName); + void Write(const std::string& aLayName); + }; + +#endif // LAYPERFWRITER_H + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/LayScale.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/LayScale.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef LAYSCALE_H +#define LAYSCALE_H + +#include +#include +#include +#include "Layout.h" +using namespace std; + +#include +using namespace CdlCompilerToolkit; + + +/** +* LayoutScale +* Compiler mode for rescaling a layout +*/ +class LayoutScale + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + +private: + LayoutScale(TLayout& aSourceLayout, int aSourceWidth, int aSourceHeight, const string& aDestLayoutName, int aDestWidth, int aDestHeight); + void Run(); + void RescaleLayout(); + void WriteLayout(); + +private: + enum TScale {EHoriz, EVert}; + void RescaleValue(string& aVal, TScale aDir); + string RescaleNum(string& aNum, TScale aDir); + void TagScaledToken(string& aToken); + int Scale(int aNumber, int aNumerator, int aDenominator); + +private: + TLayout& iLayout; + int iSourceWidth; + int iSourceHeight; + const string& iDestLayoutName; + int iDestWidth; + int iDestHeight; + }; + + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/Layout.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/Layout.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,181 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +#ifndef LAYOUT_H +#define LAYOUT_H + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) +#include +#include +#include +#include + +using namespace std; + +class TLayoutLine; +class TLayoutTable; +class TLayout; + +extern const string KWindowOutputOrder[]; +extern const string KTextOutputOrder[]; +extern const string KWindowOutputOrderMirrored[]; +extern const string KTextOutputOrderMirrored[]; +extern const int KWindowOutputOrderSize; +extern const int KTextOutputOrderSize; + + +/** +* TLayout +* The core layout class - this represents a complete layout, +* typically loaded from a .lay file +*/ +class TLayout : public vector + { +public: + enum TMergeMode { KMergeModeMerge, KMergeModeVariant, KMergeModeUnion }; + +public: + TLayout(); + TLayout(const TLayout& aOther); + TLayout& operator=(const TLayout& aOther); + + virtual ~TLayout(); + void Merge(TLayout::TMergeMode aMergeMode, TLayout& aLayout); + TLayoutLine* FindLine(const string& aName); + void Compile(); + +public: + string iName; + bool iCanBeMirror; + }; + + +/** +* TValues +* The values stored in a cell in a layout line +*/ +class TValues : public vector + { +// This class is generic with respect to the type of line it is used by +public: + TValues(); + TValues(TLayoutLine* aLine, string aName); + + bool operator==(const TValues& aOther) const; + + void Merge(TValues& aValues); + void Compile(); + string ParamName() const; + static string CppValue(const string& aValue); + +public: + TLayoutLine* iLine; + string iName; + string iParam; + bool iNeedsP; + bool iNeedsIndex; + }; + + +/** +* TLayoutLine +* A layout line +*/ +class TLayoutLine : public map + { +public: + TLayoutLine(TLayoutTable* aTable, int aId); + TLayoutLine(TLayoutTable* aTable, const TLayoutLine& aOther); + + bool operator==(const TLayoutLine& aOther) const; + bool ValuesEqual(const TLayoutLine& aOther) const; + + void Merge(TLayout::TMergeMode aMergeMode, TLayoutLine& aLine); + void Compile(); + string Name() const; + string TableName() const; + bool MatchParams(const TLayoutLine& aLine) const; + bool NeedsParams() const { return iNeedsP || iNeedsIndex; } + + void WarnMergeMismatch(TLayoutLine& aLine); + +public: + int iId; + TLayoutTable* iTable; + bool iNeedsP; + bool iNeedsIndex; + bool iIsUnique; + int iGlobalIndex; + bool iIsMirroredHorizontally; // i.e. l and r are swapped + bool iIsMergedIdentical; + }; + + +/** +* TLayoutTable +* A layout table +*/ +class TLayoutTable : public vector + { +public: + enum TTableType { EUnknownTable, EWindowTable, ETextTable }; + class TLayoutSubTable : public vector + { + public: + TLayoutSubTable(); + bool iIsMergedIdentical; + }; + typedef vector TLayoutSubTables; + +public: + TLayoutTable(TLayout* aTables); + TLayoutTable(TLayout* aTables, const TLayoutTable& aOther); + virtual ~TLayoutTable(); + + void Merge(TLayout::TMergeMode aMergeMode, TLayoutTable& aTable); + TLayoutLine* FindLine(const string& aName); + void Compile(); + void BuildSubTables(); + void DestroySubTables(); + string Name(); + static bool IsValueColumn(string aName); + static bool IsNumericColumn(string aName); + void SetDefaultColumnNames(); + bool IsWorthATableIndex(); + +public: + TLayoutSubTables iSubTables; + vector iColumnNames; + TTableType iType; + TLayout* iTables; + string iName; + TLayoutLine* iParent; + string iParentName; + bool iNeedsP; + bool iNeedsIndex; + int iFirstLineGlobalIndex; + bool iAppend; + bool iNoSubTables; + }; + + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/LayoutCompilerErr.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/LayoutCompilerErr.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +#ifndef LAYOUTCOMPILERERR_H +#define LAYOUTCOMPILERERR_H + +#include +#include +#include +using namespace CdlCompilerToolkit; +using namespace std; + +/** +* LayoutCompilerErr +* Base class for exceptions in the layout compiler +*/ +class LayoutCompilerErr : public CdlCompilerToolkitErr + {}; + +/** +* NotFoundErr +* A "not found" exception, which takes a string to explain what was not found +*/ +class NotFoundErr : public LayoutCompilerErr + { +public: + NotFoundErr(const string& aName) : iName(aName) {} + void Show(ostream& stream) const; +private: + string iName; + }; + +/** +* GeneralErr +* A general compiler error, which takes a string to explain what the error was +*/ +class GeneralErr : public LayoutCompilerErr + { +public: + GeneralErr(const string& aMessage) : iMessage(aMessage) {} + void Show(ostream& stream) const; +private: + string iMessage; + }; + +string StreamLoc(const istream& stream, const string& msg, int before, int after); + + +/** +* LayoutProcessArgsErr +* A templated exception class that indicated an exception in the command line parameter +* processing in the class in which it is instantiated on. +*/ +template +class LayoutProcessArgsErr : public LayoutCompilerErr + { + void Show(ostream& aStream) const { T::ShowHelp(aStream); } + }; + + + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/LayoutConfig.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/LayoutConfig.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#ifndef LAYOUTCONFIG_H +#define LAYOUTCONFIG_H + +#include +#include +#include +#include + +class LayoutConfig + { +public: + class Size + { + public: + enum TOrientation { EPortrait, ELandscape, ESquare }; + public: + Size(); + TOrientation Orientation() const; + bool operator>(const Size& aRhs) const; + public: + int iWidth; + int iHeight; + }; + typedef std::set > Sizes; + + enum TTarget { EPlatform, EProduct }; + enum TLegacyMode { ENoLegacyMode, ELegacyMode }; + +public: + static int Process(const std::vector& args); + static void ShowHelp(std::ostream& stream); + + ~LayoutConfig(); + +protected: + LayoutConfig(); + + void ParseArgs(const std::vector& args); + void ParseOpt(const std::string& opt); + + void SetFlags(TTarget aTarget, TLegacyMode aLegacyMode); + + const Sizes& AllSizes() const; + const Sizes& ConfiguredSizes() const; + const Sizes& SizesForTarget() const; + +// static int TestLayoutConfig(); + +private: // to be overridden + virtual int Process() = 0; + +private: + void LoadAllSizes(); + void LoadConfiguredSizes(); + void OpenBldCfg(std::ifstream& aBldCfg); + bool ParseSize(const std::string& aLine, Size& aSize) const; + +private: + Sizes iAll; + Sizes iConf; + TTarget iTarget; + TLegacyMode iLegacyMode; + std::string iTargetFileName; + std::string iBaseFileName; + }; + + +class WsiniConfig : public LayoutConfig + { +private: // from LayoutConfig + virtual int Process(); + }; + + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/LayoutPack.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/LayoutPack.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef LAYOUTPACK_H +#define LAYOUTPACK_H + +#include +#include +#include +using namespace std; + +#include +#include +#include +using namespace CdlCompilerToolkit; + +/** +* LayoutPackage +* Write a layout package according to the LayoutPack.cdl interface +*/ +class LayoutPackage + { +public: + static int Process(vector& args); + static void ShowHelp(ostream& stream); + +private: + static void Process( + const string& aName, + const string& aWidth, + const string& aHeight, + const string& aId, + const string& aStyleName, + const string& aDeliveryTypeName, + const string& aPriority, + const string& aAppUid, + vector::const_iterator aBegin, + vector::const_iterator aEnd, + const string& aZoomName); + static void Implement( + CCdlTkPackage& aPkg, + const string& aApi, + const string& aTarget, + const string& aReplace, + const string& aComment = ""); + static void ProcessOptionalStringArg(vector& args, const string& aOption, string& aArg); + static string Hash(const string& aString); + }; + + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/LayoutParse.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/LayoutParse.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,99 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef LAYOUTPARSE_H +#define LAYOUTPARSE_H + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) +#include +#include +#include +#include "LayoutCompilerErr.h" +#include "Layout.h" +using namespace std; + + +/** +* LayParseErr +* An exception class for .lay file parsing errors +*/ +class LayParseErr : public LayoutCompilerErr + { +public: + LayParseErr(istream& aIn, const string& aTok, const string& aMsg); + void Show(ostream& aOut) const; +private: + string iLoc; + string iTok; + string iMsg; + }; + + +/** +* TLayParseValues +* Parse the values in a layout cell from .lay format +*/ +class TLayParseValues : public TValues + { +// This class is generic with respect to the type of line it is used by +public: + TLayParseValues(TLayoutLine* aLine, string aName); + void Parse(istream& aIn); + }; + + +/** +* TLayParseLayoutLine +* Abstract class for common line parsing functionality +*/ +class TLayParseLayoutLine : public TLayoutLine + { +public: + TLayParseLayoutLine(TLayoutTable* aTable, int aId); + void Parse(istream& aIn); + }; + + +/** +* TLayParseLayoutTable +* Parse a layout table in .lay format +*/ +class TLayParseLayoutTable : public TLayoutTable + { +public: + TLayParseLayoutTable(TLayout* aTables); + virtual void Parse(istream& aIn); + }; + + +/** +* TLayParseLayout +* Parse a layout file in .lay format +*/ +class TLayParseLayout : public TLayout + { +public: + static auto_ptr Parse(const string& aLayName); + void Parse(istream& aIn); + }; + + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/LayoutWriter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/LayoutWriter.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef LAYOUTWRITER_H +#define LAYOUTWRITER_H + +#include "WriterBase.h" + +/** +* TLayoutTableWriter +* Writes a layout table in .lay format +*/ +class TLayoutTableWriter + { +public: + TLayoutTableWriter(TLayoutTable& aTable); + ~TLayoutTableWriter(); + + void Write(ostream& out); + static void WriteCell(ostream& out, TValues& values); + +private: + bool IsWindowTable(); + void WriteWindowTable(ostream& out); + void WriteWindowLine(ostream& out, TLayoutLine& line); + bool IsTextTable(); + void WriteTextTable(ostream& out); + void WriteTextLine(ostream& out, TLayoutLine& line); + +private: + TLayoutTable& iTable; + }; + +/** +* TLayoutWriter +* Writes a layout in .lay format +*/ +class TLayoutWriter : public TLayWriterBase + { +public: + TLayoutWriter(TLayout& aLayout, const std::string& aName); + void Write(const std::string& aLayName); + }; + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLAttributes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLAttributes.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MLATTRIBUTES_H +#define MLATTRIBUTES_H + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +// disable "decorated name length exceeded, name was truncated" +#pragma warning (disable:4503) + + +#include +#include +#include + +using namespace std; + +class TMLAttributes; + +/** +* TMLAttributeSet +* The attributes stored in an attribute set +*/ +typedef map TMLAttributeZoomLevels; +class TMLAttributeSet : public map + { +public: // constructors, operators, etc + TMLAttributeSet(); + TMLAttributeSet(TMLAttributes* aAttributes); + virtual ~TMLAttributeSet(); +public: // new methods + void Merge(TMLAttributeSet& aOther); + void Compile(); +public: // member data, not owned + TMLAttributes* iAttributes; + }; + +/** +* TMLAttributes +* The attribute values stored in a layout component +*/ +typedef map TMLAttributeSetComponent; +class TMLAttributes: public map + { +public: + typedef map TMLAttributeNames; +public: // constructors, operators, etc + TMLAttributes(); + virtual ~TMLAttributes(); +public: // new methods + void Merge(TMLAttributes& aOther); + void Compile(); +public: // member data, owned + string iName; + string iTimestamp; + bool iCanBeMirror; + TMLAttributeNames iNames; + }; + +#endif // MLATTRIBUTES_H +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLAttributesParse.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLAttributesParse.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,123 @@ +/* +* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +#ifndef MLATTRIBUTESPARSE_H +#define MLATTRIBUTESPARSE_H + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "LayoutCompilerErr.h" +#include "MLAttributes.h" + +#include // for logical font ids + +#include "SaxErrorHandler.h" + +#include +#include +#include +#include + +using namespace std; + + +// +// defines +// + +/** + * this is the interface to the SAX handler + */ +class MSaxLayoutAttributesHandler + { +public: + typedef SAX::basic_Attributes TAttribs; // this is XML Attribs, not to be confused with layout attibutes! + virtual MSaxLayoutAttributesHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs) { return this; }; + virtual void HandleSaxEnd(const std::string& aElement) { }; + }; + + +/** + * this corresponds to an attribute set in the xml + */ +class TMLAttributeSetParse : public TMLAttributeSet, public MSaxLayoutAttributesHandler + { +public: + TMLAttributeSetParse(TMLAttributes* aAttributes); +public: // from MSaxLayoutHandler + MSaxLayoutAttributesHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); + void HandleSaxEnd(const std::string& aElement); +public: // new methods + int CompId() const; + string Name() const; +private: + void HandleSaxAttribute(const TAttribs& aAttribs); + void HandleSaxCalc(const TAttribs& aAttribs); +private: + int iId; + int iCompId; + string iName; + TMLAttributeZoomLevels* iSaxZoomLevels; + }; + +/** + * this corresponds to attributes in the xml + */ +class TMLAttributesParse : public TMLAttributes, public MSaxLayoutAttributesHandler + { +public: + static auto_ptr Parse(const string& aLayName); + TMLAttributesParse(); +public: // from MSaxLayoutHandler + MSaxLayoutAttributesHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); + void HandleSaxEnd(const std::string& aElement); +private: // owned + TMLAttributeSetParse* iSaxAttributeSet; + }; + +/** + * this is the main SAX parser implementation + */ +class TLayoutAttributesSaxParser : private SAX::basic_DefaultHandler + { +private: + typedef stack TSaxAttributesHandlerStack; + typedef SAX::basic_ErrorHandler::SAXParseExceptionT TException; + +public: + TLayoutAttributesSaxParser(MSaxLayoutAttributesHandler* aHandler); + void Parse(const std::string& aFileName); + +private: // from basic_DefaultHandler + void startElement(const std::string& namespaceURI, const std::string& localName, const std::string& qName, const SAX::basic_Attributes& atts); + void endElement(const std::string& namespaceURI, const std::string& localName, const std::string& qName); + + void warning(const TException& aException); + void error(const TException& aException); + void fatalError(const TException& aException); + +private: + TSaxAttributesHandlerStack iStack; // stack content not owned + }; + + +#endif // MLATTRIBUTESPARSE_H + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLCompCdl2InstO.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLCompCdl2InstO.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,101 @@ +/* +* Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MLCOMPCDL2INSTO_H +#define MLCOMPCDL2INSTO_H + +#include +#include +#include +#include "MLCompData.h" +#include "MLAttributes.h" +using namespace std; + +#include +#include +#include +using namespace CdlCompilerToolkit; + +// forward declares and typedefs +class CInstanceList; +class CMLCompDataInstOpt; +class CMLCompDataInstOptImpl; +typedef vector CMLCompDataInstOptImpls; +class CZoomLevelNames; + +/** +* MLCompDataCdlInstanceOpt +* Generate a set of optimised layout instances for a number of layouts with a common +* CDL interface +*/ +class MLCompDataCdlInstanceOpt + { +private: + struct InstStruct + { + InstStruct(string aInstName, TMLCompData* aInst, TMLAttributes* aAttribs); + string iInstName; + TMLCompData* iInst; + TMLAttributes* iAttribs; + }; + + class InstList : public vector + { + public: + ~InstList(); + }; + + typedef vector CCompDataLayouts; + typedef vector CCompDatas; + typedef map CCompDataZoomLevelDatas; +public: + static int Process(vector& args); + static void ShowHelp(ostream& stream); + +public: + CCdlTkInterface& Interface(); + int FindSimilarBytes(CMLCompDataInstOptImpl* aImpl, int aBaseOffset); + void AddImpl(CMLCompDataInstOptImpl* aImpl); + void ResizeByteStream(int aSize); + int ByteStreamSize() const; + + +private: + static void ProcessSeparators(vector& args, vector& aSeparators); + static bool CheckForUsedInstances(const CInstanceList& aUsedList, const CZoomLevelNames& aZoomLevelNames, const vector& aArgs, const vector& aSeparators, int aSepIndex); + static void ParseInstances(const vector& aArgs, const vector& aSeparators, int aSepIndex, InstList& aInstList); + static void MergeLayouts(CInstanceList& aInstUsedList, CZoomLevelNames& aZoomLevelNames, const InstList& aInstances, InstList& aMergedLayouts); + +private: + MLCompDataCdlInstanceOpt(CCdlTkInterface& aIface); + ~MLCompDataCdlInstanceOpt(); + + void AddInst(const InstStruct& aInstStruct, CZoomLevelNames& aZoomLevelNames, bool aAllParams, bool aNonRomDelivery); + void Process(); + void WriteInstances(); + void ProcessCommonImpl(); + +private: + CCompDataLayouts iLayouts; // the comp datas are owned + CCompDataZoomLevelDatas iZoomLevelDatas; // the comp data inst opts are owned + CCdlTkInterface& iInterface; // not owned + CMLCompDataInstOptImpls iImpls; // not owned + vector iBytesAggregated; + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLCompData.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLCompData.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,367 @@ +/* +* Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MLCOMPDATA_H +#define MLCOMPDATA_H + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +// disable "decorated name length exceeded, name was truncated" +#pragma warning (disable:4503) + +#include "MLAttributes.h" + +#include +#include +#include +#include + +using namespace std; + +class TMLCompDataLine; +class TMLCompDataTable; +class TMLCompData; +class TMLAttributes; + +extern const string KCompDataPaneOutputOrder[]; +extern const string KCompDataPaneOutputOrderMirrored[]; +extern const string KCompDataGraphicOutputOrder[]; +extern const string KCompDataGraphicOutputOrderMirrored[]; +extern const string KCompDataTextOutputOrder[]; +extern const string KCompDataTextOutputOrderMirrored[]; +extern const int KCompDataPaneOutputOrderSize; +extern const int KCompDataGraphicOutputOrderSize; +extern const int KCompDataTextOutputOrderSize; +/** +* TMLCompDataCalcs +* The calcs stored in a value +*/ +typedef map TMLCompDataCalcs; +typedef map TMLCompDataZoomLevels; +typedef map TMLCompDataVarieties; + +/** +* TMLCompDataValues +* The values stored in a cell in a layout line +*/ +class TMLCompDataValues : public TMLCompDataVarieties + { +public: + enum TCompDataCellType + { + ECellTypeDefault, + ECellTypeParamLimit, + ECellTypeCol, + ECellTypeRow + }; + +public: // constructors, operators, etc + TMLCompDataValues(); + TMLCompDataValues(TMLCompDataLine* aLine); + virtual ~TMLCompDataValues(); + bool operator==(const TMLCompDataValues& aOther) const; + +public: // new methods + bool Merge(TMLCompDataLine* aLine, string aName, TMLCompDataValues& aOtherValues, bool aMirrorMerge); + void Compile(const string& aCellName); + static string CppValue(const string& aValue); + static string MirrorJustificationValue(const string& aValue); + static TCompDataCellType Type(string aName); + +public: // member data + TMLCompDataLine* iLine; // not owned + string iName; + }; + + +// +// Parent Info +// + +/** +* TMLCompDataParentInfoSelector +* +* The parent id and parent variety index for each variety index +*/ +struct TMLCompDataParentInfoSelector + { +public: + TMLCompDataParentInfoSelector(); + TMLCompDataParentInfoSelector(int aParentId, int aParentVariety); +public: + int iParentId; + int iParentVariety; + }; + +typedef map TMLCompDataParentInfoVarieties; + +/** +* TMLCompDataParentInfo +* +* Contains the parent info selector for each variety index +*/ +class TMLCompDataParentInfo : public TMLCompDataParentInfoVarieties + { +public: // constructors etc + TMLCompDataParentInfo(); + TMLCompDataParentInfo(TMLCompDataLine* aLine); + virtual ~TMLCompDataParentInfo(); +public: // new methods + void Merge(const TMLCompDataParentInfo& aOther); +public: // member data + TMLCompDataLine* iLine; // not owned + }; + +class TMLCompDataAttributeInfo; + +/** +* TMLCompDataLine +* A layout line +*/ +class TMLCompDataLine : public map + { +public: + enum TComponentType + { + EUnknownComponent, + EScreenComponent, + EContainerComponent, + EPaneComponent, + EGraphicComponent, + ETextComponent + }; + +public: // constructors etc + TMLCompDataLine(); + TMLCompDataLine(const TMLCompDataLine& aOther); + virtual ~TMLCompDataLine(); + + bool operator==(const TMLCompDataLine& aOther) const; + static bool lessthan(TMLCompDataLine* aLeft, TMLCompDataLine* aRight); + bool ValuesEqual(const TMLCompDataLine& aOther) const; + +public: // new methods + bool Merge(TMLCompDataLine& aOther); + void Compile(); + TMLAttributeZoomLevels* GetAttributeZoomLevels(string aAttribName, int aVariety); + +public: // get and set methods + string Name() const; + bool NeedsParams() const; + bool NeedsOptions() const; + bool NeedsCols() const; + bool NeedsRows() const; + int MaxVariety() const; + int NumCols() const; + int NumRows() const; + void SetMaxVariety(int aMaxVariety); + void SetNumCols(int aNumCols); + void SetNumRows(int aNumRows); + void SetNeedsCols(bool aNeeds); + void SetNeedsRows(bool aNeeds); + +public: // helpers + int EncodeFontId(int aHeight, int aOutline, int aPosture, int aWeight, int aCategory) const; + bool MatchParams(const TMLCompDataLine& aLine) const; + bool MatchNameDiscountingSuffix(const TMLCompDataLine& aLine) const; + bool MatchType(const TMLCompDataLine& aLine) const; + string NameDiscountingSuffix() const; + string NameSuffix() const; + +private: // helpers + TMLAttributeZoomLevels* GetParentAttributeZoomLevels(string aAttribSetName, int aAttribId, int aVariety); + TMLAttributeZoomLevels* FindAttributeZoomLevels(string aAttribSetName, int aAttribId); + void CompileParamLimits(TMLCompDataValues::TCompDataCellType aParamLimitType, const string& aParamLimitCellName); + void CompileFontHeights(); + + +public: // member data + int iId; + string iName; + TComponentType iType; + int iDrawingOrder; + int iMaxVariety; + TMLCompDataTable* iParentTable; + TMLCompDataParentInfo* iParentInfo;// owned + TMLCompDataAttributeInfo* iAttributeInfo;// owned + bool iIsUnique; + int iGlobalIndex; + bool iIsMirroredHorizontally; // i.e. l and r are swapped + bool iNeedsOptions; // note that can need options although numOptions is only 1, as may be needed for subtable + bool iNeedsCols; + bool iNeedsRows; + +private: + int iNumCols; // there is always at least one column + int iNumRows; // there is always at least one row + }; + + +// +// Attribute Info +// + +/** +* TMLCompDataAttributeInfoSelector +* +* Contains the attribute set name, which is used to +* disambiguate the attribute data for a given component +*/ +struct TMLCompDataAttributeInfoSelector + { +public: + TMLCompDataAttributeInfoSelector(); + TMLCompDataAttributeInfoSelector(string aAttributeSetName); +public: + string iAttributeSetName; + }; + +typedef map TMLCompDataAttributeInfoVarieties; + +/** +* TMLCompDataAttributeInfo +* +* Contains the attribute info selector for each variety +*/ +class TMLCompDataAttributeInfo : public TMLCompDataAttributeInfoVarieties + { +public: // constructors etc + TMLCompDataAttributeInfo(); + TMLCompDataAttributeInfo(TMLCompDataLine* aLine); + virtual ~TMLCompDataAttributeInfo(); +public: // new methods + void Merge(const TMLCompDataAttributeInfo& aOther); +public: // member data + TMLCompDataLine* iLine; // not owned + }; + + + +/** +* TMLCompDataTable +* A layout table +*/ +class TMLCompDataTable : public vector + { +public: + /* + * Subtables are automatically generated for contiguous collections + * of components whose names are the same, ending in _g or _t + * followed by a number. These components represent numbered + * rendered objects in the specification, and often need to be + * indexed by clients of the scalable layout API. + * + */ + class TMLCompDataSubTable : public vector + { + public: + TMLCompDataSubTable(); + bool NeedsParams() const; + public: + bool iNeedsOption; + bool iNeedsCol; + bool iNeedsRow; + string iName; + }; + typedef vector TMLCompDataSubTables; + +public: // constructors etc + TMLCompDataTable(TMLCompData* aTables); + TMLCompDataTable(TMLCompData* aTables, const TMLCompDataTable& aOther); + virtual ~TMLCompDataTable(); + static bool lessthan(TMLCompDataTable* aLeft, TMLCompDataTable* aRight); + +public: // new methods + TMLCompDataSubTable* FindSubTable(const string& aName); + TMLCompDataLine* FindLine(const string& aName); + void Merge(TMLCompDataTable& aOther); + void Compile(); + void BuildSubTables(); + void NormalizeSubTables(); + void DestroySubTables(); + void SetDefaultColumnNames(); + +public: // accessors + string Name(); + static bool IsValueColumn(string aName); + static bool IsNumericColumn(string aName); + static bool IsHorizontalColumn(string aName); + static bool IsVerticalColumn(string aName); + +public: // member data + int iId; + string iName; + TMLCompData* iTables; + TMLCompDataSubTables iSubTables; + vector iColumnNames; + TMLCompDataLine* iParentLine; // not owned + string iParentName; + bool iNeedsP; + bool iNeedsIndex; + bool iAppend; + int iFirstLineGlobalIndex; + }; + +/** +* TMLCompData +* The core layout class - this represents a complete layout, +* typically loaded from a .xml file that has been exported from the +* layout creation tool +*/ +class TMLCompData : public vector + { +public: + typedef map TMLComponents; + +public: // constructors + TMLCompData(); + TMLCompData(const TMLCompData& aOther); + TMLCompData& operator=(const TMLCompData& aOther); + +public: // new methods + virtual ~TMLCompData(); + TMLCompDataLine* FindComponent(const string& aName) const; + TMLCompDataLine* FindLine(const string& aName) const; + TMLCompDataTable* FindTable(int aId) const; + TMLCompDataTable* FindTable(const string& aName) const; + TMLCompDataTable::TMLCompDataSubTable* FindSubTable(const string& aName) const; + void Merge(TMLCompData& aOther); + void MergeComponents(TMLCompData& aOther); + void Compile(); + void CreateTables(); + void DeleteComponents(); + +public: // member data + string iName; + bool iCanBeMirror; + string iMasterName; + string iLayoutName; + string iVariantName; + string iResolutionHeight; + string iResolutionWidth; + string iTimestamp; + TMLComponents iComponents; // this is used to accumulate the lines, which are then compiled into tables + bool iIsBaseInstance; + TMLAttributes* iAttributes; // owned + }; + + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLCompData2Cdl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLCompData2Cdl.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MLCOMPDATA2CDL_H +#define MLCOMPDATA2CDL_H + +#include +#include +#include +#include "MLCompData.h" +using namespace std; + +#include +using namespace CdlCompilerToolkit; + + +/** +* MLCompDataToCdl +* Generate a CDL interface for a layout +*/ +class MLCompDataToCdl + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + static void LayoutToInterface(CCdlTkInterface& aInterface, const TMLCompData& aLayout, bool aDeletesAllowed, bool aAllParams); + static void AddGenericApiToInterface(CCdlTkInterface& aInterface, const string& aReturnType, const string& aName, bool aNeedsOptions, bool aNeedsColsRows); + static void AddTableToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, bool aAllParams); + static void AddTableCommentToApi(TMLCompDataTable& aTable, CCdlTkApi& aApi); + static void AddTableCommentToApi(TMLCompDataLine& aLine, CCdlTkApi& aApi); + static void AddLineToInterface(CCdlTkInterface& aInterface, TMLCompDataLine& aLine, bool aAllParams); + static void AddParamLimitsToInterface(CCdlTkInterface& aInterface, TMLCompDataLine& aLine, bool aAllParams); + static void AddSubTableToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, bool aAllParams); + static void AddSubTableLimitsToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable); + static void AddSubTableParamLimitsToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, bool aAllParams); + static void AddParamsToFunc(TMLCompDataLine& aLine, CCdlTkFunctionApi& aFunc, bool aAllParams, bool aIsNew, bool aRowsCols); + static void AddParamsToFunc(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, CCdlTkFunctionApi& aFunc, bool aAllParams, bool aIsNew, bool aRowsCols); + static void AddParamToParams(CCdlTkApiParams& aOldParams, CCdlTkApiParams& aParams, string aType, bool aAllParams, bool aIsNewLine, bool aNeedsParam); + static void SetHeaders(CCdlTkInterface& aInterface, const string& aCdlName, const string& aComment, int aUid, bool aRomOnly); + static string InterfaceName(const string& aFileName); + static string SubTableApiName(TMLCompDataTable::TMLCompDataSubTable& aSubTable); + static string SubTableLimitsApiName(TMLCompDataTable::TMLCompDataSubTable& aSubTable); + static string SubTableParamLimtsApiName(TMLCompDataTable::TMLCompDataSubTable& aSubTable); + static string LineApiName(TMLCompDataLine& aLine); + static string LineParamLimitsApiName(TMLCompDataLine& aLine); +private: + static string MLCompDataToCdl::ReturnType(TMLCompDataLine& aLine); + static void ReplaceRemovedAPIs(CCdlTkInterface& aInterface, const TMLCompData& aLayout, bool aDeletesAllowed); + static void CleanUpAPIComments(CCdlTkInterface& aInterface); + static CCdlTkFunctionApi* ProcessFunctionApi(CCdlTkInterface& aInterface, string aReturnType, string aName, bool& aIsNew); + static CCdlTkFunctionApi* CreateFunctionApi(CCdlTkInterface& aInterface, string aReturnType, string aName); + static void UpdateFunctionApi(CCdlTkFunctionApi& aApi, CCdlTkInterface& aInterface, string aReturnType, string aName); + static void UpdateParams(CCdlTkApiParams& aOldParams, CCdlTkApiParams& aParams, string aApiName, bool aAllParamsRequested, bool aColsRowsRequired, bool aIsNew, bool aNeedsComponentId, bool aNeedsOptions, bool aNeedsCols, bool aNeedsRows); +private: + typedef set CApiNamesUsed; + static CApiNamesUsed iInterfaceNamesUsed; + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLCompData2LayPerf.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLCompData2LayPerf.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MLCompData2LayPerf_H +#define MLCompData2LayPerf_H + +#include +#include +#include +#include "MLCompData.h" +using namespace std; + +#include +using namespace CdlCompilerToolkit; + + +/** +* MLCompDataToLayPerf +* Compiler mode for rescaling a layout +*/ +class MLCompDataToLayPerf + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + +private: + MLCompDataToLayPerf(const string& aCdlName, CCdlTkInterface& aInterface, TMLCompData& aSourceLayout, const string& aDestLayoutName); + void WriteLayout(); + +private: + TMLCompData& iLayout; + string iDestLayoutName; + string iCdlName; + CCdlTkInterface& iInterface; // not owned + }; + + +#endif // MLCompData2LayPerf_H diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLCompDataLayPerfWriter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLCompDataLayPerfWriter.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MLCompDataLayPerfWriter_H +#define MLCompDataLayPerfWriter_H + +// disable "decorated name length exceeded, name was truncated" +#pragma warning (disable:4503) + +#include "WriterBase.h" +#include "MLCompData.h" + +class TMLCompDataLayPerfWriter; + +#include +using namespace CdlCompilerToolkit; + + +/** +* TLayPerfTableWriter +* Writes a layout table in .lay format +*/ +class TMLCompDataLayPerfTableWriter + { +public: + TMLCompDataLayPerfTableWriter(TMLCompDataLayPerfWriter* aParent, TMLCompDataTable& aTable, string& aInterfaceName, int aTableId); + ~TMLCompDataLayPerfTableWriter(); + void Write(ostream& out); + +private: + void WriteTable(ostream& out); + void WriteLine(ostream& out, TMLCompDataLine& line); + string BuildMacroName(TMLCompDataLine& aLine); + string BuildApiName(TMLCompDataLine& aLine); + string BuildParams(TMLCompDataLine& aLine); + string BuildParamLimitParams(TMLCompDataLine& aLine); + +private: + TMLCompDataLayPerfWriter* iParent; + TMLCompDataTable& iTable; + string iInterfaceName; + int iTableId; + }; + +/** +* TMLCompDataLayPerfWriter +* Writes a layout in LayPerf format, using the build in macros to do the work. +*/ +class TMLCompDataLayPerfWriter : public TMLWriterBase + { +public: + TMLCompDataLayPerfWriter(CCdlTkInterface& aInterface, TMLCompData& aLayout, const std::string& aName); + void Write(const std::string& aLayName); +public: + CCdlTkInterface& iInterface; // not owned + }; + +#endif // MLCompDataLayPerfWriter_H + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLCompDataParse.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLCompDataParse.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,183 @@ +/* +* Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +#ifndef MLCOMPDATAPARSE_H +#define MLCOMPDATAPARSE_H + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "LayoutCompilerErr.h" +#include "MLCompData.h" + +#include // for logical font ids + +#include "SaxErrorHandler.h" + +#include +#include +#include +#include + +using namespace std; + + +// +// defines +// +#define ELayoutCompilerFontCategoryUndefined KAknFontCategoryUndefined /* 0 */ +#define ELayoutCompilerFontCategoryPrimary KAknFontCategoryPrimary /* 1*/ +#define ELayoutCompilerFontCategorySecondary KAknFontCategorySecondary /* 2 */ +#define ELayoutCompilerFontCategoryTitle KAknFontCategoryTitle /* 3 */ +#define ELayoutCompilerFontCategoryPrimarySmall KAknFontCategoryPrimarySmall /* 4 */ +#define ELayoutCompilerFontCategoryDigital KAknFontCategoryDigital /* 5 */ + + +class MSaxLayoutHandler + { +public: + typedef SAX::basic_Attributes TAttribs; + virtual MSaxLayoutHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs) { return this; }; + virtual void HandleSaxEnd(const std::string& aElement) { }; + }; + + +// this corresponds to a "param" in the xml +class TMLCompDataParseValues : public TMLCompDataValues, public MSaxLayoutHandler + { +public: + TMLCompDataParseValues(TMLCompDataLine* aLine); + static int ConvertZoomStr(const std::string& aValueStr); +public: // from MSaxLayoutHandler + MSaxLayoutHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); +private: + void HandleSaxEnd(const std::string& aElement); + void HandleSaxVariety(const std::string& aElement, const TAttribs& aAttribs); + void HandleSaxCalc(const std::string& aElement, const TAttribs& aAttribs); +private: + void ConvertValueStr(std::string& aValueStr); +private: + TMLCompDataZoomLevels* iSaxZoomLevels; + int iSaxVariety; + }; + +// this corresponds to the contents of "ParentInfo" in the xml +class TMLCompDataParseParentInfo : public TMLCompDataParentInfo, public MSaxLayoutHandler + { +public: + TMLCompDataParseParentInfo(TMLCompDataLine* aLine); +public: // from MSaxLayoutHandler + MSaxLayoutHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); +private: + void HandleSaxEnd(const std::string& aElement); + void HandleSaxParent(const std::string& aElement, const TAttribs& aAttribs); + void HandleSaxVariety(const std::string& aElement, const TAttribs& aAttribs); +private: + TMLCompDataParentInfoSelector* iSaxParentInfoSelector; + int iSaxVariety; + }; + + +class TMLCompDataParseAttributeInfo; + +// this corresponds to a "component" in the xml +class TMLCompDataParseLayoutLine : public TMLCompDataLine, public MSaxLayoutHandler + { +public: + TMLCompDataParseLayoutLine(); + string ShortParamName(string& aName); +public: // from MSaxLayoutHandler + MSaxLayoutHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); +private: + void HandleSaxEnd(const std::string& aElement); + void HandleSaxAttributes(const TAttribs& aAttribs); + MSaxLayoutHandler* HandleSaxParent(const std::string& aElement, const TAttribs& aAttribs); + MSaxLayoutHandler* HandleSaxParam(const std::string& aElement, const TAttribs& aAttribs); + MSaxLayoutHandler* HandleSaxAttributeInfo(const std::string& aElement, const TAttribs& aAttribs); +private: + TMLCompDataParseValues* iSaxValues; + TMLCompDataParseParentInfo* iSaxParentInfo; + TMLCompDataParseAttributeInfo* iSaxAttributeInfo; + }; + +// this corresponds to the contents of "AttributeInfo" in the xml +class TMLCompDataParseAttributeInfo : public TMLCompDataAttributeInfo, public MSaxLayoutHandler + { +public: + TMLCompDataParseAttributeInfo(TMLCompDataLine* aLine); +public: // from MSaxLayoutHandler + MSaxLayoutHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); +private: + void HandleSaxEnd(const std::string& aElement); + void HandleSaxVariety(const std::string& aElement, const TAttribs& aAttribs); + void HandleSaxAttributeSet(const std::string& aElement, const TAttribs& aAttribs); +private: + TMLCompDataAttributeInfoSelector* iSaxAttributeInfoSelector; + int iSaxVariety; + }; + + + +// this corresponds to a common parent component, and therefore does +// not correspond directly to a structure in the xml, although in general +// there is one per non-leaf component +class TMLCompDataParseLayoutTable : public TMLCompDataTable, public MSaxLayoutHandler + { +public: + TMLCompDataParseLayoutTable(TMLCompData* aTables); +public: // from MSaxLayoutHandler + MSaxLayoutHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); + }; + +// this corresponds to a layout in the xml +class TMLCompDataParseLayout : public TMLCompData, public MSaxLayoutHandler + { +public: + static auto_ptr Parse(const string& aLayName); +public: // from MSaxLayoutHandler + MSaxLayoutHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); + }; + + +class TLayoutSaxParser : private SAX::basic_DefaultHandler + { +private: + typedef stack TSaxHandlerStack; + typedef SAX::basic_ErrorHandler::SAXParseExceptionT TException; + +public: + TLayoutSaxParser(MSaxLayoutHandler* aHandler); + void Parse(const std::string& aFileName); + +private: // from basic_DefaultHandler + void startElement(const std::string& namespaceURI, const std::string& localName, const std::string& qName, const SAX::basic_Attributes& atts); + void endElement(const std::string& namespaceURI, const std::string& localName, const std::string& qName); + + void warning(const TException& aException); + void error(const TException& aException); + void fatalError(const TException& aException); + +private: + TSaxHandlerStack iStack; // stack content not owned + }; + + +#endif // MLCOMPDATAPARSE_H + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLEqCompData.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLEqCompData.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,426 @@ +/* +* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MLEQCOMPDATA_H +#define MLEQCOMPDATA_H + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +// disable "decorated name length exceeded, name was truncated" +#pragma warning (disable:4503) + +#include "MLAttributes.h" + +#include +#include +#include +#include + +using namespace std; + +class TMLEqCompDataLine; +class TMLEqCompDataTable; +class TMLEqCompData; +class TMLAttributes; +class FormulaTreeNode; + +extern const string KEqCompDataPaneOutputOrder[]; +extern const int KEqCompDataPaneOutputOrderSize; + +extern const string KEqCompDataKeywordParamLeft; +extern const string KEqCompDataKeywordParamTop; +extern const string KEqCompDataKeywordParamRight; +extern const string KEqCompDataKeywordParamBottom; +extern const string KEqCompDataKeywordParamWidth; +extern const string KEqCompDataKeywordParamHeight; + + +/** +* TMLEqCompDataFormula +* +* This represents a formula entry. It contains both the original string representation and any +* subsequent parsed and resolved versions. +*/ +struct TMLEqCompDataFormula + { +public: + TMLEqCompDataFormula(); + TMLEqCompDataFormula(const TMLEqCompDataFormula& aOther); + TMLEqCompDataFormula(string aFormulaString); + const TMLEqCompDataFormula& operator=(const TMLEqCompDataFormula& aOther); + bool operator==(const TMLEqCompDataFormula& aOther) const; + virtual ~TMLEqCompDataFormula(); +public: // new methods + void Compile(); +public: + string iFormulaString; // owned, must be present for lifetime of iFormulaTree + int iZoomId; + + // don't think that we need these as they don't seem to be used +// string lowerMargin; +// string upperMargin; +// string minLimit; +// string maxLimit; + +public: + FormulaTreeNode* iFormulaTree; // owned, but it references iFormulaString + }; + +typedef vector TMLEqCompDataFormulae; + +enum TMLEqCompDataOptionSetOrientation + { + EMLEqCompDataOptionSetOrientationUndefined = 0x00, + EMLEqCompDataOptionSetOrientationPortrait = 0x01, + EMLEqCompDataOptionSetOrientationLandscape = 0x02 + }; + +/** + * TMLEqCompDataValuesOptionSet + * an option set for a given value, which may apply to either or both orientation + */ +struct TMLEqCompDataValuesOptionSet : public TMLEqCompDataFormulae + { +public: + void Compile(); +public: + TMLEqCompDataOptionSetOrientation iOrientation; + }; + +typedef map TMLEqCompDataValuesOptionSets; + +/** +* TMLEqCompDataValues +* The values stored in a cell in a layout line +*/ +class TMLEqCompDataValues : public TMLEqCompDataFormulae + { +public: // constructors, operators, etc + TMLEqCompDataValues(); + TMLEqCompDataValues(TMLEqCompDataLine* aLine); + virtual ~TMLEqCompDataValues(); + bool operator==(const TMLEqCompDataValues& aOther) const; + +public: // new methods + bool Merge(TMLEqCompDataLine* aLine, string aName, TMLEqCompDataValues& aOtherValues, bool aMirrorMerge); + void Compile(int aOptionSetId); + static string CppValue(const string& aValue); + static string MirrorJustificationValue(const string& aValue); + +public: // member data + TMLEqCompDataLine* iLine; // not owned + TMLEqCompDataValuesOptionSets iOptionSets; // owned + string iName; + }; + + +// +// Parent Info +// + +/** +* TMLEqCompDataParentInfoSelector +* +* The parent id and parent variety index for each variety index +*/ +struct TMLEqCompDataParentInfoSelector + { +public: + TMLEqCompDataParentInfoSelector(); + TMLEqCompDataParentInfoSelector(int aParentId, int aParentVariety); +public: + int iParentId; + int iParentVariety; + }; + +typedef map TMLEqCompDataParentInfoVarieties; + +/** +* TMLEqCompDataParentInfo +* +* Contains the parent info selector for each variety index +*/ +class TMLEqCompDataParentInfo : public TMLEqCompDataParentInfoVarieties + { +public: // constructors etc + TMLEqCompDataParentInfo(); + TMLEqCompDataParentInfo(TMLEqCompDataLine* aLine); + virtual ~TMLEqCompDataParentInfo(); +public: // new methods + void Merge(const TMLEqCompDataParentInfo& aOther); +public: // member data + TMLEqCompDataLine* iLine; // not owned + }; + +class TMLEqCompDataAttributeInfo; + +/** +* TMLEqCompDataLine +* A layout line +*/ +class TMLEqCompDataLine : public map + { +public: + enum TComponentType + { + EUnknownComponent, + EScreenComponent, + EContainerComponent, + EPaneComponent, + EGraphicComponent, + ETextComponent + }; + +public: // constructors etc + TMLEqCompDataLine(); + TMLEqCompDataLine(const TMLEqCompDataLine& aOther); + virtual ~TMLEqCompDataLine(); + + bool operator==(const TMLEqCompDataLine& aOther) const; + static bool lessthan(TMLEqCompDataLine* aLeft, TMLEqCompDataLine* aRight); + bool ValuesEqual(const TMLEqCompDataLine& aOther) const; + +public: // new methods + bool Merge(TMLEqCompDataLine& aOther); + void Compile(int aOptionSetId); + TMLAttributeZoomLevels* GetAttributeZoomLevels(string aAttribName, int aVariety); + +public: // get and set methods + string Name() const; + int NumCols() const; + int NumRows() const; + void SetNumCols(int aNumCols); + void SetNumRows(int aNumRows); + +public: // helpers + int EncodeFontId(int aHeight, int aPosture, int aWeight, int aCategory) const; + bool MatchParams(const TMLEqCompDataLine& aLine) const; + bool MatchNameDiscountingSuffix(const TMLEqCompDataLine& aLine) const; + bool MatchType(const TMLEqCompDataLine& aLine) const; + string NameDiscountingSuffix() const; + string NameSuffix() const; + +private: // helpers + TMLAttributeZoomLevels* GetParentAttributeZoomLevels(string aAttribSetName, int aAttribId, int aVariety); + TMLAttributeZoomLevels* FindAttributeZoomLevels(string aAttribSetName, int aAttribId); + +public: // member data + int iId; + string iName; + TComponentType iType; + int iDrawingOrder; + TMLEqCompDataTable* iParentTable; + TMLEqCompDataParentInfo* iParentInfo;// owned +// TMLEqCompDataAttributeInfo* iAttributeInfo;// owned + bool iIsUnique; + int iGlobalIndex; + bool iIsMirroredHorizontally; // i.e. l and r are swapped + +private: + int iNumCols; // there is always at least one column + int iNumRows; // there is always at least one row + }; + + +// +// Attribute Info +// + +/** +* TMLEqCompDataAttributeInfoSelector +* +* Contains the attribute set name, which is used to +* disambiguate the attribute data for a given component +*/ +struct TMLEqCompDataAttributeInfoSelector + { +public: + TMLEqCompDataAttributeInfoSelector(); + TMLEqCompDataAttributeInfoSelector(string aAttributeSetName); +public: + string iAttributeSetName; + }; + +typedef map TMLEqCompDataAttributeInfoVarieties; + +/** +* TMLEqCompDataAttributeInfo +* +* Contains the attribute info selector for each variety +*/ +class TMLEqCompDataAttributeInfo : public TMLEqCompDataAttributeInfoVarieties + { +public: // constructors etc + TMLEqCompDataAttributeInfo(); + TMLEqCompDataAttributeInfo(TMLEqCompDataLine* aLine); + virtual ~TMLEqCompDataAttributeInfo(); +public: // new methods + void Merge(const TMLEqCompDataAttributeInfo& aOther); +public: // member data + TMLEqCompDataLine* iLine; // not owned + }; + + +typedef vector TMLEqCompDataLines; + +/** + * TMLEqCompDataTableOptionSet + * an option set for a given value, which may apply to either or both orientation + */ +struct TMLEqCompDataTableOptionSet : public TMLEqCompDataLines + { +public: + TMLEqCompDataTableOptionSet(); + TMLEqCompDataTableOptionSet(const TMLEqCompDataTableOptionSet& aOther); + virtual ~TMLEqCompDataTableOptionSet(); + void Compile(int aOptionSetId); +public: + TMLEqCompDataLine* FindLine(int aId) const; +public: + TMLEqCompDataOptionSetOrientation iOrientation; + }; + +typedef map TMLEqCompDataTableOptionSets; + +/** +* TMLEqCompDataTable +* A layout table +*/ +class TMLEqCompDataTable : public TMLEqCompDataTableOptionSets + { +public: // constructors etc + TMLEqCompDataTable(TMLEqCompData* aTables); + TMLEqCompDataTable(TMLEqCompData* aTables, const TMLEqCompDataTable& aOther); + virtual ~TMLEqCompDataTable(); + +public: // new methods + TMLEqCompDataLine* FindLine(const string& aName); + void Merge(TMLEqCompDataTable& aOther); + void Compile(); + void SetDefaultColumnNames(); + +public: // accessors + string Name(); + static bool IsValueColumn(string aName); + static bool IsNumericColumn(string aName); + static bool IsHorizontalColumn(string aName); + static bool IsVerticalColumn(string aName); + +public: // member data + int iId; + string iName; + TMLEqCompData* iTables; + vector iColumnNames; + TMLEqCompDataLine* iParentLine; // not owned + string iParentName; + }; + + + + +// +// the "List" xml is needed to get the name of each component. +// + +/** +* TMLEqListComponent +* +* This is the component element stored in the list xml. +*/ +struct TMLEqListComponent + { +public: + TMLEqListComponent(); +public: + int iId; + string iName; + }; + +// +// the "ParChild" xml is needed to get the parent relations +// + +/** +* TMLEqParChildComponent +* +* This is the component element stored in the parent chlid xml. +*/ +struct TMLEqParChildComponent + { +public: + TMLEqParChildComponent(); +public: + int iId; + int iParentId; + }; + + + +/** + * TMLEqCompData + * + * The core layout class - this represents a complete master layout, + * typically loaded from a .xml file that has been extracted from the internal + * xml data of the layout tool + */ +class TMLEqCompData : public vector + { +public: + typedef map TMLEqListComponents; + typedef map TMLEqCompDataComponents; + typedef map TMLEqParChildComponents; + +public: // constructors + TMLEqCompData(); + TMLEqCompData(const TMLEqCompData& aOther); + TMLEqCompData& operator=(const TMLEqCompData& aOther); + +public: // new methods + virtual ~TMLEqCompData(); + TMLEqCompDataLine* FindComponent(const string& aName) const; + TMLEqCompDataLine* FindLine(const string& aName) const; + TMLEqCompDataTable* FindTable(int aId) const; + TMLEqCompDataTable* FindTable(const string& aName) const; + void Merge(TMLEqCompData& aOther); + void MergeComponents(TMLEqCompData& aOther); + void Compile(); + void UpdateNames(); + void CreateTables(); + void DeleteComponents(); + +public: // member data + string iName; + bool iCanBeMirror; + string iMasterName; + string iLayoutName; + string iVariantName; + string iResolutionHeight; + string iResolutionWidth; + string iTimestamp; + TMLEqListComponents iListComponents; // this is used to accumulate the lines from the , which are then compiled into tables + TMLEqCompDataComponents iComponents; // this is used to accumulate the lines, which are then compiled into tables + TMLEqParChildComponents iParChildComponents; // this is used to accumulate the lines, which are then compiled into tables + bool iIsBaseInstance; + TMLAttributes* iAttributes; // owned + }; + + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLEqCompData2DHuiML.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLEqCompData2DHuiML.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MLEQCOMPDATA2DHUIML_H +#define MLEQCOMPDATA2DHUIML_H + +#include +#include +#include +#include "MLEqCompData.h" +using namespace std; + + +class TEqLayoutSaxWriter; + +/** +* MLEqCompDataToDHuiML +* Generate a CDL interface for a layout +*/ +class MLEqCompDataToDHuiML + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + + static void LayoutTablesToDeclarative(TEqLayoutSaxWriter& aSaxWriter, const TMLEqCompData& aLayout); + static void LayoutComponentsToDeclarative(TEqLayoutSaxWriter& aSaxWriter, const TMLEqCompData& aLayout); + + static void AddTableToDeclarative(TEqLayoutSaxWriter& aSaxWriter, TMLEqCompDataTable& aTable); + static void AddLineToDeclarative(TEqLayoutSaxWriter& aSaxWriter, TMLEqCompDataLine& aLine, int aOptionSetId); + static void AddCellToDeclarative(TEqLayoutSaxWriter& aSaxWriter, TMLEqCompDataValues& aValues, const string& aCellName, int aOptionSetId); + static void AddFormulaToDeclarative(TEqLayoutSaxWriter& aSaxWriter, const TMLEqCompDataFormula& aFormula); + +private: + static void ConvertPositionValueStr(std::string& aValueStr); + }; + + +#endif // MLEQCOMPDATA2DHUIML_H diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MLEqCompDataParse.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MLEqCompDataParse.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,197 @@ +/* +* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +#ifndef MLEQCOMPDATAPARSE_H +#define MLEQCOMPDATAPARSE_H + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "LayoutCompilerErr.h" +#include "MLEqCompData.h" + +#include // for logical font ids + +#include "SaxErrorHandler.h" + +#include +#include +#include +#include + +using namespace std; + + +// +// defines +// +#define ELayoutCompilerFontCategoryUndefined KAknFontCategoryUndefined /* 0 */ +#define ELayoutCompilerFontCategoryPrimary KAknFontCategoryPrimary /* 1*/ +#define ELayoutCompilerFontCategorySecondary KAknFontCategorySecondary /* 2 */ +#define ELayoutCompilerFontCategoryTitle KAknFontCategoryTitle /* 3 */ +#define ELayoutCompilerFontCategoryPrimarySmall KAknFontCategoryPrimarySmall /* 4 */ +#define ELayoutCompilerFontCategoryDigital KAknFontCategoryDigital /* 5 */ + + +class MSaxLayoutEqHandler + { +public: + typedef SAX::basic_Attributes TAttribs; + virtual MSaxLayoutEqHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs) { return this; }; + virtual void HandleSaxEnd(const std::string& aElement) { }; + }; + + + +class TMLEqCompDataParseFormula : public TMLEqCompDataFormula, public MSaxLayoutEqHandler + { +public: + TMLEqCompDataParseFormula(); +public: // from MSaxLayoutEqHandler + MSaxLayoutEqHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); +public: + void HandleSaxEnd(const std::string& aElement); + void HandleSaxFormulaAttributes(const std::string& aElement, const TAttribs& aAttribs); +private: + string iSaxFormulaString; + }; + + +class TMLEqCompDataParseValuesOptionSet : public TMLEqCompDataValuesOptionSet, public MSaxLayoutEqHandler + { +public: + TMLEqCompDataParseValuesOptionSet(); +public: // from MSaxLayoutEqHandler + MSaxLayoutEqHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); +public: + void HandleSaxEnd(const std::string& aElement); + void HandleSaxOptionSetNo(const std::string& aElement, const TAttribs& aAttribs); + MSaxLayoutEqHandler* HandleSaxFormula(const std::string& aElement, const TAttribs& aAttribs); +public: + int OptionSetNo() const {return iSaxOptionSetNo;} +private: + TMLEqCompDataParseFormula* iSaxFormula; + int iSaxFormulaNo; + int iSaxOptionSetNo; + }; + +// this corresponds to a "param" in the xml +class TMLEqCompDataParseValues : public TMLEqCompDataValues, public MSaxLayoutEqHandler + { +public: + TMLEqCompDataParseValues(TMLEqCompDataLine* aLine); + static int ConvertZoomStr(const std::string& aValueStr); +public: // from MSaxLayoutEqHandler + MSaxLayoutEqHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); +private: + void HandleSaxEnd(const std::string& aElement); + MSaxLayoutEqHandler* HandleSaxOptionSet(const std::string& aElement, const TAttribs& aAttribs); +private: + void ConvertValueStr(std::string& aValueStr); +private: + TMLEqCompDataParseValuesOptionSet* iSaxOptionSet; + }; + + +// this corresponds to a "component" in the xml +class TMLEqCompDataParseLine : public TMLEqCompDataLine, public MSaxLayoutEqHandler + { +public: + TMLEqCompDataParseLine(); + string ShortParamName(string& aName); +public: // from MSaxLayoutEqHandler + MSaxLayoutEqHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); +private: + void HandleSaxEnd(const std::string& aElement); + void HandleSaxAttributes(const TAttribs& aAttribs); +// MSaxLayoutEqHandler* HandleSaxParent(const std::string& aElement, const TAttribs& aAttribs); + MSaxLayoutEqHandler* HandleSaxParam(const std::string& aElement, const TAttribs& aAttribs); +// MSaxLayoutEqHandler* HandleSaxAttributeInfo(const std::string& aElement, const TAttribs& aAttribs); +private: + TMLEqCompDataParseValues* iSaxValues; +// TMLEqCompDataParseParentInfo* iSaxParentInfo; +// TMLEqCompDataParseAttributeInfo* iSaxAttributeInfo; + }; + + +// This is the component element stored in the list xml. +class TMLEqListParseComponent : public TMLEqListComponent, public MSaxLayoutEqHandler + { +public: + TMLEqListParseComponent(); +public: // from MSaxLayoutEqHandler + MSaxLayoutEqHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); + void HandleSaxEnd(const std::string& aElement); + }; + + +// This is the component element stored in the list xml. +class TMLEqParChildParseComponent : public TMLEqParChildComponent, public MSaxLayoutEqHandler + { +public: + TMLEqParChildParseComponent(); +public: // from MSaxLayoutEqHandler + MSaxLayoutEqHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); + void HandleSaxEnd(const std::string& aElement); +private: + void HandleSaxParent(const std::string& aElement, const TAttribs& aAttribs); + }; + +// this corresponds to a layout in the xml +class TMLEqCompDataParseLayout : public TMLEqCompData, public MSaxLayoutEqHandler + { +public: + static auto_ptr Parse(const string& aListName, const string& aCompDataName, const string& aParChildName); +public: // from MSaxLayoutEqHandler + MSaxLayoutEqHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs); + void HandleSaxEnd(const std::string& aElement); +private: + MSaxLayoutEqHandler* HandleSaxComponent(const std::string& aElement, const TAttribs& aAttribs); +private: + TMLEqCompDataParseLine* iSaxLine; + string iSaxLayoutType; + }; + + +class TEqLayoutSaxParser : private SAX::basic_DefaultHandler + { +private: + typedef stack TSaxHandlerStack; + typedef SAX::basic_ErrorHandler::SAXParseExceptionT TException; + +public: + TEqLayoutSaxParser(MSaxLayoutEqHandler* aHandler); + void Parse(const std::string& aFileName); + +private: // from basic_DefaultHandler + void startElement(const std::string& namespaceURI, const std::string& localName, const std::string& qName, const SAX::basic_Attributes& atts); + void endElement(const std::string& namespaceURI, const std::string& localName, const std::string& qName); + + void warning(const TException& aException); + void error(const TException& aException); + void fatalError(const TException& aException); + +private: + TSaxHandlerStack iStack; // stack content not owned + }; + + +#endif // MLEQCOMPDATAPARSE_H + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MakeLayConvTest.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MakeLayConvTest.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MAKELAYCONVTEST_H +#define MAKELAYCONVTEST_H + +#include +#include +#include +#include "Layout.h" +using namespace std; + +#include +#include +#include +using namespace CdlCompilerToolkit; + + +/** +* MakeLayoutConvTest +* Generate test code to test the validity of the conversion from the older +* AknLayout system to AknLayout2 +*/ +class MakeLayoutConvTest + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + + MakeLayoutConvTest(CCdlTkInterface& aInterface, TLayout& aLayout); + ~MakeLayoutConvTest(); + void RunProcess(); + +private: + void AddTableToTest(TLayoutTable& aTable); + void WriteTestFiles(); + void WriteTestFile(const string& aFileName, const string& iContent); + void InitFiles(); + void CompleteFiles(); + void AddLineToTest(TLayoutLine& aLine); + void AddTest(TLayoutLine& aLine, const CCdlTkFunctionApi& aApi); + const CCdlTkFunctionApi* FindApi(const string& aName); + + void AddTestToOldH(TLayoutLine& aLine, const CCdlTkFunctionApi& aApi); + void AddTestToOldCpp(TLayoutLine& aLine, const CCdlTkFunctionApi& aApi); + void AddTestFunc(TLayoutLine& aLine, const CCdlTkFunctionApi& aApi); + + string OldFuncSig(TLayoutLine& aLine, const CCdlTkFunctionApi& aApi); + +private: + CCdlTkInterface& iInterface; + TLayout& iLayout; + string iOldH; + string iOldCpp; + string iFuncs; + string iTests; + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/MasterLayoutPack.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/MasterLayoutPack.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MASTERLAYOUTPACK_H +#define MASTERLAYOUTPACK_H + +#include +#include +#include +using namespace std; + +#include +#include +#include +using namespace CdlCompilerToolkit; + +/** +* MasterLayoutPackage +* Write a master layout package according to the MasterLayoutPack.cdl interface +*/ +class MasterLayoutPackage + { +public: + static int Process(vector& args); + static void ShowHelp(ostream& stream); + }; + + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/SaxErrorHandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/SaxErrorHandler.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Defines the entry point for the console application +* +*/ + + + +// +// class SAXErrorHandler +// + +#ifndef __SAXERRORHANDLER_H_ +#define __SAXERRORHANDLER_H_ + +#include + +class SAXErrorHandler : public SAX::ErrorHandler + { +public: + SAXErrorHandler() { } + virtual ~SAXErrorHandler() { } +public: // from SAX::ErrorHandler + virtual void warning(const SAX::SAXParseException&); + virtual void error(const SAX::SAXParseException&); + virtual void fatalError(const SAX::SAXParseException& exception); + }; + +#endif // __SAXERRORHANDLER_H_ \ No newline at end of file diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/Script.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/Script.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef SCRIPT_H +#define SCRIPT_H + +#include +#include +#include +using namespace std; + +/** +* AknLayoutCompilerScript +* Intended to be a script interpreter for the layout compiler - not yet complete +*/ +class AknLayoutCompilerScript + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + + AknLayoutCompilerScript(istream& aIn); + void Process(); + +private: + void ProcessLine(string& aLine); + void Process(const string& aFunc, const vector& aParamList, const string& aResult); + +private: + istream& iIn; + }; + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/UpdateLayoutApi.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/UpdateLayoutApi.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,84 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef UPDATELAYOUTAPI_H +#define UPDATELAYOUTAPI_H + +#include +#include +#include +#include "Layout.h" +using namespace std; + +#include +#include +using namespace CdlCompilerToolkit; + +/** +* UpdateLayoutApi +* Intended to update a CDL interface for a layout - not yet complete +*/ +class UpdateLayoutApi : public MCdlTkApiCheckObserver + { +public: + static int Process(const vector& args); + static void ShowHelp(ostream& stream); + + UpdateLayoutApi(const std::string& aCdlName, const std::string& aLayoutName, const std::string& aLegacyName, const std::string& aNewName); + ~UpdateLayoutApi(); + +private: + void LoadFiles(const std::string& aLayoutName, const std::string& aNewName); + void MergeAndCheck(); + void ProcessNewApi(); + void WriteFiles(); + void Report(); + void AddDataToLegacy(const std::string& aOldName, const std::string& aNewName); + +private: + virtual void StartCheck(); + virtual void CheckComplete(); + virtual void ApiInBoth(const CCdlTkApi& aApi); + virtual void ApiNotInLeft(const CCdlTkApi& aApi); + virtual void ApiNotInRight(const CCdlTkApi& aApi); + +private: + class InterfaceCheck : public MCdlTkApiCheckObserver + { + virtual void StartCheck(); + virtual void CheckComplete(); + virtual void ApiInBoth(const CCdlTkApi& aApi); + virtual void ApiNotInLeft(const CCdlTkApi& aApi); + virtual void ApiNotInRight(const CCdlTkApi& aApi); + }; + +private: + std::string iLegacyName; + std::string iCdlName; + CCdlTkInterface* iInterface; + TLayout* iLayout; + TLayout* iLegacy; + TLayout* iNew; + CCdlTkInterface* iExt; // not owned + bool iInterfaceChanged; + bool iLegacyUpdated; + string iReport; + }; + + +#endif diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/UsefulDefinitions.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/UsefulDefinitions.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef USEFULDEFINITIONS_H +#define USEFULDEFINITIONS_H + +#define ARRAY_LEN(x) (sizeof(x)/sizeof(*(x))) +#define ARRAY_END(x) (x+(sizeof(x)/sizeof(*(x)))) + + +#endif // USEFULDEFINITIONS_H diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/WriterBase.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/WriterBase.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef WRITERBASE_H +#define WRITERBASE_H + +#include "layout.h" + +/** +* TWriterBase +* Base class for layout writers +*/ +class TWriterBase + { +public: + TWriterBase(const std::string& aName); + virtual ~TWriterBase(); + virtual void Write(const std::string& aLayName) = 0; +protected: + string iName; + }; + +class TLayWriterBase : public TWriterBase + { +public: + TLayWriterBase(TLayout& aLayout, const std::string& aName); + virtual ~TLayWriterBase(); + virtual void Write(const std::string& aLayName) = 0; +protected: + TLayout& iLayout; + }; + +template +class TMLWriterBase : public TWriterBase + { +public: + TMLWriterBase(T& aLayout, const std::string& aName) : TWriterBase(aName), iLayout(aLayout) {}; + virtual ~TMLWriterBase() {}; + virtual void Write(const std::string& aLayName) = 0; +protected: + T& iLayout; + }; + +#endif + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/inc/ZoomLevelNames.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/inc/ZoomLevelNames.h Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef ZOOMLEVELNAMES_H +#define ZOOMLEVELNAMES_H + +#include +#include +#include +using namespace std; + +/* + * CZoomLevelNames + */ +class CZoomLevelNames : public map + { +public: + // ProcessOptions will remove "-z" from aArgs + void ProcessOptions(vector& aArgs); + }; + +#endif \ No newline at end of file diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/AdaptationLayerTemplate.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/AdaptationLayerTemplate.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,256 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "AdaptationLayerTemplate.h" +#include "LayoutCompilerErr.h" +#include "LayoutParse.h" +#include "LayoutWriter.h" +#include "CppWriter.h" +#include "Lay2Cdl.h" +#include +#include +#include +#include +#include "CodeGenConsts.h" +using namespace std; +using namespace CdlCompilerToolkit; + +typedef LayoutProcessArgsErr AdaptationLayerTemplateArgsErr; + + + + +int AdaptationLayerTemplate::Process(const vector& args) + { + if (args.size() < 6) + throw AdaptationLayerTemplateArgsErr(); + + string layName = args[2]; + auto_ptr layoutParse = TLayParseLayout::Parse(layName); + + string layCdlName = args[3]; + CCdlTkCdlFileParser layCdlParser(layCdlName); + auto_ptr layIface(layCdlParser.LoadAndParse(true)); + + string scaleCdlName = args[4]; + CCdlTkCdlFileParser scaleCdlParser(scaleCdlName); + auto_ptr scaleIface(scaleCdlParser.LoadAndParse(true)); + + string instName = args[5]; + auto_ptr inst(new CCdlTkInstance(*layIface)); + inst->SetName(instName); + inst->TemplateAllImplementations(); + + string existing; + if (args.size() == 8) + { + string inputName = args[6]; + CdlTkUtil::ReadFile(existing, inputName); + } + + AdaptationLayerTemplate process(*layoutParse, *layIface, *scaleIface, *inst, existing); + process.Process(); + + CCdlTkWriteInstance writer(*inst); + writer.Process(); + + if (args.size() == 8) + { + string outputName = args[7]; + CdlTkUtil::WriteFile(existing, outputName); + } + + return 0; + } + +void AdaptationLayerTemplate::ShowHelp(ostream& stream) + { + stream << "AdaptationLayerTemplate [ ]" << endl; + stream << " Creates a template layout adaptation layer implementation." << endl; + } + + +AdaptationLayerTemplate::AdaptationLayerTemplate(TLayout& aLayout, CCdlTkInterface& aLayIface, CCdlTkInterface& aScaleIface, CCdlTkInstance& aInstance, string& aExisting) +: iLayout(aLayout), iLayIface(aLayIface), iScaleIface(aScaleIface), iInstance(aInstance), iExisting(aExisting) + { + } + +AdaptationLayerTemplate::~AdaptationLayerTemplate() + { + } + +void AdaptationLayerTemplate::Process() + { + for (TLayout::iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab) + { + AddTableToInstance(**pTab); + } + } + +void AdaptationLayerTemplate::AddTableToInstance(TLayoutTable& aTable) + { + for (TLayoutTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) + { + TLayoutLine& line = **pLine; + AddLineToInstance(line); + } + } + +void AdaptationLayerTemplate::AddLineToInstance(TLayoutLine& aLine) + { + string apiName = LayoutToCdl::LineApiName(aLine); + if (!HasApi(apiName)) + return; + CCdlTkImplementation& imp = FindImp(apiName); + SetFuncLine(imp, aLine); + } + +bool AdaptationLayerTemplate::HasApi(const string& aName) + { + return iLayIface.ApiList().Find(aName) != 0; + } + +CCdlTkImplementation& AdaptationLayerTemplate::FindImp(const string& aName) + { + CCdlTkImplementation* impl = iInstance.Impl().Find(aName); + if (!impl) + throw NotFoundErr(aName + " in interface " + iLayIface.FileName()); + return *impl; + } + +int CountMatch(const string& aLeft, const string& aRight) + { + string left(CdlTkUtil::ToLower(aLeft)); + left = CdlTkUtil::Replace("_line_", "", left); + string right(CdlTkUtil::ToLower(aRight)); + + int count = 0; + int subLen = 3; + int leftSize = left.size(); + const int maxPossibleHits = (leftSize + 1 - subLen); + for (int ii=0; ii AdaptationLayerTemplate::GetApiMatch(const string& aName) + { + int size = aName.size(); + CCdlTkApiList& apiList = iScaleIface.ApiList(); + string bestMatch; + int bestScore = 0; + for (CCdlTkApiList::iterator pApi = apiList.begin(); pApi != apiList.end(); ++pApi) + { + CCdlTkApi& api = **pApi; + string name = api.Name(); + if (aName == name) + return make_pair(name,100); + + int score = CountMatch(aName, name); + if (score > bestScore) + { + bestScore = score; + bestMatch = name; + } + } + return make_pair(bestMatch, bestScore); + } + +bool IsValueCell(const string& aCellName) + { + return + (find(KWindowOutputOrder, KWindowOutputOrder+KWindowOutputOrderSize, aCellName) != KWindowOutputOrder+KWindowOutputOrderSize) + || + (find(KTextOutputOrder, KTextOutputOrder+KTextOutputOrderSize, aCellName) != KTextOutputOrder+KTextOutputOrderSize); + } + +const string KUsefulInfo = "\ +// $LAYOUT\n\ +// Remark : $REMARK\n\ +// Parent : $PARENTNAME\n\ +// Parent API : $PARENTAPI\n\ +// Scale API match ($AM%) : $SCALEAPI\n\ +// Scale parent match ($PM%) : $SCALEPARENT\n\ +"; + +void AdaptationLayerTemplate::SetFuncLine(CCdlTkImplementation& aImp, TLayoutLine& aLine) + { + string layout; + for (TLayoutLine::iterator pCell = aLine.begin(); pCell != aLine.end(); ++pCell) + { + const string& cellName = pCell->first; + if (IsValueCell(cellName)) + { + TValues& values = pCell->second; + stringstream s; + TLayoutTableWriter::WriteCell(s, values); + CdlTkUtil::AppendString(layout, cellName); + CdlTkUtil::AppendString(layout, "="); + CdlTkUtil::AppendString(layout, s.str()); + CdlTkUtil::AppendString(layout, " "); + } + } + + string parent; + string parentApi; + if (aLine.iTable && aLine.iTable->iParent) + { + parent = aLine.iTable->iParent->Name(); + parentApi = LayoutToCdl::LineApiName(*aLine.iTable->iParent); + } + + pair apiMatch(GetApiMatch(LayoutToCdl::LineApiName(aLine))); + pair parentMatch(GetApiMatch(parentApi)); + + char apiPercent[12]; + sprintf(apiPercent, "%3d", apiMatch.second); + char parentPercent[12]; + sprintf(parentPercent, "%3d", parentMatch.second); + + CdlTkUtil::CReplaceSet set; + set.Add("$LAYOUT", layout); + set.Add("$REMARK", aLine["Remarks"][0]); + set.Add("$PARENTNAME", parent); + set.Add("$PARENTAPI", parentApi); + set.Add("$SCALEAPI", apiMatch.first); + set.Add("$SCALEPARENT", parentMatch.first); + set.Add("$AM", apiPercent); + set.Add("$PM", parentPercent); + string useful = CdlTkUtil::MultiReplace(set, KUsefulInfo); + + string defn = aImp.Definition(); + string existingTarget = defn.substr(0,defn.find_first_of('(')+1); + string existingSub = useful; + CdlTkUtil::AppendString(existingSub, existingTarget); + iExisting = CdlTkUtil::Replace(existingTarget, existingSub, iExisting); + + CdlTkUtil::AppendString(useful, defn); + aImp.SetDefinition(useful); + } diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/AknLayoutCompiler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/AknLayoutCompiler.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,201 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Defines the entry point for the console application +* +*/ + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +// disable "decorated name length exceeded, name was truncated" warning +#pragma warning (disable:4503) + + +#include +#include +#include +#include +#include "extract.h" +#include "LayoutCompilerErr.h" +#include "Lay2Cdl.h" +#include "Cdl2Lag.h" +#include "LayCdl2Inst.h" +#include "LayCdlCheck.h" +#include "LayoutPack.h" +#include "LayCdl2InstO.h" +#include "MakeLayConvTest.h" +#include "LayScale.h" +#include "AdaptationLayerTemplate.h" +#include "Lay2LayPerf.h" + +#ifdef RD_XML_PARSER_TOOLCHAIN +#include "MLCompData2Cdl.h" +#include "MLCompCdl2InstO.h" +#include "MLCompData2LayPerf.h" +#include "MLEqCompData2DHuiML.h" +#endif + +using namespace std; + +// In debug builds, we want the debugger to catch exceptions. In release mode we want +// to report exceptions to the command line user. +// The EXCEPTION_HANDLING macro flag controls this behavior in main() +#ifndef _DEBUG +#define EXCEPTION_HANDLING +#endif + +class MainArgsErr : public LayoutCompilerErr + { + void Show(ostream& aStream) const; + }; + +void MainArgsErr::Show(ostream& stream) const + { + stream << endl; + stream << "AknLayoutCompiler @scriptfile" << endl; + stream << "AknLayoutCompiler [] [args]" << endl; + stream << " are:" << endl; + stream << " -p has no effect in this version of AknLayoutCompiler." << endl; + stream << " modes are listed below" << endl; + stream << " [args] depends on as listed below" << endl; + LayoutExtract::ShowHelp(stream); + LayoutToCdl::ShowHelp(stream); + CdlToLag::ShowHelp(stream); + LayoutAndCdlToCdlInstance::ShowHelp(stream); + LayCdlCheck::ShowHelp(stream); + LayoutPackage::ShowHelp(stream); + LayoutCdlInstanceOpt::ShowHelp(stream); + MakeLayoutConvTest::ShowHelp(stream); + LayoutScale::ShowHelp(stream); + AdaptationLayerTemplate::ShowHelp(stream); + LayoutToLayPerf::ShowHelp(stream); +#ifdef RD_XML_PARSER_TOOLCHAIN + MLCompDataToCdl::ShowHelp(stream); + MLCompDataCdlInstanceOpt::ShowHelp(stream); + MLEqCompDataToDHuiML::ShowHelp(stream); +#endif + } + +int DoMain(int argc, char* argv[]) + { + CdlTkUtil::SetCommandLine(argc, argv); + + vector args; + copy(argv, argv+argc, back_inserter(args)); + + if (args.size() < 2) + { + throw MainArgsErr(); + } + + if (args[1].size() >= 2 && args[1].substr(0,2) == "-p") + { + CdlTkUtil::SetOutputPath(args[1].substr(2)); + args.erase(args.begin()+1); + } + + string& modeName = CdlTkUtil::ToLower(args[1]); + + if (modeName == "extract") + { + LayoutExtract extract; + return extract.Extract(args); + } + else if (modeName == "lay2cdl") + { + return LayoutToCdl::Process(args); + } + else if (modeName == "cdl2lag") + { + return CdlToLag::Process(args); + } + else if (modeName == "laycdl2inst") + { + return LayoutAndCdlToCdlInstance::Process(args); + } + else if (modeName == "laycdlcheck") + { + return LayCdlCheck::Process(args); + } + else if (modeName == "laypkg") + { + return LayoutPackage::Process(args); + } + else if (modeName == "laycdl2insto") + { + return LayoutCdlInstanceOpt::Process(args); + } + else if (modeName == "makelayconvtest") + { + return MakeLayoutConvTest::Process(args); + } + else if (modeName == "layscale") + { + return LayoutScale::Process(args); + } + else if (modeName == "adaptationlayertemplate") + { + return AdaptationLayerTemplate::Process(args); + } + else if (modeName == "lay2layperf") + { + return LayoutToLayPerf::Process(args); + } +#ifdef RD_XML_PARSER_TOOLCHAIN + else if (modeName == "mlcompdata2cdl") + { + return MLCompDataToCdl::Process(args); + } + else if (modeName == "mlcompcdl2insto") + { + return MLCompDataCdlInstanceOpt::Process(args); + } + else if (modeName == "mlcompdata2layperf") + { + return MLCompDataToLayPerf::Process(args); + } + else if (modeName == "mleqcompdata2dhuiml") + { + return MLEqCompDataToDHuiML::Process(args); + } +#endif + else + { + throw MainArgsErr(); + } + + return 1; + } + +int main(int argc, char* argv[]) + { +#ifdef EXCEPTION_HANDLING + try + { +#endif + return DoMain(argc, argv); +#ifdef EXCEPTION_HANDLING + } + catch (const CdlCompilerToolkitErr& aErr) + { + aErr.Show(cerr); + } + + return 1; +#endif + } + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/Cdl2Lag.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/Cdl2Lag.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,145 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Defines the entry point for the console application +* +*/ + + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "Cdl2Lag.h" +#include "LayoutCompilerErr.h" +#include "CodeGenConsts.h" +#include +using namespace std; +using namespace CdlCompilerToolkit; + +typedef LayoutProcessArgsErr CdlToLagArgsErr; + + +CdlToLag::CdlToLag(ofstream& aLag, const string& aLagName) +: iLag(aLag), iLagName(aLagName) + { + } + +int CdlToLag::Process(const vector& args) + { + if (args.size() < 4) + throw CdlToLagArgsErr(); + + string lagName = args[2]; + ofstream lag; + CCdlTkFileCleanup temp; + CdlTkUtil::OpenTempOutput(lag, temp); + + CdlToLag process(lag, lagName); + process.Start(); + + for (int ii = 3; ii < args.size(); ii++) + { + string cdlName = args[ii]; + CCdlTkCdlFileParser parser(cdlName); + auto_ptr iface(parser.LoadAndParse(true)); + process.AddInterface(*iface); + } + + process.Finish(); + + lag.close(); + CdlTkUtil::ExportFile(temp, KDirEpocSysHeader+CdlTkUtil::StripPath(lagName)); + + return 0; + } + +void CdlToLag::ShowHelp(ostream& stream) + { + stream << "Cdl2Lag " << endl; + } + +void CdlToLag::Start() + { + WriteHeader(); + } + +void CdlToLag::Finish() + { + WriteFooter(); + } + +void CdlToLag::AddInterface(CCdlTkInterface& aInterface) + { + iInterface = &aInterface; + WriteInclude(); + CCdlTkApiList& list = iInterface->ApiList(); + for (CCdlTkApiList::iterator pApi = list.begin(); pApi != list.end(); ++pApi) + { + WriteMacro(**pApi); + } + } + +void CdlToLag::WriteHeader() + { + iLag << "// " << iLagName << " generated by:" << endl; + iLag << "// " << CdlTkUtil::CommandLine() << endl; + string guardName = CdlTkUtil::ToUpper(CdlTkUtil::ToCpp(CdlTkUtil::StripPath(iLagName))); + iLag << "#if !defined(" << guardName << ")" << endl; + iLag << "#define " << guardName << endl; + } + +void CdlToLag::WriteInclude() + { + iLag << "#include <" << CdlTkUtil::StripPath(iInterface->FileName()) << ".h>" << endl; + } + +void CdlToLag::WriteMacro(CCdlTkApi& aApi) + { + string macro = "#define "; + const string& name = aApi.Name(); + string macroName = name; + if (aApi.IsFunc() && aApi.AsFunc().Params().size() && aApi.AsFunc().Params()[0].Name() == KParamLineIndex) + { + macro += "AKN_LAYOUT_TABLE_"; + } + else if (aApi.ReturnType() == KTypeWindowLineLayout) + { + macro += "AKN_LAYOUT_WINDOW_"; + } + else if (aApi.ReturnType() == KTypeTextLineLayout) + { + macro += "AKN_LAYOUT_TEXT_"; + } + else if (aApi.ReturnType() == KTypeLayoutTableLimits) + { + macro += "AKN_LAYOUT_TABLE_LIMITS_"; + } + else + { + macro += "AKN_LAYOUT_MULTILINE_TEXT_"; + macroName = macroName.substr(KFuncMultiline.length()); // remove "Multiline_" + } + + macro += macroName + " " + iInterface->NamespaceName() + "::" + name; + if (aApi.AsFunc().Params().size() == 0) // was once data only API + macro += "()"; + + iLag << macro << endl; + } + +void CdlToLag::WriteFooter() + { + iLag << "#endif" << endl; + } diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/CoreParser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/CoreParser.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,517 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#include "CoreParser.h" +#include +#include +using namespace std; + + +ParseResult::ParseResult() +: iRuleId(0), iStart(0), iEnd(0) + { + } + +bool ParseResult::Matched() const + { + return iRuleId != 0; + } + +ParseResult ParseResult::Fail() + { + ParseResult p; + return p; + } + + +Parser::Parser() +: iOp(ENul), iMatch(0), iSub1(0), iSub2(0), iId(-1) + { + } + +Parser::Parser(const char* aMatch) +: iOp(EExact), iMatch(aMatch), iSub1(0), iSub2(0), iId(-1) + { + } + +Parser::Parser(T0Op aOp) +: iOp(aOp), iMatch(0), iSub1(0), iSub2(0), iId(-1) + { + } + +Parser::Parser(T1Op aOp, const Parser& aSub) +: iOp(aOp), iMatch(0), iSub1(&aSub), iSub2(0), iId(-1) + { + } + +Parser::Parser(T2Op aOp, const Parser& aFirst, const Parser& aRest) +: iOp(aOp), iMatch(0), iSub1(&aFirst), iSub2(&aRest), iId(-1) + { + } + +Parser::Parser(const Parser& aOther) + { + *this = aOther; + } + +const Parser& Parser::operator=(const Parser& aOther) + { + if (this == &aOther) + return *this; + + iOp = aOther.iOp; + iMatch = aOther.iMatch; + iSub1 = 0; + iSub2 = 0; + iSub1 = aOther.iSub1; + iSub2 = aOther.iSub2; + iId = aOther.iId; +// if (aOther.iSub1) +// iSub1 = new Parser(*aOther.iSub1); +// if (aOther.iSub2) +// iSub2 = new Parser(*aOther.iSub2); + + return *this; + } + +Parser::~Parser() + { +// delete iSub1; +// delete iSub2; + } + +Parser Parser::EOS() + { + return Parser(EEos); + } + +Parser Parser::Int() + { + return Parser(EInt); + } + +Parser Parser::Real() + { + return Parser(EReal); + } + +const Parser& Parser::Nul() + { + static Parser nul(ENul); + nul.SetId(0); + return nul; + } + + +ParseResult Parser::Parse(const std::string& aString) const + { + vector stack; + stack.push_back(Step(this, 0, -1)); + TMatchRes res = EContinue; + bool done = false; + + while (!stack.empty() && !done) + { + Step& top = stack.back(); + int topId = stack.size()-1; + switch (res) + { + case EFail: + if (top.iRule->iOp == EAlt && top.iStep < 2) + { + res = top.iRule->ParseStep(topId, aString, top.iPos, stack); + } + else if (top.iRule->iOp == EMult && top.iStep < 2) + { + top.iStep = 2; + res = top.iRule->ParseStep(topId, aString, top.iPos, stack); + } + else + { + if (top.iParent >= 0 && stack[top.iParent].iRule->iOp == ESeq) + stack[top.iParent].iStep--; + stack.pop_back(); + } + break; + + case EPass: + { + int nextSeq = -1; + for (int i=stack.size()-1; nextSeq==-1 && i>=0; i--) + { + if ((stack[i].iRule->iOp == ESeq && stack[i].iStep < 2) || + (stack[i].iRule->iOp == EMult && stack[i].iStep < 3)) + nextSeq = i; + } + if (nextSeq >= 0) + res = stack[nextSeq].iRule->ParseStep(nextSeq, aString, top.iResult.iEnd, stack); + else + done = true; + break; + } + + case EContinue: + res = top.iRule->ParseStep(topId, aString, top.iPos, stack); + break; + } + } + + if (done) + { + for (int i=stack.size()-1; i>=1; i--) + { + Step& step = stack[i]; + Step& parent = stack[step.iParent]; + parent.iResult.iChildren.push_front(step.iResult); + if (parent.iResult.iEnd < step.iResult.iEnd) + parent.iResult.iEnd = step.iResult.iEnd; + } + + return stack[0].iResult; + } + else + return ParseResult::Fail(); + } + +Parser::TMatchRes Parser::ParseStep(int aStepId, const std::string& aString, int aPos, vector& aStack) const + { + Step& step = aStack[aStepId]; + step.iResult.iRuleId = Id(); + + switch (iOp) + { + case EExact: + { + string match(iMatch); + int mLen = match.size(); + if (mLen + aPos > aString.size()) + return EFail; + else if (aString.substr(aPos, mLen) != match) + return EFail; + else + step.iResult.iEnd = aPos + mLen; + return EPass; + } + + case EEos: + { + if (aPos != aString.size()) + return EFail; + else + step.iResult.iEnd = aPos; + return EPass; + } + + case EInt: + { + istringstream strm(aString.substr(aPos)); + int temp; + strm >> temp; + int len = strm.tellg(); + if (len >= 0) + step.iResult.iEnd = aPos + len; + else + return EFail; + return EPass; + } + + case EReal: + { + istringstream strm(aString.substr(aPos)); + double temp; + strm >> temp; + int len = strm.tellg(); + if (len >= 0) + step.iResult.iEnd = aPos + len; + else + return EFail; + return EPass; + } + + case ENul: + { + step.iResult.iChildren.clear(); + step.iResult.iEnd = aPos; + return EPass; + } + + case EMult: + { +/* Step next(iSub1, aPos, aStepId); + if (step.iStep == 1) + next.iRule = this; + else if (step.iStep == 2) + next.iRule = &Parser::Nul(); + step.iStep++; + aStack.push_back(next); + return EContinue; +*/ + return EFail; + } + + case ESeq: + { + Step next(iSub1, aPos, aStepId); + if (step.iStep == 1) + next.iRule = iSub2; + step.iStep++; + aStack.push_back(next); + return EContinue; + } + + case EAlt: + { + Step next(iSub1, aPos, aStepId); + if (step.iStep == 1) + next.iRule = iSub2; + step.iStep++; + aStack.push_back(next); + return EContinue; + } + } + + return EFail; + } + +int Parser::Id() const + { + return iId; + } + +void Parser::SetId(int aId) + { + iId = aId; + } + + +Parser operator|(const Parser& aFirst, const Parser& aRest) + { + return Parser(Parser::EAlt, aFirst, aRest); + } + +Parser operator>>(const Parser& aFirst, const Parser& aRest) + { + return Parser(Parser::ESeq, aFirst, aRest); + } + +/*Parser operator*(const Parser& aSub) + { + return Parser(Parser::EMult, aSub); + } +*/ + +void DoPrint(const ParseResult& res) + { + cout << res.iRuleId << " " << res.iStart << "..." << res.iEnd << " "; + if (res.iChildren.size()) + { + cout << "{ "; + for (int i=0; i> Parser("B"); + res = p.Parse("A"); Print(res); + res = p.Parse("B"); Print(res); + res = p.Parse("AB"); Print(res); + res = p.Parse("BA"); Print(res); + res = p.Parse("C"); Print(res); + + p = Parser("A") >> Parser("B") >> Parser("C"); + res = p.Parse("A"); Print(res); + res = p.Parse("B"); Print(res); + res = p.Parse("AB"); Print(res); + res = p.Parse("ABC"); Print(res); + res = p.Parse("ABCD"); Print(res); + res = p.Parse("BAC"); Print(res); + res = p.Parse("D"); Print(res); + + p = Parser("A") >> Parser("B") >> Parser("A") >> Parser::EOS(); + res = p.Parse("A"); Print(res); + res = p.Parse("B"); Print(res); + res = p.Parse("AB"); Print(res); + res = p.Parse("BA"); Print(res); + res = p.Parse("ABA"); Print(res); + res = p.Parse("ABAB"); Print(res); + res = p.Parse("C"); Print(res); + + p = (Parser("A") | Parser("B")) >> Parser("C"); + res = p.Parse("A"); Print(res); + res = p.Parse("B"); Print(res); + res = p.Parse("AC"); Print(res); + res = p.Parse("BC"); Print(res); + res = p.Parse("BA"); Print(res); + res = p.Parse("C"); Print(res); + res = p.Parse("CC"); Print(res); + + p = Parser("A") >> (Parser("B") | Parser("BB")) >> Parser::EOS(); + res = p.Parse("A"); Print(res); + res = p.Parse("AB"); Print(res); + res = p.Parse("ABB"); Print(res); + res = p.Parse("ABBB"); Print(res); + + p = Parser("A") >> (Parser("B") | Parser("C")) >> (Parser("D") | Parser("E")) >> Parser::EOS(); + res = p.Parse("A"); Print(res); + res = p.Parse("AB"); Print(res); + res = p.Parse("AC"); Print(res); + res = p.Parse("AD"); Print(res); + res = p.Parse("AE"); Print(res); + res = p.Parse("ABD"); Print(res); + res = p.Parse("ABE"); Print(res); + res = p.Parse("ACD"); Print(res); + res = p.Parse("ACE"); Print(res); + res = p.Parse("ADB"); Print(res); + res = p.Parse("AEB"); Print(res); + res = p.Parse("ADC"); Print(res); + res = p.Parse("AEC"); Print(res); + res = p.Parse("ABDB"); Print(res); + res = p.Parse("ABEC"); Print(res); + res = p.Parse("ACDE"); Print(res); + res = p.Parse("ACEE"); Print(res); + + p = Parser("A") | Parser("B"); + Parser q = p >> p; + cout << p.Id() << endl; + cout << q.Id() << endl; + res = q.Parse("A"); Print(res); + res = q.Parse("B"); Print(res); + res = q.Parse("AA"); Print(res); + res = q.Parse("AB"); Print(res); + res = q.Parse("BA"); Print(res); + res = q.Parse("BB"); Print(res); + res = q.Parse("AC"); Print(res); + res = q.Parse("CA"); Print(res); + + q = Parser("A") >> p; + p = q | Parser::Nul(); + res = p.Parse("A"); Print(res); + res = p.Parse("B"); Print(res); + res = p.Parse("AA"); Print(res); + res = p.Parse(""); Print(res); + + Parser r = Parser::Nul(); + q = Parser("A") >> r; + r = q | Parser::Nul(); + p = r >> Parser::EOS(); + res = p.Parse("A"); Print(res); + res = p.Parse("B"); Print(res); + res = p.Parse("AA"); Print(res); + res = p.Parse("AAB"); Print(res); + res = p.Parse(""); Print(res); + + p = Parser("B") >> r >> Parser("B"); + res = p.Parse("B"); Print(res); + res = p.Parse("BB"); Print(res); + res = p.Parse("BAB"); Print(res); + res = p.Parse("BAAB"); Print(res); + res = p.Parse("BAAAB"); Print(res); + + p = r >> Parser("AAB"); + res = p.Parse("B"); Print(res); + res = p.Parse("AB"); Print(res); + res = p.Parse("AAB"); Print(res); + res = p.Parse("AAAB"); Print(res); + res = p.Parse("AAAAB"); Print(res); + + p = Parser::Int(); + res = p.Parse("1"); Print(res); + res = p.Parse("a"); Print(res); + res = p.Parse("123"); Print(res); + res = p.Parse("123ab"); Print(res); + res = p.Parse(""); Print(res); + + p = Parser::Real(); + res = p.Parse("1"); Print(res); + res = p.Parse("1.0"); Print(res); + res = p.Parse(".01"); Print(res); + res = p.Parse("1e9"); Print(res); + res = p.Parse("a"); Print(res); + res = p.Parse("123"); Print(res); + res = p.Parse("123ab"); Print(res); + res = p.Parse(""); Print(res); + + + // unsupported * +/* p = *Parser("A"); + res = p.Parse("A"); Print(res); + res = p.Parse("B"); Print(res); + res = p.Parse("AA"); Print(res); + res = p.Parse(""); Print(res); + + p = *Parser("A") >> Parser::EOS(); + res = p.Parse("A"); Print(res); + res = p.Parse("B"); Print(res); + res = p.Parse("AA"); Print(res); + res = p.Parse("AAB"); Print(res); + res = p.Parse(""); Print(res); + + p = Parser("B") >> *Parser("A") >> Parser("B"); + res = p.Parse("B"); Print(res); + res = p.Parse("BB"); Print(res); + res = p.Parse("BAB"); Print(res); + res = p.Parse("BAAB"); Print(res); + res = p.Parse("BAAAB"); Print(res); + + p = *Parser("A") >> Parser("AB"); + res = p.Parse("B"); Print(res); + res = p.Parse("AB"); Print(res); + res = p.Parse("AAB"); Print(res); + res = p.Parse("AAAB"); Print(res); + res = p.Parse("AAAAB"); Print(res); +*/ + return 0; + } +/* +Parser p = Parser("A") >> (Parser("B") | Parser("C")) >> (Parser("D") | Parser("E")) >> Parser("F"); +Parser q = p | (p >> q); +int TestFormulaTreeNode() + { + + ParseResult res; + res = q.Parse("ACEFACEF"); Print(res); + return 0; + } +*/ +// note, uncomment this line to execute test code +//int x = TestParser(); diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/CppWriter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/CppWriter.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,709 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +#include "CppWriter.h" +#include "layoutcompilererr.h" +#include "CodeGenConsts.h" +#include "UsefulDefinitions.h" + +#include + +#include +#include +#include // !!! for debug output only + +using namespace CdlCompilerToolkit; + +string whiteSpace = " \t\r\n"; + +const string KTextOutputOrder[] = {"C", "l", "r", "B", "W", "J", "Font"}; +const string KTextOutputOrderMirrored[] = {"C", "r", "l", "B", "W", "J", "Font"}; +const int KTextOutputOrderSize = ARRAY_LEN(KTextOutputOrder); + +const string KWindowOutputOrder[] = {"C", "l", "t", "r", "b", "W", "H"}; +const string KWindowOutputOrderMirrored[] = {"C", "r", "t", "l", "b", "W", "H"}; +const int KWindowOutputOrderSize = ARRAY_LEN(KWindowOutputOrder); + +// class TValuesCppWriter +void TValuesCppWriter::WriteCpp(ostream& aCpp) + { + for (TValues::const_iterator it = iValues.begin(); it != iValues.end(); ++it) + { + if (it != iValues.begin()) + aCpp << ", "; + aCpp << TValues::CppValue(*it); + } + } + + +// class TLayoutLineCppWriter + +void TLayoutLineCppWriter::WriteCpp(ostream& aCpp) + { + // write line structure + WriteLineClassName(aCpp); + aCpp << Name() << " = { "; + WriteCppData(aCpp); + aCpp << " };" << endl << endl; + } + + +void TLayoutLineCppWriter::WriteCppData(ostream& aCpp) + { + if (iLine.iNeedsIndex) + WriteVarCppData(aCpp); + else + WriteFixedCppData(aCpp); + } + + +int TLayoutLineCppWriter::WriteParamList(ostream& aLag, const vector& aParams) + { + int written = 0; + if (aParams.size() > 0) + { + written = 2*aParams.size(); + aLag << "("; + for (vector::const_iterator pParam = aParams.begin(); pParam != aParams.end(); ++pParam) + { + if (pParam != aParams.begin()) + aLag << ", "; + aLag << *pParam; + written += pParam->size(); + } + aLag << ")"; + } + return written; + } + +int TLayoutLineCppWriter::ValCount() + { + int count = 0; + for (TLayoutLine::const_iterator pVal = iLine.begin(); pVal != iLine.end(); ++pVal) + { + if (TLayoutTable::IsValueColumn(pVal->first)) + count += pVal->second.size(); + } + return count; + } + + +// class TWindowLineCppWriter + +string TWindowLineCppWriter::Name() + { + if (iLine.iIsUnique) + return CdlTkUtil::ToCpp(iLine.Name()); + else + return CdlTkUtil::ToCpp(iLine.TableName()); + } + +void TWindowLineCppWriter::WriteLineClassName(ostream& aCpp) + { + if (iLine.iNeedsIndex) + { + aCpp << "const SVarWindowLine<" << ValCount() << "> "; + } + else + { + aCpp << "const SFixedWindowLine "; + } + } + +void TWindowLineCppWriter::WriteVarCppData(ostream& aCpp) + { + aCpp << " { "; // suppress the first offset + + int offset = 0; + for (int i=0; i0) + aCpp << ", "; + TValuesCppWriter writer(iLine[KWindowOutputOrder[i]]); + writer.WriteCpp(aCpp); + } + } + +void TWindowLineCppWriter::FillParamLists(vector& aDef, vector& aCtor) + { + if (iLine.iNeedsP) + { + aDef.push_back(KParamParentRect); + aCtor.push_back(KParamParentRect); + } + + if (iLine.iNeedsIndex) + { + aCtor.push_back(CdlTkUtil::IntToString(iLine.iIsMirroredHorizontally)); + + for (int i=0; i def_params; + vector ctor_params; + ctor_params.push_back(CdlTkUtil::IntToString(iLine.iGlobalIndex)); + + FillParamLists(def_params, ctor_params); + + aLag << "#define AKN_LAYOUT_WINDOW_" << Name(); + WriteParamList(aLag, def_params); + aLag << "\t" << KTypeWindowLineLayout; + WriteParamList(aLag, ctor_params); + aLag << endl; + } + + +// class TTextLineCppWriter + +string TTextLineCppWriter::Name() + { + return CdlTkUtil::ToCpp(iLine.TableName()); + } + +void TTextLineCppWriter::FillParamLists(vector& aDef, vector& aCtor) + { + iBaseLineVariation = false; + + if (iLine.iNeedsP) + { + aDef.push_back(KParamParentRect); + aCtor.push_back(KParamParentRect); + } + + if (iLine.iNeedsIndex) + { + aCtor.push_back(CdlTkUtil::IntToString(iLine.iIsMirroredHorizontally)); + + for (int i=0; i def_params; + vector ctor_params; + ctor_params.push_back(CdlTkUtil::IntToString(iLine.iGlobalIndex)); + + FillParamLists(def_params, ctor_params); + + aLag << "#define AKN_LAYOUT_TEXT_" << Name(); + WriteParamList(aLag, def_params); + aLag << "\t" << KTypeTextLineLayout; + WriteParamList(aLag, ctor_params); + aLag << endl; + +// Also write out a multiline_text if there are more than one Baselines supplied. Number of lines is always user-supplied + vector multiline_def_params; + vector multiline_ctor_params; + + if ( iBaseLineVariation ) + { + multiline_ctor_params.push_back(CdlTkUtil::IntToString(iLine.iGlobalIndex)); + + if (iLine.iNeedsP) + { + multiline_def_params.push_back(KParamParentRect); + multiline_ctor_params.push_back(KParamParentRect); + } + + if (iLine.iNeedsIndex) // this condition has already been tested when setting iBaseLineVariation, but check again here for completeness + { + multiline_ctor_params.push_back(CdlTkUtil::IntToString(iLine.iIsMirroredHorizontally)); + } + + for (int i=0; i "; + } + else + { + aCpp << "const SFixedTextLine "; + } + } + +void TTextLineCppWriter::WriteVarCppData(ostream& aCpp) + { + aCpp << " { "; // ! Do not write out the first 0 + + int offset = 0; + for (int i=0; i 0 ) + aCpp << ", "; + TValuesCppWriter writer(iLine[KTextOutputOrder[i]]); + writer.WriteCpp(aCpp); + } + } + +void TTextLineCppWriter::WriteMultiLineTextParamList(ostream& aLag, const vector& aParams) + { + if (aParams.size() > 0) + { + aLag << "("; + for (vector::const_iterator pParam = aParams.begin(); pParam != aParams.end(); ++pParam) + { + if (pParam != aParams.begin()) + aLag << ", "; + aLag << *pParam; + } + aLag << ", " << KParamNameNumberOfLinesShown; + aLag << ")"; + } + } + + +// class TLayoutTableCppWriter + +void TLayoutTableCppWriter::WriteCppLineData(ostream& aCpp) + { + for (TLayoutTable::iterator it = iTable.begin(); it != iTable.end(); ++it) + { + TLayoutLineCppWriter* writer = CreateLayoutLineCppWriter(**it, iTable); + writer->WriteCpp(aCpp); + delete writer; + } + } + +void TLayoutTableCppWriter::WriteCppTableData(ostream& aCpp) + { + } + +void TLayoutTableCppWriter::WriteLag(ostream& aLag) + { + aLag << endl; + int count=0; + for (TLayoutTable::TLayoutSubTables::iterator it = iTable.iSubTables.begin(); it != iTable.iSubTables.end(); ++it) + { + WriteLagSubTable(**it, count++, aLag); + } + } + + +void TLayoutTableCppWriter::WriteLagSubTable(const TLayoutTable::TLayoutSubTable& aSubTable, int aCount, ostream& aLag) + { + // normal version + string macro = "#define AKN_LAYOUT_TABLE_"; + macro = macro + CdlTkUtil::ToCpp(iTable.Name()); + if (aSubTable.size() != iTable.size()) + { + macro = macro + "_SUB_TABLE_" + CdlTkUtil::IntToString(aCount); + aLag << "// Sub table for " << iTable.Name() << ". Valid line indices are "; + for (TLayoutTable::TLayoutSubTable::const_iterator pNum = aSubTable.begin(); pNum != aSubTable.end(); ++pNum) + { + if (pNum != aSubTable.begin()) + aLag << ", "; + aLag << CdlTkUtil::IntToString(*pNum); + } + aLag << endl; + } + + aLag << macro; + + int lineSet = 0; + for (TLayoutTable::TLayoutSubTable::const_iterator pNum = aSubTable.begin(); pNum != aSubTable.end(); ++pNum) + { + if (*pNum < 32) + lineSet |= (1 << *pNum); + } + + vector def_params; + def_params.push_back(KParamLineIndex); + vector ctor_params; + ctor_params.push_back(CdlTkUtil::IntToString(iTable.iFirstLineGlobalIndex)); + ctor_params.push_back(KParamLineIndex); + ctor_params.push_back(CdlTkUtil::IntToHexString(lineSet)); + + TLayoutLineCppWriter* writer = CreateLayoutLineCppWriter(*iTable[aSubTable[0]], iTable); + writer->FillParamLists(def_params, ctor_params); + int paramSize = writer->WriteParamList(aLag, def_params); + + // some maths to make bigger tabulation + int numTabs = 6-(((paramSize+macro.size())/4)%6); + for (int i=0; iWriteParamList(aLag, ctor_params); + aLag << endl; + + delete writer; + } + +TLayoutLineCppWriter* TLayoutTableCppWriter::CreateLayoutLineCppWriter(TLayoutLine& aLine, TLayoutTable& aTable) + { + if (aTable.iType == TLayoutTable::EWindowTable) + return new TWindowLineCppWriter(aLine); + else + return new TTextLineCppWriter(aLine); + } + + +// class TLayoutCppWriter + +void TLayoutCppWriter::WriteCppLineData(ostream& aCpp) + { + for (TLayout::iterator it = iLayout.begin(); it != iLayout.end(); ++it) + { + TLayoutTableCppWriter writer(**it); + writer.WriteCppLineData(aCpp); + } + } + +void TLayoutCppWriter::WriteCppTableData(ostream& aCpp) + { + } + +void TLayoutCppWriter::WriteLag(ostream& aLag) + { + aLag << endl << endl << "// Layout MACROs for indexed table access" << endl; + // write the macros + for (TLayout::iterator it = iLayout.begin(); it != iLayout.end(); ++it) + { + TLayoutTable& table = **it; + if (table.IsWorthATableIndex()) + { + TLayoutTableCppWriter writer(table); + writer.WriteLag(aLag); + } + } + + aLag << endl << "#endif " << endl; + } + + +// class TLayoutLineTable + +void TLayoutLineTable::WriteCpp(ostream& aCpp) + { + aCpp << "const TAny* const KTheLineTable[] =" << endl << "\t{" << endl << "\t"; + int index = 0; + for (iterator it = begin(); it != end(); ++it) + { + TLayoutLine& line = **it; + TLayoutTable& table = *line.iTable; + if (table.iFirstLineGlobalIndex == -1) + table.iFirstLineGlobalIndex = index; + TLayoutLineCppWriter* writer = TLayoutTableCppWriter::CreateLayoutLineCppWriter(line, table); + if (it != begin()) + aCpp << "," << endl << "\t"; + aCpp << "&" << writer->Name(); + delete writer; + index++; + } + aCpp << endl << "\t};" << endl; + } + +void TLayoutLineTable::WriteLag(ostream& aLag) + { + string current_table_name = ""; + + for (iterator it = begin(); it != end(); ++it) + { + TLayoutLine& line = **it; + + if ( current_table_name != line.iTable->Name() ) + { + aLag << endl << "//" << " Layout MACROs for LAF Table : " << line.iTable->Name() << endl ; + current_table_name = line.iTable->Name(); + } + + TLayoutLineCppWriter* writer = TLayoutTableCppWriter::CreateLayoutLineCppWriter(line, *line.iTable); + writer->WriteMacro(aLag); + delete writer; + } + } + + +// class TLayoutLineTable + +TCppWriter::TCppWriter(TLayout& aLayout, const std::string& aName) +: TLayWriterBase(aLayout, aName) + { + } + +void TCppWriter::Write(const std::string& aLayName) + { + std::string lay = aLayName.substr(aLayName.find_last_of('\\')+1); + lay = lay.substr(0, lay.find_first_of('.')); + + iShortName = iName.substr(iName.find_last_of('\\')+1); + iName = iName.substr(0, iName.find_first_of('.')) + lay; + + BuildLayoutLineTable(); + CCdlTkFileCleanup temp(iName+".lag"); + Output(iName+".cpp", iName+".lag", lay); + CdlTkUtil::ExportFile(temp, KDirEpocSysHeader+iShortName+".lag"); + } + +void TCppWriter::Output(const string& aCpp, const string& aLag, const string& aLayName) + { + cout << "writing cpp " << aCpp << endl; + ofstream cpp(aCpp.c_str()); + WriteCppHeader(cpp); + TLayoutCppWriter writer(iLayout); + writer.WriteCppLineData(cpp); + iLineTable.WriteCpp(cpp); + writer.WriteCppTableData(cpp); + WriteCppFooter(cpp, aLayName); + cpp.close(); + + cout << "writing header " << aLag << endl; + ofstream lag(aLag.c_str()); + WriteLagHeader(lag); + iLineTable.WriteLag(lag); + writer.WriteLag(lag); + lag.close(); + } + +void TCppWriter::BuildLayoutLineTable() + { + int globalIndex = 0; + for (TLayout::const_iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab) + { + for (TLayoutTable::const_iterator pLine = (*pTab)->begin(); pLine != (*pTab)->end(); ++pLine) + { + (*pLine)->iGlobalIndex = globalIndex++; + iLineTable.push_back(*pLine); + } + } + } + +void TCppWriter::WriteCppHeader(ostream& aCpp) + { + aCpp << "/*" << endl; + aCpp << "* ============================================================================" << endl; + aCpp << "* Name : " << iShortName << ".cpp" << endl; + aCpp << "* Part of : Avkon" << endl; + aCpp << "*" << endl; + aCpp << "* Description: This file is automatically generated layout data file." << endl; + aCpp << "*" << endl; + aCpp << "* Version :" << endl; + aCpp << "*" << endl; + aCpp << "* Copyright © 2002-2004 Nokia Corporation." << endl; + aCpp << "* This material, including documentation and any related" << endl; + aCpp << "* computer programs, is protected by copyright controlled by" << endl; + aCpp << "* Nokia Corporation. All rights are reserved. Copying,"<< endl; + aCpp << "* including reproducing, storing, adapting or translating, any" << endl; + aCpp << "* or all of this material requires the prior written consent of" << endl; + aCpp << "* Nokia Corporation. This material also contains confidential" << endl; + aCpp << "* information which may not be disclosed to others without the" << endl; + aCpp << "* prior written consent of Nokia Corporation." << endl; + aCpp << "* ============================================================================" << endl; + aCpp << "*/" << endl << endl; + aCpp << "#include \"aknlayoutdatadef.h\"" << endl << endl; + } + +void TCppWriter::WriteCppFooter(ostream& aCpp, const string& aLayName) + { + aCpp << endl << "const TAny* GetData_" << aLayName << "(" << KTypeInt << " aLineId) { return KTheLineTable[aLineId]; }" << endl; + } + +void TCppWriter::WriteLagHeader(ostream& aLag) + { + aLag << "/*" << endl; + aLag << "* ============================================================================" << endl; + aLag << "* Name : " << iShortName << ".lag" << endl; + aLag << "* Part of : Avkon" << endl; + aLag << "*" << endl; + aLag << "* Description: This file is automatically generated layout file." << endl; + aLag << "*" << endl; + aLag << "* Version :" << endl; + aLag << "*" << endl; + aLag << "* Copyright © 2002-2004 Nokia Corporation." << endl; + aLag << "* This material, including documentation and any related" << endl; + aLag << "* computer programs, is protected by copyright controlled by" << endl; + aLag << "* Nokia Corporation. All rights are reserved. Copying,"<< endl; + aLag << "* including reproducing, storing, adapting or translating, any" << endl; + aLag << "* or all of this material requires the prior written consent of" << endl; + aLag << "* Nokia Corporation. This material also contains confidential" << endl; + aLag << "* information which may not be disclosed to others without the" << endl; + aLag << "* ============================================================================" << endl; + aLag << "*/" << endl << endl; + aLag << "#if !defined(__" << iShortName << "_LAG__)" << endl; + aLag << "#define __" << iShortName << "_LAG__" << endl; + aLag << "#include " << endl << endl; + } + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/Extract.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/Extract.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,101 @@ +/* +* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) +#include "Extract.h" +#include "LayoutCompilerErr.h" +#include "HtmlParse.h" +#include "LayoutParse.h" +#include "LayoutWriter.h" +#include +#include + +typedef LayoutProcessArgsErr LayoutExtractArgsErr; + + +int LayoutExtract::Extract(const vector& args) + { + ParseArgs(args); + + THtmlParseLayout html; + ifstream in(iDocName.c_str()); + if (!in.is_open()) + throw NotFoundErr(iDocName); + cout << "reading html " << iDocName << endl; + html.Parse(in); + in.close(); + + TLayout* layout = &html; + TLayParseLayout lay; + if (iMergeName.size()) + { + ifstream merge(iMergeName.c_str()); + if (!merge.is_open()) + throw NotFoundErr(iDocName); + cout << "reading layout " << iMergeName << endl; + lay.Parse(merge); + merge.close(); + + cout << "merging " << iDocName << " into " << iMergeName << endl; + lay.Merge(TLayout::KMergeModeMerge, html); + layout = &lay; + } + + TLayoutWriter writer(*layout, iLayoutName); + writer.Write(""); + + return 0; + } + +void LayoutExtract::ParseArgs(const vector& args) + { + if (args.size() < 4) + throw LayoutExtractArgsErr(); + + iDocName = args[2]; + + int layoutIndex = 3; + if (args[3][0] == '-') + { + if (args[3].size() < 3 || args[3][1] != 'o') + throw LayoutExtractArgsErr(); + + iMergeName = args[3].substr(2); + layoutIndex++; + } + + if (args.size() <= layoutIndex) + throw LayoutExtractArgsErr(); + + iLayoutName = args[layoutIndex]; + } + +void LayoutExtract::ShowHelp(ostream& stream) + { + stream << endl; + stream << "LayoutCompiler extract [-o] " << endl; + stream << " is the name of the HTML Layout specification" << endl; + stream << " is an optional layout file which the extracted layout will be" << endl; + stream << " merged with" << endl; + stream << " is the name of the resulting layout file" << endl; + stream << " You can use the same name for and " << endl; + } + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/FormulaParser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/FormulaParser.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,150 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#include "FormulaParser.h" + + +ParseResult ParseFormula(const string& aFormula) + { + Parser cell_nameParser = Parser("B") | Parser("H") | Parser("L") | Parser("R") | Parser("T") | Parser("W") | Parser("b") | Parser("h") | Parser("l") | Parser("r") | Parser("t") | Parser("w"); + cell_nameParser.SetId(cell_name_ParserId); + Parser parentParser = Parser("P"); + parentParser.SetId(parent_ParserId); + Parser parent_cellParser = parentParser >> Parser("_") >> cell_nameParser; + parent_cellParser.SetId(parent_cell_ParserId); + Parser table_cellParser = Parser::Real(); + table_cellParser.SetId(table_cell_ParserId); + Parser comp_cellParser = Parser::Real() >> Parser("_") >> cell_nameParser; + comp_cellParser.SetId(comp_cell_ParserId); + Parser abs_cellParser = + Parser("$") >> + Parser::Real() >> + Parser("!") >> + Parser::Real() >> + Parser("!") >> + cell_nameParser >> + Parser("!$"); + abs_cellParser.SetId(abs_cell_ParserId); + + // types of value + Parser cellParser = + cell_nameParser | + parent_cellParser | + parentParser | + comp_cellParser | + abs_cellParser | + table_cellParser; + + Parser unitsParser = + Parser::Real() >> + (Parser("u") | Parser("U")); + unitsParser.SetId(units_ParserId); + + Parser constantParser = + Parser::Real() >> + Parser("p"); + constantParser.SetId(constant_ParserId); + + Parser attributeParser = + Parser("pr") >> + Parser::Int(); + attributeParser.SetId(attribute_ParserId); + + Parser mysteryParser = + Parser::Int() >> + Parser("pr") >> + Parser::Int(); + mysteryParser.SetId(mystery_ParserId); + + // functions + Parser expressionParser; + Parser func_nameParser = Parser("CEIL") | Parser("FLOOR") | Parser("ROUND"); + Parser funcParser = func_nameParser >> Parser("(") >> expressionParser >> Parser(")"); + funcParser.SetId(func_ParserId); + + Parser valueParser = + unitsParser | + mysteryParser | + attributeParser | + constantParser | + funcParser | + cellParser ; + + // arithmetic expressions from boost spirit library example + Parser groupParser = Parser("(") >> expressionParser >> Parser(")"); + groupParser.SetId(group_ParserId); + Parser factorParser = valueParser | groupParser; + + Parser termExtStarParser; + Parser termExtParser = + ((Parser("*") >> factorParser) | + (Parser("/") >> factorParser)) >> + termExtStarParser; + termExtStarParser = termExtParser | Parser::Nul(); + + Parser termParser = + factorParser >> + termExtStarParser; + termParser.SetId(term_ParserId); + + Parser expressionExtStarParser; + Parser expressionExtParser = + ((Parser("+") >> termParser) | + (Parser("-") >> termParser)) >> + expressionExtStarParser; + expressionExtStarParser = expressionExtParser | Parser::Nul(); + + expressionParser = + termParser >> + expressionExtStarParser; + expressionParser.SetId(expression_ParserId); + + // comparisons + Parser comp_opParser = Parser(">=") | Parser("<=") | Parser("=") | Parser(">") | Parser("<"); + + Parser whitespaceParser; + Parser compParser = + expressionParser >> + whitespaceParser >> + comp_opParser >> + whitespaceParser >> + expressionParser; + compParser.SetId(comp_ParserId); + + Parser comp_groupParser = Parser("(") >> compParser >> Parser(")"); + comp_groupParser.SetId(comp_group_ParserId); + Parser compOptParser = compParser | comp_groupParser; + + // conditionals + Parser conditionalParser = + Parser("IF ") >> + compOptParser >> + Parser(" THEN ") >> + expressionParser >> + Parser(" ELSE ") >> + expressionParser; + conditionalParser.SetId(conditional_ParserId); + + + Parser whitespaceExtParser = Parser(" ") >> whitespaceParser; + whitespaceParser = whitespaceExtParser | Parser::Nul(); + + // formula + Parser formulaParser = conditionalParser | expressionParser; + + + return formulaParser.Parse(aFormula); + } \ No newline at end of file diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/FormulaTree.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/FormulaTree.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,306 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#include "FormulaTree.h" +#include "FormulaParser.h" +#include +#include +using namespace std; + +FormulaTreeNode* FormulaTreeNode::Parse(const string& aFormula) + { + return NewTree(ParseFormula(aFormula), aFormula); + } + +FormulaTreeNode::~FormulaTreeNode() + { + for (int i=0; i> r; + return r; + } + +double FormulaTreeNode::Real() const + { + double r; + stringstream(Text()) >> r; + return r; + } + +FormulaTreeNode* FormulaTreeNode::NewTree(const ParseResult& aParse, const string& aFormula) + { + FormulaTreeNode* node = 0; + + int parseId = aParse.iRuleId; + if (parseId == cell_name_ParserId) + { + node = new FormulaTreeNode(ECell, aFormula, aParse.iStart, aParse.iEnd-aParse.iStart); + } + else if (parseId == parent_ParserId) + { + node = new FormulaTreeNode(EParent, aFormula, aParse.iStart, aParse.iEnd-aParse.iStart); + } + else if (parseId == parent_cell_ParserId) + { + const ParseResult& cell = aParse.iChildren[1]; + node = new FormulaTreeNode(EParentCell, aFormula, cell.iStart, cell.iEnd-cell.iStart); + } + else if (parseId == table_cell_ParserId) + { + node = new FormulaTreeNode(ETableCell, aFormula, aParse.iStart, aParse.iEnd-aParse.iStart); + } + else if (parseId == comp_cell_ParserId) + { + const ParseResult& cellId = aParse.iChildren[0].iChildren[0]; + node = new FormulaTreeNode(EComponent, aFormula, cellId.iStart, cellId.iEnd-cellId.iStart); + node->iSubNodes.push_back(NewTree(aParse.iChildren[1], aFormula)); + } + else if (parseId == abs_cell_ParserId) + { + node = new FormulaTreeNode(EAbsolute, aFormula, aParse.iStart, aParse.iEnd-aParse.iStart); + const ParseResult& part1 = aParse.iChildren[0].iChildren[0].iChildren[0].iChildren[0].iChildren[0].iChildren[1]; + node->iSubNodes.push_back(new FormulaTreeNode(EReal, aFormula, part1.iStart, part1.iEnd-part1.iStart)); + const ParseResult& part2 = aParse.iChildren[0].iChildren[0].iChildren[0].iChildren[1]; + node->iSubNodes.push_back(new FormulaTreeNode(EReal, aFormula, part2.iStart, part2.iEnd-part2.iStart)); + const ParseResult& part3 = aParse.iChildren[0].iChildren[1]; + node->iSubNodes.push_back(NewTree(part3, aFormula)); + } + else if (parseId == units_ParserId) + { + const ParseResult& units = aParse.iChildren[0]; + node = new FormulaTreeNode(EUnits, aFormula, units.iStart, units.iEnd-units.iStart); + } + else if (parseId == constant_ParserId) + { + const ParseResult& constant = aParse.iChildren[0]; + node = new FormulaTreeNode(EConstant, aFormula, constant.iStart, constant.iEnd-constant.iStart); + } + else if (parseId == attribute_ParserId) + { + const ParseResult& attrib = aParse.iChildren[1]; + node = new FormulaTreeNode(EAttribute, aFormula, attrib.iStart, attrib.iEnd-attrib.iStart); + } + else if (parseId == mystery_ParserId) + { + node = new FormulaTreeNode(EMystery, aFormula, aParse.iStart, aParse.iEnd-aParse.iStart); + const ParseResult& part1 = aParse.iChildren[0].iChildren[0]; + node->iSubNodes.push_back(new FormulaTreeNode(EInt, aFormula, part1.iStart, part1.iEnd-part1.iStart)); + const ParseResult& part2 = aParse.iChildren[1]; + node->iSubNodes.push_back(new FormulaTreeNode(EInt, aFormula, part2.iStart, part2.iEnd-part2.iStart)); + } + else if (parseId == func_ParserId) + { + const ParseResult& funcName = aParse.iChildren[0].iChildren[0].iChildren[0]; + node = new FormulaTreeNode(EFunction, aFormula, funcName.iStart, funcName.iEnd-funcName.iStart); + const ParseResult& expr= aParse.iChildren[0].iChildren[1]; + node->iSubNodes.push_back(NewTree(expr, aFormula)); + } + else if (parseId == group_ParserId) + { + node = NewTree(aParse.iChildren[0].iChildren[1], aFormula); + } + else if (parseId == term_ParserId || parseId == expression_ParserId) + { + node = NewTree(aParse.iChildren[0], aFormula); + const ParseResult* parse = &aParse; + while (parse->iChildren[1].iChildren[0].iRuleId != Parser::Nul().Id()) + { + const ParseResult& oper = parse->iChildren[1].iChildren[0].iChildren[0].iChildren[0].iChildren[0]; + FormulaTreeNode* newNode = new FormulaTreeNode(EArithmetic, aFormula, oper.iStart, oper.iEnd-oper.iStart); + newNode->iSubNodes.push_back(node); + const ParseResult& right = parse->iChildren[1].iChildren[0].iChildren[0].iChildren[0].iChildren[1]; + newNode->iSubNodes.push_back(NewTree(right, aFormula)); + node = newNode; + parse = &parse->iChildren[1].iChildren[0]; + } + } + else if (parseId == comp_group_ParserId) + { + node = NewTree(aParse.iChildren[0].iChildren[1], aFormula); + } + else if (parseId == comp_ParserId) + { + const ParseResult& oper = aParse.iChildren[0].iChildren[0].iChildren[1]; + node = new FormulaTreeNode(ECondition, aFormula, oper.iStart, oper.iEnd-oper.iStart); + const ParseResult& lhs = aParse.iChildren[0].iChildren[0].iChildren[0].iChildren[0]; + node->iSubNodes.push_back(NewTree(lhs, aFormula)); + const ParseResult& rhs = aParse.iChildren[1]; + node->iSubNodes.push_back(NewTree(rhs, aFormula)); + } + else if (parseId == conditional_ParserId) + { + node = new FormulaTreeNode(EConditional, aFormula, aParse.iStart, 0); + const ParseResult& cond = aParse.iChildren[0].iChildren[0].iChildren[0].iChildren[0].iChildren[1]; + node->iSubNodes.push_back(NewTree(cond, aFormula)); + const ParseResult& thenExpr = aParse.iChildren[0].iChildren[0].iChildren[1]; + node->iSubNodes.push_back(NewTree(thenExpr, aFormula)); + const ParseResult& elseExpr = aParse.iChildren[1]; + node->iSubNodes.push_back(NewTree(elseExpr, aFormula)); + } + else // internal alt node, recurse down + { + node = NewTree(aParse.iChildren[0], aFormula); + } + + return node; + } + +FormulaTreeNode::FormulaTreeNode(TNodeType aType, const string& aSource, int aStart, int aLen) +: iSource(aSource), iStart(aStart), iLen(aLen), iType(aType) + { + } + +FormulaTreeNode::FormulaTreeNode(const FormulaTreeNode& aOther) +: iSource(aOther.iSource), iStart(aOther.iStart), iLen(aOther.iLen), iType(aOther.iType) + { + for (int i=0; i +#include +#include +#include +using namespace std; + + +const string WhiteSpace(" \t\r\n"); +const string gValidText("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_<>()-+. "); +const string gValidNum("0123456789+-p ,"); +const string KEllipsis("\205"); +const string KUnknown("unknown"); + +string TrimWhiteSpace(const string& aString) + { + int start = aString.find_first_not_of(WhiteSpace); + if (start == string::npos) + return ""; + else + return aString.substr(start, 1+aString.find_last_not_of(WhiteSpace)-start); + } + + +THtmlParseLayoutTable::THtmlParseLayoutTable(TLayout* aTables) +: TLayoutTable(aTables) + { + } + +THtmlParseLayoutTable::~THtmlParseLayoutTable() + { + } + +bool THtmlParseLayoutTable::Read(istream& in) + { + iIn = ∈ + + if (!SearchForTableStart()) + return false; + + ExtractTable(); + + iIn = 0; + + return true; + } + +bool THtmlParseLayoutTable::SearchForTableStart() + { + string text; + while (!Eof()) + { + string next = Next(); + if (IsToken(next)) + { + if (next.substr(0,6) == " gKnownTitles; + +void THtmlParseLayoutTable::ExtractTitle(const string& aText) + { + iName = UnHtml(aText); + int pos = iName.find_first_not_of("1234567890.\t\r\n "); + if (pos == string::npos) + return; + iName = iName.substr(pos); + iName = StripTo(iName, gValidText); + iName = TrimWhiteSpace(iName); + + while (gKnownTitles.find(iName) != gKnownTitles.end()) + iName += "_dup"; + + gKnownTitles.insert(iName); + } + +void THtmlParseLayoutTable::ExtractTable() + { + string cell; + string td; + Row row; + while (!Eof()) + { + string tok = Next(); + if (IsToken(tok)) + { + if (tok.substr(0,4) == "") + { + row.push_back(CleanCell(cell, row)); + cell = ""; + int colspan = GetVal(td, "COLSPAN"); + for (int i=1; i") + { + if (!row[1].length()) + row[1] = "untitled"; + AddRow(row); + row.erase(row.begin(), row.end()); + } + else if (tok == "") + { + break; + } + else if (cell.length() && (tok == "
" || tok == "

")) + { + cell += ", "; + } + } + else + { + cell += tok; + } + } + } + +string THtmlParseLayoutTable::CleanCell(const string& cell, const Row& row) + { + if (iColumnNames.size() < 6) // table header + return cell; + else if (row.size() < 2 || row.size() == iColumnNames.size()) // free text + return StripTo(UnHtml(cell),gValidText+KEllipsis); + else + return CleanMultiCell(StripTo(UnHtml(cell),gValidText+"/,*")); // value cell + } + +string THtmlParseLayoutTable::Next() + { + string s; + char c; + + do { + c = Get(); + } while (!Eof() && WhiteSpace.find(c) != string::npos); + s += c; + + if (c == '<') + { + do { + c = Get(); + s += toupper(c); + } while (!Eof() && c != '>'); + } + else + { + do { + c = Get(); + s += c; + } while (!Eof() && c != '<'); + + if (c == '<') + PutBack(c); + + s = s.substr(0, s.find_last_not_of(WhiteSpace)); + } + + return s; + } + +bool THtmlParseLayoutTable::IsToken(const string& aText) + { + return aText.length()>0 && aText[0] == '<'; + } + +void THtmlParseLayoutTable::PutBack(const string& aText) + { + for (string::const_reverse_iterator pC = aText.rbegin(); pC != aText.rend(); ++pC) + PutBack(*pC); + } + +int THtmlParseLayoutTable::GetVal(const string& aText, const string& aField) + { + int pos = aText.find(aField+"="); + if (pos == string::npos) + return 0; + string val = aText.substr(pos + aField.length() + 1); + val = val.substr(0, val.find_first_of(WhiteSpace + ">")); + stringstream s(val); + int ret; + s >> ret; + return ret; + } + +char THtmlParseLayoutTable::Get() + { + if (iPutBack.length()) + { + char c = iPutBack[iPutBack.length()-1]; + iPutBack.erase(iPutBack.length()-1, 1); + return c; + } + else + { + return iIn->get(); + } + } + +void THtmlParseLayoutTable::PutBack(char aChar) + { + iPutBack += aChar; + } + +bool THtmlParseLayoutTable::Eof() + { + return iPutBack.length()==0 && iIn->eof(); + } + +string THtmlParseLayoutTable::CleanMultiCell(const string& aText) + { + // This function removes trailing commas from the end of cells where there is no + // comma in the middle of the cell. + // needed because of odd formatting found. + if (aText.length()==0) + return aText; + + int pos = aText.find_last_not_of(" ,"); + if (pos == string::npos) + return ""; + + string text; + if (aText.substr(0,pos+1).find(",") == string::npos) + text = aText.substr(0,pos+1); + else + text = aText; + + return text; + } + +const int KMaxStars = 16; +struct SCellParamDesc + { + SCellParamDesc(); + bool operator==(const SCellParamDesc& a); + int iParams; + bool iStars[KMaxStars]; + }; + +SCellParamDesc::SCellParamDesc() + { + iParams=0; + for (int i=0; i paramDescs; + + // initialise params + for (Row::const_iterator pR = row.begin(); pR != row.end(); ++pR) + { + params.push_back(""); + paramDescs.push_back(SCellParamDesc()); + } + + // count params and stars + int i; + for (i=0; i1 && first) + { + param = name; + name[7]++; + } + } + + return params; + } + +void THtmlParseLayoutTable::AddRow(Row& row) + { + if (row.size()==0) + return; // empty row + + const string& first = row[0]; + + if (first.length()==0 || first == "P") + AddTitleRow(row); + else if (first == "No.") + AddColumnNameRow(row); + else if (first == KEllipsis) + iAppend = true; + else + AddLineRow(row); + } + +void THtmlParseLayoutTable::AddColumnNameRow(Row& row) + { + if (row.size()<4) + return; // unknown row type + + if (row[1] == "Value") + row[1] = "Item"; + + if (row[1] == "Font") + iType = ETextTable; + else if (row[1] == "Item") + iType = EWindowTable; + else + return; // unknown row type + + SetDefaultColumnNames(); + iColumnNames.insert(iColumnNames.begin()+3, "b/r"); // for skins LAF + + int foundCount = 0; + vector foundColNames; + for (Row::iterator pCol = row.begin()+1; pCol != row.end(); pCol++) + { + string cellTitle = *pCol; + if (cellTitle == "Remarks.") + cellTitle = "Remarks"; + if (iType == ETextTable && cellTitle == "Margins") + { + foundColNames.push_back("l"); + foundColNames.push_back("r"); + pCol++; + } + else if (find(iColumnNames.begin(),iColumnNames.end(),cellTitle) != iColumnNames.end()) + { + foundColNames.push_back(cellTitle); + foundCount++; + } + else + { + foundColNames.push_back(KUnknown); + } + } + iColumnNames = foundColNames; + + if (foundCount < 4) + { + iColumnNames.clear(); + iType = EUnknownTable; + } + } + +void THtmlParseLayoutTable::AddLineRow(const Row& row) + { + if (iColumnNames.size() == 0 || row.size() != iColumnNames.size()+1) + return; // unknown row type; + + Row params = MakeParamTable(row, 2, iColumnNames.size()-2); + + Row::const_iterator pCell = row.begin(); + Row::const_iterator pParam = params.begin(); + + int id; + stringstream stream(*pCell); + stream >> id; + if (id == 0) + return; // bad id; + + TLayoutLine* line = new TLayoutLine(this, id); + push_back(line); + + bool found_l = false; + for (vector::iterator pCol = iColumnNames.begin(); pCol != iColumnNames.end(); ++pCol) + { + string col = *pCol; + if (col == "b/r") + col = found_l ? "b" : "r"; + + ++pCell; + ++pParam; + TValues values(line, col); + + if (pParam->size()) + values.iParam = *pParam; + + string cell = *pCell; + if (IsValueColumn(col)) + cell = ConvertToAknName(SplitMultiCell(cell, IsNumericColumn(col) ? gValidNum : gValidText)); + + int pos=0; + do { + int newPos = cell.find(',', pos); + values.push_back(TrimWhiteSpace(cell.substr(pos, newPos-pos))); + pos = newPos+1; + } while (pos); + + if ((values.size()>1 || values[0].size()>0) && col == "l") + found_l = true; + + if (col != KUnknown) + line->insert(make_pair(col, values)); + } + } + +void THtmlParseLayoutTable::AddTitleRow(const Row& row) + { + if (row.size() < 2) + return; + if (row[0] == "P") + iParentName = TrimWhiteSpace(row[1]); + } + +string THtmlParseLayoutTable::SplitMultiCell(const string& aCell, const string& aValid) + { + string cell = aCell; + + // Make sure commas are in correctly! + cell = StripTo(UnHtml(cell), aValid+"/,"); + + int lastComma = -1; + int lastSpace = -1; + int lastNum = -1; + + for (int i=0; i lastNum && lastNum > lastComma) + { + cell[lastSpace] = ','; + lastComma = lastSpace; + } + lastNum = i; + } + } + + cell = StripTo(UnHtml(cell), aValid+","); + if (cell == "-") + cell = ""; + + return cell; + } + +string THtmlParseLayoutTable::StripTo(const string& aText, const string& aValid) + { + string cell(""); + for (string::const_iterator pC = aText.begin(); pC != aText.end(); ++pC) + { + if (aValid.find(*pC) != string::npos) + cell += *pC; + } + return cell; + } + +string THtmlParseLayoutTable::UnHtml(const string& aText) + { + string str(""); + for (int i=0; i'}, + {"lt", '<'}, + {"nbsp", ' '}, + {"#9", '\t'} + }; + +char THtmlParseLayoutTable::HtmlChar(const string& aText) + { + for (int i=0; i_plain_12", "EApacPlain12" }, + { "qfn__plain_16", "EApacPlain16" }, + { "qfn_china_plain_12", "EApacPlain12" }, + { "qfn_number_plain_5", "ENumberPlain5" }, + { "qfn_china_plain_16", "EApacPlain16" }, + { "qfn_clock_bold_30", "EClockBold30" }, + { "qfn_number_bold_14", "ELatinClock14" }, + { "gfn__plain_12", "EApacPlain12" }, + { "gfn__plain_16", "EApacPlain16" }, + { "gfn_latin_bold_16", "ELatinBold16" }, + { "qfn_calc_21", "ECalcBold21" }, + { "qfn_calc_oper_21", "ECalcOperBold21" }, + { "qfn_calc_oper_13", "ECalcOperBold13" } + }; + +string THtmlParseLayoutTable::ConvertToAknName(const string& aText) + { + string ret = aText; + for (int i=0; i table(new THtmlParseLayoutTable(this)); + if (table->Read(aIn)) + { + if (table->size() > 0) + push_back(table.release()); + } + else + break; + } + Compile(); + } + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/Lay2Cdl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/Lay2Cdl.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,263 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Defines the entry point for the console application +* +*/ + + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "Lay2Cdl.h" +#include "LayoutParse.h" +#include "LayoutCompilerErr.h" +#include +#include +#include +#include +#include "CppWriter.h" +#include "CodeGenConsts.h" + +using namespace std; + +typedef LayoutProcessArgsErr LayoutToCdlArgsErr; + +const int KGeneratedInterfaceMajorVer = 1; +const int KGeneratedInterfaceMinorVer = 0; + +string LayoutToCdl::InterfaceName(const string& aFileName) + { + return aFileName.substr(0,aFileName.find_last_of('.')); + } + +int LayoutToCdl::Process(const vector& args) + { + if (args.size() != 5) + throw LayoutToCdlArgsErr(); + + string layoutName = args[2]; + auto_ptr layout(TLayParseLayout::Parse(layoutName)); + + string cdlName = args[3]; + int uid = CdlTkUtil::ParseInt(args[4]); + auto_ptr iface(LayoutToInterface(*layout)); + + SetHeaders(*iface, cdlName, uid); + + CCdlTkWriteCdlFile writer(*iface); + cout << "writing CDL file " << cdlName << endl; + writer.Process(); + return 0; + } + +void LayoutToCdl::ShowHelp(ostream& stream) + { + stream << "Lay2Cdl " << endl; + } + +auto_ptr LayoutToCdl::LayoutToInterface(const TLayout& aLayout) + { + auto_ptr iface(new CCdlTkInterface); + + for (TLayout::const_iterator pTab = aLayout.begin(); pTab != aLayout.end(); ++pTab) + { + AddTableToInterface(*iface, **pTab); + } + + return iface; + } + +void LayoutToCdl::AddTableToInterface(CCdlTkInterface& aInterface, TLayoutTable& aTable) + { + for (TLayoutTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) + { + if (aTable.iType == TLayoutTable::EWindowTable) + AddWindowLineToInterface(aInterface, **pLine); + else + AddTextLineToInterface(aInterface, **pLine); + + if (pLine == aTable.begin()) + { + CCdlTkApi& api = **aInterface.ApiList().rbegin(); + api.SetComment(string("// LAF Table : ") + aTable.Name() + "\n"); + } + } + + int tableNum = 0; + for (TLayoutTable::TLayoutSubTables::const_iterator pSub = aTable.iSubTables.begin(); pSub != aTable.iSubTables.end(); ++pSub) + { + AddTableLimitsToInterface(aInterface, aTable, **pSub, tableNum); + string tableType = KTypeTextLineLayout; + if (aTable.iType == TLayoutTable::EWindowTable) + tableType == KTypeWindowLineLayout; + AddSubTableToInterface(tableType, aInterface, aTable, **pSub, tableNum); + tableNum++; + } + } + +void LayoutToCdl::AddWindowLineToInterface(CCdlTkInterface& aInterface, TLayoutLine& aLine) + { + CCdlTkApi* api = CreateGenericApi(aInterface, aLine); + + api->SetName(LineApiName(aLine)); + api->SetReturnType(KTypeWindowLineLayout); + + aInterface.ApiList().push_back(api); + } + +void LayoutToCdl::AddTextLineToInterface(CCdlTkInterface& aInterface, TLayoutLine& aLine) + { + CCdlTkApi* api = CreateGenericApi(aInterface, aLine); + + api->SetName(LineApiName(aLine)); + api->SetReturnType(KTypeTextLineLayout); + + aInterface.ApiList().push_back(api); + + TValues& v = aLine["B"]; + if (v.size()>1) + { + CCdlTkFunctionApi* multiline = static_cast(CreateGenericApi(aInterface, aLine)); + CCdlTkApiParams& params = multiline->Params(); + CCdlTkApiParams::iterator pParam = params.FindByName(KParamNameB); + if (pParam != params.end()) + params.erase(pParam); + params.push_back(CCdlTkApiParam(KTypeInt, KParamNameNumberOfLinesShown)); + + multiline->SetName(KFuncMultiline + LineApiName(aLine)); + multiline->SetReturnType(KTypeMultiLineTextLayout); + + aInterface.ApiList().push_back(multiline); + } + } + +string LayoutToCdl::TableApiName(TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum) + { + if (aTable.size() == aSubTable.size()) + return CdlTkUtil::ToCpp(aTable.Name()); + else + return CdlTkUtil::ToCpp(aTable.Name()) + "_SUB_TABLE_" + CdlTkUtil::IntToString(aSubTableNum); + } + +string LayoutToCdl::LineApiName(TLayoutLine& aLine) + { + if (aLine.iTable->iType == TLayoutTable::EWindowTable) + { + TWindowLineCppWriter writer(aLine); + return writer.Name(); + } + else + { + TTextLineCppWriter writer(aLine); + return writer.Name(); + } + } + +void LayoutToCdl::AddSubTableToInterface(const string& aType, CCdlTkInterface& aInterface, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum) + { + TLayoutLine& line = *aTable[aSubTable[0]]; + CCdlTkFunctionApi* api = new CCdlTkFunctionApi(aInterface); + api->Params().push_back(CCdlTkApiParam(KTypeInt, KParamLineIndex)); + AddParamsToFunc(line, *api); + + api->SetReturnType(aType); + + api->SetName(TableApiName(aTable, aSubTable, aSubTableNum)); + + aInterface.ApiList().push_back(api); + } + +void LayoutToCdl::AddTableLimitsToInterface(CCdlTkInterface& aInterface, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum) + { + CCdlTkFunctionApi* api = new CCdlTkFunctionApi(aInterface); + api->SetReturnType(KTypeLayoutTableLimits); + api->SetName(TableApiName(aTable, aSubTable, aSubTableNum)+KFuncLimitsSuffix); + aInterface.ApiList().push_back(api); + } + +CCdlTkApi* LayoutToCdl::CreateGenericApi(CCdlTkInterface& aInterface, TLayoutLine& aLine) + { + CCdlTkFunctionApi* func = new CCdlTkFunctionApi(aInterface); + AddParamsToFunc(aLine, *func); + return func; + } + +void LayoutToCdl::AddParamsToFunc(TLayoutLine& aLine, CCdlTkFunctionApi& aFunc) + { + CCdlTkApiParams& params = aFunc.Params(); + + bool mirrored = aLine.iIsMirroredHorizontally; + + if (aLine.iNeedsP) + params.push_back(CCdlTkApiParam(KTypeRect, KParamParentRect)); + + if (aLine.iNeedsIndex) + { + const string* KParams; + int count; + if (aLine.iTable->iType == TLayoutTable::EWindowTable) + { + if (mirrored) + KParams = KWindowOutputOrderMirrored; + else + KParams = KWindowOutputOrder; + count = KWindowOutputOrderSize; + } + else + { + if (mirrored) + KParams = KTextOutputOrderMirrored; + else + KParams = KTextOutputOrder; + count = KTextOutputOrderSize; + } + + for (int i=0; i"); + } + diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/Lay2LayPerf.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/Lay2LayPerf.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "Lay2LayPerf.h" +#include "LayoutParse.h" +#include "LayoutCompilerErr.h" +#include +#include +#include +#include +#include "LayPerfWriter.h" + +typedef LayoutProcessArgsErr LayoutToLayPerfArgsErr; + + +string LayoutToLayPerf::InterfaceName(const string& aFileName) + { + return aFileName.substr(0,aFileName.find_last_of('.')); + } + +int LayoutToLayPerf::Process(const vector& args) + { + if (args.size() != 5) + throw LayoutToLayPerfArgsErr(); + + string cdlName = args[2]; + + auto_ptr sourceLayout(TLayParseLayout::Parse(args[3])); + string destLayout = args[4]; + + LayoutToLayPerf layPerf(cdlName, *sourceLayout, destLayout); + layPerf.WriteLayout(); + + return 0; + } + +void LayoutToLayPerf::ShowHelp(ostream& stream) + { + stream << "Lay2LayPerf " << endl; + stream << "Lay2LayPerf ..\\cdl\\AknLayout.cdl ..\\layout\\AknElaf.lay \\s60\\akntest\\layperf\\generated\\LayPerf_AknElaf.cpp " << endl; + stream << " This converts a LAY file into a specialised format for inclusion in the LayPerf test app." << endl; + stream << " LayPerf runs on the device, calling each API that would be generated from the LAY file." << endl; + } + + + +LayoutToLayPerf::LayoutToLayPerf(const string& aCdlName, TLayout& aSourceLayout, const string& aDestLayoutName) +: + iCdlName(aCdlName), + iLayout(aSourceLayout), + iDestLayoutName(aDestLayoutName) + { + } + +void LayoutToLayPerf::WriteLayout() + { + TLayPerfWriter writer(iLayout, iDestLayoutName); + writer.Write(iCdlName); + } + diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/Lay2MLInst.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/Lay2MLInst.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,329 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "lay2MLInst.h" +#include "LayoutParse.h" +#include "LayoutCompilerErr.h" + +#include +#include +#include +#include "MLInstWriter.h" +//#include "MLInstParse.h" + +string TextOutputOrder(int aIndex, bool aMirrored); +string WindowOutputOrder(int aIndex, bool aMirrored); + +using namespace std; + +class LayoutToMLInstArgsErr : public LayoutCompilerErr + { + void Show(ostream& aStream) const; + }; + +void LayoutToMLInstArgsErr::Show(ostream& stream) const + { + LayoutToMLInst::ShowHelp(stream); + } + +string LayoutToMLInst::InterfaceName(const string& aFileName) + { + return aFileName.substr(0,aFileName.find_last_of('.')); + } + +int LayoutToMLInst::Process(const vector& args) + { + if (args.size() != 4) + throw LayoutToMLInstArgsErr(); + + // first read in the lay file + string layoutName = args[2]; + auto_ptr layoutParse(TLayParseLayout::Parse(layoutName)); + + // then convert it to internal structure format + auto_ptr mlInst(LayoutToInst(*layoutParse)); + + // finally write out the structure XML + string xmlName = args[3]; + cout << "writing XML file " << xmlName << endl; + TMLInstWriter writer(*mlInst, xmlName); + writer.Write(layoutName); + return 0; + } + +void LayoutToMLInst::ShowHelp(ostream& stream) + { + stream << "Lay2MLInst " << endl; + } + +auto_ptr LayoutToMLInst::LayoutToInst(const TLayout& aLayout) + { + auto_ptr mlInst(new TMLInst); + + for (TLayout::const_iterator pTab = aLayout.begin(); pTab != aLayout.end(); ++pTab) + { + AddTableToInst(*mlInst, **pTab); + } + + return mlInst; + } + +void LayoutToMLInst::AddTableToInst(TMLInst& aInst, TLayoutTable& aTable) + { + TMLInstTable* instTable = new TMLInstTable(&aInst, aTable); + + for (TLayoutTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) + { + if (aTable.iType == TLayoutTable::EWindowTable) + AddWindowLineToInstTable(*instTable, **pLine); + else + AddTextLineToInstTable(*instTable, **pLine); + } + +/* + int tableNum = 0; + for (TLayoutTable::TLayoutSubTables::const_iterator pSub = aTable.iSubTables.begin(); pSub != aTable.iSubTables.end(); ++pSub) + { + AddTableLimitsToInterface(aInterface, aTable, **pSub, tableNum); + if (aTable.iType == TLayoutTable::EWindowTable) + AddSubTableToInterface("TAknWindowLineLayout", aInterface, aTable, **pSub, tableNum); + else + AddSubTableToInterface("TAknTextLineLayout", aInterface, aTable, **pSub, tableNum); + tableNum++; + } +*/ + aInst.push_back(instTable); + } + +void LayoutToMLInst::AddWindowLineToInstTable(TMLInstTable& aInstTable, TLayoutLine& aLine) + { + TMLInstLine* instLine = new TMLInstLine(&aInstTable, aLine); +/* + CCdlTkApi* api = CreateGenericApi(aInterface, aLine); + api->SetName(LineApiName(aLine)); + api->SetReturnType("TAknWindowLineLayout"); + aInterface.ApiList().push_back(api); +*/ + + + // add a value for each top level cell + for (int i=0; i<7; i++) + { + string cellName = WindowOutputOrder(i, false); +// WriteCell(line, cellName, aLine[cellName]); + AddParamToLine(*instLine, aLine[cellName]); + } + +/* + for(TLayoutLine::iterator pValue = aLine.begin(); pValue != aLine.end(); ++pValue) + { + AddParamToLine(instLine, *pValue); + } +*/ + aInstTable.push_back(instLine); + } + +void LayoutToMLInst::AddTextLineToInstTable(TMLInstTable& aInstTable, TLayoutLine& aLine) + { + TMLInstLine* instLine = new TMLInstLine(&aInstTable, aLine); + +/* + CCdlTkApi* api = CreateGenericApi(aInterface, aLine); + + api->SetName(LineApiName(aLine)); + api->SetReturnType("TAknTextLineLayout"); + + aInterface.ApiList().push_back(api); +*/ + + for (int i=0; i<6; i++) + { + string cellName = TextOutputOrder(i, false); +// WriteCell(line, cellName, aLine[cellName]); + AddParamToLine(*instLine, aLine[cellName]); + } + +/* + for(TLayoutLine::iterator pValue = aLine.begin(); pValue != aLine.end(); ++pValue) + { + AddParamToLine(instLine, *pValue); + } +*/ + aInstTable.push_back(instLine); + + +/* + TValues& v = aLine["B"]; + if (v.size()>1) + { + CCdlTkFunctionApi* multiline = static_cast(CreateGenericApi(aInterface, aLine)); + CCdlTkApiParams& params = multiline->Params(); + CCdlTkApiParams::iterator pParam = params.FindByName("aIndex_B"); + if (pParam != params.end()) + params.erase(pParam); + params.push_back(CCdlTkApiParam("TInt", "aNumberOfLinesShown")); + + multiline->SetName(string("Multiline_") + LineApiName(aLine)); + multiline->SetReturnType("TAknMultiLineTextLayout"); + + aInterface.ApiList().push_back(multiline); + } +*/ + } + +/* +string LayoutToMLInst::TableApiName(TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum) + { + if (aTable.size() == aSubTable.size()) + return CdlTkUtil::ToCpp(aTable.Name()); + else + return CdlTkUtil::ToCpp(aTable.Name()) + "_SUB_TABLE_" + IntToString(aSubTableNum); + } + +string LayoutToMLInst::LineApiName(TLayoutLine& aLine) + { + if (aLine.iTable->iType == TLayoutTable::EWindowTable) + { + TWindowLineCppWriter writer(aLine); + return writer.Name(); + } + else + { + TTextLineCppWriter writer(aLine); + return writer.Name(); + } + } + +void LayoutToMLInst::AddSubTableToInterface(const string& aType, CCdlTkInterface& aInterface, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum) + { + TLayoutLine& line = *aTable[aSubTable[0]]; + CCdlTkFunctionApi* api = new CCdlTkFunctionApi(aInterface); + api->Params().push_back(CCdlTkApiParam("TInt", "aLineIndex")); + AddParamsToFunc(line, *api); + + api->SetReturnType(aType); + + api->SetName(TableApiName(aTable, aSubTable, aSubTableNum)); + + aInterface.ApiList().push_back(api); + } + +void LayoutToMLInst::AddTableLimitsToInterface(CCdlTkInterface& aInterface, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum) + { + CCdlTkFunctionApi* api = new CCdlTkFunctionApi(aInterface); + api->SetReturnType("TAknLayoutTableLimits"); + api->SetName(TableApiName(aTable, aSubTable, aSubTableNum)+"_Limits"); + aInterface.ApiList().push_back(api); + } + +CCdlTkApi* LayoutToMLInst::CreateGenericApi(CCdlTkInterface& aInterface, TLayoutLine& aLine) + { + CCdlTkFunctionApi* func = new CCdlTkFunctionApi(aInterface); + AddParamsToFunc(aLine, *func); + return func; + } + +void LayoutToMLInst::AddParamsToFunc(TLayoutLine& aLine, CCdlTkFunctionApi& aFunc) + { + CCdlTkApiParams& params = aFunc.Params(); + + if (aLine.iNeedsP) + params.push_back(CCdlTkApiParam("const TRect&", "aParentRect")); + + if (aLine.iNeedsIndex) + { + const string* KParams; + int count; + if (aLine.iTable->iType == TLayoutTable::EWindowTable) + { + KParams = KWindowOutputOrder; + count = KWindowOutputOrderSize; + } + else + { + KParams = KTextOutputOrder; + count = KTextOutputOrderSize; + } + + for (int i=0; iiValues.push_back(*pInt); + } + +/* + if (aLine.iNeedsP) + params.push_back(CCdlTkApiParam("const TRect&", "aParentRect")); + + if (aLine.iNeedsIndex) + { + const string* KParams; + int count; + if (aLine.iTable->iType == TLayoutTable::EWindowTable) + { + KParams = KWindowOutputOrder; + count = KWindowOutputOrderSize; + } + else + { + KParams = KTextOutputOrder; + count = KTextOutputOrderSize; + } + + for (int i=0; i +#include +#include +#include "CodeGenConsts.h" +using namespace std; +using namespace CdlCompilerToolkit; + +typedef LayoutProcessArgsErr LayoutAndCdlToCdlInstanceArgsErr; + + +class LayoutAndCdlToCdlInstanceChecker : public MCdlTkApiCheckObserver + { +private: + void StartCheck(); + void CheckComplete(); + void ApiInBoth(const CCdlTkApi& aApi); + void ApiNotInLeft(const CCdlTkApi& aApi); + void ApiNotInRight(const CCdlTkApi& aApi); + +private: + int iNotInLeft; + int iNotInRight; + }; + + +void LayoutAndCdlToCdlInstanceChecker::StartCheck() + { + iNotInLeft = 0; + iNotInRight = 0; + } + +void LayoutAndCdlToCdlInstanceChecker::CheckComplete() + { + if (iNotInLeft) + cout << "Layout is partial implementation of interface" << endl; + if (iNotInRight) + throw CdlTkAssert("Layout interface check failed"); + } + +void LayoutAndCdlToCdlInstanceChecker::ApiInBoth(const CCdlTkApi& /*aApi*/) + { + } + +void LayoutAndCdlToCdlInstanceChecker::ApiNotInLeft(const CCdlTkApi& /*aApi*/) + { + iNotInLeft++; + } + +void LayoutAndCdlToCdlInstanceChecker::ApiNotInRight(const CCdlTkApi& aApi) + { + iNotInRight++; + cerr << aApi.Name() << " not in interface" << endl; + } + + +int LayoutAndCdlToCdlInstance::Process(const vector& args) + { + if (args.size() < 5 || args.size()%2 == 0) + throw LayoutAndCdlToCdlInstanceArgsErr(); + + string cdlName = args[2]; + CCdlTkCdlFileParser parser(cdlName); + auto_ptr iface(parser.LoadAndParse(true)); + + LayoutAndCdlToCdlInstance process(*iface); + + TLayout* base = NULL; + for (int arg = 3; arg < args.size(); arg += 2) + { + string layoutName = args[arg]; + string instName = args[arg+1]; + auto_ptr layoutParse = TLayParseLayout::Parse(layoutName); + auto_ptr layout(layoutParse.get()); + layoutParse.release(); + if (base) + { + auto_ptr newLayout(new TLayout(*base)); + newLayout->Merge(TLayout::KMergeModeVariant, *layout); + layout = newLayout; + } + else + { + base = layout.get(); + } + process.AddLayout(layout, instName); + } + + process.WriteInstances(); + + return 0; + } + +void LayoutAndCdlToCdlInstance::ShowHelp(ostream& stream) + { + stream << "LayCdl2Inst ( )+ " << endl; + stream << " Creates CDL instances containing the layout data." << endl; + stream << " All layout instances must conform to the CDL interface." << endl; + stream << " If more than one layout is supplied, subsequent ones are treated as" << endl; + stream << " variants of the first." << endl; + } + +void LayoutAndCdlToCdlInstance::CheckLayoutAgainstInterface(const TLayout& aLayout, const CCdlTkInterface& aIface) + { + auto_ptr layIface = LayoutToCdl::LayoutToInterface(aLayout); + LayoutAndCdlToCdlInstanceChecker checker; + CCdlTkApiChecker check(*layIface, aIface, checker); + check.Process(); + } + +LayoutAndCdlToCdlInstance::LayoutAndCdlToCdlInstance(CCdlTkInterface& aInterface) +: iInterface(aInterface) + { + } + +LayoutAndCdlToCdlInstance::~LayoutAndCdlToCdlInstance() + { + for (CLayouts::iterator pLayout = iLayouts.begin(); pLayout != iLayouts.end(); ++pLayout) + delete *pLayout; + } + +void LayoutAndCdlToCdlInstance::AddLayout(auto_ptr& aLayout, const string& aInstName) + { + CLayoutToInst* base = NULL; + if (iLayouts.size()) + base = iLayouts[0]; + auto_ptr p(new CLayoutToInst(base, iInterface, aLayout, aInstName)); + iLayouts.push_back(p.get()); + p.release(); + } + +void LayoutAndCdlToCdlInstance::WriteInstances() + { + CLayouts::iterator pLayout = iLayouts.begin(); + CLayouts::iterator end = iLayouts.end(); + + if (pLayout!=end) + (*pLayout)->Process(); + + for (; pLayout != end; ++pLayout) + { + CCdlTkWriteInstance writer((*pLayout)->Instance()); + writer.Process(); + } + } + + +CLayoutToInst::CLayoutToInst(CLayoutToInst* aBase, CCdlTkInterface& aInterface, auto_ptr& aLayout, const string& aInstName) +: iBase(aBase), iInterface(aInterface), iLayout(*aLayout), iInstName(aInstName) + { + iLayoutPtr = aLayout.get(); + aLayout.release(); + + iInstance = new CCdlTkInstance(iInterface); + iInstance->SetName(aInstName); + + string extraCpp("#include \n"); + extraCpp += string("#include \"") + CdlTkUtil::ToLower(aBase ? aBase->FwdDeclName() : FwdDeclName()) + "\"\n"; + iInstance->SetExtraCpp(extraCpp); + + for (TLayout::iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab) + { + AddTableToInstance(**pTab); + } + } + +CLayoutToInst::~CLayoutToInst() + { + delete iInstance; + delete iLayoutPtr; + } + +string CLayoutToInst::FwdDeclName() + { + if (iBase) + return iBase->FwdDeclName(); + else + return iInstName + ".FwdDecl.h"; + } + +void CLayoutToInst::Process() + { + string fileName(FwdDeclName()); + string interfaceNsName = iInterface.NamespaceName(); + + ofstream stream; + CCdlTkFileCleanup tempFile; + CdlTkUtil::OpenTempOutput(stream, tempFile); + + WriteHeaderGuardStart(fileName, stream); + stream << "namespace " << CdlTkUtil::ToCpp(iInstance->Name()) << endl; + stream << "{" << endl; + + CCdlTkApiList& apiList = iInterface.ApiList(); + for (CCdlTkApiList::iterator pApi = apiList.begin(); pApi != apiList.end(); ++pApi) + { + if ((*pApi)->IsFunc()) + { + stream << "extern " << interfaceNsName << "::" << (*pApi)->AsFunc().ApiNameAsTypeName() << " " << (*pApi)->Name() << ";" << endl; + } + else + { + string typeExt = "Imp"; + if ((*pApi)->ReturnType() == KTypeLayoutTableLimits) + typeExt = ""; + stream << "extern " << (*pApi)->ReturnType() << typeExt << " const " << (*pApi)->Name() << ";" << endl; + } + } + + stream << "}" << endl << endl; + WriteHeaderGuardEnd(fileName, stream); + + stream.close(); + CdlTkUtil::ExportFile(tempFile, CdlTkUtil::OutputPath() + fileName); + } + +CCdlTkInstance& CLayoutToInst::Instance() + { + return *iInstance; + } + +void CLayoutToInst::AddTableToInstance(TLayoutTable& aTable) + { + for (TLayoutTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) + { + TLayoutLine& line = **pLine; + if (line.iIsMergedIdentical) + { + string apiName = LayoutToCdl::LineApiName(line); + AddFwdRefToInstance(apiName, false); + + string multilineApiName = KFuncMultiline + apiName; + if (aTable.iType == TLayoutTable::ETextTable && + line["B"].size() > 1 && + HasApi(multilineApiName)) + { + AddFwdRefToInstance(multilineApiName, false); + } + } + else + { + if (aTable.iType == TLayoutTable::EWindowTable) + AddWindowLineToInstance(line); + else + AddTextLineToInstance(line); + } + } + + int tableNum = 0; + for (TLayoutTable::TLayoutSubTables::const_iterator pSub = aTable.iSubTables.begin(); pSub != aTable.iSubTables.end(); ++pSub) + { + TLayoutTable::TLayoutSubTable& sub = **pSub; + if (sub.iIsMergedIdentical) + { + AddFwdRefToInstance(LayoutToCdl::TableApiName(aTable, sub, tableNum)+KFuncLimitsSuffix, false); + AddFwdRefToInstance(LayoutToCdl::TableApiName(aTable, sub, tableNum), false); + } + else + { + AddTableLimitsToInstance(aTable, sub, tableNum); + string tableType = KTypeTextLineLayout; + if (aTable.iType == TLayoutTable::EWindowTable) + tableType = KTypeWindowLineLayout; + AddSubTableToInstance(tableType, aTable, sub, tableNum); + } + tableNum++; + } + } + +void CLayoutToInst::AddWindowLineToInstance(TLayoutLine& aLine) + { + string apiName = LayoutToCdl::LineApiName(aLine); + if (!HasApi(apiName)) + return; + CCdlTkImplementation& imp = FindImp(apiName); + SetFuncLine(imp, aLine, KTypeWindowLineLayout, KWindowOutputOrder, KWindowOutputOrderSize, "", ""); + } + +const string KMultiLineTextLineExtra = "\ +\tline.iB = KB[0];\n\ +\tline.iBaselineSkip = KB[1]-KB[0];\n\ +\tline.iNumberOfLinesShown = aNumberOfLinesShown;\n"; + +const string KTextLineExtra = "\ +\tline.iBaselineSkip = 0;\n\ +\tline.iNumberOfLinesShown = 1;\n"; + +void CLayoutToInst::AddTextLineToInstance(TLayoutLine& aLine) + { + string apiName = LayoutToCdl::LineApiName(aLine); + if (!HasApi(apiName)) + return; + CCdlTkImplementation& imp = FindImp(apiName); + SetFuncLine(imp, aLine, KTypeTextLineLayout, KTextOutputOrder, KTextOutputOrderSize, "", KTextLineExtra); + if (aLine["B"].size() > 1) + { + string preExtra = "\tTInt " + KParamNameB + " = 0;\n"; + if (aLine["B"].ParamName() != KParamNameB) + preExtra = ""; + string apiName = KFuncMultiline + imp.Name(); + if (HasApi(apiName)) + { + CCdlTkImplementation& multiLineImp = FindImp(KFuncMultiline + imp.Name()); + SetFuncLine(multiLineImp, aLine, KTypeMultiLineTextLayout, KTextOutputOrder, KTextOutputOrderSize, preExtra, KMultiLineTextLineExtra); + } + } + } + +bool CLayoutToInst::HasApi(const string& aName) + { + return iInterface.ApiList().Find(aName) != 0; + } + +CCdlTkImplementation& CLayoutToInst::FindImp(const string& aName) + { + CCdlTkImplementation* impl = iInstance->Impl().Find(aName); + if (!impl) + throw NotFoundErr(aName + " in interface " + iInterface.FileName()); + return *impl; + } + + +// subtable function uses the main table of pointers, with a mask to ensure that only correct lines are accessed +// which are indexed by aLineIndex + +const string KSubTableImpl = "\ +#TYPE #NAME#PARAMLIST\n\ +\t{\n\ +\tstatic #PTRTYPE const * const KSubTableImpl = (#PTRTYPE const * const)&KCdlImpl.#FIRST_MEMBER;\n\ +\tASSERT(0<=" + KParamLineIndex + " && " + KParamLineIndex + "<32 && ((1<<" + KParamLineIndex + ") & #VALID_INDEX));\n\ +\t#PTRTYPE KImpl = KSubTableImpl[" + KParamLineIndex + "];\n\ +\treturn #EVAL;\n\ +\t}"; + +const string KSubTableFuncEval = "(*KImpl)(#PARAMNAMES)"; +const string KSubTableDataEval = "*KImpl"; + +void CLayoutToInst::AddSubTableToInstance(const string& aType, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aTableNum) + { + string apiName = LayoutToCdl::TableApiName(aTable, aSubTable, aTableNum); + if (!HasApi(apiName)) + return; + + CCdlTkImplementation& imp = FindImp(apiName); + const CCdlTkFunctionApi& api = imp.Api().AsFunc(); + const CCdlTkApiParams& params = api.Params(); + + TLayoutLine& line = *aTable[aSubTable[0]]; + CCdlTkImplementation& lineImp = FindImp(LayoutToCdl::LineApiName(line)); + const CCdlTkApi& lineApi = lineImp.Api(); + + string ptrType; + if (lineApi.IsFunc()) + ptrType = iInterface.NamespaceName() + "::" + lineApi.PointerType(); + else + ptrType = lineApi.PointerType(); + + int valid = 0; + for (int ii=0; ii 1) + { + string v; + for (TValues::iterator pVal = values.begin(); pVal != values.end(); ++pVal) + { + if (pVal != values.begin()) + v += ","; + v += TValues::CppValue(*pVal); + } + + CdlTkUtil::CReplaceSet replaceSet; + replaceSet.Add("#PARAMNAME", paramName); + replaceSet.Add("#PARAMLIMIT", paramLimit); + replaceSet.Add("#TABLENAME", tableName); + replaceSet.Add("#VALUES", v); + + CdlTkUtil::AppendString(asserts, CdlTkUtil::MultiReplace(replaceSet, KFunctionAssert)); + CdlTkUtil::AppendString(tables, CdlTkUtil::MultiReplace(replaceSet, KFunctionTable)); + CdlTkUtil::AppendString(lookups, CdlTkUtil::MultiReplace(replaceSet, KFunctionLookup)); + CdlTkUtil::AppendString(init, "0"); + } + else + { + CdlTkUtil::AppendString(init, TValues::CppValue(values[0])); + } + } + + string paramTypeAndNameList(api.ParamsTypeAndNameList()); + if (aLine.iIsMirroredHorizontally) + MirrorParamNames(paramTypeAndNameList); + + CdlTkUtil::CReplaceSet implSet; + implSet.Add("#TYPE", aType); + implSet.Add("#NAME", api.Name()); + implSet.Add("#PARAMTYPEANDNAMELIST", paramTypeAndNameList); + implSet.Add("#PRE_EXTRA", aPreExtra); + implSet.Add("#ASSERTS", asserts); + implSet.Add("#TABLES", tables); + implSet.Add("#INIT", init); + implSet.Add("#LOOKUPS", lookups); + implSet.Add("#POST_EXTRA", aPostExtra); + implSet.Add("#RECT_ADJUST", aLine.iNeedsP ? KFunctionRect : ""); + string impl = CdlTkUtil::MultiReplace(implSet, KFunctionImpl); + + aImp.SetTemplatePointerReference(); + aImp.SetDefinition(impl); + } + +void CLayoutToInst::MirrorParamNames(std::string& aNames) + { + aNames = CdlTkUtil::Replace(KParamNameL, "__tmp__", aNames); + aNames = CdlTkUtil::Replace(KParamNameR, KParamNameL, aNames); + aNames = CdlTkUtil::Replace("__tmp__", KParamNameR, aNames); + } + +void CLayoutToInst::AddFwdRefToInstance(const string& aName, bool aCast) + { + string ns(CdlTkUtil::ToCpp(iBase->iInstance->Name())); + if (!HasApi(aName)) + return; + + CCdlTkImplementation& imp = FindImp(aName); + string ptr; + if (aCast) + ptr = string("(") + imp.Api().ReturnType() + "*)"; + ptr += string("&") + ns + "::" + aName; + imp.SetPointerReference(ptr); + } + + + diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/LayCdl2InstO.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/LayCdl2InstO.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,898 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "LayCdl2InstO.h" +#include "LayoutCompilerErr.h" +#include "LayoutParse.h" +#include "CppWriter.h" +#include "Lay2Cdl.h" +#include "CodeGenConsts.h" +#include +#include +#include +using namespace std; +using namespace CdlCompilerToolkit; + +#define AKNLAYOUT_DEFINE_BYTECODE(name,byte) const char name = char(byte); +#include "AknLayoutByteCodes.h" + + +extern string KMultiLine("Multiline_"); +typedef LayoutProcessArgsErr LayoutCdlInstanceOptArgsErr; + + +/** +* gTheFuncs +* This is a collection of all SImplFunc objects that a layout instance needs, initialised +* so that there are up to four integer parameters per API type. +*/ +CAllFuncs gTheFuncs(4); + +const string KDefinitionNotSet("Layout definition not found"); + + +CAllFuncs::CAllFuncs(int aMaxParams) + { + for (int ii=0; ii<=aMaxParams; ii++) + { + for (int jj=0; jj<2; jj++) + { + bool useParent = (jj == 1); + AddLineFunc(SImplFunc::EWindowLine, ii, useParent, KTypeWindowLineLayout, "WindowLine"); + AddLineFunc(SImplFunc::ETextLine, ii, useParent, KTypeTextLineLayout, "TextLine"); + AddLineFunc(SImplFunc::EMultilineTextLine, ii, useParent, KTypeMultiLineTextLayout, "MultiLineTextLine"); + AddTableFunc(SImplFunc::EWindowTable, ii, useParent, KTypeWindowLineLayout, "WindowTable"); + AddTableFunc(SImplFunc::ETextTable, ii, useParent, KTypeTextLineLayout, "TextTable"); + } + } + SImplFunc limits( + SImplFunc::ETableLimits, 0, false, + KTypeLayoutTableLimits + " Limits() { return AknLayoutDecode::TableLimits(KDataLookup); }", + "&Limits"); + push_back(limits); + } + +void CAllFuncs::AddLineFunc(SImplFunc::TFuncType aType, int aParams, bool aParent, const string& aReturn, const string& aFuncName) + { + // create a function of this form: + //TAknWindowLineLayout WindowTable$NUM$PARENT($PARAMS_TYPES_AND_NAMES) + // { + // return AknLayoutDecode::WindowLine$NUM$PARENT(&KImplData, $PARAM_NAMES); + // } + string funcName = aFuncName + CdlTkUtil::IntToString(aParams) + (aParent ? "t" : "f"); + string defn = aReturn + " " + funcName + "("; + string body = string(") { return AknLayoutDecode::") + funcName + "(&KImplData"; + + if (aParent) + { + defn += KTypeRect + " " + KParamParentRect; + body += ", " + KParamParentRect; + } + + for (int ii=0; ii0) + defn += ","; + defn += string(KTypeInt + " aParam") + CdlTkUtil::IntToString(ii); + body += string(", aParam") + CdlTkUtil::IntToString(ii); + } + + defn += body + "); }"; + + string ptrRef = string("&") + funcName; + + SImplFunc func(aType, aParams, aParent, defn, ptrRef); + push_back(func); + } + +void CAllFuncs::AddTableFunc(SImplFunc::TFuncType aType, int aParams, bool aParent, const string& aReturn, const string& aFuncName) + { + //Create a function of this form: + //TAknWindowLineLayout WindowTable$NUM$PARENT(TInt aLineIndex, $PARAMS_TYPES_AND_NAMES) + // { + // return AknLayoutDecode::WindowTable$NUM$PARENT(&KImplData, aLineIndex, $PARAM_NAMES); + // } + + string funcName = aFuncName + CdlTkUtil::IntToString(aParams) + (aParent ? "t" : "f"); + string defn = aReturn + " " + funcName + "(" + KTypeInt + " " + KParamLineIndex; + string body = string(") { return AknLayoutDecode::") + funcName + "(&KImplData, " + KParamLineIndex; + + if (aParent) + { + defn += ", " + KTypeRect + " " + KParamParentRect; + body += ", " + KParamParentRect; + } + + for (int ii=0; ii iBytes; + }; + +CLayoutInstOptImpl::CLayoutInstOptImpl(TLayoutLine* aLine, CCdlTkImplementation* aImpl) +: iLine(aLine), iImpl(aImpl) + { + } + + +class CLayoutInstOpt + { +public: + CLayoutInstOpt(LayoutCdlInstanceOpt& aInstances, auto_ptr& aLayout, const string& aInstName); + ~CLayoutInstOpt(); + + void Process(); + void WriteInstance(); + + CCdlTkInstance& Inst() { return *iInstance; } + +private: + void ProcessTable(TLayoutTable& aTable); + void ProcessLine(TLayoutLine& aLine); + void ProcessLineApi(TLayoutLine& aLine, CCdlTkImplementation& aImpl); + void ProcessMultiLineApi(TLayoutLine& aLine, CCdlTkImplementation& aImpl); + + void SetSimilarLineData(CLayoutInstOptImpl& aImpl, CLayoutInstOptImpl& aSimilar); + void SetNewLineData(CLayoutInstOptImpl& aImpl); + bool HasApi(const string& aName); + CCdlTkImplementation& FindImp(const string& aName); + void SetLineFunc(CLayoutInstOptImpl& aImpl); + + void CountApiParams(CCdlTkImplementation& aApi, int& aParams, bool& aParent); + SImplFunc& AddImplFunc(SImplFunc::TFuncType aType, int iParams, bool aParent); + + void SetExtraCpp(); + + void AddTableToInstance(TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSub, int aTableNum); + void AddTableLimitsImpl(const string& aApiName, TLayoutTable::TLayoutSubTable& aSubTable); + void AddTableImpl(const string& aApiName, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSub); + + void EncodeValue(vector& aBytes, string aValue); + + void MirrorParamName(string& aParamName); + +private: + LayoutCdlInstanceOpt& iInstances; + TLayout* iLayout; + string iName; + CCdlTkInterface& iInterface; + CCdlTkInstance* iInstance; + CLayoutInstOptImpls iImpls; + typedef vector CImplFuncs; + CImplFuncs iFuncs; + }; + +CLayoutInstOpt::CLayoutInstOpt(LayoutCdlInstanceOpt& aInstances, auto_ptr& aLayout, const string& aInstName) +: iInstances(aInstances), iName(aInstName), iInterface(iInstances.Interface()) + { + iLayout = aLayout.get(); + aLayout.release(); + + iInstance = new CCdlTkInstance(iInterface); + iInstance->SetName(aInstName); + + // Initially set definitions that will not compile in the resulting code. + // This will alert the programmer to missing layout data. + CCdlTkImplementations& impl = iInstance->Impl(); + for (CCdlTkImplementations::iterator pImpl = impl.begin(); pImpl != impl.end(); ++pImpl) + (*pImpl)->SetDefinition(KDefinitionNotSet); + } + +CLayoutInstOpt::~CLayoutInstOpt() + { + delete iLayout; + delete iInstance; + for (CLayoutInstOptImpls::iterator pImpl = iImpls.begin(); pImpl != iImpls.end(); ++pImpl) + delete *pImpl; + } + +void CLayoutInstOpt::Process() + { + for (TLayout::iterator pTab = iLayout->begin(); pTab != iLayout->end(); ++pTab) + ProcessTable(**pTab); + SetExtraCpp(); + } + +void CLayoutInstOpt::WriteInstance() + { + CCdlTkWriteInstance writer(*iInstance); + writer.Process(); + } + +void CLayoutInstOpt::ProcessTable(TLayoutTable& aTable) + { + for (TLayoutTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) + ProcessLine(**pLine); + + int tableNum = 0; + for (TLayoutTable::TLayoutSubTables::const_iterator pSub = aTable.iSubTables.begin(); pSub != aTable.iSubTables.end(); ++pSub) + { + TLayoutTable::TLayoutSubTable& sub = **pSub; + AddTableToInstance(aTable, sub, tableNum); + tableNum++; + } + } + +void CLayoutInstOpt::ProcessLine(TLayoutLine& aLine) + { + string apiName = LayoutToCdl::LineApiName(aLine); + if (!HasApi(apiName)) + return; + + ProcessLineApi(aLine, FindImp(apiName)); + + string multilineApiName = KFuncMultiline + apiName; + if (aLine.iTable->iType == TLayoutTable::ETextTable && + aLine["B"].size() > 1 && + HasApi(multilineApiName)) + ProcessMultiLineApi(aLine, FindImp(multilineApiName)); + } + +void CLayoutInstOpt::ProcessLineApi(TLayoutLine& aLine, CCdlTkImplementation& aImpl) + { + CLayoutInstOptImpl* newImpl = new CLayoutInstOptImpl(&aLine, &aImpl); + iImpls.push_back(newImpl); + + // always set the new line data + SetNewLineData(*newImpl); + + // if we can find the new line data in the aggregated data, point to that instead + int foundIndex = iInstances.FindSimilarBytes(newImpl); + if(foundIndex >= 0) + { + newImpl->iByteCodeIndex = foundIndex; + newImpl->iBytes.clear(); + } + + SetLineFunc(*newImpl); + iInstances.AddImpl(newImpl); + newImpl->iImpl->SetDefinition(CdlTkUtil::ShortToHexString(newImpl->iByteCodeIndex) + ",\t// " + LayoutToCdl::LineApiName(aLine)); + } + +void CLayoutInstOpt::ProcessMultiLineApi(TLayoutLine& aLine, CCdlTkImplementation& aImpl) + { + CLayoutInstOptImpl* newImpl = new CLayoutInstOptImpl(&aLine, &aImpl); + iImpls.push_back(newImpl); + + CCdlTkImplementation& textImpl = FindImp(LayoutToCdl::LineApiName(aLine)); + + // locate the position of the "aIndex_B" paramters in the text API parameter list + // and the position of the "aNumberOfLinesShown" parameter in the multiline API + // parmeter list. This is all the info needed to implement multiline APIs in terms + // of the corresponding text API + int bPos = 4, lPos = 0; + const CCdlTkApiParams& mParams = aImpl.Api().AsFunc().Params(); + const CCdlTkApiParams& tParams = textImpl.Api().AsFunc().Params(); + CCdlTkApiParams::const_iterator pMParam = mParams.begin(); + CCdlTkApiParams::const_iterator pTParam = tParams.begin(); + int ii=0; + while (pMParam != mParams.end() || pTParam != tParams.end()) + { + if (pTParam != tParams.end()) + { + if (pTParam->Name() == KParamNameB) + bPos = ii; + ++pTParam; + } + if (pMParam != mParams.end()) + { + if (pMParam->Name() == KParamNameNumberOfLinesShown) + lPos = ii; + ++pMParam; + } + ii++; + } + + SetLineFunc(*newImpl); + iInstances.AddImpl(newImpl); + newImpl->iImpl->SetDefinition(CdlTkUtil::ShortToHexString((bPos<<8)|lPos) + ",\t// " + aImpl.Name()); + } + + +void CLayoutInstOpt::SetSimilarLineData(CLayoutInstOptImpl& aImpl, CLayoutInstOptImpl& aSimilar) + { + aImpl.iByteCodeIndex = aSimilar.iByteCodeIndex; + } + +void CLayoutInstOpt::SetNewLineData(CLayoutInstOptImpl& aImpl) + { + TLayoutLine& line = *aImpl.iLine; + + // set comment + aImpl.iComment = string("for ") + LayoutToCdl::LineApiName(line); + + const string* outputOrder = KWindowOutputOrder; + int outputSize = KWindowOutputOrderSize; + if (line.iTable->iType == TLayoutTable::ETextTable) + { + outputOrder = KTextOutputOrder; + outputSize = KTextOutputOrderSize; + } + + // encode parameters + const CCdlTkApiParams& params = aImpl.iImpl->Api().AsFunc().Params(); + for (CCdlTkApiParams::const_iterator pParam = params.begin(); pParam != params.end(); ++pParam) + { + const CCdlTkApiParam& param = *pParam; + if (param.Type() == KTypeInt) // is it a cell index parameter + { + string paramName = param.Name(); + if (line.iIsMirroredHorizontally) + MirrorParamName(paramName); + char cells = 0; // bit field for cells that this parameter applies to + char maxVal = 0; + char nextCell = 1; // bit flag for the next cell + for (int ii=0; iiType() == KTypeInt) // is it a cell index parameter + aParams++; + else + aParent = true; + } + } + +void CLayoutInstOpt::SetLineFunc(CLayoutInstOptImpl& aImpl) + { + int nParams; + bool hasParent; + CountApiParams(*aImpl.iImpl, nParams, hasParent); + + SImplFunc::TFuncType type = SImplFunc::EWindowLine; + if (aImpl.iLine->iTable->iType == TLayoutTable::ETextTable) + { + type = SImplFunc::ETextLine; + string name = aImpl.iImpl->Name(); + if (name.size() > KFuncMultiline.size() && name.substr(0,KFuncMultiline.size()) == KFuncMultiline) + type = SImplFunc::EMultilineTextLine; + } + + SImplFunc& func = AddImplFunc(type, nParams, hasParent); + aImpl.iImpl->SetPointerReference(func.iPtrRef); + } + +CCdlTkImplementation& CLayoutInstOpt::FindImp(const string& aName) + { + CCdlTkImplementation* impl = iInstance->Impl().Find(aName); + if (!impl) + throw NotFoundErr(aName + " in interface " + iInterface.FileName()); + return *impl; + } + +bool CLayoutInstOpt::HasApi(const string& aName) + { + return iInterface.ApiList().Find(aName) != 0; + } + +SImplFunc& CLayoutInstOpt::AddImplFunc(SImplFunc::TFuncType aType, int aParams, bool aParent) + { + for (CImplFuncs::iterator pFunc = iFuncs.begin(); pFunc != iFuncs.end(); ++pFunc) + { + SImplFunc& func = **pFunc; + if (func.iType == aType && func.iParams == aParams && func.iParent == aParent) + return func; + } + + int count = gTheFuncs.size(); + for (int ii=0; iiiType == aType && func->iParams == aParams && func->iParent == aParent) + { + iFuncs.push_back(func); + return *func; + } + } + + throw NotFoundErr("implementation function"); + return gTheFuncs[0]; + } + +// The following strings and the SetExtraCpp() function build the gross structure of +// the C++ customisation instance. +// So far, the implementations are actually just 16-bit values, typically indexes into +// the data lookup table. These need to be turned into an array by adding declarations +// and brackets to the first and last implementations. Extra support functions are also +// added. +extern string KExtraCpp = "\ +#include \"aknlayout2decode.h\"\n\ +namespace $INTERFACE_NS { extern const TUint8 KByteCodedData[]; }\n"; + +extern string KInitialCpp ="\ +extern const TUint16 KDataLookup[$INTERFACE_NS::E_TApiId_TableSize];\n\ +const SImplData KImplData = { KDataLookup, $INTERFACE_NS::KByteCodedData };\n\ +\n\ +$FUNCTIONS\ +\n\ +const TUint16 KDataLookup[$INTERFACE_NS::E_TApiId_TableSize] =\n\ +\t{\n"; + +void CLayoutInstOpt::SetExtraCpp() + { + // The "extra cpp" field is written to the top of the cpp file. + iInstance->SetExtraCpp(CdlTkUtil::Replace("$INTERFACE_NS", iInterface.NamespaceName(), KExtraCpp)); + + // add headers & fwd declarations + string init = CdlTkUtil::Replace("$INTERFACE_NS", iInterface.NamespaceName(), KInitialCpp); + + // add decode functions + string functions; + for (CImplFuncs::iterator pFunc = iFuncs.begin(); pFunc != iFuncs.end(); ++pFunc) + { + CdlTkUtil::AppendString(functions, (*pFunc)->iDefn); + CdlTkUtil::AppendString(functions, "\n"); + } + init = CdlTkUtil::Replace("$FUNCTIONS", functions, init); + CCdlTkImplementation& first = **(iInstance->Impl().begin()); + first.SetDefinition(init + first.Definition()); + + // add end of data table + CCdlTkImplementation& last = **(iInstance->Impl().end() - 1); + last.SetDefinition(last.Definition() + "\n};"); + } + +void CLayoutInstOpt::AddTableToInstance(TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSub, int aTableNum) + { + string tableName = LayoutToCdl::TableApiName(aTable, aSub, aTableNum); + if (HasApi(tableName)) + { + AddTableLimitsImpl(tableName + KFuncLimitsSuffix, aSub); + AddTableImpl(tableName, aTable, aSub); + } + } + +void CLayoutInstOpt::AddTableLimitsImpl(const string& aApiName, TLayoutTable::TLayoutSubTable& aSubTable) + { + // code up table limits as a pair of byte values, the first byte is the first table + // index, the second is the last table index. + CCdlTkImplementation& impl = FindImp(aApiName); + int first = (*aSubTable.begin()) & 0xff; + int last = (*aSubTable.rbegin()) & 0xff; + impl.SetDefinition(CdlTkUtil::ShortToHexString((first<<8)|last) + ","); + impl.SetPointerReference(AddImplFunc(SImplFunc::ETableLimits, 0, false).iPtrRef); + } + +void CLayoutInstOpt::AddTableImpl(const string& aApiName, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSub) + { + CCdlTkImplementation& impl = FindImp(aApiName); + + int nParams; + bool hasParent; + CountApiParams(impl, nParams, hasParent); + nParams--; // don't count the aLineIndex param + SImplFunc::TFuncType type = SImplFunc::EWindowTable; + if (aTable.iType == TLayoutTable::ETextTable) + type = SImplFunc::ETextTable; + + SImplFunc& func = AddImplFunc(type, nParams, hasParent); + + impl.SetDefinition(string("(TUint16)") + iInterface.NamespaceName() + "::EApiId_" + LayoutToCdl::LineApiName(*aTable[0]) + ","); + impl.SetPointerReference(func.iPtrRef); + } + +struct SIdToInt + { + int iInt; + char* iStr; + }; + +#include +const int KScalableFontIdOffset(0x1000); +extern SIdToInt gIdToIntTable[] = + { + { ELayoutAlignLeft, "ELayoutAlignLeft" }, + { ELayoutAlignRight, "ELayoutAlignRight" }, + { ELayoutAlignCenter, "ELayoutAlignCenter" }, + { ELayoutAlignBidi, "ELayoutAlignBidi" }, + { ELatinBold19, "ELatinBold19" }, + { ELatinBold17, "ELatinBold17" }, + { ELatinBold13, "ELatinBold13" }, + { ELatinBold12, "ELatinBold12" }, + { ELatinPlain12, "ELatinPlain12" }, + { ELatinClock14, "ELatinClock14" }, + { EApacPlain12, "EApacPlain12" }, + { EApacPlain16, "EApacPlain16" }, + { ENumberPlain5, "ENumberPlain5" }, + { ELatinBold16, "ELatinBold16" }, + + { ELatinBold19+KScalableFontIdOffset, "ELatinBold19_Scaled" }, + { ELatinBold17+KScalableFontIdOffset, "ELatinBold17_Scaled" }, + { ELatinBold13+KScalableFontIdOffset, "ELatinBold13_Scaled" }, + { ELatinBold12+KScalableFontIdOffset, "ELatinBold12_Scaled" }, + { ELatinPlain12+KScalableFontIdOffset, "ELatinPlain12_Scaled" }, + { ELatinClock14+KScalableFontIdOffset, "ELatinClock14_Scaled" }, + { EApacPlain12+KScalableFontIdOffset, "EApacPlain12_Scaled" }, + { EApacPlain16+KScalableFontIdOffset, "EApacPlain16_Scaled" }, + { ENumberPlain5+KScalableFontIdOffset, "ENumberPlain5_Scaled" }, + { ELatinBold16+KScalableFontIdOffset, "ELatinBold16_Scaled" }, + + { 100, "qfn_latin_plain_17" }, // fonts that appear in app laf + { ECalcBold21, "ECalcBold21" }, + { ECalcOperBold21, "ECalcOperBold21" }, + { ECalcOperBold13, "ECalcOperBold13" }, + { 100, "gfn_latin_bold_13" }, + { 100, "gfn_latin_plain_12" }, + { 100, "qfn_clock_plain_5" }, + + { 100, "qfn_latin_plain_17_Scaled" }, + { ECalcBold21+KScalableFontIdOffset, "ECalcBold21_Scaled" }, + { ECalcOperBold21+KScalableFontIdOffset, "ECalcOperBold21_Scaled" }, + { ECalcOperBold13+KScalableFontIdOffset, "ECalcOperBold13_Scaled" }, + { 100, "gfn_latin_bold_13_Scaled" }, + { 100, "gfn_latin_plain_12_Scaled" }, + { 100, "qfn_clock_plain_5_Scaled" } + + }; +extern const int gIdToIntTableCount = sizeof(gIdToIntTable)/sizeof(SIdToInt); + +extern void TranslateValue(string& aValue) + { + int count = gIdToIntTableCount; + for (int ii=0; ii& aBytes, string aValue) + { + int pos; + TranslateValue(aValue); + + if (aValue == "") + { + aBytes.push_back(KByteEmpty); + } + else if ((pos = aValue.find('p')) != string::npos) + { + if (pos != 0) + throw CdlTkAssert(string("arithmetic parser not good enough : ") + aValue); + int val = CdlTkUtil::ParseInt(aValue.substr(1)); + if (-128 <= val && val <= 127) + { + aBytes.push_back(KByteP1); + aBytes.push_back(val); + } + else + { + aBytes.push_back(KByteP2); + aBytes.push_back((val & 0xff00) >> 8); + aBytes.push_back(val); + } + } + else + { + int val = CdlTkUtil::ParseInt(aValue); + if (0 <= val && val <= KMaxSingleByteValue) + { + aBytes.push_back(val); + } + else + { + aBytes.push_back(KByteWord); + aBytes.push_back((val & 0xff00) >> 8); + aBytes.push_back(val); + } + } + } + +void CLayoutInstOpt::MirrorParamName(string& aParamName) + { + if (aParamName == KParamNameL) + aParamName = KParamNameR; + else if (aParamName == KParamNameR) + aParamName = KParamNameL; + } + + + +// +// CInstanceList +// + +void CInstanceList::ProcessOptions(vector& aArgs) + { + bool instanceFileOk = false; + iLoaded = false; + string instFile; + for(vector::iterator pArg = aArgs.begin(); pArg != aArgs.end(); ++pArg) + { + string& arg = *pArg; + if (arg.size() >= 2 && arg.substr(0,2) == "-i") + { + instFile = arg.substr(2); + aArgs.erase(pArg); + instanceFileOk = true; + break; + } + } + if(!instanceFileOk) + throw LayoutCdlInstanceOptArgsErr(); + ifstream in; + CdlTkUtil::OpenInput(in, instFile); + iLoaded = true; + string line; + while (!in.eof()) + { + getline(in, line); + iInstances.insert(line); + } + in.close(); + } + +bool CInstanceList::IsInstanceOk(const string& aInstance) const + { + return (!iLoaded || iInstances.find(aInstance) != iInstances.end()); + } + + +// +// LayoutCdlInstanceOpt +// + +int LayoutCdlInstanceOpt::Process(vector& args) + { + CInstanceList instList; + instList.ProcessOptions(args); + + int extraArgs = args.size() - 5; + if (extraArgs < 0 || extraArgs%2 == 1) + throw LayoutCdlInstanceOptArgsErr(); + + string cdlName = args[2]; + CCdlTkCdlFileParser parser(cdlName); + auto_ptr iface(parser.LoadAndParse(true)); + + LayoutCdlInstanceOpt process(*iface); + + TLayout* base = NULL; + for (int arg = 3; arg < args.size(); arg += 2) + { + string layoutName = args[arg]; + string instName = args[arg+1]; + if (!instList.IsInstanceOk(instName)) + continue; + + auto_ptr layoutParse = TLayParseLayout::Parse(layoutName); + auto_ptr layout(layoutParse.get()); + layoutParse.release(); + if (base) + { + auto_ptr newLayout(new TLayout(*base)); + newLayout->Merge(TLayout::KMergeModeVariant, *layout); + layout = newLayout; + } + else + { + base = layout.get(); + } + process.AddLayout(layout, instName); + } + + if (base) + { + process.Process(); + process.WriteInstances(); + } + + return 0; + } + +void LayoutCdlInstanceOpt::ShowHelp(ostream& stream) + { + stream << "LayCdl2InstO [-i] ( )+ " << endl; + stream << " Creates optimised CDL instances containing the layout data." << endl; + stream << " All layout instances must conform to the CDL interface." << endl; + stream << " If more than one layout is supplies, subsequent ones are treated as" << endl; + stream << " variants of the first." << endl; + stream << " If -i is specified, then only instances whose name" << endl; + stream << " appears in the file will be processed" << endl; + } + +LayoutCdlInstanceOpt::LayoutCdlInstanceOpt(CCdlTkInterface& aInterface) +: iInterface(aInterface), iByteCodeIndex(0) + { + } + +LayoutCdlInstanceOpt::~LayoutCdlInstanceOpt() + { + for (CLayouts::iterator pLayout = iLayouts.begin(); pLayout != iLayouts.end(); ++pLayout) + delete *pLayout; + } + +void LayoutCdlInstanceOpt::AddLayout(auto_ptr& aLayout, const string& aInstName) + { + auto_ptr p(new CLayoutInstOpt(*this, aLayout, aInstName)); + iLayouts.push_back(p.get()); + p.release(); + } + +void LayoutCdlInstanceOpt::Process() + { + for (CLayouts::iterator pLayout = iLayouts.begin(); pLayout != iLayouts.end(); ++pLayout) + (*pLayout)->Process(); + ProcessCommonImpl(); + } + +void LayoutCdlInstanceOpt::WriteInstances() + { + for (CLayouts::iterator pLayout = iLayouts.begin(); pLayout != iLayouts.end(); ++pLayout) + (*pLayout)->WriteInstance(); + } + +CCdlTkInterface& LayoutCdlInstanceOpt::Interface() + { + return iInterface; + } + +const string KCommonImplStart = "\ +#include \"aknlayout2decode.h\"\n\ +namespace $NAMESPACENAME { extern TUint8 const KByteCodedData[] = {\n"; + +const string KCommonImplImpl = "\ +// $INDEX $COMMENT\n\ +$BYTES\n"; + +void LayoutCdlInstanceOpt::ProcessCommonImpl() + { + string bytecode = CdlTkUtil::Replace("$NAMESPACENAME", iInterface.NamespaceName(), KCommonImplStart); + + for (CLayoutInstOptImpls::iterator pImpl = iImpls.begin(); pImpl != iImpls.end(); ++pImpl) + { + vector& bytes = (*pImpl)->iBytes; + if (bytes.size()) + { + string byteString; + for (vector::iterator pChar = bytes.begin(); pChar != bytes.end(); ++pChar) + { + CdlTkUtil::AppendString(byteString, CdlTkUtil::CharToHexString(*pChar)); + CdlTkUtil::AppendString(byteString, ","); + } + + CdlTkUtil::CReplaceSet implSet; + implSet.Add("$INDEX", CdlTkUtil::ShortToHexString((*pImpl)->iByteCodeIndex)); + implSet.Add("$COMMENT", (*pImpl)->iComment); + implSet.Add("$BYTES", byteString); + CdlTkUtil::AppendString(bytecode, CdlTkUtil::MultiReplace(implSet, KCommonImplImpl)); + } + } + CdlTkUtil::AppendString(bytecode, "};\n}"); + + CCdlTkInstance& firstInst = iLayouts[0]->Inst(); + firstInst.SetExtraCpp(bytecode); + } + +LayoutCdlInstanceOpt::CLayouts& LayoutCdlInstanceOpt::Layouts() + { + return iLayouts; + } + +CLayoutInstOptImpl* LayoutCdlInstanceOpt::FindSimilarImpl(TLayoutLine& aLine) + { + for (CLayoutInstOptImpls::iterator pImpl = iImpls.begin(); pImpl != iImpls.end(); ++pImpl) + { + CLayoutInstOptImpl* impl = *pImpl; + if (LinesAreEqual(*impl->iLine, aLine)) + { + return impl; + } + } + return NULL; + } + +int LayoutCdlInstanceOpt::FindSimilarBytes(CLayoutInstOptImpl* aImpl) + { + int index = -1; + vector::iterator found = std::search( + iBytesAggregated.begin(), + iBytesAggregated.end(), + aImpl->iBytes.begin(), + aImpl->iBytes.end()); + if(found != iBytesAggregated.end()) + { + index = std::distance(iBytesAggregated.begin(), found); + } + return index; + } + +void LayoutCdlInstanceOpt::AddImpl(CLayoutInstOptImpl* aImpl) + { + iImpls.push_back(aImpl); + int bytesAdded = aImpl->iBytes.size(); + if (bytesAdded) + { + aImpl->iByteCodeIndex = iByteCodeIndex; + iByteCodeIndex += bytesAdded; + iBytesAggregated.insert( + iBytesAggregated.end(), + aImpl->iBytes.begin(), + aImpl->iBytes.end()); + } + } + +bool LayoutCdlInstanceOpt::LinesAreEqual(TLayoutLine& aLine1, TLayoutLine& aLine2) + { + TLayoutLine::iterator pValues1 = aLine1.begin(); + TLayoutLine::iterator pValues2 = aLine2.begin(); + for (; pValues1 != aLine1.end() && pValues2 != aLine2.end(); ++pValues1, ++pValues2) + { + if (TLayoutTable::IsValueColumn(pValues1->first) && *pValues1 != *pValues2) + return false; + } + return true; + } diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/LayCdlCheck.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/LayCdlCheck.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,206 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "LayCdlCheck.h" +#include +#include "LayoutCompilerErr.h" +#include "LayoutParse.h" +#include "Lay2Cdl.h" +#include +using namespace std; +using namespace CdlCompilerToolkit; + + +typedef LayoutProcessArgsErr LayCdlCheckArgsErr; + +const string KDefaultLayCdlCheckOptions = "lcm"; + +int LayCdlCheck::Process(const vector& args) + { + if (args.size() < 4) + throw LayCdlCheckArgsErr(); + + int nextArg = 2; + string opt = args[nextArg]; + if (opt.size() >= 2 && opt.substr(0,2) == "-o") + { + nextArg++; + opt = opt.substr(2); + } + else + { + opt = KDefaultLayCdlCheckOptions; + } + + string layoutName = args[nextArg++]; + auto_ptr layout(TLayParseLayout::Parse(layoutName)); + auto_ptr iface(new CCdlTkInterface); + CCdlTkApiList& apiList = iface->ApiList(); + auto_ptr xIface(new CCdlTkInterface); + CCdlTkApiList& xApiList = xIface->ApiList(); + + for (int arg = nextArg; arg < args.size(); arg++) + { + string fileName = args[arg]; + if (fileName.size() < 4) + throw LayCdlCheckArgsErr(); + string ext = CdlTkUtil::ToLower(fileName.substr(fileName.size()-4)); + + if (ext == ".lay") + { + auto_ptr nextLayout(TLayParseLayout::Parse(fileName)); + layout->Merge(TLayout::KMergeModeVariant, *nextLayout); + } + else if (ext == ".cdl") + { + CCdlTkApiList* pApiList = &apiList; + if (fileName.substr(0,2) == "-x") + { + pApiList = &xApiList; + fileName = fileName.substr(2); + } + CCdlTkCdlFileParser parser(fileName); + auto_ptr nextIface(parser.LoadAndParse(true)); + CCdlTkApiList& nextApi = nextIface->ApiList(); + for (CCdlTkApiList::iterator pApi = nextApi.begin(); pApi != nextApi.end(); ++pApi) + pApiList->push_back((*pApi)->Clone(*iface)); + } + else + throw LayCdlCheckArgsErr(); + } + + LayCdlCheck process(*layout, *iface, *xIface, opt); + process.Process(); + + return 0; + } + +void LayCdlCheck::ShowHelp(ostream& stream) + { + stream << "LayCdlCheck [-o[glcm]] * * [-x*]" << endl; + stream << " Compare API for lay files against CDL interfaces" << endl; + stream << " -o[glcm] (default = -olcm) - show output for:" << endl; + stream << " g = good matches" << endl; + stream << " l = lay file only" << endl; + stream << " c = CDL interface only" << endl; + stream << " m = mismatches" << endl; + stream << " Where multiple are specified, the layouts are merged with variant mode." << endl; + stream << " Where multiple are specified, the CDL interfaces are added together." << endl; + stream << " -x - exclude APIs in from the report." << endl; + } + + +LayCdlCheck::LayCdlCheck(TLayout& aLayout, CCdlTkInterface& aInterface, CCdlTkInterface& aExcluded, const string& aOpt) +: iLayout(aLayout), iInterface(aInterface), iExcluded(aExcluded), iLayoutInterface(0), iOpt(aOpt) + { + } + +LayCdlCheck::~LayCdlCheck() + { + delete iLayoutInterface; + } + +void LayCdlCheck::Process() + { + delete iLayoutInterface; + iLayoutInterface = 0; + + auto_ptr iface(LayoutToCdl::LayoutToInterface(iLayout)); + iLayoutInterface = iface.get(); + iface.release(); + + vector good; + vector onlyLay; + vector onlyCdl; + vector paramMismatch; + + Compare(good, onlyLay, onlyCdl, paramMismatch); + + if (HasOpt('g')) + Report("Good API", good); + if (HasOpt('l')) + Report("API only in lay file", onlyLay); + if (HasOpt('c')) + Report("API only in CDL file", onlyCdl); + if (HasOpt('m')) + Report("API with mismatched interface", paramMismatch); + } + +void LayCdlCheck::Compare(vector& aGood, vector& aOnlyLay, vector& aOnlyCdl, vector& aParamMismatch) + { + CCdlTkApiList& layApi = iLayoutInterface->ApiList(); + CCdlTkApiList& cdlApi = iInterface.ApiList(); + CCdlTkApiList& xApi = iExcluded.ApiList(); + for (CCdlTkApiList::iterator pLay = layApi.begin(); pLay != layApi.end(); ++pLay) + { + const string& name = (*pLay)->Name(); + CCdlTkApi* xCdl = xApi.Find(name); + if (xCdl && (*xCdl) == (**pLay)) + continue; + + string fullName = (*pLay)->ReturnType() + " " + name + (*pLay)->ParamsTypeAndNameList() + ";"; + CCdlTkApi* cdl = cdlApi.Find(name); + if (cdl) + { + if (*cdl == **pLay) + { + aGood.push_back(fullName); + } + else + { + aParamMismatch.push_back(fullName + " vs " + cdl->ParamsTypeAndNameList()); + } + } + else + { + aOnlyLay.push_back(fullName); + } + } + + for (CCdlTkApiList::iterator pCdl = cdlApi.begin(); pCdl != cdlApi.end(); ++pCdl) + { + const string& name = (*pCdl)->Name(); + string fullName = (*pCdl)->ReturnType() + " " + name + (*pCdl)->ParamsTypeAndNameList(); + CCdlTkApi* lay = layApi.Find(name); + if (!lay) + { + aOnlyCdl.push_back(fullName); + } + } + } + +void LayCdlCheck::Report(const string& aTitle, vector& aApi) + { + cout << aTitle << endl; + for (vector::iterator pApi = aApi.begin(); pApi != aApi.end(); ++pApi) + { + cout << *pApi << endl; + } + cout << endl; + } + +bool LayCdlCheck::HasOpt(char c) + { + return iOpt.find(c) != string::npos; + } + + diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/LayPerfWriter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/LayPerfWriter.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,277 @@ +/* +* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +#include "LayPerfWriter.h" +#include "Lay2Cdl.h" // for static methods +#include "Layout.h" // for constants +#include "CodeGenConsts.h" + +#include + +#include +#include +#include +#include +#include + +using namespace std; +using namespace CdlCompilerToolkit; + + +// +// TLayPerfTableWriter +// + +TLayPerfTableWriter::TLayPerfTableWriter(TLayoutTable& aTable, string& aInterfaceName, int aTableId) + : + iTable(aTable), + iInterfaceName(aInterfaceName), + iTableId(aTableId) + { + } + +TLayPerfTableWriter::~TLayPerfTableWriter() + { + } + +void TLayPerfTableWriter::Write(ostream& out) + { + if (IsWindowTable()) + { + WriteWindowTable(out); + } + else if (IsTextTable()) + { + WriteTextTable(out); + } + else + { + cout << "Unknown " << "Table " << iTable.Name() << endl; + } + } + +bool TLayPerfTableWriter::IsWindowTable() + { + return iTable.iType == TLayoutTable::EWindowTable; + } + + +const string KTestAPITableFuntionSig = "\ +testLayout_$LAYOUT_$TABLEID()"; + +string GenerateFunctionName(string aInterfaceName, int aTableId) + { + string tableNum = CdlTkUtil::IntToString(aTableId); + + CdlTkUtil::CReplaceSet rep; + rep.Add("$LAYOUT", aInterfaceName); + rep.Add("$TABLEID", tableNum); + return CdlTkUtil::MultiReplace(rep, KTestAPITableFuntionSig); + } + +void TLayPerfTableWriter::WriteWindowTable(ostream& out) + { + out << "void " << GenerateFunctionName(iInterfaceName, iTableId) << endl; + + out << "{" << endl; // start of function + out << "DECLARE_LOCAL_VARS_COUNTS" << endl; + out << "DECLARE_LOCAL_VARS_LIMITS" << endl; + + out << "\n// Layout MACROs for LAF Table : "; + out << iTable.Name() << endl; + + for (int i=0; i paramList; + bool mirrored = aLine.iIsMirroredHorizontally; + + if (aLine.iNeedsP) + { + aParams += "aParent"; + } + + if (aLine.iNeedsIndex) + { + for (int i=0; i < aCount; i++) + { + const string& name = aKParams[i]; + const TValues& defValues = aLine[name]; + if (defValues.iNeedsIndex) + { + string paramName = CdlTkUtil::ToCpp(defValues.ParamName()); + if (mirrored) + { + if (paramName == KParamNameL) + paramName = KParamNameR; + else if (paramName == KParamNameR) + paramName = KParamNameL; + } + + if(find(paramList.begin(), paramList.end(), paramName) == paramList.end()) + { + if(aParams.size() > 0) + aParams += ", "; + aParams += paramName; + paramList.push_back(paramName); + + aLimits += paramName + "_Limit" + " = "; + aLimits += CdlTkUtil::IntToString(defValues.size() - 1) + "; "; // subtract one from the max value to give the upper limit + } + } + } + } + } + +void TLayPerfTableWriter::WriteCell(ostream& out, TValues& values) + { + if (values.size() > 1) + out << "{"; + + for (TValues::iterator pVal = values.begin(); pVal != values.end(); ++pVal) + { + if (pVal != values.begin()) + out << ", "; + out << *pVal; + } + + if (values.size() > 1) + out << "}"; + + if (values.iParam.length()) + out << "[" << values.iParam << "]"; + } + + +bool TLayPerfTableWriter::IsTextTable() + { + return iTable.iType == TLayoutTable::ETextTable; + } + +void TLayPerfTableWriter::WriteTextTable(ostream& out) + { + out << "void " << GenerateFunctionName(iInterfaceName, iTableId) << endl; + + out << "{" << endl; // start of function + out << "DECLARE_LOCAL_VARS_COUNTS" << endl; + out << "DECLARE_LOCAL_VARS_LIMITS" << endl; + + out << "// Layout MACROs for LAF Table : "; + out << iTable.Name() << endl; + + for (int i=0; i +#include +#include +#include +#include "LayoutWriter.h" + +typedef LayoutProcessArgsErr LayoutScaleArgsErr; + + +int LayoutScale::Process(const vector& args) + { + if (args.size() != 8) + throw LayoutScaleArgsErr(); + + auto_ptr sourceLayout(TLayParseLayout::Parse(args[2])); + int sourceWidth = CdlTkUtil::ParseInt(args[3]); + int sourceHeight = CdlTkUtil::ParseInt(args[4]); + + string destLayout = args[5]; + int destWidth = CdlTkUtil::ParseInt(args[6]); + int destHeight = CdlTkUtil::ParseInt(args[7]); + + LayoutScale scale(*sourceLayout, sourceWidth, sourceHeight, destLayout, destWidth, destHeight); + scale.Run(); + + return 0; + } + +void LayoutScale::ShowHelp(ostream& stream) + { + stream << "LayScale " << endl; + stream << " This performs an arithmetic scaling on all dimensional values in a layout." << endl; + stream << " This will not produce a pixel perfect scaling effect due to rounding errors," << endl; + stream << " however it may be sufficient for prototyping and demonstration purposes." << endl; + } + +LayoutScale::LayoutScale(TLayout& aSourceLayout, int aSourceWidth, int aSourceHeight, const string& aDestLayoutName, int aDestWidth, int aDestHeight) +: iLayout(aSourceLayout), + iSourceWidth(aSourceWidth), + iSourceHeight(aSourceHeight), + iDestLayoutName(aDestLayoutName), + iDestWidth(aDestWidth), + iDestHeight(aDestHeight) + { + } + +void LayoutScale::Run() + { + RescaleLayout(); + WriteLayout(); + } + +const string KHoriz = "lrW"; +const string KVert = "tbBH"; +const string KFont = "Font"; +const string KScaledSuffix = "_Scaled"; + +void LayoutScale::RescaleLayout() + { + for (TLayout::iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab) + { + TLayoutTable& table = **pTab; + for (TLayoutTable::iterator pLine = table.begin(); pLine != table.end(); ++pLine) + { + TLayoutLine& line = **pLine; + for (TLayoutLine::iterator pCell = line.begin(); pCell != line.end(); ++pCell) + { + const string& cellName = pCell->first; + TValues& values = pCell->second; + if ( cellName == KFont) + { + for (TValues::iterator pVal = values.begin(); pVal != values.end(); ++pVal) + { + TagScaledToken(*pVal); + } + } + else + { + TScale dir = EHoriz; + if (KVert.find(cellName) != string::npos) + dir = EVert; + else if (KHoriz.find(cellName) == string::npos) + continue; + + for (TValues::iterator pVal = values.begin(); pVal != values.end(); ++pVal) + { + RescaleValue(*pVal, dir); + } + } + } + } + } + } + +void LayoutScale::RescaleValue(string& aVal, TScale aDir) + { + // find all numbers in this value and rescale them, copy non-numeric text directly. + string result; + string num; + int count = aVal.size(); + for (int pos = 0; pos < count; pos++) + { + char c = aVal[pos]; + if (CdlTkUtil::IsNumeric(c)) + { + num += c; + } + else + { + result += RescaleNum(num, aDir); + num = ""; + result += c; + } + } + result += RescaleNum(num, aDir); + aVal = result; + } + +void LayoutScale::TagScaledToken(string& aToken) + { + string result(aToken); + result += KScaledSuffix; + aToken = result; + } + +string LayoutScale::RescaleNum(string& aNum, TScale aDir) + { + if (aNum.empty()) + return aNum; + + int num = CdlTkUtil::ParseInt(aNum); + if (aDir == EHoriz) + num = Scale(num, iDestWidth, iSourceWidth); + else + num = Scale(num, iDestHeight, iSourceHeight); + return CdlTkUtil::IntToString(num); + } + +void LayoutScale::WriteLayout() + { + TLayoutWriter writer(iLayout, iDestLayoutName); + writer.Write(""); + } + +int LayoutScale::Scale(int aNumber, int aNumerator, int aDenominator) + { + // round to nearest whole number, rounding up on .5 + int num = (aNumber * aNumerator) / aDenominator; // rounded down + int remainder = (aNumber * aNumerator) % aDenominator; // remainder + + if ((remainder*2) >= aDenominator) + num++; // round up if remainder >= half + + return num; + } + + diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/Layout.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/Layout.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,703 @@ +/* +* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +#include "Layout.h" +#include "LayoutCompilerErr.h" +#include "CodeGenConsts.h" +#include "UsefulDefinitions.h" + +#include +#include +#include + +// TValues + +TValues::TValues() +: iLine(0), iName("Bad Value") + { + } + +TValues::TValues(TLayoutLine* aLine, string aName) +: iLine(aLine), iName(aName), iNeedsIndex(0) + { + } + +bool TValues::operator==(const TValues& aOther) const + { + typedef const vector TBase; + bool eq = + iName == aOther.iName && + iParam == aOther.iParam && + iNeedsP == aOther.iNeedsP && + iNeedsIndex == aOther.iNeedsIndex && + (*static_cast(this) == aOther); + return eq; + } + +void TValues::Merge(TValues& aValues) + { + clear(); + insert(begin(), aValues.begin(), aValues.end()); + } + +void TValues::Compile() + { + iNeedsP = false; + if (!TLayoutTable::IsValueColumn(iName)) + return; + + for (iterator it = begin(); it != end(); ++it) + { + bool back2IsAlphaNum = false; + bool back1IsAlphaNum = false; + bool back1IsP = false; + for (string::iterator pC = it->begin(); pC!=it->end(); ++pC) + { + bool IsAlphaNum = ( + ('A' <= *pC && *pC <= 'Z') || + ('a' <= *pC && *pC <= 'z') || + ('0' <= *pC && *pC <= '9') || + *pC == '_'); + + if (!back2IsAlphaNum && back1IsP && !IsAlphaNum) + iNeedsP = true; + + back1IsP = *pC == 'p'; + back2IsAlphaNum = back1IsAlphaNum; + back1IsAlphaNum = IsAlphaNum; + } + + if (!back2IsAlphaNum && back1IsP) + iNeedsP = true; + } + iNeedsIndex = (size() > 1); + } + +string TValues::ParamName() const + { + if (iParam.length()) + return iParam; + else + return KParamNameBase + iName; + } + +string TValues::CppValue(const string& aValue) + { + if (aValue.size()) + return aValue; + else + return "ELayoutEmpty"; + } + + +// TLayoutLine + +TLayoutLine::TLayoutLine( TLayoutTable* aTable, int aId ) +: iTable(aTable), + iId(aId), + iIsUnique(true), + iIsMirroredHorizontally(false), + iIsMergedIdentical(false) + {} + +TLayoutLine::TLayoutLine(TLayoutTable* aTable, const TLayoutLine& aOther) + { + *this = aOther; + iTable = aTable; + for (iterator pVal = begin(); pVal != end(); ++pVal) + { + TValues& val = pVal->second; + val.iLine = this; + } + } + +#ifdef RD_SHOW_ALL_AKNLAYOUTCOMPILER_WARNINGS +void TLayoutLine::WarnMergeMismatch(TLayoutLine& aLine) +#else +void TLayoutLine::WarnMergeMismatch(TLayoutLine& /* aLine */) +#endif + { + // Merge mismatch warnings are not shown from old lay files. +#ifdef RD_SHOW_ALL_AKNLAYOUTCOMPILER_WARNINGS + string name = Name(); + if (name.empty()) + name = TableName(); + else + name = iTable->iName + " | " + name; + cerr << "WARNING merge mismatch: " << iTable->iTables->iName << " | " << name; + cerr << " vs " << aLine.iTable->iTables->iName << endl; +#endif + } + +void TLayoutLine::Merge(TLayout::TMergeMode aMergeMode, TLayoutLine& aLine) + { + iIsMergedIdentical = (*this == aLine) && (aMergeMode == TLayout::KMergeModeVariant); + if (iIsMergedIdentical) + return; + + bool similar = (Name() == aLine.Name()); + iterator pVal; + + if (similar && aMergeMode == TLayout::KMergeModeVariant && aLine.iTable->iTables->iCanBeMirror) + { + // need to check to see if the parametrisations are mirrored + // first check for P + bool lr_p = (find("l")->second.iNeedsP && aLine["r"].iNeedsP); + bool rl_p = (find("r")->second.iNeedsP && aLine["l"].iNeedsP); + + // check if they both params are valid + bool lr_both = (find("l")->second.iNeedsIndex && aLine["r"].iNeedsIndex); + bool rl_both = (find("r")->second.iNeedsIndex && aLine["l"].iNeedsIndex); + + // check if params are the same + bool lr_same = (find("l")->second.iParam == aLine["r"].iParam); + bool rl_same = (find("r")->second.iParam == aLine["l"].iParam); + + // only mirrored if both are valid and same + bool lr = lr_p || (lr_both && lr_same); + bool rl = rl_p || (rl_both && rl_same); + + // if either or both are parametrised the same way, need to swap; doesn't matter if + // both attribs have same param, as swapping it won't make any difference. + if(rl || lr) + { + iIsMirroredHorizontally = true; + } + } + + if (similar) + { + for (pVal=begin(); pVal!=end(); ++pVal) + { + TValues& val = pVal->second; + string cell = pVal->first; + if (iIsMirroredHorizontally) + { + if (cell == "l") + cell = "r"; + else if (cell == "r") + cell = "l"; + } + + TValues& other = aLine[cell]; + if (val.size() != other.size() || + val.iNeedsIndex != other.iNeedsIndex || + val.iNeedsP != other.iNeedsP) + { + similar = false; + } + } + } + + if (!similar) + WarnMergeMismatch(aLine); + + switch(aMergeMode) + { + case TLayout::KMergeModeMerge: + case TLayout::KMergeModeUnion: + if (similar) + { + for (pVal=begin(); pVal!=end(); ++pVal) + pVal->second.Merge(aLine[pVal->first]); + } + else + { + clear(); + copy(aLine.begin(), aLine.end(), inserter(*this, begin())); + for (pVal=begin(); pVal!=end(); ++pVal) + pVal->second.iLine = this; + } + break; + case TLayout::KMergeModeVariant: + clear(); + copy(aLine.begin(), aLine.end(), inserter(*this, begin())); + for (pVal=begin(); pVal!=end(); ++pVal) + pVal->second.iLine = this; + break; + } + } + +bool TLayoutLine::operator==(const TLayoutLine& aOther) const + { + return (Name() == aOther.Name()) && ValuesEqual(aOther); + } + +bool TLayoutLine::ValuesEqual(const TLayoutLine& aOther) const + { + bool eq = true; + const_iterator pVal, pOther; + for (pVal = begin(), pOther = aOther.begin(); + eq && pVal != end() && pOther != aOther.end(); + ++pVal, ++pOther) + { + eq = (*pVal == *pOther); + } + eq = eq && pVal == end() && pOther == aOther.end(); + return eq; + } + +string TLayoutLine::Name() const + { + if (find("Item") != end()) + return find("Item")->second[0]; + else + return ""; + } + +string TLayoutLine::TableName() const + { + stringstream name; + name << iTable->Name() << "_Line_" << iId; + return name.str(); + } + +void TLayoutLine::Compile() + { + iNeedsP = false; + iNeedsIndex = false; + + for (iterator pVal = begin(); pVal != end(); ++pVal) + { + TValues& val = pVal->second; + val.Compile(); + + if (val.iNeedsP) + iNeedsP = true; + if (val.iNeedsIndex) + iNeedsIndex = true; + } + } + +bool TLayoutLine::MatchParams(const TLayoutLine& aLine) const + { + if (iNeedsP != aLine.iNeedsP) + return false; + + for (const_iterator pVal = begin(), pOther = aLine.begin(); pVal != end(); ++pVal, ++pOther) + { + const TValues& val = pVal->second; + const TValues& other = pOther->second; + if (val.iNeedsIndex != other.iNeedsIndex || val.ParamName() != other.ParamName()) + return false; + } + + return true; + } + + +// +// TLayoutTable +// + + + +TLayoutTable::TLayoutTable(TLayout* aTables) +: iTables(aTables), iType(EUnknownTable), iParent(0), iFirstLineGlobalIndex(-1), iAppend(false), iNoSubTables(false) + { + } + +TLayoutTable::TLayoutTable(TLayout* aTables, const TLayoutTable& aOther) +: iTables(aTables), iType(aOther.iType), iParent(0), + iFirstLineGlobalIndex(aOther.iFirstLineGlobalIndex), + iAppend(aOther.iAppend), iColumnNames(aOther.iColumnNames), iName(aOther.iName), + iParentName(aOther.iParentName), iNoSubTables(aOther.iNoSubTables) + { + for (const_iterator it = aOther.begin(); it != aOther.end(); ++it) + push_back(new TLayoutLine(this, **it)); + } + +TLayoutTable::~TLayoutTable() + { + for (iterator it = begin(); it != end(); ++it) + delete *it; + DestroySubTables(); + } + +void TLayoutTable::Merge(TLayout::TMergeMode aMergeMode, TLayoutTable& aTable) + { + if (aTable.iAppend) + { + insert(end(), aTable.begin(), aTable.end()); + aTable.clear(); + for (iterator pLine = begin(); pLine != end(); ++pLine) + (*pLine)->iTable = this; + } + else + { + // merge lines + iterator pNew = aTable.begin(); + switch(aMergeMode) + { + case TLayout::KMergeModeMerge: + { + if (size() == aTable.size()) + { + for (iterator pLine = begin(); pLine != end(); ++pLine) + { + (*pLine)->Merge(aMergeMode, **pNew); + pNew++; + } + } + else + { + // move the other tables contents to here + iterator pLine; + for (pLine = begin(); pLine != end(); ++pLine) + delete *pLine; + clear(); + insert(begin(), aTable.begin(), aTable.end()); + aTable.clear(); + for (pLine = begin(); pLine != end(); ++pLine) + (*pLine)->iTable = this; + } + break; + } + case TLayout::KMergeModeVariant: + { + iterator pLine; + // need to merge the matching lines but append the extra ones [LMB 11-10-2002] + for (pLine = begin(); pLine != end() && pNew != aTable.end(); ++pLine) + { + (*pLine)->Merge(aMergeMode, **pNew); + pNew++; + } + insert(end(), pNew, aTable.end()); + aTable.clear(); + for (pLine = begin(); pLine != end(); ++pLine) + (*pLine)->iTable = this; + break; + } + case TLayout::KMergeModeUnion: + { + int index = 0; + for (; pNew != aTable.end(); ++pNew) + { + bool found = false; + for (iterator pLine = begin()+index; pLine != end(); ++pLine) + { + if ((*pLine)->Name() == (*pNew)->Name()) + { + (*pLine)->Merge(aMergeMode, **pNew); + found = true; + break; + } + } + if (found) + { + delete *pNew; + } + else + { + if ((*pNew)->Name().empty()) + { + throw GeneralErr(Name() + " can't union merge unnamed line"); + } + push_back(*pNew); + (*pNew)->iTable = this; + if ((*pNew)->iId != size()) + iNoSubTables = true; + (*pNew)->iId = size(); + } + if (index+1 < size()) + index++; + } + aTable.clear(); + } + } + } + } + +string TLayoutTable::Name() + { + return iName; + } + +TLayoutLine* TLayoutTable::FindLine(const string& aName) + { + for (iterator it = begin(); it != end(); ++it) + if ((*it)->Name() == aName) + return *it; + return 0; + } + +void TLayoutTable::Compile() + { + if (iType == EUnknownTable && iColumnNames.size() && iColumnNames[0].size()) + { + if (iColumnNames[0] == "Item") + iType = EWindowTable; + else + iType = ETextTable; + } + + SetDefaultColumnNames(); + + iParent = iTables->FindLine(iParentName); + + iNeedsIndex = false; + iNeedsP = false; + for (iterator it = begin(); it != end(); ++it) + { + (*it)->Compile(); + if ((*it)->iNeedsIndex) + iNeedsIndex = true; + if ((*it)->iNeedsP) + iNeedsP = true; + } + + BuildSubTables(); + } + +void TLayoutTable::BuildSubTables() + { + DestroySubTables(); + + if (iNoSubTables) + return; + + int count = size(); + TLayoutSubTable* subTable = 0; + for (int i=0; iMatchParams(line)) + { + if (subTable->size() > 1) + iSubTables.push_back(subTable); + else + delete subTable; + subTable = new TLayoutSubTable; + } + } + else + { + subTable = new TLayoutSubTable; + } + subTable->iIsMergedIdentical = subTable->iIsMergedIdentical && line.iIsMergedIdentical; + subTable->push_back(i); + } + + if (subTable->size() > 1) + iSubTables.push_back(subTable); + else + delete subTable; + +/* + for (int i=0; ibegin())]; + if (line->MatchParams(*(*this)[i])) + { + TLayoutSubTable& subTab = **it; + subTab.push_back(i); + subTab.iIsMergedIdentical = subTab.iIsMergedIdentical && nextLine.iIsMergedIdentical; + inserted = true; + } + } + + if (!inserted) + { + TLayoutSubTable* subTable = new TLayoutSubTable; + subTable->push_back(i); + subTable->iIsMergedIdentical = nextLine.iIsMergedIdentical; + iSubTables.push_back(subTable); + } + } + + TLayoutSubTables::iterator it = iSubTables.begin(); + while (it != iSubTables.end()) + { + if ((*it)->size() == 1) + it = iSubTables.erase(it); + else + ++it; + } +*/ + } + +void TLayoutTable::DestroySubTables() + { + for (TLayoutSubTables::iterator it = iSubTables.begin(); it != iSubTables.end(); ++it) + delete *it; + iSubTables.clear(); + } + +const string KValueNames[] = { "Font", "C", "l", "r", "B", "W", "J", "t", "r", "b", "H" }; +const set KValueNamesSet(KValueNames, ARRAY_END(KValueNames)); + +bool TLayoutTable::IsValueColumn(string aName) + { + return KValueNamesSet.find(aName) != KValueNamesSet.end(); + } + +const string KNumericNames[] = { "C", "l", "r", "B", "W", "t", "r", "b", "H" }; +const set KNumericNamesSet(KNumericNames, ARRAY_END(KNumericNames)); + +bool TLayoutTable::IsNumericColumn(string aName) + { + return KNumericNamesSet.find(aName) != KNumericNamesSet.end(); + } + +const string KWindowColumnNames[] = {"Item", "C", "l", "t", "r", "b", "W", "H", "Remarks"}; +const string KTextColumnNames[] = {"Font", "C", "l", "r", "B", "W", "J", "Remarks"}; + +void TLayoutTable::SetDefaultColumnNames() + { + iColumnNames.clear(); + if (iType == EWindowTable) + { + iColumnNames.insert(iColumnNames.end(), KWindowColumnNames, ARRAY_END(KWindowColumnNames)); + } + else + { + iColumnNames.insert(iColumnNames.end(), KTextColumnNames, ARRAY_END(KTextColumnNames)); + } + } + +bool TLayoutTable::IsWorthATableIndex() + { + return iSubTables.size() != 0; + } + + +TLayoutTable::TLayoutSubTable::TLayoutSubTable() +: iIsMergedIdentical(true) + { + } + +// +// TLayout +// + +TLayout::TLayout() +: iCanBeMirror(false) + { + } + +TLayout::TLayout(const TLayout& aOther) + { + *this = aOther; + } + +TLayout& TLayout::operator=(const TLayout& aOther) + { + if (this != &aOther) + { + iName = aOther.iName; + iCanBeMirror = aOther.iCanBeMirror; + for (const_iterator it = aOther.begin(); it != aOther.end(); ++it) + push_back(new TLayoutTable(this, **it)); + Compile(); + } + return *this; + } + +TLayout::~TLayout() + { + for (iterator it = begin(); it != end(); ++it) + delete *it; + } + +void TLayout::Merge(TLayout::TMergeMode aMergeMode, TLayout& aLayout) + { + if (iName.empty()) + iName = aLayout.iName; + + for (iterator pNew = aLayout.begin(); pNew != aLayout.end();) + { + iterator pTab; + for (pTab = begin(); pTab != end(); ++pTab) + { + if ((*pTab)->Name() == (*pNew)->Name()) + break; + } + + if (pTab == end()) + { + push_back(*pNew); + (*pNew)->iTables = this; + pNew = aLayout.erase(pNew); + } + else + { + (*pTab)->Merge(aMergeMode, **pNew); + ++pNew; + } + } + + Compile(); + } + +TLayoutLine* TLayout::FindLine(const string& aName) + { + for (iterator it = begin(); it != end(); ++it) + { + TLayoutLine* line = (*it)->FindLine(aName); + if (line) + return line; + } + + return 0; + } + +void TLayout::Compile() + { + iterator pTab; + for (pTab = begin(); pTab != end(); ++pTab) + (*pTab)->Compile(); + + // set uniqueness for lines + multiset names; + for (pTab = begin(); pTab != end(); ++pTab) + { + TLayoutTable& tab = **pTab; + for (TLayoutTable::iterator pLine = tab.begin(); pLine != tab.end(); ++pLine) + names.insert((*pLine)->Name()); + } + + for (pTab = begin(); pTab != end(); ++pTab) + { + TLayoutTable& tab = **pTab; + for (TLayoutTable::iterator pLine = tab.begin(); pLine != tab.end(); ++pLine) + { + TLayoutLine& line = **pLine; + const string& name = line.Name(); + if (name[0] == 'q') + { + line.iIsUnique = false; + } + else + { + line.iIsUnique = (names.count(name) == 1); + } + } + } + + } + + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/LayoutCompilerErr.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/LayoutCompilerErr.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + + +#include "LayoutCompilerErr.h" +#include +#include +#include +using namespace std; + +void NotFoundErr::Show(ostream& stream) const + { + stream << iName << " not found" << endl; + } + +void GeneralErr::Show(ostream& stream) const + { + stream << iMessage << endl; + } + +string StreamLoc(const istream& aStream, const string& msg, int before, int after) + { + string out; + istream stream(aStream.rdbuf()); + int pos = stream.tellg(); +#ifdef __VC32__ + int start = _MAX(0, pos-before); +#else + int start = max(0, pos-before); +#endif + stream.seekg(start); + bool record = (start==0); + for (int i=0; i<(pos-start)+after; i++) + { + char ch = stream.get(); + if (record) + out.append(1,ch); + if (ch == '\n' || ch == '\r') + record = true; + if (start+i == pos) + out.append(msg); + } + return out; + } + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/LayoutConfig.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/LayoutConfig.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,251 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "LayoutConfig.h" +#include "LayoutCompilerErr.h" +#include +#include + +using namespace std; + +const string KBuildConfigFile("\\epoc32\\include\\oem\\bldvariant.hrh"); +const string KLayoutMacroStart("__LAYOUT"); + +typedef LayoutProcessArgsErr LayoutConfigArgsErr; + + +LayoutConfig::Size::Size() +: iWidth(0), iHeight(0) + { + } + +LayoutConfig::Size::TOrientation LayoutConfig::Size::Orientation() const + { + if (iWidth < iHeight) + return EPortrait; + else if (iWidth == iHeight) + return ESquare; + else + return ELandscape; + } + +bool LayoutConfig::Size::operator>(const Size& aRhs) const + { + if (iWidth == aRhs.iWidth) + return iHeight > aRhs.iHeight; + else + return iWidth > aRhs.iWidth; + } + + +int LayoutConfig::Process(const vector& args) + { + if (args.size() < 3) + throw LayoutConfigArgsErr(); + + string mode = CdlTkUtil::ToLower(args[2]); + + auto_ptr config(0); + + if (mode == "wsini") + config = auto_ptr(new WsiniConfig); + else + throw LayoutConfigArgsErr(); + + config->ParseArgs(args); + return config->Process(); + } + +void LayoutConfig::ParseArgs(const vector& args) + { + int argsSize = args.size(); + int nextArg = 3; + while (nextArg < argsSize && args[nextArg][0] == '-') + { + ParseOpt(CdlTkUtil::ToLower(args[nextArg])); + nextArg++; + } + + if (nextArg == argsSize) + throw LayoutConfigArgsErr(); + + iTargetFileName = args[nextArg]; + nextArg++; + + if (nextArg < argsSize) + iBaseFileName = args[nextArg]; + } + +void LayoutConfig::ParseOpt(const std::string& opt) + { + if (opt.size() < 2) + throw LayoutConfigArgsErr(); + + switch (opt[1]) + { + case 't': + if (opt == "-tplatform") + iTarget = EPlatform; + else if (opt == "-tproduct") + iTarget = EProduct; + else + throw LayoutConfigArgsErr(); + break; + case 'l': + if (opt == "-llegacy") + iLegacyMode = ELegacyMode; + else if (opt == "-lnolegacy") + iLegacyMode = ENoLegacyMode; + else + throw LayoutConfigArgsErr(); + break; + default: + throw LayoutConfigArgsErr(); + break; + } + } + +void LayoutConfig::ShowHelp(ostream& stream) + { + stream << "Config [-t] [-l] []" << endl; + stream << " is one of wsini, epocini, aknlayout2" << endl; + stream << " is one of platform, product (default is platform)" << endl; + stream << " is one of legacy, nolegacy (default is legacy)" << endl; + stream << " is the file to be written to" << endl; + stream << " is a file containing the template for the target file" << endl; + } + +LayoutConfig::LayoutConfig() +: iTarget(EPlatform), iLegacyMode(ELegacyMode) + { + LoadAllSizes(); + LoadConfiguredSizes(); + } + +LayoutConfig::~LayoutConfig() + { + } + +const LayoutConfig::Sizes& LayoutConfig::AllSizes() const + { + return iAll; + } + +const LayoutConfig::Sizes& LayoutConfig::ConfiguredSizes() const + { + return iConf; + } + +const LayoutConfig::Sizes& LayoutConfig::SizesForTarget() const + { + if (iTarget == EPlatform) + return iAll; + else + return iConf; + } + +void LayoutConfig::LoadAllSizes() + { + ifstream bldCfg; + OpenBldCfg(bldCfg); + + string line; + while (!bldCfg.eof()) + { + getline(bldCfg, line); + Size s; + if (ParseSize(line, s)) + { + iAll.insert(s); + if (line.find("#define") == 0) + iConf.insert(s); + } + } + } + +void LayoutConfig::LoadConfiguredSizes() + { + // done crudely as part of the LoadAllSizes() function currently + } + +void LayoutConfig::OpenBldCfg(ifstream& aBldCfg) + { + aBldCfg.open(KBuildConfigFile.c_str()); + if (!aBldCfg.is_open()) + throw NotFoundErr(KBuildConfigFile); + } + +bool LayoutConfig::ParseSize(const std::string& aLine, Size& aSize) const + { + int pos = aLine.find(KLayoutMacroStart); + if (pos == string::npos) + return false; + + pos += KLayoutMacroStart.size(); + pos = aLine.find_first_not_of('_', pos); + if (pos == string::npos) + return false; + + aSize.iWidth = CdlTkUtil::ParseInt(aLine.substr(pos)); + + pos = aLine.find('_', pos); + if (pos == string::npos) + return false; + pos = aLine.find_first_not_of('_', pos); + if (pos == string::npos) + return false; + + aSize.iHeight = CdlTkUtil::ParseInt(aLine.substr(pos)); + + return (aSize.iWidth != 0 && aSize.iHeight != 0); + } + +/* +int LayoutConfig::TestLayoutConfig() + { + LayoutConfig l; + + cout << "All:" << endl; + for (Sizes::iterator pAll = l.iAll.begin(); pAll != l.iAll.end(); ++pAll) + { + Size& s = *pAll; + cout << s.iWidth << " x " << s.iHeight << endl; + } + cout << "Conf:" << endl; + for (Sizes::iterator pConf = l.iConf.begin(); pConf != l.iConf.end(); ++pConf) + { + Size& s = *pConf; + cout << s.iWidth << " x " << s.iHeight << endl; + } + return 0; + } +*/ + + +int WsiniConfig::Process() + { + const Sizes& s = SizesForTarget(); +// need a lot more info to make a sensible descision here +// eg what is the prefered size and orientation? How should legacy mode be +// handled, etc. +// also, what should we do with multiple screens????? +// neeeds a lot more thought. + return 0; + } + diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/LayoutPack.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/LayoutPack.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,202 @@ +/* +* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "LayoutPack.h" +#include "ZoomLevelNames.h" +#include "LayoutCompilerErr.h" +#include "CodeGenConsts.h" +#include "AknLayoutConsts.h" + +#include +#include + +using namespace std; +using namespace CdlCompilerToolkit; + +typedef LayoutProcessArgsErr LayoutPackageArgsErr; + +const string KLayoutPackCdlFile = "LayoutPack.cdl"; + +int LayoutPackage::Process(vector& args) + { + if (args.size() < 7) + throw LayoutPackageArgsErr(); + + CZoomLevelNames zoomLevelNames; + zoomLevelNames.ProcessOptions(args); + + string styleName; + string deliveryTypeName; + string priority; + string appUid; + + ProcessOptionalStringArg(args, string("-s"), styleName); + ProcessOptionalStringArg(args, string("-d"), deliveryTypeName); + ProcessOptionalStringArg(args, string("-p"), priority); + ProcessOptionalStringArg(args, string("-a"), appUid); + + string& name = args[2]; + string& w = args[3]; + string& h = args[4]; + string& id = args[5]; + + for(CZoomLevelNames::iterator pZoomName = zoomLevelNames.begin(); pZoomName != zoomLevelNames.end(); ++pZoomName) + Process(name, w, h, id, styleName, deliveryTypeName, priority, appUid, args.begin() + 6, args.end(), pZoomName->second); + + return 0; + } + +void LayoutPackage::ShowHelp(ostream& stream) + { + stream << "LayPkg [-z] [-s] [-d -p [-a]] +" << endl; + stream << " Creates CDL package according to Layout.cdl containing:" << endl; + stream << " The name of the package." << endl; + stream << " The size of screen that it applies to." << endl; + stream << " The layout variant it is used for." << endl; + stream << " The contents of the package." << endl; + stream << " If -z is specified, then instances for zoom factors" << endl; + stream << " (in the form \"n,string\") appearing in the file will be generated, " << endl; + stream << " by replacing the keyword $ZOOM in the package definitions." << endl; + stream << " If -s is specified, then instances for the appropriate" << endl; + stream << " screen style as found in WSINI.INI will be generated." << endl; + stream << " If -d is specified then the delivery type will be appended to" << endl; + stream << " the layout XML directory name." << endl; + stream << " If -p is specified then the pack will be loaded in priority order compared to " << endl; + stream << " instances of the same interface in all other packs, otherwise defaults to zero." << endl; + stream << " If -a is specified then the layout pack will only be loaded for an application" << endl; + stream << " with a matching Secure UID, defaults to zero which means that the pack will be loaded" << endl; + stream << " for any application ." << endl; + } + +void LayoutPackage::Process( + const string& aName, + const string& aWidth, + const string& aHeight, + const string& aId, + const string& aStyleName, + const string& aDeliveryTypeName, + const string& aPriority, + const string& aAppUid, + vector::const_iterator aBegin, + vector::const_iterator aEnd, + const string& aZoomName) + { + CCdlTkCdlFileParser parser(KDirDomainSysHeader+KLayoutPackCdlFile); + auto_ptr iface(parser.LoadAndParse(true)); + CCdlTkPackage pkg(*iface); + pkg.TemplateAllImplementations(); + + string zoomName = CdlTkUtil::Replace("$ZOOM", aZoomName, aName); + string zoomIdName = "EAknUiZoom" + aZoomName; + string styleHash = Hash(aStyleName); + string priority = CdlTkUtil::IntToString(CdlTkUtil::ParseInt(aPriority)); + string appUid = CdlTkUtil::IntToHexString(CdlTkUtil::ParseInt(aAppUid)); + + pkg.SetName(zoomName); + + Implement(pkg, "name", "\"\"", string("\"")+zoomName+"\""); + Implement(pkg, "size", "?width", aWidth); + Implement(pkg, "size", "?height", aHeight); + Implement(pkg, "id", "?value", aId); + Implement(pkg, "zoom", "?value", zoomIdName); + Implement(pkg, "styleHash", "?value", styleHash, string(" // screen style ") + aStyleName); + Implement(pkg, "priority", "?value", priority); + Implement(pkg, "appUid", "?value", appUid); + + cout << zoomName << endl; + + for (; aBegin != aEnd; ++aBegin) + { + const string& arg = *aBegin; + if (arg.size()>=2 && arg.substr(0,2)=="-x") + { + if (++aBegin == aEnd) + throw LayoutPackageArgsErr(); + string dir = *aBegin; + + dir = CdlTkUtil::Replace("\\", "/", dir); + if (*dir.rbegin() != '/') + dir += "/"; + + if (++aBegin == aEnd) + throw LayoutPackageArgsErr(); + const string& dll = *aBegin; + + if (++aBegin == aEnd) + throw LayoutPackageArgsErr(); + const string& inst = *aBegin; + + string zoomContent = CdlTkUtil::Replace("$ZOOM", aZoomName, inst); + pkg.AddExternalContent(zoomContent, dir, dll); + } + else + { + string zoomContent = CdlTkUtil::Replace("$ZOOM", aZoomName, arg); + pkg.AddLocalContent(zoomContent); + cout << zoomContent << endl; + } + } + + CCdlTkWriteInstance writer(pkg); + writer.Process(); + } + +void LayoutPackage::Implement( + CCdlTkPackage& aPkg, + const string& aApi, + const string& aTarget, + const string& aReplace, + const string& aComment) + { + CCdlTkImplementation* impl = aPkg.Impl().Find(aApi); + if (!impl) + throw NotFoundErr(aApi + " in LayoutPack.cdl"); + CdlTkUtil::CReplaceSet implSet; + implSet.Add(aTarget, aReplace); + implSet.Add(" //TODO: Initialise this data.", aComment); + impl->SetDefinition(CdlTkUtil::MultiReplace(implSet, impl->Definition())); + } + +void LayoutPackage::ProcessOptionalStringArg(vector& args, const string& aOption, string& aArg) + { + for (vector::iterator pArg = args.begin(); pArg != args.end(); ++pArg) + { + string& arg = *pArg; + if (arg.size() >= 2 && arg.substr(0,2) == aOption) + { + aArg = arg.substr(2); + args.erase(pArg); + return; + } + } + } + +string LayoutPackage::Hash(const string& aString) + { + int hash = 0; + for (string::const_iterator pChar = aString.begin(); pChar != aString.end(); ++pChar) + { + hash *= KAknLayoutScreenStyleNameHashMult; + hash += *pChar; + } + return CdlTkUtil::IntToHexString(hash); + } diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/LayoutParse.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/LayoutParse.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,300 @@ +/* +* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + + +#include "LayoutParse.h" +#include +#include +#include +#include // !!! for debug output only + +extern string whiteSpace; + +void SkipWhitespace(istream& aIn) + { + char ch; + + while (!aIn.eof()) + { + ch = aIn.get(); + if (whiteSpace.find(ch) == string::npos) + { + aIn.putback(ch); + break; + } + } + } + +void TrimEnd(string& aString) + { + int len = aString.length(); + while (whiteSpace.find(aString[len-1]) != string::npos) + len--; + aString = aString.substr(0, len); + } + +string NextToken(istream& aIn, const string& aTerminate) + { + SkipWhitespace(aIn); + + string ret; + char ch; + + while (!aIn.eof()) + { + ch = aIn.get(); + if (aTerminate.find(ch) != string::npos) + { + if (ret.length()) + aIn.putback(ch); + else + ret += (ch); + break; + } + ret += ch; + } + + TrimEnd(ret); + + return ret; + } + +void FindAndSkip(istream& aIn, const string& aString) + { + string tok = NextToken(aIn, aString); + if (aString.find(tok) == string::npos) + throw LayParseErr(aIn, tok, "not found"); + } + + +TLayParseValues::TLayParseValues(TLayoutLine* aLine, string aName) +: TValues(aLine, aName) + { + } + +void TLayParseValues::Parse(istream& aIn) + { + string tok = NextToken(aIn, ",{}"); + if (tok == "," || tok == "}") + { + aIn.putback(tok[0]); + push_back(""); + } + else if (tok == "{") + { + do { + TLayParseValues v(iLine, iName); + v.Parse(aIn); + insert(end(), v.begin(), v.end()); + tok = NextToken(aIn, ",}"); + } while (tok != "}"); + + tok = NextToken(aIn, ",}["); + if (tok == "[") + { + tok = NextToken(aIn, "]"); + if (tok != "]") + { + iParam = tok; + FindAndSkip(aIn, "]"); + } + } + else if (tok == "," || tok == "}") + { + aIn.putback(tok[0]); + } + else + { + throw LayParseErr(aIn, tok, "expected '[' ',' or '}'"); + } + } + else + { + push_back(tok); + } + } + + +// +// TLayParseLayoutLine +// + +TLayParseLayoutLine::TLayParseLayoutLine(TLayoutTable* aTable, int aId) +: TLayoutLine(aTable, aId) + { + } + +void TLayParseLayoutLine::Parse(istream& aIn) + { + FindAndSkip(aIn, "{"); + + string tok; + + for (vector::iterator pCol = iTable->iColumnNames.begin(); + pCol != iTable->iColumnNames.end(); + ++pCol) + { + TLayParseValues values(this, *pCol); + values.Parse(aIn); + insert(make_pair(*pCol, values)); + tok = NextToken(aIn, ",}"); + } + + if (tok != "}") + throw LayParseErr(aIn, tok, "expected }"); + } + + + +// TLayParseLayoutTable + + +TLayParseLayoutTable::TLayParseLayoutTable(TLayout* aTables) +: TLayoutTable(aTables) + { + } + +void TLayParseLayoutTable::Parse(istream& aIn) + { + string tok = NextToken(aIn, ":{}"); + if (string(":{}").find(tok) != string::npos) + throw LayParseErr(aIn, tok, "expected table name"); + iName = tok; + + tok = NextToken(aIn, ":{"); + if (string(":{").find(tok) == string::npos) + throw LayParseErr(aIn, tok, "expected ':' or '{'"); + + if (tok == ":") + { + iParentName = NextToken(aIn, "{"); + FindAndSkip(aIn, "{"); + } + + tok = NextToken(aIn, "{+"); + if (string("{+").find(tok) == string::npos) + throw LayParseErr(aIn, tok, "expected '+' or '{'"); + else if (tok == "+") + iAppend = true; + else + aIn.putback(tok[0]); + + int id = 0; + do { + TLayParseLayoutLine* line = new TLayParseLayoutLine(this, ++id); + push_back(line); + line->Parse(aIn); + tok = NextToken(aIn, ",}"); + if (string(",}").find(tok) == string::npos) + throw LayParseErr(aIn, tok, "expected ',' or '}'"); + } while (tok != "}"); + } + + + +void TLayParseLayout::Parse(istream& aIn) + { + while (!aIn.eof()) + { + string tok = NextToken(aIn, whiteSpace); + if (tok == "WindowTable" || tok == "TextTable") + { + TLayParseLayoutTable* tab = new TLayParseLayoutTable(this); + push_back(tab); + tab->iType = (tok == "WindowTable" ? TLayoutTable::EWindowTable : TLayoutTable::ETextTable); + tab->SetDefaultColumnNames(); + tab->Parse(aIn); + } + else if (tok.length()==0 && aIn.eof()) + { + // white space at end of file + break; + } + else + { + throw LayParseErr(aIn, tok, "expected a Table"); + } + } + Compile(); + } + +auto_ptr TLayParseLayout::Parse(const string& aLayName) + { + string layName = aLayName; + + auto_ptr layout(new TLayParseLayout); + if (layName.size() >= 2 && layName.substr(0,2) == "-m") + { + layName = layName.substr(2); + layout->iCanBeMirror = true; + } + layout->iName = layName; + + int pos=0; + bool first = true; + while (pos != string::npos) + { + int next = layName.find('+', pos); + string name; + if (next == string::npos) + { + name = layName.substr(pos); + pos = next; + } + else + { + name = layName.substr(pos, next-pos); + pos = layName.find_first_not_of('+', next); + } + + ifstream in(name.c_str()); + if (!in.is_open()) + throw NotFoundErr(name); + cout << "reading layout " << name << endl; + + if (first) + { + layout->Parse(in); + } + else + { + TLayParseLayout nextLay; + nextLay.Parse(in); + layout->Merge(TLayout::KMergeModeUnion, nextLay); + } + + first = false; + in.close(); + } + return layout; + } + + + +LayParseErr::LayParseErr(istream& aIn, const string& aTok, const string& aMsg) +: iLoc(StreamLoc(aIn,"<>", 100, 100)), iTok(aTok), iMsg(aMsg) + { + } + +void LayParseErr::Show(ostream& aOut) const + { + aOut << "ERROR : \"" << iTok << "\" " << iMsg << endl << iLoc << endl; + } + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/LayoutWriter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/LayoutWriter.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,171 @@ +/* +* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +#include "LayoutWriter.h" +#include +#include +#include +#include +using namespace std; + + +TLayoutTableWriter::TLayoutTableWriter(TLayoutTable& aTable) : iTable(aTable) + { + } + +TLayoutTableWriter::~TLayoutTableWriter() + { + } + +void TLayoutTableWriter::Write(ostream& out) + { + if (IsWindowTable()) + { + WriteWindowTable(out); + } + else if (IsTextTable()) + { + WriteTextTable(out); + } + else + { + cout << "Unknown " << "Table " << iTable.Name() << endl; + } + } + +bool TLayoutTableWriter::IsWindowTable() + { + return iTable.iType == TLayoutTable::EWindowTable; + } + + +void TLayoutTableWriter::WriteWindowTable(ostream& out) + { + out << "WindowTable " << iTable.Name(); + if (iTable.iParentName.size()) + out << " : " << iTable.iParentName; + out << endl; + out << "\t{" << endl; + + if (iTable.iAppend) + out << "\t+" << endl; + + for (int i=0; i0) + out << "," << endl; + WriteWindowLine(out, *iTable[i]); + } + + out << endl << "\t}" << endl; + out << endl; + } + +void TLayoutTableWriter::WriteWindowLine(ostream& out, TLayoutLine& line) + { + out << "\t\t{" << line.Name() << ", "; + + for (int i=0; i<7; i++) + { + WriteCell(out, line[KWindowOutputOrder[i]]); + out << ", "; + } + + out << line["Remarks"][0] << "}"; + } + +void TLayoutTableWriter::WriteCell(ostream& out, TValues& values) + { + if (values.size() > 1) + out << "{"; + + for (TValues::iterator pVal = values.begin(); pVal != values.end(); ++pVal) + { + if (pVal != values.begin()) + out << ", "; + out << *pVal; + } + + if (values.size() > 1) + out << "}"; + + if (values.iParam.length()) + out << "[" << values.iParam << "]"; + } + + +bool TLayoutTableWriter::IsTextTable() + { + return iTable.iType == TLayoutTable::ETextTable; + } + +void TLayoutTableWriter::WriteTextTable(ostream& out) + { + out << "TextTable " << iTable.Name(); + if (iTable.iParentName.size()) + out << " : " << iTable.iParentName; + out << endl; + out << "\t{" << endl; + + if (iTable.iAppend) + out << "\t+" << endl; + + for (int i=0; i0) + out << "," << endl; + WriteTextLine(out, *iTable[i]); + } + + out << endl << "\t}" << endl; + out << endl; + } + +void TLayoutTableWriter::WriteTextLine(ostream& out, TLayoutLine& line) + { + out << "\t\t{" << line["Font"][0] << ", "; + + for (int i=0; i<6; i++) + { + WriteCell(out, line[KTextOutputOrder[i]]); + out << ", "; + } + + out << line["Remarks"][0] << "}"; + } + + +TLayoutWriter::TLayoutWriter(TLayout& aLayout, const std::string& aName) +: TLayWriterBase(aLayout, aName) + { + } + +void TLayoutWriter::Write(const std::string&) + { + cout << "writing layout " << iName << endl; + ofstream out(iName.c_str()); + for (TLayout::iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab) + { + TLayoutTableWriter writer(**pTab); + writer.Write(out); + } + out.close(); + } + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/MLAttributes.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/MLAttributes.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,113 @@ +/* +* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "MLAttributes.h" +#include "MLAttributesParse.h" + +#include "LayoutCompilerErr.h" +#include "CodeGenConsts.h" +#include "UsefulDefinitions.h" + +// +// class TMLAttributeSet +// +TMLAttributeSet::TMLAttributeSet() + { + + } + +TMLAttributeSet::TMLAttributeSet(TMLAttributes* aAttributes) + : + iAttributes(aAttributes) + { + + } + +TMLAttributeSet::~TMLAttributeSet() + { + + } + +void TMLAttributeSet::Merge(TMLAttributeSet& aOther) + { + + } + +void TMLAttributeSet::Compile() + { + + } + +// +// class TMLAttributes +// + +TMLAttributes::TMLAttributes() + { + + } + +TMLAttributes::~TMLAttributes() + { + for(iterator pComponent = begin(); pComponent != end(); ++pComponent) + { + TMLAttributeSetComponent& component = pComponent->second; + for(TMLAttributeSetComponent::iterator pAttributeSet = component.begin(); pAttributeSet != component.end(); ++pAttributeSet) + { + TMLAttributeSet* nextSet = pAttributeSet->second; + delete nextSet; + } + } + } + +void TMLAttributes::Merge(TMLAttributes& aOther) + { + for(iterator pOtherComponent = aOther.begin(); pOtherComponent != aOther.end(); ++pOtherComponent) + { + int compId = pOtherComponent->first; + TMLAttributeSetComponent& otherComponent = pOtherComponent->second; + TMLAttributeSetComponent& thisComponent = (*this)[compId]; + for(TMLAttributeSetComponent::iterator pOtherAttributeSet = otherComponent.begin(); pOtherAttributeSet != otherComponent.end(); ++pOtherAttributeSet) + { + string name = pOtherAttributeSet->first; + TMLAttributeSet* otherSet = pOtherAttributeSet->second; + TMLAttributeSetComponent::iterator foundThisSet = thisComponent.find(name); + if(foundThisSet == thisComponent.end() && otherSet) + { + TMLAttributeSet* otherSetCopy = new TMLAttributeSet(*otherSet); + thisComponent.insert(make_pair(name, otherSetCopy)); + } + } + } + for(TMLAttributeNames::iterator nextOtherName = aOther.iNames.begin(); nextOtherName != aOther.iNames.end(); ++nextOtherName) + { + // we want the superset of all the names, + // it doesn't matter if there are names that correspond to attributes that don't actually exist + // as it won't take up much memory and we won't look for them + int& nextThisNameValue = iNames[nextOtherName->first]; + nextThisNameValue = nextOtherName->second; + } + } + +void TMLAttributes::Compile() + { + + } + + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/MLAttributesParse.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/MLAttributesParse.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,257 @@ +/* +* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning(disable: 4786 4250 4503 4541) + + +#include "MLAttributesParse.h" +#include "MLCompDataParse.h" // for converting zoom strings + +#include // for logical font ids + +#include +#include +#include +#include // !!! for debug output only + +extern string whiteSpace; + + +// const data +// + +const string KAttributesParseRoot = "LayoutAttributes"; +const string KAttributesParseRootAttributeCreatedOn = "createdOn"; + +const string KAttributesParseNodeAttributeSet = "attributeset"; +const string KAttributesParseNodeAttributeSetAttributeId = "compId"; +const string KAttributesParseNodeAttributeSetAttributeName = "name"; + +const string KAttributesParseNodeAttribute = "attribute"; +const string KAttributesParseNodeAttributeAttributeId = "id"; +const string KAttributesParseNodeAttributeAttributeName = "name"; + +const string KAttributesParseNodeCalc = "calc"; +const string KAttributesParseNodeCalcAttributeValue = "value"; +const string KAttributesParseNodeCalcAttributeZoom = "zoom"; + + +// +// class TMLAttributeSetParse +// +TMLAttributeSetParse::TMLAttributeSetParse(TMLAttributes* aAttributes) + : + TMLAttributeSet(aAttributes), + iSaxZoomLevels(0) + { + + } + +MSaxLayoutAttributesHandler* TMLAttributeSetParse::HandleSax(const std::string& aElement, const TAttribs& aAttribs) + { + // + if (aElement == KAttributesParseNodeAttributeSet) + { + iCompId = CdlTkUtil::ParseInt(aAttribs.getValue(KAttributesParseNodeAttributeSetAttributeId)); + iName = aAttribs.getValue(KAttributesParseNodeAttributeSetAttributeName); + } + else if(aElement == KAttributesParseNodeAttribute) + { + HandleSaxAttribute(aAttribs); + } + else if(aElement == KAttributesParseNodeCalc) + { + HandleSaxCalc(aAttribs); + } + return this; + } + +void TMLAttributeSetParse::HandleSaxEnd(const std::string& aElement) + { + if (aElement == KAttributesParseNodeAttribute) + { + insert(make_pair(iId, *iSaxZoomLevels)); + delete iSaxZoomLevels; + iSaxZoomLevels = 0; + } + } + +void TMLAttributeSetParse::HandleSaxAttribute(const TAttribs& aAttribs) + { + delete iSaxZoomLevels; + iSaxZoomLevels = 0; + iSaxZoomLevels = new TMLAttributeZoomLevels; + + // + iId = CdlTkUtil::ParseInt(aAttribs.getValue(KAttributesParseNodeAttributeAttributeId)); + string attributeName = CdlTkUtil::ToCpp(aAttribs.getValue(KAttributesParseNodeAttributeAttributeName)); + iAttributes->iNames.insert(make_pair(attributeName, iId)); + } + +void TMLAttributeSetParse::HandleSaxCalc(const TAttribs& aAttribs) + { + // + // + // + // + // + + string zoomStr = aAttribs.getValue(KAttributesParseNodeCalcAttributeZoom); + int zoom = TMLCompDataParseValues::ConvertZoomStr(zoomStr); + if(zoom != EAknUiZoomAutomatic) + { + string& calc = (*iSaxZoomLevels)[zoom]; + calc = aAttribs.getValue(KAttributesParseNodeCalcAttributeValue); + } + } + +int TMLAttributeSetParse::CompId() const + { + return iCompId; + } + +string TMLAttributeSetParse::Name() const + { + return iName; + } + + +// +// class TMLAttributesParse +// +auto_ptr TMLAttributesParse::Parse(const string& aLayName) + { + auto_ptr layout(new TMLAttributesParse); + int pos=0; + string layName = aLayName; + + if (layName.size() >= 2 && layName.substr(0,2) == "-m") + { + layName = layName.substr(2); + layout->iCanBeMirror = true; + } + layout->iName = layName; + + // SAX parsing method + cout << "reading MLAttributes(SAX) " << layName << endl; + TLayoutAttributesSaxParser saxParser(layout.get()); + saxParser.Parse(layName); + + return layout; + } + +TMLAttributesParse::TMLAttributesParse() + : + iSaxAttributeSet(0) + { + + } + +MSaxLayoutAttributesHandler* TMLAttributesParse::HandleSax(const std::string& aElement, const TAttribs& aAttribs) + { + if (aElement == KAttributesParseRoot) + { + // + iTimestamp = aAttribs.getValue(KAttributesParseRootAttributeCreatedOn); + return this; + } + else if (aElement == KAttributesParseNodeAttributeSet) + { + delete iSaxAttributeSet; + iSaxAttributeSet = 0; + iSaxAttributeSet = new TMLAttributeSetParse(this); + iSaxAttributeSet->HandleSax(aElement, aAttribs); + return iSaxAttributeSet; + } + else + return this; + } + +void TMLAttributesParse::HandleSaxEnd(const std::string& aElement) + { + if (aElement == KAttributesParseNodeAttributeSet) + { + TMLAttributeSetComponent& component = (*this)[iSaxAttributeSet->CompId()]; + component.insert(make_pair(iSaxAttributeSet->Name(), iSaxAttributeSet)); + iSaxAttributeSet = 0; + } + } + + +// +// TLayoutAttributesSaxParser +// + +TLayoutAttributesSaxParser::TLayoutAttributesSaxParser(MSaxLayoutAttributesHandler* aHandler) + { + iStack.push(aHandler); + } + +void TLayoutAttributesSaxParser::Parse(const std::string& aFileName) + { + SAX::basic_InputSource is(aFileName); + SAX::XMLReader parser; + parser.setContentHandler(*this); + parser.setErrorHandler(*this); + parser.parse(is); + } + +void TLayoutAttributesSaxParser::startElement(const std::string& /*namespaceURI*/, const std::string& localName, + const std::string& /*qName*/, const SAX::basic_Attributes& atts) + { + MSaxLayoutAttributesHandler* handler = iStack.top(); + if (!handler) + throw GeneralErr("SAX: No element handler"); + MSaxLayoutAttributesHandler* next = handler->HandleSax(localName, atts); + iStack.push(next); + } + +void TLayoutAttributesSaxParser::endElement(const std::string& /*namespaceURI*/, const std::string& localName, + const std::string& /*qName*/) + { + iStack.pop(); + MSaxLayoutAttributesHandler* handler = iStack.top(); + if (handler) + handler->HandleSaxEnd(localName); + } + + +void TLayoutAttributesSaxParser::warning(const TException& aException) + { + cerr << aException.what(); + } + +void TLayoutAttributesSaxParser::error(const TException& aException) + { + cerr << aException.what(); + } + +void TLayoutAttributesSaxParser::fatalError(const TException& aException) + { + cerr << aException.what(); + } + + + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/MLCompCdl2InstO.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/MLCompCdl2InstO.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,2016 @@ +/* +* Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +// disable "decorated name length exceeded, name was truncated" warning +#pragma warning (disable:4503) + +#include "MLCompDataParse.h" +#include "MLCompCdl2InstO.h" +#include "ZoomLevelNames.h" +#include "LayoutCompilerErr.h" +#include "LayoutParse.h" +#include "CppWriter.h" +#include "MLCompData2Cdl.h" +#include "LayCdl2InstO.h" // for common classes +#include "MLAttributesParse.h" +#include "MLAttributes.h" +#include "CodeGenConsts.h" +#include "UsefulDefinitions.h" + +#include + +#include +#include +#include +#include // accumulate + +using namespace std; +using namespace CdlCompilerToolkit; + +// +// defines +// + +#define AKNLAYOUT_DEFINE_BYTECODE(name,byte) const char name = char(byte); +#include "AknLayoutByteCodes.h" + +typedef LayoutProcessArgsErr MLCompDataCdlInstanceOptArgsErr; + + +// +// constants +// + +const string KDefinitionNotDefined("Layout not defined, this API must not be called for this instance"); +const string KDefinitionNotSet("Layout definition not found"); +extern string KMultiLine; +const string KSpace = " "; +const string KComma = ","; +const string KTheWordBlank("blank"); +const string KParentRelativeMarker("Pp"); +const string KCellNameJustification("J"); +const string KCompDataFileNameSuffix("compData"); +const string KAttributesFileNameSuffix("attributes"); + +// this is the addressable area for each instance, as the lookup table is 16bit +const int KAddressableBytecodedData = 0xFFFF; + +/** +* SCompDataImplFunc +* This class represents a layout data decompression function local to a layout instance. +* These functions will call the corresponding DLL wide function for decompression. +*/ +struct SCompDataImplFunc + { + enum TFuncType + { + EWindowLine, + ETextLine, + ETableLimits, + EWindowTable, + ETextTable, + ELineParamLimits, + ETableParamLimits, + EGenericComponentType, + EGenericParamLimits, + EGenericWindowComponent, + EGenericTextComponent + }; + TFuncType iType; + CCdlTkApiParams iParams; + string iDefn; + string iPtrRef; + + SCompDataImplFunc(TFuncType aType, string aDefn, string aPtrRef, CCdlTkApiParams& aParams) + : + iType(aType), + iDefn(aDefn), + iPtrRef(aPtrRef), + iParams(aParams) + { + + } + + SCompDataImplFunc(TFuncType aType, string aDefn, string aPtrRef) + : + iType(aType), + iDefn(aDefn), + iPtrRef(aPtrRef) + { + + } + + bool IsSimilar(TFuncType aType, CCdlTkApiParams& aParams) + { + if(iType != aType) + return false; + int size = iParams.size(); + if(size != aParams.size()) + return false; + for(int ii = 0; ii < size; ii++) + { + CCdlTkApiParam& thisParam = iParams[ii]; + CCdlTkApiParam& otherParam = aParams[ii]; + if(thisParam.Name() != otherParam.Name()) + return false; + if(thisParam.Type() != otherParam.Type()) + return false; + // don't compare the default value, as we're not interested in that for the implementation. + } + return true; + } + }; + + +/** +* CAllCompDataFuncs +* This represents a collection of all the SCompDataImplFunc objects that a layout instance may need +*/ +class CAllCompDataFuncs : public vector + { +public: + CAllCompDataFuncs(); + +private: + void AddFunc(SCompDataImplFunc::TFuncType aType, CCdlTkApiParams& aParams, const string& aReturn, const string& aFuncName, bool aAppendAbbreviation); + void AddParamsToFunc(CCdlTkApiParams& aParams, string& aDefn, string& aBody); + void AddParamToFunc(string aFiller, string aParamName, string& aDefn, string& aBody); + }; + + + +/** +* gTheFuncs +* This is a collection of all SCompDataImplFunc objects that a layout instance needs, initialised +* so that there are up to four integer parameters per API type. +*/ +CAllCompDataFuncs gTheFuncs; + +// +// CAllCompDataFuncs +// + +CAllCompDataFuncs::CAllCompDataFuncs() + { + // need to generate all combinations of parameters + vector paramNames; + paramNames.push_back(KParamOptionIndex); + paramNames.push_back(KParamColIndex); + paramNames.push_back(KParamRowIndex); + + // all cominations of option, row, and column are possible, in any order + typedef vector Seq; + Seq pattern; + set< Seq > subPatterns; + + // for each of the available positions, there could be any available value, or it could be empty + const int numPlaces = paramNames.size(); + for(int jj = 0; jj < numPlaces; jj++) + pattern.push_back(jj); + + // for each permutation, copy all the possible positions + // into a separate set, which hence will be filled with the unique permutations + do + { + int numMasks = (1 << numPlaces); // eg for 3 places there are 8 masks + for(int mask = 0; mask < numMasks; mask++) + { + Seq subPattern; + int bit = 0; + // count down the bits + for(int bitCount = mask; bitCount != 0; bitCount >>= 1) + { + if(mask & (1 << bit)) + subPattern.push_back(pattern[bit]); + bit++; + } + subPatterns.insert(subPattern); + } + } + while(next_permutation(pattern.begin(), pattern.end())); + + for(set< Seq >::iterator pPattern = subPatterns.begin(); pPattern != subPatterns.end(); ++pPattern) + { + CCdlTkApiParams params; + for(Seq::iterator pParam = pPattern->begin(); pParam != pPattern->end(); ++pParam) + { + int& param = (*pParam); + string name = paramNames[param]; + params.push_back(CCdlTkApiParam(KTypeInt, name)); + } + AddFunc(SCompDataImplFunc::EWindowLine, params, KTypeWindowComponentLayout, KFuncWindowLine, true); + AddFunc(SCompDataImplFunc::ETextLine, params, KTypeTextComponentLayout, KFuncTextLine, true); + + params.insert(params.begin(), CCdlTkApiParam(KTypeInt, KParamLineIndex)); + AddFunc(SCompDataImplFunc::EWindowTable, params, KTypeWindowComponentLayout, KFuncWindowTable, true); + AddFunc(SCompDataImplFunc::ETextTable, params, KTypeTextComponentLayout, KFuncTextTable, true); + } + + for(int ii = 0; ii < 2; ii++) + { + CCdlTkApiParams params; + if(ii) + { + params.push_back(CCdlTkApiParam(KTypeInt, KParamOptionIndex)); + } + AddFunc(SCompDataImplFunc::ELineParamLimits, params, KTypeLayoutScalableParameterLimits, KFuncParamLimits, true); + params.insert(params.begin(), CCdlTkApiParam(KTypeInt, KParamLineIndex)); + AddFunc(SCompDataImplFunc::ETableParamLimits, params, KTypeLayoutScalableParameterLimits, KFuncParamLimitsTable, true); + } + + SCompDataImplFunc limits( + SCompDataImplFunc::ETableLimits, + KTypeLayoutScalableTableLimits + " Limits() { return AknLayoutScalableDecode::TableLimits(KDataLookup); }", + "&Limits"); + push_back(limits); + + // finally, the generic APIs + CCdlTkApiParams params; + params.push_back(CCdlTkApiParam(KTypeInt, KParamComponentId)); + AddFunc(SCompDataImplFunc::EGenericComponentType, params, KTypeLayoutScalableComponentType, KFuncGetComponentTypeById, false); + + // param limits needs the variety index + params.push_back(CCdlTkApiParam(KTypeInt, KParamOptionIndex)); + AddFunc(SCompDataImplFunc::EGenericParamLimits, params, KTypeLayoutScalableParameterLimits, KFuncGetParamLimitsById, false); + + // and getting the component by id requires all the params + params.push_back(CCdlTkApiParam(KTypeInt, KParamColIndex)); + params.push_back(CCdlTkApiParam(KTypeInt, KParamRowIndex)); + AddFunc(SCompDataImplFunc::EGenericWindowComponent, params, KTypeWindowComponentLayout, KFuncGetWindowComponentById, false); + AddFunc(SCompDataImplFunc::EGenericTextComponent, params, KTypeTextComponentLayout, KFuncGetTextComponentById, false); + } + +void CAllCompDataFuncs::AddFunc(SCompDataImplFunc::TFuncType aType, CCdlTkApiParams& aParams, const string& aReturn, const string& aFuncName, bool aAppendAbbreviation) + { + // create a function of this form: + //TAknWindowComponentLayout WindowTable$NUM$PARENT($PARAMS_TYPES_AND_NAMES) + // { + // return AknLayoutScalableDecode::WindowLine$NUM$PARENT(&KImplData, $PARAM_NAMES); + // } + string funcName = aFuncName; + if(aAppendAbbreviation) + for(CCdlTkApiParams::iterator pParam = aParams.begin(); pParam != aParams.end(); ++pParam) + funcName += pParam->Name().substr(1, 1); // append the first character after the "a" + + string defn = aReturn + " " + funcName + "("; + string body = string(") { return AknLayoutScalableDecode::") + funcName + "(&KImplData"; + AddParamsToFunc(aParams, defn, body); + defn += body + "); }"; + + string ptrRef = string("&") + funcName; + + SCompDataImplFunc func(aType, defn, ptrRef, aParams); + push_back(func); + } + +void CAllCompDataFuncs::AddParamsToFunc(CCdlTkApiParams& aParams, string& aDefn, string& aBody) + { + string filler = ""; + for(CCdlTkApiParams::iterator pParam = aParams.begin(); pParam != aParams.end(); ++pParam) + { + AddParamToFunc(filler, pParam->Name(), aDefn, aBody); + filler = KComma + KSpace; + } + } + +void CAllCompDataFuncs::AddParamToFunc(string aFiller, string aParamName, string& aDefn, string& aBody) + { + aDefn += aFiller + string(KTypeInt) + KSpace + aParamName; + aBody += KComma + KSpace + aParamName; + } + + +// +// CMLCompDataInstOptImpl +// + +class CMLCompDataInstOptImpl + { +public: + CMLCompDataInstOptImpl(CCdlTkImplementation* aImpl); + virtual ~CMLCompDataInstOptImpl(); +public: + CCdlTkImplementation* iImpl; + int iByteCodeIndex; + string iComment; + string iName; + vector iBytes; + bool iIsRedirectedToExactCopy; + }; + +CMLCompDataInstOptImpl::CMLCompDataInstOptImpl(CCdlTkImplementation* aImpl) + : + iImpl(aImpl), + iIsRedirectedToExactCopy(false) + { + } + +CMLCompDataInstOptImpl::~CMLCompDataInstOptImpl() + { + } + +// +// CMLCompDataLineInstOptImpl +// + +class CMLCompDataLineInstOptImpl : public CMLCompDataInstOptImpl + { +public: + CMLCompDataLineInstOptImpl(TMLCompDataLine* aLine, CCdlTkImplementation* aImpl); + virtual ~CMLCompDataLineInstOptImpl(); +public: + TMLCompDataLine* iLine; + }; + +CMLCompDataLineInstOptImpl::CMLCompDataLineInstOptImpl(TMLCompDataLine* aLine, CCdlTkImplementation* aImpl) + : + CMLCompDataInstOptImpl(aImpl), + iLine(aLine) + { + } + +CMLCompDataLineInstOptImpl::~CMLCompDataLineInstOptImpl() + { + } + + +// +// CMLCompDataSubTableInstOptImpl +// + +class CMLCompDataSubTableInstOptImpl : public CMLCompDataInstOptImpl + { +public: + CMLCompDataSubTableInstOptImpl( + TMLCompDataTable* aTable, + TMLCompDataTable::TMLCompDataSubTable* aSubTable, + CCdlTkImplementation* aImpl); + virtual ~CMLCompDataSubTableInstOptImpl(); +public: + TMLCompDataTable* iTable; + TMLCompDataTable::TMLCompDataSubTable* iSubTable; + }; + +CMLCompDataSubTableInstOptImpl::CMLCompDataSubTableInstOptImpl( + TMLCompDataTable* aTable, + TMLCompDataTable::TMLCompDataSubTable* aSubTable, + CCdlTkImplementation* aImpl) + : + iTable(aTable), + CMLCompDataInstOptImpl(aImpl), + iSubTable(aSubTable) + { + } + +CMLCompDataSubTableInstOptImpl::~CMLCompDataSubTableInstOptImpl() + { + } + + +// +// CMLCompDataInstOpt +// + +class CMLCompDataInstOpt + { +public: + CMLCompDataInstOpt(MLCompDataCdlInstanceOpt& aInstances, TMLCompData* aLayout, const string& aInstName, const string& aZoomName, int aZoomLevel, bool aAllParams, bool aNonCompleteInstance); + ~CMLCompDataInstOpt(); + + void Process(const string& aFirstInstanceName); + void WriteInstance(); + + CCdlTkInstance& Inst() const { return *iInstance; } + string Name() const { return iName; } + string ZoomName() const { return iZoomName; } + +private: + typedef vector ParamLimitVarieties; + typedef vector ParamLimits; + typedef map IndexMap; + +private: + void ProcessLines(TMLCompDataTable& aTable); + void ProcessTables(TMLCompDataTable& aTable); + void ProcessLine(TMLCompDataLine& aLine); + void ProcessLineApi(TMLCompDataLine& aLine, CCdlTkImplementation& aImpl); + void UpdateBaseOffset(); + void UpdateLine(CMLCompDataInstOptImpl& aImpl, int& aByteCodeSizeDelta); + void UpdateLineImpls(); + void UpdateLineImplDefn(CMLCompDataInstOptImpl& aImpl); + void UpdateTableInstance(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSub, CMLCompDataInstOptImpl* aImpl); + + void SetNewLineData(CMLCompDataLineInstOptImpl& aImpl); + void SetNewLineParamData(CMLCompDataLineInstOptImpl& aImpl, IndexMap& aIndexMap, int aTotalMax, int aNumVarieties); + void OptimizeNewLineData(CMLCompDataLineInstOptImpl& aImpl, IndexMap& aIndexMap, vector& aTempBytes, const vector& aOutputOrder, bool aMirrored, int aTotalMax, int aNumVarieties); + void OptimizeNewLineCellData(IndexMap& aIndexMap, vector& aTempBytes, TMLCompDataValues& aValues, unsigned int& aNextCell, int aTotalParams, int aNumVarieties, ParamLimitVarieties& aParamLimitVarieties, string cellName, bool aMirrorJustification); + void EncodeNewLineCellData(IndexMap& aIndexMap, vector& aTempBytes, vector& aValuesToEncode, unsigned int& aNextCell, int aTotalMax, bool aOptimizeVarieties, bool aOptimizeCalcs); + + bool HasApi(const string& aName); + CCdlTkImplementation& FindImp(const string& aName); + CMLCompDataInstOptImpl* FindSimilarImpl(const CMLCompDataInstOptImpls& aImpls, const CCdlTkImplementation& aImpl); + string DefinitionString(int aByteCodeIndex, const string& aApiName); + bool CheckByteCodeIndexInRange(int aByteCodeIndex); + + void SetGenericFunc(CMLCompDataInstOptImpl& aImpl, SCompDataImplFunc::TFuncType aType); + void SetLineFunc(CMLCompDataLineInstOptImpl& aImpl); + void SetSubTableFunc(CMLCompDataSubTableInstOptImpl& aImpl); + void SetParamLimits(CMLCompDataLineInstOptImpl& aImpl); + + void ValidateRequiredParams(string aApiName, CCdlTkApiParams& aParams, bool aOption, bool aColumn, bool aRow); + void CountApiParams(CCdlTkImplementation& aApi, int& aParams); + SCompDataImplFunc& AddImplFunc(SCompDataImplFunc::TFuncType aType); + SCompDataImplFunc& AddImplFunc(SCompDataImplFunc::TFuncType aType, CCdlTkApiParams& aParams); + + void SetGenericAPI(SCompDataImplFunc::TFuncType aType, const string& aName); + void SetExtraCpp(const string& aFirstInstanceName); + void OutputStats(); + + void AddTableToInstance(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSub, int aTableNum); + void UpdateTables(TMLCompDataTable& aTable); + void AddTableParamLimitsImpl(const string& aApiName, int aByteCodeIndex, SCompDataImplFunc::TFuncType aType, bool aNeedsOptions); + void UpdateTableParamLimitsImpl(const string& aApiName, int aByteCodeIndex); + void AddTableLimitsImpl(const string& aApiName, TMLCompDataTable::TMLCompDataSubTable& aSubTable); + void AddTableLimitsImplDefn(TMLCompDataTable::TMLCompDataSubTable& aSubTable, CCdlTkImplementation& aImpl); + void AddTableImpl(const string& aApiName, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSub); + void AddParamLimits(TMLCompDataLine& aLine, bool aNeedsOptions); + void UpdateParamLimits(const string& apiName); + void SetDummyTableData(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, CMLCompDataInstOptImpl& aImpl); + void UpdateTableData(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, CMLCompDataInstOptImpl& aImpl); + void EncodeValue(vector& aBytes, string aValue); + void EncodeValue(vector& aBytes, int aValue); + void EncodeParentRelativeValue(vector& aBytes, int aValue); + void MirrorParamName(string& aParamName); + +private: + MLCompDataCdlInstanceOpt& iInstances; + TMLCompData* iLayout; + string iName; + string iZoomName; + CCdlTkInterface& iInterface; + CCdlTkInstance* iInstance; // not owned + CMLCompDataInstOptImpls iImpls; + CMLCompDataInstOptImpls iTableImpls; + typedef vector CImplFuncs; + CImplFuncs iFuncs; + int iZoomLevel; + bool iAllParams; + int iBaseOffset; // offset from the start of the main data table to the start of this instance's data + }; + +CMLCompDataInstOpt::CMLCompDataInstOpt(MLCompDataCdlInstanceOpt& aInstances, TMLCompData* aLayout, const string& aInstName, const string& aZoomName, int aZoomLevel, bool aAllParams, bool aNonCompleteInstance) + : + iInstances(aInstances), + iLayout(aLayout), + iName(aInstName), + iZoomName(aZoomName), + iZoomLevel(aZoomLevel), + iInterface(iInstances.Interface()), + iAllParams(aAllParams), + iBaseOffset(0) + { + string zoomInstName = aInstName; + if(aZoomName.length() > 0) + zoomInstName += "_" + aZoomName; + + iInstance = new CCdlTkInstance(iInterface); + iInstance->SetName(zoomInstName); + + CCdlTkImplementations& impl = iInstance->Impl(); + for (CCdlTkImplementations::iterator pImpl = impl.begin(); pImpl != impl.end(); ++pImpl) + { + const CCdlTkInterface& iface = (*pImpl)->Instance().Interface(); + const CCdlTkApi& api = (*pImpl)->Api(); + if(aLayout->iIsBaseInstance) + { + // for a base instance, need to set a default implementation + // even for missing data + (*pImpl)->SetDefinition(CdlTkUtil::ShortToHexString(0) + ",\t// " + KDefinitionNotDefined); + + // preliminary implementation of "blank" implementation. cdl engine searches to ensure that + // all implementations are not NULL. So this will satisfy that test. However, if any of the + // methods are called, there will be an access violation, which will cause a panic + // this will be a successful guide to implementers not to call the API when the wrong layout + // pack is installed. + string definition = "(" + iface.NamespaceName() + "::" + api.PointerType() + ")((void*)4), // LAYOUT NOT DEFINED FOR THIS INSTANCE"; + (*pImpl)->SetPointerReference(definition); + } + else if(aNonCompleteInstance) + { + // for a base instance, need to set a default implementation + // even for missing data + (*pImpl)->SetDefinition(CdlTkUtil::ShortToHexString(0) + ",\t// " + KDefinitionNotDefined); + + // but we need the pointer to be null so that CdlEngine falls through the layer below + string definition = "0, // " + iface.NamespaceName() + "::" + api.PointerType(); + (*pImpl)->SetPointerReference(definition); + } + else + { + // Initially set definition that will not compile in the resulting code. + // This will alert the programmer to missing layout data. + (*pImpl)->SetDefinition(KDefinitionNotSet); + } + } + } + +CMLCompDataInstOpt::~CMLCompDataInstOpt() + { + delete iInstance; + for (CMLCompDataInstOptImpls::iterator pImpl = iImpls.begin(); pImpl != iImpls.end(); ++pImpl) + delete *pImpl; + for (pImpl = iTableImpls.begin(); pImpl != iTableImpls.end(); ++pImpl) + delete *pImpl; + } + +void CMLCompDataInstOpt::Process(const string& aFirstInstName) + { + iLayout->Compile(); + + for (TMLCompData::iterator pTab = iLayout->begin(); pTab != iLayout->end(); ++pTab) + { + ProcessLines(**pTab); + } + + for (pTab = iLayout->begin(); pTab != iLayout->end(); ++pTab) + { + ProcessTables(**pTab); + } + + // update the base offset to include all the data added, including reserving space for the tables + UpdateBaseOffset(); + + // with the correct base offset, the definitions can be updated + UpdateLineImpls(); + + for (pTab = iLayout->begin(); pTab != iLayout->end(); ++pTab) + { + // now that the rest of the data is stable, we can add the tables at the end + UpdateTables(**pTab); + } + + SetGenericAPI(SCompDataImplFunc::EGenericComponentType, KFuncGetComponentTypeById); + SetGenericAPI(SCompDataImplFunc::EGenericParamLimits, KFuncGetParamLimitsById); + SetGenericAPI(SCompDataImplFunc::EGenericWindowComponent, KFuncGetWindowComponentById); + SetGenericAPI(SCompDataImplFunc::EGenericTextComponent, KFuncGetTextComponentById); + + SetExtraCpp(aFirstInstName); + OutputStats(); + } + +void CMLCompDataInstOpt::WriteInstance() + { + CCdlTkWriteInstance writer(*iInstance); + writer.Process(); + } + +void CMLCompDataInstOpt::ProcessLines(TMLCompDataTable& aTable) + { + for (TMLCompDataTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) + { + ProcessLine(**pLine); + } + } + +void CMLCompDataInstOpt::ProcessTables(TMLCompDataTable& aTable) + { + int line = 0; + for (TMLCompDataTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) + { + for (TMLCompDataTable::TMLCompDataSubTables::const_iterator pSub = aTable.iSubTables.begin(); pSub != aTable.iSubTables.end(); ++pSub) + { + TMLCompDataTable::TMLCompDataSubTable& sub = **pSub; + int last = *(sub.rbegin()); + if(line == last) + AddTableToInstance(aTable, sub, 0); + } + line++; + } + } + +void CMLCompDataInstOpt::ProcessLine(TMLCompDataLine& aLine) + { + string apiName = MLCompDataToCdl::LineApiName(aLine); + if (!HasApi(apiName)) + return; + + ProcessLineApi(aLine, FindImp(apiName)); + } + +void CMLCompDataInstOpt::ProcessLineApi(TMLCompDataLine& aLine, CCdlTkImplementation& aImpl) + { + string lineName = MLCompDataToCdl::LineApiName(aLine); + + CMLCompDataLineInstOptImpl* newImpl = new CMLCompDataLineInstOptImpl(&aLine, &aImpl); + iImpls.push_back(newImpl); + + // always set the new line data + SetNewLineData(*newImpl); + + // if we can find the new line data in the aggregated data, point to that instead + int foundIndex = iInstances.FindSimilarBytes(newImpl, iBaseOffset); + if(foundIndex >= 0) + { + newImpl->iByteCodeIndex = foundIndex; + newImpl->iIsRedirectedToExactCopy = true; + } + else + { + iInstances.AddImpl(newImpl); + } + + SetLineFunc(*newImpl); + + // only add parameter limits if the line is not simple + // and we must add the param limits after the actual impl, so that we can find it! + bool needsParamLimits = aLine.NeedsOptions() || aLine.NeedsCols() || aLine.NeedsRows(); + if(needsParamLimits) + { + AddParamLimits(aLine, aLine.NeedsOptions()); + } + } + +void CMLCompDataInstOpt::UpdateBaseOffset() + { + // have to account for this instance's tables + int tablesSize(0); + for(CMLCompDataInstOptImpls::iterator pTableImpl = iTableImpls.begin(); pTableImpl != iTableImpls.end(); ++pTableImpl) + { + CMLCompDataInstOptImpl* impl = *pTableImpl; + tablesSize += impl->iBytes.size(); + } + + int origByteStreamSize = iInstances.ByteStreamSize() + tablesSize; + + // repeat until base offset stabilizes + iBaseOffset = max(0, origByteStreamSize - KAddressableBytecodedData); + int newBaseOffset = iBaseOffset; + int byteCodeSizeDelta(0); + do + { + iBaseOffset = newBaseOffset; + for(CMLCompDataInstOptImpls::iterator pImpl = iImpls.begin(); pImpl != iImpls.end(); ++pImpl) + UpdateLine(**pImpl, byteCodeSizeDelta); + newBaseOffset = max(0, origByteStreamSize + byteCodeSizeDelta - KAddressableBytecodedData); + } + while(iBaseOffset != newBaseOffset); + } + +void CMLCompDataInstOpt::UpdateLine(CMLCompDataInstOptImpl& aImpl, int& aByteCodeSizeDelta) + { + if(aImpl.iIsRedirectedToExactCopy && aImpl.iByteCodeIndex < iBaseOffset) + { + // when we encoded the impls, we found a match in an area which now + // turns out to be before the base offset (i.e. outside the addressable range). + + // first of all check in case we've already made another copy close by + int foundIndex = iInstances.FindSimilarBytes(&aImpl, iBaseOffset); + if(foundIndex >= 0) + { + aImpl.iByteCodeIndex = foundIndex; + } + else + { + // add its bytecodes to the end + aImpl.iIsRedirectedToExactCopy = false; + iInstances.AddImpl(&aImpl); + aByteCodeSizeDelta += aImpl.iBytes.size(); + } + } + } + + +void CMLCompDataInstOpt::UpdateLineImpls() + { + for(CMLCompDataInstOptImpls::iterator pImpl = iImpls.begin(); pImpl != iImpls.end(); ++pImpl) + UpdateLineImplDefn(**pImpl); + } + +void CMLCompDataInstOpt::UpdateLineImplDefn(CMLCompDataInstOptImpl& aImpl) + { + if(!CheckByteCodeIndexInRange(aImpl.iByteCodeIndex)) + throw GeneralErr(aImpl.iName + " in interface " + iInterface.FileName()); + // the base offset has been updated, so all definitions must be refreshed + int adjustedIndex = aImpl.iByteCodeIndex - iBaseOffset; + aImpl.iImpl->SetDefinition(DefinitionString(aImpl.iByteCodeIndex, aImpl.iName)); + UpdateParamLimits(aImpl.iName); + } + +void CMLCompDataInstOpt::UpdateTables(TMLCompDataTable& aTable) + { + // regenerate the byte code indices, in case they have changed + int line = 0; + for (TMLCompDataTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) + { + for (TMLCompDataTable::TMLCompDataSubTables::const_iterator pSub = aTable.iSubTables.begin(); pSub != aTable.iSubTables.end(); ++pSub) + { + TMLCompDataTable::TMLCompDataSubTable& sub = **pSub; + int last = *(sub.rbegin()); + if(line == last) + { + string tableName = MLCompDataToCdl::SubTableApiName(sub); + CMLCompDataInstOptImpl* impl = FindSimilarImpl(iTableImpls, FindImp(tableName)); + UpdateTableInstance(aTable, sub, impl); + } + } + line++; + } + } + +void CMLCompDataInstOpt::SetNewLineData(CMLCompDataLineInstOptImpl& aImpl) + { + aImpl.iBytes.clear(); + + TMLCompDataLine& line = *aImpl.iLine; + aImpl.iComment = string("for line: "); + aImpl.iName = MLCompDataToCdl::LineApiName(line); + + // handle mirroring order + bool mirrored = false; + if(line.iParentTable) // we know top table can't be mirrored + mirrored = line.iParentTable->iTables->iCanBeMirror; + const string* outputOrder = mirrored ? + KCompDataGraphicOutputOrderMirrored : KCompDataGraphicOutputOrder; + int outputSize = KCompDataGraphicOutputOrderSize; + if (line.iType == TMLCompDataLine::ETextComponent) + { + outputOrder = mirrored ? + KCompDataTextOutputOrderMirrored : KCompDataTextOutputOrder; + outputSize = KCompDataTextOutputOrderSize; + } + vector cellOrder(outputOrder, outputOrder + outputSize); + + // we are currently storing variety as max allowed value, but it's a zero based index + int numVarieties = line.MaxVariety() + 1; + + // we will be storing all of the rows and cols, even if the rows and cols limits are lower + int totalMaxCols = numVarieties * line.NumCols(); + int totalMaxRows = numVarieties * line.NumRows(); + int totalMax = totalMaxCols > totalMaxRows ? totalMaxCols : totalMaxRows; + + // initialize the temporary bytestream, and the index map + vector tempBytes; + IndexMap indexMap; + + // fill in the temp byte stream and the index map for each cell + OptimizeNewLineData(aImpl, indexMap, tempBytes, cellOrder, mirrored, totalMax, numVarieties); + + // encode the index map + SetNewLineParamData(aImpl, indexMap, totalMax, numVarieties); + + // finally copy the temp byte stream onto the end of the real encoded byte stream + copy(tempBytes.begin(), tempBytes.end(), back_inserter(aImpl.iBytes)); + } + +void CMLCompDataInstOpt::SetNewLineParamData(CMLCompDataLineInstOptImpl& aImpl, IndexMap& aIndexMap, int aTotalMax, int aNumVarieties) + { + // only set parameter data if the line is not simple + TMLCompDataLine& line = *aImpl.iLine; + + bool needsHeader = line.NeedsOptions() || line.NeedsCols() || line.NeedsRows(); + + int typeBitfield = line.iType << 1; + if(needsHeader) + { + typeBitfield |= 1; + } + + aImpl.iBytes.push_back(typeBitfield); + + if(needsHeader) + { + // we can just dump the number of varieties, this will be used by the limits API + // and we can also them to calculate value indices within a cell when decoding + aImpl.iBytes.push_back(aNumVarieties); + } + + // count the number of cells that are complex + char numMultiValues = aIndexMap.size(); + if(needsHeader) + { + aImpl.iBytes.push_back(numMultiValues); + } + else + { + // we didn't think we needed a header, so there should be no complex cells! + if (numMultiValues > 0) + throw GeneralErr("complex cells detected in simple line"); + } + + // for each complex cell, encode the bitfield and the count + for(IndexMap::iterator pIndex = aIndexMap.begin(); pIndex != aIndexMap.end(); ++pIndex) + { + int count = pIndex->first; + int index = pIndex->second; + EncodeValue(aImpl.iBytes, index); + EncodeValue(aImpl.iBytes, count); + } + } + +void CMLCompDataInstOpt::OptimizeNewLineData( + CMLCompDataLineInstOptImpl& aImpl, + IndexMap& aIndexMap, + vector& aTempBytes, + const vector& aOutputOrder, + bool aMirrored, + int aTotalMax, + int aNumVarieties) + { + vector paramLimits; + TMLCompDataLine& line = *aImpl.iLine; + + // start by extracting the row and column data. + // we can optimize the stored format along with the rest of the data + // so no need to optimize it yet + for(int cell = 0; cell < 2; cell++) + { + string cellName = aOutputOrder[cell]; + ParamLimitVarieties nextLimits; + TMLCompDataValues& values = line[cellName]; + for(int varietyIndex = 0; varietyIndex < aNumVarieties; varietyIndex++) + { + TMLCompDataZoomLevels& zoomLevels = values[varietyIndex]; + TMLCompDataCalcs* calcs = &(zoomLevels[iZoomLevel]); + if(!calcs->size()) + calcs = &(zoomLevels[EAknUiZoomNormal]); + int value = CdlTkUtil::ParseInt((*calcs)[0]); + nextLimits.push_back(value); + } + paramLimits.push_back(nextLimits); + } + + // calculate the number of values + bool needsHeader = line.NeedsOptions() || line.NeedsCols() || line.NeedsRows(); + unsigned int nextCellFlag = 1; // bit flag for the next cell, note it can get bigger than a char + for (cell = 0; cell < aOutputOrder.size(); cell++) + { + string cellName = aOutputOrder[cell]; + TMLCompDataValues::TCompDataCellType type = TMLCompDataValues::Type(cellName); + if(!needsHeader && type == TMLCompDataValues::ECellTypeParamLimit) + { + // if we don't need header, then don't output the param limits values + // although we'll still use them internally + continue; + } + + int paramLimitsIndex = TMLCompDataValues::Type(cellName) == TMLCompDataValues::ECellTypeCol ? 0 : 1; // if it's not a row or col, it doesn't matter what param limits are used. + TMLCompDataValues& values = line[cellName]; + int numValues = 0; + if(type == TMLCompDataValues::ECellTypeCol || type == TMLCompDataValues::ECellTypeRow) + { + ParamLimitVarieties& nextLimits = paramLimits[paramLimitsIndex]; + numValues = std::accumulate(nextLimits.begin(), nextLimits.end(), 0); + } + else + { + numValues = aNumVarieties; + } + + bool mirrorJustification = (aMirrored && cellName == KCellNameJustification); + OptimizeNewLineCellData(aIndexMap, aTempBytes, values, nextCellFlag, numValues, aNumVarieties, paramLimits[paramLimitsIndex], cellName, mirrorJustification); + } + } + +void CMLCompDataInstOpt::OptimizeNewLineCellData( + IndexMap& aIndexMap, + vector& aTempBytes, + TMLCompDataValues& aValues, + unsigned int& aNextCell, + int aTotalParams, + int aNumVarieties, + CMLCompDataInstOpt::ParamLimitVarieties& aParamLimitVarieties, + string cellName, + bool aMirrorJustification) + { + // build up the values for each variety + // if the valid values for each variety are the same, then we can store them once only + // in which case there will be as many values as the variety with the largest number of values + vector optimizedValues; + + // also build up the found valid values in case we can't optimize + vector foundValues; + + bool optimizeVarieties = true; + bool optimizeCalcs = true; + int numCalcs = 0; + int* largestParamLimitPtr = max_element(aParamLimitVarieties.begin(), aParamLimitVarieties.end()); + int largestParamLimit = largestParamLimitPtr != aParamLimitVarieties.end() ? *largestParamLimitPtr : 0; + + // in the case of there being no calcs at all, we don't want to be optimizing, + // in order to avoid wasted flags. + if(largestParamLimit == 1) + optimizeCalcs = false; + + TMLCompDataValues::TCompDataCellType type = TMLCompDataValues::Type(cellName); + bool isColRow = (type == TMLCompDataValues::ECellTypeCol || type == TMLCompDataValues::ECellTypeRow); + + // only go up to the max variety, as any data past that may be from a spurious merged instance + for(int varietyIndex = 0; varietyIndex < aNumVarieties; varietyIndex++) + { + TMLCompDataZoomLevels& zoomLevels = aValues[varietyIndex]; + TMLCompDataCalcs* calcs = &(zoomLevels[iZoomLevel]); + if(!calcs->size()) + calcs = &(zoomLevels[EAknUiZoomNormal]); + numCalcs = calcs->size(); + string value; + vector foundCalcs; + int paramLimit = aParamLimitVarieties[varietyIndex]; + if(numCalcs == 0) + { + if(varietyIndex == 0) + optimizedValues.push_back(value); + if(varietyIndex > 0 && !(optimizedValues[0].empty())) + optimizeVarieties = false; + foundCalcs.push_back(value); + } + else + { + for(int index = 0; index < numCalcs; index++) + { + bool needToCheckIndexValidity = !isColRow || (index < paramLimit); + value = (*calcs)[index]; + value = aMirrorJustification ? TMLCompDataValues::MirrorJustificationValue(value) : value; + + if(index >= optimizedValues.size() && index < largestParamLimit) // index is zero based, size is quantity + { + // store the first valid value for a given index that we find. + // note that this will pick up additional values in subsequent varieties + optimizedValues.push_back(value); + } + else if(needToCheckIndexValidity && value != optimizedValues[index]) + { + // so if it doesn't match, we can't optimize + optimizeVarieties = false; + } + + // collect the valid found values as we go, in case we aren't able to optimize + if(needToCheckIndexValidity) + { + foundCalcs.push_back(value); + } + } + } + if(isColRow) + { + int found = foundCalcs.size(); + if(!found) + { + foundCalcs.push_back(string()); + found++; + } + if(found > 1) + { + optimizeCalcs = false; + } + } + else + { + optimizeCalcs = false; + } + copy(foundCalcs.begin(), foundCalcs.end(), back_inserter(foundValues)); + } + + if(optimizeVarieties && isColRow) + { + // now that we know the optimized values, fill missing values by repeating the last one. + // but if we're optimizing the calcs, then we don't want to expand them after all + if(!optimizeCalcs) + { + int optimal = optimizedValues.size(); + string value = optimal > 0 ? optimizedValues[optimal-1] : string(); + for(; optimal < largestParamLimit; optimal++) + { + optimizedValues.push_back(value); + } + } + } + + if(optimizeVarieties && aNumVarieties == 1) + { + optimizeVarieties = false; + } + + vector& valuesToEncode = optimizeVarieties ? optimizedValues : foundValues; + EncodeNewLineCellData(aIndexMap, aTempBytes, valuesToEncode, aNextCell, aTotalParams, optimizeVarieties, optimizeCalcs); + } + +void CMLCompDataInstOpt::EncodeNewLineCellData( + IndexMap& aIndexMap, + vector& aTempBytes, + vector& aValuesToEncode, + unsigned int& aNextCell, + int aTotalMax, + bool aOptimizeVarieties, + bool aOptimizeCalcs) + { + // encode the actual data into the temporary bytestream + int numOptimizedVals = aValuesToEncode.size(); + if(numOptimizedVals > 0) + { + for(vector::iterator pString = aValuesToEncode.begin(); pString != aValuesToEncode.end(); ++pString) + { + EncodeValue(aTempBytes, *pString); + } + } + else + { + EncodeValue(aTempBytes, ""); + } + + if(numOptimizedVals > aTotalMax) + throw GeneralErr("bad index in indexMap"); + + // if there is only one value stored, we can make a further optimization + // as we know that all values must be the same, however they are stored + // so in that case, don't store an index map entry + if(numOptimizedVals > 1) + { + // update the index map, + // put the flags at the right hand side, to avoid it becoming multi-byte in general + int optimizeVarietiesMask = (aOptimizeVarieties ? 1 : 0); + int optimizeCalcsMask = (aOptimizeCalcs ? 1 : 0) << 1; + int numValsMask = (numOptimizedVals) << 2; + int indexField = (numValsMask | optimizeCalcsMask | optimizeVarietiesMask); + aIndexMap[indexField] |= aNextCell; + } + aNextCell = aNextCell << 1; + } + +void CMLCompDataInstOpt::CountApiParams(CCdlTkImplementation& aApi, int& aParams) + { + aParams = 0; + const CCdlTkApiParams& params = aApi.Api().AsFunc().Params(); + for (CCdlTkApiParams::const_iterator pParam = params.begin(); pParam != params.end(); ++pParam) + { + if (pParam->Type() == KTypeInt) // is it a cell index parameter + aParams++; + } + } + +void CMLCompDataInstOpt::ValidateRequiredParams(string aApiName, CCdlTkApiParams& aParams, bool aOption, bool aColumn, bool aRow) + { + // check that data matches api + bool matches = true; + matches &= ((aOption) == (aParams.FindByName(KParamOptionIndex) != aParams.end())); + matches &= ((aColumn) == (aParams.FindByName(KParamColIndex) != aParams.end())); + matches &= ((aRow) == (aParams.FindByName(KParamRowIndex) != aParams.end())); + if(!matches) + throw CdlTkAssert(string("layout data does not match CDL API : ") + aApiName); + } + +void CMLCompDataInstOpt::SetGenericFunc(CMLCompDataInstOptImpl& aImpl, SCompDataImplFunc::TFuncType aType) + { + CCdlTkFunctionApi& api = const_cast(aImpl.iImpl->Api().AsFunc()); + CCdlTkApiParams& params = api.Params(); + + SCompDataImplFunc& func = AddImplFunc(aType, params); + aImpl.iImpl->SetPointerReference(func.iPtrRef); + } + +void CMLCompDataInstOpt::SetLineFunc(CMLCompDataLineInstOptImpl& aImpl) + { + SCompDataImplFunc::TFuncType type = SCompDataImplFunc::EWindowLine; + if (aImpl.iLine->iType == TMLCompDataLine::ETextComponent) + { + type = SCompDataImplFunc::ETextLine; + } + string name = aImpl.iImpl->Name(); + + // look up the api to see whether we need the params + CCdlTkFunctionApi& api = const_cast(aImpl.iImpl->Api().AsFunc()); + CCdlTkApiParams& params = api.Params(); + ValidateRequiredParams( + name, + params, + iAllParams || aImpl.iLine->NeedsOptions(), + iAllParams || aImpl.iLine->NeedsCols(), + iAllParams || aImpl.iLine->NeedsRows()); + SCompDataImplFunc& func = AddImplFunc(type, params); + aImpl.iImpl->SetPointerReference(func.iPtrRef); + } + +void CMLCompDataInstOpt::SetSubTableFunc(CMLCompDataSubTableInstOptImpl& aImpl) + { + TMLCompDataTable& table = *(aImpl.iTable); + TMLCompDataTable::TMLCompDataSubTable& subTable = *(aImpl.iSubTable); + TMLCompDataLine& line= *(table[subTable[0]]); + + SCompDataImplFunc::TFuncType type = SCompDataImplFunc::EWindowTable; + + if (line.iType == TMLCompDataLine::ETextComponent) + { + type = SCompDataImplFunc::ETextTable; + } + string name = aImpl.iImpl->Name(); + + CCdlTkFunctionApi& api = const_cast(aImpl.iImpl->Api().AsFunc()); + CCdlTkApiParams& params = api.Params(); + + string debug; + for(CCdlTkApiParams::iterator pParam = params.begin(); pParam != params.end(); ++pParam) + debug = pParam->Name(); + + ValidateRequiredParams( + name, + params, + iAllParams || subTable.iNeedsOption, + iAllParams || subTable.iNeedsCol, + iAllParams || subTable.iNeedsRow); + SCompDataImplFunc& func = AddImplFunc(type, params); + aImpl.iImpl->SetPointerReference(func.iPtrRef); + } + +bool CMLCompDataInstOpt::HasApi(const string& aName) + { + return iInterface.ApiList().Find(aName) != 0; + } + +CCdlTkImplementation& CMLCompDataInstOpt::FindImp(const string& aName) + { + CCdlTkImplementation* impl = iInstance->Impl().Find(aName); + if (!impl) + throw NotFoundErr(aName + " in interface " + iInterface.FileName()); + return *impl; + } + +CMLCompDataInstOptImpl* CMLCompDataInstOpt::FindSimilarImpl(const CMLCompDataInstOptImpls& aImpls, const CCdlTkImplementation& aImpl) + { + for (CMLCompDataInstOptImpls::const_iterator pOptImpl = aImpls.begin(); pOptImpl != aImpls.end(); ++pOptImpl) + { + CMLCompDataInstOptImpl* optImpl = *pOptImpl; + if (optImpl->iImpl == &aImpl) + return optImpl; + } + return NULL; + } + +string CMLCompDataInstOpt::DefinitionString(int aByteCodeIndex, const string& aApiName) + { + int adjustedIndex = aByteCodeIndex - iBaseOffset; + return CdlTkUtil::ShortToHexString(adjustedIndex) + ",\t// (" + CdlTkUtil::IntToHexString(aByteCodeIndex) + ") " + aApiName; + } + +bool CMLCompDataInstOpt::CheckByteCodeIndexInRange(int aByteCodeIndex) + { + int adjustedIndex = aByteCodeIndex - iBaseOffset; + if(adjustedIndex > KAddressableBytecodedData) + { + cerr << "Error: Out of range: index = " << CdlTkUtil::IntToHexString(aByteCodeIndex) << ", "; + cerr << "baseOffset = " << CdlTkUtil::IntToHexString(iBaseOffset ) << endl; + return false; + } + return true; + } + +SCompDataImplFunc& CMLCompDataInstOpt::AddImplFunc(SCompDataImplFunc::TFuncType aType) + { + CCdlTkApiParams params; + return AddImplFunc(aType, params); + } + +SCompDataImplFunc& CMLCompDataInstOpt::AddImplFunc(SCompDataImplFunc::TFuncType aType, CCdlTkApiParams& aParams) + { + for (CImplFuncs::iterator pFunc = iFuncs.begin(); pFunc != iFuncs.end(); ++pFunc) + { + SCompDataImplFunc& func = **pFunc; + if(func.IsSimilar(aType, aParams)) + return func; + } + + int count = gTheFuncs.size(); + for (int ii=0; iiIsSimilar(aType, aParams)) + { + iFuncs.push_back(func); + return *func; + } + } + + throw NotFoundErr("implementation function"); + return gTheFuncs[0]; + } + +void CMLCompDataInstOpt::SetGenericAPI(SCompDataImplFunc::TFuncType aType, const string& aName) + { + CCdlTkImplementation* impl = iInstance->Impl().Find(aName); + + // CMLCompDataInstOptImpl(CCdlTkImplementation* aImpl); + CMLCompDataInstOptImpl* newImpl = new CMLCompDataInstOptImpl(impl); + iImpls.push_back(newImpl); + + SetGenericFunc(*newImpl, aType); + newImpl->iImpl->SetDefinition(CdlTkUtil::ShortToHexString(0) + ","); // no specific data for generic apis + } + +// The following strings and the SetExtraCpp() function build the gross structure of +// the C++ customisation instance. +// So far, the implementations are actually just 16-bit values, typically indexes into +// the data lookup table. These need to be turned into an array by adding declarations +// and brackets to the first and last implementations. Extra support functions are also +// added. +// extern string KScalableExtraCpp; +string KScalableExtraCpp = "\ +#include \"aknlayout2scalabledecode.h\"\n\ +namespace $INTERFACE_NS { extern const TUint8 KByteCodedData_$FIRSTINSTANCENAME[]; }\n"; + +//extern string KScalableInitialCpp; +string KScalableInitialCpp ="\ +extern const TUint16 KDataLookup[$INTERFACE_NS::E_TApiId_TableSize];\n\ +const SCompDataImplData KImplData = { KDataLookup, $INTERFACE_NS::KByteCodedData_$FIRSTINSTANCENAME + $THISINSTANCEBASEOFFSET };\n\ +\n\ +$FUNCTIONS\ +\n\ +const TUint16 KDataLookup[$INTERFACE_NS::E_TApiId_TableSize] =\n\ +\t{\n"; +void CMLCompDataInstOpt::SetExtraCpp(const string& aFirstInstName) + { + // The "extra cpp" field is written to the top of the cpp file. + CdlTkUtil::CReplaceSet cppSet; + cppSet.Add("$INTERFACE_NS", iInterface.NamespaceName()); + cppSet.Add("$FIRSTINSTANCENAME", aFirstInstName); + cppSet.Add("$THISINSTANCEBASEOFFSET", CdlTkUtil::IntToHexString(iBaseOffset)); // base offset can be longer than 16 bits + iInstance->SetExtraCpp(CdlTkUtil::MultiReplace(cppSet, KScalableExtraCpp)); + + // add headers & fwd declarations + string init = CdlTkUtil::MultiReplace(cppSet, KScalableInitialCpp); + + // add decode functions + string functions; + for (CImplFuncs::iterator pFunc = iFuncs.begin(); pFunc != iFuncs.end(); ++pFunc) + { + CdlTkUtil::AppendString(functions, (*pFunc)->iDefn); + CdlTkUtil::AppendString(functions, "\n"); + } + init = CdlTkUtil::Replace("$FUNCTIONS", functions, init); + CCdlTkImplementation& first = **(iInstance->Impl().begin()); + first.SetDefinition(init + first.Definition()); + + // add end of data table + CCdlTkImplementation& last = **(iInstance->Impl().end() - 1); + last.SetDefinition(last.Definition() + "\n};"); + } + +void CMLCompDataInstOpt::OutputStats() + { + int optimizedBytes(0); + int unoptimizedBytes(0); + for (CMLCompDataInstOptImpls::iterator pImpl = iImpls.begin(); pImpl != iImpls.end(); ++pImpl) + { + int size = (*pImpl)->iBytes.size(); + if ((*pImpl)->iIsRedirectedToExactCopy) + optimizedBytes += size; + else + unoptimizedBytes += size; + } + for (CMLCompDataInstOptImpls::iterator pTableImpl = iTableImpls.begin(); pTableImpl != iTableImpls.end(); ++pTableImpl) + { + int size = (*pTableImpl)->iBytes.size(); + if ((*pTableImpl)->iIsRedirectedToExactCopy) + optimizedBytes += size; + else + unoptimizedBytes += size; + } + + float compress = (100.0 * (float)unoptimizedBytes) / ((float)optimizedBytes + (float)unoptimizedBytes); + int compressInt = (int)(compress + 0.5); + cout << "instance " << iName << " compressed to " << compressInt << "% of total (" << unoptimizedBytes<< " / " << optimizedBytes + unoptimizedBytes << ")" << endl; + } + +void CMLCompDataInstOpt::AddTableToInstance(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSub, int /*aTableNum*/) + { + string tableName = MLCompDataToCdl::SubTableApiName(aSub); + string tableParamLimitsName = tableName + KFuncParamLimitsSuffix; + + if (HasApi(tableName)) + { + CCdlTkImplementation& impl = FindImp(tableName); + CMLCompDataSubTableInstOptImpl* newImpl = new CMLCompDataSubTableInstOptImpl(&aTable, &aSub, &impl); + iTableImpls.push_back(newImpl); + + SetDummyTableData(aTable, aSub, *newImpl); + SetSubTableFunc(*newImpl); + + AddTableLimitsImpl(tableName + KFuncLimitsSuffix, aSub); + if (HasApi(tableParamLimitsName)) + { + AddTableParamLimitsImpl(tableParamLimitsName, newImpl->iByteCodeIndex, SCompDataImplFunc::ETableParamLimits, aSub.iNeedsOption); + } + AddTableImpl(tableName, aTable, aSub); + } + } + +void CMLCompDataInstOpt::UpdateTableInstance(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSub, CMLCompDataInstOptImpl* aImpl) + { + string tableName = MLCompDataToCdl::SubTableApiName(aSub); + UpdateTableData(aTable, aSub, *aImpl); + + // if we can find the new table data in the aggregated data, point to that instead + int foundIndex = iInstances.FindSimilarBytes(aImpl, iBaseOffset); + if(foundIndex >= 0) + { + if(foundIndex != aImpl->iByteCodeIndex) + { + aImpl->iByteCodeIndex = foundIndex; + aImpl->iIsRedirectedToExactCopy = true; + } + else + { + cerr << "Error: found same table already in bytestream: " << aImpl->iName << endl; + } + } + + // now we've generated the bytecode, it will be added to the bytestream + iInstances.AddImpl(aImpl); + aImpl->iImpl->SetDefinition(DefinitionString(aImpl->iByteCodeIndex, tableName)); + + string tableParamLimitsName = tableName + KFuncParamLimitsSuffix; + if (HasApi(tableParamLimitsName)) + { + UpdateTableParamLimitsImpl(tableParamLimitsName, aImpl->iByteCodeIndex); + } + } + +void CMLCompDataInstOpt::AddTableParamLimitsImpl(const string& aApiName, int aByteCodeIndex, SCompDataImplFunc::TFuncType aType, bool aNeedsOptions) + { + CCdlTkImplementation& impl = FindImp(aApiName); + + // look up the api to see whether we need a variety params + CCdlTkFunctionApi& api = const_cast(impl.Api().AsFunc()); + CCdlTkApiParams& params = api.Params(); + ValidateRequiredParams( + aApiName, + params, + iAllParams || aNeedsOptions, + false, + false); + + SCompDataImplFunc& func = AddImplFunc(aType, params); + + impl.SetDefinition(DefinitionString(aByteCodeIndex, aApiName)); + impl.SetPointerReference(func.iPtrRef); + } + +void CMLCompDataInstOpt::UpdateTableParamLimitsImpl(const string& aApiName, int aByteCodeIndex) + { + CCdlTkImplementation& paramLimitsImpl = FindImp(aApiName); + paramLimitsImpl.SetDefinition(DefinitionString(aByteCodeIndex, aApiName)); + } + +void CMLCompDataInstOpt::AddTableLimitsImpl(const string& aApiName, TMLCompDataTable::TMLCompDataSubTable& aSubTable) + { + CCdlTkImplementation& impl = FindImp(aApiName); + AddTableLimitsImplDefn(aSubTable, impl); + impl.SetPointerReference(AddImplFunc(SCompDataImplFunc::ETableLimits).iPtrRef); + } + +void CMLCompDataInstOpt::AddTableLimitsImplDefn(TMLCompDataTable::TMLCompDataSubTable& aSubTable, CCdlTkImplementation& aImpl) + { + // code up table limits as a pair of byte values, the first byte is the first table + // index, the second is the last table index. + int first = (*aSubTable.begin()) & 0xff; + int last = (*aSubTable.rbegin()) & 0xff; + + // however, we want these APIs to be accessed zero based, so have to calculate the offset. + int offset = last - first; + + int v = offset; + if ( v > KAddressableBytecodedData ) + { + std::cerr << "*** ERROR: Value " << v << "(unknown/3) of out range" << std::endl; + } + + aImpl.SetDefinition(CdlTkUtil::ShortToHexString(offset) + KComma); + } + +void CMLCompDataInstOpt::AddTableImpl(const string& aApiName, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSub) + { + CCdlTkImplementation& impl = FindImp(aApiName); + + int nParams; + CountApiParams(impl, nParams); + nParams--; // don't count the aLineIndex param + SCompDataImplFunc::TFuncType type = SCompDataImplFunc::EWindowTable; + TMLCompDataLine::TComponentType subTableType = aTable[aSub[0]]->iType; + switch(subTableType) + { + case TMLCompDataLine::ETextComponent: + { + type = SCompDataImplFunc::ETextTable; + break; + } + } + CCdlTkFunctionApi& api = const_cast(impl.Api().AsFunc()); + CCdlTkApiParams& params = api.Params(); + ValidateRequiredParams( + aApiName, + params, + iAllParams || aSub.iNeedsOption, + iAllParams || aSub.iNeedsCol, + iAllParams || aSub.iNeedsRow); + SCompDataImplFunc& func = AddImplFunc(type, params); + } + +void CMLCompDataInstOpt::AddParamLimits(TMLCompDataLine& aLine, bool aNeedsOptions) + { + string apiName = MLCompDataToCdl::LineApiName(aLine) ; + string paramLimitsApiName = apiName + KFuncParamLimitsSuffix; + if (!HasApi(paramLimitsApiName)) + throw NotFoundErr(paramLimitsApiName + " in interface " + iInterface.FileName()); + + CCdlTkImplementation& paramLimitsImpl = FindImp(paramLimitsApiName); + + // look up the api to see whether we need a variety params + CCdlTkFunctionApi& api = const_cast(paramLimitsImpl.Api().AsFunc()); + CCdlTkApiParams& params = api.Params(); + ValidateRequiredParams( + paramLimitsApiName, + params, + iAllParams || aNeedsOptions, + false, + false); + + SCompDataImplFunc& func = AddImplFunc(SCompDataImplFunc::ELineParamLimits, params); + paramLimitsImpl.SetPointerReference(func.iPtrRef); + + UpdateParamLimits(apiName); + } + +void CMLCompDataInstOpt::UpdateParamLimits(const string& apiName) + { + string paramLimitsApiName = apiName + KFuncParamLimitsSuffix; + if (HasApi(paramLimitsApiName)) + { + CCdlTkImplementation& paramLimitsImpl = FindImp(paramLimitsApiName); + CMLCompDataInstOptImpl* actualOptImpl = FindSimilarImpl(iImpls, FindImp(apiName)); + + paramLimitsImpl.SetDefinition(DefinitionString(actualOptImpl->iByteCodeIndex, paramLimitsApiName)); + } + } + +void CMLCompDataInstOpt::SetDummyTableData(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, CMLCompDataInstOptImpl& aImpl) + { + aImpl.iBytes.clear(); + aImpl.iComment = string("for table: "); + aImpl.iName = MLCompDataToCdl::SubTableApiName(aSubTable); + EncodeValue(aImpl.iBytes, aSubTable.size()); + for(TMLCompDataTable::TMLCompDataSubTable::iterator pLineId = aSubTable.begin(); pLineId != aSubTable.end(); ++pLineId) + { + aImpl.iBytes.push_back(0); + aImpl.iBytes.push_back(0); + } + } + +void CMLCompDataInstOpt::UpdateTableData(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, CMLCompDataInstOptImpl& aImpl) + { + aImpl.iBytes.clear(); + EncodeValue(aImpl.iBytes, aSubTable.size()); + for(TMLCompDataTable::TMLCompDataSubTable::iterator pLineId = aSubTable.begin(); pLineId != aSubTable.end(); ++pLineId) + { + // figure out the offset to the next line of the table + TMLCompDataLine& line = *(aTable[*pLineId]); + string lineName = MLCompDataToCdl::LineApiName(line) ; + CMLCompDataInstOptImpl* lineImpl = FindSimilarImpl(iImpls, FindImp(lineName)); + + // we must store the adjusted index, ie relative to the base offset, in the definition, as that will be used + // in the main output, so check that the offset is in range, which it should be if we've updated the lines + // correctly + if(!CheckByteCodeIndexInRange(lineImpl->iByteCodeIndex)) + throw GeneralErr(aImpl.iName + " in interface " + iInterface.FileName()); + int adjustedIndex = lineImpl->iByteCodeIndex - iBaseOffset; + + // make an assumption that data fits into 16 bits, and don't encode the lookups + // that way, when decoding, we can jump forward by 2 bytes * index without decoding + // all the values (since they're not encoded, we know they're all the same size) + aImpl.iBytes.push_back((adjustedIndex & 0xff00) >> 8); + aImpl.iBytes.push_back(adjustedIndex); + } + } + +struct SIdToInt + { + int iInt; + char* iStr; + }; + +#include +extern SIdToInt gIdToIntTable[]; +extern const int gIdToIntTableCount; +extern void TranslateValue(string& aValue); + +void CMLCompDataInstOpt::EncodeValue(vector& aBytes, string aValue) + { + int pos = 0; + TranslateValue(aValue); + if (aValue == "") + { + aBytes.push_back(KByteEmpty); + } + else + { + pos = aValue.find_first_of(KParentRelativeMarker); + if(pos != string::npos) + { + if (pos != 0) + throw CdlTkAssert(string("arithmetic parser not good enough : ") + aValue); + int val = CdlTkUtil::ParseInt(aValue.substr(1)); + EncodeParentRelativeValue(aBytes, val); + } + else + { + int val = CdlTkUtil::ParseInt(aValue); + EncodeValue(aBytes, val); + } + } + } + +void CMLCompDataInstOpt::EncodeValue(vector& aBytes, int aValue) + { + if (0 <= aValue && aValue <= KMaxSingleByteValue) + { + aBytes.push_back(aValue); + } + else if (aValue > KMaxSingleByteValue && aValue <= KMaxDoubleByteValue) + { + aBytes.push_back(KByteWord); + aBytes.push_back((aValue & 0xff00) >> 8); + aBytes.push_back(aValue); + } + else + { + aBytes.push_back(KByteLong); + aBytes.push_back((aValue & 0xff000000) >> 24); + aBytes.push_back((aValue & 0x00ff0000) >> 16); + aBytes.push_back((aValue & 0x0000ff00) >> 8); + aBytes.push_back(aValue); + } + } + +void CMLCompDataInstOpt::EncodeParentRelativeValue(vector& aBytes, int aValue) + { + if (KMinSingleByteParentRelativeValue <= aValue && aValue <= KMaxSingleByteParentRelativeValue) + { + aBytes.push_back(KByteP1); + aBytes.push_back(aValue); + } + else + { + aBytes.push_back(KByteP2); + aBytes.push_back((aValue & 0xff00) >> 8); + aBytes.push_back(aValue); + } + } + +void CMLCompDataInstOpt::MirrorParamName(string& aParamName) + { + if (aParamName == KParamNameL) + aParamName = KParamNameR; + else if (aParamName == KParamNameR) + aParamName = KParamNameL; + } + +// +// MLCompDataCdlInstanceOpt +// + +MLCompDataCdlInstanceOpt::InstStruct::InstStruct(string aInstName, TMLCompData* aInst, TMLAttributes* aAttribs) + : + iInstName(aInstName), + iInst(aInst), + iAttribs(aAttribs) + { + } + +MLCompDataCdlInstanceOpt::InstList::~InstList() + { + for(InstList::iterator pNext = begin(); pNext != end(); ++pNext) + { + delete pNext->iInst; + } + } + +void MLCompDataCdlInstanceOpt::ProcessSeparators(vector& args, vector& aSeparators) + { + for(int arg = 3; arg < args.size(); arg++) + { + if(args[arg] == "-a") + aSeparators.push_back(arg); + } + + aSeparators.push_back(args.size()); // add an implicit last separator + if(aSeparators.size() < 2) + throw MLCompDataCdlInstanceOptArgsErr(); + + // check that the distance between each separator is not a multiple of 2 + // i.e. counting the steps between aSeparators ( sep -> xml -> inst -> sep) is 3 steps + // i.e. counting the steps between aSeparators ( sep -> xml -> inst -> xml -> inst -> sep) is 5 steps + for(int sep = 0; sep < aSeparators.size() - 1; sep++) + { + int delta = aSeparators[sep+1] - aSeparators[sep]; + if (delta%2 == 0) + throw MLCompDataCdlInstanceOptArgsErr(); + } + } + +bool MLCompDataCdlInstanceOpt::CheckForUsedInstances( + const CInstanceList& aUsedList, + const CZoomLevelNames& aZoomLevelNames, + const vector& aArgs, + const vector& aSeparators, + int aSepIndex) + { + bool ok = false; + for(CZoomLevelNames::const_iterator pZoomLevel = aZoomLevelNames.begin(); pZoomLevel != aZoomLevelNames.end(); ++pZoomLevel) + { + // check if any of these instances are used - skip this if none are used + for (int arg = aSeparators[aSepIndex] + 1; arg < aSeparators[aSepIndex+1]; arg += 2) + { + string instName = aArgs[arg+1] + "_" + pZoomLevel->second; + if (aUsedList.IsInstanceOk(instName)) + ok = true; + } + } + return ok; + } + +void MLCompDataCdlInstanceOpt::ParseInstances(const vector& aArgs, const vector& aSeparators, int aSepIndex, MLCompDataCdlInstanceOpt::InstList& aInstList) + { + for (int arg = aSeparators[aSepIndex] + 1; arg < aSeparators[aSepIndex+1]; arg += 2) + { + string layoutName = aArgs[arg]; + string instName = aArgs[arg+1]; + string attribsName = CdlTkUtil::Replace(KCompDataFileNameSuffix, KAttributesFileNameSuffix, layoutName); + + auto_ptr layoutParse = TMLCompDataParseLayout::Parse(layoutName); + auto_ptr layout(layoutParse.get()); + layoutParse.release(); + + auto_ptr attribsParse = TMLAttributesParse::Parse(attribsName); + auto_ptr attribs(attribsParse.get()); + attribsParse.release(); + + InstStruct instStruct(instName, layout.get(), attribs.get()); + aInstList.push_back(instStruct); + layout.release(); + attribs.release(); + } + } + +void MLCompDataCdlInstanceOpt::MergeLayouts(CInstanceList& aInstUsedList, CZoomLevelNames& aZoomLevelNames, const InstList& aInstances, InstList& aMergedLayouts) + { + // start with the non-mirrored instances + for(int count = 0; count < 2; count++) + { + bool isMirrored = (count != 0); + // first iterate through the layouts, we will generate one instance per layout + for(int instIndex = 0; instIndex < aInstances.size(); instIndex++) + { + const InstStruct& instStruct = aInstances[instIndex]; + string targetInstName = instStruct.iInstName; + TMLCompData& targetLayout = *(instStruct.iInst); + TMLAttributes& targetAttribs = *(instStruct.iAttribs); + + bool required = false; + for(CZoomLevelNames::const_iterator pZoomLevel = aZoomLevelNames.begin(); pZoomLevel != aZoomLevelNames.end(); ++pZoomLevel) + { + string zoomInstName = targetInstName + "_" + pZoomLevel->second; + if(aInstUsedList.IsInstanceOk(zoomInstName)) + required = true; + } + + // if this target is not required, or if it's the wrong sort of mirrored + // for this iteration, skip it. + if(targetLayout.iCanBeMirror != isMirrored || !required) + continue; + + // for each instance, we must merge all the other layouts + auto_ptr mergedLayout(new TMLCompData()); + auto_ptr mergedAttribs(new TMLAttributes()); + for (InstList::const_iterator pInst2 = aInstances.begin(); pInst2 != aInstances.end(); ++pInst2) + { + // merge in all the others + const InstStruct& instStruct2 = *pInst2; + if(instStruct2.iInstName != targetInstName) + { + TMLCompData& nextLayout = *(instStruct2.iInst); + TMLAttributes& nextAttribs = *(instStruct2.iAttribs); + // but only if it's the right kind of mirrored + if(nextLayout.iCanBeMirror == isMirrored) + { + mergedLayout->Merge(nextLayout); + mergedAttribs->Merge(nextAttribs); + } + } + } + // then end up merging in the one we want + mergedLayout->Merge(targetLayout); + mergedAttribs->Merge(targetAttribs); + if(isMirrored) + { + // If we have just processed a mirrored layout, + // we need to do a mirror merge with the corresponding one. + // The instances are ordered as on the command line, + // but the merged layouts are grouped toghether, unmirrored first. + // So to convert between the two indexes: 1 -> 0, and 3 -> 1 + int unMirroredMergedLayoutIndex = (instIndex / 2); + InstStruct& unMirroredInst = aMergedLayouts[unMirroredMergedLayoutIndex]; // this works as we have already added the unmirrored instance to the vector + TMLCompData& unMirroredLayout = *(unMirroredInst.iInst); + TMLAttributes& unMirroredAttribs = *(unMirroredInst.iAttribs); + mergedLayout->Merge(unMirroredLayout); + mergedAttribs->Merge(unMirroredAttribs); + } + + InstStruct mergedInstStruct(targetInstName, mergedLayout.get(), mergedAttribs.get()); + aMergedLayouts.push_back(mergedInstStruct); + mergedLayout.release(); + mergedAttribs.release(); + } + } + } + +int MLCompDataCdlInstanceOpt::Process(vector& args) + { + // parse the file containing the used instances list. only instances in this list + // will be generated, even if also mentioned on the command line + CInstanceList instUsedList; + instUsedList.ProcessOptions(args); + + // extract the zoom level names, note that this consumes the argument if present + CZoomLevelNames zoomLevelNames; + zoomLevelNames.ProcessOptions(args); + + // check that we have an acceptable number of arguments + int extraArgs = args.size() - 3; + if (extraArgs < 0) + throw MLCompDataCdlInstanceOptArgsErr(); + + // check for optional flags + int arg = 2; + bool allParams = false; + if (args[arg] == "-allparams") + { + allParams = true; + arg++; + } + + bool nonCompleteInstance = false; + if(args[arg].substr(0,2) == "-d") + { + arg++; + if (args[arg].size() >= 2) + { + nonCompleteInstance = true; + } + } + + // parse the CDL interface + string cdlName = args[arg]; + CCdlTkCdlFileParser parser(cdlName); + auto_ptr iface(parser.LoadAndParse(true)); + MLCompDataCdlInstanceOpt process(*iface); + + // the separators divide the layout instances that are aggregated together + vector separators; + ProcessSeparators(args, separators); + for(int sep = 0; sep < separators.size() - 1; sep++) + { + if(!CheckForUsedInstances(instUsedList, zoomLevelNames, args, separators, sep)) + continue; + // start from after the next separator, and continue until before the next one + InstList instances; + ParseInstances(args, separators, sep, instances); + + InstList mergedLayouts; + MergeLayouts(instUsedList, zoomLevelNames, instances, mergedLayouts); + for(InstList::iterator pMergedLayout = mergedLayouts.begin(); pMergedLayout != mergedLayouts.end(); ) + { + process.AddInst(*pMergedLayout, zoomLevelNames, allParams, nonCompleteInstance); // pass ownership of mergedLayout + pMergedLayout = mergedLayouts.erase(pMergedLayout); + } + } + + process.Process(); + process.WriteInstances(); + return 0; + } + +void MLCompDataCdlInstanceOpt::ShowHelp(ostream& stream) + { + stream << "MLCompCdl2InstO [-i] [-z] [-allparams] [-d] (-a ([-m] )+ )+" << endl; + stream << " Creates optimised CDL instances containing the layout data." << endl; + stream << " Each -a flag is followed by a collection of xml and instance name pairs." << endl; + stream << " Each collection is aggregated separately." << endl; + stream << " The aggregation of the layout instances must conform to the CDL interface, " << endl; + stream << " but note any missing data in an instance may result in data being returned " << endl; + stream << " from a different instance, although duplicate implementations will be reused " << endl; + stream << " to reduce ROM usage." << endl; + stream << " A -m flag must precede an xml file that contains mirrored layout data." << endl; + stream << " An aggregated collection of layouts must contain interleaved" << endl; + stream << " elaf and the corresponding abrw instances." << endl; + stream << " If -i is specified, then only instances whose name" << endl; + stream << " appears in the file will be processed." << endl; + stream << " If -z is specified, then only instances whose zoom factor" << endl; + stream << " (in the form \"n,string\") appears in the file will be generated." << endl; + stream << " If -allparams is used, all processed APIs will have all available params added, " << endl; + stream << " otherwise only needed params are added." << endl; + stream << " If -d is supplied with any value, any API that has a missing" << endl; + stream << " implementation will be filled in with NULL, allowing fall-through to an instance" << endl; + stream << " from a lower priority pack." << endl; + } + +MLCompDataCdlInstanceOpt::MLCompDataCdlInstanceOpt(CCdlTkInterface& aInterface) + : + iInterface(aInterface) + { + } + +MLCompDataCdlInstanceOpt::~MLCompDataCdlInstanceOpt() + { + for(CCompDataZoomLevelDatas::iterator pZoomLevel = iZoomLevelDatas.begin(); pZoomLevel != iZoomLevelDatas.end(); ++pZoomLevel) + { + CCompDatas& compDatas = pZoomLevel->second; + for (CCompDatas::iterator pInstOpt = compDatas.begin(); pInstOpt != compDatas.end(); ++pInstOpt) + delete *pInstOpt; + } + for(CCompDataLayouts::iterator pLayout = iLayouts.begin(); pLayout != iLayouts.end(); ++pLayout) + delete *pLayout; + } + +void MLCompDataCdlInstanceOpt::AddInst(const InstStruct& aInstStruct, CZoomLevelNames& aZoomLevelNames, bool aAllParams, bool aNonCompleteInstance) + { + TMLCompData* layout = aInstStruct.iInst; + layout->iAttributes = aInstStruct.iAttribs; // transfer ownership + iLayouts.push_back(aInstStruct.iInst); + for(CZoomLevelNames::iterator pZoomLevel = aZoomLevelNames.begin(); pZoomLevel != aZoomLevelNames.end(); ++pZoomLevel) + { + auto_ptr p(new CMLCompDataInstOpt(*this, layout, aInstStruct.iInstName, pZoomLevel->second, pZoomLevel->first, aAllParams, aNonCompleteInstance)); + CCompDatas& compDatas = iZoomLevelDatas[pZoomLevel->first]; + compDatas.push_back(p.get()); + p.release(); + } + } + +void MLCompDataCdlInstanceOpt::Process() + { + for(CCompDataZoomLevelDatas::iterator pZoomLevel = iZoomLevelDatas.begin(); pZoomLevel != iZoomLevelDatas.end(); ++pZoomLevel) + { + CCompDatas& compDatas = pZoomLevel->second; + if(compDatas.size() == 0) + continue; + CMLCompDataInstOpt* firstInstOpt = compDatas[0]; + cout << "processing instances for zoom level: " << firstInstOpt->ZoomName() << endl; + + string firstInstName = firstInstOpt->Name(); + for (CCompDatas::iterator pLayout = compDatas.begin(); pLayout != compDatas.end(); ++pLayout) + (*pLayout)->Process(firstInstName); + } + ProcessCommonImpl(); + } + +void MLCompDataCdlInstanceOpt::WriteInstances() + { + bool found = false; + for(CCompDataZoomLevelDatas::iterator pZoomLevel = iZoomLevelDatas.begin(); pZoomLevel != iZoomLevelDatas.end(); ++pZoomLevel) + { + CCompDatas& compDatas = pZoomLevel->second; + if(!found && compDatas.size() > 0) + { + found = true; + cout << "writing instances ... " << endl; + } + for (CCompDatas::iterator pLayout = compDatas.begin(); pLayout != compDatas.end(); ++pLayout) + (*pLayout)->WriteInstance(); + } + } + +CCdlTkInterface& MLCompDataCdlInstanceOpt::Interface() + { + return iInterface; + } + +const string KCommonImplStart = "\ +#include \"aknlayout2scalabledecode.h\"\n\ +namespace $NAMESPACENAME { extern TUint8 const KByteCodedData_$FIRSTINSTANCENAME[] = {\n"; + +const string KCommonImplImpl = "\ +// $INDEX $COMMENT\n\ +$BYTES\n"; + +void MLCompDataCdlInstanceOpt::ProcessCommonImpl() + { + // use the first instance name of the first zoom level + // it's not entirely accurate but it only needs to disambiguate + CCompDatas& compDatas = iZoomLevelDatas[EAknUiZoomNormal]; + if(compDatas.size() == 0) + return; + CMLCompDataInstOpt* firstInstOpt = compDatas[0]; + + CdlTkUtil::CReplaceSet startImplSet; + startImplSet.Add("$NAMESPACENAME", iInterface.NamespaceName()); + startImplSet.Add("$FIRSTINSTANCENAME", firstInstOpt->Name()); + string bytecode = CdlTkUtil::MultiReplace(startImplSet, KCommonImplStart); + int byteCounter(0); + + for (CMLCompDataInstOptImpls::iterator pImpl = iImpls.begin(); pImpl != iImpls.end(); ++pImpl) + { + vector& bytes = (*pImpl)->iBytes; + if (!(*pImpl)->iIsRedirectedToExactCopy && bytes.size()) + { + string byteString; + for (vector::iterator pChar = bytes.begin(); pChar != bytes.end(); ++pChar) + { + CdlTkUtil::AppendString(byteString, CdlTkUtil::CharToHexString(*pChar)); + CdlTkUtil::AppendString(byteString, KComma); + } + + // in this case, we want to know the absolute index to help with debugging + int index = (*pImpl)->iByteCodeIndex; + if(byteCounter != index) + { + cerr << "Error: Data table mismatch for " << (*pImpl)->iName; + cerr << ": Bytecode index = " << CdlTkUtil::ShortToHexString(index); + cerr << "; byte counter = " << CdlTkUtil::ShortToHexString(byteCounter) << endl; + throw GeneralErr((*pImpl)->iName + " in interface " + iInterface.FileName()); + } + byteCounter += bytes.size(); + + CdlTkUtil::CReplaceSet implSet; + implSet.Add("$INDEX", CdlTkUtil::IntToHexString(index)); + implSet.Add("$COMMENT", (*pImpl)->iComment + (*pImpl)->iName + " (" + CdlTkUtil::ShortToHexString(bytes.size()) + " bytes)"); + implSet.Add("$BYTES", byteString); + CdlTkUtil::AppendString(bytecode, CdlTkUtil::MultiReplace(implSet, KCommonImplImpl)); + } + } + CdlTkUtil::AppendString(bytecode, "};\n}"); + CCdlTkInstance& firstInst = firstInstOpt->Inst(); + firstInst.SetExtraCpp(bytecode); + } + +int MLCompDataCdlInstanceOpt::FindSimilarBytes(CMLCompDataInstOptImpl* aImpl, int aBaseOffset) + { + int index = -1; + vector::iterator startOfAddressableBlock = iBytesAggregated.begin() + aBaseOffset; + vector::iterator found = std::search( + startOfAddressableBlock, + iBytesAggregated.end(), + aImpl->iBytes.begin(), + aImpl->iBytes.end()); + if(found != iBytesAggregated.end()) + { + index = std::distance(iBytesAggregated.begin(), found); // we return the absolute position + } + return index; + } + +void MLCompDataCdlInstanceOpt::AddImpl(CMLCompDataInstOptImpl* aImpl) + { + if(!aImpl->iIsRedirectedToExactCopy) + { + CMLCompDataInstOptImpls::iterator found = std::find(iImpls.begin(), iImpls.end(), aImpl); + if(found == iImpls.end()) + { + iImpls.push_back(aImpl); + } + else + { + cerr << "Error: " << aImpl->iName << " already added to byte stream" << endl; + throw GeneralErr(aImpl->iName + " in interface " + iInterface.FileName()); + } + if (aImpl->iBytes.size()) + { + aImpl->iByteCodeIndex = iBytesAggregated.size(); + iBytesAggregated.insert( + iBytesAggregated.end(), + aImpl->iBytes.begin(), + aImpl->iBytes.end()); + } + } + } + +int MLCompDataCdlInstanceOpt::ByteStreamSize() const + { + return iBytesAggregated.size(); + } + +// end of file + + diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/MLCompData.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/MLCompData.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,1312 @@ +/* +* Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +#include "MLCompData.h" +#include "MLCompDataParse.h" +#include "MLCompData2Cdl.h" +#include "MLAttributes.h" + +#include "LayoutCompilerErr.h" +#include "CodeGenConsts.h" +#include "UsefulDefinitions.h" + +#include "Akndef.hrh" + +#include +#include +#include +#include + + +// +// const data +// + +const string KCompDataPaneOutputOrder[] = {"C", "l", "t", "r", "b", "W", "H"}; +const string KCompDataPaneOutputOrderMirrored[] = {"C", "r", "t", "l", "b", "W", "H"}; +const int KCompDataPaneOutputOrderSize = ARRAY_LEN(KCompDataPaneOutputOrder); + +const string KCompDataGraphicOutputOrder[] = {"NumCols", "NumRows", "C", "l", "t", "r", "b", "W", "H"}; +const string KCompDataGraphicOutputOrderMirrored[] = {"NumCols", "NumRows", "C", "r", "t", "l", "b", "W", "H"}; +const int KCompDataGraphicOutputOrderSize = ARRAY_LEN(KCompDataGraphicOutputOrder); + +const string KCompDataTextOutputOrder[] = {"NumCols", "NumRows", "C", "l", "t", "r", "b", "W", "H", "J", "Font"}; +const string KCompDataTextOutputOrderMirrored[] = {"NumCols", "NumRows", "C", "r", "t", "l", "b", "W", "H", "J", "Font"}; +const int KCompDataTextOutputOrderSize = ARRAY_LEN(KCompDataTextOutputOrder); + +const string KCompDataKeywordParamHeight = "H"; +const string KCompDataKeywordParamType = "Type"; +const string KCompDataKeywordParamFont = "Font"; +const string KCompDataKeywordParamNumCols = "NumCols"; +const string KCompDataKeywordParamNumRows = "NumRows"; +const string KCompDataKeywordScreenContents = "Screen Contents"; + +const string KCompDataKeywordUnderscore = "_"; +const string KCompDataKeywordLineNameSuffixGraphic = "g"; +const string KCompDataKeywordLineNameSuffixText = "t"; + +const string KCompDataSearchCollectionNumeric = "0123456789"; +const string KCompDataBadValue = "Bad Value"; +const string KCompDataLayoutEmpty = "ELayoutEmpty"; +const string KCompDataUnknown = "unknown"; + +const string KCompDataCellNameLeft("l"); +const string KCompDataCellNameRight("r"); +const string KCompDataCellNameJustification("J"); + +const string KAttributeNameStyle1 = "style_1"; +const string KAttributeNameStyle2 = "style_2"; +const string KAttributeNameStyle3 = "style_3"; +const string KAttributeNameStyle1Plain = "plain"; +const string KAttributeNameStyle1Bold = "bold"; +const string KAttributeNameStyle3Outline = "outline"; + +const string KAttributeNameNumberOfColumns = "Number_of_columns"; +const string KAttributeNameNumberOfRows = "Number_of_rows"; +const string KAttributeNameNumberOfRowsColsAuto = "AUTO"; + + +// +// TMLCompDataValues +// + +TMLCompDataValues::TMLCompDataValues() + : + iLine(NULL), + iName(KCompDataBadValue) + { + } + +TMLCompDataValues::TMLCompDataValues(TMLCompDataLine* aLine) + : + iLine(aLine), + iName(aLine->iName) + { + } + +bool TMLCompDataValues::operator==(const TMLCompDataValues& aOther) const + { + typedef const map TBase; + bool eq = + iName == aOther.iName && + (*static_cast(this) == aOther); + return eq; + } + +TMLCompDataValues::~TMLCompDataValues() + { + } + +bool TMLCompDataValues::Merge(TMLCompDataLine* aLine, string aName, TMLCompDataValues& aOtherValues, bool aMirrorMerge) + { + iLine = aLine; + iName = aName; // we may be swapping l and r + + // create missing values in this line if needed + for (iterator pOtherVal=aOtherValues.begin(); pOtherVal!=aOtherValues.end(); ++pOtherVal) + { + TMLCompDataZoomLevels& otherZoomLevels = pOtherVal->second; + TMLCompDataZoomLevels& thisZoomLevels = (*this)[pOtherVal->first]; + thisZoomLevels = otherZoomLevels; // we want exactly the correct number of calcs from the other cell + if(aMirrorMerge) + { + if(iName == KCompDataCellNameJustification) + { + // reverse the justification + for(TMLCompDataZoomLevels::iterator pCalcs = thisZoomLevels.begin(); pCalcs != thisZoomLevels.end(); ++pCalcs) + { + TMLCompDataCalcs& calcs = pCalcs->second; + for(TMLCompDataCalcs::iterator pVal = calcs.begin(); pVal != calcs.end(); ++pVal) + pVal->second = MirrorJustificationValue(pVal->second); + } + } + } + } + return true; + } + +const string KParamLimitNames[] = { "NumCols", "NumRows" }; +const string KHorizNames[] = { "l", "r", "W" }; +const string KVertNames[] = { "t", "b", "H", "Font" }; +const set KParamLimitNamesSet(KParamLimitNames, ARRAY_END(KParamLimitNames)); +const set KHorizNamesSet(KHorizNames, ARRAY_END(KHorizNames)); +const set KVertNamesSet(KVertNames, ARRAY_END(KVertNames)); + +TMLCompDataValues::TCompDataCellType TMLCompDataValues::Type(string aName) + { + TMLCompDataValues::TCompDataCellType type; + if(KParamLimitNamesSet.find(aName) != KParamLimitNamesSet.end()) + { + type = TMLCompDataValues::ECellTypeParamLimit; + } + else if(KHorizNamesSet.find(aName) != KHorizNamesSet.end()) + { + type = TMLCompDataValues::ECellTypeCol; + } + else if(KVertNamesSet.find(aName) != KVertNamesSet.end()) + { + type = TMLCompDataValues::ECellTypeRow; + } + else + { + type = TMLCompDataValues::ECellTypeDefault; + } + return type; + } + + +string TMLCompDataValues::MirrorJustificationValue(const string& aValue) + { + int val = CdlTkUtil::ParseInt(aValue); + if(val == ELayoutAlignLeft) + val = ELayoutAlignRight; + else if(val == ELayoutAlignRight) + val = ELayoutAlignLeft; + return CdlTkUtil::IntToString(val); + } + + +void TMLCompDataValues::Compile(const string& aCellName) + { + // ensure that missing varieties are filled with null values + // we assume that each variety is present in all zoom levels that are defined + if(iLine) // screen contents isn't contained in a line + { + int thisSize = size(); + int numVarieties = iLine->MaxVariety() + 1; // get zero based index + int maximum = max(numVarieties, thisSize); + int maxMulti; + switch(TMLCompDataValues::Type(aCellName)) + { + case ECellTypeCol: + maxMulti = iLine->NumCols(); + break; + case ECellTypeRow: + maxMulti = iLine->NumRows(); + break; + default: + maxMulti = 1; + break; + } + for(int ii = 0; ii < maximum; ii++) + { + // operator[] fills in missing values + TMLCompDataZoomLevels& zoomLevels = (*this)[ii]; + for(TMLCompDataZoomLevels::iterator pCalcs = zoomLevels.begin(); pCalcs != zoomLevels.end(); ++pCalcs) + { + TMLCompDataCalcs& calcs = pCalcs->second; + if(ii < numVarieties) + { + if(calcs.size() > maxMulti) + { + // Handle the case where data from a merged instance has too many calcs + TMLCompDataCalcs::iterator start = calcs.find(maxMulti); + TMLCompDataCalcs::iterator end = calcs.end(); + calcs.erase(start, end); + } + } + else + { + // get rid of varieties from instances that we have merged onto + calcs.clear(); + } + } + } + } + } + +string TMLCompDataValues::CppValue(const string& aValue) + { + if (aValue.size()) + return aValue; + else + return KCompDataLayoutEmpty; + } + +// +// TMLCompDataParentInfoSelector +// +TMLCompDataParentInfoSelector::TMLCompDataParentInfoSelector() + { + + } + +TMLCompDataParentInfoSelector::TMLCompDataParentInfoSelector(int aParentId, int aParentVariety) + : + iParentId(aParentId), + iParentVariety(aParentVariety) + { + + } + +// +// TMLCompDataParentInfo +// + +TMLCompDataParentInfo::TMLCompDataParentInfo() + : + iLine(0) + { + + } + +TMLCompDataParentInfo::TMLCompDataParentInfo(TMLCompDataLine* aLine) + : + iLine(aLine) + { + + } + +TMLCompDataParentInfo::~TMLCompDataParentInfo() + { + + } + +void TMLCompDataParentInfo::Merge(const TMLCompDataParentInfo& aOther) + { + for (const_iterator pOtherVariety = aOther.begin(); pOtherVariety != aOther.end(); ++pOtherVariety) + { + int varietyIndex = pOtherVariety->first; + const TMLCompDataParentInfoSelector& selector = pOtherVariety->second; + insert(make_pair(varietyIndex, selector)); + } + } + +// +// TMLCompDataLine +// + +TMLCompDataLine::TMLCompDataLine() +: iId(0), + iIsUnique(true), + iIsMirroredHorizontally(false), + iType(EUnknownComponent), + iName(KCompDataUnknown), + iDrawingOrder(-1), + iMaxVariety(0), + iParentTable(0), + iParentInfo(0), + iAttributeInfo(0), + iNumCols(1), + iNumRows(1), + iNeedsOptions(false), + iNeedsCols(false), + iNeedsRows(false), + iGlobalIndex(0) + { + + } + +TMLCompDataLine::TMLCompDataLine(const TMLCompDataLine& aOther) + { + if(this == &aOther) + return; + *this = aOther; // this will take a copy of the owning pointer + if(aOther.iParentInfo) // if it wasn't zero + iParentInfo = new TMLCompDataParentInfo(*(aOther.iParentInfo)); // we don't want to take ownership, so make our own copy + if(aOther.iAttributeInfo) // if it wasn't zero + iAttributeInfo = new TMLCompDataAttributeInfo(*(aOther.iAttributeInfo)); // we don't want to take ownership, so make our own copy + + for (iterator pVal = begin(); pVal != end(); ++pVal) + { + TMLCompDataValues& val = pVal->second; + val.iLine = this; + } + iParentTable = 0; // will be set during compile + } + +bool TMLCompDataLine::operator==(const TMLCompDataLine& aOther) const + { + return (Name() == aOther.Name()) && ValuesEqual(aOther); + } + +TMLCompDataLine::~TMLCompDataLine() + { + delete iParentInfo; + delete iAttributeInfo; + } + +bool TMLCompDataLine::lessthan(TMLCompDataLine* aLeft, TMLCompDataLine* aRight) + { + string pureNameLeft = aLeft->NameDiscountingSuffix(); + string pureNameRight = aRight->NameDiscountingSuffix(); + if(pureNameLeft != pureNameRight) + { + return (aLeft->iName) < (aRight->iName); + } + else + { + int left = CdlTkUtil::ParseInt(aLeft->NameSuffix()); + int right = CdlTkUtil::ParseInt(aRight->NameSuffix()); + return left < right; + } + } + +bool TMLCompDataLine::ValuesEqual(const TMLCompDataLine& aOther) const + { + bool eq = true; + const_iterator pVal, pOther; + for (pVal = begin(), pOther = aOther.begin(); + eq && pVal != end() && pOther != aOther.end(); + ++pVal, ++pOther) + { + eq = (*pVal == *pOther); + } + eq = eq && pVal == end() && pOther == aOther.end(); + return eq; + } + +string TMLCompDataLine::Name() const + { + return iName; + } + +bool TMLCompDataLine::Merge(TMLCompDataLine& aOtherLine) + { + bool compatible = + (iId == aOtherLine.iId) || + (iName == aOtherLine.iName) || + (iType == aOtherLine.iType); + if(compatible) + { + iDrawingOrder = aOtherLine.iDrawingOrder; + iMaxVariety = aOtherLine.iMaxVariety; + iIsMirroredHorizontally |= aOtherLine.iIsMirroredHorizontally; // in the case of an elaf layout merging onto an abrw layout, the chirality will be preserved + iNeedsOptions |= aOtherLine.iNeedsOptions; + + if(!iParentInfo) + { + // must be screen... + iParentInfo = new TMLCompDataParentInfo(); + } + if(aOtherLine.iParentInfo) + { + iParentInfo->Merge(*(aOtherLine.iParentInfo)); + } + + if(!iAttributeInfo) + { + // must be screen... + iAttributeInfo = new TMLCompDataAttributeInfo(); + } + if(aOtherLine.iAttributeInfo) + { + iAttributeInfo->Merge(*(aOtherLine.iAttributeInfo)); + } + + // for the API, we need to know if there are any multi-value components in either orientation + iNeedsCols = iNeedsCols || aOtherLine.iNeedsCols; + iNeedsRows = iNeedsRows || aOtherLine.iNeedsRows; + // however, we want exactly the correct number of calcs from the other cell + iNumCols = aOtherLine.iNumCols; + iNumRows = aOtherLine.iNumRows; + + // if this line has no values, then we must do a mirror merge + bool mirrorMerge = empty() && iIsMirroredHorizontally; + + // create missing values in this line if needed + for (TMLCompDataLine::iterator pOtherValues=aOtherLine.begin(); pOtherValues!=aOtherLine.end(); ++pOtherValues) + { + string index = pOtherValues->first; + if(mirrorMerge) + { + // flip left and right + if(index == KCompDataCellNameLeft) + index = KCompDataCellNameRight; + else if(index == KCompDataCellNameRight) + index = KCompDataCellNameLeft; + } + + (*this)[index].Merge(this, index, pOtherValues->second, mirrorMerge); + } + } + return compatible; + } + +TMLAttributeZoomLevels* TMLCompDataLine::GetAttributeZoomLevels(string aAttribName, int aVariety) + { + TMLAttributeZoomLevels* found = 0; + TMLCompData& data = *(iParentTable->iTables); + TMLAttributes& attributes = *(data.iAttributes); + int attribId = attributes.iNames[aAttribName]; + if(attribId == 0) + throw GeneralErr(string("Attribute name not found: ") + aAttribName); + // find out from attribute info which attribute set we need + // but if there is none specified, we don't need to search + if(iAttributeInfo) + { + TMLCompDataAttributeInfoSelector& selector = (*iAttributeInfo)[aVariety]; + // go to parent straight away, as parent always stores attribute data for its children + found = GetParentAttributeZoomLevels(selector.iAttributeSetName, attribId, aVariety); + } + return found; + } + +TMLAttributeZoomLevels* TMLCompDataLine::GetParentAttributeZoomLevels(string aAttribSetName, int aAttribId, int aVariety) + { + TMLAttributeZoomLevels* found = NULL; + TMLCompDataParentInfo::iterator pFoundSelector = iParentInfo->find(aVariety); + if(pFoundSelector != iParentInfo->end()) + { + const TMLCompDataParentInfoSelector& parentInfoSelector = pFoundSelector->second; + if(iParentTable && iParentTable->iParentLine) + { + found = iParentTable->iParentLine->FindAttributeZoomLevels(aAttribSetName, aAttribId); + if(!found) + { + // recurse to next parent container + int variety = parentInfoSelector.iParentVariety; + iParentTable->iParentLine->GetParentAttributeZoomLevels(aAttribSetName, aAttribId, variety); + } + } + } + return found; + } + +TMLAttributeZoomLevels* TMLCompDataLine::FindAttributeZoomLevels(string aAttribSetName, int aAttribId) + { + TMLCompData& data = *(iParentTable->iTables); + TMLAttributes& attributes = *(data.iAttributes); + int id = iId; + TMLAttributes::iterator foundAttributeSetComponent = attributes.find(id); + if(foundAttributeSetComponent != attributes.end()) + { + TMLAttributeSetComponent& component = foundAttributeSetComponent->second; + TMLAttributeSet* pSet = component[aAttribSetName]; + if(pSet) + { + TMLAttributeSet& attributeSet = *pSet; + TMLAttributeSet::iterator foundAttrib = attributeSet.find(aAttribId); + if(foundAttrib != attributeSet.end()) + { + return &(foundAttrib->second); + } + } + } + return NULL; + } + +void TMLCompDataLine::Compile() + { + // compile values + for(iterator pVal = begin(); pVal != end(); ++pVal) + { + (pVal->second).Compile(pVal->first); + } + CompileParamLimits(TMLCompDataValues::ECellTypeCol, KCompDataKeywordParamNumCols); + CompileParamLimits(TMLCompDataValues::ECellTypeRow, KCompDataKeywordParamNumRows); + CompileFontHeights(); + } + +void TMLCompDataLine::CompileParamLimits(TMLCompDataValues::TCompDataCellType aParamLimitType, const string& aParamLimitCellName) + { + TMLCompDataValues paramLimits(this); + + for(iterator pValues = begin(); pValues != end(); ++pValues) + { + string cellName = pValues->first; + if(TMLCompDataValues::Type(cellName) == aParamLimitType) + { + // calculate the param limits for this cell + TMLCompDataValues& values = pValues->second; + for(TMLCompDataValues::iterator pZoomLevels = values.begin(); pZoomLevels != values.end(); ++pZoomLevels) + { + int nextVariety = pZoomLevels->first; + TMLCompDataZoomLevels& zoomLevels = pZoomLevels->second; + TMLCompDataZoomLevels& paramLimitsZoomLevels = paramLimits[nextVariety]; + for(TMLCompDataZoomLevels::iterator pCalcs = zoomLevels.begin(); pCalcs != zoomLevels.end(); ++pCalcs) + { + // accumulate the largest size of calc into the param limit + int zoomLevel = pCalcs->first; + int nextParamLimit = pCalcs->second.size(); + TMLCompDataCalcs& paramLimitCalcs = paramLimitsZoomLevels[zoomLevel]; + string& paramLimit = paramLimitCalcs[0]; + int currentParamLimit = CdlTkUtil::ParseInt(paramLimit); + if(nextParamLimit > currentParamLimit) + paramLimit = CdlTkUtil::IntToString(nextParamLimit); + } + if(!paramLimitsZoomLevels.size()) + { + // there were no defined values for this variety, but we know we'll + // insert an empty value at least + TMLCompDataCalcs& paramLimitCalcs = paramLimitsZoomLevels[EAknUiZoomNormal]; + paramLimitCalcs.insert(make_pair(0, CdlTkUtil::IntToString(1))); + } + } + } + } + insert(make_pair(aParamLimitCellName, paramLimits)); + } + +void TMLCompDataLine::CompileFontHeights() + { + if(iType == ETextComponent) + { + TMLCompDataValues font(this); + + TMLCompDataValues types = (*this)[KCompDataKeywordParamType]; + TMLCompDataValues heights = (*this)[KCompDataKeywordParamHeight]; + + // note that these are the number of varieties, there may be zoom level and then rows inside + int numTypeVarieties = types.size(); + int numHeightVarieties = heights.size(); + + for(TMLCompDataValues::iterator pZoomLevels = heights.begin(); pZoomLevels != heights.end(); ++pZoomLevels) + { + int nextVariety = pZoomLevels->first; + TMLAttributeZoomLevels* style1ZoomLevels = GetAttributeZoomLevels(KAttributeNameStyle1, nextVariety); + TMLAttributeZoomLevels* style3ZoomLevels = GetAttributeZoomLevels(KAttributeNameStyle3, nextVariety); + TMLCompDataZoomLevels& heightsZoomLevels = pZoomLevels->second; + TMLCompDataZoomLevels& typesZoomLevels = types[nextVariety]; + TMLCompDataZoomLevels& fontZoomLevels = font[nextVariety]; + + for(TMLCompDataZoomLevels::iterator pHeightCalcs = heightsZoomLevels.begin(); pHeightCalcs != heightsZoomLevels.end(); ++pHeightCalcs) + { + // if the types don't have zoom data, fall back to normal zoom + int zoomIndex = pHeightCalcs->first; + int numTypesZoomLevels = typesZoomLevels.size(); + int typeZoomIndex = numTypesZoomLevels > 1 ? zoomIndex : EAknUiZoomNormal; + TMLCompDataCalcs& typeCalcs = typesZoomLevels[typeZoomIndex]; + + // get attribute data + int outline = 0; + int posture = 0; + int weight = 0; + if(style1ZoomLevels) + { + string style1 = (*style1ZoomLevels)[pHeightCalcs->first]; + if(style1 == KAttributeNameStyle1Bold) + weight = 1; + } + if(style3ZoomLevels) + { + string style3 = (*style3ZoomLevels)[pHeightCalcs->first]; + if(style3 == KAttributeNameStyle3Outline) + outline = 1; + } + + // we want to have a font id for each height, even if the spec + // has not specified the type each time + TMLCompDataCalcs& fontCalcs = fontZoomLevels[pHeightCalcs->first]; + TMLCompDataCalcs& next = pHeightCalcs->second; + for(TMLCompDataCalcs::iterator pHeightCalc = next.begin(); pHeightCalc != next.end(); ++pHeightCalc) + { + // for undefined type, let font provider use default, + // and always choose the first type for a multi value item + int calcIndex = pHeightCalc->first; + int type = numTypeVarieties > 0 ? CdlTkUtil::ParseInt(typeCalcs[0]) : ELayoutCompilerFontCategoryUndefined; + int height = numHeightVarieties > 0 ? CdlTkUtil::ParseInt(pHeightCalc->second) : 0; + int fontId = EncodeFontId(height, outline, posture, weight, type); + fontCalcs[calcIndex] = CdlTkUtil::IntToString(fontId); + } + } + } + insert(make_pair(string(KCompDataKeywordParamFont), font)); + } + } + +int TMLCompDataLine::EncodeFontId(int aHeight, int aOutline, int aPosture, int aWeight, int aCategory) const + { + // + // 31 | 30 - 21 | 20 - 07 | 06 | 05 | 04 | 03 - 00 + // encoded | text pane height 0-1023 | | outline | posture | weight | category + + int encodedMasked = 1 << 31; + int heightMasked = aHeight << 21; + + int outlineMasked = aOutline << 6; + int postureMasked = aPosture << 5; + int weightMasked = aWeight << 4; + int categoryMasked = aCategory; + + return(encodedMasked | heightMasked | outlineMasked | postureMasked | weightMasked | categoryMasked); + } + +bool TMLCompDataLine::MatchParams(const TMLCompDataLine& aLine) const + { + if (NeedsOptions() != aLine.NeedsOptions()) + return false; + if (NeedsCols() != aLine.NeedsCols()) + return false; + if (NeedsRows() != aLine.NeedsRows()) + return false; + return true; + } + +bool TMLCompDataLine::MatchNameDiscountingSuffix(const TMLCompDataLine& aLine) const + { + // we are trying to compare whether the names are the same apart from a trailing number + string pureName = NameDiscountingSuffix(); + string pureNameOther = aLine.NameDiscountingSuffix(); + string ending = pureName.substr(pureName.find_last_not_of(KCompDataKeywordUnderscore)); + + bool namesMatch = (pureName == pureNameOther); + bool correctEnding = (ending == KCompDataKeywordLineNameSuffixGraphic || ending == KCompDataKeywordLineNameSuffixText); + return (namesMatch && correctEnding); + } + +bool TMLCompDataLine::MatchType(const TMLCompDataLine& aLine) const + { + // first check that the type is equivalent + bool equivalent = false; + switch(iType) + { + case ETextComponent: + { + if(aLine.iType == ETextComponent) + { + equivalent = true; + } + break; + } + case EScreenComponent: + case EContainerComponent: + case EPaneComponent: + case EGraphicComponent: + { + if(aLine.iType == EScreenComponent + || aLine.iType == EContainerComponent + || aLine.iType == EPaneComponent + || aLine.iType == EGraphicComponent) + { + equivalent = true; + } + break; + } + case EUnknownComponent: + default: + { + if(aLine.iType == EUnknownComponent) + { + equivalent = true; + } + break; + } + } + + return equivalent; + } + +string TMLCompDataLine::NameDiscountingSuffix() const + { + int lastNonNumericPos = iName.find_last_not_of(KCompDataSearchCollectionNumeric); + int length = lastNonNumericPos + 1; + return iName.substr(0, length); + } + +string TMLCompDataLine::NameSuffix() const + { + int lastNonNumericPos = iName.find_last_not_of(KCompDataSearchCollectionNumeric); + int suffixPos = lastNonNumericPos + 1; + return iName.substr(suffixPos); + } + +bool TMLCompDataLine::NeedsParams() const + { + return iNeedsOptions || iNeedsCols || iNeedsRows; + } + +bool TMLCompDataLine::NeedsOptions() const + { + return iNeedsOptions; + } + +bool TMLCompDataLine::NeedsCols() const + { + return iNeedsCols; + } + +bool TMLCompDataLine::NeedsRows() const + { + return iNeedsRows; + } + +int TMLCompDataLine::MaxVariety() const + { + return iMaxVariety; + } + +int TMLCompDataLine::NumCols() const + { + return iNumCols; + } + +int TMLCompDataLine::NumRows() const + { + return iNumRows; + } + + +void TMLCompDataLine::SetMaxVariety(int aMaxVariety) + { + iMaxVariety = aMaxVariety; + if(iMaxVariety > 0) // zero based + iNeedsOptions = true; + } + +void TMLCompDataLine::SetNumCols(int aNumCols) + { + iNumCols = aNumCols; + if(iNumCols > 1) + iNeedsCols = true; + } + +void TMLCompDataLine::SetNumRows(int aNumRows) + { + iNumRows = aNumRows; + if(iNumRows > 1) + iNeedsRows = true; + } + +void TMLCompDataLine::SetNeedsCols(bool aNeeds) + { + iNeedsCols = aNeeds; + } + +void TMLCompDataLine::SetNeedsRows(bool aNeeds) + { + iNeedsRows = aNeeds; + } + +// +// TMLCompDataAttributeInfoSelector +// +TMLCompDataAttributeInfoSelector::TMLCompDataAttributeInfoSelector() + { + + } + +TMLCompDataAttributeInfoSelector::TMLCompDataAttributeInfoSelector(string aAttributeSetName) + : + iAttributeSetName(aAttributeSetName) + { + + } + +// +// TMLCompDataAttributeInfo +// + +TMLCompDataAttributeInfo::TMLCompDataAttributeInfo() + : + iLine(0) + { + + } + +TMLCompDataAttributeInfo::TMLCompDataAttributeInfo(TMLCompDataLine* aLine) + : + iLine(aLine) + { + + } + +TMLCompDataAttributeInfo::~TMLCompDataAttributeInfo() + { + + } + +void TMLCompDataAttributeInfo::Merge(const TMLCompDataAttributeInfo& aOther) + { + for (const_iterator pOtherVariety = aOther.begin(); pOtherVariety != aOther.end(); ++pOtherVariety) + { + int varietyIndex = pOtherVariety->first; + const TMLCompDataAttributeInfoSelector& selector = pOtherVariety->second; + insert(make_pair(varietyIndex, selector)); + } + } + + + +// +// TMLCompDataTable::TMLCompDataSubTable +// + +bool TMLCompDataTable::TMLCompDataSubTable::NeedsParams() const + { + return iNeedsOption || iNeedsCol || iNeedsRow; + } + + +// +// TMLCompDataTable +// + +TMLCompDataTable::TMLCompDataTable(TMLCompData* aTables) + : + iTables(aTables), + iParentLine(NULL), + iFirstLineGlobalIndex(-1), + iAppend(false), + iId(0), + iNeedsP(false), + iNeedsIndex(false) + { + } + +TMLCompDataTable::TMLCompDataTable(TMLCompData* aTables, const TMLCompDataTable& aOther) + : + iTables(aTables), + iParentLine(NULL), + iFirstLineGlobalIndex(aOther.iFirstLineGlobalIndex), + iAppend(aOther.iAppend), iColumnNames(aOther.iColumnNames), iName(aOther.iName), + iParentName(aOther.iParentName), + iId(aOther.iId) + { + for (const_iterator pLine = aOther.begin(); pLine != aOther.end(); ++pLine) + push_back(new TMLCompDataLine(**pLine)); + } + +TMLCompDataTable::~TMLCompDataTable() + { + for (iterator pLine = begin(); pLine != end(); ++pLine) + delete *pLine; + } + +bool TMLCompDataTable::lessthan(TMLCompDataTable* aLeft, TMLCompDataTable* aRight) + { + return (aLeft->iId) < (aRight->iId); + } + +string TMLCompDataTable::Name() + { + return iName; + } + +TMLCompDataLine* TMLCompDataTable::FindLine(const string& aName) + { + for (iterator pLine = begin(); pLine != end(); ++pLine) + { + TMLCompDataLine& line = **pLine; + string paramLimitsName = MLCompDataToCdl::LineParamLimitsApiName(line); + // first check the lines for a direct match + // then try the param limits instead + if (line.Name() == aName || + (line.NeedsParams() && paramLimitsName == aName)) + return *pLine; + } + return 0; + } + +TMLCompDataTable::TMLCompDataSubTable* TMLCompDataTable::FindSubTable(const string& aName) + { + for(TMLCompDataSubTables::iterator pSub = iSubTables.begin(); pSub != iSubTables.end(); ++pSub) + { + TMLCompDataSubTable& sub = **pSub; + string subTableName = MLCompDataToCdl::SubTableApiName(sub); + string subTableLimitsName = MLCompDataToCdl::SubTableLimitsApiName(sub); + string paramLimitsName = MLCompDataToCdl::SubTableParamLimtsApiName(sub); + TMLCompDataLine& line = *((*this)[0]); + // first check the lines for a direct match + // then try the param limits instead + if (subTableName == aName || + subTableLimitsName == aName || + (sub.NeedsParams() && paramLimitsName == aName)) // need to check whether the subtable needs params + return ⊂ + } + return 0; + } + +void TMLCompDataTable::Merge(TMLCompDataTable& aOther) + { + for (iterator pOtherLine = aOther.begin(); pOtherLine != aOther.end(); ) + { + TMLCompDataLine* found = FindLine((*pOtherLine)->Name()); + if(found) + { + found->Merge(**pOtherLine); + delete *pOtherLine; + pOtherLine = aOther.erase(pOtherLine); + } + else + { + push_back(*pOtherLine); + (*pOtherLine)->iParentTable = this; + pOtherLine = aOther.erase(pOtherLine); + } + } + } + + +void TMLCompDataTable::Compile() + { + SetDefaultColumnNames(); + sort(begin(), end(), TMLCompDataLine::lessthan); + + iNeedsIndex = false; + iNeedsP = false; + for (iterator pLine = begin(); pLine != end(); ++pLine) + { + (*pLine)->Compile(); + } + BuildSubTables(); + NormalizeSubTables(); + } + +void TMLCompDataTable::BuildSubTables() + { + DestroySubTables(); + + int count = size(); + if(count > 0) + { + TMLCompDataSubTable* subTable = 0; + for (int i=0; iNameSuffix() == "1" && firstLine->MatchNameDiscountingSuffix(line) && firstLine->MatchType(line)) + { + subTable->iName = line.NameDiscountingSuffix(); + } + else // only terminate the subtable if the lines don't match, or if the first line isn't numbered "1" + { + if (subTable->size() > 1) + iSubTables.push_back(subTable); + else + delete subTable; + subTable = new TMLCompDataSubTable; + } + } + else + { + subTable = new TMLCompDataSubTable; + } + subTable->iNeedsOption |= line.NeedsOptions(); + subTable->iNeedsCol |= line.NeedsCols(); + subTable->iNeedsRow |= line.NeedsRows(); + subTable->push_back(i); + } + + if (subTable->size() > 1) + { + iSubTables.push_back(subTable); + } + else + delete subTable; + } + } + +void TMLCompDataTable::NormalizeSubTables() + { + for(TMLCompDataSubTables::iterator pSub = iSubTables.begin(); pSub != iSubTables.end(); ++pSub) + { + TMLCompDataSubTable& sub = **pSub; + for(TMLCompDataSubTable::iterator pLineId = sub.begin(); pLineId != sub.end(); ++pLineId) + { + TMLCompDataLine& line = *((*this)[*pLineId]); + + line.iNeedsOptions |= sub.iNeedsOption; + line.iNeedsCols |= sub.iNeedsCol; + line.iNeedsRows |= sub.iNeedsRow; + } + } + } + + +void TMLCompDataTable::DestroySubTables() + { + for (TMLCompDataSubTables::iterator pSub = iSubTables.begin(); pSub != iSubTables.end(); ++pSub) + delete *pSub; + iSubTables.clear(); + } + + +const string KValueNames[] = { "Font", "C", "l", "r", "W", "J", "t", "r", "b", "H" }; +const set KValueNamesSet(KValueNames, ARRAY_END(KValueNames)); + +bool TMLCompDataTable::IsValueColumn(string aName) + { + return KValueNamesSet.find(aName) != KValueNamesSet.end(); + } + +const string KNumericNames[] = { "C", "l", "r", "W", "t", "r", "b", "H" }; +const set KNumericNamesSet(KNumericNames, ARRAY_END(KNumericNames)); + +bool TMLCompDataTable::IsNumericColumn(string aName) + { + return KNumericNamesSet.find(aName) != KNumericNamesSet.end(); + } + +const string KHorizontalColumnNames[] = { "l", "r", "W"}; +const set KHorizontalNamesSet(KHorizontalColumnNames, ARRAY_END(KHorizontalColumnNames)); + +bool TMLCompDataTable::IsHorizontalColumn(string aName) + { + return KHorizontalNamesSet.find(aName) != KHorizontalNamesSet.end(); + } + +const string KVerticalColumnNames[] = {"t", "b", "H" }; +const set KVerticalNamesSet(KVerticalColumnNames, ARRAY_END(KVerticalColumnNames)); + +bool TMLCompDataTable::IsVerticalColumn(string aName) + { + return KVerticalNamesSet.find(aName) != KVerticalNamesSet.end(); + } + + +const string KPaneColumnNames[] = {"Item", "C", "l", "t", "r", "b", "W", "H", "Remarks"}; +const string KGraphicColumnNames[] = {"Item", "C", "l", "t", "r", "b", "W", "H", "Remarks"}; +const string KTextColumnNames[] = {"Font", "C", "l", "r", "t", "b", "W", "H", "J", "Remarks"}; + +void TMLCompDataTable::SetDefaultColumnNames() + { + iColumnNames.clear(); + iColumnNames.insert(iColumnNames.end(), KPaneColumnNames, ARRAY_END(KTextColumnNames)); // superset + } + +TMLCompDataTable::TMLCompDataSubTable::TMLCompDataSubTable() +: + iNeedsOption(false), + iNeedsCol(false), + iNeedsRow(false) + { + } + + +// +// TMLCompData +// + +TMLCompData::TMLCompData() + : + iCanBeMirror(false), + iIsBaseInstance(false), + iAttributes(0) + { + } + +TMLCompData::TMLCompData(const TMLCompData& aOther) + { + *this = aOther; + } + +TMLCompData& TMLCompData::operator=(const TMLCompData& aOther) + { + if (this != &aOther) + { + iName = aOther.iName; + iCanBeMirror = aOther.iCanBeMirror; + for (const_iterator pTab = aOther.begin(); pTab != aOther.end(); ++pTab) + push_back(new TMLCompDataTable(this, **pTab)); + Compile(); + } + return *this; + } + +TMLCompData::~TMLCompData() + { + for (iterator pTab = begin(); pTab != end(); ++pTab) + delete *pTab; + DeleteComponents(); + delete iAttributes; + } + +TMLCompDataLine* TMLCompData::FindComponent(const string& aName) const + { + for (TMLComponents::const_iterator pComp = iComponents.begin(); pComp != iComponents.end(); ++pComp) + { + TMLCompDataLine* line = pComp->second; + if (line->Name() == aName) + return line; + } + + return 0; + } + +TMLCompDataLine* TMLCompData::FindLine(const string& aName) const + { + for (const_iterator pTab = begin(); pTab != end(); ++pTab) + { + TMLCompDataLine* line = (*pTab)->FindLine(aName); + if (line) + return line; + } + + return 0; + } + +TMLCompDataTable* TMLCompData::FindTable(const string& aName) const + { + for (const_iterator pTab = begin(); pTab != end(); ++pTab) + { + if ((*pTab)->Name() == aName) + return *pTab; + } + + return 0; + } + +TMLCompDataTable* TMLCompData::FindTable(int aId) const + { + for (const_iterator pTab = begin(); pTab != end(); ++pTab) + { + if ((*pTab)->iId == aId) + return *pTab; + } + + return 0; + } + +TMLCompDataTable::TMLCompDataSubTable* TMLCompData::FindSubTable(const string& aName) const + { + for (const_iterator pTab = begin(); pTab != end(); ++pTab) + { + TMLCompDataTable::TMLCompDataSubTable* sub = (*pTab)->FindSubTable(aName); + if (sub) + return sub; + } + + return 0; + } + + +void TMLCompData::Merge(TMLCompData& aOther) + { + iName = aOther.iName; + iCanBeMirror |= aOther.iCanBeMirror; // in the case of an elaf layout merging onto an abrw layout, the chirality will be preserved + MergeComponents(aOther); + } + +void TMLCompData::MergeComponents(TMLCompData& aOther) + { + for (TMLComponents::iterator pOtherLine = aOther.iComponents.begin(); pOtherLine != aOther.iComponents.end(); ++pOtherLine) + { + TMLCompDataLine& otherLine = *(pOtherLine->second); + TMLCompDataLine* found = FindComponent(otherLine.iName); + if(found) + { + found->Merge(otherLine); + } + else + { + TMLCompDataLine* newLine = new TMLCompDataLine(otherLine); + iComponents.insert(make_pair(otherLine.iId, newLine)); + } + } + } + +void TMLCompData::Compile() + { + CreateTables(); + + // now add a special table for the screen contents + TMLCompDataTable* topTab = new TMLCompDataTable(this); + topTab->iId = -1; + topTab->iName = KCompDataKeywordScreenContents; + + // then insert each line into its parent + for (TMLComponents::iterator pComp2 = iComponents.begin(); pComp2 != iComponents.end(); ++pComp2) + { + TMLCompDataLine& line = *(pComp2->second); + if(line.iType == TMLCompDataLine::EScreenComponent) + { + line.iParentTable = topTab; + topTab->push_back(&line); + } + else + { + bool parentFound = false; + int parentId = 0; + if(line.iParentInfo) + { + TMLCompDataParentInfo& parentInfo = *(line.iParentInfo); + TMLCompDataParentInfoSelector& selector = (parentInfo.begin())->second; // we ignore the varieties for now + parentId = selector.iParentId; + TMLCompDataTable* parentTable = FindTable(parentId); + TMLCompDataLine* parentLine = iComponents[parentId]; + if(parentTable) + { + line.iParentTable = parentTable; + // copy the pointer from the components table + parentTable->push_back(&line); + parentFound = true; + // now insert the table into its place in the tree + parentTable->iParentLine = iComponents[parentId]; + } + else + { + parentFound = false; + } + } + if(!parentFound) + { + string errorText = string(" TMLCompData::Compile() - can't find parent component: "); + errorText += CdlTkUtil::IntToString(parentId); + throw GeneralErr(errorText); + } + } + } + push_back(topTab); + + // remember not to delete the components, as we have taken copies! + iComponents.clear(); + + // now compile the tables + iterator pTab; + for (pTab = begin(); pTab != end(); ++pTab) + (*pTab)->Compile(); + + // now sort the tables + sort(begin(), end(), TMLCompDataTable::lessthan); + } + +void TMLCompData::CreateTables() + { + // from the list of components, first create a table for each pane + for (TMLComponents::iterator pComp = iComponents.begin(); pComp != iComponents.end(); ++pComp) + { + TMLCompDataLine& line = *(pComp->second); + switch(line.iType) + { + case TMLCompDataLine::EScreenComponent: + case TMLCompDataLine::EContainerComponent: + case TMLCompDataLine::EPaneComponent: + { + TMLCompDataTable* tab = new TMLCompDataTable(this); + tab->iId = line.iId; + tab->iName = line.iName; + push_back(tab); + break; + } + case TMLCompDataLine::EGraphicComponent: + case TMLCompDataLine::ETextComponent: + { + // text and graphic components are not panes + // and are therefore not represented in our internal object model as tables + break; + } + default: + { + cout << "TMLCompData::CreateTables() - uncategorised component\n"; + break; + } + } + } + } + +void TMLCompData::DeleteComponents() + { + for (TMLComponents::iterator pComp = iComponents.begin(); pComp != iComponents.end(); ++pComp) + delete pComp->second; + } + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/MLCompData2Cdl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/MLCompData2Cdl.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,546 @@ +/* +* Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +#include "MLCompData2Cdl.h" +#include "MLCompDataParse.h" +#include "MLAttributesParse.h" +#include "LayoutCompilerErr.h" +#include +#include +#include +#include +#include "CppWriter.h" +#include "CodeGenConsts.h" + +using namespace std; + +typedef LayoutProcessArgsErr MLCompDataToCdlArgsErr; + +// constants + +const int KGeneratedInterfaceMajorVer = 1; +const int KGeneratedInterfaceMinorVer = 0; + +const string KCompDataFileNameSuffix("compData"); +const string KAttributesFileNameSuffix("attributes"); + + +// +// MLCompDataToCdl +// +MLCompDataToCdl::CApiNamesUsed MLCompDataToCdl::iInterfaceNamesUsed; + +string MLCompDataToCdl::InterfaceName(const string& aFileName) + { + return aFileName.substr(0,aFileName.find_last_of('.')); + } + +int MLCompDataToCdl::Process(const vector& args) + { + iInterfaceNamesUsed.clear(); + + int numExpectedArgs = 4; + if(args.size() < numExpectedArgs) + throw MLCompDataToCdlArgsErr(); + + int arg = 2; + bool deletesAllowed = true; + if (args[arg] == "-nodeletes") + { + deletesAllowed = false; + arg++; + numExpectedArgs++; + } + + bool allParams = false; + if (args[arg] == "-allparams") + { + allParams = true; + arg++; + numExpectedArgs++; + } + + bool romOnly = false; + if (args[arg] == "-romonly") + { + romOnly = true; + arg++; + numExpectedArgs++; + } + + int numLayouts = args.size() - numExpectedArgs; + if (numLayouts < 1) + throw MLCompDataToCdlArgsErr(); + + TMLCompData* mergedLayout = NULL; + TMLAttributes* mergedAttribs = NULL; + for(int ii = 0; ii < numLayouts; ii++) + { + string layoutName = args[arg++]; + string attribsName = CdlTkUtil::Replace(KCompDataFileNameSuffix, KAttributesFileNameSuffix, layoutName); + + auto_ptr layoutParse = TMLCompDataParseLayout::Parse(layoutName); + auto_ptr layout(layoutParse.get()); + layoutParse.release(); + + auto_ptr attribsParse = TMLAttributesParse::Parse(attribsName); + auto_ptr attribs(attribsParse.get()); + attribsParse.release(); + + if (mergedLayout || mergedAttribs) + { + // first we merge the components and the attributes + mergedLayout->MergeComponents(*layout); + mergedAttribs->Merge(*attribs); + } + else + { + // first time around + mergedLayout = layout.get(); + mergedAttribs = attribs.get(); + } + layout.release(); + attribs.release(); + } + + mergedLayout->iAttributes = mergedAttribs; // transfer ownership + + // once merged, we can compile the tables + mergedLayout->Compile(); + + string cdlName = args[arg++]; + int uid = CdlTkUtil::ParseInt(args[arg++]); + + auto_ptr iface(new CCdlTkInterface); + CCdlTkCdlFileParser parser(cdlName); + try + { + iface = parser.LoadAndParse(true); + } + catch (const CdlTkFileOpenErr& aErr) + { + // there was no file, so presume that we are creating a new interface. + aErr.Show(cerr); + cout << "Creating new CDL API from scratch." << endl; + } + + LayoutToInterface(*iface, *mergedLayout, deletesAllowed, allParams); + + stringstream comment; + comment << "// Generated from "; + + // ignore the args up to and including the app name, the mode name, and the optional flags, + arg = numExpectedArgs-2; + + // so that we get a list of processed files to output to the comment + for(ii = 0; ii < numLayouts; ii++) + comment << args[arg++] << ", "; + comment << endl; + comment << "// which was generated with timestamp " << mergedLayout->iTimestamp << endl; + + SetHeaders(*iface, cdlName, comment.str(), uid, romOnly); + + CCdlTkWriteCdlFile writer(*iface); + cout << "writing CDL file " << cdlName << endl; + writer.Process(); + + iInterfaceNamesUsed.clear(); + return 0; + } + +void MLCompDataToCdl::ShowHelp(ostream& stream) + { + stream << "MLCompData2Cdl [-nodeletes] [-allparams] [-romonly] ()+ " << endl; + stream << " If the CDL file does not exist, writes out the API in the order of the MLCompData." << endl; + stream << " If the CDL file does exist, and -nodeletes is not used, fills holes and appends new APIs to the end, to preseve API compatibility." << endl; + stream << " If the CDL file does exist, and -nodeletes is used, processing will halt and report an error if any of the existing APIs are missing." << endl; + stream << " If the CDL file does exist, existing APIs that do not have required params will be updated, appending missing params with default values." << endl; + stream << " If -allparams is used, all processed APIs will have all available params added, otherwise only needed params are added." << endl; + stream << " If -romonly is used, and if there is a previous CDL API it did not include the KCdlFlagRomOnly flag, then the flag will be added to the updated API." << endl; + stream << " If more than one layout is supplied, they are merged together, and then the interface of the merged data is generated. " << endl; + stream << " e.g. from \\S60\\AknLayout2\\group run " << endl; + stream << " aknlayoutcompiler MLCompData2CDL -nodeletes ..\\xml\\pdp_av_dbl_prt\\display_eur_compData.xml ..\\xml\\pdl_av_dbl_lsc\\display_eur_compData.xml ..\\cdl\\AknLayoutScalable_Avkon.cdl 0x1020384E" << endl; + stream << " aknlayoutcompiler MLCompData2CDL -nodeletes ..\\xml\\pdp_apps_dbl_prt\\display_eur_compData.xml ..\\xml\\pdl_apps_dbl_lsc\\display_eur_compData.xml ..\\cdl\\AknLayoutScalable_Apps.cdl 0x1020384F" << endl; + } + +void MLCompDataToCdl::LayoutToInterface(CCdlTkInterface& aInterface, const TMLCompData& aLayout, bool aDeletesAllowed, bool aAllParams) + { + const bool needsOptions = true; + const bool needsColsRows = true; + const bool doesntNeedOptions = false; + const bool doesntNeedColsRows = false; + + AddGenericApiToInterface(aInterface, KTypeLayoutScalableComponentType, KFuncGetComponentTypeById, doesntNeedOptions, doesntNeedColsRows); + AddGenericApiToInterface(aInterface, KTypeLayoutScalableParameterLimits, KFuncGetParamLimitsById, needsOptions, doesntNeedColsRows); + AddGenericApiToInterface(aInterface, KTypeWindowComponentLayout, KFuncGetWindowComponentById, needsOptions, needsColsRows); + AddGenericApiToInterface(aInterface, KTypeTextComponentLayout, KFuncGetTextComponentById, needsOptions, needsColsRows); + + for (TMLCompData::const_iterator pTab = aLayout.begin(); pTab != aLayout.end(); ++pTab) + { + AddTableToInterface(aInterface, **pTab, aAllParams); + } + ReplaceRemovedAPIs(aInterface, aLayout, aDeletesAllowed); + CleanUpAPIComments(aInterface); + } + +void MLCompDataToCdl::AddGenericApiToInterface(CCdlTkInterface& aInterface, const string& aReturnType, const string& aName, bool aNeedsOptions, bool aRequiresColsRows) + { + bool isNew = false; + const bool needsComponentId = true; + const bool doesntNeedAllParams = false; + CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, aReturnType, aName, isNew); + + CCdlTkApiParams& params = funcApi->Params(); + CCdlTkApiParams oldParams = params; + UpdateParams(oldParams, params, aName, doesntNeedAllParams, aRequiresColsRows, isNew, needsComponentId, aNeedsOptions, aRequiresColsRows, aRequiresColsRows); + + funcApi->SetComment(string("// Generic API\n")); + } + +void MLCompDataToCdl::AddTableToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, bool aAllParams) + { + int line = 0; + for (TMLCompDataTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) + { + // only add parameter limits if the line is not simple + bool needsParamLimits = (*pLine)->NeedsOptions() || (*pLine)->NeedsCols() || (*pLine)->NeedsRows(); + if(needsParamLimits) + { + AddParamLimitsToInterface(aInterface, **pLine, aAllParams); + } + AddLineToInterface(aInterface, **pLine, aAllParams); + + for (TMLCompDataTable::TMLCompDataSubTables::const_iterator pSub = aTable.iSubTables.begin(); pSub != aTable.iSubTables.end(); ++pSub) + { + TMLCompDataTable::TMLCompDataSubTable& sub = **pSub; + int last = *(sub.rbegin()); + if(line == last) + { + AddSubTableLimitsToInterface(aInterface, aTable, sub); + if(needsParamLimits) + AddSubTableParamLimitsToInterface(aInterface, aTable, sub, aAllParams); + AddSubTableToInterface(aInterface, aTable, sub, aAllParams); + } + } + + line++; + } + } + +void MLCompDataToCdl::AddTableCommentToApi(TMLCompDataTable& aTable, CCdlTkApi& aApi) + { + aApi.SetComment(string("// LAF Table : ") + aTable.Name() + "\n"); + } + +void MLCompDataToCdl::AddTableCommentToApi(TMLCompDataLine& aLine, CCdlTkApi& aApi) + { + if(aLine.iParentTable) + { + TMLCompDataTable& table = *(aLine.iParentTable); + AddTableCommentToApi(table, aApi); + } + } + +void MLCompDataToCdl::AddLineToInterface(CCdlTkInterface& aInterface, TMLCompDataLine& aLine, bool aAllParams) + { + bool isNew = false; + const bool requiresColsRows = true; + CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, ReturnType(aLine), LineApiName(aLine), isNew); + AddParamsToFunc(aLine, *funcApi, aAllParams, isNew, requiresColsRows); + AddTableCommentToApi(aLine, *funcApi); + } + +void MLCompDataToCdl::AddParamLimitsToInterface(CCdlTkInterface& aInterface, TMLCompDataLine& aLine, bool aAllParams) + { + bool isNew = false; + const bool doesntRequireColsRows = false; + CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, KTypeLayoutScalableParameterLimits, LineParamLimitsApiName(aLine), isNew); + AddParamsToFunc(aLine, *funcApi, aAllParams, isNew, doesntRequireColsRows); + AddTableCommentToApi(aLine, *funcApi); + } + +void MLCompDataToCdl::AddSubTableToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, bool aAllParams) + { + bool isNew = false; + const bool requiresColsRows = true; + TMLCompDataLine& line = *aTable[aSubTable[0]]; + CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, ReturnType(line), SubTableApiName(aSubTable), isNew); + AddParamsToFunc(aTable, aSubTable, *funcApi, aAllParams, isNew, requiresColsRows); + AddTableCommentToApi(aTable, *funcApi); + } + +void MLCompDataToCdl::AddSubTableLimitsToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable) + { + bool isNew = false; + CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, KTypeLayoutScalableTableLimits, SubTableLimitsApiName(aSubTable), isNew); + AddTableCommentToApi(aTable, *funcApi); + } + +void MLCompDataToCdl::AddSubTableParamLimitsToInterface(CCdlTkInterface& aInterface, TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, bool aAllParams) + { + bool isNew = false; + const bool doesntRequireColsRows = false; + CCdlTkFunctionApi* funcApi = ProcessFunctionApi(aInterface, KTypeLayoutScalableParameterLimits, SubTableParamLimtsApiName(aSubTable), isNew); + AddParamsToFunc(aTable, aSubTable, *funcApi, aAllParams, isNew, doesntRequireColsRows); + AddTableCommentToApi(aTable, *funcApi); + } + +void MLCompDataToCdl::AddParamsToFunc(TMLCompDataLine& aLine, CCdlTkFunctionApi& aFunc, bool aAllParams, bool aIsNew, bool aColsRowsRequired) + { + CCdlTkApiParams& params = aFunc.Params(); + CCdlTkApiParams oldParams = params; + + const bool doesntNeedComponentId = false; + bool options = aLine.NeedsOptions(); + bool cols = aLine.NeedsCols(); + bool rows = aLine.NeedsRows(); + UpdateParams(oldParams, params, LineApiName(aLine), aAllParams, aColsRowsRequired, aIsNew, doesntNeedComponentId, options, cols, rows); + } + +void MLCompDataToCdl::AddParamsToFunc(TMLCompDataTable& aTable, TMLCompDataTable::TMLCompDataSubTable& aSubTable, CCdlTkFunctionApi& aFunc, bool aAllParams, bool aIsNew, bool aColsRowsRequired) + { + CCdlTkApiParams& params = aFunc.Params(); + CCdlTkApiParams oldParams = params; + + if(aIsNew || params.FindByName(KParamLineIndex) == params.end()) + params.insert(params.begin(), CCdlTkApiParam(KTypeInt, KParamLineIndex)); + + const bool doesntNeedComponentId = false; + bool options = aSubTable.iNeedsOption; + bool cols = aSubTable.iNeedsCol; + bool rows = aSubTable.iNeedsRow; + UpdateParams(oldParams, params, SubTableApiName(aSubTable), aAllParams, aColsRowsRequired, aIsNew, doesntNeedComponentId, options, cols, rows); + } + +void MLCompDataToCdl::SetHeaders(CCdlTkInterface& aInterface, const string& aCdlName, const string& aComment, int aUid, bool aRomOnly) + { + aInterface.SetFileName(aCdlName); + aInterface.SetAdditionalComment(aComment); + aInterface.Header().SetUid(aUid); + + // Note that if the rom only flag was already set in the existing API, then it will remain on + // even if -romonly was not supplied as a command line argument. To remove the flag, + // the CDL file must be manually edited. + if(aRomOnly) + aInterface.Header().Flags().SetFlag("KCdlFlagRomOnly"); + + string ifName(InterfaceName(CdlTkUtil::StripPath(aCdlName))); + aInterface.Header().SetName(ifName); + aInterface.Header().SetVersion(CCdlTkInterfaceHeader::CVersion(KGeneratedInterfaceMajorVer, KGeneratedInterfaceMinorVer)); + + CCdlTkCpp& cpp = aInterface.Cpp(); + int size = cpp.size(); + if(!find(cpp.begin(), cpp.end(), KIncludeLayoutInstanceHeaderScalableDef)) + cpp.push_back(KIncludeLayoutInstanceHeaderScalableDef); + } + +string MLCompDataToCdl::SubTableApiName(TMLCompDataTable::TMLCompDataSubTable& aSubTable) + { + return CdlTkUtil::ToCpp(aSubTable.iName); + } + +string MLCompDataToCdl::SubTableLimitsApiName(TMLCompDataTable::TMLCompDataSubTable& aSubTable) + { + return CdlTkUtil::ToCpp(aSubTable.iName + KFuncLimitsSuffix); + } + +string MLCompDataToCdl::SubTableParamLimtsApiName(TMLCompDataTable::TMLCompDataSubTable& aSubTable) + { + return CdlTkUtil::ToCpp(aSubTable.iName + KFuncParamLimitsSuffix); + } + +string MLCompDataToCdl::LineApiName(TMLCompDataLine& aLine) + { + return CdlTkUtil::ToCpp(aLine.iName); + } + +string MLCompDataToCdl::LineParamLimitsApiName(TMLCompDataLine& aLine) + { + return CdlTkUtil::ToCpp(aLine.iName + KFuncParamLimitsSuffix); + } + +string MLCompDataToCdl::ReturnType(TMLCompDataLine& aLine) + { + string returnType = "BadType"; + switch(aLine.iType) + { + case TMLCompDataLine::EScreenComponent: + case TMLCompDataLine::EContainerComponent: + case TMLCompDataLine::EPaneComponent: + case TMLCompDataLine::EGraphicComponent: + { + returnType = KTypeWindowComponentLayout; + break; + } + case TMLCompDataLine::ETextComponent: + { + returnType = KTypeTextComponentLayout; + break; + } + default: + { + throw GeneralErr(" MLCompDataToCdl::ReturnType - uncategorised component"); + break; + } + } + + return returnType; + } + +void MLCompDataToCdl::ReplaceRemovedAPIs(CCdlTkInterface& aInterface, const TMLCompData& aLayout, bool aDeletesAllowed) + { + bool error = false; + // look for apis for which there is no equivalent internal structure. + CCdlTkApiList& apiList = aInterface.ApiList(); + for(CCdlTkApiList::reverse_iterator pApi = apiList.rbegin(); pApi != apiList.rend(); ++pApi) + { + CCdlTkApi*& api = *pApi; + string apiName = api->Name(); + if(iInterfaceNamesUsed.find(apiName) == iInterfaceNamesUsed.end()) + { + if(aDeletesAllowed) + { + delete api; // remove the missing api + CCdlTkApi*& last = *(apiList.rbegin()); // get a reference to the pointer to the last element + api = last; // copy the last element pointer to fill the gap + + // erasing the last element will not invalidate our reverse iterator + // but we need a forward iterator to the last element, + // so take the address of our reference to the pointer + apiList.erase(&last); + cout << "Replacing missing API: " << apiName << " <- " << api->Name() << endl; + } + else + { + error = true; + cout << "Detected missing API: " << apiName << endl; + } + } + } + if(error) + { + throw GeneralErr("Error: -nodeletes was specified on command line, but some APIs were missing."); + } + } + +void MLCompDataToCdl::CleanUpAPIComments(CCdlTkInterface& aInterface) + { + string currentComment; + CCdlTkApiList& apiList = aInterface.ApiList(); + for(CCdlTkApiList::iterator pApi = apiList.begin(); pApi != apiList.end(); ++pApi) + { + CCdlTkApi& api = **pApi; + string nextComment = api.Comment(); + if(nextComment == currentComment) + api.SetComment(string()); + else + currentComment = nextComment; + } + } + +CCdlTkFunctionApi* MLCompDataToCdl::ProcessFunctionApi(CCdlTkInterface& aInterface, string aReturnType, string aName, bool& aIsNew) + { + iInterfaceNamesUsed.insert(aName); + CCdlTkFunctionApi* funcApi; + CCdlTkApi* api = aInterface.ApiList().Find(aName); + if(api) + { + funcApi = static_cast(api); + UpdateFunctionApi(*funcApi, aInterface, aReturnType, aName); + } + else + { + funcApi = CreateFunctionApi(aInterface, aReturnType, aName); + aIsNew = true; + } + funcApi->SetReturnType(aReturnType); + funcApi->SetName(aName); + return funcApi; + } + +CCdlTkFunctionApi* MLCompDataToCdl::CreateFunctionApi(CCdlTkInterface& aInterface, string aReturnType, string aName) + { + cout << "Adding new API: " << aName << endl; + CCdlTkFunctionApi* api = new CCdlTkFunctionApi(aInterface); + api->SetReturnType(aReturnType); + api->SetName(aName); + aInterface.ApiList().push_back(api); + return api; + } + +void MLCompDataToCdl::UpdateFunctionApi(CCdlTkFunctionApi& aApi, CCdlTkInterface& aInterface, string aReturnType, string aName) + { + aApi.SetReturnType(aReturnType); + aApi.SetName(aName); + } + +void MLCompDataToCdl::UpdateParams( + CCdlTkApiParams& aOldParams, + CCdlTkApiParams& aParams, + string aApiName, + bool aAllParamsRequested, + bool aColsRowsRequired, + bool aIsNew, + bool aNeedsComponentId, + bool aNeedsOptions, + bool aNeedsCols, + bool aNeedsRows) + { + const bool allParamsDoesntApply = false; + AddParamToParams(aOldParams, aParams, KParamComponentId, allParamsDoesntApply, aIsNew, aNeedsComponentId); + AddParamToParams(aOldParams, aParams, KParamOptionIndex, aAllParamsRequested, aIsNew, aNeedsOptions); + AddParamToParams(aOldParams, aParams, KParamColIndex, aAllParamsRequested && aColsRowsRequired, aIsNew, aNeedsCols && aColsRowsRequired); + AddParamToParams(aOldParams, aParams, KParamRowIndex, aAllParamsRequested && aColsRowsRequired, aIsNew, aNeedsRows && aColsRowsRequired); + + if(aOldParams != aParams) + cout << "Updating parameters: " << aApiName << endl; + } + +void MLCompDataToCdl::AddParamToParams( + CCdlTkApiParams& aOldParams, + CCdlTkApiParams& aParams, + string aType, + bool aAllParamsRequested, + bool aIsNewLine, + bool aNeedsParam) + { + // only add new params if needed + bool alreadyPresent = aOldParams.FindByName(aType) != aOldParams.end(); + if((aNeedsParam || aAllParamsRequested) && !alreadyPresent) + { + // the only circumstance in which we don't use a default parameter, + // is if we're adding a needed param to a new line + bool needsDefaultValue = !(aIsNewLine && aNeedsParam); + + string defaultValue; + if(aParams.size() != 0 && aParams.back().DefaultValue() == CdlTkUtil::IntToString(0)) + { + defaultValue = CdlTkUtil::IntToString(0); + } + else + { + defaultValue = needsDefaultValue ? CdlTkUtil::IntToString(0) : string(); + } + CCdlTkApiParam param(KTypeInt, aType, defaultValue); + aParams.push_back(param); + } + } + diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/MLCompData2LayPerf.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/MLCompData2LayPerf.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,126 @@ +/* +* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning (disable:4786) + +// disable "decorated name length exceeded, name was truncated" +#pragma warning (disable:4503) + +#include +#include +#include +#include + +#include "LayoutCompilerErr.h" +#include "MLCompDataParse.h" +#include "MLAttributesParse.h" +#include "MLCompData2LayPerf.h" +#include "MLCompDataLayPerfWriter.h" + +typedef LayoutProcessArgsErr MLCompDataToLayPerfArgsErr; + +const string KCompDataFileNameSuffix("compData"); +const string KAttributesFileNameSuffix("attributes"); + +//------------------------------------ +// class MLCompDataToLayPerf +//------------------------------------ +int MLCompDataToLayPerf::Process(const vector& args) + { + if (args.size() != 6) + throw MLCompDataToLayPerfArgsErr(); + + int arg = 2; + string cdlName = args[arg++]; + + CCdlTkCdlFileParser parser(cdlName); + auto_ptr iface(parser.LoadAndParse(true)); + + int numLayouts = args.size() - 4; + if (numLayouts < 1) + throw MLCompDataToLayPerfArgsErr(); + + TMLCompData* mergedLayout = NULL; + TMLAttributes* mergedAttribs = NULL; + for(int ii = 0; ii < numLayouts; ii++) + { + string layoutName = args[arg++]; + string attribsName = CdlTkUtil::Replace(KCompDataFileNameSuffix, KAttributesFileNameSuffix, layoutName); + + auto_ptr layoutParse = TMLCompDataParseLayout::Parse(layoutName); + auto_ptr layout(layoutParse.get()); + layoutParse.release(); + + auto_ptr attribsParse = TMLAttributesParse::Parse(attribsName); + auto_ptr attribs(attribsParse.get()); + attribsParse.release(); + + if (mergedLayout || mergedAttribs) + { + // first we merge the components and the attributes + mergedLayout->MergeComponents(*layout); + mergedAttribs->Merge(*attribs); + } + else + { + // first time around + mergedLayout = layout.get(); + mergedAttribs = attribs.get(); + } + layout.release(); + attribs.release(); + } + + mergedLayout->iAttributes = mergedAttribs; // transfer ownership + + // once merged, we can compile the tables + mergedLayout->Compile(); + + + string destLayout = args[arg++]; + MLCompDataToLayPerf layPerf(cdlName, *iface, *mergedLayout, destLayout); + layPerf.WriteLayout(); + + return 0; + } + +void MLCompDataToLayPerf::ShowHelp(ostream& stream) + { + stream << "MLCompData2LayPerf ()+ " << endl; + stream << "MLCompData2LayPerf ..\\cdl\\AknLayoutScalable_Avkon.cdl ..\\xml\\pdp_av_dbl_prt\\display_eur_compData.xml ..\\xml\\pdl_av_dbl_lsc\\display_eur_compData.xml ..\\generated\\LayPerf_AknLayoutScalable_Avkon.cpp " << endl; + stream << " This converts a CDL file into a specialised format for inclusion in the LayPerfScalable2 test app." << endl; + stream << " LayPerfScalable2 runs on the device, calling each API that would be generated from the CDL file." << endl; + } + +MLCompDataToLayPerf::MLCompDataToLayPerf(const string& aCdlName, CCdlTkInterface& aInterface, TMLCompData& aSourceLayout, const string& aDestLayoutName) + : + iCdlName(aCdlName), + iInterface(aInterface), + iLayout(aSourceLayout), + iDestLayoutName(aDestLayoutName) + { + } + +void MLCompDataToLayPerf::WriteLayout() + { + TMLCompDataLayPerfWriter writer(iInterface, iLayout, iDestLayoutName); + writer.Write(iCdlName); + } + diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/MLCompDataLayPerfWriter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/MLCompDataLayPerfWriter.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,222 @@ +/* +* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +#include "MLCompDataLayPerfWriter.h" +#include "MLCompData2Cdl.h" // for static methods +#include "LayoutCompilerErr.h" +#include "CodeGenConsts.h" + +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; +using namespace CdlCompilerToolkit; + +const string KComma = ","; +const string KSpace = " "; +const string KMacroNameRoot = "LAYOUT_TEST"; +const string KMacroNameWindow = "_WINDOW"; +const string KMacroNameText = "_TEXT"; +const string KMacroNameComponent = "_COMPONENT"; +const string KMacroNameParams = "_PARAMS"; + +// +// TMLCompDataLayPerfTableWriter +// + +TMLCompDataLayPerfTableWriter::TMLCompDataLayPerfTableWriter(TMLCompDataLayPerfWriter* aParent, TMLCompDataTable& aTable, string& aInterfaceName, int aTableId) + : + iParent(aParent), + iTable(aTable), + iInterfaceName(aInterfaceName), + iTableId(aTableId) + { + } + +TMLCompDataLayPerfTableWriter::~TMLCompDataLayPerfTableWriter() + { + } + +void TMLCompDataLayPerfTableWriter::Write(ostream& out) + { + WriteTable(out); + } + + +const string KTestAPITableFuntionSig = "\ +testLayout_$LAYOUT_$TABLEID()"; + +string GenerateMLFunctionName(string aInterfaceName, int aTableId) + { + string tableNum = CdlTkUtil::IntToString(aTableId); + + CdlTkUtil::CReplaceSet rep; + rep.Add("$LAYOUT", aInterfaceName); + rep.Add("$TABLEID", tableNum); + return CdlTkUtil::MultiReplace(rep, KTestAPITableFuntionSig); + } + +void TMLCompDataLayPerfTableWriter::WriteTable(ostream& out) + { + out << "void " << GenerateMLFunctionName(iInterfaceName, iTableId) << endl; + + out << "{" << endl; // start of function + out << "DECLARE_LOCAL_VARS_COUNTS" << endl; + + out << "\n// Layout MACROs for Layout Table : "; + out << iTable.Name() << endl; + + for (int i=0; iiInterface.ApiList().Find(name); + if(!api) + throw NotFoundErr(name + " in interface " + iParent->iInterface.FileName()); + CCdlTkFunctionApi* funcApi = static_cast(api); + CCdlTkApiParams& params = funcApi->Params(); + bool first = true; + for(CCdlTkApiParams::iterator pParam = params.begin(); pParam != params.end(); ++pParam) + { + if(!first) + { + paramsString.append(KComma); + paramsString.append(KSpace); + } + paramsString.append(pParam->Name()); + first = false; + } + return paramsString; + } + +string TMLCompDataLayPerfTableWriter::BuildParamLimitParams(TMLCompDataLine& aLine) + { + string paramsString; + string name = aLine.Name(); + + CCdlTkApi* api = iParent->iInterface.ApiList().Find(name); + if(!api) + throw NotFoundErr(name + " in interface " + iParent->iInterface.FileName()); + CCdlTkFunctionApi* funcApi = static_cast(api); + CCdlTkApiParams& params = funcApi->Params(); + + CCdlTkApiParams::iterator pParam = params.FindByName(KParamOptionIndex); + if(pParam != params.end() && aLine.NeedsOptions()) + { + paramsString.append(pParam->Name()); + } + + return paramsString; + } + + +// +// TMLCompDataLayPerfWriter +// + +TMLCompDataLayPerfWriter::TMLCompDataLayPerfWriter(CCdlTkInterface& aInterface, TMLCompData& aLayout, const std::string& aName) + : + iInterface(aInterface), + TMLWriterBase(aLayout, aName) + { + } + +void TMLCompDataLayPerfWriter::Write(const std::string& aCdlName) + { + ofstream out(iName.c_str()); + + cout << "writing layout " << iName << endl; + string cdlFileName(CdlTkUtil::StripPath(aCdlName)); + string ifName(iInterface.Header().Name()); + + out << "// function implementations: " << endl; + int tableId = 0; + for (TMLCompData::iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab) + { + TMLCompDataLayPerfTableWriter writer(this, **pTab, ifName, tableId++); + writer.Write(out); + } + + out << "void testLayout_" << ifName << "()\n{" << endl; + tableId = 0; + for(;tableId < iLayout.size(); tableId++) + { + out << GenerateMLFunctionName(ifName, tableId) << ";" << endl; + } + out << "}\n" << endl; + + out.close(); + } + +// End of File diff -r 000000000000 -r f58d6ec98e88 aknlayoutcompiler/src/MLCompDataParse.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aknlayoutcompiler/src/MLCompDataParse.cpp Thu Dec 17 09:14:18 2009 +0200 @@ -0,0 +1,770 @@ +/* +* Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* +*/ + + +// disable "identifier was truncated to '255' characters in the browser information" warning +#pragma warning(disable: 4786 4250 4503 4541) + + +#include "MLCompDataParse.h" + +#include + +#include +#include +#include +#include // !!! for debug output only + +extern string whiteSpace; + + +// +// const data +// + +const string KCompDataParseRoot = "Layout"; + +const string KCompDataParseRootAttributeMasterName = "MasterName"; +const string KCompDataParseRootAttributeLayoutName = "LayoutName"; +const string KCompDataParseRootAttributeVariantName = "variant_name"; +const string KCompDataParseRootAttributeResolutionHeight = "resolutionHeight"; +const string KCompDataParseRootAttributeResolutionWidth = "resolutionWidth"; +const string KCompDataParseRootAttributeCreatedOn = "createdOn"; + +const string KCompDataParseNodeComponent = "Component"; +const string KCompDataParseNodeComponentAttributeName = "name"; +const string KCompDataParseNodeComponentAttributeId = "id"; +const string KCompDataParseNodeComponentAttributeType = "type"; +const string KCompDataParseNodeComponentAttributeDrawingOrder = "drawingorder"; +const string KCompDataParseNodeComponentAttributeMirror = "mirror"; +const string KCompDataParseNodeComponentAttributeMaxVariety = "maxVariety"; + +const string KCompDataParseTextComponentTypeScreen= "Screen"; +const string KCompDataParseTextComponentTypeContainer= "Container"; +const string KCompDataParseTextComponentTypePane= "Pane"; +const string KCompDataParseTextComponentTypeGraphic= "Graphic"; +const string KCompDataParseTextComponentTypeText= "Text"; + +const string KCompDataParseTextComponentMirrorTrue= "true"; + +const string KCompDataParseNodeOption = "option"; +const string KCompDataParseNodeParentInfo = "ParentInfo"; +const string KCompDataParseNodeLayoutInfo = "LayoutInfo"; +const string KCompDataParseNodeAttributeInfo = "AttributeInfo"; +const string KCompDataParseNodeAttrSets = "attrsets"; + +const string KCompDataParseNodeParent = "parent"; +const string KCompDataParseNodeParentOption = "option"; +const string KCompDataParseNodeParentOptionAttributeVariety = "variety"; +const string KCompDataParseNodeParentInfoParentAttributeId = "id"; +const string KCompDataParseNodeParentInfoParentAttributeVariety = "variety"; + +const string KCompDataParseNodeLayoutInfoParam = "Param"; +const string KCompDataParseNodeLayoutInfoParamAttributeName = "name"; + +const string KCompDataParseNodeValue = "Value"; +const string KCompDataParseNodeVarietyIndex = "varietyIndex"; +const string KCompDataParseNodeVarietyIndexValue = "value"; +const string KCompDataParseNodeCalc = "calc"; +const string KCompDataParseNodeCalcAttributeValue = "value"; +const string KCompDataParseNodeCalcAttributeColNumber = "colNumber"; +const string KCompDataParseNodeCalcAttributeRowNumber = "rowNumber"; +const string KCompDataParseNodeCalcAttributeShowInTable = "showInTable"; +const string KCompDataParseNodeCalcAttributeShowInTableTrue = "true"; +const string KCompDataParseNodeCalcAttributeShowInTableFalse = "false"; +const string KCompDataParseNodeCalcAttributeZoom = "zoom"; +const string KCompDataParseNodeCalcAttributeZoomNormal = "normal"; +const string KCompDataParseNodeCalcAttributeZoomVerySmall = "-2 zoom"; +const string KCompDataParseNodeCalcAttributeZoomSmall = "-1 zoom"; +const string KCompDataParseNodeCalcAttributeZoomLarge = "+1 zoom"; +const string KCompDataParseNodeCalcAttributeZoomVeryLarge = "+2 zoom"; + +const string KCompDataParseTextFontPrimary = "qfn_primary"; +const string KCompDataParseTextFontSecondary = "qfn_secondary"; +const string KCompDataParseTextFontTitle = "qfn_title"; +const string KCompDataParseTextFontPrimarySmall = "qfn_primary_small"; // is that the correct text? +const string KCompDataParseTextFontDigital = "qfn_digital"; + +const string KCompDataParseTextParamNameColor = "Color"; +const string KCompDataParseTextParamShortNameColor = "C"; +const string KCompDataParseTextParamNameLeft = "Left"; +const string KCompDataParseTextParamShortNameLeft = "l"; +const string KCompDataParseTextParamNameRight = "Right"; +const string KCompDataParseTextParamShortNameRight = "r"; +const string KCompDataParseTextParamNameTop = "Top"; +const string KCompDataParseTextParamShortNameTop = "t"; +const string KCompDataParseTextParamNameBottom = "Bottom"; +const string KCompDataParseTextParamShortNameBottom = "b"; +const string KCompDataParseTextParamNameWidth = "Width"; +const string KCompDataParseTextParamShortNameWidth = "W"; +const string KCompDataParseTextParamNameHeight = "Height"; +const string KCompDataParseTextParamShortNameHeight = "H"; +const string KCompDataParseTextParamNameJustification = "Justification"; +const string KCompDataParseTextParamShortNameJustification = "J"; +const string KCompDataParseTextParamNameType = "Type"; +const string KCompDataParseTextParamShortNameType = "Type"; + +// these have been changed to lower case, so that matching +// can be performed independent of case +const string KCompDataParseTextParamTypeCalcValueNone = "none"; +const string KCompDataParseTextParamTypeCalcValueLeft = "left"; +const string KCompDataParseTextParamTypeCalcValueCenter = "center"; +const string KCompDataParseTextParamTypeCalcValueRight = "right"; +const string KCompDataParseTextParamTypeCalcValueBidi = "bidi"; + +const string KCompDataParseNodeAttributeInfoOption = "option"; +const string KCompDataParseNodeAttributeInfoOptionAttributeVariety = "variety"; +const string KCompDataParseNodeAttributeInfoAttributeSet = "attributeset"; +const string KCompDataParseNodeAttributeInfoAttributeSetAttributeName = "name"; + +// +// TMLCompDataParseValues +// + +TMLCompDataParseValues::TMLCompDataParseValues(TMLCompDataLine* aLine) + : + TMLCompDataValues(aLine), + iSaxZoomLevels(0), + iSaxVariety(-1) + { + + } + +MSaxLayoutHandler* TMLCompDataParseValues::HandleSax(const std::string& aElement, const TAttribs& aAttribs) + { +// +// +// +// +// +// ... +// +// ... +// + + if (aElement == KCompDataParseNodeValue) + { + delete iSaxZoomLevels; + iSaxZoomLevels = 0; + iSaxZoomLevels = new TMLCompDataZoomLevels; + } + else if (aElement == KCompDataParseNodeVarietyIndex) + { + HandleSaxVariety(aElement, aAttribs); + } + else if (aElement == KCompDataParseNodeCalc) + { + HandleSaxCalc(aElement, aAttribs); + } + + return this; + } + +void TMLCompDataParseValues::HandleSaxEnd(const std::string& aElement) + { + if (aElement == KCompDataParseNodeValue) + { + insert(make_pair(iSaxVariety, *iSaxZoomLevels)); + delete iSaxZoomLevels; + iSaxZoomLevels = 0; + } + } + +void TMLCompDataParseValues::HandleSaxVariety(const std::string& /*aElement*/, const TAttribs& aAttribs) + { +// + + string varietyIndexStr = aAttribs.getValue(KCompDataParseNodeVarietyIndexValue); + iSaxVariety = CdlTkUtil::ParseInt(varietyIndexStr); // defaults to zero + if(iLine->MaxVariety() < iSaxVariety) + { + iLine->SetMaxVariety(iSaxVariety); + } + } + +void TMLCompDataParseValues::HandleSaxCalc(const std::string& /*aElement*/, const TAttribs& aAttribs) + { +// +// or +// +// or +// +// or +// + + // note that if there is only one calc, but the colNumber and rowNumber attributes are present + // then we have to assume that it is a multivalue component, so deduce which kind it is from + // the current value name + + // first the index part + int max = 1; + int cols = 0; + int rows = 0; + + string colStr = aAttribs.getValue(KCompDataParseNodeCalcAttributeColNumber); + if(!colStr.empty()) + { + cols = CdlTkUtil::ParseInt(colStr); + if(TMLCompDataTable::IsHorizontalColumn(iName)) + { + iLine->SetNeedsCols(true); + } + } + + string rowStr = aAttribs.getValue(KCompDataParseNodeCalcAttributeRowNumber); + if(!rowStr.empty()) + { + rows = CdlTkUtil::ParseInt(rowStr); + if(TMLCompDataTable::IsVerticalColumn(iName)) + { + iLine->SetNeedsRows(true); + } + } + + // keep the line updated if we have found more rows / cols than it knows about + if(iLine->NumCols() < cols) + iLine->SetNumCols(cols); + if(iLine->NumRows() < rows) + iLine->SetNumRows(rows); + + // each calc is either a row or a col (depending on which axis) + if(cols > 1) + max = cols; + else if(rows > 1) + max = rows; + + // then the value part of the calc + string valueStr; + valueStr = aAttribs.getValue(KCompDataParseNodeCalcAttributeValue); + ConvertValueStr(valueStr); + + // check whether the calc is a default value (which corresponds to normal zoom) + // or if it corresponds to a known zoom factor + string zoomStr = aAttribs.getValue(KCompDataParseNodeCalcAttributeZoom); + int zoom = ConvertZoomStr(zoomStr); + if(zoom != EAknUiZoomAutomatic) + { + // then put them together + int num = max - 1; // change to zero based + TMLCompDataCalcs& calcs = (*iSaxZoomLevels)[zoom]; + calcs[num] = valueStr; + } + } + +void TMLCompDataParseValues::ConvertValueStr(std::string& aValueStr) + { + int valueInt = 0; + if(iName == KCompDataParseTextParamShortNameType) + { + if(aValueStr == KCompDataParseTextFontPrimary) + valueInt = ELayoutCompilerFontCategoryPrimary; + else if(aValueStr == KCompDataParseTextFontSecondary) + valueInt = ELayoutCompilerFontCategorySecondary; + else if(aValueStr == KCompDataParseTextFontTitle) + valueInt = ELayoutCompilerFontCategoryTitle; + else if(aValueStr == KCompDataParseTextFontPrimarySmall) + valueInt = ELayoutCompilerFontCategoryPrimarySmall; + else if(aValueStr == KCompDataParseTextFontDigital) + valueInt = ELayoutCompilerFontCategoryDigital; + else + valueInt = ELayoutCompilerFontCategoryUndefined; + aValueStr = CdlTkUtil::IntToString(valueInt); + } + else if(iName == KCompDataParseTextParamShortNameJustification) + { + // jusitication does not have consistent capitalization + string lowerValueStr = CdlTkUtil::ToLower(aValueStr); + if(lowerValueStr == KCompDataParseTextParamTypeCalcValueNone) + valueInt = ELayoutAlignNone; + else if(lowerValueStr == KCompDataParseTextParamTypeCalcValueLeft) + valueInt = ELayoutAlignLeft; + else if(lowerValueStr == KCompDataParseTextParamTypeCalcValueRight) + valueInt = ELayoutAlignRight; + else if(lowerValueStr == KCompDataParseTextParamTypeCalcValueCenter) + valueInt = ELayoutAlignCenter; + else if(lowerValueStr == KCompDataParseTextParamTypeCalcValueBidi) + valueInt = ELayoutAlignBidi; + else + valueInt = ELayoutAlignNone; + aValueStr = CdlTkUtil::IntToString(valueInt); + } + } + +int TMLCompDataParseValues::ConvertZoomStr(const std::string& aZoomStr) + { + int zoomInt = EAknUiZoomAutomatic; + string lowerZoomStr = CdlTkUtil::ToLower(aZoomStr); + if(lowerZoomStr.empty()) + zoomInt = EAknUiZoomNormal; + else if(lowerZoomStr == KCompDataParseNodeCalcAttributeZoomVerySmall) + zoomInt = EAknUiZoomVerySmall; + else if(lowerZoomStr == KCompDataParseNodeCalcAttributeZoomSmall) + zoomInt = EAknUiZoomSmall; + else if(lowerZoomStr == KCompDataParseNodeCalcAttributeZoomLarge) + zoomInt = EAknUiZoomLarge; + else if(lowerZoomStr == KCompDataParseNodeCalcAttributeZoomVeryLarge) + zoomInt = EAknUiZoomVeryLarge; + return zoomInt; + } + + +// +// TMLCompDataParseParentInfo +// + +TMLCompDataParseParentInfo::TMLCompDataParseParentInfo(TMLCompDataLine* aLine) + : + iSaxParentInfoSelector(0), + iSaxVariety(0) + { + + } + +MSaxLayoutHandler* TMLCompDataParseParentInfo::HandleSax(const std::string& aElement, const TAttribs& aAttribs) + { +// +// +// + + if (aElement == KCompDataParseNodeOption) + { + delete iSaxParentInfoSelector; + iSaxParentInfoSelector= 0; + iSaxParentInfoSelector = new TMLCompDataParentInfoSelector; + HandleSaxVariety(aElement, aAttribs); + } + else if (aElement == KCompDataParseNodeParent) + { + HandleSaxParent(aElement, aAttribs); + } + + return this; + } + +void TMLCompDataParseParentInfo::HandleSaxEnd(const std::string& aElement) + { + if (aElement == KCompDataParseNodeOption) // value + { + insert(make_pair(iSaxVariety, *iSaxParentInfoSelector)); + delete iSaxParentInfoSelector; + iSaxParentInfoSelector = 0; + } + } + +void TMLCompDataParseParentInfo::HandleSaxParent(const std::string& aElement, const TAttribs& aAttribs) + { +// + string parentIdStr = aAttribs.getValue(KCompDataParseNodeParentInfoParentAttributeId); + string parentVarietyStr = aAttribs.getValue(KCompDataParseNodeParentInfoParentAttributeVariety); + + iSaxParentInfoSelector->iParentId = CdlTkUtil::ParseInt(parentIdStr); + iSaxParentInfoSelector->iParentVariety = CdlTkUtil::ParseInt(parentVarietyStr); + } + +void TMLCompDataParseParentInfo::HandleSaxVariety(const std::string& aElement, const TAttribs& aAttribs) + { +//