LibreOffice Module reportdesign (master)  1
StartMarker.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #include <StartMarker.hxx>
20 #include <UITools.hxx>
21 #include <vcl/image.hxx>
22 #include <vcl/svapp.hxx>
23 #include <bitmaps.hlst>
24 #include <ColorChanger.hxx>
25 #include <ReportDefines.hxx>
26 #include <SectionWindow.hxx>
27 #include <helpids.h>
28 #include <vcl/event.hxx>
29 #include <vcl/help.hxx>
30 #include <vcl/gradient.hxx>
31 #include <vcl/lineinfo.hxx>
32 #include <vcl/settings.hxx>
33 
34 #include <unotools/syslocale.hxx>
36 
37 #define CORNER_SPACE 5
38 
39 
40 namespace rptui
41 {
42 
43 
46 oslInterlockedCount OStartMarker::s_nImageRefCount = 0;
47 
48 
49 OStartMarker::OStartMarker(OSectionWindow* _pParent,const OUString& _sColorEntry)
50  : OColorListener(_pParent,_sColorEntry)
51  , m_aVRuler(VclPtr<Ruler>::Create(this,WB_VERT))
52  , m_pParent(_pParent)
53  , m_bShowRuler(true)
54 {
55  osl_atomic_increment(&s_nImageRefCount);
58  m_aVRuler->Show();
66  m_aVRuler->SetUnit(MeasurementSystem::Metric == eSystem ? FieldUnit::CM : FieldUnit::INCH);
68  SetParentClipMode( ParentClipMode::NoClip );
69  SetPaintTransparent( true );
70 }
71 
73 {
74  disposeOnce();
75 }
76 
78 {
79  if ( osl_atomic_decrement(&s_nImageRefCount) == 0 )
80  {
81  delete s_pDefCollapsed;
82  s_pDefCollapsed = nullptr;
83  delete s_pDefExpanded;
84  s_pDefExpanded = nullptr;
85  }
87  m_pParent.clear();
89 }
90 
91 sal_Int32 OStartMarker::getMinHeight() const
92 {
93  Fraction aExtraWidth(tools::Long(2 * REPORT_EXTRA_SPACE));
94  aExtraWidth *= GetMapMode().GetScaleX();
95  return LogicToPixel(Size(0, GetTextHeight())).Height() + tools::Long(aExtraWidth);
96 }
97 
98 void OStartMarker::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
99 {
100  rRenderContext.Push(vcl::PushFlags::TEXTCOLOR);
101 
102  Size aSize(GetOutputSizePixel());
103  const tools::Long nCornerWidth = tools::Long(CORNER_SPACE * double(GetMapMode().GetScaleX()));
104 
105  if (isCollapsed())
106  {
107  rRenderContext.SetClipRegion();
108  }
109  else
110  {
111  const tools::Long nVRulerWidth = m_aVRuler->GetSizePixel().Width();
112  tools::Long nSize = aSize.Width() - nVRulerWidth;
113  aSize.AdjustWidth(nCornerWidth );
114  rRenderContext.SetClipRegion(vcl::Region(rRenderContext.PixelToLogic(tools::Rectangle(Point(),
115  Size(nSize, aSize.Height())))));
116  }
117 
118  tools::Rectangle aWholeRect(Point(), aSize);
119  {
120  const ColorChanger aColors(&rRenderContext, m_nTextBoundaries, m_nColor);
121  tools::PolyPolygon aPoly;
122  aPoly.Insert( tools::Polygon(aWholeRect,nCornerWidth,nCornerWidth));
123 
124  Color aStartColor(m_nColor);
125  aStartColor.IncreaseLuminance(10);
126  sal_uInt16 nHue = 0;
127  sal_uInt16 nSat = 0;
128  sal_uInt16 nBri = 0;
129  aStartColor.RGBtoHSB(nHue, nSat, nBri);
130  nSat += 40;
131  Color aEndColor(Color::HSBtoRGB(nHue, nSat, nBri));
132  Gradient aGradient(GradientStyle::Linear,aStartColor,aEndColor);
133  aGradient.SetSteps(static_cast<sal_uInt16>(aSize.Height()));
134 
135  rRenderContext.DrawGradient(PixelToLogic(aPoly) ,aGradient);
136  }
137 
138  rRenderContext.Push(vcl::PushFlags::MAPMODE);
139  rRenderContext.SetMapMode();
140 
142 
143  const Color aColor(m_nColor);
144  Color aTextColor = GetTextColor();
145  if (aColor.GetLuminance() < 128)
146  aTextColor = COL_WHITE;
147  rRenderContext.SetTextColor(aTextColor);
148 
149  rRenderContext.DrawText(m_aTextRect, m_aText, DrawTextFlags::MultiLine | DrawTextFlags::WordBreakHyphenation);
150 
151  rRenderContext.Pop();
152 
153  if (m_bMarked)
154  {
155  const tools::Long nCornerHeight = tools::Long(CORNER_SPACE * double(GetMapMode().GetScaleY()));
156  tools::Rectangle aRect(Point(nCornerWidth, nCornerHeight),
157  Size(aSize.Width() - nCornerWidth - nCornerWidth,
158  aSize.Height() - nCornerHeight - nCornerHeight));
159  ColorChanger aColors(&rRenderContext, COL_WHITE, COL_WHITE);
160  rRenderContext.DrawPolyLine( tools::Polygon(rRenderContext.PixelToLogic(aRect)),
161  LineInfo(LineStyle::Solid, 2));
162  }
163 
164  rRenderContext.Pop();
165 }
166 
168 {
169  if ( !rMEvt.IsLeft() )
170  return;
171 
172  Point aPos( rMEvt.GetPosPixel());
173 
174  const Size aOutputSize = GetOutputSizePixel();
175  if( aPos.X() > aOutputSize.Width() || aPos.Y() > aOutputSize.Height() )
176  return;
177  if ( rMEvt.GetClicks() == 2 || m_aImageRect.Contains( aPos ) )
178  {
180 
181  changeImage();
182 
184  m_aCollapsedLink.Call(*this);
185  }
186 
187  m_pParent->showProperties();
188 }
189 
191 {
193 }
194 
196 {
197  if ( !s_pDefCollapsed )
198  {
199  s_pDefCollapsed = new Image(StockImage::Yes, RID_BMP_TREENODE_COLLAPSED);
200  s_pDefExpanded = new Image(StockImage::Yes, RID_BMP_TREENODE_EXPANDED);
201  }
202 
204 }
205 
207 {
208  rRenderContext.SetBackground();
209  rRenderContext.SetFillColor(Application::GetSettings().GetStyleSettings().GetDialogColor());
210 }
211 
213 {
215 }
216 
218 {
219  const Size aOutputSize( GetOutputSizePixel() );
220  const tools::Long nOutputWidth = aOutputSize.Width();
221  const tools::Long nOutputHeight = aOutputSize.Height();
222 
223  const tools::Long nVRulerWidth = m_aVRuler->GetSizePixel().Width();
224  const Point aRulerPos(nOutputWidth - nVRulerWidth,0);
225  m_aVRuler->SetPosSizePixel(aRulerPos,Size(nVRulerWidth,nOutputHeight));
226 
227  Size aImageSize = m_aImage.GetSizePixel();
228  const MapMode& rMapMode = GetMapMode();
229  aImageSize.setWidth( tools::Long(aImageSize.Width() * static_cast<double>(rMapMode.GetScaleX())) );
230  aImageSize.setHeight( tools::Long(aImageSize.Height() * static_cast<double>(rMapMode.GetScaleY())) );
231 
232  tools::Long nExtraWidth = tools::Long(REPORT_EXTRA_SPACE * rMapMode.GetScaleX());
233 
234  Point aPos(aImageSize.Width() + (nExtraWidth * 2), nExtraWidth);
235  const tools::Long nHeight = ::std::max<sal_Int32>(nOutputHeight - 2*aPos.Y(),LogicToPixel(Size(0, GetTextHeight())).Height());
236  m_aTextRect = tools::Rectangle(aPos, Size(aRulerPos.X() - aPos.X(),nHeight));
237 
238  aPos.setX( nExtraWidth );
239  aPos.AdjustY(static_cast<sal_Int32>((LogicToPixel(Size(0, GetTextHeight())).Height() - aImageSize.Height()) * 0.5) ) ;
240  m_aImageRect = tools::Rectangle(aPos, aImageSize);
241 
243 }
244 
245 void OStartMarker::setTitle(const OUString& rTitle)
246 {
247  if (m_aText != rTitle)
248  {
249  m_aText = rTitle;
250  Invalidate();
251  }
252 }
253 
254 void OStartMarker::Notify(SfxBroadcaster & rBc, SfxHint const & rHint)
255 {
256  OColorListener::Notify(rBc, rHint);
257  if (rHint.GetId() == SfxHintId::ColorsChanged)
258  {
259  Invalidate(InvalidateFlags::Children);
260  }
261 }
262 
263 void OStartMarker::showRuler(bool _bShow)
264 {
265  m_bShowRuler = _bShow;
267 }
268 
270 {
271  if (m_aText.isEmpty())
272  return;
273 
274  // show help
276  Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
277  aItemRect.SetLeft( aPt.X() );
278  aItemRect.SetTop( aPt.Y() );
279  aPt = OutputToScreenPixel( aItemRect.BottomRight() );
280  aItemRect.SetRight( aPt.X() );
281  aItemRect.SetBottom( aPt.Y() );
282  if( rHEvt.GetMode() == HelpEventMode::BALLOON )
283  Help::ShowBalloon( this, aItemRect.Center(), aItemRect, m_aText);
284  else
285  Help::ShowQuickHelp( this, aItemRect, m_aText );
286 }
287 
288 void OStartMarker::setCollapsed(bool _bCollapsed)
289 {
290  OColorListener::setCollapsed(_bCollapsed);
291  showRuler(_bCollapsed);
292  changeImage();
293 }
294 
295 void OStartMarker::zoom(const Fraction& _aZoom)
296 {
297  setZoomFactor(_aZoom, *this);
298  m_aVRuler->SetZoom(_aZoom);
299  Resize();
300  Invalidate();
301 }
302 
303 }
304 
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetClipRegion()
const Fraction & GetScaleX() const
tools::Long GetTextHeight() const
Size GetSizePixel() const
sal_Int32 getMinHeight() const
Definition: StartMarker.cxx:91
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
void SetUnit(FieldUnit eNewUnit)
void setWidth(tools::Long nWidth)
void Activate() override
bool Contains(const Point &rPOINT) const
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
long Long
#define CORNER_SPACE
Definition: StartMarker.cxx:37
void disposeAndClear()
virtual void ImplInitSettings() override
static const AllSettings & GetSettings()
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
sal_uInt8 GetLuminance() const
virtual Size GetSizePixel() const
void DrawPolyLine(const tools::Polygon &rPoly)
void SetParentClipMode(ParentClipMode nMode=ParentClipMode::NONE)
virtual ~OStartMarker() override
Definition: StartMarker.cxx:72
bool m_bShowRuler
When 0 all static images will be destroyed.
Definition: StartMarker.hxx:43
bool isCollapsed() const
void SetMapMode()
HelpEventMode GetMode() const
SfxHintId GetId() const
MeasurementSystem
constexpr tools::Long Width() const
sal_uInt16 GetClicks() const
void SetSteps(sal_uInt16 nSteps)
void showRuler(bool _bShow)
shows or hides the ruler.
const LocaleDataWrapper & GetLocaleData() const
void SetBackground()
Link< OColorListener &, void > m_aCollapsedLink
const Fraction & GetScaleY() const
WinBits const WB_VERT
void SetMargin2()
void Insert(const tools::Polygon &rPoly, sal_uInt16 nPos=POLYPOLY_APPEND)
void zoom(const Fraction &_aZoom)
zoom the ruler and view windows
void IncreaseLuminance(sal_uInt8 cLumInc)
void SetIndents(sal_uInt32 n=0, const RulerIndent *pIndentAry=nullptr)
tools::Rectangle m_aTextRect
Definition: StartMarker.hxx:35
static Color HSBtoRGB(sal_uInt16 nHue, sal_uInt16 nSaturation, sal_uInt16 nBrightness)
const Point & GetMousePosPixel() const
Point LogicToPixel(const Point &rLogicPt) const
const MapMode & GetMapMode() const
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
void SetZoom(const Fraction &rNewZoom)
void SetFillColor()
void SetTextColor(const Color &rColor)
virtual void Resize()
virtual void setCollapsed(bool _bCollapsed) override
collapse or expand
void SetPaintTransparent(bool bTransparent)
static oslInterlockedCount s_nImageRefCount
Definition: StartMarker.hxx:41
Point PixelToLogic(const Point &rDevicePt) const
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: StartMarker.cxx:98
virtual void setCollapsed(bool _bCollapsed)
collapse or expand
void setTitle(const OUString &_sTitle)
virtual void Notify(SfxBroadcaster &rBc, SfxHint const &rHint) override
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
virtual void RequestHelp(const HelpEvent &rHEvt) override
constexpr Point TopLeft() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
void SetMargin1()
VclPtr< OSectionWindow > m_pParent
Definition: StartMarker.hxx:38
OStartMarker(OStartMarker const &)=delete
constexpr Size GetSize() const
virtual void Resize() override
constexpr tools::Long Height() const
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
::OutputDevice const * GetOutDev() const
void EnableChildTransparentMode(bool bEnable=true)
bool IsLeft() const
tools::Long AdjustWidth(tools::Long n)
const Color & GetTextColor() const
const Point & GetPosPixel() const
virtual void Notify(SfxBroadcaster &rBc, SfxHint const &rHint) override
#define REPORT_EXTRA_SPACE
virtual void dispose() override
Definition: StartMarker.cxx:77
static Image * s_pDefExpanded
Definition: StartMarker.hxx:40
Size GetOutputSizePixel() const
void setHeight(tools::Long nHeight)
void setZoomFactor(const Fraction &_aZoom, vcl::Window &_rWindow)
sets the map mode at the window
Definition: UITools.cxx:1019
void RGBtoHSB(sal_uInt16 &nHue, sal_uInt16 &nSaturation, sal_uInt16 &nBrightness) const
void SetBorders(sal_uInt32 n=0, const RulerBorder *pBrdAry=nullptr)
Point OutputToScreenPixel(const Point &rPos) const
virtual void dispose() override
static Image * s_pDefCollapsed
Definition: StartMarker.hxx:39
void DrawGradient(const tools::Rectangle &rRect, const Gradient &rGradient)
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
VclPtr< Ruler > m_aVRuler
Definition: StartMarker.hxx:33
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
tools::Rectangle m_aImageRect
Definition: StartMarker.hxx:37
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)
void SetPagePos(tools::Long nOff=0, tools::Long nWidth=0)
MeasurementSystem getMeasurementSystemEnum() const