android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / view / drviews9.cxx
blob1ae793e4d60abee0bb22d02ce902c0eaf9e2a6fb
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 if ( mpDrawView->AreObjectsMarked() )
132 // is there an empty graphic object?
133 const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
135 if (rMarkList.GetMarkCount() == 1)
137 SdrMark* pMark = rMarkList.GetMark(0);
138 SdrObject* pObj = pMark->GetMarkedSdrObj();
140 if (pObj->GetObjInventor() == SdrInventor::Default && pObj->GetObjIdentifier() == SdrObjKind::Graphic)
142 pGrafObj = static_cast<SdrGrafObj*>(pObj);
144 if( pGrafObj->IsEmptyPresObj() )
146 // the empty graphic object gets a new graphic
147 bInsertNewObject = false;
149 rtl::Reference<SdrGrafObj> pNewGrafObj(SdrObject::Clone(*pGrafObj, pGrafObj->getSdrModelFromSdrObject()));
150 pNewGrafObj->SetEmptyPresObj(false);
151 pNewGrafObj->SetOutlinerParaObject(std::nullopt);
152 pNewGrafObj->SetGraphic(aGraphic);
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();
165 if( bInsertNewObject )
167 pGrafObj = new SdrGrafObj(
168 GetView()->getSdrModelFromSdrView(),
169 aGraphic,
170 aRect);
171 SdrPageView* pPV = mpDrawView->GetSdrPageView();
172 mpDrawView->InsertObjectAtView(pGrafObj.get(), *pPV, SdrInsertFlags::SETDEFLAYER);
175 // insert sound
176 else if( nType == css::gallery::GalleryItemType::MEDIA )
178 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, pGalleryItem->GetURL() );
179 GetViewFrame()->GetDispatcher()->ExecuteList(SID_INSERT_AVMEDIA,
180 SfxCallMode::SYNCHRON, { &aMediaURLItem });
183 GetDocSh()->SetWaitCursor( false );
187 * Edit macros for attribute configuration
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 */
196 void DrawViewShell::AttrExec (SfxRequest &rReq)
198 // nothing is executed during a slide show!
199 if(HasCurrentFunction(SID_PRESENTATION))
200 return;
202 CheckLineTo (rReq);
204 SfxBindings& rBindings = GetViewFrame()->GetBindings();
205 SfxItemSet aAttr( GetDoc()->GetPool() );
207 GetView()->GetAttributes( aAttr );
208 const SfxItemSet* pArgs = rReq.GetArgs();
210 switch (rReq.GetSlot ())
212 // set new fill-style
213 case SID_SETFILLSTYLE :
214 if (pArgs && pArgs->Count () == 1)
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))
219 aAttr.ClearItem (XATTR_FILLSTYLE);
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);
226 #if HAVE_FEATURE_SCRIPTING
227 else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
228 #endif
229 break;
231 #if HAVE_FEATURE_SCRIPTING
232 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
233 #endif
234 break;
236 // determine new line style
237 case SID_SETLINESTYLE :
238 if (pArgs && pArgs->Count () == 1)
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)))
243 aAttr.ClearItem (XATTR_LINESTYLE);
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);
249 #if HAVE_FEATURE_SCRIPTING
250 else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
251 #endif
252 break;
254 #if HAVE_FEATURE_SCRIPTING
255 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
256 #endif
257 break;
259 // set line width
260 case SID_SETLINEWIDTH :
261 if (pArgs && pArgs->Count () == 1)
263 const SfxUInt32Item* pLineWidth = rReq.GetArg<SfxUInt32Item>(ID_VAL_WIDTH);
264 aAttr.ClearItem (XATTR_LINEWIDTH);
265 XLineWidthItem aWidthItem(pLineWidth->GetValue());
266 aWidthItem.SetWhich(XATTR_LINEWIDTH);
267 aAttr.Put(aWidthItem);
268 rBindings.Invalidate (SID_ATTR_LINE_WIDTH);
269 break;
271 #if HAVE_FEATURE_SCRIPTING
272 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
273 #endif
274 break;
276 case SID_SETFILLCOLOR :
277 if (pArgs && pArgs->Count () == 3)
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);
283 aAttr.ClearItem (XATTR_FILLCOLOR);
284 aAttr.ClearItem (XATTR_FILLSTYLE);
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;
296 #if HAVE_FEATURE_SCRIPTING
297 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
298 #endif
299 break;
301 case SID_SETLINECOLOR :
302 if (pArgs && pArgs->Count () == 3)
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);
308 aAttr.ClearItem (XATTR_LINECOLOR);
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;
317 #if HAVE_FEATURE_SCRIPTING
318 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
319 #endif
320 break;
322 case SID_SETGRADSTARTCOLOR :
323 case SID_SETGRADENDCOLOR :
324 if (pArgs && pArgs->Count () == 4)
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");
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 ()));
337 ::tools::Long i;
339 aAttr.ClearItem (XATTR_FILLGRADIENT);
340 aAttr.ClearItem (XATTR_FILLSTYLE);
342 for ( i = 0; i < nCounts; i ++)
344 const XGradientEntry* pEntry = pGradientList->GetGradient(i);
346 if (pEntry->GetName () == pName->GetValue ())
348 basegfx::BGradient aGradient(pEntry->GetGradient());
349 basegfx::BColorStops aNewColorStops(aGradient.GetColorStops());
351 if (SID_SETGRADSTARTCOLOR == rReq.GetSlot ())
353 aNewColorStops.replaceStartColor(aColor.getBColor());
355 else
357 aNewColorStops.replaceEndColor(aColor.getBColor());
360 aGradient.SetColorStops(aNewColorStops);
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;
372 if (i >= nCounts)
374 Color aBlack (0, 0, 0);
375 basegfx::BGradient aGradient (
376 basegfx::BColorStops(
377 (rReq.GetSlot () == SID_SETGRADSTARTCOLOR)
378 ? aColor.getBColor()
379 : aBlack.getBColor(),
380 (rReq.GetSlot () == SID_SETGRADENDCOLOR)
381 ? aColor.getBColor()
382 : aBlack.getBColor()));
384 GetDoc()->GetGradientList()->Insert(std::make_unique<XGradientEntry>(aGradient, pName->GetValue()));
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);
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;
400 #if HAVE_FEATURE_SCRIPTING
401 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
402 #endif
403 break;
405 case SID_SETHATCHCOLOR :
406 if (pArgs && pArgs->Count () == 4)
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");
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 ()));
419 ::tools::Long i;
421 aAttr.ClearItem (XATTR_FILLHATCH);
422 aAttr.ClearItem (XATTR_FILLSTYLE);
424 for ( i = 0; i < nCounts; i ++)
426 const XHatchEntry* pEntry = pHatchList->GetHatch(i);
428 if (pEntry->GetName () == pName->GetValue ())
430 XHatch aHatch(pEntry->GetHatch());
432 aHatch.SetColor (aColor);
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;
444 if (i >= nCounts)
446 XHatch aHatch (aColor);
448 GetDoc()->GetHatchList()->Insert(std::make_unique<XHatchEntry>(aHatch, pName->GetValue()));
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);
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;
464 #if HAVE_FEATURE_SCRIPTING
465 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
466 #endif
467 break;
469 // configuration for line-dash
470 case SID_DASH :
471 if (pArgs && pArgs->Count () == 7)
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");
482 if (CHECK_RANGE (sal_Int32(css::drawing::DashStyle_RECT), static_cast<sal_Int32>(pStyle->GetValue()), sal_Int32(css::drawing::DashStyle_ROUNDRELATIVE)))
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 ());
487 aAttr.ClearItem (XATTR_LINEDASH);
488 aAttr.ClearItem (XATTR_LINESTYLE);
490 XDashListRef pDashList = GetDoc()->GetDashList();
491 ::tools::Long nCounts = pDashList->Count ();
492 std::unique_ptr<XDashEntry> pEntry = std::make_unique<XDashEntry>(aNewDash, pName->GetValue());
493 ::tools::Long i;
495 for ( i = 0; i < nCounts; i++ )
496 if (pDashList->GetDash (i)->GetName () == pName->GetValue ())
497 break;
499 if (i < nCounts)
500 pDashList->Replace(std::move(pEntry), i);
501 else
502 pDashList->Insert(std::move(pEntry));
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);
513 #if HAVE_FEATURE_SCRIPTING
514 else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
515 #endif
516 break;
518 #if HAVE_FEATURE_SCRIPTING
519 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
520 #endif
521 break;
523 // configuration for gradients
524 case SID_GRADIENT :
525 if (pArgs && pArgs->Count () == 8)
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");
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))
545 aAttr.ClearItem (XATTR_FILLGRADIENT);
546 aAttr.ClearItem (XATTR_FILLSTYLE);
548 XGradientListRef pGradientList = GetDoc()->GetGradientList ();
549 ::tools::Long nCounts = pGradientList->Count ();
550 ::tools::Long i;
552 for ( i = 0; i < nCounts; i++ )
554 const XGradientEntry* pEntry = pGradientList->GetGradient(i);
556 if (pEntry->GetName () == pName->GetValue ())
558 basegfx::BGradient aGradient(pEntry->GetGradient());
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 ()));
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;
578 if (i >= nCounts)
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 ()));
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);
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);
602 #if HAVE_FEATURE_SCRIPTING
603 else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
604 #endif
605 break;
607 #if HAVE_FEATURE_SCRIPTING
608 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
609 #endif
610 break;
612 // configuration for hatch
613 case SID_HATCH :
614 if (pArgs && pArgs->Count () == 4)
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");
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))
625 aAttr.ClearItem (XATTR_FILLHATCH);
626 aAttr.ClearItem (XATTR_FILLSTYLE);
628 XHatchListRef pHatchList = GetDoc()->GetHatchList ();
629 ::tools::Long nCounts = pHatchList->Count ();
630 ::tools::Long i;
632 for ( i = 0; i < nCounts; i++ )
634 const XHatchEntry* pEntry = pHatchList->GetHatch(i);
636 if (pEntry->GetName () == pName->GetValue ())
638 XHatch aHatch(pEntry->GetHatch());
640 aHatch.SetHatchStyle (static_cast<css::drawing::HatchStyle>(pStyle->GetValue ()));
641 aHatch.SetDistance (pDistance->GetValue ());
642 aHatch.SetAngle (Degree10(pAngle->GetValue () * 10));
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;
654 if (i >= nCounts)
656 XHatch aHatch (Color(0), static_cast<css::drawing::HatchStyle>(pStyle->GetValue ()), pDistance->GetValue (),
657 Degree10(pAngle->GetValue () * 10));
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);
668 rBindings.Invalidate (SID_ATTR_FILL_HATCH);
669 rBindings.Invalidate (SID_ATTR_FILL_STYLE);
671 #if HAVE_FEATURE_SCRIPTING
672 else StarBASIC::FatalError (ERRCODE_BASIC_BAD_PROP_VALUE);
673 #endif
674 break;
676 #if HAVE_FEATURE_SCRIPTING
677 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
678 #endif
679 break;
681 case SID_SELECTGRADIENT :
682 if (pArgs && (pArgs->Count() == 1))
684 const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
685 assert(pName && "must be present");
687 XGradientListRef pGradientList = GetDoc()->GetGradientList ();
688 ::tools::Long nCounts = pGradientList->Count ();
690 for (::tools::Long i = 0; i < nCounts; i ++)
692 const XGradientEntry* pEntry = pGradientList->GetGradient(i);
694 if (pEntry->GetName () == pName->GetValue ())
696 aAttr.ClearItem (XATTR_FILLGRADIENT);
697 aAttr.ClearItem (XATTR_FILLSTYLE);
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;
712 break;
714 #if HAVE_FEATURE_SCRIPTING
715 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
716 #endif
717 break;
719 case SID_SELECTHATCH :
720 if (pArgs && pArgs->Count() == 1)
722 const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(ID_VAL_INDEX);
723 assert(pName && "must be present");
725 XHatchListRef pHatchList = GetDoc()->GetHatchList ();
726 ::tools::Long nCounts = pHatchList->Count ();
728 for (::tools::Long i = 0; i < nCounts; i ++)
730 const XHatchEntry* pEntry = pHatchList->GetHatch(i);
732 if (pEntry->GetName () == pName->GetValue ())
734 aAttr.ClearItem (XATTR_FILLHATCH);
735 aAttr.ClearItem (XATTR_FILLSTYLE);
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);
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;
751 break;
753 #if HAVE_FEATURE_SCRIPTING
754 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
755 #endif
756 break;
758 case SID_UNSELECT :
759 mpDrawView->UnmarkAll ();
760 break;
762 case SID_GETRED :
763 if (pArgs && pArgs->Count () == 1)
765 break;
767 #if HAVE_FEATURE_SCRIPTING
768 StarBASIC::FatalError (ERRCODE_BASIC_WRONG_ARGS);
769 #endif
770 break;
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;*/
791 default :
795 mpDrawView->SetAttributes (const_cast<const SfxItemSet &>(aAttr));
796 rReq.Ignore ();
800 * Edit macros for attribute configuration
802 void DrawViewShell::AttrState (SfxItemSet& rSet)
804 SfxWhichIter aIter (rSet);
805 sal_uInt16 nWhich = aIter.FirstWhich ();
806 SfxItemSet aAttr( GetDoc()->GetPool() );
807 mpDrawView->GetAttributes( aAttr );
809 while (nWhich)
811 switch (nWhich)
813 case SID_GETFILLSTYLE :
815 const XFillStyleItem &rFillStyleItem = aAttr.Get (XATTR_FILLSTYLE);
817 rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>(rFillStyleItem.GetValue ())));
818 break;
821 case SID_GETLINESTYLE :
823 const XLineStyleItem &rLineStyleItem = aAttr.Get (XATTR_LINESTYLE);
825 rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>(rLineStyleItem.GetValue ())));
826 break;
829 case SID_GETLINEWIDTH :
831 const XLineWidthItem &rLineWidthItem = aAttr.Get (XATTR_LINEWIDTH);
833 rSet.Put (SfxUInt32Item (nWhich, static_cast<::tools::Long>(rLineWidthItem.GetValue ())));
834 break;
837 case SID_GETGREEN :
838 case SID_GETRED :
839 case SID_GETBLUE :
841 const SfxUInt32Item &rWhatKind = static_cast<const SfxUInt32Item &>( rSet.Get (ID_VAL_WHATKIND) );
842 Color aColor;
844 switch (rWhatKind.GetValue ())
846 case 1 :
848 const XLineColorItem &rLineColorItem = aAttr.Get (XATTR_LINECOLOR);
850 aColor = rLineColorItem.GetColorValue ();
851 break;
854 case 2 :
856 const XFillColorItem &rFillColorItem = aAttr.Get (XATTR_FILLCOLOR);
858 aColor = rFillColorItem.GetColorValue ();
859 break;
862 case 3 :
863 case 4 :
865 const XFillGradientItem &rFillGradientItem = aAttr.Get (XATTR_FILLGRADIENT);
866 const basegfx::BGradient &rGradient = rFillGradientItem.GetGradientValue ();
868 aColor = (rWhatKind.GetValue () == 3)
869 ? Color(rGradient.GetColorStops().front().getStopColor())
870 : Color(rGradient.GetColorStops().back().getStopColor());
871 break;
874 case 5:
876 const XFillHatchItem &rFillHatchItem = aAttr.Get (XATTR_FILLHATCH);
877 const XHatch &rHatch = rFillHatchItem.GetHatchValue ();
879 aColor = rHatch.GetColor ();
880 break;
883 default :
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;
895 default :
899 nWhich = aIter.NextWhich ();
903 } // end of namespace sd
905 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */