1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #include "precompiled_reportdesign.hxx"
24 #include "ReportWindow.hxx"
25 #include "ReportSection.hxx"
26 #include "SectionView.hxx"
27 #include "ViewsWindow.hxx"
28 #include "ReportRuler.hxx"
29 #include "DesignView.hxx"
30 #include "UITools.hxx"
31
32 #include <tools/debug.hxx>
33 #include <svtools/colorcfg.hxx>
34 #include <svl/itempool.hxx>
35 #include <unotools/syslocale.hxx>
36
37 #include "RptDef.hxx"
38 #include "dlgedfunc.hxx"
39 #include "RptModel.hxx"
40 #include "uistrings.hrc"
41 #include "RptPage.hxx"
42 #include "ReportController.hxx"
43 #include "EndMarker.hxx"
44 #include "ColorChanger.hxx"
45 #include "ScrollHelper.hxx"
46
47 #include "helpids.hrc"
48 #include "dlgedfac.hxx"
49 #include <boost/bind.hpp>
50 #include <toolkit/helper/vclunohelper.hxx>
51
52
53 #define SECTION_OFFSET 3
54 namespace rptui
55 {
56 using namespace ::com::sun::star;
57 using namespace ::comphelper;
58 //==================================================================
59 // class OReportWindow
60 //==================================================================
DBG_NAME(rpt_OReportWindow)61 DBG_NAME( rpt_OReportWindow )
62 //------------------------------------------------------------------------------
63 OReportWindow::OReportWindow(OScrollWindowHelper* _pParent,ODesignView* _pView)
64 : Window(_pParent,WB_DIALOGCONTROL)
65 , ::comphelper::OPropertyChangeListener(m_aMutex)
66 ,m_aHRuler(this)
67 ,m_pView(_pView)
68 ,m_pParent(_pParent)
69 ,m_aViewsWindow(this)
70 ,m_pObjFac( new DlgEdFactory() )
71 {
72 DBG_CTOR( rpt_OReportWindow,NULL);
73 SetHelpId(UID_RPT_REPORTWINDOW);
74 SetMapMode( MapMode( MAP_100TH_MM ) );
75
76 m_aViewsWindow.Show();
77
78 m_aHRuler.Show();
79 m_aHRuler.Activate();
80 m_aHRuler.SetPagePos(0);
81 m_aHRuler.SetBorders();
82 m_aHRuler.SetIndents();
83 m_aHRuler.SetMargin1();
84 m_aHRuler.SetMargin2();
85 const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
86 m_aHRuler.SetUnit(MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH);
87
88 ImplInitSettings();
89 m_pReportListener = addStyleListener(_pView->getController().getReportDefinition(),this);
90 }
91 //------------------------------------------------------------------------------
~OReportWindow()92 OReportWindow::~OReportWindow()
93 {
94 DBG_DTOR( rpt_OReportWindow,NULL);
95 if ( m_pReportListener.is() )
96 m_pReportListener->dispose();
97 }
98 // -----------------------------------------------------------------------------
initialize()99 void OReportWindow::initialize()
100 {
101 m_aViewsWindow.initialize();
102 }
103 //----------------------------------------------------------------------------
SetInsertObj(sal_uInt16 eObj,const::rtl::OUString & _sShapeType)104 void OReportWindow::SetInsertObj( sal_uInt16 eObj,const ::rtl::OUString& _sShapeType )
105 {
106 m_aViewsWindow.SetInsertObj( eObj,_sShapeType);
107 }
108
109 //----------------------------------------------------------------------------
GetInsertObjString() const110 rtl::OUString OReportWindow::GetInsertObjString() const
111 {
112 return m_aViewsWindow.GetInsertObjString();
113 }
114 //------------------------------------------------------------------------------
SetMode(DlgEdMode eNewMode)115 void OReportWindow::SetMode( DlgEdMode eNewMode )
116 {
117 m_aViewsWindow.SetMode(eNewMode);
118 }
119 //----------------------------------------------------------------------------
removeSection(sal_uInt16 _nPosition)120 void OReportWindow::removeSection(sal_uInt16 _nPosition)
121 {
122 m_aViewsWindow.removeSection(_nPosition);
123 m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
124 m_aViewsWindow.Invalidate(INVALIDATE_TRANSPARENT);
125 //Resize();
126 }
127 //----------------------------------------------------------------------------
addSection(const uno::Reference<report::XSection> & _xSection,const::rtl::OUString & _sColorEntry,sal_uInt16 _nPosition)128 void OReportWindow::addSection(const uno::Reference< report::XSection >& _xSection,const ::rtl::OUString& _sColorEntry,sal_uInt16 _nPosition)
129 {
130 if ( !_xSection.is() )
131 return;
132
133 m_aViewsWindow.addSection(_xSection,_sColorEntry,_nPosition);
134
135 m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
136 }
137 //------------------------------------------------------------------------------
toggleGrid(sal_Bool _bVisible)138 void OReportWindow::toggleGrid(sal_Bool _bVisible)
139 {
140 m_aViewsWindow.toggleGrid(_bVisible);
141 }
142 //----------------------------------------------------------------------------
showRuler(sal_Bool _bShow)143 void OReportWindow::showRuler(sal_Bool _bShow)
144 {
145 m_aHRuler.Show(_bShow);
146
147 m_aViewsWindow.showRuler(_bShow);
148 }
149 //------------------------------------------------------------------------------
getMaxMarkerWidth(sal_Bool _bWithEnd) const150 sal_Int32 OReportWindow::getMaxMarkerWidth(sal_Bool _bWithEnd) const
151 {
152 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
153 aStartWidth *= m_aViewsWindow.GetMapMode().GetScaleX();
154 if ( _bWithEnd )
155 aStartWidth += Fraction(long(REPORT_ENDMARKER_WIDTH));
156 return sal_Int32((long)aStartWidth);
157 }
158 //------------------------------------------------------------------------------
GetTotalWidth() const159 sal_Int32 OReportWindow::GetTotalWidth() const
160 {
161 sal_Int32 nWidth = 0;
162 if ( !m_aViewsWindow.empty() )
163 {
164 Fraction aStartWidth(long(REPORT_ENDMARKER_WIDTH + REPORT_STARTMARKER_WIDTH ));
165 const Fraction aZoom(m_pView->getController().getZoomValue(),100);
166 aStartWidth *= aZoom; // m_aViewsWindow.GetMapMode().GetScaleX();;
167 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
168 Fraction aPaperWidth(nPaperWidth,1);
169 aPaperWidth *= aZoom;
170 const Size aPageSize = LogicToPixel(Size(aPaperWidth,0));
171 nWidth = aPageSize.Width() + long(aStartWidth);
172 }
173 return nWidth;
174 }
175 //------------------------------------------------------------------------------
Resize()176 void OReportWindow::Resize()
177 {
178 Window::Resize();
179 if ( !m_aViewsWindow.empty() )
180 {
181 const Size aTotalOutputSize = GetOutputSizePixel();
182 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH)*m_pView->getController().getZoomValue(),100);
183
184 const Point aOffset = LogicToPixel( Point( SECTION_OFFSET, 0 ), MAP_APPFONT );
185 Point aStartPoint((long)aStartWidth + aOffset.X(),0);
186 uno::Reference<report::XReportDefinition> xReportDefinition = getReportView()->getController().getReportDefinition();
187 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
188 sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
189 sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
190 Size aPageSize = m_aViewsWindow.LogicToPixel(Size(nPaperWidth ,0));
191 nLeftMargin = m_aViewsWindow.LogicToPixel(Size(nLeftMargin,0)).Width();
192 nRightMargin = m_aViewsWindow.LogicToPixel(Size(nRightMargin,0)).Width();
193
194 aPageSize.Height() = m_aHRuler.GetSizePixel().Height();
195
196 const long nTermp(m_aViewsWindow.getTotalHeight() + aPageSize.Height());
197 long nSectionsHeight = ::std::max<long>(nTermp,aTotalOutputSize.Height());
198
199 m_aHRuler.SetPosSizePixel(aStartPoint,aPageSize);
200 m_aHRuler.SetNullOffset(nLeftMargin);
201 m_aHRuler.SetMargin1(0);
202 m_aHRuler.SetMargin2(aPageSize.Width() - nLeftMargin - nRightMargin);
203
204 aStartPoint.Y() += aPageSize.Height();
205 nSectionsHeight -= aStartPoint.Y();
206
207 aStartPoint.X() = aOffset.X();
208
209 m_aViewsWindow.SetPosSizePixel(aStartPoint,Size(aTotalOutputSize.Width(),nSectionsHeight));
210 }
211 }
212 //------------------------------------------------------------------------------
getThumbPos() const213 Point OReportWindow::getThumbPos() const
214 {
215 return m_pParent->getThumbPos();
216 }
217 //------------------------------------------------------------------------------
ImplInitSettings()218 void OReportWindow::ImplInitSettings()
219 {
220 SetBackground( );
221 }
222 //-----------------------------------------------------------------------------
DataChanged(const DataChangedEvent & rDCEvt)223 void OReportWindow::DataChanged( const DataChangedEvent& rDCEvt )
224 {
225 Window::DataChanged( rDCEvt );
226
227 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
228 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
229 {
230 ImplInitSettings();
231 Invalidate();
232 }
233 }
234 //------------------------------------------------------------------------------
GetTotalHeight() const235 sal_Int32 OReportWindow::GetTotalHeight() const
236 {
237 return m_aViewsWindow.getTotalHeight();
238 }
239 //------------------------------------------------------------------------------
ScrollChildren(const Point & _aThumbPos)240 void OReportWindow::ScrollChildren(const Point& _aThumbPos)
241 {
242 MapMode aMap = m_aHRuler.GetMapMode();
243 Point aOrg( aMap.GetOrigin() );
244 if ( aOrg.X() != (-_aThumbPos.X()) )
245 {
246 aMap.SetOrigin( Point(- _aThumbPos.X(), aOrg.Y()));
247 m_aHRuler.SetMapMode( aMap );
248 m_aHRuler.Scroll(-(aOrg.X() + _aThumbPos.X()),0);
249 }
250
251 /*const Point aPos(PixelToLogic(_aThumbPos));*/
252 m_aViewsWindow.scrollChildren(_aThumbPos);
253 }
254 //----------------------------------------------------------------------------
getSectionCount() const255 sal_uInt16 OReportWindow::getSectionCount() const
256 {
257 return m_aViewsWindow.getSectionCount();
258 }
259 //----------------------------------------------------------------------------
notifySizeChanged()260 void OReportWindow::notifySizeChanged()
261 {
262 m_pParent->setTotalSize(GetTotalWidth(),GetTotalHeight());
263 }
264 //----------------------------------------------------------------------------
HasSelection() const265 sal_Bool OReportWindow::HasSelection() const
266 {
267 return m_aViewsWindow.HasSelection();
268 }
269 //----------------------------------------------------------------------------
Delete()270 void OReportWindow::Delete()
271 {
272
273 m_aViewsWindow.Delete();
274 }
275 //----------------------------------------------------------------------------
Copy()276 void OReportWindow::Copy()
277 {
278
279 m_aViewsWindow.Copy();
280 }
281 //----------------------------------------------------------------------------
Paste()282 void OReportWindow::Paste()
283 {
284
285 m_aViewsWindow.Paste();
286 }
287 //----------------------------------------------------------------------------
IsPasteAllowed() const288 sal_Bool OReportWindow::IsPasteAllowed() const
289 {
290 return m_aViewsWindow.IsPasteAllowed();
291 }
292 //-----------------------------------------------------------------------------
SelectAll(const sal_uInt16 _nObjectType)293 void OReportWindow::SelectAll(const sal_uInt16 _nObjectType)
294 {
295
296 m_aViewsWindow.SelectAll(_nObjectType);
297 }
298 //-----------------------------------------------------------------------------
unmarkAllObjects(OSectionView * _pSectionView)299 void OReportWindow::unmarkAllObjects(OSectionView* _pSectionView)
300 {
301
302 m_aViewsWindow.unmarkAllObjects(_pSectionView);
303 }
304 //-----------------------------------------------------------------------------
showProperties(const uno::Reference<report::XSection> & _xReportComponent)305 void OReportWindow::showProperties(const uno::Reference< report::XSection>& _xReportComponent)
306 {
307 ::boost::shared_ptr<OSectionWindow> pSectionWindow = m_aViewsWindow.getSectionWindow( _xReportComponent );
308 m_pView->UpdatePropertyBrowserDelayed(pSectionWindow->getReportSection().getSectionView());
309 }
310 //------------------------------------------------------------------------------
handleKeyEvent(const KeyEvent & _rEvent)311 sal_Bool OReportWindow::handleKeyEvent(const KeyEvent& _rEvent)
312 {
313 return m_aViewsWindow.handleKeyEvent(_rEvent);
314 }
315 //------------------------------------------------------------------------
setMarked(OSectionView * _pSectionView,sal_Bool _bMark)316 void OReportWindow::setMarked(OSectionView* _pSectionView,sal_Bool _bMark)
317 {
318 if ( _pSectionView )
319 m_aViewsWindow.setMarked(_pSectionView,_bMark);
320 }
321 //------------------------------------------------------------------------
setMarked(const uno::Reference<report::XSection> & _xSection,sal_Bool _bMark)322 void OReportWindow::setMarked(const uno::Reference< report::XSection>& _xSection,sal_Bool _bMark)
323 {
324
325 m_aViewsWindow.setMarked(_xSection,_bMark);
326 }
327 //------------------------------------------------------------------------
setMarked(const uno::Sequence<uno::Reference<report::XReportComponent>> & _xShape,sal_Bool _bMark)328 void OReportWindow::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape,sal_Bool _bMark)
329 {
330
331 m_aViewsWindow.setMarked(_xShape,_bMark);
332 }
333 //-----------------------------------------------------------------------------
getMarkedSection(NearSectionAccess nsa) const334 ::boost::shared_ptr<OSectionWindow> OReportWindow::getMarkedSection(NearSectionAccess nsa) const
335 {
336 return m_aViewsWindow.getMarkedSection(nsa);
337 }
338 //-----------------------------------------------------------------------------
getSectionWindow(const::com::sun::star::uno::Reference<::com::sun::star::report::XSection> & _xSection) const339 ::boost::shared_ptr<OSectionWindow> OReportWindow::getSectionWindow(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection) const
340 {
341 return m_aViewsWindow.getSectionWindow(_xSection);
342 }
343 // -------------------------------------------------------------------------
markSection(const sal_uInt16 _nPos)344 void OReportWindow::markSection(const sal_uInt16 _nPos)
345 {
346
347 m_aViewsWindow.markSection(_nPos);
348 }
349 // -----------------------------------------------------------------------------
fillCollapsedSections(::std::vector<sal_uInt16> & _rCollapsedPositions) const350 void OReportWindow::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
351 {
352
353 m_aViewsWindow.fillCollapsedSections(_rCollapsedPositions);
354 }
355 // -----------------------------------------------------------------------------
collapseSections(const uno::Sequence<::com::sun::star::beans::PropertyValue> & _aCollpasedSections)356 void OReportWindow::collapseSections(const uno::Sequence< ::com::sun::star::beans::PropertyValue>& _aCollpasedSections)
357 {
358
359 m_aViewsWindow.collapseSections(_aCollpasedSections);
360 }
361 // -----------------------------------------------------------------------------
alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection,bool bBoundRects)362 void OReportWindow::alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool bBoundRects)
363 {
364
365 m_aViewsWindow.alignMarkedObjects(_nControlModification, _bAlignAtSection, bBoundRects);
366 }
367 // -----------------------------------------------------------------------------
setGridSnap(sal_Bool bOn)368 void OReportWindow::setGridSnap(sal_Bool bOn)
369 {
370
371 m_aViewsWindow.setGridSnap(bOn);
372 }
373 // -----------------------------------------------------------------------------
setDragStripes(sal_Bool bOn)374 void OReportWindow::setDragStripes(sal_Bool bOn)
375 {
376 m_aViewsWindow.setDragStripes(bOn);
377 }
378 // -----------------------------------------------------------------------------
getMarkedObjectCount() const379 sal_uInt32 OReportWindow::getMarkedObjectCount() const
380 {
381 return m_aViewsWindow.getMarkedObjectCount();
382 }
383 // -----------------------------------------------------------------------------
zoom(const Fraction & _aZoom)384 void OReportWindow::zoom(const Fraction& _aZoom)
385 {
386 m_aHRuler.SetZoom(_aZoom);
387 m_aHRuler.Invalidate();
388
389 //setZoomFactor(_aZoom,*this); // if this will be include the H - ruler has the wrong size
390 m_aViewsWindow.zoom(_aZoom);
391
392 notifySizeChanged();
393 const Point aNewThumbPos( m_pParent->getThumbPos() );
394
395 ScrollChildren( aNewThumbPos );
396 Resize();
397
398 Invalidate(INVALIDATE_NOERASE | INVALIDATE_NOCHILDREN | INVALIDATE_TRANSPARENT);
399 }
400 // -----------------------------------------------------------------------------
fillControlModelSelection(::std::vector<uno::Reference<uno::XInterface>> & _rSelection) const401 void OReportWindow::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
402 {
403 m_aViewsWindow.fillControlModelSelection(_rSelection);
404 }
405 // -----------------------------------------------------------------------------
impl_getRealPixelWidth() const406 sal_Int32 OReportWindow::impl_getRealPixelWidth() const
407 {
408 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_pView->getController().getReportDefinition(),PROPERTY_PAPERSIZE).Width;
409 MapMode aMap( MAP_100TH_MM );
410 const Size aPageSize = LogicToPixel(Size(nPaperWidth,0),aMap);
411 return aPageSize.Width() + REPORT_ENDMARKER_WIDTH + REPORT_STARTMARKER_WIDTH + SECTION_OFFSET;
412 }
413 // -----------------------------------------------------------------------------
getZoomFactor(SvxZoomType _eType) const414 sal_uInt16 OReportWindow::getZoomFactor(SvxZoomType _eType) const
415 {
416 sal_uInt16 nZoom(100);
417 const Size aSize( GetSizePixel() );
418 switch( _eType)
419 {
420 case SVX_ZOOM_PERCENT:
421 nZoom = m_pView->getController().getZoomValue();
422 break;
423 case SVX_ZOOM_OPTIMAL:
424 break;
425 case SVX_ZOOM_WHOLEPAGE:
426 {
427 nZoom = (sal_uInt16)(long)Fraction(aSize.Width()*100,impl_getRealPixelWidth());
428 MapMode aMap( MAP_100TH_MM );
429 const Size aHeight = m_aViewsWindow.LogicToPixel(m_aViewsWindow.PixelToLogic(Size(0,GetTotalHeight() + m_aHRuler.GetSizePixel().Height())),aMap);
430 nZoom = ::std::min(nZoom,(sal_uInt16)(long)Fraction(aSize.Height()*100,aHeight.Height()));
431 }
432 break;
433 case SVX_ZOOM_PAGEWIDTH:
434 nZoom = (sal_uInt16)(long)Fraction(aSize.Width()*100,impl_getRealPixelWidth());
435 break;
436 default:
437 break;
438 }
439
440 return nZoom;
441 }
442 // -----------------------------------------------------------------------------
_propertyChanged(const beans::PropertyChangeEvent & _rEvent)443 void OReportWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
444 {
445 (void)_rEvent;
446 Resize();
447 m_aViewsWindow.Resize();
448 static sal_Int32 nIn = INVALIDATE_TRANSPARENT;
449 Invalidate(nIn);
450 }
451 //==================================================================
452 } //rptui
453 //==================================================================
454
455