LCOV - code coverage report
Current view: top level - sw/source/uibase/frmdlg - colex.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 317 0.3 %
Date: 2015-06-13 12:38:46 Functions: 2 16 12.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 "cmdid.h"
      21             : #include "hintids.hxx"
      22             : #include <algorithm>
      23             : #include <svl/eitem.hxx>
      24             : #include <tools/fract.hxx>
      25             : #include <editeng/lrspitem.hxx>
      26             : #include <editeng/ulspitem.hxx>
      27             : #include <editeng/sizeitem.hxx>
      28             : #include <svx/pageitem.hxx>
      29             : #include <editeng/brushitem.hxx>
      30             : #include <editeng/frmdiritem.hxx>
      31             : #include <vcl/bitmap.hxx>
      32             : #include <vcl/builder.hxx>
      33             : #include <vcl/graph.hxx>
      34             : #include <vcl/settings.hxx>
      35             : #include <vcl/builderfactory.hxx>
      36             : #include <tgrditem.hxx>
      37             : #include <viewopt.hxx>
      38             : #include "colex.hxx"
      39             : #include "colmgr.hxx"
      40             : 
      41             : //UUUU
      42             : #include <svx/unobrushitemhelper.hxx>
      43             : 
      44             : // Taking the updated values from the set
      45           0 : void SwPageExample::UpdateExample( const SfxItemSet& rSet )
      46             : {
      47           0 :     SfxItemPool* pPool = rSet.GetPool();
      48           0 :     sal_uInt16 nWhich = pPool->GetWhich( SID_ATTR_PAGE );
      49           0 :     if ( rSet.GetItemState( nWhich, false ) == SfxItemState::SET )
      50             :     {
      51             :         // alignment
      52           0 :         const SvxPageItem* pPage = static_cast<const SvxPageItem*>(&rSet.Get( nWhich ));
      53             : 
      54           0 :         if ( pPage )
      55           0 :             SetUsage( pPage->GetPageUsage() );
      56             :     }
      57             : 
      58           0 :     nWhich = pPool->GetWhich( SID_ATTR_PAGE_SIZE );
      59             : 
      60           0 :     if ( rSet.GetItemState( nWhich, false ) == SfxItemState::SET )
      61             :     {
      62             :         // orientation and size from PageItem
      63           0 :         const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>(rSet.Get( nWhich ));
      64           0 :         SetSize( rSize.GetSize() );
      65             :     }
      66           0 :     nWhich = RES_LR_SPACE;
      67           0 :     if ( rSet.GetItemState( nWhich, false ) == SfxItemState::SET )
      68             :     {
      69             :         // set left and right border
      70           0 :         const SvxLRSpaceItem& rLRSpace = static_cast<const SvxLRSpaceItem&>(rSet.Get( nWhich ));
      71             : 
      72           0 :         SetLeft( rLRSpace.GetLeft() );
      73           0 :         SetRight( rLRSpace.GetRight() );
      74             :     }
      75             :     else
      76             :     {
      77           0 :         SetLeft( 0 );
      78           0 :         SetRight( 0 );
      79             :     }
      80             : 
      81           0 :     nWhich = RES_UL_SPACE;
      82             : 
      83           0 :     if ( rSet.GetItemState( nWhich, false ) == SfxItemState::SET )
      84             :     {
      85             :         // set upper and lower border
      86           0 :         const SvxULSpaceItem& rULSpace = static_cast<const SvxULSpaceItem&>(rSet.Get( nWhich ));
      87             : 
      88           0 :         SetTop( rULSpace.GetUpper() );
      89           0 :         SetBottom( rULSpace.GetLower() );
      90             :     }
      91             :     else
      92             :     {
      93           0 :         SetTop( 0 );
      94           0 :         SetBottom( 0 );
      95             :     }
      96             : 
      97             :     // evaluate header-attributes
      98             :     const SfxPoolItem* pItem;
      99           0 :     if( SfxItemState::SET == rSet.GetItemState( pPool->GetWhich( SID_ATTR_PAGE_HEADERSET),
     100           0 :             false, &pItem ) )
     101             :     {
     102           0 :         const SfxItemSet& rHeaderSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet();
     103             :         const SfxBoolItem& rHeaderOn =
     104           0 :             static_cast<const SfxBoolItem&>(rHeaderSet.Get( pPool->GetWhich( SID_ATTR_PAGE_ON ) ) );
     105             : 
     106           0 :         if ( rHeaderOn.GetValue() )
     107             :         {
     108             :             const SvxSizeItem& rSize =
     109           0 :                 static_cast<const SvxSizeItem&>(rHeaderSet.Get(pPool->GetWhich(SID_ATTR_PAGE_SIZE)));
     110             : 
     111             :             const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>(rHeaderSet.Get(
     112           0 :                                         pPool->GetWhich(SID_ATTR_ULSPACE)));
     113             :             const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>(rHeaderSet.Get(
     114           0 :                                         pPool->GetWhich(SID_ATTR_LRSPACE)));
     115             : 
     116           0 :             SetHdHeight( rSize.GetSize().Height() - rUL.GetLower());
     117           0 :             SetHdDist( rUL.GetLower() );
     118           0 :             SetHdLeft( rLR.GetLeft() );
     119           0 :             SetHdRight( rLR.GetRight() );
     120           0 :             SetHeader( true );
     121             : 
     122           0 :             if(SfxItemState::SET == rHeaderSet.GetItemState(RES_BACKGROUND))
     123             :             {
     124             :                 //UUUU create FillAttributes from SvxBrushItem //SetHdColor(rItem.GetColor());
     125           0 :                 const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rHeaderSet.Get(RES_BACKGROUND));
     126           0 :                 SfxItemSet aTempSet(*rHeaderSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST);
     127             : 
     128           0 :                 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
     129             :                 setHeaderFillAttributes(
     130             :                     drawinglayer::attribute::SdrAllFillAttributesHelperPtr(
     131             :                         new drawinglayer::attribute::SdrAllFillAttributesHelper(
     132           0 :                             aTempSet)));
     133             :             }
     134             : 
     135           0 :             if ( rHeaderSet.GetItemState( RES_BOX ) == SfxItemState::SET )
     136             :             {
     137             :                 const SvxBoxItem& rItem =
     138           0 :                     static_cast<const SvxBoxItem&>(rHeaderSet.Get( RES_BOX ));
     139           0 :                 SetHdBorder( rItem );
     140             :             }
     141             :         }
     142             :         else
     143           0 :             SetHeader( false );
     144             :     }
     145             : 
     146           0 :     if( SfxItemState::SET == rSet.GetItemState( pPool->GetWhich( SID_ATTR_PAGE_FOOTERSET),
     147           0 :             false, &pItem ) )
     148             :     {
     149           0 :         const SfxItemSet& rFooterSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet();
     150             :         const SfxBoolItem& rFooterOn =
     151           0 :             static_cast<const SfxBoolItem&>(rFooterSet.Get( SID_ATTR_PAGE_ON ));
     152             : 
     153           0 :         if ( rFooterOn.GetValue() )
     154             :         {
     155             :             const SvxSizeItem& rSize =
     156           0 :                 static_cast<const SvxSizeItem&>(rFooterSet.Get( pPool->GetWhich( SID_ATTR_PAGE_SIZE ) ));
     157             : 
     158             :             const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>(rFooterSet.Get(
     159           0 :                                         pPool->GetWhich( SID_ATTR_ULSPACE ) ));
     160             :             const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>(rFooterSet.Get(
     161           0 :                                         pPool->GetWhich( SID_ATTR_LRSPACE ) ));
     162             : 
     163           0 :             SetFtHeight( rSize.GetSize().Height() - rUL.GetUpper());
     164           0 :             SetFtDist( rUL.GetUpper() );
     165           0 :             SetFtLeft( rLR.GetLeft() );
     166           0 :             SetFtRight( rLR.GetRight() );
     167           0 :             SetFooter( true );
     168             : 
     169           0 :             if( rFooterSet.GetItemState( RES_BACKGROUND ) == SfxItemState::SET )
     170             :             {
     171             :                 //UUUU create FillAttributes from SvxBrushItem //SetFtColor(rItem.GetColor());
     172           0 :                 const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rFooterSet.Get(RES_BACKGROUND));
     173           0 :                 SfxItemSet aTempSet(*rFooterSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST);
     174             : 
     175           0 :                 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
     176             :                 setFooterFillAttributes(
     177             :                     drawinglayer::attribute::SdrAllFillAttributesHelperPtr(
     178             :                         new drawinglayer::attribute::SdrAllFillAttributesHelper(
     179           0 :                             aTempSet)));
     180             :             }
     181             : 
     182           0 :             if( rFooterSet.GetItemState( RES_BOX ) == SfxItemState::SET )
     183             :             {
     184             :                 const SvxBoxItem& rItem =
     185           0 :                     static_cast<const SvxBoxItem&>(rFooterSet.Get( RES_BOX ));
     186           0 :                 SetFtBorder( rItem );
     187             :             }
     188             :         }
     189             :         else
     190           0 :             SetFooter( false );
     191             :     }
     192             : 
     193           0 :     if(SfxItemState::SET == rSet.GetItemState(RES_BACKGROUND, false, &pItem))
     194             :     {
     195             :         //UUUU create FillAttributes from SvxBrushItem
     196           0 :         const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(*pItem);
     197           0 :         SfxItemSet aTempSet(*rSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST);
     198             : 
     199           0 :         setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
     200             :         setPageFillAttributes(
     201             :             drawinglayer::attribute::SdrAllFillAttributesHelperPtr(
     202             :                 new drawinglayer::attribute::SdrAllFillAttributesHelper(
     203           0 :                     aTempSet)));
     204             :     }
     205             : 
     206           0 :     Invalidate();
     207           0 : }
     208             : 
     209           0 : void SwColExample::DrawPage(vcl::RenderContext& rRenderContext, const Point& rOrg,
     210             :                             const bool bSecond, const bool bEnabled)
     211             : {
     212           0 :     SwPageExample::DrawPage(rRenderContext, rOrg, bSecond, bEnabled);
     213             :     sal_uInt16 nColumnCount;
     214           0 :     if (pColMgr && 0 != (nColumnCount = pColMgr->GetCount()))
     215             :     {
     216           0 :         long nL = GetLeft();
     217           0 :         long nR = GetRight();
     218             : 
     219           0 :         if (GetUsage() == SVX_PAGE_MIRROR && !bSecond)
     220             :         {
     221             :             // rotate for mirrored
     222           0 :             nL = GetRight();
     223           0 :             nR = GetLeft();
     224             :         }
     225             : 
     226           0 :         rRenderContext.SetFillColor(Color(COL_LIGHTGRAY));
     227           0 :         Rectangle aRect;
     228           0 :         aRect.Right() = rOrg.X() + GetSize().Width() - nR;
     229           0 :         aRect.Left()  = rOrg.X() + nL;
     230           0 :         aRect.Top()   = rOrg.Y() + GetTop() + GetHdHeight() + GetHdDist();
     231           0 :         aRect.Bottom()= rOrg.Y() + GetSize().Height() - GetBottom() - GetFtHeight() - GetFtDist();
     232           0 :         rRenderContext.DrawRect(aRect);
     233             : 
     234             :         //UUUU
     235           0 :         const Rectangle aDefineRect(aRect);
     236             : 
     237             :         //UUUU
     238           0 :         const drawinglayer::attribute::SdrAllFillAttributesHelperPtr& rFillAttributes = getPageFillAttributes();
     239             : 
     240           0 :         if (!rFillAttributes.get() || !rFillAttributes->isUsed())
     241             :         {
     242             :             //UUUU If there is no fill, use fallback color
     243           0 :             const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
     244           0 :             const Color& rFieldColor = rStyleSettings.GetFieldColor();
     245             : 
     246             :             setPageFillAttributes(
     247             :                 drawinglayer::attribute::SdrAllFillAttributesHelperPtr(
     248           0 :                     new drawinglayer::attribute::SdrAllFillAttributesHelper(rFieldColor)));
     249             :         }
     250             : 
     251             :         // #97495# make sure that the automatic column width's are always equal
     252           0 :         bool bAutoWidth = pColMgr->IsAutoWidth();
     253           0 :         sal_Int32 nAutoColWidth = 0;
     254           0 :         if (bAutoWidth)
     255             :         {
     256           0 :             sal_Int32 nColumnWidthSum = 0;
     257             :             sal_uInt16 i;
     258           0 :             for (i = 0; i < nColumnCount; ++i)
     259           0 :                 nColumnWidthSum += pColMgr->GetColWidth( i );
     260           0 :             nAutoColWidth = nColumnWidthSum / nColumnCount;
     261             :         }
     262             : 
     263             :         sal_uInt16 i;
     264           0 :         for (i = 0; i < nColumnCount; i++)
     265             :         {
     266           0 :             if (!bAutoWidth)
     267           0 :                 nAutoColWidth = pColMgr->GetColWidth(i);
     268           0 :             aRect.Right() = aRect.Left() + nAutoColWidth;
     269             : 
     270             :             //UUUU use primitive draw command
     271           0 :             drawFillAttributes(rRenderContext, getPageFillAttributes(), aRect, aDefineRect);
     272             : 
     273           0 :             if (i < nColumnCount - 1)
     274           0 :                 aRect.Left() = aRect.Right() + pColMgr->GetGutterWidth(i);
     275             :         }
     276           0 :         if (pColMgr->HasLine())
     277             :         {
     278           0 :             Point aUp(rOrg.X() + nL, rOrg.Y() + GetTop());
     279           0 :             Point aDown(rOrg.X() + nL,
     280           0 :                         rOrg.Y() + GetSize().Height() - GetBottom() - GetFtHeight() - GetFtDist());
     281             : 
     282           0 :             if (pColMgr->GetLineHeightPercent() != 100)
     283             :             {
     284           0 :                 long nLength = aDown.Y() - aUp.Y();
     285           0 :                 nLength -= nLength * pColMgr->GetLineHeightPercent() / 100;
     286           0 :                 switch (pColMgr->GetAdjust())
     287             :                 {
     288           0 :                     case COLADJ_BOTTOM: aUp.Y() += nLength; break;
     289           0 :                     case COLADJ_TOP: aDown.Y() -= nLength; break;
     290             :                     case COLADJ_CENTER:
     291           0 :                         aUp.Y() += nLength / 2;
     292           0 :                         aDown.Y() -= nLength / 2;
     293           0 :                     break;
     294             :                     default:; // prevent warning
     295             :                 }
     296             :             }
     297             : 
     298           0 :             for (i = 0; i < nColumnCount -  1; i++)
     299             :             {
     300           0 :                 int nGutter = pColMgr->GetGutterWidth(i);
     301           0 :                 int nDist = pColMgr->GetColWidth( i ) + nGutter;
     302           0 :                 nDist -= (i == 0) ? nGutter / 2 : 0;
     303           0 :                 aUp.X() += nDist;
     304           0 :                 aDown.X() += nDist;
     305           0 :                 rRenderContext.DrawLine(aUp, aDown);
     306             :             }
     307             :         }
     308             :     }
     309           0 : }
     310             : 
     311           0 : VCL_BUILDER_FACTORY(SwColExample)
     312             : 
     313           0 : SwColumnOnlyExample::SwColumnOnlyExample(vcl::Window* pParent)
     314             :     : Window(pParent)
     315           0 :     , m_aFrmSize(1,1)
     316             : {
     317           0 :     SetMapMode( MapMode( MAP_TWIP ) );
     318           0 :     m_aWinSize = GetOptimalSize();
     319           0 :     m_aWinSize.Height() -= 4;
     320           0 :     m_aWinSize.Width() -= 4;
     321             : 
     322           0 :     m_aWinSize = PixelToLogic( m_aWinSize );
     323             : 
     324           0 :     SetBorderStyle( WindowBorderStyle::MONO );
     325             : 
     326           0 :     m_aFrmSize  = SvxPaperInfo::GetPaperSize(PAPER_A4);// DIN A4
     327           0 :     ::FitToActualSize(m_aCols, (sal_uInt16)m_aFrmSize.Width());
     328             : 
     329           0 :     long nHeight = m_aFrmSize.Height();
     330           0 :     Fraction aScale( m_aWinSize.Height(), nHeight );
     331           0 :     MapMode aMapMode( GetMapMode() );
     332           0 :     aMapMode.SetScaleX( aScale );
     333           0 :     aMapMode.SetScaleY( aScale );
     334           0 :     SetMapMode( aMapMode );
     335           0 : }
     336             : 
     337           0 : VCL_BUILDER_FACTORY(SwColumnOnlyExample)
     338             : 
     339           0 : void SwColumnOnlyExample::Paint(vcl::RenderContext& rRenderContext, const Rectangle& /*rRect*/)
     340             : {
     341           0 :     const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
     342           0 :     const Color& rFieldColor = rStyleSettings.GetFieldColor();
     343           0 :     const Color& rDlgColor = rStyleSettings.GetDialogColor();
     344           0 :     const Color& rFieldTextColor = SwViewOption::GetFontColor();
     345           0 :     Color aGrayColor(COL_LIGHTGRAY);
     346           0 :     if (rFieldColor == aGrayColor)
     347           0 :         aGrayColor.Invert();
     348             : 
     349           0 :     Size aLogSize(rRenderContext.PixelToLogic(rRenderContext.GetOutputSizePixel()));
     350           0 :     Rectangle aCompleteRect(Point(0,0), aLogSize);
     351           0 :     rRenderContext.SetLineColor(rDlgColor);
     352           0 :     rRenderContext.SetFillColor(rDlgColor);
     353           0 :     rRenderContext.DrawRect(aCompleteRect);
     354             : 
     355           0 :     rRenderContext.SetLineColor(rFieldTextColor);
     356           0 :     Point aTL((aLogSize.Width() - m_aFrmSize.Width()) / 2,
     357           0 :               (aLogSize.Height() - m_aFrmSize.Height()) / 2);
     358           0 :     Rectangle aRect(aTL, m_aFrmSize);
     359             : 
     360             :     //draw a shadow rectangle
     361           0 :     rRenderContext.SetFillColor(Color(COL_GRAY));
     362           0 :     Rectangle aShadowRect(aRect);
     363           0 :     aShadowRect.Move(aTL.Y(), aTL.Y());
     364           0 :     rRenderContext.DrawRect(aShadowRect);
     365             : 
     366           0 :     rRenderContext.SetFillColor(rFieldColor);
     367           0 :     rRenderContext.DrawRect(aRect);
     368             : 
     369           0 :     rRenderContext.SetFillColor(aGrayColor);
     370             : 
     371             :     //column separator?
     372           0 :     long nLength = aLogSize.Height() - 2 * aTL.Y();
     373           0 :     Point aUp(aTL);
     374           0 :     Point aDown(aTL.X(), nLength);
     375           0 :     bool bLines = false;
     376           0 :     if (m_aCols.GetLineAdj() != COLADJ_NONE)
     377             :     {
     378           0 :         bLines = true;
     379             : 
     380           0 :         sal_uInt16 nPercent = m_aCols.GetLineHeight();
     381           0 :         if (nPercent != 100)
     382             :         {
     383           0 :             nLength -= nLength * nPercent / 100;
     384           0 :             switch(m_aCols.GetLineAdj())
     385             :             {
     386           0 :                 case COLADJ_BOTTOM: aUp.Y() += nLength; break;
     387           0 :                 case COLADJ_TOP: aDown.Y() -= nLength; break;
     388             :                 case COLADJ_CENTER:
     389           0 :                         aUp.Y() += nLength / 2;
     390           0 :                         aDown.Y() -= nLength / 2;
     391           0 :                 break;
     392             :                 default:
     393           0 :                     break; //prevent warning
     394             :             }
     395             :         }
     396             : 
     397             :     }
     398           0 :     const SwColumns& rCols = m_aCols.GetColumns();
     399           0 :     sal_uInt16 nColCount = rCols.size();
     400           0 :     if (nColCount)
     401             :     {
     402           0 :         rRenderContext.DrawRect(aRect);
     403           0 :         rRenderContext.SetFillColor(rFieldColor);
     404           0 :         Rectangle aFrmRect(aTL, m_aFrmSize);
     405           0 :         long nSum = aTL.X();
     406           0 :         for (sal_uInt16 i = 0; i < nColCount; i++)
     407             :         {
     408           0 :             const SwColumn* pCol = &rCols[i];
     409           0 :             aFrmRect.Left() = nSum + pCol->GetLeft(); //nSum + pCol->GetLeft() + aTL.X();
     410           0 :             nSum += pCol->GetWishWidth();
     411           0 :             aFrmRect.Right() = nSum - pCol->GetRight();
     412           0 :             rRenderContext.DrawRect(aFrmRect);
     413             :         }
     414           0 :         if (bLines)
     415             :         {
     416           0 :             nSum = aTL.X();
     417           0 :             for (sal_uInt16 i = 0; i < nColCount - 1; i++)
     418             :             {
     419           0 :                 nSum += rCols[i].GetWishWidth();
     420           0 :                 aUp.X() = nSum;
     421           0 :                 aDown.X() = nSum;
     422           0 :                 rRenderContext.DrawLine(aUp, aDown);
     423             :             }
     424             :         }
     425             :     }
     426           0 : }
     427             : 
     428           0 : void  SwColumnOnlyExample::SetColumns(const SwFormatCol& rCol)
     429             : {
     430           0 :     m_aCols = rCol;
     431           0 :     sal_uInt16 nWishSum = m_aCols.GetWishWidth();
     432           0 :     long nFrmWidth = m_aFrmSize.Width();
     433           0 :     SwColumns& rCols = m_aCols.GetColumns();
     434           0 :     sal_uInt16 nColCount = rCols.size();
     435             : 
     436           0 :     for(sal_uInt16 i = 0; i < nColCount; i++)
     437             :     {
     438           0 :         SwColumn* pCol = &rCols[i];
     439           0 :         long nWish = pCol->GetWishWidth();
     440           0 :         nWish *= nFrmWidth;
     441           0 :         nWish /= nWishSum;
     442           0 :         pCol->SetWishWidth((sal_uInt16)nWish);
     443           0 :         long nLeft = pCol->GetLeft();
     444           0 :         nLeft *= nFrmWidth;
     445           0 :         nLeft /= nWishSum;
     446           0 :         pCol->SetLeft((sal_uInt16)nLeft);
     447           0 :         long nRight = pCol->GetRight();
     448           0 :         nRight *= nFrmWidth;
     449           0 :         nRight /= nWishSum;
     450           0 :         pCol->SetRight((sal_uInt16)nRight);
     451             :     }
     452             :     // #97495# make sure that the automatic column width's are always equal
     453           0 :     if(nColCount && m_aCols.IsOrtho())
     454             :     {
     455           0 :         sal_Int32 nColumnWidthSum = 0;
     456             :         sal_uInt16 i;
     457           0 :         for(i = 0; i < nColCount; ++i)
     458             :         {
     459           0 :             SwColumn* pCol = &rCols[i];
     460           0 :             nColumnWidthSum += pCol->GetWishWidth();
     461           0 :             nColumnWidthSum -= (pCol->GetRight() + pCol->GetLeft());
     462             :         }
     463           0 :         nColumnWidthSum /= nColCount;
     464           0 :         for(i = 0; i < nColCount; ++i)
     465             :         {
     466           0 :             SwColumn* pCol = &rCols[i];
     467           0 :             pCol->SetWishWidth( static_cast< sal_uInt16 >(nColumnWidthSum + pCol->GetRight() + pCol->GetLeft()));
     468             :         }
     469             :     }
     470           0 : }
     471             : 
     472           0 : Size SwColumnOnlyExample::GetOptimalSize() const
     473             : {
     474           0 :     return LogicToPixel(Size(75, 46), MapMode(MAP_APPFONT));
     475             : }
     476             : 
     477           0 : SwPageGridExample::~SwPageGridExample()
     478             : {
     479           0 :     disposeOnce();
     480           0 : }
     481             : 
     482           0 : void SwPageGridExample::dispose()
     483             : {
     484           0 :     delete pGridItem;
     485           0 :     SwPageExample::dispose();
     486           0 : }
     487             : 
     488           0 : void SwPageGridExample::DrawPage(vcl::RenderContext& rRenderContext, const Point& rOrg,
     489             :                                  const bool bSecond, const bool bEnabled)
     490             : {
     491           0 :     SwPageExample::DrawPage(rRenderContext, rOrg, bSecond, bEnabled);
     492             : 
     493           0 :     if (pGridItem && pGridItem->GetGridType())
     494             :     {
     495             :         //paint the grid now
     496           0 :         Color aLineColor = pGridItem->GetColor();
     497           0 :         if (aLineColor.GetColor() == COL_AUTO)
     498             :         {
     499           0 :             aLineColor = rRenderContext.GetFillColor();
     500           0 :             aLineColor.Invert();
     501             :         }
     502           0 :         rRenderContext.SetLineColor(aLineColor);
     503           0 :         long nL = GetLeft();
     504           0 :         long nR = GetRight();
     505             : 
     506           0 :         if (GetUsage() == SVX_PAGE_MIRROR && !bSecond)
     507             :         {
     508             :             // rotate for mirrored
     509           0 :             nL = GetRight();
     510           0 :             nR = GetLeft();
     511             :         }
     512             : 
     513           0 :         Rectangle aRect;
     514           0 :         aRect.Right() = rOrg.X() + GetSize().Width() - nR;
     515           0 :         aRect.Left()  = rOrg.X() + nL;
     516           0 :         aRect.Top()   = rOrg.Y() + GetTop() + GetHdHeight() + GetHdDist();
     517           0 :         aRect.Bottom()= rOrg.Y() + GetSize().Height() - GetBottom() - GetFtHeight() - GetFtDist();
     518             : 
     519             :         //increase the values to get a 'viewable' preview
     520           0 :         sal_Int32 nBaseHeight = pGridItem->GetBaseHeight() * 3;
     521           0 :         sal_Int32 nRubyHeight = pGridItem->GetRubyHeight() * 3;
     522             : 
     523             :         //detect height of rectangles
     524             :         Rectangle aRubyRect(aRect.TopLeft(),
     525             :                     m_bVertical ?
     526             :                     Size(nRubyHeight, aRect.GetHeight()) :
     527           0 :                     Size(aRect.GetWidth(), nRubyHeight));
     528             :         Rectangle aCharRect(aRect.TopLeft(),
     529             :                     m_bVertical ?
     530             :                     Size(nBaseHeight, aRect.GetHeight()) :
     531           0 :                     Size(aRect.GetWidth(), nBaseHeight));
     532             : 
     533           0 :         sal_Int32 nLineHeight = nBaseHeight + nRubyHeight;
     534             : 
     535             :         //detect count of rectangles
     536           0 :         sal_Int32 nLines = (m_bVertical ? aRect.GetWidth(): aRect.GetHeight()) / nLineHeight;
     537           0 :         if (nLines > pGridItem->GetLines())
     538           0 :             nLines = pGridItem->GetLines();
     539             : 
     540             :         // determine start position
     541           0 :         if (m_bVertical)
     542             :         {
     543           0 :             sal_Int16 nXStart = static_cast<sal_Int16>(aRect.GetWidth() / 2 - nLineHeight * nLines /2);
     544           0 :             aRubyRect.Move(nXStart, 0);
     545           0 :             aCharRect.Move(nXStart, 0);
     546             :         }
     547             :         else
     548             :         {
     549           0 :             sal_Int16 nYStart = static_cast<sal_Int16>(aRect.GetHeight() / 2 - nLineHeight * nLines /2);
     550           0 :             aRubyRect.Move(0, nYStart);
     551           0 :             aCharRect.Move(0, nYStart);
     552             :         }
     553             : 
     554           0 :         if (pGridItem->IsRubyTextBelow())
     555           0 :             m_bVertical ? aRubyRect.Move(nBaseHeight, 0) : aRubyRect.Move(0, nBaseHeight);
     556             :         else
     557           0 :             m_bVertical ? aCharRect.Move(nRubyHeight, 0) : aCharRect.Move(0, nRubyHeight);
     558             : 
     559             :         //vertical lines
     560           0 :         bool bBothLines = pGridItem->GetGridType() == GRID_LINES_CHARS;
     561           0 :         rRenderContext.SetFillColor(Color(COL_TRANSPARENT));
     562           0 :         sal_Int32 nXMove = m_bVertical ? nLineHeight : 0;
     563           0 :         sal_Int32 nYMove = m_bVertical ? 0 : nLineHeight;
     564           0 :         for (sal_Int32 nLine = 0; nLine < nLines; nLine++)
     565             :         {
     566           0 :             rRenderContext.DrawRect(aRubyRect);
     567           0 :             rRenderContext.DrawRect(aCharRect);
     568           0 :             if (bBothLines)
     569             :             {
     570           0 :                 Point aStart = aCharRect.TopLeft();
     571           0 :                 Point aEnd = m_bVertical ? aCharRect.TopRight() : aCharRect.BottomLeft();
     572           0 :                 while (m_bVertical ? aStart.Y() < aRect.Bottom(): aStart.X() < aRect.Right())
     573             :                 {
     574           0 :                     rRenderContext.DrawLine(aStart, aEnd);
     575           0 :                     if(m_bVertical)
     576           0 :                         aStart.Y() = aEnd.Y() += nBaseHeight;
     577             :                     else
     578           0 :                         aStart.X() = aEnd.X() += nBaseHeight;
     579             :                 }
     580             :             }
     581           0 :             aRubyRect.Move(nXMove, nYMove);
     582           0 :             aCharRect.Move(nXMove, nYMove);
     583             :         }
     584             :     }
     585           0 : }
     586             : 
     587           0 : void SwPageGridExample::UpdateExample( const SfxItemSet& rSet )
     588             : {
     589           0 :     DELETEZ(pGridItem);
     590             :     //get the grid information
     591           0 :     if(SfxItemState::DEFAULT <= rSet.GetItemState(RES_TEXTGRID, true))
     592           0 :         pGridItem = static_cast<SwTextGridItem*>(static_cast<const SwTextGridItem&>(rSet.Get(RES_TEXTGRID)).Clone());
     593           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( RES_FRAMEDIR, true ))
     594             :     {
     595             :         const SvxFrameDirectionItem& rDirItem =
     596           0 :                     static_cast<const SvxFrameDirectionItem&>(rSet.Get(RES_FRAMEDIR));
     597           0 :         m_bVertical = rDirItem.GetValue() == FRMDIR_VERT_TOP_RIGHT||
     598           0 :                     rDirItem.GetValue() == FRMDIR_VERT_TOP_LEFT;
     599             :     }
     600           0 :     SwPageExample::UpdateExample(rSet);
     601           0 : }
     602             : 
     603         177 : VCL_BUILDER_FACTORY(SwPageGridExample)
     604             : 
     605             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11