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