User: kz Date: 2008-03-07 11:21:30+0000 Modified: dba/dbaccess/source/ui/dlg/TextConnectionHelper.cxx
Log: INTEGRATION: CWS textconnectionsettings (1.13.28); FILE MERGED 2008/03/05 13:10:43 fs 1.13.28.2: #i10000# 2008/03/05 12:55:50 fs 1.13.28.1: #i86720# some re-factoring, owed to the fact that we now have a stand-alone dialog for entering text/csv settings, which re-uses existing functionality File Changes: Directory: /dba/dbaccess/source/ui/dlg/ ======================================= File [changed]: TextConnectionHelper.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/dlg/TextConnectionHelper.cxx?r1=1.13&r2=1.14 Delta lines: +194 -76 ---------------------- --- TextConnectionHelper.cxx 2008-01-30 08:44:02+0000 1.13 +++ TextConnectionHelper.cxx 2008-03-07 11:21:27+0000 1.14 @@ -55,9 +55,6 @@ #include "AutoControls.hrc" #endif -//#ifndef _DBAUI_DBADMIN_HRC_ -//#include "dbadmin.hrc" -//#endif #ifndef _SFXITEMSET_HXX #include <svtools/itemset.hxx> #endif @@ -165,31 +162,34 @@ //======================================================================== DBG_NAME(OTextConnectionHelper) //------------------------------------------------------------------------ - OTextConnectionHelper::OTextConnectionHelper( Window* pParent, sal_Bool _bWizardMode ) - :Control(pParent) - ,m_aHeader (pParent, ModuleRes(CB_AUTOHEADER)) - ,m_aLineFormat (pParent, ModuleRes(FL_AUTOSEPARATOR2)) - ,m_aFTExtensionHeader (pParent, ModuleRes(FT_AUTOEXTENSIONHEADER)) - ,m_aRBAccessTextFiles (pParent, ModuleRes(RB_AUTOACCESSCTEXTFILES)) - ,m_aRBAccessCSVFiles (pParent, ModuleRes(RB_AUTOACCESSCCSVFILES)) - ,m_aRBAccessOtherFiles (pParent, ModuleRes(RB_AUTOACCESSOTHERS)) - ,m_aETOwnExtension (pParent, ModuleRes(ET_AUTOOWNEXTENSION)) - ,m_aFTExtensionExample (pParent, ModuleRes(FT_AUTOOWNEXTENSIONAPPENDIX)) - ,m_aFieldSeparatorLabel (pParent, ModuleRes(FT_AUTOFIELDSEPARATOR)) - ,m_aFieldSeparator (pParent, ModuleRes(CM_AUTOFIELDSEPARATOR)) - ,m_aTextSeparatorLabel (pParent, ModuleRes(FT_AUTOTEXTSEPARATOR)) - ,m_aTextSeparator (pParent, ModuleRes(CM_AUTOTEXTSEPARATOR)) - ,m_aDecimalSeparatorLabel (pParent, ModuleRes(FT_AUTODECIMALSEPARATOR)) - ,m_aDecimalSeparator (pParent, ModuleRes(CM_AUTODECIMALSEPARATOR)) - ,m_aThousandsSeparatorLabel (pParent, ModuleRes(FT_AUTOTHOUSANDSSEPARATOR)) - ,m_aThousandsSeparator (pParent, ModuleRes(CM_AUTOTHOUSANDSSEPARATOR)) + OTextConnectionHelper::OTextConnectionHelper( Window* pParent, const short _nAvailableSections ) + :Control( pParent, WB_DIALOGCONTROL ) + ,m_aFTExtensionHeader (this, ModuleRes(FT_AUTOEXTENSIONHEADER)) + ,m_aRBAccessTextFiles (this, ModuleRes(RB_AUTOACCESSCTEXTFILES)) + ,m_aRBAccessCSVFiles (this, ModuleRes(RB_AUTOACCESSCCSVFILES)) + ,m_aRBAccessOtherFiles (this, ModuleRes(RB_AUTOACCESSOTHERS)) + ,m_aETOwnExtension (this, ModuleRes(ET_AUTOOWNEXTENSION)) + ,m_aFTExtensionExample (this, ModuleRes(FT_AUTOOWNEXTENSIONAPPENDIX)) + ,m_aLineFormat (this, ModuleRes(FL_AUTOSEPARATOR2)) + ,m_aFieldSeparatorLabel (this, ModuleRes(FT_AUTOFIELDSEPARATOR)) + ,m_aFieldSeparator (this, ModuleRes(CM_AUTOFIELDSEPARATOR)) + ,m_aTextSeparatorLabel (this, ModuleRes(FT_AUTOTEXTSEPARATOR)) + ,m_aTextSeparator (this, ModuleRes(CM_AUTOTEXTSEPARATOR)) + ,m_aDecimalSeparatorLabel (this, ModuleRes(FT_AUTODECIMALSEPARATOR)) + ,m_aDecimalSeparator (this, ModuleRes(CM_AUTODECIMALSEPARATOR)) + ,m_aThousandsSeparatorLabel (this, ModuleRes(FT_AUTOTHOUSANDSSEPARATOR)) + ,m_aThousandsSeparator (this, ModuleRes(CM_AUTOTHOUSANDSSEPARATOR)) + ,m_aRowHeader (this, ModuleRes(CB_AUTOHEADER)) + ,m_aCharSetHeader (this, ModuleRes(FL_DATACONVERT)) + ,m_aCharSetLabel (this, ModuleRes(FT_CHARSET)) + ,m_aCharSet (this, ModuleRes(LB_CHARSET)) ,m_aFieldSeparatorList (ModuleRes(STR_AUTOFIELDSEPARATORLIST)) ,m_aTextSeparatorList (ModuleRes(STR_AUTOTEXTSEPARATORLIST)) ,m_aTextNone (ModuleRes(STR_AUTOTEXT_FIELD_SEP_NONE)) + ,m_nAvailableSections( _nAvailableSections ) { DBG_CTOR(OTextConnectionHelper,NULL); - m_bWizardMode = _bWizardMode; xub_StrLen nCnt = m_aFieldSeparatorList.GetTokenCount( '\t' ); xub_StrLen i; @@ -206,6 +206,7 @@ m_aFieldSeparator.SetSelectHdl(getControlModifiedLink()); m_aTextSeparator.SetUpdateDataHdl(getControlModifiedLink()); m_aTextSeparator.SetSelectHdl(getControlModifiedLink()); + m_aCharSet.SetSelectHdl(getControlModifiedLink()); m_aFieldSeparator.SetModifyHdl(getControlModifiedLink()); m_aTextSeparator.SetModifyHdl(getControlModifiedLink()); @@ -216,6 +217,94 @@ m_aRBAccessCSVFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl)); m_aRBAccessOtherFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl)); m_aRBAccessCSVFiles.Check(sal_True); + + struct SectionDescriptor + { + short nFlag; + Window* pFirstControl; + } aSections[] = { + { TC_EXTENSION, &m_aFTExtensionHeader }, + { TC_SEPARATORS, &m_aLineFormat }, + { TC_HEADER, &m_aRowHeader }, + { TC_CHARSET, &m_aCharSetHeader }, + { 0, NULL } + }; + + for ( size_t section=0; section < sizeof( aSections ) / sizeof( aSections[0] ) - 1; ++section ) + { + if ( ( m_nAvailableSections & aSections[section].nFlag ) != 0 ) + { + // the section is visible, no need to do anything here + continue; + } + + Window* pThisSection = aSections[section].pFirstControl; + Window* pNextSection = aSections[section+1].pFirstControl; + + // hide all elements from this section + Window* pControl = pThisSection; + while ( ( pControl != pNextSection ) && pControl ) + { + Window* pRealWindow = pControl->GetWindow( WINDOW_CLIENT ); + #if OSL_DEBUG_LEVEL > 0 + String sWindowText( pRealWindow->GetText() ); + (void)sWindowText; + #endif + pRealWindow->Hide(); + pControl = pControl->GetWindow( WINDOW_NEXT ); + } + + // move all controls in following sections up + if ( !pNextSection ) + continue; + const long nThisSectionStart = pThisSection->GetPosPixel().Y(); + const long nNextSectionStart = pNextSection->GetPosPixel().Y(); + const long nMoveOffset( nThisSectionStart - nNextSectionStart ); + while ( pControl ) + { + Point aPos = pControl->GetPosPixel(); + aPos.Move( 0, nMoveOffset ); + pControl->SetPosPixel( aPos ); + pControl = pControl->GetWindow( WINDOW_NEXT ); + } + } + + Rectangle aControlRectUnion; + for ( Window* pControl = aSections[0].pFirstControl; + pControl != NULL; + pControl = pControl->GetWindow( WINDOW_NEXT ) + ) + { + aControlRectUnion = aControlRectUnion.Union( Rectangle( pControl->GetPosPixel(), pControl->GetSizePixel() ) ); + } + + // need some adjustments to the positions, since the resource-specified + // positions for the control were relative to *our* parent, while by now + // the controls have |this| as parent. + + // first, move ourself to the upper left of the area occupied by all controls + SetPosPixel( aControlRectUnion.TopLeft() ); + + // then, compensate in the control positions, by moving them the up/left + for ( Window* pControl = aSections[0].pFirstControl; + pControl != NULL; + pControl = pControl->GetWindow( WINDOW_NEXT ) + ) + { + Point aPos( pControl->GetPosPixel() ); + aPos.Move( -aControlRectUnion.Left(), -aControlRectUnion.Top() ); + pControl->SetPosPixel( aPos ); + + // while we are here ... the controls should not have an own background + // (this would not be needed when our outer dialog were also the parent + // of the controls) + pControl->SetBackground(); + } + + // now, change our own size so all controls fit + SetSizePixel( aControlRectUnion.GetSize() ); + + SetBackground(); Show(); } @@ -259,7 +348,8 @@ _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aTextSeparator)); _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aDecimalSeparator)); _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aThousandsSeparator)); - _rControlList.push_back(new OSaveValueWrapper<CheckBox>(&m_aHeader)); + _rControlList.push_back(new OSaveValueWrapper<CheckBox>(&m_aRowHeader)); + _rControlList.push_back(new OSaveValueWrapper<ListBox>(&m_aCharSet)); } // ----------------------------------------------------------------------- void OTextConnectionHelper::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList) @@ -268,34 +358,47 @@ _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aTextSeparatorLabel)); _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aDecimalSeparatorLabel)); _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aThousandsSeparatorLabel)); + _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aCharSetHeader)); + _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aCharSetLabel)); + _rControlList.push_back(new ODisableWrapper<ListBox>(&m_aCharSet)); } // ----------------------------------------------------------------------- - void OTextConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool /*_bSaveValue*/, sal_Bool _bValid) + void OTextConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool _bValid) + { + if ( !_bValid ) + return; + + SFX_ITEMSET_GET( _rSet, pDelItem, SfxStringItem, DSID_FIELDDELIMITER, sal_True ); + SFX_ITEMSET_GET( _rSet, pStrItem, SfxStringItem, DSID_TEXTDELIMITER, sal_True ); + SFX_ITEMSET_GET( _rSet, pDecdelItem, SfxStringItem, DSID_DECIMALDELIMITER, sal_True ); + SFX_ITEMSET_GET( _rSet, pThodelItem, SfxStringItem, DSID_THOUSANDSDELIMITER, sal_True ); + SFX_ITEMSET_GET( _rSet, pExtensionItem, SfxStringItem, DSID_TEXTFILEEXTENSION, sal_True ); + SFX_ITEMSET_GET( _rSet, pCharsetItem, SfxStringItem, DSID_CHARSET, sal_True ); + + if ( ( m_nAvailableSections & TC_EXTENSION ) != 0 ) { - m_aHeader.Show(!m_bWizardMode); + m_aOldExtension = pExtensionItem->GetValue(); + SetExtension( m_aOldExtension ); + } - // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) - SFX_ITEMSET_GET(_rSet, pDelItem, SfxStringItem, DSID_FIELDDELIMITER, sal_True); - SFX_ITEMSET_GET(_rSet, pStrItem, SfxStringItem, DSID_TEXTDELIMITER, sal_True); - SFX_ITEMSET_GET(_rSet, pDecdelItem, SfxStringItem, DSID_DECIMALDELIMITER, sal_True); - SFX_ITEMSET_GET(_rSet, pThodelItem, SfxStringItem, DSID_THOUSANDSDELIMITER, sal_True); - SFX_ITEMSET_GET(_rSet, pExtensionItem, SfxStringItem, DSID_TEXTFILEEXTENSION, sal_True); - if (_bValid) + if ( ( m_nAvailableSections & TC_HEADER ) != 0 ) { - if (!m_bWizardMode) + SFX_ITEMSET_GET( _rSet, pHdrItem, SfxBoolItem, DSID_TEXTFILEHEADER, sal_True ); + m_aRowHeader.Check( pHdrItem->GetValue() ); + } + + if ( ( m_nAvailableSections & TC_SEPARATORS ) != 0 ) { - SFX_ITEMSET_GET(_rSet, pHdrItem, SfxBoolItem, DSID_TEXTFILEHEADER, sal_True); - m_aHeader.Check( pHdrItem->GetValue() ); + SetSeparator( m_aFieldSeparator, m_aFieldSeparatorList, pDelItem->GetValue() ); + SetSeparator( m_aTextSeparator, m_aTextSeparatorList, pStrItem->GetValue() ); + m_aDecimalSeparator.SetText( pDecdelItem->GetValue() ); + m_aThousandsSeparator.SetText( pThodelItem->GetValue() ); } - m_aOldExtension = pExtensionItem->GetValue(); - SetExtension(m_aOldExtension); - SetSeparator(m_aFieldSeparator, m_aFieldSeparatorList, pDelItem->GetValue()); - SetSeparator(m_aTextSeparator, m_aTextSeparatorList, pStrItem->GetValue()); - - m_aDecimalSeparator.SetText(pDecdelItem->GetValue()); - m_aThousandsSeparator.SetText(pThodelItem->GetValue()); - m_aETOwnExtension.Show(); + + if ( ( m_nAvailableSections & TC_CHARSET ) != 0 ) + { + m_aCharSet.SelectEntryByIanaName( pCharsetItem->GetValue() ); } } @@ -385,6 +488,28 @@ sal_Bool OTextConnectionHelper::FillItemSet( SfxItemSet& rSet, const sal_Bool _bChangedSomething ) { sal_Bool bChangedSomething = _bChangedSomething; + + if ( ( m_nAvailableSections & TC_EXTENSION ) != 0 ) + { + String sExtension = GetExtension(); + if( !m_aOldExtension.Equals( sExtension ) ) + { + rSet.Put( SfxStringItem( DSID_TEXTFILEEXTENSION, sExtension ) ); + bChangedSomething = sal_True; + } + } + + if ( ( m_nAvailableSections & TC_HEADER ) != 0 ) + { + if( (m_aRowHeader.GetState() != m_aRowHeader.GetSavedValue()) ) + { + rSet.Put(SfxBoolItem(DSID_TEXTFILEHEADER, m_aRowHeader.IsChecked())); + bChangedSomething = sal_True; + } + } + + if ( ( m_nAvailableSections & TC_SEPARATORS ) != 0 ) + { if( m_aFieldSeparator.GetText() != m_aFieldSeparator.GetSavedValue() ) { rSet.Put( SfxStringItem(DSID_FIELDDELIMITER, GetSeparator( m_aFieldSeparator, m_aFieldSeparatorList) ) ); @@ -406,21 +531,14 @@ rSet.Put( SfxStringItem(DSID_THOUSANDSDELIMITER, m_aThousandsSeparator.GetText().Copy(0,1) ) ); bChangedSomething = sal_True; } - String sExtension = GetExtension(); - if(!m_aOldExtension.Equals(sExtension)) - { - rSet.Put(SfxStringItem(DSID_TEXTFILEEXTENSION, sExtension)); - bChangedSomething = sal_True; } - if (!m_bWizardMode) + if ( ( m_nAvailableSections & TC_CHARSET ) != 0 ) { - if( (m_aHeader.GetState() != m_aHeader.GetSavedValue()) ) - { - rSet.Put(SfxBoolItem(DSID_TEXTFILEHEADER, m_aHeader.IsChecked())); + if ( m_aCharSet.StoreSelectedCharSet( rSet, DSID_CHARSET ) ) bChangedSomething = sal_True; } - } + return bChangedSomething; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
