update dev300-m58
[ooovba.git] / vcl / source / control / fixed.cxx
blob9588718efb9de37ab7d4543596cda9c3490d1ab9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fixed.cxx,v $
10 * $Revision: 1.25 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <vcl/decoview.hxx>
34 #include <vcl/event.hxx>
35 #include <vcl/fixed.hxx>
36 #include <vcl/controllayout.hxx>
37 #include <vcl/window.h>
39 #include <tools/rc.h>
41 // =======================================================================
43 #define FIXEDLINE_TEXT_BORDER 4
45 #define FIXEDTEXT_VIEW_STYLE (WB_3DLOOK | \
46 WB_LEFT | WB_CENTER | WB_RIGHT | \
47 WB_TOP | WB_VCENTER | WB_BOTTOM | \
48 WB_WORDBREAK | WB_NOLABEL | \
49 WB_INFO | WB_PATHELLIPSIS)
50 #define FIXEDLINE_VIEW_STYLE (WB_3DLOOK | WB_NOLABEL)
51 #define FIXEDBITMAP_VIEW_STYLE (WB_3DLOOK | \
52 WB_LEFT | WB_CENTER | WB_RIGHT | \
53 WB_TOP | WB_VCENTER | WB_BOTTOM | \
54 WB_SCALE)
55 #define FIXEDIMAGE_VIEW_STYLE (WB_3DLOOK | \
56 WB_LEFT | WB_CENTER | WB_RIGHT | \
57 WB_TOP | WB_VCENTER | WB_BOTTOM | \
58 WB_SCALE)
60 // =======================================================================
62 static Point ImplCalcPos( WinBits nStyle, const Point& rPos,
63 const Size& rObjSize, const Size& rWinSize )
65 long nX;
66 long nY;
68 if ( nStyle & WB_LEFT )
69 nX = 0;
70 else if ( nStyle & WB_RIGHT )
71 nX = rWinSize.Width()-rObjSize.Width();
72 else
73 nX = (rWinSize.Width()-rObjSize.Width())/2;
75 if ( nStyle & WB_TOP )
76 nY = 0;
77 else if ( nStyle & WB_BOTTOM )
78 nY = rWinSize.Height()-rObjSize.Height();
79 else
80 nY = (rWinSize.Height()-rObjSize.Height())/2;
82 if ( nStyle & WB_TOPLEFTVISIBLE )
84 if ( nX < 0 )
85 nX = 0;
86 if ( nY < 0 )
87 nY = 0;
90 Point aPos( nX+rPos.X(), nY+rPos.Y() );
91 return aPos;
94 // =======================================================================
96 void FixedText::ImplInit( Window* pParent, WinBits nStyle )
98 nStyle = ImplInitStyle( nStyle );
99 Control::ImplInit( pParent, nStyle, NULL );
100 ImplInitSettings( TRUE, TRUE, TRUE );
103 // -----------------------------------------------------------------------
105 WinBits FixedText::ImplInitStyle( WinBits nStyle )
107 if ( !(nStyle & WB_NOGROUP) )
108 nStyle |= WB_GROUP;
109 return nStyle;
112 // -----------------------------------------------------------------------
114 void FixedText::ImplInitSettings( BOOL bFont,
115 BOOL bForeground, BOOL bBackground )
117 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
119 if ( bFont )
121 Font aFont;
122 if ( GetStyle() & WB_INFO )
123 aFont = rStyleSettings.GetInfoFont();
124 else
125 aFont = rStyleSettings.GetLabelFont();
126 if ( IsControlFont() )
127 aFont.Merge( GetControlFont() );
128 SetZoomedPointFont( aFont );
131 if ( bForeground || bFont )
133 Color aColor;
134 if ( IsControlForeground() )
135 aColor = GetControlForeground();
136 else
138 if ( GetStyle() & WB_INFO )
139 aColor = rStyleSettings.GetInfoTextColor();
140 else
141 aColor = rStyleSettings.GetLabelTextColor();
143 SetTextColor( aColor );
144 SetTextFillColor();
147 if ( bBackground )
149 Window* pParent = GetParent();
150 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
152 EnableChildTransparentMode( TRUE );
153 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
154 SetPaintTransparent( TRUE );
155 SetBackground();
157 else
159 EnableChildTransparentMode( FALSE );
160 SetParentClipMode( 0 );
161 SetPaintTransparent( FALSE );
163 if ( IsControlBackground() )
164 SetBackground( GetControlBackground() );
165 else
166 SetBackground( pParent->GetBackground() );
171 // -----------------------------------------------------------------------
173 FixedText::FixedText( Window* pParent, WinBits nStyle ) :
174 Control( WINDOW_FIXEDTEXT )
176 ImplInit( pParent, nStyle );
179 // -----------------------------------------------------------------------
181 FixedText::FixedText( Window* pParent, const ResId& rResId ) :
182 Control( WINDOW_FIXEDTEXT )
184 rResId.SetRT( RSC_TEXT );
185 WinBits nStyle = ImplInitRes( rResId );
186 ImplInit( pParent, nStyle );
187 ImplLoadRes( rResId );
189 if ( !(nStyle & WB_HIDE) )
190 Show();
193 // -----------------------------------------------------------------------
195 FixedText::FixedText( Window* pParent, const ResId& rResId, bool bDisableAccessibleLabelForRelation ) :
196 Control( WINDOW_FIXEDTEXT )
198 rResId.SetRT( RSC_TEXT );
199 WinBits nStyle = ImplInitRes( rResId );
200 ImplInit( pParent, nStyle );
201 ImplLoadRes( rResId );
202 if ( bDisableAccessibleLabelForRelation )
203 ImplGetWindowImpl()->mbDisableAccessibleLabelForRelation = TRUE;
205 if ( !(nStyle & WB_HIDE) )
206 Show();
209 // -----------------------------------------------------------------------
211 USHORT FixedText::ImplGetTextStyle( WinBits nWinStyle )
213 USHORT nTextStyle = TEXT_DRAW_MNEMONIC | TEXT_DRAW_ENDELLIPSIS;
215 if( ! (nWinStyle & WB_NOMULTILINE) )
216 nTextStyle |= TEXT_DRAW_MULTILINE;
218 if ( nWinStyle & WB_RIGHT )
219 nTextStyle |= TEXT_DRAW_RIGHT;
220 else if ( nWinStyle & WB_CENTER )
221 nTextStyle |= TEXT_DRAW_CENTER;
222 else
223 nTextStyle |= TEXT_DRAW_LEFT;
224 if ( nWinStyle & WB_BOTTOM )
225 nTextStyle |= TEXT_DRAW_BOTTOM;
226 else if ( nWinStyle & WB_VCENTER )
227 nTextStyle |= TEXT_DRAW_VCENTER;
228 else
229 nTextStyle |= TEXT_DRAW_TOP;
230 if ( nWinStyle & WB_WORDBREAK )
232 nTextStyle |= TEXT_DRAW_WORDBREAK;
233 if ( (nWinStyle & WB_HYPHENATION ) == WB_HYPHENATION )
234 nTextStyle |= TEXT_DRAW_WORDBREAK_HYPHENATION;
236 if ( nWinStyle & WB_NOLABEL )
237 nTextStyle &= ~TEXT_DRAW_MNEMONIC;
239 return nTextStyle;
242 // -----------------------------------------------------------------------
244 void FixedText::ImplDraw( OutputDevice* pDev, ULONG nDrawFlags,
245 const Point& rPos, const Size& rSize,
246 bool bFillLayout
247 ) const
249 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
250 WinBits nWinStyle = GetStyle();
251 XubString aText( GetText() );
252 USHORT nTextStyle = FixedText::ImplGetTextStyle( nWinStyle );
253 Point aPos = rPos;
255 if ( nWinStyle & WB_EXTRAOFFSET )
256 aPos.X() += 2;
258 if ( nWinStyle & WB_PATHELLIPSIS )
260 nTextStyle &= ~(TEXT_DRAW_ENDELLIPSIS | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK);
261 nTextStyle |= TEXT_DRAW_PATHELLIPSIS;
263 if ( nDrawFlags & WINDOW_DRAW_NOMNEMONIC )
265 if ( nTextStyle & TEXT_DRAW_MNEMONIC )
267 aText = GetNonMnemonicString( aText );
268 nTextStyle &= ~TEXT_DRAW_MNEMONIC;
271 if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
273 if ( !IsEnabled() )
274 nTextStyle |= TEXT_DRAW_DISABLE;
276 if ( (nDrawFlags & WINDOW_DRAW_MONO) ||
277 (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
278 nTextStyle |= TEXT_DRAW_MONO;
280 if( bFillLayout )
282 mpLayoutData->m_aDisplayText = String();
283 pDev->DrawText( Rectangle( aPos, rSize ),
284 aText,
285 nTextStyle,
286 &mpLayoutData->m_aUnicodeBoundRects,
287 &mpLayoutData->m_aDisplayText
290 else
291 pDev->DrawText( Rectangle( aPos, rSize ), aText, nTextStyle );
294 // -----------------------------------------------------------------------
296 void FixedText::Paint( const Rectangle& )
298 ImplDraw( this, 0, Point(), GetOutputSizePixel() );
301 // -----------------------------------------------------------------------
303 void FixedText::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
304 ULONG nFlags )
306 ImplInitSettings( TRUE, TRUE, TRUE );
308 Point aPos = pDev->LogicToPixel( rPos );
309 Size aSize = pDev->LogicToPixel( rSize );
310 Font aFont = GetDrawPixelFont( pDev );
312 pDev->Push();
313 pDev->SetMapMode();
314 pDev->SetFont( aFont );
315 if ( nFlags & WINDOW_DRAW_MONO )
316 pDev->SetTextColor( Color( COL_BLACK ) );
317 else
318 pDev->SetTextColor( GetTextColor() );
319 pDev->SetTextFillColor();
321 BOOL bBorder = !(nFlags & WINDOW_DRAW_NOBORDER ) && (GetStyle() & WB_BORDER);
322 BOOL bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && IsControlBackground();
323 if ( bBorder || bBackground )
325 Rectangle aRect( aPos, aSize );
326 if ( bBorder )
328 ImplDrawFrame( pDev, aRect );
330 if ( bBackground )
332 pDev->SetFillColor( GetControlBackground() );
333 pDev->DrawRect( aRect );
337 ImplDraw( pDev, nFlags, aPos, aSize );
338 pDev->Pop();
341 // -----------------------------------------------------------------------
343 void FixedText::Resize()
345 Control::Resize();
346 Invalidate();
349 // -----------------------------------------------------------------------
351 void FixedText::StateChanged( StateChangedType nType )
353 Control::StateChanged( nType );
355 if ( (nType == STATE_CHANGE_ENABLE) ||
356 (nType == STATE_CHANGE_TEXT) ||
357 (nType == STATE_CHANGE_UPDATEMODE) )
359 if ( IsReallyVisible() && IsUpdateMode() )
360 Invalidate();
362 else if ( nType == STATE_CHANGE_STYLE )
364 SetStyle( ImplInitStyle( GetStyle() ) );
365 if ( (GetPrevStyle() & FIXEDTEXT_VIEW_STYLE) !=
366 (GetStyle() & FIXEDTEXT_VIEW_STYLE) )
368 ImplInitSettings( TRUE, FALSE, FALSE );
369 Invalidate();
372 else if ( (nType == STATE_CHANGE_ZOOM) ||
373 (nType == STATE_CHANGE_CONTROLFONT) )
375 ImplInitSettings( TRUE, FALSE, FALSE );
376 Invalidate();
378 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
380 ImplInitSettings( FALSE, TRUE, FALSE );
381 Invalidate();
383 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
385 ImplInitSettings( FALSE, FALSE, TRUE );
386 Invalidate();
390 // -----------------------------------------------------------------------
392 void FixedText::DataChanged( const DataChangedEvent& rDCEvt )
394 Control::DataChanged( rDCEvt );
396 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
397 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
398 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
399 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
401 ImplInitSettings( TRUE, TRUE, TRUE );
402 Invalidate();
406 // -----------------------------------------------------------------------
408 Size FixedText::CalcMinimumTextSize( Control const *pControl, long nMaxWidth )
410 USHORT nStyle = ImplGetTextStyle( pControl->GetStyle() );
411 if ( !( pControl->GetStyle() & WB_NOLABEL ) )
412 nStyle |= TEXT_DRAW_MNEMONIC;
414 Size aSize = pControl->GetTextRect( Rectangle( Point(), Size( (nMaxWidth ? nMaxWidth : 0x7fffffff), 0x7fffffff ) ),
415 pControl->GetText(), nStyle ).GetSize();
417 if ( pControl->GetStyle() & WB_EXTRAOFFSET )
418 aSize.Width() += 2;
420 // GetTextRect verkraftet keinen leeren String:
421 if ( aSize.Width() < 0 )
422 aSize.Width() = 0;
423 if ( aSize.Height() <= 0 )
424 aSize.Height() = pControl->GetTextHeight();
426 return aSize;
429 Size FixedText::CalcMinimumSize( long nMaxWidth ) const
431 return CalcWindowSize( CalcMinimumTextSize ( this, nMaxWidth ) );
433 // -----------------------------------------------------------------------
435 Size FixedText::GetOptimalSize(WindowSizeType eType) const
437 switch (eType) {
438 case WINDOWSIZE_MINIMUM:
439 return CalcMinimumSize();
440 default:
441 return Control::GetOptimalSize( eType );
445 // -----------------------------------------------------------------------
447 void FixedText::FillLayoutData() const
449 mpLayoutData = new vcl::ControlLayoutData();
450 ImplDraw( const_cast<FixedText*>(this), 0, Point(), GetOutputSizePixel(), true );
453 // =======================================================================
455 void FixedLine::ImplInit( Window* pParent, WinBits nStyle )
457 nStyle = ImplInitStyle( nStyle );
458 Control::ImplInit( pParent, nStyle, NULL );
459 ImplInitSettings( TRUE, TRUE, TRUE );
462 // -----------------------------------------------------------------------
464 WinBits FixedLine::ImplInitStyle( WinBits nStyle )
466 if ( !(nStyle & WB_NOGROUP) )
467 nStyle |= WB_GROUP;
468 return nStyle;
471 // -----------------------------------------------------------------------
473 void FixedLine::ImplInitSettings( BOOL bFont,
474 BOOL bForeground, BOOL bBackground )
476 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
478 if ( bFont )
480 Font aFont = rStyleSettings.GetGroupFont();
481 if ( IsControlFont() )
482 aFont.Merge( GetControlFont() );
483 SetZoomedPointFont( aFont );
486 if ( bForeground || bFont )
488 Color aColor;
489 if ( IsControlForeground() )
490 aColor = GetControlForeground();
491 else
492 aColor = rStyleSettings.GetGroupTextColor();
493 SetTextColor( aColor );
494 SetTextFillColor();
497 if ( bBackground )
499 Window* pParent = GetParent();
500 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
502 EnableChildTransparentMode( TRUE );
503 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
504 SetPaintTransparent( TRUE );
505 SetBackground();
507 else
509 EnableChildTransparentMode( FALSE );
510 SetParentClipMode( 0 );
511 SetPaintTransparent( FALSE );
513 if ( IsControlBackground() )
514 SetBackground( GetControlBackground() );
515 else
516 SetBackground( pParent->GetBackground() );
521 // -----------------------------------------------------------------------
523 void FixedLine::ImplDraw( bool bLayout )
525 Size aOutSize = GetOutputSizePixel();
526 String aText = GetText();
527 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
528 WinBits nWinStyle = GetStyle();
529 MetricVector* pVector = bLayout ? &mpLayoutData->m_aUnicodeBoundRects : NULL;
530 String* pDisplayText = bLayout ? &mpLayoutData->m_aDisplayText : NULL;
532 if ( rStyleSettings.GetOptions() & STYLE_OPTION_MONO )
533 SetLineColor( Color( COL_BLACK ) );
534 else
535 SetLineColor( rStyleSettings.GetShadowColor() );
537 if ( !aText.Len() || (nWinStyle & WB_VERT) )
539 if( !pVector )
541 long nX = 0;
542 long nY = 0;
544 if ( nWinStyle & WB_VERT )
546 nX = (aOutSize.Width()-1)/2;
547 DrawLine( Point( nX, 0 ), Point( nX, aOutSize.Height()-1 ) );
549 else
551 nY = (aOutSize.Height()-1)/2;
552 DrawLine( Point( 0, nY ), Point( aOutSize.Width()-1, nY ) );
555 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
557 SetLineColor( rStyleSettings.GetLightColor() );
558 if ( nWinStyle & WB_VERT )
559 DrawLine( Point( nX+1, 0 ), Point( nX+1, aOutSize.Height()-1 ) );
560 else
561 DrawLine( Point( 0, nY+1 ), Point( aOutSize.Width()-1, nY+1 ) );
565 else
567 USHORT nStyle = TEXT_DRAW_MNEMONIC | TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER | TEXT_DRAW_ENDELLIPSIS;
568 Rectangle aRect( 0, 0, aOutSize.Width(), aOutSize.Height() );
570 if ( !IsEnabled() )
571 nStyle |= TEXT_DRAW_DISABLE;
572 if ( GetStyle() & WB_NOLABEL )
573 nStyle &= ~TEXT_DRAW_MNEMONIC;
574 if ( rStyleSettings.GetOptions() & STYLE_OPTION_MONO )
575 nStyle |= TEXT_DRAW_MONO;
577 aRect = GetTextRect( aRect, aText, nStyle );
578 DrawText( aRect, aText, nStyle, pVector, pDisplayText );
580 if( !pVector )
582 long nTop = aRect.Top() + ((aRect.GetHeight()-1)/2);
583 DrawLine( Point( aRect.Right()+FIXEDLINE_TEXT_BORDER, nTop ), Point( aOutSize.Width()-1, nTop ) );
584 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
586 SetLineColor( rStyleSettings.GetLightColor() );
587 DrawLine( Point( aRect.Right()+FIXEDLINE_TEXT_BORDER, nTop+1 ), Point( aOutSize.Width()-1, nTop+1 ) );
593 // -----------------------------------------------------------------------
595 FixedLine::FixedLine( Window* pParent, WinBits nStyle ) :
596 Control( WINDOW_FIXEDLINE )
598 ImplInit( pParent, nStyle );
599 SetSizePixel( Size( 2, 2 ) );
602 // -----------------------------------------------------------------------
604 FixedLine::FixedLine( Window* pParent, const ResId& rResId ) :
605 Control( WINDOW_FIXEDLINE )
607 rResId.SetRT( RSC_FIXEDLINE );
608 WinBits nStyle = ImplInitRes( rResId );
609 ImplInit( pParent, nStyle );
610 ImplLoadRes( rResId );
612 if ( !(nStyle & WB_HIDE) )
613 Show();
616 // -----------------------------------------------------------------------
618 void FixedLine::FillLayoutData() const
620 mpLayoutData = new vcl::ControlLayoutData();
621 const_cast<FixedLine*>(this)->ImplDraw( true );
625 // -----------------------------------------------------------------------
627 void FixedLine::Paint( const Rectangle& )
629 ImplDraw();
632 // -----------------------------------------------------------------------
634 void FixedLine::Draw( OutputDevice*, const Point&, const Size&, ULONG )
638 // -----------------------------------------------------------------------
640 void FixedLine::Resize()
642 Control::Resize();
643 Invalidate();
646 // -----------------------------------------------------------------------
648 void FixedLine::StateChanged( StateChangedType nType )
650 Control::StateChanged( nType );
652 if ( (nType == STATE_CHANGE_ENABLE) ||
653 (nType == STATE_CHANGE_TEXT) ||
654 (nType == STATE_CHANGE_UPDATEMODE) )
656 if ( IsReallyVisible() && IsUpdateMode() )
657 Invalidate();
659 else if ( nType == STATE_CHANGE_STYLE )
661 SetStyle( ImplInitStyle( GetStyle() ) );
662 if ( (GetPrevStyle() & FIXEDLINE_VIEW_STYLE) !=
663 (GetStyle() & FIXEDLINE_VIEW_STYLE) )
664 Invalidate();
666 else if ( (nType == STATE_CHANGE_ZOOM) ||
667 (nType == STATE_CHANGE_STYLE) ||
668 (nType == STATE_CHANGE_CONTROLFONT) )
670 ImplInitSettings( TRUE, FALSE, FALSE );
671 Invalidate();
673 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
675 ImplInitSettings( FALSE, TRUE, FALSE );
676 Invalidate();
678 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
680 ImplInitSettings( FALSE, FALSE, TRUE );
681 Invalidate();
685 // -----------------------------------------------------------------------
687 void FixedLine::DataChanged( const DataChangedEvent& rDCEvt )
689 Control::DataChanged( rDCEvt );
691 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
692 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
693 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
694 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
696 ImplInitSettings( TRUE, TRUE, TRUE );
697 Invalidate();
701 // -----------------------------------------------------------------------
703 Size FixedLine::GetOptimalSize(WindowSizeType eType) const
705 switch (eType) {
706 case WINDOWSIZE_MINIMUM:
707 return CalcWindowSize( FixedText::CalcMinimumTextSize ( this ) );
708 default:
709 return Control::GetOptimalSize( eType );
713 // =======================================================================
715 void FixedBitmap::ImplInit( Window* pParent, WinBits nStyle )
717 nStyle = ImplInitStyle( nStyle );
718 Control::ImplInit( pParent, nStyle, NULL );
719 ImplInitSettings();
722 // -----------------------------------------------------------------------
724 WinBits FixedBitmap::ImplInitStyle( WinBits nStyle )
726 if ( !(nStyle & WB_NOGROUP) )
727 nStyle |= WB_GROUP;
728 return nStyle;
731 // -----------------------------------------------------------------------
733 void FixedBitmap::ImplInitSettings()
735 Window* pParent = GetParent();
736 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
738 EnableChildTransparentMode( TRUE );
739 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
740 SetPaintTransparent( TRUE );
741 SetBackground();
743 else
745 EnableChildTransparentMode( FALSE );
746 SetParentClipMode( 0 );
747 SetPaintTransparent( FALSE );
749 if ( IsControlBackground() )
750 SetBackground( GetControlBackground() );
751 else
752 SetBackground( pParent->GetBackground() );
756 // -----------------------------------------------------------------------
758 void FixedBitmap::ImplLoadRes( const ResId& rResId )
760 Control::ImplLoadRes( rResId );
762 ULONG nObjMask = ReadLongRes();
764 if ( RSC_FIXEDBITMAP_BITMAP & nObjMask )
766 maBitmap = Bitmap( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) );
767 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
771 // -----------------------------------------------------------------------
773 FixedBitmap::FixedBitmap( Window* pParent, WinBits nStyle ) :
774 Control( WINDOW_FIXEDBITMAP )
776 ImplInit( pParent, nStyle );
779 // -----------------------------------------------------------------------
781 FixedBitmap::FixedBitmap( Window* pParent, const ResId& rResId ) :
782 Control( WINDOW_FIXEDBITMAP )
784 rResId.SetRT( RSC_FIXEDBITMAP );
785 WinBits nStyle = ImplInitRes( rResId );
786 ImplInit( pParent, nStyle );
787 ImplLoadRes( rResId );
789 if ( !(nStyle & WB_HIDE) )
790 Show();
793 // -----------------------------------------------------------------------
795 FixedBitmap::~FixedBitmap()
799 // -----------------------------------------------------------------------
801 void FixedBitmap::ImplDraw( OutputDevice* pDev, ULONG /* nDrawFlags */,
802 const Point& rPos, const Size& rSize )
804 USHORT nStyle = 0;
805 Bitmap* pBitmap = &maBitmap;
806 Color aCol;
807 if( !!maBitmapHC && ImplGetCurrentBackgroundColor( aCol ) )
809 if( aCol.IsDark() )
810 pBitmap = &maBitmapHC;
811 // #99902 no col transform required
812 //if( aCol.IsBright() )
813 // nStyle |= IMAGE_DRAW_COLORTRANSFORM;
816 if( nStyle & IMAGE_DRAW_COLORTRANSFORM )
818 // only images support IMAGE_DRAW_COLORTRANSFORM
819 Image aImage( maBitmap );
820 if ( !(!aImage) )
822 if ( GetStyle() & WB_SCALE )
823 pDev->DrawImage( rPos, rSize, aImage, nStyle );
824 else
826 Point aPos = ImplCalcPos( GetStyle(), rPos, aImage.GetSizePixel(), rSize );
827 pDev->DrawImage( aPos, aImage, nStyle );
831 else
833 // Haben wir ueberhaupt eine Bitmap
834 if ( !(!(*pBitmap)) )
836 if ( GetStyle() & WB_SCALE )
837 pDev->DrawBitmap( rPos, rSize, *pBitmap );
838 else
840 Point aPos = ImplCalcPos( GetStyle(), rPos, pBitmap->GetSizePixel(), rSize );
841 pDev->DrawBitmap( aPos, *pBitmap );
847 // -----------------------------------------------------------------------
849 void FixedBitmap::Paint( const Rectangle& )
851 ImplDraw( this, 0, Point(), GetOutputSizePixel() );
854 // -----------------------------------------------------------------------
856 void FixedBitmap::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
857 ULONG nFlags )
859 Point aPos = pDev->LogicToPixel( rPos );
860 Size aSize = pDev->LogicToPixel( rSize );
861 Rectangle aRect( aPos, aSize );
863 pDev->Push();
864 pDev->SetMapMode();
866 // Border
867 if ( !(nFlags & WINDOW_DRAW_NOBORDER) && (GetStyle() & WB_BORDER) )
869 DecorationView aDecoView( pDev );
870 aRect = aDecoView.DrawFrame( aRect, FRAME_DRAW_DOUBLEIN );
872 pDev->IntersectClipRegion( aRect );
873 ImplDraw( pDev, nFlags, aRect.TopLeft(), aRect.GetSize() );
875 pDev->Pop();
878 // -----------------------------------------------------------------------
880 void FixedBitmap::Resize()
882 Control::Resize();
883 Invalidate();
886 // -----------------------------------------------------------------------
888 void FixedBitmap::StateChanged( StateChangedType nType )
890 Control::StateChanged( nType );
892 if ( (nType == STATE_CHANGE_DATA) ||
893 (nType == STATE_CHANGE_UPDATEMODE) )
895 if ( IsReallyVisible() && IsUpdateMode() )
896 Invalidate();
898 else if ( nType == STATE_CHANGE_STYLE )
900 SetStyle( ImplInitStyle( GetStyle() ) );
901 if ( (GetPrevStyle() & FIXEDBITMAP_VIEW_STYLE) !=
902 (GetStyle() & FIXEDBITMAP_VIEW_STYLE) )
903 Invalidate();
905 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
907 ImplInitSettings();
908 Invalidate();
912 // -----------------------------------------------------------------------
914 void FixedBitmap::DataChanged( const DataChangedEvent& rDCEvt )
916 Control::DataChanged( rDCEvt );
918 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
919 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
921 ImplInitSettings();
922 Invalidate();
926 // -----------------------------------------------------------------------
928 void FixedBitmap::SetBitmap( const Bitmap& rBitmap )
930 maBitmap = rBitmap;
931 StateChanged( STATE_CHANGE_DATA );
934 // -----------------------------------------------------------------------
936 BOOL FixedBitmap::SetModeBitmap( const Bitmap& rBitmap, BmpColorMode eMode )
938 if( eMode == BMP_COLOR_NORMAL )
939 SetBitmap( rBitmap );
940 else if( eMode == BMP_COLOR_HIGHCONTRAST )
942 maBitmapHC = rBitmap;
943 StateChanged( STATE_CHANGE_DATA );
945 else
946 return FALSE;
947 return TRUE;
950 // -----------------------------------------------------------------------
952 const Bitmap& FixedBitmap::GetModeBitmap( BmpColorMode eMode) const
954 if( eMode == BMP_COLOR_HIGHCONTRAST )
955 return maBitmapHC;
956 else
957 return maBitmap;
960 // =======================================================================
962 void FixedImage::ImplInit( Window* pParent, WinBits nStyle )
964 nStyle = ImplInitStyle( nStyle );
965 mbInUserDraw = FALSE;
966 Control::ImplInit( pParent, nStyle, NULL );
967 ImplInitSettings();
970 // -----------------------------------------------------------------------
972 WinBits FixedImage::ImplInitStyle( WinBits nStyle )
974 if ( !(nStyle & WB_NOGROUP) )
975 nStyle |= WB_GROUP;
976 return nStyle;
979 // -----------------------------------------------------------------------
981 void FixedImage::ImplInitSettings()
983 Window* pParent = GetParent();
984 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
986 EnableChildTransparentMode( TRUE );
987 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
988 SetPaintTransparent( TRUE );
989 SetBackground();
991 else
993 EnableChildTransparentMode( FALSE );
994 SetParentClipMode( 0 );
995 SetPaintTransparent( FALSE );
997 if ( IsControlBackground() )
998 SetBackground( GetControlBackground() );
999 else
1000 SetBackground( pParent->GetBackground() );
1004 // -----------------------------------------------------------------------
1006 void FixedImage::ImplLoadRes( const ResId& rResId )
1008 Control::ImplLoadRes( rResId );
1010 ULONG nObjMask = ReadLongRes();
1012 if ( RSC_FIXEDIMAGE_IMAGE & nObjMask )
1014 maImage = Image( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) );
1015 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
1019 // -----------------------------------------------------------------------
1021 FixedImage::FixedImage( Window* pParent, WinBits nStyle ) :
1022 Control( WINDOW_FIXEDIMAGE )
1024 ImplInit( pParent, nStyle );
1027 // -----------------------------------------------------------------------
1029 FixedImage::FixedImage( Window* pParent, const ResId& rResId ) :
1030 Control( WINDOW_FIXEDIMAGE )
1032 rResId.SetRT( RSC_FIXEDIMAGE );
1033 WinBits nStyle = ImplInitRes( rResId );
1034 ImplInit( pParent, nStyle );
1035 ImplLoadRes( rResId );
1037 if ( !(nStyle & WB_HIDE) )
1038 Show();
1041 // -----------------------------------------------------------------------
1043 FixedImage::~FixedImage()
1047 // -----------------------------------------------------------------------
1049 void FixedImage::ImplDraw( OutputDevice* pDev, ULONG nDrawFlags,
1050 const Point& rPos, const Size& rSize )
1052 USHORT nStyle = 0;
1053 if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
1055 if ( !IsEnabled() )
1056 nStyle |= IMAGE_DRAW_DISABLE;
1059 Image *pImage = &maImage;
1060 Color aCol;
1061 if( !!maImageHC && ImplGetCurrentBackgroundColor( aCol ) )
1063 if( aCol.IsDark() )
1064 pImage = &maImageHC;
1065 // #99902 no col transform required
1066 //if( aCol.IsBright() )
1067 // nStyle |= IMAGE_DRAW_COLORTRANSFORM;
1070 // Haben wir ueberhaupt ein Image
1071 if ( !(!(*pImage)) )
1073 if ( GetStyle() & WB_SCALE )
1074 pDev->DrawImage( rPos, rSize, *pImage, nStyle );
1075 else
1077 Point aPos = ImplCalcPos( GetStyle(), rPos, pImage->GetSizePixel(), rSize );
1078 pDev->DrawImage( aPos, *pImage, nStyle );
1082 mbInUserDraw = TRUE;
1083 UserDrawEvent aUDEvt( pDev, Rectangle( rPos, rSize ), 0, nStyle );
1084 UserDraw( aUDEvt );
1085 mbInUserDraw = FALSE;
1088 // -----------------------------------------------------------------------
1090 void FixedImage::Paint( const Rectangle& )
1092 ImplDraw( this, 0, Point(), GetOutputSizePixel() );
1095 // -----------------------------------------------------------------------
1097 void FixedImage::UserDraw( const UserDrawEvent& )
1101 // -----------------------------------------------------------------------
1103 void FixedImage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
1104 ULONG nFlags )
1106 Point aPos = pDev->LogicToPixel( rPos );
1107 Size aSize = pDev->LogicToPixel( rSize );
1108 Rectangle aRect( aPos, aSize );
1110 pDev->Push();
1111 pDev->SetMapMode();
1113 // Border
1114 if ( !(nFlags & WINDOW_DRAW_NOBORDER) && (GetStyle() & WB_BORDER) )
1116 ImplDrawFrame( pDev, aRect );
1118 pDev->IntersectClipRegion( aRect );
1119 ImplDraw( pDev, nFlags, aRect.TopLeft(), aRect.GetSize() );
1121 pDev->Pop();
1124 // -----------------------------------------------------------------------
1126 void FixedImage::Resize()
1128 Control::Resize();
1129 Invalidate();
1132 // -----------------------------------------------------------------------
1134 void FixedImage::StateChanged( StateChangedType nType )
1136 Control::StateChanged( nType );
1138 if ( (nType == STATE_CHANGE_ENABLE) ||
1139 (nType == STATE_CHANGE_DATA) ||
1140 (nType == STATE_CHANGE_UPDATEMODE) )
1142 if ( IsReallyVisible() && IsUpdateMode() )
1143 Invalidate();
1145 else if ( nType == STATE_CHANGE_STYLE )
1147 SetStyle( ImplInitStyle( GetStyle() ) );
1148 if ( (GetPrevStyle() & FIXEDIMAGE_VIEW_STYLE) !=
1149 (GetStyle() & FIXEDIMAGE_VIEW_STYLE) )
1150 Invalidate();
1152 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1154 ImplInitSettings();
1155 Invalidate();
1159 // -----------------------------------------------------------------------
1161 void FixedImage::DataChanged( const DataChangedEvent& rDCEvt )
1163 Control::DataChanged( rDCEvt );
1165 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1166 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1168 ImplInitSettings();
1169 Invalidate();
1173 // -----------------------------------------------------------------------
1175 void FixedImage::SetImage( const Image& rImage )
1177 if ( rImage != maImage )
1179 maImage = rImage;
1180 StateChanged( STATE_CHANGE_DATA );
1184 // -----------------------------------------------------------------------
1186 BOOL FixedImage::SetModeImage( const Image& rImage, BmpColorMode eMode )
1188 if( eMode == BMP_COLOR_NORMAL )
1189 SetImage( rImage );
1190 else if( eMode == BMP_COLOR_HIGHCONTRAST )
1192 if( maImageHC != rImage )
1194 maImageHC = rImage;
1195 StateChanged( STATE_CHANGE_DATA );
1198 else
1199 return FALSE;
1200 return TRUE;
1203 // -----------------------------------------------------------------------
1205 const Image& FixedImage::GetModeImage( BmpColorMode eMode ) const
1207 if( eMode == BMP_COLOR_HIGHCONTRAST )
1208 return maImageHC;
1209 else
1210 return maImage;
1213 // -----------------------------------------------------------------------
1215 Point FixedImage::CalcImagePos( const Point& rPos,
1216 const Size& rObjSize, const Size& rWinSize )
1218 return ImplCalcPos( GetStyle(), rPos, rObjSize, rWinSize );