xref: /aoo42x/main/sc/source/ui/dbgui/csvcontrol.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // ============================================================================
29cdf0e10cSrcweir #include "csvcontrol.hxx"
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #include <vcl/svapp.hxx>
32cdf0e10cSrcweir #include "AccessibleCsvControl.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // ============================================================================
36cdf0e10cSrcweir 
ScCsvLayoutData()37cdf0e10cSrcweir ScCsvLayoutData::ScCsvLayoutData() :
38cdf0e10cSrcweir     mnPosCount( 1 ),
39cdf0e10cSrcweir     mnPosOffset( 0 ),
40cdf0e10cSrcweir     mnWinWidth( 1 ),
41cdf0e10cSrcweir     mnHdrWidth( 0 ),
42cdf0e10cSrcweir     mnCharWidth( 1 ),
43cdf0e10cSrcweir     mnLineCount( 1 ),
44cdf0e10cSrcweir     mnLineOffset( 0 ),
45cdf0e10cSrcweir     mnWinHeight( 1 ),
46cdf0e10cSrcweir     mnHdrHeight( 0 ),
47cdf0e10cSrcweir     mnLineHeight( 1 ),
48cdf0e10cSrcweir     mnPosCursor( CSV_POS_INVALID ),
49cdf0e10cSrcweir     mnColCursor( 0 ),
50cdf0e10cSrcweir     mnNoRepaint( 0 ),
51cdf0e10cSrcweir     mbAppRTL( !!Application::GetSettings().GetLayoutRTL() )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
GetDiff(const ScCsvLayoutData & rData) const55cdf0e10cSrcweir ScCsvDiff ScCsvLayoutData::GetDiff( const ScCsvLayoutData& rData ) const
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     ScCsvDiff nRet = CSV_DIFF_EQUAL;
58cdf0e10cSrcweir     if( mnPosCount != rData.mnPosCount )        nRet |= CSV_DIFF_POSCOUNT;
59cdf0e10cSrcweir     if( mnPosOffset != rData.mnPosOffset )      nRet |= CSV_DIFF_POSOFFSET;
60cdf0e10cSrcweir     if( mnHdrWidth != rData.mnHdrWidth )        nRet |= CSV_DIFF_HDRWIDTH;
61cdf0e10cSrcweir     if( mnCharWidth != rData.mnCharWidth )      nRet |= CSV_DIFF_CHARWIDTH;
62cdf0e10cSrcweir     if( mnLineCount != rData.mnLineCount )      nRet |= CSV_DIFF_LINECOUNT;
63cdf0e10cSrcweir     if( mnLineOffset != rData.mnLineOffset )    nRet |= CSV_DIFF_LINEOFFSET;
64cdf0e10cSrcweir     if( mnHdrHeight != rData.mnHdrHeight )      nRet |= CSV_DIFF_HDRHEIGHT;
65cdf0e10cSrcweir     if( mnLineHeight != rData.mnLineHeight )    nRet |= CSV_DIFF_LINEHEIGHT;
66cdf0e10cSrcweir     if( mnPosCursor != rData.mnPosCursor )      nRet |= CSV_DIFF_RULERCURSOR;
67cdf0e10cSrcweir     if( mnColCursor != rData.mnColCursor )      nRet |= CSV_DIFF_GRIDCURSOR;
68cdf0e10cSrcweir     return nRet;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // ============================================================================
73cdf0e10cSrcweir 
ScCsvControl(ScCsvControl & rParent)74cdf0e10cSrcweir ScCsvControl::ScCsvControl( ScCsvControl& rParent ) :
75cdf0e10cSrcweir     Control( &rParent, WB_TABSTOP | WB_NODIALOGCONTROL ),
76cdf0e10cSrcweir     mrData( rParent.GetLayoutData() ),
77cdf0e10cSrcweir     mpAccessible( NULL ),
78cdf0e10cSrcweir     mbValidGfx( false )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
ScCsvControl(Window * pParent,const ScCsvLayoutData & rData,WinBits nStyle)82cdf0e10cSrcweir ScCsvControl::ScCsvControl( Window* pParent, const ScCsvLayoutData& rData, WinBits nStyle ) :
83cdf0e10cSrcweir     Control( pParent, nStyle ),
84cdf0e10cSrcweir     mrData( rData ),
85cdf0e10cSrcweir     mpAccessible( NULL ),
86cdf0e10cSrcweir     mbValidGfx( false )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
ScCsvControl(Window * pParent,const ScCsvLayoutData & rData,const ResId & rResId)90cdf0e10cSrcweir ScCsvControl::ScCsvControl( Window* pParent, const ScCsvLayoutData& rData, const ResId& rResId ) :
91cdf0e10cSrcweir     Control( pParent, rResId ),
92cdf0e10cSrcweir     mrData( rData ),
93cdf0e10cSrcweir     mpAccessible( NULL ),
94cdf0e10cSrcweir     mbValidGfx( false )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
~ScCsvControl()98cdf0e10cSrcweir ScCsvControl::~ScCsvControl()
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     if( mpAccessible )
101cdf0e10cSrcweir         mpAccessible->dispose();
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
105cdf0e10cSrcweir // event handling -------------------------------------------------------------
106cdf0e10cSrcweir 
GetFocus()107cdf0e10cSrcweir void ScCsvControl::GetFocus()
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     Control::GetFocus();
110cdf0e10cSrcweir     AccSendFocusEvent( true );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
LoseFocus()113cdf0e10cSrcweir void ScCsvControl::LoseFocus()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     Control::LoseFocus();
116cdf0e10cSrcweir     AccSendFocusEvent( false );
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
AccSendFocusEvent(bool bFocused)119cdf0e10cSrcweir void ScCsvControl::AccSendFocusEvent( bool bFocused )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     if( mpAccessible )
122cdf0e10cSrcweir         mpAccessible->SendFocusEvent( bFocused );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
AccSendCaretEvent()125cdf0e10cSrcweir void ScCsvControl::AccSendCaretEvent()
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     if( mpAccessible )
128cdf0e10cSrcweir         mpAccessible->SendCaretEvent();
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
AccSendVisibleEvent()131cdf0e10cSrcweir void ScCsvControl::AccSendVisibleEvent()
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     if( mpAccessible )
134cdf0e10cSrcweir         mpAccessible->SendVisibleEvent();
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
AccSendSelectionEvent()137cdf0e10cSrcweir void ScCsvControl::AccSendSelectionEvent()
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     if( mpAccessible )
140cdf0e10cSrcweir         mpAccessible->SendSelectionEvent();
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
AccSendTableUpdateEvent(sal_uInt32 nFirstColumn,sal_uInt32 nLastColumn,bool bAllRows)143cdf0e10cSrcweir void ScCsvControl::AccSendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     if( mpAccessible )
146cdf0e10cSrcweir         mpAccessible->SendTableUpdateEvent( nFirstColumn, nLastColumn, bAllRows );
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
AccSendInsertColumnEvent(sal_uInt32 nFirstColumn,sal_uInt32 nLastColumn)149cdf0e10cSrcweir void ScCsvControl::AccSendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     if( mpAccessible )
152cdf0e10cSrcweir         mpAccessible->SendInsertColumnEvent( nFirstColumn, nLastColumn );
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
AccSendRemoveColumnEvent(sal_uInt32 nFirstColumn,sal_uInt32 nLastColumn)155cdf0e10cSrcweir void ScCsvControl::AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir     if( mpAccessible )
158cdf0e10cSrcweir         mpAccessible->SendRemoveColumnEvent( nFirstColumn, nLastColumn );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 
162cdf0e10cSrcweir // repaint helpers ------------------------------------------------------------
163cdf0e10cSrcweir 
Repaint(bool bInvalidate)164cdf0e10cSrcweir void ScCsvControl::Repaint( bool bInvalidate )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     if( bInvalidate )
167cdf0e10cSrcweir         InvalidateGfx();
168cdf0e10cSrcweir     if( !IsNoRepaint() )
169cdf0e10cSrcweir         Execute( CSVCMD_REPAINT );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
DisableRepaint()172cdf0e10cSrcweir void ScCsvControl::DisableRepaint()
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     ++mrData.mnNoRepaint;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
EnableRepaint(bool bInvalidate)177cdf0e10cSrcweir void ScCsvControl::EnableRepaint( bool bInvalidate )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     DBG_ASSERT( IsNoRepaint(), "ScCsvControl::EnableRepaint - invalid call" );
180cdf0e10cSrcweir     --mrData.mnNoRepaint;
181cdf0e10cSrcweir     Repaint( bInvalidate );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 
185cdf0e10cSrcweir // command handling -----------------------------------------------------------
186cdf0e10cSrcweir 
Execute(ScCsvCmdType eType,sal_Int32 nParam1,sal_Int32 nParam2)187cdf0e10cSrcweir void ScCsvControl::Execute( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir     maCmd.Set( eType, nParam1, nParam2 );
190cdf0e10cSrcweir     maCmdHdl.Call( this );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // layout helpers -------------------------------------------------------------
195cdf0e10cSrcweir 
GetVisPosCount() const196cdf0e10cSrcweir sal_Int32 ScCsvControl::GetVisPosCount() const
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     return (mrData.mnWinWidth - GetHdrWidth()) / GetCharWidth();
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
GetMaxPosOffset() const201cdf0e10cSrcweir sal_Int32 ScCsvControl::GetMaxPosOffset() const
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     return Max( GetPosCount() - GetVisPosCount() + 2L, 0L );
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
IsValidSplitPos(sal_Int32 nPos) const206cdf0e10cSrcweir bool ScCsvControl::IsValidSplitPos( sal_Int32 nPos ) const
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     return (0 < nPos) && (nPos < GetPosCount() );
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
IsVisibleSplitPos(sal_Int32 nPos) const211cdf0e10cSrcweir bool ScCsvControl::IsVisibleSplitPos( sal_Int32 nPos ) const
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     return IsValidSplitPos( nPos ) && (GetFirstVisPos() <= nPos) && (nPos <= GetLastVisPos());
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
GetHdrX() const216cdf0e10cSrcweir sal_Int32 ScCsvControl::GetHdrX() const
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     return IsRTL() ? (mrData.mnWinWidth - GetHdrWidth()) : 0;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
GetFirstX() const221cdf0e10cSrcweir sal_Int32 ScCsvControl::GetFirstX() const
222cdf0e10cSrcweir {
223cdf0e10cSrcweir     return IsRTL() ? 0 : GetHdrWidth();
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
GetLastX() const226cdf0e10cSrcweir sal_Int32 ScCsvControl::GetLastX() const
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     return mrData.mnWinWidth - (IsRTL() ? GetHdrWidth() : 0) - 1;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
GetX(sal_Int32 nPos) const231cdf0e10cSrcweir sal_Int32 ScCsvControl::GetX( sal_Int32 nPos ) const
232cdf0e10cSrcweir {
233cdf0e10cSrcweir     return GetFirstX() + (nPos - GetFirstVisPos()) * GetCharWidth();
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
GetPosFromX(sal_Int32 nX) const236cdf0e10cSrcweir sal_Int32 ScCsvControl::GetPosFromX( sal_Int32 nX ) const
237cdf0e10cSrcweir {
238cdf0e10cSrcweir     return (nX - GetFirstX() + GetCharWidth() / 2) / GetCharWidth() + GetFirstVisPos();
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
GetVisLineCount() const241cdf0e10cSrcweir sal_Int32 ScCsvControl::GetVisLineCount() const
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     return (mrData.mnWinHeight - GetHdrHeight() - 2) / GetLineHeight() + 1;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
GetLastVisLine() const246cdf0e10cSrcweir sal_Int32 ScCsvControl::GetLastVisLine() const
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     return Min( GetFirstVisLine() + GetVisLineCount(), GetLineCount() ) - 1;
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
GetMaxLineOffset() const251cdf0e10cSrcweir sal_Int32 ScCsvControl::GetMaxLineOffset() const
252cdf0e10cSrcweir {
253cdf0e10cSrcweir     return Max( GetLineCount() - GetVisLineCount() + 1L, 0L );
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
IsValidLine(sal_Int32 nLine) const256cdf0e10cSrcweir bool ScCsvControl::IsValidLine( sal_Int32 nLine ) const
257cdf0e10cSrcweir {
258cdf0e10cSrcweir     return (0 <= nLine) && (nLine < GetLineCount());
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
IsVisibleLine(sal_Int32 nLine) const261cdf0e10cSrcweir bool ScCsvControl::IsVisibleLine( sal_Int32 nLine ) const
262cdf0e10cSrcweir {
263cdf0e10cSrcweir     return IsValidLine( nLine ) && (GetFirstVisLine() <= nLine) && (nLine <= GetLastVisLine());
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
GetY(sal_Int32 nLine) const266cdf0e10cSrcweir sal_Int32 ScCsvControl::GetY( sal_Int32 nLine ) const
267cdf0e10cSrcweir {
268cdf0e10cSrcweir     return GetHdrHeight() + (nLine - GetFirstVisLine()) * GetLineHeight();
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
GetLineFromY(sal_Int32 nY) const271cdf0e10cSrcweir sal_Int32 ScCsvControl::GetLineFromY( sal_Int32 nY ) const
272cdf0e10cSrcweir {
273cdf0e10cSrcweir     return (nY - GetHdrHeight()) / GetLineHeight() + GetFirstVisLine();
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 
277cdf0e10cSrcweir // static helpers -------------------------------------------------------------
278cdf0e10cSrcweir 
ImplInvertRect(OutputDevice & rOutDev,const Rectangle & rRect)279cdf0e10cSrcweir void ScCsvControl::ImplInvertRect( OutputDevice& rOutDev, const Rectangle& rRect )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir     rOutDev.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR | PUSH_RASTEROP );
282cdf0e10cSrcweir     rOutDev.SetLineColor( Color( COL_BLACK ) );
283cdf0e10cSrcweir     rOutDev.SetFillColor( Color( COL_BLACK ) );
284cdf0e10cSrcweir     rOutDev.SetRasterOp( ROP_INVERT );
285cdf0e10cSrcweir     rOutDev.DrawRect( rRect );
286cdf0e10cSrcweir     rOutDev.Pop();
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
GetHorzDirection(sal_uInt16 nCode,bool bHomeEnd)289cdf0e10cSrcweir ScMoveMode ScCsvControl::GetHorzDirection( sal_uInt16 nCode, bool bHomeEnd )
290cdf0e10cSrcweir {
291cdf0e10cSrcweir     switch( nCode )
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         case KEY_LEFT:  return MOVE_PREV;
294cdf0e10cSrcweir         case KEY_RIGHT: return MOVE_NEXT;
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir     if( bHomeEnd ) switch( nCode )
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         case KEY_HOME:  return MOVE_FIRST;
299cdf0e10cSrcweir         case KEY_END:   return MOVE_LAST;
300cdf0e10cSrcweir     }
301cdf0e10cSrcweir     return MOVE_NONE;
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
GetVertDirection(sal_uInt16 nCode,bool bHomeEnd)304cdf0e10cSrcweir ScMoveMode ScCsvControl::GetVertDirection( sal_uInt16 nCode, bool bHomeEnd )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir     switch( nCode )
307cdf0e10cSrcweir     {
308cdf0e10cSrcweir         case KEY_UP:        return MOVE_PREV;
309cdf0e10cSrcweir         case KEY_DOWN:      return MOVE_NEXT;
310cdf0e10cSrcweir         case KEY_PAGEUP:    return MOVE_PREVPAGE;
311cdf0e10cSrcweir         case KEY_PAGEDOWN:  return MOVE_NEXTPAGE;
312cdf0e10cSrcweir     }
313cdf0e10cSrcweir     if( bHomeEnd ) switch( nCode )
314cdf0e10cSrcweir     {
315cdf0e10cSrcweir         case KEY_HOME:      return MOVE_FIRST;
316cdf0e10cSrcweir         case KEY_END:       return MOVE_LAST;
317cdf0e10cSrcweir     }
318cdf0e10cSrcweir     return MOVE_NONE;
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 
322cdf0e10cSrcweir // accessibility --------------------------------------------------------------
323cdf0e10cSrcweir 
CreateAccessible()324cdf0e10cSrcweir ScCsvControl::XAccessibleRef ScCsvControl::CreateAccessible()
325cdf0e10cSrcweir {
326cdf0e10cSrcweir     mpAccessible = ImplCreateAccessible();
327cdf0e10cSrcweir     mxAccessible = mpAccessible;
328cdf0e10cSrcweir     return mxAccessible;
329cdf0e10cSrcweir }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 
332cdf0e10cSrcweir // ============================================================================
333cdf0e10cSrcweir 
334