Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include <cassert>
23 : #include <stdlib.h>
24 : #include <time.h>
25 :
26 : #include <vcl/help.hxx>
27 : #include <vcl/msgbox.hxx>
28 : #include <vcl/decoview.hxx>
29 : #include <vcl/toolbox.hxx>
30 : #include <vcl/scrbar.hxx>
31 : #include <vcl/virdev.hxx>
32 :
33 : #include <sfx2/app.hxx>
34 : #include <sfx2/sfxdlg.hxx>
35 : #include <sfx2/viewfrm.hxx>
36 : #include <sfx2/viewsh.hxx>
37 : #include <sfx2/msg.hxx>
38 : #include <sfx2/msgpool.hxx>
39 : #include <sfx2/mnumgr.hxx>
40 : #include <sfx2/minfitem.hxx>
41 : #include <sfx2/objsh.hxx>
42 : #include <sfx2/request.hxx>
43 : #include <sfx2/filedlghelper.hxx>
44 : #include <svl/stritem.hxx>
45 : #include <svtools/miscopt.hxx>
46 : #include <svtools/svlbitm.hxx>
47 : #include "svtools/treelistentry.hxx"
48 : #include "svtools/viewdataentry.hxx"
49 : #include <tools/diagnose_ex.h>
50 : #include <toolkit/unohlp.hxx>
51 :
52 : #include <algorithm>
53 : #include <cuires.hrc>
54 : #include "cfg.hrc"
55 : #include "helpid.hrc"
56 :
57 : #include "acccfg.hxx"
58 : #include "cfg.hxx"
59 : #include "eventdlg.hxx"
60 : #include <dialmgr.hxx>
61 :
62 : #include <comphelper/documentinfo.hxx>
63 : #include <comphelper/processfactory.hxx>
64 : #include <unotools/configmgr.hxx>
65 : #include <com/sun/star/ui/ItemType.hpp>
66 : #include <com/sun/star/ui/ItemStyle.hpp>
67 : #include <com/sun/star/ui/ModuleUIConfigurationManagerSupplier.hpp>
68 : #include <com/sun/star/frame/ModuleManager.hpp>
69 : #include <com/sun/star/frame/XController.hpp>
70 : #include <com/sun/star/frame/XDesktop.hpp>
71 : #include <com/sun/star/frame/UICommandDescription.hpp>
72 : #include <com/sun/star/ui/XUIConfiguration.hpp>
73 : #include <com/sun/star/ui/XUIConfigurationListener.hpp>
74 : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
75 : #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
76 : #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
77 : #include <com/sun/star/ui/XModuleUIConfigurationManager.hpp>
78 : #include <com/sun/star/ui/XUIElement.hpp>
79 : #include <com/sun/star/ui/UIElementType.hpp>
80 : #include <com/sun/star/ui/ImageType.hpp>
81 : #include <com/sun/star/ui/WindowStateConfiguration.hpp>
82 : #include <com/sun/star/frame/XLayoutManager.hpp>
83 : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
84 : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
85 : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
86 : #include <com/sun/star/frame/XFramesSupplier.hpp>
87 : #include <com/sun/star/frame/XFrames.hpp>
88 : #include <com/sun/star/frame/FrameSearchFlag.hpp>
89 : #include <com/sun/star/graphic/GraphicProvider.hpp>
90 : #include <com/sun/star/embed/ElementModes.hpp>
91 : #include <com/sun/star/embed/FileSystemStorageFactory.hpp>
92 :
93 : #include "dlgname.hxx"
94 :
95 : #define PRTSTR(x) rtl::OUStringToOString(x, RTL_TEXTENCODING_ASCII_US).pData->buffer
96 :
97 : #define ENTRY_HEIGHT 16
98 :
99 : static const char ITEM_DESCRIPTOR_COMMANDURL[] = "CommandURL";
100 : static const char ITEM_DESCRIPTOR_CONTAINER[] = "ItemDescriptorContainer";
101 : static const char ITEM_DESCRIPTOR_LABEL[] = "Label";
102 : static const char ITEM_DESCRIPTOR_TYPE[] = "Type";
103 : static const char ITEM_DESCRIPTOR_STYLE[] = "Style";
104 : static const char ITEM_DESCRIPTOR_ISVISIBLE[] = "IsVisible";
105 : static const char ITEM_DESCRIPTOR_RESOURCEURL[] = "ResourceURL";
106 : static const char ITEM_DESCRIPTOR_UINAME[] = "UIName";
107 :
108 : static const char ITEM_MENUBAR_URL[] = "private:resource/menubar/menubar";
109 : static const char ITEM_TOOLBAR_URL[] = "private:resource/toolbar/";
110 :
111 : static const char CUSTOM_TOOLBAR_STR[] = "custom_toolbar_";
112 : static const char CUSTOM_MENU_STR[] = "vnd.openoffice.org:CustomMenu";
113 :
114 : static const char aSeparatorStr[] = "----------------------------------";
115 : static const char aMenuSeparatorStr[] = " | ";
116 :
117 : #ifdef _MSC_VER
118 : #pragma warning (disable:4355)
119 : #endif
120 :
121 : using rtl::OUString;
122 : namespace uno = com::sun::star::uno;
123 : namespace frame = com::sun::star::frame;
124 : namespace lang = com::sun::star::lang;
125 : namespace container = com::sun::star::container;
126 : namespace beans = com::sun::star::beans;
127 : namespace graphic = com::sun::star::graphic;
128 :
129 : #if OSL_DEBUG_LEVEL > 1
130 :
131 : void printPropertySet(
132 : const OUString& prefix,
133 : const uno::Reference< beans::XPropertySet >& xPropSet )
134 : {
135 : uno::Reference< beans::XPropertySetInfo > xPropSetInfo =
136 : xPropSet->getPropertySetInfo();
137 :
138 : uno::Sequence< beans::Property > aPropDetails =
139 : xPropSetInfo->getProperties();
140 :
141 : OSL_TRACE("printPropertySet: %d properties", aPropDetails.getLength());
142 :
143 : for ( sal_Int32 i = 0; i < aPropDetails.getLength(); ++i )
144 : {
145 : OUString tmp;
146 : sal_Int32 ival;
147 :
148 : uno::Any a = xPropSet->getPropertyValue( aPropDetails[i].Name );
149 :
150 : if ( a >>= tmp )
151 : {
152 : OSL_TRACE("%s: Got property: %s = %s",
153 : PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(tmp));
154 : }
155 : else if ( ( a >>= ival ) )
156 : {
157 : OSL_TRACE("%s: Got property: %s = %d",
158 : PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(tmp));
159 : }
160 : else
161 : {
162 : OSL_TRACE("%s: Got property: %s of type %s",
163 : PRTSTR(prefix), PRTSTR(aPropDetails[i].Name), PRTSTR(a.getValueTypeName()));
164 : }
165 : }
166 : }
167 :
168 : void printProperties(
169 : const OUString& prefix,
170 : const uno::Sequence< beans::PropertyValue >& aProp )
171 : {
172 : for ( sal_Int32 i = 0; i < aProp.getLength(); ++i )
173 : {
174 : OUString tmp;
175 :
176 : aProp[i].Value >>= tmp;
177 :
178 : OSL_TRACE("%s: Got property: %s = %s",
179 : PRTSTR(prefix), PRTSTR(aProp[i].Name), PRTSTR(tmp));
180 : }
181 : }
182 :
183 : void printEntries(SvxEntries* entries)
184 : {
185 : SvxEntries::const_iterator iter = entries->begin();
186 :
187 : for ( ; iter != entries->end(); ++iter )
188 : {
189 : SvxConfigEntry* entry = *iter;
190 :
191 : OSL_TRACE("printEntries: %s", PRTSTR(entry->GetName()));
192 : }
193 : }
194 :
195 : #endif
196 :
197 : OUString
198 0 : stripHotKey( const OUString& str )
199 : {
200 0 : sal_Int32 index = str.indexOf( '~' );
201 0 : if ( index == -1 )
202 : {
203 0 : return str;
204 : }
205 : else
206 : {
207 0 : return str.replaceAt( index, 1, OUString() );
208 : }
209 : }
210 :
211 0 : OUString replaceSaveInName(
212 : const OUString& rMessage,
213 : const OUString& rSaveInName )
214 : {
215 0 : OUString name;
216 0 : OUString placeholder("%SAVE IN SELECTION%" );
217 :
218 0 : sal_Int32 pos = rMessage.indexOf( placeholder );
219 :
220 0 : if ( pos != -1 )
221 : {
222 : name = rMessage.replaceAt(
223 0 : pos, placeholder.getLength(), rSaveInName );
224 : }
225 :
226 0 : return name;
227 : }
228 :
229 : OUString
230 0 : replaceSixteen( const OUString& str, sal_Int32 nReplacement )
231 : {
232 0 : OUString result( str );
233 0 : OUString sixteen = OUString::valueOf( (sal_Int32)16 );
234 0 : OUString expected = OUString::valueOf( nReplacement );
235 :
236 0 : sal_Int32 len = sixteen.getLength();
237 0 : sal_Int32 index = result.indexOf( sixteen );
238 :
239 0 : while ( index != -1 )
240 : {
241 0 : result = result.replaceAt( index, len, expected );
242 0 : index = result.indexOf( sixteen, index );
243 : }
244 :
245 0 : return result;
246 : }
247 :
248 : OUString
249 0 : generateCustomName(
250 : const OUString& prefix,
251 : SvxEntries* entries,
252 : sal_Int32 suffix = 1 )
253 : {
254 : // find and replace the %n placeholder in the prefix string
255 0 : OUString name;
256 0 : OUString placeholder("%n" );
257 :
258 0 : sal_Int32 pos = prefix.indexOf( placeholder );
259 :
260 0 : if ( pos != -1 )
261 : {
262 : name = prefix.replaceAt(
263 0 : pos, placeholder.getLength(), OUString::valueOf( suffix ) );
264 : }
265 : else
266 : {
267 : // no placeholder found so just append the suffix
268 0 : name = prefix + OUString::valueOf( suffix );
269 : }
270 :
271 : // now check is there is an already existing entry with this name
272 0 : SvxEntries::const_iterator iter = entries->begin();
273 :
274 : SvxConfigEntry* pEntry;
275 0 : while ( iter != entries->end() )
276 : {
277 0 : pEntry = *iter;
278 :
279 0 : if ( name.equals( pEntry->GetName() ) )
280 : {
281 0 : break;
282 : }
283 0 : ++iter;
284 : }
285 :
286 0 : if ( iter != entries->end() )
287 : {
288 : // name already exists so try the next number up
289 0 : return generateCustomName( prefix, entries, ++suffix );
290 : }
291 :
292 0 : return name;
293 : }
294 :
295 0 : sal_uInt32 generateRandomValue()
296 : {
297 0 : srand( unsigned( time( NULL ) ));
298 0 : return sal_uInt32( rand() );
299 : }
300 :
301 : OUString
302 0 : generateCustomURL(
303 : SvxEntries* entries )
304 : {
305 0 : OUString url = OUString(ITEM_TOOLBAR_URL );
306 0 : url += OUString(CUSTOM_TOOLBAR_STR );
307 :
308 : // use a random number to minimize possible clash with existing custom toolbars
309 0 : url += OUString::valueOf( sal_Int64( generateRandomValue() ), 16 );
310 :
311 : // now check is there is an already existing entry with this url
312 0 : SvxEntries::const_iterator iter = entries->begin();
313 :
314 : SvxConfigEntry* pEntry;
315 0 : while ( iter != entries->end() )
316 : {
317 0 : pEntry = *iter;
318 :
319 0 : if ( url.equals( pEntry->GetCommand() ) )
320 : {
321 0 : break;
322 : }
323 0 : ++iter;
324 : }
325 :
326 0 : if ( iter != entries->end() )
327 : {
328 : // url already exists so try the next number up
329 0 : return generateCustomURL( entries );
330 : }
331 :
332 0 : return url;
333 : }
334 :
335 : OUString
336 0 : generateCustomMenuURL(
337 : SvxEntries* entries,
338 : sal_Int32 suffix = 1 )
339 : {
340 0 : OUString url(CUSTOM_MENU_STR );
341 0 : url += OUString::valueOf( suffix );
342 :
343 : // now check is there is an already existing entry with this url
344 0 : SvxEntries::const_iterator iter = entries->begin();
345 :
346 : SvxConfigEntry* pEntry;
347 0 : while ( iter != entries->end() )
348 : {
349 0 : pEntry = *iter;
350 :
351 0 : if ( url.equals( pEntry->GetCommand() ) )
352 : {
353 0 : break;
354 : }
355 0 : ++iter;
356 : }
357 :
358 0 : if ( iter != entries->end() )
359 : {
360 : // url already exists so try the next number up
361 0 : return generateCustomMenuURL( entries, ++suffix );
362 : }
363 :
364 0 : return url;
365 : }
366 :
367 : static sal_Int16 theImageType =
368 : css::ui::ImageType::COLOR_NORMAL |
369 : css::ui::ImageType::SIZE_DEFAULT;
370 :
371 0 : void InitImageType()
372 : {
373 : theImageType =
374 : css::ui::ImageType::COLOR_NORMAL |
375 0 : css::ui::ImageType::SIZE_DEFAULT;
376 :
377 0 : if ( SvtMiscOptions().AreCurrentSymbolsLarge() )
378 : {
379 0 : theImageType |= css::ui::ImageType::SIZE_LARGE;
380 : }
381 0 : }
382 :
383 0 : sal_Int16 GetImageType()
384 : {
385 0 : return theImageType;
386 : }
387 :
388 0 : void RemoveEntry( SvxEntries* pEntries, SvxConfigEntry* pChildEntry )
389 : {
390 0 : SvxEntries::iterator iter = pEntries->begin();
391 :
392 0 : while ( iter != pEntries->end() )
393 : {
394 0 : if ( pChildEntry == *iter )
395 : {
396 0 : pEntries->erase( iter );
397 0 : break;
398 : }
399 0 : ++iter;
400 : }
401 0 : }
402 :
403 : bool
404 0 : SvxConfigPage::CanConfig( const OUString& aModuleId )
405 : {
406 : OSL_TRACE("SupportsDocumentConfig: %s", PRTSTR(aModuleId));
407 :
408 0 : if ( aModuleId == "com.sun.star.script.BasicIDE" || aModuleId == "com.sun.star.frame.Bibliography" )
409 : {
410 0 : return sal_False;
411 : }
412 0 : return sal_True;
413 : }
414 :
415 0 : OUString GetModuleName( const OUString& aModuleId )
416 : {
417 0 : if ( aModuleId.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.text.TextDocument" ) ) ||
418 0 : aModuleId.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.text.GlobalDocument" ) ) )
419 0 : return OUString("Writer");
420 0 : else if ( aModuleId == "com.sun.star.text.WebDocument" )
421 0 : return OUString("Writer/Web");
422 0 : else if ( aModuleId == "com.sun.star.drawing.DrawingDocument" )
423 0 : return OUString("Draw");
424 0 : else if ( aModuleId == "com.sun.star.presentation.PresentationDocument" )
425 0 : return OUString("Impress");
426 0 : else if ( aModuleId == "com.sun.star.sheet.SpreadsheetDocument" )
427 0 : return OUString("Calc");
428 0 : else if ( aModuleId == "com.sun.star.script.BasicIDE" )
429 0 : return OUString("Basic");
430 0 : else if ( aModuleId == "com.sun.star.formula.FormulaProperties" )
431 0 : return OUString("Math");
432 0 : else if ( aModuleId == "com.sun.star.sdb.RelationDesign" )
433 0 : return OUString("Relation Design");
434 0 : else if ( aModuleId == "com.sun.star.sdb.QueryDesign" )
435 0 : return OUString("Query Design");
436 0 : else if ( aModuleId == "com.sun.star.sdb.TableDesign" )
437 0 : return OUString("Table Design");
438 0 : else if ( aModuleId == "com.sun.star.sdb.DataSourceBrowser" )
439 0 : return OUString("Data Source Browser" );
440 0 : else if ( aModuleId == "com.sun.star.sdb.DatabaseDocument" )
441 0 : return OUString("Database" );
442 :
443 0 : return ::rtl::OUString();
444 : }
445 :
446 0 : OUString GetUIModuleName( const OUString& aModuleId, const uno::Reference< css::frame::XModuleManager2 >& rModuleManager )
447 : {
448 : assert(rModuleManager.is());
449 :
450 0 : OUString aModuleUIName;
451 :
452 : try
453 : {
454 0 : uno::Any a = rModuleManager->getByName( aModuleId );
455 0 : uno::Sequence< beans::PropertyValue > aSeq;
456 :
457 0 : if ( a >>= aSeq )
458 : {
459 0 : for ( sal_Int32 i = 0; i < aSeq.getLength(); ++i )
460 : {
461 0 : if ( aSeq[i].Name == "ooSetupFactoryUIName" )
462 : {
463 0 : aSeq[i].Value >>= aModuleUIName;
464 0 : break;
465 : }
466 : }
467 0 : }
468 : }
469 0 : catch ( uno::RuntimeException& )
470 : {
471 0 : throw;
472 : }
473 0 : catch ( uno::Exception& )
474 : {
475 : }
476 :
477 0 : if ( aModuleUIName.isEmpty() )
478 0 : aModuleUIName = GetModuleName( aModuleId );
479 :
480 0 : return aModuleUIName;
481 : }
482 :
483 0 : bool GetMenuItemData(
484 : const uno::Reference< container::XIndexAccess >& rItemContainer,
485 : sal_Int32 nIndex,
486 : OUString& rCommandURL,
487 : OUString& rLabel,
488 : sal_uInt16& rType,
489 : uno::Reference< container::XIndexAccess >& rSubMenu )
490 : {
491 : try
492 : {
493 0 : uno::Sequence< beans::PropertyValue > aProp;
494 0 : if ( rItemContainer->getByIndex( nIndex ) >>= aProp )
495 : {
496 0 : for ( sal_Int32 i = 0; i < aProp.getLength(); ++i )
497 : {
498 0 : if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
499 : {
500 0 : aProp[i].Value >>= rCommandURL;
501 : }
502 0 : else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_CONTAINER ))
503 : {
504 0 : aProp[i].Value >>= rSubMenu;
505 : }
506 0 : else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ))
507 : {
508 0 : aProp[i].Value >>= rLabel;
509 : }
510 0 : else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE ))
511 : {
512 0 : aProp[i].Value >>= rType;
513 : }
514 : }
515 :
516 0 : return sal_True;
517 0 : }
518 : }
519 0 : catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
520 : {
521 : }
522 :
523 0 : return sal_False;
524 : }
525 :
526 0 : bool GetToolbarItemData(
527 : const uno::Reference< container::XIndexAccess >& rItemContainer,
528 : sal_Int32 nIndex,
529 : OUString& rCommandURL,
530 : OUString& rLabel,
531 : sal_uInt16& rType,
532 : sal_Bool& rIsVisible,
533 : sal_Int32& rStyle,
534 : uno::Reference< container::XIndexAccess >& rSubMenu )
535 : {
536 : try
537 : {
538 0 : uno::Sequence< beans::PropertyValue > aProp;
539 0 : if ( rItemContainer->getByIndex( nIndex ) >>= aProp )
540 : {
541 0 : for ( sal_Int32 i = 0; i < aProp.getLength(); ++i )
542 : {
543 0 : if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
544 : {
545 0 : aProp[i].Value >>= rCommandURL;
546 : }
547 0 : if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE ))
548 : {
549 0 : aProp[i].Value >>= rStyle;
550 : }
551 0 : else if (aProp[i].Name.equalsAscii(ITEM_DESCRIPTOR_CONTAINER))
552 : {
553 0 : aProp[i].Value >>= rSubMenu;
554 : }
555 0 : else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ))
556 : {
557 0 : aProp[i].Value >>= rLabel;
558 : }
559 0 : else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE ))
560 : {
561 0 : aProp[i].Value >>= rType;
562 : }
563 0 : else if (aProp[i].Name.equalsAscii(ITEM_DESCRIPTOR_ISVISIBLE))
564 : {
565 0 : aProp[i].Value >>= rIsVisible;
566 : }
567 : }
568 :
569 0 : return sal_True;
570 0 : }
571 : }
572 0 : catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
573 : {
574 : }
575 :
576 0 : return sal_False;
577 : }
578 :
579 : uno::Sequence< beans::PropertyValue >
580 0 : ConvertSvxConfigEntry(
581 : const uno::Reference< container::XNameAccess >& xCommandToLabelMap,
582 : const SvxConfigEntry* pEntry )
583 : {
584 : static const OUString aDescriptorCommandURL (
585 0 : ITEM_DESCRIPTOR_COMMANDURL );
586 :
587 : static const OUString aDescriptorType(
588 0 : ITEM_DESCRIPTOR_TYPE );
589 :
590 : static const OUString aDescriptorLabel(
591 0 : ITEM_DESCRIPTOR_LABEL );
592 :
593 : static const OUString aDescriptorContainer(
594 0 : ITEM_DESCRIPTOR_CONTAINER );
595 :
596 0 : uno::Sequence< beans::PropertyValue > aPropSeq( 3 );
597 :
598 0 : aPropSeq[0].Name = aDescriptorCommandURL;
599 0 : aPropSeq[0].Value <<= rtl::OUString( pEntry->GetCommand() );
600 :
601 0 : aPropSeq[1].Name = aDescriptorType;
602 0 : aPropSeq[1].Value <<= css::ui::ItemType::DEFAULT;
603 :
604 : // If the name has not been changed and the name is the same as
605 : // in the default command to label map then the label can be stored
606 : // as an empty string.
607 : // It will be initialised again later using the command to label map.
608 0 : aPropSeq[2].Name = aDescriptorLabel;
609 0 : if ( pEntry->HasChangedName() == sal_False && !pEntry->GetCommand().isEmpty() )
610 : {
611 0 : sal_Bool isDefaultName = sal_False;
612 : try
613 : {
614 0 : uno::Any a( xCommandToLabelMap->getByName( pEntry->GetCommand() ) );
615 0 : uno::Sequence< beans::PropertyValue > tmpPropSeq;
616 0 : if ( a >>= tmpPropSeq )
617 : {
618 0 : for ( sal_Int32 i = 0; i < tmpPropSeq.getLength(); ++i )
619 : {
620 0 : if ( tmpPropSeq[i].Name.equals( aDescriptorLabel ) )
621 : {
622 0 : OUString tmpLabel;
623 0 : tmpPropSeq[i].Value >>= tmpLabel;
624 :
625 0 : if ( tmpLabel.equals( pEntry->GetName() ) )
626 : {
627 0 : isDefaultName = sal_True;
628 : }
629 :
630 0 : break;
631 : }
632 : }
633 0 : }
634 : }
635 0 : catch ( container::NoSuchElementException& )
636 : {
637 : // isDefaultName is left as FALSE
638 : }
639 :
640 0 : if ( isDefaultName )
641 : {
642 0 : aPropSeq[2].Value <<= rtl::OUString();
643 : }
644 : else
645 : {
646 0 : aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
647 : }
648 : }
649 : else
650 : {
651 0 : aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
652 : }
653 :
654 0 : return aPropSeq;
655 : }
656 :
657 : uno::Sequence< beans::PropertyValue >
658 0 : ConvertToolbarEntry(
659 : const uno::Reference< container::XNameAccess >& xCommandToLabelMap,
660 : const SvxConfigEntry* pEntry )
661 : {
662 : static const OUString aDescriptorCommandURL (
663 0 : ITEM_DESCRIPTOR_COMMANDURL );
664 :
665 : static const OUString aDescriptorType(
666 0 : ITEM_DESCRIPTOR_TYPE );
667 :
668 : static const OUString aDescriptorLabel(
669 0 : ITEM_DESCRIPTOR_LABEL );
670 :
671 : static const OUString aDescriptorContainer(
672 0 : ITEM_DESCRIPTOR_CONTAINER );
673 :
674 : static const OUString aIsVisible(
675 0 : ITEM_DESCRIPTOR_ISVISIBLE );
676 :
677 0 : uno::Sequence< beans::PropertyValue > aPropSeq( 4 );
678 :
679 0 : aPropSeq[0].Name = aDescriptorCommandURL;
680 0 : aPropSeq[0].Value <<= rtl::OUString( pEntry->GetCommand() );
681 :
682 0 : aPropSeq[1].Name = aDescriptorType;
683 0 : aPropSeq[1].Value <<= css::ui::ItemType::DEFAULT;
684 :
685 : // If the name has not been changed and the name is the same as
686 : // in the default command to label map then the label can be stored
687 : // as an empty string.
688 : // It will be initialised again later using the command to label map.
689 0 : aPropSeq[2].Name = aDescriptorLabel;
690 0 : if ( pEntry->HasChangedName() == sal_False && !pEntry->GetCommand().isEmpty() )
691 : {
692 0 : sal_Bool isDefaultName = sal_False;
693 : try
694 : {
695 0 : uno::Any a( xCommandToLabelMap->getByName( pEntry->GetCommand() ) );
696 0 : uno::Sequence< beans::PropertyValue > tmpPropSeq;
697 0 : if ( a >>= tmpPropSeq )
698 : {
699 0 : for ( sal_Int32 i = 0; i < tmpPropSeq.getLength(); ++i )
700 : {
701 0 : if ( tmpPropSeq[i].Name.equals( aDescriptorLabel ) )
702 : {
703 0 : OUString tmpLabel;
704 0 : tmpPropSeq[i].Value >>= tmpLabel;
705 :
706 0 : if ( tmpLabel.equals( pEntry->GetName() ) )
707 : {
708 0 : isDefaultName = sal_True;
709 : }
710 :
711 0 : break;
712 : }
713 : }
714 0 : }
715 : }
716 0 : catch ( container::NoSuchElementException& )
717 : {
718 : // isDefaultName is left as FALSE
719 : }
720 :
721 0 : if ( isDefaultName )
722 : {
723 0 : aPropSeq[2].Value <<= rtl::OUString();
724 : }
725 : else
726 : {
727 0 : aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
728 : }
729 : }
730 : else
731 : {
732 0 : aPropSeq[2].Value <<= rtl::OUString( pEntry->GetName() );
733 : }
734 :
735 0 : aPropSeq[3].Name = aIsVisible;
736 0 : aPropSeq[3].Value <<= pEntry->IsVisible();
737 :
738 0 : return aPropSeq;
739 : }
740 :
741 0 : SfxTabPage *CreateSvxMenuConfigPage( Window *pParent, const SfxItemSet& rSet )
742 : {
743 0 : return new SvxMenuConfigPage( pParent, rSet );
744 : }
745 :
746 0 : SfxTabPage *CreateKeyboardConfigPage( Window *pParent, const SfxItemSet& rSet )
747 : {
748 0 : return new SfxAcceleratorConfigPage( pParent, rSet );
749 : }
750 :
751 0 : SfxTabPage *CreateSvxToolbarConfigPage( Window *pParent, const SfxItemSet& rSet )
752 : {
753 0 : return new SvxToolbarConfigPage( pParent, rSet );
754 : }
755 :
756 0 : SfxTabPage *CreateSvxEventConfigPage( Window *pParent, const SfxItemSet& rSet )
757 : {
758 0 : return new SvxEventConfigPage( pParent, rSet, SvxEventConfigPage::EarlyInit() );
759 : }
760 :
761 0 : sal_Bool impl_showKeyConfigTabPage( const css::uno::Reference< css::frame::XFrame >& xFrame )
762 : {
763 0 : static ::rtl::OUString SERVICENAME_DESKTOP ("com.sun.star.frame.Desktop" );
764 0 : static ::rtl::OUString MODULEID_STARTMODULE ("com.sun.star.frame.StartModule" );
765 :
766 : try
767 : {
768 0 : css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
769 0 : css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
770 0 : css::uno::Reference< css::frame::XFramesSupplier > xDesktop(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
771 0 : css::uno::Reference< css::frame::XModuleManager2 > xMM (css::frame::ModuleManager::create(xContext));
772 :
773 0 : if (xFrame.is())
774 : {
775 0 : ::rtl::OUString sModuleId = xMM->identify(xFrame);
776 0 : if (
777 0 : ( !sModuleId.isEmpty() ) &&
778 0 : (!sModuleId.equals(MODULEID_STARTMODULE))
779 : )
780 0 : return sal_True;
781 0 : }
782 : }
783 0 : catch(const css::uno::Exception&)
784 : {}
785 :
786 0 : return sal_False;
787 : }
788 :
789 : /******************************************************************************
790 : *
791 : * SvxConfigDialog is the configuration dialog which is brought up from the
792 : * Tools menu. It includes tabs for customizing menus, toolbars, events and
793 : * key bindings.
794 : *
795 : *****************************************************************************/
796 0 : SvxConfigDialog::SvxConfigDialog(
797 : Window * pParent, const SfxItemSet* pSet_ )
798 : :
799 : SfxTabDialog( pParent,
800 0 : CUI_RES( RID_SVXDLG_CUSTOMIZE ), pSet_ )
801 : {
802 0 : FreeResource();
803 :
804 0 : InitImageType();
805 :
806 0 : AddTabPage( RID_SVXPAGE_MENUS, CreateSvxMenuConfigPage, NULL );
807 0 : AddTabPage( RID_SVXPAGE_KEYBOARD, CreateKeyboardConfigPage, NULL );
808 0 : AddTabPage( RID_SVXPAGE_TOOLBARS, CreateSvxToolbarConfigPage, NULL );
809 0 : AddTabPage( RID_SVXPAGE_EVENTS, CreateSvxEventConfigPage, NULL );
810 :
811 : const SfxPoolItem* pItem =
812 0 : pSet_->GetItem( pSet_->GetPool()->GetWhich( SID_CONFIG ) );
813 :
814 0 : if ( pItem )
815 : {
816 0 : OUString text = ((const SfxStringItem*)pItem)->GetValue();
817 :
818 0 : if (text.indexOf( ITEM_TOOLBAR_URL ) == 0)
819 : {
820 0 : SetCurPageId( RID_SVXPAGE_TOOLBARS );
821 0 : }
822 : }
823 0 : }
824 :
825 0 : void SvxConfigDialog::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
826 : {
827 0 : m_xFrame = xFrame;
828 :
829 0 : if (!impl_showKeyConfigTabPage( xFrame ))
830 0 : RemoveTabPage( RID_SVXPAGE_KEYBOARD );
831 0 : }
832 :
833 0 : SvxConfigDialog::~SvxConfigDialog()
834 : {
835 0 : }
836 :
837 0 : short SvxConfigDialog::Ok()
838 : {
839 0 : return SfxTabDialog::Ok();
840 : }
841 :
842 0 : void SvxConfigDialog::PageCreated( sal_uInt16 nId, SfxTabPage& rPage )
843 : {
844 : (void)rPage;
845 :
846 0 : switch ( nId )
847 : {
848 : case RID_SVXPAGE_MENUS:
849 : case RID_SVXPAGE_TOOLBARS:
850 : case RID_SVXPAGE_KEYBOARD:
851 : {
852 0 : rPage.SetFrame(m_xFrame);
853 : }
854 0 : break;
855 : case RID_SVXPAGE_EVENTS:
856 : {
857 0 : dynamic_cast< SvxEventConfigPage& >( rPage ).LateInit( m_xFrame );
858 : };
859 0 : break;
860 : default:
861 0 : break;
862 : }
863 0 : }
864 :
865 : /******************************************************************************
866 : *
867 : * The SaveInData class is used to hold data for entries in the Save In
868 : * ListBox controls in the menu and toolbar tabs
869 : *
870 : ******************************************************************************/
871 :
872 : // Initialize static variable which holds default XImageManager
873 : uno::Reference< css::ui::XImageManager>* SaveInData::xDefaultImgMgr = NULL;
874 :
875 0 : SaveInData::SaveInData(
876 : const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
877 : const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
878 : const OUString& aModuleId,
879 : bool isDocConfig )
880 : :
881 : bModified( sal_False ),
882 : bDocConfig( isDocConfig ),
883 : bReadOnly( sal_False ),
884 : m_xCfgMgr( xCfgMgr ),
885 0 : m_xParentCfgMgr( xParentCfgMgr )
886 : {
887 0 : m_aSeparatorSeq.realloc( 1 );
888 0 : m_aSeparatorSeq[0].Name = OUString( ITEM_DESCRIPTOR_TYPE );
889 0 : m_aSeparatorSeq[0].Value <<= css::ui::ItemType::SEPARATOR_LINE;
890 :
891 0 : if ( bDocConfig )
892 : {
893 : uno::Reference< css::ui::XUIConfigurationPersistence >
894 0 : xDocPersistence( GetConfigManager(), uno::UNO_QUERY );
895 :
896 0 : bReadOnly = xDocPersistence->isReadOnly();
897 : }
898 :
899 0 : uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
900 :
901 : uno::Reference< container::XNameAccess > xNameAccess(
902 0 : css::frame::UICommandDescription::create(xContext) );
903 :
904 0 : xNameAccess->getByName( aModuleId ) >>= m_xCommandToLabelMap;
905 :
906 0 : if ( !m_xImgMgr.is() )
907 : {
908 : m_xImgMgr = uno::Reference< css::ui::XImageManager >(
909 0 : GetConfigManager()->getImageManager(), uno::UNO_QUERY );
910 : }
911 :
912 0 : if ( !IsDocConfig() )
913 : {
914 : // If this is not a document configuration then it is the settings
915 : // for the module (writer, calc, impress etc.) Use this as the default
916 : // XImageManager instance
917 0 : xDefaultImgMgr = &m_xImgMgr;
918 : }
919 : else
920 : {
921 : // If this is a document configuration then use the module image manager
922 : // as default.
923 0 : if ( m_xParentCfgMgr.is() )
924 : {
925 : m_xParentImgMgr = uno::Reference< css::ui::XImageManager >(
926 0 : m_xParentCfgMgr->getImageManager(), uno::UNO_QUERY );
927 0 : xDefaultImgMgr = &m_xParentImgMgr;
928 : }
929 0 : }
930 0 : }
931 :
932 0 : uno::Reference< graphic::XGraphic > GetGraphic(
933 : const uno::Reference< css::ui::XImageManager >& xImageManager,
934 : const OUString& rCommandURL )
935 : {
936 0 : uno::Reference< graphic::XGraphic > result;
937 :
938 0 : if ( xImageManager.is() )
939 : {
940 : // TODO handle large graphics
941 0 : uno::Sequence< uno::Reference< graphic::XGraphic > > aGraphicSeq;
942 :
943 0 : uno::Sequence< OUString > aImageCmdSeq( 1 );
944 0 : aImageCmdSeq[0] = rCommandURL;
945 :
946 : try
947 : {
948 : aGraphicSeq =
949 0 : xImageManager->getImages( GetImageType(), aImageCmdSeq );
950 :
951 0 : if ( aGraphicSeq.getLength() > 0 )
952 : {
953 0 : result = aGraphicSeq[0];
954 : }
955 : }
956 0 : catch ( uno::Exception& )
957 : {
958 : // will return empty XGraphic
959 0 : }
960 : }
961 :
962 0 : return result;
963 : }
964 :
965 0 : Image SaveInData::GetImage( const OUString& rCommandURL )
966 : {
967 0 : Image aImage;
968 :
969 : uno::Reference< graphic::XGraphic > xGraphic =
970 0 : GetGraphic( m_xImgMgr, rCommandURL );
971 :
972 0 : if ( xGraphic.is() )
973 : {
974 0 : aImage = Image( xGraphic );
975 : }
976 0 : else if ( xDefaultImgMgr != NULL && (*xDefaultImgMgr).is() )
977 : {
978 0 : xGraphic = GetGraphic( (*xDefaultImgMgr), rCommandURL );
979 :
980 0 : if ( xGraphic.is() )
981 : {
982 0 : aImage = Image( xGraphic );
983 : }
984 : }
985 :
986 0 : return aImage;
987 : }
988 :
989 0 : bool SaveInData::PersistChanges(
990 : const uno::Reference< uno::XInterface >& xManager )
991 : {
992 0 : bool result = sal_True;
993 :
994 : try
995 : {
996 0 : if ( xManager.is() && !IsReadOnly() )
997 : {
998 : uno::Reference< css::ui::XUIConfigurationPersistence >
999 0 : xConfigPersistence( xManager, uno::UNO_QUERY );
1000 :
1001 0 : if ( xConfigPersistence->isModified() )
1002 : {
1003 0 : xConfigPersistence->store();
1004 0 : }
1005 : }
1006 : }
1007 0 : catch ( com::sun::star::io::IOException& )
1008 : {
1009 0 : result = sal_False;
1010 : }
1011 :
1012 0 : return result;
1013 : }
1014 :
1015 : /******************************************************************************
1016 : *
1017 : * The MenuSaveInData class extends SaveInData and provides menu specific
1018 : * load and store functionality.
1019 : *
1020 : ******************************************************************************/
1021 :
1022 : // Initialize static variable which holds default Menu data
1023 : MenuSaveInData* MenuSaveInData::pDefaultData = NULL;
1024 :
1025 0 : MenuSaveInData::MenuSaveInData(
1026 : const uno::Reference< css::ui::XUIConfigurationManager >& cfgmgr,
1027 : const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
1028 : const OUString& aModuleId,
1029 : bool isDocConfig )
1030 : :
1031 : SaveInData( cfgmgr, xParentCfgMgr, aModuleId, isDocConfig ),
1032 : m_aMenuResourceURL(
1033 : ITEM_MENUBAR_URL ),
1034 : m_aDescriptorContainer(
1035 : ITEM_DESCRIPTOR_CONTAINER ),
1036 0 : pRootEntry( 0 )
1037 : {
1038 : try
1039 : {
1040 0 : OUString url( ITEM_MENUBAR_URL );
1041 0 : m_xMenuSettings = GetConfigManager()->getSettings( url, sal_False );
1042 : }
1043 0 : catch ( container::NoSuchElementException& )
1044 : {
1045 : // will use menu settings for the module
1046 : }
1047 :
1048 : // If this is not a document configuration then it is the settings
1049 : // for the module (writer, calc, impress etc.). These settings should
1050 : // be set as the default to be used for SaveIn locations that do not
1051 : // have custom settings
1052 0 : if ( !IsDocConfig() )
1053 : {
1054 0 : SetDefaultData( this );
1055 : }
1056 0 : }
1057 :
1058 0 : MenuSaveInData::~MenuSaveInData()
1059 : {
1060 0 : if ( pRootEntry != NULL )
1061 : {
1062 0 : delete pRootEntry;
1063 : }
1064 0 : }
1065 :
1066 : SvxEntries*
1067 0 : MenuSaveInData::GetEntries()
1068 : {
1069 0 : if ( pRootEntry == NULL )
1070 : {
1071 : pRootEntry = new SvxConfigEntry(
1072 : rtl::OUString("MainMenus"),
1073 0 : rtl::OUString(), sal_True);
1074 :
1075 0 : if ( m_xMenuSettings.is() )
1076 : {
1077 0 : LoadSubMenus( m_xMenuSettings, String(), pRootEntry );
1078 : }
1079 0 : else if ( GetDefaultData() != NULL )
1080 : {
1081 : // If the doc has no config settings use module config settings
1082 0 : LoadSubMenus( GetDefaultData()->m_xMenuSettings, String(), pRootEntry );
1083 : }
1084 : }
1085 :
1086 0 : return pRootEntry->GetEntries();
1087 : }
1088 :
1089 : void
1090 0 : MenuSaveInData::SetEntries( SvxEntries* pNewEntries )
1091 : {
1092 : // delete old menu hierarchy first
1093 0 : if ( pRootEntry != NULL )
1094 : {
1095 0 : delete pRootEntry->GetEntries();
1096 : }
1097 :
1098 : // now set new menu hierarchy
1099 0 : pRootEntry->SetEntries( pNewEntries );
1100 0 : }
1101 :
1102 0 : bool MenuSaveInData::LoadSubMenus(
1103 : const uno::Reference< container::XIndexAccess >& xMenuSettings,
1104 : const OUString& rBaseTitle,
1105 : SvxConfigEntry* pParentData )
1106 : {
1107 0 : SvxEntries* pEntries = pParentData->GetEntries();
1108 :
1109 : // Don't access non existing menu configuration!
1110 0 : if ( !xMenuSettings.is() )
1111 0 : return true;
1112 :
1113 0 : for ( sal_Int32 nIndex = 0; nIndex < xMenuSettings->getCount(); ++nIndex )
1114 : {
1115 0 : uno::Reference< container::XIndexAccess > xSubMenu;
1116 0 : OUString aCommandURL;
1117 0 : OUString aLabel;
1118 0 : bool bIsUserDefined = sal_True;
1119 :
1120 0 : sal_uInt16 nType( css::ui::ItemType::DEFAULT );
1121 :
1122 : bool bItem = GetMenuItemData( xMenuSettings, nIndex,
1123 0 : aCommandURL, aLabel, nType, xSubMenu );
1124 :
1125 0 : if ( bItem )
1126 : {
1127 0 : if ( nType == css::ui::ItemType::DEFAULT )
1128 : {
1129 0 : uno::Any a;
1130 : try
1131 : {
1132 0 : a = m_xCommandToLabelMap->getByName( aCommandURL );
1133 0 : bIsUserDefined = sal_False;
1134 : }
1135 0 : catch ( container::NoSuchElementException& )
1136 : {
1137 0 : bIsUserDefined = sal_True;
1138 : }
1139 :
1140 : // If custom label not set retrieve it from the command
1141 : // to info service
1142 0 : if ( aLabel.equals( OUString() ) )
1143 : {
1144 0 : uno::Sequence< beans::PropertyValue > aPropSeq;
1145 0 : if ( a >>= aPropSeq )
1146 : {
1147 0 : for ( sal_Int32 i = 0; i < aPropSeq.getLength(); ++i )
1148 : {
1149 0 : if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
1150 : {
1151 0 : aPropSeq[i].Value >>= aLabel;
1152 0 : break;
1153 : }
1154 : }
1155 0 : }
1156 : }
1157 :
1158 0 : if ( xSubMenu.is() )
1159 : {
1160 : // popup menu
1161 : SvxConfigEntry* pEntry = new SvxConfigEntry(
1162 0 : aLabel, aCommandURL, sal_True );
1163 :
1164 0 : pEntry->SetUserDefined( bIsUserDefined );
1165 :
1166 0 : pEntries->push_back( pEntry );
1167 :
1168 0 : OUString subMenuTitle( rBaseTitle );
1169 :
1170 0 : if ( !subMenuTitle.isEmpty() )
1171 : {
1172 0 : subMenuTitle += OUString( aMenuSeparatorStr);
1173 : }
1174 : else
1175 : {
1176 0 : pEntry->SetMain( sal_True );
1177 : }
1178 :
1179 0 : subMenuTitle += stripHotKey( aLabel );
1180 :
1181 0 : LoadSubMenus( xSubMenu, subMenuTitle, pEntry );
1182 : }
1183 : else
1184 : {
1185 : SvxConfigEntry* pEntry = new SvxConfigEntry(
1186 0 : aLabel, aCommandURL, sal_False );
1187 0 : pEntry->SetUserDefined( bIsUserDefined );
1188 0 : pEntries->push_back( pEntry );
1189 0 : }
1190 : }
1191 : else
1192 : {
1193 0 : SvxConfigEntry* pEntry = new SvxConfigEntry;
1194 0 : pEntry->SetUserDefined( bIsUserDefined );
1195 0 : pEntries->push_back( pEntry );
1196 : }
1197 : }
1198 0 : }
1199 0 : return true;
1200 : }
1201 :
1202 0 : bool MenuSaveInData::Apply()
1203 : {
1204 0 : bool result = sal_False;
1205 :
1206 0 : if ( IsModified() )
1207 : {
1208 : // Apply new menu bar structure to our settings container
1209 : m_xMenuSettings = uno::Reference< container::XIndexAccess >(
1210 0 : GetConfigManager()->createSettings(), uno::UNO_QUERY );
1211 :
1212 : uno::Reference< container::XIndexContainer > xIndexContainer (
1213 0 : m_xMenuSettings, uno::UNO_QUERY );
1214 :
1215 : uno::Reference< lang::XSingleComponentFactory > xFactory (
1216 0 : m_xMenuSettings, uno::UNO_QUERY );
1217 :
1218 0 : Apply( pRootEntry, xIndexContainer, xFactory, NULL );
1219 :
1220 : try
1221 : {
1222 0 : if ( GetConfigManager()->hasSettings( m_aMenuResourceURL ) )
1223 : {
1224 0 : GetConfigManager()->replaceSettings(
1225 0 : m_aMenuResourceURL, m_xMenuSettings );
1226 : }
1227 : else
1228 : {
1229 0 : GetConfigManager()->insertSettings(
1230 0 : m_aMenuResourceURL, m_xMenuSettings );
1231 : }
1232 : }
1233 0 : catch ( container::NoSuchElementException& )
1234 : {
1235 : OSL_TRACE("caught container::NoSuchElementException saving settings");
1236 : }
1237 0 : catch ( com::sun::star::io::IOException& )
1238 : {
1239 : OSL_TRACE("caught IOException saving settings");
1240 : }
1241 0 : catch ( com::sun::star::uno::Exception& )
1242 : {
1243 : OSL_TRACE("caught some other exception saving settings");
1244 : }
1245 :
1246 0 : SetModified( sal_False );
1247 :
1248 0 : result = PersistChanges( GetConfigManager() );
1249 : }
1250 :
1251 0 : return result;
1252 : }
1253 :
1254 0 : void MenuSaveInData::Apply(
1255 : SvxConfigEntry* pRootEntry_,
1256 : uno::Reference< container::XIndexContainer >& rMenuBar,
1257 : uno::Reference< lang::XSingleComponentFactory >& rFactory,
1258 : SvTreeListEntry *pParentEntry )
1259 : {
1260 : (void)pRootEntry_;
1261 : (void)pParentEntry;
1262 :
1263 0 : SvxEntries::const_iterator iter = GetEntries()->begin();
1264 0 : SvxEntries::const_iterator end = GetEntries()->end();
1265 :
1266 0 : uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
1267 :
1268 0 : for ( ; iter != end; ++iter )
1269 : {
1270 0 : SvxConfigEntry* pEntryData = *iter;
1271 :
1272 : uno::Sequence< beans::PropertyValue > aPropValueSeq =
1273 0 : ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntryData );
1274 :
1275 : uno::Reference< container::XIndexContainer > xSubMenuBar(
1276 0 : rFactory->createInstanceWithContext( xContext ),
1277 0 : uno::UNO_QUERY );
1278 :
1279 0 : sal_Int32 nIndex = aPropValueSeq.getLength();
1280 0 : aPropValueSeq.realloc( nIndex + 1 );
1281 0 : aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
1282 0 : aPropValueSeq[nIndex].Value <<= xSubMenuBar;
1283 0 : rMenuBar->insertByIndex(
1284 0 : rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1285 0 : ApplyMenu( xSubMenuBar, rFactory, pEntryData );
1286 0 : }
1287 0 : }
1288 :
1289 0 : void MenuSaveInData::ApplyMenu(
1290 : uno::Reference< container::XIndexContainer >& rMenuBar,
1291 : uno::Reference< lang::XSingleComponentFactory >& rFactory,
1292 : SvxConfigEntry* pMenuData )
1293 : {
1294 0 : uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
1295 :
1296 0 : SvxEntries::const_iterator iter = pMenuData->GetEntries()->begin();
1297 0 : SvxEntries::const_iterator end = pMenuData->GetEntries()->end();
1298 :
1299 0 : for ( ; iter != end; ++iter )
1300 : {
1301 0 : SvxConfigEntry* pEntry = *iter;
1302 :
1303 0 : if ( pEntry->IsPopup() )
1304 : {
1305 : uno::Sequence< beans::PropertyValue > aPropValueSeq =
1306 0 : ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntry );
1307 :
1308 : uno::Reference< container::XIndexContainer > xSubMenuBar(
1309 0 : rFactory->createInstanceWithContext( xContext ),
1310 0 : uno::UNO_QUERY );
1311 :
1312 0 : sal_Int32 nIndex = aPropValueSeq.getLength();
1313 0 : aPropValueSeq.realloc( nIndex + 1 );
1314 0 : aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
1315 0 : aPropValueSeq[nIndex].Value <<= xSubMenuBar;
1316 :
1317 0 : rMenuBar->insertByIndex(
1318 0 : rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1319 :
1320 0 : ApplyMenu( xSubMenuBar, rFactory, pEntry );
1321 : }
1322 0 : else if ( pEntry->IsSeparator() )
1323 : {
1324 0 : rMenuBar->insertByIndex(
1325 0 : rMenuBar->getCount(), uno::makeAny( m_aSeparatorSeq ));
1326 : }
1327 : else
1328 : {
1329 : uno::Sequence< beans::PropertyValue > aPropValueSeq =
1330 0 : ConvertSvxConfigEntry( m_xCommandToLabelMap, pEntry );
1331 0 : rMenuBar->insertByIndex(
1332 0 : rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
1333 : }
1334 0 : }
1335 0 : }
1336 :
1337 : void
1338 0 : MenuSaveInData::Reset()
1339 : {
1340 0 : GetConfigManager()->reset();
1341 :
1342 0 : delete pRootEntry;
1343 0 : pRootEntry = NULL;
1344 :
1345 : try
1346 : {
1347 0 : m_xMenuSettings = GetConfigManager()->getSettings(
1348 0 : m_aMenuResourceURL, sal_False );
1349 : }
1350 0 : catch ( container::NoSuchElementException& )
1351 : {
1352 : // will use default settings
1353 : }
1354 0 : }
1355 :
1356 : class PopupPainter : public SvLBoxString
1357 : {
1358 : public:
1359 0 : PopupPainter( SvTreeListEntry* pEntry, const String& rStr )
1360 0 : : SvLBoxString( pEntry, 0, rStr )
1361 0 : { }
1362 :
1363 0 : ~PopupPainter() { }
1364 :
1365 0 : virtual void Paint( const Point& rPos, SvTreeListBox& rOutDev,
1366 : const SvViewDataEntry* pView, const SvTreeListEntry* pEntry)
1367 : {
1368 0 : SvLBoxString::Paint(rPos, rOutDev, pView, pEntry);
1369 :
1370 0 : Color aOldFillColor = rOutDev.GetFillColor();
1371 :
1372 0 : SvTreeListBox* pTreeBox = static_cast< SvTreeListBox* >( &rOutDev );
1373 0 : long nX = pTreeBox->GetSizePixel().Width();
1374 :
1375 0 : ScrollBar* pVScroll = pTreeBox->GetVScroll();
1376 0 : if ( pVScroll->IsVisible() )
1377 : {
1378 0 : nX -= pVScroll->GetSizePixel().Width();
1379 : }
1380 :
1381 0 : const SvViewDataItem* pItem = rOutDev.GetViewDataItem( pEntry, this );
1382 0 : nX -= pItem->maSize.Height();
1383 :
1384 0 : long nSize = pItem->maSize.Height() / 2;
1385 0 : long nHalfSize = nSize / 2;
1386 0 : long nY = rPos.Y() + nHalfSize;
1387 :
1388 0 : if ( aOldFillColor == COL_WHITE )
1389 : {
1390 0 : rOutDev.SetFillColor( Color( COL_BLACK ) );
1391 : }
1392 : else
1393 : {
1394 0 : rOutDev.SetFillColor( Color( COL_WHITE ) );
1395 : }
1396 :
1397 0 : long n = 0;
1398 0 : while ( n <= nHalfSize )
1399 : {
1400 0 : rOutDev.DrawRect( Rectangle( nX+n, nY+n, nX+n, nY+nSize-n ) );
1401 0 : ++n;
1402 : }
1403 :
1404 0 : rOutDev.SetFillColor( aOldFillColor );
1405 0 : }
1406 : };
1407 :
1408 : /******************************************************************************
1409 : *
1410 : * SvxMenuEntriesListBox is the listbox in which the menu items for a
1411 : * particular menu are shown. We have a custom listbox because we need
1412 : * to add drag'n'drop support from the Macro Selector and within the
1413 : * listbox
1414 : *
1415 : *****************************************************************************/
1416 0 : SvxMenuEntriesListBox::SvxMenuEntriesListBox(
1417 : Window* pParent, const ResId& rResId)
1418 : : SvTreeListBox( pParent, rResId )
1419 : , pPage( (SvxMenuConfigPage*) pParent )
1420 0 : , m_bIsInternalDrag( sal_False )
1421 : {
1422 : SetStyle(
1423 0 : GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_HIDESELECTION );
1424 :
1425 0 : SetSpaceBetweenEntries( 3 );
1426 0 : SetEntryHeight( ENTRY_HEIGHT );
1427 :
1428 0 : SetHighlightRange();
1429 0 : SetSelectionMode(SINGLE_SELECTION);
1430 :
1431 : SetDragDropMode( SV_DRAGDROP_CTRL_MOVE |
1432 : SV_DRAGDROP_APP_COPY |
1433 : SV_DRAGDROP_ENABLE_TOP |
1434 0 : SV_DRAGDROP_APP_DROP);
1435 0 : }
1436 :
1437 0 : SvxMenuEntriesListBox::~SvxMenuEntriesListBox()
1438 : {
1439 : // do nothing
1440 0 : }
1441 :
1442 : // drag and drop support
1443 0 : DragDropMode SvxMenuEntriesListBox::NotifyStartDrag(
1444 : TransferDataContainer& aTransferDataContainer, SvTreeListEntry* pEntry )
1445 : {
1446 : (void)aTransferDataContainer;
1447 : (void)pEntry;
1448 :
1449 0 : m_bIsInternalDrag = sal_True;
1450 0 : return GetDragDropMode();
1451 : }
1452 :
1453 0 : void SvxMenuEntriesListBox::DragFinished( sal_Int8 nDropAction )
1454 : {
1455 : (void)nDropAction;
1456 0 : m_bIsInternalDrag = sal_False;
1457 0 : }
1458 :
1459 0 : sal_Int8 SvxMenuEntriesListBox::AcceptDrop( const AcceptDropEvent& rEvt )
1460 : {
1461 0 : if ( m_bIsInternalDrag )
1462 : {
1463 : // internal copy isn't allowed!
1464 0 : if ( rEvt.mnAction == DND_ACTION_COPY )
1465 0 : return DND_ACTION_NONE;
1466 : else
1467 0 : return SvTreeListBox::AcceptDrop( rEvt );
1468 : }
1469 :
1470 : // Always do COPY instead of MOVE if D&D comes from outside!
1471 0 : AcceptDropEvent aNewAcceptDropEvent( rEvt );
1472 0 : aNewAcceptDropEvent.mnAction = DND_ACTION_COPY;
1473 0 : return SvTreeListBox::AcceptDrop( aNewAcceptDropEvent );
1474 : }
1475 :
1476 0 : sal_Bool SvxMenuEntriesListBox::NotifyAcceptDrop( SvTreeListEntry* )
1477 : {
1478 0 : return sal_True;
1479 : }
1480 :
1481 0 : sal_Bool SvxMenuEntriesListBox::NotifyMoving(
1482 : SvTreeListEntry* pTarget, SvTreeListEntry* pSource,
1483 : SvTreeListEntry*& rpNewParent, sal_uLong& rNewChildPos)
1484 : {
1485 : // only try to do a move if we are dragging within the list box
1486 0 : if ( m_bIsInternalDrag )
1487 : {
1488 0 : if ( pPage->MoveEntryData( pSource, pTarget ) == sal_True )
1489 : {
1490 : SvTreeListBox::NotifyMoving(
1491 0 : pTarget, pSource, rpNewParent, rNewChildPos );
1492 0 : return sal_True;
1493 : }
1494 : else
1495 : {
1496 0 : return sal_False;
1497 : }
1498 : }
1499 : else
1500 : {
1501 0 : return NotifyCopying( pTarget, pSource, rpNewParent, rNewChildPos );
1502 : }
1503 : }
1504 :
1505 0 : sal_Bool SvxMenuEntriesListBox::NotifyCopying(
1506 : SvTreeListEntry* pTarget, SvTreeListEntry* pSource,
1507 : SvTreeListEntry*& rpNewParent, sal_uLong& rNewChildPos)
1508 : {
1509 : (void)pSource;
1510 : (void)rpNewParent;
1511 : (void)rNewChildPos;
1512 :
1513 0 : if ( !m_bIsInternalDrag )
1514 : {
1515 : // if the target is NULL then add function to the start of the list
1516 0 : pPage->AddFunction( pTarget, pTarget == NULL );
1517 :
1518 : // AddFunction already adds the listbox entry so return FALSE
1519 : // to stop another listbox entry being added
1520 0 : return sal_False;
1521 : }
1522 :
1523 : // Copying is only allowed from external controls, not within the listbox
1524 0 : return sal_False;
1525 : }
1526 :
1527 0 : void SvxMenuEntriesListBox::KeyInput( const KeyEvent& rKeyEvent )
1528 : {
1529 0 : KeyCode keycode = rKeyEvent.GetKeyCode();
1530 :
1531 : // support DELETE for removing the current entry
1532 0 : if ( keycode == KEY_DELETE )
1533 : {
1534 0 : pPage->DeleteSelectedContent();
1535 : }
1536 : // support CTRL+UP and CTRL+DOWN for moving selected entries
1537 0 : else if ( keycode.GetCode() == KEY_UP && keycode.IsMod1() )
1538 : {
1539 0 : pPage->MoveEntry( sal_True );
1540 : }
1541 0 : else if ( keycode.GetCode() == KEY_DOWN && keycode.IsMod1() )
1542 : {
1543 0 : pPage->MoveEntry( sal_False );
1544 : }
1545 : else
1546 : {
1547 : // pass on to superclass
1548 0 : SvTreeListBox::KeyInput( rKeyEvent );
1549 : }
1550 0 : }
1551 :
1552 : // class SvxDescriptionEdit ----------------------------------------------
1553 :
1554 0 : SvxDescriptionEdit::SvxDescriptionEdit( Window* pParent, const ResId& _rId ) :
1555 :
1556 0 : ExtMultiLineEdit( pParent, _rId )
1557 :
1558 : {
1559 : // calculate the available space for help text
1560 0 : m_aRealRect = Rectangle( Point(), GetSizePixel() );
1561 0 : if ( GetVScrollBar() )
1562 0 : m_aRealRect.Right() -= ( GetVScrollBar()->GetSizePixel().Width() + 4 );
1563 :
1564 0 : SetLeftMargin(2);
1565 0 : SetBorderStyle( WINDOW_BORDER_MONO );
1566 0 : }
1567 :
1568 : // -----------------------------------------------------------------------
1569 :
1570 0 : void SvxDescriptionEdit::SetNewText( const String& _rText )
1571 : {
1572 0 : String sTemp( _rText );
1573 0 : sal_Bool bShow = sal_False;
1574 0 : if ( sTemp.Len() > 0 )
1575 : {
1576 : // detect if a scrollbar is necessary
1577 0 : Rectangle aRect = GetTextRect( m_aRealRect, sTemp, TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE );
1578 0 : bShow = ( aRect.Bottom() > m_aRealRect.Bottom() );
1579 : }
1580 :
1581 0 : if ( GetVScrollBar() )
1582 0 : GetVScrollBar()->Show( bShow );
1583 :
1584 0 : if ( bShow )
1585 0 : sTemp += '\n';
1586 :
1587 0 : SetText( sTemp );
1588 0 : }
1589 :
1590 : /******************************************************************************
1591 : *
1592 : * SvxConfigPage is the abstract base class on which the Menu and Toolbar
1593 : * configuration tabpages are based. It includes methods which are common to
1594 : * both tabpages to add, delete, move and rename items etc.
1595 : *
1596 : *****************************************************************************/
1597 0 : SvxConfigPage::SvxConfigPage(
1598 : Window *pParent, const SfxItemSet& rSet )
1599 : :
1600 0 : SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_MENUS ), rSet ),
1601 : bInitialised( sal_False ),
1602 : pCurrentSaveInData( 0 ),
1603 0 : aTopLevelSeparator( this, CUI_RES( GRP_MENUS ) ),
1604 0 : aTopLevelLabel( this, CUI_RES( FT_MENUS ) ),
1605 0 : aTopLevelListBox( this, CUI_RES( LB_MENUS ) ),
1606 0 : aNewTopLevelButton( this, CUI_RES( BTN_NEW ) ),
1607 0 : aModifyTopLevelButton( this, CUI_RES( BTN_CHANGE ) ),
1608 0 : aContentsSeparator( this, CUI_RES( GRP_MENU_SEPARATOR ) ),
1609 0 : aContentsLabel( this, CUI_RES( GRP_MENU_ENTRIES ) ),
1610 : aContentsListBox( 0 ),
1611 0 : aAddCommandsButton( this, CUI_RES( BTN_ADD_COMMANDS ) ),
1612 0 : aModifyCommandButton( this, CUI_RES( BTN_CHANGE_ENTRY ) ),
1613 0 : aMoveUpButton( this, CUI_RES( BTN_UP ) ),
1614 0 : aMoveDownButton( this, CUI_RES( BTN_DOWN ) ),
1615 0 : aSaveInText( this, CUI_RES( TXT_SAVEIN ) ),
1616 0 : aSaveInListBox( this, CUI_RES( LB_SAVEIN ) ),
1617 0 : aDescriptionLabel( this, CUI_RES( FT_DESCRIPTION ) ),
1618 0 : aDescriptionField( this, CUI_RES( ED_DESCRIPTION ) ),
1619 0 : pSelectorDlg( 0 )
1620 : {
1621 0 : aDescriptionField.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
1622 0 : aDescriptionField.SetAutoScroll( sal_True );
1623 0 : aDescriptionField.EnableCursor( sal_False );
1624 :
1625 0 : aMoveUpButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_UP)));
1626 0 : aMoveDownButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_DOWN)));
1627 0 : aMoveUpButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1628 0 : aMoveDownButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1629 0 : aNewTopLevelButton.SetAccessibleRelationMemberOf(&aTopLevelSeparator);
1630 0 : aModifyTopLevelButton.SetAccessibleRelationMemberOf(&aTopLevelSeparator);
1631 0 : aAddCommandsButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1632 0 : aModifyCommandButton.SetAccessibleRelationMemberOf(&aContentsSeparator);
1633 0 : }
1634 :
1635 0 : SvxConfigPage::~SvxConfigPage()
1636 : {
1637 0 : }
1638 :
1639 0 : void SvxConfigPage::Reset( const SfxItemSet& )
1640 : {
1641 : // If we haven't initialised our XMultiServiceFactory reference
1642 : // then Reset is being called at the opening of the dialog.
1643 : //
1644 : // Load menu configuration data for the module of the currently
1645 : // selected document, for the currently selected document, and for
1646 : // all other open documents of the same module type
1647 0 : if ( !bInitialised )
1648 : {
1649 0 : sal_uInt16 nPos = 0;
1650 0 : uno::Reference < css::ui::XUIConfigurationManager > xCfgMgr;
1651 0 : uno::Reference < css::ui::XUIConfigurationManager > xDocCfgMgr;
1652 :
1653 : uno::Reference< lang::XMultiServiceFactory > xServiceManager(
1654 0 : ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
1655 : uno::Reference< uno::XComponentContext > xContext(
1656 0 : ::comphelper::getProcessComponentContext(), uno::UNO_QUERY_THROW );
1657 :
1658 0 : m_xFrame = GetFrame();
1659 0 : OUString aModuleId = GetFrameWithDefaultAndIdentify( m_xFrame );
1660 :
1661 : // replace %MODULENAME in the label with the correct module name
1662 : uno::Reference< css::frame::XModuleManager2 > xModuleManager(
1663 0 : css::frame::ModuleManager::create( xContext ));
1664 0 : OUString aModuleName = GetUIModuleName( aModuleId, xModuleManager );
1665 :
1666 0 : OUString title = aTopLevelSeparator.GetText();
1667 0 : OUString aSearchString("%MODULENAME" );
1668 0 : sal_Int32 index = title.indexOf( aSearchString );
1669 :
1670 0 : if ( index != -1 )
1671 : {
1672 : title = title.replaceAt(
1673 0 : index, aSearchString.getLength(), aModuleName );
1674 0 : aTopLevelSeparator.SetText( title );
1675 : }
1676 :
1677 : uno::Reference< css::ui::XModuleUIConfigurationManagerSupplier >
1678 0 : xModuleCfgSupplier( css::ui::ModuleUIConfigurationManagerSupplier::create(xContext) );
1679 :
1680 : // Set up data for module specific menus
1681 0 : SaveInData* pModuleData = NULL;
1682 :
1683 : try
1684 : {
1685 : xCfgMgr =
1686 0 : xModuleCfgSupplier->getUIConfigurationManager( aModuleId );
1687 :
1688 : pModuleData = CreateSaveInData( xCfgMgr,
1689 : uno::Reference< css::ui::XUIConfigurationManager >(),
1690 : aModuleId,
1691 0 : sal_False );
1692 : }
1693 0 : catch ( container::NoSuchElementException& )
1694 : {
1695 : }
1696 :
1697 0 : if ( pModuleData != NULL )
1698 : {
1699 : nPos = aSaveInListBox.InsertEntry(
1700 : utl::ConfigManager::getProductName() +
1701 0 : OUString( " " ) + aModuleName );
1702 0 : aSaveInListBox.SetEntryData( nPos, pModuleData );
1703 : }
1704 :
1705 : // try to retrieve the document based ui configuration manager
1706 0 : OUString aTitle;
1707 : uno::Reference< frame::XController > xController =
1708 0 : m_xFrame->getController();
1709 0 : if ( CanConfig( aModuleId ) && xController.is() )
1710 : {
1711 0 : uno::Reference< frame::XModel > xModel( xController->getModel() );
1712 0 : if ( xModel.is() )
1713 : {
1714 : uno::Reference< css::ui::XUIConfigurationManagerSupplier >
1715 0 : xCfgSupplier( xModel, uno::UNO_QUERY );
1716 :
1717 0 : if ( xCfgSupplier.is() )
1718 : {
1719 0 : xDocCfgMgr = xCfgSupplier->getUIConfigurationManager();
1720 : }
1721 0 : aTitle = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
1722 0 : }
1723 : }
1724 :
1725 0 : SaveInData* pDocData = NULL;
1726 0 : if ( xDocCfgMgr.is() )
1727 : {
1728 0 : pDocData = CreateSaveInData( xDocCfgMgr, xCfgMgr, aModuleId, sal_True );
1729 :
1730 0 : if ( !pDocData->IsReadOnly() )
1731 : {
1732 0 : nPos = aSaveInListBox.InsertEntry( aTitle );
1733 0 : aSaveInListBox.SetEntryData( nPos, pDocData );
1734 : }
1735 : }
1736 :
1737 : // if an item to select has been passed in (eg. the ResourceURL for a
1738 : // toolbar) then try to select the SaveInData entry that has that item
1739 0 : bool bURLToSelectFound = sal_False;
1740 0 : if ( !m_aURLToSelect.isEmpty() )
1741 : {
1742 0 : if ( pDocData != NULL && pDocData->HasURL( m_aURLToSelect ) )
1743 : {
1744 0 : aSaveInListBox.SelectEntryPos( nPos, sal_True );
1745 0 : pCurrentSaveInData = pDocData;
1746 0 : bURLToSelectFound = sal_True;
1747 : }
1748 0 : else if ( pModuleData->HasURL( m_aURLToSelect ) )
1749 : {
1750 0 : aSaveInListBox.SelectEntryPos( 0, sal_True );
1751 0 : pCurrentSaveInData = pModuleData;
1752 0 : bURLToSelectFound = sal_True;
1753 : }
1754 : }
1755 :
1756 0 : if ( bURLToSelectFound == sal_False )
1757 : {
1758 : // if the document has menu configuration settings select it
1759 : // it the SaveIn listbox, otherwise select the module data
1760 0 : if ( pDocData != NULL && pDocData->HasSettings() )
1761 : {
1762 0 : aSaveInListBox.SelectEntryPos( nPos, sal_True );
1763 0 : pCurrentSaveInData = pDocData;
1764 : }
1765 : else
1766 : {
1767 0 : aSaveInListBox.SelectEntryPos( 0, sal_True );
1768 0 : pCurrentSaveInData = pModuleData;
1769 : }
1770 : }
1771 :
1772 : #ifdef DBG_UTIL
1773 : DBG_ASSERT( pCurrentSaveInData, "SvxConfigPage::Reset(): no SaveInData" );
1774 : #endif
1775 :
1776 0 : if ( CanConfig( aModuleId ) )
1777 : {
1778 : // Load configuration for other open documents which have
1779 : // same module type
1780 0 : uno::Sequence< uno::Reference< frame::XFrame > > aFrameList;
1781 : try
1782 : {
1783 : uno::Reference< frame::XFramesSupplier > xFramesSupplier(
1784 0 : xServiceManager->createInstance(
1785 0 : OUString( "com.sun.star.frame.Desktop" ) ),
1786 0 : uno::UNO_QUERY_THROW );
1787 :
1788 : uno::Reference< frame::XFrames > xFrames =
1789 0 : xFramesSupplier->getFrames();
1790 :
1791 0 : aFrameList = xFrames->queryFrames(
1792 0 : frame::FrameSearchFlag::ALL & ~frame::FrameSearchFlag::SELF );
1793 :
1794 : }
1795 0 : catch( const uno::Exception& )
1796 : {
1797 : DBG_UNHANDLED_EXCEPTION();
1798 : }
1799 :
1800 0 : for ( sal_Int32 i = 0; i < aFrameList.getLength(); ++i )
1801 : {
1802 0 : SaveInData* pData = NULL;
1803 0 : uno::Reference < frame::XFrame > xf = aFrameList[i];
1804 :
1805 0 : if ( xf.is() && xf != m_xFrame )
1806 : {
1807 0 : OUString aCheckId;
1808 : try{
1809 0 : aCheckId = xModuleManager->identify( xf );
1810 0 : } catch(const uno::Exception&)
1811 0 : { aCheckId = ::rtl::OUString(); }
1812 :
1813 0 : if ( aModuleId.equals( aCheckId ) )
1814 : {
1815 : // try to get the document based ui configuration manager
1816 0 : OUString aTitle2;
1817 : uno::Reference< frame::XController > xController_ =
1818 0 : xf->getController();
1819 :
1820 0 : if ( xController_.is() )
1821 : {
1822 : uno::Reference< frame::XModel > xModel(
1823 0 : xController_->getModel() );
1824 :
1825 0 : if ( xModel.is() )
1826 : {
1827 : uno::Reference<
1828 : css::ui::XUIConfigurationManagerSupplier >
1829 0 : xCfgSupplier( xModel, uno::UNO_QUERY );
1830 :
1831 0 : if ( xCfgSupplier.is() )
1832 : {
1833 : xDocCfgMgr =
1834 0 : xCfgSupplier->getUIConfigurationManager();
1835 : }
1836 0 : aTitle2 = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
1837 0 : }
1838 : }
1839 :
1840 0 : if ( xDocCfgMgr.is() )
1841 : {
1842 0 : pData = CreateSaveInData( xDocCfgMgr, xCfgMgr, aModuleId, sal_True );
1843 :
1844 0 : if ( pData && !pData->IsReadOnly() )
1845 : {
1846 0 : nPos = aSaveInListBox.InsertEntry( aTitle2 );
1847 0 : aSaveInListBox.SetEntryData( nPos, pData );
1848 : }
1849 0 : }
1850 0 : }
1851 : }
1852 0 : }
1853 : }
1854 :
1855 : aSaveInListBox.SetSelectHdl(
1856 0 : LINK( this, SvxConfigPage, SelectSaveInLocation ) );
1857 :
1858 0 : bInitialised = sal_True;
1859 :
1860 0 : Init();
1861 : }
1862 : else
1863 : {
1864 0 : if ( QueryReset() == RET_YES )
1865 : {
1866 : // Reset menu configuration for currently selected SaveInData
1867 0 : GetSaveInData()->Reset();
1868 :
1869 0 : Init();
1870 : }
1871 : }
1872 0 : }
1873 :
1874 0 : ::rtl::OUString SvxConfigPage::GetFrameWithDefaultAndIdentify( uno::Reference< frame::XFrame >& _inout_rxFrame )
1875 : {
1876 0 : ::rtl::OUString sModuleID;
1877 : try
1878 : {
1879 : uno::Reference< lang::XMultiServiceFactory > xServiceManager(
1880 0 : ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
1881 :
1882 : uno::Reference< frame::XFramesSupplier > xFramesSupplier(
1883 0 : xServiceManager->createInstance(
1884 0 : OUString( "com.sun.star.frame.Desktop" ) ),
1885 0 : uno::UNO_QUERY_THROW );
1886 :
1887 0 : if ( !_inout_rxFrame.is() )
1888 0 : _inout_rxFrame = xFramesSupplier->getActiveFrame();
1889 :
1890 0 : if ( !_inout_rxFrame.is() )
1891 : {
1892 0 : uno::Reference< frame::XDesktop > xDesktop( xFramesSupplier, uno::UNO_QUERY_THROW );
1893 0 : _inout_rxFrame = xDesktop->getCurrentFrame();
1894 : }
1895 :
1896 0 : if ( !_inout_rxFrame.is() && SfxViewFrame::Current() )
1897 0 : _inout_rxFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
1898 :
1899 0 : if ( !_inout_rxFrame.is() )
1900 : {
1901 : SAL_WARN( "cui.customize", "SvxConfigPage::GetFrameWithDefaultAndIdentify(): no frame found!" );
1902 : return sModuleID;
1903 : }
1904 :
1905 : uno::Reference< css::frame::XModuleManager2 > xModuleManager(
1906 0 : css::frame::ModuleManager::create( comphelper::getComponentContext(xServiceManager) ) );
1907 :
1908 : try
1909 : {
1910 0 : sModuleID = xModuleManager->identify( _inout_rxFrame );
1911 : }
1912 0 : catch ( const frame::UnknownModuleException& )
1913 : {
1914 0 : }
1915 :
1916 : }
1917 0 : catch( const uno::Exception& )
1918 : {
1919 : DBG_UNHANDLED_EXCEPTION();
1920 : }
1921 :
1922 0 : return sModuleID;
1923 : }
1924 :
1925 0 : sal_Bool SvxConfigPage::FillItemSet( SfxItemSet& )
1926 : {
1927 0 : bool result = sal_False;
1928 :
1929 0 : for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); ++i )
1930 : {
1931 : SaveInData* pData =
1932 0 : (SaveInData*) aSaveInListBox.GetEntryData( i );
1933 :
1934 0 : result = pData->Apply();
1935 : }
1936 0 : return result;
1937 : }
1938 :
1939 0 : void SvxConfigPage::PositionContentsListBox()
1940 : {
1941 0 : if ( aContentsListBox == NULL )
1942 : {
1943 0 : return;
1944 : }
1945 :
1946 0 : Point p, newp;
1947 0 : Size s, news;
1948 : long x, y, width, height;
1949 :
1950 : // x and width is same as aTopLevelListBox
1951 0 : x = aTopLevelListBox.GetPosPixel().X();
1952 0 : width = aTopLevelListBox.GetSizePixel().Width();
1953 :
1954 : // y is same as aAddCommandsButton
1955 0 : y = aAddCommandsButton.GetPosPixel().Y();
1956 :
1957 : // get gap between aAddCommandsButton and aContentsSeparator
1958 0 : p = aContentsSeparator.GetPosPixel();
1959 0 : s = aContentsSeparator.GetSizePixel();
1960 0 : long gap = y - ( p.Y() + s.Height() );
1961 :
1962 0 : height = aSaveInListBox.GetPosPixel().Y() - y - gap;
1963 :
1964 0 : aContentsListBox->SetPosPixel( Point( x, y ) );
1965 0 : aContentsListBox->SetSizePixel( Size( width, height ) );
1966 : }
1967 :
1968 0 : IMPL_LINK( SvxConfigPage, SelectSaveInLocation, ListBox *, pBox )
1969 : {
1970 : (void)pBox;
1971 :
1972 : pCurrentSaveInData = (SaveInData*) aSaveInListBox.GetEntryData(
1973 0 : aSaveInListBox.GetSelectEntryPos());
1974 :
1975 0 : Init();
1976 0 : return 1;
1977 : }
1978 :
1979 0 : void SvxConfigPage::ReloadTopLevelListBox( SvxConfigEntry* pToSelect )
1980 : {
1981 0 : sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
1982 0 : aTopLevelListBox.Clear();
1983 :
1984 0 : if ( GetSaveInData() && GetSaveInData()->GetEntries() )
1985 : {
1986 0 : SvxEntries::const_iterator iter = GetSaveInData()->GetEntries()->begin();
1987 0 : SvxEntries::const_iterator end = GetSaveInData()->GetEntries()->end();
1988 :
1989 0 : for ( ; iter != end; ++iter )
1990 : {
1991 0 : SvxConfigEntry* pEntryData = *iter;
1992 0 : sal_uInt16 nPos = aTopLevelListBox.InsertEntry( stripHotKey( pEntryData->GetName() ) );
1993 0 : aTopLevelListBox.SetEntryData( nPos, pEntryData );
1994 :
1995 0 : if ( pEntryData == pToSelect )
1996 0 : nSelectionPos = nPos;
1997 :
1998 0 : AddSubMenusToUI( stripHotKey( pEntryData->GetName() ), pEntryData );
1999 : }
2000 : }
2001 : #ifdef DBG_UTIL
2002 : else
2003 : {
2004 : DBG_ASSERT( GetSaveInData(), "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData" );
2005 : DBG_ASSERT( GetSaveInData()->GetEntries() ,
2006 : "SvxConfigPage::ReloadTopLevelListBox(): no SaveInData entries" );
2007 : }
2008 : #endif
2009 :
2010 0 : nSelectionPos = nSelectionPos < aTopLevelListBox.GetEntryCount() ?
2011 0 : nSelectionPos : aTopLevelListBox.GetEntryCount() - 1;
2012 :
2013 0 : aTopLevelListBox.SelectEntryPos( nSelectionPos, sal_True );
2014 0 : aTopLevelListBox.GetSelectHdl().Call( this );
2015 0 : }
2016 :
2017 0 : void SvxConfigPage::AddSubMenusToUI(
2018 : const String& rBaseTitle, SvxConfigEntry* pParentData )
2019 : {
2020 0 : SvxEntries::const_iterator iter = pParentData->GetEntries()->begin();
2021 0 : SvxEntries::const_iterator end = pParentData->GetEntries()->end();
2022 :
2023 0 : for ( ; iter != end; ++iter )
2024 : {
2025 0 : SvxConfigEntry* pEntryData = *iter;
2026 :
2027 0 : if ( pEntryData->IsPopup() )
2028 : {
2029 0 : OUString subMenuTitle( rBaseTitle );
2030 0 : subMenuTitle += OUString(aMenuSeparatorStr);
2031 0 : subMenuTitle += stripHotKey( pEntryData->GetName() );
2032 :
2033 0 : sal_uInt16 nPos = aTopLevelListBox.InsertEntry( subMenuTitle );
2034 0 : aTopLevelListBox.SetEntryData( nPos, pEntryData );
2035 :
2036 0 : AddSubMenusToUI( subMenuTitle, pEntryData );
2037 : }
2038 : }
2039 0 : }
2040 :
2041 0 : SvxEntries* SvxConfigPage::FindParentForChild(
2042 : SvxEntries* pRootEntries, SvxConfigEntry* pChildData )
2043 : {
2044 0 : SvxEntries::const_iterator iter = pRootEntries->begin();
2045 0 : SvxEntries::const_iterator end = pRootEntries->end();
2046 :
2047 0 : for ( ; iter != end; ++iter )
2048 : {
2049 0 : SvxConfigEntry* pEntryData = *iter;
2050 :
2051 0 : if ( pEntryData == pChildData )
2052 : {
2053 0 : return pRootEntries;
2054 : }
2055 0 : else if ( pEntryData->IsPopup() )
2056 : {
2057 : SvxEntries* result =
2058 0 : FindParentForChild( pEntryData->GetEntries(), pChildData );
2059 :
2060 0 : if ( result != NULL )
2061 : {
2062 0 : return result;
2063 : }
2064 : }
2065 : }
2066 0 : return NULL;
2067 : }
2068 :
2069 0 : SvTreeListEntry* SvxConfigPage::AddFunction(
2070 : SvTreeListEntry* pTarget, bool bFront, bool bAllowDuplicates )
2071 : {
2072 0 : String aDisplayName = pSelectorDlg->GetSelectedDisplayName();
2073 0 : String aHelpText = pSelectorDlg->GetSelectedHelpText();
2074 0 : String aURL = pSelectorDlg->GetScriptURL();
2075 :
2076 0 : if ( !aURL.Len() )
2077 : {
2078 0 : return NULL;
2079 : }
2080 :
2081 : SvxConfigEntry* pNewEntryData =
2082 0 : new SvxConfigEntry( aDisplayName, aURL, sal_False );
2083 0 : pNewEntryData->SetUserDefined( sal_True );
2084 :
2085 : // check that this function is not already in the menu
2086 0 : SvxConfigEntry* pParent = GetTopLevelSelection();
2087 :
2088 0 : SvxEntries::const_iterator iter = pParent->GetEntries()->begin();
2089 0 : SvxEntries::const_iterator end = pParent->GetEntries()->end();
2090 :
2091 0 : if ( !bAllowDuplicates )
2092 : {
2093 0 : while ( iter != end )
2094 : {
2095 0 : SvxConfigEntry *pCurEntry = *iter;
2096 :
2097 0 : if ( pCurEntry->GetCommand() == pNewEntryData->GetCommand() )
2098 : {
2099 : // asynchronous error message, because of MsgBoxes
2100 : PostUserEvent(
2101 0 : LINK( this, SvxConfigPage, AsyncInfoMsg ) );
2102 0 : return NULL;
2103 : }
2104 :
2105 0 : ++iter;
2106 : }
2107 : }
2108 :
2109 0 : return InsertEntry( pNewEntryData, pTarget, bFront );
2110 : }
2111 :
2112 0 : SvTreeListEntry* SvxConfigPage::InsertEntry(
2113 : SvxConfigEntry* pNewEntryData,
2114 : SvTreeListEntry* pTarget,
2115 : bool bFront )
2116 : {
2117 : // Grab the entries list for the currently selected menu
2118 0 : SvxEntries* pEntries = GetTopLevelSelection()->GetEntries();
2119 :
2120 0 : SvTreeListEntry* pNewEntry = NULL;
2121 : SvTreeListEntry* pCurEntry =
2122 0 : pTarget != NULL ? pTarget : aContentsListBox->GetCurEntry();
2123 :
2124 0 : if ( bFront )
2125 : {
2126 0 : pEntries->insert( pEntries->begin(), pNewEntryData );
2127 0 : pNewEntry = InsertEntryIntoUI( pNewEntryData, 0 );
2128 : }
2129 0 : else if ( pCurEntry == NULL || pCurEntry == aContentsListBox->Last() )
2130 : {
2131 0 : pEntries->push_back( pNewEntryData );
2132 0 : pNewEntry = InsertEntryIntoUI( pNewEntryData );
2133 : }
2134 : else
2135 : {
2136 : SvxConfigEntry* pEntryData =
2137 0 : (SvxConfigEntry*) pCurEntry->GetUserData();
2138 :
2139 0 : SvxEntries::iterator iter = pEntries->begin();
2140 0 : SvxEntries::const_iterator end = pEntries->end();
2141 :
2142 : // Advance the iterator to the data for currently selected entry
2143 0 : sal_uInt16 nPos = 0;
2144 0 : while (*iter != pEntryData && ++iter != end)
2145 : {
2146 0 : ++nPos;
2147 : }
2148 :
2149 : // Now step past it to the entry after the currently selected one
2150 0 : ++iter;
2151 0 : ++nPos;
2152 :
2153 : // Now add the new entry to the UI and to the parent's list
2154 0 : if ( iter != end )
2155 : {
2156 0 : pEntries->insert( iter, pNewEntryData );
2157 0 : pNewEntry = InsertEntryIntoUI( pNewEntryData, nPos );
2158 : }
2159 : }
2160 :
2161 0 : if ( pNewEntry != NULL )
2162 : {
2163 0 : aContentsListBox->Select( pNewEntry );
2164 0 : aContentsListBox->MakeVisible( pNewEntry );
2165 :
2166 0 : GetSaveInData()->SetModified( sal_True );
2167 : }
2168 :
2169 0 : return pNewEntry;
2170 : }
2171 :
2172 0 : SvTreeListEntry* SvxConfigPage::InsertEntryIntoUI(
2173 : SvxConfigEntry* pNewEntryData, sal_uLong nPos )
2174 : {
2175 0 : SvTreeListEntry* pNewEntry = NULL;
2176 :
2177 0 : if (pNewEntryData->IsSeparator())
2178 : {
2179 : pNewEntry = aContentsListBox->InsertEntry(
2180 : rtl::OUString(aSeparatorStr),
2181 0 : 0, sal_False, nPos, pNewEntryData);
2182 : }
2183 : else
2184 : {
2185 0 : OUString aName = stripHotKey( pNewEntryData->GetName() );
2186 :
2187 0 : Image aImage = GetSaveInData()->GetImage(
2188 0 : pNewEntryData->GetCommand());
2189 :
2190 0 : if ( !!aImage )
2191 : {
2192 : pNewEntry = aContentsListBox->InsertEntry(
2193 0 : aName, aImage, aImage, 0, sal_False, nPos, pNewEntryData );
2194 : }
2195 : else
2196 : {
2197 : pNewEntry = aContentsListBox->InsertEntry(
2198 0 : aName, 0, sal_False, nPos, pNewEntryData );
2199 : }
2200 :
2201 0 : if ( pNewEntryData->IsPopup() ||
2202 0 : pNewEntryData->GetStyle() & css::ui::ItemStyle::DROP_DOWN )
2203 : {
2204 : // add new popup painter, it gets destructed by the entry
2205 : pNewEntry->ReplaceItem(
2206 0 : new PopupPainter( pNewEntry, aName ),
2207 0 : pNewEntry->ItemCount() - 1 );
2208 0 : }
2209 : }
2210 :
2211 0 : return pNewEntry;
2212 : }
2213 :
2214 0 : IMPL_LINK( SvxConfigPage, AsyncInfoMsg, String*, pMsg )
2215 : {
2216 : (void)pMsg;
2217 :
2218 : // Asynchronous msg because of D&D
2219 0 : InfoBox( this, CUI_RES(
2220 0 : IBX_MNUCFG_ALREADY_INCLUDED ) ).Execute();
2221 :
2222 0 : return 0;
2223 : }
2224 :
2225 0 : IMPL_LINK( SvxConfigPage, MoveHdl, Button *, pButton )
2226 : {
2227 0 : MoveEntry( pButton == &aMoveUpButton );
2228 0 : return 0;
2229 : }
2230 :
2231 0 : void SvxConfigPage::MoveEntry( bool bMoveUp )
2232 : {
2233 0 : SvTreeListEntry *pSourceEntry = aContentsListBox->FirstSelected();
2234 0 : SvTreeListEntry *pTargetEntry = NULL;
2235 0 : SvTreeListEntry *pToSelect = NULL;
2236 :
2237 0 : if ( !pSourceEntry )
2238 : {
2239 0 : return;
2240 : }
2241 :
2242 0 : if ( bMoveUp )
2243 : {
2244 : // Move Up is just a Move Down with the source and target reversed
2245 0 : pTargetEntry = pSourceEntry;
2246 0 : pSourceEntry = aContentsListBox->PrevSibling( pTargetEntry );
2247 0 : pToSelect = pTargetEntry;
2248 : }
2249 : else
2250 : {
2251 0 : pTargetEntry = aContentsListBox->NextSibling( pSourceEntry );
2252 0 : pToSelect = pSourceEntry;
2253 : }
2254 :
2255 0 : if ( MoveEntryData( pSourceEntry, pTargetEntry ) )
2256 : {
2257 0 : aContentsListBox->GetModel()->Move( pSourceEntry, pTargetEntry );
2258 0 : aContentsListBox->Select( pToSelect );
2259 0 : aContentsListBox->MakeVisible( pToSelect );
2260 :
2261 0 : UpdateButtonStates();
2262 : }
2263 : }
2264 :
2265 0 : bool SvxConfigPage::MoveEntryData(
2266 : SvTreeListEntry* pSourceEntry, SvTreeListEntry* pTargetEntry )
2267 : {
2268 : //modified by shizhoubo for issue53677
2269 0 : if ( NULL == pSourceEntry || NULL == pTargetEntry )
2270 : {
2271 0 : return sal_False;
2272 : }
2273 :
2274 : // Grab the entries list for the currently selected menu
2275 0 : SvxEntries* pEntries = GetTopLevelSelection()->GetEntries();
2276 :
2277 : SvxConfigEntry* pSourceData =
2278 0 : (SvxConfigEntry*) pSourceEntry->GetUserData();
2279 :
2280 0 : if ( pTargetEntry == NULL )
2281 : {
2282 0 : RemoveEntry( pEntries, pSourceData );
2283 : pEntries->insert(
2284 0 : pEntries->begin(), pSourceData );
2285 :
2286 0 : GetSaveInData()->SetModified( sal_True );
2287 :
2288 0 : return sal_True;
2289 : }
2290 : else
2291 : {
2292 : SvxConfigEntry* pTargetData =
2293 0 : (SvxConfigEntry*) pTargetEntry->GetUserData();
2294 :
2295 0 : if ( pSourceData != NULL && pTargetData != NULL )
2296 : {
2297 : // remove the source entry from our list
2298 0 : RemoveEntry( pEntries, pSourceData );
2299 :
2300 0 : SvxEntries::iterator iter = pEntries->begin();
2301 0 : SvxEntries::const_iterator end = pEntries->end();
2302 :
2303 : // advance the iterator to the position of the target entry
2304 0 : while (*iter != pTargetData && ++iter != end) ;
2305 :
2306 : // insert the source entry at the position after the target
2307 0 : pEntries->insert( ++iter, pSourceData );
2308 :
2309 0 : GetSaveInData()->SetModified( sal_True );
2310 :
2311 0 : return sal_True;
2312 : }
2313 : }
2314 :
2315 0 : return sal_False;
2316 : }
2317 :
2318 0 : SvxMenuConfigPage::SvxMenuConfigPage(
2319 : Window *pParent, const SfxItemSet& rSet )
2320 : :
2321 0 : SvxConfigPage( pParent, rSet )
2322 : {
2323 0 : aContentsListBox = new SvxMenuEntriesListBox( this, CUI_RES( BOX_ENTRIES ) );
2324 0 : FreeResource();
2325 :
2326 0 : PositionContentsListBox();
2327 0 : aContentsListBox->SetZOrder( &aAddCommandsButton, WINDOW_ZORDER_BEFOR );
2328 :
2329 : aTopLevelListBox.SetSelectHdl(
2330 0 : LINK( this, SvxMenuConfigPage, SelectMenu ) );
2331 :
2332 : aContentsListBox->SetSelectHdl(
2333 0 : LINK( this, SvxMenuConfigPage, SelectMenuEntry ) );
2334 :
2335 0 : aMoveUpButton.SetClickHdl ( LINK( this, SvxConfigPage, MoveHdl) );
2336 0 : aMoveDownButton.SetClickHdl ( LINK( this, SvxConfigPage, MoveHdl) );
2337 :
2338 : aNewTopLevelButton.SetClickHdl (
2339 0 : LINK( this, SvxMenuConfigPage, NewMenuHdl ) );
2340 :
2341 : aAddCommandsButton.SetClickHdl (
2342 0 : LINK( this, SvxMenuConfigPage, AddCommandsHdl ) );
2343 :
2344 0 : PopupMenu* pMenu = new PopupMenu( CUI_RES( MODIFY_MENU ) );
2345 : pMenu->SetMenuFlags(
2346 0 : pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
2347 :
2348 0 : aModifyTopLevelButton.SetPopupMenu( pMenu );
2349 : aModifyTopLevelButton.SetSelectHdl(
2350 0 : LINK( this, SvxMenuConfigPage, MenuSelectHdl ) );
2351 :
2352 0 : PopupMenu* pEntry = new PopupMenu( CUI_RES( MODIFY_ENTRY ) );
2353 : pEntry->SetMenuFlags(
2354 0 : pEntry->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
2355 :
2356 0 : aModifyCommandButton.SetPopupMenu( pEntry );
2357 : aModifyCommandButton.SetSelectHdl(
2358 0 : LINK( this, SvxMenuConfigPage, EntrySelectHdl ) );
2359 0 : }
2360 :
2361 : // Populates the Menu combo box
2362 0 : void SvxMenuConfigPage::Init()
2363 : {
2364 : // ensure that the UI is cleared before populating it
2365 0 : aTopLevelListBox.Clear();
2366 0 : aContentsListBox->Clear();
2367 :
2368 0 : ReloadTopLevelListBox();
2369 :
2370 0 : aTopLevelListBox.SelectEntryPos(0, sal_True);
2371 0 : aTopLevelListBox.GetSelectHdl().Call(this);
2372 0 : }
2373 :
2374 0 : SvxMenuConfigPage::~SvxMenuConfigPage()
2375 : {
2376 0 : for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); ++i )
2377 : {
2378 : MenuSaveInData* pData =
2379 0 : (MenuSaveInData*) aSaveInListBox.GetEntryData( i );
2380 :
2381 0 : delete pData;
2382 : }
2383 :
2384 0 : if ( pSelectorDlg != NULL )
2385 : {
2386 0 : delete pSelectorDlg;
2387 : }
2388 :
2389 0 : delete aContentsListBox;
2390 0 : }
2391 :
2392 0 : IMPL_LINK( SvxMenuConfigPage, SelectMenuEntry, Control *, pBox )
2393 : {
2394 : (void)pBox;
2395 :
2396 0 : UpdateButtonStates();
2397 :
2398 0 : return 1;
2399 : }
2400 :
2401 0 : void SvxMenuConfigPage::UpdateButtonStates()
2402 : {
2403 0 : PopupMenu* pPopup = aModifyCommandButton.GetPopupMenu();
2404 :
2405 : // Disable Up and Down buttons depending on current selection
2406 0 : SvTreeListEntry* selection = aContentsListBox->GetCurEntry();
2407 :
2408 0 : if ( aContentsListBox->GetEntryCount() == 0 || selection == NULL )
2409 : {
2410 0 : aMoveUpButton.Enable( sal_False );
2411 0 : aMoveDownButton.Enable( sal_False );
2412 :
2413 0 : pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
2414 0 : pPopup->EnableItem( ID_RENAME, sal_False );
2415 0 : pPopup->EnableItem( ID_DELETE, sal_False );
2416 :
2417 0 : aDescriptionField.Clear();
2418 :
2419 0 : return;
2420 : }
2421 :
2422 0 : SvTreeListEntry* first = aContentsListBox->First();
2423 0 : SvTreeListEntry* last = aContentsListBox->Last();
2424 :
2425 0 : aMoveUpButton.Enable( selection != first );
2426 0 : aMoveDownButton.Enable( selection != last );
2427 :
2428 : SvxConfigEntry* pEntryData =
2429 0 : (SvxConfigEntry*) selection->GetUserData();
2430 :
2431 0 : if ( pEntryData->IsSeparator() )
2432 : {
2433 0 : pPopup->EnableItem( ID_DELETE, sal_True );
2434 0 : pPopup->EnableItem( ID_BEGIN_GROUP, sal_False );
2435 0 : pPopup->EnableItem( ID_RENAME, sal_False );
2436 :
2437 0 : aDescriptionField.Clear();
2438 : }
2439 : else
2440 : {
2441 0 : pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
2442 0 : pPopup->EnableItem( ID_DELETE, sal_True );
2443 0 : pPopup->EnableItem( ID_RENAME, sal_True );
2444 :
2445 0 : aDescriptionField.SetNewText( pEntryData->GetHelpText() );
2446 : }
2447 : }
2448 :
2449 0 : void SvxMenuConfigPage::DeleteSelectedTopLevel()
2450 : {
2451 0 : SvxConfigEntry* pMenuData = GetTopLevelSelection();
2452 :
2453 : SvxEntries* pParentEntries =
2454 0 : FindParentForChild( GetSaveInData()->GetEntries(), pMenuData );
2455 :
2456 0 : RemoveEntry( pParentEntries, pMenuData );
2457 0 : delete pMenuData;
2458 :
2459 0 : ReloadTopLevelListBox();
2460 :
2461 0 : GetSaveInData()->SetModified( sal_True );
2462 0 : }
2463 :
2464 0 : bool SvxMenuConfigPage::DeleteSelectedContent()
2465 : {
2466 0 : SvTreeListEntry *pActEntry = aContentsListBox->FirstSelected();
2467 :
2468 0 : if ( pActEntry != NULL )
2469 : {
2470 : // get currently selected menu entry
2471 : SvxConfigEntry* pMenuEntry =
2472 0 : (SvxConfigEntry*) pActEntry->GetUserData();
2473 :
2474 : // get currently selected menu
2475 0 : SvxConfigEntry* pMenu = GetTopLevelSelection();
2476 :
2477 : // remove menu entry from the list for this menu
2478 0 : RemoveEntry( pMenu->GetEntries(), pMenuEntry );
2479 :
2480 : // remove menu entry from UI
2481 0 : aContentsListBox->GetModel()->Remove( pActEntry );
2482 :
2483 : // if this is a submenu entry, redraw the menus list box
2484 0 : if ( pMenuEntry->IsPopup() )
2485 : {
2486 0 : ReloadTopLevelListBox();
2487 : }
2488 :
2489 : // delete data for menu entry
2490 0 : delete pMenuEntry;
2491 :
2492 0 : GetSaveInData()->SetModified( sal_True );
2493 :
2494 0 : return sal_True;
2495 : }
2496 0 : return sal_False;
2497 : }
2498 :
2499 0 : short SvxMenuConfigPage::QueryReset()
2500 : {
2501 : String msg =
2502 0 : String( CUI_RES( RID_SVXSTR_CONFIRM_MENU_RESET ) );
2503 :
2504 : String saveInName = aSaveInListBox.GetEntry(
2505 0 : aSaveInListBox.GetSelectEntryPos() );
2506 :
2507 0 : OUString label = replaceSaveInName( msg, saveInName );
2508 :
2509 0 : QueryBox qbox( this, WB_YES_NO, label );
2510 :
2511 0 : return qbox.Execute();
2512 : }
2513 :
2514 0 : IMPL_LINK( SvxMenuConfigPage, SelectMenu, ListBox *, pBox )
2515 : {
2516 : (void)pBox;
2517 :
2518 0 : aContentsListBox->Clear();
2519 :
2520 0 : SvxConfigEntry* pMenuData = GetTopLevelSelection();
2521 :
2522 0 : PopupMenu* pPopup = aModifyTopLevelButton.GetPopupMenu();
2523 0 : if ( pMenuData )
2524 : {
2525 0 : pPopup->EnableItem( ID_DELETE, pMenuData->IsDeletable() );
2526 0 : pPopup->EnableItem( ID_RENAME, pMenuData->IsRenamable() );
2527 0 : pPopup->EnableItem( ID_MOVE, pMenuData->IsMovable() );
2528 :
2529 0 : SvxEntries* pEntries = pMenuData->GetEntries();
2530 0 : SvxEntries::const_iterator iter = pEntries->begin();
2531 :
2532 0 : for ( ; iter != pEntries->end(); ++iter )
2533 : {
2534 0 : SvxConfigEntry* pEntry = *iter;
2535 0 : InsertEntryIntoUI( pEntry );
2536 : }
2537 : }
2538 :
2539 0 : UpdateButtonStates();
2540 :
2541 0 : return 0;
2542 : }
2543 :
2544 0 : IMPL_LINK( SvxMenuConfigPage, MenuSelectHdl, MenuButton *, pButton )
2545 : {
2546 0 : switch( pButton->GetCurItemId() )
2547 : {
2548 : case ID_DELETE:
2549 : {
2550 0 : DeleteSelectedTopLevel();
2551 0 : break;
2552 : }
2553 : case ID_RENAME:
2554 : {
2555 0 : SvxConfigEntry* pMenuData = GetTopLevelSelection();
2556 :
2557 0 : String aNewName( stripHotKey( pMenuData->GetName() ) );
2558 0 : String aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
2559 :
2560 0 : SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2561 0 : pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_MENU );
2562 0 : pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_MENU ) );
2563 :
2564 0 : bool ret = pNameDialog->Execute();
2565 :
2566 0 : if ( ret == RET_OK ) {
2567 0 : pNameDialog->GetName( aNewName );
2568 0 : pMenuData->SetName( aNewName );
2569 :
2570 0 : ReloadTopLevelListBox();
2571 :
2572 0 : GetSaveInData()->SetModified( sal_True );
2573 : }
2574 :
2575 : // #i68101# Memory leak (!)
2576 0 : delete pNameDialog;
2577 :
2578 0 : break;
2579 : }
2580 : case ID_MOVE:
2581 : {
2582 0 : SvxConfigEntry* pMenuData = GetTopLevelSelection();
2583 :
2584 : SvxMainMenuOrganizerDialog* pDialog =
2585 : new SvxMainMenuOrganizerDialog( this,
2586 0 : GetSaveInData()->GetEntries(), pMenuData );
2587 :
2588 0 : bool ret = pDialog->Execute();
2589 :
2590 0 : if ( ret == RET_OK )
2591 : {
2592 0 : GetSaveInData()->SetEntries( pDialog->GetEntries() );
2593 :
2594 0 : ReloadTopLevelListBox( pDialog->GetSelectedEntry() );
2595 :
2596 0 : GetSaveInData()->SetModified( sal_True );
2597 : }
2598 :
2599 0 : delete pDialog;
2600 :
2601 0 : break;
2602 : }
2603 : default:
2604 0 : return sal_False;
2605 : }
2606 0 : return sal_True;
2607 : }
2608 :
2609 0 : IMPL_LINK( SvxMenuConfigPage, EntrySelectHdl, MenuButton *, pButton )
2610 : {
2611 0 : switch( pButton->GetCurItemId() )
2612 : {
2613 : case ID_ADD_SUBMENU:
2614 : {
2615 0 : String aNewName;
2616 0 : String aDesc = CUI_RESSTR( RID_SVXSTR_SUBMENU_NAME );
2617 :
2618 0 : SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2619 0 : pNameDialog->SetHelpId( HID_SVX_CONFIG_NAME_SUBMENU );
2620 0 : pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_ADD_SUBMENU ) );
2621 :
2622 0 : bool ret = pNameDialog->Execute();
2623 :
2624 0 : if ( ret == RET_OK ) {
2625 0 : pNameDialog->GetName(aNewName);
2626 :
2627 : SvxConfigEntry* pNewEntryData =
2628 0 : new SvxConfigEntry( aNewName, aNewName, sal_True );
2629 0 : pNewEntryData->SetUserDefined( sal_True );
2630 :
2631 0 : InsertEntry( pNewEntryData );
2632 :
2633 0 : ReloadTopLevelListBox();
2634 :
2635 0 : GetSaveInData()->SetModified( sal_True );
2636 : }
2637 :
2638 0 : delete pNameDialog;
2639 :
2640 0 : break;
2641 : }
2642 : case ID_BEGIN_GROUP:
2643 : {
2644 0 : SvxConfigEntry* pNewEntryData = new SvxConfigEntry;
2645 0 : pNewEntryData->SetUserDefined( sal_True );
2646 0 : InsertEntry( pNewEntryData );
2647 :
2648 0 : break;
2649 : }
2650 : case ID_DELETE:
2651 : {
2652 0 : DeleteSelectedContent();
2653 0 : break;
2654 : }
2655 : case ID_RENAME:
2656 : {
2657 0 : SvTreeListEntry* pActEntry = aContentsListBox->GetCurEntry();
2658 : SvxConfigEntry* pEntry =
2659 0 : (SvxConfigEntry*) pActEntry->GetUserData();
2660 :
2661 0 : String aNewName( stripHotKey( pEntry->GetName() ) );
2662 0 : String aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
2663 :
2664 0 : SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
2665 0 : pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_MENU_ITEM );
2666 0 : pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_MENU ) );
2667 :
2668 0 : bool ret = pNameDialog->Execute();
2669 :
2670 0 : if ( ret == RET_OK ) {
2671 0 : pNameDialog->GetName(aNewName);
2672 :
2673 0 : pEntry->SetName( aNewName );
2674 0 : aContentsListBox->SetEntryText( pActEntry, aNewName );
2675 :
2676 0 : GetSaveInData()->SetModified( sal_True );
2677 : }
2678 :
2679 0 : delete pNameDialog;
2680 :
2681 0 : break;
2682 : }
2683 : default:
2684 : {
2685 0 : return sal_False;
2686 : }
2687 : }
2688 :
2689 0 : if ( GetSaveInData()->IsModified() )
2690 : {
2691 0 : UpdateButtonStates();
2692 : }
2693 :
2694 0 : return sal_True;
2695 : }
2696 :
2697 0 : IMPL_LINK( SvxMenuConfigPage, AddFunctionHdl,
2698 : SvxScriptSelectorDialog *, pDialog )
2699 : {
2700 : (void)pDialog;
2701 :
2702 0 : AddFunction();
2703 :
2704 0 : return 0;
2705 : }
2706 :
2707 0 : IMPL_LINK( SvxMenuConfigPage, NewMenuHdl, Button *, pButton )
2708 : {
2709 : (void)pButton;
2710 :
2711 : SvxMainMenuOrganizerDialog* pDialog =
2712 : new SvxMainMenuOrganizerDialog( 0,
2713 0 : GetSaveInData()->GetEntries(), NULL, sal_True );
2714 :
2715 0 : bool ret = pDialog->Execute();
2716 :
2717 0 : if ( ret == RET_OK )
2718 : {
2719 0 : GetSaveInData()->SetEntries( pDialog->GetEntries() );
2720 0 : ReloadTopLevelListBox( pDialog->GetSelectedEntry() );
2721 0 : GetSaveInData()->SetModified( sal_True );
2722 : }
2723 :
2724 0 : delete pDialog;
2725 :
2726 0 : return 0;
2727 : }
2728 :
2729 0 : IMPL_LINK( SvxMenuConfigPage, AddCommandsHdl, Button *, pButton )
2730 : {
2731 : (void)pButton;
2732 :
2733 0 : if ( pSelectorDlg == NULL )
2734 : {
2735 : // Create Script Selector which also shows builtin commands
2736 0 : pSelectorDlg = new SvxScriptSelectorDialog( this, sal_True, m_xFrame );
2737 :
2738 : pSelectorDlg->SetAddHdl(
2739 0 : LINK( this, SvxMenuConfigPage, AddFunctionHdl ) );
2740 :
2741 : pSelectorDlg->SetDialogDescription( String(
2742 0 : CUI_RES( RID_SVXSTR_MENU_ADDCOMMANDS_DESCRIPTION ) ) );
2743 : }
2744 :
2745 : // Position the Script Selector over the Add button so it is
2746 : // beside the menu contents list and does not obscure it
2747 0 : pSelectorDlg->SetPosPixel( aAddCommandsButton.GetPosPixel() );
2748 :
2749 : pSelectorDlg->SetImageProvider(
2750 0 : static_cast< ImageProvider* >( GetSaveInData() ) );
2751 :
2752 0 : pSelectorDlg->Show();
2753 0 : return 1;
2754 : }
2755 :
2756 0 : SaveInData* SvxMenuConfigPage::CreateSaveInData(
2757 : const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
2758 : const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
2759 : const OUString& aModuleId,
2760 : bool bDocConfig )
2761 : {
2762 : return static_cast< SaveInData* >(
2763 0 : new MenuSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ));
2764 : }
2765 :
2766 0 : SvxMainMenuOrganizerDialog::SvxMainMenuOrganizerDialog(
2767 : Window* pParent, SvxEntries* entries,
2768 : SvxConfigEntry* selection, bool bCreateMenu )
2769 : :
2770 0 : ModalDialog( pParent, CUI_RES( MD_MENU_ORGANISER ) ),
2771 0 : aMenuNameText( this, CUI_RES( TXT_MENU_NAME ) ),
2772 0 : aMenuNameEdit( this, CUI_RES( EDIT_MENU_NAME ) ),
2773 0 : aMenuListText( this, CUI_RES( TXT_MENU ) ),
2774 0 : aMenuListBox( this, CUI_RES( BOX_MAIN_MENUS ) ),
2775 0 : aMoveUpButton( this, CUI_RES( BTN_MENU_UP ) ),
2776 0 : aMoveDownButton( this, CUI_RES( BTN_MENU_DOWN ) ),
2777 0 : aOKButton( this, CUI_RES( BTN_MENU_ADD ) ),
2778 0 : aCloseButton( this, CUI_RES( BTN_MENU_CLOSE ) ),
2779 0 : aHelpButton( this, CUI_RES( BTN_MENU_HELP ) ),
2780 0 : bModified( sal_False )
2781 : {
2782 0 : FreeResource();
2783 :
2784 : // Copy the entries list passed in
2785 0 : if ( entries != NULL )
2786 : {
2787 : SvxConfigEntry* pEntry;
2788 : SvTreeListEntry* pLBEntry;
2789 :
2790 0 : pEntries = new SvxEntries();
2791 0 : SvxEntries::const_iterator iter = entries->begin();
2792 :
2793 0 : while ( iter != entries->end() )
2794 : {
2795 0 : pEntry = *iter;
2796 : pLBEntry =
2797 0 : aMenuListBox.InsertEntry( stripHotKey( pEntry->GetName() ) );
2798 0 : pLBEntry->SetUserData( pEntry );
2799 0 : pEntries->push_back( pEntry );
2800 :
2801 0 : if ( pEntry == selection )
2802 : {
2803 0 : aMenuListBox.Select( pLBEntry );
2804 : }
2805 0 : ++iter;
2806 : }
2807 : }
2808 :
2809 0 : if ( bCreateMenu )
2810 : {
2811 : // Generate custom name for new menu
2812 : String prefix =
2813 0 : String( CUI_RES( RID_SVXSTR_NEW_MENU ) );
2814 :
2815 0 : OUString newname = generateCustomName( prefix, entries );
2816 0 : OUString newurl = generateCustomMenuURL( pEntries );
2817 :
2818 : SvxConfigEntry* pNewEntryData =
2819 0 : new SvxConfigEntry( newname, newurl, sal_True );
2820 0 : pNewEntryData->SetUserDefined( sal_True );
2821 0 : pNewEntryData->SetMain( sal_True );
2822 :
2823 : pNewMenuEntry =
2824 0 : aMenuListBox.InsertEntry( stripHotKey( pNewEntryData->GetName() ) );
2825 0 : aMenuListBox.Select( pNewMenuEntry );
2826 :
2827 0 : pNewMenuEntry->SetUserData( pNewEntryData );
2828 :
2829 0 : pEntries->push_back( pNewEntryData );
2830 :
2831 0 : aMenuNameEdit.SetText( newname );
2832 : aMenuNameEdit.SetModifyHdl(
2833 0 : LINK( this, SvxMainMenuOrganizerDialog, ModifyHdl ) );
2834 : }
2835 : else
2836 : {
2837 0 : Point p, newp;
2838 0 : Size s, news;
2839 :
2840 : // get offset to bottom of name textfield from top of dialog
2841 0 : p = aMenuNameEdit.GetPosPixel();
2842 0 : s = aMenuNameEdit.GetSizePixel();
2843 0 : long offset = p.Y() + s.Height();
2844 :
2845 : // reposition menu list and label
2846 0 : aMenuListText.SetPosPixel( aMenuNameText.GetPosPixel() );
2847 0 : aMenuListBox.SetPosPixel( aMenuNameEdit.GetPosPixel() );
2848 :
2849 : // reposition up and down buttons
2850 0 : p = aMoveUpButton.GetPosPixel();
2851 0 : newp = Point( p.X(), p.Y() - offset );
2852 0 : aMoveUpButton.SetPosPixel( newp );
2853 :
2854 0 : p = aMoveDownButton.GetPosPixel();
2855 0 : newp = Point( p.X(), p.Y() - offset );
2856 0 : aMoveDownButton.SetPosPixel( newp );
2857 :
2858 : // change size of dialog
2859 0 : s = GetSizePixel();
2860 0 : news = Size( s.Width(), s.Height() - offset );
2861 0 : SetSizePixel( news );
2862 :
2863 : // hide name label and textfield
2864 0 : aMenuNameText.Hide();
2865 0 : aMenuNameEdit.Hide();
2866 :
2867 : // change the title
2868 0 : SetText( CUI_RES( RID_SVXSTR_MOVE_MENU ) );
2869 : }
2870 :
2871 : aMenuListBox.SetSelectHdl(
2872 0 : LINK( this, SvxMainMenuOrganizerDialog, SelectHdl ) );
2873 :
2874 : aMoveUpButton.SetClickHdl (
2875 0 : LINK( this, SvxMainMenuOrganizerDialog, MoveHdl) );
2876 : aMoveDownButton.SetClickHdl (
2877 0 : LINK( this, SvxMainMenuOrganizerDialog, MoveHdl) );
2878 :
2879 0 : aMoveUpButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_UP)));
2880 0 : aMoveDownButton.SetAccessibleName(String(CUI_RES(BUTTON_STR_DOWN)));
2881 0 : }
2882 :
2883 0 : IMPL_LINK(SvxMainMenuOrganizerDialog, ModifyHdl, Edit*, pEdit)
2884 : {
2885 : (void)pEdit;
2886 :
2887 : // if the Edit control is empty do not change the name
2888 0 : if ( aMenuNameEdit.GetText().Equals( String() ) )
2889 : {
2890 0 : return 0;
2891 : }
2892 :
2893 : SvxConfigEntry* pNewEntryData =
2894 0 : (SvxConfigEntry*) pNewMenuEntry->GetUserData();
2895 :
2896 0 : pNewEntryData->SetName( aMenuNameEdit.GetText() );
2897 :
2898 0 : aMenuListBox.SetEntryText( pNewMenuEntry, pNewEntryData->GetName() );
2899 :
2900 0 : return 0;
2901 : }
2902 :
2903 0 : SvxMainMenuOrganizerDialog::~SvxMainMenuOrganizerDialog()
2904 : {
2905 0 : }
2906 :
2907 0 : IMPL_LINK( SvxMainMenuOrganizerDialog, SelectHdl, Control*, pCtrl )
2908 : {
2909 : (void)pCtrl;
2910 0 : UpdateButtonStates();
2911 0 : return 1;
2912 : }
2913 :
2914 0 : void SvxMainMenuOrganizerDialog::UpdateButtonStates()
2915 : {
2916 : // Disable Up and Down buttons depending on current selection
2917 0 : SvTreeListEntry* selection = aMenuListBox.GetCurEntry();
2918 0 : SvTreeListEntry* first = aMenuListBox.First();
2919 0 : SvTreeListEntry* last = aMenuListBox.Last();
2920 :
2921 0 : aMoveUpButton.Enable( selection != first );
2922 0 : aMoveDownButton.Enable( selection != last );
2923 0 : }
2924 :
2925 0 : IMPL_LINK( SvxMainMenuOrganizerDialog, MoveHdl, Button *, pButton )
2926 : {
2927 0 : SvTreeListEntry *pSourceEntry = aMenuListBox.FirstSelected();
2928 0 : SvTreeListEntry *pTargetEntry = NULL;
2929 :
2930 0 : if ( !pSourceEntry )
2931 : {
2932 0 : return 0;
2933 : }
2934 :
2935 0 : if ( pButton == &aMoveDownButton )
2936 : {
2937 0 : pTargetEntry = aMenuListBox.NextSibling( pSourceEntry );
2938 : }
2939 0 : else if ( pButton == &aMoveUpButton )
2940 : {
2941 : // Move Up is just a Move Down with the source and target reversed
2942 0 : pTargetEntry = pSourceEntry;
2943 0 : pSourceEntry = aMenuListBox.PrevSibling( pTargetEntry );
2944 : }
2945 :
2946 0 : if ( pSourceEntry != NULL && pTargetEntry != NULL )
2947 : {
2948 : SvxConfigEntry* pSourceData =
2949 0 : (SvxConfigEntry*) pSourceEntry->GetUserData();
2950 : SvxConfigEntry* pTargetData =
2951 0 : (SvxConfigEntry*) pTargetEntry->GetUserData();
2952 :
2953 0 : SvxEntries::iterator iter1 = GetEntries()->begin();
2954 0 : SvxEntries::iterator iter2 = GetEntries()->begin();
2955 0 : SvxEntries::const_iterator end = GetEntries()->end();
2956 :
2957 : // Advance the iterators to the positions of the source and target
2958 0 : while (*iter1 != pSourceData && ++iter1 != end) ;
2959 0 : while (*iter2 != pTargetData && ++iter2 != end) ;
2960 :
2961 : // Now swap the entries in the menu list and in the UI
2962 0 : if ( iter1 != end && iter2 != end )
2963 : {
2964 0 : std::swap( *iter1, *iter2 );
2965 0 : aMenuListBox.GetModel()->Move( pSourceEntry, pTargetEntry );
2966 0 : aMenuListBox.MakeVisible( pSourceEntry );
2967 :
2968 0 : bModified = sal_True;
2969 : }
2970 : }
2971 :
2972 0 : if ( bModified )
2973 : {
2974 0 : UpdateButtonStates();
2975 : }
2976 :
2977 0 : return 0;
2978 : }
2979 :
2980 0 : SvxEntries* SvxMainMenuOrganizerDialog::GetEntries()
2981 : {
2982 0 : return pEntries;
2983 : }
2984 :
2985 0 : SvxConfigEntry* SvxMainMenuOrganizerDialog::GetSelectedEntry()
2986 : {
2987 0 : return (SvxConfigEntry*)aMenuListBox.FirstSelected()->GetUserData();
2988 : }
2989 :
2990 : const OUString&
2991 0 : SvxConfigEntry::GetHelpText()
2992 : {
2993 0 : if ( aHelpText.isEmpty() )
2994 : {
2995 0 : if ( !aCommand.isEmpty() )
2996 : {
2997 0 : aHelpText = Application::GetHelp()->GetHelpText( aCommand, NULL );
2998 : }
2999 : }
3000 :
3001 0 : return aHelpText;
3002 : }
3003 :
3004 0 : SvxConfigEntry::SvxConfigEntry( const OUString& rDisplayName,
3005 : const OUString& rCommandURL, bool bPopup, bool bParentData )
3006 : : nId( 1 )
3007 : , aLabel(rDisplayName)
3008 : , aCommand(rCommandURL)
3009 : , bPopUp(bPopup)
3010 : , bStrEdited( sal_False )
3011 : , bIsUserDefined( sal_False )
3012 : , bIsMain( sal_False )
3013 : , bIsParentData( bParentData )
3014 : , bIsVisible( sal_True )
3015 : , nStyle( 0 )
3016 0 : , pEntries( 0 )
3017 : {
3018 0 : if (bPopUp)
3019 : {
3020 0 : pEntries = new SvxEntries();
3021 : }
3022 0 : }
3023 :
3024 0 : SvxConfigEntry::~SvxConfigEntry()
3025 : {
3026 0 : if ( pEntries != NULL )
3027 : {
3028 0 : SvxEntries::const_iterator iter = pEntries->begin();
3029 :
3030 0 : for ( ; iter != pEntries->end(); ++iter )
3031 : {
3032 0 : delete *iter;
3033 : }
3034 0 : delete pEntries;
3035 : }
3036 0 : }
3037 :
3038 0 : bool SvxConfigEntry::IsMovable()
3039 : {
3040 0 : if ( IsPopup() && !IsMain() )
3041 : {
3042 0 : return sal_False;
3043 : }
3044 0 : return sal_True;
3045 : }
3046 :
3047 0 : bool SvxConfigEntry::IsDeletable()
3048 : {
3049 0 : if ( IsMain() && !IsUserDefined() )
3050 : {
3051 0 : return sal_False;
3052 : }
3053 0 : return sal_True;
3054 : }
3055 :
3056 0 : bool SvxConfigEntry::IsRenamable()
3057 : {
3058 0 : if ( IsMain() && !IsUserDefined() )
3059 : {
3060 0 : return sal_False;
3061 : }
3062 0 : return sal_True;
3063 : }
3064 :
3065 0 : SvxToolbarConfigPage::SvxToolbarConfigPage(
3066 : Window *pParent, const SfxItemSet& rSet )
3067 : :
3068 0 : SvxConfigPage( pParent, rSet )
3069 : {
3070 0 : SetHelpId( HID_SVX_CONFIG_TOOLBAR );
3071 :
3072 0 : aContentsListBox = new SvxToolbarEntriesListBox(this, CUI_RES(BOX_ENTRIES));
3073 0 : FreeResource();
3074 0 : PositionContentsListBox();
3075 0 : aContentsListBox->SetZOrder( &aAddCommandsButton, WINDOW_ZORDER_BEFOR );
3076 :
3077 0 : aContentsListBox->SetHelpId( HID_SVX_CONFIG_TOOLBAR_CONTENTS );
3078 0 : aNewTopLevelButton.SetHelpId( HID_SVX_NEW_TOOLBAR );
3079 0 : aModifyTopLevelButton.SetHelpId( HID_SVX_MODIFY_TOOLBAR );
3080 0 : aAddCommandsButton.SetHelpId( HID_SVX_NEW_TOOLBAR_ITEM );
3081 0 : aModifyCommandButton.SetHelpId( HID_SVX_MODIFY_TOOLBAR_ITEM );
3082 0 : aSaveInListBox.SetHelpId( HID_SVX_SAVE_IN );
3083 :
3084 : aTopLevelSeparator.SetText(
3085 0 : CUI_RES ( RID_SVXSTR_PRODUCTNAME_TOOLBARS ) );
3086 :
3087 0 : aTopLevelLabel.SetText( CUI_RES( RID_SVXSTR_TOOLBAR ) );
3088 0 : aModifyTopLevelButton.SetText( CUI_RES( RID_SVXSTR_TOOLBAR ) );
3089 0 : aContentsSeparator.SetText( CUI_RES( RID_SVXSTR_TOOLBAR_CONTENT ) );
3090 0 : aContentsLabel.SetText( CUI_RES( RID_SVXSTR_COMMANDS ) );
3091 :
3092 : aTopLevelListBox.SetSelectHdl(
3093 0 : LINK( this, SvxToolbarConfigPage, SelectToolbar ) );
3094 : aContentsListBox->SetSelectHdl(
3095 0 : LINK( this, SvxToolbarConfigPage, SelectToolbarEntry ) );
3096 :
3097 : aNewTopLevelButton.SetClickHdl (
3098 0 : LINK( this, SvxToolbarConfigPage, NewToolbarHdl ) );
3099 :
3100 : aAddCommandsButton.SetClickHdl (
3101 0 : LINK( this, SvxToolbarConfigPage, AddCommandsHdl ) );
3102 :
3103 0 : aMoveUpButton.SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) );
3104 0 : aMoveDownButton.SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) );
3105 : // Always enable Up and Down buttons
3106 : // added for issue i53677 by shizhoubo
3107 0 : aMoveDownButton.Enable( sal_True );
3108 0 : aMoveUpButton.Enable( sal_True );
3109 :
3110 0 : PopupMenu* pMenu = new PopupMenu( CUI_RES( MODIFY_TOOLBAR ) );
3111 : pMenu->SetMenuFlags(
3112 0 : pMenu->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
3113 :
3114 0 : aModifyTopLevelButton.SetPopupMenu( pMenu );
3115 : aModifyTopLevelButton.SetSelectHdl(
3116 0 : LINK( this, SvxToolbarConfigPage, ToolbarSelectHdl ) );
3117 :
3118 : PopupMenu* pEntry = new PopupMenu(
3119 0 : CUI_RES( MODIFY_TOOLBAR_CONTENT ) );
3120 : pEntry->SetMenuFlags(
3121 0 : pEntry->GetMenuFlags() | MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES );
3122 :
3123 0 : aModifyCommandButton.SetPopupMenu( pEntry );
3124 : aModifyCommandButton.SetSelectHdl(
3125 0 : LINK( this, SvxToolbarConfigPage, EntrySelectHdl ) );
3126 :
3127 : // default toolbar to select is standardbar unless a different one
3128 : // has been passed in
3129 0 : m_aURLToSelect = OUString(ITEM_TOOLBAR_URL );
3130 0 : m_aURLToSelect += OUString("standardbar" );
3131 :
3132 : const SfxPoolItem* pItem =
3133 0 : rSet.GetItem( rSet.GetPool()->GetWhich( SID_CONFIG ) );
3134 :
3135 0 : if ( pItem )
3136 : {
3137 0 : OUString text = ((const SfxStringItem*)pItem)->GetValue();
3138 0 : if (text.indexOf( ITEM_TOOLBAR_URL ) == 0)
3139 : {
3140 0 : m_aURLToSelect = text.copy( 0 );
3141 0 : }
3142 : }
3143 :
3144 0 : long nTxtW = aTopLevelLabel.GetCtrlTextWidth( aTopLevelLabel.GetText() );
3145 0 : long nCtrlW = aTopLevelLabel.GetSizePixel().Width();
3146 0 : if ( nTxtW >= nCtrlW )
3147 : {
3148 0 : long nDelta = Max( (long)10, nTxtW - nCtrlW );
3149 0 : Size aNewSz = aTopLevelLabel.GetSizePixel();
3150 0 : aNewSz.Width() += nDelta;
3151 0 : aTopLevelLabel.SetSizePixel( aNewSz );
3152 0 : aNewSz = aTopLevelListBox.GetSizePixel();
3153 0 : aNewSz.Width() -= nDelta;
3154 0 : Point aNewPt = aTopLevelListBox.GetPosPixel();
3155 0 : aNewPt.X() += nDelta;
3156 0 : aTopLevelListBox.SetPosSizePixel( aNewPt, aNewSz );
3157 : }
3158 0 : }
3159 :
3160 0 : SvxToolbarConfigPage::~SvxToolbarConfigPage()
3161 : {
3162 0 : for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); ++i )
3163 : {
3164 : ToolbarSaveInData* pData =
3165 0 : (ToolbarSaveInData*) aSaveInListBox.GetEntryData( i );
3166 :
3167 0 : delete pData;
3168 : }
3169 :
3170 0 : if ( pSelectorDlg != NULL )
3171 : {
3172 0 : delete pSelectorDlg;
3173 : }
3174 :
3175 :
3176 0 : delete aContentsListBox;
3177 0 : }
3178 :
3179 0 : void SvxToolbarConfigPage::DeleteSelectedTopLevel()
3180 : {
3181 0 : sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
3182 0 : ToolbarSaveInData* pSaveInData = (ToolbarSaveInData*) GetSaveInData();
3183 0 : pSaveInData->RemoveToolbar( GetTopLevelSelection() );
3184 :
3185 0 : if ( aTopLevelListBox.GetEntryCount() > 1 )
3186 : {
3187 : // select next entry after the one being deleted
3188 : // selection position is indexed from 0 so need to
3189 : // subtract one from the entry count
3190 0 : if ( nSelectionPos != aTopLevelListBox.GetEntryCount() - 1 )
3191 : {
3192 0 : aTopLevelListBox.SelectEntryPos( nSelectionPos + 1, sal_True );
3193 : }
3194 : else
3195 : {
3196 0 : aTopLevelListBox.SelectEntryPos( nSelectionPos - 1, sal_True );
3197 : }
3198 0 : aTopLevelListBox.GetSelectHdl().Call( this );
3199 :
3200 : // and now remove the entry
3201 0 : aTopLevelListBox.RemoveEntry( nSelectionPos );
3202 : }
3203 : else
3204 : {
3205 0 : ReloadTopLevelListBox();
3206 : }
3207 0 : }
3208 :
3209 0 : bool SvxToolbarConfigPage::DeleteSelectedContent()
3210 : {
3211 0 : SvTreeListEntry *pActEntry = aContentsListBox->FirstSelected();
3212 :
3213 0 : if ( pActEntry != NULL )
3214 : {
3215 : // get currently selected entry
3216 : SvxConfigEntry* pEntry =
3217 0 : (SvxConfigEntry*) pActEntry->GetUserData();
3218 :
3219 0 : SvxConfigEntry* pToolbar = GetTopLevelSelection();
3220 :
3221 : // remove entry from the list for this toolbar
3222 0 : RemoveEntry( pToolbar->GetEntries(), pEntry );
3223 :
3224 : // remove toolbar entry from UI
3225 0 : aContentsListBox->GetModel()->Remove( pActEntry );
3226 :
3227 : // delete data for toolbar entry
3228 0 : delete pEntry;
3229 :
3230 0 : (( ToolbarSaveInData* ) GetSaveInData())->ApplyToolbar( pToolbar );
3231 0 : UpdateButtonStates();
3232 :
3233 : // if this is the last entry in the toolbar and it is a user
3234 : // defined toolbar pop up a dialog asking the user if they
3235 : // want to delete the toolbar
3236 0 : if ( aContentsListBox->GetEntryCount() == 0 &&
3237 0 : GetTopLevelSelection()->IsDeletable() )
3238 : {
3239 : QueryBox qbox( this,
3240 0 : CUI_RES( QBX_CONFIRM_DELETE_TOOLBAR ) );
3241 :
3242 0 : if ( qbox.Execute() == RET_YES )
3243 : {
3244 0 : DeleteSelectedTopLevel();
3245 0 : }
3246 : }
3247 :
3248 0 : return sal_True;
3249 : }
3250 :
3251 0 : return sal_False;
3252 : }
3253 :
3254 0 : IMPL_LINK( SvxToolbarConfigPage, MoveHdl, Button *, pButton )
3255 : {
3256 0 : MoveEntry( pButton == &aMoveUpButton );
3257 0 : return 0;
3258 : }
3259 :
3260 0 : void SvxToolbarConfigPage::MoveEntry( bool bMoveUp )
3261 : {
3262 0 : SvxConfigPage::MoveEntry( bMoveUp );
3263 :
3264 : // Apply change to currently selected toolbar
3265 0 : SvxConfigEntry* pToolbar = GetTopLevelSelection();
3266 0 : if ( pToolbar )
3267 0 : ((ToolbarSaveInData*)GetSaveInData())->ApplyToolbar( pToolbar );
3268 : else
3269 : {
3270 : SAL_WARN( "cui.customize", "SvxToolbarConfigPage::MoveEntry(): no entry" );
3271 0 : UpdateButtonStates();
3272 : }
3273 0 : }
3274 :
3275 0 : IMPL_LINK( SvxToolbarConfigPage, ToolbarSelectHdl, MenuButton *, pButton )
3276 : {
3277 0 : sal_uInt16 nSelectionPos = aTopLevelListBox.GetSelectEntryPos();
3278 :
3279 : SvxConfigEntry* pToolbar =
3280 0 : (SvxConfigEntry*)aTopLevelListBox.GetEntryData( nSelectionPos );
3281 :
3282 0 : ToolbarSaveInData* pSaveInData = (ToolbarSaveInData*) GetSaveInData();
3283 :
3284 0 : switch( pButton->GetCurItemId() )
3285 : {
3286 : case ID_DELETE:
3287 : {
3288 0 : DeleteSelectedTopLevel();
3289 0 : UpdateButtonStates();
3290 0 : break;
3291 : }
3292 : case ID_RENAME:
3293 : {
3294 0 : String aNewName( stripHotKey( pToolbar->GetName() ) );
3295 0 : String aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
3296 :
3297 0 : SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
3298 0 : pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR );
3299 0 : pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_TOOLBAR ) );
3300 :
3301 0 : bool ret = pNameDialog->Execute();
3302 :
3303 0 : if ( ret == RET_OK )
3304 : {
3305 0 : pNameDialog->GetName(aNewName);
3306 :
3307 0 : pToolbar->SetName( aNewName );
3308 0 : pSaveInData->ApplyToolbar( pToolbar );
3309 :
3310 : // have to use remove and insert to change the name
3311 0 : aTopLevelListBox.RemoveEntry( nSelectionPos );
3312 : nSelectionPos =
3313 0 : aTopLevelListBox.InsertEntry( aNewName, nSelectionPos );
3314 0 : aTopLevelListBox.SetEntryData( nSelectionPos, pToolbar );
3315 0 : aTopLevelListBox.SelectEntryPos( nSelectionPos );
3316 : }
3317 :
3318 0 : delete pNameDialog;
3319 :
3320 0 : break;
3321 : }
3322 : case ID_DEFAULT_STYLE:
3323 : {
3324 : QueryBox qbox( this,
3325 0 : CUI_RES( QBX_CONFIRM_RESTORE_DEFAULT ) );
3326 :
3327 0 : if ( qbox.Execute() == RET_YES )
3328 : {
3329 : ToolbarSaveInData* pSaveInData_ =
3330 0 : (ToolbarSaveInData*) GetSaveInData();
3331 :
3332 0 : pSaveInData_->RestoreToolbar( pToolbar );
3333 :
3334 0 : aTopLevelListBox.GetSelectHdl().Call( this );
3335 : }
3336 :
3337 0 : break;
3338 : }
3339 : case ID_ICONS_ONLY:
3340 : {
3341 0 : pToolbar->SetStyle( 0 );
3342 0 : pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 0 );
3343 :
3344 0 : aTopLevelListBox.GetSelectHdl().Call( this );
3345 :
3346 0 : break;
3347 : }
3348 : case ID_TEXT_ONLY:
3349 : {
3350 0 : pToolbar->SetStyle( 1 );
3351 0 : pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 1 );
3352 :
3353 0 : aTopLevelListBox.GetSelectHdl().Call( this );
3354 :
3355 0 : break;
3356 : }
3357 : case ID_ICONS_AND_TEXT:
3358 : {
3359 0 : pToolbar->SetStyle( 2 );
3360 0 : pSaveInData->SetSystemStyle( m_xFrame, pToolbar->GetCommand(), 2 );
3361 :
3362 0 : aTopLevelListBox.GetSelectHdl().Call( this );
3363 :
3364 0 : break;
3365 : }
3366 : }
3367 0 : return 1;
3368 : }
3369 :
3370 0 : IMPL_LINK( SvxToolbarConfigPage, EntrySelectHdl, MenuButton *, pButton )
3371 : {
3372 0 : bool bNeedsApply = sal_False;
3373 :
3374 : // get currently selected toolbar
3375 0 : SvxConfigEntry* pToolbar = GetTopLevelSelection();
3376 :
3377 0 : switch( pButton->GetCurItemId() )
3378 : {
3379 : case ID_RENAME:
3380 : {
3381 0 : SvTreeListEntry* pActEntry = aContentsListBox->GetCurEntry();
3382 : SvxConfigEntry* pEntry =
3383 0 : (SvxConfigEntry*) pActEntry->GetUserData();
3384 :
3385 0 : String aNewName( stripHotKey( pEntry->GetName() ) );
3386 0 : String aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
3387 :
3388 0 : SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
3389 0 : pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR_ITEM );
3390 0 : pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_TOOLBAR ) );
3391 :
3392 0 : bool ret = pNameDialog->Execute();
3393 :
3394 0 : if ( ret == RET_OK ) {
3395 0 : pNameDialog->GetName(aNewName);
3396 :
3397 0 : pEntry->SetName( aNewName );
3398 0 : aContentsListBox->SetEntryText( pActEntry, aNewName );
3399 :
3400 0 : bNeedsApply = sal_True;
3401 : }
3402 :
3403 0 : delete pNameDialog;
3404 0 : break;
3405 : }
3406 : case ID_DEFAULT_COMMAND:
3407 : {
3408 0 : SvTreeListEntry* pActEntry = aContentsListBox->GetCurEntry();
3409 : SvxConfigEntry* pEntry =
3410 0 : (SvxConfigEntry*) pActEntry->GetUserData();
3411 :
3412 0 : sal_uInt16 nSelectionPos = 0;
3413 :
3414 : // find position of entry within the list
3415 0 : for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); ++i )
3416 : {
3417 0 : if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3418 : {
3419 0 : nSelectionPos = i;
3420 0 : break;
3421 : }
3422 : }
3423 :
3424 : ToolbarSaveInData* pSaveInData =
3425 0 : (ToolbarSaveInData*) GetSaveInData();
3426 :
3427 : OUString aSystemName =
3428 0 : pSaveInData->GetSystemUIName( pEntry->GetCommand() );
3429 :
3430 0 : if ( !pEntry->GetName().equals( aSystemName ) )
3431 : {
3432 0 : pEntry->SetName( aSystemName );
3433 : aContentsListBox->SetEntryText(
3434 0 : pActEntry, stripHotKey( aSystemName ) );
3435 0 : bNeedsApply = sal_True;
3436 : }
3437 :
3438 0 : uno::Sequence< OUString > aURLSeq( 1 );
3439 0 : aURLSeq[ 0 ] = pEntry->GetCommand();
3440 :
3441 : try
3442 : {
3443 0 : GetSaveInData()->GetImageManager()->removeImages(
3444 0 : GetImageType(), aURLSeq );
3445 :
3446 : // reset backup in entry
3447 : pEntry->SetBackupGraphic(
3448 0 : uno::Reference< graphic::XGraphic >() );
3449 :
3450 : GetSaveInData()->PersistChanges(
3451 0 : GetSaveInData()->GetImageManager() );
3452 :
3453 0 : aContentsListBox->GetModel()->Remove( pActEntry );
3454 :
3455 : SvTreeListEntry* pNewLBEntry =
3456 0 : InsertEntryIntoUI( pEntry, nSelectionPos );
3457 :
3458 : aContentsListBox->SetCheckButtonState( pNewLBEntry,
3459 0 : pEntry->IsVisible() ?
3460 0 : SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3461 :
3462 0 : aContentsListBox->Select( pNewLBEntry );
3463 0 : aContentsListBox->MakeVisible( pNewLBEntry );
3464 :
3465 0 : bNeedsApply = sal_True;
3466 : }
3467 0 : catch ( uno::Exception& )
3468 : {
3469 : OSL_TRACE("Error restoring image");
3470 : }
3471 0 : break;
3472 : }
3473 : case ID_BEGIN_GROUP:
3474 : {
3475 0 : SvxConfigEntry* pNewEntryData = new SvxConfigEntry;
3476 0 : pNewEntryData->SetUserDefined( sal_True );
3477 :
3478 0 : SvTreeListEntry* pNewLBEntry = InsertEntry( pNewEntryData );
3479 :
3480 : aContentsListBox->SetCheckButtonState(
3481 0 : pNewLBEntry, SV_BUTTON_TRISTATE );
3482 :
3483 0 : bNeedsApply = sal_True;
3484 0 : break;
3485 : }
3486 : case ID_DELETE:
3487 : {
3488 0 : DeleteSelectedContent();
3489 0 : break;
3490 : }
3491 : case ID_ICON_ONLY:
3492 : {
3493 0 : break;
3494 : }
3495 : case ID_TEXT_ONLY:
3496 : {
3497 0 : break;
3498 : }
3499 : case ID_ICON_AND_TEXT:
3500 : {
3501 0 : break;
3502 : }
3503 : case ID_CHANGE_SYMBOL:
3504 : {
3505 0 : SvTreeListEntry* pActEntry = aContentsListBox->GetCurEntry();
3506 : SvxConfigEntry* pEntry =
3507 0 : (SvxConfigEntry*) pActEntry->GetUserData();
3508 :
3509 0 : sal_uInt16 nSelectionPos = 0;
3510 :
3511 : // find position of entry within the list
3512 0 : for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); ++i )
3513 : {
3514 0 : if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3515 : {
3516 0 : nSelectionPos = i;
3517 0 : break;
3518 : }
3519 : }
3520 :
3521 : SvxIconSelectorDialog* pIconDialog =
3522 : new SvxIconSelectorDialog( 0,
3523 : GetSaveInData()->GetImageManager(),
3524 0 : GetSaveInData()->GetParentImageManager() );
3525 :
3526 0 : bool ret = pIconDialog->Execute();
3527 :
3528 0 : if ( ret == RET_OK )
3529 : {
3530 : uno::Reference< graphic::XGraphic > newgraphic =
3531 0 : pIconDialog->GetSelectedIcon();
3532 :
3533 0 : if ( newgraphic.is() )
3534 : {
3535 : uno::Sequence< uno::Reference< graphic::XGraphic > >
3536 0 : aGraphicSeq( 1 );
3537 :
3538 0 : uno::Sequence< OUString > aURLSeq( 1 );
3539 0 : aURLSeq[ 0 ] = pEntry->GetCommand();
3540 :
3541 0 : if ( !pEntry->GetBackupGraphic().is() )
3542 : {
3543 0 : uno::Reference< graphic::XGraphic > backup;
3544 : backup = GetGraphic(
3545 0 : GetSaveInData()->GetImageManager(), aURLSeq[ 0 ] );
3546 :
3547 0 : if ( backup.is() )
3548 : {
3549 0 : pEntry->SetBackupGraphic( backup );
3550 0 : }
3551 : }
3552 :
3553 0 : aGraphicSeq[ 0 ] = newgraphic;
3554 : try
3555 : {
3556 0 : GetSaveInData()->GetImageManager()->replaceImages(
3557 0 : GetImageType(), aURLSeq, aGraphicSeq );
3558 :
3559 0 : Image aImage( newgraphic );
3560 :
3561 0 : aContentsListBox->GetModel()->Remove( pActEntry );
3562 : SvTreeListEntry* pNewLBEntry =
3563 0 : InsertEntryIntoUI( pEntry, nSelectionPos );
3564 :
3565 : aContentsListBox->SetCheckButtonState( pNewLBEntry,
3566 0 : pEntry->IsVisible() ?
3567 0 : SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3568 :
3569 0 : aContentsListBox->Select( pNewLBEntry );
3570 0 : aContentsListBox->MakeVisible( pNewLBEntry );
3571 :
3572 : GetSaveInData()->PersistChanges(
3573 0 : GetSaveInData()->GetImageManager() );
3574 : }
3575 0 : catch ( uno::Exception& )
3576 : {
3577 : OSL_TRACE("Error replacing image");
3578 0 : }
3579 0 : }
3580 : }
3581 :
3582 0 : delete pIconDialog;
3583 :
3584 0 : break;
3585 : }
3586 : case ID_RESET_SYMBOL:
3587 : {
3588 0 : SvTreeListEntry* pActEntry = aContentsListBox->GetCurEntry();
3589 : SvxConfigEntry* pEntry =
3590 0 : (SvxConfigEntry*) pActEntry->GetUserData();
3591 :
3592 0 : sal_uInt16 nSelectionPos = 0;
3593 :
3594 : // find position of entry within the list
3595 0 : for ( sal_uInt16 i = 0; i < aContentsListBox->GetEntryCount(); ++i )
3596 : {
3597 0 : if ( aContentsListBox->GetEntry( 0, i ) == pActEntry )
3598 : {
3599 0 : nSelectionPos = i;
3600 0 : break;
3601 : }
3602 : }
3603 :
3604 : uno::Reference< graphic::XGraphic > backup =
3605 0 : pEntry->GetBackupGraphic();
3606 :
3607 : uno::Sequence< uno::Reference< graphic::XGraphic > >
3608 0 : aGraphicSeq( 1 );
3609 0 : aGraphicSeq[ 0 ] = backup;
3610 :
3611 0 : uno::Sequence< OUString > aURLSeq( 1 );
3612 0 : aURLSeq[ 0 ] = pEntry->GetCommand();
3613 :
3614 : try
3615 : {
3616 0 : GetSaveInData()->GetImageManager()->replaceImages(
3617 0 : GetImageType(), aURLSeq, aGraphicSeq );
3618 :
3619 0 : Image aImage( backup );
3620 0 : aContentsListBox->GetModel()->Remove( pActEntry );
3621 :
3622 : SvTreeListEntry* pNewLBEntry =
3623 0 : InsertEntryIntoUI( pEntry, nSelectionPos );
3624 :
3625 : aContentsListBox->SetCheckButtonState( pNewLBEntry,
3626 0 : pEntry->IsVisible() ?
3627 0 : SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
3628 :
3629 0 : aContentsListBox->Select( pNewLBEntry );
3630 0 : aContentsListBox->MakeVisible( pNewLBEntry );
3631 :
3632 : // reset backup in entry
3633 : pEntry->SetBackupGraphic(
3634 0 : uno::Reference< graphic::XGraphic >() );
3635 :
3636 : GetSaveInData()->PersistChanges(
3637 0 : GetSaveInData()->GetImageManager() );
3638 : }
3639 0 : catch ( uno::Exception& )
3640 : {
3641 : OSL_TRACE("Error resetting image");
3642 : }
3643 0 : break;
3644 : }
3645 : }
3646 :
3647 0 : if ( bNeedsApply == sal_True )
3648 : {
3649 0 : (( ToolbarSaveInData* ) GetSaveInData())->ApplyToolbar( pToolbar );
3650 0 : UpdateButtonStates();
3651 : }
3652 :
3653 0 : return 1;
3654 : }
3655 :
3656 0 : void SvxToolbarConfigPage::Init()
3657 : {
3658 : // ensure that the UI is cleared before populating it
3659 0 : aTopLevelListBox.Clear();
3660 0 : aContentsListBox->Clear();
3661 :
3662 0 : ReloadTopLevelListBox();
3663 :
3664 0 : sal_uInt16 nPos = 0;
3665 0 : if ( !m_aURLToSelect.isEmpty() )
3666 : {
3667 0 : for ( sal_uInt16 i = 0 ; i < aTopLevelListBox.GetEntryCount(); ++i )
3668 : {
3669 : SvxConfigEntry* pData =
3670 0 : (SvxConfigEntry*) aTopLevelListBox.GetEntryData( i );
3671 :
3672 0 : if ( pData->GetCommand().equals( m_aURLToSelect ) )
3673 : {
3674 0 : nPos = i;
3675 0 : break;
3676 : }
3677 : }
3678 :
3679 : // in future select the default toolbar: Standard
3680 0 : m_aURLToSelect = OUString(ITEM_TOOLBAR_URL );
3681 0 : m_aURLToSelect += OUString("standardbar" );
3682 : }
3683 :
3684 0 : aTopLevelListBox.SelectEntryPos(nPos, sal_True);
3685 0 : aTopLevelListBox.GetSelectHdl().Call(this);
3686 0 : }
3687 :
3688 0 : SaveInData* SvxToolbarConfigPage::CreateSaveInData(
3689 : const uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
3690 : const uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
3691 : const OUString& aModuleId,
3692 : bool bDocConfig )
3693 : {
3694 : return static_cast< SaveInData* >(
3695 0 : new ToolbarSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ));
3696 : }
3697 :
3698 0 : ToolbarSaveInData::ToolbarSaveInData(
3699 : const uno::Reference < css::ui::XUIConfigurationManager >& xCfgMgr,
3700 : const uno::Reference < css::ui::XUIConfigurationManager >& xParentCfgMgr,
3701 : const OUString& aModuleId,
3702 : bool docConfig ) :
3703 :
3704 : SaveInData ( xCfgMgr, xParentCfgMgr, aModuleId, docConfig ),
3705 : pRootEntry ( NULL ),
3706 0 : m_aDescriptorContainer ( ITEM_DESCRIPTOR_CONTAINER )
3707 :
3708 : {
3709 : // Initialize the m_xPersistentWindowState variable which is used
3710 : // to get the default properties of system toolbars such as name
3711 0 : uno::Reference< container::XNameAccess > xPWSS = css::ui::WindowStateConfiguration::create( m_xContext );
3712 :
3713 0 : xPWSS->getByName( aModuleId ) >>= m_xPersistentWindowState;
3714 0 : }
3715 :
3716 0 : ToolbarSaveInData::~ToolbarSaveInData()
3717 : {
3718 0 : delete pRootEntry;
3719 0 : }
3720 :
3721 0 : void ToolbarSaveInData::SetSystemStyle(
3722 : uno::Reference< frame::XFrame > xFrame,
3723 : const OUString& rResourceURL,
3724 : sal_Int32 nStyle )
3725 : {
3726 : // change the style using the API
3727 0 : SetSystemStyle( rResourceURL, nStyle );
3728 :
3729 : // this code is a temporary hack as the UI is not updating after
3730 : // changing the toolbar style via the API
3731 0 : uno::Reference< css::frame::XLayoutManager > xLayoutManager;
3732 0 : Window *window = NULL;
3733 :
3734 0 : uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
3735 0 : if ( xPropSet.is() )
3736 : {
3737 0 : uno::Any a = xPropSet->getPropertyValue(
3738 0 : OUString( "LayoutManager" ) );
3739 0 : a >>= xLayoutManager;
3740 : }
3741 :
3742 0 : if ( xLayoutManager.is() )
3743 : {
3744 : uno::Reference< css::ui::XUIElement > xUIElement =
3745 0 : xLayoutManager->getElement( rResourceURL );
3746 :
3747 : // check reference before we call getRealInterface. The layout manager
3748 : // can only provide references for elements that have been created
3749 : // before. It's possible that the current element is not available.
3750 0 : uno::Reference< com::sun::star::awt::XWindow > xWindow;
3751 0 : if ( xUIElement.is() )
3752 : xWindow = uno::Reference< com::sun::star::awt::XWindow >(
3753 0 : xUIElement->getRealInterface(), uno::UNO_QUERY );
3754 :
3755 0 : window = VCLUnoHelper::GetWindow( xWindow );
3756 : }
3757 :
3758 0 : if ( window != NULL && window->GetType() == WINDOW_TOOLBOX )
3759 : {
3760 0 : ToolBox* toolbox = (ToolBox*)window;
3761 :
3762 0 : if ( nStyle == 0 )
3763 : {
3764 0 : toolbox->SetButtonType( BUTTON_SYMBOL );
3765 : }
3766 0 : else if ( nStyle == 1 )
3767 : {
3768 0 : toolbox->SetButtonType( BUTTON_TEXT );
3769 : }
3770 0 : if ( nStyle == 2 )
3771 : {
3772 0 : toolbox->SetButtonType( BUTTON_SYMBOLTEXT );
3773 : }
3774 0 : }
3775 0 : }
3776 :
3777 0 : void ToolbarSaveInData::SetSystemStyle(
3778 : const OUString& rResourceURL,
3779 : sal_Int32 nStyle )
3780 : {
3781 0 : if ( rResourceURL.indexOf( "private" ) == 0 &&
3782 0 : m_xPersistentWindowState.is() &&
3783 0 : m_xPersistentWindowState->hasByName( rResourceURL ) )
3784 : {
3785 : try
3786 : {
3787 0 : uno::Sequence< beans::PropertyValue > aProps;
3788 :
3789 0 : uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3790 :
3791 0 : if ( a >>= aProps )
3792 : {
3793 0 : for ( sal_Int32 i = 0; i < aProps.getLength(); ++i )
3794 : {
3795 0 : if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE) )
3796 : {
3797 0 : aProps[ i ].Value = uno::makeAny( nStyle );
3798 0 : break;
3799 : }
3800 : }
3801 : }
3802 :
3803 : uno::Reference< container::XNameReplace >
3804 0 : xNameReplace( m_xPersistentWindowState, uno::UNO_QUERY );
3805 :
3806 0 : xNameReplace->replaceByName( rResourceURL, uno::makeAny( aProps ) );
3807 : }
3808 0 : catch ( uno::Exception& )
3809 : {
3810 : // do nothing, a default value is returned
3811 : OSL_TRACE("Exception setting toolbar style");
3812 : }
3813 : }
3814 0 : }
3815 :
3816 0 : sal_Int32 ToolbarSaveInData::GetSystemStyle( const OUString& rResourceURL )
3817 : {
3818 0 : sal_Int32 result = 0;
3819 :
3820 0 : if ( rResourceURL.indexOf( "private" ) == 0 &&
3821 0 : m_xPersistentWindowState.is() &&
3822 0 : m_xPersistentWindowState->hasByName( rResourceURL ) )
3823 : {
3824 : try
3825 : {
3826 0 : uno::Sequence< beans::PropertyValue > aProps;
3827 0 : uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3828 :
3829 0 : if ( a >>= aProps )
3830 : {
3831 0 : for ( sal_Int32 i = 0; i < aProps.getLength(); ++i )
3832 : {
3833 0 : if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE) )
3834 : {
3835 0 : aProps[i].Value >>= result;
3836 0 : break;
3837 : }
3838 : }
3839 0 : }
3840 : }
3841 0 : catch ( uno::Exception& )
3842 : {
3843 : // do nothing, a default value is returned
3844 : }
3845 : }
3846 :
3847 0 : return result;
3848 : }
3849 :
3850 0 : OUString ToolbarSaveInData::GetSystemUIName( const OUString& rResourceURL )
3851 : {
3852 0 : OUString result;
3853 :
3854 0 : if ( rResourceURL.indexOf( "private" ) == 0 &&
3855 0 : m_xPersistentWindowState.is() &&
3856 0 : m_xPersistentWindowState->hasByName( rResourceURL ) )
3857 : {
3858 : try
3859 : {
3860 0 : uno::Sequence< beans::PropertyValue > aProps;
3861 0 : uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
3862 :
3863 0 : if ( a >>= aProps )
3864 : {
3865 0 : for ( sal_Int32 i = 0; i < aProps.getLength(); ++i )
3866 : {
3867 0 : if ( aProps[ i ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
3868 : {
3869 0 : aProps[ i ].Value >>= result;
3870 : }
3871 : }
3872 0 : }
3873 : }
3874 0 : catch ( uno::Exception& )
3875 : {
3876 : // do nothing, an empty UIName will be returned
3877 : }
3878 : }
3879 :
3880 0 : if ( rResourceURL.indexOf( ".uno" ) == 0 &&
3881 0 : m_xCommandToLabelMap.is() &&
3882 0 : m_xCommandToLabelMap->hasByName( rResourceURL ) )
3883 : {
3884 0 : uno::Any a;
3885 : try
3886 : {
3887 0 : a = m_xCommandToLabelMap->getByName( rResourceURL );
3888 :
3889 0 : uno::Sequence< beans::PropertyValue > aPropSeq;
3890 0 : if ( a >>= aPropSeq )
3891 : {
3892 0 : for ( sal_Int32 i = 0; i < aPropSeq.getLength(); ++i )
3893 : {
3894 0 : if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
3895 : {
3896 0 : aPropSeq[i].Value >>= result;
3897 : }
3898 : }
3899 0 : }
3900 : }
3901 0 : catch ( uno::Exception& )
3902 : {
3903 : // not a system command name
3904 0 : }
3905 : }
3906 :
3907 0 : return result;
3908 : }
3909 :
3910 0 : bool EntrySort( SvxConfigEntry* a, SvxConfigEntry* b )
3911 : {
3912 0 : return a->GetName().compareTo( b->GetName() ) < 0;
3913 : }
3914 :
3915 0 : SvxEntries* ToolbarSaveInData::GetEntries()
3916 : {
3917 : typedef ::boost::unordered_map< ::rtl::OUString,
3918 : bool,
3919 : ::rtl::OUStringHash,
3920 : ::std::equal_to< ::rtl::OUString > > ToolbarInfo;
3921 :
3922 0 : ToolbarInfo aToolbarInfo;
3923 :
3924 0 : if ( pRootEntry == NULL )
3925 : {
3926 :
3927 : pRootEntry = new SvxConfigEntry(
3928 : rtl::OUString("MainToolbars"),
3929 0 : rtl::OUString(), sal_True);
3930 :
3931 : uno::Sequence< uno::Sequence < beans::PropertyValue > > info =
3932 0 : GetConfigManager()->getUIElementsInfo(
3933 0 : css::ui::UIElementType::TOOLBAR );
3934 :
3935 0 : for ( sal_Int32 i = 0; i < info.getLength(); ++i )
3936 : {
3937 0 : uno::Sequence< beans::PropertyValue > props = info[ i ];
3938 :
3939 0 : OUString url;
3940 0 : OUString systemname;
3941 0 : OUString uiname;
3942 :
3943 0 : for ( sal_Int32 j = 0; j < props.getLength(); ++j )
3944 : {
3945 0 : if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) )
3946 : {
3947 0 : props[ j ].Value >>= url;
3948 0 : systemname = url.copy( url.lastIndexOf( '/' ) + 1 );
3949 : }
3950 0 : else if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
3951 : {
3952 0 : props[ j ].Value >>= uiname;
3953 : }
3954 : }
3955 :
3956 : try
3957 : {
3958 : uno::Reference< container::XIndexAccess > xToolbarSettings =
3959 0 : GetConfigManager()->getSettings( url, sal_False );
3960 :
3961 0 : if ( uiname.isEmpty() )
3962 : {
3963 : // try to get the name from m_xPersistentWindowState
3964 0 : uiname = GetSystemUIName( url );
3965 :
3966 0 : if ( uiname.isEmpty() )
3967 : {
3968 0 : uiname = systemname;
3969 : }
3970 : }
3971 :
3972 : SvxConfigEntry* pEntry = new SvxConfigEntry(
3973 0 : uiname, url, sal_True );
3974 :
3975 0 : pEntry->SetMain( sal_True );
3976 0 : pEntry->SetStyle( GetSystemStyle( url ) );
3977 :
3978 :
3979 : // insert into boost::unordered_map to filter duplicates from the parent
3980 0 : aToolbarInfo.insert( ToolbarInfo::value_type( systemname, true ));
3981 :
3982 0 : OUString custom(CUSTOM_TOOLBAR_STR);
3983 0 : if ( systemname.indexOf( custom ) == 0 )
3984 : {
3985 0 : pEntry->SetUserDefined( sal_True );
3986 : }
3987 : else
3988 : {
3989 0 : pEntry->SetUserDefined( sal_False );
3990 : }
3991 :
3992 0 : pRootEntry->GetEntries()->push_back( pEntry );
3993 :
3994 0 : LoadToolbar( xToolbarSettings, pEntry );
3995 : }
3996 0 : catch ( container::NoSuchElementException& )
3997 : {
3998 : // TODO, handle resourceURL with no settings
3999 : }
4000 0 : }
4001 :
4002 0 : uno::Reference< css::ui::XUIConfigurationManager > xParentCfgMgr = GetParentConfigManager();
4003 0 : if ( xParentCfgMgr.is() )
4004 : {
4005 : // Retrieve also the parent toolbars to make it possible
4006 : // to configure module toolbars and save them into the document
4007 : // config manager.
4008 : uno::Sequence< uno::Sequence < beans::PropertyValue > > info_ =
4009 0 : xParentCfgMgr->getUIElementsInfo(
4010 0 : css::ui::UIElementType::TOOLBAR );
4011 :
4012 0 : for ( sal_Int32 i = 0; i < info_.getLength(); ++i )
4013 : {
4014 0 : uno::Sequence< beans::PropertyValue > props = info_[ i ];
4015 :
4016 0 : OUString url;
4017 0 : OUString systemname;
4018 0 : OUString uiname;
4019 :
4020 0 : for ( sal_Int32 j = 0; j < props.getLength(); ++j )
4021 : {
4022 0 : if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) )
4023 : {
4024 0 : props[ j ].Value >>= url;
4025 0 : systemname = url.copy( url.lastIndexOf( '/' ) + 1 );
4026 : }
4027 0 : else if ( props[ j ].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) )
4028 : {
4029 0 : props[ j ].Value >>= uiname;
4030 : }
4031 : }
4032 :
4033 : // custom toolbars of the parent are not visible in the document layer
4034 0 : OUString custom(CUSTOM_TOOLBAR_STR);
4035 0 : if ( systemname.indexOf( custom ) == 0 )
4036 0 : continue;
4037 :
4038 : // check if toolbar is already in the document layer
4039 0 : ToolbarInfo::const_iterator pIter = aToolbarInfo.find( systemname );
4040 0 : if ( pIter == aToolbarInfo.end() )
4041 : {
4042 0 : aToolbarInfo.insert( ToolbarInfo::value_type( systemname, true ));
4043 :
4044 : try
4045 : {
4046 : uno::Reference< container::XIndexAccess > xToolbarSettings =
4047 0 : xParentCfgMgr->getSettings( url, sal_False );
4048 :
4049 0 : if ( uiname.isEmpty() )
4050 : {
4051 : // try to get the name from m_xPersistentWindowState
4052 0 : uiname = GetSystemUIName( url );
4053 :
4054 0 : if ( uiname.isEmpty() )
4055 : {
4056 0 : uiname = systemname;
4057 : }
4058 : }
4059 :
4060 : SvxConfigEntry* pEntry = new SvxConfigEntry(
4061 0 : uiname, url, sal_True, sal_True );
4062 :
4063 0 : pEntry->SetMain( sal_True );
4064 0 : pEntry->SetStyle( GetSystemStyle( url ) );
4065 :
4066 0 : if ( systemname.indexOf( custom ) == 0 )
4067 : {
4068 0 : pEntry->SetUserDefined( sal_True );
4069 : }
4070 : else
4071 : {
4072 0 : pEntry->SetUserDefined( sal_False );
4073 : }
4074 :
4075 0 : pRootEntry->GetEntries()->push_back( pEntry );
4076 :
4077 0 : LoadToolbar( xToolbarSettings, pEntry );
4078 : }
4079 0 : catch ( container::NoSuchElementException& )
4080 : {
4081 : // TODO, handle resourceURL with no settings
4082 : }
4083 : }
4084 0 : }
4085 : }
4086 :
4087 0 : std::sort( GetEntries()->begin(), GetEntries()->end(), EntrySort );
4088 : }
4089 :
4090 0 : return pRootEntry->GetEntries();
4091 : }
4092 :
4093 : void
4094 0 : ToolbarSaveInData::SetEntries( SvxEntries* pNewEntries )
4095 : {
4096 : // delete old menu hierarchy first
4097 0 : if ( pRootEntry != NULL && pRootEntry->GetEntries() != NULL )
4098 : {
4099 0 : delete pRootEntry->GetEntries();
4100 : }
4101 :
4102 : // now set new menu hierarchy
4103 0 : pRootEntry->SetEntries( pNewEntries );
4104 0 : }
4105 :
4106 : bool
4107 0 : ToolbarSaveInData::HasURL( const OUString& rURL )
4108 : {
4109 0 : SvxEntries::const_iterator iter = GetEntries()->begin();
4110 0 : SvxEntries::const_iterator end = GetEntries()->end();
4111 :
4112 0 : while ( iter != end )
4113 : {
4114 0 : SvxConfigEntry* pEntry = *iter;
4115 :
4116 0 : if ( pEntry->GetCommand().equals( rURL ) )
4117 : {
4118 0 : if ( pEntry->IsParentData() )
4119 0 : return sal_False;
4120 : else
4121 0 : return sal_True;
4122 : }
4123 :
4124 0 : ++iter;
4125 : }
4126 0 : return sal_False;
4127 : }
4128 :
4129 0 : bool ToolbarSaveInData::HasSettings()
4130 : {
4131 : // return true if there is at least one toolbar entry
4132 0 : if ( GetEntries()->size() > 0 )
4133 : {
4134 0 : return sal_True;
4135 : }
4136 0 : return sal_False;
4137 : }
4138 :
4139 0 : void ToolbarSaveInData::Reset()
4140 : {
4141 0 : SvxEntries::const_iterator toolbars = GetEntries()->begin();
4142 0 : SvxEntries::const_iterator end = GetEntries()->end();
4143 :
4144 : // reset each toolbar by calling removeSettings for it's toolbar URL
4145 0 : for ( ; toolbars != end; ++toolbars )
4146 : {
4147 0 : SvxConfigEntry* pToolbar = *toolbars;
4148 :
4149 : try
4150 : {
4151 0 : OUString url = pToolbar->GetCommand();
4152 0 : GetConfigManager()->removeSettings( url );
4153 : }
4154 0 : catch ( uno::Exception& )
4155 : {
4156 : // error occurred removing the settings
4157 : // TODO - add error dialog in future?
4158 : }
4159 : }
4160 :
4161 : // persist changes to toolbar storage
4162 0 : PersistChanges( GetConfigManager() );
4163 :
4164 : // now delete the root SvxConfigEntry the next call to GetEntries()
4165 : // causes it to be reinitialised
4166 0 : delete pRootEntry;
4167 0 : pRootEntry = NULL;
4168 :
4169 : // reset all icons to default
4170 : try
4171 : {
4172 0 : GetImageManager()->reset();
4173 0 : PersistChanges( GetImageManager() );
4174 : }
4175 0 : catch ( uno::Exception& )
4176 : {
4177 : OSL_TRACE("Error resetting all icons when resetting toolbars");
4178 : }
4179 0 : }
4180 :
4181 0 : bool ToolbarSaveInData::Apply()
4182 : {
4183 : // toolbar changes are instantly applied
4184 0 : return sal_False;
4185 : }
4186 :
4187 0 : void ToolbarSaveInData::ApplyToolbar(
4188 : uno::Reference< container::XIndexContainer >& rToolbarBar,
4189 : uno::Reference< lang::XSingleComponentFactory >& rFactory,
4190 : SvxConfigEntry* pToolbarData )
4191 : {
4192 0 : uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
4193 :
4194 0 : SvxEntries::const_iterator iter = pToolbarData->GetEntries()->begin();
4195 0 : SvxEntries::const_iterator end = pToolbarData->GetEntries()->end();
4196 :
4197 0 : for ( ; iter != end; ++iter )
4198 : {
4199 0 : SvxConfigEntry* pEntry = *iter;
4200 :
4201 0 : if ( pEntry->IsPopup() )
4202 : {
4203 : uno::Sequence< beans::PropertyValue > aPropValueSeq =
4204 0 : ConvertToolbarEntry( m_xCommandToLabelMap, pEntry );
4205 :
4206 : uno::Reference< container::XIndexContainer > xSubMenuBar(
4207 0 : rFactory->createInstanceWithContext( xContext ),
4208 0 : uno::UNO_QUERY );
4209 :
4210 0 : sal_Int32 nIndex = aPropValueSeq.getLength();
4211 0 : aPropValueSeq.realloc( nIndex + 1 );
4212 0 : aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
4213 0 : aPropValueSeq[nIndex].Value <<= xSubMenuBar;
4214 0 : rToolbarBar->insertByIndex(
4215 0 : rToolbarBar->getCount(), uno::makeAny( aPropValueSeq ));
4216 :
4217 0 : ApplyToolbar( xSubMenuBar, rFactory, pEntry );
4218 : }
4219 0 : else if ( pEntry->IsSeparator() )
4220 : {
4221 0 : rToolbarBar->insertByIndex(
4222 0 : rToolbarBar->getCount(), uno::makeAny( m_aSeparatorSeq ));
4223 : }
4224 : else
4225 : {
4226 : uno::Sequence< beans::PropertyValue > aPropValueSeq =
4227 0 : ConvertToolbarEntry( m_xCommandToLabelMap, pEntry );
4228 :
4229 0 : rToolbarBar->insertByIndex(
4230 0 : rToolbarBar->getCount(), uno::makeAny( aPropValueSeq ));
4231 : }
4232 0 : }
4233 0 : }
4234 :
4235 0 : void ToolbarSaveInData::ApplyToolbar( SvxConfigEntry* pToolbar )
4236 : {
4237 : // Apply new toolbar structure to our settings container
4238 : uno::Reference< container::XIndexAccess > xSettings(
4239 0 : GetConfigManager()->createSettings(), uno::UNO_QUERY );
4240 :
4241 : uno::Reference< container::XIndexContainer > xIndexContainer (
4242 0 : xSettings, uno::UNO_QUERY );
4243 :
4244 : uno::Reference< lang::XSingleComponentFactory > xFactory (
4245 0 : xSettings, uno::UNO_QUERY );
4246 :
4247 0 : ApplyToolbar( xIndexContainer, xFactory, pToolbar );
4248 :
4249 : uno::Reference< beans::XPropertySet > xProps(
4250 0 : xSettings, uno::UNO_QUERY );
4251 :
4252 0 : if ( pToolbar->IsUserDefined() )
4253 : {
4254 0 : xProps->setPropertyValue(
4255 : OUString(ITEM_DESCRIPTOR_UINAME ),
4256 0 : uno::makeAny( OUString( pToolbar->GetName() ) ) );
4257 : }
4258 :
4259 : try
4260 : {
4261 0 : if ( GetConfigManager()->hasSettings( pToolbar->GetCommand() ) )
4262 : {
4263 0 : GetConfigManager()->replaceSettings(
4264 0 : pToolbar->GetCommand(), xSettings );
4265 : }
4266 : else
4267 : {
4268 0 : GetConfigManager()->insertSettings(
4269 0 : pToolbar->GetCommand(), xSettings );
4270 0 : if ( pToolbar->IsParentData() )
4271 0 : pToolbar->SetParentData( false );
4272 : }
4273 : }
4274 0 : catch ( container::NoSuchElementException& )
4275 : {
4276 : OSL_TRACE("caught container::NoSuchElementException saving settings");
4277 : }
4278 0 : catch ( com::sun::star::io::IOException& )
4279 : {
4280 : OSL_TRACE("caught IOException saving settings");
4281 : }
4282 0 : catch ( com::sun::star::uno::Exception& )
4283 : {
4284 : OSL_TRACE("caught some other exception saving settings");
4285 : }
4286 :
4287 0 : PersistChanges( GetConfigManager() );
4288 0 : }
4289 :
4290 0 : void ToolbarSaveInData::CreateToolbar( SvxConfigEntry* pToolbar )
4291 : {
4292 : // show the new toolbar in the UI also
4293 : uno::Reference< container::XIndexAccess >
4294 0 : xSettings( GetConfigManager()->createSettings(), uno::UNO_QUERY );
4295 :
4296 : uno::Reference< container::XIndexContainer >
4297 0 : xIndexContainer ( xSettings, uno::UNO_QUERY );
4298 :
4299 : uno::Reference< beans::XPropertySet >
4300 0 : xPropertySet( xSettings, uno::UNO_QUERY );
4301 :
4302 0 : xPropertySet->setPropertyValue(
4303 : OUString(ITEM_DESCRIPTOR_UINAME ),
4304 0 : uno::makeAny( pToolbar->GetName() ) );
4305 :
4306 : try
4307 : {
4308 0 : GetConfigManager()->insertSettings( pToolbar->GetCommand(), xSettings );
4309 : }
4310 0 : catch ( container::ElementExistException& )
4311 : {
4312 : OSL_TRACE("caught ElementExistsException saving settings");
4313 : }
4314 0 : catch ( com::sun::star::lang::IllegalArgumentException& )
4315 : {
4316 : OSL_TRACE("caught IOException saving settings");
4317 : }
4318 0 : catch ( com::sun::star::lang::IllegalAccessException& )
4319 : {
4320 : OSL_TRACE("caught IOException saving settings");
4321 : }
4322 0 : catch ( com::sun::star::uno::Exception& )
4323 : {
4324 : OSL_TRACE("caught some other exception saving settings");
4325 : }
4326 :
4327 0 : GetEntries()->push_back( pToolbar );
4328 :
4329 0 : PersistChanges( GetConfigManager() );
4330 0 : }
4331 :
4332 0 : void ToolbarSaveInData::RemoveToolbar( SvxConfigEntry* pToolbar )
4333 : {
4334 : try
4335 : {
4336 0 : OUString url = pToolbar->GetCommand();
4337 0 : GetConfigManager()->removeSettings( url );
4338 0 : RemoveEntry( GetEntries(), pToolbar );
4339 0 : delete pToolbar;
4340 :
4341 0 : PersistChanges( GetConfigManager() );
4342 :
4343 : // remove the persistent window state data
4344 : css::uno::Reference< css::container::XNameContainer > xNameContainer(
4345 0 : m_xPersistentWindowState, css::uno::UNO_QUERY_THROW );
4346 :
4347 0 : xNameContainer->removeByName( url );
4348 : }
4349 0 : catch ( uno::Exception& )
4350 : {
4351 : // error occurred removing the settings
4352 : }
4353 0 : }
4354 :
4355 0 : void ToolbarSaveInData::RestoreToolbar( SvxConfigEntry* pToolbar )
4356 : {
4357 0 : OUString url = pToolbar->GetCommand();
4358 :
4359 : // Restore of toolbar is done by removing it from
4360 : // it's configuration manager and then getting it again
4361 0 : bool bParentToolbar = pToolbar->IsParentData();
4362 :
4363 : // Cannot restore parent toolbar
4364 0 : if ( bParentToolbar )
4365 : return;
4366 :
4367 : try
4368 : {
4369 0 : GetConfigManager()->removeSettings( url );
4370 0 : pToolbar->GetEntries()->clear();
4371 0 : PersistChanges( GetConfigManager() );
4372 : }
4373 0 : catch ( uno::Exception& )
4374 : {
4375 : // if an error occurs removing the settings then just return
4376 : return;
4377 : }
4378 :
4379 : // Now reload the toolbar settings
4380 : try
4381 : {
4382 0 : uno::Reference< container::XIndexAccess > xToolbarSettings;
4383 0 : if ( IsDocConfig() )
4384 : {
4385 0 : xToolbarSettings = GetParentConfigManager()->getSettings( url, sal_False );
4386 0 : pToolbar->SetParentData( true );
4387 : }
4388 : else
4389 0 : xToolbarSettings = GetConfigManager()->getSettings( url, sal_False );
4390 :
4391 0 : LoadToolbar( xToolbarSettings, pToolbar );
4392 :
4393 : // After reloading, ensure that the icon is reset of each entry
4394 : // in the toolbar
4395 0 : SvxEntries::const_iterator iter = pToolbar->GetEntries()->begin();
4396 0 : uno::Sequence< OUString > aURLSeq( 1 );
4397 0 : for ( ; iter != pToolbar->GetEntries()->end(); ++iter )
4398 : {
4399 0 : SvxConfigEntry* pEntry = *iter;
4400 0 : aURLSeq[ 0 ] = pEntry->GetCommand();
4401 :
4402 : try
4403 : {
4404 0 : GetImageManager()->removeImages( GetImageType(), aURLSeq );
4405 : }
4406 0 : catch ( uno::Exception& )
4407 : {
4408 : OSL_TRACE("Error restoring icon when resetting toolbar");
4409 : }
4410 : }
4411 0 : PersistChanges( GetImageManager() );
4412 : }
4413 0 : catch ( container::NoSuchElementException& )
4414 : {
4415 : // cannot find the resource URL after removing it
4416 : // so no entry will appear in the toolbar list
4417 0 : }
4418 : }
4419 :
4420 0 : bool ToolbarSaveInData::LoadToolbar(
4421 : const uno::Reference< container::XIndexAccess >& xToolbarSettings,
4422 : SvxConfigEntry* pParentData )
4423 : {
4424 0 : SvxEntries* pEntries = pParentData->GetEntries();
4425 :
4426 0 : for ( sal_Int32 nIndex = 0; nIndex < xToolbarSettings->getCount(); ++nIndex )
4427 : {
4428 0 : uno::Reference< container::XIndexAccess > xSubMenu;
4429 0 : OUString aCommandURL;
4430 0 : OUString aLabel;
4431 0 : bool bIsUserDefined = sal_True;
4432 : sal_Bool bIsVisible;
4433 : sal_Int32 nStyle;
4434 :
4435 0 : sal_uInt16 nType( css::ui::ItemType::DEFAULT );
4436 :
4437 : bool bItem = GetToolbarItemData( xToolbarSettings, nIndex, aCommandURL,
4438 0 : aLabel, nType, bIsVisible, nStyle, xSubMenu );
4439 :
4440 0 : if ( bItem )
4441 : {
4442 0 : if ( nType == css::ui::ItemType::DEFAULT )
4443 : {
4444 0 : uno::Any a;
4445 : try
4446 : {
4447 0 : a = m_xCommandToLabelMap->getByName( aCommandURL );
4448 0 : bIsUserDefined = sal_False;
4449 : }
4450 0 : catch ( container::NoSuchElementException& )
4451 : {
4452 0 : bIsUserDefined = sal_True;
4453 : }
4454 :
4455 : // If custom label not set retrieve it from the command
4456 : // to info service
4457 0 : if ( aLabel.equals( OUString() ) )
4458 : {
4459 0 : uno::Sequence< beans::PropertyValue > aPropSeq;
4460 0 : if ( a >>= aPropSeq )
4461 : {
4462 0 : for ( sal_Int32 i = 0; i < aPropSeq.getLength(); ++i )
4463 : {
4464 0 : if ( aPropSeq[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ) )
4465 : {
4466 0 : aPropSeq[i].Value >>= aLabel;
4467 0 : break;
4468 : }
4469 : }
4470 0 : }
4471 : }
4472 :
4473 0 : if ( xSubMenu.is() )
4474 : {
4475 : SvxConfigEntry* pEntry = new SvxConfigEntry(
4476 0 : aLabel, aCommandURL, sal_True );
4477 :
4478 0 : pEntry->SetUserDefined( bIsUserDefined );
4479 0 : pEntry->SetVisible( bIsVisible );
4480 :
4481 0 : pEntries->push_back( pEntry );
4482 :
4483 0 : LoadToolbar( xSubMenu, pEntry );
4484 : }
4485 : else
4486 : {
4487 : SvxConfigEntry* pEntry = new SvxConfigEntry(
4488 0 : aLabel, aCommandURL, sal_False );
4489 0 : pEntry->SetUserDefined( bIsUserDefined );
4490 0 : pEntry->SetVisible( bIsVisible );
4491 0 : pEntry->SetStyle( nStyle );
4492 0 : pEntries->push_back( pEntry );
4493 0 : }
4494 : }
4495 : else
4496 : {
4497 0 : SvxConfigEntry* pEntry = new SvxConfigEntry;
4498 0 : pEntry->SetUserDefined( bIsUserDefined );
4499 0 : pEntries->push_back( pEntry );
4500 : }
4501 : }
4502 0 : }
4503 :
4504 0 : return true;
4505 : }
4506 :
4507 0 : IMPL_LINK( SvxToolbarConfigPage, SelectToolbarEntry, Control *, pBox )
4508 : {
4509 : (void)pBox;
4510 0 : UpdateButtonStates();
4511 0 : return 1;
4512 : }
4513 :
4514 0 : void SvxToolbarConfigPage::UpdateButtonStates()
4515 : {
4516 0 : PopupMenu* pPopup = aModifyCommandButton.GetPopupMenu();
4517 0 : pPopup->EnableItem( ID_RENAME, sal_False );
4518 0 : pPopup->EnableItem( ID_DELETE, sal_False );
4519 0 : pPopup->EnableItem( ID_BEGIN_GROUP, sal_False );
4520 0 : pPopup->EnableItem( ID_DEFAULT_COMMAND, sal_False );
4521 0 : pPopup->EnableItem( ID_ICON_ONLY, sal_False );
4522 0 : pPopup->EnableItem( ID_ICON_AND_TEXT, sal_False );
4523 0 : pPopup->EnableItem( ID_TEXT_ONLY, sal_False );
4524 0 : pPopup->EnableItem( ID_CHANGE_SYMBOL, sal_False );
4525 0 : pPopup->EnableItem( ID_RESET_SYMBOL, sal_False );
4526 :
4527 0 : aDescriptionField.Clear();
4528 :
4529 0 : SvTreeListEntry* selection = aContentsListBox->GetCurEntry();
4530 0 : if ( aContentsListBox->GetEntryCount() == 0 || selection == NULL )
4531 : {
4532 0 : return;
4533 : }
4534 :
4535 0 : SvxConfigEntry* pEntryData = (SvxConfigEntry*) selection->GetUserData();
4536 0 : if ( pEntryData->IsSeparator() )
4537 0 : pPopup->EnableItem( ID_DELETE, sal_True );
4538 : else
4539 : {
4540 0 : pPopup->EnableItem( ID_BEGIN_GROUP, sal_True );
4541 0 : pPopup->EnableItem( ID_DELETE, sal_True );
4542 0 : pPopup->EnableItem( ID_RENAME, sal_True );
4543 0 : pPopup->EnableItem( ID_ICON_ONLY, sal_True );
4544 0 : pPopup->EnableItem( ID_ICON_AND_TEXT, sal_True );
4545 0 : pPopup->EnableItem( ID_TEXT_ONLY, sal_True );
4546 0 : pPopup->EnableItem( ID_CHANGE_SYMBOL, sal_True );
4547 :
4548 0 : if ( !pEntryData->IsUserDefined() )
4549 0 : pPopup->EnableItem( ID_DEFAULT_COMMAND, sal_True );
4550 :
4551 0 : if ( pEntryData->IsIconModified() )
4552 0 : pPopup->EnableItem( ID_RESET_SYMBOL, sal_True );
4553 :
4554 0 : aDescriptionField.SetNewText( pEntryData->GetHelpText() );
4555 : }
4556 : }
4557 :
4558 0 : short SvxToolbarConfigPage::QueryReset()
4559 : {
4560 : String msg =
4561 0 : String( CUI_RES( RID_SVXSTR_CONFIRM_TOOLBAR_RESET ) );
4562 :
4563 : String saveInName = aSaveInListBox.GetEntry(
4564 0 : aSaveInListBox.GetSelectEntryPos() );
4565 :
4566 0 : OUString label = replaceSaveInName( msg, saveInName );
4567 :
4568 0 : QueryBox qbox( this, WB_YES_NO, label );
4569 :
4570 0 : return qbox.Execute();
4571 : }
4572 :
4573 0 : IMPL_LINK( SvxToolbarConfigPage, SelectToolbar, ListBox *, pBox )
4574 : {
4575 : (void)pBox;
4576 :
4577 0 : aContentsListBox->Clear();
4578 :
4579 0 : SvxConfigEntry* pToolbar = GetTopLevelSelection();
4580 0 : if ( pToolbar == NULL )
4581 : {
4582 0 : aModifyTopLevelButton.Enable( sal_False );
4583 0 : aModifyCommandButton.Enable( sal_False );
4584 0 : aAddCommandsButton.Enable( sal_False );
4585 :
4586 0 : return 0;
4587 : }
4588 :
4589 0 : aModifyTopLevelButton.Enable( sal_True );
4590 0 : aModifyCommandButton.Enable( sal_True );
4591 0 : aAddCommandsButton.Enable( sal_True );
4592 :
4593 0 : PopupMenu* pPopup = aModifyTopLevelButton.GetPopupMenu();
4594 :
4595 0 : pPopup->EnableItem( ID_DELETE, pToolbar->IsDeletable() );
4596 0 : pPopup->EnableItem( ID_RENAME, pToolbar->IsRenamable() );
4597 0 : pPopup->EnableItem( ID_DEFAULT_STYLE, !pToolbar->IsRenamable() );
4598 :
4599 0 : switch( pToolbar->GetStyle() )
4600 : {
4601 : case 0:
4602 : {
4603 0 : pPopup->CheckItem( ID_ICONS_ONLY );
4604 0 : break;
4605 : }
4606 : case 1:
4607 : {
4608 0 : pPopup->CheckItem( ID_TEXT_ONLY );
4609 0 : break;
4610 : }
4611 : case 2:
4612 : {
4613 0 : pPopup->CheckItem( ID_ICONS_AND_TEXT );
4614 0 : break;
4615 : }
4616 : }
4617 :
4618 0 : SvxEntries* pEntries = pToolbar->GetEntries();
4619 0 : SvxEntries::const_iterator iter = pEntries->begin();
4620 :
4621 0 : for ( ; iter != pEntries->end(); ++iter )
4622 : {
4623 0 : SvxConfigEntry* pEntry = *iter;
4624 :
4625 0 : SvTreeListEntry* pNewLBEntry = InsertEntryIntoUI( pEntry );
4626 :
4627 0 : if (pEntry->IsBinding())
4628 : {
4629 : aContentsListBox->SetCheckButtonState( pNewLBEntry,
4630 0 : pEntry->IsVisible() ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
4631 : }
4632 : else
4633 : {
4634 : aContentsListBox->SetCheckButtonState(
4635 0 : pNewLBEntry, SV_BUTTON_TRISTATE );
4636 : }
4637 : }
4638 :
4639 0 : UpdateButtonStates();
4640 :
4641 0 : return 0;
4642 : }
4643 :
4644 0 : IMPL_LINK( SvxToolbarConfigPage, NewToolbarHdl, Button *, pButton )
4645 : {
4646 : (void)pButton;
4647 :
4648 : String prefix =
4649 0 : String( CUI_RES( RID_SVXSTR_NEW_TOOLBAR ) );
4650 :
4651 : OUString aNewName =
4652 0 : generateCustomName( prefix, GetSaveInData()->GetEntries() );
4653 :
4654 : OUString aNewURL =
4655 0 : generateCustomURL( GetSaveInData()->GetEntries() );
4656 :
4657 0 : SvxNewToolbarDialog* pNameDialog = new SvxNewToolbarDialog( 0, aNewName );
4658 :
4659 : sal_uInt16 nInsertPos;
4660 0 : for ( sal_uInt16 i = 0 ; i < aSaveInListBox.GetEntryCount(); ++i )
4661 : {
4662 : SaveInData* pData =
4663 0 : (SaveInData*) aSaveInListBox.GetEntryData( i );
4664 :
4665 : nInsertPos = pNameDialog->aSaveInListBox.InsertEntry(
4666 0 : aSaveInListBox.GetEntry( i ) );
4667 :
4668 0 : pNameDialog->aSaveInListBox.SetEntryData( nInsertPos, pData );
4669 : }
4670 :
4671 : pNameDialog->aSaveInListBox.SelectEntryPos(
4672 0 : aSaveInListBox.GetSelectEntryPos(), sal_True );
4673 :
4674 0 : bool ret = pNameDialog->Execute();
4675 0 : if ( ret == RET_OK )
4676 : {
4677 0 : pNameDialog->GetName( aNewName );
4678 :
4679 0 : nInsertPos = pNameDialog->aSaveInListBox.GetSelectEntryPos();
4680 :
4681 : ToolbarSaveInData* pData = (ToolbarSaveInData*)
4682 0 : pNameDialog->aSaveInListBox.GetEntryData( nInsertPos );
4683 :
4684 0 : if ( GetSaveInData() != pData )
4685 : {
4686 0 : aSaveInListBox.SelectEntryPos( nInsertPos, sal_True );
4687 0 : aSaveInListBox.GetSelectHdl().Call(this);
4688 : }
4689 :
4690 : SvxConfigEntry* pToolbar =
4691 0 : new SvxConfigEntry( aNewName, aNewURL, sal_True );
4692 :
4693 0 : pToolbar->SetUserDefined( sal_True );
4694 0 : pToolbar->SetMain( sal_True );
4695 :
4696 0 : pData->CreateToolbar( pToolbar );
4697 :
4698 0 : nInsertPos = aTopLevelListBox.InsertEntry( pToolbar->GetName() );
4699 0 : aTopLevelListBox.SetEntryData( nInsertPos, pToolbar );
4700 0 : aTopLevelListBox.SelectEntryPos( nInsertPos, sal_True );
4701 0 : aTopLevelListBox.GetSelectHdl().Call(this);
4702 :
4703 0 : pData->SetModified( sal_True );
4704 : }
4705 :
4706 0 : delete pNameDialog;
4707 :
4708 0 : return 0;
4709 : }
4710 :
4711 0 : IMPL_LINK( SvxToolbarConfigPage, AddCommandsHdl, Button *, pButton )
4712 : {
4713 : (void)pButton;
4714 :
4715 0 : if ( pSelectorDlg == NULL )
4716 : {
4717 : // Create Script Selector which shows slot commands
4718 0 : pSelectorDlg = new SvxScriptSelectorDialog( this, sal_True, m_xFrame );
4719 :
4720 : // Position the Script Selector over the Add button so it is
4721 : // beside the menu contents list and does not obscure it
4722 0 : pSelectorDlg->SetPosPixel( aAddCommandsButton.GetPosPixel() );
4723 :
4724 : pSelectorDlg->SetAddHdl(
4725 0 : LINK( this, SvxToolbarConfigPage, AddFunctionHdl ) );
4726 : }
4727 :
4728 : pSelectorDlg->SetImageProvider(
4729 0 : static_cast< ImageProvider* >( GetSaveInData() ) );
4730 :
4731 0 : pSelectorDlg->Show();
4732 0 : return 1;
4733 : }
4734 :
4735 0 : IMPL_LINK( SvxToolbarConfigPage, AddFunctionHdl,
4736 : SvxScriptSelectorDialog *, pDialog )
4737 : {
4738 : (void)pDialog;
4739 :
4740 0 : AddFunction();
4741 :
4742 0 : return 0;
4743 : }
4744 :
4745 0 : SvTreeListEntry* SvxToolbarConfigPage::AddFunction(
4746 : SvTreeListEntry* pTarget, bool bFront, bool bAllowDuplicates )
4747 : {
4748 : SvTreeListEntry* pNewLBEntry =
4749 0 : SvxConfigPage::AddFunction( pTarget, bFront, bAllowDuplicates );
4750 :
4751 0 : SvxConfigEntry* pEntry = (SvxConfigEntry*) pNewLBEntry->GetUserData();
4752 :
4753 0 : if ( pEntry->IsBinding() )
4754 : {
4755 0 : pEntry->SetVisible( sal_True );
4756 : aContentsListBox->SetCheckButtonState(
4757 0 : pNewLBEntry, SV_BUTTON_CHECKED );
4758 : }
4759 : else
4760 : {
4761 : aContentsListBox->SetCheckButtonState(
4762 0 : pNewLBEntry, SV_BUTTON_TRISTATE );
4763 : }
4764 :
4765 : // get currently selected toolbar and apply change
4766 0 : SvxConfigEntry* pToolbar = GetTopLevelSelection();
4767 :
4768 0 : if ( pToolbar != NULL )
4769 : {
4770 0 : ( ( ToolbarSaveInData* ) GetSaveInData() )->ApplyToolbar( pToolbar );
4771 : }
4772 :
4773 0 : return pNewLBEntry;
4774 : }
4775 :
4776 : // -----------------------------------------------------------------------
4777 :
4778 0 : SvxToolbarEntriesListBox::SvxToolbarEntriesListBox(
4779 : Window* pParent, const ResId& aResId )
4780 : :
4781 : SvxMenuEntriesListBox( pParent, aResId ),
4782 0 : pPage( ( SvxToolbarConfigPage* ) pParent )
4783 : {
4784 0 : m_pButtonData = new SvLBoxButtonData( this );
4785 0 : BuildCheckBoxButtonImages( m_pButtonData );
4786 0 : EnableCheckButton( m_pButtonData );
4787 0 : }
4788 :
4789 : // --------------------------------------------------------
4790 :
4791 0 : SvxToolbarEntriesListBox::~SvxToolbarEntriesListBox()
4792 : {
4793 0 : delete m_pButtonData;
4794 0 : }
4795 :
4796 : // --------------------------------------------------------
4797 :
4798 0 : void SvxToolbarEntriesListBox::BuildCheckBoxButtonImages( SvLBoxButtonData* pData )
4799 : {
4800 : // Build checkbox images according to the current application
4801 : // settings. This is necessary to be able to have correct colors
4802 : // in all color modes, like high contrast.
4803 0 : const AllSettings& rSettings = Application::GetSettings();
4804 :
4805 0 : VirtualDevice aDev;
4806 0 : Size aSize( 26, 20 );
4807 :
4808 0 : aDev.SetOutputSizePixel( aSize );
4809 :
4810 : Image aImage = GetSizedImage( aDev, aSize,
4811 0 : CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DEFAULT ));
4812 :
4813 : // Fill button data struct with new images
4814 0 : pData->aBmps[SV_BMP_UNCHECKED] = aImage;
4815 0 : pData->aBmps[SV_BMP_CHECKED] = GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_CHECKED ));
4816 0 : pData->aBmps[SV_BMP_HICHECKED] = GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_CHECKED | BUTTON_DRAW_PRESSED ));
4817 0 : pData->aBmps[SV_BMP_HIUNCHECKED] = GetSizedImage( aDev, aSize, CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DEFAULT | BUTTON_DRAW_PRESSED));
4818 0 : pData->aBmps[SV_BMP_TRISTATE] = GetSizedImage( aDev, aSize, Image() ); // Use tristate bitmaps to have no checkbox for separator entries
4819 0 : pData->aBmps[SV_BMP_HITRISTATE] = GetSizedImage( aDev, aSize, Image() );
4820 :
4821 : // Get image size
4822 0 : m_aCheckBoxImageSizePixel = aImage.GetSizePixel();
4823 0 : }
4824 :
4825 0 : Image SvxToolbarEntriesListBox::GetSizedImage(
4826 : VirtualDevice& aDev, const Size& aNewSize, const Image& aImage )
4827 : {
4828 : // Create new checkbox images for treelistbox. They must have a
4829 : // decent width to have a clear column for the visibility checkbox.
4830 :
4831 : // Standard transparent color is light magenta as is won't be
4832 : // used for other things
4833 0 : Color aFillColor( COL_LIGHTMAGENTA );
4834 :
4835 : // Position image at the center of (width-2),(height) rectangle.
4836 : // We need 2 pixels to have a bigger border to the next button image
4837 0 : sal_uInt16 nPosX = std::max( (sal_uInt16) (((( aNewSize.Width() - 2 ) - aImage.GetSizePixel().Width() ) / 2 ) - 1), (sal_uInt16) 0 );
4838 0 : sal_uInt16 nPosY = std::max( (sal_uInt16) (((( aNewSize.Height() - 2 ) - aImage.GetSizePixel().Height() ) / 2 ) + 1), (sal_uInt16) 0 );
4839 0 : Point aPos( nPosX > 0 ? nPosX : 0, nPosY > 0 ? nPosY : 0 );
4840 0 : aDev.SetFillColor( aFillColor );
4841 0 : aDev.SetLineColor( aFillColor );
4842 0 : aDev.DrawRect( Rectangle( Point(), aNewSize ));
4843 0 : aDev.DrawImage( aPos, aImage );
4844 :
4845 : // Draw separator line 2 pixels left from the right border
4846 0 : Color aLineColor = GetDisplayBackground().GetColor().IsDark() ? Color( COL_WHITE ) : Color( COL_BLACK );
4847 0 : aDev.SetLineColor( aLineColor );
4848 0 : aDev.DrawLine( Point( aNewSize.Width()-3, 0 ), Point( aNewSize.Width()-3, aNewSize.Height()-1 ));
4849 :
4850 : // Create new image that uses the fillcolor as transparent
4851 0 : return Image( aDev.GetBitmap( Point(), aNewSize ), aFillColor );
4852 : }
4853 :
4854 0 : void SvxToolbarEntriesListBox::DataChanged( const DataChangedEvent& rDCEvt )
4855 : {
4856 0 : SvTreeListBox::DataChanged( rDCEvt );
4857 :
4858 0 : if (( rDCEvt.GetType() == DATACHANGED_SETTINGS ) &&
4859 0 : ( rDCEvt.GetFlags() & SETTINGS_STYLE ))
4860 : {
4861 0 : BuildCheckBoxButtonImages( m_pButtonData );
4862 0 : Invalidate();
4863 : }
4864 0 : }
4865 :
4866 : // --------------------------------------------------------
4867 :
4868 0 : void SvxToolbarEntriesListBox::ChangeVisibility( SvTreeListEntry* pEntry )
4869 : {
4870 0 : if ( pEntry != NULL )
4871 : {
4872 : SvxConfigEntry* pEntryData =
4873 0 : (SvxConfigEntry*) pEntry->GetUserData();
4874 :
4875 0 : if ( pEntryData->IsBinding() )
4876 : {
4877 0 : pEntryData->SetVisible( !pEntryData->IsVisible() );
4878 :
4879 0 : SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
4880 :
4881 : ToolbarSaveInData* pToolbarSaveInData = ( ToolbarSaveInData* )
4882 0 : pPage->GetSaveInData();
4883 :
4884 0 : pToolbarSaveInData->ApplyToolbar( pToolbar );
4885 :
4886 0 : SetCheckButtonState( pEntry, pEntryData->IsVisible() ?
4887 0 : SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
4888 : }
4889 : }
4890 0 : }
4891 :
4892 0 : void SvxToolbarEntriesListBox::CheckButtonHdl()
4893 : {
4894 0 : ChangeVisibility( GetHdlEntry() );
4895 0 : }
4896 :
4897 0 : void SvxToolbarEntriesListBox::KeyInput( const KeyEvent& rKeyEvent )
4898 : {
4899 : // space key will change visibility of toolbar items
4900 0 : if ( rKeyEvent.GetKeyCode() == KEY_SPACE )
4901 : {
4902 0 : ChangeVisibility( GetCurEntry() );
4903 : }
4904 : else
4905 : {
4906 : // pass on to superclass
4907 0 : SvxMenuEntriesListBox::KeyInput( rKeyEvent );
4908 : }
4909 0 : }
4910 :
4911 0 : sal_Bool SvxToolbarEntriesListBox::NotifyMoving(
4912 : SvTreeListEntry* pTarget, SvTreeListEntry* pSource,
4913 : SvTreeListEntry*& rpNewParent, sal_uLong& rNewChildPos)
4914 : {
4915 : bool result = SvxMenuEntriesListBox::NotifyMoving(
4916 0 : pTarget, pSource, rpNewParent, rNewChildPos );
4917 :
4918 0 : if ( result == sal_True )
4919 : {
4920 : // Instant Apply changes to UI
4921 0 : SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
4922 0 : if ( pToolbar != NULL )
4923 : {
4924 : ToolbarSaveInData* pSaveInData =
4925 0 : ( ToolbarSaveInData*) pPage->GetSaveInData();
4926 0 : pSaveInData->ApplyToolbar( pToolbar );
4927 : }
4928 : }
4929 :
4930 0 : return result;
4931 : }
4932 :
4933 0 : sal_Bool SvxToolbarEntriesListBox::NotifyCopying(
4934 : SvTreeListEntry* pTarget,
4935 : SvTreeListEntry* pSource,
4936 : SvTreeListEntry*& rpNewParent,
4937 : sal_uLong& rNewChildPos)
4938 : {
4939 : (void)pSource;
4940 : (void)rpNewParent;
4941 : (void)rNewChildPos;
4942 :
4943 0 : if ( !m_bIsInternalDrag )
4944 : {
4945 : // if the target is NULL then add function to the start of the list
4946 0 : ((SvxToolbarConfigPage*)pPage)->AddFunction( pTarget, pTarget == NULL );
4947 :
4948 : // Instant Apply changes to UI
4949 0 : SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection();
4950 0 : if ( pToolbar != NULL )
4951 : {
4952 : ToolbarSaveInData* pSaveInData =
4953 0 : ( ToolbarSaveInData*) pPage->GetSaveInData();
4954 0 : pSaveInData->ApplyToolbar( pToolbar );
4955 : }
4956 :
4957 : // AddFunction already adds the listbox entry so return FALSE
4958 : // to stop another listbox entry being added
4959 0 : return sal_False;
4960 : }
4961 :
4962 : // Copying is only allowed from external controls, not within the listbox
4963 0 : return sal_False;
4964 : }
4965 :
4966 0 : SvxNewToolbarDialog::SvxNewToolbarDialog(
4967 : Window* pWindow, const String& rName )
4968 : :
4969 0 : ModalDialog ( pWindow, CUI_RES( MD_NEW_TOOLBAR ) ),
4970 0 : aFtDescription ( this, CUI_RES( FT_NAME ) ),
4971 0 : aEdtName ( this, CUI_RES( EDT_STRING ) ),
4972 0 : aSaveInText ( this, CUI_RES( TXT_SAVEIN ) ),
4973 0 : aBtnOK ( this, CUI_RES( BTN_OK ) ),
4974 0 : aBtnCancel ( this, CUI_RES( BTN_CANCEL ) ),
4975 0 : aBtnHelp ( this, CUI_RES( BTN_HELP ) ),
4976 0 : aSaveInListBox ( this, CUI_RES( LB_SAVEIN ) )
4977 : {
4978 0 : FreeResource();
4979 :
4980 0 : aEdtName.SetText( rName );
4981 0 : aEdtName.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
4982 0 : ModifyHdl(&aEdtName);
4983 0 : aEdtName.SetModifyHdl(LINK(this, SvxNewToolbarDialog, ModifyHdl));
4984 0 : }
4985 :
4986 0 : IMPL_LINK(SvxNewToolbarDialog, ModifyHdl, Edit*, pEdit)
4987 : {
4988 : (void)pEdit;
4989 :
4990 0 : if(aCheckNameHdl.IsSet())
4991 0 : aBtnOK.Enable(aCheckNameHdl.Call(this) > 0);
4992 :
4993 0 : return 0;
4994 : }
4995 :
4996 : /*******************************************************************************
4997 : *
4998 : * The SvxIconSelectorDialog class
4999 : *
5000 : *******************************************************************************/
5001 0 : SvxIconSelectorDialog::SvxIconSelectorDialog( Window *pWindow,
5002 : const uno::Reference< css::ui::XImageManager >& rXImageManager,
5003 : const uno::Reference< css::ui::XImageManager >& rXParentImageManager )
5004 : :
5005 0 : ModalDialog ( pWindow, CUI_RES( MD_ICONSELECTOR ) ),
5006 0 : aFtDescription ( this, CUI_RES( FT_SYMBOLS ) ),
5007 0 : aTbSymbol ( this, CUI_RES( TB_SYMBOLS ) ),
5008 0 : aFtNote ( this, CUI_RES( FT_NOTE ) ),
5009 0 : aBtnOK ( this, CUI_RES( BTN_OK ) ),
5010 0 : aBtnCancel ( this, CUI_RES( BTN_CANCEL ) ),
5011 0 : aBtnHelp ( this, CUI_RES( BTN_HELP ) ),
5012 0 : aBtnImport ( this, CUI_RES( BTN_IMPORT ) ),
5013 0 : aBtnDelete ( this, CUI_RES( BTN_DELETE ) ),
5014 0 : aFlSeparator ( this, CUI_RES( FL_SEPARATOR ) ),
5015 : m_nNextId ( 0 ),
5016 : m_xImageManager ( rXImageManager ),
5017 0 : m_xParentImageManager( rXParentImageManager )
5018 : {
5019 0 : FreeResource();
5020 :
5021 : typedef ::boost::unordered_map< ::rtl::OUString,
5022 : bool,
5023 : ::rtl::OUStringHash,
5024 : ::std::equal_to< ::rtl::OUString > > ImageInfo;
5025 :
5026 0 : aTbSymbol.SetPageScroll( sal_True );
5027 :
5028 0 : bool bLargeIcons = GetImageType() & css::ui::ImageType::SIZE_LARGE;
5029 0 : m_nExpectedSize = bLargeIcons ? 26 : 16;
5030 :
5031 0 : if ( m_nExpectedSize != 16 )
5032 : {
5033 0 : aFtNote.SetText( replaceSixteen( aFtNote.GetText(), m_nExpectedSize ) );
5034 : }
5035 :
5036 : uno::Reference< lang::XMultiServiceFactory > xServiceManager =
5037 0 : ::comphelper::getProcessServiceFactory();
5038 : uno::Reference< uno::XComponentContext > xComponentContext =
5039 0 : ::comphelper::getProcessComponentContext();
5040 :
5041 : m_xGraphProvider = uno::Reference< graphic::XGraphicProvider >(
5042 0 : graphic::GraphicProvider::create( xComponentContext ) );
5043 :
5044 : uno::Reference< beans::XPropertySet > xPropSet(
5045 0 : xServiceManager->createInstance( ::rtl::OUString("com.sun.star.util.PathSettings" ) ),
5046 0 : uno::UNO_QUERY );
5047 :
5048 0 : uno::Any aAny = xPropSet->getPropertyValue( ::rtl::OUString( "UserConfig" ) );
5049 :
5050 0 : ::rtl::OUString aDirectory;
5051 :
5052 0 : aAny >>= aDirectory;
5053 :
5054 0 : sal_Int32 aCount = aDirectory.getLength();
5055 :
5056 0 : if ( aCount > 0 )
5057 : {
5058 0 : sal_Unicode aChar = aDirectory[ aCount-1 ];
5059 0 : if ( aChar != '/')
5060 : {
5061 0 : aDirectory += ::rtl::OUString( "/" );
5062 : }
5063 : }
5064 : else
5065 : {
5066 0 : aBtnImport.Enable( sal_False );
5067 : }
5068 :
5069 0 : aDirectory += ::rtl::OUString( "soffice.cfg/import" );
5070 :
5071 : uno::Reference< lang::XSingleServiceFactory > xStorageFactory(
5072 0 : ::com::sun::star::embed::FileSystemStorageFactory::create( xComponentContext ) );
5073 :
5074 0 : uno::Sequence< uno::Any > aArgs( 2 );
5075 0 : aArgs[ 0 ] <<= aDirectory;
5076 0 : aArgs[ 1 ] <<= com::sun::star::embed::ElementModes::READWRITE;
5077 :
5078 : uno::Reference< com::sun::star::embed::XStorage > xStorage(
5079 0 : xStorageFactory->createInstanceWithArguments( aArgs ), uno::UNO_QUERY );
5080 :
5081 0 : uno::Sequence< uno::Any > aProp( 2 );
5082 0 : beans::PropertyValue aPropValue;
5083 :
5084 0 : aPropValue.Name = ::rtl::OUString( "UserConfigStorage" );
5085 0 : aPropValue.Value <<= xStorage;
5086 0 : aProp[ 0 ] <<= aPropValue;
5087 :
5088 0 : aPropValue.Name = ::rtl::OUString( "OpenMode" );
5089 0 : aPropValue.Value <<= com::sun::star::embed::ElementModes::READWRITE;
5090 0 : aProp[ 1 ] <<= aPropValue;
5091 :
5092 : m_xImportedImageManager = uno::Reference< com::sun::star::ui::XImageManager >(
5093 0 : xServiceManager->createInstanceWithArguments(
5094 0 : ::rtl::OUString("com.sun.star.ui.ImageManager" ), aProp ),
5095 0 : uno::UNO_QUERY );
5096 :
5097 0 : ImageInfo mImageInfo;
5098 0 : uno::Sequence< OUString > names;
5099 0 : if ( m_xImportedImageManager.is() )
5100 : {
5101 0 : names = m_xImportedImageManager->getAllImageNames( GetImageType() );
5102 0 : for ( sal_Int32 n = 0; n < names.getLength(); ++n )
5103 0 : mImageInfo.insert( ImageInfo::value_type( names[n], false ));
5104 : }
5105 0 : sal_uInt16 nId = 1;
5106 0 : ImageInfo::const_iterator pConstIter = mImageInfo.begin();
5107 0 : uno::Sequence< OUString > name( 1 );
5108 0 : while ( pConstIter != mImageInfo.end() )
5109 : {
5110 0 : name[ 0 ] = pConstIter->first;
5111 0 : uno::Sequence< uno::Reference< graphic::XGraphic> > graphics = m_xImportedImageManager->getImages( GetImageType(), name );
5112 0 : if ( graphics.getLength() > 0 )
5113 : {
5114 0 : Image img = Image( graphics[ 0 ] );
5115 0 : aTbSymbol.InsertItem( nId, img, pConstIter->first );
5116 :
5117 0 : graphics[ 0 ]->acquire();
5118 :
5119 : aTbSymbol.SetItemData(
5120 0 : nId, static_cast< void * > ( graphics[ 0 ].get() ) );
5121 :
5122 0 : ++nId;
5123 : }
5124 0 : ++pConstIter;
5125 0 : }
5126 :
5127 0 : ImageInfo aImageInfo;
5128 :
5129 0 : if ( m_xParentImageManager.is() )
5130 : {
5131 0 : names = m_xParentImageManager->getAllImageNames( GetImageType() );
5132 0 : for ( sal_Int32 n = 0; n < names.getLength(); ++n )
5133 0 : aImageInfo.insert( ImageInfo::value_type( names[n], false ));
5134 : }
5135 :
5136 0 : names = m_xImageManager->getAllImageNames( GetImageType() );
5137 0 : for ( sal_Int32 n = 0; n < names.getLength(); ++n )
5138 : {
5139 0 : ImageInfo::iterator pIter = aImageInfo.find( names[n] );
5140 0 : if ( pIter != aImageInfo.end() )
5141 0 : pIter->second = true;
5142 : else
5143 0 : aImageInfo.insert( ImageInfo::value_type( names[n], true ));
5144 : }
5145 :
5146 : // large growth factor, expecting many entries
5147 0 : pConstIter = aImageInfo.begin();
5148 0 : while ( pConstIter != aImageInfo.end() )
5149 : {
5150 0 : name[ 0 ] = pConstIter->first;
5151 :
5152 0 : uno::Sequence< uno::Reference< graphic::XGraphic> > graphics;
5153 : try
5154 : {
5155 0 : if ( pConstIter->second )
5156 0 : graphics = m_xImageManager->getImages( GetImageType(), name );
5157 : else
5158 0 : graphics = m_xParentImageManager->getImages( GetImageType(), name );
5159 : }
5160 0 : catch ( uno::Exception& )
5161 : {
5162 : // can't get sequence for this name so it will not be
5163 : // added to the list
5164 : }
5165 :
5166 0 : if ( graphics.getLength() > 0 )
5167 : {
5168 0 : Image img = Image( graphics[ 0 ] );
5169 0 : aTbSymbol.InsertItem( nId, img, pConstIter->first );
5170 :
5171 0 : uno::Reference< graphic::XGraphic > xGraphic = graphics[ 0 ];
5172 :
5173 0 : if ( xGraphic.is() )
5174 0 : xGraphic->acquire();
5175 :
5176 : aTbSymbol.SetItemData(
5177 0 : nId, static_cast< void * > ( xGraphic.get() ) );
5178 :
5179 0 : ++nId;
5180 : }
5181 :
5182 0 : ++pConstIter;
5183 0 : }
5184 :
5185 0 : aBtnDelete.Enable( sal_False );
5186 0 : aTbSymbol.SetSelectHdl( LINK(this, SvxIconSelectorDialog, SelectHdl) );
5187 0 : aBtnImport.SetClickHdl( LINK(this, SvxIconSelectorDialog, ImportHdl) );
5188 0 : aBtnDelete.SetClickHdl( LINK(this, SvxIconSelectorDialog, DeleteHdl) );
5189 :
5190 0 : m_nNextId = aTbSymbol.GetItemCount()+1;
5191 0 : }
5192 :
5193 0 : SvxIconSelectorDialog::~SvxIconSelectorDialog()
5194 : {
5195 0 : sal_uInt16 nCount = aTbSymbol.GetItemCount();
5196 :
5197 0 : for (sal_uInt16 n = 0; n < nCount; ++n )
5198 : {
5199 0 : sal_uInt16 nId = aTbSymbol.GetItemId(n);
5200 :
5201 : uno::XInterface* xi = static_cast< uno::XInterface* >(
5202 0 : aTbSymbol.GetItemData( nId ) );
5203 :
5204 0 : if ( xi != NULL )
5205 : {
5206 0 : xi->release();
5207 : }
5208 : }
5209 0 : }
5210 :
5211 0 : uno::Reference< graphic::XGraphic> SvxIconSelectorDialog::GetSelectedIcon()
5212 : {
5213 0 : uno::Reference< graphic::XGraphic > result;
5214 :
5215 : sal_uInt16 nId;
5216 0 : for ( sal_uInt16 n = 0; n < aTbSymbol.GetItemCount(); ++n )
5217 : {
5218 0 : nId = aTbSymbol.GetItemId( n );
5219 0 : if ( aTbSymbol.IsItemChecked( nId ) )
5220 : {
5221 : result = uno::Reference< graphic::XGraphic >(
5222 : reinterpret_cast< graphic::XGraphic* >(
5223 0 : aTbSymbol.GetItemData( nId ) ) );
5224 : }
5225 : }
5226 :
5227 0 : return result;
5228 : }
5229 :
5230 0 : IMPL_LINK( SvxIconSelectorDialog, SelectHdl, ToolBox *, pToolBox )
5231 : {
5232 : (void)pToolBox;
5233 :
5234 0 : sal_uInt16 nCount = aTbSymbol.GetItemCount();
5235 :
5236 0 : for (sal_uInt16 n = 0; n < nCount; ++n )
5237 : {
5238 0 : sal_uInt16 nId = aTbSymbol.GetItemId( n );
5239 :
5240 0 : if ( aTbSymbol.IsItemChecked( nId ) )
5241 : {
5242 0 : aTbSymbol.CheckItem( nId, sal_False );
5243 : }
5244 : }
5245 :
5246 0 : sal_uInt16 nId = aTbSymbol.GetCurItemId();
5247 0 : aTbSymbol.CheckItem( nId );
5248 :
5249 0 : ::rtl::OUString aSelImageText = aTbSymbol.GetItemText( nId );
5250 0 : if ( m_xImportedImageManager->hasImage( GetImageType(), aSelImageText ) )
5251 : {
5252 0 : aBtnDelete.Enable( sal_True );
5253 : }
5254 : else
5255 : {
5256 0 : aBtnDelete.Enable( sal_False );
5257 : }
5258 :
5259 0 : return 0;
5260 : }
5261 :
5262 0 : IMPL_LINK( SvxIconSelectorDialog, ImportHdl, PushButton *, pButton )
5263 : {
5264 : (void)pButton;
5265 :
5266 : sfx2::FileDialogHelper aImportDialog(
5267 : css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW,
5268 0 : SFXWB_GRAPHIC | SFXWB_MULTISELECTION );
5269 :
5270 : // disable the link checkbox in the dialog
5271 : uno::Reference< css::ui::dialogs::XFilePickerControlAccess >
5272 0 : xController( aImportDialog.GetFilePicker(), uno::UNO_QUERY);
5273 0 : if ( xController.is() )
5274 : {
5275 0 : xController->enableControl(
5276 : css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK,
5277 0 : sal_False);
5278 : }
5279 :
5280 : aImportDialog.SetCurrentFilter(
5281 0 : rtl::OUString("PNG - Portable Network Graphic"));
5282 :
5283 0 : if ( ERRCODE_NONE == aImportDialog.Execute() )
5284 : {
5285 0 : uno::Sequence< OUString > paths = aImportDialog.GetMPath();
5286 0 : ImportGraphics ( paths );
5287 : }
5288 :
5289 0 : return 0;
5290 : }
5291 :
5292 0 : IMPL_LINK( SvxIconSelectorDialog, DeleteHdl, PushButton *, pButton )
5293 : {
5294 : (void)pButton;
5295 :
5296 0 : OUString message = String( CUI_RES( RID_SVXSTR_DELETE_ICON_CONFIRM ) );
5297 0 : bool ret = WarningBox( this, WinBits(WB_OK_CANCEL), message ).Execute();
5298 :
5299 0 : if ( ret == RET_OK )
5300 : {
5301 0 : sal_uInt16 nCount = aTbSymbol.GetItemCount();
5302 :
5303 0 : for (sal_uInt16 n = 0; n < nCount; ++n )
5304 : {
5305 0 : sal_uInt16 nId = aTbSymbol.GetItemId( n );
5306 :
5307 0 : if ( aTbSymbol.IsItemChecked( nId ) )
5308 : {
5309 0 : ::rtl::OUString aSelImageText = aTbSymbol.GetItemText( nId );
5310 0 : uno::Sequence< OUString > URLs(1);
5311 0 : URLs[0] = aSelImageText;
5312 0 : aTbSymbol.RemoveItem( aTbSymbol.GetItemPos( nId ) );
5313 0 : m_xImportedImageManager->removeImages( GetImageType(), URLs );
5314 : uno::Reference< css::ui::XUIConfigurationPersistence >
5315 0 : xConfigPersistence( m_xImportedImageManager, uno::UNO_QUERY );
5316 0 : if ( xConfigPersistence.is() && xConfigPersistence->isModified() )
5317 : {
5318 0 : xConfigPersistence->store();
5319 : }
5320 0 : break;
5321 : }
5322 : }
5323 : }
5324 0 : return 0;
5325 : }
5326 :
5327 0 : bool SvxIconSelectorDialog::ReplaceGraphicItem(
5328 : const ::rtl::OUString& aURL )
5329 : {
5330 0 : uno::Sequence< OUString > URLs(1);
5331 0 : uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5332 : uno::Reference< css::ui::XUIConfigurationPersistence >
5333 0 : xConfigPer( m_xImportedImageManager, uno::UNO_QUERY );
5334 :
5335 0 : uno::Reference< graphic::XGraphic > xGraphic;
5336 0 : uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5337 0 : aMediaProps[0].Name = ::rtl::OUString("URL" );
5338 0 : aMediaProps[0].Value <<= aURL;
5339 :
5340 0 : com::sun::star::awt::Size aSize;
5341 0 : bool bOK = sal_False;
5342 : try
5343 : {
5344 0 : xGraphic = m_xGraphProvider->queryGraphic( aMediaProps );
5345 :
5346 : uno::Reference< beans::XPropertySet > props =
5347 0 : m_xGraphProvider->queryGraphicDescriptor( aMediaProps );
5348 0 : uno::Any a = props->getPropertyValue(
5349 0 : OUString("SizePixel") );
5350 0 : a >>= aSize;
5351 0 : if (0 == aSize.Width || 0 == aSize.Height)
5352 0 : return sal_False;
5353 : else
5354 0 : bOK = sal_True;
5355 : }
5356 0 : catch ( uno::Exception& )
5357 : {
5358 0 : return false;
5359 : }
5360 :
5361 0 : bool bResult( false );
5362 0 : sal_uInt16 nCount = aTbSymbol.GetItemCount();
5363 0 : for (sal_uInt16 n = 0; n < nCount; ++n )
5364 : {
5365 0 : sal_uInt16 nId = aTbSymbol.GetItemId( n );
5366 :
5367 0 : if ( OUString( aTbSymbol.GetItemText( nId ) ) == aURL )
5368 : {
5369 : try
5370 : {
5371 : // replace/insert image with provided URL
5372 0 : aTbSymbol.RemoveItem( aTbSymbol.GetItemPos( nId ) );
5373 0 : aMediaProps[0].Value <<= aURL;
5374 :
5375 0 : Image aImage( xGraphic );
5376 0 : if ( bOK && ((aSize.Width != m_nExpectedSize) || (aSize.Height != m_nExpectedSize)) )
5377 : {
5378 0 : BitmapEx aBitmap = aImage.GetBitmapEx();
5379 0 : BitmapEx aBitmapex = BitmapEx::AutoScaleBitmap(aBitmap, m_nExpectedSize);
5380 0 : aImage = Image( aBitmapex);
5381 : }
5382 0 : aTbSymbol.InsertItem( nId,aImage, aURL, 0, 0 ); //modify
5383 :
5384 0 : xGraphic = aImage.GetXGraphic();
5385 :
5386 0 : URLs[0] = aURL;
5387 0 : aImportGraph[ 0 ] = xGraphic;
5388 0 : m_xImportedImageManager->replaceImages( GetImageType(), URLs, aImportGraph );
5389 0 : xConfigPer->store();
5390 :
5391 0 : bResult = true;
5392 0 : break;
5393 : }
5394 0 : catch ( ::com::sun::star::uno::Exception& )
5395 : {
5396 : break;
5397 : }
5398 : }
5399 : }
5400 :
5401 0 : return bResult;
5402 : }
5403 :
5404 0 : void SvxIconSelectorDialog::ImportGraphics(
5405 : const uno::Sequence< OUString >& rPaths )
5406 : {
5407 0 : uno::Sequence< OUString > rejected( rPaths.getLength() );
5408 0 : sal_Int32 rejectedCount = 0;
5409 :
5410 0 : sal_uInt16 ret = 0;
5411 : sal_Int32 aIndex;
5412 0 : OUString aIconName;
5413 0 : uno::Sequence< OUString > URLs(1);
5414 0 : uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5415 0 : uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5416 0 : aMediaProps[0].Name = ::rtl::OUString("URL" );
5417 : uno::Reference< css::ui::XUIConfigurationPersistence >
5418 0 : xConfigPer( m_xImportedImageManager, uno::UNO_QUERY );
5419 :
5420 0 : if ( rPaths.getLength() == 1 )
5421 : {
5422 0 : if ( m_xImportedImageManager->hasImage( GetImageType(), rPaths[0] ) )
5423 : {
5424 0 : aIndex = rPaths[0].lastIndexOf( '/' );
5425 0 : aIconName = rPaths[0].copy( aIndex+1 );
5426 0 : ret = SvxIconReplacementDialog( this, aIconName ).ShowDialog();
5427 0 : if ( ret == 2 )
5428 : {
5429 0 : ReplaceGraphicItem( rPaths[0] );
5430 : }
5431 : }
5432 : else
5433 : {
5434 0 : if ( ImportGraphic( rPaths[0] ) == sal_False )
5435 : {
5436 0 : rejected[0] = rPaths[0];
5437 0 : rejectedCount = 1;
5438 : }
5439 : }
5440 : }
5441 : else
5442 : {
5443 0 : ::rtl::OUString aSourcePath( rPaths[0] );
5444 0 : if ( rPaths[0].lastIndexOf( '/' ) != rPaths[0].getLength() -1 )
5445 0 : aSourcePath = rPaths[0] + ::rtl::OUString("/" );
5446 :
5447 0 : for ( sal_Int32 i = 1; i < rPaths.getLength(); ++i )
5448 : {
5449 0 : ::rtl::OUString aPath = aSourcePath + rPaths[i];
5450 0 : if ( m_xImportedImageManager->hasImage( GetImageType(), aPath ) )
5451 : {
5452 0 : aIndex = rPaths[i].lastIndexOf( '/' );
5453 0 : aIconName = rPaths[i].copy( aIndex+1 );
5454 0 : ret = SvxIconReplacementDialog( this, aIconName, sal_True ).ShowDialog();
5455 0 : if ( ret == 2 )
5456 : {
5457 0 : ReplaceGraphicItem( aPath );
5458 : }
5459 0 : else if ( ret == 5 )
5460 : {
5461 0 : for ( sal_Int32 k = i; k < rPaths.getLength(); ++k )
5462 : {
5463 0 : aPath = aSourcePath + rPaths[k];
5464 0 : bool bHasReplaced = ReplaceGraphicItem( aPath );
5465 :
5466 0 : if ( !bHasReplaced )
5467 : {
5468 0 : bool result = ImportGraphic( aPath );
5469 0 : if ( result == sal_False )
5470 : {
5471 0 : rejected[ rejectedCount ] = rPaths[i];
5472 0 : ++rejectedCount;
5473 : }
5474 : }
5475 : }
5476 : break;
5477 : }
5478 : }
5479 : else
5480 : {
5481 0 : bool result = ImportGraphic( aSourcePath + rPaths[i] );
5482 0 : if ( result == sal_False )
5483 : {
5484 0 : rejected[ rejectedCount ] = rPaths[i];
5485 0 : ++rejectedCount;
5486 : }
5487 : }
5488 0 : }
5489 : }
5490 :
5491 0 : if ( rejectedCount != 0 )
5492 : {
5493 0 : OUString message;
5494 0 : OUString newLine("\n");
5495 0 : OUString fPath;
5496 0 : if (rejectedCount > 1)
5497 0 : fPath = rPaths[0].copy(8) + ::rtl::OUString("/" );
5498 0 : for ( sal_Int32 i = 0; i < rejectedCount; ++i )
5499 : {
5500 0 : message += fPath + rejected[i];
5501 0 : message += newLine;
5502 : }
5503 :
5504 0 : SvxIconChangeDialog aDialog(this, message);
5505 0 : aDialog.Execute();
5506 0 : }
5507 0 : }
5508 :
5509 0 : bool SvxIconSelectorDialog::ImportGraphic( const OUString& aURL )
5510 : {
5511 0 : bool result = sal_False;
5512 :
5513 0 : sal_uInt16 nId = m_nNextId;
5514 0 : ++m_nNextId;
5515 :
5516 0 : uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
5517 0 : aMediaProps[0].Name = ::rtl::OUString("URL" );
5518 :
5519 0 : uno::Reference< graphic::XGraphic > xGraphic;
5520 0 : com::sun::star::awt::Size aSize;
5521 0 : bool bOK = sal_True;
5522 0 : aMediaProps[0].Value <<= aURL;
5523 : try
5524 : {
5525 : uno::Reference< beans::XPropertySet > props =
5526 0 : m_xGraphProvider->queryGraphicDescriptor( aMediaProps );
5527 :
5528 0 : uno::Any a = props->getPropertyValue(
5529 0 : OUString("SizePixel") );
5530 :
5531 0 : xGraphic = m_xGraphProvider->queryGraphic( aMediaProps );
5532 0 : if ( xGraphic.is() )
5533 : {
5534 0 : a >>= aSize;
5535 0 : if ( 0 == aSize.Width || 0 == aSize.Height )
5536 0 : bOK = sal_False;
5537 :
5538 0 : Image aImage( xGraphic );
5539 :
5540 0 : if ( bOK && ((aSize.Width != m_nExpectedSize) || (aSize.Height != m_nExpectedSize)) )
5541 : {
5542 0 : BitmapEx aBitmap = aImage.GetBitmapEx();
5543 0 : BitmapEx aBitmapex = BitmapEx::AutoScaleBitmap(aBitmap, m_nExpectedSize);
5544 0 : aImage = Image( aBitmapex);
5545 : }
5546 0 : if ( bOK && !!aImage )
5547 : {
5548 0 : aTbSymbol.InsertItem( nId, aImage, aURL, 0, 0 );
5549 :
5550 0 : xGraphic = aImage.GetXGraphic();
5551 0 : xGraphic->acquire();
5552 :
5553 : aTbSymbol.SetItemData(
5554 0 : nId, static_cast< void * > ( xGraphic.get() ) );
5555 0 : uno::Sequence< OUString > aImportURL( 1 );
5556 0 : aImportURL[ 0 ] = aURL;
5557 0 : uno::Sequence< uno::Reference<graphic::XGraphic > > aImportGraph( 1 );
5558 0 : aImportGraph[ 0 ] = xGraphic;
5559 0 : m_xImportedImageManager->insertImages( GetImageType(), aImportURL, aImportGraph );
5560 : uno::Reference< css::ui::XUIConfigurationPersistence >
5561 0 : xConfigPersistence( m_xImportedImageManager, uno::UNO_QUERY );
5562 :
5563 0 : if ( xConfigPersistence.is() && xConfigPersistence->isModified() )
5564 : {
5565 0 : xConfigPersistence->store();
5566 : }
5567 :
5568 0 : result = sal_True;
5569 : }
5570 : else
5571 : {
5572 : OSL_TRACE("could not create Image from XGraphic");
5573 0 : }
5574 : }
5575 : else
5576 : {
5577 : OSL_TRACE("could not get query XGraphic");
5578 0 : }
5579 : }
5580 0 : catch( uno::Exception& e )
5581 : {
5582 : OSL_TRACE("Caught exception importing XGraphic: %s", PRTSTR(e.Message));
5583 : }
5584 0 : return result;
5585 : }
5586 :
5587 : /*******************************************************************************
5588 : *
5589 : * The SvxIconReplacementDialog class
5590 : *
5591 : *******************************************************************************/
5592 0 : SvxIconReplacementDialog :: SvxIconReplacementDialog(
5593 : Window *pWindow, const rtl::OUString& aMessage, bool /*bYestoAll*/ )
5594 : :
5595 0 : MessBox( pWindow, WB_DEF_YES, String( CUI_RES( RID_SVXSTR_REPLACE_ICON_CONFIRM ) ), String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) ) )
5596 :
5597 : {
5598 0 : SetImage( WarningBox::GetStandardImage() );
5599 0 : SetMessText( ReplaceIconName( aMessage ) );
5600 0 : RemoveButton( 1 );
5601 0 : AddButton( BUTTON_YES, 2, 0 );
5602 0 : AddButton( String( CUI_RES( RID_SVXSTR_YESTOALL ) ), 5, 0 );
5603 0 : AddButton( BUTTON_NO, 3, 0 );
5604 0 : AddButton( BUTTON_CANCEL, 4, 0 );
5605 0 : }
5606 :
5607 0 : SvxIconReplacementDialog :: SvxIconReplacementDialog(
5608 : Window *pWindow, const rtl::OUString& aMessage )
5609 : :
5610 0 : MessBox( pWindow, WB_YES_NO_CANCEL, String( CUI_RES( RID_SVXSTR_REPLACE_ICON_CONFIRM ) ), String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) ) )
5611 : {
5612 0 : SetImage( WarningBox::GetStandardImage() );
5613 0 : SetMessText( ReplaceIconName( aMessage ));
5614 0 : }
5615 :
5616 0 : rtl::OUString SvxIconReplacementDialog :: ReplaceIconName( const OUString& rMessage )
5617 : {
5618 0 : rtl::OUString name;
5619 0 : rtl::OUString message = String( CUI_RES( RID_SVXSTR_REPLACE_ICON_WARNING ) );
5620 0 : rtl::OUString placeholder("%ICONNAME" );
5621 0 : sal_Int32 pos = message.indexOf( placeholder );
5622 0 : if ( pos != -1 )
5623 : {
5624 : name = message.replaceAt(
5625 0 : pos, placeholder.getLength(), rMessage );
5626 : }
5627 0 : return name;
5628 : }
5629 :
5630 0 : sal_uInt16 SvxIconReplacementDialog :: ShowDialog()
5631 : {
5632 0 : this->Execute();
5633 0 : return ( this->GetCurButtonId() );
5634 : }
5635 : /*******************************************************************************
5636 : *
5637 : * The SvxIconChangeDialog class added for issue83555
5638 : *
5639 : *******************************************************************************/
5640 0 : SvxIconChangeDialog::SvxIconChangeDialog(
5641 : Window *pWindow, const rtl::OUString& aMessage)
5642 : :
5643 0 : ModalDialog ( pWindow, CUI_RES( MD_ICONCHANGE ) ),
5644 0 : aFImageInfo (this, CUI_RES( FI_INFO ) ),
5645 0 : aBtnOK (this, CUI_RES(MD_BTN_OK)),
5646 0 : aDescriptionLabel (this, CUI_RES(FTCHGE_DESCRIPTION)),
5647 0 : aLineEditDescription (this, CUI_RES(EDT_ADDR))
5648 : {
5649 0 : FreeResource();
5650 0 : aFImageInfo.SetImage(InfoBox::GetStandardImage());
5651 0 : aLineEditDescription.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
5652 0 : aLineEditDescription.SetAutoScroll( sal_True );
5653 0 : aLineEditDescription.EnableCursor( sal_False );
5654 0 : aLineEditDescription.SetText(aMessage);
5655 6 : }
5656 :
5657 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|