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