Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/drawfunc/fuconcustomshape.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 <fuconcustomshape.hxx>
21
#include <editeng/svxenum.hxx>
22
#include <svx/gallery.hxx>
23
#include <sfx2/request.hxx>
24
#include <svx/fmmodel.hxx>
25
#include <svl/stritem.hxx>
26
#include <svx/svdpage.hxx>
27
#include <svx/svdoashp.hxx>
28
#include <svx/xfillit0.hxx>
29
#include <editeng/eeitem.hxx>
30
#include <svx/sdtagitm.hxx>
31
#include <vcl/ptrstyle.hxx>
32
#include <tabvwsh.hxx>
33
#include <drawview.hxx>
34
#include <editeng/adjustitem.hxx>
35
36
using namespace com::sun::star;
37
38
FuConstCustomShape::FuConstCustomShape(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawView* pViewP, SdrModel& rDoc, const SfxRequest& rReq )
39
0
    : FuConstruct(rViewSh, pWin, pViewP, rDoc, rReq)
40
0
{
41
0
    const SfxItemSet* pArgs = rReq.GetArgs();
42
0
    if ( pArgs )
43
0
    {
44
0
        const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
45
0
        aCustomShape = rItm.GetValue();
46
0
    }
47
0
}
48
49
FuConstCustomShape::~FuConstCustomShape()
50
0
{
51
0
}
52
53
bool FuConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
54
0
{
55
    // remember button state for creation of own MouseEvents
56
0
    SetMouseButtonCode(rMEvt.GetButtons());
57
58
0
    bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
59
0
    if ( rMEvt.IsLeft() && !pView->IsAction() )
60
0
    {
61
0
        Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
62
0
        pWindow->CaptureMouse();
63
0
        pView->BegCreateObj(aPnt);
64
65
0
        SdrObject* pObj = pView->GetCreateObj();
66
0
        if ( pObj )
67
0
        {
68
0
            SetAttributes( pObj );
69
0
            bool bForceNoFillStyle = false;
70
0
            if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
71
0
                bForceNoFillStyle = true;
72
0
            if ( bForceNoFillStyle )
73
0
                pObj->SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE ) );
74
0
        }
75
76
0
        bReturn = true;
77
0
    }
78
0
    return bReturn;
79
0
}
80
81
bool FuConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
82
0
{
83
    // remember button state for creation of own MouseEvents
84
0
    SetMouseButtonCode(rMEvt.GetButtons());
85
86
0
    bool bReturn = false;
87
88
0
    if ( pView->IsCreateObj() && rMEvt.IsLeft() )
89
0
    {
90
0
        pView->EndCreateObj(SdrCreateCmd::ForceEnd);
91
0
        bReturn = true;
92
0
    }
93
0
    return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
94
0
}
95
96
void FuConstCustomShape::Activate()
97
0
{
98
0
    pView->SetCurrentObj( SdrObjKind::CustomShape );
99
100
0
    aNewPointer = PointerStyle::DrawRect;
101
0
    aOldPointer = pWindow->GetPointer();
102
0
    rViewShell.SetActivePointer( aNewPointer );
103
104
0
    FuConstruct::Activate();
105
0
}
106
107
void FuConstCustomShape::Deactivate()
108
0
{
109
0
    FuConstruct::Deactivate();
110
111
0
    rViewShell.SetActivePointer( aOldPointer );
112
0
}
113
114
// Create default drawing objects via keyboard
115
rtl::Reference<SdrObject> FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, const tools::Rectangle& rRectangle)
116
0
{
117
0
    rtl::Reference<SdrObject> pObj(SdrObjFactory::MakeNewObject(
118
0
        rDrDoc,
119
0
        pView->GetCurrentObjInventor(),
120
0
        pView->GetCurrentObjIdentifier()));
121
122
0
    if( pObj )
123
0
    {
124
0
        tools::Rectangle aRectangle( rRectangle );
125
0
        SetAttributes( pObj.get() );
126
0
        if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape ) )
127
0
            ImpForceQuadratic( aRectangle );
128
0
        pObj->SetLogicRect( aRectangle );
129
0
    }
130
131
0
    return pObj;
132
0
}
133
134
void FuConstCustomShape::SetAttributes( SdrObject* pObj )
135
0
{
136
0
    bool bAttributesAppliedFromGallery = false;
137
138
0
    if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
139
0
    {
140
0
        std::vector< OUString > aObjList;
141
0
        if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
142
0
        {
143
0
            for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
144
0
            {
145
0
                if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
146
0
                {
147
0
                    FmFormModel aFormModel;
148
149
0
                    if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
150
0
                    {
151
0
                        const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
152
0
                        if( pSourceObj )
153
0
                        {
154
0
                            const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
155
0
                            SfxItemSetFixed<
156
                                    // Ranges from SdrAttrObj:
157
0
                                    SDRATTR_START, SDRATTR_SHADOW_LAST,
158
0
                                    SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
159
0
                                    SDRATTR_TEXTDIRECTION,
160
0
                                        SDRATTR_TEXTDIRECTION,
161
                                    // Graphic attributes, 3D properties,
162
                                    // CustomShape properties:
163
0
                                    SDRATTR_GRAF_FIRST,
164
0
                                        SDRATTR_CUSTOMSHAPE_LAST,
165
                                    // Range from SdrTextObj:
166
0
                                    EE_ITEMS_START, EE_ITEMS_END>  aDest(
167
0
                                pObj->getSdrModelFromSdrObject().GetItemPool());
168
0
                            aDest.Set( rSource );
169
0
                            pObj->SetMergedItemSet( aDest );
170
0
                            Degree100 nAngle = pSourceObj->GetRotateAngle();
171
0
                            if ( nAngle )
172
0
                                pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle );
173
0
                            bAttributesAppliedFromGallery = true;
174
0
                        }
175
0
                    }
176
0
                    break;
177
0
                }
178
0
            }
179
0
        }
180
0
    }
181
0
    if ( !bAttributesAppliedFromGallery )
182
0
    {
183
0
        pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
184
0
        pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
185
0
        pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
186
0
        pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
187
0
        static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
188
0
    }
189
0
}
190
191
// #i33136#
192
bool FuConstCustomShape::doConstructOrthogonal() const
193
0
{
194
0
    return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
195
0
}
196
197
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */