1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: csvcontrol.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 // ============================================================================
36 #include "csvcontrol.hxx"
37 #include <tools/debug.hxx>
38 #include <vcl/svapp.hxx>
39 #include "AccessibleCsvControl.hxx"
42 // ============================================================================
44 ScCsvLayoutData::ScCsvLayoutData() :
55 mnPosCursor( CSV_POS_INVALID
),
58 mbAppRTL( !!Application::GetSettings().GetLayoutRTL() )
62 ScCsvDiff
ScCsvLayoutData::GetDiff( const ScCsvLayoutData
& rData
) const
64 ScCsvDiff nRet
= CSV_DIFF_EQUAL
;
65 if( mnPosCount
!= rData
.mnPosCount
) nRet
|= CSV_DIFF_POSCOUNT
;
66 if( mnPosOffset
!= rData
.mnPosOffset
) nRet
|= CSV_DIFF_POSOFFSET
;
67 if( mnHdrWidth
!= rData
.mnHdrWidth
) nRet
|= CSV_DIFF_HDRWIDTH
;
68 if( mnCharWidth
!= rData
.mnCharWidth
) nRet
|= CSV_DIFF_CHARWIDTH
;
69 if( mnLineCount
!= rData
.mnLineCount
) nRet
|= CSV_DIFF_LINECOUNT
;
70 if( mnLineOffset
!= rData
.mnLineOffset
) nRet
|= CSV_DIFF_LINEOFFSET
;
71 if( mnHdrHeight
!= rData
.mnHdrHeight
) nRet
|= CSV_DIFF_HDRHEIGHT
;
72 if( mnLineHeight
!= rData
.mnLineHeight
) nRet
|= CSV_DIFF_LINEHEIGHT
;
73 if( mnPosCursor
!= rData
.mnPosCursor
) nRet
|= CSV_DIFF_RULERCURSOR
;
74 if( mnColCursor
!= rData
.mnColCursor
) nRet
|= CSV_DIFF_GRIDCURSOR
;
79 // ============================================================================
81 ScCsvControl::ScCsvControl( ScCsvControl
& rParent
) :
82 Control( &rParent
, WB_TABSTOP
| WB_NODIALOGCONTROL
),
83 mrData( rParent
.GetLayoutData() ),
89 ScCsvControl::ScCsvControl( Window
* pParent
, const ScCsvLayoutData
& rData
, WinBits nStyle
) :
90 Control( pParent
, nStyle
),
97 ScCsvControl::ScCsvControl( Window
* pParent
, const ScCsvLayoutData
& rData
, const ResId
& rResId
) :
98 Control( pParent
, rResId
),
100 mpAccessible( NULL
),
105 ScCsvControl::~ScCsvControl()
108 mpAccessible
->dispose();
112 // event handling -------------------------------------------------------------
114 void ScCsvControl::GetFocus()
117 AccSendFocusEvent( true );
120 void ScCsvControl::LoseFocus()
122 Control::LoseFocus();
123 AccSendFocusEvent( false );
126 void ScCsvControl::AccSendFocusEvent( bool bFocused
)
129 mpAccessible
->SendFocusEvent( bFocused
);
132 void ScCsvControl::AccSendCaretEvent()
135 mpAccessible
->SendCaretEvent();
138 void ScCsvControl::AccSendVisibleEvent()
141 mpAccessible
->SendVisibleEvent();
144 void ScCsvControl::AccSendSelectionEvent()
147 mpAccessible
->SendSelectionEvent();
150 void ScCsvControl::AccSendTableUpdateEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
, bool bAllRows
)
153 mpAccessible
->SendTableUpdateEvent( nFirstColumn
, nLastColumn
, bAllRows
);
156 void ScCsvControl::AccSendInsertColumnEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
)
159 mpAccessible
->SendInsertColumnEvent( nFirstColumn
, nLastColumn
);
162 void ScCsvControl::AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
)
165 mpAccessible
->SendRemoveColumnEvent( nFirstColumn
, nLastColumn
);
169 // repaint helpers ------------------------------------------------------------
171 void ScCsvControl::Repaint( bool bInvalidate
)
176 Execute( CSVCMD_REPAINT
);
179 void ScCsvControl::DisableRepaint()
181 ++mrData
.mnNoRepaint
;
184 void ScCsvControl::EnableRepaint( bool bInvalidate
)
186 DBG_ASSERT( IsNoRepaint(), "ScCsvControl::EnableRepaint - invalid call" );
187 --mrData
.mnNoRepaint
;
188 Repaint( bInvalidate
);
192 // command handling -----------------------------------------------------------
194 void ScCsvControl::Execute( ScCsvCmdType eType
, sal_Int32 nParam1
, sal_Int32 nParam2
)
196 maCmd
.Set( eType
, nParam1
, nParam2
);
197 maCmdHdl
.Call( this );
201 // layout helpers -------------------------------------------------------------
203 sal_Int32
ScCsvControl::GetVisPosCount() const
205 return (mrData
.mnWinWidth
- GetHdrWidth()) / GetCharWidth();
208 sal_Int32
ScCsvControl::GetMaxPosOffset() const
210 return Max( GetPosCount() - GetVisPosCount() + 2L, 0L );
213 bool ScCsvControl::IsValidSplitPos( sal_Int32 nPos
) const
215 return (0 < nPos
) && (nPos
< GetPosCount() );
218 bool ScCsvControl::IsVisibleSplitPos( sal_Int32 nPos
) const
220 return IsValidSplitPos( nPos
) && (GetFirstVisPos() <= nPos
) && (nPos
<= GetLastVisPos());
223 sal_Int32
ScCsvControl::GetHdrX() const
225 return IsRTL() ? (mrData
.mnWinWidth
- GetHdrWidth()) : 0;
228 sal_Int32
ScCsvControl::GetFirstX() const
230 return IsRTL() ? 0 : GetHdrWidth();
233 sal_Int32
ScCsvControl::GetLastX() const
235 return mrData
.mnWinWidth
- (IsRTL() ? GetHdrWidth() : 0) - 1;
238 sal_Int32
ScCsvControl::GetX( sal_Int32 nPos
) const
240 return GetFirstX() + (nPos
- GetFirstVisPos()) * GetCharWidth();
243 sal_Int32
ScCsvControl::GetPosFromX( sal_Int32 nX
) const
245 return (nX
- GetFirstX() + GetCharWidth() / 2) / GetCharWidth() + GetFirstVisPos();
248 sal_Int32
ScCsvControl::GetVisLineCount() const
250 return (mrData
.mnWinHeight
- GetHdrHeight() - 2) / GetLineHeight() + 1;
253 sal_Int32
ScCsvControl::GetLastVisLine() const
255 return Min( GetFirstVisLine() + GetVisLineCount(), GetLineCount() ) - 1;
258 sal_Int32
ScCsvControl::GetMaxLineOffset() const
260 return Max( GetLineCount() - GetVisLineCount() + 1L, 0L );
263 bool ScCsvControl::IsValidLine( sal_Int32 nLine
) const
265 return (0 <= nLine
) && (nLine
< GetLineCount());
268 bool ScCsvControl::IsVisibleLine( sal_Int32 nLine
) const
270 return IsValidLine( nLine
) && (GetFirstVisLine() <= nLine
) && (nLine
<= GetLastVisLine());
273 sal_Int32
ScCsvControl::GetY( sal_Int32 nLine
) const
275 return GetHdrHeight() + (nLine
- GetFirstVisLine()) * GetLineHeight();
278 sal_Int32
ScCsvControl::GetLineFromY( sal_Int32 nY
) const
280 return (nY
- GetHdrHeight()) / GetLineHeight() + GetFirstVisLine();
284 // static helpers -------------------------------------------------------------
286 void ScCsvControl::ImplInvertRect( OutputDevice
& rOutDev
, const Rectangle
& rRect
)
288 rOutDev
.Push( PUSH_LINECOLOR
| PUSH_FILLCOLOR
| PUSH_RASTEROP
);
289 rOutDev
.SetLineColor( Color( COL_BLACK
) );
290 rOutDev
.SetFillColor( Color( COL_BLACK
) );
291 rOutDev
.SetRasterOp( ROP_INVERT
);
292 rOutDev
.DrawRect( rRect
);
296 ScMoveMode
ScCsvControl::GetHorzDirection( sal_uInt16 nCode
, bool bHomeEnd
)
300 case KEY_LEFT
: return MOVE_PREV
;
301 case KEY_RIGHT
: return MOVE_NEXT
;
303 if( bHomeEnd
) switch( nCode
)
305 case KEY_HOME
: return MOVE_FIRST
;
306 case KEY_END
: return MOVE_LAST
;
311 ScMoveMode
ScCsvControl::GetVertDirection( sal_uInt16 nCode
, bool bHomeEnd
)
315 case KEY_UP
: return MOVE_PREV
;
316 case KEY_DOWN
: return MOVE_NEXT
;
317 case KEY_PAGEUP
: return MOVE_PREVPAGE
;
318 case KEY_PAGEDOWN
: return MOVE_NEXTPAGE
;
320 if( bHomeEnd
) switch( nCode
)
322 case KEY_HOME
: return MOVE_FIRST
;
323 case KEY_END
: return MOVE_LAST
;
329 // accessibility --------------------------------------------------------------
331 ScCsvControl::XAccessibleRef
ScCsvControl::CreateAccessible()
333 mpAccessible
= ImplCreateAccessible();
334 mxAccessible
= mpAccessible
;
339 // ============================================================================