1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include "vcl/decoview.hxx"
24 #include "vcl/dialog.hxx"
25 #include "vcl/event.hxx"
26 #include "vcl/fixed.hxx"
27 #include "vcl/svapp.hxx"
28 #include <comphelper/string.hxx>
29 #include "controldata.hxx"
30 #include "impimagetree.hxx"
33 // =======================================================================
35 #define FIXEDLINE_TEXT_BORDER 4
37 #define FIXEDTEXT_VIEW_STYLE (WB_3DLOOK | \
38 WB_LEFT | WB_CENTER | WB_RIGHT | \
39 WB_TOP | WB_VCENTER | WB_BOTTOM | \
40 WB_WORDBREAK | WB_NOLABEL | \
41 WB_INFO | WB_PATHELLIPSIS)
42 #define FIXEDLINE_VIEW_STYLE (WB_3DLOOK | WB_NOLABEL)
43 #define FIXEDBITMAP_VIEW_STYLE (WB_3DLOOK | \
44 WB_LEFT | WB_CENTER | WB_RIGHT | \
45 WB_TOP | WB_VCENTER | WB_BOTTOM | \
47 #define FIXEDIMAGE_VIEW_STYLE (WB_3DLOOK | \
48 WB_LEFT | WB_CENTER | WB_RIGHT | \
49 WB_TOP | WB_VCENTER | WB_BOTTOM | \
52 // =======================================================================
54 static Point
ImplCalcPos( WinBits nStyle
, const Point
& rPos
,
55 const Size
& rObjSize
, const Size
& rWinSize
)
60 if ( nStyle
& WB_LEFT
)
62 else if ( nStyle
& WB_RIGHT
)
63 nX
= rWinSize
.Width()-rObjSize
.Width();
65 nX
= (rWinSize
.Width()-rObjSize
.Width())/2;
67 if ( nStyle
& WB_TOP
)
69 else if ( nStyle
& WB_BOTTOM
)
70 nY
= rWinSize
.Height()-rObjSize
.Height();
72 nY
= (rWinSize
.Height()-rObjSize
.Height())/2;
74 if ( nStyle
& WB_TOPLEFTVISIBLE
)
82 Point
aPos( nX
+rPos
.X(), nY
+rPos
.Y() );
86 // =======================================================================
88 void FixedText::ImplInit( Window
* pParent
, WinBits nStyle
)
90 nStyle
= ImplInitStyle( nStyle
);
91 Control::ImplInit( pParent
, nStyle
, NULL
);
92 ImplInitSettings( sal_True
, sal_True
, sal_True
);
95 // -----------------------------------------------------------------------
97 WinBits
FixedText::ImplInitStyle( WinBits nStyle
)
99 if ( !(nStyle
& WB_NOGROUP
) )
104 // -----------------------------------------------------------------
106 const Font
& FixedText::GetCanonicalFont( const StyleSettings
& _rStyle
) const
108 return ( GetStyle() & WB_INFO
) ? _rStyle
.GetInfoFont() : _rStyle
.GetLabelFont();
111 // -----------------------------------------------------------------
112 const Color
& FixedText::GetCanonicalTextColor( const StyleSettings
& _rStyle
) const
114 return ( GetStyle() & WB_INFO
) ? _rStyle
.GetInfoTextColor() : _rStyle
.GetLabelTextColor();
117 // -----------------------------------------------------------------------
119 void FixedText::ImplInitSettings( sal_Bool bFont
,
120 sal_Bool bForeground
, sal_Bool bBackground
)
122 Control::ImplInitSettings( bFont
, bForeground
);
126 Window
* pParent
= GetParent();
127 if ( pParent
->IsChildTransparentModeEnabled() && !IsControlBackground() )
129 EnableChildTransparentMode( sal_True
);
130 SetParentClipMode( PARENTCLIPMODE_NOCLIP
);
131 SetPaintTransparent( sal_True
);
136 EnableChildTransparentMode( sal_False
);
137 SetParentClipMode( 0 );
138 SetPaintTransparent( sal_False
);
140 if ( IsControlBackground() )
141 SetBackground( GetControlBackground() );
143 SetBackground( pParent
->GetBackground() );
148 // -----------------------------------------------------------------------
150 FixedText::FixedText( Window
* pParent
, WinBits nStyle
)
151 : Control(WINDOW_FIXEDTEXT
)
152 , m_nMaxWidthChars(-1)
153 , m_nMinWidthChars(-1)
154 , m_pMnemonicWindow(NULL
)
156 ImplInit( pParent
, nStyle
);
159 // -----------------------------------------------------------------------
161 FixedText::FixedText( Window
* pParent
, const ResId
& rResId
)
162 : Control(WINDOW_FIXEDTEXT
)
163 , m_nMaxWidthChars(-1)
164 , m_nMinWidthChars(-1)
165 , m_pMnemonicWindow(NULL
)
167 rResId
.SetRT( RSC_TEXT
);
168 WinBits nStyle
= ImplInitRes( rResId
);
169 ImplInit( pParent
, nStyle
);
170 ImplLoadRes( rResId
);
172 if ( !(nStyle
& WB_HIDE
) )
176 // -----------------------------------------------------------------------
178 sal_uInt16
FixedText::ImplGetTextStyle( WinBits nWinStyle
)
180 sal_uInt16 nTextStyle
= TEXT_DRAW_MNEMONIC
| TEXT_DRAW_ENDELLIPSIS
;
182 if( ! (nWinStyle
& WB_NOMULTILINE
) )
183 nTextStyle
|= TEXT_DRAW_MULTILINE
;
185 if ( nWinStyle
& WB_RIGHT
)
186 nTextStyle
|= TEXT_DRAW_RIGHT
;
187 else if ( nWinStyle
& WB_CENTER
)
188 nTextStyle
|= TEXT_DRAW_CENTER
;
190 nTextStyle
|= TEXT_DRAW_LEFT
;
191 if ( nWinStyle
& WB_BOTTOM
)
192 nTextStyle
|= TEXT_DRAW_BOTTOM
;
193 else if ( nWinStyle
& WB_VCENTER
)
194 nTextStyle
|= TEXT_DRAW_VCENTER
;
196 nTextStyle
|= TEXT_DRAW_TOP
;
197 if ( nWinStyle
& WB_WORDBREAK
)
199 nTextStyle
|= TEXT_DRAW_WORDBREAK
;
200 if ( (nWinStyle
& WB_HYPHENATION
) == WB_HYPHENATION
)
201 nTextStyle
|= TEXT_DRAW_WORDBREAK_HYPHENATION
;
203 if ( nWinStyle
& WB_NOLABEL
)
204 nTextStyle
&= ~TEXT_DRAW_MNEMONIC
;
209 // -----------------------------------------------------------------------
211 void FixedText::ImplDraw( OutputDevice
* pDev
, sal_uLong nDrawFlags
,
212 const Point
& rPos
, const Size
& rSize
,
216 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
217 WinBits nWinStyle
= GetStyle();
218 OUString
aText( GetText() );
219 sal_uInt16 nTextStyle
= FixedText::ImplGetTextStyle( nWinStyle
);
222 if ( nWinStyle
& WB_EXTRAOFFSET
)
225 if ( nWinStyle
& WB_PATHELLIPSIS
)
227 nTextStyle
&= ~(TEXT_DRAW_ENDELLIPSIS
| TEXT_DRAW_MULTILINE
| TEXT_DRAW_WORDBREAK
);
228 nTextStyle
|= TEXT_DRAW_PATHELLIPSIS
;
230 if ( nDrawFlags
& WINDOW_DRAW_NOMNEMONIC
)
232 if ( nTextStyle
& TEXT_DRAW_MNEMONIC
)
234 aText
= GetNonMnemonicString( aText
);
235 nTextStyle
&= ~TEXT_DRAW_MNEMONIC
;
238 if ( !(nDrawFlags
& WINDOW_DRAW_NODISABLE
) )
241 nTextStyle
|= TEXT_DRAW_DISABLE
;
243 if ( (nDrawFlags
& WINDOW_DRAW_MONO
) ||
244 (rStyleSettings
.GetOptions() & STYLE_OPTION_MONO
) )
245 nTextStyle
|= TEXT_DRAW_MONO
;
248 mpControlData
->mpLayoutData
->m_aDisplayText
= OUString();
250 Rectangle
aRect( Rectangle( aPos
, rSize
) );
251 DrawControlText( *pDev
, aRect
, aText
, nTextStyle
,
252 bFillLayout
? &mpControlData
->mpLayoutData
->m_aUnicodeBoundRects
: NULL
,
253 bFillLayout
? &mpControlData
->mpLayoutData
->m_aDisplayText
: NULL
257 // -----------------------------------------------------------------------
259 void FixedText::Paint( const Rectangle
& )
261 ImplDraw( this, 0, Point(), GetOutputSizePixel() );
264 // -----------------------------------------------------------------------
266 void FixedText::Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
,
269 ImplInitSettings( sal_True
, sal_True
, sal_True
);
271 Point aPos
= pDev
->LogicToPixel( rPos
);
272 Size aSize
= pDev
->LogicToPixel( rSize
);
273 Font aFont
= GetDrawPixelFont( pDev
);
277 pDev
->SetFont( aFont
);
278 if ( nFlags
& WINDOW_DRAW_MONO
)
279 pDev
->SetTextColor( Color( COL_BLACK
) );
281 pDev
->SetTextColor( GetTextColor() );
282 pDev
->SetTextFillColor();
284 bool bBorder
= !(nFlags
& WINDOW_DRAW_NOBORDER
) && (GetStyle() & WB_BORDER
);
285 bool bBackground
= !(nFlags
& WINDOW_DRAW_NOBACKGROUND
) && IsControlBackground();
286 if ( bBorder
|| bBackground
)
288 Rectangle
aRect( aPos
, aSize
);
291 ImplDrawFrame( pDev
, aRect
);
295 pDev
->SetFillColor( GetControlBackground() );
296 pDev
->DrawRect( aRect
);
300 ImplDraw( pDev
, nFlags
, aPos
, aSize
);
304 // -----------------------------------------------------------------------
306 void FixedText::Resize()
312 // -----------------------------------------------------------------------
314 void FixedText::StateChanged( StateChangedType nType
)
316 Control::StateChanged( nType
);
318 if ( (nType
== STATE_CHANGE_ENABLE
) ||
319 (nType
== STATE_CHANGE_TEXT
) ||
320 (nType
== STATE_CHANGE_UPDATEMODE
) )
322 if ( IsReallyVisible() && IsUpdateMode() )
325 else if ( nType
== STATE_CHANGE_STYLE
)
327 SetStyle( ImplInitStyle( GetStyle() ) );
328 if ( (GetPrevStyle() & FIXEDTEXT_VIEW_STYLE
) !=
329 (GetStyle() & FIXEDTEXT_VIEW_STYLE
) )
331 ImplInitSettings( sal_True
, sal_False
, sal_False
);
335 else if ( (nType
== STATE_CHANGE_ZOOM
) ||
336 (nType
== STATE_CHANGE_CONTROLFONT
) )
338 ImplInitSettings( sal_True
, sal_False
, sal_False
);
341 else if ( nType
== STATE_CHANGE_CONTROLFOREGROUND
)
343 ImplInitSettings( sal_False
, sal_True
, sal_False
);
346 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
348 ImplInitSettings( sal_False
, sal_False
, sal_True
);
353 // -----------------------------------------------------------------------
355 void FixedText::DataChanged( const DataChangedEvent
& rDCEvt
)
357 Control::DataChanged( rDCEvt
);
359 if ( (rDCEvt
.GetType() == DATACHANGED_FONTS
) ||
360 (rDCEvt
.GetType() == DATACHANGED_FONTSUBSTITUTION
) ||
361 ((rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
362 (rDCEvt
.GetFlags() & SETTINGS_STYLE
)) )
364 ImplInitSettings( sal_True
, sal_True
, sal_True
);
369 // -----------------------------------------------------------------------
371 Size
FixedText::getTextDimensions(Control
const *pControl
, const OUString
&rTxt
, long nMaxWidth
)
373 sal_uInt16 nStyle
= ImplGetTextStyle( pControl
->GetStyle() );
374 if ( !( pControl
->GetStyle() & WB_NOLABEL
) )
375 nStyle
|= TEXT_DRAW_MNEMONIC
;
377 return pControl
->GetTextRect(Rectangle( Point(), Size(nMaxWidth
, 0x7fffffff)),
378 rTxt
, nStyle
).GetSize();
382 Size
FixedText::CalcMinimumTextSize( Control
const *pControl
, long nMaxWidth
)
384 Size aSize
= getTextDimensions(pControl
, pControl
->GetText(), nMaxWidth
);
386 if ( pControl
->GetStyle() & WB_EXTRAOFFSET
)
389 // GetTextRect cannot take an empty string
390 if ( aSize
.Width() < 0 )
392 if ( aSize
.Height() <= 0 )
393 aSize
.Height() = pControl
->GetTextHeight();
398 Size
FixedText::CalcMinimumSize( long nMaxWidth
) const
400 return CalcWindowSize( CalcMinimumTextSize ( this, nMaxWidth
) );
402 // -----------------------------------------------------------------------
404 Size
FixedText::GetOptimalSize() const
406 sal_Int32 nMaxAvailWidth
= 0x7fffffff;
407 const OUString
&rTxt
= GetText();
408 if (m_nMaxWidthChars
!= -1 && m_nMaxWidthChars
< rTxt
.getLength())
410 nMaxAvailWidth
= getTextDimensions(this,
411 rTxt
.copy(0, m_nMaxWidthChars
), 0x7fffffff).Width();
413 Size aRet
= CalcMinimumSize(nMaxAvailWidth
);
414 if (m_nMinWidthChars
!= -1)
417 comphelper::string::padToLength(aBuf
, m_nMinWidthChars
, 'x');
418 Size aMinAllowed
= getTextDimensions(this,
419 aBuf
.makeStringAndClear(), 0x7fffffff);
420 if (aMinAllowed
.Width() > aRet
.Width())
426 // -----------------------------------------------------------------------
428 void FixedText::FillLayoutData() const
430 mpControlData
->mpLayoutData
= new vcl::ControlLayoutData();
431 ImplDraw( const_cast<FixedText
*>(this), 0, Point(), GetOutputSizePixel(), true );
434 void FixedText::setMaxWidthChars(sal_Int32 nWidth
)
436 if (nWidth
!= m_nMaxWidthChars
)
438 m_nMaxWidthChars
= nWidth
;
443 void FixedText::setMinWidthChars(sal_Int32 nWidth
)
445 if (nWidth
!= m_nMinWidthChars
)
447 m_nMinWidthChars
= nWidth
;
452 bool FixedText::set_property(const OString
&rKey
, const OString
&rValue
)
454 if (rKey
== "max-width-chars")
455 setMaxWidthChars(rValue
.toInt32());
456 else if (rKey
== "width-chars")
457 setMinWidthChars(rValue
.toInt32());
459 return Control::set_property(rKey
, rValue
);
463 Window
* FixedText::getAccessibleRelationLabelFor() const
465 Window
*pWindow
= Control::getAccessibleRelationLabelFor();
468 return get_mnemonic_widget();
471 void FixedText::set_mnemonic_widget(Window
*pWindow
)
473 if (pWindow
== m_pMnemonicWindow
)
475 if (m_pMnemonicWindow
)
477 Window
*pTempReEntryGuard
= m_pMnemonicWindow
;
478 m_pMnemonicWindow
= NULL
;
479 pTempReEntryGuard
->remove_mnemonic_label(this);
481 m_pMnemonicWindow
= pWindow
;
482 if (m_pMnemonicWindow
)
483 m_pMnemonicWindow
->add_mnemonic_label(this);
486 FixedText::~FixedText()
488 set_mnemonic_widget(NULL
);
491 SelectableFixedText::SelectableFixedText(Window
* pParent
, WinBits nStyle
)
492 : Edit(pParent
, nStyle
)
495 SetBorderStyle( WINDOW_BORDER_NOBORDER
);
498 // make it transparent
499 SetControlBackground();
501 SetPaintTransparent( sal_True
);
504 // -----------------------------------------------------------------------
506 void SelectableFixedText::LoseFocus()
513 // =======================================================================
515 void FixedLine::ImplInit( Window
* pParent
, WinBits nStyle
)
517 nStyle
= ImplInitStyle( nStyle
);
518 Control::ImplInit( pParent
, nStyle
, NULL
);
519 ImplInitSettings( sal_True
, sal_True
, sal_True
);
522 // -----------------------------------------------------------------------
524 WinBits
FixedLine::ImplInitStyle( WinBits nStyle
)
526 if ( !(nStyle
& WB_NOGROUP
) )
531 // -----------------------------------------------------------------
533 const Font
& FixedLine::GetCanonicalFont( const StyleSettings
& _rStyle
) const
535 return _rStyle
.GetGroupFont();
538 // -----------------------------------------------------------------
539 const Color
& FixedLine::GetCanonicalTextColor( const StyleSettings
& _rStyle
) const
541 return _rStyle
.GetGroupTextColor();
544 // -----------------------------------------------------------------------
546 void FixedLine::ImplInitSettings( sal_Bool bFont
,
547 sal_Bool bForeground
, sal_Bool bBackground
)
549 Control::ImplInitSettings( bFont
, bForeground
);
553 Window
* pParent
= GetParent();
554 if ( pParent
->IsChildTransparentModeEnabled() && !IsControlBackground() )
556 EnableChildTransparentMode( sal_True
);
557 SetParentClipMode( PARENTCLIPMODE_NOCLIP
);
558 SetPaintTransparent( sal_True
);
563 EnableChildTransparentMode( sal_False
);
564 SetParentClipMode( 0 );
565 SetPaintTransparent( sal_False
);
567 if ( IsControlBackground() )
568 SetBackground( GetControlBackground() );
570 SetBackground( pParent
->GetBackground() );
575 // -----------------------------------------------------------------------
577 void FixedLine::ImplDraw( bool bLayout
)
579 Size aOutSize
= GetOutputSizePixel();
580 String aText
= GetText();
581 WinBits nWinStyle
= GetStyle();
582 MetricVector
* pVector
= bLayout
? &mpControlData
->mpLayoutData
->m_aUnicodeBoundRects
: NULL
;
583 OUString
* pDisplayText
= bLayout
? &mpControlData
->mpLayoutData
->m_aDisplayText
: NULL
;
585 DecorationView
aDecoView( this );
590 if ( nWinStyle
& WB_VERT
)
592 long nX
= (aOutSize
.Width()-1)/2;
593 aDecoView
.DrawSeparator( Point( nX
, 0 ), Point( nX
, aOutSize
.Height()-1 ) );
597 long nY
= (aOutSize
.Height()-1)/2;
598 aDecoView
.DrawSeparator( Point( 0, nY
), Point( aOutSize
.Width()-1, nY
), false );
602 else if( (nWinStyle
& WB_VERT
) )
604 long nWidth
= GetTextWidth( aText
);
606 Font
aFont( GetFont() );
607 aFont
.SetOrientation( 900 );
609 Point
aStartPt( aOutSize
.Width()/2, aOutSize
.Height()-1 );
610 if( (nWinStyle
& WB_VCENTER
) )
611 aStartPt
.Y() -= (aOutSize
.Height() - nWidth
)/2;
612 Point
aTextPt( aStartPt
);
613 aTextPt
.X() -= GetTextHeight()/2;
614 DrawText( aTextPt
, aText
, 0, STRING_LEN
, pVector
, pDisplayText
);
616 if( aOutSize
.Height() - aStartPt
.Y() > FIXEDLINE_TEXT_BORDER
)
617 aDecoView
.DrawSeparator( Point( aStartPt
.X(), aOutSize
.Height()-1 ),
618 Point( aStartPt
.X(), aStartPt
.Y() + FIXEDLINE_TEXT_BORDER
) );
619 if( aStartPt
.Y() - nWidth
- FIXEDLINE_TEXT_BORDER
> 0 )
620 aDecoView
.DrawSeparator( Point( aStartPt
.X(), aStartPt
.Y() - nWidth
- FIXEDLINE_TEXT_BORDER
),
621 Point( aStartPt
.X(), 0 ) );
625 sal_uInt16 nStyle
= TEXT_DRAW_MNEMONIC
| TEXT_DRAW_LEFT
| TEXT_DRAW_VCENTER
| TEXT_DRAW_ENDELLIPSIS
;
626 Rectangle
aRect( 0, 0, aOutSize
.Width(), aOutSize
.Height() );
627 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
628 if( (nWinStyle
& WB_CENTER
) )
629 nStyle
|= TEXT_DRAW_CENTER
;
632 nStyle
|= TEXT_DRAW_DISABLE
;
633 if ( GetStyle() & WB_NOLABEL
)
634 nStyle
&= ~TEXT_DRAW_MNEMONIC
;
635 if ( rStyleSettings
.GetOptions() & STYLE_OPTION_MONO
)
636 nStyle
|= TEXT_DRAW_MONO
;
638 DrawControlText( *this, aRect
, aText
, nStyle
, pVector
, pDisplayText
);
642 long nTop
= aRect
.Top() + ((aRect
.GetHeight()-1)/2);
643 aDecoView
.DrawSeparator( Point( aRect
.Right()+FIXEDLINE_TEXT_BORDER
, nTop
), Point( aOutSize
.Width()-1, nTop
), false );
644 if( aRect
.Left() > FIXEDLINE_TEXT_BORDER
)
645 aDecoView
.DrawSeparator( Point( 0, nTop
), Point( aRect
.Left()-FIXEDLINE_TEXT_BORDER
, nTop
), false );
650 // -----------------------------------------------------------------------
652 FixedLine::FixedLine( Window
* pParent
, WinBits nStyle
) :
653 Control( WINDOW_FIXEDLINE
)
655 ImplInit( pParent
, nStyle
);
656 SetSizePixel( Size( 2, 2 ) );
659 // -----------------------------------------------------------------------
661 FixedLine::FixedLine( Window
* pParent
, const ResId
& rResId
) :
662 Control( WINDOW_FIXEDLINE
)
664 rResId
.SetRT( RSC_FIXEDLINE
);
665 WinBits nStyle
= ImplInitRes( rResId
);
666 ImplInit( pParent
, nStyle
);
667 ImplLoadRes( rResId
);
669 if ( !(nStyle
& WB_HIDE
) )
673 // -----------------------------------------------------------------------
675 void FixedLine::FillLayoutData() const
677 mpControlData
->mpLayoutData
= new vcl::ControlLayoutData();
678 const_cast<FixedLine
*>(this)->ImplDraw( true );
682 // -----------------------------------------------------------------------
684 void FixedLine::Paint( const Rectangle
& )
689 // -----------------------------------------------------------------------
691 void FixedLine::Draw( OutputDevice
*, const Point
&, const Size
&, sal_uLong
)
695 // -----------------------------------------------------------------------
697 void FixedLine::Resize()
703 // -----------------------------------------------------------------------
705 void FixedLine::StateChanged( StateChangedType nType
)
707 Control::StateChanged( nType
);
709 if ( (nType
== STATE_CHANGE_ENABLE
) ||
710 (nType
== STATE_CHANGE_TEXT
) ||
711 (nType
== STATE_CHANGE_UPDATEMODE
) )
713 if ( IsReallyVisible() && IsUpdateMode() )
716 else if ( nType
== STATE_CHANGE_STYLE
)
718 SetStyle( ImplInitStyle( GetStyle() ) );
719 if ( (GetPrevStyle() & FIXEDLINE_VIEW_STYLE
) !=
720 (GetStyle() & FIXEDLINE_VIEW_STYLE
) )
723 else if ( (nType
== STATE_CHANGE_ZOOM
) ||
724 (nType
== STATE_CHANGE_STYLE
) ||
725 (nType
== STATE_CHANGE_CONTROLFONT
) )
727 ImplInitSettings( sal_True
, sal_False
, sal_False
);
730 else if ( nType
== STATE_CHANGE_CONTROLFOREGROUND
)
732 ImplInitSettings( sal_False
, sal_True
, sal_False
);
735 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
737 ImplInitSettings( sal_False
, sal_False
, sal_True
);
742 // -----------------------------------------------------------------------
744 void FixedLine::DataChanged( const DataChangedEvent
& rDCEvt
)
746 Control::DataChanged( rDCEvt
);
748 if ( (rDCEvt
.GetType() == DATACHANGED_FONTS
) ||
749 (rDCEvt
.GetType() == DATACHANGED_FONTSUBSTITUTION
) ||
750 ((rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
751 (rDCEvt
.GetFlags() & SETTINGS_STYLE
)) )
753 ImplInitSettings( sal_True
, sal_True
, sal_True
);
758 // -----------------------------------------------------------------------
760 Size
FixedLine::GetOptimalSize() const
762 return CalcWindowSize( FixedText::CalcMinimumTextSize ( this, 0x7fffffff ) );
765 // =======================================================================
767 void FixedBitmap::ImplInit( Window
* pParent
, WinBits nStyle
)
769 nStyle
= ImplInitStyle( nStyle
);
770 Control::ImplInit( pParent
, nStyle
, NULL
);
774 // -----------------------------------------------------------------------
776 WinBits
FixedBitmap::ImplInitStyle( WinBits nStyle
)
778 if ( !(nStyle
& WB_NOGROUP
) )
783 // -----------------------------------------------------------------------
785 void FixedBitmap::ImplInitSettings()
787 Window
* pParent
= GetParent();
788 if ( pParent
->IsChildTransparentModeEnabled() && !IsControlBackground() )
790 EnableChildTransparentMode( sal_True
);
791 SetParentClipMode( PARENTCLIPMODE_NOCLIP
);
792 SetPaintTransparent( sal_True
);
797 EnableChildTransparentMode( sal_False
);
798 SetParentClipMode( 0 );
799 SetPaintTransparent( sal_False
);
801 if ( IsControlBackground() )
802 SetBackground( GetControlBackground() );
804 SetBackground( pParent
->GetBackground() );
808 // -----------------------------------------------------------------------
810 void FixedBitmap::ImplLoadRes( const ResId
& rResId
)
812 Control::ImplLoadRes( rResId
);
814 sal_uLong nObjMask
= ReadLongRes();
816 if ( RSC_FIXEDBITMAP_BITMAP
& nObjMask
)
818 maBitmap
= Bitmap( ResId( (RSHEADER_TYPE
*)GetClassRes(), *rResId
.GetResMgr() ) );
819 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE
*)GetClassRes() ) );
823 // -----------------------------------------------------------------------
825 FixedBitmap::FixedBitmap( Window
* pParent
, WinBits nStyle
) :
826 Control( WINDOW_FIXEDBITMAP
)
828 ImplInit( pParent
, nStyle
);
831 // -----------------------------------------------------------------------
833 FixedBitmap::FixedBitmap( Window
* pParent
, const ResId
& rResId
) :
834 Control( WINDOW_FIXEDBITMAP
)
836 rResId
.SetRT( RSC_FIXEDBITMAP
);
837 WinBits nStyle
= ImplInitRes( rResId
);
838 ImplInit( pParent
, nStyle
);
839 ImplLoadRes( rResId
);
841 if ( !(nStyle
& WB_HIDE
) )
845 // -----------------------------------------------------------------------
847 FixedBitmap::~FixedBitmap()
851 // -----------------------------------------------------------------------
853 void FixedBitmap::ImplDraw( OutputDevice
* pDev
, sal_uLong
/* nDrawFlags */,
854 const Point
& rPos
, const Size
& rSize
)
856 sal_uInt16 nStyle
= 0;
857 Bitmap
* pBitmap
= &maBitmap
;
859 if( nStyle
& IMAGE_DRAW_COLORTRANSFORM
)
861 // only images support IMAGE_DRAW_COLORTRANSFORM
862 Image
aImage( maBitmap
);
865 if ( GetStyle() & WB_SCALE
)
866 pDev
->DrawImage( rPos
, rSize
, aImage
, nStyle
);
869 Point aPos
= ImplCalcPos( GetStyle(), rPos
, aImage
.GetSizePixel(), rSize
);
870 pDev
->DrawImage( aPos
, aImage
, nStyle
);
876 // do we have a Bitmap?
877 if ( !(!(*pBitmap
)) )
879 if ( GetStyle() & WB_SCALE
)
880 pDev
->DrawBitmap( rPos
, rSize
, *pBitmap
);
883 Point aPos
= ImplCalcPos( GetStyle(), rPos
, pBitmap
->GetSizePixel(), rSize
);
884 pDev
->DrawBitmap( aPos
, *pBitmap
);
890 // -----------------------------------------------------------------------
892 void FixedBitmap::Paint( const Rectangle
& )
894 ImplDraw( this, 0, Point(), GetOutputSizePixel() );
897 // -----------------------------------------------------------------------
899 void FixedBitmap::Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
,
902 Point aPos
= pDev
->LogicToPixel( rPos
);
903 Size aSize
= pDev
->LogicToPixel( rSize
);
904 Rectangle
aRect( aPos
, aSize
);
910 if ( !(nFlags
& WINDOW_DRAW_NOBORDER
) && (GetStyle() & WB_BORDER
) )
912 DecorationView
aDecoView( pDev
);
913 aRect
= aDecoView
.DrawFrame( aRect
, FRAME_DRAW_DOUBLEIN
);
915 pDev
->IntersectClipRegion( aRect
);
916 ImplDraw( pDev
, nFlags
, aRect
.TopLeft(), aRect
.GetSize() );
921 // -----------------------------------------------------------------------
923 void FixedBitmap::Resize()
929 // -----------------------------------------------------------------------
931 void FixedBitmap::StateChanged( StateChangedType nType
)
933 Control::StateChanged( nType
);
935 if ( (nType
== STATE_CHANGE_DATA
) ||
936 (nType
== STATE_CHANGE_UPDATEMODE
) )
938 if ( IsReallyVisible() && IsUpdateMode() )
941 else if ( nType
== STATE_CHANGE_STYLE
)
943 SetStyle( ImplInitStyle( GetStyle() ) );
944 if ( (GetPrevStyle() & FIXEDBITMAP_VIEW_STYLE
) !=
945 (GetStyle() & FIXEDBITMAP_VIEW_STYLE
) )
948 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
955 // -----------------------------------------------------------------------
957 void FixedBitmap::DataChanged( const DataChangedEvent
& rDCEvt
)
959 Control::DataChanged( rDCEvt
);
961 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
962 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
969 // -----------------------------------------------------------------------
971 void FixedBitmap::SetBitmap( const Bitmap
& rBitmap
)
974 StateChanged( STATE_CHANGE_DATA
);
978 // =======================================================================
980 void FixedImage::ImplInit( Window
* pParent
, WinBits nStyle
)
982 nStyle
= ImplInitStyle( nStyle
);
983 mbInUserDraw
= sal_False
;
984 Control::ImplInit( pParent
, nStyle
, NULL
);
988 // -----------------------------------------------------------------------
990 WinBits
FixedImage::ImplInitStyle( WinBits nStyle
)
992 if ( !(nStyle
& WB_NOGROUP
) )
997 // -----------------------------------------------------------------------
999 void FixedImage::ImplInitSettings()
1001 Window
* pParent
= GetParent();
1002 if ( pParent
&& pParent
->IsChildTransparentModeEnabled() && !IsControlBackground() )
1004 EnableChildTransparentMode( sal_True
);
1005 SetParentClipMode( PARENTCLIPMODE_NOCLIP
);
1006 SetPaintTransparent( sal_True
);
1011 EnableChildTransparentMode( sal_False
);
1012 SetParentClipMode( 0 );
1013 SetPaintTransparent( sal_False
);
1015 if ( IsControlBackground() )
1016 SetBackground( GetControlBackground() );
1018 SetBackground( pParent
->GetBackground() );
1022 // -----------------------------------------------------------------------
1024 void FixedImage::ImplLoadRes( const ResId
& rResId
)
1026 Control::ImplLoadRes( rResId
);
1028 sal_uLong nObjMask
= ReadLongRes();
1030 if ( RSC_FIXEDIMAGE_IMAGE
& nObjMask
)
1032 maImage
= Image( ResId( (RSHEADER_TYPE
*)GetClassRes(), *rResId
.GetResMgr() ) );
1033 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE
*)GetClassRes() ) );
1037 // -----------------------------------------------------------------------
1039 FixedImage::FixedImage( Window
* pParent
, WinBits nStyle
) :
1040 Control( WINDOW_FIXEDIMAGE
)
1042 ImplInit( pParent
, nStyle
);
1045 // -----------------------------------------------------------------------
1047 FixedImage::FixedImage( Window
* pParent
, const ResId
& rResId
) :
1048 Control( WINDOW_FIXEDIMAGE
)
1050 rResId
.SetRT( RSC_FIXEDIMAGE
);
1051 WinBits nStyle
= ImplInitRes( rResId
);
1052 ImplInit( pParent
, nStyle
);
1053 ImplLoadRes( rResId
);
1055 if ( !(nStyle
& WB_HIDE
) )
1059 // -----------------------------------------------------------------------
1061 FixedImage::~FixedImage()
1065 // -----------------------------------------------------------------------
1067 void FixedImage::ImplDraw( OutputDevice
* pDev
, sal_uLong nDrawFlags
,
1068 const Point
& rPos
, const Size
& rSize
)
1070 sal_uInt16 nStyle
= 0;
1071 if ( !(nDrawFlags
& WINDOW_DRAW_NODISABLE
) )
1074 nStyle
|= IMAGE_DRAW_DISABLE
;
1077 Image
*pImage
= &maImage
;
1079 // do we have an image?
1080 if ( !(!(*pImage
)) )
1082 if ( GetStyle() & WB_SCALE
)
1083 pDev
->DrawImage( rPos
, rSize
, *pImage
, nStyle
);
1086 Point aPos
= ImplCalcPos( GetStyle(), rPos
, pImage
->GetSizePixel(), rSize
);
1087 pDev
->DrawImage( aPos
, *pImage
, nStyle
);
1091 mbInUserDraw
= sal_True
;
1092 UserDrawEvent
aUDEvt( pDev
, Rectangle( rPos
, rSize
), 0, nStyle
);
1094 mbInUserDraw
= sal_False
;
1097 // -----------------------------------------------------------------------
1099 void FixedImage::Paint( const Rectangle
& )
1101 ImplDraw( this, 0, Point(), GetOutputSizePixel() );
1104 // -----------------------------------------------------------------------
1106 Size
FixedImage::GetOptimalSize() const
1108 return maImage
.GetSizePixel();
1111 // -----------------------------------------------------------------------
1113 void FixedImage::UserDraw( const UserDrawEvent
& )
1117 // -----------------------------------------------------------------------
1119 void FixedImage::Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
,
1122 Point aPos
= pDev
->LogicToPixel( rPos
);
1123 Size aSize
= pDev
->LogicToPixel( rSize
);
1124 Rectangle
aRect( aPos
, aSize
);
1130 if ( !(nFlags
& WINDOW_DRAW_NOBORDER
) && (GetStyle() & WB_BORDER
) )
1132 ImplDrawFrame( pDev
, aRect
);
1134 pDev
->IntersectClipRegion( aRect
);
1135 ImplDraw( pDev
, nFlags
, aRect
.TopLeft(), aRect
.GetSize() );
1140 // -----------------------------------------------------------------------
1142 void FixedImage::Resize()
1148 // -----------------------------------------------------------------------
1150 void FixedImage::StateChanged( StateChangedType nType
)
1152 Control::StateChanged( nType
);
1154 if ( (nType
== STATE_CHANGE_ENABLE
) ||
1155 (nType
== STATE_CHANGE_DATA
) ||
1156 (nType
== STATE_CHANGE_UPDATEMODE
) )
1158 if ( IsReallyVisible() && IsUpdateMode() )
1161 else if ( nType
== STATE_CHANGE_STYLE
)
1163 SetStyle( ImplInitStyle( GetStyle() ) );
1164 if ( (GetPrevStyle() & FIXEDIMAGE_VIEW_STYLE
) !=
1165 (GetStyle() & FIXEDIMAGE_VIEW_STYLE
) )
1168 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
1175 // -----------------------------------------------------------------------
1177 void FixedImage::DataChanged( const DataChangedEvent
& rDCEvt
)
1179 Control::DataChanged( rDCEvt
);
1181 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
1182 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
1189 // -----------------------------------------------------------------------
1191 void FixedImage::SetImage( const Image
& rImage
)
1193 if ( rImage
!= maImage
)
1196 StateChanged( STATE_CHANGE_DATA
);
1201 // -----------------------------------------------------------------------
1203 sal_Bool
FixedImage::SetModeImage( const Image
& rImage
)
1209 // -----------------------------------------------------------------------
1211 const Image
& FixedImage::GetModeImage( ) const
1216 bool FixedImage::set_property(const OString
&rKey
, const OString
&rValue
)
1218 if (rKey
== "pixbuf")
1220 static ImplImageTreeSingletonRef aImageTree
;
1221 OUString sCurrentSymbolsStyle
=
1222 Application::GetSettings().GetStyleSettings().GetCurrentSymbolsStyleName();
1223 const OUString
sFileName(OStringToOUString(rValue
, RTL_TEXTENCODING_UTF8
));
1225 bool bSuccess
= aImageTree
->loadImage(sFileName
, sCurrentSymbolsStyle
, aBitmap
, true);
1226 SAL_WARN_IF(!bSuccess
, "vcl.layout", "Unable to load " << sFileName
1227 << " from theme " << sCurrentSymbolsStyle
);
1228 SetImage(Image(aBitmap
));
1231 return Control::set_property(rKey
, rValue
);
1235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */