build fix
[LibreOffice.git] / fpicker / source / office / iodlgimp.cxx
blob62ed95d92af8bfda7ff3c54db052207928427726
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 .
20 #include "iodlgimp.hxx"
21 #include "svtools/headbar.hxx"
22 #include <tools/debug.hxx>
23 #include <tools/urlobj.hxx>
24 #include <vcl/menu.hxx>
25 #include <vcl/msgbox.hxx>
26 #include <vcl/lstbox.hxx>
27 #include <vcl/svapp.hxx>
28 #include "svl/ctypeitm.hxx"
29 #include "svl/eitem.hxx"
30 #include "unotools/viewoptions.hxx"
31 #include "svtools/fileview.hxx"
32 #include "svtools/inettbc.hxx"
33 #include "iodlg.hxx"
34 #include "iodlg.hrc"
35 #include "svtools/imagemgr.hxx"
36 #include <unotools/localfilehelper.hxx>
37 #include "unotools/useroptions.hxx"
38 #include "rtl/instance.hxx"
39 #include <osl/getglobalmutex.hxx>
40 #include <svl/svl.hrc>
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::lang;
44 using namespace ::utl;
47 // ResMgrHolder / SvtSimpleResId
49 namespace
51 struct ResMgrHolder
53 ResMgr * operator ()()
55 return ResMgr::CreateResMgr ("svl");
57 static ResMgr * getOrCreate()
59 return rtl_Instance<
60 ResMgr, ResMgrHolder,
61 osl::MutexGuard, osl::GetGlobalMutex >::create (
62 ResMgrHolder(), osl::GetGlobalMutex());
66 struct SvtSimpleResId : public ResId
68 explicit SvtSimpleResId (sal_uInt16 nId) : ResId (nId, *ResMgrHolder::getOrCreate()) {}
72 SvtFileDialogFilter_Impl::SvtFileDialogFilter_Impl( const OUString& rName, const OUString& rType )
73 :m_aName( rName )
74 ,m_aType( rType )
76 m_aType = m_aType.toAsciiLowerCase();
80 SvtFileDialogFilter_Impl::~SvtFileDialogFilter_Impl()
85 // SvtFileDialogFilterList_Impl
88 //= SvtFileDialogURLSelector
91 SvtFileDialogURLSelector::SvtFileDialogURLSelector( vcl::Window* _pParent, SvtFileDialog* _pDlg, WinBits nBits, sal_uInt16 _nButtonId )
92 :MenuButton ( _pParent, nBits )
93 ,m_pDlg ( _pDlg )
94 ,m_pMenu ( VclPtr<PopupMenu>::Create() )
96 SetStyle( GetStyle() | WB_NOPOINTERFOCUS | WB_RECTSTYLE | WB_SMALLSTYLE );
97 SetModeImage( _pDlg->GetButtonImage( _nButtonId ) );
98 SetDelayMenu(true);
99 SetDropDown(PushButtonDropdownStyle::Toolbox);
103 SvtFileDialogURLSelector::~SvtFileDialogURLSelector()
105 disposeOnce();
108 void SvtFileDialogURLSelector::dispose()
110 m_pMenu.disposeAndClear();
111 m_pDlg.clear();
112 MenuButton::dispose();
116 void SvtFileDialogURLSelector::Activate()
118 m_pMenu->Clear();
120 FillURLMenu( m_pMenu );
122 SetPopupMenu( m_pMenu );
126 //= SvtUpButton_Impl
129 SvtUpButton_Impl::SvtUpButton_Impl( vcl::Window *pParent, SvtFileDialog* pDlg, WinBits nBits )
130 :SvtFileDialogURLSelector( pParent, pDlg, nBits, IMG_FILEDLG_BTN_UP )
135 SvtUpButton_Impl::~SvtUpButton_Impl()
140 void SvtUpButton_Impl::FillURLMenu( PopupMenu* _pMenu )
142 SvtFileView* pBox = GetDialogParent()->GetView();
144 sal_uInt16 nItemId = 1;
146 _aURLs.clear();
148 // determine parent levels
149 INetURLObject aObject( pBox->GetViewURL() );
150 sal_Int32 nCount = aObject.getSegmentCount();
152 ::svtools::VolumeInfo aVolInfo( true /* volume */, false /* remote */,
153 false /* removable */, false /* floppy */,
154 false /* compact disk */ );
155 Image aVolumeImage( SvFileInformationManager::GetFolderImage( aVolInfo ) );
157 while ( nCount >= 1 )
159 aObject.removeSegment();
160 OUString aParentURL(aObject.GetMainURL(INetURLObject::DecodeMechanism::NONE));
162 OUString aTitle;
163 if (!GetDialogParent()->ContentGetTitle(aParentURL, aTitle) || aTitle.isEmpty())
164 aTitle = aObject.getName();
166 Image aImage = ( nCount > 1 ) // if nCount == 1 means workplace, which detects the wrong image
167 ? SvFileInformationManager::GetImage( aObject ) : aVolumeImage;
169 _pMenu->InsertItem( nItemId++, aTitle, aImage );
170 _aURLs.push_back(aParentURL);
172 if ( nCount == 1 )
174 // adjust the title of the top level entry (the workspace)
175 _pMenu->SetItemText( --nItemId, SvtSimpleResId(STR_SVT_MIMETYPE_CNT_FSYSBOX).toString() );
177 --nCount;
182 void SvtUpButton_Impl::Select()
184 sal_uInt16 nId = GetCurItemId();
186 if ( nId )
188 --nId;
189 assert( nId <= _aURLs.size() && "SvtUpButton_Impl:falscher Index" );
191 GetDialogParent()->OpenURL_Impl(_aURLs[nId]);
195 void SvtUpButton_Impl::Click()
197 GetDialogParent()->PrevLevel_Impl();
200 Size SvtUpButton_Impl::GetOptimalSize() const
202 return LogicToPixel(Size(12, 12), MapUnit::MapAppFont);
205 // SvtExpFileDlg_Impl
206 SvtExpFileDlg_Impl::SvtExpFileDlg_Impl() :
208 _pCurFilter ( nullptr ),
209 _pUserFilter ( nullptr ),
210 _pFtFileName ( nullptr ),
211 _pEdFileName ( nullptr ),
212 _pFtFileVersion ( nullptr ),
213 _pLbFileVersion ( nullptr ),
214 _pFtTemplates ( nullptr ),
215 _pLbTemplates ( nullptr ),
216 _pFtImageTemplates ( nullptr ),
217 _pLbImageTemplates ( nullptr ),
218 _pFtFileType ( nullptr ),
219 _pLbFilter ( nullptr ),
220 _pBtnFileOpen ( nullptr ),
221 _pBtnCancel ( nullptr ),
222 _pBtnHelp ( nullptr ),
223 _pBtnUp ( nullptr ),
224 _pBtnNewFolder ( nullptr ),
225 _pCbPassword ( nullptr ),
226 _pEdCurrentPath ( nullptr ),
227 _pCbAutoExtension ( nullptr ),
228 _pCbOptions ( nullptr ),
229 _pPlaces ( nullptr ),
230 _pBtnConnectToServer( nullptr ),
231 _eMode ( FILEDLG_MODE_OPEN ),
232 _eDlgType ( FILEDLG_TYPE_FILEDLG ),
233 _nStyle ( PickerFlags::NONE ),
234 _bDoubleClick ( false ),
235 m_bNeedDelayedFilterExecute ( false ),
236 _pDefaultFilter ( nullptr ),
237 _bMultiSelection ( false )
242 SvtExpFileDlg_Impl::~SvtExpFileDlg_Impl()
244 _pBtnUp.disposeAndClear();
245 delete _pUserFilter;
246 _pPlaces.disposeAndClear();
250 void SvtExpFileDlg_Impl::SetStandardDir( const OUString& _rDir )
252 _aStdDir = _rDir;
253 if ( _aStdDir.isEmpty() )
254 _aStdDir = "file:///";
257 namespace {
258 OUString lcl_DecoratedFilter( const OUString& _rOriginalFilter )
260 OUStringBuffer aDecoratedFilter;
261 aDecoratedFilter.append('<');
262 aDecoratedFilter.append(_rOriginalFilter);
263 aDecoratedFilter.append('>');
264 return aDecoratedFilter.makeStringAndClear();
268 void SvtExpFileDlg_Impl::SetCurFilter( SvtFileDialogFilter_Impl* pFilter, const OUString& rDisplayName )
270 DBG_ASSERT( pFilter, "SvtExpFileDlg_Impl::SetCurFilter: invalid filter!" );
271 DBG_ASSERT( ( rDisplayName == pFilter->GetName() )
272 || ( rDisplayName == lcl_DecoratedFilter( pFilter->GetName() ) ),
273 "SvtExpFileDlg_Impl::SetCurFilter: arguments are inconsistent!" );
275 _pCurFilter = pFilter;
276 m_sCurrentFilterDisplayName = rDisplayName;
280 void SvtExpFileDlg_Impl::InsertFilterListEntry( const SvtFileDialogFilter_Impl* _pFilterDesc )
282 OUString sName = _pFilterDesc->GetName();
283 if ( _pFilterDesc->isGroupSeparator() )
284 sName = "------------------------------------------";
285 else
286 sName = _pFilterDesc->GetName();
288 // insert an set user data
289 const sal_Int32 nPos = _pLbFilter->InsertEntry( sName );
290 _pLbFilter->SetEntryData( nPos, const_cast< void* >( static_cast< const void* >( _pFilterDesc ) ) );
294 void SvtExpFileDlg_Impl::InitFilterList( )
296 // clear the current list
297 _pLbFilter->Clear();
299 // reinit it
300 sal_uInt16 nPos = m_aFilter.size();
302 // search for the first entry which is no group separator
303 while ( nPos-- && m_aFilter[ nPos ]->isGroupSeparator() )
306 // add all following entries
307 while ( (sal_Int16)nPos >= 0 )
308 InsertFilterListEntry( m_aFilter[ nPos-- ].get() );
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */