LCOV - code coverage report
Current view: top level - dbaccess/source/ui/control - opendoccontrols.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 132 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 12 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             : #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/builderfactory.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 :     VCL_BUILDER_FACTORY_ARGS( OpenDocumentButton, "com.sun.star.sdb.OfficeDatabaseDocument" );
     166             : 
     167           0 :     void OpenDocumentButton::impl_init( const sal_Char* _pAsciiModuleName )
     168             :     {
     169             :         OSL_ENSURE( _pAsciiModuleName, "OpenDocumentButton::impl_init: invalid module name!" );
     170           0 :         m_sModule = OUString::createFromAscii( _pAsciiModuleName );
     171             : 
     172             :         // our label should equal the UI text of the "Open" command
     173           0 :         OUString sLabel(GetCommandText(".uno:Open", m_sModule));
     174           0 :         SetText(" " + sLabel.replaceAll("~", OUString()));
     175             : 
     176             :         // Place icon left of text and both centered in the button.
     177           0 :         SetModeImage( GetCommandIcon( ".uno:Open", m_sModule ) );
     178           0 :         EnableImageDisplay( true );
     179           0 :         EnableTextDisplay( true );
     180           0 :         SetImageAlign( IMAGEALIGN_LEFT );
     181           0 :         SetStyle( GetStyle() | WB_CENTER );
     182           0 :     }
     183             : 
     184             :     // OpenDocumentListBox
     185             : 
     186           0 :     OpenDocumentListBox::OpenDocumentListBox( vcl::Window* _pParent, const sal_Char* _pAsciiModuleName )
     187           0 :         :ListBox( _pParent, WB_BORDER | WB_DROPDOWN )
     188             :     {
     189           0 :         impl_init( _pAsciiModuleName );
     190           0 :     }
     191             : 
     192           0 :     VCL_BUILDER_FACTORY_ARGS( OpenDocumentListBox, "com.sun.star.sdb.OfficeDatabaseDocument" );
     193             : 
     194           0 :     void OpenDocumentListBox::impl_init( const sal_Char* _pAsciiModuleName )
     195             :     {
     196             :         OSL_ENSURE( _pAsciiModuleName, "OpenDocumentListBox::impl_init: invalid module name!" );
     197             : 
     198           0 :         Sequence< Sequence< PropertyValue> > aHistory = SvtHistoryOptions().GetList( ePICKLIST );
     199           0 :         Reference< XNameAccess > xFilterFactory;
     200           0 :         xFilterFactory.set(::comphelper::getProcessServiceFactory()->createInstance(
     201           0 :             OUString( "com.sun.star.document.FilterFactory" ) ), css::uno::UNO_QUERY);
     202             : 
     203           0 :         sal_uInt32 nCount = aHistory.getLength();
     204           0 :         for ( sal_uInt32 nItem = 0; nItem < nCount; ++nItem )
     205             :         {
     206             :             try
     207             :             {
     208             :                 //  Get the current history item's properties.
     209           0 :                 ::comphelper::SequenceAsHashMap aItemProperties( aHistory[ nItem ] );
     210           0 :                 OUString sURL = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_URL, OUString() );
     211           0 :                 OUString sFilter = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_FILTER, OUString() );
     212           0 :                 OUString sTitle = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_TITLE, OUString() );
     213           0 :                 OUString sPassword = aItemProperties.getUnpackedValueOrDefault( HISTORY_PROPERTYNAME_PASSWORD, OUString() );
     214             : 
     215             :                 //  If the entry is an impress file then insert it into the
     216             :                 //  history list and the list box.
     217           0 :                 Sequence< PropertyValue > aProps;
     218           0 :                 xFilterFactory->getByName( sFilter ) >>= aProps;
     219             : 
     220           0 :                 ::comphelper::SequenceAsHashMap aFilterProperties( aProps );
     221             :                 OUString sDocumentService = aFilterProperties.getUnpackedValueOrDefault(
     222           0 :                     OUString( "DocumentService" ), OUString() );
     223           0 :                 if ( sDocumentService.equalsAscii( _pAsciiModuleName ) )
     224             :                 {
     225             :                     // yes, it's a Base document
     226           0 :                     INetURLObject aURL;
     227           0 :                     aURL.SetSmartURL( sURL );
     228             :                     // The password is set only when it is not empty.
     229           0 :                     if ( !sPassword.isEmpty() )
     230           0 :                         aURL.SetPass( sPassword );
     231             : 
     232           0 :                     if ( sTitle.isEmpty() )
     233           0 :                         sTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_UNAMBIGUOUS );
     234             : 
     235           0 :                     OUString sDecodedURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
     236             : 
     237           0 :                     sal_Int32 nPos = InsertEntry( sTitle );
     238           0 :                     m_aURLs.insert( MapIndexToStringPair::value_type( nPos, StringPair( sDecodedURL, sFilter ) ) );
     239           0 :                 }
     240             :             }
     241           0 :             catch( Exception& rException )
     242             :             {
     243             :                 (void)rException;
     244             :             }
     245           0 :         }
     246           0 :     }
     247             : 
     248           0 :     OUString OpenDocumentListBox::GetSelectedDocumentURL() const
     249             :     {
     250           0 :         OUString sURL;
     251           0 :         sal_Int32 nSelected = GetSelectEntryPos();
     252           0 :         if ( LISTBOX_ENTRY_NOTFOUND != GetSelectEntryPos() )
     253           0 :             sURL = impl_getDocumentAtIndex( nSelected ).first;
     254           0 :         return sURL;
     255             :     }
     256             : 
     257           0 :     OUString OpenDocumentListBox::GetSelectedDocumentFilter() const
     258             :     {
     259           0 :         OUString sFilter;
     260           0 :         sal_Int32 nSelected = GetSelectEntryPos();
     261           0 :         if ( LISTBOX_ENTRY_NOTFOUND != GetSelectEntryPos() )
     262           0 :             sFilter = impl_getDocumentAtIndex( nSelected ).second;
     263           0 :         return sFilter;
     264             :     }
     265             : 
     266           0 :     OpenDocumentListBox::StringPair OpenDocumentListBox::impl_getDocumentAtIndex( sal_uInt16 _nListIndex, bool _bSystemNotation ) const
     267             :     {
     268           0 :         MapIndexToStringPair::const_iterator pos = m_aURLs.find( _nListIndex );
     269             :         OSL_ENSURE( pos != m_aURLs.end(), "OpenDocumentListBox::impl_getDocumentAtIndex: invalid index!" );
     270             : 
     271           0 :         StringPair aDocumentDescriptor;
     272           0 :         if ( pos != m_aURLs.end() )
     273             :         {
     274           0 :             aDocumentDescriptor = pos->second;
     275           0 :             if ( _bSystemNotation && !aDocumentDescriptor.first.isEmpty() )
     276             :             {
     277           0 :                 ::svt::OFileNotation aNotation( aDocumentDescriptor.first );
     278           0 :                 aDocumentDescriptor.first = aNotation.get( ::svt::OFileNotation::N_SYSTEM );
     279             :             }
     280             :         }
     281           0 :         return aDocumentDescriptor;
     282             :     }
     283             : 
     284           0 :     void  OpenDocumentListBox::RequestHelp( const HelpEvent& _rHEvt )
     285             :     {
     286           0 :         if( !( _rHEvt.GetMode() & HelpEventMode::QUICK ) )
     287           0 :             return;
     288           0 :         if ( !IsEnabled() )
     289           0 :             return;
     290             : 
     291           0 :         Point aRequestPos( ScreenToOutputPixel( _rHEvt.GetMousePosPixel() ) );
     292           0 :         sal_Int32 nItemIndex = LISTBOX_ENTRY_NOTFOUND;
     293           0 :         if ( GetIndexForPoint( aRequestPos, nItemIndex ) != -1 )
     294             :         {
     295           0 :             Rectangle aItemRect( GetBoundingRectangle( nItemIndex ) );
     296             :             aItemRect = Rectangle(
     297           0 :                 OutputToScreenPixel( aItemRect.TopLeft() ),
     298           0 :                 OutputToScreenPixel( aItemRect.BottomRight() ) );
     299           0 :             OUString sHelpText = impl_getDocumentAtIndex( nItemIndex, true ).first;
     300           0 :             Help::ShowQuickHelp( this, aItemRect, sHelpText, QuickHelpFlags::Left | QuickHelpFlags::VCenter );
     301             :         }
     302             :     }
     303             : 
     304             : } // namespace dbaui
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11