LibreOffice Module sc (master) 1
csvcontrol.cxx
Go to the documentation of this file.
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#include <csvcontrol.hxx>
21#include <vcl/keycodes.hxx>
22#include <vcl/outdev.hxx>
23#include <vcl/settings.hxx>
24
26 mnPosCount( 1 ),
27 mnPosOffset( 0 ),
28 mnWinWidth( 1 ),
29 mnHdrWidth( 0 ),
30 mnCharWidth( 1 ),
31 mnLineCount( 1 ),
32 mnLineOffset( 0 ),
33 mnWinHeight( 1 ),
34 mnHdrHeight( 0 ),
35 mnLineHeight( 1 ),
36 mnPosCursor( CSV_POS_INVALID ),
37 mnColCursor( 0 ),
38 mnNoRepaint( 0 ),
39 mbAppRTL( AllSettings::GetLayoutRTL() )
40{
41}
42
44{
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;
56 return nRet;
57}
58
60 : mrData(rData)
61 , mbValidGfx(false)
62{
63}
64
66{
67 if( mxAccessible.is() )
68 mxAccessible->dispose();
69 mxAccessible = nullptr; // lp#1566050: prevent cyclic reference zombies
70}
71
72// event handling -------------------------------------------------------------
73
75{
77 AccSendFocusEvent( true );
78}
79
81{
83 AccSendFocusEvent( false );
84}
85
87{
88 if( mxAccessible.is() )
89 mxAccessible->SendFocusEvent( bFocused );
90}
91
93{
94 if( mxAccessible.is() )
95 mxAccessible->SendCaretEvent();
96}
97
99{
100 if( mxAccessible.is() )
101 mxAccessible->SendVisibleEvent();
102}
103
105{
106 if( mxAccessible.is() )
107 mxAccessible->SendSelectionEvent();
108}
109
110void ScCsvControl::AccSendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows )
111{
112 if( mxAccessible.is() )
113 mxAccessible->SendTableUpdateEvent( nFirstColumn, nLastColumn, bAllRows );
114}
115
116void ScCsvControl::AccSendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn )
117{
118 if( mxAccessible.is() )
119 mxAccessible->SendInsertColumnEvent( nFirstColumn, nLastColumn );
120}
121
122void ScCsvControl::AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn )
123{
124 if( mxAccessible.is() )
125 mxAccessible->SendRemoveColumnEvent( nFirstColumn, nLastColumn );
126}
127
128// repaint helpers ------------------------------------------------------------
129
130void ScCsvControl::Repaint( bool bInvalidate )
131{
132 if( bInvalidate )
134 if( !IsNoRepaint() )
136}
137
139{
141}
142
144{
145 OSL_ENSURE( IsNoRepaint(), "ScCsvControl::EnableRepaint - invalid call" );
147 Repaint();
148}
149
150// command handling -----------------------------------------------------------
151
152void ScCsvControl::Execute( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 )
153{
154 maCmd.Set( eType, nParam1, nParam2 );
155 maCmdHdl.Call( *this );
156}
157
158// layout helpers -------------------------------------------------------------
159
161{
162 return (mrData.mnWinWidth - GetHdrWidth()) / GetCharWidth();
163}
164
166{
167 return std::max<sal_Int32>( GetPosCount() - GetVisPosCount() + 2, 0 );
168}
169
170bool ScCsvControl::IsValidSplitPos( sal_Int32 nPos ) const
171{
172 return (0 < nPos) && (nPos < GetPosCount() );
173}
174
175bool ScCsvControl::IsVisibleSplitPos( sal_Int32 nPos ) const
176{
177 return IsValidSplitPos( nPos ) && (GetFirstVisPos() <= nPos) && (nPos <= GetLastVisPos());
178}
179
180sal_Int32 ScCsvControl::GetHdrX() const
181{
182 return IsRTL() ? (mrData.mnWinWidth - GetHdrWidth()) : 0;
183}
184
185sal_Int32 ScCsvControl::GetFirstX() const
186{
187 return IsRTL() ? 0 : GetHdrWidth();
188}
189
190sal_Int32 ScCsvControl::GetLastX() const
191{
192 return mrData.mnWinWidth - (IsRTL() ? GetHdrWidth() : 0) - 1;
193}
194
195sal_Int32 ScCsvControl::GetX( sal_Int32 nPos ) const
196{
197 return GetFirstX() + (nPos - GetFirstVisPos()) * GetCharWidth();
198}
199
200sal_Int32 ScCsvControl::GetPosFromX( sal_Int32 nX ) const
201{
202 return (nX - GetFirstX() + GetCharWidth() / 2) / GetCharWidth() + GetFirstVisPos();
203}
204
206{
207 return (mrData.mnWinHeight - GetHdrHeight() - 2) / GetLineHeight() + 1;
208}
209
211{
212 return std::min( GetFirstVisLine() + GetVisLineCount(), GetLineCount() ) - 1;
213}
214
216{
217 return std::max<sal_Int32>( GetLineCount() - GetVisLineCount() + 1, 0 );
218}
219
220bool ScCsvControl::IsValidLine( sal_Int32 nLine ) const
221{
222 return (0 <= nLine) && (nLine < GetLineCount());
223}
224
225bool ScCsvControl::IsVisibleLine( sal_Int32 nLine ) const
226{
227 return IsValidLine( nLine ) && (GetFirstVisLine() <= nLine) && (nLine <= GetLastVisLine());
228}
229
230sal_Int32 ScCsvControl::GetY( sal_Int32 nLine ) const
231{
232 return GetHdrHeight() + (nLine - GetFirstVisLine()) * GetLineHeight();
233}
234
235sal_Int32 ScCsvControl::GetLineFromY( sal_Int32 nY ) const
236{
237 return (nY - GetHdrHeight()) / GetLineHeight() + GetFirstVisLine();
238}
239
240// static helpers -------------------------------------------------------------
241
243{
245 rOutDev.SetLineColor( COL_BLACK );
246 rOutDev.SetFillColor( COL_BLACK );
247 rOutDev.SetRasterOp( RasterOp::Invert );
248 rOutDev.DrawRect( rRect );
249 rOutDev.Pop();
250}
251
252ScMoveMode ScCsvControl::GetHorzDirection( sal_uInt16 nCode, bool bHomeEnd )
253{
254 switch( nCode )
255 {
256 case KEY_LEFT: return MOVE_PREV;
257 case KEY_RIGHT: return MOVE_NEXT;
258 }
259 if( bHomeEnd ) switch( nCode )
260 {
261 case KEY_HOME: return MOVE_FIRST;
262 case KEY_END: return MOVE_LAST;
263 }
264 return MOVE_NONE;
265}
266
267ScMoveMode ScCsvControl::GetVertDirection( sal_uInt16 nCode, bool bHomeEnd )
268{
269 switch( nCode )
270 {
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;
275 }
276 if( bHomeEnd ) switch( nCode )
277 {
278 case KEY_HOME: return MOVE_FIRST;
279 case KEY_END: return MOVE_LAST;
280 }
281 return MOVE_NONE;
282}
283
284/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void DrawRect(const tools::Rectangle &rRect)
void SetLineColor()
void SetFillColor()
void SetRasterOp(RasterOp eRasterOp)
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
void Set(ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2)
Definition: csvcontrol.hxx:216
void EnableRepaint()
Decreases no-repaint counter and repaints if counter reaches 0.
Definition: csvcontrol.cxx:143
void Execute(ScCsvCmdType eType, sal_Int32 nParam1=CSV_POS_INVALID, sal_Int32 nParam2=CSV_POS_INVALID)
Executes a command by calling command handler.
Definition: csvcontrol.cxx:152
void DisableRepaint()
Increases no-repaint counter (controls do not repaint until the last EnableRepaint()).
Definition: csvcontrol.cxx:138
sal_Int32 GetFirstVisPos() const
Returns the first visible position.
Definition: csvcontrol.hxx:304
static ScMoveMode GetVertDirection(sal_uInt16 nCode, bool bHomeEnd)
Returns direction code for the keys UP, DOWN, HOME, END, PAGE UP, PAGE DOWN.
Definition: csvcontrol.cxx:267
bool IsNoRepaint() const
Returns true, if controls will not repaint.
Definition: csvcontrol.hxx:277
static void ImplInvertRect(OutputDevice &rOutDev, const tools::Rectangle &rRect)
Inverts a rectangle in the specified output device.
Definition: csvcontrol.cxx:242
sal_Int32 GetPosCount() const
Returns the number of available positions.
Definition: csvcontrol.hxx:300
virtual void GetFocus() override
Definition: csvcontrol.cxx:74
bool IsVisibleLine(sal_Int32 nLine) const
Returns true, if nLine is a valid and visible line index.
Definition: csvcontrol.cxx:225
sal_Int32 GetMaxLineOffset() const
Returns highest possible index for first line.
Definition: csvcontrol.cxx:215
sal_Int32 GetPosFromX(sal_Int32 nX) const
Returns position from output coordinate.
Definition: csvcontrol.cxx:200
void AccSendSelectionEvent()
Sends a selection changed event to the accessibility object.
Definition: csvcontrol.cxx:104
sal_Int32 GetLastVisLine() const
Returns index of last visible line.
Definition: csvcontrol.cxx:210
bool IsValidLine(sal_Int32 nLine) const
Returns true, if nLine is a valid line index.
Definition: csvcontrol.cxx:220
void InvalidateGfx()
Sets the graphic invalid (next Redraw() will not use cached graphic).
Definition: csvcontrol.hxx:263
bool IsRTL() const
Returns true, if the Right-to-Left layout mode is active.
Definition: csvcontrol.hxx:297
void AccSendFocusEvent(bool bFocused)
Sends a GetFocus or LoseFocus event to the accessibility object.
Definition: csvcontrol.cxx:86
sal_Int32 GetCharWidth() const
Returns the width of one character column.
Definition: csvcontrol.hxx:318
void AccSendTableUpdateEvent(sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows=true)
Sends a table model changed event for changed cell contents to the accessibility object.
Definition: csvcontrol.cxx:110
ScCsvControl(const ScCsvLayoutData &rData)
Reference to the accessible implementation object.
Definition: csvcontrol.cxx:59
sal_Int32 GetLineHeight() const
Returns the height of one line.
Definition: csvcontrol.hxx:349
ScCsvCmd maCmd
External command handler.
Definition: csvcontrol.hxx:226
sal_Int32 GetFirstVisLine() const
Returns index of first visible line.
Definition: csvcontrol.hxx:335
virtual void LoseFocus() override
Definition: csvcontrol.cxx:80
void AccSendCaretEvent()
Sends a caret changed event to the accessibility object.
Definition: csvcontrol.cxx:92
sal_Int32 GetHdrWidth() const
Returns the width of the header column.
Definition: csvcontrol.hxx:316
void AccSendVisibleEvent()
Sends a visible area changed event to the accessibility object.
Definition: csvcontrol.cxx:98
Link< ScCsvControl &, void > maCmdHdl
Definition: csvcontrol.hxx:225
void AccSendRemoveColumnEvent(sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn)
Sends a table model changed event for a removed column to the accessibility object.
Definition: csvcontrol.cxx:122
sal_Int32 GetVisLineCount() const
Returns the number of visible lines (including partly visible bottom line).
Definition: csvcontrol.cxx:205
sal_Int32 GetLineCount() const
Returns the number of data lines.
Definition: csvcontrol.hxx:331
sal_Int32 GetX(sal_Int32 nPos) const
Returns output X coordinate of the specified position.
Definition: csvcontrol.cxx:195
void AccSendInsertColumnEvent(sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn)
Sends a table model changed event for an inserted column to the accessibility object.
Definition: csvcontrol.cxx:116
sal_Int32 GetLineFromY(sal_Int32 nY) const
Returns line index from output coordinate.
Definition: csvcontrol.cxx:235
sal_Int32 GetHdrHeight() const
Returns the height of the header line.
Definition: csvcontrol.hxx:347
rtl::Reference< ScAccessibleCsvControl > mxAccessible
Content of virtual devices valid?
Definition: csvcontrol.hxx:232
const ScCsvLayoutData & mrData
Data of last command.
Definition: csvcontrol.hxx:227
sal_Int32 GetLastVisPos() const
Returns the last visible position.
Definition: csvcontrol.hxx:306
bool IsVisibleSplitPos(sal_Int32 nPos) const
Returns true, if nPos is an allowed AND visible split position.
Definition: csvcontrol.cxx:175
sal_Int32 GetLastX() const
Returns the X position of the last pixel of the data area.
Definition: csvcontrol.cxx:190
void Repaint(bool bInvalidate=false)
Repaints all controls.
Definition: csvcontrol.cxx:130
sal_Int32 GetHdrX() const
Returns the start position of the header column.
Definition: csvcontrol.cxx:180
sal_Int32 GetMaxPosOffset() const
Returns highest possible position for first visible character.
Definition: csvcontrol.cxx:165
sal_Int32 GetFirstX() const
Returns the X position of the first pixel of the data area.
Definition: csvcontrol.cxx:185
static ScMoveMode GetHorzDirection(sal_uInt16 nCode, bool bHomeEnd)
Returns direction code for the keys LEFT, RIGHT, HOME, END.
Definition: csvcontrol.cxx:252
sal_Int32 GetVisPosCount() const
Returns the number of visible positions.
Definition: csvcontrol.cxx:160
bool IsValidSplitPos(sal_Int32 nPos) const
Returns true, if it is allowed to set a split at nPos.
Definition: csvcontrol.cxx:170
virtual ~ScCsvControl() override
Definition: csvcontrol.cxx:65
sal_Int32 GetY(sal_Int32 nLine) const
Returns output Y coordinate of the specified line.
Definition: csvcontrol.cxx:230
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
ScMoveMode
Specifies which element should be used to perform an action.
Definition: csvcontrol.hxx:77
@ MOVE_NEXTPAGE
Previous page relative to current context.
Definition: csvcontrol.hxx:84
@ MOVE_LAST
First element in current context.
Definition: csvcontrol.hxx:80
@ MOVE_PREVPAGE
Successor of current element in current context.
Definition: csvcontrol.hxx:83
@ MOVE_FIRST
No action.
Definition: csvcontrol.hxx:79
@ MOVE_NEXT
Predecessor of current element in current context.
Definition: csvcontrol.hxx:82
@ MOVE_NONE
Definition: csvcontrol.hxx:78
@ MOVE_PREV
Last element in current context.
Definition: csvcontrol.hxx:81
ScCsvDiff
Flags for comparison of old and new control layout data.
Definition: csvcontrol.hxx:88
ScCsvCmdType
Enumeration of possible commands to change any settings of the CSV controls.
Definition: csvcontrol.hxx:159
@ CSVCMD_REPAINT
No command. [-].
Definition: csvcontrol.hxx:162
const sal_Int32 CSV_POS_INVALID
Constant for an invalid ruler position.
Definition: csvsplits.hxx:29
DocumentType eType
constexpr sal_uInt16 KEY_HOME
constexpr sal_uInt16 KEY_LEFT
constexpr sal_uInt16 KEY_PAGEDOWN
constexpr sal_uInt16 KEY_UP
constexpr sal_uInt16 KEY_RIGHT
constexpr sal_uInt16 KEY_DOWN
constexpr sal_uInt16 KEY_PAGEUP
constexpr sal_uInt16 KEY_END
sal_uInt16 nPos
ObjectFormatterData & mrData
A structure containing all layout data valid for both ruler and data grid (i.e.
Definition: csvcontrol.hxx:112
ScCsvLayoutData()
true = application in RTL mode.
Definition: csvcontrol.cxx:25
sal_Int32 mnPosCursor
Height of a data line.
Definition: csvcontrol.hxx:130
sal_Int32 mnPosOffset
Number of positions.
Definition: csvcontrol.hxx:115
sal_Int32 mnHdrWidth
Width of ruler and data grid.
Definition: csvcontrol.hxx:118
ScCsvDiff GetDiff(const ScCsvLayoutData &rData) const
Returns differences to rData.
Definition: csvcontrol.cxx:43
sal_Int32 mnLineOffset
Number of data lines.
Definition: csvcontrol.hxx:123
sal_Int32 mnCharWidth
Width of the header column.
Definition: csvcontrol.hxx:119
sal_Int32 mnWinHeight
Index of first visible line (0-based).
Definition: csvcontrol.hxx:125
sal_Int32 mnHdrHeight
Height of entire data grid (incl. header).
Definition: csvcontrol.hxx:126
sal_Int32 mnNoRepaint
Position of grid column cursor.
Definition: csvcontrol.hxx:133
sal_Int32 mnLineCount
Pixel width of one character.
Definition: csvcontrol.hxx:122
sal_Int32 mnPosCount
Definition: csvcontrol.hxx:114
sal_Int32 mnWinWidth
Horizontal scroll offset.
Definition: csvcontrol.hxx:117
sal_Int32 mnColCursor
Position of ruler cursor.
Definition: csvcontrol.hxx:131
sal_Int32 mnLineHeight
Height of the header line.
Definition: csvcontrol.hxx:127