LCOV - code coverage report
Current view: top level - svtools/source/table - tabledatawindow.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 27 100 27.0 %
Date: 2015-06-13 12:38:46 Functions: 8 12 66.7 %
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 "table/tablecontrol.hxx"
      21             : 
      22             : #include "tabledatawindow.hxx"
      23             : #include "tablecontrol_impl.hxx"
      24             : #include "tablegeometry.hxx"
      25             : 
      26             : #include <vcl/help.hxx>
      27             : #include <vcl/settings.hxx>
      28             : 
      29             : namespace svt { namespace table
      30             : {
      31             :     using css::uno::Any;
      32             : 
      33           1 :     TableDataWindow::TableDataWindow( TableControl_Impl& _rTableControl )
      34           1 :         :Window( &_rTableControl.getAntiImpl() )
      35             :         ,m_rTableControl( _rTableControl )
      36           1 :         ,m_nTipWindowHandle( 0 )
      37             :     {
      38             :         // by default, use the background as determined by the style settings
      39           1 :         const Color aWindowColor( GetSettings().GetStyleSettings().GetFieldColor() );
      40           1 :         SetBackground( Wallpaper( aWindowColor ) );
      41           1 :         SetFillColor( aWindowColor );
      42           1 :     }
      43             : 
      44           3 :     TableDataWindow::~TableDataWindow()
      45             :     {
      46           1 :         disposeOnce();
      47           2 :     }
      48             : 
      49           1 :     void TableDataWindow::dispose()
      50             :     {
      51           1 :         impl_hideTipWindow();
      52           1 :         Window::dispose();
      53           1 :     }
      54             : 
      55           5 :     void TableDataWindow::Paint( vcl::RenderContext& rRenderContext, const Rectangle& rUpdateRect )
      56             :     {
      57           5 :         m_rTableControl.doPaintContent(rRenderContext, rUpdateRect);
      58           5 :     }
      59             : 
      60           1 :     void TableDataWindow::SetBackground( const Wallpaper& rColor )
      61             :     {
      62           1 :         Window::SetBackground( rColor );
      63           1 :     }
      64             : 
      65           0 :     void TableDataWindow::RequestHelp( const HelpEvent& rHEvt )
      66             :     {
      67           0 :         HelpEventMode const nHelpMode = rHEvt.GetMode();
      68           0 :         if  (   IsMouseCaptured()
      69           0 :             ||  !( nHelpMode & HelpEventMode::QUICK )
      70             :             )
      71             :         {
      72           0 :             Window::RequestHelp( rHEvt );
      73           0 :             return;
      74             :         }
      75             : 
      76           0 :         OUString sHelpText;
      77           0 :         QuickHelpFlags nHelpStyle = QuickHelpFlags::NONE;
      78             : 
      79           0 :         Point const aMousePos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
      80           0 :         RowPos const hitRow = m_rTableControl.getRowAtPoint( aMousePos );
      81           0 :         ColPos const hitCol = m_rTableControl.getColAtPoint( aMousePos );
      82             : 
      83           0 :         PTableModel const pTableModel( m_rTableControl.getModel() );
      84           0 :         if ( ( hitCol >= 0 ) && ( hitCol < pTableModel->getColumnCount() ) )
      85             :         {
      86           0 :             if ( hitRow == ROW_COL_HEADERS )
      87             :             {
      88           0 :                 sHelpText = pTableModel->getColumnModel( hitCol )->getHelpText();
      89             :             }
      90           0 :             else if ( ( hitRow >= 0 ) && ( hitRow < pTableModel->getRowCount() ) )
      91             :             {
      92           0 :                 Any aCellToolTip;
      93           0 :                 pTableModel->getCellToolTip( hitCol, hitRow, aCellToolTip );
      94           0 :                 if ( !aCellToolTip.hasValue() )
      95             :                 {
      96             :                     // use the cell content
      97           0 :                     pTableModel->getCellContent( hitCol, hitRow, aCellToolTip );
      98             : 
      99             :                     // use the cell content as tool tip only if it doesn't fit into the cell.
     100           0 :                     bool const activeCell = ( hitRow == m_rTableControl.getCurrentRow() ) && ( hitCol == m_rTableControl.getCurrentColumn() );
     101           0 :                     bool const selectedCell = m_rTableControl.isRowSelected( hitRow );
     102             : 
     103           0 :                     Rectangle const aWindowRect( Point( 0, 0 ), GetOutputSizePixel() );
     104           0 :                     TableCellGeometry const aCell( m_rTableControl, aWindowRect, hitCol, hitRow );
     105           0 :                     Rectangle const aCellRect( aCell.getRect() );
     106             : 
     107           0 :                     PTableRenderer const pRenderer = pTableModel->getRenderer();
     108           0 :                     if ( pRenderer->FitsIntoCell( aCellToolTip, hitCol, hitRow, activeCell, selectedCell, *this, aCellRect ) )
     109           0 :                         aCellToolTip.clear();
     110             :                 }
     111             : 
     112           0 :                 pTableModel->getRenderer()->GetFormattedCellString( aCellToolTip, hitCol, hitRow, sHelpText );
     113             : 
     114           0 :                 if ( sHelpText.indexOf( '\n' ) >= 0 )
     115           0 :                     nHelpStyle = QuickHelpFlags::TipStyleBalloon;
     116             :             }
     117             :         }
     118             : 
     119           0 :         if ( !sHelpText.isEmpty() )
     120             :         {
     121             :             // hide the standard (singleton) help window, so we do not have two help windows open at the same time
     122           0 :             Help::HideBalloonAndQuickHelp();
     123             : 
     124             :             Rectangle const aControlScreenRect(
     125           0 :                 OutputToScreenPixel( Point( 0, 0 ) ),
     126           0 :                 GetOutputSizePixel()
     127           0 :             );
     128             : 
     129           0 :             if ( m_nTipWindowHandle )
     130             :             {
     131           0 :                 Help::UpdateTip( m_nTipWindowHandle, this, aControlScreenRect, sHelpText );
     132             :             }
     133             :             else
     134           0 :                 m_nTipWindowHandle = Help::ShowTip( this, aControlScreenRect, sHelpText, nHelpStyle );
     135             :         }
     136             :         else
     137             :         {
     138           0 :             impl_hideTipWindow();
     139           0 :             Window::RequestHelp( rHEvt );
     140           0 :         }
     141             :     }
     142             : 
     143             : 
     144           1 :     void TableDataWindow::impl_hideTipWindow()
     145             :     {
     146           1 :         if ( m_nTipWindowHandle != 0 )
     147             :         {
     148           0 :             Help::HideTip( m_nTipWindowHandle );
     149           0 :             m_nTipWindowHandle = 0;
     150             :         }
     151           1 :     }
     152             : 
     153             : 
     154           0 :     void TableDataWindow::MouseMove( const MouseEvent& rMEvt )
     155             :     {
     156           0 :         if ( rMEvt.IsLeaveWindow() )
     157           0 :             impl_hideTipWindow();
     158             : 
     159           0 :         if ( !m_rTableControl.getInputHandler()->MouseMove( m_rTableControl, rMEvt ) )
     160             :         {
     161           0 :             Window::MouseMove( rMEvt );
     162             :         }
     163           0 :     }
     164             : 
     165           0 :     void TableDataWindow::MouseButtonDown( const MouseEvent& rMEvt )
     166             :     {
     167           0 :         impl_hideTipWindow();
     168             : 
     169           0 :         Point const aPoint = rMEvt.GetPosPixel();
     170           0 :         RowPos const hitRow = m_rTableControl.getRowAtPoint( aPoint );
     171           0 :         bool const wasRowSelected = m_rTableControl.isRowSelected( hitRow );
     172           0 :         size_t const nPrevSelRowCount = m_rTableControl.getSelectedRowCount();
     173             : 
     174           0 :         if ( !m_rTableControl.getInputHandler()->MouseButtonDown( m_rTableControl, rMEvt ) )
     175             :         {
     176           0 :             Window::MouseButtonDown( rMEvt );
     177           0 :             return;
     178             :         }
     179             : 
     180           0 :         bool const isRowSelected = m_rTableControl.isRowSelected( hitRow );
     181           0 :         size_t const nCurSelRowCount = m_rTableControl.getSelectedRowCount();
     182           0 :         if ( isRowSelected != wasRowSelected || nCurSelRowCount != nPrevSelRowCount )
     183             :         {
     184           0 :             m_aSelectHdl.Call( NULL );
     185             :         }
     186             :     }
     187             : 
     188             : 
     189           0 :     void TableDataWindow::MouseButtonUp( const MouseEvent& rMEvt )
     190             :     {
     191           0 :         if ( !m_rTableControl.getInputHandler()->MouseButtonUp( m_rTableControl, rMEvt ) )
     192           0 :             Window::MouseButtonUp( rMEvt );
     193             : 
     194           0 :         m_rTableControl.getAntiImpl().GrabFocus();
     195           0 :     }
     196             : 
     197             : 
     198           1 :     bool TableDataWindow::Notify(NotifyEvent& rNEvt )
     199             :     {
     200           1 :         bool nDone = false;
     201           1 :         if ( rNEvt.GetType() == MouseNotifyEvent::COMMAND )
     202             :         {
     203           0 :             const CommandEvent& rCEvt = *rNEvt.GetCommandEvent();
     204           0 :             if ( rCEvt.GetCommand() == CommandEventId::Wheel )
     205             :             {
     206           0 :                 const CommandWheelData* pData = rCEvt.GetWheelData();
     207           0 :                 if( !pData->GetModifier() && ( pData->GetMode() == CommandWheelMode::SCROLL ) )
     208             :                 {
     209           0 :                     nDone = HandleScrollCommand( rCEvt, m_rTableControl.getHorzScrollbar(), m_rTableControl.getVertScrollbar() );
     210             :                 }
     211             :             }
     212             :         }
     213           1 :         return nDone || Window::Notify( rNEvt );
     214             :     }
     215             : 
     216             : }} // namespace svt::table
     217             : 
     218             : 
     219             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11