LCOV - code coverage report
Current view: top level - sc/source/ui/dbgui - csvtablebox.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 234 0.0 %
Date: 2014-04-14 Functions: 0 23 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "csvtablebox.hxx"
      21             : #include <vcl/builder.hxx>
      22             : #include <vcl/lstbox.hxx>
      23             : #include <vcl/settings.hxx>
      24             : 
      25             : // ause
      26             : #include "editutil.hxx"
      27             : 
      28           0 : ScCsvTableBox::ScCsvTableBox( Window* pParent, WinBits nBits ) :
      29             :     ScCsvControl( pParent, maData, nBits ),
      30             :     maRuler( *this ),
      31             :     maGrid( *this ),
      32             :     maHScroll( this, WB_HORZ | WB_DRAG ),
      33             :     maVScroll( this, WB_VERT | WB_DRAG ),
      34           0 :     maScrollBox( this )
      35             : {
      36           0 :     mbFixedMode = false;
      37           0 :     mnFixedWidth = 1;
      38             : 
      39           0 :     maHScroll.EnableRTL( false ); // RTL
      40           0 :     maHScroll.SetLineSize( 1 );
      41           0 :     maVScroll.SetLineSize( 1 );
      42             : 
      43           0 :     Link aLink = LINK( this, ScCsvTableBox, CsvCmdHdl );
      44           0 :     SetCmdHdl( aLink );
      45           0 :     maRuler.SetCmdHdl( aLink );
      46           0 :     maGrid.SetCmdHdl( aLink );
      47             : 
      48           0 :     aLink = LINK( this, ScCsvTableBox, ScrollHdl );
      49           0 :     maHScroll.SetScrollHdl( aLink );
      50           0 :     maVScroll.SetScrollHdl( aLink );
      51             : 
      52           0 :     aLink = LINK( this, ScCsvTableBox, ScrollEndHdl );
      53           0 :     maHScroll.SetEndScrollHdl( aLink );
      54           0 :     maVScroll.SetEndScrollHdl( aLink );
      55             : 
      56           0 :     InitControls();
      57           0 : }
      58             : 
      59           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeScCsvTableBox(Window *pParent, VclBuilder::stringmap &)
      60             : {
      61           0 :     return new ScCsvTableBox(pParent, WB_BORDER);
      62             : }
      63             : 
      64           0 : Size ScCsvTableBox::GetOptimalSize() const
      65             : {
      66           0 :     Size aDefault(LogicToPixel(Size(243, 82), MapMode(MAP_APPFONT)));
      67           0 :     return aDefault;
      68             : }
      69             : 
      70             : // common table box handling --------------------------------------------------
      71             : 
      72           0 : void ScCsvTableBox::SetSeparatorsMode()
      73             : {
      74           0 :     if( mbFixedMode )
      75             :     {
      76             :         // rescue data for fixed width mode
      77           0 :         mnFixedWidth = GetPosCount();
      78           0 :         maFixColStates = maGrid.GetColumnStates();
      79             :         // switch to separators mode
      80           0 :         mbFixedMode = false;
      81             :         // reset and reinitialize controls
      82           0 :         DisableRepaint();
      83           0 :         Execute( CSVCMD_SETLINEOFFSET, 0 );
      84           0 :         Execute( CSVCMD_SETPOSCOUNT, 1 );
      85           0 :         Execute( CSVCMD_NEWCELLTEXTS );
      86           0 :         maGrid.SetColumnStates( maSepColStates );
      87           0 :         InitControls();
      88           0 :         EnableRepaint();
      89             :     }
      90           0 : }
      91             : 
      92           0 : void ScCsvTableBox::SetFixedWidthMode()
      93             : {
      94           0 :     if( !mbFixedMode )
      95             :     {
      96             :         // rescue data for separators mode
      97           0 :         maSepColStates = maGrid.GetColumnStates();
      98             :         // switch to fixed width mode
      99           0 :         mbFixedMode = true;
     100             :         // reset and reinitialize controls
     101           0 :         DisableRepaint();
     102           0 :         Execute( CSVCMD_SETLINEOFFSET, 0 );
     103           0 :         Execute( CSVCMD_SETPOSCOUNT, mnFixedWidth );
     104           0 :         maGrid.SetSplits( maRuler.GetSplits() );
     105           0 :         maGrid.SetColumnStates( maFixColStates );
     106           0 :         InitControls();
     107           0 :         EnableRepaint();
     108             :     }
     109           0 : }
     110             : 
     111           0 : void ScCsvTableBox::Init()
     112             : {
     113           0 :     maGrid.Init();
     114           0 : }
     115             : 
     116           0 : void ScCsvTableBox::InitControls()
     117             : {
     118           0 :     maGrid.UpdateLayoutData();
     119             : 
     120           0 :     long nScrollBarSize = GetSettings().GetStyleSettings().GetScrollBarSize();
     121           0 :     Size aWinSize = CalcOutputSize( GetSizePixel() );
     122           0 :     long nDataWidth = aWinSize.Width() - nScrollBarSize;
     123           0 :     long nDataHeight = aWinSize.Height() - nScrollBarSize;
     124             : 
     125           0 :     maData.mnWinWidth = nDataWidth;
     126           0 :     maData.mnWinHeight = nDataHeight;
     127             : 
     128           0 :     if( mbFixedMode )
     129             :     {
     130             :         // ruler sets height internally
     131           0 :         maRuler.setPosSizePixel( 0, 0, nDataWidth, 0 );
     132           0 :         sal_Int32 nY = maRuler.GetSizePixel().Height();
     133           0 :         maData.mnWinHeight -= nY;
     134           0 :         maGrid.setPosSizePixel( 0, nY, nDataWidth, maData.mnWinHeight );
     135             :     }
     136             :     else
     137           0 :         maGrid.setPosSizePixel( 0, 0, nDataWidth, nDataHeight );
     138           0 :     maGrid.Show();
     139           0 :     maRuler.Show( mbFixedMode );
     140             : 
     141             :     // scrollbars always visible
     142           0 :     maHScroll.setPosSizePixel( 0, nDataHeight, nDataWidth, nScrollBarSize );
     143           0 :     InitHScrollBar();
     144           0 :     maHScroll.Show();
     145             : 
     146             :     // scrollbars always visible
     147           0 :     maVScroll.setPosSizePixel( nDataWidth, 0, nScrollBarSize, nDataHeight );
     148           0 :     InitVScrollBar();
     149           0 :     maVScroll.Show();
     150             : 
     151           0 :     bool bScrBox = maHScroll.IsVisible() && maVScroll.IsVisible();
     152           0 :     if( bScrBox )
     153           0 :         maScrollBox.setPosSizePixel( nDataWidth, nDataHeight, nScrollBarSize, nScrollBarSize );
     154           0 :     maScrollBox.Show( bScrBox );
     155             : 
     156             :     // let the controls self-adjust to visible area
     157           0 :     Execute( CSVCMD_SETPOSOFFSET, GetFirstVisPos() );
     158           0 :     Execute( CSVCMD_SETLINEOFFSET, GetFirstVisLine() );
     159           0 : }
     160             : 
     161           0 : void ScCsvTableBox::InitHScrollBar()
     162             : {
     163           0 :     maHScroll.SetRange( Range( 0, GetPosCount() + 2 ) );
     164           0 :     maHScroll.SetVisibleSize( GetVisPosCount() );
     165           0 :     maHScroll.SetPageSize( GetVisPosCount() * 3 / 4 );
     166           0 :     maHScroll.SetThumbPos( GetFirstVisPos() );
     167           0 : }
     168             : 
     169           0 : void ScCsvTableBox::InitVScrollBar()
     170             : {
     171           0 :     maVScroll.SetRange( Range( 0, GetLineCount() + 1 ) );
     172           0 :     maVScroll.SetVisibleSize( GetVisLineCount() );
     173           0 :     maVScroll.SetPageSize( GetVisLineCount() - 2 );
     174           0 :     maVScroll.SetThumbPos( GetFirstVisLine() );
     175           0 : }
     176             : 
     177           0 : void ScCsvTableBox::MakePosVisible( sal_Int32 nPos )
     178             : {
     179           0 :     if( (0 <= nPos) && (nPos < GetPosCount()) )
     180             :     {
     181           0 :         if( nPos - CSV_SCROLL_DIST + 1 <= GetFirstVisPos() )
     182           0 :             Execute( CSVCMD_SETPOSOFFSET, nPos - CSV_SCROLL_DIST );
     183           0 :         else if( nPos + CSV_SCROLL_DIST >= GetLastVisPos() )
     184           0 :             Execute( CSVCMD_SETPOSOFFSET, nPos - GetVisPosCount() + CSV_SCROLL_DIST );
     185             :     }
     186           0 : }
     187             : 
     188             : 
     189             : // cell contents --------------------------------------------------------------
     190             : 
     191           0 : void ScCsvTableBox::SetUniStrings(
     192             :         const OUString* pTextLines, const OUString& rSepChars,
     193             :         sal_Unicode cTextSep, bool bMergeSep )
     194             : {
     195             :     // assuming that pTextLines is a string array with size CSV_PREVIEW_LINES
     196             :     // -> will be dynamic sometime
     197           0 :     DisableRepaint();
     198           0 :     sal_Int32 nEndLine = GetFirstVisLine() + CSV_PREVIEW_LINES;
     199           0 :     const OUString* pString = pTextLines;
     200           0 :     for( sal_Int32 nLine = GetFirstVisLine(); nLine < nEndLine; ++nLine, ++pString )
     201             :     {
     202           0 :         if( mbFixedMode )
     203           0 :             maGrid.ImplSetTextLineFix( nLine, *pString );
     204             :         else
     205           0 :             maGrid.ImplSetTextLineSep( nLine, *pString, rSepChars, cTextSep, bMergeSep );
     206             :     }
     207           0 :     EnableRepaint();
     208           0 : }
     209             : 
     210             : 
     211             : // column settings ------------------------------------------------------------
     212             : 
     213           0 : void ScCsvTableBox::InitTypes( const ListBox& rListBox )
     214             : {
     215           0 :     sal_uInt16 nTypeCount = rListBox.GetEntryCount();
     216           0 :     StringVec aTypeNames( nTypeCount );
     217           0 :     for( sal_uInt16 nIndex = 0; nIndex < nTypeCount; ++nIndex )
     218           0 :         aTypeNames[ nIndex ] = rListBox.GetEntry( nIndex );
     219           0 :     maGrid.SetTypeNames( aTypeNames );
     220           0 : }
     221             : 
     222           0 : void ScCsvTableBox::FillColumnData( ScAsciiOptions& rOptions ) const
     223             : {
     224           0 :     if( mbFixedMode )
     225           0 :         maGrid.FillColumnDataFix( rOptions );
     226             :     else
     227           0 :         maGrid.FillColumnDataSep( rOptions );
     228           0 : }
     229             : 
     230             : 
     231             : // event handling -------------------------------------------------------------
     232             : 
     233           0 : void ScCsvTableBox::Resize()
     234             : {
     235           0 :     ScCsvControl::Resize();
     236           0 :     InitControls();
     237           0 : }
     238             : 
     239           0 : void ScCsvTableBox::DataChanged( const DataChangedEvent& rDCEvt )
     240             : {
     241           0 :     if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     242           0 :         InitControls();
     243           0 :     ScCsvControl::DataChanged( rDCEvt );
     244           0 : }
     245             : 
     246           0 : IMPL_LINK( ScCsvTableBox, CsvCmdHdl, ScCsvControl*, pCtrl )
     247             : {
     248             :     OSL_ENSURE( pCtrl, "ScCsvTableBox::CsvCmdHdl - missing sender" );
     249             : 
     250           0 :     const ScCsvCmd& rCmd = pCtrl->GetCmd();
     251           0 :     ScCsvCmdType eType = rCmd.GetType();
     252           0 :     sal_Int32 nParam1 = rCmd.GetParam1();
     253           0 :     sal_Int32 nParam2 = rCmd.GetParam2();
     254             : 
     255           0 :     bool bFound = true;
     256           0 :     switch( eType )
     257             :     {
     258             :         case CSVCMD_REPAINT:
     259           0 :             if( !IsNoRepaint() )
     260             :             {
     261           0 :                 maGrid.ImplRedraw();
     262           0 :                 maRuler.ImplRedraw();
     263           0 :                 InitHScrollBar();
     264           0 :                 InitVScrollBar();
     265             :             }
     266           0 :         break;
     267             :         case CSVCMD_MAKEPOSVISIBLE:
     268           0 :             MakePosVisible( nParam1 );
     269           0 :         break;
     270             : 
     271             :         case CSVCMD_NEWCELLTEXTS:
     272           0 :             if( mbFixedMode )
     273           0 :                 Execute( CSVCMD_UPDATECELLTEXTS );
     274             :             else
     275             :             {
     276           0 :                 DisableRepaint();
     277           0 :                 ScCsvColStateVec aStates( maGrid.GetColumnStates() );
     278           0 :                 sal_Int32 nPos = GetFirstVisPos();
     279           0 :                 Execute( CSVCMD_SETPOSCOUNT, 1 );
     280           0 :                 Execute( CSVCMD_UPDATECELLTEXTS );
     281           0 :                 Execute( CSVCMD_SETPOSOFFSET, nPos );
     282           0 :                 maGrid.SetColumnStates( aStates );
     283           0 :                 EnableRepaint();
     284             :             }
     285           0 :         break;
     286             :         case CSVCMD_UPDATECELLTEXTS:
     287           0 :             maUpdateTextHdl.Call( this );
     288           0 :         break;
     289             :         case CSVCMD_SETCOLUMNTYPE:
     290           0 :             maGrid.SetSelColumnType( nParam1 );
     291           0 :         break;
     292             :         case CSVCMD_EXPORTCOLUMNTYPE:
     293           0 :             maColTypeHdl.Call( this );
     294           0 :         break;
     295             :         case CSVCMD_SETFIRSTIMPORTLINE:
     296           0 :             maGrid.SetFirstImportedLine( nParam1 );
     297           0 :         break;
     298             : 
     299             :         case CSVCMD_INSERTSPLIT:
     300             :             OSL_ENSURE( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::InsertSplit - invalid call" );
     301           0 :             if( maRuler.GetSplitCount() + 1 < sal::static_int_cast<sal_uInt32>(CSV_MAXCOLCOUNT) )
     302             :             {
     303           0 :                 maRuler.InsertSplit( nParam1 );
     304           0 :                 maGrid.InsertSplit( nParam1 );
     305             :             }
     306           0 :         break;
     307             :         case CSVCMD_REMOVESPLIT:
     308             :             OSL_ENSURE( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::RemoveSplit - invalid call" );
     309           0 :             maRuler.RemoveSplit( nParam1 );
     310           0 :             maGrid.RemoveSplit( nParam1 );
     311           0 :         break;
     312             :         case CSVCMD_TOGGLESPLIT:
     313           0 :             Execute( maRuler.HasSplit( nParam1 ) ? CSVCMD_REMOVESPLIT : CSVCMD_INSERTSPLIT, nParam1 );
     314           0 :         break;
     315             :         case CSVCMD_MOVESPLIT:
     316             :             OSL_ENSURE( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::MoveSplit - invalid call" );
     317           0 :             maRuler.MoveSplit( nParam1, nParam2 );
     318           0 :             maGrid.MoveSplit( nParam1, nParam2 );
     319           0 :         break;
     320             :         case CSVCMD_REMOVEALLSPLITS:
     321             :             OSL_ENSURE( mbFixedMode, "ScCsvTableBox::CsvCmdHdl::RemoveAllSplits - invalid call" );
     322           0 :             maRuler.RemoveAllSplits();
     323           0 :             maGrid.RemoveAllSplits();
     324           0 :         break;
     325             :         default:
     326           0 :             bFound = false;
     327             :     }
     328           0 :     if( bFound )
     329           0 :         return 0;
     330             : 
     331           0 :     const ScCsvLayoutData aOldData( maData );
     332           0 :     switch( eType )
     333             :     {
     334             :         case CSVCMD_SETPOSCOUNT:
     335           0 :             maData.mnPosCount = std::max( nParam1, sal_Int32( 1 ) );
     336           0 :             ImplSetPosOffset( GetFirstVisPos() );
     337           0 :         break;
     338             :         case CSVCMD_SETPOSOFFSET:
     339           0 :             ImplSetPosOffset( nParam1 );
     340           0 :         break;
     341             :         case CSVCMD_SETHDRWIDTH:
     342           0 :             maData.mnHdrWidth = std::max( nParam1, sal_Int32( 0 ) );
     343           0 :             ImplSetPosOffset( GetFirstVisPos() );
     344           0 :         break;
     345             :         case CSVCMD_SETCHARWIDTH:
     346           0 :             maData.mnCharWidth = std::max( nParam1, sal_Int32( 1 ) );
     347           0 :             ImplSetPosOffset( GetFirstVisPos() );
     348           0 :         break;
     349             :         case CSVCMD_SETLINECOUNT:
     350           0 :             maData.mnLineCount = std::max( nParam1, sal_Int32( 1 ) );
     351           0 :             ImplSetLineOffset( GetFirstVisLine() );
     352           0 :         break;
     353             :         case CSVCMD_SETLINEOFFSET:
     354           0 :             ImplSetLineOffset( nParam1 );
     355           0 :         break;
     356             :         case CSVCMD_SETHDRHEIGHT:
     357           0 :             maData.mnHdrHeight = std::max( nParam1, sal_Int32( 0 ) );
     358           0 :             ImplSetLineOffset( GetFirstVisLine() );
     359           0 :         break;
     360             :         case CSVCMD_SETLINEHEIGHT:
     361           0 :             maData.mnLineHeight = std::max( nParam1, sal_Int32( 1 ) );
     362           0 :             ImplSetLineOffset( GetFirstVisLine() );
     363           0 :         break;
     364             :         case CSVCMD_MOVERULERCURSOR:
     365           0 :             maData.mnPosCursor = IsVisibleSplitPos( nParam1 ) ? nParam1 : CSV_POS_INVALID;
     366           0 :         break;
     367             :         case CSVCMD_MOVEGRIDCURSOR:
     368           0 :             maData.mnColCursor = ((0 <= nParam1) && (nParam1 < GetPosCount())) ? nParam1 : CSV_POS_INVALID;
     369           0 :         break;
     370             :         default:
     371             :         {
     372             :             // added to avoid warnings
     373             :         }
     374             :     }
     375             : 
     376           0 :     if( maData != aOldData )
     377             :     {
     378           0 :         DisableRepaint();
     379           0 :         maRuler.ApplyLayout( aOldData );
     380           0 :         maGrid.ApplyLayout( aOldData );
     381           0 :         EnableRepaint();
     382             :     }
     383             : 
     384           0 :     return 0;
     385             : }
     386             : 
     387           0 : IMPL_LINK( ScCsvTableBox, ScrollHdl, ScrollBar*, pScrollBar )
     388             : {
     389             :     OSL_ENSURE( pScrollBar, "ScCsvTableBox::ScrollHdl - missing sender" );
     390             : 
     391           0 :     if( pScrollBar == &maHScroll )
     392           0 :         Execute( CSVCMD_SETPOSOFFSET, pScrollBar->GetThumbPos() );
     393           0 :     else if( pScrollBar == &maVScroll )
     394           0 :         Execute( CSVCMD_SETLINEOFFSET, pScrollBar->GetThumbPos() );
     395             : 
     396           0 :     return 0;
     397             : }
     398             : 
     399           0 : IMPL_LINK( ScCsvTableBox, ScrollEndHdl, ScrollBar*, pScrollBar )
     400             : {
     401             :     OSL_ENSURE( pScrollBar, "ScCsvTableBox::ScrollEndHdl - missing sender" );
     402             : 
     403           0 :     if( pScrollBar == &maHScroll )
     404             :     {
     405           0 :         if( GetRulerCursorPos() != CSV_POS_INVALID )
     406           0 :             Execute( CSVCMD_MOVERULERCURSOR, maRuler.GetNoScrollPos( GetRulerCursorPos() ) );
     407           0 :         if( GetGridCursorPos() != CSV_POS_INVALID )
     408           0 :             Execute( CSVCMD_MOVEGRIDCURSOR, maGrid.GetNoScrollCol( GetGridCursorPos() ) );
     409             :     }
     410             : 
     411           0 :     return 0;
     412             : }
     413             : 
     414             : 
     415             : // accessibility --------------------------------------------------------------
     416             : 
     417           0 : ScCsvTableBox::XAccessibleRef ScCsvTableBox::CreateAccessible()
     418             : {
     419             :     // do not use the ScCsvControl mechanism, return default accessible object
     420           0 :     return Control::CreateAccessible();
     421             : }
     422             : 
     423           0 : ScAccessibleCsvControl* ScCsvTableBox::ImplCreateAccessible()
     424             : {
     425           0 :     return NULL;    // not used, see CreateAccessible()
     426             : }
     427             : 
     428             : 
     429             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10