tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / fpicker / source / office / iodlg.hxx
blob9de9261af2d7f3fc03dd80b99db919547b04813f
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 #pragma once
21 #include <memory>
22 #include <com/sun/star/beans/StringPair.hpp>
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <com/sun/star/ucb/IOErrorCode.hpp>
27 #include <unotools/confignode.hxx>
28 #include "asyncfilepicker.hxx"
29 #include "fpsmartcontent.hxx"
30 #include "fpdialogbase.hxx"
31 #include <o3tl/typed_flags_set.hxx>
32 #include <vcl/timer.hxx>
34 #include <set>
35 #include <string_view>
37 class SvtFileView;
38 class SvtFileDialogFilter_Impl;
39 class SvtExpFileDlg_Impl;
40 class SvtURLBox;
42 enum class AdjustFilterFlags {
43 NONE = 0x0000,
44 NonEmpty = 0x0001,
45 Changed = 0x0002,
46 UserFilter = 0x0004,
48 namespace o3tl {
49 template<> struct typed_flags<AdjustFilterFlags> : is_typed_flags<AdjustFilterFlags, 0x0007> {};
53 class SvtFileDialog final : public SvtFileDialog_Base
55 private:
56 std::unique_ptr<weld::CheckButton> m_xCbReadOnly;
57 std::unique_ptr<weld::CheckButton> m_xCbLinkBox;
58 std::unique_ptr<weld::CheckButton> m_xCbPreviewBox;
59 std::unique_ptr<weld::CheckButton> m_xCbSelection;
60 std::unique_ptr<weld::Button> m_xPbPlay;
61 std::unique_ptr<weld::Widget> m_xPreviewFrame;
62 std::unique_ptr<weld::Image> m_xPrevBmp;
63 std::unique_ptr<weld::Container> m_xContainer;
64 std::unique_ptr<SvtFileView> m_xFileView;
65 ::svt::IFilePickerListener* m_pFileNotifier;
66 std::unique_ptr<SvtExpFileDlg_Impl> m_xImpl;
67 Size m_aPreviewSize;
68 PickerFlags m_nPickerFlags;
69 bool m_bIsInExecute : 1;
71 ::svt::SmartContent m_aContent;
73 ::std::set<weld::Widget*> m_aDisabledControls;
75 ::utl::OConfigurationNode m_aConfiguration;
76 ::rtl::Reference< ::svt::AsyncPickerAction >
77 m_pCurrentAsyncAction;
78 bool m_bInExecuteAsync;
79 bool m_bHasFilename;
81 DECL_LINK( FilterSelectHdl_Impl, weld::ComboBox&, void );
82 DECL_LINK( FilterSelectTimerHdl_Impl, Timer*, void );
83 DECL_LINK( NewFolderHdl_Impl, weld::Button&, void );
84 DECL_LINK( OpenUrlHdl_Impl, weld::ComboBox&, bool );
85 DECL_LINK( OpenClickHdl_Impl, weld::Button&, void );
86 DECL_LINK( CancelHdl_Impl, weld::Button&, void );
87 DECL_LINK( FileNameGetFocusHdl_Impl, weld::Widget&, void );
88 DECL_LINK( FileNameModifiedHdl_Impl, weld::ComboBox&, void );
90 DECL_LINK( URLBoxModifiedHdl_Impl, weld::ComboBox&, bool );
91 DECL_LINK( ConnectToServerPressed_Hdl, weld::Button&, void );
93 DECL_LINK( AddPlacePressed_Hdl, weld::Button&, void );
94 DECL_LINK( RemovePlacePressed_Hdl, weld::Button&, void );
95 DECL_LINK( PreviewSizeAllocHdl, const Size&, void);
97 void OpenHdl_Impl(void const * pVoid);
99 /** find a filter with the given wildcard
100 @param _rFilter
101 the wildcard pattern to look for in the filter list
102 @param _bMultiExt
103 allow for filters with more than one extension pattern
104 @param _rFilterChanged
105 set to <TRUE/> if the filter changed
106 @return
107 the filter which has been found
109 SvtFileDialogFilter_Impl* FindFilter_Impl( const OUString& _rFilter,
110 bool _bMultiExt,
111 bool& _rFilterChanged
113 void ExecuteFilter();
114 void OpenMultiSelection_Impl();
115 void AddControls_Impl( );
117 DECL_LINK(SelectHdl_Impl, SvtFileView*, void);
118 DECL_LINK(DblClickHdl_Impl, SvtFileView*, bool);
119 DECL_LINK(EntrySelectHdl_Impl, weld::ComboBox&, void);
120 DECL_LINK(OpenDoneHdl_Impl, SvtFileView*, void);
121 DECL_LINK(AutoExtensionHdl_Impl, weld::Toggleable&, void);
122 DECL_LINK(ClickHdl_Impl, weld::Toggleable&, void);
123 DECL_LINK(PlayButtonHdl_Impl, weld::Button&, void);
124 DECL_LINK(SizeAllocHdl, const Size&, void);
126 // removes a filter with wildcards from the path and returns it
127 static bool IsolateFilterFromPath_Impl( OUString& rPath, OUString& rFilter );
129 OUString m_aPath;
130 OUString m_aDefExt;
132 /** enables or disables the complete UI of the file picker, with only offering a
133 cancel button
135 This method preserves the "enabled" state of its controls in the following sense:
136 If you disable a certain control, then disable the dialog UI, then enable the dialog
137 UI, the control will still be disabled.
138 This is under the assumption that you'll use EnableControl. Direct access to the control
139 (such as pControl->Enable()) will break this.
141 void EnableUI( bool _bEnable );
143 /** enables or disables a control
145 You are strongly encouraged to prefer this method over pControl->Enable( bEnable ). See
146 <member>EnableUI</member> for details.
148 void EnableControl(weld::Widget* pControl, bool bEnable);
149 virtual bool PrepareExecute() override;
151 public:
152 SvtFileDialog( weld::Window* pParent, PickerFlags nBits );
153 virtual ~SvtFileDialog() override;
155 virtual short run() override;
157 void FileSelect();
158 void FilterSelect() override;
160 void SetDenyList( const css::uno::Sequence< OUString >& rDenyList ) override;
161 const css::uno::Sequence< OUString >& GetDenyList() const override;
162 void SetStandardDir( const OUString& rStdDir ) override;
163 const OUString& GetStandardDir() const override;
164 std::vector<OUString> GetPathList() const override; // for MultiSelection
166 void AddFilter( const OUString& rFilter,
167 const OUString& rType ) override;
169 void AddFilterGroup(
170 const OUString& _rFilter,
171 const css::uno::Sequence< css::beans::StringPair >& rFilters ) override;
173 void SetCurFilter( const OUString& rFilter ) override;
174 OUString GetCurFilter() const override;
175 sal_uInt16 GetFilterCount() const;
176 const OUString& GetFilterName( sal_uInt16 nPos ) const;
178 void PrevLevel_Impl();
179 void OpenURL_Impl( const OUString& rURL );
181 SvtFileView* GetView() override;
183 void InitSize();
184 void UpdateControls( const OUString& rURL ) override;
185 void EnableAutocompletion( bool _bEnable = true ) override;
187 void SetFileCallback( ::svt::IFilePickerListener *pNotifier ) override { m_pFileNotifier = pNotifier; }
189 sal_Int32 getAvailableWidth() override;
190 sal_Int32 getAvailableHeight() override;
191 void setImage( const css::uno::Any& rImage ) override;
192 bool getShowState() override;
193 bool isAutoExtensionEnabled() const;
195 OUString getCurrentFileText( ) const override;
196 void setCurrentFileText( const OUString& _rText, bool _bSelectAll = false ) override;
198 void onAsyncOperationStarted() override;
199 void onAsyncOperationFinished() override;
201 void RemovablePlaceSelected(bool enable = true);
203 static void displayIOException( const OUString& _rURL, css::ucb::IOErrorCode _eCode );
205 // inline
206 inline void SetPath( const OUString& rNewURL ) override;
207 inline void SetHasFilename( bool bHasFilename ) override;
208 inline const OUString& GetPath() override;
209 inline void SetDefaultExt( const OUString& rExt );
210 inline void EraseDefaultExt( sal_Int32 _nIndex = 0 );
211 inline const OUString& GetDefaultExt() const;
213 bool ContentIsFolder( const OUString& rURL ) override { return m_aContent.isFolder( rURL ) && m_aContent.isValid(); }
214 bool ContentHasParentFolder( const OUString& rURL );
215 bool ContentCanMakeFolder( const OUString& rURL );
216 bool ContentGetTitle( const OUString& rURL, OUString& rTitle );
218 private:
219 SvtFileDialogFilter_Impl* implAddFilter( const OUString& _rFilter, const OUString& _rType );
221 /** updates m_xUserFilter with a new filter
222 <p>No checks for necessity are made.</p>
224 void createNewUserFilter( const OUString& _rNewFilter );
226 AdjustFilterFlags adjustFilter( const OUString& _rFilter );
228 // IFilePickerController, needed by OControlAccess
229 virtual weld::Widget* getControl( sal_Int16 nControlId, bool bLabelControl = false ) const override;
230 virtual void enableControl( sal_Int16 _nControlId, bool _bEnable ) override;
231 virtual OUString getCurFilter( ) const override;
233 OUString implGetInitialURL( const OUString& _rPath, std::u16string_view _rFallback );
235 /// executes a certain FileView action asynchronously
236 void executeAsync(
237 ::svt::AsyncPickerAction::Action _eAction,
238 const OUString& _rURL,
239 const OUString& _rFilter
242 /** helper function to check and append the default filter extension if
243 necessary.
244 The function checks if the specified filename already contains one of
245 the valid extensions of the specified filter. If not the filter default
246 extension is appended to the filename.
248 @param _rFileName the filename which is checked and extended if necessary.
249 @param _rFilterDefaultExtension the default extension of the used filter.
250 @param _rFilterExtensions a list of one or more valid filter extensions
251 of the used filter.
254 static void appendDefaultExtension(
255 OUString& _rFileName,
256 std::u16string_view _rFilterDefaultExtension,
257 const OUString& _rFilterExtensions);
259 void initDefaultPlaces( );
263 inline void SvtFileDialog::SetPath( const OUString& rNewURL )
265 m_aPath = rNewURL;
269 inline void SvtFileDialog::SetHasFilename( bool bHasFilename )
271 m_bHasFilename = bHasFilename;
275 inline const OUString& SvtFileDialog::GetPath()
277 return m_aPath;
281 inline void SvtFileDialog::SetDefaultExt( const OUString& rExt )
283 m_aDefExt = rExt;
286 inline void SvtFileDialog::EraseDefaultExt( sal_Int32 _nIndex )
288 m_aDefExt = m_aDefExt.copy( 0, _nIndex );
291 inline const OUString& SvtFileDialog::GetDefaultExt() const
293 return m_aDefExt;
297 inline SvtFileView* SvtFileDialog::GetView()
299 return m_xFileView.get();
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */