Update ooo320-m1
[ooovba.git] / filter / source / xsltdialog / xmlfiltersettingsdialog.cxx
blob7d02fd65f42071d237aa055a96bbd43bfd8e4356
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfiltersettingsdialog.cxx,v $
10 * $Revision: 1.24 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_filter.hxx"
33 #include <com/sun/star/frame/XConfigManager.hpp>
34 #include <com/sun/star/container/XNameAccess.hpp>
35 #include <com/sun/star/util/XFlushable.hpp>
37 #ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #endif
41 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
42 #include <tools/urlobj.hxx>
43 #include <svtools/headbar.hxx>
44 #include <unotools/streamwrap.hxx>
45 #include <osl/file.hxx>
46 #include <vcl/msgbox.hxx>
47 #include <sfx2/filedlghelper.hxx>
49 #include <rtl/uri.hxx>
51 #include <algorithm>
53 #include "xmlfilterdialogstrings.hrc"
54 #include "xmlfiltersettingsdialog.hxx"
55 #include "xmlfiltersettingsdialog.hrc"
56 #include "xmlfiltertabdialog.hxx"
57 #include "xmlfiltertestdialog.hxx"
58 #include "xmlfilterjar.hxx"
59 #include "xmlfilterhelpids.hrc"
61 using namespace rtl;
62 using namespace osl;
63 using namespace com::sun::star::lang;
64 using namespace com::sun::star::uno;
65 using namespace com::sun::star::io;
66 using namespace com::sun::star::frame;
67 using namespace com::sun::star::container;
68 using namespace com::sun::star::beans;
69 using namespace com::sun::star::util;
71 ResMgr* XMLFilterSettingsDialog::mpResMgr = NULL;
73 XMLFilterSettingsDialog::XMLFilterSettingsDialog( Window* pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF ) :
74 WorkWindow( pParent, ResId( DLG_XML_FILTER_SETTINGS_DIALOG, rResMgr ) ),
75 mxMSF( rxMSF ),
76 maCtrlFilterList( this, ResId( CTRL_XML_FILTER_LIST, rResMgr ) ),
77 maPBNew( this, ResId( PB_XML_FILTER_NEW, rResMgr ) ),
78 maPBEdit( this, ResId( PB_XML_FILTER_EDIT, rResMgr ) ),
79 maPBTest( this, ResId( PB_XML_FILTER_TEST, rResMgr ) ),
80 maPBDelete( this, ResId( PB_XML_FILTER_DELETE, rResMgr ) ),
81 maPBSave( this, ResId( PB_XML_FILTER_SAVE, rResMgr ) ),
82 maPBOpen( this, ResId( PB_XML_FILTER_OPEN, rResMgr ) ),
83 maPBHelp( this, ResId( BTN_XML_FILTER_HELP, rResMgr ) ),
84 maPBClose( this, ResId( PB_XML_FILTER_CLOSE, rResMgr ) ),
85 mbIsClosable(true),
86 sTemplatePath( RTL_CONSTASCII_USTRINGPARAM( "$(user)/template/") ),
87 sDocTypePrefix( RTL_CONSTASCII_USTRINGPARAM( "doctype:") )
89 FreeResource();
91 mpResMgr = &rResMgr;
93 mpFilterListBox = new XMLFilterListBox( &maCtrlFilterList );
94 mpFilterListBox->SetSelectHdl( LINK( this, XMLFilterSettingsDialog, SelectionChangedHdl_Impl ) );
95 mpFilterListBox->SetDeselectHdl( LINK( this, XMLFilterSettingsDialog, SelectionChangedHdl_Impl ) );
96 mpFilterListBox->SetDoubleClickHdl( LINK( this, XMLFilterSettingsDialog, DoubleClickHdl_Impl ) );
97 mpFilterListBox->SetHelpId( HID_XML_FILTER_LIST );
99 maPBNew.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
100 maPBEdit.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
101 maPBTest.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
102 maPBDelete.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
103 maPBSave.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
104 maPBOpen.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
105 maPBClose.SetClickHdl(LINK( this, XMLFilterSettingsDialog, ClickHdl_Impl ) );
109 mxFilterContainer = Reference< XNameContainer >::query( rxMSF->createInstance( OUString::createFromAscii("com.sun.star.document.FilterFactory" ) ) );
110 mxTypeDetection = Reference< XNameContainer >::query( rxMSF->createInstance( OUString::createFromAscii("com.sun.star.document.TypeDetection" ) ));
111 mxExtendedTypeDetection = Reference< XNameContainer >::query( rxMSF->createInstance( OUString::createFromAscii("com.sun.star.document.ExtendedTypeDetectionFactory" ) ) );
113 Reference< XConfigManager > xCfgMgr( mxMSF->createInstance(OUString::createFromAscii("com.sun.star.config.SpecialConfigManager") ), UNO_QUERY );
114 if( xCfgMgr.is() )
116 sTemplatePath = xCfgMgr->substituteVariables( sTemplatePath );
119 catch(Exception&)
121 DBG_ERROR( "XMLFilterSettingsDialog::XMLFilterSettingsDialog exception catched!" );
125 // -----------------------------------------------------------------------
127 XMLFilterSettingsDialog::~XMLFilterSettingsDialog()
129 delete mpFilterListBox;
132 // -----------------------------------------------------------------------
134 IMPL_LINK(XMLFilterSettingsDialog, ClickHdl_Impl, PushButton *, pButton )
136 mbIsClosable = false;
138 if( &maPBNew == pButton )
140 onNew();
142 else if( &maPBEdit == pButton )
144 onEdit();
146 else if( &maPBTest == pButton )
148 onTest();
150 else if( &maPBDelete == pButton )
152 onDelete();
154 else if( &maPBSave == pButton )
156 onSave();
158 else if( &maPBOpen == pButton )
160 onOpen();
162 else if( &maPBClose == pButton )
164 onClose();
167 mbIsClosable = true;
168 return 0;
171 // -----------------------------------------------------------------------
173 IMPL_LINK(XMLFilterSettingsDialog, SelectionChangedHdl_Impl, void *, EMPTYARG )
175 updateStates();
176 return 0;
179 // -----------------------------------------------------------------------
181 IMPL_LINK(XMLFilterSettingsDialog, DoubleClickHdl_Impl, void *, EMPTYARG )
183 onEdit();
184 return 0;
187 bool XMLFilterSettingsDialog::isClosable()
189 return mbIsClosable;
192 // -----------------------------------------------------------------------
194 void XMLFilterSettingsDialog::ShowWindow()
196 maCtrlFilterList.GrabFocus();
197 disposeFilterList();
198 mpFilterListBox->Clear();
199 initFilterList();
200 updateStates();
201 mpFilterListBox->Reset();
203 WorkWindow::Show( TRUE );
206 // -----------------------------------------------------------------------
208 void XMLFilterSettingsDialog::updateStates()
210 SvLBoxEntry* pSelectedEntry = mpFilterListBox->FirstSelected();
212 bool bHasSelection = pSelectedEntry != NULL;
214 bool bMultiSelection = bHasSelection && (mpFilterListBox->NextSelected( pSelectedEntry ) != NULL );
215 bool bIsReadonly = false;
216 bool bIsDefault = false;
217 if(pSelectedEntry)
219 filter_info_impl* pInfo = (filter_info_impl*)pSelectedEntry->GetUserData();
220 bIsReadonly = 0 != pInfo->mbReadonly;
222 sal_Int32 nFact = SvtModuleOptions::E_WRITER;
223 while(nFact <= SvtModuleOptions::E_BASIC)
225 ::rtl::OUString sDefault = maModuleOpt.GetFactoryDefaultFilter((SvtModuleOptions::EFactory)nFact);
226 if( sDefault == pInfo->maFilterName )
228 bIsDefault = true;
229 break;
231 ++nFact;
234 maPBEdit.Enable( bHasSelection && !bMultiSelection && !bIsReadonly);
235 maPBTest.Enable( bHasSelection && !bMultiSelection );
236 maPBDelete.Enable( bHasSelection && !bMultiSelection && !bIsReadonly && !bIsDefault);
237 maPBSave.Enable( bHasSelection );
240 // -----------------------------------------------------------------------
242 /** is called when the user clicks on the "New" button */
243 void XMLFilterSettingsDialog::onNew()
245 filter_info_impl aTempInfo;
247 // create a unique filter name
248 aTempInfo.maFilterName = createUniqueFilterName( String( RESID( STR_DEFAULT_FILTER_NAME ) ) );
250 // init default extension
251 String aDefaultExtension( RESID( STR_DEFAULT_EXTENSION ) );
252 aTempInfo.maExtension = aDefaultExtension;
254 // set default ui name
255 aTempInfo.maInterfaceName = createUniqueInterfaceName( String( RESID( STR_DEFAULT_UI_NAME ) ) );
257 // set default application
258 aTempInfo.maDocumentService = OUString::createFromAscii("com.sun.star.text.TextDocument");
260 // execute XML Filter Dialog
261 XMLFilterTabDialog aDlg( this, *mpResMgr, mxMSF, &aTempInfo );
262 if ( aDlg.Execute() == RET_OK )
264 // insert the new filter
265 insertOrEdit( aDlg.getNewFilterInfo() );
269 // -----------------------------------------------------------------------
271 /** is called when the user clicks on the "Edit" Button */
272 void XMLFilterSettingsDialog::onEdit()
274 // get selected filter entry
275 SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected();
276 if( pEntry )
278 // get its filter info
279 filter_info_impl* pOldInfo = (filter_info_impl*)pEntry->GetUserData();
281 // execute XML Filter Dialog
282 XMLFilterTabDialog aDlg( this, *mpResMgr, mxMSF, pOldInfo );
283 if ( aDlg.Execute() == RET_OK )
285 filter_info_impl* pNewInfo = aDlg.getNewFilterInfo();
287 if( !(*pOldInfo == *pNewInfo) )
289 // change filter
290 insertOrEdit( pNewInfo, pOldInfo );
296 // -----------------------------------------------------------------------
298 /** helper to create a sequence of strings from an extensions strings
299 "ext1;ext2;ext3" will become { "ext1", "ext2", "ext3" } */
300 static Sequence< OUString > createExtensionsSequence( const rtl::OUString& rExtensions )
302 // first count how many extensions we have inside the string
303 int nExtensions = 0;
305 int nLength = rExtensions.getLength();
306 if( nLength )
308 // a non empty string has at least one extension
309 nExtensions++;
311 // now count the delimeters ';'
312 const sal_Unicode * pString = rExtensions.getStr();
313 int i;
314 for( i = 0; i < nLength; i++, pString++ )
316 if( *pString == sal_Unicode( ';' ) )
317 nExtensions++;
321 Sequence< OUString > aExtensions( nExtensions );
323 // extract the extensions from the source string and fill the sequence
325 int nLastIndex = 0;
326 int nCurrentIndex = 0;
327 int i;
329 for( i = 0; i < nExtensions; i++ )
331 nLastIndex = rExtensions.indexOf( sal_Unicode( ';' ), nLastIndex );
333 if( nLastIndex == -1 )
335 aExtensions[i] = rExtensions.copy( nCurrentIndex );
336 break;
338 else
340 aExtensions[i] = rExtensions.copy( nCurrentIndex, nLastIndex - nCurrentIndex );
341 nCurrentIndex = nLastIndex + 1;
342 nLastIndex = nCurrentIndex;
346 return aExtensions;
349 // -----------------------------------------------------------------------
351 /** checks if the given name is unique inside the filter factory. If not,
352 numbers are added until the returned name is unique */
353 OUString XMLFilterSettingsDialog::createUniqueFilterName( const OUString& rFilterName )
355 OUString aFilterName( rFilterName );
356 OUString aSpace( sal_Unicode( ' ' ) );
358 sal_Int32 nId = 2;
360 while( mxFilterContainer->hasByName( aFilterName ) )
362 aFilterName = rFilterName;
363 aFilterName += aSpace;
364 aFilterName += OUString::valueOf( nId++ );
367 return aFilterName;
370 // -----------------------------------------------------------------------
372 /** checks if the given name is unique inside the type detection. If not,
373 numbers are added until the returned name is unique */
374 OUString XMLFilterSettingsDialog::createUniqueTypeName( const OUString& rTypeName )
376 OUString aTypeName( rTypeName );
377 OUString aSpace( sal_Unicode( ' ' ) );
379 sal_Int32 nId = 2;
381 while( mxFilterContainer->hasByName( aTypeName ) )
383 aTypeName = rTypeName;
384 aTypeName += aSpace;
385 aTypeName += OUString::valueOf( nId++ );
388 return aTypeName;
391 /** checks if the given name is a unique ui name inside the filter factory. If not,
392 numbers are added until the returned name is unique */
393 OUString XMLFilterSettingsDialog::createUniqueInterfaceName( const OUString& rInterfaceName )
395 sal_Int32 nDefaultNumber = 0;
399 Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() );
400 OUString* pFilterName = aFilterNames.getArray();
402 const sal_Int32 nCount = aFilterNames.getLength();
403 sal_Int32 nFilter;
405 Sequence< PropertyValue > aValues;
406 for( nFilter = 0; (nFilter < nCount); nFilter++, pFilterName++ )
408 Any aAny( mxFilterContainer->getByName( *pFilterName ) );
409 if( !(aAny >>= aValues) )
410 continue;
412 const sal_Int32 nValueCount( aValues.getLength() );
413 PropertyValue* pValues = aValues.getArray();
414 sal_Int32 nValue;
416 for( nValue = 0; nValue < nValueCount; nValue++, pValues++ )
418 if( pValues->Name.equalsAscii( "UIName" ) )
420 OUString aInterfaceName;
421 pValues->Value >>= aInterfaceName;
424 // see if this filter matches our default filter name
425 if( aInterfaceName.match( rInterfaceName ) )
427 // if yes, make sure we generate a unique name with a higher number
428 // this is dump but fast
429 sal_Int32 nNumber = aInterfaceName.copy( rInterfaceName.getLength() ).toInt32();
430 if( nNumber >= nDefaultNumber )
431 nDefaultNumber = nNumber + 1;
437 catch( Exception& )
439 DBG_ERROR( "XMLFilterSettingsDialog::createUniqueInterfaceName exception catched!" );
442 OUString aInterfaceName( rInterfaceName );
443 if( nDefaultNumber )
445 aInterfaceName += OUString( sal_Unicode( ' ' ) );
446 aInterfaceName += String::CreateFromInt32( nDefaultNumber );
449 return aInterfaceName;
452 // -----------------------------------------------------------------------
454 /** inserts a new filter into the ui and configuration if pOldInfo is NULL.
455 If pOldInfo is not null, the old filter will be replaced with the new settings */
456 bool XMLFilterSettingsDialog::insertOrEdit( filter_info_impl* pNewInfo, const filter_info_impl* pOldInfo )
458 bool bOk = true;
460 if( pOldInfo )
462 // see if we need to update the type name
463 if( pOldInfo->maFilterName != pNewInfo->maFilterName )
465 if( pOldInfo->maType == pOldInfo->maFilterName )
467 pNewInfo->maType = OUString();
471 // see if we need to clean up old stuff first
474 // if filter name changed, we need to remove the old filter first
475 if( pOldInfo->maFilterName != pNewInfo->maFilterName )
476 mxFilterContainer->removeByName( pOldInfo->maFilterName );
478 // if type name changed, we need to remove the old type first
479 if( pOldInfo->maType != pNewInfo->maType )
480 mxTypeDetection->removeByName( pOldInfo->maType );
482 catch( Exception& )
484 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
485 bOk = false;
489 filter_info_impl* pFilterEntry( NULL );
491 if( bOk )
493 // create or copy filter info
494 if( pOldInfo )
496 // change existing filter entry in filter list box
497 pFilterEntry = const_cast<filter_info_impl*>(pOldInfo);
498 *pFilterEntry = *pNewInfo;
500 else
502 // add new entry to filter list box
503 pFilterEntry = new filter_info_impl( *pNewInfo );
507 // check if we need to copy the template
508 if( pFilterEntry->maImportTemplate.getLength() )
510 if( !pFilterEntry->maImportTemplate.matchIgnoreAsciiCase( sTemplatePath ) )
512 INetURLObject aSourceURL( pFilterEntry->maImportTemplate );
513 if( aSourceURL.GetName().getLength() != 0 )
515 OUString aDestURL( sTemplatePath );
516 aDestURL += pFilterEntry->maFilterName;
517 aDestURL += OUString( sal_Unicode('/') );
518 if( createDirectory( aDestURL ) )
520 aDestURL += aSourceURL.GetName();
522 SvFileStream aInputStream(pFilterEntry->maImportTemplate, STREAM_READ );
523 Reference< XInputStream > xIS( new utl::OInputStreamWrapper( aInputStream ) );
524 SvFileStream aOutputStream(aDestURL, STREAM_WRITE );
525 Reference< XOutputStream > xOS( new utl::OOutputStreamWrapper( aOutputStream ) );
527 if( copyStreams( xIS, xOS ) )
528 pFilterEntry->maImportTemplate = aDestURL;
534 if( bOk )
536 if( pFilterEntry->maType.getLength() == 0 )
538 pFilterEntry->maType = createUniqueTypeName( pNewInfo->maFilterName );
541 // update import/export flags
542 if( pFilterEntry->maImportXSLT.getLength() )
544 pFilterEntry->maFlags |= 1;
546 else
548 pFilterEntry->maFlags &= ~1;
551 if( pFilterEntry->maExportXSLT.getLength() )
553 pFilterEntry->maFlags |= 2;
555 else
557 pFilterEntry->maFlags &= ~2;
559 pFilterEntry->maFlags |= 0x80040;
561 // 2. create user data for filter entry
562 Sequence< OUString > aUserData( pFilterEntry->getFilterUserData());
564 // 3. create property values for filter entry
565 Sequence< PropertyValue > aFilterData( 8 );
567 aFilterData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ) );
568 aFilterData[0].Value <<= pFilterEntry->maType;
570 aFilterData[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ) );
571 aFilterData[1].Value <<= pFilterEntry->maInterfaceName;
573 aFilterData[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ) );
574 aFilterData[2].Value <<= pFilterEntry->maDocumentService;
576 aFilterData[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterService" ) );
577 aFilterData[3].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) );
579 aFilterData[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Flags" ) );
580 aFilterData[4].Value <<= pFilterEntry->maFlags;
582 aFilterData[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "UserData" ) );
583 aFilterData[5].Value <<= aUserData;
585 aFilterData[6].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FileFormatVersion" ) );
586 aFilterData[6].Value <<= pFilterEntry->maFileFormatVersion;
588 aFilterData[7].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "TemplateName" ) );
589 aFilterData[7].Value <<= pFilterEntry->maImportTemplate;
591 // 4. insert new or replace existing filter
594 Any aAny( makeAny( aFilterData ) );
595 if( mxFilterContainer->hasByName( pFilterEntry->maFilterName ) )
597 mxFilterContainer->replaceByName( pFilterEntry->maFilterName, aAny );
599 else
601 mxFilterContainer->insertByName( pFilterEntry->maFilterName, aAny );
604 catch( Exception& )
606 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
607 bOk = false;
611 // 5. prepare type information
612 if( bOk )
614 Sequence< PropertyValue > aValues(4);
616 aValues[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ) );
617 aValues[0].Value <<= pFilterEntry->maInterfaceName;
619 aValues[i ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
620 aValues[i++].Value <<= pFilterEntry->maDocType;
622 aValues[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "ClipboardFormat" ) );
623 OUString aDocType;
624 if( !pFilterEntry->maDocType.match( sDocTypePrefix ) )
626 aDocType = sDocTypePrefix;
627 aDocType += pFilterEntry->maDocType;
629 else
631 aDocType = pFilterEntry->maDocType;
633 if (aDocType == sDocTypePrefix)
634 aValues[1].Value <<= OUString();
635 else
636 aValues[1].Value <<= aDocType;
638 aValues[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentIconID" ) );
639 aValues[2].Value <<= pFilterEntry->mnDocumentIconID;
641 aValues[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Extensions" ) );
642 aValues[3].Value <<= createExtensionsSequence( pFilterEntry->maExtension );
644 // the detect service will only be registered, if a doctype/search token was specified
645 if (aDocType.getLength() > sDocTypePrefix.getLength())
647 aValues.realloc(5);
648 aValues[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DetectService" ) );
649 aValues[4].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.filters.XMLFilterDetect" ) );
652 // 6. insert new or replace existing type information
653 if( mxTypeDetection.is() )
657 Any aAny( makeAny( aValues ) );
658 if( mxTypeDetection->hasByName( pFilterEntry->maType ) )
660 mxTypeDetection->replaceByName( pFilterEntry->maType, aAny );
662 else
664 mxTypeDetection->insertByName( pFilterEntry->maType, aAny );
667 catch( Exception& )
669 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
670 bOk = false;
674 if( bOk )
678 Reference< XFlushable > xFlushable = Reference< XFlushable >::query( mxTypeDetection );
679 if( xFlushable.is() )
680 xFlushable->flush();
682 catch( Exception& )
684 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
685 bOk = false;
689 if( !bOk )
691 // we failed to add the type, so lets remove the filter
694 mxFilterContainer->removeByName( pFilterEntry->maFilterName );
696 catch( Exception& )
698 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
699 bOk = false;
702 else
704 if( bOk )
708 Reference< XFlushable > xFlushable( mxFilterContainer, UNO_QUERY );
709 if( xFlushable.is() )
710 xFlushable->flush();
712 catch( Exception& )
714 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
715 bOk = false;
718 if( !bOk )
720 // we failed to add the filter, so lets remove the type
723 mxTypeDetection->removeByName( pFilterEntry->maType );
725 catch( Exception& )
727 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
735 if( bOk )
737 if( mxExtendedTypeDetection.is() )
739 OUString sFilterDetectService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.filters.XMLFilterDetect") );
740 if( mxExtendedTypeDetection->hasByName( sFilterDetectService ) )
742 Sequence< PropertyValue > aSequence;
743 if( mxExtendedTypeDetection->getByName( sFilterDetectService ) >>= aSequence )
745 sal_Int32 nCount = aSequence.getLength();
746 sal_Int32 nIndex;
747 for( nIndex = 0; nIndex < nCount; nIndex++ )
749 OUString aName( aSequence[nIndex].Name );
750 if( aSequence[nIndex].Name.equalsAscii( "Types" ) )
752 Sequence< OUString > aTypes;
753 if( aSequence[nIndex].Value >>= aTypes )
755 sal_Int32 nStrCount = aTypes.getLength();
756 sal_Int32 nStr;
757 for( nStr = 0; nStr < nStrCount; nStr++ )
759 OUString aType( aTypes[nStr] );
760 if( aTypes[nStr] == pFilterEntry->maType )
761 break;
764 if( nStr == nStrCount )
766 aTypes.realloc( nStrCount + 1 );
767 aTypes[nStrCount] = pFilterEntry->maType;
769 aSequence[nIndex].Value <<= aTypes;
771 mxExtendedTypeDetection->replaceByName( sFilterDetectService, makeAny( aSequence ) );
773 Reference< XFlushable > xFlushable( mxExtendedTypeDetection, UNO_QUERY );
774 if( xFlushable.is() )
775 xFlushable->flush();
779 break;
787 // update ui
788 if( bOk )
790 if( pOldInfo )
792 mpFilterListBox->changeEntry( pFilterEntry );
794 else
796 mpFilterListBox->addFilterEntry( pFilterEntry );
797 maFilterVector.push_back( pFilterEntry );
801 return bOk;
804 // -----------------------------------------------------------------------
806 /** is called when the user clicks the "Test" button */
807 void XMLFilterSettingsDialog::onTest()
809 // get the first selected filter
810 SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected();
811 if( pEntry )
813 filter_info_impl* pInfo = (filter_info_impl*)pEntry->GetUserData();
815 XMLFilterTestDialog aDlg( this, *mpResMgr, mxMSF );
816 aDlg.test( *pInfo );
820 // -----------------------------------------------------------------------
822 void XMLFilterSettingsDialog::onDelete()
824 SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected();
825 if( pEntry )
827 filter_info_impl* pInfo = (filter_info_impl*)pEntry->GetUserData();
829 String aPlaceHolder( RTL_CONSTASCII_USTRINGPARAM("%s") );
830 String aMessage(RESID(STR_WARN_DELETE));
831 aMessage.SearchAndReplace( aPlaceHolder, pInfo->maFilterName );
833 WarningBox aWarnBox(this, (WinBits)(WB_YES_NO | WB_DEF_YES), aMessage );
834 if( aWarnBox.Execute() == RET_YES )
838 if( mxFilterContainer->hasByName( pInfo->maFilterName ) )
840 mxFilterContainer->removeByName( pInfo->maFilterName );
842 bool bTypeStillUsed = false;
844 // now loop over all filter and see if someone else uses the same type
845 Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() );
846 OUString* pFilterName = aFilterNames.getArray();
848 const sal_Int32 nCount = aFilterNames.getLength();
849 sal_Int32 nFilter;
850 Sequence< PropertyValue > aValues;
852 for( nFilter = 0; (nFilter < nCount) && !bTypeStillUsed; nFilter++, pFilterName++ )
854 Any aAny( mxFilterContainer->getByName( *pFilterName ) );
855 if( !(aAny >>= aValues) )
856 continue;
858 const sal_Int32 nValueCount( aValues.getLength() );
859 PropertyValue* pValues = aValues.getArray();
860 sal_Int32 nValue;
862 for( nValue = 0; (nValue < nValueCount) && !bTypeStillUsed; nValue++, pValues++ )
864 if( pValues->Name.equalsAscii( "Type" ) )
866 OUString aType;
867 pValues->Value >>= aType;
868 if( aType == pInfo->maType )
869 bTypeStillUsed = true;
871 break;
876 // if the type is not used anymore, remove it also
877 if( !bTypeStillUsed )
879 if( mxTypeDetection->hasByName( pInfo->maType ) )
881 mxTypeDetection->removeByName( pInfo->maType );
885 Reference< XFlushable > xFlushable( mxFilterContainer, UNO_QUERY );
886 if( xFlushable.is() )
887 xFlushable->flush();
889 xFlushable = Reference< XFlushable >::query( mxTypeDetection );
890 if( xFlushable.is() )
891 xFlushable->flush();
893 // now remove entry from ui
894 mpFilterListBox->RemoveSelection();
896 // and delete the filter entry
897 maFilterVector.erase(std::find( maFilterVector.begin(), maFilterVector.end(), pInfo ));
899 delete pInfo;
902 catch( Exception& )
904 DBG_ERROR( "XMLFilterSettingsDialog::onDelete exception catched!" );
909 updateStates();
912 // -----------------------------------------------------------------------
914 void XMLFilterSettingsDialog::onSave()
916 XMLFilterVector aFilters;
918 int nFilters = 0;
920 SvLBoxEntry* pEntry = mpFilterListBox->FirstSelected();
921 while( pEntry )
923 filter_info_impl* pInfo = (filter_info_impl*)pEntry->GetUserData();
924 aFilters.push_back( pInfo );
925 pEntry = mpFilterListBox->NextSelected( pEntry );
926 nFilters++;
929 // Open Fileopen-Dialog
930 ::sfx2::FileDialogHelper aDlg(
931 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
932 0 );
934 String aExtensions( RTL_CONSTASCII_USTRINGPARAM("*.jar") );
935 String aFilterName( RESID( STR_FILTER_PACKAGE ) );
936 aFilterName += String( RTL_CONSTASCII_USTRINGPARAM(" (") );
937 aFilterName += aExtensions;
938 aFilterName += sal_Unicode(')');
940 aDlg.AddFilter( aFilterName, aExtensions );
942 if ( aDlg.Execute() == ERRCODE_NONE )
944 XMLFilterJarHelper aJarHelper( mxMSF );
945 aJarHelper.savePackage( aDlg.GetPath(), aFilters );
947 INetURLObject aURL( aDlg.GetPath() );
949 String sPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%s" ) );
951 String aMsg;
952 if( nFilters > 0 )
954 aMsg = String( RESID( STR_FILTERS_HAVE_BEEN_SAVED ) );
955 aMsg.SearchAndReplace( sPlaceholder, String::CreateFromInt32(nFilters) );
956 aMsg.SearchAndReplace( sPlaceholder, aURL.GetName() );
958 else
960 aMsg = String( RESID( STR_FILTER_HAS_BEEN_SAVED ) );
961 aMsg.SearchAndReplace( sPlaceholder, (*aFilters.begin())->maFilterName );
962 aMsg.SearchAndReplace( sPlaceholder, aURL.GetName() );
965 InfoBox aBox(this, aMsg );
966 aBox.Execute();
970 // -----------------------------------------------------------------------
972 void XMLFilterSettingsDialog::onOpen()
974 XMLFilterVector aFilters;
976 // Open Fileopen-Dialog
977 ::sfx2::FileDialogHelper aDlg(
978 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
980 String aExtensions( RTL_CONSTASCII_USTRINGPARAM("*.jar") );
981 String aFilterName( RESID( STR_FILTER_PACKAGE ) );
982 aFilterName += String( RTL_CONSTASCII_USTRINGPARAM(" (") );
983 aFilterName += aExtensions;
984 aFilterName += sal_Unicode(')');
986 aDlg.AddFilter( aFilterName, aExtensions );
988 if ( aDlg.Execute() == ERRCODE_NONE )
990 OUString aURL( aDlg.GetPath() );
992 XMLFilterJarHelper aJarHelper( mxMSF );
993 aJarHelper.openPackage( aURL, aFilters );
995 int nFilters = 0;
996 XMLFilterVector::iterator aIter( aFilters.begin() );
997 while( aIter != aFilters.end() )
999 filter_info_impl* pInfo = (*aIter++);
1001 if( insertOrEdit( pInfo ) )
1003 aFilterName = pInfo->maFilterName;
1004 nFilters++;
1007 delete pInfo;
1010 disposeFilterList();
1011 initFilterList();
1013 String sPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%s" ) );
1014 String aMsg;
1015 if( nFilters == 0 )
1017 INetURLObject aURLObj( aURL );
1018 aMsg = String( RESID( STR_NO_FILTERS_FOUND ) );
1019 aMsg.SearchAndReplace( sPlaceholder, aURLObj.GetName() );
1021 else if( nFilters == 1 )
1023 aMsg = String( RESID( STR_FILTER_INSTALLED ) );
1024 aMsg.SearchAndReplace( sPlaceholder, aFilterName );
1027 else
1029 aMsg = String( RESID( STR_FILTERS_INSTALLED ) );
1030 aMsg.SearchAndReplace( sPlaceholder, String::CreateFromInt32(nFilters) );
1033 InfoBox aBox(this, aMsg );
1034 aBox.Execute();
1038 // -----------------------------------------------------------------------
1040 void XMLFilterSettingsDialog::onClose()
1042 Close();
1045 long XMLFilterSettingsDialog::Notify( NotifyEvent& rNEvt )
1047 // Zuerst Basisklasse rufen wegen TabSteuerung
1048 long nRet = WorkWindow::Notify( rNEvt );
1049 if ( !nRet )
1051 if ( rNEvt.GetType() == EVENT_KEYINPUT )
1053 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1054 KeyCode aKeyCode = pKEvt->GetKeyCode();
1055 USHORT nKeyCode = aKeyCode.GetCode();
1057 if( nKeyCode == KEY_ESCAPE )
1059 Close();
1060 return TRUE;
1065 return nRet;
1068 // -----------------------------------------------------------------------
1070 void XMLFilterSettingsDialog::disposeFilterList()
1072 std::vector< filter_info_impl* >::iterator aIter( maFilterVector.begin() );
1073 while( aIter != maFilterVector.end() )
1075 delete (*aIter++);
1077 maFilterVector.clear();
1079 mpFilterListBox->Clear();
1082 // -----------------------------------------------------------------------
1084 void XMLFilterSettingsDialog::initFilterList()
1086 if( mxFilterContainer.is() )
1088 Sequence< OUString > aFilterNames( mxFilterContainer->getElementNames() );
1089 OUString* pFilterName = aFilterNames.getArray();
1091 const sal_Int32 nCount = aFilterNames.getLength();
1092 sal_Int32 nFilter;
1094 Sequence< PropertyValue > aValues;
1096 filter_info_impl* pTempFilter = new filter_info_impl;
1097 Sequence< OUString > aUserData;
1099 for( nFilter = 0; nFilter < nCount; nFilter++, pFilterName++ )
1101 aUserData.realloc(0);
1105 Any aAny( mxFilterContainer->getByName( *pFilterName ) );
1106 if( !(aAny >>= aValues) )
1107 continue;
1109 OUString aFilterService;
1110 pTempFilter->maFilterName = *pFilterName;
1112 const sal_Int32 nValueCount( aValues.getLength() );
1113 PropertyValue* pValues = aValues.getArray();
1114 sal_Int32 nValue;
1116 for( nValue = 0; nValue < nValueCount; nValue++, pValues++ )
1118 if( pValues->Name.equalsAscii( "Type" ) )
1120 pValues->Value >>= pTempFilter->maType;
1122 else if( pValues->Name.equalsAscii( "UIName" ) )
1124 pValues->Value >>= pTempFilter->maInterfaceName;
1126 else if( pValues->Name.equalsAscii( "DocumentService" ) )
1128 pValues->Value >>= pTempFilter->maDocumentService;
1130 else if( pValues->Name.equalsAscii( "FilterService" ) )
1132 pValues->Value >>= aFilterService;
1134 else if( pValues->Name.equalsAscii( "Flags" ) )
1136 pValues->Value >>= pTempFilter->maFlags;
1138 else if( pValues->Name.equalsAscii( "UserData" ) )
1140 pValues->Value >>= aUserData;
1142 else if( pValues->Name.equalsAscii( "FileFormatVersion" ) )
1144 pValues->Value >>= pTempFilter->maFileFormatVersion;
1146 else if( pValues->Name.equalsAscii( "TemplateName" ) )
1148 pValues->Value >>= pTempFilter->maImportTemplate;
1150 else if(pValues->Name.equalsAscii( "Finalized" ))
1152 pValues->Value >>= pTempFilter->mbReadonly;
1156 // if this is not a XmlFilterAdaptor entry, skip it
1157 if( !aFilterService.equalsAscii( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) )
1158 continue;
1161 // if we don't have the needed user data, skip it
1162 if( aUserData.getLength() < 6 )
1163 continue;
1165 // if this is not an XSLTFilter entry, skip it
1166 if( !aUserData[0].equalsAscii( "com.sun.star.documentconversion.XSLTFilter" ) )
1167 continue;
1169 // get filter information from userdata
1170 pTempFilter->maImportService = aUserData[2];
1171 pTempFilter->maExportService = aUserData[3];
1172 pTempFilter->maImportXSLT = aUserData[4];
1173 pTempFilter->maExportXSLT = aUserData[5];
1174 if( aUserData.getLength() >= 7 )
1175 pTempFilter->maDTD = aUserData[6];
1176 if( aUserData.getLength() >= 8 )
1177 pTempFilter->maComment = aUserData[7];
1179 // get type information
1180 if( mxTypeDetection.is() )
1184 aAny = mxTypeDetection->getByName( pTempFilter->maType );
1185 Sequence< PropertyValue > aValues2;
1187 if( aAny >>= aValues2 )
1189 const sal_Int32 nValueCount2( aValues2.getLength() );
1190 PropertyValue* pValues2 = aValues2.getArray();
1191 sal_Int32 nValue2;
1193 for( nValue2 = 0; nValue2 < nValueCount2; nValue2++, pValues2++ )
1196 if( pValues2->Name.equalsAscii( "MediaType" ) )
1198 pValues2->Value >>= pTempFilter->maDocType;
1199 } else
1201 if( pValues2->Name.equalsAscii( "ClipboardFormat" ) )
1203 OUString aDocType;
1204 pValues2->Value >>= aDocType;
1206 if( aDocType.match( sDocTypePrefix ) )
1207 aDocType = aDocType.copy( sDocTypePrefix.getLength() );
1209 pTempFilter->maDocType = aDocType;
1211 else if( pValues2->Name.equalsAscii( "Extensions" ) )
1213 Sequence< OUString > aExtensions;
1214 if( pValues2->Value >>= aExtensions )
1216 pTempFilter->maExtension = OUString();
1218 sal_Int32 nCount3( aExtensions.getLength() );
1219 OUString* pExtensions = aExtensions.getArray();
1220 sal_Int32 n;
1221 for( n = 0; n < nCount3; n++ )
1223 if( n > 0 )
1224 pTempFilter->maExtension += OUString( sal_Unicode(';') );
1225 pTempFilter->maExtension += (*pExtensions++);
1229 else if( pValues2->Name.equalsAscii( "DocumentIconID" ) )
1231 pValues2->Value >>= pTempFilter->mnDocumentIconID;
1233 else if(pValues2->Name.equalsAscii( "Finalized" ))
1235 // both the filter and the type may be finalized
1236 sal_Bool bTemp = sal_False;
1237 pValues2->Value >>= bTemp;
1238 pTempFilter->mbReadonly |= bTemp;
1243 catch( ::com::sun::star::container::NoSuchElementException& )
1245 DBG_ERROR( "Type not found, user error?" ); // TODO: error?
1249 // add entry to internal container and to ui filter list box
1250 maFilterVector.push_back( pTempFilter );
1251 mpFilterListBox->addFilterEntry( pTempFilter );
1254 pTempFilter = new filter_info_impl;
1256 catch( Exception& )
1258 DBG_ERROR( "XMLFilterSettingsDialog::initFilterList exception catched!" );
1263 delete pTempFilter;
1266 SvLBoxEntry* pEntry = mpFilterListBox->GetEntry( 0 );
1267 if( pEntry )
1268 mpFilterListBox->Select( pEntry );
1271 // -----------------------------------------------------------------------
1273 // -----------------------------------------------------------------------
1275 application_info_impl::application_info_impl( const sal_Char * pDocumentService, ResId& rUINameRes, const sal_Char * mpXMLImporter, const sal_Char * mpXMLExporter )
1276 : maDocumentService( pDocumentService, strlen( pDocumentService ), RTL_TEXTENCODING_ASCII_US ),
1277 maDocumentUIName( String( rUINameRes ) ),
1278 maXMLImporter( mpXMLImporter, strlen( mpXMLImporter ), RTL_TEXTENCODING_ASCII_US ),
1279 maXMLExporter( mpXMLExporter, strlen( mpXMLExporter ), RTL_TEXTENCODING_ASCII_US )
1283 // -----------------------------------------------------------------------
1285 std::vector< application_info_impl* >& getApplicationInfos()
1287 static std::vector< application_info_impl* > aInfos;
1289 if( aInfos.empty() )
1291 ResId aResId1( STR_APPL_NAME_WRITER, *getXSLTDialogResMgr() );
1292 aInfos.push_back( new application_info_impl(
1293 "com.sun.star.text.TextDocument",
1294 aResId1,
1295 "com.sun.star.comp.Writer.XMLImporter",
1296 "com.sun.star.comp.Writer.XMLExporter" ) );
1298 ResId aResId2( STR_APPL_NAME_CALC, *getXSLTDialogResMgr() );
1299 aInfos.push_back( new application_info_impl(
1300 "com.sun.star.sheet.SpreadsheetDocument",
1301 aResId2,
1302 "com.sun.star.comp.Calc.XMLImporter",
1303 "com.sun.star.comp.Calc.XMLExporter" ) );
1305 ResId aResId3( STR_APPL_NAME_IMPRESS, *getXSLTDialogResMgr() );
1306 aInfos.push_back( new application_info_impl(
1307 "com.sun.star.presentation.PresentationDocument",
1308 aResId3,
1309 "com.sun.star.comp.Impress.XMLImporter",
1310 "com.sun.star.comp.Impress.XMLExporter" ) );
1312 ResId aResId4( STR_APPL_NAME_DRAW, *getXSLTDialogResMgr() );
1313 aInfos.push_back( new application_info_impl(
1314 "com.sun.star.drawing.DrawingDocument",
1315 aResId4,
1316 "com.sun.star.comp.Draw.XMLImporter",
1317 "com.sun.star.comp.Draw.XMLExporter" ) );
1319 // --- oasis file formats...
1320 ResId aResId5( STR_APPL_NAME_OASIS_WRITER, *getXSLTDialogResMgr() );
1321 aInfos.push_back( new application_info_impl(
1322 "com.sun.star.text.TextDocument",
1323 aResId5,
1324 "com.sun.star.comp.Writer.XMLOasisImporter",
1325 "com.sun.star.comp.Writer.XMLOasisExporter" ) );
1327 ResId aResId6( STR_APPL_NAME_OASIS_CALC, *getXSLTDialogResMgr() );
1328 aInfos.push_back( new application_info_impl(
1329 "com.sun.star.sheet.SpreadsheetDocument",
1330 aResId6,
1331 "com.sun.star.comp.Calc.XMLOasisImporter",
1332 "com.sun.star.comp.Calc.XMLOasisExporter" ) );
1334 ResId aResId7( STR_APPL_NAME_OASIS_IMPRESS, *getXSLTDialogResMgr() );
1335 aInfos.push_back( new application_info_impl(
1336 "com.sun.star.presentation.PresentationDocument",
1337 aResId7,
1338 "com.sun.star.comp.Impress.XMLOasisImporter",
1339 "com.sun.star.comp.Impress.XMLOasisExporter" ) );
1341 ResId aResId8( STR_APPL_NAME_OASIS_DRAW, *getXSLTDialogResMgr() );
1342 aInfos.push_back( new application_info_impl(
1343 "com.sun.star.drawing.DrawingDocument",
1344 aResId8,
1345 "com.sun.star.comp.Draw.XMLOasisImporter",
1346 "com.sun.star.comp.Draw.XMLOasisExporter" ) );
1349 return aInfos;
1352 // -----------------------------------------------------------------------
1354 const application_info_impl* getApplicationInfo( const OUString& rServiceName )
1356 std::vector< application_info_impl* >& rInfos = getApplicationInfos();
1357 std::vector< application_info_impl* >::iterator aIter( rInfos.begin() );
1358 while( aIter != rInfos.end() )
1360 // if( rServiceName == (*aIter)->maDocumentService )
1361 if( rServiceName == (*aIter)->maXMLExporter ||
1362 rServiceName == (*aIter)->maXMLImporter)
1364 return (*aIter);
1366 aIter++;
1368 return NULL;
1371 // -----------------------------------------------------------------------
1373 OUString getApplicationUIName( const OUString& rServiceName )
1375 const application_info_impl* pInfo = getApplicationInfo( rServiceName );
1376 if( pInfo )
1378 return pInfo->maDocumentUIName;
1380 else
1382 OUString aRet = String( RESID( STR_UNKNOWN_APPLICATION ) );
1383 if( rServiceName.getLength() )
1385 aRet += OUString::createFromAscii(" (");
1386 aRet += rServiceName;
1387 aRet += OUString::createFromAscii(")");
1389 return aRet;
1393 // -----------------------------------------------------------------------
1395 ResMgr* getXSLTDialogResMgr()
1397 return XMLFilterSettingsDialog::mpResMgr;
1400 // -----------------------------------------------------------------------
1402 // -----------------------------------------------------------------------
1404 long SvxPathControl_Impl::Notify( NotifyEvent& rNEvt )
1406 long nRet = Control::Notify( rNEvt );
1408 if ( m_pFocusCtrl && rNEvt.GetWindow() != m_pFocusCtrl && rNEvt.GetType() == EVENT_GETFOCUS )
1409 m_pFocusCtrl->GrabFocus();
1410 return nRet;
1413 #define ITEMID_NAME 1
1414 #define ITEMID_TYPE 2
1416 XMLFilterListBox::XMLFilterListBox( SvxPathControl_Impl * pParent )
1417 : SvTabListBox( pParent, WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ),
1418 mbFirstPaint( true )
1420 Size aBoxSize( pParent->GetOutputSizePixel() );
1422 mpHeaderBar = new HeaderBar( pParent, /*WB_BUTTONSTYLE | */ WB_BOTTOMBORDER );
1423 mpHeaderBar->SetPosSizePixel( Point( 0, 0 ), Size( aBoxSize.Width(), 16 ) );
1424 mpHeaderBar->SetEndDragHdl( LINK( this, XMLFilterListBox, HeaderEndDrag_Impl ) );
1426 String aStr1( RESID( STR_COLUMN_HEADER_NAME ) );
1427 String aStr2( RESID( STR_COLUMN_HEADER_TYPE ) );
1429 long nTabSize = aBoxSize.Width() / 2;
1431 mpHeaderBar->InsertItem( ITEMID_NAME, aStr1, nTabSize,
1432 HIB_LEFT | HIB_VCENTER );
1433 mpHeaderBar->InsertItem( ITEMID_TYPE, aStr2, nTabSize,
1434 HIB_LEFT | HIB_VCENTER );
1436 static long nTabs[] = {3, 0, nTabSize, 2*nTabSize };
1437 Size aHeadSize( mpHeaderBar->GetSizePixel() );
1439 WinBits nBits = WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP;
1440 pParent->SetFocusControl( this );
1441 SetWindowBits( nBits );
1442 // SetDoubleClickHdl( aLink );
1443 // SetSelectHdl( LINK( this, SvxPathTabPage, PathSelect_Impl ) );
1444 SetSelectionMode( MULTIPLE_SELECTION );
1445 SetPosSizePixel( Point( 0, aHeadSize.Height() ), Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) );
1446 SetTabs( &nTabs[0], MAP_PIXEL );
1447 SetScrolledHdl( LINK( this, XMLFilterListBox, TabBoxScrollHdl_Impl ) );
1448 SetHighlightRange();
1449 // SetHelpId( HID_OPTPATH_CTL_PATH );
1450 // mpHeaderBar->SetHelpId( HID_OPTPATH_HEADERBAR );
1451 Show();
1452 mpHeaderBar->Show();
1455 // -----------------------------------------------------------------------
1457 XMLFilterListBox::~XMLFilterListBox()
1459 delete mpHeaderBar;
1462 // -----------------------------------------------------------------------
1464 void XMLFilterListBox::Reset()
1466 Size aBoxSize( Window::GetParent()->GetOutputSizePixel() );
1467 long nTabSize = aBoxSize.Width() / 2;
1468 static long nTabs[] = {3, 0, nTabSize, 2*nTabSize };
1469 SetTabs( &nTabs[0], MAP_PIXEL );
1470 mpHeaderBar->SetItemSize( ITEMID_NAME, nTabSize );
1471 mpHeaderBar->SetItemSize( ITEMID_TYPE, nTabSize );
1474 // -----------------------------------------------------------------------
1476 void XMLFilterListBox::Paint( const Rectangle& rRect )
1478 if( mbFirstPaint )
1480 mbFirstPaint = false;
1481 RepaintScrollBars();
1484 SvTabListBox::Paint( rRect );
1487 IMPL_LINK( XMLFilterListBox, TabBoxScrollHdl_Impl, SvTabListBox*, /* pList */ )
1489 mpHeaderBar->SetOffset( -GetXOffset() );
1490 return 0;
1493 // -----------------------------------------------------------------------
1495 IMPL_LINK( XMLFilterListBox, HeaderSelect_Impl, HeaderBar*, pBar )
1497 if ( pBar && pBar->GetCurItemId() != ITEMID_NAME )
1498 return 0;
1500 HeaderBarItemBits nBits = mpHeaderBar->GetItemBits(ITEMID_TYPE);
1501 BOOL bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
1502 SvSortMode eMode = SortAscending;
1504 if ( bUp )
1506 nBits &= ~HIB_UPARROW;
1507 nBits |= HIB_DOWNARROW;
1508 eMode = SortDescending;
1510 else
1512 nBits &= ~HIB_DOWNARROW;
1513 nBits |= HIB_UPARROW;
1515 mpHeaderBar->SetItemBits( ITEMID_NAME, nBits );
1516 SvTreeList* pMod = GetModel();
1517 pMod->SetSortMode( eMode );
1518 pMod->Resort();
1519 return 1;
1522 // -----------------------------------------------------------------------
1524 IMPL_LINK( XMLFilterListBox, HeaderEndDrag_Impl, HeaderBar*, pBar )
1526 if ( pBar && !pBar->GetCurItemId() )
1527 return 0;
1529 if ( !mpHeaderBar->IsItemMode() )
1531 Size aSz;
1532 USHORT nTabs = mpHeaderBar->GetItemCount();
1533 long nTmpSz = 0;
1534 long nWidth = mpHeaderBar->GetItemSize(ITEMID_NAME);
1535 long nBarWidth = mpHeaderBar->GetSizePixel().Width();
1537 if(nWidth < 30)
1538 mpHeaderBar->SetItemSize( ITEMID_TYPE, 30);
1539 else if ( ( nBarWidth - nWidth ) < 30 )
1540 mpHeaderBar->SetItemSize( ITEMID_TYPE, nBarWidth - 30 );
1542 for ( USHORT i = 1; i <= nTabs; ++i )
1544 long nW = mpHeaderBar->GetItemSize(i);
1545 aSz.Width() = nW + nTmpSz;
1546 nTmpSz += nW;
1547 SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
1550 return 1;
1553 // -----------------------------------------------------------------------
1555 /** adds a new filter info entry to the ui filter list */
1556 void XMLFilterListBox::addFilterEntry( const filter_info_impl* pInfo )
1558 const XubString aEntryStr( getEntryString( pInfo ) );
1559 InsertEntryToColumn( aEntryStr, LIST_APPEND, 0xffff, (void*)pInfo );
1562 // -----------------------------------------------------------------------
1564 void XMLFilterListBox::changeEntry( const filter_info_impl* pInfo )
1566 const ULONG nCount = GetEntryCount();
1567 ULONG nPos;
1568 for( nPos = 0; nPos < nCount; nPos++ )
1570 SvLBoxEntry* pEntry = GetEntry( nPos );
1571 if( (filter_info_impl*)pEntry->GetUserData() == pInfo )
1573 XubString aEntryText( getEntryString( pInfo ) );
1574 SetEntryText( aEntryText, pEntry );
1575 break;
1580 // -----------------------------------------------------------------------
1582 String XMLFilterListBox::getEntryString( const filter_info_impl* pInfo ) const
1584 String aEntryStr( pInfo->maFilterName );
1585 aEntryStr += '\t';
1586 // aEntryStr += String( getApplicationUIName( pInfo->maDocumentService ) );
1587 if ( pInfo->maExportService.getLength() > 0 )
1588 aEntryStr += String( getApplicationUIName( pInfo->maExportService ) );
1589 else
1590 aEntryStr += String( getApplicationUIName( pInfo->maImportService ) );
1591 aEntryStr += ' ';
1592 aEntryStr += '-';
1593 aEntryStr += ' ';
1595 if( pInfo->maFlags & 1 )
1597 if( pInfo->maFlags & 2 )
1599 aEntryStr += String( RESID( STR_IMPORT_EXPORT ) );
1601 else
1603 aEntryStr += String( RESID( STR_IMPORT_ONLY ) );
1606 else if( pInfo->maFlags & 2 )
1608 aEntryStr += String( RESID( STR_EXPORT_ONLY ) );
1610 else
1612 aEntryStr += String( RESID( STR_UNDEFINED_FILTER ) );
1615 return aEntryStr;
1618 // -----------------------------------------------------------------------
1620 // -----------------------------------------------------------------------
1622 filter_info_impl::filter_info_impl()
1623 : maFlags(0x00080040),
1624 maFileFormatVersion(0),
1625 mnDocumentIconID(0),
1626 mbReadonly(sal_False)
1630 // -----------------------------------------------------------------------
1632 filter_info_impl::filter_info_impl( const filter_info_impl& rInfo ) :
1633 maFilterName( rInfo.maFilterName ),
1634 maType( rInfo.maType ),
1635 maDocumentService( rInfo.maDocumentService ),
1636 maFilterService( rInfo.maFilterService ),
1637 maInterfaceName( rInfo.maInterfaceName ),
1638 maComment( rInfo.maComment ),
1639 maExtension( rInfo.maExtension ),
1640 maDTD( rInfo.maDTD ),
1641 maExportXSLT( rInfo.maExportXSLT ),
1642 maImportXSLT( rInfo.maImportXSLT ),
1643 maImportTemplate( rInfo.maImportTemplate ),
1644 maDocType( rInfo.maDocType ),
1645 maImportService( rInfo.maImportService ),
1646 maExportService( rInfo.maExportService ),
1647 maFlags( rInfo.maFlags ),
1648 maFileFormatVersion( rInfo.maFileFormatVersion ),
1649 mnDocumentIconID( rInfo.mnDocumentIconID ),
1650 mbReadonly( rInfo.mbReadonly )
1654 // -----------------------------------------------------------------------
1656 int filter_info_impl::operator==( const filter_info_impl& r ) const
1658 if( maFilterName != r.maFilterName ||
1659 maType != r.maType ||
1660 maDocumentService != r.maDocumentService ||
1661 maFilterService != r.maFilterService ||
1662 maInterfaceName != r.maInterfaceName ||
1663 maComment != r.maComment ||
1664 maExtension != r.maExtension ||
1665 maDocType != r.maDocType ||
1666 maDTD != r.maDTD ||
1667 maExportXSLT != r.maExportXSLT ||
1668 maImportXSLT != r.maImportXSLT ||
1669 maExportService != r.maExportService ||
1670 maImportService != r.maImportService ||
1671 maImportTemplate != r.maImportTemplate ||
1672 maFlags != r.maFlags ||
1673 maFileFormatVersion != r.maFileFormatVersion )
1674 return false;
1676 return true;
1679 // -----------------------------------------------------------------------
1681 Sequence< OUString > filter_info_impl::getFilterUserData() const
1683 Sequence< OUString > aUserData(8);
1685 aUserData[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.documentconversion.XSLTFilter" ) );
1687 const application_info_impl* pInfo = getApplicationInfo( maDocumentService );
1688 if( pInfo )
1690 aUserData[2] = pInfo->maXMLImporter;
1691 aUserData[3] = pInfo->maXMLExporter;
1694 aUserData[2] = maImportService;
1695 aUserData[3] = maExportService;
1696 aUserData[4] = maImportXSLT;
1697 aUserData[5] = maExportXSLT;
1698 aUserData[6] = maDTD;
1699 aUserData[7] = maComment;
1701 return aUserData;
1705 // -----------------------------------------------------------------------
1707 OUString string_encode( const OUString & rText )
1710 static sal_Bool const aCharClass[]
1711 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* UricNoSlash */
1712 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1713 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, /* !"#$%&'()*+,-./*/
1714 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, /*0123456789:;<=>?*/
1715 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*@ABCDEFGHIJKLMNO*/
1716 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /*PQRSTUVWXYZ[\]^_*/
1717 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*`abcdefghijklmno*/
1718 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 /*pqrstuvwxyz{|}~ */
1722 return Uri::encode( rText, aCharClass, rtl_UriEncodeCheckEscapes, RTL_TEXTENCODING_UTF8 );
1725 // -----------------------------------------------------------------------
1727 OUString string_decode( const OUString & rText )
1729 return Uri::decode( rText, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
1732 // -----------------------------------------------------------------------
1734 bool isFileURL( const ::rtl::OUString & rURL )
1736 return rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("file:") ) == 0;
1739 // -----------------------------------------------------------------------
1741 bool copyStreams( Reference< XInputStream > xIS, Reference< XOutputStream > xOS )
1745 sal_Int32 nBufferSize = 512;
1746 Sequence< sal_Int8 > aDataBuffer(nBufferSize);
1748 sal_Int32 nRead;
1751 nRead = xIS->readBytes( aDataBuffer, nBufferSize );
1753 if( nRead )
1755 if( nRead < nBufferSize )
1757 nBufferSize = nRead;
1758 aDataBuffer.realloc(nRead);
1761 xOS->writeBytes( aDataBuffer );
1764 while( nRead );
1766 xOS->flush();
1768 return true;
1770 catch(Exception&)
1772 DBG_ERROR( "copyStreams() exception catched!" );
1775 return false;
1778 // -----------------------------------------------------------------------
1780 bool createDirectory( OUString& rURL )
1782 sal_Int32 nLastIndex = sizeof( "file:///" ) - 2;
1783 while( nLastIndex != -1 )
1785 nLastIndex = rURL.indexOf( sal_Unicode('/'), nLastIndex + 1);
1786 if( nLastIndex != -1 )
1788 OUString aDirURL( rURL.copy( 0, nLastIndex ) );
1789 Directory aDir( aDirURL );
1790 Directory::RC rc = aDir.open();
1791 if( rc == Directory::E_NOENT )
1792 rc = osl::Directory::create( aDirURL );
1794 if( rc != Directory::E_None )
1796 return false;
1801 return true;