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