1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optpath.cxx,v $
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_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
38 // include ---------------------------------------------------------------
40 #include <svx/svxdlg.hxx> //CHINA001
41 #include <tools/shl.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <sfx2/filedlghelper.hxx>
44 #include <sfx2/app.hxx>
45 #include <svtools/pickerhelper.hxx>
46 #include <svtools/aeitem.hxx>
47 #include <svtools/svtabbx.hxx>
48 #include <svtools/filedlg.hxx>
49 #include <tools/config.hxx>
50 #include <tools/urlobj.hxx>
51 #include <vcl/svapp.hxx>
52 #include <svtools/defaultoptions.hxx>
53 #include <unotools/localfilehelper.hxx>
54 #include <svtools/pathoptions.hxx>
55 #include <svtools/moduleoptions.hxx>
56 #include <svtools/viewoptions.hxx>
58 #define _SVX_OPTPATH_CXX
60 #include "optpath.hxx"
61 #include <svx/dialmgr.hxx>
62 //CHINA001 #include "multipat.hxx"
63 #include "optpath.hrc"
64 #include <svx/dialogs.hrc>
66 #include <comphelper/processfactory.hxx>
67 #include <comphelper/configurationhelper.hxx>
68 #include <com/sun/star/uno/Exception.hpp>
69 #include <com/sun/star/beans/XPropertySet.hpp>
70 #include <com/sun/star/beans/PropertyAttribute.hpp>
71 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
72 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
73 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
74 #include "optHeaderTabListbox.hxx"
75 #include <readonlyimage.hxx>
76 #include <vcl/help.hxx>
78 using namespace ::com::sun::star::beans
;
79 using namespace ::com::sun::star::lang
;
80 using namespace ::com::sun::star::ui::dialogs
;
81 using namespace ::com::sun::star::uno
;
84 // define ----------------------------------------------------------------
87 #define TAB_WIDTH_MIN 10
88 #define TAB_WIDTH2 1000
92 #define POSTFIX_INTERNAL String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_internal" ) )
93 #define POSTFIX_USER String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_user" ) )
94 #define POSTFIX_WRITABLE String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_writable" ) )
95 #define POSTFIX_READONLY String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_readonly" ) )
96 #define VAR_ONE String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "%1" ) )
97 #define IODLG_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Save"))
99 // struct OptPath_Impl ---------------------------------------------------
103 SvtDefaultOptions m_aDefOpt
;
105 Image m_aLockImageHC
;
106 String m_sMultiPathDlg
;
107 Reference
< XPropertySet
> m_xPathSettings
;
109 OptPath_Impl(const ResId
& rLockRes
, const ResId
& rLockResHC
) :
110 m_aLockImage(rLockRes
),
111 m_aLockImageHC(rLockResHC
){}
114 // struct PathUserData_Impl ----------------------------------------------
116 struct PathUserData_Impl
121 String sWritablePath
;
123 PathUserData_Impl( USHORT nId
) :
124 nRealId( nId
), eState( SFX_ITEM_UNKNOWN
) {}
127 struct Handle2CfgNameMapping_Impl
130 const char* m_pCfgName
;
133 static Handle2CfgNameMapping_Impl __READONLY_DATA Hdl2CfgMap_Impl
[] =
135 { SvtPathOptions::PATH_AUTOCORRECT
, "AutoCorrect" },
136 { SvtPathOptions::PATH_AUTOTEXT
, "AutoText" },
137 { SvtPathOptions::PATH_BACKUP
, "Backup" },
138 { SvtPathOptions::PATH_GALLERY
, "Gallery" },
139 { SvtPathOptions::PATH_GRAPHIC
, "Graphic" },
140 { SvtPathOptions::PATH_TEMP
, "Temp" },
141 { SvtPathOptions::PATH_TEMPLATE
, "Template" },
142 { SvtPathOptions::PATH_WORK
, "Work" },
143 #if OSL_DEBUG_LEVEL > 1
144 { SvtPathOptions::PATH_LINGUISTIC
, "Linguistic" },
145 { SvtPathOptions::PATH_DICTIONARY
, "Dictionary" },
150 static String
getCfgName_Impl( USHORT _nHandle
)
154 while ( Hdl2CfgMap_Impl
[ nIndex
].m_nHandle
!= USHRT_MAX
)
156 if ( Hdl2CfgMap_Impl
[ nIndex
].m_nHandle
== _nHandle
)
159 sCfgName
= String::CreateFromAscii( Hdl2CfgMap_Impl
[ nIndex
].m_pCfgName
);
168 #define MULTIPATH_DELIMITER ';'
170 String
Convert_Impl( const String
& rValue
)
172 char cDelim
= MULTIPATH_DELIMITER
;
173 USHORT nCount
= rValue
.GetTokenCount( cDelim
);
175 for ( USHORT i
=0; i
<nCount
; ++i
)
177 String aValue
= rValue
.GetToken( i
, cDelim
);
178 INetURLObject
aObj( aValue
);
179 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
180 aReturn
+= String(aObj
.PathToFileName());
181 else if ( ::utl::LocalFileHelper::IsFileContent( aValue
) )
182 aReturn
+= String(aObj
.GetURLPath( INetURLObject::DECODE_WITH_CHARSET
));
184 aReturn
+= MULTIPATH_DELIMITER
;
190 // class SvxControlFocusHelper ---------------------------------------------
192 long SvxControlFocusHelper::Notify( NotifyEvent
& rNEvt
)
194 long nRet
= Control::Notify( rNEvt
);
196 if ( m_pFocusCtrl
&& rNEvt
.GetWindow() != m_pFocusCtrl
&& rNEvt
.GetType() == EVENT_GETFOCUS
)
197 m_pFocusCtrl
->GrabFocus();
201 // functions -------------------------------------------------------------
203 BOOL
IsMultiPath_Impl( const USHORT nIndex
)
205 #if OSL_DEBUG_LEVEL > 1
206 return ( SvtPathOptions::PATH_AUTOCORRECT
== nIndex
||
207 SvtPathOptions::PATH_AUTOTEXT
== nIndex
||
208 SvtPathOptions::PATH_BASIC
== nIndex
||
209 SvtPathOptions::PATH_GALLERY
== nIndex
||
210 SvtPathOptions::PATH_TEMPLATE
== nIndex
);
212 return ( SvtPathOptions::PATH_AUTOCORRECT
== nIndex
||
213 SvtPathOptions::PATH_AUTOTEXT
== nIndex
||
214 SvtPathOptions::PATH_BASIC
== nIndex
||
215 SvtPathOptions::PATH_GALLERY
== nIndex
||
216 SvtPathOptions::PATH_TEMPLATE
== nIndex
||
217 SvtPathOptions::PATH_LINGUISTIC
== nIndex
||
218 SvtPathOptions::PATH_DICTIONARY
== nIndex
);
222 // class SvxPathTabPage --------------------------------------------------
224 SvxPathTabPage::SvxPathTabPage( Window
* pParent
, const SfxItemSet
& rSet
) :
226 SfxTabPage( pParent
, SVX_RES( RID_SFXPAGE_PATH
), rSet
),
228 aTypeText ( this, SVX_RES( FT_TYPE
) ),
229 aPathText ( this, SVX_RES( FT_PATH
) ),
230 aPathCtrl ( this, SVX_RES( LB_PATH
) ),
231 aStandardBtn ( this, SVX_RES( BTN_STANDARD
) ),
232 aPathBtn ( this, SVX_RES( BTN_PATH
) ),
233 aStdBox ( this, SVX_RES( GB_STD
) ),
237 pImpl ( new OptPath_Impl( SVX_RES(IMG_LOCK
), SVX_RES(IMG_LOCK_HC
) ) ),
238 xDialogListener ( new ::svt::DialogClosedListener() )
241 pImpl
->m_sMultiPathDlg
= String( SVX_RES( STR_MULTIPATHDLG
) );
242 aStandardBtn
.SetClickHdl( LINK( this, SvxPathTabPage
, StandardHdl_Impl
) );
243 Link aLink
= LINK( this, SvxPathTabPage
, PathHdl_Impl
);
244 aPathBtn
.SetClickHdl( aLink
);
245 Size aBoxSize
= aPathCtrl
.GetOutputSizePixel();
246 pHeaderBar
= new HeaderBar( &aPathCtrl
, WB_BUTTONSTYLE
| WB_BOTTOMBORDER
);
247 pHeaderBar
->SetPosSizePixel( Point( 0, 0 ), Size( aBoxSize
.Width(), 16 ) );
248 pHeaderBar
->SetSelectHdl( LINK( this, SvxPathTabPage
, HeaderSelect_Impl
) );
249 pHeaderBar
->SetEndDragHdl( LINK( this, SvxPathTabPage
, HeaderEndDrag_Impl
) );
251 aSz
.Width() = TAB_WIDTH1
;
252 pHeaderBar
->InsertItem( ITEMID_TYPE
, aTypeText
.GetText(),
253 LogicToPixel( aSz
, MapMode( MAP_APPFONT
) ).Width(),
254 HIB_LEFT
| HIB_VCENTER
| HIB_CLICKABLE
| HIB_UPARROW
);
255 aSz
.Width() = TAB_WIDTH2
;
256 pHeaderBar
->InsertItem( ITEMID_PATH
, aPathText
.GetText(),
257 LogicToPixel( aSz
, MapMode( MAP_APPFONT
) ).Width(),
258 HIB_LEFT
| HIB_VCENTER
);
260 static long nTabs
[] = {3, 0, TAB_WIDTH1
, TAB_WIDTH1
+ TAB_WIDTH2
};
261 Size aHeadSize
= pHeaderBar
->GetSizePixel();
263 WinBits nBits
= WB_SORT
| WB_HSCROLL
| WB_CLIPCHILDREN
| WB_TABSTOP
;
264 pPathBox
= new OptHeaderTabListBox( &aPathCtrl
, nBits
);
265 aPathCtrl
.SetFocusControl( pPathBox
);
266 pPathBox
->SetWindowBits( nBits
);
267 pPathBox
->SetDoubleClickHdl( aLink
);
268 pPathBox
->SetSelectHdl( LINK( this, SvxPathTabPage
, PathSelect_Impl
) );
269 pPathBox
->SetSelectionMode( MULTIPLE_SELECTION
);
270 pPathBox
->SetPosSizePixel( Point( 0, aHeadSize
.Height() ),
271 Size( aBoxSize
.Width(), aBoxSize
.Height() - aHeadSize
.Height() ) );
272 pPathBox
->SetTabs( &nTabs
[0], MAP_APPFONT
);
273 pPathBox
->InitHeaderBar( pHeaderBar
);
274 pPathBox
->SetHighlightRange();
275 pPathBox
->SetHelpId( HID_OPTPATH_CTL_PATH
);
276 pHeaderBar
->SetHelpId( HID_OPTPATH_HEADERBAR
);
282 xDialogListener
->SetDialogClosedLink( LINK( this, SvxPathTabPage
, DialogClosedHdl
) );
285 // -----------------------------------------------------------------------
287 SvxPathTabPage::~SvxPathTabPage()
289 // #110603# do not grab focus to a destroyed window !!!
290 aPathCtrl
.SetFocusControl( NULL
);
293 for ( USHORT i
= 0; i
< pPathBox
->GetEntryCount(); ++i
)
294 delete (PathUserData_Impl
*)pPathBox
->GetEntry(i
)->GetUserData();
300 // -----------------------------------------------------------------------
302 SfxTabPage
* SvxPathTabPage::Create( Window
* pParent
,
303 const SfxItemSet
& rAttrSet
)
305 return ( new SvxPathTabPage( pParent
, rAttrSet
) );
308 // -----------------------------------------------------------------------
310 BOOL
SvxPathTabPage::FillItemSet( SfxItemSet
& )
312 SvtPathOptions aPathOpt
;
313 for ( USHORT i
= 0; i
< pPathBox
->GetEntryCount(); ++i
)
315 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pPathBox
->GetEntry(i
)->GetUserData();
316 USHORT nRealId
= pPathImpl
->nRealId
;
317 if ( pPathImpl
->eState
== SFX_ITEM_SET
)
318 SetPathList( nRealId
, pPathImpl
->sUserPath
, pPathImpl
->sWritablePath
);
323 // -----------------------------------------------------------------------
325 void SvxPathTabPage::Reset( const SfxItemSet
& )
328 SvtPathOptions aPathOpt
; //! deprecated
330 for( USHORT i
= 0; i
<= (USHORT
)SvtPathOptions::PATH_WORK
; ++i
)
332 // only writer uses autotext
333 if ( i
== SvtPathOptions::PATH_AUTOTEXT
334 && !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SWRITER
) )
339 case SvtPathOptions::PATH_AUTOCORRECT
:
340 case SvtPathOptions::PATH_AUTOTEXT
:
341 case SvtPathOptions::PATH_BACKUP
:
342 case SvtPathOptions::PATH_GALLERY
:
343 case SvtPathOptions::PATH_GRAPHIC
:
344 case SvtPathOptions::PATH_TEMP
:
345 case SvtPathOptions::PATH_TEMPLATE
:
346 #if OSL_DEBUG_LEVEL > 1
347 case SvtPathOptions::PATH_LINGUISTIC
:
348 case SvtPathOptions::PATH_DICTIONARY
:
350 case SvtPathOptions::PATH_WORK
:
352 String
aStr( SVX_RES( RID_SVXSTR_PATH_NAME_START
+ i
) );
353 String sInternal
, sUser
, sWritable
;
354 sal_Bool bReadOnly
= sal_False
;
355 GetPathList( i
, sInternal
, sUser
, sWritable
, bReadOnly
);
356 String sTmpPath
= sUser
;
357 if ( sTmpPath
.Len() > 0 && sWritable
.Len() > 0 )
358 sTmpPath
+= MULTIPATH_DELIMITER
;
359 sTmpPath
+= sWritable
;
360 String
aValue( sTmpPath
);
362 aStr
+= Convert_Impl( aValue
);
363 SvLBoxEntry
* pEntry
= pPathBox
->InsertEntry( aStr
);
366 pPathBox
->SetCollapsedEntryBmp( pEntry
, pImpl
->m_aLockImage
, BMP_COLOR_NORMAL
);
367 pPathBox
->SetCollapsedEntryBmp( pEntry
, pImpl
->m_aLockImageHC
, BMP_COLOR_HIGHCONTRAST
);
369 PathUserData_Impl
* pPathImpl
= new PathUserData_Impl(i
);
370 pPathImpl
->sUserPath
= sUser
;
371 pPathImpl
->sWritablePath
= sWritable
;
372 pEntry
->SetUserData( pPathImpl
);
377 String aUserData
= GetUserData();
378 if ( aUserData
.Len() )
380 // Spaltenbreite restaurieren
381 pHeaderBar
->SetItemSize( ITEMID_TYPE
, aUserData
.GetToken(0).ToInt32() );
382 HeaderEndDrag_Impl( NULL
);
383 // Sortierrichtung restaurieren
384 BOOL bUp
= (BOOL
)(USHORT
)aUserData
.GetToken(1).ToInt32();
385 HeaderBarItemBits nBits
= pHeaderBar
->GetItemBits(ITEMID_TYPE
);
389 nBits
&= ~HIB_UPARROW
;
390 nBits
|= HIB_DOWNARROW
;
394 nBits
&= ~HIB_DOWNARROW
;
395 nBits
|= HIB_UPARROW
;
397 pHeaderBar
->SetItemBits( ITEMID_TYPE
, nBits
);
398 HeaderSelect_Impl( NULL
);
400 PathSelect_Impl( NULL
);
403 // -----------------------------------------------------------------------
405 void SvxPathTabPage::FillUserData()
407 String aUserData
= String::CreateFromInt32( pHeaderBar
->GetItemSize( ITEMID_TYPE
) );
409 HeaderBarItemBits nBits
= pHeaderBar
->GetItemBits( ITEMID_TYPE
);
410 BOOL bUp
= ( ( nBits
& HIB_UPARROW
) == HIB_UPARROW
);
411 aUserData
+= bUp
? '1' : '0';
412 SetUserData( aUserData
);
415 // -----------------------------------------------------------------------
417 IMPL_LINK( SvxPathTabPage
, PathSelect_Impl
, OptHeaderTabListBox
*, EMPTYARG
)
424 USHORT nSelCount
= 0;
425 SvLBoxEntry
* pEntry
= pPathBox
->FirstSelected();
427 //the entry image indicates whether the path is write protected
430 aEntryImage
= pPathBox
->GetCollapsedEntryBmp( pEntry
);
431 BOOL bEnable
= !aEntryImage
;
432 while ( pEntry
&& ( nSelCount
< 2 ) )
435 pEntry
= pPathBox
->NextSelected( pEntry
);
438 aPathBtn
.Enable( 1 == nSelCount
&& bEnable
);
439 aStandardBtn
.Enable( nSelCount
> 0 && bEnable
);
443 // -----------------------------------------------------------------------
445 IMPL_LINK( SvxPathTabPage
, StandardHdl_Impl
, PushButton
*, EMPTYARG
)
447 SvLBoxEntry
* pEntry
= pPathBox
->FirstSelected();
450 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
451 String aOldPath
= pImpl
->m_aDefOpt
.GetDefaultPath( pPathImpl
->nRealId
);
453 if ( aOldPath
.Len() )
455 String sInternal
, sUser
, sWritable
, sTemp
;
456 sal_Bool bReadOnly
= sal_False
;
457 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
460 USHORT nOldCount
= aOldPath
.GetTokenCount( MULTIPATH_DELIMITER
);
461 USHORT nIntCount
= sInternal
.GetTokenCount( MULTIPATH_DELIMITER
);
462 for ( i
= 0; i
< nOldCount
; ++i
)
465 String sOnePath
= aOldPath
.GetToken( i
, MULTIPATH_DELIMITER
);
466 for ( USHORT j
= 0; !bFound
&& j
< nIntCount
; ++j
)
468 if ( sInternal
.GetToken( i
, MULTIPATH_DELIMITER
) == sOnePath
)
473 if ( sTemp
.Len() > 0 )
474 sTemp
+= MULTIPATH_DELIMITER
;
479 String sUserPath
, sWritablePath
;
480 nOldCount
= sTemp
.GetTokenCount( MULTIPATH_DELIMITER
);
481 for ( i
= 0; nOldCount
> 0 && i
< nOldCount
- 1; ++i
)
483 if ( sUserPath
.Len() > 0 )
484 sUserPath
+= MULTIPATH_DELIMITER
;
485 sUserPath
+= sTemp
.GetToken( i
, MULTIPATH_DELIMITER
);
487 sWritablePath
= sTemp
.GetToken( nOldCount
- 1, MULTIPATH_DELIMITER
);
489 pPathBox
->SetEntryText( Convert_Impl( sTemp
), pEntry
, 1 );
490 pPathImpl
->eState
= SFX_ITEM_SET
;
491 pPathImpl
->sUserPath
= sUserPath
;
492 pPathImpl
->sWritablePath
= sWritablePath
;
494 pEntry
= pPathBox
->NextSelected( pEntry
);
499 // -----------------------------------------------------------------------
501 void SvxPathTabPage::ChangeCurrentEntry( const String
& _rFolder
)
503 SvLBoxEntry
* pEntry
= pPathBox
->GetCurEntry();
506 DBG_ERRORFILE( "SvxPathTabPage::ChangeCurrentEntry(): no entry" );
510 String sInternal
, sUser
, sWritable
;
511 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
512 sal_Bool bReadOnly
= sal_False
;
513 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
514 sUser
= pPathImpl
->sUserPath
;
515 sWritable
= pPathImpl
->sWritablePath
;
516 USHORT nPos
= pPathImpl
->nRealId
;
518 // old path is an URL?
519 INetURLObject
aObj( sWritable
);
520 FASTBOOL bURL
= ( aObj
.GetProtocol() != INET_PROT_NOT_VALID
);
521 rtl::OUString
aPathStr( _rFolder
);
522 INetURLObject
aNewObj( aPathStr
);
523 aNewObj
.removeFinalSlash();
525 // then the new path also an URL else system path
526 String sNewPathStr
= bURL
? aPathStr
: aNewObj
.getFSysPath( INetURLObject::FSYS_DETECT
);
530 // Unix is case sensitive
531 ( sNewPathStr
!= sWritable
);
533 ( sNewPathStr
.CompareIgnoreCaseToAscii( sWritable
) != COMPARE_EQUAL
);
538 pPathBox
->SetEntryText( Convert_Impl( sNewPathStr
), pEntry
, 1 );
539 nPos
= (USHORT
)pPathBox
->GetModel()->GetAbsPos( pEntry
);
540 pPathImpl
= (PathUserData_Impl
*)pPathBox
->GetEntry(nPos
)->GetUserData();
541 pPathImpl
->eState
= SFX_ITEM_SET
;
542 pPathImpl
->sWritablePath
= sNewPathStr
;
543 if ( SvtPathOptions::PATH_WORK
== pPathImpl
->nRealId
)
545 // Remove view options entry so the new work path
546 // will be used for the next open dialog.
547 SvtViewOptions
aDlgOpt( E_DIALOG
, IODLG_CONFIGNAME
);
549 // Reset also last used dir in the sfx application instance
550 SfxApplication
*pSfxApp
= SFX_APP();
551 pSfxApp
->ResetLastDir();
553 // Set configuration flag to notify file picker that it's necessary
554 // to take over the path provided.
555 Reference
< XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
556 ::comphelper::ConfigurationHelper::writeDirectKey(xFactory
,
557 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Common/")),
558 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Path/Info")),
559 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WorkPathChanged")),
560 ::com::sun::star::uno::makeAny(true),
561 ::comphelper::ConfigurationHelper::E_STANDARD
);
566 // -----------------------------------------------------------------------
568 IMPL_LINK( SvxPathTabPage
, PathHdl_Impl
, PushButton
*, EMPTYARG
)
570 SvLBoxEntry
* pEntry
= pPathBox
->GetCurEntry();
571 USHORT nPos
= ( pEntry
!= NULL
) ? ( (PathUserData_Impl
*)pEntry
->GetUserData() )->nRealId
: 0;
572 String sInternal
, sUser
, sWritable
;
575 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
576 sal_Bool bReadOnly
= sal_False
;
577 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
578 sUser
= pPathImpl
->sUserPath
;
579 sWritable
= pPathImpl
->sWritablePath
;
582 if(pEntry
&& !(!((OptHeaderTabListBox
*)pPathBox
)->GetCollapsedEntryBmp(pEntry
)))
585 if ( IsMultiPath_Impl( nPos
) )
587 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
590 AbstractSvxMultiPathDialog
* pMultiDlg
=
591 pFact
->CreateSvxMultiPathDialog( this, RID_SVXDLG_MULTIPATH
);
592 DBG_ASSERT( pMultiDlg
, "Dialogdiet fail!" );
593 pMultiDlg
->EnableRadioButtonMode();
595 String
sPath( sUser
);
596 if ( sPath
.Len() > 0 )
597 sPath
+= MULTIPATH_DELIMITER
;
599 pMultiDlg
->SetPath( sPath
);
601 String sPathName
= pPathBox
->GetEntryText( pEntry
, 0 );
602 String
sNewTitle( pImpl
->m_sMultiPathDlg
);
603 sNewTitle
.SearchAndReplace( VAR_ONE
, sPathName
);
604 pMultiDlg
->SetTitle( sNewTitle
);
606 if ( pMultiDlg
->Execute() == RET_OK
&& pEntry
)
611 String sNewPath
= pMultiDlg
->GetPath();
612 char cDelim
= MULTIPATH_DELIMITER
;
613 USHORT nCount
= sNewPath
.GetTokenCount( cDelim
);
617 for ( ; i
< nCount
- 1; ++i
)
619 if ( sUser
.Len() > 0 )
621 sUser
+= sNewPath
.GetToken( i
, cDelim
);
623 if ( sFullPath
.Len() > 0 )
626 sWritable
+= sNewPath
.GetToken( i
, cDelim
);
627 if ( sFullPath
.Len() > 0 )
629 sFullPath
+= sWritable
;
632 pPathBox
->SetEntryText( Convert_Impl( sFullPath
), pEntry
, 1 );
633 // save modified flag
634 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
635 pPathImpl
->eState
= SFX_ITEM_SET
;
636 pPathImpl
->sUserPath
= sUser
;
637 pPathImpl
->sWritablePath
= sWritable
;
646 rtl::OUString
aService( RTL_CONSTASCII_USTRINGPARAM( FOLDER_PICKER_SERVICE_NAME
) );
647 Reference
< XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
648 xFolderPicker
= ::com::sun::star::uno::Reference
< XFolderPicker
>(
649 xFactory
->createInstance( aService
), UNO_QUERY
);
651 // svt::SetDialogHelpId( xFolderPicker, HID_OPTIONS_PATHS_SELECTFOLDER );
653 INetURLObject
aURL( sWritable
, INET_PROT_FILE
);
654 xFolderPicker
->setDisplayDirectory( aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
656 Reference
< XAsynchronousExecutableDialog
> xAsyncDlg( xFolderPicker
, UNO_QUERY
);
657 if ( xAsyncDlg
.is() )
658 xAsyncDlg
->startExecuteModal( xDialogListener
.get() );
661 short nRet
= xFolderPicker
->execute();
662 if ( ExecutableDialogResults::OK
!= nRet
)
665 String
sFolder( xFolderPicker
->getDirectory() );
666 ChangeCurrentEntry( sFolder
);
671 DBG_ERRORFILE( "SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
677 // -----------------------------------------------------------------------
679 IMPL_LINK( SvxPathTabPage
, HeaderSelect_Impl
, HeaderBar
*, pBar
)
681 if ( pBar
&& pBar
->GetCurItemId() != ITEMID_TYPE
)
684 HeaderBarItemBits nBits
= pHeaderBar
->GetItemBits(ITEMID_TYPE
);
685 BOOL bUp
= ( ( nBits
& HIB_UPARROW
) == HIB_UPARROW
);
686 SvSortMode eMode
= SortAscending
;
690 nBits
&= ~HIB_UPARROW
;
691 nBits
|= HIB_DOWNARROW
;
692 eMode
= SortDescending
;
696 nBits
&= ~HIB_DOWNARROW
;
697 nBits
|= HIB_UPARROW
;
699 pHeaderBar
->SetItemBits( ITEMID_TYPE
, nBits
);
700 SvTreeList
* pModel
= pPathBox
->GetModel();
701 pModel
->SetSortMode( eMode
);
706 // -----------------------------------------------------------------------
708 IMPL_LINK( SvxPathTabPage
, HeaderEndDrag_Impl
, HeaderBar
*, pBar
)
710 if ( pBar
&& !pBar
->GetCurItemId() )
713 if ( !pHeaderBar
->IsItemMode() )
716 USHORT nTabs
= pHeaderBar
->GetItemCount();
718 long nWidth
= pHeaderBar
->GetItemSize(ITEMID_TYPE
);
719 long nBarWidth
= pHeaderBar
->GetSizePixel().Width();
721 if(nWidth
< TAB_WIDTH_MIN
)
722 pHeaderBar
->SetItemSize( ITEMID_TYPE
, TAB_WIDTH_MIN
);
723 else if ( ( nBarWidth
- nWidth
) < TAB_WIDTH_MIN
)
724 pHeaderBar
->SetItemSize( ITEMID_TYPE
, nBarWidth
- TAB_WIDTH_MIN
);
726 for ( USHORT i
= 1; i
<= nTabs
; ++i
)
728 long _nWidth
= pHeaderBar
->GetItemSize(i
);
729 aSz
.Width() = _nWidth
+ nTmpSz
;
731 pPathBox
->SetTab( i
, PixelToLogic( aSz
, MapMode(MAP_APPFONT
) ).Width(), MAP_APPFONT
);
737 // -----------------------------------------------------------------------
739 IMPL_LINK( SvxPathTabPage
, DialogClosedHdl
, DialogClosedEvent
*, pEvt
)
741 if ( RET_OK
== pEvt
->DialogResult
)
743 DBG_ASSERT( xFolderPicker
.is() == sal_True
, "SvxPathTabPage::DialogClosedHdl(): no folder picker" );
745 String sURL
= String( xFolderPicker
->getDirectory() );
746 ChangeCurrentEntry( sURL
);
751 // -----------------------------------------------------------------------
753 void SvxPathTabPage::GetPathList(
754 USHORT _nPathHandle
, String
& _rInternalPath
,
755 String
& _rUserPath
, String
& _rWritablePath
, sal_Bool
& _rReadOnly
)
757 String sCfgName
= getCfgName_Impl( _nPathHandle
);
759 // load PathSettings service if necessary
760 if ( !pImpl
->m_xPathSettings
.is() )
762 Reference
< XMultiServiceFactory
> xSMgr
= comphelper::getProcessServiceFactory();
763 pImpl
->m_xPathSettings
= Reference
< XPropertySet
>( xSMgr
->createInstance(
764 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
765 "com.sun.star.util.PathSettings") ) ), UNO_QUERY
);
770 if ( pImpl
->m_xPathSettings
.is() )
772 // load internal paths
773 String
sProp( sCfgName
);
775 sProp
+= POSTFIX_INTERNAL
;
776 Any aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
777 Sequence
< ::rtl::OUString
> aPathSeq
;
778 if ( aAny
>>= aPathSeq
)
780 long i
, nCount
= aPathSeq
.getLength();
781 const ::rtl::OUString
* pPaths
= aPathSeq
.getConstArray();
783 for ( i
= 0; i
< nCount
; ++i
)
785 if ( _rInternalPath
.Len() > 0 )
786 _rInternalPath
+= ';';
787 _rInternalPath
+= String( pPaths
[i
] );
792 sProp
+= POSTFIX_USER
;
793 aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
794 if ( aAny
>>= aPathSeq
)
796 long i
, nCount
= aPathSeq
.getLength();
797 const ::rtl::OUString
* pPaths
= aPathSeq
.getConstArray();
799 for ( i
= 0; i
< nCount
; ++i
)
801 if ( _rUserPath
.Len() > 0 )
803 _rUserPath
+= String( pPaths
[i
] );
806 // then the writable path
808 sProp
+= POSTFIX_WRITABLE
;
809 aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
810 ::rtl::OUString sWritablePath
;
811 if ( aAny
>>= sWritablePath
)
812 _rWritablePath
= String( sWritablePath
);
814 // and the readonly flag
816 Reference
< XPropertySetInfo
> xInfo
= pImpl
->m_xPathSettings
->getPropertySetInfo();
817 Property aProp
= xInfo
->getPropertyByName( sProp
);
818 _rReadOnly
= ( ( aProp
.Attributes
& PropertyAttribute::READONLY
) == PropertyAttribute::READONLY
);
821 catch( const Exception
& )
823 OSL_ENSURE( sal_False
, "SvxPathTabPage::GetPathList(): caught an exception!" );
827 // -----------------------------------------------------------------------
829 void SvxPathTabPage::SetPathList(
830 USHORT _nPathHandle
, const String
& _rUserPath
, const String
& _rWritablePath
)
832 String sCfgName
= getCfgName_Impl( _nPathHandle
);
834 // load PathSettings service if necessary
835 if ( !pImpl
->m_xPathSettings
.is() )
837 Reference
< XMultiServiceFactory
> xSMgr
= comphelper::getProcessServiceFactory();
838 pImpl
->m_xPathSettings
= Reference
< XPropertySet
>( xSMgr
->createInstance(
839 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
840 "com.sun.star.util.PathSettings") ) ), UNO_QUERY
);
845 if ( pImpl
->m_xPathSettings
.is() )
848 char cDelim
= MULTIPATH_DELIMITER
;
849 USHORT nCount
= _rUserPath
.GetTokenCount( cDelim
);
850 Sequence
< ::rtl::OUString
> aPathSeq( nCount
);
851 ::rtl::OUString
* pArray
= aPathSeq
.getArray();
852 for ( USHORT i
= 0; i
< nCount
; ++i
)
853 pArray
[i
] = ::rtl::OUString( _rUserPath
.GetToken( i
, cDelim
) );
854 String
sProp( sCfgName
);
855 sProp
+= POSTFIX_USER
;
856 Any aValue
= makeAny( aPathSeq
);
857 pImpl
->m_xPathSettings
->setPropertyValue( sProp
, aValue
);
859 // then the writable path
860 aValue
= makeAny( ::rtl::OUString( _rWritablePath
) );
862 sProp
+= POSTFIX_WRITABLE
;
863 pImpl
->m_xPathSettings
->setPropertyValue( sProp
, aValue
);
866 catch( const Exception
& )
868 OSL_ENSURE( sal_False
, "SvxPathTabPage::SetPathList(): caught an exception!" );