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/svapp.hxx>
22 #include <vcl/settings.hxx>
23 #include "AccessibleCsvControl.hxx"
25 ScCsvLayoutData::ScCsvLayoutData() :
36 mnPosCursor( CSV_POS_INVALID
),
39 mbAppRTL( !!AllSettings::GetLayoutRTL() )
43 ScCsvDiff
ScCsvLayoutData::GetDiff( const ScCsvLayoutData
& rData
) const
45 ScCsvDiff nRet
= CSV_DIFF_EQUAL
;
46 if( mnPosCount
!= rData
.mnPosCount
) nRet
|= CSV_DIFF_POSCOUNT
;
47 if( mnPosOffset
!= rData
.mnPosOffset
) nRet
|= CSV_DIFF_POSOFFSET
;
48 if( mnHdrWidth
!= rData
.mnHdrWidth
) nRet
|= CSV_DIFF_HDRWIDTH
;
49 if( mnCharWidth
!= rData
.mnCharWidth
) nRet
|= CSV_DIFF_CHARWIDTH
;
50 if( mnLineCount
!= rData
.mnLineCount
) nRet
|= CSV_DIFF_LINECOUNT
;
51 if( mnLineOffset
!= rData
.mnLineOffset
) nRet
|= CSV_DIFF_LINEOFFSET
;
52 if( mnHdrHeight
!= rData
.mnHdrHeight
) nRet
|= CSV_DIFF_HDRHEIGHT
;
53 if( mnLineHeight
!= rData
.mnLineHeight
) nRet
|= CSV_DIFF_LINEHEIGHT
;
54 if( mnPosCursor
!= rData
.mnPosCursor
) nRet
|= CSV_DIFF_RULERCURSOR
;
55 if( mnColCursor
!= rData
.mnColCursor
) nRet
|= CSV_DIFF_GRIDCURSOR
;
59 ScCsvControl::ScCsvControl( ScCsvControl
& rParent
) :
60 Control( &rParent
, WB_TABSTOP
| WB_NODIALOGCONTROL
),
61 mrData( rParent
.GetLayoutData() ),
62 mxAccessible( nullptr ),
67 ScCsvControl::ScCsvControl( vcl::Window
* pParent
, const ScCsvLayoutData
& rData
, WinBits nBits
) :
68 Control( pParent
, nBits
),
70 mxAccessible( nullptr ),
75 ScCsvControl::~ScCsvControl()
80 void ScCsvControl::dispose()
82 if( mxAccessible
.is() )
83 mxAccessible
->dispose();
84 mxAccessible
= nullptr; // lp#1566050: prevent cyclic reference zombies
88 // event handling -------------------------------------------------------------
90 void ScCsvControl::GetFocus()
93 AccSendFocusEvent( true );
96 void ScCsvControl::LoseFocus()
99 AccSendFocusEvent( false );
102 void ScCsvControl::AccSendFocusEvent( bool bFocused
)
104 if( mxAccessible
.is() )
105 mxAccessible
->SendFocusEvent( bFocused
);
108 void ScCsvControl::AccSendCaretEvent()
110 if( mxAccessible
.is() )
111 mxAccessible
->SendCaretEvent();
114 void ScCsvControl::AccSendVisibleEvent()
116 if( mxAccessible
.is() )
117 mxAccessible
->SendVisibleEvent();
120 void ScCsvControl::AccSendSelectionEvent()
122 if( mxAccessible
.is() )
123 mxAccessible
->SendSelectionEvent();
126 void ScCsvControl::AccSendTableUpdateEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
, bool bAllRows
)
128 if( mxAccessible
.is() )
129 mxAccessible
->SendTableUpdateEvent( nFirstColumn
, nLastColumn
, bAllRows
);
132 void ScCsvControl::AccSendInsertColumnEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
)
134 if( mxAccessible
.is() )
135 mxAccessible
->SendInsertColumnEvent( nFirstColumn
, nLastColumn
);
138 void ScCsvControl::AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
)
140 if( mxAccessible
.is() )
141 mxAccessible
->SendRemoveColumnEvent( nFirstColumn
, nLastColumn
);
144 // repaint helpers ------------------------------------------------------------
146 void ScCsvControl::Repaint( bool bInvalidate
)
151 Execute( CSVCMD_REPAINT
);
154 void ScCsvControl::DisableRepaint()
156 ++mrData
.mnNoRepaint
;
159 void ScCsvControl::EnableRepaint()
161 OSL_ENSURE( IsNoRepaint(), "ScCsvControl::EnableRepaint - invalid call" );
162 --mrData
.mnNoRepaint
;
166 // command handling -----------------------------------------------------------
168 void ScCsvControl::Execute( ScCsvCmdType eType
, sal_Int32 nParam1
, sal_Int32 nParam2
)
170 maCmd
.Set( eType
, nParam1
, nParam2
);
171 maCmdHdl
.Call( *this );
174 // layout helpers -------------------------------------------------------------
176 sal_Int32
ScCsvControl::GetVisPosCount() const
178 return (mrData
.mnWinWidth
- GetHdrWidth()) / GetCharWidth();
181 sal_Int32
ScCsvControl::GetMaxPosOffset() const
183 return std::max( GetPosCount() - GetVisPosCount() + 2L, 0L );
186 bool ScCsvControl::IsValidSplitPos( sal_Int32 nPos
) const
188 return (0 < nPos
) && (nPos
< GetPosCount() );
191 bool ScCsvControl::IsVisibleSplitPos( sal_Int32 nPos
) const
193 return IsValidSplitPos( nPos
) && (GetFirstVisPos() <= nPos
) && (nPos
<= GetLastVisPos());
196 sal_Int32
ScCsvControl::GetHdrX() const
198 return IsRTL() ? (mrData
.mnWinWidth
- GetHdrWidth()) : 0;
201 sal_Int32
ScCsvControl::GetFirstX() const
203 return IsRTL() ? 0 : GetHdrWidth();
206 sal_Int32
ScCsvControl::GetLastX() const
208 return mrData
.mnWinWidth
- (IsRTL() ? GetHdrWidth() : 0) - 1;
211 sal_Int32
ScCsvControl::GetX( sal_Int32 nPos
) const
213 return GetFirstX() + (nPos
- GetFirstVisPos()) * GetCharWidth();
216 sal_Int32
ScCsvControl::GetPosFromX( sal_Int32 nX
) const
218 return (nX
- GetFirstX() + GetCharWidth() / 2) / GetCharWidth() + GetFirstVisPos();
221 sal_Int32
ScCsvControl::GetVisLineCount() const
223 return (mrData
.mnWinHeight
- GetHdrHeight() - 2) / GetLineHeight() + 1;
226 sal_Int32
ScCsvControl::GetLastVisLine() const
228 return std::min( GetFirstVisLine() + GetVisLineCount(), GetLineCount() ) - 1;
231 sal_Int32
ScCsvControl::GetMaxLineOffset() const
233 return std::max( GetLineCount() - GetVisLineCount() + 1L, 0L );
236 bool ScCsvControl::IsValidLine( sal_Int32 nLine
) const
238 return (0 <= nLine
) && (nLine
< GetLineCount());
241 bool ScCsvControl::IsVisibleLine( sal_Int32 nLine
) const
243 return IsValidLine( nLine
) && (GetFirstVisLine() <= nLine
) && (nLine
<= GetLastVisLine());
246 sal_Int32
ScCsvControl::GetY( sal_Int32 nLine
) const
248 return GetHdrHeight() + (nLine
- GetFirstVisLine()) * GetLineHeight();
251 sal_Int32
ScCsvControl::GetLineFromY( sal_Int32 nY
) const
253 return (nY
- GetHdrHeight()) / GetLineHeight() + GetFirstVisLine();
256 // static helpers -------------------------------------------------------------
258 void ScCsvControl::ImplInvertRect( OutputDevice
& rOutDev
, const Rectangle
& rRect
)
260 rOutDev
.Push( PushFlags::LINECOLOR
| PushFlags::FILLCOLOR
| PushFlags::RASTEROP
);
261 rOutDev
.SetLineColor( Color( COL_BLACK
) );
262 rOutDev
.SetFillColor( Color( COL_BLACK
) );
263 rOutDev
.SetRasterOp( ROP_INVERT
);
264 rOutDev
.DrawRect( rRect
);
268 ScMoveMode
ScCsvControl::GetHorzDirection( sal_uInt16 nCode
, bool bHomeEnd
)
272 case KEY_LEFT
: return MOVE_PREV
;
273 case KEY_RIGHT
: return MOVE_NEXT
;
275 if( bHomeEnd
) switch( nCode
)
277 case KEY_HOME
: return MOVE_FIRST
;
278 case KEY_END
: return MOVE_LAST
;
283 ScMoveMode
ScCsvControl::GetVertDirection( sal_uInt16 nCode
, bool bHomeEnd
)
287 case KEY_UP
: return MOVE_PREV
;
288 case KEY_DOWN
: return MOVE_NEXT
;
289 case KEY_PAGEUP
: return MOVE_PREVPAGE
;
290 case KEY_PAGEDOWN
: return MOVE_NEXTPAGE
;
292 if( bHomeEnd
) switch( nCode
)
294 case KEY_HOME
: return MOVE_FIRST
;
295 case KEY_END
: return MOVE_LAST
;
300 // accessibility --------------------------------------------------------------
302 css::uno::Reference
< css::accessibility::XAccessible
> ScCsvControl::CreateAccessible()
304 mxAccessible
= ImplCreateAccessible().get();
305 return css::uno::Reference
< css::accessibility::XAccessible
>(mxAccessible
.get());
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */