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 // MARKER(update_precomp.py): autogen include statement, do not remove 28*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 29*cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_ 30*cdf0e10cSrcweir #include "moduledbu.hxx" 31*cdf0e10cSrcweir #endif 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #ifndef DBAUI_TEXTCONNECTIONHELPER_HXX 34*cdf0e10cSrcweir #include "TextConnectionHelper.hxx" 35*cdf0e10cSrcweir #endif 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #ifndef _DBAUI_SQLMESSAGE_HXX_ 38*cdf0e10cSrcweir #include "sqlmessage.hxx" 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_ 41*cdf0e10cSrcweir #include "dbu_dlg.hrc" 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #ifndef _DBU_RESOURCE_HRC_ 44*cdf0e10cSrcweir #include "dbu_resource.hrc" 45*cdf0e10cSrcweir #endif 46*cdf0e10cSrcweir #ifndef _DBAUI_AUTOCONTROLS_HRC_ 47*cdf0e10cSrcweir #include "AutoControls.hrc" 48*cdf0e10cSrcweir #endif 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #ifndef _SFXITEMSET_HXX 51*cdf0e10cSrcweir #include <svl/itemset.hxx> 52*cdf0e10cSrcweir #endif 53*cdf0e10cSrcweir #ifndef _SFXSTRITEM_HXX 54*cdf0e10cSrcweir #include <svl/stritem.hxx> 55*cdf0e10cSrcweir #endif 56*cdf0e10cSrcweir #ifndef _SFXENUMITEM_HXX 57*cdf0e10cSrcweir #include <svl/eitem.hxx> 58*cdf0e10cSrcweir #endif 59*cdf0e10cSrcweir #ifndef _SFXINTITEM_HXX 60*cdf0e10cSrcweir #include <svl/intitem.hxx> 61*cdf0e10cSrcweir #endif 62*cdf0e10cSrcweir #ifndef _DBAUI_DATASOURCEITEMS_HXX_ 63*cdf0e10cSrcweir #include "dsitems.hxx" 64*cdf0e10cSrcweir #endif 65*cdf0e10cSrcweir #ifndef _DBAUI_DBFINDEX_HXX_ 66*cdf0e10cSrcweir #include "dbfindex.hxx" 67*cdf0e10cSrcweir #endif 68*cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_ 69*cdf0e10cSrcweir #include "dbaccess_helpid.hrc" 70*cdf0e10cSrcweir #endif 71*cdf0e10cSrcweir #ifndef _DBAUI_LOCALRESACCESS_HXX_ 72*cdf0e10cSrcweir #include "localresaccess.hxx" 73*cdf0e10cSrcweir #endif 74*cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX 75*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 76*cdf0e10cSrcweir #endif 77*cdf0e10cSrcweir #ifndef _SV_MNEMONIC_HXX 78*cdf0e10cSrcweir #include <vcl/mnemonic.hxx> 79*cdf0e10cSrcweir #endif 80*cdf0e10cSrcweir #ifndef _SVTOOLS_CJKOPTIONS_HXX 81*cdf0e10cSrcweir #include <svl/cjkoptions.hxx> 82*cdf0e10cSrcweir #endif 83*cdf0e10cSrcweir #include <jvmaccess/virtualmachine.hxx> 84*cdf0e10cSrcweir #ifndef _DBAUI_ADASTAT_HXX_ 85*cdf0e10cSrcweir #include "AdabasStat.hxx" 86*cdf0e10cSrcweir #endif 87*cdf0e10cSrcweir #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ 88*cdf0e10cSrcweir #include <connectivity/CommonTools.hxx> 89*cdf0e10cSrcweir #endif 90*cdf0e10cSrcweir #ifndef DBAUI_DRIVERSETTINGS_HXX 91*cdf0e10cSrcweir #include "DriverSettings.hxx" 92*cdf0e10cSrcweir #endif 93*cdf0e10cSrcweir #ifndef _DBAUI_DBADMIN_HXX_ 94*cdf0e10cSrcweir #include "dbadmin.hxx" 95*cdf0e10cSrcweir #endif 96*cdf0e10cSrcweir #ifndef _COMPHELPER_TYPES_HXX_ 97*cdf0e10cSrcweir #include <comphelper/types.hxx> 98*cdf0e10cSrcweir #endif 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_DIALOGS_XFOLDERPICKER_HPP_ 101*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFolderPicker.hpp> 102*cdf0e10cSrcweir #endif 103*cdf0e10cSrcweir // #106016# ------------------------------------ 104*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_ 105*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 106*cdf0e10cSrcweir #endif 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir #ifndef SVTOOLS_FILENOTATION_HXX_ 109*cdf0e10cSrcweir #include <svl/filenotation.hxx> 110*cdf0e10cSrcweir #endif 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir #ifndef _UNOTOOLS_LOCALFILEHELPER_HXX 113*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx> 114*cdf0e10cSrcweir #endif 115*cdf0e10cSrcweir #ifndef _UNOTOOLS_UCBHELPER_HXX 116*cdf0e10cSrcweir #include <unotools/ucbhelper.hxx> 117*cdf0e10cSrcweir #endif 118*cdf0e10cSrcweir #ifndef _UCBHELPER_COMMANDENVIRONMENT_HXX 119*cdf0e10cSrcweir #include <ucbhelper/commandenvironment.hxx> 120*cdf0e10cSrcweir #endif 121*cdf0e10cSrcweir #ifndef DBAUI_FILEPICKER_INTERACTION_HXX 122*cdf0e10cSrcweir #include "finteraction.hxx" 123*cdf0e10cSrcweir #endif 124*cdf0e10cSrcweir #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ 125*cdf0e10cSrcweir #include <connectivity/CommonTools.hxx> 126*cdf0e10cSrcweir #endif 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir #ifndef DBAUI_DBSETUPCONNECTIONPAGES_HXX 129*cdf0e10cSrcweir #include "DBSetupConnectionPages.hxx" 130*cdf0e10cSrcweir #endif 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_ 133*cdf0e10cSrcweir #include "dbu_dlg.hrc" 134*cdf0e10cSrcweir #endif 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_ 137*cdf0e10cSrcweir #include "dbaccess_helpid.hrc" 138*cdf0e10cSrcweir #endif 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX 141*cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 142*cdf0e10cSrcweir #endif 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir #ifndef SVTOOLS_INC_ROADMAPWIZARD_HXX 145*cdf0e10cSrcweir #include <svtools/roadmapwizard.hxx> 146*cdf0e10cSrcweir #endif 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir namespace dbaui 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir //======================================================================== 153*cdf0e10cSrcweir //= OTextConnectionPageSetup 154*cdf0e10cSrcweir //======================================================================== 155*cdf0e10cSrcweir DBG_NAME(OTextConnectionHelper) 156*cdf0e10cSrcweir //------------------------------------------------------------------------ 157*cdf0e10cSrcweir OTextConnectionHelper::OTextConnectionHelper( Window* pParent, const short _nAvailableSections ) 158*cdf0e10cSrcweir :Control( pParent, WB_DIALOGCONTROL ) 159*cdf0e10cSrcweir ,m_aFTExtensionHeader (this, ModuleRes(FT_AUTOEXTENSIONHEADER)) 160*cdf0e10cSrcweir ,m_aRBAccessTextFiles (this, ModuleRes(RB_AUTOACCESSCTEXTFILES)) 161*cdf0e10cSrcweir ,m_aRBAccessCSVFiles (this, ModuleRes(RB_AUTOACCESSCCSVFILES)) 162*cdf0e10cSrcweir ,m_aRBAccessOtherFiles (this, ModuleRes(RB_AUTOACCESSOTHERS)) 163*cdf0e10cSrcweir ,m_aETOwnExtension (this, ModuleRes(ET_AUTOOWNEXTENSION)) 164*cdf0e10cSrcweir ,m_aFTExtensionExample (this, ModuleRes(FT_AUTOOWNEXTENSIONAPPENDIX)) 165*cdf0e10cSrcweir ,m_aLineFormat (this, ModuleRes(FL_AUTOSEPARATOR2)) 166*cdf0e10cSrcweir ,m_aFieldSeparatorLabel (this, ModuleRes(FT_AUTOFIELDSEPARATOR)) 167*cdf0e10cSrcweir ,m_aFieldSeparator (this, ModuleRes(CM_AUTOFIELDSEPARATOR)) 168*cdf0e10cSrcweir ,m_aTextSeparatorLabel (this, ModuleRes(FT_AUTOTEXTSEPARATOR)) 169*cdf0e10cSrcweir ,m_aTextSeparator (this, ModuleRes(CM_AUTOTEXTSEPARATOR)) 170*cdf0e10cSrcweir ,m_aDecimalSeparatorLabel (this, ModuleRes(FT_AUTODECIMALSEPARATOR)) 171*cdf0e10cSrcweir ,m_aDecimalSeparator (this, ModuleRes(CM_AUTODECIMALSEPARATOR)) 172*cdf0e10cSrcweir ,m_aThousandsSeparatorLabel (this, ModuleRes(FT_AUTOTHOUSANDSSEPARATOR)) 173*cdf0e10cSrcweir ,m_aThousandsSeparator (this, ModuleRes(CM_AUTOTHOUSANDSSEPARATOR)) 174*cdf0e10cSrcweir ,m_aRowHeader (this, ModuleRes(CB_AUTOHEADER)) 175*cdf0e10cSrcweir ,m_aCharSetHeader (this, ModuleRes(FL_DATACONVERT)) 176*cdf0e10cSrcweir ,m_aCharSetLabel (this, ModuleRes(FT_CHARSET)) 177*cdf0e10cSrcweir ,m_aCharSet (this, ModuleRes(LB_CHARSET)) 178*cdf0e10cSrcweir ,m_aFieldSeparatorList (ModuleRes(STR_AUTOFIELDSEPARATORLIST)) 179*cdf0e10cSrcweir ,m_aTextSeparatorList (ModuleRes(STR_AUTOTEXTSEPARATORLIST)) 180*cdf0e10cSrcweir ,m_aTextNone (ModuleRes(STR_AUTOTEXT_FIELD_SEP_NONE)) 181*cdf0e10cSrcweir ,m_nAvailableSections( _nAvailableSections ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir DBG_CTOR(OTextConnectionHelper,NULL); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir xub_StrLen nCnt = m_aFieldSeparatorList.GetTokenCount( '\t' ); 186*cdf0e10cSrcweir xub_StrLen i; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir for( i = 0 ; i < nCnt ; i += 2 ) 189*cdf0e10cSrcweir m_aFieldSeparator.InsertEntry( m_aFieldSeparatorList.GetToken( i, '\t' ) ); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir nCnt = m_aTextSeparatorList.GetTokenCount( '\t' ); 192*cdf0e10cSrcweir for( i=0 ; i<nCnt ; i+=2 ) 193*cdf0e10cSrcweir m_aTextSeparator.InsertEntry( m_aTextSeparatorList.GetToken( i, '\t' ) ); 194*cdf0e10cSrcweir m_aTextSeparator.InsertEntry(m_aTextNone); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // set the modify handlers 197*cdf0e10cSrcweir m_aFieldSeparator.SetUpdateDataHdl(getControlModifiedLink()); 198*cdf0e10cSrcweir m_aFieldSeparator.SetSelectHdl(getControlModifiedLink()); 199*cdf0e10cSrcweir m_aTextSeparator.SetUpdateDataHdl(getControlModifiedLink()); 200*cdf0e10cSrcweir m_aTextSeparator.SetSelectHdl(getControlModifiedLink()); 201*cdf0e10cSrcweir m_aCharSet.SetSelectHdl(getControlModifiedLink()); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir m_aFieldSeparator.SetModifyHdl(getControlModifiedLink()); 204*cdf0e10cSrcweir m_aTextSeparator.SetModifyHdl(getControlModifiedLink()); 205*cdf0e10cSrcweir m_aDecimalSeparator.SetModifyHdl(getControlModifiedLink()); 206*cdf0e10cSrcweir m_aThousandsSeparator.SetModifyHdl(getControlModifiedLink()); 207*cdf0e10cSrcweir m_aETOwnExtension.SetModifyHdl(LINK(this, OTextConnectionHelper, OnEditModified)); 208*cdf0e10cSrcweir m_aRBAccessTextFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl)); 209*cdf0e10cSrcweir m_aRBAccessCSVFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl)); 210*cdf0e10cSrcweir m_aRBAccessOtherFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl)); 211*cdf0e10cSrcweir m_aRBAccessCSVFiles.Check(sal_True); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir struct SectionDescriptor 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir short nFlag; 216*cdf0e10cSrcweir Window* pFirstControl; 217*cdf0e10cSrcweir } aSections[] = { 218*cdf0e10cSrcweir { TC_EXTENSION, &m_aFTExtensionHeader }, 219*cdf0e10cSrcweir { TC_SEPARATORS, &m_aLineFormat }, 220*cdf0e10cSrcweir { TC_HEADER, &m_aRowHeader }, 221*cdf0e10cSrcweir { TC_CHARSET, &m_aCharSetHeader }, 222*cdf0e10cSrcweir { 0, NULL } 223*cdf0e10cSrcweir }; 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir for ( size_t section=0; section < sizeof( aSections ) / sizeof( aSections[0] ) - 1; ++section ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir if ( ( m_nAvailableSections & aSections[section].nFlag ) != 0 ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir // the section is visible, no need to do anything here 230*cdf0e10cSrcweir continue; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir Window* pThisSection = aSections[section].pFirstControl; 234*cdf0e10cSrcweir Window* pNextSection = aSections[section+1].pFirstControl; 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir // hide all elements from this section 237*cdf0e10cSrcweir Window* pControl = pThisSection; 238*cdf0e10cSrcweir while ( ( pControl != pNextSection ) && pControl ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir Window* pRealWindow = pControl->GetWindow( WINDOW_CLIENT ); 241*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 242*cdf0e10cSrcweir String sWindowText( pRealWindow->GetText() ); 243*cdf0e10cSrcweir (void)sWindowText; 244*cdf0e10cSrcweir #endif 245*cdf0e10cSrcweir pRealWindow->Hide(); 246*cdf0e10cSrcweir pControl = pControl->GetWindow( WINDOW_NEXT ); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir // move all controls in following sections up 250*cdf0e10cSrcweir if ( !pNextSection ) 251*cdf0e10cSrcweir continue; 252*cdf0e10cSrcweir const long nThisSectionStart = pThisSection->GetPosPixel().Y(); 253*cdf0e10cSrcweir const long nNextSectionStart = pNextSection->GetPosPixel().Y(); 254*cdf0e10cSrcweir const long nMoveOffset( nThisSectionStart - nNextSectionStart ); 255*cdf0e10cSrcweir while ( pControl ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir Point aPos = pControl->GetPosPixel(); 258*cdf0e10cSrcweir aPos.Move( 0, nMoveOffset ); 259*cdf0e10cSrcweir pControl->SetPosPixel( aPos ); 260*cdf0e10cSrcweir pControl = pControl->GetWindow( WINDOW_NEXT ); 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir Rectangle aControlRectUnion; 265*cdf0e10cSrcweir for ( Window* pControl = aSections[0].pFirstControl; 266*cdf0e10cSrcweir pControl != NULL; 267*cdf0e10cSrcweir pControl = pControl->GetWindow( WINDOW_NEXT ) 268*cdf0e10cSrcweir ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir aControlRectUnion = aControlRectUnion.Union( Rectangle( pControl->GetPosPixel(), pControl->GetSizePixel() ) ); 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir // need some adjustments to the positions, since the resource-specified 274*cdf0e10cSrcweir // positions for the control were relative to *our* parent, while by now 275*cdf0e10cSrcweir // the controls have |this| as parent. 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir // first, move ourself to the upper left of the area occupied by all controls 278*cdf0e10cSrcweir SetPosPixel( aControlRectUnion.TopLeft() ); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir // then, compensate in the control positions, by moving them the up/left 281*cdf0e10cSrcweir for ( Window* pControl = aSections[0].pFirstControl; 282*cdf0e10cSrcweir pControl != NULL; 283*cdf0e10cSrcweir pControl = pControl->GetWindow( WINDOW_NEXT ) 284*cdf0e10cSrcweir ) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir Point aPos( pControl->GetPosPixel() ); 287*cdf0e10cSrcweir aPos.Move( -aControlRectUnion.Left(), -aControlRectUnion.Top() ); 288*cdf0e10cSrcweir pControl->SetPosPixel( aPos ); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir // while we are here ... the controls should not have an own background 291*cdf0e10cSrcweir // (this would not be needed when our outer dialog were also the parent 292*cdf0e10cSrcweir // of the controls) 293*cdf0e10cSrcweir pControl->SetBackground(); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir // now, change our own size so all controls fit 297*cdf0e10cSrcweir SetSizePixel( aControlRectUnion.GetSize() ); 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir SetBackground(); 300*cdf0e10cSrcweir Show(); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir // ----------------------------------------------------------------------- 304*cdf0e10cSrcweir OTextConnectionHelper::~OTextConnectionHelper() 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir DBG_DTOR(OTextConnectionHelper,NULL); 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir // ----------------------------------------------------------------------- 312*cdf0e10cSrcweir IMPL_LINK(OTextConnectionHelper, OnControlModified, Control*, /*EMPTYARG*/) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir callModifiedHdl(); 315*cdf0e10cSrcweir return 0L; 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir // ----------------------------------------------------------------------- 319*cdf0e10cSrcweir IMPL_LINK(OTextConnectionHelper, OnEditModified, Edit*, /*_pEdit*/) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir m_aGetExtensionHandler.Call(this); 322*cdf0e10cSrcweir return 0L; 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir IMPL_LINK(OTextConnectionHelper, OnSetExtensionHdl, RadioButton*, /*_pRadioButton*/) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir sal_Bool bDoEnable = m_aRBAccessOtherFiles.IsChecked(); 329*cdf0e10cSrcweir m_aETOwnExtension.Enable(bDoEnable); 330*cdf0e10cSrcweir m_aFTExtensionExample.Enable(bDoEnable); 331*cdf0e10cSrcweir m_aGetExtensionHandler.Call(this); 332*cdf0e10cSrcweir return 0L; 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir // ----------------------------------------------------------------------- 337*cdf0e10cSrcweir void OTextConnectionHelper::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList) 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aFieldSeparator)); 340*cdf0e10cSrcweir _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aTextSeparator)); 341*cdf0e10cSrcweir _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aDecimalSeparator)); 342*cdf0e10cSrcweir _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aThousandsSeparator)); 343*cdf0e10cSrcweir _rControlList.push_back(new OSaveValueWrapper<CheckBox>(&m_aRowHeader)); 344*cdf0e10cSrcweir _rControlList.push_back(new OSaveValueWrapper<ListBox>(&m_aCharSet)); 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir // ----------------------------------------------------------------------- 347*cdf0e10cSrcweir void OTextConnectionHelper::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFieldSeparatorLabel)); 350*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aTextSeparatorLabel)); 351*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aDecimalSeparatorLabel)); 352*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aThousandsSeparatorLabel)); 353*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aCharSetHeader)); 354*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aCharSetLabel)); 355*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<ListBox>(&m_aCharSet)); 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir // ----------------------------------------------------------------------- 359*cdf0e10cSrcweir void OTextConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool _bValid) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir if ( !_bValid ) 362*cdf0e10cSrcweir return; 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pDelItem, SfxStringItem, DSID_FIELDDELIMITER, sal_True ); 365*cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pStrItem, SfxStringItem, DSID_TEXTDELIMITER, sal_True ); 366*cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pDecdelItem, SfxStringItem, DSID_DECIMALDELIMITER, sal_True ); 367*cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pThodelItem, SfxStringItem, DSID_THOUSANDSDELIMITER, sal_True ); 368*cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pExtensionItem, SfxStringItem, DSID_TEXTFILEEXTENSION, sal_True ); 369*cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pCharsetItem, SfxStringItem, DSID_CHARSET, sal_True ); 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir if ( ( m_nAvailableSections & TC_EXTENSION ) != 0 ) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir m_aOldExtension = pExtensionItem->GetValue(); 374*cdf0e10cSrcweir SetExtension( m_aOldExtension ); 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir if ( ( m_nAvailableSections & TC_HEADER ) != 0 ) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir SFX_ITEMSET_GET( _rSet, pHdrItem, SfxBoolItem, DSID_TEXTFILEHEADER, sal_True ); 380*cdf0e10cSrcweir m_aRowHeader.Check( pHdrItem->GetValue() ); 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir if ( ( m_nAvailableSections & TC_SEPARATORS ) != 0 ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir SetSeparator( m_aFieldSeparator, m_aFieldSeparatorList, pDelItem->GetValue() ); 386*cdf0e10cSrcweir SetSeparator( m_aTextSeparator, m_aTextSeparatorList, pStrItem->GetValue() ); 387*cdf0e10cSrcweir m_aDecimalSeparator.SetText( pDecdelItem->GetValue() ); 388*cdf0e10cSrcweir m_aThousandsSeparator.SetText( pThodelItem->GetValue() ); 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir if ( ( m_nAvailableSections & TC_CHARSET ) != 0 ) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir m_aCharSet.SelectEntryByIanaName( pCharsetItem->GetValue() ); 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir // ----------------------------------------------------------------------- 400*cdf0e10cSrcweir sal_Bool OTextConnectionHelper::prepareLeave() 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir LocalResourceAccess aStringResAccess(PAGE_TEXT, RSC_TABPAGE); 403*cdf0e10cSrcweir // for accessing the strings which are local to our own resource block 404*cdf0e10cSrcweir String sExtension = GetExtension(); 405*cdf0e10cSrcweir String aErrorText; 406*cdf0e10cSrcweir Control* pErrorWin = NULL; 407*cdf0e10cSrcweir // if (!m_aFieldSeparator.GetText().Len()) 408*cdf0e10cSrcweir // bug (#42168) if this line is compiled under OS2 (in a product environent) 409*cdf0e10cSrcweir // -> use a temporary variable 410*cdf0e10cSrcweir String aDelText(m_aFieldSeparator.GetText()); 411*cdf0e10cSrcweir if(!aDelText.Len()) 412*cdf0e10cSrcweir { // Kein FeldTrenner 413*cdf0e10cSrcweir aErrorText = String(ModuleRes(STR_AUTODELIMITER_MISSING)); 414*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#1",m_aFieldSeparatorLabel.GetText()); 415*cdf0e10cSrcweir pErrorWin = &m_aFieldSeparator; 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir else if (!m_aDecimalSeparator.GetText().Len()) 418*cdf0e10cSrcweir { // kein Decimaltrenner 419*cdf0e10cSrcweir aErrorText = String(ModuleRes(STR_AUTODELIMITER_MISSING)); 420*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#1",m_aDecimalSeparatorLabel.GetText()); 421*cdf0e10cSrcweir pErrorWin = &m_aDecimalSeparator; 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir else if (m_aTextSeparator.GetText() == m_aFieldSeparator.GetText()) 424*cdf0e10cSrcweir { // Feld und TextTrenner duerfen nicht gleich sein 425*cdf0e10cSrcweir aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 426*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#1",m_aTextSeparatorLabel.GetText()); 427*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#2",m_aFieldSeparatorLabel.GetText()); 428*cdf0e10cSrcweir pErrorWin = &m_aTextSeparator; 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir else if (m_aDecimalSeparator.GetText() == m_aThousandsSeparator.GetText()) 431*cdf0e10cSrcweir { // Tausender und DecimalTrenner duerfen nicht gleich sein 432*cdf0e10cSrcweir aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 433*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#1",m_aDecimalSeparatorLabel.GetText()); 434*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#2",m_aThousandsSeparatorLabel.GetText()); 435*cdf0e10cSrcweir pErrorWin = &m_aDecimalSeparator; 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir else if (m_aFieldSeparator.GetText() == m_aThousandsSeparator.GetText()) 438*cdf0e10cSrcweir { // Tausender und FeldTrenner duerfen nicht gleich sein 439*cdf0e10cSrcweir aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 440*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#1",m_aFieldSeparatorLabel.GetText()); 441*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#2",m_aThousandsSeparatorLabel.GetText()); 442*cdf0e10cSrcweir pErrorWin = &m_aFieldSeparator; 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir else if (m_aFieldSeparator.GetText() == m_aDecimalSeparator.GetText()) 445*cdf0e10cSrcweir { // Zehner und FeldTrenner duerfen nicht gleich sein 446*cdf0e10cSrcweir aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 447*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#1",m_aFieldSeparatorLabel.GetText()); 448*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#2",m_aDecimalSeparatorLabel.GetText()); 449*cdf0e10cSrcweir pErrorWin = &m_aFieldSeparator; 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir else if (m_aTextSeparator.GetText() == m_aThousandsSeparator.GetText()) 452*cdf0e10cSrcweir { // Tausender und TextTrenner duerfen nicht gleich sein 453*cdf0e10cSrcweir aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 454*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#1",m_aTextSeparatorLabel.GetText()); 455*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#2",m_aThousandsSeparatorLabel.GetText()); 456*cdf0e10cSrcweir pErrorWin = &m_aTextSeparator; 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir else if (m_aTextSeparator.GetText() == m_aDecimalSeparator.GetText()) 459*cdf0e10cSrcweir { // Zehner und TextTrenner duerfen nicht gleich sein 460*cdf0e10cSrcweir aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 461*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#1",m_aTextSeparatorLabel.GetText()); 462*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#2",m_aDecimalSeparatorLabel.GetText()); 463*cdf0e10cSrcweir pErrorWin = &m_aTextSeparator; 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir else if ((sExtension.Search('*') != STRING_NOTFOUND) || (sExtension.Search('?') != STRING_NOTFOUND)) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir aErrorText = String(ModuleRes(STR_AUTONO_WILDCARDS)); 468*cdf0e10cSrcweir aErrorText.SearchAndReplaceAscii("#1",sExtension); 469*cdf0e10cSrcweir pErrorWin = &m_aETOwnExtension; 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir else 472*cdf0e10cSrcweir return sal_True; 473*cdf0e10cSrcweir ErrorBox(NULL, WB_OK, MnemonicGenerator::EraseAllMnemonicChars( aErrorText)).Execute(); 474*cdf0e10cSrcweir pErrorWin->GrabFocus(); 475*cdf0e10cSrcweir return 0; 476*cdf0e10cSrcweir } 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir // ----------------------------------------------------------------------- 480*cdf0e10cSrcweir sal_Bool OTextConnectionHelper::FillItemSet( SfxItemSet& rSet, const sal_Bool _bChangedSomething ) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir sal_Bool bChangedSomething = _bChangedSomething; 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir if ( ( m_nAvailableSections & TC_EXTENSION ) != 0 ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir String sExtension = GetExtension(); 487*cdf0e10cSrcweir if( !m_aOldExtension.Equals( sExtension ) ) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir rSet.Put( SfxStringItem( DSID_TEXTFILEEXTENSION, sExtension ) ); 490*cdf0e10cSrcweir bChangedSomething = sal_True; 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir if ( ( m_nAvailableSections & TC_HEADER ) != 0 ) 495*cdf0e10cSrcweir { 496*cdf0e10cSrcweir if( (m_aRowHeader.GetState() != m_aRowHeader.GetSavedValue()) ) 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir rSet.Put(SfxBoolItem(DSID_TEXTFILEHEADER, m_aRowHeader.IsChecked())); 499*cdf0e10cSrcweir bChangedSomething = sal_True; 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir } 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir if ( ( m_nAvailableSections & TC_SEPARATORS ) != 0 ) 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir if( m_aFieldSeparator.GetText() != m_aFieldSeparator.GetSavedValue() ) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir rSet.Put( SfxStringItem(DSID_FIELDDELIMITER, GetSeparator( m_aFieldSeparator, m_aFieldSeparatorList) ) ); 508*cdf0e10cSrcweir bChangedSomething = sal_True; 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir if( m_aTextSeparator.GetText() != m_aTextSeparator.GetSavedValue() ) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir rSet.Put( SfxStringItem(DSID_TEXTDELIMITER, GetSeparator( m_aTextSeparator, m_aTextSeparatorList) ) ); 513*cdf0e10cSrcweir bChangedSomething = sal_True; 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir if( m_aDecimalSeparator.GetText() != m_aDecimalSeparator.GetSavedValue() ) 517*cdf0e10cSrcweir { 518*cdf0e10cSrcweir rSet.Put( SfxStringItem(DSID_DECIMALDELIMITER, m_aDecimalSeparator.GetText().Copy(0, 1) ) ); 519*cdf0e10cSrcweir bChangedSomething = sal_True; 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir if( m_aThousandsSeparator.GetText() != m_aThousandsSeparator.GetSavedValue() ) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir rSet.Put( SfxStringItem(DSID_THOUSANDSDELIMITER, m_aThousandsSeparator.GetText().Copy(0,1) ) ); 524*cdf0e10cSrcweir bChangedSomething = sal_True; 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir if ( ( m_nAvailableSections & TC_CHARSET ) != 0 ) 529*cdf0e10cSrcweir { 530*cdf0e10cSrcweir if ( m_aCharSet.StoreSelectedCharSet( rSet, DSID_CHARSET ) ) 531*cdf0e10cSrcweir bChangedSomething = sal_True; 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir return bChangedSomething; 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir void OTextConnectionHelper::SetExtension(const String& _rVal) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir if (_rVal.EqualsAscii("txt")) 541*cdf0e10cSrcweir m_aRBAccessTextFiles.Check(sal_True); 542*cdf0e10cSrcweir else if (_rVal.EqualsAscii( "csv" )) 543*cdf0e10cSrcweir m_aRBAccessCSVFiles.Check(sal_True); 544*cdf0e10cSrcweir else 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir m_aRBAccessOtherFiles.Check(sal_True); 547*cdf0e10cSrcweir m_aFTExtensionExample.SetText(_rVal); 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir } 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir String OTextConnectionHelper::GetExtension() 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir String sExtension; 555*cdf0e10cSrcweir if (m_aRBAccessTextFiles.IsChecked()) 556*cdf0e10cSrcweir sExtension = String::CreateFromAscii("txt"); 557*cdf0e10cSrcweir else if (m_aRBAccessCSVFiles.IsChecked()) 558*cdf0e10cSrcweir sExtension = String::CreateFromAscii("csv"); 559*cdf0e10cSrcweir else 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir sExtension = m_aETOwnExtension.GetText(); 562*cdf0e10cSrcweir if ( sExtension.GetToken(0,'.').Equals('*') ) 563*cdf0e10cSrcweir sExtension.Erase(0,2); 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir return sExtension; 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir //------------------------------------------------------------------------ 570*cdf0e10cSrcweir String OTextConnectionHelper::GetSeparator( const ComboBox& rBox, const String& rList ) 571*cdf0e10cSrcweir { 572*cdf0e10cSrcweir sal_Unicode nTok = '\t'; 573*cdf0e10cSrcweir xub_StrLen nPos(rBox.GetEntryPos( rBox.GetText() )); 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir if( nPos == COMBOBOX_ENTRY_NOTFOUND ) 576*cdf0e10cSrcweir return rBox.GetText().Copy(0); 577*cdf0e10cSrcweir 578*cdf0e10cSrcweir if ( !( &m_aTextSeparator == &rBox && nPos == (rBox.GetEntryCount()-1) ) ) 579*cdf0e10cSrcweir return String( 580*cdf0e10cSrcweir static_cast< sal_Unicode >( 581*cdf0e10cSrcweir rList.GetToken(((nPos*2)+1), nTok ).ToInt32())); 582*cdf0e10cSrcweir // somewhat strange ... translates for instance an "32" into " " 583*cdf0e10cSrcweir return String(); 584*cdf0e10cSrcweir } 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir //------------------------------------------------------------------------ 587*cdf0e10cSrcweir void OTextConnectionHelper::SetSeparator( ComboBox& rBox, const String& rList, const String& rVal ) 588*cdf0e10cSrcweir { 589*cdf0e10cSrcweir char nTok = '\t'; 590*cdf0e10cSrcweir xub_StrLen nCnt(rList.GetTokenCount( nTok )); 591*cdf0e10cSrcweir xub_StrLen i; 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir for( i=0 ; i<nCnt ; i+=2 ) 594*cdf0e10cSrcweir { 595*cdf0e10cSrcweir String sTVal( 596*cdf0e10cSrcweir static_cast< sal_Unicode >( 597*cdf0e10cSrcweir rList.GetToken( (i+1), nTok ).ToInt32())); 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir if( sTVal == rVal ) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir rBox.SetText( rList.GetToken( i, nTok ) ); 602*cdf0e10cSrcweir break; 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir if ( i >= nCnt ) 607*cdf0e10cSrcweir { 608*cdf0e10cSrcweir if ( &m_aTextSeparator == &rBox && !rVal.Len() ) 609*cdf0e10cSrcweir rBox.SetText(m_aTextNone); 610*cdf0e10cSrcweir else 611*cdf0e10cSrcweir rBox.SetText( rVal.Copy(0, 1) ); 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir } 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir //......................................................................... 616*cdf0e10cSrcweir } // namespace dbaui 617*cdf0e10cSrcweir //......................................................................... 618