1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_fpicker.hxx"
31 // includes *******************************************************************
33 #include "iodlgimp.hxx"
34 #include "svtools/headbar.hxx"
35 #include <tools/debug.hxx>
36 #include <tools/wldcrd.hxx>
37 #include <tools/urlobj.hxx>
38 #include <vcl/menu.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <vcl/lstbox.hxx>
41 #include <vcl/svapp.hxx>
42 // #97148# ---------------
43 #include "svl/ctypeitm.hxx"
44 #include "svl/eitem.hxx"
45 #include "unotools/viewoptions.hxx"
46 #include "svtools/fileview.hxx"
47 #include "svtools/inettbc.hxx"
50 #include "svtools/imagemgr.hxx"
51 #include <unotools/localfilehelper.hxx>
52 #include "unotools/useroptions.hxx"
53 #include "rtl/instance.hxx"
54 #include <svl/svl.hrc>
56 #define _SVSTDARR_STRINGSSORTDTOR
57 #define _SVSTDARR_STRINGSDTOR
58 #define _SVSTDARR_USHORTS
59 #include "svl/svstdarr.hxx"
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::lang
;
63 using namespace ::utl
;
65 // some stuff for easier changes for SvtViewOptions
66 static const sal_Char
* pViewOptDataName
= "dialog data";
67 #define VIEWOPT_DATANAME ::rtl::OUString::createFromAscii( pViewOptDataName )
69 static inline void SetViewOptUserItem( SvtViewOptions
& rOpt
, const String
& rData
)
71 rOpt
.SetUserItem( VIEWOPT_DATANAME
, makeAny( ::rtl::OUString( rData
) ) );
74 static inline String
GetViewOptUserItem( const SvtViewOptions
& rOpt
)
76 Any
aAny( rOpt
.GetUserItem( VIEWOPT_DATANAME
) );
77 ::rtl::OUString aUserData
;
80 return String( aUserData
);
84 // defines f"ur den Style der BrowseBox
86 #define STYLE_MULTI_SELECTION \
87 CNTVIEWSTYLE_NODE_BUTTONS | \
88 CNTVIEWSTYLE_NODE_BUTTONS_AT_ROOT | \
89 CNTVIEWSTYLE_SHOW_MESSAGES | \
90 CNTVIEWSTYLE_SHOW_FOLDERS | \
91 CNTVIEWSTYLE_NO_SMARTHIGHLIGHT | \
92 CNTVIEWSTYLE_HIDE_OPENMENU | \
93 CNTVIEWSTYLE_DEFAULT_APPEARANCE | \
94 CNTVIEWSTYLE_SORT_BY_FOLDER
96 #define STYLE_SINGLE_SELECTION \
97 STYLE_MULTI_SELECTION | CNTVIEWSTYLE_SINGLE_SELECTION
99 #define BOOL_NOT_INITIALIZE ((sal_Bool)2)
101 //*****************************************************************************
102 // ResMgrHolder / SvtSimpleResId
103 //*****************************************************************************
108 ResMgr
* operator ()()
110 return ResMgr::CreateResMgr (CREATEVERSIONRESMGR_NAME(svs
));
112 static ResMgr
* getOrCreate()
115 ResMgr
, ResMgrHolder
,
116 osl::MutexGuard
, osl::GetGlobalMutex
>::create (
117 ResMgrHolder(), osl::GetGlobalMutex());
121 struct SvtSimpleResId
: public ResId
123 SvtSimpleResId (sal_uInt16 nId
) : ResId (nId
, *ResMgrHolder::getOrCreate()) {}
127 //*****************************************************************************
128 // SvtFileDialogFilter_Impl
129 //*****************************************************************************
131 DBG_NAME( SvtFileDialogFilter_Impl
)
132 SvtFileDialogFilter_Impl::SvtFileDialogFilter_Impl( const String
& rName
, const String
& rType
)
136 DBG_CTOR( SvtFileDialogFilter_Impl
, NULL
);
138 m_aType
.ToLowerAscii();
141 //*****************************************************************************
143 SvtFileDialogFilter_Impl::~SvtFileDialogFilter_Impl()
145 DBG_DTOR( SvtFileDialogFilter_Impl
, NULL
);
148 //*****************************************************************************
149 // SvtFileDialogFilterList_Impl
150 //*****************************************************************************
152 SV_IMPL_PTRARR( SvtFileDialogFilterList_Impl
, SvtFileDialogFilter_Impl
* );
154 //=============================================================================
155 //= SvtFileDialogURLSelector
156 //=============================================================================
158 //-----------------------------------------------------------------------------
159 SvtFileDialogURLSelector::SvtFileDialogURLSelector( SvtFileDialog
* _pParent
, const ResId
& _rResId
, sal_uInt16 _nButtonId
)
160 :MenuButton ( _pParent
, _rResId
)
161 ,m_pParent ( _pParent
)
162 ,m_pMenu ( new PopupMenu
)
164 SetStyle( GetStyle() | WB_NOPOINTERFOCUS
| WB_RECTSTYLE
| WB_SMALLSTYLE
);
165 SetModeImage( m_pParent
->GetButtonImage( _nButtonId
) );
166 SetMenuMode( MENUBUTTON_MENUMODE_TIMED
);
167 SetDropDown( PUSHBUTTON_DROPDOWN_TOOLBOX
);
170 //-----------------------------------------------------------------------------
171 SvtFileDialogURLSelector::~SvtFileDialogURLSelector()
176 //-----------------------------------------------------------------------------
177 void SvtFileDialogURLSelector::OpenURL( const String
& rURL
)
179 INetURLObject
aObj( rURL
);
180 DBG_ASSERT( aObj
.GetProtocol() != INET_PROT_NOT_VALID
, "SvtFileDialogURLSelector::OpenURL: Invalid URL!" );
181 m_pParent
->OpenURL_Impl( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
184 //-----------------------------------------------------------------------------
185 void SvtFileDialogURLSelector::Activate()
189 FillURLMenu( m_pMenu
);
191 SetPopupMenu( m_pMenu
);
194 //=============================================================================
196 //=============================================================================
198 //-----------------------------------------------------------------------------
199 SvtUpButton_Impl::SvtUpButton_Impl( SvtFileDialog
* pParent
, const ResId
& rResId
)
200 :SvtFileDialogURLSelector( pParent
, rResId
, IMG_FILEDLG_BTN_UP
)
205 //-----------------------------------------------------------------------------
206 SvtUpButton_Impl::~SvtUpButton_Impl()
211 //-----------------------------------------------------------------------------
212 void SvtUpButton_Impl::FillURLMenu( PopupMenu
* _pMenu
)
214 SvtFileView
* pBox
= GetDialogParent()->GetView();
216 sal_uInt16 nItemId
= 1;
219 _pURLs
= new SvStringsDtor
;
221 // "Ubergeordnete Ebenen bestimmen.
222 INetURLObject
aObject( pBox
->GetViewURL() );
223 sal_Int32 nCount
= aObject
.getSegmentCount();
225 ::svtools::VolumeInfo
aVolInfo( sal_True
/* volume */, sal_False
/* remote */,
226 sal_False
/* removable */, sal_False
/* floppy */,
227 sal_False
/* compact disk */ );
228 sal_Bool bIsHighContrast
= pBox
->GetSettings().GetStyleSettings().GetHighContrastMode();
229 Image
aVolumeImage( SvFileInformationManager::GetFolderImage( aVolInfo
, bIsHighContrast
) );
231 while ( nCount
>= 1 )
233 aObject
.removeSegment();
234 String
* pParentURL
= new String( aObject
.GetMainURL( INetURLObject::NO_DECODE
) );
236 if ( GetDialogParent()->isUrlAllowed( *pParentURL
) )
239 // 97148# --------------------------------
240 if ( !GetDialogParent()->ContentGetTitle( *pParentURL
, aTitle
) || aTitle
.Len() == 0 )
241 aTitle
= aObject
.getName();
243 Image aImage
= ( nCount
> 1 ) // if nCount == 1 means workplace, which detects the wrong image
244 ? SvFileInformationManager::GetImage( aObject
, bIsHighContrast
)
247 _pMenu
->InsertItem( nItemId
++, aTitle
, aImage
);
248 _pURLs
->Insert( pParentURL
, _pURLs
->Count() );
252 // adjust the title of the top level entry (the workspace)
253 _pMenu
->SetItemText( --nItemId
, SvtSimpleResId( STR_SVT_MIMETYPE_CNT_FSYSBOX
) );
261 //-----------------------------------------------------------------------------
262 void SvtUpButton_Impl::Select()
264 sal_uInt16 nId
= GetCurItemId();
269 DBG_ASSERT( nId
<= _pURLs
->Count(), "SvtUpButton_Impl:falscher Index" );
271 String aURL
= *(_pURLs
->GetObject( nId
));
272 GetDialogParent()->OpenURL_Impl( aURL
);
276 //-----------------------------------------------------------------------------
277 void SvtUpButton_Impl::Click()
279 GetDialogParent()->PrevLevel_Impl();
282 //=============================================================================
283 //= SvtTravelButton_Impl
284 //=============================================================================
286 //-----------------------------------------------------------------------------
287 SvtTravelButton_Impl::SvtTravelButton_Impl( SvtFileDialog
* pParent
, const ResId
& rResId
)
288 :SvtFileDialogURLSelector ( pParent
, rResId
, IMG_FILEDLG_BTN_STD
)
290 SetDropDown( 0 ); // by default, don't drop down, as we don't have favourites
293 //-----------------------------------------------------------------------------
294 void SvtTravelButton_Impl::SetFavouriteLocations( const ::std::vector
< String
>& _rLocations
)
296 m_aFavourites
= _rLocations
;
297 // enable the drop down if and only if we have favourites
298 SetDropDown( m_aFavourites
.empty() ? 0 : PUSHBUTTON_DROPDOWN_TOOLBOX
);
301 //-----------------------------------------------------------------------------
302 SvtTravelButton_Impl::~SvtTravelButton_Impl()
306 //-----------------------------------------------------------------------------
307 void SvtTravelButton_Impl::FillURLMenu( PopupMenu
* _pMenu
)
309 if ( m_aFavourites
.empty() )
310 // though we claimed that we do not want to have a drop down button
311 // in this case, VCL nevertheless behaves as if we had one .... :(
316 sal_Bool bIsHighContrast
= GetDialogParent()->GetView()->GetSettings().GetStyleSettings().GetHighContrastMode();
318 sal_uInt16 nItemId
= 1;
321 ::std::vector
< String
>::const_iterator aLoop
;
322 for ( aLoop
= m_aFavourites
.begin(); aLoop
!= m_aFavourites
.end(); ++aLoop
, ++nItemId
)
324 if ( GetDialogParent()->isUrlAllowed( *aLoop
) )
326 Image aImage
= SvFileInformationManager::GetImage(
327 INetURLObject(*aLoop
), bIsHighContrast
);
328 if ( LocalFileHelper::ConvertURLToSystemPath(*aLoop
, sDisplayName
) )
329 _pMenu
->InsertItem( nItemId
, sDisplayName
, aImage
);
331 _pMenu
->InsertItem( nItemId
, *aLoop
, aImage
);
336 //-----------------------------------------------------------------------------
337 void SvtTravelButton_Impl::Select()
339 sal_uInt16 nId
= GetCurItemId();
343 DBG_ASSERT( nId
< m_aFavourites
.size(), "SvtTravelButton_Impl::Select: invalid index!" );
344 if ( nId
< m_aFavourites
.size() )
345 OpenURL( m_aFavourites
[ nId
] );
349 //-----------------------------------------------------------------------------
350 void SvtTravelButton_Impl::Click()
352 OpenURL( GetDialogParent()->GetStandardDir() );
355 //*****************************************************************************
356 // SvtExpFileDlg_Impl
357 //*****************************************************************************
359 SvtExpFileDlg_Impl::SvtExpFileDlg_Impl( WinBits
) :
362 _pCurFilter ( NULL
),
363 _pFilter ( new SvtFileDialogFilterList_Impl() ),
364 _pUserFilter ( NULL
),
365 _pFtFileName ( NULL
),
366 _pEdFileName ( NULL
),
367 _pFtFileVersion ( NULL
),
368 _pLbFileVersion ( NULL
),
369 _pFtTemplates ( NULL
),
370 _pLbTemplates ( NULL
),
371 _pFtImageTemplates ( NULL
),
372 _pLbImageTemplates ( NULL
),
373 _pFtFileType ( NULL
),
374 _pBtnFileOpen ( NULL
),
375 _pBtnCancel ( NULL
),
378 _pBtnNewFolder ( NULL
),
379 _pBtnStandard ( NULL
),
380 _pCbPassword ( NULL
),
381 _pFtCurrentPath ( NULL
),
382 _pCbAutoExtension ( NULL
),
383 _pCbOptions ( NULL
),
384 _nState ( FILEDLG_STATE_REMOTE
),
386 _bDoubleClick ( sal_False
),
387 m_bNeedDelayedFilterExecute ( sal_False
),
388 _pDefaultFilter ( NULL
),
389 _bMultiSelection ( sal_False
),
390 _nFixDeltaHeight ( 0 ),
391 _bFolderHasOpened ( sal_False
)
395 //*****************************************************************************
397 SvtExpFileDlg_Impl::~SvtExpFileDlg_Impl()
399 delete _pFtCurrentPath
;
401 delete _pCbAutoExtension
;
403 delete _pBtnStandard
;
404 delete _pBtnNewFolder
;
408 delete _pBtnFileOpen
;
411 delete _pLbFileVersion
;
412 delete _pFtFileVersion
;
413 delete _pFtTemplates
;
414 delete _pLbTemplates
;
415 delete _pFtImageTemplates
;
416 delete _pLbImageTemplates
;
423 //*****************************************************************************
425 void SvtExpFileDlg_Impl::SetStandardDir( const String
& _rDir
)
428 if ( 0 == _aStdDir
.Len() )
429 _aStdDir
.AssignAscii( "file:///" );
432 //*****************************************************************************
433 #if OSL_DEBUG_LEVEL > 0
434 //-----------------------------------------------------------------------------
436 String
lcl_DecoratedFilter( const String
& _rOriginalFilter
)
438 String aDecoratedFilter
= '<';
439 aDecoratedFilter
+= _rOriginalFilter
;
440 aDecoratedFilter
+= '>';
441 return aDecoratedFilter
;
445 //-----------------------------------------------------------------------------
447 void SvtExpFileDlg_Impl::ClearFilterList( )
452 //-----------------------------------------------------------------------------
453 void SvtExpFileDlg_Impl::SetCurFilter( SvtFileDialogFilter_Impl
* pFilter
, const String
& rDisplayName
)
455 DBG_ASSERT( pFilter
, "SvtExpFileDlg_Impl::SetCurFilter: invalid filter!" );
456 DBG_ASSERT( ( rDisplayName
== pFilter
->GetName() )
457 || ( rDisplayName
== lcl_DecoratedFilter( pFilter
->GetName() ) ),
458 "SvtExpFileDlg_Impl::SetCurFilter: arguments are inconsistent!" );
460 _pCurFilter
= pFilter
;
461 m_sCurrentFilterDisplayName
= rDisplayName
;
464 //-----------------------------------------------------------------------------
465 void SvtExpFileDlg_Impl::InsertFilterListEntry( const SvtFileDialogFilter_Impl
* _pFilterDesc
)
467 String sName
= _pFilterDesc
->GetName();
468 if ( _pFilterDesc
->isGroupSeparator() )
469 sName
= String::CreateFromAscii( "------------------------------------------" );
471 sName
= _pFilterDesc
->GetName();
473 // insert an set user data
474 sal_uInt16 nPos
= _pLbFilter
->InsertEntry( sName
);
475 _pLbFilter
->SetEntryData( nPos
, const_cast< void* >( static_cast< const void* >( _pFilterDesc
) ) );
478 //-----------------------------------------------------------------------------
480 void SvtExpFileDlg_Impl::InitFilterList( )
482 // clear the current list
486 sal_uInt16 nPos
= _pFilter
->Count();
488 // search for the first entry which is no group separator
489 while ( nPos
-- && _pFilter
->GetObject( nPos
) && _pFilter
->GetObject( nPos
)->isGroupSeparator() )
492 // add all following entries
493 while ( (sal_Int16
)nPos
>= 0 )
494 InsertFilterListEntry( _pFilter
->GetObject( nPos
-- ) );
497 //-----------------------------------------------------------------------------
499 void SvtExpFileDlg_Impl::CreateFilterListControl( Window
* _pParent
, const ResId
& _rId
)
501 DBG_ASSERT( !_pLbFilter
, "SvtExpFileDlg_Impl::CreateFilterListControl: already created the control!" );
504 _pLbFilter
= new ListBox( _pParent
, _rId
);
505 _pLbFilter
->SetDropDownLineCount( 10 );