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

Generated by: LCOV version 1.10