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 .
19 #include <StartMarker.hxx>
20 #include <vcl/image.hxx>
21 #include <vcl/svapp.hxx>
22 #include <bitmaps.hlst>
23 #include <ColorChanger.hxx>
24 #include <ReportDefines.hxx>
25 #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>
33 #include <unotools/syslocale.hxx>
34 #include <unotools/localedatawrapper.hxx>
36 #define CORNER_SPACE 5
43 Image
* OStartMarker::s_pDefCollapsed
= nullptr;
44 Image
* OStartMarker::s_pDefExpanded
= nullptr;
45 oslInterlockedCount
OStartMarker::s_nImageRefCount
= 0;
48 OStartMarker::OStartMarker(OSectionWindow
* _pParent
,const OUString
& _sColorEntry
)
49 : OColorListener(_pParent
,_sColorEntry
)
50 ,m_aVRuler(VclPtr
<Ruler
>::Create(this,WB_VERT
))
51 ,m_aText(VclPtr
<FixedText
>::Create(this,WB_HYPHENATION
))
52 ,m_aImage(VclPtr
<FixedImage
>::Create(this,WB_LEFT
|WB_TOP
|WB_SCALE
))
56 osl_atomic_increment(&s_nImageRefCount
);
57 initDefaultNodeImages();
59 m_aText
->SetHelpId(HID_RPT_START_TITLE
);
60 m_aText
->SetPaintTransparent(true);
61 m_aImage
->SetHelpId(HID_RPT_START_IMAGE
);
65 m_aVRuler
->Activate();
66 m_aVRuler
->SetPagePos();
67 m_aVRuler
->SetBorders();
68 m_aVRuler
->SetIndents();
69 m_aVRuler
->SetMargin1();
70 m_aVRuler
->SetMargin2();
71 const MeasurementSystem eSystem
= SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
72 m_aVRuler
->SetUnit(MeasurementSystem::Metric
== eSystem
? FieldUnit::CM
: FieldUnit::INCH
);
73 EnableChildTransparentMode();
74 SetParentClipMode( ParentClipMode::NoClip
);
75 SetPaintTransparent( true );
78 OStartMarker::~OStartMarker()
83 void OStartMarker::dispose()
85 if ( osl_atomic_decrement(&s_nImageRefCount
) == 0 )
87 DELETEZ(s_pDefCollapsed
);
88 DELETEZ(s_pDefExpanded
);
90 m_aVRuler
.disposeAndClear();
91 m_aText
.disposeAndClear();
92 m_aImage
.disposeAndClear();
94 OColorListener::dispose();
97 sal_Int32
OStartMarker::getMinHeight() const
99 Fraction
aExtraWidth(long(2 * REPORT_EXTRA_SPACE
));
100 aExtraWidth
*= GetMapMode().GetScaleX();
101 return LogicToPixel(Size(0, m_aText
->GetTextHeight())).Height() + long(aExtraWidth
);
104 void OStartMarker::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& /*rRect*/)
106 Size
aSize(GetOutputSizePixel());
107 const long nCornerWidth
= long(CORNER_SPACE
* double(GetMapMode().GetScaleX()));
111 rRenderContext
.SetClipRegion();
115 const long nVRulerWidth
= m_aVRuler
->GetSizePixel().Width();
116 long nSize
= aSize
.Width() - nVRulerWidth
;
117 aSize
.AdjustWidth(nCornerWidth
);
118 rRenderContext
.SetClipRegion(vcl::Region(rRenderContext
.PixelToLogic(tools::Rectangle(Point(),
119 Size(nSize
, aSize
.Height())))));
122 tools::Rectangle
aWholeRect(Point(), aSize
);
124 const ColorChanger
aColors(&rRenderContext
, m_nTextBoundaries
, m_nColor
);
125 tools::PolyPolygon aPoly
;
126 aPoly
.Insert( tools::Polygon(aWholeRect
,nCornerWidth
,nCornerWidth
));
128 Color
aStartColor(m_nColor
);
129 aStartColor
.IncreaseLuminance(10);
133 aStartColor
.RGBtoHSB(nHue
, nSat
, nBri
);
135 Color
aEndColor(Color::HSBtoRGB(nHue
, nSat
, nBri
));
136 Gradient
aGradient(GradientStyle::Linear
,aStartColor
,aEndColor
);
137 aGradient
.SetSteps(static_cast<sal_uInt16
>(aSize
.Height()));
139 rRenderContext
.DrawGradient(PixelToLogic(aPoly
) ,aGradient
);
143 const long nCornerHeight
= long(CORNER_SPACE
* double(GetMapMode().GetScaleY()));
144 tools::Rectangle
aRect(Point(nCornerWidth
, nCornerHeight
),
145 Size(aSize
.Width() - nCornerWidth
- nCornerWidth
,
146 aSize
.Height() - nCornerHeight
- nCornerHeight
));
147 ColorChanger
aColors(&rRenderContext
, COL_WHITE
, COL_WHITE
);
148 rRenderContext
.DrawPolyLine( tools::Polygon(rRenderContext
.PixelToLogic(aRect
)),
149 LineInfo(LineStyle::Solid
, 2));
153 void OStartMarker::setColor()
155 const Color
aColor(m_nColor
);
156 Color aTextColor
= GetTextColor();
157 if ( aColor
.GetLuminance() < 128 )
158 aTextColor
= COL_WHITE
;
159 m_aText
->SetTextColor(aTextColor
);
160 m_aText
->SetLineColor(m_nColor
);
163 void OStartMarker::MouseButtonUp( const MouseEvent
& rMEvt
)
165 if ( !rMEvt
.IsLeft() )
168 Point
aPos( rMEvt
.GetPosPixel());
170 const Size aOutputSize
= GetOutputSizePixel();
171 if( aPos
.X() > aOutputSize
.Width() || aPos
.Y() > aOutputSize
.Height() )
173 tools::Rectangle
aRect(m_aImage
->GetPosPixel(),m_aImage
->GetSizePixel());
174 if ( rMEvt
.GetClicks() == 2 || aRect
.IsInside( aPos
) )
176 m_bCollapsed
= !m_bCollapsed
;
180 m_aVRuler
->Show(!m_bCollapsed
&& m_bShowRuler
);
181 m_aCollapsedLink
.Call(*this);
184 m_pParent
->showProperties();
187 void OStartMarker::changeImage()
189 Image
* pImage
= m_bCollapsed
? s_pDefCollapsed
: s_pDefExpanded
;
190 m_aImage
->SetImage(*pImage
);
193 void OStartMarker::initDefaultNodeImages()
195 if ( !s_pDefCollapsed
)
197 s_pDefCollapsed
= new Image(StockImage::Yes
, RID_BMP_TREENODE_COLLAPSED
);
198 s_pDefExpanded
= new Image(StockImage::Yes
, RID_BMP_TREENODE_EXPANDED
);
201 Image
* pImage
= m_bCollapsed
? s_pDefCollapsed
: s_pDefExpanded
;
202 m_aImage
->SetImage(*pImage
);
203 m_aImage
->SetMouseTransparent(true);
204 m_aImage
->SetBackground();
205 m_aText
->SetBackground();
206 m_aText
->SetMouseTransparent(true);
209 void OStartMarker::ApplySettings(vcl::RenderContext
& rRenderContext
)
211 rRenderContext
.SetBackground();
212 rRenderContext
.SetFillColor(Application::GetSettings().GetStyleSettings().GetDialogColor());
216 void OStartMarker::ImplInitSettings()
218 ApplySettings(*this);
221 void OStartMarker::Resize()
223 const Size
aOutputSize( GetOutputSizePixel() );
224 const long nOutputWidth
= aOutputSize
.Width();
225 const long nOutputHeight
= aOutputSize
.Height();
227 const long nVRulerWidth
= m_aVRuler
->GetSizePixel().Width();
228 const Point
aRulerPos(nOutputWidth
- nVRulerWidth
,0);
229 m_aVRuler
->SetPosSizePixel(aRulerPos
,Size(nVRulerWidth
,nOutputHeight
));
231 Size aImageSize
= m_aImage
->GetImage().GetSizePixel();
232 const MapMode
& rMapMode
= GetMapMode();
233 aImageSize
.setWidth( long(aImageSize
.Width() * static_cast<double>(rMapMode
.GetScaleX())) );
234 aImageSize
.setHeight( long(aImageSize
.Height() * static_cast<double>(rMapMode
.GetScaleY())) );
236 long nExtraWidth
= long(REPORT_EXTRA_SPACE
* rMapMode
.GetScaleX());
238 Point
aPos(aImageSize
.Width() + (nExtraWidth
* 2), nExtraWidth
);
239 const long nHeight
= ::std::max
<sal_Int32
>(nOutputHeight
- 2*aPos
.Y(),LogicToPixel(Size(0,m_aText
->GetTextHeight())).Height());
240 m_aText
->SetPosSizePixel(aPos
,Size(aRulerPos
.X() - aPos
.X(),nHeight
));
242 aPos
.setX( nExtraWidth
);
243 aPos
.AdjustY(static_cast<sal_Int32
>((LogicToPixel(Size(0,m_aText
->GetTextHeight())).Height() - aImageSize
.Height()) * 0.5) ) ;
244 m_aImage
->SetPosSizePixel(aPos
,aImageSize
);
247 void OStartMarker::setTitle(const OUString
& _sTitle
)
249 m_aText
->SetText(_sTitle
);
252 void OStartMarker::Notify(SfxBroadcaster
& rBc
, SfxHint
const & rHint
)
254 OColorListener::Notify(rBc
, rHint
);
255 if (rHint
.GetId() == SfxHintId::ColorsChanged
)
258 Invalidate(InvalidateFlags::Children
);
262 void OStartMarker::showRuler(bool _bShow
)
264 m_bShowRuler
= _bShow
;
265 m_aVRuler
->Show(!m_bCollapsed
&& m_bShowRuler
);
268 void OStartMarker::RequestHelp( const HelpEvent
& rHEvt
)
270 if( !m_aText
->GetText().isEmpty())
273 tools::Rectangle
aItemRect(rHEvt
.GetMousePosPixel(),Size(GetSizePixel().Width(),getMinHeight()));
274 Point aPt
= OutputToScreenPixel( aItemRect
.TopLeft() );
275 aItemRect
.SetLeft( aPt
.X() );
276 aItemRect
.SetTop( aPt
.Y() );
277 aPt
= OutputToScreenPixel( aItemRect
.BottomRight() );
278 aItemRect
.SetRight( aPt
.X() );
279 aItemRect
.SetBottom( aPt
.Y() );
280 if( rHEvt
.GetMode() == HelpEventMode::BALLOON
)
281 Help::ShowBalloon( this, aItemRect
.Center(), aItemRect
, m_aText
->GetText());
283 Help::ShowQuickHelp( this, aItemRect
, m_aText
->GetText() );
287 void OStartMarker::setCollapsed(bool _bCollapsed
)
289 OColorListener::setCollapsed(_bCollapsed
);
290 showRuler(_bCollapsed
);
294 void OStartMarker::zoom(const Fraction
& _aZoom
)
296 setZoomFactor(_aZoom
,*this);
297 m_aVRuler
->SetZoom(_aZoom
);
298 setZoomFactor(_aZoom
, *m_aText
.get());
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */