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