LCOV - code coverage report
Current view: top level - svx/source/dialog - pagectrl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 207 0.0 %
Date: 2014-04-11 Functions: 0 18 0.0 %
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 <vcl/bitmap.hxx>
      21             : #include <vcl/builder.hxx>
      22             : #include <vcl/settings.hxx>
      23             : #include <editeng/frmdiritem.hxx>
      24             : #include <svx/pageitem.hxx>
      25             : #include <svx/pagectrl.hxx>
      26             : #include <editeng/boxitem.hxx>
      27             : 
      28             : #include <algorithm>
      29             : 
      30             : // struct PageWindow_Impl ------------------------------------------------
      31             : 
      32           0 : struct PageWindow_Impl
      33             : {
      34             :     SvxBoxItem*     pBorder;
      35             :     Bitmap          aBitmap;
      36             :     bool            bBitmap;
      37             :     bool            bResetBackground;
      38             :     sal_Bool        bFrameDirection;
      39             :     sal_Int32       nFrameDirection;
      40             : 
      41             : 
      42           0 :     PageWindow_Impl() :
      43             :         pBorder(0),
      44             :         bBitmap(false),
      45             :         bResetBackground(false),
      46             :         bFrameDirection(sal_False),
      47           0 :         nFrameDirection(0) {}
      48             : 
      49           0 :     void        EnableFrameDirection(sal_Bool bEnable){bFrameDirection = bEnable;}
      50           0 :     void        SetFrameDirection(sal_Int32 nDirection){nFrameDirection = nDirection;}
      51             : 
      52             : };
      53             : 
      54             : // STATIC DATA -----------------------------------------------------------
      55             : 
      56             : #define CELL_WIDTH      1600L
      57             : #define CELL_HEIGHT      800L
      58             : 
      59             : // class SvxPageWindow ---------------------------------------------------
      60             : 
      61           0 : SvxPageWindow::SvxPageWindow( Window* pParent ) :
      62             : 
      63             :     Window( pParent ),
      64             : 
      65             :     nTop        ( 0 ),
      66             :     nBottom     ( 0 ),
      67             :     nLeft       ( 0 ),
      68             :     nRight      ( 0 ),
      69             :     aColor      ( COL_TRANSPARENT ),
      70             :     nHdLeft     ( 0 ),
      71             :     nHdRight    ( 0 ),
      72             :     nHdDist     ( 0 ),
      73             :     nHdHeight   ( 0 ),
      74             :     aHdColor    ( COL_TRANSPARENT ),
      75             :     pHdBorder   ( 0 ),
      76             :     nFtLeft     ( 0 ),
      77             :     nFtRight    ( 0 ),
      78             :     nFtDist     ( 0 ),
      79             :     nFtHeight   ( 0 ),
      80             :     aFtColor    ( COL_TRANSPARENT ),
      81             :     pFtBorder   ( 0 ),
      82             :     bFooter     ( false ),
      83             :     bHeader     ( false ),
      84             :     bTable      ( false ),
      85             :     bHorz       ( false ),
      86             :     bVert       ( false ),
      87           0 :     eUsage      ( SVX_PAGE_ALL )
      88             : {
      89           0 :     pImpl = new PageWindow_Impl;
      90             : 
      91             :     // Count in Twips by default
      92           0 :     SetMapMode( MapMode( MAP_TWIP ) );
      93           0 :     aWinSize = GetOptimalSize();
      94           0 :     aWinSize.Height() -= 4;
      95           0 :     aWinSize.Width() -= 4;
      96             : 
      97           0 :     aWinSize = PixelToLogic( aWinSize );
      98           0 :     SetBackground();
      99           0 : }
     100             : 
     101             : 
     102             : 
     103           0 : SvxPageWindow::~SvxPageWindow()
     104             : {
     105           0 :     delete pImpl;
     106           0 :     delete pHdBorder;
     107           0 :     delete pFtBorder;
     108           0 : }
     109             : 
     110           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxPageWindow(Window *pParent, VclBuilder::stringmap &)
     111             : {
     112           0 :     return new SvxPageWindow(pParent);
     113             : }
     114             : 
     115             : 
     116             : 
     117             : 
     118           0 : void SvxPageWindow::Paint( const Rectangle& )
     119             : {
     120           0 :     Fraction aXScale( aWinSize.Width(), std::max( (long) (aSize.Width() * 2 + aSize.Width() / 8), 1L ) );
     121           0 :     Fraction aYScale( aWinSize.Height(), std::max( aSize.Height(), 1L ) );
     122           0 :     MapMode aMapMode( GetMapMode() );
     123             : 
     124           0 :     if ( aYScale < aXScale )
     125             :     {
     126           0 :         aMapMode.SetScaleX( aYScale );
     127           0 :         aMapMode.SetScaleY( aYScale );
     128             :     }
     129             :     else
     130             :     {
     131           0 :         aMapMode.SetScaleX( aXScale );
     132           0 :         aMapMode.SetScaleY( aXScale );
     133             :     }
     134           0 :     SetMapMode( aMapMode );
     135           0 :     Size aSz( PixelToLogic( GetSizePixel() ) );
     136           0 :     long nYPos = ( aSz.Height() - aSize.Height() ) / 2;
     137             : 
     138           0 :     if ( eUsage == SVX_PAGE_ALL )
     139             :     {
     140             :         // all pages are equal -> draw one page
     141           0 :         if ( aSize.Width() > aSize.Height() )
     142             :         {
     143             :             // Draw Landscape page of the same size
     144           0 :             Fraction aX = aMapMode.GetScaleX();
     145           0 :             Fraction aY = aMapMode.GetScaleY();
     146           0 :             Fraction a2( 1.5 );
     147           0 :             aX *= a2;
     148           0 :             aY *= a2;
     149           0 :             aMapMode.SetScaleX( aX );
     150           0 :             aMapMode.SetScaleY( aY );
     151           0 :             SetMapMode( aMapMode );
     152           0 :             aSz = PixelToLogic( GetSizePixel() );
     153           0 :             nYPos = ( aSz.Height() - aSize.Height() ) / 2;
     154           0 :             long nXPos = ( aSz.Width() - aSize.Width() ) / 2;
     155           0 :             DrawPage( Point( nXPos, nYPos ), true, true );
     156             :         }
     157             :         else
     158             :             // Portrait
     159           0 :             DrawPage( Point( ( aSz.Width() - aSize.Width() ) / 2, nYPos ), true, true );
     160             :     }
     161             :     else
     162             :     {
     163             :         // Left and right page are different -> draw two pages if possible
     164           0 :         DrawPage( Point( 0, nYPos ), false, eUsage & SVX_PAGE_LEFT );
     165           0 :         DrawPage( Point( aSize.Width() + aSize.Width() / 8, nYPos ), true,
     166           0 :                   eUsage & SVX_PAGE_RIGHT );
     167           0 :     }
     168           0 : }
     169             : 
     170             : 
     171           0 : void SvxPageWindow::DrawPage( const Point& rOrg, const bool bSecond, const bool bEnabled )
     172             : {
     173           0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     174           0 :     const Color& rFieldColor = rStyleSettings.GetFieldColor();
     175           0 :     const Color& rFieldTextColor = rStyleSettings.GetFieldTextColor();
     176           0 :     const Color& rDisableColor = rStyleSettings.GetDisableColor();
     177           0 :     const Color& rDlgColor = rStyleSettings.GetDialogColor();
     178             : 
     179             :     // background
     180           0 :     if(!bSecond || pImpl->bResetBackground)
     181             :     {
     182           0 :         SetLineColor( Color(COL_TRANSPARENT) );
     183           0 :         SetFillColor( rDlgColor );
     184           0 :         Size winSize(GetOutputSize());
     185           0 :         DrawRect( Rectangle( Point(0,0), winSize ) );
     186             : 
     187           0 :         if ( pImpl->bResetBackground )
     188           0 :             pImpl->bResetBackground = false;
     189             :     }
     190           0 :     SetLineColor( rFieldTextColor );
     191             :     // Shadow
     192           0 :     Size aTempSize = aSize;
     193             :     // Page
     194           0 :     if ( !bEnabled )
     195             :     {
     196           0 :         SetFillColor( rDisableColor );
     197           0 :         DrawRect( Rectangle( rOrg, aTempSize ) );
     198           0 :         return;
     199             :     }
     200           0 :     SetFillColor( rFieldColor );
     201           0 :     DrawRect( Rectangle( rOrg, aTempSize ) );
     202             : 
     203           0 :     long nL = nLeft;
     204           0 :     long nR = nRight;
     205             : 
     206           0 :     if ( eUsage == SVX_PAGE_MIRROR && !bSecond )
     207             :     {
     208             :         // turn for mirrored
     209           0 :         nL = nRight;
     210           0 :         nR = nLeft;
     211             :     }
     212             : 
     213           0 :     Rectangle aRect;
     214             : 
     215           0 :     aRect.Left()  = rOrg.X() + nL;
     216           0 :     aRect.Right() = rOrg.X() + aTempSize.Width() - nR;
     217           0 :     aRect.Top()   = rOrg.Y() + nTop;
     218           0 :     aRect.Bottom()= rOrg.Y() + aTempSize.Height() - nBottom;
     219             : 
     220           0 :     Rectangle aHdRect( aRect );
     221           0 :     Rectangle aFtRect( aRect );
     222             : 
     223           0 :     if ( bHeader )
     224             :     {
     225             :         // show headers if possible
     226           0 :         aHdRect.Left() += nHdLeft;
     227           0 :         aHdRect.Right() -= nHdRight;
     228           0 :         aHdRect.Bottom() = aRect.Top() + nHdHeight;
     229           0 :         aRect.Top() += nHdHeight + nHdDist;
     230           0 :         SetFillColor( aHdColor );
     231           0 :         DrawRect( aHdRect );
     232             :     }
     233             : 
     234           0 :     if ( bFooter )
     235             :     {
     236             :         // show footer if possible
     237           0 :         aFtRect.Left() += nFtLeft;
     238           0 :         aFtRect.Right() -= nFtRight;
     239           0 :         aFtRect.Top() = aRect.Bottom() - nFtHeight;
     240           0 :         aRect.Bottom() -= nFtHeight + nFtDist;
     241           0 :         SetFillColor( aFtColor );
     242           0 :         DrawRect( aFtRect );
     243             :     }
     244             : 
     245             :     // Paint Body
     246           0 :     SetFillColor( aColor );
     247           0 :     if ( pImpl->bBitmap )
     248             :     {
     249           0 :         DrawRect( aRect );
     250           0 :         Point aBmpPnt = aRect.TopLeft();
     251           0 :         Size aBmpSiz = aRect.GetSize();
     252           0 :         long nDeltaX = aBmpSiz.Width() / 15;
     253           0 :         long nDeltaY = aBmpSiz.Height() / 15;
     254           0 :         aBmpPnt.X() += nDeltaX;
     255           0 :         aBmpPnt.Y() += nDeltaY;
     256           0 :         aBmpSiz.Width() -= nDeltaX * 2;
     257           0 :         aBmpSiz.Height() -= nDeltaY * 2;
     258           0 :         DrawBitmap( aBmpPnt, aBmpSiz, pImpl->aBitmap );
     259             :     }
     260             :     else
     261           0 :         DrawRect( aRect );
     262             : 
     263           0 :     if(pImpl->bFrameDirection && !bTable)
     264             :     {
     265           0 :         Point aPos;
     266           0 :         Font aFont(GetFont());
     267           0 :         const Size aSaveSize = aFont.GetSize();
     268           0 :         Size aDrawSize( 0, aRect.GetHeight() / 6);
     269           0 :         aFont.SetSize(aDrawSize);
     270           0 :         SetFont(aFont);
     271           0 :         OUString sText("ABC");
     272           0 :         Point aMove(1, GetTextHeight());
     273           0 :         sal_Unicode cArrow = 0x2193;
     274           0 :         long nAWidth = GetTextWidth(sText.copy(0,1));
     275           0 :         switch(pImpl->nFrameDirection)
     276             :         {
     277             :             case FRMDIR_HORI_LEFT_TOP:
     278           0 :                 aPos = aRect.TopLeft();
     279           0 :                 aPos.X() += PixelToLogic(Point(1,1)).X();
     280           0 :                 aMove.Y() = 0;
     281           0 :                 cArrow = 0x2192;
     282           0 :             break;
     283             :             case FRMDIR_HORI_RIGHT_TOP:
     284           0 :                 aPos = aRect.TopRight();
     285           0 :                 aPos.X() -= nAWidth;
     286           0 :                 aMove.Y() = 0;
     287           0 :                 aMove.X() *= -1;
     288           0 :                 cArrow = 0x2190;
     289           0 :             break;
     290             :             case FRMDIR_VERT_TOP_LEFT:
     291           0 :                 aPos = aRect.TopLeft();
     292           0 :                 aPos.X() += PixelToLogic(Point(1,1)).X();
     293           0 :                 aMove.X() = 0;
     294           0 :             break;
     295             :             case FRMDIR_VERT_TOP_RIGHT:
     296           0 :                 aPos = aRect.TopRight();
     297           0 :                 aPos.X() -= nAWidth;
     298           0 :                 aMove.X() = 0;
     299           0 :             break;
     300             :         }
     301           0 :         sText += OUString(cArrow);
     302           0 :         for(sal_uInt16 i = 0; i < sText.getLength(); i++)
     303             :         {
     304           0 :             OUString sDraw(sText.copy(i,1));
     305           0 :             long nHDiff = 0;
     306           0 :             long nCharWidth = GetTextWidth(sDraw);
     307           0 :             bool bHorizontal = 0 == aMove.Y();
     308           0 :             if(!bHorizontal)
     309             :             {
     310           0 :                 nHDiff = (nAWidth - nCharWidth)/2;
     311           0 :                 aPos.X() += nHDiff;
     312             :             }
     313           0 :             DrawText(aPos, sDraw);
     314           0 :             if(bHorizontal)
     315             :             {
     316           0 :                 aPos.X() += aMove.X() < 0 ? - nCharWidth : nCharWidth;
     317             :             }
     318             :             else
     319             :             {
     320           0 :                 aPos.X() -= nHDiff;
     321           0 :                 aPos.Y() += aMove.Y();
     322             :             }
     323           0 :         }
     324           0 :         aFont.SetSize(aSaveSize);
     325           0 :         SetFont(aFont);
     326             : 
     327             :     }
     328           0 :     if ( bTable )
     329             :     {
     330             :         // Paint Table, if necessary center it
     331           0 :         SetLineColor( Color(COL_LIGHTGRAY) );
     332             : 
     333           0 :         long nW = aRect.GetWidth(), nH = aRect.GetHeight();
     334           0 :         long nTW = CELL_WIDTH * 3, nTH = CELL_HEIGHT * 3;
     335           0 :         long _nLeft = bHorz ? aRect.Left() + ((nW - nTW) / 2) : aRect.Left();
     336           0 :         long _nTop = bVert ? aRect.Top() + ((nH - nTH) / 2) : aRect.Top();
     337           0 :         Rectangle aCellRect( Point( _nLeft, _nTop ), Size( CELL_WIDTH, CELL_HEIGHT ) );
     338             : 
     339           0 :         for ( sal_uInt16 i = 0; i < 3; ++i )
     340             :         {
     341           0 :             aCellRect.Left() = _nLeft;
     342           0 :             aCellRect.Right() = _nLeft + CELL_WIDTH;
     343           0 :             if ( i > 0 )
     344           0 :                 aCellRect.Move( 0, CELL_HEIGHT );
     345             : 
     346           0 :             for ( sal_uInt16 j = 0; j < 3; ++j )
     347             :             {
     348           0 :                 if ( j > 0 )
     349           0 :                     aCellRect.Move( CELL_WIDTH, 0 );
     350           0 :                 DrawRect( aCellRect );
     351             :             }
     352             :         }
     353             :     }
     354             : }
     355             : 
     356             : 
     357             : 
     358           0 : void SvxPageWindow::SetBorder( const SvxBoxItem& rNew )
     359             : {
     360           0 :     delete pImpl->pBorder;
     361           0 :     pImpl->pBorder = new SvxBoxItem( rNew );
     362           0 : }
     363             : 
     364             : 
     365             : 
     366           0 : void SvxPageWindow::SetBitmap( Bitmap* pBmp )
     367             : {
     368           0 :     if ( pBmp )
     369             :     {
     370           0 :         pImpl->aBitmap = *pBmp;
     371           0 :         pImpl->bBitmap = true;
     372             :     }
     373             :     else
     374           0 :         pImpl->bBitmap = false;
     375           0 : }
     376             : 
     377             : 
     378             : 
     379           0 : void SvxPageWindow::SetHdBorder( const SvxBoxItem& rNew )
     380             : {
     381           0 :     delete pHdBorder;
     382           0 :     pHdBorder = new SvxBoxItem( rNew );
     383           0 : }
     384             : 
     385             : 
     386           0 : void SvxPageWindow::SetFtBorder( const SvxBoxItem& rNew )
     387             : {
     388           0 :     delete pFtBorder;
     389           0 :     pFtBorder = new SvxBoxItem( rNew );
     390           0 : }
     391             : 
     392           0 : void  SvxPageWindow::EnableFrameDirection(bool bEnable)
     393             : {
     394           0 :     pImpl->EnableFrameDirection(bEnable);
     395           0 : }
     396             : 
     397           0 : void  SvxPageWindow::SetFrameDirection(sal_Int32 nFrameDirection)
     398             : {
     399           0 :     pImpl->SetFrameDirection(nFrameDirection);
     400           0 : }
     401             : 
     402           0 : void SvxPageWindow::ResetBackground()
     403             : {
     404           0 :     pImpl->bResetBackground = true;
     405           0 : }
     406             : 
     407           0 : Size SvxPageWindow::GetOptimalSize() const
     408             : {
     409           0 :     return LogicToPixel(Size(75, 46), MapMode(MAP_APPFONT));
     410             : }
     411             : 
     412             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10