Update ooo320-m1
[ooovba.git] / sc / source / ui / view / gridmerg.cxx
blob9fe73890365fc2f33f435b3587060b1c999be741
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gridmerg.cxx,v $
10 * $Revision: 1.6 $
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"
36 #include <vcl/outdev.hxx>
38 #include "gridmerg.hxx"
40 //------------------------------------------------------------------
42 ScGridMerger::ScGridMerger( OutputDevice* pOutDev, long nOnePixelX, long nOnePixelY ) :
43 pDev( pOutDev ),
44 nOneX( nOnePixelX ),
45 nOneY( nOnePixelY ),
46 nCount( 0 ),
47 bVertical( FALSE )
49 // optimize (DrawGrid) only for pixel MapMode,
50 // to avoid rounding errors
52 bOptimize = ( pDev->GetMapMode().GetMapUnit() == MAP_PIXEL );
55 ScGridMerger::~ScGridMerger()
57 Flush();
60 void ScGridMerger::AddLine( long nStart, long nEnd, long nPos )
62 if ( nCount )
64 // not first line - test fix position
65 // more than one previous line - test distance
67 if ( nStart != nFixStart || nEnd != nFixEnd )
69 if ( nCount == 1 && nPos == nVarStart &&
70 ( nStart == nFixEnd ||
71 nStart == nFixEnd + ( bVertical ? nOneY : nOneX ) ) )
73 // additional optimization: extend connected lines
74 // keep nCount at 1
75 nFixEnd = nEnd;
77 else
78 Flush();
80 else if ( nCount == 1 )
82 nVarDiff = nPos - nVarStart;
83 ++nCount;
85 else if ( nPos != nVarStart + nCount * nVarDiff ) //! keep VarEnd?
86 Flush();
87 else
88 ++nCount;
91 if ( !nCount )
93 // first line (or flushed above) - just store
95 nFixStart = nStart;
96 nFixEnd = nEnd;
97 nVarStart = nPos;
98 nVarDiff = 0;
99 nCount = 1;
103 void ScGridMerger::AddHorLine( long nX1, long nX2, long nY )
105 if ( bOptimize )
107 if ( bVertical )
109 Flush();
110 bVertical = FALSE;
112 AddLine( nX1, nX2, nY );
114 else
115 pDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
118 void ScGridMerger::AddVerLine( long nX, long nY1, long nY2 )
120 if ( bOptimize )
122 if ( !bVertical )
124 Flush();
125 bVertical = TRUE;
127 AddLine( nY1, nY2, nX );
129 else
130 pDev->DrawLine( Point( nX, nY1 ), Point( nX, nY2 ) );
133 void ScGridMerger::Flush()
135 if (nCount)
137 if (bVertical)
139 if ( nCount == 1 )
140 pDev->DrawLine( Point( nVarStart, nFixStart ), Point( nVarStart, nFixEnd ) );
141 else
143 long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
144 if ( nVarDiff < 0 )
146 // nVarDiff is negative in RTL layout mode
147 // Change the positions so DrawGrid is called with a positive distance
148 // (nVarStart / nVarDiff can be modified, aren't used after Flush)
150 nVarDiff = -nVarDiff;
151 long nTemp = nVarStart;
152 nVarStart = nVarEnd;
153 nVarEnd = nTemp;
155 pDev->DrawGrid( Rectangle( nVarStart, nFixStart, nVarEnd, nFixEnd ),
156 Size( nVarDiff, nFixEnd - nFixStart ),
157 GRID_VERTLINES );
160 else
162 if ( nCount == 1 )
163 pDev->DrawLine( Point( nFixStart, nVarStart ), Point( nFixEnd, nVarStart ) );
164 else
166 long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
167 pDev->DrawGrid( Rectangle( nFixStart, nVarStart, nFixEnd, nVarEnd ),
168 Size( nFixEnd - nFixStart, nVarDiff ),
169 GRID_HORZLINES );
172 nCount = 0;