1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _FILEPICKER_HXX_
25 #define _FILEPICKER_HXX_
26 
27 //_______________________________________________________________________________________________________________________
28 //	includes of other projects
29 //_______________________________________________________________________________________________________________________
30 
31 
32 #include <cppuhelper/compbase10.hxx>
33 #include <osl/mutex.hxx>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
37 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
38 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
39 #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
40 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
41 #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
42 #include <com/sun/star/util/XCancellable.hpp>
43 #include "asynceventnotifier.hxx"
44 #include "eventnotification.hxx"
45 
46 #include <memory>
47 
48 //----------------------------------------------------------
49 // Implementation class for the XFilePicker Interface
50 //----------------------------------------------------------
51 
52 //----------------------------------------------------------
53 // forward declarations
54 //----------------------------------------------------------
55 
56 class CWinFileOpenImpl;
57 
58 //----------------------------------------------------------
59 // class declaration
60 //----------------------------------------------------------
61 
62 class CFilePickerDummy
63 {
64 protected:
65 	osl::Mutex	m_aMutex;
66 	osl::Mutex	m_rbHelperMtx;
67 };
68 
69 class CFilePicker :
70 	public CFilePickerDummy,
71 	public cppu::WeakComponentImplHelper10<
72         ::com::sun::star::ui::dialogs::XFilterManager,
73         ::com::sun::star::ui::dialogs::XFilterGroupManager,
74         ::com::sun::star::ui::dialogs::XFilePickerControlAccess,
75         ::com::sun::star::ui::dialogs::XFilePickerNotifier,
76         ::com::sun::star::ui::dialogs::XFilePreview,
77         ::com::sun::star::ui::dialogs::XFilePicker2,
78 		::com::sun::star::lang::XInitialization,
79         ::com::sun::star::util::XCancellable,
80 		::com::sun::star::lang::XEventListener,
81 		::com::sun::star::lang::XServiceInfo >
82 {
83 public:
84 
85 	// ctor
86 	CFilePicker( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceMgr );
87 
88 	//------------------------------------------------------------------------------------
89 	// XFilePickerNotifier
90 	//------------------------------------------------------------------------------------
91 
92     virtual void SAL_CALL addFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener )
93 		throw( ::com::sun::star::uno::RuntimeException );
94     virtual void SAL_CALL removeFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener )
95 		throw( ::com::sun::star::uno::RuntimeException );
96 
97 	//------------------------------------------------------------------------------------
98 	// XExecutableDialog functions
99 	//------------------------------------------------------------------------------------
100 
101 	virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
102 		throw( ::com::sun::star::uno::RuntimeException );
103 
104 	virtual sal_Int16 SAL_CALL execute(  )
105 		throw( ::com::sun::star::uno::RuntimeException );
106 
107 	//------------------------------------------------------------------------------------
108 	// XFilePicker functions
109 	//------------------------------------------------------------------------------------
110 
111 	virtual void SAL_CALL setMultiSelectionMode( sal_Bool bMode )
112 		throw( ::com::sun::star::uno::RuntimeException );
113 
114     virtual void SAL_CALL setDefaultName( const ::rtl::OUString& aName )
115 		throw( ::com::sun::star::uno::RuntimeException );
116 
117     virtual void SAL_CALL setDisplayDirectory( const ::rtl::OUString& aDirectory )
118 		throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
119 
120 	virtual ::rtl::OUString SAL_CALL getDisplayDirectory(  )
121 		throw( ::com::sun::star::uno::RuntimeException );
122 
123     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFiles(  )
124 		throw( ::com::sun::star::uno::RuntimeException );
125 
126 	//------------------------------------------------------------------------------------
127 	// XFilePicker2 functions
128 	//------------------------------------------------------------------------------------
129     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSelectedFiles(  )
130         throw (::com::sun::star::uno::RuntimeException);
131 
132 	//------------------------------------------------------------------------------------
133 	// XFilterManager functions
134 	//------------------------------------------------------------------------------------
135 
136 	virtual void SAL_CALL appendFilter( const ::rtl::OUString& aTitle, const ::rtl::OUString& aFilter )
137         throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
138 
139     virtual void SAL_CALL setCurrentFilter( const ::rtl::OUString& aTitle )
140 		throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
141 
142     virtual ::rtl::OUString SAL_CALL getCurrentFilter(  )
143 		throw( ::com::sun::star::uno::RuntimeException );
144 
145     //------------------------------------------------------------------------------------
146 	// XFilterGroupManager functions
147 	//------------------------------------------------------------------------------------
148 
149     virtual void SAL_CALL appendFilterGroup( const ::rtl::OUString& sGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aFilters )
150         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
151 
152 	//------------------------------------------------------------------------------------
153 	// XFilePickerControlAccess functions
154 	//------------------------------------------------------------------------------------
155 
156 	virtual void SAL_CALL setValue( sal_Int16 aControlId, sal_Int16 aControlAction, const ::com::sun::star::uno::Any& aValue )
157         throw (::com::sun::star::uno::RuntimeException);
158 
159     virtual ::com::sun::star::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction )
160         throw (::com::sun::star::uno::RuntimeException);
161 
162     virtual void SAL_CALL enableControl( sal_Int16 aControlId, sal_Bool bEnable )
163 		throw(::com::sun::star::uno::RuntimeException );
164 
165 	virtual void SAL_CALL setLabel( sal_Int16 aControlId, const ::rtl::OUString& aLabel )
166 		throw (::com::sun::star::uno::RuntimeException);
167 
168     virtual ::rtl::OUString SAL_CALL getLabel( sal_Int16 aControlId )
169 		throw (::com::sun::star::uno::RuntimeException);
170 
171     //------------------------------------------------
172     // XFilePreview
173     //------------------------------------------------
174 
175     virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats(  ) throw (::com::sun::star::uno::RuntimeException);
176 
177     virtual sal_Int32 SAL_CALL getTargetColorDepth(  ) throw (::com::sun::star::uno::RuntimeException);
178 
179     virtual sal_Int32 SAL_CALL getAvailableWidth(  ) throw (::com::sun::star::uno::RuntimeException);
180 
181     virtual sal_Int32 SAL_CALL getAvailableHeight(  ) throw (::com::sun::star::uno::RuntimeException);
182 
183     virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& aImage ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
184 
185     virtual sal_Bool SAL_CALL setShowState( sal_Bool bShowState ) throw (::com::sun::star::uno::RuntimeException);
186 
187     virtual sal_Bool SAL_CALL getShowState(  ) throw (::com::sun::star::uno::RuntimeException);
188 
189 	//------------------------------------------------
190 	// XInitialization
191 	//------------------------------------------------
192 
193 	virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
194 		throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
195 
196     //------------------------------------------------
197 	// XCancellable
198 	//------------------------------------------------
199 
200     virtual void SAL_CALL cancel( )
201 		throw(::com::sun::star::uno::RuntimeException);
202 
203 	//------------------------------------------------
204     // XEventListener
205     //------------------------------------------------
206 
207     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent )
208         throw(::com::sun::star::uno::RuntimeException);
209 
210 	//------------------------------------------------
211 	// XServiceInfo
212 	//------------------------------------------------
213 
214 	virtual ::rtl::OUString SAL_CALL getImplementationName(	 )
215 		throw(::com::sun::star::uno::RuntimeException);
216 
217 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
218 		throw(::com::sun::star::uno::RuntimeException);
219 
220 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
221 		throw(::com::sun::star::uno::RuntimeException);
222 
223 	//------------------------------------------------------------------------------------
224 	// FilePicker Event functions
225 	//------------------------------------------------------------------------------------
226 
227 	void SAL_CALL fileSelectionChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
228 	void SAL_CALL directoryChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
229     rtl::OUString SAL_CALL helpRequested( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent ) const;
230 	void SAL_CALL controlStateChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
231     void SAL_CALL dialogSizeChanged( );
232 
233     bool startupEventNotification(bool bStartupSuspended);
234     void shutdownEventNotification();
235     void suspendEventNotification();
236     void resumeEventNotification();
237 
238 private:
239 	// prevent copy and assignment
240 	CFilePicker( const CFilePicker& );
241 	CFilePicker& operator=( const CFilePicker& );
242 
243     using WeakComponentImplHelperBase::disposing;
244 
245 private:
246 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceMgr;   // to instanciate own services
247     CAsyncEventNotifier				                                               m_aAsyncEventNotifier;
248 	std::auto_ptr<CWinFileOpenImpl>	    										   m_pImpl;
249 };
250 
251 #endif
252