| 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 <controls/table/AccessibleGridControl.hxx> |
| 22 |
#include <controls/table/tablecontrol.hxx> |
| 23 |
#include <controls/table/defaultinputhandler.hxx> |
| 24 |
#include <controls/table/tablemodel.hxx> |
| 25 |
|
| 26 |
#include "tabledatawindow.hxx" |
| 27 |
#include "tablecontrol_impl.hxx" |
| 28 |
#include "tablegeometry.hxx" |
| 29 |
|
| 30 |
#include <com/sun/star/accessibility/XAccessible.hpp> |
| 31 |
#include <com/sun/star/accessibility/AccessibleTableModelChange.hpp> |
| 32 |
#include <com/sun/star/accessibility/AccessibleEventId.hpp> |
| 33 |
#include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp> |
| 34 |
|
| 35 |
#include <comphelper/flagguard.hxx> |
| 36 |
#include <vcl/toolkit/scrbar.hxx> |
| 37 |
#include <vcl/seleng.hxx> |
| 38 |
#include <vcl/settings.hxx> |
| 39 |
#include <vcl/image.hxx> |
| 40 |
#include <comphelper/diagnose_ex.hxx> |
| 41 |
#include <tools/debug.hxx> |
| 42 |
|
| 43 |
#include <cstdlib> |
| 44 |
#include <numeric> |
| 45 |
|
| 46 |
#define MIN_COLUMN_WIDTH_PIXEL 4 |
| 47 |
|
| 48 |
|
| 49 |
namespace svt::table |
| 50 |
{ |
| 51 |
|
| 52 |
|
| 53 |
using ::com::sun::star::accessibility::AccessibleTableModelChange; |
| 54 |
using ::com::sun::star::uno::Any; |
| 55 |
using ::com::sun::star::accessibility::XAccessible; |
| 56 |
using ::com::sun::star::uno::Reference; |
| 57 |
|
| 58 |
namespace AccessibleEventId = css::accessibility::AccessibleEventId; |
| 59 |
namespace AccessibleTableModelChangeType = css::accessibility::AccessibleTableModelChangeType; |
| 60 |
|
| 61 |
|
| 62 |
//= SuppressCursor |
| 63 |
|
| 64 |
namespace { |
| 65 |
|
| 66 |
class SuppressCursor |
| 67 |
{ |
| 68 |
private: |
| 69 |
ITableControl& m_rTable; |
| 70 |
|
| 71 |
public: |
| 72 |
explicit SuppressCursor( ITableControl& _rTable ) |
| 73 |
:m_rTable( _rTable ) |
| 74 |
{ |
| 75 |
m_rTable.hideCursor(); |
| 76 |
} |
| 77 |
~SuppressCursor() |
| 78 |
{ |
| 79 |
m_rTable.showCursor(); |
| 80 |
} |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
//= EmptyTableModel |
| 85 |
|
| 86 |
/** default implementation of an ->ITableModel, used as fallback when no |
| 87 |
real model is present |
| 88 |
|
| 89 |
Instances of this class are static in any way, and provide the least |
| 90 |
necessary default functionality for a table model. |
| 91 |
*/ |
| 92 |
class EmptyTableModel : public ITableModel |
| 93 |
{ |
| 94 |
public: |
| 95 |
EmptyTableModel() |
| 96 |
{ |
| 97 |
} |
| 98 |
|
| 99 |
// ITableModel overridables |
| 100 |
virtual TableSize getColumnCount() const override |
| 101 |
{ |
| 102 |
return 0; |
| 103 |
} |
| 104 |
virtual TableSize getRowCount() const override |
| 105 |
{ |
| 106 |
return 0; |
| 107 |
} |
| 108 |
virtual bool hasColumnHeaders() const override |
| 109 |
{ |
| 110 |
return false; |
| 111 |
} |
| 112 |
virtual bool hasRowHeaders() const override |
| 113 |
{ |
| 114 |
return false; |
| 115 |
} |
| 116 |
virtual PColumnModel getColumnModel( ColPos ) override |
| 117 |
{ |
| 118 |
OSL_FAIL( "EmptyTableModel::getColumnModel: invalid call!" ); |
| 119 |
return PColumnModel(); |
| 120 |
} |
| 121 |
virtual PTableRenderer getRenderer() const override |
| 122 |
{ |
| 123 |
return PTableRenderer(); |
| 124 |
} |
| 125 |
virtual PTableInputHandler getInputHandler() const override |
| 126 |
{ |
| 127 |
return PTableInputHandler(); |
| 128 |
} |
| 129 |
virtual TableMetrics getRowHeight() const override |
| 130 |
{ |
| 131 |
return 5 * 100; |
| 132 |
} |
| 133 |
virtual TableMetrics getColumnHeaderHeight() const override |
| 134 |
{ |
| 135 |
return 0; |
| 136 |
} |
| 137 |
virtual TableMetrics getRowHeaderWidth() const override |
| 138 |
{ |
| 139 |
return 0; |
| 140 |
} |
| 141 |
virtual ScrollbarVisibility getVerticalScrollbarVisibility() const override |
| 142 |
{ |
| 143 |
return ScrollbarShowNever; |
| 144 |
} |
| 145 |
virtual ScrollbarVisibility getHorizontalScrollbarVisibility() const override |
| 146 |
{ |
| 147 |
return ScrollbarShowNever; |
| 148 |
} |
| 149 |
virtual void addTableModelListener( const PTableModelListener& ) override {} |
| 150 |
virtual void removeTableModelListener( const PTableModelListener& ) override {} |
| 151 |
virtual ::std::optional< ::Color > getLineColor() const override |
| 152 |
{ |
| 153 |
return ::std::optional< ::Color >(); |
| 154 |
} |
| 155 |
virtual ::std::optional< ::Color > getHeaderBackgroundColor() const override |
| 156 |
{ |
| 157 |
return ::std::optional< ::Color >(); |
| 158 |
} |
| 159 |
virtual ::std::optional< ::Color > getHeaderTextColor() const override |
| 160 |
{ |
| 161 |
return ::std::optional< ::Color >(); |
| 162 |
} |
| 163 |
virtual ::std::optional< ::Color > getActiveSelectionBackColor() const override |
| 164 |
{ |
| 165 |
return ::std::optional< ::Color >(); |
| 166 |
} |
| 167 |
virtual ::std::optional< ::Color > getInactiveSelectionBackColor() const override |
| 168 |
{ |
| 169 |
return ::std::optional< ::Color >(); |
| 170 |
} |
| 171 |
virtual ::std::optional< ::Color > getActiveSelectionTextColor() const override |
| 172 |
{ |
| 173 |
return ::std::optional< ::Color >(); |
| 174 |
} |
| 175 |
virtual ::std::optional< ::Color > getInactiveSelectionTextColor() const override |
| 176 |
{ |
| 177 |
return ::std::optional< ::Color >(); |
| 178 |
} |
| 179 |
virtual ::std::optional< ::Color > getTextColor() const override |
| 180 |
{ |
| 181 |
return ::std::optional< ::Color >(); |
| 182 |
} |
| 183 |
virtual ::std::optional< ::Color > getTextLineColor() const override |
| 184 |
{ |
| 185 |
return ::std::optional< ::Color >(); |
| 186 |
} |
| 187 |
virtual ::std::optional< ::std::vector< ::Color > > getRowBackgroundColors() const override |
| 188 |
{ |
| 189 |
return ::std::optional< ::std::vector< ::Color > >(); |
| 190 |
} |
| 191 |
virtual css::style::VerticalAlignment getVerticalAlign() const override |
| 192 |
{ |
| 193 |
return css::style::VerticalAlignment(0); |
| 194 |
} |
| 195 |
virtual ITableDataSort* getSortAdapter() override |
| 196 |
{ |
| 197 |
return nullptr; |
| 198 |
} |
| 199 |
virtual bool isEnabled() const override |
| 200 |
{ |
| 201 |
return true; |
| 202 |
} |
| 203 |
virtual void getCellContent( ColPos const, RowPos const, css::uno::Any& o_cellContent ) override |
| 204 |
{ |
| 205 |
o_cellContent.clear(); |
| 206 |
} |
| 207 |
virtual void getCellToolTip( ColPos const, RowPos const, css::uno::Any& ) override |
| 208 |
{ |
| 209 |
} |
| 210 |
virtual Any getRowHeading( RowPos const ) const override |
| 211 |
{ |
| 212 |
return Any(); |
| 213 |
} |
| 214 |
}; |
| 215 |
|
| 216 |
} |
| 217 |
|
| 218 |
TableControl_Impl::TableControl_Impl( TableControl& _rAntiImpl ) |
| 219 |
:m_rAntiImpl ( _rAntiImpl ) |
| 220 |
,m_pModel ( std::make_shared<EmptyTableModel>() ) |
| 221 |
,m_pInputHandler ( ) |
| 222 |
,m_nRowHeightPixel ( 15 ) |
| 223 |
,m_nColHeaderHeightPixel( 0 ) |
| 224 |
,m_nRowHeaderWidthPixel ( 0 ) |
| 225 |
,m_nColumnCount ( 0 ) |
| 226 |
,m_nRowCount ( 0 ) |
| 227 |
,m_nCurColumn ( COL_INVALID ) |
| 228 |
,m_nCurRow ( ROW_INVALID ) |
| 229 |
,m_nLeftColumn ( 0 ) |
| 230 |
,m_nTopRow ( 0 ) |
| 231 |
,m_nCursorHidden ( 1 ) |
| 232 |
,m_pDataWindow ( VclPtr<TableDataWindow>::Create( *this ) ) |
| 233 |
,m_pVScroll ( nullptr ) |
| 234 |
,m_pHScroll ( nullptr ) |
| 235 |
,m_pScrollCorner ( nullptr ) |
| 236 |
,m_aSelectedRows ( ) |
| 237 |
,m_pTableFunctionSet ( new TableFunctionSet( this ) ) |
| 238 |
,m_nAnchor ( -1 ) |
| 239 |
,m_bUpdatingColWidths ( false ) |
| 240 |
{ |
| 241 |
m_pSelEngine.reset( new SelectionEngine( m_pDataWindow.get(), m_pTableFunctionSet.get() ) ); |
| 242 |
m_pSelEngine->SetSelectionMode(SelectionMode::Single); |
| 243 |
m_pDataWindow->SetPosPixel( Point( 0, 0 ) ); |
| 244 |
m_pDataWindow->Show(); |
| 245 |
} |
| 246 |
|
| 247 |
TableControl_Impl::~TableControl_Impl() |
| 248 |
{ |
| 249 |
m_pVScroll.disposeAndClear(); |
| 250 |
m_pHScroll.disposeAndClear(); |
| 251 |
m_pScrollCorner.disposeAndClear(); |
| 252 |
m_pDataWindow.disposeAndClear(); |
| 253 |
m_pTableFunctionSet.reset(); |
| 254 |
m_pSelEngine.reset(); |
| 255 |
} |
| 256 |
|
| 257 |
void TableControl_Impl::setModel( const PTableModel& _pModel ) |
| 258 |
{ |
| 259 |
SuppressCursor aHideCursor( *this ); |
| 260 |
|
| 261 |
if ( m_pModel ) |
| 262 |
m_pModel->removeTableModelListener( shared_from_this() ); |
| 263 |
|
| 264 |
m_pModel = _pModel; |
| 265 |
if ( !m_pModel) |
| 266 |
m_pModel = std::make_shared<EmptyTableModel>(); |
| 267 |
|
| 268 |
m_pModel->addTableModelListener( shared_from_this() ); |
| 269 |
|
| 270 |
m_nCurRow = ROW_INVALID; |
| 271 |
m_nCurColumn = COL_INVALID; |
| 272 |
|
| 273 |
// recalc some model-dependent cached info |
| 274 |
impl_ni_updateCachedModelValues(); |
| 275 |
impl_ni_relayout(); |
| 276 |
|
| 277 |
// completely invalidate |
| 278 |
m_rAntiImpl.Invalidate(); |
| 279 |
|
| 280 |
// reset cursor to (0,0) |
| 281 |
if ( m_nRowCount ) m_nCurRow = 0; |
| 282 |
if ( m_nColumnCount ) m_nCurColumn = 0; |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
namespace |
| 287 |
{ |
| 288 |
bool lcl_adjustSelectedRows( ::std::vector< RowPos >& io_selectionIndexes, RowPos const i_firstAffectedRowIndex, TableSize const i_offset ) |
| 289 |
{ |
| 290 |
bool didChanges = false; |
| 291 |
for (auto & selectionIndex : io_selectionIndexes) |
| 292 |
{ |
| 293 |
if ( selectionIndex < i_firstAffectedRowIndex ) |
| 294 |
continue; |
| 295 |
selectionIndex += i_offset; |
| 296 |
didChanges = true; |
| 297 |
} |
| 298 |
return didChanges; |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
void TableControl_Impl::rowsInserted( RowPos i_first, RowPos i_last ) |
| 304 |
{ |
| 305 |
OSL_PRECOND( i_last >= i_first, "TableControl_Impl::rowsInserted: invalid row indexes!" ); |
| 306 |
|
| 307 |
TableSize const insertedRows = i_last - i_first + 1; |
| 308 |
|
| 309 |
// adjust selection, if necessary |
| 310 |
bool const selectionChanged = lcl_adjustSelectedRows( m_aSelectedRows, i_first, insertedRows ); |
| 311 |
|
| 312 |
// adjust our cached row count |
| 313 |
m_nRowCount = m_pModel->getRowCount(); |
| 314 |
|
| 315 |
// if the rows have been inserted before the current row, adjust this |
| 316 |
if ( i_first <= m_nCurRow ) |
| 317 |
goTo( m_nCurColumn, m_nCurRow + insertedRows ); |
| 318 |
|
| 319 |
// relayout, since the scrollbar need might have changed |
| 320 |
impl_ni_relayout(); |
| 321 |
|
| 322 |
// notify A1YY events |
| 323 |
impl_commitAccessibleEvent( |
| 324 |
AccessibleEventId::TABLE_MODEL_CHANGED, |
| 325 |
Any(AccessibleTableModelChange(AccessibleTableModelChangeType::ROWS_INSERTED, i_first, |
| 326 |
i_last, -1, -1))); |
| 327 |
|
| 328 |
// schedule repaint |
| 329 |
invalidateRowRange( i_first, ROW_INVALID ); |
| 330 |
|
| 331 |
// call selection handlers, if necessary |
| 332 |
if ( selectionChanged ) |
| 333 |
m_rAntiImpl.Select(); |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
void TableControl_Impl::rowsRemoved( RowPos i_first, RowPos i_last ) |
| 338 |
{ |
| 339 |
sal_Int32 firstRemovedRow = i_first; |
| 340 |
sal_Int32 lastRemovedRow = i_last; |
| 341 |
|
| 342 |
// adjust selection, if necessary |
| 343 |
bool selectionChanged = false; |
| 344 |
if ( i_first == -1 ) |
| 345 |
{ |
| 346 |
selectionChanged = markAllRowsAsDeselected(); |
| 347 |
|
| 348 |
firstRemovedRow = 0; |
| 349 |
lastRemovedRow = m_nRowCount - 1; |
| 350 |
} |
| 351 |
else |
| 352 |
{ |
| 353 |
ENSURE_OR_RETURN_VOID( i_last >= i_first, "TableControl_Impl::rowsRemoved: illegal indexes!" ); |
| 354 |
|
| 355 |
for ( sal_Int32 row = i_first; row <= i_last; ++row ) |
| 356 |
{ |
| 357 |
if ( markRowAsDeselected( row ) ) |
| 358 |
selectionChanged = true; |
| 359 |
} |
| 360 |
|
| 361 |
if ( lcl_adjustSelectedRows( m_aSelectedRows, i_last + 1, i_first - i_last - 1 ) ) |
| 362 |
selectionChanged = true; |
| 363 |
} |
| 364 |
|
| 365 |
// adjust cached row count |
| 366 |
m_nRowCount = m_pModel->getRowCount(); |
| 367 |
|
| 368 |
// adjust the current row, if it is larger than the row count now |
| 369 |
if ( m_nCurRow >= m_nRowCount ) |
| 370 |
{ |
| 371 |
if ( m_nRowCount > 0 ) |
| 372 |
goTo( m_nCurColumn, m_nRowCount - 1 ); |
| 373 |
else |
| 374 |
{ |
| 375 |
m_nCurRow = ROW_INVALID; |
| 376 |
m_nTopRow = 0; |
| 377 |
} |
| 378 |
} |
| 379 |
else if ( m_nRowCount == 0 ) |
| 380 |
{ |
| 381 |
m_nTopRow = 0; |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
// relayout, since the scrollbar need might have changed |
| 386 |
impl_ni_relayout(); |
| 387 |
|
| 388 |
// notify A11Y events |
| 389 |
commitTableEvent( |
| 390 |
AccessibleEventId::TABLE_MODEL_CHANGED, |
| 391 |
Any(AccessibleTableModelChange(AccessibleTableModelChangeType::ROWS_REMOVED, |
| 392 |
firstRemovedRow, lastRemovedRow, -1, -1)), |
| 393 |
Any()); |
| 394 |
|
| 395 |
// schedule a repaint |
| 396 |
invalidateRowRange( firstRemovedRow, ROW_INVALID ); |
| 397 |
|
| 398 |
// call selection handlers, if necessary |
| 399 |
if ( selectionChanged ) |
| 400 |
m_rAntiImpl.Select(); |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
void TableControl_Impl::columnInserted() |
| 405 |
{ |
| 406 |
m_nColumnCount = m_pModel->getColumnCount(); |
| 407 |
impl_ni_relayout(); |
| 408 |
|
| 409 |
m_rAntiImpl.Invalidate(); |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
void TableControl_Impl::columnRemoved() |
| 414 |
{ |
| 415 |
m_nColumnCount = m_pModel->getColumnCount(); |
| 416 |
|
| 417 |
// adjust the current column, if it is larger than the column count now |
| 418 |
if ( m_nCurColumn >= m_nColumnCount ) |
| 419 |
{ |
| 420 |
if ( m_nColumnCount > 0 ) |
| 421 |
goTo( m_nCurColumn - 1, m_nCurRow ); |
| 422 |
else |
| 423 |
m_nCurColumn = COL_INVALID; |
| 424 |
} |
| 425 |
|
| 426 |
impl_ni_relayout(); |
| 427 |
|
| 428 |
m_rAntiImpl.Invalidate(); |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
void TableControl_Impl::allColumnsRemoved() |
| 433 |
{ |
| 434 |
m_nColumnCount = m_pModel->getColumnCount(); |
| 435 |
impl_ni_relayout(); |
| 436 |
|
| 437 |
m_rAntiImpl.Invalidate(); |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
void TableControl_Impl::cellsUpdated( RowPos const i_firstRow, RowPos const i_lastRow ) |
| 442 |
{ |
| 443 |
invalidateRowRange( i_firstRow, i_lastRow ); |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
void TableControl_Impl::tableMetricsChanged() |
| 448 |
{ |
| 449 |
impl_ni_updateCachedTableMetrics(); |
| 450 |
impl_ni_relayout(); |
| 451 |
m_rAntiImpl.Invalidate(); |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
void TableControl_Impl::impl_invalidateColumn( ColPos const i_column ) |
| 456 |
{ |
| 457 |
tools::Rectangle const aAllCellsArea( impl_getAllVisibleCellsArea() ); |
| 458 |
|
| 459 |
const TableColumnGeometry aColumn( *this, aAllCellsArea, i_column ); |
| 460 |
if ( aColumn.isValid() ) |
| 461 |
m_rAntiImpl.Invalidate( aColumn.getRect() ); |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
void TableControl_Impl::columnChanged( ColPos const i_column, ColumnAttributeGroup const i_attributeGroup ) |
| 466 |
{ |
| 467 |
ColumnAttributeGroup nGroup( i_attributeGroup ); |
| 468 |
if ( nGroup & ColumnAttributeGroup::APPEARANCE ) |
| 469 |
{ |
| 470 |
impl_invalidateColumn( i_column ); |
| 471 |
nGroup &= ~ColumnAttributeGroup::APPEARANCE; |
| 472 |
} |
| 473 |
|
| 474 |
if ( nGroup & ColumnAttributeGroup::WIDTH ) |
| 475 |
{ |
| 476 |
if ( !m_bUpdatingColWidths ) |
| 477 |
{ |
| 478 |
impl_ni_relayout( i_column ); |
| 479 |
invalidate( TableArea::All ); |
| 480 |
} |
| 481 |
|
| 482 |
nGroup &= ~ColumnAttributeGroup::WIDTH; |
| 483 |
} |
| 484 |
|
| 485 |
OSL_ENSURE( ( nGroup == ColumnAttributeGroup::NONE ) || ( i_attributeGroup == ColumnAttributeGroup::ALL ), |
| 486 |
"TableControl_Impl::columnChanged: don't know how to handle this change!" ); |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
tools::Rectangle TableControl_Impl::impl_getAllVisibleCellsArea() const |
| 491 |
{ |
| 492 |
tools::Rectangle aArea( Point( 0, 0 ), Size( 0, 0 ) ); |
| 493 |
|
| 494 |
// determine the right-most border of the last column which is |
| 495 |
// at least partially visible |
| 496 |
aArea.SetRight( m_nRowHeaderWidthPixel ); |
| 497 |
if ( !m_aColumnWidths.empty() ) |
| 498 |
{ |
| 499 |
// the number of pixels which are scrolled out of the left hand |
| 500 |
// side of the window |
| 501 |
const tools::Long nScrolledOutLeft = m_nLeftColumn == 0 ? 0 : m_aColumnWidths[ m_nLeftColumn - 1 ].getEnd(); |
| 502 |
|
| 503 |
ColumnPositions::const_reverse_iterator loop = m_aColumnWidths.rbegin(); |
| 504 |
do |
| 505 |
{ |
| 506 |
aArea.SetRight(loop->getEnd() - nScrolledOutLeft); |
| 507 |
++loop; |
| 508 |
} |
| 509 |
while ( ( loop != m_aColumnWidths.rend() ) |
| 510 |
&& ( loop->getEnd() - nScrolledOutLeft >= aArea.Right() ) |
| 511 |
); |
| 512 |
} |
| 513 |
// so far, aArea.Right() denotes the first pixel *after* the cell area |
| 514 |
aArea.AdjustRight( -1 ); |
| 515 |
|
| 516 |
// determine the last row which is at least partially visible |
| 517 |
aArea.SetBottom( |
| 518 |
m_nColHeaderHeightPixel |
| 519 |
+ impl_getVisibleRows( true ) * m_nRowHeightPixel |
| 520 |
- 1 ); |
| 521 |
|
| 522 |
return aArea; |
| 523 |
} |
| 524 |
|
| 525 |
|
| 526 |
tools::Rectangle TableControl_Impl::impl_getAllVisibleDataCellArea() const |
| 527 |
{ |
| 528 |
tools::Rectangle aArea( impl_getAllVisibleCellsArea() ); |
| 529 |
aArea.SetLeft( m_nRowHeaderWidthPixel ); |
| 530 |
aArea.SetTop( m_nColHeaderHeightPixel ); |
| 531 |
return aArea; |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
void TableControl_Impl::impl_ni_updateCachedTableMetrics() |
| 536 |
{ |
| 537 |
m_nRowHeightPixel = m_rAntiImpl.LogicToPixel(Size(0, m_pModel->getRowHeight()), MapMode(MapUnit::MapAppFont)).Height(); |
| 538 |
|
| 539 |
m_nColHeaderHeightPixel = 0; |
| 540 |
if ( m_pModel->hasColumnHeaders() ) |
| 541 |
m_nColHeaderHeightPixel = m_rAntiImpl.LogicToPixel(Size(0, m_pModel->getColumnHeaderHeight()), MapMode(MapUnit::MapAppFont)).Height(); |
| 542 |
|
| 543 |
m_nRowHeaderWidthPixel = 0; |
| 544 |
if ( m_pModel->hasRowHeaders() ) |
| 545 |
m_nRowHeaderWidthPixel = m_rAntiImpl.LogicToPixel(Size(m_pModel->getRowHeaderWidth(), 0), MapMode(MapUnit::MapAppFont)).Width(); |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
void TableControl_Impl::impl_ni_updateCachedModelValues() |
| 550 |
{ |
| 551 |
m_pInputHandler = m_pModel->getInputHandler(); |
| 552 |
if ( !m_pInputHandler ) |
| 553 |
m_pInputHandler = std::make_shared<DefaultInputHandler>(); |
| 554 |
|
| 555 |
m_nColumnCount = m_pModel->getColumnCount(); |
| 556 |
if ( m_nLeftColumn >= m_nColumnCount ) |
| 557 |
m_nLeftColumn = ( m_nColumnCount > 0 ) ? m_nColumnCount - 1 : 0; |
| 558 |
|
| 559 |
m_nRowCount = m_pModel->getRowCount(); |
| 560 |
if ( m_nTopRow >= m_nRowCount ) |
| 561 |
m_nTopRow = ( m_nRowCount > 0 ) ? m_nRowCount - 1 : 0; |
| 562 |
|
| 563 |
impl_ni_updateCachedTableMetrics(); |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
namespace |
| 568 |
{ |
| 569 |
|
| 570 |
/// determines whether a scrollbar is needed for the given values |
| 571 |
bool lcl_determineScrollbarNeed( tools::Long const i_position, ScrollbarVisibility const i_visibility, |
| 572 |
tools::Long const i_availableSpace, tools::Long const i_neededSpace ) |
| 573 |
{ |
| 574 |
if ( i_visibility == ScrollbarShowNever ) |
| 575 |
return false; |
| 576 |
if ( i_visibility == ScrollbarShowAlways ) |
| 577 |
return true; |
| 578 |
if ( i_position > 0 ) |
| 579 |
return true; |
| 580 |
if ( i_availableSpace >= i_neededSpace ) |
| 581 |
return false; |
| 582 |
return true; |
| 583 |
} |
| 584 |
|
| 585 |
|
| 586 |
void lcl_setButtonRepeat( vcl::Window& _rWindow ) |
| 587 |
{ |
| 588 |
AllSettings aSettings = _rWindow.GetSettings(); |
| 589 |
MouseSettings aMouseSettings = aSettings.GetMouseSettings(); |
| 590 |
|
| 591 |
aMouseSettings.SetButtonRepeat( 0 ); |
| 592 |
aSettings.SetMouseSettings( aMouseSettings ); |
| 593 |
|
| 594 |
_rWindow.SetSettings( aSettings, true ); |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
bool lcl_updateScrollbar( vcl::Window& _rParent, VclPtr<ScrollBar>& _rpBar, |
| 599 |
bool const i_needBar, tools::Long _nVisibleUnits, |
| 600 |
tools::Long _nPosition, tools::Long _nRange, |
| 601 |
bool _bHorizontal, const Link<ScrollBar*,void>& _rScrollHandler ) |
| 602 |
{ |
| 603 |
// do we currently have the scrollbar? |
| 604 |
bool bHaveBar = _rpBar != nullptr; |
| 605 |
|
| 606 |
// do we need to correct the scrollbar visibility? |
| 607 |
if ( bHaveBar && !i_needBar ) |
| 608 |
{ |
| 609 |
if ( _rpBar->IsTracking() ) |
| 610 |
_rpBar->EndTracking(); |
| 611 |
_rpBar.disposeAndClear(); |
| 612 |
} |
| 613 |
else if ( !bHaveBar && i_needBar ) |
| 614 |
{ |
| 615 |
_rpBar = VclPtr<ScrollBar>::Create( |
| 616 |
|
| 617 |
&_rParent, |
| 618 |
WB_DRAG | ( _bHorizontal ? WB_HSCROLL : WB_VSCROLL ) |
| 619 |
); |
| 620 |
_rpBar->SetScrollHdl( _rScrollHandler ); |
| 621 |
// get some speed into the scrolling... |
| 622 |
lcl_setButtonRepeat( *_rpBar ); |
| 623 |
} |
| 624 |
|
| 625 |
if ( _rpBar ) |
| 626 |
{ |
| 627 |
_rpBar->SetRange( Range( 0, _nRange ) ); |
| 628 |
_rpBar->SetVisibleSize( _nVisibleUnits ); |
| 629 |
_rpBar->SetPageSize( _nVisibleUnits ); |
| 630 |
_rpBar->SetLineSize( 1 ); |
| 631 |
_rpBar->SetThumbPos( _nPosition ); |
| 632 |
_rpBar->Show(); |
| 633 |
} |
| 634 |
|
| 635 |
return ( bHaveBar != i_needBar ); |
| 636 |
} |
| 637 |
|
| 638 |
|
| 639 |
/** returns the number of rows fitting into the given range, |
| 640 |
for the given row height. Partially fitting rows are counted, too, if the |
| 641 |
respective parameter says so. |
| 642 |
*/ |
| 643 |
TableSize lcl_getRowsFittingInto( tools::Long _nOverallHeight, tools::Long _nRowHeightPixel, bool _bAcceptPartialRow ) |
| 644 |
{ |
| 645 |
return _bAcceptPartialRow |
| 646 |
? ( _nOverallHeight + ( _nRowHeightPixel - 1 ) ) / _nRowHeightPixel |
| 647 |
: _nOverallHeight / _nRowHeightPixel; |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
/** returns the number of columns fitting into the given area, |
| 652 |
with the first visible column as given. Partially fitting columns are counted, too, |
| 653 |
if the respective parameter says so. |
| 654 |
*/ |
| 655 |
TableSize lcl_getColumnsVisibleWithin( const tools::Rectangle& _rArea, ColPos _nFirstVisibleColumn, |
| 656 |
const TableControl_Impl& _rControl, bool _bAcceptPartialRow ) |
| 657 |
{ |
| 658 |
TableSize visibleColumns = 0; |
| 659 |
TableColumnGeometry aColumn( _rControl, _rArea, _nFirstVisibleColumn ); |
| 660 |
while ( aColumn.isValid() ) |
| 661 |
{ |
| 662 |
if ( !_bAcceptPartialRow ) |
| 663 |
if ( aColumn.getRect().Right() > _rArea.Right() ) |
| 664 |
// this column is only partially visible, and this is not allowed |
| 665 |
break; |
| 666 |
|
| 667 |
aColumn.moveRight(); |
| 668 |
++visibleColumns; |
| 669 |
} |
| 670 |
return visibleColumns; |
| 671 |
} |
| 672 |
|
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
tools::Long TableControl_Impl::impl_ni_calculateColumnWidths( ColPos const i_assumeInflexibleColumnsUpToIncluding, |
| 677 |
bool const i_assumeVerticalScrollbar, ::std::vector< tools::Long >& o_newColWidthsPixel ) const |
| 678 |
{ |
| 679 |
// the available horizontal space |
| 680 |
tools::Long gridWidthPixel = m_rAntiImpl.GetOutputSizePixel().Width(); |
| 681 |
ENSURE_OR_RETURN( !!m_pModel, "TableControl_Impl::impl_ni_calculateColumnWidths: not allowed without a model!", gridWidthPixel ); |
| 682 |
if ( m_pModel->hasRowHeaders() && ( gridWidthPixel != 0 ) ) |
| 683 |
{ |
| 684 |
gridWidthPixel -= m_nRowHeaderWidthPixel; |
| 685 |
} |
| 686 |
|
| 687 |
if ( i_assumeVerticalScrollbar && ( m_pModel->getVerticalScrollbarVisibility() != ScrollbarShowNever ) ) |
| 688 |
{ |
| 689 |
tools::Long nScrollbarMetrics = m_rAntiImpl.GetSettings().GetStyleSettings().GetScrollBarSize(); |
| 690 |
gridWidthPixel -= nScrollbarMetrics; |
| 691 |
} |
| 692 |
|
| 693 |
// no need to do anything without columns |
| 694 |
TableSize const colCount = m_pModel->getColumnCount(); |
| 695 |
if ( colCount == 0 ) |
| 696 |
return gridWidthPixel; |
| 697 |
|
| 698 |
// collect some meta data for our columns: |
| 699 |
// - their current (pixel) metrics |
| 700 |
tools::Long accumulatedCurrentWidth = 0; |
| 701 |
::std::vector< tools::Long > currentColWidths; |
| 702 |
currentColWidths.reserve( colCount ); |
| 703 |
typedef ::std::vector< ::std::pair< tools::Long, long > > ColumnLimits; |
| 704 |
ColumnLimits effectiveColumnLimits; |
| 705 |
effectiveColumnLimits.reserve( colCount ); |
| 706 |
tools::Long accumulatedMinWidth = 0; |
| 707 |
tools::Long accumulatedMaxWidth = 0; |
| 708 |
// - their relative flexibility |
| 709 |
::std::vector< ::sal_Int32 > columnFlexibilities; |
| 710 |
columnFlexibilities.reserve( colCount ); |
| 711 |
tools::Long flexibilityDenominator = 0; |
| 712 |
size_t flexibleColumnCount = 0; |
| 713 |
for ( ColPos col = 0; col < colCount; ++col ) |
| 714 |
{ |
| 715 |
PColumnModel const pColumn = m_pModel->getColumnModel( col ); |
| 716 |
ENSURE_OR_THROW( !!pColumn, "invalid column returned by the model!" ); |
| 717 |
|
| 718 |
// current width |
| 719 |
tools::Long const currentWidth = appFontWidthToPixel( pColumn->getWidth() ); |
| 720 |
currentColWidths.push_back( currentWidth ); |
| 721 |
|
| 722 |
// accumulated width |
| 723 |
accumulatedCurrentWidth += currentWidth; |
| 724 |
|
| 725 |
// flexibility |
| 726 |
::sal_Int32 flexibility = pColumn->getFlexibility(); |
| 727 |
OSL_ENSURE( flexibility >= 0, "TableControl_Impl::impl_ni_calculateColumnWidths: a column's flexibility should be non-negative." ); |
| 728 |
if ( ( flexibility < 0 ) // normalization |
| 729 |
|| ( !pColumn->isResizable() ) // column not resizable => no auto-resize |
| 730 |
|| ( col <= i_assumeInflexibleColumnsUpToIncluding ) // column shall be treated as inflexible => respect this |
| 731 |
) |
| 732 |
flexibility = 0; |
| 733 |
|
| 734 |
// min/max width |
| 735 |
tools::Long effectiveMin = currentWidth, effectiveMax = currentWidth; |
| 736 |
// if the column is not flexible, it will not be asked for min/max, but we assume the current width as limit then |
| 737 |
if ( flexibility > 0 ) |
| 738 |
{ |
| 739 |
tools::Long const minWidth = appFontWidthToPixel( pColumn->getMinWidth() ); |
| 740 |
if ( minWidth > 0 ) |
| 741 |
effectiveMin = minWidth; |
| 742 |
else |
| 743 |
effectiveMin = MIN_COLUMN_WIDTH_PIXEL; |
| 744 |
|
| 745 |
tools::Long const maxWidth = appFontWidthToPixel( pColumn->getMaxWidth() ); |
| 746 |
OSL_ENSURE( minWidth <= maxWidth, "TableControl_Impl::impl_ni_calculateColumnWidths: pretty undecided 'bout its width limits, this column!" ); |
| 747 |
if ( ( maxWidth > 0 ) && ( maxWidth >= minWidth ) ) |
| 748 |
effectiveMax = maxWidth; |
| 749 |
else |
| 750 |
effectiveMax = gridWidthPixel; // TODO: any better guess here? |
| 751 |
|
| 752 |
if ( effectiveMin == effectiveMax ) |
| 753 |
// if the min and the max are identical, this implies no flexibility at all |
| 754 |
flexibility = 0; |
| 755 |
} |
| 756 |
|
| 757 |
columnFlexibilities.push_back( flexibility ); |
| 758 |
flexibilityDenominator += flexibility; |
| 759 |
if ( flexibility > 0 ) |
| 760 |
++flexibleColumnCount; |
| 761 |
|
| 762 |
effectiveColumnLimits.emplace_back( effectiveMin, effectiveMax ); |
| 763 |
accumulatedMinWidth += effectiveMin; |
| 764 |
accumulatedMaxWidth += effectiveMax; |
| 765 |
} |
| 766 |
|
| 767 |
o_newColWidthsPixel = currentColWidths; |
| 768 |
if ( flexibilityDenominator == 0 ) |
| 769 |
{ |
| 770 |
// no column is flexible => don't adjust anything |
| 771 |
} |
| 772 |
else if ( gridWidthPixel > accumulatedCurrentWidth ) |
| 773 |
{ // we have space to give away ... |
| 774 |
tools::Long distributePixel = gridWidthPixel - accumulatedCurrentWidth; |
| 775 |
if ( gridWidthPixel > accumulatedMaxWidth ) |
| 776 |
{ |
| 777 |
// ... but the column's maximal widths are still less than we have |
| 778 |
// => set them all to max |
| 779 |
for ( svt::table::TableSize i = 0; i < colCount; ++i ) |
| 780 |
{ |
| 781 |
o_newColWidthsPixel[i] = effectiveColumnLimits[i].second; |
| 782 |
} |
| 783 |
} |
| 784 |
else |
| 785 |
{ |
| 786 |
bool startOver = false; |
| 787 |
do |
| 788 |
{ |
| 789 |
startOver = false; |
| 790 |
// distribute the remaining space amongst all columns with a positive flexibility |
| 791 |
for ( size_t i=0; i<o_newColWidthsPixel.size() && !startOver; ++i ) |
| 792 |
{ |
| 793 |
tools::Long const columnFlexibility = columnFlexibilities[i]; |
| 794 |
if ( columnFlexibility == 0 ) |
| 795 |
continue; |
| 796 |
|
| 797 |
tools::Long newColWidth = currentColWidths[i] + columnFlexibility * distributePixel / flexibilityDenominator; |
| 798 |
|
| 799 |
if ( newColWidth > effectiveColumnLimits[i].second ) |
| 800 |
{ // that was too much, we hit the col's maximum |
| 801 |
// set the new width to exactly this maximum |
| 802 |
newColWidth = effectiveColumnLimits[i].second; |
| 803 |
// adjust the flexibility denominator ... |
| 804 |
flexibilityDenominator -= columnFlexibility; |
| 805 |
columnFlexibilities[i] = 0; |
| 806 |
--flexibleColumnCount; |
| 807 |
// ... and the remaining width ... |
| 808 |
tools::Long const difference = newColWidth - currentColWidths[i]; |
| 809 |
distributePixel -= difference; |
| 810 |
// ... this way, we ensure that the width not taken up by this column is consumed by the other |
| 811 |
// flexible ones (if there are some) |
| 812 |
|
| 813 |
// and start over with the first column, since there might be earlier columns which need |
| 814 |
// to be recalculated now |
| 815 |
startOver = true; |
| 816 |
} |
| 817 |
|
| 818 |
o_newColWidthsPixel[i] = newColWidth; |
| 819 |
} |
| 820 |
} |
| 821 |
while ( startOver ); |
| 822 |
|
| 823 |
// are there pixels left (might be caused by rounding errors)? |
| 824 |
distributePixel = gridWidthPixel - ::std::accumulate( o_newColWidthsPixel.begin(), o_newColWidthsPixel.end(), 0 ); |
| 825 |
while ( ( distributePixel > 0 ) && ( flexibleColumnCount > 0 ) ) |
| 826 |
{ |
| 827 |
// yes => ignore relative flexibilities, and subsequently distribute single pixels to all flexible |
| 828 |
// columns which did not yet reach their maximum. |
| 829 |
for ( size_t i=0; ( i < o_newColWidthsPixel.size() ) && ( distributePixel > 0 ); ++i ) |
| 830 |
{ |
| 831 |
if ( columnFlexibilities[i] == 0 ) |
| 832 |
continue; |
| 833 |
|
| 834 |
OSL_ENSURE( o_newColWidthsPixel[i] <= effectiveColumnLimits[i].second, |
| 835 |
"TableControl_Impl::impl_ni_calculateColumnWidths: inconsistency!" ); |
| 836 |
if ( o_newColWidthsPixel[i] >= effectiveColumnLimits[i].first ) |
| 837 |
{ |
| 838 |
columnFlexibilities[i] = 0; |
| 839 |
--flexibleColumnCount; |
| 840 |
continue; |
| 841 |
} |
| 842 |
|
| 843 |
++o_newColWidthsPixel[i]; |
| 844 |
--distributePixel; |
| 845 |
} |
| 846 |
} |
| 847 |
} |
| 848 |
} |
| 849 |
else if ( gridWidthPixel < accumulatedCurrentWidth ) |
| 850 |
{ // we need to take away some space from the columns which allow it ... |
| 851 |
tools::Long takeAwayPixel = accumulatedCurrentWidth - gridWidthPixel; |
| 852 |
if ( gridWidthPixel < accumulatedMinWidth ) |
| 853 |
{ |
| 854 |
// ... but the column's minimal widths are still more than we have |
| 855 |
// => set them all to min |
| 856 |
for ( svt::table::TableSize i = 0; i < colCount; ++i ) |
| 857 |
{ |
| 858 |
o_newColWidthsPixel[i] = effectiveColumnLimits[i].first; |
| 859 |
} |
| 860 |
} |
| 861 |
else |
| 862 |
{ |
| 863 |
bool startOver = false; |
| 864 |
do |
| 865 |
{ |
| 866 |
startOver = false; |
| 867 |
// take away the space we need from the columns with a positive flexibility |
| 868 |
for ( size_t i=0; i<o_newColWidthsPixel.size() && !startOver; ++i ) |
| 869 |
{ |
| 870 |
tools::Long const columnFlexibility = columnFlexibilities[i]; |
| 871 |
if ( columnFlexibility == 0 ) |
| 872 |
continue; |
| 873 |
|
| 874 |
tools::Long newColWidth = currentColWidths[i] - columnFlexibility * takeAwayPixel / flexibilityDenominator; |
| 875 |
|
| 876 |
if ( newColWidth < effectiveColumnLimits[i].first ) |
| 877 |
{ // that was too much, we hit the col's minimum |
| 878 |
// set the new width to exactly this minimum |
| 879 |
newColWidth = effectiveColumnLimits[i].first; |
| 880 |
// adjust the flexibility denominator ... |
| 881 |
flexibilityDenominator -= columnFlexibility; |
| 882 |
columnFlexibilities[i] = 0; |
| 883 |
--flexibleColumnCount; |
| 884 |
// ... and the remaining width ... |
| 885 |
tools::Long const difference = currentColWidths[i] - newColWidth; |
| 886 |
takeAwayPixel -= difference; |
| 887 |
|
| 888 |
// and start over with the first column, since there might be earlier columns which need |
| 889 |
// to be recalculated now |
| 890 |
startOver = true; |
| 891 |
} |
| 892 |
|
| 893 |
o_newColWidthsPixel[i] = newColWidth; |
| 894 |
} |
| 895 |
} |
| 896 |
while ( startOver ); |
| 897 |
|
| 898 |
// are there pixels left (might be caused by rounding errors)? |
| 899 |
takeAwayPixel = ::std::accumulate( o_newColWidthsPixel.begin(), o_newColWidthsPixel.end(), 0 ) - gridWidthPixel; |
| 900 |
while ( ( takeAwayPixel > 0 ) && ( flexibleColumnCount > 0 ) ) |
| 901 |
{ |
| 902 |
// yes => ignore relative flexibilities, and subsequently take away pixels from all flexible |
| 903 |
// columns which did not yet reach their minimum. |
| 904 |
for ( size_t i=0; ( i < o_newColWidthsPixel.size() ) && ( takeAwayPixel > 0 ); ++i ) |
| 905 |
{ |
| 906 |
if ( columnFlexibilities[i] == 0 ) |
| 907 |
continue; |
| 908 |
|
| 909 |
OSL_ENSURE( o_newColWidthsPixel[i] >= effectiveColumnLimits[i].first, |
| 910 |
"TableControl_Impl::impl_ni_calculateColumnWidths: inconsistency!" ); |
| 911 |
if ( o_newColWidthsPixel[i] <= effectiveColumnLimits[i].first ) |
| 912 |
{ |
| 913 |
columnFlexibilities[i] = 0; |
| 914 |
--flexibleColumnCount; |
| 915 |
continue; |
| 916 |
} |
| 917 |
|
| 918 |
--o_newColWidthsPixel[i]; |
| 919 |
--takeAwayPixel; |
| 920 |
} |
| 921 |
} |
| 922 |
} |
| 923 |
} |
| 924 |
|
| 925 |
return gridWidthPixel; |
| 926 |
} |
| 927 |
|
| 928 |
|
| 929 |
void TableControl_Impl::impl_ni_relayout( ColPos const i_assumeInflexibleColumnsUpToIncluding ) |
| 930 |
{ |
| 931 |
ENSURE_OR_RETURN_VOID( !m_bUpdatingColWidths, "TableControl_Impl::impl_ni_relayout: recursive call detected!" ); |
| 932 |
|
| 933 |
m_aColumnWidths.resize( 0 ); |
| 934 |
if ( !m_pModel ) |
| 935 |
return; |
| 936 |
|
| 937 |
::comphelper::FlagRestorationGuard const aWidthUpdateFlag( m_bUpdatingColWidths, true ); |
| 938 |
SuppressCursor aHideCursor( *this ); |
| 939 |
|
| 940 |
// layouting steps: |
| 941 |
|
| 942 |
// 1. adjust column widths, leaving space for a vertical scrollbar |
| 943 |
// 2. determine need for a vertical scrollbar |
| 944 |
// - V-YES: all fine, result from 1. is still valid |
| 945 |
// - V-NO: result from 1. is still under consideration |
| 946 |
|
| 947 |
// 3. determine need for a horizontal scrollbar |
| 948 |
// - H-NO: all fine, result from 2. is still valid |
| 949 |
// - H-YES: reconsider need for a vertical scrollbar, if result of 2. was V-NO |
| 950 |
// - V-YES: all fine, result from 1. is still valid |
| 951 |
// - V-NO: redistribute the remaining space (if any) amongst all columns which allow it |
| 952 |
|
| 953 |
::std::vector< tools::Long > newWidthsPixel; |
| 954 |
tools::Long gridWidthPixel = impl_ni_calculateColumnWidths( i_assumeInflexibleColumnsUpToIncluding, true, newWidthsPixel ); |
| 955 |
|
| 956 |
// the width/height of a scrollbar, needed several times below |
| 957 |
tools::Long const nScrollbarMetrics = m_rAntiImpl.GetSettings().GetStyleSettings().GetScrollBarSize(); |
| 958 |
|
| 959 |
// determine the playground for the data cells (excluding headers) |
| 960 |
// TODO: what if the control is smaller than needed for the headers/scrollbars? |
| 961 |
tools::Rectangle aDataCellPlayground( Point( 0, 0 ), m_rAntiImpl.GetOutputSizePixel() ); |
| 962 |
aDataCellPlayground.SetLeft( m_nRowHeaderWidthPixel ); |
| 963 |
aDataCellPlayground.SetTop( m_nColHeaderHeightPixel ); |
| 964 |
|
| 965 |
OSL_ENSURE( ( m_nRowCount == m_pModel->getRowCount() ) && ( m_nColumnCount == m_pModel->getColumnCount() ), |
| 966 |
"TableControl_Impl::impl_ni_relayout: how is this expected to work with invalid data?" ); |
| 967 |
tools::Long const nAllColumnsWidth = ::std::accumulate( newWidthsPixel.begin(), newWidthsPixel.end(), 0 ); |
| 968 |
|
| 969 |
ScrollbarVisibility const eVertScrollbar = m_pModel->getVerticalScrollbarVisibility(); |
| 970 |
ScrollbarVisibility const eHorzScrollbar = m_pModel->getHorizontalScrollbarVisibility(); |
| 971 |
|
| 972 |
// do we need a vertical scrollbar? |
| 973 |
bool bNeedVerticalScrollbar = lcl_determineScrollbarNeed( |
| 974 |
m_nTopRow, eVertScrollbar, aDataCellPlayground.GetHeight(), m_nRowHeightPixel * m_nRowCount ); |
| 975 |
bool bFirstRoundVScrollNeed = false; |
| 976 |
if ( bNeedVerticalScrollbar ) |
| 977 |
{ |
| 978 |
aDataCellPlayground.AdjustRight( -nScrollbarMetrics ); |
| 979 |
bFirstRoundVScrollNeed = true; |
| 980 |
} |
| 981 |
|
| 982 |
// do we need a horizontal scrollbar? |
| 983 |
bool const bNeedHorizontalScrollbar = lcl_determineScrollbarNeed( |
| 984 |
m_nLeftColumn, eHorzScrollbar, aDataCellPlayground.GetWidth(), nAllColumnsWidth ); |
| 985 |
if ( bNeedHorizontalScrollbar ) |
| 986 |
{ |
| 987 |
aDataCellPlayground.AdjustBottom( -nScrollbarMetrics ); |
| 988 |
|
| 989 |
// now that we just found that we need a horizontal scrollbar, |
| 990 |
// the need for a vertical one may have changed, since the horizontal |
| 991 |
// SB might just occupy enough space so that not all rows do fit |
| 992 |
// anymore |
| 993 |
if ( !bFirstRoundVScrollNeed ) |
| 994 |
{ |
| 995 |
bNeedVerticalScrollbar = lcl_determineScrollbarNeed( |
| 996 |
m_nTopRow, eVertScrollbar, aDataCellPlayground.GetHeight(), m_nRowHeightPixel * m_nRowCount ); |
| 997 |
if ( bNeedVerticalScrollbar ) |
| 998 |
{ |
| 999 |
aDataCellPlayground.AdjustRight( -nScrollbarMetrics ); |
| 1000 |
} |
| 1001 |
} |
| 1002 |
} |
| 1003 |
|
| 1004 |
// the initial call to impl_ni_calculateColumnWidths assumed that we need a vertical scrollbar. If, by now, |
| 1005 |
// we know that this is not the case, re-calculate the column widths. |
| 1006 |
if ( !bNeedVerticalScrollbar ) |
| 1007 |
gridWidthPixel = impl_ni_calculateColumnWidths( i_assumeInflexibleColumnsUpToIncluding, false, newWidthsPixel ); |
| 1008 |
|
| 1009 |
// update the column objects with the new widths we finally calculated |
| 1010 |
TableSize const colCount = m_pModel->getColumnCount(); |
| 1011 |
m_aColumnWidths.reserve( colCount ); |
| 1012 |
tools::Long accumulatedWidthPixel = m_nRowHeaderWidthPixel; |
| 1013 |
bool anyColumnWidthChanged = false; |
| 1014 |
for ( ColPos col = 0; col < colCount; ++col ) |
| 1015 |
{ |
| 1016 |
const tools::Long columnStart = accumulatedWidthPixel; |
| 1017 |
const tools::Long columnEnd = columnStart + newWidthsPixel[col]; |
| 1018 |
m_aColumnWidths.emplace_back( columnStart, columnEnd ); |
| 1019 |
accumulatedWidthPixel = columnEnd; |
| 1020 |
|
| 1021 |
// and don't forget to forward this to the column models |
| 1022 |
PColumnModel const pColumn = m_pModel->getColumnModel( col ); |
| 1023 |
ENSURE_OR_THROW( !!pColumn, "invalid column returned by the model!" ); |
| 1024 |
|
| 1025 |
tools::Long const oldColumnWidthAppFont = pColumn->getWidth(); |
| 1026 |
tools::Long const newColumnWidthAppFont = pixelWidthToAppFont( newWidthsPixel[col] ); |
| 1027 |
pColumn->setWidth( newColumnWidthAppFont ); |
| 1028 |
|
| 1029 |
anyColumnWidthChanged |= ( oldColumnWidthAppFont != newColumnWidthAppFont ); |
| 1030 |
} |
| 1031 |
|
| 1032 |
// if the column widths changed, ensure everything is repainted |
| 1033 |
if ( anyColumnWidthChanged ) |
| 1034 |
invalidate( TableArea::All ); |
| 1035 |
|
| 1036 |
// if the column resizing happened to leave some space at the right, but there are columns |
| 1037 |
// scrolled out to the left, scroll them in |
| 1038 |
while ( ( m_nLeftColumn > 0 ) |
| 1039 |
&& ( accumulatedWidthPixel - m_aColumnWidths[ m_nLeftColumn - 1 ].getStart() <= gridWidthPixel ) |
| 1040 |
) |
| 1041 |
{ |
| 1042 |
--m_nLeftColumn; |
| 1043 |
} |
| 1044 |
|
| 1045 |
// now adjust the column metrics, since they currently ignore the horizontal scroll position |
| 1046 |
if ( m_nLeftColumn > 0 ) |
| 1047 |
{ |
| 1048 |
const tools::Long offsetPixel = m_aColumnWidths[ 0 ].getStart() - m_aColumnWidths[ m_nLeftColumn ].getStart(); |
| 1049 |
for (auto & columnWidth : m_aColumnWidths) |
| 1050 |
{ |
| 1051 |
columnWidth.move( offsetPixel ); |
| 1052 |
} |
| 1053 |
} |
| 1054 |
|
| 1055 |
// show or hide the scrollbars as needed, and position the data window |
| 1056 |
impl_ni_positionChildWindows( aDataCellPlayground, bNeedVerticalScrollbar, bNeedHorizontalScrollbar ); |
| 1057 |
} |
| 1058 |
|
| 1059 |
|
| 1060 |
void TableControl_Impl::impl_ni_positionChildWindows( tools::Rectangle const & i_dataCellPlayground, |
| 1061 |
bool const i_verticalScrollbar, bool const i_horizontalScrollbar ) |
| 1062 |
{ |
| 1063 |
tools::Long const nScrollbarMetrics = m_rAntiImpl.GetSettings().GetStyleSettings().GetScrollBarSize(); |
| 1064 |
|
| 1065 |
// create or destroy the vertical scrollbar, as needed |
| 1066 |
lcl_updateScrollbar( |
| 1067 |
m_rAntiImpl, |
| 1068 |
m_pVScroll, |
| 1069 |
i_verticalScrollbar, |
| 1070 |
lcl_getRowsFittingInto( i_dataCellPlayground.GetHeight(), m_nRowHeightPixel, false ), |
| 1071 |
// visible units |
| 1072 |
m_nTopRow, // current position |
| 1073 |
m_nRowCount, // range |
| 1074 |
false, // vertical |
| 1075 |
LINK( this, TableControl_Impl, OnScroll ) // scroll handler |
| 1076 |
); |
| 1077 |
|
| 1078 |
// position it |
| 1079 |
if ( m_pVScroll ) |
| 1080 |
{ |
| 1081 |
tools::Rectangle aScrollbarArea( |
| 1082 |
Point( i_dataCellPlayground.Right() + 1, 0 ), |
| 1083 |
Size( nScrollbarMetrics, i_dataCellPlayground.Bottom() + 1 ) |
| 1084 |
); |
| 1085 |
m_pVScroll->SetPosSizePixel( |
| 1086 |
aScrollbarArea.TopLeft(), aScrollbarArea.GetSize() ); |
| 1087 |
} |
| 1088 |
|
| 1089 |
// create or destroy the horizontal scrollbar, as needed |
| 1090 |
lcl_updateScrollbar( |
| 1091 |
m_rAntiImpl, |
| 1092 |
m_pHScroll, |
| 1093 |
i_horizontalScrollbar, |
| 1094 |
lcl_getColumnsVisibleWithin( i_dataCellPlayground, m_nLeftColumn, *this, false ), |
| 1095 |
// visible units |
| 1096 |
m_nLeftColumn, // current position |
| 1097 |
m_nColumnCount, // range |
| 1098 |
true, // horizontal |
| 1099 |
LINK( this, TableControl_Impl, OnScroll ) // scroll handler |
| 1100 |
); |
| 1101 |
|
| 1102 |
// position it |
| 1103 |
if ( m_pHScroll ) |
| 1104 |
{ |
| 1105 |
TableSize const nVisibleUnits = lcl_getColumnsVisibleWithin( i_dataCellPlayground, m_nLeftColumn, *this, false ); |
| 1106 |
TableMetrics const nRange = m_nColumnCount; |
| 1107 |
if( m_nLeftColumn + nVisibleUnits == nRange - 1 ) |
| 1108 |
{ |
| 1109 |
if ( m_aColumnWidths[ nRange - 1 ].getStart() - m_aColumnWidths[ m_nLeftColumn ].getEnd() + m_aColumnWidths[ nRange-1 ].getWidth() > i_dataCellPlayground.GetWidth() ) |
| 1110 |
{ |
| 1111 |
m_pHScroll->SetVisibleSize( nVisibleUnits -1 ); |
| 1112 |
m_pHScroll->SetPageSize( nVisibleUnits - 1 ); |
| 1113 |
} |
| 1114 |
} |
| 1115 |
tools::Rectangle aScrollbarArea( |
| 1116 |
Point( 0, i_dataCellPlayground.Bottom() + 1 ), |
| 1117 |
Size( i_dataCellPlayground.Right() + 1, nScrollbarMetrics ) |
| 1118 |
); |
| 1119 |
m_pHScroll->SetPosSizePixel( |
| 1120 |
aScrollbarArea.TopLeft(), aScrollbarArea.GetSize() ); |
| 1121 |
} |
| 1122 |
|
| 1123 |
// the corner window connecting the two scrollbars in the lower right corner |
| 1124 |
bool bHaveScrollCorner = nullptr != m_pScrollCorner; |
| 1125 |
bool bNeedScrollCorner = ( nullptr != m_pHScroll ) && ( nullptr != m_pVScroll ); |
| 1126 |
if ( bHaveScrollCorner && !bNeedScrollCorner ) |
| 1127 |
{ |
| 1128 |
m_pScrollCorner.disposeAndClear(); |
| 1129 |
} |
| 1130 |
else if ( !bHaveScrollCorner && bNeedScrollCorner ) |
| 1131 |
{ |
| 1132 |
m_pScrollCorner = VclPtr<ScrollBarBox>::Create( &m_rAntiImpl ); |
| 1133 |
m_pScrollCorner->SetSizePixel( Size( nScrollbarMetrics, nScrollbarMetrics ) ); |
| 1134 |
m_pScrollCorner->SetPosPixel( Point( i_dataCellPlayground.Right() + 1, i_dataCellPlayground.Bottom() + 1 ) ); |
| 1135 |
m_pScrollCorner->Show(); |
| 1136 |
} |
| 1137 |
else if(bHaveScrollCorner && bNeedScrollCorner) |
| 1138 |
{ |
| 1139 |
m_pScrollCorner->SetPosPixel( Point( i_dataCellPlayground.Right() + 1, i_dataCellPlayground.Bottom() + 1 ) ); |
| 1140 |
m_pScrollCorner->Show(); |
| 1141 |
} |
| 1142 |
|
| 1143 |
// resize the data window |
| 1144 |
m_pDataWindow->SetSizePixel( Size( |
| 1145 |
i_dataCellPlayground.GetWidth() + m_nRowHeaderWidthPixel, |
| 1146 |
i_dataCellPlayground.GetHeight() + m_nColHeaderHeightPixel |
| 1147 |
) ); |
| 1148 |
} |
| 1149 |
|
| 1150 |
|
| 1151 |
void TableControl_Impl::onResize() |
| 1152 |
{ |
| 1153 |
impl_ni_relayout(); |
| 1154 |
checkCursorPosition(); |
| 1155 |
} |
| 1156 |
|
| 1157 |
|
| 1158 |
void TableControl_Impl::doPaintContent(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rUpdateRect) |
| 1159 |
{ |
| 1160 |
if (!getModel()) |
| 1161 |
return; |
| 1162 |
PTableRenderer pRenderer = getModel()->getRenderer(); |
| 1163 |
DBG_ASSERT(!!pRenderer, "TableDataWindow::doPaintContent: invalid renderer!"); |
| 1164 |
if (!pRenderer) |
| 1165 |
return; |
| 1166 |
|
| 1167 |
// our current style settings, to be passed to the renderer |
| 1168 |
const StyleSettings& rStyle = rRenderContext.GetSettings().GetStyleSettings(); |
| 1169 |
m_nRowCount = m_pModel->getRowCount(); |
| 1170 |
// the area occupied by all (at least partially) visible cells, including |
| 1171 |
// headers |
| 1172 |
tools::Rectangle const aAllCellsWithHeaders( impl_getAllVisibleCellsArea() ); |
| 1173 |
|
| 1174 |
// draw the header column area |
| 1175 |
if (m_pModel->hasColumnHeaders()) |
| 1176 |
{ |
| 1177 |
TableRowGeometry const aHeaderRow(*this, tools::Rectangle(Point(0, 0), aAllCellsWithHeaders.BottomRight()), ROW_COL_HEADERS); |
| 1178 |
tools::Rectangle const aColRect(aHeaderRow.getRect()); |
| 1179 |
pRenderer->PaintHeaderArea(rRenderContext, aColRect, true, false, rStyle); |
| 1180 |
// Note that strictly, aHeaderRow.getRect() also contains the intersection between column |
| 1181 |
// and row header area. However, below we go to paint this intersection, again, |
| 1182 |
// so this hopefully doesn't hurt if we already paint it here. |
| 1183 |
|
| 1184 |
for (TableCellGeometry aCell(aHeaderRow, m_nLeftColumn); aCell.isValid(); aCell.moveRight()) |
| 1185 |
{ |
| 1186 |
if (_rUpdateRect.GetIntersection(aCell.getRect()).IsEmpty()) |
| 1187 |
continue; |
| 1188 |
|
| 1189 |
pRenderer->PaintColumnHeader(aCell.getColumn(), rRenderContext, aCell.getRect(), rStyle); |
| 1190 |
} |
| 1191 |
} |
| 1192 |
// the area occupied by the row header, if any |
| 1193 |
tools::Rectangle aRowHeaderArea; |
| 1194 |
if (m_pModel->hasRowHeaders()) |
| 1195 |
{ |
| 1196 |
aRowHeaderArea = aAllCellsWithHeaders; |
| 1197 |
aRowHeaderArea.SetRight( m_nRowHeaderWidthPixel - 1 ); |
| 1198 |
|
| 1199 |
TableSize const nVisibleRows = impl_getVisibleRows(true); |
| 1200 |
TableSize nActualRows = nVisibleRows; |
| 1201 |
if (m_nTopRow + nActualRows > m_nRowCount) |
| 1202 |
nActualRows = m_nRowCount - m_nTopRow; |
| 1203 |
aRowHeaderArea.SetBottom( m_nColHeaderHeightPixel + m_nRowHeightPixel * nActualRows - 1 ); |
| 1204 |
|
| 1205 |
pRenderer->PaintHeaderArea(rRenderContext, aRowHeaderArea, false, true, rStyle); |
| 1206 |
// Note that strictly, aRowHeaderArea also contains the intersection between column |
| 1207 |
// and row header area. However, below we go to paint this intersection, again, |
| 1208 |
// so this hopefully doesn't hurt if we already paint it here. |
| 1209 |
|
| 1210 |
if (m_pModel->hasColumnHeaders()) |
| 1211 |
{ |
| 1212 |
TableCellGeometry const aIntersection(*this, tools::Rectangle(Point(0, 0), aAllCellsWithHeaders.BottomRight()), |
| 1213 |
COL_ROW_HEADERS, ROW_COL_HEADERS); |
| 1214 |
tools::Rectangle const aInters(aIntersection.getRect()); |
| 1215 |
pRenderer->PaintHeaderArea(rRenderContext, aInters, true, true, rStyle); |
| 1216 |
} |
| 1217 |
} |
| 1218 |
|
| 1219 |
// draw the table content row by row |
| 1220 |
TableSize colCount = getModel()->getColumnCount(); |
| 1221 |
|
| 1222 |
// paint all rows |
| 1223 |
tools::Rectangle const aAllDataCellsArea(impl_getAllVisibleDataCellArea()); |
| 1224 |
for (TableRowGeometry aRowIterator(*this, aAllCellsWithHeaders, getTopRow()); aRowIterator.isValid(); aRowIterator.moveDown()) |
| 1225 |
{ |
| 1226 |
if (_rUpdateRect.GetIntersection(aRowIterator.getRect() ).IsEmpty()) |
| 1227 |
continue; |
| 1228 |
|
| 1229 |
bool const isControlFocused = m_rAntiImpl.HasControlFocus(); |
| 1230 |
bool const isSelectedRow = isRowSelected(aRowIterator.getRow()); |
| 1231 |
|
| 1232 |
tools::Rectangle const aRect = aRowIterator.getRect().GetIntersection(aAllDataCellsArea); |
| 1233 |
|
| 1234 |
// give the renderer a chance to prepare the row |
| 1235 |
pRenderer->PrepareRow(aRowIterator.getRow(), isControlFocused, isSelectedRow, rRenderContext, aRect, rStyle); |
| 1236 |
|
| 1237 |
// paint the row header |
| 1238 |
if (m_pModel->hasRowHeaders()) |
| 1239 |
{ |
| 1240 |
const tools::Rectangle aCurrentRowHeader(aRowHeaderArea.GetIntersection(aRowIterator.getRect())); |
| 1241 |
pRenderer->PaintRowHeader(rRenderContext, aCurrentRowHeader, rStyle); |
| 1242 |
} |
| 1243 |
|
| 1244 |
if (!colCount) |
| 1245 |
continue; |
| 1246 |
|
| 1247 |
// paint all cells in this row |
| 1248 |
for (TableCellGeometry aCell(aRowIterator, m_nLeftColumn); aCell.isValid(); aCell.moveRight()) |
| 1249 |
{ |
| 1250 |
pRenderer->PaintCell(aCell.getColumn(), isSelectedRow, isControlFocused, |
| 1251 |
rRenderContext, aCell.getRect(), rStyle); |
| 1252 |
} |
| 1253 |
} |
| 1254 |
} |
| 1255 |
|
| 1256 |
void TableControl_Impl::hideCursor() |
| 1257 |
{ |
| 1258 |
if ( ++m_nCursorHidden == 1 ) |
| 1259 |
impl_ni_doSwitchCursor( false ); |
| 1260 |
} |
| 1261 |
|
| 1262 |
|
| 1263 |
void TableControl_Impl::showCursor() |
| 1264 |
{ |
| 1265 |
DBG_ASSERT( m_nCursorHidden > 0, "TableControl_Impl::showCursor: cursor not hidden!" ); |
| 1266 |
if ( --m_nCursorHidden == 0 ) |
| 1267 |
impl_ni_doSwitchCursor( true ); |
| 1268 |
} |
| 1269 |
|
| 1270 |
|
| 1271 |
bool TableControl_Impl::dispatchAction( TableControlAction _eAction ) |
| 1272 |
{ |
| 1273 |
bool bSuccess = false; |
| 1274 |
bool selectionChanged = false; |
| 1275 |
|
| 1276 |
switch ( _eAction ) |
| 1277 |
{ |
| 1278 |
case TableControlAction::cursorDown: |
| 1279 |
if ( m_pSelEngine->GetSelectionMode() == SelectionMode::Single ) |
| 1280 |
{ |
| 1281 |
//if other rows already selected, deselect them |
| 1282 |
if(!m_aSelectedRows.empty()) |
| 1283 |
{ |
| 1284 |
invalidateSelectedRows(); |
| 1285 |
m_aSelectedRows.clear(); |
| 1286 |
} |
| 1287 |
if ( m_nCurRow < m_nRowCount-1 ) |
| 1288 |
{ |
| 1289 |
++m_nCurRow; |
| 1290 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1291 |
} |
| 1292 |
else |
| 1293 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1294 |
invalidateRow( m_nCurRow ); |
| 1295 |
ensureVisible(m_nCurColumn,m_nCurRow); |
| 1296 |
selectionChanged = true; |
| 1297 |
bSuccess = true; |
| 1298 |
} |
| 1299 |
else |
| 1300 |
{ |
| 1301 |
if ( m_nCurRow < m_nRowCount - 1 ) |
| 1302 |
bSuccess = goTo( m_nCurColumn, m_nCurRow + 1 ); |
| 1303 |
} |
| 1304 |
break; |
| 1305 |
|
| 1306 |
case TableControlAction::cursorUp: |
| 1307 |
if(m_pSelEngine->GetSelectionMode() == SelectionMode::Single) |
| 1308 |
{ |
| 1309 |
if(!m_aSelectedRows.empty()) |
| 1310 |
{ |
| 1311 |
invalidateSelectedRows(); |
| 1312 |
m_aSelectedRows.clear(); |
| 1313 |
} |
| 1314 |
if(m_nCurRow>0) |
| 1315 |
{ |
| 1316 |
--m_nCurRow; |
| 1317 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1318 |
invalidateRow( m_nCurRow ); |
| 1319 |
} |
| 1320 |
else |
| 1321 |
{ |
| 1322 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1323 |
invalidateRow( m_nCurRow ); |
| 1324 |
} |
| 1325 |
ensureVisible(m_nCurColumn,m_nCurRow); |
| 1326 |
selectionChanged = true; |
| 1327 |
bSuccess = true; |
| 1328 |
} |
| 1329 |
else |
| 1330 |
{ |
| 1331 |
if ( m_nCurRow > 0 ) |
| 1332 |
bSuccess = goTo( m_nCurColumn, m_nCurRow - 1 ); |
| 1333 |
} |
| 1334 |
break; |
| 1335 |
case TableControlAction::cursorLeft: |
| 1336 |
if ( m_nCurColumn > 0 ) |
| 1337 |
bSuccess = goTo( m_nCurColumn - 1, m_nCurRow ); |
| 1338 |
else |
| 1339 |
if ( ( m_nCurColumn == 0) && ( m_nCurRow > 0 ) ) |
| 1340 |
bSuccess = goTo( m_nColumnCount - 1, m_nCurRow - 1 ); |
| 1341 |
break; |
| 1342 |
|
| 1343 |
case TableControlAction::cursorRight: |
| 1344 |
if ( m_nCurColumn < m_nColumnCount - 1 ) |
| 1345 |
bSuccess = goTo( m_nCurColumn + 1, m_nCurRow ); |
| 1346 |
else |
| 1347 |
if ( ( m_nCurColumn == m_nColumnCount - 1 ) && ( m_nCurRow < m_nRowCount - 1 ) ) |
| 1348 |
bSuccess = goTo( 0, m_nCurRow + 1 ); |
| 1349 |
break; |
| 1350 |
|
| 1351 |
case TableControlAction::cursorToLineStart: |
| 1352 |
bSuccess = goTo( 0, m_nCurRow ); |
| 1353 |
break; |
| 1354 |
|
| 1355 |
case TableControlAction::cursorToLineEnd: |
| 1356 |
bSuccess = goTo( m_nColumnCount - 1, m_nCurRow ); |
| 1357 |
break; |
| 1358 |
|
| 1359 |
case TableControlAction::cursorToFirstLine: |
| 1360 |
bSuccess = goTo( m_nCurColumn, 0 ); |
| 1361 |
break; |
| 1362 |
|
| 1363 |
case TableControlAction::cursorToLastLine: |
| 1364 |
bSuccess = goTo( m_nCurColumn, m_nRowCount - 1 ); |
| 1365 |
break; |
| 1366 |
|
| 1367 |
case TableControlAction::cursorPageUp: |
| 1368 |
{ |
| 1369 |
RowPos nNewRow = ::std::max( RowPos(0), m_nCurRow - impl_getVisibleRows( false ) ); |
| 1370 |
bSuccess = goTo( m_nCurColumn, nNewRow ); |
| 1371 |
} |
| 1372 |
break; |
| 1373 |
|
| 1374 |
case TableControlAction::cursorPageDown: |
| 1375 |
{ |
| 1376 |
RowPos nNewRow = ::std::min( m_nRowCount - 1, m_nCurRow + impl_getVisibleRows( false ) ); |
| 1377 |
bSuccess = goTo( m_nCurColumn, nNewRow ); |
| 1378 |
} |
| 1379 |
break; |
| 1380 |
|
| 1381 |
case TableControlAction::cursorTopLeft: |
| 1382 |
bSuccess = goTo( 0, 0 ); |
| 1383 |
break; |
| 1384 |
|
| 1385 |
case TableControlAction::cursorBottomRight: |
| 1386 |
bSuccess = goTo( m_nColumnCount - 1, m_nRowCount - 1 ); |
| 1387 |
break; |
| 1388 |
|
| 1389 |
case TableControlAction::cursorSelectRow: |
| 1390 |
{ |
| 1391 |
if(m_pSelEngine->GetSelectionMode() == SelectionMode::NONE) |
| 1392 |
return false; |
| 1393 |
//pos is the position of the current row in the vector of selected rows, if current row is selected |
| 1394 |
int pos = getRowSelectedNumber(m_aSelectedRows, m_nCurRow); |
| 1395 |
//if current row is selected, it should be deselected, when ALT+SPACE are pressed |
| 1396 |
if(pos>-1) |
| 1397 |
{ |
| 1398 |
m_aSelectedRows.erase(m_aSelectedRows.begin()+pos); |
| 1399 |
if(m_aSelectedRows.empty() && m_nAnchor != -1) |
| 1400 |
m_nAnchor = -1; |
| 1401 |
} |
| 1402 |
//else select the row->put it in the vector |
| 1403 |
else |
| 1404 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1405 |
invalidateRow( m_nCurRow ); |
| 1406 |
selectionChanged = true; |
| 1407 |
bSuccess = true; |
| 1408 |
} |
| 1409 |
break; |
| 1410 |
case TableControlAction::cursorSelectRowUp: |
| 1411 |
{ |
| 1412 |
if(m_pSelEngine->GetSelectionMode() == SelectionMode::NONE) |
| 1413 |
return false; |
| 1414 |
else if(m_pSelEngine->GetSelectionMode() == SelectionMode::Single) |
| 1415 |
{ |
| 1416 |
//if there are other selected rows, deselect them |
| 1417 |
return false; |
| 1418 |
} |
| 1419 |
else |
| 1420 |
{ |
| 1421 |
//there are other selected rows |
| 1422 |
if(!m_aSelectedRows.empty()) |
| 1423 |
{ |
| 1424 |
//the anchor wasn't set -> a region is not selected, that's why clear all selection |
| 1425 |
//and select the current row |
| 1426 |
if(m_nAnchor==-1) |
| 1427 |
{ |
| 1428 |
invalidateSelectedRows(); |
| 1429 |
m_aSelectedRows.clear(); |
| 1430 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1431 |
invalidateRow( m_nCurRow ); |
| 1432 |
} |
| 1433 |
else |
| 1434 |
{ |
| 1435 |
//a region is already selected, prevRow is last selected row and the row above - nextRow - should be selected |
| 1436 |
int prevRow = getRowSelectedNumber(m_aSelectedRows, m_nCurRow); |
| 1437 |
int nextRow = getRowSelectedNumber(m_aSelectedRows, m_nCurRow-1); |
| 1438 |
if(prevRow>-1) |
| 1439 |
{ |
| 1440 |
//if m_nCurRow isn't the upper one, can move up, otherwise not |
| 1441 |
if(m_nCurRow>0) |
| 1442 |
m_nCurRow--; |
| 1443 |
else |
| 1444 |
return true; |
| 1445 |
//if nextRow already selected, deselect it, otherwise select it |
| 1446 |
if(nextRow>-1 && m_aSelectedRows[nextRow] == m_nCurRow) |
| 1447 |
{ |
| 1448 |
m_aSelectedRows.erase(m_aSelectedRows.begin()+prevRow); |
| 1449 |
invalidateRow( m_nCurRow + 1 ); |
| 1450 |
} |
| 1451 |
else |
| 1452 |
{ |
| 1453 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1454 |
invalidateRow( m_nCurRow ); |
| 1455 |
} |
| 1456 |
} |
| 1457 |
else |
| 1458 |
{ |
| 1459 |
if(m_nCurRow>0) |
| 1460 |
{ |
| 1461 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1462 |
m_nCurRow--; |
| 1463 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1464 |
invalidateSelectedRegion( m_nCurRow+1, m_nCurRow ); |
| 1465 |
} |
| 1466 |
} |
| 1467 |
} |
| 1468 |
} |
| 1469 |
else |
| 1470 |
{ |
| 1471 |
//if nothing is selected and the current row isn't the upper one |
| 1472 |
//select the current and one row above |
| 1473 |
//otherwise select only the upper row |
| 1474 |
if(m_nCurRow>0) |
| 1475 |
{ |
| 1476 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1477 |
m_nCurRow--; |
| 1478 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1479 |
invalidateSelectedRegion( m_nCurRow+1, m_nCurRow ); |
| 1480 |
} |
| 1481 |
else |
| 1482 |
{ |
| 1483 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1484 |
invalidateRow( m_nCurRow ); |
| 1485 |
} |
| 1486 |
} |
| 1487 |
m_pSelEngine->SetAnchor(true); |
| 1488 |
m_nAnchor = m_nCurRow; |
| 1489 |
ensureVisible(m_nCurColumn, m_nCurRow); |
| 1490 |
selectionChanged = true; |
| 1491 |
bSuccess = true; |
| 1492 |
} |
| 1493 |
} |
| 1494 |
break; |
| 1495 |
case TableControlAction::cursorSelectRowDown: |
| 1496 |
{ |
| 1497 |
if(m_pSelEngine->GetSelectionMode() == SelectionMode::NONE) |
| 1498 |
bSuccess = false; |
| 1499 |
else if(m_pSelEngine->GetSelectionMode() == SelectionMode::Single) |
| 1500 |
{ |
| 1501 |
bSuccess = false; |
| 1502 |
} |
| 1503 |
else |
| 1504 |
{ |
| 1505 |
if(!m_aSelectedRows.empty()) |
| 1506 |
{ |
| 1507 |
//the anchor wasn't set -> a region is not selected, that's why clear all selection |
| 1508 |
//and select the current row |
| 1509 |
if(m_nAnchor==-1) |
| 1510 |
{ |
| 1511 |
invalidateSelectedRows(); |
| 1512 |
m_aSelectedRows.clear(); |
| 1513 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1514 |
invalidateRow( m_nCurRow ); |
| 1515 |
} |
| 1516 |
else |
| 1517 |
{ |
| 1518 |
//a region is already selected, prevRow is last selected row and the row beneath - nextRow - should be selected |
| 1519 |
int prevRow = getRowSelectedNumber(m_aSelectedRows, m_nCurRow); |
| 1520 |
int nextRow = getRowSelectedNumber(m_aSelectedRows, m_nCurRow+1); |
| 1521 |
if(prevRow>-1) |
| 1522 |
{ |
| 1523 |
//if m_nCurRow isn't the last one, can move down, otherwise not |
| 1524 |
if(m_nCurRow<m_nRowCount-1) |
| 1525 |
m_nCurRow++; |
| 1526 |
else |
| 1527 |
return true; |
| 1528 |
//if next row already selected, deselect it, otherwise select it |
| 1529 |
if(nextRow>-1 && m_aSelectedRows[nextRow] == m_nCurRow) |
| 1530 |
{ |
| 1531 |
m_aSelectedRows.erase(m_aSelectedRows.begin()+prevRow); |
| 1532 |
invalidateRow( m_nCurRow - 1 ); |
| 1533 |
} |
| 1534 |
else |
| 1535 |
{ |
| 1536 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1537 |
invalidateRow( m_nCurRow ); |
| 1538 |
} |
| 1539 |
} |
| 1540 |
else |
| 1541 |
{ |
| 1542 |
if(m_nCurRow<m_nRowCount-1) |
| 1543 |
{ |
| 1544 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1545 |
m_nCurRow++; |
| 1546 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1547 |
invalidateSelectedRegion( m_nCurRow-1, m_nCurRow ); |
| 1548 |
} |
| 1549 |
} |
| 1550 |
} |
| 1551 |
} |
| 1552 |
else |
| 1553 |
{ |
| 1554 |
//there wasn't any selection, select current and row beneath, otherwise only row beneath |
| 1555 |
if(m_nCurRow<m_nRowCount-1) |
| 1556 |
{ |
| 1557 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1558 |
m_nCurRow++; |
| 1559 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1560 |
invalidateSelectedRegion( m_nCurRow-1, m_nCurRow ); |
| 1561 |
} |
| 1562 |
else |
| 1563 |
{ |
| 1564 |
m_aSelectedRows.push_back(m_nCurRow); |
| 1565 |
invalidateRow( m_nCurRow ); |
| 1566 |
} |
| 1567 |
} |
| 1568 |
m_pSelEngine->SetAnchor(true); |
| 1569 |
m_nAnchor = m_nCurRow; |
| 1570 |
ensureVisible(m_nCurColumn, m_nCurRow); |
| 1571 |
selectionChanged = true; |
| 1572 |
bSuccess = true; |
| 1573 |
} |
| 1574 |
} |
| 1575 |
break; |
| 1576 |
|
| 1577 |
case TableControlAction::cursorSelectRowAreaTop: |
| 1578 |
{ |
| 1579 |
if(m_pSelEngine->GetSelectionMode() == SelectionMode::NONE) |
| 1580 |
bSuccess = false; |
| 1581 |
else if(m_pSelEngine->GetSelectionMode() == SelectionMode::Single) |
| 1582 |
bSuccess = false; |
| 1583 |
else |
| 1584 |
{ |
| 1585 |
//select the region between the current and the upper row |
| 1586 |
RowPos iter = m_nCurRow; |
| 1587 |
invalidateSelectedRegion( m_nCurRow, 0 ); |
| 1588 |
//put the rows in vector |
| 1589 |
while(iter>=0) |
| 1590 |
{ |
| 1591 |
if ( !isRowSelected( iter ) ) |
| 1592 |
m_aSelectedRows.push_back(iter); |
| 1593 |
--iter; |
| 1594 |
} |
| 1595 |
m_nCurRow = 0; |
| 1596 |
m_nAnchor = m_nCurRow; |
| 1597 |
m_pSelEngine->SetAnchor(true); |
| 1598 |
ensureVisible(m_nCurColumn, 0); |
| 1599 |
selectionChanged = true; |
| 1600 |
bSuccess = true; |
| 1601 |
} |
| 1602 |
} |
| 1603 |
break; |
| 1604 |
|
| 1605 |
case TableControlAction::cursorSelectRowAreaBottom: |
| 1606 |
{ |
| 1607 |
if(m_pSelEngine->GetSelectionMode() == SelectionMode::NONE) |
| 1608 |
return false; |
| 1609 |
else if(m_pSelEngine->GetSelectionMode() == SelectionMode::Single) |
| 1610 |
return false; |
| 1611 |
//select the region between the current and the last row |
| 1612 |
RowPos iter = m_nCurRow; |
| 1613 |
invalidateSelectedRegion( m_nCurRow, m_nRowCount-1 ); |
| 1614 |
//put the rows in the vector |
| 1615 |
while(iter<=m_nRowCount) |
| 1616 |
{ |
| 1617 |
if ( !isRowSelected( iter ) ) |
| 1618 |
m_aSelectedRows.push_back(iter); |
| 1619 |
++iter; |
| 1620 |
} |
| 1621 |
m_nCurRow = m_nRowCount-1; |
| 1622 |
m_nAnchor = m_nCurRow; |
| 1623 |
m_pSelEngine->SetAnchor(true); |
| 1624 |
ensureVisible(m_nCurColumn, m_nRowCount-1); |
| 1625 |
selectionChanged = true; |
| 1626 |
bSuccess = true; |
| 1627 |
} |
| 1628 |
break; |
| 1629 |
default: |
| 1630 |
OSL_FAIL( "TableControl_Impl::dispatchAction: unsupported action!" ); |
| 1631 |
break; |
| 1632 |
} |
| 1633 |
|
| 1634 |
if ( bSuccess && selectionChanged ) |
| 1635 |
{ |
| 1636 |
m_rAntiImpl.Select(); |
| 1637 |
} |
| 1638 |
|
| 1639 |
return bSuccess; |
| 1640 |
} |
| 1641 |
|
| 1642 |
|
| 1643 |
void TableControl_Impl::impl_ni_doSwitchCursor( bool _bShow ) |
| 1644 |
{ |
| 1645 |
PTableRenderer pRenderer = m_pModel ? m_pModel->getRenderer() : PTableRenderer(); |
| 1646 |
if ( pRenderer ) |
| 1647 |
{ |
| 1648 |
tools::Rectangle aCellRect = calcCellRect(m_nCurRow, m_nCurColumn); |
| 1649 |
if ( _bShow ) |
| 1650 |
pRenderer->ShowCellCursor( *m_pDataWindow, aCellRect ); |
| 1651 |
else |
| 1652 |
pRenderer->HideCellCursor( *m_pDataWindow ); |
| 1653 |
} |
| 1654 |
} |
| 1655 |
|
| 1656 |
RowPos TableControl_Impl::getRowAtPoint( const Point& rPoint ) const |
| 1657 |
{ |
| 1658 |
return impl_getRowForAbscissa( rPoint.Y() ); |
| 1659 |
} |
| 1660 |
|
| 1661 |
|
| 1662 |
ColPos TableControl_Impl::getColAtPoint( const Point& rPoint ) const |
| 1663 |
{ |
| 1664 |
return impl_getColumnForOrdinate( rPoint.X() ); |
| 1665 |
} |
| 1666 |
|
| 1667 |
|
| 1668 |
TableCell TableControl_Impl::hitTest( Point const & i_point ) const |
| 1669 |
{ |
| 1670 |
TableCell aCell( getColAtPoint( i_point ), getRowAtPoint( i_point ) ); |
| 1671 |
if ( aCell.nColumn > COL_ROW_HEADERS ) |
| 1672 |
{ |
| 1673 |
PColumnModel const pColumn = m_pModel->getColumnModel( aCell.nColumn ); |
| 1674 |
MutableColumnMetrics const & rColInfo( m_aColumnWidths[ aCell.nColumn ] ); |
| 1675 |
if ( ( rColInfo.getEnd() - 3 <= i_point.X() ) |
| 1676 |
&& ( rColInfo.getEnd() >= i_point.X() ) |
| 1677 |
&& pColumn->isResizable() |
| 1678 |
) |
| 1679 |
{ |
| 1680 |
aCell.eArea = ColumnDivider; |
| 1681 |
} |
| 1682 |
} |
| 1683 |
return aCell; |
| 1684 |
} |
| 1685 |
|
| 1686 |
|
| 1687 |
ColumnMetrics TableControl_Impl::getColumnMetrics( ColPos const i_column ) const |
| 1688 |
{ |
| 1689 |
ENSURE_OR_RETURN( ( i_column >= 0 ) && ( i_column < m_pModel->getColumnCount() ), |
| 1690 |
"TableControl_Impl::getColumnMetrics: illegal column index!", ColumnMetrics() ); |
| 1691 |
return m_aColumnWidths[ i_column ]; |
| 1692 |
} |
| 1693 |
|
| 1694 |
|
| 1695 |
PTableModel TableControl_Impl::getModel() const |
| 1696 |
{ |
| 1697 |
return m_pModel; |
| 1698 |
} |
| 1699 |
|
| 1700 |
|
| 1701 |
ColPos TableControl_Impl::getCurrentColumn() const |
| 1702 |
{ |
| 1703 |
return m_nCurColumn; |
| 1704 |
} |
| 1705 |
|
| 1706 |
|
| 1707 |
RowPos TableControl_Impl::getCurrentRow() const |
| 1708 |
{ |
| 1709 |
return m_nCurRow; |
| 1710 |
} |
| 1711 |
|
| 1712 |
|
| 1713 |
::Size TableControl_Impl::getTableSizePixel() const |
| 1714 |
{ |
| 1715 |
return m_pDataWindow->GetOutputSizePixel(); |
| 1716 |
} |
| 1717 |
|
| 1718 |
|
| 1719 |
void TableControl_Impl::setPointer( PointerStyle i_pointer ) |
| 1720 |
{ |
| 1721 |
m_pDataWindow->SetPointer( i_pointer ); |
| 1722 |
} |
| 1723 |
|
| 1724 |
|
| 1725 |
void TableControl_Impl::captureMouse() |
| 1726 |
{ |
| 1727 |
m_pDataWindow->CaptureMouse(); |
| 1728 |
} |
| 1729 |
|
| 1730 |
|
| 1731 |
void TableControl_Impl::releaseMouse() |
| 1732 |
{ |
| 1733 |
m_pDataWindow->ReleaseMouse(); |
| 1734 |
} |
| 1735 |
|
| 1736 |
|
| 1737 |
void TableControl_Impl::invalidate( TableArea const i_what ) |
| 1738 |
{ |
| 1739 |
switch ( i_what ) |
| 1740 |
{ |
| 1741 |
case TableArea::ColumnHeaders: |
| 1742 |
m_pDataWindow->Invalidate( calcHeaderRect( true ) ); |
| 1743 |
break; |
| 1744 |
|
| 1745 |
case TableArea::RowHeaders: |
| 1746 |
m_pDataWindow->Invalidate( calcHeaderRect( false ) ); |
| 1747 |
break; |
| 1748 |
|
| 1749 |
case TableArea::All: |
| 1750 |
m_pDataWindow->Invalidate(); |
| 1751 |
m_pDataWindow->GetParent()->Invalidate( InvalidateFlags::Transparent ); |
| 1752 |
break; |
| 1753 |
} |
| 1754 |
} |
| 1755 |
|
| 1756 |
|
| 1757 |
tools::Long TableControl_Impl::pixelWidthToAppFont( tools::Long const i_pixels ) const |
| 1758 |
{ |
| 1759 |
return m_pDataWindow->PixelToLogic(Size(i_pixels, 0), MapMode(MapUnit::MapAppFont)).Width(); |
| 1760 |
} |
| 1761 |
|
| 1762 |
|
| 1763 |
tools::Long TableControl_Impl::appFontWidthToPixel( tools::Long const i_appFontUnits ) const |
| 1764 |
{ |
| 1765 |
return m_pDataWindow->LogicToPixel(Size(i_appFontUnits, 0), MapMode(MapUnit::MapAppFont)).Width(); |
| 1766 |
} |
| 1767 |
|
| 1768 |
|
| 1769 |
void TableControl_Impl::hideTracking() |
| 1770 |
{ |
| 1771 |
m_pDataWindow->HideTracking(); |
| 1772 |
} |
| 1773 |
|
| 1774 |
|
| 1775 |
void TableControl_Impl::showTracking( tools::Rectangle const & i_location, ShowTrackFlags const i_flags ) |
| 1776 |
{ |
| 1777 |
m_pDataWindow->ShowTracking( i_location, i_flags ); |
| 1778 |
} |
| 1779 |
|
| 1780 |
|
| 1781 |
void TableControl_Impl::activateCell( ColPos const i_col, RowPos const i_row ) |
| 1782 |
{ |
| 1783 |
goTo( i_col, i_row ); |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
void TableControl_Impl::invalidateSelectedRegion( RowPos _nPrevRow, RowPos _nCurRow ) |
| 1788 |
{ |
| 1789 |
// get the visible area of the table control and set the Left and right border of the region to be repainted |
| 1790 |
tools::Rectangle const aAllCells( impl_getAllVisibleCellsArea() ); |
| 1791 |
|
| 1792 |
tools::Rectangle aInvalidateRect; |
| 1793 |
aInvalidateRect.SetLeft( aAllCells.Left() ); |
| 1794 |
aInvalidateRect.SetRight( aAllCells.Right() ); |
| 1795 |
// if only one row is selected |
| 1796 |
if ( _nPrevRow == _nCurRow ) |
| 1797 |
{ |
| 1798 |
tools::Rectangle aCellRect = calcCellRect(_nCurRow, m_nCurColumn); |
| 1799 |
aInvalidateRect.SetTop( aCellRect.Top() ); |
| 1800 |
aInvalidateRect.SetBottom( aCellRect.Bottom() ); |
| 1801 |
} |
| 1802 |
//if the region is above the current row |
| 1803 |
else if(_nPrevRow < _nCurRow ) |
| 1804 |
{ |
| 1805 |
tools::Rectangle aCellRect = calcCellRect(_nPrevRow, m_nCurColumn); |
| 1806 |
aInvalidateRect.SetTop( aCellRect.Top() ); |
| 1807 |
aCellRect = calcCellRect(_nCurRow, m_nCurColumn); |
| 1808 |
aInvalidateRect.SetBottom( aCellRect.Bottom() ); |
| 1809 |
} |
| 1810 |
//if the region is beneath the current row |
| 1811 |
else |
| 1812 |
{ |
| 1813 |
tools::Rectangle aCellRect = calcCellRect(_nCurRow, m_nCurColumn); |
| 1814 |
aInvalidateRect.SetTop( aCellRect.Top() ); |
| 1815 |
aCellRect = calcCellRect(_nPrevRow, m_nCurColumn); |
| 1816 |
aInvalidateRect.SetBottom( aCellRect.Bottom() ); |
| 1817 |
} |
| 1818 |
|
| 1819 |
invalidateRect(aInvalidateRect); |
| 1820 |
} |
| 1821 |
|
| 1822 |
void TableControl_Impl::invalidateRect(const tools::Rectangle &rInvalidateRect) |
| 1823 |
{ |
| 1824 |
m_pDataWindow->Invalidate( rInvalidateRect, |
| 1825 |
m_pDataWindow->GetControlBackground().IsTransparent() ? InvalidateFlags::Transparent : InvalidateFlags::NONE ); |
| 1826 |
} |
| 1827 |
|
| 1828 |
|
| 1829 |
void TableControl_Impl::invalidateSelectedRows() |
| 1830 |
{ |
| 1831 |
for (auto const& selectedRow : m_aSelectedRows) |
| 1832 |
{ |
| 1833 |
invalidateRow(selectedRow); |
| 1834 |
} |
| 1835 |
} |
| 1836 |
|
| 1837 |
|
| 1838 |
void TableControl_Impl::invalidateRowRange( RowPos const i_firstRow, RowPos const i_lastRow ) |
| 1839 |
{ |
| 1840 |
RowPos const firstRow = i_firstRow < m_nTopRow ? m_nTopRow : i_firstRow; |
| 1841 |
RowPos const lastVisibleRow = m_nTopRow + impl_getVisibleRows( true ) - 1; |
| 1842 |
RowPos const lastRow = ( ( i_lastRow == ROW_INVALID ) || ( i_lastRow > lastVisibleRow ) ) ? lastVisibleRow : i_lastRow; |
| 1843 |
|
| 1844 |
tools::Rectangle aInvalidateRect; |
| 1845 |
|
| 1846 |
tools::Rectangle const aVisibleCellsArea( impl_getAllVisibleCellsArea() ); |
| 1847 |
TableRowGeometry aRow( *this, aVisibleCellsArea, firstRow, true ); |
| 1848 |
while ( aRow.isValid() && ( aRow.getRow() <= lastRow ) ) |
| 1849 |
{ |
| 1850 |
aInvalidateRect.Union( aRow.getRect() ); |
| 1851 |
aRow.moveDown(); |
| 1852 |
} |
| 1853 |
|
| 1854 |
if ( i_lastRow == ROW_INVALID ) |
| 1855 |
aInvalidateRect.SetBottom( m_pDataWindow->GetOutputSizePixel().Height() ); |
| 1856 |
|
| 1857 |
invalidateRect(aInvalidateRect); |
| 1858 |
} |
| 1859 |
|
| 1860 |
|
| 1861 |
void TableControl_Impl::checkCursorPosition() |
| 1862 |
{ |
| 1863 |
|
| 1864 |
TableSize nVisibleRows = impl_getVisibleRows(true); |
| 1865 |
TableSize nVisibleCols = impl_getVisibleColumns(true); |
| 1866 |
if ( ( m_nTopRow + nVisibleRows > m_nRowCount ) |
| 1867 |
&& ( m_nRowCount >= nVisibleRows ) |
| 1868 |
) |
| 1869 |
{ |
| 1870 |
--m_nTopRow; |
| 1871 |
} |
| 1872 |
else |
| 1873 |
{ |
| 1874 |
m_nTopRow = 0; |
| 1875 |
} |
| 1876 |
|
| 1877 |
if ( ( m_nLeftColumn + nVisibleCols > m_nColumnCount ) |
| 1878 |
&& ( m_nColumnCount >= nVisibleCols ) |
| 1879 |
) |
| 1880 |
{ |
| 1881 |
--m_nLeftColumn; |
| 1882 |
} |
| 1883 |
else |
| 1884 |
{ |
| 1885 |
m_nLeftColumn = 0; |
| 1886 |
} |
| 1887 |
|
| 1888 |
m_pDataWindow->Invalidate(); |
| 1889 |
} |
| 1890 |
|
| 1891 |
|
| 1892 |
TableSize TableControl_Impl::impl_getVisibleRows( bool _bAcceptPartialRow ) const |
| 1893 |
{ |
| 1894 |
DBG_ASSERT( m_pDataWindow, "TableControl_Impl::impl_getVisibleRows: no data window!" ); |
| 1895 |
|
| 1896 |
return lcl_getRowsFittingInto( |
| 1897 |
m_pDataWindow->GetOutputSizePixel().Height() - m_nColHeaderHeightPixel, |
| 1898 |
m_nRowHeightPixel, |
| 1899 |
_bAcceptPartialRow |
| 1900 |
); |
| 1901 |
} |
| 1902 |
|
| 1903 |
|
| 1904 |
TableSize TableControl_Impl::impl_getVisibleColumns( bool _bAcceptPartialCol ) const |
| 1905 |
{ |
| 1906 |
DBG_ASSERT( m_pDataWindow, "TableControl_Impl::impl_getVisibleColumns: no data window!" ); |
| 1907 |
|
| 1908 |
return lcl_getColumnsVisibleWithin( |
| 1909 |
tools::Rectangle( Point( 0, 0 ), m_pDataWindow->GetOutputSizePixel() ), |
| 1910 |
m_nLeftColumn, |
| 1911 |
*this, |
| 1912 |
_bAcceptPartialCol |
| 1913 |
); |
| 1914 |
} |
| 1915 |
|
| 1916 |
|
| 1917 |
bool TableControl_Impl::goTo( ColPos _nColumn, RowPos _nRow ) |
| 1918 |
{ |
| 1919 |
// TODO: give veto listeners a chance |
| 1920 |
|
| 1921 |
if ( ( _nColumn < 0 ) || ( _nColumn >= m_nColumnCount ) |
| 1922 |
|| ( _nRow < 0 ) || ( _nRow >= m_nRowCount ) |
| 1923 |
) |
| 1924 |
{ |
| 1925 |
OSL_ENSURE( false, "TableControl_Impl::goTo: invalid row or column index!" ); |
| 1926 |
return false; |
| 1927 |
} |
| 1928 |
|
| 1929 |
SuppressCursor aHideCursor( *this ); |
| 1930 |
m_nCurColumn = _nColumn; |
| 1931 |
m_nCurRow = _nRow; |
| 1932 |
|
| 1933 |
// ensure that the new cell is visible |
| 1934 |
ensureVisible( m_nCurColumn, m_nCurRow ); |
| 1935 |
return true; |
| 1936 |
} |
| 1937 |
|
| 1938 |
|
| 1939 |
void TableControl_Impl::ensureVisible( ColPos _nColumn, RowPos _nRow ) |
| 1940 |
{ |
| 1941 |
DBG_ASSERT( ( _nColumn >= 0 ) && ( _nColumn < m_nColumnCount ) |
| 1942 |
&& ( _nRow >= 0 ) && ( _nRow < m_nRowCount ), |
| 1943 |
"TableControl_Impl::ensureVisible: invalid coordinates!" ); |
| 1944 |
|
| 1945 |
SuppressCursor aHideCursor( *this ); |
| 1946 |
|
| 1947 |
if ( _nColumn < m_nLeftColumn ) |
| 1948 |
impl_scrollColumns( _nColumn - m_nLeftColumn ); |
| 1949 |
else |
| 1950 |
{ |
| 1951 |
TableSize nVisibleColumns = impl_getVisibleColumns( false/*bAcceptPartialVisibility*/ ); |
| 1952 |
if ( _nColumn > m_nLeftColumn + nVisibleColumns - 1 ) |
| 1953 |
{ |
| 1954 |
impl_scrollColumns( _nColumn - ( m_nLeftColumn + nVisibleColumns - 1 ) ); |
| 1955 |
// TODO: since not all columns have the same width, this might in theory result |
| 1956 |
// in the column still not being visible. |
| 1957 |
} |
| 1958 |
} |
| 1959 |
|
| 1960 |
if ( _nRow < m_nTopRow ) |
| 1961 |
impl_scrollRows( _nRow - m_nTopRow ); |
| 1962 |
else |
| 1963 |
{ |
| 1964 |
TableSize nVisibleRows = impl_getVisibleRows( false/*_bAcceptPartialVisibility*/ ); |
| 1965 |
if ( _nRow > m_nTopRow + nVisibleRows - 1 ) |
| 1966 |
impl_scrollRows( _nRow - ( m_nTopRow + nVisibleRows - 1 ) ); |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
|
| 1971 |
OUString TableControl_Impl::getCellContentAsString( RowPos const i_row, ColPos const i_col ) |
| 1972 |
{ |
| 1973 |
Any aCellValue; |
| 1974 |
m_pModel->getCellContent( i_col, i_row, aCellValue ); |
| 1975 |
|
| 1976 |
OUString sCellStringContent; |
| 1977 |
m_pModel->getRenderer()->GetFormattedCellString( aCellValue, sCellStringContent ); |
| 1978 |
|
| 1979 |
return sCellStringContent; |
| 1980 |
} |
| 1981 |
|
| 1982 |
|
| 1983 |
TableSize TableControl_Impl::impl_ni_ScrollRows( TableSize _nRowDelta ) |
| 1984 |
{ |
| 1985 |
// compute new top row |
| 1986 |
RowPos nNewTopRow = |
| 1987 |
::std::max( |
| 1988 |
::std::min( static_cast<RowPos>( m_nTopRow + _nRowDelta ), static_cast<RowPos>( m_nRowCount - 1 ) ), |
| 1989 |
RowPos(0) |
| 1990 |
); |
| 1991 |
|
| 1992 |
RowPos nOldTopRow = m_nTopRow; |
| 1993 |
m_nTopRow = nNewTopRow; |
| 1994 |
|
| 1995 |
// if updates are enabled currently, scroll the viewport |
| 1996 |
if ( m_nTopRow != nOldTopRow ) |
| 1997 |
{ |
| 1998 |
SuppressCursor aHideCursor( *this ); |
| 1999 |
// TODO: call an onStartScroll at our listener (or better an own onStartScroll, |
| 2000 |
// which hides the cursor and then calls the listener) |
| 2001 |
// Same for onEndScroll |
| 2002 |
|
| 2003 |
// scroll the view port, if possible |
| 2004 |
tools::Long nPixelDelta = m_nRowHeightPixel * ( m_nTopRow - nOldTopRow ); |
| 2005 |
|
| 2006 |
tools::Rectangle aDataArea( Point( 0, m_nColHeaderHeightPixel ), m_pDataWindow->GetOutputSizePixel() ); |
| 2007 |
|
| 2008 |
if ( m_pDataWindow->GetBackground().IsScrollable() |
| 2009 |
&& std::abs( nPixelDelta ) < aDataArea.GetHeight() |
| 2010 |
) |
| 2011 |
{ |
| 2012 |
m_pDataWindow->Scroll( 0, static_cast<tools::Long>(-nPixelDelta), aDataArea, ScrollFlags::Clip | ScrollFlags::Update | ScrollFlags::Children); |
| 2013 |
} |
| 2014 |
else |
| 2015 |
{ |
| 2016 |
m_pDataWindow->Invalidate( InvalidateFlags::Update ); |
| 2017 |
m_pDataWindow->GetParent()->Invalidate( InvalidateFlags::Transparent ); |
| 2018 |
} |
| 2019 |
|
| 2020 |
// update the position at the vertical scrollbar |
| 2021 |
if ( m_pVScroll != nullptr ) |
| 2022 |
m_pVScroll->SetThumbPos( m_nTopRow ); |
| 2023 |
} |
| 2024 |
|
| 2025 |
// The scroll bar availability might change when we scrolled. |
| 2026 |
// For instance, imagine a view with 10 rows, if which 5 fit into the window, numbered 1 to 10. |
| 2027 |
// Now let |
| 2028 |
// - the user scroll to row number 6, so the last 5 rows are visible |
| 2029 |
// - somebody remove the last 4 rows |
| 2030 |
// - the user scroll to row number 5 being the top row, so the last two rows are visible |
| 2031 |
// - somebody remove row number 6 |
| 2032 |
// - the user scroll to row number 1 |
| 2033 |
// => in this case, the need for the scrollbar vanishes immediately. |
| 2034 |
if ( m_nTopRow == 0 ) |
| 2035 |
m_rAntiImpl.PostUserEvent( LINK( this, TableControl_Impl, OnUpdateScrollbars ) ); |
| 2036 |
|
| 2037 |
return static_cast<TableSize>( m_nTopRow - nOldTopRow ); |
| 2038 |
} |
| 2039 |
|
| 2040 |
|
| 2041 |
TableSize TableControl_Impl::impl_scrollRows( TableSize const i_rowDelta ) |
| 2042 |
{ |
| 2043 |
return impl_ni_ScrollRows( i_rowDelta ); |
| 2044 |
} |
| 2045 |
|
| 2046 |
|
| 2047 |
TableSize TableControl_Impl::impl_ni_ScrollColumns( TableSize _nColumnDelta ) |
| 2048 |
{ |
| 2049 |
// compute new left column |
| 2050 |
const ColPos nNewLeftColumn = |
| 2051 |
::std::max( |
| 2052 |
::std::min( static_cast<ColPos>( m_nLeftColumn + _nColumnDelta ), static_cast<ColPos>( m_nColumnCount - 1 ) ), |
| 2053 |
ColPos(0) |
| 2054 |
); |
| 2055 |
|
| 2056 |
const ColPos nOldLeftColumn = m_nLeftColumn; |
| 2057 |
m_nLeftColumn = nNewLeftColumn; |
| 2058 |
|
| 2059 |
// if updates are enabled currently, scroll the viewport |
| 2060 |
if ( m_nLeftColumn != nOldLeftColumn ) |
| 2061 |
{ |
| 2062 |
SuppressCursor aHideCursor( *this ); |
| 2063 |
// TODO: call an onStartScroll at our listener (or better an own onStartScroll, |
| 2064 |
// which hides the cursor and then calls the listener) |
| 2065 |
// Same for onEndScroll |
| 2066 |
|
| 2067 |
// scroll the view port, if possible |
| 2068 |
const tools::Rectangle aDataArea( Point( m_nRowHeaderWidthPixel, 0 ), m_pDataWindow->GetOutputSizePixel() ); |
| 2069 |
|
| 2070 |
tools::Long nPixelDelta = |
| 2071 |
m_aColumnWidths[ nOldLeftColumn ].getStart() |
| 2072 |
- m_aColumnWidths[ m_nLeftColumn ].getStart(); |
| 2073 |
|
| 2074 |
// update our column positions |
| 2075 |
// Do this *before* scrolling, as ScrollFlags::Update will trigger a paint, which already needs the correct |
| 2076 |
// information in m_aColumnWidths |
| 2077 |
for (auto & columnWidth : m_aColumnWidths) |
| 2078 |
{ |
| 2079 |
columnWidth.move(nPixelDelta); |
| 2080 |
} |
| 2081 |
|
| 2082 |
// scroll the window content (if supported and possible), or invalidate the complete window |
| 2083 |
if ( m_pDataWindow->GetBackground().IsScrollable() |
| 2084 |
&& std::abs( nPixelDelta ) < aDataArea.GetWidth() |
| 2085 |
) |
| 2086 |
{ |
| 2087 |
m_pDataWindow->Scroll( nPixelDelta, 0, aDataArea, ScrollFlags::Clip | ScrollFlags::Update ); |
| 2088 |
} |
| 2089 |
else |
| 2090 |
{ |
| 2091 |
m_pDataWindow->Invalidate( InvalidateFlags::Update ); |
| 2092 |
m_pDataWindow->GetParent()->Invalidate( InvalidateFlags::Transparent ); |
| 2093 |
} |
| 2094 |
|
| 2095 |
// update the position at the horizontal scrollbar |
| 2096 |
if ( m_pHScroll != nullptr ) |
| 2097 |
m_pHScroll->SetThumbPos( m_nLeftColumn ); |
| 2098 |
} |
| 2099 |
|
| 2100 |
// The scroll bar availability might change when we scrolled. This is because we do not hide |
| 2101 |
// the scrollbar when it is, in theory, unnecessary, but currently at a position > 0. In this case, it will |
| 2102 |
// be auto-hidden when it's scrolled back to pos 0. |
| 2103 |
if ( m_nLeftColumn == 0 ) |
| 2104 |
m_rAntiImpl.PostUserEvent( LINK( this, TableControl_Impl, OnUpdateScrollbars ) ); |
| 2105 |
|
| 2106 |
return static_cast<TableSize>( m_nLeftColumn - nOldLeftColumn ); |
| 2107 |
} |
| 2108 |
|
| 2109 |
|
| 2110 |
TableSize TableControl_Impl::impl_scrollColumns( TableSize const i_columnDelta ) |
| 2111 |
{ |
| 2112 |
return impl_ni_ScrollColumns( i_columnDelta ); |
| 2113 |
} |
| 2114 |
|
| 2115 |
|
| 2116 |
SelectionEngine* TableControl_Impl::getSelEngine() |
| 2117 |
{ |
| 2118 |
return m_pSelEngine.get(); |
| 2119 |
} |
| 2120 |
|
| 2121 |
bool TableControl_Impl::isRowSelected( RowPos i_row ) const |
| 2122 |
{ |
| 2123 |
return ::std::find( m_aSelectedRows.begin(), m_aSelectedRows.end(), i_row ) != m_aSelectedRows.end(); |
| 2124 |
} |
| 2125 |
|
| 2126 |
|
| 2127 |
RowPos TableControl_Impl::getSelectedRowIndex( size_t const i_selectionIndex ) const |
| 2128 |
{ |
| 2129 |
if ( i_selectionIndex < m_aSelectedRows.size() ) |
| 2130 |
return m_aSelectedRows[ i_selectionIndex ]; |
| 2131 |
return ROW_INVALID; |
| 2132 |
} |
| 2133 |
|
| 2134 |
|
| 2135 |
int TableControl_Impl::getRowSelectedNumber(const ::std::vector<RowPos>& selectedRows, RowPos current) |
| 2136 |
{ |
| 2137 |
std::vector<RowPos>::const_iterator it = ::std::find(selectedRows.begin(),selectedRows.end(),current); |
| 2138 |
if ( it != selectedRows.end() ) |
| 2139 |
{ |
| 2140 |
return it - selectedRows.begin(); |
| 2141 |
} |
| 2142 |
return -1; |
| 2143 |
} |
| 2144 |
|
| 2145 |
|
| 2146 |
ColPos TableControl_Impl::impl_getColumnForOrdinate( tools::Long const i_ordinate ) const |
| 2147 |
{ |
| 2148 |
if ( ( m_aColumnWidths.empty() ) || ( i_ordinate < 0 ) ) |
| 2149 |
return COL_INVALID; |
| 2150 |
|
| 2151 |
if ( i_ordinate < m_nRowHeaderWidthPixel ) |
| 2152 |
return COL_ROW_HEADERS; |
| 2153 |
|
| 2154 |
ColumnPositions::const_iterator lowerBound = ::std::lower_bound( |
| 2155 |
m_aColumnWidths.begin(), |
| 2156 |
m_aColumnWidths.end(), |
| 2157 |
MutableColumnMetrics(i_ordinate+1, i_ordinate+1), |
| 2158 |
ColumnInfoPositionLess() |
| 2159 |
); |
| 2160 |
if ( lowerBound == m_aColumnWidths.end() ) |
| 2161 |
{ |
| 2162 |
// point is *behind* the start of the last column ... |
| 2163 |
if ( i_ordinate < m_aColumnWidths.rbegin()->getEnd() ) |
| 2164 |
// ... but still before its end |
| 2165 |
return m_nColumnCount - 1; |
| 2166 |
return COL_INVALID; |
| 2167 |
} |
| 2168 |
return lowerBound - m_aColumnWidths.begin(); |
| 2169 |
} |
| 2170 |
|
| 2171 |
|
| 2172 |
RowPos TableControl_Impl::impl_getRowForAbscissa( tools::Long const i_abscissa ) const |
| 2173 |
{ |
| 2174 |
if ( i_abscissa < 0 ) |
| 2175 |
return ROW_INVALID; |
| 2176 |
|
| 2177 |
if ( i_abscissa < m_nColHeaderHeightPixel ) |
| 2178 |
return ROW_COL_HEADERS; |
| 2179 |
|
| 2180 |
tools::Long const abscissa = i_abscissa - m_nColHeaderHeightPixel; |
| 2181 |
tools::Long const row = m_nTopRow + abscissa / m_nRowHeightPixel; |
| 2182 |
return row < m_pModel->getRowCount() ? row : ROW_INVALID; |
| 2183 |
} |
| 2184 |
|
| 2185 |
|
| 2186 |
bool TableControl_Impl::markRowAsDeselected( RowPos const i_rowIndex ) |
| 2187 |
{ |
| 2188 |
::std::vector< RowPos >::iterator selPos = ::std::find( m_aSelectedRows.begin(), m_aSelectedRows.end(), i_rowIndex ); |
| 2189 |
if ( selPos == m_aSelectedRows.end() ) |
| 2190 |
return false; |
| 2191 |
|
| 2192 |
m_aSelectedRows.erase( selPos ); |
| 2193 |
return true; |
| 2194 |
} |
| 2195 |
|
| 2196 |
|
| 2197 |
bool TableControl_Impl::markRowAsSelected( RowPos const i_rowIndex ) |
| 2198 |
{ |
| 2199 |
if ( isRowSelected( i_rowIndex ) ) |
| 2200 |
return false; |
| 2201 |
|
| 2202 |
SelectionMode const eSelMode = getSelEngine()->GetSelectionMode(); |
| 2203 |
switch ( eSelMode ) |
| 2204 |
{ |
| 2205 |
case SelectionMode::Single: |
| 2206 |
if ( !m_aSelectedRows.empty() ) |
| 2207 |
{ |
| 2208 |
OSL_ENSURE( m_aSelectedRows.size() == 1, "TableControl::markRowAsSelected: SingleSelection with more than one selected element?" ); |
| 2209 |
m_aSelectedRows[0] = i_rowIndex; |
| 2210 |
break; |
| 2211 |
} |
| 2212 |
[[fallthrough]]; |
| 2213 |
|
| 2214 |
case SelectionMode::Multiple: |
| 2215 |
m_aSelectedRows.push_back( i_rowIndex ); |
| 2216 |
break; |
| 2217 |
|
| 2218 |
default: |
| 2219 |
OSL_ENSURE( false, "TableControl_Impl::markRowAsSelected: unsupported selection mode!" ); |
| 2220 |
return false; |
| 2221 |
} |
| 2222 |
|
| 2223 |
return true; |
| 2224 |
} |
| 2225 |
|
| 2226 |
|
| 2227 |
bool TableControl_Impl::markAllRowsAsDeselected() |
| 2228 |
{ |
| 2229 |
if ( m_aSelectedRows.empty() ) |
| 2230 |
return false; |
| 2231 |
|
| 2232 |
m_aSelectedRows.clear(); |
| 2233 |
return true; |
| 2234 |
} |
| 2235 |
|
| 2236 |
|
| 2237 |
bool TableControl_Impl::markAllRowsAsSelected() |
| 2238 |
{ |
| 2239 |
SelectionMode const eSelMode = getSelEngine()->GetSelectionMode(); |
| 2240 |
ENSURE_OR_RETURN_FALSE( eSelMode == SelectionMode::Multiple, "TableControl_Impl::markAllRowsAsSelected: unsupported selection mode!" ); |
| 2241 |
|
| 2242 |
if ( m_aSelectedRows.size() == size_t( m_pModel->getRowCount() ) ) |
| 2243 |
{ |
| 2244 |
#if OSL_DEBUG_LEVEL > 0 |
| 2245 |
for ( TableSize row = 0; row < m_pModel->getRowCount(); ++row ) |
| 2246 |
{ |
| 2247 |
OSL_ENSURE( isRowSelected( row ), "TableControl_Impl::markAllRowsAsSelected: inconsistency in the selected rows!" ); |
| 2248 |
} |
| 2249 |
#endif |
| 2250 |
// already all rows marked as selected |
| 2251 |
return false; |
| 2252 |
} |
| 2253 |
|
| 2254 |
m_aSelectedRows.clear(); |
| 2255 |
for ( RowPos i=0; i < m_pModel->getRowCount(); ++i ) |
| 2256 |
m_aSelectedRows.push_back(i); |
| 2257 |
|
| 2258 |
return true; |
| 2259 |
} |
| 2260 |
|
| 2261 |
|
| 2262 |
void TableControl_Impl::commitAccessibleEvent( sal_Int16 const i_eventID ) |
| 2263 |
{ |
| 2264 |
impl_commitAccessibleEvent( i_eventID, Any() ); |
| 2265 |
} |
| 2266 |
|
| 2267 |
|
| 2268 |
void TableControl_Impl::commitCellEvent( sal_Int16 const i_eventID, const Any& i_newValue, const Any& i_oldValue ) |
| 2269 |
{ |
| 2270 |
if (m_xAccessibleTable.is()) |
| 2271 |
m_xAccessibleTable->commitCellEvent(i_eventID, i_newValue, i_oldValue); |
| 2272 |
} |
| 2273 |
|
| 2274 |
|
| 2275 |
void TableControl_Impl::commitTableEvent( sal_Int16 const i_eventID, const Any& i_newValue, const Any& i_oldValue ) |
| 2276 |
{ |
| 2277 |
if (m_xAccessibleTable.is()) |
| 2278 |
m_xAccessibleTable->commitTableEvent(i_eventID, i_newValue, i_oldValue); |
| 2279 |
} |
| 2280 |
|
| 2281 |
|
| 2282 |
tools::Rectangle TableControl_Impl::calcHeaderRect(bool bColHeader) |
| 2283 |
{ |
| 2284 |
tools::Rectangle const aRectTableWithHeaders( impl_getAllVisibleCellsArea() ); |
| 2285 |
Size const aSizeTableWithHeaders( aRectTableWithHeaders.GetSize() ); |
| 2286 |
if ( bColHeader ) |
| 2287 |
return tools::Rectangle( aRectTableWithHeaders.TopLeft(), Size( aSizeTableWithHeaders.Width(), m_nColHeaderHeightPixel ) ); |
| 2288 |
else |
| 2289 |
return tools::Rectangle( aRectTableWithHeaders.TopLeft(), Size( m_nRowHeaderWidthPixel, aSizeTableWithHeaders.Height() ) ); |
| 2290 |
} |
| 2291 |
|
| 2292 |
|
| 2293 |
tools::Rectangle TableControl_Impl::calcHeaderCellRect( bool bColHeader, sal_Int32 nPos ) |
| 2294 |
{ |
| 2295 |
tools::Rectangle const aHeaderRect = calcHeaderRect( bColHeader ); |
| 2296 |
TableCellGeometry const aGeometry( |
| 2297 |
*this, aHeaderRect, |
| 2298 |
bColHeader ? nPos : COL_ROW_HEADERS, |
| 2299 |
bColHeader ? ROW_COL_HEADERS : nPos |
| 2300 |
); |
| 2301 |
return aGeometry.getRect(); |
| 2302 |
} |
| 2303 |
|
| 2304 |
|
| 2305 |
tools::Rectangle TableControl_Impl::calcTableRect() const |
| 2306 |
{ |
| 2307 |
return impl_getAllVisibleDataCellArea(); |
| 2308 |
} |
| 2309 |
|
| 2310 |
|
| 2311 |
tools::Rectangle TableControl_Impl::calcCellRect( sal_Int32 nRow, sal_Int32 nCol ) const |
| 2312 |
{ |
| 2313 |
if (!m_pModel || (nRow == ROW_INVALID) || (nCol == COL_INVALID)) |
| 2314 |
return tools::Rectangle(); |
| 2315 |
|
| 2316 |
TableCellGeometry aCell(*this, impl_getAllVisibleCellsArea(), nCol, nRow); |
| 2317 |
return aCell.getRect(); |
| 2318 |
} |
| 2319 |
|
| 2320 |
|
| 2321 |
IMPL_LINK_NOARG( TableControl_Impl, OnUpdateScrollbars, void*, void ) |
| 2322 |
{ |
| 2323 |
// TODO: can't we simply use lcl_updateScrollbar here, so the scrollbars ranges are updated, instead of |
| 2324 |
// doing a complete re-layout? |
| 2325 |
impl_ni_relayout(); |
| 2326 |
} |
| 2327 |
|
| 2328 |
|
| 2329 |
IMPL_LINK( TableControl_Impl, OnScroll, ScrollBar*, _pScrollbar, void ) |
| 2330 |
{ |
| 2331 |
DBG_ASSERT( ( _pScrollbar == m_pVScroll ) || ( _pScrollbar == m_pHScroll ), |
| 2332 |
"TableControl_Impl::OnScroll: where did this come from?" ); |
| 2333 |
|
| 2334 |
if ( _pScrollbar == m_pVScroll ) |
| 2335 |
impl_ni_ScrollRows( _pScrollbar->GetDelta() ); |
| 2336 |
else |
| 2337 |
impl_ni_ScrollColumns( _pScrollbar->GetDelta() ); |
| 2338 |
} |
| 2339 |
|
| 2340 |
const rtl::Reference<accessibility::AccessibleGridControl>& |
| 2341 |
TableControl_Impl::getAccessible(const css::uno::Reference<css::accessibility::XAccessible>& rxParent) |
| 2342 |
{ |
| 2343 |
if (m_xAccessibleTable.is()) |
| 2344 |
return m_xAccessibleTable; |
| 2345 |
|
| 2346 |
DBG_TESTSOLARMUTEX(); |
| 2347 |
if (rxParent.is()) |
| 2348 |
{ |
| 2349 |
m_xAccessibleTable = new accessibility::AccessibleGridControl(rxParent, m_rAntiImpl); |
| 2350 |
} |
| 2351 |
|
| 2352 |
return m_xAccessibleTable; |
| 2353 |
} |
| 2354 |
|
| 2355 |
|
| 2356 |
void TableControl_Impl::disposeAccessible() |
| 2357 |
{ |
| 2358 |
if (m_xAccessibleTable.is()) |
| 2359 |
m_xAccessibleTable->dispose(); |
| 2360 |
m_xAccessibleTable.clear(); |
| 2361 |
} |
| 2362 |
|
| 2363 |
void TableControl_Impl::impl_commitAccessibleEvent( sal_Int16 const i_eventID, Any const & i_newValue ) |
| 2364 |
{ |
| 2365 |
if (m_xAccessibleTable.is()) |
| 2366 |
m_xAccessibleTable->commitEvent(i_eventID, i_newValue, css::uno::Any()); |
| 2367 |
} |
| 2368 |
|
| 2369 |
|
| 2370 |
//= TableFunctionSet |
| 2371 |
|
| 2372 |
|
| 2373 |
TableFunctionSet::TableFunctionSet(TableControl_Impl* _pTableControl) |
| 2374 |
:m_pTableControl( _pTableControl) |
| 2375 |
,m_nCurrentRow( ROW_INVALID ) |
| 2376 |
{ |
| 2377 |
} |
| 2378 |
|
| 2379 |
TableFunctionSet::~TableFunctionSet() |
| 2380 |
{ |
| 2381 |
} |
| 2382 |
|
| 2383 |
void TableFunctionSet::BeginDrag() |
| 2384 |
{ |
| 2385 |
} |
| 2386 |
|
| 2387 |
void TableFunctionSet::CreateAnchor() |
| 2388 |
{ |
| 2389 |
m_pTableControl->setAnchor( m_pTableControl->getCurRow() ); |
| 2390 |
} |
| 2391 |
|
| 2392 |
|
| 2393 |
void TableFunctionSet::DestroyAnchor() |
| 2394 |
{ |
| 2395 |
m_pTableControl->setAnchor( ROW_INVALID ); |
| 2396 |
} |
| 2397 |
|
| 2398 |
|
| 2399 |
void TableFunctionSet::SetCursorAtPoint(const Point& rPoint, bool bDontSelectAtCursor) |
| 2400 |
{ |
| 2401 |
// newRow is the row which includes the point, getCurRow() is the last selected row, before the mouse click |
| 2402 |
RowPos newRow = m_pTableControl->getRowAtPoint( rPoint ); |
| 2403 |
if ( newRow == ROW_COL_HEADERS ) |
| 2404 |
newRow = m_pTableControl->getTopRow(); |
| 2405 |
|
| 2406 |
ColPos newCol = m_pTableControl->getColAtPoint( rPoint ); |
| 2407 |
if ( newCol == COL_ROW_HEADERS ) |
| 2408 |
newCol = m_pTableControl->getLeftColumn(); |
| 2409 |
|
| 2410 |
if ( ( newRow == ROW_INVALID ) || ( newCol == COL_INVALID ) ) |
| 2411 |
return; |
| 2412 |
|
| 2413 |
if ( bDontSelectAtCursor ) |
| 2414 |
{ |
| 2415 |
if ( m_pTableControl->getSelectedRowCount() > 1 ) |
| 2416 |
m_pTableControl->getSelEngine()->AddAlways(true); |
| 2417 |
} |
| 2418 |
else if ( m_pTableControl->getAnchor() == m_pTableControl->getCurRow() ) |
| 2419 |
{ |
| 2420 |
//selected region lies above the last selection |
| 2421 |
if( m_pTableControl->getCurRow() >= newRow) |
| 2422 |
{ |
| 2423 |
//put selected rows in vector |
| 2424 |
while ( m_pTableControl->getAnchor() >= newRow ) |
| 2425 |
{ |
| 2426 |
m_pTableControl->markRowAsSelected( m_pTableControl->getAnchor() ); |
| 2427 |
m_pTableControl->setAnchor( m_pTableControl->getAnchor() - 1 ); |
| 2428 |
} |
| 2429 |
m_pTableControl->setAnchor( m_pTableControl->getAnchor() + 1 ); |
| 2430 |
} |
| 2431 |
//selected region lies beneath the last selected row |
| 2432 |
else |
| 2433 |
{ |
| 2434 |
while ( m_pTableControl->getAnchor() <= newRow ) |
| 2435 |
{ |
| 2436 |
m_pTableControl->markRowAsSelected( m_pTableControl->getAnchor() ); |
| 2437 |
m_pTableControl->setAnchor( m_pTableControl->getAnchor() + 1 ); |
| 2438 |
} |
| 2439 |
m_pTableControl->setAnchor( m_pTableControl->getAnchor() - 1 ); |
| 2440 |
} |
| 2441 |
m_pTableControl->invalidateSelectedRegion( m_pTableControl->getCurRow(), newRow ); |
| 2442 |
} |
| 2443 |
//no region selected |
| 2444 |
else |
| 2445 |
{ |
| 2446 |
if ( !m_pTableControl->hasRowSelection() ) |
| 2447 |
m_pTableControl->markRowAsSelected( newRow ); |
| 2448 |
else |
| 2449 |
{ |
| 2450 |
if ( m_pTableControl->getSelEngine()->GetSelectionMode() == SelectionMode::Single ) |
| 2451 |
{ |
| 2452 |
DeselectAll(); |
| 2453 |
m_pTableControl->markRowAsSelected( newRow ); |
| 2454 |
} |
| 2455 |
else |
| 2456 |
{ |
| 2457 |
m_pTableControl->markRowAsSelected( newRow ); |
| 2458 |
} |
| 2459 |
} |
| 2460 |
if ( m_pTableControl->getSelectedRowCount() > 1 && m_pTableControl->getSelEngine()->GetSelectionMode() != SelectionMode::Single ) |
| 2461 |
m_pTableControl->getSelEngine()->AddAlways(true); |
| 2462 |
|
| 2463 |
m_pTableControl->invalidateRow( newRow ); |
| 2464 |
} |
| 2465 |
m_pTableControl->goTo( newCol, newRow ); |
| 2466 |
} |
| 2467 |
|
| 2468 |
bool TableFunctionSet::IsSelectionAtPoint( const Point& rPoint ) |
| 2469 |
{ |
| 2470 |
m_pTableControl->getSelEngine()->AddAlways(false); |
| 2471 |
if ( !m_pTableControl->hasRowSelection() ) |
| 2472 |
return false; |
| 2473 |
else |
| 2474 |
{ |
| 2475 |
RowPos curRow = m_pTableControl->getRowAtPoint( rPoint ); |
| 2476 |
m_pTableControl->setAnchor( ROW_INVALID ); |
| 2477 |
bool selected = m_pTableControl->isRowSelected( curRow ); |
| 2478 |
m_nCurrentRow = curRow; |
| 2479 |
return selected; |
| 2480 |
} |
| 2481 |
} |
| 2482 |
|
| 2483 |
void TableFunctionSet::DeselectAtPoint( const Point& ) |
| 2484 |
{ |
| 2485 |
m_pTableControl->invalidateRow( m_nCurrentRow ); |
| 2486 |
m_pTableControl->markRowAsDeselected( m_nCurrentRow ); |
| 2487 |
} |
| 2488 |
|
| 2489 |
|
| 2490 |
void TableFunctionSet::DeselectAll() |
| 2491 |
{ |
| 2492 |
if ( m_pTableControl->hasRowSelection() ) |
| 2493 |
{ |
| 2494 |
for ( size_t i=0; i<m_pTableControl->getSelectedRowCount(); ++i ) |
| 2495 |
{ |
| 2496 |
RowPos const rowIndex = m_pTableControl->getSelectedRowIndex(i); |
| 2497 |
m_pTableControl->invalidateRow( rowIndex ); |
| 2498 |
} |
| 2499 |
|
| 2500 |
m_pTableControl->markAllRowsAsDeselected(); |
| 2501 |
} |
| 2502 |
} |
| 2503 |
|
| 2504 |
|
| 2505 |
} // namespace svt::table |
| 2506 |
|
| 2507 |
|
| 2508 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |