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