Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/view/drviews9.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 <svx/svdpagv.hxx>
24
#include <svx/xfillit0.hxx>
25
#include <svx/xlineit0.hxx>
26
#include <svx/xlnwtit.hxx>
27
#include <svx/xlndsit.hxx>
28
#include <svx/xflhtit.hxx>
29
#include <svx/xflgrit.hxx>
30
#include <svx/xlnclit.hxx>
31
#include <svx/xflclit.hxx>
32
#include <sfx2/bindings.hxx>
33
34
#include <sfx2/dispatch.hxx>
35
#include <svl/intitem.hxx>
36
#include <sfx2/request.hxx>
37
#include <svl/stritem.hxx>
38
#include <svx/svxids.hrc>
39
#include <svx/xtable.hxx>
40
#include <vcl/graph.hxx>
41
#include <svx/svdograf.hxx>
42
#include <svl/whiter.hxx>
43
#include <basic/sbstar.hxx>
44
#include <basic/sberrors.hxx>
45
46
#include <sfx2/viewfrm.hxx>
47
48
#include <app.hrc>
49
#include <strings.hrc>
50
#include <Window.hxx>
51
#include <drawdoc.hxx>
52
#include <drawview.hxx>
53
#include <DrawDocShell.hxx>
54
#include <sdresid.hxx>
55
56
#include <svx/galleryitem.hxx>
57
#include <com/sun/star/gallery/GalleryItemType.hpp>
58
#include <com/sun/star/drawing/LineStyle.hpp>
59
#include <memory>
60
61
using namespace com::sun::star;
62
63
namespace sd {
64
65
void DrawViewShell::ExecGallery(SfxRequest const & rReq)
66
0
{
67
    // nothing is executed during a slide show!
68
0
    if(HasCurrentFunction(SID_PRESENTATION))
69
0
        return;
70
71
0
    const SfxItemSet* pArgs = rReq.GetArgs();
72
73
0
    const SvxGalleryItem* pGalleryItem = SfxItemSet::GetItem<SvxGalleryItem>(pArgs, SID_GALLERY_FORMATS, false);
74
0
    if ( !pGalleryItem )
75
0
        return;
76
77
0
    GetDocSh()->SetWaitCursor( true );
78
79
0
    sal_Int8 nType( pGalleryItem->GetType() );
80
    // insert graphic
81
0
    if (nType == css::gallery::GalleryItemType::GRAPHIC)
82
0
    {
83
0
        Graphic aGraphic( pGalleryItem->GetGraphic() );
84
85
        // reduce size if necessary
86
0
        ScopedVclPtrInstance< Window > aWindow(GetActiveWindow());
87
0
        aWindow->SetMapMode(aGraphic.GetPrefMapMode());
88
0
        Size aSizePix = aWindow->LogicToPixel(aGraphic.GetPrefSize());
89
0
        aWindow->SetMapMode( MapMode(MapUnit::Map100thMM) );
90
0
        Size aSize = aWindow->PixelToLogic(aSizePix);
91
92
        // constrain size to page size if necessary
93
0
        SdrPage* pPage = mpDrawView->GetSdrPageView()->GetPage();
94
0
        Size aPageSize = pPage->GetSize();
95
0
        aPageSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) );
96
0
        aPageSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) );
97
98
        // If the image is too large we make it fit into the page
99
0
        const auto nSizeHeight = aSize.Height(), nSizeWidth = aSize.Width();
100
0
        const auto nPageHeight = aPageSize.Height(), nPageWidth = aPageSize.Width();
101
0
        if ((nSizeHeight > nPageHeight || nSizeWidth > nPageWidth) &&
102
0
            nSizeHeight && nPageHeight)
103
0
        {
104
0
            float fGrfWH =  static_cast<float>(nSizeWidth) / static_cast<float>(nSizeHeight);
105
0
            float fWinWH =  static_cast<float>(nPageWidth) / static_cast<float>(nPageHeight);
106
107
            // constrain size to page size if necessary
108
0
            if (fGrfWH < fWinWH)
109
0
            {
110
0
                aSize.setWidth( static_cast<::tools::Long>(nPageHeight * fGrfWH) );
111
0
                aSize.setHeight( nPageHeight );
112
0
            }
113
0
            else
114
0
            {
115
0
                aSize.setWidth( nPageWidth );
116
0
                aSize.setHeight( static_cast<::tools::Long>(nPageWidth / fGrfWH) );
117
0
            }
118
0
        }
119
120
        // set output rectangle for graphic
121
0
        Point aPnt ((nPageWidth  - aSize.Width())  / 2,
122
0
                    (nPageHeight - aSize.Height()) / 2);
123
0
        aPnt += Point(pPage->GetLeftBorder(), pPage->GetUpperBorder());
124
0
        ::tools::Rectangle aRect (aPnt, aSize);
125
126
0
        rtl::Reference<SdrGrafObj> pGrafObj;
127
128
0
        bool bInsertNewObject = true;
129
130
0
        const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
131
0
        if ( rMarkList.GetMarkCount() != 0 )
132
0
        {
133
            // is there an empty graphic object?
134
0
            if (rMarkList.GetMarkCount() == 1)
135
0
            {
136
0
                SdrMark* pMark = rMarkList.GetMark(0);
137
0
                SdrObject* pObj = pMark->GetMarkedSdrObj();
138
139
0
                if (pObj->GetObjInventor() == SdrInventor::Default && pObj->GetObjIdentifier() == SdrObjKind::Graphic)
140
0
                {
141
0
                    pGrafObj = static_cast<SdrGrafObj*>(pObj);
142
143
0
                    if( pGrafObj->IsEmptyPresObj() )
144
0
                    {
145
                        // the empty graphic object gets a new graphic
146
0
                        bInsertNewObject = false;
147
148
0
                        rtl::Reference<SdrGrafObj> pNewGrafObj(SdrObject::Clone(*pGrafObj, pGrafObj->getSdrModelFromSdrObject()));
149
0
                        pNewGrafObj->SetEmptyPresObj(false);
150
0
                        pNewGrafObj->SetOutlinerParaObject(std::nullopt);
151
0
                        pNewGrafObj->SetGraphic(aGraphic);
152
153
0
                        OUString aStr = rMarkList.GetMarkDescription() +
154
0
                            " " + SdResId(STR_UNDO_REPLACE);
155
0
                        mpDrawView->BegUndo(aStr);
156
0
                        SdrPageView* pPV = mpDrawView->GetSdrPageView();
157
0
                        mpDrawView->ReplaceObjectAtView(pGrafObj.get(), *pPV, pNewGrafObj.get());
158
0
                        mpDrawView->EndUndo();
159
0
                    }
160
0
                }
161
0
            }
162
0
        }
163
164
0
        if( bInsertNewObject )
165
0
        {
166
0
            pGrafObj = new SdrGrafObj(
167
0
                GetView()->getSdrModelFromSdrView(),
168
0
                aGraphic,
169
0
                aRect);
170
0
            SdrPageView* pPV = mpDrawView->GetSdrPageView();
171
0
            mpDrawView->InsertObjectAtView(pGrafObj.get(), *pPV, SdrInsertFlags::SETDEFLAYER);
172
0
        }
173
0
    }
174
    // insert sound
175
0
    else if( nType == css::gallery::GalleryItemType::MEDIA )
176
0
    {
177
0
        const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, pGalleryItem->GetURL() );
178
0
        GetViewFrame()->GetDispatcher()->ExecuteList(SID_INSERT_AVMEDIA,
179
0
                SfxCallMode::SYNCHRON, { &aMediaURLItem });
180
0
    }
181
182
0
    GetDocSh()->SetWaitCursor( false );
183
0
}
184
185
/**
186
 * Edit macros for attribute configuration
187
 */
188
189
/* the work flow to adjust the attributes is nearly everywhere the same
190
   1. read existing attributes
191
   2. read parameter from the basic-set
192
   3. delete selected item from the attribute-set
193
   4. create new attribute-item
194
   5. insert item into set      */
195
void DrawViewShell::AttrExec (SfxRequest &rReq)
196
0
{
197
    // nothing is executed during a slide show!
198
0
    if(HasCurrentFunction(SID_PRESENTATION))
199
0
        return;
200
201
0
    CheckLineTo (rReq);
202
203
0
    SfxBindings&    rBindings = GetViewFrame()->GetBindings();
204
0
    SfxItemSet aAttr( GetDoc()->GetPool() );
205
206
0
    GetView()->GetAttributes( aAttr );
207
0
    const SfxItemSet* pArgs = rReq.GetArgs();
208
209
0
    switch (rReq.GetSlot ())
210
0
    {
211
        // set new fill-style
212
0
        case SID_SETFILLSTYLE :
213
0
            if (pArgs && pArgs->Count () == 1)
214
0
            {
215
0
                const SfxUInt32Item* pFillStyle = rReq.GetArg<SfxUInt32Item>(ID_VAL_STYLE);
216
0
                if (CHECK_RANGE (drawing::FillStyle_NONE, static_cast<drawing::FillStyle>(pFillStyle->GetValue ()), drawing::FillStyle_BITMAP))
217
0
                {
218
0
                    aAttr.ClearItem (XATTR_FILLSTYLE);
219
0
                    XFillStyleItem aStyleItem(static_cast<drawing::FillStyle>(pFillStyle->GetValue ()));
220
0
                    aStyleItem.SetWhich(XATTR_FILLSTYLE);
221
0
                    aAttr.Put (aStyleItem);
222
0
                    rBindings.Invalidate (SID_ATTR_FILL_STYLE);
223
0
                    rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
224
0
                }
225
#if HAVE_FEATURE_SCRIPTING
226
                else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
227
#endif
228
0
                break;
229
0
            }
230
#if HAVE_FEATURE_SCRIPTING
231
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
232
#endif
233
0
            break;
234
235
        // determine new line style
236
0
        case SID_SETLINESTYLE :
237
0
            if (pArgs && pArgs->Count () == 1)
238
0
            {
239
0
                const SfxUInt32Item* pLineStyle = rReq.GetArg<SfxUInt32Item>(ID_VAL_STYLE);
240
0
                if (CHECK_RANGE (sal_Int32(drawing::LineStyle_NONE), static_cast<sal_Int32>(pLineStyle->GetValue()), sal_Int32(drawing::LineStyle_DASH)))
241
0
                {
242
0
                    aAttr.ClearItem (XATTR_LINESTYLE);
243
0
                    XLineStyleItem aStyleItem(static_cast<drawing::LineStyle>(pLineStyle->GetValue()));
244
0
                    aStyleItem.SetWhich(XATTR_LINESTYLE);
245
0
                    aAttr.Put(aStyleItem);
246
0
                    rBindings.Invalidate (SID_ATTR_LINE_STYLE);
247
0
                }
248
#if HAVE_FEATURE_SCRIPTING
249
                else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
250
#endif
251
0
                break;
252
0
            }
253
#if HAVE_FEATURE_SCRIPTING
254
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
255
#endif
256
0
            break;
257
258
        // set line width
259
0
        case SID_SETLINEWIDTH :
260
0
            if (pArgs && pArgs->Count () == 1)
261
0
            {
262
0
                const SfxUInt32Item* pLineWidth = rReq.GetArg<SfxUInt32Item>(ID_VAL_WIDTH);
263
0
                aAttr.ClearItem (XATTR_LINEWIDTH);
264
0
                XLineWidthItem aWidthItem(pLineWidth->GetValue());
265
0
                aWidthItem.SetWhich(XATTR_LINEWIDTH);
266
0
                aAttr.Put(aWidthItem);
267
0
                rBindings.Invalidate (SID_ATTR_LINE_WIDTH);
268
0
                break;
269
0
            }
270
#if HAVE_FEATURE_SCRIPTING
271
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
272
#endif
273
0
            break;
274
275
0
        case SID_SETFILLCOLOR :
276
0
            if (pArgs && pArgs->Count () == 3)
277
0
            {
278
0
                const SfxUInt32Item* pRed = rReq.GetArg<SfxUInt32Item>(ID_VAL_RED);
279
0
                const SfxUInt32Item* pGreen = rReq.GetArg<SfxUInt32Item>(ID_VAL_GREEN);
280
0
                const SfxUInt32Item* pBlue = rReq.GetArg<SfxUInt32Item>(ID_VAL_BLUE);
281
282
0
                aAttr.ClearItem (XATTR_FILLCOLOR);
283
0
                aAttr.ClearItem (XATTR_FILLSTYLE);
284
0
                XFillColorItem aColorItem(-1, Color (static_cast<sal_uInt8>(pRed->GetValue ()),
285
0
                                                       static_cast<sal_uInt8>(pGreen->GetValue ()),
286
0
                                                       static_cast<sal_uInt8>(pBlue->GetValue ())));
287
0
                aColorItem.SetWhich(XATTR_FILLCOLOR);
288
0
                aAttr.Put(aColorItem);
289
0
                rBindings.Invalidate (SID_ATTR_FILL_COLOR);
290
0
                rBindings.Invalidate (SID_ATTR_PAGE_COLOR);
291
0
                rBindings.Invalidate (SID_ATTR_FILL_STYLE);
292
0
                rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
293
0
                break;
294
0
            }
295
#if HAVE_FEATURE_SCRIPTING
296
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
297
#endif
298
0
            break;
299
300
0
        case SID_SETLINECOLOR :
301
0
            if (pArgs && pArgs->Count () == 3)
302
0
            {
303
0
                const SfxUInt32Item* pRed = rReq.GetArg<SfxUInt32Item>(ID_VAL_RED);
304
0
                const SfxUInt32Item* pGreen = rReq.GetArg<SfxUInt32Item>(ID_VAL_GREEN);
305
0
                const SfxUInt32Item* pBlue = rReq.GetArg<SfxUInt32Item>(ID_VAL_BLUE);
306
307
0
                aAttr.ClearItem (XATTR_LINECOLOR);
308
0
                XLineColorItem aColorItem(-1, Color(static_cast<sal_uInt8>(pRed->GetValue()),
309
0
                                                    static_cast<sal_uInt8>(pGreen->GetValue()),
310
0
                                                    static_cast<sal_uInt8>(pBlue->GetValue())));
311
0
                aColorItem.SetWhich(XATTR_LINECOLOR);
312
0
                aAttr.Put(aColorItem);
313
0
                rBindings.Invalidate (SID_ATTR_LINE_COLOR);
314
0
                break;
315
0
            }
316
#if HAVE_FEATURE_SCRIPTING
317
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
318
#endif
319
0
            break;
320
321
0
        case SID_SETGRADSTARTCOLOR :
322
0
        case SID_SETGRADENDCOLOR :
323
0
            if (pArgs && pArgs->Count () == 4)
324
0
            {
325
0
                const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
326
0
                const SfxUInt32Item* pRed = rReq.GetArg<SfxUInt32Item>(ID_VAL_RED);
327
0
                const SfxUInt32Item* pGreen = rReq.GetArg<SfxUInt32Item>(ID_VAL_GREEN);
328
0
                const SfxUInt32Item* pBlue = rReq.GetArg<SfxUInt32Item>(ID_VAL_BLUE);
329
0
                assert(pName && pRed && pGreen && pBlue && "must be present");
330
331
0
                XGradientListRef pGradientList = GetDoc()->GetGradientList ();
332
0
                ::tools::Long          nCounts        = pGradientList->Count ();
333
0
                Color         aColor (static_cast<sal_uInt8>(pRed->GetValue ()),
334
0
                                      static_cast<sal_uInt8>(pGreen->GetValue ()),
335
0
                                      static_cast<sal_uInt8>(pBlue->GetValue ()));
336
0
                ::tools::Long i;
337
338
0
                aAttr.ClearItem (XATTR_FILLGRADIENT);
339
0
                aAttr.ClearItem (XATTR_FILLSTYLE);
340
341
0
                for ( i = 0; i < nCounts; i ++)
342
0
                {
343
0
                    const XGradientEntry* pEntry = pGradientList->GetGradient(i);
344
345
0
                    if (pEntry->GetName () == pName->GetValue ())
346
0
                    {
347
0
                        basegfx::BGradient aGradient(pEntry->GetGradient());
348
0
                        basegfx::BColorStops aNewColorStops(aGradient.GetColorStops());
349
350
0
                        if (SID_SETGRADSTARTCOLOR == rReq.GetSlot ())
351
0
                        {
352
0
                            aNewColorStops.replaceStartColor(aColor.getBColor());
353
0
                        }
354
0
                        else
355
0
                        {
356
0
                            aNewColorStops.replaceEndColor(aColor.getBColor());
357
0
                        }
358
359
0
                        aGradient.SetColorStops(aNewColorStops);
360
361
0
                        XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT);
362
0
                        aStyleItem.SetWhich(XATTR_FILLSTYLE);
363
0
                        aAttr.Put(aStyleItem);
364
0
                        XFillGradientItem aGradientItem(pName->GetValue (), aGradient);
365
0
                        aGradientItem.SetWhich(XATTR_FILLGRADIENT);
366
0
                        aAttr.Put(aGradientItem);
367
0
                        break;
368
0
                    }
369
0
                }
370
371
0
                if (i >= nCounts)
372
0
                {
373
0
                    Color aBlack (0, 0, 0);
374
0
                    basegfx::BGradient aGradient (
375
0
                        basegfx::BColorStops(
376
0
                            (rReq.GetSlot () == SID_SETGRADSTARTCOLOR)
377
0
                                             ? aColor.getBColor()
378
0
                                             : aBlack.getBColor(),
379
0
                            (rReq.GetSlot () == SID_SETGRADENDCOLOR)
380
0
                                             ? aColor.getBColor()
381
0
                                             : aBlack.getBColor()));
382
383
0
                    GetDoc()->GetGradientList()->Insert(std::make_unique<XGradientEntry>(aGradient, pName->GetValue()));
384
385
0
                    XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT);
386
0
                    aStyleItem.SetWhich(XATTR_FILLSTYLE);
387
0
                    aAttr.Put(aStyleItem);
388
0
                    XFillGradientItem aGradientItem(pName->GetValue(), aGradient);
389
0
                    aGradientItem.SetWhich(XATTR_FILLGRADIENT);
390
0
                    aAttr.Put(aGradientItem);
391
0
                }
392
393
0
                rBindings.Invalidate (SID_ATTR_FILL_STYLE);
394
0
                rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
395
0
                rBindings.Invalidate (SID_ATTR_FILL_GRADIENT);
396
0
                rBindings.Invalidate (SID_ATTR_PAGE_GRADIENT);
397
0
                break;
398
0
            }
399
#if HAVE_FEATURE_SCRIPTING
400
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
401
#endif
402
0
            break;
403
404
0
        case SID_SETHATCHCOLOR :
405
0
            if (pArgs && pArgs->Count () == 4)
406
0
            {
407
0
                const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
408
0
                const SfxUInt32Item* pRed = rReq.GetArg<SfxUInt32Item>(ID_VAL_RED);
409
0
                const SfxUInt32Item* pGreen = rReq.GetArg<SfxUInt32Item>(ID_VAL_GREEN);
410
0
                const SfxUInt32Item* pBlue = rReq.GetArg<SfxUInt32Item>(ID_VAL_BLUE);
411
0
                assert(pName && pRed && pGreen && pBlue && "must be present");
412
413
0
                XHatchListRef pHatchList = GetDoc()->GetHatchList ();
414
0
                ::tools::Long       nCounts     = pHatchList->Count ();
415
0
                Color      aColor (static_cast<sal_uInt8>(pRed->GetValue ()),
416
0
                                   static_cast<sal_uInt8>(pGreen->GetValue ()),
417
0
                                   static_cast<sal_uInt8>(pBlue->GetValue ()));
418
0
                ::tools::Long i;
419
420
0
                aAttr.ClearItem (XATTR_FILLHATCH);
421
0
                aAttr.ClearItem (XATTR_FILLSTYLE);
422
423
0
                for ( i = 0; i < nCounts; i ++)
424
0
                {
425
0
                    const XHatchEntry* pEntry = pHatchList->GetHatch(i);
426
427
0
                    if (pEntry->GetName () == pName->GetValue ())
428
0
                    {
429
0
                        XHatch aHatch(pEntry->GetHatch());
430
431
0
                        aHatch.SetColor (aColor);
432
433
0
                        XFillStyleItem aStyleItem(drawing::FillStyle_HATCH);
434
0
                        aStyleItem.SetWhich(XATTR_FILLSTYLE);
435
0
                        aAttr.Put(aStyleItem);
436
0
                        XFillHatchItem aHatchItem(pName->GetValue(), aHatch);
437
0
                        aHatchItem.SetWhich(XATTR_FILLHATCH);
438
0
                        aAttr.Put(aHatchItem);
439
0
                        break;
440
0
                    }
441
0
                }
442
443
0
                if (i >= nCounts)
444
0
                {
445
0
                    XHatch aHatch (aColor);
446
447
0
                    GetDoc()->GetHatchList()->Insert(std::make_unique<XHatchEntry>(aHatch, pName->GetValue()));
448
449
0
                    XFillStyleItem aStyleItem(drawing::FillStyle_HATCH);
450
0
                    aStyleItem.SetWhich(XATTR_FILLSTYLE);
451
0
                    aAttr.Put(aStyleItem);
452
0
                    XFillHatchItem aHatchItem(pName->GetValue (), aHatch);
453
0
                    aHatchItem.SetWhich(XATTR_FILLHATCH);
454
0
                    aAttr.Put(aHatchItem);
455
0
                }
456
457
0
                rBindings.Invalidate (SID_ATTR_FILL_HATCH);
458
0
                rBindings.Invalidate (SID_ATTR_PAGE_HATCH);
459
0
                rBindings.Invalidate (SID_ATTR_FILL_STYLE);
460
0
                rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
461
0
                break;
462
0
            }
463
#if HAVE_FEATURE_SCRIPTING
464
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
465
#endif
466
0
            break;
467
468
        // configuration for line-dash
469
0
        case SID_DASH :
470
0
            if (pArgs && pArgs->Count () == 7)
471
0
            {
472
0
                const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
473
0
                const SfxUInt32Item* pStyle = rReq.GetArg<SfxUInt32Item>(ID_VAL_STYLE);
474
0
                const SfxUInt32Item* pDots = rReq.GetArg<SfxUInt32Item>(ID_VAL_DOTS);
475
0
                const SfxUInt32Item* pDotLen = rReq.GetArg<SfxUInt32Item>(ID_VAL_DOTLEN);
476
0
                const SfxUInt32Item* pDashes = rReq.GetArg<SfxUInt32Item>(ID_VAL_DASHES);
477
0
                const SfxUInt32Item* pDashLen = rReq.GetArg<SfxUInt32Item>(ID_VAL_DASHLEN);
478
0
                const SfxUInt32Item* pDistance = rReq.GetArg<SfxUInt32Item>(ID_VAL_DISTANCE);
479
0
                assert(pName && pStyle && pDots && pDotLen && pDashes && pDashLen && pDistance && "must be present");
480
481
0
                if (CHECK_RANGE (sal_Int32(css::drawing::DashStyle_RECT), static_cast<sal_Int32>(pStyle->GetValue()), sal_Int32(css::drawing::DashStyle_ROUNDRELATIVE)))
482
0
                {
483
0
                    XDash aNewDash (static_cast<css::drawing::DashStyle>(pStyle->GetValue ()), static_cast<short>(pDots->GetValue ()), pDotLen->GetValue (),
484
0
                                    static_cast<short>(pDashes->GetValue ()), pDashLen->GetValue (), pDistance->GetValue ());
485
486
0
                    aAttr.ClearItem (XATTR_LINEDASH);
487
0
                    aAttr.ClearItem (XATTR_LINESTYLE);
488
489
0
                    XDashListRef pDashList = GetDoc()->GetDashList();
490
0
                    ::tools::Long       nCounts    = pDashList->Count ();
491
0
                    std::unique_ptr<XDashEntry> pEntry = std::make_unique<XDashEntry>(aNewDash, pName->GetValue());
492
0
                    ::tools::Long i;
493
494
0
                    for ( i = 0; i < nCounts; i++ )
495
0
                        if (pDashList->GetDash (i)->GetName () == pName->GetValue ())
496
0
                            break;
497
498
0
                    if (i < nCounts)
499
0
                        pDashList->Replace(std::move(pEntry), i);
500
0
                    else
501
0
                        pDashList->Insert(std::move(pEntry));
502
503
0
                    XLineDashItem aDashItem(pName->GetValue(), aNewDash);
504
0
                    aDashItem.SetWhich(XATTR_LINEDASH);
505
0
                    aAttr.Put(aDashItem);
506
0
                    XLineStyleItem aStyleItem(drawing::LineStyle_DASH);
507
0
                    aStyleItem.SetWhich(XATTR_LINESTYLE);
508
0
                    aAttr.Put(aStyleItem);
509
0
                    rBindings.Invalidate (SID_ATTR_LINE_DASH);
510
0
                    rBindings.Invalidate (SID_ATTR_FILL_STYLE);
511
0
                }
512
#if HAVE_FEATURE_SCRIPTING
513
                else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
514
#endif
515
0
                break;
516
0
            }
517
#if HAVE_FEATURE_SCRIPTING
518
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
519
#endif
520
0
            break;
521
522
        // configuration for gradients
523
0
        case SID_GRADIENT :
524
0
            if (pArgs && pArgs->Count () == 8)
525
0
            {
526
0
                const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
527
0
                const SfxUInt32Item* pStyle = rReq.GetArg<SfxUInt32Item>(ID_VAL_STYLE);
528
0
                const SfxUInt32Item* pAngle = rReq.GetArg<SfxUInt32Item>(ID_VAL_ANGLE);
529
0
                const SfxUInt32Item* pBorder = rReq.GetArg<SfxUInt32Item>(ID_VAL_BORDER);
530
0
                const SfxUInt32Item* pCenterX = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_X);
531
0
                const SfxUInt32Item* pCenterY = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_Y);
532
0
                const SfxUInt32Item* pStart = rReq.GetArg<SfxUInt32Item>(ID_VAL_STARTINTENS);
533
0
                const SfxUInt32Item* pEnd = rReq.GetArg<SfxUInt32Item>(ID_VAL_ENDINTENS);
534
0
                assert(pName && pStyle && pAngle && pBorder && pCenterX && pCenterY && pStart && pEnd && "must be present");
535
536
0
                if (CHECK_RANGE (sal_Int32(css::awt::GradientStyle_LINEAR), static_cast<sal_Int32>(pStyle->GetValue()), sal_Int32(css::awt::GradientStyle_RECT)) &&
537
0
                    CHECK_RANGE (0, static_cast<sal_Int32>(pAngle->GetValue ()), 360) &&
538
0
                    CHECK_RANGE (0, static_cast<sal_Int32>(pBorder->GetValue ()), 100) &&
539
0
                    CHECK_RANGE (0, static_cast<sal_Int32>(pCenterX->GetValue ()), 100) &&
540
0
                    CHECK_RANGE (0, static_cast<sal_Int32>(pCenterY->GetValue ()), 100) &&
541
0
                    CHECK_RANGE (0, static_cast<sal_Int32>(pStart->GetValue ()), 100) &&
542
0
                    CHECK_RANGE (0, static_cast<sal_Int32>(pEnd->GetValue ()), 100))
543
0
                {
544
0
                    aAttr.ClearItem (XATTR_FILLGRADIENT);
545
0
                    aAttr.ClearItem (XATTR_FILLSTYLE);
546
547
0
                    XGradientListRef pGradientList = GetDoc()->GetGradientList ();
548
0
                    ::tools::Long           nCounts        = pGradientList->Count ();
549
0
                    ::tools::Long i;
550
551
0
                    for ( i = 0; i < nCounts; i++ )
552
0
                    {
553
0
                        const XGradientEntry* pEntry = pGradientList->GetGradient(i);
554
555
0
                        if (pEntry->GetName () == pName->GetValue ())
556
0
                        {
557
0
                            basegfx::BGradient aGradient(pEntry->GetGradient());
558
559
0
                            aGradient.SetGradientStyle (static_cast<css::awt::GradientStyle>(pStyle->GetValue ()));
560
0
                            aGradient.SetAngle (Degree10(pAngle->GetValue () * 10));
561
0
                            aGradient.SetBorder (static_cast<short>(pBorder->GetValue ()));
562
0
                            aGradient.SetXOffset (static_cast<short>(pCenterX->GetValue ()));
563
0
                            aGradient.SetYOffset (static_cast<short>(pCenterY->GetValue ()));
564
0
                            aGradient.SetStartIntens (static_cast<short>(pStart->GetValue ()));
565
0
                            aGradient.SetEndIntens (static_cast<short>(pEnd->GetValue ()));
566
567
0
                            XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT);
568
0
                            aStyleItem.SetWhich(XATTR_FILLSTYLE);
569
0
                            aAttr.Put(aStyleItem);
570
0
                            XFillGradientItem aGradientItem(pName->GetValue (), aGradient);
571
0
                            aGradientItem.SetWhich(XATTR_FILLGRADIENT);
572
0
                            aAttr.Put(aGradientItem);
573
0
                            break;
574
0
                        }
575
0
                    }
576
577
0
                    if (i >= nCounts)
578
0
                    {
579
0
                        Color aBlack (0, 0, 0);
580
0
                        basegfx::BGradient aGradient (
581
0
                            basegfx::BColorStops(aBlack.getBColor(), aBlack.getBColor()),
582
0
                            static_cast<css::awt::GradientStyle>(pStyle->GetValue ()),
583
0
                            Degree10(pAngle->GetValue () * 10), static_cast<short>(pCenterX->GetValue ()),
584
0
                            static_cast<short>(pCenterY->GetValue ()), static_cast<short>(pBorder->GetValue ()),
585
0
                            static_cast<short>(pStart->GetValue ()), static_cast<short>(pEnd->GetValue ()));
586
587
0
                        pGradientList->Insert(std::make_unique<XGradientEntry>(aGradient, pName->GetValue()));
588
0
                        XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT);
589
0
                        aStyleItem.SetWhich(XATTR_FILLSTYLE);
590
0
                        aAttr.Put(aStyleItem);
591
0
                        XFillGradientItem aGradientItem(pName->GetValue (), aGradient);
592
0
                        aGradientItem.SetWhich(XATTR_FILLGRADIENT);
593
0
                        aAttr.Put(aGradientItem);
594
0
                    }
595
596
0
                    rBindings.Invalidate (SID_ATTR_FILL_GRADIENT);
597
0
                    rBindings.Invalidate (SID_ATTR_PAGE_GRADIENT);
598
0
                    rBindings.Invalidate (SID_ATTR_FILL_STYLE);
599
0
                    rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
600
0
                }
601
#if HAVE_FEATURE_SCRIPTING
602
                else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
603
#endif
604
0
                break;
605
0
            }
606
#if HAVE_FEATURE_SCRIPTING
607
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
608
#endif
609
0
            break;
610
611
        // configuration for hatch
612
0
        case SID_HATCH :
613
0
            if (pArgs && pArgs->Count () == 4)
614
0
            {
615
0
                const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
616
0
                const SfxUInt32Item* pStyle = rReq.GetArg<SfxUInt32Item>(ID_VAL_STYLE);
617
0
                const SfxUInt32Item* pDistance = rReq.GetArg<SfxUInt32Item>(ID_VAL_DISTANCE);
618
0
                const SfxUInt32Item* pAngle = rReq.GetArg<SfxUInt32Item>(ID_VAL_ANGLE);
619
0
                assert(pName && pStyle && pDistance && pAngle && "must be present");
620
621
0
                if (CHECK_RANGE (sal_Int32(css::drawing::HatchStyle_SINGLE), static_cast<sal_Int32>(pStyle->GetValue()), sal_Int32(css::drawing::HatchStyle_TRIPLE)) &&
622
0
                    CHECK_RANGE (0, static_cast<sal_Int32>(pAngle->GetValue ()), 360))
623
0
                {
624
0
                    aAttr.ClearItem (XATTR_FILLHATCH);
625
0
                    aAttr.ClearItem (XATTR_FILLSTYLE);
626
627
0
                    XHatchListRef pHatchList = GetDoc()->GetHatchList ();
628
0
                    ::tools::Long       nCounts     = pHatchList->Count ();
629
0
                    ::tools::Long i;
630
631
0
                    for ( i = 0; i < nCounts; i++ )
632
0
                    {
633
0
                        const XHatchEntry* pEntry = pHatchList->GetHatch(i);
634
635
0
                        if (pEntry->GetName () == pName->GetValue ())
636
0
                        {
637
0
                            XHatch aHatch(pEntry->GetHatch());
638
639
0
                            aHatch.SetHatchStyle (static_cast<css::drawing::HatchStyle>(pStyle->GetValue ()));
640
0
                            aHatch.SetDistance (pDistance->GetValue ());
641
0
                            aHatch.SetAngle (Degree10(pAngle->GetValue () * 10));
642
643
0
                            XFillStyleItem aStyleItem(drawing::FillStyle_HATCH);
644
0
                            aStyleItem.SetWhich(XATTR_FILLSTYLE);
645
0
                            aAttr.Put(aStyleItem);
646
0
                            XFillHatchItem aHatchItem(pName->GetValue (), aHatch);
647
0
                            aHatchItem.SetWhich(XATTR_FILLHATCH);
648
0
                            aAttr.Put(aHatchItem);
649
0
                            break;
650
0
                        }
651
0
                    }
652
653
0
                    if (i >= nCounts)
654
0
                    {
655
0
                        XHatch aHatch (Color(0), static_cast<css::drawing::HatchStyle>(pStyle->GetValue ()), pDistance->GetValue (),
656
0
                                       Degree10(pAngle->GetValue () * 10));
657
658
0
                        pHatchList->Insert(std::make_unique<XHatchEntry>(aHatch, pName->GetValue()));
659
0
                        XFillStyleItem aStyleItem(drawing::FillStyle_HATCH);
660
0
                        aStyleItem.SetWhich(XATTR_FILLSTYLE);
661
0
                        aAttr.Put(aStyleItem);
662
0
                        XFillHatchItem aHatchItem(pName->GetValue (), aHatch);
663
0
                        aHatchItem.SetWhich(XATTR_FILLHATCH);
664
0
                        aAttr.Put(aHatchItem);
665
0
                    }
666
667
0
                    rBindings.Invalidate (SID_ATTR_FILL_HATCH);
668
0
                    rBindings.Invalidate (SID_ATTR_FILL_STYLE);
669
0
                }
670
#if HAVE_FEATURE_SCRIPTING
671
                else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
672
#endif
673
0
                break;
674
0
            }
675
#if HAVE_FEATURE_SCRIPTING
676
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
677
#endif
678
0
            break;
679
680
0
        case SID_SELECTGRADIENT :
681
0
            if (pArgs && (pArgs->Count() == 1))
682
0
            {
683
0
                const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
684
0
                assert(pName && "must be present");
685
686
0
                XGradientListRef pGradientList = GetDoc()->GetGradientList ();
687
0
                ::tools::Long           nCounts        = pGradientList->Count ();
688
689
0
                for (::tools::Long i = 0; i < nCounts; i ++)
690
0
                {
691
0
                    const XGradientEntry* pEntry = pGradientList->GetGradient(i);
692
693
0
                    if (pEntry->GetName () == pName->GetValue ())
694
0
                    {
695
0
                        aAttr.ClearItem (XATTR_FILLGRADIENT);
696
0
                        aAttr.ClearItem (XATTR_FILLSTYLE);
697
0
                        XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT);
698
0
                        aStyleItem.SetWhich(XATTR_FILLSTYLE);
699
0
                        aAttr.Put(aStyleItem);
700
0
                        XFillGradientItem aGradientItem(pName->GetValue (), pEntry->GetGradient ());
701
0
                        aGradientItem.SetWhich(XATTR_FILLGRADIENT);
702
0
                        aAttr.Put(aGradientItem);
703
0
                        rBindings.Invalidate (SID_ATTR_FILL_GRADIENT);
704
0
                        rBindings.Invalidate (SID_ATTR_PAGE_GRADIENT);
705
0
                        rBindings.Invalidate (SID_ATTR_FILL_STYLE);
706
0
                        rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
707
0
                        break;
708
0
                    }
709
0
                }
710
711
0
                break;
712
0
            }
713
#if HAVE_FEATURE_SCRIPTING
714
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
715
#endif
716
0
            break;
717
718
0
        case SID_SELECTHATCH :
719
0
            if (pArgs && pArgs->Count() == 1)
720
0
            {
721
0
                const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
722
0
                assert(pName && "must be present");
723
724
0
                XHatchListRef pHatchList = GetDoc()->GetHatchList ();
725
0
                ::tools::Long       nCounts     = pHatchList->Count ();
726
727
0
                for (::tools::Long i = 0; i < nCounts; i ++)
728
0
                {
729
0
                    const XHatchEntry* pEntry = pHatchList->GetHatch(i);
730
731
0
                    if (pEntry->GetName () == pName->GetValue ())
732
0
                    {
733
0
                        aAttr.ClearItem (XATTR_FILLHATCH);
734
0
                        aAttr.ClearItem (XATTR_FILLSTYLE);
735
0
                        XFillStyleItem aStyleItem(drawing::FillStyle_HATCH);
736
0
                        aStyleItem.SetWhich(XATTR_FILLSTYLE);
737
0
                        aAttr.Put(aStyleItem);
738
0
                        XFillHatchItem aHatchItem(pName->GetValue (), pEntry->GetHatch ());
739
0
                        aHatchItem.SetWhich(XATTR_FILLHATCH);
740
0
                        aAttr.Put(aHatchItem);
741
742
0
                        rBindings.Invalidate (SID_ATTR_FILL_HATCH);
743
0
                        rBindings.Invalidate (SID_ATTR_PAGE_HATCH);
744
0
                        rBindings.Invalidate (SID_ATTR_FILL_STYLE);
745
0
                        rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
746
0
                        break;
747
0
                    }
748
0
                }
749
750
0
                break;
751
0
            }
752
#if HAVE_FEATURE_SCRIPTING
753
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
754
#endif
755
0
            break;
756
757
0
        case SID_UNSELECT :
758
0
            mpDrawView->UnmarkAll ();
759
0
            break;
760
761
0
        case SID_GETRED :
762
0
            if (pArgs && pArgs->Count () == 1)
763
0
            {
764
0
                break;
765
0
            }
766
#if HAVE_FEATURE_SCRIPTING
767
            StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
768
#endif
769
0
            break;
770
771
/*        case SID_SETFONTFAMILYNAME :
772
        case SID_SETFONTSTYLENAME :
773
        case SID_SETFONTFAMILY :
774
        case SID_SETFONTPITCH :
775
        case SID_SETFONTCHARSET :
776
        case SID_SETFONTPOSTURE :
777
        case SID_SETFONTWEIGHT :
778
        case SID_SETFONTUNDERLINE :
779
        case SID_SETFONTCROSSEDOUT :
780
        case SID_SETFONTSHADOWED :
781
        case SID_SETFONTCONTOUR :
782
        case SID_SETFONTCOLOR :
783
        case SID_SETFONTLANGUAGE :
784
        case SID_SETFONTWORDLINE :
785
        case SID_SETFONTCASEMAP :
786
        case SID_SETFONTESCAPE :
787
        case SID_SETFONTKERNING :
788
            break;*/
789
790
0
        default :
791
0
            ;
792
0
    }
793
794
0
    mpDrawView->SetAttributes (aAttr);
795
0
    rReq.Ignore ();
796
0
}
797
798
/**
799
 * Edit macros for attribute configuration
800
 */
801
void DrawViewShell::AttrState (SfxItemSet& rSet)
802
0
{
803
0
    SfxWhichIter     aIter (rSet);
804
0
    sal_uInt16           nWhich = aIter.FirstWhich ();
805
0
    SfxItemSet aAttr( GetDoc()->GetPool() );
806
0
    mpDrawView->GetAttributes( aAttr );
807
808
0
    while (nWhich)
809
0
    {
810
0
        switch (nWhich)
811
0
        {
812
0
            case SID_GETFILLSTYLE :
813
0
            {
814
0
                const XFillStyleItem &rFillStyleItem = aAttr.Get (XATTR_FILLSTYLE);
815
816
0
                rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>(rFillStyleItem.GetValue ())));
817
0
                break;
818
0
            }
819
820
0
            case SID_GETLINESTYLE :
821
0
            {
822
0
                const XLineStyleItem &rLineStyleItem = aAttr.Get (XATTR_LINESTYLE);
823
824
0
                rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>(rLineStyleItem.GetValue ())));
825
0
                break;
826
0
            }
827
828
0
            case SID_GETLINEWIDTH :
829
0
            {
830
0
                const XLineWidthItem &rLineWidthItem = aAttr.Get (XATTR_LINEWIDTH);
831
832
0
                rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>(rLineWidthItem.GetValue ())));
833
0
                break;
834
0
            }
835
836
0
            case SID_GETGREEN :
837
0
            case SID_GETRED :
838
0
            case SID_GETBLUE :
839
0
            {
840
0
                const SfxUInt32Item &rWhatKind = static_cast<const SfxUInt32Item &>( rSet.Get (ID_VAL_WHATKIND) );
841
0
                Color               aColor;
842
843
0
                switch (rWhatKind.GetValue ())
844
0
                {
845
0
                    case 1 :
846
0
                    {
847
0
                        const XLineColorItem &rLineColorItem = aAttr.Get (XATTR_LINECOLOR);
848
849
0
                        aColor = rLineColorItem.GetColorValue ();
850
0
                        break;
851
0
                    }
852
853
0
                    case 2 :
854
0
                    {
855
0
                        const XFillColorItem &rFillColorItem = aAttr.Get (XATTR_FILLCOLOR);
856
857
0
                        aColor = rFillColorItem.GetColorValue ();
858
0
                        break;
859
0
                    }
860
861
0
                    case 3 :
862
0
                    case 4 :
863
0
                    {
864
0
                        const XFillGradientItem &rFillGradientItem = aAttr.Get (XATTR_FILLGRADIENT);
865
0
                        const basegfx::BGradient &rGradient = rFillGradientItem.GetGradientValue ();
866
867
0
                        aColor = (rWhatKind.GetValue () == 3)
868
0
                                    ? Color(rGradient.GetColorStops().front().getStopColor())
869
0
                                    : Color(rGradient.GetColorStops().back().getStopColor());
870
0
                        break;
871
0
                    }
872
873
0
                    case 5:
874
0
                    {
875
0
                        const XFillHatchItem &rFillHatchItem = aAttr.Get (XATTR_FILLHATCH);
876
0
                        const XHatch         &rHatch         = rFillHatchItem.GetHatchValue ();
877
878
0
                        aColor = rHatch.GetColor ();
879
0
                        break;
880
0
                    }
881
882
0
                    default :
883
0
                        ;
884
0
                }
885
886
0
                rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>((nWhich == SID_GETRED)
887
0
                                                             ? aColor.GetRed ()
888
0
                                                             : (nWhich == SID_GETGREEN)
889
0
                                                                   ? aColor.GetGreen ()
890
0
                                                                   : aColor.GetBlue ())));
891
0
                break;
892
0
            }
893
894
0
            default :
895
0
                ;
896
0
        }
897
898
0
        nWhich = aIter.NextWhich ();
899
0
    }
900
0
}
901
902
} // end of namespace sd
903
904
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */