1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfiltersettingsdialog.cxx,v $
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>
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>
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"
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
) ),
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
) ),
86 sTemplatePath( RTL_CONSTASCII_USTRINGPARAM( "$(user)/template/") ),
87 sDocTypePrefix( RTL_CONSTASCII_USTRINGPARAM( "doctype:") )
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
);
116 sTemplatePath
= xCfgMgr
->substituteVariables( sTemplatePath
);
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
)
142 else if( &maPBEdit
== pButton
)
146 else if( &maPBTest
== pButton
)
150 else if( &maPBDelete
== pButton
)
154 else if( &maPBSave
== pButton
)
158 else if( &maPBOpen
== pButton
)
162 else if( &maPBClose
== pButton
)
171 // -----------------------------------------------------------------------
173 IMPL_LINK(XMLFilterSettingsDialog
, SelectionChangedHdl_Impl
, void *, EMPTYARG
)
179 // -----------------------------------------------------------------------
181 IMPL_LINK(XMLFilterSettingsDialog
, DoubleClickHdl_Impl
, void *, EMPTYARG
)
187 bool XMLFilterSettingsDialog::isClosable()
192 // -----------------------------------------------------------------------
194 void XMLFilterSettingsDialog::ShowWindow()
196 maCtrlFilterList
.GrabFocus();
198 mpFilterListBox
->Clear();
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;
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
)
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();
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
) )
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
305 int nLength
= rExtensions
.getLength();
308 // a non empty string has at least one extension
311 // now count the delimeters ';'
312 const sal_Unicode
* pString
= rExtensions
.getStr();
314 for( i
= 0; i
< nLength
; i
++, pString
++ )
316 if( *pString
== sal_Unicode( ';' ) )
321 Sequence
< OUString
> aExtensions( nExtensions
);
323 // extract the extensions from the source string and fill the sequence
326 int nCurrentIndex
= 0;
329 for( i
= 0; i
< nExtensions
; i
++ )
331 nLastIndex
= rExtensions
.indexOf( sal_Unicode( ';' ), nLastIndex
);
333 if( nLastIndex
== -1 )
335 aExtensions
[i
] = rExtensions
.copy( nCurrentIndex
);
340 aExtensions
[i
] = rExtensions
.copy( nCurrentIndex
, nLastIndex
- nCurrentIndex
);
341 nCurrentIndex
= nLastIndex
+ 1;
342 nLastIndex
= nCurrentIndex
;
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( ' ' ) );
360 while( mxFilterContainer
->hasByName( aFilterName
) )
362 aFilterName
= rFilterName
;
363 aFilterName
+= aSpace
;
364 aFilterName
+= OUString::valueOf( nId
++ );
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( ' ' ) );
381 while( mxFilterContainer
->hasByName( aTypeName
) )
383 aTypeName
= rTypeName
;
385 aTypeName
+= OUString::valueOf( nId
++ );
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();
405 Sequence
< PropertyValue
> aValues
;
406 for( nFilter
= 0; (nFilter
< nCount
); nFilter
++, pFilterName
++ )
408 Any
aAny( mxFilterContainer
->getByName( *pFilterName
) );
409 if( !(aAny
>>= aValues
) )
412 const sal_Int32
nValueCount( aValues
.getLength() );
413 PropertyValue
* pValues
= aValues
.getArray();
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;
439 DBG_ERROR( "XMLFilterSettingsDialog::createUniqueInterfaceName exception catched!" );
442 OUString
aInterfaceName( rInterfaceName
);
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
)
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
);
484 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
489 filter_info_impl
* pFilterEntry( NULL
);
493 // create or copy filter info
496 // change existing filter entry in filter list box
497 pFilterEntry
= const_cast<filter_info_impl
*>(pOldInfo
);
498 *pFilterEntry
= *pNewInfo
;
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
;
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;
548 pFilterEntry
->maFlags
&= ~1;
551 if( pFilterEntry
->maExportXSLT
.getLength() )
553 pFilterEntry
->maFlags
|= 2;
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
);
601 mxFilterContainer
->insertByName( pFilterEntry
->maFilterName
, aAny
);
606 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
611 // 5. prepare type information
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" ) );
624 if( !pFilterEntry
->maDocType
.match( sDocTypePrefix
) )
626 aDocType
= sDocTypePrefix
;
627 aDocType
+= pFilterEntry
->maDocType
;
631 aDocType
= pFilterEntry
->maDocType
;
633 if (aDocType
== sDocTypePrefix
)
634 aValues
[1].Value
<<= OUString();
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())
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
);
664 mxTypeDetection
->insertByName( pFilterEntry
->maType
, aAny
);
669 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
678 Reference
< XFlushable
> xFlushable
= Reference
< XFlushable
>::query( mxTypeDetection
);
679 if( xFlushable
.is() )
684 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
691 // we failed to add the type, so lets remove the filter
694 mxFilterContainer
->removeByName( pFilterEntry
->maFilterName
);
698 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
708 Reference
< XFlushable
> xFlushable( mxFilterContainer
, UNO_QUERY
);
709 if( xFlushable
.is() )
714 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
720 // we failed to add the filter, so lets remove the type
723 mxTypeDetection
->removeByName( pFilterEntry
->maType
);
727 DBG_ERROR( "XMLFilterSettingsDialog::insertOrEdit exception catched!" );
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();
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();
757 for( nStr
= 0; nStr
< nStrCount
; nStr
++ )
759 OUString
aType( aTypes
[nStr
] );
760 if( aTypes
[nStr
] == pFilterEntry
->maType
)
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() )
792 mpFilterListBox
->changeEntry( pFilterEntry
);
796 mpFilterListBox
->addFilterEntry( pFilterEntry
);
797 maFilterVector
.push_back( pFilterEntry
);
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();
813 filter_info_impl
* pInfo
= (filter_info_impl
*)pEntry
->GetUserData();
815 XMLFilterTestDialog
aDlg( this, *mpResMgr
, mxMSF
);
820 // -----------------------------------------------------------------------
822 void XMLFilterSettingsDialog::onDelete()
824 SvLBoxEntry
* pEntry
= mpFilterListBox
->FirstSelected();
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();
850 Sequence
< PropertyValue
> aValues
;
852 for( nFilter
= 0; (nFilter
< nCount
) && !bTypeStillUsed
; nFilter
++, pFilterName
++ )
854 Any
aAny( mxFilterContainer
->getByName( *pFilterName
) );
855 if( !(aAny
>>= aValues
) )
858 const sal_Int32
nValueCount( aValues
.getLength() );
859 PropertyValue
* pValues
= aValues
.getArray();
862 for( nValue
= 0; (nValue
< nValueCount
) && !bTypeStillUsed
; nValue
++, pValues
++ )
864 if( pValues
->Name
.equalsAscii( "Type" ) )
867 pValues
->Value
>>= aType
;
868 if( aType
== pInfo
->maType
)
869 bTypeStillUsed
= true;
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() )
889 xFlushable
= Reference
< XFlushable
>::query( mxTypeDetection
);
890 if( xFlushable
.is() )
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
));
904 DBG_ERROR( "XMLFilterSettingsDialog::onDelete exception catched!" );
912 // -----------------------------------------------------------------------
914 void XMLFilterSettingsDialog::onSave()
916 XMLFilterVector aFilters
;
920 SvLBoxEntry
* pEntry
= mpFilterListBox
->FirstSelected();
923 filter_info_impl
* pInfo
= (filter_info_impl
*)pEntry
->GetUserData();
924 aFilters
.push_back( pInfo
);
925 pEntry
= mpFilterListBox
->NextSelected( pEntry
);
929 // Open Fileopen-Dialog
930 ::sfx2::FileDialogHelper
aDlg(
931 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION
,
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" ) );
954 aMsg
= String( RESID( STR_FILTERS_HAVE_BEEN_SAVED
) );
955 aMsg
.SearchAndReplace( sPlaceholder
, String::CreateFromInt32(nFilters
) );
956 aMsg
.SearchAndReplace( sPlaceholder
, aURL
.GetName() );
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
);
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
);
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
;
1010 disposeFilterList();
1013 String
sPlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%s" ) );
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
);
1029 aMsg
= String( RESID( STR_FILTERS_INSTALLED
) );
1030 aMsg
.SearchAndReplace( sPlaceholder
, String::CreateFromInt32(nFilters
) );
1033 InfoBox
aBox(this, aMsg
);
1038 // -----------------------------------------------------------------------
1040 void XMLFilterSettingsDialog::onClose()
1045 long XMLFilterSettingsDialog::Notify( NotifyEvent
& rNEvt
)
1047 // Zuerst Basisklasse rufen wegen TabSteuerung
1048 long nRet
= WorkWindow::Notify( rNEvt
);
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
)
1068 // -----------------------------------------------------------------------
1070 void XMLFilterSettingsDialog::disposeFilterList()
1072 std::vector
< filter_info_impl
* >::iterator
aIter( maFilterVector
.begin() );
1073 while( aIter
!= maFilterVector
.end() )
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();
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
) )
1109 OUString aFilterService
;
1110 pTempFilter
->maFilterName
= *pFilterName
;
1112 const sal_Int32
nValueCount( aValues
.getLength() );
1113 PropertyValue
* pValues
= aValues
.getArray();
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" ) )
1161 // if we don't have the needed user data, skip it
1162 if( aUserData
.getLength() < 6 )
1165 // if this is not an XSLTFilter entry, skip it
1166 if( !aUserData
[0].equalsAscii( "com.sun.star.documentconversion.XSLTFilter" ) )
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();
1193 for( nValue2
= 0; nValue2
< nValueCount2
; nValue2
++, pValues2
++ )
1196 if( pValues2->Name.equalsAscii( "MediaType" ) )
1198 pValues2->Value >>= pTempFilter->maDocType;
1201 if( pValues2
->Name
.equalsAscii( "ClipboardFormat" ) )
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();
1221 for( n
= 0; n
< nCount3
; n
++ )
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
;
1258 DBG_ERROR( "XMLFilterSettingsDialog::initFilterList exception catched!" );
1266 SvLBoxEntry
* pEntry
= mpFilterListBox
->GetEntry( 0 );
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",
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",
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",
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",
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",
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",
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",
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",
1345 "com.sun.star.comp.Draw.XMLOasisImporter",
1346 "com.sun.star.comp.Draw.XMLOasisExporter" ) );
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
)
1371 // -----------------------------------------------------------------------
1373 OUString
getApplicationUIName( const OUString
& rServiceName
)
1375 const application_info_impl
* pInfo
= getApplicationInfo( rServiceName
);
1378 return pInfo
->maDocumentUIName
;
1382 OUString aRet
= String( RESID( STR_UNKNOWN_APPLICATION
) );
1383 if( rServiceName
.getLength() )
1385 aRet
+= OUString::createFromAscii(" (");
1386 aRet
+= rServiceName
;
1387 aRet
+= OUString::createFromAscii(")");
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();
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 );
1452 mpHeaderBar
->Show();
1455 // -----------------------------------------------------------------------
1457 XMLFilterListBox::~XMLFilterListBox()
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
)
1480 mbFirstPaint
= false;
1481 RepaintScrollBars();
1484 SvTabListBox::Paint( rRect
);
1487 IMPL_LINK( XMLFilterListBox
, TabBoxScrollHdl_Impl
, SvTabListBox
*, /* pList */ )
1489 mpHeaderBar
->SetOffset( -GetXOffset() );
1493 // -----------------------------------------------------------------------
1495 IMPL_LINK( XMLFilterListBox
, HeaderSelect_Impl
, HeaderBar
*, pBar
)
1497 if ( pBar
&& pBar
->GetCurItemId() != ITEMID_NAME
)
1500 HeaderBarItemBits nBits
= mpHeaderBar
->GetItemBits(ITEMID_TYPE
);
1501 BOOL bUp
= ( ( nBits
& HIB_UPARROW
) == HIB_UPARROW
);
1502 SvSortMode eMode
= SortAscending
;
1506 nBits
&= ~HIB_UPARROW
;
1507 nBits
|= HIB_DOWNARROW
;
1508 eMode
= SortDescending
;
1512 nBits
&= ~HIB_DOWNARROW
;
1513 nBits
|= HIB_UPARROW
;
1515 mpHeaderBar
->SetItemBits( ITEMID_NAME
, nBits
);
1516 SvTreeList
* pMod
= GetModel();
1517 pMod
->SetSortMode( eMode
);
1522 // -----------------------------------------------------------------------
1524 IMPL_LINK( XMLFilterListBox
, HeaderEndDrag_Impl
, HeaderBar
*, pBar
)
1526 if ( pBar
&& !pBar
->GetCurItemId() )
1529 if ( !mpHeaderBar
->IsItemMode() )
1532 USHORT nTabs
= mpHeaderBar
->GetItemCount();
1534 long nWidth
= mpHeaderBar
->GetItemSize(ITEMID_NAME
);
1535 long nBarWidth
= mpHeaderBar
->GetSizePixel().Width();
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
;
1547 SetTab( i
, PixelToLogic( aSz
, MapMode(MAP_APPFONT
) ).Width(), MAP_APPFONT
);
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();
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
);
1580 // -----------------------------------------------------------------------
1582 String
XMLFilterListBox::getEntryString( const filter_info_impl
* pInfo
) const
1584 String
aEntryStr( pInfo
->maFilterName
);
1586 // aEntryStr += String( getApplicationUIName( pInfo->maDocumentService ) );
1587 if ( pInfo
->maExportService
.getLength() > 0 )
1588 aEntryStr
+= String( getApplicationUIName( pInfo
->maExportService
) );
1590 aEntryStr
+= String( getApplicationUIName( pInfo
->maImportService
) );
1595 if( pInfo
->maFlags
& 1 )
1597 if( pInfo
->maFlags
& 2 )
1599 aEntryStr
+= String( RESID( STR_IMPORT_EXPORT
) );
1603 aEntryStr
+= String( RESID( STR_IMPORT_ONLY
) );
1606 else if( pInfo
->maFlags
& 2 )
1608 aEntryStr
+= String( RESID( STR_EXPORT_ONLY
) );
1612 aEntryStr
+= String( RESID( STR_UNDEFINED_FILTER
) );
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
||
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
)
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 );
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
;
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
);
1751 nRead
= xIS
->readBytes( aDataBuffer
, nBufferSize
);
1755 if( nRead
< nBufferSize
)
1757 nBufferSize
= nRead
;
1758 aDataBuffer
.realloc(nRead
);
1761 xOS
->writeBytes( aDataBuffer
);
1772 DBG_ERROR( "copyStreams() exception catched!" );
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
)