Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
20 : #define INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
21 :
22 : #include <vcl/timer.hxx>
23 : #include <vcl/graph.hxx>
24 : #include <cppuhelper/implbase2.hxx>
25 : #include <com/sun/star/beans/StringPair.hpp>
26 : #include <com/sun/star/container/XNameAccess.hpp>
27 : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
28 : #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
29 : #include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
30 : #include <sfx2/fcontnr.hxx>
31 : #include <sfx2/filedlghelper.hxx>
32 : #include <comphelper/sequenceasvector.hxx>
33 :
34 : class SfxFilterMatcher;
35 : class GraphicFilter;
36 : class FileDialogHelper;
37 :
38 : namespace sfx2
39 : {
40 : typedef ::com::sun::star::beans::StringPair FilterPair;
41 :
42 : class FileDialogHelper_Impl :
43 : public ::cppu::WeakImplHelper2<
44 : ::com::sun::star::ui::dialogs::XFilePickerListener,
45 : ::com::sun::star::ui::dialogs::XDialogClosedListener >
46 : {
47 : friend class FileDialogHelper;
48 :
49 : ::com::sun::star::uno::Reference < ::com::sun::star::ui::dialogs::XFilePicker > mxFileDlg;
50 : ::com::sun::star::uno::Reference < ::com::sun::star::container::XNameAccess > mxFilterCFG;
51 :
52 : std::vector< FilterPair > maFilters;
53 :
54 : SfxFilterMatcher* mpMatcher;
55 : GraphicFilter* mpGraphicFilter;
56 : FileDialogHelper* mpAntiImpl;
57 : Window* mpPreferredParentWindow;
58 :
59 : ::comphelper::SequenceAsVector< OUString > mlLastURLs;
60 :
61 : OUString maPath;
62 : OUString maFileName;
63 : OUString maCurFilter;
64 : OUString maSelectFilter;
65 : OUString maButtonLabel;
66 :
67 : Timer maPreviewTimer;
68 : Graphic maGraphic;
69 :
70 : const short m_nDialogType;
71 :
72 : SfxFilterFlags m_nMustFlags;
73 : SfxFilterFlags m_nDontFlags;
74 :
75 : sal_uIntPtr mnPostUserEventId;
76 :
77 : ErrCode mnError;
78 :
79 : FileDialogHelper::Context meContext;
80 :
81 : bool mbHasPassword : 1;
82 : bool mbIsPwdEnabled : 1;
83 : bool m_bHaveFilterOptions : 1;
84 : bool mbHasVersions : 1;
85 : bool mbHasAutoExt : 1;
86 : bool mbAddGraphicFilter : 1;
87 : bool mbHasPreview : 1;
88 : bool mbShowPreview : 1;
89 : bool mbIsSaveDlg : 1;
90 : bool mbIsSaveACopyDlg : 1;
91 : bool mbExport : 1;
92 :
93 : bool mbDeleteMatcher : 1;
94 : bool mbInsert : 1;
95 : bool mbSystemPicker : 1;
96 : bool mbPwdCheckBoxState : 1;
97 : bool mbSelection : 1;
98 : bool mbSelectionEnabled : 1;
99 : bool mbHasSelectionBox : 1;
100 : bool mbSelectionFltrEnabled : 1;
101 :
102 : private:
103 : void addFilters( const OUString& rFactory,
104 : SfxFilterFlags nMust,
105 : SfxFilterFlags nDont );
106 : void addFilter( const OUString& rFilterName,
107 : const OUString& rExtension );
108 : void addGraphicFilter();
109 : void enablePasswordBox( bool bInit );
110 : void updateFilterOptionsBox();
111 : void updateExportButton();
112 : void updateSelectionBox();
113 : void updateVersions();
114 : void updatePreviewState( bool _bUpdatePreviewWindow = true );
115 : void dispose();
116 :
117 : void loadConfig();
118 : void saveConfig();
119 :
120 : const SfxFilter* getCurentSfxFilter();
121 : bool updateExtendedControl( sal_Int16 _nExtendedControlId, bool _bEnable );
122 :
123 : ErrCode getGraphic( const OUString& rURL, Graphic& rGraphic ) const;
124 : void setDefaultValues();
125 :
126 : void preExecute();
127 : void postExecute( sal_Int16 _nResult );
128 : sal_Int16 implDoExecute();
129 : void implStartExecute();
130 :
131 : void correctVirtualDialogType();
132 :
133 : void setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId );
134 :
135 : bool CheckFilterOptionsCapability( const SfxFilter* _pFilter );
136 :
137 : bool isInOpenMode() const;
138 : OUString getCurrentFilterUIName() const;
139 :
140 : void LoadLastUsedFilter( const OUString& _rContextIdentifier );
141 : void SaveLastUsedFilter( const OUString& _rContextIdentifier );
142 : void SaveLastUsedFilter( void );
143 :
144 : void implInitializeFileName( );
145 :
146 : void verifyPath( );
147 :
148 : void implGetAndCacheFiles( const ::com::sun::star::uno::Reference< XInterface >& xPicker ,
149 : std::vector<OUString>& rpURLList,
150 : const SfxFilter* pFilter );
151 :
152 : DECL_LINK(TimeOutHdl_Impl, void *);
153 : DECL_LINK( HandleEvent, FileDialogHelper* );
154 : DECL_LINK( InitControls, void* );
155 :
156 : public:
157 : // XFilePickerListener methods
158 : virtual void SAL_CALL fileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
159 : virtual void SAL_CALL directoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
160 : virtual OUString SAL_CALL helpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
161 : virtual void SAL_CALL controlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
162 : virtual void SAL_CALL dialogSizeChanged() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
163 :
164 : // XDialogClosedListener methods
165 : virtual void SAL_CALL dialogClosed( const ::com::sun::star::ui::dialogs::DialogClosedEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
166 :
167 : // XEventListener methods
168 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
169 :
170 : // handle XFilePickerListener events
171 : void handleFileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
172 : void handleDirectoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
173 : OUString handleHelpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
174 : void handleControlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
175 : void handleDialogSizeChanged();
176 :
177 : // Own methods
178 : FileDialogHelper_Impl(
179 : FileDialogHelper* _pAntiImpl,
180 : const short nDialogType,
181 : sal_Int64 nFlags,
182 : sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG,
183 : Window* _pPreferredParentWindow = NULL,
184 : const OUString& sStandardDir = OUString(),
185 : const ::com::sun::star::uno::Sequence< OUString >& rBlackList = ::com::sun::star::uno::Sequence< OUString >()
186 : );
187 : virtual ~FileDialogHelper_Impl();
188 :
189 : ErrCode execute( std::vector<OUString>& rpURLList,
190 : SfxItemSet *& rpSet,
191 : OUString& rFilter );
192 : ErrCode execute();
193 :
194 : void setFilter( const OUString& rFilter );
195 :
196 : /** sets the directory which should be browsed
197 :
198 : <p>If the given path does not point to a valid (existent and accessible) folder, the request
199 : is silently dropped</p>
200 : */
201 : void displayFolder( const OUString& rPath );
202 : void setFileName( const OUString& _rFile );
203 :
204 : OUString getPath() const;
205 : OUString getFilter() const;
206 : void getRealFilter( OUString& _rFilter ) const;
207 :
208 : ErrCode getGraphic( Graphic& rGraphic ) const;
209 : void createMatcher( const OUString& rFactory );
210 :
211 : bool isShowFilterExtensionEnabled() const;
212 : void addFilterPair( const OUString& rFilter,
213 : const OUString& rFilterWithExtension );
214 : OUString getFilterName( const OUString& rFilterWithExtension ) const;
215 : OUString getFilterWithExtension( const OUString& rFilter ) const;
216 :
217 : void SetContext( FileDialogHelper::Context _eNewContext );
218 :
219 0 : inline bool isSystemFilePicker() const { return mbSystemPicker; }
220 0 : inline bool isPasswordEnabled() const { return mbIsPwdEnabled; }
221 : };
222 :
223 : } // end of namespace sfx2
224 :
225 : #endif // INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
226 :
227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|