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

Generated by: LCOV version 1.10