LibreOffice Module reportdesign (master)  1
ScrollHelper.cxx
Go to the documentation of this file.
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 <com/sun/star/accessibility/AccessibleRole.hpp>
25 
26 #include <vcl/commandevent.hxx>
27 #include <vcl/settings.hxx>
28 #include <vcl/svapp.hxx>
29 
30 namespace rptui
31 {
32 #define SECTION_OFFSET 3
33 #define SCR_LINE_SIZE 10
34 using namespace ::com::sun::star;
35 
36 
37 static void lcl_setScrollBar(sal_Int32 _nNewValue,const Point& _aPos,const Size& _aSize,ScrollBar& _rScrollBar)
38 {
39  _rScrollBar.SetPosSizePixel(_aPos,_aSize);
40  _rScrollBar.SetPageSize( _nNewValue );
41  _rScrollBar.SetVisibleSize( _nNewValue );
42 }
43 
44 
48  ,m_aHScroll( VclPtr<ScrollBar>::Create(this, WB_HSCROLL|WB_REPEAT|WB_DRAG) )
49  ,m_aVScroll( VclPtr<ScrollBar>::Create(this, WB_VSCROLL|WB_REPEAT|WB_DRAG) )
50  ,m_aCornerWin( VclPtr<ScrollBarBox>::Create(this) )
51  ,m_pParent(_pDesignView)
52  ,m_aReportWindow(VclPtr<rptui::OReportWindow>::Create(this,m_pParent))
53 {
54  SetMapMode( MapMode( MapUnit::Map100thMM ) );
55 
58 
59  m_aReportWindow->SetMapMode( MapMode( MapUnit::Map100thMM ) );
60  m_aReportWindow->Show();
61 
62  // normally we should be SCROLL_PANE
63  SetAccessibleRole(css::accessibility::AccessibleRole::SCROLL_PANE);
65 }
66 
67 
69 {
70  disposeOnce();
71 }
72 
74 {
77 
81  m_aReportWindow.disposeAndClear();
82  m_pParent.clear();
84 }
85 
86 
88 {
89  AllSettings aSettings( _rScrollBar.GetSettings() );
90  StyleSettings aStyle( aSettings.GetStyleSettings() );
91  aStyle.SetDragFullOptions( aStyle.GetDragFullOptions() | DragFullOptions::Scroll ); // live scrolling
92  aSettings.SetStyleSettings( aStyle );
93  _rScrollBar.SetSettings( aSettings );
94 
95  _rScrollBar.SetScrollHdl( LINK( const_cast<OScrollWindowHelper*>(this), OScrollWindowHelper, ScrollHdl ) );
96  _rScrollBar.SetLineSize( SCR_LINE_SIZE );
97 }
98 
99 
101 {
102  uno::Reference<report::XReportDefinition> xReportDefinition = m_pParent->getController().getReportDefinition();
103  m_pReportDefinitionMultiPlexer = addStyleListener(xReportDefinition,this);
104 }
105 
106 void OScrollWindowHelper::setTotalSize(sal_Int32 _nWidth ,sal_Int32 _nHeight)
107 {
108  m_aTotalPixelSize.setWidth( _nWidth );
109  m_aTotalPixelSize.setHeight( _nHeight );
110 
111  // now set the ranges without start marker
112  Fraction aStartWidth(REPORT_STARTMARKER_WIDTH * m_pParent->getController().getZoomValue(),100);
113  tools::Long nWidth = tools::Long(_nWidth - static_cast<double>(aStartWidth));
114  m_aHScroll->SetRangeMax( nWidth );
116 
117  Resize();
118 }
119 
121 {
122  // get the new output-size in pixel
123  Size aOutPixSz = GetOutputSizePixel();
124  if ( aOutPixSz.IsEmpty() )
125  return aOutPixSz;
126 
127  aOutPixSz.AdjustHeight( -(m_aReportWindow->getRulerHeight()) );
128  // determine the size of the output-area and if we need scrollbars
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.AdjustHeight( -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.AdjustWidth( -nScrSize );
150  bChanged = true;
151  }
152 
153  }
154  while ( bChanged ); // until no visibility has changed
155 
156  aOutPixSz.AdjustHeight(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), MapMode(MapUnit::MapAppFont));
172  // resize scrollbars and set their ranges
173  {
174  Fraction aStartWidth(tools::Long(REPORT_STARTMARKER_WIDTH*m_pParent->getController().getZoomValue()),100);
175  const sal_Int32 nNewWidth = aOutPixSz.Width() - aOffset.X() - static_cast<tools::Long>(aStartWidth);
176  lcl_setScrollBar(nNewWidth,Point( static_cast<tools::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 
187 {
189  const Size aTotalOutputSize = ResizeScrollBars();
190 
191  m_aReportWindow->SetPosSizePixel(Point( 0, 0 ),aTotalOutputSize);
192 }
193 
194 IMPL_LINK( OScrollWindowHelper, ScrollHdl, ScrollBar*, /*pScroll*/, void )
195 {
196  m_aReportWindow->ScrollChildren( getThumbPos() );
197 }
198 
199 void OScrollWindowHelper::addSection(const uno::Reference< report::XSection >& _xSection
200  ,const OUString& _sColorEntry
201  ,sal_uInt16 _nPosition)
202 {
203  m_aReportWindow->addSection(_xSection,_sColorEntry,_nPosition);
204 }
205 
206 void OScrollWindowHelper::removeSection(sal_uInt16 _nPosition)
207 {
208  m_aReportWindow->removeSection(_nPosition);
209 }
210 
212 {
213  m_aReportWindow->toggleGrid(_bVisible);
214 }
215 
217 {
218  return m_aReportWindow->getSectionCount();
219 }
220 
221 void OScrollWindowHelper::SetInsertObj(SdrObjKind eObj, const OUString& _sShapeType)
222 {
223  m_aReportWindow->SetInsertObj(eObj,_sShapeType);
224 }
225 
227 {
228  return m_aReportWindow->GetInsertObjString();
229 }
230 
232 {
233  m_aReportWindow->SetMode(_eNewMode);
234 }
235 
237 {
238  return m_aReportWindow->HasSelection();
239 }
240 
242 {
243  m_aReportWindow->Delete();
244 }
245 
247 {
248  m_aReportWindow->Copy();
249 }
250 
252 {
253  m_aReportWindow->Paste();
254 }
255 
257 {
258  return m_aReportWindow->IsPasteAllowed();
259 }
260 
261 void OScrollWindowHelper::SelectAll(const sal_uInt16 _nObjectType)
262 {
263  m_aReportWindow->SelectAll(_nObjectType);
264 }
265 
267 {
268  m_aReportWindow->unmarkAllObjects();
269 }
270 
272 {
273  return m_aReportWindow->getMaxMarkerWidth();
274 }
275 
277 {
278  m_aReportWindow->showRuler(_bShow);
279 }
280 
282 {
283  return m_aReportWindow->handleKeyEvent(_rEvent);
284 }
285 
286 void OScrollWindowHelper::setMarked(OSectionView const * _pSectionView, bool _bMark)
287 {
288  m_aReportWindow->setMarked(_pSectionView,_bMark);
289 }
290 
291 void OScrollWindowHelper::setMarked(const uno::Reference< report::XSection>& _xSection, bool _bMark)
292 {
293  m_aReportWindow->setMarked(_xSection,_bMark);
294 }
295 
296 void OScrollWindowHelper::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape, bool _bMark)
297 {
298  m_aReportWindow->setMarked(_xShape,_bMark);
299 }
300 
302 {
303  return m_aReportWindow->getMarkedSection(nsa);
304 }
305 
306 OSectionWindow* OScrollWindowHelper::getSectionWindow(const css::uno::Reference< css::report::XSection>& _xSection) const
307 {
308  return m_aReportWindow->getSectionWindow(_xSection);
309 }
310 
311 void OScrollWindowHelper::markSection(const sal_uInt16 _nPos)
312 {
313  m_aReportWindow->markSection(_nPos);
314 }
315 
316 void OScrollWindowHelper::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
317 {
318  m_aReportWindow->fillCollapsedSections(_rCollapsedPositions);
319 }
320 
321 void OScrollWindowHelper::collapseSections(const uno::Sequence< css::beans::PropertyValue>& _aCollapsedSections)
322 {
323  m_aReportWindow->collapseSections(_aCollapsedSections);
324 }
325 
327 {
328  const CommandEvent* pCommandEvent = rNEvt.GetCommandEvent();
329  if ( pCommandEvent &&
330  ((pCommandEvent->GetCommand() == CommandEventId::Wheel) ||
331  (pCommandEvent->GetCommand() == CommandEventId::StartAutoScroll) ||
332  (pCommandEvent->GetCommand() == CommandEventId::AutoScroll)) )
333  {
334  ScrollBar* pHScrBar = nullptr;
335  ScrollBar* pVScrBar = nullptr;
336  if ( m_aHScroll->IsVisible() )
337  pHScrBar = m_aHScroll.get();
338 
339  if ( m_aVScroll->IsVisible() )
340  pVScrBar = m_aVScroll.get();
341 
342  if ( HandleScrollCommand( *pCommandEvent, pHScrBar, pVScrBar ) )
343  return true;
344  }
346 }
347 
348 void OScrollWindowHelper::alignMarkedObjects(ControlModification _nControlModification, bool _bAlignAtSection)
349 {
350  m_aReportWindow->alignMarkedObjects(_nControlModification, _bAlignAtSection);
351 }
352 
354 {
355  SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
356  SetFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
357  SetTextFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
358 }
359 
361 {
362  Window::DataChanged( rDCEvt );
363 
364  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
365  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
366  {
368  Invalidate();
369  }
370 }
371 
372 void OScrollWindowHelper::_propertyChanged(const beans::PropertyChangeEvent& /*_rEvent*/)
373 {
374  m_aReportWindow->notifySizeChanged();
375 }
376 
378 {
379  m_aReportWindow->setGridSnap(bOn);
380 }
381 
383 {
384  m_aReportWindow->setDragStripes(bOn);
385 }
386 
388 {
389  return m_aReportWindow->getMarkedObjectCount();
390 }
391 
393 {
394  m_aReportWindow->zoom(_aZoom);
395  Resize();
396  Invalidate(InvalidateFlags::NoChildren|InvalidateFlags::Transparent);
397 }
398 
399 void OScrollWindowHelper::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
400 {
401  m_aReportWindow->fillControlModelSelection(_rSelection);
402 }
403 
405 {
406  return m_aReportWindow->getZoomFactor(_eType);
407 }
408 
409 } // rptui
410 
411 
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void _propertyChanged(const css::beans::PropertyChangeEvent &_rEvent) override
OScrollWindowHelper(OScrollWindowHelper const &)=delete
VclPtr< ScrollBarBox > m_aCornerWin
osl::Mutex m_aMutex
void setWidth(tools::Long nWidth)
OSectionWindow * getSectionWindow(const css::uno::Reference< css::report::XSection > &_xSection) const
void SetDragFullOptions(DragFullOptions nOptions)
const CommandEvent * GetCommandEvent() const
virtual bool EventNotify(NotifyEvent &rNEvt) override
void collapseSections(const css::uno::Sequence< css::beans::PropertyValue > &_aCollapsedSections)
collapse all sections given by their position
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
long Long
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
void toggleGrid(bool _bVisible)
turns the grid on or off
VclPtr< ScrollBar > m_aHScroll
void SetTextFillColor()
DataChangedEventType GetType() const
WinBits const WB_VSCROLL
virtual void SetSettings(const AllSettings &rSettings) override
virtual void dispose() override
void SetRangeMax(tools::Long nNewRange)
bool HandleScrollCommand(const CommandEvent &rCmd, ScrollBar *pHScrl, ScrollBar *pVScrl)
OUString const & GetInsertObjString() const
void SetMapMode()
SdrObjKind
sal_Int32 getMaxMarkerWidth() const
calculate the max width of the markers
void Paste()
paste a new control in this section
void setTotalSize(sal_Int32 _nWidth, sal_Int32 _nHeight)
void SetMode(DlgEdMode _eMode)
constexpr tools::Long Width() const
sal_uInt16 getZoomFactor(SvxZoomType _eType) const
calculates the zoom factor.
void SetBackground()
void SetPageSize(tools::Long nNewSize)
VclPtr< ScrollBar > m_aVScroll
WinBits const WB_HSCROLL
sal_uInt32 getMarkedObjectCount() const
void removeSection(sal_uInt16 _nPosition)
removes the section at the given position.
AllSettingsFlags GetFlags() const
ControlModification
Definition: RptDef.hxx:48
#define REPORT_STARTMARKER_WIDTH
virtual void markSection(const sal_uInt16 _nPos) override
mark the section on the given position .
void fillControlModelSelection(::std::vector< css::uno::Reference< css::uno::XInterface > > &_rSelection) const
fills the vector with all selected control models /param _rSelection The vector will be filled and wi...
void setMarked(OSectionView const *_pSectionView, bool _bMark)
the section as marked or not marked
void SetLineSize(tools::Long nNewSize)
#define SECTION_OFFSET
WinBits const WB_DIALOGCONTROL
sal_Int32 GetScrollBarSize() const
bool IsPasteAllowed() const
returns if paste is allowed
bool IsEmpty() const
virtual bool EventNotify(NotifyEvent &rNEvt)
void unmarkAllObjects()
unmark all objects on the views.
virtual ~OScrollWindowHelper() override
void SetVisibleSize(tools::Long nNewSize)
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
void impl_initScrollBar(ScrollBar &_rScrollBar) const
VclPtr< ODesignView > m_pParent
void SetFillColor()
CommandEventId GetCommand() const
OSectionWindow * getMarkedSection(NearSectionAccess nsa=CURRENT) const override
returns the section which is currently marked.
virtual void Resize()
void SelectAll(const sal_uInt16 _nObjectType)
All objects will be marked.
const AllSettings & GetSettings() const
Size GetOutputSizePixel() const
WinBits const WB_REPEAT
void alignMarkedObjects(ControlModification _nControlModification, bool _bAlignAtSection)
align all marked objects in all sections
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
void showRuler(bool _bShow)
shows or hides the ruler.
Point LogicToPixel(const Point &rLogicPt) const
virtual void dispose() override
IMPL_LINK(OAddFieldWindow, DragBeginHdl, bool &, rUnsetDragIcon, bool)
Definition: AddField.cxx:49
bool handleKeyEvent(const KeyEvent &_rEvent)
checks if the keycode is known by the child windows
::rtl::Reference< comphelper::OPropertyChangeMultiplexer > addStyleListener(const css::uno::Reference< css::report::XReportDefinition > &_xReportDefinition,::comphelper::OPropertyChangeListener *_pListener)
add a listener for the properties size, left margin, right margin to the page style ...
constexpr tools::Long Height() const
bool IsVisible() const
VclPtr< OReportWindow > m_aReportWindow
::rtl::Reference< comphelper::OPropertyChangeMultiplexer > m_pReportDefinitionMultiPlexer
void Copy()
copies the current selection in this section
tools::Long AdjustWidth(tools::Long n)
void SetScrollHdl(const Link< ScrollBar *, void > &rLink)
sal_uInt16 getSectionCount() const
tools::Long AdjustHeight(tools::Long n)
void setHeight(tools::Long nHeight)
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
ScrollBar * get() const
SvxZoomType
void SetInsertObj(SdrObjKind eObj, const OUString &_sShapeType)
void SetAccessibleRole(sal_uInt16 nRole)
static void lcl_setScrollBar(sal_Int32 _nNewValue, const Point &_aPos, const Size &_aSize, ScrollBar &_rScrollBar)
void zoom(const Fraction &_aZoom)
zoom the ruler and view windows
void fillCollapsedSections(::std::vector< sal_uInt16 > &_rCollapsedPositions) const
fills the positions of all collapsed sections.
void addSection(const css::uno::Reference< css::report::XSection > &_xSection, const OUString &_sColorEntry, sal_uInt16 _nPosition)
adds a new section at position _nPosition.
virtual void Resize() override
void Delete()
Deletes the current selection in this section.
#define SCR_LINE_SIZE
WinBits const WB_DRAG
bool HasSelection() const
returns when an object is marked
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
void initialize()
late ctor