LibreOffice Module reportdesign (master)  1
ReportWindow.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 <ReportWindow.hxx>
20 #include <ReportSection.hxx>
21 #include <SectionView.hxx>
22 #include <ViewsWindow.hxx>
23 #include <DesignView.hxx>
24 #include <UITools.hxx>
25 
26 #include <unotools/syslocale.hxx>
28 
29 #include <vcl/settings.hxx>
30 
31 #include <RptDef.hxx>
32 #include <strings.hxx>
33 #include <ReportController.hxx>
34 #include <ScrollHelper.hxx>
35 
36 #include <helpids.h>
37 #include <dlgedfac.hxx>
38 
39 
40 #define SECTION_OFFSET 3
41 namespace rptui
42 {
43 using namespace ::com::sun::star;
44 using namespace ::comphelper;
45 
46 
47 
49 : Window(_pParent,WB_DIALOGCONTROL)
51 ,m_aHRuler(VclPtr<Ruler>::Create(this))
52 ,m_pView(_pView)
53 ,m_pParent(_pParent)
54 ,m_aViewsWindow(VclPtr<rptui::OViewsWindow>::Create(this))
55 ,m_pObjFac( new DlgEdFactory() )
56 {
58  SetMapMode( MapMode( MapUnit::Map100thMM ) );
59 
60  m_aViewsWindow->Show();
61 
62  m_aHRuler->Show();
70  m_aHRuler->SetUnit(MeasurementSystem::Metric == eSystem ? FieldUnit::CM : FieldUnit::INCH);
71 
74 }
75 
77 {
78  disposeOnce();
79 }
80 
82 {
83  if ( m_pReportListener.is() )
84  m_pReportListener->dispose();
86  m_aViewsWindow.disposeAndClear();
87  m_pView.clear();
88  m_pParent.clear();
90 }
91 
92 void OReportWindow::SetInsertObj( SdrObjKind eObj,const OUString& _sShapeType )
93 {
94  m_aViewsWindow->SetInsertObj( eObj,_sShapeType);
95 }
96 
97 OUString const & OReportWindow::GetInsertObjString() const
98 {
99  return m_aViewsWindow->GetInsertObjString();
100 }
101 
103 {
104  m_aViewsWindow->SetMode(eNewMode);
105 }
106 
107 void OReportWindow::removeSection(sal_uInt16 _nPosition)
108 {
109  m_aViewsWindow->removeSection(_nPosition);
110  m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
111  m_aViewsWindow->Invalidate(InvalidateFlags::Transparent);
112 }
113 
114 void OReportWindow::addSection(const uno::Reference< report::XSection >& _xSection,const OUString& _sColorEntry,sal_uInt16 _nPosition)
115 {
116  if ( !_xSection.is() )
117  return;
118 
119  m_aViewsWindow->addSection(_xSection,_sColorEntry,_nPosition);
120 
121  m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
122 }
123 
124 void OReportWindow::toggleGrid(bool _bVisible)
125 {
126  m_aViewsWindow->toggleGrid(_bVisible);
127 }
128 
129 void OReportWindow::showRuler(bool _bShow)
130 {
131  m_aHRuler->Show(_bShow);
132 
133  m_aViewsWindow->showRuler(_bShow);
134 }
135 
137 {
139  aStartWidth *= m_aViewsWindow->GetMapMode().GetScaleX();
140  return sal_Int32(static_cast<tools::Long>(aStartWidth));
141 }
142 
144 {
145  sal_Int32 nWidth = 0;
146  if ( !m_aViewsWindow->empty() )
147  {
149  const Fraction aZoom(m_pView->getController().getZoomValue(),100);
150  aStartWidth *= aZoom;
151  sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
152  nPaperWidth = tools::Long(nPaperWidth * aZoom);
153  const Size aPageSize = LogicToPixel(Size(nPaperWidth,0));
154  nWidth = aPageSize.Width() + tools::Long(aStartWidth);
155  }
156  return nWidth;
157 }
158 
160 {
161  Window::Resize();
162  if ( m_aViewsWindow->empty() )
163  return;
164 
165  const Size aTotalOutputSize = GetOutputSizePixel();
166  Fraction aStartWidth(tools::Long(REPORT_STARTMARKER_WIDTH)*m_pView->getController().getZoomValue(),100);
167 
168  const Point aOffset = LogicToPixel(Point(SECTION_OFFSET, 0), MapMode(MapUnit::MapAppFont));
169  Point aStartPoint(static_cast<tools::Long>(aStartWidth) + aOffset.X(),0);
170  uno::Reference<report::XReportDefinition> xReportDefinition = getReportView()->getController().getReportDefinition();
171  const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
172  sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
173  sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
174  Size aPageSize = m_aViewsWindow->LogicToPixel(Size(nPaperWidth ,0));
175  nLeftMargin = m_aViewsWindow->LogicToPixel(Size(nLeftMargin,0)).Width();
176  nRightMargin = m_aViewsWindow->LogicToPixel(Size(nRightMargin,0)).Width();
177 
178  aPageSize.setHeight( m_aHRuler->GetSizePixel().Height() );
179 
180  const tools::Long nTermp(m_aViewsWindow->getTotalHeight() + aPageSize.Height());
181  tools::Long nSectionsHeight = ::std::max<tools::Long>(nTermp,aTotalOutputSize.Height());
182 
183  m_aHRuler->SetPosSizePixel(aStartPoint,aPageSize);
184  m_aHRuler->SetNullOffset(nLeftMargin);
185  m_aHRuler->SetMargin1(0);
186  m_aHRuler->SetMargin2(aPageSize.Width() - nLeftMargin - nRightMargin);
187 
188  aStartPoint.AdjustY(aPageSize.Height() );
189  nSectionsHeight -= aStartPoint.Y();
190 
191  aStartPoint.setX( aOffset.X() );
192 
193  m_aViewsWindow->SetPosSizePixel(aStartPoint,Size(aTotalOutputSize.Width(),nSectionsHeight));
194 }
195 
197 {
198  return m_pParent->getThumbPos();
199 }
200 
202 {
203  SetBackground( );
204 }
205 
207 {
208  Window::DataChanged( rDCEvt );
209 
210  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
211  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
212  {
214  Invalidate();
215  }
216 }
217 
219 {
220  return m_aViewsWindow->getTotalHeight();
221 }
222 
223 void OReportWindow::ScrollChildren(const Point& _aThumbPos)
224 {
225  MapMode aMap = m_aHRuler->GetMapMode();
226  Point aOrg( aMap.GetOrigin() );
227  if ( aOrg.X() != (-_aThumbPos.X()) )
228  {
229  aMap.SetOrigin( Point(- _aThumbPos.X(), aOrg.Y()));
230  m_aHRuler->SetMapMode( aMap );
231  m_aHRuler->Scroll(-(aOrg.X() + _aThumbPos.X()),0);
232  }
233 
234  m_aViewsWindow->scrollChildren(_aThumbPos);
235 }
236 
238 {
239  return m_aViewsWindow->getSectionCount();
240 }
241 
243 {
244  m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
245 }
246 
248 {
249  return m_aViewsWindow->HasSelection();
250 }
251 
253 {
254 
255  m_aViewsWindow->Delete();
256 }
257 
259 {
260 
261  m_aViewsWindow->Copy();
262 }
263 
265 {
266 
267  m_aViewsWindow->Paste();
268 }
269 
271 {
272  return m_aViewsWindow->IsPasteAllowed();
273 }
274 
275 void OReportWindow::SelectAll(const sal_uInt16 _nObjectType)
276 {
277 
278  m_aViewsWindow->SelectAll(_nObjectType);
279 }
280 
282 {
283 
284  m_aViewsWindow->unmarkAllObjects(nullptr);
285 }
286 
287 void OReportWindow::showProperties(const uno::Reference< report::XSection>& _xReportComponent)
288 {
289  OSectionWindow* pSectionWindow = m_aViewsWindow->getSectionWindow( _xReportComponent );
290  m_pView->UpdatePropertyBrowserDelayed(pSectionWindow->getReportSection().getSectionView());
291 }
292 
294 {
295  return m_aViewsWindow->handleKeyEvent(_rEvent);
296 }
297 
298 void OReportWindow::setMarked(OSectionView const * _pSectionView, bool _bMark)
299 {
300  if ( _pSectionView )
301  m_aViewsWindow->setMarked(_pSectionView,_bMark);
302 }
303 
304 void OReportWindow::setMarked(const uno::Reference< report::XSection>& _xSection, bool _bMark)
305 {
306 
307  m_aViewsWindow->setMarked(_xSection,_bMark);
308 }
309 
310 void OReportWindow::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape, bool _bMark)
311 {
312 
313  m_aViewsWindow->setMarked(_xShape,_bMark);
314 }
315 
317 {
318  return m_aViewsWindow->getMarkedSection(nsa);
319 }
320 
321 OSectionWindow* OReportWindow::getSectionWindow(const css::uno::Reference< css::report::XSection>& _xSection) const
322 {
323  return m_aViewsWindow->getSectionWindow(_xSection);
324 }
325 
326 void OReportWindow::markSection(const sal_uInt16 _nPos)
327 {
328 
329  m_aViewsWindow->markSection(_nPos);
330 }
331 
332 void OReportWindow::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
333 {
334 
335  m_aViewsWindow->fillCollapsedSections(_rCollapsedPositions);
336 }
337 
338 void OReportWindow::collapseSections(const uno::Sequence< css::beans::PropertyValue>& _aCollapsedSections)
339 {
340 
341  m_aViewsWindow->collapseSections(_aCollapsedSections);
342 }
343 
344 void OReportWindow::alignMarkedObjects(ControlModification _nControlModification, bool _bAlignAtSection)
345 {
346  m_aViewsWindow->alignMarkedObjects(_nControlModification, _bAlignAtSection);
347 }
348 
350 {
351 
352  m_aViewsWindow->setGridSnap(bOn);
353 }
354 
356 {
357  m_aViewsWindow->setDragStripes(bOn);
358 }
359 
361 {
362  return m_aViewsWindow->getMarkedObjectCount();
363 }
364 
365 void OReportWindow::zoom(const Fraction& _aZoom)
366 {
367  m_aHRuler->SetZoom(_aZoom);
368  m_aHRuler->Invalidate();
369 
370  m_aViewsWindow->zoom(_aZoom);
371 
373  const Point aNewThumbPos( m_pParent->getThumbPos() );
374 
375  ScrollChildren( aNewThumbPos );
376  Resize();
377 
378  Invalidate(InvalidateFlags::NoErase | InvalidateFlags::NoChildren | InvalidateFlags::Transparent);
379 }
380 
381 void OReportWindow::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
382 {
383  m_aViewsWindow->fillControlModelSelection(_rSelection);
384 }
385 
387 {
388  const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
389  MapMode aMap( MapUnit::Map100thMM );
390  const Size aPageSize = LogicToPixel(Size(nPaperWidth,0),aMap);
392 }
393 
395 {
396  sal_uInt16 nZoom(100);
397  const Size aSize( GetSizePixel() );
398  switch( _eType)
399  {
400  case SvxZoomType::PERCENT:
401  nZoom = m_pView->getController().getZoomValue();
402  break;
403  case SvxZoomType::OPTIMAL:
404  break;
405  case SvxZoomType::WHOLEPAGE:
406  {
407  nZoom = static_cast<sal_uInt16>(static_cast<tools::Long>(Fraction(aSize.Width()*100,impl_getRealPixelWidth())));
408  MapMode aMap( MapUnit::Map100thMM );
409  const Size aHeight = m_aViewsWindow->LogicToPixel(m_aViewsWindow->PixelToLogic(Size(0,GetTotalHeight() + m_aHRuler->GetSizePixel().Height())),aMap);
410  nZoom = ::std::min(nZoom,static_cast<sal_uInt16>(static_cast<tools::Long>(Fraction(aSize.Height()*100,aHeight.Height()))));
411  }
412  break;
413  case SvxZoomType::PAGEWIDTH:
414  nZoom = static_cast<sal_uInt16>(static_cast<tools::Long>(Fraction(aSize.Width()*100,impl_getRealPixelWidth())));
415  break;
416  default:
417  break;
418  }
419 
420  return nZoom;
421 }
422 
423 void OReportWindow::_propertyChanged(const beans::PropertyChangeEvent&)
424 {
425  Resize();
426  m_aViewsWindow->Resize();
427  Invalidate(InvalidateFlags::Transparent);
428 }
429 
430 } //rptui
431 
432 
433 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString const & GetInsertObjString() const
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...
bool IsPasteAllowed() const
returns if paste is allowed
void SetBackground()
virtual ~OReportWindow() override
void fillCollapsedSections(::std::vector< sal_uInt16 > &_rCollapsedPositions) const
fills the positions of all collapsed sections.
void collapseSections(const css::uno::Sequence< css::beans::PropertyValue > &_aCollapsedSections)
collapse all sections given by their position
#define PROPERTY_RIGHTMARGIN
Definition: strings.hxx:105
osl::Mutex m_aMutex
void SetUnit(FieldUnit eNewUnit)
void Activate() override
sal_Int32 GetTotalWidth() const
returns the total width of the first section
tools::Long const nLeftMargin
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
long Long
void disposeAndClear()
void zoom(const Fraction &_aZoom)
zoom the ruler and view windows
virtual Size GetSizePixel() const
void Delete()
Deletes the current selection in this section.
DataChangedEventType GetType() const
void SetHelpId(const OString &)
void SelectAll(const sal_uInt16 _nObjectType)
All objects will be marked.
virtual void dispose() override
void setGridSnap(bool bOn)
#define SECTION_OFFSET
SdrObjKind
MeasurementSystem
constexpr tools::Long Width() const
HashMap_OWString_Interface aMap
sal_Int32 getMaxMarkerWidth() const
calculate the max width of the markers The end marker will not be used for calculation.
const LocaleDataWrapper & GetLocaleData() const
#define PROPERTY_LEFTMARGIN
Definition: strings.hxx:104
OSectionWindow * getSectionWindow(const css::uno::Reference< css::report::XSection > &_xSection) const
VclPtr< OScrollWindowHelper > m_pParent
AllSettingsFlags GetFlags() const
ControlModification
Definition: RptDef.hxx:48
void SetMargin2()
#define REPORT_STARTMARKER_WIDTH
rtl::Reference< comphelper::OPropertyChangeMultiplexer > m_pReportListener
void SetIndents(sal_uInt32 n=0, const RulerIndent *pIndentAry=nullptr)
sal_uInt16 getSectionCount() const
VclPtr< Ruler > m_aHRuler
OReportSection & getReportSection()
#define REPORT_ENDMARKER_WIDTH
WinBits const WB_DIALOGCONTROL
Point LogicToPixel(const Point &rLogicPt) const
void showRuler(bool _bShow)
shows the ruler
#define PROPERTY_PAPERSIZE
Definition: strings.hxx:62
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
void SetOrigin(const Point &rOrigin)
void SetZoom(const Fraction &rNewZoom)
void setMarked(OSectionView const *_pSectionView, bool _bMark)
the section as marked or not marked
void ScrollChildren(const Point &_aThumbPos)
bool HasSelection() const
returns when an object is marked
void toggleGrid(bool _bVisible)
turns the grid on or off
virtual void _propertyChanged(const css::beans::PropertyChangeEvent &_rEvent) override
OReportWindow(OReportWindow const &)=delete
VclPtr< OViewsWindow > m_aViewsWindow
VclPtr< ODesignView > m_pView
sal_uInt16 getZoomFactor(SvxZoomType _eType) const
calculates the zoom factor.
void alignMarkedObjects(ControlModification _nControlModification, bool _bAlignAtSection)
align all marked objects in all sections
sal_Int32 GetTotalHeight() const
void Paste()
paste a new control in this section
void setDragStripes(bool bOn)
void SetMargin1()
void Copy()
copies the current selection in this section
sal_Int32 impl_getRealPixelWidth() const
void unmarkAllObjects()
unmark all objects on the views without the given one.
ODesignView * getReportView() const
void SetInsertObj(SdrObjKind eObj, const OUString &_sShapeType)
Point getThumbPos() const
::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 handleKeyEvent(const KeyEvent &_rEvent)
checks if the keycode is known by the child windows
void showProperties(const css::uno::Reference< css::report::XSection > &_xReportComponent)
triggers the property browser with the report component or section
void SetNullOffset(tools::Long nPos)
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
sal_uInt32 getMarkedObjectCount() const
#define UID_RPT_REPORTWINDOW
Definition: helpids.h:29
tools::Long const nRightMargin
void addSection(const css::uno::Reference< css::report::XSection > &_xSection, const OUString &_sColorEntry, sal_uInt16 _nPosition)
adds a new section at position _nPosition.
OSectionWindow * getMarkedSection(NearSectionAccess nsa=CURRENT) const override
returns the section which is currently marked.
const Point & GetOrigin() const
virtual void Resize() override
Size GetOutputSizePixel() const
void SetBorders(sal_uInt32 n=0, const RulerBorder *pBrdAry=nullptr)
SvxZoomType
void SetMapMode()
virtual void dispose() override
virtual void markSection(const sal_uInt16 _nPos) override
mark the section on the given position .
OReportController & getController() const
Definition: DesignView.hxx:97
void SetMode(DlgEdMode m_eMode)
const css::uno::Reference< css::report::XReportDefinition > & getReportDefinition() const
gives access to the report definition
void SetPagePos(tools::Long nOff=0, tools::Long nWidth=0)
MeasurementSystem getMeasurementSystemEnum() const
OSectionView & getSectionView() const
void removeSection(sal_uInt16 _nPosition)
removes the section at the given position.