merge the formfield patch from ooo-build
[ooovba.git] / reportdesign / source / ui / inc / ViewsWindow.hxx
blob156ed2ad468ffc1853a354002b496ca536a96cb6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ViewsWindow.hxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef RPTUI_VIEWSWINDOW_HXX
31 #define RPTUI_VIEWSWINDOW_HXX
33 #include <com/sun/star/report/XSection.hpp>
34 #include <vcl/window.hxx>
35 #include <svtools/colorcfg.hxx>
36 #include "ReportDefines.hxx"
37 #include "ReportSection.hxx"
38 #include <comphelper/propmultiplex.hxx>
39 #include "cppuhelper/basemutex.hxx"
40 #include <svtools/colorcfg.hxx>
41 #include <com/sun/star/beans/NamedValue.hpp>
42 #include <svx/svdedtv.hxx>
43 #include <SectionView.hxx>
45 #include <list>
46 #include <vector>
47 #include <boost/shared_ptr.hpp>
49 #include <MarkedSection.hxx>
50 #include <SectionWindow.hxx>
52 class SdrHdl;
53 namespace rptui
55 class OReportWindow;
56 class ODesignView;
57 class OEndMarker;
58 class OReportSection;
59 class OSectionView;
62 // -----------------------------------------------------------------------------
63 struct RectangleLess : public ::std::binary_function< Rectangle, Rectangle, bool>
65 enum CompareMode { POS_LEFT,POS_RIGHT,POS_UPPER,POS_DOWN,POS_CENTER_HORIZONTAL,POS_CENTER_VERTICAL };
66 CompareMode m_eCompareMode;
67 Point m_aRefPoint;
68 RectangleLess(CompareMode _eCompareMode,const Point& _rRefPoint ) : m_eCompareMode(_eCompareMode),m_aRefPoint(_rRefPoint){}
69 bool operator() (const Rectangle& lhs, const Rectangle& rhs) const
71 switch(m_eCompareMode)
73 case POS_LEFT:
74 return lhs.Left() < rhs.Left();
75 case POS_RIGHT:
76 return lhs.Right() >= rhs.Right();
77 case POS_UPPER:
78 return lhs.Top() < rhs.Top();
79 case POS_DOWN:
80 return lhs.Bottom() >= rhs.Bottom();
81 case POS_CENTER_HORIZONTAL:
82 return abs(m_aRefPoint.X() - lhs.Center().X()) < abs(m_aRefPoint.X() - rhs.Center().X());
83 case POS_CENTER_VERTICAL:
84 return abs(lhs.Center().Y() - m_aRefPoint.Y()) < abs(rhs.Center().Y() - m_aRefPoint.Y());
86 return false;
90 class OWindowPositionCorrector
92 ::std::vector< ::std::pair<Window*,Point> > m_aChildren;
93 long m_nDeltaX;
94 long m_nDeltaY;
95 public:
96 OWindowPositionCorrector(Window* _pWindow,long _nDeltaX, long _nDeltaY) :m_nDeltaX(_nDeltaX), m_nDeltaY(_nDeltaY)
98 USHORT nCount = _pWindow->GetChildCount();
99 m_aChildren.reserve(nCount);
100 while( nCount )
102 Window* pChild = _pWindow->GetChild(--nCount);
103 m_aChildren.push_back(::std::pair<Window*,Point>(pChild,pChild->GetPosPixel()));
106 ~OWindowPositionCorrector()
108 ::std::vector< ::std::pair<Window*,Point> >::iterator aIter = m_aChildren.begin();
109 ::std::vector< ::std::pair<Window*,Point> >::iterator aEnd = m_aChildren.end();
110 for (; aIter != aEnd; ++aIter)
112 const Point aPos = aIter->first->GetPosPixel();
113 if ( aPos == aIter->second )
114 aIter->first->SetPosPixel(Point(m_nDeltaX,m_nDeltaY) + aPos);
119 class OViewsWindow : public Window
120 , public SfxListener
121 , public IMarkedSection
123 typedef ::std::multimap<Rectangle,::std::pair<SdrObject*,OSectionView*>,RectangleLess> TRectangleMap;
124 public:
125 typedef ::std::vector< ::boost::shared_ptr<OSectionWindow> > TSectionsMap;
127 struct TReportPairHelper : public ::std::unary_function< TSectionsMap::value_type, OReportSection >
129 OReportSection& operator() (const TSectionsMap::value_type& lhs) const
131 return lhs->getReportSection();
134 struct TStartMarkerHelper : public ::std::unary_function< TSectionsMap::value_type, OStartMarker >
136 OStartMarker& operator() (const TSectionsMap::value_type& lhs) const
138 return lhs->getStartMarker();
141 private:
142 TSectionsMap m_aSections;
143 svtools::ColorConfig m_aColorConfig;
144 OReportWindow* m_pParent;
145 ::rtl::OUString m_sShapeType;
146 sal_Bool m_bInSplitHandler;
147 sal_Bool m_bInUnmark;
149 void ImplInitSettings();
150 /** returns the iterator at pos _nPos or the end()
152 TSectionsMap::iterator getIteratorAtPos(USHORT _nPos);
153 void collectRectangles(TRectangleMap& _rMap,bool _bBoundRects);
154 void collectBoundResizeRect(const TRectangleMap& _rSortRectangles,sal_Int32 _nControlModification,bool _bAlignAtSection,bool _bBoundRects,Rectangle& _rBound,Rectangle& _rResize);
155 void impl_resizeSectionWindow(OSectionWindow& _rSectionWindow,Point& _rStartPoint,bool _bSet);
157 OViewsWindow(OViewsWindow&);
158 void operator =(OViewsWindow&);
159 protected:
160 virtual void DataChanged( const DataChangedEvent& rDCEvt );
161 // windows overload
162 virtual void MouseButtonDown( const MouseEvent& rMEvt );
163 virtual void MouseButtonUp( const MouseEvent& rMEvt );
164 using Window::Notify;
165 virtual void Paint( const Rectangle& rRect );
166 // SfxListener
167 virtual void Notify(SfxBroadcaster & rBc, SfxHint const & rHint);
168 public:
169 OViewsWindow(
170 OReportWindow* _pReportWindow);
171 virtual ~OViewsWindow();
173 // windows overload
174 virtual void Resize();
176 void resize(const OSectionWindow& _rSectionWindow);
178 /** late ctor
180 void initialize();
182 inline OReportWindow* getView() const { return m_pParent; }
184 /** removes the section at the given position.
186 * \param _nPosition Zero based.
188 void removeSection(USHORT _nPosition);
190 /** adds a new section at position _nPosition.
191 If the section is <NULL/> nothing happens.
192 If the position is grater than the current elements, the section will be appended.
194 void addSection(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >& _xSection
195 ,const ::rtl::OUString& _sColorEntry
196 ,USHORT _nPosition = USHRT_MAX);
198 USHORT getSectionCount() const;
199 /** return the section at the given position
201 * \param _nPos
202 * \return the section at this pos or an empty section
204 ::boost::shared_ptr<OSectionWindow> getSectionWindow(const USHORT _nPos) const;
206 void showView(USHORT _nPos,BOOL _bShow);
208 /** turns the grid on or off
210 * \param _bVisible
212 void toggleGrid(sal_Bool _bVisible);
213 void setGridSnap(BOOL bOn);
214 void setDragStripes(BOOL bOn);
215 BOOL isDragStripes() const;
217 /** returns the total accumulated height of all sections until _pSection is reached
219 sal_Int32 getTotalHeight() const;
221 inline bool empty() const { return m_aSections.empty(); }
222 void SetMode( DlgEdMode m_eMode );
223 void SetInsertObj( USHORT eObj,const ::rtl::OUString& _sShapeType = ::rtl::OUString());
224 rtl::OUString GetInsertObjString() const;
225 /** copies the current selection in this section
227 void Copy();
229 /** returns if paste is allowed
231 * \return <TRUE/> if paste is allowed
233 BOOL IsPasteAllowed();
235 /** paste a new control in this section
237 void Paste();
239 /** Deletes the current selection in this section
242 void Delete();
244 /** All objects will be marked.
246 void SelectAll(const sal_uInt16 _nObjectType);
248 /** returns <TRUE/> when a object is marked
250 BOOL HasSelection();
252 void SectionHasFocus(OReportSection* _pSection,BOOL _bHasFocus);
254 /** unmark all objects on the views without the given one.
256 * @param _pSectionView The view where the objects should not be unmarked.
258 void unmarkAllObjects(OSectionView* _pSectionView);
260 /** returns the report section window for the given xsection
261 @param _xSection the section
263 // ::boost::shared_ptr<OSectionWindow> getReportSection(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >& _xSection);
264 ::boost::shared_ptr<OSectionWindow> getSectionWindow(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection) const;
266 /** checks if the keycode is known by the child windows
267 @param _rCode the keycode
268 @return <TRUE/> if the keycode is handled otherwise <FALSE/>
270 sal_Bool handleKeyEvent(const KeyEvent& _rEvent);
272 /** the the section as marked or not marked
273 @param _pSectionView the section where to set the marked flag
274 @param _bMark the marked flag
276 void setMarked(OSectionView* _pSectionView,sal_Bool _bMark);
277 void setMarked(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection,sal_Bool _bMark);
278 void setMarked(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportComponent> >& _xShape,sal_Bool _bMark);
280 // IMarkedSection
281 ::boost::shared_ptr<OSectionWindow> getMarkedSection(NearSectionAccess nsa = CURRENT) const;
282 virtual void markSection(const sal_uInt16 _nPos);
284 /** align all marked objects in all sections
286 void alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool bBoundRects = false);
288 /** creates a default object
291 void createDefault();
293 /** shows or hides the ruler.
295 void showRuler(sal_Bool _bShow);
297 /** returns the currently set shape type.
299 * \return \member m_sShapeType
301 inline ::rtl::OUString getShapeType() const { return m_sShapeType; }
303 /** returns the current position in the list
305 USHORT getPosition(const OSectionWindow* _pSectionWindow = NULL) const;
307 /** calls on every section BrkAction
310 void BrkAction();
311 void BegMarkObj(const Point& _aPnt,const OSectionView* _pSection);
313 private:
314 void BegDragObj_createInvisibleObjectAtPosition(const Rectangle& _aRect, const OSectionView& _rSection);
315 void EndDragObj_removeInvisibleObjects();
316 Point m_aDragDelta;
317 ::std::vector<SdrObject*> m_aBegDragTempList;
318 bool isObjectInMyTempList(SdrObject *);
319 public:
320 void BegDragObj(const Point& _aPnt, SdrHdl* _pHdl,const OSectionView* _pSection);
321 void EndDragObj(BOOL _bDragIntoNewSection,const OSectionView* _pSection,const Point& _aPnt);
323 void EndAction();
324 void ForceMarkedToAnotherPage();
325 BOOL IsAction() const;
326 BOOL IsDragObj() const;
327 void handleKey(const KeyCode& _rCode);
328 void stopScrollTimer();
330 /** return the section at the given point which is relative to the given section
332 * \param _pSection the section which is used as reference point
333 * \param _rPnt the point, it will be changed that it is inside the section which will be returned
334 * \return the section
336 OSectionView* getSectionRelativeToPosition(const OSectionView* _pSection,Point& _rPnt);
338 void MovAction(const Point& rPnt,const OSectionView* _pSection,bool _bMove /*= true */, bool _bControlKeySet);
339 // void MovAction2(const Point& rPnt,const OSectionView* _pSection);
341 sal_uInt32 getMarkedObjectCount() const;
343 /** fills the positions of all collapsed sections.
345 * \param _rCollapsedPositions Out parameter which holds afterwards all positions of the collapsed sections.
347 void fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const;
349 /** collpase all sections given by their position
351 * \param _aCollpasedSections The position of the sections which should be collapsed.
353 void collapseSections(const com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _aCollpasedSections);
355 /** zoom the ruler and view windows
357 void zoom(const Fraction& _aZoom);
359 void scrollChildren(const Point& _aThumbPos);
361 /** fills the vector with all selected control models
362 /param _rSelection The vector will be filled and will not be cleared before.
364 void fillControlModelSelection(::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >& _rSelection) const;
366 //==============================================================================
367 } // rptui
368 //==============================================================================
369 #endif // RPTUI_VIEWSWINDOW_HXX