Update ooo320-m1
[ooovba.git] / vcl / source / control / fixed.cxx
blob3c53624dff149507d4a6f182f5b79df88010f920
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 )
809 if( GetSettings().GetStyleSettings().GetHighContrastMode() )
810 pBitmap = &maBitmapHC;
813 if( nStyle & IMAGE_DRAW_COLORTRANSFORM )
815 // only images support IMAGE_DRAW_COLORTRANSFORM
816 Image aImage( maBitmap );
817 if ( !(!aImage) )
819 if ( GetStyle() & WB_SCALE )
820 pDev->DrawImage( rPos, rSize, aImage, nStyle );
821 else
823 Point aPos = ImplCalcPos( GetStyle(), rPos, aImage.GetSizePixel(), rSize );
824 pDev->DrawImage( aPos, aImage, nStyle );
828 else
830 // Haben wir ueberhaupt eine Bitmap
831 if ( !(!(*pBitmap)) )
833 if ( GetStyle() & WB_SCALE )
834 pDev->DrawBitmap( rPos, rSize, *pBitmap );
835 else
837 Point aPos = ImplCalcPos( GetStyle(), rPos, pBitmap->GetSizePixel(), rSize );
838 pDev->DrawBitmap( aPos, *pBitmap );
844 // -----------------------------------------------------------------------
846 void FixedBitmap::Paint( const Rectangle& )
848 ImplDraw( this, 0, Point(), GetOutputSizePixel() );
851 // -----------------------------------------------------------------------
853 void FixedBitmap::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
854 ULONG nFlags )
856 Point aPos = pDev->LogicToPixel( rPos );
857 Size aSize = pDev->LogicToPixel( rSize );
858 Rectangle aRect( aPos, aSize );
860 pDev->Push();
861 pDev->SetMapMode();
863 // Border
864 if ( !(nFlags & WINDOW_DRAW_NOBORDER) && (GetStyle() & WB_BORDER) )
866 DecorationView aDecoView( pDev );
867 aRect = aDecoView.DrawFrame( aRect, FRAME_DRAW_DOUBLEIN );
869 pDev->IntersectClipRegion( aRect );
870 ImplDraw( pDev, nFlags, aRect.TopLeft(), aRect.GetSize() );
872 pDev->Pop();
875 // -----------------------------------------------------------------------
877 void FixedBitmap::Resize()
879 Control::Resize();
880 Invalidate();
883 // -----------------------------------------------------------------------
885 void FixedBitmap::StateChanged( StateChangedType nType )
887 Control::StateChanged( nType );
889 if ( (nType == STATE_CHANGE_DATA) ||
890 (nType == STATE_CHANGE_UPDATEMODE) )
892 if ( IsReallyVisible() && IsUpdateMode() )
893 Invalidate();
895 else if ( nType == STATE_CHANGE_STYLE )
897 SetStyle( ImplInitStyle( GetStyle() ) );
898 if ( (GetPrevStyle() & FIXEDBITMAP_VIEW_STYLE) !=
899 (GetStyle() & FIXEDBITMAP_VIEW_STYLE) )
900 Invalidate();
902 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
904 ImplInitSettings();
905 Invalidate();
909 // -----------------------------------------------------------------------
911 void FixedBitmap::DataChanged( const DataChangedEvent& rDCEvt )
913 Control::DataChanged( rDCEvt );
915 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
916 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
918 ImplInitSettings();
919 Invalidate();
923 // -----------------------------------------------------------------------
925 void FixedBitmap::SetBitmap( const Bitmap& rBitmap )
927 maBitmap = rBitmap;
928 StateChanged( STATE_CHANGE_DATA );
931 // -----------------------------------------------------------------------
933 BOOL FixedBitmap::SetModeBitmap( const Bitmap& rBitmap, BmpColorMode eMode )
935 if( eMode == BMP_COLOR_NORMAL )
936 SetBitmap( rBitmap );
937 else if( eMode == BMP_COLOR_HIGHCONTRAST )
939 maBitmapHC = rBitmap;
940 StateChanged( STATE_CHANGE_DATA );
942 else
943 return FALSE;
944 return TRUE;
947 // -----------------------------------------------------------------------
949 const Bitmap& FixedBitmap::GetModeBitmap( BmpColorMode eMode) const
951 if( eMode == BMP_COLOR_HIGHCONTRAST )
952 return maBitmapHC;
953 else
954 return maBitmap;
957 // =======================================================================
959 void FixedImage::ImplInit( Window* pParent, WinBits nStyle )
961 nStyle = ImplInitStyle( nStyle );
962 mbInUserDraw = FALSE;
963 Control::ImplInit( pParent, nStyle, NULL );
964 ImplInitSettings();
967 // -----------------------------------------------------------------------
969 WinBits FixedImage::ImplInitStyle( WinBits nStyle )
971 if ( !(nStyle & WB_NOGROUP) )
972 nStyle |= WB_GROUP;
973 return nStyle;
976 // -----------------------------------------------------------------------
978 void FixedImage::ImplInitSettings()
980 Window* pParent = GetParent();
981 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
983 EnableChildTransparentMode( TRUE );
984 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
985 SetPaintTransparent( TRUE );
986 SetBackground();
988 else
990 EnableChildTransparentMode( FALSE );
991 SetParentClipMode( 0 );
992 SetPaintTransparent( FALSE );
994 if ( IsControlBackground() )
995 SetBackground( GetControlBackground() );
996 else
997 SetBackground( pParent->GetBackground() );
1001 // -----------------------------------------------------------------------
1003 void FixedImage::ImplLoadRes( const ResId& rResId )
1005 Control::ImplLoadRes( rResId );
1007 ULONG nObjMask = ReadLongRes();
1009 if ( RSC_FIXEDIMAGE_IMAGE & nObjMask )
1011 maImage = Image( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) );
1012 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
1016 // -----------------------------------------------------------------------
1018 FixedImage::FixedImage( Window* pParent, WinBits nStyle ) :
1019 Control( WINDOW_FIXEDIMAGE )
1021 ImplInit( pParent, nStyle );
1024 // -----------------------------------------------------------------------
1026 FixedImage::FixedImage( Window* pParent, const ResId& rResId ) :
1027 Control( WINDOW_FIXEDIMAGE )
1029 rResId.SetRT( RSC_FIXEDIMAGE );
1030 WinBits nStyle = ImplInitRes( rResId );
1031 ImplInit( pParent, nStyle );
1032 ImplLoadRes( rResId );
1034 if ( !(nStyle & WB_HIDE) )
1035 Show();
1038 // -----------------------------------------------------------------------
1040 FixedImage::~FixedImage()
1044 // -----------------------------------------------------------------------
1046 void FixedImage::ImplDraw( OutputDevice* pDev, ULONG nDrawFlags,
1047 const Point& rPos, const Size& rSize )
1049 USHORT nStyle = 0;
1050 if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
1052 if ( !IsEnabled() )
1053 nStyle |= IMAGE_DRAW_DISABLE;
1056 Image *pImage = &maImage;
1057 Color aCol;
1058 if( !!maImageHC )
1060 if( GetSettings().GetStyleSettings().GetHighContrastMode() )
1061 pImage = &maImageHC;
1064 // Haben wir ueberhaupt ein Image
1065 if ( !(!(*pImage)) )
1067 if ( GetStyle() & WB_SCALE )
1068 pDev->DrawImage( rPos, rSize, *pImage, nStyle );
1069 else
1071 Point aPos = ImplCalcPos( GetStyle(), rPos, pImage->GetSizePixel(), rSize );
1072 pDev->DrawImage( aPos, *pImage, nStyle );
1076 mbInUserDraw = TRUE;
1077 UserDrawEvent aUDEvt( pDev, Rectangle( rPos, rSize ), 0, nStyle );
1078 UserDraw( aUDEvt );
1079 mbInUserDraw = FALSE;
1082 // -----------------------------------------------------------------------
1084 void FixedImage::Paint( const Rectangle& )
1086 ImplDraw( this, 0, Point(), GetOutputSizePixel() );
1089 // -----------------------------------------------------------------------
1091 void FixedImage::UserDraw( const UserDrawEvent& )
1095 // -----------------------------------------------------------------------
1097 void FixedImage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
1098 ULONG nFlags )
1100 Point aPos = pDev->LogicToPixel( rPos );
1101 Size aSize = pDev->LogicToPixel( rSize );
1102 Rectangle aRect( aPos, aSize );
1104 pDev->Push();
1105 pDev->SetMapMode();
1107 // Border
1108 if ( !(nFlags & WINDOW_DRAW_NOBORDER) && (GetStyle() & WB_BORDER) )
1110 ImplDrawFrame( pDev, aRect );
1112 pDev->IntersectClipRegion( aRect );
1113 ImplDraw( pDev, nFlags, aRect.TopLeft(), aRect.GetSize() );
1115 pDev->Pop();
1118 // -----------------------------------------------------------------------
1120 void FixedImage::Resize()
1122 Control::Resize();
1123 Invalidate();
1126 // -----------------------------------------------------------------------
1128 void FixedImage::StateChanged( StateChangedType nType )
1130 Control::StateChanged( nType );
1132 if ( (nType == STATE_CHANGE_ENABLE) ||
1133 (nType == STATE_CHANGE_DATA) ||
1134 (nType == STATE_CHANGE_UPDATEMODE) )
1136 if ( IsReallyVisible() && IsUpdateMode() )
1137 Invalidate();
1139 else if ( nType == STATE_CHANGE_STYLE )
1141 SetStyle( ImplInitStyle( GetStyle() ) );
1142 if ( (GetPrevStyle() & FIXEDIMAGE_VIEW_STYLE) !=
1143 (GetStyle() & FIXEDIMAGE_VIEW_STYLE) )
1144 Invalidate();
1146 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1148 ImplInitSettings();
1149 Invalidate();
1153 // -----------------------------------------------------------------------
1155 void FixedImage::DataChanged( const DataChangedEvent& rDCEvt )
1157 Control::DataChanged( rDCEvt );
1159 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1160 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1162 ImplInitSettings();
1163 Invalidate();
1167 // -----------------------------------------------------------------------
1169 void FixedImage::SetImage( const Image& rImage )
1171 if ( rImage != maImage )
1173 maImage = rImage;
1174 StateChanged( STATE_CHANGE_DATA );
1178 // -----------------------------------------------------------------------
1180 BOOL FixedImage::SetModeImage( const Image& rImage, BmpColorMode eMode )
1182 if( eMode == BMP_COLOR_NORMAL )
1183 SetImage( rImage );
1184 else if( eMode == BMP_COLOR_HIGHCONTRAST )
1186 if( maImageHC != rImage )
1188 maImageHC = rImage;
1189 StateChanged( STATE_CHANGE_DATA );
1192 else
1193 return FALSE;
1194 return TRUE;
1197 // -----------------------------------------------------------------------
1199 const Image& FixedImage::GetModeImage( BmpColorMode eMode ) const
1201 if( eMode == BMP_COLOR_HIGHCONTRAST )
1202 return maImageHC;
1203 else
1204 return maImage;
1207 // -----------------------------------------------------------------------
1209 Point FixedImage::CalcImagePos( const Point& rPos,
1210 const Size& rObjSize, const Size& rWinSize )
1212 return ImplCalcPos( GetStyle(), rPos, rObjSize, rWinSize );