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