LCOV - code coverage report
Current view: top level - svtools/source/table - mousefunction.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 106 0.9 %
Date: 2014-11-03 Functions: 2 11 18.2 %
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             : 
      21             : #include "mousefunction.hxx"
      22             : #include "table/tablecontrolinterface.hxx"
      23             : 
      24             : #include <tools/diagnose_ex.h>
      25             : #include <vcl/window.hxx>
      26             : 
      27             : 
      28             : namespace svt { namespace table
      29             : {
      30             : 
      31             : 
      32             : 
      33             :     //= ColumnResize
      34             : 
      35             : 
      36           0 :     FunctionResult ColumnResize::handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event )
      37             :     {
      38           0 :         Point const aPoint = i_event.GetPosPixel();
      39             : 
      40           0 :         if ( m_nResizingColumn == COL_INVALID )
      41             :         {
      42             :             // if we hit a column divider, change the mosue pointer accordingly
      43           0 :             Pointer aNewPointer( POINTER_ARROW );
      44           0 :             TableCell const tableCell = i_tableControl.hitTest( aPoint );
      45           0 :             if ( ( tableCell.nRow == ROW_COL_HEADERS ) && ( tableCell.eArea == ColumnDivider ) )
      46             :             {
      47           0 :                 aNewPointer = Pointer( POINTER_HSPLIT );
      48             :             }
      49           0 :             i_tableControl.setPointer( aNewPointer );
      50             : 
      51           0 :             return SkipFunction;    // TODO: is this correct?
      52             :         }
      53             : 
      54           0 :         ::Size const tableSize = i_tableControl.getTableSizePixel();
      55             : 
      56             :         // set proper pointer
      57           0 :         Pointer aNewPointer( POINTER_ARROW );
      58           0 :         ColumnMetrics const & columnMetrics( i_tableControl.getColumnMetrics( m_nResizingColumn ) );
      59           0 :         if  (   ( aPoint.X() > tableSize.Width() )
      60           0 :             ||  ( aPoint.X() < columnMetrics.nStartPixel )
      61             :             )
      62             :         {
      63           0 :             aNewPointer = Pointer( POINTER_NOTALLOWED );
      64             :         }
      65             :         else
      66             :         {
      67           0 :             aNewPointer = Pointer( POINTER_HSPLIT );
      68             :         }
      69           0 :         i_tableControl.setPointer( aNewPointer );
      70             : 
      71             :         // show tracking line
      72           0 :         i_tableControl.hideTracking();
      73             :         i_tableControl.showTracking(
      74             :             Rectangle(
      75             :                 Point( aPoint.X(), 0 ),
      76             :                 Size( 1, tableSize.Height() )
      77             :             ),
      78             :             SHOWTRACK_SPLIT | SHOWTRACK_WINDOW
      79           0 :         );
      80             : 
      81             :         (void)i_event;
      82           0 :         return ContinueFunction;
      83             :     }
      84             : 
      85             : 
      86           0 :     FunctionResult ColumnResize::handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event )
      87             :     {
      88           0 :         if ( m_nResizingColumn != COL_INVALID )
      89             :         {
      90             :             OSL_ENSURE( false, "ColumnResize::handleMouseDown: suspicious: MouseButtonDown while still tracking?" );
      91           0 :             return ContinueFunction;
      92             :         }
      93             : 
      94           0 :         TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
      95           0 :         if ( tableCell.nRow == ROW_COL_HEADERS )
      96             :         {
      97           0 :             if  (   ( tableCell.nColumn != COL_INVALID )
      98           0 :                 &&  ( tableCell.eArea == ColumnDivider )
      99             :                 )
     100             :             {
     101           0 :                 m_nResizingColumn = tableCell.nColumn;
     102           0 :                 i_tableControl.captureMouse();
     103           0 :                 return ActivateFunction;
     104             :             }
     105             :         }
     106             : 
     107           0 :         return SkipFunction;
     108             :     }
     109             : 
     110             : 
     111           0 :     FunctionResult ColumnResize::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event )
     112             :     {
     113           0 :         if ( m_nResizingColumn == COL_INVALID )
     114           0 :             return SkipFunction;
     115             : 
     116           0 :         Point const aPoint = i_event.GetPosPixel();
     117             : 
     118           0 :         i_tableControl.hideTracking();
     119           0 :         PColumnModel const pColumn = i_tableControl.getModel()->getColumnModel( m_nResizingColumn );
     120           0 :         long const maxWidthLogical = pColumn->getMaxWidth();
     121           0 :         long const minWidthLogical = pColumn->getMinWidth();
     122             : 
     123             :         // new position of mouse
     124           0 :         long const requestedEnd = aPoint.X();
     125             : 
     126             :         // old position of right border
     127           0 :         long const oldEnd = i_tableControl.getColumnMetrics( m_nResizingColumn ).nEndPixel;
     128             : 
     129             :         // position of left border if cursor in the to-be-resized column
     130           0 :         long const columnStart = i_tableControl.getColumnMetrics( m_nResizingColumn ).nStartPixel;
     131           0 :         long const requestedWidth = requestedEnd - columnStart;
     132             :             // TODO: this is not correct, strictly: It assumes that the mouse was pressed exactly on the "end" pos,
     133             :             // but for a while now, we have relaxed this, and allow clicking a few pixels aside, too
     134             : 
     135           0 :         if ( requestedEnd >= columnStart )
     136             :         {
     137           0 :             long requestedWidthLogical = i_tableControl.pixelWidthToAppFont( requestedWidth );
     138             :             // respect column width limits
     139           0 :             if ( oldEnd > requestedEnd )
     140             :             {
     141             :                 // column has become smaller, check against minimum width
     142           0 :                 if ( ( minWidthLogical != 0 ) && ( requestedWidthLogical < minWidthLogical ) )
     143           0 :                     requestedWidthLogical = minWidthLogical;
     144             :             }
     145           0 :             else if ( oldEnd < requestedEnd )
     146             :             {
     147             :                 // column has become larger, check against max width
     148           0 :                 if ( ( maxWidthLogical != 0 ) && ( requestedWidthLogical >= maxWidthLogical ) )
     149           0 :                     requestedWidthLogical = maxWidthLogical;
     150             :             }
     151           0 :             pColumn->setWidth( requestedWidthLogical );
     152           0 :             i_tableControl.invalidate( TableAreaAll );
     153             :         }
     154             : 
     155           0 :         i_tableControl.setPointer( Pointer() );
     156           0 :         i_tableControl.releaseMouse();
     157             : 
     158           0 :         m_nResizingColumn = COL_INVALID;
     159           0 :         return DeactivateFunction;
     160             :     }
     161             : 
     162             : 
     163             :     //= RowSelection
     164             : 
     165             : 
     166           0 :     FunctionResult RowSelection::handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event )
     167             :     {
     168             :         OSL_UNUSED( i_tableControl );
     169             :         OSL_UNUSED( i_event );
     170           0 :         return SkipFunction;
     171             :     }
     172             : 
     173             : 
     174           0 :     FunctionResult RowSelection::handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event )
     175             :     {
     176           0 :         bool handled = false;
     177             : 
     178           0 :         TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
     179           0 :         if ( tableCell.nRow >= 0 )
     180             :         {
     181           0 :             if ( i_tableControl.getSelEngine()->GetSelectionMode() == NO_SELECTION )
     182             :             {
     183           0 :                 i_tableControl.activateCell( tableCell.nColumn, tableCell.nRow );
     184           0 :                 handled = true;
     185             :             }
     186             :             else
     187             :             {
     188           0 :                 handled = i_tableControl.getSelEngine()->SelMouseButtonDown( i_event );
     189             :             }
     190             :         }
     191             : 
     192           0 :         if ( handled )
     193           0 :             m_bActive = true;
     194           0 :         return handled ? ActivateFunction : SkipFunction;
     195             :     }
     196             : 
     197             : 
     198           0 :     FunctionResult RowSelection::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event )
     199             :     {
     200           0 :         TableCell const tableCell = i_tableControl.hitTest( i_event.GetPosPixel() );
     201           0 :         if ( tableCell.nRow >= 0 )
     202             :         {
     203           0 :             if ( i_tableControl.getSelEngine()->GetSelectionMode() != NO_SELECTION )
     204             :             {
     205           0 :                 i_tableControl.getSelEngine()->SelMouseButtonUp( i_event );
     206             :             }
     207             :         }
     208           0 :         if ( m_bActive )
     209             :         {
     210           0 :             m_bActive = false;
     211           0 :             return DeactivateFunction;
     212             :         }
     213           0 :         return SkipFunction;
     214             :     }
     215             : 
     216             : 
     217             :     //= ColumnSortHandler
     218             : 
     219             : 
     220           0 :     FunctionResult ColumnSortHandler::handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event )
     221             :     {
     222             :         OSL_UNUSED( i_tableControl );
     223             :         OSL_UNUSED( i_event );
     224           0 :         return SkipFunction;
     225             :     }
     226             : 
     227             : 
     228           0 :     FunctionResult ColumnSortHandler::handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event )
     229             :     {
     230           0 :         if ( m_nActiveColumn != COL_INVALID )
     231             :         {
     232             :             OSL_ENSURE( false, "ColumnSortHandler::handleMouseDown: called while already active - suspicious!" );
     233           0 :             return ContinueFunction;
     234             :         }
     235             : 
     236           0 :         if ( i_tableControl.getModel()->getSortAdapter() == NULL )
     237             :             // no sorting support at the model
     238           0 :             return SkipFunction;
     239             : 
     240           0 :         TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
     241           0 :         if ( ( tableCell.nRow != ROW_COL_HEADERS ) || ( tableCell.nColumn < 0 ) )
     242           0 :             return SkipFunction;
     243             : 
     244             :         // TODO: ensure the column header is rendered in some special way, indicating its current state
     245             : 
     246           0 :         m_nActiveColumn = tableCell.nColumn;
     247           0 :         return ActivateFunction;
     248             :     }
     249             : 
     250             : 
     251           0 :     FunctionResult ColumnSortHandler::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event )
     252             :     {
     253           0 :         if ( m_nActiveColumn == COL_INVALID )
     254           0 :             return SkipFunction;
     255             : 
     256           0 :         TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
     257           0 :         if ( ( tableCell.nRow == ROW_COL_HEADERS ) && ( tableCell.nColumn == m_nActiveColumn ) )
     258             :         {
     259           0 :             ITableDataSort* pSort = i_tableControl.getModel()->getSortAdapter();
     260           0 :             ENSURE_OR_RETURN( pSort != NULL, "ColumnSortHandler::handleMouseUp: somebody is mocking with us!", DeactivateFunction );
     261             :                 // in handleMousButtonDown, the model claimed to have sort support ...
     262             : 
     263           0 :             ColumnSortDirection eSortDirection = ColumnSortAscending;
     264           0 :             ColumnSort const aCurrentSort = pSort->getCurrentSortOrder();
     265           0 :             if ( aCurrentSort.nColumnPos == m_nActiveColumn )
     266             :                 // invert existing sort order
     267           0 :                 eSortDirection = ( aCurrentSort.eSortDirection == ColumnSortAscending ) ? ColumnSortDescending : ColumnSortAscending;
     268             : 
     269           0 :             pSort->sortByColumn( m_nActiveColumn, eSortDirection );
     270             :         }
     271             : 
     272           0 :         m_nActiveColumn = COL_INVALID;
     273           0 :         return DeactivateFunction;
     274             :     }
     275             : 
     276             : 
     277        1227 : } } // namespace svt::table
     278             : 
     279             : 
     280             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10