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 <svx/svxdlg.hxx>
21 #include <tools/shl.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <sfx2/filedlghelper.hxx>
24 #include <sfx2/app.hxx>
25 #include <svl/aeitem.hxx>
26 #include <svtools/svtabbx.hxx>
27 #include "svtools/treelistentry.hxx"
28 #include <tools/urlobj.hxx>
29 #include <vcl/svapp.hxx>
30 #include <unotools/defaultoptions.hxx>
31 #include <unotools/localfilehelper.hxx>
32 #include <unotools/pathoptions.hxx>
33 #include <unotools/moduleoptions.hxx>
34 #include <unotools/viewoptions.hxx>
36 #define _SVX_OPTPATH_CXX
38 #include "optpath.hxx"
39 #include <dialmgr.hxx>
40 #include "optpath.hrc"
43 #include <comphelper/configuration.hxx>
44 #include <comphelper/processfactory.hxx>
45 #include <comphelper/string.hxx>
46 #include <com/sun/star/uno/Exception.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/beans/PropertyAttribute.hpp>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
51 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
52 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
53 #include <officecfg/Office/Common.hxx>
54 #include "optHeaderTabListbox.hxx"
55 #include <readonlyimage.hxx>
56 #include <vcl/help.hxx>
58 using namespace ::com::sun::star::beans
;
59 using namespace ::com::sun::star::lang
;
60 using namespace ::com::sun::star::ui::dialogs
;
61 using namespace ::com::sun::star::uno
;
64 // define ----------------------------------------------------------------
67 #define TAB_WIDTH_MIN 10
68 #define TAB_WIDTH2 1000
72 #define POSTFIX_INTERNAL rtl::OUString("_internal")
73 #define POSTFIX_USER rtl::OUString("_user")
74 #define POSTFIX_WRITABLE rtl::OUString("_writable")
75 #define VAR_ONE rtl::OUString("%1")
76 #define IODLG_CONFIGNAME rtl::OUString("FilePicker_Save")
78 // struct OptPath_Impl ---------------------------------------------------
82 SvtDefaultOptions m_aDefOpt
;
84 String m_sMultiPathDlg
;
85 Reference
< XPropertySet
> m_xPathSettings
;
87 OptPath_Impl(const ResId
& rLockRes
)
88 : m_aLockImage(rLockRes
)
93 // struct PathUserData_Impl ----------------------------------------------
95 struct PathUserData_Impl
100 String sWritablePath
;
102 PathUserData_Impl( sal_uInt16 nId
) :
103 nRealId( nId
), eState( SFX_ITEM_UNKNOWN
) {}
106 struct Handle2CfgNameMapping_Impl
108 sal_uInt16 m_nHandle
;
109 const char* m_pCfgName
;
112 static Handle2CfgNameMapping_Impl
const Hdl2CfgMap_Impl
[] =
114 { SvtPathOptions::PATH_AUTOCORRECT
, "AutoCorrect" },
115 { SvtPathOptions::PATH_AUTOTEXT
, "AutoText" },
116 { SvtPathOptions::PATH_BACKUP
, "Backup" },
117 { SvtPathOptions::PATH_GALLERY
, "Gallery" },
118 { SvtPathOptions::PATH_GRAPHIC
, "Graphic" },
119 { SvtPathOptions::PATH_TEMP
, "Temp" },
120 { SvtPathOptions::PATH_TEMPLATE
, "Template" },
121 { SvtPathOptions::PATH_WORK
, "Work" },
122 #if OSL_DEBUG_LEVEL > 1
123 { SvtPathOptions::PATH_LINGUISTIC
, "Linguistic" },
124 { SvtPathOptions::PATH_DICTIONARY
, "Dictionary" },
129 static String
getCfgName_Impl( sal_uInt16 _nHandle
)
132 sal_uInt16 nIndex
= 0;
133 while ( Hdl2CfgMap_Impl
[ nIndex
].m_nHandle
!= USHRT_MAX
)
135 if ( Hdl2CfgMap_Impl
[ nIndex
].m_nHandle
== _nHandle
)
138 sCfgName
= rtl::OUString::createFromAscii( Hdl2CfgMap_Impl
[ nIndex
].m_pCfgName
);
147 #define MULTIPATH_DELIMITER ';'
149 String
Convert_Impl( const String
& rValue
)
151 char cDelim
= MULTIPATH_DELIMITER
;
152 sal_uInt16 nCount
= comphelper::string::getTokenCount(rValue
, cDelim
);
154 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
156 String aValue
= rValue
.GetToken( i
, cDelim
);
157 INetURLObject
aObj( aValue
);
158 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
159 aReturn
+= String(aObj
.PathToFileName());
160 else if ( ::utl::LocalFileHelper::IsFileContent( aValue
) )
161 aReturn
+= String(aObj
.GetURLPath( INetURLObject::DECODE_WITH_CHARSET
));
163 aReturn
+= MULTIPATH_DELIMITER
;
169 // class SvxControlFocusHelper ---------------------------------------------
171 long SvxControlFocusHelper::Notify( NotifyEvent
& rNEvt
)
173 long nRet
= Control::Notify( rNEvt
);
175 if ( m_pFocusCtrl
&& rNEvt
.GetWindow() != m_pFocusCtrl
&& rNEvt
.GetType() == EVENT_GETFOCUS
)
176 m_pFocusCtrl
->GrabFocus();
180 // functions -------------------------------------------------------------
182 sal_Bool
IsMultiPath_Impl( const sal_uInt16 nIndex
)
184 #if OSL_DEBUG_LEVEL > 1
185 return ( SvtPathOptions::PATH_AUTOCORRECT
== nIndex
||
186 SvtPathOptions::PATH_AUTOTEXT
== nIndex
||
187 SvtPathOptions::PATH_BASIC
== nIndex
||
188 SvtPathOptions::PATH_GALLERY
== nIndex
||
189 SvtPathOptions::PATH_TEMPLATE
== nIndex
);
191 return ( SvtPathOptions::PATH_AUTOCORRECT
== nIndex
||
192 SvtPathOptions::PATH_AUTOTEXT
== nIndex
||
193 SvtPathOptions::PATH_BASIC
== nIndex
||
194 SvtPathOptions::PATH_GALLERY
== nIndex
||
195 SvtPathOptions::PATH_TEMPLATE
== nIndex
||
196 SvtPathOptions::PATH_LINGUISTIC
== nIndex
||
197 SvtPathOptions::PATH_DICTIONARY
== nIndex
);
201 // class SvxPathTabPage --------------------------------------------------
203 SvxPathTabPage::SvxPathTabPage( Window
* pParent
, const SfxItemSet
& rSet
) :
205 SfxTabPage( pParent
, CUI_RES( RID_SFXPAGE_PATH
), rSet
),
207 aStdBox ( this, CUI_RES( GB_STD
) ),
208 aTypeText ( this, CUI_RES( FT_TYPE
) ),
209 aPathText ( this, CUI_RES( FT_PATH
) ),
210 aPathCtrl ( this, CUI_RES( LB_PATH
) ),
211 aStandardBtn ( this, CUI_RES( BTN_STANDARD
) ),
212 aPathBtn ( this, CUI_RES( BTN_PATH
) ),
215 pImpl ( new OptPath_Impl( CUI_RES(IMG_LOCK
) ) ),
216 xDialogListener ( new ::svt::DialogClosedListener() )
219 pImpl
->m_sMultiPathDlg
= String( CUI_RES( STR_MULTIPATHDLG
) );
220 aStandardBtn
.SetClickHdl( LINK( this, SvxPathTabPage
, StandardHdl_Impl
) );
221 Link aLink
= LINK( this, SvxPathTabPage
, PathHdl_Impl
);
222 aPathBtn
.SetClickHdl( aLink
);
223 Size aBoxSize
= aPathCtrl
.GetOutputSizePixel();
224 pHeaderBar
= new HeaderBar( &aPathCtrl
, WB_BUTTONSTYLE
| WB_BOTTOMBORDER
);
225 pHeaderBar
->SetPosSizePixel( Point( 0, 0 ), Size( aBoxSize
.Width(), 16 ) );
226 pHeaderBar
->SetSelectHdl( LINK( this, SvxPathTabPage
, HeaderSelect_Impl
) );
227 pHeaderBar
->SetEndDragHdl( LINK( this, SvxPathTabPage
, HeaderEndDrag_Impl
) );
229 aSz
.Width() = TAB_WIDTH1
;
230 pHeaderBar
->InsertItem( ITEMID_TYPE
, aTypeText
.GetText(),
231 LogicToPixel( aSz
, MapMode( MAP_APPFONT
) ).Width(),
232 HIB_LEFT
| HIB_VCENTER
| HIB_CLICKABLE
| HIB_UPARROW
);
233 aSz
.Width() = TAB_WIDTH2
;
234 pHeaderBar
->InsertItem( ITEMID_PATH
, aPathText
.GetText(),
235 LogicToPixel( aSz
, MapMode( MAP_APPFONT
) ).Width(),
236 HIB_LEFT
| HIB_VCENTER
);
238 static long nTabs
[] = {3, 0, TAB_WIDTH1
, TAB_WIDTH1
+ TAB_WIDTH2
};
239 Size aHeadSize
= pHeaderBar
->GetSizePixel();
241 WinBits nBits
= WB_SORT
| WB_HSCROLL
| WB_CLIPCHILDREN
| WB_TABSTOP
;
242 pPathBox
= new svx::OptHeaderTabListBox( &aPathCtrl
, nBits
);
243 aPathCtrl
.SetFocusControl( pPathBox
);
244 pPathBox
->SetDoubleClickHdl( aLink
);
245 pPathBox
->SetSelectHdl( LINK( this, SvxPathTabPage
, PathSelect_Impl
) );
246 pPathBox
->SetSelectionMode( MULTIPLE_SELECTION
);
247 pPathBox
->SetPosSizePixel( Point( 0, aHeadSize
.Height() ),
248 Size( aBoxSize
.Width(), aBoxSize
.Height() - aHeadSize
.Height() ) );
249 pPathBox
->SetTabs( &nTabs
[0], MAP_APPFONT
);
250 pPathBox
->InitHeaderBar( pHeaderBar
);
251 pPathBox
->SetHighlightRange();
252 pPathBox
->SetHelpId( HID_OPTPATH_CTL_PATH
);
253 pHeaderBar
->SetHelpId( HID_OPTPATH_HEADERBAR
);
259 xDialogListener
->SetDialogClosedLink( LINK( this, SvxPathTabPage
, DialogClosedHdl
) );
262 // -----------------------------------------------------------------------
264 SvxPathTabPage::~SvxPathTabPage()
266 // #110603# do not grab focus to a destroyed window !!!
267 aPathCtrl
.SetFocusControl( NULL
);
270 for ( sal_uInt16 i
= 0; i
< pPathBox
->GetEntryCount(); ++i
)
271 delete (PathUserData_Impl
*)pPathBox
->GetEntry(i
)->GetUserData();
277 // -----------------------------------------------------------------------
279 SfxTabPage
* SvxPathTabPage::Create( Window
* pParent
,
280 const SfxItemSet
& rAttrSet
)
282 return ( new SvxPathTabPage( pParent
, rAttrSet
) );
285 // -----------------------------------------------------------------------
287 sal_Bool
SvxPathTabPage::FillItemSet( SfxItemSet
& )
289 SvtPathOptions aPathOpt
;
290 for ( sal_uInt16 i
= 0; i
< pPathBox
->GetEntryCount(); ++i
)
292 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pPathBox
->GetEntry(i
)->GetUserData();
293 sal_uInt16 nRealId
= pPathImpl
->nRealId
;
294 if ( pPathImpl
->eState
== SFX_ITEM_SET
)
295 SetPathList( nRealId
, pPathImpl
->sUserPath
, pPathImpl
->sWritablePath
);
300 // -----------------------------------------------------------------------
302 void SvxPathTabPage::Reset( const SfxItemSet
& )
305 SvtPathOptions aPathOpt
; //! deprecated
307 for( sal_uInt16 i
= 0; i
<= (sal_uInt16
)SvtPathOptions::PATH_WORK
; ++i
)
309 // only writer uses autotext
310 if ( i
== SvtPathOptions::PATH_AUTOTEXT
311 && !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SWRITER
) )
316 case SvtPathOptions::PATH_AUTOCORRECT
:
317 case SvtPathOptions::PATH_AUTOTEXT
:
318 case SvtPathOptions::PATH_BACKUP
:
319 case SvtPathOptions::PATH_GALLERY
:
320 case SvtPathOptions::PATH_GRAPHIC
:
321 case SvtPathOptions::PATH_TEMP
:
322 case SvtPathOptions::PATH_TEMPLATE
:
323 #if OSL_DEBUG_LEVEL > 1
324 case SvtPathOptions::PATH_LINGUISTIC
:
325 case SvtPathOptions::PATH_DICTIONARY
:
327 case SvtPathOptions::PATH_WORK
:
329 String
aStr( CUI_RES( RID_SVXSTR_PATH_NAME_START
+ i
) );
330 String sInternal
, sUser
, sWritable
;
331 sal_Bool bReadOnly
= sal_False
;
332 GetPathList( i
, sInternal
, sUser
, sWritable
, bReadOnly
);
333 String sTmpPath
= sUser
;
334 if ( sTmpPath
.Len() > 0 && sWritable
.Len() > 0 )
335 sTmpPath
+= MULTIPATH_DELIMITER
;
336 sTmpPath
+= sWritable
;
337 String
aValue( sTmpPath
);
339 aStr
+= Convert_Impl( aValue
);
340 SvTreeListEntry
* pEntry
= pPathBox
->InsertEntry( aStr
);
343 pPathBox
->SetCollapsedEntryBmp( pEntry
, pImpl
->m_aLockImage
);
345 PathUserData_Impl
* pPathImpl
= new PathUserData_Impl(i
);
346 pPathImpl
->sUserPath
= sUser
;
347 pPathImpl
->sWritablePath
= sWritable
;
348 pEntry
->SetUserData( pPathImpl
);
353 String aUserData
= GetUserData();
354 if ( aUserData
.Len() )
356 // restore column width
357 pHeaderBar
->SetItemSize( ITEMID_TYPE
, aUserData
.GetToken(0).ToInt32() );
358 HeaderEndDrag_Impl( NULL
);
359 // restore sort direction
360 sal_Bool bUp
= (sal_Bool
)(sal_uInt16
)aUserData
.GetToken(1).ToInt32();
361 HeaderBarItemBits nBits
= pHeaderBar
->GetItemBits(ITEMID_TYPE
);
365 nBits
&= ~HIB_UPARROW
;
366 nBits
|= HIB_DOWNARROW
;
370 nBits
&= ~HIB_DOWNARROW
;
371 nBits
|= HIB_UPARROW
;
373 pHeaderBar
->SetItemBits( ITEMID_TYPE
, nBits
);
374 HeaderSelect_Impl( NULL
);
376 PathSelect_Impl( NULL
);
379 // -----------------------------------------------------------------------
381 void SvxPathTabPage::FillUserData()
383 String aUserData
= String::CreateFromInt32( pHeaderBar
->GetItemSize( ITEMID_TYPE
) );
385 HeaderBarItemBits nBits
= pHeaderBar
->GetItemBits( ITEMID_TYPE
);
386 sal_Bool bUp
= ( ( nBits
& HIB_UPARROW
) == HIB_UPARROW
);
387 aUserData
+= bUp
? '1' : '0';
388 SetUserData( aUserData
);
391 // -----------------------------------------------------------------------
393 IMPL_LINK_NOARG(SvxPathTabPage
, PathSelect_Impl
)
395 sal_uInt16 nSelCount
= 0;
396 SvTreeListEntry
* pEntry
= pPathBox
->FirstSelected();
398 //the entry image indicates whether the path is write protected
401 aEntryImage
= pPathBox
->GetCollapsedEntryBmp( pEntry
);
402 sal_Bool bEnable
= !aEntryImage
;
403 while ( pEntry
&& ( nSelCount
< 2 ) )
406 pEntry
= pPathBox
->NextSelected( pEntry
);
409 aPathBtn
.Enable( 1 == nSelCount
&& bEnable
);
410 aStandardBtn
.Enable( nSelCount
> 0 && bEnable
);
414 // -----------------------------------------------------------------------
416 IMPL_LINK_NOARG(SvxPathTabPage
, StandardHdl_Impl
)
418 SvTreeListEntry
* pEntry
= pPathBox
->FirstSelected();
421 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
422 String aOldPath
= pImpl
->m_aDefOpt
.GetDefaultPath( pPathImpl
->nRealId
);
424 if ( aOldPath
.Len() )
426 String sInternal
, sUser
, sWritable
, sTemp
;
427 sal_Bool bReadOnly
= sal_False
;
428 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
431 sal_uInt16 nOldCount
= comphelper::string::getTokenCount(aOldPath
, MULTIPATH_DELIMITER
);
432 sal_uInt16 nIntCount
= comphelper::string::getTokenCount(sInternal
, MULTIPATH_DELIMITER
);
433 for ( i
= 0; i
< nOldCount
; ++i
)
436 String sOnePath
= aOldPath
.GetToken( i
, MULTIPATH_DELIMITER
);
437 for ( sal_uInt16 j
= 0; !bFound
&& j
< nIntCount
; ++j
)
439 if ( sInternal
.GetToken( i
, MULTIPATH_DELIMITER
) == sOnePath
)
444 if ( sTemp
.Len() > 0 )
445 sTemp
+= MULTIPATH_DELIMITER
;
450 String sUserPath
, sWritablePath
;
451 nOldCount
= comphelper::string::getTokenCount(sTemp
, MULTIPATH_DELIMITER
);
452 for ( i
= 0; nOldCount
> 0 && i
< nOldCount
- 1; ++i
)
454 if ( sUserPath
.Len() > 0 )
455 sUserPath
+= MULTIPATH_DELIMITER
;
456 sUserPath
+= sTemp
.GetToken( i
, MULTIPATH_DELIMITER
);
458 sWritablePath
= sTemp
.GetToken( nOldCount
- 1, MULTIPATH_DELIMITER
);
460 pPathBox
->SetEntryText( Convert_Impl( sTemp
), pEntry
, 1 );
461 pPathImpl
->eState
= SFX_ITEM_SET
;
462 pPathImpl
->sUserPath
= sUserPath
;
463 pPathImpl
->sWritablePath
= sWritablePath
;
465 pEntry
= pPathBox
->NextSelected( pEntry
);
470 // -----------------------------------------------------------------------
472 void SvxPathTabPage::ChangeCurrentEntry( const String
& _rFolder
)
474 SvTreeListEntry
* pEntry
= pPathBox
->GetCurEntry();
477 SAL_WARN( "cui.options", "SvxPathTabPage::ChangeCurrentEntry(): no entry" );
481 String sInternal
, sUser
, sWritable
;
482 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
483 sal_Bool bReadOnly
= sal_False
;
484 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
485 sUser
= pPathImpl
->sUserPath
;
486 sWritable
= pPathImpl
->sWritablePath
;
487 sal_uInt16 nPos
= pPathImpl
->nRealId
;
489 // old path is an URL?
490 INetURLObject
aObj( sWritable
);
491 bool bURL
= ( aObj
.GetProtocol() != INET_PROT_NOT_VALID
);
492 rtl::OUString
aPathStr( _rFolder
);
493 INetURLObject
aNewObj( aPathStr
);
494 aNewObj
.removeFinalSlash();
496 // then the new path also an URL else system path
497 String sNewPathStr
= bURL
? aPathStr
: aNewObj
.getFSysPath( INetURLObject::FSYS_DETECT
);
501 // Unix is case sensitive
502 ( sNewPathStr
!= sWritable
);
504 ( sNewPathStr
.CompareIgnoreCaseToAscii( sWritable
) != COMPARE_EQUAL
);
509 pPathBox
->SetEntryText( Convert_Impl( sNewPathStr
), pEntry
, 1 );
510 nPos
= (sal_uInt16
)pPathBox
->GetModel()->GetAbsPos( pEntry
);
511 pPathImpl
= (PathUserData_Impl
*)pPathBox
->GetEntry(nPos
)->GetUserData();
512 pPathImpl
->eState
= SFX_ITEM_SET
;
513 pPathImpl
->sWritablePath
= sNewPathStr
;
514 if ( SvtPathOptions::PATH_WORK
== pPathImpl
->nRealId
)
516 // Remove view options entry so the new work path
517 // will be used for the next open dialog.
518 SvtViewOptions
aDlgOpt( E_DIALOG
, IODLG_CONFIGNAME
);
520 // Reset also last used dir in the sfx application instance
521 SfxApplication
*pSfxApp
= SFX_APP();
522 pSfxApp
->ResetLastDir();
524 // Set configuration flag to notify file picker that it's necessary
525 // to take over the path provided.
526 boost::shared_ptr
< comphelper::ConfigurationChanges
> batch(
527 comphelper::ConfigurationChanges::create());
528 officecfg::Office::Common::Path::Info::WorkPathChanged::set(
535 // -----------------------------------------------------------------------
537 IMPL_LINK_NOARG(SvxPathTabPage
, PathHdl_Impl
)
539 SvTreeListEntry
* pEntry
= pPathBox
->GetCurEntry();
540 sal_uInt16 nPos
= ( pEntry
!= NULL
) ? ( (PathUserData_Impl
*)pEntry
->GetUserData() )->nRealId
: 0;
541 String sInternal
, sUser
, sWritable
;
544 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
545 sal_Bool bReadOnly
= sal_False
;
546 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
547 sUser
= pPathImpl
->sUserPath
;
548 sWritable
= pPathImpl
->sWritablePath
;
551 if(pEntry
&& !(!((OptHeaderTabListBox
*)pPathBox
)->GetCollapsedEntryBmp(pEntry
)))
554 if ( IsMultiPath_Impl( nPos
) )
556 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
559 AbstractSvxMultiPathDialog
* pMultiDlg
=
560 pFact
->CreateSvxMultiPathDialog( this );
561 DBG_ASSERT( pMultiDlg
, "Dialogdiet fail!" );
562 pMultiDlg
->EnableRadioButtonMode();
564 String
sPath( sUser
);
565 if ( sPath
.Len() > 0 )
566 sPath
+= MULTIPATH_DELIMITER
;
568 pMultiDlg
->SetPath( sPath
);
570 String sPathName
= pPathBox
->GetEntryText( pEntry
, 0 );
571 String
sNewTitle( pImpl
->m_sMultiPathDlg
);
572 sNewTitle
.SearchAndReplace( VAR_ONE
, sPathName
);
573 pMultiDlg
->SetTitle( sNewTitle
);
575 if ( pMultiDlg
->Execute() == RET_OK
&& pEntry
)
580 String sNewPath
= pMultiDlg
->GetPath();
581 char cDelim
= MULTIPATH_DELIMITER
;
582 sal_uInt16 nCount
= comphelper::string::getTokenCount(sNewPath
, cDelim
);
586 for ( ; i
< nCount
- 1; ++i
)
588 if ( sUser
.Len() > 0 )
590 sUser
+= sNewPath
.GetToken( i
, cDelim
);
592 if ( sFullPath
.Len() > 0 )
595 sWritable
+= sNewPath
.GetToken( i
, cDelim
);
596 if ( sFullPath
.Len() > 0 )
598 sFullPath
+= sWritable
;
601 pPathBox
->SetEntryText( Convert_Impl( sFullPath
), pEntry
, 1 );
602 // save modified flag
603 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
604 pPathImpl
->eState
= SFX_ITEM_SET
;
605 pPathImpl
->sUserPath
= sUser
;
606 pPathImpl
->sWritablePath
= sWritable
;
615 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
616 xFolderPicker
= FolderPicker::create(xContext
);;
618 INetURLObject
aURL( sWritable
, INET_PROT_FILE
);
619 xFolderPicker
->setDisplayDirectory( aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
621 Reference
< XAsynchronousExecutableDialog
> xAsyncDlg( xFolderPicker
, UNO_QUERY
);
622 if ( xAsyncDlg
.is() )
623 xAsyncDlg
->startExecuteModal( xDialogListener
.get() );
626 short nRet
= xFolderPicker
->execute();
627 if ( ExecutableDialogResults::OK
!= nRet
)
630 String
sFolder( xFolderPicker
->getDirectory() );
631 ChangeCurrentEntry( sFolder
);
636 SAL_WARN( "cui.options", "SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
642 // -----------------------------------------------------------------------
644 IMPL_LINK( SvxPathTabPage
, HeaderSelect_Impl
, HeaderBar
*, pBar
)
646 if ( pBar
&& pBar
->GetCurItemId() != ITEMID_TYPE
)
649 HeaderBarItemBits nBits
= pHeaderBar
->GetItemBits(ITEMID_TYPE
);
650 sal_Bool bUp
= ( ( nBits
& HIB_UPARROW
) == HIB_UPARROW
);
651 SvSortMode eMode
= SortAscending
;
655 nBits
&= ~HIB_UPARROW
;
656 nBits
|= HIB_DOWNARROW
;
657 eMode
= SortDescending
;
661 nBits
&= ~HIB_DOWNARROW
;
662 nBits
|= HIB_UPARROW
;
664 pHeaderBar
->SetItemBits( ITEMID_TYPE
, nBits
);
665 SvTreeList
* pModel
= pPathBox
->GetModel();
666 pModel
->SetSortMode( eMode
);
671 // -----------------------------------------------------------------------
673 IMPL_LINK( SvxPathTabPage
, HeaderEndDrag_Impl
, HeaderBar
*, pBar
)
675 if ( pBar
&& !pBar
->GetCurItemId() )
678 if ( !pHeaderBar
->IsItemMode() )
681 sal_uInt16 nTabs
= pHeaderBar
->GetItemCount();
683 long nWidth
= pHeaderBar
->GetItemSize(ITEMID_TYPE
);
684 long nBarWidth
= pHeaderBar
->GetSizePixel().Width();
686 if(nWidth
< TAB_WIDTH_MIN
)
687 pHeaderBar
->SetItemSize( ITEMID_TYPE
, TAB_WIDTH_MIN
);
688 else if ( ( nBarWidth
- nWidth
) < TAB_WIDTH_MIN
)
689 pHeaderBar
->SetItemSize( ITEMID_TYPE
, nBarWidth
- TAB_WIDTH_MIN
);
691 for ( sal_uInt16 i
= 1; i
<= nTabs
; ++i
)
693 long _nWidth
= pHeaderBar
->GetItemSize(i
);
694 aSz
.Width() = _nWidth
+ nTmpSz
;
696 pPathBox
->SetTab( i
, PixelToLogic( aSz
, MapMode(MAP_APPFONT
) ).Width(), MAP_APPFONT
);
702 // -----------------------------------------------------------------------
704 IMPL_LINK( SvxPathTabPage
, DialogClosedHdl
, DialogClosedEvent
*, pEvt
)
706 if ( RET_OK
== pEvt
->DialogResult
)
708 DBG_ASSERT( xFolderPicker
.is() == sal_True
, "SvxPathTabPage::DialogClosedHdl(): no folder picker" );
710 String sURL
= String( xFolderPicker
->getDirectory() );
711 ChangeCurrentEntry( sURL
);
716 // -----------------------------------------------------------------------
718 void SvxPathTabPage::GetPathList(
719 sal_uInt16 _nPathHandle
, String
& _rInternalPath
,
720 String
& _rUserPath
, String
& _rWritablePath
, sal_Bool
& _rReadOnly
)
722 String sCfgName
= getCfgName_Impl( _nPathHandle
);
724 // load PathSettings service if necessary
725 if ( !pImpl
->m_xPathSettings
.is() )
727 Reference
< XMultiServiceFactory
> xSMgr
= comphelper::getProcessServiceFactory();
728 pImpl
->m_xPathSettings
= Reference
< XPropertySet
>( xSMgr
->createInstance(
729 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
730 "com.sun.star.util.PathSettings") ) ), UNO_QUERY
);
735 if ( pImpl
->m_xPathSettings
.is() )
737 // load internal paths
738 String
sProp( sCfgName
);
740 sProp
+= POSTFIX_INTERNAL
;
741 Any aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
742 Sequence
< ::rtl::OUString
> aPathSeq
;
743 if ( aAny
>>= aPathSeq
)
745 long i
, nCount
= aPathSeq
.getLength();
746 const ::rtl::OUString
* pPaths
= aPathSeq
.getConstArray();
748 for ( i
= 0; i
< nCount
; ++i
)
750 if ( _rInternalPath
.Len() > 0 )
751 _rInternalPath
+= ';';
752 _rInternalPath
+= String( pPaths
[i
] );
757 sProp
+= POSTFIX_USER
;
758 aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
759 if ( aAny
>>= aPathSeq
)
761 long i
, nCount
= aPathSeq
.getLength();
762 const ::rtl::OUString
* pPaths
= aPathSeq
.getConstArray();
764 for ( i
= 0; i
< nCount
; ++i
)
766 if ( _rUserPath
.Len() > 0 )
768 _rUserPath
+= String( pPaths
[i
] );
771 // then the writable path
773 sProp
+= POSTFIX_WRITABLE
;
774 aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
775 ::rtl::OUString sWritablePath
;
776 if ( aAny
>>= sWritablePath
)
777 _rWritablePath
= String( sWritablePath
);
779 // and the readonly flag
781 Reference
< XPropertySetInfo
> xInfo
= pImpl
->m_xPathSettings
->getPropertySetInfo();
782 Property aProp
= xInfo
->getPropertyByName( sProp
);
783 _rReadOnly
= ( ( aProp
.Attributes
& PropertyAttribute::READONLY
) == PropertyAttribute::READONLY
);
786 catch( const Exception
& )
788 OSL_FAIL( "SvxPathTabPage::GetPathList(): caught an exception!" );
792 // -----------------------------------------------------------------------
794 void SvxPathTabPage::SetPathList(
795 sal_uInt16 _nPathHandle
, const String
& _rUserPath
, const String
& _rWritablePath
)
797 String sCfgName
= getCfgName_Impl( _nPathHandle
);
799 // load PathSettings service if necessary
800 if ( !pImpl
->m_xPathSettings
.is() )
802 Reference
< XMultiServiceFactory
> xSMgr
= comphelper::getProcessServiceFactory();
803 pImpl
->m_xPathSettings
= Reference
< XPropertySet
>( xSMgr
->createInstance(
804 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
805 "com.sun.star.util.PathSettings") ) ), UNO_QUERY
);
810 if ( pImpl
->m_xPathSettings
.is() )
813 char cDelim
= MULTIPATH_DELIMITER
;
814 sal_uInt16 nCount
= comphelper::string::getTokenCount(_rUserPath
, cDelim
);
815 Sequence
< ::rtl::OUString
> aPathSeq( nCount
);
816 ::rtl::OUString
* pArray
= aPathSeq
.getArray();
817 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
818 pArray
[i
] = ::rtl::OUString( _rUserPath
.GetToken( i
, cDelim
) );
819 String
sProp( sCfgName
);
820 sProp
+= POSTFIX_USER
;
821 Any aValue
= makeAny( aPathSeq
);
822 pImpl
->m_xPathSettings
->setPropertyValue( sProp
, aValue
);
824 // then the writable path
825 aValue
= makeAny( ::rtl::OUString( _rWritablePath
) );
827 sProp
+= POSTFIX_WRITABLE
;
828 pImpl
->m_xPathSettings
->setPropertyValue( sProp
, aValue
);
831 catch( const Exception
& e
)
833 SAL_WARN("cui", "caught: " << e
.Message
);
837 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */