1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScrollHelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
31 #include "ScrollHelper.hxx"
32 #include "DesignView.hxx"
33 #include "ReportController.hxx"
34 #include "ReportWindow.hxx"
35 #include "UITools.hxx"
36 #include <tools/debug.hxx>
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
38 #include <toolkit/helper/convert.hxx>
39 #include <vcl/svapp.hxx>
44 #define SECTION_OFFSET 3
45 #define SCR_LINE_SIZE 10
46 using namespace ::com::sun::star
;
48 // -----------------------------------------------------------------------------
49 void lcl_setScrollBar(sal_Int32 _nNewValue
,const Point
& _aPos
,const Size
& _aSize
,ScrollBar
& _rScrollBar
)
51 _rScrollBar
.SetPosSizePixel(_aPos
,_aSize
);
52 _rScrollBar
.SetPageSize( _nNewValue
);
53 _rScrollBar
.SetVisibleSize( _nNewValue
);
56 // -----------------------------------------------------------------------------
57 DBG_NAME( rpt_OScrollWindowHelper
);
58 OScrollWindowHelper::OScrollWindowHelper( ODesignView
* _pDesignView
)
59 : OScrollWindowHelper_BASE( _pDesignView
,WB_DIALOGCONTROL
)
60 ,OPropertyChangeListener(m_aMutex
)
61 ,m_aHScroll( this, WB_HSCROLL
|WB_REPEAT
|WB_DRAG
)
62 ,m_aVScroll( this, WB_VSCROLL
|WB_REPEAT
|WB_DRAG
)
64 ,m_pParent(_pDesignView
)
65 ,m_aReportWindow(this,m_pParent
)
66 ,m_pReportDefintionMultiPlexer(NULL
)
68 DBG_CTOR( rpt_OScrollWindowHelper
,NULL
);
69 SetMapMode( MapMode( MAP_100TH_MM
) );
71 impl_initScrollBar( m_aHScroll
);
72 impl_initScrollBar( m_aVScroll
);
74 m_aReportWindow
.SetMapMode( MapMode( MAP_100TH_MM
) );
75 m_aReportWindow
.Show();
77 // normally we should be SCROLL_PANE
78 SetAccessibleRole(accessibility::AccessibleRole::SCROLL_PANE
);
82 // -----------------------------------------------------------------------------
83 OScrollWindowHelper::~OScrollWindowHelper()
85 DBG_DTOR( rpt_OScrollWindowHelper
,NULL
);
86 if ( m_pReportDefintionMultiPlexer
.is() )
87 m_pReportDefintionMultiPlexer
->dispose();
90 // -----------------------------------------------------------------------------
91 void OScrollWindowHelper::impl_initScrollBar( ScrollBar
& _rScrollBar
) const
93 AllSettings
aSettings( _rScrollBar
.GetSettings() );
94 StyleSettings
aStyle( aSettings
.GetStyleSettings() );
95 aStyle
.SetDragFullOptions( aStyle
.GetDragFullOptions() | DRAGFULL_OPTION_SCROLL
); // live scrolling
96 aSettings
.SetStyleSettings( aStyle
);
97 _rScrollBar
.SetSettings( aSettings
);
98 //_rScrollBar.SetMapMode( MapMode( MAP_100TH_MM ) );
100 _rScrollBar
.SetScrollHdl( LINK( this, OScrollWindowHelper
, ScrollHdl
) );
101 _rScrollBar
.SetLineSize( SCR_LINE_SIZE
);
104 // -----------------------------------------------------------------------------
105 void OScrollWindowHelper::initialize()
107 uno::Reference
<report::XReportDefinition
> xReportDefinition
= m_pParent
->getController().getReportDefinition();
108 m_pReportDefintionMultiPlexer
= addStyleListener(xReportDefinition
,this);
110 m_aReportWindow
.initialize();
112 //------------------------------------------------------------------------------
113 void OScrollWindowHelper::setTotalSize(sal_Int32 _nWidth
,sal_Int32 _nHeight
)
115 m_aTotalPixelSize
.Width() = _nWidth
;
116 m_aTotalPixelSize
.Height() = _nHeight
;
118 // now set the ranges without start marker
119 Fraction
aStartWidth(REPORT_STARTMARKER_WIDTH
* m_pParent
->getController().getZoomValue(),100);
120 long nWidth
= long(_nWidth
- (double)aStartWidth
);
121 m_aHScroll
.SetRangeMax( nWidth
);
122 m_aVScroll
.SetRangeMax( m_aTotalPixelSize
.Height() );
126 //------------------------------------------------------------------------------
127 Size
OScrollWindowHelper::ResizeScrollBars()
129 // get the new output-size in pixel
130 Size aOutPixSz
= GetOutputSizePixel();
131 if ( aOutPixSz
.Width() == 0 || aOutPixSz
.Height() == 0 )
134 aOutPixSz
.Height() -= m_aReportWindow
.getRulerHeight();
135 // determine the size of the output-area and if we need scrollbars
136 const long nScrSize
= GetSettings().GetStyleSettings().GetScrollBarSize();
137 bool bVVisible
= false; // by default no vertical-ScrollBar
138 bool bHVisible
= false; // by default no horizontal-ScrollBar
139 bool bChanged
; // determines if a visiblility was changed
144 // does we need a vertical ScrollBar
145 if ( aOutPixSz
.Width() < m_aTotalPixelSize
.Width() && !bHVisible
)
148 aOutPixSz
.Height() -= nScrSize
;
152 // does we need a horizontal ScrollBar
153 if ( aOutPixSz
.Height() < m_aTotalPixelSize
.Height() && !bVVisible
)
156 aOutPixSz
.Width() -= nScrSize
;
161 while ( bChanged
); // until no visibility has changed
163 aOutPixSz
.Height() += m_aReportWindow
.getRulerHeight();
165 // show or hide scrollbars
166 m_aVScroll
.Show( bVVisible
);
167 m_aHScroll
.Show( bHVisible
);
169 // disable painting in the corner between the scrollbars
170 if ( bVVisible
&& bHVisible
)
172 m_aCornerWin
.SetPosSizePixel(Point(aOutPixSz
.Width(), aOutPixSz
.Height()), Size(nScrSize
, nScrSize
) );
178 const Point aOffset
= LogicToPixel( Point( SECTION_OFFSET
, SECTION_OFFSET
), MAP_APPFONT
);
179 // resize scrollbars and set their ranges
181 Fraction
aStartWidth(long(REPORT_STARTMARKER_WIDTH
*m_pParent
->getController().getZoomValue()),100);
182 const sal_Int32 nNewWidth
= aOutPixSz
.Width() - aOffset
.X() - (long)aStartWidth
;
183 lcl_setScrollBar(nNewWidth
,Point( (long)aStartWidth
+ aOffset
.X(), aOutPixSz
.Height() ),Size( nNewWidth
, nScrSize
),m_aHScroll
);
186 const sal_Int32 nNewHeight
= aOutPixSz
.Height() - m_aReportWindow
.getRulerHeight();
187 lcl_setScrollBar(nNewHeight
,Point( aOutPixSz
.Width(), m_aReportWindow
.getRulerHeight() ),Size( nScrSize
,nNewHeight
),m_aVScroll
);
192 //------------------------------------------------------------------------------
193 void OScrollWindowHelper::Resize()
195 OScrollWindowHelper_BASE::Resize();
196 const Size aTotalOutputSize
= ResizeScrollBars();
198 m_aReportWindow
.SetPosSizePixel(Point( 0, 0 ),aTotalOutputSize
);
200 //------------------------------------------------------------------------------
201 IMPL_LINK( OScrollWindowHelper
, ScrollHdl
, ScrollBar
*, /*pScroll*/ )
203 m_aReportWindow
.ScrollChildren( getThumbPos() );
206 //------------------------------------------------------------------------------
207 void OScrollWindowHelper::addSection(const uno::Reference
< report::XSection
>& _xSection
208 ,const ::rtl::OUString
& _sColorEntry
211 m_aReportWindow
.addSection(_xSection
,_sColorEntry
,_nPosition
);
213 //------------------------------------------------------------------------------
214 void OScrollWindowHelper::removeSection(USHORT _nPosition
)
216 m_aReportWindow
.removeSection(_nPosition
);
218 //------------------------------------------------------------------------------
219 void OScrollWindowHelper::toggleGrid(sal_Bool _bVisible
)
221 m_aReportWindow
.toggleGrid(_bVisible
);
223 //------------------------------------------------------------------------------
224 USHORT
OScrollWindowHelper::getSectionCount() const
226 return m_aReportWindow
.getSectionCount();
228 //------------------------------------------------------------------------------
229 void OScrollWindowHelper::SetInsertObj( USHORT eObj
,const ::rtl::OUString
& _sShapeType
)
231 m_aReportWindow
.SetInsertObj(eObj
,_sShapeType
);
233 //----------------------------------------------------------------------------
234 rtl::OUString
OScrollWindowHelper::GetInsertObjString() const
236 return m_aReportWindow
.GetInsertObjString();
238 //------------------------------------------------------------------------------
239 void OScrollWindowHelper::SetMode( DlgEdMode _eNewMode
)
241 m_aReportWindow
.SetMode(_eNewMode
);
243 //------------------------------------------------------------------------------
244 BOOL
OScrollWindowHelper::HasSelection()
246 return m_aReportWindow
.HasSelection();
248 //----------------------------------------------------------------------------
249 void OScrollWindowHelper::Delete()
251 m_aReportWindow
.Delete();
253 //----------------------------------------------------------------------------
254 void OScrollWindowHelper::Copy()
256 m_aReportWindow
.Copy();
258 //----------------------------------------------------------------------------
259 void OScrollWindowHelper::Paste()
261 m_aReportWindow
.Paste();
263 //----------------------------------------------------------------------------
264 BOOL
OScrollWindowHelper::IsPasteAllowed()
266 return m_aReportWindow
.IsPasteAllowed();
268 //-----------------------------------------------------------------------------
269 void OScrollWindowHelper::SelectAll(const sal_uInt16 _nObjectType
)
271 m_aReportWindow
.SelectAll(_nObjectType
);
273 //----------------------------------------------------------------------------
274 void OScrollWindowHelper::unmarkAllObjects(OSectionView
* _pSectionView
)
276 m_aReportWindow
.unmarkAllObjects(_pSectionView
);
278 //------------------------------------------------------------------------------
279 sal_Int32
OScrollWindowHelper::getMaxMarkerWidth(sal_Bool _bWithEnd
) const
281 return m_aReportWindow
.getMaxMarkerWidth(_bWithEnd
);
283 //----------------------------------------------------------------------------
284 void OScrollWindowHelper::showRuler(sal_Bool _bShow
)
286 m_aReportWindow
.showRuler(_bShow
);
288 //------------------------------------------------------------------------------
289 sal_Bool
OScrollWindowHelper::handleKeyEvent(const KeyEvent
& _rEvent
)
291 return m_aReportWindow
.handleKeyEvent(_rEvent
);
293 //------------------------------------------------------------------------
294 void OScrollWindowHelper::setMarked(OSectionView
* _pSectionView
,sal_Bool _bMark
)
296 m_aReportWindow
.setMarked(_pSectionView
,_bMark
);
298 //------------------------------------------------------------------------
299 void OScrollWindowHelper::setMarked(const uno::Reference
< report::XSection
>& _xSection
,sal_Bool _bMark
)
301 m_aReportWindow
.setMarked(_xSection
,_bMark
);
303 //------------------------------------------------------------------------
304 void OScrollWindowHelper::setMarked(const uno::Sequence
< uno::Reference
< report::XReportComponent
> >& _xShape
,sal_Bool _bMark
)
306 m_aReportWindow
.setMarked(_xShape
,_bMark
);
308 // -------------------------------------------------------------------------
309 ::boost::shared_ptr
<OSectionWindow
> OScrollWindowHelper::getMarkedSection(NearSectionAccess nsa
) const
311 return m_aReportWindow
.getMarkedSection(nsa
);
313 // -------------------------------------------------------------------------
314 ::boost::shared_ptr
<OSectionWindow
> OScrollWindowHelper::getSectionWindow(const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XSection
>& _xSection
) const
316 return m_aReportWindow
.getSectionWindow(_xSection
);
318 // -------------------------------------------------------------------------
319 void OScrollWindowHelper::markSection(const sal_uInt16 _nPos
)
321 m_aReportWindow
.markSection(_nPos
);
323 // -----------------------------------------------------------------------------
324 void OScrollWindowHelper::fillCollapsedSections(::std::vector
<sal_uInt16
>& _rCollapsedPositions
) const
326 m_aReportWindow
.fillCollapsedSections(_rCollapsedPositions
);
328 // -----------------------------------------------------------------------------
329 void OScrollWindowHelper::collapseSections(const uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aCollpasedSections
)
331 m_aReportWindow
.collapseSections(_aCollpasedSections
);
333 //------------------------------------------------------------------------------
334 long OScrollWindowHelper::Notify( NotifyEvent
& rNEvt
)
336 const CommandEvent
* pCommandEvent
= rNEvt
.GetCommandEvent();
337 if ( pCommandEvent
&&
338 ( ((pCommandEvent
->GetCommand() == COMMAND_WHEEL
) ||
339 (pCommandEvent
->GetCommand() == COMMAND_STARTAUTOSCROLL
) ||
340 (pCommandEvent
->GetCommand() == COMMAND_AUTOSCROLL
))) )
342 ScrollBar
* pHScrBar
= NULL
;
343 ScrollBar
* pVScrBar
= NULL
;
344 if ( m_aHScroll
.IsVisible() )
345 pHScrBar
= &m_aHScroll
;
347 if ( m_aVScroll
.IsVisible() )
348 pVScrBar
= &m_aVScroll
;
350 if ( HandleScrollCommand( *pCommandEvent
, pHScrBar
, pVScrBar
) )
353 return OScrollWindowHelper_BASE::Notify(rNEvt
);
355 // -----------------------------------------------------------------------------
356 void OScrollWindowHelper::alignMarkedObjects(sal_Int32 _nControlModification
,bool _bAlignAtSection
, bool bBoundRects
)
358 m_aReportWindow
.alignMarkedObjects(_nControlModification
, _bAlignAtSection
, bBoundRects
);
360 //------------------------------------------------------------------------------
361 void OScrollWindowHelper::ImplInitSettings()
363 SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
364 // SetBackground( Wallpaper( COL_LIGHTRED ));
365 SetFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
366 SetTextFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
368 //-----------------------------------------------------------------------------
369 void OScrollWindowHelper::DataChanged( const DataChangedEvent
& rDCEvt
)
371 Window::DataChanged( rDCEvt
);
373 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
374 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
380 // -----------------------------------------------------------------------------
381 void OScrollWindowHelper::_propertyChanged(const beans::PropertyChangeEvent
& /*_rEvent*/) throw( uno::RuntimeException
)
383 m_aReportWindow
.notifySizeChanged();
385 // -----------------------------------------------------------------------------
386 void OScrollWindowHelper::setGridSnap(BOOL bOn
)
388 m_aReportWindow
.setGridSnap(bOn
);
390 // -----------------------------------------------------------------------------
391 void OScrollWindowHelper::setDragStripes(BOOL bOn
)
393 m_aReportWindow
.setDragStripes(bOn
);
395 // -----------------------------------------------------------------------------
396 BOOL
OScrollWindowHelper::isDragStripes() const
398 return m_aReportWindow
.isDragStripes();
400 // -----------------------------------------------------------------------------
401 sal_uInt32
OScrollWindowHelper::getMarkedObjectCount() const
403 return m_aReportWindow
.getMarkedObjectCount();
405 // -----------------------------------------------------------------------------
406 void OScrollWindowHelper::zoom(const Fraction
& _aZoom
)
408 m_aReportWindow
.zoom(_aZoom
);
410 Invalidate(INVALIDATE_NOCHILDREN
|INVALIDATE_TRANSPARENT
);
412 // -----------------------------------------------------------------------------
413 void OScrollWindowHelper::fillControlModelSelection(::std::vector
< uno::Reference
< uno::XInterface
> >& _rSelection
) const
415 m_aReportWindow
.fillControlModelSelection(_rSelection
);
417 // -----------------------------------------------------------------------------
418 sal_uInt16
OScrollWindowHelper::getZoomFactor(SvxZoomType _eType
) const
420 return m_aReportWindow
.getZoomFactor(_eType
);
422 //==============================================================================
424 //==============================================================================