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