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