bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / control / fixed.cxx
blob237f2f30e3047cba6df19113048a917422176293
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <vcl/decoview.hxx>
21 #include <vcl/event.hxx>
22 #include <vcl/fixed.hxx>
23 #include <vcl/settings.hxx>
25 #include <comphelper/string.hxx>
26 #include <sal/log.hxx>
27 #include <controldata.hxx>
29 #define FIXEDLINE_TEXT_BORDER 4
31 static constexpr auto FIXEDTEXT_VIEW_STYLE = WB_3DLOOK |
32 WB_LEFT | WB_CENTER | WB_RIGHT |
33 WB_TOP | WB_VCENTER | WB_BOTTOM |
34 WB_WORDBREAK | WB_NOLABEL |
35 WB_PATHELLIPSIS;
36 static constexpr auto FIXEDLINE_VIEW_STYLE = WB_3DLOOK | WB_NOLABEL;
37 static constexpr auto FIXEDBITMAP_VIEW_STYLE = WB_3DLOOK |
38 WB_LEFT | WB_CENTER | WB_RIGHT |
39 WB_TOP | WB_VCENTER | WB_BOTTOM |
40 WB_SCALE;
41 static constexpr auto FIXEDIMAGE_VIEW_STYLE = WB_3DLOOK |
42 WB_LEFT | WB_CENTER | WB_RIGHT |
43 WB_TOP | WB_VCENTER | WB_BOTTOM |
44 WB_SCALE;
46 static Point ImplCalcPos( WinBits nStyle, const Point& rPos,
47 const Size& rObjSize, const Size& rWinSize )
49 long nX;
50 long nY;
52 if ( nStyle & WB_LEFT )
53 nX = 0;
54 else if ( nStyle & WB_RIGHT )
55 nX = rWinSize.Width()-rObjSize.Width();
56 else
57 nX = (rWinSize.Width()-rObjSize.Width())/2;
59 if ( nStyle & WB_TOP )
60 nY = 0;
61 else if ( nStyle & WB_BOTTOM )
62 nY = rWinSize.Height()-rObjSize.Height();
63 else
64 nY = (rWinSize.Height()-rObjSize.Height())/2;
66 Point aPos( nX+rPos.X(), nY+rPos.Y() );
67 return aPos;
70 void FixedText::ImplInit( vcl::Window* pParent, WinBits nStyle )
72 nStyle = ImplInitStyle( nStyle );
73 Control::ImplInit( pParent, nStyle, nullptr );
74 ApplySettings(*this);
77 WinBits FixedText::ImplInitStyle( WinBits nStyle )
79 if ( !(nStyle & WB_NOGROUP) )
80 nStyle |= WB_GROUP;
81 return nStyle;
84 const vcl::Font& FixedText::GetCanonicalFont( const StyleSettings& _rStyle ) const
86 return _rStyle.GetLabelFont();
89 const Color& FixedText::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
91 return _rStyle.GetLabelTextColor();
94 FixedText::FixedText( vcl::Window* pParent, WinBits nStyle )
95 : Control(WindowType::FIXEDTEXT)
96 , m_nMaxWidthChars(-1)
97 , m_nMinWidthChars(-1)
98 , m_pMnemonicWindow(nullptr)
100 ImplInit( pParent, nStyle );
103 DrawTextFlags FixedText::ImplGetTextStyle( WinBits nWinStyle )
105 DrawTextFlags nTextStyle = DrawTextFlags::Mnemonic | DrawTextFlags::EndEllipsis;
107 if( ! (nWinStyle & WB_NOMULTILINE) )
108 nTextStyle |= DrawTextFlags::MultiLine;
110 if ( nWinStyle & WB_RIGHT )
111 nTextStyle |= DrawTextFlags::Right;
112 else if ( nWinStyle & WB_CENTER )
113 nTextStyle |= DrawTextFlags::Center;
114 else
115 nTextStyle |= DrawTextFlags::Left;
116 if ( nWinStyle & WB_BOTTOM )
117 nTextStyle |= DrawTextFlags::Bottom;
118 else if ( nWinStyle & WB_VCENTER )
119 nTextStyle |= DrawTextFlags::VCenter;
120 else
121 nTextStyle |= DrawTextFlags::Top;
122 if ( nWinStyle & WB_WORDBREAK )
124 nTextStyle |= DrawTextFlags::WordBreak;
125 if ( (nWinStyle & WB_HYPHENATION ) == WB_HYPHENATION )
126 nTextStyle |= DrawTextFlags::WordBreakHyphenation;
128 if ( nWinStyle & WB_NOLABEL )
129 nTextStyle &= ~DrawTextFlags::Mnemonic;
131 return nTextStyle;
134 void FixedText::ImplDraw(OutputDevice* pDev, DrawFlags nDrawFlags,
135 const Point& rPos, const Size& rSize,
136 bool bFillLayout) const
138 const StyleSettings& rStyleSettings = pDev->GetSettings().GetStyleSettings();
139 WinBits nWinStyle = GetStyle();
140 OUString aText(GetText());
141 DrawTextFlags nTextStyle = FixedText::ImplGetTextStyle( nWinStyle );
142 Point aPos = rPos;
144 if ( nWinStyle & WB_EXTRAOFFSET )
145 aPos.AdjustX(2 );
147 if ( nWinStyle & WB_PATHELLIPSIS )
149 nTextStyle &= ~DrawTextFlags(DrawTextFlags::EndEllipsis | DrawTextFlags::MultiLine | DrawTextFlags::WordBreak);
150 nTextStyle |= DrawTextFlags::PathEllipsis;
152 if ( !IsEnabled() )
153 nTextStyle |= DrawTextFlags::Disable;
154 if ( (nDrawFlags & DrawFlags::Mono) ||
155 (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono) )
156 nTextStyle |= DrawTextFlags::Mono;
158 if( bFillLayout )
159 mpControlData->mpLayoutData->m_aDisplayText.clear();
161 const tools::Rectangle aRect(aPos, rSize);
162 DrawControlText(*pDev, aRect, aText, nTextStyle,
163 bFillLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : nullptr,
164 bFillLayout ? &mpControlData->mpLayoutData->m_aDisplayText : nullptr);
167 void FixedText::ApplySettings(vcl::RenderContext& rRenderContext)
169 Control::ApplySettings(rRenderContext);
171 vcl::Window* pParent = GetParent();
172 bool bEnableTransparent = true;
173 if (!pParent->IsChildTransparentModeEnabled() || IsControlBackground())
175 EnableChildTransparentMode(false);
176 SetParentClipMode();
177 SetPaintTransparent(false);
179 if (IsControlBackground())
180 rRenderContext.SetBackground(GetControlBackground());
181 else
182 rRenderContext.SetBackground(pParent->GetBackground());
184 if (rRenderContext.IsBackground())
185 bEnableTransparent = false;
188 if (bEnableTransparent)
190 EnableChildTransparentMode();
191 SetParentClipMode(ParentClipMode::NoClip);
192 SetPaintTransparent(true);
193 rRenderContext.SetBackground();
197 void FixedText::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
199 ImplDraw(&rRenderContext, DrawFlags::NONE, Point(), GetOutputSizePixel());
202 void FixedText::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
203 DrawFlags nFlags )
205 ApplySettings(*pDev);
207 Point aPos = pDev->LogicToPixel( rPos );
208 Size aSize = pDev->LogicToPixel( rSize );
209 vcl::Font aFont = GetDrawPixelFont( pDev );
211 pDev->Push();
212 pDev->SetMapMode();
213 pDev->SetFont( aFont );
214 if ( nFlags & DrawFlags::Mono )
215 pDev->SetTextColor( COL_BLACK );
216 else
217 pDev->SetTextColor( GetTextColor() );
218 pDev->SetTextFillColor();
220 bool bBorder = (GetStyle() & WB_BORDER);
221 bool bBackground = IsControlBackground();
222 if ( bBorder || bBackground )
224 tools::Rectangle aRect( aPos, aSize );
225 if ( bBorder )
227 ImplDrawFrame( pDev, aRect );
229 if ( bBackground )
231 pDev->SetFillColor( GetControlBackground() );
232 pDev->DrawRect( aRect );
236 ImplDraw( pDev, nFlags, aPos, aSize );
237 pDev->Pop();
240 void FixedText::Resize()
242 Control::Resize();
243 Invalidate();
246 void FixedText::StateChanged( StateChangedType nType )
248 Control::StateChanged( nType );
250 if ( (nType == StateChangedType::Enable) ||
251 (nType == StateChangedType::Text) ||
252 (nType == StateChangedType::UpdateMode) )
254 if ( IsReallyVisible() && IsUpdateMode() )
255 Invalidate();
257 else if ( nType == StateChangedType::Style )
259 SetStyle( ImplInitStyle( GetStyle() ) );
260 if ( (GetPrevStyle() & FIXEDTEXT_VIEW_STYLE) !=
261 (GetStyle() & FIXEDTEXT_VIEW_STYLE) )
263 ApplySettings(*this);
264 Invalidate();
267 else if ( (nType == StateChangedType::Zoom) ||
268 (nType == StateChangedType::ControlFont) )
270 ApplySettings(*this);
271 Invalidate();
273 else if ( nType == StateChangedType::ControlForeground )
275 ApplySettings(*this);
276 Invalidate();
278 else if ( nType == StateChangedType::ControlBackground )
280 ApplySettings(*this);
281 Invalidate();
285 void FixedText::DataChanged( const DataChangedEvent& rDCEvt )
287 Control::DataChanged( rDCEvt );
289 if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
290 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
291 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
292 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
294 ApplySettings(*this);
295 Invalidate();
299 Size FixedText::getTextDimensions(Control const *pControl, const OUString &rTxt, long nMaxWidth)
301 DrawTextFlags nStyle = ImplGetTextStyle( pControl->GetStyle() );
302 if ( !( pControl->GetStyle() & WB_NOLABEL ) )
303 nStyle |= DrawTextFlags::Mnemonic;
305 return pControl->GetTextRect(tools::Rectangle( Point(), Size(nMaxWidth, 0x7fffffff)),
306 rTxt, nStyle).GetSize();
309 Size FixedText::CalcMinimumTextSize( Control const *pControl, long nMaxWidth )
311 Size aSize = getTextDimensions(pControl, pControl->GetText(), nMaxWidth);
313 if ( pControl->GetStyle() & WB_EXTRAOFFSET )
314 aSize.AdjustWidth(2 );
316 // GetTextRect cannot take an empty string
317 if ( aSize.Width() < 0 )
318 aSize.setWidth( 0 );
319 if ( aSize.Height() <= 0 )
320 aSize.setHeight( pControl->GetTextHeight() );
322 return aSize;
325 Size FixedText::CalcMinimumSize( long nMaxWidth ) const
327 return CalcWindowSize( CalcMinimumTextSize ( this, nMaxWidth ) );
330 Size FixedText::GetOptimalSize() const
332 sal_Int32 nMaxAvailWidth = 0x7fffffff;
333 if (m_nMaxWidthChars != -1)
335 OUStringBuffer aBuf;
336 comphelper::string::padToLength(aBuf, m_nMaxWidthChars, 'x');
337 nMaxAvailWidth = getTextDimensions(this,
338 aBuf.makeStringAndClear(), 0x7fffffff).Width();
340 Size aRet = CalcMinimumSize(nMaxAvailWidth);
341 if (m_nMinWidthChars != -1)
343 OUStringBuffer aBuf;
344 comphelper::string::padToLength(aBuf, m_nMinWidthChars, 'x');
345 Size aMinAllowed = getTextDimensions(this,
346 aBuf.makeStringAndClear(), 0x7fffffff);
347 aRet.setWidth(std::max(aMinAllowed.Width(), aRet.Width()));
349 return aRet;
352 void FixedText::FillLayoutData() const
354 mpControlData->mpLayoutData.reset( new vcl::ControlLayoutData );
355 ImplDraw(const_cast<FixedText*>(this), DrawFlags::NONE, Point(), GetOutputSizePixel(), true);
356 //const_cast<FixedText*>(this)->Invalidate();
359 void FixedText::setMaxWidthChars(sal_Int32 nWidth)
361 if (nWidth != m_nMaxWidthChars)
363 m_nMaxWidthChars = nWidth;
364 queue_resize();
368 void FixedText::setMinWidthChars(sal_Int32 nWidth)
370 if (nWidth != m_nMinWidthChars)
372 m_nMinWidthChars = nWidth;
373 queue_resize();
377 bool FixedText::set_property(const OString &rKey, const OUString &rValue)
379 if (rKey == "max-width-chars")
380 setMaxWidthChars(rValue.toInt32());
381 else if (rKey == "width-chars")
382 setMinWidthChars(rValue.toInt32());
383 else if (rKey == "ellipsize")
385 WinBits nBits = GetStyle();
386 nBits &= ~WB_PATHELLIPSIS;
387 if (rValue != "none")
389 SAL_WARN_IF(rValue != "end", "vcl.layout", "Only endellipsis support for now");
390 nBits |= WB_PATHELLIPSIS;
392 SetStyle(nBits);
394 else
395 return Control::set_property(rKey, rValue);
396 return true;
399 vcl::Window* FixedText::getAccessibleRelationLabelFor() const
401 vcl::Window *pWindow = Control::getAccessibleRelationLabelFor();
402 if (pWindow)
403 return pWindow;
404 return get_mnemonic_widget();
407 void FixedText::set_mnemonic_widget(vcl::Window *pWindow)
409 if (pWindow == m_pMnemonicWindow)
410 return;
411 if (m_pMnemonicWindow)
413 vcl::Window *pTempReEntryGuard = m_pMnemonicWindow;
414 m_pMnemonicWindow = nullptr;
415 pTempReEntryGuard->remove_mnemonic_label(this);
417 m_pMnemonicWindow = pWindow;
418 if (m_pMnemonicWindow)
419 m_pMnemonicWindow->add_mnemonic_label(this);
422 FixedText::~FixedText()
424 disposeOnce();
427 void FixedText::dispose()
429 set_mnemonic_widget(nullptr);
430 m_pMnemonicWindow.clear();
431 Control::dispose();
434 SelectableFixedText::SelectableFixedText(vcl::Window* pParent, WinBits nStyle)
435 : Edit(pParent, nStyle)
437 // no border
438 SetBorderStyle( WindowBorderStyle::NOBORDER );
439 // read-only
440 SetReadOnly();
441 // make it transparent
442 SetPaintTransparent(true);
443 SetControlBackground();
446 void SelectableFixedText::ApplySettings(vcl::RenderContext& rRenderContext)
448 rRenderContext.SetBackground();
451 void SelectableFixedText::LoseFocus()
453 Edit::LoseFocus();
454 // clear cursor
455 Invalidate();
458 void FixedLine::ImplInit( vcl::Window* pParent, WinBits nStyle )
460 nStyle = ImplInitStyle( nStyle );
461 Control::ImplInit( pParent, nStyle, nullptr );
462 ApplySettings(*this);
465 WinBits FixedLine::ImplInitStyle( WinBits nStyle )
467 if ( !(nStyle & WB_NOGROUP) )
468 nStyle |= WB_GROUP;
469 return nStyle;
472 const vcl::Font& FixedLine::GetCanonicalFont( const StyleSettings& _rStyle ) const
474 return _rStyle.GetGroupFont();
477 const Color& FixedLine::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
479 return _rStyle.GetGroupTextColor();
482 void FixedLine::ImplDraw(vcl::RenderContext& rRenderContext)
484 // we need to measure according to the window, not according to the
485 // RenderContext we paint to
486 Size aOutSize = GetOutputSizePixel();
488 OUString aText = GetText();
489 WinBits nWinStyle = GetStyle();
491 DecorationView aDecoView(&rRenderContext);
492 if (aText.isEmpty())
494 if (nWinStyle & WB_VERT)
496 long nX = (aOutSize.Width() - 1) / 2;
497 aDecoView.DrawSeparator(Point(nX, 0), Point(nX, aOutSize.Height() - 1));
499 else
501 long nY = (aOutSize.Height() - 1) / 2;
502 aDecoView.DrawSeparator(Point(0, nY), Point(aOutSize.Width() - 1, nY), false);
505 else if (nWinStyle & WB_VERT)
507 long nWidth = rRenderContext.GetTextWidth(aText);
508 rRenderContext.Push(PushFlags::FONT);
509 vcl::Font aFont(rRenderContext.GetFont());
510 aFont.SetOrientation(900);
511 SetFont(aFont);
512 Point aStartPt(aOutSize.Width() / 2, aOutSize.Height() - 1);
513 if (nWinStyle & WB_VCENTER)
514 aStartPt.AdjustY( -((aOutSize.Height() - nWidth) / 2) );
515 Point aTextPt(aStartPt);
516 aTextPt.AdjustX( -(GetTextHeight() / 2) );
517 rRenderContext.DrawText(aTextPt, aText, 0, aText.getLength());
518 rRenderContext.Pop();
519 if (aOutSize.Height() - aStartPt.Y() > FIXEDLINE_TEXT_BORDER)
520 aDecoView.DrawSeparator(Point(aStartPt.X(), aStartPt.Y() + FIXEDLINE_TEXT_BORDER),
521 Point(aStartPt.X(), aOutSize.Height() - 1));
522 if (aStartPt.Y() - nWidth - FIXEDLINE_TEXT_BORDER > 0)
523 aDecoView.DrawSeparator(Point(aStartPt.X(), 0),
524 Point(aStartPt.X(), aStartPt.Y() - nWidth - FIXEDLINE_TEXT_BORDER));
526 else
528 DrawTextFlags nStyle = DrawTextFlags::Mnemonic | DrawTextFlags::Left | DrawTextFlags::VCenter | DrawTextFlags::EndEllipsis;
529 tools::Rectangle aRect(0, 0, aOutSize.Width(), aOutSize.Height());
530 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
531 if (nWinStyle & WB_CENTER)
532 nStyle |= DrawTextFlags::Center;
534 if (!IsEnabled())
535 nStyle |= DrawTextFlags::Disable;
536 if (GetStyle() & WB_NOLABEL)
537 nStyle &= ~DrawTextFlags::Mnemonic;
538 if (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono)
539 nStyle |= DrawTextFlags::Mono;
541 aRect = DrawControlText(*this, aRect, aText, nStyle, nullptr, nullptr);
543 long nTop = aRect.Top() + ((aRect.GetHeight() - 1) / 2);
544 aDecoView.DrawSeparator(Point(aRect.Right() + FIXEDLINE_TEXT_BORDER, nTop), Point(aOutSize.Width() - 1, nTop), false);
545 if (aRect.Left() > FIXEDLINE_TEXT_BORDER)
546 aDecoView.DrawSeparator(Point(0, nTop), Point(aRect.Left() - FIXEDLINE_TEXT_BORDER, nTop), false);
550 FixedLine::FixedLine( vcl::Window* pParent, WinBits nStyle ) :
551 Control( WindowType::FIXEDLINE )
553 ImplInit( pParent, nStyle );
554 SetSizePixel( Size( 2, 2 ) );
557 void FixedLine::FillLayoutData() const
559 mpControlData->mpLayoutData.reset( new vcl::ControlLayoutData );
560 const_cast<FixedLine*>(this)->Invalidate();
563 void FixedLine::ApplySettings(vcl::RenderContext& rRenderContext)
565 Control::ApplySettings(rRenderContext);
567 vcl::Window* pParent = GetParent();
568 if (pParent->IsChildTransparentModeEnabled() && !IsControlBackground())
570 EnableChildTransparentMode();
571 SetParentClipMode(ParentClipMode::NoClip);
572 SetPaintTransparent(true);
573 rRenderContext.SetBackground();
575 else
577 EnableChildTransparentMode(false);
578 SetParentClipMode();
579 SetPaintTransparent(false);
581 if (IsControlBackground())
582 rRenderContext.SetBackground(GetControlBackground());
583 else
584 rRenderContext.SetBackground(pParent->GetBackground());
588 void FixedLine::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
590 ImplDraw(rRenderContext);
593 void FixedLine::Draw( OutputDevice*, const Point&, const Size&, DrawFlags )
597 void FixedLine::Resize()
599 Control::Resize();
600 Invalidate();
603 void FixedLine::StateChanged( StateChangedType nType )
605 Control::StateChanged( nType );
607 if ( (nType == StateChangedType::Enable) ||
608 (nType == StateChangedType::Text) ||
609 (nType == StateChangedType::UpdateMode) )
611 if ( IsReallyVisible() && IsUpdateMode() )
612 Invalidate();
614 else if ( nType == StateChangedType::Style )
616 SetStyle( ImplInitStyle( GetStyle() ) );
617 if ( (GetPrevStyle() & FIXEDLINE_VIEW_STYLE) !=
618 (GetStyle() & FIXEDLINE_VIEW_STYLE) )
619 Invalidate();
621 else if ( (nType == StateChangedType::Zoom) ||
622 (nType == StateChangedType::Style) ||
623 (nType == StateChangedType::ControlFont) )
625 ApplySettings(*this);
626 Invalidate();
628 else if ( nType == StateChangedType::ControlForeground )
630 ApplySettings(*this);
631 Invalidate();
633 else if ( nType == StateChangedType::ControlBackground )
635 ApplySettings(*this);
636 Invalidate();
640 void FixedLine::DataChanged( const DataChangedEvent& rDCEvt )
642 Control::DataChanged( rDCEvt );
644 if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
645 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
646 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
647 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
649 ApplySettings(*this);
650 Invalidate();
654 Size FixedLine::GetOptimalSize() const
656 return CalcWindowSize( FixedText::CalcMinimumTextSize ( this ) );
659 void FixedBitmap::ImplInit( vcl::Window* pParent, WinBits nStyle )
661 nStyle = ImplInitStyle( nStyle );
662 Control::ImplInit( pParent, nStyle, nullptr );
663 ApplySettings(*this);
666 WinBits FixedBitmap::ImplInitStyle( WinBits nStyle )
668 if ( !(nStyle & WB_NOGROUP) )
669 nStyle |= WB_GROUP;
670 return nStyle;
673 FixedBitmap::FixedBitmap( vcl::Window* pParent, WinBits nStyle ) :
674 Control( WindowType::FIXEDBITMAP )
676 ImplInit( pParent, nStyle );
679 void FixedBitmap::ImplDraw( OutputDevice* pDev, const Point& rPos, const Size& rSize )
681 // do we have a Bitmap?
682 if ( !!maBitmap )
684 if ( GetStyle() & WB_SCALE )
685 pDev->DrawBitmapEx( rPos, rSize, maBitmap );
686 else
688 Point aPos = ImplCalcPos( GetStyle(), rPos, maBitmap.GetSizePixel(), rSize );
689 pDev->DrawBitmapEx( aPos, maBitmap );
694 void FixedBitmap::ApplySettings(vcl::RenderContext& rRenderContext)
696 vcl::Window* pParent = GetParent();
697 if (pParent->IsChildTransparentModeEnabled() && !IsControlBackground())
699 EnableChildTransparentMode();
700 SetParentClipMode(ParentClipMode::NoClip);
701 SetPaintTransparent(true);
702 rRenderContext.SetBackground();
704 else
706 EnableChildTransparentMode(false);
707 SetParentClipMode();
708 SetPaintTransparent(false);
710 if (IsControlBackground())
711 rRenderContext.SetBackground(GetControlBackground());
712 else
713 rRenderContext.SetBackground(pParent->GetBackground());
717 void FixedBitmap::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
719 ImplDraw(&rRenderContext, Point(), GetOutputSizePixel());
722 void FixedBitmap::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
723 DrawFlags )
725 Point aPos = pDev->LogicToPixel( rPos );
726 Size aSize = pDev->LogicToPixel( rSize );
727 tools::Rectangle aRect( aPos, aSize );
729 pDev->Push();
730 pDev->SetMapMode();
732 // Border
733 if ( GetStyle() & WB_BORDER )
735 DecorationView aDecoView( pDev );
736 aRect = aDecoView.DrawFrame( aRect, DrawFrameStyle::DoubleIn );
738 pDev->IntersectClipRegion( aRect );
739 ImplDraw( pDev, aRect.TopLeft(), aRect.GetSize() );
741 pDev->Pop();
744 void FixedBitmap::Resize()
746 Control::Resize();
747 Invalidate();
750 void FixedBitmap::StateChanged( StateChangedType nType )
752 Control::StateChanged( nType );
754 if ( (nType == StateChangedType::Data) ||
755 (nType == StateChangedType::UpdateMode) )
757 if ( IsReallyVisible() && IsUpdateMode() )
758 Invalidate();
760 else if ( nType == StateChangedType::Style )
762 SetStyle( ImplInitStyle( GetStyle() ) );
763 if ( (GetPrevStyle() & FIXEDBITMAP_VIEW_STYLE) !=
764 (GetStyle() & FIXEDBITMAP_VIEW_STYLE) )
765 Invalidate();
767 else if ( nType == StateChangedType::ControlBackground )
769 ApplySettings(*this);
770 Invalidate();
774 void FixedBitmap::DataChanged( const DataChangedEvent& rDCEvt )
776 Control::DataChanged( rDCEvt );
778 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
779 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
781 ApplySettings(*this);
782 Invalidate();
786 void FixedBitmap::SetBitmap( const BitmapEx& rBitmap )
788 maBitmap = rBitmap;
789 CompatStateChanged( StateChangedType::Data );
790 queue_resize();
793 void FixedImage::ImplInit( vcl::Window* pParent, WinBits nStyle )
795 nStyle = ImplInitStyle( nStyle );
796 Control::ImplInit( pParent, nStyle, nullptr );
797 ApplySettings(*this);
800 WinBits FixedImage::ImplInitStyle( WinBits nStyle )
802 if ( !(nStyle & WB_NOGROUP) )
803 nStyle |= WB_GROUP;
804 return nStyle;
807 FixedImage::FixedImage( vcl::Window* pParent, WinBits nStyle ) :
808 Control( WindowType::FIXEDIMAGE )
810 ImplInit( pParent, nStyle );
813 void FixedImage::ImplDraw( OutputDevice* pDev,
814 const Point& rPos, const Size& rSize )
816 DrawImageFlags nStyle = DrawImageFlags::NONE;
817 if ( !IsEnabled() )
818 nStyle |= DrawImageFlags::Disable;
820 Image *pImage = &maImage;
822 // do we have an image?
823 if ( !(!(*pImage)) )
825 if ( GetStyle() & WB_SCALE )
826 pDev->DrawImage( rPos, rSize, *pImage, nStyle );
827 else
829 Point aPos = ImplCalcPos( GetStyle(), rPos, pImage->GetSizePixel(), rSize );
830 pDev->DrawImage( aPos, *pImage, nStyle );
835 void FixedImage::ApplySettings(vcl::RenderContext& rRenderContext)
837 vcl::Window* pParent = GetParent();
838 if (pParent && pParent->IsChildTransparentModeEnabled() && !IsControlBackground())
840 EnableChildTransparentMode();
841 SetParentClipMode(ParentClipMode::NoClip);
842 SetPaintTransparent(true);
843 rRenderContext.SetBackground();
845 else
847 EnableChildTransparentMode(false);
848 SetParentClipMode();
849 SetPaintTransparent(false);
851 if (IsControlBackground())
852 rRenderContext.SetBackground(GetControlBackground());
853 else if (pParent)
854 rRenderContext.SetBackground(pParent->GetBackground());
859 void FixedImage::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
861 ImplDraw(&rRenderContext, Point(), GetOutputSizePixel());
864 Size FixedImage::GetOptimalSize() const
866 return maImage.GetSizePixel();
869 void FixedImage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
870 DrawFlags )
872 Point aPos = pDev->LogicToPixel( rPos );
873 Size aSize = pDev->LogicToPixel( rSize );
874 tools::Rectangle aRect( aPos, aSize );
876 pDev->Push();
877 pDev->SetMapMode();
879 // Border
880 if ( GetStyle() & WB_BORDER )
882 ImplDrawFrame( pDev, aRect );
884 pDev->IntersectClipRegion( aRect );
885 ImplDraw( pDev, aRect.TopLeft(), aRect.GetSize() );
887 pDev->Pop();
890 void FixedImage::Resize()
892 Control::Resize();
893 Invalidate();
896 void FixedImage::StateChanged( StateChangedType nType )
898 Control::StateChanged( nType );
900 if ( (nType == StateChangedType::Enable) ||
901 (nType == StateChangedType::Data) ||
902 (nType == StateChangedType::UpdateMode) )
904 if ( IsReallyVisible() && IsUpdateMode() )
905 Invalidate();
907 else if ( nType == StateChangedType::Style )
909 SetStyle( ImplInitStyle( GetStyle() ) );
910 if ( (GetPrevStyle() & FIXEDIMAGE_VIEW_STYLE) !=
911 (GetStyle() & FIXEDIMAGE_VIEW_STYLE) )
912 Invalidate();
914 else if ( nType == StateChangedType::ControlBackground )
916 ApplySettings(*this);
917 Invalidate();
921 void FixedImage::DataChanged( const DataChangedEvent& rDCEvt )
923 Control::DataChanged( rDCEvt );
925 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
926 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
928 ApplySettings(*this);
929 Invalidate();
933 void FixedImage::SetImage( const Image& rImage )
935 if ( rImage != maImage )
937 maImage = rImage;
938 CompatStateChanged( StateChangedType::Data );
939 queue_resize();
943 void FixedImage::SetModeImage( const Image& rImage )
945 SetImage( rImage );
948 Image FixedImage::loadThemeImage(const OUString &rFileName)
950 return Image(StockImage::Yes, rFileName);
953 bool FixedImage::set_property(const OString &rKey, const OUString &rValue)
955 if (rKey == "pixbuf" || rKey == "icon-name")
957 SetImage(loadThemeImage(rValue));
959 else
960 return Control::set_property(rKey, rValue);
961 return true;
964 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */