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

Generated by: LCOV version 1.11