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