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

Generated by: LCOV version 1.10