Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / frmsh.cxx
blob65c41becb0c39033b6cf242b496770030c529bb6
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 <config_features.h>
22 #include <hintids.hxx>
23 #include <svl/whiter.hxx>
24 #include <sfx2/viewfrm.hxx>
25 #include <basic/sbstar.hxx>
26 #include <svl/ptitem.hxx>
27 #include <svl/stritem.hxx>
28 #include <svl/intitem.hxx>
29 #include <svl/eitem.hxx>
30 #include <editeng/colritem.hxx>
31 #include <editeng/lineitem.hxx>
32 #include <editeng/boxitem.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/request.hxx>
35 #include <sfx2/objface.hxx>
36 #include <vcl/EnumContext.hxx>
37 #include <svx/hlnkitem.hxx>
38 #include <svx/svdview.hxx>
39 #include <svx/sdangitm.hxx>
40 #include <vcl/commandinfoprovider.hxx>
41 #include <sal/log.hxx>
43 #include <doc.hxx>
44 #include <drawdoc.hxx>
45 #include <IDocumentSettingAccess.hxx>
46 #include <IDocumentDrawModelAccess.hxx>
47 #include <fmturl.hxx>
48 #include <fmtclds.hxx>
49 #include <fmtcnct.hxx>
50 #include <swmodule.hxx>
51 #include <wrtsh.hxx>
52 #include <wview.hxx>
53 #include <uitool.hxx>
54 #include <frmfmt.hxx>
55 #include <frmsh.hxx>
56 #include <frmmgr.hxx>
57 #include <edtwin.hxx>
58 #include <swdtflvr.hxx>
59 #include <viewopt.hxx>
61 #include <cmdid.h>
62 #include <strings.hrc>
63 #include <swabstdlg.hxx>
65 #include <svx/svxdlg.hxx>
67 #include <docsh.hxx>
68 #include <svx/drawitem.hxx>
69 #include <memory>
71 #define ShellClass_SwFrameShell
72 #include <sfx2/msg.hxx>
73 #include <swslots.hxx>
74 #include <grfatr.hxx>
75 #include <fldmgr.hxx>
76 #include <flyfrm.hxx>
78 using ::editeng::SvxBorderLine;
79 using namespace ::com::sun::star;
80 using namespace ::com::sun::star::uno;
82 // Prototypes
83 static void lcl_FrameGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine);
84 static const SwFrameFormat* lcl_GetFrameFormatByName(SwWrtShell const & rSh, std::u16string_view rName)
86 const size_t nCount = rSh.GetFlyCount(FLYCNTTYPE_FRM);
87 for( size_t i = 0; i < nCount; ++i )
89 const SwFrameFormat* pFormat = rSh.GetFlyNum(i, FLYCNTTYPE_FRM);
90 if(pFormat->GetName() == rName)
91 return pFormat;
93 return nullptr;
96 SFX_IMPL_INTERFACE(SwFrameShell, SwBaseShell)
98 void SwFrameShell::InitInterface_Impl()
100 GetStaticInterface()->RegisterPopupMenu("frame");
102 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Frame_Toolbox);
105 void SwFrameShell::ExecMove(SfxRequest& rReq)
107 SwWrtShell& rSh = GetShell();
108 sal_uInt16 nSlot = rReq.GetSlot();
109 switch (nSlot)
111 case SID_SELECTALL:
112 rSh.SelAll();
113 rReq.Done();
114 break;
118 void SwFrameShell::ExecField(const SfxRequest& rReq)
120 SwWrtShell& rSh = GetShell();
121 sal_uInt16 nSlot = rReq.GetSlot();
122 switch (nSlot)
124 case FN_POSTIT:
125 SwFieldMgr aFieldMgr(&rSh);
126 rSh.InsertPostIt(aFieldMgr, rReq);
127 break;
131 void SwFrameShell::Execute(SfxRequest &rReq)
133 //First those who do not need FrameMgr.
134 SwWrtShell &rSh = GetShell();
135 bool bMore = false;
136 const SfxItemSet* pArgs = rReq.GetArgs();
137 const SfxPoolItem* pItem;
138 sal_uInt16 nSlot = rReq.GetSlot();
140 switch ( nSlot )
142 case FN_FRAME_TO_ANCHOR:
143 if ( rSh.IsFrameSelected() )
145 rSh.GotoFlyAnchor();
146 rSh.EnterStdMode();
147 rSh.CallChgLnk();
149 break;
150 case SID_FRAME_TO_TOP:
151 rSh.SelectionToTop();
152 break;
154 case SID_FRAME_TO_BOTTOM:
155 rSh.SelectionToBottom();
156 break;
158 case FN_FRAME_UP:
159 rSh.SelectionToTop( false );
160 break;
162 case FN_FRAME_DOWN:
163 rSh.SelectionToBottom( false );
164 break;
165 case FN_INSERT_FRAME:
166 if (!pArgs)
168 // Frame already exists, open frame dialog for editing.
169 SfxStringItem aDefPage(FN_FORMAT_FRAME_DLG, "columns");
170 rSh.GetView().GetViewFrame().GetDispatcher()->ExecuteList(
171 FN_FORMAT_FRAME_DLG,
172 SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
173 { &aDefPage });
176 else
178 // Frame already exists, only the number of columns will be changed.
179 sal_uInt16 nCols = 1;
180 if(const SfxUInt16Item* pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false))
181 nCols = pColsItem->GetValue();
183 SfxItemSetFixed<RES_COL,RES_COL> aSet(GetPool());
184 rSh.GetFlyFrameAttr( aSet );
185 SwFormatCol aCol(aSet.Get(RES_COL));
186 // GutterWidth will not always passed, hence get firstly
187 // (see view2: Execute on this slot)
188 sal_uInt16 nGutterWidth = aCol.GetGutterWidth();
189 if(!nCols )
190 nCols++;
191 aCol.Init(nCols, nGutterWidth, aCol.GetWishWidth());
192 aSet.Put(aCol);
193 // Template AutoUpdate
194 SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
195 if(pFormat && pFormat->IsAutoUpdateOnDirectFormat())
197 rSh.AutoUpdateFrame(pFormat, aSet);
199 else
201 rSh.StartAllAction();
202 rSh.SetFlyFrameAttr( aSet );
203 rSh.SetModified();
204 rSh.EndAllAction();
208 return;
210 case SID_HYPERLINK_SETLINK:
212 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_HYPERLINK_SETLINK, false, &pItem))
214 const SvxHyperlinkItem& rHLinkItem = *static_cast<const SvxHyperlinkItem *>(pItem);
215 const OUString& rURL = rHLinkItem.GetURL();
216 const OUString& rTarget = rHLinkItem.GetTargetFrame();
218 SfxItemSetFixed<RES_URL, RES_URL> aSet( rSh.GetAttrPool() );
219 rSh.GetFlyFrameAttr( aSet );
220 SwFormatURL aURL( aSet.Get( RES_URL ) );
222 OUString sOldName(rHLinkItem.GetName().toAsciiUpperCase());
223 OUString sFlyName(rSh.GetFlyName().toAsciiUpperCase());
224 if (sOldName != sFlyName)
226 OUString sName(sOldName);
227 sal_uInt16 i = 1;
228 while (rSh.FindFlyByName(sName))
230 sName = sOldName + "_" + OUString::number(i++);
232 rSh.SetFlyName(sName);
234 aURL.SetURL( rURL, false );
235 aURL.SetTargetFrameName(rTarget);
237 aSet.Put( aURL );
238 rSh.SetFlyFrameAttr( aSet );
241 break;
243 case FN_FRAME_CHAIN:
244 rSh.GetView().GetEditWin().SetChainMode( !rSh.GetView().GetEditWin().IsChainMode() );
245 break;
247 case FN_FRAME_UNCHAIN:
248 rSh.Unchain( *rSh.GetFlyFrameFormat() );
249 GetView().GetViewFrame().GetBindings().Invalidate(FN_FRAME_CHAIN);
250 break;
251 case FN_FORMAT_FOOTNOTE_DLG:
253 GetView().ExecFormatFootnote();
254 break;
256 case FN_NUMBERING_OUTLINE_DLG:
258 GetView().ExecNumberingOutline(GetPool());
259 rReq.Done();
260 break;
262 case SID_OPEN_XML_FILTERSETTINGS:
264 HandleOpenXmlFilterSettings(rReq);
266 break;
267 case FN_WORDCOUNT_DIALOG:
269 GetView().UpdateWordCount(this, nSlot);
270 break;
272 default: bMore = true;
275 if ( !bMore )
277 return;
280 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
281 bool bUpdateMgr = true;
282 bool bCopyToFormat = false;
283 switch ( nSlot )
285 case SID_OBJECT_ALIGN_MIDDLE:
286 case FN_FRAME_ALIGN_VERT_CENTER:
287 aMgr.SetVertOrientation( text::VertOrientation::CENTER );
288 break;
289 case SID_OBJECT_ALIGN_DOWN :
290 case FN_FRAME_ALIGN_VERT_BOTTOM:
291 aMgr.SetVertOrientation( text::VertOrientation::BOTTOM );
292 break;
293 case SID_OBJECT_ALIGN_UP :
294 case FN_FRAME_ALIGN_VERT_TOP:
295 aMgr.SetVertOrientation( text::VertOrientation::TOP );
296 break;
298 case FN_FRAME_ALIGN_VERT_CHAR_CENTER:
299 aMgr.SetVertOrientation( text::VertOrientation::CHAR_CENTER );
300 break;
302 case FN_FRAME_ALIGN_VERT_CHAR_BOTTOM:
303 aMgr.SetVertOrientation( text::VertOrientation::CHAR_BOTTOM );
304 break;
306 case FN_FRAME_ALIGN_VERT_CHAR_TOP:
307 aMgr.SetVertOrientation( text::VertOrientation::CHAR_TOP );
308 break;
310 case FN_FRAME_ALIGN_VERT_ROW_CENTER:
311 aMgr.SetVertOrientation( text::VertOrientation::LINE_CENTER );
312 break;
314 case FN_FRAME_ALIGN_VERT_ROW_BOTTOM:
315 aMgr.SetVertOrientation( text::VertOrientation::LINE_BOTTOM );
316 break;
318 case FN_FRAME_ALIGN_VERT_ROW_TOP:
319 aMgr.SetVertOrientation( text::VertOrientation::LINE_TOP );
320 break;
321 case SID_OBJECT_ALIGN_CENTER :
322 case FN_FRAME_ALIGN_HORZ_CENTER:
323 aMgr.SetHorzOrientation( text::HoriOrientation::CENTER );
324 break;
325 case SID_OBJECT_ALIGN_RIGHT:
326 case FN_FRAME_ALIGN_HORZ_RIGHT:
327 aMgr.SetHorzOrientation( text::HoriOrientation::RIGHT );
328 break;
329 case SID_OBJECT_ALIGN_LEFT:
330 case FN_FRAME_ALIGN_HORZ_LEFT:
331 aMgr.SetHorzOrientation( text::HoriOrientation::LEFT );
332 break;
334 case FN_SET_FRM_POSITION:
336 aMgr.SetAbsPos(static_cast<const SfxPointItem &>(pArgs->Get
337 (FN_SET_FRM_POSITION)).GetValue());
339 break;
340 case SID_ATTR_BRUSH:
342 if(pArgs)
344 aMgr.SetAttrSet( *pArgs );
345 bCopyToFormat = true;
348 break;
349 case SID_ATTR_ULSPACE:
350 case SID_ATTR_LRSPACE:
352 if(pArgs && SfxItemState::SET == pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem))
354 aMgr.SetAttrSet( *pArgs );
355 bCopyToFormat = true;
358 break;
360 case SID_ATTR_TRANSFORM:
362 bool bApplyNewPos = false;
363 bool bApplyNewSize = false;
365 Point aNewPos = aMgr.GetPos();
366 if (pArgs)
368 if (const SfxInt32Item* pXItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_POS_X, false))
370 aNewPos.setX( pXItem->GetValue() );
371 bApplyNewPos = true;
373 if (const SfxInt32Item* pYItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_POS_Y, false))
375 aNewPos.setY( pYItem->GetValue() );
376 bApplyNewPos = true;
380 Size aNewSize = aMgr.GetSize();
381 if (pArgs)
383 if (const SfxUInt32Item* pWidthItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_WIDTH, false))
385 aNewSize.setWidth( pWidthItem->GetValue() );
386 bApplyNewSize = true;
388 if (const SfxUInt32Item* pHeightItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_HEIGHT, false))
390 aNewSize.setHeight( pHeightItem->GetValue() );
391 bApplyNewSize = true;
395 if (pArgs && (pArgs->HasItem(SID_ATTR_TRANSFORM_ANGLE) || pArgs->HasItem(SID_ATTR_TRANSFORM_DELTA_ANGLE)))
397 SfxItemSetFixed<RES_GRFATR_ROTATION, RES_GRFATR_ROTATION> aSet(rSh.GetAttrPool() );
398 rSh.GetCurAttr(aSet);
399 const SwRotationGrf& rRotation = aSet.Get(RES_GRFATR_ROTATION);
400 const Degree10 nOldRot(rRotation.GetValue());
402 if (const SdrAngleItem* pAngleItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_DELTA_ANGLE, false))
404 const Degree10 nDeltaRot = to<Degree10>(pAngleItem->GetValue());
405 aMgr.SetRotation(nOldRot, nOldRot + nDeltaRot, rRotation.GetUnrotatedSize());
408 // RotGrfFlyFrame: Get Value and disable is in SwGrfShell::GetAttrStateForRotation, but the
409 // value setter uses SID_ATTR_TRANSFORM and a group of three values. Rotation is
410 // added now, so use it in this central place. Do no forget to convert angle from
411 // 100th degrees in SID_ATTR_TRANSFORM_ANGLE to 10th degrees in RES_GRFATR_ROTATION
412 if (const SdrAngleItem* pTransformItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_ANGLE, false))
414 const Degree10 nNewRot = to<Degree10>(pTransformItem->GetValue());
416 // RotGrfFlyFrame: Rotation change here, SwFlyFrameAttrMgr aMgr is available
417 aMgr.SetRotation(nOldRot, nNewRot, rRotation.GetUnrotatedSize());
421 if (bApplyNewPos)
423 aMgr.SetAbsPos(aNewPos);
425 if ( bApplyNewSize )
427 aMgr.SetSize( aNewSize );
429 if (!bApplyNewPos && !bApplyNewSize)
431 bUpdateMgr = false;
435 break;
437 case FN_FORMAT_FRAME_DLG:
438 case FN_DRAW_WRAP_DLG:
440 const SelectionType nSel = rSh.GetSelectionType();
441 if (nSel & SelectionType::Graphic)
443 rSh.GetView().GetViewFrame().GetDispatcher()->Execute(FN_FORMAT_GRAFIC_DLG);
444 bUpdateMgr = false;
446 else
448 SfxItemSetFixed<
449 RES_FRMATR_BEGIN, RES_FRMATR_END - 1,
450 // FillAttribute support:
451 XATTR_FILL_FIRST, XATTR_FILL_LAST,
452 SID_DOCFRAME, SID_DOCFRAME,
453 SID_ATTR_BRUSH, SID_ATTR_BRUSH,
454 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
455 SID_ATTR_LRSPACE, SID_ATTR_ULSPACE,
456 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
457 // Items to hand over XPropertyList things like
458 // XColorList, XHatchList, XGradientList, and
459 // XBitmapList to the Area TabPage
460 SID_COLOR_TABLE, SID_PATTERN_LIST,
461 SID_HTML_MODE, SID_HTML_MODE,
462 FN_GET_PRINT_AREA, FN_GET_PRINT_AREA,
463 FN_SURROUND, FN_KEEP_ASPECT_RATIO,
464 FN_SET_FRM_ALT_NAME, FN_SET_FRM_ALT_NAME,
465 FN_UNO_DESCRIPTION, FN_UNO_DESCRIPTION,
466 FN_OLE_IS_MATH, FN_MATH_BASELINE_ALIGNMENT,
467 FN_PARAM_CHAIN_PREVIOUS, FN_PARAM_CHAIN_NEXT> aSet( GetPool() );
469 // create needed items for XPropertyList entries from the DrawModel so that
470 // the Area TabPage can access them
471 const SwDrawModel* pDrawModel = rSh.GetView().GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
472 pDrawModel->PutAreaListItems(aSet);
474 const SwViewOption* pVOpt = rSh.GetViewOptions();
475 if(nSel & SelectionType::Ole)
476 aSet.Put( SfxBoolItem(FN_KEEP_ASPECT_RATIO, pVOpt->IsKeepRatio()) );
477 aSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(GetView().GetDocShell())));
478 aSet.Put(SfxStringItem(FN_SET_FRM_NAME, rSh.GetFlyName()));
479 aSet.Put(SfxStringItem(FN_UNO_DESCRIPTION, rSh.GetObjDescription()));
480 if( nSel & SelectionType::Ole )
482 // #i73249#
483 aSet.Put( SfxStringItem( FN_SET_FRM_ALT_NAME, rSh.GetObjTitle() ) );
486 const SwRect &rPg = rSh.GetAnyCurRect(CurRectType::Page);
487 SwFormatFrameSize aFrameSize(SwFrameSize::Variable, rPg.Width(), rPg.Height());
488 aFrameSize.SetWhich(GetPool().GetWhich(SID_ATTR_PAGE_SIZE));
489 aSet.Put(aFrameSize);
491 const SwRect &rPr = rSh.GetAnyCurRect(CurRectType::PagePrt);
492 SwFormatFrameSize aPrtSize(SwFrameSize::Variable, rPr.Width(), rPr.Height());
493 aPrtSize.SetWhich(GetPool().GetWhich(FN_GET_PRINT_AREA));
494 aSet.Put(aPrtSize);
496 aSet.Put(aMgr.GetAttrSet());
497 aSet.SetParent( aMgr.GetAttrSet().GetParent() );
499 // On % values initialize size
500 SwFormatFrameSize& rSize = const_cast<SwFormatFrameSize&>(aSet.Get(RES_FRM_SIZE));
501 if (rSize.GetWidthPercent() && rSize.GetWidthPercent() != SwFormatFrameSize::SYNCED)
502 rSize.SetWidth(rSh.GetAnyCurRect(CurRectType::FlyEmbedded).Width());
503 if (rSize.GetHeightPercent() && rSize.GetHeightPercent() != SwFormatFrameSize::SYNCED)
504 rSize.SetHeight(rSh.GetAnyCurRect(CurRectType::FlyEmbedded).Height());
506 // disable vertical positioning for Math Objects anchored 'as char' if baseline alignment is activated
507 aSet.Put( SfxBoolItem( FN_MATH_BASELINE_ALIGNMENT,
508 rSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT ) ) );
509 const uno::Reference < embed::XEmbeddedObject > xObj( rSh.GetOleRef() );
510 aSet.Put( SfxBoolItem( FN_OLE_IS_MATH, xObj.is() && SotExchange::IsMath( xObj->getClassID() ) ) );
512 OUString sDefPage;
513 const SfxStringItem* pDlgItem;
514 if(pArgs && (pDlgItem = pArgs->GetItemIfSet(FN_FORMAT_FRAME_DLG, false)))
515 sDefPage = pDlgItem->GetValue();
517 aSet.Put(SfxFrameItem( SID_DOCFRAME, &GetView().GetViewFrame().GetFrame()));
518 FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( &GetView()) != nullptr );
519 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric) ));
520 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
521 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateFrameTabDialog(
522 nSel & SelectionType::Graphic ? OUString("PictureDialog") :
523 nSel & SelectionType::Ole ? OUString("ObjectDialog"):
524 OUString("FrameDialog"),
525 GetView().GetViewFrame(),
526 GetView().GetFrameWeld(),
527 aSet,
528 false,
529 sDefPage));
531 if ( nSlot == FN_DRAW_WRAP_DLG )
533 pDlg->SetCurPageId("wrap");
536 if ( pDlg->Execute() )
538 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
539 if(pOutSet)
541 rReq.Done(*pOutSet);
542 const SfxBoolItem* pRatioItem = nullptr;
543 if(nSel & SelectionType::Ole &&
544 (pRatioItem = pOutSet->GetItemIfSet(FN_KEEP_ASPECT_RATIO)))
546 SwViewOption aUsrPref( *pVOpt );
547 aUsrPref.SetKeepRatio(pRatioItem->GetValue());
548 SW_MOD()->ApplyUsrPref(aUsrPref, &GetView());
550 if (const SfxStringItem* pAltNameItem = pOutSet->GetItemIfSet(FN_SET_FRM_ALT_NAME))
552 // #i73249#
553 rSh.SetObjTitle(pAltNameItem->GetValue());
555 if (const SfxStringItem* pDescripItem = pOutSet->GetItemIfSet(FN_UNO_DESCRIPTION))
556 rSh.SetObjDescription(pDescripItem->GetValue());
558 // Template AutoUpdate
559 SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
560 if(pFormat && pFormat->IsAutoUpdateOnDirectFormat())
562 rSh.AutoUpdateFrame(pFormat, *pOutSet);
563 // Anything which is not supported by the format must be set hard.
564 if(const SfxStringItem* pFrameName = pOutSet->GetItemIfSet(FN_SET_FRM_NAME, false))
565 rSh.SetFlyName(pFrameName->GetValue());
566 SfxItemSetFixed<
567 RES_FRM_SIZE, RES_FRM_SIZE,
568 RES_SURROUND, RES_ANCHOR> aShellSet( GetPool() );
569 aShellSet.Put(*pOutSet);
570 aMgr.SetAttrSet(aShellSet);
571 if(const SfxStringItem* pFrameName = pOutSet->GetItemIfSet(FN_SET_FRM_NAME, false))
572 rSh.SetFlyName(pFrameName->GetValue());
574 else
575 aMgr.SetAttrSet( *pOutSet );
577 const SwFrameFormat* pCurrFlyFormat = rSh.GetFlyFrameFormat();
578 if(const SfxStringItem* pPreviousItem =
579 pOutSet->GetItemIfSet(FN_PARAM_CHAIN_PREVIOUS, false))
581 rSh.HideChainMarker();
583 OUString sPrevName = pPreviousItem->GetValue();
584 const SwFormatChain &rChain = pCurrFlyFormat->GetChain();
585 //needs cast - no non-const method available
586 SwFlyFrameFormat* pFlyFormat =
587 rChain.GetPrev();
588 if(pFlyFormat)
590 if (pFlyFormat->GetName() != sPrevName)
592 rSh.Unchain(*pFlyFormat);
594 else
595 sPrevName.clear();
598 if (!sPrevName.isEmpty())
600 //needs cast - no non-const method available
601 SwFrameFormat* pPrevFormat = const_cast<SwFrameFormat*>(
602 lcl_GetFrameFormatByName(rSh, sPrevName));
603 SAL_WARN_IF(!pPrevFormat, "sw.ui", "No frame found!");
604 if(pPrevFormat)
606 rSh.Chain(*pPrevFormat, *pCurrFlyFormat);
609 rSh.SetChainMarker();
611 if(const SfxStringItem* pChainNextItem =
612 pOutSet->GetItemIfSet(FN_PARAM_CHAIN_NEXT, false))
614 rSh.HideChainMarker();
615 OUString sNextName = pChainNextItem->GetValue();
616 const SwFormatChain &rChain = pCurrFlyFormat->GetChain();
617 //needs cast - no non-const method available
618 SwFlyFrameFormat* pFlyFormat =
619 rChain.GetNext();
620 if(pFlyFormat)
622 if (pFlyFormat->GetName() != sNextName)
624 rSh.Unchain(*const_cast<SwFlyFrameFormat*>(static_cast<const SwFlyFrameFormat*>( pCurrFlyFormat)));
626 else
627 sNextName.clear();
630 if (!sNextName.isEmpty())
632 //needs cast - no non-const method available
633 SwFrameFormat* pNextFormat = const_cast<SwFrameFormat*>(
634 lcl_GetFrameFormatByName(rSh, sNextName));
635 SAL_WARN_IF(!pNextFormat, "sw.ui", "No frame found!");
636 if(pNextFormat)
638 rSh.Chain(*const_cast<SwFrameFormat*>(
639 pCurrFlyFormat), *pNextFormat);
642 rSh.SetChainMarker();
646 else
647 bUpdateMgr = false;
650 break;
651 case FN_FRAME_MIRROR_ON_EVEN_PAGES:
653 SwFormatHoriOrient aHori(aMgr.GetHoriOrient());
654 bool bMirror = !aHori.IsPosToggle();
655 aHori.SetPosToggle(bMirror);
656 SfxItemSetFixed<RES_HORI_ORIENT, RES_HORI_ORIENT> aSet(GetPool());
657 aSet.Put(aHori);
658 aMgr.SetAttrSet(aSet);
659 bCopyToFormat = true;
660 rReq.SetReturnValue(SfxBoolItem(nSlot, bMirror));
662 break;
663 case FN_NAME_SHAPE:
665 bUpdateMgr = false;
666 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
667 if ( pSdrView &&
668 pSdrView->GetMarkedObjectCount() == 1 )
670 OUString aName(rSh.GetFlyName());
671 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
672 ScopedVclPtr<AbstractSvxObjectNameDialog> pDlg(
673 pFact->CreateSvxObjectNameDialog(GetView().GetFrameWeld(), aName));
675 if ( pDlg->Execute() == RET_OK )
677 pDlg->GetName(aName);
678 rSh.SetFlyName(aName);
682 break;
683 // #i73249#
684 case FN_TITLE_DESCRIPTION_SHAPE:
686 bUpdateMgr = false;
687 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
688 if ( pSdrView &&
689 pSdrView->GetMarkedObjectCount() == 1 )
691 OUString aDescription(rSh.GetObjDescription());
692 OUString aTitle(rSh.GetObjTitle());
693 bool isDecorative(rSh.IsObjDecorative());
695 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
696 ScopedVclPtr<AbstractSvxObjectTitleDescDialog> pDlg(
697 pFact->CreateSvxObjectTitleDescDialog(GetView().GetFrameWeld(),
698 aTitle, aDescription, isDecorative));
700 if ( pDlg->Execute() == RET_OK )
702 pDlg->GetDescription(aDescription);
703 pDlg->GetTitle(aTitle);
704 pDlg->IsDecorative(isDecorative);
706 rSh.SetObjDescription(aDescription);
707 rSh.SetObjTitle(aTitle);
708 rSh.SetObjDecorative(isDecorative);
712 break;
713 default:
714 assert(!"wrong dispatcher");
715 return;
717 if ( bUpdateMgr )
719 SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
720 if ( bCopyToFormat && pFormat && pFormat->IsAutoUpdateOnDirectFormat() )
722 rSh.AutoUpdateFrame(pFormat, aMgr.GetAttrSet());
724 else
726 aMgr.UpdateFlyFrame();
732 void SwFrameShell::GetState(SfxItemSet& rSet)
734 SwWrtShell &rSh = GetShell();
735 bool bHtmlMode = 0 != ::GetHtmlMode(rSh.GetView().GetDocShell());
736 if (!rSh.IsFrameSelected())
737 return;
739 SfxItemSetFixed<
740 RES_LR_SPACE, RES_UL_SPACE,
741 RES_PRINT, RES_HORI_ORIENT> aSet(rSh.GetAttrPool() );
742 rSh.GetFlyFrameAttr( aSet );
744 bool bProtect = rSh.IsSelObjProtected(FlyProtectFlags::Pos) != FlyProtectFlags::NONE;
745 bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
747 bProtect |= bParentCntProt;
749 const FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
750 SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
752 SfxWhichIter aIter( rSet );
753 sal_uInt16 nWhich = aIter.FirstWhich();
754 while ( nWhich )
756 switch ( nWhich )
758 case RES_FRM_SIZE:
760 const SwFormatFrameSize& aSz(aMgr.GetFrameSize());
761 rSet.Put(aSz);
763 break;
764 case RES_VERT_ORIENT:
765 case RES_HORI_ORIENT:
766 case SID_ATTR_ULSPACE:
767 case SID_ATTR_LRSPACE:
768 case RES_LR_SPACE:
769 case RES_UL_SPACE:
770 case RES_PROTECT:
771 case RES_OPAQUE:
772 case RES_PRINT:
773 case RES_SURROUND:
775 rSet.Put(aSet.Get(GetPool().GetWhich(nWhich)));
777 break;
778 case SID_OBJECT_ALIGN:
780 if ( bProtect )
781 rSet.DisableItem( nWhich );
783 break;
784 case SID_OBJECT_ALIGN_LEFT :
785 case SID_OBJECT_ALIGN_CENTER :
786 case SID_OBJECT_ALIGN_RIGHT :
787 case FN_FRAME_ALIGN_HORZ_CENTER:
788 case FN_FRAME_ALIGN_HORZ_RIGHT:
789 case FN_FRAME_ALIGN_HORZ_LEFT:
790 if ( (eFrameType & FrameTypeFlags::FLY_INCNT) ||
791 bProtect ||
792 ((nWhich == FN_FRAME_ALIGN_HORZ_CENTER || nWhich == SID_OBJECT_ALIGN_CENTER) &&
793 bHtmlMode ))
795 rSet.DisableItem( nWhich );
797 else
799 sal_Int16 nHoriOrient = -1;
800 switch(nWhich)
802 case SID_OBJECT_ALIGN_LEFT:
803 nHoriOrient = text::HoriOrientation::LEFT;
804 break;
805 case SID_OBJECT_ALIGN_CENTER:
806 nHoriOrient = text::HoriOrientation::CENTER;
807 break;
808 case SID_OBJECT_ALIGN_RIGHT:
809 nHoriOrient = text::HoriOrientation::RIGHT;
810 break;
811 default:
812 break;
814 SwFormatHoriOrient aHOrient(aMgr.GetHoriOrient());
815 if (nHoriOrient != -1)
816 rSet.Put(SfxBoolItem(nWhich, nHoriOrient == aHOrient.GetHoriOrient()));
818 break;
819 case FN_FRAME_ALIGN_VERT_ROW_TOP:
820 case FN_FRAME_ALIGN_VERT_ROW_CENTER:
821 case FN_FRAME_ALIGN_VERT_ROW_BOTTOM:
822 case FN_FRAME_ALIGN_VERT_CHAR_TOP:
823 case FN_FRAME_ALIGN_VERT_CHAR_CENTER:
824 case FN_FRAME_ALIGN_VERT_CHAR_BOTTOM:
825 if ( !(eFrameType & FrameTypeFlags::FLY_INCNT) || bProtect
826 || (bHtmlMode && FN_FRAME_ALIGN_VERT_CHAR_BOTTOM == nWhich) )
827 rSet.DisableItem( nWhich );
828 break;
830 case SID_OBJECT_ALIGN_UP :
831 case SID_OBJECT_ALIGN_MIDDLE :
832 case SID_OBJECT_ALIGN_DOWN :
834 case FN_FRAME_ALIGN_VERT_TOP:
835 case FN_FRAME_ALIGN_VERT_CENTER:
836 case FN_FRAME_ALIGN_VERT_BOTTOM:
837 if ( bProtect || (bHtmlMode && eFrameType & FrameTypeFlags::FLY_ATCNT))
838 rSet.DisableItem( nWhich );
839 else
841 // These slots need different labels depending on whether they are anchored in a character
842 // or on a paragraph/page etc.
843 OUString sNewLabel;
844 if (eFrameType & FrameTypeFlags::FLY_INCNT)
846 switch (nWhich)
848 case SID_OBJECT_ALIGN_UP :
849 case FN_FRAME_ALIGN_VERT_TOP:
850 sNewLabel = SwResId(STR_FRMUI_TOP_BASE);
851 break;
852 case SID_OBJECT_ALIGN_MIDDLE :
853 case FN_FRAME_ALIGN_VERT_CENTER:
854 sNewLabel = SwResId(STR_FRMUI_CENTER_BASE);
855 break;
856 case SID_OBJECT_ALIGN_DOWN :
857 case FN_FRAME_ALIGN_VERT_BOTTOM:
858 if(!bHtmlMode)
859 sNewLabel = SwResId(STR_FRMUI_BOTTOM_BASE);
860 else
861 rSet.DisableItem( nWhich );
862 break;
865 else
867 if (nWhich != FN_FRAME_ALIGN_VERT_TOP &&
868 nWhich != SID_OBJECT_ALIGN_UP )
870 if (aMgr.GetAnchor() == RndStdIds::FLY_AT_FLY)
872 const SwFrameFormat* pFormat = rSh.IsFlyInFly();
873 if (pFormat)
875 const SwFormatFrameSize& rFrameSz = pFormat->GetFrameSize();
876 if (rFrameSz.GetHeightSizeType() != SwFrameSize::Fixed)
878 rSet.DisableItem( nWhich );
879 break;
884 OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(GetFrame()->GetFrame().GetFrameInterface()));
885 switch (nWhich)
887 case SID_OBJECT_ALIGN_UP :
888 case FN_FRAME_ALIGN_VERT_TOP:
890 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(".uno:AlignTop", aModuleName);
891 sNewLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
892 break;
894 case SID_OBJECT_ALIGN_MIDDLE:
895 case FN_FRAME_ALIGN_VERT_CENTER:
897 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(".uno:AlignVerticalCenter", aModuleName);
898 sNewLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
899 break;
901 case SID_OBJECT_ALIGN_DOWN:
902 case FN_FRAME_ALIGN_VERT_BOTTOM:
904 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(".uno:AlignBottom", aModuleName);
905 sNewLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
906 break;
910 if ( !sNewLabel.isEmpty() )
911 rSet.Put( SfxStringItem( nWhich, sNewLabel ));
913 break;
914 case SID_HYPERLINK_GETLINK:
916 SvxHyperlinkItem aHLinkItem;
918 SfxItemSetFixed<RES_URL, RES_URL> aURLSet(GetPool());
919 rSh.GetFlyFrameAttr( aURLSet );
921 if(const SwFormatURL* pFormatURL = aURLSet.GetItemIfSet(RES_URL))
923 aHLinkItem.SetURL(pFormatURL->GetURL());
924 aHLinkItem.SetTargetFrame(pFormatURL->GetTargetFrameName());
925 aHLinkItem.SetName(rSh.GetFlyName());
928 aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() |
929 (bHtmlMode ? HLINK_HTMLMODE : 0)));
931 rSet.Put(aHLinkItem);
933 break;
935 case FN_FRAME_CHAIN:
937 const SelectionType nSel = rSh.GetSelectionType();
938 if (nSel & SelectionType::Graphic || nSel & SelectionType::Ole)
939 rSet.DisableItem( FN_FRAME_CHAIN );
940 else
942 const SwFrameFormat *pFormat = rSh.GetFlyFrameFormat();
943 if ( bParentCntProt || rSh.GetView().GetEditWin().GetApplyTemplate() ||
944 !pFormat || pFormat->GetChain().GetNext() )
946 rSet.DisableItem( FN_FRAME_CHAIN );
948 else
950 bool bChainMode = rSh.GetView().GetEditWin().IsChainMode();
951 rSet.Put( SfxBoolItem( FN_FRAME_CHAIN, bChainMode ) );
955 break;
956 case FN_FRAME_UNCHAIN:
958 const SelectionType nSel = rSh.GetSelectionType();
959 if (nSel & SelectionType::Graphic || nSel & SelectionType::Ole)
960 rSet.DisableItem( FN_FRAME_UNCHAIN );
961 else
963 const SwFrameFormat *pFormat = rSh.GetFlyFrameFormat();
964 if ( bParentCntProt || rSh.GetView().GetEditWin().GetApplyTemplate() ||
965 !pFormat || !pFormat->GetChain().GetNext() )
967 rSet.DisableItem( FN_FRAME_UNCHAIN );
971 break;
972 case SID_FRAME_TO_TOP:
973 case SID_FRAME_TO_BOTTOM:
974 case FN_FRAME_UP:
975 case FN_FRAME_DOWN:
976 if ( bParentCntProt )
977 rSet.DisableItem( nWhich );
978 break;
980 case SID_ATTR_TRANSFORM:
982 rSet.DisableItem( nWhich );
984 break;
986 case SID_ATTR_TRANSFORM_PROTECT_SIZE:
988 const FlyProtectFlags eProtection = rSh.IsSelObjProtected( FlyProtectFlags::Size );
989 if ( ( eProtection & FlyProtectFlags::Content ) ||
990 ( eProtection & FlyProtectFlags::Size ) )
992 rSet.Put( SfxBoolItem( SID_ATTR_TRANSFORM_PROTECT_SIZE, true ) );
994 else
996 rSet.Put( SfxBoolItem( SID_ATTR_TRANSFORM_PROTECT_SIZE, false ) );
999 break;
1001 case SID_ATTR_TRANSFORM_WIDTH:
1003 rSet.Put( SfxUInt32Item( SID_ATTR_TRANSFORM_WIDTH, aMgr.GetSize().getWidth() ) );
1005 break;
1007 case SID_ATTR_TRANSFORM_HEIGHT:
1009 rSet.Put( SfxUInt32Item( SID_ATTR_TRANSFORM_HEIGHT, aMgr.GetSize().getHeight() ) );
1011 break;
1013 case FN_FORMAT_FRAME_DLG:
1015 const SelectionType nSel = rSh.GetSelectionType();
1016 if ( bParentCntProt || nSel & SelectionType::Graphic)
1017 rSet.DisableItem( nWhich );
1019 break;
1020 // #i73249#
1021 case FN_TITLE_DESCRIPTION_SHAPE:
1022 case FN_NAME_SHAPE:
1024 SwWrtShell &rWrtSh = GetShell();
1025 SdrView* pSdrView = rWrtSh.GetDrawViewWithValidMarkList();
1026 if ( !pSdrView ||
1027 pSdrView->GetMarkedObjectCount() != 1 )
1029 rSet.DisableItem( nWhich );
1032 break;
1034 case FN_POSTIT:
1036 SwFlyFrame* pFly = rSh.GetSelectedFlyFrame();
1037 if (pFly)
1039 SwFrameFormat* pFormat = pFly->GetFormat();
1040 if (pFormat)
1042 RndStdIds eAnchorId = pFormat->GetAnchor().GetAnchorId();
1043 // SwWrtShell::InsertPostIt() only works on as-char and at-char anchored
1044 // images.
1045 if (eAnchorId != RndStdIds::FLY_AS_CHAR && eAnchorId != RndStdIds::FLY_AT_CHAR)
1047 rSet.DisableItem(nWhich);
1052 break;
1054 default:
1055 /* do nothing */;
1056 break;
1058 nWhich = aIter.NextWhich();
1062 SwFrameShell::SwFrameShell(SwView &_rView) :
1063 SwBaseShell( _rView )
1065 SetName("Frame");
1067 // #96392# Use this to announce it is the frame shell who creates the selection.
1068 SwTransferable::CreateSelection( _rView.GetWrtShell(), this );
1070 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Frame));
1073 SwFrameShell::~SwFrameShell()
1075 // #96392# Only clear the selection if it was this frame shell who created it.
1076 SwTransferable::ClearSelection( GetShell(), this );
1079 void SwFrameShell::ExecFrameStyle(SfxRequest const & rReq)
1081 SwWrtShell &rSh = GetShell();
1082 bool bDefault = false;
1083 if (!rSh.IsFrameSelected())
1084 return;
1085 // At first pick the default BoxItem out of the pool.
1086 // If unequal to regular box item, then it has already
1087 // been changed (New one is no default).
1088 const SvxBoxItem* pPoolBoxItem = ::GetDfltAttr(RES_BOX);
1090 const SfxItemSet *pArgs = rReq.GetArgs();
1091 SfxItemSetFixed<RES_BOX, RES_BOX> aFrameSet(rSh.GetAttrPool());
1093 rSh.GetFlyFrameAttr( aFrameSet );
1094 const SvxBoxItem& rBoxItem = aFrameSet.Get(RES_BOX);
1096 if (pPoolBoxItem == &rBoxItem)
1097 bDefault = true;
1099 std::unique_ptr<SvxBoxItem> aBoxItem(rBoxItem.Clone());
1101 SvxBorderLine aBorderLine;
1103 if(pArgs) // Any controller can sometimes deliver nothing #48169#
1105 switch (rReq.GetSlot())
1107 case SID_ATTR_BORDER:
1109 if (const SvxBoxItem* pBoxItem = pArgs->GetItemIfSet(RES_BOX))
1111 std::unique_ptr<SvxBoxItem> aNewBox(pBoxItem->Clone());
1112 const SvxBorderLine* pBorderLine;
1114 pBorderLine = aBoxItem->GetTop();
1115 if (pBorderLine != nullptr)
1116 lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine);
1117 pBorderLine = aBoxItem->GetBottom();
1118 if (pBorderLine != nullptr)
1119 lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine);
1120 pBorderLine = aBoxItem->GetLeft();
1121 if (pBorderLine != nullptr)
1122 lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine);
1123 pBorderLine = aBoxItem->GetRight();
1124 if (pBorderLine != nullptr)
1125 lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine);
1127 if(aBorderLine.GetOutWidth() == 0)
1129 aBorderLine.SetBorderLineStyle(
1130 SvxBorderLineStyle::SOLID);
1131 aBorderLine.SetWidth( SvxBorderLineWidth::Hairline );
1133 //Set distance only if the request is received from the controller.
1135 #if HAVE_FEATURE_SCRIPTING
1136 if(!StarBASIC::IsRunning())
1137 #endif
1139 // TODO: should this copy 4 individual Dist instead?
1140 aNewBox->SetAllDistances(rBoxItem.GetSmallestDistance());
1143 aBoxItem = std::move(aNewBox);
1145 if( aBoxItem->GetTop() != nullptr )
1146 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP);
1147 if( aBoxItem->GetBottom() != nullptr )
1148 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM);
1149 if( aBoxItem->GetLeft() != nullptr )
1150 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT);
1151 if( aBoxItem->GetRight() != nullptr )
1152 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT);
1155 break;
1157 case SID_FRAME_LINESTYLE:
1159 if ( const SvxLineItem* pLineItem = pArgs->GetItemIfSet(SID_FRAME_LINESTYLE, false))
1161 if ( pLineItem->GetLine() )
1163 aBorderLine = *(pLineItem->GetLine());
1165 if (!aBoxItem->GetTop() && !aBoxItem->GetBottom() &&
1166 !aBoxItem->GetLeft() && !aBoxItem->GetRight())
1168 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP);
1169 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM);
1170 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT);
1171 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT);
1173 else
1175 if( aBoxItem->GetTop() )
1177 aBorderLine.SetColor( aBoxItem->GetTop()->GetColor() );
1178 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP);
1180 if( aBoxItem->GetBottom() )
1182 aBorderLine.SetColor( aBoxItem->GetBottom()->GetColor());
1183 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM);
1185 if( aBoxItem->GetLeft() )
1187 aBorderLine.SetColor( aBoxItem->GetLeft()->GetColor());
1188 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT);
1190 if( aBoxItem->GetRight() )
1192 aBorderLine.SetColor(aBoxItem->GetRight()->GetColor());
1193 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT);
1197 else
1199 aBoxItem->SetLine(nullptr, SvxBoxItemLine::TOP);
1200 aBoxItem->SetLine(nullptr, SvxBoxItemLine::BOTTOM);
1201 aBoxItem->SetLine(nullptr, SvxBoxItemLine::LEFT);
1202 aBoxItem->SetLine(nullptr, SvxBoxItemLine::RIGHT);
1206 break;
1208 case SID_FRAME_LINECOLOR:
1210 if (const SvxColorItem* pColorItem = pArgs->GetItemIfSet(SID_FRAME_LINECOLOR, false))
1212 const Color& rNewColor = pColorItem->GetValue();
1214 if (!aBoxItem->GetTop() && !aBoxItem->GetBottom() &&
1215 !aBoxItem->GetLeft() && !aBoxItem->GetRight())
1217 aBorderLine.SetColor( rNewColor );
1218 aBorderLine.SetBorderLineStyle(SvxBorderLineStyle::SOLID);
1219 aBorderLine.SetWidth(SvxBorderLineWidth::Hairline);
1221 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP);
1222 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM);
1223 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT);
1224 aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT);
1226 else
1228 if (aBoxItem->GetTop())
1229 aBoxItem->GetTop()->SetColor(rNewColor);
1230 if (aBoxItem->GetBottom())
1231 aBoxItem->GetBottom()->SetColor(rNewColor);
1232 if (aBoxItem->GetLeft())
1233 aBoxItem->GetLeft()->SetColor(rNewColor);
1234 if (aBoxItem->GetRight())
1235 aBoxItem->GetRight()->SetColor(rNewColor);
1239 break;
1242 if (bDefault && (aBoxItem->GetTop() || aBoxItem->GetBottom() ||
1243 aBoxItem->GetLeft() || aBoxItem->GetRight()))
1245 aBoxItem->SetAllDistances(MIN_BORDER_DIST);
1247 aFrameSet.Put( std::move(aBoxItem) );
1248 // Template AutoUpdate
1249 SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
1250 if(pFormat && pFormat->IsAutoUpdateOnDirectFormat())
1252 rSh.AutoUpdateFrame(pFormat, aFrameSet);
1254 else
1255 rSh.SetFlyFrameAttr( aFrameSet );
1259 static void lcl_FrameGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine)
1261 if(pBorderLine->GetWidth() > rBorderLine.GetWidth())
1262 rBorderLine.SetWidth(pBorderLine->GetWidth());
1264 rBorderLine.SetBorderLineStyle(pBorderLine->GetBorderLineStyle());
1265 rBorderLine.SetColor(pBorderLine->GetColor());
1268 void SwFrameShell::GetLineStyleState(SfxItemSet &rSet)
1270 SwWrtShell &rSh = GetShell();
1271 bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
1273 if (bParentCntProt)
1275 if (rSh.IsFrameSelected())
1276 rSet.DisableItem( SID_FRAME_LINECOLOR );
1278 rSet.DisableItem( SID_ATTR_BORDER );
1279 rSet.DisableItem( SID_FRAME_LINESTYLE );
1281 else
1283 if (rSh.IsFrameSelected())
1285 SfxItemSetFixed<RES_BOX, RES_BOX> aFrameSet( rSh.GetAttrPool() );
1287 rSh.GetFlyFrameAttr(aFrameSet);
1289 const SvxBorderLine* pLine = aFrameSet.Get(RES_BOX).GetTop();
1290 rSet.Put(SvxColorItem(pLine ? pLine->GetColor() : Color(), SID_FRAME_LINECOLOR));
1295 void SwFrameShell::StateInsert(SfxItemSet &rSet)
1297 const SelectionType nSel = GetShell().GetSelectionType();
1298 if ( (nSel & SelectionType::Graphic)
1299 || (nSel & SelectionType::Ole) )
1301 rSet.DisableItem(FN_INSERT_FRAME);
1303 else if ( GetShell().CursorInsideInputField() )
1305 rSet.DisableItem(FN_INSERT_FRAME);
1309 void SwFrameShell::GetDrawAttrStateTextFrame(SfxItemSet &rSet)
1311 SwWrtShell &rSh = GetShell();
1313 if(rSh.IsFrameSelected())
1315 rSh.GetFlyFrameAttr(rSet);
1317 else
1319 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
1321 if(pSdrView)
1323 rSet.Put(pSdrView->GetDefaultAttr());
1328 void SwFrameShell::ExecDrawAttrArgsTextFrame(SfxRequest const & rReq)
1330 const SfxItemSet* pArgs = rReq.GetArgs();
1331 SwWrtShell& rSh = GetShell();
1333 if(pArgs)
1335 if(rSh.IsFrameSelected())
1337 rSh.SetFlyFrameAttr(const_cast< SfxItemSet& >(*pArgs));
1339 else
1341 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
1343 if(pSdrView)
1345 pSdrView->SetDefaultAttr(*pArgs, false);
1349 else
1351 SfxDispatcher* pDis = rSh.GetView().GetViewFrame().GetDispatcher();
1353 switch(rReq.GetSlot())
1355 case SID_ATTR_FILL_STYLE:
1356 case SID_ATTR_FILL_COLOR:
1357 case SID_ATTR_FILL_GRADIENT:
1358 case SID_ATTR_FILL_HATCH:
1359 case SID_ATTR_FILL_BITMAP:
1360 case SID_ATTR_FILL_TRANSPARENCE:
1361 case SID_ATTR_FILL_FLOATTRANSPARENCE:
1363 pDis->Execute(SID_ATTRIBUTES_AREA);
1364 break;
1370 void SwFrameShell::ExecDrawDlgTextFrame(SfxRequest const & rReq)
1372 switch(rReq.GetSlot())
1374 case SID_ATTRIBUTES_AREA:
1376 SwWrtShell& rSh = GetShell();
1378 if(rSh.IsFrameSelected())
1380 SdrModel& rModel = rSh.GetDrawView()->GetModel();
1381 SfxItemSet aNewAttr(rModel.GetItemPool());
1383 // get attributes from FlyFrame
1384 rSh.GetFlyFrameAttr(aNewAttr);
1386 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1387 VclPtr<AbstractSvxAreaTabDialog> pDlg(pFact->CreateSvxAreaTabDialog(
1388 GetView().GetFrameWeld(),
1389 &aNewAttr,
1390 &rModel,
1391 false,
1392 false));
1394 pDlg->StartExecuteAsync([pDlg, this](sal_Int32 nResult){
1395 if(nResult == RET_OK)
1397 // set attributes at FlyFrame
1398 GetShell().SetFlyFrameAttr(const_cast< SfxItemSet& >(*pDlg->GetOutputItemSet()));
1400 static sal_uInt16 aInval[] =
1402 SID_ATTR_FILL_STYLE,
1403 SID_ATTR_FILL_COLOR,
1404 SID_ATTR_FILL_TRANSPARENCE,
1405 SID_ATTR_FILL_FLOATTRANSPARENCE,
1409 SfxBindings &rBnd = GetView().GetViewFrame().GetBindings();
1411 rBnd.Invalidate(aInval);
1412 rBnd.Update(SID_ATTR_FILL_STYLE);
1413 rBnd.Update(SID_ATTR_FILL_COLOR);
1414 rBnd.Update(SID_ATTR_FILL_TRANSPARENCE);
1415 rBnd.Update(SID_ATTR_FILL_FLOATTRANSPARENCE);
1417 pDlg->disposeOnce();
1421 break;
1426 void SwFrameShell::DisableStateTextFrame(SfxItemSet &rSet)
1428 SfxWhichIter aIter(rSet);
1429 sal_uInt16 nWhich(aIter.FirstWhich());
1431 while(nWhich)
1433 switch(nWhich)
1435 case SID_ATTRIBUTES_AREA:
1437 SwWrtShell& rSh = GetShell();
1439 if(!rSh.IsFrameSelected())
1441 rSet.DisableItem(nWhich);
1444 break;
1446 default:
1448 rSet.DisableItem(nWhich);
1449 break;
1453 nWhich = aIter.NextWhich();
1457 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */