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 "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 <tools/debug.hxx>
27 : #include <svtools/colorcfg.hxx>
28 : #include <svl/itempool.hxx>
29 : #include <unotools/syslocale.hxx>
30 :
31 : #include <vcl/settings.hxx>
32 :
33 : #include "RptDef.hxx"
34 : #include "dlgedfunc.hxx"
35 : #include "RptModel.hxx"
36 : #include "uistrings.hrc"
37 : #include "RptPage.hxx"
38 : #include "ReportController.hxx"
39 : #include "EndMarker.hxx"
40 : #include "ColorChanger.hxx"
41 : #include "ScrollHelper.hxx"
42 :
43 : #include "helpids.hrc"
44 : #include "dlgedfac.hxx"
45 : #include <boost/shared_ptr.hpp>
46 : #include <toolkit/helper/vclunohelper.hxx>
47 :
48 :
49 : #define SECTION_OFFSET 3
50 : namespace rptui
51 : {
52 : using namespace ::com::sun::star;
53 : using namespace ::comphelper;
54 :
55 : // class OReportWindow
56 :
57 :
58 0 : OReportWindow::OReportWindow(OScrollWindowHelper* _pParent,ODesignView* _pView)
59 : : Window(_pParent,WB_DIALOGCONTROL)
60 : , ::comphelper::OPropertyChangeListener(m_aMutex)
61 : ,m_aHRuler(VclPtr<Ruler>::Create(this))
62 : ,m_pView(_pView)
63 : ,m_pParent(_pParent)
64 : ,m_aViewsWindow(VclPtr<rptui::OViewsWindow>::Create(this))
65 0 : ,m_pObjFac( new DlgEdFactory() )
66 : {
67 0 : SetHelpId(UID_RPT_REPORTWINDOW);
68 0 : SetMapMode( MapMode( MAP_100TH_MM ) );
69 :
70 0 : m_aViewsWindow->Show();
71 :
72 0 : m_aHRuler->Show();
73 0 : m_aHRuler->Activate();
74 0 : m_aHRuler->SetPagePos(0);
75 0 : m_aHRuler->SetBorders();
76 0 : m_aHRuler->SetIndents();
77 0 : m_aHRuler->SetMargin1();
78 0 : m_aHRuler->SetMargin2();
79 0 : const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
80 0 : m_aHRuler->SetUnit(MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH);
81 :
82 0 : ImplInitSettings();
83 0 : m_pReportListener = addStyleListener(_pView->getController().getReportDefinition(),this);
84 0 : }
85 :
86 0 : OReportWindow::~OReportWindow()
87 : {
88 0 : disposeOnce();
89 0 : }
90 :
91 0 : void OReportWindow::dispose()
92 : {
93 0 : if ( m_pReportListener.is() )
94 0 : m_pReportListener->dispose();
95 0 : m_aHRuler.disposeAndClear();
96 0 : m_aViewsWindow.disposeAndClear();
97 0 : m_pView.clear();
98 0 : m_pParent.clear();
99 0 : vcl::Window::dispose();
100 0 : }
101 :
102 0 : void OReportWindow::SetInsertObj( sal_uInt16 eObj,const OUString& _sShapeType )
103 : {
104 0 : m_aViewsWindow->SetInsertObj( eObj,_sShapeType);
105 0 : }
106 :
107 0 : OUString OReportWindow::GetInsertObjString() const
108 : {
109 0 : return m_aViewsWindow->GetInsertObjString();
110 : }
111 :
112 0 : void OReportWindow::SetMode( DlgEdMode eNewMode )
113 : {
114 0 : m_aViewsWindow->SetMode(eNewMode);
115 0 : }
116 :
117 0 : void OReportWindow::removeSection(sal_uInt16 _nPosition)
118 : {
119 0 : m_aViewsWindow->removeSection(_nPosition);
120 0 : m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
121 0 : m_aViewsWindow->Invalidate(InvalidateFlags::Transparent);
122 0 : }
123 :
124 0 : void OReportWindow::addSection(const uno::Reference< report::XSection >& _xSection,const OUString& _sColorEntry,sal_uInt16 _nPosition)
125 : {
126 0 : if ( !_xSection.is() )
127 0 : return;
128 :
129 0 : m_aViewsWindow->addSection(_xSection,_sColorEntry,_nPosition);
130 :
131 0 : m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
132 : }
133 :
134 0 : void OReportWindow::toggleGrid(bool _bVisible)
135 : {
136 0 : m_aViewsWindow->toggleGrid(_bVisible);
137 0 : }
138 :
139 0 : void OReportWindow::showRuler(bool _bShow)
140 : {
141 0 : m_aHRuler->Show(_bShow);
142 :
143 0 : m_aViewsWindow->showRuler(_bShow);
144 0 : }
145 :
146 0 : sal_Int32 OReportWindow::getMaxMarkerWidth(bool _bWithEnd) const
147 : {
148 0 : Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
149 0 : aStartWidth *= m_aViewsWindow->GetMapMode().GetScaleX();
150 0 : if ( _bWithEnd )
151 0 : aStartWidth += Fraction(long(REPORT_ENDMARKER_WIDTH));
152 0 : return sal_Int32((long)aStartWidth);
153 : }
154 :
155 0 : sal_Int32 OReportWindow::GetTotalWidth() const
156 : {
157 0 : sal_Int32 nWidth = 0;
158 0 : if ( !m_aViewsWindow->empty() )
159 : {
160 0 : Fraction aStartWidth(long(REPORT_ENDMARKER_WIDTH + REPORT_STARTMARKER_WIDTH ));
161 0 : const Fraction aZoom(m_pView->getController().getZoomValue(),100);
162 0 : aStartWidth *= aZoom;
163 0 : const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
164 0 : Fraction aPaperWidth(nPaperWidth,1);
165 0 : aPaperWidth *= aZoom;
166 0 : const Size aPageSize = LogicToPixel(Size(aPaperWidth,0));
167 0 : nWidth = aPageSize.Width() + long(aStartWidth);
168 : }
169 0 : return nWidth;
170 : }
171 :
172 0 : void OReportWindow::Resize()
173 : {
174 0 : Window::Resize();
175 0 : if ( !m_aViewsWindow->empty() )
176 : {
177 0 : const Size aTotalOutputSize = GetOutputSizePixel();
178 0 : Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH)*m_pView->getController().getZoomValue(),100);
179 :
180 0 : const Point aOffset = LogicToPixel( Point( SECTION_OFFSET, 0 ), MAP_APPFONT );
181 0 : Point aStartPoint((long)aStartWidth + aOffset.X(),0);
182 0 : uno::Reference<report::XReportDefinition> xReportDefinition = getReportView()->getController().getReportDefinition();
183 0 : const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
184 0 : sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
185 0 : sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
186 0 : Size aPageSize = m_aViewsWindow->LogicToPixel(Size(nPaperWidth ,0));
187 0 : nLeftMargin = m_aViewsWindow->LogicToPixel(Size(nLeftMargin,0)).Width();
188 0 : nRightMargin = m_aViewsWindow->LogicToPixel(Size(nRightMargin,0)).Width();
189 :
190 0 : aPageSize.Height() = m_aHRuler->GetSizePixel().Height();
191 :
192 0 : const long nTermp(m_aViewsWindow->getTotalHeight() + aPageSize.Height());
193 0 : long nSectionsHeight = ::std::max<long>(nTermp,aTotalOutputSize.Height());
194 :
195 0 : m_aHRuler->SetPosSizePixel(aStartPoint,aPageSize);
196 0 : m_aHRuler->SetNullOffset(nLeftMargin);
197 0 : m_aHRuler->SetMargin1(0);
198 0 : m_aHRuler->SetMargin2(aPageSize.Width() - nLeftMargin - nRightMargin);
199 :
200 0 : aStartPoint.Y() += aPageSize.Height();
201 0 : nSectionsHeight -= aStartPoint.Y();
202 :
203 0 : aStartPoint.X() = aOffset.X();
204 :
205 0 : m_aViewsWindow->SetPosSizePixel(aStartPoint,Size(aTotalOutputSize.Width(),nSectionsHeight));
206 : }
207 0 : }
208 :
209 0 : Point OReportWindow::getThumbPos() const
210 : {
211 0 : return m_pParent->getThumbPos();
212 : }
213 :
214 0 : void OReportWindow::ImplInitSettings()
215 : {
216 0 : SetBackground( );
217 0 : }
218 :
219 0 : void OReportWindow::DataChanged( const DataChangedEvent& rDCEvt )
220 : {
221 0 : Window::DataChanged( rDCEvt );
222 :
223 0 : if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
224 0 : (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
225 : {
226 0 : ImplInitSettings();
227 0 : Invalidate();
228 : }
229 0 : }
230 :
231 0 : sal_Int32 OReportWindow::GetTotalHeight() const
232 : {
233 0 : return m_aViewsWindow->getTotalHeight();
234 : }
235 :
236 0 : void OReportWindow::ScrollChildren(const Point& _aThumbPos)
237 : {
238 0 : MapMode aMap = m_aHRuler->GetMapMode();
239 0 : Point aOrg( aMap.GetOrigin() );
240 0 : if ( aOrg.X() != (-_aThumbPos.X()) )
241 : {
242 0 : aMap.SetOrigin( Point(- _aThumbPos.X(), aOrg.Y()));
243 0 : m_aHRuler->SetMapMode( aMap );
244 0 : m_aHRuler->Scroll(-(aOrg.X() + _aThumbPos.X()),0);
245 : }
246 :
247 0 : m_aViewsWindow->scrollChildren(_aThumbPos);
248 0 : }
249 :
250 0 : sal_uInt16 OReportWindow::getSectionCount() const
251 : {
252 0 : return m_aViewsWindow->getSectionCount();
253 : }
254 :
255 0 : void OReportWindow::notifySizeChanged()
256 : {
257 0 : m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
258 0 : }
259 :
260 0 : bool OReportWindow::HasSelection() const
261 : {
262 0 : return m_aViewsWindow->HasSelection();
263 : }
264 :
265 0 : void OReportWindow::Delete()
266 : {
267 :
268 0 : m_aViewsWindow->Delete();
269 0 : }
270 :
271 0 : void OReportWindow::Copy()
272 : {
273 :
274 0 : m_aViewsWindow->Copy();
275 0 : }
276 :
277 0 : void OReportWindow::Paste()
278 : {
279 :
280 0 : m_aViewsWindow->Paste();
281 0 : }
282 :
283 0 : bool OReportWindow::IsPasteAllowed() const
284 : {
285 0 : return m_aViewsWindow->IsPasteAllowed();
286 : }
287 :
288 0 : void OReportWindow::SelectAll(const sal_uInt16 _nObjectType)
289 : {
290 :
291 0 : m_aViewsWindow->SelectAll(_nObjectType);
292 0 : }
293 :
294 0 : void OReportWindow::unmarkAllObjects(OSectionView* _pSectionView)
295 : {
296 :
297 0 : m_aViewsWindow->unmarkAllObjects(_pSectionView);
298 0 : }
299 :
300 0 : void OReportWindow::showProperties(const uno::Reference< report::XSection>& _xReportComponent)
301 : {
302 0 : OSectionWindow* pSectionWindow = m_aViewsWindow->getSectionWindow( _xReportComponent );
303 0 : m_pView->UpdatePropertyBrowserDelayed(pSectionWindow->getReportSection().getSectionView());
304 0 : }
305 :
306 0 : bool OReportWindow::handleKeyEvent(const KeyEvent& _rEvent)
307 : {
308 0 : return m_aViewsWindow->handleKeyEvent(_rEvent);
309 : }
310 :
311 0 : void OReportWindow::setMarked(OSectionView* _pSectionView, bool _bMark)
312 : {
313 0 : if ( _pSectionView )
314 0 : m_aViewsWindow->setMarked(_pSectionView,_bMark);
315 0 : }
316 :
317 0 : void OReportWindow::setMarked(const uno::Reference< report::XSection>& _xSection, bool _bMark)
318 : {
319 :
320 0 : m_aViewsWindow->setMarked(_xSection,_bMark);
321 0 : }
322 :
323 0 : void OReportWindow::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape, bool _bMark)
324 : {
325 :
326 0 : m_aViewsWindow->setMarked(_xShape,_bMark);
327 0 : }
328 :
329 0 : OSectionWindow* OReportWindow::getMarkedSection(NearSectionAccess nsa) const
330 : {
331 0 : return m_aViewsWindow->getMarkedSection(nsa);
332 : }
333 :
334 0 : OSectionWindow* OReportWindow::getSectionWindow(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection) const
335 : {
336 0 : return m_aViewsWindow->getSectionWindow(_xSection);
337 : }
338 :
339 0 : void OReportWindow::markSection(const sal_uInt16 _nPos)
340 : {
341 :
342 0 : m_aViewsWindow->markSection(_nPos);
343 0 : }
344 :
345 0 : void OReportWindow::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
346 : {
347 :
348 0 : m_aViewsWindow->fillCollapsedSections(_rCollapsedPositions);
349 0 : }
350 :
351 0 : void OReportWindow::collapseSections(const uno::Sequence< ::com::sun::star::beans::PropertyValue>& _aCollpasedSections)
352 : {
353 :
354 0 : m_aViewsWindow->collapseSections(_aCollpasedSections);
355 0 : }
356 :
357 0 : void OReportWindow::alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool bBoundRects)
358 : {
359 :
360 0 : m_aViewsWindow->alignMarkedObjects(_nControlModification, _bAlignAtSection, bBoundRects);
361 0 : }
362 :
363 0 : void OReportWindow::setGridSnap(bool bOn)
364 : {
365 :
366 0 : m_aViewsWindow->setGridSnap(bOn);
367 0 : }
368 :
369 0 : void OReportWindow::setDragStripes(bool bOn)
370 : {
371 0 : m_aViewsWindow->setDragStripes(bOn);
372 0 : }
373 :
374 0 : sal_uInt32 OReportWindow::getMarkedObjectCount() const
375 : {
376 0 : return m_aViewsWindow->getMarkedObjectCount();
377 : }
378 :
379 0 : void OReportWindow::zoom(const Fraction& _aZoom)
380 : {
381 0 : m_aHRuler->SetZoom(_aZoom);
382 0 : m_aHRuler->Invalidate();
383 :
384 0 : m_aViewsWindow->zoom(_aZoom);
385 :
386 0 : notifySizeChanged();
387 0 : const Point aNewThumbPos( m_pParent->getThumbPos() );
388 :
389 0 : ScrollChildren( aNewThumbPos );
390 0 : Resize();
391 :
392 0 : Invalidate(InvalidateFlags::NoErase | InvalidateFlags::NoChildren | InvalidateFlags::Transparent);
393 0 : }
394 :
395 0 : void OReportWindow::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
396 : {
397 0 : m_aViewsWindow->fillControlModelSelection(_rSelection);
398 0 : }
399 :
400 0 : sal_Int32 OReportWindow::impl_getRealPixelWidth() const
401 : {
402 0 : const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
403 0 : MapMode aMap( MAP_100TH_MM );
404 0 : const Size aPageSize = LogicToPixel(Size(nPaperWidth,0),aMap);
405 0 : return aPageSize.Width() + REPORT_ENDMARKER_WIDTH + REPORT_STARTMARKER_WIDTH + SECTION_OFFSET;
406 : }
407 :
408 0 : sal_uInt16 OReportWindow::getZoomFactor(SvxZoomType _eType) const
409 : {
410 0 : sal_uInt16 nZoom(100);
411 0 : const Size aSize( GetSizePixel() );
412 0 : switch( _eType)
413 : {
414 : case SvxZoomType::PERCENT:
415 0 : nZoom = m_pView->getController().getZoomValue();
416 0 : break;
417 : case SvxZoomType::OPTIMAL:
418 0 : break;
419 : case SvxZoomType::WHOLEPAGE:
420 : {
421 0 : nZoom = (sal_uInt16)(long)Fraction(aSize.Width()*100,impl_getRealPixelWidth());
422 0 : MapMode aMap( MAP_100TH_MM );
423 0 : const Size aHeight = m_aViewsWindow->LogicToPixel(m_aViewsWindow->PixelToLogic(Size(0,GetTotalHeight() + m_aHRuler->GetSizePixel().Height())),aMap);
424 0 : nZoom = ::std::min(nZoom,(sal_uInt16)(long)Fraction(aSize.Height()*100,aHeight.Height()));
425 : }
426 0 : break;
427 : case SvxZoomType::PAGEWIDTH:
428 0 : nZoom = (sal_uInt16)(long)Fraction(aSize.Width()*100,impl_getRealPixelWidth());
429 0 : break;
430 : default:
431 0 : break;
432 : }
433 :
434 0 : return nZoom;
435 : }
436 :
437 0 : void OReportWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
438 : {
439 : (void)_rEvent;
440 0 : Resize();
441 0 : m_aViewsWindow->Resize();
442 0 : Invalidate(InvalidateFlags::Transparent);
443 0 : }
444 :
445 3 : } //rptui
446 :
447 :
448 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|