1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <csvcontrol.hxx>
21 #include <vcl/keycodes.hxx>
22 #include <vcl/outdev.hxx>
23 #include <vcl/settings.hxx>
25 ScCsvLayoutData::ScCsvLayoutData() :
36 mnPosCursor( CSV_POS_INVALID
),
39 mbAppRTL( AllSettings::GetLayoutRTL() )
43 ScCsvDiff
ScCsvLayoutData::GetDiff( const ScCsvLayoutData
& rData
) const
45 ScCsvDiff nRet
= ScCsvDiff::Equal
;
46 if( mnPosCount
!= rData
.mnPosCount
) nRet
|= ScCsvDiff::PosCount
;
47 if( mnPosOffset
!= rData
.mnPosOffset
) nRet
|= ScCsvDiff::PosOffset
;
48 if( mnHdrWidth
!= rData
.mnHdrWidth
) nRet
|= ScCsvDiff::HeaderWidth
;
49 if( mnCharWidth
!= rData
.mnCharWidth
) nRet
|= ScCsvDiff::CharWidth
;
50 if( mnLineCount
!= rData
.mnLineCount
) nRet
|= ScCsvDiff::LineCount
;
51 if( mnLineOffset
!= rData
.mnLineOffset
) nRet
|= ScCsvDiff::LineOffset
;
52 if( mnHdrHeight
!= rData
.mnHdrHeight
) nRet
|= ScCsvDiff::HeaderHeight
;
53 if( mnLineHeight
!= rData
.mnLineHeight
) nRet
|= ScCsvDiff::LineHeight
;
54 if( mnPosCursor
!= rData
.mnPosCursor
) nRet
|= ScCsvDiff::RulerCursor
;
55 if( mnColCursor
!= rData
.mnColCursor
) nRet
|= ScCsvDiff::GridCursor
;
59 ScCsvControl::ScCsvControl(const ScCsvLayoutData
& rData
)
65 ScCsvControl::~ScCsvControl()
67 if( mxAccessible
.is() )
68 mxAccessible
->dispose();
69 mxAccessible
= nullptr; // lp#1566050: prevent cyclic reference zombies
72 // event handling -------------------------------------------------------------
74 void ScCsvControl::GetFocus()
76 weld::CustomWidgetController::GetFocus();
77 AccSendFocusEvent( true );
80 void ScCsvControl::LoseFocus()
82 weld::CustomWidgetController::LoseFocus();
83 AccSendFocusEvent( false );
86 void ScCsvControl::AccSendFocusEvent( bool bFocused
)
88 if( mxAccessible
.is() )
89 mxAccessible
->SendFocusEvent( bFocused
);
92 void ScCsvControl::AccSendCaretEvent()
94 if( mxAccessible
.is() )
95 mxAccessible
->SendCaretEvent();
98 void ScCsvControl::AccSendVisibleEvent()
100 if( mxAccessible
.is() )
101 mxAccessible
->SendVisibleEvent();
104 void ScCsvControl::AccSendSelectionEvent()
106 if( mxAccessible
.is() )
107 mxAccessible
->SendSelectionEvent();
110 void ScCsvControl::AccSendTableUpdateEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
, bool bAllRows
)
112 if( mxAccessible
.is() )
113 mxAccessible
->SendTableUpdateEvent( nFirstColumn
, nLastColumn
, bAllRows
);
116 void ScCsvControl::AccSendInsertColumnEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
)
118 if( mxAccessible
.is() )
119 mxAccessible
->SendInsertColumnEvent( nFirstColumn
, nLastColumn
);
122 void ScCsvControl::AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
)
124 if( mxAccessible
.is() )
125 mxAccessible
->SendRemoveColumnEvent( nFirstColumn
, nLastColumn
);
128 // repaint helpers ------------------------------------------------------------
130 void ScCsvControl::Repaint( bool bInvalidate
)
135 Execute( CSVCMD_REPAINT
);
138 void ScCsvControl::DisableRepaint()
140 ++mrData
.mnNoRepaint
;
143 void ScCsvControl::EnableRepaint()
145 OSL_ENSURE( IsNoRepaint(), "ScCsvControl::EnableRepaint - invalid call" );
146 --mrData
.mnNoRepaint
;
150 // command handling -----------------------------------------------------------
152 void ScCsvControl::Execute( ScCsvCmdType eType
, sal_Int32 nParam1
, sal_Int32 nParam2
)
154 maCmd
.Set( eType
, nParam1
, nParam2
);
155 maCmdHdl
.Call( *this );
158 // layout helpers -------------------------------------------------------------
160 sal_Int32
ScCsvControl::GetVisPosCount() const
162 return (mrData
.mnWinWidth
- GetHdrWidth()) / GetCharWidth();
165 sal_Int32
ScCsvControl::GetMaxPosOffset() const
167 return std::max
<sal_Int32
>( GetPosCount() - GetVisPosCount() + 2, 0 );
170 bool ScCsvControl::IsValidSplitPos( sal_Int32 nPos
) const
172 return (0 < nPos
) && (nPos
< GetPosCount() );
175 bool ScCsvControl::IsVisibleSplitPos( sal_Int32 nPos
) const
177 return IsValidSplitPos( nPos
) && (GetFirstVisPos() <= nPos
) && (nPos
<= GetLastVisPos());
180 sal_Int32
ScCsvControl::GetHdrX() const
182 return IsRTL() ? (mrData
.mnWinWidth
- GetHdrWidth()) : 0;
185 sal_Int32
ScCsvControl::GetFirstX() const
187 return IsRTL() ? 0 : GetHdrWidth();
190 sal_Int32
ScCsvControl::GetLastX() const
192 return mrData
.mnWinWidth
- (IsRTL() ? GetHdrWidth() : 0) - 1;
195 sal_Int32
ScCsvControl::GetX( sal_Int32 nPos
) const
197 return GetFirstX() + (nPos
- GetFirstVisPos()) * GetCharWidth();
200 sal_Int32
ScCsvControl::GetPosFromX( sal_Int32 nX
) const
202 return (nX
- GetFirstX() + GetCharWidth() / 2) / GetCharWidth() + GetFirstVisPos();
205 sal_Int32
ScCsvControl::GetVisLineCount() const
207 return (mrData
.mnWinHeight
- GetHdrHeight() - 2) / GetLineHeight() + 1;
210 sal_Int32
ScCsvControl::GetLastVisLine() const
212 return std::min( GetFirstVisLine() + GetVisLineCount(), GetLineCount() ) - 1;
215 sal_Int32
ScCsvControl::GetMaxLineOffset() const
217 return std::max
<sal_Int32
>( GetLineCount() - GetVisLineCount() + 1, 0 );
220 bool ScCsvControl::IsValidLine( sal_Int32 nLine
) const
222 return (0 <= nLine
) && (nLine
< GetLineCount());
225 bool ScCsvControl::IsVisibleLine( sal_Int32 nLine
) const
227 return IsValidLine( nLine
) && (GetFirstVisLine() <= nLine
) && (nLine
<= GetLastVisLine());
230 sal_Int32
ScCsvControl::GetY( sal_Int32 nLine
) const
232 return GetHdrHeight() + (nLine
- GetFirstVisLine()) * GetLineHeight();
235 sal_Int32
ScCsvControl::GetLineFromY( sal_Int32 nY
) const
237 return (nY
- GetHdrHeight()) / GetLineHeight() + GetFirstVisLine();
240 // static helpers -------------------------------------------------------------
242 void ScCsvControl::ImplInvertRect( OutputDevice
& rOutDev
, const tools::Rectangle
& rRect
)
244 rOutDev
.Push( vcl::PushFlags::LINECOLOR
| vcl::PushFlags::FILLCOLOR
| vcl::PushFlags::RASTEROP
);
245 rOutDev
.SetLineColor( COL_BLACK
);
246 rOutDev
.SetFillColor( COL_BLACK
);
247 rOutDev
.SetRasterOp( RasterOp::Invert
);
248 rOutDev
.DrawRect( rRect
);
252 ScMoveMode
ScCsvControl::GetHorzDirection( sal_uInt16 nCode
, bool bHomeEnd
)
256 case KEY_LEFT
: return MOVE_PREV
;
257 case KEY_RIGHT
: return MOVE_NEXT
;
259 if( bHomeEnd
) switch( nCode
)
261 case KEY_HOME
: return MOVE_FIRST
;
262 case KEY_END
: return MOVE_LAST
;
267 ScMoveMode
ScCsvControl::GetVertDirection( sal_uInt16 nCode
, bool bHomeEnd
)
271 case KEY_UP
: return MOVE_PREV
;
272 case KEY_DOWN
: return MOVE_NEXT
;
273 case KEY_PAGEUP
: return MOVE_PREVPAGE
;
274 case KEY_PAGEDOWN
: return MOVE_NEXTPAGE
;
276 if( bHomeEnd
) switch( nCode
)
278 case KEY_HOME
: return MOVE_FIRST
;
279 case KEY_END
: return MOVE_LAST
;
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */