1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SALAQUAFILEPICKER_HXX_
29 #define _SALAQUAFILEPICKER_HXX_
30 
31 //_______________________________________________________________________________________________________________________
32 //  includes of other projects
33 //_______________________________________________________________________________________________________________________
34 
35 #include <cppuhelper/compbase8.hxx>
36 #include <com/sun/star/util/XCancellable.hpp>
37 #include <com/sun/star/lang/XInitialization.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
40 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
41 #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
42 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
43 #include <com/sun/star/beans/StringPair.hpp>
44 
45 #ifndef _SALAQUAPICKER_HXX_
46 #include "SalAquaPicker.hxx"
47 #endif
48 
49 #include <memory>
50 #include <list>
51 
52 #ifndef _RTL_USTRING_H_
53 #include <rtl/ustring.hxx>
54 #endif
55 #include "FilterHelper.hxx"
56 #include "AquaFilePickerDelegate.hxx"
57 
58 //----------------------------------------------------------
59 // Implementation class for the XFilePicker Interface
60 //----------------------------------------------------------
61 
62 //----------------------------------------------------------
63 // forward declarations
64 //----------------------------------------------------------
65 
66 using namespace rtl;
67 
68 //----------------------------------------------------------
69 // class declaration
70 //----------------------------------------------------------
71 
72 class SalAquaFilePicker :
73     public SalAquaPicker,
74     public cppu::WeakComponentImplHelper8<
75     ::com::sun::star::ui::dialogs::XFilterManager,
76     ::com::sun::star::ui::dialogs::XFilterGroupManager,
77     ::com::sun::star::ui::dialogs::XFilePickerControlAccess,
78     ::com::sun::star::ui::dialogs::XFilePickerNotifier,
79     ::com::sun::star::lang::XInitialization,
80     ::com::sun::star::util::XCancellable,
81     ::com::sun::star::lang::XEventListener,
82     ::com::sun::star::lang::XServiceInfo >
83 {
84 public:
85 
86     // constructor
87     SalAquaFilePicker( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceMgr );
88 
89     //------------------------------------------------------------------------------------
90     // XFilePickerNotifier
91     //------------------------------------------------------------------------------------
92 
93     virtual void SAL_CALL addFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener )
94         throw( ::com::sun::star::uno::RuntimeException );
95     virtual void SAL_CALL removeFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener )
96         throw( ::com::sun::star::uno::RuntimeException );
97 
98     //------------------------------------------------------------------------------------
99     // XExecutableDialog functions
100     //------------------------------------------------------------------------------------
101 
102     virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
103         throw( ::com::sun::star::uno::RuntimeException );
104 
105     virtual sal_Int16 SAL_CALL execute(  )
106         throw( ::com::sun::star::uno::RuntimeException );
107 
108     //------------------------------------------------------------------------------------
109     // XFilePicker functions
110     //------------------------------------------------------------------------------------
111 
112     virtual void SAL_CALL setMultiSelectionMode( sal_Bool bMode )
113         throw( ::com::sun::star::uno::RuntimeException );
114 
115     virtual void SAL_CALL setDefaultName( const ::rtl::OUString& aName )
116         throw( ::com::sun::star::uno::RuntimeException );
117 
118     virtual void SAL_CALL setDisplayDirectory( const ::rtl::OUString& aDirectory )
119         throw( com::sun::star::lang::IllegalArgumentException,
120                ::com::sun::star::uno::RuntimeException );
121 
122     virtual ::rtl::OUString SAL_CALL getDisplayDirectory(  )
123         throw( ::com::sun::star::uno::RuntimeException );
124 
125     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFiles(  )
126         throw( ::com::sun::star::uno::RuntimeException );
127 
128     //------------------------------------------------------------------------------------
129     // XFilterManager functions
130     //------------------------------------------------------------------------------------
131 
132     virtual void SAL_CALL appendFilter( const ::rtl::OUString& aTitle, const ::rtl::OUString& aFilter )
133         throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
134 
135     virtual void SAL_CALL setCurrentFilter( const ::rtl::OUString& aTitle )
136         throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
137 
138     virtual ::rtl::OUString SAL_CALL getCurrentFilter(  )
139         throw( ::com::sun::star::uno::RuntimeException );
140 
141     //------------------------------------------------------------------------------------
142     // XFilterGroupManager functions
143     //------------------------------------------------------------------------------------
144 
145     virtual void SAL_CALL appendFilterGroup( const ::rtl::OUString& sGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aFilters )
146         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
147 
148     //------------------------------------------------------------------------------------
149     // XFilePickerControlAccess functions
150     //------------------------------------------------------------------------------------
151 
152     virtual void SAL_CALL setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const ::com::sun::star::uno::Any& aValue )
153         throw (::com::sun::star::uno::RuntimeException);
154 
155     virtual ::com::sun::star::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction )
156         throw (::com::sun::star::uno::RuntimeException);
157 
158     virtual void SAL_CALL enableControl( sal_Int16 nControlId, sal_Bool bEnable )
159         throw(::com::sun::star::uno::RuntimeException );
160 
161     virtual void SAL_CALL setLabel( sal_Int16 nControlId, const ::rtl::OUString& aLabel )
162         throw (::com::sun::star::uno::RuntimeException);
163 
164     virtual ::rtl::OUString SAL_CALL getLabel( sal_Int16 nControlId )
165         throw (::com::sun::star::uno::RuntimeException);
166 
167     //------------------------------------------------
168     // XInitialization
169     //------------------------------------------------
170 
171     virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
172         throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
173 
174     //------------------------------------------------
175     // XCancellable
176     //------------------------------------------------
177 
178     virtual void SAL_CALL cancel( )
179         throw( ::com::sun::star::uno::RuntimeException );
180 
181     //------------------------------------------------
182     // XEventListener
183     //------------------------------------------------
184 
185     using cppu::WeakComponentImplHelperBase::disposing;
186     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent )
187         throw(::com::sun::star::uno::RuntimeException);
188 
189     //------------------------------------------------
190     // XServiceInfo
191     //------------------------------------------------
192 
193     virtual ::rtl::OUString SAL_CALL getImplementationName(  )
194         throw(::com::sun::star::uno::RuntimeException);
195 
196     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
197         throw(::com::sun::star::uno::RuntimeException);
198 
199     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
200         throw(::com::sun::star::uno::RuntimeException);
201 
202     //------------------------------------------------------------------------------------
203     // FilePicker Event functions
204     //------------------------------------------------------------------------------------
205 
206    void SAL_CALL fileSelectionChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
207    void SAL_CALL directoryChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
208    // rtl::OUString SAL_CALL helpRequested( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent ) const;
209    void SAL_CALL controlStateChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
210    void SAL_CALL dialogSizeChanged( );
211 
212    inline AquaFilePickerDelegate * getDelegate() {
213        return m_pDelegate;
214    }
215 
216    inline rtl::OUString getSaveFileName() {
217        return m_sSaveFileName;
218    }
219 
220 private:
221     // prevent copy and assignment
222     SalAquaFilePicker( const SalAquaFilePicker& );
223     SalAquaFilePicker& operator=( const SalAquaFilePicker& );
224 
225     virtual void ensureFilterHelper();
226 
227     // to instantiate own services
228     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceMgr;
229 
230     ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >
231     m_xListener;
232 
233     FilterHelper *m_pFilterHelper;
234 
235     rtl::OUString m_sSaveFileName;
236 
237     AquaFilePickerDelegate *m_pDelegate;
238 
239     void updateFilterUI();
240     void updateSaveFileNameExtension();
241 
242 public:
243 
244     virtual ~SalAquaFilePicker();
245 
246     void filterControlChanged();
247 
248     void implInitialize();
249 
250 };
251 
252 #endif // _SALAQUAFILEPICKER_HXX_
253