xref: /aoo42x/main/sc/source/ui/dbgui/csvcontrol.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir // ============================================================================
33*cdf0e10cSrcweir #include "csvcontrol.hxx"
34*cdf0e10cSrcweir #include <tools/debug.hxx>
35*cdf0e10cSrcweir #include <vcl/svapp.hxx>
36*cdf0e10cSrcweir #include "AccessibleCsvControl.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir // ============================================================================
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir ScCsvLayoutData::ScCsvLayoutData() :
42*cdf0e10cSrcweir     mnPosCount( 1 ),
43*cdf0e10cSrcweir     mnPosOffset( 0 ),
44*cdf0e10cSrcweir     mnWinWidth( 1 ),
45*cdf0e10cSrcweir     mnHdrWidth( 0 ),
46*cdf0e10cSrcweir     mnCharWidth( 1 ),
47*cdf0e10cSrcweir     mnLineCount( 1 ),
48*cdf0e10cSrcweir     mnLineOffset( 0 ),
49*cdf0e10cSrcweir     mnWinHeight( 1 ),
50*cdf0e10cSrcweir     mnHdrHeight( 0 ),
51*cdf0e10cSrcweir     mnLineHeight( 1 ),
52*cdf0e10cSrcweir     mnPosCursor( CSV_POS_INVALID ),
53*cdf0e10cSrcweir     mnColCursor( 0 ),
54*cdf0e10cSrcweir     mnNoRepaint( 0 ),
55*cdf0e10cSrcweir     mbAppRTL( !!Application::GetSettings().GetLayoutRTL() )
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir ScCsvDiff ScCsvLayoutData::GetDiff( const ScCsvLayoutData& rData ) const
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     ScCsvDiff nRet = CSV_DIFF_EQUAL;
62*cdf0e10cSrcweir     if( mnPosCount != rData.mnPosCount )        nRet |= CSV_DIFF_POSCOUNT;
63*cdf0e10cSrcweir     if( mnPosOffset != rData.mnPosOffset )      nRet |= CSV_DIFF_POSOFFSET;
64*cdf0e10cSrcweir     if( mnHdrWidth != rData.mnHdrWidth )        nRet |= CSV_DIFF_HDRWIDTH;
65*cdf0e10cSrcweir     if( mnCharWidth != rData.mnCharWidth )      nRet |= CSV_DIFF_CHARWIDTH;
66*cdf0e10cSrcweir     if( mnLineCount != rData.mnLineCount )      nRet |= CSV_DIFF_LINECOUNT;
67*cdf0e10cSrcweir     if( mnLineOffset != rData.mnLineOffset )    nRet |= CSV_DIFF_LINEOFFSET;
68*cdf0e10cSrcweir     if( mnHdrHeight != rData.mnHdrHeight )      nRet |= CSV_DIFF_HDRHEIGHT;
69*cdf0e10cSrcweir     if( mnLineHeight != rData.mnLineHeight )    nRet |= CSV_DIFF_LINEHEIGHT;
70*cdf0e10cSrcweir     if( mnPosCursor != rData.mnPosCursor )      nRet |= CSV_DIFF_RULERCURSOR;
71*cdf0e10cSrcweir     if( mnColCursor != rData.mnColCursor )      nRet |= CSV_DIFF_GRIDCURSOR;
72*cdf0e10cSrcweir     return nRet;
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir // ============================================================================
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir ScCsvControl::ScCsvControl( ScCsvControl& rParent ) :
79*cdf0e10cSrcweir     Control( &rParent, WB_TABSTOP | WB_NODIALOGCONTROL ),
80*cdf0e10cSrcweir     mrData( rParent.GetLayoutData() ),
81*cdf0e10cSrcweir     mpAccessible( NULL ),
82*cdf0e10cSrcweir     mbValidGfx( false )
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir ScCsvControl::ScCsvControl( Window* pParent, const ScCsvLayoutData& rData, WinBits nStyle ) :
87*cdf0e10cSrcweir     Control( pParent, nStyle ),
88*cdf0e10cSrcweir     mrData( rData ),
89*cdf0e10cSrcweir     mpAccessible( NULL ),
90*cdf0e10cSrcweir     mbValidGfx( false )
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir ScCsvControl::ScCsvControl( Window* pParent, const ScCsvLayoutData& rData, const ResId& rResId ) :
95*cdf0e10cSrcweir     Control( pParent, rResId ),
96*cdf0e10cSrcweir     mrData( rData ),
97*cdf0e10cSrcweir     mpAccessible( NULL ),
98*cdf0e10cSrcweir     mbValidGfx( false )
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir ScCsvControl::~ScCsvControl()
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir     if( mpAccessible )
105*cdf0e10cSrcweir         mpAccessible->dispose();
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir // event handling -------------------------------------------------------------
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir void ScCsvControl::GetFocus()
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir     Control::GetFocus();
114*cdf0e10cSrcweir     AccSendFocusEvent( true );
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir void ScCsvControl::LoseFocus()
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir     Control::LoseFocus();
120*cdf0e10cSrcweir     AccSendFocusEvent( false );
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir void ScCsvControl::AccSendFocusEvent( bool bFocused )
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir     if( mpAccessible )
126*cdf0e10cSrcweir         mpAccessible->SendFocusEvent( bFocused );
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir void ScCsvControl::AccSendCaretEvent()
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir     if( mpAccessible )
132*cdf0e10cSrcweir         mpAccessible->SendCaretEvent();
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir void ScCsvControl::AccSendVisibleEvent()
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir     if( mpAccessible )
138*cdf0e10cSrcweir         mpAccessible->SendVisibleEvent();
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir void ScCsvControl::AccSendSelectionEvent()
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     if( mpAccessible )
144*cdf0e10cSrcweir         mpAccessible->SendSelectionEvent();
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir void ScCsvControl::AccSendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     if( mpAccessible )
150*cdf0e10cSrcweir         mpAccessible->SendTableUpdateEvent( nFirstColumn, nLastColumn, bAllRows );
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir void ScCsvControl::AccSendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn )
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir     if( mpAccessible )
156*cdf0e10cSrcweir         mpAccessible->SendInsertColumnEvent( nFirstColumn, nLastColumn );
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir void ScCsvControl::AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn )
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     if( mpAccessible )
162*cdf0e10cSrcweir         mpAccessible->SendRemoveColumnEvent( nFirstColumn, nLastColumn );
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir // repaint helpers ------------------------------------------------------------
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir void ScCsvControl::Repaint( bool bInvalidate )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     if( bInvalidate )
171*cdf0e10cSrcweir         InvalidateGfx();
172*cdf0e10cSrcweir     if( !IsNoRepaint() )
173*cdf0e10cSrcweir         Execute( CSVCMD_REPAINT );
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir void ScCsvControl::DisableRepaint()
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir     ++mrData.mnNoRepaint;
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir void ScCsvControl::EnableRepaint( bool bInvalidate )
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir     DBG_ASSERT( IsNoRepaint(), "ScCsvControl::EnableRepaint - invalid call" );
184*cdf0e10cSrcweir     --mrData.mnNoRepaint;
185*cdf0e10cSrcweir     Repaint( bInvalidate );
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir // command handling -----------------------------------------------------------
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir void ScCsvControl::Execute( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 )
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir     maCmd.Set( eType, nParam1, nParam2 );
194*cdf0e10cSrcweir     maCmdHdl.Call( this );
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir // layout helpers -------------------------------------------------------------
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetVisPosCount() const
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir     return (mrData.mnWinWidth - GetHdrWidth()) / GetCharWidth();
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetMaxPosOffset() const
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     return Max( GetPosCount() - GetVisPosCount() + 2L, 0L );
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir bool ScCsvControl::IsValidSplitPos( sal_Int32 nPos ) const
211*cdf0e10cSrcweir {
212*cdf0e10cSrcweir     return (0 < nPos) && (nPos < GetPosCount() );
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir bool ScCsvControl::IsVisibleSplitPos( sal_Int32 nPos ) const
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir     return IsValidSplitPos( nPos ) && (GetFirstVisPos() <= nPos) && (nPos <= GetLastVisPos());
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetHdrX() const
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir     return IsRTL() ? (mrData.mnWinWidth - GetHdrWidth()) : 0;
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetFirstX() const
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir     return IsRTL() ? 0 : GetHdrWidth();
228*cdf0e10cSrcweir }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetLastX() const
231*cdf0e10cSrcweir {
232*cdf0e10cSrcweir     return mrData.mnWinWidth - (IsRTL() ? GetHdrWidth() : 0) - 1;
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetX( sal_Int32 nPos ) const
236*cdf0e10cSrcweir {
237*cdf0e10cSrcweir     return GetFirstX() + (nPos - GetFirstVisPos()) * GetCharWidth();
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetPosFromX( sal_Int32 nX ) const
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir     return (nX - GetFirstX() + GetCharWidth() / 2) / GetCharWidth() + GetFirstVisPos();
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetVisLineCount() const
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir     return (mrData.mnWinHeight - GetHdrHeight() - 2) / GetLineHeight() + 1;
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetLastVisLine() const
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir     return Min( GetFirstVisLine() + GetVisLineCount(), GetLineCount() ) - 1;
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetMaxLineOffset() const
256*cdf0e10cSrcweir {
257*cdf0e10cSrcweir     return Max( GetLineCount() - GetVisLineCount() + 1L, 0L );
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir bool ScCsvControl::IsValidLine( sal_Int32 nLine ) const
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir     return (0 <= nLine) && (nLine < GetLineCount());
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir bool ScCsvControl::IsVisibleLine( sal_Int32 nLine ) const
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir     return IsValidLine( nLine ) && (GetFirstVisLine() <= nLine) && (nLine <= GetLastVisLine());
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetY( sal_Int32 nLine ) const
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir     return GetHdrHeight() + (nLine - GetFirstVisLine()) * GetLineHeight();
273*cdf0e10cSrcweir }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir sal_Int32 ScCsvControl::GetLineFromY( sal_Int32 nY ) const
276*cdf0e10cSrcweir {
277*cdf0e10cSrcweir     return (nY - GetHdrHeight()) / GetLineHeight() + GetFirstVisLine();
278*cdf0e10cSrcweir }
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir // static helpers -------------------------------------------------------------
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir void ScCsvControl::ImplInvertRect( OutputDevice& rOutDev, const Rectangle& rRect )
284*cdf0e10cSrcweir {
285*cdf0e10cSrcweir     rOutDev.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR | PUSH_RASTEROP );
286*cdf0e10cSrcweir     rOutDev.SetLineColor( Color( COL_BLACK ) );
287*cdf0e10cSrcweir     rOutDev.SetFillColor( Color( COL_BLACK ) );
288*cdf0e10cSrcweir     rOutDev.SetRasterOp( ROP_INVERT );
289*cdf0e10cSrcweir     rOutDev.DrawRect( rRect );
290*cdf0e10cSrcweir     rOutDev.Pop();
291*cdf0e10cSrcweir }
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir ScMoveMode ScCsvControl::GetHorzDirection( sal_uInt16 nCode, bool bHomeEnd )
294*cdf0e10cSrcweir {
295*cdf0e10cSrcweir     switch( nCode )
296*cdf0e10cSrcweir     {
297*cdf0e10cSrcweir         case KEY_LEFT:  return MOVE_PREV;
298*cdf0e10cSrcweir         case KEY_RIGHT: return MOVE_NEXT;
299*cdf0e10cSrcweir     }
300*cdf0e10cSrcweir     if( bHomeEnd ) switch( nCode )
301*cdf0e10cSrcweir     {
302*cdf0e10cSrcweir         case KEY_HOME:  return MOVE_FIRST;
303*cdf0e10cSrcweir         case KEY_END:   return MOVE_LAST;
304*cdf0e10cSrcweir     }
305*cdf0e10cSrcweir     return MOVE_NONE;
306*cdf0e10cSrcweir }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir ScMoveMode ScCsvControl::GetVertDirection( sal_uInt16 nCode, bool bHomeEnd )
309*cdf0e10cSrcweir {
310*cdf0e10cSrcweir     switch( nCode )
311*cdf0e10cSrcweir     {
312*cdf0e10cSrcweir         case KEY_UP:        return MOVE_PREV;
313*cdf0e10cSrcweir         case KEY_DOWN:      return MOVE_NEXT;
314*cdf0e10cSrcweir         case KEY_PAGEUP:    return MOVE_PREVPAGE;
315*cdf0e10cSrcweir         case KEY_PAGEDOWN:  return MOVE_NEXTPAGE;
316*cdf0e10cSrcweir     }
317*cdf0e10cSrcweir     if( bHomeEnd ) switch( nCode )
318*cdf0e10cSrcweir     {
319*cdf0e10cSrcweir         case KEY_HOME:      return MOVE_FIRST;
320*cdf0e10cSrcweir         case KEY_END:       return MOVE_LAST;
321*cdf0e10cSrcweir     }
322*cdf0e10cSrcweir     return MOVE_NONE;
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir // accessibility --------------------------------------------------------------
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir ScCsvControl::XAccessibleRef ScCsvControl::CreateAccessible()
329*cdf0e10cSrcweir {
330*cdf0e10cSrcweir     mpAccessible = ImplCreateAccessible();
331*cdf0e10cSrcweir     mxAccessible = mpAccessible;
332*cdf0e10cSrcweir     return mxAccessible;
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir // ============================================================================
337*cdf0e10cSrcweir 
338