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 : #ifndef RPTUI_VIEWSWINDOW_HXX
20 : #define RPTUI_VIEWSWINDOW_HXX
21 :
22 : #include <com/sun/star/report/XSection.hpp>
23 : #include <vcl/window.hxx>
24 : #include <svtools/colorcfg.hxx>
25 : #include "ReportDefines.hxx"
26 : #include "ReportSection.hxx"
27 : #include <comphelper/propmultiplex.hxx>
28 : #include "cppuhelper/basemutex.hxx"
29 : #include <svtools/colorcfg.hxx>
30 : #include <com/sun/star/beans/NamedValue.hpp>
31 : #include <svx/svdedtv.hxx>
32 : #include <SectionView.hxx>
33 : #include <unotools/options.hxx>
34 : #include <list>
35 : #include <vector>
36 : #include <boost/shared_ptr.hpp>
37 :
38 : #include <MarkedSection.hxx>
39 : #include <SectionWindow.hxx>
40 :
41 : class SdrHdl;
42 : namespace rptui
43 : {
44 : class OReportWindow;
45 : class OReportSection;
46 : class OSectionView;
47 :
48 :
49 : // -----------------------------------------------------------------------------
50 : struct RectangleLess : public ::std::binary_function< Rectangle, Rectangle, bool>
51 : {
52 : enum CompareMode { POS_LEFT,POS_RIGHT,POS_UPPER,POS_DOWN,POS_CENTER_HORIZONTAL,POS_CENTER_VERTICAL };
53 : CompareMode m_eCompareMode;
54 : Point m_aRefPoint;
55 0 : RectangleLess(CompareMode _eCompareMode,const Point& _rRefPoint ) : m_eCompareMode(_eCompareMode),m_aRefPoint(_rRefPoint){}
56 0 : bool operator() (const Rectangle& lhs, const Rectangle& rhs) const
57 : {
58 0 : switch(m_eCompareMode)
59 : {
60 : case POS_LEFT:
61 0 : return lhs.Left() < rhs.Left();
62 : case POS_RIGHT:
63 0 : return lhs.Right() >= rhs.Right();
64 : case POS_UPPER:
65 0 : return lhs.Top() < rhs.Top();
66 : case POS_DOWN:
67 0 : return lhs.Bottom() >= rhs.Bottom();
68 : case POS_CENTER_HORIZONTAL:
69 0 : return abs(m_aRefPoint.X() - lhs.Center().X()) < abs(m_aRefPoint.X() - rhs.Center().X());
70 : case POS_CENTER_VERTICAL:
71 0 : return abs(lhs.Center().Y() - m_aRefPoint.Y()) < abs(rhs.Center().Y() - m_aRefPoint.Y());
72 : }
73 0 : return false;
74 : }
75 : };
76 :
77 : class OWindowPositionCorrector
78 : {
79 : ::std::vector< ::std::pair<Window*,Point> > m_aChildren;
80 : long m_nDeltaX;
81 : long m_nDeltaY;
82 : public:
83 : OWindowPositionCorrector(Window* _pWindow,long _nDeltaX, long _nDeltaY) :m_nDeltaX(_nDeltaX), m_nDeltaY(_nDeltaY)
84 : {
85 : sal_uInt16 nCount = _pWindow->GetChildCount();
86 : m_aChildren.reserve(nCount);
87 : while( nCount )
88 : {
89 : Window* pChild = _pWindow->GetChild(--nCount);
90 : m_aChildren.push_back(::std::pair<Window*,Point>(pChild,pChild->GetPosPixel()));
91 : }
92 : }
93 : ~OWindowPositionCorrector()
94 : {
95 : ::std::vector< ::std::pair<Window*,Point> >::iterator aIter = m_aChildren.begin();
96 : ::std::vector< ::std::pair<Window*,Point> >::iterator aEnd = m_aChildren.end();
97 : for (; aIter != aEnd; ++aIter)
98 : {
99 : const Point aPos = aIter->first->GetPosPixel();
100 : if ( aPos == aIter->second )
101 : aIter->first->SetPosPixel(Point(m_nDeltaX,m_nDeltaY) + aPos);
102 : }
103 : }
104 : };
105 :
106 : class OViewsWindow : public Window
107 : , public utl::ConfigurationListener
108 : , public IMarkedSection
109 : {
110 : typedef ::std::multimap<Rectangle,::std::pair<SdrObject*,OSectionView*>,RectangleLess> TRectangleMap;
111 : public:
112 : typedef ::std::vector< ::boost::shared_ptr<OSectionWindow> > TSectionsMap;
113 :
114 : struct TReportPairHelper : public ::std::unary_function< TSectionsMap::value_type, OReportSection >
115 : {
116 0 : OReportSection& operator() (const TSectionsMap::value_type& lhs) const
117 : {
118 0 : return lhs->getReportSection();
119 : }
120 : };
121 : struct TStartMarkerHelper : public ::std::unary_function< TSectionsMap::value_type, OStartMarker >
122 : {
123 0 : OStartMarker& operator() (const TSectionsMap::value_type& lhs) const
124 : {
125 0 : return lhs->getStartMarker();
126 : }
127 : };
128 : private:
129 : TSectionsMap m_aSections;
130 : svtools::ColorConfig m_aColorConfig;
131 : OReportWindow* m_pParent;
132 : ::rtl::OUString m_sShapeType;
133 : sal_Bool m_bInSplitHandler;
134 : sal_Bool m_bInUnmark;
135 :
136 : void ImplInitSettings();
137 : /** returns the iterator at pos _nPos or the end()
138 : */
139 : TSectionsMap::iterator getIteratorAtPos(sal_uInt16 _nPos);
140 : void collectRectangles(TRectangleMap& _rMap,bool _bBoundRects);
141 : void collectBoundResizeRect(const TRectangleMap& _rSortRectangles,sal_Int32 _nControlModification,bool _bAlignAtSection,bool _bBoundRects,Rectangle& _rBound,Rectangle& _rResize);
142 : void impl_resizeSectionWindow(OSectionWindow& _rSectionWindow,Point& _rStartPoint,bool _bSet);
143 :
144 : OViewsWindow(OViewsWindow&);
145 : void operator =(OViewsWindow&);
146 : protected:
147 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
148 : // windows overload
149 : virtual void MouseButtonDown( const MouseEvent& rMEvt );
150 : virtual void MouseButtonUp( const MouseEvent& rMEvt );
151 :
152 : virtual void Paint( const Rectangle& rRect );
153 : virtual void ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 );
154 : public:
155 : OViewsWindow(
156 : OReportWindow* _pReportWindow);
157 : virtual ~OViewsWindow();
158 :
159 : // windows overload
160 : virtual void Resize();
161 :
162 : void resize(const OSectionWindow& _rSectionWindow);
163 :
164 : /** late ctor
165 : */
166 : void initialize();
167 :
168 0 : inline OReportWindow* getView() const { return m_pParent; }
169 :
170 : /** removes the section at the given position.
171 : *
172 : * \param _nPosition Zero based.
173 : */
174 : void removeSection(sal_uInt16 _nPosition);
175 :
176 : /** adds a new section at position _nPosition.
177 : If the section is <NULL/> nothing happens.
178 : If the position is grater than the current elements, the section will be appended.
179 : */
180 : void addSection(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >& _xSection
181 : ,const ::rtl::OUString& _sColorEntry
182 : ,sal_uInt16 _nPosition = USHRT_MAX);
183 :
184 : sal_uInt16 getSectionCount() const;
185 : /** return the section at the given position
186 : *
187 : * \param _nPos
188 : * \return the section at this pos or an empty section
189 : */
190 : ::boost::shared_ptr<OSectionWindow> getSectionWindow(const sal_uInt16 _nPos) const;
191 :
192 : /** turns the grid on or off
193 : *
194 : * \param _bVisible
195 : */
196 : void toggleGrid(sal_Bool _bVisible);
197 : void setGridSnap(sal_Bool bOn);
198 : void setDragStripes(sal_Bool bOn);
199 :
200 : /** returns the total accumulated height of all sections until _pSection is reached
201 : */
202 : sal_Int32 getTotalHeight() const;
203 :
204 0 : inline bool empty() const { return m_aSections.empty(); }
205 : void SetMode( DlgEdMode m_eMode );
206 : void SetInsertObj( sal_uInt16 eObj,const ::rtl::OUString& _sShapeType = ::rtl::OUString());
207 : rtl::OUString GetInsertObjString() const;
208 : /** copies the current selection in this section
209 : */
210 : void Copy();
211 :
212 : /** returns if paste is allowed
213 : *
214 : * \return <TRUE/> if paste is allowed
215 : */
216 : sal_Bool IsPasteAllowed() const;
217 :
218 : /** paste a new control in this section
219 : */
220 : void Paste();
221 :
222 : /** Deletes the current selection in this section
223 : *
224 : */
225 : void Delete();
226 :
227 : /** All objects will be marked.
228 : */
229 : void SelectAll(const sal_uInt16 _nObjectType);
230 :
231 : /** returns <TRUE/> when a object is marked
232 : */
233 : sal_Bool HasSelection() const;
234 :
235 : /** unmark all objects on the views without the given one.
236 : *
237 : * @param _pSectionView The view where the objects should not be unmarked.
238 : */
239 : void unmarkAllObjects(OSectionView* _pSectionView);
240 :
241 : /** returns the report section window for the given xsection
242 : @param _xSection the section
243 : */
244 : ::boost::shared_ptr<OSectionWindow> getSectionWindow(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection) const;
245 :
246 : /** checks if the keycode is known by the child windows
247 : @param _rCode the keycode
248 : @return <TRUE/> if the keycode is handled otherwise <FALSE/>
249 : */
250 : sal_Bool handleKeyEvent(const KeyEvent& _rEvent);
251 :
252 : /** the the section as marked or not marked
253 : @param _pSectionView the section where to set the marked flag
254 : @param _bMark the marked flag
255 : */
256 : void setMarked(OSectionView* _pSectionView,sal_Bool _bMark);
257 : void setMarked(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection,sal_Bool _bMark);
258 : void setMarked(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportComponent> >& _xShape,sal_Bool _bMark);
259 :
260 : // IMarkedSection
261 : ::boost::shared_ptr<OSectionWindow> getMarkedSection(NearSectionAccess nsa = CURRENT) const;
262 : virtual void markSection(const sal_uInt16 _nPos);
263 :
264 : /** align all marked objects in all sections
265 : */
266 : void alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool bBoundRects = false);
267 :
268 : /** creates a default object
269 : *
270 : */
271 : void createDefault();
272 :
273 : /** shows or hides the ruler.
274 : */
275 : void showRuler(sal_Bool _bShow);
276 :
277 : /** returns the currently set shape type.
278 : *
279 : * \return \member m_sShapeType
280 : */
281 0 : inline ::rtl::OUString getShapeType() const { return m_sShapeType; }
282 :
283 : /** returns the current position in the list
284 : */
285 : sal_uInt16 getPosition(const OSectionWindow* _pSectionWindow = NULL) const;
286 :
287 : /** calls on every section BrkAction
288 : *
289 : */
290 : void BrkAction();
291 : void BegMarkObj(const Point& _aPnt,const OSectionView* _pSection);
292 :
293 : private:
294 : void BegDragObj_createInvisibleObjectAtPosition(const Rectangle& _aRect, const OSectionView& _rSection);
295 : void EndDragObj_removeInvisibleObjects();
296 : Point m_aDragDelta;
297 : ::std::vector<SdrObject*> m_aBegDragTempList;
298 : bool isObjectInMyTempList(SdrObject *);
299 : public:
300 : void BegDragObj(const Point& _aPnt, SdrHdl* _pHdl,const OSectionView* _pSection);
301 : void EndDragObj(sal_Bool _bDragIntoNewSection,const OSectionView* _pSection,const Point& _aPnt);
302 :
303 : void EndAction();
304 : void ForceMarkedToAnotherPage();
305 : sal_Bool IsAction() const;
306 : sal_Bool IsDragObj() const;
307 : void handleKey(const KeyCode& _rCode);
308 : void stopScrollTimer();
309 :
310 : /** return the section at the given point which is relative to the given section
311 : *
312 : * \param _pSection the section which is used as reference point
313 : * \param _rPnt the point, it will be changed that it is inside the section which will be returned
314 : * \return the section
315 : */
316 : OSectionView* getSectionRelativeToPosition(const OSectionView* _pSection,Point& _rPnt);
317 :
318 : void MovAction(const Point& rPnt,const OSectionView* _pSection,bool _bMove /*= true */, bool _bControlKeySet);
319 :
320 : sal_uInt32 getMarkedObjectCount() const;
321 :
322 : /** fills the positions of all collapsed sections.
323 : *
324 : * \param _rCollapsedPositions Out parameter which holds afterwards all positions of the collapsed sections.
325 : */
326 : void fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const;
327 :
328 : /** collpase all sections given by their position
329 : *
330 : * \param _aCollpasedSections The position of the sections which should be collapsed.
331 : */
332 : void collapseSections(const com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _aCollpasedSections);
333 :
334 : /** zoom the ruler and view windows
335 : */
336 : void zoom(const Fraction& _aZoom);
337 :
338 : void scrollChildren(const Point& _aThumbPos);
339 :
340 : /** fills the vector with all selected control models
341 : /param _rSelection The vector will be filled and will not be cleared before.
342 : */
343 : void fillControlModelSelection(::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >& _rSelection) const;
344 : };
345 : //==============================================================================
346 : } // rptui
347 : //==============================================================================
348 : #endif // RPTUI_VIEWSWINDOW_HXX
349 :
350 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|