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

Generated by: LCOV version 1.10