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_vcl.hxx" 30 31 #include "tools/rc.h" 32 33 #include "vcl/decoview.hxx" 34 #include "vcl/event.hxx" 35 #include "vcl/fixed.hxx" 36 37 #include "controldata.hxx" 38 #include "window.h" 39 40 // ======================================================================= 41 42 #define FIXEDLINE_TEXT_BORDER 4 43 44 #define FIXEDTEXT_VIEW_STYLE (WB_3DLOOK | \ 45 WB_LEFT | WB_CENTER | WB_RIGHT | \ 46 WB_TOP | WB_VCENTER | WB_BOTTOM | \ 47 WB_WORDBREAK | WB_NOLABEL | \ 48 WB_INFO | WB_PATHELLIPSIS) 49 #define FIXEDLINE_VIEW_STYLE (WB_3DLOOK | WB_NOLABEL) 50 #define FIXEDBITMAP_VIEW_STYLE (WB_3DLOOK | \ 51 WB_LEFT | WB_CENTER | WB_RIGHT | \ 52 WB_TOP | WB_VCENTER | WB_BOTTOM | \ 53 WB_SCALE) 54 #define FIXEDIMAGE_VIEW_STYLE (WB_3DLOOK | \ 55 WB_LEFT | WB_CENTER | WB_RIGHT | \ 56 WB_TOP | WB_VCENTER | WB_BOTTOM | \ 57 WB_SCALE) 58 59 // ======================================================================= 60 61 static Point ImplCalcPos( WinBits nStyle, const Point& rPos, 62 const Size& rObjSize, const Size& rWinSize ) 63 { 64 long nX; 65 long nY; 66 67 if ( nStyle & WB_LEFT ) 68 nX = 0; 69 else if ( nStyle & WB_RIGHT ) 70 nX = rWinSize.Width()-rObjSize.Width(); 71 else 72 nX = (rWinSize.Width()-rObjSize.Width())/2; 73 74 if ( nStyle & WB_TOP ) 75 nY = 0; 76 else if ( nStyle & WB_BOTTOM ) 77 nY = rWinSize.Height()-rObjSize.Height(); 78 else 79 nY = (rWinSize.Height()-rObjSize.Height())/2; 80 81 if ( nStyle & WB_TOPLEFTVISIBLE ) 82 { 83 if ( nX < 0 ) 84 nX = 0; 85 if ( nY < 0 ) 86 nY = 0; 87 } 88 89 Point aPos( nX+rPos.X(), nY+rPos.Y() ); 90 return aPos; 91 } 92 93 // ======================================================================= 94 95 void FixedText::ImplInit( Window* pParent, WinBits nStyle ) 96 { 97 nStyle = ImplInitStyle( nStyle ); 98 Control::ImplInit( pParent, nStyle, NULL ); 99 ImplInitSettings( sal_True, sal_True, sal_True ); 100 } 101 102 // ----------------------------------------------------------------------- 103 104 WinBits FixedText::ImplInitStyle( WinBits nStyle ) 105 { 106 if ( !(nStyle & WB_NOGROUP) ) 107 nStyle |= WB_GROUP; 108 return nStyle; 109 } 110 111 // ----------------------------------------------------------------- 112 113 const Font& FixedText::GetCanonicalFont( const StyleSettings& _rStyle ) const 114 { 115 return ( GetStyle() & WB_INFO ) ? _rStyle.GetInfoFont() : _rStyle.GetLabelFont(); 116 } 117 118 // ----------------------------------------------------------------- 119 const Color& FixedText::GetCanonicalTextColor( const StyleSettings& _rStyle ) const 120 { 121 return ( GetStyle() & WB_INFO ) ? _rStyle.GetInfoTextColor() : _rStyle.GetLabelTextColor(); 122 } 123 124 // ----------------------------------------------------------------------- 125 126 void FixedText::ImplInitSettings( sal_Bool bFont, 127 sal_Bool bForeground, sal_Bool bBackground ) 128 { 129 Control::ImplInitSettings( bFont, bForeground ); 130 131 if ( bBackground ) 132 { 133 Window* pParent = GetParent(); 134 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() ) 135 { 136 EnableChildTransparentMode( sal_True ); 137 SetParentClipMode( PARENTCLIPMODE_NOCLIP ); 138 SetPaintTransparent( sal_True ); 139 SetBackground(); 140 } 141 else 142 { 143 EnableChildTransparentMode( sal_False ); 144 SetParentClipMode( 0 ); 145 SetPaintTransparent( sal_False ); 146 147 if ( IsControlBackground() ) 148 SetBackground( GetControlBackground() ); 149 else 150 SetBackground( pParent->GetBackground() ); 151 } 152 } 153 } 154 155 // ----------------------------------------------------------------------- 156 157 FixedText::FixedText( Window* pParent, WinBits nStyle ) : 158 Control( WINDOW_FIXEDTEXT ) 159 { 160 ImplInit( pParent, nStyle ); 161 } 162 163 // ----------------------------------------------------------------------- 164 165 FixedText::FixedText( Window* pParent, const ResId& rResId ) : 166 Control( WINDOW_FIXEDTEXT ) 167 { 168 rResId.SetRT( RSC_TEXT ); 169 WinBits nStyle = ImplInitRes( rResId ); 170 ImplInit( pParent, nStyle ); 171 ImplLoadRes( rResId ); 172 173 if ( !(nStyle & WB_HIDE) ) 174 Show(); 175 } 176 177 // ----------------------------------------------------------------------- 178 179 FixedText::FixedText( Window* pParent, const ResId& rResId, bool bDisableAccessibleLabelForRelation ) : 180 Control( WINDOW_FIXEDTEXT ) 181 { 182 rResId.SetRT( RSC_TEXT ); 183 WinBits nStyle = ImplInitRes( rResId ); 184 ImplInit( pParent, nStyle ); 185 ImplLoadRes( rResId ); 186 if ( bDisableAccessibleLabelForRelation ) 187 ImplGetWindowImpl()->mbDisableAccessibleLabelForRelation = sal_True; 188 189 if ( !(nStyle & WB_HIDE) ) 190 Show(); 191 } 192 193 // ----------------------------------------------------------------------- 194 195 sal_uInt16 FixedText::ImplGetTextStyle( WinBits nWinStyle ) 196 { 197 sal_uInt16 nTextStyle = TEXT_DRAW_MNEMONIC | TEXT_DRAW_ENDELLIPSIS; 198 199 if( ! (nWinStyle & WB_NOMULTILINE) ) 200 nTextStyle |= TEXT_DRAW_MULTILINE; 201 202 if ( nWinStyle & WB_RIGHT ) 203 nTextStyle |= TEXT_DRAW_RIGHT; 204 else if ( nWinStyle & WB_CENTER ) 205 nTextStyle |= TEXT_DRAW_CENTER; 206 else 207 nTextStyle |= TEXT_DRAW_LEFT; 208 if ( nWinStyle & WB_BOTTOM ) 209 nTextStyle |= TEXT_DRAW_BOTTOM; 210 else if ( nWinStyle & WB_VCENTER ) 211 nTextStyle |= TEXT_DRAW_VCENTER; 212 else 213 nTextStyle |= TEXT_DRAW_TOP; 214 if ( nWinStyle & WB_WORDBREAK ) 215 { 216 nTextStyle |= TEXT_DRAW_WORDBREAK; 217 if ( (nWinStyle & WB_HYPHENATION ) == WB_HYPHENATION ) 218 nTextStyle |= TEXT_DRAW_WORDBREAK_HYPHENATION; 219 } 220 if ( nWinStyle & WB_NOLABEL ) 221 nTextStyle &= ~TEXT_DRAW_MNEMONIC; 222 223 return nTextStyle; 224 } 225 226 // ----------------------------------------------------------------------- 227 228 void FixedText::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags, 229 const Point& rPos, const Size& rSize, 230 bool bFillLayout 231 ) const 232 { 233 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 234 WinBits nWinStyle = GetStyle(); 235 XubString aText( GetText() ); 236 sal_uInt16 nTextStyle = FixedText::ImplGetTextStyle( nWinStyle ); 237 Point aPos = rPos; 238 239 if ( nWinStyle & WB_EXTRAOFFSET ) 240 aPos.X() += 2; 241 242 if ( nWinStyle & WB_PATHELLIPSIS ) 243 { 244 nTextStyle &= ~(TEXT_DRAW_ENDELLIPSIS | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK); 245 nTextStyle |= TEXT_DRAW_PATHELLIPSIS; 246 } 247 if ( nDrawFlags & WINDOW_DRAW_NOMNEMONIC ) 248 { 249 if ( nTextStyle & TEXT_DRAW_MNEMONIC ) 250 { 251 aText = GetNonMnemonicString( aText ); 252 nTextStyle &= ~TEXT_DRAW_MNEMONIC; 253 } 254 } 255 if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) ) 256 { 257 if ( !IsEnabled() ) 258 nTextStyle |= TEXT_DRAW_DISABLE; 259 } 260 if ( (nDrawFlags & WINDOW_DRAW_MONO) || 261 (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) ) 262 nTextStyle |= TEXT_DRAW_MONO; 263 264 if( bFillLayout ) 265 mpControlData->mpLayoutData->m_aDisplayText = String(); 266 267 Rectangle aRect( Rectangle( aPos, rSize ) ); 268 DrawControlText( *pDev, aRect, aText, nTextStyle, 269 bFillLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL, 270 bFillLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL 271 ); 272 } 273 274 // ----------------------------------------------------------------------- 275 276 void FixedText::Paint( const Rectangle& ) 277 { 278 ImplDraw( this, 0, Point(), GetOutputSizePixel() ); 279 } 280 281 // ----------------------------------------------------------------------- 282 283 void FixedText::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, 284 sal_uLong nFlags ) 285 { 286 ImplInitSettings( sal_True, sal_True, sal_True ); 287 288 Point aPos = pDev->LogicToPixel( rPos ); 289 Size aSize = pDev->LogicToPixel( rSize ); 290 Font aFont = GetDrawPixelFont( pDev ); 291 292 pDev->Push(); 293 pDev->SetMapMode(); 294 pDev->SetFont( aFont ); 295 if ( nFlags & WINDOW_DRAW_MONO ) 296 pDev->SetTextColor( Color( COL_BLACK ) ); 297 else 298 pDev->SetTextColor( GetTextColor() ); 299 pDev->SetTextFillColor(); 300 301 sal_Bool bBorder = !(nFlags & WINDOW_DRAW_NOBORDER ) && (GetStyle() & WB_BORDER); 302 sal_Bool bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && IsControlBackground(); 303 if ( bBorder || bBackground ) 304 { 305 Rectangle aRect( aPos, aSize ); 306 if ( bBorder ) 307 { 308 ImplDrawFrame( pDev, aRect ); 309 } 310 if ( bBackground ) 311 { 312 pDev->SetFillColor( GetControlBackground() ); 313 pDev->DrawRect( aRect ); 314 } 315 } 316 317 ImplDraw( pDev, nFlags, aPos, aSize ); 318 pDev->Pop(); 319 } 320 321 // ----------------------------------------------------------------------- 322 323 void FixedText::Resize() 324 { 325 Control::Resize(); 326 Invalidate(); 327 } 328 329 // ----------------------------------------------------------------------- 330 331 void FixedText::StateChanged( StateChangedType nType ) 332 { 333 Control::StateChanged( nType ); 334 335 if ( (nType == STATE_CHANGE_ENABLE) || 336 (nType == STATE_CHANGE_TEXT) || 337 (nType == STATE_CHANGE_UPDATEMODE) ) 338 { 339 if ( IsReallyVisible() && IsUpdateMode() ) 340 Invalidate(); 341 } 342 else if ( nType == STATE_CHANGE_STYLE ) 343 { 344 SetStyle( ImplInitStyle( GetStyle() ) ); 345 if ( (GetPrevStyle() & FIXEDTEXT_VIEW_STYLE) != 346 (GetStyle() & FIXEDTEXT_VIEW_STYLE) ) 347 { 348 ImplInitSettings( sal_True, sal_False, sal_False ); 349 Invalidate(); 350 } 351 } 352 else if ( (nType == STATE_CHANGE_ZOOM) || 353 (nType == STATE_CHANGE_CONTROLFONT) ) 354 { 355 ImplInitSettings( sal_True, sal_False, sal_False ); 356 Invalidate(); 357 } 358 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND ) 359 { 360 ImplInitSettings( sal_False, sal_True, sal_False ); 361 Invalidate(); 362 } 363 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 364 { 365 ImplInitSettings( sal_False, sal_False, sal_True ); 366 Invalidate(); 367 } 368 } 369 370 // ----------------------------------------------------------------------- 371 372 void FixedText::DataChanged( const DataChangedEvent& rDCEvt ) 373 { 374 Control::DataChanged( rDCEvt ); 375 376 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) || 377 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) || 378 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) && 379 (rDCEvt.GetFlags() & SETTINGS_STYLE)) ) 380 { 381 ImplInitSettings( sal_True, sal_True, sal_True ); 382 Invalidate(); 383 } 384 } 385 386 // ----------------------------------------------------------------------- 387 388 Size FixedText::CalcMinimumTextSize( Control const *pControl, long nMaxWidth ) 389 { 390 sal_uInt16 nStyle = ImplGetTextStyle( pControl->GetStyle() ); 391 if ( !( pControl->GetStyle() & WB_NOLABEL ) ) 392 nStyle |= TEXT_DRAW_MNEMONIC; 393 394 Size aSize = pControl->GetTextRect( Rectangle( Point(), Size( (nMaxWidth ? nMaxWidth : 0x7fffffff), 0x7fffffff ) ), 395 pControl->GetText(), nStyle ).GetSize(); 396 397 if ( pControl->GetStyle() & WB_EXTRAOFFSET ) 398 aSize.Width() += 2; 399 400 // GetTextRect verkraftet keinen leeren String: 401 if ( aSize.Width() < 0 ) 402 aSize.Width() = 0; 403 if ( aSize.Height() <= 0 ) 404 aSize.Height() = pControl->GetTextHeight(); 405 406 return aSize; 407 } 408 409 Size FixedText::CalcMinimumSize( long nMaxWidth ) const 410 { 411 return CalcWindowSize( CalcMinimumTextSize ( this, nMaxWidth ) ); 412 } 413 // ----------------------------------------------------------------------- 414 415 Size FixedText::GetOptimalSize(WindowSizeType eType) const 416 { 417 switch (eType) { 418 case WINDOWSIZE_MINIMUM: 419 return CalcMinimumSize(); 420 default: 421 return Control::GetOptimalSize( eType ); 422 } 423 } 424 425 // ----------------------------------------------------------------------- 426 427 void FixedText::FillLayoutData() const 428 { 429 mpControlData->mpLayoutData = new vcl::ControlLayoutData(); 430 ImplDraw( const_cast<FixedText*>(this), 0, Point(), GetOutputSizePixel(), true ); 431 } 432 433 // ======================================================================= 434 435 void FixedLine::ImplInit( Window* pParent, WinBits nStyle ) 436 { 437 nStyle = ImplInitStyle( nStyle ); 438 Control::ImplInit( pParent, nStyle, NULL ); 439 ImplInitSettings( sal_True, sal_True, sal_True ); 440 } 441 442 // ----------------------------------------------------------------------- 443 444 WinBits FixedLine::ImplInitStyle( WinBits nStyle ) 445 { 446 if ( !(nStyle & WB_NOGROUP) ) 447 nStyle |= WB_GROUP; 448 return nStyle; 449 } 450 451 // ----------------------------------------------------------------- 452 453 const Font& FixedLine::GetCanonicalFont( const StyleSettings& _rStyle ) const 454 { 455 return _rStyle.GetGroupFont(); 456 } 457 458 // ----------------------------------------------------------------- 459 const Color& FixedLine::GetCanonicalTextColor( const StyleSettings& _rStyle ) const 460 { 461 return _rStyle.GetGroupTextColor(); 462 } 463 464 // ----------------------------------------------------------------------- 465 466 void FixedLine::ImplInitSettings( sal_Bool bFont, 467 sal_Bool bForeground, sal_Bool bBackground ) 468 { 469 Control::ImplInitSettings( bFont, bForeground ); 470 471 if ( bBackground ) 472 { 473 Window* pParent = GetParent(); 474 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() ) 475 { 476 EnableChildTransparentMode( sal_True ); 477 SetParentClipMode( PARENTCLIPMODE_NOCLIP ); 478 SetPaintTransparent( sal_True ); 479 SetBackground(); 480 } 481 else 482 { 483 EnableChildTransparentMode( sal_False ); 484 SetParentClipMode( 0 ); 485 SetPaintTransparent( sal_False ); 486 487 if ( IsControlBackground() ) 488 SetBackground( GetControlBackground() ); 489 else 490 SetBackground( pParent->GetBackground() ); 491 } 492 } 493 } 494 495 // ----------------------------------------------------------------------- 496 497 void FixedLine::ImplDraw( bool bLayout ) 498 { 499 Size aOutSize = GetOutputSizePixel(); 500 String aText = GetText(); 501 WinBits nWinStyle = GetStyle(); 502 MetricVector* pVector = bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL; 503 String* pDisplayText = bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL; 504 505 DecorationView aDecoView( this ); 506 if ( !aText.Len() ) 507 { 508 if( !pVector ) 509 { 510 long nX = 0; 511 long nY = 0; 512 513 if ( nWinStyle & WB_VERT ) 514 { 515 nX = (aOutSize.Width()-1)/2; 516 aDecoView.DrawSeparator( Point( nX, 0 ), Point( nX, aOutSize.Height()-1 ) ); 517 } 518 else 519 { 520 nY = (aOutSize.Height()-1)/2; 521 aDecoView.DrawSeparator( Point( 0, nY ), Point( aOutSize.Width()-1, nY ), false ); 522 } 523 } 524 } 525 else if( (nWinStyle & WB_VERT) ) 526 { 527 long nWidth = GetTextWidth( aText ); 528 Push( PUSH_FONT ); 529 Font aFont( GetFont() ); 530 aFont.SetOrientation( 900 ); 531 SetFont( aFont ); 532 Point aStartPt( aOutSize.Width()/2, aOutSize.Height()-1 ); 533 if( (nWinStyle & WB_VCENTER) ) 534 aStartPt.Y() -= (aOutSize.Height() - nWidth)/2; 535 Point aTextPt( aStartPt ); 536 aTextPt.X() -= GetTextHeight()/2; 537 DrawText( aTextPt, aText, 0, STRING_LEN, pVector, pDisplayText ); 538 Pop(); 539 if( aOutSize.Height() - aStartPt.Y() > FIXEDLINE_TEXT_BORDER ) 540 aDecoView.DrawSeparator( Point( aStartPt.X(), aOutSize.Height()-1 ), 541 Point( aStartPt.X(), aStartPt.Y() + FIXEDLINE_TEXT_BORDER ) ); 542 if( aStartPt.Y() - nWidth - FIXEDLINE_TEXT_BORDER > 0 ) 543 aDecoView.DrawSeparator( Point( aStartPt.X(), aStartPt.Y() - nWidth - FIXEDLINE_TEXT_BORDER ), 544 Point( aStartPt.X(), 0 ) ); 545 } 546 else 547 { 548 sal_uInt16 nStyle = TEXT_DRAW_MNEMONIC | TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER | TEXT_DRAW_ENDELLIPSIS; 549 Rectangle aRect( 0, 0, aOutSize.Width(), aOutSize.Height() ); 550 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 551 if( (nWinStyle & WB_CENTER) ) 552 nStyle |= TEXT_DRAW_CENTER; 553 554 if ( !IsEnabled() ) 555 nStyle |= TEXT_DRAW_DISABLE; 556 if ( GetStyle() & WB_NOLABEL ) 557 nStyle &= ~TEXT_DRAW_MNEMONIC; 558 if ( rStyleSettings.GetOptions() & STYLE_OPTION_MONO ) 559 nStyle |= TEXT_DRAW_MONO; 560 561 DrawControlText( *this, aRect, aText, nStyle, pVector, pDisplayText ); 562 563 if( !pVector ) 564 { 565 long nTop = aRect.Top() + ((aRect.GetHeight()-1)/2); 566 aDecoView.DrawSeparator( Point( aRect.Right()+FIXEDLINE_TEXT_BORDER, nTop ), Point( aOutSize.Width()-1, nTop ), false ); 567 if( aRect.Left() > FIXEDLINE_TEXT_BORDER ) 568 aDecoView.DrawSeparator( Point( 0, nTop ), Point( aRect.Left()-FIXEDLINE_TEXT_BORDER, nTop ), false ); 569 } 570 } 571 } 572 573 // ----------------------------------------------------------------------- 574 575 FixedLine::FixedLine( Window* pParent, WinBits nStyle ) : 576 Control( WINDOW_FIXEDLINE ) 577 { 578 ImplInit( pParent, nStyle ); 579 SetSizePixel( Size( 2, 2 ) ); 580 } 581 582 // ----------------------------------------------------------------------- 583 584 FixedLine::FixedLine( Window* pParent, const ResId& rResId ) : 585 Control( WINDOW_FIXEDLINE ) 586 { 587 rResId.SetRT( RSC_FIXEDLINE ); 588 WinBits nStyle = ImplInitRes( rResId ); 589 ImplInit( pParent, nStyle ); 590 ImplLoadRes( rResId ); 591 592 if ( !(nStyle & WB_HIDE) ) 593 Show(); 594 } 595 596 // ----------------------------------------------------------------------- 597 598 void FixedLine::FillLayoutData() const 599 { 600 mpControlData->mpLayoutData = new vcl::ControlLayoutData(); 601 const_cast<FixedLine*>(this)->ImplDraw( true ); 602 } 603 604 605 // ----------------------------------------------------------------------- 606 607 void FixedLine::Paint( const Rectangle& ) 608 { 609 ImplDraw(); 610 } 611 612 // ----------------------------------------------------------------------- 613 614 void FixedLine::Draw( OutputDevice*, const Point&, const Size&, sal_uLong ) 615 { 616 } 617 618 // ----------------------------------------------------------------------- 619 620 void FixedLine::Resize() 621 { 622 Control::Resize(); 623 Invalidate(); 624 } 625 626 // ----------------------------------------------------------------------- 627 628 void FixedLine::StateChanged( StateChangedType nType ) 629 { 630 Control::StateChanged( nType ); 631 632 if ( (nType == STATE_CHANGE_ENABLE) || 633 (nType == STATE_CHANGE_TEXT) || 634 (nType == STATE_CHANGE_UPDATEMODE) ) 635 { 636 if ( IsReallyVisible() && IsUpdateMode() ) 637 Invalidate(); 638 } 639 else if ( nType == STATE_CHANGE_STYLE ) 640 { 641 SetStyle( ImplInitStyle( GetStyle() ) ); 642 if ( (GetPrevStyle() & FIXEDLINE_VIEW_STYLE) != 643 (GetStyle() & FIXEDLINE_VIEW_STYLE) ) 644 Invalidate(); 645 } 646 else if ( (nType == STATE_CHANGE_ZOOM) || 647 (nType == STATE_CHANGE_STYLE) || 648 (nType == STATE_CHANGE_CONTROLFONT) ) 649 { 650 ImplInitSettings( sal_True, sal_False, sal_False ); 651 Invalidate(); 652 } 653 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND ) 654 { 655 ImplInitSettings( sal_False, sal_True, sal_False ); 656 Invalidate(); 657 } 658 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 659 { 660 ImplInitSettings( sal_False, sal_False, sal_True ); 661 Invalidate(); 662 } 663 } 664 665 // ----------------------------------------------------------------------- 666 667 void FixedLine::DataChanged( const DataChangedEvent& rDCEvt ) 668 { 669 Control::DataChanged( rDCEvt ); 670 671 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) || 672 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) || 673 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) && 674 (rDCEvt.GetFlags() & SETTINGS_STYLE)) ) 675 { 676 ImplInitSettings( sal_True, sal_True, sal_True ); 677 Invalidate(); 678 } 679 } 680 681 // ----------------------------------------------------------------------- 682 683 Size FixedLine::GetOptimalSize(WindowSizeType eType) const 684 { 685 switch (eType) { 686 case WINDOWSIZE_MINIMUM: 687 return CalcWindowSize( FixedText::CalcMinimumTextSize ( this ) ); 688 default: 689 return Control::GetOptimalSize( eType ); 690 } 691 } 692 693 // ======================================================================= 694 695 void FixedBitmap::ImplInit( Window* pParent, WinBits nStyle ) 696 { 697 nStyle = ImplInitStyle( nStyle ); 698 Control::ImplInit( pParent, nStyle, NULL ); 699 ImplInitSettings(); 700 } 701 702 // ----------------------------------------------------------------------- 703 704 WinBits FixedBitmap::ImplInitStyle( WinBits nStyle ) 705 { 706 if ( !(nStyle & WB_NOGROUP) ) 707 nStyle |= WB_GROUP; 708 return nStyle; 709 } 710 711 // ----------------------------------------------------------------------- 712 713 void FixedBitmap::ImplInitSettings() 714 { 715 Window* pParent = GetParent(); 716 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() ) 717 { 718 EnableChildTransparentMode( sal_True ); 719 SetParentClipMode( PARENTCLIPMODE_NOCLIP ); 720 SetPaintTransparent( sal_True ); 721 SetBackground(); 722 } 723 else 724 { 725 EnableChildTransparentMode( sal_False ); 726 SetParentClipMode( 0 ); 727 SetPaintTransparent( sal_False ); 728 729 if ( IsControlBackground() ) 730 SetBackground( GetControlBackground() ); 731 else 732 SetBackground( pParent->GetBackground() ); 733 } 734 } 735 736 // ----------------------------------------------------------------------- 737 738 void FixedBitmap::ImplLoadRes( const ResId& rResId ) 739 { 740 Control::ImplLoadRes( rResId ); 741 742 sal_uLong nObjMask = ReadLongRes(); 743 744 if ( RSC_FIXEDBITMAP_BITMAP & nObjMask ) 745 { 746 maBitmap = Bitmap( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) ); 747 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) ); 748 } 749 } 750 751 // ----------------------------------------------------------------------- 752 753 FixedBitmap::FixedBitmap( Window* pParent, WinBits nStyle ) : 754 Control( WINDOW_FIXEDBITMAP ) 755 { 756 ImplInit( pParent, nStyle ); 757 } 758 759 // ----------------------------------------------------------------------- 760 761 FixedBitmap::FixedBitmap( Window* pParent, const ResId& rResId ) : 762 Control( WINDOW_FIXEDBITMAP ) 763 { 764 rResId.SetRT( RSC_FIXEDBITMAP ); 765 WinBits nStyle = ImplInitRes( rResId ); 766 ImplInit( pParent, nStyle ); 767 ImplLoadRes( rResId ); 768 769 if ( !(nStyle & WB_HIDE) ) 770 Show(); 771 } 772 773 // ----------------------------------------------------------------------- 774 775 FixedBitmap::~FixedBitmap() 776 { 777 } 778 779 // ----------------------------------------------------------------------- 780 781 void FixedBitmap::ImplDraw( OutputDevice* pDev, sal_uLong /* nDrawFlags */, 782 const Point& rPos, const Size& rSize ) 783 { 784 sal_uInt16 nStyle = 0; 785 Bitmap* pBitmap = &maBitmap; 786 Color aCol; 787 if( !!maBitmapHC ) 788 { 789 if( GetSettings().GetStyleSettings().GetHighContrastMode() ) 790 pBitmap = &maBitmapHC; 791 } 792 793 if( nStyle & IMAGE_DRAW_COLORTRANSFORM ) 794 { 795 // only images support IMAGE_DRAW_COLORTRANSFORM 796 Image aImage( maBitmap ); 797 if ( !(!aImage) ) 798 { 799 if ( GetStyle() & WB_SCALE ) 800 pDev->DrawImage( rPos, rSize, aImage, nStyle ); 801 else 802 { 803 Point aPos = ImplCalcPos( GetStyle(), rPos, aImage.GetSizePixel(), rSize ); 804 pDev->DrawImage( aPos, aImage, nStyle ); 805 } 806 } 807 } 808 else 809 { 810 // Haben wir ueberhaupt eine Bitmap 811 if ( !(!(*pBitmap)) ) 812 { 813 if ( GetStyle() & WB_SCALE ) 814 pDev->DrawBitmap( rPos, rSize, *pBitmap ); 815 else 816 { 817 Point aPos = ImplCalcPos( GetStyle(), rPos, pBitmap->GetSizePixel(), rSize ); 818 pDev->DrawBitmap( aPos, *pBitmap ); 819 } 820 } 821 } 822 } 823 824 // ----------------------------------------------------------------------- 825 826 void FixedBitmap::Paint( const Rectangle& ) 827 { 828 ImplDraw( this, 0, Point(), GetOutputSizePixel() ); 829 } 830 831 // ----------------------------------------------------------------------- 832 833 void FixedBitmap::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, 834 sal_uLong nFlags ) 835 { 836 Point aPos = pDev->LogicToPixel( rPos ); 837 Size aSize = pDev->LogicToPixel( rSize ); 838 Rectangle aRect( aPos, aSize ); 839 840 pDev->Push(); 841 pDev->SetMapMode(); 842 843 // Border 844 if ( !(nFlags & WINDOW_DRAW_NOBORDER) && (GetStyle() & WB_BORDER) ) 845 { 846 DecorationView aDecoView( pDev ); 847 aRect = aDecoView.DrawFrame( aRect, FRAME_DRAW_DOUBLEIN ); 848 } 849 pDev->IntersectClipRegion( aRect ); 850 ImplDraw( pDev, nFlags, aRect.TopLeft(), aRect.GetSize() ); 851 852 pDev->Pop(); 853 } 854 855 // ----------------------------------------------------------------------- 856 857 void FixedBitmap::Resize() 858 { 859 Control::Resize(); 860 Invalidate(); 861 } 862 863 // ----------------------------------------------------------------------- 864 865 void FixedBitmap::StateChanged( StateChangedType nType ) 866 { 867 Control::StateChanged( nType ); 868 869 if ( (nType == STATE_CHANGE_DATA) || 870 (nType == STATE_CHANGE_UPDATEMODE) ) 871 { 872 if ( IsReallyVisible() && IsUpdateMode() ) 873 Invalidate(); 874 } 875 else if ( nType == STATE_CHANGE_STYLE ) 876 { 877 SetStyle( ImplInitStyle( GetStyle() ) ); 878 if ( (GetPrevStyle() & FIXEDBITMAP_VIEW_STYLE) != 879 (GetStyle() & FIXEDBITMAP_VIEW_STYLE) ) 880 Invalidate(); 881 } 882 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 883 { 884 ImplInitSettings(); 885 Invalidate(); 886 } 887 } 888 889 // ----------------------------------------------------------------------- 890 891 void FixedBitmap::DataChanged( const DataChangedEvent& rDCEvt ) 892 { 893 Control::DataChanged( rDCEvt ); 894 895 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && 896 (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 897 { 898 ImplInitSettings(); 899 Invalidate(); 900 } 901 } 902 903 // ----------------------------------------------------------------------- 904 905 void FixedBitmap::SetBitmap( const Bitmap& rBitmap ) 906 { 907 maBitmap = rBitmap; 908 StateChanged( STATE_CHANGE_DATA ); 909 } 910 911 // ----------------------------------------------------------------------- 912 913 sal_Bool FixedBitmap::SetModeBitmap( const Bitmap& rBitmap, BmpColorMode eMode ) 914 { 915 if( eMode == BMP_COLOR_NORMAL ) 916 SetBitmap( rBitmap ); 917 else if( eMode == BMP_COLOR_HIGHCONTRAST ) 918 { 919 maBitmapHC = rBitmap; 920 StateChanged( STATE_CHANGE_DATA ); 921 } 922 else 923 return sal_False; 924 return sal_True; 925 } 926 927 // ----------------------------------------------------------------------- 928 929 const Bitmap& FixedBitmap::GetModeBitmap( BmpColorMode eMode) const 930 { 931 if( eMode == BMP_COLOR_HIGHCONTRAST ) 932 return maBitmapHC; 933 else 934 return maBitmap; 935 } 936 937 // ======================================================================= 938 939 void FixedImage::ImplInit( Window* pParent, WinBits nStyle ) 940 { 941 nStyle = ImplInitStyle( nStyle ); 942 mbInUserDraw = sal_False; 943 Control::ImplInit( pParent, nStyle, NULL ); 944 ImplInitSettings(); 945 } 946 947 // ----------------------------------------------------------------------- 948 949 WinBits FixedImage::ImplInitStyle( WinBits nStyle ) 950 { 951 if ( !(nStyle & WB_NOGROUP) ) 952 nStyle |= WB_GROUP; 953 return nStyle; 954 } 955 956 // ----------------------------------------------------------------------- 957 958 void FixedImage::ImplInitSettings() 959 { 960 Window* pParent = GetParent(); 961 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() ) 962 { 963 EnableChildTransparentMode( sal_True ); 964 SetParentClipMode( PARENTCLIPMODE_NOCLIP ); 965 SetPaintTransparent( sal_True ); 966 SetBackground(); 967 } 968 else 969 { 970 EnableChildTransparentMode( sal_False ); 971 SetParentClipMode( 0 ); 972 SetPaintTransparent( sal_False ); 973 974 if ( IsControlBackground() ) 975 SetBackground( GetControlBackground() ); 976 else 977 SetBackground( pParent->GetBackground() ); 978 } 979 } 980 981 // ----------------------------------------------------------------------- 982 983 void FixedImage::ImplLoadRes( const ResId& rResId ) 984 { 985 Control::ImplLoadRes( rResId ); 986 987 sal_uLong nObjMask = ReadLongRes(); 988 989 if ( RSC_FIXEDIMAGE_IMAGE & nObjMask ) 990 { 991 maImage = Image( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) ); 992 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) ); 993 } 994 } 995 996 // ----------------------------------------------------------------------- 997 998 FixedImage::FixedImage( Window* pParent, WinBits nStyle ) : 999 Control( WINDOW_FIXEDIMAGE ) 1000 { 1001 ImplInit( pParent, nStyle ); 1002 } 1003 1004 // ----------------------------------------------------------------------- 1005 1006 FixedImage::FixedImage( Window* pParent, const ResId& rResId ) : 1007 Control( WINDOW_FIXEDIMAGE ) 1008 { 1009 rResId.SetRT( RSC_FIXEDIMAGE ); 1010 WinBits nStyle = ImplInitRes( rResId ); 1011 ImplInit( pParent, nStyle ); 1012 ImplLoadRes( rResId ); 1013 1014 if ( !(nStyle & WB_HIDE) ) 1015 Show(); 1016 } 1017 1018 // ----------------------------------------------------------------------- 1019 1020 FixedImage::~FixedImage() 1021 { 1022 } 1023 1024 // ----------------------------------------------------------------------- 1025 1026 void FixedImage::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags, 1027 const Point& rPos, const Size& rSize ) 1028 { 1029 sal_uInt16 nStyle = 0; 1030 if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) ) 1031 { 1032 if ( !IsEnabled() ) 1033 nStyle |= IMAGE_DRAW_DISABLE; 1034 } 1035 1036 Image *pImage = &maImage; 1037 Color aCol; 1038 if( !!maImageHC ) 1039 { 1040 if( GetSettings().GetStyleSettings().GetHighContrastMode() ) 1041 pImage = &maImageHC; 1042 } 1043 1044 // Haben wir ueberhaupt ein Image 1045 if ( !(!(*pImage)) ) 1046 { 1047 if ( GetStyle() & WB_SCALE ) 1048 pDev->DrawImage( rPos, rSize, *pImage, nStyle ); 1049 else 1050 { 1051 Point aPos = ImplCalcPos( GetStyle(), rPos, pImage->GetSizePixel(), rSize ); 1052 pDev->DrawImage( aPos, *pImage, nStyle ); 1053 } 1054 } 1055 1056 mbInUserDraw = sal_True; 1057 UserDrawEvent aUDEvt( pDev, Rectangle( rPos, rSize ), 0, nStyle ); 1058 UserDraw( aUDEvt ); 1059 mbInUserDraw = sal_False; 1060 } 1061 1062 // ----------------------------------------------------------------------- 1063 1064 void FixedImage::Paint( const Rectangle& ) 1065 { 1066 ImplDraw( this, 0, Point(), GetOutputSizePixel() ); 1067 } 1068 1069 // ----------------------------------------------------------------------- 1070 1071 Size FixedImage::GetOptimalSize( WindowSizeType ) const 1072 { 1073 const Image* pImage = GetSettings().GetStyleSettings().GetHighContrastMode() ? &maImageHC : &maImage; 1074 return pImage->GetSizePixel(); 1075 } 1076 1077 // ----------------------------------------------------------------------- 1078 1079 void FixedImage::UserDraw( const UserDrawEvent& ) 1080 { 1081 } 1082 1083 // ----------------------------------------------------------------------- 1084 1085 void FixedImage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, 1086 sal_uLong nFlags ) 1087 { 1088 Point aPos = pDev->LogicToPixel( rPos ); 1089 Size aSize = pDev->LogicToPixel( rSize ); 1090 Rectangle aRect( aPos, aSize ); 1091 1092 pDev->Push(); 1093 pDev->SetMapMode(); 1094 1095 // Border 1096 if ( !(nFlags & WINDOW_DRAW_NOBORDER) && (GetStyle() & WB_BORDER) ) 1097 { 1098 ImplDrawFrame( pDev, aRect ); 1099 } 1100 pDev->IntersectClipRegion( aRect ); 1101 ImplDraw( pDev, nFlags, aRect.TopLeft(), aRect.GetSize() ); 1102 1103 pDev->Pop(); 1104 } 1105 1106 // ----------------------------------------------------------------------- 1107 1108 void FixedImage::Resize() 1109 { 1110 Control::Resize(); 1111 Invalidate(); 1112 } 1113 1114 // ----------------------------------------------------------------------- 1115 1116 void FixedImage::StateChanged( StateChangedType nType ) 1117 { 1118 Control::StateChanged( nType ); 1119 1120 if ( (nType == STATE_CHANGE_ENABLE) || 1121 (nType == STATE_CHANGE_DATA) || 1122 (nType == STATE_CHANGE_UPDATEMODE) ) 1123 { 1124 if ( IsReallyVisible() && IsUpdateMode() ) 1125 Invalidate(); 1126 } 1127 else if ( nType == STATE_CHANGE_STYLE ) 1128 { 1129 SetStyle( ImplInitStyle( GetStyle() ) ); 1130 if ( (GetPrevStyle() & FIXEDIMAGE_VIEW_STYLE) != 1131 (GetStyle() & FIXEDIMAGE_VIEW_STYLE) ) 1132 Invalidate(); 1133 } 1134 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 1135 { 1136 ImplInitSettings(); 1137 Invalidate(); 1138 } 1139 } 1140 1141 // ----------------------------------------------------------------------- 1142 1143 void FixedImage::DataChanged( const DataChangedEvent& rDCEvt ) 1144 { 1145 Control::DataChanged( rDCEvt ); 1146 1147 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && 1148 (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 1149 { 1150 ImplInitSettings(); 1151 Invalidate(); 1152 } 1153 } 1154 1155 // ----------------------------------------------------------------------- 1156 1157 void FixedImage::SetImage( const Image& rImage ) 1158 { 1159 if ( rImage != maImage ) 1160 { 1161 maImage = rImage; 1162 StateChanged( STATE_CHANGE_DATA ); 1163 } 1164 } 1165 1166 // ----------------------------------------------------------------------- 1167 1168 sal_Bool FixedImage::SetModeImage( const Image& rImage, BmpColorMode eMode ) 1169 { 1170 if( eMode == BMP_COLOR_NORMAL ) 1171 SetImage( rImage ); 1172 else if( eMode == BMP_COLOR_HIGHCONTRAST ) 1173 { 1174 if( maImageHC != rImage ) 1175 { 1176 maImageHC = rImage; 1177 StateChanged( STATE_CHANGE_DATA ); 1178 } 1179 } 1180 else 1181 return sal_False; 1182 return sal_True; 1183 } 1184 1185 // ----------------------------------------------------------------------- 1186 1187 const Image& FixedImage::GetModeImage( BmpColorMode eMode ) const 1188 { 1189 if( eMode == BMP_COLOR_HIGHCONTRAST ) 1190 return maImageHC; 1191 else 1192 return maImage; 1193 } 1194 1195 // ----------------------------------------------------------------------- 1196 1197 Point FixedImage::CalcImagePos( const Point& rPos, 1198 const Size& rObjSize, const Size& rWinSize ) 1199 { 1200 return ImplCalcPos( GetStyle(), rPos, rObjSize, rWinSize ); 1201 } 1202