1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir #include <svx/xoutbmp.hxx> 27cdf0e10cSrcweir #include <svx/dialogs.hrc> 28cdf0e10cSrcweir #include <svx/svxids.hrc> 29cdf0e10cSrcweir #include <contdlg.hrc> 30cdf0e10cSrcweir #include <contwnd.hxx> 31cdf0e10cSrcweir #include <svx/svdpage.hxx> 32cdf0e10cSrcweir #include <svx/svdopath.hxx> 33cdf0e10cSrcweir #include <svx/xfltrit.hxx> 34cdf0e10cSrcweir #include <svx/xfillit.hxx> 35cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 36cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir // #i75482# 39cdf0e10cSrcweir #include "svx/sdrpaintwindow.hxx" 40cdf0e10cSrcweir 41cdf0e10cSrcweir #define TRANSCOL Color( COL_WHITE ) 42cdf0e10cSrcweir 43cdf0e10cSrcweir /************************************************************************* 44cdf0e10cSrcweir |* 45cdf0e10cSrcweir |* 46cdf0e10cSrcweir |* 47cdf0e10cSrcweir \************************************************************************/ 48cdf0e10cSrcweir 49cdf0e10cSrcweir ContourWindow::ContourWindow( Window* pParent, const ResId& rResId ) : 50cdf0e10cSrcweir GraphCtrl ( pParent, rResId ), 51cdf0e10cSrcweir aWorkRect ( 0, 0, 0, 0 ), 52cdf0e10cSrcweir bPipetteMode ( sal_False ), 53cdf0e10cSrcweir bWorkplaceMode ( sal_False ), 54cdf0e10cSrcweir bClickValid ( sal_False ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir SetWinStyle( WB_SDRMODE ); 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir 60cdf0e10cSrcweir /************************************************************************* 61cdf0e10cSrcweir |* 62cdf0e10cSrcweir |* 63cdf0e10cSrcweir |* 64cdf0e10cSrcweir \************************************************************************/ 65cdf0e10cSrcweir 66cdf0e10cSrcweir ContourWindow::~ContourWindow() 67cdf0e10cSrcweir { 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir 71cdf0e10cSrcweir /************************************************************************* 72cdf0e10cSrcweir |* 73cdf0e10cSrcweir |* 74cdf0e10cSrcweir |* 75cdf0e10cSrcweir \************************************************************************/ 76cdf0e10cSrcweir 77cdf0e10cSrcweir void ContourWindow::SetPolyPolygon( const PolyPolygon& rPolyPoly ) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 ); 80cdf0e10cSrcweir const sal_uInt16 nPolyCount = rPolyPoly.Count(); 81cdf0e10cSrcweir 82cdf0e10cSrcweir // zuerst alle Zeichenobjekte loeschen 83cdf0e10cSrcweir aPolyPoly = rPolyPoly; 84cdf0e10cSrcweir 85cdf0e10cSrcweir // #117412# 86cdf0e10cSrcweir // To avoid to have destroyed objects which are still selected, it is necessary to deselect 87cdf0e10cSrcweir // them first (!) 88cdf0e10cSrcweir pView->UnmarkAllObj(); 89cdf0e10cSrcweir 90cdf0e10cSrcweir pPage->Clear(); 91cdf0e10cSrcweir 92cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nPolyCount; i++ ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir basegfx::B2DPolyPolygon aPolyPolygon; 95cdf0e10cSrcweir aPolyPolygon.append(aPolyPoly[ i ].getB2DPolygon()); 96cdf0e10cSrcweir SdrPathObj* pPathObj = new SdrPathObj( OBJ_PATHFILL, aPolyPolygon ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir if ( pPathObj ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir SfxItemSet aSet( pModel->GetItemPool() ); 101cdf0e10cSrcweir 102cdf0e10cSrcweir aSet.Put( XFillStyleItem( XFILL_SOLID ) ); 103cdf0e10cSrcweir aSet.Put( XFillColorItem( String(), TRANSCOL ) ); 104cdf0e10cSrcweir aSet.Put( XFillTransparenceItem( 50 ) ); 105cdf0e10cSrcweir 106cdf0e10cSrcweir //pPathObj->SetItemSetAndBroadcast(aSet); 107cdf0e10cSrcweir pPathObj->SetMergedItemSetAndBroadcast(aSet); 108cdf0e10cSrcweir 109cdf0e10cSrcweir pPage->InsertObject( pPathObj ); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir if ( nPolyCount ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir pView->MarkAll(); 116cdf0e10cSrcweir pView->CombineMarkedObjects( sal_False ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir pModel->SetChanged( sal_False ); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir 123cdf0e10cSrcweir /************************************************************************* 124cdf0e10cSrcweir |* 125cdf0e10cSrcweir |* 126cdf0e10cSrcweir |* 127cdf0e10cSrcweir \************************************************************************/ 128cdf0e10cSrcweir 129cdf0e10cSrcweir const PolyPolygon& ContourWindow::GetPolyPolygon() 130cdf0e10cSrcweir { 131cdf0e10cSrcweir if ( pModel->IsChanged() ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 ); 134cdf0e10cSrcweir 135cdf0e10cSrcweir aPolyPoly = PolyPolygon(); 136cdf0e10cSrcweir 137cdf0e10cSrcweir if ( pPage && pPage->GetObjCount() ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir SdrPathObj* pPathObj = (SdrPathObj*)pPage->GetObj(0L); 140cdf0e10cSrcweir // Not sure if subdivision is needed for ContourWindow, but maybe it cannot handle 141cdf0e10cSrcweir // curves at all. Keeping subdivision here for security 142cdf0e10cSrcweir const basegfx::B2DPolyPolygon aB2DPolyPolygon(basegfx::tools::adaptiveSubdivideByAngle(pPathObj->GetPathPoly())); 143cdf0e10cSrcweir aPolyPoly = PolyPolygon(aB2DPolyPolygon); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir pModel->SetChanged( sal_False ); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir return aPolyPoly; 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir 153cdf0e10cSrcweir /************************************************************************* 154cdf0e10cSrcweir |* 155cdf0e10cSrcweir |* 156cdf0e10cSrcweir |* 157cdf0e10cSrcweir \************************************************************************/ 158cdf0e10cSrcweir 159cdf0e10cSrcweir void ContourWindow::InitSdrModel() 160cdf0e10cSrcweir { 161cdf0e10cSrcweir GraphCtrl::InitSdrModel(); 162cdf0e10cSrcweir 163cdf0e10cSrcweir SfxItemSet aSet( pModel->GetItemPool() ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir aSet.Put( XFillColorItem( String(), TRANSCOL ) ); 166cdf0e10cSrcweir aSet.Put( XFillTransparenceItem( 50 ) ); 167cdf0e10cSrcweir pView->SetAttributes( aSet ); 168cdf0e10cSrcweir pView->SetFrameDragSingles( sal_True ); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir 172cdf0e10cSrcweir /************************************************************************* 173cdf0e10cSrcweir |* 174cdf0e10cSrcweir |* 175cdf0e10cSrcweir |* 176cdf0e10cSrcweir \************************************************************************/ 177cdf0e10cSrcweir 178cdf0e10cSrcweir void ContourWindow::SdrObjCreated( const SdrObject& ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir pView->MarkAll(); 181cdf0e10cSrcweir pView->CombineMarkedObjects( sal_False ); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir 185cdf0e10cSrcweir /************************************************************************* 186cdf0e10cSrcweir |* 187cdf0e10cSrcweir |* 188cdf0e10cSrcweir |* 189cdf0e10cSrcweir \************************************************************************/ 190cdf0e10cSrcweir 191cdf0e10cSrcweir sal_Bool ContourWindow::IsContourChanged() const 192cdf0e10cSrcweir { 193cdf0e10cSrcweir SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 ); 194cdf0e10cSrcweir sal_Bool bRet = sal_False; 195cdf0e10cSrcweir 196cdf0e10cSrcweir if ( pPage && pPage->GetObjCount() ) 197cdf0e10cSrcweir bRet = ( (SdrPathObj*) pPage->GetObj( 0 ) )->GetPathPoly().count() && pModel->IsChanged(); 198cdf0e10cSrcweir 199cdf0e10cSrcweir return bRet; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir 203cdf0e10cSrcweir /************************************************************************* 204cdf0e10cSrcweir |* 205cdf0e10cSrcweir |* 206cdf0e10cSrcweir |* 207cdf0e10cSrcweir \************************************************************************/ 208cdf0e10cSrcweir 209cdf0e10cSrcweir void ContourWindow::MouseButtonDown( const MouseEvent& rMEvt ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir if ( bWorkplaceMode ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) ); 214cdf0e10cSrcweir 215cdf0e10cSrcweir SetPolyPolygon( PolyPolygon() ); 216cdf0e10cSrcweir aWorkRect = Rectangle( aLogPt, aLogPt ); 217cdf0e10cSrcweir Paint( Rectangle( Point(), GetGraphicSize() ) ); 218cdf0e10cSrcweir SetEditMode( sal_True ); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir if ( !bPipetteMode ) 222cdf0e10cSrcweir GraphCtrl::MouseButtonDown( rMEvt ); 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir 226cdf0e10cSrcweir /************************************************************************* 227cdf0e10cSrcweir |* 228cdf0e10cSrcweir |* 229cdf0e10cSrcweir |* 230cdf0e10cSrcweir \************************************************************************/ 231cdf0e10cSrcweir 232cdf0e10cSrcweir void ContourWindow::MouseMove( const MouseEvent& rMEvt ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir bClickValid = sal_False; 235cdf0e10cSrcweir 236cdf0e10cSrcweir if ( bPipetteMode ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) ); 239cdf0e10cSrcweir 240cdf0e10cSrcweir aPipetteColor = GetPixel( aLogPt ); 241cdf0e10cSrcweir Control::MouseMove( rMEvt ); 242cdf0e10cSrcweir 243cdf0e10cSrcweir if ( aPipetteLink.IsSet() && Rectangle( Point(), GetGraphicSize() ).IsInside( aLogPt ) ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir SetPointer( POINTER_REFHAND ); 246cdf0e10cSrcweir aPipetteLink.Call( this ); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir } 249cdf0e10cSrcweir else 250cdf0e10cSrcweir GraphCtrl::MouseMove( rMEvt ); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir 254cdf0e10cSrcweir /************************************************************************* 255cdf0e10cSrcweir |* 256cdf0e10cSrcweir |* 257cdf0e10cSrcweir |* 258cdf0e10cSrcweir \************************************************************************/ 259cdf0e10cSrcweir 260cdf0e10cSrcweir void ContourWindow::MouseButtonUp(const MouseEvent& rMEvt) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir Point aTmpPoint; 263cdf0e10cSrcweir const Rectangle aGraphRect( aTmpPoint, GetGraphicSize() ); 264cdf0e10cSrcweir const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) ); 265cdf0e10cSrcweir 266cdf0e10cSrcweir bClickValid = aGraphRect.IsInside( aLogPt ); 267cdf0e10cSrcweir ReleaseMouse(); 268cdf0e10cSrcweir 269cdf0e10cSrcweir if ( bPipetteMode ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir Control::MouseButtonUp( rMEvt ); 272cdf0e10cSrcweir 273cdf0e10cSrcweir if ( aPipetteClickLink.IsSet() ) 274cdf0e10cSrcweir aPipetteClickLink.Call( this ); 275cdf0e10cSrcweir } 276cdf0e10cSrcweir else if ( bWorkplaceMode ) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir GraphCtrl::MouseButtonUp( rMEvt ); 279cdf0e10cSrcweir 280cdf0e10cSrcweir aWorkRect.Right() = aLogPt.X(); 281cdf0e10cSrcweir aWorkRect.Bottom() = aLogPt.Y(); 282cdf0e10cSrcweir aWorkRect.Intersection( aGraphRect ); 283cdf0e10cSrcweir aWorkRect.Justify(); 284cdf0e10cSrcweir 285cdf0e10cSrcweir if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir PolyPolygon _aPolyPoly( GetPolyPolygon() ); 288cdf0e10cSrcweir 289cdf0e10cSrcweir _aPolyPoly.Clip( aWorkRect ); 290cdf0e10cSrcweir SetPolyPolygon( _aPolyPoly ); 291cdf0e10cSrcweir pView->SetWorkArea( aWorkRect ); 292cdf0e10cSrcweir } 293cdf0e10cSrcweir else 294cdf0e10cSrcweir pView->SetWorkArea( aGraphRect ); 295cdf0e10cSrcweir 296cdf0e10cSrcweir Invalidate( aGraphRect ); 297cdf0e10cSrcweir 298cdf0e10cSrcweir if ( aWorkplaceClickLink.IsSet() ) 299cdf0e10cSrcweir aWorkplaceClickLink.Call( this ); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir else 302cdf0e10cSrcweir GraphCtrl::MouseButtonUp( rMEvt ); 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir 306cdf0e10cSrcweir /************************************************************************* 307cdf0e10cSrcweir |* 308cdf0e10cSrcweir |* 309cdf0e10cSrcweir |* 310cdf0e10cSrcweir \************************************************************************/ 311cdf0e10cSrcweir 312cdf0e10cSrcweir void ContourWindow::Paint( const Rectangle& rRect ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir // #i75482# 315cdf0e10cSrcweir // encapsulate the redraw using Begin/End and use the returned 316cdf0e10cSrcweir // data to get the target output device (e.g. when pre-rendering) 317cdf0e10cSrcweir SdrPaintWindow* pPaintWindow = pView->BeginCompleteRedraw(this); 318cdf0e10cSrcweir OutputDevice& rTarget = pPaintWindow->GetTargetOutputDevice(); 319cdf0e10cSrcweir 320cdf0e10cSrcweir const Graphic& rGraphic = GetGraphic(); 321cdf0e10cSrcweir const Color& rOldLineColor = GetLineColor(); 322cdf0e10cSrcweir const Color& rOldFillColor = GetFillColor(); 323cdf0e10cSrcweir 324cdf0e10cSrcweir rTarget.SetLineColor( Color( COL_BLACK ) ); 325cdf0e10cSrcweir rTarget.SetFillColor( Color( COL_WHITE ) ); 326cdf0e10cSrcweir 327cdf0e10cSrcweir rTarget.DrawRect( Rectangle( Point(), GetGraphicSize() ) ); 328cdf0e10cSrcweir 329cdf0e10cSrcweir rTarget.SetLineColor( rOldLineColor ); 330cdf0e10cSrcweir rTarget.SetFillColor( rOldFillColor ); 331cdf0e10cSrcweir 332cdf0e10cSrcweir if ( rGraphic.GetType() != GRAPHIC_NONE ) 333cdf0e10cSrcweir rGraphic.Draw( &rTarget, Point(), GetGraphicSize() ); 334cdf0e10cSrcweir 335cdf0e10cSrcweir if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() ) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir PolyPolygon _aPolyPoly( 2, 2 ); 338cdf0e10cSrcweir const Color aOldFillColor( GetFillColor() ); 339cdf0e10cSrcweir 340cdf0e10cSrcweir _aPolyPoly.Insert( Rectangle( Point(), GetGraphicSize() ) ); 341cdf0e10cSrcweir _aPolyPoly.Insert( aWorkRect ); 342cdf0e10cSrcweir 343cdf0e10cSrcweir rTarget.SetFillColor( COL_LIGHTRED ); 344cdf0e10cSrcweir rTarget.DrawTransparent( _aPolyPoly, 50 ); 345cdf0e10cSrcweir rTarget.SetFillColor( aOldFillColor ); 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir // #i75482# 349cdf0e10cSrcweir const Region aRepaintRegion(rRect); 350cdf0e10cSrcweir pView->DoCompleteRedraw(*pPaintWindow, aRepaintRegion); 351cdf0e10cSrcweir pView->EndCompleteRedraw(*pPaintWindow, true); 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir // eof 355