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
30namespace rptui
31{
32#define SECTION_OFFSET 3
33#define SCR_LINE_SIZE 10
34using namespace ::com::sun::star;
35
36
37static void lcl_setScrollBar(sal_Int32 _nNewValue,const Point& _aPos,const Size& _aSize,ScrollAdaptor& _rScrollBar)
38{
39 _rScrollBar.SetPosSizePixel(_aPos,_aSize);
40 _rScrollBar.SetPageSize( _nNewValue );
41 _rScrollBar.SetVisibleSize( _nNewValue );
42}
43
44
48 ,m_aHScroll( VclPtr<ScrollAdaptor>::Create(this, true) )
49 ,m_aVScroll( VclPtr<ScrollAdaptor>::Create(this, false) )
50 ,m_pParent(_pDesignView)
51 ,m_aReportWindow(VclPtr<rptui::OReportWindow>::Create(this,m_pParent))
52{
53 SetMapMode( MapMode( MapUnit::Map100thMM ) );
54
57
58 m_aReportWindow->SetMapMode( MapMode( MapUnit::Map100thMM ) );
59 m_aReportWindow->Show();
60
61 // normally we should be SCROLL_PANE
62 SetAccessibleRole(css::accessibility::AccessibleRole::SCROLL_PANE);
64}
65
66
68{
70}
71
73{
76
79 m_aReportWindow.disposeAndClear();
80 m_pParent.clear();
82}
83
85{
86 _rScrollBar.SetScrollHdl( LINK( const_cast<OScrollWindowHelper*>(this), OScrollWindowHelper, ScrollHdl ) );
87 _rScrollBar.SetLineSize( SCR_LINE_SIZE );
88}
89
91{
92 uno::Reference<report::XReportDefinition> xReportDefinition = m_pParent->getController().getReportDefinition();
93 m_pReportDefinitionMultiPlexer = addStyleListener(xReportDefinition,this);
94}
95
96void OScrollWindowHelper::setTotalSize(sal_Int32 _nWidth ,sal_Int32 _nHeight)
97{
98 m_aTotalPixelSize.setWidth( _nWidth );
99 m_aTotalPixelSize.setHeight( _nHeight );
100
101 // now set the ranges without start marker
102 Fraction aStartWidth(REPORT_STARTMARKER_WIDTH * m_pParent->getController().getZoomValue(),100);
103 tools::Long nWidth = tools::Long(_nWidth - static_cast<double>(aStartWidth));
104 m_aHScroll->SetRangeMax( nWidth );
105 m_aVScroll->SetRangeMax( m_aTotalPixelSize.Height() );
106
107 Resize();
108}
109
111{
112 // get the new output-size in pixel
113 Size aOutPixSz = GetOutputSizePixel();
114 if ( aOutPixSz.IsEmpty() )
115 return aOutPixSz;
116
117 aOutPixSz.AdjustHeight( -(m_aReportWindow->getRulerHeight()) );
118 // determine the size of the output-area and if we need scrollbars
120 bool bVVisible = false; // by default no vertical-ScrollBar
121 bool bHVisible = false; // by default no horizontal-ScrollBar
122 bool bChanged; // determines if a visiblility was changed
123 do
124 {
125 bChanged = false;
126
127 // does we need a vertical ScrollBar
128 if ( aOutPixSz.Width() < m_aTotalPixelSize.Width() && !bHVisible )
129 {
130 bHVisible = true;
131 aOutPixSz.AdjustHeight( -nScrSize );
132 bChanged = true;
133 }
134
135 // does we need a horizontal ScrollBar
136 if ( aOutPixSz.Height() < m_aTotalPixelSize.Height() && !bVVisible )
137 {
138 bVVisible = true;
139 aOutPixSz.AdjustWidth( -nScrSize );
140 bChanged = true;
141 }
142
143 }
144 while ( bChanged ); // until no visibility has changed
145
146 aOutPixSz.AdjustHeight(m_aReportWindow->getRulerHeight() );
147
148 // show or hide scrollbars
149 m_aVScroll->Show( bVVisible );
150 m_aHScroll->Show( bHVisible );
151
152 const Point aOffset = LogicToPixel(Point(SECTION_OFFSET, SECTION_OFFSET), MapMode(MapUnit::MapAppFont));
153 // resize scrollbars and set their ranges
154 {
155 Fraction aStartWidth(tools::Long(REPORT_STARTMARKER_WIDTH*m_pParent->getController().getZoomValue()),100);
156 const sal_Int32 nNewWidth = aOutPixSz.Width() - aOffset.X() - static_cast<tools::Long>(aStartWidth);
157 lcl_setScrollBar(nNewWidth,Point( static_cast<tools::Long>(aStartWidth) + aOffset.X(), aOutPixSz.Height() ), Size( nNewWidth, nScrSize ), *m_aHScroll);
158 }
159 {
160 const sal_Int32 nNewHeight = aOutPixSz.Height() - m_aReportWindow->getRulerHeight();
161 lcl_setScrollBar(nNewHeight,Point( aOutPixSz.Width(), m_aReportWindow->getRulerHeight() ), Size( nScrSize,nNewHeight), *m_aVScroll);
162 }
163
164 return aOutPixSz;
165}
166
168{
170 const Size aTotalOutputSize = ResizeScrollBars();
171
172 m_aReportWindow->SetPosSizePixel(Point( 0, 0 ),aTotalOutputSize);
173}
174
176{
177 m_aReportWindow->ScrollChildren( getThumbPos() );
178}
179
180void OScrollWindowHelper::addSection(const uno::Reference< report::XSection >& _xSection
181 ,const OUString& _sColorEntry
182 ,sal_uInt16 _nPosition)
183{
184 m_aReportWindow->addSection(_xSection,_sColorEntry,_nPosition);
185}
186
187void OScrollWindowHelper::removeSection(sal_uInt16 _nPosition)
188{
189 m_aReportWindow->removeSection(_nPosition);
190}
191
193{
194 m_aReportWindow->toggleGrid(_bVisible);
195}
196
198{
199 return m_aReportWindow->getSectionCount();
200}
201
202void OScrollWindowHelper::SetInsertObj(SdrObjKind eObj, const OUString& _sShapeType)
203{
204 m_aReportWindow->SetInsertObj(eObj,_sShapeType);
205}
206
208{
209 return m_aReportWindow->GetInsertObjString();
210}
211
213{
214 m_aReportWindow->SetMode(_eNewMode);
215}
216
218{
219 return m_aReportWindow->HasSelection();
220}
221
223{
224 m_aReportWindow->Delete();
225}
226
228{
229 m_aReportWindow->Copy();
230}
231
233{
234 m_aReportWindow->Paste();
235}
236
238{
239 return m_aReportWindow->IsPasteAllowed();
240}
241
243{
244 m_aReportWindow->SelectAll(_nObjectType);
245}
246
248{
249 m_aReportWindow->unmarkAllObjects();
250}
251
253{
254 return m_aReportWindow->getMaxMarkerWidth();
255}
256
258{
259 m_aReportWindow->showRuler(_bShow);
260}
261
263{
264 return m_aReportWindow->handleKeyEvent(_rEvent);
265}
266
267void OScrollWindowHelper::setMarked(OSectionView const * _pSectionView, bool _bMark)
268{
269 m_aReportWindow->setMarked(_pSectionView,_bMark);
270}
271
272void OScrollWindowHelper::setMarked(const uno::Reference< report::XSection>& _xSection, bool _bMark)
273{
274 m_aReportWindow->setMarked(_xSection,_bMark);
275}
276
277void OScrollWindowHelper::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape, bool _bMark)
278{
279 m_aReportWindow->setMarked(_xShape,_bMark);
280}
281
283{
284 return m_aReportWindow->getMarkedSection(nsa);
285}
286
287OSectionWindow* OScrollWindowHelper::getSectionWindow(const css::uno::Reference< css::report::XSection>& _xSection) const
288{
289 return m_aReportWindow->getSectionWindow(_xSection);
290}
291
292void OScrollWindowHelper::markSection(const sal_uInt16 _nPos)
293{
294 m_aReportWindow->markSection(_nPos);
295}
296
297void OScrollWindowHelper::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
298{
299 m_aReportWindow->fillCollapsedSections(_rCollapsedPositions);
300}
301
302void OScrollWindowHelper::collapseSections(const uno::Sequence< css::beans::PropertyValue>& _aCollapsedSections)
303{
304 m_aReportWindow->collapseSections(_aCollapsedSections);
305}
306
308{
309 const CommandEvent* pCommandEvent = rNEvt.GetCommandEvent();
310 if ( pCommandEvent &&
311 ((pCommandEvent->GetCommand() == CommandEventId::Wheel) ||
312 (pCommandEvent->GetCommand() == CommandEventId::StartAutoScroll) ||
313 (pCommandEvent->GetCommand() == CommandEventId::AutoScroll)) )
314 {
315 ScrollAdaptor* pHScrBar = nullptr;
316 ScrollAdaptor* pVScrBar = nullptr;
317 if ( m_aHScroll->IsVisible() )
318 pHScrBar = m_aHScroll.get();
319
320 if ( m_aVScroll->IsVisible() )
321 pVScrBar = m_aVScroll.get();
322
323 if ( HandleScrollCommand( *pCommandEvent, pHScrBar, pVScrBar ) )
324 return true;
325 }
327}
328
329void OScrollWindowHelper::alignMarkedObjects(ControlModification _nControlModification, bool _bAlignAtSection)
330{
331 m_aReportWindow->alignMarkedObjects(_nControlModification, _bAlignAtSection);
332}
333
335{
336 SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
337 GetOutDev()->SetFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
338 SetTextFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
339}
340
342{
343 Window::DataChanged( rDCEvt );
344
345 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
346 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
347 {
349 Invalidate();
350 }
351}
352
353void OScrollWindowHelper::_propertyChanged(const beans::PropertyChangeEvent& /*_rEvent*/)
354{
355 m_aReportWindow->notifySizeChanged();
356}
357
359{
360 m_aReportWindow->setGridSnap(bOn);
361}
362
364{
365 m_aReportWindow->setDragStripes(bOn);
366}
367
369{
370 return m_aReportWindow->getMarkedObjectCount();
371}
372
374{
375 m_aReportWindow->zoom(_aZoom);
376 Resize();
377 Invalidate(InvalidateFlags::NoChildren|InvalidateFlags::Transparent);
378}
379
380void OScrollWindowHelper::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
381{
382 m_aReportWindow->fillControlModelSelection(_rSelection);
383}
384
386{
387 return m_aReportWindow->getZoomFactor(_eType);
388}
389
390} // rptui
391
392
393/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define REPORT_STARTMARKER_WIDTH
#define SCR_LINE_SIZE
#define SECTION_OFFSET
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
CommandEventId GetCommand() const
DataChangedEventType GetType() const
AllSettingsFlags GetFlags() const
const CommandEvent * GetCommandEvent() const
void SetFillColor()
void SetScrollHdl(const Link< weld::Scrollbar &, void > &rLink)
virtual void SetPageSize(tools::Long nNewSize) override
virtual void SetVisibleSize(tools::Long nNewSize) override
virtual void SetLineSize(tools::Long nNewSize) override
bool IsEmpty() const
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
void setWidth(tools::Long nWidth)
tools::Long AdjustWidth(tools::Long n)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
sal_Int32 GetScrollBarSize() const
void disposeAndClear()
reference_type * get() const
void SetMode(DlgEdMode _eMode)
sal_Int32 getMaxMarkerWidth() const
calculate the max width of the markers
virtual ~OScrollWindowHelper() override
virtual void dispose() override
void fillCollapsedSections(::std::vector< sal_uInt16 > &_rCollapsedPositions) const
fills the positions of all collapsed sections.
VclPtr< ODesignView > m_pParent
virtual void markSection(const sal_uInt16 _nPos) override
mark the section on the given position .
void toggleGrid(bool _bVisible)
turns the grid on or off
VclPtr< OReportWindow > m_aReportWindow
sal_uInt16 getZoomFactor(SvxZoomType _eType) const
calculates the zoom factor.
void zoom(const Fraction &_aZoom)
zoom the ruler and view windows
bool HasSelection() const
returns <TRUE> when an object is marked
VclPtr< ScrollAdaptor > m_aHScroll
void Paste()
paste a new control in this section
::rtl::Reference< comphelper::OPropertyChangeMultiplexer > m_pReportDefinitionMultiPlexer
void setTotalSize(sal_Int32 _nWidth, sal_Int32 _nHeight)
void removeSection(sal_uInt16 _nPosition)
removes the section at the given position.
virtual void _propertyChanged(const css::beans::PropertyChangeEvent &_rEvent) override
OSectionWindow * getMarkedSection(NearSectionAccess nsa=CURRENT) const override
returns the section which is currently marked.
VclPtr< ScrollAdaptor > m_aVScroll
void alignMarkedObjects(ControlModification _nControlModification, bool _bAlignAtSection)
align all marked objects in all sections
void unmarkAllObjects()
unmark all objects on the views.
OSectionWindow * getSectionWindow(const css::uno::Reference< css::report::XSection > &_xSection) const
sal_uInt32 getMarkedObjectCount() const
void SelectAll(const SdrObjKind _nObjectType)
All objects will be marked.
OUString const & GetInsertObjString() const
void SetInsertObj(SdrObjKind eObj, const OUString &_sShapeType)
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
void addSection(const css::uno::Reference< css::report::XSection > &_xSection, const OUString &_sColorEntry, sal_uInt16 _nPosition)
adds a new section at position _nPosition.
void collapseSections(const css::uno::Sequence< css::beans::PropertyValue > &_aCollapsedSections)
collapse all sections given by their position
bool handleKeyEvent(const KeyEvent &_rEvent)
checks if the keycode is known by the child windows
sal_uInt16 getSectionCount() const
OScrollWindowHelper(OScrollWindowHelper const &)=delete
virtual void Resize() override
void impl_initScrollBar(ScrollAdaptor &rScrollBar) const
void Delete()
Deletes the current selection in this section.
virtual bool EventNotify(NotifyEvent &rNEvt) override
void showRuler(bool _bShow)
shows or hides the ruler.
void initialize()
late ctor
void setMarked(OSectionView const *_pSectionView, bool _bMark)
the section as marked or not marked
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 Copy()
copies the current selection in this section
bool IsPasteAllowed() const
returns if paste is allowed
virtual void dispose() override
Point LogicToPixel(const Point &rLogicPt) const
bool HandleScrollCommand(const CommandEvent &rCmd, Scrollable *pHScrl, Scrollable *pVScrl)
virtual void Resize()
void SetMapMode()
const AllSettings & GetSettings() const
void SetTextFillColor()
::OutputDevice const * GetOutDev() const
void SetAccessibleRole(sal_uInt16 nRole)
Size GetOutputSizePixel() const
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
virtual bool EventNotify(NotifyEvent &rNEvt)
void SetBackground()
std::mutex m_aMutex
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
::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
static void lcl_setScrollBar(sal_Int32 _nNewValue, const Point &_aPos, const Size &_aSize, ScrollAdaptor &_rScrollBar)
ControlModification
Definition: RptDef.hxx:49
IMPL_LINK_NOARG(OAddFieldWindow, FocusChangeHdl, weld::Container &, void)
Definition: AddField.cxx:120
long Long
SdrObjKind
WinBits const WB_DIALOGCONTROL
sal_Int32 _nPos
SvxZoomType