LCOV - code coverage report
Current view: top level - sc/source/ui/drawfunc - fuconrec.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 97 1.0 %
Date: 2014-04-11 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 "fuconrec.hxx"
      22             : #include "tabvwsh.hxx"
      23             : #include "sc.hrc"
      24             : #include "drawview.hxx"
      25             : 
      26             : #include <editeng/outlobj.hxx>
      27             : // Create default drawing objects via keyboard
      28             : #include <svx/svdopath.hxx>
      29             : #include <svx/svdocapt.hxx>
      30             : #include <basegfx/polygon/b2dpolygon.hxx>
      31             : #include <basegfx/point/b2dpoint.hxx>
      32             : 
      33             : #include "scresid.hxx"
      34             : 
      35             : 
      36             : /*************************************************************************
      37             : |*
      38             : |* Konstruktor
      39             : |*
      40             : \************************************************************************/
      41             : 
      42           0 : FuConstRectangle::FuConstRectangle(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
      43             :                    SdrModel* pDoc, SfxRequest& rReq)
      44           0 :     : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
      45             : {
      46           0 : }
      47             : 
      48             : /*************************************************************************
      49             : |*
      50             : |* Destruktor
      51             : |*
      52             : \************************************************************************/
      53             : 
      54           0 : FuConstRectangle::~FuConstRectangle()
      55             : {
      56           0 : }
      57             : 
      58             : /*************************************************************************
      59             : |*
      60             : |* MouseButtonDown-event
      61             : |*
      62             : \************************************************************************/
      63             : 
      64           0 : bool FuConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)
      65             : {
      66             :     // remember button state for creation of own MouseEvents
      67           0 :     SetMouseButtonCode(rMEvt.GetButtons());
      68             : 
      69           0 :     bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
      70             : 
      71           0 :     if ( rMEvt.IsLeft() && !pView->IsAction() )
      72             :     {
      73           0 :         Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
      74             :         // Hack  to align object to nearest grid position where object
      75             :         // would be anchored ( if it were cell anchored )
      76             :         // Get grid offset for current position ( note: aPnt is
      77             :         // also adjusted )
      78           0 :         Point aGridOff = CurrentGridSyncOffsetAndPos( aPos );
      79           0 :         pWindow->CaptureMouse();
      80             : 
      81           0 :         if ( pView->GetCurrentObjIdentifier() == OBJ_CAPTION )
      82             :         {
      83           0 :             Size aCaptionSize ( 2268, 1134 ); // 4x2cm
      84             : 
      85           0 :             bReturn = pView->BegCreateCaptionObj( aPos, aCaptionSize );
      86             : 
      87             :             // wie stellt man den Font ein, mit dem geschrieben wird
      88             :         }
      89             :         else
      90           0 :             bReturn = pView->BegCreateObj(aPos);
      91           0 :         if ( bReturn )
      92           0 :             pView->GetCreateObj()->SetGridOffset( aGridOff );
      93             :     }
      94           0 :     return bReturn;
      95             : }
      96             : 
      97             : /*************************************************************************
      98             : |*
      99             : |* MouseMove-event
     100             : |*
     101             : \************************************************************************/
     102             : 
     103           0 : bool FuConstRectangle::MouseMove(const MouseEvent& rMEvt)
     104             : {
     105           0 :     return FuConstruct::MouseMove(rMEvt);
     106             : }
     107             : 
     108             : /*************************************************************************
     109             : |*
     110             : |* MouseButtonUp-event
     111             : |*
     112             : \************************************************************************/
     113             : 
     114           0 : bool FuConstRectangle::MouseButtonUp(const MouseEvent& rMEvt)
     115             : {
     116             :     // remember button state for creation of own MouseEvents
     117           0 :     SetMouseButtonCode(rMEvt.GetButtons());
     118             : 
     119           0 :     bool bReturn = false;
     120             : 
     121           0 :     if ( pView->IsCreateObj() && rMEvt.IsLeft() )
     122             :     {
     123           0 :         pView->EndCreateObj(SDRCREATE_FORCEEND);
     124             : 
     125           0 :         if (aSfxRequest.GetSlot() == SID_DRAW_CAPTION_VERTICAL)
     126             :         {
     127             :             //  set vertical flag for caption object
     128             : 
     129           0 :             const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     130           0 :             if (rMarkList.GetMark(0))
     131             :             {
     132           0 :                 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
     133             :                 //  create OutlinerParaObject now so it can be set to vertical
     134           0 :                 if ( pObj->ISA(SdrTextObj) )
     135           0 :                     ((SdrTextObj*)pObj)->ForceOutlinerParaObject();
     136           0 :                 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
     137           0 :                 if( pOPO && !pOPO->IsVertical() )
     138           0 :                     pOPO->SetVertical( true );
     139             :             }
     140             :         }
     141             : 
     142           0 :         bReturn = true;
     143             :     }
     144           0 :     return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
     145             : }
     146             : 
     147             : /*************************************************************************
     148             : |*
     149             : |* Tastaturereignisse bearbeiten
     150             : |*
     151             : |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
     152             : |* FALSE.
     153             : |*
     154             : \************************************************************************/
     155             : 
     156           0 : bool FuConstRectangle::KeyInput(const KeyEvent& rKEvt)
     157             : {
     158           0 :     return FuConstruct::KeyInput(rKEvt);
     159             : }
     160             : 
     161             : /*************************************************************************
     162             : |*
     163             : |* Function aktivieren
     164             : |*
     165             : \************************************************************************/
     166             : 
     167           0 : void FuConstRectangle::Activate()
     168             : {
     169             :     SdrObjKind aObjKind;
     170             : 
     171           0 :     switch (aSfxRequest.GetSlot() )
     172             :     {
     173             :         case SID_DRAW_LINE:
     174           0 :             aNewPointer = Pointer( POINTER_DRAW_LINE );
     175           0 :             aObjKind = OBJ_LINE;
     176           0 :             break;
     177             : 
     178             :         case SID_DRAW_RECT:
     179           0 :             aNewPointer = Pointer( POINTER_DRAW_RECT );
     180           0 :             aObjKind = OBJ_RECT;
     181           0 :             break;
     182             : 
     183             :         case SID_DRAW_ELLIPSE:
     184           0 :             aNewPointer = Pointer( POINTER_DRAW_ELLIPSE );
     185           0 :             aObjKind = OBJ_CIRC;
     186           0 :             break;
     187             : 
     188             :         case SID_DRAW_CAPTION:
     189             :         case SID_DRAW_CAPTION_VERTICAL:
     190           0 :             aNewPointer = Pointer( POINTER_DRAW_CAPTION );
     191           0 :             aObjKind = OBJ_CAPTION;
     192           0 :             break;
     193             : 
     194             :         default:
     195           0 :             aNewPointer = Pointer( POINTER_CROSS );
     196           0 :             aObjKind = OBJ_RECT;
     197           0 :             break;
     198             :     }
     199             : 
     200           0 :     pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(aObjKind));
     201             : 
     202           0 :     aOldPointer = pWindow->GetPointer();
     203           0 :     pViewShell->SetActivePointer( aNewPointer );
     204             : 
     205           0 :     FuConstruct::Activate();
     206           0 : }
     207             : 
     208             : /*************************************************************************
     209             : |*
     210             : |* Function deaktivieren
     211             : |*
     212             : \************************************************************************/
     213             : 
     214           0 : void FuConstRectangle::Deactivate()
     215             : {
     216           0 :     FuConstruct::Deactivate();
     217           0 :     pViewShell->SetActivePointer( aOldPointer );
     218           0 : }
     219             : 
     220             : // Create default drawing objects via keyboard
     221           0 : SdrObject* FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
     222             : {
     223             :     SdrObject* pObj = SdrObjFactory::MakeNewObject(
     224           0 :         pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
     225           0 :         0L, pDrDoc);
     226             : 
     227           0 :     if(pObj)
     228             :     {
     229           0 :         Rectangle aRect(rRectangle);
     230           0 :         Point aStart = aRect.TopLeft();
     231           0 :         Point aEnd = aRect.BottomRight();
     232             : 
     233           0 :         switch(nID)
     234             :         {
     235             :             case SID_DRAW_LINE:
     236             :             {
     237           0 :                 if(pObj->ISA(SdrPathObj))
     238             :                 {
     239           0 :                     sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
     240           0 :                     basegfx::B2DPolygon aPoly;
     241           0 :                     aPoly.append(basegfx::B2DPoint(aStart.X(), nYMiddle));
     242           0 :                     aPoly.append(basegfx::B2DPoint(aEnd.X(), nYMiddle));
     243           0 :                     ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aPoly));
     244             :                 }
     245             :                 else
     246             :                 {
     247             :                     OSL_FAIL("Object is NO line object");
     248             :                 }
     249             : 
     250           0 :                 break;
     251             :             }
     252             :             case SID_DRAW_CAPTION:
     253             :             case SID_DRAW_CAPTION_VERTICAL:
     254             :             {
     255           0 :                 if(pObj->ISA(SdrCaptionObj))
     256             :                 {
     257           0 :                     sal_Bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
     258             : 
     259           0 :                     ((SdrTextObj*)pObj)->SetVerticalWriting(bIsVertical);
     260             : 
     261           0 :                     if(bIsVertical)
     262             :                     {
     263           0 :                         SfxItemSet aSet(pObj->GetMergedItemSet());
     264           0 :                         aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
     265           0 :                         aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
     266           0 :                         pObj->SetMergedItemSet(aSet);
     267             :                     }
     268             : 
     269             :                     //  don't set default text, start edit mode instead
     270             :                     //  (Edit mode is started in ScTabViewShell::ExecDraw, because
     271             :                     //  it must be handled by FuText)
     272             :                     // String aText(ScResId(STR_CAPTION_DEFAULT_TEXT));
     273             :                     // ((SdrCaptionObj*)pObj)->SetText(aText);
     274             : 
     275           0 :                     ((SdrCaptionObj*)pObj)->SetLogicRect(aRect);
     276             :                     ((SdrCaptionObj*)pObj)->SetTailPos(
     277           0 :                         aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
     278             :                 }
     279             :                 else
     280             :                 {
     281             :                     OSL_FAIL("Object is NO caption object");
     282             :                 }
     283             : 
     284           0 :                 break;
     285             :             }
     286             : 
     287             :             default:
     288             :             {
     289           0 :                 pObj->SetLogicRect(aRect);
     290             : 
     291           0 :                 break;
     292             :             }
     293             :         }
     294             : 
     295           0 :         SfxItemSet aAttr(pDrDoc->GetItemPool());
     296           0 :         pObj->SetMergedItemSet(aAttr);
     297             :     }
     298             : 
     299           0 :     return pObj;
     300         102 : }
     301             : 
     302             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10