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: multipat.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 ---------------------------------------------------------------
39 #include <tools/debug.hxx>
40 #include <tools/urlobj.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <sfx2/filedlghelper.hxx>
44 #include "multipat.hxx"
45 #include <svx/dialmgr.hxx>
47 #include "multipat.hrc"
48 #include <svx/dialogs.hrc>
49 #include <comphelper/processfactory.hxx>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
52 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
54 #include <unotools/localfilehelper.hxx>
55 #include <svtools/pathoptions.hxx>
57 using namespace ::com::sun::star::lang
;
58 using namespace ::com::sun::star::ui::dialogs
;
59 using namespace ::com::sun::star::uno
;
61 // struct MultiPath_Impl -------------------------------------------------
66 BOOL bIsClassPathMode
;
67 bool bIsRadioButtonMode
;
69 MultiPath_Impl( BOOL bAllowed
) :
70 bEmptyAllowed( bAllowed
), bIsClassPathMode( FALSE
), bIsRadioButtonMode( false ) {}
73 // class SvxMultiPathDialog ----------------------------------------------
75 IMPL_LINK( SvxMultiPathDialog
, SelectHdl_Impl
, void *, EMPTYARG
)
77 ULONG nCount
= pImpl
->bIsRadioButtonMode
? aRadioLB
.GetEntryCount() : aPathLB
.GetEntryCount();
78 bool bIsSelected
= pImpl
->bIsRadioButtonMode
79 ? aRadioLB
.FirstSelected() != NULL
80 : aPathLB
.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
;
81 BOOL bEnable
= ( pImpl
->bEmptyAllowed
|| nCount
> 1 );
82 aDelBtn
.Enable( bEnable
&& bIsSelected
);
86 // -----------------------------------------------------------------------
88 IMPL_LINK( SvxMultiPathDialog
, CheckHdl_Impl
, svx::SvxRadioButtonListBox
*, pBox
)
91 pBox
? pBox
->GetEntry( pBox
->GetCurMousePoint() ) : aRadioLB
.FirstSelected();
93 aRadioLB
.HandleEntryChecked( pEntry
);
97 // -----------------------------------------------------------------------
99 IMPL_LINK( SvxMultiPathDialog
, AddHdl_Impl
, PushButton
*, EMPTYARG
)
101 rtl::OUString
aService( RTL_CONSTASCII_USTRINGPARAM( FOLDER_PICKER_SERVICE_NAME
) );
102 Reference
< XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
103 Reference
< XFolderPicker
> xFolderPicker( xFactory
->createInstance( aService
), UNO_QUERY
);
105 if ( xFolderPicker
->execute() == ExecutableDialogResults::OK
)
107 INetURLObject
aPath( xFolderPicker
->getDirectory() );
108 aPath
.removeFinalSlash();
109 String aURL
= aPath
.GetMainURL( INetURLObject::NO_DECODE
);
111 ::utl::LocalFileHelper::ConvertURLToSystemPath( aURL
, sInsPath
);
113 if ( pImpl
->bIsRadioButtonMode
)
115 ULONG nPos
= aRadioLB
.GetEntryPos( sInsPath
, 1 );
116 if ( 0xffffffff == nPos
) //See svtools/source/contnr/svtabbx.cxx SvTabListBox::GetEntryPos
118 String
sNewEntry( '\t' );
119 sNewEntry
+= sInsPath
;
120 SvLBoxEntry
* pEntry
= aRadioLB
.InsertEntry( sNewEntry
);
121 String
* pData
= new String( aURL
);
122 pEntry
->SetUserData( pData
);
126 String
sMsg( SVX_RES( RID_MULTIPATH_DBL_ERR
) );
127 sMsg
.SearchAndReplaceAscii( "%1", sInsPath
);
128 InfoBox( this, sMsg
).Execute();
133 if ( LISTBOX_ENTRY_NOTFOUND
!= aPathLB
.GetEntryPos( sInsPath
) )
135 String
sMsg( SVX_RES( RID_MULTIPATH_DBL_ERR
) );
136 sMsg
.SearchAndReplaceAscii( "%1", sInsPath
);
137 InfoBox( this, sMsg
).Execute();
141 USHORT nPos
= aPathLB
.InsertEntry( sInsPath
, LISTBOX_APPEND
);
142 aPathLB
.SetEntryData( nPos
, (void*)new String( aURL
) );
145 SelectHdl_Impl( NULL
);
150 // -----------------------------------------------------------------------
152 IMPL_LINK( SvxMultiPathDialog
, DelHdl_Impl
, PushButton
*, EMPTYARG
)
154 if ( pImpl
->bIsRadioButtonMode
)
156 SvLBoxEntry
* pEntry
= aRadioLB
.FirstSelected();
157 delete (String
*)pEntry
->GetUserData();
158 bool bChecked
= aRadioLB
.GetCheckButtonState( pEntry
) == SV_BUTTON_CHECKED
;
159 ULONG nPos
= aRadioLB
.GetEntryPos( pEntry
);
160 aRadioLB
.RemoveEntry( pEntry
);
161 ULONG nCnt
= aRadioLB
.GetEntryCount();
167 pEntry
= aRadioLB
.GetEntry( nPos
);
170 aRadioLB
.SetCheckButtonState( pEntry
, SV_BUTTON_CHECKED
);
171 aRadioLB
.HandleEntryChecked( pEntry
);
174 aRadioLB
.Select( pEntry
);
179 USHORT nPos
= aPathLB
.GetSelectEntryPos();
180 aPathLB
.RemoveEntry( nPos
);
181 USHORT nCnt
= aPathLB
.GetEntryCount();
189 aPathLB
.SelectEntryPos( nPos
);
192 SelectHdl_Impl( NULL
);
196 // -----------------------------------------------------------------------
198 SvxMultiPathDialog::SvxMultiPathDialog( Window
* pParent
, BOOL bEmptyAllowed
) :
200 ModalDialog( pParent
, SVX_RES( RID_SVXDLG_MULTIPATH
) ),
202 aPathFL ( this, SVX_RES( FL_MULTIPATH
) ),
203 aPathLB ( this, SVX_RES( LB_MULTIPATH
) ),
204 aRadioLB ( this, SVX_RES( LB_RADIOBUTTON
) ),
205 aRadioFT ( this, SVX_RES( FT_RADIOBUTTON
) ),
206 aAddBtn ( this, SVX_RES( BTN_ADD_MULTIPATH
) ),
207 aDelBtn ( this, SVX_RES( BTN_DEL_MULTIPATH
) ),
208 aOKBtn ( this, SVX_RES( BTN_MULTIPATH_OK
) ),
209 aCancelBtn ( this, SVX_RES( BTN_MULTIPATH_CANCEL
) ),
210 aHelpButton ( this, SVX_RES( BTN_MULTIPATH_HELP
) ),
211 pImpl ( new MultiPath_Impl( bEmptyAllowed
) )
214 static long aStaticTabs
[]= { 2, 0, 12 };
215 aRadioLB
.SvxSimpleTable::SetTabs( aStaticTabs
);
216 String
sHeader( SVX_RES( STR_HEADER_PATHS
) );
217 aRadioLB
.SetQuickHelpText( sHeader
);
218 sHeader
.Insert( '\t', 0 );
219 aRadioLB
.InsertHeaderEntry( sHeader
, HEADERBAR_APPEND
, HIB_LEFT
);
223 aPathLB
.SetSelectHdl( LINK( this, SvxMultiPathDialog
, SelectHdl_Impl
) );
224 aRadioLB
.SetSelectHdl( LINK( this, SvxMultiPathDialog
, SelectHdl_Impl
) );
225 aRadioLB
.SetCheckButtonHdl( LINK( this, SvxMultiPathDialog
, CheckHdl_Impl
) );
226 aAddBtn
.SetClickHdl( LINK( this, SvxMultiPathDialog
, AddHdl_Impl
) );
227 aDelBtn
.SetClickHdl( LINK( this, SvxMultiPathDialog
, DelHdl_Impl
) );
229 SelectHdl_Impl( NULL
);
232 // -----------------------------------------------------------------------
234 SvxMultiPathDialog::~SvxMultiPathDialog()
236 USHORT nPos
= aPathLB
.GetEntryCount();
238 delete (String
*)aPathLB
.GetEntryData(nPos
);
239 nPos
= (USHORT
)aRadioLB
.GetEntryCount();
242 SvLBoxEntry
* pEntry
= aRadioLB
.GetEntry( nPos
);
243 delete (String
*)pEntry
->GetUserData();
248 // -----------------------------------------------------------------------
250 String
SvxMultiPathDialog::GetPath() const
253 sal_Unicode cDelim
= pImpl
->bIsClassPathMode
? CLASSPATH_DELIMITER
: SVT_SEARCHPATH_DELIMITER
;
255 if ( pImpl
->bIsRadioButtonMode
)
258 for ( USHORT i
= 0; i
< aRadioLB
.GetEntryCount(); ++i
)
260 SvLBoxEntry
* pEntry
= aRadioLB
.GetEntry(i
);
261 if ( aRadioLB
.GetCheckButtonState( pEntry
) == SV_BUTTON_CHECKED
)
262 sWritable
= *(String
*)pEntry
->GetUserData();
265 if ( sNewPath
.Len() > 0 )
267 sNewPath
+= *(String
*)pEntry
->GetUserData();
270 if ( sNewPath
.Len() > 0 )
272 sNewPath
+= sWritable
;
276 for ( USHORT i
= 0; i
< aPathLB
.GetEntryCount(); ++i
)
278 if ( sNewPath
.Len() > 0 )
280 sNewPath
+= *(String
*)aPathLB
.GetEntryData(i
);
286 // -----------------------------------------------------------------------
288 void SvxMultiPathDialog::SetPath( const String
& rPath
)
290 sal_Unicode cDelim
= pImpl
->bIsClassPathMode
? CLASSPATH_DELIMITER
: SVT_SEARCHPATH_DELIMITER
;
291 USHORT nPos
, nCount
= rPath
.GetTokenCount( cDelim
);
293 for ( USHORT i
= 0; i
< nCount
; ++i
)
295 String sPath
= rPath
.GetToken( i
, cDelim
);
297 sal_Bool bIsSystemPath
=
298 ::utl::LocalFileHelper::ConvertURLToSystemPath( sPath
, sSystemPath
);
300 if ( pImpl
->bIsRadioButtonMode
)
302 String
sEntry( '\t' );
303 sEntry
+= bIsSystemPath
? sSystemPath
: sPath
;
304 SvLBoxEntry
* pEntry
= aRadioLB
.InsertEntry( sEntry
);
305 String
* pURL
= new String( sPath
);
306 pEntry
->SetUserData( pURL
);
311 nPos
= aPathLB
.InsertEntry( sSystemPath
, LISTBOX_APPEND
);
313 nPos
= aPathLB
.InsertEntry( sPath
, LISTBOX_APPEND
);
314 aPathLB
.SetEntryData( nPos
, (void*)new String( sPath
) );
318 if ( pImpl
->bIsRadioButtonMode
&& nCount
> 0 )
320 SvLBoxEntry
* pEntry
= aRadioLB
.GetEntry( nCount
- 1 );
323 aRadioLB
.SetCheckButtonState( pEntry
, SV_BUTTON_CHECKED
);
324 aRadioLB
.HandleEntryChecked( pEntry
);
328 SelectHdl_Impl( NULL
);
331 // -----------------------------------------------------------------------
333 void SvxMultiPathDialog::SetClassPathMode()
335 pImpl
->bIsClassPathMode
= TRUE
;
336 SetText( SVX_RES( RID_SVXSTR_ARCHIVE_TITLE
));
337 aPathFL
.SetText( SVX_RES( RID_SVXSTR_ARCHIVE_HEADLINE
) );
340 // -----------------------------------------------------------------------
342 sal_Bool
SvxMultiPathDialog::IsClassPathMode() const
344 return pImpl
->bIsClassPathMode
;
347 // -----------------------------------------------------------------------
349 void SvxMultiPathDialog::EnableRadioButtonMode()
351 pImpl
->bIsRadioButtonMode
= true;
356 aRadioLB
.ShowTable();
359 Point aNewPos
= aAddBtn
.GetPosPixel();
360 long nDelta
= aNewPos
.Y() - aRadioLB
.GetPosPixel().Y();
361 aNewPos
.Y() -= nDelta
;
362 aAddBtn
.SetPosPixel( aNewPos
);
363 aNewPos
= aDelBtn
.GetPosPixel();
364 aNewPos
.Y() -= nDelta
;
365 aDelBtn
.SetPosPixel( aNewPos
);