Update ooo320-m1
[ooovba.git] / fpicker / source / office / iodlgimp.cxx
blobf3b768ac535f7d5d35244de0881d3ad41b88b6bf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: iodlgimp.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_fpicker.hxx"
34 // includes *******************************************************************
36 #include "iodlgimp.hxx"
37 #include "svtools/headbar.hxx"
38 #include <tools/debug.hxx>
39 #include <tools/wldcrd.hxx>
40 #include <tools/urlobj.hxx>
41 #include <vcl/menu.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <vcl/lstbox.hxx>
44 #include <vcl/svapp.hxx>
45 // #97148# ---------------
46 #include "svtools/ctypeitm.hxx"
47 #include "svtools/eitem.hxx"
48 #include "svtools/viewoptions.hxx"
49 #include "svtools/fileview.hxx"
50 #include "svtools/inettbc.hxx"
51 #include "iodlg.hxx"
52 #ifndef _SVTOOLS_IODLGIMPL_HRC
53 #include "iodlg.hrc"
54 #endif
55 #include "svtools/imagemgr.hxx"
56 #include <unotools/localfilehelper.hxx>
57 #include "svtools/useroptions.hxx"
58 #ifndef _RTL_INSTANCE_HXX_
59 #include "rtl/instance.hxx"
60 #endif
62 #define _SVSTDARR_STRINGSSORTDTOR
63 #define _SVSTDARR_STRINGSDTOR
64 #define _SVSTDARR_USHORTS
65 #include "svtools/svstdarr.hxx"
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::lang;
69 using namespace ::utl;
71 // some stuff for easier changes for SvtViewOptions
72 static const sal_Char* pViewOptDataName = "dialog data";
73 #define VIEWOPT_DATANAME ::rtl::OUString::createFromAscii( pViewOptDataName )
75 static inline void SetViewOptUserItem( SvtViewOptions& rOpt, const String& rData )
77 rOpt.SetUserItem( VIEWOPT_DATANAME, makeAny( ::rtl::OUString( rData ) ) );
80 static inline String GetViewOptUserItem( const SvtViewOptions& rOpt )
82 Any aAny( rOpt.GetUserItem( VIEWOPT_DATANAME ) );
83 ::rtl::OUString aUserData;
84 aAny >>= aUserData;
86 return String( aUserData );
90 // defines f"ur den Style der BrowseBox
92 #define STYLE_MULTI_SELECTION \
93 CNTVIEWSTYLE_NODE_BUTTONS | \
94 CNTVIEWSTYLE_NODE_BUTTONS_AT_ROOT | \
95 CNTVIEWSTYLE_SHOW_MESSAGES | \
96 CNTVIEWSTYLE_SHOW_FOLDERS | \
97 CNTVIEWSTYLE_NO_SMARTHIGHLIGHT | \
98 CNTVIEWSTYLE_HIDE_OPENMENU | \
99 CNTVIEWSTYLE_DEFAULT_APPEARANCE | \
100 CNTVIEWSTYLE_SORT_BY_FOLDER
102 #define STYLE_SINGLE_SELECTION \
103 STYLE_MULTI_SELECTION | CNTVIEWSTYLE_SINGLE_SELECTION
105 #define BOOL_NOT_INITIALIZE ((sal_Bool)2)
107 //*****************************************************************************
108 // ResMgrHolder / SvtSimpleResId
109 //*****************************************************************************
110 namespace
112 struct ResMgrHolder
114 ResMgr * operator ()()
116 return ResMgr::CreateResMgr (CREATEVERSIONRESMGR_NAME(svs));
118 static ResMgr * getOrCreate()
120 return rtl_Instance<
121 ResMgr, ResMgrHolder,
122 osl::MutexGuard, osl::GetGlobalMutex >::create (
123 ResMgrHolder(), osl::GetGlobalMutex());
127 struct SvtSimpleResId : public ResId
129 SvtSimpleResId (USHORT nId) : ResId (nId, *ResMgrHolder::getOrCreate()) {}
133 //*****************************************************************************
134 // SvtFileDialogFilter_Impl
135 //*****************************************************************************
137 DBG_NAME( SvtFileDialogFilter_Impl )
138 SvtFileDialogFilter_Impl::SvtFileDialogFilter_Impl( const String& rName, const String& rType )
139 :m_aName( rName )
140 ,m_aType( rType )
142 DBG_CTOR( SvtFileDialogFilter_Impl, NULL );
144 m_aType.ToLowerAscii();
147 //*****************************************************************************
149 SvtFileDialogFilter_Impl::~SvtFileDialogFilter_Impl()
151 DBG_DTOR( SvtFileDialogFilter_Impl, NULL );
154 //*****************************************************************************
155 // SvtFileDialogFilterList_Impl
156 //*****************************************************************************
158 SV_IMPL_PTRARR( SvtFileDialogFilterList_Impl, SvtFileDialogFilter_Impl* );
160 //=============================================================================
161 //= SvtFileDialogURLSelector
162 //=============================================================================
164 //-----------------------------------------------------------------------------
165 SvtFileDialogURLSelector::SvtFileDialogURLSelector( SvtFileDialog* _pParent, const ResId& _rResId, sal_uInt16 _nButtonId )
166 :MenuButton ( _pParent, _rResId )
167 ,m_pParent ( _pParent )
168 ,m_pMenu ( new PopupMenu )
170 SetStyle( GetStyle() | WB_NOPOINTERFOCUS | WB_RECTSTYLE | WB_SMALLSTYLE );
171 SetModeImage( m_pParent->GetButtonImage( _nButtonId ) );
172 SetMenuMode( MENUBUTTON_MENUMODE_TIMED );
173 SetDropDown( PUSHBUTTON_DROPDOWN_TOOLBOX );
176 //-----------------------------------------------------------------------------
177 SvtFileDialogURLSelector::~SvtFileDialogURLSelector()
179 delete m_pMenu;
182 //-----------------------------------------------------------------------------
183 void SvtFileDialogURLSelector::OpenURL( const String& rURL )
185 INetURLObject aObj( rURL );
186 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "SvtFileDialogURLSelector::OpenURL: Invalid URL!" );
187 m_pParent->OpenURL_Impl( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
190 //-----------------------------------------------------------------------------
191 void SvtFileDialogURLSelector::Activate()
193 m_pMenu->Clear();
195 FillURLMenu( m_pMenu );
197 SetPopupMenu( m_pMenu );
200 //=============================================================================
201 //= SvtUpButton_Impl
202 //=============================================================================
204 //-----------------------------------------------------------------------------
205 SvtUpButton_Impl::SvtUpButton_Impl( SvtFileDialog* pParent, const ResId& rResId )
206 :SvtFileDialogURLSelector( pParent, rResId, IMG_FILEDLG_BTN_UP )
207 ,_pURLs ( NULL )
211 //-----------------------------------------------------------------------------
212 SvtUpButton_Impl::~SvtUpButton_Impl()
214 delete _pURLs;
217 //-----------------------------------------------------------------------------
218 void SvtUpButton_Impl::FillURLMenu( PopupMenu* _pMenu )
220 SvtFileView* pBox = GetDialogParent()->GetView();
222 sal_uInt16 nItemId = 1;
224 delete _pURLs;
225 _pURLs = new SvStringsDtor;
227 // "Ubergeordnete Ebenen bestimmen.
228 INetURLObject aObject( pBox->GetViewURL() );
229 sal_Int32 nCount = aObject.getSegmentCount();
231 ::svtools::VolumeInfo aVolInfo( sal_True /* volume */, sal_False /* remote */,
232 sal_False /* removable */, sal_False /* floppy */,
233 sal_False /* compact disk */ );
234 sal_Bool bIsHighContrast = pBox->GetDisplayBackground().GetColor().IsDark();
235 Image aVolumeImage( SvFileInformationManager::GetFolderImage( aVolInfo, bIsHighContrast ) );
237 while ( nCount >= 1 )
239 aObject.removeSegment();
240 String* pParentURL = new String( aObject.GetMainURL( INetURLObject::NO_DECODE ) );
242 if ( GetDialogParent()->isUrlAllowed( *pParentURL ) )
244 String aTitle;
245 // 97148# --------------------------------
246 if ( !GetDialogParent()->ContentGetTitle( *pParentURL, aTitle ) || aTitle.Len() == 0 )
247 aTitle = aObject.getName();
249 Image aImage = ( nCount > 1 ) // if nCount == 1 means workplace, which detects the wrong image
250 ? SvFileInformationManager::GetImage( aObject, bIsHighContrast )
251 : aVolumeImage;
253 _pMenu->InsertItem( nItemId++, aTitle, aImage );
254 _pURLs->Insert( pParentURL, _pURLs->Count() );
256 if ( nCount == 1 )
258 // adjust the title of the top level entry (the workspace)
259 _pMenu->SetItemText( --nItemId, SvtSimpleResId( STR_SVT_MIMETYPE_CNT_FSYSBOX ) );
263 --nCount;
267 //-----------------------------------------------------------------------------
268 void SvtUpButton_Impl::Select()
270 sal_uInt16 nId = GetCurItemId();
272 if ( nId )
274 --nId;
275 DBG_ASSERT( nId <= _pURLs->Count(), "SvtUpButton_Impl:falscher Index" );
277 String aURL = *(_pURLs->GetObject( nId ));
278 GetDialogParent()->OpenURL_Impl( aURL );
282 //-----------------------------------------------------------------------------
283 void SvtUpButton_Impl::Click()
285 GetDialogParent()->PrevLevel_Impl();
288 //=============================================================================
289 //= SvtTravelButton_Impl
290 //=============================================================================
292 //-----------------------------------------------------------------------------
293 SvtTravelButton_Impl::SvtTravelButton_Impl( SvtFileDialog* pParent, const ResId& rResId )
294 :SvtFileDialogURLSelector ( pParent, rResId, IMG_FILEDLG_BTN_STD )
296 SetDropDown( 0 ); // by default, don't drop down, as we don't have favourites
299 //-----------------------------------------------------------------------------
300 void SvtTravelButton_Impl::SetFavouriteLocations( const ::std::vector< String >& _rLocations )
302 m_aFavourites = _rLocations;
303 // enable the drop down if and only if we have favourites
304 SetDropDown( m_aFavourites.empty() ? 0 : PUSHBUTTON_DROPDOWN_TOOLBOX );
307 //-----------------------------------------------------------------------------
308 SvtTravelButton_Impl::~SvtTravelButton_Impl()
312 //-----------------------------------------------------------------------------
313 void SvtTravelButton_Impl::FillURLMenu( PopupMenu* _pMenu )
315 if ( m_aFavourites.empty() )
316 // though we claimed that we do not want to have a drop down button
317 // in this case, VCL nevertheless behaves as if we had one .... :(
318 return;
320 _pMenu->Clear();
322 sal_Bool bIsHighContrast = GetDialogParent()->GetView()->GetDisplayBackground().GetColor().IsDark();
324 USHORT nItemId = 1;
325 String sDisplayName;
327 ::std::vector< String >::const_iterator aLoop;
328 for ( aLoop = m_aFavourites.begin(); aLoop != m_aFavourites.end(); ++aLoop, ++nItemId )
330 if ( GetDialogParent()->isUrlAllowed( *aLoop ) )
332 Image aImage = SvFileInformationManager::GetImage(
333 INetURLObject(*aLoop), bIsHighContrast );
334 if ( LocalFileHelper::ConvertURLToSystemPath(*aLoop, sDisplayName) )
335 _pMenu->InsertItem( nItemId, sDisplayName, aImage );
336 else
337 _pMenu->InsertItem( nItemId, *aLoop, aImage );
342 //-----------------------------------------------------------------------------
343 void SvtTravelButton_Impl::Select()
345 sal_uInt16 nId = GetCurItemId();
346 if ( nId )
348 --nId;
349 DBG_ASSERT( nId < m_aFavourites.size(), "SvtTravelButton_Impl::Select: invalid index!" );
350 if ( nId < m_aFavourites.size() )
351 OpenURL( m_aFavourites[ nId ] );
355 //-----------------------------------------------------------------------------
356 void SvtTravelButton_Impl::Click()
358 OpenURL( GetDialogParent()->GetStandardDir() );
361 //*****************************************************************************
362 // SvtExpFileDlg_Impl
363 //*****************************************************************************
365 SvtExpFileDlg_Impl::SvtExpFileDlg_Impl( WinBits ) :
367 _pLbFilter ( NULL ),
368 _pCurFilter ( NULL ),
369 _pFilter ( new SvtFileDialogFilterList_Impl() ),
370 _pUserFilter ( NULL ),
371 _pFtFileName ( NULL ),
372 _pEdFileName ( NULL ),
373 _pFtFileVersion ( NULL ),
374 _pLbFileVersion ( NULL ),
375 _pFtTemplates ( NULL ),
376 _pLbTemplates ( NULL ),
377 _pFtImageTemplates ( NULL ),
378 _pLbImageTemplates ( NULL ),
379 _pFtFileType ( NULL ),
380 _pBtnFileOpen ( NULL ),
381 _pBtnCancel ( NULL ),
382 _pBtnHelp ( NULL ),
383 _pBtnUp ( NULL ),
384 _pBtnNewFolder ( NULL ),
385 _pBtnStandard ( NULL ),
386 _pCbPassword ( NULL ),
387 _pFtCurrentPath ( NULL ),
388 _pCbAutoExtension ( NULL ),
389 _pCbOptions ( NULL ),
390 _nState ( FILEDLG_STATE_REMOTE ),
391 _nStyle ( 0 ),
392 _bDoubleClick ( sal_False ),
393 m_bNeedDelayedFilterExecute ( sal_False ),
394 _pDefaultFilter ( NULL ),
395 _bMultiSelection ( sal_False ),
396 _nFixDeltaHeight ( 0 ),
397 _bFolderHasOpened ( sal_False )
401 //*****************************************************************************
403 SvtExpFileDlg_Impl::~SvtExpFileDlg_Impl()
405 delete _pFtCurrentPath;
406 delete _pCbPassword;
407 delete _pCbAutoExtension;
408 delete _pCbOptions;
409 delete _pBtnStandard;
410 delete _pBtnNewFolder;
411 delete _pBtnUp;
412 delete _pBtnHelp;
413 delete _pBtnCancel;
414 delete _pBtnFileOpen;
415 delete _pLbFilter;
416 delete _pFtFileType;
417 delete _pLbFileVersion;
418 delete _pFtFileVersion;
419 delete _pFtTemplates;
420 delete _pLbTemplates;
421 delete _pFtImageTemplates;
422 delete _pLbImageTemplates;
423 delete _pEdFileName;
424 delete _pFtFileName;
425 delete _pUserFilter;
426 delete _pFilter;
429 //*****************************************************************************
431 void SvtExpFileDlg_Impl::SetStandardDir( const String& _rDir )
433 _aStdDir = _rDir;
434 if ( 0 == _aStdDir.Len() )
435 _aStdDir.AssignAscii( "file:///" );
438 //*****************************************************************************
439 #if OSL_DEBUG_LEVEL > 0
440 //-----------------------------------------------------------------------------
441 namespace {
442 String lcl_DecoratedFilter( const String& _rOriginalFilter )
444 String aDecoratedFilter = '<';
445 aDecoratedFilter += _rOriginalFilter;
446 aDecoratedFilter += '>';
447 return aDecoratedFilter;
450 #endif
451 //-----------------------------------------------------------------------------
453 void SvtExpFileDlg_Impl::ClearFilterList( )
455 _pLbFilter->Clear();
458 //-----------------------------------------------------------------------------
459 void SvtExpFileDlg_Impl::SetCurFilter( SvtFileDialogFilter_Impl* pFilter, const String& rDisplayName )
461 DBG_ASSERT( pFilter, "SvtExpFileDlg_Impl::SetCurFilter: invalid filter!" );
462 DBG_ASSERT( ( rDisplayName == pFilter->GetName() )
463 || ( rDisplayName == lcl_DecoratedFilter( pFilter->GetName() ) ),
464 "SvtExpFileDlg_Impl::SetCurFilter: arguments are inconsistent!" );
466 _pCurFilter = pFilter;
467 m_sCurrentFilterDisplayName = rDisplayName;
470 //-----------------------------------------------------------------------------
471 void SvtExpFileDlg_Impl::InsertFilterListEntry( const SvtFileDialogFilter_Impl* _pFilterDesc )
473 String sName = _pFilterDesc->GetName();
474 if ( _pFilterDesc->isGroupSeparator() )
475 sName = String::CreateFromAscii( "------------------------------------------" );
476 else
477 sName = _pFilterDesc->GetName();
479 // insert an set user data
480 USHORT nPos = _pLbFilter->InsertEntry( sName );
481 _pLbFilter->SetEntryData( nPos, const_cast< void* >( static_cast< const void* >( _pFilterDesc ) ) );
484 //-----------------------------------------------------------------------------
486 void SvtExpFileDlg_Impl::InitFilterList( )
488 // clear the current list
489 ClearFilterList( );
491 // reinit it
492 USHORT nPos = _pFilter->Count();
494 // search for the first entry which is no group separator
495 while ( nPos-- && _pFilter->GetObject( nPos ) && _pFilter->GetObject( nPos )->isGroupSeparator() )
498 // add all following entries
499 while ( (sal_Int16)nPos >= 0 )
500 InsertFilterListEntry( _pFilter->GetObject( nPos-- ) );
503 //-----------------------------------------------------------------------------
505 void SvtExpFileDlg_Impl::CreateFilterListControl( Window* _pParent, const ResId& _rId )
507 DBG_ASSERT( !_pLbFilter, "SvtExpFileDlg_Impl::CreateFilterListControl: already created the control!" );
508 if ( !_pLbFilter )
510 _pLbFilter = new ListBox( _pParent, _rId );
511 _pLbFilter->SetDropDownLineCount( 10 );