Update git submodules
[LibreOffice.git] / sd / source / ui / view / drviews9.cxx
blob9422ac4ca5cbe4c3790e8210a544b172f73e9f12
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <config_features.h>
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>
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>
46 #include <sfx2/viewfrm.hxx>
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>
56 #include <svx/galleryitem.hxx>
57 #include <com/sun/star/gallery/GalleryItemType.hpp>
58 #include <com/sun/star/drawing/LineStyle.hpp>
59 #include <memory>
61 using namespace com::sun::star;
63 namespace sd {
65 void DrawViewShell::ExecGallery(SfxRequest const & rReq)
67 // nothing is executed during a slide show!
68 if(HasCurrentFunction(SID_PRESENTATION))
69 return;
71 const SfxItemSet* pArgs = rReq.GetArgs();
73 const SvxGalleryItem* pGalleryItem = SfxItemSet::GetItem<SvxGalleryItem>(pArgs, SID_GALLERY_FORMATS, false);
74 if ( !pGalleryItem )
75 return;
77 GetDocSh()->SetWaitCursor( true );
79 sal_Int8 nType( pGalleryItem->GetType() );
80 // insert graphic
81 if (nType == css::gallery::GalleryItemType::GRAPHIC)
83 Graphic aGraphic( pGalleryItem->GetGraphic() );
85 // reduce size if necessary
86 ScopedVclPtrInstance< Window > aWindow(GetActiveWindow());
87 aWindow->SetMapMode(aGraphic.GetPrefMapMode());
88 Size aSizePix = aWindow->LogicToPixel(aGraphic.GetPrefSize());
89 aWindow->SetMapMode( MapMode(MapUnit::Map100thMM) );
90 Size aSize = aWindow->PixelToLogic(aSizePix);
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()) );
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() )
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());
107 // constrain size to page size if necessary
108 if ((fGrfWH != 0.F) && (fGrfWH < fWinWH))
110 aSize.setWidth( static_cast<::tools::Long>(aPageSize.Height() * fGrfWH) );
111 aSize.setHeight( aPageSize.Height() );
113 else
115 aSize.setWidth( aPageSize.Width() );
116 aSize.setHeight( static_cast<::tools::Long>(aPageSize.Width() / fGrfWH) );
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);
126 rtl::Reference<SdrGrafObj> pGrafObj;
128 bool bInsertNewObject = true;
130 const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
131 if ( rMarkList.GetMarkCount() != 0 )
133 // is there an empty graphic object?
134 if (rMarkList.GetMarkCount() == 1)
136 SdrMark* pMark = rMarkList.GetMark(0);
137 SdrObject* pObj = pMark->GetMarkedSdrObj();
139 if (pObj->GetObjInventor() == SdrInventor::Default && pObj->GetObjIdentifier() == SdrObjKind::Graphic)
141 pGrafObj = static_cast<SdrGrafObj*>(pObj);
143 if( pGrafObj->IsEmptyPresObj() )
145 // the empty graphic object gets a new graphic
146 bInsertNewObject = false;
148 rtl::Reference<SdrGrafObj> pNewGrafObj(SdrObject::Clone(*pGrafObj, pGrafObj->getSdrModelFromSdrObject()));
149 pNewGrafObj->SetEmptyPresObj(false);
150 pNewGrafObj->SetOutlinerParaObject(std::nullopt);
151 pNewGrafObj->SetGraphic(aGraphic);
153 OUString aStr = rMarkList.GetMarkDescription() +
154 " " + SdResId(STR_UNDO_REPLACE);
155 mpDrawView->BegUndo(aStr);
156 SdrPageView* pPV = mpDrawView->GetSdrPageView();
157 mpDrawView->ReplaceObjectAtView(pGrafObj.get(), *pPV, pNewGrafObj.get());
158 mpDrawView->EndUndo();
164 if( bInsertNewObject )
166 pGrafObj = new SdrGrafObj(
167 GetView()->getSdrModelFromSdrView(),
168 aGraphic,
169 aRect);
170 SdrPageView* pPV = mpDrawView->GetSdrPageView();
171 mpDrawView->InsertObjectAtView(pGrafObj.get(), *pPV, SdrInsertFlags::SETDEFLAYER);
174 // insert sound
175 else if( nType == css::gallery::GalleryItemType::MEDIA )
177 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, pGalleryItem->GetURL() );
178 GetViewFrame()->GetDispatcher()->ExecuteList(SID_INSERT_AVMEDIA,
179 SfxCallMode::SYNCHRON, { &aMediaURLItem });
182 GetDocSh()->SetWaitCursor( false );
186 * Edit macros for attribute configuration
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)
197 // nothing is executed during a slide show!
198 if(HasCurrentFunction(SID_PRESENTATION))
199 return;
201 CheckLineTo (rReq);
203 SfxBindings& rBindings = GetViewFrame()->GetBindings();
204 SfxItemSet aAttr( GetDoc()->GetPool() );
206 GetView()->GetAttributes( aAttr );
207 const SfxItemSet* pArgs = rReq.GetArgs();
209 switch (rReq.GetSlot ())
211 // set new fill-style
212 case SID_SETFILLSTYLE :
213 if (pArgs && pArgs->Count () == 1)
215 const SfxUInt32Item* pFillStyle = rReq.GetArg<SfxUInt32Item>(ID_VAL_STYLE);
216 if (CHECK_RANGE (drawing::FillStyle_NONE, static_cast<drawing::FillStyle>(pFillStyle->GetValue ()), drawing::FillStyle_BITMAP))
218 aAttr.ClearItem (XATTR_FILLSTYLE);
219 XFillStyleItem aStyleItem(static_cast<drawing::FillStyle>(pFillStyle->GetValue ()));
220 aStyleItem.SetWhich(XATTR_FILLSTYLE);
221 aAttr.Put (aStyleItem);
222 rBindings.Invalidate (SID_ATTR_FILL_STYLE);
223 rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
225 #if HAVE_FEATURE_SCRIPTING
226 else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
227 #endif
228 break;
230 #if HAVE_FEATURE_SCRIPTING
231 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
232 #endif
233 break;
235 // determine new line style
236 case SID_SETLINESTYLE :
237 if (pArgs && pArgs->Count () == 1)
239 const SfxUInt32Item* pLineStyle = rReq.GetArg<SfxUInt32Item>(ID_VAL_STYLE);
240 if (CHECK_RANGE (sal_Int32(drawing::LineStyle_NONE), static_cast<sal_Int32>(pLineStyle->GetValue()), sal_Int32(drawing::LineStyle_DASH)))
242 aAttr.ClearItem (XATTR_LINESTYLE);
243 XLineStyleItem aStyleItem(static_cast<drawing::LineStyle>(pLineStyle->GetValue()));
244 aStyleItem.SetWhich(XATTR_LINESTYLE);
245 aAttr.Put(aStyleItem);
246 rBindings.Invalidate (SID_ATTR_LINE_STYLE);
248 #if HAVE_FEATURE_SCRIPTING
249 else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
250 #endif
251 break;
253 #if HAVE_FEATURE_SCRIPTING
254 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
255 #endif
256 break;
258 // set line width
259 case SID_SETLINEWIDTH :
260 if (pArgs && pArgs->Count () == 1)
262 const SfxUInt32Item* pLineWidth = rReq.GetArg<SfxUInt32Item>(ID_VAL_WIDTH);
263 aAttr.ClearItem (XATTR_LINEWIDTH);
264 XLineWidthItem aWidthItem(pLineWidth->GetValue());
265 aWidthItem.SetWhich(XATTR_LINEWIDTH);
266 aAttr.Put(aWidthItem);
267 rBindings.Invalidate (SID_ATTR_LINE_WIDTH);
268 break;
270 #if HAVE_FEATURE_SCRIPTING
271 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
272 #endif
273 break;
275 case SID_SETFILLCOLOR :
276 if (pArgs && pArgs->Count () == 3)
278 const SfxUInt32Item* pRed = rReq.GetArg<SfxUInt32Item>(ID_VAL_RED);
279 const SfxUInt32Item* pGreen = rReq.GetArg<SfxUInt32Item>(ID_VAL_GREEN);
280 const SfxUInt32Item* pBlue = rReq.GetArg<SfxUInt32Item>(ID_VAL_BLUE);
282 aAttr.ClearItem (XATTR_FILLCOLOR);
283 aAttr.ClearItem (XATTR_FILLSTYLE);
284 XFillColorItem aColorItem(-1, Color (static_cast<sal_uInt8>(pRed->GetValue ()),
285 static_cast<sal_uInt8>(pGreen->GetValue ()),
286 static_cast<sal_uInt8>(pBlue->GetValue ())));
287 aColorItem.SetWhich(XATTR_FILLCOLOR);
288 aAttr.Put(aColorItem);
289 rBindings.Invalidate (SID_ATTR_FILL_COLOR);
290 rBindings.Invalidate (SID_ATTR_PAGE_COLOR);
291 rBindings.Invalidate (SID_ATTR_FILL_STYLE);
292 rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
293 break;
295 #if HAVE_FEATURE_SCRIPTING
296 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
297 #endif
298 break;
300 case SID_SETLINECOLOR :
301 if (pArgs && pArgs->Count () == 3)
303 const SfxUInt32Item* pRed = rReq.GetArg<SfxUInt32Item>(ID_VAL_RED);
304 const SfxUInt32Item* pGreen = rReq.GetArg<SfxUInt32Item>(ID_VAL_GREEN);
305 const SfxUInt32Item* pBlue = rReq.GetArg<SfxUInt32Item>(ID_VAL_BLUE);
307 aAttr.ClearItem (XATTR_LINECOLOR);
308 XLineColorItem aColorItem(-1, Color(static_cast<sal_uInt8>(pRed->GetValue()),
309 static_cast<sal_uInt8>(pGreen->GetValue()),
310 static_cast<sal_uInt8>(pBlue->GetValue())));
311 aColorItem.SetWhich(XATTR_LINECOLOR);
312 aAttr.Put(aColorItem);
313 rBindings.Invalidate (SID_ATTR_LINE_COLOR);
314 break;
316 #if HAVE_FEATURE_SCRIPTING
317 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
318 #endif
319 break;
321 case SID_SETGRADSTARTCOLOR :
322 case SID_SETGRADENDCOLOR :
323 if (pArgs && pArgs->Count () == 4)
325 const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
326 const SfxUInt32Item* pRed = rReq.GetArg<SfxUInt32Item>(ID_VAL_RED);
327 const SfxUInt32Item* pGreen = rReq.GetArg<SfxUInt32Item>(ID_VAL_GREEN);
328 const SfxUInt32Item* pBlue = rReq.GetArg<SfxUInt32Item>(ID_VAL_BLUE);
329 assert(pName && pRed && pGreen && pBlue && "must be present");
331 XGradientListRef pGradientList = GetDoc()->GetGradientList ();
332 ::tools::Long nCounts = pGradientList->Count ();
333 Color aColor (static_cast<sal_uInt8>(pRed->GetValue ()),
334 static_cast<sal_uInt8>(pGreen->GetValue ()),
335 static_cast<sal_uInt8>(pBlue->GetValue ()));
336 ::tools::Long i;
338 aAttr.ClearItem (XATTR_FILLGRADIENT);
339 aAttr.ClearItem (XATTR_FILLSTYLE);
341 for ( i = 0; i < nCounts; i ++)
343 const XGradientEntry* pEntry = pGradientList->GetGradient(i);
345 if (pEntry->GetName () == pName->GetValue ())
347 basegfx::BGradient aGradient(pEntry->GetGradient());
348 basegfx::BColorStops aNewColorStops(aGradient.GetColorStops());
350 if (SID_SETGRADSTARTCOLOR == rReq.GetSlot ())
352 aNewColorStops.replaceStartColor(aColor.getBColor());
354 else
356 aNewColorStops.replaceEndColor(aColor.getBColor());
359 aGradient.SetColorStops(aNewColorStops);
361 XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT);
362 aStyleItem.SetWhich(XATTR_FILLSTYLE);
363 aAttr.Put(aStyleItem);
364 XFillGradientItem aGradientItem(pName->GetValue (), aGradient);
365 aGradientItem.SetWhich(XATTR_FILLGRADIENT);
366 aAttr.Put(aGradientItem);
367 break;
371 if (i >= nCounts)
373 Color aBlack (0, 0, 0);
374 basegfx::BGradient aGradient (
375 basegfx::BColorStops(
376 (rReq.GetSlot () == SID_SETGRADSTARTCOLOR)
377 ? aColor.getBColor()
378 : aBlack.getBColor(),
379 (rReq.GetSlot () == SID_SETGRADENDCOLOR)
380 ? aColor.getBColor()
381 : aBlack.getBColor()));
383 GetDoc()->GetGradientList()->Insert(std::make_unique<XGradientEntry>(aGradient, pName->GetValue()));
385 XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT);
386 aStyleItem.SetWhich(XATTR_FILLSTYLE);
387 aAttr.Put(aStyleItem);
388 XFillGradientItem aGradientItem(pName->GetValue(), aGradient);
389 aGradientItem.SetWhich(XATTR_FILLGRADIENT);
390 aAttr.Put(aGradientItem);
393 rBindings.Invalidate (SID_ATTR_FILL_STYLE);
394 rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
395 rBindings.Invalidate (SID_ATTR_FILL_GRADIENT);
396 rBindings.Invalidate (SID_ATTR_PAGE_GRADIENT);
397 break;
399 #if HAVE_FEATURE_SCRIPTING
400 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
401 #endif
402 break;
404 case SID_SETHATCHCOLOR :
405 if (pArgs && pArgs->Count () == 4)
407 const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
408 const SfxUInt32Item* pRed = rReq.GetArg<SfxUInt32Item>(ID_VAL_RED);
409 const SfxUInt32Item* pGreen = rReq.GetArg<SfxUInt32Item>(ID_VAL_GREEN);
410 const SfxUInt32Item* pBlue = rReq.GetArg<SfxUInt32Item>(ID_VAL_BLUE);
411 assert(pName && pRed && pGreen && pBlue && "must be present");
413 XHatchListRef pHatchList = GetDoc()->GetHatchList ();
414 ::tools::Long nCounts = pHatchList->Count ();
415 Color aColor (static_cast<sal_uInt8>(pRed->GetValue ()),
416 static_cast<sal_uInt8>(pGreen->GetValue ()),
417 static_cast<sal_uInt8>(pBlue->GetValue ()));
418 ::tools::Long i;
420 aAttr.ClearItem (XATTR_FILLHATCH);
421 aAttr.ClearItem (XATTR_FILLSTYLE);
423 for ( i = 0; i < nCounts; i ++)
425 const XHatchEntry* pEntry = pHatchList->GetHatch(i);
427 if (pEntry->GetName () == pName->GetValue ())
429 XHatch aHatch(pEntry->GetHatch());
431 aHatch.SetColor (aColor);
433 XFillStyleItem aStyleItem(drawing::FillStyle_HATCH);
434 aStyleItem.SetWhich(XATTR_FILLSTYLE);
435 aAttr.Put(aStyleItem);
436 XFillHatchItem aHatchItem(pName->GetValue(), aHatch);
437 aHatchItem.SetWhich(XATTR_FILLHATCH);
438 aAttr.Put(aHatchItem);
439 break;
443 if (i >= nCounts)
445 XHatch aHatch (aColor);
447 GetDoc()->GetHatchList()->Insert(std::make_unique<XHatchEntry>(aHatch, pName->GetValue()));
449 XFillStyleItem aStyleItem(drawing::FillStyle_HATCH);
450 aStyleItem.SetWhich(XATTR_FILLSTYLE);
451 aAttr.Put(aStyleItem);
452 XFillHatchItem aHatchItem(pName->GetValue (), aHatch);
453 aHatchItem.SetWhich(XATTR_FILLHATCH);
454 aAttr.Put(aHatchItem);
457 rBindings.Invalidate (SID_ATTR_FILL_HATCH);
458 rBindings.Invalidate (SID_ATTR_PAGE_HATCH);
459 rBindings.Invalidate (SID_ATTR_FILL_STYLE);
460 rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
461 break;
463 #if HAVE_FEATURE_SCRIPTING
464 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
465 #endif
466 break;
468 // configuration for line-dash
469 case SID_DASH :
470 if (pArgs && pArgs->Count () == 7)
472 const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
473 const SfxUInt32Item* pStyle = rReq.GetArg<SfxUInt32Item>(ID_VAL_STYLE);
474 const SfxUInt32Item* pDots = rReq.GetArg<SfxUInt32Item>(ID_VAL_DOTS);
475 const SfxUInt32Item* pDotLen = rReq.GetArg<SfxUInt32Item>(ID_VAL_DOTLEN);
476 const SfxUInt32Item* pDashes = rReq.GetArg<SfxUInt32Item>(ID_VAL_DASHES);
477 const SfxUInt32Item* pDashLen = rReq.GetArg<SfxUInt32Item>(ID_VAL_DASHLEN);
478 const SfxUInt32Item* pDistance = rReq.GetArg<SfxUInt32Item>(ID_VAL_DISTANCE);
479 assert(pName && pStyle && pDots && pDotLen && pDashes && pDashLen && pDistance && "must be present");
481 if (CHECK_RANGE (sal_Int32(css::drawing::DashStyle_RECT), static_cast<sal_Int32>(pStyle->GetValue()), sal_Int32(css::drawing::DashStyle_ROUNDRELATIVE)))
483 XDash aNewDash (static_cast<css::drawing::DashStyle>(pStyle->GetValue ()), static_cast<short>(pDots->GetValue ()), pDotLen->GetValue (),
484 static_cast<short>(pDashes->GetValue ()), pDashLen->GetValue (), pDistance->GetValue ());
486 aAttr.ClearItem (XATTR_LINEDASH);
487 aAttr.ClearItem (XATTR_LINESTYLE);
489 XDashListRef pDashList = GetDoc()->GetDashList();
490 ::tools::Long nCounts = pDashList->Count ();
491 std::unique_ptr<XDashEntry> pEntry = std::make_unique<XDashEntry>(aNewDash, pName->GetValue());
492 ::tools::Long i;
494 for ( i = 0; i < nCounts; i++ )
495 if (pDashList->GetDash (i)->GetName () == pName->GetValue ())
496 break;
498 if (i < nCounts)
499 pDashList->Replace(std::move(pEntry), i);
500 else
501 pDashList->Insert(std::move(pEntry));
503 XLineDashItem aDashItem(pName->GetValue(), aNewDash);
504 aDashItem.SetWhich(XATTR_LINEDASH);
505 aAttr.Put(aDashItem);
506 XLineStyleItem aStyleItem(drawing::LineStyle_DASH);
507 aStyleItem.SetWhich(XATTR_LINESTYLE);
508 aAttr.Put(aStyleItem);
509 rBindings.Invalidate (SID_ATTR_LINE_DASH);
510 rBindings.Invalidate (SID_ATTR_FILL_STYLE);
512 #if HAVE_FEATURE_SCRIPTING
513 else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
514 #endif
515 break;
517 #if HAVE_FEATURE_SCRIPTING
518 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
519 #endif
520 break;
522 // configuration for gradients
523 case SID_GRADIENT :
524 if (pArgs && pArgs->Count () == 8)
526 const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
527 const SfxUInt32Item* pStyle = rReq.GetArg<SfxUInt32Item>(ID_VAL_STYLE);
528 const SfxUInt32Item* pAngle = rReq.GetArg<SfxUInt32Item>(ID_VAL_ANGLE);
529 const SfxUInt32Item* pBorder = rReq.GetArg<SfxUInt32Item>(ID_VAL_BORDER);
530 const SfxUInt32Item* pCenterX = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_X);
531 const SfxUInt32Item* pCenterY = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_Y);
532 const SfxUInt32Item* pStart = rReq.GetArg<SfxUInt32Item>(ID_VAL_STARTINTENS);
533 const SfxUInt32Item* pEnd = rReq.GetArg<SfxUInt32Item>(ID_VAL_ENDINTENS);
534 assert(pName && pStyle && pAngle && pBorder && pCenterX && pCenterY && pStart && pEnd && "must be present");
536 if (CHECK_RANGE (sal_Int32(css::awt::GradientStyle_LINEAR), static_cast<sal_Int32>(pStyle->GetValue()), sal_Int32(css::awt::GradientStyle_RECT)) &&
537 CHECK_RANGE (0, static_cast<sal_Int32>(pAngle->GetValue ()), 360) &&
538 CHECK_RANGE (0, static_cast<sal_Int32>(pBorder->GetValue ()), 100) &&
539 CHECK_RANGE (0, static_cast<sal_Int32>(pCenterX->GetValue ()), 100) &&
540 CHECK_RANGE (0, static_cast<sal_Int32>(pCenterY->GetValue ()), 100) &&
541 CHECK_RANGE (0, static_cast<sal_Int32>(pStart->GetValue ()), 100) &&
542 CHECK_RANGE (0, static_cast<sal_Int32>(pEnd->GetValue ()), 100))
544 aAttr.ClearItem (XATTR_FILLGRADIENT);
545 aAttr.ClearItem (XATTR_FILLSTYLE);
547 XGradientListRef pGradientList = GetDoc()->GetGradientList ();
548 ::tools::Long nCounts = pGradientList->Count ();
549 ::tools::Long i;
551 for ( i = 0; i < nCounts; i++ )
553 const XGradientEntry* pEntry = pGradientList->GetGradient(i);
555 if (pEntry->GetName () == pName->GetValue ())
557 basegfx::BGradient aGradient(pEntry->GetGradient());
559 aGradient.SetGradientStyle (static_cast<css::awt::GradientStyle>(pStyle->GetValue ()));
560 aGradient.SetAngle (Degree10(pAngle->GetValue () * 10));
561 aGradient.SetBorder (static_cast<short>(pBorder->GetValue ()));
562 aGradient.SetXOffset (static_cast<short>(pCenterX->GetValue ()));
563 aGradient.SetYOffset (static_cast<short>(pCenterY->GetValue ()));
564 aGradient.SetStartIntens (static_cast<short>(pStart->GetValue ()));
565 aGradient.SetEndIntens (static_cast<short>(pEnd->GetValue ()));
567 XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT);
568 aStyleItem.SetWhich(XATTR_FILLSTYLE);
569 aAttr.Put(aStyleItem);
570 XFillGradientItem aGradientItem(pName->GetValue (), aGradient);
571 aGradientItem.SetWhich(XATTR_FILLGRADIENT);
572 aAttr.Put(aGradientItem);
573 break;
577 if (i >= nCounts)
579 Color aBlack (0, 0, 0);
580 basegfx::BGradient aGradient (
581 basegfx::BColorStops(aBlack.getBColor(), aBlack.getBColor()),
582 static_cast<css::awt::GradientStyle>(pStyle->GetValue ()),
583 Degree10(pAngle->GetValue () * 10), static_cast<short>(pCenterX->GetValue ()),
584 static_cast<short>(pCenterY->GetValue ()), static_cast<short>(pBorder->GetValue ()),
585 static_cast<short>(pStart->GetValue ()), static_cast<short>(pEnd->GetValue ()));
587 pGradientList->Insert(std::make_unique<XGradientEntry>(aGradient, pName->GetValue()));
588 XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT);
589 aStyleItem.SetWhich(XATTR_FILLSTYLE);
590 aAttr.Put(aStyleItem);
591 XFillGradientItem aGradientItem(pName->GetValue (), aGradient);
592 aGradientItem.SetWhich(XATTR_FILLGRADIENT);
593 aAttr.Put(aGradientItem);
596 rBindings.Invalidate (SID_ATTR_FILL_GRADIENT);
597 rBindings.Invalidate (SID_ATTR_PAGE_GRADIENT);
598 rBindings.Invalidate (SID_ATTR_FILL_STYLE);
599 rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
601 #if HAVE_FEATURE_SCRIPTING
602 else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
603 #endif
604 break;
606 #if HAVE_FEATURE_SCRIPTING
607 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
608 #endif
609 break;
611 // configuration for hatch
612 case SID_HATCH :
613 if (pArgs && pArgs->Count () == 4)
615 const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
616 const SfxUInt32Item* pStyle = rReq.GetArg<SfxUInt32Item>(ID_VAL_STYLE);
617 const SfxUInt32Item* pDistance = rReq.GetArg<SfxUInt32Item>(ID_VAL_DISTANCE);
618 const SfxUInt32Item* pAngle = rReq.GetArg<SfxUInt32Item>(ID_VAL_ANGLE);
619 assert(pName && pStyle && pDistance && pAngle && "must be present");
621 if (CHECK_RANGE (sal_Int32(css::drawing::HatchStyle_SINGLE), static_cast<sal_Int32>(pStyle->GetValue()), sal_Int32(css::drawing::HatchStyle_TRIPLE)) &&
622 CHECK_RANGE (0, static_cast<sal_Int32>(pAngle->GetValue ()), 360))
624 aAttr.ClearItem (XATTR_FILLHATCH);
625 aAttr.ClearItem (XATTR_FILLSTYLE);
627 XHatchListRef pHatchList = GetDoc()->GetHatchList ();
628 ::tools::Long nCounts = pHatchList->Count ();
629 ::tools::Long i;
631 for ( i = 0; i < nCounts; i++ )
633 const XHatchEntry* pEntry = pHatchList->GetHatch(i);
635 if (pEntry->GetName () == pName->GetValue ())
637 XHatch aHatch(pEntry->GetHatch());
639 aHatch.SetHatchStyle (static_cast<css::drawing::HatchStyle>(pStyle->GetValue ()));
640 aHatch.SetDistance (pDistance->GetValue ());
641 aHatch.SetAngle (Degree10(pAngle->GetValue () * 10));
643 XFillStyleItem aStyleItem(drawing::FillStyle_HATCH);
644 aStyleItem.SetWhich(XATTR_FILLSTYLE);
645 aAttr.Put(aStyleItem);
646 XFillHatchItem aHatchItem(pName->GetValue (), aHatch);
647 aHatchItem.SetWhich(XATTR_FILLHATCH);
648 aAttr.Put(aHatchItem);
649 break;
653 if (i >= nCounts)
655 XHatch aHatch (Color(0), static_cast<css::drawing::HatchStyle>(pStyle->GetValue ()), pDistance->GetValue (),
656 Degree10(pAngle->GetValue () * 10));
658 pHatchList->Insert(std::make_unique<XHatchEntry>(aHatch, pName->GetValue()));
659 XFillStyleItem aStyleItem(drawing::FillStyle_HATCH);
660 aStyleItem.SetWhich(XATTR_FILLSTYLE);
661 aAttr.Put(aStyleItem);
662 XFillHatchItem aHatchItem(pName->GetValue (), aHatch);
663 aHatchItem.SetWhich(XATTR_FILLHATCH);
664 aAttr.Put(aHatchItem);
667 rBindings.Invalidate (SID_ATTR_FILL_HATCH);
668 rBindings.Invalidate (SID_ATTR_FILL_STYLE);
670 #if HAVE_FEATURE_SCRIPTING
671 else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
672 #endif
673 break;
675 #if HAVE_FEATURE_SCRIPTING
676 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
677 #endif
678 break;
680 case SID_SELECTGRADIENT :
681 if (pArgs && (pArgs->Count() == 1))
683 const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
684 assert(pName && "must be present");
686 XGradientListRef pGradientList = GetDoc()->GetGradientList ();
687 ::tools::Long nCounts = pGradientList->Count ();
689 for (::tools::Long i = 0; i < nCounts; i ++)
691 const XGradientEntry* pEntry = pGradientList->GetGradient(i);
693 if (pEntry->GetName () == pName->GetValue ())
695 aAttr.ClearItem (XATTR_FILLGRADIENT);
696 aAttr.ClearItem (XATTR_FILLSTYLE);
697 XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT);
698 aStyleItem.SetWhich(XATTR_FILLSTYLE);
699 aAttr.Put(aStyleItem);
700 XFillGradientItem aGradientItem(pName->GetValue (), pEntry->GetGradient ());
701 aGradientItem.SetWhich(XATTR_FILLGRADIENT);
702 aAttr.Put(aGradientItem);
703 rBindings.Invalidate (SID_ATTR_FILL_GRADIENT);
704 rBindings.Invalidate (SID_ATTR_PAGE_GRADIENT);
705 rBindings.Invalidate (SID_ATTR_FILL_STYLE);
706 rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
707 break;
711 break;
713 #if HAVE_FEATURE_SCRIPTING
714 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
715 #endif
716 break;
718 case SID_SELECTHATCH :
719 if (pArgs && pArgs->Count() == 1)
721 const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
722 assert(pName && "must be present");
724 XHatchListRef pHatchList = GetDoc()->GetHatchList ();
725 ::tools::Long nCounts = pHatchList->Count ();
727 for (::tools::Long i = 0; i < nCounts; i ++)
729 const XHatchEntry* pEntry = pHatchList->GetHatch(i);
731 if (pEntry->GetName () == pName->GetValue ())
733 aAttr.ClearItem (XATTR_FILLHATCH);
734 aAttr.ClearItem (XATTR_FILLSTYLE);
735 XFillStyleItem aStyleItem(drawing::FillStyle_HATCH);
736 aStyleItem.SetWhich(XATTR_FILLSTYLE);
737 aAttr.Put(aStyleItem);
738 XFillHatchItem aHatchItem(pName->GetValue (), pEntry->GetHatch ());
739 aHatchItem.SetWhich(XATTR_FILLHATCH);
740 aAttr.Put(aHatchItem);
742 rBindings.Invalidate (SID_ATTR_FILL_HATCH);
743 rBindings.Invalidate (SID_ATTR_PAGE_HATCH);
744 rBindings.Invalidate (SID_ATTR_FILL_STYLE);
745 rBindings.Invalidate (SID_ATTR_PAGE_FILLSTYLE);
746 break;
750 break;
752 #if HAVE_FEATURE_SCRIPTING
753 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
754 #endif
755 break;
757 case SID_UNSELECT :
758 mpDrawView->UnmarkAll ();
759 break;
761 case SID_GETRED :
762 if (pArgs && pArgs->Count () == 1)
764 break;
766 #if HAVE_FEATURE_SCRIPTING
767 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
768 #endif
769 break;
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;*/
790 default :
794 mpDrawView->SetAttributes (const_cast<const SfxItemSet &>(aAttr));
795 rReq.Ignore ();
799 * Edit macros for attribute configuration
801 void DrawViewShell::AttrState (SfxItemSet& rSet)
803 SfxWhichIter aIter (rSet);
804 sal_uInt16 nWhich = aIter.FirstWhich ();
805 SfxItemSet aAttr( GetDoc()->GetPool() );
806 mpDrawView->GetAttributes( aAttr );
808 while (nWhich)
810 switch (nWhich)
812 case SID_GETFILLSTYLE :
814 const XFillStyleItem &rFillStyleItem = aAttr.Get (XATTR_FILLSTYLE);
816 rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>(rFillStyleItem.GetValue ())));
817 break;
820 case SID_GETLINESTYLE :
822 const XLineStyleItem &rLineStyleItem = aAttr.Get (XATTR_LINESTYLE);
824 rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>(rLineStyleItem.GetValue ())));
825 break;
828 case SID_GETLINEWIDTH :
830 const XLineWidthItem &rLineWidthItem = aAttr.Get (XATTR_LINEWIDTH);
832 rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>(rLineWidthItem.GetValue ())));
833 break;
836 case SID_GETGREEN :
837 case SID_GETRED :
838 case SID_GETBLUE :
840 const SfxUInt32Item &rWhatKind = static_cast<const SfxUInt32Item &>( rSet.Get (ID_VAL_WHATKIND) );
841 Color aColor;
843 switch (rWhatKind.GetValue ())
845 case 1 :
847 const XLineColorItem &rLineColorItem = aAttr.Get (XATTR_LINECOLOR);
849 aColor = rLineColorItem.GetColorValue ();
850 break;
853 case 2 :
855 const XFillColorItem &rFillColorItem = aAttr.Get (XATTR_FILLCOLOR);
857 aColor = rFillColorItem.GetColorValue ();
858 break;
861 case 3 :
862 case 4 :
864 const XFillGradientItem &rFillGradientItem = aAttr.Get (XATTR_FILLGRADIENT);
865 const basegfx::BGradient &rGradient = rFillGradientItem.GetGradientValue ();
867 aColor = (rWhatKind.GetValue () == 3)
868 ? Color(rGradient.GetColorStops().front().getStopColor())
869 : Color(rGradient.GetColorStops().back().getStopColor());
870 break;
873 case 5:
875 const XFillHatchItem &rFillHatchItem = aAttr.Get (XATTR_FILLHATCH);
876 const XHatch &rHatch = rFillHatchItem.GetHatchValue ();
878 aColor = rHatch.GetColor ();
879 break;
882 default :
886 rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>((nWhich == SID_GETRED)
887 ? aColor.GetRed ()
888 : (nWhich == SID_GETGREEN)
889 ? aColor.GetGreen ()
890 : aColor.GetBlue ())));
891 break;
894 default :
898 nWhich = aIter.NextWhich ();
902 } // end of namespace sd
904 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */