LCOV - code coverage report
Current view: top level - svx/source/dialog - contwnd.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 133 0.8 %
Date: 2014-11-03 Functions: 2 15 13.3 %
Legend: Lines: hit not hit

          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             : 
      20             : #include <svx/xoutbmp.hxx>
      21             : #include <svx/dialogs.hrc>
      22             : #include <svx/svxids.hrc>
      23             : #include <contwnd.hxx>
      24             : #include <svx/svdpage.hxx>
      25             : #include <svx/svdopath.hxx>
      26             : #include <svx/xfltrit.hxx>
      27             : #include <svx/xfillit.hxx>
      28             : #include <basegfx/polygon/b2dpolygon.hxx>
      29             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      30             : #include "svx/sdrpaintwindow.hxx"
      31             : 
      32             : using namespace com::sun::star;
      33             : 
      34             : #define TRANSCOL Color( COL_WHITE )
      35             : 
      36           0 : ContourWindow::ContourWindow( vcl::Window* pParent, WinBits nBits ) :
      37             :             GraphCtrl       ( pParent, nBits ),
      38             :             aWorkRect       ( 0, 0, 0, 0 ),
      39             :             bPipetteMode    ( false ),
      40             :             bWorkplaceMode  ( false ),
      41           0 :             bClickValid     ( false )
      42             : {
      43           0 :     SetWinStyle( WB_SDRMODE );
      44           0 : }
      45             : 
      46           0 : ContourWindow::~ContourWindow()
      47             : {
      48           0 : }
      49             : 
      50           0 : void ContourWindow::SetPolyPolygon( const tools::PolyPolygon& rPolyPoly )
      51             : {
      52           0 :     SdrPage*        pPage = (SdrPage*) pModel->GetPage( 0 );
      53           0 :     const sal_uInt16    nPolyCount = rPolyPoly.Count();
      54             : 
      55             :     // First delete all drawing objects
      56           0 :     aPolyPoly = rPolyPoly;
      57             : 
      58             :     // To avoid to have destroyed objects which are still selected, it is necessary to deselect
      59             :     // them first (!)
      60           0 :     pView->UnmarkAllObj();
      61             : 
      62           0 :     pPage->Clear();
      63             : 
      64           0 :     for ( sal_uInt16 i = 0; i < nPolyCount; i++ )
      65             :     {
      66           0 :         basegfx::B2DPolyPolygon aPolyPolygon;
      67           0 :         aPolyPolygon.append(aPolyPoly[ i ].getB2DPolygon());
      68           0 :         SdrPathObj* pPathObj = new SdrPathObj( OBJ_PATHFILL, aPolyPolygon );
      69             : 
      70           0 :         if ( pPathObj )
      71             :         {
      72           0 :             SfxItemSet aSet( pModel->GetItemPool() );
      73             : 
      74           0 :             aSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
      75           0 :             aSet.Put( XFillColorItem( "", TRANSCOL ) );
      76           0 :             aSet.Put( XFillTransparenceItem( 50 ) );
      77             : 
      78           0 :             pPathObj->SetMergedItemSetAndBroadcast(aSet);
      79             : 
      80           0 :             pPage->InsertObject( pPathObj );
      81             :         }
      82           0 :     }
      83             : 
      84           0 :     if ( nPolyCount )
      85             :     {
      86           0 :         pView->MarkAll();
      87           0 :         pView->CombineMarkedObjects( false );
      88             :     }
      89             : 
      90           0 :     pModel->SetChanged( false );
      91           0 : }
      92             : 
      93           0 : const tools::PolyPolygon& ContourWindow::GetPolyPolygon()
      94             : {
      95           0 :     if ( pModel->IsChanged() )
      96             :     {
      97           0 :         SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
      98             : 
      99           0 :         aPolyPoly = tools::PolyPolygon();
     100             : 
     101           0 :         if ( pPage && pPage->GetObjCount() )
     102             :         {
     103           0 :             SdrPathObj* pPathObj = static_cast<SdrPathObj*>(pPage->GetObj(0));
     104             :             // Not sure if subdivision is needed for ContourWindow, but maybe it cannot handle
     105             :             // curves at all. Keeping subdivision here for security
     106           0 :             const basegfx::B2DPolyPolygon aB2DPolyPolygon(basegfx::tools::adaptiveSubdivideByAngle(pPathObj->GetPathPoly()));
     107           0 :             aPolyPoly = tools::PolyPolygon(aB2DPolyPolygon);
     108             :         }
     109             : 
     110           0 :         pModel->SetChanged( false );
     111             :     }
     112             : 
     113           0 :     return aPolyPoly;
     114             : }
     115             : 
     116           0 : void ContourWindow::InitSdrModel()
     117             : {
     118           0 :     GraphCtrl::InitSdrModel();
     119             : 
     120           0 :     SfxItemSet aSet( pModel->GetItemPool() );
     121             : 
     122           0 :     aSet.Put( XFillColorItem( "", TRANSCOL ) );
     123           0 :     aSet.Put( XFillTransparenceItem( 50 ) );
     124           0 :     pView->SetAttributes( aSet );
     125           0 :     pView->SetFrameDragSingles( true );
     126           0 : }
     127             : 
     128           0 : void ContourWindow::SdrObjCreated( const SdrObject&  )
     129             : {
     130           0 :     pView->MarkAll();
     131           0 :     pView->CombineMarkedObjects( false );
     132           0 : }
     133             : 
     134           0 : bool ContourWindow::IsContourChanged() const
     135             : {
     136           0 :     SdrPage*    pPage = (SdrPage*) pModel->GetPage( 0 );
     137           0 :     bool        bRet = false;
     138             : 
     139           0 :     if ( pPage && pPage->GetObjCount() )
     140           0 :         bRet = static_cast<SdrPathObj*>( pPage->GetObj( 0 ) )->GetPathPoly().count() && pModel->IsChanged();
     141             : 
     142           0 :     return bRet;
     143             : }
     144             : 
     145           0 : void ContourWindow::MouseButtonDown( const MouseEvent& rMEvt )
     146             : {
     147           0 :     if ( bWorkplaceMode )
     148             :     {
     149           0 :         const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
     150             : 
     151           0 :         SetPolyPolygon( tools::PolyPolygon() );
     152           0 :         aWorkRect = Rectangle( aLogPt, aLogPt );
     153           0 :         Paint( Rectangle( Point(), GetGraphicSize() ) );
     154           0 :         SetEditMode( true );
     155             :     }
     156             : 
     157           0 :     if ( !bPipetteMode )
     158           0 :         GraphCtrl::MouseButtonDown( rMEvt );
     159           0 : }
     160             : 
     161           0 : void ContourWindow::MouseMove( const MouseEvent& rMEvt )
     162             : {
     163           0 :     bClickValid = false;
     164             : 
     165           0 :     if ( bPipetteMode )
     166             :     {
     167           0 :         const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
     168             : 
     169           0 :         aPipetteColor = GetPixel( aLogPt );
     170           0 :         Control::MouseMove( rMEvt );
     171             : 
     172           0 :         if ( aPipetteLink.IsSet() && Rectangle( Point(), GetGraphicSize() ).IsInside( aLogPt ) )
     173             :         {
     174           0 :             SetPointer( POINTER_REFHAND );
     175           0 :             aPipetteLink.Call( this );
     176             :         }
     177             :     }
     178             :     else
     179           0 :         GraphCtrl::MouseMove( rMEvt );
     180           0 : }
     181             : 
     182           0 : void ContourWindow::MouseButtonUp(const MouseEvent& rMEvt)
     183             : {
     184           0 :     Point aTmpPoint;
     185           0 :     const Rectangle aGraphRect( aTmpPoint, GetGraphicSize() );
     186           0 :     const Point     aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
     187             : 
     188           0 :     bClickValid = aGraphRect.IsInside( aLogPt );
     189           0 :     ReleaseMouse();
     190             : 
     191           0 :     if ( bPipetteMode )
     192             :     {
     193           0 :         Control::MouseButtonUp( rMEvt );
     194             : 
     195           0 :         if ( aPipetteClickLink.IsSet() )
     196           0 :             aPipetteClickLink.Call( this );
     197             :     }
     198           0 :     else if ( bWorkplaceMode )
     199             :     {
     200           0 :         GraphCtrl::MouseButtonUp( rMEvt );
     201             : 
     202           0 :         aWorkRect.Right() = aLogPt.X();
     203           0 :         aWorkRect.Bottom() = aLogPt.Y();
     204           0 :         aWorkRect.Intersection( aGraphRect );
     205           0 :         aWorkRect.Justify();
     206             : 
     207           0 :         if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
     208             :         {
     209           0 :             tools::PolyPolygon _aPolyPoly( GetPolyPolygon() );
     210             : 
     211           0 :             _aPolyPoly.Clip( aWorkRect );
     212           0 :             SetPolyPolygon( _aPolyPoly );
     213           0 :             pView->SetWorkArea( aWorkRect );
     214             :         }
     215             :         else
     216           0 :             pView->SetWorkArea( aGraphRect );
     217             : 
     218           0 :         Invalidate( aGraphRect );
     219             : 
     220           0 :         if ( aWorkplaceClickLink.IsSet() )
     221           0 :             aWorkplaceClickLink.Call( this );
     222             :     }
     223             :     else
     224           0 :         GraphCtrl::MouseButtonUp( rMEvt );
     225           0 : }
     226             : 
     227           0 : void ContourWindow::Paint( const Rectangle& rRect )
     228             : {
     229             :     // #i75482#
     230             :     // encapsulate the redraw using Begin/End and use the returned
     231             :     // data to get the target output device (e.g. when pre-rendering)
     232           0 :     SdrPaintWindow* pPaintWindow = pView->BeginCompleteRedraw(this);
     233           0 :     OutputDevice& rTarget = pPaintWindow->GetTargetOutputDevice();
     234             : 
     235           0 :     const Graphic& rGraphic = GetGraphic();
     236           0 :     const Color& rOldLineColor = GetLineColor();
     237           0 :     const Color& rOldFillColor = GetFillColor();
     238             : 
     239           0 :     rTarget.SetLineColor( Color( COL_BLACK ) );
     240           0 :     rTarget.SetFillColor( Color( COL_WHITE ) );
     241             : 
     242           0 :     rTarget.DrawRect( Rectangle( Point(), GetGraphicSize() ) );
     243             : 
     244           0 :     rTarget.SetLineColor( rOldLineColor );
     245           0 :     rTarget.SetFillColor( rOldFillColor );
     246             : 
     247           0 :     if ( rGraphic.GetType() != GRAPHIC_NONE )
     248           0 :         rGraphic.Draw( &rTarget, Point(), GetGraphicSize() );
     249             : 
     250           0 :     if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
     251             :     {
     252           0 :         tools::PolyPolygon _aPolyPoly( 2, 2 );
     253           0 :         const Color aOldFillColor( GetFillColor() );
     254             : 
     255           0 :         _aPolyPoly.Insert( Rectangle( Point(), GetGraphicSize() ) );
     256           0 :         _aPolyPoly.Insert( aWorkRect );
     257             : 
     258           0 :         rTarget.SetFillColor( COL_LIGHTRED );
     259           0 :         rTarget.DrawTransparent( _aPolyPoly, 50 );
     260           0 :         rTarget.SetFillColor( aOldFillColor );
     261             :     }
     262             : 
     263             :     // #i75482#
     264           0 :     const vcl::Region aRepaintRegion(rRect);
     265           0 :     pView->DoCompleteRedraw(*pPaintWindow, aRepaintRegion);
     266           0 :     pView->EndCompleteRedraw(*pPaintWindow, true);
     267           0 : }
     268             : 
     269           0 : Size ContourWindow::GetOptimalSize() const
     270             : {
     271           0 :     return LogicToPixel(Size(270, 170), MAP_APPFONT);
     272         594 : }
     273             : 
     274             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10