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