Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / uiview / viewdraw.cxx
blob9e718ee379ea94a4d18c9218df14b3970236889a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <hintids.hxx>
21 #include <svl/itempool.hxx>
22 #include <svl/stritem.hxx>
23 #include <svx/svdobj.hxx>
24 #include <svx/svdview.hxx>
25 #include <svx/svdpage.hxx>
26 #include <editeng/outliner.hxx>
27 #include <svx/fmview.hxx>
28 #include <svx/dataaccessdescriptor.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <doc.hxx>
31 #include <IDocumentDeviceAccess.hxx>
32 #include <textboxhelper.hxx>
33 #include <editeng/langitem.hxx>
34 #include <svx/fontworkbar.hxx>
35 #include <svx/fontworkgallery.hxx>
36 #include <editeng/eeitem.hxx>
37 #include <svx/svdogrp.hxx>
38 #include <svx/svdetc.hxx>
39 #include <editeng/editstat.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/bindings.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <svx/svdoutl.hxx>
44 #include <vcl/ptrstyle.hxx>
45 #include <osl/diagnose.h>
47 #include <view.hxx>
48 #include <wrtsh.hxx>
49 #include <viewopt.hxx>
50 #include <cmdid.h>
51 #include <drwbassh.hxx>
52 #include <beziersh.hxx>
53 #include <conrect.hxx>
54 #include <conpoly.hxx>
55 #include <conarc.hxx>
56 #include <conform.hxx>
57 #include <concustomshape.hxx>
58 #include <dselect.hxx>
59 #include <edtwin.hxx>
61 #include <dcontact.hxx>
63 #include <svx/svdpagv.hxx>
64 #include <svx/extrusionbar.hxx>
65 #include <comphelper/lok.hxx>
66 #include <sfx2/lokhelper.hxx>
67 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
69 using namespace ::com::sun::star;
71 // Execute Drawing-Ids
73 void SwView::ExecDraw(const SfxRequest& rReq)
75 const SfxItemSet *pArgs = rReq.GetArgs();
76 const SfxPoolItem* pItem;
77 const SfxStringItem* pStringItem = nullptr;
78 SdrView *pSdrView = m_pWrtShell->GetDrawView();
79 bool bDeselect = false;
81 sal_uInt16 nSlotId = rReq.GetSlot();
82 if(pArgs && SfxItemState::SET == pArgs->GetItemState(GetPool().GetWhich(nSlotId), false, &pItem))
83 pStringItem = dynamic_cast< const SfxStringItem*>(pItem);
85 SdrObjKind eNewFormObjKind = SdrObjKind::NONE;
86 if (nSlotId == SID_FM_CREATE_CONTROL)
88 const SfxUInt16Item* pIdentifierItem = rReq.GetArg<SfxUInt16Item>(SID_FM_CONTROL_IDENTIFIER);
89 if (pIdentifierItem)
90 eNewFormObjKind = static_cast<SdrObjKind>(pIdentifierItem->GetValue());
93 if (nSlotId == SID_OBJECT_SELECT && m_nFormSfxId == nSlotId)
95 bDeselect = true;
97 else if (nSlotId == SID_FM_CREATE_CONTROL)
99 if (eNewFormObjKind == m_eFormObjKind || eNewFormObjKind == SdrObjKind::NONE)
101 bDeselect = true;
102 GetViewFrame().GetDispatcher()->Execute(SID_FM_LEAVE_CREATE); // Button should popping out
105 else if (nSlotId == SID_FM_CREATE_FIELDCONTROL)
107 FmFormView* pFormView = dynamic_cast<FmFormView*>(pSdrView);
108 if (pFormView)
110 const SfxUnoAnyItem* pDescriptorItem = rReq.GetArg<SfxUnoAnyItem>(SID_FM_DATACCESS_DESCRIPTOR);
111 OSL_ENSURE( pDescriptorItem, "SwView::ExecDraw(SID_FM_CREATE_FIELDCONTROL): invalid request args!" );
112 if( pDescriptorItem )
114 svx::ODataAccessDescriptor aDescriptor( pDescriptorItem->GetValue() );
115 rtl::Reference<SdrObject> pObj = pFormView->CreateFieldControl( aDescriptor );
117 if ( pObj )
119 Size aDocSize(m_pWrtShell->GetDocSize());
120 const SwRect& rVisArea = m_pWrtShell->VisArea();
121 Point aStartPos = rVisArea.Center();
122 if(rVisArea.Width() > aDocSize.Width())
123 aStartPos.setX( aDocSize.Width() / 2 + rVisArea.Left() );
124 if(rVisArea.Height() > aDocSize.Height())
125 aStartPos.setY( aDocSize.Height() / 2 + rVisArea.Top() );
127 //determine the size of the object
128 if(pObj->IsGroupObject())
130 const tools::Rectangle& rBoundRect = static_cast<SdrObjGroup*>(pObj.get())->GetCurrentBoundRect();
131 aStartPos.AdjustX( -(rBoundRect.GetWidth()/2) );
132 aStartPos.AdjustY( -(rBoundRect.GetHeight()/2) );
135 // TODO: unmark all other
136 m_pWrtShell->EnterStdMode();
137 m_pWrtShell->SwFEShell::InsertDrawObj( *pObj, aStartPos );
142 else if ( nSlotId == SID_FONTWORK_GALLERY_FLOATER )
144 vcl::Window& rWin = m_pWrtShell->GetView().GetViewFrame().GetWindow();
146 rWin.EnterWait();
148 if( !m_pWrtShell->HasDrawView() )
149 m_pWrtShell->MakeDrawView();
151 pSdrView = m_pWrtShell->GetDrawView();
152 if (pSdrView)
154 std::shared_ptr<svx::FontWorkGalleryDialog> pDlg = std::make_shared<svx::FontWorkGalleryDialog>(rWin.GetFrameWeld(), *pSdrView);
155 pDlg->SetSdrObjectRef(&pSdrView->GetModel());
156 weld::DialogController::runAsync(pDlg, [this, pDlg](int) {
157 vcl::Window& rWin2 = m_pWrtShell->GetView().GetViewFrame().GetWindow();
159 SdrObject* pObj = pDlg->GetSdrObjectRef();
160 if ( pObj )
162 Size aDocSize( m_pWrtShell->GetDocSize() );
163 const SwRect& rVisArea = comphelper::LibreOfficeKit::isActive() ?
164 SwRect(m_pWrtShell->getLOKVisibleArea()) : m_pWrtShell->VisArea();
165 Point aPos( rVisArea.Center() );
166 tools::Rectangle aObjRect( pObj->GetLogicRect() );
168 if ( rVisArea.Width() > aDocSize.Width())
169 aPos.setX( aDocSize.Width() / 2 + rVisArea.Left() );
170 else if (aPos.getX() > aObjRect.GetWidth() / 2)
171 aPos.AdjustX( -(aObjRect.GetWidth() / 2) );
173 if (rVisArea.Height() > aDocSize.Height())
174 aPos.setY( aDocSize.Height() / 2 + rVisArea.Top() );
175 else if (aPos.getY() > aObjRect.GetHeight() / 2)
176 aPos.AdjustY( -(aObjRect.GetHeight() / 2) );
178 m_pWrtShell->EnterStdMode();
179 m_pWrtShell->SwFEShell::InsertDrawObj( *pObj, aPos );
182 rWin2.LeaveWait();
185 else
186 rWin.LeaveWait();
188 else if ( m_nFormSfxId != USHRT_MAX )
189 GetViewFrame().GetDispatcher()->Execute( SID_FM_LEAVE_CREATE );
191 if( nSlotId == SID_DRAW_CS_ID )
193 //deselect if same custom shape is selected again
194 SwDrawBase* pFuncPtr = GetDrawFuncPtr();
195 if( pFuncPtr && pFuncPtr->GetSlotId() == SID_DRAW_CS_ID )
197 ConstCustomShape* pConstCustomShape = static_cast<ConstCustomShape*>(pFuncPtr);
198 OUString aNew = ConstCustomShape::GetShapeTypeFromRequest( rReq );
199 const OUString& aOld = pConstCustomShape->GetShapeType();
200 if( aNew == aOld )
202 bDeselect = true;
207 //deselect if same shape is selected again (but different custom shapes do have same slot id)
208 if ( bDeselect || (nSlotId == m_nDrawSfxId &&
209 (!pStringItem || (pStringItem->GetValue() == m_sDrawCustom))
210 && (nSlotId != SID_DRAW_CS_ID) ) )
212 if (GetDrawFuncPtr())
214 GetDrawFuncPtr()->Deactivate();
215 SetDrawFuncPtr(nullptr);
218 if (m_pWrtShell->IsObjSelected() && !m_pWrtShell->IsSelFrameMode())
219 m_pWrtShell->EnterSelFrameMode();
220 LeaveDrawCreate();
222 AttrChangedNotify(nullptr);
223 return;
226 LeaveDrawCreate();
228 if (m_pWrtShell->IsFrameSelected())
229 m_pWrtShell->EnterStdMode(); // because bug #45639
231 std::unique_ptr<SwDrawBase> pFuncPtr;
233 // for LibreOfficeKit - choosing a shape should construct it directly
234 bool bCreateDirectly = false;
236 switch (nSlotId)
238 case SID_OBJECT_SELECT:
239 case SID_DRAW_SELECT:
240 pFuncPtr.reset( new DrawSelection(m_pWrtShell.get(), m_pEditWin, this) );
241 m_nDrawSfxId = m_nFormSfxId = SID_OBJECT_SELECT;
242 m_sDrawCustom.clear();
243 break;
245 case SID_LINE_ARROW_END:
246 case SID_LINE_ARROW_CIRCLE:
247 case SID_LINE_ARROW_SQUARE:
248 case SID_LINE_ARROW_START:
249 case SID_LINE_CIRCLE_ARROW:
250 case SID_LINE_SQUARE_ARROW:
251 case SID_LINE_ARROWS:
252 case SID_DRAW_LINE:
253 case SID_DRAW_XLINE:
254 case SID_DRAW_MEASURELINE:
255 case SID_DRAW_RECT:
256 case SID_DRAW_ELLIPSE:
257 case SID_DRAW_TEXT:
258 case SID_DRAW_TEXT_VERTICAL:
259 case SID_DRAW_TEXT_MARQUEE:
260 case SID_DRAW_CAPTION:
261 case SID_DRAW_CAPTION_VERTICAL:
262 pFuncPtr.reset( new ConstRectangle(m_pWrtShell.get(), m_pEditWin, this) );
263 bCreateDirectly = comphelper::LibreOfficeKit::isActive();
264 m_nDrawSfxId = nSlotId;
265 m_sDrawCustom.clear();
266 break;
268 case SID_DRAW_XPOLYGON_NOFILL:
269 case SID_DRAW_XPOLYGON:
270 case SID_DRAW_POLYGON_NOFILL:
271 case SID_DRAW_POLYGON:
272 case SID_DRAW_BEZIER_NOFILL:
273 case SID_DRAW_BEZIER_FILL:
274 case SID_DRAW_FREELINE_NOFILL:
275 case SID_DRAW_FREELINE:
276 pFuncPtr.reset( new ConstPolygon(m_pWrtShell.get(), m_pEditWin, this) );
277 m_nDrawSfxId = nSlotId;
278 m_sDrawCustom.clear();
279 break;
281 case SID_DRAW_ARC:
282 case SID_DRAW_PIE:
283 case SID_DRAW_CIRCLECUT:
284 pFuncPtr.reset( new ConstArc(m_pWrtShell.get(), m_pEditWin, this) );
285 m_nDrawSfxId = nSlotId;
286 m_sDrawCustom.clear();
287 break;
289 case SID_FM_CREATE_CONTROL:
291 pFuncPtr.reset(new ConstFormControl(m_pWrtShell.get(), m_pEditWin, this, eNewFormObjKind));
292 m_nFormSfxId = nSlotId;
293 m_eFormObjKind = eNewFormObjKind;
295 break;
297 case SID_DRAWTBX_CS_BASIC :
298 case SID_DRAWTBX_CS_SYMBOL :
299 case SID_DRAWTBX_CS_ARROW :
300 case SID_DRAWTBX_CS_FLOWCHART :
301 case SID_DRAWTBX_CS_CALLOUT :
302 case SID_DRAWTBX_CS_STAR :
303 case SID_DRAW_CS_ID :
305 pFuncPtr.reset( new ConstCustomShape(m_pWrtShell.get(), m_pEditWin, this, rReq ) );
307 bCreateDirectly = comphelper::LibreOfficeKit::isActive();
309 m_nDrawSfxId = nSlotId;
310 if ( nSlotId != SID_DRAW_CS_ID )
312 if ( pStringItem )
314 m_sDrawCustom = pStringItem->GetValue();
315 SfxBindings& rBind = GetViewFrame().GetBindings();
316 rBind.Invalidate( nSlotId );
317 rBind.Update( nSlotId );
321 break;
323 default:
324 break;
327 GetViewFrame().GetBindings().Invalidate(SID_ATTRIBUTES_AREA);
329 bool bEndTextEdit = true;
330 if (pFuncPtr)
332 if (GetDrawFuncPtr())
334 GetDrawFuncPtr()->Deactivate();
337 auto pTempFuncPtr = pFuncPtr.get();
338 SetDrawFuncPtr(std::move(pFuncPtr));
339 AttrChangedNotify(nullptr);
341 pTempFuncPtr->Activate(nSlotId);
342 NoRotate();
343 if(rReq.GetModifier() == KEY_MOD1 || bCreateDirectly)
345 if (bCreateDirectly)
346 GetViewFrame().GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
347 if(SID_OBJECT_SELECT == m_nDrawSfxId )
349 m_pWrtShell->GotoObj(true);
351 else if (dynamic_cast<ConstCustomShape*>(pTempFuncPtr))
353 pTempFuncPtr->CreateDefaultObject();
355 else
357 pTempFuncPtr->CreateDefaultObject();
358 pTempFuncPtr->Deactivate();
359 SetDrawFuncPtr(nullptr);
360 LeaveDrawCreate();
361 m_pWrtShell->EnterStdMode();
362 SdrView *pTmpSdrView = m_pWrtShell->GetDrawView();
363 const SdrMarkList& rMarkList = pTmpSdrView->GetMarkedObjectList();
364 if(rMarkList.GetMarkCount() == 1 &&
365 (SID_DRAW_TEXT == nSlotId || SID_DRAW_TEXT_VERTICAL == nSlotId ||
366 SID_DRAW_TEXT_MARQUEE == nSlotId ))
368 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
369 BeginTextEdit(pObj);
370 bEndTextEdit = false;
375 else
377 if (m_pWrtShell->IsObjSelected() && !m_pWrtShell->IsSelFrameMode())
378 m_pWrtShell->EnterSelFrameMode();
381 if(bEndTextEdit && pSdrView && pSdrView->IsTextEdit())
382 pSdrView->SdrEndTextEdit( true );
384 AttrChangedNotify(nullptr);
387 // End drawing
389 void SwView::ExitDraw()
391 NoRotate();
393 if(!m_pShell)
394 return;
396 // the shell may be invalid at close/reload/SwitchToViewShell
397 SfxDispatcher* pDispatch = GetViewFrame().GetDispatcher();
398 sal_uInt16 nIdx = 0;
399 SfxShell* pTest = nullptr;
402 pTest = pDispatch->GetShell(nIdx++);
404 while( pTest && pTest != this && pTest != m_pShell);
405 if(!(pTest == m_pShell &&
406 // don't call LeaveSelFrameMode() etc. for the below,
407 // because objects may still be selected:
408 dynamic_cast< const SwDrawBaseShell *>( m_pShell ) == nullptr &&
409 dynamic_cast< const SwBezierShell *>( m_pShell ) == nullptr &&
410 dynamic_cast< const svx::ExtrusionBar *>( m_pShell ) == nullptr &&
411 dynamic_cast< const svx::FontworkBar *>( m_pShell ) == nullptr))
412 return;
414 SdrView *pSdrView = m_pWrtShell->GetDrawView();
416 if (pSdrView && pSdrView->IsGroupEntered())
418 pSdrView->LeaveOneGroup();
419 pSdrView->UnmarkAll();
420 GetViewFrame().GetBindings().Invalidate(SID_ENTER_GROUP);
423 if (GetDrawFuncPtr())
425 if (m_pWrtShell->IsSelFrameMode())
426 m_pWrtShell->LeaveSelFrameMode();
427 GetDrawFuncPtr()->Deactivate();
429 SetDrawFuncPtr(nullptr);
430 LeaveDrawCreate();
432 GetViewFrame().GetBindings().Invalidate(SID_INSERT_DRAW);
434 GetEditWin().SetPointer(PointerStyle::Text);
437 // Disable rotate mode
439 void SwView::NoRotate()
441 if (IsDrawRotate())
443 m_pWrtShell->SetDragMode(SdrDragMode::Move);
444 FlipDrawRotate();
446 const SfxBoolItem aTmp( SID_OBJECT_ROTATE, false );
447 GetViewFrame().GetBindings().SetState( aTmp );
451 // Enable DrawTextEditMode
453 static bool lcl_isTextBox(SdrObject const * pObject)
455 if (SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(pObject->GetUserCall()))
457 if (SwFrameFormat* pFormat = pDrawContact->GetFormat())
458 return SwTextBoxHelper::isTextBox(pFormat, RES_DRAWFRMFMT);
460 return false;
463 bool SwView::EnterDrawTextMode(const Point& aDocPos)
465 SwWrtShell *pSh = &GetWrtShell();
466 SdrView *pSdrView = pSh->GetDrawView();
467 OSL_ENSURE( pSdrView, "EnterDrawTextMode without DrawView?" );
469 bool bReturn = false;
471 sal_uInt16 nOld = pSdrView->GetHitTolerancePixel();
472 pSdrView->SetHitTolerancePixel( 2 );
474 SdrObject* pObj = nullptr;
475 SdrPageView* pPV = nullptr;
476 if (pSdrView->IsMarkedHit(aDocPos) && !pSdrView->PickHandle(aDocPos) && IsTextTool())
477 pObj = pSdrView->PickObj(aDocPos, pSdrView->getHitTolLog(), pPV, SdrSearchOptions::PICKTEXTEDIT);
479 if (pObj)
481 // To allow SwDrawVirtObj text objects to be activated, allow their type, too.
482 auto pVirtObj = dynamic_cast<SwDrawVirtObj*>( pObj );
483 if ( (pVirtObj && DynCastSdrTextObj(&pVirtObj->GetReferencedObj() ) != nullptr &&
484 m_pWrtShell->IsSelObjProtected(FlyProtectFlags::Content) == FlyProtectFlags::NONE) ||
485 DynCastSdrTextObj( pObj ) != nullptr )
487 // Refuse to edit editeng text of the shape if it has textbox attached.
488 if (!lcl_isTextBox(pObj))
489 bReturn = BeginTextEdit( pObj, pPV, m_pEditWin );
493 pSdrView->SetHitTolerancePixel( nOld );
495 return bReturn;
498 bool SwView::EnterShapeDrawTextMode(SdrObject* pObject)
500 SdrView* pSdrView = GetWrtShell().GetDrawView();
501 SdrPageView* pPageView = pSdrView->GetSdrPageView();
502 return BeginTextEdit(pObject, pPageView, m_pEditWin);
505 // Enable DrawTextEditMode
507 bool SwView::BeginTextEdit(SdrObject* pObj, SdrPageView* pPV, vcl::Window* pWin,
508 bool bIsNewObj, bool bSetSelectionToStart)
510 SwWrtShell *pSh = &GetWrtShell();
511 SdrView *pSdrView = pSh->GetDrawView();
512 std::unique_ptr<SdrOutliner> pOutliner = ::SdrMakeOutliner(OutlinerMode::TextObject, pSdrView->GetModel());
513 uno::Reference< linguistic2::XSpellChecker1 > xSpell( ::GetSpellChecker() );
514 if (pOutliner)
516 pOutliner->SetRefDevice(pSh->getIDocumentDeviceAccess().getReferenceDevice(false));
517 pOutliner->SetSpeller(xSpell);
518 uno::Reference<linguistic2::XHyphenator> xHyphenator( ::GetHyphenator() );
519 pOutliner->SetHyphenator( xHyphenator );
520 pSh->SetCalcFieldValueHdl(pOutliner.get());
522 EEControlBits nCntrl = pOutliner->GetControlWord();
523 nCntrl |= EEControlBits::ALLOWBIGOBJS;
525 const SwViewOption *pOpt = pSh->GetViewOptions();
527 if (pOpt->IsFieldShadings())
528 nCntrl |= EEControlBits::MARKFIELDS;
529 else
530 nCntrl &= ~EEControlBits::MARKFIELDS;
532 if (pOpt->IsOnlineSpell())
533 nCntrl |= EEControlBits::ONLINESPELLING;
534 else
535 nCntrl &= ~EEControlBits::ONLINESPELLING;
537 pOutliner->SetControlWord(nCntrl);
538 const SfxPoolItem& rItem = pSh->GetDoc()->GetDefault(RES_CHRATR_LANGUAGE);
539 pOutliner->SetDefaultLanguage(static_cast<const SvxLanguageItem&>(rItem).GetLanguage());
541 if( bIsNewObj )
542 pOutliner->SetVertical( SID_DRAW_TEXT_VERTICAL == m_nDrawSfxId ||
543 SID_DRAW_CAPTION_VERTICAL == m_nDrawSfxId );
545 // set default horizontal text direction at outliner
546 EEHorizontalTextDirection aDefHoriTextDir =
547 pSh->IsShapeDefaultHoriTextDirR2L() ? EEHorizontalTextDirection::R2L : EEHorizontalTextDirection::L2R;
548 pOutliner->SetDefaultHorizontalTextDirection( aDefHoriTextDir );
551 // To allow editing the referenced object from a SwDrawVirtObj here
552 // the original needs to be fetched eventually. This ATM activates the
553 // text edit mode for the original object.
554 SdrObject* pToBeActivated = pObj;
556 // Always the original object is edited. To allow the TextEdit to happen
557 // where the VirtObj is positioned, on demand an occurring offset is set at
558 // the TextEdit object. That offset is used for creating and managing the
559 // OutlinerView.
560 Point aNewTextEditOffset(0, 0);
562 if (SwDrawVirtObj* pVirtObj = dynamic_cast<SwDrawVirtObj *>(pObj))
564 pToBeActivated = &const_cast<SdrObject&>(pVirtObj->GetReferencedObj());
565 aNewTextEditOffset = pVirtObj->GetOffset();
568 // set in each case, thus it will be correct for all objects
569 static_cast<SdrTextObj*>(pToBeActivated)->SetTextEditOffset(aNewTextEditOffset);
571 bool bRet(pSdrView->SdrBeginTextEdit( pToBeActivated, pPV, pWin, true, pOutliner.release(), nullptr, false, false, false ));
573 // #i7672#
574 // Since SdrBeginTextEdit actually creates the OutlinerView and thus also
575 // sets the background color, an own background color needs to be set
576 // after TextEditing was started. This is now done here.
577 if(bRet)
579 OutlinerView* pView = pSdrView->GetTextEditOutlinerView();
581 if(pView)
583 Color aBackground(pSh->GetShapeBackground());
584 pView->SetBackgroundColor(aBackground);
587 // editing should start at the end of text, spell checking at the beginning ...
588 ESelection aNewSelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
589 if (bSetSelectionToStart)
590 aNewSelection = ESelection();
591 if (pView)
593 pView->SetSelection(aNewSelection);
595 if (comphelper::LibreOfficeKit::isActive())
597 OString sRect = pView->GetOutputArea().toString();
598 SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_VIEW_LOCK, "rectangle", sRect);
603 return bRet;
606 // Is a DrawTextObject selected?
607 bool SwView::IsTextTool() const
609 SdrObjKind nId;
610 SdrInventor nInvent;
611 SdrView *pSdrView = GetWrtShell().GetDrawView();
612 OSL_ENSURE( pSdrView, "IsTextTool without DrawView?" );
614 if (pSdrView->IsCreateMode())
615 pSdrView->SetCreateMode(false);
617 pSdrView->TakeCurrentObj(nId,nInvent);
618 return nInvent == SdrInventor::Default;
621 SdrView* SwView::GetDrawView() const
623 return GetWrtShell().GetDrawView();
626 bool SwView::IsBezierEditMode() const
628 return (!IsDrawSelMode() && GetWrtShell().GetDrawView()->HasMarkablePoints());
631 bool SwView::IsFormMode() const
633 if (GetDrawFuncPtr() && GetDrawFuncPtr()->IsCreateObj())
635 return GetDrawFuncPtr()->IsInsertForm();
638 return AreOnlyFormsSelected();
641 void SwView::SetDrawFuncPtr(std::unique_ptr<SwDrawBase> pFuncPtr)
643 m_pDrawActual = std::move(pFuncPtr);
646 void SwView::SetSelDrawSlot()
648 m_nDrawSfxId = SID_OBJECT_SELECT;
649 m_sDrawCustom.clear();
652 bool SwView::AreOnlyFormsSelected() const
654 if ( GetWrtShell().IsFrameSelected() )
655 return false;
657 bool bForm = true;
659 SdrView* pSdrView = GetWrtShell().GetDrawView();
661 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
662 const size_t nCount = rMarkList.GetMarkCount();
664 if (nCount)
666 for (size_t i = 0; i < nCount; ++i)
668 // Except controls, are still normal draw objects selected?
669 SdrObject *pSdrObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
670 if (!pSdrObj)
671 continue;
673 if (!HasOnlyObj(pSdrObj, SdrInventor::FmForm))
675 bForm = false;
676 break;
680 else
681 bForm = false;
683 return bForm;
686 bool SwView::HasOnlyObj(SdrObject const *pSdrObj, SdrInventor eObjInventor) const
688 bool bRet = false;
690 if (pSdrObj->IsGroupObject())
692 SdrObjList* pList = pSdrObj->GetSubList();
693 const size_t nCnt = pList->GetObjCount();
695 for (size_t i = 0; i < nCnt; ++i)
697 bRet = HasOnlyObj(pList->GetObj(i), eObjInventor);
698 if (!bRet)
699 break;
702 else if (eObjInventor == pSdrObj->GetObjInventor())
703 return true;
705 return bRet;
708 //#i87414# mod
709 IMPL_LINK(SwView, OnlineSpellCallback, SpellCallbackInfo&, rInfo, void)
711 if (rInfo.nCommand == SpellCallbackCommand::STARTSPELLDLG)
712 GetViewFrame().GetDispatcher()->Execute( FN_SPELL_GRAMMAR_DIALOG, SfxCallMode::ASYNCHRON);
713 else if (rInfo.nCommand == SpellCallbackCommand::AUTOCORRECT_OPTIONS)
714 GetViewFrame().GetDispatcher()->Execute( SID_AUTO_CORRECT_DLG, SfxCallMode::ASYNCHRON );
717 bool SwView::ExecDrwTextSpellPopup(const Point& rPt)
719 bool bRet = false;
720 SdrView *pSdrView = m_pWrtShell->GetDrawView();
721 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
722 Point aPos( GetEditWin().LogicToPixel( rPt ) );
724 if (pOLV->IsWrongSpelledWordAtPos( aPos ))
726 bRet = true;
727 Link<SpellCallbackInfo&,void> aLink = LINK(this, SwView, OnlineSpellCallback);
728 pOLV->ExecuteSpellPopup(aPos, aLink);
730 return bRet;
733 bool SwView::IsDrawTextHyphenate()
735 SdrView *pSdrView = m_pWrtShell->GetDrawView();
736 bool bHyphenate = false;
738 SfxItemSetFixed<EE_PARA_HYPHENATE, EE_PARA_HYPHENATE> aNewAttr( pSdrView->GetModel().GetItemPool() );
739 pSdrView->GetAttributes( aNewAttr );
740 if( aNewAttr.GetItemState( EE_PARA_HYPHENATE ) >= SfxItemState::DEFAULT )
741 bHyphenate = aNewAttr.Get( EE_PARA_HYPHENATE ).GetValue();
743 return bHyphenate;
746 void SwView::HyphenateDrawText()
748 SdrView *pSdrView = m_pWrtShell->GetDrawView();
749 bool bHyphenate = IsDrawTextHyphenate();
751 SfxItemSetFixed<EE_PARA_HYPHENATE, EE_PARA_HYPHENATE> aSet( GetPool() );
752 aSet.Put( SfxBoolItem( EE_PARA_HYPHENATE, !bHyphenate ) );
753 pSdrView->SetAttributes( aSet );
754 GetViewFrame().GetBindings().Invalidate(FN_HYPHENATE_OPT_DLG);
757 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */