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

Generated by: LCOV version 1.11