LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - WNameMatch.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 203 0.0 %
Date: 2014-04-14 Functions: 0 25 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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 "WizardPages.hrc"
      27             : #include <vcl/scrbar.hxx>
      28             : #include <vcl/settings.hxx>
      29             : #include "svtools/treelistentry.hxx"
      30             : #include <com/sun/star/sdbc/DataType.hpp>
      31             : 
      32             : using namespace ::dbaui;
      33             : // OWizColumnSelect
      34           0 : OWizNameMatching::OWizNameMatching( Window* pParent)
      35             :         :OWizardPage( pParent, ModuleRes( TAB_WIZ_NAME_MATCHING     ) )
      36             :         ,m_FT_TABLE_LEFT(       this, ModuleRes( FT_TABLE_LEFT          ) )
      37             :         ,m_FT_TABLE_RIGHT(      this, ModuleRes( FT_TABLE_RIGHT         ) )
      38             :         ,m_CTRL_LEFT(           this, ModuleRes( CTRL_LEFT              ) )
      39             :         ,m_CTRL_RIGHT(          this, ModuleRes( CTRL_RIGHT             ) )
      40             :         ,m_ibColumn_up(         this, ModuleRes( IB_COLUMN_UP           ) )
      41             :         ,m_ibColumn_down(       this, ModuleRes( IB_COLUMN_DOWN         ) )
      42             :         ,m_ibColumn_up_right(   this, ModuleRes( IB_COLUMN_UP_RIGHT     ) )
      43             :         ,m_ibColumn_down_right( this, ModuleRes( IB_COLUMN_DOWN_RIGHT   ) )
      44             :         ,m_pbAll(               this, ModuleRes( PB_ALL                 ) )
      45           0 :         ,m_pbNone(              this, ModuleRes( PB_NONE                    ) )
      46             : 
      47             : {
      48             : 
      49           0 :     m_ibColumn_up.SetClickHdl(LINK(this,OWizNameMatching,ButtonClickHdl));
      50           0 :     m_ibColumn_down.SetClickHdl(LINK(this,OWizNameMatching,ButtonClickHdl));
      51             : 
      52           0 :     m_ibColumn_up_right.SetClickHdl(LINK(this,OWizNameMatching,RightButtonClickHdl));
      53           0 :     m_ibColumn_down_right.SetClickHdl(LINK(this,OWizNameMatching,RightButtonClickHdl));
      54             : 
      55           0 :     m_pbAll.SetClickHdl(LINK(this,OWizNameMatching,AllNoneClickHdl));
      56           0 :     m_pbNone.SetClickHdl(LINK(this,OWizNameMatching,AllNoneClickHdl));
      57             : 
      58           0 :     m_CTRL_LEFT.SetSelectHdl(LINK(this,OWizNameMatching,TableListClickHdl));
      59           0 :     m_CTRL_RIGHT.SetSelectHdl(LINK(this,OWizNameMatching,TableListRightSelectHdl));
      60           0 :     m_CTRL_RIGHT.EnableCheckButton( NULL );
      61             : 
      62           0 :     m_CTRL_LEFT.SetStyle( m_CTRL_LEFT.GetStyle() | WB_FORCE_MAKEVISIBLE );
      63           0 :     m_CTRL_RIGHT.SetStyle( m_CTRL_RIGHT.GetStyle() | WB_FORCE_MAKEVISIBLE );
      64             : 
      65           0 :     m_sSourceText = m_FT_TABLE_LEFT.GetText();
      66           0 :     m_sSourceText += "\n";
      67           0 :     m_sDestText   = m_FT_TABLE_RIGHT.GetText();
      68           0 :     m_sDestText   += "\n";
      69             : 
      70           0 :     FreeResource();
      71           0 : }
      72             : 
      73           0 : OWizNameMatching::~OWizNameMatching()
      74             : {
      75           0 : }
      76             : 
      77           0 : void OWizNameMatching::Reset()
      78             : {
      79             :     // urspr"unglichen zustand wiederherstellen
      80             :     // the left tree contains bitmaps so i need to resize the right one
      81           0 :     if(m_bFirstTime)
      82             :     {
      83           0 :         m_CTRL_RIGHT.SetReadOnly(); // sets autoinc to readonly
      84           0 :         m_CTRL_RIGHT.SetEntryHeight(m_CTRL_LEFT.GetEntryHeight());
      85           0 :         m_CTRL_RIGHT.SetIndent(m_CTRL_LEFT.GetIndent());
      86           0 :         m_CTRL_RIGHT.SetSpaceBetweenEntries(m_CTRL_LEFT.GetSpaceBetweenEntries());
      87             : 
      88           0 :         m_bFirstTime = sal_False;
      89             :     }
      90             : 
      91           0 : }
      92             : 
      93           0 : void OWizNameMatching::ActivatePage( )
      94             : {
      95             : 
      96             :     // set source table name
      97           0 :     OUString aName = m_sSourceText;
      98           0 :     aName += m_pParent->m_sSourceName;
      99             : 
     100           0 :     m_FT_TABLE_LEFT.SetText(aName);
     101             : 
     102             :     // set dest table name
     103           0 :     aName = m_sDestText;
     104           0 :     aName += m_pParent->m_sName;
     105           0 :     m_FT_TABLE_RIGHT.SetText(aName);
     106             : 
     107           0 :     m_CTRL_LEFT.FillListBox(*m_pParent->getSrcVector());
     108           0 :     m_CTRL_RIGHT.FillListBox(*m_pParent->getDestVector());
     109             : 
     110           0 :     m_ibColumn_up.Enable( m_CTRL_LEFT.GetEntryCount() > 1 );
     111           0 :     m_ibColumn_down.Enable( m_CTRL_LEFT.GetEntryCount() > 1 );
     112             : 
     113           0 :     m_ibColumn_up_right.Enable( m_CTRL_RIGHT.GetEntryCount() > 1 );
     114           0 :     m_ibColumn_down_right.Enable( m_CTRL_RIGHT.GetEntryCount() > 1 );
     115             : 
     116           0 :     m_pParent->EnableButton(OCopyTableWizard::WIZARD_NEXT,sal_False);
     117           0 :     m_CTRL_LEFT.GrabFocus();
     118           0 : }
     119             : 
     120           0 : sal_Bool OWizNameMatching::LeavePage()
     121             : {
     122             : 
     123           0 :     const ODatabaseExport::TColumnVector* pSrcColumns = m_pParent->getSrcVector();
     124             : 
     125           0 :     m_pParent->m_vColumnPos.clear();
     126           0 :     m_pParent->m_vColumnTypes.clear();
     127           0 :     m_pParent->m_vColumnPos.resize( pSrcColumns->size(), ODatabaseExport::TPositions::value_type( COLUMN_POSITION_NOT_FOUND, COLUMN_POSITION_NOT_FOUND ) );
     128           0 :     m_pParent->m_vColumnTypes.resize( pSrcColumns->size(), COLUMN_POSITION_NOT_FOUND );
     129             : 
     130           0 :     sal_Int32 nParamPos = 0;
     131           0 :     SvTreeListEntry* pLeftEntry = m_CTRL_LEFT.GetModel()->First();
     132           0 :     SvTreeListEntry* pRightEntry = m_CTRL_RIGHT.GetModel()->First();
     133           0 :     while(pLeftEntry && pRightEntry)
     134             :     {
     135           0 :         OFieldDescription* pSrcField = static_cast<OFieldDescription*>(pLeftEntry->GetUserData());
     136             :         OSL_ENSURE(pSrcField,"OWizNameMatching: OColumn can not be null!");
     137             : 
     138           0 :         ODatabaseExport::TColumnVector::const_iterator aSrcIter = pSrcColumns->begin();
     139           0 :         ODatabaseExport::TColumnVector::const_iterator aSrcEnd  = pSrcColumns->end();
     140           0 :         for(;aSrcIter != aSrcEnd && (*aSrcIter)->second != pSrcField;++aSrcIter)
     141             :             ;
     142           0 :         const sal_Int32 nPos = ::std::distance(pSrcColumns->begin(),aSrcIter);
     143             : 
     144           0 :         if(m_CTRL_LEFT.GetCheckButtonState(pLeftEntry) == SV_BUTTON_CHECKED)
     145             :         {
     146           0 :             OFieldDescription* pDestField = static_cast<OFieldDescription*>(pRightEntry->GetUserData());
     147             :             OSL_ENSURE(pDestField,"OWizNameMatching: OColumn can not be null!");
     148           0 :             const ODatabaseExport::TColumnVector* pDestColumns          = m_pParent->getDestVector();
     149           0 :             ODatabaseExport::TColumnVector::const_iterator aDestIter    = pDestColumns->begin();
     150           0 :             ODatabaseExport::TColumnVector::const_iterator aDestEnd = pDestColumns->end();
     151             : 
     152           0 :             for(;aDestIter != aDestEnd && (*aDestIter)->second != pDestField;++aDestIter)
     153             :                 ;
     154             : 
     155             :             OSL_ENSURE((nPos) < static_cast<sal_Int32>(m_pParent->m_vColumnPos.size()),"m_pParent->m_vColumnPos: Illegal index for vector");
     156           0 :             m_pParent->m_vColumnPos[nPos].first = ++nParamPos;
     157           0 :             m_pParent->m_vColumnPos[nPos].second = ::std::distance(pDestColumns->begin(),aDestIter) + 1;
     158           0 :             sal_Bool bNotConvert = sal_True;
     159             : 
     160           0 :             TOTypeInfoSP pTypeInfo;
     161             : 
     162             :             assert(aDestIter != aDestEnd);
     163           0 :             if (aDestIter != aDestEnd)
     164           0 :                 pTypeInfo = m_pParent->convertType((*aDestIter)->second->getSpecialTypeInfo(),bNotConvert);
     165             : 
     166           0 :             sal_Int32 nType = ::com::sun::star::sdbc::DataType::VARCHAR;
     167           0 :             if ( pTypeInfo.get() )
     168           0 :                 nType = pTypeInfo->nType;
     169           0 :             m_pParent->m_vColumnTypes[nPos] = nType;
     170             :         }
     171             :         else
     172             :         {
     173           0 :             m_pParent->m_vColumnPos[nPos].first = COLUMN_POSITION_NOT_FOUND;
     174           0 :             m_pParent->m_vColumnPos[nPos].second = COLUMN_POSITION_NOT_FOUND;
     175             :         }
     176             : 
     177           0 :         pLeftEntry = m_CTRL_LEFT.GetModel()->Next(pLeftEntry);
     178           0 :         pRightEntry = m_CTRL_RIGHT.GetModel()->Next(pRightEntry);
     179             :     }
     180             : 
     181           0 :     return sal_True;
     182             : }
     183             : 
     184           0 : OUString OWizNameMatching::GetTitle() const { return ModuleRes(STR_WIZ_NAME_MATCHING_TITEL); }
     185             : 
     186           0 : IMPL_LINK( OWizNameMatching, ButtonClickHdl, Button *, pButton )
     187             : {
     188           0 :     SvTreeListEntry* pEntry = m_CTRL_LEFT.FirstSelected();
     189           0 :     if ( pEntry )
     190             :     {
     191           0 :         sal_Int32 nPos      = m_CTRL_LEFT.GetModel()->GetAbsPos(pEntry);
     192           0 :         if(pButton == &m_ibColumn_up && nPos)
     193           0 :             --nPos;
     194           0 :         else if(pButton == &m_ibColumn_down)
     195           0 :             nPos += 2;
     196             : 
     197           0 :         m_CTRL_LEFT.ModelIsMoving(pEntry,NULL,nPos);
     198           0 :         m_CTRL_LEFT.GetModel()->Move(pEntry,NULL,nPos);
     199           0 :         m_CTRL_LEFT.ModelHasMoved(pEntry);
     200             : 
     201           0 :         long nThumbPos      = m_CTRL_LEFT.GetVScroll()->GetThumbPos();
     202           0 :         long nVisibleSize   = m_CTRL_LEFT.GetVScroll()->GetVisibleSize();
     203             : 
     204           0 :         if(pButton == &m_ibColumn_down && (nThumbPos+nVisibleSize+1) < nPos)
     205             :         {
     206           0 :             m_CTRL_LEFT.GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
     207             :         }
     208             : 
     209           0 :         TableListClickHdl(&m_CTRL_LEFT);
     210             :     }
     211             : 
     212           0 :     return 0;
     213             : }
     214             : 
     215           0 : IMPL_LINK( OWizNameMatching, RightButtonClickHdl, Button *, pButton )
     216             : {
     217           0 :     SvTreeListEntry* pEntry = m_CTRL_RIGHT.FirstSelected();
     218           0 :     if ( pEntry )
     219             :     {
     220           0 :         sal_Int32 nPos      = m_CTRL_RIGHT.GetModel()->GetAbsPos(pEntry);
     221           0 :         if(pButton == &m_ibColumn_up_right && nPos)
     222           0 :             --nPos;
     223           0 :         else if(pButton == &m_ibColumn_down_right)
     224           0 :             nPos += 2;
     225             : 
     226           0 :         m_CTRL_RIGHT.ModelIsMoving(pEntry,NULL,nPos);
     227           0 :         m_CTRL_RIGHT.GetModel()->Move(pEntry,NULL,nPos);
     228           0 :         m_CTRL_RIGHT.ModelHasMoved(pEntry);
     229           0 :         long nThumbPos      = m_CTRL_RIGHT.GetVScroll()->GetThumbPos();
     230           0 :         long nVisibleSize   = m_CTRL_RIGHT.GetVScroll()->GetVisibleSize();
     231             : 
     232           0 :         if(pButton == &m_ibColumn_down_right && (nThumbPos+nVisibleSize+1) < nPos)
     233           0 :             m_CTRL_RIGHT.GetVScroll()->DoScrollAction(SCROLL_LINEDOWN);
     234           0 :         TableListRightSelectHdl(&m_CTRL_RIGHT);
     235             :     }
     236           0 :     return 0;
     237             : }
     238             : 
     239           0 : IMPL_LINK( OWizNameMatching, TableListClickHdl, void*, /*NOTINTERESTEDIN*/ )
     240             : {
     241           0 :     SvTreeListEntry* pEntry = m_CTRL_LEFT.FirstSelected();
     242           0 :     if(pEntry)
     243             :     {
     244           0 :         sal_uLong nPos          = m_CTRL_LEFT.GetModel()->GetAbsPos(pEntry);
     245           0 :         SvTreeListEntry* pOldEntry = m_CTRL_RIGHT.FirstSelected();
     246           0 :         if(pOldEntry && nPos != m_CTRL_RIGHT.GetModel()->GetAbsPos(pOldEntry))
     247             :         {
     248           0 :             if(pOldEntry)
     249           0 :                 m_CTRL_RIGHT.Select(pOldEntry,sal_False);
     250           0 :             pOldEntry = m_CTRL_RIGHT.GetEntry(nPos);
     251           0 :             if(pOldEntry)
     252             :             {
     253           0 :                 sal_uLong nNewPos = m_CTRL_LEFT.GetModel()->GetAbsPos(m_CTRL_LEFT.GetFirstEntryInView());
     254           0 :                 if ( nNewPos - nPos == 1 )
     255           0 :                     --nNewPos;
     256           0 :                 m_CTRL_RIGHT.MakeVisible(m_CTRL_RIGHT.GetEntry(nNewPos), true);
     257           0 :                 m_CTRL_RIGHT.Select(pOldEntry,sal_True);
     258             :             }
     259             :         }
     260           0 :         else if(!pOldEntry)
     261             :         {
     262           0 :             pOldEntry = m_CTRL_RIGHT.GetEntry(nPos);
     263           0 :             if(pOldEntry)
     264             :             {
     265           0 :                 m_CTRL_RIGHT.Select(pOldEntry,sal_True);
     266             :             }
     267             :         }
     268             :     }
     269             : 
     270           0 :     return 0;
     271             : }
     272             : 
     273           0 : IMPL_LINK( OWizNameMatching, TableListRightSelectHdl, void*, /*NOTINTERESTEDIN*/ )
     274             : {
     275           0 :     SvTreeListEntry* pEntry = m_CTRL_RIGHT.FirstSelected();
     276           0 :     if(pEntry)
     277             :     {
     278           0 :         sal_uLong nPos          = m_CTRL_RIGHT.GetModel()->GetAbsPos(pEntry);
     279           0 :         SvTreeListEntry* pOldEntry = m_CTRL_LEFT.FirstSelected();
     280           0 :         if(pOldEntry && nPos != m_CTRL_LEFT.GetModel()->GetAbsPos(pOldEntry))
     281             :         {
     282           0 :             if(pOldEntry)
     283           0 :                 m_CTRL_LEFT.Select(pOldEntry,sal_False);
     284           0 :             pOldEntry = m_CTRL_LEFT.GetEntry(nPos);
     285           0 :             if(pOldEntry)
     286             :             {
     287           0 :                 sal_uLong nNewPos = m_CTRL_RIGHT.GetModel()->GetAbsPos(m_CTRL_RIGHT.GetFirstEntryInView());
     288           0 :                 if ( nNewPos - nPos == 1 )
     289           0 :                     nNewPos--;
     290           0 :                 m_CTRL_LEFT.MakeVisible(m_CTRL_LEFT.GetEntry(nNewPos), true);
     291           0 :                 m_CTRL_LEFT.Select(pOldEntry,sal_True);
     292             :             }
     293             :         }
     294           0 :         else if(!pOldEntry)
     295             :         {
     296           0 :             pOldEntry = m_CTRL_LEFT.GetEntry(nPos);
     297           0 :             if(pOldEntry)
     298             :             {
     299           0 :                 m_CTRL_LEFT.Select(pOldEntry,sal_True);
     300             :             }
     301             :         }
     302             :     }
     303             : 
     304           0 :     return 0;
     305             : }
     306             : 
     307           0 : IMPL_LINK( OWizNameMatching, AllNoneClickHdl, Button *, pButton )
     308             : {
     309           0 :     sal_Bool bAll = pButton == &m_pbAll;
     310           0 :     SvTreeListEntry* pEntry = m_CTRL_LEFT.First();
     311           0 :     while(pEntry)
     312             :     {
     313           0 :         m_CTRL_LEFT.SetCheckButtonState( pEntry, bAll ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED);
     314           0 :         pEntry = m_CTRL_LEFT.Next(pEntry);
     315             :     }
     316             : 
     317           0 :     return 0;
     318             : }
     319             : 
     320             : // class OColumnString
     321           0 : class OColumnString : public SvLBoxString
     322             : {
     323             :     sal_Bool m_bReadOnly;
     324             : public:
     325           0 :     OColumnString( SvTreeListEntry* pEntry, sal_uInt16 nFlags, const OUString& rStr, sal_Bool _RO)
     326             :         :SvLBoxString(pEntry,nFlags,rStr)
     327           0 :         ,m_bReadOnly(_RO)
     328             :     {
     329           0 :     }
     330             : 
     331             :     virtual void Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
     332             : };
     333             : 
     334           0 : void OColumnString::Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* /*pView*/, const SvTreeListEntry* /*pEntry*/)
     335             : {
     336           0 :     if(m_bReadOnly)
     337             :     {
     338           0 :         const StyleSettings& rStyleSettings = rDev.GetSettings().GetStyleSettings();
     339           0 :         rDev.SetTextColor( rStyleSettings.GetDisableColor() );
     340           0 :         rDev.SetTextFillColor( rStyleSettings.GetFieldColor() );
     341             :     }
     342           0 :     rDev.DrawText( rPos, GetText() );
     343           0 : }
     344             : 
     345           0 : OColumnTreeBox::OColumnTreeBox( Window* pParent, const ResId& rResId )
     346             :     : OMarkableTreeListBox(pParent, rResId)
     347           0 :     , m_bReadOnly(false)
     348             : {
     349           0 :     SetDragDropMode( 0 );
     350           0 :     EnableInplaceEditing( false );
     351           0 :     SetStyle(GetStyle() | WB_BORDER | WB_HASBUTTONS | WB_HSCROLL);
     352           0 :     SetSelectionMode( SINGLE_SELECTION );
     353           0 : }
     354             : 
     355           0 : void OColumnTreeBox::InitEntry(SvTreeListEntry* pEntry, const OUString& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind)
     356             : {
     357           0 :     DBTreeListBox::InitEntry(pEntry, rStr, rImg1, rImg2, eButtonKind);
     358           0 :     SvLBoxString* pString = new OColumnString(pEntry, 0, rStr,sal_False);
     359           0 :     if (pString)
     360           0 :         pEntry->ReplaceItem( pString, pEntry->ItemCount() - 1 );
     361           0 : }
     362             : 
     363           0 : sal_Bool OColumnTreeBox::Select( SvTreeListEntry* pEntry, sal_Bool bSelect )
     364             : {
     365           0 :     if(bSelect)
     366             :     {
     367           0 :         OFieldDescription* pColumn = static_cast<OFieldDescription*>(pEntry->GetUserData());
     368           0 :         if(!(pColumn->IsAutoIncrement() && m_bReadOnly))
     369           0 :             bSelect = DBTreeListBox::Select( pEntry,bSelect );
     370             :     }
     371             :     else
     372           0 :         bSelect = DBTreeListBox::Select( pEntry,bSelect );
     373           0 :     return bSelect;
     374             : }
     375             : 
     376           0 : void OColumnTreeBox::FillListBox( const ODatabaseExport::TColumnVector& _rList)
     377             : {
     378           0 :     Clear();
     379           0 :     ODatabaseExport::TColumnVector::const_iterator aIter = _rList.begin();
     380           0 :     ODatabaseExport::TColumnVector::const_iterator aEnd = _rList.end();
     381           0 :     for(;aIter != aEnd;++aIter)
     382             :     {
     383           0 :         SvTreeListEntry* pEntry = InsertEntry((*aIter)->first, 0, false, TREELIST_APPEND, (*aIter)->second);
     384           0 :         SvButtonState eState = !(m_bReadOnly && (*aIter)->second->IsAutoIncrement()) ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED;
     385           0 :         SetCheckButtonState( pEntry, eState );
     386             :     }
     387           0 : }
     388             : 
     389             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10