Hello Carsten,

While I tested my changed code yesterday I discovered if I selected the
imported icon the program would crash. So I tried to figure out the
problem by getting rid of the newly created variable "mId" and making
use of the original variable "nId". Thus the IDs of imported icons would
follow the ones of original icons continuously so that it could not
cause confusion.

In addition, I think it's better to get the type of images existing in
m_xImportedImageManager by means of methods instead of using "1". How do
you think about it?

And I attach the latest code and you can see the changes.

Thanks for your inspection. :-)

Best regards,
Liang Weike



SvxIconSelectorDialog::SvxIconSelectorDialog( Window *pWindow,
                                                                                
         const uno::Reference< css::ui::XImageManager >& rXImageManager,
                                                                                
         const uno::Reference< css::ui::XImageManager >& rXParentImageManager ) 
                                                                                
         :
ModalDialog                  ( pWindow, ResId( MD_ICONSELECTOR, DIALOG_MGR() ) 
),
aFtDescription       ( this, ResId( FT_SYMBOLS ) ),
aTbSymbol                    ( this, ResId( TB_SYMBOLS ) ),
aFtNote                      ( this, ResId( FT_NOTE ) ),
aBtnOK                       ( this, ResId( BTN_OK ) ),
aBtnCancel                   ( this, ResId( BTN_CANCEL ) ),
aBtnHelp                     ( this, ResId( BTN_HELP ) ),
aBtnImport                   ( this, ResId( BTN_IMPORT ) ),
m_xImageManager      ( rXImageManager ),
m_xParentImageManager( rXParentImageManager )
{
        FreeResource();

        typedef ::std::hash_map< ::rtl::OUString,
                bool,
                ::rtl::OUStringHash,
                ::std::equal_to< ::rtl::OUString > > ImageInfo;

        aTbSymbol.SetPageScroll( TRUE );

        bool bLargeIcons = GetImageType() & css::ui::ImageType::SIZE_LARGE;
        m_nExpectedSize = bLargeIcons ? 26 : 16;

        if ( m_nExpectedSize != 16 )
        {
                aFtNote.SetText( replaceSixteen( aFtNote.GetText(), 
m_nExpectedSize ) );
        }

        uno::Reference< lang::XMultiServiceFactory > xServiceManager =
                ::comphelper::getProcessServiceFactory();

        if ( xServiceManager.is() )
        {
                m_xGraphProvider = uno::Reference< graphic::XGraphicProvider >(
                        xServiceManager->createInstance(
                        ::rtl::OUString::createFromAscii(
                        "com.sun.star.graphic.GraphicProvider" ) ),
                        uno::UNO_QUERY );
        }

        if ( !m_xGraphProvider.is() )
        {
                aBtnImport.Enable( FALSE );
        }

        //added 
        uno::Reference< beans::XPropertySet > xPropSet(
                xServiceManager->createInstance( 
::rtl::OUString::createFromAscii( "com.sun.star.util.PathSettings" ) ),
                uno::UNO_QUERY );

        uno::Any aAny = xPropSet->getPropertyValue( ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM( "UserConfig" ) ) );

        ::rtl::OUString aDirectory;

        aAny >>= aDirectory;

        sal_Int32 aCount = aDirectory.getLength();

        sal_Unicode aChar;

        if ( aCount > 0 )
        {
                aChar = aDirectory[ aCount-1 ];
        }
        else
        {
                aBtnImport.Enable( FALSE );
        }

        if ( aChar != '/')
        {
                aDirectory += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" 
) );
        }

        aDirectory += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"soffice.cfg/import" ) );

        uno::Reference< lang::XSingleServiceFactory > xStorageFactory(
                xServiceManager->createInstance( 
                ::rtl::OUString::createFromAscii( 
"com.sun.star.embed.FileSystemStorageFactory" )),
                uno::UNO_QUERY );

        uno::Sequence< uno::Any > aArgs( 2 );
        aArgs[ 0 ] <<= aDirectory;
        aArgs[ 1 ] <<= com::sun::star::embed::ElementModes::READWRITE;

        uno::Reference< com::sun::star::embed::XStorage > xStorage( 
                xStorageFactory->createInstanceWithArguments( aArgs ), 
uno::UNO_QUERY );

        uno::Sequence< uno::Any > aProp( 2 );
        beans::PropertyValue aPropValue;

        aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"UserConfigStorage" ) );
        aPropValue.Value <<= xStorage;
        aProp[ 0 ] <<= aPropValue;

        aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"OpenMode" ) );
        aPropValue.Value <<= com::sun::star::embed::ElementModes::READWRITE;
        aProp[ 1 ] <<= aPropValue;

        m_xImportedImageManager = uno::Reference< 
