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

Generated by: LCOV version 1.10