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_cui.hxx"
31 // include ---------------------------------------------------------------
33 #include <svx/svxdlg.hxx>
34 #include <tools/shl.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <sfx2/filedlghelper.hxx>
37 #include <sfx2/app.hxx>
38 #include <svl/aeitem.hxx>
39 #include <svtools/svtabbx.hxx>
40 #include <svtools/filedlg.hxx>
41 #include <tools/config.hxx>
42 #include <tools/urlobj.hxx>
43 #include <vcl/svapp.hxx>
44 #include <unotools/defaultoptions.hxx>
45 #include <unotools/localfilehelper.hxx>
46 #include <unotools/pathoptions.hxx>
47 #include <unotools/moduleoptions.hxx>
48 #include <unotools/viewoptions.hxx>
50 #define _SVX_OPTPATH_CXX
52 #include "optpath.hxx"
53 #include <dialmgr.hxx>
54 #include "optpath.hrc"
57 #include <comphelper/processfactory.hxx>
58 #include <comphelper/configurationhelper.hxx>
59 #include <com/sun/star/uno/Exception.hpp>
60 #include <com/sun/star/beans/XPropertySet.hpp>
61 #include <com/sun/star/beans/PropertyAttribute.hpp>
62 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
63 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
64 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
65 #include "optHeaderTabListbox.hxx"
66 #include <readonlyimage.hxx>
67 #include <vcl/help.hxx>
69 using namespace ::com::sun::star::beans
;
70 using namespace ::com::sun::star::lang
;
71 using namespace ::com::sun::star::ui::dialogs
;
72 using namespace ::com::sun::star::uno
;
75 // define ----------------------------------------------------------------
78 #define TAB_WIDTH_MIN 10
79 #define TAB_WIDTH2 1000
83 #define POSTFIX_INTERNAL String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_internal" ) )
84 #define POSTFIX_USER String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_user" ) )
85 #define POSTFIX_WRITABLE String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_writable" ) )
86 #define POSTFIX_READONLY String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_readonly" ) )
87 #define VAR_ONE String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "%1" ) )
88 #define IODLG_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Save"))
90 // struct OptPath_Impl ---------------------------------------------------
94 SvtDefaultOptions m_aDefOpt
;
97 String m_sMultiPathDlg
;
98 Reference
< XPropertySet
> m_xPathSettings
;
100 OptPath_Impl(const ResId
& rLockRes
, const ResId
& rLockResHC
) :
101 m_aLockImage(rLockRes
),
102 m_aLockImageHC(rLockResHC
){}
105 // struct PathUserData_Impl ----------------------------------------------
107 struct PathUserData_Impl
112 String sWritablePath
;
114 PathUserData_Impl( sal_uInt16 nId
) :
115 nRealId( nId
), eState( SFX_ITEM_UNKNOWN
) {}
118 struct Handle2CfgNameMapping_Impl
120 sal_uInt16 m_nHandle
;
121 const char* m_pCfgName
;
124 static Handle2CfgNameMapping_Impl __READONLY_DATA Hdl2CfgMap_Impl
[] =
126 { SvtPathOptions::PATH_AUTOCORRECT
, "AutoCorrect" },
127 { SvtPathOptions::PATH_AUTOTEXT
, "AutoText" },
128 { SvtPathOptions::PATH_BACKUP
, "Backup" },
129 { SvtPathOptions::PATH_GALLERY
, "Gallery" },
130 { SvtPathOptions::PATH_GRAPHIC
, "Graphic" },
131 { SvtPathOptions::PATH_TEMP
, "Temp" },
132 { SvtPathOptions::PATH_TEMPLATE
, "Template" },
133 { SvtPathOptions::PATH_WORK
, "Work" },
134 #if OSL_DEBUG_LEVEL > 1
135 { SvtPathOptions::PATH_LINGUISTIC
, "Linguistic" },
136 { SvtPathOptions::PATH_DICTIONARY
, "Dictionary" },
141 static String
getCfgName_Impl( sal_uInt16 _nHandle
)
144 sal_uInt16 nIndex
= 0;
145 while ( Hdl2CfgMap_Impl
[ nIndex
].m_nHandle
!= USHRT_MAX
)
147 if ( Hdl2CfgMap_Impl
[ nIndex
].m_nHandle
== _nHandle
)
150 sCfgName
= String::CreateFromAscii( Hdl2CfgMap_Impl
[ nIndex
].m_pCfgName
);
159 #define MULTIPATH_DELIMITER ';'
161 String
Convert_Impl( const String
& rValue
)
163 char cDelim
= MULTIPATH_DELIMITER
;
164 sal_uInt16 nCount
= rValue
.GetTokenCount( cDelim
);
166 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
168 String aValue
= rValue
.GetToken( i
, cDelim
);
169 INetURLObject
aObj( aValue
);
170 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
171 aReturn
+= String(aObj
.PathToFileName());
172 else if ( ::utl::LocalFileHelper::IsFileContent( aValue
) )
173 aReturn
+= String(aObj
.GetURLPath( INetURLObject::DECODE_WITH_CHARSET
));
175 aReturn
+= MULTIPATH_DELIMITER
;
181 // class SvxControlFocusHelper ---------------------------------------------
183 long SvxControlFocusHelper::Notify( NotifyEvent
& rNEvt
)
185 long nRet
= Control::Notify( rNEvt
);
187 if ( m_pFocusCtrl
&& rNEvt
.GetWindow() != m_pFocusCtrl
&& rNEvt
.GetType() == EVENT_GETFOCUS
)
188 m_pFocusCtrl
->GrabFocus();
192 // functions -------------------------------------------------------------
194 sal_Bool
IsMultiPath_Impl( const sal_uInt16 nIndex
)
196 #if OSL_DEBUG_LEVEL > 1
197 return ( SvtPathOptions::PATH_AUTOCORRECT
== nIndex
||
198 SvtPathOptions::PATH_AUTOTEXT
== nIndex
||
199 SvtPathOptions::PATH_BASIC
== nIndex
||
200 SvtPathOptions::PATH_GALLERY
== nIndex
||
201 SvtPathOptions::PATH_TEMPLATE
== nIndex
);
203 return ( SvtPathOptions::PATH_AUTOCORRECT
== nIndex
||
204 SvtPathOptions::PATH_AUTOTEXT
== nIndex
||
205 SvtPathOptions::PATH_BASIC
== nIndex
||
206 SvtPathOptions::PATH_GALLERY
== nIndex
||
207 SvtPathOptions::PATH_TEMPLATE
== nIndex
||
208 SvtPathOptions::PATH_LINGUISTIC
== nIndex
||
209 SvtPathOptions::PATH_DICTIONARY
== nIndex
);
213 // class SvxPathTabPage --------------------------------------------------
215 SvxPathTabPage::SvxPathTabPage( Window
* pParent
, const SfxItemSet
& rSet
) :
217 SfxTabPage( pParent
, CUI_RES( RID_SFXPAGE_PATH
), rSet
),
219 aStdBox ( this, CUI_RES( GB_STD
) ),
220 aTypeText ( this, CUI_RES( FT_TYPE
) ),
221 aPathText ( this, CUI_RES( FT_PATH
) ),
222 aPathCtrl ( this, CUI_RES( LB_PATH
) ),
223 aStandardBtn ( this, CUI_RES( BTN_STANDARD
) ),
224 aPathBtn ( this, CUI_RES( BTN_PATH
) ),
227 pImpl ( new OptPath_Impl( CUI_RES(IMG_LOCK
), CUI_RES(IMG_LOCK_HC
) ) ),
228 xDialogListener ( new ::svt::DialogClosedListener() )
231 pImpl
->m_sMultiPathDlg
= String( CUI_RES( STR_MULTIPATHDLG
) );
232 aStandardBtn
.SetClickHdl( LINK( this, SvxPathTabPage
, StandardHdl_Impl
) );
233 Link aLink
= LINK( this, SvxPathTabPage
, PathHdl_Impl
);
234 aPathBtn
.SetClickHdl( aLink
);
235 Size aBoxSize
= aPathCtrl
.GetOutputSizePixel();
236 pHeaderBar
= new HeaderBar( &aPathCtrl
, WB_BUTTONSTYLE
| WB_BOTTOMBORDER
);
237 pHeaderBar
->SetPosSizePixel( Point( 0, 0 ), Size( aBoxSize
.Width(), 16 ) );
238 pHeaderBar
->SetSelectHdl( LINK( this, SvxPathTabPage
, HeaderSelect_Impl
) );
239 pHeaderBar
->SetEndDragHdl( LINK( this, SvxPathTabPage
, HeaderEndDrag_Impl
) );
241 aSz
.Width() = TAB_WIDTH1
;
242 pHeaderBar
->InsertItem( ITEMID_TYPE
, aTypeText
.GetText(),
243 LogicToPixel( aSz
, MapMode( MAP_APPFONT
) ).Width(),
244 HIB_LEFT
| HIB_VCENTER
| HIB_CLICKABLE
| HIB_UPARROW
);
245 aSz
.Width() = TAB_WIDTH2
;
246 pHeaderBar
->InsertItem( ITEMID_PATH
, aPathText
.GetText(),
247 LogicToPixel( aSz
, MapMode( MAP_APPFONT
) ).Width(),
248 HIB_LEFT
| HIB_VCENTER
);
250 static long nTabs
[] = {3, 0, TAB_WIDTH1
, TAB_WIDTH1
+ TAB_WIDTH2
};
251 Size aHeadSize
= pHeaderBar
->GetSizePixel();
253 WinBits nBits
= WB_SORT
| WB_HSCROLL
| WB_CLIPCHILDREN
| WB_TABSTOP
;
254 pPathBox
= new svx::OptHeaderTabListBox( &aPathCtrl
, nBits
);
255 aPathCtrl
.SetFocusControl( pPathBox
);
256 pPathBox
->SetDoubleClickHdl( aLink
);
257 pPathBox
->SetSelectHdl( LINK( this, SvxPathTabPage
, PathSelect_Impl
) );
258 pPathBox
->SetSelectionMode( MULTIPLE_SELECTION
);
259 pPathBox
->SetPosSizePixel( Point( 0, aHeadSize
.Height() ),
260 Size( aBoxSize
.Width(), aBoxSize
.Height() - aHeadSize
.Height() ) );
261 pPathBox
->SetTabs( &nTabs
[0], MAP_APPFONT
);
262 pPathBox
->InitHeaderBar( pHeaderBar
);
263 pPathBox
->SetHighlightRange();
264 pPathBox
->SetHelpId( HID_OPTPATH_CTL_PATH
);
265 pHeaderBar
->SetHelpId( HID_OPTPATH_HEADERBAR
);
271 xDialogListener
->SetDialogClosedLink( LINK( this, SvxPathTabPage
, DialogClosedHdl
) );
274 // -----------------------------------------------------------------------
276 SvxPathTabPage::~SvxPathTabPage()
278 // #110603# do not grab focus to a destroyed window !!!
279 aPathCtrl
.SetFocusControl( NULL
);
282 for ( sal_uInt16 i
= 0; i
< pPathBox
->GetEntryCount(); ++i
)
283 delete (PathUserData_Impl
*)pPathBox
->GetEntry(i
)->GetUserData();
289 // -----------------------------------------------------------------------
291 SfxTabPage
* SvxPathTabPage::Create( Window
* pParent
,
292 const SfxItemSet
& rAttrSet
)
294 return ( new SvxPathTabPage( pParent
, rAttrSet
) );
297 // -----------------------------------------------------------------------
299 sal_Bool
SvxPathTabPage::FillItemSet( SfxItemSet
& )
301 SvtPathOptions aPathOpt
;
302 for ( sal_uInt16 i
= 0; i
< pPathBox
->GetEntryCount(); ++i
)
304 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pPathBox
->GetEntry(i
)->GetUserData();
305 sal_uInt16 nRealId
= pPathImpl
->nRealId
;
306 if ( pPathImpl
->eState
== SFX_ITEM_SET
)
307 SetPathList( nRealId
, pPathImpl
->sUserPath
, pPathImpl
->sWritablePath
);
312 // -----------------------------------------------------------------------
314 void SvxPathTabPage::Reset( const SfxItemSet
& )
317 SvtPathOptions aPathOpt
; //! deprecated
319 for( sal_uInt16 i
= 0; i
<= (sal_uInt16
)SvtPathOptions::PATH_WORK
; ++i
)
321 // only writer uses autotext
322 if ( i
== SvtPathOptions::PATH_AUTOTEXT
323 && !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SWRITER
) )
328 case SvtPathOptions::PATH_AUTOCORRECT
:
329 case SvtPathOptions::PATH_AUTOTEXT
:
330 case SvtPathOptions::PATH_BACKUP
:
331 case SvtPathOptions::PATH_GALLERY
:
332 case SvtPathOptions::PATH_GRAPHIC
:
333 case SvtPathOptions::PATH_TEMP
:
334 case SvtPathOptions::PATH_TEMPLATE
:
335 #if OSL_DEBUG_LEVEL > 1
336 case SvtPathOptions::PATH_LINGUISTIC
:
337 case SvtPathOptions::PATH_DICTIONARY
:
339 case SvtPathOptions::PATH_WORK
:
341 String
aStr( CUI_RES( RID_SVXSTR_PATH_NAME_START
+ i
) );
342 String sInternal
, sUser
, sWritable
;
343 sal_Bool bReadOnly
= sal_False
;
344 GetPathList( i
, sInternal
, sUser
, sWritable
, bReadOnly
);
345 String sTmpPath
= sUser
;
346 if ( sTmpPath
.Len() > 0 && sWritable
.Len() > 0 )
347 sTmpPath
+= MULTIPATH_DELIMITER
;
348 sTmpPath
+= sWritable
;
349 String
aValue( sTmpPath
);
351 aStr
+= Convert_Impl( aValue
);
352 SvLBoxEntry
* pEntry
= pPathBox
->InsertEntry( aStr
);
355 pPathBox
->SetCollapsedEntryBmp( pEntry
, pImpl
->m_aLockImage
, BMP_COLOR_NORMAL
);
356 pPathBox
->SetCollapsedEntryBmp( pEntry
, pImpl
->m_aLockImageHC
, BMP_COLOR_HIGHCONTRAST
);
358 PathUserData_Impl
* pPathImpl
= new PathUserData_Impl(i
);
359 pPathImpl
->sUserPath
= sUser
;
360 pPathImpl
->sWritablePath
= sWritable
;
361 pEntry
->SetUserData( pPathImpl
);
366 String aUserData
= GetUserData();
367 if ( aUserData
.Len() )
369 // Spaltenbreite restaurieren
370 pHeaderBar
->SetItemSize( ITEMID_TYPE
, aUserData
.GetToken(0).ToInt32() );
371 HeaderEndDrag_Impl( NULL
);
372 // Sortierrichtung restaurieren
373 sal_Bool bUp
= (sal_Bool
)(sal_uInt16
)aUserData
.GetToken(1).ToInt32();
374 HeaderBarItemBits nBits
= pHeaderBar
->GetItemBits(ITEMID_TYPE
);
378 nBits
&= ~HIB_UPARROW
;
379 nBits
|= HIB_DOWNARROW
;
383 nBits
&= ~HIB_DOWNARROW
;
384 nBits
|= HIB_UPARROW
;
386 pHeaderBar
->SetItemBits( ITEMID_TYPE
, nBits
);
387 HeaderSelect_Impl( NULL
);
389 PathSelect_Impl( NULL
);
392 // -----------------------------------------------------------------------
394 void SvxPathTabPage::FillUserData()
396 String aUserData
= String::CreateFromInt32( pHeaderBar
->GetItemSize( ITEMID_TYPE
) );
398 HeaderBarItemBits nBits
= pHeaderBar
->GetItemBits( ITEMID_TYPE
);
399 sal_Bool bUp
= ( ( nBits
& HIB_UPARROW
) == HIB_UPARROW
);
400 aUserData
+= bUp
? '1' : '0';
401 SetUserData( aUserData
);
404 // -----------------------------------------------------------------------
406 IMPL_LINK( SvxPathTabPage
, PathSelect_Impl
, svx::OptHeaderTabListBox
*, EMPTYARG
)
413 sal_uInt16 nSelCount
= 0;
414 SvLBoxEntry
* pEntry
= pPathBox
->FirstSelected();
416 //the entry image indicates whether the path is write protected
419 aEntryImage
= pPathBox
->GetCollapsedEntryBmp( pEntry
);
420 sal_Bool bEnable
= !aEntryImage
;
421 while ( pEntry
&& ( nSelCount
< 2 ) )
424 pEntry
= pPathBox
->NextSelected( pEntry
);
427 aPathBtn
.Enable( 1 == nSelCount
&& bEnable
);
428 aStandardBtn
.Enable( nSelCount
> 0 && bEnable
);
432 // -----------------------------------------------------------------------
434 IMPL_LINK( SvxPathTabPage
, StandardHdl_Impl
, PushButton
*, EMPTYARG
)
436 SvLBoxEntry
* pEntry
= pPathBox
->FirstSelected();
439 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
440 String aOldPath
= pImpl
->m_aDefOpt
.GetDefaultPath( pPathImpl
->nRealId
);
442 if ( aOldPath
.Len() )
444 String sInternal
, sUser
, sWritable
, sTemp
;
445 sal_Bool bReadOnly
= sal_False
;
446 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
449 sal_uInt16 nOldCount
= aOldPath
.GetTokenCount( MULTIPATH_DELIMITER
);
450 sal_uInt16 nIntCount
= sInternal
.GetTokenCount( MULTIPATH_DELIMITER
);
451 for ( i
= 0; i
< nOldCount
; ++i
)
454 String sOnePath
= aOldPath
.GetToken( i
, MULTIPATH_DELIMITER
);
455 for ( sal_uInt16 j
= 0; !bFound
&& j
< nIntCount
; ++j
)
457 if ( sInternal
.GetToken( i
, MULTIPATH_DELIMITER
) == sOnePath
)
462 if ( sTemp
.Len() > 0 )
463 sTemp
+= MULTIPATH_DELIMITER
;
468 String sUserPath
, sWritablePath
;
469 nOldCount
= sTemp
.GetTokenCount( MULTIPATH_DELIMITER
);
470 for ( i
= 0; nOldCount
> 0 && i
< nOldCount
- 1; ++i
)
472 if ( sUserPath
.Len() > 0 )
473 sUserPath
+= MULTIPATH_DELIMITER
;
474 sUserPath
+= sTemp
.GetToken( i
, MULTIPATH_DELIMITER
);
476 sWritablePath
= sTemp
.GetToken( nOldCount
- 1, MULTIPATH_DELIMITER
);
478 pPathBox
->SetEntryText( Convert_Impl( sTemp
), pEntry
, 1 );
479 pPathImpl
->eState
= SFX_ITEM_SET
;
480 pPathImpl
->sUserPath
= sUserPath
;
481 pPathImpl
->sWritablePath
= sWritablePath
;
483 pEntry
= pPathBox
->NextSelected( pEntry
);
488 // -----------------------------------------------------------------------
490 void SvxPathTabPage::ChangeCurrentEntry( const String
& _rFolder
)
492 SvLBoxEntry
* pEntry
= pPathBox
->GetCurEntry();
495 DBG_ERRORFILE( "SvxPathTabPage::ChangeCurrentEntry(): no entry" );
499 String sInternal
, sUser
, sWritable
;
500 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
501 sal_Bool bReadOnly
= sal_False
;
502 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
503 sUser
= pPathImpl
->sUserPath
;
504 sWritable
= pPathImpl
->sWritablePath
;
505 sal_uInt16 nPos
= pPathImpl
->nRealId
;
507 // old path is an URL?
508 INetURLObject
aObj( sWritable
);
509 FASTBOOL bURL
= ( aObj
.GetProtocol() != INET_PROT_NOT_VALID
);
510 rtl::OUString
aPathStr( _rFolder
);
511 INetURLObject
aNewObj( aPathStr
);
512 aNewObj
.removeFinalSlash();
514 // then the new path also an URL else system path
515 String sNewPathStr
= bURL
? aPathStr
: aNewObj
.getFSysPath( INetURLObject::FSYS_DETECT
);
519 // Unix is case sensitive
520 ( sNewPathStr
!= sWritable
);
522 ( sNewPathStr
.CompareIgnoreCaseToAscii( sWritable
) != COMPARE_EQUAL
);
527 pPathBox
->SetEntryText( Convert_Impl( sNewPathStr
), pEntry
, 1 );
528 nPos
= (sal_uInt16
)pPathBox
->GetModel()->GetAbsPos( pEntry
);
529 pPathImpl
= (PathUserData_Impl
*)pPathBox
->GetEntry(nPos
)->GetUserData();
530 pPathImpl
->eState
= SFX_ITEM_SET
;
531 pPathImpl
->sWritablePath
= sNewPathStr
;
532 if ( SvtPathOptions::PATH_WORK
== pPathImpl
->nRealId
)
534 // Remove view options entry so the new work path
535 // will be used for the next open dialog.
536 SvtViewOptions
aDlgOpt( E_DIALOG
, IODLG_CONFIGNAME
);
538 // Reset also last used dir in the sfx application instance
539 SfxApplication
*pSfxApp
= SFX_APP();
540 pSfxApp
->ResetLastDir();
542 // Set configuration flag to notify file picker that it's necessary
543 // to take over the path provided.
544 Reference
< XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
545 ::comphelper::ConfigurationHelper::writeDirectKey(xFactory
,
546 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Common/")),
547 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Path/Info")),
548 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WorkPathChanged")),
549 ::com::sun::star::uno::makeAny(true),
550 ::comphelper::ConfigurationHelper::E_STANDARD
);
555 // -----------------------------------------------------------------------
557 IMPL_LINK( SvxPathTabPage
, PathHdl_Impl
, PushButton
*, EMPTYARG
)
559 SvLBoxEntry
* pEntry
= pPathBox
->GetCurEntry();
560 sal_uInt16 nPos
= ( pEntry
!= NULL
) ? ( (PathUserData_Impl
*)pEntry
->GetUserData() )->nRealId
: 0;
561 String sInternal
, sUser
, sWritable
;
564 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
565 sal_Bool bReadOnly
= sal_False
;
566 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
567 sUser
= pPathImpl
->sUserPath
;
568 sWritable
= pPathImpl
->sWritablePath
;
571 if(pEntry
&& !(!((OptHeaderTabListBox
*)pPathBox
)->GetCollapsedEntryBmp(pEntry
)))
574 if ( IsMultiPath_Impl( nPos
) )
576 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
579 AbstractSvxMultiPathDialog
* pMultiDlg
=
580 pFact
->CreateSvxMultiPathDialog( this );
581 DBG_ASSERT( pMultiDlg
, "Dialogdiet fail!" );
582 pMultiDlg
->EnableRadioButtonMode();
584 String
sPath( sUser
);
585 if ( sPath
.Len() > 0 )
586 sPath
+= MULTIPATH_DELIMITER
;
588 pMultiDlg
->SetPath( sPath
);
590 String sPathName
= pPathBox
->GetEntryText( pEntry
, 0 );
591 String
sNewTitle( pImpl
->m_sMultiPathDlg
);
592 sNewTitle
.SearchAndReplace( VAR_ONE
, sPathName
);
593 pMultiDlg
->SetTitle( sNewTitle
);
595 if ( pMultiDlg
->Execute() == RET_OK
&& pEntry
)
600 String sNewPath
= pMultiDlg
->GetPath();
601 char cDelim
= MULTIPATH_DELIMITER
;
602 sal_uInt16 nCount
= sNewPath
.GetTokenCount( cDelim
);
606 for ( ; i
< nCount
- 1; ++i
)
608 if ( sUser
.Len() > 0 )
610 sUser
+= sNewPath
.GetToken( i
, cDelim
);
612 if ( sFullPath
.Len() > 0 )
615 sWritable
+= sNewPath
.GetToken( i
, cDelim
);
616 if ( sFullPath
.Len() > 0 )
618 sFullPath
+= sWritable
;
621 pPathBox
->SetEntryText( Convert_Impl( sFullPath
), pEntry
, 1 );
622 // save modified flag
623 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
624 pPathImpl
->eState
= SFX_ITEM_SET
;
625 pPathImpl
->sUserPath
= sUser
;
626 pPathImpl
->sWritablePath
= sWritable
;
635 rtl::OUString
aService( RTL_CONSTASCII_USTRINGPARAM( FOLDER_PICKER_SERVICE_NAME
) );
636 Reference
< XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
637 xFolderPicker
= ::com::sun::star::uno::Reference
< XFolderPicker
>(
638 xFactory
->createInstance( aService
), UNO_QUERY
);
640 INetURLObject
aURL( sWritable
, INET_PROT_FILE
);
641 xFolderPicker
->setDisplayDirectory( aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
643 Reference
< XAsynchronousExecutableDialog
> xAsyncDlg( xFolderPicker
, UNO_QUERY
);
644 if ( xAsyncDlg
.is() )
645 xAsyncDlg
->startExecuteModal( xDialogListener
.get() );
648 short nRet
= xFolderPicker
->execute();
649 if ( ExecutableDialogResults::OK
!= nRet
)
652 String
sFolder( xFolderPicker
->getDirectory() );
653 ChangeCurrentEntry( sFolder
);
658 DBG_ERRORFILE( "SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
664 // -----------------------------------------------------------------------
666 IMPL_LINK( SvxPathTabPage
, HeaderSelect_Impl
, HeaderBar
*, pBar
)
668 if ( pBar
&& pBar
->GetCurItemId() != ITEMID_TYPE
)
671 HeaderBarItemBits nBits
= pHeaderBar
->GetItemBits(ITEMID_TYPE
);
672 sal_Bool bUp
= ( ( nBits
& HIB_UPARROW
) == HIB_UPARROW
);
673 SvSortMode eMode
= SortAscending
;
677 nBits
&= ~HIB_UPARROW
;
678 nBits
|= HIB_DOWNARROW
;
679 eMode
= SortDescending
;
683 nBits
&= ~HIB_DOWNARROW
;
684 nBits
|= HIB_UPARROW
;
686 pHeaderBar
->SetItemBits( ITEMID_TYPE
, nBits
);
687 SvTreeList
* pModel
= pPathBox
->GetModel();
688 pModel
->SetSortMode( eMode
);
693 // -----------------------------------------------------------------------
695 IMPL_LINK( SvxPathTabPage
, HeaderEndDrag_Impl
, HeaderBar
*, pBar
)
697 if ( pBar
&& !pBar
->GetCurItemId() )
700 if ( !pHeaderBar
->IsItemMode() )
703 sal_uInt16 nTabs
= pHeaderBar
->GetItemCount();
705 long nWidth
= pHeaderBar
->GetItemSize(ITEMID_TYPE
);
706 long nBarWidth
= pHeaderBar
->GetSizePixel().Width();
708 if(nWidth
< TAB_WIDTH_MIN
)
709 pHeaderBar
->SetItemSize( ITEMID_TYPE
, TAB_WIDTH_MIN
);
710 else if ( ( nBarWidth
- nWidth
) < TAB_WIDTH_MIN
)
711 pHeaderBar
->SetItemSize( ITEMID_TYPE
, nBarWidth
- TAB_WIDTH_MIN
);
713 for ( sal_uInt16 i
= 1; i
<= nTabs
; ++i
)
715 long _nWidth
= pHeaderBar
->GetItemSize(i
);
716 aSz
.Width() = _nWidth
+ nTmpSz
;
718 pPathBox
->SetTab( i
, PixelToLogic( aSz
, MapMode(MAP_APPFONT
) ).Width(), MAP_APPFONT
);
724 // -----------------------------------------------------------------------
726 IMPL_LINK( SvxPathTabPage
, DialogClosedHdl
, DialogClosedEvent
*, pEvt
)
728 if ( RET_OK
== pEvt
->DialogResult
)
730 DBG_ASSERT( xFolderPicker
.is() == sal_True
, "SvxPathTabPage::DialogClosedHdl(): no folder picker" );
732 String sURL
= String( xFolderPicker
->getDirectory() );
733 ChangeCurrentEntry( sURL
);
738 // -----------------------------------------------------------------------
740 void SvxPathTabPage::GetPathList(
741 sal_uInt16 _nPathHandle
, String
& _rInternalPath
,
742 String
& _rUserPath
, String
& _rWritablePath
, sal_Bool
& _rReadOnly
)
744 String sCfgName
= getCfgName_Impl( _nPathHandle
);
746 // load PathSettings service if necessary
747 if ( !pImpl
->m_xPathSettings
.is() )
749 Reference
< XMultiServiceFactory
> xSMgr
= comphelper::getProcessServiceFactory();
750 pImpl
->m_xPathSettings
= Reference
< XPropertySet
>( xSMgr
->createInstance(
751 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
752 "com.sun.star.util.PathSettings") ) ), UNO_QUERY
);
757 if ( pImpl
->m_xPathSettings
.is() )
759 // load internal paths
760 String
sProp( sCfgName
);
762 sProp
+= POSTFIX_INTERNAL
;
763 Any aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
764 Sequence
< ::rtl::OUString
> aPathSeq
;
765 if ( aAny
>>= aPathSeq
)
767 long i
, nCount
= aPathSeq
.getLength();
768 const ::rtl::OUString
* pPaths
= aPathSeq
.getConstArray();
770 for ( i
= 0; i
< nCount
; ++i
)
772 if ( _rInternalPath
.Len() > 0 )
773 _rInternalPath
+= ';';
774 _rInternalPath
+= String( pPaths
[i
] );
779 sProp
+= POSTFIX_USER
;
780 aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
781 if ( aAny
>>= aPathSeq
)
783 long i
, nCount
= aPathSeq
.getLength();
784 const ::rtl::OUString
* pPaths
= aPathSeq
.getConstArray();
786 for ( i
= 0; i
< nCount
; ++i
)
788 if ( _rUserPath
.Len() > 0 )
790 _rUserPath
+= String( pPaths
[i
] );
793 // then the writable path
795 sProp
+= POSTFIX_WRITABLE
;
796 aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
797 ::rtl::OUString sWritablePath
;
798 if ( aAny
>>= sWritablePath
)
799 _rWritablePath
= String( sWritablePath
);
801 // and the readonly flag
803 Reference
< XPropertySetInfo
> xInfo
= pImpl
->m_xPathSettings
->getPropertySetInfo();
804 Property aProp
= xInfo
->getPropertyByName( sProp
);
805 _rReadOnly
= ( ( aProp
.Attributes
& PropertyAttribute::READONLY
) == PropertyAttribute::READONLY
);
808 catch( const Exception
& )
810 OSL_ENSURE( sal_False
, "SvxPathTabPage::GetPathList(): caught an exception!" );
814 // -----------------------------------------------------------------------
816 void SvxPathTabPage::SetPathList(
817 sal_uInt16 _nPathHandle
, const String
& _rUserPath
, const String
& _rWritablePath
)
819 String sCfgName
= getCfgName_Impl( _nPathHandle
);
821 // load PathSettings service if necessary
822 if ( !pImpl
->m_xPathSettings
.is() )
824 Reference
< XMultiServiceFactory
> xSMgr
= comphelper::getProcessServiceFactory();
825 pImpl
->m_xPathSettings
= Reference
< XPropertySet
>( xSMgr
->createInstance(
826 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
827 "com.sun.star.util.PathSettings") ) ), UNO_QUERY
);
832 if ( pImpl
->m_xPathSettings
.is() )
835 char cDelim
= MULTIPATH_DELIMITER
;
836 sal_uInt16 nCount
= _rUserPath
.GetTokenCount( cDelim
);
837 Sequence
< ::rtl::OUString
> aPathSeq( nCount
);
838 ::rtl::OUString
* pArray
= aPathSeq
.getArray();
839 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
840 pArray
[i
] = ::rtl::OUString( _rUserPath
.GetToken( i
, cDelim
) );
841 String
sProp( sCfgName
);
842 sProp
+= POSTFIX_USER
;
843 Any aValue
= makeAny( aPathSeq
);
844 pImpl
->m_xPathSettings
->setPropertyValue( sProp
, aValue
);
846 // then the writable path
847 aValue
= makeAny( ::rtl::OUString( _rWritablePath
) );
849 sProp
+= POSTFIX_WRITABLE
;
850 pImpl
->m_xPathSettings
->setPropertyValue( sProp
, aValue
);
853 catch( const Exception
& )
855 OSL_ENSURE( sal_False
, "SvxPathTabPage::SetPathList(): caught an exception!" );