LCOV - code coverage report
Current view: top level - sw/source/uibase/uiview - viewdraw.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 7 375 1.9 %
Date: 2014-11-03 Functions: 4 22 18.2 %
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 "hintids.hxx"
      21             : #include <svl/aeitem.hxx>
      22             : #include <svl/itempool.hxx>
      23             : #include <svx/svdobj.hxx>
      24             : #include <svx/svdview.hxx>
      25             : #include <svx/svdpage.hxx>
      26             : #include <editeng/editview.hxx>
      27             : #include <editeng/editeng.hxx>
      28             : #include <editeng/outliner.hxx>
      29             : #include <svx/fmview.hxx>
      30             : #include <svx/dataaccessdescriptor.hxx>
      31             : #include <sfx2/viewfrm.hxx>
      32             : #include <doc.hxx>
      33             : #include <IDocumentDeviceAccess.hxx>
      34             : #include <textboxhelper.hxx>
      35             : #include <editeng/langitem.hxx>
      36             : #include <linguistic/lngprops.hxx>
      37             : #include <editeng/unolingu.hxx>
      38             : #include <svx/fontworkbar.hxx>
      39             : #include <svx/fontworkgallery.hxx>
      40             : #include <editeng/eeitem.hxx>
      41             : #include <svx/svdogrp.hxx>
      42             : #include <svx/svdetc.hxx>
      43             : #include <editeng/editstat.hxx>
      44             : #include <sfx2/request.hxx>
      45             : #include <sfx2/bindings.hxx>
      46             : #include <sfx2/printer.hxx>
      47             : #include <svx/fmglob.hxx>
      48             : #include <sfx2/dispatch.hxx>
      49             : #include <svx/svdoutl.hxx>
      50             : 
      51             : #include "view.hxx"
      52             : #include "wrtsh.hxx"
      53             : #include "viewopt.hxx"
      54             : #include "cmdid.h"
      55             : #include "drawsh.hxx"
      56             : #include "drwbassh.hxx"
      57             : #include "beziersh.hxx"
      58             : #include "conrect.hxx"
      59             : #include "conpoly.hxx"
      60             : #include "conarc.hxx"
      61             : #include "conform.hxx"
      62             : #include "concustomshape.hxx"
      63             : #include "dselect.hxx"
      64             : #include "edtwin.hxx"
      65             : 
      66             : #include <dcontact.hxx>
      67             : 
      68             : #include <svx/svdpagv.hxx>
      69             : #include <svx/extrusionbar.hxx>
      70             : #include <vcl/svapp.hxx>
      71             : 
      72             : using namespace ::com::sun::star;
      73             : 
      74             : // Execute Drawing-Ids
      75             : 
      76           0 : void SwView::ExecDraw(SfxRequest& rReq)
      77             : {
      78           0 :     const SfxItemSet *pArgs = rReq.GetArgs();
      79             :     const SfxPoolItem* pItem;
      80           0 :     const SfxAllEnumItem* pEItem = 0;
      81           0 :     const SfxStringItem* pStringItem = 0;
      82           0 :     SdrView *pSdrView = m_pWrtShell->GetDrawView();
      83           0 :     bool bDeselect = false;
      84             : 
      85           0 :     sal_uInt16 nSlotId = rReq.GetSlot();
      86           0 :     if(pArgs && SfxItemState::SET == pArgs->GetItemState(GetPool().GetWhich(nSlotId), false, &pItem))
      87             :     {
      88           0 :         pEItem = dynamic_cast< const SfxAllEnumItem*>(pItem);
      89           0 :         pStringItem = dynamic_cast< const SfxStringItem*>(pItem);
      90             :     }
      91             : 
      92           0 :     if (SID_INSERT_DRAW == nSlotId && pEItem)
      93           0 :         switch ( pEItem->GetValue() )
      94             :         {
      95           0 :             case SVX_SNAP_DRAW_SELECT:              nSlotId = SID_OBJECT_SELECT;            break;
      96           0 :             case SVX_SNAP_DRAW_LINE:                nSlotId = SID_DRAW_LINE;                break;
      97           0 :             case SVX_SNAP_DRAW_RECT:                nSlotId = SID_DRAW_RECT;                break;
      98           0 :             case SVX_SNAP_DRAW_ELLIPSE:             nSlotId = SID_DRAW_ELLIPSE;             break;
      99           0 :             case SVX_SNAP_DRAW_POLYGON_NOFILL:      nSlotId = SID_DRAW_POLYGON_NOFILL;      break;
     100           0 :             case SVX_SNAP_DRAW_BEZIER_NOFILL:       nSlotId = SID_DRAW_BEZIER_NOFILL;       break;
     101           0 :             case SVX_SNAP_DRAW_FREELINE_NOFILL:     nSlotId = SID_DRAW_FREELINE_NOFILL;     break;
     102           0 :             case SVX_SNAP_DRAW_ARC:                 nSlotId = SID_DRAW_ARC;                 break;
     103           0 :             case SVX_SNAP_DRAW_PIE:                 nSlotId = SID_DRAW_PIE;                 break;
     104           0 :             case SVX_SNAP_DRAW_CIRCLECUT:           nSlotId = SID_DRAW_CIRCLECUT;           break;
     105           0 :             case SVX_SNAP_DRAW_TEXT:                nSlotId = SID_DRAW_TEXT;                break;
     106           0 :             case SVX_SNAP_DRAW_TEXT_VERTICAL:       nSlotId = SID_DRAW_TEXT_VERTICAL;       break;
     107           0 :             case SVX_SNAP_DRAW_TEXT_MARQUEE:        nSlotId = SID_DRAW_TEXT_MARQUEE;        break;
     108           0 :             case SVX_SNAP_DRAW_CAPTION:             nSlotId = SID_DRAW_CAPTION;             break;
     109           0 :             case SVX_SNAP_DRAW_CAPTION_VERTICAL:    nSlotId = SID_DRAW_CAPTION_VERTICAL;    break;
     110             :         }
     111             : 
     112           0 :     if (nSlotId == SID_OBJECT_SELECT && m_nFormSfxId == nSlotId)
     113             :     {
     114           0 :         bDeselect = true;
     115             :     }
     116           0 :     else if (nSlotId == SID_FM_CREATE_CONTROL)
     117             :     {
     118           0 :         SFX_REQUEST_ARG( rReq, pIdentifierItem, SfxUInt16Item, SID_FM_CONTROL_IDENTIFIER, false );
     119           0 :         if( pIdentifierItem )
     120             :         {
     121           0 :             sal_uInt16 nNewId = pIdentifierItem->GetValue();
     122           0 :             if (nNewId == m_nFormSfxId)
     123             :             {
     124           0 :                 bDeselect = true;
     125           0 :                 GetViewFrame()->GetDispatcher()->Execute(SID_FM_LEAVE_CREATE);  // Button should popping out
     126             :             }
     127             :         }
     128             :     }
     129           0 :     else if( nSlotId == SID_FM_CREATE_FIELDCONTROL)
     130             :     {
     131           0 :         FmFormView* pFormView = PTR_CAST( FmFormView, pSdrView );
     132           0 :         if ( pFormView )
     133             :         {
     134           0 :             SFX_REQUEST_ARG( rReq, pDescriptorItem, SfxUnoAnyItem, SID_FM_DATACCESS_DESCRIPTOR, false );
     135             :             OSL_ENSURE( pDescriptorItem, "SwView::ExecDraw(SID_FM_CREATE_FIELDCONTROL): invalid request args!" );
     136           0 :             if( pDescriptorItem )
     137             :             {
     138           0 :                 ::svx::ODataAccessDescriptor aDescriptor( pDescriptorItem->GetValue() );
     139           0 :                 SdrObject* pObj = pFormView->CreateFieldControl( aDescriptor );
     140             : 
     141           0 :                 if ( pObj )
     142             :                 {
     143           0 :                     Size aDocSize(m_pWrtShell->GetDocSize());
     144           0 :                     const SwRect& rVisArea = m_pWrtShell->VisArea();
     145           0 :                     Point aStartPos = rVisArea.Center();
     146           0 :                     if(rVisArea.Width() > aDocSize.Width())
     147           0 :                         aStartPos.X() = aDocSize.Width() / 2 + rVisArea.Left();
     148           0 :                     if(rVisArea.Height() > aDocSize.Height())
     149           0 :                         aStartPos.Y() = aDocSize.Height() / 2 + rVisArea.Top();
     150             : 
     151             :                     //determine the size of the object
     152           0 :                     if(pObj->IsGroupObject())
     153             :                     {
     154           0 :                         const Rectangle& rBoundRect = ((SdrObjGroup*)pObj)->GetCurrentBoundRect();
     155           0 :                         aStartPos.X() -= rBoundRect.GetWidth()/2;
     156           0 :                         aStartPos.Y() -= rBoundRect.GetHeight()/2;
     157             :                     }
     158             : 
     159             :                     // TODO: unmark all other
     160           0 :                     m_pWrtShell->EnterStdMode();
     161           0 :                     m_pWrtShell->SwFEShell::InsertDrawObj( *pObj, aStartPos );
     162           0 :                 }
     163             :             }
     164             :         }
     165             :     }
     166           0 :     else if ( nSlotId == SID_FONTWORK_GALLERY_FLOATER )
     167             :     {
     168           0 :         vcl::Window*  pWin = &( m_pWrtShell->GetView().GetViewFrame()->GetWindow() );
     169             : 
     170           0 :         if ( pWin )
     171           0 :             pWin->EnterWait();
     172             : 
     173           0 :         if( !m_pWrtShell->HasDrawView() )
     174           0 :             m_pWrtShell->MakeDrawView();
     175             : 
     176           0 :         pSdrView = m_pWrtShell->GetDrawView();
     177           0 :         if ( pSdrView )
     178             :         {
     179           0 :             SdrObject* pObj = NULL;
     180           0 :             svx::FontWorkGalleryDialog aDlg( pSdrView, pWin, nSlotId );
     181           0 :             aDlg.SetSdrObjectRef( &pObj, pSdrView->GetModel() );
     182           0 :             aDlg.Execute();
     183           0 :             if ( pObj )
     184             :             {
     185           0 :                 Size            aDocSize( m_pWrtShell->GetDocSize() );
     186           0 :                 const SwRect&   rVisArea = m_pWrtShell->VisArea();
     187           0 :                 Point           aPos( rVisArea.Center() );
     188           0 :                 Size            aSize;
     189           0 :                 Size            aPrefSize( pObj->GetSnapRect().GetSize() );
     190             : 
     191           0 :                 if( rVisArea.Width() > aDocSize.Width())
     192           0 :                     aPos.X() = aDocSize.Width() / 2 + rVisArea.Left();
     193             : 
     194           0 :                 if(rVisArea.Height() > aDocSize.Height())
     195           0 :                     aPos.Y() = aDocSize.Height() / 2 + rVisArea.Top();
     196             : 
     197           0 :                 if( aPrefSize.Width() && aPrefSize.Height() )
     198             :                 {
     199           0 :                     if( pWin )
     200           0 :                         aSize = pWin->PixelToLogic( aPrefSize, MAP_TWIP );
     201             :                     else
     202           0 :                         aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_TWIP );
     203             :                 }
     204             :                 else
     205           0 :                     aSize = Size( 2835, 2835 );
     206             : 
     207           0 :                 m_pWrtShell->EnterStdMode();
     208           0 :                 m_pWrtShell->SwFEShell::InsertDrawObj( *pObj, aPos );
     209           0 :                 rReq.Ignore ();
     210           0 :             }
     211             :         }
     212           0 :         if( pWin )
     213           0 :             pWin->LeaveWait();
     214             :     }
     215             : 
     216           0 :     if( nSlotId == SID_DRAW_CS_ID )
     217             :     {
     218             :         //deselect if same custom shape is selected again
     219           0 :         SwDrawBase* pFuncPtr = GetDrawFuncPtr();
     220           0 :         if( pFuncPtr && pFuncPtr->GetSlotId() == SID_DRAW_CS_ID )
     221             :         {
     222           0 :             ConstCustomShape* pConstCustomShape = (ConstCustomShape*)(pFuncPtr);
     223           0 :             OUString aNew = ConstCustomShape::GetShapeTypeFromRequest( rReq );
     224           0 :             OUString aOld = pConstCustomShape->GetShapeType();
     225           0 :             if( aNew == aOld )
     226             :             {
     227           0 :                 bDeselect = true;
     228           0 :             }
     229             :         }
     230             :     }
     231             : 
     232             :     //deselect if same shape is selected again (but different custom shapes do have same slot id)
     233           0 :     if ( bDeselect || (nSlotId == m_nDrawSfxId &&
     234           0 :             (!pStringItem || (pStringItem->GetValue() == m_sDrawCustom))
     235           0 :                 && (nSlotId != SID_DRAW_CS_ID) ) )
     236             :     {
     237           0 :         if (GetDrawFuncPtr())
     238             :         {
     239           0 :             GetDrawFuncPtr()->Deactivate();
     240           0 :             SetDrawFuncPtr(NULL);
     241             :         }
     242             : 
     243           0 :         if (m_pWrtShell->IsObjSelected() && !m_pWrtShell->IsSelFrmMode())
     244           0 :             m_pWrtShell->EnterSelFrmMode(NULL);
     245           0 :         LeaveDrawCreate();
     246             : 
     247           0 :         GetViewFrame()->GetBindings().Invalidate(SID_INSERT_DRAW);
     248             : 
     249           0 :         AttrChangedNotify(m_pWrtShell);
     250           0 :         return;
     251             :     }
     252             : 
     253           0 :     LeaveDrawCreate();
     254             : 
     255           0 :     if (m_pWrtShell->IsFrmSelected())
     256           0 :         m_pWrtShell->EnterStdMode();  // because bug #45639
     257             : 
     258           0 :     SwDrawBase* pFuncPtr = NULL;
     259             : 
     260           0 :     switch (nSlotId)
     261             :     {
     262             :         case SID_OBJECT_SELECT:
     263             :         case SID_DRAW_SELECT:
     264           0 :             pFuncPtr = new DrawSelection(m_pWrtShell, m_pEditWin, this);
     265           0 :             m_nDrawSfxId = m_nFormSfxId = SID_OBJECT_SELECT;
     266           0 :             m_sDrawCustom = "";
     267           0 :             break;
     268             : 
     269             :         case SID_DRAW_LINE:
     270             :         case SID_DRAW_RECT:
     271             :         case SID_DRAW_ELLIPSE:
     272             :         case SID_DRAW_TEXT:
     273             :         case SID_DRAW_TEXT_VERTICAL:
     274             :         case SID_DRAW_TEXT_MARQUEE:
     275             :         case SID_DRAW_CAPTION:
     276             :         case SID_DRAW_CAPTION_VERTICAL:
     277           0 :             pFuncPtr = new ConstRectangle(m_pWrtShell, m_pEditWin, this);
     278           0 :             m_nDrawSfxId = nSlotId;
     279           0 :             m_sDrawCustom = "";
     280           0 :             break;
     281             : 
     282             :         case SID_DRAW_POLYGON_NOFILL:
     283             :         case SID_DRAW_BEZIER_NOFILL:
     284             :         case SID_DRAW_FREELINE_NOFILL:
     285           0 :             pFuncPtr = new ConstPolygon(m_pWrtShell, m_pEditWin, this);
     286           0 :             m_nDrawSfxId = nSlotId;
     287           0 :             m_sDrawCustom = "";
     288           0 :             break;
     289             : 
     290             :         case SID_DRAW_ARC:
     291             :         case SID_DRAW_PIE:
     292             :         case SID_DRAW_CIRCLECUT:
     293           0 :             pFuncPtr = new ConstArc(m_pWrtShell, m_pEditWin, this);
     294           0 :             m_nDrawSfxId = nSlotId;
     295           0 :             m_sDrawCustom = "";
     296           0 :             break;
     297             : 
     298             :         case SID_FM_CREATE_CONTROL:
     299             :         {
     300           0 :             SFX_REQUEST_ARG( rReq, pIdentifierItem, SfxUInt16Item, SID_FM_CONTROL_IDENTIFIER, false );
     301           0 :             if( pIdentifierItem )
     302           0 :                 nSlotId = pIdentifierItem->GetValue();
     303           0 :             pFuncPtr = new ConstFormControl(m_pWrtShell, m_pEditWin, this);
     304           0 :             m_nFormSfxId = nSlotId;
     305             :         }
     306           0 :         break;
     307             : 
     308             :         case SID_DRAWTBX_CS_BASIC :
     309             :         case SID_DRAWTBX_CS_SYMBOL :
     310             :         case SID_DRAWTBX_CS_ARROW :
     311             :         case SID_DRAWTBX_CS_FLOWCHART :
     312             :         case SID_DRAWTBX_CS_CALLOUT :
     313             :         case SID_DRAWTBX_CS_STAR :
     314             :         case SID_DRAW_CS_ID :
     315             :         {
     316           0 :             pFuncPtr = new ConstCustomShape(m_pWrtShell, m_pEditWin, this, rReq );
     317           0 :             m_nDrawSfxId = nSlotId;
     318           0 :             if ( nSlotId != SID_DRAW_CS_ID )
     319             :             {
     320           0 :                 if ( pStringItem )
     321             :                 {
     322           0 :                     m_sDrawCustom = pStringItem->GetValue();
     323           0 :                     m_aCurrShapeEnumCommand[ nSlotId - SID_DRAWTBX_CS_BASIC ] = m_sDrawCustom;
     324           0 :                     SfxBindings& rBind = GetViewFrame()->GetBindings();
     325           0 :                     rBind.Invalidate( nSlotId );
     326           0 :                     rBind.Update( nSlotId );
     327             :                 }
     328             :             }
     329             :         }
     330           0 :         break;
     331             : 
     332             :         default:
     333           0 :             break;
     334             :     }
     335             : 
     336             :     static sal_uInt16 const aInval[] =
     337             :     {
     338             :         // Slot IDs must be sorted when calling Invalidate!
     339             :         SID_ATTRIBUTES_AREA,
     340             :         SID_INSERT_DRAW,
     341             :         0
     342             :     };
     343           0 :     GetViewFrame()->GetBindings().Invalidate(aInval);
     344             : 
     345           0 :     bool bEndTextEdit = true;
     346           0 :     if (pFuncPtr)
     347             :     {
     348           0 :         if (GetDrawFuncPtr())
     349             :         {
     350           0 :             GetDrawFuncPtr()->Deactivate();
     351           0 :             SetDrawFuncPtr(NULL);
     352             :         }
     353             : 
     354           0 :         SetDrawFuncPtr(pFuncPtr);
     355           0 :         AttrChangedNotify(m_pWrtShell);
     356             : 
     357           0 :         pFuncPtr->Activate(nSlotId);
     358           0 :         NoRotate();
     359           0 :         if(rReq.GetModifier() == KEY_MOD1)
     360             :         {
     361           0 :             if(SID_OBJECT_SELECT == m_nDrawSfxId )
     362             :             {
     363           0 :                 m_pWrtShell->GotoObj(true);
     364             :             }
     365             :             else
     366             :             {
     367           0 :                 pFuncPtr->CreateDefaultObject();
     368           0 :                 pFuncPtr->Deactivate();
     369           0 :                 SetDrawFuncPtr(NULL);
     370           0 :                 LeaveDrawCreate();
     371           0 :                 m_pWrtShell->EnterStdMode();
     372           0 :                 SdrView *pTmpSdrView = m_pWrtShell->GetDrawView();
     373           0 :                 const SdrMarkList& rMarkList = pTmpSdrView->GetMarkedObjectList();
     374           0 :                 if(rMarkList.GetMarkCount() == 1 &&
     375           0 :                         (SID_DRAW_TEXT == nSlotId || SID_DRAW_TEXT_VERTICAL == nSlotId ||
     376             :                             SID_DRAW_TEXT_MARQUEE == nSlotId ))
     377             :                 {
     378           0 :                     SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
     379           0 :                     BeginTextEdit(pObj);
     380           0 :                     bEndTextEdit = false;
     381             :                 }
     382             :             }
     383             :         }
     384             :     }
     385             :     else
     386             :     {
     387           0 :         if (m_pWrtShell->IsObjSelected() && !m_pWrtShell->IsSelFrmMode())
     388           0 :             m_pWrtShell->EnterSelFrmMode(NULL);
     389             :     }
     390             : 
     391           0 :     if(bEndTextEdit && pSdrView && pSdrView->IsTextEdit())
     392           0 :         pSdrView->SdrEndTextEdit( true );
     393             : 
     394           0 :     AttrChangedNotify(m_pWrtShell);
     395             : }
     396             : 
     397             : // End drawing
     398             : 
     399           0 : void SwView::ExitDraw()
     400             : {
     401           0 :     NoRotate();
     402             : 
     403           0 :     if(m_pShell)
     404             :     {
     405             :         // the shell may be invalid at close/reload/SwitchToViewShell
     406           0 :         SfxDispatcher* pDispatch = GetViewFrame()->GetDispatcher();
     407           0 :         sal_uInt16 nIdx = 0;
     408           0 :         SfxShell* pTest = 0;
     409           0 :         do
     410             :         {
     411           0 :             pTest = pDispatch->GetShell(nIdx++);
     412             :         }
     413           0 :         while( pTest && pTest != this && pTest != m_pShell);
     414           0 :         if(pTest == m_pShell &&
     415             :             // don't call LeaveSelFrmMode() etc. for the below,
     416             :             // because objects may still be selected:
     417           0 :             !m_pShell->ISA(SwDrawBaseShell) &&
     418           0 :             !m_pShell->ISA(SwBezierShell) &&
     419           0 :             !m_pShell->ISA(svx::ExtrusionBar) &&
     420           0 :             !m_pShell->ISA(svx::FontworkBar))
     421             :         {
     422           0 :             SdrView *pSdrView = m_pWrtShell->GetDrawView();
     423             : 
     424           0 :             if (pSdrView && pSdrView->IsGroupEntered())
     425             :             {
     426           0 :                 pSdrView->LeaveOneGroup();
     427           0 :                 pSdrView->UnmarkAll();
     428           0 :                 GetViewFrame()->GetBindings().Invalidate(SID_ENTER_GROUP);
     429             :             }
     430             : 
     431           0 :             if (GetDrawFuncPtr())
     432             :             {
     433           0 :                 if (m_pWrtShell->IsSelFrmMode())
     434           0 :                     m_pWrtShell->LeaveSelFrmMode();
     435           0 :                 GetDrawFuncPtr()->Deactivate();
     436             : 
     437           0 :                 SetDrawFuncPtr(NULL);
     438           0 :                 LeaveDrawCreate();
     439             : 
     440           0 :                 GetViewFrame()->GetBindings().Invalidate(SID_INSERT_DRAW);
     441             :             }
     442           0 :             GetEditWin().SetPointer(Pointer(POINTER_TEXT));
     443             :         }
     444             :     }
     445           0 : }
     446             : 
     447             : // Disable rotate mode
     448             : 
     449           0 : void SwView::NoRotate()
     450             : {
     451           0 :     if (IsDrawRotate())
     452             :     {
     453           0 :         m_pWrtShell->SetDragMode(SDRDRAG_MOVE);
     454           0 :         FlipDrawRotate();
     455             : 
     456           0 :         const SfxBoolItem aTmp( SID_OBJECT_ROTATE, false );
     457           0 :         GetViewFrame()->GetBindings().SetState( aTmp );
     458             :     }
     459           0 : }
     460             : 
     461             : // Enable DrawTextEditMode
     462             : 
     463           0 : static bool lcl_isTextBox(SdrObject* pObject)
     464             : {
     465           0 :     if (SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(pObject->GetUserCall()))
     466             :     {
     467           0 :         if (SwFrmFmt* pFmt = pDrawContact->GetFmt())
     468           0 :             return SwTextBoxHelper::findTextBox(pFmt);
     469             :     }
     470           0 :     return false;
     471             : }
     472             : 
     473           0 : bool SwView::EnterDrawTextMode(const Point& aDocPos)
     474             : {
     475             :     SdrObject* pObj;
     476             :     SdrPageView* pPV;
     477           0 :     SwWrtShell *pSh = &GetWrtShell();
     478           0 :     SdrView *pSdrView = pSh->GetDrawView();
     479             :     OSL_ENSURE( pSdrView, "EnterDrawTextMode without DrawView?" );
     480             : 
     481           0 :     bool bReturn = false;
     482             : 
     483           0 :     sal_uInt16 nOld = pSdrView->GetHitTolerancePixel();
     484           0 :     pSdrView->SetHitTolerancePixel( 2 );
     485             : 
     486           0 :     if( pSdrView->IsMarkedHit( aDocPos ) &&
     487           0 :         !pSdrView->PickHandle( aDocPos ) && IsTextTool() &&
     488           0 :         pSdrView->PickObj( aDocPos, pSdrView->getHitTolLog(), pObj, pPV, SDRSEARCH_PICKTEXTEDIT ) &&
     489             : 
     490             :         // To allow SwDrawVirtObj text objects to be activated, allow their type, too.
     491           0 :         ( pObj->ISA( SdrTextObj ) ||
     492           0 :           ( pObj->ISA(SwDrawVirtObj) &&
     493           0 :             ((SwDrawVirtObj*)pObj)->GetReferencedObj().ISA(SdrTextObj) ) ) &&
     494             : 
     495           0 :         !m_pWrtShell->IsSelObjProtected(FLYPROTECT_CONTENT))
     496             :     {
     497             :         // Refuse to edit editeng text of the shape if it has textbox attached.
     498           0 :         if (!lcl_isTextBox(pObj))
     499           0 :             bReturn = BeginTextEdit( pObj, pPV, m_pEditWin, false );
     500             :     }
     501             : 
     502           0 :     pSdrView->SetHitTolerancePixel( nOld );
     503             : 
     504           0 :     return bReturn;
     505             : }
     506             : 
     507             : // Enable DrawTextEditMode
     508             : 
     509           0 : bool SwView::BeginTextEdit(SdrObject* pObj, SdrPageView* pPV, vcl::Window* pWin,
     510             :         bool bIsNewObj, bool bSetSelectionToStart)
     511             : {
     512           0 :     SwWrtShell *pSh = &GetWrtShell();
     513           0 :     SdrView *pSdrView = pSh->GetDrawView();
     514           0 :     SdrOutliner* pOutliner = ::SdrMakeOutliner(OUTLINERMODE_TEXTOBJECT, *pSdrView->GetModel());
     515           0 :     uno::Reference< linguistic2::XSpellChecker1 >  xSpell( ::GetSpellChecker() );
     516           0 :     if (pOutliner)
     517             :     {
     518           0 :         pOutliner->SetRefDevice(pSh->getIDocumentDeviceAccess()->getReferenceDevice(false));
     519           0 :         pOutliner->SetSpeller(xSpell);
     520           0 :         uno::Reference<linguistic2::XHyphenator> xHyphenator( ::GetHyphenator() );
     521           0 :         pOutliner->SetHyphenator( xHyphenator );
     522           0 :         pSh->SetCalcFieldValueHdl(pOutliner);
     523             : 
     524           0 :         sal_uInt32 nCntrl = pOutliner->GetControlWord();
     525           0 :         nCntrl |= EE_CNTRL_ALLOWBIGOBJS;
     526             : 
     527           0 :         const SwViewOption *pOpt = pSh->GetViewOptions();
     528             : 
     529           0 :         if (SwViewOption::IsFieldShadings())
     530           0 :             nCntrl |= EE_CNTRL_MARKFIELDS;
     531             :         else
     532           0 :             nCntrl &= ~EE_CNTRL_MARKFIELDS;
     533             : 
     534           0 :         if (pOpt->IsOnlineSpell())
     535           0 :             nCntrl |= EE_CNTRL_ONLINESPELLING;
     536             :         else
     537           0 :             nCntrl &= ~EE_CNTRL_ONLINESPELLING;
     538             : 
     539           0 :         pOutliner->SetControlWord(nCntrl);
     540           0 :         const SfxPoolItem& rItem = pSh->GetDoc()->GetDefault(RES_CHRATR_LANGUAGE);
     541           0 :         pOutliner->SetDefaultLanguage(((const SvxLanguageItem&)rItem).GetLanguage());
     542             : 
     543           0 :         if( bIsNewObj )
     544           0 :             pOutliner->SetVertical( SID_DRAW_TEXT_VERTICAL == m_nDrawSfxId ||
     545           0 :                                     SID_DRAW_CAPTION_VERTICAL == m_nDrawSfxId );
     546             : 
     547             :         // set default horizontal text direction at outliner
     548             :         EEHorizontalTextDirection aDefHoriTextDir =
     549           0 :             pSh->IsShapeDefaultHoriTextDirR2L() ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
     550           0 :         pOutliner->SetDefaultHorizontalTextDirection( aDefHoriTextDir );
     551             :     }
     552             : 
     553             :     // To allow editing the referenced object from a SwDrawVirtObj here
     554             :     // the original needs to be fetched evenually. This ATM activates the
     555             :     // text edit mode for the original object.
     556           0 :     SdrObject* pToBeActivated = pObj;
     557             : 
     558             :     // Always the original object is edited. To allow the TextEdit to happen
     559             :     // where the VirtObj is positioned, on demand a occurring offset is set at
     560             :     // the TextEdit object. That offset is used for creating and managing the
     561             :     // OutlinerView.
     562           0 :     Point aNewTextEditOffset(0, 0);
     563             : 
     564           0 :     if(pObj->ISA(SwDrawVirtObj))
     565             :     {
     566           0 :         SwDrawVirtObj* pVirtObj = (SwDrawVirtObj*)pObj;
     567           0 :         pToBeActivated = &((SdrObject&)pVirtObj->GetReferencedObj());
     568           0 :         aNewTextEditOffset = pVirtObj->GetOffset();
     569             :     }
     570             : 
     571             :     // set in each case, thus it will be correct for all objects
     572           0 :     ((SdrTextObj*)pToBeActivated)->SetTextEditOffset(aNewTextEditOffset);
     573             : 
     574           0 :     bool bRet(pSdrView->SdrBeginTextEdit( pToBeActivated, pPV, pWin, true, pOutliner, 0, false, false, false ));
     575             : 
     576             :     // #i7672#
     577             :     // Since SdrBeginTextEdit actually creates the OutlinerView and thus also
     578             :     // sets the background color, an own background color needs to be set
     579             :     // after TextEditing was started. This is now done here.
     580           0 :     if(bRet)
     581             :     {
     582           0 :         OutlinerView* pView = pSdrView->GetTextEditOutlinerView();
     583             : 
     584           0 :         if(pView)
     585             :         {
     586           0 :             Color aBackground(pSh->GetShapeBackgrd());
     587           0 :             pView->SetBackgroundColor(aBackground);
     588             :         }
     589             : 
     590             :         // editing should start at the end of text, spell checking at the beginning ...
     591           0 :         ESelection aNewSelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
     592           0 :         if (bSetSelectionToStart)
     593           0 :             aNewSelection = ESelection();
     594           0 :         if (pView)
     595             :         {
     596           0 :             pView->SetSelection(aNewSelection);
     597             :         }
     598             :     }
     599             : 
     600           0 :     return bRet;
     601             : }
     602             : 
     603             : // Is a DrawTextObjekt selected?
     604             : 
     605           0 : bool SwView::IsTextTool() const
     606             : {
     607             :     sal_uInt16 nId;
     608             :     sal_uInt32 nInvent;
     609           0 :     SdrView *pSdrView = GetWrtShell().GetDrawView();
     610             :     OSL_ENSURE( pSdrView, "IsTextTool without DrawView?" );
     611             : 
     612           0 :     if (pSdrView->IsCreateMode())
     613           0 :         pSdrView->SetCreateMode(false);
     614             : 
     615           0 :     pSdrView->TakeCurrentObj(nId,nInvent);
     616           0 :     return (nInvent==SdrInventor);
     617             : }
     618             : 
     619        5500 : SdrView* SwView::GetDrawView() const
     620             : {
     621        5500 :     return GetWrtShell().GetDrawView();
     622             : }
     623             : 
     624           0 : bool SwView::IsBezierEditMode()
     625             : {
     626           0 :     return (!IsDrawSelMode() && GetWrtShell().GetDrawView()->HasMarkablePoints());
     627             : }
     628             : 
     629           0 : bool SwView::IsFormMode() const
     630             : {
     631           0 :     if (GetDrawFuncPtr() && GetDrawFuncPtr()->IsCreateObj())
     632             :     {
     633           0 :         return (GetDrawFuncPtr()->IsInsertForm());
     634             :     }
     635             : 
     636           0 :     return AreOnlyFormsSelected();
     637             : }
     638             : 
     639        4706 : void SwView::SetDrawFuncPtr(SwDrawBase* pFuncPtr)
     640             : {
     641        4706 :     delete m_pDrawActual;
     642        4706 :     m_pDrawActual = pFuncPtr;
     643        4706 : }
     644             : 
     645           0 : void SwView::SetSelDrawSlot()
     646             : {
     647           0 :     m_nDrawSfxId = SID_OBJECT_SELECT;
     648           0 :     m_sDrawCustom = "";
     649           0 : }
     650             : 
     651           0 : bool SwView::AreOnlyFormsSelected() const
     652             : {
     653           0 :     if ( GetWrtShell().IsFrmSelected() )
     654           0 :         return false;
     655             : 
     656           0 :     bool bForm = true;
     657             : 
     658           0 :     SdrView* pSdrView = GetWrtShell().GetDrawView();
     659             : 
     660           0 :     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
     661           0 :     const size_t nCount = rMarkList.GetMarkCount();
     662             : 
     663           0 :     if (nCount)
     664             :     {
     665           0 :         for (size_t i = 0; i < nCount; ++i)
     666             :         {
     667             :             // Except controls, are still normal draw objects selected?
     668           0 :             SdrObject *pSdrObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
     669             : 
     670           0 :             if (!HasOnlyObj(pSdrObj, FmFormInventor))
     671             :             {
     672           0 :                 bForm = false;
     673           0 :                 break;
     674             :             }
     675             :         }
     676             :     }
     677             :     else
     678           0 :         bForm = false;
     679             : 
     680           0 :     return bForm;
     681             : }
     682             : 
     683           0 : bool SwView::HasDrwObj(SdrObject *pSdrObj) const
     684             : {
     685           0 :     bool bRet = false;
     686             : 
     687           0 :     if (pSdrObj->IsGroupObject())
     688             :     {
     689           0 :         SdrObjList* pList = pSdrObj->GetSubList();
     690           0 :         const size_t nCnt = pList->GetObjCount();
     691             : 
     692           0 :         for (size_t i = 0; i < nCnt; ++i)
     693           0 :             if ((bRet = HasDrwObj(pList->GetObj(i))))
     694           0 :                 break;
     695             :     }
     696           0 :     else if (SdrInventor == pSdrObj->GetObjInventor() || pSdrObj->Is3DObj())
     697           0 :         return true;
     698             : 
     699           0 :     return bRet;
     700             : }
     701             : 
     702           0 : bool SwView::HasOnlyObj(SdrObject *pSdrObj, sal_uInt32 eObjInventor) const
     703             : {
     704           0 :     bool bRet = false;
     705             : 
     706           0 :     if (pSdrObj->IsGroupObject())
     707             :     {
     708           0 :         SdrObjList* pList = pSdrObj->GetSubList();
     709           0 :         const size_t nCnt = pList->GetObjCount();
     710             : 
     711           0 :         for (size_t i = 0; i < nCnt; ++i)
     712           0 :             if ((bRet = HasOnlyObj(pList->GetObj(i), eObjInventor)) == false)
     713           0 :                 break;
     714             :     }
     715           0 :     else if (eObjInventor == pSdrObj->GetObjInventor())
     716           0 :         return true;
     717             : 
     718           0 :     return bRet;
     719             : }
     720             : 
     721             : //#i87414# mod
     722           0 : IMPL_LINK(SwView, OnlineSpellCallback, SpellCallbackInfo*, pInfo)
     723             : {
     724           0 :     if (pInfo->nCommand == SPELLCMD_STARTSPELLDLG)
     725           0 :         GetViewFrame()->GetDispatcher()->Execute( FN_SPELL_GRAMMAR_DIALOG, SfxCallMode::ASYNCHRON);
     726           0 :     return 0;
     727             : }
     728             : 
     729           0 : bool SwView::ExecDrwTxtSpellPopup(const Point& rPt)
     730             : {
     731           0 :     bool bRet = false;
     732           0 :     SdrView *pSdrView = m_pWrtShell->GetDrawView();
     733           0 :     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
     734           0 :     Point aPos( GetEditWin().LogicToPixel( rPt ) );
     735             : 
     736           0 :     if (pOLV->IsWrongSpelledWordAtPos( aPos ))
     737             :     {
     738           0 :         bRet = true;
     739           0 :         Link aLink = LINK(this, SwView, OnlineSpellCallback);
     740           0 :         pOLV->ExecuteSpellPopup( aPos,&aLink );
     741             :     }
     742           0 :     return bRet;
     743             : }
     744             : 
     745           0 : bool SwView::IsDrawTextHyphenate()
     746             : {
     747           0 :     SdrView *pSdrView = m_pWrtShell->GetDrawView();
     748           0 :     bool bHyphenate = false;
     749             : 
     750           0 :     SfxItemSet aNewAttr( pSdrView->GetModel()->GetItemPool(),
     751           0 :                             EE_PARA_HYPHENATE, EE_PARA_HYPHENATE );
     752           0 :     if( pSdrView->GetAttributes( aNewAttr ) &&
     753           0 :         aNewAttr.GetItemState( EE_PARA_HYPHENATE ) >= SfxItemState::DEFAULT )
     754           0 :         bHyphenate = ((const SfxBoolItem&)aNewAttr.Get( EE_PARA_HYPHENATE )).
     755           0 :                         GetValue();
     756             : 
     757           0 :     return bHyphenate;
     758             : }
     759             : 
     760           0 : void SwView::HyphenateDrawText()
     761             : {
     762           0 :     SdrView *pSdrView = m_pWrtShell->GetDrawView();
     763           0 :     bool bHyphenate = IsDrawTextHyphenate();
     764             : 
     765           0 :     SfxItemSet aSet( GetPool(), EE_PARA_HYPHENATE, EE_PARA_HYPHENATE );
     766           0 :     aSet.Put( SfxBoolItem( EE_PARA_HYPHENATE, !bHyphenate ) );
     767           0 :     pSdrView->SetAttributes( aSet );
     768           0 :     GetViewFrame()->GetBindings().Invalidate(FN_HYPHENATE_OPT_DLG);
     769         270 : }
     770             : 
     771             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10