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 "SectionWindow.hxx"
20 : #include "ReportWindow.hxx"
21 : #include "ReportRuler.hxx"
22 : #include "rptui_slotid.hrc"
23 : #include "ReportController.hxx"
24 : #include "SectionView.hxx"
25 : #include "RptDef.hxx"
26 : #include "ReportSection.hxx"
27 : #include "DesignView.hxx"
28 : #include "uistrings.hrc"
29 : #include "helpids.hrc"
30 : #include "RptResId.hrc"
31 : #include "StartMarker.hxx"
32 : #include "EndMarker.hxx"
33 : #include "ViewsWindow.hxx"
34 :
35 : #include <svtools/colorcfg.hxx>
36 : #include <functional>
37 : #include <algorithm>
38 : #include <vcl/svapp.hxx>
39 : #include <connectivity/dbtools.hxx>
40 :
41 : namespace rptui
42 : {
43 : using namespace ::com::sun::star;
44 : using namespace ::comphelper;
45 :
46 : DBG_NAME( rpt_OSectionWindow )
47 0 : OSectionWindow::OSectionWindow( OViewsWindow* _pParent,const uno::Reference< report::XSection >& _xSection,const OUString& _sColorEntry)
48 : : Window( _pParent,WB_DIALOGCONTROL)
49 : ,OPropertyChangeListener(m_aMutex)
50 : ,m_pParent(_pParent)
51 : ,m_aStartMarker( this,_sColorEntry)
52 : ,m_aReportSection( this,_xSection)
53 : ,m_aSplitter(this)
54 0 : ,m_aEndMarker( this,_sColorEntry)
55 : {
56 : DBG_CTOR( rpt_OSectionWindow,NULL);
57 0 : SetUniqueId(UID_RPT_SECTIONSWINDOW);
58 0 : const MapMode& rMapMode = _pParent->GetMapMode();
59 0 : SetMapMode( rMapMode );
60 0 : ImplInitSettings();
61 : // TRY
62 0 : m_aSplitter.SetMapMode( MapMode( MAP_100TH_MM ) );
63 0 : m_aSplitter.SetStartSplitHdl(LINK(this, OSectionWindow,StartSplitHdl));
64 0 : m_aSplitter.SetSplitHdl(LINK(this, OSectionWindow,SplitHdl));
65 0 : m_aSplitter.SetEndSplitHdl(LINK(this, OSectionWindow,EndSplitHdl));
66 0 : m_aSplitter.SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
67 0 : m_aSplitter.SetSplitPosPixel(m_aSplitter.LogicToPixel(Size(0,_xSection->getHeight())).Height());
68 :
69 :
70 0 : m_aStartMarker.setCollapsedHdl(LINK(this,OSectionWindow,Collapsed));
71 :
72 0 : m_aStartMarker.zoom(rMapMode.GetScaleX());
73 0 : setZoomFactor(rMapMode.GetScaleX(),m_aReportSection);
74 0 : setZoomFactor(rMapMode.GetScaleX(),m_aSplitter);
75 0 : setZoomFactor(rMapMode.GetScaleX(),m_aEndMarker);
76 :
77 0 : m_aSplitter.Show();
78 0 : m_aStartMarker.Show();
79 0 : m_aReportSection.Show();
80 0 : m_aEndMarker.Show();
81 0 : Show();
82 :
83 0 : m_pSectionMulti = new OPropertyChangeMultiplexer(this,_xSection.get());
84 0 : m_pSectionMulti->addProperty(PROPERTY_NAME);
85 0 : m_pSectionMulti->addProperty(PROPERTY_HEIGHT);
86 :
87 0 : beans::PropertyChangeEvent aEvent;
88 0 : aEvent.Source = _xSection;
89 0 : aEvent.PropertyName = PROPERTY_NAME;
90 0 : uno::Reference< report::XGroup > xGroup(_xSection->getGroup());
91 0 : if ( xGroup.is() )
92 : {
93 0 : m_pGroupMulti = new OPropertyChangeMultiplexer(this,xGroup.get());
94 0 : m_pGroupMulti->addProperty(PROPERTY_EXPRESSION);
95 0 : aEvent.Source = xGroup;
96 0 : aEvent.PropertyName = PROPERTY_EXPRESSION;
97 : }
98 :
99 0 : _propertyChanged(aEvent);
100 0 : }
101 : // -----------------------------------------------------------------------------
102 0 : OSectionWindow::~OSectionWindow()
103 : {
104 : DBG_DTOR( rpt_OSectionWindow,NULL);
105 : try
106 : {
107 0 : if ( m_pSectionMulti.is() )
108 0 : m_pSectionMulti->dispose();
109 0 : if ( m_pGroupMulti.is() )
110 0 : m_pGroupMulti->dispose();
111 : }
112 0 : catch (uno::Exception&)
113 : {
114 : }
115 0 : }
116 : // -----------------------------------------------------------------------------
117 0 : void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
118 : {
119 0 : SolarMutexGuard g;
120 0 : const uno::Reference< report::XSection > xSection(_rEvent.Source,uno::UNO_QUERY);
121 0 : if ( xSection.is() )
122 : {
123 0 : const uno::Reference< report::XSection> xCurrentSection = m_aReportSection.getSection();
124 0 : if ( _rEvent.PropertyName.equals(PROPERTY_HEIGHT) )
125 : {
126 0 : m_pParent->getView()->SetUpdateMode(sal_False);
127 : //Resize();
128 0 : m_pParent->getView()->notifySizeChanged();
129 0 : m_pParent->resize(*this);
130 0 : m_pParent->getView()->SetUpdateMode(sal_True);
131 : // getViewsWindow()->getView()->getReportView()->getController().resetZoomType();
132 : }
133 0 : else if ( _rEvent.PropertyName.equals(PROPERTY_NAME) && !xSection->getGroup().is() )
134 : {
135 0 : uno::Reference< report::XReportDefinition > xReport = xSection->getReportDefinition();
136 0 : if ( setReportSectionTitle(xReport,RID_STR_REPORT_HEADER,::std::mem_fun(&OReportHelper::getReportHeader),::std::mem_fun(&OReportHelper::getReportHeaderOn))
137 0 : || setReportSectionTitle(xReport,RID_STR_REPORT_FOOTER,::std::mem_fun(&OReportHelper::getReportFooter),::std::mem_fun(&OReportHelper::getReportFooterOn))
138 0 : || setReportSectionTitle(xReport,RID_STR_PAGE_HEADER,::std::mem_fun(&OReportHelper::getPageHeader),::std::mem_fun(&OReportHelper::getPageHeaderOn))
139 0 : || setReportSectionTitle(xReport,RID_STR_PAGE_FOOTER,::std::mem_fun(&OReportHelper::getPageFooter),::std::mem_fun(&OReportHelper::getPageFooterOn)) )
140 : {
141 0 : m_aStartMarker.Invalidate(INVALIDATE_NOERASE);
142 : }
143 : else
144 : {
145 0 : String sTitle = String(ModuleRes(RID_STR_DETAIL));
146 0 : m_aStartMarker.setTitle(sTitle);
147 0 : m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
148 0 : }
149 0 : }
150 : }
151 0 : else if ( _rEvent.PropertyName.equals(PROPERTY_EXPRESSION) )
152 : {
153 0 : uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
154 0 : if ( xGroup.is() && !setGroupSectionTitle(xGroup,RID_STR_HEADER,::std::mem_fun(&OGroupHelper::getHeader),::std::mem_fun(&OGroupHelper::getHeaderOn)))
155 : {
156 0 : setGroupSectionTitle(xGroup,RID_STR_FOOTER,::std::mem_fun(&OGroupHelper::getFooter),::std::mem_fun(&OGroupHelper::getFooterOn));
157 0 : }
158 0 : }
159 0 : }
160 : // -----------------------------------------------------------------------------
161 0 : bool OSectionWindow::setReportSectionTitle(const uno::Reference< report::XReportDefinition>& _xReport,sal_uInt16 _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OReportHelper> _pGetSection,::std::mem_fun_t<sal_Bool,OReportHelper> _pIsSectionOn)
162 : {
163 0 : OReportHelper aReportHelper(_xReport);
164 0 : const bool bRet = _pIsSectionOn(&aReportHelper) && _pGetSection(&aReportHelper) == m_aReportSection.getSection();
165 0 : if ( bRet )
166 : {
167 0 : String sTitle = String(ModuleRes(_nResId));
168 0 : m_aStartMarker.setTitle(sTitle);
169 0 : m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
170 : }
171 0 : return bRet;
172 : }
173 : // -----------------------------------------------------------------------------
174 0 : bool OSectionWindow::setGroupSectionTitle(const uno::Reference< report::XGroup>& _xGroup,sal_uInt16 _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> _pGetSection,::std::mem_fun_t<sal_Bool,OGroupHelper> _pIsSectionOn)
175 : {
176 0 : OGroupHelper aGroupHelper(_xGroup);
177 0 : const bool bRet = _pIsSectionOn(&aGroupHelper) && _pGetSection(&aGroupHelper) == m_aReportSection.getSection() ;
178 0 : if ( bRet )
179 : {
180 0 : OUString sExpression = _xGroup->getExpression();
181 0 : OUString sLabel = getViewsWindow()->getView()->getReportView()->getController().getColumnLabel_throw(sExpression);
182 0 : if ( !sLabel.isEmpty() )
183 : {
184 0 : sExpression = sLabel;
185 : }
186 :
187 0 : String sTitle = ModuleRes(_nResId).toString();
188 0 : sTitle.SearchAndReplace(OUString('#') ,sExpression);
189 0 : m_aStartMarker.setTitle(sTitle);
190 0 : m_aStartMarker.Invalidate(INVALIDATE_CHILDREN);
191 : }
192 0 : return bRet;
193 : }
194 : //------------------------------------------------------------------------------
195 0 : void OSectionWindow::ImplInitSettings()
196 : {
197 : static bool t = false;
198 0 : if ( t )
199 : {
200 0 : EnableChildTransparentMode( sal_True );
201 0 : SetParentClipMode( PARENTCLIPMODE_NOCLIP );
202 0 : SetPaintTransparent( sal_True );
203 : }
204 0 : SetBackground( );
205 0 : }
206 : //-----------------------------------------------------------------------------
207 0 : void OSectionWindow::DataChanged( const DataChangedEvent& rDCEvt )
208 : {
209 0 : Window::DataChanged( rDCEvt );
210 :
211 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
212 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
213 : {
214 0 : ImplInitSettings();
215 0 : Invalidate();
216 : }
217 0 : }
218 : //------------------------------------------------------------------------------
219 0 : void OSectionWindow::Resize()
220 : {
221 0 : Window::Resize();
222 :
223 0 : Size aOutputSize = GetOutputSizePixel();
224 0 : Fraction aEndWidth(long(REPORT_ENDMARKER_WIDTH));
225 0 : aEndWidth *= GetMapMode().GetScaleX();
226 :
227 0 : const Point aThumbPos = m_pParent->getView()->getThumbPos();
228 0 : aOutputSize.Width() -= aThumbPos.X();
229 0 : aOutputSize.Height() -= m_aSplitter.GetSizePixel().Height();
230 :
231 0 : if ( m_aStartMarker.isCollapsed() )
232 : {
233 0 : Point aPos(0,0);
234 0 : m_aStartMarker.SetPosSizePixel(aPos,aOutputSize);
235 : }
236 : else
237 : {
238 0 : const bool bShowEndMarker = m_pParent->getView()->GetTotalWidth() <= (aThumbPos.X() + aOutputSize.Width() );
239 :
240 0 : Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
241 0 : aStartWidth *= GetMapMode().GetScaleX();
242 :
243 : // set start marker
244 0 : m_aStartMarker.SetPosSizePixel(Point(0,0),Size(aStartWidth,aOutputSize.Height()));
245 :
246 : // set report section
247 0 : const uno::Reference< report::XSection> xSection = m_aReportSection.getSection();
248 0 : Size aSectionSize = LogicToPixel( Size( 0,xSection->getHeight() ) );
249 0 : Point aReportPos(aStartWidth,0);
250 0 : aSectionSize.Width() = aOutputSize.Width() - (long)aStartWidth;
251 0 : if ( bShowEndMarker )
252 0 : aSectionSize.Width() -= (long)aEndWidth;
253 :
254 0 : m_aReportSection.SetPosSizePixel(aReportPos,aSectionSize);
255 :
256 : // set splitter
257 0 : aReportPos.Y() += aSectionSize.Height();
258 0 : m_aSplitter.SetPosSizePixel(aReportPos,Size(aSectionSize.Width(),m_aSplitter.GetSizePixel().Height()));
259 0 : aSectionSize.Height() = (long)(1000 * (double)GetMapMode().GetScaleY());
260 0 : m_aSplitter.SetDragRectPixel( Rectangle(Point(aStartWidth,0),aSectionSize));
261 :
262 : // set end marker
263 0 : aReportPos.X() += aSectionSize.Width();
264 0 : aReportPos.Y() = 0;
265 0 : m_aEndMarker.Show(bShowEndMarker);
266 0 : m_aEndMarker.SetPosSizePixel(aReportPos,Size(aEndWidth,aOutputSize.Height()));
267 : }
268 0 : }
269 : // -----------------------------------------------------------------------------
270 0 : void OSectionWindow::setCollapsed(sal_Bool _bCollapsed)
271 : {
272 0 : if ( m_aStartMarker.isCollapsed() != _bCollapsed )
273 : {
274 0 : m_aStartMarker.setCollapsed(_bCollapsed);
275 : }
276 0 : }
277 : //-----------------------------------------------------------------------------
278 0 : void OSectionWindow::showProperties()
279 : {
280 0 : m_pParent->getView()->showProperties( m_aReportSection.getSection().get() );
281 0 : }
282 : //-----------------------------------------------------------------------------
283 0 : void OSectionWindow::setMarked(sal_Bool _bMark)
284 : {
285 0 : m_aStartMarker.setMarked(_bMark);
286 0 : m_aEndMarker.setMarked(_bMark);
287 0 : }
288 : // -----------------------------------------------------------------------------
289 0 : IMPL_LINK( OSectionWindow, Collapsed, OColorListener *, _pMarker )
290 : {
291 0 : if ( _pMarker )
292 : {
293 0 : sal_Bool bShow = !_pMarker->isCollapsed();
294 0 : m_aReportSection.Show(bShow);
295 0 : m_aEndMarker.Show(bShow);
296 0 : m_aSplitter.Show(bShow);
297 :
298 0 : m_pParent->resize(*this);
299 : }
300 0 : return 0L;
301 : }
302 : // -----------------------------------------------------------------------------
303 0 : void OSectionWindow::zoom(const Fraction& _aZoom)
304 : {
305 0 : setZoomFactor(_aZoom,*this);
306 0 : m_aStartMarker.zoom(_aZoom);
307 :
308 0 : setZoomFactor(_aZoom,m_aReportSection);
309 0 : setZoomFactor(_aZoom,m_aSplitter);
310 0 : setZoomFactor(_aZoom,m_aEndMarker);
311 0 : Invalidate();
312 0 : }
313 : //-----------------------------------------------------------------------------
314 0 : IMPL_LINK( OSectionWindow, StartSplitHdl, Splitter*, )
315 : {
316 0 : const String sUndoAction( ModuleRes( RID_STR_UNDO_CHANGE_SIZE ) );
317 0 : getViewsWindow()->getView()->getReportView()->getController().getUndoManager().EnterListAction( sUndoAction, String() );
318 0 : return 0L;
319 : }
320 : //------------------------------------------------------------------------------
321 0 : IMPL_LINK( OSectionWindow, EndSplitHdl, Splitter*, )
322 : {
323 0 : getViewsWindow()->getView()->getReportView()->getController().getUndoManager().LeaveListAction();
324 0 : return 0L;
325 : }
326 : //-----------------------------------------------------------------------------
327 0 : IMPL_LINK( OSectionWindow, SplitHdl, Splitter*, _pSplitter )
328 : {
329 0 : if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
330 : {
331 0 : return 0L;
332 : }
333 :
334 0 : sal_Int32 nSplitPos = _pSplitter->GetSplitPosPixel();
335 :
336 0 : const uno::Reference< report::XSection> xSection = m_aReportSection.getSection();
337 0 : nSplitPos = m_aSplitter.PixelToLogic(Size(0,nSplitPos)).Height();
338 :
339 0 : const sal_Int32 nCount = xSection->getCount();
340 0 : for (sal_Int32 i = 0; i < nCount; ++i)
341 : {
342 0 : uno::Reference<report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
343 0 : if ( xReportComponent.is() )
344 : {
345 0 : nSplitPos = ::std::max(nSplitPos,xReportComponent->getPositionY() + xReportComponent->getHeight());
346 : }
347 0 : }
348 :
349 0 : if ( nSplitPos < 0 )
350 0 : nSplitPos = 0;
351 :
352 0 : xSection->setHeight(nSplitPos);
353 0 : m_aSplitter.SetSplitPosPixel(m_aSplitter.LogicToPixel(Size(0,nSplitPos)).Height());
354 :
355 0 : return 0L;
356 : }
357 : // -----------------------------------------------------------------------------
358 0 : void lcl_scroll(Window& _rWindow,const Point& _aDelta)
359 : {
360 0 : _rWindow.Scroll(-_aDelta.X(),-_aDelta.Y());
361 0 : _rWindow.Invalidate(INVALIDATE_TRANSPARENT);
362 0 : }
363 : // -----------------------------------------------------------------------------
364 0 : void lcl_setOrigin(Window& _rWindow,long _nX, long _nY)
365 : {
366 0 : MapMode aMap = _rWindow.GetMapMode();
367 0 : aMap.SetOrigin( Point(- _nX, - _nY));
368 0 : _rWindow.SetMapMode( aMap );
369 0 : }
370 : //----------------------------------------------------------------------------
371 0 : void OSectionWindow::scrollChildren(long _nX)
372 : {
373 0 : const Point aDelta( _nX,0 );
374 :
375 0 : MapMode aMapMode( m_aReportSection.GetMapMode() );
376 0 : const Point aOld = aMapMode.GetOrigin();
377 0 : lcl_setOrigin(m_aReportSection,aDelta.X(), 0);
378 :
379 0 : aMapMode = m_aReportSection.GetMapMode();
380 0 : const Point aNew = aMapMode.GetOrigin();
381 0 : const Point aDiff = aOld - aNew;
382 : {
383 0 : lcl_scroll(m_aReportSection,aDiff);
384 : }
385 :
386 0 : lcl_scroll(m_aEndMarker,m_aEndMarker.PixelToLogic(Point(_nX,0)));
387 :
388 0 : lcl_setOrigin(m_aSplitter,_nX, 0);
389 0 : lcl_scroll(m_aSplitter,aDiff);
390 0 : }
391 : //==============================================================================
392 0 : } // rptui
393 : //==============================================================================
394 :
395 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|