1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
35 class FileDialogHelper
;
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
;
62 OUString maSelectFilter
;
63 OUString maButtonLabel
;
68 const short m_nDialogType
;
70 SfxFilterFlags m_nMustFlags
;
71 SfxFilterFlags m_nDontFlags
;
73 ImplSVEvent
* mnPostUserEventId
;
75 FileDialogHelper::Context meContext
;
77 bool mbHasPassword
: 1;
78 bool mbIsPwdEnabled
: 1;
79 bool m_bHaveFilterOptions
: 1;
80 bool mbHasVersions
: 1;
81 bool mbHasAutoExt
: 1;
82 bool mbHasPreview
: 1;
83 bool mbShowPreview
: 1;
87 bool mbDeleteMatcher
: 1;
89 bool mbSystemPicker
: 1;
90 bool mbAsyncPicker
: 1;
91 bool mbPwdCheckBoxState
: 1;
93 bool mbSelectionEnabled
: 1;
94 bool mbHasSelectionBox
: 1;
95 bool mbSelectionFltrEnabled
: 1;
98 void addFilters( const OUString
& rFactory
,
100 SfxFilterFlags nDont
);
101 void addFilter( const OUString
& rFilterName
,
102 const OUString
& rExtension
);
103 void addGraphicFilter();
104 void enablePasswordBox( bool bInit
);
105 void updateFilterOptionsBox();
106 void updateExportButton();
107 void updateSelectionBox();
108 void updateVersions();
109 void updatePreviewState( bool _bUpdatePreviewWindow
);
115 std::shared_ptr
<const SfxFilter
> getCurentSfxFilter();
116 bool updateExtendedControl( sal_Int16 _nExtendedControlId
, bool _bEnable
);
118 ErrCode
getGraphic( const OUString
& rURL
, Graphic
& rGraphic
) const;
119 void setDefaultValues();
122 void postExecute( sal_Int16 _nResult
);
123 sal_Int16
implDoExecute();
124 void implStartExecute();
126 void setControlHelpIds( const sal_Int16
* _pControlId
, const char** _pHelpId
);
128 bool CheckFilterOptionsCapability( const std::shared_ptr
<const SfxFilter
>& _pFilter
);
130 bool isInOpenMode() const;
131 OUString
getCurrentFilterUIName() const;
133 void LoadLastUsedFilter( const OUString
& _rContextIdentifier
);
134 void SaveLastUsedFilter();
136 void implInitializeFileName( );
140 void implGetAndCacheFiles( const css::uno::Reference
< XInterface
>& xPicker
,
141 std::vector
<OUString
>& rpURLList
);
143 DECL_LINK( TimeOutHdl_Impl
, Timer
*, void);
144 DECL_LINK( InitControls
, void*, void );
147 // XFilePickerListener methods
148 virtual void SAL_CALL
fileSelectionChanged( const css::ui::dialogs::FilePickerEvent
& aEvent
) override
;
149 virtual void SAL_CALL
directoryChanged( const css::ui::dialogs::FilePickerEvent
& aEvent
) override
;
150 virtual OUString SAL_CALL
helpRequested( const css::ui::dialogs::FilePickerEvent
& aEvent
) override
;
151 virtual void SAL_CALL
controlStateChanged( const css::ui::dialogs::FilePickerEvent
& aEvent
) override
;
152 virtual void SAL_CALL
dialogSizeChanged() override
;
154 // XDialogClosedListener methods
155 virtual void SAL_CALL
dialogClosed( const css::ui::dialogs::DialogClosedEvent
& _rEvent
) override
;
157 // XEventListener methods
158 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
160 // handle XFilePickerListener events
161 void handleFileSelectionChanged();
162 void handleDirectoryChanged();
163 static OUString
handleHelpRequested( const css::ui::dialogs::FilePickerEvent
& aEvent
);
164 void handleControlStateChanged( const css::ui::dialogs::FilePickerEvent
& aEvent
);
165 void handleDialogSizeChanged();
168 FileDialogHelper_Impl(
169 FileDialogHelper
* _pAntiImpl
,
170 const sal_Int16 nDialogType
,
171 FileDialogFlags nFlags
,
173 weld::Window
* pFrameWeld
,
174 const OUString
& sStandardDir
= OUString(),
175 const css::uno::Sequence
< OUString
>& rDenyList
= css::uno::Sequence
< OUString
>()
177 virtual ~FileDialogHelper_Impl() override
;
179 ErrCode
execute( std::vector
<OUString
>& rpURLList
,
180 std::optional
<SfxAllItemSet
>& rpSet
,
184 void setFilter( const OUString
& rFilter
);
186 /** sets the directory which should be browsed
188 <p>If the given path does not point to a valid (existent and accessible) folder, the request
189 is silently dropped</p>
191 void displayFolder( const OUString
& rPath
);
192 void setFileName( const OUString
& _rFile
);
194 OUString
getPath() const;
195 OUString
getFilter() const;
196 void getRealFilter( OUString
& _rFilter
) const;
198 ErrCode
getGraphic( Graphic
& rGraphic
) const;
199 void createMatcher( const OUString
& rFactory
);
201 bool isShowFilterExtensionEnabled() const;
202 void addFilterPair( const OUString
& rFilter
,
203 const OUString
& rFilterWithExtension
);
204 OUString
getFilterName( std::u16string_view rFilterWithExtension
) const;
205 OUString
getFilterWithExtension( std::u16string_view rFilter
) const;
207 void SetContext( FileDialogHelper::Context _eNewContext
);
208 OUString
getInitPath( const OUString
& _rFallback
, const sal_Int32 _nFallbackToken
);
210 bool isAsyncFilePicker() const { return mbAsyncPicker
; }
211 bool isPasswordEnabled() const { return mbIsPwdEnabled
; }
213 css::uno::Reference
<css::awt::XWindow
> GetFrameInterface();
216 } // end of namespace sfx2
218 #endif // INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */