LCOV - code coverage report
Current view: top level - svx/source/dialog - connctrl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 165 0.6 %
Date: 2015-06-13 12:38:46 Functions: 2 17 11.8 %
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 <vcl/svapp.hxx>
      21             : 
      22             : #include "svx/connctrl.hxx"
      23             : #include "svx/dlgutil.hxx"
      24             : 
      25             : #include <svx/dialmgr.hxx>
      26             : #include <svx/sdr/contact/displayinfo.hxx>
      27             : #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
      28             : #include <svx/svdmark.hxx>
      29             : #include <svx/svdoedge.hxx>
      30             : #include <svx/svdpage.hxx>
      31             : #include <svx/svdview.hxx>
      32             : #include <svx/sxelditm.hxx>
      33             : #include <sxmkitm.hxx>
      34             : 
      35             : #include <vcl/builderfactory.hxx>
      36             : #include <vcl/settings.hxx>
      37             : #include <boost/scoped_ptr.hpp>
      38             : 
      39           0 : SvxXConnectionPreview::SvxXConnectionPreview( vcl::Window* pParent, WinBits nStyle)
      40             :     : Control(pParent, nStyle)
      41             :     , pEdgeObj(NULL)
      42             :     , pObjList(NULL)
      43           0 :     , pView(NULL)
      44             : {
      45           0 :     SetMapMode( MAP_100TH_MM );
      46           0 :     SetStyles();
      47           0 : }
      48             : 
      49           0 : VCL_BUILDER_DECL_FACTORY(SvxXConnectionPreview)
      50             : {
      51           0 :     WinBits nWinStyle = 0;
      52           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
      53           0 :     if (!sBorder.isEmpty())
      54           0 :         nWinStyle |= WB_BORDER;
      55           0 :     rRet = VclPtr<SvxXConnectionPreview>::Create(pParent, nWinStyle);
      56           0 : }
      57             : 
      58           0 : SvxXConnectionPreview::~SvxXConnectionPreview()
      59             : {
      60           0 :     disposeOnce();
      61           0 : }
      62             : 
      63           0 : void SvxXConnectionPreview::dispose()
      64             : {
      65           0 :     delete pObjList;
      66           0 :     Control::dispose();
      67           0 : }
      68             : 
      69           0 : void SvxXConnectionPreview::Resize()
      70             : {
      71           0 :     Control::Resize();
      72             : 
      73           0 :     AdaptSize();
      74             : 
      75           0 :     Invalidate();
      76           0 : }
      77             : 
      78           0 : Size SvxXConnectionPreview::GetOptimalSize() const
      79             : {
      80           0 :     return LogicToPixel(Size(118 , 121), MapMode(MAP_APPFONT));
      81             : }
      82             : 
      83           0 : void SvxXConnectionPreview::AdaptSize()
      84             : {
      85             :     // Adapt size
      86           0 :     if( pObjList )
      87             :     {
      88           0 :         SetMapMode( MAP_100TH_MM );
      89             : 
      90           0 :         OutputDevice* pOD = pView->GetFirstOutputDevice(); // GetWin( 0 );
      91           0 :         Rectangle aRect = pObjList->GetAllObjBoundRect();
      92             : 
      93           0 :         MapMode aMapMode = GetMapMode();
      94           0 :         aMapMode.SetMapUnit( pOD->GetMapMode().GetMapUnit() );
      95           0 :         SetMapMode( aMapMode );
      96             : 
      97           0 :         MapMode         aDisplayMap( aMapMode );
      98           0 :         Point           aNewPos;
      99           0 :         Size            aNewSize;
     100           0 :         const Size      aWinSize = PixelToLogic( GetOutputSizePixel(), aDisplayMap );
     101           0 :         const long      nWidth = aWinSize.Width();
     102           0 :         const long      nHeight = aWinSize.Height();
     103           0 :         if (aRect.GetHeight() == 0)
     104           0 :             return;
     105           0 :         double          fRectWH = (double) aRect.GetWidth() / aRect.GetHeight();
     106           0 :         if (nHeight == 0)
     107           0 :             return;
     108           0 :         double          fWinWH = (double) nWidth / nHeight;
     109             : 
     110             :         // Adapt bitmap to Thumb size (not here!)
     111           0 :         if ( fRectWH < fWinWH)
     112             :         {
     113           0 :             aNewSize.Width() = (long) ( (double) nHeight * fRectWH );
     114           0 :             aNewSize.Height()= nHeight;
     115             :         }
     116             :         else
     117             :         {
     118           0 :             aNewSize.Width() = nWidth;
     119           0 :             aNewSize.Height()= (long) ( (double) nWidth / fRectWH );
     120             :         }
     121             : 
     122           0 :         Fraction aFrac1( aWinSize.Width(), aRect.GetWidth() );
     123           0 :         Fraction aFrac2( aWinSize.Height(), aRect.GetHeight() );
     124           0 :         Fraction aMinFrac( aFrac1 <= aFrac2 ? aFrac1 : aFrac2 );
     125             : 
     126             :         // Implement MapMode
     127           0 :         aDisplayMap.SetScaleX( aMinFrac );
     128           0 :         aDisplayMap.SetScaleY( aMinFrac );
     129             : 
     130             :         // Centering
     131           0 :         aNewPos.X() = ( nWidth - aNewSize.Width() )  >> 1;
     132           0 :         aNewPos.Y() = ( nHeight - aNewSize.Height() ) >> 1;
     133             : 
     134           0 :         aDisplayMap.SetOrigin( LogicToLogic( aNewPos, aMapMode, aDisplayMap ) );
     135           0 :         SetMapMode( aDisplayMap );
     136             : 
     137             :         // Origin
     138           0 :         aNewPos = aDisplayMap.GetOrigin();
     139           0 :         aNewPos -= Point( aRect.TopLeft().X(), aRect.TopLeft().Y() );
     140           0 :         aDisplayMap.SetOrigin( aNewPos );
     141           0 :         SetMapMode( aDisplayMap );
     142             : 
     143           0 :         Point aPos;
     144           0 :         MouseEvent aMEvt( aPos, 1, MouseEventModifiers::NONE, MOUSE_RIGHT );
     145           0 :         MouseButtonDown( aMEvt );
     146             :     }
     147             : }
     148             : 
     149           0 : void SvxXConnectionPreview::Construct()
     150             : {
     151             :     DBG_ASSERT( pView, "No valid view is passed on! ");
     152             : 
     153           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     154           0 :     const size_t nMarkCount = rMarkList.GetMarkCount();
     155             : 
     156           0 :     if( nMarkCount >= 1 )
     157             :     {
     158           0 :         bool bFound = false;
     159             : 
     160           0 :         for( size_t i = 0; i < nMarkCount && !bFound; ++i )
     161             :         {
     162           0 :             const SdrObject* pObj = rMarkList.GetMark( i )->GetMarkedSdrObj();
     163           0 :             sal_uInt32 nInv = pObj->GetObjInventor();
     164           0 :             sal_uInt16 nId = pObj->GetObjIdentifier();
     165           0 :             if( nInv == SdrInventor && nId == OBJ_EDGE )
     166             :             {
     167           0 :                 bFound = true;
     168           0 :                 const SdrEdgeObj* pTmpEdgeObj = static_cast<const SdrEdgeObj*>(pObj);
     169           0 :                 pEdgeObj = pTmpEdgeObj->Clone();
     170             : 
     171           0 :                 SdrObjConnection& rConn1 = (SdrObjConnection&)pEdgeObj->GetConnection( true );
     172           0 :                 SdrObjConnection& rConn2 = (SdrObjConnection&)pEdgeObj->GetConnection( false );
     173             : 
     174           0 :                 rConn1 = pTmpEdgeObj->GetConnection( true );
     175           0 :                 rConn2 = pTmpEdgeObj->GetConnection( false );
     176             : 
     177           0 :                 SdrObject* pTmpObj1 = pTmpEdgeObj->GetConnectedNode( true );
     178           0 :                 SdrObject* pTmpObj2 = pTmpEdgeObj->GetConnectedNode( false );
     179             : 
     180             :                 // potential memory leak here (!). Create SdrObjList only when there is
     181             :                 // not yet one.
     182           0 :                 if(!pObjList)
     183             :                 {
     184           0 :                     pObjList = new SdrObjList( pView->GetModel(), NULL );
     185             :                 }
     186             : 
     187           0 :                 if( pTmpObj1 )
     188             :                 {
     189           0 :                     SdrObject* pObj1 = pTmpObj1->Clone();
     190           0 :                     pObjList->InsertObject( pObj1 );
     191           0 :                     pEdgeObj->ConnectToNode( true, pObj1 );
     192             :                 }
     193           0 :                 if( pTmpObj2 )
     194             :                 {
     195           0 :                     SdrObject* pObj2 = pTmpObj2->Clone();
     196           0 :                     pObjList->InsertObject( pObj2 );
     197           0 :                     pEdgeObj->ConnectToNode( false, pObj2 );
     198             :                 }
     199           0 :                 pObjList->InsertObject( pEdgeObj );
     200             :             }
     201             :         }
     202             :     }
     203             : 
     204           0 :     if( !pEdgeObj )
     205           0 :         pEdgeObj = new SdrEdgeObj();
     206             : 
     207           0 :     AdaptSize();
     208           0 : }
     209             : 
     210           0 : void SvxXConnectionPreview::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
     211             : {
     212           0 :     if (pObjList)
     213             :     {
     214             :         // #110094#
     215             :         // This will not work anymore. To not start at Adam and Eve, i will
     216             :         // ATM not try to change all this stuff to really using an own model
     217             :         // and a view. I will just try to provide a mechanism to paint such
     218             :         // objects without own model and without a page/view with the new
     219             :         // mechanism.
     220             : 
     221             :         // New stuff: Use a ObjectContactOfObjListPainter.
     222           0 :         sdr::contact::SdrObjectVector aObjectVector;
     223             : 
     224           0 :         for (size_t a = 0; a < pObjList->GetObjCount(); ++a)
     225             :         {
     226           0 :             SdrObject* pObject = pObjList->GetObj(a);
     227             :             DBG_ASSERT(pObject,
     228             :                 "SvxXConnectionPreview::Paint: Corrupt ObjectList (!)");
     229           0 :             aObjectVector.push_back(pObject);
     230             :         }
     231             : 
     232           0 :         sdr::contact::ObjectContactOfObjListPainter aPainter(rRenderContext, aObjectVector, 0);
     233           0 :         sdr::contact::DisplayInfo aDisplayInfo;
     234             : 
     235             :         // do processing
     236           0 :         aPainter.ProcessDisplay(aDisplayInfo);
     237             :     }
     238           0 : }
     239             : 
     240           0 : void SvxXConnectionPreview::SetAttributes( const SfxItemSet& rInAttrs )
     241             : {
     242           0 :     pEdgeObj->SetMergedItemSetAndBroadcast(rInAttrs);
     243             : 
     244           0 :     Invalidate();
     245           0 : }
     246             : 
     247             : 
     248             : // Get number of lines which are offset based on the preview object
     249             : 
     250           0 : sal_uInt16 SvxXConnectionPreview::GetLineDeltaAnz()
     251             : {
     252           0 :     const SfxItemSet& rSet = pEdgeObj->GetMergedItemSet();
     253           0 :     sal_uInt16 nCount(0);
     254             : 
     255           0 :     if(SfxItemState::DONTCARE != rSet.GetItemState(SDRATTR_EDGELINEDELTAANZ))
     256           0 :         nCount = static_cast<const SdrEdgeLineDeltaAnzItem&>(rSet.Get(SDRATTR_EDGELINEDELTAANZ)).GetValue();
     257             : 
     258           0 :     return nCount;
     259             : }
     260             : 
     261           0 : void SvxXConnectionPreview::MouseButtonDown( const MouseEvent& rMEvt )
     262             : {
     263           0 :     bool bZoomIn  = rMEvt.IsLeft() && !rMEvt.IsShift();
     264           0 :     bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
     265           0 :     bool bCtrl    = rMEvt.IsMod1();
     266             : 
     267           0 :     if( bZoomIn || bZoomOut )
     268             :     {
     269           0 :         MapMode aMapMode = GetMapMode();
     270           0 :         Fraction aXFrac = aMapMode.GetScaleX();
     271           0 :         Fraction aYFrac = aMapMode.GetScaleY();
     272           0 :         boost::scoped_ptr<Fraction> pMultFrac;
     273             : 
     274           0 :         if( bZoomIn )
     275             :         {
     276           0 :             if( bCtrl )
     277           0 :                 pMultFrac.reset(new Fraction( 3, 2 ));
     278             :             else
     279           0 :                 pMultFrac.reset(new Fraction( 11, 10 ));
     280             :         }
     281             :         else
     282             :         {
     283           0 :             if( bCtrl )
     284           0 :                 pMultFrac.reset(new Fraction( 2, 3 ));
     285             :             else
     286           0 :                 pMultFrac.reset(new Fraction( 10, 11 ));
     287             :         }
     288             : 
     289           0 :         aXFrac *= *pMultFrac;
     290           0 :         aYFrac *= *pMultFrac;
     291           0 :         if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
     292           0 :             (double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
     293             :         {
     294           0 :             aMapMode.SetScaleX( aXFrac );
     295           0 :             aMapMode.SetScaleY( aYFrac );
     296           0 :             SetMapMode( aMapMode );
     297             : 
     298           0 :             Size aOutSize( GetOutputSize() );
     299             : 
     300           0 :             Point aPt( aMapMode.GetOrigin() );
     301           0 :             long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac  ) ) / 2.0 + 0.5 );
     302           0 :             long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac  ) ) / 2.0 + 0.5 );
     303           0 :             aPt.X() +=  nX;
     304           0 :             aPt.Y() +=  nY;
     305             : 
     306           0 :             aMapMode.SetOrigin( aPt );
     307           0 :             SetMapMode( aMapMode );
     308             : 
     309           0 :             Invalidate();
     310           0 :         }
     311             :     }
     312           0 : }
     313             : 
     314           0 : void SvxXConnectionPreview::SetStyles()
     315             : {
     316           0 :     const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
     317           0 :     SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
     318           0 :     SetBackground( Wallpaper( Color( rStyles.GetFieldColor() ) ) );
     319           0 : }
     320             : 
     321           0 : void SvxXConnectionPreview::DataChanged( const DataChangedEvent& rDCEvt )
     322             : {
     323           0 :     Control::DataChanged( rDCEvt );
     324             : 
     325           0 :     if ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
     326             :     {
     327           0 :         SetStyles();
     328             :     }
     329         390 : }
     330             : 
     331             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11