android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / func / fuconrec.cxx
blob1a8e1852332683fbc6be963b237c5dbc75ca63b6
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/xlineit0.hxx>
30 #include <svx/xlnstwit.hxx>
31 #include <svx/xlnedwit.hxx>
32 #include <svx/xlnedit.hxx>
33 #include <svx/xlnstit.hxx>
34 #include <svx/xlnwtit.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <svx/sdtmfitm.hxx>
37 #include <svx/sxekitm.hxx>
38 #include <svx/sderitm.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <svx/svdopath.hxx>
41 #include <svx/svdocirc.hxx>
42 #include <svl/intitem.hxx>
43 #include <sfx2/request.hxx>
44 #include <editeng/adjustitem.hxx>
45 #include <editeng/eeitem.hxx>
46 #include <svx/xtable.hxx>
47 #include <svx/xfltrit.hxx>
48 #include <svx/xflclit.hxx>
49 #include <svx/sdtagitm.hxx>
50 #include <svx/sdtditm.hxx>
52 #include <svx/svdocapt.hxx>
54 #include <svx/svdomeas.hxx>
55 #include <ViewShell.hxx>
56 #include <ViewShellBase.hxx>
57 #include <ToolBarManager.hxx>
58 #include <editeng/writingmodeitem.hxx>
59 #include <basegfx/polygon/b2dpolygontools.hxx>
60 #include <basegfx/polygon/b2dpolygon.hxx>
61 #include <svx/xfillit0.hxx>
62 #include <svx/signaturelinehelper.hxx>
63 #include <osl/diagnose.h>
65 #include <sdresid.hxx>
66 #include <View.hxx>
67 #include <sdpage.hxx>
68 #include <Window.hxx>
69 #include <drawdoc.hxx>
70 #include <unokywds.hxx>
72 #include <strings.hrc>
74 using namespace com::sun::star;
76 namespace sd {
79 FuConstructRectangle::FuConstructRectangle (
80 ViewShell* pViewSh,
81 ::sd::Window* pWin,
82 ::sd::View* pView,
83 SdDrawDocument* pDoc,
84 SfxRequest& rReq)
85 : FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
86 , mnFillTransparence(0)
87 , mnLineStyle(SAL_MAX_UINT16)
91 namespace{
93 /// Checks to see if the request has a parameter of IsSticky:bool=true
94 /// It means that the selected command/button will stay selected after use
95 bool isSticky(const SfxRequest& rReq)
97 const SfxItemSet *pArgs = rReq.GetArgs ();
98 if (pArgs)
100 const SfxBoolItem* pIsSticky = rReq.GetArg<SfxBoolItem>(FN_PARAM_4);
101 if (pIsSticky && pIsSticky->GetValue())
102 return true;
105 return false;
110 rtl::Reference<FuPoor> FuConstructRectangle::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
112 FuConstructRectangle* pFunc;
113 rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructRectangle( pViewSh, pWin, pView, pDoc, rReq ) );
114 xFunc->DoExecute(rReq);
115 pFunc->SetPermanent(bPermanent || isSticky(rReq));
116 return xFunc;
119 void FuConstructRectangle::DoExecute( SfxRequest& rReq )
121 FuConstruct::DoExecute( rReq );
123 mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
124 ToolBarManager::ToolBarGroup::Function,
125 ToolBarManager::msDrawingObjectToolBar);
127 const SfxItemSet *pArgs = rReq.GetArgs ();
129 if (pArgs)
131 switch (nSlotId)
133 case SID_DRAW_ELLIPSE :
135 const SfxUInt32Item* pCenterX = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_X);
136 const SfxUInt32Item* pCenterY = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_Y);
137 const SfxUInt32Item* pAxisX = rReq.GetArg<SfxUInt32Item>(ID_VAL_AXIS_X);
138 const SfxUInt32Item* pAxisY = rReq.GetArg<SfxUInt32Item>(ID_VAL_AXIS_Y);
140 if (!pCenterX || !pCenterY || !pAxisX || !pAxisY)
141 break;
143 ::tools::Rectangle aNewRectangle (pCenterX->GetValue () - pAxisX->GetValue () / 2,
144 pCenterY->GetValue () - pAxisY->GetValue () / 2,
145 pCenterX->GetValue () + pAxisX->GetValue () / 2,
146 pCenterY->GetValue () + pAxisY->GetValue () / 2);
147 rtl::Reference<SdrCircObj> pNewCircle = new SdrCircObj(
148 mpView->getSdrModelFromSdrView(),
149 SdrCircKind::Full,
150 aNewRectangle);
151 SdrPageView *pPV = mpView->GetSdrPageView();
153 mpView->InsertObjectAtView(pNewCircle.get(), *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
155 break;
157 case SID_DRAW_RECT :
159 const SfxUInt32Item* pMouseStartX = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSESTART_X);
160 const SfxUInt32Item* pMouseStartY = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSESTART_Y);
161 const SfxUInt32Item* pMouseEndX = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSEEND_X);
162 const SfxUInt32Item* pMouseEndY = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSEEND_Y);
163 const SfxUInt16Item* pFillTransparence = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
164 const SfxStringItem* pFillColor = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
165 const SfxUInt16Item* pLineStyle = rReq.GetArg<SfxUInt16Item>(FN_PARAM_3);
166 const SfxStringItem* pShapeName = rReq.GetArg<SfxStringItem>(SID_SHAPE_NAME);
168 if (pFillTransparence && pFillTransparence->GetValue() > 0)
170 mnFillTransparence = pFillTransparence->GetValue();
172 if (pFillColor && !pFillColor->GetValue().isEmpty())
174 msFillColor = pFillColor->GetValue();
176 if (pLineStyle)
178 mnLineStyle = pLineStyle->GetValue();
180 if (pShapeName && !pShapeName->GetValue().isEmpty())
182 msShapeName = pShapeName->GetValue();
185 if (!pMouseStartX || !pMouseStartY || !pMouseEndX || !pMouseEndY)
186 break;
188 ::tools::Rectangle aNewRectangle (pMouseStartX->GetValue (),
189 pMouseStartY->GetValue (),
190 pMouseEndX->GetValue (),
191 pMouseEndY->GetValue ());
192 rtl::Reference<SdrRectObj> pNewRect = new SdrRectObj(
193 mpView->getSdrModelFromSdrView(),
194 aNewRectangle);
195 SdrPageView *pPV = mpView->GetSdrPageView();
197 mpView->InsertObjectAtView(pNewRect.get(), *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
199 break;
203 if (nSlotId == SID_TOOL_CONNECTOR ||
204 nSlotId == SID_CONNECTOR_ARROW_START ||
205 nSlotId == SID_CONNECTOR_ARROW_END ||
206 nSlotId == SID_CONNECTOR_ARROWS ||
207 nSlotId == SID_CONNECTOR_CIRCLE_START ||
208 nSlotId == SID_CONNECTOR_CIRCLE_END ||
209 nSlotId == SID_CONNECTOR_CIRCLES ||
210 nSlotId == SID_CONNECTOR_LINE ||
211 nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
212 nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
213 nSlotId == SID_CONNECTOR_LINE_ARROWS ||
214 nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
215 nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
216 nSlotId == SID_CONNECTOR_LINE_CIRCLES ||
217 nSlotId == SID_CONNECTOR_CURVE ||
218 nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
219 nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
220 nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
221 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
222 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
223 nSlotId == SID_CONNECTOR_CURVE_CIRCLES ||
224 nSlotId == SID_CONNECTOR_LINES ||
225 nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
226 nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
227 nSlotId == SID_CONNECTOR_LINES_ARROWS ||
228 nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
229 nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
230 nSlotId == SID_CONNECTOR_LINES_CIRCLES ||
231 nSlotId == SID_LINE_ARROW_START ||
232 nSlotId == SID_LINE_ARROW_END ||
233 nSlotId == SID_LINE_ARROWS ||
234 nSlotId == SID_LINE_ARROW_CIRCLE ||
235 nSlotId == SID_LINE_CIRCLE_ARROW ||
236 nSlotId == SID_LINE_ARROW_SQUARE ||
237 nSlotId == SID_LINE_SQUARE_ARROW )
239 mpView->UnmarkAll();
243 bool FuConstructRectangle::MouseButtonDown(const MouseEvent& rMEvt)
245 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
247 if ( rMEvt.IsLeft() && !mpView->IsAction() )
249 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
251 mpWindow->CaptureMouse();
252 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(mpView->GetDragThresholdPixels(),0)).Width() );
254 if (mpView->GetCurrentObjIdentifier() == SdrObjKind::Caption)
256 Size aCaptionSize(846, 846); // (4x2)cm
257 bReturn = mpView->BegCreateCaptionObj(aPnt, aCaptionSize,
258 nullptr, nDrgLog);
260 else
262 mpView->BegCreateObj(aPnt, nullptr, nDrgLog);
265 SdrObject* pObj = mpView->GetCreateObj();
267 if (pObj)
269 SfxItemSet aAttr(mpDoc->GetPool());
270 SetStyleSheet(aAttr, pObj);
271 SetAttributes(aAttr, pObj);
272 SetLineEnds(aAttr, *pObj);
273 pObj->SetMergedItemSet(aAttr);
275 if( nSlotId == SID_DRAW_CAPTION_VERTICAL )
276 static_cast<SdrTextObj*>(pObj)->SetVerticalWriting( true );
279 return bReturn;
282 bool FuConstructRectangle::MouseButtonUp(const MouseEvent& rMEvt)
284 bool bReturn(false);
286 if(mpView->IsCreateObj() && rMEvt.IsLeft())
288 SdrObject* pObj = mpView->GetCreateObj();
290 if(pObj && mpView->EndCreateObj(SdrCreateCmd::ForceEnd))
292 if(SID_DRAW_MEASURELINE == nSlotId)
294 SdrLayerAdmin& rAdmin = mpDoc->GetLayerAdmin();
295 pObj->SetLayer(rAdmin.GetLayerID(sUNO_LayerName_measurelines));
298 // init text position when vertical caption object is created
299 if( dynamic_cast< const SdrCaptionObj *>( pObj ) != nullptr && SID_DRAW_CAPTION_VERTICAL == nSlotId)
301 // draw text object, needs to be initialized when vertical text is used
302 SfxItemSet aSet(pObj->GetMergedItemSet());
304 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
305 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
307 // Correct the value of SDRATTR_TEXTDIRECTION to avoid SetItemSet
308 // calling SetVerticalWriting() again since this item may not yet
309 // be set at the object and thus may differ from vertical state of
310 // the object.
311 aSet.Put(SvxWritingModeItem(css::text::WritingMode_TB_RL, SDRATTR_TEXTDIRECTION));
312 pObj->SetMergedItemSet(aSet);
315 bReturn = true;
317 else
319 //Drag was too small to create object, so insert default object at click pos
320 Point aClickPos(mpWindow->PixelToLogic(rMEvt.GetPosPixel()));
321 sal_uInt32 nDefaultObjectSize(1500);
322 sal_Int32 nCenterOffset(-sal_Int32(nDefaultObjectSize / 2));
323 aClickPos.AdjustX(nCenterOffset);
324 aClickPos.AdjustY(nCenterOffset);
326 SdrPageView *pPV = mpView->GetSdrPageView();
327 if(mpView->IsSnapEnabled())
328 aClickPos = mpView->GetSnapPos(aClickPos, pPV);
330 ::tools::Rectangle aNewObjectRectangle(aClickPos, Size(nDefaultObjectSize, nDefaultObjectSize));
331 rtl::Reference<SdrObject> pObjDefault = CreateDefaultObject(nSlotId, aNewObjectRectangle);
333 bReturn = mpView->InsertObjectAtView(pObjDefault.get(), *pPV);
337 bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
339 if (!bPermanent)
340 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
342 return bReturn;
345 void FuConstructRectangle::Activate()
347 SdrObjKind aObjKind;
349 switch (nSlotId)
351 case SID_LINE_ARROW_START:
352 case SID_LINE_ARROW_END:
353 case SID_LINE_ARROWS:
354 case SID_LINE_ARROW_CIRCLE:
355 case SID_LINE_CIRCLE_ARROW:
356 case SID_LINE_ARROW_SQUARE:
357 case SID_LINE_SQUARE_ARROW:
358 mpView->SetGlueVisible();
359 [[fallthrough]];
360 case SID_DRAW_LINE :
361 case SID_DRAW_XLINE:
362 aObjKind = SdrObjKind::Line;
363 break;
365 case SID_DRAW_MEASURELINE:
367 aObjKind = SdrObjKind::Measure;
369 break;
371 case SID_DRAW_RECT :
372 case SID_DRAW_RECT_NOFILL :
373 case SID_DRAW_RECT_ROUND :
374 case SID_DRAW_RECT_ROUND_NOFILL:
375 case SID_DRAW_SQUARE :
376 case SID_DRAW_SQUARE_NOFILL :
377 case SID_DRAW_SQUARE_ROUND :
378 case SID_DRAW_SQUARE_ROUND_NOFILL:
380 aObjKind = SdrObjKind::Rectangle;
382 break;
384 case SID_DRAW_ELLIPSE :
385 case SID_DRAW_ELLIPSE_NOFILL:
386 case SID_DRAW_CIRCLE :
387 case SID_DRAW_CIRCLE_NOFILL :
389 aObjKind = SdrObjKind::CircleOrEllipse;
391 break;
393 case SID_DRAW_CAPTION:
394 case SID_DRAW_CAPTION_VERTICAL:
396 aObjKind = SdrObjKind::Caption;
398 break;
400 case SID_TOOL_CONNECTOR:
401 case SID_CONNECTOR_ARROW_START:
402 case SID_CONNECTOR_ARROW_END:
403 case SID_CONNECTOR_ARROWS:
404 case SID_CONNECTOR_CIRCLE_START:
405 case SID_CONNECTOR_CIRCLE_END:
406 case SID_CONNECTOR_CIRCLES:
407 case SID_CONNECTOR_LINE:
408 case SID_CONNECTOR_LINE_ARROW_START:
409 case SID_CONNECTOR_LINE_ARROW_END:
410 case SID_CONNECTOR_LINE_ARROWS:
411 case SID_CONNECTOR_LINE_CIRCLE_START:
412 case SID_CONNECTOR_LINE_CIRCLE_END:
413 case SID_CONNECTOR_LINE_CIRCLES:
414 case SID_CONNECTOR_CURVE:
415 case SID_CONNECTOR_CURVE_ARROW_START:
416 case SID_CONNECTOR_CURVE_ARROW_END:
417 case SID_CONNECTOR_CURVE_ARROWS:
418 case SID_CONNECTOR_CURVE_CIRCLE_START:
419 case SID_CONNECTOR_CURVE_CIRCLE_END:
420 case SID_CONNECTOR_CURVE_CIRCLES:
421 case SID_CONNECTOR_LINES:
422 case SID_CONNECTOR_LINES_ARROW_START:
423 case SID_CONNECTOR_LINES_ARROW_END:
424 case SID_CONNECTOR_LINES_ARROWS:
425 case SID_CONNECTOR_LINES_CIRCLE_START:
426 case SID_CONNECTOR_LINES_CIRCLE_END:
427 case SID_CONNECTOR_LINES_CIRCLES:
429 aObjKind = SdrObjKind::Edge;
430 mpView->SetGlueVisible();
432 break;
433 case SID_INSERT_SIGNATURELINE:
435 aObjKind = SdrObjKind::Graphic;
437 break;
439 default:
441 aObjKind = SdrObjKind::Rectangle;
443 break;
446 mpView->SetCurrentObj(aObjKind);
448 FuConstruct::Activate();
451 void FuConstructRectangle::Deactivate()
453 if( nSlotId == SID_TOOL_CONNECTOR ||
454 nSlotId == SID_CONNECTOR_ARROW_START ||
455 nSlotId == SID_CONNECTOR_ARROW_END ||
456 nSlotId == SID_CONNECTOR_ARROWS ||
457 nSlotId == SID_CONNECTOR_CIRCLE_START ||
458 nSlotId == SID_CONNECTOR_CIRCLE_END ||
459 nSlotId == SID_CONNECTOR_CIRCLES ||
460 nSlotId == SID_CONNECTOR_LINE ||
461 nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
462 nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
463 nSlotId == SID_CONNECTOR_LINE_ARROWS ||
464 nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
465 nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
466 nSlotId == SID_CONNECTOR_LINE_CIRCLES ||
467 nSlotId == SID_CONNECTOR_CURVE ||
468 nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
469 nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
470 nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
471 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
472 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
473 nSlotId == SID_CONNECTOR_CURVE_CIRCLES ||
474 nSlotId == SID_CONNECTOR_LINES ||
475 nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
476 nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
477 nSlotId == SID_CONNECTOR_LINES_ARROWS ||
478 nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
479 nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
480 nSlotId == SID_CONNECTOR_LINES_CIRCLES ||
481 nSlotId == SID_LINE_ARROW_START ||
482 nSlotId == SID_LINE_ARROW_END ||
483 nSlotId == SID_LINE_ARROWS ||
484 nSlotId == SID_LINE_ARROW_CIRCLE ||
485 nSlotId == SID_LINE_CIRCLE_ARROW ||
486 nSlotId == SID_LINE_ARROW_SQUARE ||
487 nSlotId == SID_LINE_SQUARE_ARROW )
489 mpView->SetGlueVisible( false );
491 FuConstruct::Deactivate();
493 if (nSlotId != SID_INSERT_SIGNATURELINE)
495 return;
498 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
499 if (rMarkList.GetMarkCount() < 1)
501 // Just switching pages, no signature rectangle yet.
502 return;
505 // Finished drawing a signature rectangle, now set it up.
506 if (!mpViewShell)
508 return;
511 uno::Reference<security::XCertificate> xCertificate
512 = svx::SignatureLineHelper::getSignatureCertificate(mpViewShell->GetObjectShell(),
513 mpViewShell->GetFrameWeld());
514 if (!xCertificate.is())
516 return;
519 svx::SignatureLineHelper::setShapeCertificate(mpView, xCertificate);
521 // Update infobar to offer "finish signing".
522 SfxViewFrame* pFrame = mpViewShell->GetViewFrame();
523 if (pFrame && pFrame->HasInfoBarWithID(u"readonly"))
525 pFrame->RemoveInfoBar(u"readonly");
526 pFrame->AppendReadOnlyInfobar();
530 namespace {
531 /// Returns the color based on the color names listed in core/include/tools/color.hxx
532 /// Feel free to extend with more color names from color.hxx
533 Color strToColor(std::u16string_view sColor)
535 Color aColor = COL_AUTO;
537 if (sColor == u"COL_GRAY")
538 aColor = COL_GRAY;
539 else if (sColor == u"COL_GRAY3")
540 aColor = COL_GRAY3;
541 else if (sColor == u"COL_GRAY7")
542 aColor = COL_GRAY7;
544 return aColor;
549 * set attribute for the object to be created
551 void FuConstructRectangle::SetAttributes(SfxItemSet& rAttr, SdrObject* pObj)
553 if (nSlotId == SID_DRAW_RECT_ROUND ||
554 nSlotId == SID_DRAW_RECT_ROUND_NOFILL ||
555 nSlotId == SID_DRAW_SQUARE_ROUND ||
556 nSlotId == SID_DRAW_SQUARE_ROUND_NOFILL)
558 // round corner
559 rAttr.Put(makeSdrEckenradiusItem(500));
561 else if (nSlotId == SID_CONNECTOR_LINE ||
562 nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
563 nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
564 nSlotId == SID_CONNECTOR_LINE_ARROWS ||
565 nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
566 nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
567 nSlotId == SID_CONNECTOR_LINE_CIRCLES)
569 // direct connector
570 rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::OneLine));
572 else if (nSlotId == SID_CONNECTOR_LINES ||
573 nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
574 nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
575 nSlotId == SID_CONNECTOR_LINES_ARROWS ||
576 nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
577 nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
578 nSlotId == SID_CONNECTOR_LINES_CIRCLES)
580 // line connector
581 rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::ThreeLines));
583 else if (nSlotId == SID_CONNECTOR_CURVE ||
584 nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
585 nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
586 nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
587 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
588 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
589 nSlotId == SID_CONNECTOR_CURVE_CIRCLES)
591 // curve connector
592 rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::Bezier));
594 else if ( nSlotId == SID_DRAW_CAPTION || nSlotId == SID_DRAW_CAPTION_VERTICAL )
596 // legend object
597 Size aSize(pObj->GetLogicRect().GetSize());
598 rAttr.Put( makeSdrTextMinFrameHeightItem( aSize.Height() ) );
599 rAttr.Put( makeSdrTextMinFrameWidthItem( aSize.Width() ) );
600 rAttr.Put( makeSdrTextAutoGrowHeightItem( true ) );
601 rAttr.Put( makeSdrTextAutoGrowWidthItem( true ) );
603 // Support full with for vertical caption objects, too
604 if(SID_DRAW_CAPTION == nSlotId)
605 rAttr.Put( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
606 else
607 rAttr.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_BLOCK ) );
609 rAttr.Put( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
610 rAttr.Put( makeSdrTextLeftDistItem( 100 ) );
611 rAttr.Put( makeSdrTextRightDistItem( 100 ) );
612 rAttr.Put( makeSdrTextUpperDistItem( 100 ) );
613 rAttr.Put( makeSdrTextLowerDistItem( 100 ) );
615 else if (nSlotId == SID_DRAW_MEASURELINE)
617 // dimension line
618 SdPage* pPage = static_cast<SdPage*>( mpView->GetSdrPageView()->GetPage() );
619 OUString aName(SdResId(STR_POOLSHEET_MEASURE));
620 SfxStyleSheet* pSheet(
621 static_cast< SfxStyleSheet* >(
622 pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Para)));
623 DBG_ASSERT(pSheet, "StyleSheet missing");
625 if (pSheet)
627 pObj->SetStyleSheet(pSheet, false);
630 SdrLayerAdmin& rAdmin = mpDoc->GetLayerAdmin();
631 pObj->SetLayer(rAdmin.GetLayerID(sUNO_LayerName_measurelines));
633 else if (nSlotId == SID_DRAW_RECT)
635 if (mnFillTransparence > 0 && mnFillTransparence <= 100)
636 rAttr.Put(XFillTransparenceItem(mnFillTransparence));
637 if (!msFillColor.isEmpty())
638 rAttr.Put(XFillColorItem(OUString(), strToColor(msFillColor)));
639 if (!msShapeName.isEmpty())
640 pObj->SetName(msShapeName);
642 switch(mnLineStyle)
644 case 0:
645 rAttr.Put( XLineStyleItem(css::drawing::LineStyle_NONE ) );
646 break;
647 case 1:
648 rAttr.Put( XLineStyleItem(css::drawing::LineStyle_SOLID ) );
649 break;
650 case 2:
651 rAttr.Put( XLineStyleItem(css::drawing::LineStyle_DASH ) );
652 break;
653 default:
654 // Leave it to the defaults
655 break;
658 else if (nSlotId == SID_INSERT_SIGNATURELINE)
660 // Avoid the default solid fill and line, we'll set a graphic instead.
661 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
662 rAttr.Put(XLineStyleItem(drawing::LineStyle_NONE));
667 * set line starts and ends for the object to be created
669 static ::basegfx::B2DPolyPolygon getPolygon(TranslateId pResId, const SdrModel& rModel)
671 ::basegfx::B2DPolyPolygon aRetval;
672 XLineEndListRef pLineEndList(rModel.GetLineEndList());
674 if( pLineEndList.is() )
676 OUString aArrowName(SvxResId(pResId));
677 ::tools::Long nCount = pLineEndList->Count();
678 ::tools::Long nIndex;
679 for( nIndex = 0; nIndex < nCount; nIndex++ )
681 const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex);
682 if( pEntry->GetName() == aArrowName )
684 aRetval = pEntry->GetLineEnd();
685 break;
690 return aRetval;
693 void FuConstructRectangle::SetLineEnds(SfxItemSet& rAttr, SdrObject const & rObj)
695 if ( !((rObj.GetObjIdentifier() == SdrObjKind::Edge &&
696 nSlotId != SID_TOOL_CONNECTOR &&
697 nSlotId != SID_CONNECTOR_LINE &&
698 nSlotId != SID_CONNECTOR_LINES &&
699 nSlotId != SID_CONNECTOR_CURVE) ||
700 nSlotId == SID_LINE_ARROW_START ||
701 nSlotId == SID_LINE_ARROW_END ||
702 nSlotId == SID_LINE_ARROWS ||
703 nSlotId == SID_LINE_ARROW_CIRCLE ||
704 nSlotId == SID_LINE_CIRCLE_ARROW ||
705 nSlotId == SID_LINE_ARROW_SQUARE ||
706 nSlotId == SID_LINE_SQUARE_ARROW) )
707 return;
709 // set attributes of line start and ends
710 SdrModel& rModel(rObj.getSdrModelFromSdrObject());
712 // arrowhead
713 ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, rModel ) );
714 if( !aArrow.count() )
716 ::basegfx::B2DPolygon aNewArrow;
717 aNewArrow.append(::basegfx::B2DPoint(10.0, 0.0));
718 aNewArrow.append(::basegfx::B2DPoint(0.0, 30.0));
719 aNewArrow.append(::basegfx::B2DPoint(20.0, 30.0));
720 aNewArrow.setClosed(true);
721 aArrow.append(aNewArrow);
724 // Circles
725 ::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, rModel ) );
726 if( !aCircle.count() )
728 ::basegfx::B2DPolygon aNewCircle = ::basegfx::utils::createPolygonFromEllipse(::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0);
729 aNewCircle.setClosed(true);
730 aCircle.append(aNewCircle);
733 // Square
734 ::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, rModel ) );
735 if( !aSquare.count() )
737 ::basegfx::B2DPolygon aNewSquare;
738 aNewSquare.append(::basegfx::B2DPoint(0.0, 0.0));
739 aNewSquare.append(::basegfx::B2DPoint(10.0, 0.0));
740 aNewSquare.append(::basegfx::B2DPoint(10.0, 10.0));
741 aNewSquare.append(::basegfx::B2DPoint(0.0, 10.0));
742 aNewSquare.setClosed(true);
743 aSquare.append(aNewSquare);
746 SfxItemSet aSet( mpDoc->GetPool() );
747 mpView->GetAttributes( aSet );
749 // #i3908# Here, the default Line Start/End width for arrow construction is
750 // set. To have the same value in all situations (construction) in i3908
751 // it was decided to change the default to 0.03 cm for all situations.
752 ::tools::Long nWidth = 300; // (1/100th mm)
754 // determine line width and calculate with it the line end width
755 if( aSet.GetItemState( XATTR_LINEWIDTH ) != SfxItemState::DONTCARE )
757 ::tools::Long nValue = aSet.Get( XATTR_LINEWIDTH ).GetValue();
758 if( nValue > 0 )
759 nWidth = nValue * 3;
762 switch (nSlotId)
764 case SID_CONNECTOR_ARROWS:
765 case SID_CONNECTOR_LINE_ARROWS:
766 case SID_CONNECTOR_LINES_ARROWS:
767 case SID_CONNECTOR_CURVE_ARROWS:
768 case SID_LINE_ARROWS:
770 // connector with arrow ends
771 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
772 rAttr.Put(XLineStartWidthItem(nWidth));
773 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
774 rAttr.Put(XLineEndWidthItem(nWidth));
776 break;
778 case SID_CONNECTOR_ARROW_START:
779 case SID_CONNECTOR_LINE_ARROW_START:
780 case SID_CONNECTOR_LINES_ARROW_START:
781 case SID_CONNECTOR_CURVE_ARROW_START:
782 case SID_LINE_ARROW_START:
783 case SID_LINE_ARROW_CIRCLE:
784 case SID_LINE_ARROW_SQUARE:
786 // connector with arrow start
787 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
788 rAttr.Put(XLineStartWidthItem(nWidth));
790 break;
792 case SID_CONNECTOR_ARROW_END:
793 case SID_CONNECTOR_LINE_ARROW_END:
794 case SID_CONNECTOR_LINES_ARROW_END:
795 case SID_CONNECTOR_CURVE_ARROW_END:
796 case SID_LINE_ARROW_END:
797 case SID_LINE_CIRCLE_ARROW:
798 case SID_LINE_SQUARE_ARROW:
800 // connector with arrow end
801 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
802 rAttr.Put(XLineEndWidthItem(nWidth));
804 break;
806 case SID_CONNECTOR_CIRCLES:
807 case SID_CONNECTOR_LINE_CIRCLES:
808 case SID_CONNECTOR_LINES_CIRCLES:
809 case SID_CONNECTOR_CURVE_CIRCLES:
811 // connector with circle ends
812 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
813 rAttr.Put(XLineStartWidthItem(nWidth));
814 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
815 rAttr.Put(XLineEndWidthItem(nWidth));
817 break;
819 case SID_CONNECTOR_CIRCLE_START:
820 case SID_CONNECTOR_LINE_CIRCLE_START:
821 case SID_CONNECTOR_LINES_CIRCLE_START:
822 case SID_CONNECTOR_CURVE_CIRCLE_START:
824 // connector with circle start
825 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
826 rAttr.Put(XLineStartWidthItem(nWidth));
828 break;
830 case SID_CONNECTOR_CIRCLE_END:
831 case SID_CONNECTOR_LINE_CIRCLE_END:
832 case SID_CONNECTOR_LINES_CIRCLE_END:
833 case SID_CONNECTOR_CURVE_CIRCLE_END:
835 // connector with circle ends
836 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
837 rAttr.Put(XLineEndWidthItem(nWidth));
839 break;
842 // and again, for the still missing ends
843 switch (nSlotId)
845 case SID_LINE_ARROW_CIRCLE:
847 // circle end
848 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
849 rAttr.Put(XLineEndWidthItem(nWidth));
851 break;
853 case SID_LINE_CIRCLE_ARROW:
855 // circle start
856 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
857 rAttr.Put(XLineStartWidthItem(nWidth));
859 break;
861 case SID_LINE_ARROW_SQUARE:
863 // square end
864 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
865 rAttr.Put(XLineEndWidthItem(nWidth));
867 break;
869 case SID_LINE_SQUARE_ARROW:
871 // square start
872 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
873 rAttr.Put(XLineStartWidthItem(nWidth));
875 break;
879 rtl::Reference<SdrObject> FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle)
881 DBG_ASSERT( (nID != SID_DRAW_FONTWORK) && (nID != SID_DRAW_FONTWORK_VERTICAL ), "FuConstRectangle::CreateDefaultObject can not create Fontwork shapes!" );
883 // case SID_DRAW_LINE:
884 // case SID_DRAW_XLINE:
885 // case SID_DRAW_MEASURELINE:
886 // case SID_LINE_ARROW_START:
887 // case SID_LINE_ARROW_END:
888 // case SID_LINE_ARROWS:
889 // case SID_LINE_ARROW_CIRCLE:
890 // case SID_LINE_CIRCLE_ARROW:
891 // case SID_LINE_ARROW_SQUARE:
892 // case SID_LINE_SQUARE_ARROW:
893 // case SID_DRAW_RECT:
894 // case SID_DRAW_RECT_NOFILL:
895 // case SID_DRAW_RECT_ROUND:
896 // case SID_DRAW_RECT_ROUND_NOFILL:
897 // case SID_DRAW_SQUARE:
898 // case SID_DRAW_SQUARE_NOFILL:
899 // case SID_DRAW_SQUARE_ROUND:
900 // case SID_DRAW_SQUARE_ROUND_NOFILL:
901 // case SID_DRAW_ELLIPSE:
902 // case SID_DRAW_ELLIPSE_NOFILL:
903 // case SID_DRAW_CIRCLE:
904 // case SID_DRAW_CIRCLE_NOFILL:
905 // case SID_DRAW_CAPTION:
906 // case SID_DRAW_CAPTION_VERTICAL:
907 // case SID_TOOL_CONNECTOR:
908 // case SID_CONNECTOR_ARROW_START:
909 // case SID_CONNECTOR_ARROW_END:
910 // case SID_CONNECTOR_ARROWS:
911 // case SID_CONNECTOR_CIRCLE_START:
912 // case SID_CONNECTOR_CIRCLE_END:
913 // case SID_CONNECTOR_CIRCLES:
914 // case SID_CONNECTOR_LINE:
915 // case SID_CONNECTOR_LINE_ARROW_START:
916 // case SID_CONNECTOR_LINE_ARROW_END:
917 // case SID_CONNECTOR_LINE_ARROWS:
918 // case SID_CONNECTOR_LINE_CIRCLE_START:
919 // case SID_CONNECTOR_LINE_CIRCLE_END:
920 // case SID_CONNECTOR_LINE_CIRCLES:
921 // case SID_CONNECTOR_CURVE:
922 // case SID_CONNECTOR_CURVE_ARROW_START:
923 // case SID_CONNECTOR_CURVE_ARROW_END:
924 // case SID_CONNECTOR_CURVE_ARROWS:
925 // case SID_CONNECTOR_CURVE_CIRCLE_START:
926 // case SID_CONNECTOR_CURVE_CIRCLE_END:
927 // case SID_CONNECTOR_CURVE_CIRCLES:
928 // case SID_CONNECTOR_LINES:
929 // case SID_CONNECTOR_LINES_ARROW_START:
930 // case SID_CONNECTOR_LINES_ARROW_END:
931 // case SID_CONNECTOR_LINES_ARROWS:
932 // case SID_CONNECTOR_LINES_CIRCLE_START:
933 // case SID_CONNECTOR_LINES_CIRCLE_END:
934 // case SID_CONNECTOR_LINES_CIRCLES:
936 rtl::Reference<SdrObject> pObj(SdrObjFactory::MakeNewObject(
937 mpView->getSdrModelFromSdrView(),
938 mpView->GetCurrentObjInventor(),
939 mpView->GetCurrentObjIdentifier()));
941 if(pObj)
943 ::tools::Rectangle aRect(rRectangle);
945 if(SID_DRAW_SQUARE == nID ||
946 SID_DRAW_SQUARE_NOFILL == nID ||
947 SID_DRAW_SQUARE_ROUND == nID ||
948 SID_DRAW_SQUARE_ROUND_NOFILL == nID ||
949 SID_DRAW_CIRCLE == nID ||
950 SID_DRAW_CIRCLE_NOFILL == nID)
952 // force quadratic
953 ImpForceQuadratic(aRect);
956 Point aStart = aRect.TopLeft();
957 Point aEnd = aRect.BottomRight();
959 switch(nID)
961 case SID_DRAW_LINE:
962 case SID_DRAW_XLINE:
963 case SID_LINE_ARROW_START:
964 case SID_LINE_ARROW_END:
965 case SID_LINE_ARROWS:
966 case SID_LINE_ARROW_CIRCLE:
967 case SID_LINE_CIRCLE_ARROW:
968 case SID_LINE_ARROW_SQUARE:
969 case SID_LINE_SQUARE_ARROW:
971 if( auto pPathObj = dynamic_cast<SdrPathObj *>( pObj.get() ) )
973 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
975 ::basegfx::B2DPolygon aB2DPolygon;
976 aB2DPolygon.append(::basegfx::B2DPoint(aStart.X(), nYMiddle));
977 aB2DPolygon.append(::basegfx::B2DPoint(aEnd.X(), nYMiddle));
978 pPathObj->SetPathPoly(::basegfx::B2DPolyPolygon(aB2DPolygon));
980 else
982 OSL_FAIL("Object is NO line object");
985 break;
988 case SID_DRAW_MEASURELINE:
990 if( auto pMeasureObj = dynamic_cast< SdrMeasureObj *>( pObj.get() ) )
992 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
993 pMeasureObj->SetPoint(Point(aStart.X(), nYMiddle), 0);
994 pMeasureObj->SetPoint(Point(aEnd.X(), nYMiddle), 1);
996 else
998 OSL_FAIL("Object is NO measure object");
1001 break;
1004 case SID_TOOL_CONNECTOR:
1005 case SID_CONNECTOR_ARROW_START:
1006 case SID_CONNECTOR_ARROW_END:
1007 case SID_CONNECTOR_ARROWS:
1008 case SID_CONNECTOR_CIRCLE_START:
1009 case SID_CONNECTOR_CIRCLE_END:
1010 case SID_CONNECTOR_CIRCLES:
1011 case SID_CONNECTOR_LINE:
1012 case SID_CONNECTOR_LINE_ARROW_START:
1013 case SID_CONNECTOR_LINE_ARROW_END:
1014 case SID_CONNECTOR_LINE_ARROWS:
1015 case SID_CONNECTOR_LINE_CIRCLE_START:
1016 case SID_CONNECTOR_LINE_CIRCLE_END:
1017 case SID_CONNECTOR_LINE_CIRCLES:
1018 case SID_CONNECTOR_CURVE:
1019 case SID_CONNECTOR_CURVE_ARROW_START:
1020 case SID_CONNECTOR_CURVE_ARROW_END:
1021 case SID_CONNECTOR_CURVE_ARROWS:
1022 case SID_CONNECTOR_CURVE_CIRCLE_START:
1023 case SID_CONNECTOR_CURVE_CIRCLE_END:
1024 case SID_CONNECTOR_CURVE_CIRCLES:
1025 case SID_CONNECTOR_LINES:
1026 case SID_CONNECTOR_LINES_ARROW_START:
1027 case SID_CONNECTOR_LINES_ARROW_END:
1028 case SID_CONNECTOR_LINES_ARROWS:
1029 case SID_CONNECTOR_LINES_CIRCLE_START:
1030 case SID_CONNECTOR_LINES_CIRCLE_END:
1031 case SID_CONNECTOR_LINES_CIRCLES:
1033 if( auto pEdgeObj = dynamic_cast< SdrEdgeObj *>( pObj.get() ) )
1035 pEdgeObj->SetTailPoint(false, aStart);
1036 pEdgeObj->SetTailPoint(true, aEnd);
1038 else
1040 OSL_FAIL("Object is NO connector object");
1043 break;
1045 case SID_DRAW_CAPTION:
1046 case SID_DRAW_CAPTION_VERTICAL:
1048 if( auto pCaptionObj = dynamic_cast< SdrCaptionObj *>( pObj.get() ) )
1050 bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
1052 pCaptionObj->SetVerticalWriting(bIsVertical);
1054 if(bIsVertical)
1056 SfxItemSet aSet(pObj->GetMergedItemSet());
1057 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
1058 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
1059 pObj->SetMergedItemSet(aSet);
1062 // The default text is not inserted anymore.
1064 pCaptionObj->SetLogicRect(aRect);
1065 pCaptionObj->SetTailPos(
1066 aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
1068 else
1070 OSL_FAIL("Object is NO caption object");
1073 break;
1076 default:
1078 pObj->SetLogicRect(aRect);
1080 break;
1084 SfxItemSet aAttr(mpDoc->GetPool());
1085 SetStyleSheet(aAttr, pObj.get());
1086 SetAttributes(aAttr, pObj.get());
1087 SetLineEnds(aAttr, *pObj);
1088 pObj->SetMergedItemSet(aAttr);
1091 return pObj;
1094 } // end of namespace sd
1096 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */