LCOV - code coverage report
Current view: top level - dbaccess/source/ui/control - opendoccontrols.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 135 0.7 %
Date: 2014-11-03 Functions: 2 14 14.3 %
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             : #include "opendoccontrols.hxx"
      21             : 
      22             : #include <com/sun/star/uno/Sequence.hxx>
      23             : #include <com/sun/star/beans/PropertyValue.hpp>
      24             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      25             : #include <com/sun/star/container/XNameAccess.hpp>
      26             : #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
      27             : #include <com/sun/star/frame/theUICommandDescription.hpp>
      28             : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
      29             : #include <com/sun/star/graphic/XGraphic.hpp>
      30             : #include <com/sun/star/ui/XImageManager.hpp>
      31             : 
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <vcl/graph.hxx>
      34             : #include <vcl/help.hxx>
      35             : #include <unotools/historyoptions.hxx>
      36             : #include <comphelper/sequenceashashmap.hxx>
      37             : #include <tools/urlobj.hxx>
      38             : #include <svl/filenotation.hxx>
      39             : #include <osl/diagnose.h>
      40             : #include <vcl/builder.hxx>
      41             : 
      42             : namespace dbaui
      43             : {
      44             : 
      45             :     namespace
      46             :     {
      47             :         using ::com::sun::star::uno::Reference;
      48             :         using ::com::sun::star::uno::Exception;
      49             :         using ::com::sun::star::uno::Sequence;
      50             :         using ::com::sun::star::uno::UNO_QUERY_THROW;
      51             :         using ::com::sun::star::uno::XComponentContext;
      52             :         using ::com::sun::star::container::XNameAccess;
      53             :         using ::com::sun::star::lang::XMultiServiceFactory;
      54             :         using ::com::sun::star::beans::PropertyValue;
      55             :         using ::com::sun::star::ui::theModuleUIConfigurationManagerSupplier;
      56             :         using ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier;
      57             :         using ::com::sun::star::ui::XUIConfigurationManager;
      58             :         using ::com::sun::star::ui::XImageManager;
      59             :         using ::com::sun::star::frame::theUICommandDescription;
      60             :         using ::com::sun::star::graphic::XGraphic;
      61             : 
      62           0 :         OUString GetCommandText( const sal_Char* _pCommandURL, const OUString& _rModuleName )
      63             :         {
      64           0 :             OUString sLabel;
      65           0 :             if ( !_pCommandURL || !*_pCommandURL )
      66           0 :                 return sLabel;
      67             : 
      68           0 :             Reference< XNameAccess > xUICommandLabels;
      69           0 :             OUString sCommandURL = OUString::createFromAscii( _pCommandURL );
      70             : 
      71             :             try
      72             :             {
      73             :                 do
      74             :                 {
      75             :                     // Retrieve popup menu labels
      76           0 :                     Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
      77           0 :                     if ( !xContext.is() )
      78           0 :                         break;
      79             : 
      80           0 :                     Reference< XNameAccess> xNameAccess( theUICommandDescription::get(xContext) );
      81             : 
      82           0 :                     xNameAccess->getByName( _rModuleName ) >>= xUICommandLabels;
      83           0 :                     if ( !xUICommandLabels.is() )
      84           0 :                         break;
      85             : 
      86           0 :                     Sequence< PropertyValue > aProperties;
      87           0 :                     if ( !( xUICommandLabels->getByName(sCommandURL) >>= aProperties ) )
      88           0 :                         break;
      89             : 
      90           0 :                     sal_Int32 nCount( aProperties.getLength() );
      91           0 :                     for ( sal_Int32 i=0; i<nCount; ++i )
      92             :                     {
      93           0 :                         OUString sPropertyName( aProperties[i].Name );
      94           0 :                         if ( sPropertyName == "Label" )
      95             :                         {
      96           0 :                             aProperties[i].Value >>= sLabel;
      97           0 :                             break;
      98             :                         }
      99           0 :                     }
     100             :                 }
     101             :                 while ( false );
     102             :             }
     103           0 :             catch( Exception& rException )
     104             :             {
     105             :                 (void)rException;
     106             :             }
     107             : 
     108           0 :             return sLabel;
     109             :         }
     110             : 
     111           0 :         Image GetCommandIcon( const sal_Char* _pCommandURL, const OUString& _rModuleName )
     112             :         {
     113           0 :             Image aIcon;
     114           0 :             if ( !_pCommandURL || !*_pCommandURL )
     115           0 :                 return aIcon;
     116             : 
     117           0 :             Reference< XNameAccess > xUICommandLabels;
     118           0 :             OUString sCommandURL = OUString::createFromAscii( _pCommandURL );
     119             :             try
     120             :             {
     121             :                 do
     122             :                 {
     123             :                     // Retrieve popup menu labels
     124           0 :                     Reference< com::sun::star::uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     125           0 :                     if ( !xContext.is() )
     126           0 :                         break;
     127             : 
     128             :                     Reference< XModuleUIConfigurationManagerSupplier > xSupplier(
     129           0 :                         theModuleUIConfigurationManagerSupplier::get(xContext) );
     130             : 
     131           0 :                     Reference< XUIConfigurationManager > xManager( xSupplier->getUIConfigurationManager( _rModuleName ) );
     132           0 :                     Reference< XImageManager > xImageManager;
     133           0 :                     if ( xManager.is() )
     134           0 :                         xImageManager.set(xManager->getImageManager(), css::uno::UNO_QUERY);
     135           0 :                     if ( !xImageManager.is() )
     136           0 :                         break;
     137             : 
     138           0 :                     Sequence< OUString > aCommandList( &sCommandURL, 1 );
     139           0 :                     Sequence<Reference< XGraphic> > xIconList( xImageManager->getImages( 0, aCommandList ) );
     140           0 :                     if ( !xIconList.hasElements() )
     141           0 :                         break;
     142             : 
     143           0 :                     aIcon = Image(Graphic(xIconList[0]).GetBitmapEx());
     144             :                 }
     145             :                 while ( false );
     146             :             }
     147           0 :             catch ( Exception& rException )
     148             :             {
     149             :                 (void)rException;
     150             :             }
     151             : 
     152           0 :             return aIcon;
     153             :         }
     154             : 
     155             :     }
     156             : 
     157             :     // OpenButton
     158             : 
     159           0 :     OpenDocumentButton::OpenDocumentButton( vcl::Window* _pParent, const sal_Char* _pAsciiModuleName )
     160           0 :         :PushButton( _pParent )
     161             :     {
     162           0 :         impl_init( _pAsciiModuleName );
     163           0 :     }
     164             : 
     165           0 :     extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeOpenDocumentButton( vcl::Window *pParent, VclBuilder::stringmap & )
     166             :     {
     167           0 :         return new OpenDocumentButton( pParent, "com.sun.star.sdb.OfficeDatabaseDocument" );
     168             :     }
     169             : 
     170           0 :     void OpenDocumentButton::impl_init( const sal_Char* _pAsciiModuleName )
     171             :     {
     172             :         OSL_ENSURE( _pAsciiModuleName, "OpenDocumentButton::impl_init: invalid module name!" );
     173           0 :         m_sModule = OUString::createFromAscii( _pAsciiModuleName );
     174             : 
     175             :         // our label should equal the UI text of the "Open" command
     176           0 :         OUString sLabel(GetCommandText(".uno:Open", m_sModule));
     177           0 :         SetText(OUString(' ') + sLabel.replaceAll("~", OUString()));
     178             : 
     179             :         // Place icon left of text and both centered in the button.
     180           0 :         SetModeImage( GetCommandIcon( ".uno:Open", m_sModule ) );
     181           0 :         EnableImageDisplay( true );
     182           0 :         EnableTextDisplay( true );
     183           0 :         SetImageAlign( IMAGEALIGN_LEFT );
     184           0 :         SetStyle( GetStyle() | WB_CENTER );
     185           0 :     }
     186             : 
     187             :     // OpenDocumentListBox
     188             : 
     189           0 :     OpenDocumentListBox::OpenDocumentListBox( vcl::Window* _pParent, const sal_Char* _pAsciiModuleName )
     190           0 :         :ListBox( _pParent, WB_BORDER | WB_DROPDOWN )
     191             :     {
     192           0 :         impl_init( _pAsciiModuleName );
     193           0 :     }
     194             : 
     195           0 :     extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeOpenDocumentListBox( vcl::Window *pParent, VclBuilder::stringmap & )
     196             :     {
     197           0 :         return new OpenDocumentListBox( pParent, "com.sun.star.sdb.OfficeDatabaseDocument" );
     198             :     }
     199             : 
     200           0 :     void OpenDocumentListBox::impl_init( const sal_Char* _pAsciiModuleName )
     201             :     {
     202             :         OSL_ENSURE( _pAsciiModuleName, "OpenDocumentListBox::impl_init: invalid module name!" );
     203             : 
     204           0 :         Sequence< Sequence< PropertyValue> > aHistory = SvtHistoryOptions().GetList( ePICKLIST );
     205           0 :         Reference< XNameAccess > xFilterFactory;
     206           0 :         xFilterFactory.set(::comphelper::getProcessServiceFactory()->createInstance(
     207           0 :             OUString( "com.sun.star.document.FilterFactory" ) ), css::uno::UNO_QUERY);
     208             : 
     209           0 :         sal_uInt32 nCount = aHistory.getLength();
     210           0 :         for ( sal_uInt32 nItem = 0; nItem < nCount; ++nItem )
     211             :         {
     212             :             try
     213             :             {
     214             :                 //  Get the current history item's properties.
     215           0 :                 ::comphelper::SequenceAsHashMap aItemProperties( aHistory[ nItem ] );
     216           0 :                 OUString sURL = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_URL, OUString() );
     217           0 :                 OUString sFilter = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_FILTER, OUString() );
     218           0 :                 OUString sTitle = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_TITLE, OUString() );
     219           0 :                 OUString sPassword = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_PASSWORD, OUString() );
     220             : 
     221             :                 //  If the entry is an impress file then insert it into the
     222             :                 //  history list and the list box.
     223           0 :                 Sequence< PropertyValue > aProps;
     224           0 :                 xFilterFactory->getByName( sFilter ) >>= aProps;
     225             : 
     226           0 :                 ::comphelper::SequenceAsHashMap aFilterProperties( aProps );
     227             :                 OUString sDocumentService = aFilterProperties.getUnpackedValueOrDefault(
     228           0 :                     OUString( "DocumentService" ), OUString() );
     229           0 :                 if ( sDocumentService.equalsAscii( _pAsciiModuleName ) )
     230             :                 {
     231             :                     // yes, it's a Base document
     232           0 :                     INetURLObject aURL;
     233           0 :                     aURL.SetSmartURL( sURL );
     234             :                     // The password is set only when it is not empty.
     235           0 :                     if ( !sPassword.isEmpty() )
     236           0 :                         aURL.SetPass( sPassword );
     237             : 
     238           0 :                     if ( sTitle.isEmpty() )
     239           0 :                         sTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_UNAMBIGUOUS );
     240             : 
     241           0 :                     OUString sDecodedURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
     242             : 
     243           0 :                     sal_Int32 nPos = InsertEntry( sTitle );
     244           0 :                     m_aURLs.insert( MapIndexToStringPair::value_type( nPos, StringPair( sDecodedURL, sFilter ) ) );
     245           0 :                 }
     246             :             }
     247           0 :             catch( Exception& rException )
     248             :             {
     249             :                 (void)rException;
     250             :             }
     251           0 :         }
     252           0 :     }
     253             : 
     254           0 :     OUString OpenDocumentListBox::GetSelectedDocumentURL() const
     255             :     {
     256           0 :         OUString sURL;
     257           0 :         sal_Int32 nSelected = GetSelectEntryPos();
     258           0 :         if ( LISTBOX_ENTRY_NOTFOUND != GetSelectEntryPos() )
     259           0 :             sURL = impl_getDocumentAtIndex( nSelected ).first;
     260           0 :         return sURL;
     261             :     }
     262             : 
     263           0 :     OUString OpenDocumentListBox::GetSelectedDocumentFilter() const
     264             :     {
     265           0 :         OUString sFilter;
     266           0 :         sal_Int32 nSelected = GetSelectEntryPos();
     267           0 :         if ( LISTBOX_ENTRY_NOTFOUND != GetSelectEntryPos() )
     268           0 :             sFilter = impl_getDocumentAtIndex( nSelected ).second;
     269           0 :         return sFilter;
     270             :     }
     271             : 
     272           0 :     OpenDocumentListBox::StringPair OpenDocumentListBox::impl_getDocumentAtIndex( sal_uInt16 _nListIndex, bool _bSystemNotation ) const
     273             :     {
     274           0 :         MapIndexToStringPair::const_iterator pos = m_aURLs.find( _nListIndex );
     275             :         OSL_ENSURE( pos != m_aURLs.end(), "OpenDocumentListBox::impl_getDocumentAtIndex: invalid index!" );
     276             : 
     277           0 :         StringPair aDocumentDescriptor;
     278           0 :         if ( pos != m_aURLs.end() )
     279             :         {
     280           0 :             aDocumentDescriptor = pos->second;
     281           0 :             if ( _bSystemNotation && !aDocumentDescriptor.first.isEmpty() )
     282             :             {
     283           0 :                 ::svt::OFileNotation aNotation( aDocumentDescriptor.first );
     284           0 :                 aDocumentDescriptor.first = aNotation.get( ::svt::OFileNotation::N_SYSTEM );
     285             :             }
     286             :         }
     287           0 :         return aDocumentDescriptor;
     288             :     }
     289             : 
     290           0 :     void  OpenDocumentListBox::RequestHelp( const HelpEvent& _rHEvt )
     291             :     {
     292           0 :         if( !( _rHEvt.GetMode() & HELPMODE_QUICK ) )
     293           0 :             return;
     294           0 :         if ( !IsEnabled() )
     295           0 :             return;
     296             : 
     297           0 :         Point aRequestPos( ScreenToOutputPixel( _rHEvt.GetMousePosPixel() ) );
     298           0 :         sal_Int32 nItemIndex = LISTBOX_ENTRY_NOTFOUND;
     299           0 :         if ( GetIndexForPoint( aRequestPos, nItemIndex ) != -1 )
     300             :         {
     301           0 :             Rectangle aItemRect( GetBoundingRectangle( nItemIndex ) );
     302             :             aItemRect = Rectangle(
     303           0 :                 OutputToScreenPixel( aItemRect.TopLeft() ),
     304           0 :                 OutputToScreenPixel( aItemRect.BottomRight() ) );
     305           0 :             OUString sHelpText = impl_getDocumentAtIndex( nItemIndex, true ).first;
     306           0 :             Help::ShowQuickHelp( this, aItemRect, sHelpText, QUICKHELP_LEFT | QUICKHELP_VCENTER );
     307             :         }
     308             :     }
     309             : 
     310          72 : } // namespace dbaui
     311             : 
     312             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10