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 .
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 // #97148# ---------------
29 #include "svl/ctypeitm.hxx"
30 #include "svl/eitem.hxx"
31 #include "unotools/viewoptions.hxx"
32 #include "svtools/fileview.hxx"
33 #include "svtools/inettbc.hxx"
36 #include "svtools/imagemgr.hxx"
37 #include <unotools/localfilehelper.hxx>
38 #include "unotools/useroptions.hxx"
39 #include "rtl/instance.hxx"
40 #include <svl/svl.hrc>
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::utl
;
46 // some stuff for easier changes for SvtViewOptions
47 static const sal_Char
* pViewOptDataName
= "dialog data";
48 #define VIEWOPT_DATANAME OUString::createFromAscii( pViewOptDataName )
50 static inline void SetViewOptUserItem( SvtViewOptions
& rOpt
, const String
& rData
)
52 rOpt
.SetUserItem( VIEWOPT_DATANAME
, makeAny( OUString( rData
) ) );
55 static inline String
GetViewOptUserItem( const SvtViewOptions
& rOpt
)
57 Any
aAny( rOpt
.GetUserItem( VIEWOPT_DATANAME
) );
61 return String( aUserData
);
64 //*****************************************************************************
65 // ResMgrHolder / SvtSimpleResId
66 //*****************************************************************************
71 ResMgr
* operator ()()
73 return ResMgr::CreateResMgr ("svl");
75 static ResMgr
* getOrCreate()
79 osl::MutexGuard
, osl::GetGlobalMutex
>::create (
80 ResMgrHolder(), osl::GetGlobalMutex());
84 struct SvtSimpleResId
: public ResId
86 SvtSimpleResId (sal_uInt16 nId
) : ResId (nId
, *ResMgrHolder::getOrCreate()) {}
90 //*****************************************************************************
91 // SvtFileDialogFilter_Impl
92 //*****************************************************************************
94 DBG_NAME( SvtFileDialogFilter_Impl
)
95 SvtFileDialogFilter_Impl::SvtFileDialogFilter_Impl( const String
& rName
, const String
& rType
)
99 DBG_CTOR( SvtFileDialogFilter_Impl
, NULL
);
101 m_aType
.ToLowerAscii();
104 //*****************************************************************************
106 SvtFileDialogFilter_Impl::~SvtFileDialogFilter_Impl()
108 DBG_DTOR( SvtFileDialogFilter_Impl
, NULL
);
111 //*****************************************************************************
112 // SvtFileDialogFilterList_Impl
113 //*****************************************************************************
115 //=============================================================================
116 //= SvtFileDialogURLSelector
117 //=============================================================================
119 //-----------------------------------------------------------------------------
120 SvtFileDialogURLSelector::SvtFileDialogURLSelector( SvtFileDialog
* _pParent
, const ResId
& _rResId
, sal_uInt16 _nButtonId
)
121 :MenuButton ( _pParent
, _rResId
)
122 ,m_pParent ( _pParent
)
123 ,m_pMenu ( new PopupMenu
)
125 SetStyle( GetStyle() | WB_NOPOINTERFOCUS
| WB_RECTSTYLE
| WB_SMALLSTYLE
);
126 SetModeImage( m_pParent
->GetButtonImage( _nButtonId
) );
127 SetMenuMode( MENUBUTTON_MENUMODE_TIMED
);
128 SetDropDown( PUSHBUTTON_DROPDOWN_TOOLBOX
);
131 //-----------------------------------------------------------------------------
132 SvtFileDialogURLSelector::~SvtFileDialogURLSelector()
137 //-----------------------------------------------------------------------------
138 void SvtFileDialogURLSelector::Activate()
142 FillURLMenu( m_pMenu
);
144 SetPopupMenu( m_pMenu
);
147 //=============================================================================
149 //=============================================================================
151 //-----------------------------------------------------------------------------
152 SvtUpButton_Impl::SvtUpButton_Impl( SvtFileDialog
* pParent
, const ResId
& rResId
)
153 :SvtFileDialogURLSelector( pParent
, rResId
, IMG_FILEDLG_BTN_UP
)
157 //-----------------------------------------------------------------------------
158 SvtUpButton_Impl::~SvtUpButton_Impl()
162 //-----------------------------------------------------------------------------
163 void SvtUpButton_Impl::FillURLMenu( PopupMenu
* _pMenu
)
165 SvtFileView
* pBox
= GetDialogParent()->GetView();
167 sal_uInt16 nItemId
= 1;
171 // determine parent levels
172 INetURLObject
aObject( pBox
->GetViewURL() );
173 sal_Int32 nCount
= aObject
.getSegmentCount();
175 ::svtools::VolumeInfo
aVolInfo( sal_True
/* volume */, sal_False
/* remote */,
176 sal_False
/* removable */, sal_False
/* floppy */,
177 sal_False
/* compact disk */ );
178 Image
aVolumeImage( SvFileInformationManager::GetFolderImage( aVolInfo
) );
180 while ( nCount
>= 1 )
182 aObject
.removeSegment();
183 String
aParentURL(aObject
.GetMainURL(INetURLObject::NO_DECODE
));
186 // 97148# --------------------------------
187 if (!GetDialogParent()->ContentGetTitle(aParentURL
, aTitle
) || aTitle
.Len() == 0)
188 aTitle
= aObject
.getName();
190 Image aImage
= ( nCount
> 1 ) // if nCount == 1 means workplace, which detects the wrong image
191 ? SvFileInformationManager::GetImage( aObject
) : aVolumeImage
;
193 _pMenu
->InsertItem( nItemId
++, aTitle
, aImage
);
194 _aURLs
.push_back(aParentURL
);
198 // adjust the title of the top level entry (the workspace)
199 _pMenu
->SetItemText( --nItemId
, SvtSimpleResId( STR_SVT_MIMETYPE_CNT_FSYSBOX
) );
205 //-----------------------------------------------------------------------------
206 void SvtUpButton_Impl::Select()
208 sal_uInt16 nId
= GetCurItemId();
213 DBG_ASSERT( nId
<= _aURLs
.size(), "SvtUpButton_Impl:falscher Index" );
215 GetDialogParent()->OpenURL_Impl(_aURLs
[nId
]);
219 //-----------------------------------------------------------------------------
220 void SvtUpButton_Impl::Click()
222 GetDialogParent()->PrevLevel_Impl();
225 //*****************************************************************************
226 // SvtExpFileDlg_Impl
227 //*****************************************************************************
229 SvtExpFileDlg_Impl::SvtExpFileDlg_Impl( WinBits
) :
232 _pCurFilter ( NULL
),
233 _pFilter ( new SvtFileDialogFilterList_Impl() ),
234 _pUserFilter ( NULL
),
235 _pFtFileName ( NULL
),
236 _pEdFileName ( NULL
),
237 _pFtFileVersion ( NULL
),
238 _pLbFileVersion ( NULL
),
239 _pFtTemplates ( NULL
),
240 _pLbTemplates ( NULL
),
241 _pFtImageTemplates ( NULL
),
242 _pLbImageTemplates ( NULL
),
243 _pFtFileType ( NULL
),
244 _pBtnFileOpen ( NULL
),
245 _pBtnCancel ( NULL
),
248 _pBtnNewFolder ( NULL
),
249 _pCbPassword ( NULL
),
250 _pEdCurrentPath ( NULL
),
251 _pCbAutoExtension ( NULL
),
252 _pCbOptions ( NULL
),
254 _pBtnConnectToServer( NULL
),
255 _nState ( FILEDLG_STATE_REMOTE
),
257 _bDoubleClick ( sal_False
),
258 m_bNeedDelayedFilterExecute ( sal_False
),
259 _pDefaultFilter ( NULL
),
260 _bMultiSelection ( sal_False
),
261 _nFixDeltaHeight ( 0 ),
262 _bFolderHasOpened ( sal_False
)
266 //*****************************************************************************
268 SvtExpFileDlg_Impl::~SvtExpFileDlg_Impl()
270 delete _pEdCurrentPath
;
272 delete _pCbAutoExtension
;
274 delete _pBtnNewFolder
;
278 delete _pBtnFileOpen
;
281 delete _pLbFileVersion
;
282 delete _pFtFileVersion
;
283 delete _pFtTemplates
;
284 delete _pLbTemplates
;
285 delete _pFtImageTemplates
;
286 delete _pLbImageTemplates
;
292 delete _pBtnConnectToServer
;
295 //*****************************************************************************
297 void SvtExpFileDlg_Impl::SetStandardDir( const String
& _rDir
)
300 if ( 0 == _aStdDir
.Len() )
301 _aStdDir
.AssignAscii( "file:///" );
304 //*****************************************************************************
306 //-----------------------------------------------------------------------------
308 String
lcl_DecoratedFilter( const String
& _rOriginalFilter
)
310 OUStringBuffer aDecoratedFilter
;
311 aDecoratedFilter
.append('<');
312 aDecoratedFilter
.append(_rOriginalFilter
);
313 aDecoratedFilter
.append('>');
314 return aDecoratedFilter
.makeStringAndClear();
318 //-----------------------------------------------------------------------------
320 void SvtExpFileDlg_Impl::ClearFilterList( )
325 //-----------------------------------------------------------------------------
326 void SvtExpFileDlg_Impl::SetCurFilter( SvtFileDialogFilter_Impl
* pFilter
, const String
& rDisplayName
)
328 DBG_ASSERT( pFilter
, "SvtExpFileDlg_Impl::SetCurFilter: invalid filter!" );
329 DBG_ASSERT( ( rDisplayName
== pFilter
->GetName() )
330 || ( rDisplayName
== lcl_DecoratedFilter( pFilter
->GetName() ) ),
331 "SvtExpFileDlg_Impl::SetCurFilter: arguments are inconsistent!" );
333 _pCurFilter
= pFilter
;
334 m_sCurrentFilterDisplayName
= rDisplayName
;
337 //-----------------------------------------------------------------------------
338 void SvtExpFileDlg_Impl::InsertFilterListEntry( const SvtFileDialogFilter_Impl
* _pFilterDesc
)
340 String sName
= _pFilterDesc
->GetName();
341 if ( _pFilterDesc
->isGroupSeparator() )
342 sName
= OUString( "------------------------------------------" );
344 sName
= _pFilterDesc
->GetName();
346 // insert an set user data
347 sal_uInt16 nPos
= _pLbFilter
->InsertEntry( sName
);
348 _pLbFilter
->SetEntryData( nPos
, const_cast< void* >( static_cast< const void* >( _pFilterDesc
) ) );
351 //-----------------------------------------------------------------------------
353 void SvtExpFileDlg_Impl::InitFilterList( )
355 // clear the current list
359 sal_uInt16 nPos
= _pFilter
->size();
361 // search for the first entry which is no group separator
362 while ( nPos
-- && (*_pFilter
)[ nPos
].isGroupSeparator() )
365 // add all following entries
366 while ( (sal_Int16
)nPos
>= 0 )
367 InsertFilterListEntry( &(*_pFilter
)[ nPos
-- ] );
370 //-----------------------------------------------------------------------------
372 void SvtExpFileDlg_Impl::CreateFilterListControl( Window
* _pParent
, const ResId
& _rId
)
374 DBG_ASSERT( !_pLbFilter
, "SvtExpFileDlg_Impl::CreateFilterListControl: already created the control!" );
377 _pLbFilter
= new ListBox( _pParent
, _rId
);
378 _pLbFilter
->SetDropDownLineCount( 10 );
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */