LCOV - code coverage report
Current view: top level - sd/source/ui/func - fusnapln.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 84 1.2 %
Date: 2014-11-03 Functions: 2 12 16.7 %
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 "fusnapln.hxx"
      21             : #include <svl/aeitem.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <sfx2/request.hxx>
      24             : 
      25             : #include "strings.hrc"
      26             : 
      27             : #include "sdattr.hxx"
      28             : #include "View.hxx"
      29             : #include "ViewShell.hxx"
      30             : #include "DrawViewShell.hxx"
      31             : #include "Window.hxx"
      32             : #include "sdenumdef.hxx"
      33             : #include "sdresid.hxx"
      34             : #include "sdabstdlg.hxx"
      35             : #include "app.hrc"
      36             : #include <svx/svdpagv.hxx>
      37             : #include <boost/scoped_ptr.hpp>
      38             : 
      39             : namespace sd {
      40             : 
      41           0 : TYPEINIT1( FuSnapLine, FuPoor );
      42             : 
      43           0 : FuSnapLine::FuSnapLine(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
      44             :                        SdDrawDocument* pDoc, SfxRequest& rReq) :
      45           0 :     FuPoor(pViewSh, pWin, pView, pDoc, rReq)
      46             : {
      47           0 : }
      48             : 
      49           0 : rtl::Reference<FuPoor> FuSnapLine::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
      50             : {
      51           0 :     rtl::Reference<FuPoor> xFunc( new FuSnapLine( pViewSh, pWin, pView, pDoc, rReq ) );
      52           0 :     xFunc->DoExecute(rReq);
      53           0 :     return xFunc;
      54             : }
      55             : 
      56           0 : void FuSnapLine::DoExecute( SfxRequest& rReq )
      57             : {
      58           0 :     const SfxItemSet* pArgs = rReq.GetArgs();
      59           0 :     sal_uInt16  nHelpLine = 0;
      60           0 :     bool    bCreateNew = true;
      61             : 
      62             :     // Get index of snap line or snap point from the request.
      63           0 :     SFX_REQUEST_ARG (rReq, pHelpLineIndex, SfxUInt32Item, ID_VAL_INDEX, false);
      64           0 :     if (pHelpLineIndex != NULL)
      65             :     {
      66           0 :         nHelpLine = static_cast<sal_uInt16>(pHelpLineIndex->GetValue());
      67             :         // Reset the argument pointer to trigger the display of the dialog.
      68           0 :         pArgs = NULL;
      69             :     }
      70             : 
      71           0 :     SdrPageView* pPV = mpView->GetSdrPageView();
      72             : 
      73           0 :     if (!pArgs)
      74             :     {
      75           0 :         SfxItemSet aNewAttr(mpViewShell->GetPool(), ATTR_SNAPLINE_START, ATTR_SNAPLINE_END);
      76           0 :         bool bLineExist (false);
      77           0 :         Point aLinePos;
      78             : 
      79           0 :         if (pHelpLineIndex == NULL)
      80             :         {
      81             :             // The index of the snap line is not provided as argument to the
      82             :             // request.  Determine it from the mouse position.
      83             : 
      84           0 :             aLinePos = static_cast<DrawViewShell*>(mpViewShell)->GetMousePos();
      85           0 :             static_cast<DrawViewShell*>(mpViewShell)->SetMousePosFreezed( false );
      86             : 
      87           0 :             if ( aLinePos.X() >= 0 )
      88             :             {
      89           0 :                 aLinePos = mpWindow->PixelToLogic(aLinePos);
      90           0 :                 sal_uInt16 nHitLog = (sal_uInt16) mpWindow->PixelToLogic(Size(HITPIX,0)).Width();
      91           0 :                 bLineExist = mpView->PickHelpLine(aLinePos, nHitLog, *mpWindow, nHelpLine, pPV);
      92           0 :                 if ( bLineExist )
      93           0 :                     aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
      94             :                 else
      95           0 :                     pPV = mpView->GetSdrPageView();
      96             : 
      97           0 :                 pPV->LogicToPagePos(aLinePos);
      98             :             }
      99             :             else
     100           0 :                 aLinePos = Point(0,0);
     101             :         }
     102             :         else
     103             :         {
     104             :             assert(pPV!=NULL);
     105           0 :             aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
     106           0 :             pPV->LogicToPagePos(aLinePos);
     107           0 :             bLineExist = true;
     108             :         }
     109           0 :         aNewAttr.Put(SfxInt32Item(ATTR_SNAPLINE_X, aLinePos.X()));
     110           0 :         aNewAttr.Put(SfxInt32Item(ATTR_SNAPLINE_Y, aLinePos.Y()));
     111             : 
     112           0 :         SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
     113           0 :         boost::scoped_ptr<AbstractSdSnapLineDlg> pDlg(pFact ? pFact->CreateSdSnapLineDlg( NULL, aNewAttr, mpView ) : 0);
     114             :         OSL_ASSERT(pDlg);
     115           0 :         if (!pDlg)
     116           0 :             return;
     117             : 
     118           0 :         if ( bLineExist )
     119             :         {
     120           0 :             pDlg->HideRadioGroup();
     121             : 
     122           0 :             const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
     123             : 
     124           0 :             if ( rHelpLine.GetKind() == SDRHELPLINE_POINT )
     125             :             {
     126           0 :                 pDlg->SetText(SD_RESSTR(STR_SNAPDLG_SETPOINT));
     127           0 :                 pDlg->SetInputFields(true, true);
     128             :             }
     129             :             else
     130             :             {
     131           0 :                 pDlg->SetText(SD_RESSTR(STR_SNAPDLG_SETLINE));
     132             : 
     133           0 :                 if ( rHelpLine.GetKind() == SDRHELPLINE_VERTICAL )
     134           0 :                     pDlg->SetInputFields(true, false);
     135             :                 else
     136           0 :                     pDlg->SetInputFields(false, true);
     137             :             }
     138           0 :             bCreateNew = false;
     139             :         }
     140             :         else
     141           0 :             pDlg->HideDeleteBtn();
     142             : 
     143           0 :         sal_uInt16 nResult = pDlg->Execute();
     144             : 
     145           0 :         pDlg->GetAttr(aNewAttr);
     146           0 :         pDlg.reset();
     147             : 
     148           0 :         switch( nResult )
     149             :         {
     150             :             case RET_OK:
     151           0 :                 rReq.Done(aNewAttr);
     152           0 :                 pArgs = rReq.GetArgs();
     153           0 :                 break;
     154             : 
     155             :             case RET_SNAP_DELETE:
     156             :                 // delete snap object
     157           0 :                 if ( !bCreateNew )
     158           0 :                     pPV->DeleteHelpLine(nHelpLine);
     159             :                 /*fall-through*/
     160             :             default:
     161           0 :                 return;
     162           0 :         }
     163             :     }
     164           0 :     Point aHlpPos;
     165             : 
     166           0 :     aHlpPos.X() = ((const SfxInt32Item&) pArgs->Get(ATTR_SNAPLINE_X)).GetValue();
     167           0 :     aHlpPos.Y() = ((const SfxInt32Item&) pArgs->Get(ATTR_SNAPLINE_Y)).GetValue();
     168           0 :     pPV->PagePosToLogic(aHlpPos);
     169             : 
     170           0 :     if ( bCreateNew )
     171             :     {
     172             :         SdrHelpLineKind eKind;
     173             : 
     174           0 :         pPV = mpView->GetSdrPageView();
     175             : 
     176           0 :         switch ( (SnapKind) ((const SfxAllEnumItem&)
     177           0 :                  pArgs->Get(ATTR_SNAPLINE_KIND)).GetValue() )
     178             :         {
     179           0 :             case SK_HORIZONTAL  : eKind = SDRHELPLINE_HORIZONTAL;   break;
     180           0 :             case SK_VERTICAL    : eKind = SDRHELPLINE_VERTICAL;     break;
     181           0 :             default             : eKind = SDRHELPLINE_POINT;        break;
     182             :         }
     183           0 :         pPV->InsertHelpLine(SdrHelpLine(eKind, aHlpPos));
     184             :     }
     185             :     else
     186             :     {
     187           0 :         const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
     188           0 :         pPV->SetHelpLine(nHelpLine, SdrHelpLine(rHelpLine.GetKind(), aHlpPos));
     189             :     }
     190             : }
     191             : 
     192           0 : void FuSnapLine::Activate()
     193             : {
     194           0 : }
     195             : 
     196           0 : void FuSnapLine::Deactivate()
     197             : {
     198           0 : }
     199             : 
     200         114 : } // end of namespace sd
     201             : 
     202             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10