bump product version to 6.3.0.0.beta1
[LibreOffice.git] / reportdesign / source / ui / report / ScrollHelper.cxx
blob2b076349346a2935274db6a85abfc23d3a9fab54
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 <com/sun/star/accessibility/AccessibleRole.hpp>
25 #include <toolkit/helper/convert.hxx>
27 #include <vcl/commandevent.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 static 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))
55 SetMapMode( MapMode( MapUnit::Map100thMM ) );
57 impl_initScrollBar( *m_aHScroll.get() );
58 impl_initScrollBar( *m_aVScroll.get() );
60 m_aReportWindow->SetMapMode( MapMode( MapUnit::Map100thMM ) );
61 m_aReportWindow->Show();
63 // normally we should be SCROLL_PANE
64 SetAccessibleRole(css::accessibility::AccessibleRole::SCROLL_PANE);
65 ImplInitSettings();
69 OScrollWindowHelper::~OScrollWindowHelper()
71 disposeOnce();
74 void OScrollWindowHelper::dispose()
76 if ( m_pReportDefinitionMultiPlexer.is() )
77 m_pReportDefinitionMultiPlexer->dispose();
79 m_aHScroll.disposeAndClear();
80 m_aVScroll.disposeAndClear();
81 m_aCornerWin.disposeAndClear();
82 m_aReportWindow.disposeAndClear();
83 m_pParent.clear();
84 OScrollWindowHelper_BASE::dispose();
88 void OScrollWindowHelper::impl_initScrollBar( ScrollBar& _rScrollBar ) const
90 AllSettings aSettings( _rScrollBar.GetSettings() );
91 StyleSettings aStyle( aSettings.GetStyleSettings() );
92 aStyle.SetDragFullOptions( aStyle.GetDragFullOptions() | DragFullOptions::Scroll ); // live scrolling
93 aSettings.SetStyleSettings( aStyle );
94 _rScrollBar.SetSettings( aSettings );
96 _rScrollBar.SetScrollHdl( LINK( const_cast<OScrollWindowHelper*>(this), OScrollWindowHelper, ScrollHdl ) );
97 _rScrollBar.SetLineSize( SCR_LINE_SIZE );
101 void OScrollWindowHelper::initialize()
103 uno::Reference<report::XReportDefinition> xReportDefinition = m_pParent->getController().getReportDefinition();
104 m_pReportDefinitionMultiPlexer = addStyleListener(xReportDefinition,this);
107 void OScrollWindowHelper::setTotalSize(sal_Int32 _nWidth ,sal_Int32 _nHeight)
109 m_aTotalPixelSize.setWidth( _nWidth );
110 m_aTotalPixelSize.setHeight( _nHeight );
112 // now set the ranges without start marker
113 Fraction aStartWidth(REPORT_STARTMARKER_WIDTH * m_pParent->getController().getZoomValue(),100);
114 long nWidth = long(_nWidth - static_cast<double>(aStartWidth));
115 m_aHScroll->SetRangeMax( nWidth );
116 m_aVScroll->SetRangeMax( m_aTotalPixelSize.Height() );
118 Resize();
121 Size OScrollWindowHelper::ResizeScrollBars()
123 // get the new output-size in pixel
124 Size aOutPixSz = GetOutputSizePixel();
125 if ( aOutPixSz.Width() == 0 || aOutPixSz.Height() == 0 )
126 return aOutPixSz;
128 aOutPixSz.AdjustHeight( -(m_aReportWindow->getRulerHeight()) );
129 // determine the size of the output-area and if we need scrollbars
130 const long nScrSize = GetSettings().GetStyleSettings().GetScrollBarSize();
131 bool bVVisible = false; // by default no vertical-ScrollBar
132 bool bHVisible = false; // by default no horizontal-ScrollBar
133 bool bChanged; // determines if a visiblility was changed
136 bChanged = false;
138 // does we need a vertical ScrollBar
139 if ( aOutPixSz.Width() < m_aTotalPixelSize.Width() && !bHVisible )
141 bHVisible = true;
142 aOutPixSz.AdjustHeight( -nScrSize );
143 bChanged = true;
146 // does we need a horizontal ScrollBar
147 if ( aOutPixSz.Height() < m_aTotalPixelSize.Height() && !bVVisible )
149 bVVisible = true;
150 aOutPixSz.AdjustWidth( -nScrSize );
151 bChanged = true;
155 while ( bChanged ); // until no visibility has changed
157 aOutPixSz.AdjustHeight(m_aReportWindow->getRulerHeight() );
159 // show or hide scrollbars
160 m_aVScroll->Show( bVVisible );
161 m_aHScroll->Show( bHVisible );
163 // disable painting in the corner between the scrollbars
164 if ( bVVisible && bHVisible )
166 m_aCornerWin->SetPosSizePixel(Point(aOutPixSz.Width(), aOutPixSz.Height()), Size(nScrSize, nScrSize) );
167 m_aCornerWin->Show();
169 else
170 m_aCornerWin->Hide();
172 const Point aOffset = LogicToPixel(Point(SECTION_OFFSET, SECTION_OFFSET), MapMode(MapUnit::MapAppFont));
173 // resize scrollbars and set their ranges
175 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH*m_pParent->getController().getZoomValue()),100);
176 const sal_Int32 nNewWidth = aOutPixSz.Width() - aOffset.X() - static_cast<long>(aStartWidth);
177 lcl_setScrollBar(nNewWidth,Point( static_cast<long>(aStartWidth) + aOffset.X(), aOutPixSz.Height() ), Size( nNewWidth, nScrSize ), *m_aHScroll.get());
180 const sal_Int32 nNewHeight = aOutPixSz.Height() - m_aReportWindow->getRulerHeight();
181 lcl_setScrollBar(nNewHeight,Point( aOutPixSz.Width(), m_aReportWindow->getRulerHeight() ), Size( nScrSize,nNewHeight), *m_aVScroll.get());
184 return aOutPixSz;
187 void OScrollWindowHelper::Resize()
189 OScrollWindowHelper_BASE::Resize();
190 const Size aTotalOutputSize = ResizeScrollBars();
192 m_aReportWindow->SetPosSizePixel(Point( 0, 0 ),aTotalOutputSize);
195 IMPL_LINK( OScrollWindowHelper, ScrollHdl, ScrollBar*, /*pScroll*/, void )
197 m_aReportWindow->ScrollChildren( getThumbPos() );
200 void OScrollWindowHelper::addSection(const uno::Reference< report::XSection >& _xSection
201 ,const OUString& _sColorEntry
202 ,sal_uInt16 _nPosition)
204 m_aReportWindow->addSection(_xSection,_sColorEntry,_nPosition);
207 void OScrollWindowHelper::removeSection(sal_uInt16 _nPosition)
209 m_aReportWindow->removeSection(_nPosition);
212 void OScrollWindowHelper::toggleGrid(bool _bVisible)
214 m_aReportWindow->toggleGrid(_bVisible);
217 sal_uInt16 OScrollWindowHelper::getSectionCount() const
219 return m_aReportWindow->getSectionCount();
222 void OScrollWindowHelper::SetInsertObj( sal_uInt16 eObj,const OUString& _sShapeType )
224 m_aReportWindow->SetInsertObj(eObj,_sShapeType);
227 OUString const & OScrollWindowHelper::GetInsertObjString() const
229 return m_aReportWindow->GetInsertObjString();
232 void OScrollWindowHelper::SetMode( DlgEdMode _eNewMode )
234 m_aReportWindow->SetMode(_eNewMode);
237 bool OScrollWindowHelper::HasSelection() const
239 return m_aReportWindow->HasSelection();
242 void OScrollWindowHelper::Delete()
244 m_aReportWindow->Delete();
247 void OScrollWindowHelper::Copy()
249 m_aReportWindow->Copy();
252 void OScrollWindowHelper::Paste()
254 m_aReportWindow->Paste();
257 bool OScrollWindowHelper::IsPasteAllowed() const
259 return m_aReportWindow->IsPasteAllowed();
262 void OScrollWindowHelper::SelectAll(const sal_uInt16 _nObjectType)
264 m_aReportWindow->SelectAll(_nObjectType);
267 void OScrollWindowHelper::unmarkAllObjects()
269 m_aReportWindow->unmarkAllObjects();
272 sal_Int32 OScrollWindowHelper::getMaxMarkerWidth() const
274 return m_aReportWindow->getMaxMarkerWidth();
277 void OScrollWindowHelper::showRuler(bool _bShow)
279 m_aReportWindow->showRuler(_bShow);
282 bool OScrollWindowHelper::handleKeyEvent(const KeyEvent& _rEvent)
284 return m_aReportWindow->handleKeyEvent(_rEvent);
287 void OScrollWindowHelper::setMarked(OSectionView const * _pSectionView, bool _bMark)
289 m_aReportWindow->setMarked(_pSectionView,_bMark);
292 void OScrollWindowHelper::setMarked(const uno::Reference< report::XSection>& _xSection, bool _bMark)
294 m_aReportWindow->setMarked(_xSection,_bMark);
297 void OScrollWindowHelper::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape, bool _bMark)
299 m_aReportWindow->setMarked(_xShape,_bMark);
302 OSectionWindow* OScrollWindowHelper::getMarkedSection(NearSectionAccess nsa) const
304 return m_aReportWindow->getMarkedSection(nsa);
307 OSectionWindow* OScrollWindowHelper::getSectionWindow(const css::uno::Reference< css::report::XSection>& _xSection) const
309 return m_aReportWindow->getSectionWindow(_xSection);
312 void OScrollWindowHelper::markSection(const sal_uInt16 _nPos)
314 m_aReportWindow->markSection(_nPos);
317 void OScrollWindowHelper::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
319 m_aReportWindow->fillCollapsedSections(_rCollapsedPositions);
322 void OScrollWindowHelper::collapseSections(const uno::Sequence< css::beans::PropertyValue>& _aCollpasedSections)
324 m_aReportWindow->collapseSections(_aCollpasedSections);
327 bool OScrollWindowHelper::EventNotify( NotifyEvent& rNEvt )
329 const CommandEvent* pCommandEvent = rNEvt.GetCommandEvent();
330 if ( pCommandEvent &&
331 ((pCommandEvent->GetCommand() == CommandEventId::Wheel) ||
332 (pCommandEvent->GetCommand() == CommandEventId::StartAutoScroll) ||
333 (pCommandEvent->GetCommand() == CommandEventId::AutoScroll)) )
335 ScrollBar* pHScrBar = nullptr;
336 ScrollBar* pVScrBar = nullptr;
337 if ( m_aHScroll->IsVisible() )
338 pHScrBar = m_aHScroll.get();
340 if ( m_aVScroll->IsVisible() )
341 pVScrBar = m_aVScroll.get();
343 if ( HandleScrollCommand( *pCommandEvent, pHScrBar, pVScrBar ) )
344 return true;
346 return OScrollWindowHelper_BASE::EventNotify(rNEvt);
349 void OScrollWindowHelper::alignMarkedObjects(ControlModification _nControlModification, bool _bAlignAtSection)
351 m_aReportWindow->alignMarkedObjects(_nControlModification, _bAlignAtSection);
354 void OScrollWindowHelper::ImplInitSettings()
356 SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
357 SetFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
358 SetTextFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
361 void OScrollWindowHelper::DataChanged( const DataChangedEvent& rDCEvt )
363 Window::DataChanged( rDCEvt );
365 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
366 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
368 ImplInitSettings();
369 Invalidate();
373 void OScrollWindowHelper::_propertyChanged(const beans::PropertyChangeEvent& /*_rEvent*/)
375 m_aReportWindow->notifySizeChanged();
378 void OScrollWindowHelper::setGridSnap(bool bOn)
380 m_aReportWindow->setGridSnap(bOn);
383 void OScrollWindowHelper::setDragStripes(bool bOn)
385 m_aReportWindow->setDragStripes(bOn);
388 sal_uInt32 OScrollWindowHelper::getMarkedObjectCount() const
390 return m_aReportWindow->getMarkedObjectCount();
393 void OScrollWindowHelper::zoom(const Fraction& _aZoom)
395 m_aReportWindow->zoom(_aZoom);
396 Resize();
397 Invalidate(InvalidateFlags::NoChildren|InvalidateFlags::Transparent);
400 void OScrollWindowHelper::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
402 m_aReportWindow->fillControlModelSelection(_rSelection);
405 sal_uInt16 OScrollWindowHelper::getZoomFactor(SvxZoomType _eType) const
407 return m_aReportWindow->getZoomFactor(_eType);
410 } // rptui
413 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */