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