LCOV - code coverage report
Current view: top level - sc/source/ui/dbgui - csvgrid.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 815 0.0 %
Date: 2012-08-25 Functions: 0 84 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 981 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      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.
      15                 :            :  *
      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).
      21                 :            :  *
      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.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "csvgrid.hxx"
      30                 :            : 
      31                 :            : #include <algorithm>
      32                 :            : #include <memory>
      33                 :            : 
      34                 :            : #include <comphelper/string.hxx>
      35                 :            : #include <svtools/colorcfg.hxx>
      36                 :            : #include <svl/smplhint.hxx>
      37                 :            : #include <sal/macros.h>
      38                 :            : #include <tools/poly.hxx>
      39                 :            : #include "scmod.hxx"
      40                 :            : #include "asciiopt.hxx"
      41                 :            : #include "impex.hxx"
      42                 :            : #include "AccessibleCsvControl.hxx"
      43                 :            : 
      44                 :            : // *** edit engine ***
      45                 :            : #include "scitems.hxx"
      46                 :            : #include <editeng/eeitem.hxx>
      47                 :            : 
      48                 :            : 
      49                 :            : #include <editeng/colritem.hxx>
      50                 :            : #include <editeng/fhgtitem.hxx>
      51                 :            : #include <editeng/fontitem.hxx>
      52                 :            : #include <svl/itemset.hxx>
      53                 :            : #include "editutil.hxx"
      54                 :            : // *** edit engine ***
      55                 :            : 
      56                 :            : 
      57                 :            : // ============================================================================
      58                 :            : 
      59                 :            : struct Func_SetType
      60                 :            : {
      61                 :            :     sal_Int32                   mnType;
      62                 :          0 :     inline                      Func_SetType( sal_Int32 nType ) : mnType( nType ) {}
      63                 :          0 :     inline void                 operator()( ScCsvColState& rState ) const
      64                 :          0 :         { rState.mnType = mnType; }
      65                 :            : };
      66                 :            : 
      67                 :            : struct Func_Select
      68                 :            : {
      69                 :            :     bool                        mbSelect;
      70                 :          0 :     inline                      Func_Select( bool bSelect ) : mbSelect( bSelect ) {}
      71                 :          0 :     inline void                 operator()( ScCsvColState& rState ) const
      72                 :          0 :         { rState.Select( mbSelect ); }
      73                 :            : };
      74                 :            : 
      75                 :            : 
      76                 :            : // ============================================================================
      77                 :            : 
      78                 :          0 : ScCsvGrid::ScCsvGrid( ScCsvControl& rParent ) :
      79                 :            :     ScCsvControl( rParent ),
      80                 :            :     mpColorConfig( 0 ),
      81         [ #  # ]:          0 :     mpEditEngine( new ScEditEngineDefaulter( EditEngine::CreatePool(), true ) ),
      82                 :          0 :     maHeaderFont( GetFont() ),
      83                 :            :     maColStates( 1 ),
      84                 :            :     maTypeNames( 1 ),
      85                 :            :     mnFirstImpLine( 0 ),
      86 [ #  # ][ #  # ]:          0 :     mnRecentSelCol( CSV_COLUMN_INVALID )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      87                 :            : {
      88         [ #  # ]:          0 :     mpEditEngine->SetRefDevice( &maBackgrDev );
      89 [ #  # ][ #  # ]:          0 :     mpEditEngine->SetRefMapMode( MapMode( MAP_PIXEL ) );
                 [ #  # ]
      90         [ #  # ]:          0 :     maEdEngSize = mpEditEngine->GetPaperSize();
      91                 :            : 
      92                 :          0 :     maPopup.SetMenuFlags( maPopup.GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS );
      93                 :            : 
      94         [ #  # ]:          0 :     EnableRTL( false ); // RTL
      95         [ #  # ]:          0 :     InitFonts();
      96         [ #  # ]:          0 :     ImplClearSplits();
      97                 :          0 : }
      98                 :            : 
      99 [ #  # ][ #  # ]:          0 : ScCsvGrid::~ScCsvGrid()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     100                 :            : {
     101                 :            :     OSL_ENSURE(mpColorConfig, "the object hasn't been initialized properly");
     102         [ #  # ]:          0 :     if (mpColorConfig)
     103         [ #  # ]:          0 :         mpColorConfig->RemoveListener(this);
     104         [ #  # ]:          0 : }
     105                 :            : 
     106                 :            : void
     107                 :          0 : ScCsvGrid::Init()
     108                 :            : {
     109                 :            :     OSL_PRECOND(!mpColorConfig, "the object has already been initialized");
     110                 :          0 :     mpColorConfig = &SC_MOD()->GetColorConfig();
     111                 :          0 :     InitColors();
     112                 :          0 :     mpColorConfig->AddListener(this);
     113                 :          0 : }
     114                 :            : 
     115                 :            : // common grid handling -------------------------------------------------------
     116                 :            : 
     117                 :          0 : void ScCsvGrid::UpdateLayoutData()
     118                 :            : {
     119                 :          0 :     DisableRepaint();
     120                 :          0 :     SetFont( maMonoFont );
     121 [ #  # ][ #  # ]:          0 :     Execute( CSVCMD_SETCHARWIDTH, GetTextWidth( rtl::OUString( 'X' ) ) );
         [ #  # ][ #  # ]
     122                 :          0 :     Execute( CSVCMD_SETLINEHEIGHT, GetTextHeight() + 1 );
     123                 :          0 :     SetFont( maHeaderFont );
     124                 :          0 :     Execute( CSVCMD_SETHDRHEIGHT, GetTextHeight() + 1 );
     125                 :          0 :     UpdateOffsetX();
     126                 :          0 :     EnableRepaint();
     127                 :          0 : }
     128                 :            : 
     129                 :          0 : void ScCsvGrid::UpdateOffsetX()
     130                 :            : {
     131                 :          0 :     sal_Int32 nLastLine = GetLastVisLine() + 1;
     132                 :          0 :     sal_Int32 nDigits = 2;
     133         [ #  # ]:          0 :     while( nLastLine /= 10 ) ++nDigits;
     134                 :          0 :     nDigits = Max( nDigits, sal_Int32( 3 ) );
     135 [ #  # ][ #  # ]:          0 :     Execute( CSVCMD_SETHDRWIDTH, GetTextWidth( rtl::OUString( '0' ) ) * nDigits );
         [ #  # ][ #  # ]
     136                 :          0 : }
     137                 :            : 
     138                 :          0 : void ScCsvGrid::ApplyLayout( const ScCsvLayoutData& rOldData )
     139                 :            : {
     140                 :          0 :     ScCsvDiff nDiff = GetLayoutData().GetDiff( rOldData );
     141         [ #  # ]:          0 :     if( nDiff == CSV_DIFF_EQUAL ) return;
     142                 :            : 
     143                 :          0 :     DisableRepaint();
     144                 :            : 
     145         [ #  # ]:          0 :     if( nDiff & CSV_DIFF_RULERCURSOR )
     146                 :            :     {
     147                 :          0 :         ImplInvertCursor( rOldData.mnPosCursor );
     148                 :          0 :         ImplInvertCursor( GetRulerCursorPos() );
     149                 :            :     }
     150                 :            : 
     151         [ #  # ]:          0 :     if( nDiff & CSV_DIFF_POSCOUNT )
     152                 :            :     {
     153         [ #  # ]:          0 :         if( GetPosCount() < rOldData.mnPosCount )
     154                 :            :         {
     155                 :          0 :             SelectAll( false );
     156                 :          0 :             maSplits.RemoveRange( GetPosCount(), rOldData.mnPosCount );
     157                 :            :         }
     158                 :            :         else
     159                 :          0 :             maSplits.Remove( rOldData.mnPosCount );
     160                 :          0 :         maSplits.Insert( GetPosCount() );
     161                 :          0 :         maColStates.resize( maSplits.Count() - 1 );
     162                 :            :     }
     163                 :            : 
     164         [ #  # ]:          0 :     if( nDiff & CSV_DIFF_LINEOFFSET )
     165                 :            :     {
     166                 :          0 :         Execute( CSVCMD_UPDATECELLTEXTS );
     167                 :          0 :         UpdateOffsetX();
     168                 :            :     }
     169                 :            : 
     170                 :          0 :     ScCsvDiff nHVDiff = nDiff & (CSV_DIFF_HORIZONTAL | CSV_DIFF_VERTICAL);
     171         [ #  # ]:          0 :     if( nHVDiff == CSV_DIFF_POSOFFSET )
     172                 :          0 :         ImplDrawHorzScrolled( rOldData.mnPosOffset );
     173         [ #  # ]:          0 :     else if( nHVDiff != CSV_DIFF_EQUAL )
     174                 :          0 :         InvalidateGfx();
     175                 :            : 
     176                 :          0 :     EnableRepaint();
     177                 :            : 
     178         [ #  # ]:          0 :     if( nDiff & (CSV_DIFF_POSOFFSET | CSV_DIFF_LINEOFFSET) )
     179                 :          0 :         AccSendVisibleEvent();
     180                 :            : }
     181                 :            : 
     182                 :          0 : void ScCsvGrid::SetFirstImportedLine( sal_Int32 nLine )
     183                 :            : {
     184                 :          0 :     ImplDrawFirstLineSep( false );
     185                 :          0 :     mnFirstImpLine = nLine;
     186                 :          0 :     ImplDrawFirstLineSep( true );
     187                 :          0 :     ImplDrawGridDev();
     188                 :          0 :     Repaint();
     189                 :          0 : }
     190                 :            : 
     191                 :          0 : sal_Int32 ScCsvGrid::GetNoScrollCol( sal_Int32 nPos ) const
     192                 :            : {
     193                 :          0 :     sal_Int32 nNewPos = nPos;
     194         [ #  # ]:          0 :     if( nNewPos != CSV_POS_INVALID )
     195                 :            :     {
     196         [ #  # ]:          0 :         if( nNewPos < GetFirstVisPos() + CSV_SCROLL_DIST )
     197                 :            :         {
     198         [ #  # ]:          0 :             sal_Int32 nScroll = (GetFirstVisPos() > 0) ? CSV_SCROLL_DIST : 0;
     199                 :          0 :             nNewPos = GetFirstVisPos() + nScroll;
     200                 :            :         }
     201         [ #  # ]:          0 :         else if( nNewPos > GetLastVisPos() - CSV_SCROLL_DIST - 1L )
     202                 :            :         {
     203         [ #  # ]:          0 :             sal_Int32 nScroll = (GetFirstVisPos() < GetMaxPosOffset()) ? CSV_SCROLL_DIST : 0;
     204                 :          0 :             nNewPos = GetLastVisPos() - nScroll - 1;
     205                 :            :         }
     206                 :            :     }
     207                 :          0 :     return nNewPos;
     208                 :            : }
     209                 :            : 
     210                 :          0 : void ScCsvGrid::InitColors()
     211                 :            : {
     212                 :            :     OSL_PRECOND(mpColorConfig, "the object hasn't been initialized properly");
     213         [ #  # ]:          0 :     if ( !mpColorConfig )
     214                 :          0 :         return;
     215                 :          0 :     maBackColor.SetColor( static_cast< sal_uInt32 >( mpColorConfig->GetColorValue( ::svtools::DOCCOLOR ).nColor ) );
     216                 :          0 :     maGridColor.SetColor( static_cast< sal_uInt32 >( mpColorConfig->GetColorValue( ::svtools::CALCGRID ).nColor ) );
     217                 :          0 :     maGridPBColor.SetColor( static_cast< sal_uInt32 >( mpColorConfig->GetColorValue( ::svtools::CALCPAGEBREAK ).nColor ) );
     218                 :          0 :     maAppBackColor.SetColor( static_cast< sal_uInt32 >( mpColorConfig->GetColorValue( ::svtools::APPBACKGROUND ).nColor ) );
     219                 :          0 :     maTextColor.SetColor( static_cast< sal_uInt32 >( mpColorConfig->GetColorValue( ::svtools::FONTCOLOR ).nColor ) );
     220                 :            : 
     221                 :          0 :     const StyleSettings& rSett = GetSettings().GetStyleSettings();
     222                 :          0 :     maHeaderBackColor = rSett.GetFaceColor();
     223                 :          0 :     maHeaderGridColor = rSett.GetDarkShadowColor();
     224                 :          0 :     maHeaderTextColor = rSett.GetButtonTextColor();
     225                 :          0 :     maSelectColor = rSett.GetActiveColor();
     226                 :            : 
     227                 :          0 :     InvalidateGfx();
     228                 :            : }
     229                 :            : 
     230                 :          0 : void ScCsvGrid::InitFonts()
     231                 :            : {
     232 [ #  # ][ #  # ]:          0 :     maMonoFont = OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, LANGUAGE_ENGLISH_US, 0 );
                 [ #  # ]
     233 [ #  # ][ #  # ]:          0 :     maMonoFont.SetSize( Size( maMonoFont.GetSize().Width(), maHeaderFont.GetSize().Height() ) );
                 [ #  # ]
     234                 :            : 
     235                 :            :     /* *** Set edit engine defaults ***
     236                 :            :         maMonoFont for Latin script, smaller default font for Asian and Complex script. */
     237                 :            : 
     238                 :            :     // get default fonts
     239         [ #  # ]:          0 :     SvxFontItem aLatinItem( EE_CHAR_FONTINFO );
     240         [ #  # ]:          0 :     SvxFontItem aAsianItem( EE_CHAR_FONTINFO_CJK );
     241         [ #  # ]:          0 :     SvxFontItem aComplexItem( EE_CHAR_FONTINFO_CTL );
     242         [ #  # ]:          0 :     ::GetDefaultFonts( aLatinItem, aAsianItem, aComplexItem );
     243                 :            : 
     244                 :            :     // create item set for defaults
     245 [ #  # ][ #  # ]:          0 :     SfxItemSet aDefSet( mpEditEngine->GetEmptyItemSet() );
     246         [ #  # ]:          0 :     EditEngine::SetFontInfoInItemSet( aDefSet, maMonoFont );
     247         [ #  # ]:          0 :     aDefSet.Put( aAsianItem );
     248         [ #  # ]:          0 :     aDefSet.Put( aComplexItem );
     249                 :            : 
     250                 :            :     // set Asian/Complex font size to height of character in Latin font
     251         [ #  # ]:          0 :     sal_uLong nFontHt = static_cast< sal_uLong >( maMonoFont.GetSize().Height() );
     252 [ #  # ][ #  # ]:          0 :     aDefSet.Put( SvxFontHeightItem( nFontHt, 100, EE_CHAR_FONTHEIGHT_CJK ) );
                 [ #  # ]
     253 [ #  # ][ #  # ]:          0 :     aDefSet.Put( SvxFontHeightItem( nFontHt, 100, EE_CHAR_FONTHEIGHT_CTL ) );
                 [ #  # ]
     254                 :            : 
     255                 :            :     // copy other items from default font
     256         [ #  # ]:          0 :     const SfxPoolItem& rWeightItem = aDefSet.Get( EE_CHAR_WEIGHT );
     257         [ #  # ]:          0 :     aDefSet.Put( rWeightItem, EE_CHAR_WEIGHT_CJK );
     258         [ #  # ]:          0 :     aDefSet.Put( rWeightItem, EE_CHAR_WEIGHT_CTL );
     259         [ #  # ]:          0 :     const SfxPoolItem& rItalicItem = aDefSet.Get( EE_CHAR_ITALIC );
     260         [ #  # ]:          0 :     aDefSet.Put( rItalicItem, EE_CHAR_ITALIC_CJK );
     261         [ #  # ]:          0 :     aDefSet.Put( rItalicItem, EE_CHAR_ITALIC_CTL );
     262         [ #  # ]:          0 :     const SfxPoolItem& rLangItem = aDefSet.Get( EE_CHAR_LANGUAGE );
     263         [ #  # ]:          0 :     aDefSet.Put( rLangItem, EE_CHAR_LANGUAGE_CJK );
     264         [ #  # ]:          0 :     aDefSet.Put( rLangItem, EE_CHAR_LANGUAGE_CTL );
     265                 :            : 
     266         [ #  # ]:          0 :     mpEditEngine->SetDefaults( aDefSet );
     267 [ #  # ][ #  # ]:          0 :     InvalidateGfx();
         [ #  # ][ #  # ]
     268                 :          0 : }
     269                 :            : 
     270                 :          0 : void ScCsvGrid::InitSizeData()
     271                 :            : {
     272                 :          0 :     maWinSize = GetSizePixel();
     273                 :          0 :     maBackgrDev.SetOutputSizePixel( maWinSize );
     274                 :          0 :     maGridDev.SetOutputSizePixel( maWinSize );
     275                 :          0 :     InvalidateGfx();
     276                 :          0 : }
     277                 :            : 
     278                 :            : 
     279                 :            : // split handling -------------------------------------------------------------
     280                 :            : 
     281                 :          0 : void ScCsvGrid::InsertSplit( sal_Int32 nPos )
     282                 :            : {
     283         [ #  # ]:          0 :     if( ImplInsertSplit( nPos ) )
     284                 :            :     {
     285                 :          0 :         DisableRepaint();
     286                 :          0 :         Execute( CSVCMD_EXPORTCOLUMNTYPE );
     287                 :          0 :         Execute( CSVCMD_UPDATECELLTEXTS );
     288                 :          0 :         sal_uInt32 nColIx = GetColumnFromPos( nPos );
     289                 :          0 :         ImplDrawColumn( nColIx - 1 );
     290                 :          0 :         ImplDrawColumn( nColIx );
     291                 :          0 :         ValidateGfx();  // performance: do not redraw all columns
     292                 :          0 :         EnableRepaint();
     293                 :            :     }
     294                 :          0 : }
     295                 :            : 
     296                 :          0 : void ScCsvGrid::RemoveSplit( sal_Int32 nPos )
     297                 :            : {
     298         [ #  # ]:          0 :     if( ImplRemoveSplit( nPos ) )
     299                 :            :     {
     300                 :          0 :         DisableRepaint();
     301                 :          0 :         Execute( CSVCMD_EXPORTCOLUMNTYPE );
     302                 :          0 :         Execute( CSVCMD_UPDATECELLTEXTS );
     303                 :          0 :         ImplDrawColumn( GetColumnFromPos( nPos ) );
     304                 :          0 :         ValidateGfx();  // performance: do not redraw all columns
     305                 :          0 :         EnableRepaint();
     306                 :            :     }
     307                 :          0 : }
     308                 :            : 
     309                 :          0 : void ScCsvGrid::MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos )
     310                 :            : {
     311                 :          0 :     sal_uInt32 nColIx = GetColumnFromPos( nPos );
     312         [ #  # ]:          0 :     if( nColIx != CSV_COLUMN_INVALID )
     313                 :            :     {
     314                 :          0 :         DisableRepaint();
     315 [ #  # ][ #  # ]:          0 :         if( (GetColumnPos( nColIx - 1 ) < nNewPos) && (nNewPos < GetColumnPos( nColIx + 1 )) )
                 [ #  # ]
     316                 :            :         {
     317                 :            :             // move a split in the range between 2 others -> keep selection state of both columns
     318                 :          0 :             maSplits.Remove( nPos );
     319                 :          0 :             maSplits.Insert( nNewPos );
     320                 :          0 :             Execute( CSVCMD_UPDATECELLTEXTS );
     321                 :          0 :             ImplDrawColumn( nColIx - 1 );
     322                 :          0 :             ImplDrawColumn( nColIx );
     323                 :          0 :             ValidateGfx();  // performance: do not redraw all columns
     324                 :          0 :             AccSendTableUpdateEvent( nColIx - 1, nColIx );
     325                 :            :         }
     326                 :            :         else
     327                 :            :         {
     328                 :          0 :             ImplRemoveSplit( nPos );
     329                 :          0 :             ImplInsertSplit( nNewPos );
     330                 :          0 :             Execute( CSVCMD_EXPORTCOLUMNTYPE );
     331                 :          0 :             Execute( CSVCMD_UPDATECELLTEXTS );
     332                 :            :         }
     333                 :          0 :         EnableRepaint();
     334                 :            :     }
     335                 :          0 : }
     336                 :            : 
     337                 :          0 : void ScCsvGrid::RemoveAllSplits()
     338                 :            : {
     339                 :          0 :     DisableRepaint();
     340                 :          0 :     ImplClearSplits();
     341                 :          0 :     Execute( CSVCMD_EXPORTCOLUMNTYPE );
     342                 :          0 :     Execute( CSVCMD_UPDATECELLTEXTS );
     343                 :          0 :     EnableRepaint();
     344                 :          0 : }
     345                 :            : 
     346                 :          0 : void ScCsvGrid::SetSplits( const ScCsvSplits& rSplits )
     347                 :            : {
     348                 :          0 :     DisableRepaint();
     349                 :          0 :     ImplClearSplits();
     350                 :          0 :     sal_uInt32 nCount = rSplits.Count();
     351         [ #  # ]:          0 :     for( sal_uInt32 nIx = 0; nIx < nCount; ++nIx )
     352                 :          0 :         maSplits.Insert( rSplits[ nIx ] );
     353                 :          0 :     maColStates.clear();
     354                 :          0 :     maColStates.resize( maSplits.Count() - 1 );
     355                 :          0 :     Execute( CSVCMD_EXPORTCOLUMNTYPE );
     356                 :          0 :     Execute( CSVCMD_UPDATECELLTEXTS );
     357                 :          0 :     EnableRepaint();
     358                 :          0 : }
     359                 :            : 
     360                 :          0 : bool ScCsvGrid::ImplInsertSplit( sal_Int32 nPos )
     361                 :            : {
     362                 :          0 :     sal_uInt32 nColIx = GetColumnFromPos( nPos );
     363 [ #  # ][ #  # ]:          0 :     bool bRet = (nColIx < GetColumnCount()) && maSplits.Insert( nPos );
     364         [ #  # ]:          0 :     if( bRet )
     365                 :            :     {
     366         [ #  # ]:          0 :         ScCsvColState aState( GetColumnType( nColIx ) );
     367 [ #  # ][ #  # ]:          0 :         aState.Select( IsSelected( nColIx ) && IsSelected( nColIx + 1 ) );
         [ #  # ][ #  # ]
     368 [ #  # ][ #  # ]:          0 :         maColStates.insert( maColStates.begin() + nColIx + 1, aState );
                 [ #  # ]
     369         [ #  # ]:          0 :         AccSendInsertColumnEvent( nColIx + 1, nColIx + 1 );
     370         [ #  # ]:          0 :         AccSendTableUpdateEvent( nColIx, nColIx );
     371                 :            :     }
     372                 :          0 :     return bRet;
     373                 :            : }
     374                 :            : 
     375                 :          0 : bool ScCsvGrid::ImplRemoveSplit( sal_Int32 nPos )
     376                 :            : {
     377                 :          0 :     bool bRet = maSplits.Remove( nPos );
     378         [ #  # ]:          0 :     if( bRet )
     379                 :            :     {
     380                 :          0 :         sal_uInt32 nColIx = GetColumnFromPos( nPos );
     381 [ #  # ][ #  # ]:          0 :         bool bSel = IsSelected( nColIx ) || IsSelected( nColIx + 1 );
     382 [ #  # ][ #  # ]:          0 :         maColStates.erase( maColStates.begin() + nColIx + 1 );
                 [ #  # ]
     383                 :          0 :         maColStates[ nColIx ].Select( bSel );
     384                 :          0 :         AccSendRemoveColumnEvent( nColIx + 1, nColIx + 1 );
     385                 :          0 :         AccSendTableUpdateEvent( nColIx, nColIx );
     386                 :            :     }
     387                 :          0 :     return bRet;
     388                 :            : }
     389                 :            : 
     390                 :          0 : void ScCsvGrid::ImplClearSplits()
     391                 :            : {
     392                 :          0 :     sal_uInt32 nColumns = GetColumnCount();
     393                 :          0 :     maSplits.Clear();
     394                 :          0 :     maSplits.Insert( 0 );
     395                 :          0 :     maSplits.Insert( GetPosCount() );
     396                 :          0 :     maColStates.resize( 1 );
     397                 :          0 :     InvalidateGfx();
     398                 :          0 :     AccSendRemoveColumnEvent( 1, nColumns - 1 );
     399                 :          0 : }
     400                 :            : 
     401                 :            : // columns/column types -------------------------------------------------------
     402                 :            : 
     403                 :          0 : sal_uInt32 ScCsvGrid::GetFirstVisColumn() const
     404                 :            : {
     405                 :          0 :     return GetColumnFromPos( GetFirstVisPos() );
     406                 :            : }
     407                 :            : 
     408                 :          0 : sal_uInt32 ScCsvGrid::GetLastVisColumn() const
     409                 :            : {
     410                 :          0 :     return GetColumnFromPos( Min( GetLastVisPos(), GetPosCount() ) - 1 );
     411                 :            : }
     412                 :            : 
     413                 :          0 : bool ScCsvGrid::IsValidColumn( sal_uInt32 nColIndex ) const
     414                 :            : {
     415                 :          0 :     return nColIndex < GetColumnCount();
     416                 :            : }
     417                 :            : 
     418                 :          0 : bool ScCsvGrid::IsVisibleColumn( sal_uInt32 nColIndex ) const
     419                 :            : {
     420                 :          0 :     return  IsValidColumn( nColIndex ) &&
     421                 :          0 :             (GetColumnPos( nColIndex ) < GetLastVisPos()) &&
     422         [ #  # ]:          0 :             (GetFirstVisPos() < GetColumnPos( nColIndex + 1 ));
           [ #  #  #  # ]
     423                 :            : }
     424                 :            : 
     425                 :          0 : sal_Int32 ScCsvGrid::GetColumnX( sal_uInt32 nColIndex ) const
     426                 :            : {
     427                 :          0 :     return GetX( GetColumnPos( nColIndex ) );
     428                 :            : }
     429                 :            : 
     430                 :          0 : sal_uInt32 ScCsvGrid::GetColumnFromX( sal_Int32 nX ) const
     431                 :            : {
     432                 :          0 :     sal_Int32 nPos = (nX - GetFirstX()) / GetCharWidth() + GetFirstVisPos();
     433                 :          0 :     return ((GetFirstVisPos() <= nPos) && (nPos <= GetLastVisPos())) ?
     434   [ #  #  #  # ]:          0 :         GetColumnFromPos( nPos ) : CSV_COLUMN_INVALID;
     435                 :            : }
     436                 :            : 
     437                 :          0 : sal_uInt32 ScCsvGrid::GetColumnFromPos( sal_Int32 nPos ) const
     438                 :            : {
     439                 :          0 :     return maSplits.UpperBound( nPos );
     440                 :            : }
     441                 :            : 
     442                 :          0 : sal_Int32 ScCsvGrid::GetColumnWidth( sal_uInt32 nColIndex ) const
     443                 :            : {
     444         [ #  # ]:          0 :     return IsValidColumn( nColIndex ) ? (GetColumnPos( nColIndex + 1 ) - GetColumnPos( nColIndex )) : 0;
     445                 :            : }
     446                 :            : 
     447                 :          0 : void ScCsvGrid::SetColumnStates( const ScCsvColStateVec& rStates )
     448                 :            : {
     449                 :          0 :     maColStates = rStates;
     450                 :          0 :     maColStates.resize( maSplits.Count() - 1 );
     451                 :          0 :     Execute( CSVCMD_EXPORTCOLUMNTYPE );
     452                 :          0 :     AccSendTableUpdateEvent( 0, GetColumnCount(), false );
     453                 :          0 :     AccSendSelectionEvent();
     454                 :          0 : }
     455                 :            : 
     456                 :          0 : sal_Int32 ScCsvGrid::GetColumnType( sal_uInt32 nColIndex ) const
     457                 :            : {
     458         [ #  # ]:          0 :     return IsValidColumn( nColIndex ) ? maColStates[ nColIndex ].mnType : CSV_TYPE_NOSELECTION;
     459                 :            : }
     460                 :            : 
     461                 :          0 : void ScCsvGrid::SetColumnType( sal_uInt32 nColIndex, sal_Int32 nColType )
     462                 :            : {
     463         [ #  # ]:          0 :     if( IsValidColumn( nColIndex ) )
     464                 :            :     {
     465                 :          0 :         maColStates[ nColIndex ].mnType = nColType;
     466                 :          0 :         AccSendTableUpdateEvent( nColIndex, nColIndex, false );
     467                 :            :     }
     468                 :          0 : }
     469                 :            : 
     470                 :          0 : sal_Int32 ScCsvGrid::GetSelColumnType() const
     471                 :            : {
     472                 :          0 :     sal_uInt32 nColIx = GetFirstSelected();
     473         [ #  # ]:          0 :     if( nColIx == CSV_COLUMN_INVALID )
     474                 :          0 :         return CSV_TYPE_NOSELECTION;
     475                 :            : 
     476                 :          0 :     sal_Int32 nType = GetColumnType( nColIx );
     477 [ #  # ][ #  # ]:          0 :     while( (nColIx != CSV_COLUMN_INVALID) && (nType != CSV_TYPE_MULTI) )
                 [ #  # ]
     478                 :            :     {
     479         [ #  # ]:          0 :         if( nType != GetColumnType( nColIx ) )
     480                 :          0 :             nType = CSV_TYPE_MULTI;
     481                 :          0 :         nColIx = GetNextSelected( nColIx );
     482                 :            :     }
     483                 :          0 :     return nType;
     484                 :            : }
     485                 :            : 
     486                 :          0 : void ScCsvGrid::SetSelColumnType( sal_Int32 nType )
     487                 :            : {
     488 [ #  # ][ #  # ]:          0 :     if( (nType != CSV_TYPE_MULTI) && (nType != CSV_TYPE_NOSELECTION) )
     489                 :            :     {
     490         [ #  # ]:          0 :         for( sal_uInt32 nColIx = GetFirstSelected(); nColIx != CSV_COLUMN_INVALID; nColIx = GetNextSelected( nColIx ) )
     491                 :          0 :             SetColumnType( nColIx, nType );
     492                 :          0 :         Repaint( true );
     493                 :          0 :         Execute( CSVCMD_EXPORTCOLUMNTYPE );
     494                 :            :     }
     495                 :          0 : }
     496                 :            : 
     497                 :          0 : void ScCsvGrid::SetTypeNames( const StringVec& rTypeNames )
     498                 :            : {
     499                 :            :     OSL_ENSURE( !rTypeNames.empty(), "ScCsvGrid::SetTypeNames - vector is empty" );
     500                 :          0 :     maTypeNames = rTypeNames;
     501                 :          0 :     Repaint( true );
     502                 :            : 
     503                 :          0 :     maPopup.Clear();
     504                 :          0 :     sal_uInt32 nCount = maTypeNames.size();
     505                 :            :     sal_uInt32 nIx;
     506                 :            :     sal_uInt16 nItemId;
     507         [ #  # ]:          0 :     for( nIx = 0, nItemId = 1; nIx < nCount; ++nIx, ++nItemId )
     508                 :          0 :         maPopup.InsertItem( nItemId, maTypeNames[ nIx ] );
     509                 :            : 
     510         [ #  # ]:          0 :     ::std::for_each( maColStates.begin(), maColStates.end(), Func_SetType( CSV_TYPE_DEFAULT ) );
     511                 :          0 : }
     512                 :            : 
     513                 :          0 : const String& ScCsvGrid::GetColumnTypeName( sal_uInt32 nColIndex ) const
     514                 :            : {
     515                 :          0 :     sal_uInt32 nTypeIx = static_cast< sal_uInt32 >( GetColumnType( nColIndex ) );
     516         [ #  # ]:          0 :     return (nTypeIx < maTypeNames.size()) ? maTypeNames[ nTypeIx ] : EMPTY_STRING;
     517                 :            : }
     518                 :            : 
     519                 :          0 : sal_uInt8 lcl_GetExtColumnType( sal_Int32 nIntType )
     520                 :            : {
     521                 :            :     static sal_uInt8 pExtTypes[] =
     522                 :            :         { SC_COL_STANDARD, SC_COL_TEXT, SC_COL_DMY, SC_COL_MDY, SC_COL_YMD, SC_COL_ENGLISH, SC_COL_SKIP };
     523                 :            :     static sal_Int32 nExtTypeCount = SAL_N_ELEMENTS(pExtTypes);
     524 [ #  # ][ #  # ]:          0 :     return pExtTypes[ ((0 <= nIntType) && (nIntType < nExtTypeCount)) ? nIntType : 0 ];
     525                 :            : }
     526                 :            : 
     527                 :          0 : void ScCsvGrid::FillColumnDataSep( ScAsciiOptions& rOptions ) const
     528                 :            : {
     529                 :          0 :     sal_uInt32 nCount = GetColumnCount();
     530         [ #  # ]:          0 :     ScCsvExpDataVec aDataVec;
     531                 :            : 
     532         [ #  # ]:          0 :     for( sal_uInt32 nColIx = 0; nColIx < nCount; ++nColIx )
     533                 :            :     {
     534 [ #  # ][ #  # ]:          0 :         if( GetColumnType( nColIx ) != CSV_TYPE_DEFAULT )
     535                 :            :             // 1-based column index
     536                 :            :             aDataVec.push_back( ScCsvExpData(
     537                 :            :                 static_cast< sal_Int32 >( nColIx + 1 ),
     538 [ #  # ][ #  # ]:          0 :                 lcl_GetExtColumnType( GetColumnType( nColIx ) ) ) );
                 [ #  # ]
     539                 :            :     }
     540         [ #  # ]:          0 :     rOptions.SetColumnInfo( aDataVec );
     541                 :          0 : }
     542                 :            : 
     543                 :          0 : void ScCsvGrid::FillColumnDataFix( ScAsciiOptions& rOptions ) const
     544                 :            : {
     545                 :          0 :     sal_uInt32 nCount = Min( GetColumnCount(), static_cast<sal_uInt32>(MAXCOLCOUNT) );
     546         [ #  # ]:          0 :     ScCsvExpDataVec aDataVec( nCount + 1 );
     547                 :            : 
     548         [ #  # ]:          0 :     for( sal_uInt32 nColIx = 0; nColIx < nCount; ++nColIx )
     549                 :            :     {
     550                 :          0 :         ScCsvExpData& rData = aDataVec[ nColIx ];
     551         [ #  # ]:          0 :         rData.mnIndex = static_cast< sal_Int32 >( GetColumnPos( nColIx ) );
     552 [ #  # ][ #  # ]:          0 :         rData.mnType = lcl_GetExtColumnType( GetColumnType( nColIx ) );
     553                 :            :     }
     554                 :          0 :     aDataVec[ nCount ].mnIndex = SAL_MAX_INT32;
     555                 :          0 :     aDataVec[ nCount ].mnType = SC_COL_SKIP;
     556         [ #  # ]:          0 :     rOptions.SetColumnInfo( aDataVec );
     557                 :          0 : }
     558                 :            : 
     559                 :          0 : void ScCsvGrid::ScrollVertRel( ScMoveMode eDir )
     560                 :            : {
     561                 :          0 :     sal_Int32 nLine = GetFirstVisLine();
     562   [ #  #  #  #  :          0 :     switch( eDir )
                #  #  # ]
     563                 :            :     {
     564                 :          0 :         case MOVE_PREV:     --nLine;                        break;
     565                 :          0 :         case MOVE_NEXT:     ++nLine;                        break;
     566                 :          0 :         case MOVE_FIRST:    nLine = 0;                      break;
     567                 :          0 :         case MOVE_LAST:     nLine = GetMaxLineOffset();     break;
     568                 :          0 :         case MOVE_PREVPAGE: nLine -= GetVisLineCount() - 2; break;
     569                 :          0 :         case MOVE_NEXTPAGE: nLine += GetVisLineCount() - 2; break;
     570                 :            :         default:
     571                 :            :         {
     572                 :            :             // added to avoid warnings
     573                 :            :         }
     574                 :            :     }
     575                 :          0 :     Execute( CSVCMD_SETLINEOFFSET, nLine );
     576                 :          0 : }
     577                 :            : 
     578                 :          0 : void ScCsvGrid::ExecutePopup( const Point& rPos )
     579                 :            : {
     580                 :          0 :     sal_uInt16 nItemId = maPopup.Execute( this, rPos );
     581         [ #  # ]:          0 :     if( nItemId )   // 0 = cancelled
     582                 :          0 :         Execute( CSVCMD_SETCOLUMNTYPE, maPopup.GetItemPos( nItemId ) );
     583                 :          0 : }
     584                 :            : 
     585                 :            : 
     586                 :            : // selection handling ---------------------------------------------------------
     587                 :            : 
     588                 :          0 : bool ScCsvGrid::IsSelected( sal_uInt32 nColIndex ) const
     589                 :            : {
     590 [ #  # ][ #  # ]:          0 :     return IsValidColumn( nColIndex ) && maColStates[ nColIndex ].IsSelected();
     591                 :            : }
     592                 :            : 
     593                 :          0 : sal_uInt32 ScCsvGrid::GetFirstSelected() const
     594                 :            : {
     595         [ #  # ]:          0 :     return IsSelected( 0 ) ? 0 : GetNextSelected( 0 );
     596                 :            : }
     597                 :            : 
     598                 :          0 : sal_uInt32 ScCsvGrid::GetNextSelected( sal_uInt32 nFromIndex ) const
     599                 :            : {
     600                 :          0 :     sal_uInt32 nColCount = GetColumnCount();
     601         [ #  # ]:          0 :     for( sal_uInt32 nColIx = nFromIndex + 1; nColIx < nColCount; ++nColIx )
     602         [ #  # ]:          0 :         if( IsSelected( nColIx ) )
     603                 :          0 :             return nColIx;
     604                 :          0 :     return CSV_COLUMN_INVALID;
     605                 :            : }
     606                 :            : 
     607                 :          0 : void ScCsvGrid::Select( sal_uInt32 nColIndex, bool bSelect )
     608                 :            : {
     609         [ #  # ]:          0 :     if( IsValidColumn( nColIndex ) )
     610                 :            :     {
     611                 :          0 :         maColStates[ nColIndex ].Select( bSelect );
     612                 :          0 :         ImplDrawColumnSelection( nColIndex );
     613                 :          0 :         Repaint();
     614                 :          0 :         Execute( CSVCMD_EXPORTCOLUMNTYPE );
     615         [ #  # ]:          0 :         if( bSelect )
     616                 :          0 :             mnRecentSelCol = nColIndex;
     617                 :          0 :         AccSendSelectionEvent();
     618                 :            :     }
     619                 :          0 : }
     620                 :            : 
     621                 :          0 : void ScCsvGrid::ToggleSelect( sal_uInt32 nColIndex )
     622                 :            : {
     623                 :          0 :     Select( nColIndex, !IsSelected( nColIndex ) );
     624                 :          0 : }
     625                 :            : 
     626                 :          0 : void ScCsvGrid::SelectRange( sal_uInt32 nColIndex1, sal_uInt32 nColIndex2, bool bSelect )
     627                 :            : {
     628         [ #  # ]:          0 :     if( nColIndex1 == CSV_COLUMN_INVALID )
     629                 :          0 :         Select( nColIndex2 );
     630         [ #  # ]:          0 :     else if( nColIndex2 == CSV_COLUMN_INVALID )
     631                 :          0 :         Select( nColIndex1 );
     632         [ #  # ]:          0 :     else if( nColIndex1 > nColIndex2 )
     633                 :            :     {
     634                 :          0 :         SelectRange( nColIndex2, nColIndex1, bSelect );
     635         [ #  # ]:          0 :         if( bSelect )
     636                 :          0 :             mnRecentSelCol = nColIndex1;
     637                 :            :     }
     638 [ #  # ][ #  # ]:          0 :     else if( IsValidColumn( nColIndex1 ) && IsValidColumn( nColIndex2 ) )
                 [ #  # ]
     639                 :            :     {
     640         [ #  # ]:          0 :         for( sal_uInt32 nColIx = nColIndex1; nColIx <= nColIndex2; ++nColIx )
     641                 :            :         {
     642                 :          0 :             maColStates[ nColIx ].Select( bSelect );
     643                 :          0 :             ImplDrawColumnSelection( nColIx );
     644                 :            :         }
     645                 :          0 :         Repaint();
     646                 :          0 :         Execute( CSVCMD_EXPORTCOLUMNTYPE );
     647         [ #  # ]:          0 :         if( bSelect )
     648                 :          0 :             mnRecentSelCol = nColIndex1;
     649                 :          0 :         AccSendSelectionEvent();
     650                 :            :     }
     651                 :          0 : }
     652                 :            : 
     653                 :          0 : void ScCsvGrid::SelectAll( bool bSelect )
     654                 :            : {
     655                 :          0 :     SelectRange( 0, GetColumnCount() - 1, bSelect );
     656                 :          0 : }
     657                 :            : 
     658                 :          0 : void ScCsvGrid::MoveCursor( sal_uInt32 nColIndex )
     659                 :            : {
     660                 :          0 :     DisableRepaint();
     661         [ #  # ]:          0 :     if( IsValidColumn( nColIndex ) )
     662                 :            :     {
     663                 :          0 :         sal_Int32 nPosBeg = GetColumnPos( nColIndex );
     664                 :          0 :         sal_Int32 nPosEnd = GetColumnPos( nColIndex + 1 );
     665                 :          0 :         sal_Int32 nMinPos = Max( nPosBeg - CSV_SCROLL_DIST, sal_Int32( 0 ) );
     666                 :          0 :         sal_Int32 nMaxPos = Min( nPosEnd - GetVisPosCount() + CSV_SCROLL_DIST + sal_Int32( 1 ), nMinPos );
     667         [ #  # ]:          0 :         if( nPosBeg - CSV_SCROLL_DIST + 1 <= GetFirstVisPos() )
     668                 :          0 :             Execute( CSVCMD_SETPOSOFFSET, nMinPos );
     669         [ #  # ]:          0 :         else if( nPosEnd + CSV_SCROLL_DIST >= GetLastVisPos() )
     670                 :          0 :             Execute( CSVCMD_SETPOSOFFSET, nMaxPos );
     671                 :            :     }
     672                 :          0 :     Execute( CSVCMD_MOVEGRIDCURSOR, GetColumnPos( nColIndex ) );
     673                 :          0 :     EnableRepaint();
     674                 :          0 : }
     675                 :            : 
     676                 :          0 : void ScCsvGrid::MoveCursorRel( ScMoveMode eDir )
     677                 :            : {
     678         [ #  # ]:          0 :     if( GetFocusColumn() != CSV_COLUMN_INVALID )
     679                 :            :     {
     680   [ #  #  #  #  :          0 :         switch( eDir )
                      # ]
     681                 :            :         {
     682                 :            :             case MOVE_FIRST:
     683                 :          0 :                 MoveCursor( 0 );
     684                 :          0 :             break;
     685                 :            :             case MOVE_LAST:
     686                 :          0 :                 MoveCursor( GetColumnCount() - 1 );
     687                 :          0 :             break;
     688                 :            :             case MOVE_PREV:
     689         [ #  # ]:          0 :                 if( GetFocusColumn() > 0 )
     690                 :          0 :                     MoveCursor( GetFocusColumn() - 1 );
     691                 :          0 :             break;
     692                 :            :             case MOVE_NEXT:
     693         [ #  # ]:          0 :                 if( GetFocusColumn() < GetColumnCount() - 1 )
     694                 :          0 :                     MoveCursor( GetFocusColumn() + 1 );
     695                 :          0 :             break;
     696                 :            :             default:
     697                 :            :             {
     698                 :            :                 // added to avoid warnings
     699                 :            :             }
     700                 :            :         }
     701                 :            :     }
     702                 :          0 : }
     703                 :            : 
     704                 :          0 : void ScCsvGrid::ImplClearSelection()
     705                 :            : {
     706         [ #  # ]:          0 :     ::std::for_each( maColStates.begin(), maColStates.end(), Func_Select( false ) );
     707                 :          0 :     ImplDrawGridDev();
     708                 :          0 : }
     709                 :            : 
     710                 :          0 : void ScCsvGrid::DoSelectAction( sal_uInt32 nColIndex, sal_uInt16 nModifier )
     711                 :            : {
     712         [ #  # ]:          0 :     if( !(nModifier & KEY_MOD1) )
     713                 :          0 :         ImplClearSelection();
     714         [ #  # ]:          0 :     if( nModifier & KEY_SHIFT )             // SHIFT always expands
     715                 :          0 :         SelectRange( mnRecentSelCol, nColIndex );
     716         [ #  # ]:          0 :     else if( !(nModifier & KEY_MOD1) )      // no SHIFT/CTRL always selects 1 column
     717                 :          0 :         Select( nColIndex );
     718         [ #  # ]:          0 :     else if( IsTracking() )                 // CTRL in tracking does not toggle
     719                 :          0 :         Select( nColIndex, mbMTSelecting );
     720                 :            :     else                                    // CTRL only toggles
     721                 :          0 :         ToggleSelect( nColIndex );
     722                 :          0 :     Execute( CSVCMD_MOVEGRIDCURSOR, GetColumnPos( nColIndex ) );
     723                 :          0 : }
     724                 :            : 
     725                 :            : 
     726                 :            : // cell contents --------------------------------------------------------------
     727                 :            : 
     728                 :          0 : void ScCsvGrid::ImplSetTextLineSep(
     729                 :            :         sal_Int32 nLine, const rtl::OUString& rTextLine,
     730                 :            :         const String& rSepChars, sal_Unicode cTextSep, bool bMergeSep )
     731                 :            : {
     732         [ #  # ]:          0 :     if( nLine < GetFirstVisLine() ) return;
     733                 :            : 
     734                 :          0 :     sal_uInt32 nLineIx = nLine - GetFirstVisLine();
     735         [ #  # ]:          0 :     while( maTexts.size() <= nLineIx )
     736 [ #  # ][ #  # ]:          0 :         maTexts.push_back( StringVec() );
     737         [ #  # ]:          0 :     StringVec& rStrVec = maTexts[ nLineIx ];
     738                 :          0 :     rStrVec.clear();
     739                 :            : 
     740                 :            :     // scan for separators
     741         [ #  # ]:          0 :     String aCellText;
     742                 :          0 :     const sal_Unicode* pSepChars = rSepChars.GetBuffer();
     743                 :          0 :     const sal_Unicode* pChar = rTextLine.getStr();
     744                 :          0 :     sal_uInt32 nColIx = 0;
     745                 :            : 
     746 [ #  # ][ #  # ]:          0 :     while( *pChar && (nColIx < sal::static_int_cast<sal_uInt32>(CSV_MAXCOLCOUNT)) )
                 [ #  # ]
     747                 :            :     {
     748                 :            :         // scan for next cell text
     749                 :          0 :         bool bIsQuoted = false;
     750                 :          0 :         bool bOverflowCell = false;
     751                 :            :         pChar = ScImportExport::ScanNextFieldFromString( pChar, aCellText,
     752         [ #  # ]:          0 :                 cTextSep, pSepChars, bMergeSep, bIsQuoted, bOverflowCell );
     753                 :            :         /* TODO: signal overflow somewhere in UI */
     754                 :            : 
     755                 :            :         // update column width
     756                 :          0 :         sal_Int32 nWidth = Max( CSV_MINCOLWIDTH, aCellText.Len() + sal_Int32( 1 ) );
     757 [ #  # ][ #  # ]:          0 :         if( IsValidColumn( nColIx ) )
     758                 :            :         {
     759                 :            :             // expand existing column
     760         [ #  # ]:          0 :             sal_Int32 nDiff = nWidth - GetColumnWidth( nColIx );
     761         [ #  # ]:          0 :             if( nDiff > 0 )
     762                 :            :             {
     763         [ #  # ]:          0 :                 Execute( CSVCMD_SETPOSCOUNT, GetPosCount() + nDiff );
     764         [ #  # ]:          0 :                 for( sal_uInt32 nSplitIx = GetColumnCount() - 1; nSplitIx > nColIx; --nSplitIx )
     765                 :            :                 {
     766         [ #  # ]:          0 :                     sal_Int32 nPos = maSplits[ nSplitIx ];
     767         [ #  # ]:          0 :                     maSplits.Remove( nPos );
     768         [ #  # ]:          0 :                     maSplits.Insert( nPos + nDiff );
     769                 :            :                 }
     770                 :            :             }
     771                 :            :         }
     772                 :            :         else
     773                 :            :         {
     774                 :            :             // append new column
     775                 :          0 :             sal_Int32 nLastPos = GetPosCount();
     776         [ #  # ]:          0 :             Execute( CSVCMD_SETPOSCOUNT, nLastPos + nWidth );
     777         [ #  # ]:          0 :             ImplInsertSplit( nLastPos );
     778                 :            :         }
     779                 :            : 
     780         [ #  # ]:          0 :         if( aCellText.Len() <= CSV_MAXSTRLEN )
     781         [ #  # ]:          0 :             rStrVec.push_back( aCellText );
     782                 :            :         else
     783 [ #  # ][ #  # ]:          0 :             rStrVec.push_back( aCellText.Copy( 0, CSV_MAXSTRLEN ) );
                 [ #  # ]
     784                 :          0 :         ++nColIx;
     785                 :            :     }
     786         [ #  # ]:          0 :     InvalidateGfx();
     787                 :            : }
     788                 :            : 
     789                 :          0 : void ScCsvGrid::ImplSetTextLineFix( sal_Int32 nLine, const rtl::OUString& rTextLine )
     790                 :            : {
     791         [ #  # ]:          0 :     if( nLine < GetFirstVisLine() ) return;
     792                 :            : 
     793                 :          0 :     sal_Int32 nChars = rTextLine.getLength();
     794         [ #  # ]:          0 :     if( nChars > GetPosCount() )
     795                 :          0 :         Execute( CSVCMD_SETPOSCOUNT, nChars );
     796                 :            : 
     797                 :          0 :     sal_uInt32 nLineIx = nLine - GetFirstVisLine();
     798         [ #  # ]:          0 :     while( maTexts.size() <= nLineIx )
     799         [ #  # ]:          0 :         maTexts.push_back( StringVec() );
     800                 :            : 
     801                 :          0 :     StringVec& rStrVec = maTexts[ nLineIx ];
     802                 :          0 :     rStrVec.clear();
     803                 :          0 :     sal_uInt32 nColCount = GetColumnCount();
     804                 :          0 :     sal_Int32 nStrLen = rTextLine.getLength();
     805                 :          0 :     sal_Int32 nStrIx = 0;
     806 [ #  # ][ #  # ]:          0 :     for( sal_uInt32 nColIx = 0; (nColIx < nColCount) && (nStrIx < nStrLen); ++nColIx )
                 [ #  # ]
     807                 :            :     {
     808         [ #  # ]:          0 :         sal_Int32 nColWidth = GetColumnWidth( nColIx );
     809 [ #  # ][ #  # ]:          0 :         sal_Int32 nLen = std::min( std::min( nColWidth, static_cast<sal_Int32>(CSV_MAXSTRLEN) ), nStrLen - nStrIx);
     810 [ #  # ][ #  # ]:          0 :         rStrVec.push_back( rTextLine.copy( nStrIx, nLen ) );
                 [ #  # ]
     811                 :          0 :         nStrIx = nStrIx + nColWidth;
     812                 :            :     }
     813                 :          0 :     InvalidateGfx();
     814                 :            : }
     815                 :            : 
     816                 :          0 : const String& ScCsvGrid::GetCellText( sal_uInt32 nColIndex, sal_Int32 nLine ) const
     817                 :            : {
     818         [ #  # ]:          0 :     if( nLine < GetFirstVisLine() ) return EMPTY_STRING;
     819                 :            : 
     820                 :          0 :     sal_uInt32 nLineIx = nLine - GetFirstVisLine();
     821         [ #  # ]:          0 :     if( nLineIx >= maTexts.size() ) return EMPTY_STRING;
     822                 :            : 
     823                 :          0 :     const StringVec& rStrVec = maTexts[ nLineIx ];
     824         [ #  # ]:          0 :     if( nColIndex >= rStrVec.size() ) return EMPTY_STRING;
     825                 :            : 
     826                 :          0 :     return rStrVec[ nColIndex ];
     827                 :            : }
     828                 :            : 
     829                 :            : 
     830                 :            : // event handling -------------------------------------------------------------
     831                 :            : 
     832                 :          0 : void ScCsvGrid::Resize()
     833                 :            : {
     834                 :          0 :     ScCsvControl::Resize();
     835                 :          0 :     InitSizeData();
     836                 :          0 :     Execute( CSVCMD_UPDATECELLTEXTS );
     837                 :          0 : }
     838                 :            : 
     839                 :          0 : void ScCsvGrid::GetFocus()
     840                 :            : {
     841                 :          0 :     ScCsvControl::GetFocus();
     842                 :          0 :     Execute( CSVCMD_MOVEGRIDCURSOR, GetNoScrollCol( GetGridCursorPos() ) );
     843                 :          0 :     Repaint();
     844                 :          0 : }
     845                 :            : 
     846                 :          0 : void ScCsvGrid::LoseFocus()
     847                 :            : {
     848                 :          0 :     ScCsvControl::LoseFocus();
     849                 :          0 :     Repaint();
     850                 :          0 : }
     851                 :            : 
     852                 :          0 : void ScCsvGrid::MouseButtonDown( const MouseEvent& rMEvt )
     853                 :            : {
     854         [ #  # ]:          0 :     DisableRepaint();
     855 [ #  # ][ #  # ]:          0 :     if( !HasFocus() )
     856         [ #  # ]:          0 :         GrabFocus();
     857                 :            : 
     858                 :          0 :     Point aPos( rMEvt.GetPosPixel() );
     859         [ #  # ]:          0 :     sal_uInt32 nColIx = GetColumnFromX( aPos.X() );
     860                 :            : 
     861         [ #  # ]:          0 :     if( rMEvt.IsLeft() )
     862                 :            :     {
     863 [ #  # ][ #  # ]:          0 :         if( (GetFirstX() > aPos.X()) || (aPos.X() > GetLastX()) )   // in header column
         [ #  # ][ #  # ]
                 [ #  # ]
     864                 :            :         {
     865         [ #  # ]:          0 :             if( aPos.Y() <= GetHdrHeight() )
     866         [ #  # ]:          0 :                 SelectAll();
     867                 :            :         }
     868 [ #  # ][ #  # ]:          0 :         else if( IsValidColumn( nColIx ) )
     869                 :            :         {
     870         [ #  # ]:          0 :             DoSelectAction( nColIx, rMEvt.GetModifier() );
     871                 :          0 :             mnMTCurrCol = nColIx;
     872         [ #  # ]:          0 :             mbMTSelecting = IsSelected( nColIx );
     873         [ #  # ]:          0 :             StartTracking( STARTTRACK_BUTTONREPEAT );
     874                 :            :         }
     875                 :            :     }
     876         [ #  # ]:          0 :     EnableRepaint();
     877                 :          0 : }
     878                 :            : 
     879                 :          0 : void ScCsvGrid::Tracking( const TrackingEvent& rTEvt )
     880                 :            : {
     881 [ #  # ][ #  # ]:          0 :     if( rTEvt.IsTrackingEnded() || rTEvt.IsTrackingRepeat() )
                 [ #  # ]
     882                 :            :     {
     883                 :          0 :         DisableRepaint();
     884                 :          0 :         const MouseEvent& rMEvt = rTEvt.GetMouseEvent();
     885                 :            : 
     886                 :          0 :         sal_Int32 nPos = (rMEvt.GetPosPixel().X() - GetFirstX()) / GetCharWidth() + GetFirstVisPos();
     887                 :            :         // on mouse tracking: keep position valid
     888                 :          0 :         nPos = Max( Min( nPos, GetPosCount() - sal_Int32( 1 ) ), sal_Int32( 0 ) );
     889                 :          0 :         Execute( CSVCMD_MAKEPOSVISIBLE, nPos );
     890                 :            : 
     891                 :          0 :         sal_uInt32 nColIx = GetColumnFromPos( nPos );
     892         [ #  # ]:          0 :         if( mnMTCurrCol != nColIx )
     893                 :            :         {
     894                 :          0 :             DoSelectAction( nColIx, rMEvt.GetModifier() );
     895                 :          0 :             mnMTCurrCol = nColIx;
     896                 :            :         }
     897                 :          0 :         EnableRepaint();
     898                 :            :     }
     899                 :          0 : }
     900                 :            : 
     901                 :          0 : void ScCsvGrid::KeyInput( const KeyEvent& rKEvt )
     902                 :            : {
     903                 :          0 :     const KeyCode& rKCode = rKEvt.GetKeyCode();
     904                 :          0 :     sal_uInt16 nCode = rKCode.GetCode();
     905                 :          0 :     bool bShift = rKCode.IsShift() == sal_True;
     906                 :          0 :     bool bMod1 = rKCode.IsMod1() == sal_True;
     907                 :            : 
     908         [ #  # ]:          0 :     if( !rKCode.IsMod2() )
     909                 :            :     {
     910                 :          0 :         ScMoveMode eHDir = GetHorzDirection( nCode, !bMod1 );
     911                 :          0 :         ScMoveMode eVDir = GetVertDirection( nCode, bMod1 );
     912                 :            : 
     913         [ #  # ]:          0 :         if( eHDir != MOVE_NONE )
     914                 :            :         {
     915                 :          0 :             DisableRepaint();
     916                 :          0 :             MoveCursorRel( eHDir );
     917         [ #  # ]:          0 :             if( !bMod1 )
     918                 :          0 :                 ImplClearSelection();
     919         [ #  # ]:          0 :             if( bShift )
     920                 :          0 :                 SelectRange( mnRecentSelCol, GetFocusColumn() );
     921         [ #  # ]:          0 :             else if( !bMod1 )
     922                 :          0 :                 Select( GetFocusColumn() );
     923                 :          0 :             EnableRepaint();
     924                 :            :         }
     925         [ #  # ]:          0 :         else if( eVDir != MOVE_NONE )
     926                 :          0 :             ScrollVertRel( eVDir );
     927         [ #  # ]:          0 :         else if( nCode == KEY_SPACE )
     928                 :            :         {
     929         [ #  # ]:          0 :             if( !bMod1 )
     930                 :          0 :                 ImplClearSelection();
     931         [ #  # ]:          0 :             if( bShift )
     932                 :          0 :                 SelectRange( mnRecentSelCol, GetFocusColumn() );
     933         [ #  # ]:          0 :             else if( bMod1 )
     934                 :          0 :                 ToggleSelect( GetFocusColumn() );
     935                 :            :             else
     936                 :          0 :                 Select( GetFocusColumn() );
     937                 :            :         }
     938 [ #  # ][ #  # ]:          0 :         else if( !bShift && bMod1 )
     939                 :            :         {
     940         [ #  # ]:          0 :             if( nCode == KEY_A )
     941                 :          0 :                 SelectAll();
     942 [ #  # ][ #  # ]:          0 :             else if( (KEY_1 <= nCode) && (nCode <= KEY_9) )
     943                 :            :             {
     944                 :          0 :                 sal_uInt32 nType = nCode - KEY_1;
     945         [ #  # ]:          0 :                 if( nType < maTypeNames.size() )
     946                 :          0 :                     Execute( CSVCMD_SETCOLUMNTYPE, nType );
     947                 :            :             }
     948                 :            :         }
     949                 :            :     }
     950                 :            : 
     951         [ #  # ]:          0 :     if( rKCode.GetGroup() != KEYGROUP_CURSOR )
     952                 :          0 :         ScCsvControl::KeyInput( rKEvt );
     953                 :          0 : }
     954                 :            : 
     955                 :          0 : void ScCsvGrid::Command( const CommandEvent& rCEvt )
     956                 :            : {
     957      [ #  #  # ]:          0 :     switch( rCEvt.GetCommand() )
     958                 :            :     {
     959                 :            :         case COMMAND_CONTEXTMENU:
     960                 :            :         {
     961         [ #  # ]:          0 :             if( rCEvt.IsMouseEvent() )
     962                 :            :             {
     963                 :          0 :                 Point aPos( rCEvt.GetMousePosPixel() );
     964         [ #  # ]:          0 :                 sal_uInt32 nColIx = GetColumnFromX( aPos.X() );
     965 [ #  # ][ #  # ]:          0 :                 if( IsValidColumn( nColIx ) && (GetFirstX() <= aPos.X()) && (aPos.X() <= GetLastX()) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     966                 :            :                 {
     967 [ #  # ][ #  # ]:          0 :                     if( !IsSelected( nColIx ) )
     968         [ #  # ]:          0 :                         DoSelectAction( nColIx, 0 );    // focus & select
     969         [ #  # ]:          0 :                     ExecutePopup( aPos );
     970                 :            :                 }
     971                 :            :             }
     972                 :            :             else
     973                 :            :             {
     974                 :          0 :                 sal_uInt32 nColIx = GetFocusColumn();
     975         [ #  # ]:          0 :                 if( !IsSelected( nColIx ) )
     976                 :          0 :                     Select( nColIx );
     977                 :          0 :                 sal_Int32 nX1 = Max( GetColumnX( nColIx ), GetFirstX() );
     978                 :          0 :                 sal_Int32 nX2 = Min( GetColumnX( nColIx + 1 ), GetWidth() );
     979         [ #  # ]:          0 :                 ExecutePopup( Point( (nX1 + nX2) / 2, GetHeight() / 2 ) );
     980                 :            :             }
     981                 :            :         }
     982                 :          0 :         break;
     983                 :            :         case COMMAND_WHEEL:
     984                 :            :         {
     985                 :          0 :             Point aPoint;
     986         [ #  # ]:          0 :             Rectangle aRect( aPoint, maWinSize );
     987 [ #  # ][ #  # ]:          0 :             if( aRect.IsInside( rCEvt.GetMousePosPixel() ) )
     988                 :            :             {
     989         [ #  # ]:          0 :                 const CommandWheelData* pData = rCEvt.GetWheelData();
     990 [ #  # ][ #  # ]:          0 :                 if( pData && (pData->GetMode() == COMMAND_WHEEL_SCROLL) && !pData->IsHorz() )
         [ #  # ][ #  # ]
     991         [ #  # ]:          0 :                     Execute( CSVCMD_SETLINEOFFSET, GetFirstVisLine() - pData->GetNotchDelta() );
     992                 :            :             }
     993                 :            :         }
     994                 :          0 :         break;
     995                 :            :         default:
     996                 :          0 :             ScCsvControl::Command( rCEvt );
     997                 :            :     }
     998                 :          0 : }
     999                 :            : 
    1000                 :          0 : void ScCsvGrid::DataChanged( const DataChangedEvent& rDCEvt )
    1001                 :            : {
    1002 [ #  # ][ #  # ]:          0 :     if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
                 [ #  # ]
    1003                 :            :     {
    1004                 :          0 :         InitColors();
    1005                 :          0 :         InitFonts();
    1006                 :          0 :         UpdateLayoutData();
    1007                 :          0 :         Execute( CSVCMD_UPDATECELLTEXTS );
    1008                 :            :     }
    1009                 :          0 :     ScCsvControl::DataChanged( rDCEvt );
    1010                 :          0 : }
    1011                 :            : 
    1012                 :          0 : void ScCsvGrid::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 )
    1013                 :            : {
    1014                 :          0 :     InitColors();
    1015                 :          0 :     Repaint();
    1016                 :          0 : }
    1017                 :            : 
    1018                 :            : 
    1019                 :            : // painting -------------------------------------------------------------------
    1020                 :            : 
    1021                 :          0 : void ScCsvGrid::Paint( const Rectangle& )
    1022                 :            : {
    1023                 :          0 :     Repaint();
    1024                 :          0 : }
    1025                 :            : 
    1026                 :          0 : void ScCsvGrid::ImplRedraw()
    1027                 :            : {
    1028         [ #  # ]:          0 :     if( IsVisible() )
    1029                 :            :     {
    1030         [ #  # ]:          0 :         if( !IsValidGfx() )
    1031                 :            :         {
    1032                 :          0 :             ValidateGfx();
    1033                 :          0 :             ImplDrawBackgrDev();
    1034                 :          0 :             ImplDrawGridDev();
    1035                 :            :         }
    1036         [ #  # ]:          0 :         DrawOutDev( Point(), maWinSize, Point(), maWinSize, maGridDev );
    1037                 :          0 :         ImplDrawTrackingRect( GetFocusColumn() );
    1038                 :            :     }
    1039                 :          0 : }
    1040                 :            : 
    1041                 :          0 : EditEngine* ScCsvGrid::GetEditEngine()
    1042                 :            : {
    1043         [ #  # ]:          0 :     return mpEditEngine.get();
    1044                 :            : }
    1045                 :            : 
    1046                 :          0 : void ScCsvGrid::ImplSetColumnClipRegion( OutputDevice& rOutDev, sal_uInt32 nColIndex )
    1047                 :            : {
    1048                 :            :     rOutDev.SetClipRegion( Region( Rectangle(
    1049                 :          0 :         Max( GetColumnX( nColIndex ), GetFirstX() ) + 1, 0,
    1050 [ #  # ][ #  # ]:          0 :         Min( GetColumnX( nColIndex + 1 ), GetLastX() ), GetHeight() - 1 ) ) );
                 [ #  # ]
    1051                 :          0 : }
    1052                 :            : 
    1053                 :          0 : void ScCsvGrid::ImplDrawColumnHeader( OutputDevice& rOutDev, sal_uInt32 nColIndex, Color aFillColor )
    1054                 :            : {
    1055                 :          0 :     sal_Int32 nX1 = GetColumnX( nColIndex ) + 1;
    1056                 :          0 :     sal_Int32 nX2 = GetColumnX( nColIndex + 1 );
    1057                 :          0 :     sal_Int32 nHdrHt = GetHdrHeight();
    1058                 :            : 
    1059                 :          0 :     rOutDev.SetLineColor();
    1060                 :          0 :     rOutDev.SetFillColor( aFillColor );
    1061         [ #  # ]:          0 :     rOutDev.DrawRect( Rectangle( nX1, 0, nX2, nHdrHt ) );
    1062                 :            : 
    1063                 :          0 :     rOutDev.SetFont( maHeaderFont );
    1064                 :          0 :     rOutDev.SetTextColor( maHeaderTextColor );
    1065                 :          0 :     rOutDev.SetTextFillColor();
    1066         [ #  # ]:          0 :     rOutDev.DrawText( Point( nX1 + 1, 0 ), GetColumnTypeName( nColIndex ) );
    1067                 :            : 
    1068                 :          0 :     rOutDev.SetLineColor( maHeaderGridColor );
    1069         [ #  # ]:          0 :     rOutDev.DrawLine( Point( nX1, nHdrHt ), Point( nX2, nHdrHt ) );
    1070         [ #  # ]:          0 :     rOutDev.DrawLine( Point( nX2, 0 ), Point( nX2, nHdrHt ) );
    1071                 :          0 : }
    1072                 :            : 
    1073                 :          0 : void ScCsvGrid::ImplDrawCellText( const Point& rPos, const String& rText )
    1074                 :            : {
    1075         [ #  # ]:          0 :     String aPlainText( rText );
    1076         [ #  # ]:          0 :     aPlainText.SearchAndReplaceAll( '\t', ' ' );
    1077         [ #  # ]:          0 :     aPlainText.SearchAndReplaceAll( '\n', ' ' );
    1078         [ #  # ]:          0 :     mpEditEngine->SetPaperSize( maEdEngSize );
    1079                 :            : 
    1080                 :            :     /*  #i60296# If string contains mixed script types, the space character
    1081                 :            :         U+0020 may be drawn with a wrong width (from non-fixed-width Asian or
    1082                 :            :         Complex font). Now we draw every non-space portion separately. */
    1083 [ #  # ][ #  # ]:          0 :     xub_StrLen nTokenCount = comphelper::string::getTokenCount(aPlainText, ' ');
    1084                 :          0 :     xub_StrLen nCharIx = 0;
    1085         [ #  # ]:          0 :     for( xub_StrLen nToken = 0; nToken < nTokenCount; ++nToken )
    1086                 :            :     {
    1087                 :          0 :         xub_StrLen nBeginIx = nCharIx;
    1088         [ #  # ]:          0 :         String aToken = aPlainText.GetToken( 0, ' ', nCharIx );
    1089         [ #  # ]:          0 :         if( aToken.Len() > 0 )
    1090                 :            :         {
    1091                 :          0 :             sal_Int32 nX = rPos.X() + GetCharWidth() * nBeginIx;
    1092         [ #  # ]:          0 :             mpEditEngine->SetText( aToken );
    1093         [ #  # ]:          0 :             mpEditEngine->Draw( &maBackgrDev, Point( nX, rPos.Y() ) );
    1094                 :            :         }
    1095         [ #  # ]:          0 :     }
    1096                 :            : 
    1097                 :          0 :     nCharIx = 0;
    1098 [ #  # ][ #  # ]:          0 :     while( (nCharIx = rText.Search( '\t', nCharIx )) != STRING_NOTFOUND )
    1099                 :            :     {
    1100                 :          0 :         sal_Int32 nX1 = rPos.X() + GetCharWidth() * nCharIx;
    1101                 :          0 :         sal_Int32 nX2 = nX1 + GetCharWidth() - 2;
    1102                 :          0 :         sal_Int32 nY = rPos.Y() + GetLineHeight() / 2;
    1103                 :          0 :         Color aColor( maTextColor );
    1104         [ #  # ]:          0 :         maBackgrDev.SetLineColor( aColor );
    1105         [ #  # ]:          0 :         maBackgrDev.DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
    1106         [ #  # ]:          0 :         maBackgrDev.DrawLine( Point( nX2 - 2, nY - 2 ), Point( nX2, nY ) );
    1107         [ #  # ]:          0 :         maBackgrDev.DrawLine( Point( nX2 - 2, nY + 2 ), Point( nX2, nY ) );
    1108                 :          0 :         ++nCharIx;
    1109                 :            :     }
    1110                 :          0 :     nCharIx = 0;
    1111 [ #  # ][ #  # ]:          0 :     while( (nCharIx = rText.Search( '\n', nCharIx )) != STRING_NOTFOUND )
    1112                 :            :     {
    1113                 :          0 :         sal_Int32 nX1 = rPos.X() + GetCharWidth() * nCharIx;
    1114                 :          0 :         sal_Int32 nX2 = nX1 + GetCharWidth() - 2;
    1115                 :          0 :         sal_Int32 nY = rPos.Y() + GetLineHeight() / 2;
    1116                 :          0 :         Color aColor( maTextColor );
    1117         [ #  # ]:          0 :         maBackgrDev.SetLineColor( aColor );
    1118         [ #  # ]:          0 :         maBackgrDev.DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
    1119         [ #  # ]:          0 :         maBackgrDev.DrawLine( Point( nX1 + 2, nY - 2 ), Point( nX1, nY ) );
    1120         [ #  # ]:          0 :         maBackgrDev.DrawLine( Point( nX1 + 2, nY + 2 ), Point( nX1, nY ) );
    1121         [ #  # ]:          0 :         maBackgrDev.DrawLine( Point( nX2, nY - 2 ), Point( nX2, nY ) );
    1122                 :          0 :         ++nCharIx;
    1123         [ #  # ]:          0 :     }
    1124                 :          0 : }
    1125                 :            : 
    1126                 :          0 : void ScCsvGrid::ImplDrawFirstLineSep( bool bSet )
    1127                 :            : {
    1128 [ #  # ][ #  # ]:          0 :     if( IsVisibleLine( mnFirstImpLine ) && (mnFirstImpLine != GetFirstVisLine() ) )
                 [ #  # ]
    1129                 :            :     {
    1130                 :          0 :         sal_Int32 nY = GetY( mnFirstImpLine );
    1131                 :          0 :         sal_Int32 nX = Min( GetColumnX( GetLastVisColumn() + 1 ), GetLastX() );
    1132         [ #  # ]:          0 :         maBackgrDev.SetLineColor( bSet ? maGridPBColor : maGridColor );
    1133 [ #  # ][ #  # ]:          0 :         maBackgrDev.DrawLine( Point( GetFirstX() + 1, nY ), Point( nX, nY ) );
    1134                 :            :     }
    1135                 :          0 : }
    1136                 :            : 
    1137                 :          0 : void ScCsvGrid::ImplDrawColumnBackgr( sal_uInt32 nColIndex )
    1138                 :            : {
    1139 [ #  # ][ #  # ]:          0 :     if( !IsVisibleColumn( nColIndex ) )
    1140                 :          0 :         return;
    1141                 :            : 
    1142         [ #  # ]:          0 :     ImplSetColumnClipRegion( maBackgrDev, nColIndex );
    1143                 :            : 
    1144                 :            :     // grid
    1145         [ #  # ]:          0 :     maBackgrDev.SetLineColor();
    1146         [ #  # ]:          0 :     maBackgrDev.SetFillColor( maBackColor );
    1147         [ #  # ]:          0 :     sal_Int32 nX1 = GetColumnX( nColIndex ) + 1;
    1148         [ #  # ]:          0 :     sal_Int32 nX2 = GetColumnX( nColIndex + 1 );
    1149 [ #  # ][ #  # ]:          0 :     sal_Int32 nY2 = GetY( GetLastVisLine() + 1 );
    1150                 :          0 :     sal_Int32 nHdrHt = GetHdrHeight();
    1151         [ #  # ]:          0 :     Rectangle aRect( nX1, nHdrHt, nX2, nY2 );
    1152         [ #  # ]:          0 :     maBackgrDev.DrawRect( aRect );
    1153         [ #  # ]:          0 :     maBackgrDev.SetLineColor( maGridColor );
    1154         [ #  # ]:          0 :     maBackgrDev.DrawGrid( aRect, Size( 1, GetLineHeight() ), GRID_HORZLINES );
    1155         [ #  # ]:          0 :     maBackgrDev.DrawLine( Point( nX2, nHdrHt ), Point( nX2, nY2 ) );
    1156         [ #  # ]:          0 :     ImplDrawFirstLineSep( true );
    1157                 :            : 
    1158                 :            :     // cell texts
    1159 [ #  # ][ #  # ]:          0 :     mpEditEngine->SetDefaultItem( SvxColorItem( maTextColor, EE_CHAR_COLOR ) );
                 [ #  # ]
    1160 [ #  # ][ #  # ]:          0 :     size_t nLineCount = ::std::min( static_cast< size_t >( GetLastVisLine() - GetFirstVisLine() + 1 ), maTexts.size() );
    1161                 :            :     // #i67432# cut string to avoid edit engine performance problems with very large strings
    1162 [ #  # ][ #  # ]:          0 :     sal_Int32 nFirstVisPos = ::std::max( GetColumnPos( nColIndex ), GetFirstVisPos() );
    1163 [ #  # ][ #  # ]:          0 :     sal_Int32 nLastVisPos = ::std::min( GetColumnPos( nColIndex + 1 ), GetLastVisPos() );
                 [ #  # ]
    1164         [ #  # ]:          0 :     xub_StrLen nStrPos = static_cast< xub_StrLen >( nFirstVisPos - GetColumnPos( nColIndex ) );
    1165                 :          0 :     xub_StrLen nStrLen = static_cast< xub_StrLen >( nLastVisPos - nFirstVisPos + 1 );
    1166         [ #  # ]:          0 :     sal_Int32 nStrX = GetX( nFirstVisPos );
    1167         [ #  # ]:          0 :     for( size_t nLine = 0; nLine < nLineCount; ++nLine )
    1168                 :            :     {
    1169         [ #  # ]:          0 :         StringVec& rStrVec = maTexts[ nLine ];
    1170 [ #  # ][ #  # ]:          0 :         if( (nColIndex < rStrVec.size()) && (rStrVec[ nColIndex ].Len() > nStrPos) )
         [ #  # ][ #  # ]
    1171                 :            :         {
    1172 [ #  # ][ #  # ]:          0 :             String aText( rStrVec[ nColIndex ], nStrPos, nStrLen );
    1173 [ #  # ][ #  # ]:          0 :             ImplDrawCellText( Point( nStrX, GetY( GetFirstVisLine() + nLine ) ), aText );
                 [ #  # ]
    1174                 :            :         }
    1175                 :            :     }
    1176                 :            : 
    1177                 :            :     // header
    1178         [ #  # ]:          0 :     ImplDrawColumnHeader( maBackgrDev, nColIndex, maHeaderBackColor );
    1179                 :            : 
    1180         [ #  # ]:          0 :     maBackgrDev.SetClipRegion();
    1181                 :            : }
    1182                 :            : 
    1183                 :          0 : void ScCsvGrid::ImplDrawRowHeaders()
    1184                 :            : {
    1185         [ #  # ]:          0 :     maBackgrDev.SetLineColor();
    1186         [ #  # ]:          0 :     maBackgrDev.SetFillColor( maAppBackColor );
    1187         [ #  # ]:          0 :     Point aPoint( GetHdrX(), 0 );
    1188         [ #  # ]:          0 :     Rectangle aRect( aPoint, Size( GetHdrWidth() + 1, GetHeight() ) );
    1189         [ #  # ]:          0 :     maBackgrDev.DrawRect( aRect );
    1190                 :            : 
    1191         [ #  # ]:          0 :     maBackgrDev.SetFillColor( maHeaderBackColor );
    1192 [ #  # ][ #  # ]:          0 :     aRect.Bottom() = GetY( GetLastVisLine() + 1 );
    1193         [ #  # ]:          0 :     maBackgrDev.DrawRect( aRect );
    1194                 :            : 
    1195                 :            :     // line numbers
    1196         [ #  # ]:          0 :     maBackgrDev.SetFont( maHeaderFont );
    1197         [ #  # ]:          0 :     maBackgrDev.SetTextColor( maHeaderTextColor );
    1198         [ #  # ]:          0 :     maBackgrDev.SetTextFillColor();
    1199         [ #  # ]:          0 :     sal_Int32 nLastLine = GetLastVisLine();
    1200         [ #  # ]:          0 :     for( sal_Int32 nLine = GetFirstVisLine(); nLine <= nLastLine; ++nLine )
    1201                 :            :     {
    1202         [ #  # ]:          0 :         String aText( String::CreateFromInt32( nLine + 1 ) );
    1203 [ #  # ][ #  # ]:          0 :         sal_Int32 nX = GetHdrX() + (GetHdrWidth() - maBackgrDev.GetTextWidth( aText )) / 2;
    1204 [ #  # ][ #  # ]:          0 :         maBackgrDev.DrawText( Point( nX, GetY( nLine ) ), aText );
    1205         [ #  # ]:          0 :     }
    1206                 :            : 
    1207                 :            :     // grid
    1208         [ #  # ]:          0 :     maBackgrDev.SetLineColor( maHeaderGridColor );
    1209         [ #  # ]:          0 :     if( IsRTL() )
    1210                 :            :     {
    1211         [ #  # ]:          0 :         maBackgrDev.DrawLine( Point( 0, 0 ), Point( 0, GetHeight() - 1 ) );
    1212 [ #  # ][ #  # ]:          0 :         maBackgrDev.DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
    1213                 :            :     }
    1214                 :            :     else
    1215 [ #  # ][ #  # ]:          0 :         maBackgrDev.DrawLine( aRect.TopRight(), aRect.BottomRight() );
                 [ #  # ]
    1216                 :          0 :     aRect.Top() = GetHdrHeight();
    1217         [ #  # ]:          0 :     maBackgrDev.DrawGrid( aRect, Size( 1, GetLineHeight() ), GRID_HORZLINES );
    1218                 :          0 : }
    1219                 :            : 
    1220                 :          0 : void ScCsvGrid::ImplDrawBackgrDev()
    1221                 :            : {
    1222                 :          0 :     maBackgrDev.SetLineColor();
    1223                 :          0 :     maBackgrDev.SetFillColor( maAppBackColor );
    1224                 :            :     maBackgrDev.DrawRect( Rectangle(
    1225 [ #  # ][ #  # ]:          0 :         Point( GetFirstX() + 1, 0 ), Size( GetWidth() - GetHdrWidth(), GetHeight() ) ) );
                 [ #  # ]
    1226                 :            : 
    1227                 :          0 :     sal_uInt32 nLastCol = GetLastVisColumn();
    1228         [ #  # ]:          0 :     for( sal_uInt32 nColIx = GetFirstVisColumn(); nColIx <= nLastCol; ++nColIx )
    1229                 :          0 :         ImplDrawColumnBackgr( nColIx );
    1230                 :            : 
    1231                 :          0 :     ImplDrawRowHeaders();
    1232                 :          0 : }
    1233                 :            : 
    1234                 :          0 : void ScCsvGrid::ImplDrawColumnSelection( sal_uInt32 nColIndex )
    1235                 :            : {
    1236                 :          0 :     ImplInvertCursor( GetRulerCursorPos() );
    1237                 :          0 :     ImplSetColumnClipRegion( maGridDev, nColIndex );
    1238         [ #  # ]:          0 :     maGridDev.DrawOutDev( Point(), maWinSize, Point(), maWinSize, maBackgrDev );
    1239                 :            : 
    1240         [ #  # ]:          0 :     if( IsSelected( nColIndex ) )
    1241                 :            :     {
    1242         [ #  # ]:          0 :         sal_Int32 nX1 = GetColumnX( nColIndex ) + 1;
    1243         [ #  # ]:          0 :         sal_Int32 nX2 = GetColumnX( nColIndex + 1 );
    1244                 :            : 
    1245                 :            :         // header
    1246         [ #  # ]:          0 :         Rectangle aRect( nX1, 0, nX2, GetHdrHeight() );
    1247         [ #  # ]:          0 :         maGridDev.SetLineColor();
    1248 [ #  # ][ #  # ]:          0 :         if( maHeaderBackColor.IsDark() )
    1249                 :            :             // redraw with light gray background in dark mode
    1250         [ #  # ]:          0 :             ImplDrawColumnHeader( maGridDev, nColIndex, COL_LIGHTGRAY );
    1251                 :            :         else
    1252                 :            :         {
    1253                 :            :             // use transparent active color
    1254         [ #  # ]:          0 :             maGridDev.SetFillColor( maSelectColor );
    1255 [ #  # ][ #  # ]:          0 :             maGridDev.DrawTransparent( PolyPolygon( Polygon( aRect ) ), CSV_HDR_TRANSPARENCY );
         [ #  # ][ #  # ]
                 [ #  # ]
    1256                 :            :         }
    1257                 :            : 
    1258                 :            :         // column selection
    1259 [ #  # ][ #  # ]:          0 :         aRect = Rectangle( nX1, GetHdrHeight() + 1, nX2, GetY( GetLastVisLine() + 1 ) - 1 );
                 [ #  # ]
    1260         [ #  # ]:          0 :         ImplInvertRect( maGridDev, aRect );
    1261                 :            :     }
    1262                 :            : 
    1263                 :          0 :     maGridDev.SetClipRegion();
    1264                 :          0 :     ImplInvertCursor( GetRulerCursorPos() );
    1265                 :          0 : }
    1266                 :            : 
    1267                 :          0 : void ScCsvGrid::ImplDrawGridDev()
    1268                 :            : {
    1269         [ #  # ]:          0 :     maGridDev.DrawOutDev( Point(), maWinSize, Point(), maWinSize, maBackgrDev );
    1270                 :          0 :     sal_uInt32 nLastCol = GetLastVisColumn();
    1271         [ #  # ]:          0 :     for( sal_uInt32 nColIx = GetFirstVisColumn(); nColIx <= nLastCol; ++nColIx )
    1272                 :          0 :         ImplDrawColumnSelection( nColIx );
    1273                 :          0 : }
    1274                 :            : 
    1275                 :          0 : void ScCsvGrid::ImplDrawColumn( sal_uInt32 nColIndex )
    1276                 :            : {
    1277                 :          0 :     ImplDrawColumnBackgr( nColIndex );
    1278                 :          0 :     ImplDrawColumnSelection( nColIndex );
    1279                 :          0 : }
    1280                 :            : 
    1281                 :          0 : void ScCsvGrid::ImplDrawHorzScrolled( sal_Int32 nOldPos )
    1282                 :            : {
    1283                 :          0 :     sal_Int32 nPos = GetFirstVisPos();
    1284 [ #  # ][ #  # ]:          0 :     if( !IsValidGfx() || (nPos == nOldPos) )
                 [ #  # ]
    1285                 :            :         return;
    1286 [ #  # ][ #  # ]:          0 :     if( Abs( nPos - nOldPos ) > GetVisPosCount() / 2 )
    1287                 :            :     {
    1288         [ #  # ]:          0 :         ImplDrawBackgrDev();
    1289         [ #  # ]:          0 :         ImplDrawGridDev();
    1290                 :            :         return;
    1291                 :            :     }
    1292                 :            : 
    1293                 :          0 :     Point aSrc, aDest;
    1294                 :            :     sal_uInt32 nFirstColIx, nLastColIx;
    1295         [ #  # ]:          0 :     if( nPos < nOldPos )
    1296                 :            :     {
    1297         [ #  # ]:          0 :         aSrc = Point( GetFirstX() + 1, 0 );
    1298         [ #  # ]:          0 :         aDest = Point( GetFirstX() + GetCharWidth() * (nOldPos - nPos) + 1, 0 );
    1299         [ #  # ]:          0 :         nFirstColIx = GetColumnFromPos( nPos );
    1300         [ #  # ]:          0 :         nLastColIx = GetColumnFromPos( nOldPos );
    1301                 :            :     }
    1302                 :            :     else
    1303                 :            :     {
    1304         [ #  # ]:          0 :         aSrc = Point( GetFirstX() + GetCharWidth() * (nPos - nOldPos) + 1, 0 );
    1305         [ #  # ]:          0 :         aDest = Point( GetFirstX() + 1, 0 );
    1306 [ #  # ][ #  # ]:          0 :         nFirstColIx = GetColumnFromPos( Min( nOldPos + GetVisPosCount(), GetPosCount() ) - 1 );
    1307 [ #  # ][ #  # ]:          0 :         nLastColIx = GetColumnFromPos( Min( nPos + GetVisPosCount(), GetPosCount() ) - 1 );
    1308                 :            :     }
    1309                 :            : 
    1310         [ #  # ]:          0 :     ImplInvertCursor( GetRulerCursorPos() + (nPos - nOldPos) );
    1311 [ #  # ][ #  # ]:          0 :     Rectangle aRectangle( GetFirstX(), 0, GetLastX(), GetHeight() - 1 );
                 [ #  # ]
    1312         [ #  # ]:          0 :     Region aClipReg( aRectangle );
    1313         [ #  # ]:          0 :     maBackgrDev.SetClipRegion( aClipReg );
    1314         [ #  # ]:          0 :     maBackgrDev.CopyArea( aDest, aSrc, maWinSize );
    1315         [ #  # ]:          0 :     maBackgrDev.SetClipRegion();
    1316         [ #  # ]:          0 :     maGridDev.SetClipRegion( aClipReg );
    1317         [ #  # ]:          0 :     maGridDev.CopyArea( aDest, aSrc, maWinSize );
    1318         [ #  # ]:          0 :     maGridDev.SetClipRegion();
    1319         [ #  # ]:          0 :     ImplInvertCursor( GetRulerCursorPos() );
    1320                 :            : 
    1321         [ #  # ]:          0 :     for( sal_uInt32 nColIx = nFirstColIx; nColIx <= nLastColIx; ++nColIx )
    1322         [ #  # ]:          0 :         ImplDrawColumn( nColIx );
    1323                 :            : 
    1324         [ #  # ]:          0 :     sal_Int32 nLastX = GetX( GetPosCount() ) + 1;
    1325 [ #  # ][ #  # ]:          0 :     if( nLastX <= GetLastX() )
    1326                 :            :     {
    1327 [ #  # ][ #  # ]:          0 :         Rectangle aRect( nLastX, 0, GetLastX(), GetHeight() - 1 );
    1328         [ #  # ]:          0 :         maBackgrDev.SetLineColor();
    1329         [ #  # ]:          0 :         maBackgrDev.SetFillColor( maAppBackColor );
    1330         [ #  # ]:          0 :         maBackgrDev.DrawRect( aRect );
    1331         [ #  # ]:          0 :         maGridDev.SetLineColor();
    1332         [ #  # ]:          0 :         maGridDev.SetFillColor( maAppBackColor );
    1333         [ #  # ]:          0 :         maGridDev.DrawRect( aRect );
    1334         [ #  # ]:          0 :     }
    1335                 :            : }
    1336                 :            : 
    1337                 :          0 : void ScCsvGrid::ImplInvertCursor( sal_Int32 nPos )
    1338                 :            : {
    1339         [ #  # ]:          0 :     if( IsVisibleSplitPos( nPos ) )
    1340                 :            :     {
    1341         [ #  # ]:          0 :         sal_Int32 nX = GetX( nPos ) - 1;
    1342         [ #  # ]:          0 :         Rectangle aRect( Point( nX, 0 ), Size( 3, GetHdrHeight() ) );
    1343         [ #  # ]:          0 :         ImplInvertRect( maGridDev, aRect );
    1344                 :          0 :         aRect.Top() = GetHdrHeight() + 1;
    1345 [ #  # ][ #  # ]:          0 :         aRect.Bottom() = GetY( GetLastVisLine() + 1 );
    1346         [ #  # ]:          0 :         ImplInvertRect( maGridDev, aRect );
    1347                 :            :     }
    1348                 :          0 : }
    1349                 :            : 
    1350                 :          0 : void ScCsvGrid::ImplDrawTrackingRect( sal_uInt32 nColIndex )
    1351                 :            : {
    1352 [ #  # ][ #  # ]:          0 :     if( HasFocus() && IsVisibleColumn( nColIndex ) )
                 [ #  # ]
    1353                 :            :     {
    1354                 :          0 :         sal_Int32 nX1 = Max( GetColumnX( nColIndex ), GetFirstX() ) + 1;
    1355                 :          0 :         sal_Int32 nX2 = Min( GetColumnX( nColIndex + 1 ) - sal_Int32( 1 ), GetLastX() );
    1356                 :          0 :         sal_Int32 nY2 = Min( GetY( GetLastVisLine() + 1 ), GetHeight() ) - 1;
    1357         [ #  # ]:          0 :         InvertTracking( Rectangle( nX1, 0, nX2, nY2 ), SHOWTRACK_SMALL | SHOWTRACK_WINDOW );
    1358                 :            :     }
    1359                 :          0 : }
    1360                 :            : 
    1361                 :            : 
    1362                 :            : // accessibility ==============================================================
    1363                 :            : 
    1364                 :          0 : ScAccessibleCsvControl* ScCsvGrid::ImplCreateAccessible()
    1365                 :            : {
    1366         [ #  # ]:          0 :     std::auto_ptr<ScAccessibleCsvControl> pControl(new ScAccessibleCsvGrid( *this ));
    1367         [ #  # ]:          0 :     pControl->Init();
    1368         [ #  # ]:          0 :     return pControl.release();
    1369                 :            : }
    1370                 :            : 
    1371                 :            : 
    1372                 :            : // ============================================================================
    1373                 :            : 
    1374                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10