Files
libreoffice/sc/source/ui/dbgui/csvcontrol.cxx

308 lines
8.5 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Herbert Duerr i#118735 prevent endless loop if vlookup/hlookup doesn't find anything http://svn.apache.org/viewvc?view=revision&revision=1239673 Patches contributed by Andre Fischer remove lp_solver http://svn.apache.org/viewvc?view=revision&revision=1199180 i#118160: Added external CoinMP library. http://svn.apache.org/viewvc?view=revision&revision=1233909 Patches contributed by Armin Le-Grand i#118485 - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 i#118524: apply patch, followup fixes to 118485 http://svn.apache.org/viewvc?view=revision&revision=1186077 Patches contributed by lihuiibm i#108860 - Fix range validation. http://svn.apache.org/viewvc?view=revision&revision=1242846 i#118954 Chart data will lost after copy to different file http://svn.apache.org/viewvc?view=revision&revision=1301345 Patches contributed by Ariel Constenla-Haile Fix Linux build breaker: extra qualification on member http://svn.apache.org/viewvc?view=revision&revision=1301591 i#118696 - i#118697 - Fix some Sheet Tab Color API issues http://svn.apache.org/viewvc?view=revision&revision=1225428 i#118697 - Fix uninitialized variable http://svn.apache.org/viewvc?view=revision&revision=1225859 i#118771 - ScUndoImportTab should preserve tab background color http://svn.apache.org/viewvc?view=revision&revision=1230356 i#118921 - Repaint linked sheet tab background color after updating link http://svn.apache.org/viewvc?view=revision&revision=1245177 i#118927 - Undo/Redo "Update Link" does not reset sheet tab color http://svn.apache.org/viewvc?view=revision&revision=1245241 i#118747 - Copy tab color when transferring sheets across documents http://svn.apache.org/viewvc?view=revision&revision=1230355 Patch contributed by Oliver Rainer-Wittman i#118012 - methods <ScBroadcastAreaSlot::AreaBroadcast(..)> and <ScBroadcastAreaSlot::AreaBroadcastInRange(..)> adapt stl-container iteration in order to avoid destroyed iterators during iteration. http://svn.apache.org/viewvc?view=revision&revision=1297916 Patches contributed by Mathias Bauer gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 Patch contributed by Daniel Rentz calc69: #i116936# fix VBA symbol Cells http://svn.apache.org/viewvc?view=revision&revision=1172135 Patches contributed by leiw: i#118546 CPU 100% on switched off AutoCalculate with Conditional Formatting on date values http://svn.apache.org/viewvc?view=revision&revision=1301380 Re-add new function documentation. Many various cleanups. Add missing calc66: #o11817313# also look at formula result number format, remove redundant binaries.
2012-11-30 12:23:25 +00:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "csvcontrol.hxx"
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
2002-08-15 08:29:12 +00:00
#include "AccessibleCsvControl.hxx"
ScCsvLayoutData::ScCsvLayoutData() :
mnPosCount( 1 ),
mnPosOffset( 0 ),
mnWinWidth( 1 ),
mnHdrWidth( 0 ),
mnCharWidth( 1 ),
mnLineCount( 1 ),
mnLineOffset( 0 ),
mnWinHeight( 1 ),
mnHdrHeight( 0 ),
mnLineHeight( 1 ),
2002-08-16 12:01:00 +00:00
mnPosCursor( CSV_POS_INVALID ),
mnColCursor( 0 ),
mnNoRepaint( 0 ),
mbAppRTL( !!AllSettings::GetLayoutRTL() )
{
}
2002-08-01 11:48:33 +00:00
ScCsvDiff ScCsvLayoutData::GetDiff( const ScCsvLayoutData& rData ) const
{
2002-08-01 11:48:33 +00:00
ScCsvDiff nRet = CSV_DIFF_EQUAL;
if( mnPosCount != rData.mnPosCount ) nRet |= CSV_DIFF_POSCOUNT;
if( mnPosOffset != rData.mnPosOffset ) nRet |= CSV_DIFF_POSOFFSET;
if( mnHdrWidth != rData.mnHdrWidth ) nRet |= CSV_DIFF_HDRWIDTH;
if( mnCharWidth != rData.mnCharWidth ) nRet |= CSV_DIFF_CHARWIDTH;
if( mnLineCount != rData.mnLineCount ) nRet |= CSV_DIFF_LINECOUNT;
if( mnLineOffset != rData.mnLineOffset ) nRet |= CSV_DIFF_LINEOFFSET;
if( mnHdrHeight != rData.mnHdrHeight ) nRet |= CSV_DIFF_HDRHEIGHT;
if( mnLineHeight != rData.mnLineHeight ) nRet |= CSV_DIFF_LINEHEIGHT;
if( mnPosCursor != rData.mnPosCursor ) nRet |= CSV_DIFF_RULERCURSOR;
if( mnColCursor != rData.mnColCursor ) nRet |= CSV_DIFF_GRIDCURSOR;
return nRet;
}
ScCsvControl::ScCsvControl( ScCsvControl& rParent ) :
Control( &rParent, WB_TABSTOP | WB_NODIALOGCONTROL ),
mrData( rParent.GetLayoutData() ),
mxAccessible( NULL ),
mbValidGfx( false )
{
}
ScCsvControl::ScCsvControl( vcl::Window* pParent, const ScCsvLayoutData& rData, WinBits nBits ) :
Control( pParent, nBits ),
mrData( rData ),
mxAccessible( NULL ),
mbValidGfx( false )
{
}
2002-08-15 08:29:12 +00:00
ScCsvControl::~ScCsvControl()
{
disposeOnce();
}
void ScCsvControl::dispose()
2002-08-15 08:29:12 +00:00
{
if( mxAccessible.is() )
mxAccessible->dispose();
Control::dispose();
2002-08-15 08:29:12 +00:00
}
// event handling -------------------------------------------------------------
void ScCsvControl::GetFocus()
{
Control::GetFocus();
AccSendFocusEvent( true );
}
void ScCsvControl::LoseFocus()
{
Control::LoseFocus();
AccSendFocusEvent( false );
}
void ScCsvControl::AccSendFocusEvent( bool bFocused )
{
if( mxAccessible.is() )
mxAccessible->SendFocusEvent( bFocused );
2002-08-15 08:29:12 +00:00
}
void ScCsvControl::AccSendCaretEvent()
{
if( mxAccessible.is() )
mxAccessible->SendCaretEvent();
2002-08-15 08:29:12 +00:00
}
2002-08-16 12:01:00 +00:00
void ScCsvControl::AccSendVisibleEvent()
{
if( mxAccessible.is() )
mxAccessible->SendVisibleEvent();
2002-08-16 12:01:00 +00:00
}
2002-08-15 08:29:12 +00:00
void ScCsvControl::AccSendSelectionEvent()
{
if( mxAccessible.is() )
mxAccessible->SendSelectionEvent();
2002-08-15 08:29:12 +00:00
}
void ScCsvControl::AccSendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows )
{
if( mxAccessible.is() )
mxAccessible->SendTableUpdateEvent( nFirstColumn, nLastColumn, bAllRows );
2002-08-15 08:29:12 +00:00
}
void ScCsvControl::AccSendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn )
{
if( mxAccessible.is() )
mxAccessible->SendInsertColumnEvent( nFirstColumn, nLastColumn );
2002-08-15 08:29:12 +00:00
}
void ScCsvControl::AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn )
{
if( mxAccessible.is() )
mxAccessible->SendRemoveColumnEvent( nFirstColumn, nLastColumn );
2002-08-15 08:29:12 +00:00
}
2002-08-01 11:48:33 +00:00
// repaint helpers ------------------------------------------------------------
void ScCsvControl::Repaint( bool bInvalidate )
{
if( bInvalidate )
InvalidateGfx();
if( !IsNoRepaint() )
2002-08-01 11:48:33 +00:00
Execute( CSVCMD_REPAINT );
}
void ScCsvControl::DisableRepaint()
{
++mrData.mnNoRepaint;
}
void ScCsvControl::EnableRepaint( bool bInvalidate )
{
OSL_ENSURE( IsNoRepaint(), "ScCsvControl::EnableRepaint - invalid call" );
--mrData.mnNoRepaint;
Repaint( bInvalidate );
}
2002-08-01 11:48:33 +00:00
// command handling -----------------------------------------------------------
2002-08-01 11:48:33 +00:00
void ScCsvControl::Execute( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 )
{
2002-08-01 11:48:33 +00:00
maCmd.Set( eType, nParam1, nParam2 );
maCmdHdl.Call( this );
}
// layout helpers -------------------------------------------------------------
sal_Int32 ScCsvControl::GetVisPosCount() const
{
return (mrData.mnWinWidth - GetHdrWidth()) / GetCharWidth();
}
sal_Int32 ScCsvControl::GetMaxPosOffset() const
{
return std::max( GetPosCount() - GetVisPosCount() + 2L, 0L );
}
bool ScCsvControl::IsValidSplitPos( sal_Int32 nPos ) const
{
return (0 < nPos) && (nPos < GetPosCount() );
}
bool ScCsvControl::IsVisibleSplitPos( sal_Int32 nPos ) const
{
return IsValidSplitPos( nPos ) && (GetFirstVisPos() <= nPos) && (nPos <= GetLastVisPos());
}
sal_Int32 ScCsvControl::GetHdrX() const
{
return IsRTL() ? (mrData.mnWinWidth - GetHdrWidth()) : 0;
}
sal_Int32 ScCsvControl::GetFirstX() const
{
return IsRTL() ? 0 : GetHdrWidth();
}
sal_Int32 ScCsvControl::GetLastX() const
{
return mrData.mnWinWidth - (IsRTL() ? GetHdrWidth() : 0) - 1;
}
sal_Int32 ScCsvControl::GetX( sal_Int32 nPos ) const
{
return GetFirstX() + (nPos - GetFirstVisPos()) * GetCharWidth();
}
sal_Int32 ScCsvControl::GetPosFromX( sal_Int32 nX ) const
{
return (nX - GetFirstX() + GetCharWidth() / 2) / GetCharWidth() + GetFirstVisPos();
}
sal_Int32 ScCsvControl::GetVisLineCount() const
{
return (mrData.mnWinHeight - GetHdrHeight() - 2) / GetLineHeight() + 1;
}
sal_Int32 ScCsvControl::GetLastVisLine() const
{
return std::min( GetFirstVisLine() + GetVisLineCount(), GetLineCount() ) - 1;
}
sal_Int32 ScCsvControl::GetMaxLineOffset() const
{
return std::max( GetLineCount() - GetVisLineCount() + 1L, 0L );
}
bool ScCsvControl::IsValidLine( sal_Int32 nLine ) const
{
return (0 <= nLine) && (nLine < GetLineCount());
}
bool ScCsvControl::IsVisibleLine( sal_Int32 nLine ) const
{
return IsValidLine( nLine ) && (GetFirstVisLine() <= nLine) && (nLine <= GetLastVisLine());
}
sal_Int32 ScCsvControl::GetY( sal_Int32 nLine ) const
{
return GetHdrHeight() + (nLine - GetFirstVisLine()) * GetLineHeight();
}
2002-08-15 08:29:12 +00:00
sal_Int32 ScCsvControl::GetLineFromY( sal_Int32 nY ) const
{
return (nY - GetHdrHeight()) / GetLineHeight() + GetFirstVisLine();
2002-08-15 08:29:12 +00:00
}
2002-08-01 11:48:33 +00:00
// static helpers -------------------------------------------------------------
void ScCsvControl::ImplInvertRect( OutputDevice& rOutDev, const Rectangle& rRect )
{
rOutDev.Push( PushFlags::LINECOLOR | PushFlags::FILLCOLOR | PushFlags::RASTEROP );
rOutDev.SetLineColor( Color( COL_BLACK ) );
rOutDev.SetFillColor( Color( COL_BLACK ) );
2002-08-01 11:48:33 +00:00
rOutDev.SetRasterOp( ROP_INVERT );
rOutDev.DrawRect( rRect );
rOutDev.Pop();
2002-08-01 11:48:33 +00:00
}
ScMoveMode ScCsvControl::GetHorzDirection( sal_uInt16 nCode, bool bHomeEnd )
{
switch( nCode )
{
case KEY_LEFT: return MOVE_PREV;
case KEY_RIGHT: return MOVE_NEXT;
}
if( bHomeEnd ) switch( nCode )
{
case KEY_HOME: return MOVE_FIRST;
case KEY_END: return MOVE_LAST;
}
return MOVE_NONE;
}
ScMoveMode ScCsvControl::GetVertDirection( sal_uInt16 nCode, bool bHomeEnd )
{
switch( nCode )
{
case KEY_UP: return MOVE_PREV;
case KEY_DOWN: return MOVE_NEXT;
case KEY_PAGEUP: return MOVE_PREVPAGE;
case KEY_PAGEDOWN: return MOVE_NEXTPAGE;
}
if( bHomeEnd ) switch( nCode )
{
case KEY_HOME: return MOVE_FIRST;
case KEY_END: return MOVE_LAST;
}
return MOVE_NONE;
}
2002-08-15 08:29:12 +00:00
// accessibility --------------------------------------------------------------
ScCsvControl::XAccessibleRef ScCsvControl::CreateAccessible()
{
mxAccessible = ImplCreateAccessible();
return XAccessibleRef(mxAccessible.get());
2002-08-15 08:29:12 +00:00
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */