LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/control - opendoccontrols.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 122 0.0 %
Date: 2012-12-27 Functions: 0 10 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "opendoccontrols.hxx"
      22             : 
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : #include <com/sun/star/beans/PropertyValue.hpp>
      25             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      26             : #include <com/sun/star/container/XNameAccess.hpp>
      27             : #include <com/sun/star/ui/ModuleUIConfigurationManagerSupplier.hpp>
      28             : #include <com/sun/star/frame/UICommandDescription.hpp>
      29             : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
      30             : #include <com/sun/star/graphic/XGraphic.hpp>
      31             : #include <com/sun/star/ui/XImageManager.hpp>
      32             : 
      33             : #include <comphelper/processfactory.hxx>
      34             : #include <vcl/graph.hxx>
      35             : #include <vcl/help.hxx>
      36             : #include <unotools/historyoptions.hxx>
      37             : #include <comphelper/sequenceashashmap.hxx>
      38             : #include <tools/urlobj.hxx>
      39             : #include <svl/filenotation.hxx>
      40             : #include <osl/diagnose.h>
      41             : 
      42             : //........................................................................
      43             : namespace dbaui
      44             : {
      45             : //........................................................................
      46             : 
      47             :     namespace
      48             :     {
      49             :         using ::com::sun::star::uno::Reference;
      50             :         using ::com::sun::star::uno::Exception;
      51             :         using ::com::sun::star::uno::Sequence;
      52             :         using ::com::sun::star::uno::UNO_QUERY_THROW;
      53             :         using ::com::sun::star::uno::XComponentContext;
      54             :         using ::com::sun::star::container::XNameAccess;
      55             :         using ::com::sun::star::lang::XMultiServiceFactory;
      56             :         using ::com::sun::star::beans::PropertyValue;
      57             :         using ::com::sun::star::ui::ModuleUIConfigurationManagerSupplier;
      58             :         using ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier;
      59             :         using ::com::sun::star::ui::XUIConfigurationManager;
      60             :         using ::com::sun::star::ui::XImageManager;
      61             :         using ::com::sun::star::frame::UICommandDescription;
      62             :         using ::com::sun::star::graphic::XGraphic;
      63             : 
      64           0 :         String GetCommandText( const sal_Char* _pCommandURL, const ::rtl::OUString& _rModuleName )
      65             :         {
      66           0 :             ::rtl::OUString sLabel;
      67           0 :             if ( !_pCommandURL || !*_pCommandURL )
      68           0 :                 return sLabel;
      69             : 
      70           0 :             Reference< XNameAccess > xUICommandLabels;
      71           0 :             ::rtl::OUString sCommandURL = ::rtl::OUString::createFromAscii( _pCommandURL );
      72             : 
      73             :             try
      74             :             {
      75             :                 do
      76             :                 {
      77             :                     // Retrieve popup menu labels
      78           0 :                     Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
      79           0 :                     if ( !xContext.is() )
      80             :                         break;
      81             : 
      82           0 :                     Reference< XNameAccess> xNameAccess( UICommandDescription::create(xContext) );
      83             : 
      84           0 :                     xNameAccess->getByName( _rModuleName ) >>= xUICommandLabels;
      85           0 :                     if ( !xUICommandLabels.is() )
      86             :                         break;
      87             : 
      88           0 :                     Sequence< PropertyValue > aProperties;
      89           0 :                     if ( !( xUICommandLabels->getByName(sCommandURL) >>= aProperties ) )
      90             :                         break;
      91             : 
      92           0 :                     sal_Int32 nCount( aProperties.getLength() );
      93           0 :                     for ( sal_Int32 i=0; i<nCount; ++i )
      94             :                     {
      95           0 :                         ::rtl::OUString sPropertyName( aProperties[i].Name );
      96           0 :                         if ( sPropertyName == "Label" )
      97             :                         {
      98           0 :                             aProperties[i].Value >>= sLabel;
      99             :                             break;
     100             :                         }
     101           0 :                     }
     102             :                 }
     103             :                 while ( false );
     104             :             }
     105           0 :             catch( Exception& rException )
     106             :             {
     107             :                 (void)rException;
     108             :             }
     109             : 
     110           0 :             return sLabel;
     111             :         }
     112             : 
     113           0 :         Image GetCommandIcon( const sal_Char* _pCommandURL, const ::rtl::OUString& _rModuleName )
     114             :         {
     115           0 :             Image aIcon;
     116           0 :             if ( !_pCommandURL || !*_pCommandURL )
     117             :                 return aIcon;
     118             : 
     119           0 :             Reference< XNameAccess > xUICommandLabels;
     120           0 :             ::rtl::OUString sCommandURL = ::rtl::OUString::createFromAscii( _pCommandURL );
     121             :             try
     122             :             {
     123             :                 do
     124             :                 {
     125             :                     // Retrieve popup menu labels
     126           0 :                     Reference< com::sun::star::uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     127           0 :                     if ( !xContext.is() )
     128             :                         break;
     129             : 
     130             :                     Reference< XModuleUIConfigurationManagerSupplier > xSupplier(
     131           0 :                         ModuleUIConfigurationManagerSupplier::create(xContext) );
     132             : 
     133           0 :                     Reference< XUIConfigurationManager > xManager( xSupplier->getUIConfigurationManager( _rModuleName ) );
     134           0 :                     Reference< XImageManager > xImageManager;
     135           0 :                     if ( xManager.is() )
     136           0 :                         xImageManager = xImageManager.query( xManager->getImageManager() );
     137           0 :                     if ( !xImageManager.is() )
     138             :                         break;
     139             : 
     140           0 :                     Sequence< ::rtl::OUString > aCommandList( &sCommandURL, 1 );
     141           0 :                     Sequence<Reference< XGraphic> > xIconList( xImageManager->getImages( 0, aCommandList ) );
     142           0 :                     if ( !xIconList.hasElements() )
     143             :                         break;
     144             : 
     145           0 :                     aIcon = Graphic( xIconList[0] ).GetBitmapEx();
     146             :                 }
     147             :                 while ( false );
     148             :             }
     149           0 :             catch ( Exception& rException )
     150             :             {
     151             :                 (void)rException;
     152             :             }
     153             : 
     154           0 :             return aIcon;
     155             :         }
     156             : 
     157             : 
     158             :     }
     159             : 
     160             :     //====================================================================
     161             :     //= OpenButton
     162             :     //====================================================================
     163             :     //--------------------------------------------------------------------
     164           0 :     OpenDocumentButton::OpenDocumentButton( Window* _pParent, const sal_Char* _pAsciiModuleName, const ResId& _rResId )
     165           0 :         :PushButton( _pParent, _rResId )
     166             :     {
     167           0 :         impl_init( _pAsciiModuleName );
     168           0 :     }
     169             : 
     170             :     //--------------------------------------------------------------------
     171           0 :     void OpenDocumentButton::impl_init( const sal_Char* _pAsciiModuleName )
     172             :     {
     173             :         OSL_ENSURE( _pAsciiModuleName, "OpenDocumentButton::impl_init: invalid module name!" );
     174           0 :         m_sModule = ::rtl::OUString::createFromAscii( _pAsciiModuleName );
     175             : 
     176             :         // our label should equal the UI text of the "Open" command
     177           0 :         String sLabel( GetCommandText( ".uno:Open", m_sModule ) );
     178           0 :         sLabel.SearchAndReplaceAllAscii( "~", String() );
     179           0 :         sLabel.Insert( (sal_Unicode)' ', 0 );
     180           0 :         SetText( sLabel );
     181             : 
     182             :         // Place icon left of text and both centered in the button.
     183           0 :         SetModeImage( GetCommandIcon( ".uno:Open", m_sModule ) );
     184           0 :         EnableImageDisplay( sal_True );
     185           0 :         EnableTextDisplay( sal_True );
     186           0 :         SetImageAlign( IMAGEALIGN_LEFT );
     187           0 :         SetStyle( GetStyle() | WB_CENTER );
     188           0 :     }
     189             : 
     190             :     //====================================================================
     191             :     //= OpenDocumentListBox
     192             :     //====================================================================
     193             :     //--------------------------------------------------------------------
     194           0 :     OpenDocumentListBox::OpenDocumentListBox( Window* _pParent, const sal_Char* _pAsciiModuleName, const ResId& _rResId )
     195           0 :         :ListBox( _pParent, _rResId )
     196             :     {
     197           0 :         impl_init( _pAsciiModuleName );
     198           0 :     }
     199             : 
     200             :     //--------------------------------------------------------------------
     201           0 :     void OpenDocumentListBox::impl_init( const sal_Char* _pAsciiModuleName )
     202             :     {
     203             :         OSL_ENSURE( _pAsciiModuleName, "OpenDocumentListBox::impl_init: invalid module name!" );
     204             : 
     205           0 :         Sequence< Sequence< PropertyValue> > aHistory = SvtHistoryOptions().GetList( ePICKLIST );
     206           0 :         Reference< XNameAccess > xFilterFactory;
     207           0 :         xFilterFactory = xFilterFactory.query( ::comphelper::getProcessServiceFactory()->createInstance(
     208           0 :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ) ) ) );
     209             : 
     210           0 :         sal_uInt32 nCount = aHistory.getLength();
     211           0 :         for ( sal_uInt32 nItem = 0; nItem < nCount; ++nItem )
     212             :         {
     213             :             try
     214             :             {
     215             :                 //  Get the current history item's properties.
     216           0 :                 ::comphelper::SequenceAsHashMap aItemProperties( aHistory[ nItem ] );
     217           0 :                 ::rtl::OUString sURL = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_URL, ::rtl::OUString() );
     218           0 :                 ::rtl::OUString sFilter = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_FILTER, ::rtl::OUString() );
     219           0 :                 String          sTitle = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_TITLE, ::rtl::OUString() );
     220           0 :                 ::rtl::OUString sPassword = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_PASSWORD, ::rtl::OUString() );
     221             : 
     222             :                 //  If the entry is an impress file then insert it into the
     223             :                 //  history list and the list box.
     224           0 :                 Sequence< PropertyValue > aProps;
     225           0 :                 xFilterFactory->getByName( sFilter ) >>= aProps;
     226             : 
     227           0 :                 ::comphelper::SequenceAsHashMap aFilterProperties( aProps );
     228             :                 ::rtl::OUString sDocumentService = aFilterProperties.getUnpackedValueOrDefault(
     229           0 :                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ) ), ::rtl::OUString() );
     230           0 :                 if ( sDocumentService.equalsAscii( _pAsciiModuleName ) )
     231             :                 {
     232             :                     // yes, it's a Base document
     233           0 :                     INetURLObject aURL;
     234           0 :                     aURL.SetSmartURL( sURL );
     235             :                     // The password is set only when it is not empty.
     236           0 :                     if ( !sPassword.isEmpty() )
     237           0 :                         aURL.SetPass( sPassword );
     238             : 
     239           0 :                     if ( !sTitle.Len() )
     240           0 :                         sTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_UNAMBIGUOUS );
     241             : 
     242           0 :                     String sDecodedURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
     243             : 
     244           0 :                     sal_uInt16 nPos = InsertEntry( sTitle );
     245           0 :                     m_aURLs.insert( MapIndexToStringPair::value_type( nPos, StringPair( sDecodedURL, sFilter ) ) );
     246           0 :                 }
     247             :             }
     248           0 :             catch( Exception& rException )
     249             :             {
     250             :                 (void)rException;
     251             :             }
     252           0 :         }
     253           0 :     }
     254             : 
     255             :     //--------------------------------------------------------------------
     256           0 :     String OpenDocumentListBox::GetSelectedDocumentURL() const
     257             :     {
     258           0 :         String sURL;
     259           0 :         sal_uInt16 nSelected = GetSelectEntryPos();
     260           0 :         if ( LISTBOX_ENTRY_NOTFOUND != GetSelectEntryPos() )
     261           0 :             sURL = impl_getDocumentAtIndex( nSelected ).first;
     262           0 :         return sURL;
     263             :     }
     264             : 
     265             :     //--------------------------------------------------------------------
     266           0 :     String OpenDocumentListBox::GetSelectedDocumentFilter() const
     267             :     {
     268           0 :         String sFilter;
     269           0 :         sal_uInt16 nSelected = GetSelectEntryPos();
     270           0 :         if ( LISTBOX_ENTRY_NOTFOUND != GetSelectEntryPos() )
     271           0 :             sFilter = impl_getDocumentAtIndex( nSelected ).second;
     272           0 :         return sFilter;
     273             :     }
     274             : 
     275             :     //--------------------------------------------------------------------
     276           0 :     OpenDocumentListBox::StringPair OpenDocumentListBox::impl_getDocumentAtIndex( sal_uInt16 _nListIndex, bool _bSystemNotation ) const
     277             :     {
     278           0 :         MapIndexToStringPair::const_iterator pos = m_aURLs.find( _nListIndex );
     279             :         OSL_ENSURE( pos != m_aURLs.end(), "OpenDocumentListBox::impl_getDocumentAtIndex: invalid index!" );
     280             : 
     281           0 :         StringPair aDocumentDescriptor;
     282           0 :         if ( pos != m_aURLs.end() )
     283             :         {
     284           0 :             aDocumentDescriptor = pos->second;
     285           0 :             if ( _bSystemNotation && aDocumentDescriptor.first.Len() )
     286             :             {
     287           0 :                 ::svt::OFileNotation aNotation( aDocumentDescriptor.first );
     288           0 :                 aDocumentDescriptor.first = aNotation.get( ::svt::OFileNotation::N_SYSTEM );
     289             :             }
     290             :         }
     291           0 :         return aDocumentDescriptor;
     292             :     }
     293             : 
     294             :     //--------------------------------------------------------------------
     295           0 :     void  OpenDocumentListBox::RequestHelp( const HelpEvent& _rHEvt )
     296             :     {
     297           0 :         if( !( _rHEvt.GetMode() & HELPMODE_QUICK ) )
     298             :             return;
     299           0 :         if ( !IsEnabled() )
     300             :             return;
     301             : 
     302           0 :         Point aRequestPos( ScreenToOutputPixel( _rHEvt.GetMousePosPixel() ) );
     303           0 :         sal_uInt16 nItemIndex = LISTBOX_ENTRY_NOTFOUND;
     304           0 :         if ( GetIndexForPoint( aRequestPos, nItemIndex ) != -1 )
     305             :         {
     306           0 :             Rectangle aItemRect( GetBoundingRectangle( nItemIndex ) );
     307             :             aItemRect = Rectangle(
     308           0 :                 OutputToScreenPixel( aItemRect.TopLeft() ),
     309           0 :                 OutputToScreenPixel( aItemRect.BottomRight() ) );
     310           0 :             String sHelpText = impl_getDocumentAtIndex( nItemIndex, true ).first;
     311           0 :             Help::ShowQuickHelp( this, aItemRect, sHelpText, QUICKHELP_LEFT | QUICKHELP_VCENTER );
     312             :         }
     313             :     }
     314             : 
     315             : //........................................................................
     316             : } // namespace dbaui
     317             : //........................................................................
     318             : 
     319             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10