1*9e0e4191SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9e0e4191SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9e0e4191SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9e0e4191SAndrew Rist * distributed with this work for additional information
6*9e0e4191SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9e0e4191SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9e0e4191SAndrew Rist * "License"); you may not use this file except in compliance
9*9e0e4191SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*9e0e4191SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*9e0e4191SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9e0e4191SAndrew Rist * software distributed under the License is distributed on an
15*9e0e4191SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9e0e4191SAndrew Rist * KIND, either express or implied. See the License for the
17*9e0e4191SAndrew Rist * specific language governing permissions and limitations
18*9e0e4191SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*9e0e4191SAndrew Rist *************************************************************/
21*9e0e4191SAndrew Rist
22*9e0e4191SAndrew Rist
23cdf0e10cSrcweir #include "precompiled_reportdesign.hxx"
24cdf0e10cSrcweir #include "StartMarker.hxx"
25cdf0e10cSrcweir #include <vcl/image.hxx>
26cdf0e10cSrcweir #include <vcl/svapp.hxx>
27cdf0e10cSrcweir #include "RptResId.hrc"
28cdf0e10cSrcweir #include "ModuleHelper.hxx"
29cdf0e10cSrcweir #include "ColorChanger.hxx"
30cdf0e10cSrcweir #include "ReportDefines.hxx"
31cdf0e10cSrcweir #include "SectionWindow.hxx"
32cdf0e10cSrcweir #include "helpids.hrc"
33cdf0e10cSrcweir #include <vcl/help.hxx>
34cdf0e10cSrcweir #include <vcl/gradient.hxx>
35cdf0e10cSrcweir #include <vcl/lineinfo.hxx>
36cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
37cdf0e10cSrcweir #include <unotools/syslocale.hxx>
38cdf0e10cSrcweir #include <svl/smplhint.hxx>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #define CORNER_SPACE 5
41cdf0e10cSrcweir
42cdf0e10cSrcweir //=====================================================================
43cdf0e10cSrcweir namespace rptui
44cdf0e10cSrcweir {
45cdf0e10cSrcweir //=====================================================================
46cdf0e10cSrcweir
47cdf0e10cSrcweir Image* OStartMarker::s_pDefCollapsed = NULL;
48cdf0e10cSrcweir Image* OStartMarker::s_pDefExpanded = NULL;
49cdf0e10cSrcweir Image* OStartMarker::s_pDefCollapsedHC = NULL;
50cdf0e10cSrcweir Image* OStartMarker::s_pDefExpandedHC = NULL;
51cdf0e10cSrcweir oslInterlockedCount OStartMarker::s_nImageRefCount = 0;
52cdf0e10cSrcweir
DBG_NAME(rpt_OStartMarker)53cdf0e10cSrcweir DBG_NAME( rpt_OStartMarker )
54cdf0e10cSrcweir // -----------------------------------------------------------------------------
55cdf0e10cSrcweir OStartMarker::OStartMarker(OSectionWindow* _pParent,const ::rtl::OUString& _sColorEntry)
56cdf0e10cSrcweir : OColorListener(_pParent,_sColorEntry)
57cdf0e10cSrcweir ,m_aVRuler(this,WB_VERT)
58cdf0e10cSrcweir ,m_aText(this,WB_HYPHENATION)
59cdf0e10cSrcweir ,m_aImage(this,WB_LEFT|WB_TOP|WB_SCALE)
60cdf0e10cSrcweir ,m_pParent(_pParent)
61cdf0e10cSrcweir ,m_bShowRuler(sal_True)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir DBG_CTOR( rpt_OStartMarker,NULL);
64cdf0e10cSrcweir SetUniqueId(HID_RPT_STARTMARKER);
65cdf0e10cSrcweir
66cdf0e10cSrcweir osl_incrementInterlockedCount(&s_nImageRefCount);
67cdf0e10cSrcweir initDefaultNodeImages();
68cdf0e10cSrcweir ImplInitSettings();
69cdf0e10cSrcweir m_aText.SetHelpId(HID_RPT_START_TITLE);
70cdf0e10cSrcweir m_aText.SetPaintTransparent(sal_True);
71cdf0e10cSrcweir m_aImage.SetHelpId(HID_RPT_START_IMAGE);
72cdf0e10cSrcweir m_aText.Show();
73cdf0e10cSrcweir m_aImage.Show();
74cdf0e10cSrcweir m_aVRuler.Show();
75cdf0e10cSrcweir m_aVRuler.Activate();
76cdf0e10cSrcweir m_aVRuler.SetPagePos(0);
77cdf0e10cSrcweir m_aVRuler.SetBorders();
78cdf0e10cSrcweir m_aVRuler.SetIndents();
79cdf0e10cSrcweir m_aVRuler.SetMargin1();
80cdf0e10cSrcweir m_aVRuler.SetMargin2();
81cdf0e10cSrcweir const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
82cdf0e10cSrcweir m_aVRuler.SetUnit(MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH);
83cdf0e10cSrcweir EnableChildTransparentMode( sal_True );
84cdf0e10cSrcweir SetParentClipMode( PARENTCLIPMODE_NOCLIP );
85cdf0e10cSrcweir SetPaintTransparent( sal_True );
86cdf0e10cSrcweir }
87cdf0e10cSrcweir // -----------------------------------------------------------------------------
~OStartMarker()88cdf0e10cSrcweir OStartMarker::~OStartMarker()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir DBG_DTOR( rpt_OStartMarker,NULL);
91cdf0e10cSrcweir if ( osl_decrementInterlockedCount(&s_nImageRefCount) == 0 )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir DELETEZ(s_pDefCollapsed);
94cdf0e10cSrcweir DELETEZ(s_pDefExpanded);
95cdf0e10cSrcweir DELETEZ(s_pDefCollapsedHC);
96cdf0e10cSrcweir DELETEZ(s_pDefExpandedHC);
97cdf0e10cSrcweir } // if ( osl_decrementInterlockedCount(&s_nImageRefCount) == 0 )
98cdf0e10cSrcweir }
99cdf0e10cSrcweir // -----------------------------------------------------------------------------
getMinHeight() const100cdf0e10cSrcweir sal_Int32 OStartMarker::getMinHeight() const
101cdf0e10cSrcweir {
102cdf0e10cSrcweir Fraction aExtraWidth(long(2*REPORT_EXTRA_SPACE));
103cdf0e10cSrcweir aExtraWidth *= GetMapMode().GetScaleX();
104cdf0e10cSrcweir return LogicToPixel(Size(0,m_aText.GetTextHeight())).Height() + (long)aExtraWidth;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir // -----------------------------------------------------------------------------
Paint(const Rectangle & rRect)107cdf0e10cSrcweir void OStartMarker::Paint( const Rectangle& rRect )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir (void)rRect;
110cdf0e10cSrcweir //SetUpdateMode(sal_False);
111cdf0e10cSrcweir Size aSize = GetOutputSizePixel();
112cdf0e10cSrcweir long nSize = aSize.Width();
113cdf0e10cSrcweir const long nCornerWidth = long(CORNER_SPACE * (double)GetMapMode().GetScaleX());
114cdf0e10cSrcweir
115cdf0e10cSrcweir if ( isCollapsed() )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir SetClipRegion();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir else
120cdf0e10cSrcweir {
121cdf0e10cSrcweir const long nVRulerWidth = m_aVRuler.GetSizePixel().Width();
122cdf0e10cSrcweir nSize = aSize.Width() - nVRulerWidth/* - m_nCornerSize*/;
123cdf0e10cSrcweir aSize.Width() += nCornerWidth;
124cdf0e10cSrcweir SetClipRegion(Region(PixelToLogic(Rectangle(Point(),Size(nSize,aSize.Height())))));
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
127cdf0e10cSrcweir const Point aGcc3WorkaroundTemporary;
128cdf0e10cSrcweir Rectangle aWholeRect(aGcc3WorkaroundTemporary,aSize);
129cdf0e10cSrcweir {
130cdf0e10cSrcweir const ColorChanger aColors( this, m_nTextBoundaries, m_nColor );
131cdf0e10cSrcweir PolyPolygon aPoly;
132cdf0e10cSrcweir aPoly.Insert(Polygon(aWholeRect,nCornerWidth,nCornerWidth));
133cdf0e10cSrcweir
134cdf0e10cSrcweir Color aStartColor(m_nColor);
135cdf0e10cSrcweir aStartColor.IncreaseLuminance(10);
136cdf0e10cSrcweir sal_uInt16 nHue = 0;
137cdf0e10cSrcweir sal_uInt16 nSat = 0;
138cdf0e10cSrcweir sal_uInt16 nBri = 0;
139cdf0e10cSrcweir aStartColor.RGBtoHSB(nHue, nSat, nBri);
140cdf0e10cSrcweir nSat += 40;
141cdf0e10cSrcweir Color aEndColor(Color::HSBtoRGB(nHue, nSat, nBri));
142cdf0e10cSrcweir Gradient aGradient(GRADIENT_LINEAR,aStartColor,aEndColor);
143cdf0e10cSrcweir aGradient.SetSteps(static_cast<sal_uInt16>(aSize.Height()));
144cdf0e10cSrcweir
145cdf0e10cSrcweir DrawGradient(PixelToLogic(aPoly) ,aGradient);
146cdf0e10cSrcweir }
147cdf0e10cSrcweir if ( m_bMarked )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir const long nCornerHeight = long(CORNER_SPACE * (double)GetMapMode().GetScaleY());
150cdf0e10cSrcweir Rectangle aRect( Point(nCornerWidth,nCornerHeight),
151cdf0e10cSrcweir Size(aSize.Width() - nCornerWidth - nCornerWidth,aSize.Height() - nCornerHeight - nCornerHeight));
152cdf0e10cSrcweir ColorChanger aColors( this, COL_WHITE, COL_WHITE );
153cdf0e10cSrcweir DrawPolyLine(Polygon(PixelToLogic(aRect)),LineInfo(LINE_SOLID,2 ));
154cdf0e10cSrcweir }
155cdf0e10cSrcweir }
156cdf0e10cSrcweir // -----------------------------------------------------------------------------
setColor()157cdf0e10cSrcweir void OStartMarker::setColor()
158cdf0e10cSrcweir {
159cdf0e10cSrcweir const Color aColor(m_nColor);
160cdf0e10cSrcweir Color aTextColor = GetTextColor();
161cdf0e10cSrcweir if ( aColor.GetLuminance() < 128 )
162cdf0e10cSrcweir aTextColor = COL_WHITE;
163cdf0e10cSrcweir m_aText.SetTextColor(aTextColor);
164cdf0e10cSrcweir m_aText.SetLineColor(m_nColor);
165cdf0e10cSrcweir }
166cdf0e10cSrcweir // -----------------------------------------------------------------------
MouseButtonUp(const MouseEvent & rMEvt)167cdf0e10cSrcweir void OStartMarker::MouseButtonUp( const MouseEvent& rMEvt )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir if ( !rMEvt.IsLeft() )
170cdf0e10cSrcweir return;
171cdf0e10cSrcweir
172cdf0e10cSrcweir Point aPos( rMEvt.GetPosPixel());
173cdf0e10cSrcweir
174cdf0e10cSrcweir const Size aOutputSize = GetOutputSizePixel();
175cdf0e10cSrcweir if( aPos.X() > aOutputSize.Width() || aPos.Y() > aOutputSize.Height() )
176cdf0e10cSrcweir return;
177cdf0e10cSrcweir Rectangle aRect(m_aImage.GetPosPixel(),m_aImage.GetSizePixel());
178cdf0e10cSrcweir if ( rMEvt.GetClicks() == 2 || aRect.IsInside( aPos ) )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir m_bCollapsed = !m_bCollapsed;
181cdf0e10cSrcweir
182cdf0e10cSrcweir changeImage();
183cdf0e10cSrcweir
184cdf0e10cSrcweir m_aVRuler.Show(!m_bCollapsed && m_bShowRuler);
185cdf0e10cSrcweir if ( m_aCollapsedLink.IsSet() )
186cdf0e10cSrcweir m_aCollapsedLink.Call(this);
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
189cdf0e10cSrcweir m_pParent->showProperties();
190cdf0e10cSrcweir }
191cdf0e10cSrcweir // -----------------------------------------------------------------------------
changeImage()192cdf0e10cSrcweir void OStartMarker::changeImage()
193cdf0e10cSrcweir {
194cdf0e10cSrcweir Image* pImage = NULL;
195cdf0e10cSrcweir if ( GetSettings().GetStyleSettings().GetHighContrastMode() )
196cdf0e10cSrcweir pImage = m_bCollapsed ? s_pDefCollapsedHC : s_pDefExpandedHC;
197cdf0e10cSrcweir else
198cdf0e10cSrcweir pImage = m_bCollapsed ? s_pDefCollapsed : s_pDefExpanded;
199cdf0e10cSrcweir m_aImage.SetImage(*pImage);
200cdf0e10cSrcweir }
201cdf0e10cSrcweir // -----------------------------------------------------------------------
initDefaultNodeImages()202cdf0e10cSrcweir void OStartMarker::initDefaultNodeImages()
203cdf0e10cSrcweir {
204cdf0e10cSrcweir if ( !s_pDefCollapsed )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir s_pDefCollapsed = new Image( ModuleRes( RID_IMG_TREENODE_COLLAPSED ) );
207cdf0e10cSrcweir s_pDefCollapsedHC = new Image( ModuleRes( RID_IMG_TREENODE_COLLAPSED_HC ) );
208cdf0e10cSrcweir s_pDefExpanded = new Image( ModuleRes( RID_IMG_TREENODE_EXPANDED ) );
209cdf0e10cSrcweir s_pDefExpandedHC = new Image( ModuleRes( RID_IMG_TREENODE_EXPANDED_HC ) );
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
212cdf0e10cSrcweir Image* pImage = NULL;
213cdf0e10cSrcweir if ( GetSettings().GetStyleSettings().GetHighContrastMode() )
214cdf0e10cSrcweir {
215cdf0e10cSrcweir pImage = m_bCollapsed ? s_pDefCollapsedHC : s_pDefExpandedHC;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir else
218cdf0e10cSrcweir {
219cdf0e10cSrcweir pImage = m_bCollapsed ? s_pDefCollapsed : s_pDefExpanded;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir m_aImage.SetImage(*pImage);
222cdf0e10cSrcweir m_aImage.SetMouseTransparent(sal_True);
223cdf0e10cSrcweir m_aImage.SetBackground();
224cdf0e10cSrcweir m_aText.SetBackground();
225cdf0e10cSrcweir m_aText.SetMouseTransparent(sal_True);
226cdf0e10cSrcweir }
227cdf0e10cSrcweir // -----------------------------------------------------------------------
ImplInitSettings()228cdf0e10cSrcweir void OStartMarker::ImplInitSettings()
229cdf0e10cSrcweir {
230cdf0e10cSrcweir // SetBackground( Wallpaper( COL_YELLOW ));
231cdf0e10cSrcweir SetBackground( );
232cdf0e10cSrcweir SetFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
233cdf0e10cSrcweir setColor();
234cdf0e10cSrcweir }
235cdf0e10cSrcweir //------------------------------------------------------------------------------
Resize()236cdf0e10cSrcweir void OStartMarker::Resize()
237cdf0e10cSrcweir {
238cdf0e10cSrcweir const Size aOutputSize( GetOutputSizePixel() );
239cdf0e10cSrcweir const long nOutputWidth = aOutputSize.Width();
240cdf0e10cSrcweir const long nOutputHeight = aOutputSize.Height();
241cdf0e10cSrcweir
242cdf0e10cSrcweir const long nVRulerWidth = m_aVRuler.GetSizePixel().Width();
243cdf0e10cSrcweir const Point aRulerPos(nOutputWidth - nVRulerWidth,0);
244cdf0e10cSrcweir m_aVRuler.SetPosSizePixel(aRulerPos,Size(nVRulerWidth,nOutputHeight));
245cdf0e10cSrcweir
246cdf0e10cSrcweir Size aImageSize = m_aImage.GetImage().GetSizePixel();
247cdf0e10cSrcweir const MapMode& rMapMode = GetMapMode();
248cdf0e10cSrcweir aImageSize.Width() = long(aImageSize.Width() * (double)rMapMode.GetScaleX());
249cdf0e10cSrcweir aImageSize.Height() = long(aImageSize.Height() * (double)rMapMode.GetScaleY());
250cdf0e10cSrcweir
251cdf0e10cSrcweir Fraction aExtraWidth(long(REPORT_EXTRA_SPACE));
252cdf0e10cSrcweir aExtraWidth *= rMapMode.GetScaleX();
253cdf0e10cSrcweir
254cdf0e10cSrcweir Point aPos(aImageSize.Width() + (long)(aExtraWidth + aExtraWidth), aExtraWidth);
255cdf0e10cSrcweir const long nHeight = ::std::max<sal_Int32>(nOutputHeight - 2*aPos.Y(),LogicToPixel(Size(0,m_aText.GetTextHeight())).Height());
256cdf0e10cSrcweir m_aText.SetPosSizePixel(aPos,Size(aRulerPos.X() - aPos.X(),nHeight));
257cdf0e10cSrcweir
258cdf0e10cSrcweir aPos.X() = aExtraWidth;
259cdf0e10cSrcweir aPos.Y() += static_cast<sal_Int32>((LogicToPixel(Size(0,m_aText.GetTextHeight())).Height() - aImageSize.Height()) * 0.5) ;
260cdf0e10cSrcweir m_aImage.SetPosSizePixel(aPos,aImageSize);
261cdf0e10cSrcweir }
262cdf0e10cSrcweir // -----------------------------------------------------------------------------
setTitle(const String & _sTitle)263cdf0e10cSrcweir void OStartMarker::setTitle(const String& _sTitle)
264cdf0e10cSrcweir {
265cdf0e10cSrcweir m_aText.SetText(_sTitle);
266cdf0e10cSrcweir }
267cdf0e10cSrcweir // -----------------------------------------------------------------------------
Notify(SfxBroadcaster & rBc,SfxHint const & rHint)268cdf0e10cSrcweir void OStartMarker::Notify(SfxBroadcaster & rBc, SfxHint const & rHint)
269cdf0e10cSrcweir {
270cdf0e10cSrcweir OColorListener::Notify(rBc, rHint);
271cdf0e10cSrcweir if (rHint.ISA(SfxSimpleHint)
272cdf0e10cSrcweir && (static_cast< SfxSimpleHint const & >(rHint).GetId()
273cdf0e10cSrcweir == SFX_HINT_COLORS_CHANGED))
274cdf0e10cSrcweir {
275cdf0e10cSrcweir setColor();
276cdf0e10cSrcweir Invalidate(INVALIDATE_CHILDREN);
277cdf0e10cSrcweir }
278cdf0e10cSrcweir }
279cdf0e10cSrcweir //----------------------------------------------------------------------------
showRuler(sal_Bool _bShow)280cdf0e10cSrcweir void OStartMarker::showRuler(sal_Bool _bShow)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir m_bShowRuler = _bShow;
283cdf0e10cSrcweir m_aVRuler.Show(!m_bCollapsed && m_bShowRuler);
284cdf0e10cSrcweir }
285cdf0e10cSrcweir //------------------------------------------------------------------------------
RequestHelp(const HelpEvent & rHEvt)286cdf0e10cSrcweir void OStartMarker::RequestHelp( const HelpEvent& rHEvt )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir if( m_aText.GetText().Len())
289cdf0e10cSrcweir {
290cdf0e10cSrcweir // Hilfe anzeigen
291cdf0e10cSrcweir Rectangle aItemRect(rHEvt.GetMousePosPixel(),Size(GetSizePixel().Width(),getMinHeight()));
292cdf0e10cSrcweir //aItemRect = LogicToPixel( aItemRect );
293cdf0e10cSrcweir Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
294cdf0e10cSrcweir aItemRect.Left() = aPt.X();
295cdf0e10cSrcweir aItemRect.Top() = aPt.Y();
296cdf0e10cSrcweir aPt = OutputToScreenPixel( aItemRect.BottomRight() );
297cdf0e10cSrcweir aItemRect.Right() = aPt.X();
298cdf0e10cSrcweir aItemRect.Bottom() = aPt.Y();
299cdf0e10cSrcweir if( rHEvt.GetMode() == HELPMODE_BALLOON )
300cdf0e10cSrcweir Help::ShowBalloon( this, aItemRect.Center(), aItemRect, m_aText.GetText());
301cdf0e10cSrcweir else
302cdf0e10cSrcweir Help::ShowQuickHelp( this, aItemRect, m_aText.GetText() );
303cdf0e10cSrcweir }
304cdf0e10cSrcweir }
305cdf0e10cSrcweir // -----------------------------------------------------------------------------
setCollapsed(sal_Bool _bCollapsed)306cdf0e10cSrcweir void OStartMarker::setCollapsed(sal_Bool _bCollapsed)
307cdf0e10cSrcweir {
308cdf0e10cSrcweir OColorListener::setCollapsed(_bCollapsed);
309cdf0e10cSrcweir showRuler(_bCollapsed);
310cdf0e10cSrcweir changeImage();
311cdf0e10cSrcweir }
312cdf0e10cSrcweir // -----------------------------------------------------------------------
zoom(const Fraction & _aZoom)313cdf0e10cSrcweir void OStartMarker::zoom(const Fraction& _aZoom)
314cdf0e10cSrcweir {
315cdf0e10cSrcweir setZoomFactor(_aZoom,*this);
316cdf0e10cSrcweir m_aVRuler.SetZoom(_aZoom);
317cdf0e10cSrcweir setZoomFactor(_aZoom,m_aText);
318cdf0e10cSrcweir Resize();
319cdf0e10cSrcweir Invalidate();
320cdf0e10cSrcweir }
321cdf0e10cSrcweir // -----------------------------------------------------------------------
322cdf0e10cSrcweir // =======================================================================
323cdf0e10cSrcweir }
324cdf0e10cSrcweir // =======================================================================
325