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 "RptResId.hrc"
23 #include "ModuleHelper.hxx"
24 #include "ColorChanger.hxx"
25 #include "ReportDefines.hxx"
26 #include "SectionWindow.hxx"
27 #include "helpids.hrc"
28 #include <vcl/help.hxx>
29 #include <vcl/gradient.hxx>
30 #include <vcl/lineinfo.hxx>
31 #include <vcl/settings.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <unotools/syslocale.hxx>
35 #include <svl/smplhint.hxx>
37 #define CORNER_SPACE 5
44 Image
* OStartMarker::s_pDefCollapsed
= NULL
;
45 Image
* OStartMarker::s_pDefExpanded
= NULL
;
46 oslInterlockedCount
OStartMarker::s_nImageRefCount
= 0;
49 OStartMarker::OStartMarker(OSectionWindow
* _pParent
,const OUString
& _sColorEntry
)
50 : OColorListener(_pParent
,_sColorEntry
)
51 ,m_aVRuler(VclPtr
<Ruler
>::Create(this,WB_VERT
))
52 ,m_aText(VclPtr
<FixedText
>::Create(this,WB_HYPHENATION
))
53 ,m_aImage(VclPtr
<FixedImage
>::Create(this,WB_LEFT
|WB_TOP
|WB_SCALE
))
57 SetUniqueId(HID_RPT_STARTMARKER
);
59 osl_atomic_increment(&s_nImageRefCount
);
60 initDefaultNodeImages();
62 m_aText
->SetHelpId(HID_RPT_START_TITLE
);
63 m_aText
->SetPaintTransparent(true);
64 m_aImage
->SetHelpId(HID_RPT_START_IMAGE
);
68 m_aVRuler
->Activate();
69 m_aVRuler
->SetPagePos(0);
70 m_aVRuler
->SetBorders();
71 m_aVRuler
->SetIndents();
72 m_aVRuler
->SetMargin1();
73 m_aVRuler
->SetMargin2();
74 const MeasurementSystem eSystem
= SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
75 m_aVRuler
->SetUnit(MEASURE_METRIC
== eSystem
? FUNIT_CM
: FUNIT_INCH
);
76 EnableChildTransparentMode( true );
77 SetParentClipMode( PARENTCLIPMODE_NOCLIP
);
78 SetPaintTransparent( true );
81 OStartMarker::~OStartMarker()
86 void OStartMarker::dispose()
88 if ( osl_atomic_decrement(&s_nImageRefCount
) == 0 )
90 DELETEZ(s_pDefCollapsed
);
91 DELETEZ(s_pDefExpanded
);
93 m_aVRuler
.disposeAndClear();
94 m_aText
.disposeAndClear();
95 m_aImage
.disposeAndClear();
97 OColorListener::dispose();
100 sal_Int32
OStartMarker::getMinHeight() const
102 Fraction
aExtraWidth(long(2 * REPORT_EXTRA_SPACE
));
103 aExtraWidth
*= GetMapMode().GetScaleX();
104 return LogicToPixel(Size(0, m_aText
->GetTextHeight())).Height() + long(aExtraWidth
);
107 void OStartMarker::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& /*rRect*/)
109 Size
aSize(GetOutputSizePixel());
110 long nSize
= aSize
.Width();
111 const long nCornerWidth
= long(CORNER_SPACE
* double(GetMapMode().GetScaleX()));
115 rRenderContext
.SetClipRegion();
119 const long nVRulerWidth
= m_aVRuler
->GetSizePixel().Width();
120 nSize
= aSize
.Width() - nVRulerWidth
;
121 aSize
.Width() += nCornerWidth
;
122 rRenderContext
.SetClipRegion(vcl::Region(rRenderContext
.PixelToLogic(Rectangle(Point(),
123 Size(nSize
, aSize
.Height())))));
126 Rectangle
aWholeRect(Point(), aSize
);
128 const ColorChanger
aColors(&rRenderContext
, m_nTextBoundaries
, m_nColor
);
129 tools::PolyPolygon aPoly
;
130 aPoly
.Insert(Polygon(aWholeRect
,nCornerWidth
,nCornerWidth
));
132 Color
aStartColor(m_nColor
);
133 aStartColor
.IncreaseLuminance(10);
137 aStartColor
.RGBtoHSB(nHue
, nSat
, nBri
);
139 Color
aEndColor(Color::HSBtoRGB(nHue
, nSat
, nBri
));
140 Gradient
aGradient(GradientStyle_LINEAR
,aStartColor
,aEndColor
);
141 aGradient
.SetSteps(static_cast<sal_uInt16
>(aSize
.Height()));
143 rRenderContext
.DrawGradient(PixelToLogic(aPoly
) ,aGradient
);
147 const long nCornerHeight
= long(CORNER_SPACE
* double(GetMapMode().GetScaleY()));
148 Rectangle
aRect(Point(nCornerWidth
, nCornerHeight
),
149 Size(aSize
.Width() - nCornerWidth
- nCornerWidth
,
150 aSize
.Height() - nCornerHeight
- nCornerHeight
));
151 ColorChanger
aColors(&rRenderContext
, COL_WHITE
, COL_WHITE
);
152 rRenderContext
.DrawPolyLine(Polygon(rRenderContext
.PixelToLogic(aRect
)),
153 LineInfo(LINE_SOLID
, 2));
157 void OStartMarker::setColor()
159 const Color
aColor(m_nColor
);
160 Color aTextColor
= GetTextColor();
161 if ( aColor
.GetLuminance() < 128 )
162 aTextColor
= COL_WHITE
;
163 m_aText
->SetTextColor(aTextColor
);
164 m_aText
->SetLineColor(m_nColor
);
167 void OStartMarker::MouseButtonUp( const MouseEvent
& rMEvt
)
169 if ( !rMEvt
.IsLeft() )
172 Point
aPos( rMEvt
.GetPosPixel());
174 const Size aOutputSize
= GetOutputSizePixel();
175 if( aPos
.X() > aOutputSize
.Width() || aPos
.Y() > aOutputSize
.Height() )
177 Rectangle
aRect(m_aImage
->GetPosPixel(),m_aImage
->GetSizePixel());
178 if ( rMEvt
.GetClicks() == 2 || aRect
.IsInside( aPos
) )
180 m_bCollapsed
= !m_bCollapsed
;
184 m_aVRuler
->Show(!m_bCollapsed
&& m_bShowRuler
);
185 if ( m_aCollapsedLink
.IsSet() )
186 m_aCollapsedLink
.Call(this);
189 m_pParent
->showProperties();
192 void OStartMarker::changeImage()
194 Image
* pImage
= m_bCollapsed
? s_pDefCollapsed
: s_pDefExpanded
;
195 m_aImage
->SetImage(*pImage
);
198 void OStartMarker::initDefaultNodeImages()
200 if ( !s_pDefCollapsed
)
202 s_pDefCollapsed
= new Image( ModuleRes( RID_IMG_TREENODE_COLLAPSED
) );
203 s_pDefExpanded
= new Image( ModuleRes( RID_IMG_TREENODE_EXPANDED
) );
206 Image
* pImage
= m_bCollapsed
? s_pDefCollapsed
: s_pDefExpanded
;
207 m_aImage
->SetImage(*pImage
);
208 m_aImage
->SetMouseTransparent(true);
209 m_aImage
->SetBackground();
210 m_aText
->SetBackground();
211 m_aText
->SetMouseTransparent(true);
214 void OStartMarker::ApplySettings(vcl::RenderContext
& rRenderContext
)
216 rRenderContext
.SetBackground();
217 rRenderContext
.SetFillColor(Application::GetSettings().GetStyleSettings().GetDialogColor());
221 void OStartMarker::ImplInitSettings()
223 ApplySettings(*this);
226 void OStartMarker::Resize()
228 const Size
aOutputSize( GetOutputSizePixel() );
229 const long nOutputWidth
= aOutputSize
.Width();
230 const long nOutputHeight
= aOutputSize
.Height();
232 const long nVRulerWidth
= m_aVRuler
->GetSizePixel().Width();
233 const Point
aRulerPos(nOutputWidth
- nVRulerWidth
,0);
234 m_aVRuler
->SetPosSizePixel(aRulerPos
,Size(nVRulerWidth
,nOutputHeight
));
236 Size aImageSize
= m_aImage
->GetImage().GetSizePixel();
237 const MapMode
& rMapMode
= GetMapMode();
238 aImageSize
.Width() = long(aImageSize
.Width() * (double)rMapMode
.GetScaleX());
239 aImageSize
.Height() = long(aImageSize
.Height() * (double)rMapMode
.GetScaleY());
241 Fraction
aExtraWidth(long(REPORT_EXTRA_SPACE
));
242 aExtraWidth
*= rMapMode
.GetScaleX();
244 Point
aPos(aImageSize
.Width() + (long)(aExtraWidth
+ aExtraWidth
), aExtraWidth
);
245 const long nHeight
= ::std::max
<sal_Int32
>(nOutputHeight
- 2*aPos
.Y(),LogicToPixel(Size(0,m_aText
->GetTextHeight())).Height());
246 m_aText
->SetPosSizePixel(aPos
,Size(aRulerPos
.X() - aPos
.X(),nHeight
));
248 aPos
.X() = aExtraWidth
;
249 aPos
.Y() += static_cast<sal_Int32
>((LogicToPixel(Size(0,m_aText
->GetTextHeight())).Height() - aImageSize
.Height()) * 0.5) ;
250 m_aImage
->SetPosSizePixel(aPos
,aImageSize
);
253 void OStartMarker::setTitle(const OUString
& _sTitle
)
255 m_aText
->SetText(_sTitle
);
258 void OStartMarker::Notify(SfxBroadcaster
& rBc
, SfxHint
const & rHint
)
260 OColorListener::Notify(rBc
, rHint
);
261 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
262 if (pSimpleHint
&& pSimpleHint
->GetId() == SFX_HINT_COLORS_CHANGED
)
265 Invalidate(INVALIDATE_CHILDREN
);
269 void OStartMarker::showRuler(bool _bShow
)
271 m_bShowRuler
= _bShow
;
272 m_aVRuler
->Show(!m_bCollapsed
&& m_bShowRuler
);
275 void OStartMarker::RequestHelp( const HelpEvent
& rHEvt
)
277 if( !m_aText
->GetText().isEmpty())
280 Rectangle
aItemRect(rHEvt
.GetMousePosPixel(),Size(GetSizePixel().Width(),getMinHeight()));
281 Point aPt
= OutputToScreenPixel( aItemRect
.TopLeft() );
282 aItemRect
.Left() = aPt
.X();
283 aItemRect
.Top() = aPt
.Y();
284 aPt
= OutputToScreenPixel( aItemRect
.BottomRight() );
285 aItemRect
.Right() = aPt
.X();
286 aItemRect
.Bottom() = aPt
.Y();
287 if( rHEvt
.GetMode() == HelpEventMode::BALLOON
)
288 Help::ShowBalloon( this, aItemRect
.Center(), aItemRect
, m_aText
->GetText());
290 Help::ShowQuickHelp( this, aItemRect
, m_aText
->GetText() );
294 void OStartMarker::setCollapsed(bool _bCollapsed
)
296 OColorListener::setCollapsed(_bCollapsed
);
297 showRuler(_bCollapsed
);
301 void OStartMarker::zoom(const Fraction
& _aZoom
)
303 setZoomFactor(_aZoom
,*this);
304 m_aVRuler
->SetZoom(_aZoom
);
305 setZoomFactor(_aZoom
, *m_aText
.get());
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */