Get the style color and number just once
[LibreOffice.git] / sd / source / ui / func / fuconrec.cxx
blob45abc8058d8208cdcff14d817967e2135a0ef049
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 <fuconrec.hxx>
21 #include <svx/svdpagv.hxx>
23 #include <svx/svxids.hrc>
24 #include <svx/strings.hrc>
25 #include <svx/dialmgr.hxx>
27 #include <app.hrc>
28 #include <svl/itemset.hxx>
29 #include <svx/constructhelper.hxx>
30 #include <svx/xlineit0.hxx>
31 #include <svx/xlnstwit.hxx>
32 #include <svx/xlnedwit.hxx>
33 #include <svx/xlnedit.hxx>
34 #include <svx/xlnstit.hxx>
35 #include <svx/xlnwtit.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <svx/sdtmfitm.hxx>
38 #include <svx/sxekitm.hxx>
39 #include <svx/sderitm.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <svx/svdopath.hxx>
42 #include <svx/svdocirc.hxx>
43 #include <svl/intitem.hxx>
44 #include <sfx2/request.hxx>
45 #include <editeng/adjustitem.hxx>
46 #include <editeng/eeitem.hxx>
47 #include <svx/xtable.hxx>
48 #include <svx/xfltrit.hxx>
49 #include <svx/xflclit.hxx>
50 #include <svx/sdtagitm.hxx>
51 #include <svx/sdtditm.hxx>
53 #include <svx/svdocapt.hxx>
55 #include <svx/svdomeas.hxx>
56 #include <ViewShell.hxx>
57 #include <ViewShellBase.hxx>
58 #include <ToolBarManager.hxx>
59 #include <editeng/writingmodeitem.hxx>
60 #include <basegfx/polygon/b2dpolygontools.hxx>
61 #include <basegfx/polygon/b2dpolygon.hxx>
62 #include <svx/xfillit0.hxx>
63 #include <svx/signaturelinehelper.hxx>
64 #include <osl/diagnose.h>
66 #include <sdresid.hxx>
67 #include <View.hxx>
68 #include <sdpage.hxx>
69 #include <Window.hxx>
70 #include <drawdoc.hxx>
71 #include <unokywds.hxx>
73 #include <strings.hrc>
75 using namespace com::sun::star;
77 namespace sd {
80 FuConstructRectangle::FuConstructRectangle (
81 ViewShell* pViewSh,
82 ::sd::Window* pWin,
83 ::sd::View* pView,
84 SdDrawDocument* pDoc,
85 SfxRequest& rReq)
86 : FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
87 , mnFillTransparence(0)
88 , mnLineStyle(SAL_MAX_UINT16)
92 namespace{
94 /// Checks to see if the request has a parameter of IsSticky:bool=true
95 /// It means that the selected command/button will stay selected after use
96 bool isSticky(const SfxRequest& rReq)
98 const SfxItemSet *pArgs = rReq.GetArgs ();
99 if (pArgs)
101 const SfxBoolItem* pIsSticky = rReq.GetArg<SfxBoolItem>(FN_PARAM_4);
102 if (pIsSticky && pIsSticky->GetValue())
103 return true;
106 return false;
111 rtl::Reference<FuPoor> FuConstructRectangle::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
113 FuConstructRectangle* pFunc;
114 rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructRectangle( pViewSh, pWin, pView, pDoc, rReq ) );
115 xFunc->DoExecute(rReq);
116 pFunc->SetPermanent(bPermanent || isSticky(rReq));
117 return xFunc;
120 void FuConstructRectangle::DoExecute( SfxRequest& rReq )
122 FuConstruct::DoExecute( rReq );
124 mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
125 ToolBarManager::ToolBarGroup::Function,
126 ToolBarManager::msDrawingObjectToolBar);
128 const SfxItemSet *pArgs = rReq.GetArgs ();
130 if (pArgs)
132 switch (nSlotId)
134 case SID_DRAW_ELLIPSE :
136 const SfxUInt32Item* pCenterX = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_X);
137 const SfxUInt32Item* pCenterY = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_Y);
138 const SfxUInt32Item* pAxisX = rReq.GetArg<SfxUInt32Item>(ID_VAL_AXIS_X);
139 const SfxUInt32Item* pAxisY = rReq.GetArg<SfxUInt32Item>(ID_VAL_AXIS_Y);
141 if (!pCenterX || !pCenterY || !pAxisX || !pAxisY)
142 break;
144 ::tools::Rectangle aNewRectangle (pCenterX->GetValue () - pAxisX->GetValue () / 2,
145 pCenterY->GetValue () - pAxisY->GetValue () / 2,
146 pCenterX->GetValue () + pAxisX->GetValue () / 2,
147 pCenterY->GetValue () + pAxisY->GetValue () / 2);
148 rtl::Reference<SdrCircObj> pNewCircle = new SdrCircObj(
149 mpView->getSdrModelFromSdrView(),
150 SdrCircKind::Full,
151 aNewRectangle);
152 SdrPageView *pPV = mpView->GetSdrPageView();
154 mpView->InsertObjectAtView(pNewCircle.get(), *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
156 break;
158 case SID_DRAW_RECT :
160 const SfxUInt32Item* pMouseStartX = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSESTART_X);
161 const SfxUInt32Item* pMouseStartY = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSESTART_Y);
162 const SfxUInt32Item* pMouseEndX = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSEEND_X);
163 const SfxUInt32Item* pMouseEndY = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSEEND_Y);
164 const SfxUInt16Item* pFillTransparence = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
165 const SfxStringItem* pFillColor = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
166 const SfxUInt16Item* pLineStyle = rReq.GetArg<SfxUInt16Item>(FN_PARAM_3);
167 const SfxStringItem* pShapeName = rReq.GetArg<SfxStringItem>(SID_SHAPE_NAME);
169 if (pFillTransparence && pFillTransparence->GetValue() > 0)
171 mnFillTransparence = pFillTransparence->GetValue();
173 if (pFillColor && !pFillColor->GetValue().isEmpty())
175 msFillColor = pFillColor->GetValue();
177 if (pLineStyle)
179 mnLineStyle = pLineStyle->GetValue();
181 if (pShapeName && !pShapeName->GetValue().isEmpty())
183 msShapeName = pShapeName->GetValue();
186 if (!pMouseStartX || !pMouseStartY || !pMouseEndX || !pMouseEndY)
187 break;
189 ::tools::Rectangle aNewRectangle (pMouseStartX->GetValue (),
190 pMouseStartY->GetValue (),
191 pMouseEndX->GetValue (),
192 pMouseEndY->GetValue ());
193 rtl::Reference<SdrRectObj> pNewRect = new SdrRectObj(
194 mpView->getSdrModelFromSdrView(),
195 aNewRectangle);
196 SdrPageView *pPV = mpView->GetSdrPageView();
198 mpView->InsertObjectAtView(pNewRect.get(), *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
200 break;
204 if (nSlotId == SID_TOOL_CONNECTOR ||
205 nSlotId == SID_CONNECTOR_ARROW_START ||
206 nSlotId == SID_CONNECTOR_ARROW_END ||
207 nSlotId == SID_CONNECTOR_ARROWS ||
208 nSlotId == SID_CONNECTOR_CIRCLE_START ||
209 nSlotId == SID_CONNECTOR_CIRCLE_END ||
210 nSlotId == SID_CONNECTOR_CIRCLES ||
211 nSlotId == SID_CONNECTOR_LINE ||
212 nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
213 nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
214 nSlotId == SID_CONNECTOR_LINE_ARROWS ||
215 nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
216 nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
217 nSlotId == SID_CONNECTOR_LINE_CIRCLES ||
218 nSlotId == SID_CONNECTOR_CURVE ||
219 nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
220 nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
221 nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
222 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
223 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
224 nSlotId == SID_CONNECTOR_CURVE_CIRCLES ||
225 nSlotId == SID_CONNECTOR_LINES ||
226 nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
227 nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
228 nSlotId == SID_CONNECTOR_LINES_ARROWS ||
229 nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
230 nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
231 nSlotId == SID_CONNECTOR_LINES_CIRCLES ||
232 nSlotId == SID_LINE_ARROW_START ||
233 nSlotId == SID_LINE_ARROW_END ||
234 nSlotId == SID_LINE_ARROWS ||
235 nSlotId == SID_LINE_ARROW_CIRCLE ||
236 nSlotId == SID_LINE_CIRCLE_ARROW ||
237 nSlotId == SID_LINE_ARROW_SQUARE ||
238 nSlotId == SID_LINE_SQUARE_ARROW )
240 mpView->UnmarkAll();
244 bool FuConstructRectangle::MouseButtonDown(const MouseEvent& rMEvt)
246 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
248 if ( rMEvt.IsLeft() && !mpView->IsAction() )
250 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
252 mpWindow->CaptureMouse();
253 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(mpView->GetDragThresholdPixels(),0)).Width() );
255 if (mpView->GetCurrentObjIdentifier() == SdrObjKind::Caption)
257 Size aCaptionSize(846, 846); // (4x2)cm
258 bReturn = mpView->BegCreateCaptionObj(aPnt, aCaptionSize,
259 nullptr, nDrgLog);
261 else
263 mpView->BegCreateObj(aPnt, nullptr, nDrgLog);
266 SdrObject* pObj = mpView->GetCreateObj();
268 if (pObj)
270 SfxItemSet aAttr(mpDoc->GetPool());
271 SetStyleSheet(aAttr, pObj);
272 SetAttributes(aAttr, pObj);
273 SetLineEnds(aAttr, *pObj);
274 pObj->SetMergedItemSet(aAttr);
276 if( nSlotId == SID_DRAW_CAPTION_VERTICAL )
277 static_cast<SdrTextObj*>(pObj)->SetVerticalWriting( true );
280 return bReturn;
283 bool FuConstructRectangle::MouseButtonUp(const MouseEvent& rMEvt)
285 if (rMEvt.IsLeft() && IsIgnoreUnexpectedMouseButtonUp())
286 return false;
288 bool bReturn(false);
290 if(mpView->IsCreateObj() && rMEvt.IsLeft())
292 SdrObject* pObj = mpView->GetCreateObj();
294 if(pObj && mpView->EndCreateObj(SdrCreateCmd::ForceEnd))
296 if(SID_DRAW_MEASURELINE == nSlotId)
298 SdrLayerAdmin& rAdmin = mpDoc->GetLayerAdmin();
299 pObj->SetLayer(rAdmin.GetLayerID(sUNO_LayerName_measurelines));
302 // init text position when vertical caption object is created
303 if( dynamic_cast< const SdrCaptionObj *>( pObj ) != nullptr && SID_DRAW_CAPTION_VERTICAL == nSlotId)
305 // draw text object, needs to be initialized when vertical text is used
306 SfxItemSet aSet(pObj->GetMergedItemSet());
308 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
309 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
311 // Correct the value of SDRATTR_TEXTDIRECTION to avoid SetItemSet
312 // calling SetVerticalWriting() again since this item may not yet
313 // be set at the object and thus may differ from vertical state of
314 // the object.
315 aSet.Put(SvxWritingModeItem(css::text::WritingMode_TB_RL, SDRATTR_TEXTDIRECTION));
316 pObj->SetMergedItemSet(aSet);
319 bReturn = true;
321 else
323 //Drag was too small to create object, so insert default object at click pos
324 Point aClickPos(mpWindow->PixelToLogic(rMEvt.GetPosPixel()));
325 sal_uInt32 nDefaultObjectSize(1500);
326 sal_Int32 nCenterOffset(-sal_Int32(nDefaultObjectSize / 2));
327 aClickPos.AdjustX(nCenterOffset);
328 aClickPos.AdjustY(nCenterOffset);
330 SdrPageView *pPV = mpView->GetSdrPageView();
331 if(mpView->IsSnapEnabled())
332 aClickPos = mpView->GetSnapPos(aClickPos, pPV);
334 ::tools::Rectangle aNewObjectRectangle(aClickPos, Size(nDefaultObjectSize, nDefaultObjectSize));
335 rtl::Reference<SdrObject> pObjDefault = CreateDefaultObject(nSlotId, aNewObjectRectangle);
337 bReturn = mpView->InsertObjectAtView(pObjDefault.get(), *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
341 bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
343 if (!bPermanent)
344 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
346 return bReturn;
349 void FuConstructRectangle::Activate()
351 SdrObjKind aObjKind;
353 switch (nSlotId)
355 case SID_LINE_ARROW_START:
356 case SID_LINE_ARROW_END:
357 case SID_LINE_ARROWS:
358 case SID_LINE_ARROW_CIRCLE:
359 case SID_LINE_CIRCLE_ARROW:
360 case SID_LINE_ARROW_SQUARE:
361 case SID_LINE_SQUARE_ARROW:
362 mpView->SetGlueVisible();
363 [[fallthrough]];
364 case SID_DRAW_LINE :
365 case SID_DRAW_XLINE:
366 aObjKind = SdrObjKind::Line;
367 break;
369 case SID_DRAW_MEASURELINE:
371 aObjKind = SdrObjKind::Measure;
373 break;
375 case SID_DRAW_RECT :
376 case SID_DRAW_RECT_NOFILL :
377 case SID_DRAW_RECT_ROUND :
378 case SID_DRAW_RECT_ROUND_NOFILL:
379 case SID_DRAW_SQUARE :
380 case SID_DRAW_SQUARE_NOFILL :
381 case SID_DRAW_SQUARE_ROUND :
382 case SID_DRAW_SQUARE_ROUND_NOFILL:
384 aObjKind = SdrObjKind::Rectangle;
386 break;
388 case SID_DRAW_ELLIPSE :
389 case SID_DRAW_ELLIPSE_NOFILL:
390 case SID_DRAW_CIRCLE :
391 case SID_DRAW_CIRCLE_NOFILL :
393 aObjKind = SdrObjKind::CircleOrEllipse;
395 break;
397 case SID_DRAW_CAPTION:
398 case SID_DRAW_CAPTION_VERTICAL:
400 aObjKind = SdrObjKind::Caption;
402 break;
404 case SID_TOOL_CONNECTOR:
405 case SID_CONNECTOR_ARROW_START:
406 case SID_CONNECTOR_ARROW_END:
407 case SID_CONNECTOR_ARROWS:
408 case SID_CONNECTOR_CIRCLE_START:
409 case SID_CONNECTOR_CIRCLE_END:
410 case SID_CONNECTOR_CIRCLES:
411 case SID_CONNECTOR_LINE:
412 case SID_CONNECTOR_LINE_ARROW_START:
413 case SID_CONNECTOR_LINE_ARROW_END:
414 case SID_CONNECTOR_LINE_ARROWS:
415 case SID_CONNECTOR_LINE_CIRCLE_START:
416 case SID_CONNECTOR_LINE_CIRCLE_END:
417 case SID_CONNECTOR_LINE_CIRCLES:
418 case SID_CONNECTOR_CURVE:
419 case SID_CONNECTOR_CURVE_ARROW_START:
420 case SID_CONNECTOR_CURVE_ARROW_END:
421 case SID_CONNECTOR_CURVE_ARROWS:
422 case SID_CONNECTOR_CURVE_CIRCLE_START:
423 case SID_CONNECTOR_CURVE_CIRCLE_END:
424 case SID_CONNECTOR_CURVE_CIRCLES:
425 case SID_CONNECTOR_LINES:
426 case SID_CONNECTOR_LINES_ARROW_START:
427 case SID_CONNECTOR_LINES_ARROW_END:
428 case SID_CONNECTOR_LINES_ARROWS:
429 case SID_CONNECTOR_LINES_CIRCLE_START:
430 case SID_CONNECTOR_LINES_CIRCLE_END:
431 case SID_CONNECTOR_LINES_CIRCLES:
433 aObjKind = SdrObjKind::Edge;
434 mpView->SetGlueVisible();
436 break;
437 case SID_INSERT_SIGNATURELINE:
439 aObjKind = SdrObjKind::Graphic;
441 break;
443 default:
445 aObjKind = SdrObjKind::Rectangle;
447 break;
450 mpView->SetCurrentObj(aObjKind);
452 FuConstruct::Activate();
455 void FuConstructRectangle::Deactivate()
457 if( nSlotId == SID_TOOL_CONNECTOR ||
458 nSlotId == SID_CONNECTOR_ARROW_START ||
459 nSlotId == SID_CONNECTOR_ARROW_END ||
460 nSlotId == SID_CONNECTOR_ARROWS ||
461 nSlotId == SID_CONNECTOR_CIRCLE_START ||
462 nSlotId == SID_CONNECTOR_CIRCLE_END ||
463 nSlotId == SID_CONNECTOR_CIRCLES ||
464 nSlotId == SID_CONNECTOR_LINE ||
465 nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
466 nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
467 nSlotId == SID_CONNECTOR_LINE_ARROWS ||
468 nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
469 nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
470 nSlotId == SID_CONNECTOR_LINE_CIRCLES ||
471 nSlotId == SID_CONNECTOR_CURVE ||
472 nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
473 nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
474 nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
475 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
476 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
477 nSlotId == SID_CONNECTOR_CURVE_CIRCLES ||
478 nSlotId == SID_CONNECTOR_LINES ||
479 nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
480 nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
481 nSlotId == SID_CONNECTOR_LINES_ARROWS ||
482 nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
483 nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
484 nSlotId == SID_CONNECTOR_LINES_CIRCLES ||
485 nSlotId == SID_LINE_ARROW_START ||
486 nSlotId == SID_LINE_ARROW_END ||
487 nSlotId == SID_LINE_ARROWS ||
488 nSlotId == SID_LINE_ARROW_CIRCLE ||
489 nSlotId == SID_LINE_CIRCLE_ARROW ||
490 nSlotId == SID_LINE_ARROW_SQUARE ||
491 nSlotId == SID_LINE_SQUARE_ARROW )
493 mpView->SetGlueVisible( false );
495 FuConstruct::Deactivate();
497 if (nSlotId != SID_INSERT_SIGNATURELINE)
499 return;
502 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
503 if (rMarkList.GetMarkCount() < 1)
505 // Just switching pages, no signature rectangle yet.
506 return;
509 // Finished drawing a signature rectangle, now set it up.
510 if (!mpViewShell)
512 return;
515 uno::Reference<security::XCertificate> xCertificate
516 = svx::SignatureLineHelper::getSignatureCertificate(mpViewShell->GetObjectShell(),
517 mpViewShell->GetFrameWeld());
518 if (!xCertificate.is())
520 return;
523 svx::SignatureLineHelper::setShapeCertificate(mpView, xCertificate);
525 // Update infobar to offer "finish signing".
526 SfxViewFrame* pFrame = mpViewShell->GetViewFrame();
527 if (pFrame && pFrame->HasInfoBarWithID(u"readonly"))
529 pFrame->RemoveInfoBar(u"readonly");
530 pFrame->AppendReadOnlyInfobar();
534 namespace {
535 /// Returns the color based on the color names listed in core/include/tools/color.hxx
536 /// Feel free to extend with more color names from color.hxx
537 Color strToColor(std::u16string_view sColor)
539 Color aColor = COL_AUTO;
541 if (sColor == u"COL_GRAY")
542 aColor = COL_GRAY;
543 else if (sColor == u"COL_GRAY3")
544 aColor = COL_GRAY3;
545 else if (sColor == u"COL_GRAY7")
546 aColor = COL_GRAY7;
548 return aColor;
553 * set attribute for the object to be created
555 void FuConstructRectangle::SetAttributes(SfxItemSet& rAttr, SdrObject* pObj)
557 if (nSlotId == SID_DRAW_RECT_ROUND ||
558 nSlotId == SID_DRAW_RECT_ROUND_NOFILL ||
559 nSlotId == SID_DRAW_SQUARE_ROUND ||
560 nSlotId == SID_DRAW_SQUARE_ROUND_NOFILL)
562 // round corner
563 rAttr.Put(makeSdrEckenradiusItem(500));
565 else if (nSlotId == SID_CONNECTOR_LINE ||
566 nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
567 nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
568 nSlotId == SID_CONNECTOR_LINE_ARROWS ||
569 nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
570 nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
571 nSlotId == SID_CONNECTOR_LINE_CIRCLES)
573 // direct connector
574 rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::OneLine));
576 else if (nSlotId == SID_CONNECTOR_LINES ||
577 nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
578 nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
579 nSlotId == SID_CONNECTOR_LINES_ARROWS ||
580 nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
581 nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
582 nSlotId == SID_CONNECTOR_LINES_CIRCLES)
584 // line connector
585 rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::ThreeLines));
587 else if (nSlotId == SID_CONNECTOR_CURVE ||
588 nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
589 nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
590 nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
591 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
592 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
593 nSlotId == SID_CONNECTOR_CURVE_CIRCLES)
595 // curve connector
596 rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::Bezier));
598 else if ( nSlotId == SID_DRAW_CAPTION || nSlotId == SID_DRAW_CAPTION_VERTICAL )
600 // legend object
601 Size aSize(pObj->GetLogicRect().GetSize());
602 rAttr.Put( makeSdrTextMinFrameHeightItem( aSize.Height() ) );
603 rAttr.Put( makeSdrTextMinFrameWidthItem( aSize.Width() ) );
604 rAttr.Put( makeSdrTextAutoGrowHeightItem( true ) );
605 rAttr.Put( makeSdrTextAutoGrowWidthItem( true ) );
607 // Support full with for vertical caption objects, too
608 if(SID_DRAW_CAPTION == nSlotId)
609 rAttr.Put( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
610 else
611 rAttr.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_BLOCK ) );
613 rAttr.Put( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
614 rAttr.Put( makeSdrTextLeftDistItem( 100 ) );
615 rAttr.Put( makeSdrTextRightDistItem( 100 ) );
616 rAttr.Put( makeSdrTextUpperDistItem( 100 ) );
617 rAttr.Put( makeSdrTextLowerDistItem( 100 ) );
619 else if (nSlotId == SID_DRAW_MEASURELINE)
621 // dimension line
622 SdPage* pPage = static_cast<SdPage*>( mpView->GetSdrPageView()->GetPage() );
623 OUString aName(SdResId(STR_POOLSHEET_MEASURE));
624 SfxStyleSheet* pSheet(
625 static_cast< SfxStyleSheet* >(
626 pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Para)));
627 DBG_ASSERT(pSheet, "StyleSheet missing");
629 if (pSheet)
631 pObj->SetStyleSheet(pSheet, false);
634 SdrLayerAdmin& rAdmin = mpDoc->GetLayerAdmin();
635 pObj->SetLayer(rAdmin.GetLayerID(sUNO_LayerName_measurelines));
637 else if (nSlotId == SID_DRAW_RECT)
639 if (mnFillTransparence > 0 && mnFillTransparence <= 100)
640 rAttr.Put(XFillTransparenceItem(mnFillTransparence));
641 if (!msFillColor.isEmpty())
642 rAttr.Put(XFillColorItem(OUString(), strToColor(msFillColor)));
643 if (!msShapeName.isEmpty())
644 pObj->SetName(msShapeName);
646 switch(mnLineStyle)
648 case 0:
649 rAttr.Put( XLineStyleItem(css::drawing::LineStyle_NONE ) );
650 break;
651 case 1:
652 rAttr.Put( XLineStyleItem(css::drawing::LineStyle_SOLID ) );
653 break;
654 case 2:
655 rAttr.Put( XLineStyleItem(css::drawing::LineStyle_DASH ) );
656 break;
657 default:
658 // Leave it to the defaults
659 break;
662 else if (nSlotId == SID_INSERT_SIGNATURELINE)
664 // Avoid the default solid fill and line, we'll set a graphic instead.
665 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
666 rAttr.Put(XLineStyleItem(drawing::LineStyle_NONE));
671 * set line starts and ends for the object to be created
673 void FuConstructRectangle::SetLineEnds(SfxItemSet& rAttr, SdrObject const & rObj)
675 if ( !((rObj.GetObjIdentifier() == SdrObjKind::Edge &&
676 nSlotId != SID_TOOL_CONNECTOR &&
677 nSlotId != SID_CONNECTOR_LINE &&
678 nSlotId != SID_CONNECTOR_LINES &&
679 nSlotId != SID_CONNECTOR_CURVE) ||
680 nSlotId == SID_LINE_ARROW_START ||
681 nSlotId == SID_LINE_ARROW_END ||
682 nSlotId == SID_LINE_ARROWS ||
683 nSlotId == SID_LINE_ARROW_CIRCLE ||
684 nSlotId == SID_LINE_CIRCLE_ARROW ||
685 nSlotId == SID_LINE_ARROW_SQUARE ||
686 nSlotId == SID_LINE_SQUARE_ARROW) )
687 return;
689 // set attributes of line start and ends
690 SdrModel& rModel(rObj.getSdrModelFromSdrObject());
692 // arrowhead
693 ::basegfx::B2DPolyPolygon aArrow(ConstructHelper::GetLineEndPoly(RID_SVXSTR_ARROW, rModel));
694 if( !aArrow.count() )
696 ::basegfx::B2DPolygon aNewArrow;
697 aNewArrow.append(::basegfx::B2DPoint(10.0, 0.0));
698 aNewArrow.append(::basegfx::B2DPoint(0.0, 30.0));
699 aNewArrow.append(::basegfx::B2DPoint(20.0, 30.0));
700 aNewArrow.setClosed(true);
701 aArrow.append(aNewArrow);
704 // Circles
705 ::basegfx::B2DPolyPolygon aCircle(ConstructHelper::GetLineEndPoly(RID_SVXSTR_CIRCLE, rModel));
706 if( !aCircle.count() )
708 ::basegfx::B2DPolygon aNewCircle = ::basegfx::utils::createPolygonFromEllipse(::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0);
709 aNewCircle.setClosed(true);
710 aCircle.append(aNewCircle);
713 // Square
714 ::basegfx::B2DPolyPolygon aSquare(ConstructHelper::GetLineEndPoly(RID_SVXSTR_SQUARE, rModel));
715 if( !aSquare.count() )
717 ::basegfx::B2DPolygon aNewSquare;
718 aNewSquare.append(::basegfx::B2DPoint(0.0, 0.0));
719 aNewSquare.append(::basegfx::B2DPoint(10.0, 0.0));
720 aNewSquare.append(::basegfx::B2DPoint(10.0, 10.0));
721 aNewSquare.append(::basegfx::B2DPoint(0.0, 10.0));
722 aNewSquare.setClosed(true);
723 aSquare.append(aNewSquare);
726 SfxItemSet aSet( mpDoc->GetPool() );
727 mpView->GetAttributes( aSet );
729 // #i3908# Here, the default Line Start/End width for arrow construction is
730 // set. To have the same value in all situations (construction) in i3908
731 // it was decided to change the default to 0.03 cm for all situations.
732 ::tools::Long nWidth = 300; // (1/100th mm)
734 // determine line width and calculate with it the line end width
735 if( aSet.GetItemState( XATTR_LINEWIDTH ) != SfxItemState::INVALID )
737 ::tools::Long nValue = aSet.Get( XATTR_LINEWIDTH ).GetValue();
738 if( nValue > 0 )
739 nWidth = nValue * 3;
742 switch (nSlotId)
744 case SID_CONNECTOR_ARROWS:
745 case SID_CONNECTOR_LINE_ARROWS:
746 case SID_CONNECTOR_LINES_ARROWS:
747 case SID_CONNECTOR_CURVE_ARROWS:
748 case SID_LINE_ARROWS:
750 // connector with arrow ends
751 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
752 rAttr.Put(XLineStartWidthItem(nWidth));
753 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
754 rAttr.Put(XLineEndWidthItem(nWidth));
756 break;
758 case SID_CONNECTOR_ARROW_START:
759 case SID_CONNECTOR_LINE_ARROW_START:
760 case SID_CONNECTOR_LINES_ARROW_START:
761 case SID_CONNECTOR_CURVE_ARROW_START:
762 case SID_LINE_ARROW_START:
763 case SID_LINE_ARROW_CIRCLE:
764 case SID_LINE_ARROW_SQUARE:
766 // connector with arrow start
767 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
768 rAttr.Put(XLineStartWidthItem(nWidth));
770 break;
772 case SID_CONNECTOR_ARROW_END:
773 case SID_CONNECTOR_LINE_ARROW_END:
774 case SID_CONNECTOR_LINES_ARROW_END:
775 case SID_CONNECTOR_CURVE_ARROW_END:
776 case SID_LINE_ARROW_END:
777 case SID_LINE_CIRCLE_ARROW:
778 case SID_LINE_SQUARE_ARROW:
780 // connector with arrow end
781 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), std::move(aArrow)));
782 rAttr.Put(XLineEndWidthItem(nWidth));
784 break;
786 case SID_CONNECTOR_CIRCLES:
787 case SID_CONNECTOR_LINE_CIRCLES:
788 case SID_CONNECTOR_LINES_CIRCLES:
789 case SID_CONNECTOR_CURVE_CIRCLES:
791 // connector with circle ends
792 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
793 rAttr.Put(XLineStartWidthItem(nWidth));
794 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
795 rAttr.Put(XLineEndWidthItem(nWidth));
797 break;
799 case SID_CONNECTOR_CIRCLE_START:
800 case SID_CONNECTOR_LINE_CIRCLE_START:
801 case SID_CONNECTOR_LINES_CIRCLE_START:
802 case SID_CONNECTOR_CURVE_CIRCLE_START:
804 // connector with circle start
805 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
806 rAttr.Put(XLineStartWidthItem(nWidth));
808 break;
810 case SID_CONNECTOR_CIRCLE_END:
811 case SID_CONNECTOR_LINE_CIRCLE_END:
812 case SID_CONNECTOR_LINES_CIRCLE_END:
813 case SID_CONNECTOR_CURVE_CIRCLE_END:
815 // connector with circle ends
816 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
817 rAttr.Put(XLineEndWidthItem(nWidth));
819 break;
822 // and again, for the still missing ends
823 switch (nSlotId)
825 case SID_LINE_ARROW_CIRCLE:
827 // circle end
828 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
829 rAttr.Put(XLineEndWidthItem(nWidth));
831 break;
833 case SID_LINE_CIRCLE_ARROW:
835 // circle start
836 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), std::move(aCircle)));
837 rAttr.Put(XLineStartWidthItem(nWidth));
839 break;
841 case SID_LINE_ARROW_SQUARE:
843 // square end
844 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
845 rAttr.Put(XLineEndWidthItem(nWidth));
847 break;
849 case SID_LINE_SQUARE_ARROW:
851 // square start
852 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE), std::move(aSquare)));
853 rAttr.Put(XLineStartWidthItem(nWidth));
855 break;
859 rtl::Reference<SdrObject> FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle)
861 DBG_ASSERT( (nID != SID_DRAW_FONTWORK) && (nID != SID_DRAW_FONTWORK_VERTICAL ), "FuConstRectangle::CreateDefaultObject can not create Fontwork shapes!" );
863 // case SID_DRAW_LINE:
864 // case SID_DRAW_XLINE:
865 // case SID_DRAW_MEASURELINE:
866 // case SID_LINE_ARROW_START:
867 // case SID_LINE_ARROW_END:
868 // case SID_LINE_ARROWS:
869 // case SID_LINE_ARROW_CIRCLE:
870 // case SID_LINE_CIRCLE_ARROW:
871 // case SID_LINE_ARROW_SQUARE:
872 // case SID_LINE_SQUARE_ARROW:
873 // case SID_DRAW_RECT:
874 // case SID_DRAW_RECT_NOFILL:
875 // case SID_DRAW_RECT_ROUND:
876 // case SID_DRAW_RECT_ROUND_NOFILL:
877 // case SID_DRAW_SQUARE:
878 // case SID_DRAW_SQUARE_NOFILL:
879 // case SID_DRAW_SQUARE_ROUND:
880 // case SID_DRAW_SQUARE_ROUND_NOFILL:
881 // case SID_DRAW_ELLIPSE:
882 // case SID_DRAW_ELLIPSE_NOFILL:
883 // case SID_DRAW_CIRCLE:
884 // case SID_DRAW_CIRCLE_NOFILL:
885 // case SID_DRAW_CAPTION:
886 // case SID_DRAW_CAPTION_VERTICAL:
887 // case SID_TOOL_CONNECTOR:
888 // case SID_CONNECTOR_ARROW_START:
889 // case SID_CONNECTOR_ARROW_END:
890 // case SID_CONNECTOR_ARROWS:
891 // case SID_CONNECTOR_CIRCLE_START:
892 // case SID_CONNECTOR_CIRCLE_END:
893 // case SID_CONNECTOR_CIRCLES:
894 // case SID_CONNECTOR_LINE:
895 // case SID_CONNECTOR_LINE_ARROW_START:
896 // case SID_CONNECTOR_LINE_ARROW_END:
897 // case SID_CONNECTOR_LINE_ARROWS:
898 // case SID_CONNECTOR_LINE_CIRCLE_START:
899 // case SID_CONNECTOR_LINE_CIRCLE_END:
900 // case SID_CONNECTOR_LINE_CIRCLES:
901 // case SID_CONNECTOR_CURVE:
902 // case SID_CONNECTOR_CURVE_ARROW_START:
903 // case SID_CONNECTOR_CURVE_ARROW_END:
904 // case SID_CONNECTOR_CURVE_ARROWS:
905 // case SID_CONNECTOR_CURVE_CIRCLE_START:
906 // case SID_CONNECTOR_CURVE_CIRCLE_END:
907 // case SID_CONNECTOR_CURVE_CIRCLES:
908 // case SID_CONNECTOR_LINES:
909 // case SID_CONNECTOR_LINES_ARROW_START:
910 // case SID_CONNECTOR_LINES_ARROW_END:
911 // case SID_CONNECTOR_LINES_ARROWS:
912 // case SID_CONNECTOR_LINES_CIRCLE_START:
913 // case SID_CONNECTOR_LINES_CIRCLE_END:
914 // case SID_CONNECTOR_LINES_CIRCLES:
916 rtl::Reference<SdrObject> pObj(SdrObjFactory::MakeNewObject(
917 mpView->getSdrModelFromSdrView(),
918 mpView->GetCurrentObjInventor(),
919 mpView->GetCurrentObjIdentifier()));
921 if(pObj)
923 ::tools::Rectangle aRect(rRectangle);
925 if(SID_DRAW_SQUARE == nID ||
926 SID_DRAW_SQUARE_NOFILL == nID ||
927 SID_DRAW_SQUARE_ROUND == nID ||
928 SID_DRAW_SQUARE_ROUND_NOFILL == nID ||
929 SID_DRAW_CIRCLE == nID ||
930 SID_DRAW_CIRCLE_NOFILL == nID)
932 // force quadratic
933 ImpForceQuadratic(aRect);
936 Point aStart = aRect.TopLeft();
937 Point aEnd = aRect.BottomRight();
939 switch(nID)
941 case SID_DRAW_LINE:
942 case SID_DRAW_XLINE:
943 case SID_LINE_ARROW_START:
944 case SID_LINE_ARROW_END:
945 case SID_LINE_ARROWS:
946 case SID_LINE_ARROW_CIRCLE:
947 case SID_LINE_CIRCLE_ARROW:
948 case SID_LINE_ARROW_SQUARE:
949 case SID_LINE_SQUARE_ARROW:
951 if( auto pPathObj = dynamic_cast<SdrPathObj *>( pObj.get() ) )
953 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
955 ::basegfx::B2DPolygon aB2DPolygon;
956 aB2DPolygon.append(::basegfx::B2DPoint(aStart.X(), nYMiddle));
957 aB2DPolygon.append(::basegfx::B2DPoint(aEnd.X(), nYMiddle));
958 pPathObj->SetPathPoly(::basegfx::B2DPolyPolygon(aB2DPolygon));
960 else
962 OSL_FAIL("Object is NO line object");
965 break;
968 case SID_DRAW_MEASURELINE:
970 if( auto pMeasureObj = dynamic_cast< SdrMeasureObj *>( pObj.get() ) )
972 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
973 pMeasureObj->SetPoint(Point(aStart.X(), nYMiddle), 0);
974 pMeasureObj->SetPoint(Point(aEnd.X(), nYMiddle), 1);
976 else
978 OSL_FAIL("Object is NO measure object");
981 break;
984 case SID_TOOL_CONNECTOR:
985 case SID_CONNECTOR_ARROW_START:
986 case SID_CONNECTOR_ARROW_END:
987 case SID_CONNECTOR_ARROWS:
988 case SID_CONNECTOR_CIRCLE_START:
989 case SID_CONNECTOR_CIRCLE_END:
990 case SID_CONNECTOR_CIRCLES:
991 case SID_CONNECTOR_LINE:
992 case SID_CONNECTOR_LINE_ARROW_START:
993 case SID_CONNECTOR_LINE_ARROW_END:
994 case SID_CONNECTOR_LINE_ARROWS:
995 case SID_CONNECTOR_LINE_CIRCLE_START:
996 case SID_CONNECTOR_LINE_CIRCLE_END:
997 case SID_CONNECTOR_LINE_CIRCLES:
998 case SID_CONNECTOR_CURVE:
999 case SID_CONNECTOR_CURVE_ARROW_START:
1000 case SID_CONNECTOR_CURVE_ARROW_END:
1001 case SID_CONNECTOR_CURVE_ARROWS:
1002 case SID_CONNECTOR_CURVE_CIRCLE_START:
1003 case SID_CONNECTOR_CURVE_CIRCLE_END:
1004 case SID_CONNECTOR_CURVE_CIRCLES:
1005 case SID_CONNECTOR_LINES:
1006 case SID_CONNECTOR_LINES_ARROW_START:
1007 case SID_CONNECTOR_LINES_ARROW_END:
1008 case SID_CONNECTOR_LINES_ARROWS:
1009 case SID_CONNECTOR_LINES_CIRCLE_START:
1010 case SID_CONNECTOR_LINES_CIRCLE_END:
1011 case SID_CONNECTOR_LINES_CIRCLES:
1013 if( auto pEdgeObj = dynamic_cast< SdrEdgeObj *>( pObj.get() ) )
1015 pEdgeObj->SetTailPoint(false, aStart);
1016 pEdgeObj->SetTailPoint(true, aEnd);
1018 else
1020 OSL_FAIL("Object is NO connector object");
1023 break;
1025 case SID_DRAW_CAPTION:
1026 case SID_DRAW_CAPTION_VERTICAL:
1028 if( auto pCaptionObj = dynamic_cast< SdrCaptionObj *>( pObj.get() ) )
1030 bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
1032 pCaptionObj->SetVerticalWriting(bIsVertical);
1034 if(bIsVertical)
1036 SfxItemSet aSet(pObj->GetMergedItemSet());
1037 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
1038 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
1039 pObj->SetMergedItemSet(aSet);
1042 // The default text is not inserted anymore.
1044 pCaptionObj->SetLogicRect(aRect);
1045 pCaptionObj->SetTailPos(
1046 aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
1048 else
1050 OSL_FAIL("Object is NO caption object");
1053 break;
1056 default:
1058 pObj->SetLogicRect(aRect);
1060 break;
1064 SfxItemSet aAttr(mpDoc->GetPool());
1065 SetStyleSheet(aAttr, pObj.get());
1066 SetAttributes(aAttr, pObj.get());
1067 SetLineEnds(aAttr, *pObj);
1068 pObj->SetMergedItemSet(aAttr);
1071 return pObj;
1074 } // end of namespace sd
1076 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */