|
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 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
20 #pragma warning (disable:4786) |
|
21 |
|
22 #include "lay2MLInst.h" |
|
23 #include "LayoutParse.h" |
|
24 #include "LayoutCompilerErr.h" |
|
25 |
|
26 #include <fstream> |
|
27 #include <iostream> |
|
28 #include <algorithm> |
|
29 #include "MLInstWriter.h" |
|
30 //#include "MLInstParse.h" |
|
31 |
|
32 string TextOutputOrder(int aIndex, bool aMirrored); |
|
33 string WindowOutputOrder(int aIndex, bool aMirrored); |
|
34 |
|
35 using namespace std; |
|
36 |
|
37 class LayoutToMLInstArgsErr : public LayoutCompilerErr |
|
38 { |
|
39 void Show(ostream& aStream) const; |
|
40 }; |
|
41 |
|
42 void LayoutToMLInstArgsErr::Show(ostream& stream) const |
|
43 { |
|
44 LayoutToMLInst::ShowHelp(stream); |
|
45 } |
|
46 |
|
47 string LayoutToMLInst::InterfaceName(const string& aFileName) |
|
48 { |
|
49 return aFileName.substr(0,aFileName.find_last_of('.')); |
|
50 } |
|
51 |
|
52 int LayoutToMLInst::Process(const vector<string>& args) |
|
53 { |
|
54 if (args.size() != 4) |
|
55 throw LayoutToMLInstArgsErr(); |
|
56 |
|
57 // first read in the lay file |
|
58 string layoutName = args[2]; |
|
59 auto_ptr<TLayParseLayout> layoutParse(TLayParseLayout::Parse(layoutName)); |
|
60 |
|
61 // then convert it to internal structure format |
|
62 auto_ptr<TMLInst> mlInst(LayoutToInst(*layoutParse)); |
|
63 |
|
64 // finally write out the structure XML |
|
65 string xmlName = args[3]; |
|
66 cout << "writing XML file " << xmlName << endl; |
|
67 TMLInstWriter writer(*mlInst, xmlName); |
|
68 writer.Write(layoutName); |
|
69 return 0; |
|
70 } |
|
71 |
|
72 void LayoutToMLInst::ShowHelp(ostream& stream) |
|
73 { |
|
74 stream << "Lay2MLInst <layoutName> <instXmlName>" << endl; |
|
75 } |
|
76 |
|
77 auto_ptr<TMLInst> LayoutToMLInst::LayoutToInst(const TLayout& aLayout) |
|
78 { |
|
79 auto_ptr<TMLInst> mlInst(new TMLInst); |
|
80 |
|
81 for (TLayout::const_iterator pTab = aLayout.begin(); pTab != aLayout.end(); ++pTab) |
|
82 { |
|
83 AddTableToInst(*mlInst, **pTab); |
|
84 } |
|
85 |
|
86 return mlInst; |
|
87 } |
|
88 |
|
89 void LayoutToMLInst::AddTableToInst(TMLInst& aInst, TLayoutTable& aTable) |
|
90 { |
|
91 TMLInstTable* instTable = new TMLInstTable(&aInst, aTable); |
|
92 |
|
93 for (TLayoutTable::iterator pLine = aTable.begin(); pLine != aTable.end(); ++pLine) |
|
94 { |
|
95 if (aTable.iType == TLayoutTable::EWindowTable) |
|
96 AddWindowLineToInstTable(*instTable, **pLine); |
|
97 else |
|
98 AddTextLineToInstTable(*instTable, **pLine); |
|
99 } |
|
100 |
|
101 /* |
|
102 int tableNum = 0; |
|
103 for (TLayoutTable::TLayoutSubTables::const_iterator pSub = aTable.iSubTables.begin(); pSub != aTable.iSubTables.end(); ++pSub) |
|
104 { |
|
105 AddTableLimitsToInterface(aInterface, aTable, **pSub, tableNum); |
|
106 if (aTable.iType == TLayoutTable::EWindowTable) |
|
107 AddSubTableToInterface("TAknWindowLineLayout", aInterface, aTable, **pSub, tableNum); |
|
108 else |
|
109 AddSubTableToInterface("TAknTextLineLayout", aInterface, aTable, **pSub, tableNum); |
|
110 tableNum++; |
|
111 } |
|
112 */ |
|
113 aInst.push_back(instTable); |
|
114 } |
|
115 |
|
116 void LayoutToMLInst::AddWindowLineToInstTable(TMLInstTable& aInstTable, TLayoutLine& aLine) |
|
117 { |
|
118 TMLInstLine* instLine = new TMLInstLine(&aInstTable, aLine); |
|
119 /* |
|
120 CCdlTkApi* api = CreateGenericApi(aInterface, aLine); |
|
121 api->SetName(LineApiName(aLine)); |
|
122 api->SetReturnType("TAknWindowLineLayout"); |
|
123 aInterface.ApiList().push_back(api); |
|
124 */ |
|
125 |
|
126 |
|
127 // add a value for each top level cell |
|
128 for (int i=0; i<7; i++) |
|
129 { |
|
130 string cellName = WindowOutputOrder(i, false); |
|
131 // WriteCell(line, cellName, aLine[cellName]); |
|
132 AddParamToLine(*instLine, aLine[cellName]); |
|
133 } |
|
134 |
|
135 /* |
|
136 for(TLayoutLine::iterator pValue = aLine.begin(); pValue != aLine.end(); ++pValue) |
|
137 { |
|
138 AddParamToLine(instLine, *pValue); |
|
139 } |
|
140 */ |
|
141 aInstTable.push_back(instLine); |
|
142 } |
|
143 |
|
144 void LayoutToMLInst::AddTextLineToInstTable(TMLInstTable& aInstTable, TLayoutLine& aLine) |
|
145 { |
|
146 TMLInstLine* instLine = new TMLInstLine(&aInstTable, aLine); |
|
147 |
|
148 /* |
|
149 CCdlTkApi* api = CreateGenericApi(aInterface, aLine); |
|
150 |
|
151 api->SetName(LineApiName(aLine)); |
|
152 api->SetReturnType("TAknTextLineLayout"); |
|
153 |
|
154 aInterface.ApiList().push_back(api); |
|
155 */ |
|
156 |
|
157 for (int i=0; i<6; i++) |
|
158 { |
|
159 string cellName = TextOutputOrder(i, false); |
|
160 // WriteCell(line, cellName, aLine[cellName]); |
|
161 AddParamToLine(*instLine, aLine[cellName]); |
|
162 } |
|
163 |
|
164 /* |
|
165 for(TLayoutLine::iterator pValue = aLine.begin(); pValue != aLine.end(); ++pValue) |
|
166 { |
|
167 AddParamToLine(instLine, *pValue); |
|
168 } |
|
169 */ |
|
170 aInstTable.push_back(instLine); |
|
171 |
|
172 |
|
173 /* |
|
174 TValues& v = aLine["B"]; |
|
175 if (v.size()>1) |
|
176 { |
|
177 CCdlTkFunctionApi* multiline = static_cast<CCdlTkFunctionApi*>(CreateGenericApi(aInterface, aLine)); |
|
178 CCdlTkApiParams& params = multiline->Params(); |
|
179 CCdlTkApiParams::iterator pParam = params.FindByName("aIndex_B"); |
|
180 if (pParam != params.end()) |
|
181 params.erase(pParam); |
|
182 params.push_back(CCdlTkApiParam("TInt", "aNumberOfLinesShown")); |
|
183 |
|
184 multiline->SetName(string("Multiline_") + LineApiName(aLine)); |
|
185 multiline->SetReturnType("TAknMultiLineTextLayout"); |
|
186 |
|
187 aInterface.ApiList().push_back(multiline); |
|
188 } |
|
189 */ |
|
190 } |
|
191 |
|
192 /* |
|
193 string LayoutToMLInst::TableApiName(TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum) |
|
194 { |
|
195 if (aTable.size() == aSubTable.size()) |
|
196 return CdlTkUtil::ToCpp(aTable.Name()); |
|
197 else |
|
198 return CdlTkUtil::ToCpp(aTable.Name()) + "_SUB_TABLE_" + IntToString(aSubTableNum); |
|
199 } |
|
200 |
|
201 string LayoutToMLInst::LineApiName(TLayoutLine& aLine) |
|
202 { |
|
203 if (aLine.iTable->iType == TLayoutTable::EWindowTable) |
|
204 { |
|
205 TWindowLineCppWriter writer(aLine); |
|
206 return writer.Name(); |
|
207 } |
|
208 else |
|
209 { |
|
210 TTextLineCppWriter writer(aLine); |
|
211 return writer.Name(); |
|
212 } |
|
213 } |
|
214 |
|
215 void LayoutToMLInst::AddSubTableToInterface(const string& aType, CCdlTkInterface& aInterface, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum) |
|
216 { |
|
217 TLayoutLine& line = *aTable[aSubTable[0]]; |
|
218 CCdlTkFunctionApi* api = new CCdlTkFunctionApi(aInterface); |
|
219 api->Params().push_back(CCdlTkApiParam("TInt", "aLineIndex")); |
|
220 AddParamsToFunc(line, *api); |
|
221 |
|
222 api->SetReturnType(aType); |
|
223 |
|
224 api->SetName(TableApiName(aTable, aSubTable, aSubTableNum)); |
|
225 |
|
226 aInterface.ApiList().push_back(api); |
|
227 } |
|
228 |
|
229 void LayoutToMLInst::AddTableLimitsToInterface(CCdlTkInterface& aInterface, TLayoutTable& aTable, TLayoutTable::TLayoutSubTable& aSubTable, int aSubTableNum) |
|
230 { |
|
231 CCdlTkFunctionApi* api = new CCdlTkFunctionApi(aInterface); |
|
232 api->SetReturnType("TAknLayoutTableLimits"); |
|
233 api->SetName(TableApiName(aTable, aSubTable, aSubTableNum)+"_Limits"); |
|
234 aInterface.ApiList().push_back(api); |
|
235 } |
|
236 |
|
237 CCdlTkApi* LayoutToMLInst::CreateGenericApi(CCdlTkInterface& aInterface, TLayoutLine& aLine) |
|
238 { |
|
239 CCdlTkFunctionApi* func = new CCdlTkFunctionApi(aInterface); |
|
240 AddParamsToFunc(aLine, *func); |
|
241 return func; |
|
242 } |
|
243 |
|
244 void LayoutToMLInst::AddParamsToFunc(TLayoutLine& aLine, CCdlTkFunctionApi& aFunc) |
|
245 { |
|
246 CCdlTkApiParams& params = aFunc.Params(); |
|
247 |
|
248 if (aLine.iNeedsP) |
|
249 params.push_back(CCdlTkApiParam("const TRect&", "aParentRect")); |
|
250 |
|
251 if (aLine.iNeedsIndex) |
|
252 { |
|
253 const string* KParams; |
|
254 int count; |
|
255 if (aLine.iTable->iType == TLayoutTable::EWindowTable) |
|
256 { |
|
257 KParams = KWindowOutputOrder; |
|
258 count = KWindowOutputOrderSize; |
|
259 } |
|
260 else |
|
261 { |
|
262 KParams = KTextOutputOrder; |
|
263 count = KTextOutputOrderSize; |
|
264 } |
|
265 |
|
266 for (int i=0; i<count; i++) |
|
267 { |
|
268 const string& name = KParams[i]; |
|
269 |
|
270 const TValues& defValues = aLine[name]; |
|
271 if (defValues.iNeedsIndex) |
|
272 { |
|
273 CCdlTkApiParam param("TInt", CdlTkUtil::ToCpp(defValues.ParamName())); |
|
274 if (params.FindByName(param.Name()) == params.end()) |
|
275 params.push_back(param); |
|
276 } |
|
277 } |
|
278 } |
|
279 } |
|
280 |
|
281 */ |
|
282 |
|
283 void LayoutToMLInst::AddParamToLine(TMLInstLine& aInstLine, TValues& aValue) |
|
284 { |
|
285 // CCdlTkApiParams& params = aFunc.Params(); |
|
286 |
|
287 TMLInstParam* instLine = new TMLInstParam(&aInstLine, aValue); |
|
288 |
|
289 for(TValues::iterator pInt = aValue.begin(); pInt != aValue.end(); ++pInt) |
|
290 { |
|
291 instLine->iValues.push_back(*pInt); |
|
292 } |
|
293 |
|
294 /* |
|
295 if (aLine.iNeedsP) |
|
296 params.push_back(CCdlTkApiParam("const TRect&", "aParentRect")); |
|
297 |
|
298 if (aLine.iNeedsIndex) |
|
299 { |
|
300 const string* KParams; |
|
301 int count; |
|
302 if (aLine.iTable->iType == TLayoutTable::EWindowTable) |
|
303 { |
|
304 KParams = KWindowOutputOrder; |
|
305 count = KWindowOutputOrderSize; |
|
306 } |
|
307 else |
|
308 { |
|
309 KParams = KTextOutputOrder; |
|
310 count = KTextOutputOrderSize; |
|
311 } |
|
312 |
|
313 for (int i=0; i<count; i++) |
|
314 { |
|
315 const string& name = KParams[i]; |
|
316 |
|
317 const TValues& defValues = aLine[name]; |
|
318 if (defValues.iNeedsIndex) |
|
319 { |
|
320 CCdlTkApiParam param("TInt", CdlTkUtil::ToCpp(defValues.ParamName())); |
|
321 if (params.FindByName(param.Name()) == params.end()) |
|
322 params.push_back(param); |
|
323 } |
|
324 } |
|
325 } |
|
326 */ |
|
327 |
|
328 aInstLine.push_back(instLine); |
|
329 } |