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