bump product version to 5.0.4.1
[LibreOffice.git] / reportdesign / source / ui / report / ScrollHelper.cxx
blob02cbca064b5c0297b36132b9489a50f957684476
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "ScrollHelper.hxx"
20 #include "DesignView.hxx"
21 #include "ReportController.hxx"
22 #include "ReportWindow.hxx"
23 #include "UITools.hxx"
24 #include <tools/debug.hxx>
25 #include <com/sun/star/accessibility/AccessibleRole.hpp>
26 #include <toolkit/helper/convert.hxx>
28 #include <vcl/settings.hxx>
29 #include <vcl/svapp.hxx>
31 namespace rptui
33 #define SECTION_OFFSET 3
34 #define SCR_LINE_SIZE 10
35 using namespace ::com::sun::star;
38 void lcl_setScrollBar(sal_Int32 _nNewValue,const Point& _aPos,const Size& _aSize,ScrollBar& _rScrollBar)
40 _rScrollBar.SetPosSizePixel(_aPos,_aSize);
41 _rScrollBar.SetPageSize( _nNewValue );
42 _rScrollBar.SetVisibleSize( _nNewValue );
46 OScrollWindowHelper::OScrollWindowHelper( ODesignView* _pDesignView)
47 : OScrollWindowHelper_BASE( _pDesignView,WB_DIALOGCONTROL)
48 ,OPropertyChangeListener(m_aMutex)
49 ,m_aHScroll( VclPtr<ScrollBar>::Create(this, WB_HSCROLL|WB_REPEAT|WB_DRAG) )
50 ,m_aVScroll( VclPtr<ScrollBar>::Create(this, WB_VSCROLL|WB_REPEAT|WB_DRAG) )
51 ,m_aCornerWin( VclPtr<ScrollBarBox>::Create(this) )
52 ,m_pParent(_pDesignView)
53 ,m_aReportWindow(VclPtr<rptui::OReportWindow>::Create(this,m_pParent))
54 ,m_pReportDefintionMultiPlexer(NULL)
56 SetMapMode( MapMode( MAP_100TH_MM ) );
58 impl_initScrollBar( *m_aHScroll.get() );
59 impl_initScrollBar( *m_aVScroll.get() );
61 m_aReportWindow->SetMapMode( MapMode( MAP_100TH_MM ) );
62 m_aReportWindow->Show();
64 // normally we should be SCROLL_PANE
65 SetAccessibleRole(css::accessibility::AccessibleRole::SCROLL_PANE);
66 ImplInitSettings();
70 OScrollWindowHelper::~OScrollWindowHelper()
72 disposeOnce();
75 void OScrollWindowHelper::dispose()
77 if ( m_pReportDefintionMultiPlexer.is() )
78 m_pReportDefintionMultiPlexer->dispose();
80 m_aHScroll.disposeAndClear();
81 m_aVScroll.disposeAndClear();
82 m_aCornerWin.disposeAndClear();
83 m_aReportWindow.disposeAndClear();
84 m_pParent.clear();
85 OScrollWindowHelper_BASE::dispose();
89 void OScrollWindowHelper::impl_initScrollBar( ScrollBar& _rScrollBar ) const
91 AllSettings aSettings( _rScrollBar.GetSettings() );
92 StyleSettings aStyle( aSettings.GetStyleSettings() );
93 aStyle.SetDragFullOptions( aStyle.GetDragFullOptions() | DragFullOptions::Scroll ); // live scrolling
94 aSettings.SetStyleSettings( aStyle );
95 _rScrollBar.SetSettings( aSettings );
97 _rScrollBar.SetScrollHdl( LINK( const_cast<OScrollWindowHelper*>(this), OScrollWindowHelper, ScrollHdl ) );
98 _rScrollBar.SetLineSize( SCR_LINE_SIZE );
102 void OScrollWindowHelper::initialize()
104 uno::Reference<report::XReportDefinition> xReportDefinition = m_pParent->getController().getReportDefinition();
105 m_pReportDefintionMultiPlexer = addStyleListener(xReportDefinition,this);
108 void OScrollWindowHelper::setTotalSize(sal_Int32 _nWidth ,sal_Int32 _nHeight)
110 m_aTotalPixelSize.Width() = _nWidth;
111 m_aTotalPixelSize.Height() = _nHeight;
113 // now set the ranges without start marker
114 Fraction aStartWidth(REPORT_STARTMARKER_WIDTH * m_pParent->getController().getZoomValue(),100);
115 long nWidth = long(_nWidth - (double)aStartWidth);
116 m_aHScroll->SetRangeMax( nWidth );
117 m_aVScroll->SetRangeMax( m_aTotalPixelSize.Height() );
119 Resize();
122 Size OScrollWindowHelper::ResizeScrollBars()
124 // get the new output-size in pixel
125 Size aOutPixSz = GetOutputSizePixel();
126 if ( aOutPixSz.Width() == 0 || aOutPixSz.Height() == 0 )
127 return aOutPixSz;
129 aOutPixSz.Height() -= m_aReportWindow->getRulerHeight();
130 // determine the size of the output-area and if we need scrollbars
131 const long nScrSize = GetSettings().GetStyleSettings().GetScrollBarSize();
132 bool bVVisible = false; // by default no vertical-ScrollBar
133 bool bHVisible = false; // by default no horizontal-ScrollBar
134 bool bChanged; // determines if a visiblility was changed
137 bChanged = false;
139 // does we need a vertical ScrollBar
140 if ( aOutPixSz.Width() < m_aTotalPixelSize.Width() && !bHVisible )
142 bHVisible = true;
143 aOutPixSz.Height() -= nScrSize;
144 bChanged = true;
147 // does we need a horizontal ScrollBar
148 if ( aOutPixSz.Height() < m_aTotalPixelSize.Height() && !bVVisible )
150 bVVisible = true;
151 aOutPixSz.Width() -= nScrSize;
152 bChanged = true;
156 while ( bChanged ); // until no visibility has changed
158 aOutPixSz.Height() += m_aReportWindow->getRulerHeight();
160 // show or hide scrollbars
161 m_aVScroll->Show( bVVisible );
162 m_aHScroll->Show( bHVisible );
164 // disable painting in the corner between the scrollbars
165 if ( bVVisible && bHVisible )
167 m_aCornerWin->SetPosSizePixel(Point(aOutPixSz.Width(), aOutPixSz.Height()), Size(nScrSize, nScrSize) );
168 m_aCornerWin->Show();
170 else
171 m_aCornerWin->Hide();
173 const Point aOffset = LogicToPixel( Point( SECTION_OFFSET, SECTION_OFFSET ), MAP_APPFONT );
174 // resize scrollbars and set their ranges
176 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH*m_pParent->getController().getZoomValue()),100);
177 const sal_Int32 nNewWidth = aOutPixSz.Width() - aOffset.X() - (long)aStartWidth;
178 lcl_setScrollBar(nNewWidth,Point( (long)aStartWidth + aOffset.X(), aOutPixSz.Height() ), Size( nNewWidth, nScrSize ), *m_aHScroll.get());
181 const sal_Int32 nNewHeight = aOutPixSz.Height() - m_aReportWindow->getRulerHeight();
182 lcl_setScrollBar(nNewHeight,Point( aOutPixSz.Width(), m_aReportWindow->getRulerHeight() ), Size( nScrSize,nNewHeight), *m_aVScroll.get());
185 return aOutPixSz;
188 void OScrollWindowHelper::Resize()
190 OScrollWindowHelper_BASE::Resize();
191 const Size aTotalOutputSize = ResizeScrollBars();
193 m_aReportWindow->SetPosSizePixel(Point( 0, 0 ),aTotalOutputSize);
196 IMPL_LINK( OScrollWindowHelper, ScrollHdl, ScrollBar*, /*pScroll*/ )
198 m_aReportWindow->ScrollChildren( getThumbPos() );
199 return 0;
202 void OScrollWindowHelper::addSection(const uno::Reference< report::XSection >& _xSection
203 ,const OUString& _sColorEntry
204 ,sal_uInt16 _nPosition)
206 m_aReportWindow->addSection(_xSection,_sColorEntry,_nPosition);
209 void OScrollWindowHelper::removeSection(sal_uInt16 _nPosition)
211 m_aReportWindow->removeSection(_nPosition);
214 void OScrollWindowHelper::toggleGrid(bool _bVisible)
216 m_aReportWindow->toggleGrid(_bVisible);
219 sal_uInt16 OScrollWindowHelper::getSectionCount() const
221 return m_aReportWindow->getSectionCount();
224 void OScrollWindowHelper::SetInsertObj( sal_uInt16 eObj,const OUString& _sShapeType )
226 m_aReportWindow->SetInsertObj(eObj,_sShapeType);
229 OUString OScrollWindowHelper::GetInsertObjString() const
231 return m_aReportWindow->GetInsertObjString();
234 void OScrollWindowHelper::SetMode( DlgEdMode _eNewMode )
236 m_aReportWindow->SetMode(_eNewMode);
239 bool OScrollWindowHelper::HasSelection() const
241 return m_aReportWindow->HasSelection();
244 void OScrollWindowHelper::Delete()
246 m_aReportWindow->Delete();
249 void OScrollWindowHelper::Copy()
251 m_aReportWindow->Copy();
254 void OScrollWindowHelper::Paste()
256 m_aReportWindow->Paste();
259 bool OScrollWindowHelper::IsPasteAllowed() const
261 return m_aReportWindow->IsPasteAllowed();
264 void OScrollWindowHelper::SelectAll(const sal_uInt16 _nObjectType)
266 m_aReportWindow->SelectAll(_nObjectType);
269 void OScrollWindowHelper::unmarkAllObjects(OSectionView* _pSectionView)
271 m_aReportWindow->unmarkAllObjects(_pSectionView);
274 sal_Int32 OScrollWindowHelper::getMaxMarkerWidth(bool _bWithEnd) const
276 return m_aReportWindow->getMaxMarkerWidth(_bWithEnd);
279 void OScrollWindowHelper::showRuler(bool _bShow)
281 m_aReportWindow->showRuler(_bShow);
284 bool OScrollWindowHelper::handleKeyEvent(const KeyEvent& _rEvent)
286 return m_aReportWindow->handleKeyEvent(_rEvent);
289 void OScrollWindowHelper::setMarked(OSectionView* _pSectionView, bool _bMark)
291 m_aReportWindow->setMarked(_pSectionView,_bMark);
294 void OScrollWindowHelper::setMarked(const uno::Reference< report::XSection>& _xSection, bool _bMark)
296 m_aReportWindow->setMarked(_xSection,_bMark);
299 void OScrollWindowHelper::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape, bool _bMark)
301 m_aReportWindow->setMarked(_xShape,_bMark);
304 OSectionWindow* OScrollWindowHelper::getMarkedSection(NearSectionAccess nsa) const
306 return m_aReportWindow->getMarkedSection(nsa);
309 OSectionWindow* OScrollWindowHelper::getSectionWindow(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection) const
311 return m_aReportWindow->getSectionWindow(_xSection);
314 void OScrollWindowHelper::markSection(const sal_uInt16 _nPos)
316 m_aReportWindow->markSection(_nPos);
319 void OScrollWindowHelper::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
321 m_aReportWindow->fillCollapsedSections(_rCollapsedPositions);
324 void OScrollWindowHelper::collapseSections(const uno::Sequence< ::com::sun::star::beans::PropertyValue>& _aCollpasedSections)
326 m_aReportWindow->collapseSections(_aCollpasedSections);
329 bool OScrollWindowHelper::Notify( NotifyEvent& rNEvt )
331 const CommandEvent* pCommandEvent = rNEvt.GetCommandEvent();
332 if ( pCommandEvent &&
333 ( ((pCommandEvent->GetCommand() == CommandEventId::Wheel) ||
334 (pCommandEvent->GetCommand() == CommandEventId::StartAutoScroll) ||
335 (pCommandEvent->GetCommand() == CommandEventId::AutoScroll))) )
337 ScrollBar* pHScrBar = NULL;
338 ScrollBar* pVScrBar = NULL;
339 if ( m_aHScroll->IsVisible() )
340 pHScrBar = m_aHScroll.get();
342 if ( m_aVScroll->IsVisible() )
343 pVScrBar = m_aVScroll.get();
345 if ( HandleScrollCommand( *pCommandEvent, pHScrBar, pVScrBar ) )
346 return true;
348 return OScrollWindowHelper_BASE::Notify(rNEvt);
351 void OScrollWindowHelper::alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool bBoundRects)
353 m_aReportWindow->alignMarkedObjects(_nControlModification, _bAlignAtSection, bBoundRects);
356 void OScrollWindowHelper::ImplInitSettings()
358 SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
359 SetFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
360 SetTextFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
363 void OScrollWindowHelper::DataChanged( const DataChangedEvent& rDCEvt )
365 Window::DataChanged( rDCEvt );
367 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
368 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
370 ImplInitSettings();
371 Invalidate();
375 void OScrollWindowHelper::_propertyChanged(const beans::PropertyChangeEvent& /*_rEvent*/)
376 throw (uno::RuntimeException, std::exception)
378 m_aReportWindow->notifySizeChanged();
381 void OScrollWindowHelper::setGridSnap(bool bOn)
383 m_aReportWindow->setGridSnap(bOn);
386 void OScrollWindowHelper::setDragStripes(bool bOn)
388 m_aReportWindow->setDragStripes(bOn);
391 sal_uInt32 OScrollWindowHelper::getMarkedObjectCount() const
393 return m_aReportWindow->getMarkedObjectCount();
396 void OScrollWindowHelper::zoom(const Fraction& _aZoom)
398 m_aReportWindow->zoom(_aZoom);
399 Resize();
400 Invalidate(INVALIDATE_NOCHILDREN|INVALIDATE_TRANSPARENT);
403 void OScrollWindowHelper::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
405 m_aReportWindow->fillControlModelSelection(_rSelection);
408 sal_uInt16 OScrollWindowHelper::getZoomFactor(SvxZoomType _eType) const
410 return m_aReportWindow->getZoomFactor(_eType);
413 } // rptui
416 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */