Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / misc / WNameMatch.cxx
bloba68b52af1a3c80d8e0f99401ed0e1274cc3d8c78
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "WNameMatch.hxx"
30 #include <osl/diagnose.h>
31 #include "FieldDescriptions.hxx"
32 #include "WCopyTable.hxx"
33 #include "dbaccess_helpid.hrc"
34 #include "dbu_misc.hrc"
35 #include "WizardPages.hrc"
36 #include <vcl/scrbar.hxx>
37 #include <com/sun/star/sdbc/DataType.hpp>
39 using namespace ::dbaui;
40 //========================================================================
41 // OWizColumnSelect
42 DBG_NAME(OWizNameMatching)
43 //========================================================================
44 OWizNameMatching::OWizNameMatching( Window* pParent)
45 :OWizardPage( pParent, ModuleRes( TAB_WIZ_NAME_MATCHING ) )
46 ,m_FT_TABLE_LEFT( this, ModuleRes( FT_TABLE_LEFT ) )
47 ,m_FT_TABLE_RIGHT( this, ModuleRes( FT_TABLE_RIGHT ) )
48 ,m_CTRL_LEFT( this, ModuleRes( CTRL_LEFT ) )
49 ,m_CTRL_RIGHT( this, ModuleRes( CTRL_RIGHT ) )
50 ,m_ibColumn_up( this, ModuleRes( IB_COLUMN_UP ) )
51 ,m_ibColumn_down( this, ModuleRes( IB_COLUMN_DOWN ) )
52 ,m_ibColumn_up_right( this, ModuleRes( IB_COLUMN_UP_RIGHT ) )
53 ,m_ibColumn_down_right( this, ModuleRes( IB_COLUMN_DOWN_RIGHT ) )
54 ,m_pbAll( this, ModuleRes( PB_ALL ) )
55 ,m_pbNone( this, ModuleRes( PB_NONE ) )
58 DBG_CTOR(OWizNameMatching,NULL);
60 m_ibColumn_up.SetClickHdl(LINK(this,OWizNameMatching,ButtonClickHdl));
61 m_ibColumn_down.SetClickHdl(LINK(this,OWizNameMatching,ButtonClickHdl));
63 m_ibColumn_up_right.SetClickHdl(LINK(this,OWizNameMatching,RightButtonClickHdl));
64 m_ibColumn_down_right.SetClickHdl(LINK(this,OWizNameMatching,RightButtonClickHdl));
66 m_pbAll.SetClickHdl(LINK(this,OWizNameMatching,AllNoneClickHdl));
67 m_pbNone.SetClickHdl(LINK(this,OWizNameMatching,AllNoneClickHdl));
69 m_CTRL_LEFT.SetSelectHdl(LINK(this,OWizNameMatching,TableListClickHdl));
70 m_CTRL_RIGHT.SetSelectHdl(LINK(this,OWizNameMatching,TableListRightSelectHdl));
71 m_CTRL_RIGHT.EnableCheckButton( NULL );
73 m_CTRL_LEFT.SetStyle( m_CTRL_LEFT.GetStyle() | WB_FORCE_MAKEVISIBLE );
74 m_CTRL_RIGHT.SetStyle( m_CTRL_RIGHT.GetStyle() | WB_FORCE_MAKEVISIBLE );
76 m_sSourceText = m_FT_TABLE_LEFT.GetText();
77 m_sSourceText.AppendAscii("\n");
78 m_sDestText = m_FT_TABLE_RIGHT.GetText();
79 m_sDestText.AppendAscii("\n");
81 FreeResource();
83 // -----------------------------------------------------------------------
84 OWizNameMatching::~OWizNameMatching()
86 DBG_DTOR(OWizNameMatching,NULL);
89 // -----------------------------------------------------------------------
90 void OWizNameMatching::Reset()
92 // urspr"unglichen zustand wiederherstellen
93 DBG_CHKTHIS(OWizNameMatching,NULL);
94 // the left tree contains bitmaps so i need to resize the right one
95 if(m_bFirstTime)
97 m_CTRL_RIGHT.SetReadOnly(); // sets autoinc to readonly
98 m_CTRL_RIGHT.SetEntryHeight(m_CTRL_LEFT.GetEntryHeight());
99 m_CTRL_RIGHT.SetIndent(m_CTRL_LEFT.GetIndent());
100 m_CTRL_RIGHT.SetSpaceBetweenEntries(m_CTRL_LEFT.GetSpaceBetweenEntries());
102 m_bFirstTime = sal_False;
106 // -----------------------------------------------------------------------
107 void OWizNameMatching::ActivatePage( )
109 DBG_CHKTHIS(OWizNameMatching,NULL);
111 // set source table name
112 String aName = m_sSourceText;
113 aName += String(m_pParent->m_sSourceName);
115 m_FT_TABLE_LEFT.SetText(aName);
117 // set dest table name
118 aName = m_sDestText;
119 aName += String(m_pParent->m_sName);
120 m_FT_TABLE_RIGHT.SetText(aName);
123 m_CTRL_LEFT.FillListBox(*m_pParent->getSrcVector());
124 m_CTRL_RIGHT.FillListBox(*m_pParent->getDestVector());
126 m_ibColumn_up.Enable( m_CTRL_LEFT.GetEntryCount() > 1 );
127 m_ibColumn_down.Enable( m_CTRL_LEFT.GetEntryCount() > 1 );
129 m_ibColumn_up_right.Enable( m_CTRL_RIGHT.GetEntryCount() > 1 );
130 m_ibColumn_down_right.Enable( m_CTRL_RIGHT.GetEntryCount() > 1 );
133 m_pParent->EnableButton(OCopyTableWizard::WIZARD_NEXT,sal_False);
134 m_CTRL_LEFT.GrabFocus();
136 // -----------------------------------------------------------------------
137 sal_Bool OWizNameMatching::LeavePage()
139 DBG_CHKTHIS(OWizNameMatching,NULL);
141 const ODatabaseExport::TColumnVector* pSrcColumns = m_pParent->getSrcVector();
143 m_pParent->m_vColumnPos.clear();
144 m_pParent->m_vColumnTypes.clear();
145 m_pParent->m_vColumnPos.resize( pSrcColumns->size(), ODatabaseExport::TPositions::value_type( COLUMN_POSITION_NOT_FOUND, COLUMN_POSITION_NOT_FOUND ) );
146 m_pParent->m_vColumnTypes.resize( pSrcColumns->size(), COLUMN_POSITION_NOT_FOUND );
149 sal_Int32 nParamPos = 0;
150 SvLBoxEntry* pLeftEntry = m_CTRL_LEFT.GetModel()->First();
151 SvLBoxEntry* pRightEntry = m_CTRL_RIGHT.GetModel()->First();
152 while(pLeftEntry && pRightEntry)
154 OFieldDescription* pSrcField = static_cast<OFieldDescription*>(pLeftEntry->GetUserData());
155 OSL_ENSURE(pSrcField,"OWizNameMatching: OColumn can not be null!");
157 ODatabaseExport::TColumnVector::const_iterator aSrcIter = pSrcColumns->begin();
158 ODatabaseExport::TColumnVector::const_iterator aSrcEnd = pSrcColumns->end();
159 for(;aSrcIter != aSrcEnd && (*aSrcIter)->second != pSrcField;++aSrcIter)
161 const sal_Int32 nPos = ::std::distance(pSrcColumns->begin(),aSrcIter);
163 if(m_CTRL_LEFT.GetCheckButtonState(pLeftEntry) == SV_BUTTON_CHECKED)
165 OFieldDescription* pDestField = static_cast<OFieldDescription*>(pRightEntry->GetUserData());
166 OSL_ENSURE(pDestField,"OWizNameMatching: OColumn can not be null!");
167 const ODatabaseExport::TColumnVector* pDestColumns = m_pParent->getDestVector();
168 ODatabaseExport::TColumnVector::const_iterator aDestIter = pDestColumns->begin();
169 ODatabaseExport::TColumnVector::const_iterator aDestEnd = pDestColumns->end();
171 for(;aDestIter != aDestEnd && (*aDestIter)->second != pDestField;++aDestIter)
174 OSL_ENSURE((nPos) < static_cast<sal_Int32>(m_pParent->m_vColumnPos.size()),"m_pParent->m_vColumnPos: Illegal index for vector");
175 m_pParent->m_vColumnPos[nPos].first = ++nParamPos;
176 m_pParent->m_vColumnPos[nPos].second = ::std::distance(pDestColumns->begin(),aDestIter) + 1;
177 sal_Bool bNotConvert = sal_True;
178 TOTypeInfoSP pTypeInfo = m_pParent->convertType((*aDestIter)->second->getSpecialTypeInfo(),bNotConvert);
179 sal_Int32 nType = ::com::sun::star::sdbc::DataType::VARCHAR;
180 if ( pTypeInfo.get() )
181 nType = pTypeInfo->nType;
182 m_pParent->m_vColumnTypes[nPos] = nType;
184 else
186 m_pParent->m_vColumnPos[nPos].first = COLUMN_POSITION_NOT_FOUND;
187 m_pParent->m_vColumnPos[nPos].second = COLUMN_POSITION_NOT_FOUND;
190 pLeftEntry = m_CTRL_LEFT.GetModel()->Next(pLeftEntry);
191 pRightEntry = m_CTRL_RIGHT.GetModel()->Next(pRightEntry);
194 return sal_True;
196 // -----------------------------------------------------------------------
197 String OWizNameMatching::GetTitle() const { return String(ModuleRes(STR_WIZ_NAME_MATCHING_TITEL)); }
198 // -----------------------------------------------------------------------
199 IMPL_LINK( OWizNameMatching, ButtonClickHdl, Button *, pButton )
201 SvLBoxEntry* pEntry = m_CTRL_LEFT.FirstSelected();
202 if ( pEntry )
204 sal_Int32 nPos = m_CTRL_LEFT.GetModel()->GetAbsPos(pEntry);
205 if(pButton == &m_ibColumn_up && nPos)
206 --nPos;
207 else if(pButton == &m_ibColumn_down)
208 nPos += 2;
210 m_CTRL_LEFT.ModelIsMoving(pEntry,NULL,nPos);
211 m_CTRL_LEFT.GetModel()->Move(pEntry,NULL,nPos);
212 m_CTRL_LEFT.ModelHasMoved(pEntry);
214 long nThumbPos = m_CTRL_LEFT.GetVScroll()->GetThumbPos();
215 long nVisibleSize = m_CTRL_LEFT.GetVScroll()->GetVisibleSize();
217 if(pButton == &m_ibColumn_down && (nThumbPos+nVisibleSize+1) < nPos)
219 m_CTRL_LEFT.GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
222 TableListClickHdl(&m_CTRL_LEFT);
226 return 0;
228 //------------------------------------------------------------------------------
229 IMPL_LINK( OWizNameMatching, RightButtonClickHdl, Button *, pButton )
231 SvLBoxEntry* pEntry = m_CTRL_RIGHT.FirstSelected();
232 if ( pEntry )
234 sal_Int32 nPos = m_CTRL_RIGHT.GetModel()->GetAbsPos(pEntry);
235 if(pButton == &m_ibColumn_up_right && nPos)
236 --nPos;
237 else if(pButton == &m_ibColumn_down_right)
238 nPos += 2;
240 m_CTRL_RIGHT.ModelIsMoving(pEntry,NULL,nPos);
241 m_CTRL_RIGHT.GetModel()->Move(pEntry,NULL,nPos);
242 m_CTRL_RIGHT.ModelHasMoved(pEntry);
243 long nThumbPos = m_CTRL_RIGHT.GetVScroll()->GetThumbPos();
244 long nVisibleSize = m_CTRL_RIGHT.GetVScroll()->GetVisibleSize();
246 if(pButton == &m_ibColumn_down_right && (nThumbPos+nVisibleSize+1) < nPos)
247 m_CTRL_RIGHT.GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
248 TableListRightSelectHdl(&m_CTRL_RIGHT);
250 return 0;
252 //------------------------------------------------------------------------------
253 IMPL_LINK( OWizNameMatching, TableListClickHdl, void*, /*NOTINTERESTEDIN*/ )
255 SvLBoxEntry* pEntry = m_CTRL_LEFT.FirstSelected();
256 if(pEntry)
258 sal_uLong nPos = m_CTRL_LEFT.GetModel()->GetAbsPos(pEntry);
259 SvLBoxEntry* pOldEntry = m_CTRL_RIGHT.FirstSelected();
260 if(pOldEntry && nPos != m_CTRL_RIGHT.GetModel()->GetAbsPos(pOldEntry))
262 if(pOldEntry)
263 m_CTRL_RIGHT.Select(pOldEntry,sal_False);
264 pOldEntry = m_CTRL_RIGHT.GetEntry(nPos);
265 if(pOldEntry)
267 sal_uLong nNewPos = m_CTRL_LEFT.GetModel()->GetAbsPos(m_CTRL_LEFT.GetFirstEntryInView());
268 if ( nNewPos - nPos == 1 )
269 --nNewPos;
270 m_CTRL_RIGHT.MakeVisible(m_CTRL_RIGHT.GetEntry(nNewPos),sal_True);
271 m_CTRL_RIGHT.Select(pOldEntry,sal_True);
274 else if(!pOldEntry)
276 pOldEntry = m_CTRL_RIGHT.GetEntry(nPos);
277 if(pOldEntry)
279 m_CTRL_RIGHT.Select(pOldEntry,sal_True);
284 return 0;
286 //------------------------------------------------------------------------------
287 IMPL_LINK( OWizNameMatching, TableListRightSelectHdl, void*, /*NOTINTERESTEDIN*/ )
289 SvLBoxEntry* pEntry = m_CTRL_RIGHT.FirstSelected();
290 if(pEntry)
292 sal_uLong nPos = m_CTRL_RIGHT.GetModel()->GetAbsPos(pEntry);
293 SvLBoxEntry* pOldEntry = m_CTRL_LEFT.FirstSelected();
294 if(pOldEntry && nPos != m_CTRL_LEFT.GetModel()->GetAbsPos(pOldEntry))
296 if(pOldEntry)
297 m_CTRL_LEFT.Select(pOldEntry,sal_False);
298 pOldEntry = m_CTRL_LEFT.GetEntry(nPos);
299 if(pOldEntry)
301 sal_uLong nNewPos = m_CTRL_RIGHT.GetModel()->GetAbsPos(m_CTRL_RIGHT.GetFirstEntryInView());
302 if ( nNewPos - nPos == 1 )
303 nNewPos--;
304 m_CTRL_LEFT.MakeVisible(m_CTRL_LEFT.GetEntry(nNewPos),sal_True);
305 m_CTRL_LEFT.Select(pOldEntry,sal_True);
308 else if(!pOldEntry)
310 pOldEntry = m_CTRL_LEFT.GetEntry(nPos);
311 if(pOldEntry)
313 m_CTRL_LEFT.Select(pOldEntry,sal_True);
318 return 0;
320 // -----------------------------------------------------------------------
321 IMPL_LINK( OWizNameMatching, AllNoneClickHdl, Button *, pButton )
323 sal_Bool bAll = pButton == &m_pbAll;
324 SvLBoxEntry* pEntry = m_CTRL_LEFT.First();
325 while(pEntry)
327 m_CTRL_LEFT.SetCheckButtonState( pEntry, bAll ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED);
328 pEntry = m_CTRL_LEFT.Next(pEntry);
331 return 0;
333 // -----------------------------------------------------------------------
334 //========================================================================
335 // class OColumnString
336 //========================================================================
337 class OColumnString : public SvLBoxString
339 sal_Bool m_bReadOnly;
340 public:
341 OColumnString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& rStr,sal_Bool _RO)
342 :SvLBoxString(pEntry,nFlags,rStr)
343 ,m_bReadOnly(_RO)
347 virtual void Paint(const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry);
349 //------------------------------------------------------------------------
350 void OColumnString::Paint(const Point& rPos, SvLBox& rDev, sal_uInt16 /*nFlags*/, SvLBoxEntry* /*pEntry*/ )
352 if(m_bReadOnly)
354 const StyleSettings& rStyleSettings = rDev.GetSettings().GetStyleSettings();
355 rDev.SetTextColor( rStyleSettings.GetDisableColor() );
356 rDev.SetTextFillColor( rStyleSettings.GetFieldColor() );
358 rDev.DrawText( rPos, GetText() );
360 //========================================================================
361 OColumnTreeBox::OColumnTreeBox( Window* pParent, const ResId& rResId )
362 : OMarkableTreeListBox(pParent,NULL,rResId)
364 SetDragDropMode( 0 );
365 EnableInplaceEditing( sal_False );
366 SetStyle(GetStyle() | WB_BORDER | WB_HASBUTTONS | WB_HSCROLL);
367 SetSelectionMode( SINGLE_SELECTION );
369 //------------------------------------------------------------------------
370 void OColumnTreeBox::InitEntry(SvLBoxEntry* pEntry, const String& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind)
372 DBTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
373 SvLBoxString* pString = new OColumnString(pEntry, 0, rStr,sal_False);
374 if (pString)
375 pEntry->ReplaceItem( pString, pEntry->ItemCount() - 1 );
377 //------------------------------------------------------------------------
378 sal_Bool OColumnTreeBox::Select( SvLBoxEntry* pEntry, sal_Bool bSelect )
380 if(bSelect)
382 OFieldDescription* pColumn = static_cast<OFieldDescription*>(pEntry->GetUserData());
383 if(!(pColumn->IsAutoIncrement() && m_bReadOnly))
384 bSelect = DBTreeListBox::Select( pEntry,bSelect );
386 else
387 bSelect = DBTreeListBox::Select( pEntry,bSelect );
388 return bSelect;
390 //------------------------------------------------------------------------
391 void OColumnTreeBox::FillListBox( const ODatabaseExport::TColumnVector& _rList)
393 Clear();
394 ODatabaseExport::TColumnVector::const_iterator aIter = _rList.begin();
395 ODatabaseExport::TColumnVector::const_iterator aEnd = _rList.end();
396 for(;aIter != aEnd;++aIter)
398 SvLBoxEntry* pEntry = InsertEntry((*aIter)->first,0,sal_False,LIST_APPEND,(*aIter)->second);
399 SvButtonState eState = !(m_bReadOnly && (*aIter)->second->IsAutoIncrement()) ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED;
400 SetCheckButtonState( pEntry, eState );
403 // -----------------------------------------------------------------------------
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */