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 .
20 #include <vcl/cvtgrf.hxx>
21 #include <vcl/decoview.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/toolkit/fixed.hxx>
24 #include <vcl/settings.hxx>
26 #include <comphelper/base64.hxx>
27 #include <comphelper/string.hxx>
28 #include <sal/log.hxx>
29 #include <tools/json_writer.hxx>
30 #include <tools/stream.hxx>
32 #define FIXEDLINE_TEXT_BORDER 4
34 constexpr auto FIXEDTEXT_VIEW_STYLE
= WB_3DLOOK
|
35 WB_LEFT
| WB_CENTER
| WB_RIGHT
|
36 WB_TOP
| WB_VCENTER
| WB_BOTTOM
|
37 WB_WORDBREAK
| WB_NOLABEL
|
39 constexpr auto FIXEDLINE_VIEW_STYLE
= WB_3DLOOK
| WB_NOLABEL
;
40 constexpr auto FIXEDBITMAP_VIEW_STYLE
= WB_3DLOOK
|
41 WB_LEFT
| WB_CENTER
| WB_RIGHT
|
42 WB_TOP
| WB_VCENTER
| WB_BOTTOM
|
44 constexpr auto FIXEDIMAGE_VIEW_STYLE
= WB_3DLOOK
|
45 WB_LEFT
| WB_CENTER
| WB_RIGHT
|
46 WB_TOP
| WB_VCENTER
| WB_BOTTOM
|
49 static Point
ImplCalcPos( WinBits nStyle
, const Point
& rPos
,
50 const Size
& rObjSize
, const Size
& rWinSize
)
55 if ( nStyle
& WB_LEFT
)
57 else if ( nStyle
& WB_RIGHT
)
58 nX
= rWinSize
.Width()-rObjSize
.Width();
60 nX
= (rWinSize
.Width()-rObjSize
.Width())/2;
62 if ( nStyle
& WB_TOP
)
64 else if ( nStyle
& WB_BOTTOM
)
65 nY
= rWinSize
.Height()-rObjSize
.Height();
67 nY
= (rWinSize
.Height()-rObjSize
.Height())/2;
69 Point
aPos( nX
+rPos
.X(), nY
+rPos
.Y() );
73 void FixedText::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
75 nStyle
= ImplInitStyle( nStyle
);
76 Control::ImplInit( pParent
, nStyle
, nullptr );
77 ApplySettings(*GetOutDev());
80 WinBits
FixedText::ImplInitStyle( WinBits nStyle
)
82 if ( !(nStyle
& WB_NOGROUP
) )
87 const vcl::Font
& FixedText::GetCanonicalFont( const StyleSettings
& _rStyle
) const
89 return _rStyle
.GetLabelFont();
92 const Color
& FixedText::GetCanonicalTextColor( const StyleSettings
& _rStyle
) const
94 return _rStyle
.GetLabelTextColor();
97 FixedText::FixedText(vcl::Window
* pParent
, WinBits nStyle
, WindowType eType
)
99 , m_nMaxWidthChars(-1)
100 , m_nMinWidthChars(-1)
101 , m_pMnemonicWindow(nullptr)
103 ImplInit( pParent
, nStyle
);
106 DrawTextFlags
FixedText::ImplGetTextStyle( WinBits nWinStyle
)
108 DrawTextFlags nTextStyle
= DrawTextFlags::Mnemonic
| DrawTextFlags::EndEllipsis
;
110 if( ! (nWinStyle
& WB_NOMULTILINE
) )
111 nTextStyle
|= DrawTextFlags::MultiLine
;
113 if ( nWinStyle
& WB_RIGHT
)
114 nTextStyle
|= DrawTextFlags::Right
;
115 else if ( nWinStyle
& WB_CENTER
)
116 nTextStyle
|= DrawTextFlags::Center
;
118 nTextStyle
|= DrawTextFlags::Left
;
119 if ( nWinStyle
& WB_BOTTOM
)
120 nTextStyle
|= DrawTextFlags::Bottom
;
121 else if ( nWinStyle
& WB_VCENTER
)
122 nTextStyle
|= DrawTextFlags::VCenter
;
124 nTextStyle
|= DrawTextFlags::Top
;
125 if ( nWinStyle
& WB_WORDBREAK
)
126 nTextStyle
|= DrawTextFlags::WordBreak
;
127 if ( nWinStyle
& WB_NOLABEL
)
128 nTextStyle
&= ~DrawTextFlags::Mnemonic
;
133 void FixedText::ImplDraw(OutputDevice
* pDev
, SystemTextColorFlags nSystemTextColorFlags
,
134 const Point
& rPos
, const Size
& rSize
,
135 bool bFillLayout
) const
137 const StyleSettings
& rStyleSettings
= pDev
->GetSettings().GetStyleSettings();
138 WinBits nWinStyle
= GetStyle();
139 OUString
aText(GetText());
140 DrawTextFlags nTextStyle
= FixedText::ImplGetTextStyle( nWinStyle
);
143 if ( nWinStyle
& WB_EXTRAOFFSET
)
146 if ( nWinStyle
& WB_PATHELLIPSIS
)
148 nTextStyle
&= ~DrawTextFlags(DrawTextFlags::EndEllipsis
| DrawTextFlags::MultiLine
| DrawTextFlags::WordBreak
);
149 nTextStyle
|= DrawTextFlags::PathEllipsis
;
152 nTextStyle
|= DrawTextFlags::Disable
;
153 if ( (nSystemTextColorFlags
& SystemTextColorFlags::Mono
) ||
154 (rStyleSettings
.GetOptions() & StyleSettingsOptions::Mono
) )
155 nTextStyle
|= DrawTextFlags::Mono
;
158 mxLayoutData
->m_aDisplayText
.clear();
160 const tools::Rectangle
aRect(aPos
, rSize
);
161 DrawControlText(*pDev
, aRect
, aText
, nTextStyle
,
162 bFillLayout
? &mxLayoutData
->m_aUnicodeBoundRects
: nullptr,
163 bFillLayout
? &mxLayoutData
->m_aDisplayText
: nullptr);
166 void FixedText::ApplySettings(vcl::RenderContext
& rRenderContext
)
168 Control::ApplySettings(rRenderContext
);
170 vcl::Window
* pParent
= GetParent();
171 bool bEnableTransparent
= true;
172 if (!pParent
->IsChildTransparentModeEnabled() || IsControlBackground())
174 EnableChildTransparentMode(false);
176 SetPaintTransparent(false);
178 if (IsControlBackground())
179 rRenderContext
.SetBackground(GetControlBackground());
181 rRenderContext
.SetBackground(pParent
->GetBackground());
183 if (rRenderContext
.IsBackground())
184 bEnableTransparent
= false;
187 if (bEnableTransparent
)
189 EnableChildTransparentMode();
190 SetParentClipMode(ParentClipMode::NoClip
);
191 SetPaintTransparent(true);
192 rRenderContext
.SetBackground();
196 void FixedText::Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& )
198 ImplDraw(&rRenderContext
, SystemTextColorFlags::NONE
, Point(), GetOutputSizePixel());
201 void FixedText::Draw( OutputDevice
* pDev
, const Point
& rPos
,
202 SystemTextColorFlags nFlags
)
204 ApplySettings(*pDev
);
206 Point aPos
= pDev
->LogicToPixel( rPos
);
207 Size aSize
= GetSizePixel();
208 vcl::Font aFont
= GetDrawPixelFont( pDev
);
212 pDev
->SetFont( aFont
);
213 if ( nFlags
& SystemTextColorFlags::Mono
)
214 pDev
->SetTextColor( COL_BLACK
);
216 pDev
->SetTextColor( GetTextColor() );
217 pDev
->SetTextFillColor();
219 bool bBorder
= (GetStyle() & WB_BORDER
);
220 bool bBackground
= IsControlBackground();
221 if ( bBorder
|| bBackground
)
223 tools::Rectangle
aRect( aPos
, aSize
);
226 ImplDrawFrame( pDev
, aRect
);
230 pDev
->SetFillColor( GetControlBackground() );
231 pDev
->DrawRect( aRect
);
235 ImplDraw( pDev
, nFlags
, aPos
, aSize
);
239 void FixedText::Resize()
245 void FixedText::StateChanged( StateChangedType nType
)
247 Control::StateChanged( nType
);
249 if ( (nType
== StateChangedType::Enable
) ||
250 (nType
== StateChangedType::Text
) ||
251 (nType
== StateChangedType::UpdateMode
) )
253 if ( IsReallyVisible() && IsUpdateMode() )
256 else if ( nType
== StateChangedType::Style
)
258 SetStyle( ImplInitStyle( GetStyle() ) );
259 if ( (GetPrevStyle() & FIXEDTEXT_VIEW_STYLE
) !=
260 (GetStyle() & FIXEDTEXT_VIEW_STYLE
) )
262 ApplySettings(*GetOutDev());
266 else if ( (nType
== StateChangedType::Zoom
) ||
267 (nType
== StateChangedType::ControlFont
) )
269 ApplySettings(*GetOutDev());
272 else if ( nType
== StateChangedType::ControlForeground
)
274 ApplySettings(*GetOutDev());
277 else if ( nType
== StateChangedType::ControlBackground
)
279 ApplySettings(*GetOutDev());
284 void FixedText::DataChanged( const DataChangedEvent
& rDCEvt
)
286 Control::DataChanged( rDCEvt
);
288 if ( (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ||
289 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
290 ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
291 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)) )
293 ApplySettings(*GetOutDev());
298 Size
FixedText::getTextDimensions(Control
const *pControl
, const OUString
&rTxt
, tools::Long nMaxWidth
)
300 DrawTextFlags nStyle
= ImplGetTextStyle( pControl
->GetStyle() );
301 if ( !( pControl
->GetStyle() & WB_NOLABEL
) )
302 nStyle
|= DrawTextFlags::Mnemonic
;
304 return pControl
->GetTextRect(tools::Rectangle( Point(), Size(nMaxWidth
, 0x7fffffff)),
305 rTxt
, nStyle
).GetSize();
308 Size
FixedText::CalcMinimumTextSize( Control
const *pControl
, tools::Long nMaxWidth
)
310 Size aSize
= getTextDimensions(pControl
, pControl
->GetText(), nMaxWidth
);
312 if ( pControl
->GetStyle() & WB_EXTRAOFFSET
)
313 aSize
.AdjustWidth(2 );
315 // GetTextRect cannot take an empty string
316 if ( aSize
.Width() < 0 )
318 if ( aSize
.Height() <= 0 )
319 aSize
.setHeight( pControl
->GetTextHeight() );
324 Size
FixedText::CalcMinimumSize( tools::Long nMaxWidth
) const
326 return CalcWindowSize( CalcMinimumTextSize ( this, nMaxWidth
) );
329 Size
FixedText::GetOptimalSize() const
331 sal_Int32 nMaxAvailWidth
= 0x7fffffff;
332 if (m_nMaxWidthChars
!= -1)
334 OUStringBuffer
aBuf(m_nMaxWidthChars
);
335 comphelper::string::padToLength(aBuf
, m_nMaxWidthChars
, 'x');
336 nMaxAvailWidth
= getTextDimensions(this,
337 aBuf
.makeStringAndClear(), 0x7fffffff).Width();
339 Size aRet
= CalcMinimumSize(nMaxAvailWidth
);
340 if (m_nMinWidthChars
!= -1)
342 OUStringBuffer
aBuf(m_nMinWidthChars
);
343 comphelper::string::padToLength(aBuf
, m_nMinWidthChars
, 'x');
344 Size aMinAllowed
= getTextDimensions(this,
345 aBuf
.makeStringAndClear(), 0x7fffffff);
346 aRet
.setWidth(std::max(aMinAllowed
.Width(), aRet
.Width()));
351 void FixedText::FillLayoutData() const
353 mxLayoutData
.emplace();
354 ImplDraw(const_cast<FixedText
*>(this)->GetOutDev(), SystemTextColorFlags::NONE
, Point(), GetOutputSizePixel(), true);
355 //const_cast<FixedText*>(this)->Invalidate();
358 void FixedText::setMaxWidthChars(sal_Int32 nWidth
)
360 if (nWidth
!= m_nMaxWidthChars
)
362 m_nMaxWidthChars
= nWidth
;
367 void FixedText::setMinWidthChars(sal_Int32 nWidth
)
369 if (nWidth
!= m_nMinWidthChars
)
371 m_nMinWidthChars
= nWidth
;
376 bool FixedText::set_property(const OUString
&rKey
, const OUString
&rValue
)
378 if (rKey
== "max-width-chars")
379 setMaxWidthChars(rValue
.toInt32());
380 else if (rKey
== "width-chars")
381 setMinWidthChars(rValue
.toInt32());
382 else if (rKey
== "ellipsize")
384 WinBits nBits
= GetStyle();
385 nBits
&= ~WB_PATHELLIPSIS
;
386 if (rValue
!= "none")
388 SAL_WARN_IF(rValue
!= "end", "vcl.layout", "Only endellipsis support for now");
389 nBits
|= WB_PATHELLIPSIS
;
394 return Control::set_property(rKey
, rValue
);
398 vcl::Window
* FixedText::getAccessibleRelationLabelFor() const
400 vcl::Window
*pWindow
= Control::getAccessibleRelationLabelFor();
403 return get_mnemonic_widget();
406 void FixedText::set_mnemonic_widget(vcl::Window
*pWindow
)
408 if (pWindow
== m_pMnemonicWindow
)
410 if (m_pMnemonicWindow
)
412 vcl::Window
*pTempReEntryGuard
= m_pMnemonicWindow
;
413 m_pMnemonicWindow
= nullptr;
414 pTempReEntryGuard
->remove_mnemonic_label(this);
416 m_pMnemonicWindow
= pWindow
;
417 if (m_pMnemonicWindow
)
418 m_pMnemonicWindow
->add_mnemonic_label(this);
421 FixedText::~FixedText()
426 void FixedText::dispose()
428 set_mnemonic_widget(nullptr);
429 m_pMnemonicWindow
.clear();
433 SelectableFixedText::SelectableFixedText(vcl::Window
* pParent
, WinBits nStyle
)
434 : Edit(pParent
, nStyle
)
437 SetBorderStyle( WindowBorderStyle::NOBORDER
);
440 // make it transparent
441 SetPaintTransparent(true);
442 SetControlBackground();
445 void SelectableFixedText::ApplySettings(vcl::RenderContext
& rRenderContext
)
447 rRenderContext
.SetBackground();
450 void SelectableFixedText::LoseFocus()
457 void SelectableFixedText::DumpAsPropertyTree(tools::JsonWriter
& rJsonWriter
)
459 Edit::DumpAsPropertyTree(rJsonWriter
);
460 rJsonWriter
.put("type", "fixedtext");
461 rJsonWriter
.put("selectable", true);
464 void FixedLine::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
466 nStyle
= ImplInitStyle( nStyle
);
467 Control::ImplInit( pParent
, nStyle
, nullptr );
468 ApplySettings(*GetOutDev());
471 WinBits
FixedLine::ImplInitStyle( WinBits nStyle
)
473 if ( !(nStyle
& WB_NOGROUP
) )
478 const vcl::Font
& FixedLine::GetCanonicalFont( const StyleSettings
& _rStyle
) const
480 return _rStyle
.GetGroupFont();
483 const Color
& FixedLine::GetCanonicalTextColor( const StyleSettings
& _rStyle
) const
485 return _rStyle
.GetGroupTextColor();
488 void FixedLine::ImplDraw(vcl::RenderContext
& rRenderContext
)
490 // we need to measure according to the window, not according to the
491 // RenderContext we paint to
492 Size aOutSize
= GetOutputSizePixel();
494 OUString aText
= GetText();
495 WinBits nWinStyle
= GetStyle();
497 DecorationView
aDecoView(&rRenderContext
);
500 if (nWinStyle
& WB_VERT
)
502 tools::Long nX
= (aOutSize
.Width() - 1) / 2;
503 aDecoView
.DrawSeparator(Point(nX
, 0), Point(nX
, aOutSize
.Height() - 1));
507 tools::Long nY
= (aOutSize
.Height() - 1) / 2;
508 aDecoView
.DrawSeparator(Point(0, nY
), Point(aOutSize
.Width() - 1, nY
), false);
511 else if (nWinStyle
& WB_VERT
)
513 tools::Long nWidth
= rRenderContext
.GetTextWidth(aText
);
514 rRenderContext
.Push(vcl::PushFlags::FONT
);
515 vcl::Font
aFont(rRenderContext
.GetFont());
516 aFont
.SetOrientation(900_deg10
);
518 Point
aStartPt(aOutSize
.Width() / 2, aOutSize
.Height() - 1);
519 if (nWinStyle
& WB_VCENTER
)
520 aStartPt
.AdjustY( -((aOutSize
.Height() - nWidth
) / 2) );
521 Point
aTextPt(aStartPt
);
522 aTextPt
.AdjustX( -(GetTextHeight() / 2) );
523 rRenderContext
.DrawText(aTextPt
, aText
, 0, aText
.getLength());
524 rRenderContext
.Pop();
525 if (aOutSize
.Height() - aStartPt
.Y() > FIXEDLINE_TEXT_BORDER
)
526 aDecoView
.DrawSeparator(Point(aStartPt
.X(), aStartPt
.Y() + FIXEDLINE_TEXT_BORDER
),
527 Point(aStartPt
.X(), aOutSize
.Height() - 1));
528 if (aStartPt
.Y() - nWidth
- FIXEDLINE_TEXT_BORDER
> 0)
529 aDecoView
.DrawSeparator(Point(aStartPt
.X(), 0),
530 Point(aStartPt
.X(), aStartPt
.Y() - nWidth
- FIXEDLINE_TEXT_BORDER
));
534 DrawTextFlags nStyle
= DrawTextFlags::Mnemonic
| DrawTextFlags::Left
| DrawTextFlags::VCenter
| DrawTextFlags::EndEllipsis
;
535 tools::Rectangle
aRect(0, 0, aOutSize
.Width(), aOutSize
.Height());
536 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
537 if (nWinStyle
& WB_CENTER
)
538 nStyle
|= DrawTextFlags::Center
;
541 nStyle
|= DrawTextFlags::Disable
;
542 if (GetStyle() & WB_NOLABEL
)
543 nStyle
&= ~DrawTextFlags::Mnemonic
;
544 if (rStyleSettings
.GetOptions() & StyleSettingsOptions::Mono
)
545 nStyle
|= DrawTextFlags::Mono
;
547 aRect
= DrawControlText(*GetOutDev(), aRect
, aText
, nStyle
, nullptr, nullptr);
549 tools::Long nTop
= aRect
.Top() + ((aRect
.GetHeight() - 1) / 2);
550 aDecoView
.DrawSeparator(Point(aRect
.Right() + FIXEDLINE_TEXT_BORDER
, nTop
), Point(aOutSize
.Width() - 1, nTop
), false);
551 if (aRect
.Left() > FIXEDLINE_TEXT_BORDER
)
552 aDecoView
.DrawSeparator(Point(0, nTop
), Point(aRect
.Left() - FIXEDLINE_TEXT_BORDER
, nTop
), false);
556 FixedLine::FixedLine( vcl::Window
* pParent
, WinBits nStyle
) :
557 Control( WindowType::FIXEDLINE
)
559 ImplInit( pParent
, nStyle
);
560 SetSizePixel( Size( 2, 2 ) );
563 void FixedLine::FillLayoutData() const
565 mxLayoutData
.emplace();
566 const_cast<FixedLine
*>(this)->Invalidate();
569 void FixedLine::ApplySettings(vcl::RenderContext
& rRenderContext
)
571 Control::ApplySettings(rRenderContext
);
573 vcl::Window
* pParent
= GetParent();
574 if (pParent
->IsChildTransparentModeEnabled() && !IsControlBackground())
576 EnableChildTransparentMode();
577 SetParentClipMode(ParentClipMode::NoClip
);
578 SetPaintTransparent(true);
579 rRenderContext
.SetBackground();
583 EnableChildTransparentMode(false);
585 SetPaintTransparent(false);
587 if (IsControlBackground())
588 rRenderContext
.SetBackground(GetControlBackground());
590 rRenderContext
.SetBackground(pParent
->GetBackground());
594 void FixedLine::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&)
596 ImplDraw(rRenderContext
);
599 void FixedLine::Draw( OutputDevice
*, const Point
&, SystemTextColorFlags
)
603 void FixedLine::Resize()
609 void FixedLine::StateChanged( StateChangedType nType
)
611 Control::StateChanged( nType
);
613 if ( (nType
== StateChangedType::Enable
) ||
614 (nType
== StateChangedType::Text
) ||
615 (nType
== StateChangedType::UpdateMode
) )
617 if ( IsReallyVisible() && IsUpdateMode() )
620 else if ( nType
== StateChangedType::Style
)
622 SetStyle( ImplInitStyle( GetStyle() ) );
623 if ( (GetPrevStyle() & FIXEDLINE_VIEW_STYLE
) !=
624 (GetStyle() & FIXEDLINE_VIEW_STYLE
) )
627 else if ( (nType
== StateChangedType::Zoom
) ||
628 (nType
== StateChangedType::Style
) ||
629 (nType
== StateChangedType::ControlFont
) )
631 ApplySettings(*GetOutDev());
634 else if ( nType
== StateChangedType::ControlForeground
)
636 ApplySettings(*GetOutDev());
639 else if ( nType
== StateChangedType::ControlBackground
)
641 ApplySettings(*GetOutDev());
646 void FixedLine::DataChanged( const DataChangedEvent
& rDCEvt
)
648 Control::DataChanged( rDCEvt
);
650 if ( (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ||
651 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
652 ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
653 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)) )
655 ApplySettings(*GetOutDev());
660 Size
FixedLine::GetOptimalSize() const
662 return CalcWindowSize( FixedText::CalcMinimumTextSize ( this ) );
665 void FixedLine::DumpAsPropertyTree(tools::JsonWriter
& rJsonWriter
)
667 Control::DumpAsPropertyTree(rJsonWriter
);
668 rJsonWriter
.put("type", "separator");
669 rJsonWriter
.put("orientation", (GetStyle() & WB_VERT
) ? "vertical" : "horizontal");
672 void FixedBitmap::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
674 nStyle
= ImplInitStyle( nStyle
);
675 Control::ImplInit( pParent
, nStyle
, nullptr );
676 ApplySettings(*GetOutDev());
679 WinBits
FixedBitmap::ImplInitStyle( WinBits nStyle
)
681 if ( !(nStyle
& WB_NOGROUP
) )
686 FixedBitmap::FixedBitmap( vcl::Window
* pParent
, WinBits nStyle
) :
687 Control( WindowType::FIXEDBITMAP
)
689 ImplInit( pParent
, nStyle
);
692 void FixedBitmap::ImplDraw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
)
694 // do we have a Bitmap?
695 if ( !maBitmap
.IsEmpty() )
697 if ( GetStyle() & WB_SCALE
)
698 pDev
->DrawBitmapEx( rPos
, rSize
, maBitmap
);
701 Point aPos
= ImplCalcPos( GetStyle(), rPos
, maBitmap
.GetSizePixel(), rSize
);
702 pDev
->DrawBitmapEx( aPos
, maBitmap
);
707 void FixedBitmap::ApplySettings(vcl::RenderContext
& rRenderContext
)
709 vcl::Window
* pParent
= GetParent();
710 if (pParent
->IsChildTransparentModeEnabled() && !IsControlBackground())
712 EnableChildTransparentMode();
713 SetParentClipMode(ParentClipMode::NoClip
);
714 SetPaintTransparent(true);
715 rRenderContext
.SetBackground();
719 EnableChildTransparentMode(false);
721 SetPaintTransparent(false);
723 if (IsControlBackground())
724 rRenderContext
.SetBackground(GetControlBackground());
726 rRenderContext
.SetBackground(pParent
->GetBackground());
730 void FixedBitmap::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&)
732 ImplDraw(&rRenderContext
, Point(), GetOutputSizePixel());
735 void FixedBitmap::Draw( OutputDevice
* pDev
, const Point
& rPos
,
736 SystemTextColorFlags
)
738 Point aPos
= pDev
->LogicToPixel( rPos
);
739 Size aSize
= GetSizePixel();
740 tools::Rectangle
aRect( aPos
, aSize
);
746 if ( GetStyle() & WB_BORDER
)
748 DecorationView
aDecoView( pDev
);
749 aRect
= aDecoView
.DrawFrame( aRect
, DrawFrameStyle::DoubleIn
);
751 pDev
->IntersectClipRegion( aRect
);
752 ImplDraw( pDev
, aRect
.TopLeft(), aRect
.GetSize() );
757 void FixedBitmap::Resize()
763 void FixedBitmap::StateChanged( StateChangedType nType
)
765 Control::StateChanged( nType
);
767 if ( (nType
== StateChangedType::Data
) ||
768 (nType
== StateChangedType::UpdateMode
) )
770 if ( IsReallyVisible() && IsUpdateMode() )
773 else if ( nType
== StateChangedType::Style
)
775 SetStyle( ImplInitStyle( GetStyle() ) );
776 if ( (GetPrevStyle() & FIXEDBITMAP_VIEW_STYLE
) !=
777 (GetStyle() & FIXEDBITMAP_VIEW_STYLE
) )
780 else if ( nType
== StateChangedType::ControlBackground
)
782 ApplySettings(*GetOutDev());
787 void FixedBitmap::DataChanged( const DataChangedEvent
& rDCEvt
)
789 Control::DataChanged( rDCEvt
);
791 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
792 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
794 ApplySettings(*GetOutDev());
799 void FixedBitmap::SetBitmap( const BitmapEx
& rBitmap
)
802 CompatStateChanged( StateChangedType::Data
);
806 void FixedImage::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
808 nStyle
= ImplInitStyle( nStyle
);
809 Control::ImplInit( pParent
, nStyle
, nullptr );
810 ApplySettings(*GetOutDev());
813 WinBits
FixedImage::ImplInitStyle( WinBits nStyle
)
815 if ( !(nStyle
& WB_NOGROUP
) )
820 FixedImage::FixedImage( vcl::Window
* pParent
, WinBits nStyle
) :
821 Control( WindowType::FIXEDIMAGE
)
823 ImplInit( pParent
, nStyle
);
826 void FixedImage::ImplDraw( OutputDevice
* pDev
,
827 const Point
& rPos
, const Size
& rSize
)
829 DrawImageFlags nStyle
= DrawImageFlags::NONE
;
831 nStyle
|= DrawImageFlags::Disable
;
833 Image
*pImage
= &maImage
;
835 // do we have an image?
838 if ( GetStyle() & WB_SCALE
)
839 pDev
->DrawImage( rPos
, rSize
, *pImage
, nStyle
);
842 Point aPos
= ImplCalcPos( GetStyle(), rPos
, pImage
->GetSizePixel(), rSize
);
843 pDev
->DrawImage( aPos
, *pImage
, nStyle
);
848 void FixedImage::ApplySettings(vcl::RenderContext
& rRenderContext
)
850 vcl::Window
* pParent
= GetParent();
851 if (pParent
&& pParent
->IsChildTransparentModeEnabled() && !IsControlBackground())
853 EnableChildTransparentMode();
854 SetParentClipMode(ParentClipMode::NoClip
);
855 SetPaintTransparent(true);
856 rRenderContext
.SetBackground();
860 EnableChildTransparentMode(false);
862 SetPaintTransparent(false);
864 if (IsControlBackground())
865 rRenderContext
.SetBackground(GetControlBackground());
867 rRenderContext
.SetBackground(pParent
->GetBackground());
872 void FixedImage::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&)
874 ImplDraw(&rRenderContext
, Point(), GetOutputSizePixel());
877 Size
FixedImage::GetOptimalSize() const
879 return maImage
.GetSizePixel();
882 void FixedImage::Draw( OutputDevice
* pDev
, const Point
& rPos
,
883 SystemTextColorFlags
)
885 Point aPos
= pDev
->LogicToPixel( rPos
);
886 Size aSize
= GetSizePixel();
887 tools::Rectangle
aRect( aPos
, aSize
);
893 if ( GetStyle() & WB_BORDER
)
895 ImplDrawFrame( pDev
, aRect
);
897 pDev
->IntersectClipRegion( aRect
);
898 ImplDraw( pDev
, aRect
.TopLeft(), aRect
.GetSize() );
903 void FixedImage::Resize()
909 void FixedImage::StateChanged( StateChangedType nType
)
911 Control::StateChanged( nType
);
913 if ( (nType
== StateChangedType::Enable
) ||
914 (nType
== StateChangedType::Data
) ||
915 (nType
== StateChangedType::UpdateMode
) )
917 if ( IsReallyVisible() && IsUpdateMode() )
920 else if ( nType
== StateChangedType::Style
)
922 SetStyle( ImplInitStyle( GetStyle() ) );
923 if ( (GetPrevStyle() & FIXEDIMAGE_VIEW_STYLE
) !=
924 (GetStyle() & FIXEDIMAGE_VIEW_STYLE
) )
927 else if ( nType
== StateChangedType::ControlBackground
)
929 ApplySettings(*GetOutDev());
934 void FixedImage::DataChanged( const DataChangedEvent
& rDCEvt
)
936 Control::DataChanged( rDCEvt
);
938 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
939 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
941 ApplySettings(*GetOutDev());
946 void FixedImage::SetImage( const Image
& rImage
)
948 if ( rImage
!= maImage
)
951 CompatStateChanged( StateChangedType::Data
);
956 bool FixedImage::set_property(const OUString
&rKey
, const OUString
&rValue
)
958 if (rKey
== "icon-size")
960 WinBits nBits
= GetStyle();
961 nBits
&= ~WB_SMALLSTYLE
;
963 nBits
|= WB_SMALLSTYLE
;
967 return Control::set_property(rKey
, rValue
);
971 void FixedImage::DumpAsPropertyTree(tools::JsonWriter
& rJsonWriter
)
973 Control::DumpAsPropertyTree(rJsonWriter
);
974 rJsonWriter
.put("id", get_id());
975 rJsonWriter
.put("type", "image");
978 SvMemoryStream
aOStm(6535, 6535);
979 if(GraphicConverter::Export(aOStm
, maImage
.GetBitmapEx(), ConvertDataFormat::PNG
) == ERRCODE_NONE
)
981 css::uno::Sequence
<sal_Int8
> aSeq( static_cast<sal_Int8
const *>(aOStm
.GetData()), aOStm
.Tell());
982 OStringBuffer
aBuffer("data:image/png;base64,");
983 ::comphelper::Base64::encode(aBuffer
, aSeq
);
984 rJsonWriter
.put("image", aBuffer
);
990 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */