xref: /aoo41x/main/sfx2/source/dialog/filedlgimpl.hxx (revision cdf0e10c)
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 #ifndef _SFX_FILEDLGIMPL_HXX
28 #define _SFX_FILEDLGIMPL_HXX
29 
30 #include <vcl/timer.hxx>
31 #include <vcl/graph.hxx>
32 #include <cppuhelper/implbase2.hxx>
33 #include <com/sun/star/beans/StringPair.hpp>
34 #include <com/sun/star/container/XNameAccess.hpp>
35 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
36 #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
37 #include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
38 #include <sfx2/fcontnr.hxx>
39 
40 #define _SVSTDARR_STRINGSDTOR
41 #include <svl/svstdarr.hxx>
42 
43 #include <sfx2/filedlghelper.hxx>
44 #include <comphelper/sequenceasvector.hxx>
45 
46 class SfxFilterMatcher;
47 class GraphicFilter;
48 class FileDialogHelper;
49 
50 namespace sfx2
51 {
52     typedef ::com::sun::star::beans::StringPair FilterPair;
53 
54     class FileDialogHelper_Impl :
55         public ::cppu::WeakImplHelper2<
56             ::com::sun::star::ui::dialogs::XFilePickerListener,
57             ::com::sun::star::ui::dialogs::XDialogClosedListener >
58 	{
59 		friend class FileDialogHelper;
60 
61 		::com::sun::star::uno::Reference < ::com::sun::star::ui::dialogs::XFilePicker >	mxFileDlg;
62 		::com::sun::star::uno::Reference < ::com::sun::star::container::XNameAccess >	mxFilterCFG;
63 
64 		std::vector< FilterPair >	maFilters;
65 
66 		SfxFilterMatcher*			mpMatcher;
67 		GraphicFilter*				mpGraphicFilter;
68 		FileDialogHelper*			mpAntiImpl;
69 		Window*						mpPreferredParentWindow;
70 
71         ::comphelper::SequenceAsVector< ::rtl::OUString > mlLastURLs;
72 
73 		::rtl::OUString				maPath;
74 		::rtl::OUString				maFileName;
75 		::rtl::OUString				maCurFilter;
76 		::rtl::OUString				maSelectFilter;
77 		::rtl::OUString				maButtonLabel;
78 
79 		Timer						maPreViewTimer;
80 		Graphic 					maGraphic;
81 
82 		const short 				m_nDialogType;
83 
84 		SfxFilterFlags				m_nMustFlags;
85 		SfxFilterFlags				m_nDontFlags;
86 
87 		sal_uIntPtr						mnPostUserEventId;
88 
89 		ErrCode 					mnError;
90 
91 		FileDialogHelper::Context	meContext;
92 
93 		sal_Bool					mbHasPassword			: 1;
94 		sal_Bool					mbIsPwdEnabled			: 1;
95 		sal_Bool					m_bHaveFilterOptions	: 1;
96 		sal_Bool					mbHasVersions			: 1;
97 		sal_Bool					mbHasAutoExt			: 1;
98 		sal_Bool					mbHasLink				: 1;
99 		sal_Bool					mbHasPreview			: 1;
100 		sal_Bool					mbShowPreview			: 1;
101 		sal_Bool					mbIsSaveDlg 			: 1;
102 		sal_Bool					mbExport	 			: 1;
103 
104 		sal_Bool					mbDeleteMatcher 		: 1;
105 		sal_Bool					mbInsert				: 1;
106 		sal_Bool					mbSystemPicker			: 1;
107 		sal_Bool					mbPwdCheckBoxState		: 1;
108 		sal_Bool					mbSelection				: 1;
109 		sal_Bool					mbSelectionEnabled   	: 1;
110 		sal_Bool                    mbHasSelectionBox       : 1;
111 		sal_Bool                    mbSelectionFltrEnabled  : 1;
112 
113 	private:
114 		void					addFilters( sal_Int64 nFlags,
115 											const String& rFactory,
116 											SfxFilterFlags nMust,
117 											SfxFilterFlags nDont );
118 		void					addFilter( const ::rtl::OUString& rFilterName,
119 										   const ::rtl::OUString& rExtension );
120 		void					addGraphicFilter();
121 		void					enablePasswordBox( sal_Bool bInit );
122 		void					updateFilterOptionsBox();
123 		void					updateExportButton();
124 		void					updateSelectionBox();
125 		void					updateVersions();
126 		void					updatePreviewState( sal_Bool _bUpdatePreviewWindow = sal_True );
127 		void					dispose();
128 
129 		void					loadConfig();
130 		void					saveConfig();
131 
132 		const SfxFilter*		getCurentSfxFilter();
133 		sal_Bool				updateExtendedControl( sal_Int16 _nExtendedControlId, sal_Bool _bEnable );
134 
135 		ErrCode 				getGraphic( const ::rtl::OUString& rURL, Graphic& rGraphic ) const;
136 		void					setDefaultValues();
137 
138 		void					preExecute();
139 		void					postExecute( sal_Int16 _nResult );
140         sal_Int16               implDoExecute();
141         void                    implStartExecute();
142 
143 		void					correctVirtualDialogType();
144 
145 		void					setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId );
146 
147 		sal_Bool 				CheckFilterOptionsCapability( const SfxFilter* _pFilter );
148 
149 		sal_Bool				isInOpenMode() const;
150 		String					getCurrentFilterUIName() const;
151 
152 		void					LoadLastUsedFilter( const ::rtl::OUString& _rContextIdentifier );
153 		void					SaveLastUsedFilter( const ::rtl::OUString& _rContextIdentifier );
154 		void					SaveLastUsedFilter( void );
155 
156 		void					implInitializeFileName( );
157 
158         void                    implGetAndCacheFiles( const ::com::sun::star::uno::Reference< XInterface >& xPicker  ,
159                                                             SvStringsDtor*&               rpURLList,
160                                                       const SfxFilter*                    pFilter  );
161         String                  implEnsureURLExtension(const String& sURL      ,
162                                                        const String& sExtension);
163 
164 		DECL_LINK( TimeOutHdl_Impl, Timer* );
165 		DECL_LINK( HandleEvent, FileDialogHelper* );
166         DECL_LINK( InitControls, void* );
167 
168 	public:
169 		// XFilePickerListener methods
170 		virtual void SAL_CALL				fileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
171 		virtual void SAL_CALL				directoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
172 		virtual ::rtl::OUString SAL_CALL	helpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
173 		virtual void SAL_CALL				controlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
174 		virtual void SAL_CALL				dialogSizeChanged() throw( ::com::sun::star::uno::RuntimeException );
175 
176         // XDialogClosedListener methods
177         virtual void SAL_CALL               dialogClosed( const ::com::sun::star::ui::dialogs::DialogClosedEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException);
178 
179         // XEventListener methods
180 		virtual void SAL_CALL		disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException );
181 
182 		// handle XFilePickerListener events
183 		void					handleFileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
184 		void					handleDirectoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
185 		::rtl::OUString			handleHelpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
186 		void					handleControlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
187 		void					handleDialogSizeChanged();
188 
189         // Own methods
190 								FileDialogHelper_Impl(
191 									FileDialogHelper* _pAntiImpl,
192 									const short nDialogType,
193 									sal_Int64 nFlags,
194 									sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG,
195 									Window* _pPreferredParentWindow = NULL,
196 									const String& sStandardDir = String::CreateFromAscii( "" ),
197 									const ::com::sun::star::uno::Sequence< ::rtl::OUString >&	rBlackList = ::com::sun::star::uno::Sequence< ::rtl::OUString >()
198 								);
199 		virtual					~FileDialogHelper_Impl();
200 
201 		ErrCode 				execute( SvStringsDtor*& rpURLList,
202 										 SfxItemSet *&	 rpSet,
203 										 String&		 rFilter );
204 		ErrCode 				execute();
205 
206 		void					setFilter( const ::rtl::OUString& rFilter );
207 
208 		/** sets the directory which should be browsed
209 
210 			<p>If the given path does not point to a valid (existent and accessible) folder, the request
211 			is silently dropped</p>
212 		*/
213 		void					displayFolder( const ::rtl::OUString& rPath );
214 		void					setFileName( const ::rtl::OUString& _rFile );
215 
216 		::rtl::OUString			getPath() const;
217 		::rtl::OUString			getFilter() const;
218 		void					getRealFilter( String& _rFilter ) const;
219 
220 		ErrCode 				getGraphic( Graphic& rGraphic ) const;
221 		void 					createMatcher( const String& rFactory );
222 
223 		sal_Bool				isShowFilterExtensionEnabled() const;
224 		void					addFilterPair( const ::rtl::OUString& rFilter,
225 											   const ::rtl::OUString& rFilterWithExtension );
226 		::rtl::OUString			getFilterName( const ::rtl::OUString& rFilterWithExtension ) const;
227 		::rtl::OUString			getFilterWithExtension( const ::rtl::OUString& rFilter ) const;
228 
229 		void					SetContext( FileDialogHelper::Context _eNewContext );
230 
231         inline sal_Bool         isSystemFilePicker() const { return mbSystemPicker; }
232         inline sal_Bool         isPasswordEnabled() const { return mbIsPwdEnabled; }
233 	};
234 
235 }	// end of namespace sfx2
236 
237 #endif // _SFX_FILEDLGIMPL_HXX
238 
239