|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
20 #pragma warning (disable:4786) |
|
21 |
|
22 #include "MLEqCompData2DHuiML.h" |
|
23 #include "MLEqCompDataParse.h" |
|
24 #include "LayoutCompilerErr.h" |
|
25 #include "FormulaTree.h" |
|
26 |
|
27 #include <cdlcompilertoolkit/cdltkprocess.h> |
|
28 |
|
29 #include <fstream> |
|
30 #include <iostream> |
|
31 #include <sstream> |
|
32 #include <algorithm> |
|
33 |
|
34 #include "CodeGenConsts.h" |
|
35 |
|
36 |
|
37 using namespace std; |
|
38 |
|
39 typedef LayoutProcessArgsErr<MLEqCompDataToDHuiML> MLEqCompDataToDHuiMLArgsErr; |
|
40 |
|
41 // constants |
|
42 |
|
43 const string KCompDataFileNameSuffix("compData"); |
|
44 const string KAttributesFileNameSuffix("attributes"); |
|
45 |
|
46 |
|
47 // |
|
48 // class TEqLayoutSaxWriter |
|
49 // |
|
50 |
|
51 |
|
52 class TEqLayoutSaxWriter |
|
53 { |
|
54 public: |
|
55 enum |
|
56 { |
|
57 KIndentSize=4 |
|
58 }; |
|
59 public: |
|
60 TEqLayoutSaxWriter(ofstream& aStream); |
|
61 void StartDocument(); |
|
62 void EndDocument(); |
|
63 void OpenStartElement(const string& aLocalName); |
|
64 void CloseStartElement(); |
|
65 void CloseAndEndStartElement(); |
|
66 void EndElement(const string& aLocalName); |
|
67 void Attribute(const string& aLocalName, const string& aValue); |
|
68 void Comment(const string& aComment); |
|
69 |
|
70 private: |
|
71 void Indent(); |
|
72 void IncreaseIndentLevel(); |
|
73 void DecreaseIndentLevel(); |
|
74 private: |
|
75 ofstream& iStream; |
|
76 int iIndentLevel; |
|
77 }; |
|
78 |
|
79 TEqLayoutSaxWriter::TEqLayoutSaxWriter(ofstream& aStream) |
|
80 : |
|
81 iStream(aStream), |
|
82 iIndentLevel(0) |
|
83 { |
|
84 |
|
85 }; |
|
86 |
|
87 void TEqLayoutSaxWriter::StartDocument() |
|
88 { |
|
89 Indent(); |
|
90 iStream << string("<xmluiml xmlns=\"http://www.series60.com/xml/xmluiml/1\">") << endl; |
|
91 IncreaseIndentLevel(); |
|
92 } |
|
93 |
|
94 void TEqLayoutSaxWriter::EndDocument() |
|
95 { |
|
96 DecreaseIndentLevel(); |
|
97 Indent(); |
|
98 iStream << string("</xmluiml>") << endl; |
|
99 } |
|
100 |
|
101 //void TEqLayoutSaxWriter::StartElement(const string& /*namespaceURI*/, const string& localName /*, const string& qName*/ /*, const AttributesT& atts*/) |
|
102 void TEqLayoutSaxWriter::OpenStartElement(const string& aLocalName) |
|
103 { |
|
104 Indent(); |
|
105 iStream << "<" << aLocalName; |
|
106 IncreaseIndentLevel(); |
|
107 } |
|
108 |
|
109 void TEqLayoutSaxWriter::CloseStartElement() |
|
110 { |
|
111 iStream << ">" << endl; |
|
112 } |
|
113 |
|
114 void TEqLayoutSaxWriter::CloseAndEndStartElement() |
|
115 { |
|
116 iStream << " />" << endl; |
|
117 DecreaseIndentLevel(); |
|
118 } |
|
119 |
|
120 void TEqLayoutSaxWriter::EndElement(const string& aLocalName) |
|
121 { |
|
122 DecreaseIndentLevel(); |
|
123 Indent(); |
|
124 iStream << "</" << aLocalName << ">" << endl; |
|
125 } |
|
126 |
|
127 void TEqLayoutSaxWriter::Attribute(const string& aLocalName, const string& aValue) |
|
128 { |
|
129 iStream << " " << aLocalName << "=\"" << aValue << "\""; |
|
130 } |
|
131 |
|
132 void TEqLayoutSaxWriter::Comment(const string& aComment) |
|
133 { |
|
134 iStream << "<!-- " << aComment << " -->" << endl; |
|
135 } |
|
136 |
|
137 void TEqLayoutSaxWriter::Indent() |
|
138 { |
|
139 stringstream ss; |
|
140 int max = iIndentLevel * KIndentSize; |
|
141 for(int count = 0; count < max; count++) |
|
142 { |
|
143 ss << " "; |
|
144 } |
|
145 iStream << ss.str(); |
|
146 } |
|
147 |
|
148 void TEqLayoutSaxWriter::IncreaseIndentLevel() |
|
149 { |
|
150 if(iIndentLevel > 1000) |
|
151 throw GeneralErr("TEqLayoutSaxWriter::DecreaseIndentLevel - nesting inconsistency"); |
|
152 iIndentLevel++; |
|
153 } |
|
154 |
|
155 void TEqLayoutSaxWriter::DecreaseIndentLevel() |
|
156 { |
|
157 if(iIndentLevel == 0) |
|
158 throw GeneralErr("TEqLayoutSaxWriter::DecreaseIndentLevel - nesting inconsistency"); |
|
159 iIndentLevel--; |
|
160 } |
|
161 |
|
162 |
|
163 |
|
164 // |
|
165 // MLEqCompDataToDHuiML |
|
166 // |
|
167 |
|
168 int MLEqCompDataToDHuiML::Process(const vector<string>& args) |
|
169 { |
|
170 int numExpectedArgs = 5; |
|
171 int numArgs = args.size(); |
|
172 if(numArgs < numExpectedArgs) |
|
173 throw MLEqCompDataToDHuiMLArgsErr(); |
|
174 |
|
175 int arg = 2; |
|
176 string listName = args[arg++]; |
|
177 string compDataName = args[arg++]; |
|
178 string parChildName = args[arg++]; |
|
179 string dhuimlName = args[arg++]; |
|
180 |
|
181 auto_ptr<TMLEqCompDataParseLayout> layoutParse = TMLEqCompDataParseLayout::Parse(listName, compDataName, parChildName); |
|
182 auto_ptr<TMLEqCompData> layout(layoutParse.get()); |
|
183 layoutParse.release(); |
|
184 |
|
185 TMLEqCompData* theLayout = layout.get(); |
|
186 theLayout->Compile(); |
|
187 |
|
188 cout << "writing dhuiml file " << dhuimlName << endl; |
|
189 ofstream dhuiml(dhuimlName.c_str()); |
|
190 |
|
191 int KIndent = 4; |
|
192 TEqLayoutSaxWriter saxWriter(dhuiml); |
|
193 saxWriter.StartDocument(); |
|
194 |
|
195 stringstream comment1; |
|
196 comment1 << "Generated from list: " << listName; |
|
197 saxWriter.Comment(comment1.str()); |
|
198 |
|
199 stringstream comment2; |
|
200 comment2 << "Generated from component data: " << compDataName; |
|
201 saxWriter.Comment(comment2.str()); |
|
202 |
|
203 stringstream comment3; |
|
204 comment3 << "Generated from parent child data: " << parChildName; |
|
205 saxWriter.Comment(comment3.str()); |
|
206 |
|
207 LayoutTablesToDeclarative(saxWriter, *theLayout); |
|
208 |
|
209 saxWriter.EndDocument(); |
|
210 |
|
211 return 0; |
|
212 } |
|
213 |
|
214 void MLEqCompDataToDHuiML::ShowHelp(ostream& stream) |
|
215 { |
|
216 stream << "MLEqCompData2DHuiML <MLEqCompListName> <MLEqCompDataName> <MLEqParChildName> <DHuiMLName>" << endl; |
|
217 stream << " e.g. from \\S60\\AknLayout2\\group run " << endl; |
|
218 stream << " aknlayoutcompiler MLEqCompData2DHuiML " << endl; |
|
219 stream << " ..\\..\\xml_master\\xml\\m_p_30\\m_p_30_list.xml " << endl; |
|
220 stream << " ..\\..\\xml_master\\xml\\m_p_30\\m_p_30\\0.161093285736413\\eur_compData.xml " << endl; |
|
221 stream << " ..\\..\\xml_master\\xml\\m_p_30\\m_p_30\\0.161093285736413\\eur_parChildRelation.xml " << endl; |
|
222 stream << " ..\\generated_declarative\\lct_avkon.dhuiml" << endl; |
|
223 } |
|
224 |
|
225 void MLEqCompDataToDHuiML::LayoutTablesToDeclarative(TEqLayoutSaxWriter& aSaxWriter, const TMLEqCompData& aLayout) |
|
226 { |
|
227 // first the tables are output |
|
228 for (TMLEqCompData::const_iterator pTab = aLayout.begin(); pTab != aLayout.end(); ++pTab) |
|
229 { |
|
230 AddTableToDeclarative(aSaxWriter, **pTab); |
|
231 } |
|
232 } |
|
233 |
|
234 void MLEqCompDataToDHuiML::LayoutComponentsToDeclarative(TEqLayoutSaxWriter& aSaxWriter, const TMLEqCompData& aLayout) |
|
235 { |
|
236 // then the individual components are output |
|
237 for (TMLEqCompData::TMLEqCompDataComponents::const_iterator pLine = aLayout.iComponents.begin(); pLine != aLayout.iComponents.end(); ++pLine) |
|
238 { |
|
239 // @todo this may be needed if the components are to be written out separately from the tables |
|
240 } |
|
241 } |
|
242 |
|
243 |
|
244 const string KDHuiMLLayoutmanager("layoutmanager"); |
|
245 const string KDHuiMLLayoutmanagerId("id"); |
|
246 const string KDHuiMLLayoutmanagerName("name"); |
|
247 const string KDHuiMLOptionSet("optionset"); |
|
248 const string KDHuiMLOptionSetId("id"); |
|
249 const string KDHuiMLOptionSetOrientationPortrait("portrait"); |
|
250 const string KDHuiMLOptionSetOrientationLandscape("landscape"); |
|
251 const string KDHuiMLOptionSetOrientationTrue("true"); |
|
252 const string KDHuiMLOptionSetOrientationFalse("false"); |
|
253 |
|
254 void MLEqCompDataToDHuiML::AddTableToDeclarative(TEqLayoutSaxWriter& aSaxWriter, TMLEqCompDataTable& aTable) |
|
255 { |
|
256 if(aTable.size() == 0) |
|
257 return; |
|
258 |
|
259 // <layoutmanager id="1233" name="listscroll_app_pane"> |
|
260 // <optionset id="0" portrait="true" landscape="false"> |
|
261 // <lctcomponent id="1234" name="grid_app_pane"> |
|
262 |
|
263 aSaxWriter.OpenStartElement(KDHuiMLLayoutmanager); |
|
264 aSaxWriter.Attribute(KDHuiMLLayoutmanagerId, CdlTkUtil::IntToString(aTable.iId)); |
|
265 aSaxWriter.Attribute(KDHuiMLLayoutmanagerName, aTable.iName); |
|
266 aSaxWriter.CloseStartElement(); |
|
267 |
|
268 // iterate through option sets |
|
269 for(TMLEqCompDataTable::iterator pOptionSet = aTable.begin(); pOptionSet != aTable.end(); ++pOptionSet) |
|
270 { |
|
271 int optionSetId = pOptionSet->first; |
|
272 TMLEqCompDataTableOptionSet& optionSet = pOptionSet->second; |
|
273 aSaxWriter.OpenStartElement(KDHuiMLOptionSet); |
|
274 aSaxWriter.Attribute(KDHuiMLOptionSetId, CdlTkUtil::IntToString(optionSetId)); |
|
275 |
|
276 string isPortrait = (optionSet.iOrientation & EMLEqCompDataOptionSetOrientationPortrait) ? KDHuiMLOptionSetOrientationTrue : KDHuiMLOptionSetOrientationFalse; |
|
277 aSaxWriter.Attribute(KDHuiMLOptionSetOrientationPortrait, isPortrait); |
|
278 string isLandscape = (optionSet.iOrientation & EMLEqCompDataOptionSetOrientationLandscape) ? KDHuiMLOptionSetOrientationTrue : KDHuiMLOptionSetOrientationFalse; |
|
279 aSaxWriter.Attribute(KDHuiMLOptionSetOrientationLandscape, isLandscape); |
|
280 |
|
281 aSaxWriter.CloseStartElement(); |
|
282 |
|
283 for(TMLEqCompDataTableOptionSet::iterator pLine = optionSet.begin(); pLine != optionSet.end(); ++pLine) |
|
284 { |
|
285 AddLineToDeclarative(aSaxWriter, **pLine, optionSetId); |
|
286 } |
|
287 aSaxWriter.EndElement(KDHuiMLOptionSet); |
|
288 } |
|
289 |
|
290 aSaxWriter.EndElement(KDHuiMLLayoutmanager); |
|
291 } |
|
292 |
|
293 |
|
294 const string KDHuiMLLCTComponent("lctcomponent"); |
|
295 const string KDHuiMLLCTComponentId("id"); |
|
296 const string KDHuiMLLCTComponentName("name"); |
|
297 const string KDHuiMLAlfLayout("alflayout"); |
|
298 const string KDHuiMLAlfLayoutType("type"); |
|
299 const string KDHuiMLAlfLayoutTypeAnchor("anchor"); |
|
300 |
|
301 void MLEqCompDataToDHuiML::AddLineToDeclarative(TEqLayoutSaxWriter& aSaxWriter, TMLEqCompDataLine& aLine, int aOptionSetId) |
|
302 { |
|
303 // beginning of component |
|
304 |
|
305 // <lctcomponent id="1234" name="grid_app_pane"> |
|
306 // <alflayout type="anchor"> |
|
307 |
|
308 aSaxWriter.OpenStartElement(KDHuiMLLCTComponent); |
|
309 aSaxWriter.Attribute(KDHuiMLLCTComponentId, CdlTkUtil::IntToString(aLine.iId)); |
|
310 aSaxWriter.Attribute(KDHuiMLLCTComponentName, aLine.iName); |
|
311 aSaxWriter.CloseStartElement(); |
|
312 |
|
313 aSaxWriter.OpenStartElement(KDHuiMLAlfLayout); |
|
314 aSaxWriter.Attribute(KDHuiMLAlfLayoutType, KDHuiMLAlfLayoutTypeAnchor); |
|
315 aSaxWriter.CloseStartElement(); |
|
316 |
|
317 const string* outputOrder = KEqCompDataPaneOutputOrder; |
|
318 const int outputSize = KEqCompDataPaneOutputOrderSize; |
|
319 vector<string> cellOrder(outputOrder, outputOrder + outputSize); |
|
320 |
|
321 for (vector<string>::iterator pCell = cellOrder.begin(); pCell != cellOrder.end(); ++pCell) |
|
322 { |
|
323 string cellName = *pCell; |
|
324 AddCellToDeclarative(aSaxWriter, aLine[cellName], cellName, aOptionSetId); |
|
325 } |
|
326 |
|
327 aSaxWriter.EndElement(KDHuiMLAlfLayout); |
|
328 aSaxWriter.EndElement(KDHuiMLLCTComponent); |
|
329 } |
|
330 |
|
331 const string KDHuiMLAnchor("anchor"); |
|
332 const string KDHuiMLAnchorOrdinal("ordinal"); |
|
333 const string KDHuiMLAnchorType("type"); |
|
334 const string KDHuiMLAnchorTypePrefix("EAlfAnchorType"); // not currently used, to save disk space |
|
335 const string KDHuiMLAnchorAttachmentOrigin("attachmentOrigin"); |
|
336 const string KDHuiMLAnchorAttachmentOriginPrefix("EAlfAnchorAttachmentOrigin"); // not currently used, to save disk space |
|
337 const string KDHuiMLAnchorAttachmentOrdinal("attachmentOrdinal"); |
|
338 const string KDHuiMLAnchorAttachmentOrdinalAttachToParent("P"); |
|
339 const string KDHuiMLAnchorOffset("offset"); |
|
340 const string KDHuiMLAnchorOffsetMagnitude("magnitude"); |
|
341 const string KDHuiMLAnchorOffsetUnit("unit"); |
|
342 const string KDHuiMLAnchorOffsetUnitPixel("S60"); |
|
343 |
|
344 void MLEqCompDataToDHuiML::AddCellToDeclarative(TEqLayoutSaxWriter& aSaxWriter, TMLEqCompDataValues& aValues, const string& aCellName, int aOptionSetId) |
|
345 { |
|
346 // <anchor |
|
347 // ordinal="0" // don't need this, as declarative can calculate drawing order at runtime |
|
348 // type="EAlfAnchorTypeLeft" |
|
349 // attachmentOrigin="EAlfAnchorAttachmentOriginLeft" |
|
350 // attachmentOrdinal="EAlfAnchorAttachToParent"> |
|
351 // <offset |
|
352 // magnitude="20" |
|
353 // unit="EAlfUnitPixel" |
|
354 // zoomId = "233" /> |
|
355 // <formula formulaStr=""> // @todo this is temporary whilst equation evaluation is developed |
|
356 // ... |
|
357 // </formula> |
|
358 // </anchor> |
|
359 |
|
360 bool validCell(false); |
|
361 TMLEqCompDataFormula* formula = NULL; |
|
362 TMLEqCompDataValuesOptionSet& optionSet = aValues.iOptionSets[aOptionSetId]; |
|
363 // always assume it's the first and only forumla |
|
364 if(optionSet.size() > 0) |
|
365 { |
|
366 formula = &(optionSet[0]); |
|
367 if(!formula->iFormulaString.empty()) |
|
368 { |
|
369 validCell = true; |
|
370 } |
|
371 } |
|
372 |
|
373 if(!validCell) |
|
374 return; |
|
375 |
|
376 aSaxWriter.OpenStartElement(KDHuiMLAnchor); |
|
377 |
|
378 // aSaxWriter.Attribute(KDHuiMLAnchorOrdinal, 0); // don't need this, as declarative can calculate drawing order at runtime |
|
379 |
|
380 string anchorType = aCellName; |
|
381 ConvertPositionValueStr(anchorType); |
|
382 aSaxWriter.Attribute(KDHuiMLAnchorType, anchorType); |
|
383 |
|
384 // @todo for now, always attach to the same side, but need to calculate this for e.g. orthogonal anchors |
|
385 aSaxWriter.Attribute(KDHuiMLAnchorAttachmentOrigin, anchorType); |
|
386 |
|
387 aSaxWriter.Attribute(KDHuiMLAnchorAttachmentOrdinal, KDHuiMLAnchorAttachmentOrdinalAttachToParent); |
|
388 |
|
389 aSaxWriter.CloseStartElement(); |
|
390 |
|
391 { |
|
392 aSaxWriter.OpenStartElement(KDHuiMLAnchorOffset); |
|
393 aSaxWriter.Attribute(KDHuiMLAnchorOffsetMagnitude, "0"); // @todo, replace with value in units! |
|
394 aSaxWriter.Attribute(KDHuiMLAnchorOffsetUnit, KDHuiMLAnchorOffsetUnitPixel); // @todo, replace with s60 units when supported |
|
395 aSaxWriter.CloseAndEndStartElement(); |
|
396 } |
|
397 |
|
398 AddFormulaToDeclarative(aSaxWriter, *formula); |
|
399 |
|
400 aSaxWriter.EndElement(KDHuiMLAnchor); |
|
401 } |
|
402 |
|
403 |
|
404 // |
|
405 // this is all temporary, to illustrate equation parsing |
|
406 // |
|
407 |
|
408 |
|
409 const string KDHuiMLAnchorFormula("formula"); |
|
410 const string KDHuiMLAnchorFormulaString("formulastr"); |
|
411 const string KDHuiMLAnchorFormulaNode("node"); |
|
412 const string KDHuiMLAnchorFormulaNodeType("type"); |
|
413 const string KDHuiMLAnchorFormulaNodeValue("value"); |
|
414 |
|
415 |
|
416 void Print(TEqLayoutSaxWriter& aSaxWriter, const FormulaTreeNode& aNode) |
|
417 { |
|
418 aSaxWriter.OpenStartElement(KDHuiMLAnchorFormulaNode); |
|
419 stringstream ss; |
|
420 |
|
421 switch (aNode.Type()) |
|
422 { |
|
423 case FormulaTreeNode::EReal: // Double() = the number |
|
424 ss << aNode.Real(); |
|
425 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "real"); |
|
426 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
427 aSaxWriter.CloseStartElement(); |
|
428 break; |
|
429 case FormulaTreeNode::EInt: // Int() = the number |
|
430 ss << aNode.Int(); |
|
431 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "int"); |
|
432 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
433 aSaxWriter.CloseStartElement(); |
|
434 break; |
|
435 case FormulaTreeNode::ECell: // Char() = cell name |
|
436 ss << aNode.Char(); |
|
437 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "cell"); |
|
438 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
439 aSaxWriter.CloseStartElement(); |
|
440 break; |
|
441 case FormulaTreeNode::EParent: // nothing special |
|
442 ss << aNode.Char(); |
|
443 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "parent"); |
|
444 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
445 aSaxWriter.CloseStartElement(); |
|
446 break; |
|
447 case FormulaTreeNode::EParentCell: // Char() = parent cell name |
|
448 ss << aNode.Char(); |
|
449 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "parent_cell"); |
|
450 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
451 aSaxWriter.CloseStartElement(); |
|
452 break; |
|
453 case FormulaTreeNode::ETableCell: // Double() = target table |
|
454 ss << aNode.Real(); |
|
455 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "table_cell"); |
|
456 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
457 aSaxWriter.CloseStartElement(); |
|
458 break; |
|
459 case FormulaTreeNode::EComponent: // Double() = component id, [0] = cell name |
|
460 ss << aNode.Real(); |
|
461 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "component"); |
|
462 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
463 aSaxWriter.CloseStartElement(); |
|
464 Print(aSaxWriter, aNode[0]); |
|
465 break; |
|
466 case FormulaTreeNode::EAbsolute: // Text() = whole thing, [0], [1] = real components, [2] = cell name |
|
467 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "absolute_cell_ref"); |
|
468 // aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
469 aSaxWriter.CloseStartElement(); |
|
470 Print(aSaxWriter, aNode[0]); |
|
471 Print(aSaxWriter, aNode[1]); |
|
472 Print(aSaxWriter, aNode[2]); |
|
473 break; |
|
474 case FormulaTreeNode::EUnits: // Double() = units |
|
475 ss << aNode.Real(); |
|
476 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "units"); |
|
477 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
478 aSaxWriter.CloseStartElement(); |
|
479 break; |
|
480 case FormulaTreeNode::EConstant: // Double() = constant |
|
481 ss << aNode.Real(); |
|
482 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "constant"); |
|
483 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
484 aSaxWriter.CloseStartElement(); |
|
485 break; |
|
486 case FormulaTreeNode::EAttribute: // Int() = attribute |
|
487 ss << aNode.Int(); |
|
488 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "attribute"); |
|
489 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
490 aSaxWriter.CloseStartElement(); |
|
491 break; |
|
492 case FormulaTreeNode::EMystery: // Text() = whole thing, [0], [1] = int components |
|
493 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "mystery"); |
|
494 // aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
495 aSaxWriter.CloseStartElement(); |
|
496 Print(aSaxWriter, aNode[0]); |
|
497 Print(aSaxWriter, aNode[1]); |
|
498 break; |
|
499 case FormulaTreeNode::EFunction: // Text() = function name, [0] = parameter |
|
500 ss << aNode.Text(); |
|
501 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "function"); |
|
502 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
503 aSaxWriter.CloseStartElement(); |
|
504 Print(aSaxWriter, aNode[0]); |
|
505 break; |
|
506 case FormulaTreeNode::EArithmetic: // Char() = arithmetic operator, [0], [1] = sub expressions |
|
507 ss << aNode.Char(); |
|
508 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "arithmetic"); |
|
509 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
510 aSaxWriter.CloseStartElement(); |
|
511 Print(aSaxWriter, aNode[0]); |
|
512 Print(aSaxWriter, aNode[1]); |
|
513 break; |
|
514 case FormulaTreeNode::ECondition: // Text() = comparison operator, [0], [1] = sub expressions |
|
515 ss << aNode.Text(); |
|
516 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "condition"); |
|
517 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
518 aSaxWriter.CloseStartElement(); |
|
519 Print(aSaxWriter, aNode[0]); |
|
520 Print(aSaxWriter, aNode[1]); |
|
521 break; |
|
522 case FormulaTreeNode::EConditional: // no content, [0] = condition, [1] = then expression, [2] = else expression |
|
523 aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeType, "if_then_else"); |
|
524 // aSaxWriter.Attribute(KDHuiMLAnchorFormulaNodeValue, ss.str()); |
|
525 aSaxWriter.CloseStartElement(); |
|
526 Print(aSaxWriter, aNode[0]); |
|
527 Print(aSaxWriter, aNode[1]); |
|
528 Print(aSaxWriter, aNode[2]); |
|
529 break; |
|
530 } |
|
531 aSaxWriter.EndElement(KDHuiMLAnchorFormulaNode); |
|
532 } |
|
533 |
|
534 |
|
535 void MLEqCompDataToDHuiML::AddFormulaToDeclarative(TEqLayoutSaxWriter& aSaxWriter, const TMLEqCompDataFormula& aFormula) |
|
536 { |
|
537 // <formula formulaStr=""> // @todo this is temporary whilst equation evaluation is developed |
|
538 // <node type="123" value="456"/> |
|
539 // </formula> |
|
540 aSaxWriter.OpenStartElement(KDHuiMLAnchorFormula); |
|
541 aSaxWriter.Attribute(KDHuiMLAnchorFormulaString, aFormula.iFormulaString); // @todo, replace with expanded formula xml |
|
542 aSaxWriter.CloseStartElement(); |
|
543 |
|
544 if(aFormula.iFormulaTree) |
|
545 { |
|
546 Print(aSaxWriter, *(aFormula.iFormulaTree)); |
|
547 } |
|
548 |
|
549 aSaxWriter.EndElement(KDHuiMLAnchorFormula); |
|
550 } |
|
551 |
|
552 extern const string KEqCompDataKeywordParamLeft; |
|
553 extern const string KEqCompDataKeywordParamTop; |
|
554 extern const string KEqCompDataKeywordParamRight; |
|
555 extern const string KEqCompDataKeywordParamBottom; |
|
556 extern const string KEqCompDataKeywordParamWidth; |
|
557 extern const string KEqCompDataKeywordParamHeight; |
|
558 |
|
559 const string KDHuiMLAnchorLeft("left"); |
|
560 const string KDHuiMLAnchorTop("top"); |
|
561 const string KDHuiMLAnchorRight("right"); |
|
562 const string KDHuiMLAnchorBottom("bottom"); |
|
563 const string KDHuiMLAnchorWidth("width"); |
|
564 const string KDHuiMLAnchorHeight("height"); |
|
565 |
|
566 void MLEqCompDataToDHuiML::ConvertPositionValueStr(std::string& aValueStr) |
|
567 { |
|
568 if(aValueStr == KEqCompDataKeywordParamLeft) |
|
569 aValueStr = KDHuiMLAnchorLeft; |
|
570 else if(aValueStr == KEqCompDataKeywordParamTop) |
|
571 aValueStr = KDHuiMLAnchorTop; |
|
572 else if(aValueStr == KEqCompDataKeywordParamRight) |
|
573 aValueStr = KDHuiMLAnchorRight; |
|
574 else if(aValueStr == KEqCompDataKeywordParamBottom) |
|
575 aValueStr = KDHuiMLAnchorBottom; |
|
576 else if(aValueStr == KEqCompDataKeywordParamWidth) |
|
577 aValueStr = KDHuiMLAnchorWidth; |
|
578 else if(aValueStr == KEqCompDataKeywordParamHeight) |
|
579 aValueStr = KDHuiMLAnchorHeight; |
|
580 else |
|
581 aValueStr = KDHuiMLAnchorLeft; |
|
582 } |
|
583 |
|
584 |
|
585 // end of file |