LCOV - code coverage report
Current view: top level - svtools/source/table - mousefunction.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 117 0.0 %
Date: 2012-08-25 Functions: 0 11 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 166 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       4                 :            :  *
       5                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       6                 :            :  *
       7                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       8                 :            :  *
       9                 :            :  * This file is part of OpenOffice.org.
      10                 :            :  *
      11                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      12                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      13                 :            :  * only, as published by the Free Software Foundation.
      14                 :            :  *
      15                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      16                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      17                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18                 :            :  * GNU Lesser General Public License version 3 for more details
      19                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      20                 :            :  *
      21                 :            :  * You should have received a copy of the GNU Lesser General Public License
      22                 :            :  * version 3 along with OpenOffice.org.  If not, see
      23                 :            :  * <http://www.openoffice.org/license.html>
      24                 :            :  * for a copy of the LGPLv3 License.
      25                 :            :  *
      26                 :            :  ************************************************************************/
      27                 :            : 
      28                 :            : 
      29                 :            : #include "mousefunction.hxx"
      30                 :            : #include "svtools/table/tablecontrolinterface.hxx"
      31                 :            : 
      32                 :            : #include <tools/diagnose_ex.h>
      33                 :            : #include <vcl/window.hxx>
      34                 :            : 
      35                 :            : //......................................................................................................................
      36                 :            : namespace svt { namespace table
      37                 :            : {
      38                 :            : //......................................................................................................................
      39                 :            : 
      40                 :            :     //==================================================================================================================
      41                 :            :     //= MouseFunction
      42                 :            :     //==================================================================================================================
      43                 :            :     //------------------------------------------------------------------------------------------------------------------
      44                 :          0 :     oslInterlockedCount MouseFunction::acquire()
      45                 :            :     {
      46                 :          0 :         return osl_incrementInterlockedCount( &m_refCount );
      47                 :            :     }
      48                 :            : 
      49                 :            :     //------------------------------------------------------------------------------------------------------------------
      50                 :          0 :     oslInterlockedCount MouseFunction::release()
      51                 :            :     {
      52                 :          0 :         oslInterlockedCount newCount = osl_decrementInterlockedCount( &m_refCount );
      53         [ #  # ]:          0 :         if ( newCount == 0 )
      54                 :            :         {
      55         [ #  # ]:          0 :             delete this;
      56                 :          0 :             return 0;
      57                 :            :         }
      58                 :          0 :         return newCount;
      59                 :            :     }
      60                 :            : 
      61                 :            :     //==================================================================================================================
      62                 :            :     //= ColumnResize
      63                 :            :     //==================================================================================================================
      64                 :            :     //------------------------------------------------------------------------------------------------------------------
      65                 :          0 :     FunctionResult ColumnResize::handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event )
      66                 :            :     {
      67                 :          0 :         Point const aPoint = i_event.GetPosPixel();
      68                 :            : 
      69         [ #  # ]:          0 :         if ( m_nResizingColumn == COL_INVALID )
      70                 :            :         {
      71                 :            :             // if we hit a column divider, change the mosue pointer accordingly
      72                 :          0 :             Pointer aNewPointer( POINTER_ARROW );
      73         [ #  # ]:          0 :             TableCell const tableCell = i_tableControl.hitTest( aPoint );
      74 [ #  # ][ #  # ]:          0 :             if ( ( tableCell.nRow == ROW_COL_HEADERS ) && ( tableCell.eArea == ColumnDivider ) )
      75                 :            :             {
      76                 :          0 :                 aNewPointer = Pointer( POINTER_HSPLIT );
      77                 :            :             }
      78         [ #  # ]:          0 :             i_tableControl.setPointer( aNewPointer );
      79                 :            : 
      80                 :          0 :             return SkipFunction;    // TODO: is this correct?
      81                 :            :         }
      82                 :            : 
      83         [ #  # ]:          0 :         ::Size const tableSize = i_tableControl.getTableSizePixel();
      84                 :            : 
      85                 :            :         // set proper pointer
      86                 :          0 :         Pointer aNewPointer( POINTER_ARROW );
      87         [ #  # ]:          0 :         ColumnMetrics const & columnMetrics( i_tableControl.getColumnMetrics( m_nResizingColumn ) );
      88   [ #  #  #  # ]:          0 :         if  (   ( aPoint.X() > tableSize.Width() )
                 [ #  # ]
      89                 :          0 :             ||  ( aPoint.X() < columnMetrics.nStartPixel )
      90                 :            :             )
      91                 :            :         {
      92                 :          0 :             aNewPointer = Pointer( POINTER_NOTALLOWED );
      93                 :            :         }
      94                 :            :         else
      95                 :            :         {
      96                 :          0 :             aNewPointer = Pointer( POINTER_HSPLIT );
      97                 :            :         }
      98         [ #  # ]:          0 :         i_tableControl.setPointer( aNewPointer );
      99                 :            : 
     100                 :            :         // show tracking line
     101         [ #  # ]:          0 :         i_tableControl.hideTracking();
     102                 :            :         i_tableControl.showTracking(
     103                 :            :             Rectangle(
     104                 :            :                 Point( aPoint.X(), 0 ),
     105                 :            :                 Size( 1, tableSize.Height() )
     106                 :            :             ),
     107                 :            :             SHOWTRACK_SPLIT | SHOWTRACK_WINDOW
     108 [ #  # ][ #  # ]:          0 :         );
     109                 :            : 
     110                 :            :         (void)i_event;
     111                 :          0 :         return ContinueFunction;
     112                 :            :     }
     113                 :            : 
     114                 :            :     //------------------------------------------------------------------------------------------------------------------
     115                 :          0 :     FunctionResult ColumnResize::handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event )
     116                 :            :     {
     117         [ #  # ]:          0 :         if ( m_nResizingColumn != COL_INVALID )
     118                 :            :         {
     119                 :            :             OSL_ENSURE( false, "ColumnResize::handleMouseDown: suspicious: MouseButtonDown while still tracking?" );
     120                 :          0 :             return ContinueFunction;
     121                 :            :         }
     122                 :            : 
     123         [ #  # ]:          0 :         TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
     124         [ #  # ]:          0 :         if ( tableCell.nRow == ROW_COL_HEADERS )
     125                 :            :         {
     126 [ #  # ][ #  # ]:          0 :             if  (   ( tableCell.nColumn != COL_INVALID )
     127                 :            :                 &&  ( tableCell.eArea == ColumnDivider )
     128                 :            :                 )
     129                 :            :             {
     130                 :          0 :                 m_nResizingColumn = tableCell.nColumn;
     131         [ #  # ]:          0 :                 i_tableControl.captureMouse();
     132                 :          0 :                 return ActivateFunction;
     133                 :            :             }
     134                 :            :         }
     135                 :            : 
     136                 :          0 :         return SkipFunction;
     137                 :            :     }
     138                 :            : 
     139                 :            :     //------------------------------------------------------------------------------------------------------------------
     140                 :          0 :     FunctionResult ColumnResize::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event )
     141                 :            :     {
     142         [ #  # ]:          0 :         if ( m_nResizingColumn == COL_INVALID )
     143                 :          0 :             return SkipFunction;
     144                 :            : 
     145                 :          0 :         Point const aPoint = i_event.GetPosPixel();
     146                 :            : 
     147         [ #  # ]:          0 :         i_tableControl.hideTracking();
     148 [ #  # ][ #  # ]:          0 :         PColumnModel const pColumn = i_tableControl.getModel()->getColumnModel( m_nResizingColumn );
                 [ #  # ]
     149         [ #  # ]:          0 :         long const maxWidthLogical = pColumn->getMaxWidth();
     150         [ #  # ]:          0 :         long const minWidthLogical = pColumn->getMinWidth();
     151                 :            : 
     152                 :            :         // new position of mouse
     153                 :          0 :         long const requestedEnd = aPoint.X();
     154                 :            : 
     155                 :            :         // old position of right border
     156         [ #  # ]:          0 :         long const oldEnd = i_tableControl.getColumnMetrics( m_nResizingColumn ).nEndPixel;
     157                 :            : 
     158                 :            :         // position of left border if cursor in the to-be-resized column
     159         [ #  # ]:          0 :         long const columnStart = i_tableControl.getColumnMetrics( m_nResizingColumn ).nStartPixel;
     160                 :          0 :         long const requestedWidth = requestedEnd - columnStart;
     161                 :            :             // TODO: this is not correct, strictly: It assumes that the mouse was pressed exactly on the "end" pos,
     162                 :            :             // but for a while now, we have relaxed this, and allow clicking a few pixels aside, too
     163                 :            : 
     164         [ #  # ]:          0 :         if ( requestedEnd >= columnStart )
     165                 :            :         {
     166         [ #  # ]:          0 :             long requestedWidthLogical = i_tableControl.pixelWidthToAppFont( requestedWidth );
     167                 :            :             // respect column width limits
     168         [ #  # ]:          0 :             if ( oldEnd > requestedEnd )
     169                 :            :             {
     170                 :            :                 // column has become smaller, check against minimum width
     171 [ #  # ][ #  # ]:          0 :                 if ( ( minWidthLogical != 0 ) && ( requestedWidthLogical < minWidthLogical ) )
     172                 :          0 :                     requestedWidthLogical = minWidthLogical;
     173                 :            :             }
     174         [ #  # ]:          0 :             else if ( oldEnd < requestedEnd )
     175                 :            :             {
     176                 :            :                 // column has become larger, check against max width
     177 [ #  # ][ #  # ]:          0 :                 if ( ( maxWidthLogical != 0 ) && ( requestedWidthLogical >= maxWidthLogical ) )
     178                 :          0 :                     requestedWidthLogical = maxWidthLogical;
     179                 :            :             }
     180         [ #  # ]:          0 :             pColumn->setWidth( requestedWidthLogical );
     181         [ #  # ]:          0 :             i_tableControl.invalidate( TableAreaAll );
     182                 :            :         }
     183                 :            : 
     184         [ #  # ]:          0 :         i_tableControl.setPointer( Pointer() );
     185         [ #  # ]:          0 :         i_tableControl.releaseMouse();
     186                 :            : 
     187                 :          0 :         m_nResizingColumn = COL_INVALID;
     188         [ #  # ]:          0 :         return DeactivateFunction;
     189                 :            :     }
     190                 :            : 
     191                 :            :     //==================================================================================================================
     192                 :            :     //= RowSelection
     193                 :            :     //==================================================================================================================
     194                 :            :     //------------------------------------------------------------------------------------------------------------------
     195                 :          0 :     FunctionResult RowSelection::handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event )
     196                 :            :     {
     197                 :            :         OSL_UNUSED( i_tableControl );
     198                 :            :         OSL_UNUSED( i_event );
     199                 :          0 :         return SkipFunction;
     200                 :            :     }
     201                 :            : 
     202                 :            :     //------------------------------------------------------------------------------------------------------------------
     203                 :          0 :     FunctionResult RowSelection::handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event )
     204                 :            :     {
     205                 :          0 :         bool handled = false;
     206                 :            : 
     207         [ #  # ]:          0 :         TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
     208         [ #  # ]:          0 :         if ( tableCell.nRow >= 0 )
     209                 :            :         {
     210                 :          0 :             bool bSetCursor = false;
     211 [ #  # ][ #  # ]:          0 :             if ( i_tableControl.getSelEngine()->GetSelectionMode() == NO_SELECTION )
     212                 :            :             {
     213                 :          0 :                 bSetCursor = true;
     214                 :            :             }
     215                 :            :             else
     216                 :            :             {
     217 [ #  # ][ #  # ]:          0 :                 if ( !i_tableControl.isRowSelected( tableCell.nRow ) )
     218                 :            :                 {
     219 [ #  # ][ #  # ]:          0 :                     handled = i_tableControl.getSelEngine()->SelMouseButtonDown( i_event );
     220                 :            :                 }
     221                 :            :                 else
     222                 :            :                 {
     223                 :          0 :                     bSetCursor = true;
     224                 :            :                 }
     225                 :            :             }
     226                 :            : 
     227         [ #  # ]:          0 :             if ( bSetCursor )
     228                 :            :             {
     229         [ #  # ]:          0 :                 i_tableControl.activateCell( tableCell.nColumn, tableCell.nRow );
     230                 :          0 :                 handled = true;
     231                 :            :             }
     232                 :            :         }
     233                 :            : 
     234         [ #  # ]:          0 :         if ( handled )
     235                 :          0 :             m_bActive = true;
     236         [ #  # ]:          0 :         return handled ? ActivateFunction : SkipFunction;
     237                 :            :     }
     238                 :            : 
     239                 :            :     //------------------------------------------------------------------------------------------------------------------
     240                 :          0 :     FunctionResult RowSelection::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event )
     241                 :            :     {
     242         [ #  # ]:          0 :         TableCell const tableCell = i_tableControl.hitTest( i_event.GetPosPixel() );
     243         [ #  # ]:          0 :         if ( tableCell.nRow >= 0 )
     244                 :            :         {
     245 [ #  # ][ #  # ]:          0 :             if ( i_tableControl.getSelEngine()->GetSelectionMode() != NO_SELECTION )
     246                 :            :             {
     247 [ #  # ][ #  # ]:          0 :                 i_tableControl.getSelEngine()->SelMouseButtonUp( i_event );
     248                 :            :             }
     249                 :            :         }
     250         [ #  # ]:          0 :         if ( m_bActive )
     251                 :            :         {
     252                 :          0 :             m_bActive = false;
     253                 :          0 :             return DeactivateFunction;
     254                 :            :         }
     255                 :          0 :         return SkipFunction;
     256                 :            :     }
     257                 :            : 
     258                 :            :     //==================================================================================================================
     259                 :            :     //= ColumnSortHandler
     260                 :            :     //==================================================================================================================
     261                 :            :     //------------------------------------------------------------------------------------------------------------------
     262                 :          0 :     FunctionResult ColumnSortHandler::handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event )
     263                 :            :     {
     264                 :            :         OSL_UNUSED( i_tableControl );
     265                 :            :         OSL_UNUSED( i_event );
     266                 :          0 :         return SkipFunction;
     267                 :            :     }
     268                 :            : 
     269                 :            :     //------------------------------------------------------------------------------------------------------------------
     270                 :          0 :     FunctionResult ColumnSortHandler::handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event )
     271                 :            :     {
     272         [ #  # ]:          0 :         if ( m_nActiveColumn != COL_INVALID )
     273                 :            :         {
     274                 :            :             OSL_ENSURE( false, "ColumnSortHandler::handleMouseDown: called while already active - suspicious!" );
     275                 :          0 :             return ContinueFunction;
     276                 :            :         }
     277                 :            : 
     278 [ #  # ][ #  # ]:          0 :         if ( i_tableControl.getModel()->getSortAdapter() == NULL )
         [ #  # ][ #  # ]
     279                 :            :             // no sorting support at the model
     280                 :          0 :             return SkipFunction;
     281                 :            : 
     282         [ #  # ]:          0 :         TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
     283 [ #  # ][ #  # ]:          0 :         if ( ( tableCell.nRow != ROW_COL_HEADERS ) || ( tableCell.nColumn < 0 ) )
     284                 :          0 :             return SkipFunction;
     285                 :            : 
     286                 :            :         // TODO: ensure the column header is rendered in some special way, indicating its current state
     287                 :            : 
     288                 :          0 :         m_nActiveColumn = tableCell.nColumn;
     289                 :          0 :         return ActivateFunction;
     290                 :            :     }
     291                 :            : 
     292                 :            :     //------------------------------------------------------------------------------------------------------------------
     293                 :          0 :     FunctionResult ColumnSortHandler::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event )
     294                 :            :     {
     295         [ #  # ]:          0 :         if ( m_nActiveColumn == COL_INVALID )
     296                 :          0 :             return SkipFunction;
     297                 :            : 
     298         [ #  # ]:          0 :         TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
     299 [ #  # ][ #  # ]:          0 :         if ( ( tableCell.nRow == ROW_COL_HEADERS ) && ( tableCell.nColumn == m_nActiveColumn ) )
     300                 :            :         {
     301 [ #  # ][ #  # ]:          0 :             ITableDataSort* pSort = i_tableControl.getModel()->getSortAdapter();
                 [ #  # ]
     302         [ #  # ]:          0 :             ENSURE_OR_RETURN( pSort != NULL, "ColumnSortHandler::handleMouseUp: somebody is mocking with us!", DeactivateFunction );
     303                 :            :                 // in handleMousButtonDown, the model claimed to have sort support ...
     304                 :            : 
     305                 :          0 :             ColumnSortDirection eSortDirection = ColumnSortAscending;
     306         [ #  # ]:          0 :             ColumnSort const aCurrentSort = pSort->getCurrentSortOrder();
     307         [ #  # ]:          0 :             if ( aCurrentSort.nColumnPos == m_nActiveColumn )
     308                 :            :                 // invert existing sort order
     309         [ #  # ]:          0 :                 eSortDirection = ( aCurrentSort.eSortDirection == ColumnSortAscending ) ? ColumnSortDescending : ColumnSortAscending;
     310                 :            : 
     311         [ #  # ]:          0 :             pSort->sortByColumn( m_nActiveColumn, eSortDirection );
     312                 :            :         }
     313                 :            : 
     314                 :          0 :         m_nActiveColumn = COL_INVALID;
     315                 :          0 :         return DeactivateFunction;
     316                 :            :     }
     317                 :            : 
     318                 :            : //......................................................................................................................
     319                 :            : } } // namespace svt::table
     320                 :            : //......................................................................................................................
     321                 :            : 
     322                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10