LCOV - code coverage report
Current view: top level - svx/source/dialog - swframeexample.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 338 0.0 %
Date: 2012-08-25 Functions: 0 11 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 393 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <tools/poly.hxx>
      30                 :            : #include <vcl/metric.hxx>
      31                 :            : #include <vcl/svapp.hxx>
      32                 :            : #include <svtools/colorcfg.hxx>
      33                 :            : #include <svx/swframeexample.hxx>
      34                 :            : #include <com/sun/star/text/TextContentAnchorType.hpp>
      35                 :            : #include <com/sun/star/text/HoriOrientation.hpp>
      36                 :            : #include <com/sun/star/text/VertOrientation.hpp>
      37                 :            : #include <com/sun/star/text/RelOrientation.hpp>
      38                 :            : #include <com/sun/star/text/WrapTextMode.hpp>
      39                 :            : 
      40                 :            : using namespace ::com::sun::star::text;
      41                 :            : 
      42                 :            : #define FLYINFLY_BORDER 3
      43                 :            : #define DEMOTEXT        "Ij"
      44                 :            : 
      45                 :          0 : SvxSwFrameExample::SvxSwFrameExample( Window *pParent, const ResId& rResID ) :
      46                 :            : 
      47                 :            :     Window(pParent, rResID),
      48                 :            : 
      49                 :            :     nHAlign     (HoriOrientation::CENTER),
      50                 :            :     nHRel       (RelOrientation::FRAME),
      51                 :            :     nVAlign     (VertOrientation::TOP),
      52                 :            :     nVRel       (RelOrientation::PRINT_AREA),
      53                 :            :     nWrap       (WrapTextMode_NONE),
      54                 :            :     nAnchor     (TextContentAnchorType_AT_PAGE),
      55                 :            :     bTrans      (sal_False),
      56 [ #  # ][ #  # ]:          0 :     aRelPos     (Point(0,0))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      57                 :            : {
      58         [ #  # ]:          0 :     InitColors_Impl();
      59 [ #  # ][ #  # ]:          0 :     SetMapMode(MAP_PIXEL);
                 [ #  # ]
      60                 :          0 : }
      61                 :            : 
      62                 :          0 : SvxSwFrameExample::~SvxSwFrameExample()
      63                 :            : {
      64         [ #  # ]:          0 : }
      65                 :            : 
      66                 :          0 : void SvxSwFrameExample::InitColors_Impl( void )
      67                 :            : {
      68                 :          0 :     const StyleSettings& rSettings = GetSettings().GetStyleSettings();
      69                 :          0 :     m_aBgCol = Color( rSettings.GetWindowColor() );
      70                 :            : 
      71                 :          0 :     sal_Bool bHC = rSettings.GetHighContrastMode();
      72                 :            : 
      73                 :          0 :     m_aFrameColor = Color( COL_LIGHTGREEN );
      74                 :          0 :     m_aAlignColor = Color( COL_LIGHTRED );
      75                 :          0 :     m_aTransColor = Color( COL_TRANSPARENT );
      76                 :            : 
      77                 :            :     m_aTxtCol = bHC?
      78 [ #  # ][ #  # ]:          0 :         svtools::ColorConfig().GetColorValue(svtools::FONTCOLOR).nColor :
                 [ #  # ]
      79 [ #  # ][ #  # ]:          0 :         Color( COL_GRAY );
         [ #  # ][ #  # ]
           [ #  #  #  #  
           #  # ][ #  # ]
      80 [ #  # ][ #  # ]:          0 :     m_aPrintAreaCol = bHC? m_aTxtCol : Color( COL_GRAY );
      81                 :          0 :     m_aBorderCol = m_aTxtCol;
      82 [ #  # ][ #  # ]:          0 :     m_aBlankCol = bHC? m_aTxtCol : Color( COL_LIGHTGRAY );
      83 [ #  # ][ #  # ]:          0 :     m_aBlankFrameCol = bHC? m_aTxtCol : Color( COL_GRAY );
      84                 :          0 : }
      85                 :            : 
      86                 :          0 : void SvxSwFrameExample::DataChanged( const DataChangedEvent& rDCEvt )
      87                 :            : {
      88                 :          0 :     Window::DataChanged( rDCEvt );
      89                 :            : 
      90 [ #  # ][ #  # ]:          0 :     if( rDCEvt.GetType() == DATACHANGED_SETTINGS && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
                 [ #  # ]
      91                 :          0 :         InitColors_Impl();
      92                 :          0 : }
      93                 :            : 
      94                 :          0 : void SvxSwFrameExample::InitAllRects_Impl()
      95                 :            : {
      96         [ #  # ]:          0 :     aPage.SetSize( GetOutputSizePixel() );
      97                 :            : 
      98                 :          0 :     sal_uIntPtr nOutWPix = aPage.GetWidth();
      99                 :          0 :     sal_uIntPtr nOutHPix = aPage.GetHeight();
     100                 :            : 
     101                 :            :     // PrintArea
     102                 :            :     sal_uIntPtr nLBorder;
     103                 :            :     sal_uIntPtr nRBorder;
     104                 :            :     sal_uIntPtr nTBorder;
     105                 :            :     sal_uIntPtr nBBorder;
     106                 :            : 
     107                 :            :     sal_uIntPtr nLTxtBorder;
     108                 :            :     sal_uIntPtr nRTxtBorder;
     109                 :            :     sal_uIntPtr nTTxtBorder;
     110                 :            :     sal_uIntPtr nBTxtBorder;
     111                 :            : 
     112         [ #  # ]:          0 :     if (nAnchor != TextContentAnchorType_AS_CHARACTER)
     113                 :            :     {
     114                 :          0 :         nLBorder = 14;
     115                 :          0 :         nRBorder = 10;
     116                 :          0 :         nTBorder = 10;
     117                 :          0 :         nBBorder = 15;
     118                 :            : 
     119                 :          0 :         nLTxtBorder = 8;
     120                 :          0 :         nRTxtBorder = 4;
     121                 :          0 :         nTTxtBorder = 2;
     122                 :          0 :         nBTxtBorder = 2;
     123                 :            :     }
     124                 :            :     else
     125                 :            :     {
     126                 :          0 :         nLBorder = 2;
     127                 :          0 :         nRBorder = 2;
     128                 :          0 :         nTBorder = 2;
     129                 :          0 :         nBBorder = 2;
     130                 :            : 
     131                 :          0 :         nLTxtBorder = 2;
     132                 :          0 :         nRTxtBorder = 2;
     133                 :          0 :         nTTxtBorder = 2;
     134                 :          0 :         nBTxtBorder = 2;
     135                 :            :     }
     136         [ #  # ]:          0 :     aPagePrtArea = Rectangle(Point(nLBorder, nTBorder), Point((nOutWPix - 1) - nRBorder, (nOutHPix - 1) - nBBorder));
     137                 :            : 
     138                 :            :     // Example text: Preparing for the text output
     139                 :            :     // A line of text
     140                 :          0 :     aTextLine = aPagePrtArea;
     141         [ #  # ]:          0 :     aTextLine.SetSize(Size(aTextLine.GetWidth(), 2));
     142                 :          0 :     aTextLine.Left()    += nLTxtBorder;
     143                 :          0 :     aTextLine.Right()   -= nRTxtBorder;
     144                 :          0 :     aTextLine.Move(0, nTTxtBorder);
     145                 :            : 
     146                 :            :     // Rectangle to edges including paragraph
     147                 :          0 :     sal_uInt16 nLines = (sal_uInt16)((aPagePrtArea.GetHeight() / 2 - nTTxtBorder - nBTxtBorder)
     148                 :          0 :              / (aTextLine.GetHeight() + 2));
     149                 :          0 :     aPara = aPagePrtArea;
     150                 :            :     aPara.SetSize(Size(aPara.GetWidth(),
     151         [ #  # ]:          0 :         (aTextLine.GetHeight() + 2) * nLines + nTTxtBorder + nBTxtBorder));
     152                 :            : 
     153                 :            :     // Rectangle around paragraph without borders
     154                 :          0 :     aParaPrtArea = aPara;
     155                 :          0 :     aParaPrtArea.Left()     += nLTxtBorder;
     156                 :          0 :     aParaPrtArea.Right()    -= nRTxtBorder;
     157                 :          0 :     aParaPrtArea.Top()      += nTTxtBorder;
     158                 :          0 :     aParaPrtArea.Bottom()   -= nBTxtBorder;
     159                 :            : 
     160 [ #  # ][ #  # ]:          0 :     if (nAnchor == TextContentAnchorType_AS_CHARACTER || nAnchor == TextContentAnchorType_AT_CHARACTER)
     161                 :            :     {
     162                 :            :         Font aFont = OutputDevice::GetDefaultFont(
     163 [ #  # ][ #  # ]:          0 :                                 DEFAULTFONT_LATIN_TEXT, Application::GetSettings().GetLanguage(),
     164         [ #  # ]:          0 :                                 DEFAULTFONT_FLAGS_ONLYONE, this );
     165         [ #  # ]:          0 :         aFont.SetColor( m_aTxtCol );
     166         [ #  # ]:          0 :         aFont.SetFillColor( m_aBgCol );
     167         [ #  # ]:          0 :         aFont.SetWeight(WEIGHT_NORMAL);
     168                 :            : 
     169         [ #  # ]:          0 :         if (nAnchor == TextContentAnchorType_AS_CHARACTER)
     170                 :            :         {
     171 [ #  # ][ #  # ]:          0 :             aFont.SetSize(Size(0, aParaPrtArea.GetHeight() - 2));
     172         [ #  # ]:          0 :             SetFont(aFont);
     173 [ #  # ][ #  # ]:          0 :             aParaPrtArea.SetSize(Size(GetTextWidth(rtl::OUString(DEMOTEXT)), GetTextHeight()));
         [ #  # ][ #  # ]
                 [ #  # ]
     174                 :            :         }
     175                 :            :         else
     176                 :            :         {
     177 [ #  # ][ #  # ]:          0 :             aFont.SetSize(Size(0, aParaPrtArea.GetHeight() / 2));
     178         [ #  # ]:          0 :             SetFont(aFont);
     179 [ #  # ][ #  # ]:          0 :             aAutoCharFrame.SetSize(Size(GetTextWidth(rtl::OUString('A')), GetTextHeight()));
         [ #  # ][ #  # ]
                 [ #  # ]
     180 [ #  # ][ #  # ]:          0 :             aAutoCharFrame.SetPos(Point(aParaPrtArea.Left() + (aParaPrtArea.GetWidth() - aAutoCharFrame.GetWidth()) / 2,
     181 [ #  # ][ #  # ]:          0 :                 aParaPrtArea.Top() + (aParaPrtArea.GetHeight() - aAutoCharFrame.GetHeight()) / 2));
     182         [ #  # ]:          0 :         }
     183                 :            :     }
     184                 :            : 
     185                 :            :     // Inner Frame anchored at the Frame
     186                 :          0 :     aFrameAtFrame = aPara;
     187                 :          0 :     aFrameAtFrame.Left() += 9;
     188                 :          0 :     aFrameAtFrame.Right() -= 5;
     189                 :          0 :     aFrameAtFrame.Bottom() += 5;
     190                 :          0 :     aFrameAtFrame.SetPos(Point(aFrameAtFrame.Left() + 2, (aPagePrtArea.Bottom() - aFrameAtFrame.GetHeight()) / 2 + 5));
     191                 :            : 
     192                 :            :     // Size of the frame to be positioned
     193         [ #  # ]:          0 :     if (nAnchor != TextContentAnchorType_AS_CHARACTER)
     194                 :            :     {
     195         [ #  # ]:          0 :         sal_uIntPtr nLFBorder = nAnchor == TextContentAnchorType_AT_PAGE ? nLBorder : nLTxtBorder;
     196         [ #  # ]:          0 :         sal_uIntPtr nRFBorder = nAnchor == TextContentAnchorType_AT_PAGE ? nRBorder : nRTxtBorder;
     197                 :            : 
     198      [ #  #  # ]:          0 :         switch (nHRel)
     199                 :            :         {
     200                 :            :             case RelOrientation::PAGE_LEFT:
     201                 :            :             case RelOrientation::FRAME_LEFT:
     202                 :          0 :                 aFrmSize = Size(nLFBorder - 4, (aTextLine.GetHeight() + 2) * 3);
     203                 :          0 :                 break;
     204                 :            : 
     205                 :            :             case RelOrientation::PAGE_RIGHT:
     206                 :            :             case RelOrientation::FRAME_RIGHT:
     207                 :          0 :                 aFrmSize = Size(nRFBorder - 4, (aTextLine.GetHeight() + 2) * 3);
     208                 :          0 :                 break;
     209                 :            : 
     210                 :            :             default:
     211                 :          0 :                 aFrmSize = Size(nLBorder - 3, (aTextLine.GetHeight() + 2) * 3);
     212                 :          0 :                 break;
     213                 :            :         }
     214                 :          0 :         aFrmSize.Width() = Max(5L, aFrmSize.Width());
     215                 :          0 :         aFrmSize.Height() = Max(5L, aFrmSize.Height());
     216                 :            :     }
     217                 :            :     else
     218                 :            :     {
     219 [ #  # ][ #  # ]:          0 :         sal_uIntPtr nFreeWidth = aPagePrtArea.GetWidth() - GetTextWidth(rtl::OUString(DEMOTEXT));
                 [ #  # ]
     220                 :            : 
     221                 :          0 :         aFrmSize = Size(nFreeWidth / 2, (aTextLine.GetHeight() + 2) * 3);
     222         [ #  # ]:          0 :         aDrawObj.SetSize(Size(Max(5L, (long)nFreeWidth / 3L), Max(5L, aFrmSize.Height() * 3L)));
     223                 :          0 :         aDrawObj.SetPos(Point(aParaPrtArea.Right() + 1, aParaPrtArea.Bottom() / 2));
     224                 :          0 :         aParaPrtArea.Right() = aDrawObj.Right();
     225                 :            :     }
     226                 :          0 : }
     227                 :            : 
     228                 :          0 : void SvxSwFrameExample::CalcBoundRect_Impl(Rectangle &rRect)
     229                 :            : {
     230   [ #  #  #  #  :          0 :     switch (nAnchor)
                      # ]
     231                 :            :     {
     232                 :            :         case TextContentAnchorType_AT_PAGE:
     233                 :            :         {
     234   [ #  #  #  #  :          0 :             switch (nHRel)
                      # ]
     235                 :            :             {
     236                 :            :                 case RelOrientation::FRAME:
     237                 :            :                 case RelOrientation::PAGE_FRAME:
     238                 :          0 :                     rRect.Left() = aPage.Left();
     239                 :          0 :                     rRect.Right() = aPage.Right();
     240                 :          0 :                     break;
     241                 :            : 
     242                 :            :                 case RelOrientation::PRINT_AREA:
     243                 :            :                 case RelOrientation::PAGE_PRINT_AREA:
     244                 :          0 :                     rRect.Left() = aPagePrtArea.Left();
     245                 :          0 :                     rRect.Right() = aPagePrtArea.Right();
     246                 :          0 :                     break;
     247                 :            : 
     248                 :            :                 case RelOrientation::PAGE_LEFT:
     249                 :          0 :                     rRect.Left() = aPage.Left();
     250                 :          0 :                     rRect.Right() = aPagePrtArea.Left();
     251                 :          0 :                     break;
     252                 :            : 
     253                 :            :                 case RelOrientation::PAGE_RIGHT:
     254                 :          0 :                     rRect.Left() = aPagePrtArea.Right();
     255                 :          0 :                     rRect.Right() = aPage.Right();
     256                 :          0 :                     break;
     257                 :            :             }
     258                 :            : 
     259      [ #  #  # ]:          0 :             switch (nVRel)
     260                 :            :             {
     261                 :            :                 case RelOrientation::PRINT_AREA:
     262                 :            :                 case RelOrientation::PAGE_PRINT_AREA:
     263                 :          0 :                     rRect.Top() = aPagePrtArea.Top();
     264                 :          0 :                     rRect.Bottom() = aPagePrtArea.Bottom();
     265                 :          0 :                     break;
     266                 :            : 
     267                 :            :                 case RelOrientation::FRAME:
     268                 :            :                 case RelOrientation::PAGE_FRAME:
     269                 :          0 :                     rRect.Top() = aPage.Top();
     270                 :          0 :                     rRect.Bottom() = aPage.Bottom();
     271                 :          0 :                     break;
     272                 :            :             }
     273                 :            :         }
     274                 :          0 :         break;
     275                 :            : 
     276                 :            :         case TextContentAnchorType_AT_FRAME:
     277                 :            :         {
     278   [ #  #  #  #  :          0 :             switch (nHRel)
                      # ]
     279                 :            :             {
     280                 :            :                 case RelOrientation::FRAME:
     281                 :            :                 case RelOrientation::PAGE_FRAME:
     282                 :          0 :                     rRect.Left() = aFrameAtFrame.Left();
     283                 :          0 :                     rRect.Right() = aFrameAtFrame.Right();
     284                 :          0 :                     break;
     285                 :            : 
     286                 :            :                 case RelOrientation::PRINT_AREA:
     287                 :            :                 case RelOrientation::PAGE_PRINT_AREA:
     288                 :          0 :                     rRect.Left() = aFrameAtFrame.Left() + FLYINFLY_BORDER;
     289                 :          0 :                     rRect.Right() = aFrameAtFrame.Right() - FLYINFLY_BORDER;
     290                 :          0 :                     break;
     291                 :            : 
     292                 :            :                 case RelOrientation::PAGE_RIGHT:
     293                 :          0 :                     rRect.Left() = aFrameAtFrame.Left();
     294                 :          0 :                     rRect.Right() = aFrameAtFrame.Left() + FLYINFLY_BORDER;
     295                 :          0 :                     break;
     296                 :            : 
     297                 :            :                 case RelOrientation::PAGE_LEFT:
     298                 :          0 :                     rRect.Left() = aFrameAtFrame.Right();
     299                 :          0 :                     rRect.Right() = aFrameAtFrame.Right() - FLYINFLY_BORDER;
     300                 :          0 :                     break;
     301                 :            :             }
     302                 :            : 
     303      [ #  #  # ]:          0 :             switch (nVRel)
     304                 :            :             {
     305                 :            :                 case RelOrientation::FRAME:
     306                 :            :                 case RelOrientation::PAGE_FRAME:
     307                 :          0 :                     rRect.Top() = aFrameAtFrame.Top();
     308                 :          0 :                     rRect.Bottom() = aFrameAtFrame.Bottom();
     309                 :          0 :                     break;
     310                 :            : 
     311                 :            :                 case RelOrientation::PRINT_AREA:
     312                 :            :                 case RelOrientation::PAGE_PRINT_AREA:
     313                 :          0 :                     rRect.Top() = aFrameAtFrame.Top() + FLYINFLY_BORDER;
     314                 :          0 :                     rRect.Bottom() = aFrameAtFrame.Bottom() - FLYINFLY_BORDER;
     315                 :          0 :                     break;
     316                 :            :             }
     317                 :            :         }
     318                 :          0 :         break;
     319                 :            :         case TextContentAnchorType_AT_PARAGRAPH:
     320                 :            :         case TextContentAnchorType_AT_CHARACTER:
     321                 :            :         {
     322   [ #  #  #  #  :          0 :             switch (nHRel)
          #  #  #  #  #  
                      # ]
     323                 :            :             {
     324                 :            :                 case RelOrientation::FRAME:
     325                 :          0 :                     rRect.Left() = aPara.Left();
     326                 :          0 :                     rRect.Right() = aPara.Right();
     327                 :          0 :                     break;
     328                 :            : 
     329                 :            :                 case RelOrientation::PRINT_AREA:
     330                 :          0 :                     rRect.Left() = aParaPrtArea.Left();
     331                 :          0 :                     rRect.Right() = aParaPrtArea.Right();
     332                 :          0 :                     break;
     333                 :            : 
     334                 :            :                 case RelOrientation::PAGE_LEFT:
     335                 :          0 :                     rRect.Left() = aPage.Left();
     336                 :          0 :                     rRect.Right() = aPagePrtArea.Left();
     337                 :          0 :                     break;
     338                 :            : 
     339                 :            :                 case RelOrientation::PAGE_RIGHT:
     340                 :          0 :                     rRect.Left() = aPagePrtArea.Right();
     341                 :          0 :                     rRect.Right() = aPage.Right();
     342                 :          0 :                     break;
     343                 :            : 
     344                 :            :                 case RelOrientation::PAGE_FRAME:
     345                 :          0 :                     rRect.Left() = aPage.Left();
     346                 :          0 :                     rRect.Right() = aPage.Right();
     347                 :          0 :                     break;
     348                 :            : 
     349                 :            :                 case RelOrientation::PAGE_PRINT_AREA:
     350                 :          0 :                     rRect.Left() = aPagePrtArea.Left();
     351                 :          0 :                     rRect.Right() = aPagePrtArea.Right();
     352                 :          0 :                     break;
     353                 :            : 
     354                 :            :                 case RelOrientation::FRAME_LEFT:
     355                 :          0 :                     rRect.Left() = aPara.Left();
     356                 :          0 :                     rRect.Right() = aParaPrtArea.Left();
     357                 :          0 :                     break;
     358                 :            : 
     359                 :            :                 case RelOrientation::FRAME_RIGHT:
     360                 :          0 :                     rRect.Left() = aParaPrtArea.Right();
     361                 :          0 :                     rRect.Right() = aPara.Right();
     362                 :          0 :                     break;
     363                 :            : 
     364                 :            :                 case RelOrientation::CHAR:
     365                 :          0 :                     rRect.Left() = aAutoCharFrame.Left();
     366                 :          0 :                     rRect.Right() = aAutoCharFrame.Left();
     367                 :          0 :                     break;
     368                 :            :             }
     369                 :            : 
     370   [ #  #  #  #  :          0 :             switch (nVRel)
                      # ]
     371                 :            :             {
     372                 :            :                 case RelOrientation::FRAME:
     373                 :          0 :                     rRect.Top() = aPara.Top();
     374                 :          0 :                     rRect.Bottom() = aPara.Bottom();
     375                 :          0 :                     break;
     376                 :            : 
     377                 :            :                 case RelOrientation::PRINT_AREA:
     378                 :          0 :                     rRect.Top() = aParaPrtArea.Top();
     379                 :          0 :                     rRect.Bottom() = aParaPrtArea.Bottom();
     380                 :          0 :                     break;
     381                 :            : 
     382                 :            :                 case RelOrientation::CHAR:
     383 [ #  # ][ #  # ]:          0 :                     if (nVAlign != VertOrientation::NONE &&
     384                 :            :                                 nVAlign != VertOrientation::CHAR_BOTTOM)
     385                 :          0 :                         rRect.Top() = aAutoCharFrame.Top();
     386                 :            :                     else
     387                 :          0 :                         rRect.Top() = aAutoCharFrame.Bottom();
     388                 :          0 :                     rRect.Bottom() = aAutoCharFrame.Bottom();
     389                 :          0 :                     break;
     390                 :            :                 // OD 12.11.2003 #i22341#
     391                 :            :                 case RelOrientation::TEXT_LINE:
     392                 :          0 :                     rRect.Top() = aAutoCharFrame.Top();
     393                 :          0 :                     rRect.Bottom() = aAutoCharFrame.Top();
     394                 :          0 :                 break;
     395                 :            :             }
     396                 :            :         }
     397                 :          0 :         break;
     398                 :            : 
     399                 :            :         case TextContentAnchorType_AS_CHARACTER:
     400                 :          0 :             rRect.Left() = aParaPrtArea.Left();
     401                 :          0 :             rRect.Right() = aParaPrtArea.Right();
     402                 :            : 
     403      [ #  #  # ]:          0 :             switch (nVAlign)
     404                 :            :             {
     405                 :            :                 case VertOrientation::NONE:
     406                 :            :                 case VertOrientation::TOP:
     407                 :            :                 case VertOrientation::CENTER:
     408                 :            :                 case VertOrientation::BOTTOM:
     409                 :            :                 {
     410         [ #  # ]:          0 :                     FontMetric aMetric(GetFontMetric());
     411                 :            : 
     412         [ #  # ]:          0 :                     rRect.Top() = aParaPrtArea.Bottom() - aMetric.GetDescent();
     413         [ #  # ]:          0 :                     rRect.Bottom() = rRect.Top();
     414                 :            :                 }
     415                 :          0 :                 break;
     416                 :            : 
     417                 :            :                 default:
     418                 :            : 
     419                 :            :                 case VertOrientation::LINE_TOP:
     420                 :            :                 case VertOrientation::LINE_CENTER:
     421                 :            :                 case VertOrientation::LINE_BOTTOM:
     422                 :          0 :                     rRect.Top() = aParaPrtArea.Top();
     423                 :          0 :                     rRect.Bottom() = aDrawObj.Bottom();
     424                 :          0 :                     break;
     425                 :            : 
     426                 :            :                 case VertOrientation::CHAR_TOP:
     427                 :            :                 case VertOrientation::CHAR_CENTER:
     428                 :            :                 case VertOrientation::CHAR_BOTTOM:
     429                 :          0 :                     rRect.Top() = aParaPrtArea.Top();
     430                 :          0 :                     rRect.Bottom() = aParaPrtArea.Bottom();
     431                 :          0 :                     break;
     432                 :            :             }
     433                 :          0 :             break;
     434                 :            : 
     435                 :            :         default:
     436                 :          0 :             break;
     437                 :            :     }
     438                 :          0 : }
     439                 :            : 
     440                 :          0 : Rectangle SvxSwFrameExample::DrawInnerFrame_Impl(const Rectangle &rRect, const Color &rFillColor, const Color &rBorderColor)
     441                 :            : {
     442                 :          0 :     DrawRect_Impl(rRect, rFillColor, rBorderColor);
     443                 :            : 
     444                 :            :     // Bereich, zu dem relativ positioniert wird, bestimmen
     445                 :          0 :     Rectangle aRect(rRect); // aPagePrtArea = Default
     446                 :          0 :     CalcBoundRect_Impl(aRect);
     447                 :            : 
     448 [ #  # ][ #  # ]:          0 :     if (nAnchor == TextContentAnchorType_AT_FRAME && &rRect == &aPagePrtArea)
     449                 :            :     {
     450                 :            :         // Testabsatz zeichnen
     451                 :          0 :         Rectangle aTxt(aTextLine);
     452         [ #  # ]:          0 :         sal_Int32 nStep = aTxt.GetHeight() + 2;
     453 [ #  # ][ #  # ]:          0 :         sal_uInt16 nLines = (sal_uInt16)(aParaPrtArea.GetHeight() / (aTextLine.GetHeight() + 2));
     454                 :            : 
     455         [ #  # ]:          0 :         for (sal_uInt16 i = 0; i < nLines; i++)
     456                 :            :         {
     457         [ #  # ]:          0 :             if (i == nLines - 1)
     458 [ #  # ][ #  # ]:          0 :                 aTxt.SetSize(Size(aTxt.GetWidth() / 2, aTxt.GetHeight()));
                 [ #  # ]
     459         [ #  # ]:          0 :             DrawRect_Impl(aTxt, m_aTxtCol, m_aTransColor);
     460         [ #  # ]:          0 :             aTxt.Move(0, nStep);
     461                 :            :         }
     462                 :            :     }
     463                 :            : 
     464                 :          0 :     return aRect;
     465                 :            : }
     466                 :            : 
     467                 :          0 : void SvxSwFrameExample::Paint(const Rectangle&)
     468                 :            : {
     469         [ #  # ]:          0 :     InitAllRects_Impl();
     470                 :            : 
     471                 :            :     // Draw page
     472         [ #  # ]:          0 :     DrawRect_Impl( aPage, m_aBgCol, m_aBorderCol );
     473                 :            : 
     474                 :            :     // Draw PrintArea
     475         [ #  # ]:          0 :     Rectangle aRect = DrawInnerFrame_Impl( aPagePrtArea, m_aTransColor, m_aPrintAreaCol );
     476                 :            : 
     477         [ #  # ]:          0 :     if (nAnchor == TextContentAnchorType_AT_FRAME)
     478         [ #  # ]:          0 :         aRect = DrawInnerFrame_Impl( aFrameAtFrame, m_aBgCol, m_aBorderCol );
     479                 :            : 
     480                 :          0 :     long lXPos    = 0;
     481                 :          0 :     long lYPos    = 0;
     482                 :            : 
     483                 :            :     // Horizontal alignment
     484         [ #  # ]:          0 :     if (nAnchor != TextContentAnchorType_AS_CHARACTER)
     485                 :            :     {
     486   [ #  #  #  # ]:          0 :         switch (nHAlign)
     487                 :            :         {
     488                 :            :             case HoriOrientation::RIGHT:
     489                 :            :             {
     490                 :          0 :                 lXPos = aRect.Right() - aFrmSize.Width() + 1;
     491                 :          0 :                 break;
     492                 :            :             }
     493                 :            :             case HoriOrientation::CENTER:
     494                 :            :             {
     495         [ #  # ]:          0 :                 lXPos = aRect.Left() + (aRect.GetWidth() - aFrmSize.Width()) / 2;
     496                 :          0 :                 break;
     497                 :            :             }
     498                 :            :             case HoriOrientation::NONE:
     499                 :            :             {
     500                 :          0 :                 lXPos = aRect.Left() + aRelPos.X();
     501                 :          0 :                 break;
     502                 :            :             }
     503                 :            : 
     504                 :            :             default: // HoriOrientation::LEFT
     505                 :          0 :                 lXPos = aRect.Left();
     506                 :          0 :                 break;
     507                 :            :         }
     508                 :            :     }
     509                 :            :     else
     510                 :          0 :        lXPos = aRect.Right() + 2;
     511                 :            : 
     512                 :            :     // Vertical Alignment
     513         [ #  # ]:          0 :     if (nAnchor != TextContentAnchorType_AS_CHARACTER)
     514                 :            :     {
     515   [ #  #  #  # ]:          0 :         switch (nVAlign)
     516                 :            :         {
     517                 :            :             case VertOrientation::BOTTOM:
     518                 :            :             case VertOrientation::LINE_BOTTOM:
     519                 :            :             {
     520                 :            :                 // #i22341#
     521         [ #  # ]:          0 :                 if ( nVRel != RelOrientation::TEXT_LINE )
     522                 :            :                 {
     523                 :          0 :                     lYPos = aRect.Bottom() - aFrmSize.Height() + 1;
     524                 :            :                 }
     525                 :            :                 else
     526                 :            :                 {
     527                 :          0 :                     lYPos = aRect.Top();
     528                 :            :                 }
     529                 :          0 :                 break;
     530                 :            :             }
     531                 :            :             case VertOrientation::CENTER:
     532                 :            :             case VertOrientation::LINE_CENTER:
     533                 :            :             {
     534         [ #  # ]:          0 :                 lYPos = aRect.Top() + (aRect.GetHeight() - aFrmSize.Height()) / 2;
     535                 :          0 :                 break;
     536                 :            :             }
     537                 :            :             case VertOrientation::NONE:
     538                 :            :             {
     539                 :            :                 // #i22341#
     540 [ #  # ][ #  # ]:          0 :                 if ( nVRel != RelOrientation::CHAR && nVRel != RelOrientation::TEXT_LINE )
     541                 :          0 :                     lYPos = aRect.Top() + aRelPos.Y();
     542                 :            :                 else
     543                 :          0 :                     lYPos = aRect.Top() - aRelPos.Y();
     544                 :          0 :                 break;
     545                 :            :             }
     546                 :            :             default:
     547                 :            :                 // #i22341#
     548         [ #  # ]:          0 :                 if ( nVRel != RelOrientation::TEXT_LINE )
     549                 :            :                 {
     550                 :          0 :                     lYPos = aRect.Top();
     551                 :            :                 }
     552                 :            :                 else
     553                 :            :                 {
     554                 :          0 :                     lYPos = aRect.Bottom() - aFrmSize.Height() + 1;
     555                 :            :                 }
     556                 :          0 :                 break;
     557                 :            :         }
     558                 :            :     }
     559                 :            :     else
     560                 :            :     {
     561      [ #  #  # ]:          0 :         switch(nVAlign)
     562                 :            :         {
     563                 :            :             case VertOrientation::CENTER:
     564                 :            :             case VertOrientation::CHAR_CENTER:
     565                 :            :             case VertOrientation::LINE_CENTER:
     566         [ #  # ]:          0 :                 lYPos = aRect.Top() + (aRect.GetHeight() - aFrmSize.Height()) / 2;
     567                 :          0 :                 break;
     568                 :            : 
     569                 :            :             case VertOrientation::TOP:
     570                 :            :             case VertOrientation::CHAR_BOTTOM:
     571                 :            :             case VertOrientation::LINE_BOTTOM:
     572                 :          0 :                 lYPos = aRect.Bottom() - aFrmSize.Height() + 1;
     573                 :          0 :                 break;
     574                 :            : 
     575                 :            :             default:
     576                 :          0 :                 lYPos = aRect.Top() - aRelPos.Y();
     577                 :          0 :                 break;
     578                 :            :         }
     579                 :            :     }
     580                 :            : 
     581         [ #  # ]:          0 :     Rectangle aFrmRect(Point(lXPos, lYPos), aFrmSize);
     582                 :            : 
     583                 :          0 :     Rectangle *pOuterFrame = &aPage;
     584                 :            : 
     585         [ #  # ]:          0 :     if (nAnchor == TextContentAnchorType_AT_FRAME)
     586                 :          0 :         pOuterFrame = &aFrameAtFrame;
     587                 :            : 
     588         [ #  # ]:          0 :     if (aFrmRect.Left() < pOuterFrame->Left())
     589         [ #  # ]:          0 :         aFrmRect.Move(pOuterFrame->Left() - aFrmRect.Left(), 0);
     590         [ #  # ]:          0 :     if (aFrmRect.Right() > pOuterFrame->Right())
     591         [ #  # ]:          0 :         aFrmRect.Move(pOuterFrame->Right() - aFrmRect.Right(), 0);
     592                 :            : 
     593         [ #  # ]:          0 :     if (aFrmRect.Top() < pOuterFrame->Top())
     594         [ #  # ]:          0 :         aFrmRect.Move(0, pOuterFrame->Top() - aFrmRect.Top());
     595         [ #  # ]:          0 :     if (aFrmRect.Bottom() > pOuterFrame->Bottom())
     596         [ #  # ]:          0 :         aFrmRect.Move(0, pOuterFrame->Bottom() - aFrmRect.Bottom());
     597                 :            : 
     598                 :            :     // Draw Test paragraph
     599         [ #  # ]:          0 :     const long nTxtLineHeight = aTextLine.GetHeight();
     600                 :          0 :     Rectangle aTxt(aTextLine);
     601                 :            :     sal_Int32 nStep;
     602                 :            :     sal_uInt16 nLines;
     603                 :            : 
     604         [ #  # ]:          0 :     if (nAnchor == TextContentAnchorType_AT_FRAME)
     605                 :            :     {
     606                 :          0 :         aTxt.Left() = aFrameAtFrame.Left() + FLYINFLY_BORDER;
     607                 :          0 :         aTxt.Right() = aFrameAtFrame.Right() - FLYINFLY_BORDER;
     608                 :          0 :         aTxt.Top() = aFrameAtFrame.Top() + FLYINFLY_BORDER;
     609         [ #  # ]:          0 :         aTxt.Bottom() = aTxt.Top() + aTextLine.GetHeight() - 1;
     610                 :            : 
     611         [ #  # ]:          0 :         nStep = aTxt.GetHeight() + 2;
     612         [ #  # ]:          0 :         nLines = (sal_uInt16)(((aFrameAtFrame.GetHeight() - 2 * FLYINFLY_BORDER) * 2 / 3)
     613         [ #  # ]:          0 :                  / (aTxt.GetHeight() + 2));
     614                 :            :     }
     615                 :            :     else
     616                 :            :     {
     617         [ #  # ]:          0 :         nStep = aTxt.GetHeight() + 2;
     618 [ #  # ][ #  # ]:          0 :         nLines = (sal_uInt16)(aParaPrtArea.GetHeight() / (aTextLine.GetHeight() + 2));
     619                 :            :     }
     620                 :            : 
     621         [ #  # ]:          0 :     if (nAnchor != TextContentAnchorType_AS_CHARACTER)
     622                 :            :     {
     623                 :            :         // Simulate text
     624                 :          0 :         const long nOldR = aTxt.Right();
     625                 :          0 :         const long nOldL = aTxt.Left();
     626                 :            : 
     627                 :            :         // #i22341#
     628                 :            :         const bool bIgnoreWrap = nAnchor == TextContentAnchorType_AT_CHARACTER &&
     629                 :            :                            ( nHRel == RelOrientation::CHAR || nVRel == RelOrientation::CHAR ||
     630 [ #  # ][ #  # ]:          0 :                              nVRel == RelOrientation::TEXT_LINE );
         [ #  # ][ #  # ]
     631                 :            : 
     632         [ #  # ]:          0 :         for (sal_uInt16 i = 0; i < nLines; ++i)
     633                 :            :         {
     634         [ #  # ]:          0 :             if (i == (nLines - 1))
     635 [ #  # ][ #  # ]:          0 :                 aTxt.SetSize(Size(aTxt.GetWidth() / 2, aTxt.GetHeight()));
                 [ #  # ]
     636                 :            : 
     637 [ #  # ][ #  # ]:          0 :             if (aTxt.IsOver(aFrmRect) && nAnchor != TextContentAnchorType_AS_CHARACTER && !bIgnoreWrap)
         [ #  # ][ #  # ]
                 [ #  # ]
     638                 :            :             {
     639   [ #  #  #  # ]:          0 :                 switch(nWrap)
     640                 :            :                 {
     641                 :            :                     case WrapTextMode_NONE:
     642                 :          0 :                         aTxt.Top()    = aFrmRect.Bottom() + nTxtLineHeight;
     643                 :          0 :                         aTxt.Bottom() = aTxt.Top() + nTxtLineHeight - 1;
     644                 :          0 :                         break;
     645                 :            : 
     646                 :            :                     case WrapTextMode_LEFT:
     647                 :          0 :                         aTxt.Right() = aFrmRect.Left();
     648                 :          0 :                         break;
     649                 :            : 
     650                 :            :                     case WrapTextMode_RIGHT:
     651                 :          0 :                         aTxt.Left() = aFrmRect.Right();
     652                 :          0 :                         break;
     653                 :            :                 }
     654                 :            :             }
     655 [ #  # ][ #  # ]:          0 :             if (pOuterFrame->IsInside(aTxt))
     656         [ #  # ]:          0 :                 DrawRect_Impl( aTxt, m_aTxtCol, m_aTransColor );
     657                 :            : 
     658         [ #  # ]:          0 :             aTxt.Move(0, nStep);
     659                 :          0 :             aTxt.Right() = nOldR;
     660                 :          0 :             aTxt.Left()  = nOldL;
     661                 :            :         }
     662         [ #  # ]:          0 :         aTxt.Move(0, -nStep);
     663                 :            : 
     664 [ #  # ][ #  # ]:          0 :         if (nAnchor != TextContentAnchorType_AT_FRAME && aTxt.Bottom() > aParaPrtArea.Bottom())
                 [ #  # ]
     665                 :            :         {
     666                 :            :             // Text has been replaced by frame, so adjust parameters height
     667                 :          0 :             sal_uIntPtr nDiff = aTxt.Bottom() - aParaPrtArea.Bottom();
     668                 :          0 :             aParaPrtArea.Bottom() += nDiff;
     669                 :          0 :             aPara.Bottom() += nDiff;
     670                 :            : 
     671         [ #  # ]:          0 :             CalcBoundRect_Impl(aRect);
     672                 :            : 
     673                 :          0 :             aParaPrtArea.Bottom() -= nDiff;
     674                 :          0 :             aPara.Bottom() -= nDiff;
     675                 :            :         }
     676 [ #  # ][ #  # ]:          0 :         if (nAnchor == TextContentAnchorType_AT_CHARACTER && bIgnoreWrap)
     677 [ #  # ][ #  # ]:          0 :             DrawText(aAutoCharFrame, rtl::OUString('A'));
                 [ #  # ]
     678                 :            :     }
     679                 :            :     else
     680                 :            :     {
     681 [ #  # ][ #  # ]:          0 :         DrawText(aParaPrtArea, rtl::OUString(DEMOTEXT));
                 [ #  # ]
     682         [ #  # ]:          0 :         DrawRect_Impl(aDrawObj, m_aBlankCol, m_aBlankFrameCol );
     683                 :            :     }
     684                 :            : 
     685                 :            :     // Draw rectangle on which the frame is aligned:
     686         [ #  # ]:          0 :     DrawRect_Impl(aRect, m_aTransColor, m_aAlignColor);
     687                 :            : 
     688                 :            :     // Frame View
     689 [ #  # ][ #  # ]:          0 :     sal_Bool bDontFill = (nAnchor == TextContentAnchorType_AT_CHARACTER && aFrmRect.IsOver(aAutoCharFrame)) ? sal_True : bTrans;
                 [ #  # ]
     690 [ #  # ][ #  # ]:          0 :     DrawRect_Impl( aFrmRect, bDontFill? m_aTransColor : m_aBgCol, m_aFrameColor );
     691                 :          0 : }
     692                 :            : 
     693                 :          0 : void SvxSwFrameExample::SetRelPos(const Point& rP)
     694                 :            : {
     695                 :          0 :     aRelPos = rP;
     696                 :            : 
     697         [ #  # ]:          0 :     if (aRelPos.X() > 0)
     698                 :          0 :         aRelPos.X() = 5;
     699         [ #  # ]:          0 :     if (aRelPos.X() < 0)
     700                 :          0 :         aRelPos.X() = -5;
     701                 :            : 
     702         [ #  # ]:          0 :     if (aRelPos.Y() > 0)
     703                 :          0 :         aRelPos.Y() = 5;
     704         [ #  # ]:          0 :     if (aRelPos.Y() < 0)
     705                 :          0 :         aRelPos.Y() = -5;
     706                 :          0 : }
     707                 :            : 
     708                 :          0 : void SvxSwFrameExample::DrawRect_Impl(const Rectangle &rRect, const Color &rFillColor, const Color &rLineColor)
     709                 :            : {
     710                 :          0 :     SetFillColor(rFillColor);
     711                 :          0 :     SetLineColor(rLineColor);
     712                 :          0 :     Window::DrawRect(rRect);
     713                 :          0 : }
     714                 :            : 
     715                 :            : 
     716                 :            : 
     717                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10