LibreOffice Module sw (master)  1
viewdraw.cxx
Go to the documentation of this file.
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/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>
29 #include <sfx2/viewfrm.hxx>
30 #include <doc.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>
46 
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>
60 
61 #include <dcontact.hxx>
62 
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>
68 
69 using namespace ::com::sun::star;
70 
71 // Execute Drawing-Ids
72 
74 {
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;
80 
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);
84 
85  SdrObjKind eNewFormObjKind = OBJ_NONE;
86  if (nSlotId == SID_FM_CREATE_CONTROL)
87  {
88  const SfxUInt16Item* pIdentifierItem = rReq.GetArg<SfxUInt16Item>(SID_FM_CONTROL_IDENTIFIER);
89  if (pIdentifierItem)
90  eNewFormObjKind = static_cast<SdrObjKind>(pIdentifierItem->GetValue());
91  }
92 
93  if (nSlotId == SID_OBJECT_SELECT && m_nFormSfxId == nSlotId)
94  {
95  bDeselect = true;
96  }
97  else if (nSlotId == SID_FM_CREATE_CONTROL)
98  {
99  if (eNewFormObjKind == m_eFormObjKind || eNewFormObjKind == OBJ_NONE)
100  {
101  bDeselect = true;
102  GetViewFrame()->GetDispatcher()->Execute(SID_FM_LEAVE_CREATE); // Button should popping out
103  }
104  }
105  else if (nSlotId == SID_FM_CREATE_FIELDCONTROL)
106  {
107  FmFormView* pFormView = dynamic_cast<FmFormView*>(pSdrView);
108  if (pFormView)
109  {
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 )
113  {
114  svx::ODataAccessDescriptor aDescriptor( pDescriptorItem->GetValue() );
115  SdrObjectUniquePtr pObj = pFormView->CreateFieldControl( aDescriptor );
116 
117  if ( pObj )
118  {
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() );
126 
127  //determine the size of the object
128  if(pObj->IsGroupObject())
129  {
130  const tools::Rectangle& rBoundRect = static_cast<SdrObjGroup*>(pObj.get())->GetCurrentBoundRect();
131  aStartPos.AdjustX( -(rBoundRect.GetWidth()/2) );
132  aStartPos.AdjustY( -(rBoundRect.GetHeight()/2) );
133  }
134 
135  // TODO: unmark all other
136  m_pWrtShell->EnterStdMode();
137  m_pWrtShell->SwFEShell::InsertDrawObj( *(pObj.release()), aStartPos );
138  }
139  }
140  }
141  }
142  else if ( nSlotId == SID_FONTWORK_GALLERY_FLOATER )
143  {
144  vcl::Window& rWin = m_pWrtShell->GetView().GetViewFrame()->GetWindow();
145 
146  rWin.EnterWait();
147 
148  if( !m_pWrtShell->HasDrawView() )
149  m_pWrtShell->MakeDrawView();
150 
151  pSdrView = m_pWrtShell->GetDrawView();
152  if (pSdrView)
153  {
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();
158 
159  SdrObject* pObj = pDlg->GetSdrObjectRef();
160  if ( pObj )
161  {
162  Size aDocSize( m_pWrtShell->GetDocSize() );
163  const SwRect& rVisArea = comphelper::LibreOfficeKit::isActive() ?
164  m_pWrtShell->getLOKVisibleArea() : m_pWrtShell->VisArea();
165  Point aPos( rVisArea.Center() );
166  tools::Rectangle aObjRect( pObj->GetLogicRect() );
167 
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) );
172 
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) );
177 
178  m_pWrtShell->EnterStdMode();
179  m_pWrtShell->SwFEShell::InsertDrawObj( *pObj, aPos );
180  }
181 
182  rWin2.LeaveWait();
183  });
184  }
185  else
186  rWin.LeaveWait();
187  }
188  else if ( m_nFormSfxId != USHRT_MAX )
189  GetViewFrame()->GetDispatcher()->Execute( SID_FM_LEAVE_CREATE );
190 
191  if( nSlotId == SID_DRAW_CS_ID )
192  {
193  //deselect if same custom shape is selected again
194  SwDrawBase* pFuncPtr = GetDrawFuncPtr();
195  if( pFuncPtr && pFuncPtr->GetSlotId() == SID_DRAW_CS_ID )
196  {
197  ConstCustomShape* pConstCustomShape = static_cast<ConstCustomShape*>(pFuncPtr);
198  OUString aNew = ConstCustomShape::GetShapeTypeFromRequest( rReq );
199  const OUString& aOld = pConstCustomShape->GetShapeType();
200  if( aNew == aOld )
201  {
202  bDeselect = true;
203  }
204  }
205  }
206 
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) ) )
211  {
212  if (GetDrawFuncPtr())
213  {
215  SetDrawFuncPtr(nullptr);
216  }
217 
218  if (m_pWrtShell->IsObjSelected() && !m_pWrtShell->IsSelFrameMode())
219  m_pWrtShell->EnterSelFrameMode();
220  LeaveDrawCreate();
221 
222  AttrChangedNotify(nullptr);
223  return;
224  }
225 
226  LeaveDrawCreate();
227 
228  if (m_pWrtShell->IsFrameSelected())
229  m_pWrtShell->EnterStdMode(); // because bug #45639
230 
231  std::unique_ptr<SwDrawBase> pFuncPtr;
232 
233  // for LibreOfficeKit - choosing a shape should construct it directly
234  bool bCreateDirectly = false;
235 
236  switch (nSlotId)
237  {
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;
244 
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  m_nDrawSfxId = nSlotId;
264  m_sDrawCustom.clear();
265  break;
266 
267  case SID_DRAW_XPOLYGON_NOFILL:
268  case SID_DRAW_XPOLYGON:
269  case SID_DRAW_POLYGON_NOFILL:
270  case SID_DRAW_POLYGON:
271  case SID_DRAW_BEZIER_NOFILL:
272  case SID_DRAW_BEZIER_FILL:
273  case SID_DRAW_FREELINE_NOFILL:
274  case SID_DRAW_FREELINE:
275  pFuncPtr.reset( new ConstPolygon(m_pWrtShell.get(), m_pEditWin, this) );
276  m_nDrawSfxId = nSlotId;
277  m_sDrawCustom.clear();
278  break;
279 
280  case SID_DRAW_ARC:
281  case SID_DRAW_PIE:
282  case SID_DRAW_CIRCLECUT:
283  pFuncPtr.reset( new ConstArc(m_pWrtShell.get(), m_pEditWin, this) );
284  m_nDrawSfxId = nSlotId;
285  m_sDrawCustom.clear();
286  break;
287 
288  case SID_FM_CREATE_CONTROL:
289  {
290  pFuncPtr.reset(new ConstFormControl(m_pWrtShell.get(), m_pEditWin, this, eNewFormObjKind));
291  m_nFormSfxId = nSlotId;
292  m_eFormObjKind = eNewFormObjKind;
293  }
294  break;
295 
296  case SID_DRAWTBX_CS_BASIC :
297  case SID_DRAWTBX_CS_SYMBOL :
298  case SID_DRAWTBX_CS_ARROW :
299  case SID_DRAWTBX_CS_FLOWCHART :
300  case SID_DRAWTBX_CS_CALLOUT :
301  case SID_DRAWTBX_CS_STAR :
302  case SID_DRAW_CS_ID :
303  {
304  pFuncPtr.reset( new ConstCustomShape(m_pWrtShell.get(), m_pEditWin, this, rReq ) );
305 
306  bCreateDirectly = comphelper::LibreOfficeKit::isActive();
307 
308  m_nDrawSfxId = nSlotId;
309  if ( nSlotId != SID_DRAW_CS_ID )
310  {
311  if ( pStringItem )
312  {
313  m_sDrawCustom = pStringItem->GetValue();
314  SfxBindings& rBind = GetViewFrame()->GetBindings();
315  rBind.Invalidate( nSlotId );
316  rBind.Update( nSlotId );
317  }
318  }
319  }
320  break;
321 
322  default:
323  break;
324  }
325 
326  GetViewFrame()->GetBindings().Invalidate(SID_ATTRIBUTES_AREA);
327 
328  bool bEndTextEdit = true;
329  if (pFuncPtr)
330  {
331  if (GetDrawFuncPtr())
332  {
334  }
335 
336  auto pTempFuncPtr = pFuncPtr.get();
337  SetDrawFuncPtr(std::move(pFuncPtr));
338  AttrChangedNotify(nullptr);
339 
340  pTempFuncPtr->Activate(nSlotId);
341  NoRotate();
342  if(rReq.GetModifier() == KEY_MOD1 || bCreateDirectly)
343  {
344  if(SID_OBJECT_SELECT == m_nDrawSfxId )
345  {
346  m_pWrtShell->GotoObj(true);
347  }
348  else if (dynamic_cast<ConstCustomShape*>(pTempFuncPtr))
349  {
350  pTempFuncPtr->CreateDefaultObject();
351  }
352  else
353  {
354  pTempFuncPtr->CreateDefaultObject();
355  pTempFuncPtr->Deactivate();
356  SetDrawFuncPtr(nullptr);
357  LeaveDrawCreate();
358  m_pWrtShell->EnterStdMode();
359  SdrView *pTmpSdrView = m_pWrtShell->GetDrawView();
360  const SdrMarkList& rMarkList = pTmpSdrView->GetMarkedObjectList();
361  if(rMarkList.GetMarkCount() == 1 &&
362  (SID_DRAW_TEXT == nSlotId || SID_DRAW_TEXT_VERTICAL == nSlotId ||
363  SID_DRAW_TEXT_MARQUEE == nSlotId ))
364  {
365  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
366  BeginTextEdit(pObj);
367  bEndTextEdit = false;
368  }
369  }
370  }
371  }
372  else
373  {
374  if (m_pWrtShell->IsObjSelected() && !m_pWrtShell->IsSelFrameMode())
375  m_pWrtShell->EnterSelFrameMode();
376  }
377 
378  if(bEndTextEdit && pSdrView && pSdrView->IsTextEdit())
379  pSdrView->SdrEndTextEdit( true );
380 
381  AttrChangedNotify(nullptr);
382 }
383 
384 // End drawing
385 
387 {
388  NoRotate();
389 
390  if(!m_pShell)
391  return;
392 
393  // the shell may be invalid at close/reload/SwitchToViewShell
394  SfxDispatcher* pDispatch = GetViewFrame()->GetDispatcher();
395  sal_uInt16 nIdx = 0;
396  SfxShell* pTest = nullptr;
397  do
398  {
399  pTest = pDispatch->GetShell(nIdx++);
400  }
401  while( pTest && pTest != this && pTest != m_pShell);
402  if(!(pTest == m_pShell &&
403  // don't call LeaveSelFrameMode() etc. for the below,
404  // because objects may still be selected:
405  dynamic_cast< const SwDrawBaseShell *>( m_pShell ) == nullptr &&
406  dynamic_cast< const SwBezierShell *>( m_pShell ) == nullptr &&
407  dynamic_cast< const svx::ExtrusionBar *>( m_pShell ) == nullptr &&
408  dynamic_cast< const svx::FontworkBar *>( m_pShell ) == nullptr))
409  return;
410 
411  SdrView *pSdrView = m_pWrtShell->GetDrawView();
412 
413  if (pSdrView && pSdrView->IsGroupEntered())
414  {
415  pSdrView->LeaveOneGroup();
416  pSdrView->UnmarkAll();
417  GetViewFrame()->GetBindings().Invalidate(SID_ENTER_GROUP);
418  }
419 
420  if (GetDrawFuncPtr())
421  {
422  if (m_pWrtShell->IsSelFrameMode())
423  m_pWrtShell->LeaveSelFrameMode();
425 
426  SetDrawFuncPtr(nullptr);
427  LeaveDrawCreate();
428 
429  GetViewFrame()->GetBindings().Invalidate(SID_INSERT_DRAW);
430  }
431  GetEditWin().SetPointer(PointerStyle::Text);
432 }
433 
434 // Disable rotate mode
435 
437 {
438  if (IsDrawRotate())
439  {
440  m_pWrtShell->SetDragMode(SdrDragMode::Move);
441  FlipDrawRotate();
442 
443  const SfxBoolItem aTmp( SID_OBJECT_ROTATE, false );
444  GetViewFrame()->GetBindings().SetState( aTmp );
445  }
446 }
447 
448 // Enable DrawTextEditMode
449 
450 static bool lcl_isTextBox(SdrObject const * pObject)
451 {
452  if (SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(pObject->GetUserCall()))
453  {
454  if (SwFrameFormat* pFormat = pDrawContact->GetFormat())
456  }
457  return false;
458 }
459 
460 bool SwView::EnterDrawTextMode(const Point& aDocPos)
461 {
462  SwWrtShell *pSh = &GetWrtShell();
463  SdrView *pSdrView = pSh->GetDrawView();
464  OSL_ENSURE( pSdrView, "EnterDrawTextMode without DrawView?" );
465 
466  bool bReturn = false;
467 
468  sal_uInt16 nOld = pSdrView->GetHitTolerancePixel();
469  pSdrView->SetHitTolerancePixel( 2 );
470 
471  SdrObject* pObj = nullptr;
472  SdrPageView* pPV = nullptr;
473  if (pSdrView->IsMarkedHit(aDocPos) && !pSdrView->PickHandle(aDocPos) && IsTextTool())
474  pObj = pSdrView->PickObj(aDocPos, pSdrView->getHitTolLog(), pPV, SdrSearchOptions::PICKTEXTEDIT);
475 
476  if (pObj)
477  {
478  // To allow SwDrawVirtObj text objects to be activated, allow their type, too.
479  auto pVirtObj = dynamic_cast<SwDrawVirtObj*>( pObj );
480  if ( (pVirtObj && dynamic_cast< const SdrTextObj *>(&pVirtObj->GetReferencedObj() ) != nullptr &&
482  dynamic_cast< const SdrTextObj *>( pObj ) != nullptr )
483  {
484  // Refuse to edit editeng text of the shape if it has textbox attached.
485  if (!lcl_isTextBox(pObj))
486  bReturn = BeginTextEdit( pObj, pPV, m_pEditWin );
487  }
488  }
489 
490  pSdrView->SetHitTolerancePixel( nOld );
491 
492  return bReturn;
493 }
494 
496 {
497  SdrView* pSdrView = GetWrtShell().GetDrawView();
498  SdrPageView* pPageView = pSdrView->GetSdrPageView();
499  return BeginTextEdit(pObject, pPageView, m_pEditWin);
500 }
501 
502 // Enable DrawTextEditMode
503 
505  bool bIsNewObj, bool bSetSelectionToStart)
506 {
507  SwWrtShell *pSh = &GetWrtShell();
508  SdrView *pSdrView = pSh->GetDrawView();
509  std::unique_ptr<SdrOutliner> pOutliner = ::SdrMakeOutliner(OutlinerMode::TextObject, *pSdrView->GetModel());
510  uno::Reference< linguistic2::XSpellChecker1 > xSpell( ::GetSpellChecker() );
511  if (pOutliner)
512  {
513  pOutliner->SetRefDevice(pSh->getIDocumentDeviceAccess().getReferenceDevice(false));
514  pOutliner->SetSpeller(xSpell);
515  uno::Reference<linguistic2::XHyphenator> xHyphenator( ::GetHyphenator() );
516  pOutliner->SetHyphenator( xHyphenator );
517  pSh->SetCalcFieldValueHdl(pOutliner.get());
518 
519  EEControlBits nCntrl = pOutliner->GetControlWord();
520  nCntrl |= EEControlBits::ALLOWBIGOBJS;
521 
522  const SwViewOption *pOpt = pSh->GetViewOptions();
523 
525  nCntrl |= EEControlBits::MARKFIELDS;
526  else
527  nCntrl &= ~EEControlBits::MARKFIELDS;
528 
529  if (pOpt->IsOnlineSpell())
530  nCntrl |= EEControlBits::ONLINESPELLING;
531  else
532  nCntrl &= ~EEControlBits::ONLINESPELLING;
533 
534  pOutliner->SetControlWord(nCntrl);
535  const SfxPoolItem& rItem = pSh->GetDoc()->GetDefault(RES_CHRATR_LANGUAGE);
536  pOutliner->SetDefaultLanguage(static_cast<const SvxLanguageItem&>(rItem).GetLanguage());
537 
538  if( bIsNewObj )
539  pOutliner->SetVertical( SID_DRAW_TEXT_VERTICAL == m_nDrawSfxId ||
540  SID_DRAW_CAPTION_VERTICAL == m_nDrawSfxId );
541 
542  // set default horizontal text direction at outliner
543  EEHorizontalTextDirection aDefHoriTextDir =
544  pSh->IsShapeDefaultHoriTextDirR2L() ? EEHorizontalTextDirection::R2L : EEHorizontalTextDirection::L2R;
545  pOutliner->SetDefaultHorizontalTextDirection( aDefHoriTextDir );
546  }
547 
548  // To allow editing the referenced object from a SwDrawVirtObj here
549  // the original needs to be fetched eventually. This ATM activates the
550  // text edit mode for the original object.
551  SdrObject* pToBeActivated = pObj;
552 
553  // Always the original object is edited. To allow the TextEdit to happen
554  // where the VirtObj is positioned, on demand an occurring offset is set at
555  // the TextEdit object. That offset is used for creating and managing the
556  // OutlinerView.
557  Point aNewTextEditOffset(0, 0);
558 
559  if (SwDrawVirtObj* pVirtObj = dynamic_cast<SwDrawVirtObj *>(pObj))
560  {
561  pToBeActivated = &const_cast<SdrObject&>(pVirtObj->GetReferencedObj());
562  aNewTextEditOffset = pVirtObj->GetOffset();
563  }
564 
565  // set in each case, thus it will be correct for all objects
566  static_cast<SdrTextObj*>(pToBeActivated)->SetTextEditOffset(aNewTextEditOffset);
567 
568  bool bRet(pSdrView->SdrBeginTextEdit( pToBeActivated, pPV, pWin, true, pOutliner.release(), nullptr, false, false, false ));
569 
570  // #i7672#
571  // Since SdrBeginTextEdit actually creates the OutlinerView and thus also
572  // sets the background color, an own background color needs to be set
573  // after TextEditing was started. This is now done here.
574  if(bRet)
575  {
576  OutlinerView* pView = pSdrView->GetTextEditOutlinerView();
577 
578  if(pView)
579  {
580  Color aBackground(pSh->GetShapeBackgrd());
581  pView->SetBackgroundColor(aBackground);
582  }
583 
584  // editing should start at the end of text, spell checking at the beginning ...
586  if (bSetSelectionToStart)
587  aNewSelection = ESelection();
588  if (pView)
589  {
590  pView->SetSelection(aNewSelection);
591 
593  {
594  OString sRect = pView->GetOutputArea().toString();
595  SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_VIEW_LOCK, "rectangle", sRect);
596  }
597  }
598  }
599 
600  return bRet;
601 }
602 
603 // Is a DrawTextObject selected?
604 bool SwView::IsTextTool() const
605 {
606  SdrObjKind nId;
607  SdrInventor nInvent;
608  SdrView *pSdrView = GetWrtShell().GetDrawView();
609  OSL_ENSURE( pSdrView, "IsTextTool without DrawView?" );
610 
611  if (pSdrView->IsCreateMode())
612  pSdrView->SetCreateMode(false);
613 
614  pSdrView->TakeCurrentObj(nId,nInvent);
615  return nInvent == SdrInventor::Default;
616 }
617 
619 {
620  return GetWrtShell().GetDrawView();
621 }
622 
624 {
625  return (!IsDrawSelMode() && GetWrtShell().GetDrawView()->HasMarkablePoints());
626 }
627 
628 bool SwView::IsFormMode() const
629 {
630  if (GetDrawFuncPtr() && GetDrawFuncPtr()->IsCreateObj())
631  {
632  return GetDrawFuncPtr()->IsInsertForm();
633  }
634 
635  return AreOnlyFormsSelected();
636 }
637 
638 void SwView::SetDrawFuncPtr(std::unique_ptr<SwDrawBase> pFuncPtr)
639 {
640  m_pDrawActual = std::move(pFuncPtr);
641 }
642 
644 {
645  m_nDrawSfxId = SID_OBJECT_SELECT;
646  m_sDrawCustom.clear();
647 }
648 
650 {
651  if ( GetWrtShell().IsFrameSelected() )
652  return false;
653 
654  bool bForm = true;
655 
656  SdrView* pSdrView = GetWrtShell().GetDrawView();
657 
658  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
659  const size_t nCount = rMarkList.GetMarkCount();
660 
661  if (nCount)
662  {
663  for (size_t i = 0; i < nCount; ++i)
664  {
665  // Except controls, are still normal draw objects selected?
666  SdrObject *pSdrObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
667  if (!pSdrObj)
668  continue;
669 
670  if (!HasOnlyObj(pSdrObj, SdrInventor::FmForm))
671  {
672  bForm = false;
673  break;
674  }
675  }
676  }
677  else
678  bForm = false;
679 
680  return bForm;
681 }
682 
683 bool SwView::HasOnlyObj(SdrObject const *pSdrObj, SdrInventor eObjInventor) const
684 {
685  bool bRet = false;
686 
687  if (pSdrObj->IsGroupObject())
688  {
689  SdrObjList* pList = pSdrObj->GetSubList();
690  const size_t nCnt = pList->GetObjCount();
691 
692  for (size_t i = 0; i < nCnt; ++i)
693  {
694  bRet = HasOnlyObj(pList->GetObj(i), eObjInventor);
695  if (!bRet)
696  break;
697  }
698  }
699  else if (eObjInventor == pSdrObj->GetObjInventor())
700  return true;
701 
702  return bRet;
703 }
704 
705 //#i87414# mod
706 IMPL_LINK(SwView, OnlineSpellCallback, SpellCallbackInfo&, rInfo, void)
707 {
708  if (rInfo.nCommand == SpellCallbackCommand::STARTSPELLDLG)
709  GetViewFrame()->GetDispatcher()->Execute( FN_SPELL_GRAMMAR_DIALOG, SfxCallMode::ASYNCHRON);
710  else if (rInfo.nCommand == SpellCallbackCommand::AUTOCORRECT_OPTIONS)
711  GetViewFrame()->GetDispatcher()->Execute( SID_AUTO_CORRECT_DLG, SfxCallMode::ASYNCHRON );
712 }
713 
714 bool SwView::ExecDrwTextSpellPopup(const Point& rPt)
715 {
716  bool bRet = false;
717  SdrView *pSdrView = m_pWrtShell->GetDrawView();
718  OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
719  Point aPos( GetEditWin().LogicToPixel( rPt ) );
720 
721  if (pOLV->IsWrongSpelledWordAtPos( aPos ))
722  {
723  bRet = true;
724  Link<SpellCallbackInfo&,void> aLink = LINK(this, SwView, OnlineSpellCallback);
725  pOLV->ExecuteSpellPopup(aPos, aLink);
726  }
727  return bRet;
728 }
729 
731 {
732  SdrView *pSdrView = m_pWrtShell->GetDrawView();
733  bool bHyphenate = false;
734 
735  SfxItemSet aNewAttr( pSdrView->GetModel()->GetItemPool(),
737  pSdrView->GetAttributes( aNewAttr );
738  if( aNewAttr.GetItemState( EE_PARA_HYPHENATE ) >= SfxItemState::DEFAULT )
739  bHyphenate = aNewAttr.Get( EE_PARA_HYPHENATE ).GetValue();
740 
741  return bHyphenate;
742 }
743 
745 {
746  SdrView *pSdrView = m_pWrtShell->GetDrawView();
747  bool bHyphenate = IsDrawTextHyphenate();
748 
750  aSet.Put( SfxBoolItem( EE_PARA_HYPHENATE, !bHyphenate ) );
751  pSdrView->SetAttributes( aSet );
753 }
754 
755 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
void ExitDraw()
Definition: viewdraw.cxx:386
static void notifyOtherViews(const SfxViewShell *pThisView, int nType, std::string_view rKey, const OString &rPayload)
void ExecDraw(SfxRequest &)
Definition: viewdraw.cxx:73
SdrObjKind m_eFormObjKind
Definition: view.hxx:229
size_t GetMarkCount() const
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false)
constexpr sal_uInt16 KEY_MOD1
SdrView * GetDrawView()
Definition: vnew.cxx:376
bool BeginTextEdit(SdrObject *pObj, SdrPageView *pPV=nullptr, vcl::Window *pWin=nullptr, bool bIsNewObj=false, bool bSetSelectionToStart=false)
Definition: viewdraw.cxx:504
void SetState(const SfxItemSet &rSet)
bool IsBezierEditMode() const
Definition: viewdraw.cxx:623
bool AreOnlyFormsSelected() const
Definition: viewdraw.cxx:649
std::unique_ptr< SwWrtShell > m_pWrtShell
Definition: view.hxx:193
#define FN_HYPHENATE_OPT_DLG
Definition: cmdid.h:487
tools::Rectangle const & GetOutputArea() const
SfxDispatcher * GetDispatcher()
void SetHitTolerancePixel(sal_uInt16 nVal)
void FlipDrawRotate()
Definition: view.hxx:530
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_LANGUAGE(10)
void EnterWait()
#define EE_INDEX_NOT_FOUND
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:390
SdrObject * GetObj(size_t nNum) const
size_t GetObjCount() const
sal_uInt16 GetValue() const
sal_Int16 nId
tools::Long GetWidth() const
SdrInventor
SwEditWin & GetEditWin()
Definition: view.hxx:416
SdrMark * GetMark(size_t nNum) const
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
EEControlBits
bool EnterShapeDrawTextMode(SdrObject *pObject)
Same as EnterDrawTextMode(), but takes an SdrObject instead of guessing it by document position...
Definition: viewdraw.cxx:495
virtual SdrObjList * GetSubList() const
SdrObjKind
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
void SetDrawFuncPtr(std::unique_ptr< SwDrawBase > pFuncPtr)
Definition: viewdraw.cxx:638
Used by the UI to modify the document model.
Definition: wrtsh.hxx:91
sal_uInt16 m_nFormSfxId
Definition: view.hxx:228
#define EE_PARA_NOT_FOUND
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
weld::Window * GetFrameWeld() const
ESelection aNewSelection(GetSelection())
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(159)
SfxShell * GetShell(sal_uInt16 nIdx) const
void ExecuteSpellPopup(const Point &rPosPixel, const Link< SpellCallbackInfo &, void > &rCallBack)
const SfxPoolItem & GetDefault(sal_uInt16 nFormatHint) const
Get the default attribute in this document.
Definition: docfmt.cxx:653
int nCount
static bool isTextBox(const SwFrameFormat *pFormat, sal_uInt16 nType)
Is the frame format a text box?
OUString m_sDrawCustom
Definition: view.hxx:227
bool EnterDrawTextMode(const Point &aDocPos)
Definition: viewdraw.cxx:460
void TakeCurrentObj(SdrObjKind &nIdent, SdrInventor &nInvent) const
SAL_DLLPRIVATE bool IsTextTool() const
Definition: viewdraw.cxx:604
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
const css::uno::Any & GetValue() const
bool IsMarkedHit(const Point &rPnt, short nTol=-2) const
std::unique_ptr< SwDrawBase > m_pDrawActual
Definition: view.hxx:214
void UnmarkAll()
void setX(tools::Long x)
virtual void Deactivate()
Definition: drawbase.cxx:439
SAL_DLLPRIVATE void HyphenateDrawText()
Definition: viewdraw.cxx:744
VclPtr< SwEditWin > m_pEditWin
Definition: view.hxx:192
bool IsDrawSelMode() const
Definition: view.hxx:531
SfxItemPool & GetPool() const
SdrObject * GetMarkedSdrObj() const
const IDocumentDeviceAccess & getIDocumentDeviceAccess() const
Provides access to the document device interface.
Definition: viewsh.cxx:2663
SdrObject * PickObj(const Point &rPnt, short nTol, SdrPageView *&rpPV, SdrSearchOptions nOptions, SdrObject **ppRootObj, bool *pbHitPassDirect=nullptr) const
bool IsShapeDefaultHoriTextDirR2L() const
Is default horizontal text direction for selected drawing object right-to-left.
Definition: feshview.cxx:3209
Style of a layout element.
Definition: frmfmt.hxx:58
void NoRotate()
Definition: viewdraw.cxx:436
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
int i
void SetSelDrawSlot()
Definition: viewdraw.cxx:643
sal_uInt16 GetModifier() const
static OUString GetShapeTypeFromRequest(SfxRequest const &rReq)
static bool lcl_isTextBox(SdrObject const *pObject)
Definition: viewdraw.cxx:450
SfxBindings & GetBindings()
bool IsWrongSpelledWordAtPos(const Point &rPosPixel)
const OUString & GetValue() const
const SdrMarkList & GetMarkedObjectList() const
const T * GetArg(sal_uInt16 nSlotId) const
bool SetAttributes(const SfxItemSet &rSet, bool bReplaceAll=false)
virtual bool SdrBeginTextEdit(SdrObject *pObj, SdrPageView *pPV=nullptr, vcl::Window *pWin=nullptr, bool bIsNewObj=false, SdrOutliner *pGivenOutliner=nullptr, OutlinerView *pGivenOutlinerView=nullptr, bool bDontDeleteOutliner=false, bool bOnlyOneView=false, bool bGrabFocus=true)
EEHorizontalTextDirection
IMPL_LINK(SwView, OnlineSpellCallback, SpellCallbackInfo &, rInfo, void)
Definition: viewdraw.cxx:706
bool IsInsertForm() const
Definition: drawbase.hxx:50
SdrHdl * PickHandle(const Point &rPnt) const
bool IsGroupObject() const
const OutlinerView * GetTextEditOutlinerView() const
void LeaveOneGroup()
bool IsDrawRotate() const
Definition: view.hxx:529
bool IsOnlineSpell() const
Definition: viewopt.hxx:371
void SetCalcFieldValueHdl(Outliner *pOutliner)
Definition: feshview.cxx:2786
void LeaveDrawCreate()
Definition: view.hxx:538
SwDrawBase * GetDrawFuncPtr() const
Definition: view.hxx:526
static bool IsFieldShadings()
Definition: viewopt.hxx:671
bool IsCreateMode() const
virtual SdrInventor GetObjInventor() const
void Update(sal_uInt16 nId)
uno::Reference< linguistic2::XSpellChecker1 > GetSpellChecker()
Definition: swtypes.cxx:52
void SetPointer(PointerStyle)
sal_uInt16 GetSlot() const
void SetSelection(const ESelection &)
virtual bool IsTextEdit() const final override
#define FN_SPELL_GRAMMAR_DIALOG
Definition: cmdid.h:601
#define GetWhich(nSlot)
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:423
sal_uInt16 GetSlotId() const
Definition: drawbase.hxx:60
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
const OUString & GetShapeType() const
SdrObjectUniquePtr CreateFieldControl(const OUString &rFieldDesc) const
void GetAttributes(SfxItemSet &rTargetSet, bool bOnlyHardAttr=false) const
void SetBackgroundColor(const Color &rColor)
bool HasOnlyObj(SdrObject const *pSdrObj, SdrInventor eObjInventor) const
Definition: viewdraw.cxx:683
new class for re-direct methods calls at a 'virtual' drawing object to its referenced object...
Definition: dcontact.hxx:212
sal_uInt16 GetHitTolerancePixel() const
void SetCreateMode(bool bOn=true)
constexpr TypedWhichId< SfxBoolItem > EE_PARA_HYPHENATE(EE_PARA_START+6)
void release() const
SAL_DLLPRIVATE bool IsDrawTextHyphenate()
Definition: viewdraw.cxx:730
virtual OutputDevice * getReferenceDevice(bool bCreate) const =0
Returns the current reference device.
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
SdrPageView * GetSdrPageView() const
bool ExecDrwTextSpellPopup(const Point &rPt)
Definition: viewdraw.cxx:714
tools::Long GetHeight() const
sal_uInt16 m_nDrawSfxId
Definition: view.hxx:226
uno::Reference< linguistic2::XHyphenator > GetHyphenator()
Definition: swtypes.cxx:57
SfxShell * m_pShell
Definition: view.hxx:196
const SfxItemPool & GetItemPool() const
virtual const tools::Rectangle & GetLogicRect() const
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
void LeaveWait()
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:618
rtl::OString toString() const
bool IsFormMode() const
Definition: viewdraw.cxx:628
OBJ_NONE
sal_uInt16 getHitTolLog() const
SdrModel * GetModel() const
SdrObjUserCall * GetUserCall() const
bool IsGroupEntered() const
Definition: view.hxx:144
Color GetShapeBackgrd() const
SwFEShell::GetShapeBackgrd.
Definition: feshview.cxx:3161