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