xref: /aoo41x/main/cui/source/options/dbregister.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 "dbregister.hxx"
32*cdf0e10cSrcweir #include "dbregister.hrc"
33*cdf0e10cSrcweir #include "dbregistersettings.hxx"
34*cdf0e10cSrcweir #include "connpooloptions.hxx"
35*cdf0e10cSrcweir #include <svl/filenotation.hxx>
36*cdf0e10cSrcweir #include <cuires.hrc>
37*cdf0e10cSrcweir #include "helpid.hrc"
38*cdf0e10cSrcweir #include <svtools/editbrowsebox.hxx>
39*cdf0e10cSrcweir #include <cuires.hrc>
40*cdf0e10cSrcweir #include <vcl/field.hxx>
41*cdf0e10cSrcweir #include <svl/eitem.hxx>
42*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
43*cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
48*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
49*cdf0e10cSrcweir #include <svtools/svtabbx.hxx>
50*cdf0e10cSrcweir #include <svl/itemset.hxx>
51*cdf0e10cSrcweir #include "doclinkdialog.hxx"
52*cdf0e10cSrcweir #include <tools/urlobj.hxx>
53*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
54*cdf0e10cSrcweir #include "optHeaderTabListbox.hxx"
55*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
56*cdf0e10cSrcweir #include <dialmgr.hxx>
57*cdf0e10cSrcweir #include "dbregisterednamesconfig.hxx"
58*cdf0e10cSrcweir #include <svx/dialogs.hrc>
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir #define TAB_WIDTH1		80
61*cdf0e10cSrcweir #define TAB_WIDTH_MIN   10
62*cdf0e10cSrcweir #define TAB_WIDTH2		1000
63*cdf0e10cSrcweir #define ITEMID_TYPE       1
64*cdf0e10cSrcweir #define ITEMID_PATH       2
65*cdf0e10cSrcweir //........................................................................
66*cdf0e10cSrcweir namespace svx
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir //........................................................................
69*cdf0e10cSrcweir 
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 ::svt;
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir // class RegistrationItemSetHolder  -------------------------------------------------
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir RegistrationItemSetHolder::RegistrationItemSetHolder( const SfxItemSet& _rMasterSet )
78*cdf0e10cSrcweir     :m_aRegistrationItems( _rMasterSet )
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	DbRegisteredNamesConfig::GetOptions( m_aRegistrationItems );
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir RegistrationItemSetHolder::~RegistrationItemSetHolder()
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir // class DatabaseRegistrationDialog  ------------------------------------------------
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir DatabaseRegistrationDialog::DatabaseRegistrationDialog( Window* pParent, const SfxItemSet& rInAttrs )
90*cdf0e10cSrcweir     :RegistrationItemSetHolder( rInAttrs )
91*cdf0e10cSrcweir     ,SfxSingleTabDialog( pParent, getRegistrationItems(), RID_SFXPAGE_DBREGISTER )
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     SfxTabPage* page = DbRegistrationOptionsPage::Create( this, getRegistrationItems() );
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	SetTabPage( page );
96*cdf0e10cSrcweir 	SetText( page->GetText() );
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir DatabaseRegistrationDialog::~DatabaseRegistrationDialog()
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir short DatabaseRegistrationDialog::Execute()
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     short result = SfxSingleTabDialog::Execute();
106*cdf0e10cSrcweir     if ( result == RET_OK )
107*cdf0e10cSrcweir     {
108*cdf0e10cSrcweir         DBG_ASSERT( GetOutputItemSet(), "DatabaseRegistrationDialog::Execute: no output items!" );
109*cdf0e10cSrcweir         if ( GetOutputItemSet() )
110*cdf0e10cSrcweir 	        DbRegisteredNamesConfig::SetOptions( *GetOutputItemSet() );
111*cdf0e10cSrcweir     }
112*cdf0e10cSrcweir     return result;
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir // class DbRegistrationOptionsPage --------------------------------------------------
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir DbRegistrationOptionsPage::DbRegistrationOptionsPage( Window* pParent, const SfxItemSet& rSet ) :
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	SfxTabPage( pParent, CUI_RES( RID_SFXPAGE_DBREGISTER), rSet ),
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 	aStdBox			( this, CUI_RES( GB_STD ) ),
122*cdf0e10cSrcweir 	aTypeText		( this, CUI_RES( FT_TYPE ) ),
123*cdf0e10cSrcweir 	aPathText		( this, CUI_RES( FT_PATH ) ),
124*cdf0e10cSrcweir 	aPathCtrl		( this, CUI_RES( LB_PATH ) ),
125*cdf0e10cSrcweir 	m_aNew			( this, CUI_RES( BTN_NEW ) ),
126*cdf0e10cSrcweir 	m_aEdit			( this, CUI_RES( BTN_EDIT ) ),
127*cdf0e10cSrcweir 	m_aDelete		( this, CUI_RES( BTN_DELETE ) ),
128*cdf0e10cSrcweir 	pHeaderBar		( NULL ),
129*cdf0e10cSrcweir 	pPathBox		( NULL ),
130*cdf0e10cSrcweir 	m_pCurEntry		( NULL ),
131*cdf0e10cSrcweir 	m_nOldCount		( 0 ),
132*cdf0e10cSrcweir 	m_bModified		( sal_False )
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir 	m_aNew.SetClickHdl( LINK( this, DbRegistrationOptionsPage, NewHdl ) );
135*cdf0e10cSrcweir 	m_aEdit.SetClickHdl( LINK( this, DbRegistrationOptionsPage, EditHdl ) );
136*cdf0e10cSrcweir 	m_aDelete.SetClickHdl( LINK( this, DbRegistrationOptionsPage, DeleteHdl ) );
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	Size aBoxSize = aPathCtrl.GetOutputSizePixel();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	WinBits nBits = WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP;
142*cdf0e10cSrcweir 	pPathBox = new ::svx::OptHeaderTabListBox( &aPathCtrl, nBits );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir     pHeaderBar = new HeaderBar( &aPathCtrl, WB_BUTTONSTYLE | WB_BOTTOMBORDER );
145*cdf0e10cSrcweir 	pHeaderBar->SetPosSizePixel( Point( 0, 0 ), Size( aBoxSize.Width(), 16 ) );
146*cdf0e10cSrcweir 	pHeaderBar->SetSelectHdl( LINK( this, DbRegistrationOptionsPage, HeaderSelect_Impl ) );
147*cdf0e10cSrcweir 	pHeaderBar->SetEndDragHdl( LINK( this, DbRegistrationOptionsPage, HeaderEndDrag_Impl ) );
148*cdf0e10cSrcweir 	Size aSz;
149*cdf0e10cSrcweir 	aSz.Width() = TAB_WIDTH1;
150*cdf0e10cSrcweir 	pHeaderBar->InsertItem( ITEMID_TYPE, aTypeText.GetText(),
151*cdf0e10cSrcweir 							LogicToPixel( aSz, MapMode( MAP_APPFONT ) ).Width(),
152*cdf0e10cSrcweir 							HIB_LEFT | HIB_VCENTER | HIB_CLICKABLE | HIB_UPARROW );
153*cdf0e10cSrcweir 	aSz.Width() = TAB_WIDTH2;
154*cdf0e10cSrcweir 	pHeaderBar->InsertItem( ITEMID_PATH, aPathText.GetText(),
155*cdf0e10cSrcweir 							LogicToPixel( aSz, MapMode( MAP_APPFONT ) ).Width(),
156*cdf0e10cSrcweir 							HIB_LEFT | HIB_VCENTER );
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	static long nTabs[] = {3, 0, TAB_WIDTH1, TAB_WIDTH1 + TAB_WIDTH2 };
159*cdf0e10cSrcweir 	Size aHeadSize = pHeaderBar->GetSizePixel();
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	aPathCtrl.SetFocusControl( pPathBox );
162*cdf0e10cSrcweir 	pPathBox->SetStyle( pPathBox->GetStyle()|nBits );
163*cdf0e10cSrcweir 	pPathBox->SetDoubleClickHdl( LINK( this, DbRegistrationOptionsPage, EditHdl ) );
164*cdf0e10cSrcweir 	pPathBox->SetSelectHdl( LINK( this, DbRegistrationOptionsPage, PathSelect_Impl ) );
165*cdf0e10cSrcweir 	pPathBox->SetSelectionMode( SINGLE_SELECTION );
166*cdf0e10cSrcweir 	pPathBox->SetPosSizePixel( Point( 0, aHeadSize.Height() ),
167*cdf0e10cSrcweir 							   Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) );
168*cdf0e10cSrcweir 	pPathBox->SetTabs( &nTabs[0], MAP_APPFONT );
169*cdf0e10cSrcweir 	pPathBox->InitHeaderBar( pHeaderBar );
170*cdf0e10cSrcweir 	pPathBox->SetHighlightRange();
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 	pPathBox->SetHelpId( HID_DBPATH_CTL_PATH );
173*cdf0e10cSrcweir 	pHeaderBar->SetHelpId( HID_DBPATH_HEADERBAR );
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	pPathBox->Show();
176*cdf0e10cSrcweir 	pHeaderBar->Show();
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 	FreeResource();
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir // -----------------------------------------------------------------------
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir DbRegistrationOptionsPage::~DbRegistrationOptionsPage()
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir     // #110603# do not grab focus to a destroyed window !!!
186*cdf0e10cSrcweir     aPathCtrl.SetFocusControl( NULL );
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	pHeaderBar->Hide();
189*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < pPathBox->GetEntryCount(); ++i )
190*cdf0e10cSrcweir 		delete static_cast< DatabaseRegistration* >( pPathBox->GetEntry(i)->GetUserData() );
191*cdf0e10cSrcweir 	delete pPathBox;
192*cdf0e10cSrcweir 	delete pHeaderBar;
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir // -----------------------------------------------------------------------
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir SfxTabPage*	DbRegistrationOptionsPage::Create( Window* pParent,
198*cdf0e10cSrcweir 									const SfxItemSet& rAttrSet )
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir 	return ( new DbRegistrationOptionsPage( pParent, rAttrSet ) );
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir // -----------------------------------------------------------------------
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir sal_Bool DbRegistrationOptionsPage::FillItemSet( SfxItemSet& rCoreSet )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir 	// the settings for the single drivers
208*cdf0e10cSrcweir 	sal_Bool bModified = sal_False;
209*cdf0e10cSrcweir 	DatabaseRegistrations aRegistrations;
210*cdf0e10cSrcweir 	sal_uLong nCount = pPathBox->GetEntryCount();
211*cdf0e10cSrcweir 	for ( sal_uLong i = 0; i < nCount; ++i )
212*cdf0e10cSrcweir 	{
213*cdf0e10cSrcweir 		SvLBoxEntry* pEntry = pPathBox->GetEntry(i);
214*cdf0e10cSrcweir 		DatabaseRegistration* pRegistration = static_cast< DatabaseRegistration* >( pEntry->GetUserData() );
215*cdf0e10cSrcweir         if ( pRegistration && pRegistration->sLocation.getLength() )
216*cdf0e10cSrcweir 		{
217*cdf0e10cSrcweir             ::rtl::OUString sName( pPathBox->GetEntryText( pEntry, 0 ) );
218*cdf0e10cSrcweir             OFileNotation aTransformer( pRegistration->sLocation );
219*cdf0e10cSrcweir             aRegistrations[ sName ] = DatabaseRegistration( aTransformer.get( OFileNotation::N_URL ), pRegistration->bReadOnly );
220*cdf0e10cSrcweir 		}
221*cdf0e10cSrcweir 	}
222*cdf0e10cSrcweir 	if ( m_nOldCount != aRegistrations.size() || m_bModified )
223*cdf0e10cSrcweir 	{
224*cdf0e10cSrcweir 		rCoreSet.Put(DatabaseMapItem( SID_SB_DB_REGISTER, aRegistrations ), SID_SB_DB_REGISTER);
225*cdf0e10cSrcweir 		bModified = sal_True;
226*cdf0e10cSrcweir 	}
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 	return bModified;
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir // -----------------------------------------------------------------------
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir void DbRegistrationOptionsPage::Reset( const SfxItemSet& rSet )
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir 	// the settings for the single drivers
236*cdf0e10cSrcweir 	SFX_ITEMSET_GET( rSet, pRegistrations, DatabaseMapItem, SID_SB_DB_REGISTER, sal_True );
237*cdf0e10cSrcweir     if ( !pRegistrations )
238*cdf0e10cSrcweir         return;
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 	pPathBox->Clear();
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 	const DatabaseRegistrations& rRegistrations = pRegistrations->getRegistrations();
243*cdf0e10cSrcweir 	m_nOldCount = rRegistrations.size();
244*cdf0e10cSrcweir 	DatabaseRegistrations::const_iterator aIter = rRegistrations.begin();
245*cdf0e10cSrcweir 	DatabaseRegistrations::const_iterator aEnd = rRegistrations.end();
246*cdf0e10cSrcweir 	for ( ; aIter != aEnd; ++aIter )
247*cdf0e10cSrcweir 	{
248*cdf0e10cSrcweir 		OFileNotation aTransformer( aIter->second.sLocation );
249*cdf0e10cSrcweir 		insertNewEntry( aIter->first, aTransformer.get( OFileNotation::N_SYSTEM ), aIter->second.bReadOnly );
250*cdf0e10cSrcweir 	}
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 	String aUserData = GetUserData();
253*cdf0e10cSrcweir 	if ( aUserData.Len() )
254*cdf0e10cSrcweir 	{
255*cdf0e10cSrcweir 		// Spaltenbreite restaurieren
256*cdf0e10cSrcweir 		pHeaderBar->SetItemSize( ITEMID_TYPE, aUserData.GetToken(0).ToInt32() );
257*cdf0e10cSrcweir 		HeaderEndDrag_Impl( NULL );
258*cdf0e10cSrcweir 		// Sortierrichtung restaurieren
259*cdf0e10cSrcweir 		sal_Bool bUp = (sal_Bool)(sal_uInt16)aUserData.GetToken(1).ToInt32();
260*cdf0e10cSrcweir 		HeaderBarItemBits nBits	= pHeaderBar->GetItemBits(ITEMID_TYPE);
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 		if ( bUp )
263*cdf0e10cSrcweir 		{
264*cdf0e10cSrcweir 			nBits &= ~HIB_UPARROW;
265*cdf0e10cSrcweir 			nBits |= HIB_DOWNARROW;
266*cdf0e10cSrcweir 		}
267*cdf0e10cSrcweir 		else
268*cdf0e10cSrcweir 		{
269*cdf0e10cSrcweir 			nBits &= ~HIB_DOWNARROW;
270*cdf0e10cSrcweir 			nBits |= HIB_UPARROW;
271*cdf0e10cSrcweir 		}
272*cdf0e10cSrcweir 		pHeaderBar->SetItemBits( ITEMID_TYPE, nBits );
273*cdf0e10cSrcweir 		HeaderSelect_Impl( NULL );
274*cdf0e10cSrcweir 	}
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir // -----------------------------------------------------------------------
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir void DbRegistrationOptionsPage::FillUserData()
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir 	String aUserData = String::CreateFromInt32( pHeaderBar->GetItemSize( ITEMID_TYPE ) );
282*cdf0e10cSrcweir 	aUserData += ';';
283*cdf0e10cSrcweir 	HeaderBarItemBits nBits	= pHeaderBar->GetItemBits( ITEMID_TYPE );
284*cdf0e10cSrcweir 	sal_Bool bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
285*cdf0e10cSrcweir 	aUserData += bUp ? '1' : '0';
286*cdf0e10cSrcweir 	SetUserData( aUserData );
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir // -----------------------------------------------------------------------
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir IMPL_LINK( DbRegistrationOptionsPage, DeleteHdl, void *, EMPTYARG )
291*cdf0e10cSrcweir {
292*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pPathBox->FirstSelected();
293*cdf0e10cSrcweir 	if ( pEntry )
294*cdf0e10cSrcweir 	{
295*cdf0e10cSrcweir 		QueryBox aQuery(this,CUI_RES(QUERY_DELETE_CONFIRM));
296*cdf0e10cSrcweir 		if ( aQuery.Execute() == RET_YES )
297*cdf0e10cSrcweir 			pPathBox->GetModel()->Remove(pEntry);
298*cdf0e10cSrcweir 	}
299*cdf0e10cSrcweir 	return 0;
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir // -----------------------------------------------------------------------
302*cdf0e10cSrcweir IMPL_LINK( DbRegistrationOptionsPage, NewHdl, void *, EMPTYARG )
303*cdf0e10cSrcweir {
304*cdf0e10cSrcweir 	String sNewName,sNewLocation;
305*cdf0e10cSrcweir 	openLinkDialog(sNewName,sNewLocation);
306*cdf0e10cSrcweir 	return 0;
307*cdf0e10cSrcweir }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir // -----------------------------------------------------------------------
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir IMPL_LINK( DbRegistrationOptionsPage, EditHdl, void *, EMPTYARG )
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pPathBox->GetCurEntry();
314*cdf0e10cSrcweir 	if ( !pEntry )
315*cdf0e10cSrcweir         return 0L;
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 	DatabaseRegistration* pOldRegistration = static_cast< DatabaseRegistration* >( pEntry->GetUserData() );
318*cdf0e10cSrcweir     if ( !pOldRegistration || pOldRegistration->bReadOnly )
319*cdf0e10cSrcweir         return 0L;
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 	String sOldName = pPathBox->GetEntryText(pEntry,0);
322*cdf0e10cSrcweir 	m_pCurEntry = pEntry;
323*cdf0e10cSrcweir 	openLinkDialog( sOldName, pOldRegistration->sLocation, pEntry );
324*cdf0e10cSrcweir 	m_pCurEntry = NULL;
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir 	return 1L;
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir // -----------------------------------------------------------------------
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir IMPL_LINK( DbRegistrationOptionsPage, HeaderSelect_Impl, HeaderBar*, pBar )
332*cdf0e10cSrcweir {
333*cdf0e10cSrcweir 	if ( pBar && pBar->GetCurItemId() != ITEMID_TYPE )
334*cdf0e10cSrcweir 		return 0;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 	HeaderBarItemBits nBits	= pHeaderBar->GetItemBits(ITEMID_TYPE);
337*cdf0e10cSrcweir 	sal_Bool bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
338*cdf0e10cSrcweir 	SvSortMode eMode = SortAscending;
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 	if ( bUp )
341*cdf0e10cSrcweir 	{
342*cdf0e10cSrcweir 		nBits &= ~HIB_UPARROW;
343*cdf0e10cSrcweir 		nBits |= HIB_DOWNARROW;
344*cdf0e10cSrcweir 		eMode = SortDescending;
345*cdf0e10cSrcweir 	}
346*cdf0e10cSrcweir 	else
347*cdf0e10cSrcweir 	{
348*cdf0e10cSrcweir 		nBits &= ~HIB_DOWNARROW;
349*cdf0e10cSrcweir 		nBits |= HIB_UPARROW;
350*cdf0e10cSrcweir 	}
351*cdf0e10cSrcweir 	pHeaderBar->SetItemBits( ITEMID_TYPE, nBits );
352*cdf0e10cSrcweir 	SvTreeList* pModel = pPathBox->GetModel();
353*cdf0e10cSrcweir 	pModel->SetSortMode( eMode );
354*cdf0e10cSrcweir 	pModel->Resort();
355*cdf0e10cSrcweir 	return 1;
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir // -----------------------------------------------------------------------
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir IMPL_LINK( DbRegistrationOptionsPage, HeaderEndDrag_Impl, HeaderBar*, pBar )
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir 	if ( pBar && !pBar->GetCurItemId() )
363*cdf0e10cSrcweir 		return 0;
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 	if ( !pHeaderBar->IsItemMode() )
366*cdf0e10cSrcweir 	{
367*cdf0e10cSrcweir 		Size aSz;
368*cdf0e10cSrcweir 		sal_uInt16 nTabs = pHeaderBar->GetItemCount();
369*cdf0e10cSrcweir 		long nTmpSz = 0;
370*cdf0e10cSrcweir 		long nWidth = pHeaderBar->GetItemSize(ITEMID_TYPE);
371*cdf0e10cSrcweir 		long nBarWidth = pHeaderBar->GetSizePixel().Width();
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir         if(nWidth < TAB_WIDTH_MIN)
374*cdf0e10cSrcweir             pHeaderBar->SetItemSize( ITEMID_TYPE, TAB_WIDTH_MIN);
375*cdf0e10cSrcweir         else if ( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
376*cdf0e10cSrcweir             pHeaderBar->SetItemSize( ITEMID_TYPE, nBarWidth - TAB_WIDTH_MIN );
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 		for ( sal_uInt16 i = 1; i <= nTabs; ++i )
379*cdf0e10cSrcweir 		{
380*cdf0e10cSrcweir             long _nWidth = pHeaderBar->GetItemSize(i);
381*cdf0e10cSrcweir             aSz.Width() =  _nWidth + nTmpSz;
382*cdf0e10cSrcweir             nTmpSz += _nWidth;
383*cdf0e10cSrcweir 			pPathBox->SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
384*cdf0e10cSrcweir 		}
385*cdf0e10cSrcweir 	}
386*cdf0e10cSrcweir 	return 1;
387*cdf0e10cSrcweir }
388*cdf0e10cSrcweir // -----------------------------------------------------------------------
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir IMPL_LINK( DbRegistrationOptionsPage, PathSelect_Impl, SvTabListBox *, EMPTYARG )
391*cdf0e10cSrcweir {
392*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pPathBox->FirstSelected();
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir     bool bReadOnly = true;
395*cdf0e10cSrcweir     if ( pEntry )
396*cdf0e10cSrcweir     {
397*cdf0e10cSrcweir 	    DatabaseRegistration* pRegistration = static_cast< DatabaseRegistration* >( pEntry->GetUserData() );
398*cdf0e10cSrcweir         bReadOnly = pRegistration->bReadOnly;
399*cdf0e10cSrcweir     }
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir     m_aEdit.Enable( !bReadOnly );
402*cdf0e10cSrcweir 	m_aDelete.Enable( !bReadOnly );
403*cdf0e10cSrcweir 	return 0;
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir // -----------------------------------------------------------------------------
406*cdf0e10cSrcweir void DbRegistrationOptionsPage::insertNewEntry( const ::rtl::OUString& _sName,const ::rtl::OUString& _sLocation, const bool _bReadOnly )
407*cdf0e10cSrcweir {
408*cdf0e10cSrcweir 	String aStr( _sName );
409*cdf0e10cSrcweir 	aStr += '\t';
410*cdf0e10cSrcweir 	aStr += String(_sLocation);
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir     SvLBoxEntry* pEntry = NULL;
413*cdf0e10cSrcweir     if ( _bReadOnly )
414*cdf0e10cSrcweir     {
415*cdf0e10cSrcweir         sal_Bool bHighContrast = pPathBox->GetDisplayBackground().GetColor().IsDark();
416*cdf0e10cSrcweir         Image aLocked( CUI_RES( bHighContrast ? RID_SVXBMP_LOCK_HC : RID_SVXBMP_LOCK ) );
417*cdf0e10cSrcweir         pEntry = pPathBox->InsertEntry( aStr, aLocked, aLocked );
418*cdf0e10cSrcweir     }
419*cdf0e10cSrcweir     else
420*cdf0e10cSrcweir     {
421*cdf0e10cSrcweir         pEntry = pPathBox->InsertEntry( aStr );
422*cdf0e10cSrcweir     }
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir 	pEntry->SetUserData( new DatabaseRegistration( _sLocation, _bReadOnly ) );
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir // -----------------------------------------------------------------------------
428*cdf0e10cSrcweir void DbRegistrationOptionsPage::openLinkDialog(const String& _sOldName,const String& _sOldLocation,SvLBoxEntry* _pEntry)
429*cdf0e10cSrcweir {
430*cdf0e10cSrcweir 	ODocumentLinkDialog aDlg(this,_pEntry == NULL);
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir 	aDlg.set(_sOldName,_sOldLocation);
433*cdf0e10cSrcweir 	aDlg.setNameValidator(LINK( this, DbRegistrationOptionsPage, NameValidator ) );
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 	if ( aDlg.Execute() == RET_OK )
436*cdf0e10cSrcweir 	{
437*cdf0e10cSrcweir 		String sNewName,sNewLocation;
438*cdf0e10cSrcweir 		aDlg.get(sNewName,sNewLocation);
439*cdf0e10cSrcweir 		if ( _pEntry == NULL || sNewName != _sOldName || sNewLocation != _sOldLocation )
440*cdf0e10cSrcweir 		{
441*cdf0e10cSrcweir 			if ( _pEntry )
442*cdf0e10cSrcweir 			{
443*cdf0e10cSrcweir 				delete static_cast< DatabaseRegistration* >( _pEntry->GetUserData() );
444*cdf0e10cSrcweir 				pPathBox->GetModel()->Remove( _pEntry );
445*cdf0e10cSrcweir 			}
446*cdf0e10cSrcweir 			insertNewEntry( sNewName, sNewLocation, false );
447*cdf0e10cSrcweir 			m_bModified = sal_True;
448*cdf0e10cSrcweir 		}
449*cdf0e10cSrcweir 	}
450*cdf0e10cSrcweir }
451*cdf0e10cSrcweir // -----------------------------------------------------------------------------
452*cdf0e10cSrcweir IMPL_LINK( DbRegistrationOptionsPage, NameValidator, String*, _pName )
453*cdf0e10cSrcweir {
454*cdf0e10cSrcweir 	if ( _pName )
455*cdf0e10cSrcweir 	{
456*cdf0e10cSrcweir 		sal_uLong nCount = pPathBox->GetEntryCount();
457*cdf0e10cSrcweir 		for ( sal_uLong i = 0; i < nCount; ++i )
458*cdf0e10cSrcweir 		{
459*cdf0e10cSrcweir 			SvLBoxEntry* pEntry = pPathBox->GetEntry(i);
460*cdf0e10cSrcweir 			if ( (!m_pCurEntry || m_pCurEntry != pEntry) && pPathBox->GetEntryText(pEntry,0) == *_pName )
461*cdf0e10cSrcweir 				return 0L;
462*cdf0e10cSrcweir 		}
463*cdf0e10cSrcweir 	}
464*cdf0e10cSrcweir 	return 1L;
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir //........................................................................
467*cdf0e10cSrcweir }	// namespace svx
468*cdf0e10cSrcweir //........................................................................
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 
471