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