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

Generated by: LCOV version 1.10