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 "ScrollHelper.hxx" 29 #include "DesignView.hxx" 30 #include "ReportController.hxx" 31 #include "ReportWindow.hxx" 32 #include "UITools.hxx" 33 #include <tools/debug.hxx> 34 #include <com/sun/star/accessibility/AccessibleRole.hpp> 35 #include <toolkit/helper/convert.hxx> 36 #include <vcl/svapp.hxx> 37 38 namespace rptui 39 { 40 #define LINE_SIZE 50 41 #define SECTION_OFFSET 3 42 #define SCR_LINE_SIZE 10 43 using namespace ::com::sun::star; 44 45 // ----------------------------------------------------------------------------- 46 void lcl_setScrollBar(sal_Int32 _nNewValue,const Point& _aPos,const Size& _aSize,ScrollBar& _rScrollBar) 47 { 48 _rScrollBar.SetPosSizePixel(_aPos,_aSize); 49 _rScrollBar.SetPageSize( _nNewValue ); 50 _rScrollBar.SetVisibleSize( _nNewValue ); 51 } 52 53 // ----------------------------------------------------------------------------- 54 DBG_NAME( rpt_OScrollWindowHelper ); 55 OScrollWindowHelper::OScrollWindowHelper( ODesignView* _pDesignView) 56 : OScrollWindowHelper_BASE( _pDesignView,WB_DIALOGCONTROL) 57 ,OPropertyChangeListener(m_aMutex) 58 ,m_aHScroll( this, WB_HSCROLL|WB_REPEAT|WB_DRAG ) 59 ,m_aVScroll( this, WB_VSCROLL|WB_REPEAT|WB_DRAG ) 60 ,m_aCornerWin( this ) 61 ,m_pParent(_pDesignView) 62 ,m_aReportWindow(this,m_pParent) 63 ,m_pReportDefintionMultiPlexer(NULL) 64 { 65 DBG_CTOR( rpt_OScrollWindowHelper,NULL); 66 SetMapMode( MapMode( MAP_100TH_MM ) ); 67 68 impl_initScrollBar( m_aHScroll ); 69 impl_initScrollBar( m_aVScroll ); 70 71 m_aReportWindow.SetMapMode( MapMode( MAP_100TH_MM ) ); 72 m_aReportWindow.Show(); 73 74 // normally we should be SCROLL_PANE 75 SetAccessibleRole(accessibility::AccessibleRole::SCROLL_PANE); 76 ImplInitSettings(); 77 } 78 79 // ----------------------------------------------------------------------------- 80 OScrollWindowHelper::~OScrollWindowHelper() 81 { 82 DBG_DTOR( rpt_OScrollWindowHelper,NULL); 83 if ( m_pReportDefintionMultiPlexer.is() ) 84 m_pReportDefintionMultiPlexer->dispose(); 85 } 86 87 // ----------------------------------------------------------------------------- 88 void OScrollWindowHelper::impl_initScrollBar( ScrollBar& _rScrollBar ) const 89 { 90 AllSettings aSettings( _rScrollBar.GetSettings() ); 91 StyleSettings aStyle( aSettings.GetStyleSettings() ); 92 aStyle.SetDragFullOptions( aStyle.GetDragFullOptions() | DRAGFULL_OPTION_SCROLL ); // live scrolling 93 aSettings.SetStyleSettings( aStyle ); 94 _rScrollBar.SetSettings( aSettings ); 95 //_rScrollBar.SetMapMode( MapMode( MAP_100TH_MM ) ); 96 97 _rScrollBar.SetScrollHdl( LINK( this, OScrollWindowHelper, ScrollHdl ) ); 98 _rScrollBar.SetLineSize( SCR_LINE_SIZE ); 99 } 100 101 // ----------------------------------------------------------------------------- 102 void OScrollWindowHelper::initialize() 103 { 104 uno::Reference<report::XReportDefinition> xReportDefinition = m_pParent->getController().getReportDefinition(); 105 m_pReportDefintionMultiPlexer = addStyleListener(xReportDefinition,this); 106 107 m_aReportWindow.initialize(); 108 } 109 //------------------------------------------------------------------------------ 110 void OScrollWindowHelper::setTotalSize(sal_Int32 _nWidth ,sal_Int32 _nHeight) 111 { 112 m_aTotalPixelSize.Width() = _nWidth; 113 m_aTotalPixelSize.Height() = _nHeight; 114 115 // now set the ranges without start marker 116 Fraction aStartWidth(REPORT_STARTMARKER_WIDTH * m_pParent->getController().getZoomValue(),100); 117 long nWidth = long(_nWidth - (double)aStartWidth); 118 m_aHScroll.SetRangeMax( nWidth ); 119 m_aVScroll.SetRangeMax( m_aTotalPixelSize.Height() ); 120 121 Resize(); 122 } 123 //------------------------------------------------------------------------------ 124 Size OScrollWindowHelper::ResizeScrollBars() 125 { 126 // get the new output-size in pixel 127 Size aOutPixSz = GetOutputSizePixel(); 128 if ( aOutPixSz.Width() == 0 || aOutPixSz.Height() == 0 ) 129 return aOutPixSz; 130 131 aOutPixSz.Height() -= m_aReportWindow.getRulerHeight(); 132 // determine the size of the output-area and if we need scrollbars 133 const long nScrSize = GetSettings().GetStyleSettings().GetScrollBarSize(); 134 bool bVVisible = false; // by default no vertical-ScrollBar 135 bool bHVisible = false; // by default no horizontal-ScrollBar 136 bool bChanged; // determines if a visiblility was changed 137 do 138 { 139 bChanged = false; 140 141 // does we need a vertical ScrollBar 142 if ( aOutPixSz.Width() < m_aTotalPixelSize.Width() && !bHVisible ) 143 { 144 bHVisible = true; 145 aOutPixSz.Height() -= nScrSize; 146 bChanged = true; 147 } 148 149 // does we need a horizontal ScrollBar 150 if ( aOutPixSz.Height() < m_aTotalPixelSize.Height() && !bVVisible ) 151 { 152 bVVisible = true; 153 aOutPixSz.Width() -= nScrSize; 154 bChanged = true; 155 } 156 157 } 158 while ( bChanged ); // until no visibility has changed 159 160 aOutPixSz.Height() += m_aReportWindow.getRulerHeight(); 161 162 // show or hide scrollbars 163 m_aVScroll.Show( bVVisible ); 164 m_aHScroll.Show( bHVisible ); 165 166 // disable painting in the corner between the scrollbars 167 if ( bVVisible && bHVisible ) 168 { 169 m_aCornerWin.SetPosSizePixel(Point(aOutPixSz.Width(), aOutPixSz.Height()), Size(nScrSize, nScrSize) ); 170 m_aCornerWin.Show(); 171 } 172 else 173 m_aCornerWin.Hide(); 174 175 const Point aOffset = LogicToPixel( Point( SECTION_OFFSET, SECTION_OFFSET ), MAP_APPFONT ); 176 // resize scrollbars and set their ranges 177 { 178 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH*m_pParent->getController().getZoomValue()),100); 179 const sal_Int32 nNewWidth = aOutPixSz.Width() - aOffset.X() - (long)aStartWidth; 180 lcl_setScrollBar(nNewWidth,Point( (long)aStartWidth + aOffset.X(), aOutPixSz.Height() ),Size( nNewWidth, nScrSize ),m_aHScroll); 181 } 182 { 183 const sal_Int32 nNewHeight = aOutPixSz.Height() - m_aReportWindow.getRulerHeight(); 184 lcl_setScrollBar(nNewHeight,Point( aOutPixSz.Width(), m_aReportWindow.getRulerHeight() ),Size( nScrSize,nNewHeight),m_aVScroll); 185 } 186 187 return aOutPixSz; 188 } 189 //------------------------------------------------------------------------------ 190 void OScrollWindowHelper::Resize() 191 { 192 OScrollWindowHelper_BASE::Resize(); 193 const Size aTotalOutputSize = ResizeScrollBars(); 194 195 m_aReportWindow.SetPosSizePixel(Point( 0, 0 ),aTotalOutputSize); 196 } 197 //------------------------------------------------------------------------------ 198 IMPL_LINK( OScrollWindowHelper, ScrollHdl, ScrollBar*, /*pScroll*/ ) 199 { 200 m_aReportWindow.ScrollChildren( getThumbPos() ); 201 return 0; 202 } 203 //------------------------------------------------------------------------------ 204 void OScrollWindowHelper::addSection(const uno::Reference< report::XSection >& _xSection 205 ,const ::rtl::OUString& _sColorEntry 206 ,sal_uInt16 _nPosition) 207 { 208 m_aReportWindow.addSection(_xSection,_sColorEntry,_nPosition); 209 } 210 //------------------------------------------------------------------------------ 211 void OScrollWindowHelper::removeSection(sal_uInt16 _nPosition) 212 { 213 m_aReportWindow.removeSection(_nPosition); 214 } 215 //------------------------------------------------------------------------------ 216 void OScrollWindowHelper::toggleGrid(sal_Bool _bVisible) 217 { 218 m_aReportWindow.toggleGrid(_bVisible); 219 } 220 //------------------------------------------------------------------------------ 221 sal_uInt16 OScrollWindowHelper::getSectionCount() const 222 { 223 return m_aReportWindow.getSectionCount(); 224 } 225 //------------------------------------------------------------------------------ 226 void OScrollWindowHelper::SetInsertObj( sal_uInt16 eObj,const ::rtl::OUString& _sShapeType ) 227 { 228 m_aReportWindow.SetInsertObj(eObj,_sShapeType); 229 } 230 //---------------------------------------------------------------------------- 231 rtl::OUString OScrollWindowHelper::GetInsertObjString() const 232 { 233 return m_aReportWindow.GetInsertObjString(); 234 } 235 //------------------------------------------------------------------------------ 236 void OScrollWindowHelper::SetMode( DlgEdMode _eNewMode ) 237 { 238 m_aReportWindow.SetMode(_eNewMode); 239 } 240 //------------------------------------------------------------------------------ 241 sal_Bool OScrollWindowHelper::HasSelection() const 242 { 243 return m_aReportWindow.HasSelection(); 244 } 245 //---------------------------------------------------------------------------- 246 void OScrollWindowHelper::Delete() 247 { 248 m_aReportWindow.Delete(); 249 } 250 //---------------------------------------------------------------------------- 251 void OScrollWindowHelper::Copy() 252 { 253 m_aReportWindow.Copy(); 254 } 255 //---------------------------------------------------------------------------- 256 void OScrollWindowHelper::Paste() 257 { 258 m_aReportWindow.Paste(); 259 } 260 //---------------------------------------------------------------------------- 261 sal_Bool OScrollWindowHelper::IsPasteAllowed() const 262 { 263 return m_aReportWindow.IsPasteAllowed(); 264 } 265 //----------------------------------------------------------------------------- 266 void OScrollWindowHelper::SelectAll(const sal_uInt16 _nObjectType) 267 { 268 m_aReportWindow.SelectAll(_nObjectType); 269 } 270 //---------------------------------------------------------------------------- 271 void OScrollWindowHelper::unmarkAllObjects(OSectionView* _pSectionView) 272 { 273 m_aReportWindow.unmarkAllObjects(_pSectionView); 274 } 275 //------------------------------------------------------------------------------ 276 sal_Int32 OScrollWindowHelper::getMaxMarkerWidth(sal_Bool _bWithEnd) const 277 { 278 return m_aReportWindow.getMaxMarkerWidth(_bWithEnd); 279 } 280 //---------------------------------------------------------------------------- 281 void OScrollWindowHelper::showRuler(sal_Bool _bShow) 282 { 283 m_aReportWindow.showRuler(_bShow); 284 } 285 //------------------------------------------------------------------------------ 286 sal_Bool OScrollWindowHelper::handleKeyEvent(const KeyEvent& _rEvent) 287 { 288 return m_aReportWindow.handleKeyEvent(_rEvent); 289 } 290 //------------------------------------------------------------------------ 291 void OScrollWindowHelper::setMarked(OSectionView* _pSectionView,sal_Bool _bMark) 292 { 293 m_aReportWindow.setMarked(_pSectionView,_bMark); 294 } 295 //------------------------------------------------------------------------ 296 void OScrollWindowHelper::setMarked(const uno::Reference< report::XSection>& _xSection,sal_Bool _bMark) 297 { 298 m_aReportWindow.setMarked(_xSection,_bMark); 299 } 300 //------------------------------------------------------------------------ 301 void OScrollWindowHelper::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape,sal_Bool _bMark) 302 { 303 m_aReportWindow.setMarked(_xShape,_bMark); 304 } 305 // ------------------------------------------------------------------------- 306 ::boost::shared_ptr<OSectionWindow> OScrollWindowHelper::getMarkedSection(NearSectionAccess nsa) const 307 { 308 return m_aReportWindow.getMarkedSection(nsa); 309 } 310 // ------------------------------------------------------------------------- 311 ::boost::shared_ptr<OSectionWindow> OScrollWindowHelper::getSectionWindow(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection) const 312 { 313 return m_aReportWindow.getSectionWindow(_xSection); 314 } 315 // ------------------------------------------------------------------------- 316 void OScrollWindowHelper::markSection(const sal_uInt16 _nPos) 317 { 318 m_aReportWindow.markSection(_nPos); 319 } 320 // ----------------------------------------------------------------------------- 321 void OScrollWindowHelper::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const 322 { 323 m_aReportWindow.fillCollapsedSections(_rCollapsedPositions); 324 } 325 // ----------------------------------------------------------------------------- 326 void OScrollWindowHelper::collapseSections(const uno::Sequence< ::com::sun::star::beans::PropertyValue>& _aCollpasedSections) 327 { 328 m_aReportWindow.collapseSections(_aCollpasedSections); 329 } 330 //------------------------------------------------------------------------------ 331 long OScrollWindowHelper::Notify( NotifyEvent& rNEvt ) 332 { 333 const CommandEvent* pCommandEvent = rNEvt.GetCommandEvent(); 334 if ( pCommandEvent && 335 ( ((pCommandEvent->GetCommand() == COMMAND_WHEEL) || 336 (pCommandEvent->GetCommand() == COMMAND_STARTAUTOSCROLL) || 337 (pCommandEvent->GetCommand() == COMMAND_AUTOSCROLL))) ) 338 { 339 ScrollBar* pHScrBar = NULL; 340 ScrollBar* pVScrBar = NULL; 341 if ( m_aHScroll.IsVisible() ) 342 pHScrBar = &m_aHScroll; 343 344 if ( m_aVScroll.IsVisible() ) 345 pVScrBar = &m_aVScroll; 346 347 if ( HandleScrollCommand( *pCommandEvent, pHScrBar, pVScrBar ) ) 348 return 1L; 349 } 350 return OScrollWindowHelper_BASE::Notify(rNEvt); 351 } 352 // ----------------------------------------------------------------------------- 353 void OScrollWindowHelper::alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool bBoundRects) 354 { 355 m_aReportWindow.alignMarkedObjects(_nControlModification, _bAlignAtSection, bBoundRects); 356 } 357 //------------------------------------------------------------------------------ 358 void OScrollWindowHelper::ImplInitSettings() 359 { 360 SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() )); 361 // SetBackground( Wallpaper( COL_LIGHTRED )); 362 SetFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() ); 363 SetTextFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() ); 364 } 365 //----------------------------------------------------------------------------- 366 void OScrollWindowHelper::DataChanged( const DataChangedEvent& rDCEvt ) 367 { 368 Window::DataChanged( rDCEvt ); 369 370 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && 371 (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 372 { 373 ImplInitSettings(); 374 Invalidate(); 375 } 376 } 377 // ----------------------------------------------------------------------------- 378 void OScrollWindowHelper::_propertyChanged(const beans::PropertyChangeEvent& /*_rEvent*/) throw( uno::RuntimeException) 379 { 380 m_aReportWindow.notifySizeChanged(); 381 } 382 // ----------------------------------------------------------------------------- 383 void OScrollWindowHelper::setGridSnap(sal_Bool bOn) 384 { 385 m_aReportWindow.setGridSnap(bOn); 386 } 387 // ----------------------------------------------------------------------------- 388 void OScrollWindowHelper::setDragStripes(sal_Bool bOn) 389 { 390 m_aReportWindow.setDragStripes(bOn); 391 } 392 // ----------------------------------------------------------------------------- 393 sal_uInt32 OScrollWindowHelper::getMarkedObjectCount() const 394 { 395 return m_aReportWindow.getMarkedObjectCount(); 396 } 397 // ----------------------------------------------------------------------------- 398 void OScrollWindowHelper::zoom(const Fraction& _aZoom) 399 { 400 m_aReportWindow.zoom(_aZoom); 401 Resize(); 402 Invalidate(INVALIDATE_NOCHILDREN|INVALIDATE_TRANSPARENT); 403 } 404 // ----------------------------------------------------------------------------- 405 void OScrollWindowHelper::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const 406 { 407 m_aReportWindow.fillControlModelSelection(_rSelection); 408 } 409 // ----------------------------------------------------------------------------- 410 sal_uInt16 OScrollWindowHelper::getZoomFactor(SvxZoomType _eType) const 411 { 412 return m_aReportWindow.getZoomFactor(_eType); 413 } 414 //============================================================================== 415 } // rptui 416 //============================================================================== 417