|
1 /* |
|
2 * Copyright (c) 2002-2008 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 |
|
20 #include "MLCompData.h" |
|
21 #include "MLCompDataParse.h" |
|
22 #include "MLCompData2Cdl.h" |
|
23 #include "MLAttributes.h" |
|
24 |
|
25 #include "LayoutCompilerErr.h" |
|
26 #include "CodeGenConsts.h" |
|
27 #include "UsefulDefinitions.h" |
|
28 |
|
29 #include "Akndef.hrh" |
|
30 |
|
31 #include <set> |
|
32 #include <sstream> |
|
33 #include <iostream> |
|
34 #include <algorithm> |
|
35 |
|
36 |
|
37 // |
|
38 // const data |
|
39 // |
|
40 |
|
41 const string KCompDataPaneOutputOrder[] = {"C", "l", "t", "r", "b", "W", "H"}; |
|
42 const string KCompDataPaneOutputOrderMirrored[] = {"C", "r", "t", "l", "b", "W", "H"}; |
|
43 const int KCompDataPaneOutputOrderSize = ARRAY_LEN(KCompDataPaneOutputOrder); |
|
44 |
|
45 const string KCompDataGraphicOutputOrder[] = {"NumCols", "NumRows", "C", "l", "t", "r", "b", "W", "H"}; |
|
46 const string KCompDataGraphicOutputOrderMirrored[] = {"NumCols", "NumRows", "C", "r", "t", "l", "b", "W", "H"}; |
|
47 const int KCompDataGraphicOutputOrderSize = ARRAY_LEN(KCompDataGraphicOutputOrder); |
|
48 |
|
49 const string KCompDataTextOutputOrder[] = {"NumCols", "NumRows", "C", "l", "t", "r", "b", "W", "H", "J", "Font"}; |
|
50 const string KCompDataTextOutputOrderMirrored[] = {"NumCols", "NumRows", "C", "r", "t", "l", "b", "W", "H", "J", "Font"}; |
|
51 const int KCompDataTextOutputOrderSize = ARRAY_LEN(KCompDataTextOutputOrder); |
|
52 |
|
53 const string KCompDataKeywordParamHeight = "H"; |
|
54 const string KCompDataKeywordParamType = "Type"; |
|
55 const string KCompDataKeywordParamFont = "Font"; |
|
56 const string KCompDataKeywordParamNumCols = "NumCols"; |
|
57 const string KCompDataKeywordParamNumRows = "NumRows"; |
|
58 const string KCompDataKeywordScreenContents = "Screen Contents"; |
|
59 |
|
60 const string KCompDataKeywordUnderscore = "_"; |
|
61 const string KCompDataKeywordLineNameSuffixGraphic = "g"; |
|
62 const string KCompDataKeywordLineNameSuffixText = "t"; |
|
63 |
|
64 const string KCompDataSearchCollectionNumeric = "0123456789"; |
|
65 const string KCompDataBadValue = "Bad Value"; |
|
66 const string KCompDataLayoutEmpty = "ELayoutEmpty"; |
|
67 const string KCompDataUnknown = "unknown"; |
|
68 |
|
69 const string KCompDataCellNameLeft("l"); |
|
70 const string KCompDataCellNameRight("r"); |
|
71 const string KCompDataCellNameJustification("J"); |
|
72 |
|
73 const string KAttributeNameStyle1 = "style_1"; |
|
74 const string KAttributeNameStyle2 = "style_2"; |
|
75 const string KAttributeNameStyle3 = "style_3"; |
|
76 const string KAttributeNameStyle1Plain = "plain"; |
|
77 const string KAttributeNameStyle1Bold = "bold"; |
|
78 const string KAttributeNameStyle3Outline = "outline"; |
|
79 |
|
80 const string KAttributeNameNumberOfColumns = "Number_of_columns"; |
|
81 const string KAttributeNameNumberOfRows = "Number_of_rows"; |
|
82 const string KAttributeNameNumberOfRowsColsAuto = "AUTO"; |
|
83 |
|
84 |
|
85 // |
|
86 // TMLCompDataValues |
|
87 // |
|
88 |
|
89 TMLCompDataValues::TMLCompDataValues() |
|
90 : |
|
91 iLine(NULL), |
|
92 iName(KCompDataBadValue) |
|
93 { |
|
94 } |
|
95 |
|
96 TMLCompDataValues::TMLCompDataValues(TMLCompDataLine* aLine) |
|
97 : |
|
98 iLine(aLine), |
|
99 iName(aLine->iName) |
|
100 { |
|
101 } |
|
102 |
|
103 bool TMLCompDataValues::operator==(const TMLCompDataValues& aOther) const |
|
104 { |
|
105 typedef const map<int, TMLCompDataZoomLevels> TBase; |
|
106 bool eq = |
|
107 iName == aOther.iName && |
|
108 (*static_cast<TBase*>(this) == aOther); |
|
109 return eq; |
|
110 } |
|
111 |
|
112 TMLCompDataValues::~TMLCompDataValues() |
|
113 { |
|
114 } |
|
115 |
|
116 bool TMLCompDataValues::Merge(TMLCompDataLine* aLine, string aName, TMLCompDataValues& aOtherValues, bool aMirrorMerge) |
|
117 { |
|
118 iLine = aLine; |
|
119 iName = aName; // we may be swapping l and r |
|
120 |
|
121 // create missing values in this line if needed |
|
122 for (iterator pOtherVal=aOtherValues.begin(); pOtherVal!=aOtherValues.end(); ++pOtherVal) |
|
123 { |
|
124 TMLCompDataZoomLevels& otherZoomLevels = pOtherVal->second; |
|
125 TMLCompDataZoomLevels& thisZoomLevels = (*this)[pOtherVal->first]; |
|
126 thisZoomLevels = otherZoomLevels; // we want exactly the correct number of calcs from the other cell |
|
127 if(aMirrorMerge) |
|
128 { |
|
129 if(iName == KCompDataCellNameJustification) |
|
130 { |
|
131 // reverse the justification |
|
132 for(TMLCompDataZoomLevels::iterator pCalcs = thisZoomLevels.begin(); pCalcs != thisZoomLevels.end(); ++pCalcs) |
|
133 { |
|
134 TMLCompDataCalcs& calcs = pCalcs->second; |
|
135 for(TMLCompDataCalcs::iterator pVal = calcs.begin(); pVal != calcs.end(); ++pVal) |
|
136 pVal->second = MirrorJustificationValue(pVal->second); |
|
137 } |
|
138 } |
|
139 } |
|
140 } |
|
141 return true; |
|
142 } |
|
143 |
|
144 const string KParamLimitNames[] = { "NumCols", "NumRows" }; |
|
145 const string KHorizNames[] = { "l", "r", "W" }; |
|
146 const string KVertNames[] = { "t", "b", "H", "Font" }; |
|
147 const set<string> KParamLimitNamesSet(KParamLimitNames, ARRAY_END(KParamLimitNames)); |
|
148 const set<string> KHorizNamesSet(KHorizNames, ARRAY_END(KHorizNames)); |
|
149 const set<string> KVertNamesSet(KVertNames, ARRAY_END(KVertNames)); |
|
150 |
|
151 TMLCompDataValues::TCompDataCellType TMLCompDataValues::Type(string aName) |
|
152 { |
|
153 TMLCompDataValues::TCompDataCellType type; |
|
154 if(KParamLimitNamesSet.find(aName) != KParamLimitNamesSet.end()) |
|
155 { |
|
156 type = TMLCompDataValues::ECellTypeParamLimit; |
|
157 } |
|
158 else if(KHorizNamesSet.find(aName) != KHorizNamesSet.end()) |
|
159 { |
|
160 type = TMLCompDataValues::ECellTypeCol; |
|
161 } |
|
162 else if(KVertNamesSet.find(aName) != KVertNamesSet.end()) |
|
163 { |
|
164 type = TMLCompDataValues::ECellTypeRow; |
|
165 } |
|
166 else |
|
167 { |
|
168 type = TMLCompDataValues::ECellTypeDefault; |
|
169 } |
|
170 return type; |
|
171 } |
|
172 |
|
173 |
|
174 string TMLCompDataValues::MirrorJustificationValue(const string& aValue) |
|
175 { |
|
176 int val = CdlTkUtil::ParseInt(aValue); |
|
177 if(val == ELayoutAlignLeft) |
|
178 val = ELayoutAlignRight; |
|
179 else if(val == ELayoutAlignRight) |
|
180 val = ELayoutAlignLeft; |
|
181 return CdlTkUtil::IntToString(val); |
|
182 } |
|
183 |
|
184 |
|
185 void TMLCompDataValues::Compile(const string& aCellName) |
|
186 { |
|
187 // ensure that missing varieties are filled with null values |
|
188 // we assume that each variety is present in all zoom levels that are defined |
|
189 if(iLine) // screen contents isn't contained in a line |
|
190 { |
|
191 int thisSize = size(); |
|
192 int numVarieties = iLine->MaxVariety() + 1; // get zero based index |
|
193 int maximum = max(numVarieties, thisSize); |
|
194 int maxMulti; |
|
195 switch(TMLCompDataValues::Type(aCellName)) |
|
196 { |
|
197 case ECellTypeCol: |
|
198 maxMulti = iLine->NumCols(); |
|
199 break; |
|
200 case ECellTypeRow: |
|
201 maxMulti = iLine->NumRows(); |
|
202 break; |
|
203 default: |
|
204 maxMulti = 1; |
|
205 break; |
|
206 } |
|
207 for(int ii = 0; ii < maximum; ii++) |
|
208 { |
|
209 // operator[] fills in missing values |
|
210 TMLCompDataZoomLevels& zoomLevels = (*this)[ii]; |
|
211 for(TMLCompDataZoomLevels::iterator pCalcs = zoomLevels.begin(); pCalcs != zoomLevels.end(); ++pCalcs) |
|
212 { |
|
213 TMLCompDataCalcs& calcs = pCalcs->second; |
|
214 if(ii < numVarieties) |
|
215 { |
|
216 if(calcs.size() > maxMulti) |
|
217 { |
|
218 // Handle the case where data from a merged instance has too many calcs |
|
219 TMLCompDataCalcs::iterator start = calcs.find(maxMulti); |
|
220 TMLCompDataCalcs::iterator end = calcs.end(); |
|
221 calcs.erase(start, end); |
|
222 } |
|
223 } |
|
224 else |
|
225 { |
|
226 // get rid of varieties from instances that we have merged onto |
|
227 calcs.clear(); |
|
228 } |
|
229 } |
|
230 } |
|
231 } |
|
232 } |
|
233 |
|
234 string TMLCompDataValues::CppValue(const string& aValue) |
|
235 { |
|
236 if (aValue.size()) |
|
237 return aValue; |
|
238 else |
|
239 return KCompDataLayoutEmpty; |
|
240 } |
|
241 |
|
242 // |
|
243 // TMLCompDataParentInfoSelector |
|
244 // |
|
245 TMLCompDataParentInfoSelector::TMLCompDataParentInfoSelector() |
|
246 { |
|
247 |
|
248 } |
|
249 |
|
250 TMLCompDataParentInfoSelector::TMLCompDataParentInfoSelector(int aParentId, int aParentVariety) |
|
251 : |
|
252 iParentId(aParentId), |
|
253 iParentVariety(aParentVariety) |
|
254 { |
|
255 |
|
256 } |
|
257 |
|
258 // |
|
259 // TMLCompDataParentInfo |
|
260 // |
|
261 |
|
262 TMLCompDataParentInfo::TMLCompDataParentInfo() |
|
263 : |
|
264 iLine(0) |
|
265 { |
|
266 |
|
267 } |
|
268 |
|
269 TMLCompDataParentInfo::TMLCompDataParentInfo(TMLCompDataLine* aLine) |
|
270 : |
|
271 iLine(aLine) |
|
272 { |
|
273 |
|
274 } |
|
275 |
|
276 TMLCompDataParentInfo::~TMLCompDataParentInfo() |
|
277 { |
|
278 |
|
279 } |
|
280 |
|
281 void TMLCompDataParentInfo::Merge(const TMLCompDataParentInfo& aOther) |
|
282 { |
|
283 for (const_iterator pOtherVariety = aOther.begin(); pOtherVariety != aOther.end(); ++pOtherVariety) |
|
284 { |
|
285 int varietyIndex = pOtherVariety->first; |
|
286 const TMLCompDataParentInfoSelector& selector = pOtherVariety->second; |
|
287 insert(make_pair(varietyIndex, selector)); |
|
288 } |
|
289 } |
|
290 |
|
291 // |
|
292 // TMLCompDataLine |
|
293 // |
|
294 |
|
295 TMLCompDataLine::TMLCompDataLine() |
|
296 : iId(0), |
|
297 iIsUnique(true), |
|
298 iIsMirroredHorizontally(false), |
|
299 iType(EUnknownComponent), |
|
300 iName(KCompDataUnknown), |
|
301 iDrawingOrder(-1), |
|
302 iMaxVariety(0), |
|
303 iParentTable(0), |
|
304 iParentInfo(0), |
|
305 iAttributeInfo(0), |
|
306 iNumCols(1), |
|
307 iNumRows(1), |
|
308 iNeedsOptions(false), |
|
309 iNeedsCols(false), |
|
310 iNeedsRows(false), |
|
311 iGlobalIndex(0) |
|
312 { |
|
313 |
|
314 } |
|
315 |
|
316 TMLCompDataLine::TMLCompDataLine(const TMLCompDataLine& aOther) |
|
317 { |
|
318 if(this == &aOther) |
|
319 return; |
|
320 *this = aOther; // this will take a copy of the owning pointer |
|
321 if(aOther.iParentInfo) // if it wasn't zero |
|
322 iParentInfo = new TMLCompDataParentInfo(*(aOther.iParentInfo)); // we don't want to take ownership, so make our own copy |
|
323 if(aOther.iAttributeInfo) // if it wasn't zero |
|
324 iAttributeInfo = new TMLCompDataAttributeInfo(*(aOther.iAttributeInfo)); // we don't want to take ownership, so make our own copy |
|
325 |
|
326 for (iterator pVal = begin(); pVal != end(); ++pVal) |
|
327 { |
|
328 TMLCompDataValues& val = pVal->second; |
|
329 val.iLine = this; |
|
330 } |
|
331 iParentTable = 0; // will be set during compile |
|
332 } |
|
333 |
|
334 bool TMLCompDataLine::operator==(const TMLCompDataLine& aOther) const |
|
335 { |
|
336 return (Name() == aOther.Name()) && ValuesEqual(aOther); |
|
337 } |
|
338 |
|
339 TMLCompDataLine::~TMLCompDataLine() |
|
340 { |
|
341 delete iParentInfo; |
|
342 delete iAttributeInfo; |
|
343 } |
|
344 |
|
345 bool TMLCompDataLine::lessthan(TMLCompDataLine* aLeft, TMLCompDataLine* aRight) |
|
346 { |
|
347 string pureNameLeft = aLeft->NameDiscountingSuffix(); |
|
348 string pureNameRight = aRight->NameDiscountingSuffix(); |
|
349 if(pureNameLeft != pureNameRight) |
|
350 { |
|
351 return (aLeft->iName) < (aRight->iName); |
|
352 } |
|
353 else |
|
354 { |
|
355 int left = CdlTkUtil::ParseInt(aLeft->NameSuffix()); |
|
356 int right = CdlTkUtil::ParseInt(aRight->NameSuffix()); |
|
357 return left < right; |
|
358 } |
|
359 } |
|
360 |
|
361 bool TMLCompDataLine::ValuesEqual(const TMLCompDataLine& aOther) const |
|
362 { |
|
363 bool eq = true; |
|
364 const_iterator pVal, pOther; |
|
365 for (pVal = begin(), pOther = aOther.begin(); |
|
366 eq && pVal != end() && pOther != aOther.end(); |
|
367 ++pVal, ++pOther) |
|
368 { |
|
369 eq = (*pVal == *pOther); |
|
370 } |
|
371 eq = eq && pVal == end() && pOther == aOther.end(); |
|
372 return eq; |
|
373 } |
|
374 |
|
375 string TMLCompDataLine::Name() const |
|
376 { |
|
377 return iName; |
|
378 } |
|
379 |
|
380 bool TMLCompDataLine::Merge(TMLCompDataLine& aOtherLine) |
|
381 { |
|
382 bool compatible = |
|
383 (iId == aOtherLine.iId) || |
|
384 (iName == aOtherLine.iName) || |
|
385 (iType == aOtherLine.iType); |
|
386 if(compatible) |
|
387 { |
|
388 iDrawingOrder = aOtherLine.iDrawingOrder; |
|
389 iMaxVariety = aOtherLine.iMaxVariety; |
|
390 iIsMirroredHorizontally |= aOtherLine.iIsMirroredHorizontally; // in the case of an elaf layout merging onto an abrw layout, the chirality will be preserved |
|
391 iNeedsOptions |= aOtherLine.iNeedsOptions; |
|
392 |
|
393 if(!iParentInfo) |
|
394 { |
|
395 // must be screen... |
|
396 iParentInfo = new TMLCompDataParentInfo(); |
|
397 } |
|
398 if(aOtherLine.iParentInfo) |
|
399 { |
|
400 iParentInfo->Merge(*(aOtherLine.iParentInfo)); |
|
401 } |
|
402 |
|
403 if(!iAttributeInfo) |
|
404 { |
|
405 // must be screen... |
|
406 iAttributeInfo = new TMLCompDataAttributeInfo(); |
|
407 } |
|
408 if(aOtherLine.iAttributeInfo) |
|
409 { |
|
410 iAttributeInfo->Merge(*(aOtherLine.iAttributeInfo)); |
|
411 } |
|
412 |
|
413 // for the API, we need to know if there are any multi-value components in either orientation |
|
414 iNeedsCols = iNeedsCols || aOtherLine.iNeedsCols; |
|
415 iNeedsRows = iNeedsRows || aOtherLine.iNeedsRows; |
|
416 // however, we want exactly the correct number of calcs from the other cell |
|
417 iNumCols = aOtherLine.iNumCols; |
|
418 iNumRows = aOtherLine.iNumRows; |
|
419 |
|
420 // if this line has no values, then we must do a mirror merge |
|
421 bool mirrorMerge = empty() && iIsMirroredHorizontally; |
|
422 |
|
423 // create missing values in this line if needed |
|
424 for (TMLCompDataLine::iterator pOtherValues=aOtherLine.begin(); pOtherValues!=aOtherLine.end(); ++pOtherValues) |
|
425 { |
|
426 string index = pOtherValues->first; |
|
427 if(mirrorMerge) |
|
428 { |
|
429 // flip left and right |
|
430 if(index == KCompDataCellNameLeft) |
|
431 index = KCompDataCellNameRight; |
|
432 else if(index == KCompDataCellNameRight) |
|
433 index = KCompDataCellNameLeft; |
|
434 } |
|
435 |
|
436 (*this)[index].Merge(this, index, pOtherValues->second, mirrorMerge); |
|
437 } |
|
438 } |
|
439 return compatible; |
|
440 } |
|
441 |
|
442 TMLAttributeZoomLevels* TMLCompDataLine::GetAttributeZoomLevels(string aAttribName, int aVariety) |
|
443 { |
|
444 TMLAttributeZoomLevels* found = 0; |
|
445 TMLCompData& data = *(iParentTable->iTables); |
|
446 TMLAttributes& attributes = *(data.iAttributes); |
|
447 int attribId = attributes.iNames[aAttribName]; |
|
448 if(attribId == 0) |
|
449 throw GeneralErr(string("Attribute name not found: ") + aAttribName); |
|
450 // find out from attribute info which attribute set we need |
|
451 // but if there is none specified, we don't need to search |
|
452 if(iAttributeInfo) |
|
453 { |
|
454 TMLCompDataAttributeInfoSelector& selector = (*iAttributeInfo)[aVariety]; |
|
455 // go to parent straight away, as parent always stores attribute data for its children |
|
456 found = GetParentAttributeZoomLevels(selector.iAttributeSetName, attribId, aVariety); |
|
457 } |
|
458 return found; |
|
459 } |
|
460 |
|
461 TMLAttributeZoomLevels* TMLCompDataLine::GetParentAttributeZoomLevels(string aAttribSetName, int aAttribId, int aVariety) |
|
462 { |
|
463 TMLAttributeZoomLevels* found = NULL; |
|
464 TMLCompDataParentInfo::iterator pFoundSelector = iParentInfo->find(aVariety); |
|
465 if(pFoundSelector != iParentInfo->end()) |
|
466 { |
|
467 const TMLCompDataParentInfoSelector& parentInfoSelector = pFoundSelector->second; |
|
468 if(iParentTable && iParentTable->iParentLine) |
|
469 { |
|
470 found = iParentTable->iParentLine->FindAttributeZoomLevels(aAttribSetName, aAttribId); |
|
471 if(!found) |
|
472 { |
|
473 // recurse to next parent container |
|
474 int variety = parentInfoSelector.iParentVariety; |
|
475 iParentTable->iParentLine->GetParentAttributeZoomLevels(aAttribSetName, aAttribId, variety); |
|
476 } |
|
477 } |
|
478 } |
|
479 return found; |
|
480 } |
|
481 |
|
482 TMLAttributeZoomLevels* TMLCompDataLine::FindAttributeZoomLevels(string aAttribSetName, int aAttribId) |
|
483 { |
|
484 TMLCompData& data = *(iParentTable->iTables); |
|
485 TMLAttributes& attributes = *(data.iAttributes); |
|
486 int id = iId; |
|
487 TMLAttributes::iterator foundAttributeSetComponent = attributes.find(id); |
|
488 if(foundAttributeSetComponent != attributes.end()) |
|
489 { |
|
490 TMLAttributeSetComponent& component = foundAttributeSetComponent->second; |
|
491 TMLAttributeSet* pSet = component[aAttribSetName]; |
|
492 if(pSet) |
|
493 { |
|
494 TMLAttributeSet& attributeSet = *pSet; |
|
495 TMLAttributeSet::iterator foundAttrib = attributeSet.find(aAttribId); |
|
496 if(foundAttrib != attributeSet.end()) |
|
497 { |
|
498 return &(foundAttrib->second); |
|
499 } |
|
500 } |
|
501 } |
|
502 return NULL; |
|
503 } |
|
504 |
|
505 void TMLCompDataLine::Compile() |
|
506 { |
|
507 // compile values |
|
508 for(iterator pVal = begin(); pVal != end(); ++pVal) |
|
509 { |
|
510 (pVal->second).Compile(pVal->first); |
|
511 } |
|
512 CompileParamLimits(TMLCompDataValues::ECellTypeCol, KCompDataKeywordParamNumCols); |
|
513 CompileParamLimits(TMLCompDataValues::ECellTypeRow, KCompDataKeywordParamNumRows); |
|
514 CompileFontHeights(); |
|
515 } |
|
516 |
|
517 void TMLCompDataLine::CompileParamLimits(TMLCompDataValues::TCompDataCellType aParamLimitType, const string& aParamLimitCellName) |
|
518 { |
|
519 TMLCompDataValues paramLimits(this); |
|
520 |
|
521 for(iterator pValues = begin(); pValues != end(); ++pValues) |
|
522 { |
|
523 string cellName = pValues->first; |
|
524 if(TMLCompDataValues::Type(cellName) == aParamLimitType) |
|
525 { |
|
526 // calculate the param limits for this cell |
|
527 TMLCompDataValues& values = pValues->second; |
|
528 for(TMLCompDataValues::iterator pZoomLevels = values.begin(); pZoomLevels != values.end(); ++pZoomLevels) |
|
529 { |
|
530 int nextVariety = pZoomLevels->first; |
|
531 TMLCompDataZoomLevels& zoomLevels = pZoomLevels->second; |
|
532 TMLCompDataZoomLevels& paramLimitsZoomLevels = paramLimits[nextVariety]; |
|
533 for(TMLCompDataZoomLevels::iterator pCalcs = zoomLevels.begin(); pCalcs != zoomLevels.end(); ++pCalcs) |
|
534 { |
|
535 // accumulate the largest size of calc into the param limit |
|
536 int zoomLevel = pCalcs->first; |
|
537 int nextParamLimit = pCalcs->second.size(); |
|
538 TMLCompDataCalcs& paramLimitCalcs = paramLimitsZoomLevels[zoomLevel]; |
|
539 string& paramLimit = paramLimitCalcs[0]; |
|
540 int currentParamLimit = CdlTkUtil::ParseInt(paramLimit); |
|
541 if(nextParamLimit > currentParamLimit) |
|
542 paramLimit = CdlTkUtil::IntToString(nextParamLimit); |
|
543 } |
|
544 if(!paramLimitsZoomLevels.size()) |
|
545 { |
|
546 // there were no defined values for this variety, but we know we'll |
|
547 // insert an empty value at least |
|
548 TMLCompDataCalcs& paramLimitCalcs = paramLimitsZoomLevels[EAknUiZoomNormal]; |
|
549 paramLimitCalcs.insert(make_pair(0, CdlTkUtil::IntToString(1))); |
|
550 } |
|
551 } |
|
552 } |
|
553 } |
|
554 insert(make_pair(aParamLimitCellName, paramLimits)); |
|
555 } |
|
556 |
|
557 void TMLCompDataLine::CompileFontHeights() |
|
558 { |
|
559 if(iType == ETextComponent) |
|
560 { |
|
561 TMLCompDataValues font(this); |
|
562 |
|
563 TMLCompDataValues types = (*this)[KCompDataKeywordParamType]; |
|
564 TMLCompDataValues heights = (*this)[KCompDataKeywordParamHeight]; |
|
565 |
|
566 // note that these are the number of varieties, there may be zoom level and then rows inside |
|
567 int numTypeVarieties = types.size(); |
|
568 int numHeightVarieties = heights.size(); |
|
569 |
|
570 for(TMLCompDataValues::iterator pZoomLevels = heights.begin(); pZoomLevels != heights.end(); ++pZoomLevels) |
|
571 { |
|
572 int nextVariety = pZoomLevels->first; |
|
573 TMLAttributeZoomLevels* style1ZoomLevels = GetAttributeZoomLevels(KAttributeNameStyle1, nextVariety); |
|
574 TMLAttributeZoomLevels* style3ZoomLevels = GetAttributeZoomLevels(KAttributeNameStyle3, nextVariety); |
|
575 TMLCompDataZoomLevels& heightsZoomLevels = pZoomLevels->second; |
|
576 TMLCompDataZoomLevels& typesZoomLevels = types[nextVariety]; |
|
577 TMLCompDataZoomLevels& fontZoomLevels = font[nextVariety]; |
|
578 |
|
579 for(TMLCompDataZoomLevels::iterator pHeightCalcs = heightsZoomLevels.begin(); pHeightCalcs != heightsZoomLevels.end(); ++pHeightCalcs) |
|
580 { |
|
581 // if the types don't have zoom data, fall back to normal zoom |
|
582 int zoomIndex = pHeightCalcs->first; |
|
583 int numTypesZoomLevels = typesZoomLevels.size(); |
|
584 int typeZoomIndex = numTypesZoomLevels > 1 ? zoomIndex : EAknUiZoomNormal; |
|
585 TMLCompDataCalcs& typeCalcs = typesZoomLevels[typeZoomIndex]; |
|
586 |
|
587 // get attribute data |
|
588 int outline = 0; |
|
589 int posture = 0; |
|
590 int weight = 0; |
|
591 if(style1ZoomLevels) |
|
592 { |
|
593 string style1 = (*style1ZoomLevels)[pHeightCalcs->first]; |
|
594 if(style1 == KAttributeNameStyle1Bold) |
|
595 weight = 1; |
|
596 } |
|
597 if(style3ZoomLevels) |
|
598 { |
|
599 string style3 = (*style3ZoomLevels)[pHeightCalcs->first]; |
|
600 if(style3 == KAttributeNameStyle3Outline) |
|
601 outline = 1; |
|
602 } |
|
603 |
|
604 // we want to have a font id for each height, even if the spec |
|
605 // has not specified the type each time |
|
606 TMLCompDataCalcs& fontCalcs = fontZoomLevels[pHeightCalcs->first]; |
|
607 TMLCompDataCalcs& next = pHeightCalcs->second; |
|
608 for(TMLCompDataCalcs::iterator pHeightCalc = next.begin(); pHeightCalc != next.end(); ++pHeightCalc) |
|
609 { |
|
610 // for undefined type, let font provider use default, |
|
611 // and always choose the first type for a multi value item |
|
612 int calcIndex = pHeightCalc->first; |
|
613 int type = numTypeVarieties > 0 ? CdlTkUtil::ParseInt(typeCalcs[0]) : ELayoutCompilerFontCategoryUndefined; |
|
614 int height = numHeightVarieties > 0 ? CdlTkUtil::ParseInt(pHeightCalc->second) : 0; |
|
615 int fontId = EncodeFontId(height, outline, posture, weight, type); |
|
616 fontCalcs[calcIndex] = CdlTkUtil::IntToString(fontId); |
|
617 } |
|
618 } |
|
619 } |
|
620 insert(make_pair(string(KCompDataKeywordParamFont), font)); |
|
621 } |
|
622 } |
|
623 |
|
624 int TMLCompDataLine::EncodeFontId(int aHeight, int aOutline, int aPosture, int aWeight, int aCategory) const |
|
625 { |
|
626 // |
|
627 // 31 | 30 - 21 | 20 - 07 | 06 | 05 | 04 | 03 - 00 |
|
628 // encoded | text pane height 0-1023 | <not used> | outline | posture | weight | category |
|
629 |
|
630 int encodedMasked = 1 << 31; |
|
631 int heightMasked = aHeight << 21; |
|
632 |
|
633 int outlineMasked = aOutline << 6; |
|
634 int postureMasked = aPosture << 5; |
|
635 int weightMasked = aWeight << 4; |
|
636 int categoryMasked = aCategory; |
|
637 |
|
638 return(encodedMasked | heightMasked | outlineMasked | postureMasked | weightMasked | categoryMasked); |
|
639 } |
|
640 |
|
641 bool TMLCompDataLine::MatchParams(const TMLCompDataLine& aLine) const |
|
642 { |
|
643 if (NeedsOptions() != aLine.NeedsOptions()) |
|
644 return false; |
|
645 if (NeedsCols() != aLine.NeedsCols()) |
|
646 return false; |
|
647 if (NeedsRows() != aLine.NeedsRows()) |
|
648 return false; |
|
649 return true; |
|
650 } |
|
651 |
|
652 bool TMLCompDataLine::MatchNameDiscountingSuffix(const TMLCompDataLine& aLine) const |
|
653 { |
|
654 // we are trying to compare whether the names are the same apart from a trailing number |
|
655 string pureName = NameDiscountingSuffix(); |
|
656 string pureNameOther = aLine.NameDiscountingSuffix(); |
|
657 string ending = pureName.substr(pureName.find_last_not_of(KCompDataKeywordUnderscore)); |
|
658 |
|
659 bool namesMatch = (pureName == pureNameOther); |
|
660 bool correctEnding = (ending == KCompDataKeywordLineNameSuffixGraphic || ending == KCompDataKeywordLineNameSuffixText); |
|
661 return (namesMatch && correctEnding); |
|
662 } |
|
663 |
|
664 bool TMLCompDataLine::MatchType(const TMLCompDataLine& aLine) const |
|
665 { |
|
666 // first check that the type is equivalent |
|
667 bool equivalent = false; |
|
668 switch(iType) |
|
669 { |
|
670 case ETextComponent: |
|
671 { |
|
672 if(aLine.iType == ETextComponent) |
|
673 { |
|
674 equivalent = true; |
|
675 } |
|
676 break; |
|
677 } |
|
678 case EScreenComponent: |
|
679 case EContainerComponent: |
|
680 case EPaneComponent: |
|
681 case EGraphicComponent: |
|
682 { |
|
683 if(aLine.iType == EScreenComponent |
|
684 || aLine.iType == EContainerComponent |
|
685 || aLine.iType == EPaneComponent |
|
686 || aLine.iType == EGraphicComponent) |
|
687 { |
|
688 equivalent = true; |
|
689 } |
|
690 break; |
|
691 } |
|
692 case EUnknownComponent: |
|
693 default: |
|
694 { |
|
695 if(aLine.iType == EUnknownComponent) |
|
696 { |
|
697 equivalent = true; |
|
698 } |
|
699 break; |
|
700 } |
|
701 } |
|
702 |
|
703 return equivalent; |
|
704 } |
|
705 |
|
706 string TMLCompDataLine::NameDiscountingSuffix() const |
|
707 { |
|
708 int lastNonNumericPos = iName.find_last_not_of(KCompDataSearchCollectionNumeric); |
|
709 int length = lastNonNumericPos + 1; |
|
710 return iName.substr(0, length); |
|
711 } |
|
712 |
|
713 string TMLCompDataLine::NameSuffix() const |
|
714 { |
|
715 int lastNonNumericPos = iName.find_last_not_of(KCompDataSearchCollectionNumeric); |
|
716 int suffixPos = lastNonNumericPos + 1; |
|
717 return iName.substr(suffixPos); |
|
718 } |
|
719 |
|
720 bool TMLCompDataLine::NeedsParams() const |
|
721 { |
|
722 return iNeedsOptions || iNeedsCols || iNeedsRows; |
|
723 } |
|
724 |
|
725 bool TMLCompDataLine::NeedsOptions() const |
|
726 { |
|
727 return iNeedsOptions; |
|
728 } |
|
729 |
|
730 bool TMLCompDataLine::NeedsCols() const |
|
731 { |
|
732 return iNeedsCols; |
|
733 } |
|
734 |
|
735 bool TMLCompDataLine::NeedsRows() const |
|
736 { |
|
737 return iNeedsRows; |
|
738 } |
|
739 |
|
740 int TMLCompDataLine::MaxVariety() const |
|
741 { |
|
742 return iMaxVariety; |
|
743 } |
|
744 |
|
745 int TMLCompDataLine::NumCols() const |
|
746 { |
|
747 return iNumCols; |
|
748 } |
|
749 |
|
750 int TMLCompDataLine::NumRows() const |
|
751 { |
|
752 return iNumRows; |
|
753 } |
|
754 |
|
755 |
|
756 void TMLCompDataLine::SetMaxVariety(int aMaxVariety) |
|
757 { |
|
758 iMaxVariety = aMaxVariety; |
|
759 if(iMaxVariety > 0) // zero based |
|
760 iNeedsOptions = true; |
|
761 } |
|
762 |
|
763 void TMLCompDataLine::SetNumCols(int aNumCols) |
|
764 { |
|
765 iNumCols = aNumCols; |
|
766 if(iNumCols > 1) |
|
767 iNeedsCols = true; |
|
768 } |
|
769 |
|
770 void TMLCompDataLine::SetNumRows(int aNumRows) |
|
771 { |
|
772 iNumRows = aNumRows; |
|
773 if(iNumRows > 1) |
|
774 iNeedsRows = true; |
|
775 } |
|
776 |
|
777 void TMLCompDataLine::SetNeedsCols(bool aNeeds) |
|
778 { |
|
779 iNeedsCols = aNeeds; |
|
780 } |
|
781 |
|
782 void TMLCompDataLine::SetNeedsRows(bool aNeeds) |
|
783 { |
|
784 iNeedsRows = aNeeds; |
|
785 } |
|
786 |
|
787 // |
|
788 // TMLCompDataAttributeInfoSelector |
|
789 // |
|
790 TMLCompDataAttributeInfoSelector::TMLCompDataAttributeInfoSelector() |
|
791 { |
|
792 |
|
793 } |
|
794 |
|
795 TMLCompDataAttributeInfoSelector::TMLCompDataAttributeInfoSelector(string aAttributeSetName) |
|
796 : |
|
797 iAttributeSetName(aAttributeSetName) |
|
798 { |
|
799 |
|
800 } |
|
801 |
|
802 // |
|
803 // TMLCompDataAttributeInfo |
|
804 // |
|
805 |
|
806 TMLCompDataAttributeInfo::TMLCompDataAttributeInfo() |
|
807 : |
|
808 iLine(0) |
|
809 { |
|
810 |
|
811 } |
|
812 |
|
813 TMLCompDataAttributeInfo::TMLCompDataAttributeInfo(TMLCompDataLine* aLine) |
|
814 : |
|
815 iLine(aLine) |
|
816 { |
|
817 |
|
818 } |
|
819 |
|
820 TMLCompDataAttributeInfo::~TMLCompDataAttributeInfo() |
|
821 { |
|
822 |
|
823 } |
|
824 |
|
825 void TMLCompDataAttributeInfo::Merge(const TMLCompDataAttributeInfo& aOther) |
|
826 { |
|
827 for (const_iterator pOtherVariety = aOther.begin(); pOtherVariety != aOther.end(); ++pOtherVariety) |
|
828 { |
|
829 int varietyIndex = pOtherVariety->first; |
|
830 const TMLCompDataAttributeInfoSelector& selector = pOtherVariety->second; |
|
831 insert(make_pair(varietyIndex, selector)); |
|
832 } |
|
833 } |
|
834 |
|
835 |
|
836 |
|
837 // |
|
838 // TMLCompDataTable::TMLCompDataSubTable |
|
839 // |
|
840 |
|
841 bool TMLCompDataTable::TMLCompDataSubTable::NeedsParams() const |
|
842 { |
|
843 return iNeedsOption || iNeedsCol || iNeedsRow; |
|
844 } |
|
845 |
|
846 |
|
847 // |
|
848 // TMLCompDataTable |
|
849 // |
|
850 |
|
851 TMLCompDataTable::TMLCompDataTable(TMLCompData* aTables) |
|
852 : |
|
853 iTables(aTables), |
|
854 iParentLine(NULL), |
|
855 iFirstLineGlobalIndex(-1), |
|
856 iAppend(false), |
|
857 iId(0), |
|
858 iNeedsP(false), |
|
859 iNeedsIndex(false) |
|
860 { |
|
861 } |
|
862 |
|
863 TMLCompDataTable::TMLCompDataTable(TMLCompData* aTables, const TMLCompDataTable& aOther) |
|
864 : |
|
865 iTables(aTables), |
|
866 iParentLine(NULL), |
|
867 iFirstLineGlobalIndex(aOther.iFirstLineGlobalIndex), |
|
868 iAppend(aOther.iAppend), iColumnNames(aOther.iColumnNames), iName(aOther.iName), |
|
869 iParentName(aOther.iParentName), |
|
870 iId(aOther.iId) |
|
871 { |
|
872 for (const_iterator pLine = aOther.begin(); pLine != aOther.end(); ++pLine) |
|
873 push_back(new TMLCompDataLine(**pLine)); |
|
874 } |
|
875 |
|
876 TMLCompDataTable::~TMLCompDataTable() |
|
877 { |
|
878 for (iterator pLine = begin(); pLine != end(); ++pLine) |
|
879 delete *pLine; |
|
880 } |
|
881 |
|
882 bool TMLCompDataTable::lessthan(TMLCompDataTable* aLeft, TMLCompDataTable* aRight) |
|
883 { |
|
884 return (aLeft->iId) < (aRight->iId); |
|
885 } |
|
886 |
|
887 string TMLCompDataTable::Name() |
|
888 { |
|
889 return iName; |
|
890 } |
|
891 |
|
892 TMLCompDataLine* TMLCompDataTable::FindLine(const string& aName) |
|
893 { |
|
894 for (iterator pLine = begin(); pLine != end(); ++pLine) |
|
895 { |
|
896 TMLCompDataLine& line = **pLine; |
|
897 string paramLimitsName = MLCompDataToCdl::LineParamLimitsApiName(line); |
|
898 // first check the lines for a direct match |
|
899 // then try the param limits instead |
|
900 if (line.Name() == aName || |
|
901 (line.NeedsParams() && paramLimitsName == aName)) |
|
902 return *pLine; |
|
903 } |
|
904 return 0; |
|
905 } |
|
906 |
|
907 TMLCompDataTable::TMLCompDataSubTable* TMLCompDataTable::FindSubTable(const string& aName) |
|
908 { |
|
909 for(TMLCompDataSubTables::iterator pSub = iSubTables.begin(); pSub != iSubTables.end(); ++pSub) |
|
910 { |
|
911 TMLCompDataSubTable& sub = **pSub; |
|
912 string subTableName = MLCompDataToCdl::SubTableApiName(sub); |
|
913 string subTableLimitsName = MLCompDataToCdl::SubTableLimitsApiName(sub); |
|
914 string paramLimitsName = MLCompDataToCdl::SubTableParamLimtsApiName(sub); |
|
915 TMLCompDataLine& line = *((*this)[0]); |
|
916 // first check the lines for a direct match |
|
917 // then try the param limits instead |
|
918 if (subTableName == aName || |
|
919 subTableLimitsName == aName || |
|
920 (sub.NeedsParams() && paramLimitsName == aName)) // need to check whether the subtable needs params |
|
921 return ⊂ |
|
922 } |
|
923 return 0; |
|
924 } |
|
925 |
|
926 void TMLCompDataTable::Merge(TMLCompDataTable& aOther) |
|
927 { |
|
928 for (iterator pOtherLine = aOther.begin(); pOtherLine != aOther.end(); ) |
|
929 { |
|
930 TMLCompDataLine* found = FindLine((*pOtherLine)->Name()); |
|
931 if(found) |
|
932 { |
|
933 found->Merge(**pOtherLine); |
|
934 delete *pOtherLine; |
|
935 pOtherLine = aOther.erase(pOtherLine); |
|
936 } |
|
937 else |
|
938 { |
|
939 push_back(*pOtherLine); |
|
940 (*pOtherLine)->iParentTable = this; |
|
941 pOtherLine = aOther.erase(pOtherLine); |
|
942 } |
|
943 } |
|
944 } |
|
945 |
|
946 |
|
947 void TMLCompDataTable::Compile() |
|
948 { |
|
949 SetDefaultColumnNames(); |
|
950 sort(begin(), end(), TMLCompDataLine::lessthan); |
|
951 |
|
952 iNeedsIndex = false; |
|
953 iNeedsP = false; |
|
954 for (iterator pLine = begin(); pLine != end(); ++pLine) |
|
955 { |
|
956 (*pLine)->Compile(); |
|
957 } |
|
958 BuildSubTables(); |
|
959 NormalizeSubTables(); |
|
960 } |
|
961 |
|
962 void TMLCompDataTable::BuildSubTables() |
|
963 { |
|
964 DestroySubTables(); |
|
965 |
|
966 int count = size(); |
|
967 if(count > 0) |
|
968 { |
|
969 TMLCompDataSubTable* subTable = 0; |
|
970 for (int i=0; i<count; i++) |
|
971 { |
|
972 TMLCompDataLine& line = *(*this)[i]; |
|
973 if (subTable) |
|
974 { |
|
975 TMLCompDataLine* firstLine = (*this)[(*subTable)[0]]; |
|
976 if (firstLine->NameSuffix() == "1" && firstLine->MatchNameDiscountingSuffix(line) && firstLine->MatchType(line)) |
|
977 { |
|
978 subTable->iName = line.NameDiscountingSuffix(); |
|
979 } |
|
980 else // only terminate the subtable if the lines don't match, or if the first line isn't numbered "1" |
|
981 { |
|
982 if (subTable->size() > 1) |
|
983 iSubTables.push_back(subTable); |
|
984 else |
|
985 delete subTable; |
|
986 subTable = new TMLCompDataSubTable; |
|
987 } |
|
988 } |
|
989 else |
|
990 { |
|
991 subTable = new TMLCompDataSubTable; |
|
992 } |
|
993 subTable->iNeedsOption |= line.NeedsOptions(); |
|
994 subTable->iNeedsCol |= line.NeedsCols(); |
|
995 subTable->iNeedsRow |= line.NeedsRows(); |
|
996 subTable->push_back(i); |
|
997 } |
|
998 |
|
999 if (subTable->size() > 1) |
|
1000 { |
|
1001 iSubTables.push_back(subTable); |
|
1002 } |
|
1003 else |
|
1004 delete subTable; |
|
1005 } |
|
1006 } |
|
1007 |
|
1008 void TMLCompDataTable::NormalizeSubTables() |
|
1009 { |
|
1010 for(TMLCompDataSubTables::iterator pSub = iSubTables.begin(); pSub != iSubTables.end(); ++pSub) |
|
1011 { |
|
1012 TMLCompDataSubTable& sub = **pSub; |
|
1013 for(TMLCompDataSubTable::iterator pLineId = sub.begin(); pLineId != sub.end(); ++pLineId) |
|
1014 { |
|
1015 TMLCompDataLine& line = *((*this)[*pLineId]); |
|
1016 |
|
1017 line.iNeedsOptions |= sub.iNeedsOption; |
|
1018 line.iNeedsCols |= sub.iNeedsCol; |
|
1019 line.iNeedsRows |= sub.iNeedsRow; |
|
1020 } |
|
1021 } |
|
1022 } |
|
1023 |
|
1024 |
|
1025 void TMLCompDataTable::DestroySubTables() |
|
1026 { |
|
1027 for (TMLCompDataSubTables::iterator pSub = iSubTables.begin(); pSub != iSubTables.end(); ++pSub) |
|
1028 delete *pSub; |
|
1029 iSubTables.clear(); |
|
1030 } |
|
1031 |
|
1032 |
|
1033 const string KValueNames[] = { "Font", "C", "l", "r", "W", "J", "t", "r", "b", "H" }; |
|
1034 const set<string> KValueNamesSet(KValueNames, ARRAY_END(KValueNames)); |
|
1035 |
|
1036 bool TMLCompDataTable::IsValueColumn(string aName) |
|
1037 { |
|
1038 return KValueNamesSet.find(aName) != KValueNamesSet.end(); |
|
1039 } |
|
1040 |
|
1041 const string KNumericNames[] = { "C", "l", "r", "W", "t", "r", "b", "H" }; |
|
1042 const set<string> KNumericNamesSet(KNumericNames, ARRAY_END(KNumericNames)); |
|
1043 |
|
1044 bool TMLCompDataTable::IsNumericColumn(string aName) |
|
1045 { |
|
1046 return KNumericNamesSet.find(aName) != KNumericNamesSet.end(); |
|
1047 } |
|
1048 |
|
1049 const string KHorizontalColumnNames[] = { "l", "r", "W"}; |
|
1050 const set<string> KHorizontalNamesSet(KHorizontalColumnNames, ARRAY_END(KHorizontalColumnNames)); |
|
1051 |
|
1052 bool TMLCompDataTable::IsHorizontalColumn(string aName) |
|
1053 { |
|
1054 return KHorizontalNamesSet.find(aName) != KHorizontalNamesSet.end(); |
|
1055 } |
|
1056 |
|
1057 const string KVerticalColumnNames[] = {"t", "b", "H" }; |
|
1058 const set<string> KVerticalNamesSet(KVerticalColumnNames, ARRAY_END(KVerticalColumnNames)); |
|
1059 |
|
1060 bool TMLCompDataTable::IsVerticalColumn(string aName) |
|
1061 { |
|
1062 return KVerticalNamesSet.find(aName) != KVerticalNamesSet.end(); |
|
1063 } |
|
1064 |
|
1065 |
|
1066 const string KPaneColumnNames[] = {"Item", "C", "l", "t", "r", "b", "W", "H", "Remarks"}; |
|
1067 const string KGraphicColumnNames[] = {"Item", "C", "l", "t", "r", "b", "W", "H", "Remarks"}; |
|
1068 const string KTextColumnNames[] = {"Font", "C", "l", "r", "t", "b", "W", "H", "J", "Remarks"}; |
|
1069 |
|
1070 void TMLCompDataTable::SetDefaultColumnNames() |
|
1071 { |
|
1072 iColumnNames.clear(); |
|
1073 iColumnNames.insert(iColumnNames.end(), KPaneColumnNames, ARRAY_END(KTextColumnNames)); // superset |
|
1074 } |
|
1075 |
|
1076 TMLCompDataTable::TMLCompDataSubTable::TMLCompDataSubTable() |
|
1077 : |
|
1078 iNeedsOption(false), |
|
1079 iNeedsCol(false), |
|
1080 iNeedsRow(false) |
|
1081 { |
|
1082 } |
|
1083 |
|
1084 |
|
1085 // |
|
1086 // TMLCompData |
|
1087 // |
|
1088 |
|
1089 TMLCompData::TMLCompData() |
|
1090 : |
|
1091 iCanBeMirror(false), |
|
1092 iIsBaseInstance(false), |
|
1093 iAttributes(0) |
|
1094 { |
|
1095 } |
|
1096 |
|
1097 TMLCompData::TMLCompData(const TMLCompData& aOther) |
|
1098 { |
|
1099 *this = aOther; |
|
1100 } |
|
1101 |
|
1102 TMLCompData& TMLCompData::operator=(const TMLCompData& aOther) |
|
1103 { |
|
1104 if (this != &aOther) |
|
1105 { |
|
1106 iName = aOther.iName; |
|
1107 iCanBeMirror = aOther.iCanBeMirror; |
|
1108 for (const_iterator pTab = aOther.begin(); pTab != aOther.end(); ++pTab) |
|
1109 push_back(new TMLCompDataTable(this, **pTab)); |
|
1110 Compile(); |
|
1111 } |
|
1112 return *this; |
|
1113 } |
|
1114 |
|
1115 TMLCompData::~TMLCompData() |
|
1116 { |
|
1117 for (iterator pTab = begin(); pTab != end(); ++pTab) |
|
1118 delete *pTab; |
|
1119 DeleteComponents(); |
|
1120 delete iAttributes; |
|
1121 } |
|
1122 |
|
1123 TMLCompDataLine* TMLCompData::FindComponent(const string& aName) const |
|
1124 { |
|
1125 for (TMLComponents::const_iterator pComp = iComponents.begin(); pComp != iComponents.end(); ++pComp) |
|
1126 { |
|
1127 TMLCompDataLine* line = pComp->second; |
|
1128 if (line->Name() == aName) |
|
1129 return line; |
|
1130 } |
|
1131 |
|
1132 return 0; |
|
1133 } |
|
1134 |
|
1135 TMLCompDataLine* TMLCompData::FindLine(const string& aName) const |
|
1136 { |
|
1137 for (const_iterator pTab = begin(); pTab != end(); ++pTab) |
|
1138 { |
|
1139 TMLCompDataLine* line = (*pTab)->FindLine(aName); |
|
1140 if (line) |
|
1141 return line; |
|
1142 } |
|
1143 |
|
1144 return 0; |
|
1145 } |
|
1146 |
|
1147 TMLCompDataTable* TMLCompData::FindTable(const string& aName) const |
|
1148 { |
|
1149 for (const_iterator pTab = begin(); pTab != end(); ++pTab) |
|
1150 { |
|
1151 if ((*pTab)->Name() == aName) |
|
1152 return *pTab; |
|
1153 } |
|
1154 |
|
1155 return 0; |
|
1156 } |
|
1157 |
|
1158 TMLCompDataTable* TMLCompData::FindTable(int aId) const |
|
1159 { |
|
1160 for (const_iterator pTab = begin(); pTab != end(); ++pTab) |
|
1161 { |
|
1162 if ((*pTab)->iId == aId) |
|
1163 return *pTab; |
|
1164 } |
|
1165 |
|
1166 return 0; |
|
1167 } |
|
1168 |
|
1169 TMLCompDataTable::TMLCompDataSubTable* TMLCompData::FindSubTable(const string& aName) const |
|
1170 { |
|
1171 for (const_iterator pTab = begin(); pTab != end(); ++pTab) |
|
1172 { |
|
1173 TMLCompDataTable::TMLCompDataSubTable* sub = (*pTab)->FindSubTable(aName); |
|
1174 if (sub) |
|
1175 return sub; |
|
1176 } |
|
1177 |
|
1178 return 0; |
|
1179 } |
|
1180 |
|
1181 |
|
1182 void TMLCompData::Merge(TMLCompData& aOther) |
|
1183 { |
|
1184 iName = aOther.iName; |
|
1185 iCanBeMirror |= aOther.iCanBeMirror; // in the case of an elaf layout merging onto an abrw layout, the chirality will be preserved |
|
1186 MergeComponents(aOther); |
|
1187 } |
|
1188 |
|
1189 void TMLCompData::MergeComponents(TMLCompData& aOther) |
|
1190 { |
|
1191 for (TMLComponents::iterator pOtherLine = aOther.iComponents.begin(); pOtherLine != aOther.iComponents.end(); ++pOtherLine) |
|
1192 { |
|
1193 TMLCompDataLine& otherLine = *(pOtherLine->second); |
|
1194 TMLCompDataLine* found = FindComponent(otherLine.iName); |
|
1195 if(found) |
|
1196 { |
|
1197 found->Merge(otherLine); |
|
1198 } |
|
1199 else |
|
1200 { |
|
1201 TMLCompDataLine* newLine = new TMLCompDataLine(otherLine); |
|
1202 iComponents.insert(make_pair(otherLine.iId, newLine)); |
|
1203 } |
|
1204 } |
|
1205 } |
|
1206 |
|
1207 void TMLCompData::Compile() |
|
1208 { |
|
1209 CreateTables(); |
|
1210 |
|
1211 // now add a special table for the screen contents |
|
1212 TMLCompDataTable* topTab = new TMLCompDataTable(this); |
|
1213 topTab->iId = -1; |
|
1214 topTab->iName = KCompDataKeywordScreenContents; |
|
1215 |
|
1216 // then insert each line into its parent |
|
1217 for (TMLComponents::iterator pComp2 = iComponents.begin(); pComp2 != iComponents.end(); ++pComp2) |
|
1218 { |
|
1219 TMLCompDataLine& line = *(pComp2->second); |
|
1220 if(line.iType == TMLCompDataLine::EScreenComponent) |
|
1221 { |
|
1222 line.iParentTable = topTab; |
|
1223 topTab->push_back(&line); |
|
1224 } |
|
1225 else |
|
1226 { |
|
1227 bool parentFound = false; |
|
1228 int parentId = 0; |
|
1229 if(line.iParentInfo) |
|
1230 { |
|
1231 TMLCompDataParentInfo& parentInfo = *(line.iParentInfo); |
|
1232 TMLCompDataParentInfoSelector& selector = (parentInfo.begin())->second; // we ignore the varieties for now |
|
1233 parentId = selector.iParentId; |
|
1234 TMLCompDataTable* parentTable = FindTable(parentId); |
|
1235 TMLCompDataLine* parentLine = iComponents[parentId]; |
|
1236 if(parentTable) |
|
1237 { |
|
1238 line.iParentTable = parentTable; |
|
1239 // copy the pointer from the components table |
|
1240 parentTable->push_back(&line); |
|
1241 parentFound = true; |
|
1242 // now insert the table into its place in the tree |
|
1243 parentTable->iParentLine = iComponents[parentId]; |
|
1244 } |
|
1245 else |
|
1246 { |
|
1247 parentFound = false; |
|
1248 } |
|
1249 } |
|
1250 if(!parentFound) |
|
1251 { |
|
1252 string errorText = string(" TMLCompData::Compile() - can't find parent component: "); |
|
1253 errorText += CdlTkUtil::IntToString(parentId); |
|
1254 throw GeneralErr(errorText); |
|
1255 } |
|
1256 } |
|
1257 } |
|
1258 push_back(topTab); |
|
1259 |
|
1260 // remember not to delete the components, as we have taken copies! |
|
1261 iComponents.clear(); |
|
1262 |
|
1263 // now compile the tables |
|
1264 iterator pTab; |
|
1265 for (pTab = begin(); pTab != end(); ++pTab) |
|
1266 (*pTab)->Compile(); |
|
1267 |
|
1268 // now sort the tables |
|
1269 sort(begin(), end(), TMLCompDataTable::lessthan); |
|
1270 } |
|
1271 |
|
1272 void TMLCompData::CreateTables() |
|
1273 { |
|
1274 // from the list of components, first create a table for each pane |
|
1275 for (TMLComponents::iterator pComp = iComponents.begin(); pComp != iComponents.end(); ++pComp) |
|
1276 { |
|
1277 TMLCompDataLine& line = *(pComp->second); |
|
1278 switch(line.iType) |
|
1279 { |
|
1280 case TMLCompDataLine::EScreenComponent: |
|
1281 case TMLCompDataLine::EContainerComponent: |
|
1282 case TMLCompDataLine::EPaneComponent: |
|
1283 { |
|
1284 TMLCompDataTable* tab = new TMLCompDataTable(this); |
|
1285 tab->iId = line.iId; |
|
1286 tab->iName = line.iName; |
|
1287 push_back(tab); |
|
1288 break; |
|
1289 } |
|
1290 case TMLCompDataLine::EGraphicComponent: |
|
1291 case TMLCompDataLine::ETextComponent: |
|
1292 { |
|
1293 // text and graphic components are not panes |
|
1294 // and are therefore not represented in our internal object model as tables |
|
1295 break; |
|
1296 } |
|
1297 default: |
|
1298 { |
|
1299 cout << "TMLCompData::CreateTables() - uncategorised component\n"; |
|
1300 break; |
|
1301 } |
|
1302 } |
|
1303 } |
|
1304 } |
|
1305 |
|
1306 void TMLCompData::DeleteComponents() |
|
1307 { |
|
1308 for (TMLComponents::iterator pComp = iComponents.begin(); pComp != iComponents.end(); ++pComp) |
|
1309 delete pComp->second; |
|
1310 } |
|
1311 |
|
1312 // End of File |