fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / misc / WNameMatch.cxx
blob0b35a87ead0cd5fa3072414ffc168fe0d7bbaf8b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "WNameMatch.hxx"
21 #include <osl/diagnose.h>
22 #include "FieldDescriptions.hxx"
23 #include "WCopyTable.hxx"
24 #include "dbaccess_helpid.hrc"
25 #include "dbu_misc.hrc"
26 #include <vcl/scrbar.hxx>
27 #include <vcl/settings.hxx>
28 #include <vcl/builderfactory.hxx>
29 #include "svtools/treelistentry.hxx"
30 #include <com/sun/star/sdbc/DataType.hpp>
32 using namespace ::dbaui;
33 // OWizColumnSelect
34 OWizNameMatching::OWizNameMatching( vcl::Window* pParent)
35 :OWizardPage( pParent, "NameMatching", "dbaccess/ui/namematchingpage.ui" )
36 , m_aImgUp(ModuleRes(IMG_UP))
37 , m_aImgDown(ModuleRes(IMG_DOWN))
39 get(m_pTABLE_LEFT, "leftlabel");
40 get(m_pTABLE_RIGHT, "rightlabel");
41 get(m_pCTRL_LEFT, "left");
42 get(m_pCTRL_RIGHT, "right");
43 get(m_pColumn_up, "up");
44 m_pColumn_up->SetModeImage(m_aImgUp);
45 get(m_pColumn_down, "down");
46 m_pColumn_down->SetModeImage(m_aImgDown);
47 get(m_pColumn_up_right, "up_right");
48 m_pColumn_up_right->SetModeImage(m_aImgUp);
49 get(m_pColumn_down_right, "down_right");
50 m_pColumn_down_right->SetModeImage(m_aImgDown);
51 get(m_pAll, "all");
52 get(m_pNone, "none");
54 m_pColumn_up->SetClickHdl(LINK(this,OWizNameMatching,ButtonClickHdl));
55 m_pColumn_down->SetClickHdl(LINK(this,OWizNameMatching,ButtonClickHdl));
57 m_pColumn_up_right->SetClickHdl(LINK(this,OWizNameMatching,RightButtonClickHdl));
58 m_pColumn_down_right->SetClickHdl(LINK(this,OWizNameMatching,RightButtonClickHdl));
60 m_pAll->SetClickHdl(LINK(this,OWizNameMatching,AllNoneClickHdl));
61 m_pNone->SetClickHdl(LINK(this,OWizNameMatching,AllNoneClickHdl));
63 m_pCTRL_LEFT->SetSelectHdl(LINK(this,OWizNameMatching,TableListClickHdl));
64 m_pCTRL_RIGHT->SetSelectHdl(LINK(this,OWizNameMatching,TableListRightSelectHdl));
65 m_pCTRL_RIGHT->EnableCheckButton( NULL );
67 m_pCTRL_LEFT->SetStyle( m_pCTRL_LEFT->GetStyle() | WB_FORCE_MAKEVISIBLE );
68 m_pCTRL_RIGHT->SetStyle( m_pCTRL_RIGHT->GetStyle() | WB_FORCE_MAKEVISIBLE );
70 m_sSourceText = m_pTABLE_LEFT->GetText();
71 m_sSourceText += "\n";
72 m_sDestText = m_pTABLE_RIGHT->GetText();
73 m_sDestText += "\n";
76 OWizNameMatching::~OWizNameMatching()
78 disposeOnce();
81 void OWizNameMatching::dispose()
83 m_pTABLE_LEFT.clear();
84 m_pTABLE_RIGHT.clear();
85 m_pCTRL_LEFT.clear();
86 m_pCTRL_RIGHT.clear();
87 m_pColumn_up.clear();
88 m_pColumn_down.clear();
89 m_pColumn_up_right.clear();
90 m_pColumn_down_right.clear();
91 m_pAll.clear();
92 m_pNone.clear();
93 OWizardPage::dispose();
96 void OWizNameMatching::Reset()
98 // urspr"unglichen zustand wiederherstellen
99 // the left tree contains bitmaps so i need to resize the right one
100 if(m_bFirstTime)
102 m_pCTRL_RIGHT->SetReadOnly(); // sets autoinc to readonly
103 m_pCTRL_RIGHT->SetEntryHeight(m_pCTRL_LEFT->GetEntryHeight());
104 m_pCTRL_RIGHT->SetIndent(m_pCTRL_LEFT->GetIndent());
105 m_pCTRL_RIGHT->SetSpaceBetweenEntries(m_pCTRL_LEFT->GetSpaceBetweenEntries());
107 m_bFirstTime = false;
112 void OWizNameMatching::ActivatePage( )
115 // set source table name
116 OUString aName = m_sSourceText;
117 aName += m_pParent->m_sSourceName;
119 m_pTABLE_LEFT->SetText(aName);
121 // set dest table name
122 aName = m_sDestText;
123 aName += m_pParent->m_sName;
124 m_pTABLE_RIGHT->SetText(aName);
126 m_pCTRL_LEFT->FillListBox(m_pParent->getSrcVector());
127 m_pCTRL_RIGHT->FillListBox(m_pParent->getDestVector());
129 m_pColumn_up->Enable( m_pCTRL_LEFT->GetEntryCount() > 1 );
130 m_pColumn_down->Enable( m_pCTRL_LEFT->GetEntryCount() > 1 );
132 m_pColumn_up_right->Enable( m_pCTRL_RIGHT->GetEntryCount() > 1 );
133 m_pColumn_down_right->Enable( m_pCTRL_RIGHT->GetEntryCount() > 1 );
135 m_pParent->EnableButton(OCopyTableWizard::WIZARD_NEXT,false);
136 m_pCTRL_LEFT->GrabFocus();
139 bool OWizNameMatching::LeavePage()
142 const ODatabaseExport::TColumnVector& rSrcColumns = m_pParent->getSrcVector();
144 m_pParent->m_vColumnPos.clear();
145 m_pParent->m_vColumnTypes.clear();
146 m_pParent->m_vColumnPos.resize( rSrcColumns.size(), ODatabaseExport::TPositions::value_type( COLUMN_POSITION_NOT_FOUND, COLUMN_POSITION_NOT_FOUND ) );
147 m_pParent->m_vColumnTypes.resize( rSrcColumns.size(), COLUMN_POSITION_NOT_FOUND );
149 sal_Int32 nParamPos = 0;
150 SvTreeListEntry* pLeftEntry = m_pCTRL_LEFT->GetModel()->First();
151 SvTreeListEntry* pRightEntry = m_pCTRL_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 = rSrcColumns.begin();
158 ODatabaseExport::TColumnVector::const_iterator aSrcEnd = rSrcColumns.end();
159 for(;aSrcIter != aSrcEnd && (*aSrcIter)->second != pSrcField;++aSrcIter)
161 const sal_Int32 nPos = ::std::distance(rSrcColumns.begin(),aSrcIter);
163 if(m_pCTRL_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& rDestColumns = m_pParent->getDestVector();
168 ODatabaseExport::TColumnVector::const_iterator aDestIter = rDestColumns.begin();
169 ODatabaseExport::TColumnVector::const_iterator aDestEnd = rDestColumns.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(rDestColumns.begin(),aDestIter) + 1;
178 TOTypeInfoSP pTypeInfo;
180 assert(aDestIter != aDestEnd);
181 if (aDestIter != aDestEnd)
183 bool bNotConvert = true;
184 pTypeInfo = m_pParent->convertType((*aDestIter)->second->getSpecialTypeInfo(), bNotConvert);
187 sal_Int32 nType = ::com::sun::star::sdbc::DataType::VARCHAR;
188 if ( pTypeInfo.get() )
189 nType = pTypeInfo->nType;
190 m_pParent->m_vColumnTypes[nPos] = nType;
192 else
194 m_pParent->m_vColumnPos[nPos].first = COLUMN_POSITION_NOT_FOUND;
195 m_pParent->m_vColumnPos[nPos].second = COLUMN_POSITION_NOT_FOUND;
198 pLeftEntry = m_pCTRL_LEFT->GetModel()->Next(pLeftEntry);
199 pRightEntry = m_pCTRL_RIGHT->GetModel()->Next(pRightEntry);
202 return true;
205 OUString OWizNameMatching::GetTitle() const { return ModuleRes(STR_WIZ_NAME_MATCHING_TITEL); }
207 IMPL_LINK( OWizNameMatching, ButtonClickHdl, Button *, pButton )
209 SvTreeListEntry* pEntry = m_pCTRL_LEFT->FirstSelected();
210 if ( pEntry )
212 sal_Int32 nPos = m_pCTRL_LEFT->GetModel()->GetAbsPos(pEntry);
213 if(pButton == m_pColumn_up && nPos)
214 --nPos;
215 else if(pButton == m_pColumn_down)
216 nPos += 2;
218 m_pCTRL_LEFT->ModelIsMoving(pEntry,NULL,nPos);
219 m_pCTRL_LEFT->GetModel()->Move(pEntry,NULL,nPos);
220 m_pCTRL_LEFT->ModelHasMoved(pEntry);
222 long nThumbPos = m_pCTRL_LEFT->GetVScroll()->GetThumbPos();
223 long nVisibleSize = m_pCTRL_LEFT->GetVScroll()->GetVisibleSize();
225 if(pButton == m_pColumn_down && (nThumbPos+nVisibleSize+1) < nPos)
227 m_pCTRL_LEFT->GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
230 TableListClickHdl(m_pCTRL_LEFT);
233 return 0;
236 IMPL_LINK( OWizNameMatching, RightButtonClickHdl, Button *, pButton )
238 SvTreeListEntry* pEntry = m_pCTRL_RIGHT->FirstSelected();
239 if ( pEntry )
241 sal_Int32 nPos = m_pCTRL_RIGHT->GetModel()->GetAbsPos(pEntry);
242 if(pButton == m_pColumn_up_right && nPos)
243 --nPos;
244 else if(pButton == m_pColumn_down_right)
245 nPos += 2;
247 m_pCTRL_RIGHT->ModelIsMoving(pEntry,NULL,nPos);
248 m_pCTRL_RIGHT->GetModel()->Move(pEntry,NULL,nPos);
249 m_pCTRL_RIGHT->ModelHasMoved(pEntry);
250 long nThumbPos = m_pCTRL_RIGHT->GetVScroll()->GetThumbPos();
251 long nVisibleSize = m_pCTRL_RIGHT->GetVScroll()->GetVisibleSize();
253 if(pButton == m_pColumn_down_right && (nThumbPos+nVisibleSize+1) < nPos)
254 m_pCTRL_RIGHT->GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
255 TableListRightSelectHdl(m_pCTRL_RIGHT);
257 return 0;
260 IMPL_LINK_NOARG( OWizNameMatching, TableListClickHdl )
262 SvTreeListEntry* pEntry = m_pCTRL_LEFT->FirstSelected();
263 if(pEntry)
265 sal_uLong nPos = m_pCTRL_LEFT->GetModel()->GetAbsPos(pEntry);
266 SvTreeListEntry* pOldEntry = m_pCTRL_RIGHT->FirstSelected();
267 if(pOldEntry && nPos != m_pCTRL_RIGHT->GetModel()->GetAbsPos(pOldEntry))
269 if(pOldEntry)
270 m_pCTRL_RIGHT->Select(pOldEntry,false);
271 pOldEntry = m_pCTRL_RIGHT->GetEntry(nPos);
272 if(pOldEntry)
274 sal_uLong nNewPos = m_pCTRL_LEFT->GetModel()->GetAbsPos(m_pCTRL_LEFT->GetFirstEntryInView());
275 if ( nNewPos - nPos == 1 )
276 --nNewPos;
277 m_pCTRL_RIGHT->MakeVisible(m_pCTRL_RIGHT->GetEntry(nNewPos), true);
278 m_pCTRL_RIGHT->Select(pOldEntry,true);
281 else if(!pOldEntry)
283 pOldEntry = m_pCTRL_RIGHT->GetEntry(nPos);
284 if(pOldEntry)
286 m_pCTRL_RIGHT->Select(pOldEntry,true);
291 return 0;
294 IMPL_LINK_NOARG( OWizNameMatching, TableListRightSelectHdl )
296 SvTreeListEntry* pEntry = m_pCTRL_RIGHT->FirstSelected();
297 if(pEntry)
299 sal_uLong nPos = m_pCTRL_RIGHT->GetModel()->GetAbsPos(pEntry);
300 SvTreeListEntry* pOldEntry = m_pCTRL_LEFT->FirstSelected();
301 if(pOldEntry && nPos != m_pCTRL_LEFT->GetModel()->GetAbsPos(pOldEntry))
303 if(pOldEntry)
304 m_pCTRL_LEFT->Select(pOldEntry,false);
305 pOldEntry = m_pCTRL_LEFT->GetEntry(nPos);
306 if(pOldEntry)
308 sal_uLong nNewPos = m_pCTRL_RIGHT->GetModel()->GetAbsPos(m_pCTRL_RIGHT->GetFirstEntryInView());
309 if ( nNewPos - nPos == 1 )
310 nNewPos--;
311 m_pCTRL_LEFT->MakeVisible(m_pCTRL_LEFT->GetEntry(nNewPos), true);
312 m_pCTRL_LEFT->Select(pOldEntry,true);
315 else if(!pOldEntry)
317 pOldEntry = m_pCTRL_LEFT->GetEntry(nPos);
318 if(pOldEntry)
320 m_pCTRL_LEFT->Select(pOldEntry,true);
325 return 0;
328 IMPL_LINK( OWizNameMatching, AllNoneClickHdl, Button *, pButton )
330 bool bAll = pButton == m_pAll;
331 SvTreeListEntry* pEntry = m_pCTRL_LEFT->First();
332 while(pEntry)
334 m_pCTRL_LEFT->SetCheckButtonState( pEntry, bAll ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED);
335 pEntry = m_pCTRL_LEFT->Next(pEntry);
338 return 0;
341 // class OColumnString
342 class OColumnString : public SvLBoxString
344 bool m_bReadOnly;
345 public:
346 OColumnString( SvTreeListEntry* pEntry, sal_uInt16 nFlags, const OUString& rStr, bool _RO)
347 :SvLBoxString(pEntry,nFlags,rStr)
348 ,m_bReadOnly(_RO)
352 virtual void Paint(const Point& rPos, SvTreeListBox& rDev, vcl::RenderContext& rRenderContext,
353 const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
356 void OColumnString::Paint(const Point& rPos, SvTreeListBox& /*rDev*/, vcl::RenderContext& rRenderContext,
357 const SvViewDataEntry* /*pView*/, const SvTreeListEntry* /*pEntry*/)
359 rRenderContext.Push(PushFlags::TEXTCOLOR | PushFlags::TEXTFILLCOLOR);
360 if(m_bReadOnly)
362 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
363 rRenderContext.SetTextColor(rStyleSettings.GetDisableColor());
364 rRenderContext.SetTextFillColor(rStyleSettings.GetFieldColor());
366 rRenderContext.DrawText(rPos, GetText());
367 rRenderContext.Pop();
370 OColumnTreeBox::OColumnTreeBox( vcl::Window* pParent, WinBits nBits )
371 : OMarkableTreeListBox(pParent, nBits)
372 , m_bReadOnly(false)
374 SetDragDropMode( DragDropMode::NONE );
375 EnableInplaceEditing( false );
376 SetStyle(GetStyle() | WB_BORDER | WB_HASBUTTONS | WB_HSCROLL | nBits);
377 SetSelectionMode( SINGLE_SELECTION );
380 VCL_BUILDER_FACTORY(OColumnTreeBox)
382 void OColumnTreeBox::InitEntry(SvTreeListEntry* pEntry, const OUString& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind)
384 DBTreeListBox::InitEntry(pEntry, rStr, rImg1, rImg2, eButtonKind);
385 SvLBoxString* pString = new OColumnString(pEntry, 0, rStr,false);
386 pEntry->ReplaceItem( pString, pEntry->ItemCount() - 1 );
389 bool OColumnTreeBox::Select( SvTreeListEntry* pEntry, bool bSelect )
391 if(bSelect)
393 OFieldDescription* pColumn = static_cast<OFieldDescription*>(pEntry->GetUserData());
394 if(!(pColumn->IsAutoIncrement() && m_bReadOnly))
395 bSelect = DBTreeListBox::Select( pEntry,bSelect );
397 else
398 bSelect = DBTreeListBox::Select( pEntry,bSelect );
399 return bSelect;
402 void OColumnTreeBox::FillListBox( const ODatabaseExport::TColumnVector& _rList)
404 Clear();
405 ODatabaseExport::TColumnVector::const_iterator aIter = _rList.begin();
406 ODatabaseExport::TColumnVector::const_iterator aEnd = _rList.end();
407 for(;aIter != aEnd;++aIter)
409 SvTreeListEntry* pEntry = InsertEntry((*aIter)->first, 0, false, TREELIST_APPEND, (*aIter)->second);
410 SvButtonState eState = !(m_bReadOnly && (*aIter)->second->IsAutoIncrement()) ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED;
411 SetCheckButtonState( pEntry, eState );
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */