xref: /aoo41x/main/sc/source/ui/view/gridwin4.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 ---------------------------------------------------------------
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "scitems.hxx"
36*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <svtools/colorcfg.hxx>
40*cdf0e10cSrcweir #include <editeng/colritem.hxx>
41*cdf0e10cSrcweir #include <editeng/editview.hxx>
42*cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
43*cdf0e10cSrcweir #include <editeng/scripttypeitem.hxx>
44*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
45*cdf0e10cSrcweir #include <sfx2/printer.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <svx/svdview.hxx>
48*cdf0e10cSrcweir #include "tabvwsh.hxx"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include "gridwin.hxx"
51*cdf0e10cSrcweir #include "viewdata.hxx"
52*cdf0e10cSrcweir #include "output.hxx"
53*cdf0e10cSrcweir #include "document.hxx"
54*cdf0e10cSrcweir #include "attrib.hxx"
55*cdf0e10cSrcweir #include "patattr.hxx"			// InvertSimple
56*cdf0e10cSrcweir #include "dbcolect.hxx"
57*cdf0e10cSrcweir #include "docoptio.hxx"
58*cdf0e10cSrcweir #include "notemark.hxx"
59*cdf0e10cSrcweir #include "dbfunc.hxx"			// oder GetPageBreakData an die ViewData
60*cdf0e10cSrcweir #include "scmod.hxx"
61*cdf0e10cSrcweir #include "inputhdl.hxx"
62*cdf0e10cSrcweir #include "rfindlst.hxx"
63*cdf0e10cSrcweir #include "hiranges.hxx"
64*cdf0e10cSrcweir #include "pagedata.hxx"
65*cdf0e10cSrcweir #include "docpool.hxx"
66*cdf0e10cSrcweir #include "globstr.hrc"
67*cdf0e10cSrcweir #include "docsh.hxx"			// oder GetSfxInPlaceObject
68*cdf0e10cSrcweir #include "cbutton.hxx"
69*cdf0e10cSrcweir #include "invmerge.hxx"
70*cdf0e10cSrcweir #include "editutil.hxx"
71*cdf0e10cSrcweir #include "inputopt.hxx"
72*cdf0e10cSrcweir #include "fillinfo.hxx"
73*cdf0e10cSrcweir #include "dpcontrol.hxx"
74*cdf0e10cSrcweir #include "queryparam.hxx"
75*cdf0e10cSrcweir #include "sc.hrc"
76*cdf0e10cSrcweir #include <vcl/virdev.hxx>
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir // #i74769#
79*cdf0e10cSrcweir #include <svx/sdrpaintwindow.hxx>
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir //#include "tabvwsh.hxx"			//! Test !!!!
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir //------------------------------------------------------------------------
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir void lcl_LimitRect( Rectangle& rRect, const Rectangle& rVisible )
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir 	if ( rRect.Top()    < rVisible.Top()-1 )    rRect.Top()    = rVisible.Top()-1;
88*cdf0e10cSrcweir //	if ( rRect.Left()   < rVisible.Left()-1 )   rRect.Left()   = rVisible.Left()-1;
89*cdf0e10cSrcweir 	if ( rRect.Bottom() > rVisible.Bottom()+1 ) rRect.Bottom() = rVisible.Bottom()+1;
90*cdf0e10cSrcweir //	if ( rRect.Right()  > rVisible.Right()+1 )  rRect.Right()  = rVisible.Right()+1;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	// #51122# auch wenn das inner-Rectangle nicht sichtbar ist, muss evtl.
93*cdf0e10cSrcweir 	// die Titelzeile gezeichnet werden, darum kein Rueckgabewert mehr.
94*cdf0e10cSrcweir 	// Wenn's weit daneben liegt, wird lcl_DrawOneFrame erst gar nicht gerufen.
95*cdf0e10cSrcweir }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir void lcl_DrawOneFrame( OutputDevice* pDev, const Rectangle& rInnerPixel,
98*cdf0e10cSrcweir 						const String& rTitle, const Color& rColor, sal_Bool bTextBelow,
99*cdf0e10cSrcweir 						double nPPTX, double nPPTY, const Fraction& rZoomY,
100*cdf0e10cSrcweir 						ScDocument* pDoc, ScViewData* pButtonViewData, sal_Bool bLayoutRTL )
101*cdf0e10cSrcweir {
102*cdf0e10cSrcweir 	//	pButtonViewData wird nur benutzt, um die Button-Groesse zu setzen,
103*cdf0e10cSrcweir 	//	darf ansonsten NULL sein!
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	Rectangle aInner = rInnerPixel;
106*cdf0e10cSrcweir 	if ( bLayoutRTL )
107*cdf0e10cSrcweir 	{
108*cdf0e10cSrcweir 		aInner.Left() = rInnerPixel.Right();
109*cdf0e10cSrcweir 		aInner.Right() = rInnerPixel.Left();
110*cdf0e10cSrcweir 	}
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	Rectangle aVisible( Point(0,0), pDev->GetOutputSizePixel() );
113*cdf0e10cSrcweir 	lcl_LimitRect( aInner, aVisible );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	Rectangle aOuter = aInner;
116*cdf0e10cSrcweir 	long nHor = (long) ( SC_SCENARIO_HSPACE * nPPTX );
117*cdf0e10cSrcweir 	long nVer = (long) ( SC_SCENARIO_VSPACE * nPPTY );
118*cdf0e10cSrcweir 	aOuter.Left()	-= nHor;
119*cdf0e10cSrcweir 	aOuter.Right()	+= nHor;
120*cdf0e10cSrcweir 	aOuter.Top()	-= nVer;
121*cdf0e10cSrcweir 	aOuter.Bottom()	+= nVer;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 	//	use ScPatternAttr::GetFont only for font size
124*cdf0e10cSrcweir 	Font aAttrFont;
125*cdf0e10cSrcweir 	((const ScPatternAttr&)pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN)).
126*cdf0e10cSrcweir 									GetFont(aAttrFont,SC_AUTOCOL_BLACK,pDev,&rZoomY);
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 	//	everything else from application font
129*cdf0e10cSrcweir 	Font aAppFont = pDev->GetSettings().GetStyleSettings().GetAppFont();
130*cdf0e10cSrcweir 	aAppFont.SetSize( aAttrFont.GetSize() );
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	aAppFont.SetAlign( ALIGN_TOP );
133*cdf0e10cSrcweir 	pDev->SetFont( aAppFont );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	Size aTextSize( pDev->GetTextWidth( rTitle ), pDev->GetTextHeight() );
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	if ( bTextBelow )
138*cdf0e10cSrcweir 		aOuter.Bottom() += aTextSize.Height();
139*cdf0e10cSrcweir 	else
140*cdf0e10cSrcweir 		aOuter.Top()    -= aTextSize.Height();
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	pDev->SetLineColor();
143*cdf0e10cSrcweir 	pDev->SetFillColor( rColor );
144*cdf0e10cSrcweir 	//	links, oben, rechts, unten
145*cdf0e10cSrcweir 	pDev->DrawRect( Rectangle( aOuter.Left(),  aOuter.Top(),    aInner.Left(),  aOuter.Bottom() ) );
146*cdf0e10cSrcweir 	pDev->DrawRect( Rectangle( aOuter.Left(),  aOuter.Top(),    aOuter.Right(), aInner.Top()    ) );
147*cdf0e10cSrcweir 	pDev->DrawRect( Rectangle( aInner.Right(), aOuter.Top(),    aOuter.Right(), aOuter.Bottom() ) );
148*cdf0e10cSrcweir 	pDev->DrawRect( Rectangle( aOuter.Left(),  aInner.Bottom(), aOuter.Right(), aOuter.Bottom() ) );
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	long nButtonY = bTextBelow ? aInner.Bottom() : aOuter.Top();
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	ScDDComboBoxButton aComboButton((Window*)pDev);
153*cdf0e10cSrcweir 	aComboButton.SetOptSizePixel();
154*cdf0e10cSrcweir 	long nBWidth  = ( aComboButton.GetSizePixel().Width() * rZoomY.GetNumerator() )
155*cdf0e10cSrcweir 						/ rZoomY.GetDenominator();
156*cdf0e10cSrcweir 	long nBHeight = nVer + aTextSize.Height() + 1;
157*cdf0e10cSrcweir 	Size aButSize( nBWidth, nBHeight );
158*cdf0e10cSrcweir     long nButtonPos = bLayoutRTL ? aOuter.Left() : aOuter.Right()-nBWidth+1;
159*cdf0e10cSrcweir     aComboButton.Draw( Point(nButtonPos, nButtonY), aButSize, sal_False );
160*cdf0e10cSrcweir 	if (pButtonViewData)
161*cdf0e10cSrcweir 		pButtonViewData->SetScenButSize( aButSize );
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 	long nTextStart = bLayoutRTL ? aInner.Right() - aTextSize.Width() + 1 : aInner.Left();
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 	sal_Bool bWasClip = sal_False;
166*cdf0e10cSrcweir 	Region aOldClip;
167*cdf0e10cSrcweir 	sal_Bool bClip = ( aTextSize.Width() > aOuter.Right() - nBWidth - aInner.Left() );
168*cdf0e10cSrcweir 	if ( bClip )
169*cdf0e10cSrcweir 	{
170*cdf0e10cSrcweir 		if (pDev->IsClipRegion())
171*cdf0e10cSrcweir 		{
172*cdf0e10cSrcweir 			bWasClip = sal_True;
173*cdf0e10cSrcweir 			aOldClip = pDev->GetActiveClipRegion();
174*cdf0e10cSrcweir 		}
175*cdf0e10cSrcweir 		long nClipStartX = bLayoutRTL ? aOuter.Left() + nBWidth : aInner.Left();
176*cdf0e10cSrcweir 		long nClipEndX = bLayoutRTL ? aInner.Right() : aOuter.Right() - nBWidth;
177*cdf0e10cSrcweir 		pDev->SetClipRegion( Rectangle( nClipStartX, nButtonY + nVer/2,
178*cdf0e10cSrcweir 								nClipEndX, nButtonY + nVer/2 + aTextSize.Height() ) );
179*cdf0e10cSrcweir 	}
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	pDev->DrawText( Point( nTextStart, nButtonY + nVer/2 ), rTitle );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 	if ( bClip )
184*cdf0e10cSrcweir 	{
185*cdf0e10cSrcweir 		if ( bWasClip )
186*cdf0e10cSrcweir 			pDev->SetClipRegion(aOldClip);
187*cdf0e10cSrcweir 		else
188*cdf0e10cSrcweir 			pDev->SetClipRegion();
189*cdf0e10cSrcweir 	}
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	pDev->SetFillColor();
192*cdf0e10cSrcweir 	pDev->SetLineColor( COL_BLACK );
193*cdf0e10cSrcweir 	pDev->DrawRect( aInner );
194*cdf0e10cSrcweir 	pDev->DrawRect( aOuter );
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir void lcl_DrawScenarioFrames( OutputDevice* pDev, ScViewData* pViewData, ScSplitPos eWhich,
198*cdf0e10cSrcweir 							SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 )
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
201*cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
202*cdf0e10cSrcweir 	SCTAB nTabCount = pDoc->GetTableCount();
203*cdf0e10cSrcweir 	if ( nTab+1<nTabCount && pDoc->IsScenario(nTab+1) && !pDoc->IsScenario(nTab) )
204*cdf0e10cSrcweir 	{
205*cdf0e10cSrcweir 		if ( nX1 > 0 ) --nX1;
206*cdf0e10cSrcweir 		if ( nY1>=2 ) nY1 -= 2;				// Hack: Titelzeile beruehrt zwei Zellen
207*cdf0e10cSrcweir 		else if ( nY1 > 0 ) --nY1;
208*cdf0e10cSrcweir 		if ( nX2 < MAXCOL ) ++nX2;
209*cdf0e10cSrcweir 		if ( nY2 < MAXROW-1 ) nY2 += 2;		// Hack: Titelzeile beruehrt zwei Zellen
210*cdf0e10cSrcweir 		else if ( nY2 < MAXROW ) ++nY2;
211*cdf0e10cSrcweir 		ScRange aViewRange( nX1,nY1,nTab, nX2,nY2,nTab );
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 		//!	Ranges an der Table cachen!!!!
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 		ScMarkData aMarks;
216*cdf0e10cSrcweir 		for (SCTAB i=nTab+1; i<nTabCount && pDoc->IsScenario(i); i++)
217*cdf0e10cSrcweir 			pDoc->MarkScenario( i, nTab, aMarks, sal_False, SC_SCENARIO_SHOWFRAME );
218*cdf0e10cSrcweir 		ScRangeListRef xRanges = new ScRangeList;
219*cdf0e10cSrcweir 		aMarks.FillRangeListWithMarks( xRanges, sal_False );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 		sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
222*cdf0e10cSrcweir 		long nLayoutSign = bLayoutRTL ? -1 : 1;
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 		sal_uInt16 nRangeCount = (sal_uInt16)xRanges->Count();
225*cdf0e10cSrcweir 		for (sal_uInt16 j=0; j<nRangeCount; j++)
226*cdf0e10cSrcweir 		{
227*cdf0e10cSrcweir 			ScRange aRange = *xRanges->GetObject(j);
228*cdf0e10cSrcweir 			//	Szenario-Rahmen immer dann auf zusammengefasste Zellen erweitern, wenn
229*cdf0e10cSrcweir 			//	dadurch keine neuen nicht-ueberdeckten Zellen mit umrandet werden
230*cdf0e10cSrcweir 			pDoc->ExtendTotalMerge( aRange );
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 			//!	-> Repaint beim Zusammenfassen erweitern !!!
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 			if ( aRange.Intersects( aViewRange ) )			//! Platz fuer Text/Button?
235*cdf0e10cSrcweir 			{
236*cdf0e10cSrcweir 				Point aStartPos = pViewData->GetScrPos(
237*cdf0e10cSrcweir 									aRange.aStart.Col(), aRange.aStart.Row(), eWhich, sal_True );
238*cdf0e10cSrcweir 				Point aEndPos = pViewData->GetScrPos(
239*cdf0e10cSrcweir 									aRange.aEnd.Col()+1, aRange.aEnd.Row()+1, eWhich, sal_True );
240*cdf0e10cSrcweir 				//	on the grid:
241*cdf0e10cSrcweir 				aStartPos.X() -= nLayoutSign;
242*cdf0e10cSrcweir 				aStartPos.Y() -= 1;
243*cdf0e10cSrcweir 				aEndPos.X() -= nLayoutSign;
244*cdf0e10cSrcweir 				aEndPos.Y() -= 1;
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 				sal_Bool bTextBelow = ( aRange.aStart.Row() == 0 );
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 				String aCurrent;
249*cdf0e10cSrcweir 				Color aColor( COL_LIGHTGRAY );
250*cdf0e10cSrcweir 				for (SCTAB nAct=nTab+1; nAct<nTabCount && pDoc->IsScenario(nAct); nAct++)
251*cdf0e10cSrcweir 					if ( pDoc->IsActiveScenario(nAct) && pDoc->HasScenarioRange(nAct,aRange) )
252*cdf0e10cSrcweir 					{
253*cdf0e10cSrcweir 						String aDummyComment;
254*cdf0e10cSrcweir 						sal_uInt16 nDummyFlags;
255*cdf0e10cSrcweir 						pDoc->GetName( nAct, aCurrent );
256*cdf0e10cSrcweir 						pDoc->GetScenarioData( nAct, aDummyComment, aColor, nDummyFlags );
257*cdf0e10cSrcweir 					}
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 				if (!aCurrent.Len())
260*cdf0e10cSrcweir 					aCurrent = ScGlobal::GetRscString( STR_EMPTYDATA );
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 				//!	eigener Text "(keins)" statt "(leer)" ???
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 				lcl_DrawOneFrame( pDev, Rectangle( aStartPos, aEndPos ),
265*cdf0e10cSrcweir 									aCurrent, aColor, bTextBelow,
266*cdf0e10cSrcweir 									pViewData->GetPPTX(), pViewData->GetPPTY(), pViewData->GetZoomY(),
267*cdf0e10cSrcweir 									pDoc, pViewData, bLayoutRTL );
268*cdf0e10cSrcweir 			}
269*cdf0e10cSrcweir 		}
270*cdf0e10cSrcweir 	}
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir //------------------------------------------------------------------------
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir void lcl_DrawHighlight( ScOutputData& rOutputData, ScViewData* pViewData,
276*cdf0e10cSrcweir 						ScHighlightRanges& rHighlightRanges )
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
279*cdf0e10cSrcweir 	sal_uLong nCount = rHighlightRanges.Count();
280*cdf0e10cSrcweir 	for (sal_uLong i=0; i<nCount; i++)
281*cdf0e10cSrcweir 	{
282*cdf0e10cSrcweir 		ScHighlightEntry* pEntry = rHighlightRanges.GetObject( i );
283*cdf0e10cSrcweir 		if (pEntry)
284*cdf0e10cSrcweir 		{
285*cdf0e10cSrcweir 			ScRange aRange = pEntry->aRef;
286*cdf0e10cSrcweir 			if ( nTab >= aRange.aStart.Tab() && nTab <= aRange.aEnd.Tab() )
287*cdf0e10cSrcweir 			{
288*cdf0e10cSrcweir 				rOutputData.DrawRefMark(
289*cdf0e10cSrcweir 									aRange.aStart.Col(), aRange.aStart.Row(),
290*cdf0e10cSrcweir 									aRange.aEnd.Col(), aRange.aEnd.Row(),
291*cdf0e10cSrcweir 									pEntry->aColor, sal_False );
292*cdf0e10cSrcweir 			}
293*cdf0e10cSrcweir 		}
294*cdf0e10cSrcweir 	}
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir //------------------------------------------------------------------------
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir void ScGridWindow::DoInvertRect( const Rectangle& rPixel )
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir //	Invert( PixelToLogic(rPixel) );
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	if ( rPixel == aInvertRect )
304*cdf0e10cSrcweir 		aInvertRect = Rectangle();		// aufheben
305*cdf0e10cSrcweir 	else
306*cdf0e10cSrcweir 	{
307*cdf0e10cSrcweir 		DBG_ASSERT( aInvertRect.IsEmpty(), "DoInvertRect nicht paarig" );
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 		aInvertRect = rPixel;			// neues Rechteck merken
310*cdf0e10cSrcweir 	}
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir     UpdateHeaderOverlay();      // uses aInvertRect
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir //------------------------------------------------------------------------
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir void __EXPORT ScGridWindow::PrePaint()
318*cdf0e10cSrcweir {
319*cdf0e10cSrcweir 	// forward PrePaint to DrawingLayer
320*cdf0e10cSrcweir 	ScTabViewShell* pTabViewShell = pViewData->GetViewShell();
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 	if(pTabViewShell)
323*cdf0e10cSrcweir 	{
324*cdf0e10cSrcweir 		SdrView* pDrawView = pTabViewShell->GetSdrView();
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir 		if(pDrawView)
327*cdf0e10cSrcweir 		{
328*cdf0e10cSrcweir             pDrawView->PrePaint();
329*cdf0e10cSrcweir         }
330*cdf0e10cSrcweir     }
331*cdf0e10cSrcweir }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir //------------------------------------------------------------------------
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir void __EXPORT ScGridWindow::Paint( const Rectangle& rRect )
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir     //TODO/LATER: how to get environment? Do we need that?!
338*cdf0e10cSrcweir     /*
339*cdf0e10cSrcweir 	ScDocShell* pDocSh = pViewData->GetDocShell();
340*cdf0e10cSrcweir 	SvInPlaceEnvironment* pEnv = pDocSh->GetIPEnv();
341*cdf0e10cSrcweir 	if (pEnv && pEnv->GetRectsChangedLockCount())
342*cdf0e10cSrcweir 	{
343*cdf0e10cSrcweir 		Invalidate(rRect);
344*cdf0e10cSrcweir 		return;
345*cdf0e10cSrcweir     }*/
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
348*cdf0e10cSrcweir 	if ( pDoc->IsInInterpreter() )
349*cdf0e10cSrcweir 	{
350*cdf0e10cSrcweir 		//	via Reschedule, interpretierende Zellen nicht nochmal anstossen
351*cdf0e10cSrcweir 		//	hier kein Invalidate, sonst kommt z.B. eine Error-Box nie an die Reihe
352*cdf0e10cSrcweir 		//	(Bug 36381). Durch bNeedsRepaint wird spaeter alles nochmal gemalt.
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 		if ( bNeedsRepaint )
355*cdf0e10cSrcweir 		{
356*cdf0e10cSrcweir 			//!	Rechtecke zusammenfassen?
357*cdf0e10cSrcweir 			aRepaintPixel = Rectangle();			// mehrfach -> alles painten
358*cdf0e10cSrcweir 		}
359*cdf0e10cSrcweir 		else
360*cdf0e10cSrcweir 		{
361*cdf0e10cSrcweir 			bNeedsRepaint = sal_True;
362*cdf0e10cSrcweir 			aRepaintPixel = LogicToPixel(rRect);	// nur betroffenen Bereich
363*cdf0e10cSrcweir 		}
364*cdf0e10cSrcweir 		return;
365*cdf0e10cSrcweir 	}
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	if (bIsInPaint)
368*cdf0e10cSrcweir 		return;
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir 	bIsInPaint = sal_True;
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 	Rectangle aPixRect = LogicToPixel( rRect );
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 	SCCOL nX1 = pViewData->GetPosX(eHWhich);
375*cdf0e10cSrcweir 	SCROW nY1 = pViewData->GetPosY(eVWhich);
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 	double nPPTX = pViewData->GetPPTX();
380*cdf0e10cSrcweir 	double nPPTY = pViewData->GetPPTY();
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 	Rectangle aMirroredPixel = aPixRect;
383*cdf0e10cSrcweir 	if ( pDoc->IsLayoutRTL( nTab ) )
384*cdf0e10cSrcweir 	{
385*cdf0e10cSrcweir 		//	mirror and swap
386*cdf0e10cSrcweir 		long nWidth = GetSizePixel().Width();
387*cdf0e10cSrcweir 		aMirroredPixel.Left()  = nWidth - 1 - aPixRect.Right();
388*cdf0e10cSrcweir 		aMirroredPixel.Right() = nWidth - 1 - aPixRect.Left();
389*cdf0e10cSrcweir 	}
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 	long nScrX = ScViewData::ToPixel( pDoc->GetColWidth( nX1, nTab ), nPPTX );
392*cdf0e10cSrcweir 	while ( nScrX <= aMirroredPixel.Left() && nX1 < MAXCOL )
393*cdf0e10cSrcweir 	{
394*cdf0e10cSrcweir 		++nX1;
395*cdf0e10cSrcweir 		nScrX += ScViewData::ToPixel( pDoc->GetColWidth( nX1, nTab ), nPPTX );
396*cdf0e10cSrcweir 	}
397*cdf0e10cSrcweir 	SCCOL nX2 = nX1;
398*cdf0e10cSrcweir 	while ( nScrX <= aMirroredPixel.Right() && nX2 < MAXCOL )
399*cdf0e10cSrcweir 	{
400*cdf0e10cSrcweir 		++nX2;
401*cdf0e10cSrcweir 		nScrX += ScViewData::ToPixel( pDoc->GetColWidth( nX2, nTab ), nPPTX );
402*cdf0e10cSrcweir 	}
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 	long nScrY = 0;
405*cdf0e10cSrcweir     ScViewData::AddPixelsWhile( nScrY, aPixRect.Top(), nY1, MAXROW, nPPTY, pDoc, nTab);
406*cdf0e10cSrcweir 	SCROW nY2 = nY1;
407*cdf0e10cSrcweir     if (nScrY <= aPixRect.Bottom() && nY2 < MAXROW)
408*cdf0e10cSrcweir     {
409*cdf0e10cSrcweir         ++nY2;
410*cdf0e10cSrcweir         ScViewData::AddPixelsWhile( nScrY, aPixRect.Bottom(), nY2, MAXROW, nPPTY, pDoc, nTab);
411*cdf0e10cSrcweir     }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 	Draw( nX1,nY1,nX2,nY2, SC_UPDATE_MARKS );			// nicht weiterzeichnen
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 	bIsInPaint = sal_False;
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir //
419*cdf0e10cSrcweir // 	Draw  ----------------------------------------------------------------
420*cdf0e10cSrcweir //
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir void ScGridWindow::Draw( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, ScUpdateMode eMode )
423*cdf0e10cSrcweir {
424*cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
425*cdf0e10cSrcweir 	sal_Bool bTextWysiwyg = pScMod->GetInputOptions().GetTextWysiwyg();
426*cdf0e10cSrcweir 	sal_Bool bGridFirst = sal_True;		//! entscheiden!!!
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 	if (pViewData->IsMinimized())
429*cdf0e10cSrcweir 		return;
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir 	PutInOrder( nX1, nX2 );
432*cdf0e10cSrcweir 	PutInOrder( nY1, nY2 );
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir 	DBG_ASSERT( ValidCol(nX2) && ValidRow(nY2), "GridWin Draw Bereich zu gross" );
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 	SCCOL nPosX = pViewData->GetPosX( eHWhich );
437*cdf0e10cSrcweir 	SCROW nPosY = pViewData->GetPosY( eVWhich );
438*cdf0e10cSrcweir 	if (nX2 < nPosX || nY2 < nPosY)
439*cdf0e10cSrcweir 		return;											// unsichtbar
440*cdf0e10cSrcweir 	if (nX1 < nPosX) nX1 = nPosX;
441*cdf0e10cSrcweir 	if (nY1 < nPosY) nY1 = nPosY;
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 	SCCOL nXRight = nPosX + pViewData->VisibleCellsX(eHWhich);
444*cdf0e10cSrcweir 	if (nXRight > MAXCOL) nXRight = MAXCOL;
445*cdf0e10cSrcweir 	SCROW nYBottom = nPosY + pViewData->VisibleCellsY(eVWhich);
446*cdf0e10cSrcweir 	if (nYBottom > MAXROW) nYBottom = MAXROW;
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir     // Store the current visible range.
449*cdf0e10cSrcweir     maVisibleRange.mnCol1 = nPosX;
450*cdf0e10cSrcweir     maVisibleRange.mnCol2 = nXRight;
451*cdf0e10cSrcweir     maVisibleRange.mnRow1 = nPosY;
452*cdf0e10cSrcweir     maVisibleRange.mnRow2 = nYBottom;
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir 	if (nX1 > nXRight || nY1 > nYBottom)
455*cdf0e10cSrcweir 		return;											// unsichtbar
456*cdf0e10cSrcweir 	if (nX2 > nXRight) nX2 = nXRight;
457*cdf0e10cSrcweir 	if (nY2 > nYBottom) nY2 = nYBottom;
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 	if ( eMode != SC_UPDATE_MARKS )
460*cdf0e10cSrcweir 		if (nX2 < nXRight)
461*cdf0e10cSrcweir 			nX2 = nXRight;								// zum Weiterzeichnen
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 		//	ab hier kein return mehr
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 	++nPaintCount;					// merken, dass gemalt wird (wichtig beim Invertieren)
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 	ScDocShell* pDocSh = pViewData->GetDocShell();
468*cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
469*cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 	pDoc->ExtendHidden( nX1, nY1, nX2, nY2, nTab );
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir 	Point aScrPos = pViewData->GetScrPos( nX1, nY1, eWhich );
474*cdf0e10cSrcweir 	long nMirrorWidth = GetSizePixel().Width();
475*cdf0e10cSrcweir 	sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
476*cdf0e10cSrcweir 	long nLayoutSign = bLayoutRTL ? -1 : 1;
477*cdf0e10cSrcweir 	if ( bLayoutRTL )
478*cdf0e10cSrcweir 	{
479*cdf0e10cSrcweir 		long nEndPixel = pViewData->GetScrPos( nX2+1, nPosY, eWhich ).X();
480*cdf0e10cSrcweir 		nMirrorWidth = aScrPos.X() - nEndPixel;
481*cdf0e10cSrcweir 		aScrPos.X() = nEndPixel + 1;
482*cdf0e10cSrcweir 	}
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir 	long nScrX = aScrPos.X();
485*cdf0e10cSrcweir 	long nScrY = aScrPos.Y();
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 	SCCOL nCurX = pViewData->GetCurX();
488*cdf0e10cSrcweir 	SCROW nCurY = pViewData->GetCurY();
489*cdf0e10cSrcweir 	SCCOL nCurEndX = nCurX;
490*cdf0e10cSrcweir 	SCROW nCurEndY = nCurY;
491*cdf0e10cSrcweir 	pDoc->ExtendMerge( nCurX, nCurY, nCurEndX, nCurEndY, nTab );
492*cdf0e10cSrcweir 	sal_Bool bCurVis = nCursorHideCount==0 &&
493*cdf0e10cSrcweir 					( nCurEndX+1 >= nX1 && nCurX <= nX2+1 && nCurEndY+1 >= nY1 && nCurY <= nY2+1 );
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 	//	AutoFill-Anfasser
496*cdf0e10cSrcweir 	if ( !bCurVis && nCursorHideCount==0 && bAutoMarkVisible && aAutoMarkPos.Tab() == nTab &&
497*cdf0e10cSrcweir 			( aAutoMarkPos.Col() != nCurX || aAutoMarkPos.Row() != nCurY ) )
498*cdf0e10cSrcweir 	{
499*cdf0e10cSrcweir 		SCCOL nHdlX = aAutoMarkPos.Col();
500*cdf0e10cSrcweir 		SCROW nHdlY = aAutoMarkPos.Row();
501*cdf0e10cSrcweir 		pDoc->ExtendMerge( nHdlX, nHdlY, nHdlX, nHdlY, nTab );
502*cdf0e10cSrcweir 		bCurVis = ( nHdlX+1 >= nX1 && nHdlX <= nX2 && nHdlY+1 >= nY1 && nHdlY <= nY2 );
503*cdf0e10cSrcweir 		//	links und oben ist nicht betroffen
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 		//!	AutoFill-Anfasser alleine (ohne Cursor) zeichnen ???
506*cdf0e10cSrcweir 	}
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir 	double nPPTX = pViewData->GetPPTX();
509*cdf0e10cSrcweir 	double nPPTY = pViewData->GetPPTY();
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir 	const ScViewOptions& rOpts = pViewData->GetOptions();
512*cdf0e10cSrcweir 	sal_Bool bFormulaMode = rOpts.GetOption( VOPT_FORMULAS );
513*cdf0e10cSrcweir 	sal_Bool bMarkClipped = rOpts.GetOption( VOPT_CLIPMARKS );
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 		// Datenblock
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir     ScTableInfo aTabInfo;
518*cdf0e10cSrcweir     pDoc->FillInfo( aTabInfo, nX1, nY1, nX2, nY2, nTab,
519*cdf0e10cSrcweir 										nPPTX, nPPTY, sal_False, bFormulaMode,
520*cdf0e10cSrcweir 										&pViewData->GetMarkData() );
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir 	//--------------------------------------------------------------------
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir 	Fraction aZoomX = pViewData->GetZoomX();
525*cdf0e10cSrcweir 	Fraction aZoomY = pViewData->GetZoomY();
526*cdf0e10cSrcweir     ScOutputData aOutputData( this, OUTTYPE_WINDOW, aTabInfo, pDoc, nTab,
527*cdf0e10cSrcweir 								nScrX, nScrY, nX1, nY1, nX2, nY2, nPPTX, nPPTY,
528*cdf0e10cSrcweir 								&aZoomX, &aZoomY );
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 	aOutputData.SetMirrorWidth( nMirrorWidth );			// needed for RTL
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir     std::auto_ptr< VirtualDevice > xFmtVirtDev;
533*cdf0e10cSrcweir     sal_Bool bLogicText = bTextWysiwyg;                     // call DrawStrings in logic MapMode?
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 	if ( bTextWysiwyg )
536*cdf0e10cSrcweir 	{
537*cdf0e10cSrcweir 		//	use printer for text formatting
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir 		OutputDevice* pFmtDev = pDoc->GetPrinter();
540*cdf0e10cSrcweir 		pFmtDev->SetMapMode( pViewData->GetLogicMode(eWhich) );
541*cdf0e10cSrcweir 		aOutputData.SetFmtDevice( pFmtDev );
542*cdf0e10cSrcweir 	}
543*cdf0e10cSrcweir     else if ( aZoomX != aZoomY && pViewData->IsOle() )
544*cdf0e10cSrcweir     {
545*cdf0e10cSrcweir         //  #i45033# For OLE inplace editing with different zoom factors,
546*cdf0e10cSrcweir         //  use a virtual device with 1/100th mm as text formatting reference
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir         xFmtVirtDev.reset( new VirtualDevice );
549*cdf0e10cSrcweir         xFmtVirtDev->SetMapMode( MAP_100TH_MM );
550*cdf0e10cSrcweir         aOutputData.SetFmtDevice( xFmtVirtDev.get() );
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir         bLogicText = sal_True;                      // use logic MapMode
553*cdf0e10cSrcweir     }
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir     const svtools::ColorConfig& rColorCfg = pScMod->GetColorConfig();
556*cdf0e10cSrcweir     Color aGridColor( rColorCfg.GetColorValue( svtools::CALCGRID, sal_False ).nColor );
557*cdf0e10cSrcweir 	if ( aGridColor.GetColor() == COL_TRANSPARENT )
558*cdf0e10cSrcweir 	{
559*cdf0e10cSrcweir 		//	use view options' grid color only if color config has "automatic" color
560*cdf0e10cSrcweir 		aGridColor = rOpts.GetGridColor();
561*cdf0e10cSrcweir 	}
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir 	aOutputData.SetSyntaxMode		( pViewData->IsSyntaxMode() );
564*cdf0e10cSrcweir 	aOutputData.SetGridColor		( aGridColor );
565*cdf0e10cSrcweir 	aOutputData.SetShowNullValues	( rOpts.GetOption( VOPT_NULLVALS ) );
566*cdf0e10cSrcweir 	aOutputData.SetShowFormulas		( bFormulaMode );
567*cdf0e10cSrcweir     aOutputData.SetShowSpellErrors  ( pDoc->GetDocOptions().IsAutoSpell() );
568*cdf0e10cSrcweir 	aOutputData.SetMarkClipped		( bMarkClipped );
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir 	aOutputData.SetUseStyleColor( sal_True );		// always set in table view
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 	aOutputData.SetEditObject( GetEditObject() );
573*cdf0e10cSrcweir 	aOutputData.SetViewShell( pViewData->GetViewShell() );
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir 	sal_Bool bGrid = rOpts.GetOption( VOPT_GRID );
576*cdf0e10cSrcweir 	sal_Bool bPage = rOpts.GetOption( VOPT_PAGEBREAKS );
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir 	if ( eMode == SC_UPDATE_CHANGED )
579*cdf0e10cSrcweir 	{
580*cdf0e10cSrcweir 		aOutputData.FindChanged();
581*cdf0e10cSrcweir 		aOutputData.SetSingleGrid(sal_True);
582*cdf0e10cSrcweir 	}
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 	sal_Bool bPageMode = pViewData->IsPagebreakMode();
585*cdf0e10cSrcweir 	if (bPageMode)										// nach FindChanged
586*cdf0e10cSrcweir 	{
587*cdf0e10cSrcweir 		// SetPagebreakMode initialisiert auch bPrinted Flags
588*cdf0e10cSrcweir 		aOutputData.SetPagebreakMode( pViewData->GetView()->GetPageBreakData() );
589*cdf0e10cSrcweir 	}
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir 	EditView*	pEditView = NULL;
592*cdf0e10cSrcweir 	sal_Bool		bEditMode = pViewData->HasEditView(eWhich);
593*cdf0e10cSrcweir 	if ( bEditMode && pViewData->GetRefTabNo() == nTab )
594*cdf0e10cSrcweir 	{
595*cdf0e10cSrcweir 		SCCOL nEditCol;
596*cdf0e10cSrcweir 		SCROW nEditRow;
597*cdf0e10cSrcweir 		pViewData->GetEditView( eWhich, pEditView, nEditCol, nEditRow );
598*cdf0e10cSrcweir 		SCCOL nEditEndCol = pViewData->GetEditEndCol();
599*cdf0e10cSrcweir 		SCROW nEditEndRow = pViewData->GetEditEndRow();
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir 		if ( nEditEndCol >= nX1 && nEditCol <= nX2 && nEditEndRow >= nY1 && nEditRow <= nY2 )
602*cdf0e10cSrcweir 			aOutputData.SetEditCell( nEditCol, nEditRow );
603*cdf0e10cSrcweir 		else
604*cdf0e10cSrcweir 			bEditMode = sal_False;
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 		//	nur Edit-Area zu zeichnen?
607*cdf0e10cSrcweir 		//!	dann muss trotzdem noch der Rand / das Gitter gemalt werden!
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir //		if ( nEditCol <= nX1 && nEditEndCol >= nX2 && nEditRow <= nY1 && nEditEndRow >= nY2 )
610*cdf0e10cSrcweir //			bOnlyEdit = sal_True;
611*cdf0e10cSrcweir 	}
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir 	// define drawing layer map mode and paint rectangle
614*cdf0e10cSrcweir 	const MapMode aDrawMode = GetDrawMapMode();
615*cdf0e10cSrcweir 	Rectangle aDrawingRectLogic;
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir 	{
618*cdf0e10cSrcweir 		// get drawing pixel rect
619*cdf0e10cSrcweir 		Rectangle aDrawingRectPixel(Point(nScrX, nScrY), Size(aOutputData.GetScrW(), aOutputData.GetScrH()));
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 		// correct for border (left/right)
622*cdf0e10cSrcweir 		if(MAXCOL == nX2)
623*cdf0e10cSrcweir 		{
624*cdf0e10cSrcweir 			if(bLayoutRTL)
625*cdf0e10cSrcweir 			{
626*cdf0e10cSrcweir 				aDrawingRectPixel.Left() = 0L;
627*cdf0e10cSrcweir 			}
628*cdf0e10cSrcweir 			else
629*cdf0e10cSrcweir 			{
630*cdf0e10cSrcweir 				aDrawingRectPixel.Right() = GetOutputSizePixel().getWidth();
631*cdf0e10cSrcweir 			}
632*cdf0e10cSrcweir 		}
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir 		// correct for border (bottom)
635*cdf0e10cSrcweir 		if(MAXROW == nY2)
636*cdf0e10cSrcweir 		{
637*cdf0e10cSrcweir 			aDrawingRectPixel.Bottom() = GetOutputSizePixel().getHeight();
638*cdf0e10cSrcweir 		}
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir 		// get logic positions
641*cdf0e10cSrcweir 		aDrawingRectLogic = PixelToLogic(aDrawingRectPixel, aDrawMode);
642*cdf0e10cSrcweir 	}
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir // not necessary with overlay
645*cdf0e10cSrcweir //	if (bCurVis)
646*cdf0e10cSrcweir //		HideCursor();
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir     OutputDevice* pContentDev = this;       // device for document content, used by overlay manager
649*cdf0e10cSrcweir 	SdrPaintWindow* pTargetPaintWindow = 0;	// #i74769# work with SdrPaintWindow directly
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir 	{
652*cdf0e10cSrcweir 		// init redraw
653*cdf0e10cSrcweir 		ScTabViewShell* pTabViewShell = pViewData->GetViewShell();
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir 		if(pTabViewShell)
656*cdf0e10cSrcweir 		{
657*cdf0e10cSrcweir 			MapMode aCurrentMapMode(pContentDev->GetMapMode());
658*cdf0e10cSrcweir 			pContentDev->SetMapMode(aDrawMode);
659*cdf0e10cSrcweir 			SdrView* pDrawView = pTabViewShell->GetSdrView();
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir 			if(pDrawView)
662*cdf0e10cSrcweir 			{
663*cdf0e10cSrcweir 				// #i74769# Use new BeginDrawLayers() interface
664*cdf0e10cSrcweir 				Region aDrawingRegion(aDrawingRectLogic);
665*cdf0e10cSrcweir 				pTargetPaintWindow = pDrawView->BeginDrawLayers(this, aDrawingRegion);
666*cdf0e10cSrcweir 				OSL_ENSURE(pTargetPaintWindow, "BeginDrawLayers: Got no SdrPaintWindow (!)");
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir 				// #i74769# get target device from SdrPaintWindow, this may be the prerender
669*cdf0e10cSrcweir 				// device now, too.
670*cdf0e10cSrcweir 				pContentDev = &(pTargetPaintWindow->GetTargetOutputDevice());
671*cdf0e10cSrcweir                 aOutputData.SetContentDevice( pContentDev );
672*cdf0e10cSrcweir 			}
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir 			pContentDev->SetMapMode(aCurrentMapMode);
675*cdf0e10cSrcweir 		}
676*cdf0e10cSrcweir 	}
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir 	//	Rand (Wiese) (Pixel)
679*cdf0e10cSrcweir 	if ( nX2==MAXCOL || nY2==MAXROW )
680*cdf0e10cSrcweir 	{
681*cdf0e10cSrcweir 		// save MapMode and set to pixel
682*cdf0e10cSrcweir 		MapMode aCurrentMapMode(pContentDev->GetMapMode());
683*cdf0e10cSrcweir 		pContentDev->SetMapMode(MAP_PIXEL);
684*cdf0e10cSrcweir 
685*cdf0e10cSrcweir 		Rectangle aPixRect = Rectangle( Point(), GetOutputSizePixel() );
686*cdf0e10cSrcweir         pContentDev->SetFillColor( rColorCfg.GetColorValue(svtools::APPBACKGROUND).nColor );
687*cdf0e10cSrcweir 		pContentDev->SetLineColor();
688*cdf0e10cSrcweir 		if ( nX2==MAXCOL )
689*cdf0e10cSrcweir 		{
690*cdf0e10cSrcweir 			Rectangle aDrawRect( aPixRect );
691*cdf0e10cSrcweir 			if ( bLayoutRTL )
692*cdf0e10cSrcweir 				aDrawRect.Right() = nScrX - 1;
693*cdf0e10cSrcweir 			else
694*cdf0e10cSrcweir 				aDrawRect.Left() = nScrX + aOutputData.GetScrW();
695*cdf0e10cSrcweir 			if (aDrawRect.Right() >= aDrawRect.Left())
696*cdf0e10cSrcweir 				pContentDev->DrawRect( aDrawRect );
697*cdf0e10cSrcweir 		}
698*cdf0e10cSrcweir 		if ( nY2==MAXROW )
699*cdf0e10cSrcweir 		{
700*cdf0e10cSrcweir 			Rectangle aDrawRect( aPixRect );
701*cdf0e10cSrcweir 			aDrawRect.Top() = nScrY + aOutputData.GetScrH();
702*cdf0e10cSrcweir 			if ( nX2==MAXCOL )
703*cdf0e10cSrcweir 			{
704*cdf0e10cSrcweir 				// no double painting of the corner
705*cdf0e10cSrcweir 				if ( bLayoutRTL )
706*cdf0e10cSrcweir 					aDrawRect.Left() = nScrX;
707*cdf0e10cSrcweir 				else
708*cdf0e10cSrcweir 					aDrawRect.Right() = nScrX + aOutputData.GetScrW() - 1;
709*cdf0e10cSrcweir 			}
710*cdf0e10cSrcweir 			if (aDrawRect.Bottom() >= aDrawRect.Top())
711*cdf0e10cSrcweir 				pContentDev->DrawRect( aDrawRect );
712*cdf0e10cSrcweir 		}
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir 		// restore MapMode
715*cdf0e10cSrcweir 		pContentDev->SetMapMode(aCurrentMapMode);
716*cdf0e10cSrcweir 	}
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir 	if ( pDoc->HasBackgroundDraw( nTab, aDrawingRectLogic ) )
719*cdf0e10cSrcweir 	{
720*cdf0e10cSrcweir 		pContentDev->SetMapMode(MAP_PIXEL);
721*cdf0e10cSrcweir 		aOutputData.DrawClear();
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir 			// Drawing Hintergrund
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir 		pContentDev->SetMapMode(aDrawMode);
726*cdf0e10cSrcweir 		DrawRedraw( aOutputData, eMode, SC_LAYER_BACK );
727*cdf0e10cSrcweir 	}
728*cdf0e10cSrcweir 	else
729*cdf0e10cSrcweir 		aOutputData.SetSolidBackground(sal_True);
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir 	pContentDev->SetMapMode(MAP_PIXEL);
732*cdf0e10cSrcweir 	aOutputData.DrawBackground();
733*cdf0e10cSrcweir 	if ( bGridFirst && ( bGrid || bPage ) )
734*cdf0e10cSrcweir 		aOutputData.DrawGrid( bGrid, bPage );
735*cdf0e10cSrcweir 	if ( bPageMode )
736*cdf0e10cSrcweir 	{
737*cdf0e10cSrcweir 		// #87655# DrawPagePreview draws complete lines/page numbers, must always be clipped
738*cdf0e10cSrcweir 		if ( aOutputData.SetChangedClip() )
739*cdf0e10cSrcweir 		{
740*cdf0e10cSrcweir             DrawPagePreview(nX1,nY1,nX2,nY2, pContentDev);
741*cdf0e10cSrcweir 			pContentDev->SetClipRegion();
742*cdf0e10cSrcweir 		}
743*cdf0e10cSrcweir 	}
744*cdf0e10cSrcweir 	aOutputData.DrawShadow();
745*cdf0e10cSrcweir 	aOutputData.DrawFrame();
746*cdf0e10cSrcweir 	if ( !bLogicText )
747*cdf0e10cSrcweir 		aOutputData.DrawStrings(sal_False);		// in pixel MapMode
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir     // edit cells and printer-metrics text must be before the buttons
750*cdf0e10cSrcweir     // (DataPilot buttons contain labels in UI font)
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir     pContentDev->SetMapMode(pViewData->GetLogicMode(eWhich));
753*cdf0e10cSrcweir     if ( bLogicText )
754*cdf0e10cSrcweir         aOutputData.DrawStrings(sal_True);      // in logic MapMode if bTextWysiwyg is set
755*cdf0e10cSrcweir     aOutputData.DrawEdit(sal_True);
756*cdf0e10cSrcweir     pContentDev->SetMapMode(MAP_PIXEL);
757*cdf0e10cSrcweir 
758*cdf0e10cSrcweir 		// Autofilter- und Pivot-Buttons
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir     DrawButtons( nX1, nY1, nX2, nY2, aTabInfo, pContentDev );          // Pixel
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir 		// Notiz-Anzeiger
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir 	if ( rOpts.GetOption( VOPT_NOTES ) )
765*cdf0e10cSrcweir 		aOutputData.DrawNoteMarks();
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir 	if ( !bGridFirst && ( bGrid || bPage ) )
768*cdf0e10cSrcweir 	{
769*cdf0e10cSrcweir 		aOutputData.DrawGrid( bGrid, bPage );
770*cdf0e10cSrcweir 	}
771*cdf0e10cSrcweir 	aOutputData.DrawClipMarks();
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir 	//	Szenario / ChangeTracking muss auf jeden Fall nach DrawGrid sein, auch bei !bGridFirst
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir 	//!	Test, ob ChangeTrack-Anzeige aktiv ist
776*cdf0e10cSrcweir 	//!	Szenario-Rahmen per View-Optionen abschaltbar?
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir 	SCTAB nTabCount = pDoc->GetTableCount();
779*cdf0e10cSrcweir 	ScHighlightRanges* pHigh = pViewData->GetView()->GetHighlightRanges();
780*cdf0e10cSrcweir 	sal_Bool bHasScenario = ( nTab+1<nTabCount && pDoc->IsScenario(nTab+1) && !pDoc->IsScenario(nTab) );
781*cdf0e10cSrcweir 	sal_Bool bHasChange = ( pDoc->GetChangeTrack() != NULL );
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir 	if ( bHasChange || bHasScenario || pHigh != NULL )
784*cdf0e10cSrcweir 	{
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir 		//! SetChangedClip() mit DrawMarks() zusammenfassen?? (anderer MapMode!)
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir 		sal_Bool bAny = sal_True;
789*cdf0e10cSrcweir 		if (eMode == SC_UPDATE_CHANGED)
790*cdf0e10cSrcweir 			bAny = aOutputData.SetChangedClip();
791*cdf0e10cSrcweir 		if (bAny)
792*cdf0e10cSrcweir 		{
793*cdf0e10cSrcweir 			if ( bHasChange )
794*cdf0e10cSrcweir 				aOutputData.DrawChangeTrack();
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir 			if ( bHasScenario )
797*cdf0e10cSrcweir 				lcl_DrawScenarioFrames( pContentDev, pViewData, eWhich, nX1,nY1,nX2,nY2 );
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir 			if ( pHigh )
800*cdf0e10cSrcweir 				lcl_DrawHighlight( aOutputData, pViewData, *pHigh );
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir 			if (eMode == SC_UPDATE_CHANGED)
803*cdf0e10cSrcweir 				pContentDev->SetClipRegion();
804*cdf0e10cSrcweir 		}
805*cdf0e10cSrcweir 	}
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir 		// Drawing Vordergrund
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir 	pContentDev->SetMapMode(aDrawMode);
810*cdf0e10cSrcweir 
811*cdf0e10cSrcweir 	DrawRedraw( aOutputData, eMode, SC_LAYER_FRONT );
812*cdf0e10cSrcweir 	DrawRedraw( aOutputData, eMode, SC_LAYER_INTERN );
813*cdf0e10cSrcweir     DrawSdrGrid( aDrawingRectLogic, pContentDev );
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir 	if (!bIsInScroll)								// Drawing Markierungen
816*cdf0e10cSrcweir 	{
817*cdf0e10cSrcweir 		if(eMode == SC_UPDATE_CHANGED && aOutputData.SetChangedClip())
818*cdf0e10cSrcweir 		{
819*cdf0e10cSrcweir 			pContentDev->SetClipRegion();
820*cdf0e10cSrcweir 		}
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir 		//sal_Bool bDraw = sal_True;
823*cdf0e10cSrcweir 		//if (eMode == SC_UPDATE_CHANGED)
824*cdf0e10cSrcweir 		//	bDraw = NeedDrawMarks() && aOutputData.SetChangedClip();
825*cdf0e10cSrcweir 		//if (bDraw)
826*cdf0e10cSrcweir 		//{
827*cdf0e10cSrcweir 		//	DrawMarks();
828*cdf0e10cSrcweir 		//	if (eMode == SC_UPDATE_CHANGED)
829*cdf0e10cSrcweir 		//		pContentDev->SetClipRegion();
830*cdf0e10cSrcweir 		//}
831*cdf0e10cSrcweir 	}
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir 	pContentDev->SetMapMode(MAP_PIXEL);
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir #ifdef OLD_SELECTION_PAINT
836*cdf0e10cSrcweir 	if (pViewData->IsActive())
837*cdf0e10cSrcweir 		aOutputData.DrawMark( this );
838*cdf0e10cSrcweir #endif
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir 	if ( pViewData->IsRefMode() && nTab >= pViewData->GetRefStartZ() && nTab <= pViewData->GetRefEndZ() )
841*cdf0e10cSrcweir 	{
842*cdf0e10cSrcweir         // The AutoFill shrink area has an own overlay now
843*cdf0e10cSrcweir #if 0
844*cdf0e10cSrcweir 		//	Schraffur beim Loeschen per AutoFill
845*cdf0e10cSrcweir 		if ( pViewData->GetRefType() == SC_REFTYPE_FILL )
846*cdf0e10cSrcweir 		{
847*cdf0e10cSrcweir 			ScRange aRange;
848*cdf0e10cSrcweir 			if ( pViewData->GetDelMark( aRange ) )
849*cdf0e10cSrcweir 			{
850*cdf0e10cSrcweir 				if ( aRange.aStart.Col() < nX1 ) aRange.aStart.SetCol(nX1);
851*cdf0e10cSrcweir 				if ( aRange.aEnd.Col() > nX2 )	 aRange.aEnd.SetCol(nX2);
852*cdf0e10cSrcweir 				if ( aRange.aStart.Row() < nY1 ) aRange.aStart.SetRow(nY1);
853*cdf0e10cSrcweir 				if ( aRange.aEnd.Row() > nY2 )	 aRange.aEnd.SetRow(nY2);
854*cdf0e10cSrcweir 				if ( aRange.aStart.Col() <= aRange.aEnd.Col() &&
855*cdf0e10cSrcweir 					 aRange.aStart.Row() <= aRange.aEnd.Row() )
856*cdf0e10cSrcweir 				{
857*cdf0e10cSrcweir 					Point aStart = pViewData->GetScrPos( aRange.aStart.Col(),
858*cdf0e10cSrcweir 														 aRange.aStart.Row(), eWhich );
859*cdf0e10cSrcweir 					Point aEnd = pViewData->GetScrPos( aRange.aEnd.Col()+1,
860*cdf0e10cSrcweir 													   aRange.aEnd.Row()+1, eWhich );
861*cdf0e10cSrcweir 					aEnd.X() -= 1;
862*cdf0e10cSrcweir 					aEnd.Y() -= 1;
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir 					//	Markierung aufheben - roter Rahmen bleibt stehen
865*cdf0e10cSrcweir 					Rectangle aRect( aStart,aEnd );
866*cdf0e10cSrcweir 					Invert( aRect, INVERT_HIGHLIGHT );
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 					//!	Delete-Bereich extra kennzeichnen?!?!?
869*cdf0e10cSrcweir 				}
870*cdf0e10cSrcweir 			}
871*cdf0e10cSrcweir 		}
872*cdf0e10cSrcweir #endif
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir         Color aRefColor( rColorCfg.GetColorValue(svtools::CALCREFERENCE).nColor );
875*cdf0e10cSrcweir 		aOutputData.DrawRefMark( pViewData->GetRefStartX(), pViewData->GetRefStartY(),
876*cdf0e10cSrcweir 								 pViewData->GetRefEndX(), pViewData->GetRefEndY(),
877*cdf0e10cSrcweir 								 aRefColor, sal_False );
878*cdf0e10cSrcweir 	}
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir 		//	Range-Finder
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir 	ScInputHandler* pHdl = pScMod->GetInputHdl( pViewData->GetViewShell() );
883*cdf0e10cSrcweir 	if (pHdl)
884*cdf0e10cSrcweir 	{
885*cdf0e10cSrcweir 		ScRangeFindList* pRangeFinder = pHdl->GetRangeFindList();
886*cdf0e10cSrcweir 		if ( pRangeFinder && !pRangeFinder->IsHidden() &&
887*cdf0e10cSrcweir 				pRangeFinder->GetDocName() == pDocSh->GetTitle() )
888*cdf0e10cSrcweir 		{
889*cdf0e10cSrcweir 			sal_uInt16 nCount = (sal_uInt16)pRangeFinder->Count();
890*cdf0e10cSrcweir 			for (sal_uInt16 i=0; i<nCount; i++)
891*cdf0e10cSrcweir 			{
892*cdf0e10cSrcweir 				ScRangeFindData* pData = pRangeFinder->GetObject(i);
893*cdf0e10cSrcweir 				if (pData)
894*cdf0e10cSrcweir 				{
895*cdf0e10cSrcweir 					ScRange aRef = pData->aRef;
896*cdf0e10cSrcweir 					aRef.Justify();
897*cdf0e10cSrcweir 					if ( aRef.aStart.Tab() >= nTab && aRef.aEnd.Tab() <= nTab )
898*cdf0e10cSrcweir 						aOutputData.DrawRefMark( aRef.aStart.Col(), aRef.aStart.Row(),
899*cdf0e10cSrcweir 												aRef.aEnd.Col(), aRef.aEnd.Row(),
900*cdf0e10cSrcweir 												Color( ScRangeFindList::GetColorName( i ) ),
901*cdf0e10cSrcweir 												sal_True );
902*cdf0e10cSrcweir 				}
903*cdf0e10cSrcweir 			}
904*cdf0e10cSrcweir 		}
905*cdf0e10cSrcweir 	}
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir 	{
908*cdf0e10cSrcweir 		// end redraw
909*cdf0e10cSrcweir 		ScTabViewShell* pTabViewShell = pViewData->GetViewShell();
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir 		if(pTabViewShell)
912*cdf0e10cSrcweir 		{
913*cdf0e10cSrcweir 			MapMode aCurrentMapMode(pContentDev->GetMapMode());
914*cdf0e10cSrcweir 			pContentDev->SetMapMode(aDrawMode);
915*cdf0e10cSrcweir 			SdrView* pDrawView = pTabViewShell->GetSdrView();
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir 			if(pDrawView)
918*cdf0e10cSrcweir 			{
919*cdf0e10cSrcweir 				// #i74769# work with SdrPaintWindow directly
920*cdf0e10cSrcweir 				pDrawView->EndDrawLayers(*pTargetPaintWindow, true);
921*cdf0e10cSrcweir 			}
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir 			pContentDev->SetMapMode(aCurrentMapMode);
924*cdf0e10cSrcweir 		}
925*cdf0e10cSrcweir 	}
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir 	//	InPlace Edit-View
928*cdf0e10cSrcweir 	// moved after EndDrawLayers() to get it outside the overlay buffer and
929*cdf0e10cSrcweir 	// on top of everything
930*cdf0e10cSrcweir 	if ( bEditMode && (pViewData->GetRefTabNo() == pViewData->GetTabNo()) )
931*cdf0e10cSrcweir 	{
932*cdf0e10cSrcweir         //! use pContentDev for EditView?
933*cdf0e10cSrcweir         SetMapMode(MAP_PIXEL);
934*cdf0e10cSrcweir 		SCCOL nCol1 = pViewData->GetEditStartCol();
935*cdf0e10cSrcweir 		SCROW nRow1 = pViewData->GetEditStartRow();
936*cdf0e10cSrcweir 		SCCOL nCol2 = pViewData->GetEditEndCol();
937*cdf0e10cSrcweir 		SCROW nRow2 = pViewData->GetEditEndRow();
938*cdf0e10cSrcweir 		SetLineColor();
939*cdf0e10cSrcweir 		SetFillColor( pEditView->GetBackgroundColor() );
940*cdf0e10cSrcweir 		Point aStart = pViewData->GetScrPos( nCol1, nRow1, eWhich );
941*cdf0e10cSrcweir 		Point aEnd = pViewData->GetScrPos( nCol2+1, nRow2+1, eWhich );
942*cdf0e10cSrcweir 		aEnd.X() -= 2 * nLayoutSign;		// don't overwrite grid
943*cdf0e10cSrcweir 		aEnd.Y() -= 2;
944*cdf0e10cSrcweir 		DrawRect( Rectangle( aStart,aEnd ) );
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir 		SetMapMode(pViewData->GetLogicMode());
947*cdf0e10cSrcweir 		pEditView->Paint( PixelToLogic( Rectangle( Point( nScrX, nScrY ),
948*cdf0e10cSrcweir 							Size( aOutputData.GetScrW(), aOutputData.GetScrH() ) ) ) );
949*cdf0e10cSrcweir 		SetMapMode(MAP_PIXEL);
950*cdf0e10cSrcweir 	}
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir 	if (pViewData->HasEditView(eWhich))
953*cdf0e10cSrcweir 	{
954*cdf0e10cSrcweir 		// flush OverlayManager before changing the MapMode
955*cdf0e10cSrcweir 		flushOverlayManager();
956*cdf0e10cSrcweir 
957*cdf0e10cSrcweir 		// set MapMode for text edit
958*cdf0e10cSrcweir 		SetMapMode(pViewData->GetLogicMode());
959*cdf0e10cSrcweir 	}
960*cdf0e10cSrcweir 	else
961*cdf0e10cSrcweir 		SetMapMode(aDrawMode);
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir 	if ( pNoteMarker )
964*cdf0e10cSrcweir 		pNoteMarker->Draw();		// ueber den Cursor, im Drawing-MapMode
965*cdf0e10cSrcweir 
966*cdf0e10cSrcweir 	//DrawStartTimer();				// fuer bunte Handles ohne System-Clipping
967*cdf0e10cSrcweir 
968*cdf0e10cSrcweir 	//
969*cdf0e10cSrcweir 	//	Wenn waehrend des Paint etwas invertiert wurde (Selektion geaendert aus Basic-Macro),
970*cdf0e10cSrcweir 	//	ist das jetzt durcheinandergekommen und es muss neu gemalt werden
971*cdf0e10cSrcweir 	//
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir 	DBG_ASSERT(nPaintCount, "nPaintCount falsch");
974*cdf0e10cSrcweir 	--nPaintCount;
975*cdf0e10cSrcweir 	if (!nPaintCount)
976*cdf0e10cSrcweir 		CheckNeedsRepaint();
977*cdf0e10cSrcweir }
978*cdf0e10cSrcweir 
979*cdf0e10cSrcweir void ScGridWindow::CheckNeedsRepaint()
980*cdf0e10cSrcweir {
981*cdf0e10cSrcweir 	//	called at the end of painting, and from timer after background text width calculation
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir 	if (bNeedsRepaint)
984*cdf0e10cSrcweir 	{
985*cdf0e10cSrcweir 		bNeedsRepaint = sal_False;
986*cdf0e10cSrcweir 		if (aRepaintPixel.IsEmpty())
987*cdf0e10cSrcweir 			Invalidate();
988*cdf0e10cSrcweir 		else
989*cdf0e10cSrcweir 			Invalidate(PixelToLogic(aRepaintPixel));
990*cdf0e10cSrcweir 		aRepaintPixel = Rectangle();
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir         // selection function in status bar might also be invalid
993*cdf0e10cSrcweir         SfxBindings& rBindings = pViewData->GetBindings();
994*cdf0e10cSrcweir         rBindings.Invalidate( SID_STATUS_SUM );
995*cdf0e10cSrcweir         rBindings.Invalidate( SID_ATTR_SIZE );
996*cdf0e10cSrcweir         rBindings.Invalidate( SID_TABLE_CELL );
997*cdf0e10cSrcweir 	}
998*cdf0e10cSrcweir }
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, OutputDevice* pContentDev )
1001*cdf0e10cSrcweir {
1002*cdf0e10cSrcweir 	ScPageBreakData* pPageData = pViewData->GetView()->GetPageBreakData();
1003*cdf0e10cSrcweir 	if (pPageData)
1004*cdf0e10cSrcweir 	{
1005*cdf0e10cSrcweir 		ScDocument* pDoc = pViewData->GetDocument();
1006*cdf0e10cSrcweir 		SCTAB nTab = pViewData->GetTabNo();
1007*cdf0e10cSrcweir 		Size aWinSize = GetOutputSizePixel();
1008*cdf0e10cSrcweir         const svtools::ColorConfig& rColorCfg = SC_MOD()->GetColorConfig();
1009*cdf0e10cSrcweir         Color aManual( rColorCfg.GetColorValue(svtools::CALCPAGEBREAKMANUAL).nColor );
1010*cdf0e10cSrcweir         Color aAutomatic( rColorCfg.GetColorValue(svtools::CALCPAGEBREAK).nColor );
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir 		String aPageText = ScGlobal::GetRscString( STR_PAGE );
1013*cdf0e10cSrcweir 		if ( nPageScript == 0 )
1014*cdf0e10cSrcweir 		{
1015*cdf0e10cSrcweir 			//	get script type of translated "Page" string only once
1016*cdf0e10cSrcweir 			nPageScript = pDoc->GetStringScriptType( aPageText );
1017*cdf0e10cSrcweir 			if (nPageScript == 0)
1018*cdf0e10cSrcweir 				nPageScript = ScGlobal::GetDefaultScriptType();
1019*cdf0e10cSrcweir 		}
1020*cdf0e10cSrcweir 		aPageText += ' ';
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir 		Font aFont;
1023*cdf0e10cSrcweir 		ScEditEngineDefaulter* pEditEng = NULL;
1024*cdf0e10cSrcweir 		const ScPatternAttr& rDefPattern = ((const ScPatternAttr&)pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN));
1025*cdf0e10cSrcweir 		if ( nPageScript == SCRIPTTYPE_LATIN )
1026*cdf0e10cSrcweir 		{
1027*cdf0e10cSrcweir 			//	use single font and call DrawText directly
1028*cdf0e10cSrcweir 			rDefPattern.GetFont( aFont, SC_AUTOCOL_BLACK );
1029*cdf0e10cSrcweir 			aFont.SetColor( Color( COL_LIGHTGRAY ) );
1030*cdf0e10cSrcweir 			//	font size is set as needed
1031*cdf0e10cSrcweir 		}
1032*cdf0e10cSrcweir 		else
1033*cdf0e10cSrcweir 		{
1034*cdf0e10cSrcweir 			//	use EditEngine to draw mixed-script string
1035*cdf0e10cSrcweir 			pEditEng = new ScEditEngineDefaulter( EditEngine::CreatePool(), sal_True );
1036*cdf0e10cSrcweir 			pEditEng->SetRefMapMode( pContentDev->GetMapMode() );
1037*cdf0e10cSrcweir 			SfxItemSet* pEditDefaults = new SfxItemSet( pEditEng->GetEmptyItemSet() );
1038*cdf0e10cSrcweir 			rDefPattern.FillEditItemSet( pEditDefaults );
1039*cdf0e10cSrcweir 			pEditDefaults->Put( SvxColorItem( Color( COL_LIGHTGRAY ), EE_CHAR_COLOR ) );
1040*cdf0e10cSrcweir 			pEditEng->SetDefaults( pEditDefaults );
1041*cdf0e10cSrcweir 		}
1042*cdf0e10cSrcweir 
1043*cdf0e10cSrcweir         sal_uInt16 nCount = sal::static_int_cast<sal_uInt16>( pPageData->GetCount() );
1044*cdf0e10cSrcweir 		for (sal_uInt16 nPos=0; nPos<nCount; nPos++)
1045*cdf0e10cSrcweir 		{
1046*cdf0e10cSrcweir 			ScPrintRangeData& rData = pPageData->GetData(nPos);
1047*cdf0e10cSrcweir 			ScRange aRange = rData.GetPrintRange();
1048*cdf0e10cSrcweir 			if ( aRange.aStart.Col() <= nX2+1  && aRange.aEnd.Col()+1 >= nX1 &&
1049*cdf0e10cSrcweir 				 aRange.aStart.Row() <= nY2+1 && aRange.aEnd.Row()+1 >= nY1 )
1050*cdf0e10cSrcweir 			{
1051*cdf0e10cSrcweir 				//	3 Pixel Rahmen um den Druckbereich
1052*cdf0e10cSrcweir 				//	(mittlerer Pixel auf den Gitterlinien)
1053*cdf0e10cSrcweir 
1054*cdf0e10cSrcweir 				pContentDev->SetLineColor();
1055*cdf0e10cSrcweir 				if (rData.IsAutomatic())
1056*cdf0e10cSrcweir 					pContentDev->SetFillColor( aAutomatic );
1057*cdf0e10cSrcweir 				else
1058*cdf0e10cSrcweir 					pContentDev->SetFillColor( aManual );
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir 				Point aStart = pViewData->GetScrPos(
1061*cdf0e10cSrcweir 									aRange.aStart.Col(), aRange.aStart.Row(), eWhich, sal_True );
1062*cdf0e10cSrcweir 				Point aEnd = pViewData->GetScrPos(
1063*cdf0e10cSrcweir 									aRange.aEnd.Col() + 1, aRange.aEnd.Row() + 1, eWhich, sal_True );
1064*cdf0e10cSrcweir 				aStart.X() -= 2;
1065*cdf0e10cSrcweir 				aStart.Y() -= 2;
1066*cdf0e10cSrcweir 
1067*cdf0e10cSrcweir 				//	Ueberlaeufe verhindern:
1068*cdf0e10cSrcweir 				if ( aStart.X() < -10 )	aStart.X() = -10;
1069*cdf0e10cSrcweir 				if ( aStart.Y() < -10 )	aStart.Y() = -10;
1070*cdf0e10cSrcweir 				if ( aEnd.X() > aWinSize.Width() + 10 )
1071*cdf0e10cSrcweir 					aEnd.X() = aWinSize.Width() + 10;
1072*cdf0e10cSrcweir 				if ( aEnd.Y() > aWinSize.Height() + 10 )
1073*cdf0e10cSrcweir 					aEnd.Y() = aWinSize.Height() + 10;
1074*cdf0e10cSrcweir 
1075*cdf0e10cSrcweir 				pContentDev->DrawRect( Rectangle( aStart, Point(aEnd.X(),aStart.Y()+2) ) );
1076*cdf0e10cSrcweir 				pContentDev->DrawRect( Rectangle( aStart, Point(aStart.X()+2,aEnd.Y()) ) );
1077*cdf0e10cSrcweir 				pContentDev->DrawRect( Rectangle( Point(aStart.X(),aEnd.Y()-2), aEnd ) );
1078*cdf0e10cSrcweir 				pContentDev->DrawRect( Rectangle( Point(aEnd.X()-2,aStart.Y()), aEnd ) );
1079*cdf0e10cSrcweir 
1080*cdf0e10cSrcweir 				//	Seitenumbrueche
1081*cdf0e10cSrcweir 				//!	anders darstellen (gestrichelt ????)
1082*cdf0e10cSrcweir 
1083*cdf0e10cSrcweir 				size_t nColBreaks = rData.GetPagesX();
1084*cdf0e10cSrcweir 				const SCCOL* pColEnd = rData.GetPageEndX();
1085*cdf0e10cSrcweir 				size_t nColPos;
1086*cdf0e10cSrcweir 				for (nColPos=0; nColPos+1<nColBreaks; nColPos++)
1087*cdf0e10cSrcweir 				{
1088*cdf0e10cSrcweir 					SCCOL nBreak = pColEnd[nColPos]+1;
1089*cdf0e10cSrcweir 					if ( nBreak >= nX1 && nBreak <= nX2+1 )
1090*cdf0e10cSrcweir 					{
1091*cdf0e10cSrcweir 						//! hidden suchen
1092*cdf0e10cSrcweir                         if (pDoc->HasColBreak(nBreak, nTab) & BREAK_MANUAL)
1093*cdf0e10cSrcweir 							pContentDev->SetFillColor( aManual );
1094*cdf0e10cSrcweir 						else
1095*cdf0e10cSrcweir 							pContentDev->SetFillColor( aAutomatic );
1096*cdf0e10cSrcweir 						Point aBreak = pViewData->GetScrPos(
1097*cdf0e10cSrcweir 										nBreak, aRange.aStart.Row(), eWhich, sal_True );
1098*cdf0e10cSrcweir 						pContentDev->DrawRect( Rectangle( aBreak.X()-1, aStart.Y(), aBreak.X(), aEnd.Y() ) );
1099*cdf0e10cSrcweir 					}
1100*cdf0e10cSrcweir 				}
1101*cdf0e10cSrcweir 
1102*cdf0e10cSrcweir 				size_t nRowBreaks = rData.GetPagesY();
1103*cdf0e10cSrcweir 				const SCROW* pRowEnd = rData.GetPageEndY();
1104*cdf0e10cSrcweir 				size_t nRowPos;
1105*cdf0e10cSrcweir 				for (nRowPos=0; nRowPos+1<nRowBreaks; nRowPos++)
1106*cdf0e10cSrcweir 				{
1107*cdf0e10cSrcweir 					SCROW nBreak = pRowEnd[nRowPos]+1;
1108*cdf0e10cSrcweir 					if ( nBreak >= nY1 && nBreak <= nY2+1 )
1109*cdf0e10cSrcweir 					{
1110*cdf0e10cSrcweir 						//! hidden suchen
1111*cdf0e10cSrcweir                         if (pDoc->HasRowBreak(nBreak, nTab) & BREAK_MANUAL)
1112*cdf0e10cSrcweir 							pContentDev->SetFillColor( aManual );
1113*cdf0e10cSrcweir 						else
1114*cdf0e10cSrcweir 							pContentDev->SetFillColor( aAutomatic );
1115*cdf0e10cSrcweir 						Point aBreak = pViewData->GetScrPos(
1116*cdf0e10cSrcweir 										aRange.aStart.Col(), nBreak, eWhich, sal_True );
1117*cdf0e10cSrcweir 						pContentDev->DrawRect( Rectangle( aStart.X(), aBreak.Y()-1, aEnd.X(), aBreak.Y() ) );
1118*cdf0e10cSrcweir 					}
1119*cdf0e10cSrcweir 				}
1120*cdf0e10cSrcweir 
1121*cdf0e10cSrcweir 				//	Seitenzahlen
1122*cdf0e10cSrcweir 
1123*cdf0e10cSrcweir 				SCROW nPrStartY = aRange.aStart.Row();
1124*cdf0e10cSrcweir 				for (nRowPos=0; nRowPos<nRowBreaks; nRowPos++)
1125*cdf0e10cSrcweir 				{
1126*cdf0e10cSrcweir 					SCROW nPrEndY = pRowEnd[nRowPos];
1127*cdf0e10cSrcweir 					if ( nPrEndY >= nY1 && nPrStartY <= nY2 )
1128*cdf0e10cSrcweir 					{
1129*cdf0e10cSrcweir 						SCCOL nPrStartX = aRange.aStart.Col();
1130*cdf0e10cSrcweir 						for (nColPos=0; nColPos<nColBreaks; nColPos++)
1131*cdf0e10cSrcweir 						{
1132*cdf0e10cSrcweir 							SCCOL nPrEndX = pColEnd[nColPos];
1133*cdf0e10cSrcweir 							if ( nPrEndX >= nX1 && nPrStartX <= nX2 )
1134*cdf0e10cSrcweir 							{
1135*cdf0e10cSrcweir 								Point aPageStart = pViewData->GetScrPos(
1136*cdf0e10cSrcweir 														nPrStartX, nPrStartY, eWhich, sal_True );
1137*cdf0e10cSrcweir 								Point aPageEnd = pViewData->GetScrPos(
1138*cdf0e10cSrcweir 														nPrEndX+1,nPrEndY+1, eWhich, sal_True );
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir 								long nPageNo = rData.GetFirstPage();
1141*cdf0e10cSrcweir 								if ( rData.IsTopDown() )
1142*cdf0e10cSrcweir 									nPageNo += ((long)nColPos)*nRowBreaks+nRowPos;
1143*cdf0e10cSrcweir 								else
1144*cdf0e10cSrcweir 									nPageNo += ((long)nRowPos)*nColBreaks+nColPos;
1145*cdf0e10cSrcweir 								String aPageStr = aPageText;
1146*cdf0e10cSrcweir 								aPageStr += String::CreateFromInt32(nPageNo);
1147*cdf0e10cSrcweir 
1148*cdf0e10cSrcweir 								if ( pEditEng )
1149*cdf0e10cSrcweir 								{
1150*cdf0e10cSrcweir 									//	find right font size with EditEngine
1151*cdf0e10cSrcweir 									long nHeight = 100;
1152*cdf0e10cSrcweir 									pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT ) );
1153*cdf0e10cSrcweir 									pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CJK ) );
1154*cdf0e10cSrcweir 									pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CTL ) );
1155*cdf0e10cSrcweir 									pEditEng->SetText( aPageStr );
1156*cdf0e10cSrcweir 									Size aSize100( pEditEng->CalcTextWidth(), pEditEng->GetTextHeight() );
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir 									//	40% of width or 60% of height
1159*cdf0e10cSrcweir 									long nSizeX = 40 * ( aPageEnd.X() - aPageStart.X() ) / aSize100.Width();
1160*cdf0e10cSrcweir 									long nSizeY = 60 * ( aPageEnd.Y() - aPageStart.Y() ) / aSize100.Height();
1161*cdf0e10cSrcweir 									nHeight = Min(nSizeX,nSizeY);
1162*cdf0e10cSrcweir 									pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT ) );
1163*cdf0e10cSrcweir 									pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CJK ) );
1164*cdf0e10cSrcweir 									pEditEng->SetDefaultItem( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CTL ) );
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir 									//	centered output with EditEngine
1167*cdf0e10cSrcweir 									Size aTextSize( pEditEng->CalcTextWidth(), pEditEng->GetTextHeight() );
1168*cdf0e10cSrcweir 									Point aPos( (aPageStart.X()+aPageEnd.X()-aTextSize.Width())/2,
1169*cdf0e10cSrcweir 												(aPageStart.Y()+aPageEnd.Y()-aTextSize.Height())/2 );
1170*cdf0e10cSrcweir 									pEditEng->Draw( pContentDev, aPos );
1171*cdf0e10cSrcweir 								}
1172*cdf0e10cSrcweir 								else
1173*cdf0e10cSrcweir 								{
1174*cdf0e10cSrcweir 									//	find right font size for DrawText
1175*cdf0e10cSrcweir 									aFont.SetSize( Size( 0,100 ) );
1176*cdf0e10cSrcweir 									pContentDev->SetFont( aFont );
1177*cdf0e10cSrcweir 									Size aSize100( pContentDev->GetTextWidth( aPageStr ), pContentDev->GetTextHeight() );
1178*cdf0e10cSrcweir 
1179*cdf0e10cSrcweir 									//	40% of width or 60% of height
1180*cdf0e10cSrcweir 									long nSizeX = 40 * ( aPageEnd.X() - aPageStart.X() ) / aSize100.Width();
1181*cdf0e10cSrcweir 									long nSizeY = 60 * ( aPageEnd.Y() - aPageStart.Y() ) / aSize100.Height();
1182*cdf0e10cSrcweir 									aFont.SetSize( Size( 0,Min(nSizeX,nSizeY) ) );
1183*cdf0e10cSrcweir 									pContentDev->SetFont( aFont );
1184*cdf0e10cSrcweir 
1185*cdf0e10cSrcweir 									//	centered output with DrawText
1186*cdf0e10cSrcweir 									Size aTextSize( pContentDev->GetTextWidth( aPageStr ), pContentDev->GetTextHeight() );
1187*cdf0e10cSrcweir 									Point aPos( (aPageStart.X()+aPageEnd.X()-aTextSize.Width())/2,
1188*cdf0e10cSrcweir 												(aPageStart.Y()+aPageEnd.Y()-aTextSize.Height())/2 );
1189*cdf0e10cSrcweir 									pContentDev->DrawText( aPos, aPageStr );
1190*cdf0e10cSrcweir 								}
1191*cdf0e10cSrcweir 							}
1192*cdf0e10cSrcweir 							nPrStartX = nPrEndX + 1;
1193*cdf0e10cSrcweir 						}
1194*cdf0e10cSrcweir 					}
1195*cdf0e10cSrcweir 					nPrStartY = nPrEndY + 1;
1196*cdf0e10cSrcweir 				}
1197*cdf0e10cSrcweir 			}
1198*cdf0e10cSrcweir 		}
1199*cdf0e10cSrcweir 
1200*cdf0e10cSrcweir 		delete pEditEng;
1201*cdf0e10cSrcweir 	}
1202*cdf0e10cSrcweir }
1203*cdf0e10cSrcweir 
1204*cdf0e10cSrcweir void ScGridWindow::DrawButtons( SCCOL nX1, SCROW /*nY1*/, SCCOL nX2, SCROW /*nY2*/, ScTableInfo& rTabInfo, OutputDevice* pContentDev )
1205*cdf0e10cSrcweir {
1206*cdf0e10cSrcweir     aComboButton.SetOutputDevice( pContentDev );
1207*cdf0e10cSrcweir 
1208*cdf0e10cSrcweir     ScDocument* pDoc = pViewData->GetDocument();
1209*cdf0e10cSrcweir     ScDPFieldButton aCellBtn(pContentDev, &GetSettings().GetStyleSettings(), &pViewData->GetZoomX(), &pViewData->GetZoomY(), pDoc);
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir 	SCCOL nCol;
1212*cdf0e10cSrcweir 	SCROW nRow;
1213*cdf0e10cSrcweir 	SCSIZE nArrY;
1214*cdf0e10cSrcweir 	SCSIZE nQuery;
1215*cdf0e10cSrcweir 	SCTAB			nTab = pViewData->GetTabNo();
1216*cdf0e10cSrcweir 	ScDBData*		pDBData = NULL;
1217*cdf0e10cSrcweir 	ScQueryParam*	pQueryParam = NULL;
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir     RowInfo*        pRowInfo = rTabInfo.mpRowInfo;
1220*cdf0e10cSrcweir     sal_uInt16          nArrCount = rTabInfo.mnArrCount;
1221*cdf0e10cSrcweir 
1222*cdf0e10cSrcweir 	sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
1223*cdf0e10cSrcweir 
1224*cdf0e10cSrcweir 	Point aOldPos  = aComboButton.GetPosPixel();	// Zustand fuer MouseDown/Up
1225*cdf0e10cSrcweir 	Size  aOldSize = aComboButton.GetSizePixel();   // merken
1226*cdf0e10cSrcweir 
1227*cdf0e10cSrcweir 	for (nArrY=1; nArrY+1<nArrCount; nArrY++)
1228*cdf0e10cSrcweir 	{
1229*cdf0e10cSrcweir 		if ( pRowInfo[nArrY].bAutoFilter && pRowInfo[nArrY].bChanged )
1230*cdf0e10cSrcweir 		{
1231*cdf0e10cSrcweir 			RowInfo* pThisRowInfo = &pRowInfo[nArrY];
1232*cdf0e10cSrcweir 
1233*cdf0e10cSrcweir 			nRow = pThisRowInfo->nRowNo;
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir 
1236*cdf0e10cSrcweir 			for (nCol=nX1; nCol<=nX2; nCol++)
1237*cdf0e10cSrcweir 			{
1238*cdf0e10cSrcweir 				CellInfo* pInfo = &pThisRowInfo->pCellInfo[nCol+1];
1239*cdf0e10cSrcweir 				if ( pInfo->bAutoFilter && !pInfo->bHOverlapped && !pInfo->bVOverlapped )
1240*cdf0e10cSrcweir 				{
1241*cdf0e10cSrcweir 					if (!pQueryParam)
1242*cdf0e10cSrcweir 						pQueryParam = new ScQueryParam;
1243*cdf0e10cSrcweir 
1244*cdf0e10cSrcweir 					sal_Bool bNewData = sal_True;
1245*cdf0e10cSrcweir 					if (pDBData)
1246*cdf0e10cSrcweir 					{
1247*cdf0e10cSrcweir 						SCCOL nStartCol;
1248*cdf0e10cSrcweir 						SCROW nStartRow;
1249*cdf0e10cSrcweir 						SCCOL nEndCol;
1250*cdf0e10cSrcweir 						SCROW nEndRow;
1251*cdf0e10cSrcweir 						SCTAB nAreaTab;
1252*cdf0e10cSrcweir 						pDBData->GetArea( nAreaTab, nStartCol, nStartRow, nEndCol, nEndRow );
1253*cdf0e10cSrcweir 						if ( nCol >= nStartCol && nCol <= nEndCol &&
1254*cdf0e10cSrcweir 							 nRow >= nStartRow && nRow <= nEndRow )
1255*cdf0e10cSrcweir 							bNewData = sal_False;
1256*cdf0e10cSrcweir 					}
1257*cdf0e10cSrcweir 					if (bNewData)
1258*cdf0e10cSrcweir 					{
1259*cdf0e10cSrcweir 						pDBData = pDoc->GetDBAtCursor( nCol, nRow, nTab );
1260*cdf0e10cSrcweir 						if (pDBData)
1261*cdf0e10cSrcweir 							pDBData->GetQueryParam( *pQueryParam );
1262*cdf0e10cSrcweir 						else
1263*cdf0e10cSrcweir 						{
1264*cdf0e10cSrcweir 							// can also be part of DataPilot table
1265*cdf0e10cSrcweir 							// DBG_ERROR("Auto-Filter-Button ohne DBData");
1266*cdf0e10cSrcweir 						}
1267*cdf0e10cSrcweir 					}
1268*cdf0e10cSrcweir 
1269*cdf0e10cSrcweir 					//	pQueryParam kann nur MAXQUERY Eintraege enthalten
1270*cdf0e10cSrcweir 
1271*cdf0e10cSrcweir 					sal_Bool bSimpleQuery = sal_True;
1272*cdf0e10cSrcweir 					sal_Bool bColumnFound = sal_False;
1273*cdf0e10cSrcweir 					if (!pQueryParam->bInplace)
1274*cdf0e10cSrcweir 						bSimpleQuery = sal_False;
1275*cdf0e10cSrcweir 					for (nQuery=0; nQuery<MAXQUERY && bSimpleQuery; nQuery++)
1276*cdf0e10cSrcweir 						if (pQueryParam->GetEntry(nQuery).bDoQuery)
1277*cdf0e10cSrcweir 						{
1278*cdf0e10cSrcweir 							//	hier nicht auf EQUAL beschraenken
1279*cdf0e10cSrcweir 							//	(auch bei ">1" soll der Spaltenkopf blau werden)
1280*cdf0e10cSrcweir 
1281*cdf0e10cSrcweir 							if (pQueryParam->GetEntry(nQuery).nField == nCol)
1282*cdf0e10cSrcweir 								bColumnFound = sal_True;
1283*cdf0e10cSrcweir 							if (nQuery > 0)
1284*cdf0e10cSrcweir 								if (pQueryParam->GetEntry(nQuery).eConnect != SC_AND)
1285*cdf0e10cSrcweir 									bSimpleQuery = sal_False;
1286*cdf0e10cSrcweir 						}
1287*cdf0e10cSrcweir 
1288*cdf0e10cSrcweir                     bool bArrowState = bSimpleQuery && bColumnFound;
1289*cdf0e10cSrcweir 					long	nSizeX;
1290*cdf0e10cSrcweir 					long	nSizeY;
1291*cdf0e10cSrcweir 					pViewData->GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
1292*cdf0e10cSrcweir 					Point aScrPos = pViewData->GetScrPos( nCol, nRow, eWhich );
1293*cdf0e10cSrcweir 
1294*cdf0e10cSrcweir                     aCellBtn.setBoundingBox(aScrPos, Size(nSizeX-1, nSizeY-1), bLayoutRTL);
1295*cdf0e10cSrcweir                     aCellBtn.setPopupLeft(bLayoutRTL);   // #i114944# AutoFilter button is left-aligned in RTL
1296*cdf0e10cSrcweir                     aCellBtn.setDrawBaseButton(false);
1297*cdf0e10cSrcweir                     aCellBtn.setDrawPopupButton(true);
1298*cdf0e10cSrcweir                     aCellBtn.setHasHiddenMember(bArrowState);
1299*cdf0e10cSrcweir                     aCellBtn.draw();
1300*cdf0e10cSrcweir 				}
1301*cdf0e10cSrcweir 			}
1302*cdf0e10cSrcweir 		}
1303*cdf0e10cSrcweir 
1304*cdf0e10cSrcweir 		if ( pRowInfo[nArrY].bPushButton && pRowInfo[nArrY].bChanged )
1305*cdf0e10cSrcweir 		{
1306*cdf0e10cSrcweir 			RowInfo* pThisRowInfo = &pRowInfo[nArrY];
1307*cdf0e10cSrcweir 			nRow = pThisRowInfo->nRowNo;
1308*cdf0e10cSrcweir 			for (nCol=nX1; nCol<=nX2; nCol++)
1309*cdf0e10cSrcweir 			{
1310*cdf0e10cSrcweir 				CellInfo* pInfo = &pThisRowInfo->pCellInfo[nCol+1];
1311*cdf0e10cSrcweir 				if ( pInfo->bPushButton && !pInfo->bHOverlapped && !pInfo->bVOverlapped )
1312*cdf0e10cSrcweir 				{
1313*cdf0e10cSrcweir 					Point aScrPos = pViewData->GetScrPos( nCol, nRow, eWhich );
1314*cdf0e10cSrcweir 					long nSizeX;
1315*cdf0e10cSrcweir 					long nSizeY;
1316*cdf0e10cSrcweir 					pViewData->GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
1317*cdf0e10cSrcweir 					long nPosX = aScrPos.X();
1318*cdf0e10cSrcweir 					long nPosY = aScrPos.Y();
1319*cdf0e10cSrcweir 					// bLayoutRTL is handled in setBoundingBox
1320*cdf0e10cSrcweir 
1321*cdf0e10cSrcweir                     String aStr;
1322*cdf0e10cSrcweir                     pDoc->GetString(nCol, nRow, nTab, aStr);
1323*cdf0e10cSrcweir                     aCellBtn.setText(aStr);
1324*cdf0e10cSrcweir                     aCellBtn.setBoundingBox(Point(nPosX, nPosY), Size(nSizeX-1, nSizeY-1), bLayoutRTL);
1325*cdf0e10cSrcweir                     aCellBtn.setPopupLeft(false);   // DataPilot popup is always right-aligned for now
1326*cdf0e10cSrcweir                     aCellBtn.setDrawBaseButton(true);
1327*cdf0e10cSrcweir                     aCellBtn.setDrawPopupButton(pInfo->bPopupButton);
1328*cdf0e10cSrcweir                     aCellBtn.setHasHiddenMember(pInfo->bFilterActive);
1329*cdf0e10cSrcweir                     aCellBtn.draw();
1330*cdf0e10cSrcweir 				}
1331*cdf0e10cSrcweir 			}
1332*cdf0e10cSrcweir 		}
1333*cdf0e10cSrcweir 
1334*cdf0e10cSrcweir         if ( bListValButton && pRowInfo[nArrY].nRowNo == aListValPos.Row() && pRowInfo[nArrY].bChanged )
1335*cdf0e10cSrcweir         {
1336*cdf0e10cSrcweir             Rectangle aRect = GetListValButtonRect( aListValPos );
1337*cdf0e10cSrcweir             aComboButton.SetPosPixel( aRect.TopLeft() );
1338*cdf0e10cSrcweir             aComboButton.SetSizePixel( aRect.GetSize() );
1339*cdf0e10cSrcweir             pContentDev->SetClipRegion( aRect );
1340*cdf0e10cSrcweir             aComboButton.Draw( sal_False, sal_False );
1341*cdf0e10cSrcweir             pContentDev->SetClipRegion();           // always called from Draw() without clip region
1342*cdf0e10cSrcweir             aComboButton.SetPosPixel( aOldPos );    // restore old state
1343*cdf0e10cSrcweir             aComboButton.SetSizePixel( aOldSize );  // for MouseUp/Down (AutoFilter)
1344*cdf0e10cSrcweir         }
1345*cdf0e10cSrcweir 	}
1346*cdf0e10cSrcweir 
1347*cdf0e10cSrcweir 	delete pQueryParam;
1348*cdf0e10cSrcweir     aComboButton.SetOutputDevice( this );
1349*cdf0e10cSrcweir }
1350*cdf0e10cSrcweir 
1351*cdf0e10cSrcweir Rectangle ScGridWindow::GetListValButtonRect( const ScAddress& rButtonPos )
1352*cdf0e10cSrcweir {
1353*cdf0e10cSrcweir     ScDocument* pDoc = pViewData->GetDocument();
1354*cdf0e10cSrcweir     SCTAB nTab = pViewData->GetTabNo();
1355*cdf0e10cSrcweir     sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
1356*cdf0e10cSrcweir     long nLayoutSign = bLayoutRTL ? -1 : 1;
1357*cdf0e10cSrcweir 
1358*cdf0e10cSrcweir     ScDDComboBoxButton aButton( this );             // for optimal size
1359*cdf0e10cSrcweir     Size aBtnSize = aButton.GetSizePixel();
1360*cdf0e10cSrcweir 
1361*cdf0e10cSrcweir     SCCOL nCol = rButtonPos.Col();
1362*cdf0e10cSrcweir     SCROW nRow = rButtonPos.Row();
1363*cdf0e10cSrcweir 
1364*cdf0e10cSrcweir     long nCellSizeX;    // width of this cell, including merged
1365*cdf0e10cSrcweir     long nDummy;
1366*cdf0e10cSrcweir     pViewData->GetMergeSizePixel( nCol, nRow, nCellSizeX, nDummy );
1367*cdf0e10cSrcweir 
1368*cdf0e10cSrcweir     // for height, only the cell's row is used, excluding merged cells
1369*cdf0e10cSrcweir     long nCellSizeY = ScViewData::ToPixel( pDoc->GetRowHeight( nRow, nTab ), pViewData->GetPPTY() );
1370*cdf0e10cSrcweir     long nAvailable = nCellSizeX;
1371*cdf0e10cSrcweir 
1372*cdf0e10cSrcweir     //  left edge of next cell if there is a non-hidden next column
1373*cdf0e10cSrcweir     SCCOL nNextCol = nCol + 1;
1374*cdf0e10cSrcweir     const ScMergeAttr* pMerge = static_cast<const ScMergeAttr*>(pDoc->GetAttr( nCol,nRow,nTab, ATTR_MERGE ));
1375*cdf0e10cSrcweir     if ( pMerge->GetColMerge() > 1 )
1376*cdf0e10cSrcweir         nNextCol = nCol + pMerge->GetColMerge();    // next cell after the merged area
1377*cdf0e10cSrcweir     while ( nNextCol <= MAXCOL && pDoc->ColHidden(nNextCol, nTab) )
1378*cdf0e10cSrcweir         ++nNextCol;
1379*cdf0e10cSrcweir     sal_Bool bNextCell = ( nNextCol <= MAXCOL );
1380*cdf0e10cSrcweir     if ( bNextCell )
1381*cdf0e10cSrcweir         nAvailable = ScViewData::ToPixel( pDoc->GetColWidth( nNextCol, nTab ), pViewData->GetPPTX() );
1382*cdf0e10cSrcweir 
1383*cdf0e10cSrcweir     if ( nAvailable < aBtnSize.Width() )
1384*cdf0e10cSrcweir         aBtnSize.Width() = nAvailable;
1385*cdf0e10cSrcweir     if ( nCellSizeY < aBtnSize.Height() )
1386*cdf0e10cSrcweir         aBtnSize.Height() = nCellSizeY;
1387*cdf0e10cSrcweir 
1388*cdf0e10cSrcweir     Point aPos = pViewData->GetScrPos( nCol, nRow, eWhich, sal_True );
1389*cdf0e10cSrcweir     aPos.X() += nCellSizeX * nLayoutSign;               // start of next cell
1390*cdf0e10cSrcweir     if (!bNextCell)
1391*cdf0e10cSrcweir         aPos.X() -= aBtnSize.Width() * nLayoutSign;     // right edge of cell if next cell not available
1392*cdf0e10cSrcweir     aPos.Y() += nCellSizeY - aBtnSize.Height();
1393*cdf0e10cSrcweir     // X remains at the left edge
1394*cdf0e10cSrcweir 
1395*cdf0e10cSrcweir     if ( bLayoutRTL )
1396*cdf0e10cSrcweir         aPos.X() -= aBtnSize.Width()-1;     // align right edge of button with cell border
1397*cdf0e10cSrcweir 
1398*cdf0e10cSrcweir     return Rectangle( aPos, aBtnSize );
1399*cdf0e10cSrcweir }
1400*cdf0e10cSrcweir 
1401*cdf0e10cSrcweir sal_Bool ScGridWindow::IsAutoFilterActive( SCCOL nCol, SCROW nRow, SCTAB nTab )
1402*cdf0e10cSrcweir {
1403*cdf0e10cSrcweir 	ScDocument*		pDoc	= pViewData->GetDocument();
1404*cdf0e10cSrcweir 	ScDBData*		pDBData = pDoc->GetDBAtCursor( nCol, nRow, nTab );
1405*cdf0e10cSrcweir 	ScQueryParam	aQueryParam;
1406*cdf0e10cSrcweir 
1407*cdf0e10cSrcweir 	if ( pDBData )
1408*cdf0e10cSrcweir 		pDBData->GetQueryParam( aQueryParam );
1409*cdf0e10cSrcweir 	else
1410*cdf0e10cSrcweir 	{
1411*cdf0e10cSrcweir 		DBG_ERROR("Auto-Filter-Button ohne DBData");
1412*cdf0e10cSrcweir 	}
1413*cdf0e10cSrcweir 
1414*cdf0e10cSrcweir 	sal_Bool	bSimpleQuery = sal_True;
1415*cdf0e10cSrcweir 	sal_Bool	bColumnFound = sal_False;
1416*cdf0e10cSrcweir 	SCSIZE	nQuery;
1417*cdf0e10cSrcweir 
1418*cdf0e10cSrcweir 	if ( !aQueryParam.bInplace )
1419*cdf0e10cSrcweir 		bSimpleQuery = sal_False;
1420*cdf0e10cSrcweir 
1421*cdf0e10cSrcweir 	//	aQueryParam kann nur MAXQUERY Eintraege enthalten
1422*cdf0e10cSrcweir 
1423*cdf0e10cSrcweir 	for ( nQuery=0; nQuery<MAXQUERY && bSimpleQuery; nQuery++ )
1424*cdf0e10cSrcweir 		if ( aQueryParam.GetEntry(nQuery).bDoQuery )
1425*cdf0e10cSrcweir 		{
1426*cdf0e10cSrcweir 			if (aQueryParam.GetEntry(nQuery).nField == nCol)
1427*cdf0e10cSrcweir 				bColumnFound = sal_True;
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir 			if (nQuery > 0)
1430*cdf0e10cSrcweir 				if (aQueryParam.GetEntry(nQuery).eConnect != SC_AND)
1431*cdf0e10cSrcweir 					bSimpleQuery = sal_False;
1432*cdf0e10cSrcweir 		}
1433*cdf0e10cSrcweir 
1434*cdf0e10cSrcweir 	return ( bSimpleQuery && bColumnFound );
1435*cdf0e10cSrcweir }
1436*cdf0e10cSrcweir 
1437*cdf0e10cSrcweir void ScGridWindow::DrawComboButton( const Point&	rCellPos,
1438*cdf0e10cSrcweir 									long			nCellSizeX,
1439*cdf0e10cSrcweir 									long			nCellSizeY,
1440*cdf0e10cSrcweir                                     sal_Bool            bArrowState,
1441*cdf0e10cSrcweir 									sal_Bool			bBtnIn )
1442*cdf0e10cSrcweir {
1443*cdf0e10cSrcweir 	Point	aScrPos	 = rCellPos;
1444*cdf0e10cSrcweir 	Size	aBtnSize = aComboButton.GetSizePixel();
1445*cdf0e10cSrcweir 
1446*cdf0e10cSrcweir 	if ( nCellSizeX < aBtnSize.Width() || nCellSizeY < aBtnSize.Height() )
1447*cdf0e10cSrcweir 	{
1448*cdf0e10cSrcweir 		if ( nCellSizeX < aBtnSize.Width() )
1449*cdf0e10cSrcweir 			aBtnSize.Width() = nCellSizeX;
1450*cdf0e10cSrcweir 
1451*cdf0e10cSrcweir 		if ( nCellSizeY < aBtnSize.Height() )
1452*cdf0e10cSrcweir 			aBtnSize.Height() = nCellSizeY;
1453*cdf0e10cSrcweir 
1454*cdf0e10cSrcweir 		aComboButton.SetSizePixel( aBtnSize );
1455*cdf0e10cSrcweir 	}
1456*cdf0e10cSrcweir 
1457*cdf0e10cSrcweir 	sal_Bool bLayoutRTL = pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
1458*cdf0e10cSrcweir 
1459*cdf0e10cSrcweir 	if ( bLayoutRTL )
1460*cdf0e10cSrcweir 		aScrPos.X() -= nCellSizeX - 1;
1461*cdf0e10cSrcweir 	else
1462*cdf0e10cSrcweir 		aScrPos.X() += nCellSizeX - aBtnSize.Width();
1463*cdf0e10cSrcweir 	aScrPos.Y() += nCellSizeY - aBtnSize.Height();
1464*cdf0e10cSrcweir 
1465*cdf0e10cSrcweir 	aComboButton.SetPosPixel( aScrPos );
1466*cdf0e10cSrcweir 
1467*cdf0e10cSrcweir 	HideCursor();
1468*cdf0e10cSrcweir     aComboButton.Draw( bArrowState, bBtnIn );
1469*cdf0e10cSrcweir 	ShowCursor();
1470*cdf0e10cSrcweir }
1471*cdf0e10cSrcweir 
1472*cdf0e10cSrcweir void ScGridWindow::InvertSimple( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
1473*cdf0e10cSrcweir 									sal_Bool bTestMerge, sal_Bool bRepeat )
1474*cdf0e10cSrcweir {
1475*cdf0e10cSrcweir 	//!	if INVERT_HIGHLIGHT swaps foreground and background (like on Mac),
1476*cdf0e10cSrcweir 	//!	use INVERT_HIGHLIGHT only for cells that have no background color set
1477*cdf0e10cSrcweir 	//!	(here and in ScOutputData::DrawMark)
1478*cdf0e10cSrcweir 
1479*cdf0e10cSrcweir 	PutInOrder( nX1, nX2 );
1480*cdf0e10cSrcweir 	PutInOrder( nY1, nY2 );
1481*cdf0e10cSrcweir 
1482*cdf0e10cSrcweir 	ScMarkData& rMark = pViewData->GetMarkData();
1483*cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
1484*cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
1485*cdf0e10cSrcweir 
1486*cdf0e10cSrcweir 	sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
1487*cdf0e10cSrcweir 	long nLayoutSign = bLayoutRTL ? -1 : 1;
1488*cdf0e10cSrcweir 
1489*cdf0e10cSrcweir 	SCCOL nTestX2 = nX2;
1490*cdf0e10cSrcweir 	SCROW nTestY2 = nY2;
1491*cdf0e10cSrcweir 	if (bTestMerge)
1492*cdf0e10cSrcweir 		pDoc->ExtendMerge( nX1,nY1, nTestX2,nTestY2, nTab );
1493*cdf0e10cSrcweir 
1494*cdf0e10cSrcweir 	SCCOL nPosX = pViewData->GetPosX( eHWhich );
1495*cdf0e10cSrcweir 	SCROW nPosY = pViewData->GetPosY( eVWhich );
1496*cdf0e10cSrcweir 	if (nTestX2 < nPosX || nTestY2 < nPosY)
1497*cdf0e10cSrcweir 		return;											// unsichtbar
1498*cdf0e10cSrcweir 	SCCOL nRealX1 = nX1;
1499*cdf0e10cSrcweir 	if (nX1 < nPosX)
1500*cdf0e10cSrcweir 		nX1 = nPosX;
1501*cdf0e10cSrcweir 	if (nY1 < nPosY)
1502*cdf0e10cSrcweir 		nY1 = nPosY;
1503*cdf0e10cSrcweir 
1504*cdf0e10cSrcweir 	SCCOL nXRight = nPosX + pViewData->VisibleCellsX(eHWhich);
1505*cdf0e10cSrcweir 	if (nXRight > MAXCOL) nXRight = MAXCOL;
1506*cdf0e10cSrcweir 	SCROW nYBottom = nPosY + pViewData->VisibleCellsY(eVWhich);
1507*cdf0e10cSrcweir 	if (nYBottom > MAXROW) nYBottom = MAXROW;
1508*cdf0e10cSrcweir 
1509*cdf0e10cSrcweir 	if (nX1 > nXRight || nY1 > nYBottom)
1510*cdf0e10cSrcweir 		return;											// unsichtbar
1511*cdf0e10cSrcweir 	if (nX2 > nXRight) nX2 = nXRight;
1512*cdf0e10cSrcweir 	if (nY2 > nYBottom) nY2 = nYBottom;
1513*cdf0e10cSrcweir 
1514*cdf0e10cSrcweir 	MapMode aOld = GetMapMode(); SetMapMode(MAP_PIXEL);		// erst nach den return's !!!
1515*cdf0e10cSrcweir 
1516*cdf0e10cSrcweir 	double nPPTX = pViewData->GetPPTX();
1517*cdf0e10cSrcweir 	double nPPTY = pViewData->GetPPTY();
1518*cdf0e10cSrcweir 
1519*cdf0e10cSrcweir 	ScInvertMerger aInvert( this );
1520*cdf0e10cSrcweir 
1521*cdf0e10cSrcweir 	Point aScrPos = pViewData->GetScrPos( nX1, nY1, eWhich );
1522*cdf0e10cSrcweir 	long nScrY = aScrPos.Y();
1523*cdf0e10cSrcweir 	sal_Bool bWasHidden = sal_False;
1524*cdf0e10cSrcweir 	for (SCROW nY=nY1; nY<=nY2; nY++)
1525*cdf0e10cSrcweir 	{
1526*cdf0e10cSrcweir 		sal_Bool bFirstRow = ( nY == nPosY );						// first visible row?
1527*cdf0e10cSrcweir 		sal_Bool bDoHidden = sal_False;									// versteckte nachholen ?
1528*cdf0e10cSrcweir 		sal_uInt16 nHeightTwips = pDoc->GetRowHeight( nY,nTab );
1529*cdf0e10cSrcweir 		sal_Bool bDoRow = ( nHeightTwips != 0 );
1530*cdf0e10cSrcweir 		if (bDoRow)
1531*cdf0e10cSrcweir 		{
1532*cdf0e10cSrcweir 			if (bTestMerge)
1533*cdf0e10cSrcweir 				if (bWasHidden)					// auf versteckte zusammengefasste testen
1534*cdf0e10cSrcweir 				{
1535*cdf0e10cSrcweir //					--nY;						// nY geaendert -> vorherige zeichnen
1536*cdf0e10cSrcweir 					bDoHidden = sal_True;
1537*cdf0e10cSrcweir 					bDoRow = sal_True;
1538*cdf0e10cSrcweir 				}
1539*cdf0e10cSrcweir 
1540*cdf0e10cSrcweir 			bWasHidden = sal_False;
1541*cdf0e10cSrcweir 		}
1542*cdf0e10cSrcweir 		else
1543*cdf0e10cSrcweir 		{
1544*cdf0e10cSrcweir 			bWasHidden = sal_True;
1545*cdf0e10cSrcweir 			if (bTestMerge)
1546*cdf0e10cSrcweir 				if (nY==nY2)
1547*cdf0e10cSrcweir 					bDoRow = sal_True;				// letzte Zeile aus Block
1548*cdf0e10cSrcweir 		}
1549*cdf0e10cSrcweir 
1550*cdf0e10cSrcweir 		if ( bDoRow )
1551*cdf0e10cSrcweir 		{
1552*cdf0e10cSrcweir 			SCCOL nLoopEndX = nX2;
1553*cdf0e10cSrcweir 			if (nX2 < nX1)						// Rest von zusammengefasst
1554*cdf0e10cSrcweir 			{
1555*cdf0e10cSrcweir 				SCCOL nStartX = nX1;
1556*cdf0e10cSrcweir 				while ( ((const ScMergeFlagAttr*)pDoc->
1557*cdf0e10cSrcweir 							GetAttr(nStartX,nY,nTab,ATTR_MERGE_FLAG))->IsHorOverlapped() )
1558*cdf0e10cSrcweir 					--nStartX;
1559*cdf0e10cSrcweir 				if (nStartX <= nX2)
1560*cdf0e10cSrcweir 					nLoopEndX = nX1;
1561*cdf0e10cSrcweir 			}
1562*cdf0e10cSrcweir 
1563*cdf0e10cSrcweir 			long nEndY = nScrY + ScViewData::ToPixel( nHeightTwips, nPPTY ) - 1;
1564*cdf0e10cSrcweir 			long nScrX = aScrPos.X();
1565*cdf0e10cSrcweir 			for (SCCOL nX=nX1; nX<=nLoopEndX; nX++)
1566*cdf0e10cSrcweir 			{
1567*cdf0e10cSrcweir 				long nWidth = ScViewData::ToPixel( pDoc->GetColWidth( nX,nTab ), nPPTX );
1568*cdf0e10cSrcweir 				if ( nWidth > 0 )
1569*cdf0e10cSrcweir 				{
1570*cdf0e10cSrcweir 					long nEndX = nScrX + ( nWidth - 1 ) * nLayoutSign;
1571*cdf0e10cSrcweir 					if (bTestMerge)
1572*cdf0e10cSrcweir 					{
1573*cdf0e10cSrcweir 						SCROW nThisY = nY;
1574*cdf0e10cSrcweir 						const ScPatternAttr* pPattern = pDoc->GetPattern( nX, nY, nTab );
1575*cdf0e10cSrcweir 						const ScMergeFlagAttr* pMergeFlag = (const ScMergeFlagAttr*) &pPattern->
1576*cdf0e10cSrcweir 																		GetItem(ATTR_MERGE_FLAG);
1577*cdf0e10cSrcweir 						if ( pMergeFlag->IsVerOverlapped() && ( bDoHidden || bFirstRow ) )
1578*cdf0e10cSrcweir 						{
1579*cdf0e10cSrcweir 							while ( pMergeFlag->IsVerOverlapped() && nThisY > 0 &&
1580*cdf0e10cSrcweir                                     (pDoc->RowHidden(nThisY-1, nTab) || bFirstRow) )
1581*cdf0e10cSrcweir 							{
1582*cdf0e10cSrcweir 								--nThisY;
1583*cdf0e10cSrcweir 								pPattern = pDoc->GetPattern( nX, nThisY, nTab );
1584*cdf0e10cSrcweir 								pMergeFlag = (const ScMergeFlagAttr*) &pPattern->GetItem(ATTR_MERGE_FLAG);
1585*cdf0e10cSrcweir 							}
1586*cdf0e10cSrcweir 						}
1587*cdf0e10cSrcweir 
1588*cdf0e10cSrcweir 						// nur Rest von zusammengefasster zu sehen ?
1589*cdf0e10cSrcweir 						SCCOL nThisX = nX;
1590*cdf0e10cSrcweir 						if ( pMergeFlag->IsHorOverlapped() && nX == nPosX && nX > nRealX1 )
1591*cdf0e10cSrcweir 						{
1592*cdf0e10cSrcweir 							while ( pMergeFlag->IsHorOverlapped() )
1593*cdf0e10cSrcweir 							{
1594*cdf0e10cSrcweir 								--nThisX;
1595*cdf0e10cSrcweir 								pPattern = pDoc->GetPattern( nThisX, nThisY, nTab );
1596*cdf0e10cSrcweir 								pMergeFlag = (const ScMergeFlagAttr*) &pPattern->GetItem(ATTR_MERGE_FLAG);
1597*cdf0e10cSrcweir 							}
1598*cdf0e10cSrcweir 						}
1599*cdf0e10cSrcweir 
1600*cdf0e10cSrcweir 						if ( rMark.IsCellMarked( nThisX, nThisY, sal_True ) == bRepeat )
1601*cdf0e10cSrcweir 						{
1602*cdf0e10cSrcweir 							if ( !pMergeFlag->IsOverlapped() )
1603*cdf0e10cSrcweir 							{
1604*cdf0e10cSrcweir 								ScMergeAttr* pMerge = (ScMergeAttr*)&pPattern->GetItem(ATTR_MERGE);
1605*cdf0e10cSrcweir 								if (pMerge->GetColMerge() > 0 || pMerge->GetRowMerge() > 0)
1606*cdf0e10cSrcweir 								{
1607*cdf0e10cSrcweir 									Point aEndPos = pViewData->GetScrPos(
1608*cdf0e10cSrcweir 											nThisX + pMerge->GetColMerge(),
1609*cdf0e10cSrcweir 											nThisY + pMerge->GetRowMerge(), eWhich );
1610*cdf0e10cSrcweir 									if ( aEndPos.X() * nLayoutSign > nScrX * nLayoutSign && aEndPos.Y() > nScrY )
1611*cdf0e10cSrcweir 									{
1612*cdf0e10cSrcweir 										aInvert.AddRect( Rectangle( nScrX,nScrY,
1613*cdf0e10cSrcweir 													aEndPos.X()-nLayoutSign,aEndPos.Y()-1 ) );
1614*cdf0e10cSrcweir 									}
1615*cdf0e10cSrcweir 								}
1616*cdf0e10cSrcweir 								else if ( nEndX * nLayoutSign >= nScrX * nLayoutSign && nEndY >= nScrY )
1617*cdf0e10cSrcweir 								{
1618*cdf0e10cSrcweir 									aInvert.AddRect( Rectangle( nScrX,nScrY,nEndX,nEndY ) );
1619*cdf0e10cSrcweir 								}
1620*cdf0e10cSrcweir 							}
1621*cdf0e10cSrcweir 						}
1622*cdf0e10cSrcweir 					}
1623*cdf0e10cSrcweir 					else		// !bTestMerge
1624*cdf0e10cSrcweir 					{
1625*cdf0e10cSrcweir 						if ( rMark.IsCellMarked( nX, nY, sal_True ) == bRepeat &&
1626*cdf0e10cSrcweir 												nEndX * nLayoutSign >= nScrX * nLayoutSign && nEndY >= nScrY )
1627*cdf0e10cSrcweir 						{
1628*cdf0e10cSrcweir 							aInvert.AddRect( Rectangle( nScrX,nScrY,nEndX,nEndY ) );
1629*cdf0e10cSrcweir 						}
1630*cdf0e10cSrcweir 					}
1631*cdf0e10cSrcweir 
1632*cdf0e10cSrcweir 					nScrX = nEndX + nLayoutSign;
1633*cdf0e10cSrcweir 				}
1634*cdf0e10cSrcweir 			}
1635*cdf0e10cSrcweir 			nScrY = nEndY + 1;
1636*cdf0e10cSrcweir 		}
1637*cdf0e10cSrcweir 	}
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir 	aInvert.Flush();		// before restoring MapMode
1640*cdf0e10cSrcweir 
1641*cdf0e10cSrcweir 	SetMapMode(aOld);
1642*cdf0e10cSrcweir 
1643*cdf0e10cSrcweir 	CheckInverted();
1644*cdf0e10cSrcweir }
1645*cdf0e10cSrcweir 
1646*cdf0e10cSrcweir void ScGridWindow::GetSelectionRects( ::std::vector< Rectangle >& rPixelRects )
1647*cdf0e10cSrcweir {
1648*cdf0e10cSrcweir     // transformed from ScGridWindow::InvertSimple
1649*cdf0e10cSrcweir 
1650*cdf0e10cSrcweir //  ScMarkData& rMark = pViewData->GetMarkData();
1651*cdf0e10cSrcweir     ScMarkData aMultiMark( pViewData->GetMarkData() );
1652*cdf0e10cSrcweir     aMultiMark.SetMarking( sal_False );
1653*cdf0e10cSrcweir     aMultiMark.MarkToMulti();
1654*cdf0e10cSrcweir 
1655*cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
1656*cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
1657*cdf0e10cSrcweir 
1658*cdf0e10cSrcweir 	sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
1659*cdf0e10cSrcweir 	long nLayoutSign = bLayoutRTL ? -1 : 1;
1660*cdf0e10cSrcweir 
1661*cdf0e10cSrcweir     if ( !aMultiMark.IsMultiMarked() )
1662*cdf0e10cSrcweir         return;
1663*cdf0e10cSrcweir 
1664*cdf0e10cSrcweir     ScRange aMultiRange;
1665*cdf0e10cSrcweir     aMultiMark.GetMultiMarkArea( aMultiRange );
1666*cdf0e10cSrcweir     SCCOL nX1 = aMultiRange.aStart.Col();
1667*cdf0e10cSrcweir     SCROW nY1 = aMultiRange.aStart.Row();
1668*cdf0e10cSrcweir     SCCOL nX2 = aMultiRange.aEnd.Col();
1669*cdf0e10cSrcweir     SCROW nY2 = aMultiRange.aEnd.Row();
1670*cdf0e10cSrcweir 
1671*cdf0e10cSrcweir 	PutInOrder( nX1, nX2 );
1672*cdf0e10cSrcweir 	PutInOrder( nY1, nY2 );
1673*cdf0e10cSrcweir 
1674*cdf0e10cSrcweir     sal_Bool bTestMerge = sal_True;
1675*cdf0e10cSrcweir     sal_Bool bRepeat = sal_True;
1676*cdf0e10cSrcweir 
1677*cdf0e10cSrcweir 	SCCOL nTestX2 = nX2;
1678*cdf0e10cSrcweir 	SCROW nTestY2 = nY2;
1679*cdf0e10cSrcweir 	if (bTestMerge)
1680*cdf0e10cSrcweir 		pDoc->ExtendMerge( nX1,nY1, nTestX2,nTestY2, nTab );
1681*cdf0e10cSrcweir 
1682*cdf0e10cSrcweir 	SCCOL nPosX = pViewData->GetPosX( eHWhich );
1683*cdf0e10cSrcweir 	SCROW nPosY = pViewData->GetPosY( eVWhich );
1684*cdf0e10cSrcweir 	if (nTestX2 < nPosX || nTestY2 < nPosY)
1685*cdf0e10cSrcweir 		return;											// unsichtbar
1686*cdf0e10cSrcweir 	SCCOL nRealX1 = nX1;
1687*cdf0e10cSrcweir 	if (nX1 < nPosX)
1688*cdf0e10cSrcweir 		nX1 = nPosX;
1689*cdf0e10cSrcweir 	if (nY1 < nPosY)
1690*cdf0e10cSrcweir 		nY1 = nPosY;
1691*cdf0e10cSrcweir 
1692*cdf0e10cSrcweir 	SCCOL nXRight = nPosX + pViewData->VisibleCellsX(eHWhich);
1693*cdf0e10cSrcweir 	if (nXRight > MAXCOL) nXRight = MAXCOL;
1694*cdf0e10cSrcweir 	SCROW nYBottom = nPosY + pViewData->VisibleCellsY(eVWhich);
1695*cdf0e10cSrcweir 	if (nYBottom > MAXROW) nYBottom = MAXROW;
1696*cdf0e10cSrcweir 
1697*cdf0e10cSrcweir 	if (nX1 > nXRight || nY1 > nYBottom)
1698*cdf0e10cSrcweir 		return;											// unsichtbar
1699*cdf0e10cSrcweir 	if (nX2 > nXRight) nX2 = nXRight;
1700*cdf0e10cSrcweir 	if (nY2 > nYBottom) nY2 = nYBottom;
1701*cdf0e10cSrcweir 
1702*cdf0e10cSrcweir //	MapMode aOld = GetMapMode(); SetMapMode(MAP_PIXEL);		// erst nach den return's !!!
1703*cdf0e10cSrcweir 
1704*cdf0e10cSrcweir 	double nPPTX = pViewData->GetPPTX();
1705*cdf0e10cSrcweir 	double nPPTY = pViewData->GetPPTY();
1706*cdf0e10cSrcweir 
1707*cdf0e10cSrcweir     ScInvertMerger aInvert( &rPixelRects );
1708*cdf0e10cSrcweir 
1709*cdf0e10cSrcweir 	Point aScrPos = pViewData->GetScrPos( nX1, nY1, eWhich );
1710*cdf0e10cSrcweir 	long nScrY = aScrPos.Y();
1711*cdf0e10cSrcweir 	sal_Bool bWasHidden = sal_False;
1712*cdf0e10cSrcweir 	for (SCROW nY=nY1; nY<=nY2; nY++)
1713*cdf0e10cSrcweir 	{
1714*cdf0e10cSrcweir 		sal_Bool bFirstRow = ( nY == nPosY );						// first visible row?
1715*cdf0e10cSrcweir 		sal_Bool bDoHidden = sal_False;									// versteckte nachholen ?
1716*cdf0e10cSrcweir 		sal_uInt16 nHeightTwips = pDoc->GetRowHeight( nY,nTab );
1717*cdf0e10cSrcweir 		sal_Bool bDoRow = ( nHeightTwips != 0 );
1718*cdf0e10cSrcweir 		if (bDoRow)
1719*cdf0e10cSrcweir 		{
1720*cdf0e10cSrcweir 			if (bTestMerge)
1721*cdf0e10cSrcweir 				if (bWasHidden)					// auf versteckte zusammengefasste testen
1722*cdf0e10cSrcweir 				{
1723*cdf0e10cSrcweir 					bDoHidden = sal_True;
1724*cdf0e10cSrcweir 					bDoRow = sal_True;
1725*cdf0e10cSrcweir 				}
1726*cdf0e10cSrcweir 
1727*cdf0e10cSrcweir 			bWasHidden = sal_False;
1728*cdf0e10cSrcweir 		}
1729*cdf0e10cSrcweir 		else
1730*cdf0e10cSrcweir 		{
1731*cdf0e10cSrcweir 			bWasHidden = sal_True;
1732*cdf0e10cSrcweir 			if (bTestMerge)
1733*cdf0e10cSrcweir 				if (nY==nY2)
1734*cdf0e10cSrcweir 					bDoRow = sal_True;				// letzte Zeile aus Block
1735*cdf0e10cSrcweir 		}
1736*cdf0e10cSrcweir 
1737*cdf0e10cSrcweir 		if ( bDoRow )
1738*cdf0e10cSrcweir 		{
1739*cdf0e10cSrcweir 			SCCOL nLoopEndX = nX2;
1740*cdf0e10cSrcweir 			if (nX2 < nX1)						// Rest von zusammengefasst
1741*cdf0e10cSrcweir 			{
1742*cdf0e10cSrcweir 				SCCOL nStartX = nX1;
1743*cdf0e10cSrcweir 				while ( ((const ScMergeFlagAttr*)pDoc->
1744*cdf0e10cSrcweir 							GetAttr(nStartX,nY,nTab,ATTR_MERGE_FLAG))->IsHorOverlapped() )
1745*cdf0e10cSrcweir 					--nStartX;
1746*cdf0e10cSrcweir 				if (nStartX <= nX2)
1747*cdf0e10cSrcweir 					nLoopEndX = nX1;
1748*cdf0e10cSrcweir 			}
1749*cdf0e10cSrcweir 
1750*cdf0e10cSrcweir 			long nEndY = nScrY + ScViewData::ToPixel( nHeightTwips, nPPTY ) - 1;
1751*cdf0e10cSrcweir 			long nScrX = aScrPos.X();
1752*cdf0e10cSrcweir 			for (SCCOL nX=nX1; nX<=nLoopEndX; nX++)
1753*cdf0e10cSrcweir 			{
1754*cdf0e10cSrcweir 				long nWidth = ScViewData::ToPixel( pDoc->GetColWidth( nX,nTab ), nPPTX );
1755*cdf0e10cSrcweir 				if ( nWidth > 0 )
1756*cdf0e10cSrcweir 				{
1757*cdf0e10cSrcweir 					long nEndX = nScrX + ( nWidth - 1 ) * nLayoutSign;
1758*cdf0e10cSrcweir 					if (bTestMerge)
1759*cdf0e10cSrcweir 					{
1760*cdf0e10cSrcweir 						SCROW nThisY = nY;
1761*cdf0e10cSrcweir 						const ScPatternAttr* pPattern = pDoc->GetPattern( nX, nY, nTab );
1762*cdf0e10cSrcweir 						const ScMergeFlagAttr* pMergeFlag = (const ScMergeFlagAttr*) &pPattern->
1763*cdf0e10cSrcweir 																		GetItem(ATTR_MERGE_FLAG);
1764*cdf0e10cSrcweir 						if ( pMergeFlag->IsVerOverlapped() && ( bDoHidden || bFirstRow ) )
1765*cdf0e10cSrcweir 						{
1766*cdf0e10cSrcweir 							while ( pMergeFlag->IsVerOverlapped() && nThisY > 0 &&
1767*cdf0e10cSrcweir                                     (pDoc->RowHidden(nThisY-1, nTab) || bFirstRow) )
1768*cdf0e10cSrcweir 							{
1769*cdf0e10cSrcweir 								--nThisY;
1770*cdf0e10cSrcweir 								pPattern = pDoc->GetPattern( nX, nThisY, nTab );
1771*cdf0e10cSrcweir 								pMergeFlag = (const ScMergeFlagAttr*) &pPattern->GetItem(ATTR_MERGE_FLAG);
1772*cdf0e10cSrcweir 							}
1773*cdf0e10cSrcweir 						}
1774*cdf0e10cSrcweir 
1775*cdf0e10cSrcweir 						// nur Rest von zusammengefasster zu sehen ?
1776*cdf0e10cSrcweir 						SCCOL nThisX = nX;
1777*cdf0e10cSrcweir 						if ( pMergeFlag->IsHorOverlapped() && nX == nPosX && nX > nRealX1 )
1778*cdf0e10cSrcweir 						{
1779*cdf0e10cSrcweir 							while ( pMergeFlag->IsHorOverlapped() )
1780*cdf0e10cSrcweir 							{
1781*cdf0e10cSrcweir 								--nThisX;
1782*cdf0e10cSrcweir 								pPattern = pDoc->GetPattern( nThisX, nThisY, nTab );
1783*cdf0e10cSrcweir 								pMergeFlag = (const ScMergeFlagAttr*) &pPattern->GetItem(ATTR_MERGE_FLAG);
1784*cdf0e10cSrcweir 							}
1785*cdf0e10cSrcweir 						}
1786*cdf0e10cSrcweir 
1787*cdf0e10cSrcweir 						if ( aMultiMark.IsCellMarked( nThisX, nThisY, sal_True ) == bRepeat )
1788*cdf0e10cSrcweir 						{
1789*cdf0e10cSrcweir 							if ( !pMergeFlag->IsOverlapped() )
1790*cdf0e10cSrcweir 							{
1791*cdf0e10cSrcweir 								ScMergeAttr* pMerge = (ScMergeAttr*)&pPattern->GetItem(ATTR_MERGE);
1792*cdf0e10cSrcweir 								if (pMerge->GetColMerge() > 0 || pMerge->GetRowMerge() > 0)
1793*cdf0e10cSrcweir 								{
1794*cdf0e10cSrcweir 									Point aEndPos = pViewData->GetScrPos(
1795*cdf0e10cSrcweir 											nThisX + pMerge->GetColMerge(),
1796*cdf0e10cSrcweir 											nThisY + pMerge->GetRowMerge(), eWhich );
1797*cdf0e10cSrcweir 									if ( aEndPos.X() * nLayoutSign > nScrX * nLayoutSign && aEndPos.Y() > nScrY )
1798*cdf0e10cSrcweir 									{
1799*cdf0e10cSrcweir 										aInvert.AddRect( Rectangle( nScrX,nScrY,
1800*cdf0e10cSrcweir 													aEndPos.X()-nLayoutSign,aEndPos.Y()-1 ) );
1801*cdf0e10cSrcweir 									}
1802*cdf0e10cSrcweir 								}
1803*cdf0e10cSrcweir 								else if ( nEndX * nLayoutSign >= nScrX * nLayoutSign && nEndY >= nScrY )
1804*cdf0e10cSrcweir 								{
1805*cdf0e10cSrcweir 									aInvert.AddRect( Rectangle( nScrX,nScrY,nEndX,nEndY ) );
1806*cdf0e10cSrcweir 								}
1807*cdf0e10cSrcweir 							}
1808*cdf0e10cSrcweir 						}
1809*cdf0e10cSrcweir 					}
1810*cdf0e10cSrcweir 					else		// !bTestMerge
1811*cdf0e10cSrcweir 					{
1812*cdf0e10cSrcweir 						if ( aMultiMark.IsCellMarked( nX, nY, sal_True ) == bRepeat &&
1813*cdf0e10cSrcweir 												nEndX * nLayoutSign >= nScrX * nLayoutSign && nEndY >= nScrY )
1814*cdf0e10cSrcweir 						{
1815*cdf0e10cSrcweir 							aInvert.AddRect( Rectangle( nScrX,nScrY,nEndX,nEndY ) );
1816*cdf0e10cSrcweir 						}
1817*cdf0e10cSrcweir 					}
1818*cdf0e10cSrcweir 
1819*cdf0e10cSrcweir 					nScrX = nEndX + nLayoutSign;
1820*cdf0e10cSrcweir 				}
1821*cdf0e10cSrcweir 			}
1822*cdf0e10cSrcweir 			nScrY = nEndY + 1;
1823*cdf0e10cSrcweir 		}
1824*cdf0e10cSrcweir 	}
1825*cdf0e10cSrcweir 
1826*cdf0e10cSrcweir //	aInvert.Flush();		// before restoring MapMode
1827*cdf0e10cSrcweir }
1828*cdf0e10cSrcweir 
1829*cdf0e10cSrcweir // -------------------------------------------------------------------------
1830*cdf0e10cSrcweir 
1831*cdf0e10cSrcweir //UNUSED2008-05  void ScGridWindow::DrawDragRect( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 )
1832*cdf0e10cSrcweir //UNUSED2008-05  {
1833*cdf0e10cSrcweir //UNUSED2008-05      if ( nX2 < pViewData->GetPosX(eHWhich) || nY2 < pViewData->GetPosY(eVWhich) )
1834*cdf0e10cSrcweir //UNUSED2008-05          return;
1835*cdf0e10cSrcweir //UNUSED2008-05
1836*cdf0e10cSrcweir //UNUSED2008-05      Update();           // wegen XOR
1837*cdf0e10cSrcweir //UNUSED2008-05
1838*cdf0e10cSrcweir //UNUSED2008-05      MapMode aOld = GetMapMode(); SetMapMode(MAP_PIXEL);
1839*cdf0e10cSrcweir //UNUSED2008-05
1840*cdf0e10cSrcweir //UNUSED2008-05      SCTAB nTab = pViewData->GetTabNo();
1841*cdf0e10cSrcweir //UNUSED2008-05
1842*cdf0e10cSrcweir //UNUSED2008-05      SCCOL nPosX = pViewData->GetPosX(WhichH(eWhich));
1843*cdf0e10cSrcweir //UNUSED2008-05      SCROW nPosY = pViewData->GetPosY(WhichV(eWhich));
1844*cdf0e10cSrcweir //UNUSED2008-05      if (nX1 < nPosX) nX1 = nPosX;
1845*cdf0e10cSrcweir //UNUSED2008-05      if (nX2 < nPosX) nX2 = nPosX;
1846*cdf0e10cSrcweir //UNUSED2008-05      if (nY1 < nPosY) nY1 = nPosY;
1847*cdf0e10cSrcweir //UNUSED2008-05      if (nY2 < nPosY) nY2 = nPosY;
1848*cdf0e10cSrcweir //UNUSED2008-05
1849*cdf0e10cSrcweir //UNUSED2008-05      Point aScrPos( pViewData->GetScrPos( nX1, nY1, eWhich ) );
1850*cdf0e10cSrcweir //UNUSED2008-05
1851*cdf0e10cSrcweir //UNUSED2008-05      long nSizeXPix=0;
1852*cdf0e10cSrcweir //UNUSED2008-05      long nSizeYPix=0;
1853*cdf0e10cSrcweir //UNUSED2008-05      ScDocument* pDoc = pViewData->GetDocument();
1854*cdf0e10cSrcweir //UNUSED2008-05      double nPPTX = pViewData->GetPPTX();
1855*cdf0e10cSrcweir //UNUSED2008-05      double nPPTY = pViewData->GetPPTY();
1856*cdf0e10cSrcweir //UNUSED2008-05      SCCOLROW i;
1857*cdf0e10cSrcweir //UNUSED2008-05
1858*cdf0e10cSrcweir //UNUSED2008-05      sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
1859*cdf0e10cSrcweir //UNUSED2008-05      long nLayoutSign = bLayoutRTL ? -1 : 1;
1860*cdf0e10cSrcweir //UNUSED2008-05
1861*cdf0e10cSrcweir //UNUSED2008-05      if (ValidCol(nX2) && nX2>=nX1)
1862*cdf0e10cSrcweir //UNUSED2008-05          for (i=nX1; i<=nX2; i++)
1863*cdf0e10cSrcweir //UNUSED2008-05              nSizeXPix += ScViewData::ToPixel( pDoc->GetColWidth( static_cast<SCCOL>(i), nTab ), nPPTX );
1864*cdf0e10cSrcweir //UNUSED2008-05      else
1865*cdf0e10cSrcweir //UNUSED2008-05      {
1866*cdf0e10cSrcweir //UNUSED2008-05          aScrPos.X() -= nLayoutSign;
1867*cdf0e10cSrcweir //UNUSED2008-05          nSizeXPix   += 2;
1868*cdf0e10cSrcweir //UNUSED2008-05      }
1869*cdf0e10cSrcweir //UNUSED2008-05
1870*cdf0e10cSrcweir //UNUSED2008-05      if (ValidRow(nY2) && nY2>=nY1)
1871*cdf0e10cSrcweir //UNUSED2008-05          for (i=nY1; i<=nY2; i++)
1872*cdf0e10cSrcweir //UNUSED2008-05              nSizeYPix += ScViewData::ToPixel( pDoc->GetRowHeight( i, nTab ), nPPTY );
1873*cdf0e10cSrcweir //UNUSED2008-05      else
1874*cdf0e10cSrcweir //UNUSED2008-05      {
1875*cdf0e10cSrcweir //UNUSED2008-05          aScrPos.Y() -= 1;
1876*cdf0e10cSrcweir //UNUSED2008-05          nSizeYPix   += 2;
1877*cdf0e10cSrcweir //UNUSED2008-05      }
1878*cdf0e10cSrcweir //UNUSED2008-05
1879*cdf0e10cSrcweir //UNUSED2008-05      aScrPos.X() -= 2 * nLayoutSign;
1880*cdf0e10cSrcweir //UNUSED2008-05      aScrPos.Y() -= 2;
1881*cdf0e10cSrcweir //UNUSED2008-05  //	Rectangle aRect( aScrPos, Size( nSizeXPix + 3, nSizeYPix + 3 ) );
1882*cdf0e10cSrcweir //UNUSED2008-05      Rectangle aRect( aScrPos.X(), aScrPos.Y(),
1883*cdf0e10cSrcweir //UNUSED2008-05                       aScrPos.X() + ( nSizeXPix + 2 ) * nLayoutSign, aScrPos.Y() + nSizeYPix + 2 );
1884*cdf0e10cSrcweir //UNUSED2008-05      if ( bLayoutRTL )
1885*cdf0e10cSrcweir //UNUSED2008-05      {
1886*cdf0e10cSrcweir //UNUSED2008-05          aRect.Left() = aRect.Right();   // end position is left
1887*cdf0e10cSrcweir //UNUSED2008-05          aRect.Right() = aScrPos.X();
1888*cdf0e10cSrcweir //UNUSED2008-05      }
1889*cdf0e10cSrcweir //UNUSED2008-05
1890*cdf0e10cSrcweir //UNUSED2008-05      Invert(Rectangle( aRect.Left(), aRect.Top(), aRect.Left()+2, aRect.Bottom() ));
1891*cdf0e10cSrcweir //UNUSED2008-05      Invert(Rectangle( aRect.Right()-2, aRect.Top(), aRect.Right(), aRect.Bottom() ));
1892*cdf0e10cSrcweir //UNUSED2008-05      Invert(Rectangle( aRect.Left()+3, aRect.Top(), aRect.Right()-3, aRect.Top()+2 ));
1893*cdf0e10cSrcweir //UNUSED2008-05      Invert(Rectangle( aRect.Left()+3, aRect.Bottom()-2, aRect.Right()-3, aRect.Bottom() ));
1894*cdf0e10cSrcweir //UNUSED2008-05
1895*cdf0e10cSrcweir //UNUSED2008-05      SetMapMode(aOld);
1896*cdf0e10cSrcweir //UNUSED2008-05  }
1897*cdf0e10cSrcweir 
1898*cdf0e10cSrcweir // -------------------------------------------------------------------------
1899*cdf0e10cSrcweir 
1900*cdf0e10cSrcweir void ScGridWindow::DrawCursor()
1901*cdf0e10cSrcweir {
1902*cdf0e10cSrcweir // #114409#
1903*cdf0e10cSrcweir //	SCTAB nTab = pViewData->GetTabNo();
1904*cdf0e10cSrcweir //	SCCOL nX = pViewData->GetCurX();
1905*cdf0e10cSrcweir //	SCROW nY = pViewData->GetCurY();
1906*cdf0e10cSrcweir //
1907*cdf0e10cSrcweir //	//	in verdeckten Zellen nicht zeichnen
1908*cdf0e10cSrcweir //
1909*cdf0e10cSrcweir //	ScDocument* pDoc = pViewData->GetDocument();
1910*cdf0e10cSrcweir //	const ScPatternAttr* pPattern = pDoc->GetPattern(nX,nY,nTab);
1911*cdf0e10cSrcweir //	const ScMergeFlagAttr& rMerge = (const ScMergeFlagAttr&) pPattern->GetItem(ATTR_MERGE_FLAG);
1912*cdf0e10cSrcweir //	if (rMerge.IsOverlapped())
1913*cdf0e10cSrcweir //		return;
1914*cdf0e10cSrcweir //
1915*cdf0e10cSrcweir //	//	links/oben ausserhalb des Bildschirms ?
1916*cdf0e10cSrcweir //
1917*cdf0e10cSrcweir //	sal_Bool bVis = ( nX>=pViewData->GetPosX(eHWhich) && nY>=pViewData->GetPosY(eVWhich) );
1918*cdf0e10cSrcweir //	if (!bVis)
1919*cdf0e10cSrcweir //	{
1920*cdf0e10cSrcweir //		SCCOL nEndX = nX;
1921*cdf0e10cSrcweir //		SCROW nEndY = nY;
1922*cdf0e10cSrcweir //		ScDocument* pDoc = pViewData->GetDocument();
1923*cdf0e10cSrcweir //		const ScMergeAttr& rMerge = (const ScMergeAttr&) pPattern->GetItem(ATTR_MERGE);
1924*cdf0e10cSrcweir //		if (rMerge.GetColMerge() > 1)
1925*cdf0e10cSrcweir //			nEndX += rMerge.GetColMerge()-1;
1926*cdf0e10cSrcweir //		if (rMerge.GetRowMerge() > 1)
1927*cdf0e10cSrcweir //			nEndY += rMerge.GetRowMerge()-1;
1928*cdf0e10cSrcweir //		bVis = ( nEndX>=pViewData->GetPosX(eHWhich) && nEndY>=pViewData->GetPosY(eVWhich) );
1929*cdf0e10cSrcweir //	}
1930*cdf0e10cSrcweir //
1931*cdf0e10cSrcweir //	if ( bVis )
1932*cdf0e10cSrcweir //	{
1933*cdf0e10cSrcweir //		//	hier kein Update, da aus Paint gerufen und laut Zaehler Cursor schon da
1934*cdf0e10cSrcweir //		//	wenn Update noetig, dann bei Hide/Showcursor vor dem Hoch-/Runterzaehlen
1935*cdf0e10cSrcweir //
1936*cdf0e10cSrcweir //		MapMode aOld = GetMapMode(); SetMapMode(MAP_PIXEL);
1937*cdf0e10cSrcweir //
1938*cdf0e10cSrcweir //		Point aScrPos = pViewData->GetScrPos( nX, nY, eWhich, sal_True );
1939*cdf0e10cSrcweir //		sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
1940*cdf0e10cSrcweir //
1941*cdf0e10cSrcweir //		//	completely right of/below the screen?
1942*cdf0e10cSrcweir //		//	(test with logical start position in aScrPos)
1943*cdf0e10cSrcweir //		sal_Bool bMaybeVisible;
1944*cdf0e10cSrcweir //		if ( bLayoutRTL )
1945*cdf0e10cSrcweir //			bMaybeVisible = ( aScrPos.X() >= -2 && aScrPos.Y() >= -2 );
1946*cdf0e10cSrcweir //		else
1947*cdf0e10cSrcweir //		{
1948*cdf0e10cSrcweir //			Size aOutSize = GetOutputSizePixel();
1949*cdf0e10cSrcweir //			bMaybeVisible = ( aScrPos.X() <= aOutSize.Width() + 2 && aScrPos.Y() <= aOutSize.Height() + 2 );
1950*cdf0e10cSrcweir //		}
1951*cdf0e10cSrcweir //		if ( bMaybeVisible )
1952*cdf0e10cSrcweir //		{
1953*cdf0e10cSrcweir //			long nSizeXPix;
1954*cdf0e10cSrcweir //			long nSizeYPix;
1955*cdf0e10cSrcweir //			pViewData->GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );
1956*cdf0e10cSrcweir //
1957*cdf0e10cSrcweir //			if ( bLayoutRTL )
1958*cdf0e10cSrcweir //				aScrPos.X() -= nSizeXPix - 2;		// move instead of mirroring
1959*cdf0e10cSrcweir //
1960*cdf0e10cSrcweir //			sal_Bool bFix = ( pViewData->GetHSplitMode() == SC_SPLIT_FIX ||
1961*cdf0e10cSrcweir //							pViewData->GetVSplitMode() == SC_SPLIT_FIX );
1962*cdf0e10cSrcweir //			if ( pViewData->GetActivePart()==eWhich || bFix )
1963*cdf0e10cSrcweir //			{
1964*cdf0e10cSrcweir //				//	old UNX version with two Invert calls causes flicker.
1965*cdf0e10cSrcweir //				//	if optimization is needed, a new flag should be added
1966*cdf0e10cSrcweir //				//	to InvertTracking
1967*cdf0e10cSrcweir //
1968*cdf0e10cSrcweir //				aScrPos.X() -= 2;
1969*cdf0e10cSrcweir //				aScrPos.Y() -= 2;
1970*cdf0e10cSrcweir //				Rectangle aRect( aScrPos, Size( nSizeXPix + 3, nSizeYPix + 3 ) );
1971*cdf0e10cSrcweir //
1972*cdf0e10cSrcweir //				Invert(Rectangle( aRect.Left(), aRect.Top(), aRect.Left()+2, aRect.Bottom() ));
1973*cdf0e10cSrcweir //				Invert(Rectangle( aRect.Right()-2, aRect.Top(), aRect.Right(), aRect.Bottom() ));
1974*cdf0e10cSrcweir //				Invert(Rectangle( aRect.Left()+3, aRect.Top(), aRect.Right()-3, aRect.Top()+2 ));
1975*cdf0e10cSrcweir //				Invert(Rectangle( aRect.Left()+3, aRect.Bottom()-2, aRect.Right()-3, aRect.Bottom() ));
1976*cdf0e10cSrcweir //			}
1977*cdf0e10cSrcweir //			else
1978*cdf0e10cSrcweir //			{
1979*cdf0e10cSrcweir //				Rectangle aRect( aScrPos, Size( nSizeXPix - 1, nSizeYPix - 1 ) );
1980*cdf0e10cSrcweir //				Invert( aRect );
1981*cdf0e10cSrcweir //			}
1982*cdf0e10cSrcweir //		}
1983*cdf0e10cSrcweir //
1984*cdf0e10cSrcweir //		SetMapMode(aOld);
1985*cdf0e10cSrcweir //	}
1986*cdf0e10cSrcweir }
1987*cdf0e10cSrcweir 
1988*cdf0e10cSrcweir 	//	AutoFill-Anfasser:
1989*cdf0e10cSrcweir 
1990*cdf0e10cSrcweir void ScGridWindow::DrawAutoFillMark()
1991*cdf0e10cSrcweir {
1992*cdf0e10cSrcweir // #114409#
1993*cdf0e10cSrcweir //	if ( bAutoMarkVisible && aAutoMarkPos.Tab() == pViewData->GetTabNo() )
1994*cdf0e10cSrcweir //	{
1995*cdf0e10cSrcweir //		SCCOL nX = aAutoMarkPos.Col();
1996*cdf0e10cSrcweir //		SCROW nY = aAutoMarkPos.Row();
1997*cdf0e10cSrcweir //		SCTAB nTab = pViewData->GetTabNo();
1998*cdf0e10cSrcweir //		ScDocument* pDoc = pViewData->GetDocument();
1999*cdf0e10cSrcweir //		sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
2000*cdf0e10cSrcweir //
2001*cdf0e10cSrcweir //		Point aFillPos = pViewData->GetScrPos( nX, nY, eWhich, sal_True );
2002*cdf0e10cSrcweir //		long nSizeXPix;
2003*cdf0e10cSrcweir //		long nSizeYPix;
2004*cdf0e10cSrcweir //		pViewData->GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );
2005*cdf0e10cSrcweir //		if ( bLayoutRTL )
2006*cdf0e10cSrcweir //			aFillPos.X() -= nSizeXPix + 3;
2007*cdf0e10cSrcweir //		else
2008*cdf0e10cSrcweir //			aFillPos.X() += nSizeXPix - 2;
2009*cdf0e10cSrcweir //
2010*cdf0e10cSrcweir //		aFillPos.Y() += nSizeYPix;
2011*cdf0e10cSrcweir //		aFillPos.Y() -= 2;
2012*cdf0e10cSrcweir //		Rectangle aFillRect( aFillPos, Size(6,6) );
2013*cdf0e10cSrcweir //		//	Anfasser von Zeichenobjekten sind 7*7
2014*cdf0e10cSrcweir //
2015*cdf0e10cSrcweir //		MapMode aOld = GetMapMode(); SetMapMode(MAP_PIXEL);
2016*cdf0e10cSrcweir //		Invert( aFillRect );
2017*cdf0e10cSrcweir //		SetMapMode(aOld);
2018*cdf0e10cSrcweir //	}
2019*cdf0e10cSrcweir }
2020*cdf0e10cSrcweir 
2021*cdf0e10cSrcweir // -------------------------------------------------------------------------
2022*cdf0e10cSrcweir 
2023*cdf0e10cSrcweir void ScGridWindow::DataChanged( const DataChangedEvent& rDCEvt )
2024*cdf0e10cSrcweir {
2025*cdf0e10cSrcweir 	Window::DataChanged(rDCEvt);
2026*cdf0e10cSrcweir 
2027*cdf0e10cSrcweir 	if ( (rDCEvt.GetType() == DATACHANGED_PRINTER) ||
2028*cdf0e10cSrcweir 		 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
2029*cdf0e10cSrcweir 		 (rDCEvt.GetType() == DATACHANGED_FONTS) ||
2030*cdf0e10cSrcweir 		 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
2031*cdf0e10cSrcweir 		 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
2032*cdf0e10cSrcweir 		  (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
2033*cdf0e10cSrcweir 	{
2034*cdf0e10cSrcweir 		if ( rDCEvt.GetType() == DATACHANGED_FONTS && eWhich == pViewData->GetActivePart() )
2035*cdf0e10cSrcweir 			pViewData->GetDocShell()->UpdateFontList();
2036*cdf0e10cSrcweir 
2037*cdf0e10cSrcweir 		if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
2038*cdf0e10cSrcweir 			 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
2039*cdf0e10cSrcweir 		{
2040*cdf0e10cSrcweir 			if ( eWhich == pViewData->GetActivePart() )		// only once for the view
2041*cdf0e10cSrcweir 			{
2042*cdf0e10cSrcweir 				ScTabView* pView = pViewData->GetView();
2043*cdf0e10cSrcweir 
2044*cdf0e10cSrcweir 				//	update scale in case the UI ScreenZoom has changed
2045*cdf0e10cSrcweir 				ScGlobal::UpdatePPT(this);
2046*cdf0e10cSrcweir 				pView->RecalcPPT();
2047*cdf0e10cSrcweir 
2048*cdf0e10cSrcweir 				//	RepeatResize in case scroll bar sizes have changed
2049*cdf0e10cSrcweir 				pView->RepeatResize();
2050*cdf0e10cSrcweir                 pView->UpdateAllOverlays();
2051*cdf0e10cSrcweir 
2052*cdf0e10cSrcweir 				//	invalidate cell attribs in input handler, in case the
2053*cdf0e10cSrcweir 				//	EditEngine BackgroundColor has to be changed
2054*cdf0e10cSrcweir 				if ( pViewData->IsActive() )
2055*cdf0e10cSrcweir 				{
2056*cdf0e10cSrcweir 					ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
2057*cdf0e10cSrcweir 					if (pHdl)
2058*cdf0e10cSrcweir 						pHdl->ForgetLastPattern();
2059*cdf0e10cSrcweir 				}
2060*cdf0e10cSrcweir 			}
2061*cdf0e10cSrcweir 		}
2062*cdf0e10cSrcweir 
2063*cdf0e10cSrcweir 		Invalidate();
2064*cdf0e10cSrcweir 	}
2065*cdf0e10cSrcweir }
2066*cdf0e10cSrcweir 
2067*cdf0e10cSrcweir 
2068*cdf0e10cSrcweir 
2069*cdf0e10cSrcweir 
2070