summaryrefslogtreecommitdiff
path: root/svx/source/cui/dbregister.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'svx/source/cui/dbregister.cxx')
-rw-r--r--svx/source/cui/dbregister.cxx534
1 files changed, 0 insertions, 534 deletions
diff --git a/svx/source/cui/dbregister.cxx b/svx/source/cui/dbregister.cxx
deleted file mode 100644
index 1a5b0019ee9d..000000000000
--- a/svx/source/cui/dbregister.cxx
+++ /dev/null
@@ -1,534 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2008 by Sun Microsystems, Inc.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * $RCSfile: dbregister.cxx,v $
- * $Revision: 1.16 $
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_svx.hxx"
-
-#ifdef SVX_DLLIMPLEMENTATION
-#undef SVX_DLLIMPLEMENTATION
-#endif
-
-#include "dbregister.hxx"
-#include "dbregister.hrc"
-#include "dbregistersettings.hxx"
-#include "connpooloptions.hxx"
-#ifndef SVTOOLS_FILENOTATION_HXX_
-#include <svtools/filenotation.hxx>
-#endif
-#include <svx/dialogs.hrc>
-#include <svx/svxids.hrc>
-#include "helpid.hrc"
-#include <svtools/editbrowsebox.hxx>
-#include <svx/dialogs.hrc>
-#include <vcl/field.hxx>
-#include <svtools/eitem.hxx>
-#include <comphelper/processfactory.hxx>
-#include <com/sun/star/uno/Exception.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
-#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
-#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
-#include <vcl/msgbox.hxx>
-#include <svtools/svtabbx.hxx>
-
-#include <svtools/itemset.hxx>
-#include "doclinkdialog.hxx"
-#include <tools/urlobj.hxx>
-#include <unotools/localfilehelper.hxx>
-#include "optHeaderTabListbox.hxx"
-#include <sfx2/docfilt.hxx>
-#include <svx/dialmgr.hxx>
-#include "dbregisterednamesconfig.hxx"
-
-#define TAB_WIDTH1 80
-#define TAB_WIDTH_MIN 10
-#define TAB_WIDTH2 1000
-#define ITEMID_TYPE 1
-#define ITEMID_PATH 2
-//........................................................................
-namespace svx
-{
-//........................................................................
-
-using namespace ::com::sun::star::lang;
-using namespace ::com::sun::star::ui::dialogs;
-using namespace ::com::sun::star::uno;
-using namespace ::svt;
-
-// class RegistrationItemSetHolder -------------------------------------------------
-
-RegistrationItemSetHolder::RegistrationItemSetHolder( const SfxItemSet& _rMasterSet )
- :m_aRegistrationItems( _rMasterSet )
-{
- DbRegisteredNamesConfig::GetOptions( m_aRegistrationItems );
-}
-
-RegistrationItemSetHolder::~RegistrationItemSetHolder()
-{
-}
-
-// class DatabaseRegistrationDialog ------------------------------------------------
-
-DatabaseRegistrationDialog::DatabaseRegistrationDialog( Window* pParent, const SfxItemSet& rInAttrs )
- :RegistrationItemSetHolder( rInAttrs )
- ,SfxSingleTabDialog( pParent, getRegistrationItems(), RID_SFXPAGE_DBREGISTER )
-{
- SfxTabPage* page = DbRegistrationOptionsPage::Create( this, getRegistrationItems() );
-
- SetTabPage( page );
- SetText( page->GetText() );
-}
-
-DatabaseRegistrationDialog::~DatabaseRegistrationDialog()
-{
-}
-
-short DatabaseRegistrationDialog::Execute()
-{
- short result = SfxSingleTabDialog::Execute();
- if ( result == RET_OK )
- {
- DBG_ASSERT( GetOutputItemSet(), "DatabaseRegistrationDialog::Execute: no output items!" );
- if ( GetOutputItemSet() )
- DbRegisteredNamesConfig::SetOptions( *GetOutputItemSet() );
- }
- return result;
-}
-
-// class DbRegistrationOptionsPage --------------------------------------------------
-
-DbRegistrationOptionsPage::DbRegistrationOptionsPage( Window* pParent, const SfxItemSet& rSet ) :
-
- SfxTabPage( pParent, SVX_RES( RID_SFXPAGE_DBREGISTER), rSet ),
-
- aTypeText ( this, SVX_RES( FT_TYPE ) ),
- aPathText ( this, SVX_RES( FT_PATH ) ),
- aPathCtrl ( this, SVX_RES( LB_PATH ) ),
- m_aNew ( this, SVX_RES( BTN_NEW ) ),
- m_aEdit ( this, SVX_RES( BTN_EDIT ) ),
- m_aDelete ( this, SVX_RES( BTN_DELETE ) ),
- aStdBox ( this, SVX_RES( GB_STD ) ),
- pHeaderBar ( NULL ),
- pPathBox ( NULL ),
- m_pCurEntry ( NULL ),
- m_nOldCount ( 0 ),
- m_bModified ( FALSE )
-{
- m_aNew.SetClickHdl( LINK( this, DbRegistrationOptionsPage, NewHdl ) );
- m_aEdit.SetClickHdl( LINK( this, DbRegistrationOptionsPage, EditHdl ) );
- m_aDelete.SetClickHdl( LINK( this, DbRegistrationOptionsPage, DeleteHdl ) );
-
- Size aBoxSize = aPathCtrl.GetOutputSizePixel();
-
-
- WinBits nBits = WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP;
- pPathBox = new ::svx::OptHeaderTabListBox( &aPathCtrl, nBits );
-
- pHeaderBar = new HeaderBar( &aPathCtrl, WB_BUTTONSTYLE | WB_BOTTOMBORDER );
- pHeaderBar->SetPosSizePixel( Point( 0, 0 ), Size( aBoxSize.Width(), 16 ) );
- pHeaderBar->SetSelectHdl( LINK( this, DbRegistrationOptionsPage, HeaderSelect_Impl ) );
- pHeaderBar->SetEndDragHdl( LINK( this, DbRegistrationOptionsPage, HeaderEndDrag_Impl ) );
- Size aSz;
- aSz.Width() = TAB_WIDTH1;
- pHeaderBar->InsertItem( ITEMID_TYPE, aTypeText.GetText(),
- LogicToPixel( aSz, MapMode( MAP_APPFONT ) ).Width(),
- HIB_LEFT | HIB_VCENTER | HIB_CLICKABLE | HIB_UPARROW );
- aSz.Width() = TAB_WIDTH2;
- pHeaderBar->InsertItem( ITEMID_PATH, aPathText.GetText(),
- LogicToPixel( aSz, MapMode( MAP_APPFONT ) ).Width(),
- HIB_LEFT | HIB_VCENTER );
-
- static long nTabs[] = {3, 0, TAB_WIDTH1, TAB_WIDTH1 + TAB_WIDTH2 };
- Size aHeadSize = pHeaderBar->GetSizePixel();
-
- aPathCtrl.SetFocusControl( pPathBox );
- pPathBox->SetWindowBits( nBits );
- pPathBox->SetDoubleClickHdl( LINK( this, DbRegistrationOptionsPage, EditHdl ) );
- pPathBox->SetSelectHdl( LINK( this, DbRegistrationOptionsPage, PathSelect_Impl ) );
- pPathBox->SetSelectionMode( SINGLE_SELECTION );
- pPathBox->SetPosSizePixel( Point( 0, aHeadSize.Height() ),
- Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) );
- pPathBox->SetTabs( &nTabs[0], MAP_APPFONT );
- pPathBox->InitHeaderBar( pHeaderBar );
- pPathBox->SetHighlightRange();
-
- pPathBox->SetHelpId( HID_DBPATH_CTL_PATH );
- pHeaderBar->SetHelpId( HID_DBPATH_HEADERBAR );
-
- pPathBox->Show();
- pHeaderBar->Show();
-
- FreeResource();
-}
-
-// -----------------------------------------------------------------------
-
-DbRegistrationOptionsPage::~DbRegistrationOptionsPage()
-{
- // #110603# do not grab focus to a destroyed window !!!
- aPathCtrl.SetFocusControl( NULL );
-
- pHeaderBar->Hide();
- for ( USHORT i = 0; i < pPathBox->GetEntryCount(); ++i )
- delete static_cast< DatabaseRegistration* >( pPathBox->GetEntry(i)->GetUserData() );
- delete pPathBox;
- delete pHeaderBar;
-}
-
-// -----------------------------------------------------------------------
-
-SfxTabPage* DbRegistrationOptionsPage::Create( Window* pParent,
- const SfxItemSet& rAttrSet )
-{
- return ( new DbRegistrationOptionsPage( pParent, rAttrSet ) );
-}
-
-// -----------------------------------------------------------------------
-
-BOOL DbRegistrationOptionsPage::FillItemSet( SfxItemSet& rCoreSet )
-{
- // the settings for the single drivers
- sal_Bool bModified = sal_False;
- DatabaseRegistrations aRegistrations;
- ULONG nCount = pPathBox->GetEntryCount();
- for ( ULONG i = 0; i < nCount; ++i )
- {
- SvLBoxEntry* pEntry = pPathBox->GetEntry(i);
- DatabaseRegistration* pRegistration = static_cast< DatabaseRegistration* >( pEntry->GetUserData() );
- if ( pRegistration && pRegistration->sLocation.getLength() )
- {
- ::rtl::OUString sName( pPathBox->GetEntryText( pEntry, 0 ) );
- OFileNotation aTransformer( pRegistration->sLocation );
- aRegistrations[ sName ] = DatabaseRegistration( aTransformer.get( OFileNotation::N_URL ), pRegistration->bReadOnly );
- }
- }
- if ( m_nOldCount != aRegistrations.size() || m_bModified )
- {
- rCoreSet.Put(DatabaseMapItem( SID_SB_DB_REGISTER, aRegistrations ), SID_SB_DB_REGISTER);
- bModified = sal_True;
- }
-
- return bModified;
-}
-
-// -----------------------------------------------------------------------
-
-void DbRegistrationOptionsPage::Reset( const SfxItemSet& rSet )
-{
- // the settings for the single drivers
- SFX_ITEMSET_GET( rSet, pRegistrations, DatabaseMapItem, SID_SB_DB_REGISTER, sal_True );
- if ( !pRegistrations )
- return;
-
- pPathBox->Clear();
-
- const DatabaseRegistrations& rRegistrations = pRegistrations->getRegistrations();
- m_nOldCount = rRegistrations.size();
- DatabaseRegistrations::const_iterator aIter = rRegistrations.begin();
- DatabaseRegistrations::const_iterator aEnd = rRegistrations.end();
- for ( ; aIter != aEnd; ++aIter )
- {
- OFileNotation aTransformer( aIter->second.sLocation );
- insertNewEntry( aIter->first, aTransformer.get( OFileNotation::N_SYSTEM ), aIter->second.bReadOnly );
- }
-
- String aUserData = GetUserData();
- if ( aUserData.Len() )
- {
- // Spaltenbreite restaurieren
- pHeaderBar->SetItemSize( ITEMID_TYPE, aUserData.GetToken(0).ToInt32() );
- HeaderEndDrag_Impl( NULL );
- // Sortierrichtung restaurieren
- BOOL bUp = (BOOL)(USHORT)aUserData.GetToken(1).ToInt32();
- HeaderBarItemBits nBits = pHeaderBar->GetItemBits(ITEMID_TYPE);
-
- if ( bUp )
- {
- nBits &= ~HIB_UPARROW;
- nBits |= HIB_DOWNARROW;
- }
- else
- {
- nBits &= ~HIB_DOWNARROW;
- nBits |= HIB_UPARROW;
- }
- pHeaderBar->SetItemBits( ITEMID_TYPE, nBits );
- HeaderSelect_Impl( NULL );
- }
-}
-
-// -----------------------------------------------------------------------
-
-void DbRegistrationOptionsPage::FillUserData()
-{
- String aUserData = String::CreateFromInt32( pHeaderBar->GetItemSize( ITEMID_TYPE ) );
- aUserData += ';';
- HeaderBarItemBits nBits = pHeaderBar->GetItemBits( ITEMID_TYPE );
- BOOL bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
- aUserData += bUp ? '1' : '0';
- SetUserData( aUserData );
-}
-// -----------------------------------------------------------------------
-
-IMPL_LINK( DbRegistrationOptionsPage, DeleteHdl, void *, EMPTYARG )
-{
- SvLBoxEntry* pEntry = pPathBox->FirstSelected();
- if ( pEntry )
- {
- QueryBox aQuery(this,SVX_RES(QUERY_DELETE_CONFIRM));
- if ( aQuery.Execute() == RET_YES )
- pPathBox->GetModel()->Remove(pEntry);
- }
- return 0;
-}
-// -----------------------------------------------------------------------
-IMPL_LINK( DbRegistrationOptionsPage, NewHdl, void *, EMPTYARG )
-{
- String sNewName,sNewLocation;
- openLinkDialog(sNewName,sNewLocation);
- return 0;
-}
-
-// -----------------------------------------------------------------------
-
-IMPL_LINK( DbRegistrationOptionsPage, EditHdl, void *, EMPTYARG )
-{
- SvLBoxEntry* pEntry = pPathBox->GetCurEntry();
- if ( !pEntry )
- return 0L;
-
- DatabaseRegistration* pOldRegistration = static_cast< DatabaseRegistration* >( pEntry->GetUserData() );
- if ( !pOldRegistration || pOldRegistration->bReadOnly )
- return 0L;
-
- String sOldName = pPathBox->GetEntryText(pEntry,0);
- m_pCurEntry = pEntry;
- openLinkDialog( sOldName, pOldRegistration->sLocation, pEntry );
- m_pCurEntry = NULL;
-
- return 1L;
-}
-
-// -----------------------------------------------------------------------
-
-IMPL_LINK( DbRegistrationOptionsPage, HeaderSelect_Impl, HeaderBar*, pBar )
-{
- if ( pBar && pBar->GetCurItemId() != ITEMID_TYPE )
- return 0;
-
- HeaderBarItemBits nBits = pHeaderBar->GetItemBits(ITEMID_TYPE);
- BOOL bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
- SvSortMode eMode = SortAscending;
-
- if ( bUp )
- {
- nBits &= ~HIB_UPARROW;
- nBits |= HIB_DOWNARROW;
- eMode = SortDescending;
- }
- else
- {
- nBits &= ~HIB_DOWNARROW;
- nBits |= HIB_UPARROW;
- }
- pHeaderBar->SetItemBits( ITEMID_TYPE, nBits );
- SvTreeList* pModel = pPathBox->GetModel();
- pModel->SetSortMode( eMode );
- pModel->Resort();
- return 1;
-}
-
-// -----------------------------------------------------------------------
-
-IMPL_LINK( DbRegistrationOptionsPage, HeaderEndDrag_Impl, HeaderBar*, pBar )
-{
- if ( pBar && !pBar->GetCurItemId() )
- return 0;
-
- if ( !pHeaderBar->IsItemMode() )
- {
- Size aSz;
- USHORT nTabs = pHeaderBar->GetItemCount();
- long nTmpSz = 0;
- long nWidth = pHeaderBar->GetItemSize(ITEMID_TYPE);
- long nBarWidth = pHeaderBar->GetSizePixel().Width();
-
- if(nWidth < TAB_WIDTH_MIN)
- pHeaderBar->SetItemSize( ITEMID_TYPE, TAB_WIDTH_MIN);
- else if ( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
- pHeaderBar->SetItemSize( ITEMID_TYPE, nBarWidth - TAB_WIDTH_MIN );
-
- for ( USHORT i = 1; i <= nTabs; ++i )
- {
- long _nWidth = pHeaderBar->GetItemSize(i);
- aSz.Width() = _nWidth + nTmpSz;
- nTmpSz += _nWidth;
- pPathBox->SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
- }
- }
- return 1;
-}
-// -----------------------------------------------------------------------
-
-IMPL_LINK( DbRegistrationOptionsPage, PathSelect_Impl, SvTabListBox *, EMPTYARG )
-{
- SvLBoxEntry* pEntry = pPathBox->FirstSelected();
-
- bool bReadOnly = true;
- if ( pEntry )
- {
- DatabaseRegistration* pRegistration = static_cast< DatabaseRegistration* >( pEntry->GetUserData() );
- bReadOnly = pRegistration->bReadOnly;
- }
-
- m_aEdit.Enable( !bReadOnly );
- m_aDelete.Enable( !bReadOnly );
- return 0;
-}
-// -----------------------------------------------------------------------------
-void DbRegistrationOptionsPage::insertNewEntry( const ::rtl::OUString& _sName,const ::rtl::OUString& _sLocation, const bool _bReadOnly )
-{
- String aStr( _sName );
- aStr += '\t';
- aStr += String(_sLocation);
-
- SvLBoxEntry* pEntry = NULL;
- if ( _bReadOnly )
- {
- sal_Bool bHighContrast = pPathBox->GetDisplayBackground().GetColor().IsDark();
- Image aLocked( SVX_RES( bHighContrast ? RID_SVXBMP_LOCK_HC : RID_SVXBMP_LOCK ) );
- pEntry = pPathBox->InsertEntry( aStr, aLocked, aLocked );
- }
- else
- {
- pEntry = pPathBox->InsertEntry( aStr );
- }
-
- pEntry->SetUserData( new DatabaseRegistration( _sLocation, _bReadOnly ) );
-}
-
-// -----------------------------------------------------------------------------
-String DbRegistrationOptionsPage::getFileLocation(const String& _sLocation)
-{
- try
- {
- rtl::OUString aService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) );
- Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
- Reference < XFilePicker > xFilePicker( xFactory->createInstance( aService ), UNO_QUERY );
- OSL_ENSURE(xFilePicker.is() ,"Could create file picker service!");
- Reference < XFilterManager> xFilterManager(xFilePicker,UNO_QUERY);
- static const String s_sDatabaseType = String::CreateFromAscii("StarOffice XML (Base)");
- const SfxFilter* pFilter = SfxFilter::GetFilterByName( s_sDatabaseType);
- if ( pFilter )
- {
- xFilterManager->appendFilter( pFilter->GetUIName(),pFilter->GetDefaultExtension());
- xFilterManager->setCurrentFilter(pFilter->GetUIName());
- }
-
- INetURLObject aURL( _sLocation, INET_PROT_FILE );
- xFilePicker->setMultiSelectionMode(sal_False);
- xFilePicker->setDisplayDirectory( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
- short nRet = xFilePicker->execute();
-
- if ( ExecutableDialogResults::OK == nRet )
- {
-
- // old path is an URL?
- INetURLObject aObj( _sLocation );
- FASTBOOL bURL = ( aObj.GetProtocol() != INET_PROT_NOT_VALID );
- Sequence< ::rtl::OUString > aFiles = xFilePicker->getFiles();
- INetURLObject aNewObj( aFiles[0] );
- aNewObj.removeFinalSlash();
-
- // then the new path also an URL else system path
- String sNewLocation = bURL ? rtl::OUString(aFiles[0]) : aNewObj.getFSysPath( INetURLObject::FSYS_DETECT );
-
- if (
-#ifdef UNX
- // Unix is case sensitive
- ( sNewLocation != _sLocation )
-#else
- ( sNewLocation.CompareIgnoreCaseToAscii( _sLocation ) != COMPARE_EQUAL )
-#endif
- )
- return sNewLocation;
- }
- }
- catch( Exception& )
- {
- DBG_ERRORFILE( "DbRegistrationOptionsPage::EditLocationHdl: exception from folder picker" );
- }
-
- return String();
-}
-// -----------------------------------------------------------------------------
-void DbRegistrationOptionsPage::openLinkDialog(const String& _sOldName,const String& _sOldLocation,SvLBoxEntry* _pEntry)
-{
- ODocumentLinkDialog aDlg(this,_pEntry == NULL);
-
- aDlg.set(_sOldName,_sOldLocation);
- aDlg.setNameValidator(LINK( this, DbRegistrationOptionsPage, NameValidator ) );
-
- if ( aDlg.Execute() == RET_OK )
- {
- String sNewName,sNewLocation;
- aDlg.get(sNewName,sNewLocation);
- if ( _pEntry == NULL || sNewName != _sOldName || sNewLocation != _sOldLocation )
- {
- if ( _pEntry )
- {
- delete static_cast< DatabaseRegistration* >( _pEntry->GetUserData() );
- pPathBox->GetModel()->Remove( _pEntry );
- }
- insertNewEntry( sNewName, sNewLocation, false );
- m_bModified = sal_True;
- }
- }
-}
-// -----------------------------------------------------------------------------
-IMPL_LINK( DbRegistrationOptionsPage, NameValidator, String*, _pName )
-{
- if ( _pName )
- {
- ULONG nCount = pPathBox->GetEntryCount();
- for ( ULONG i = 0; i < nCount; ++i )
- {
- SvLBoxEntry* pEntry = pPathBox->GetEntry(i);
- if ( (!m_pCurEntry || m_pCurEntry != pEntry) && pPathBox->GetEntryText(pEntry,0) == *_pName )
- return 0L;
- }
- }
- return 1L;
-}
-//........................................................................
-} // namespace svx
-//........................................................................
-
-