Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / dialog / filedlgimpl.hxx
blob97b748d950e3871d6bb740df13b097180a5957db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
20 #define INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
22 #include <vcl/timer.hxx>
23 #include <vcl/idle.hxx>
24 #include <vcl/graph.hxx>
25 #include <cppuhelper/implbase2.hxx>
26 #include <com/sun/star/beans/StringPair.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
29 #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
30 #include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
31 #include <sfx2/fcontnr.hxx>
32 #include <sfx2/filedlghelper.hxx>
34 class SfxFilterMatcher;
35 class GraphicFilter;
36 class FileDialogHelper;
38 namespace sfx2
40 typedef ::com::sun::star::beans::StringPair FilterPair;
42 class FileDialogHelper_Impl :
43 public ::cppu::WeakImplHelper2<
44 ::com::sun::star::ui::dialogs::XFilePickerListener,
45 ::com::sun::star::ui::dialogs::XDialogClosedListener >
47 friend class FileDialogHelper;
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;
52 std::vector< FilterPair > maFilters;
54 SfxFilterMatcher* mpMatcher;
55 GraphicFilter* mpGraphicFilter;
56 FileDialogHelper* mpAntiImpl;
57 VclPtr<vcl::Window> mpPreferredParentWindow;
59 ::std::vector< OUString > mlLastURLs;
61 OUString maPath;
62 OUString maFileName;
63 OUString maCurFilter;
64 OUString maSelectFilter;
65 OUString maButtonLabel;
67 Idle maPreviewIdle;
68 Graphic maGraphic;
70 const short m_nDialogType;
72 SfxFilterFlags m_nMustFlags;
73 SfxFilterFlags m_nDontFlags;
75 ImplSVEvent * mnPostUserEventId;
77 ErrCode mnError;
79 FileDialogHelper::Context meContext;
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;
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;
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();
117 void loadConfig();
118 void saveConfig();
120 const SfxFilter* getCurentSfxFilter();
121 bool updateExtendedControl( sal_Int16 _nExtendedControlId, bool _bEnable );
123 ErrCode getGraphic( const OUString& rURL, Graphic& rGraphic ) const;
124 void setDefaultValues();
126 void preExecute();
127 void postExecute( sal_Int16 _nResult );
128 sal_Int16 implDoExecute();
129 void implStartExecute();
131 void correctVirtualDialogType();
133 void setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId );
135 bool CheckFilterOptionsCapability( const SfxFilter* _pFilter );
137 bool isInOpenMode() const;
138 OUString getCurrentFilterUIName() const;
140 void LoadLastUsedFilter( const OUString& _rContextIdentifier );
141 void SaveLastUsedFilter( const OUString& _rContextIdentifier );
142 void SaveLastUsedFilter();
144 void implInitializeFileName( );
146 void verifyPath( );
148 void implGetAndCacheFiles( const ::com::sun::star::uno::Reference< XInterface >& xPicker ,
149 std::vector<OUString>& rpURLList,
150 const SfxFilter* pFilter );
152 DECL_LINK_TYPED(TimeOutHdl_Impl, Idle *, void);
153 DECL_LINK( HandleEvent, FileDialogHelper* );
154 DECL_LINK( InitControls, void* );
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;
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;
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;
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 static OUString handleHelpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
174 void handleControlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
175 void handleDialogSizeChanged();
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 vcl::Window* _pPreferredParentWindow = NULL,
184 const OUString& sStandardDir = OUString(),
185 const ::com::sun::star::uno::Sequence< OUString >& rBlackList = ::com::sun::star::uno::Sequence< OUString >()
187 virtual ~FileDialogHelper_Impl();
189 ErrCode execute( std::vector<OUString>& rpURLList,
190 SfxItemSet *& rpSet,
191 OUString& rFilter );
192 ErrCode execute();
194 void setFilter( const OUString& rFilter );
196 /** sets the directory which should be browsed
198 <p>If the given path does not point to a valid (existent and accessible) folder, the request
199 is silently dropped</p>
201 void displayFolder( const OUString& rPath );
202 void setFileName( const OUString& _rFile );
204 OUString getPath() const;
205 OUString getFilter() const;
206 void getRealFilter( OUString& _rFilter ) const;
208 ErrCode getGraphic( Graphic& rGraphic ) const;
209 void createMatcher( const OUString& rFactory );
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;
217 void SetContext( FileDialogHelper::Context _eNewContext );
219 inline bool isSystemFilePicker() const { return mbSystemPicker; }
220 inline bool isPasswordEnabled() const { return mbIsPwdEnabled; }
223 } // end of namespace sfx2
225 #endif // INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */