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

Generated by: LCOV version 1.10