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

Generated by: LCOV version 1.10