Replace workaround of resize to invalidate with an explicit SfxHint
[LibreOffice.git] / svx / source / dialog / swframeexample.cxx
blob8beb189a40fe8db9b6ce4e26e968a21ce7c235e4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/metric.hxx>
21 #include <vcl/outdev.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
24 #include <svtools/colorcfg.hxx>
25 #include <svx/swframeexample.hxx>
26 #include <i18nlangtag/languagetag.hxx>
27 #include <com/sun/star/text/HoriOrientation.hpp>
28 #include <com/sun/star/text/VertOrientation.hpp>
29 #include <com/sun/star/text/RelOrientation.hpp>
31 using namespace ::com::sun::star::text;
33 #define FLYINFLY_BORDER 3
34 constexpr OUString DEMOTEXT = u"Ij"_ustr;
36 namespace {
38 void DrawRect_Impl(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect,
39 const Color &rFillColor, const Color &rLineColor)
41 rRenderContext.SetFillColor(rFillColor);
42 rRenderContext.SetLineColor(rLineColor);
43 rRenderContext.DrawRect(rRect);
48 SwFrameExample::SwFrameExample()
49 : nHAlign(HoriOrientation::CENTER)
50 , nHRel(RelOrientation::FRAME)
51 , nVAlign(VertOrientation::TOP)
52 , nVRel(RelOrientation::PRINT_AREA)
53 , nWrap(WrapTextMode_NONE)
54 , nAnchor(RndStdIds::FLY_AT_PAGE)
55 , bTrans(false)
56 , aRelPos(Point(0,0))
58 InitColors_Impl();
61 void SwFrameExample::SetDrawingArea(weld::DrawingArea* pDrawingArea)
63 CustomWidgetController::SetDrawingArea(pDrawingArea);
64 pDrawingArea->set_size_request(pDrawingArea->get_approximate_digit_width() * 16,
65 pDrawingArea->get_text_height() * 12);
68 void SwFrameExample::InitColors_Impl()
70 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
71 m_aBgCol = rSettings.GetWindowColor();
73 bool bHC = rSettings.GetHighContrastMode();
75 m_aFrameColor = COL_LIGHTGREEN;
76 m_aAlignColor = COL_LIGHTRED;
77 m_aTransColor = COL_TRANSPARENT;
79 m_aTxtCol = bHC?
80 svtools::ColorConfig().GetColorValue(svtools::FONTCOLOR).nColor :
81 COL_GRAY;
82 m_aPrintAreaCol = bHC? m_aTxtCol : COL_GRAY;
83 m_aBorderCol = m_aTxtCol;
84 m_aBlankCol = bHC? m_aTxtCol : COL_LIGHTGRAY;
85 m_aBlankFrameCol = bHC? m_aTxtCol : COL_GRAY;
88 void SwFrameExample::StyleUpdated()
90 InitColors_Impl();
91 CustomWidgetController::StyleUpdated();
94 void SwFrameExample::InitAllRects_Impl(vcl::RenderContext& rRenderContext)
96 aPage.SetSize(GetOutputSizePixel());
98 sal_uInt32 nOutWPix = aPage.GetWidth();
99 sal_uInt32 nOutHPix = aPage.GetHeight();
101 assert(nOutWPix > 0 && nOutHPix > 0);
103 // PrintArea
104 sal_uInt32 nLBorder;
105 sal_uInt32 nRBorder;
106 sal_uInt32 nTBorder;
107 sal_uInt32 nBBorder;
109 sal_uInt32 nLTxtBorder;
110 sal_uInt32 nRTxtBorder;
111 sal_uInt32 nTTxtBorder;
112 sal_uInt32 nBTxtBorder;
114 if (nAnchor != RndStdIds::FLY_AS_CHAR)
116 nLBorder = 14;
117 nRBorder = 10;
118 nTBorder = 10;
119 nBBorder = 15;
121 nLTxtBorder = 8;
122 nRTxtBorder = 4;
123 nTTxtBorder = 2;
124 nBTxtBorder = 2;
126 else
128 nLBorder = 2;
129 nRBorder = 2;
130 nTBorder = 2;
131 nBBorder = 2;
133 nLTxtBorder = 2;
134 nRTxtBorder = 2;
135 nTTxtBorder = 2;
136 nBTxtBorder = 2;
138 aPagePrtArea = tools::Rectangle(Point(nLBorder, nTBorder), Point((nOutWPix - 1) - nRBorder, (nOutHPix - 1) - nBBorder));
140 // Example text: Preparing for the text output
141 // A line of text
142 aTextLine = aPagePrtArea;
143 aTextLine.SetSize(Size(aTextLine.GetWidth(), 2));
144 aTextLine.AdjustLeft(nLTxtBorder );
145 aTextLine.AdjustRight( -sal_Int32(nRTxtBorder) );
146 aTextLine.Move(0, nTTxtBorder);
148 // Rectangle to edges including paragraph
149 sal_uInt16 nLines = static_cast<sal_uInt16>((aPagePrtArea.GetHeight() / 2 - nTTxtBorder - nBTxtBorder)
150 / (aTextLine.GetHeight() + 2));
151 aPara = aPagePrtArea;
152 aPara.SetSize(Size(aPara.GetWidth(),
153 (aTextLine.GetHeight() + 2) * nLines + nTTxtBorder + nBTxtBorder));
155 // Rectangle around paragraph without borders
156 aParaPrtArea = aPara;
157 aParaPrtArea.AdjustLeft(nLTxtBorder );
158 aParaPrtArea.AdjustRight( -sal_Int32(nRTxtBorder) );
159 aParaPrtArea.AdjustTop(nTTxtBorder );
160 aParaPrtArea.AdjustBottom( -sal_Int32(nBTxtBorder) );
162 if (nAnchor == RndStdIds::FLY_AS_CHAR || nAnchor == RndStdIds::FLY_AT_CHAR)
164 vcl::Font aFont = OutputDevice::GetDefaultFont(
165 DefaultFontType::LATIN_TEXT, Application::GetSettings().GetLanguageTag().getLanguageType(),
166 GetDefaultFontFlags::OnlyOne, &rRenderContext );
167 aFont.SetColor( m_aTxtCol );
168 aFont.SetFillColor( m_aBgCol );
169 aFont.SetWeight(WEIGHT_NORMAL);
171 if (nAnchor == RndStdIds::FLY_AS_CHAR)
173 aFont.SetFontSize(Size(0, aParaPrtArea.GetHeight() - 2));
174 rRenderContext.SetFont(aFont);
175 aParaPrtArea.SetSize(Size(rRenderContext.GetTextWidth(DEMOTEXT), rRenderContext.GetTextHeight()));
177 else
179 aFont.SetFontSize(Size(0, aParaPrtArea.GetHeight() / 2));
180 rRenderContext.SetFont(aFont);
181 aAutoCharFrame.SetSize(Size(rRenderContext.GetTextWidth(OUString('A')), GetTextHeight()));
182 aAutoCharFrame.SetPos(Point(aParaPrtArea.Left() + (aParaPrtArea.GetWidth() - aAutoCharFrame.GetWidth()) / 2,
183 aParaPrtArea.Top() + (aParaPrtArea.GetHeight() - aAutoCharFrame.GetHeight()) / 2));
187 // Inner Frame anchored at the Frame
188 aFrameAtFrame = aPara;
189 aFrameAtFrame.AdjustLeft(9 );
190 aFrameAtFrame.AdjustRight( -5 );
191 aFrameAtFrame.AdjustBottom(5 );
192 aFrameAtFrame.SetPos(Point(aFrameAtFrame.Left() + 2, (aPagePrtArea.Bottom() - aFrameAtFrame.GetHeight()) / 2 + 5));
194 // Size of the frame to be positioned
195 if (nAnchor != RndStdIds::FLY_AS_CHAR)
197 sal_uInt32 nLFBorder = nAnchor == RndStdIds::FLY_AT_PAGE ? nLBorder : nLTxtBorder;
198 sal_uInt32 nRFBorder = nAnchor == RndStdIds::FLY_AT_PAGE ? nRBorder : nRTxtBorder;
200 switch (nHRel)
202 case RelOrientation::PAGE_LEFT:
203 case RelOrientation::FRAME_LEFT:
204 aFrmSize = Size(nLFBorder - 4, (aTextLine.GetHeight() + 2) * 3);
205 break;
207 case RelOrientation::PAGE_RIGHT:
208 case RelOrientation::FRAME_RIGHT:
209 aFrmSize = Size(nRFBorder - 4, (aTextLine.GetHeight() + 2) * 3);
210 break;
212 default:
213 aFrmSize = Size(nLBorder - 3, (aTextLine.GetHeight() + 2) * 3);
214 break;
216 aFrmSize.setWidth( std::max(tools::Long(5), aFrmSize.Width()) );
217 aFrmSize.setHeight( std::max(tools::Long(5), aFrmSize.Height()) );
219 else
221 sal_uInt32 nFreeWidth = aPagePrtArea.GetWidth() - rRenderContext.GetTextWidth(DEMOTEXT);
223 aFrmSize = Size(nFreeWidth / 2, (aTextLine.GetHeight() + 2) * 3);
224 aDrawObj.SetSize(Size(std::max(tools::Long(5), tools::Long(nFreeWidth / 3)), std::max(tools::Long(5), aFrmSize.Height() * 3)));
225 aDrawObj.SetPos(Point(aParaPrtArea.Right() + 1, aParaPrtArea.Bottom() / 2));
226 aParaPrtArea.SetRight( aDrawObj.Right() );
230 void SwFrameExample::CalcBoundRect_Impl(const vcl::RenderContext& rRenderContext, tools::Rectangle &rRect)
232 switch (nAnchor)
234 case RndStdIds::FLY_AT_PAGE:
236 switch (nHRel)
238 case RelOrientation::FRAME:
239 case RelOrientation::PAGE_FRAME:
240 rRect.SetLeft( aPage.Left() );
241 rRect.SetRight( aPage.Right() );
242 break;
244 case RelOrientation::PRINT_AREA:
245 case RelOrientation::PAGE_PRINT_AREA:
246 rRect.SetLeft( aPagePrtArea.Left() );
247 rRect.SetRight( aPagePrtArea.Right() );
248 break;
250 case RelOrientation::PAGE_LEFT:
251 rRect.SetLeft( aPage.Left() );
252 rRect.SetRight( aPagePrtArea.Left() );
253 break;
255 case RelOrientation::PAGE_RIGHT:
256 rRect.SetLeft( aPagePrtArea.Right() );
257 rRect.SetRight( aPage.Right() );
258 break;
261 switch (nVRel)
263 case RelOrientation::PRINT_AREA:
264 case RelOrientation::PAGE_PRINT_AREA:
265 rRect.SetTop( aPagePrtArea.Top() );
266 rRect.SetBottom( aPagePrtArea.Bottom() );
267 break;
269 case RelOrientation::FRAME:
270 case RelOrientation::PAGE_FRAME:
271 rRect.SetTop( aPage.Top() );
272 rRect.SetBottom( aPage.Bottom() );
273 break;
276 break;
278 case RndStdIds::FLY_AT_FLY:
280 switch (nHRel)
282 case RelOrientation::FRAME:
283 case RelOrientation::PAGE_FRAME:
284 rRect.SetLeft( aFrameAtFrame.Left() );
285 rRect.SetRight( aFrameAtFrame.Right() );
286 break;
288 case RelOrientation::PRINT_AREA:
289 case RelOrientation::PAGE_PRINT_AREA:
290 rRect.SetLeft( aFrameAtFrame.Left() + FLYINFLY_BORDER );
291 rRect.SetRight( aFrameAtFrame.Right() - FLYINFLY_BORDER );
292 break;
294 case RelOrientation::PAGE_LEFT:
295 rRect.SetLeft( aFrameAtFrame.Left() );
296 rRect.SetRight( aFrameAtFrame.Left() + FLYINFLY_BORDER );
297 break;
299 case RelOrientation::PAGE_RIGHT:
300 rRect.SetLeft( aFrameAtFrame.Right() );
301 rRect.SetRight( aFrameAtFrame.Right() - FLYINFLY_BORDER );
302 break;
305 switch (nVRel)
307 case RelOrientation::FRAME:
308 case RelOrientation::PAGE_FRAME:
309 rRect.SetTop( aFrameAtFrame.Top() );
310 rRect.SetBottom( aFrameAtFrame.Bottom() );
311 break;
313 case RelOrientation::PRINT_AREA:
314 case RelOrientation::PAGE_PRINT_AREA:
315 rRect.SetTop( aFrameAtFrame.Top() + FLYINFLY_BORDER );
316 rRect.SetBottom( aFrameAtFrame.Bottom() - FLYINFLY_BORDER );
317 break;
320 break;
321 case RndStdIds::FLY_AT_PARA:
322 case RndStdIds::FLY_AT_CHAR:
324 switch (nHRel)
326 case RelOrientation::FRAME:
327 rRect.SetLeft( aPara.Left() );
328 rRect.SetRight( aPara.Right() );
329 break;
331 case RelOrientation::PRINT_AREA:
332 rRect.SetLeft( aParaPrtArea.Left() );
333 rRect.SetRight( aParaPrtArea.Right() );
334 break;
336 case RelOrientation::PAGE_LEFT:
337 rRect.SetLeft( aPage.Left() );
338 rRect.SetRight( aPagePrtArea.Left() );
339 break;
341 case RelOrientation::PAGE_RIGHT:
342 rRect.SetLeft( aPagePrtArea.Right() );
343 rRect.SetRight( aPage.Right() );
344 break;
346 case RelOrientation::PAGE_FRAME:
347 rRect.SetLeft( aPage.Left() );
348 rRect.SetRight( aPage.Right() );
349 break;
351 case RelOrientation::PAGE_PRINT_AREA:
352 rRect.SetLeft( aPagePrtArea.Left() );
353 rRect.SetRight( aPagePrtArea.Right() );
354 break;
356 case RelOrientation::FRAME_LEFT:
357 rRect.SetLeft( aPara.Left() );
358 rRect.SetRight( aParaPrtArea.Left() );
359 break;
361 case RelOrientation::FRAME_RIGHT:
362 rRect.SetLeft( aParaPrtArea.Right() );
363 rRect.SetRight( aPara.Right() );
364 break;
366 case RelOrientation::CHAR:
367 rRect.SetLeft( aAutoCharFrame.Left() );
368 rRect.SetRight( aAutoCharFrame.Left() );
369 break;
372 switch (nVRel)
374 case RelOrientation::FRAME:
375 rRect.SetTop( aPara.Top() );
376 rRect.SetBottom( aPara.Bottom() );
377 break;
379 case RelOrientation::PRINT_AREA:
380 rRect.SetTop( aParaPrtArea.Top() );
381 rRect.SetBottom( aParaPrtArea.Bottom() );
382 break;
384 case RelOrientation::CHAR:
385 if (nVAlign != VertOrientation::NONE &&
386 nVAlign != VertOrientation::CHAR_BOTTOM)
387 rRect.SetTop( aAutoCharFrame.Top() );
388 else
389 rRect.SetTop( aAutoCharFrame.Bottom() );
390 rRect.SetBottom( aAutoCharFrame.Bottom() );
391 break;
392 // OD 12.11.2003 #i22341#
393 case RelOrientation::TEXT_LINE:
394 rRect.SetTop( aAutoCharFrame.Top() );
395 rRect.SetBottom( aAutoCharFrame.Top() );
396 break;
399 break;
401 case RndStdIds::FLY_AS_CHAR:
402 rRect.SetLeft( aParaPrtArea.Left() );
403 rRect.SetRight( aParaPrtArea.Right() );
405 switch (nVAlign)
407 case VertOrientation::NONE:
408 case VertOrientation::TOP:
409 case VertOrientation::CENTER:
410 case VertOrientation::BOTTOM:
412 FontMetric aMetric(rRenderContext.GetFontMetric());
414 rRect.SetTop( aParaPrtArea.Bottom() - aMetric.GetDescent() );
415 rRect.SetBottom( rRect.Top() );
417 break;
419 default:
421 case VertOrientation::LINE_TOP:
422 case VertOrientation::LINE_CENTER:
423 case VertOrientation::LINE_BOTTOM:
424 rRect.SetTop( aParaPrtArea.Top() );
425 rRect.SetBottom( aDrawObj.Bottom() );
426 break;
428 case VertOrientation::CHAR_TOP:
429 case VertOrientation::CHAR_CENTER:
430 case VertOrientation::CHAR_BOTTOM:
431 rRect.SetTop( aParaPrtArea.Top() );
432 rRect.SetBottom( aParaPrtArea.Bottom() );
433 break;
435 break;
437 default:
438 break;
442 tools::Rectangle SwFrameExample::DrawInnerFrame_Impl(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect,
443 const Color &rFillColor, const Color &rBorderColor)
445 DrawRect_Impl(rRenderContext, rRect, rFillColor, rBorderColor);
447 // determine the area relative to which the positioning happens
448 tools::Rectangle aRect(rRect); // aPagePrtArea = Default
449 CalcBoundRect_Impl(rRenderContext, aRect);
451 if (nAnchor == RndStdIds::FLY_AT_FLY && &rRect == &aPagePrtArea)
453 // draw text paragraph
454 tools::Rectangle aTxt(aTextLine);
455 sal_Int32 nStep = aTxt.GetHeight() + 2;
456 sal_uInt16 nLines = static_cast<sal_uInt16>(aParaPrtArea.GetHeight() / (aTextLine.GetHeight() + 2));
458 for (sal_uInt16 i = 0; i < nLines; i++)
460 if (i == nLines - 1)
461 aTxt.SetSize(Size(aTxt.GetWidth() / 2, aTxt.GetHeight()));
462 DrawRect_Impl(rRenderContext, aTxt, m_aTxtCol, m_aTransColor);
463 aTxt.Move(0, nStep);
467 return aRect;
470 void SwFrameExample::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
472 rRenderContext.SetMapMode(MapMode(MapUnit::MapPixel));
474 InitAllRects_Impl(rRenderContext);
476 // Draw page
477 DrawRect_Impl(rRenderContext, aPage, m_aBgCol, m_aBorderCol);
479 // Draw PrintArea
480 tools::Rectangle aRect = DrawInnerFrame_Impl(rRenderContext, aPagePrtArea, m_aTransColor, m_aPrintAreaCol);
482 if (nAnchor == RndStdIds::FLY_AT_FLY)
483 aRect = DrawInnerFrame_Impl(rRenderContext, aFrameAtFrame, m_aBgCol, m_aBorderCol);
485 tools::Long lXPos = 0;
486 tools::Long lYPos = 0;
488 // Horizontal alignment
489 if (nAnchor != RndStdIds::FLY_AS_CHAR)
491 switch (nHAlign)
493 case HoriOrientation::RIGHT:
495 lXPos = aRect.Right() - aFrmSize.Width() + 1;
496 break;
498 case HoriOrientation::CENTER:
500 lXPos = aRect.Left() + (aRect.GetWidth() - aFrmSize.Width()) / 2;
501 break;
503 case HoriOrientation::NONE:
505 lXPos = aRect.Left() + aRelPos.X();
506 break;
509 default: // HoriOrientation::LEFT
510 lXPos = aRect.Left();
511 break;
514 else
516 lXPos = aRect.Right() + 2;
519 // Vertical Alignment
520 if (nAnchor != RndStdIds::FLY_AS_CHAR)
522 switch (nVAlign)
524 case VertOrientation::BOTTOM:
525 case VertOrientation::LINE_BOTTOM:
527 // #i22341#
528 if ( nVRel != RelOrientation::TEXT_LINE )
530 lYPos = aRect.Bottom() - aFrmSize.Height() + 1;
532 else
534 lYPos = aRect.Top();
536 break;
538 case VertOrientation::CENTER:
539 case VertOrientation::LINE_CENTER:
541 lYPos = aRect.Top() + (aRect.GetHeight() - aFrmSize.Height()) / 2;
542 break;
544 case VertOrientation::NONE:
546 // #i22341#
547 if ( nVRel != RelOrientation::CHAR && nVRel != RelOrientation::TEXT_LINE )
548 lYPos = aRect.Top() + aRelPos.Y();
549 else
550 lYPos = aRect.Top() - aRelPos.Y();
551 break;
553 default:
554 // #i22341#
555 if ( nVRel != RelOrientation::TEXT_LINE )
557 lYPos = aRect.Top();
559 else
561 lYPos = aRect.Bottom() - aFrmSize.Height() + 1;
563 break;
566 else
568 switch(nVAlign)
570 case VertOrientation::CENTER:
571 case VertOrientation::CHAR_CENTER:
572 case VertOrientation::LINE_CENTER:
573 lYPos = aRect.Top() + (aRect.GetHeight() - aFrmSize.Height()) / 2;
574 break;
576 case VertOrientation::TOP:
577 case VertOrientation::CHAR_BOTTOM:
578 case VertOrientation::LINE_BOTTOM:
579 lYPos = aRect.Bottom() - aFrmSize.Height() + 1;
580 break;
582 default:
583 lYPos = aRect.Top() - aRelPos.Y();
584 break;
588 tools::Rectangle aFrmRect(Point(lXPos, lYPos), aFrmSize);
590 tools::Rectangle* pOuterFrame = &aPage;
592 if (nAnchor == RndStdIds::FLY_AT_FLY)
593 pOuterFrame = &aFrameAtFrame;
595 if (aFrmRect.Left() < pOuterFrame->Left())
596 aFrmRect.Move(pOuterFrame->Left() - aFrmRect.Left(), 0);
597 if (aFrmRect.Right() > pOuterFrame->Right())
598 aFrmRect.Move(pOuterFrame->Right() - aFrmRect.Right(), 0);
600 if (aFrmRect.Top() < pOuterFrame->Top())
601 aFrmRect.Move(0, pOuterFrame->Top() - aFrmRect.Top());
602 if (aFrmRect.Bottom() > pOuterFrame->Bottom())
603 aFrmRect.Move(0, pOuterFrame->Bottom() - aFrmRect.Bottom());
605 // Draw Test paragraph
606 const tools::Long nTxtLineHeight = aTextLine.GetHeight();
607 tools::Rectangle aTxt(aTextLine);
608 sal_Int32 nStep;
609 sal_uInt16 nLines;
611 if (nAnchor == RndStdIds::FLY_AT_FLY)
613 aTxt.SetLeft( aFrameAtFrame.Left() + FLYINFLY_BORDER );
614 aTxt.SetRight( aFrameAtFrame.Right() - FLYINFLY_BORDER );
615 aTxt.SetTop( aFrameAtFrame.Top() + FLYINFLY_BORDER );
616 aTxt.SetBottom( aTxt.Top() + aTextLine.GetHeight() - 1 );
618 nStep = aTxt.GetHeight() + 2;
619 nLines = static_cast<sal_uInt16>(((aFrameAtFrame.GetHeight() - 2 * FLYINFLY_BORDER) * 2 / 3)
620 / (aTxt.GetHeight() + 2));
622 else
624 nStep = aTxt.GetHeight() + 2;
625 nLines = static_cast<sal_uInt16>(aParaPrtArea.GetHeight() / (aTextLine.GetHeight() + 2));
628 if (nAnchor != RndStdIds::FLY_AS_CHAR)
630 // Simulate text
631 const tools::Long nOldR = aTxt.Right();
632 const tools::Long nOldL = aTxt.Left();
634 // #i22341#
635 const bool bIgnoreWrap = nAnchor == RndStdIds::FLY_AT_CHAR &&
636 ( nHRel == RelOrientation::CHAR || nVRel == RelOrientation::CHAR ||
637 nVRel == RelOrientation::TEXT_LINE );
639 for (sal_uInt16 i = 0; i < nLines; ++i)
641 if (i == (nLines - 1))
642 aTxt.SetSize(Size(aTxt.GetWidth() / 2, aTxt.GetHeight()));
644 if (aTxt.Overlaps(aFrmRect) && nAnchor != RndStdIds::FLY_AS_CHAR && !bIgnoreWrap)
646 switch(nWrap)
648 case WrapTextMode_NONE:
649 aTxt.SetTop( aFrmRect.Bottom() + nTxtLineHeight );
650 aTxt.SetBottom( aTxt.Top() + nTxtLineHeight - 1 );
651 break;
653 case WrapTextMode_LEFT:
654 aTxt.SetRight( aFrmRect.Left() );
655 break;
657 case WrapTextMode_RIGHT:
658 aTxt.SetLeft( aFrmRect.Right() );
659 break;
660 default: break;
663 if (pOuterFrame->Contains(aTxt))
664 DrawRect_Impl(rRenderContext, aTxt, m_aTxtCol, m_aTransColor );
666 aTxt.Move(0, nStep);
667 aTxt.SetRight( nOldR );
668 aTxt.SetLeft( nOldL );
670 aTxt.Move(0, -nStep);
672 if (nAnchor != RndStdIds::FLY_AT_FLY && aTxt.Bottom() > aParaPrtArea.Bottom())
674 // Text has been replaced by frame, so adjust parameters height
675 sal_Int32 nDiff = aTxt.Bottom() - aParaPrtArea.Bottom();
676 aParaPrtArea.AdjustBottom(nDiff );
677 aPara.AdjustBottom(nDiff );
679 CalcBoundRect_Impl(rRenderContext, aRect);
681 aParaPrtArea.AdjustBottom( -nDiff );
682 aPara.AdjustBottom( -nDiff );
684 if (nAnchor == RndStdIds::FLY_AT_CHAR && bIgnoreWrap)
685 rRenderContext.DrawText(aAutoCharFrame, OUString('A'));
687 else
689 rRenderContext.DrawText(aParaPrtArea, DEMOTEXT);
690 DrawRect_Impl(rRenderContext, aDrawObj, m_aBlankCol, m_aBlankFrameCol );
693 // Draw rectangle on which the frame is aligned:
694 DrawRect_Impl(rRenderContext, aRect, m_aTransColor, m_aAlignColor);
696 // Frame View
697 bool bDontFill = (nAnchor == RndStdIds::FLY_AT_CHAR && aFrmRect.Overlaps(aAutoCharFrame)) || bTrans;
698 DrawRect_Impl(rRenderContext, aFrmRect, bDontFill? m_aTransColor : m_aBgCol, m_aFrameColor);
701 void SwFrameExample::SetRelPos(const Point& rP)
703 aRelPos = rP;
705 if (aRelPos.X() > 0)
706 aRelPos.setX( 5 );
707 if (aRelPos.X() < 0)
708 aRelPos.setX( -5 );
710 if (aRelPos.Y() > 0)
711 aRelPos.setY( 5 );
712 if (aRelPos.Y() < 0)
713 aRelPos.setY( -5 );
716 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */