Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/shells/frmsh.cxx
Line
Count
Source
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 <config_features.h>
21
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 <sfx2/toolbarids.hxx>
37
#include <vcl/EnumContext.hxx>
38
#include <svx/hlnkitem.hxx>
39
#include <svx/svdview.hxx>
40
#include <svx/sdangitm.hxx>
41
#include <vcl/commandinfoprovider.hxx>
42
#include <sal/log.hxx>
43
44
#include <doc.hxx>
45
#include <drawdoc.hxx>
46
#include <IDocumentSettingAccess.hxx>
47
#include <IDocumentDrawModelAccess.hxx>
48
#include <fmturl.hxx>
49
#include <fmtclds.hxx>
50
#include <fmtcnct.hxx>
51
#include <swmodule.hxx>
52
#include <wrtsh.hxx>
53
#include <wview.hxx>
54
#include <uitool.hxx>
55
#include <frmfmt.hxx>
56
#include <frmsh.hxx>
57
#include <frmmgr.hxx>
58
#include <edtwin.hxx>
59
#include <swdtflvr.hxx>
60
#include <viewopt.hxx>
61
62
#include <cmdid.h>
63
#include <strings.hrc>
64
#include <swabstdlg.hxx>
65
66
#include <svx/svxdlg.hxx>
67
68
#include <docsh.hxx>
69
#include <svx/drawitem.hxx>
70
#include <memory>
71
72
#define ShellClass_SwFrameShell
73
#include <sfx2/msg.hxx>
74
#include <swslots.hxx>
75
#include <grfatr.hxx>
76
#include <fldmgr.hxx>
77
#include <flyfrm.hxx>
78
79
using ::editeng::SvxBorderLine;
80
using namespace ::com::sun::star;
81
using namespace ::com::sun::star::uno;
82
83
// Prototypes
84
static void lcl_FrameGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine);
85
86
SFX_IMPL_INTERFACE(SwFrameShell, SwBaseShell)
87
88
void SwFrameShell::InitInterface_Impl()
89
9
{
90
9
    GetStaticInterface()->RegisterPopupMenu(u"frame"_ustr);
91
92
9
    GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Frame_Toolbox);
93
9
}
94
95
void SwFrameShell::ExecMove(SfxRequest& rReq)
96
0
{
97
0
    SwWrtShell& rSh = GetShell();
98
0
    sal_uInt16 nSlot = rReq.GetSlot();
99
0
    switch (nSlot)
100
0
    {
101
0
        case SID_SELECTALL:
102
0
            rSh.SelAll();
103
0
            rReq.Done();
104
0
            break;
105
0
    }
106
0
}
107
108
void SwFrameShell::ExecField(const SfxRequest& rReq)
109
0
{
110
0
    SwWrtShell& rSh = GetShell();
111
0
    sal_uInt16 nSlot = rReq.GetSlot();
112
0
    switch (nSlot)
113
0
    {
114
0
        case FN_POSTIT:
115
0
            SwFieldMgr aFieldMgr(&rSh);
116
0
            rSh.InsertPostIt(aFieldMgr, rReq);
117
0
            break;
118
0
    }
119
0
}
120
121
void SwFrameShell::Execute(SfxRequest &rReq)
122
0
{
123
    //First those who do not need FrameMgr.
124
0
    SwWrtShell &rSh = GetShell();
125
0
    bool bMore = false;
126
0
    const SfxItemSet* pArgs = rReq.GetArgs();
127
0
    const SfxPoolItem* pItem;
128
0
    sal_uInt16 nSlot = rReq.GetSlot();
129
130
0
    switch ( nSlot )
131
0
    {
132
0
        case FN_FRAME_TO_ANCHOR:
133
0
            if ( rSh.IsFrameSelected() )
134
0
            {
135
0
                rSh.GotoFlyAnchor();
136
0
                rSh.EnterStdMode();
137
0
                rSh.CallChgLnk();
138
0
            }
139
0
            break;
140
0
        case SID_FRAME_TO_TOP:
141
0
            rSh.SelectionToTop();
142
0
            break;
143
144
0
        case SID_FRAME_TO_BOTTOM:
145
0
            rSh.SelectionToBottom();
146
0
            break;
147
148
0
        case FN_FRAME_UP:
149
0
            rSh.SelectionToTop( false );
150
0
            break;
151
152
0
        case FN_FRAME_DOWN:
153
0
            rSh.SelectionToBottom( false );
154
0
            break;
155
0
        case FN_INSERT_FRAME:
156
0
            if (!pArgs)
157
0
            {
158
                // Frame already exists, open frame dialog for editing.
159
0
                SfxStringItem aDefPage(FN_FORMAT_FRAME_DLG, u"columns"_ustr);
160
0
                rSh.GetView().GetViewFrame().GetDispatcher()->ExecuteList(
161
0
                        FN_FORMAT_FRAME_DLG,
162
0
                        SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
163
0
                        { &aDefPage });
164
165
0
            }
166
0
            else
167
0
            {
168
                // Frame already exists, only the number of columns will be changed.
169
0
                sal_uInt16 nCols = 1;
170
0
                if(const SfxUInt16Item* pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false))
171
0
                    nCols = pColsItem->GetValue();
172
173
0
                SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_COL,RES_COL>(GetPool()));
174
0
                rSh.GetFlyFrameAttr( aSet );
175
0
                SwFormatCol aCol(aSet.Get(RES_COL));
176
                // GutterWidth will not always passed, hence get firstly
177
                // (see view2: Execute on this slot)
178
0
                sal_uInt16 nGutterWidth = aCol.GetGutterWidth();
179
0
                if(!nCols )
180
0
                    nCols++;
181
0
                aCol.Init(nCols, nGutterWidth, aCol.GetWishWidth());
182
0
                aSet.Put(aCol);
183
                // Template AutoUpdate
184
0
                SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
185
0
                if(pFormat && pFormat->IsAutoUpdateOnDirectFormat())
186
0
                {
187
0
                    rSh.AutoUpdateFrame(pFormat, aSet);
188
0
                }
189
0
                else
190
0
                {
191
0
                    rSh.StartAllAction();
192
0
                    rSh.SetFlyFrameAttr( aSet );
193
0
                    rSh.SetModified();
194
0
                    rSh.EndAllAction();
195
0
                }
196
197
0
            }
198
0
            return;
199
200
0
        case SID_HYPERLINK_SETLINK:
201
0
        {
202
0
            if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_HYPERLINK_SETLINK, false, &pItem))
203
0
            {
204
0
                const SvxHyperlinkItem& rHLinkItem = *static_cast<const SvxHyperlinkItem *>(pItem);
205
0
                const OUString& rURL = rHLinkItem.GetURL();
206
0
                const OUString& rTarget = rHLinkItem.GetTargetFrame();
207
208
0
                SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_URL, RES_URL>( rSh.GetAttrPool() ));
209
0
                rSh.GetFlyFrameAttr( aSet );
210
0
                SwFormatURL aURL( aSet.Get( RES_URL ) );
211
212
0
                OUString sOldName(rHLinkItem.GetName().toAsciiUpperCase());
213
0
                OUString sFlyName(rSh.GetFlyName().toString().toAsciiUpperCase());
214
0
                if (sOldName != sFlyName)
215
0
                {
216
0
                    OUString sName(sOldName);
217
0
                    sal_uInt16 i = 1;
218
0
                    while (rSh.FindFlyByName(UIName(sName)))
219
0
                    {
220
0
                        sName = sOldName + "_" + OUString::number(i++);
221
0
                    }
222
0
                    rSh.SetFlyName(UIName(sName));
223
0
                }
224
0
                aURL.SetURL( rURL, false );
225
0
                aURL.SetTargetFrameName(rTarget);
226
227
0
                aSet.Put( aURL );
228
0
                rSh.SetFlyFrameAttr( aSet );
229
0
            }
230
0
        }
231
0
        break;
232
233
0
        case FN_FRAME_CHAIN:
234
0
            rSh.GetView().GetEditWin().SetChainMode( !rSh.GetView().GetEditWin().IsChainMode() );
235
0
            break;
236
237
0
        case FN_FRAME_UNCHAIN:
238
0
            rSh.Unchain( *rSh.GetFlyFrameFormat() );
239
0
            GetView().GetViewFrame().GetBindings().Invalidate(FN_FRAME_CHAIN);
240
0
            break;
241
0
        case FN_FORMAT_FOOTNOTE_DLG:
242
0
        {
243
0
            GetView().ExecFormatFootnote();
244
0
            break;
245
0
        }
246
0
        case FN_NUMBERING_OUTLINE_DLG:
247
0
        {
248
0
            GetView().ExecNumberingOutline(GetPool());
249
0
            rReq.Done();
250
0
            break;
251
0
        }
252
0
        case SID_OPEN_XML_FILTERSETTINGS:
253
0
        {
254
0
            HandleOpenXmlFilterSettings(rReq);
255
0
        }
256
0
        break;
257
0
        case FN_WORDCOUNT_DIALOG:
258
0
        {
259
0
            GetView().UpdateWordCount(this, nSlot);
260
0
            break;
261
0
        }
262
0
        case FN_UNFLOAT_FRAME:
263
0
        {
264
0
            rSh.UnfloatFlyFrame();
265
0
            rReq.Done();
266
0
            break;
267
0
        }
268
0
        default: bMore = true;
269
0
    }
270
271
0
    if ( !bMore )
272
0
    {
273
0
        return;
274
0
    }
275
276
0
    SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
277
0
    bool bUpdateMgr = true;
278
0
    bool bCopyToFormat = false;
279
0
    switch ( nSlot )
280
0
    {
281
0
        case SID_OBJECT_ALIGN_MIDDLE:
282
0
        case FN_FRAME_ALIGN_VERT_CENTER:
283
0
            aMgr.SetVertOrientation( text::VertOrientation::CENTER );
284
0
            break;
285
0
        case SID_OBJECT_ALIGN_DOWN :
286
0
        case FN_FRAME_ALIGN_VERT_BOTTOM:
287
0
            aMgr.SetVertOrientation( text::VertOrientation::BOTTOM );
288
0
            break;
289
0
        case SID_OBJECT_ALIGN_UP :
290
0
        case FN_FRAME_ALIGN_VERT_TOP:
291
0
            aMgr.SetVertOrientation( text::VertOrientation::TOP );
292
0
            break;
293
294
0
        case FN_FRAME_ALIGN_VERT_CHAR_CENTER:
295
0
            aMgr.SetVertOrientation( text::VertOrientation::CHAR_CENTER );
296
0
            break;
297
298
0
        case FN_FRAME_ALIGN_VERT_CHAR_BOTTOM:
299
0
            aMgr.SetVertOrientation( text::VertOrientation::CHAR_BOTTOM );
300
0
            break;
301
302
0
        case FN_FRAME_ALIGN_VERT_CHAR_TOP:
303
0
            aMgr.SetVertOrientation( text::VertOrientation::CHAR_TOP );
304
0
            break;
305
306
0
        case FN_FRAME_ALIGN_VERT_ROW_CENTER:
307
0
            aMgr.SetVertOrientation( text::VertOrientation::LINE_CENTER );
308
0
            break;
309
310
0
        case FN_FRAME_ALIGN_VERT_ROW_BOTTOM:
311
0
            aMgr.SetVertOrientation( text::VertOrientation::LINE_BOTTOM );
312
0
            break;
313
314
0
        case FN_FRAME_ALIGN_VERT_ROW_TOP:
315
0
            aMgr.SetVertOrientation( text::VertOrientation::LINE_TOP );
316
0
            break;
317
0
        case SID_OBJECT_ALIGN_CENTER :
318
0
        case FN_FRAME_ALIGN_HORZ_CENTER:
319
0
            aMgr.SetHorzOrientation( text::HoriOrientation::CENTER );
320
0
            break;
321
0
        case SID_OBJECT_ALIGN_RIGHT:
322
0
        case FN_FRAME_ALIGN_HORZ_RIGHT:
323
0
            aMgr.SetHorzOrientation( text::HoriOrientation::RIGHT );
324
0
            break;
325
0
        case SID_OBJECT_ALIGN_LEFT:
326
0
        case FN_FRAME_ALIGN_HORZ_LEFT:
327
0
            aMgr.SetHorzOrientation( text::HoriOrientation::LEFT );
328
0
            break;
329
330
0
        case FN_SET_FRM_POSITION:
331
0
        {
332
0
            aMgr.SetAbsPos(static_cast<const SfxPointItem &>(pArgs->Get
333
0
                                (FN_SET_FRM_POSITION)).GetValue());
334
0
        }
335
0
        break;
336
0
        case SID_ATTR_BRUSH:
337
0
        {
338
0
            if(pArgs)
339
0
            {
340
0
                aMgr.SetAttrSet( *pArgs );
341
0
                bCopyToFormat = true;
342
0
            }
343
0
        }
344
0
        break;
345
0
        case SID_ATTR_ULSPACE:
346
0
        case SID_ATTR_LRSPACE:
347
0
        {
348
0
            if(pArgs && SfxItemState::SET == pArgs->GetItemState(GetPool().GetWhichIDFromSlotID(nSlot), false, &pItem))
349
0
            {
350
0
                aMgr.SetAttrSet( *pArgs );
351
0
                bCopyToFormat = true;
352
0
            }
353
0
        }
354
0
        break;
355
356
0
        case SID_ATTR_TRANSFORM:
357
0
        {
358
0
            bool bApplyNewPos = false;
359
0
            bool bApplyNewSize = false;
360
361
0
            Point aNewPos = aMgr.GetPos();
362
0
            if (pArgs)
363
0
            {
364
0
                if (const SfxInt32Item* pXItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_POS_X, false))
365
0
                {
366
0
                    aNewPos.setX( pXItem->GetValue() );
367
0
                    bApplyNewPos = true;
368
0
                }
369
0
                if (const SfxInt32Item* pYItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_POS_Y, false))
370
0
                {
371
0
                    aNewPos.setY( pYItem->GetValue() );
372
0
                    bApplyNewPos = true;
373
0
                }
374
0
            }
375
376
0
            Size aNewSize = aMgr.GetSize();
377
0
            if (pArgs)
378
0
            {
379
0
                if (const SfxUInt32Item* pWidthItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_WIDTH, false))
380
0
                {
381
0
                    aNewSize.setWidth( pWidthItem->GetValue() );
382
0
                    bApplyNewSize = true;
383
0
                }
384
0
                if (const SfxUInt32Item* pHeightItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_HEIGHT, false))
385
0
                {
386
0
                    aNewSize.setHeight( pHeightItem->GetValue() );
387
0
                    bApplyNewSize = true;
388
0
                }
389
0
            }
390
391
0
            if (pArgs && (pArgs->HasItem(SID_ATTR_TRANSFORM_ANGLE) || pArgs->HasItem(SID_ATTR_TRANSFORM_DELTA_ANGLE)))
392
0
            {
393
0
                SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_GRFATR_ROTATION, RES_GRFATR_ROTATION>(rSh.GetAttrPool() ));
394
0
                rSh.GetCurAttr(aSet);
395
0
                const SwRotationGrf& rRotation = aSet.Get(RES_GRFATR_ROTATION);
396
0
                const Degree10 nOldRot(rRotation.GetValue());
397
398
0
                if (const SdrAngleItem* pAngleItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_DELTA_ANGLE, false))
399
0
                {
400
0
                    const Degree10 nDeltaRot = to<Degree10>(pAngleItem->GetValue());
401
0
                    aMgr.SetRotation(nOldRot, nOldRot + nDeltaRot, rRotation.GetUnrotatedSize());
402
0
                }
403
404
                // RotGrfFlyFrame: Get Value and disable is in SwGrfShell::GetAttrStateForRotation, but the
405
                // value setter uses SID_ATTR_TRANSFORM and a group of three values. Rotation is
406
                // added now, so use it in this central place. Do no forget to convert angle from
407
                // 100th degrees in SID_ATTR_TRANSFORM_ANGLE to 10th degrees in RES_GRFATR_ROTATION
408
0
                if (const SdrAngleItem* pTransformItem = pArgs->GetItemIfSet(SID_ATTR_TRANSFORM_ANGLE, false))
409
0
                {
410
0
                    const Degree10 nNewRot = to<Degree10>(pTransformItem->GetValue());
411
412
                    // RotGrfFlyFrame: Rotation change here, SwFlyFrameAttrMgr aMgr is available
413
0
                    aMgr.SetRotation(nOldRot, nNewRot, rRotation.GetUnrotatedSize());
414
0
                }
415
0
            }
416
417
0
            if (bApplyNewPos)
418
0
            {
419
0
                aMgr.SetAbsPos(aNewPos);
420
0
            }
421
0
            if ( bApplyNewSize )
422
0
            {
423
0
                aMgr.SetSize( aNewSize );
424
0
            }
425
0
            if (!bApplyNewPos && !bApplyNewSize)
426
0
            {
427
0
                bUpdateMgr = false;
428
0
            }
429
430
0
        }
431
0
        break;
432
433
0
        case FN_FORMAT_FRAME_DLG:
434
0
        case FN_DRAW_WRAP_DLG:
435
0
        {
436
0
            const SelectionType nSel = rSh.GetSelectionType();
437
0
            if (nSel & SelectionType::Graphic)
438
0
            {
439
0
                rSh.GetView().GetViewFrame().GetDispatcher()->Execute(FN_FORMAT_GRAFIC_DLG);
440
0
                bUpdateMgr = false;
441
0
            }
442
0
            else
443
0
            {
444
0
                SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<
445
0
                        RES_FRMATR_BEGIN, RES_FRMATR_END - 1,
446
                        // FillAttribute support:
447
0
                        XATTR_FILL_FIRST, XATTR_FILL_LAST,
448
0
                        SID_DOCFRAME, SID_DOCFRAME,
449
0
                        SID_ATTR_BRUSH, SID_ATTR_BRUSH,
450
0
                        SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
451
0
                        SID_ATTR_LRSPACE, SID_ATTR_ULSPACE,
452
0
                        SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
453
                        // Items to hand over XPropertyList things like
454
                        // XColorList, XHatchList, XGradientList, and
455
                        // XBitmapList to the Area TabPage
456
0
                        SID_COLOR_TABLE, SID_PATTERN_LIST,
457
0
                        SID_HTML_MODE, SID_HTML_MODE,
458
0
                        FN_GET_PRINT_AREA, FN_GET_PRINT_AREA,
459
0
                        FN_SURROUND, FN_KEEP_ASPECT_RATIO,
460
0
                        FN_SET_FRM_ALT_NAME, FN_SET_FRM_ALT_NAME,
461
0
                        FN_UNO_DESCRIPTION, FN_UNO_DESCRIPTION,
462
0
                        FN_OLE_IS_MATH, FN_MATH_BASELINE_ALIGNMENT,
463
0
                        FN_PARAM_CHAIN_PREVIOUS, FN_PARAM_CHAIN_NEXT>( GetPool() ));
464
465
                // create needed items for XPropertyList entries from the DrawModel so that
466
                // the Area TabPage can access them
467
0
                const SwDrawModel* pDrawModel = rSh.GetView().GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
468
0
                pDrawModel->PutAreaListItems(aSet);
469
470
0
                const SwViewOption* pVOpt = rSh.GetViewOptions();
471
0
                if(nSel & SelectionType::Ole)
472
0
                    aSet.Put( SfxBoolItem(FN_KEEP_ASPECT_RATIO, pVOpt->IsKeepRatio()) );
473
0
                aSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(GetView().GetDocShell())));
474
0
                aSet.Put(SfxStringItem(FN_SET_FRM_NAME, rSh.GetFlyName().toString()));
475
0
                aSet.Put(SfxStringItem(FN_UNO_DESCRIPTION, rSh.GetObjDescription()));
476
0
                if( nSel & SelectionType::Ole )
477
0
                {
478
                    // #i73249#
479
0
                    aSet.Put( SfxStringItem( FN_SET_FRM_ALT_NAME, rSh.GetObjTitle() ) );
480
0
                }
481
482
0
                const SwRect &rPg = rSh.GetAnyCurRect(CurRectType::Page);
483
0
                SwFormatFrameSize aFrameSize(SwFrameSize::Variable, rPg.Width(), rPg.Height());
484
0
                aFrameSize.SetWhich(GetPool().GetWhichIDFromSlotID(SID_ATTR_PAGE_SIZE));
485
0
                aSet.Put(aFrameSize);
486
487
0
                const SwRect &rPr = rSh.GetAnyCurRect(CurRectType::PagePrt);
488
0
                SwFormatFrameSize aPrtSize(SwFrameSize::Variable, rPr.Width(), rPr.Height());
489
0
                aPrtSize.SetWhich(GetPool().GetWhichIDFromSlotID(FN_GET_PRINT_AREA));
490
0
                aSet.Put(aPrtSize);
491
492
0
                aSet.Put(aMgr.GetAttrSet());
493
0
                aSet.SetParent( aMgr.GetAttrSet().GetParent() );
494
495
                // On % values initialize size
496
0
                SwFormatFrameSize aSize(aSet.Get(RES_FRM_SIZE));
497
0
                if (aSize.GetWidthPercent() && aSize.GetWidthPercent() != SwFormatFrameSize::SYNCED)
498
0
                    aSize.SetWidth(rSh.GetAnyCurRect(CurRectType::FlyEmbedded).Width());
499
0
                if (aSize.GetHeightPercent() && aSize.GetHeightPercent() != SwFormatFrameSize::SYNCED)
500
0
                    aSize.SetHeight(rSh.GetAnyCurRect(CurRectType::FlyEmbedded).Height());
501
0
                if (aSize != aSet.Get(RES_FRM_SIZE))
502
0
                {
503
0
                    aSet.Put(aSize);
504
0
                }
505
506
                // disable vertical positioning for Math Objects anchored 'as char' if baseline alignment is activated
507
0
                aSet.Put( SfxBoolItem( FN_MATH_BASELINE_ALIGNMENT,
508
0
                        rSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT ) ) );
509
0
                const uno::Reference < embed::XEmbeddedObject > xObj( rSh.GetOleRef() );
510
0
                aSet.Put( SfxBoolItem( FN_OLE_IS_MATH, xObj.is() && SotExchange::IsMath( xObj->getClassID() ) ) );
511
512
0
                OUString sDefPage;
513
0
                const SfxStringItem* pDlgItem;
514
0
                if(pArgs && (pDlgItem = pArgs->GetItemIfSet(FN_FORMAT_FRAME_DLG, false)))
515
0
                    sDefPage = pDlgItem->GetValue();
516
517
0
                aSet.Put(SfxFrameItem( SID_DOCFRAME, &GetView().GetViewFrame().GetFrame()));
518
0
                FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( &GetView()) != nullptr );
519
0
                SwModule* mod = SwModule::get();
520
0
                mod->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast<sal_uInt16>(eMetric)));
521
0
                SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
522
0
                ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateFrameTabDialog(
523
0
                                                        nSel & SelectionType::Graphic ? u"PictureDialog"_ustr :
524
0
                                                        nSel & SelectionType::Ole ? u"ObjectDialog"_ustr:
525
0
                                                                                        u"FrameDialog"_ustr,
526
0
                                                        GetView().GetViewFrame(),
527
0
                                                        GetView().GetFrameWeld(),
528
0
                                                        aSet,
529
0
                                                        false,
530
0
                                                        sDefPage));
531
532
0
                if ( nSlot == FN_DRAW_WRAP_DLG )
533
0
                {
534
0
                    pDlg->SetCurPageId(u"wrap"_ustr);
535
0
                }
536
537
0
                if ( pDlg->Execute() )
538
0
                {
539
0
                    const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
540
0
                    if(pOutSet)
541
0
                    {
542
0
                        rReq.Done(*pOutSet);
543
0
                        const SfxBoolItem* pRatioItem = nullptr;
544
0
                        if(nSel & SelectionType::Ole &&
545
0
                            (pRatioItem = pOutSet->GetItemIfSet(FN_KEEP_ASPECT_RATIO)))
546
0
                        {
547
0
                            SwViewOption aUsrPref( *pVOpt );
548
0
                            aUsrPref.SetKeepRatio(pRatioItem->GetValue());
549
0
                            mod->ApplyUsrPref(aUsrPref, &GetView());
550
0
                        }
551
0
                        if (const SfxStringItem* pAltNameItem = pOutSet->GetItemIfSet(FN_SET_FRM_ALT_NAME))
552
0
                        {
553
                            // #i73249#
554
0
                            rSh.SetObjTitle(pAltNameItem->GetValue());
555
0
                        }
556
0
                        if (const SfxStringItem* pDescripItem = pOutSet->GetItemIfSet(FN_UNO_DESCRIPTION))
557
0
                            rSh.SetObjDescription(pDescripItem->GetValue());
558
559
                        // Template AutoUpdate
560
0
                        SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
561
0
                        if(pFormat && pFormat->IsAutoUpdateOnDirectFormat())
562
0
                        {
563
0
                            rSh.AutoUpdateFrame(pFormat, *pOutSet);
564
                            // Anything which is not supported by the format must be set hard.
565
0
                            if(const SfxStringItem* pFrameName = pOutSet->GetItemIfSet(FN_SET_FRM_NAME, false))
566
0
                                rSh.SetFlyName(UIName(pFrameName->GetValue()));
567
0
                            SfxItemSet aShellSet(SfxItemSet::makeFixedSfxItemSet<
568
0
                                    RES_FRM_SIZE, RES_FRM_SIZE,
569
0
                                    RES_SURROUND, RES_ANCHOR>( GetPool() ));
570
0
                            aShellSet.Put(*pOutSet);
571
0
                            aMgr.SetAttrSet(aShellSet);
572
0
                            if(const SfxStringItem* pFrameName = pOutSet->GetItemIfSet(FN_SET_FRM_NAME, false))
573
0
                                rSh.SetFlyName(UIName(pFrameName->GetValue()));
574
0
                        }
575
0
                        else
576
0
                            aMgr.SetAttrSet( *pOutSet );
577
578
0
                        const SwFrameFormat* pCurrFlyFormat = rSh.GetFlyFrameFormat();
579
0
                        if(const SfxStringItem* pPreviousItem =
580
0
                           pOutSet->GetItemIfSet(FN_PARAM_CHAIN_PREVIOUS, false))
581
0
                        {
582
0
                            rSh.HideChainMarker();
583
584
0
                            OUString sPrevName = pPreviousItem->GetValue();
585
0
                            const SwFormatChain &rChain = pCurrFlyFormat->GetChain();
586
                            //needs cast - no non-const method available
587
0
                            SwFlyFrameFormat* pFlyFormat =
588
0
                                rChain.GetPrev();
589
0
                            if(pFlyFormat)
590
0
                            {
591
0
                                if (pFlyFormat->GetName() != sPrevName)
592
0
                                {
593
0
                                    rSh.Unchain(*pFlyFormat);
594
0
                                }
595
0
                                else
596
0
                                    sPrevName.clear();
597
0
                            }
598
599
0
                            if (!sPrevName.isEmpty())
600
0
                            {
601
                                //needs cast - no non-const method available
602
0
                                SwFrameFormat* pPrevFormat = rSh.GetDoc()->GetFlyFrameFormatByName(UIName(sPrevName));
603
0
                                SAL_WARN_IF(!pPrevFormat, "sw.ui", "No frame found!");
604
0
                                if(pPrevFormat)
605
0
                                {
606
0
                                    rSh.Chain(*pPrevFormat, *pCurrFlyFormat);
607
0
                                }
608
0
                            }
609
0
                            rSh.SetChainMarker();
610
0
                        }
611
0
                        if(const SfxStringItem* pChainNextItem =
612
0
                           pOutSet->GetItemIfSet(FN_PARAM_CHAIN_NEXT, false))
613
0
                        {
614
0
                            rSh.HideChainMarker();
615
0
                            OUString sNextName = pChainNextItem->GetValue();
616
0
                            const SwFormatChain &rChain = pCurrFlyFormat->GetChain();
617
                            //needs cast - no non-const method available
618
0
                            SwFlyFrameFormat* pFlyFormat =
619
0
                                rChain.GetNext();
620
0
                            if(pFlyFormat)
621
0
                            {
622
0
                                if (pFlyFormat->GetName() != sNextName)
623
0
                                {
624
0
                                    rSh.Unchain(*const_cast<SwFlyFrameFormat*>(static_cast<const SwFlyFrameFormat*>( pCurrFlyFormat)));
625
0
                                }
626
0
                                else
627
0
                                    sNextName.clear();
628
0
                            }
629
630
0
                            if (!sNextName.isEmpty())
631
0
                            {
632
                                //needs cast - no non-const method available
633
0
                                SwFrameFormat* pNextFormat = rSh.GetDoc()->GetFlyFrameFormatByName(UIName(sNextName));
634
0
                                SAL_WARN_IF(!pNextFormat, "sw.ui", "No frame found!");
635
0
                                if(pNextFormat)
636
0
                                {
637
0
                                    rSh.Chain(*const_cast<SwFrameFormat*>(
638
0
                                              pCurrFlyFormat), *pNextFormat);
639
0
                                }
640
0
                            }
641
0
                            rSh.SetChainMarker();
642
0
                        }
643
0
                    }
644
0
                }
645
0
                else
646
0
                    bUpdateMgr = false;
647
0
            }
648
0
        }
649
0
        break;
650
0
        case FN_FRAME_MIRROR_ON_EVEN_PAGES:
651
0
        {
652
0
            SwFormatHoriOrient aHori(aMgr.GetHoriOrient());
653
0
            bool bMirror = !aHori.IsPosToggle();
654
0
            aHori.SetPosToggle(bMirror);
655
0
            SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_HORI_ORIENT, RES_HORI_ORIENT>(GetPool()));
656
0
            aSet.Put(aHori);
657
0
            aMgr.SetAttrSet(aSet);
658
0
            bCopyToFormat = true;
659
0
            rReq.SetReturnValue(SfxBoolItem(nSlot, bMirror));
660
0
        }
661
0
        break;
662
0
        case FN_NAME_SHAPE:
663
0
        {
664
0
            bUpdateMgr = false;
665
0
            SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
666
0
            if ( pSdrView &&
667
0
                 pSdrView->GetMarkedObjectList().GetMarkCount() == 1 )
668
0
            {
669
0
                UIName aName(rSh.GetFlyName());
670
0
                SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
671
0
                VclPtr<AbstractSvxObjectNameDialog> pDlg(
672
0
                    pFact->CreateSvxObjectNameDialog(GetView().GetFrameWeld(), aName.toString()));
673
674
0
                pDlg->StartExecuteAsync(
675
0
                    [this, pDlg] (sal_Int32 nResult)->void
676
0
                    {
677
0
                        if (nResult == RET_OK)
678
0
                            GetShell().SetFlyName(UIName(pDlg->GetName()));
679
0
                        pDlg->disposeOnce();
680
0
                    }
681
0
                );
682
0
            }
683
0
        }
684
0
        break;
685
        // #i73249#
686
0
        case FN_TITLE_DESCRIPTION_SHAPE:
687
0
        {
688
0
            bUpdateMgr = false;
689
0
            SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
690
0
            if ( pSdrView &&
691
0
                 pSdrView->GetMarkedObjectList().GetMarkCount() == 1 )
692
0
            {
693
0
                OUString aDescription(rSh.GetObjDescription());
694
0
                OUString aTitle(rSh.GetObjTitle());
695
0
                bool isDecorative(rSh.IsObjDecorative());
696
697
0
                SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
698
0
                VclPtr<AbstractSvxObjectTitleDescDialog> pDlg(
699
0
                    pFact->CreateSvxObjectTitleDescDialog(GetView().GetFrameWeld(),
700
0
                        aTitle, aDescription, isDecorative));
701
702
0
                pDlg->StartExecuteAsync(
703
0
                    [this, pDlg] (sal_Int32 nResult)->void
704
0
                    {
705
0
                        if (nResult == RET_OK)
706
0
                        {
707
0
                            GetShell().SetObjDescription(pDlg->GetDescription());
708
0
                            GetShell().SetObjTitle(pDlg->GetTitle());
709
0
                            GetShell().SetObjDecorative(pDlg->IsDecorative());
710
0
                        }
711
0
                        pDlg->disposeOnce();
712
0
                    }
713
0
                );
714
0
            }
715
0
        }
716
0
        break;
717
0
        default:
718
0
            assert(!"wrong dispatcher");
719
0
            return;
720
0
    }
721
0
    if ( bUpdateMgr )
722
0
    {
723
0
        SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
724
0
        if ( bCopyToFormat && pFormat && pFormat->IsAutoUpdateOnDirectFormat() )
725
0
        {
726
0
            rSh.AutoUpdateFrame(pFormat, aMgr.GetAttrSet());
727
0
        }
728
0
        else
729
0
        {
730
0
            aMgr.UpdateFlyFrame();
731
0
        }
732
0
    }
733
734
0
}
735
736
void SwFrameShell::GetState(SfxItemSet& rSet)
737
0
{
738
0
    SwWrtShell &rSh = GetShell();
739
0
    bool bHtmlMode = 0 != ::GetHtmlMode(rSh.GetView().GetDocShell());
740
0
    if (!rSh.IsFrameSelected())
741
0
        return;
742
743
0
    SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<
744
0
            RES_LR_SPACE, RES_UL_SPACE,
745
0
            RES_PRINT, RES_HORI_ORIENT>(rSh.GetAttrPool() ));
746
0
    rSh.GetFlyFrameAttr( aSet );
747
748
0
    bool bProtect = rSh.IsSelObjProtected(FlyProtectFlags::Pos) != FlyProtectFlags::NONE;
749
0
    bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
750
751
0
    bProtect |= bParentCntProt;
752
753
0
    const FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
754
0
    SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
755
756
0
    SfxWhichIter aIter( rSet );
757
0
    sal_uInt16 nWhich = aIter.FirstWhich();
758
0
    while ( nWhich )
759
0
    {
760
0
        switch ( nWhich )
761
0
        {
762
0
            case RES_FRM_SIZE:
763
0
            {
764
0
                const SwFormatFrameSize& aSz(aMgr.GetFrameSize());
765
0
                rSet.Put(aSz);
766
0
            }
767
0
            break;
768
0
            case RES_VERT_ORIENT:
769
0
            case RES_HORI_ORIENT:
770
0
            case SID_ATTR_ULSPACE:
771
0
            case SID_ATTR_LRSPACE:
772
0
            case RES_LR_SPACE:
773
0
            case RES_UL_SPACE:
774
0
            case RES_PROTECT:
775
0
            case RES_OPAQUE:
776
0
            case RES_PRINT:
777
0
            case RES_SURROUND:
778
0
            {
779
0
                rSet.Put(aSet.Get(GetPool().GetWhichIDFromSlotID(nWhich)));
780
0
            }
781
0
            break;
782
0
            case SID_OBJECT_ALIGN:
783
0
            {
784
0
                if ( bProtect )
785
0
                    rSet.DisableItem( nWhich );
786
0
            }
787
0
            break;
788
0
            case SID_OBJECT_ALIGN_LEFT   :
789
0
            case SID_OBJECT_ALIGN_CENTER :
790
0
            case SID_OBJECT_ALIGN_RIGHT  :
791
0
            case FN_FRAME_ALIGN_HORZ_CENTER:
792
0
            case FN_FRAME_ALIGN_HORZ_RIGHT:
793
0
            case FN_FRAME_ALIGN_HORZ_LEFT:
794
0
                if ( (eFrameType & FrameTypeFlags::FLY_INCNT) ||
795
0
                     bProtect ||
796
0
                     ((nWhich == FN_FRAME_ALIGN_HORZ_CENTER  || nWhich == SID_OBJECT_ALIGN_CENTER) &&
797
0
                      bHtmlMode ))
798
0
                {
799
0
                    rSet.DisableItem( nWhich );
800
0
                }
801
0
                else
802
0
                {
803
0
                    sal_Int16 nHoriOrient = -1;
804
0
                    switch(nWhich)
805
0
                    {
806
0
                        case SID_OBJECT_ALIGN_LEFT:
807
0
                            nHoriOrient = text::HoriOrientation::LEFT;
808
0
                            break;
809
0
                        case SID_OBJECT_ALIGN_CENTER:
810
0
                            nHoriOrient = text::HoriOrientation::CENTER;
811
0
                            break;
812
0
                        case SID_OBJECT_ALIGN_RIGHT:
813
0
                            nHoriOrient = text::HoriOrientation::RIGHT;
814
0
                            break;
815
0
                        default:
816
0
                            break;
817
0
                    }
818
0
                    const SwFormatHoriOrient& aHOrient(aMgr.GetHoriOrient());
819
0
                    if (nHoriOrient != -1)
820
0
                        rSet.Put(SfxBoolItem(nWhich, nHoriOrient == aHOrient.GetHoriOrient()));
821
0
                }
822
0
            break;
823
0
            case FN_FRAME_ALIGN_VERT_ROW_TOP:
824
0
            case FN_FRAME_ALIGN_VERT_ROW_CENTER:
825
0
            case FN_FRAME_ALIGN_VERT_ROW_BOTTOM:
826
0
            case FN_FRAME_ALIGN_VERT_CHAR_TOP:
827
0
            case FN_FRAME_ALIGN_VERT_CHAR_CENTER:
828
0
            case FN_FRAME_ALIGN_VERT_CHAR_BOTTOM:
829
0
                if ( !(eFrameType & FrameTypeFlags::FLY_INCNT) || bProtect
830
0
                     || (bHtmlMode && FN_FRAME_ALIGN_VERT_CHAR_BOTTOM == nWhich) )
831
0
                    rSet.DisableItem( nWhich );
832
0
            break;
833
834
0
            case SID_OBJECT_ALIGN_UP     :
835
0
            case SID_OBJECT_ALIGN_MIDDLE :
836
0
            case SID_OBJECT_ALIGN_DOWN :
837
838
0
            case FN_FRAME_ALIGN_VERT_TOP:
839
0
            case FN_FRAME_ALIGN_VERT_CENTER:
840
0
            case FN_FRAME_ALIGN_VERT_BOTTOM:
841
0
                if ( bProtect || (bHtmlMode && eFrameType & FrameTypeFlags::FLY_ATCNT))
842
0
                    rSet.DisableItem( nWhich );
843
0
                else
844
0
                {
845
                    // These slots need different labels depending on whether they are anchored in a character
846
                    // or on a paragraph/page etc.
847
0
                    OUString sNewLabel;
848
0
                    if (eFrameType & FrameTypeFlags::FLY_INCNT)
849
0
                    {
850
0
                        switch (nWhich)
851
0
                        {
852
0
                            case SID_OBJECT_ALIGN_UP     :
853
0
                            case FN_FRAME_ALIGN_VERT_TOP:
854
0
                                sNewLabel = SwResId(STR_FRMUI_TOP_BASE);
855
0
                                break;
856
0
                            case SID_OBJECT_ALIGN_MIDDLE :
857
0
                            case FN_FRAME_ALIGN_VERT_CENTER:
858
0
                                sNewLabel = SwResId(STR_FRMUI_CENTER_BASE);
859
0
                                break;
860
0
                            case SID_OBJECT_ALIGN_DOWN :
861
0
                            case FN_FRAME_ALIGN_VERT_BOTTOM:
862
0
                                if(!bHtmlMode)
863
0
                                    sNewLabel = SwResId(STR_FRMUI_BOTTOM_BASE);
864
0
                                else
865
0
                                    rSet.DisableItem( nWhich );
866
0
                            break;
867
0
                        }
868
0
                    }
869
0
                    else
870
0
                    {
871
0
                        if (nWhich != FN_FRAME_ALIGN_VERT_TOP &&
872
0
                                nWhich != SID_OBJECT_ALIGN_UP )
873
0
                        {
874
0
                            if (aMgr.GetAnchor() == RndStdIds::FLY_AT_FLY)
875
0
                            {
876
0
                                const SwFrameFormat* pFormat = rSh.IsFlyInFly();
877
0
                                if (pFormat)
878
0
                                {
879
0
                                    const SwFormatFrameSize& rFrameSz = pFormat->GetFrameSize();
880
0
                                    if (rFrameSz.GetHeightSizeType() != SwFrameSize::Fixed)
881
0
                                    {
882
0
                                        rSet.DisableItem( nWhich );
883
0
                                        break;
884
0
                                    }
885
0
                                }
886
0
                            }
887
0
                        }
888
0
                        OUString aModuleName;
889
0
                        if (SfxViewFrame* pFrame = GetFrame())
890
0
                            aModuleName = vcl::CommandInfoProvider::GetModuleIdentifier(pFrame->GetFrame().GetFrameInterface());
891
0
                        switch (nWhich)
892
0
                        {
893
0
                            case SID_OBJECT_ALIGN_UP :
894
0
                            case FN_FRAME_ALIGN_VERT_TOP:
895
0
                            {
896
0
                                auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(u".uno:AlignTop"_ustr, aModuleName);
897
0
                                sNewLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
898
0
                                break;
899
0
                            }
900
0
                            case SID_OBJECT_ALIGN_MIDDLE:
901
0
                            case FN_FRAME_ALIGN_VERT_CENTER:
902
0
                            {
903
0
                                auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(u".uno:AlignVerticalCenter"_ustr, aModuleName);
904
0
                                sNewLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
905
0
                                break;
906
0
                            }
907
0
                            case SID_OBJECT_ALIGN_DOWN:
908
0
                            case FN_FRAME_ALIGN_VERT_BOTTOM:
909
0
                            {
910
0
                                auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(u".uno:AlignBottom"_ustr, aModuleName);
911
0
                                sNewLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
912
0
                                break;
913
0
                            }
914
0
                        }
915
0
                    }
916
0
                    if ( !sNewLabel.isEmpty() )
917
0
                        rSet.Put( SfxStringItem( nWhich, sNewLabel ));
918
0
                }
919
0
            break;
920
0
            case SID_HYPERLINK_GETLINK:
921
0
            {
922
0
                SvxHyperlinkItem aHLinkItem;
923
924
0
                aHLinkItem.SetShowName(false);
925
0
                aHLinkItem.SetShowText(false);
926
927
0
                SfxItemSet aURLSet(SfxItemSet::makeFixedSfxItemSet<RES_URL, RES_URL>(GetPool()));
928
0
                rSh.GetFlyFrameAttr( aURLSet );
929
930
0
                if(const SwFormatURL* pFormatURL = aURLSet.GetItemIfSet(RES_URL))
931
0
                {
932
0
                    aHLinkItem.SetURL(pFormatURL->GetURL());
933
0
                    aHLinkItem.SetTargetFrame(pFormatURL->GetTargetFrameName());
934
0
                    aHLinkItem.SetName(rSh.GetFlyName().toString());
935
0
                }
936
937
0
                aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() |
938
0
                    (bHtmlMode ? HLINK_HTMLMODE : 0)));
939
940
0
                rSet.Put(aHLinkItem);
941
0
            }
942
0
            break;
943
944
0
            case FN_FRAME_CHAIN:
945
0
            {
946
0
                const SelectionType nSel = rSh.GetSelectionType();
947
0
                if (nSel & SelectionType::Graphic || nSel & SelectionType::Ole)
948
0
                    rSet.DisableItem( FN_FRAME_CHAIN );
949
0
                else
950
0
                {
951
0
                    const SwFrameFormat *pFormat = rSh.GetFlyFrameFormat();
952
0
                    if ( bParentCntProt || rSh.GetView().GetEditWin().GetApplyTemplate() ||
953
0
                         !pFormat || pFormat->GetChain().GetNext() )
954
0
                    {
955
0
                        rSet.DisableItem( FN_FRAME_CHAIN );
956
0
                    }
957
0
                    else
958
0
                    {
959
0
                        bool bChainMode = rSh.GetView().GetEditWin().IsChainMode();
960
0
                        rSet.Put( SfxBoolItem( FN_FRAME_CHAIN, bChainMode ) );
961
0
                    }
962
0
                }
963
0
            }
964
0
            break;
965
0
            case FN_FRAME_UNCHAIN:
966
0
            {
967
0
                const SelectionType nSel = rSh.GetSelectionType();
968
0
                if (nSel & SelectionType::Graphic || nSel & SelectionType::Ole)
969
0
                    rSet.DisableItem( FN_FRAME_UNCHAIN );
970
0
                else
971
0
                {
972
0
                    const SwFrameFormat *pFormat = rSh.GetFlyFrameFormat();
973
0
                    if ( bParentCntProt || rSh.GetView().GetEditWin().GetApplyTemplate() ||
974
0
                         !pFormat || !pFormat->GetChain().GetNext() )
975
0
                    {
976
0
                        rSet.DisableItem( FN_FRAME_UNCHAIN );
977
0
                    }
978
0
                }
979
0
            }
980
0
            break;
981
0
            case SID_FRAME_TO_TOP:
982
0
            case SID_FRAME_TO_BOTTOM:
983
0
            case FN_FRAME_UP:
984
0
            case FN_FRAME_DOWN:
985
0
                if ( bParentCntProt )
986
0
                    rSet.DisableItem( nWhich );
987
0
            break;
988
989
0
            case SID_ATTR_TRANSFORM:
990
0
            {
991
0
                rSet.DisableItem( nWhich );
992
0
            }
993
0
            break;
994
995
0
            case SID_ATTR_TRANSFORM_PROTECT_SIZE:
996
0
            {
997
0
                const FlyProtectFlags eProtection = rSh.IsSelObjProtected( FlyProtectFlags::Size );
998
0
                if ( ( eProtection & FlyProtectFlags::Content ) ||
999
0
                     ( eProtection & FlyProtectFlags::Size ) )
1000
0
                {
1001
0
                    rSet.Put( SfxBoolItem( SID_ATTR_TRANSFORM_PROTECT_SIZE, true ) );
1002
0
                }
1003
0
                else
1004
0
                {
1005
0
                    rSet.Put( SfxBoolItem( SID_ATTR_TRANSFORM_PROTECT_SIZE, false ) );
1006
0
                }
1007
0
            }
1008
0
            break;
1009
1010
0
            case SID_ATTR_TRANSFORM_WIDTH:
1011
0
            {
1012
0
                rSet.Put( SfxUInt32Item( SID_ATTR_TRANSFORM_WIDTH, aMgr.GetSize().getWidth() ) );
1013
0
            }
1014
0
            break;
1015
1016
0
            case SID_ATTR_TRANSFORM_HEIGHT:
1017
0
            {
1018
0
                rSet.Put( SfxUInt32Item( SID_ATTR_TRANSFORM_HEIGHT, aMgr.GetSize().getHeight() ) );
1019
0
            }
1020
0
            break;
1021
1022
0
            case FN_FORMAT_FRAME_DLG:
1023
0
            {
1024
0
                const SelectionType nSel = rSh.GetSelectionType();
1025
0
                if ( bParentCntProt || nSel & SelectionType::Graphic)
1026
0
                    rSet.DisableItem( nWhich );
1027
0
            }
1028
0
            break;
1029
            // #i73249#
1030
0
            case FN_TITLE_DESCRIPTION_SHAPE:
1031
0
            case FN_NAME_SHAPE:
1032
0
            {
1033
0
                SwWrtShell &rWrtSh = GetShell();
1034
0
                SdrView* pSdrView = rWrtSh.GetDrawViewWithValidMarkList();
1035
0
                if ( !pSdrView ||
1036
0
                     pSdrView->GetMarkedObjectList().GetMarkCount() != 1 )
1037
0
                {
1038
0
                    rSet.DisableItem( nWhich );
1039
0
                }
1040
0
            }
1041
0
            break;
1042
1043
0
            case FN_POSTIT:
1044
0
            {
1045
0
                SwFlyFrame* pFly = rSh.GetSelectedFlyFrame();
1046
0
                if (pFly)
1047
0
                {
1048
0
                    SwFrameFormat* pFormat = pFly->GetFormat();
1049
0
                    if (pFormat)
1050
0
                    {
1051
0
                        RndStdIds eAnchorId = pFormat->GetAnchor().GetAnchorId();
1052
                        // SwWrtShell::InsertPostIt() only works on as-char and at-char anchored
1053
                        // images.
1054
0
                        if (eAnchorId != RndStdIds::FLY_AS_CHAR && eAnchorId != RndStdIds::FLY_AT_CHAR)
1055
0
                        {
1056
0
                            rSet.DisableItem(nWhich);
1057
0
                        }
1058
0
                    }
1059
0
                }
1060
0
            }
1061
0
            break;
1062
1063
0
            default:
1064
0
                /* do nothing */;
1065
0
                break;
1066
0
        }
1067
0
        nWhich = aIter.NextWhich();
1068
0
    }
1069
0
}
1070
1071
SwFrameShell::SwFrameShell(SwView &_rView) :
1072
0
    SwBaseShell( _rView )
1073
0
{
1074
0
    SetName(u"Frame"_ustr);
1075
1076
    // #96392# Use this to announce it is the frame shell who creates the selection.
1077
0
    SwTransferable::CreateSelection( _rView.GetWrtShell(), this );
1078
1079
0
    SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Frame));
1080
0
}
1081
1082
SwFrameShell::~SwFrameShell()
1083
0
{
1084
    // #96392# Only clear the selection if it was this frame shell who created it.
1085
0
    SwTransferable::ClearSelection( GetShell(), this );
1086
0
}
1087
1088
void SwFrameShell::ExecFrameStyle(SfxRequest const & rReq)
1089
0
{
1090
0
    SwWrtShell &rSh = GetShell();
1091
0
    bool bDefault = false;
1092
0
    if (!rSh.IsFrameSelected())
1093
0
        return;
1094
    // At first pick the default BoxItem out of the pool.
1095
    // If unequal to regular box item, then it has already
1096
    // been changed (New one is no default).
1097
0
    const SvxBoxItem* pPoolBoxItem = ::GetDfltAttr(RES_BOX);
1098
1099
0
    const SfxItemSet *pArgs = rReq.GetArgs();
1100
0
    SfxItemSet aFrameSet(SfxItemSet::makeFixedSfxItemSet<RES_BOX, RES_BOX>(rSh.GetAttrPool()));
1101
1102
0
    rSh.GetFlyFrameAttr( aFrameSet );
1103
0
    const SvxBoxItem& rBoxItem = aFrameSet.Get(RES_BOX);
1104
1105
0
    if (SfxPoolItem::areSame(pPoolBoxItem, &rBoxItem))
1106
0
        bDefault = true;
1107
1108
0
    std::unique_ptr<SvxBoxItem> aBoxItem(rBoxItem.Clone());
1109
1110
0
    SvxBorderLine aBorderLine;
1111
1112
0
    if(pArgs)    // Any controller can sometimes deliver nothing #48169#
1113
0
    {
1114
0
        switch (rReq.GetSlot())
1115
0
        {
1116
0
            case SID_ATTR_BORDER:
1117
0
            {
1118
0
                if (const SvxBoxItem* pBoxItem = pArgs->GetItemIfSet(RES_BOX))
1119
0
                {
1120
0
                    std::unique_ptr<SvxBoxItem> aNewBox(pBoxItem->Clone());
1121
0
                    const SvxBorderLine* pBorderLine;
1122
1123
0
                    pBorderLine = aBoxItem->GetTop();
1124
0
                    if (pBorderLine != nullptr)
1125
0
                        lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine);
1126
0
                    pBorderLine = aBoxItem->GetBottom();
1127
0
                    if (pBorderLine != nullptr)
1128
0
                        lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine);
1129
0
                    pBorderLine = aBoxItem->GetLeft();
1130
0
                    if (pBorderLine != nullptr)
1131
0
                        lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine);
1132
0
                    pBorderLine = aBoxItem->GetRight();
1133
0
                    if (pBorderLine != nullptr)
1134
0
                        lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine);
1135
1136
0
                    if(aBorderLine.GetOutWidth() == 0)
1137
0
                    {
1138
0
                        aBorderLine.SetBorderLineStyle(
1139
0
                                SvxBorderLineStyle::SOLID);
1140
0
                        aBorderLine.SetWidth( SvxBorderLineWidth::Hairline );
1141
0
                    }
1142
                    //Set distance only if the request is received from the controller.
1143
1144
#if HAVE_FEATURE_SCRIPTING
1145
                    if(!StarBASIC::IsRunning())
1146
#endif
1147
0
                    {
1148
                        // TODO: should this copy 4 individual Dist instead?
1149
0
                        aNewBox->SetAllDistances(rBoxItem.GetSmallestDistance());
1150
0
                    }
1151
1152
0
                    aBoxItem = std::move(aNewBox);
1153
1154
0
                    if( aBoxItem->GetTop() != nullptr )
1155
0
                        aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP);
1156
0
                    if( aBoxItem->GetBottom() != nullptr )
1157
0
                        aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM);
1158
0
                    if( aBoxItem->GetLeft() != nullptr )
1159
0
                        aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT);
1160
0
                    if( aBoxItem->GetRight() != nullptr )
1161
0
                        aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT);
1162
0
                }
1163
0
            }
1164
0
            break;
1165
1166
0
            case SID_FRAME_LINESTYLE:
1167
0
            {
1168
0
                if ( const SvxLineItem* pLineItem = pArgs->GetItemIfSet(SID_FRAME_LINESTYLE, false))
1169
0
                {
1170
0
                    if ( pLineItem->GetLine() )
1171
0
                    {
1172
0
                        aBorderLine = *(pLineItem->GetLine());
1173
1174
0
                        if (!aBoxItem->GetTop() && !aBoxItem->GetBottom() &&
1175
0
                            !aBoxItem->GetLeft() && !aBoxItem->GetRight())
1176
0
                        {
1177
0
                            aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP);
1178
0
                            aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM);
1179
0
                            aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT);
1180
0
                            aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT);
1181
0
                        }
1182
0
                        else
1183
0
                        {
1184
0
                            if( aBoxItem->GetTop() )
1185
0
                            {
1186
0
                                aBorderLine.SetColor( aBoxItem->GetTop()->GetColor() );
1187
0
                                aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP);
1188
0
                            }
1189
0
                            if( aBoxItem->GetBottom() )
1190
0
                            {
1191
0
                                aBorderLine.SetColor( aBoxItem->GetBottom()->GetColor());
1192
0
                                aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM);
1193
0
                            }
1194
0
                            if( aBoxItem->GetLeft() )
1195
0
                            {
1196
0
                                aBorderLine.SetColor( aBoxItem->GetLeft()->GetColor());
1197
0
                                aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT);
1198
0
                            }
1199
0
                            if( aBoxItem->GetRight() )
1200
0
                            {
1201
0
                                aBorderLine.SetColor(aBoxItem->GetRight()->GetColor());
1202
0
                                aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT);
1203
0
                            }
1204
0
                        }
1205
0
                    }
1206
0
                    else
1207
0
                    {
1208
0
                        aBoxItem->SetLine(nullptr, SvxBoxItemLine::TOP);
1209
0
                        aBoxItem->SetLine(nullptr, SvxBoxItemLine::BOTTOM);
1210
0
                        aBoxItem->SetLine(nullptr, SvxBoxItemLine::LEFT);
1211
0
                        aBoxItem->SetLine(nullptr, SvxBoxItemLine::RIGHT);
1212
0
                    }
1213
0
                }
1214
0
            }
1215
0
            break;
1216
1217
0
            case SID_FRAME_LINECOLOR:
1218
0
            {
1219
0
                if (const SvxColorItem* pColorItem = pArgs->GetItemIfSet(SID_FRAME_LINECOLOR, false))
1220
0
                {
1221
0
                    const Color& rNewColor = pColorItem->GetValue();
1222
1223
0
                    if (!aBoxItem->GetTop() && !aBoxItem->GetBottom() &&
1224
0
                        !aBoxItem->GetLeft() && !aBoxItem->GetRight())
1225
0
                    {
1226
0
                        aBorderLine.SetColor( rNewColor );
1227
0
                        aBorderLine.SetBorderLineStyle(SvxBorderLineStyle::SOLID);
1228
0
                        aBorderLine.SetWidth(SvxBorderLineWidth::Hairline);
1229
1230
0
                        aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP);
1231
0
                        aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM);
1232
0
                        aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT);
1233
0
                        aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT);
1234
0
                    }
1235
0
                    else
1236
0
                    {
1237
0
                        if (aBoxItem->GetTop())
1238
0
                            aBoxItem->GetTop()->SetColor(rNewColor);
1239
0
                        if (aBoxItem->GetBottom())
1240
0
                            aBoxItem->GetBottom()->SetColor(rNewColor);
1241
0
                        if (aBoxItem->GetLeft())
1242
0
                            aBoxItem->GetLeft()->SetColor(rNewColor);
1243
0
                        if (aBoxItem->GetRight())
1244
0
                            aBoxItem->GetRight()->SetColor(rNewColor);
1245
0
                    }
1246
0
                }
1247
0
            }
1248
0
            break;
1249
0
        }
1250
0
    }
1251
0
    if (bDefault && (aBoxItem->GetTop() || aBoxItem->GetBottom() ||
1252
0
        aBoxItem->GetLeft() || aBoxItem->GetRight()))
1253
0
    {
1254
0
        aBoxItem->SetAllDistances(MIN_BORDER_DIST);
1255
0
    }
1256
0
    aFrameSet.Put( std::move(aBoxItem) );
1257
    // Template AutoUpdate
1258
0
    SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
1259
0
    if(pFormat && pFormat->IsAutoUpdateOnDirectFormat())
1260
0
    {
1261
0
        rSh.AutoUpdateFrame(pFormat, aFrameSet);
1262
0
    }
1263
0
    else
1264
0
        rSh.SetFlyFrameAttr( aFrameSet );
1265
1266
0
}
1267
1268
static void lcl_FrameGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine)
1269
0
{
1270
0
    if(pBorderLine->GetWidth() > rBorderLine.GetWidth())
1271
0
        rBorderLine.SetWidth(pBorderLine->GetWidth());
1272
1273
0
    rBorderLine.SetBorderLineStyle(pBorderLine->GetBorderLineStyle());
1274
0
    rBorderLine.SetColor(pBorderLine->GetColor());
1275
0
}
1276
1277
void SwFrameShell::GetLineStyleState(SfxItemSet &rSet)
1278
0
{
1279
0
    SwWrtShell &rSh = GetShell();
1280
0
    bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
1281
1282
0
    if (bParentCntProt)
1283
0
    {
1284
0
        if (rSh.IsFrameSelected())
1285
0
            rSet.DisableItem( SID_FRAME_LINECOLOR );
1286
1287
0
        rSet.DisableItem( SID_ATTR_BORDER );
1288
0
        rSet.DisableItem( SID_FRAME_LINESTYLE );
1289
0
    }
1290
0
    else
1291
0
    {
1292
0
        if (rSh.IsFrameSelected())
1293
0
        {
1294
0
            SfxItemSet aFrameSet(SfxItemSet::makeFixedSfxItemSet<RES_BOX, RES_BOX>( rSh.GetAttrPool() ));
1295
1296
0
            rSh.GetFlyFrameAttr(aFrameSet);
1297
1298
0
            const SvxBorderLine* pLine = aFrameSet.Get(RES_BOX).GetTop();
1299
0
            rSet.Put(SvxColorItem(pLine ? pLine->GetColor() : Color(), SID_FRAME_LINECOLOR));
1300
0
        }
1301
0
    }
1302
0
}
1303
1304
void  SwFrameShell::StateInsert(SfxItemSet &rSet)
1305
0
{
1306
0
    const SelectionType nSel = GetShell().GetSelectionType();
1307
0
    if ( (nSel & SelectionType::Graphic)
1308
0
        || (nSel & SelectionType::Ole) )
1309
0
    {
1310
0
        rSet.DisableItem(FN_INSERT_FRAME);
1311
0
    }
1312
0
    else if ( GetShell().CursorInsideInputField() )
1313
0
    {
1314
0
        rSet.DisableItem(FN_INSERT_FRAME);
1315
0
    }
1316
0
}
1317
1318
void SwFrameShell::GetDrawAttrStateTextFrame(SfxItemSet &rSet)
1319
0
{
1320
0
    SwWrtShell &rSh = GetShell();
1321
1322
0
    if(rSh.IsFrameSelected())
1323
0
    {
1324
0
        rSh.GetFlyFrameAttr(rSet);
1325
0
    }
1326
0
    else
1327
0
    {
1328
0
        SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
1329
1330
0
        if(pSdrView)
1331
0
        {
1332
0
            rSet.Put(pSdrView->GetDefaultAttr());
1333
0
        }
1334
0
    }
1335
0
}
1336
1337
void SwFrameShell::ExecDrawAttrArgsTextFrame(SfxRequest const & rReq)
1338
0
{
1339
0
    const SfxItemSet* pArgs = rReq.GetArgs();
1340
0
    SwWrtShell& rSh = GetShell();
1341
1342
0
    if(pArgs)
1343
0
    {
1344
0
        if(rSh.IsFrameSelected())
1345
0
        {
1346
0
            rSh.SetFlyFrameAttr(const_cast< SfxItemSet& >(*pArgs));
1347
0
        }
1348
0
        else
1349
0
        {
1350
0
            SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
1351
1352
0
            if(pSdrView)
1353
0
            {
1354
0
                pSdrView->SetDefaultAttr(*pArgs, false);
1355
0
            }
1356
0
        }
1357
0
    }
1358
0
    else
1359
0
    {
1360
0
        SfxDispatcher* pDis = rSh.GetView().GetViewFrame().GetDispatcher();
1361
1362
0
        switch(rReq.GetSlot())
1363
0
        {
1364
0
            case SID_ATTR_FILL_STYLE:
1365
0
            case SID_ATTR_FILL_COLOR:
1366
0
            case SID_ATTR_FILL_GRADIENT:
1367
0
            case SID_ATTR_FILL_HATCH:
1368
0
            case SID_ATTR_FILL_BITMAP:
1369
0
            case SID_ATTR_FILL_TRANSPARENCE:
1370
0
            case SID_ATTR_FILL_FLOATTRANSPARENCE:
1371
0
            {
1372
0
                pDis->Execute(SID_ATTRIBUTES_AREA);
1373
0
                break;
1374
0
            }
1375
0
        }
1376
0
    }
1377
0
}
1378
1379
void SwFrameShell::ExecDrawDlgTextFrame(SfxRequest const & rReq)
1380
0
{
1381
0
    switch(rReq.GetSlot())
1382
0
    {
1383
0
        case SID_ATTRIBUTES_AREA:
1384
0
        {
1385
0
            SwWrtShell& rSh = GetShell();
1386
1387
0
            if(rSh.IsFrameSelected())
1388
0
            {
1389
0
                SdrModel& rModel = rSh.GetDrawView()->GetModel();
1390
0
                SfxItemSet aNewAttr(rModel.GetItemPool());
1391
1392
                // get attributes from FlyFrame
1393
0
                rSh.GetFlyFrameAttr(aNewAttr);
1394
1395
0
                SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1396
0
                VclPtr<AbstractSvxAreaTabDialog> pDlg(pFact->CreateSvxAreaTabDialog(
1397
0
                    GetView().GetFrameWeld(),
1398
0
                    &aNewAttr,
1399
0
                    &rModel,
1400
0
                    false,
1401
0
                    false));
1402
1403
0
                pDlg->StartExecuteAsync([pDlg, this](sal_Int32 nResult){
1404
0
                    if(nResult == RET_OK)
1405
0
                    {
1406
                        // set attributes at FlyFrame
1407
0
                        GetShell().SetFlyFrameAttr(const_cast< SfxItemSet& >(*pDlg->GetOutputItemSet()));
1408
1409
0
                        static const sal_uInt16 aInval[] =
1410
0
                        {
1411
0
                            SID_ATTR_FILL_STYLE,
1412
0
                            SID_ATTR_FILL_COLOR,
1413
0
                            SID_ATTR_FILL_TRANSPARENCE,
1414
0
                            SID_ATTR_FILL_FLOATTRANSPARENCE,
1415
0
                            0
1416
0
                        };
1417
1418
0
                        SfxBindings &rBnd = GetView().GetViewFrame().GetBindings();
1419
1420
0
                        rBnd.Invalidate(aInval);
1421
0
                        rBnd.Update(SID_ATTR_FILL_STYLE);
1422
0
                        rBnd.Update(SID_ATTR_FILL_COLOR);
1423
0
                        rBnd.Update(SID_ATTR_FILL_TRANSPARENCE);
1424
0
                        rBnd.Update(SID_ATTR_FILL_FLOATTRANSPARENCE);
1425
0
                    }
1426
0
                    pDlg->disposeOnce();
1427
0
                });
1428
0
            }
1429
1430
0
            break;
1431
0
        }
1432
0
    }
1433
0
}
1434
1435
void SwFrameShell::DisableStateTextFrame(SfxItemSet &rSet)
1436
0
{
1437
0
    SfxWhichIter aIter(rSet);
1438
0
    sal_uInt16 nWhich(aIter.FirstWhich());
1439
1440
0
    while(nWhich)
1441
0
    {
1442
0
        switch(nWhich)
1443
0
        {
1444
0
            case SID_ATTRIBUTES_AREA:
1445
0
            {
1446
0
                SwWrtShell& rSh = GetShell();
1447
1448
0
                if(!rSh.IsFrameSelected())
1449
0
                {
1450
0
                    rSet.DisableItem(nWhich);
1451
0
                }
1452
1453
0
                break;
1454
0
            }
1455
0
            default:
1456
0
            {
1457
0
                rSet.DisableItem(nWhich);
1458
0
                break;
1459
0
            }
1460
0
        }
1461
1462
0
        nWhich = aIter.NextWhich();
1463
0
    }
1464
0
}
1465
1466
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */