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() ),
67 ScCsvControl::ScCsvControl( vcl::Window
* pParent
, const ScCsvLayoutData
& rData
, WinBits nBits
) :
68 Control( pParent
, nBits
),
75 ScCsvControl::~ScCsvControl()
80 void ScCsvControl::dispose()
82 if( mxAccessible
.is() )
83 mxAccessible
->dispose();
87 // event handling -------------------------------------------------------------
89 void ScCsvControl::GetFocus()
92 AccSendFocusEvent( true );
95 void ScCsvControl::LoseFocus()
98 AccSendFocusEvent( false );
101 void ScCsvControl::AccSendFocusEvent( bool bFocused
)
103 if( mxAccessible
.is() )
104 mxAccessible
->SendFocusEvent( bFocused
);
107 void ScCsvControl::AccSendCaretEvent()
109 if( mxAccessible
.is() )
110 mxAccessible
->SendCaretEvent();
113 void ScCsvControl::AccSendVisibleEvent()
115 if( mxAccessible
.is() )
116 mxAccessible
->SendVisibleEvent();
119 void ScCsvControl::AccSendSelectionEvent()
121 if( mxAccessible
.is() )
122 mxAccessible
->SendSelectionEvent();
125 void ScCsvControl::AccSendTableUpdateEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
, bool bAllRows
)
127 if( mxAccessible
.is() )
128 mxAccessible
->SendTableUpdateEvent( nFirstColumn
, nLastColumn
, bAllRows
);
131 void ScCsvControl::AccSendInsertColumnEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
)
133 if( mxAccessible
.is() )
134 mxAccessible
->SendInsertColumnEvent( nFirstColumn
, nLastColumn
);
137 void ScCsvControl::AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
)
139 if( mxAccessible
.is() )
140 mxAccessible
->SendRemoveColumnEvent( nFirstColumn
, nLastColumn
);
143 // repaint helpers ------------------------------------------------------------
145 void ScCsvControl::Repaint( bool bInvalidate
)
150 Execute( CSVCMD_REPAINT
);
153 void ScCsvControl::DisableRepaint()
155 ++mrData
.mnNoRepaint
;
158 void ScCsvControl::EnableRepaint( bool bInvalidate
)
160 OSL_ENSURE( IsNoRepaint(), "ScCsvControl::EnableRepaint - invalid call" );
161 --mrData
.mnNoRepaint
;
162 Repaint( bInvalidate
);
165 // command handling -----------------------------------------------------------
167 void ScCsvControl::Execute( ScCsvCmdType eType
, sal_Int32 nParam1
, sal_Int32 nParam2
)
169 maCmd
.Set( eType
, nParam1
, nParam2
);
170 maCmdHdl
.Call( this );
173 // layout helpers -------------------------------------------------------------
175 sal_Int32
ScCsvControl::GetVisPosCount() const
177 return (mrData
.mnWinWidth
- GetHdrWidth()) / GetCharWidth();
180 sal_Int32
ScCsvControl::GetMaxPosOffset() const
182 return std::max( GetPosCount() - GetVisPosCount() + 2L, 0L );
185 bool ScCsvControl::IsValidSplitPos( sal_Int32 nPos
) const
187 return (0 < nPos
) && (nPos
< GetPosCount() );
190 bool ScCsvControl::IsVisibleSplitPos( sal_Int32 nPos
) const
192 return IsValidSplitPos( nPos
) && (GetFirstVisPos() <= nPos
) && (nPos
<= GetLastVisPos());
195 sal_Int32
ScCsvControl::GetHdrX() const
197 return IsRTL() ? (mrData
.mnWinWidth
- GetHdrWidth()) : 0;
200 sal_Int32
ScCsvControl::GetFirstX() const
202 return IsRTL() ? 0 : GetHdrWidth();
205 sal_Int32
ScCsvControl::GetLastX() const
207 return mrData
.mnWinWidth
- (IsRTL() ? GetHdrWidth() : 0) - 1;
210 sal_Int32
ScCsvControl::GetX( sal_Int32 nPos
) const
212 return GetFirstX() + (nPos
- GetFirstVisPos()) * GetCharWidth();
215 sal_Int32
ScCsvControl::GetPosFromX( sal_Int32 nX
) const
217 return (nX
- GetFirstX() + GetCharWidth() / 2) / GetCharWidth() + GetFirstVisPos();
220 sal_Int32
ScCsvControl::GetVisLineCount() const
222 return (mrData
.mnWinHeight
- GetHdrHeight() - 2) / GetLineHeight() + 1;
225 sal_Int32
ScCsvControl::GetLastVisLine() const
227 return std::min( GetFirstVisLine() + GetVisLineCount(), GetLineCount() ) - 1;
230 sal_Int32
ScCsvControl::GetMaxLineOffset() const
232 return std::max( GetLineCount() - GetVisLineCount() + 1L, 0L );
235 bool ScCsvControl::IsValidLine( sal_Int32 nLine
) const
237 return (0 <= nLine
) && (nLine
< GetLineCount());
240 bool ScCsvControl::IsVisibleLine( sal_Int32 nLine
) const
242 return IsValidLine( nLine
) && (GetFirstVisLine() <= nLine
) && (nLine
<= GetLastVisLine());
245 sal_Int32
ScCsvControl::GetY( sal_Int32 nLine
) const
247 return GetHdrHeight() + (nLine
- GetFirstVisLine()) * GetLineHeight();
250 sal_Int32
ScCsvControl::GetLineFromY( sal_Int32 nY
) const
252 return (nY
- GetHdrHeight()) / GetLineHeight() + GetFirstVisLine();
255 // static helpers -------------------------------------------------------------
257 void ScCsvControl::ImplInvertRect( OutputDevice
& rOutDev
, const Rectangle
& rRect
)
259 rOutDev
.Push( PushFlags::LINECOLOR
| PushFlags::FILLCOLOR
| PushFlags::RASTEROP
);
260 rOutDev
.SetLineColor( Color( COL_BLACK
) );
261 rOutDev
.SetFillColor( Color( COL_BLACK
) );
262 rOutDev
.SetRasterOp( ROP_INVERT
);
263 rOutDev
.DrawRect( rRect
);
267 ScMoveMode
ScCsvControl::GetHorzDirection( sal_uInt16 nCode
, bool bHomeEnd
)
271 case KEY_LEFT
: return MOVE_PREV
;
272 case KEY_RIGHT
: return MOVE_NEXT
;
274 if( bHomeEnd
) switch( nCode
)
276 case KEY_HOME
: return MOVE_FIRST
;
277 case KEY_END
: return MOVE_LAST
;
282 ScMoveMode
ScCsvControl::GetVertDirection( sal_uInt16 nCode
, bool bHomeEnd
)
286 case KEY_UP
: return MOVE_PREV
;
287 case KEY_DOWN
: return MOVE_NEXT
;
288 case KEY_PAGEUP
: return MOVE_PREVPAGE
;
289 case KEY_PAGEDOWN
: return MOVE_NEXTPAGE
;
291 if( bHomeEnd
) switch( nCode
)
293 case KEY_HOME
: return MOVE_FIRST
;
294 case KEY_END
: return MOVE_LAST
;
299 // accessibility --------------------------------------------------------------
301 ScCsvControl::XAccessibleRef
ScCsvControl::CreateAccessible()
303 mxAccessible
= ImplCreateAccessible();
304 return XAccessibleRef(mxAccessible
.get());
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */