merge the formfield patch from ooo-build
[ooovba.git] / reportdesign / source / ui / report / StartMarker.cxx
blobde583cf0ce3dc5d0c86ded85268d933b2ab478f1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: StartMarker.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
31 #include "StartMarker.hxx"
32 #include <vcl/image.hxx>
33 #include <vcl/svapp.hxx>
34 #include "RptResId.hrc"
35 #include "ModuleHelper.hxx"
36 #include "ColorChanger.hxx"
37 #include "ReportDefines.hxx"
38 #include "SectionWindow.hxx"
39 #include "helpids.hrc"
40 #include <vcl/help.hxx>
41 #include <vcl/gradient.hxx>
42 #include <vcl/lineinfo.hxx>
43 #include <toolkit/helper/vclunohelper.hxx>
44 #include <svtools/syslocale.hxx>
45 #include <svtools/smplhint.hxx>
47 #define CORNER_SPACE 5
49 //=====================================================================
50 namespace rptui
52 //=====================================================================
54 Image* OStartMarker::s_pDefCollapsed = NULL;
55 Image* OStartMarker::s_pDefExpanded = NULL;
56 Image* OStartMarker::s_pDefCollapsedHC = NULL;
57 Image* OStartMarker::s_pDefExpandedHC = NULL;
58 oslInterlockedCount OStartMarker::s_nImageRefCount = 0;
60 DBG_NAME( rpt_OStartMarker )
61 // -----------------------------------------------------------------------------
62 OStartMarker::OStartMarker(OSectionWindow* _pParent,const ::rtl::OUString& _sColorEntry)
63 : OColorListener(_pParent,_sColorEntry)
64 ,m_aVRuler(this,WB_VERT)
65 ,m_aText(this,WB_HYPHENATION)
66 ,m_aImage(this,WB_LEFT|WB_TOP|WB_SCALE)
67 ,m_pParent(_pParent)
68 ,m_bShowRuler(sal_True)
70 DBG_CTOR( rpt_OStartMarker,NULL);
71 SetUniqueId(HID_RPT_STARTMARKER);
73 osl_incrementInterlockedCount(&s_nImageRefCount);
74 initDefaultNodeImages();
75 ImplInitSettings();
76 m_aText.SetHelpId(HID_RPT_START_TITLE);
77 m_aImage.SetHelpId(HID_RPT_START_IMAGE);
78 m_aText.Show();
79 m_aImage.Show();
80 m_aVRuler.Show();
81 m_aVRuler.Activate();
82 m_aVRuler.SetPagePos(0);
83 m_aVRuler.SetBorders();
84 m_aVRuler.SetIndents();
85 m_aVRuler.SetMargin1();
86 m_aVRuler.SetMargin2();
87 const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
88 m_aVRuler.SetUnit(MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH);
89 SetPaintTransparent(TRUE);
91 // -----------------------------------------------------------------------------
92 OStartMarker::~OStartMarker()
94 DBG_DTOR( rpt_OStartMarker,NULL);
95 if ( osl_decrementInterlockedCount(&s_nImageRefCount) == 0 )
97 DELETEZ(s_pDefCollapsed);
98 DELETEZ(s_pDefExpanded);
99 DELETEZ(s_pDefCollapsedHC);
100 DELETEZ(s_pDefExpandedHC);
101 } // if ( osl_decrementInterlockedCount(&s_nImageRefCount) == 0 )
103 // -----------------------------------------------------------------------------
104 sal_Int32 OStartMarker::getMinHeight() const
106 Fraction aExtraWidth(long(2*REPORT_EXTRA_SPACE));
107 aExtraWidth *= GetMapMode().GetScaleX();
108 return LogicToPixel(Size(0,m_aText.GetTextHeight())).Height() + (long)aExtraWidth;
110 // -----------------------------------------------------------------------------
111 void OStartMarker::Paint( const Rectangle& rRect )
113 Window::Paint( rRect );
114 //SetUpdateMode(FALSE);
115 Size aSize = GetOutputSizePixel();
116 long nSize = aSize.Width();
117 const long nCornerWidth = long(CORNER_SPACE * (double)GetMapMode().GetScaleX());
119 if ( !isCollapsed() )
121 const long nVRulerWidth = m_aVRuler.GetSizePixel().Width();
122 nSize = aSize.Width() - nVRulerWidth/* - m_nCornerSize*/;
123 SetClipRegion(Region(PixelToLogic(Rectangle(Point(),Size( nSize,aSize.Height())))));
124 aSize.Width() += nCornerWidth;
125 } // if ( !isCollapsed() )
126 else
127 SetClipRegion();
129 const Point aGcc3WorkaroundTemporary;
130 Rectangle aWholeRect(aGcc3WorkaroundTemporary,aSize);
132 const ColorChanger aColors( this, m_nTextBoundaries, m_nColor );
133 PolyPolygon aPoly;
134 aPoly.Insert(Polygon(aWholeRect,nCornerWidth,nCornerWidth));
136 Color aStartColor(m_nColor);
137 aStartColor.IncreaseLuminance(10);
138 USHORT nHue = 0;
139 USHORT nSat = 0;
140 USHORT nBri = 0;
141 aStartColor.RGBtoHSB(nHue, nSat, nBri);
142 nSat += 40;
143 Color aEndColor(Color::HSBtoRGB(nHue, nSat, nBri));
144 Gradient aGradient(GRADIENT_LINEAR,aStartColor,aEndColor);
145 aGradient.SetSteps(static_cast<USHORT>(aSize.Height()));
147 DrawGradient(PixelToLogic(aPoly) ,aGradient);
149 if ( m_bMarked )
151 const long nCornerHeight = long(CORNER_SPACE * (double)GetMapMode().GetScaleY());
152 Rectangle aRect( Point(nCornerWidth,nCornerHeight),
153 Size(aSize.Width() - nCornerWidth - nCornerWidth,aSize.Height() - nCornerHeight - nCornerHeight));
154 ColorChanger aColors( this, COL_WHITE, COL_WHITE );
155 DrawPolyLine(Polygon(PixelToLogic(aRect)),LineInfo(LINE_SOLID,2 ));
158 // -----------------------------------------------------------------------------
159 void OStartMarker::setColor()
161 const Color aColor(m_nColor);
162 Color aTextColor = GetTextColor();
163 if ( aColor.GetLuminance() < 128 )
164 aTextColor = COL_WHITE;
165 m_aText.SetTextColor(aTextColor);
166 m_aText.SetLineColor(m_nColor);
168 // -----------------------------------------------------------------------
169 void OStartMarker::MouseButtonUp( const MouseEvent& rMEvt )
171 if ( !rMEvt.IsLeft() )
172 return;
174 Point aPos( rMEvt.GetPosPixel());
176 const Size aOutputSize = GetOutputSizePixel();
177 if( aPos.X() > aOutputSize.Width() || aPos.Y() > aOutputSize.Height() )
178 return;
179 Rectangle aRect(m_aImage.GetPosPixel(),m_aImage.GetSizePixel());
180 if ( rMEvt.GetClicks() == 2 || aRect.IsInside( aPos ) )
182 m_bCollapsed = !m_bCollapsed;
184 changeImage();
186 m_aVRuler.Show(!m_bCollapsed && m_bShowRuler);
187 if ( m_aCollapsedLink.IsSet() )
188 m_aCollapsedLink.Call(this);
191 m_pParent->showProperties();
193 // -----------------------------------------------------------------------------
194 void OStartMarker::changeImage()
196 Image* pImage = NULL;
197 if ( GetDisplayBackground().GetColor().IsDark() )
198 pImage = m_bCollapsed ? s_pDefCollapsedHC : s_pDefExpandedHC;
199 else
200 pImage = m_bCollapsed ? s_pDefCollapsed : s_pDefExpanded;
201 m_aImage.SetImage(*pImage);
203 // -----------------------------------------------------------------------
204 void OStartMarker::initDefaultNodeImages()
206 if ( !s_pDefCollapsed )
208 s_pDefCollapsed = new Image( ModuleRes( RID_IMG_TREENODE_COLLAPSED ) );
209 s_pDefCollapsedHC = new Image( ModuleRes( RID_IMG_TREENODE_COLLAPSED_HC ) );
210 s_pDefExpanded = new Image( ModuleRes( RID_IMG_TREENODE_EXPANDED ) );
211 s_pDefExpandedHC = new Image( ModuleRes( RID_IMG_TREENODE_EXPANDED_HC ) );
214 Image* pImage = NULL;
215 if ( GetDisplayBackground().GetColor().IsDark() )
217 pImage = m_bCollapsed ? s_pDefCollapsedHC : s_pDefExpandedHC;
219 else
221 pImage = m_bCollapsed ? s_pDefCollapsed : s_pDefExpanded;
223 m_aImage.SetImage(*pImage);
224 m_aImage.SetMouseTransparent(TRUE);
225 m_aImage.SetBackground();
226 m_aText.SetBackground();
227 m_aText.SetMouseTransparent(TRUE);
229 // -----------------------------------------------------------------------
230 void OStartMarker::ImplInitSettings()
232 // SetBackground( Wallpaper( COL_YELLOW ));
233 SetBackground( );
234 SetFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
235 setColor();
237 //------------------------------------------------------------------------------
238 void OStartMarker::Resize()
240 const Size aOutputSize( GetOutputSizePixel() );
241 const long nOutputWidth = aOutputSize.Width();
242 const long nOutputHeight = aOutputSize.Height();
244 const long nVRulerWidth = m_aVRuler.GetSizePixel().Width();
245 const Point aRulerPos(nOutputWidth - nVRulerWidth,0);
246 m_aVRuler.SetPosSizePixel(aRulerPos,Size(nVRulerWidth,nOutputHeight));
248 Size aImageSize = m_aImage.GetImage().GetSizePixel();
249 const MapMode& rMapMode = GetMapMode();
250 aImageSize.Width() = long(aImageSize.Width() * (double)rMapMode.GetScaleX());
251 aImageSize.Height() = long(aImageSize.Height() * (double)rMapMode.GetScaleY());
253 Fraction aExtraWidth(long(REPORT_EXTRA_SPACE));
254 aExtraWidth *= rMapMode.GetScaleX();
256 Point aPos(aImageSize.Width() + (long)(aExtraWidth + aExtraWidth), aExtraWidth);
257 const long nHeight = ::std::max<sal_Int32>(nOutputHeight - 2*aPos.Y(),LogicToPixel(Size(0,m_aText.GetTextHeight())).Height());
258 m_aText.SetPosSizePixel(aPos,Size(aRulerPos.X() - aPos.X(),nHeight));
260 aPos.X() = aExtraWidth;
261 aPos.Y() += static_cast<sal_Int32>((LogicToPixel(Size(0,m_aText.GetTextHeight())).Height() - aImageSize.Height()) * 0.5) ;
262 m_aImage.SetPosSizePixel(aPos,aImageSize);
264 // -----------------------------------------------------------------------------
265 void OStartMarker::setTitle(const String& _sTitle)
267 m_aText.SetText(_sTitle);
269 // -----------------------------------------------------------------------------
270 void OStartMarker::Notify(SfxBroadcaster & rBc, SfxHint const & rHint)
272 OColorListener::Notify(rBc, rHint);
273 if (rHint.ISA(SfxSimpleHint)
274 && (static_cast< SfxSimpleHint const & >(rHint).GetId()
275 == SFX_HINT_COLORS_CHANGED))
277 setColor();
278 //m_aText.Invalidate();
279 Invalidate(INVALIDATE_CHILDREN);
282 //----------------------------------------------------------------------------
283 void OStartMarker::showRuler(sal_Bool _bShow)
285 m_bShowRuler = _bShow;
286 m_aVRuler.Show(!m_bCollapsed && m_bShowRuler);
288 //------------------------------------------------------------------------------
289 sal_Int32 OStartMarker::getRulerOffset() const
291 return m_aVRuler.GetSizePixel().Width();
294 //------------------------------------------------------------------------------
295 void OStartMarker::RequestHelp( const HelpEvent& rHEvt )
297 if( m_aText.GetText().Len())
299 // Hilfe anzeigen
300 Rectangle aItemRect(rHEvt.GetMousePosPixel(),Size(GetSizePixel().Width(),getMinHeight()));
301 //aItemRect = LogicToPixel( aItemRect );
302 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
303 aItemRect.Left() = aPt.X();
304 aItemRect.Top() = aPt.Y();
305 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
306 aItemRect.Right() = aPt.X();
307 aItemRect.Bottom() = aPt.Y();
308 if( rHEvt.GetMode() == HELPMODE_BALLOON )
309 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, m_aText.GetText());
310 else
311 Help::ShowQuickHelp( this, aItemRect, m_aText.GetText() );
314 // -----------------------------------------------------------------------------
315 void OStartMarker::setCollapsed(sal_Bool _bCollapsed)
317 OColorListener::setCollapsed(_bCollapsed);
318 showRuler(_bCollapsed);
319 changeImage();
321 // -----------------------------------------------------------------------
322 void OStartMarker::zoom(const Fraction& _aZoom)
324 setZoomFactor(_aZoom,*this);
325 m_aVRuler.SetZoom(_aZoom);
326 setZoomFactor(_aZoom,m_aText);
327 Resize();
328 Invalidate();
330 // -----------------------------------------------------------------------
331 // =======================================================================
333 // =======================================================================