|
1 /* |
|
2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "CppWriter.h" |
|
21 #include "layoutcompilererr.h" |
|
22 #include "CodeGenConsts.h" |
|
23 #include "UsefulDefinitions.h" |
|
24 |
|
25 #include <cdlcompilertoolkit/cdltkutil.h> |
|
26 |
|
27 #include <fstream> |
|
28 #include <algorithm> |
|
29 #include <iostream> // !!! for debug output only |
|
30 |
|
31 using namespace CdlCompilerToolkit; |
|
32 |
|
33 string whiteSpace = " \t\r\n"; |
|
34 |
|
35 const string KTextOutputOrder[] = {"C", "l", "r", "B", "W", "J", "Font"}; |
|
36 const string KTextOutputOrderMirrored[] = {"C", "r", "l", "B", "W", "J", "Font"}; |
|
37 const int KTextOutputOrderSize = ARRAY_LEN(KTextOutputOrder); |
|
38 |
|
39 const string KWindowOutputOrder[] = {"C", "l", "t", "r", "b", "W", "H"}; |
|
40 const string KWindowOutputOrderMirrored[] = {"C", "r", "t", "l", "b", "W", "H"}; |
|
41 const int KWindowOutputOrderSize = ARRAY_LEN(KWindowOutputOrder); |
|
42 |
|
43 // class TValuesCppWriter |
|
44 void TValuesCppWriter::WriteCpp(ostream& aCpp) |
|
45 { |
|
46 for (TValues::const_iterator it = iValues.begin(); it != iValues.end(); ++it) |
|
47 { |
|
48 if (it != iValues.begin()) |
|
49 aCpp << ", "; |
|
50 aCpp << TValues::CppValue(*it); |
|
51 } |
|
52 } |
|
53 |
|
54 |
|
55 // class TLayoutLineCppWriter |
|
56 |
|
57 void TLayoutLineCppWriter::WriteCpp(ostream& aCpp) |
|
58 { |
|
59 // write line structure |
|
60 WriteLineClassName(aCpp); |
|
61 aCpp << Name() << " = { "; |
|
62 WriteCppData(aCpp); |
|
63 aCpp << " };" << endl << endl; |
|
64 } |
|
65 |
|
66 |
|
67 void TLayoutLineCppWriter::WriteCppData(ostream& aCpp) |
|
68 { |
|
69 if (iLine.iNeedsIndex) |
|
70 WriteVarCppData(aCpp); |
|
71 else |
|
72 WriteFixedCppData(aCpp); |
|
73 } |
|
74 |
|
75 |
|
76 int TLayoutLineCppWriter::WriteParamList(ostream& aLag, const vector<string>& aParams) |
|
77 { |
|
78 int written = 0; |
|
79 if (aParams.size() > 0) |
|
80 { |
|
81 written = 2*aParams.size(); |
|
82 aLag << "("; |
|
83 for (vector<string>::const_iterator pParam = aParams.begin(); pParam != aParams.end(); ++pParam) |
|
84 { |
|
85 if (pParam != aParams.begin()) |
|
86 aLag << ", "; |
|
87 aLag << *pParam; |
|
88 written += pParam->size(); |
|
89 } |
|
90 aLag << ")"; |
|
91 } |
|
92 return written; |
|
93 } |
|
94 |
|
95 int TLayoutLineCppWriter::ValCount() |
|
96 { |
|
97 int count = 0; |
|
98 for (TLayoutLine::const_iterator pVal = iLine.begin(); pVal != iLine.end(); ++pVal) |
|
99 { |
|
100 if (TLayoutTable::IsValueColumn(pVal->first)) |
|
101 count += pVal->second.size(); |
|
102 } |
|
103 return count; |
|
104 } |
|
105 |
|
106 |
|
107 // class TWindowLineCppWriter |
|
108 |
|
109 string TWindowLineCppWriter::Name() |
|
110 { |
|
111 if (iLine.iIsUnique) |
|
112 return CdlTkUtil::ToCpp(iLine.Name()); |
|
113 else |
|
114 return CdlTkUtil::ToCpp(iLine.TableName()); |
|
115 } |
|
116 |
|
117 void TWindowLineCppWriter::WriteLineClassName(ostream& aCpp) |
|
118 { |
|
119 if (iLine.iNeedsIndex) |
|
120 { |
|
121 aCpp << "const SVarWindowLine<" << ValCount() << "> "; |
|
122 } |
|
123 else |
|
124 { |
|
125 aCpp << "const SFixedWindowLine "; |
|
126 } |
|
127 } |
|
128 |
|
129 void TWindowLineCppWriter::WriteVarCppData(ostream& aCpp) |
|
130 { |
|
131 aCpp << " { "; // suppress the first offset |
|
132 |
|
133 int offset = 0; |
|
134 for (int i=0; i<KWindowOutputOrderSize-1; i++) // Last offset is not used |
|
135 { |
|
136 offset += iLine[KWindowOutputOrder[i]].size(); |
|
137 if ( i != 0 ) |
|
138 aCpp << ", "; |
|
139 aCpp << offset; |
|
140 } |
|
141 |
|
142 aCpp << " }, { "; |
|
143 |
|
144 WriteFixedCppData(aCpp); |
|
145 |
|
146 aCpp << " }"; |
|
147 } |
|
148 |
|
149 void TWindowLineCppWriter::WriteFixedCppData(ostream& aCpp) |
|
150 { |
|
151 for (int i=0; i<KWindowOutputOrderSize; i++) |
|
152 { |
|
153 if (i>0) |
|
154 aCpp << ", "; |
|
155 TValuesCppWriter writer(iLine[KWindowOutputOrder[i]]); |
|
156 writer.WriteCpp(aCpp); |
|
157 } |
|
158 } |
|
159 |
|
160 void TWindowLineCppWriter::FillParamLists(vector<string>& aDef, vector<string>& aCtor) |
|
161 { |
|
162 if (iLine.iNeedsP) |
|
163 { |
|
164 aDef.push_back(KParamParentRect); |
|
165 aCtor.push_back(KParamParentRect); |
|
166 } |
|
167 |
|
168 if (iLine.iNeedsIndex) |
|
169 { |
|
170 aCtor.push_back(CdlTkUtil::IntToString(iLine.iIsMirroredHorizontally)); |
|
171 |
|
172 for (int i=0; i<KWindowOutputOrderSize; i++) |
|
173 { |
|
174 // need to worry about parameter mirroring here. The problem is that |
|
175 // the macro needs to have a fixed parameter ordering, but the parameters |
|
176 // might vary between variants, therefore the order of mirrored parameters |
|
177 // may vary, e.g. (l, t) becomes (t, r) etc. Solution is to swap l and r if the line is mirrored |
|
178 // just for the macro definition (not for the ctor). |
|
179 string name = KWindowOutputOrder[i]; |
|
180 string nameMirrored = KWindowOutputOrderMirrored[i]; |
|
181 |
|
182 const TValues& defValues = iLine[iLine.iIsMirroredHorizontally ? nameMirrored : name]; |
|
183 if (defValues.iNeedsIndex) |
|
184 { |
|
185 string param = CdlTkUtil::ToCpp(defValues.ParamName()); |
|
186 if (find(aDef.begin(), aDef.end(), param) == aDef.end()) // param Only written once to Macro |
|
187 { |
|
188 aDef.push_back(param); |
|
189 } |
|
190 } |
|
191 |
|
192 const TValues& ctorValues = iLine[name]; |
|
193 if (ctorValues.iNeedsIndex) |
|
194 { |
|
195 string param = CdlTkUtil::ToCpp(ctorValues.ParamName()); |
|
196 aCtor.push_back(param); |
|
197 } |
|
198 else |
|
199 { |
|
200 aCtor.push_back("0"); |
|
201 } |
|
202 } |
|
203 } |
|
204 } |
|
205 |
|
206 void TWindowLineCppWriter::WriteMacro(ostream& aLag) |
|
207 { |
|
208 vector<string> def_params; |
|
209 vector<string> ctor_params; |
|
210 ctor_params.push_back(CdlTkUtil::IntToString(iLine.iGlobalIndex)); |
|
211 |
|
212 FillParamLists(def_params, ctor_params); |
|
213 |
|
214 aLag << "#define AKN_LAYOUT_WINDOW_" << Name(); |
|
215 WriteParamList(aLag, def_params); |
|
216 aLag << "\t" << KTypeWindowLineLayout; |
|
217 WriteParamList(aLag, ctor_params); |
|
218 aLag << endl; |
|
219 } |
|
220 |
|
221 |
|
222 // class TTextLineCppWriter |
|
223 |
|
224 string TTextLineCppWriter::Name() |
|
225 { |
|
226 return CdlTkUtil::ToCpp(iLine.TableName()); |
|
227 } |
|
228 |
|
229 void TTextLineCppWriter::FillParamLists(vector<string>& aDef, vector<string>& aCtor) |
|
230 { |
|
231 iBaseLineVariation = false; |
|
232 |
|
233 if (iLine.iNeedsP) |
|
234 { |
|
235 aDef.push_back(KParamParentRect); |
|
236 aCtor.push_back(KParamParentRect); |
|
237 } |
|
238 |
|
239 if (iLine.iNeedsIndex) |
|
240 { |
|
241 aCtor.push_back(CdlTkUtil::IntToString(iLine.iIsMirroredHorizontally)); |
|
242 |
|
243 for (int i=0; i<KTextOutputOrderSize; i++) |
|
244 { |
|
245 // need to worry about parameter mirroring here. The problem is that |
|
246 // the macro needs to have a fixed parameter ordering, but the parameters |
|
247 // might vary between variants, therefore the order of mirrored parameters |
|
248 // may vary, e.g. (l, t) becomes (t, r) etc. Solution is to swap l and r if the line is mirrored |
|
249 // just for the macro definition (not for the ctor). |
|
250 string name = KTextOutputOrder[i]; |
|
251 string nameMirrored = KTextOutputOrderMirrored[i]; |
|
252 |
|
253 const TValues& defValues = iLine[iLine.iIsMirroredHorizontally ? nameMirrored : name]; |
|
254 if (defValues.iNeedsIndex) |
|
255 { |
|
256 string param = CdlTkUtil::ToCpp(defValues.ParamName()); |
|
257 if (find(aDef.begin(), aDef.end(), param) == aDef.end()) // uniqueness check |
|
258 { |
|
259 aDef.push_back(param); |
|
260 } |
|
261 |
|
262 // record whether some of the variation comes from the Baseline column |
|
263 if ( defValues.iName == "B") |
|
264 iBaseLineVariation = true; |
|
265 } |
|
266 |
|
267 const TValues& ctorValues = iLine[name]; |
|
268 if (ctorValues.iNeedsIndex) |
|
269 { |
|
270 string param = CdlTkUtil::ToCpp(ctorValues.ParamName()); |
|
271 aCtor.push_back(param); |
|
272 } |
|
273 else |
|
274 { |
|
275 aCtor.push_back("0"); |
|
276 } |
|
277 } |
|
278 } |
|
279 } |
|
280 |
|
281 void TTextLineCppWriter::WriteMacro(ostream& aLag) |
|
282 { |
|
283 vector<string> def_params; |
|
284 vector<string> ctor_params; |
|
285 ctor_params.push_back(CdlTkUtil::IntToString(iLine.iGlobalIndex)); |
|
286 |
|
287 FillParamLists(def_params, ctor_params); |
|
288 |
|
289 aLag << "#define AKN_LAYOUT_TEXT_" << Name(); |
|
290 WriteParamList(aLag, def_params); |
|
291 aLag << "\t" << KTypeTextLineLayout; |
|
292 WriteParamList(aLag, ctor_params); |
|
293 aLag << endl; |
|
294 |
|
295 // Also write out a multiline_text if there are more than one Baselines supplied. Number of lines is always user-supplied |
|
296 vector<string> multiline_def_params; |
|
297 vector<string> multiline_ctor_params; |
|
298 |
|
299 if ( iBaseLineVariation ) |
|
300 { |
|
301 multiline_ctor_params.push_back(CdlTkUtil::IntToString(iLine.iGlobalIndex)); |
|
302 |
|
303 if (iLine.iNeedsP) |
|
304 { |
|
305 multiline_def_params.push_back(KParamParentRect); |
|
306 multiline_ctor_params.push_back(KParamParentRect); |
|
307 } |
|
308 |
|
309 if (iLine.iNeedsIndex) // this condition has already been tested when setting iBaseLineVariation, but check again here for completeness |
|
310 { |
|
311 multiline_ctor_params.push_back(CdlTkUtil::IntToString(iLine.iIsMirroredHorizontally)); |
|
312 } |
|
313 |
|
314 for (int i=0; i<KTextOutputOrderSize; i++) |
|
315 { |
|
316 // need to worry about parameter mirroring here. The problem is that |
|
317 // the macro needs to have a fixed parameter ordering, but the parameters |
|
318 // might vary between variants, therefore the order of mirrored parameters |
|
319 // may vary, e.g. (l, t) becomes (t, r) etc. Solution is to swap l and r if the line is mirrored |
|
320 // just for the macro definition (not for the ctor). |
|
321 string name = KTextOutputOrder[i]; |
|
322 string nameMirrored = KTextOutputOrderMirrored[i]; |
|
323 |
|
324 const TValues& defValues = iLine[iLine.iIsMirroredHorizontally ? nameMirrored : name]; |
|
325 if (defValues.iNeedsIndex) |
|
326 { |
|
327 if (defValues.iName != "B") |
|
328 { |
|
329 string param = CdlTkUtil::ToCpp(defValues.ParamName()); |
|
330 if (find(multiline_def_params.begin(), multiline_def_params.end(), param) == multiline_def_params.end()) |
|
331 { |
|
332 multiline_def_params.push_back(param); |
|
333 } |
|
334 // A variable parameter that is tied to the baseline is NOT suppressed in the Multiline |
|
335 // You have to supply the parameter in the macro as a zero |
|
336 } |
|
337 } |
|
338 |
|
339 const TValues& ctorValues = iLine[name]; |
|
340 if (ctorValues.iNeedsIndex) |
|
341 { |
|
342 if (defValues.iName != "B") |
|
343 { |
|
344 string param = CdlTkUtil::ToCpp(ctorValues.ParamName()); |
|
345 multiline_ctor_params.push_back(param); |
|
346 // A variable parameter that is tied to the baseline is NOT suppressed in the Multiline |
|
347 // You have to supply the parameter in the macro as a zero |
|
348 } |
|
349 else |
|
350 { |
|
351 multiline_ctor_params.push_back("0"); |
|
352 } |
|
353 } |
|
354 else |
|
355 { |
|
356 multiline_ctor_params.push_back("0"); |
|
357 } |
|
358 |
|
359 } // end of for loop |
|
360 |
|
361 // The final param for the multiline macro is user input for the layout utilities (pass-through data) |
|
362 multiline_def_params.push_back(KParamNameNumberOfLinesShown); |
|
363 multiline_ctor_params.push_back(KParamNameNumberOfLinesShown); |
|
364 |
|
365 aLag << "#define AKN_LAYOUT_MULTILINE_TEXT_" << Name(); |
|
366 WriteParamList(aLag, multiline_def_params); |
|
367 aLag << "\t" + KTypeMultiLineTextLayout; |
|
368 WriteParamList(aLag, multiline_ctor_params); |
|
369 aLag << endl; |
|
370 } // end of if on baseline_variation |
|
371 } |
|
372 |
|
373 |
|
374 void TTextLineCppWriter::WriteLineClassName(ostream& aCpp) |
|
375 { |
|
376 if (iLine.iNeedsIndex) |
|
377 { |
|
378 aCpp << "const SVarTextLine<" << ValCount() << "> "; |
|
379 } |
|
380 else |
|
381 { |
|
382 aCpp << "const SFixedTextLine "; |
|
383 } |
|
384 } |
|
385 |
|
386 void TTextLineCppWriter::WriteVarCppData(ostream& aCpp) |
|
387 { |
|
388 aCpp << " { "; // ! Do not write out the first 0 |
|
389 |
|
390 int offset = 0; |
|
391 for (int i=0; i<KTextOutputOrderSize-1; i++) // last offset IS used because font id is written out |
|
392 { |
|
393 offset += iLine[KTextOutputOrder[i]].size(); |
|
394 if ( i != 0 ) |
|
395 aCpp << ", "; |
|
396 aCpp << offset; |
|
397 } |
|
398 |
|
399 aCpp << " }, { "; |
|
400 |
|
401 WriteFixedCppData(aCpp); |
|
402 |
|
403 aCpp << " }"; |
|
404 } |
|
405 |
|
406 void TTextLineCppWriter::WriteFixedCppData(ostream& aCpp) |
|
407 { |
|
408 for (int i=0; i<KTextOutputOrderSize; i++) |
|
409 { |
|
410 if ( i > 0 ) |
|
411 aCpp << ", "; |
|
412 TValuesCppWriter writer(iLine[KTextOutputOrder[i]]); |
|
413 writer.WriteCpp(aCpp); |
|
414 } |
|
415 } |
|
416 |
|
417 void TTextLineCppWriter::WriteMultiLineTextParamList(ostream& aLag, const vector<string>& aParams) |
|
418 { |
|
419 if (aParams.size() > 0) |
|
420 { |
|
421 aLag << "("; |
|
422 for (vector<string>::const_iterator pParam = aParams.begin(); pParam != aParams.end(); ++pParam) |
|
423 { |
|
424 if (pParam != aParams.begin()) |
|
425 aLag << ", "; |
|
426 aLag << *pParam; |
|
427 } |
|
428 aLag << ", " << KParamNameNumberOfLinesShown; |
|
429 aLag << ")"; |
|
430 } |
|
431 } |
|
432 |
|
433 |
|
434 // class TLayoutTableCppWriter |
|
435 |
|
436 void TLayoutTableCppWriter::WriteCppLineData(ostream& aCpp) |
|
437 { |
|
438 for (TLayoutTable::iterator it = iTable.begin(); it != iTable.end(); ++it) |
|
439 { |
|
440 TLayoutLineCppWriter* writer = CreateLayoutLineCppWriter(**it, iTable); |
|
441 writer->WriteCpp(aCpp); |
|
442 delete writer; |
|
443 } |
|
444 } |
|
445 |
|
446 void TLayoutTableCppWriter::WriteCppTableData(ostream& aCpp) |
|
447 { |
|
448 } |
|
449 |
|
450 void TLayoutTableCppWriter::WriteLag(ostream& aLag) |
|
451 { |
|
452 aLag << endl; |
|
453 int count=0; |
|
454 for (TLayoutTable::TLayoutSubTables::iterator it = iTable.iSubTables.begin(); it != iTable.iSubTables.end(); ++it) |
|
455 { |
|
456 WriteLagSubTable(**it, count++, aLag); |
|
457 } |
|
458 } |
|
459 |
|
460 |
|
461 void TLayoutTableCppWriter::WriteLagSubTable(const TLayoutTable::TLayoutSubTable& aSubTable, int aCount, ostream& aLag) |
|
462 { |
|
463 // normal version |
|
464 string macro = "#define AKN_LAYOUT_TABLE_"; |
|
465 macro = macro + CdlTkUtil::ToCpp(iTable.Name()); |
|
466 if (aSubTable.size() != iTable.size()) |
|
467 { |
|
468 macro = macro + "_SUB_TABLE_" + CdlTkUtil::IntToString(aCount); |
|
469 aLag << "// Sub table for " << iTable.Name() << ". Valid line indices are "; |
|
470 for (TLayoutTable::TLayoutSubTable::const_iterator pNum = aSubTable.begin(); pNum != aSubTable.end(); ++pNum) |
|
471 { |
|
472 if (pNum != aSubTable.begin()) |
|
473 aLag << ", "; |
|
474 aLag << CdlTkUtil::IntToString(*pNum); |
|
475 } |
|
476 aLag << endl; |
|
477 } |
|
478 |
|
479 aLag << macro; |
|
480 |
|
481 int lineSet = 0; |
|
482 for (TLayoutTable::TLayoutSubTable::const_iterator pNum = aSubTable.begin(); pNum != aSubTable.end(); ++pNum) |
|
483 { |
|
484 if (*pNum < 32) |
|
485 lineSet |= (1 << *pNum); |
|
486 } |
|
487 |
|
488 vector<string> def_params; |
|
489 def_params.push_back(KParamLineIndex); |
|
490 vector<string> ctor_params; |
|
491 ctor_params.push_back(CdlTkUtil::IntToString(iTable.iFirstLineGlobalIndex)); |
|
492 ctor_params.push_back(KParamLineIndex); |
|
493 ctor_params.push_back(CdlTkUtil::IntToHexString(lineSet)); |
|
494 |
|
495 TLayoutLineCppWriter* writer = CreateLayoutLineCppWriter(*iTable[aSubTable[0]], iTable); |
|
496 writer->FillParamLists(def_params, ctor_params); |
|
497 int paramSize = writer->WriteParamList(aLag, def_params); |
|
498 |
|
499 // some maths to make bigger tabulation |
|
500 int numTabs = 6-(((paramSize+macro.size())/4)%6); |
|
501 for (int i=0; i<numTabs; i++) |
|
502 aLag << "\t"; |
|
503 |
|
504 if (iTable.iType == TLayoutTable::EWindowTable) |
|
505 aLag << KTypeWindowLineLayout; |
|
506 else |
|
507 aLag << KTypeTextLineLayout; |
|
508 writer->WriteParamList(aLag, ctor_params); |
|
509 aLag << endl; |
|
510 |
|
511 delete writer; |
|
512 } |
|
513 |
|
514 TLayoutLineCppWriter* TLayoutTableCppWriter::CreateLayoutLineCppWriter(TLayoutLine& aLine, TLayoutTable& aTable) |
|
515 { |
|
516 if (aTable.iType == TLayoutTable::EWindowTable) |
|
517 return new TWindowLineCppWriter(aLine); |
|
518 else |
|
519 return new TTextLineCppWriter(aLine); |
|
520 } |
|
521 |
|
522 |
|
523 // class TLayoutCppWriter |
|
524 |
|
525 void TLayoutCppWriter::WriteCppLineData(ostream& aCpp) |
|
526 { |
|
527 for (TLayout::iterator it = iLayout.begin(); it != iLayout.end(); ++it) |
|
528 { |
|
529 TLayoutTableCppWriter writer(**it); |
|
530 writer.WriteCppLineData(aCpp); |
|
531 } |
|
532 } |
|
533 |
|
534 void TLayoutCppWriter::WriteCppTableData(ostream& aCpp) |
|
535 { |
|
536 } |
|
537 |
|
538 void TLayoutCppWriter::WriteLag(ostream& aLag) |
|
539 { |
|
540 aLag << endl << endl << "// Layout MACROs for indexed table access" << endl; |
|
541 // write the macros |
|
542 for (TLayout::iterator it = iLayout.begin(); it != iLayout.end(); ++it) |
|
543 { |
|
544 TLayoutTable& table = **it; |
|
545 if (table.IsWorthATableIndex()) |
|
546 { |
|
547 TLayoutTableCppWriter writer(table); |
|
548 writer.WriteLag(aLag); |
|
549 } |
|
550 } |
|
551 |
|
552 aLag << endl << "#endif " << endl; |
|
553 } |
|
554 |
|
555 |
|
556 // class TLayoutLineTable |
|
557 |
|
558 void TLayoutLineTable::WriteCpp(ostream& aCpp) |
|
559 { |
|
560 aCpp << "const TAny* const KTheLineTable[] =" << endl << "\t{" << endl << "\t"; |
|
561 int index = 0; |
|
562 for (iterator it = begin(); it != end(); ++it) |
|
563 { |
|
564 TLayoutLine& line = **it; |
|
565 TLayoutTable& table = *line.iTable; |
|
566 if (table.iFirstLineGlobalIndex == -1) |
|
567 table.iFirstLineGlobalIndex = index; |
|
568 TLayoutLineCppWriter* writer = TLayoutTableCppWriter::CreateLayoutLineCppWriter(line, table); |
|
569 if (it != begin()) |
|
570 aCpp << "," << endl << "\t"; |
|
571 aCpp << "&" << writer->Name(); |
|
572 delete writer; |
|
573 index++; |
|
574 } |
|
575 aCpp << endl << "\t};" << endl; |
|
576 } |
|
577 |
|
578 void TLayoutLineTable::WriteLag(ostream& aLag) |
|
579 { |
|
580 string current_table_name = ""; |
|
581 |
|
582 for (iterator it = begin(); it != end(); ++it) |
|
583 { |
|
584 TLayoutLine& line = **it; |
|
585 |
|
586 if ( current_table_name != line.iTable->Name() ) |
|
587 { |
|
588 aLag << endl << "//" << " Layout MACROs for LAF Table : " << line.iTable->Name() << endl ; |
|
589 current_table_name = line.iTable->Name(); |
|
590 } |
|
591 |
|
592 TLayoutLineCppWriter* writer = TLayoutTableCppWriter::CreateLayoutLineCppWriter(line, *line.iTable); |
|
593 writer->WriteMacro(aLag); |
|
594 delete writer; |
|
595 } |
|
596 } |
|
597 |
|
598 |
|
599 // class TLayoutLineTable |
|
600 |
|
601 TCppWriter::TCppWriter(TLayout& aLayout, const std::string& aName) |
|
602 : TLayWriterBase(aLayout, aName) |
|
603 { |
|
604 } |
|
605 |
|
606 void TCppWriter::Write(const std::string& aLayName) |
|
607 { |
|
608 std::string lay = aLayName.substr(aLayName.find_last_of('\\')+1); |
|
609 lay = lay.substr(0, lay.find_first_of('.')); |
|
610 |
|
611 iShortName = iName.substr(iName.find_last_of('\\')+1); |
|
612 iName = iName.substr(0, iName.find_first_of('.')) + lay; |
|
613 |
|
614 BuildLayoutLineTable(); |
|
615 CCdlTkFileCleanup temp(iName+".lag"); |
|
616 Output(iName+".cpp", iName+".lag", lay); |
|
617 CdlTkUtil::ExportFile(temp, KDirEpocSysHeader+iShortName+".lag"); |
|
618 } |
|
619 |
|
620 void TCppWriter::Output(const string& aCpp, const string& aLag, const string& aLayName) |
|
621 { |
|
622 cout << "writing cpp " << aCpp << endl; |
|
623 ofstream cpp(aCpp.c_str()); |
|
624 WriteCppHeader(cpp); |
|
625 TLayoutCppWriter writer(iLayout); |
|
626 writer.WriteCppLineData(cpp); |
|
627 iLineTable.WriteCpp(cpp); |
|
628 writer.WriteCppTableData(cpp); |
|
629 WriteCppFooter(cpp, aLayName); |
|
630 cpp.close(); |
|
631 |
|
632 cout << "writing header " << aLag << endl; |
|
633 ofstream lag(aLag.c_str()); |
|
634 WriteLagHeader(lag); |
|
635 iLineTable.WriteLag(lag); |
|
636 writer.WriteLag(lag); |
|
637 lag.close(); |
|
638 } |
|
639 |
|
640 void TCppWriter::BuildLayoutLineTable() |
|
641 { |
|
642 int globalIndex = 0; |
|
643 for (TLayout::const_iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab) |
|
644 { |
|
645 for (TLayoutTable::const_iterator pLine = (*pTab)->begin(); pLine != (*pTab)->end(); ++pLine) |
|
646 { |
|
647 (*pLine)->iGlobalIndex = globalIndex++; |
|
648 iLineTable.push_back(*pLine); |
|
649 } |
|
650 } |
|
651 } |
|
652 |
|
653 void TCppWriter::WriteCppHeader(ostream& aCpp) |
|
654 { |
|
655 aCpp << "/*" << endl; |
|
656 aCpp << "* ============================================================================" << endl; |
|
657 aCpp << "* Name : " << iShortName << ".cpp" << endl; |
|
658 aCpp << "* Part of : Avkon" << endl; |
|
659 aCpp << "*" << endl; |
|
660 aCpp << "* Description: This file is automatically generated layout data file." << endl; |
|
661 aCpp << "*" << endl; |
|
662 aCpp << "* Version :" << endl; |
|
663 aCpp << "*" << endl; |
|
664 aCpp << "* Copyright © 2002-2004 Nokia Corporation." << endl; |
|
665 aCpp << "* This material, including documentation and any related" << endl; |
|
666 aCpp << "* computer programs, is protected by copyright controlled by" << endl; |
|
667 aCpp << "* Nokia Corporation. All rights are reserved. Copying,"<< endl; |
|
668 aCpp << "* including reproducing, storing, adapting or translating, any" << endl; |
|
669 aCpp << "* or all of this material requires the prior written consent of" << endl; |
|
670 aCpp << "* Nokia Corporation. This material also contains confidential" << endl; |
|
671 aCpp << "* information which may not be disclosed to others without the" << endl; |
|
672 aCpp << "* prior written consent of Nokia Corporation." << endl; |
|
673 aCpp << "* ============================================================================" << endl; |
|
674 aCpp << "*/" << endl << endl; |
|
675 aCpp << "#include \"aknlayoutdatadef.h\"" << endl << endl; |
|
676 } |
|
677 |
|
678 void TCppWriter::WriteCppFooter(ostream& aCpp, const string& aLayName) |
|
679 { |
|
680 aCpp << endl << "const TAny* GetData_" << aLayName << "(" << KTypeInt << " aLineId) { return KTheLineTable[aLineId]; }" << endl; |
|
681 } |
|
682 |
|
683 void TCppWriter::WriteLagHeader(ostream& aLag) |
|
684 { |
|
685 aLag << "/*" << endl; |
|
686 aLag << "* ============================================================================" << endl; |
|
687 aLag << "* Name : " << iShortName << ".lag" << endl; |
|
688 aLag << "* Part of : Avkon" << endl; |
|
689 aLag << "*" << endl; |
|
690 aLag << "* Description: This file is automatically generated layout file." << endl; |
|
691 aLag << "*" << endl; |
|
692 aLag << "* Version :" << endl; |
|
693 aLag << "*" << endl; |
|
694 aLag << "* Copyright © 2002-2004 Nokia Corporation." << endl; |
|
695 aLag << "* This material, including documentation and any related" << endl; |
|
696 aLag << "* computer programs, is protected by copyright controlled by" << endl; |
|
697 aLag << "* Nokia Corporation. All rights are reserved. Copying,"<< endl; |
|
698 aLag << "* including reproducing, storing, adapting or translating, any" << endl; |
|
699 aLag << "* or all of this material requires the prior written consent of" << endl; |
|
700 aLag << "* Nokia Corporation. This material also contains confidential" << endl; |
|
701 aLag << "* information which may not be disclosed to others without the" << endl; |
|
702 aLag << "* ============================================================================" << endl; |
|
703 aLag << "*/" << endl << endl; |
|
704 aLag << "#if !defined(__" << iShortName << "_LAG__)" << endl; |
|
705 aLag << "#define __" << iShortName << "_LAG__" << endl; |
|
706 aLag << "#include <aknlayoutdef.h>" << endl << endl; |
|
707 } |
|
708 |
|
709 // End of File |