LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/miscdlgs - autofmt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 261 0.4 %
Date: 2012-12-27 Functions: 2 21 9.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10