fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / table / mousefunction.cxx
blob1fe94b84d0054832b3da81b6460d23c3f5e009b0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "mousefunction.hxx"
22 #include "svtools/table/tablecontrolinterface.hxx"
24 #include <tools/diagnose_ex.h>
25 #include <vcl/window.hxx>
27 //......................................................................................................................
28 namespace svt { namespace table
30 //......................................................................................................................
32 //==================================================================================================================
33 //= MouseFunction
34 //==================================================================================================================
35 //------------------------------------------------------------------------------------------------------------------
36 oslInterlockedCount MouseFunction::acquire()
38 return osl_atomic_increment( &m_refCount );
41 //------------------------------------------------------------------------------------------------------------------
42 oslInterlockedCount MouseFunction::release()
44 oslInterlockedCount newCount = osl_atomic_decrement( &m_refCount );
45 if ( newCount == 0 )
47 delete this;
48 return 0;
50 return newCount;
53 //==================================================================================================================
54 //= ColumnResize
55 //==================================================================================================================
56 //------------------------------------------------------------------------------------------------------------------
57 FunctionResult ColumnResize::handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event )
59 Point const aPoint = i_event.GetPosPixel();
61 if ( m_nResizingColumn == COL_INVALID )
63 // if we hit a column divider, change the mosue pointer accordingly
64 Pointer aNewPointer( POINTER_ARROW );
65 TableCell const tableCell = i_tableControl.hitTest( aPoint );
66 if ( ( tableCell.nRow == ROW_COL_HEADERS ) && ( tableCell.eArea == ColumnDivider ) )
68 aNewPointer = Pointer( POINTER_HSPLIT );
70 i_tableControl.setPointer( aNewPointer );
72 return SkipFunction; // TODO: is this correct?
75 ::Size const tableSize = i_tableControl.getTableSizePixel();
77 // set proper pointer
78 Pointer aNewPointer( POINTER_ARROW );
79 ColumnMetrics const & columnMetrics( i_tableControl.getColumnMetrics( m_nResizingColumn ) );
80 if ( ( aPoint.X() > tableSize.Width() )
81 || ( aPoint.X() < columnMetrics.nStartPixel )
84 aNewPointer = Pointer( POINTER_NOTALLOWED );
86 else
88 aNewPointer = Pointer( POINTER_HSPLIT );
90 i_tableControl.setPointer( aNewPointer );
92 // show tracking line
93 i_tableControl.hideTracking();
94 i_tableControl.showTracking(
95 Rectangle(
96 Point( aPoint.X(), 0 ),
97 Size( 1, tableSize.Height() )
99 SHOWTRACK_SPLIT | SHOWTRACK_WINDOW
102 (void)i_event;
103 return ContinueFunction;
106 //------------------------------------------------------------------------------------------------------------------
107 FunctionResult ColumnResize::handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event )
109 if ( m_nResizingColumn != COL_INVALID )
111 OSL_ENSURE( false, "ColumnResize::handleMouseDown: suspicious: MouseButtonDown while still tracking?" );
112 return ContinueFunction;
115 TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
116 if ( tableCell.nRow == ROW_COL_HEADERS )
118 if ( ( tableCell.nColumn != COL_INVALID )
119 && ( tableCell.eArea == ColumnDivider )
122 m_nResizingColumn = tableCell.nColumn;
123 i_tableControl.captureMouse();
124 return ActivateFunction;
128 return SkipFunction;
131 //------------------------------------------------------------------------------------------------------------------
132 FunctionResult ColumnResize::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event )
134 if ( m_nResizingColumn == COL_INVALID )
135 return SkipFunction;
137 Point const aPoint = i_event.GetPosPixel();
139 i_tableControl.hideTracking();
140 PColumnModel const pColumn = i_tableControl.getModel()->getColumnModel( m_nResizingColumn );
141 long const maxWidthLogical = pColumn->getMaxWidth();
142 long const minWidthLogical = pColumn->getMinWidth();
144 // new position of mouse
145 long const requestedEnd = aPoint.X();
147 // old position of right border
148 long const oldEnd = i_tableControl.getColumnMetrics( m_nResizingColumn ).nEndPixel;
150 // position of left border if cursor in the to-be-resized column
151 long const columnStart = i_tableControl.getColumnMetrics( m_nResizingColumn ).nStartPixel;
152 long const requestedWidth = requestedEnd - columnStart;
153 // TODO: this is not correct, strictly: It assumes that the mouse was pressed exactly on the "end" pos,
154 // but for a while now, we have relaxed this, and allow clicking a few pixels aside, too
156 if ( requestedEnd >= columnStart )
158 long requestedWidthLogical = i_tableControl.pixelWidthToAppFont( requestedWidth );
159 // respect column width limits
160 if ( oldEnd > requestedEnd )
162 // column has become smaller, check against minimum width
163 if ( ( minWidthLogical != 0 ) && ( requestedWidthLogical < minWidthLogical ) )
164 requestedWidthLogical = minWidthLogical;
166 else if ( oldEnd < requestedEnd )
168 // column has become larger, check against max width
169 if ( ( maxWidthLogical != 0 ) && ( requestedWidthLogical >= maxWidthLogical ) )
170 requestedWidthLogical = maxWidthLogical;
172 pColumn->setWidth( requestedWidthLogical );
173 i_tableControl.invalidate( TableAreaAll );
176 i_tableControl.setPointer( Pointer() );
177 i_tableControl.releaseMouse();
179 m_nResizingColumn = COL_INVALID;
180 return DeactivateFunction;
183 //==================================================================================================================
184 //= RowSelection
185 //==================================================================================================================
186 //------------------------------------------------------------------------------------------------------------------
187 FunctionResult RowSelection::handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event )
189 OSL_UNUSED( i_tableControl );
190 OSL_UNUSED( i_event );
191 return SkipFunction;
194 //------------------------------------------------------------------------------------------------------------------
195 FunctionResult RowSelection::handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event )
197 bool handled = false;
199 TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
200 if ( tableCell.nRow >= 0 )
202 if ( i_tableControl.getSelEngine()->GetSelectionMode() == NO_SELECTION )
204 i_tableControl.activateCell( tableCell.nColumn, tableCell.nRow );
205 handled = true;
207 else
209 handled = i_tableControl.getSelEngine()->SelMouseButtonDown( i_event );
213 if ( handled )
214 m_bActive = true;
215 return handled ? ActivateFunction : SkipFunction;
218 //------------------------------------------------------------------------------------------------------------------
219 FunctionResult RowSelection::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event )
221 TableCell const tableCell = i_tableControl.hitTest( i_event.GetPosPixel() );
222 if ( tableCell.nRow >= 0 )
224 if ( i_tableControl.getSelEngine()->GetSelectionMode() != NO_SELECTION )
226 i_tableControl.getSelEngine()->SelMouseButtonUp( i_event );
229 if ( m_bActive )
231 m_bActive = false;
232 return DeactivateFunction;
234 return SkipFunction;
237 //==================================================================================================================
238 //= ColumnSortHandler
239 //==================================================================================================================
240 //------------------------------------------------------------------------------------------------------------------
241 FunctionResult ColumnSortHandler::handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event )
243 OSL_UNUSED( i_tableControl );
244 OSL_UNUSED( i_event );
245 return SkipFunction;
248 //------------------------------------------------------------------------------------------------------------------
249 FunctionResult ColumnSortHandler::handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event )
251 if ( m_nActiveColumn != COL_INVALID )
253 OSL_ENSURE( false, "ColumnSortHandler::handleMouseDown: called while already active - suspicious!" );
254 return ContinueFunction;
257 if ( i_tableControl.getModel()->getSortAdapter() == NULL )
258 // no sorting support at the model
259 return SkipFunction;
261 TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
262 if ( ( tableCell.nRow != ROW_COL_HEADERS ) || ( tableCell.nColumn < 0 ) )
263 return SkipFunction;
265 // TODO: ensure the column header is rendered in some special way, indicating its current state
267 m_nActiveColumn = tableCell.nColumn;
268 return ActivateFunction;
271 //------------------------------------------------------------------------------------------------------------------
272 FunctionResult ColumnSortHandler::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event )
274 if ( m_nActiveColumn == COL_INVALID )
275 return SkipFunction;
277 TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) );
278 if ( ( tableCell.nRow == ROW_COL_HEADERS ) && ( tableCell.nColumn == m_nActiveColumn ) )
280 ITableDataSort* pSort = i_tableControl.getModel()->getSortAdapter();
281 ENSURE_OR_RETURN( pSort != NULL, "ColumnSortHandler::handleMouseUp: somebody is mocking with us!", DeactivateFunction );
282 // in handleMousButtonDown, the model claimed to have sort support ...
284 ColumnSortDirection eSortDirection = ColumnSortAscending;
285 ColumnSort const aCurrentSort = pSort->getCurrentSortOrder();
286 if ( aCurrentSort.nColumnPos == m_nActiveColumn )
287 // invert existing sort order
288 eSortDirection = ( aCurrentSort.eSortDirection == ColumnSortAscending ) ? ColumnSortDescending : ColumnSortAscending;
290 pSort->sortByColumn( m_nActiveColumn, eSortDirection );
293 m_nActiveColumn = COL_INVALID;
294 return DeactivateFunction;
297 //......................................................................................................................
298 } } // namespace svt::table
299 //......................................................................................................................
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */