Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "scitems.hxx"
30 : : #include <svx/algitem.hxx>
31 : : #include <editeng/boxitem.hxx>
32 : : #include <editeng/brshitem.hxx>
33 : : #include <editeng/cntritem.hxx>
34 : : #include <editeng/colritem.hxx>
35 : : #include <editeng/crsditem.hxx>
36 : : #include <editeng/fontitem.hxx>
37 : : #include <editeng/postitem.hxx>
38 : : #include <editeng/shdditem.hxx>
39 : : #include <editeng/udlnitem.hxx>
40 : : #include <editeng/wghtitem.hxx>
41 : : #include <vcl/svapp.hxx>
42 : : #include <svl/zforlist.hxx>
43 : : #include <vcl/msgbox.hxx>
44 : : #include <sfx2/viewfrm.hxx>
45 : : #include <comphelper/processfactory.hxx>
46 : :
47 : : #include "sc.hrc"
48 : : #include "scmod.hxx"
49 : : #include "attrib.hxx"
50 : : #include "zforauto.hxx"
51 : : #include "global.hxx"
52 : : #include "globstr.hrc"
53 : : #include "autoform.hxx"
54 : : #include "miscdlgs.hrc"
55 : : #include "autofmt.hxx"
56 : : #include "scresid.hxx"
57 : : #include "document.hxx"
58 : : #include "docsh.hxx"
59 : : #include "tabvwsh.hxx"
60 : :
61 : : #define FRAME_OFFSET 4
62 : :
63 : :
64 : : //========================================================================
65 : : // ScAutoFmtPreview
66 : :
67 : 0 : ScAutoFmtPreview::ScAutoFmtPreview( Window* pParent, const ResId& rRes, ScDocument* pDoc ) :
68 : : Window ( pParent, rRes ),
69 : : pCurData ( NULL ),
70 : : aVD ( *this ),
71 : : aScriptedText ( aVD ),
72 [ # # ]: 0 : xBreakIter ( pDoc->GetBreakIterator() ),
73 : : bFitWidth ( false ),
74 : : mbRTL ( false ),
75 [ # # ][ # # ]: 0 : aPrvSize ( GetSizePixel().Width() - 6, GetSizePixel().Height() - 30 ),
76 : 0 : mnLabelColWidth ( (aPrvSize.Width() - 4) / 4 - 12 ),
77 : 0 : mnDataColWidth1 ( (aPrvSize.Width() - 4 - 2 * mnLabelColWidth) / 3 ),
78 : 0 : mnDataColWidth2 ( (aPrvSize.Width() - 4 - 2 * mnLabelColWidth) / 4 ),
79 : 0 : mnRowHeight ( (aPrvSize.Height() - 4) / 5 ),
80 : : aStrJan ( ScResId( STR_JAN ) ),
81 : : aStrFeb ( ScResId( STR_FEB ) ),
82 : : aStrMar ( ScResId( STR_MAR ) ),
83 : : aStrNorth ( ScResId( STR_NORTH ) ),
84 : : aStrMid ( ScResId( STR_MID ) ),
85 : : aStrSouth ( ScResId( STR_SOUTH ) ),
86 : : aStrSum ( ScResId( STR_SUM ) ),
87 [ # # ][ # # ]: 0 : pNumFmt ( new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), ScGlobal::eLnge ) )
[ # # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
88 : : {
89 [ # # ]: 0 : Init();
90 : 0 : }
91 : :
92 : : //------------------------------------------------------------------------
93 : :
94 [ # # ][ # # ]: 0 : ScAutoFmtPreview::~ScAutoFmtPreview()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
95 : : {
96 [ # # ][ # # ]: 0 : delete pNumFmt;
97 [ # # ]: 0 : }
98 : :
99 : : //------------------------------------------------------------------------
100 : :
101 : 0 : void lcl_SetFontProperties(
102 : : Font& rFont,
103 : : const SvxFontItem& rFontItem,
104 : : const SvxWeightItem& rWeightItem,
105 : : const SvxPostureItem& rPostureItem )
106 : : {
107 : 0 : rFont.SetFamily ( rFontItem.GetFamily() );
108 [ # # ]: 0 : rFont.SetName ( rFontItem.GetFamilyName() );
109 : 0 : rFont.SetStyleName ( rFontItem.GetStyleName() );
110 : 0 : rFont.SetCharSet ( rFontItem.GetCharSet() );
111 : 0 : rFont.SetPitch ( rFontItem.GetPitch() );
112 : 0 : rFont.SetWeight ( (FontWeight)rWeightItem.GetValue() );
113 : 0 : rFont.SetItalic ( (FontItalic)rPostureItem.GetValue() );
114 : 0 : }
115 : :
116 : 0 : void ScAutoFmtPreview::MakeFonts( sal_uInt16 nIndex, Font& rFont, Font& rCJKFont, Font& rCTLFont )
117 : : {
118 [ # # ]: 0 : if ( pCurData )
119 : : {
120 [ # # ][ # # ]: 0 : rFont = rCJKFont = rCTLFont = GetFont();
[ # # ]
121 [ # # ]: 0 : Size aFontSize( rFont.GetSize().Width(), 10 );
122 : :
123 [ # # ]: 0 : const SvxFontItem* pFontItem = (const SvxFontItem*) pCurData->GetItem( nIndex, ATTR_FONT );
124 [ # # ]: 0 : const SvxWeightItem* pWeightItem = (const SvxWeightItem*) pCurData->GetItem( nIndex, ATTR_FONT_WEIGHT );
125 [ # # ]: 0 : const SvxPostureItem* pPostureItem = (const SvxPostureItem*) pCurData->GetItem( nIndex, ATTR_FONT_POSTURE );
126 [ # # ]: 0 : const SvxFontItem* pCJKFontItem = (const SvxFontItem*) pCurData->GetItem( nIndex, ATTR_CJK_FONT );
127 [ # # ]: 0 : const SvxWeightItem* pCJKWeightItem = (const SvxWeightItem*) pCurData->GetItem( nIndex, ATTR_CJK_FONT_WEIGHT );
128 [ # # ]: 0 : const SvxPostureItem* pCJKPostureItem = (const SvxPostureItem*) pCurData->GetItem( nIndex, ATTR_CJK_FONT_POSTURE );
129 [ # # ]: 0 : const SvxFontItem* pCTLFontItem = (const SvxFontItem*) pCurData->GetItem( nIndex, ATTR_CTL_FONT );
130 [ # # ]: 0 : const SvxWeightItem* pCTLWeightItem = (const SvxWeightItem*) pCurData->GetItem( nIndex, ATTR_CTL_FONT_WEIGHT );
131 [ # # ]: 0 : const SvxPostureItem* pCTLPostureItem = (const SvxPostureItem*) pCurData->GetItem( nIndex, ATTR_CTL_FONT_POSTURE );
132 [ # # ]: 0 : const SvxUnderlineItem* pUnderlineItem = (const SvxUnderlineItem*) pCurData->GetItem( nIndex, ATTR_FONT_UNDERLINE );
133 [ # # ]: 0 : const SvxOverlineItem* pOverlineItem = (const SvxOverlineItem*) pCurData->GetItem( nIndex, ATTR_FONT_OVERLINE );
134 [ # # ]: 0 : const SvxCrossedOutItem* pCrossedOutItem = (const SvxCrossedOutItem*)pCurData->GetItem( nIndex, ATTR_FONT_CROSSEDOUT );
135 [ # # ]: 0 : const SvxContourItem* pContourItem = (const SvxContourItem*) pCurData->GetItem( nIndex, ATTR_FONT_CONTOUR );
136 [ # # ]: 0 : const SvxShadowedItem* pShadowedItem = (const SvxShadowedItem*) pCurData->GetItem( nIndex, ATTR_FONT_SHADOWED );
137 [ # # ]: 0 : const SvxColorItem* pColorItem = (const SvxColorItem*) pCurData->GetItem( nIndex, ATTR_FONT_COLOR );
138 : :
139 [ # # ]: 0 : lcl_SetFontProperties( rFont, *pFontItem, *pWeightItem, *pPostureItem );
140 [ # # ]: 0 : lcl_SetFontProperties( rCJKFont, *pCJKFontItem, *pCJKWeightItem, *pCJKPostureItem );
141 [ # # ]: 0 : lcl_SetFontProperties( rCTLFont, *pCTLFontItem, *pCTLWeightItem, *pCTLPostureItem );
142 : :
143 : 0 : Color aColor( pColorItem->GetValue() );
144 [ # # ]: 0 : if( aColor.GetColor() == COL_TRANSPARENT )
145 : 0 : aColor = GetSettings().GetStyleSettings().GetWindowTextColor();
146 : :
147 : : #define SETONALLFONTS( MethodName, Value ) \
148 : : rFont.MethodName( Value ); rCJKFont.MethodName( Value ); rCTLFont.MethodName( Value );
149 : :
150 [ # # ][ # # ]: 0 : SETONALLFONTS( SetUnderline, (FontUnderline)pUnderlineItem->GetValue() )
[ # # ]
151 [ # # ][ # # ]: 0 : SETONALLFONTS( SetOverline, (FontUnderline)pOverlineItem->GetValue() )
[ # # ]
152 [ # # ][ # # ]: 0 : SETONALLFONTS( SetStrikeout, (FontStrikeout)pCrossedOutItem->GetValue() )
[ # # ]
153 [ # # ][ # # ]: 0 : SETONALLFONTS( SetOutline, pContourItem->GetValue() )
[ # # ]
154 [ # # ][ # # ]: 0 : SETONALLFONTS( SetShadow, pShadowedItem->GetValue() )
[ # # ]
155 [ # # ][ # # ]: 0 : SETONALLFONTS( SetColor, aColor )
[ # # ]
156 [ # # ][ # # ]: 0 : SETONALLFONTS( SetSize, aFontSize )
[ # # ]
157 [ # # ][ # # ]: 0 : SETONALLFONTS( SetTransparent, sal_True )
[ # # ]
158 : :
159 : : #undef SETONALLFONTS
160 : : }
161 : 0 : }
162 : :
163 : : //------------------------------------------------------------------------
164 : :
165 : 0 : sal_uInt16 ScAutoFmtPreview::GetFormatIndex( size_t nCol, size_t nRow ) const
166 : : {
167 : : static const sal_uInt16 pnFmtMap[] =
168 : : {
169 : : 0, 1, 2, 1, 3,
170 : : 4, 5, 6, 5, 7,
171 : : 8, 9, 10, 9, 11,
172 : : 4, 5, 6, 5, 7,
173 : : 12, 13, 14, 13, 15
174 : : };
175 : 0 : return pnFmtMap[ maArray.GetCellIndex( nCol, nRow, mbRTL ) ];
176 : : }
177 : :
178 : 0 : const SvxBoxItem& ScAutoFmtPreview::GetBoxItem( size_t nCol, size_t nRow ) const
179 : : {
180 : : OSL_ENSURE( pCurData, "ScAutoFmtPreview::GetBoxItem - no format data found" );
181 : 0 : return *static_cast< const SvxBoxItem* >( pCurData->GetItem( GetFormatIndex( nCol, nRow ), ATTR_BORDER ) );
182 : : }
183 : :
184 : 0 : const SvxLineItem& ScAutoFmtPreview::GetDiagItem( size_t nCol, size_t nRow, bool bTLBR ) const
185 : : {
186 : : OSL_ENSURE( pCurData, "ScAutoFmtPreview::GetDiagItem - no format data found" );
187 [ # # ]: 0 : return *static_cast< const SvxLineItem* >( pCurData->GetItem( GetFormatIndex( nCol, nRow ), bTLBR ? ATTR_BORDER_TLBR : ATTR_BORDER_BLTR ) );
188 : : }
189 : :
190 : : //------------------------------------------------------------------------
191 : :
192 : 0 : void ScAutoFmtPreview::DrawString( size_t nCol, size_t nRow )
193 : : {
194 [ # # ]: 0 : if ( pCurData )
195 : : {
196 : : //------------------------
197 : : // Ausgabe des Zelltextes:
198 : : //------------------------
199 : :
200 [ # # ]: 0 : String cellString;
201 : 0 : sal_Bool bNumFormat = pCurData->GetIncludeValueFormat();
202 : : sal_uLong nNum;
203 : : double nVal;
204 : 0 : Color* pDummy = NULL;
205 [ # # ]: 0 : sal_uInt16 nIndex = static_cast< sal_uInt16 >( maArray.GetCellIndex( nCol, nRow, mbRTL ) );
206 : :
207 [ # # # # : 0 : switch( nIndex )
# # # # #
# # # # #
# # # # ]
208 : : {
209 [ # # ]: 0 : case 1: cellString = aStrJan; break;
210 [ # # ]: 0 : case 2: cellString = aStrFeb; break;
211 [ # # ]: 0 : case 3: cellString = aStrMar; break;
212 [ # # ]: 0 : case 5: cellString = aStrNorth; break;
213 [ # # ]: 0 : case 10: cellString = aStrMid; break;
214 [ # # ]: 0 : case 15: cellString = aStrSouth; break;
215 : : case 4:
216 [ # # ]: 0 : case 20: cellString = aStrSum; break;
217 : :
218 : : case 6:
219 : : case 8:
220 : : case 16:
221 : 0 : case 18: nVal = nIndex;
222 : 0 : nNum = 5;
223 : 0 : goto mknum;
224 : : case 17:
225 : 0 : case 7: nVal = nIndex;
226 : 0 : nNum = 6;
227 : 0 : goto mknum;
228 : : case 11:
229 : : case 12:
230 : 0 : case 13: nVal = nIndex;
231 [ # # ]: 0 : nNum = 12 == nIndex ? 10 : 9;
232 : 0 : goto mknum;
233 : :
234 : 0 : case 9: nVal = 21; nNum = 7; goto mknum;
235 : 0 : case 14: nVal = 36; nNum = 11; goto mknum;
236 : 0 : case 19: nVal = 51; nNum = 7; goto mknum;
237 : 0 : case 21: nVal = 33; nNum = 13; goto mknum;
238 : 0 : case 22: nVal = 36; nNum = 14; goto mknum;
239 : 0 : case 23: nVal = 39; nNum = 13; goto mknum;
240 : 0 : case 24: nVal = 108; nNum = 15;
241 : : mknum:
242 [ # # ]: 0 : if( bNumFormat )
243 : : {
244 [ # # ]: 0 : ScNumFormatAbbrev& rNumFormat = (ScNumFormatAbbrev&)pCurData->GetNumFormat( (sal_uInt16) nNum );
245 [ # # ]: 0 : nNum = rNumFormat.GetFormatIndex( *pNumFmt );
246 : : }
247 : : else
248 : 0 : nNum = 0;
249 [ # # ]: 0 : pNumFmt->GetOutputString( nVal, nNum, cellString, &pDummy );
250 : 0 : break;
251 : : }
252 : :
253 [ # # ]: 0 : if ( cellString.Len() > 0 )
254 : : {
255 : 0 : Size aStrSize;
256 [ # # ]: 0 : sal_uInt16 nFmtIndex = GetFormatIndex( nCol, nRow );
257 [ # # ]: 0 : Rectangle cellRect = maArray.GetCellRect( nCol, nRow );
258 : 0 : Point aPos = cellRect.TopLeft();
259 : 0 : sal_uInt16 nRightX = 0;
260 : 0 : sal_Bool bJustify = pCurData->GetIncludeJustify();
261 [ # # ]: 0 : SvxHorJustifyItem aHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY );
262 : : SvxCellHorJustify eJustification;
263 : :
264 : : //-------------
265 : : // Ausrichtung:
266 : : //-------------
267 : : eJustification = mbRTL ? SVX_HOR_JUSTIFY_RIGHT : bJustify ?
268 [ # # ]: 0 : (SvxCellHorJustify)(((const SvxHorJustifyItem*)pCurData->GetItem( nFmtIndex, ATTR_HOR_JUSTIFY ))->GetValue()) :
269 [ # # ][ # # ]: 0 : SVX_HOR_JUSTIFY_STANDARD;
270 : :
271 [ # # ]: 0 : if ( pCurData->GetIncludeFont() )
272 : : {
273 [ # # ][ # # ]: 0 : Font aFont, aCJKFont, aCTLFont;
[ # # ]
274 : 0 : Size theMaxStrSize;
275 : :
276 [ # # ]: 0 : MakeFonts( nFmtIndex, aFont, aCJKFont, aCTLFont );
277 : :
278 [ # # ]: 0 : theMaxStrSize = cellRect.GetSize();
279 : 0 : theMaxStrSize.Width() -= FRAME_OFFSET;
280 : 0 : theMaxStrSize.Height() -= FRAME_OFFSET;
281 : :
282 [ # # ]: 0 : aScriptedText.SetFonts( &aFont, &aCJKFont, &aCTLFont );
283 [ # # ][ # # ]: 0 : aScriptedText.SetText( cellString, xBreakIter );
284 [ # # ]: 0 : aStrSize = aScriptedText.GetTextSize();
285 : :
286 [ # # ]: 0 : if ( theMaxStrSize.Height() < aStrSize.Height() )
287 : : {
288 : : // wenn der String in diesem Font nicht
289 : : // in die Zelle passt, wird wieder der
290 : : // Standard-Font genommen:
291 [ # # ]: 0 : aScriptedText.SetDefaultFont();
292 [ # # ]: 0 : aStrSize = aScriptedText.GetTextSize();
293 : : }
294 [ # # # # ]: 0 : while ( ( theMaxStrSize.Width() <= aStrSize.Width() )
[ # # ]
295 : 0 : && ( cellString.Len() > 1 ) )
296 : : {
297 [ # # ]: 0 : if( eJustification == SVX_HOR_JUSTIFY_RIGHT )
298 [ # # ]: 0 : cellString.Erase( 0, 1 );
299 : : else
300 [ # # ]: 0 : cellString.Erase( cellString.Len() - 1 );
301 : :
302 [ # # ][ # # ]: 0 : aScriptedText.SetText( cellString, xBreakIter );
303 [ # # ]: 0 : aStrSize = aScriptedText.GetTextSize();
304 [ # # ][ # # ]: 0 : }
[ # # ]
305 : : }
306 : : else
307 : : {
308 [ # # ]: 0 : aScriptedText.SetDefaultFont();
309 [ # # ][ # # ]: 0 : aScriptedText.SetText( cellString, xBreakIter );
310 [ # # ]: 0 : aStrSize = aScriptedText.GetTextSize();
311 : : }
312 : :
313 [ # # ]: 0 : nRightX = (sal_uInt16)( cellRect.GetWidth()
314 : 0 : - aStrSize.Width()
315 : 0 : - FRAME_OFFSET );
316 : :
317 : : //-----------------------------
318 : : // vertikal (immer zentrieren):
319 : : //-----------------------------
320 : 0 : aPos.Y() += (mnRowHeight - (sal_uInt16)aStrSize.Height()) / 2;
321 : :
322 : : //-----------
323 : : // horizontal
324 : : //-----------
325 [ # # ]: 0 : if ( eJustification != SVX_HOR_JUSTIFY_STANDARD )
326 : : {
327 : : sal_uInt16 nHorPos = (sal_uInt16)
328 [ # # ]: 0 : ((cellRect.GetWidth()-aStrSize.Width())/2);
329 : :
330 [ # # # # ]: 0 : switch ( eJustification )
331 : : {
332 : : case SVX_HOR_JUSTIFY_LEFT:
333 : 0 : aPos.X() += FRAME_OFFSET;
334 : 0 : break;
335 : : case SVX_HOR_JUSTIFY_RIGHT:
336 : 0 : aPos.X() += nRightX;
337 : 0 : break;
338 : : case SVX_HOR_JUSTIFY_BLOCK:
339 : : case SVX_HOR_JUSTIFY_REPEAT:
340 : : case SVX_HOR_JUSTIFY_CENTER:
341 : 0 : aPos.X() += nHorPos;
342 : 0 : break;
343 : : case SVX_HOR_JUSTIFY_STANDARD:
344 : : default:
345 : : // Standard wird hier nicht behandelt
346 : 0 : break;
347 : : }
348 : : }
349 : : else
350 : : {
351 : : //---------------------
352 : : // Standardausrichtung:
353 : : //---------------------
354 [ # # ][ # # ]: 0 : if ( (nCol == 0) || (nRow == 0) )
355 : : {
356 : : // Text-Label links oder Summe linksbuendig
357 : 0 : aPos.X() += FRAME_OFFSET;
358 : : }
359 : : else
360 : : {
361 : : // Zahlen/Datum rechtsbuendig
362 : 0 : aPos.X() += nRightX;
363 : : }
364 : : }
365 : :
366 : : //-------------------------------
367 [ # # ][ # # ]: 0 : aScriptedText.DrawText( aPos );
368 : : //-------------------------------
369 [ # # ]: 0 : }
370 : : }
371 : 0 : }
372 : :
373 : : #undef FRAME_OFFSET
374 : :
375 : : //------------------------------------------------------------------------
376 : :
377 : 0 : void ScAutoFmtPreview::DrawStrings()
378 : : {
379 [ # # ]: 0 : for( size_t nRow = 0; nRow < 5; ++nRow )
380 [ # # ]: 0 : for( size_t nCol = 0; nCol < 5; ++nCol )
381 : 0 : DrawString( nCol, nRow );
382 : 0 : }
383 : :
384 : : //------------------------------------------------------------------------
385 : :
386 : 0 : void ScAutoFmtPreview::DrawBackground()
387 : : {
388 [ # # ]: 0 : if( pCurData )
389 : : {
390 [ # # ]: 0 : for( size_t nRow = 0; nRow < 5; ++nRow )
391 : : {
392 [ # # ]: 0 : for( size_t nCol = 0; nCol < 5; ++nCol )
393 : : {
394 : : const SvxBrushItem* pItem = static_cast< const SvxBrushItem* >(
395 : 0 : pCurData->GetItem( GetFormatIndex( nCol, nRow ), ATTR_BACKGROUND ) );
396 : :
397 : 0 : aVD.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
398 : 0 : aVD.SetLineColor();
399 : 0 : aVD.SetFillColor( pItem->GetColor() );
400 [ # # ]: 0 : aVD.DrawRect( maArray.GetCellRect( nCol, nRow ) );
401 : 0 : aVD.Pop();
402 : : }
403 : : }
404 : : }
405 : 0 : }
406 : :
407 : : //------------------------------------------------------------------------
408 : :
409 : 0 : void ScAutoFmtPreview::PaintCells()
410 : : {
411 [ # # ]: 0 : if ( pCurData )
412 : : {
413 : : // 1) background
414 [ # # ]: 0 : if ( pCurData->GetIncludeBackground() )
415 : 0 : DrawBackground();
416 : :
417 : : // 2) values
418 : 0 : DrawStrings();
419 : :
420 : : // 3) border
421 [ # # ]: 0 : if ( pCurData->GetIncludeFrame() )
422 : 0 : maArray.DrawArray( aVD );
423 : : }
424 : 0 : }
425 : :
426 : : //------------------------------------------------------------------------
427 : :
428 : 0 : void ScAutoFmtPreview::Init()
429 : : {
430 [ # # ]: 0 : SetBorderStyle( WINDOW_BORDER_MONO );
431 [ # # ]: 0 : maArray.Initialize( 5, 5 );
432 [ # # ]: 0 : maArray.SetUseDiagDoubleClipping( false );
433 [ # # ]: 0 : CalcCellArray( false );
434 [ # # ]: 0 : CalcLineMap();
435 : :
436 [ # # ]: 0 : TypeId aType(TYPE(ScDocShell));
437 [ # # ]: 0 : ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType);
438 [ # # ]: 0 : SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
439 [ # # ]: 0 : SfxViewShell* p = pFrame->GetViewShell();
440 [ # # ]: 0 : ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell* >( p );
441 : 0 : ScViewData* pViewData = pViewSh->GetViewData();
442 : 0 : SCTAB nCurrentTab = pViewData->GetTabNo();
443 [ # # ]: 0 : ScDocument* pDoc = pViewData->GetDocument();
444 [ # # ]: 0 : mbRTL = pDoc->IsLayoutRTL( nCurrentTab );
445 : 0 : }
446 : :
447 : : //------------------------------------------------------------------------
448 : :
449 : 0 : void ScAutoFmtPreview::CalcCellArray( bool bFitWidthP )
450 : : {
451 : 0 : maArray.SetXOffset( 2 );
452 [ # # ]: 0 : maArray.SetAllColWidths( bFitWidthP ? mnDataColWidth2 : mnDataColWidth1 );
453 : 0 : maArray.SetColWidth( 0, mnLabelColWidth );
454 : 0 : maArray.SetColWidth( 4, mnLabelColWidth );
455 : :
456 : 0 : maArray.SetYOffset( 2 );
457 : 0 : maArray.SetAllRowHeights( mnRowHeight );
458 : :
459 : 0 : aPrvSize.Width() = maArray.GetWidth() + 4;
460 : 0 : aPrvSize.Height() = maArray.GetHeight() + 4;
461 : 0 : }
462 : :
463 : : //------------------------------------------------------------------------
464 : :
465 : 0 : inline void lclSetStyleFromBorder( svx::frame::Style& rStyle, const ::editeng::SvxBorderLine* pBorder )
466 : : {
467 : 0 : rStyle.Set( pBorder, 1.0 / TWIPS_PER_POINT, 5 );
468 : 0 : }
469 : :
470 : 0 : void ScAutoFmtPreview::CalcLineMap()
471 : : {
472 [ # # ]: 0 : if ( pCurData )
473 : : {
474 [ # # ]: 0 : for( size_t nRow = 0; nRow < 5; ++nRow )
475 : : {
476 [ # # ]: 0 : for( size_t nCol = 0; nCol < 5; ++nCol )
477 : : {
478 [ # # ]: 0 : svx::frame::Style aStyle;
479 : :
480 [ # # ]: 0 : const SvxBoxItem& rItem = GetBoxItem( nCol, nRow );
481 [ # # ]: 0 : lclSetStyleFromBorder( aStyle, rItem.GetLeft() );
482 [ # # ]: 0 : maArray.SetCellStyleLeft( nCol, nRow, aStyle );
483 [ # # ]: 0 : lclSetStyleFromBorder( aStyle, rItem.GetRight() );
484 [ # # ]: 0 : maArray.SetCellStyleRight( nCol, nRow, aStyle );
485 [ # # ]: 0 : lclSetStyleFromBorder( aStyle, rItem.GetTop() );
486 [ # # ]: 0 : maArray.SetCellStyleTop( nCol, nRow, aStyle );
487 [ # # ]: 0 : lclSetStyleFromBorder( aStyle, rItem.GetBottom() );
488 [ # # ]: 0 : maArray.SetCellStyleBottom( nCol, nRow, aStyle );
489 : :
490 [ # # ][ # # ]: 0 : lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, true ).GetLine() );
491 [ # # ]: 0 : maArray.SetCellStyleTLBR( nCol, nRow, aStyle );
492 [ # # ][ # # ]: 0 : lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, false ).GetLine() );
493 [ # # ]: 0 : maArray.SetCellStyleBLTR( nCol, nRow, aStyle );
494 : : }
495 : : }
496 : : }
497 : 0 : }
498 : :
499 : : //------------------------------------------------------------------------
500 : :
501 : 0 : void ScAutoFmtPreview::NotifyChange( ScAutoFormatData* pNewData )
502 : : {
503 [ # # ]: 0 : if ( pNewData != pCurData )
504 : : {
505 : 0 : pCurData = pNewData;
506 : 0 : bFitWidth = pNewData->GetIncludeWidthHeight();
507 : 0 : CalcCellArray( bFitWidth );
508 : 0 : CalcLineMap();
509 : : }
510 [ # # ]: 0 : else if ( bFitWidth != pNewData->GetIncludeWidthHeight() )
511 : : {
512 : 0 : bFitWidth = !bFitWidth;
513 : 0 : CalcCellArray( bFitWidth );
514 : : }
515 : :
516 [ # # ][ # # ]: 0 : DoPaint( Rectangle( Point(0,0), GetSizePixel() ) );
517 : 0 : }
518 : :
519 : : //------------------------------------------------------------------------
520 : :
521 : 0 : void ScAutoFmtPreview::DoPaint( const Rectangle& /* rRect */ )
522 : : {
523 : 0 : sal_uInt32 nOldDrawMode = aVD.GetDrawMode();
524 : :
525 [ # # ]: 0 : Size aWndSize( GetSizePixel() );
526 [ # # ]: 0 : Font aFont( aVD.GetFont() );
527 : 0 : Color aBackCol( GetSettings().GetStyleSettings().GetWindowColor() );
528 : 0 : Point aTmpPoint;
529 [ # # ]: 0 : Rectangle aRect( aTmpPoint, aWndSize );
530 : :
531 [ # # ]: 0 : aFont.SetTransparent( sal_True );
532 [ # # ]: 0 : aVD.SetFont( aFont );
533 [ # # ]: 0 : aVD.SetLineColor();
534 [ # # ]: 0 : aVD.SetFillColor( aBackCol );
535 [ # # ]: 0 : aVD.SetOutputSize( aWndSize );
536 [ # # ]: 0 : aVD.DrawRect( aRect );
537 : :
538 [ # # ]: 0 : PaintCells();
539 [ # # ]: 0 : SetLineColor();
540 [ # # ]: 0 : SetFillColor( aBackCol );
541 [ # # ]: 0 : DrawRect( aRect );
542 : :
543 : 0 : Point aPos( (aWndSize.Width() - aPrvSize.Width()) / 2, (aWndSize.Height() - aPrvSize.Height()) / 2 );
544 [ # # ][ # # ]: 0 : if (Application::GetSettings().GetLayoutRTL())
[ # # ]
545 : 0 : aPos.X() = -aPos.X();
546 [ # # ]: 0 : DrawOutDev( aPos, aWndSize, Point(), aWndSize, aVD );
547 : :
548 [ # # ][ # # ]: 0 : aVD.SetDrawMode( nOldDrawMode );
549 : 0 : }
550 : :
551 : : //------------------------------------------------------------------------
552 : :
553 : 0 : void ScAutoFmtPreview::Paint( const Rectangle& rRect )
554 : : {
555 : 0 : DoPaint( rRect );
556 : 0 : }
557 : :
558 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|