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 #ifndef INCLUDED_FPICKER_SOURCE_OFFICE_OFFICEFILEPICKER_HXX
20 #define INCLUDED_FPICKER_SOURCE_OFFICE_OFFICEFILEPICKER_HXX
21 
22 #include <cppuhelper/implbase5.hxx>
23 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
24 #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
25 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
26 #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
27 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/lang/XEventListener.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 
32 
33 #include "commonpicker.hxx"
34 #include "pickercallbacks.hxx"
35 
36 #include <vector>
37 
38 class Dialog;
39 struct FilterEntry;
40 struct ElementEntry_Impl;
41 enum class PickerFlags;
42 
43 typedef ::std::vector< FilterEntry >           FilterList;     // can be maintained more effectively
44 typedef ::std::vector< ElementEntry_Impl >     ElementList;
45 
46 typedef css::beans::StringPair                 UnoFilterEntry;
47 typedef css::uno::Sequence< UnoFilterEntry >   UnoFilterList;  // can be transported more effectively
48 
49 // class SvtFilePicker ---------------------------------------------------
50 
51 typedef ::cppu::ImplHelper5 <   css::ui::dialogs::XFilePicker3
52                             ,   css::ui::dialogs::XFilePickerControlAccess
53                             ,   css::ui::dialogs::XFilePreview
54                             ,   css::lang::XServiceInfo
55                             ,   css::ui::dialogs::XAsynchronousExecutableDialog
56                             >   SvtFilePicker_Base;
57 
58 class SvtFilePicker :public SvtFilePicker_Base
59                     ,public ::svt::OCommonPicker
60                     ,public ::svt::IFilePickerListener
61 {
62 protected:
63     std::unique_ptr<FilterList>
64                         m_pFilterList;
65     std::unique_ptr<ElementList>
66                         m_pElemList;
67 
68     bool                m_bMultiSelection;
69     sal_Int16           m_nServiceType;
70     OUString            m_aDefaultName;
71     OUString            m_aCurrentFilter;
72 
73     OUString            m_aOldDisplayDirectory;
74     OUString            m_aOldHideDirectory;
75 
76     OUString            m_aStandardDir;
77     css::uno::Sequence< OUString >
78                         m_aBlackList;
79 
80     css::uno::Reference< css::ui::dialogs::XFilePickerListener >
81                         m_xListener;
82     css::uno::Reference< css::ui::dialogs::XDialogClosedListener >
83                         m_xDlgClosedListener;
84 
85 public:
86                        SvtFilePicker();
87     virtual           ~SvtFilePicker() override;
88 
89 
90     // disambiguate XInterface
91 
92     DECLARE_XINTERFACE( )
93 
94 
95     // disambiguate XTypeProvider
96 
97     DECLARE_XTYPEPROVIDER( )
98 
99 
100     // XExecutableDialog functions
101 
102     virtual void SAL_CALL setTitle( const OUString& _rTitle ) override;
103     virtual sal_Int16 SAL_CALL execute(  ) override;
104 
105 
106     // XAsynchronousExecutableDialog functions
107 
108     virtual void SAL_CALL setDialogTitle( const OUString& _rTitle ) override;
109     virtual void SAL_CALL startExecuteModal( const css::uno::Reference< css::ui::dialogs::XDialogClosedListener >& xListener ) override;
110 
111 
112     // XFilePicker functions
113 
114 
115     virtual void SAL_CALL           setMultiSelectionMode( sal_Bool bMode ) override;
116     virtual void SAL_CALL           setDefaultName( const OUString& aName ) override;
117     virtual void SAL_CALL           setDisplayDirectory( const OUString& aDirectory ) override;
118     virtual OUString SAL_CALL    getDisplayDirectory() override;
119     virtual css::uno::Sequence< OUString > SAL_CALL getFiles() override;
120     virtual css::uno::Sequence< OUString > SAL_CALL getSelectedFiles() override;
121 
122 
123     // XFilePickerControlAccess functions
124 
125 
126     virtual void SAL_CALL           setValue( sal_Int16 ElementID, sal_Int16 ControlAction, const css::uno::Any& value ) override;
127     virtual css::uno::Any SAL_CALL           getValue( sal_Int16 ElementID, sal_Int16 ControlAction ) override;
128     virtual void SAL_CALL           setLabel( sal_Int16 ElementID, const OUString& aValue ) override;
129     virtual OUString SAL_CALL    getLabel( sal_Int16 ElementID ) override;
130     virtual void SAL_CALL           enableControl( sal_Int16 ElementID, sal_Bool bEnable ) override;
131 
132 
133     // XFilePickerNotifier functions
134 
135 
136     virtual void SAL_CALL           addFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener ) override;
137     virtual void SAL_CALL           removeFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener ) override;
138 
139 
140     // XFilePreview functions
141 
142 
143     virtual css::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats() override;
144     virtual sal_Int32 SAL_CALL      getTargetColorDepth() override;
145     virtual sal_Int32 SAL_CALL      getAvailableWidth() override;
146     virtual sal_Int32 SAL_CALL      getAvailableHeight() override;
147     virtual void SAL_CALL           setImage( sal_Int16 aImageFormat, const css::uno::Any& aImage ) override;
148     virtual sal_Bool SAL_CALL       setShowState( sal_Bool bShowState ) override;
149     virtual sal_Bool SAL_CALL       getShowState() override;
150 
151 
152     // XFilterManager functions
153 
154 
155     virtual void SAL_CALL           appendFilter( const OUString& aTitle, const OUString& aFilter ) override;
156     virtual void SAL_CALL           setCurrentFilter( const OUString& aTitle ) override;
157     virtual OUString SAL_CALL       getCurrentFilter() override;
158 
159 
160     // XFilterGroupManager functions
161 
162     virtual void SAL_CALL           appendFilterGroup( const OUString& sGroupTitle, const css::uno::Sequence< css::beans::StringPair >& aFilters ) override;
163 
164 
165     // these methods are here because they're ambiguous
166 
cancel()167     virtual void SAL_CALL           cancel() override
168      { ::svt::OCommonPicker::cancel(); }
dispose()169     virtual void SAL_CALL           dispose() override
170      { ::svt::OCommonPicker::dispose(); }
addEventListener(const css::uno::Reference<css::lang::XEventListener> & l)171     virtual void SAL_CALL           addEventListener(const css::uno::Reference<css::lang::XEventListener>& l) override
172      { ::svt::OCommonPicker::addEventListener(l); }
removeEventListener(const css::uno::Reference<css::lang::XEventListener> & l)173     virtual void SAL_CALL           removeEventListener(const css::uno::Reference<css::lang::XEventListener>& l) override
174      { ::svt::OCommonPicker::removeEventListener(l); }
175 
176 
177     // XInitialization functions
178 
179 
180     virtual void SAL_CALL           initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
181 
182 
183     // XServiceInfo functions
184 
185 
186     /* XServiceInfo */
187     virtual OUString SAL_CALL       getImplementationName() override;
188     virtual sal_Bool SAL_CALL       supportsService( const OUString& sServiceName ) override;
189     virtual css::uno::Sequence< OUString > SAL_CALL
190                                     getSupportedServiceNames() override;
191 
192     /* Helper for XServiceInfo */
193     static css::uno::Sequence< OUString >
194                                     impl_getStaticSupportedServiceNames();
195     static OUString                 impl_getStaticImplementationName();
196 
197     /* Helper for registry */
198     /// @throws css::uno::Exception
199     static css::uno::Reference< css::uno::XInterface > impl_createInstance (
200         const css::uno::Reference< css::uno::XComponentContext >& rxContext );
201 
202 protected:
203 
204     // OCommonPicker overridables
205 
206     virtual std::unique_ptr<SvtFileDialog_Base> implCreateDialog( weld::Window* pParent ) override;
207     virtual sal_Int16       implExecutePicker( ) override;
208     virtual bool            implHandleInitializationArgument(
209                                 const OUString& _rName,
210                                 const css::uno::Any& _rValue
211                             ) override;
212 
213 protected:
214     PickerFlags         getPickerFlags() const;
215     virtual void        notify( sal_Int16 _nEventId, sal_Int16 _nControlId ) override;
216 
217     bool                FilterNameExists( const OUString& rTitle );
218     bool                FilterNameExists( const UnoFilterList& _rGroupedFilters );
219 
220     void                ensureFilterList( const OUString& _rInitialCurrentFilter );
221 
222     void                prepareExecute( );
223 
224     void                DialogClosedHdl(sal_Int32 nResult);
225 };
226 
227 // SvtRemoteFilePicker
228 
229 class SvtRemoteFilePicker : public SvtFilePicker
230 {
231 public:
232     SvtRemoteFilePicker();
233 
234     virtual std::unique_ptr<SvtFileDialog_Base> implCreateDialog( weld::Window* pParent ) override;
235 
236     // disambiguate XInterface
237 
238     DECLARE_XINTERFACE( )
239 
240     // disambiguate XTypeProvider
241 
242     DECLARE_XTYPEPROVIDER( )
243 
244     /* XServiceInfo */
245     virtual OUString SAL_CALL getImplementationName() override;
246     virtual sal_Bool SAL_CALL supportsService( const OUString& sServiceName ) override;
247     virtual css::uno::Sequence< OUString > SAL_CALL
248                                     getSupportedServiceNames() override;
249 
250     /* Helper for XServiceInfo */
251     static css::uno::Sequence< OUString > impl_getStaticSupportedServiceNames();
252     static OUString impl_getStaticImplementationName();
253 
254     /* Helper for registry */
255     /// @throws css::uno::Exception
256     static css::uno::Reference< css::uno::XInterface > impl_createInstance (
257         const css::uno::Reference< css::uno::XComponentContext >& rxContext );
258 };
259 
260 #endif // INCLUDED_FPICKER_SOURCE_OFFICE_OFFICEFILEPICKER_HXX
261 
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
263