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) + { +//