update dev300-m58
[ooovba.git] / framework / collector / cmduicollector.cxx
blob94cbf563c6259044b0b9feea89a3221aeb42970a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cmduicollector.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #include <sal/main.h>
35 #include <osl/file.hxx>
36 #include <osl/thread.h>
37 #include "tools/getprocessworkingdir.hxx"
38 #include <rtl/ustring.hxx>
39 #include <rtl/ustrbuf.hxx>
40 #include <rtl/strbuf.hxx>
41 #include <rtl/string.hxx>
43 #include <rsc/rscsfx.hxx>
44 #include <comphelper/processfactory.hxx>
45 #include <cppuhelper/servicefactory.hxx>
46 #include <cppuhelper/bootstrap.hxx>
47 #include <tools/resmgr.hxx>
48 #include <tools/rc.h>
49 #include <tools/isolang.hxx>
50 //#include <vcl/rc.hxx>
51 #include <vcl/menu.hxx>
52 #include <vcl/toolbox.hxx>
53 #include <vcl/svapp.hxx>
54 #include <vcl/wrkwin.hxx>
55 #include <vcl/floatwin.hxx>
56 #include <vcl/keycodes.hxx>
58 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
59 #include <com/sun/star/lang/Locale.hpp>
61 #include <com/sun/star/awt/KeyEvent.hpp>
62 #include <com/sun/star/awt/Key.hpp>
63 #include <com/sun/star/awt/KeyModifier.hpp>
65 #include <hash_map>
66 #include <vector>
68 using namespace rtl;
69 namespace css = ::com::sun::star;
71 // Menubars
72 const unsigned short MENUBAR_GLOBAL = 261;
73 const unsigned short MENUBAR_BASIC = 14851;
74 const unsigned short MENUBAR_WRITER = 20016;
75 const unsigned short MENUBAR_WRITERWEB = 20019;
76 const unsigned short MENUBAR_WRITERGLOBAL = 20029;
77 const unsigned short MENUBAR_CALC = 26007;
78 const unsigned short MENUBAR_DRAW = 23009;
79 const unsigned short MENUBAR_CHART = 20081;
80 const unsigned short MENUBAR_MATH = 20814;
81 const unsigned short MENUBAR_IMPRESS = 23006;
82 const unsigned short MENUBAR_BIBLIOGRAPHY = 15901;
83 const unsigned short MENUBAR_BACKINGCOMP = 261;
84 const unsigned short MENUBAR_DBACCESS_TABLE = 19210;
85 const unsigned short MENUBAR_DBACCESS_QUERY = 19211;
86 const unsigned short MENUBAR_DBACCESS_RELATION = 19212;
88 // Accelerators (TODO_AS change numbers)
89 const unsigned short ACC_GLOBAL = 262;
90 const unsigned short ACC_WRITER = 20017;
91 const unsigned short ACC_WRITERWEB = 20017; // same as writer ?
92 const unsigned short ACC_WRITERGLOBAL = 20017; // same as writer ?
93 const unsigned short ACC_CALC = 26006;
94 const unsigned short ACC_DRAW = 23008;
95 const unsigned short ACC_CHART = 20080;
96 const unsigned short ACC_MATH = 20815;
97 const unsigned short ACC_IMPRESS = 23008; // same as draw ?
98 const unsigned short ACC_BASIC = 0;
99 const unsigned short ACC_BIBLIOGRAPHY = 0;
100 const unsigned short ACC_BACKINGCOMP = 0;
101 const unsigned short ACC_DBACCESS_TABLE = 0;
102 const unsigned short ACC_DBACCESS_QUERY = 0;
103 const unsigned short ACC_DBACCESS_RELATION = 0;
105 // Toolbars
106 const unsigned short TOOLBAR_functionbar = 560;
107 const unsigned short TOOLBAR_fullscreenbar = 558;
108 const unsigned short TOOLBAR_macrobar = 14850;
109 const unsigned short TOOLBAR_formsnavigationbar = 18003;
110 const unsigned short TOOLBAR_formsfilterbar = 18004;
111 const unsigned short TOOLBAR_mathtoolbar = 20050;
112 //const unsigned short TOOLBAR_chartobjectbar = 30001;
113 const unsigned short TOOLBAR_charttoolbar = 30513;
114 const unsigned short TOOLBAR_calctextobjectbar = 25005;
115 const unsigned short TOOLBAR_calcformsobjectbar = 25047;
116 const unsigned short TOOLBAR_calcdrawobjectbar = 25053;
117 const unsigned short TOOLBAR_calcgrapicobjectbar = 25054;
118 const unsigned short TOOLBAR_calcformatobjectbar = 25001;
119 const unsigned short TOOLBAR_calcpreviewbar = 25006;
120 const unsigned short TOOLBAR_calctoolbar = 25035;
121 const unsigned short TOOLBAR_drawbezierobjectbar = 23015;
122 const unsigned short TOOLBAR_drawgluepointsobjectbar = 23019;
123 const unsigned short TOOLBAR_impressgraphicobjectbar = 23030;
124 const unsigned short TOOLBAR_drawdrawingobjectbar = 23013;
125 const unsigned short TOOLBAR_impresstextobjectbar = 23016;
126 const unsigned short TOOLBAR_drawtextobjectbar = 23028;
127 const unsigned short TOOLBAR_impresstoolbar = 23011;
128 const unsigned short TOOLBAR_impressoptionsbar = 23020;
129 const unsigned short TOOLBAR_impresscommontaskbar = 23021;
130 const unsigned short TOOLBAR_drawtoolbar = 23025;
131 const unsigned short TOOLBAR_drawoptionsbar = 23026;
132 const unsigned short TOOLBAR_drawgraphicobjectbar = 23027;
133 const unsigned short TOOLBAR_impressoutlinetoolbar = 23017;
134 const unsigned short TOOLBAR_impressslideviewtoolbar = 23012;
135 const unsigned short TOOLBAR_impressslideviewobjectbar = 23014;
136 const unsigned short TOOLBAR_writerbezierobjectbar = 23283;
137 const unsigned short TOOLBAR_writerdrawingobjectbar = 23269;
138 const unsigned short TOOLBAR_writerformsobjectbar = 23299;
139 const unsigned short TOOLBAR_writerdrawtextobjectbar = 23270;
140 const unsigned short TOOLBAR_writerframeobjectbar = 23267;
141 const unsigned short TOOLBAR_writergraphicobjectbar = 23268;
142 const unsigned short TOOLBAR_writernumobjectbar = 23271;
143 const unsigned short TOOLBAR_writeroleobjectbar = 23272;
144 const unsigned short TOOLBAR_writertableobjectbar = 23266;
145 const unsigned short TOOLBAR_writertextobjectbar = 23265;
146 const unsigned short TOOLBAR_writerpreviewobjectbar = 20631;
147 //const unsigned short TOOLBAR_websourceviewobjectbar = 23282;
148 //const unsigned short TOOLBAR_websourceviewtoolbar = 20412;
149 const unsigned short TOOLBAR_webtextobjectbar = 20403;
150 const unsigned short TOOLBAR_writertoolbar = 23273;
151 const unsigned short TOOLBAR_webframeobjectbar = 20408;
152 const unsigned short TOOLBAR_webgraphicobjectbar = 20410;
153 const unsigned short TOOLBAR_weboleobjectbar = 20411;
154 const unsigned short TOOLBAR_webtoolbar = 20402;
155 //const unsigned short TOOLBAR_BRW_TAB_TOOLBOX = 19200;
156 const unsigned short TOOLBAR_BRW_QRY_TOOLBOX = 19201;
157 //const unsigned short TOOLBAR_QRY_TOOLBOX_SQL = 19202;
158 const unsigned short TOOLBAR_BRW_QUERYDESIGN_TOOLBOX = 19203;
159 const unsigned short TOOLBAR_BRW_REALTIONDESIGN_TOOLBOX = 19204;
160 const unsigned short TOOLBAR_fontworkobjectbar = 10987;
161 const unsigned short TOOLBAR_extrusionobjectbar = 10986;
162 const unsigned short TOOLBAR_writerviewerbar = 23310;
163 const unsigned short TOOLBAR_calcviewerbar = 25000;
164 const unsigned short TOOLBAR_impressviewerbar = 23023;
165 const unsigned short TOOLBAR_drawviewerbar = 23024;
167 // Sub-Toolbars
168 const unsigned short RID_LIB_START = 10000;
169 const unsigned short RID_APP_START = 20000;
171 // Draw/Impress
172 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_ALIGNMENT = RID_APP_START+1;
173 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_ALIGNMENT_TBX = RID_APP_START+5;
174 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_ZOOM = RID_APP_START+2;
175 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_ZOOM_TBX = RID_APP_START+6;
176 const unsigned short SUBTOOLBAR_DRAWIMPRESS_CHOOSE_MODE = RID_APP_START+7;
177 const unsigned short SUBTOOLBAR_DRAWIMPRESS_CHOOSE_MODE_TBX = RID_APP_START+8;
178 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_TEXT = RID_APP_START+10;
179 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_TEXT_TBX = RID_APP_START+11;
180 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_RECTANGLES = RID_APP_START+12;
181 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_RECTANGLES_TBX = RID_APP_START+13;
182 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_ELLIPSES = RID_APP_START+14;
183 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_ELLIPSES_TBX = RID_APP_START+15;
184 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_LINES = RID_APP_START+16;
185 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_LINES_TBX = RID_APP_START+17;
186 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_3D_OBJECTS = RID_APP_START+18;
187 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_3D_OBJECTS_TBX = RID_APP_START+19;
188 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_INSERT = RID_APP_START+20;
189 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_INSERT_TBX = RID_APP_START+21;
190 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_POSITION = RID_APP_START+22;
191 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_POSITION_TBX = RID_APP_START+23;
192 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_CONNECTORS = RID_APP_START+24;
193 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_CONNECTORS_TBX = RID_APP_START+25;
194 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_ARROWS = RID_APP_START+26;
195 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_ARROWS_TBX = RID_APP_START+27;
196 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_GRAFFILTERS = RID_APP_START+29;
197 const unsigned short SUBTOOLBAR_DRAWIMPRESS_RID_GRAFFILTERS_TBX = RID_APP_START+30;
199 //Writer
200 const unsigned short RID_SW_START = 20000;
201 const unsigned short RC_BASE = RID_SW_START;
202 const unsigned short RC_RIBBAR = (RC_BASE + 720);
203 const unsigned short RC_RIBBAR_BEGIN = RC_RIBBAR;
204 const unsigned short SUBTOOLBAR_WRITER_RID_INSERT_CTRL = (RC_RIBBAR_BEGIN + 24);
205 const unsigned short SUBTOOLBAR_WRITER_TBX_INSERT = 1;
206 const unsigned short SUBTOOLBAR_WRITER_RID_INSERT_OBJ_CTRL = (RC_RIBBAR_BEGIN + 25);
207 const unsigned short SUBTOOLBAR_WRITER_TBX_OBJ_INSERT = 2;
208 const unsigned short SUBTOOLBAR_WRITER_RID_TBL_OPT_CTRL = (RC_RIBBAR_BEGIN + 27);
209 const unsigned short SUBTOOLBAR_WRITER_TBX_OPTIMIZE_TABLE = 1;
211 //Calc
212 const unsigned short SC_RESOURCE_START = (RID_APP_START+5000);
213 const unsigned short SUBTOOLBAR_CALC_RID_TBXCTL_INSERT = (SC_RESOURCE_START+38);
214 const unsigned short SUBTOOLBAR_CALC_RID_TOOLBOX_INSERT = 1;
215 const unsigned short SUBTOOLBAR_CALC_RID_TBXCTL_INSCELLS = (SC_RESOURCE_START+39);
216 const unsigned short SUBTOOLBAR_CALC_RID_TOOLBOX_INSCELLS = 2;
217 const unsigned short SUBTOOLBAR_CALC_RID_TBXCTL_INSOBJ = (SC_RESOURCE_START+40);
218 const unsigned short SUBTOOLBAR_CALC_RID_TOOLBOX_INSOBJ = 3;
220 //Basic
221 const unsigned short RID_BASICIDE_START = (RID_LIB_START+4850);
222 const unsigned short SUBTOOLBAR_BASIC_RID_TBXCONTROLS = ( RID_BASICIDE_START + 65 );
223 const unsigned short SUBTOOLBAR_BASIC_RID_TOOLBOX = ( RID_BASICIDE_START + 66 );
225 //Global
226 const unsigned short RID_SVX_START = (RID_LIB_START);
227 const unsigned short SUBTOOLBAR_GLOBAL_RID_SVXTBX_DRAW = (RID_SVX_START + 189);
228 const unsigned short SUBTOOLBAR_GLOBAL_TBX_DRAW = 1;
229 const unsigned short SUBTOOLBAR_GLOBAL_RID_SVXTBX_ALIGNMENT = (RID_SVX_START + 190);
230 const unsigned short SUBTOOLBAR_GLOBAL_TBX_ALIGNMENT = 10131; // SID_OBJECT_ALIGN_LEFT
232 struct KeyIdentifierInfo
234 sal_Int16 Code ;
235 char* Identifier;
238 KeyIdentifierInfo AWTKeyIdentifierMap[] =
240 {css::awt::Key::NUM0 , "KEY_0" },
241 {css::awt::Key::NUM1 , "KEY_1" },
242 {css::awt::Key::NUM2 , "KEY_2" },
243 {css::awt::Key::NUM3 , "KEY_3" },
244 {css::awt::Key::NUM4 , "KEY_4" },
245 {css::awt::Key::NUM5 , "KEY_5" },
246 {css::awt::Key::NUM6 , "KEY_6" },
247 {css::awt::Key::NUM7 , "KEY_7" },
248 {css::awt::Key::NUM8 , "KEY_8" },
249 {css::awt::Key::NUM9 , "KEY_9" },
250 {css::awt::Key::A , "KEY_A" },
251 {css::awt::Key::B , "KEY_B" },
252 {css::awt::Key::C , "KEY_C" },
253 {css::awt::Key::D , "KEY_D" },
254 {css::awt::Key::E , "KEY_E" },
255 {css::awt::Key::F , "KEY_F" },
256 {css::awt::Key::G , "KEY_G" },
257 {css::awt::Key::H , "KEY_H" },
258 {css::awt::Key::I , "KEY_I" },
259 {css::awt::Key::J , "KEY_J" },
260 {css::awt::Key::K , "KEY_K" },
261 {css::awt::Key::L , "KEY_L" },
262 {css::awt::Key::M , "KEY_M" },
263 {css::awt::Key::N , "KEY_N" },
264 {css::awt::Key::O , "KEY_O" },
265 {css::awt::Key::P , "KEY_P" },
266 {css::awt::Key::Q , "KEY_Q" },
267 {css::awt::Key::R , "KEY_R" },
268 {css::awt::Key::S , "KEY_S" },
269 {css::awt::Key::T , "KEY_T" },
270 {css::awt::Key::U , "KEY_U" },
271 {css::awt::Key::V , "KEY_V" },
272 {css::awt::Key::W , "KEY_W" },
273 {css::awt::Key::X , "KEY_X" },
274 {css::awt::Key::Y , "KEY_Y" },
275 {css::awt::Key::Z , "KEY_Z" },
276 {css::awt::Key::F1 , "KEY_F1" },
277 {css::awt::Key::F2 , "KEY_F2" },
278 {css::awt::Key::F3 , "KEY_F3" },
279 {css::awt::Key::F4 , "KEY_F4" },
280 {css::awt::Key::F5 , "KEY_F5" },
281 {css::awt::Key::F6 , "KEY_F6" },
282 {css::awt::Key::F7 , "KEY_F7" },
283 {css::awt::Key::F8 , "KEY_F8" },
284 {css::awt::Key::F9 , "KEY_F9" },
285 {css::awt::Key::F10 , "KEY_F10" },
286 {css::awt::Key::F11 , "KEY_F11" },
287 {css::awt::Key::F12 , "KEY_F12" },
288 {css::awt::Key::F13 , "KEY_F13" },
289 {css::awt::Key::F14 , "KEY_F14" },
290 {css::awt::Key::F15 , "KEY_F15" },
291 {css::awt::Key::F16 , "KEY_F16" },
292 {css::awt::Key::F17 , "KEY_F17" },
293 {css::awt::Key::F18 , "KEY_F18" },
294 {css::awt::Key::F19 , "KEY_F19" },
295 {css::awt::Key::F20 , "KEY_F20" },
296 {css::awt::Key::F21 , "KEY_F21" },
297 {css::awt::Key::F22 , "KEY_F22" },
298 {css::awt::Key::F23 , "KEY_F23" },
299 {css::awt::Key::F24 , "KEY_F24" },
300 {css::awt::Key::F25 , "KEY_F25" },
301 {css::awt::Key::F26 , "KEY_F26" },
302 {css::awt::Key::DOWN , "KEY_DOWN" },
303 {css::awt::Key::UP , "KEY_UP" },
304 {css::awt::Key::LEFT , "KEY_LEFT" },
305 {css::awt::Key::RIGHT , "KEY_RIGHT" },
306 {css::awt::Key::HOME , "KEY_HOME" },
307 {css::awt::Key::END , "KEY_END" },
308 {css::awt::Key::PAGEUP , "KEY_PAGEUP" },
309 {css::awt::Key::PAGEDOWN , "KEY_PAGEDOWN" },
310 {css::awt::Key::RETURN , "KEY_RETURN" },
311 {css::awt::Key::ESCAPE , "KEY_ESCAPE" },
312 {css::awt::Key::TAB , "KEY_TAB" },
313 {css::awt::Key::BACKSPACE , "KEY_BACKSPACE" },
314 {css::awt::Key::SPACE , "KEY_SPACE" },
315 {css::awt::Key::INSERT , "KEY_INSERT" },
316 {css::awt::Key::DELETE , "KEY_DELETE" },
317 {css::awt::Key::ADD , "KEY_ADD" },
318 {css::awt::Key::SUBTRACT , "KEY_SUBTRACT" },
319 {css::awt::Key::MULTIPLY , "KEY_MULTIPLY" },
320 {css::awt::Key::DIVIDE , "KEY_DIVIDE" },
321 {css::awt::Key::POINT , "KEY_POINT" },
322 {css::awt::Key::COMMA , "KEY_COMMA" },
323 {css::awt::Key::LESS , "KEY_LESS" },
324 {css::awt::Key::GREATER , "KEY_GREATER" },
325 {css::awt::Key::EQUAL , "KEY_EQUAL" },
326 {css::awt::Key::OPEN , "KEY_OPEN" },
327 {css::awt::Key::CUT , "KEY_CUT" },
328 {css::awt::Key::COPY , "KEY_COPY" },
329 {css::awt::Key::PASTE , "KEY_PASTE" },
330 {css::awt::Key::UNDO , "KEY_UNDO" },
331 {css::awt::Key::REPEAT , "KEY_REPEAT" },
332 {css::awt::Key::FIND , "KEY_FIND" },
333 {css::awt::Key::PROPERTIES , "KEY_PROPERTIES" },
334 {css::awt::Key::FRONT , "KEY_FRONT" },
335 {css::awt::Key::CONTEXTMENU , "KEY_CONTEXTMENU"},
336 {css::awt::Key::HELP , "KEY_HELP" },
337 {css::awt::Key::MENU , "KEY_MENU" },
338 {css::awt::Key::HANGUL_HANJA , "KEY_HANGUL_HANJA"},
339 {css::awt::Key::DECIMAL , "KEY_DECIMAL" },
340 {css::awt::Key::TILDE , "KEY_TILDE" },
341 {css::awt::Key::QUOTELEFT , "KEY_QUOTELEFT" },
342 {0 , "" } // mark the end of this array!
345 struct ISO_code
347 const char* pLanguage;
348 const char* pCountry;
351 const int NUM_LANGUAGES = 27;
352 //const int NUM_LANGUAGES = 1;
354 ISO_code Language_codes[] =
356 { "de", "" },
357 { "en", "US" },
358 { "ar", "" },
359 { "no", "" },
360 { "ca", "" },
361 { "zh", "TW" },
362 { "cs", "" },
363 { "da", "" },
364 { "el", "" },
365 { "es", "" },
366 { "fi", "" },
367 { "fr", "" },
368 { "he", "" },
369 { "it", "" },
370 { "ja", "" },
371 { "ko", "" },
372 { "nl", "" },
373 { "pl", "" },
374 { "pt", "BR" },
375 { "ru", "" },
376 { "sk", "" },
377 { "sv", "" },
378 { "th", "" },
379 { "tr", "" },
380 { "hi", "" },
381 { "zh", "CN" },
382 { "pt", "" },
383 { 0, 0 }
386 enum MODULES
388 MODULE_GLOBAL,
389 MODULE_WRITER,
390 MODULE_CALC,
391 MODULE_DRAWIMPRESS,
392 MODULE_CHART,
393 MODULE_MATH,
394 MODULE_BASIC,
395 MODULE_BIBLIO,
396 MODULE_BACKINGCOMP,
397 MODULE_DBACCESS,
398 MODULE_COUNT
401 enum SUBMODULES
403 SUBMODULE_GLOBAL = 1,
404 SUBMODULE_WRITER = 2,
405 SUBMODULE_WRITERWEB = 4,
406 SUBMODULE_WRITERGLOBAL = 8,
407 SUBMODULE_CALC = 16,
408 SUBMODULE_DRAW = 32,
409 SUBMODULE_IMPRESSS = 64,
410 SUBMODULE_CHART = 128,
411 SUBMODULE_MATH = 256,
412 SUBMODULE_BASIC = 512,
413 SUBMODULE_BIBLIO = 1024,
414 SUBMODULE_BACKINGCOMP = 2048,
415 SUBMODULE_DB_TABLE = 4096,
416 SUBMODULE_DB_QUERY = 8192,
417 SUBMODULE_DB_RELATION = 16384
420 enum PARENT_RESTYPES
422 PARENT_RESTYPE_FLOATINGWINDOW
425 struct Projects
427 const char* pProjectFolder;
428 const char* pResPrefix;
429 const char* pCSVPrefix;
430 bool bSlotCommands;
431 MODULES eBelongsTo;
434 Projects ProjectModule_Mapping[] =
436 { "sfx2" , "sfx", "sfx2", true, MODULE_GLOBAL },
437 { "svx" , "svx", "svx", true, MODULE_GLOBAL },
438 { "svx" , "ofa", "ofa", true, MODULE_GLOBAL },
439 { "sw" , "sw", "sw", true, MODULE_WRITER },
440 { "sd" , "sd", "sd", true, MODULE_DRAWIMPRESS },
441 { "sc" , "sc", "sc", true, MODULE_CALC },
442 { "sch" , "sch", "sch", true, MODULE_CHART },
443 { "starmath" , "sm", "starmath", true, MODULE_MATH },
444 { "basctl" , "basctl", "bastctl", true, MODULE_BASIC },
445 { "extensions" , "bib", "", false, MODULE_BIBLIO },
446 { "offmgr" , "ofa", "", false, MODULE_BACKINGCOMP },
447 { "dbaccess" , "dbu", "", false, MODULE_DBACCESS },
448 { 0 , 0, "", false, MODULE_BASIC }
451 const char XMLFileExtension[] = ".xcu";
452 const char* ModuleToXML_Mapping[] =
454 "GenericCommands",
455 "WriterCommands",
456 "CalcCommands",
457 "DrawImpressCommands",
458 "ChartCommands",
459 "MathCommands",
460 "BasicIDECommands",
461 "BibliographyCommands",
462 "StartModuleCommands",
463 "DbuCommands",
467 struct ResourceToModule
469 unsigned short nResId;
470 const char* pXMLPrefix;
471 MODULES eBelongsTo;
472 bool bWritten;
475 struct SubResourceToModule
477 unsigned short nParentResId;
478 PARENT_RESTYPES eParentResType;
479 unsigned short nResId;
480 const char* pXMLPrefix;
481 MODULES eBelongsTo;
482 bool bWritten;
485 ResourceToModule ResourceModule_Mapping[] =
487 { MENUBAR_GLOBAL, "default", MODULE_GLOBAL }, // important: To prevent duplicate popup menu entries make sure this is the first entry!!
488 { MENUBAR_BASIC, "basic", MODULE_BASIC },
489 { MENUBAR_WRITER, "writer", MODULE_WRITER },
490 { MENUBAR_WRITERWEB, "web", MODULE_WRITER },
491 { MENUBAR_WRITERGLOBAL, "global", MODULE_WRITER },
492 { MENUBAR_CALC, "calc", MODULE_CALC },
493 { MENUBAR_DRAW, "draw", MODULE_DRAWIMPRESS },
494 { MENUBAR_CHART, "chart", MODULE_CHART },
495 { MENUBAR_MATH, "math", MODULE_MATH },
496 { MENUBAR_IMPRESS, "impress", MODULE_DRAWIMPRESS },
497 { MENUBAR_BIBLIOGRAPHY, "biblio", MODULE_BIBLIO },
498 { MENUBAR_BACKINGCOMP, "backing", MODULE_BACKINGCOMP },
499 { MENUBAR_DBACCESS_TABLE, "dbtable", MODULE_DBACCESS },
500 { MENUBAR_DBACCESS_QUERY, "dbquery", MODULE_DBACCESS },
501 { MENUBAR_DBACCESS_RELATION,"dbrelation", MODULE_DBACCESS },
502 { 0, "", MODULE_DBACCESS }
506 ResourceToModule AccResourceModule_Mapping[] =
508 { ACC_GLOBAL, "default", MODULE_GLOBAL },
509 { ACC_WRITER, "writer", MODULE_WRITER },
510 { ACC_WRITERWEB, "web", MODULE_WRITER },
511 { ACC_WRITERGLOBAL, "global", MODULE_WRITER },
512 { ACC_CALC, "calc", MODULE_CALC },
513 { ACC_DRAW, "draw", MODULE_DRAWIMPRESS },
514 { ACC_CHART, "chart", MODULE_CHART },
515 { ACC_MATH, "math", MODULE_MATH },
516 { ACC_IMPRESS, "impress", MODULE_DRAWIMPRESS },
517 { ACC_BIBLIOGRAPHY, "biblio", MODULE_BIBLIO }, // 0
518 { ACC_BACKINGCOMP, "backing", MODULE_BACKINGCOMP }, // 0
519 { ACC_DBACCESS_TABLE, "dbtable", MODULE_DBACCESS }, // 0
520 { ACC_DBACCESS_QUERY, "dbquery", MODULE_DBACCESS }, // 0
521 { ACC_DBACCESS_RELATION,"dbrelation", MODULE_DBACCESS }, // 0
522 { ACC_BASIC, "basic", MODULE_BASIC }, // 0
523 { 0, "", MODULE_COUNT }
526 ResourceToModule TBResourceModule_Mapping[] =
528 { TOOLBAR_functionbar ,"standardbar", MODULE_GLOBAL , false },
529 { TOOLBAR_fullscreenbar ,"fullscreenbar", MODULE_GLOBAL , false },
530 { TOOLBAR_macrobar ,"macrobar", MODULE_BASIC , false },
531 { TOOLBAR_formsnavigationbar ,"formsnavigationbar", MODULE_GLOBAL , false },
532 { TOOLBAR_formsfilterbar ,"formsfilterbar", MODULE_GLOBAL , false },
533 { TOOLBAR_fontworkobjectbar ,"fontworkobjectbar", MODULE_GLOBAL , false },
534 { TOOLBAR_extrusionobjectbar ,"extrusionobjectbar", MODULE_GLOBAL , false },
535 { TOOLBAR_mathtoolbar ,"mathtoolbar", MODULE_MATH , false },
536 // { TOOLBAR_chartobjectbar ,"chartobjectbar", MODULE_CHART , false },
537 { TOOLBAR_charttoolbar ,"charttoolbar", MODULE_CHART , false },
538 { TOOLBAR_calctextobjectbar ,"calctextobjectbar", MODULE_CALC , false },
539 { TOOLBAR_calcformsobjectbar ,"calcformsobjectbar", MODULE_CALC , false },
540 { TOOLBAR_calcdrawobjectbar ,"calcdrawobjectbar", MODULE_CALC , false },
541 { TOOLBAR_calcgrapicobjectbar ,"calcgrapicobjectbar", MODULE_CALC , false },
542 { TOOLBAR_calcformatobjectbar ,"calcformatobjectbar", MODULE_CALC , false },
543 { TOOLBAR_calcpreviewbar ,"calcpreviewbar", MODULE_CALC , false },
544 { TOOLBAR_calctoolbar ,"calctoolbar", MODULE_CALC , false },
545 { TOOLBAR_drawbezierobjectbar ,"drawbezierobjectbar", MODULE_DRAWIMPRESS , false },
546 { TOOLBAR_drawgluepointsobjectbar ,"drawgluepointsobjectbar", MODULE_DRAWIMPRESS , false },
547 { TOOLBAR_impressgraphicobjectbar ,"impressgraphicobjectbar", MODULE_DRAWIMPRESS , false },
548 { TOOLBAR_drawdrawingobjectbar ,"drawdrawingobjectbar", MODULE_DRAWIMPRESS , false },
549 { TOOLBAR_impresstextobjectbar ,"impresstextobjectbar", MODULE_DRAWIMPRESS , false },
550 { TOOLBAR_drawtextobjectbar ,"drawtextobjectbar", MODULE_DRAWIMPRESS , false },
551 { TOOLBAR_impresstoolbar ,"impresstoolbar", MODULE_DRAWIMPRESS , false },
552 { TOOLBAR_impressoptionsbar ,"impressoptionsbar", MODULE_DRAWIMPRESS , false },
553 { TOOLBAR_impresscommontaskbar ,"impresscommontaskbar", MODULE_DRAWIMPRESS , false },
554 { TOOLBAR_drawtoolbar ,"drawtoolbar", MODULE_DRAWIMPRESS , false },
555 { TOOLBAR_drawoptionsbar ,"drawoptionsbar", MODULE_DRAWIMPRESS , false },
556 { TOOLBAR_drawgraphicobjectbar ,"drawgraphicobjectbar", MODULE_DRAWIMPRESS , false },
557 { TOOLBAR_impressoutlinetoolbar ,"impressoutlinetoolbar", MODULE_DRAWIMPRESS , false },
558 { TOOLBAR_impressslideviewtoolbar ,"impressslideviewtoolbar", MODULE_DRAWIMPRESS , false },
559 { TOOLBAR_impressslideviewobjectbar ,"impressslideviewobjectbar", MODULE_DRAWIMPRESS , false },
560 { TOOLBAR_writerbezierobjectbar ,"writerbezierobjectbar", MODULE_WRITER , false },
561 { TOOLBAR_writerdrawingobjectbar ,"writerdrawingobjectbar", MODULE_WRITER , false },
562 { TOOLBAR_writerformsobjectbar ,"writerformsobjectbar", MODULE_WRITER , false },
563 { TOOLBAR_writerdrawtextobjectbar ,"writerdrawtextobjectbar", MODULE_WRITER , false },
564 { TOOLBAR_writerframeobjectbar ,"writerframeobjectbar", MODULE_WRITER , false },
565 { TOOLBAR_writergraphicobjectbar ,"writergraphicobjectbar", MODULE_WRITER , false },
566 { TOOLBAR_writernumobjectbar ,"writernumobjectbar", MODULE_WRITER , false },
567 { TOOLBAR_writeroleobjectbar ,"writeroleobjectbar", MODULE_WRITER , false },
568 { TOOLBAR_writertableobjectbar ,"writertableobjectbar", MODULE_WRITER , false },
569 { TOOLBAR_writertextobjectbar ,"writertextobjectbar", MODULE_WRITER , false },
570 { TOOLBAR_writerpreviewobjectbar ,"writerpreviewobjectbar", MODULE_WRITER , false },
571 // { TOOLBAR_websourceviewobjectbar ,"websourceviewobjectbar", MODULE_WRITER , false },
572 // { TOOLBAR_websourceviewtoolbar ,"websourceviewtoolbar", MODULE_WRITER , false },
573 { TOOLBAR_webtextobjectbar ,"webtextobjectbar", MODULE_WRITER , false },
574 { TOOLBAR_writertoolbar ,"writertoolbar", MODULE_WRITER , false },
575 { TOOLBAR_webframeobjectbar ,"webframeobjectbar", MODULE_WRITER , false },
576 { TOOLBAR_webgraphicobjectbar ,"webgraphicobjectbar", MODULE_WRITER , false },
577 { TOOLBAR_weboleobjectbar ,"weboleobjectbar", MODULE_WRITER , false },
578 { TOOLBAR_webtoolbar ,"webtoolbar", MODULE_WRITER , false },
579 // { TOOLBAR_BRW_TAB_TOOLBOX ,"dbtablebrowsebar", MODULE_DBACCESS , false },
580 { TOOLBAR_BRW_QRY_TOOLBOX ,"dbquerybrowsebar", MODULE_DBACCESS , false },
581 // { TOOLBAR_QRY_TOOLBOX_SQL ,"dbquerysqlbar", MODULE_DBACCESS , false },
582 { TOOLBAR_BRW_QUERYDESIGN_TOOLBOX ,"dbquerydesignbar", MODULE_DBACCESS , false },
583 { TOOLBAR_BRW_REALTIONDESIGN_TOOLBOX ,"dbrelationbrowsebar", MODULE_DBACCESS , false },
584 { TOOLBAR_writerviewerbar ,"writerviewerbar", MODULE_WRITER , false },
585 { TOOLBAR_calcviewerbar ,"calcviewerbar", MODULE_CALC , false },
586 { TOOLBAR_impressviewerbar ,"impressviewerbar", MODULE_DRAWIMPRESS , false },
587 { TOOLBAR_drawviewerbar ,"drawviewerbar", MODULE_DRAWIMPRESS , false },
588 { 0 ,"", MODULE_GLOBAL , false }
591 struct SubResourceToModule TBSubResourceModule_Mapping[] =
593 { SUBTOOLBAR_DRAWIMPRESS_RID_ALIGNMENT, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_ALIGNMENT_TBX , "drawimpressalignmentbar" , MODULE_DRAWIMPRESS , false },
594 { SUBTOOLBAR_DRAWIMPRESS_RID_ZOOM, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_ZOOM_TBX , "drawimpresszoombar" , MODULE_DRAWIMPRESS , false },
595 { SUBTOOLBAR_DRAWIMPRESS_CHOOSE_MODE, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_CHOOSE_MODE_TBX , "drawimpresschoosemodebar" , MODULE_DRAWIMPRESS , false },
596 { SUBTOOLBAR_DRAWIMPRESS_RID_TEXT, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_TEXT_TBX , "drawimpresstextbar" , MODULE_DRAWIMPRESS , false },
597 { SUBTOOLBAR_DRAWIMPRESS_RID_RECTANGLES, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_RECTANGLES_TBX , "drawimpressrectanglebar" , MODULE_DRAWIMPRESS , false },
598 { SUBTOOLBAR_DRAWIMPRESS_RID_ELLIPSES, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_ELLIPSES_TBX , "drawimpressellipsesbar" , MODULE_DRAWIMPRESS , false },
599 { SUBTOOLBAR_DRAWIMPRESS_RID_LINES, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_LINES_TBX , "drawimpresslinesbar" , MODULE_DRAWIMPRESS , false },
600 { SUBTOOLBAR_DRAWIMPRESS_RID_3D_OBJECTS, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_3D_OBJECTS_TBX , "drawimpress3dobjectsbar" , MODULE_DRAWIMPRESS , false },
601 { SUBTOOLBAR_DRAWIMPRESS_RID_INSERT, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_INSERT_TBX , "drawimpressinsertbar" , MODULE_DRAWIMPRESS , false },
602 { SUBTOOLBAR_DRAWIMPRESS_RID_POSITION, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_POSITION_TBX , "drawimpresspositionbar" , MODULE_DRAWIMPRESS , false },
603 { SUBTOOLBAR_DRAWIMPRESS_RID_CONNECTORS, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_CONNECTORS_TBX , "drawimpressconnectorsbar" , MODULE_DRAWIMPRESS , false },
604 { SUBTOOLBAR_DRAWIMPRESS_RID_ARROWS, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_ARROWS_TBX , "drawimpressarrowsbar" , MODULE_DRAWIMPRESS , false },
605 // { SUBTOOLBAR_DRAWIMPRESS_RID_GRAFFILTERS, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_DRAWIMPRESS_RID_GRAFFILTERS_TBX , "drawimpressgraffiltersbar" , MODULE_DRAWIMPRESS, false },
606 { SUBTOOLBAR_WRITER_RID_INSERT_CTRL , PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_WRITER_TBX_INSERT , "writerinsertbar" , MODULE_WRITER , false },
607 { SUBTOOLBAR_WRITER_RID_INSERT_OBJ_CTRL , PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_WRITER_TBX_OBJ_INSERT , "writerinsertobjectbar" , MODULE_WRITER , false },
608 { SUBTOOLBAR_WRITER_RID_TBL_OPT_CTRL , PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_WRITER_TBX_OPTIMIZE_TABLE , "writeroptimizetablebar" , MODULE_WRITER , false },
609 { SUBTOOLBAR_GLOBAL_RID_SVXTBX_DRAW , PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_GLOBAL_TBX_DRAW , "genericdrawbar" , MODULE_GLOBAL , false },
610 { SUBTOOLBAR_GLOBAL_RID_SVXTBX_ALIGNMENT, PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_GLOBAL_TBX_ALIGNMENT , "genericalignmentbar" , MODULE_GLOBAL , false },
611 { SUBTOOLBAR_CALC_RID_TBXCTL_INSERT , PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_CALC_RID_TOOLBOX_INSERT , "calcinsertbar" , MODULE_CALC , false },
612 { SUBTOOLBAR_CALC_RID_TBXCTL_INSCELLS , PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_CALC_RID_TOOLBOX_INSCELLS , "calcinsertcellsbar" , MODULE_CALC , false },
613 { SUBTOOLBAR_CALC_RID_TBXCTL_INSOBJ , PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_CALC_RID_TOOLBOX_INSOBJ , "calcinsertobjectbar" , MODULE_CALC , false },
614 { SUBTOOLBAR_BASIC_RID_TBXCONTROLS , PARENT_RESTYPE_FLOATINGWINDOW, SUBTOOLBAR_BASIC_RID_TOOLBOX , "basicinsertcontrolsbar" , MODULE_BASIC , false },
615 { 0, PARENT_RESTYPE_FLOATINGWINDOW, 0 , "" , MODULE_GLOBAL , false }
618 struct CommandLabels
620 unsigned short nID;
621 bool bWritten;
622 bool bPopupMenu;
623 rtl::OUString aCommand;
624 unsigned long nModules;
625 rtl::OUString aLabels[NUM_LANGUAGES];
626 unsigned long nProperties;
628 CommandLabels() :
629 nID( 0 ),
630 bWritten( false ),
631 bPopupMenu( false ),
632 nModules( 0 ),
633 nProperties( 0 )
638 struct KeyCommandInfo
640 KeyCode aVCLKey;
641 css::awt::KeyEvent aAWTKey;
642 ::rtl::OUString sCommand;
643 ::rtl::OUString sKey;
644 USHORT nCommandId;
646 bool operator==(const KeyCommandInfo& rI) const
648 return (
649 (rI.aVCLKey == aVCLKey) &&
650 (rI.aAWTKey.KeyCode == aAWTKey.KeyCode) &&
651 (rI.aAWTKey.Modifiers == aAWTKey.Modifiers) &&
652 (rI.sCommand == sCommand) &&
653 (rI.sKey == sKey) &&
654 (rI.nCommandId == nCommandId)
659 struct ToolBarInfo
661 unsigned short nID;
662 bool bWritten;
663 unsigned long nModules; // Which sub modules need this toolbar
664 rtl::OUString aUIName[NUM_LANGUAGES];
666 ToolBarInfo() :
667 nID( 0 ),
668 bWritten( false ),
669 nModules( 0 ) {}
672 struct OUStringHashCode
674 size_t operator()( const ::rtl::OUString& sString ) const
676 return sString.hashCode();
680 typedef std::hash_map< int, CommandLabels > CommandIDToLabelsMap;
681 typedef std::hash_map< OUString, CommandLabels, OUStringHashCode, ::std::equal_to< OUString > > CommandToLabelsMap;
682 typedef std::hash_map< int, ToolBarInfo > ResIdToToolBarInfoMap;
683 typedef std::vector< KeyCommandInfo > KeyCommandInfoList;
684 typedef std::hash_map< int, KeyCommandInfoList > Locale2KeyCommandInfoList;
686 static CommandIDToLabelsMap moduleMapFiles[MODULE_COUNT];
687 static CommandToLabelsMap modulePopupMenusCmd[MODULE_COUNT];
688 static Locale2KeyCommandInfoList moduleAccs[MODULE_COUNT];
690 bool ExtractVersionNumber( const OUString& rVersion, OUString& rVersionNumber )
692 bool bCheckNumOnly( false );
694 OUStringBuffer aBuf;
696 rVersionNumber = OUString();
697 for ( int i = 0; i < rVersion.getLength(); i++ )
699 if ( rVersion[i] >= sal_Unicode( '0' ) && rVersion[i] <= sal_Unicode( '9' ))
701 bCheckNumOnly = true;
702 aBuf.append( rVersion[i] );
704 else if ( bCheckNumOnly )
705 return false;
708 rVersionNumber = aBuf.makeStringAndClear();
709 return true;
712 bool ReadCSVFile( const OUString& aCVSFileURL, MODULES eModule, const OUString& aProjectName )
714 osl::File aCSVFile( aCVSFileURL );
715 fprintf(stdout, "############ read csv \"%s\" ... ", ::rtl::OUStringToOString(aCVSFileURL, RTL_TEXTENCODING_UTF8).getStr());
716 if ( aCSVFile.open( OpenFlag_Read ) != osl::FileBase::E_None )
718 fprintf(stdout, "failed!\n");
719 return false;
721 fprintf(stdout, "OK!\n");
724 sal_Bool bEOF;
725 ::rtl::ByteSequence aCSVLine;
726 OUString aUnoCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
728 while ( aCSVFile.isEndOfFile( &bEOF ) == osl::FileBase::E_None && !bEOF )
730 aCSVFile.readLine( aCSVLine );
732 OString aLine( (const char *)aCSVLine.getConstArray(), aCSVLine.getLength() );
733 OString aID;
734 OString aAccelState;
735 OString aMenuState;
736 OString aStatusState;
737 OString aToolbarState;
738 OString aCmdName;
739 OString aSlotName;
740 OString aImageRotationState;
741 OString aImageReflectionState;
743 sal_Int32 nIndex = 0;
744 aID = aLine.getToken( 2, ',', nIndex );
745 aAccelState = aLine.getToken( 2, ',', nIndex );
746 aMenuState = aLine.getToken( 0, ',', nIndex );
747 aStatusState = aLine.getToken( 0, ',', nIndex );
748 aToolbarState = aLine.getToken( 0, ',', nIndex );
749 aImageRotationState = aLine.getToken( 8, ',', nIndex );
750 aImageReflectionState = aLine.getToken( 0, ',', nIndex );
751 aCmdName = aLine.getToken( 10, ',', nIndex );
752 aSlotName = aLine.getToken( 1, ',', nIndex );
754 if ( aCmdName.getLength() == 0 )
755 aCmdName = aSlotName;
757 int nID = aID.toInt32();
759 if ( nID > 5000 && ( aAccelState.equalsIgnoreAsciiCase( "TRUE" ) ||
760 aMenuState.equalsIgnoreAsciiCase( "TRUE" ) ||
761 aStatusState.equalsIgnoreAsciiCase( "TRUE" ) ||
762 aToolbarState.equalsIgnoreAsciiCase( "TRUE" ) ))
764 CommandLabels aCmdLabel;
766 aCmdLabel.nID = nID;
767 aCmdLabel.aCommand = aUnoCmd;
768 aCmdLabel.aCommand += OStringToOUString( aCmdName, RTL_TEXTENCODING_ASCII_US );
769 aCmdLabel.nModules |= ( 1 << (unsigned long)( eModule ));
771 // Set bitfield
772 aCmdLabel.nProperties = (( aImageRotationState.equalsIgnoreAsciiCase( "TRUE" ) ? 1 : 0 ) << 1 );
773 aCmdLabel.nProperties |= (( aImageReflectionState.equalsIgnoreAsciiCase( "TRUE" ) ? 1 : 0 ) << 2 );
775 moduleMapFiles[int(eModule)].insert( CommandIDToLabelsMap::value_type( nID, aCmdLabel ));
776 modulePopupMenusCmd[int(eModule)].insert( CommandToLabelsMap::value_type( aCmdLabel.aCommand, aCmdLabel ));
780 aCSVFile.close();
783 return true;
786 CommandLabels* RetrieveCommandLabelsFromID( unsigned short nId, MODULES eModule )
788 CommandIDToLabelsMap::iterator pIter = moduleMapFiles[MODULE_GLOBAL].find( nId );
789 if ( pIter != moduleMapFiles[MODULE_GLOBAL].end() )
790 return &(pIter->second);
791 else if ( eModule != MODULE_GLOBAL )
793 CommandIDToLabelsMap::iterator pIter = moduleMapFiles[eModule].find( nId );
794 if ( pIter != moduleMapFiles[eModule].end() )
795 return &(pIter->second);
798 return NULL;
801 CommandLabels* RetrieveCommandLabelsFromCommand( const OUString& aCommand, MODULES eModule )
803 CommandToLabelsMap::iterator pIter = modulePopupMenusCmd[MODULE_GLOBAL].find( aCommand );
804 if ( pIter != modulePopupMenusCmd[MODULE_GLOBAL].end() )
805 return &(pIter->second);
806 else if ( eModule != MODULE_GLOBAL )
808 CommandToLabelsMap::iterator pIter = modulePopupMenusCmd[eModule].find( aCommand );
809 if ( pIter != modulePopupMenusCmd[eModule].end() )
810 return &(pIter->second);
813 return NULL;
816 void AddCommandLabelsToIDHashMap( MODULES eModule, const CommandLabels& rNewCmdLabels )
818 moduleMapFiles[int(eModule)].insert( CommandIDToLabelsMap::value_type( rNewCmdLabels.nID, rNewCmdLabels ));
821 void AddCommandLabelsToCommandHashMap( MODULES eModule, const CommandLabels& rNewCmdLabels )
823 modulePopupMenusCmd[int(eModule)].insert( CommandToLabelsMap::value_type( rNewCmdLabels.aCommand, rNewCmdLabels ));
826 KeyCode impl_KeyCodeAWT2VCL(const css::awt::KeyEvent& aAWTKey)
828 BOOL bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT );
829 BOOL bMod1 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 );
830 BOOL bMod2 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 );
831 BOOL bMod3 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 );
832 USHORT nKey = (USHORT)aAWTKey.KeyCode;
833 // unfortunately MENU and CONTEXTMENU are twisted between vcl and awt
834 if( aAWTKey.KeyCode == css::awt::Key::MENU )
835 nKey = KEY_CONTEXTMENU;
836 else if( aAWTKey.KeyCode == css::awt::Key::CONTEXTMENU )
837 nKey = KEY_MENU;
838 return KeyCode(nKey, bShift, bMod1, bMod2, bMod3);
841 css::awt::KeyEvent impl_KeyCodeVCL2AWT(const KeyCode& aVCLKey)
843 css::awt::KeyEvent aAWTKey;
844 aAWTKey.Modifiers = 0;
845 aAWTKey.KeyCode = (sal_Int16)aVCLKey.GetCode();
846 // unfortunately MENU and CONTEXTMENU are twisted between vcl and awt
847 if( aAWTKey.KeyCode == css::awt::Key::MENU )
848 aAWTKey.KeyCode = css::awt::Key::CONTEXTMENU;
849 else if( aAWTKey.KeyCode == css::awt::Key::CONTEXTMENU )
850 aAWTKey.KeyCode = css::awt::Key::MENU;
852 if (aVCLKey.IsShift())
853 aAWTKey.Modifiers |= css::awt::KeyModifier::SHIFT;
854 if (aVCLKey.IsMod1())
855 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD1;
856 if (aVCLKey.IsMod2())
857 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD2;
858 if (aVCLKey.IsMod3())
859 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD3;
861 return aAWTKey;
864 bool impl_isDuplicateKey(const KeyCommandInfoList& rList,
865 const KeyCommandInfo& aInfo)
867 KeyCommandInfoList::const_iterator pInfo;
868 KeyCommandInfoList::const_iterator aEnd = rList.end();
869 for ( pInfo = rList.begin();
870 pInfo != aEnd ;
871 ++pInfo )
873 if (
874 (pInfo->aVCLKey == aInfo.aVCLKey ) &&
875 (pInfo->nCommandId == aInfo.nCommandId)
878 return true;
881 return false;
884 bool ReadAccelerators( int nLangIndex, ResMgr* pResMgr, MODULES eModule, const ::rtl::OUString& aProjectName, Accelerator* pAcc )
886 Locale2KeyCommandInfoList& rLocale = moduleAccs[eModule];
887 KeyCommandInfoList& rAccs = rLocale[nLangIndex];
889 USHORT c = pAcc->GetItemCount();
890 rAccs.reserve(rAccs.size()+c);
891 USHORT i = 0;
892 for (i=0; i<c; ++i)
894 USHORT nItem = pAcc->GetItemId(i);
896 KeyCommandInfo aInfo;
897 aInfo.nCommandId = nItem;
898 aInfo.aVCLKey = pAcc->GetItemKeyCode(i); // dont use GetKeyCode(nItem) ... You cant handle logic keys then. Because they have the same ID - but another keycode!
899 aInfo.aAWTKey = impl_KeyCodeVCL2AWT(aInfo.aVCLKey);
901 fprintf(stdout, " acc key=%d\tid=%d", aInfo.aVCLKey.GetFullCode(), aInfo.nCommandId);
902 CommandLabels* pCmdInfo = RetrieveCommandLabelsFromID(aInfo.nCommandId, eModule);
903 if (!pCmdInfo || !pCmdInfo->aCommand.getLength())
905 fprintf(stdout, "\t\t\t=>\tERROR\t: no command [mod=%d]\n", eModule);
906 continue;
908 aInfo.sCommand = pCmdInfo->aCommand;
909 fprintf(stdout, "\tcmd=%s\t=>\t", ::rtl::OUStringToOString(aInfo.sCommand, RTL_TEXTENCODING_UTF8).getStr());
911 sal_Int32 i = 0;
912 while(AWTKeyIdentifierMap[i].Code != 0)
914 const KeyIdentifierInfo& rKeyInfo = AWTKeyIdentifierMap[i];
915 if (aInfo.aAWTKey.KeyCode == rKeyInfo.Code)
917 aInfo.sKey = ::rtl::OUString::createFromAscii(rKeyInfo.Identifier);
918 break;
920 ++i;
923 if (!aInfo.sKey.getLength())
925 fprintf(stdout, "ERROR\t: no key identifier\n");
926 continue;
929 if (impl_isDuplicateKey(rAccs, aInfo))
931 fprintf(stdout, "WARNING\t: key is duplicate\n");
932 continue;
935 fprintf(stdout, "\n");
936 rAccs.push_back(aInfo);
939 return true;
942 bool ReadMenuLabels( int nLangIndex, Menu* pMenu, MODULES eModule, bool bHasSlotInfos, OUString aResourceFilePrefix )
944 OUString aCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
946 for ( unsigned short n = 0; n < pMenu->GetItemCount(); n++ )
948 unsigned short nId = pMenu->GetItemId( n );
949 if ( pMenu->GetItemType( n ) != MENUITEM_SEPARATOR )
951 OUString aLabel( pMenu->GetItemText( nId ));
952 OUString aCommand( pMenu->GetItemCommand( nId ));
953 bool bHasUnoCommand( aCommand.getLength() > 0 && ( aCommand.indexOf( aCmd ) == 0 ));
955 if ( pMenu->GetPopupMenu( nId ) != 0 )
957 CommandLabels* pCmdLabels = 0;
958 // Special popup menus have ID's between 5000-10000. Apps uses various ID's from their number area =>
959 // don't use ID if outside this area, you can accidently map popups to functions!!
960 if (( nId > 5000 ) && ( nId < 10000 ))
961 pCmdLabels = RetrieveCommandLabelsFromID( nId, eModule );
962 if ( !pCmdLabels )
963 pCmdLabels = RetrieveCommandLabelsFromCommand( aCommand, eModule );
965 if ( pCmdLabels )
967 pCmdLabels->aLabels[nLangIndex] = aLabel;
968 pCmdLabels->bPopupMenu = true;
970 else
972 if ( bHasUnoCommand )
974 CommandLabels aCmdLabels;
976 aCmdLabels.nID = 0;
977 aCmdLabels.aCommand = aCommand;
978 aCmdLabels.aLabels[nLangIndex] = aLabel;
979 aCmdLabels.bPopupMenu = true;
980 AddCommandLabelsToCommandHashMap( eModule, aCmdLabels );
982 else
984 fprintf( stderr, "Popup menu (resource = %s ) with unknown uno-command and id '%s', ID = %d, aCmd = %s\n",
985 OUStringToOString( aResourceFilePrefix, RTL_TEXTENCODING_UTF8 ).getStr(),
986 OUStringToOString( aLabel, RTL_TEXTENCODING_UTF8 ).getStr(),
987 nId,
988 OUStringToOString( aCommand, RTL_TEXTENCODING_ASCII_US ).getStr() );
992 ReadMenuLabels( nLangIndex, pMenu->GetPopupMenu( nId ), eModule, bHasSlotInfos, aResourceFilePrefix );
994 else
996 if ( bHasSlotInfos )
998 CommandLabels* pCmdLabels = RetrieveCommandLabelsFromID( nId, eModule );
999 if ( !pCmdLabels )
1000 pCmdLabels = RetrieveCommandLabelsFromCommand( aCommand, eModule );
1002 if ( pCmdLabels )
1003 pCmdLabels->aLabels[nLangIndex] = aLabel;
1004 else if ( bHasUnoCommand )
1006 CommandLabels aCmdLabels;
1008 aCmdLabels.nID = ( nId > 5000 ) ? nId : 0;
1009 aCmdLabels.aCommand = aCommand;
1010 aCmdLabels.aLabels[nLangIndex] = aLabel;
1011 AddCommandLabelsToCommandHashMap( eModule, aCmdLabels );
1012 if ( nId > 5000 )
1013 AddCommandLabelsToIDHashMap( eModule, aCmdLabels );
1015 else
1017 fprintf( stderr, "Menu item with unknown uno-command and id '%s', ID = %d, aCmd = %s\n",
1018 OUStringToOString( aLabel, RTL_TEXTENCODING_UTF8 ).getStr(),
1019 nId,
1020 OUStringToOString( aCommand, RTL_TEXTENCODING_ASCII_US ).getStr() );
1023 else if ( bHasUnoCommand )
1025 CommandLabels* pCmdLabels = RetrieveCommandLabelsFromCommand( aCommand, eModule );
1026 if ( pCmdLabels )
1027 pCmdLabels->aLabels[nLangIndex] = aLabel;
1028 else
1030 CommandLabels aCmdLabels;
1032 aCmdLabels.nID = 0;
1033 aCmdLabels.aCommand = aCommand;
1034 aCmdLabels.aLabels[nLangIndex] = aLabel;
1035 AddCommandLabelsToCommandHashMap( eModule, aCmdLabels );
1042 return true;
1045 class SfxSlotInfo : public Resource
1047 OUString aName;
1048 OUString aHelpText;
1049 public:
1050 SfxSlotInfo(const ResId &rResId);
1052 const OUString &GetName() const { return aName; }
1053 const OUString &GetHelpText() const { return aHelpText; }
1056 SfxSlotInfo::SfxSlotInfo( const ResId &rResId ) :
1057 Resource( rResId.SetRT( RSC_SFX_SLOT_INFO ) )
1059 unsigned short nMask = (unsigned short) ReadShortRes();
1060 if(nMask & RSC_SFX_SLOT_INFO_SLOTNAME)
1062 aName = ReadStringRes();
1064 if(nMask & RSC_SFX_SLOT_INFO_HELPTEXT)
1066 aHelpText = ReadStringRes();
1070 bool ReadSlotInfos( int nLangIndex, ResMgr* pResMgr, MODULES eModule, const OUString& aProjectName )
1072 CommandIDToLabelsMap::iterator pIter = moduleMapFiles[MODULE_GLOBAL].begin();
1073 CommandIDToLabelsMap::iterator pEnd = moduleMapFiles[MODULE_GLOBAL].end();
1075 if ( eModule != MODULE_GLOBAL )
1077 while ( pIter != pEnd )
1079 int nId = pIter->first;
1080 CommandLabels& rCmdLabels = pIter->second;
1082 ResId aResId( nId, pResMgr );
1083 aResId.SetRT( RSC_SFX_SLOT_INFO );
1085 if ( pResMgr->IsAvailable( aResId ))
1087 SfxSlotInfo aSlotInfo( aResId );
1088 OUString aText( aSlotInfo.GetName() );
1089 if ( rCmdLabels.aLabels[nLangIndex].getLength() == 0 )
1090 rCmdLabels.aLabels[nLangIndex] = aText;
1092 ++pIter;
1096 pIter = moduleMapFiles[eModule].begin();
1097 pEnd = moduleMapFiles[eModule].end();
1098 while ( pIter != pEnd )
1100 int nId = pIter->first;
1101 CommandLabels& rCmdLabels = pIter->second;
1103 ResId aResId( nId, pResMgr );
1104 aResId.SetRT( RSC_SFX_SLOT_INFO );
1106 if ( pResMgr->IsAvailable( aResId ))
1108 SfxSlotInfo aSlotInfo( aResId );
1109 OUString aText( aSlotInfo.GetName() );
1110 if ( rCmdLabels.aLabels[nLangIndex].getLength() == 0 )
1111 rCmdLabels.aLabels[nLangIndex] = aText;
1113 ++pIter;
1116 return true;
1119 bool ReadResourceFile( int nLangIndex, const OUString& aResourceDirURL, const OUString& aResourceFilePrefix, MODULES eModule, const OUString& aProjectName, bool bHasSlotInfos )
1121 OUString aSysDirPath;
1122 OString aResFilePrefix = OUStringToOString( aResourceFilePrefix, RTL_TEXTENCODING_ASCII_US );
1124 osl::FileBase::getSystemPathFromFileURL( aResourceDirURL, aSysDirPath );
1126 String aSysDirPathStr( aSysDirPath );
1128 // String aLangString( String::CreateFromAscii( Language_Mapping[nLangIndex].pISO ));
1129 // LanguageType aLangtype = ConvertIsoStringToLanguage( aLangString );
1130 ::com::sun::star::lang::Locale aLocale;
1131 aLocale.Language = OUString::createFromAscii( Language_codes[nLangIndex].pLanguage );
1132 aLocale.Country = OUString::createFromAscii( Language_codes[nLangIndex].pCountry );
1133 ResMgr* pResMgr = ResMgr::CreateResMgr( aResFilePrefix.getStr(),
1134 aLocale,
1135 NULL,
1136 &aSysDirPathStr );
1137 if ( pResMgr )
1139 int i = 0;
1140 while ( ResourceModule_Mapping[i].nResId > 0 )
1142 if ( ResourceModule_Mapping[i].eBelongsTo == eModule )
1144 ResId aResId( ResourceModule_Mapping[i].nResId, pResMgr );
1145 aResId.SetRT( RSC_MENU );
1147 if ( pResMgr->IsAvailable( aResId ))
1149 MenuBar* pMenuBar = new MenuBar( aResId );
1150 ReadMenuLabels( nLangIndex, (Menu *)pMenuBar, eModule, bHasSlotInfos, aResourceFilePrefix );
1151 delete pMenuBar;
1154 if ( bHasSlotInfos )
1155 ReadSlotInfos( nLangIndex, pResMgr, eModule, aProjectName );
1157 ++i;
1160 i = 0;
1161 while ( AccResourceModule_Mapping[i].nResId > 0 )
1163 if ( AccResourceModule_Mapping[i].eBelongsTo != eModule )
1165 ++i;
1166 continue;
1169 ResId aAccResId( AccResourceModule_Mapping[i].nResId, pResMgr );
1170 aAccResId.SetRT( RSC_ACCEL );
1172 if (!pResMgr->IsAvailable( aAccResId ))
1174 fprintf(stdout, ".. acc %d not found\n", AccResourceModule_Mapping[i].nResId);
1175 ++i;
1176 continue;
1179 Accelerator* pAcc = new Accelerator( aAccResId );
1180 ReadAccelerators( nLangIndex, pResMgr, eModule, aProjectName, pAcc );
1181 delete pAcc;
1182 ++i;
1185 delete pResMgr;
1188 return true;
1191 static const char ENCODED_AMPERSAND[] = "&amp;";
1192 static const char ENCODED_LESS[] = "&lt;";
1193 static const char ENCODED_GREATER[] = "&gt;";
1194 static const char ENCODED_QUOTE[] = "&quot;";
1195 static const char ENCODED_APOS[] = "&apos;";
1197 struct EncodeChars
1199 char cChar;
1200 const char* pEncodedChars;
1203 EncodeChars EncodeChar_Map[] =
1205 { '&', ENCODED_AMPERSAND },
1206 { '<', ENCODED_LESS },
1207 { '>', ENCODED_GREATER },
1208 { '"', ENCODED_QUOTE },
1209 { '\'', ENCODED_APOS },
1210 { ' ', 0 }
1213 // Encodes a string to UTF-8 and uses "Built-in entity reference" to
1214 // to escape character data that is not markup!
1215 OString EncodeString( const OUString& aToEncodeStr )
1217 OString aString = OUStringToOString( aToEncodeStr, RTL_TEXTENCODING_UTF8 );
1219 int i = 0;
1220 bool bMustCopy( sal_False );
1221 while ( EncodeChar_Map[i].pEncodedChars != 0 )
1223 OStringBuffer aBuf;
1224 bool bEncoded( false );
1226 sal_Int32 nCurIndex = 0;
1227 sal_Int32 nIndex = 0;
1228 while ( nIndex < aString.getLength() )
1230 nIndex = aString.indexOf( EncodeChar_Map[i].cChar, nIndex );
1231 if ( nIndex > 0 )
1233 bEncoded = true;
1234 if ( nIndex > nCurIndex )
1235 aBuf.append( aString.copy( nCurIndex, nIndex-nCurIndex ));
1236 aBuf.append( EncodeChar_Map[i].pEncodedChars );
1237 nCurIndex = nIndex+1;
1239 else if ( nIndex == 0 )
1241 bEncoded = true;
1242 aBuf.append( EncodeChar_Map[i].pEncodedChars );
1243 nCurIndex = nIndex+1;
1245 else
1247 if ( bEncoded && nCurIndex < aString.getLength() )
1248 aBuf.append( aString.copy( nCurIndex ));
1249 break;
1251 ++nIndex;
1254 if ( bEncoded )
1255 aString = aBuf.makeStringAndClear();
1256 ++i;
1259 return aString;
1262 // Mark all commands which are popups
1263 void FindAndMarkModulePopupMenuCmds()
1265 for ( int i = 0; i < int( MODULE_COUNT ); i++ )
1267 CommandToLabelsMap::iterator pCmdIter = modulePopupMenusCmd[i].begin();
1268 CommandToLabelsMap::iterator pCmdEnd = modulePopupMenusCmd[i].end();
1269 while ( pCmdIter != pCmdEnd )
1271 CommandLabels& rCmdLabel = pCmdIter->second;
1272 if ( rCmdLabel.bPopupMenu )
1274 CommandIDToLabelsMap::iterator pIDIter = moduleMapFiles[i].begin();
1275 CommandIDToLabelsMap::iterator pIDEnd = moduleMapFiles[i].end();
1276 while ( pIDIter != pIDEnd )
1278 CommandLabels& rIDLabel = pIDIter->second;
1279 if ( rIDLabel.aCommand.equals( rCmdLabel.aCommand ))
1281 rIDLabel.bPopupMenu = true;
1282 break;
1284 ++pIDIter;
1288 ++pCmdIter;
1294 bool FindAndMarkPopupMenuCmds( const OUString& aCommand, MODULES eExcludeModule )
1296 bool bFound( sal_False );
1298 for ( int i = 1; i < int( MODULE_COUNT ); i++ )
1300 if ( eExcludeModule != MODULES( i ))
1302 CommandToLabelsMap::iterator pCmdIter = modulePopupMenusCmd[i].find( aCommand );
1303 if ( pCmdIter != modulePopupMenusCmd[i].end() )
1305 CommandLabels& rCmdLabel = pCmdIter->second;
1306 rCmdLabel.bWritten = true; // mark as written, this is now a global popup menu command
1307 bFound = true;
1312 return bFound;
1315 bool FindAndMoveGlobalPopupMenus()
1317 for ( int i = 1; i < int( MODULE_COUNT ); i++ )
1319 CommandToLabelsMap::iterator pCmdIter = modulePopupMenusCmd[i].begin();
1320 CommandToLabelsMap::iterator pCmdEnd = modulePopupMenusCmd[i].end();
1321 while ( pCmdIter != pCmdEnd )
1323 CommandLabels& rCmdLabel = pCmdIter->second;
1324 if ( rCmdLabel.bPopupMenu )
1326 bool bDuplicate = FindAndMarkPopupMenuCmds( rCmdLabel.aCommand, MODULES( i ));
1327 if ( bDuplicate )
1329 CommandToLabelsMap::const_iterator pIter = modulePopupMenusCmd[MODULE_GLOBAL].find( rCmdLabel.aCommand );
1330 if ( pIter == modulePopupMenusCmd[MODULE_GLOBAL].end() )
1332 // Put command into global ui command list
1333 CommandLabels aCmdLabels;
1335 aCmdLabels.nID = 0;
1336 aCmdLabels.aCommand = rCmdLabel.aCommand;
1337 aCmdLabels.bPopupMenu = true;
1338 for ( int j = 0; j < NUM_LANGUAGES; j++ )
1339 aCmdLabels.aLabels[j] = rCmdLabel.aLabels[j];
1340 AddCommandLabelsToCommandHashMap( MODULE_GLOBAL, aCmdLabels );
1341 rCmdLabel.bWritten = true;
1343 else
1345 rCmdLabel.bWritten = true;
1349 ++pCmdIter;
1353 return true;
1356 static const char XMLStart[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
1358 bool WriteXMLFiles( const OUString& aOutputDirURL)
1360 static const char DocType[] = "<!DOCTYPE oor:component-data SYSTEM \"../../../../../component-update.dtd\">\n";
1361 static const char ComponentDataStart[] = "<oor:component-data oor:name=\"";
1362 static const char ComponentDataStartEnd[] = "\" oor:package=\"org.openoffice.Office.UI\" xmlns:oor=\"http://openoffice.org/2001/registry\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";
1363 static const char GroupText[] = "\t<node oor:name=\"UserInterface\">\n";
1364 static const char SetTextCmds[] = "\t\t<node oor:name=\"Commands\">\n";
1365 static const char SetTextPopups[] = "\t\t<node oor:name=\"Popups\">\n";
1366 static const char NodeStart[] = "\t\t\t<node oor:name=\"";
1367 static const char ReplaceOp[] = "\" oor:op=\"replace\">\n";
1368 static const char NodeEnd[] = "\t\t\t</node>\n";
1369 static const char PropLabelNodeStart[] = "\t\t\t\t<prop oor:name=\"Label\" oor:type=\"xs:string\">\n";
1370 static const char PropNodeEnd[] = "\t\t\t\t</prop>\n";
1371 static const char PropPropNodeStart[] = "\t\t\t\t<prop oor:name=\"Properties\" oor:type=\"xs:int\">\n";
1372 static const char PropHelpIdStart[] = "\t\t\t\t<prop oor:name=\"HelpId\" oor:type=\"xs:int\">\n";
1373 static const char ValueSimpleNodeStart[] = "\t\t\t\t\t<value>";
1374 static const char ValueNodeStart[] = "\t\t\t\t\t<value xml:lang=\"";
1375 static const char ValueNodeMid[] = "\">";
1376 static const char ValueNodeEnd[] = "</value>\n";
1377 static const char ValueNodeEmpty[] = "\t\t\t\t\t<value/>\n";
1378 static const char SetTextEnd[] = "\t\t</node>\n";
1379 static const char GroupTextEnd[] = "\t</node>\n";
1380 static const char ComponentDataEnd[] = "</oor:component-data>\n";
1382 // Search popup menu commands that can be moved to the global list as they are used in more than one project
1383 FindAndMoveGlobalPopupMenus();
1384 // Search and mark all commands which are popups
1385 FindAndMarkModulePopupMenuCmds();
1387 OUString aOutputDirectoryURL( aOutputDirURL );
1388 if ( aOutputDirectoryURL.getLength() > 0 && aOutputDirectoryURL[aOutputDirectoryURL.getLength()-1] != '/' )
1389 aOutputDirectoryURL += OUString::createFromAscii( "/" );
1391 int i = 0;
1392 while ( ModuleToXML_Mapping[i] != 0 )
1394 OUString aOutputFileURL( aOutputDirectoryURL );
1395 aOutputFileURL += OUString::createFromAscii( ModuleToXML_Mapping[i] );
1396 aOutputFileURL += OUString::createFromAscii( XMLFileExtension );
1398 osl::File aXMLFile( aOutputFileURL );
1400 osl::File::RC nRet = aXMLFile.open( OpenFlag_Create|OpenFlag_Write );
1401 if ( nRet == osl::File::E_EXIST )
1403 nRet = aXMLFile.open( OpenFlag_Write );
1404 if ( nRet == osl::File::E_None )
1405 nRet = aXMLFile.setSize( 0 );
1408 if ( nRet == osl::FileBase::E_None )
1410 sal_uInt64 nWritten;
1412 aXMLFile.write( XMLStart, strlen( XMLStart ), nWritten );
1413 aXMLFile.write( DocType, strlen( DocType ), nWritten );
1414 aXMLFile.write( ComponentDataStart, strlen( ComponentDataStart ), nWritten );
1415 aXMLFile.write( ModuleToXML_Mapping[i], strlen( ModuleToXML_Mapping[i] ), nWritten );
1416 aXMLFile.write( ComponentDataStartEnd, strlen( ComponentDataStartEnd ), nWritten );
1417 aXMLFile.write( GroupText, strlen( GroupText ), nWritten );
1419 if (( !moduleMapFiles[i].empty() ) ||
1420 ( !modulePopupMenusCmd[i].empty() ) )
1422 for ( int nSets = 0; nSets < 2; nSets++ )
1424 if ( nSets == 0 )
1425 aXMLFile.write( SetTextCmds, strlen( SetTextCmds ), nWritten );
1426 else
1427 aXMLFile.write( SetTextPopups, strlen( SetTextPopups ), nWritten );
1429 CommandIDToLabelsMap::iterator pIter = moduleMapFiles[i].begin();
1430 CommandIDToLabelsMap::iterator pEnd = moduleMapFiles[i].end();
1431 while ( pIter != pEnd )
1433 CommandLabels& rCmdLabels = pIter->second;
1435 if ( rCmdLabels.bWritten )
1437 ++pIter;
1438 continue;
1441 CommandToLabelsMap::iterator pCmdIter = modulePopupMenusCmd[i].find( rCmdLabels.aCommand );
1442 if ( pCmdIter != modulePopupMenusCmd[i].end() )
1444 // Mark as written within the popup menus hash table
1445 CommandLabels& rCmdLabel = pCmdIter->second;
1446 rCmdLabel.bWritten = true;
1449 // We have to save popups on the next iteration
1450 if (( nSets == 0 ) && rCmdLabels.bPopupMenu )
1452 ++pIter;
1453 continue;
1456 // Mark as written for next iteration
1457 rCmdLabels.bWritten = true;
1459 // we have to use UTF-8 as encoding
1460 OString aCmd = OUStringToOString( rCmdLabels.aCommand, RTL_TEXTENCODING_UTF8 );
1462 aXMLFile.write( NodeStart, strlen( NodeStart ), nWritten );
1463 aXMLFile.write( aCmd.getStr(), aCmd.getLength(), nWritten );
1464 aXMLFile.write( ReplaceOp, strlen( ReplaceOp ), nWritten );
1465 aXMLFile.write( PropLabelNodeStart, strlen( PropLabelNodeStart ), nWritten );
1467 sal_Bool bLabels( sal_False );
1468 for ( int j = 0; j < NUM_LANGUAGES; j++ )
1470 OString aLabel;
1471 if ( rCmdLabels.aLabels[j].getLength() > 0 )
1473 bLabels = sal_True;
1475 // Encode label to the XML rules.
1476 aLabel = EncodeString( rCmdLabels.aLabels[j] );
1478 else
1480 CommandToLabelsMap::const_iterator pIter = modulePopupMenusCmd[i].find( rCmdLabels.aCommand );
1481 if ( pIter != modulePopupMenusCmd[i].end() )
1483 const CommandLabels& rCmdLabels = pIter->second;
1484 if ( rCmdLabels.aLabels[j].getLength() > 0 )
1486 bLabels = sal_True;
1487 aLabel = EncodeString( rCmdLabels.aLabels[j] );
1492 if ( aLabel.getLength() > 0 )
1494 OString mystr;
1495 mystr += Language_codes[j].pLanguage;
1496 if ( strlen(Language_codes[j].pCountry))
1498 mystr += "-";
1499 mystr += Language_codes[j].pCountry;
1503 char mystr[255];
1504 strncat( mystr, Language_codes[j].pLanguage, 2);
1505 if ( strlen(Language_codes[j].pCountry))
1507 strncat( mystr, "-", 1);
1508 strncat( mystr, Language_codes[j].pCountry, 2);
1511 aXMLFile.write( ValueNodeStart, strlen( ValueNodeStart ), nWritten );
1512 aXMLFile.write( mystr, strlen( mystr ), nWritten );
1513 aXMLFile.write( ValueNodeMid, strlen( ValueNodeMid ), nWritten );
1514 aXMLFile.write( aLabel.getStr(), aLabel.getLength(), nWritten );
1515 aXMLFile.write( ValueNodeEnd, strlen( ValueNodeEnd ), nWritten );
1519 if ( !bLabels )
1520 aXMLFile.write( ValueNodeEmpty, strlen( ValueNodeEmpty ), nWritten );
1521 aXMLFile.write( PropNodeEnd, strlen( PropNodeEnd ), nWritten );
1523 char aBuf[16] = {0};
1525 // write properties node which stores additional information about a command
1526 if ( rCmdLabels.nProperties != 0 )
1528 sprintf( aBuf, "%d", rCmdLabels.nProperties );
1529 aXMLFile.write( PropPropNodeStart, strlen( PropPropNodeStart ), nWritten );
1530 aXMLFile.write( ValueSimpleNodeStart, strlen( ValueSimpleNodeStart ), nWritten );
1531 aXMLFile.write( aBuf, strlen( aBuf ), nWritten );
1532 aXMLFile.write( ValueNodeEnd, strlen( ValueNodeEnd ), nWritten );
1533 aXMLFile.write( PropNodeEnd, strlen( PropNodeEnd ), nWritten );
1537 // write help ID property node
1538 sprintf( aBuf, "%d", rCmdLabels.nID );
1539 aXMLFile.write( PropHelpIdStart, strlen( PropHelpIdStart ), nWritten );
1540 aXMLFile.write( ValueSimpleNodeStart, strlen( ValueSimpleNodeStart ), nWritten );
1541 aXMLFile.write( aBuf, strlen( aBuf ), nWritten );
1542 aXMLFile.write( ValueNodeEnd, strlen( ValueNodeEnd ), nWritten );
1543 aXMLFile.write( PropNodeEnd, strlen( PropNodeEnd ), nWritten );
1545 aXMLFile.write( NodeEnd, strlen( NodeEnd ), nWritten );
1546 ++pIter;
1549 sal_uInt32 nSize = modulePopupMenusCmd[i].size();
1550 if ( nSize > 0 )
1552 CommandToLabelsMap::iterator pIter = modulePopupMenusCmd[i].begin();
1553 while ( pIter != modulePopupMenusCmd[i].end() )
1555 CommandLabels& rCmdLabels = pIter->second;
1557 if (( nSets == 0 ) && rCmdLabels.bPopupMenu )
1559 ++pIter;
1560 continue;
1563 if ( !rCmdLabels.bWritten )
1565 rCmdLabels.bWritten = true;
1566 OString aCmd( OUStringToOString( rCmdLabels.aCommand, RTL_TEXTENCODING_UTF8 ));
1567 aXMLFile.write( NodeStart, strlen( NodeStart ), nWritten );
1568 aXMLFile.write( aCmd.getStr(), aCmd.getLength(), nWritten );
1569 aXMLFile.write( ReplaceOp, strlen( ReplaceOp ), nWritten );
1570 aXMLFile.write( PropLabelNodeStart, strlen( PropLabelNodeStart ), nWritten );
1572 sal_Bool bLabels( sal_False );
1573 for ( int k = 0; k < NUM_LANGUAGES; k++ )
1575 if ( rCmdLabels.aLabels[k].getLength() > 0 )
1577 bLabels = sal_True;
1578 OString aLabel( OUStringToOString( rCmdLabels.aLabels[k], RTL_TEXTENCODING_UTF8 ));
1580 char mystr[255];
1581 strncat( mystr, Language_codes[k].pLanguage, 2);
1582 if ( strlen(Language_codes[k].pCountry))
1584 strncat( mystr, "-", 1);
1585 strncat( mystr, Language_codes[k].pCountry, 2);
1588 aXMLFile.write( ValueNodeStart, strlen( ValueNodeStart ), nWritten );
1589 aXMLFile.write( mystr, strlen( mystr ), nWritten );
1590 aXMLFile.write( ValueNodeMid, strlen( ValueNodeMid ), nWritten );
1591 aXMLFile.write( aLabel.getStr(), aLabel.getLength(), nWritten );
1592 aXMLFile.write( ValueNodeEnd, strlen( ValueNodeEnd ), nWritten );
1596 if ( !bLabels )
1597 aXMLFile.write( ValueNodeEmpty, strlen( ValueNodeEmpty ), nWritten );
1599 aXMLFile.write( PropNodeEnd, strlen( PropNodeEnd ), nWritten );
1600 aXMLFile.write( NodeEnd, strlen( NodeEnd ), nWritten );
1603 ++pIter;
1607 aXMLFile.write( SetTextEnd, strlen( SetTextEnd ), nWritten );
1610 else
1612 // Write empty sets
1613 aXMLFile.write( SetTextCmds, strlen( SetTextCmds ), nWritten );
1614 aXMLFile.write( SetTextEnd, strlen( SetTextEnd ), nWritten );
1615 aXMLFile.write( SetTextPopups, strlen( SetTextPopups ), nWritten );
1616 aXMLFile.write( SetTextEnd, strlen( SetTextEnd ), nWritten );
1619 aXMLFile.write( GroupTextEnd, strlen( GroupTextEnd ), nWritten );
1620 aXMLFile.write( ComponentDataEnd, strlen( ComponentDataEnd ), nWritten );
1622 aXMLFile.close();
1623 ++i;
1627 return true;
1630 bool WriteLevel( osl::File& rFile, int nLevel )
1632 const char cTab[] = "\t";
1634 sal_uInt64 nWritten;
1635 for ( int i = 0; i < nLevel; i++ )
1636 rFile.write( cTab, strlen( cTab ), nWritten );
1638 return true;
1641 bool WriteSeparator( osl::File& rFile, int nLevel )
1643 static const char MenuSeparator[] = "<menu:menuseparator/>\n";
1645 sal_uInt64 nWritten;
1646 WriteLevel( rFile, nLevel );
1647 rFile.write( MenuSeparator, strlen( MenuSeparator ), nWritten );
1649 return true;
1652 bool WriteMenuItem( osl::File& rFile, const OUString& aCmd, const OUString& aHelpID, int nLevel )
1654 static const char MenuItemStart[] = "<menu:menuitem menu:id=\"";
1655 static const char MenuItemHelp[] = "menu:helpid=\"";
1656 static const char MenuItemLabel[] = "menu:label=\"";
1657 static const char MenuItemAttrEnd[] = "\" ";
1658 static const char MenuItemEnd[] = "/>\n";
1660 OString aCmdStr = OUStringToOString( aCmd, RTL_TEXTENCODING_UTF8 );
1661 OString aHelpId = OUStringToOString( aHelpID, RTL_TEXTENCODING_UTF8 );
1663 sal_uInt64 nWritten;
1664 WriteLevel( rFile, nLevel );
1665 rFile.write( MenuItemStart, strlen( MenuItemStart ), nWritten );
1666 rFile.write( aCmdStr.getStr(), aCmdStr.getLength(), nWritten );
1667 rFile.write( MenuItemAttrEnd, strlen( MenuItemAttrEnd ), nWritten );
1668 rFile.write( MenuItemHelp, strlen( MenuItemHelp ), nWritten );
1669 rFile.write( aHelpId.getStr(), aHelpId.getLength(), nWritten );
1670 rFile.write( MenuItemAttrEnd, strlen( MenuItemAttrEnd ), nWritten );
1671 rFile.write( MenuItemLabel, strlen( MenuItemLabel ), nWritten );
1672 rFile.write( MenuItemAttrEnd, strlen( MenuItemAttrEnd ), nWritten );
1673 rFile.write( MenuItemEnd, strlen( MenuItemEnd ), nWritten );
1675 return true;
1678 bool WritePopupMenuEmpty( osl::File& rFile, int nLevel )
1680 static const char MenuPopupStart[] = "<menu:menupopup/>\n";
1682 sal_uInt64 nWritten;
1683 WriteLevel( rFile, nLevel );
1684 rFile.write( MenuPopupStart, strlen( MenuPopupStart ), nWritten );
1686 return true;
1689 bool WritePopupMenuStart( osl::File& rFile, int nLevel )
1691 static const char MenuPopupStart[] = "<menu:menupopup>\n";
1693 sal_uInt64 nWritten;
1694 WriteLevel( rFile, nLevel );
1695 rFile.write( MenuPopupStart, strlen( MenuPopupStart ), nWritten );
1697 return true;
1700 bool WritePopupMenuEnd( osl::File& rFile, int nLevel )
1702 static const char MenuPopupEnd[] = "</menu:menupopup>\n";
1704 sal_uInt64 nWritten;
1705 WriteLevel( rFile, nLevel );
1706 rFile.write( MenuPopupEnd, strlen( MenuPopupEnd ), nWritten );
1708 return true;
1711 bool WriteMenuStart( osl::File& rFile, const OUString& aCmd, int nLevel )
1713 static const char MenuStart[] = "<menu:menu menu:id=\"";
1714 static const char MenuEnd[] = ">\n";
1715 static const char MenuAttrEnd[] = "\" ";
1716 static const char MenuLabel[] = "menu:label=\"";
1718 OString aCmdStr = OUStringToOString( aCmd, RTL_TEXTENCODING_UTF8 );
1720 sal_uInt64 nWritten;
1721 WriteLevel( rFile, nLevel );
1722 rFile.write( MenuStart, strlen( MenuStart ), nWritten );
1723 rFile.write( aCmdStr.getStr(), aCmdStr.getLength(), nWritten );
1724 rFile.write( MenuAttrEnd, strlen( MenuAttrEnd ), nWritten );
1725 rFile.write( MenuLabel, strlen( MenuLabel ), nWritten );
1726 rFile.write( MenuAttrEnd, strlen( MenuAttrEnd ), nWritten );
1727 rFile.write( MenuEnd, strlen( MenuEnd ), nWritten );
1729 return true;
1732 bool WriteMenuEnd( osl::File& rFile, int nLevel )
1734 static const char MenuEnd[] = "</menu:menu>\n";
1736 sal_uInt64 nWritten;
1737 WriteLevel( rFile, nLevel );
1738 rFile.write( MenuEnd, strlen( MenuEnd ), nWritten );
1740 return true;
1743 bool WriteAccXML( osl::File& rFile, Accelerator* pAcc, MODULES eModule, int nLevel )
1745 ::rtl::OUString aCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
1747 for ( unsigned short n = 0; n < pAcc->GetItemCount(); n++ )
1749 unsigned short nId = pAcc->GetItemId( n );
1752 return true;
1755 bool WriteMenuBarXML( osl::File& rFile, Menu* pMenu, MODULES eModule, int nLevel )
1757 OUString aCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
1759 for ( unsigned short n = 0; n < pMenu->GetItemCount(); n++ )
1761 unsigned short nId = pMenu->GetItemId( n );
1762 if ( pMenu->GetItemType( n ) != MENUITEM_SEPARATOR )
1764 OUString aLabel( pMenu->GetItemText( nId ));
1765 OUString aCommand( pMenu->GetItemCommand( nId ));
1766 bool bHasUnoCommand( aCommand.getLength() > 0 && ( aCommand.indexOf( aCmd ) == 0 ));
1768 if ( pMenu->GetPopupMenu( nId ) != 0 )
1770 if ( !bHasUnoCommand )
1772 CommandLabels* pCmdLabels = 0;
1773 pCmdLabels = RetrieveCommandLabelsFromID( nId, eModule );
1774 if ( !pCmdLabels )
1775 pCmdLabels = RetrieveCommandLabelsFromCommand( aCommand, eModule );
1777 if ( pCmdLabels )
1778 aCommand = pCmdLabels->aCommand;
1779 else if ( aCommand.getLength() == 0 )
1780 aCommand = OUString( RTL_CONSTASCII_USTRINGPARAM( "???" ));
1783 WriteMenuStart( rFile, aCommand, nLevel );
1784 WritePopupMenuStart( rFile, nLevel+1 );
1785 WriteMenuBarXML( rFile, pMenu->GetPopupMenu( nId ), eModule, nLevel+2 );
1786 WritePopupMenuEnd( rFile, nLevel+1 );
1787 WriteMenuEnd( rFile, nLevel );
1789 else if ( pMenu->IsMenuBar() )
1791 // write empty popup menu
1792 WriteMenuStart( rFile, aCommand, nLevel );
1793 WritePopupMenuEmpty( rFile, nLevel+1 );
1794 WriteMenuEnd( rFile, nLevel );
1796 else
1798 CommandLabels* pCmdLabels = RetrieveCommandLabelsFromID( nId, eModule );
1799 if ( !pCmdLabels )
1800 pCmdLabels = RetrieveCommandLabelsFromCommand( aCommand, eModule );
1802 if ( pCmdLabels )
1803 aCommand = pCmdLabels->aCommand;
1804 else
1805 aCommand = OUString( RTL_CONSTASCII_USTRINGPARAM( "???" ));
1807 OUString aHelpId = OUString::valueOf( sal_Int32( pMenu->GetHelpId( nId )));
1808 WriteMenuItem( rFile, aCommand, aHelpId, nLevel );
1811 else
1813 WriteSeparator( rFile, nLevel );
1817 return true;
1820 bool impl_isAccListDuplicate(const KeyCommandInfoList& rAccsReference,
1821 const KeyCommandInfoList& rAccs )
1823 KeyCommandInfoList::const_iterator pIt1;
1824 KeyCommandInfoList::const_iterator aEnd = rAccsReference.end();
1825 for ( pIt1 = rAccsReference.begin();
1826 pIt1 != aEnd ;
1827 ++pIt1 )
1829 KeyCommandInfoList::const_iterator pIt2 = ::std::find(rAccs.begin(), rAccs.end(), *pIt1);
1830 if (pIt2 == rAccs.end())
1831 return false;
1833 return true;
1836 bool ReadResourceWriteAcceleratorXMLLang( const ::rtl::OUString& aOutDirURL,
1837 const ::rtl::OUString& aResourceDirURL,
1838 const ::rtl::OUString& aResourceFilePrefix,
1839 MODULES eModule,
1840 const ::rtl::OUString& aProjectName,
1841 int nLanguage)
1843 static const char AccStart[] = "<accel:acceleratorlist xmlns:accel=\"http://openoffice.org/2001/accel\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
1844 static const char AccEnd[] = "</accel:acceleratorlist>\n";
1846 Locale2KeyCommandInfoList& rLocale = moduleAccs[eModule];
1847 KeyCommandInfoList& rAccs = rLocale[nLanguage]; // current language
1848 KeyCommandInfoList& rAccsReference = rLocale[1]; // en-US!
1850 // dont write empty files :-)
1851 if ( rAccs.empty() )
1852 return true;
1854 ::rtl::OUString sLanguage = ::rtl::OUString::createFromAscii(Language_codes[nLanguage].pLanguage);
1855 ::rtl::OUString sCountry = ::rtl::OUString::createFromAscii(Language_codes[nLanguage].pCountry);
1857 // dont generate duplicate xml files, if current language isnt different from en-US!
1858 // Of course we have to write en-US everytimes :-)
1859 if (nLanguage != 1 && impl_isAccListDuplicate(rAccsReference, rAccs))
1861 fprintf(stdout, "ignore acc list [mod=%d, lang=%s-%s] ... seems to be duplicate against en-US=1\n", eModule, ::rtl::OUStringToOString(sLanguage, RTL_TEXTENCODING_UTF8).getStr(), ::rtl::OUStringToOString(sCountry, RTL_TEXTENCODING_UTF8).getStr());
1862 return true;
1865 fprintf(stdout, "write acc list [mod=%d, lang=%s-%s] ... seems to be duplicate against en-US=1\n", eModule, ::rtl::OUStringToOString(sLanguage, RTL_TEXTENCODING_UTF8).getStr(), ::rtl::OUStringToOString(sCountry, RTL_TEXTENCODING_UTF8).getStr());
1867 ::rtl::OUString aSysDirPath;
1868 ::rtl::OString aResFilePrefix = ::rtl::OUStringToOString( aResourceFilePrefix, RTL_TEXTENCODING_ASCII_US );
1870 osl::FileBase::getSystemPathFromFileURL( aResourceDirURL, aSysDirPath );
1872 String aSysDirPathStr( aSysDirPath );
1874 ::rtl::OUString aOutputDirectoryURL( aOutDirURL );
1875 if ( aOutputDirectoryURL.getLength() > 0 && aOutputDirectoryURL[aOutputDirectoryURL.getLength()-1] != '/' )
1876 aOutputDirectoryURL += ::rtl::OUString::createFromAscii( "/" );
1878 int i = 0;
1879 while ( AccResourceModule_Mapping[i].nResId > 0 )
1881 if ( AccResourceModule_Mapping[i].eBelongsTo == eModule )
1882 break;
1883 ++i;
1886 ::rtl::OUString aOutputFileURL( aOutputDirectoryURL );
1887 aOutputFileURL += ::rtl::OUString::createFromAscii( AccResourceModule_Mapping[i].pXMLPrefix );
1888 aOutputFileURL += ::rtl::OUString::createFromAscii( "_(" );
1889 aOutputFileURL += sLanguage;
1890 aOutputFileURL += ::rtl::OUString::createFromAscii( "-" );
1891 aOutputFileURL += sCountry;
1892 aOutputFileURL += ::rtl::OUString::createFromAscii( ")_accelerator.xml" );
1894 osl::File aXMLFile( aOutputFileURL );
1895 osl::File::RC nRet = aXMLFile.open( OpenFlag_Write );
1896 if ( nRet != osl::File::E_None )
1898 nRet = aXMLFile.open( OpenFlag_Write | OpenFlag_Create );
1899 if ( nRet != osl::File::E_None )
1901 fprintf(stdout, "ERROR:\tcould not create acc.xml \"%s\" [ret=%d]\n", ::rtl::OUStringToOString( aOutputFileURL, RTL_TEXTENCODING_ASCII_US ).getStr(), nRet);
1902 return false;
1906 sal_uInt64 nWritten;
1908 aXMLFile.write( XMLStart, strlen( XMLStart ), nWritten );
1909 aXMLFile.write( AccStart, strlen( AccStart ), nWritten );
1911 ::rtl::OUStringBuffer sAccBuf(10000);
1912 KeyCommandInfoList::const_iterator pIt;
1913 KeyCommandInfoList::const_iterator aEnd = rAccs.end();
1914 for ( pIt = rAccs.begin();
1915 pIt != aEnd ;
1916 ++pIt )
1918 const KeyCommandInfo& aInfo = *pIt;
1920 sAccBuf.appendAscii("\t<accel:item accel:code=\"");
1921 sAccBuf.append(aInfo.sKey);
1922 sAccBuf.appendAscii("\"");
1924 BOOL bShift = ((aInfo.aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT );
1925 BOOL bMod1 = ((aInfo.aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 );
1926 BOOL bMod2 = ((aInfo.aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 );
1927 BOOL bMod3 = ((aInfo.aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 );
1929 if (bShift)
1930 sAccBuf.appendAscii(" accel:shift=\"true\"");
1931 if (bMod1)
1932 sAccBuf.appendAscii(" accel:mod1=\"true\"");
1933 if (bMod2)
1934 sAccBuf.appendAscii(" accel:mod2=\"true\"");
1935 if (bMod3)
1936 sAccBuf.appendAscii(" accel:mod3=\"true\"");
1938 sAccBuf.appendAscii(" xlink:href=\"");
1939 sAccBuf.append(aInfo.sCommand);
1940 sAccBuf.appendAscii("\"/>\n");
1943 ::rtl::OString sAcc = ::rtl::OUStringToOString(sAccBuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
1945 aXMLFile.write( sAcc.getStr(), sAcc.getLength(), nWritten );
1946 aXMLFile.write( AccEnd, strlen( AccEnd ), nWritten );
1947 aXMLFile.close();
1949 return true;
1952 bool ReadResourceWriteAcceleratorXML( const ::rtl::OUString& aOutDirURL,
1953 const ::rtl::OUString& aResourceDirURL,
1954 const ::rtl::OUString& aResourceFilePrefix,
1955 MODULES eModule,
1956 const ::rtl::OUString& aProjectName)
1958 for ( int k = 0; k < NUM_LANGUAGES; k++ )
1960 if (!ReadResourceWriteAcceleratorXMLLang(aOutDirURL, aResourceDirURL, aResourceFilePrefix, eModule, aProjectName, k))
1961 return false;
1963 return true;
1966 bool ReadResourceWriteMenuBarXML( const OUString& aOutDirURL,
1967 const OUString& aResourceDirURL,
1968 const OUString& aResourceFilePrefix,
1969 MODULES eModule,
1970 const OUString& aProjectName )
1972 static const char MenuBarStart[] = "<menu:menubar xmlns:menu=\"http://openoffice.org/2001/menu\" menu:id=\"menubar\">\n";
1973 static const char MenuBarEnd[] = "</menu:menubar>";
1975 OUString aSysDirPath;
1976 OString aResFilePrefix = OUStringToOString( aResourceFilePrefix, RTL_TEXTENCODING_ASCII_US );
1978 osl::FileBase::getSystemPathFromFileURL( aResourceDirURL, aSysDirPath );
1980 String aSysDirPathStr( aSysDirPath );
1982 // String aLangString( String::CreateFromAscii( Language_Mapping[0].pISO ));
1983 // LanguageType aLangtype = ConvertIsoStringToLanguage( aLangString );
1984 ::com::sun::star::lang::Locale aLocale;
1985 aLocale.Language = OUString::createFromAscii( Language_codes[1].pLanguage );
1986 aLocale.Country = OUString::createFromAscii( Language_codes[1].pCountry );
1987 ResMgr* pResMgr = ResMgr::CreateResMgr( aResFilePrefix.getStr(),
1988 aLocale,
1989 NULL,
1990 &aSysDirPathStr );
1991 if ( pResMgr )
1993 OUString aMenuBar( RTL_CONSTASCII_USTRINGPARAM( "menubar" ));
1994 int i = 0;
1995 while ( ResourceModule_Mapping[i].nResId > 0 )
1997 if ( ResourceModule_Mapping[i].eBelongsTo == eModule )
1999 ResId aResId( ResourceModule_Mapping[i].nResId, pResMgr );
2000 aResId.SetRT( RSC_MENU );
2002 if ( pResMgr->IsAvailable( aResId ))
2004 OUString aOutputDirectoryURL( aOutDirURL );
2005 if ( aOutputDirectoryURL.getLength() > 0 && aOutputDirectoryURL[aOutputDirectoryURL.getLength()-1] != '/' )
2006 aOutputDirectoryURL += OUString::createFromAscii( "/" );
2008 OUString aOutputFileURL( aOutputDirectoryURL );
2009 aOutputFileURL += OUString::createFromAscii( ResourceModule_Mapping[i].pXMLPrefix );
2010 aOutputFileURL += aMenuBar;
2011 aOutputFileURL += OUString::createFromAscii( ".xml" );
2013 osl::File aXMLFile( aOutputFileURL );
2014 osl::File::RC nRet = aXMLFile.open( OpenFlag_Create|OpenFlag_Write );
2015 if ( nRet == osl::File::E_EXIST )
2017 nRet = aXMLFile.open( OpenFlag_Write );
2018 if ( nRet == osl::File::E_None )
2019 nRet = aXMLFile.setSize( 0 );
2022 if ( nRet == osl::FileBase::E_None )
2024 sal_uInt64 nWritten;
2026 aXMLFile.write( XMLStart, strlen( XMLStart ), nWritten );
2027 aXMLFile.write( MenuBarStart, strlen( MenuBarStart ), nWritten );
2029 MenuBar* pMenuBar = new MenuBar( aResId );
2030 WriteMenuBarXML( aXMLFile, (Menu *)pMenuBar, eModule, 1 );
2031 delete pMenuBar;
2033 aXMLFile.write( MenuBarEnd, strlen( MenuBarEnd ), nWritten );
2034 aXMLFile.close();
2038 ++i;
2041 delete pResMgr;
2044 return true;
2047 bool WriteToolBarSeparator( osl::File& rFile )
2049 static const char ToolBarSeparator[] = " <toolbar:toolbarseparator/>\n";
2051 sal_uInt64 nWritten;
2052 rFile.write( ToolBarSeparator, strlen( ToolBarSeparator ), nWritten );
2054 return true;
2057 bool WriteToolBarSpace( osl::File& rFile )
2059 static const char ToolBarSpace[] = " <toolbar:toolbarspace/>\n";
2061 sal_uInt64 nWritten;
2062 rFile.write( ToolBarSpace, strlen( ToolBarSpace ), nWritten );
2064 return true;
2067 bool WriteToolBarBreak( osl::File& rFile )
2069 static const char ToolBarBlank[] = " <toolbar:toolbarbreak/>\n";
2071 sal_uInt64 nWritten;
2072 rFile.write( ToolBarBlank, strlen( ToolBarBlank ), nWritten );
2074 return true;
2077 bool WriteToolBarItem( osl::File& rFile, const OUString& aCmd, const OUString& aHelpID, ToolBoxItemBits nStyle, bool bVisible )
2079 static const char ToolBarItemStart[] = " <toolbar:toolbaritem xlink:href=\"";
2080 static const char ToolBarItemLabel[] = "toolbar:text=\"";
2081 static const char ToolBarItemHelp[] = "toolbar:helpid=\"helpid:";
2082 static const char ToolBarItemStyle[] = "toolbar:style=\"";
2083 static const char ToolBarItemVisible[] = "toolbar:visible=\"false";
2084 static const char ToolBarItemAttrEnd[] = "\" ";
2085 static const char ToolBarItemEnd[] = "/>\n";
2086 static const char ATTRIBUTE_ITEMSTYLE_RADIO[] = "radio";
2087 static const char ATTRIBUTE_ITEMSTYLE_AUTO[] = "auto";
2088 static const char ATTRIBUTE_ITEMSTYLE_LEFT[] = "left";
2089 static const char ATTRIBUTE_ITEMSTYLE_AUTOSIZE[] = "autosize";
2090 static const char ATTRIBUTE_ITEMSTYLE_DROPDOWN[] = "dropdown";
2091 static const char ATTRIBUTE_ITEMSTYLE_REPEAT[] = "repeat";
2093 OString aCmdStr = OUStringToOString( aCmd, RTL_TEXTENCODING_UTF8 );
2094 OString aHelpId = OUStringToOString( aHelpID, RTL_TEXTENCODING_UTF8 );
2096 sal_uInt64 nWritten;
2097 rFile.write( ToolBarItemStart, strlen( ToolBarItemStart ), nWritten );
2098 rFile.write( aCmdStr.getStr(), aCmdStr.getLength(), nWritten );
2099 rFile.write( ToolBarItemAttrEnd, strlen( ToolBarItemAttrEnd ), nWritten );
2100 rFile.write( ToolBarItemHelp, strlen( ToolBarItemHelp ), nWritten );
2101 rFile.write( aHelpId.getStr(), aHelpId.getLength(), nWritten );
2102 rFile.write( ToolBarItemAttrEnd, strlen( ToolBarItemAttrEnd ), nWritten );
2103 rFile.write( ToolBarItemLabel, strlen( ToolBarItemLabel ), nWritten );
2104 rFile.write( ToolBarItemAttrEnd, strlen( ToolBarItemAttrEnd ), nWritten );
2105 if ( nStyle != 0 )
2107 rFile.write( ToolBarItemStyle, strlen( ToolBarItemStyle ), nWritten );
2108 sal_Bool bBitSet( sal_False );
2109 if ( nStyle & TIB_RADIOCHECK )
2111 rFile.write( ATTRIBUTE_ITEMSTYLE_RADIO, strlen( ATTRIBUTE_ITEMSTYLE_RADIO ), nWritten );
2112 bBitSet = sal_True;
2114 if ( nStyle & TIB_AUTOCHECK )
2116 if ( bBitSet )
2117 rFile.write( " ", 1, nWritten );
2118 rFile.write( ATTRIBUTE_ITEMSTYLE_AUTO, strlen( ATTRIBUTE_ITEMSTYLE_AUTO ), nWritten );
2119 bBitSet = sal_True;
2121 if ( nStyle & TIB_LEFT )
2123 if ( bBitSet )
2124 rFile.write( " ", 1, nWritten );
2125 rFile.write( ATTRIBUTE_ITEMSTYLE_LEFT, strlen( ATTRIBUTE_ITEMSTYLE_LEFT ), nWritten );
2126 bBitSet = sal_True;
2128 if ( nStyle & TIB_AUTOSIZE )
2130 if ( bBitSet )
2131 rFile.write( " ", 1, nWritten );
2132 rFile.write( ATTRIBUTE_ITEMSTYLE_AUTOSIZE, strlen( ATTRIBUTE_ITEMSTYLE_AUTOSIZE ), nWritten );
2133 bBitSet = sal_True;
2135 if ( nStyle & TIB_DROPDOWN )
2137 if ( bBitSet )
2138 rFile.write( " ", 1, nWritten );
2139 rFile.write( ATTRIBUTE_ITEMSTYLE_DROPDOWN, strlen( ATTRIBUTE_ITEMSTYLE_DROPDOWN ), nWritten );
2140 bBitSet = sal_True;
2142 if ( nStyle & TIB_REPEAT )
2144 if ( bBitSet )
2145 rFile.write( " ", 1, nWritten );
2146 rFile.write( ATTRIBUTE_ITEMSTYLE_REPEAT, strlen( ATTRIBUTE_ITEMSTYLE_REPEAT ), nWritten );
2148 rFile.write( ToolBarItemAttrEnd, strlen( ToolBarItemAttrEnd ), nWritten );
2150 if ( !bVisible )
2152 rFile.write( ToolBarItemVisible, strlen( ToolBarItemVisible ), nWritten );
2153 rFile.write( ToolBarItemAttrEnd, strlen( ToolBarItemAttrEnd ), nWritten );
2156 rFile.write( ToolBarItemEnd, strlen( ToolBarItemEnd ), nWritten );
2158 return true;
2161 bool WriteToolBarXML( osl::File& rFile, ToolBox* pToolBar, MODULES eModule )
2163 OUString aCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
2165 for ( unsigned short n = 0; n < pToolBar->GetItemCount(); n++ )
2167 unsigned short nId = pToolBar->GetItemId( n );
2168 ToolBoxItemType eType = pToolBar->GetItemType( n );
2170 if ( eType == TOOLBOXITEM_BUTTON )
2172 OUString aLabel( pToolBar->GetItemText( nId ));
2173 OUString aCommand( pToolBar->GetItemCommand( nId ));
2174 bool bHasUnoCommand( aCommand.getLength() > 0 && ( aCommand.indexOf( aCmd ) == 0 ));
2175 bool bVisible( pToolBar->IsItemVisible( nId ));
2176 ToolBoxItemBits nItemBits( pToolBar->GetItemBits( nId ));
2178 CommandLabels* pCmdLabels = RetrieveCommandLabelsFromID( nId, eModule );
2179 if ( !pCmdLabels )
2180 pCmdLabels = RetrieveCommandLabelsFromCommand( aCommand, eModule );
2182 if ( pCmdLabels )
2183 aCommand = pCmdLabels->aCommand;
2184 else
2185 aCommand = OUString( RTL_CONSTASCII_USTRINGPARAM( "???" ));
2187 sal_uInt32 nHelpId = pToolBar->GetHelpId( nId );
2188 if ( nHelpId == 0 )
2189 nHelpId = nId;
2191 OUString aHelpId = OUString::valueOf( sal_Int32( nHelpId ));
2192 WriteToolBarItem( rFile, aCommand, aHelpId, nItemBits, bVisible );
2194 else if ( eType == TOOLBOXITEM_SEPARATOR )
2196 WriteToolBarSeparator( rFile );
2198 else if ( eType == TOOLBOXITEM_SPACE )
2200 WriteToolBarSpace( rFile );
2202 else if ( eType == TOOLBOXITEM_BREAK )
2204 WriteToolBarBreak( rFile );
2208 return true;
2211 bool ReadResourceWriteToolBarXML( const OUString& aOutDirURL,
2212 const OUString& aResourceDirURL,
2213 const OUString& aResourceFilePrefix,
2214 MODULES eModule,
2215 const OUString& aProjectName )
2217 static const char ToolBarDocType[] = "<!DOCTYPE toolbar:toolbar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"toolbar.dtd\">\n";
2218 static const char ToolBarStart[] = "<toolbar:toolbar xmlns:toolbar=\"http://openoffice.org/2001/toolbar\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" toolbar:id=\"toolbar\">\n";
2219 static const char ToolBarEnd[] = "</toolbar:toolbar>";
2221 OUString aSysDirPath;
2222 OString aResFilePrefix = OUStringToOString( aResourceFilePrefix, RTL_TEXTENCODING_ASCII_US );
2224 osl::FileBase::getSystemPathFromFileURL( aResourceDirURL, aSysDirPath );
2226 String aSysDirPathStr( aSysDirPath );
2228 ::com::sun::star::lang::Locale aLocale;
2229 aLocale.Language = OUString::createFromAscii( Language_codes[0].pLanguage );
2230 aLocale.Country = OUString::createFromAscii( Language_codes[0].pCountry );
2231 ResMgr* pResMgr = ResMgr::CreateResMgr( aResFilePrefix.getStr(),
2232 aLocale,
2233 NULL,
2234 &aSysDirPathStr );
2236 WorkWindow* pWindow = new WorkWindow( NULL, WB_APP | WB_STDWORK | WB_HIDE );
2237 if ( pResMgr )
2239 int i = 0;
2240 while ( TBResourceModule_Mapping[i].nResId > 0 )
2242 if ( TBResourceModule_Mapping[i].eBelongsTo == eModule )
2244 ResId aResId( TBResourceModule_Mapping[i].nResId, pResMgr );
2245 aResId.SetRT( RSC_TOOLBOX );
2247 if ( pResMgr->IsAvailable( aResId ))
2249 OUString aOutputDirectoryURL( aOutDirURL );
2250 if ( aOutputDirectoryURL.getLength() > 0 && aOutputDirectoryURL[aOutputDirectoryURL.getLength()-1] != '/' )
2251 aOutputDirectoryURL += OUString::createFromAscii( "/" );
2253 OUString aOutputFileURL( aOutputDirectoryURL );
2254 aOutputFileURL += OUString::createFromAscii( TBResourceModule_Mapping[i].pXMLPrefix );
2255 aOutputFileURL += OUString::createFromAscii( ".xml" );
2257 osl::File aXMLFile( aOutputFileURL );
2258 osl::File::RC nRet = aXMLFile.open( OpenFlag_Create|OpenFlag_Write );
2259 if ( nRet == osl::File::E_EXIST )
2261 nRet = aXMLFile.open( OpenFlag_Write );
2262 if ( nRet == osl::File::E_None )
2263 nRet = aXMLFile.setSize( 0 );
2266 if ( nRet == osl::FileBase::E_None )
2268 sal_uInt64 nWritten;
2270 aXMLFile.write( XMLStart, strlen( XMLStart ), nWritten );
2271 aXMLFile.write( ToolBarDocType, strlen( ToolBarDocType ), nWritten );
2272 aXMLFile.write( ToolBarStart, strlen( ToolBarStart ), nWritten );
2274 ToolBox* pToolBox = new ToolBox( pWindow, aResId );
2275 WriteToolBarXML( aXMLFile, (ToolBox *)pToolBox, eModule );
2276 delete pToolBox;
2278 aXMLFile.write( ToolBarEnd, strlen( ToolBarEnd ), nWritten );
2279 aXMLFile.close();
2281 TBResourceModule_Mapping[i].bWritten = true;
2285 ++i;
2288 delete pResMgr;
2291 delete pWindow;
2293 return true;
2296 class MyFloatingWindow : public FloatingWindow
2298 public:
2299 MyFloatingWindow( Window* pParent, const ResId& rResId, const ResId& rSubTbxResId );
2300 ~MyFloatingWindow()
2302 delete pMyToolBox;
2305 ToolBox* GetSubToolBox() { return pMyToolBox; }
2307 private:
2308 ToolBox* pMyToolBox;
2311 MyFloatingWindow::MyFloatingWindow( Window* pParent, const ResId& rResId, const ResId& rSubTbxResId ) :
2312 FloatingWindow( pParent, rResId )
2314 pMyToolBox = new ToolBox( this, rSubTbxResId );
2316 FreeResource();
2320 bool ReadResourceWriteSubToolBarXML( const OUString& aOutDirURL,
2321 const OUString& aResourceDirURL,
2322 const OUString& aResourceFilePrefix,
2323 MODULES eModule,
2324 const OUString& aProjectName )
2326 static const char ToolBarDocType[] = "<!DOCTYPE toolbar:toolbar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"toolbar.dtd\">\n";
2327 static const char ToolBarStart[] = "<toolbar:toolbar xmlns:toolbar=\"http://openoffice.org/2001/toolbar\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" toolbar:id=\"toolbar\">\n";
2328 static const char ToolBarEnd[] = "</toolbar:toolbar>";
2330 OUString aSysDirPath;
2331 OString aResFilePrefix = OUStringToOString( aResourceFilePrefix, RTL_TEXTENCODING_ASCII_US );
2333 osl::FileBase::getSystemPathFromFileURL( aResourceDirURL, aSysDirPath );
2335 String aSysDirPathStr( aSysDirPath );
2337 ::com::sun::star::lang::Locale aLocale;
2338 aLocale.Language = OUString::createFromAscii( Language_codes[0].pLanguage );
2339 aLocale.Country = OUString::createFromAscii( Language_codes[0].pCountry );
2340 ResMgr* pResMgr = ResMgr::CreateResMgr( aResFilePrefix.getStr(),
2341 aLocale,
2342 NULL,
2343 &aSysDirPathStr );
2345 WorkWindow* pWindow = new WorkWindow( NULL, WB_APP | WB_STDWORK | WB_HIDE );
2346 if ( pResMgr )
2348 int i = 0;
2349 while ( TBSubResourceModule_Mapping[i].nParentResId > 0 )
2351 if ( TBSubResourceModule_Mapping[i].eBelongsTo == eModule )
2353 ResId aParentResId( TBSubResourceModule_Mapping[i].nParentResId, pResMgr );
2354 ResId aResId( TBSubResourceModule_Mapping[i].nResId, pResMgr );
2355 MyFloatingWindow* pFloatWin( 0 );
2357 aResId.SetRT( RSC_TOOLBOX );
2358 aParentResId.SetRT( RSC_FLOATINGWINDOW );
2360 if ( pResMgr->IsAvailable( aParentResId ))
2362 pFloatWin = new MyFloatingWindow( pWindow, aParentResId, aResId );
2364 OUString aOutputDirectoryURL( aOutDirURL );
2365 if ( aOutputDirectoryURL.getLength() > 0 && aOutputDirectoryURL[aOutputDirectoryURL.getLength()-1] != '/' )
2366 aOutputDirectoryURL += OUString::createFromAscii( "/" );
2368 OUString aOutputFileURL( aOutputDirectoryURL );
2369 aOutputFileURL += OUString::createFromAscii( TBSubResourceModule_Mapping[i].pXMLPrefix );
2370 aOutputFileURL += OUString::createFromAscii( ".xml" );
2372 osl::File aXMLFile( aOutputFileURL );
2373 osl::File::RC nRet = aXMLFile.open( OpenFlag_Create|OpenFlag_Write );
2374 if ( nRet == osl::File::E_EXIST )
2376 nRet = aXMLFile.open( OpenFlag_Write );
2377 if ( nRet == osl::File::E_None )
2378 nRet = aXMLFile.setSize( 0 );
2381 if ( nRet == osl::FileBase::E_None )
2383 sal_uInt64 nWritten;
2385 aXMLFile.write( XMLStart, strlen( XMLStart ), nWritten );
2386 aXMLFile.write( ToolBarDocType, strlen( ToolBarDocType ), nWritten );
2387 aXMLFile.write( ToolBarStart, strlen( ToolBarStart ), nWritten );
2389 ToolBox* pToolBox = pFloatWin->GetSubToolBox();
2390 if ( pToolBox )
2391 WriteToolBarXML( aXMLFile, (ToolBox *)pToolBox, eModule );
2393 aXMLFile.write( ToolBarEnd, strlen( ToolBarEnd ), nWritten );
2394 aXMLFile.close();
2396 TBSubResourceModule_Mapping[i].bWritten = true;
2399 if ( pFloatWin )
2401 delete pFloatWin;
2402 pFloatWin = 0;
2406 ++i;
2409 delete pResMgr;
2412 delete pWindow;
2414 return true;
2417 bool Convert( sal_Bool bUseProduct,
2418 const OUString& aUseRes,
2419 const OUString& rVersion,
2420 const OUString& rOutputDirName,
2421 const OUString& rPlatformName,
2422 const std::vector< OUString >& rInDirVector,
2423 const OUString& rErrOutputFileName )
2425 OUString aWorkDir;
2427 tools::getProcessWorkingDir( &aWorkDir );
2429 // Try to find xx*.csv file and put all commands into hash table
2430 for ( int i = 0; i < (int)rInDirVector.size(); i++ )
2432 OUString aAbsInDirURL;
2433 OUString aInDirURL;
2434 OUString aInDir( rInDirVector[i] );
2436 osl::FileBase::getFileURLFromSystemPath( aInDir, aInDirURL );
2437 osl::FileBase::getAbsoluteFileURL( aWorkDir, aInDirURL, aAbsInDirURL );
2438 osl::Directory aDir( aAbsInDirURL );
2439 if ( aDir.open() == osl::FileBase::E_None )
2441 osl::DirectoryItem aItem;
2442 while ( aDir.getNextItem( aItem ) == osl::FileBase::E_None )
2444 osl::FileStatus aFileStatus( FileStatusMask_FileName );
2446 aItem.getFileStatus( aFileStatus );
2448 int j=0;
2449 OUString aFileName = aFileStatus.getFileName();
2451 while ( ProjectModule_Mapping[j].pProjectFolder != 0 &&
2452 ProjectModule_Mapping[j].bSlotCommands == true )
2454 if ( aFileName.equalsAscii( ProjectModule_Mapping[j].pProjectFolder ))
2456 OUStringBuffer aBuf( aAbsInDirURL );
2458 aBuf.appendAscii( "/" );
2459 aBuf.append( aFileStatus.getFileName() );
2460 aBuf.appendAscii( "/" );
2461 aBuf.append( rPlatformName );
2462 if ( bUseProduct )
2463 aBuf.appendAscii( ".pro" );
2464 aBuf.appendAscii( "/misc/xx" );
2465 aBuf.appendAscii( ProjectModule_Mapping[j].pCSVPrefix );
2466 aBuf.appendAscii( ".csv" );
2468 OUString aCSVFileURL( aBuf.makeStringAndClear() );
2469 ReadCSVFile( aCSVFileURL, ProjectModule_Mapping[j].eBelongsTo, OUString::createFromAscii( ProjectModule_Mapping[j].pProjectFolder ));
2470 break;
2472 j++;
2476 aDir.close();
2480 OUString aVersionNumber;
2481 bool bOk = ExtractVersionNumber( rVersion, aVersionNumber );
2482 if ( bOk )
2484 // Try to find the resource files and read in menus and slot infos
2485 for ( int i = 0; i < (int)rInDirVector.size(); i++ )
2487 OUString aAbsInDirURL;
2488 OUString aInDirURL;
2489 OUString aInDir( rInDirVector[i] );
2491 osl::FileBase::getFileURLFromSystemPath( aInDir, aInDirURL );
2492 osl::FileBase::getAbsoluteFileURL( aWorkDir, aInDirURL, aAbsInDirURL );
2493 osl::Directory aDir( aAbsInDirURL );
2494 if ( aDir.open() == osl::FileBase::E_None )
2496 osl::DirectoryItem aItem;
2497 while ( aDir.getNextItem( aItem ) == osl::FileBase::E_None )
2499 osl::FileStatus aFileStatus( FileStatusMask_FileName );
2501 aItem.getFileStatus( aFileStatus );
2503 int j=0;
2504 OUString aFileName = aFileStatus.getFileName();
2506 while ( ProjectModule_Mapping[j].pProjectFolder != 0 )
2508 if ( aFileName.equalsAscii( ProjectModule_Mapping[j].pProjectFolder ))
2510 OUStringBuffer aBuf( aAbsInDirURL );
2512 aBuf.appendAscii( "/" );
2513 aBuf.append( aFileStatus.getFileName() );
2514 aBuf.appendAscii( "/common" );
2515 if ( bUseProduct )
2516 aBuf.appendAscii( ".pro" );
2517 aBuf.appendAscii( "/bin/" );
2518 if ( aUseRes.equalsAscii( "so" ))
2519 aBuf.appendAscii( "so/" );
2521 OUString aResDirURL( aBuf.makeStringAndClear() );
2523 OUStringBuffer aLangResBuf;
2524 aLangResBuf.appendAscii( ProjectModule_Mapping[j].pResPrefix );
2525 aLangResBuf.append( aVersionNumber );
2526 OUString aLangResPrefix( aLangResBuf.makeStringAndClear() );
2528 for ( int k = 0; k < NUM_LANGUAGES; k++ )
2530 char aBuf[8] = {0};
2532 ReadResourceFile( k,
2533 aResDirURL,
2534 aLangResPrefix,
2535 ProjectModule_Mapping[j].eBelongsTo,
2536 OUString::createFromAscii( ProjectModule_Mapping[j].pProjectFolder ),
2537 ProjectModule_Mapping[j].bSlotCommands );
2540 OUString aOutDirURL;
2541 osl::FileBase::getFileURLFromSystemPath( rOutputDirName, aOutDirURL );
2542 osl::FileBase::getAbsoluteFileURL( aWorkDir, aOutDirURL, aOutDirURL );
2544 ReadResourceWriteMenuBarXML( aOutDirURL, aResDirURL, aLangResPrefix, ProjectModule_Mapping[j].eBelongsTo, OUString::createFromAscii( ProjectModule_Mapping[j].pProjectFolder ));
2545 ReadResourceWriteToolBarXML( aOutDirURL, aResDirURL, aLangResPrefix, ProjectModule_Mapping[j].eBelongsTo, OUString::createFromAscii( ProjectModule_Mapping[j].pProjectFolder ));
2546 ReadResourceWriteSubToolBarXML( aOutDirURL, aResDirURL, aLangResPrefix, ProjectModule_Mapping[j].eBelongsTo, OUString::createFromAscii( ProjectModule_Mapping[j].pProjectFolder ));
2547 ReadResourceWriteAcceleratorXML( aOutDirURL, aResDirURL, aLangResPrefix, ProjectModule_Mapping[j].eBelongsTo, ::rtl::OUString::createFromAscii( ProjectModule_Mapping[j].pProjectFolder ));
2549 j++;
2553 aDir.close();
2558 OUString aOutDirURL;
2559 osl::FileBase::getFileURLFromSystemPath( rOutputDirName, aOutDirURL );
2560 osl::FileBase::getAbsoluteFileURL( aWorkDir, aOutDirURL, aOutDirURL );
2562 WriteXMLFiles( aOutDirURL );
2564 sal_Int32 n = 0;
2565 while ( TBResourceModule_Mapping[n].nResId > 0 )
2567 if ( !TBResourceModule_Mapping[n].bWritten )
2568 fprintf( stderr, "Warning: Couldn't convert toolbar %s\n", TBResourceModule_Mapping[n].pXMLPrefix );
2569 n++;
2572 n = 0;
2573 while ( TBSubResourceModule_Mapping[n].nResId > 0 )
2575 if ( !TBSubResourceModule_Mapping[n].bWritten )
2576 fprintf( stderr, "Warning: Couldn't convert sub toolbar %s\n", TBSubResourceModule_Mapping[n].pXMLPrefix );
2577 n++;
2580 return true;
2583 bool GetCommandOption( const ::std::vector< OUString >& rArgs, const OUString& rSwitch, OUString& rParam )
2585 bool bRet = false;
2586 OUString aSwitch( OUString::createFromAscii( "-" ));
2588 aSwitch += rSwitch;
2589 for( int i = 0, nCount = rArgs.size(); ( i < nCount ) && !bRet; i++ )
2591 for( int n = 0; ( n < 2 ) && !bRet; n++ )
2593 if ( aSwitch.equalsIgnoreAsciiCase( rArgs[ i ] ))
2595 bRet = true;
2597 if( i < ( nCount - 1 ) )
2598 rParam = rArgs[ i + 1 ];
2599 else
2600 rParam = OUString();
2605 return bRet;
2608 // -----------------------------------------------------------------------
2610 bool GetCommandOptions( const ::std::vector< OUString >& rArgs, const OUString& rSwitch, ::std::vector< OUString >& rParams )
2612 bool bRet = false;
2614 OUString aSwitch( OUString::createFromAscii( "-" ));
2616 aSwitch += rSwitch;
2617 for( int i = 0, nCount = rArgs.size(); ( i < nCount ); i++ )
2619 for( int n = 0; ( n < 2 ) && !bRet; n++ )
2621 if ( aSwitch.equalsIgnoreAsciiCase( rArgs[ i ] ))
2623 if( i < ( nCount - 1 ) )
2624 rParams.push_back( rArgs[ i + 1 ] );
2625 else
2626 rParams.push_back( OUString() );
2628 break;
2633 return( !rParams.empty() );
2636 void ShowUsage()
2638 fprintf( stderr, "Usage: uicmdxml output_dir -r res -v version [-p] -s platform -i input_dir [-i input_dir] [-f errfile]\n" );
2639 fprintf( stderr, "Options:" );
2640 fprintf( stderr, " -r [oo|so] use resources from ooo, so\n" );
2641 fprintf( stderr, " -v name of the version used, f.e. SRX645, SRC680\n" );
2642 fprintf( stderr, " -p use product version\n" );
2643 fprintf( stderr, " -s name of the system to use, f.e. wntmsci8, unxsols4, unxlngi5\n" );
2644 fprintf( stderr, " -i ... name of directory to be searched for input files [multiple occurence is possible]\n" );
2645 fprintf( stderr, " -f name of file, error output should be written to\n" );
2646 fprintf( stderr, "Examples:\n" );
2647 fprintf( stderr, " uicmdxml /home/out -r so -v SRC680 -p unxlngi5 -i /home/res -f /home/out/log.err\n" );
2650 using namespace ::com::sun::star::uno;
2651 using namespace ::com::sun::star::lang;
2652 // -----------------------------------------------------------------------
2654 // Forward declaration
2655 void Main();
2657 // -----------------------------------------------------------------------
2659 SAL_IMPLEMENT_MAIN()
2661 Reference< XMultiServiceFactory > xMS;
2663 // for this to work make sure an <appname>.ini file is available, you can just copy soffice.ini
2664 Reference< XComponentContext > xComponentContext = ::cppu::defaultBootstrap_InitialComponentContext();
2665 xMS = Reference< XMultiServiceFactory >( xComponentContext->getServiceManager() , UNO_QUERY );
2667 InitVCL( xMS );
2668 ::Main();
2669 DeInitVCL();
2671 return 0;
2674 void Main()
2676 ::std::vector< OUString > aArgs;
2678 sal_uInt32 nCmds = osl_getCommandArgCount();
2679 if ( nCmds >= 8 )
2681 for ( sal_uInt32 i=0; i < nCmds; i++ )
2683 OUString aArg;
2684 osl_getCommandArg( i, &aArg.pData );
2685 aArgs.push_back( aArg );
2688 ::std::vector< OUString > aInDirVector;
2689 OUString aErrOutputFileName;
2690 OUString aOutputDirName( aArgs[0] );
2691 OUString aPlatformName;
2692 OUString aVersion;
2693 OUString aUseRes;
2694 bool bUseProduct;
2695 OUString aDummy;
2697 GetCommandOption( aArgs, OUString::createFromAscii( "v" ), aVersion );
2698 bUseProduct = GetCommandOption( aArgs, OUString::createFromAscii( "p" ), aDummy );
2699 GetCommandOption( aArgs, OUString::createFromAscii( "s" ), aPlatformName );
2700 GetCommandOptions( aArgs, OUString::createFromAscii( "i" ), aInDirVector );
2701 GetCommandOption( aArgs, OUString::createFromAscii( "f" ), aErrOutputFileName );
2702 GetCommandOption( aArgs, OUString::createFromAscii( "r" ), aUseRes );
2704 if ( aVersion.getLength() > 0 &&
2705 aPlatformName.getLength() > 0 &&
2706 aUseRes.getLength() > 0 &&
2707 !aInDirVector.empty() )
2709 Convert( bUseProduct, aUseRes, aVersion, aOutputDirName, aPlatformName, aInDirVector, aErrOutputFileName );
2711 else
2713 ShowUsage();
2714 exit( -1 );
2717 else
2719 ShowUsage();
2720 exit( -1 );