xref: /AOO41X/main/fpicker/source/unx/gnome/SalGtkFilePicker.hxx (revision 10ce801889b00990ebdbcb412f4f91e2a9e6f21d)
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 _SALGTKFILEPICKER_HXX_
25 #define _SALGTKFILEPICKER_HXX_
26 
27 //_______________________________________________________________________________________________________________________
28 //  includes of other projects
29 //_______________________________________________________________________________________________________________________
30 
31 #include <cppuhelper/compbase10.hxx>
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
34 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
35 #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
36 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
37 #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
38 #include <com/sun/star/beans/StringPair.hpp>
39 
40 #ifndef _SALGTKPICKER_HXX_
41 #include "SalGtkPicker.hxx"
42 #endif
43 
44 #include <memory>
45 
46 #ifndef _RTL_USTRING_H_
47 #include <rtl/ustring.hxx>
48 #endif
49 
50 #include <list>
51 
52 //----------------------------------------------------------
53 // Implementation class for the XFilePicker Interface
54 //----------------------------------------------------------
55 
56 //----------------------------------------------------------
57 // forward declarations
58 //----------------------------------------------------------
59 
60 using namespace rtl;
61 
62 struct FilterEntry;
63 struct ElementEntry_Impl;
64 
65 typedef ::std::list < FilterEntry >     FilterList;
66 typedef ::std::list < ElementEntry_Impl >   ElementList;
67 typedef ::com::sun::star::beans::StringPair UnoFilterEntry;
68 typedef ::com::sun::star::uno::Sequence< UnoFilterEntry >   UnoFilterList;  // can be transported more effectively
69 
70 
71 //----------------------------------------------------------
72 // class declaration
73 //----------------------------------------------------------
74 
75 class SalGtkFilePicker :
76         public SalGtkPicker,
77     public cppu::WeakComponentImplHelper10<
78         ::com::sun::star::ui::dialogs::XFilterManager,
79         ::com::sun::star::ui::dialogs::XFilterGroupManager,
80         ::com::sun::star::ui::dialogs::XFilePickerControlAccess,
81         ::com::sun::star::ui::dialogs::XFilePickerNotifier,
82         ::com::sun::star::ui::dialogs::XFilePreview,
83         ::com::sun::star::ui::dialogs::XFilePicker2,
84     ::com::sun::star::lang::XInitialization,
85         ::com::sun::star::util::XCancellable,
86     ::com::sun::star::lang::XEventListener,
87     ::com::sun::star::lang::XServiceInfo >
88 {
89     public:
90 
91         // constructor
92         SalGtkFilePicker( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceMgr );
93 
94         //------------------------------------------------------------------------------------
95         // XFilePickerNotifier
96         //------------------------------------------------------------------------------------
97 
98         virtual void SAL_CALL addFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener )
99             throw( ::com::sun::star::uno::RuntimeException );
100         virtual void SAL_CALL removeFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener )
101             throw( ::com::sun::star::uno::RuntimeException );
102 
103         //------------------------------------------------------------------------------------
104         // XExecutableDialog functions
105         //------------------------------------------------------------------------------------
106 
107         virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
108             throw( ::com::sun::star::uno::RuntimeException );
109 
110         virtual sal_Int16 SAL_CALL execute(  )
111             throw( ::com::sun::star::uno::RuntimeException );
112 
113         //------------------------------------------------------------------------------------
114         // XFilePicker functions
115         //------------------------------------------------------------------------------------
116 
117         virtual void SAL_CALL setMultiSelectionMode( sal_Bool bMode )
118             throw( ::com::sun::star::uno::RuntimeException );
119 
120         virtual void SAL_CALL setDefaultName( const ::rtl::OUString& aName )
121             throw( ::com::sun::star::uno::RuntimeException );
122 
123         virtual void SAL_CALL setDisplayDirectory( const ::rtl::OUString& aDirectory )
124             throw( com::sun::star::lang::IllegalArgumentException,
125                 ::com::sun::star::uno::RuntimeException );
126 
127         virtual ::rtl::OUString SAL_CALL getDisplayDirectory(  )
128             throw( ::com::sun::star::uno::RuntimeException );
129 
130         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFiles(  )
131             throw( ::com::sun::star::uno::RuntimeException );
132 
133         //------------------------------------------------------------------------------------
134         // XFilePicker2 functions
135         //------------------------------------------------------------------------------------
136 
137         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSelectedFiles()
138                 throw (::com::sun::star::uno::RuntimeException);
139 
140         //------------------------------------------------------------------------------------
141         // XFilterManager functions
142         //------------------------------------------------------------------------------------
143 
144         virtual void SAL_CALL appendFilter( const ::rtl::OUString& aTitle, const ::rtl::OUString& aFilter )
145             throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
146 
147         virtual void SAL_CALL setCurrentFilter( const ::rtl::OUString& aTitle )
148             throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
149 
150         virtual ::rtl::OUString SAL_CALL getCurrentFilter(  )
151             throw( ::com::sun::star::uno::RuntimeException );
152 
153         //------------------------------------------------------------------------------------
154         // XFilterGroupManager functions
155         //------------------------------------------------------------------------------------
156 
157         virtual void SAL_CALL appendFilterGroup( const ::rtl::OUString& sGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aFilters )
158                 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
159 
160         //------------------------------------------------------------------------------------
161         // XFilePickerControlAccess functions
162         //------------------------------------------------------------------------------------
163 
164         virtual void SAL_CALL setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const ::com::sun::star::uno::Any& aValue )
165                 throw (::com::sun::star::uno::RuntimeException);
166 
167         virtual ::com::sun::star::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction )
168                 throw (::com::sun::star::uno::RuntimeException);
169 
170         virtual void SAL_CALL enableControl( sal_Int16 nControlId, sal_Bool bEnable )
171             throw(::com::sun::star::uno::RuntimeException );
172 
173         virtual void SAL_CALL setLabel( sal_Int16 nControlId, const ::rtl::OUString& aLabel )
174             throw (::com::sun::star::uno::RuntimeException);
175 
176         virtual ::rtl::OUString SAL_CALL getLabel( sal_Int16 nControlId )
177             throw (::com::sun::star::uno::RuntimeException);
178 
179         //------------------------------------------------
180         // XFilePreview
181         //------------------------------------------------
182 
183         virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats(  )
184             throw (::com::sun::star::uno::RuntimeException);
185 
186         virtual sal_Int32 SAL_CALL getTargetColorDepth(  )
187             throw (::com::sun::star::uno::RuntimeException);
188 
189         virtual sal_Int32 SAL_CALL getAvailableWidth(  )
190             throw (::com::sun::star::uno::RuntimeException);
191 
192         virtual sal_Int32 SAL_CALL getAvailableHeight(  )
193             throw (::com::sun::star::uno::RuntimeException);
194 
195         virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& aImage )
196             throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
197 
198         virtual sal_Bool SAL_CALL setShowState( sal_Bool bShowState )
199             throw (::com::sun::star::uno::RuntimeException);
200 
201         virtual sal_Bool SAL_CALL getShowState(  )
202             throw (::com::sun::star::uno::RuntimeException);
203 
204         //------------------------------------------------
205         // XInitialization
206         //------------------------------------------------
207 
208         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
209             throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
210 
211         //------------------------------------------------
212         // XCancellable
213         //------------------------------------------------
214 
215         virtual void SAL_CALL cancel( )
216             throw( ::com::sun::star::uno::RuntimeException );
217 
218         //------------------------------------------------
219         // XEventListener
220         //------------------------------------------------
221 
222         using cppu::WeakComponentImplHelperBase::disposing;
223         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent )
224             throw(::com::sun::star::uno::RuntimeException);
225 
226         //------------------------------------------------
227         // XServiceInfo
228         //------------------------------------------------
229 
230         virtual ::rtl::OUString SAL_CALL getImplementationName(  )
231             throw(::com::sun::star::uno::RuntimeException);
232 
233         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
234             throw(::com::sun::star::uno::RuntimeException);
235 
236         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
237             throw(::com::sun::star::uno::RuntimeException);
238 
239         //------------------------------------------------------------------------------------
240         // FilePicker Event functions
241         //------------------------------------------------------------------------------------
242 
243         void SAL_CALL fileSelectionChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
244         void SAL_CALL directoryChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
245         rtl::OUString SAL_CALL helpRequested( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent ) const;
246         void SAL_CALL controlStateChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
247 
248     private:
249         // prevent copy and assignment
250         SalGtkFilePicker( const SalGtkFilePicker& );
251         SalGtkFilePicker& operator=( const SalGtkFilePicker& );
252 
253         sal_Bool FilterNameExists( const ::rtl::OUString& rTitle );
254         sal_Bool FilterNameExists( const UnoFilterList& _rGroupedFilters );
255 
256         void ensureFilterList( const ::rtl::OUString& _rInitialCurrentFilter );
257 
258         // to instanciate own services
259         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceMgr;
260 
261     private:
262         ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >
263             m_xListener;
264         ::rtl::OUString msPlayLabel;
265         FilterList *m_pFilterList;
266         GtkWidget  *m_pVBox;
267 
268         GtkWidget  *m_pFilterExpander;
269         GtkWidget  *m_pFilterView;
270         GtkListStore *m_pFilterStore;
271 
272         enum {
273             AUTOEXTENSION,
274             PASSWORD,
275             FILTEROPTIONS,
276             READONLY,
277             LINK,
278             PREVIEW,
279             SELECTION,
280             TOGGLE_LAST
281               };
282 
283         GtkWidget  *m_pToggles[ TOGGLE_LAST ];
284 
285         bool mbToggleVisibility[TOGGLE_LAST];
286         bool mbToggleChecked[TOGGLE_LAST];
287 
288         static const rtl::OString m_ToggleLabels[TOGGLE_LAST];
289 
290         enum {
291             PLAY,
292             BUTTON_LAST };
293 
294         GtkWidget  *m_pButtons[ BUTTON_LAST ];
295 
296         enum {
297             VERSION,
298             TEMPLATE,
299             IMAGE_TEMPLATE,
300             LIST_LAST
301               };
302 
303         GtkWidget *m_pHBoxs[ LIST_LAST ];
304         GtkWidget *m_pAligns[ LIST_LAST ];
305         GtkWidget *m_pLists[ LIST_LAST ];
306         GtkWidget *m_pListLabels[ LIST_LAST ];
307         bool mbListVisibility[ LIST_LAST ];
308         bool mbButtonVisibility[ BUTTON_LAST ];
309         gulong mnHID_FolderChange;
310         gulong mnHID_SelectionChange;
311 
312         ::rtl::OUString m_aCurrentFilter;
313         ::rtl::OUString m_aInitialFilter;
314 
315         bool bVersionWidthUnset;
316         sal_Bool mbPreviewState;
317         gulong mHID_Preview;
318         GtkWidget* m_pPreview;
319         GtkFileFilter* m_pPseudoFilter;
320         sal_Int32 m_PreviewImageWidth;
321         sal_Int32 m_PreviewImageHeight;
322 
323         GtkWidget  *getWidget( sal_Int16 nControlId, GType *pType = NULL);
324 
325         void SetCurFilter( const OUString& rFilter );
326         void SetFilters();
327         void UpdateFilterfromUI();
328 
329         void implChangeType( GtkTreeSelection *selection );
330         GtkFileFilter * implAddFilter( const OUString& rFilter, const OUString& rType );
331         void implAddFilterGroup( const OUString& rFilter,
332                      const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair>& _rFilters );
333         void updateCurrentFilterFromName(const gchar* filtername);
334         void unselect_type();
335         void InitialMapping();
336 
337         void HandleSetListValue(GtkComboBox *pWidget, sal_Int16 nControlAction,
338             const ::com::sun::star::uno::Any& rValue);
339         ::com::sun::star::uno::Any HandleGetListValue(GtkComboBox *pWidget, sal_Int16 nControlAction) const;
340 
341         static void expander_changed_cb( GtkExpander *expander, SalGtkFilePicker *pobjFP );
342         static void preview_toggled_cb (GtkObject *cb, SalGtkFilePicker *pobjFP);
343         static void filter_changed_cb (GtkFileChooser *file_chooser, GParamSpec *pspec, SalGtkFilePicker *pobjFP);
344         static void type_changed_cb( GtkTreeSelection *selection, SalGtkFilePicker *pobjFP );
345         static void folder_changed_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP);
346         static void selection_changed_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP);
347         static void update_preview_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP);
348         static void dialog_mapped_cb(GtkWidget *widget, SalGtkFilePicker *pobjFP);
349     public:
350          virtual ~SalGtkFilePicker();
351 
352 };
353 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
354 #endif // _SALGTKFILEPICKER_HXX_
355