com::sun::star::ui::XImageManager >(
                xServiceManager->createInstanceWithArguments( 
                ::rtl::OUString::createFromAscii( 
"com.sun.star.ui.ImageManager" ), aProp ), 
                uno::UNO_QUERY );
        //ended

        uno::Sequence< OUString > names;
        ImageInfo                 aImageInfo;

        if ( m_xParentImageManager.is() )
        {
                names = m_xParentImageManager->getAllImageNames( GetImageType() 
);
                for ( sal_Int32 n = 0; n < names.getLength(); n++ )
                        aImageInfo.insert( ImageInfo::value_type( names[n], 
false ));
        }

        names = m_xImageManager->getAllImageNames( GetImageType() );
        for ( sal_Int32 n = 0; n < names.getLength(); n++ )
        {
                ImageInfo::iterator pIter = aImageInfo.find( names[n] );
                if ( pIter != aImageInfo.end() )
                        pIter->second = true;
                else
                        aImageInfo.insert( ImageInfo::value_type( names[n], 
true ));
        }

        // large growth factor, expecting many entries
        USHORT nId = 1;
        uno::Sequence< OUString > name( 1 );
        ImageInfo::const_iterator pConstIter = aImageInfo.begin();
        while ( pConstIter != aImageInfo.end() )
        {
                name[ 0 ] = pConstIter->first;

                uno::Sequence< uno::Reference< graphic::XGraphic> > graphics;
                try
                {
                        if ( pConstIter->second )
                                graphics = m_xImageManager->getImages( 
GetImageType(), name );
                        else 
                                graphics = m_xParentImageManager->getImages( 
GetImageType(), name );
                }
                catch ( uno::Exception& )
                {
                        // can't get sequence for this name so it will not be
                        // added to the list
                }

                if ( graphics.getLength() > 0 )
                {
                        Image img = Image( graphics[ 0 ] );
                        aTbSymbol.InsertItem( nId, img, pConstIter->first );

                        graphics[ 0 ]->acquire();

                        aTbSymbol.SetItemData(
                                nId, static_cast< void * > ( graphics[ 0 
].get() ) );

                        ++nId;
                }

                ++pConstIter;
        }

        //added
        ImageInfo mImageInfo;
        if ( m_xImportedImageManager.is() )
        {
                names = m_xImportedImageManager->getAllImageNames( 1 );
                for ( sal_Int32 n = 0; n < names.getLength(); n++ )
                        mImageInfo.insert( ImageInfo::value_type( names[n], 
false ));
        }
        pConstIter = mImageInfo.begin();
        while ( pConstIter != mImageInfo.end() )
        {
                name[ 0 ] = pConstIter->first;
                uno::Sequence< uno::Reference< graphic::XGraphic> > graphics = 
m_xImportedImageManager->getImages( 1, name );
                if ( graphics.getLength() > 0 )
                {
                        Image img = Image( graphics[ 0 ] );
                        aTbSymbol.InsertItem( nId, img, pConstIter->first );

                        graphics[ 0 ]->acquire();

                        aTbSymbol.SetItemData(
                                nId, static_cast< void * > ( graphics[ 0 
].get() ) );

                        ++nId;
                }
                ++pConstIter;
        }
        //ended 

        aTbSymbol.SetSelectHdl( LINK(this, SvxIconSelectorDialog, SelectHdl) );
        aBtnImport.SetClickHdl( LINK(this, SvxIconSelectorDialog, ImportHdl) );
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to