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