LCOV - code coverage report
Current view: top level - sw/source/uibase/uiview - viewdraw.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 76 380 20.0 %
Date: 2015-06-13 12:38:46 Functions: 11 23 47.8 %
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 = static_cast<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 :             ScopedVclPtrInstance< 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 = static_cast<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.clear();
     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.clear();
     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.clear();
     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.clear();
     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           0 :                             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(PointerStyle::Text));
     443             :         }
     444             :     }
     445           0 : }
     446             : 
     447             : // Disable rotate mode
     448             : 
     449           1 : void SwView::NoRotate()
     450             : {
     451           1 :     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           1 : }
     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 (SwFrameFormat* pFormat = pDrawContact->GetFormat())
     468           0 :             return SwTextBoxHelper::findTextBox(pFormat);
     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, SdrSearchOptions::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 :             static_cast<SwDrawVirtObj*>(pObj)->GetReferencedObj().ISA(SdrTextObj) ) ) &&
     494             : 
     495           0 :         m_pWrtShell->IsSelObjProtected(FlyProtectFlags::Content) == FlyProtectFlags::NONE )
     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           2 : bool SwView::EnterShapeDrawTextMode(SdrObject* pObject)
     508             : {
     509           2 :     SdrView* pSdrView = GetWrtShell().GetDrawView();
     510           2 :     SdrPageView* pPageView = pSdrView->GetSdrPageView();
     511           2 :     return BeginTextEdit(pObject, pPageView, m_pEditWin);
     512             : }
     513             : 
     514             : // Enable DrawTextEditMode
     515             : 
     516           2 : bool SwView::BeginTextEdit(SdrObject* pObj, SdrPageView* pPV, vcl::Window* pWin,
     517             :         bool bIsNewObj, bool bSetSelectionToStart)
     518             : {
     519           2 :     SwWrtShell *pSh = &GetWrtShell();
     520           2 :     SdrView *pSdrView = pSh->GetDrawView();
     521           2 :     SdrOutliner* pOutliner = ::SdrMakeOutliner(OUTLINERMODE_TEXTOBJECT, *pSdrView->GetModel());
     522           2 :     uno::Reference< linguistic2::XSpellChecker1 >  xSpell( ::GetSpellChecker() );
     523           2 :     if (pOutliner)
     524             :     {
     525           2 :         pOutliner->SetRefDevice(pSh->getIDocumentDeviceAccess()->getReferenceDevice(false));
     526           2 :         pOutliner->SetSpeller(xSpell);
     527           2 :         uno::Reference<linguistic2::XHyphenator> xHyphenator( ::GetHyphenator() );
     528           2 :         pOutliner->SetHyphenator( xHyphenator );
     529           2 :         pSh->SetCalcFieldValueHdl(pOutliner);
     530             : 
     531           2 :         EEControlBits nCntrl = pOutliner->GetControlWord();
     532           2 :         nCntrl |= EEControlBits::ALLOWBIGOBJS;
     533             : 
     534           2 :         const SwViewOption *pOpt = pSh->GetViewOptions();
     535             : 
     536           2 :         if (SwViewOption::IsFieldShadings())
     537           2 :             nCntrl |= EEControlBits::MARKFIELDS;
     538             :         else
     539           0 :             nCntrl &= ~EEControlBits::MARKFIELDS;
     540             : 
     541           2 :         if (pOpt->IsOnlineSpell())
     542           2 :             nCntrl |= EEControlBits::ONLINESPELLING;
     543             :         else
     544           0 :             nCntrl &= ~EEControlBits::ONLINESPELLING;
     545             : 
     546           2 :         pOutliner->SetControlWord(nCntrl);
     547           2 :         const SfxPoolItem& rItem = pSh->GetDoc()->GetDefault(RES_CHRATR_LANGUAGE);
     548           2 :         pOutliner->SetDefaultLanguage(static_cast<const SvxLanguageItem&>(rItem).GetLanguage());
     549             : 
     550           2 :         if( bIsNewObj )
     551           0 :             pOutliner->SetVertical( SID_DRAW_TEXT_VERTICAL == m_nDrawSfxId ||
     552           0 :                                     SID_DRAW_CAPTION_VERTICAL == m_nDrawSfxId );
     553             : 
     554             :         // set default horizontal text direction at outliner
     555             :         EEHorizontalTextDirection aDefHoriTextDir =
     556           2 :             pSh->IsShapeDefaultHoriTextDirR2L() ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
     557           2 :         pOutliner->SetDefaultHorizontalTextDirection( aDefHoriTextDir );
     558             :     }
     559             : 
     560             :     // To allow editing the referenced object from a SwDrawVirtObj here
     561             :     // the original needs to be fetched evenually. This ATM activates the
     562             :     // text edit mode for the original object.
     563           2 :     SdrObject* pToBeActivated = pObj;
     564             : 
     565             :     // Always the original object is edited. To allow the TextEdit to happen
     566             :     // where the VirtObj is positioned, on demand a occurring offset is set at
     567             :     // the TextEdit object. That offset is used for creating and managing the
     568             :     // OutlinerView.
     569           2 :     Point aNewTextEditOffset(0, 0);
     570             : 
     571           2 :     if(pObj->ISA(SwDrawVirtObj))
     572             :     {
     573           0 :         SwDrawVirtObj* pVirtObj = static_cast<SwDrawVirtObj*>(pObj);
     574           0 :         pToBeActivated = &const_cast<SdrObject&>(pVirtObj->GetReferencedObj());
     575           0 :         aNewTextEditOffset = pVirtObj->GetOffset();
     576             :     }
     577             : 
     578             :     // set in each case, thus it will be correct for all objects
     579           2 :     static_cast<SdrTextObj*>(pToBeActivated)->SetTextEditOffset(aNewTextEditOffset);
     580             : 
     581           2 :     bool bRet(pSdrView->SdrBeginTextEdit( pToBeActivated, pPV, pWin, true, pOutliner, 0, false, false, false ));
     582             : 
     583             :     // #i7672#
     584             :     // Since SdrBeginTextEdit actually creates the OutlinerView and thus also
     585             :     // sets the background color, an own background color needs to be set
     586             :     // after TextEditing was started. This is now done here.
     587           2 :     if(bRet)
     588             :     {
     589           2 :         OutlinerView* pView = pSdrView->GetTextEditOutlinerView();
     590             : 
     591           2 :         if(pView)
     592             :         {
     593           2 :             Color aBackground(pSh->GetShapeBackgrd());
     594           2 :             pView->SetBackgroundColor(aBackground);
     595             :         }
     596             : 
     597             :         // editing should start at the end of text, spell checking at the beginning ...
     598           2 :         ESelection aNewSelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
     599           2 :         if (bSetSelectionToStart)
     600           0 :             aNewSelection = ESelection();
     601           2 :         if (pView)
     602             :         {
     603           2 :             pView->SetSelection(aNewSelection);
     604             :         }
     605             :     }
     606             : 
     607           2 :     return bRet;
     608             : }
     609             : 
     610             : // Is a DrawTextObjekt selected?
     611             : 
     612           0 : bool SwView::IsTextTool() const
     613             : {
     614             :     sal_uInt16 nId;
     615             :     sal_uInt32 nInvent;
     616           0 :     SdrView *pSdrView = GetWrtShell().GetDrawView();
     617             :     OSL_ENSURE( pSdrView, "IsTextTool without DrawView?" );
     618             : 
     619           0 :     if (pSdrView->IsCreateMode())
     620           0 :         pSdrView->SetCreateMode(false);
     621             : 
     622           0 :     pSdrView->TakeCurrentObj(nId,nInvent);
     623           0 :     return (nInvent==SdrInventor);
     624             : }
     625             : 
     626        3248 : SdrView* SwView::GetDrawView() const
     627             : {
     628        3248 :     return GetWrtShell().GetDrawView();
     629             : }
     630             : 
     631           2 : bool SwView::IsBezierEditMode()
     632             : {
     633           2 :     return (!IsDrawSelMode() && GetWrtShell().GetDrawView()->HasMarkablePoints());
     634             : }
     635             : 
     636           2 : bool SwView::IsFormMode() const
     637             : {
     638           2 :     if (GetDrawFuncPtr() && GetDrawFuncPtr()->IsCreateObj())
     639             :     {
     640           0 :         return (GetDrawFuncPtr()->IsInsertForm());
     641             :     }
     642             : 
     643           2 :     return AreOnlyFormsSelected();
     644             : }
     645             : 
     646        2757 : void SwView::SetDrawFuncPtr(SwDrawBase* pFuncPtr)
     647             : {
     648        2757 :     delete m_pDrawActual;
     649        2757 :     m_pDrawActual = pFuncPtr;
     650        2757 : }
     651             : 
     652           0 : void SwView::SetSelDrawSlot()
     653             : {
     654           0 :     m_nDrawSfxId = SID_OBJECT_SELECT;
     655           0 :     m_sDrawCustom.clear();
     656           0 : }
     657             : 
     658           2 : bool SwView::AreOnlyFormsSelected() const
     659             : {
     660           2 :     if ( GetWrtShell().IsFrmSelected() )
     661           0 :         return false;
     662             : 
     663           2 :     bool bForm = true;
     664             : 
     665           2 :     SdrView* pSdrView = GetWrtShell().GetDrawView();
     666             : 
     667           2 :     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
     668           2 :     const size_t nCount = rMarkList.GetMarkCount();
     669             : 
     670           2 :     if (nCount)
     671             :     {
     672           2 :         for (size_t i = 0; i < nCount; ++i)
     673             :         {
     674             :             // Except controls, are still normal draw objects selected?
     675           2 :             SdrObject *pSdrObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
     676             : 
     677           2 :             if (!HasOnlyObj(pSdrObj, FmFormInventor))
     678             :             {
     679           2 :                 bForm = false;
     680           2 :                 break;
     681             :             }
     682             :         }
     683             :     }
     684             :     else
     685           0 :         bForm = false;
     686             : 
     687           2 :     return bForm;
     688             : }
     689             : 
     690           0 : bool SwView::HasDrwObj(SdrObject *pSdrObj) const
     691             : {
     692           0 :     bool bRet = false;
     693             : 
     694           0 :     if (pSdrObj->IsGroupObject())
     695             :     {
     696           0 :         SdrObjList* pList = pSdrObj->GetSubList();
     697           0 :         const size_t nCnt = pList->GetObjCount();
     698             : 
     699           0 :         for (size_t i = 0; i < nCnt; ++i)
     700           0 :             if ((bRet = HasDrwObj(pList->GetObj(i))))
     701           0 :                 break;
     702             :     }
     703           0 :     else if (SdrInventor == pSdrObj->GetObjInventor() || pSdrObj->Is3DObj())
     704           0 :         return true;
     705             : 
     706           0 :     return bRet;
     707             : }
     708             : 
     709           2 : bool SwView::HasOnlyObj(SdrObject *pSdrObj, sal_uInt32 eObjInventor) const
     710             : {
     711           2 :     bool bRet = false;
     712             : 
     713           2 :     if (pSdrObj->IsGroupObject())
     714             :     {
     715           0 :         SdrObjList* pList = pSdrObj->GetSubList();
     716           0 :         const size_t nCnt = pList->GetObjCount();
     717             : 
     718           0 :         for (size_t i = 0; i < nCnt; ++i)
     719           0 :             if (!(bRet = HasOnlyObj(pList->GetObj(i), eObjInventor)))
     720           0 :                 break;
     721             :     }
     722           2 :     else if (eObjInventor == pSdrObj->GetObjInventor())
     723           0 :         return true;
     724             : 
     725           2 :     return bRet;
     726             : }
     727             : 
     728             : //#i87414# mod
     729           0 : IMPL_LINK(SwView, OnlineSpellCallback, SpellCallbackInfo*, pInfo)
     730             : {
     731           0 :     if (pInfo->nCommand == SpellCallbackCommand::STARTSPELLDLG)
     732           0 :         GetViewFrame()->GetDispatcher()->Execute( FN_SPELL_GRAMMAR_DIALOG, SfxCallMode::ASYNCHRON);
     733           0 :     return 0;
     734             : }
     735             : 
     736           0 : bool SwView::ExecDrwTextSpellPopup(const Point& rPt)
     737             : {
     738           0 :     bool bRet = false;
     739           0 :     SdrView *pSdrView = m_pWrtShell->GetDrawView();
     740           0 :     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
     741           0 :     Point aPos( GetEditWin().LogicToPixel( rPt ) );
     742             : 
     743           0 :     if (pOLV->IsWrongSpelledWordAtPos( aPos ))
     744             :     {
     745           0 :         bRet = true;
     746           0 :         Link<> aLink = LINK(this, SwView, OnlineSpellCallback);
     747           0 :         pOLV->ExecuteSpellPopup( aPos,&aLink );
     748             :     }
     749           0 :     return bRet;
     750             : }
     751             : 
     752           0 : bool SwView::IsDrawTextHyphenate()
     753             : {
     754           0 :     SdrView *pSdrView = m_pWrtShell->GetDrawView();
     755           0 :     bool bHyphenate = false;
     756             : 
     757           0 :     SfxItemSet aNewAttr( pSdrView->GetModel()->GetItemPool(),
     758           0 :                             EE_PARA_HYPHENATE, EE_PARA_HYPHENATE );
     759           0 :     if( pSdrView->GetAttributes( aNewAttr ) &&
     760           0 :         aNewAttr.GetItemState( EE_PARA_HYPHENATE ) >= SfxItemState::DEFAULT )
     761           0 :         bHyphenate = static_cast<const SfxBoolItem&>(aNewAttr.Get( EE_PARA_HYPHENATE )).
     762           0 :                         GetValue();
     763             : 
     764           0 :     return bHyphenate;
     765             : }
     766             : 
     767           0 : void SwView::HyphenateDrawText()
     768             : {
     769           0 :     SdrView *pSdrView = m_pWrtShell->GetDrawView();
     770           0 :     bool bHyphenate = IsDrawTextHyphenate();
     771             : 
     772           0 :     SfxItemSet aSet( GetPool(), EE_PARA_HYPHENATE, EE_PARA_HYPHENATE );
     773           0 :     aSet.Put( SfxBoolItem( EE_PARA_HYPHENATE, !bHyphenate ) );
     774           0 :     pSdrView->SetAttributes( aSet );
     775           0 :     GetViewFrame()->GetBindings().Invalidate(FN_HYPHENATE_OPT_DLG);
     776         177 : }
     777             : 
     778             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11