xref: /aoo42x/main/cui/source/options/optpath.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cui.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // include ---------------------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <svx/svxdlg.hxx>
34*cdf0e10cSrcweir #include <tools/shl.hxx>
35*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
36*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
37*cdf0e10cSrcweir #include <sfx2/app.hxx>
38*cdf0e10cSrcweir #include <svl/aeitem.hxx>
39*cdf0e10cSrcweir #include <svtools/svtabbx.hxx>
40*cdf0e10cSrcweir #include <svtools/filedlg.hxx>
41*cdf0e10cSrcweir #include <tools/config.hxx>
42*cdf0e10cSrcweir #include <tools/urlobj.hxx>
43*cdf0e10cSrcweir #include <vcl/svapp.hxx>
44*cdf0e10cSrcweir #include <unotools/defaultoptions.hxx>
45*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
46*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
47*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
48*cdf0e10cSrcweir #include <unotools/viewoptions.hxx>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #define _SVX_OPTPATH_CXX
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #include "optpath.hxx"
53*cdf0e10cSrcweir #include <dialmgr.hxx>
54*cdf0e10cSrcweir #include "optpath.hrc"
55*cdf0e10cSrcweir #include <cuires.hrc>
56*cdf0e10cSrcweir #include "helpid.hrc"
57*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
58*cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
59*cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
65*cdf0e10cSrcweir #include "optHeaderTabListbox.hxx"
66*cdf0e10cSrcweir #include <readonlyimage.hxx>
67*cdf0e10cSrcweir #include <vcl/help.hxx>
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
70*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
71*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
72*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
73*cdf0e10cSrcweir using namespace svx;
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir // define ----------------------------------------------------------------
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir #define TAB_WIDTH1		80
78*cdf0e10cSrcweir #define TAB_WIDTH_MIN   10
79*cdf0e10cSrcweir #define TAB_WIDTH2		1000
80*cdf0e10cSrcweir #define ITEMID_TYPE       1
81*cdf0e10cSrcweir #define ITEMID_PATH       2
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir #define POSTFIX_INTERNAL    String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_internal" ) )
84*cdf0e10cSrcweir #define POSTFIX_USER        String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_user" ) )
85*cdf0e10cSrcweir #define POSTFIX_WRITABLE    String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_writable" ) )
86*cdf0e10cSrcweir #define POSTFIX_READONLY    String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_readonly" ) )
87*cdf0e10cSrcweir #define VAR_ONE             String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "%1" ) )
88*cdf0e10cSrcweir #define IODLG_CONFIGNAME	String(DEFINE_CONST_UNICODE("FilePicker_Save"))
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir // struct OptPath_Impl ---------------------------------------------------
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir struct OptPath_Impl
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir     SvtDefaultOptions           m_aDefOpt;
95*cdf0e10cSrcweir     Image                       m_aLockImage;
96*cdf0e10cSrcweir     Image                       m_aLockImageHC;
97*cdf0e10cSrcweir     String                      m_sMultiPathDlg;
98*cdf0e10cSrcweir     Reference< XPropertySet >   m_xPathSettings;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     OptPath_Impl(const ResId& rLockRes, const ResId& rLockResHC) :
101*cdf0e10cSrcweir         m_aLockImage(rLockRes),
102*cdf0e10cSrcweir         m_aLockImageHC(rLockResHC){}
103*cdf0e10cSrcweir };
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir // struct PathUserData_Impl ----------------------------------------------
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir struct PathUserData_Impl
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     sal_uInt16          nRealId;
110*cdf0e10cSrcweir     SfxItemState    eState;
111*cdf0e10cSrcweir     String          sUserPath;
112*cdf0e10cSrcweir     String          sWritablePath;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     PathUserData_Impl( sal_uInt16 nId ) :
115*cdf0e10cSrcweir         nRealId( nId ), eState( SFX_ITEM_UNKNOWN ) {}
116*cdf0e10cSrcweir };
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir struct Handle2CfgNameMapping_Impl
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     sal_uInt16      m_nHandle;
121*cdf0e10cSrcweir     const char* m_pCfgName;
122*cdf0e10cSrcweir };
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir static Handle2CfgNameMapping_Impl __READONLY_DATA Hdl2CfgMap_Impl[] =
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     { SvtPathOptions::PATH_AUTOCORRECT, "AutoCorrect" },
127*cdf0e10cSrcweir     { SvtPathOptions::PATH_AUTOTEXT,    "AutoText" },
128*cdf0e10cSrcweir     { SvtPathOptions::PATH_BACKUP,      "Backup" },
129*cdf0e10cSrcweir     { SvtPathOptions::PATH_GALLERY,     "Gallery" },
130*cdf0e10cSrcweir     { SvtPathOptions::PATH_GRAPHIC,     "Graphic" },
131*cdf0e10cSrcweir     { SvtPathOptions::PATH_TEMP,        "Temp" },
132*cdf0e10cSrcweir     { SvtPathOptions::PATH_TEMPLATE,    "Template" },
133*cdf0e10cSrcweir     { SvtPathOptions::PATH_WORK,        "Work" },
134*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
135*cdf0e10cSrcweir     { SvtPathOptions::PATH_LINGUISTIC,        "Linguistic" },
136*cdf0e10cSrcweir     { SvtPathOptions::PATH_DICTIONARY,        "Dictionary" },
137*cdf0e10cSrcweir #endif
138*cdf0e10cSrcweir     { USHRT_MAX, NULL }
139*cdf0e10cSrcweir };
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir static String getCfgName_Impl( sal_uInt16 _nHandle )
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     String sCfgName;
144*cdf0e10cSrcweir     sal_uInt16 nIndex = 0;
145*cdf0e10cSrcweir     while ( Hdl2CfgMap_Impl[ nIndex ].m_nHandle != USHRT_MAX )
146*cdf0e10cSrcweir     {
147*cdf0e10cSrcweir         if ( Hdl2CfgMap_Impl[ nIndex ].m_nHandle == _nHandle )
148*cdf0e10cSrcweir         {
149*cdf0e10cSrcweir             // config name found
150*cdf0e10cSrcweir             sCfgName = String::CreateFromAscii( Hdl2CfgMap_Impl[ nIndex ].m_pCfgName );
151*cdf0e10cSrcweir             break;
152*cdf0e10cSrcweir         }
153*cdf0e10cSrcweir         ++nIndex;
154*cdf0e10cSrcweir     }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     return sCfgName;
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir #define MULTIPATH_DELIMITER     ';'
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir String Convert_Impl( const String& rValue )
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir 	char cDelim = MULTIPATH_DELIMITER;
164*cdf0e10cSrcweir     sal_uInt16 nCount = rValue.GetTokenCount( cDelim );
165*cdf0e10cSrcweir     String aReturn;
166*cdf0e10cSrcweir     for ( sal_uInt16 i=0; i<nCount ; ++i )
167*cdf0e10cSrcweir 	{
168*cdf0e10cSrcweir         String aValue = rValue.GetToken( i, cDelim );
169*cdf0e10cSrcweir         INetURLObject aObj( aValue );
170*cdf0e10cSrcweir         if ( aObj.GetProtocol() == INET_PROT_FILE )
171*cdf0e10cSrcweir             aReturn += String(aObj.PathToFileName());
172*cdf0e10cSrcweir         else if ( ::utl::LocalFileHelper::IsFileContent( aValue ) )
173*cdf0e10cSrcweir             aReturn += String(aObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ));
174*cdf0e10cSrcweir         if ( i+1 < nCount)
175*cdf0e10cSrcweir             aReturn += MULTIPATH_DELIMITER;
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     return aReturn;
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir // class SvxControlFocusHelper ---------------------------------------------
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir long SvxControlFocusHelper::Notify( NotifyEvent& rNEvt )
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir 	long nRet = Control::Notify( rNEvt );
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 	if ( m_pFocusCtrl && rNEvt.GetWindow() != m_pFocusCtrl && rNEvt.GetType() == EVENT_GETFOCUS )
188*cdf0e10cSrcweir 		m_pFocusCtrl->GrabFocus();
189*cdf0e10cSrcweir 	return nRet;
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir // functions -------------------------------------------------------------
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir sal_Bool IsMultiPath_Impl( const sal_uInt16 nIndex )
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
197*cdf0e10cSrcweir 	return ( SvtPathOptions::PATH_AUTOCORRECT == nIndex ||
198*cdf0e10cSrcweir 			 SvtPathOptions::PATH_AUTOTEXT == nIndex ||
199*cdf0e10cSrcweir 			 SvtPathOptions::PATH_BASIC == nIndex ||
200*cdf0e10cSrcweir 			 SvtPathOptions::PATH_GALLERY == nIndex ||
201*cdf0e10cSrcweir 			 SvtPathOptions::PATH_TEMPLATE == nIndex );
202*cdf0e10cSrcweir #else
203*cdf0e10cSrcweir     return ( SvtPathOptions::PATH_AUTOCORRECT == nIndex ||
204*cdf0e10cSrcweir              SvtPathOptions::PATH_AUTOTEXT == nIndex ||
205*cdf0e10cSrcweir              SvtPathOptions::PATH_BASIC == nIndex ||
206*cdf0e10cSrcweir              SvtPathOptions::PATH_GALLERY == nIndex ||
207*cdf0e10cSrcweir              SvtPathOptions::PATH_TEMPLATE == nIndex ||
208*cdf0e10cSrcweir              SvtPathOptions::PATH_LINGUISTIC == nIndex ||
209*cdf0e10cSrcweir              SvtPathOptions::PATH_DICTIONARY == nIndex  );
210*cdf0e10cSrcweir #endif
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir // class SvxPathTabPage --------------------------------------------------
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir SvxPathTabPage::SvxPathTabPage( Window* pParent, const SfxItemSet& rSet ) :
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 	SfxTabPage( pParent, CUI_RES( RID_SFXPAGE_PATH ), rSet ),
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 	aStdBox			( this, CUI_RES( GB_STD ) ),
220*cdf0e10cSrcweir 	aTypeText		( this, CUI_RES( FT_TYPE ) ),
221*cdf0e10cSrcweir 	aPathText		( this, CUI_RES( FT_PATH ) ),
222*cdf0e10cSrcweir 	aPathCtrl		( this, CUI_RES( LB_PATH ) ),
223*cdf0e10cSrcweir 	aStandardBtn	( this, CUI_RES( BTN_STANDARD ) ),
224*cdf0e10cSrcweir 	aPathBtn		( this, CUI_RES( BTN_PATH ) ),
225*cdf0e10cSrcweir 	pHeaderBar		( NULL ),
226*cdf0e10cSrcweir 	pPathBox		( NULL ),
227*cdf0e10cSrcweir     pImpl           ( new OptPath_Impl( CUI_RES(IMG_LOCK), CUI_RES(IMG_LOCK_HC) ) ),
228*cdf0e10cSrcweir     xDialogListener ( new ::svt::DialogClosedListener() )
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     pImpl->m_sMultiPathDlg = String( CUI_RES( STR_MULTIPATHDLG ) );
232*cdf0e10cSrcweir 	aStandardBtn.SetClickHdl( LINK( this, SvxPathTabPage, StandardHdl_Impl ) );
233*cdf0e10cSrcweir 	Link aLink = LINK( this, SvxPathTabPage, PathHdl_Impl );
234*cdf0e10cSrcweir 	aPathBtn.SetClickHdl( aLink );
235*cdf0e10cSrcweir 	Size aBoxSize = aPathCtrl.GetOutputSizePixel();
236*cdf0e10cSrcweir 	pHeaderBar = new HeaderBar( &aPathCtrl, WB_BUTTONSTYLE | WB_BOTTOMBORDER );
237*cdf0e10cSrcweir 	pHeaderBar->SetPosSizePixel( Point( 0, 0 ), Size( aBoxSize.Width(), 16 ) );
238*cdf0e10cSrcweir 	pHeaderBar->SetSelectHdl( LINK( this, SvxPathTabPage, HeaderSelect_Impl ) );
239*cdf0e10cSrcweir 	pHeaderBar->SetEndDragHdl( LINK( this, SvxPathTabPage, HeaderEndDrag_Impl ) );
240*cdf0e10cSrcweir 	Size aSz;
241*cdf0e10cSrcweir 	aSz.Width() = TAB_WIDTH1;
242*cdf0e10cSrcweir 	pHeaderBar->InsertItem( ITEMID_TYPE, aTypeText.GetText(),
243*cdf0e10cSrcweir 							LogicToPixel( aSz, MapMode( MAP_APPFONT ) ).Width(),
244*cdf0e10cSrcweir 							HIB_LEFT | HIB_VCENTER | HIB_CLICKABLE | HIB_UPARROW );
245*cdf0e10cSrcweir 	aSz.Width() = TAB_WIDTH2;
246*cdf0e10cSrcweir 	pHeaderBar->InsertItem( ITEMID_PATH, aPathText.GetText(),
247*cdf0e10cSrcweir 							LogicToPixel( aSz, MapMode( MAP_APPFONT ) ).Width(),
248*cdf0e10cSrcweir 							HIB_LEFT | HIB_VCENTER );
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 	static long nTabs[] = {3, 0, TAB_WIDTH1, TAB_WIDTH1 + TAB_WIDTH2 };
251*cdf0e10cSrcweir 	Size aHeadSize = pHeaderBar->GetSizePixel();
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir 	WinBits nBits = WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP;
254*cdf0e10cSrcweir 	pPathBox = new svx::OptHeaderTabListBox( &aPathCtrl, nBits );
255*cdf0e10cSrcweir 	aPathCtrl.SetFocusControl( pPathBox );
256*cdf0e10cSrcweir 	pPathBox->SetDoubleClickHdl( aLink );
257*cdf0e10cSrcweir 	pPathBox->SetSelectHdl( LINK( this, SvxPathTabPage, PathSelect_Impl ) );
258*cdf0e10cSrcweir 	pPathBox->SetSelectionMode( MULTIPLE_SELECTION );
259*cdf0e10cSrcweir 	pPathBox->SetPosSizePixel( Point( 0, aHeadSize.Height() ),
260*cdf0e10cSrcweir 							   Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) );
261*cdf0e10cSrcweir 	pPathBox->SetTabs( &nTabs[0], MAP_APPFONT );
262*cdf0e10cSrcweir 	pPathBox->InitHeaderBar( pHeaderBar );
263*cdf0e10cSrcweir 	pPathBox->SetHighlightRange();
264*cdf0e10cSrcweir 	pPathBox->SetHelpId( HID_OPTPATH_CTL_PATH );
265*cdf0e10cSrcweir 	pHeaderBar->SetHelpId( HID_OPTPATH_HEADERBAR );
266*cdf0e10cSrcweir 	pPathBox->Show();
267*cdf0e10cSrcweir 	pHeaderBar->Show();
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 	FreeResource();
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir     xDialogListener->SetDialogClosedLink( LINK( this, SvxPathTabPage, DialogClosedHdl ) );
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir // -----------------------------------------------------------------------
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir SvxPathTabPage::~SvxPathTabPage()
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir     // #110603# do not grab focus to a destroyed window !!!
279*cdf0e10cSrcweir     aPathCtrl.SetFocusControl( NULL );
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir 	pHeaderBar->Hide();
282*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < pPathBox->GetEntryCount(); ++i )
283*cdf0e10cSrcweir 		delete (PathUserData_Impl*)pPathBox->GetEntry(i)->GetUserData();
284*cdf0e10cSrcweir 	delete pPathBox;
285*cdf0e10cSrcweir 	delete pHeaderBar;
286*cdf0e10cSrcweir 	delete pImpl;
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir // -----------------------------------------------------------------------
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir SfxTabPage*	SvxPathTabPage::Create( Window* pParent,
292*cdf0e10cSrcweir 									const SfxItemSet& rAttrSet )
293*cdf0e10cSrcweir {
294*cdf0e10cSrcweir 	return ( new SvxPathTabPage( pParent, rAttrSet ) );
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir // -----------------------------------------------------------------------
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir sal_Bool SvxPathTabPage::FillItemSet( SfxItemSet& )
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir     SvtPathOptions aPathOpt;
302*cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < pPathBox->GetEntryCount(); ++i )
303*cdf0e10cSrcweir     {
304*cdf0e10cSrcweir 		PathUserData_Impl* pPathImpl = (PathUserData_Impl*)pPathBox->GetEntry(i)->GetUserData();
305*cdf0e10cSrcweir 		sal_uInt16 nRealId = pPathImpl->nRealId;
306*cdf0e10cSrcweir         if ( pPathImpl->eState == SFX_ITEM_SET )
307*cdf0e10cSrcweir             SetPathList( nRealId, pPathImpl->sUserPath, pPathImpl->sWritablePath );
308*cdf0e10cSrcweir     }
309*cdf0e10cSrcweir 	return sal_True;
310*cdf0e10cSrcweir }
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir // -----------------------------------------------------------------------
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir void SvxPathTabPage::Reset( const SfxItemSet& )
315*cdf0e10cSrcweir {
316*cdf0e10cSrcweir     pPathBox->Clear();
317*cdf0e10cSrcweir     SvtPathOptions aPathOpt; //! deprecated
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir     for( sal_uInt16 i = 0; i <= (sal_uInt16)SvtPathOptions::PATH_WORK; ++i )
320*cdf0e10cSrcweir     {
321*cdf0e10cSrcweir         // only writer uses autotext
322*cdf0e10cSrcweir         if ( i == SvtPathOptions::PATH_AUTOTEXT
323*cdf0e10cSrcweir             && !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
324*cdf0e10cSrcweir             continue;
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir         switch (i)
327*cdf0e10cSrcweir         {
328*cdf0e10cSrcweir             case SvtPathOptions::PATH_AUTOCORRECT:
329*cdf0e10cSrcweir             case SvtPathOptions::PATH_AUTOTEXT:
330*cdf0e10cSrcweir             case SvtPathOptions::PATH_BACKUP:
331*cdf0e10cSrcweir             case SvtPathOptions::PATH_GALLERY:
332*cdf0e10cSrcweir             case SvtPathOptions::PATH_GRAPHIC:
333*cdf0e10cSrcweir             case SvtPathOptions::PATH_TEMP:
334*cdf0e10cSrcweir             case SvtPathOptions::PATH_TEMPLATE:
335*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
336*cdf0e10cSrcweir             case SvtPathOptions::PATH_LINGUISTIC:
337*cdf0e10cSrcweir             case SvtPathOptions::PATH_DICTIONARY:
338*cdf0e10cSrcweir #endif
339*cdf0e10cSrcweir             case SvtPathOptions::PATH_WORK:
340*cdf0e10cSrcweir             {
341*cdf0e10cSrcweir                 String aStr( CUI_RES( RID_SVXSTR_PATH_NAME_START + i ) );
342*cdf0e10cSrcweir                 String sInternal, sUser, sWritable;
343*cdf0e10cSrcweir                 sal_Bool bReadOnly = sal_False;
344*cdf0e10cSrcweir                 GetPathList( i, sInternal, sUser, sWritable, bReadOnly );
345*cdf0e10cSrcweir                 String sTmpPath = sUser;
346*cdf0e10cSrcweir                 if ( sTmpPath.Len() > 0 && sWritable.Len() > 0 )
347*cdf0e10cSrcweir                     sTmpPath += MULTIPATH_DELIMITER;
348*cdf0e10cSrcweir                 sTmpPath += sWritable;
349*cdf0e10cSrcweir                 String aValue( sTmpPath );
350*cdf0e10cSrcweir                 aStr += '\t';
351*cdf0e10cSrcweir                 aStr += Convert_Impl( aValue );
352*cdf0e10cSrcweir                 SvLBoxEntry* pEntry = pPathBox->InsertEntry( aStr );
353*cdf0e10cSrcweir                 if ( bReadOnly )
354*cdf0e10cSrcweir                 {
355*cdf0e10cSrcweir                     pPathBox->SetCollapsedEntryBmp( pEntry, pImpl->m_aLockImage, BMP_COLOR_NORMAL );
356*cdf0e10cSrcweir                     pPathBox->SetCollapsedEntryBmp( pEntry, pImpl->m_aLockImageHC, BMP_COLOR_HIGHCONTRAST );
357*cdf0e10cSrcweir                 }
358*cdf0e10cSrcweir                 PathUserData_Impl* pPathImpl = new PathUserData_Impl(i);
359*cdf0e10cSrcweir                 pPathImpl->sUserPath = sUser;
360*cdf0e10cSrcweir                 pPathImpl->sWritablePath = sWritable;
361*cdf0e10cSrcweir                 pEntry->SetUserData( pPathImpl );
362*cdf0e10cSrcweir             }
363*cdf0e10cSrcweir         }
364*cdf0e10cSrcweir     }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir     String aUserData = GetUserData();
367*cdf0e10cSrcweir 	if ( aUserData.Len() )
368*cdf0e10cSrcweir 	{
369*cdf0e10cSrcweir 		// Spaltenbreite restaurieren
370*cdf0e10cSrcweir 		pHeaderBar->SetItemSize( ITEMID_TYPE, aUserData.GetToken(0).ToInt32() );
371*cdf0e10cSrcweir 		HeaderEndDrag_Impl( NULL );
372*cdf0e10cSrcweir 		// Sortierrichtung restaurieren
373*cdf0e10cSrcweir 		sal_Bool bUp = (sal_Bool)(sal_uInt16)aUserData.GetToken(1).ToInt32();
374*cdf0e10cSrcweir 		HeaderBarItemBits nBits	= pHeaderBar->GetItemBits(ITEMID_TYPE);
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 		if ( bUp )
377*cdf0e10cSrcweir 		{
378*cdf0e10cSrcweir 			nBits &= ~HIB_UPARROW;
379*cdf0e10cSrcweir 			nBits |= HIB_DOWNARROW;
380*cdf0e10cSrcweir 		}
381*cdf0e10cSrcweir 		else
382*cdf0e10cSrcweir 		{
383*cdf0e10cSrcweir 			nBits &= ~HIB_DOWNARROW;
384*cdf0e10cSrcweir 			nBits |= HIB_UPARROW;
385*cdf0e10cSrcweir 		}
386*cdf0e10cSrcweir 		pHeaderBar->SetItemBits( ITEMID_TYPE, nBits );
387*cdf0e10cSrcweir 		HeaderSelect_Impl( NULL );
388*cdf0e10cSrcweir 	}
389*cdf0e10cSrcweir 	PathSelect_Impl( NULL );
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir // -----------------------------------------------------------------------
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir void SvxPathTabPage::FillUserData()
395*cdf0e10cSrcweir {
396*cdf0e10cSrcweir 	String aUserData = String::CreateFromInt32( pHeaderBar->GetItemSize( ITEMID_TYPE ) );
397*cdf0e10cSrcweir 	aUserData += ';';
398*cdf0e10cSrcweir 	HeaderBarItemBits nBits	= pHeaderBar->GetItemBits( ITEMID_TYPE );
399*cdf0e10cSrcweir 	sal_Bool bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
400*cdf0e10cSrcweir 	aUserData += bUp ? '1' : '0';
401*cdf0e10cSrcweir 	SetUserData( aUserData );
402*cdf0e10cSrcweir }
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir // -----------------------------------------------------------------------
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir IMPL_LINK( SvxPathTabPage, PathSelect_Impl, svx::OptHeaderTabListBox *, EMPTYARG )
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir /*	[Beschreibung]
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir */
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir 	sal_uInt16 nSelCount = 0;
414*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pPathBox->FirstSelected();
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir     //the entry image indicates whether the path is write protected
417*cdf0e10cSrcweir     Image aEntryImage;
418*cdf0e10cSrcweir     if(pEntry)
419*cdf0e10cSrcweir         aEntryImage = pPathBox->GetCollapsedEntryBmp( pEntry );
420*cdf0e10cSrcweir     sal_Bool bEnable = !aEntryImage;
421*cdf0e10cSrcweir 	while ( pEntry && ( nSelCount < 2 ) )
422*cdf0e10cSrcweir 	{
423*cdf0e10cSrcweir 		nSelCount++;
424*cdf0e10cSrcweir 		pEntry = pPathBox->NextSelected( pEntry );
425*cdf0e10cSrcweir 	}
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir     aPathBtn.Enable( 1 == nSelCount && bEnable);
428*cdf0e10cSrcweir     aStandardBtn.Enable( nSelCount > 0 && bEnable);
429*cdf0e10cSrcweir 	return 0;
430*cdf0e10cSrcweir }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir // -----------------------------------------------------------------------
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir IMPL_LINK( SvxPathTabPage, StandardHdl_Impl, PushButton *, EMPTYARG )
435*cdf0e10cSrcweir {
436*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pPathBox->FirstSelected();
437*cdf0e10cSrcweir 	while ( pEntry )
438*cdf0e10cSrcweir 	{
439*cdf0e10cSrcweir 		PathUserData_Impl* pPathImpl = (PathUserData_Impl*)pEntry->GetUserData();
440*cdf0e10cSrcweir         String aOldPath = pImpl->m_aDefOpt.GetDefaultPath( pPathImpl->nRealId );
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 		if ( aOldPath.Len() )
443*cdf0e10cSrcweir 		{
444*cdf0e10cSrcweir             String sInternal, sUser, sWritable, sTemp;
445*cdf0e10cSrcweir             sal_Bool bReadOnly = sal_False;
446*cdf0e10cSrcweir             GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir             sal_uInt16 i;
449*cdf0e10cSrcweir             sal_uInt16 nOldCount = aOldPath.GetTokenCount( MULTIPATH_DELIMITER );
450*cdf0e10cSrcweir             sal_uInt16 nIntCount = sInternal.GetTokenCount( MULTIPATH_DELIMITER );
451*cdf0e10cSrcweir             for ( i = 0; i < nOldCount; ++i )
452*cdf0e10cSrcweir             {
453*cdf0e10cSrcweir                 bool bFound = false;
454*cdf0e10cSrcweir                 String sOnePath = aOldPath.GetToken( i, MULTIPATH_DELIMITER );
455*cdf0e10cSrcweir                 for ( sal_uInt16 j = 0; !bFound && j < nIntCount; ++j )
456*cdf0e10cSrcweir                 {
457*cdf0e10cSrcweir                     if ( sInternal.GetToken( i, MULTIPATH_DELIMITER ) == sOnePath )
458*cdf0e10cSrcweir                         bFound = true;
459*cdf0e10cSrcweir                 }
460*cdf0e10cSrcweir                 if ( !bFound )
461*cdf0e10cSrcweir                 {
462*cdf0e10cSrcweir                     if ( sTemp.Len() > 0 )
463*cdf0e10cSrcweir                         sTemp += MULTIPATH_DELIMITER;
464*cdf0e10cSrcweir                     sTemp += sOnePath;
465*cdf0e10cSrcweir                 }
466*cdf0e10cSrcweir             }
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir             String sUserPath, sWritablePath;
469*cdf0e10cSrcweir             nOldCount = sTemp.GetTokenCount( MULTIPATH_DELIMITER );
470*cdf0e10cSrcweir             for ( i = 0; nOldCount > 0 && i < nOldCount - 1; ++i )
471*cdf0e10cSrcweir             {
472*cdf0e10cSrcweir                 if ( sUserPath.Len() > 0 )
473*cdf0e10cSrcweir                     sUserPath += MULTIPATH_DELIMITER;
474*cdf0e10cSrcweir                 sUserPath += sTemp.GetToken( i, MULTIPATH_DELIMITER );
475*cdf0e10cSrcweir             }
476*cdf0e10cSrcweir             sWritablePath = sTemp.GetToken( nOldCount - 1, MULTIPATH_DELIMITER );
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir             pPathBox->SetEntryText( Convert_Impl( sTemp ), pEntry, 1 );
479*cdf0e10cSrcweir 			pPathImpl->eState = SFX_ITEM_SET;
480*cdf0e10cSrcweir             pPathImpl->sUserPath = sUserPath;
481*cdf0e10cSrcweir             pPathImpl->sWritablePath = sWritablePath;
482*cdf0e10cSrcweir 		}
483*cdf0e10cSrcweir 		pEntry = pPathBox->NextSelected( pEntry );
484*cdf0e10cSrcweir 	}
485*cdf0e10cSrcweir 	return 0;
486*cdf0e10cSrcweir }
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir // -----------------------------------------------------------------------
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir void SvxPathTabPage::ChangeCurrentEntry( const String& _rFolder )
491*cdf0e10cSrcweir {
492*cdf0e10cSrcweir     SvLBoxEntry* pEntry = pPathBox->GetCurEntry();
493*cdf0e10cSrcweir     if ( !pEntry )
494*cdf0e10cSrcweir     {
495*cdf0e10cSrcweir         DBG_ERRORFILE( "SvxPathTabPage::ChangeCurrentEntry(): no entry" );
496*cdf0e10cSrcweir         return;
497*cdf0e10cSrcweir     }
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir     String sInternal, sUser, sWritable;
500*cdf0e10cSrcweir     PathUserData_Impl* pPathImpl = (PathUserData_Impl*)pEntry->GetUserData();
501*cdf0e10cSrcweir     sal_Bool bReadOnly = sal_False;
502*cdf0e10cSrcweir     GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
503*cdf0e10cSrcweir     sUser = pPathImpl->sUserPath;
504*cdf0e10cSrcweir     sWritable = pPathImpl->sWritablePath;
505*cdf0e10cSrcweir     sal_uInt16 nPos = pPathImpl->nRealId;
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir     // old path is an URL?
508*cdf0e10cSrcweir     INetURLObject aObj( sWritable );
509*cdf0e10cSrcweir     FASTBOOL bURL = ( aObj.GetProtocol() != INET_PROT_NOT_VALID );
510*cdf0e10cSrcweir     rtl::OUString aPathStr( _rFolder );
511*cdf0e10cSrcweir     INetURLObject aNewObj( aPathStr );
512*cdf0e10cSrcweir     aNewObj.removeFinalSlash();
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir     // then the new path also an URL else system path
515*cdf0e10cSrcweir     String sNewPathStr = bURL ? aPathStr : aNewObj.getFSysPath( INetURLObject::FSYS_DETECT );
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir     FASTBOOL bChanged =
518*cdf0e10cSrcweir #ifdef UNX
519*cdf0e10cSrcweir // Unix is case sensitive
520*cdf0e10cSrcweir         ( sNewPathStr != sWritable );
521*cdf0e10cSrcweir #else
522*cdf0e10cSrcweir         ( sNewPathStr.CompareIgnoreCaseToAscii( sWritable ) != COMPARE_EQUAL );
523*cdf0e10cSrcweir #endif
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir     if ( bChanged )
526*cdf0e10cSrcweir     {
527*cdf0e10cSrcweir         pPathBox->SetEntryText( Convert_Impl( sNewPathStr ), pEntry, 1 );
528*cdf0e10cSrcweir         nPos = (sal_uInt16)pPathBox->GetModel()->GetAbsPos( pEntry );
529*cdf0e10cSrcweir         pPathImpl = (PathUserData_Impl*)pPathBox->GetEntry(nPos)->GetUserData();
530*cdf0e10cSrcweir         pPathImpl->eState = SFX_ITEM_SET;
531*cdf0e10cSrcweir         pPathImpl->sWritablePath = sNewPathStr;
532*cdf0e10cSrcweir         if ( SvtPathOptions::PATH_WORK == pPathImpl->nRealId )
533*cdf0e10cSrcweir         {
534*cdf0e10cSrcweir             // Remove view options entry so the new work path
535*cdf0e10cSrcweir             // will be used for the next open dialog.
536*cdf0e10cSrcweir             SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
537*cdf0e10cSrcweir             aDlgOpt.Delete();
538*cdf0e10cSrcweir 		    // Reset also last used dir in the sfx application instance
539*cdf0e10cSrcweir             SfxApplication *pSfxApp = SFX_APP();
540*cdf0e10cSrcweir 		    pSfxApp->ResetLastDir();
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir     		// Set configuration flag to notify file picker that it's necessary
543*cdf0e10cSrcweir             // to take over the path provided.
544*cdf0e10cSrcweir             Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
545*cdf0e10cSrcweir             ::comphelper::ConfigurationHelper::writeDirectKey(xFactory,
546*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Common/")),
547*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Path/Info")),
548*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WorkPathChanged")),
549*cdf0e10cSrcweir                 ::com::sun::star::uno::makeAny(true),
550*cdf0e10cSrcweir                 ::comphelper::ConfigurationHelper::E_STANDARD);
551*cdf0e10cSrcweir         }
552*cdf0e10cSrcweir     }
553*cdf0e10cSrcweir }
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir // -----------------------------------------------------------------------
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir IMPL_LINK( SvxPathTabPage, PathHdl_Impl, PushButton *, EMPTYARG )
558*cdf0e10cSrcweir {
559*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pPathBox->GetCurEntry();
560*cdf0e10cSrcweir 	sal_uInt16 nPos = ( pEntry != NULL ) ? ( (PathUserData_Impl*)pEntry->GetUserData() )->nRealId : 0;
561*cdf0e10cSrcweir     String sInternal, sUser, sWritable;
562*cdf0e10cSrcweir 	if ( pEntry )
563*cdf0e10cSrcweir 	{
564*cdf0e10cSrcweir 		PathUserData_Impl* pPathImpl = (PathUserData_Impl*)pEntry->GetUserData();
565*cdf0e10cSrcweir         sal_Bool bReadOnly = sal_False;
566*cdf0e10cSrcweir         GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
567*cdf0e10cSrcweir         sUser = pPathImpl->sUserPath;
568*cdf0e10cSrcweir         sWritable = pPathImpl->sWritablePath;
569*cdf0e10cSrcweir 	}
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir     if(pEntry && !(!((OptHeaderTabListBox*)pPathBox)->GetCollapsedEntryBmp(pEntry)))
572*cdf0e10cSrcweir         return 0;
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 	if ( IsMultiPath_Impl( nPos ) )
575*cdf0e10cSrcweir 	{
576*cdf0e10cSrcweir 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
577*cdf0e10cSrcweir         if ( pFact )
578*cdf0e10cSrcweir 		{
579*cdf0e10cSrcweir             AbstractSvxMultiPathDialog* pMultiDlg =
580*cdf0e10cSrcweir                 pFact->CreateSvxMultiPathDialog( this );
581*cdf0e10cSrcweir             DBG_ASSERT( pMultiDlg, "Dialogdiet fail!" );
582*cdf0e10cSrcweir             pMultiDlg->EnableRadioButtonMode();
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir             String sPath( sUser );
585*cdf0e10cSrcweir             if ( sPath.Len() > 0 )
586*cdf0e10cSrcweir                 sPath += MULTIPATH_DELIMITER;
587*cdf0e10cSrcweir             sPath += sWritable;
588*cdf0e10cSrcweir             pMultiDlg->SetPath( sPath );
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir             String sPathName = pPathBox->GetEntryText( pEntry, 0 );
591*cdf0e10cSrcweir             String sNewTitle( pImpl->m_sMultiPathDlg );
592*cdf0e10cSrcweir             sNewTitle.SearchAndReplace( VAR_ONE, sPathName );
593*cdf0e10cSrcweir             pMultiDlg->SetTitle( sNewTitle );
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir             if ( pMultiDlg->Execute() == RET_OK && pEntry )
596*cdf0e10cSrcweir 			{
597*cdf0e10cSrcweir                 sUser.Erase();
598*cdf0e10cSrcweir                 sWritable.Erase();
599*cdf0e10cSrcweir                 String sFullPath;
600*cdf0e10cSrcweir                 String sNewPath = pMultiDlg->GetPath();
601*cdf0e10cSrcweir                 char cDelim = MULTIPATH_DELIMITER;
602*cdf0e10cSrcweir                 sal_uInt16 nCount = sNewPath.GetTokenCount( cDelim );
603*cdf0e10cSrcweir                 if ( nCount > 0 )
604*cdf0e10cSrcweir                 {
605*cdf0e10cSrcweir                     sal_uInt16 i = 0;
606*cdf0e10cSrcweir                     for ( ; i < nCount - 1; ++i )
607*cdf0e10cSrcweir                     {
608*cdf0e10cSrcweir                         if ( sUser.Len() > 0 )
609*cdf0e10cSrcweir                             sUser += cDelim;
610*cdf0e10cSrcweir                         sUser += sNewPath.GetToken( i, cDelim );
611*cdf0e10cSrcweir                     }
612*cdf0e10cSrcweir                     if ( sFullPath.Len() > 0 )
613*cdf0e10cSrcweir                         sFullPath += cDelim;
614*cdf0e10cSrcweir                     sFullPath += sUser;
615*cdf0e10cSrcweir                     sWritable += sNewPath.GetToken( i, cDelim );
616*cdf0e10cSrcweir                     if ( sFullPath.Len() > 0 )
617*cdf0e10cSrcweir                         sFullPath += cDelim;
618*cdf0e10cSrcweir                     sFullPath += sWritable;
619*cdf0e10cSrcweir                 }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir                 pPathBox->SetEntryText( Convert_Impl( sFullPath ), pEntry, 1 );
622*cdf0e10cSrcweir                 // save modified flag
623*cdf0e10cSrcweir                 PathUserData_Impl* pPathImpl = (PathUserData_Impl*)pEntry->GetUserData();
624*cdf0e10cSrcweir 				pPathImpl->eState = SFX_ITEM_SET;
625*cdf0e10cSrcweir                 pPathImpl->sUserPath = sUser;
626*cdf0e10cSrcweir                 pPathImpl->sWritablePath = sWritable;
627*cdf0e10cSrcweir             }
628*cdf0e10cSrcweir             delete pMultiDlg;
629*cdf0e10cSrcweir 		}
630*cdf0e10cSrcweir 	}
631*cdf0e10cSrcweir 	else if ( pEntry )
632*cdf0e10cSrcweir 	{
633*cdf0e10cSrcweir         try
634*cdf0e10cSrcweir         {
635*cdf0e10cSrcweir     		rtl::OUString aService( RTL_CONSTASCII_USTRINGPARAM( FOLDER_PICKER_SERVICE_NAME ) );
636*cdf0e10cSrcweir     		Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
637*cdf0e10cSrcweir             xFolderPicker = ::com::sun::star::uno::Reference< XFolderPicker >(
638*cdf0e10cSrcweir                 xFactory->createInstance( aService ), UNO_QUERY );
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir             INetURLObject aURL( sWritable, INET_PROT_FILE );
641*cdf0e10cSrcweir         	xFolderPicker->setDisplayDirectory( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir             Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
644*cdf0e10cSrcweir             if ( xAsyncDlg.is() )
645*cdf0e10cSrcweir                 xAsyncDlg->startExecuteModal( xDialogListener.get() );
646*cdf0e10cSrcweir             else
647*cdf0e10cSrcweir             {
648*cdf0e10cSrcweir                 short nRet = xFolderPicker->execute();
649*cdf0e10cSrcweir                 if ( ExecutableDialogResults::OK != nRet )
650*cdf0e10cSrcweir                     return 0;
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir                 String sFolder( xFolderPicker->getDirectory() );
653*cdf0e10cSrcweir                 ChangeCurrentEntry( sFolder );
654*cdf0e10cSrcweir             }
655*cdf0e10cSrcweir 		}
656*cdf0e10cSrcweir         catch( Exception& )
657*cdf0e10cSrcweir         {
658*cdf0e10cSrcweir             DBG_ERRORFILE( "SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
659*cdf0e10cSrcweir         }
660*cdf0e10cSrcweir 	}
661*cdf0e10cSrcweir 	return 0;
662*cdf0e10cSrcweir }
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir // -----------------------------------------------------------------------
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir IMPL_LINK( SvxPathTabPage, HeaderSelect_Impl, HeaderBar*, pBar )
667*cdf0e10cSrcweir {
668*cdf0e10cSrcweir 	if ( pBar && pBar->GetCurItemId() != ITEMID_TYPE )
669*cdf0e10cSrcweir 		return 0;
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir 	HeaderBarItemBits nBits	= pHeaderBar->GetItemBits(ITEMID_TYPE);
672*cdf0e10cSrcweir 	sal_Bool bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
673*cdf0e10cSrcweir 	SvSortMode eMode = SortAscending;
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir 	if ( bUp )
676*cdf0e10cSrcweir 	{
677*cdf0e10cSrcweir 		nBits &= ~HIB_UPARROW;
678*cdf0e10cSrcweir 		nBits |= HIB_DOWNARROW;
679*cdf0e10cSrcweir 		eMode = SortDescending;
680*cdf0e10cSrcweir 	}
681*cdf0e10cSrcweir 	else
682*cdf0e10cSrcweir 	{
683*cdf0e10cSrcweir 		nBits &= ~HIB_DOWNARROW;
684*cdf0e10cSrcweir 		nBits |= HIB_UPARROW;
685*cdf0e10cSrcweir 	}
686*cdf0e10cSrcweir 	pHeaderBar->SetItemBits( ITEMID_TYPE, nBits );
687*cdf0e10cSrcweir 	SvTreeList* pModel = pPathBox->GetModel();
688*cdf0e10cSrcweir 	pModel->SetSortMode( eMode );
689*cdf0e10cSrcweir 	pModel->Resort();
690*cdf0e10cSrcweir 	return 1;
691*cdf0e10cSrcweir }
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir // -----------------------------------------------------------------------
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir IMPL_LINK( SvxPathTabPage, HeaderEndDrag_Impl, HeaderBar*, pBar )
696*cdf0e10cSrcweir {
697*cdf0e10cSrcweir 	if ( pBar && !pBar->GetCurItemId() )
698*cdf0e10cSrcweir 		return 0;
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir 	if ( !pHeaderBar->IsItemMode() )
701*cdf0e10cSrcweir 	{
702*cdf0e10cSrcweir 		Size aSz;
703*cdf0e10cSrcweir 		sal_uInt16 nTabs = pHeaderBar->GetItemCount();
704*cdf0e10cSrcweir 		long nTmpSz = 0;
705*cdf0e10cSrcweir 		long nWidth = pHeaderBar->GetItemSize(ITEMID_TYPE);
706*cdf0e10cSrcweir 		long nBarWidth = pHeaderBar->GetSizePixel().Width();
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir         if(nWidth < TAB_WIDTH_MIN)
709*cdf0e10cSrcweir             pHeaderBar->SetItemSize( ITEMID_TYPE, TAB_WIDTH_MIN);
710*cdf0e10cSrcweir         else if ( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
711*cdf0e10cSrcweir             pHeaderBar->SetItemSize( ITEMID_TYPE, nBarWidth - TAB_WIDTH_MIN );
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir 		for ( sal_uInt16 i = 1; i <= nTabs; ++i )
714*cdf0e10cSrcweir 		{
715*cdf0e10cSrcweir 			long _nWidth = pHeaderBar->GetItemSize(i);
716*cdf0e10cSrcweir 			aSz.Width() =  _nWidth + nTmpSz;
717*cdf0e10cSrcweir 			nTmpSz += _nWidth;
718*cdf0e10cSrcweir 			pPathBox->SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
719*cdf0e10cSrcweir 		}
720*cdf0e10cSrcweir 	}
721*cdf0e10cSrcweir 	return 1;
722*cdf0e10cSrcweir }
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir // -----------------------------------------------------------------------
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir IMPL_LINK( SvxPathTabPage, DialogClosedHdl, DialogClosedEvent*, pEvt )
727*cdf0e10cSrcweir {
728*cdf0e10cSrcweir     if ( RET_OK == pEvt->DialogResult )
729*cdf0e10cSrcweir     {
730*cdf0e10cSrcweir         DBG_ASSERT( xFolderPicker.is() == sal_True, "SvxPathTabPage::DialogClosedHdl(): no folder picker" );
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir         String sURL = String( xFolderPicker->getDirectory() );
733*cdf0e10cSrcweir         ChangeCurrentEntry( sURL );
734*cdf0e10cSrcweir     }
735*cdf0e10cSrcweir     return 0L;
736*cdf0e10cSrcweir }
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir // -----------------------------------------------------------------------
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir void SvxPathTabPage::GetPathList(
741*cdf0e10cSrcweir     sal_uInt16 _nPathHandle, String& _rInternalPath,
742*cdf0e10cSrcweir     String& _rUserPath, String& _rWritablePath, sal_Bool& _rReadOnly )
743*cdf0e10cSrcweir {
744*cdf0e10cSrcweir     String sCfgName = getCfgName_Impl( _nPathHandle );
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir     // load PathSettings service if necessary
747*cdf0e10cSrcweir     if ( !pImpl->m_xPathSettings.is() )
748*cdf0e10cSrcweir     {
749*cdf0e10cSrcweir         Reference< XMultiServiceFactory > xSMgr = comphelper::getProcessServiceFactory();
750*cdf0e10cSrcweir         pImpl->m_xPathSettings = Reference< XPropertySet >( xSMgr->createInstance(
751*cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
752*cdf0e10cSrcweir                 "com.sun.star.util.PathSettings") ) ), UNO_QUERY );
753*cdf0e10cSrcweir     }
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir     try
756*cdf0e10cSrcweir     {
757*cdf0e10cSrcweir         if ( pImpl->m_xPathSettings.is() )
758*cdf0e10cSrcweir         {
759*cdf0e10cSrcweir             // load internal paths
760*cdf0e10cSrcweir             String sProp( sCfgName );
761*cdf0e10cSrcweir             sProp = sCfgName;
762*cdf0e10cSrcweir             sProp += POSTFIX_INTERNAL;
763*cdf0e10cSrcweir             Any aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
764*cdf0e10cSrcweir             Sequence< ::rtl::OUString > aPathSeq;
765*cdf0e10cSrcweir             if ( aAny >>= aPathSeq )
766*cdf0e10cSrcweir             {
767*cdf0e10cSrcweir                 long i, nCount = aPathSeq.getLength();
768*cdf0e10cSrcweir                 const ::rtl::OUString* pPaths = aPathSeq.getConstArray();
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir                 for ( i = 0; i < nCount; ++i )
771*cdf0e10cSrcweir                 {
772*cdf0e10cSrcweir                     if ( _rInternalPath.Len() > 0 )
773*cdf0e10cSrcweir                         _rInternalPath += ';';
774*cdf0e10cSrcweir                     _rInternalPath += String( pPaths[i] );
775*cdf0e10cSrcweir                 }
776*cdf0e10cSrcweir             }
777*cdf0e10cSrcweir             // load user paths
778*cdf0e10cSrcweir             sProp = sCfgName;
779*cdf0e10cSrcweir             sProp += POSTFIX_USER;
780*cdf0e10cSrcweir             aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
781*cdf0e10cSrcweir             if ( aAny >>= aPathSeq )
782*cdf0e10cSrcweir             {
783*cdf0e10cSrcweir                 long i, nCount = aPathSeq.getLength();
784*cdf0e10cSrcweir                 const ::rtl::OUString* pPaths = aPathSeq.getConstArray();
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir                 for ( i = 0; i < nCount; ++i )
787*cdf0e10cSrcweir                 {
788*cdf0e10cSrcweir                     if ( _rUserPath.Len() > 0 )
789*cdf0e10cSrcweir                         _rUserPath += ';';
790*cdf0e10cSrcweir                     _rUserPath += String( pPaths[i] );
791*cdf0e10cSrcweir                 }
792*cdf0e10cSrcweir             }
793*cdf0e10cSrcweir             // then the writable path
794*cdf0e10cSrcweir             sProp = sCfgName;
795*cdf0e10cSrcweir             sProp += POSTFIX_WRITABLE;
796*cdf0e10cSrcweir             aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
797*cdf0e10cSrcweir             ::rtl::OUString sWritablePath;
798*cdf0e10cSrcweir             if ( aAny >>= sWritablePath )
799*cdf0e10cSrcweir                 _rWritablePath = String( sWritablePath );
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir             // and the readonly flag
802*cdf0e10cSrcweir             sProp = sCfgName;
803*cdf0e10cSrcweir             Reference< XPropertySetInfo > xInfo = pImpl->m_xPathSettings->getPropertySetInfo();
804*cdf0e10cSrcweir             Property aProp = xInfo->getPropertyByName( sProp );
805*cdf0e10cSrcweir             _rReadOnly = ( ( aProp.Attributes & PropertyAttribute::READONLY ) == PropertyAttribute::READONLY );
806*cdf0e10cSrcweir         }
807*cdf0e10cSrcweir     }
808*cdf0e10cSrcweir     catch( const Exception& )
809*cdf0e10cSrcweir     {
810*cdf0e10cSrcweir         OSL_ENSURE( sal_False, "SvxPathTabPage::GetPathList(): caught an exception!" );
811*cdf0e10cSrcweir     }
812*cdf0e10cSrcweir }
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir // -----------------------------------------------------------------------
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir void SvxPathTabPage::SetPathList(
817*cdf0e10cSrcweir     sal_uInt16 _nPathHandle, const String& _rUserPath, const String& _rWritablePath )
818*cdf0e10cSrcweir {
819*cdf0e10cSrcweir     String sCfgName = getCfgName_Impl( _nPathHandle );
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir     // load PathSettings service if necessary
822*cdf0e10cSrcweir     if ( !pImpl->m_xPathSettings.is() )
823*cdf0e10cSrcweir     {
824*cdf0e10cSrcweir         Reference< XMultiServiceFactory > xSMgr = comphelper::getProcessServiceFactory();
825*cdf0e10cSrcweir         pImpl->m_xPathSettings = Reference< XPropertySet >( xSMgr->createInstance(
826*cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
827*cdf0e10cSrcweir                 "com.sun.star.util.PathSettings") ) ), UNO_QUERY );
828*cdf0e10cSrcweir     }
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir     try
831*cdf0e10cSrcweir     {
832*cdf0e10cSrcweir         if ( pImpl->m_xPathSettings.is() )
833*cdf0e10cSrcweir         {
834*cdf0e10cSrcweir             // save user paths
835*cdf0e10cSrcweir             char cDelim = MULTIPATH_DELIMITER;
836*cdf0e10cSrcweir             sal_uInt16 nCount = _rUserPath.GetTokenCount( cDelim );
837*cdf0e10cSrcweir             Sequence< ::rtl::OUString > aPathSeq( nCount );
838*cdf0e10cSrcweir             ::rtl::OUString* pArray = aPathSeq.getArray();
839*cdf0e10cSrcweir             for ( sal_uInt16 i = 0; i < nCount; ++i )
840*cdf0e10cSrcweir                 pArray[i] = ::rtl::OUString( _rUserPath.GetToken( i, cDelim ) );
841*cdf0e10cSrcweir             String sProp( sCfgName );
842*cdf0e10cSrcweir             sProp += POSTFIX_USER;
843*cdf0e10cSrcweir             Any aValue = makeAny( aPathSeq );
844*cdf0e10cSrcweir             pImpl->m_xPathSettings->setPropertyValue( sProp, aValue );
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir             // then the writable path
847*cdf0e10cSrcweir             aValue = makeAny( ::rtl::OUString( _rWritablePath ) );
848*cdf0e10cSrcweir             sProp = sCfgName;
849*cdf0e10cSrcweir             sProp += POSTFIX_WRITABLE;
850*cdf0e10cSrcweir             pImpl->m_xPathSettings->setPropertyValue( sProp, aValue );
851*cdf0e10cSrcweir         }
852*cdf0e10cSrcweir     }
853*cdf0e10cSrcweir     catch( const Exception& )
854*cdf0e10cSrcweir     {
855*cdf0e10cSrcweir         OSL_ENSURE( sal_False, "SvxPathTabPage::SetPathList(): caught an exception!" );
856*cdf0e10cSrcweir     }
857*cdf0e10cSrcweir }
858*cdf0e10cSrcweir 
859