Use COMReference to handle COM pointers in CreateShortcut
[LibreOffice.git] / sfx2 / source / dialog / filedlgimpl.hxx
blobb7ec174d0bb1003bed19f350fec4fdd8916a0da5
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/implbase.hxx>
26 #include <com/sun/star/beans/StringPair.hpp>
27 #include <com/sun/star/container/XNameAccess.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>
33 class SfxFilterMatcher;
34 class GraphicFilter;
35 class FileDialogHelper;
36 struct ImplSVEvent;
38 namespace sfx2
40 class FileDialogHelper_Impl :
41 public ::cppu::WeakImplHelper<
42 css::ui::dialogs::XFilePickerListener,
43 css::ui::dialogs::XDialogClosedListener >
45 friend class FileDialogHelper;
47 css::uno::Reference < css::ui::dialogs::XFilePicker3 > mxFileDlg;
48 css::uno::Reference < css::container::XNameAccess > mxFilterCFG;
50 std::vector< css::beans::StringPair > maFilters;
52 SfxFilterMatcher* mpMatcher;
53 std::unique_ptr<GraphicFilter> mpGraphicFilter;
54 FileDialogHelper* mpAntiImpl;
55 weld::Window* mpFrameWeld;
57 ::std::vector< OUString > mlLastURLs;
59 OUString maPath;
60 OUString maFileName;
61 OUString maCurFilter;
62 OUString maSelectFilter;
63 OUString maButtonLabel;
65 Idle maPreviewIdle;
66 Graphic maGraphic;
68 const short m_nDialogType;
70 SfxFilterFlags m_nMustFlags;
71 SfxFilterFlags m_nDontFlags;
73 FileDialogHelper::Context meContext;
75 bool mbHasPassword : 1; // checkbox is visible
76 bool mbIsPwdEnabled : 1; // password checkbox is not grayed out
77 bool mbIsGpgEncrEnabled : 1; // GPG checkbox is not grayed out
78 bool m_bHaveFilterOptions : 1;
79 bool mbHasVersions : 1;
80 bool mbHasAutoExt : 1;
81 bool mbHasPreview : 1;
82 bool mbShowPreview : 1;
83 bool mbIsSaveDlg : 1;
84 bool mbExport : 1;
86 bool mbDeleteMatcher : 1;
87 bool mbInsert : 1;
88 bool mbSystemPicker : 1;
89 bool mbAsyncPicker : 1;
90 bool mbPwdCheckBoxState : 1;
91 bool mbGpgCheckBoxState : 1;
92 bool mbSelection : 1;
93 bool mbSelectionEnabled : 1;
94 bool mbHasSelectionBox : 1;
95 bool mbSelectionFltrEnabled : 1;
96 bool mbHasSignByDefault : 1;
98 private:
99 void addFilters( const OUString& rFactory,
100 SfxFilterFlags nMust,
101 SfxFilterFlags nDont );
102 void addFilter( const OUString& rFilterName,
103 const OUString& rExtension );
104 void addGraphicFilter();
105 void enablePasswordBox( bool bInit );
106 void enableGpgEncrBox( bool bInit );
107 void updateFilterOptionsBox();
108 void updateExportButton();
109 void updateSelectionBox();
110 void updateSignByDefault();
111 void updateVersions();
112 void updatePreviewState( bool _bUpdatePreviewWindow );
113 void dispose();
115 void loadConfig();
116 void saveConfig();
118 std::shared_ptr<const SfxFilter> getCurrentSfxFilter();
119 bool updateExtendedControl( sal_Int16 _nExtendedControlId, bool _bEnable );
121 ErrCode getGraphic( const OUString& rURL, Graphic& rGraphic ) const;
122 void setDefaultValues();
124 void preExecute();
125 void postExecute( sal_Int16 _nResult );
126 sal_Int16 implDoExecute();
127 void implStartExecute();
129 void setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId );
131 bool CheckFilterOptionsCapability( const std::shared_ptr<const SfxFilter>& _pFilter );
133 bool isInOpenMode() const;
134 OUString getCurrentFilterUIName() const;
136 void LoadLastUsedFilter( const OUString& _rContextIdentifier );
137 void SaveLastUsedFilter();
139 void implInitializeFileName( );
141 void verifyPath( );
143 void implGetAndCacheFiles( const css::uno::Reference< XInterface >& xPicker ,
144 std::vector<OUString>& rpURLList );
146 DECL_LINK( TimeOutHdl_Impl, Timer *, void);
148 public:
149 // XFilePickerListener methods
150 virtual void SAL_CALL fileSelectionChanged( const css::ui::dialogs::FilePickerEvent& aEvent ) override;
151 virtual void SAL_CALL directoryChanged( const css::ui::dialogs::FilePickerEvent& aEvent ) override;
152 virtual OUString SAL_CALL helpRequested( const css::ui::dialogs::FilePickerEvent& aEvent ) override;
153 virtual void SAL_CALL controlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent ) override;
154 virtual void SAL_CALL dialogSizeChanged() override;
156 // XDialogClosedListener methods
157 virtual void SAL_CALL dialogClosed( const css::ui::dialogs::DialogClosedEvent& _rEvent ) override;
159 // XEventListener methods
160 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
162 // handle XFilePickerListener events
163 void handleFileSelectionChanged();
164 void handleDirectoryChanged();
165 static OUString handleHelpRequested( const css::ui::dialogs::FilePickerEvent& aEvent );
166 void handleControlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent );
167 void handleDialogSizeChanged();
169 // Own methods
170 FileDialogHelper_Impl(
171 FileDialogHelper* _pAntiImpl,
172 const sal_Int16 nDialogType,
173 FileDialogFlags nFlags,
174 sal_Int16 nDialog,
175 weld::Window* pFrameWeld,
176 const OUString& sStandardDir = OUString(),
177 const css::uno::Sequence< OUString >& rDenyList = css::uno::Sequence< OUString >()
179 virtual ~FileDialogHelper_Impl() override;
181 ErrCode execute( std::vector<OUString>& rpURLList,
182 std::optional<SfxAllItemSet>& rpSet,
183 OUString& rFilter );
184 ErrCode execute();
186 void setFilter( const OUString& rFilter );
188 /** sets the directory which should be browsed
190 <p>If the given path does not point to a valid (existent and accessible) folder, the request
191 is silently dropped</p>
193 void displayFolder( const OUString& rPath );
194 void setFileName( const OUString& _rFile );
196 OUString getPath() const;
197 OUString getFilter() const;
198 void getRealFilter( OUString& _rFilter ) const;
200 ErrCode getGraphic( Graphic& rGraphic ) const;
201 void createMatcher( const OUString& rFactory );
203 bool isShowFilterExtensionEnabled() const;
204 void addFilterPair( const OUString& rFilter,
205 const OUString& rFilterWithExtension );
206 OUString getFilterName( std::u16string_view rFilterWithExtension ) const;
207 OUString getFilterWithExtension( std::u16string_view rFilter ) const;
209 void SetContext( FileDialogHelper::Context _eNewContext );
210 OUString getInitPath( std::u16string_view _rFallback, const sal_Int32 _nFallbackToken );
212 bool isAsyncFilePicker() const { return mbAsyncPicker; }
213 bool isPasswordEnabled() const { return mbIsPwdEnabled; }
215 css::uno::Reference<css::awt::XWindow> GetFrameInterface();
218 } // end of namespace sfx2
220 #endif // INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */