Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/view/drviews6.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 <DrawViewShell.hxx>
23
#include <sfx2/request.hxx>
24
#include <vcl/svapp.hxx>
25
#include <vcl/weld/weld.hxx>
26
#include <sfx2/viewfrm.hxx>
27
#include <svx/svdograf.hxx>
28
#include <svx/svxids.hrc>
29
#include <svx/fontwork.hxx>
30
#include <svx/bmpmask.hxx>
31
#include <svx/imapdlg.hxx>
32
#include <svx/SvxColorChildWindow.hxx>
33
#include <svx/f3dchild.hxx>
34
#include <avmedia/mediaplayer.hxx>
35
#include <svl/intitem.hxx>
36
37
#include <app.hrc>
38
#include <strings.hrc>
39
40
#include <animobjs.hxx>
41
#include <AnimationChildWindow.hxx>
42
#include <sdresid.hxx>
43
#include <drawdoc.hxx>
44
#include <drawview.hxx>
45
#include <svx/svdoashp.hxx>
46
47
namespace sd {
48
49
/**
50
 * handle SfxRequests for FontWork
51
 */
52
void DrawViewShell::ExecFormText(SfxRequest& rReq)
53
0
{
54
    // nothing is executed during a slide show!
55
0
    if(HasCurrentFunction(SID_PRESENTATION))
56
0
        return;
57
58
0
    CheckLineTo (rReq);
59
60
0
    const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
61
62
0
    if ( rMarkList.GetMarkCount() == 1 && rReq.GetArgs() &&
63
0
         !mpDrawView->IsPresObjSelected() )
64
0
    {
65
0
        const SfxItemSet& rSet = *rReq.GetArgs();
66
67
0
        if ( mpDrawView->IsTextEdit() )
68
0
            mpDrawView->SdrEndTextEdit();
69
70
0
        mpDrawView->SetAttributes(rSet);
71
0
    }
72
0
}
73
74
/**
75
 * Return state values for FontWork
76
 */
77
void DrawViewShell::GetFormTextState(SfxItemSet& rSet)
78
0
{
79
0
    const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
80
0
    const SdrObject* pObj = nullptr;
81
82
0
    if ( rMarkList.GetMarkCount() == 1 )
83
0
        pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
84
85
0
    const SdrTextObj* pTextObj = DynCastSdrTextObj(pObj);
86
0
    const bool bDeactivate(
87
0
        !pObj ||
88
0
        !pTextObj ||
89
0
        !pTextObj->HasText() ||
90
0
        dynamic_cast< const SdrObjCustomShape* >(pObj)); // #121538# no FontWork for CustomShapes
91
92
0
    if(bDeactivate)
93
0
    {
94
// automatic open/close the FontWork-Dialog; first deactivate it
95
96
0
        rSet.DisableItem(XATTR_FORMTXTSTYLE);
97
0
        rSet.DisableItem(XATTR_FORMTXTADJUST);
98
0
        rSet.DisableItem(XATTR_FORMTXTDISTANCE);
99
0
        rSet.DisableItem(XATTR_FORMTXTSTART);
100
0
        rSet.DisableItem(XATTR_FORMTXTMIRROR);
101
0
        rSet.DisableItem(XATTR_FORMTXTHIDEFORM);
102
0
        rSet.DisableItem(XATTR_FORMTXTOUTLINE);
103
0
        rSet.DisableItem(XATTR_FORMTXTSHADOW);
104
0
        rSet.DisableItem(XATTR_FORMTXTSHDWCOLOR);
105
0
        rSet.DisableItem(XATTR_FORMTXTSHDWXVAL);
106
0
        rSet.DisableItem(XATTR_FORMTXTSHDWYVAL);
107
0
    }
108
0
    else
109
0
    {
110
0
        SfxItemSet aSet( GetDoc()->GetPool() );
111
0
        mpDrawView->GetAttributes( aSet );
112
0
        rSet.Set( aSet );
113
0
    }
114
0
}
115
116
void DrawViewShell::ExecAnimationWin( SfxRequest& rReq )
117
0
{
118
    // nothing is executed during a slide show!
119
0
    if (HasCurrentFunction(SID_PRESENTATION))
120
0
        return;
121
122
0
    CheckLineTo (rReq);
123
124
0
    sal_uInt16 nSId = rReq.GetSlot();
125
126
0
    switch( nSId )
127
0
    {
128
0
        case SID_ANIMATOR_INIT:
129
0
        case SID_ANIMATOR_ADD:
130
0
        case SID_ANIMATOR_CREATE:
131
0
        {
132
0
            AnimationWindow* pAnimWin;
133
0
            sal_uInt16 nId = AnimationChildWindow::GetChildWindowId();
134
135
0
            SfxChildWindow* pWnd = GetViewFrame()->GetChildWindow(nId);
136
137
0
            pAnimWin = pWnd ? static_cast<AnimationWindow*>(pWnd->GetWindow()) : nullptr;
138
139
0
            if ( pAnimWin )
140
0
            {
141
0
                if( nSId == SID_ANIMATOR_ADD )
142
0
                    pAnimWin->AddObj( *mpDrawView );
143
0
                else if( nSId == SID_ANIMATOR_CREATE )
144
0
                    pAnimWin->CreateAnimObj( *mpDrawView );
145
0
            }
146
0
        }
147
0
        break;
148
149
0
        default:
150
0
        break;
151
0
    }
152
0
}
153
154
/**
155
 * Return status values for animator
156
 *
157
 * nValue == 0 -> No button
158
 * nValue == 1 -> Button 'accept'
159
 * nValue == 2 -> Button 'accept individually'
160
 * nValue == 3 -> Buttons 'accept' and 'accept individually'
161
 */
162
void DrawViewShell::GetAnimationWinState( SfxItemSet& rSet )
163
0
{
164
    // here we could disable buttons etc.
165
0
    sal_uInt16 nValue;
166
167
0
    const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
168
0
    const size_t nMarkCount = rMarkList.GetMarkCount();
169
170
0
    if( nMarkCount == 0 )
171
0
        nValue = 0;
172
0
    else if( nMarkCount > 1 )
173
0
        nValue = 3;
174
0
    else // 1 Object
175
0
    {
176
0
        const SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
177
0
        SdrInventor nInv = pObj->GetObjInventor();
178
0
        SdrObjKind  nId  = pObj->GetObjIdentifier();
179
        // 1 selected group object
180
0
        if( nInv == SdrInventor::Default && nId == SdrObjKind::Group )
181
0
            nValue = 3;
182
0
        else if( nInv == SdrInventor::Default && nId == SdrObjKind::Graphic ) // Animated GIF ?
183
0
        {
184
0
            sal_uInt16 nCount = 0;
185
186
0
            if( static_cast<const SdrGrafObj*>(pObj)->IsAnimated() )
187
0
                nCount = static_cast<const SdrGrafObj*>(pObj)->GetGraphic().GetAnimation().Count();
188
0
            if( nCount > 0 )
189
0
                nValue = 2;
190
0
            else
191
0
                nValue = 1;
192
0
        }
193
0
        else
194
0
            nValue = 1;
195
0
    }
196
0
    rSet.Put( SfxUInt16Item( SID_ANIMATOR_STATE, nValue ) );
197
0
}
198
199
void DrawViewShell::SetChildWindowState( SfxItemSet& rSet )
200
0
{
201
    // State of SfxChild-Windows (Animator, Fontwork etc.)
202
0
    if( SfxItemState::DEFAULT == rSet.GetItemState( SID_FONTWORK ) )
203
0
    {
204
0
        sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
205
0
        rSet.Put(SfxBoolItem(SID_FONTWORK, GetViewFrame()->HasChildWindow(nId)));
206
0
    }
207
0
    if( SfxItemState::DEFAULT == rSet.GetItemState( SID_COLOR_CONTROL ) )
208
0
    {
209
0
        sal_uInt16 nId = SvxColorChildWindow::GetChildWindowId();
210
0
        rSet.Put(SfxBoolItem(SID_COLOR_CONTROL, GetViewFrame()->HasChildWindow(nId)));
211
0
    }
212
0
    if( SfxItemState::DEFAULT == rSet.GetItemState( SID_ANIMATION_OBJECTS ) )
213
0
    {
214
0
        sal_uInt16 nId = AnimationChildWindow::GetChildWindowId();
215
0
        rSet.Put( SfxBoolItem( SID_ANIMATION_OBJECTS, GetViewFrame()->HasChildWindow( nId ) ) );
216
0
    }
217
0
    if( SfxItemState::DEFAULT == rSet.GetItemState( SID_NAVIGATOR ) )
218
0
    {
219
0
        rSet.Put( SfxBoolItem( SID_NAVIGATOR, GetViewFrame()->HasChildWindow( SID_NAVIGATOR ) ) );
220
0
    }
221
0
    if( SfxItemState::DEFAULT == rSet.GetItemState( SID_BMPMASK ) )
222
0
    {
223
0
        sal_uInt16 nId = SvxBmpMaskChildWindow::GetChildWindowId();
224
0
        rSet.Put( SfxBoolItem( SID_BMPMASK, GetViewFrame()->HasChildWindow( nId ) ) );
225
0
    }
226
0
    if( SfxItemState::DEFAULT == rSet.GetItemState( SID_IMAP ) )
227
0
    {
228
0
        sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
229
0
        rSet.Put( SfxBoolItem( SID_IMAP, GetViewFrame()->HasChildWindow( nId ) ) );
230
0
    }
231
0
    if( SfxItemState::DEFAULT == rSet.GetItemState( SID_3D_WIN ) )
232
0
    {
233
0
        sal_uInt16 nId = Svx3DChildWindow::GetChildWindowId();
234
0
        rSet.Put( SfxBoolItem( SID_3D_WIN, GetViewFrame()->HasChildWindow( nId ) ) );
235
0
    }
236
0
#if HAVE_FEATURE_AVMEDIA
237
0
    if( SfxItemState::DEFAULT == rSet.GetItemState( SID_AVMEDIA_PLAYER ) )
238
0
    {
239
0
        sal_uInt16 nId = ::avmedia::MediaPlayer::GetChildWindowId();
240
0
        rSet.Put( SfxBoolItem( SID_AVMEDIA_PLAYER, GetViewFrame()->HasChildWindow( nId ) ) );
241
0
    }
242
0
#endif
243
0
}
244
245
/**
246
 * Handle SfxRequests for pipette
247
 */
248
void DrawViewShell::ExecBmpMask( SfxRequest const & rReq )
249
0
{
250
    // nothing is executed during a slide show!
251
0
    if (HasCurrentFunction(SID_PRESENTATION))
252
0
        return;
253
254
0
    switch ( rReq.GetSlot() )
255
0
    {
256
0
        case SID_BMPMASK_PIPETTE :
257
0
        {
258
0
            mbPipette = rReq.GetArgs()->Get( SID_BMPMASK_PIPETTE ).GetValue();
259
0
        }
260
0
        break;
261
262
0
        case SID_BMPMASK_EXEC :
263
0
        {
264
0
            if (!mpDrawView)
265
0
                return;
266
267
0
            SdrGrafObj* pObj = nullptr;
268
0
            const SdrMarkList&  rMarkList = mpDrawView->GetMarkedObjectList();
269
0
            if( rMarkList.GetMarkCount() )
270
0
                pObj = dynamic_cast< SdrGrafObj* >( rMarkList.GetMark(0)->GetMarkedSdrObj() );
271
272
0
            if ( pObj && !mpDrawView->IsTextEdit() )
273
0
            {
274
0
                rtl::Reference<SdrGrafObj> xNewObj(SdrObject::Clone(*pObj, pObj->getSdrModelFromSdrObject()));
275
0
                bool bCont = true;
276
277
0
                if (xNewObj->IsLinkedGraphic())
278
0
                {
279
0
                    std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), u"modules/sdraw/ui/queryunlinkimagedialog.ui"_ustr));
280
0
                    std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog(u"QueryUnlinkImageDialog"_ustr));
281
282
0
                    if (RET_YES == xQueryBox->run())
283
0
                        xNewObj->ReleaseGraphicLink();
284
0
                    else
285
0
                        bCont = false;
286
0
                }
287
288
0
                SfxChildWindow* pWnd = GetViewFrame()->GetChildWindow(
289
0
                                         SvxBmpMaskChildWindow::GetChildWindowId());
290
0
                SvxBmpMask* pBmpMask = pWnd ? static_cast<SvxBmpMask*>(pWnd->GetWindow()) : nullptr;
291
0
                assert(pBmpMask);
292
0
                if (bCont && pBmpMask)
293
0
                {
294
0
                    const Graphic&  rOldGraphic = xNewObj->GetGraphic();
295
0
                    const Graphic   aNewGraphic(pBmpMask->Mask(rOldGraphic));
296
297
0
                    if( aNewGraphic != rOldGraphic )
298
0
                    {
299
0
                        SdrPageView* pPV = mpDrawView->GetSdrPageView();
300
301
0
                        xNewObj->SetEmptyPresObj(false);
302
0
                        xNewObj->SetGraphic(pBmpMask->Mask(xNewObj->GetGraphic()));
303
304
0
                        OUString aStr = rMarkList.GetMarkDescription() +
305
0
                            " " + SdResId(STR_EYEDROPPER);
306
307
0
                        mpDrawView->BegUndo( aStr );
308
0
                        mpDrawView->ReplaceObjectAtView(pObj, *pPV, xNewObj.get());
309
0
                        mpDrawView->EndUndo();
310
0
                    }
311
0
                }
312
0
            }
313
0
        }
314
0
        break;
315
316
0
        default:
317
0
        break;
318
0
    }
319
0
}
320
321
void DrawViewShell::GetBmpMaskState( SfxItemSet& rSet )
322
0
{
323
0
    const SdrMarkList&  rMarkList = mpDrawView->GetMarkedObjectList();
324
0
    const SdrObject*    pObj = nullptr;
325
0
    bool                bEnable = false;
326
327
0
    if ( rMarkList.GetMarkCount() == 1 )
328
0
        pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
329
330
    // valid graphic object?
331
0
    if( auto pGrafObj = dynamic_cast< const SdrGrafObj *>( pObj ) )
332
0
        if (!pGrafObj->IsEPS() && !mpDrawView->IsTextEdit() )
333
0
            bEnable = true;
334
335
    // put value
336
0
    rSet.Put( SfxBoolItem( SID_BMPMASK_EXEC, bEnable ) );
337
0
}
338
339
} // end of namespace sd
340
341
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */