Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fuconrec.cxx
blob1cca1e11aa6261ea445a72861310cd0a9dd81f56
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/aeitem.hxx>
29 #include <svx/xlnstwit.hxx>
30 #include <svx/xlnedwit.hxx>
31 #include <svx/xlnedit.hxx>
32 #include <svx/xlnstit.hxx>
33 #include <svx/xlnwtit.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <svx/sdtmfitm.hxx>
36 #include <svx/sxekitm.hxx>
37 #include <svx/sderitm.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <svx/svdopath.hxx>
40 #include <svx/svdocirc.hxx>
41 #include <svl/intitem.hxx>
42 #include <sfx2/request.hxx>
43 #include <editeng/adjustitem.hxx>
44 #include <svx/xtable.hxx>
46 #include <svx/svdocapt.hxx>
48 #include <svx/svdomeas.hxx>
49 #include <ViewShell.hxx>
50 #include <ViewShellBase.hxx>
51 #include <ToolBarManager.hxx>
52 #include <editeng/writingmodeitem.hxx>
53 #include <basegfx/polygon/b2dpolygontools.hxx>
54 #include <basegfx/polygon/b2dpolygon.hxx>
56 #include <sdresid.hxx>
57 #include <View.hxx>
58 #include <sdpage.hxx>
59 #include <Window.hxx>
60 #include <stlpool.hxx>
61 #include <drawdoc.hxx>
63 #include <strings.hrc>
65 namespace sd {
68 FuConstructRectangle::FuConstructRectangle (
69 ViewShell* pViewSh,
70 ::sd::Window* pWin,
71 ::sd::View* pView,
72 SdDrawDocument* pDoc,
73 SfxRequest& rReq)
74 : FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
78 rtl::Reference<FuPoor> FuConstructRectangle::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
80 FuConstructRectangle* pFunc;
81 rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructRectangle( pViewSh, pWin, pView, pDoc, rReq ) );
82 xFunc->DoExecute(rReq);
83 pFunc->SetPermanent(bPermanent);
84 return xFunc;
87 void FuConstructRectangle::DoExecute( SfxRequest& rReq )
89 FuConstruct::DoExecute( rReq );
91 mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
92 ToolBarManager::ToolBarGroup::Function,
93 ToolBarManager::msDrawingObjectToolBar);
95 const SfxItemSet *pArgs = rReq.GetArgs ();
97 if (pArgs)
99 switch (nSlotId)
101 case SID_DRAW_ELLIPSE :
103 const SfxUInt32Item* pCenterX = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_X);
104 const SfxUInt32Item* pCenterY = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_Y);
105 const SfxUInt32Item* pAxisX = rReq.GetArg<SfxUInt32Item>(ID_VAL_AXIS_X);
106 const SfxUInt32Item* pAxisY = rReq.GetArg<SfxUInt32Item>(ID_VAL_AXIS_Y);
108 ::tools::Rectangle aNewRectangle (pCenterX->GetValue () - pAxisX->GetValue () / 2,
109 pCenterY->GetValue () - pAxisY->GetValue () / 2,
110 pCenterX->GetValue () + pAxisX->GetValue () / 2,
111 pCenterY->GetValue () + pAxisY->GetValue () / 2);
112 SdrCircObj *pNewCircle = new SdrCircObj(
113 mpView->getSdrModelFromSdrView(),
114 OBJ_CIRC,
115 aNewRectangle);
116 SdrPageView *pPV = mpView->GetSdrPageView();
118 mpView->InsertObjectAtView(pNewCircle, *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
120 break;
122 case SID_DRAW_RECT :
124 const SfxUInt32Item* pMouseStartX = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSESTART_X);
125 const SfxUInt32Item* pMouseStartY = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSESTART_Y);
126 const SfxUInt32Item* pMouseEndX = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSEEND_X);
127 const SfxUInt32Item* pMouseEndY = rReq.GetArg<SfxUInt32Item>(ID_VAL_MOUSEEND_Y);
129 ::tools::Rectangle aNewRectangle (pMouseStartX->GetValue (),
130 pMouseStartY->GetValue (),
131 pMouseEndX->GetValue (),
132 pMouseEndY->GetValue ());
133 SdrRectObj *pNewRect = new SdrRectObj(
134 mpView->getSdrModelFromSdrView(),
135 aNewRectangle);
136 SdrPageView *pPV = mpView->GetSdrPageView();
138 mpView->InsertObjectAtView(pNewRect, *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
140 break;
144 if (nSlotId == SID_TOOL_CONNECTOR ||
145 nSlotId == SID_CONNECTOR_ARROW_START ||
146 nSlotId == SID_CONNECTOR_ARROW_END ||
147 nSlotId == SID_CONNECTOR_ARROWS ||
148 nSlotId == SID_CONNECTOR_CIRCLE_START ||
149 nSlotId == SID_CONNECTOR_CIRCLE_END ||
150 nSlotId == SID_CONNECTOR_CIRCLES ||
151 nSlotId == SID_CONNECTOR_LINE ||
152 nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
153 nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
154 nSlotId == SID_CONNECTOR_LINE_ARROWS ||
155 nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
156 nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
157 nSlotId == SID_CONNECTOR_LINE_CIRCLES ||
158 nSlotId == SID_CONNECTOR_CURVE ||
159 nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
160 nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
161 nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
162 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
163 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
164 nSlotId == SID_CONNECTOR_CURVE_CIRCLES ||
165 nSlotId == SID_CONNECTOR_LINES ||
166 nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
167 nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
168 nSlotId == SID_CONNECTOR_LINES_ARROWS ||
169 nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
170 nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
171 nSlotId == SID_CONNECTOR_LINES_CIRCLES ||
172 nSlotId == SID_LINE_ARROW_START ||
173 nSlotId == SID_LINE_ARROW_END ||
174 nSlotId == SID_LINE_ARROWS ||
175 nSlotId == SID_LINE_ARROW_CIRCLE ||
176 nSlotId == SID_LINE_CIRCLE_ARROW ||
177 nSlotId == SID_LINE_ARROW_SQUARE ||
178 nSlotId == SID_LINE_SQUARE_ARROW )
180 mpView->UnmarkAll();
184 bool FuConstructRectangle::MouseButtonDown(const MouseEvent& rMEvt)
186 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
188 if ( rMEvt.IsLeft() && !mpView->IsAction() )
190 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
192 mpWindow->CaptureMouse();
193 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
195 if (mpView->GetCurrentObjIdentifier() == OBJ_CAPTION)
197 Size aCaptionSize(846, 846); // (4x2)cm
198 bReturn = mpView->BegCreateCaptionObj(aPnt, aCaptionSize,
199 nullptr, nDrgLog);
201 else
203 mpView->BegCreateObj(aPnt, nullptr, nDrgLog);
206 SdrObject* pObj = mpView->GetCreateObj();
208 if (pObj)
210 SfxItemSet aAttr(mpDoc->GetPool());
211 SetStyleSheet(aAttr, pObj);
212 SetAttributes(aAttr, pObj);
213 SetLineEnds(aAttr, *pObj);
214 pObj->SetMergedItemSet(aAttr);
216 if( nSlotId == SID_DRAW_CAPTION_VERTICAL )
217 static_cast<SdrTextObj*>(pObj)->SetVerticalWriting( true );
220 return bReturn;
223 bool FuConstructRectangle::MouseButtonUp(const MouseEvent& rMEvt)
225 bool bReturn(false);
227 if(mpView->IsCreateObj() && rMEvt.IsLeft())
229 SdrObject* pObj = mpView->GetCreateObj();
231 if(pObj && mpView->EndCreateObj(SdrCreateCmd::ForceEnd))
233 if(SID_DRAW_MEASURELINE == nSlotId)
235 SdrLayerAdmin& rAdmin = mpDoc->GetLayerAdmin();
236 OUString aStr(SdResId(STR_LAYER_MEASURELINES));
237 pObj->SetLayer(rAdmin.GetLayerID(aStr));
240 // init text position when vertical caption object is created
241 if( dynamic_cast< const SdrCaptionObj *>( pObj ) != nullptr && SID_DRAW_CAPTION_VERTICAL == nSlotId)
243 // draw text object, needs to be initialized when vertical text is used
244 SfxItemSet aSet(pObj->GetMergedItemSet());
246 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
247 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
249 // Correct the value of SDRATTR_TEXTDIRECTION to avoid SetItemSet
250 // calling SetVerticalWriting() again since this item may not yet
251 // be set at the object and thus may differ from vertical state of
252 // the object.
253 aSet.Put(SvxWritingModeItem(css::text::WritingMode_TB_RL, SDRATTR_TEXTDIRECTION));
254 pObj->SetMergedItemSet(aSet);
257 bReturn = true;
261 bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
263 if (!bPermanent)
264 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
266 return bReturn;
269 void FuConstructRectangle::Activate()
271 SdrObjKind aObjKind;
273 switch (nSlotId)
275 case SID_LINE_ARROW_START:
276 case SID_LINE_ARROW_END:
277 case SID_LINE_ARROWS:
278 case SID_LINE_ARROW_CIRCLE:
279 case SID_LINE_CIRCLE_ARROW:
280 case SID_LINE_ARROW_SQUARE:
281 case SID_LINE_SQUARE_ARROW:
282 mpView->SetGlueVisible();
283 SAL_FALLTHROUGH;
284 case SID_DRAW_LINE :
285 case SID_DRAW_XLINE:
286 aObjKind = OBJ_LINE;
287 break;
289 case SID_DRAW_MEASURELINE:
291 aObjKind = OBJ_MEASURE;
293 break;
295 case SID_DRAW_RECT :
296 case SID_DRAW_RECT_NOFILL :
297 case SID_DRAW_RECT_ROUND :
298 case SID_DRAW_RECT_ROUND_NOFILL:
299 case SID_DRAW_SQUARE :
300 case SID_DRAW_SQUARE_NOFILL :
301 case SID_DRAW_SQUARE_ROUND :
302 case SID_DRAW_SQUARE_ROUND_NOFILL:
304 aObjKind = OBJ_RECT;
306 break;
308 case SID_DRAW_ELLIPSE :
309 case SID_DRAW_ELLIPSE_NOFILL:
310 case SID_DRAW_CIRCLE :
311 case SID_DRAW_CIRCLE_NOFILL :
313 aObjKind = OBJ_CIRC;
315 break;
317 case SID_DRAW_CAPTION:
318 case SID_DRAW_CAPTION_VERTICAL:
320 aObjKind = OBJ_CAPTION;
322 break;
324 case SID_TOOL_CONNECTOR:
325 case SID_CONNECTOR_ARROW_START:
326 case SID_CONNECTOR_ARROW_END:
327 case SID_CONNECTOR_ARROWS:
328 case SID_CONNECTOR_CIRCLE_START:
329 case SID_CONNECTOR_CIRCLE_END:
330 case SID_CONNECTOR_CIRCLES:
331 case SID_CONNECTOR_LINE:
332 case SID_CONNECTOR_LINE_ARROW_START:
333 case SID_CONNECTOR_LINE_ARROW_END:
334 case SID_CONNECTOR_LINE_ARROWS:
335 case SID_CONNECTOR_LINE_CIRCLE_START:
336 case SID_CONNECTOR_LINE_CIRCLE_END:
337 case SID_CONNECTOR_LINE_CIRCLES:
338 case SID_CONNECTOR_CURVE:
339 case SID_CONNECTOR_CURVE_ARROW_START:
340 case SID_CONNECTOR_CURVE_ARROW_END:
341 case SID_CONNECTOR_CURVE_ARROWS:
342 case SID_CONNECTOR_CURVE_CIRCLE_START:
343 case SID_CONNECTOR_CURVE_CIRCLE_END:
344 case SID_CONNECTOR_CURVE_CIRCLES:
345 case SID_CONNECTOR_LINES:
346 case SID_CONNECTOR_LINES_ARROW_START:
347 case SID_CONNECTOR_LINES_ARROW_END:
348 case SID_CONNECTOR_LINES_ARROWS:
349 case SID_CONNECTOR_LINES_CIRCLE_START:
350 case SID_CONNECTOR_LINES_CIRCLE_END:
351 case SID_CONNECTOR_LINES_CIRCLES:
353 aObjKind = OBJ_EDGE;
354 mpView->SetGlueVisible();
356 break;
358 default:
360 aObjKind = OBJ_RECT;
362 break;
365 mpView->SetCurrentObj(static_cast<sal_uInt16>(aObjKind));
367 FuConstruct::Activate();
370 void FuConstructRectangle::Deactivate()
372 if( nSlotId == SID_TOOL_CONNECTOR ||
373 nSlotId == SID_CONNECTOR_ARROW_START ||
374 nSlotId == SID_CONNECTOR_ARROW_END ||
375 nSlotId == SID_CONNECTOR_ARROWS ||
376 nSlotId == SID_CONNECTOR_CIRCLE_START ||
377 nSlotId == SID_CONNECTOR_CIRCLE_END ||
378 nSlotId == SID_CONNECTOR_CIRCLES ||
379 nSlotId == SID_CONNECTOR_LINE ||
380 nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
381 nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
382 nSlotId == SID_CONNECTOR_LINE_ARROWS ||
383 nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
384 nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
385 nSlotId == SID_CONNECTOR_LINE_CIRCLES ||
386 nSlotId == SID_CONNECTOR_CURVE ||
387 nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
388 nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
389 nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
390 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
391 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
392 nSlotId == SID_CONNECTOR_CURVE_CIRCLES ||
393 nSlotId == SID_CONNECTOR_LINES ||
394 nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
395 nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
396 nSlotId == SID_CONNECTOR_LINES_ARROWS ||
397 nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
398 nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
399 nSlotId == SID_CONNECTOR_LINES_CIRCLES ||
400 nSlotId == SID_LINE_ARROW_START ||
401 nSlotId == SID_LINE_ARROW_END ||
402 nSlotId == SID_LINE_ARROWS ||
403 nSlotId == SID_LINE_ARROW_CIRCLE ||
404 nSlotId == SID_LINE_CIRCLE_ARROW ||
405 nSlotId == SID_LINE_ARROW_SQUARE ||
406 nSlotId == SID_LINE_SQUARE_ARROW )
408 mpView->SetGlueVisible( false );
410 FuConstruct::Deactivate();
414 * set attribute for the object to be created
416 void FuConstructRectangle::SetAttributes(SfxItemSet& rAttr, SdrObject* pObj)
418 if (nSlotId == SID_DRAW_RECT_ROUND ||
419 nSlotId == SID_DRAW_RECT_ROUND_NOFILL ||
420 nSlotId == SID_DRAW_SQUARE_ROUND ||
421 nSlotId == SID_DRAW_SQUARE_ROUND_NOFILL)
423 // round corner
424 rAttr.Put(makeSdrEckenradiusItem(500));
426 else if (nSlotId == SID_CONNECTOR_LINE ||
427 nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
428 nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
429 nSlotId == SID_CONNECTOR_LINE_ARROWS ||
430 nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
431 nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
432 nSlotId == SID_CONNECTOR_LINE_CIRCLES)
434 // direct connector
435 rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::OneLine));
437 else if (nSlotId == SID_CONNECTOR_LINES ||
438 nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
439 nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
440 nSlotId == SID_CONNECTOR_LINES_ARROWS ||
441 nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
442 nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
443 nSlotId == SID_CONNECTOR_LINES_CIRCLES)
445 // line connector
446 rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::ThreeLines));
448 else if (nSlotId == SID_CONNECTOR_CURVE ||
449 nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
450 nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
451 nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
452 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
453 nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
454 nSlotId == SID_CONNECTOR_CURVE_CIRCLES)
456 // curve connector
457 rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::Bezier));
459 else if ( nSlotId == SID_DRAW_CAPTION || nSlotId == SID_DRAW_CAPTION_VERTICAL )
461 // legend object
462 Size aSize(pObj->GetLogicRect().GetSize());
463 rAttr.Put( makeSdrTextMinFrameHeightItem( aSize.Height() ) );
464 rAttr.Put( makeSdrTextMinFrameWidthItem( aSize.Width() ) );
465 rAttr.Put( makeSdrTextAutoGrowHeightItem( true ) );
466 rAttr.Put( makeSdrTextAutoGrowWidthItem( true ) );
468 // Support full with for vertical caption objects, too
469 if(SID_DRAW_CAPTION == nSlotId)
470 rAttr.Put( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
471 else
472 rAttr.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_BLOCK ) );
474 rAttr.Put( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
475 rAttr.Put( makeSdrTextLeftDistItem( 100 ) );
476 rAttr.Put( makeSdrTextRightDistItem( 100 ) );
477 rAttr.Put( makeSdrTextUpperDistItem( 100 ) );
478 rAttr.Put( makeSdrTextLowerDistItem( 100 ) );
480 else if (nSlotId == SID_DRAW_MEASURELINE)
482 // dimension line
483 SdPage* pPage = static_cast<SdPage*>( mpView->GetSdrPageView()->GetPage() );
484 OUString aName(SdResId(STR_POOLSHEET_MEASURE));
485 SfxStyleSheet* pSheet(
486 static_cast< SfxStyleSheet* >(
487 pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Para)));
488 DBG_ASSERT(pSheet, "StyleSheet missing");
490 if (pSheet)
492 pObj->SetStyleSheet(pSheet, false);
495 SdrLayerAdmin& rAdmin = mpDoc->GetLayerAdmin();
496 OUString aStr(SdResId(STR_LAYER_MEASURELINES));
497 pObj->SetLayer(rAdmin.GetLayerID(aStr));
502 * set line starts and ends for the object to be created
504 ::basegfx::B2DPolyPolygon getPolygon(const char* pResId, const SdrModel& rModel)
506 ::basegfx::B2DPolyPolygon aRetval;
507 XLineEndListRef pLineEndList(rModel.GetLineEndList());
509 if( pLineEndList.is() )
511 OUString aArrowName(SvxResId(pResId));
512 long nCount = pLineEndList->Count();
513 long nIndex;
514 for( nIndex = 0; nIndex < nCount; nIndex++ )
516 const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex);
517 if( pEntry->GetName() == aArrowName )
519 aRetval = pEntry->GetLineEnd();
520 break;
525 return aRetval;
528 void FuConstructRectangle::SetLineEnds(SfxItemSet& rAttr, SdrObject const & rObj)
530 if ( (rObj.GetObjIdentifier() == OBJ_EDGE &&
531 nSlotId != SID_TOOL_CONNECTOR &&
532 nSlotId != SID_CONNECTOR_LINE &&
533 nSlotId != SID_CONNECTOR_LINES &&
534 nSlotId != SID_CONNECTOR_CURVE) ||
535 nSlotId == SID_LINE_ARROW_START ||
536 nSlotId == SID_LINE_ARROW_END ||
537 nSlotId == SID_LINE_ARROWS ||
538 nSlotId == SID_LINE_ARROW_CIRCLE ||
539 nSlotId == SID_LINE_CIRCLE_ARROW ||
540 nSlotId == SID_LINE_ARROW_SQUARE ||
541 nSlotId == SID_LINE_SQUARE_ARROW )
543 // set attributes of line start and ends
544 SdrModel& rModel(rObj.getSdrModelFromSdrObject());
546 // arrowhead
547 ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, rModel ) );
548 if( !aArrow.count() )
550 ::basegfx::B2DPolygon aNewArrow;
551 aNewArrow.append(::basegfx::B2DPoint(10.0, 0.0));
552 aNewArrow.append(::basegfx::B2DPoint(0.0, 30.0));
553 aNewArrow.append(::basegfx::B2DPoint(20.0, 30.0));
554 aNewArrow.setClosed(true);
555 aArrow.append(aNewArrow);
558 // Circles
559 ::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, rModel ) );
560 if( !aCircle.count() )
562 ::basegfx::B2DPolygon aNewCircle;
563 aNewCircle = ::basegfx::utils::createPolygonFromEllipse(::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0);
564 aNewCircle.setClosed(true);
565 aCircle.append(aNewCircle);
568 // Square
569 ::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, rModel ) );
570 if( !aSquare.count() )
572 ::basegfx::B2DPolygon aNewSquare;
573 aNewSquare.append(::basegfx::B2DPoint(0.0, 0.0));
574 aNewSquare.append(::basegfx::B2DPoint(10.0, 0.0));
575 aNewSquare.append(::basegfx::B2DPoint(10.0, 10.0));
576 aNewSquare.append(::basegfx::B2DPoint(0.0, 10.0));
577 aNewSquare.setClosed(true);
578 aSquare.append(aNewSquare);
581 SfxItemSet aSet( mpDoc->GetPool() );
582 mpView->GetAttributes( aSet );
584 // #i3908# Here, the default Line Start/End width for arrow construction is
585 // set. To have the same value in all situations (construction) in i3908
586 // it was decided to change the default to 0.03 cm for all situations.
587 long nWidth = 300; // (1/100th mm)
589 // determine line width and calculate with it the line end width
590 if( aSet.GetItemState( XATTR_LINEWIDTH ) != SfxItemState::DONTCARE )
592 long nValue = aSet.Get( XATTR_LINEWIDTH ).GetValue();
593 if( nValue > 0 )
594 nWidth = nValue * 3;
597 switch (nSlotId)
599 case SID_CONNECTOR_ARROWS:
600 case SID_CONNECTOR_LINE_ARROWS:
601 case SID_CONNECTOR_LINES_ARROWS:
602 case SID_CONNECTOR_CURVE_ARROWS:
603 case SID_LINE_ARROWS:
605 // connector with arrow ends
606 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
607 rAttr.Put(XLineStartWidthItem(nWidth));
608 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
609 rAttr.Put(XLineEndWidthItem(nWidth));
611 break;
613 case SID_CONNECTOR_ARROW_START:
614 case SID_CONNECTOR_LINE_ARROW_START:
615 case SID_CONNECTOR_LINES_ARROW_START:
616 case SID_CONNECTOR_CURVE_ARROW_START:
617 case SID_LINE_ARROW_START:
618 case SID_LINE_ARROW_CIRCLE:
619 case SID_LINE_ARROW_SQUARE:
621 // connector with arrow start
622 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
623 rAttr.Put(XLineStartWidthItem(nWidth));
625 break;
627 case SID_CONNECTOR_ARROW_END:
628 case SID_CONNECTOR_LINE_ARROW_END:
629 case SID_CONNECTOR_LINES_ARROW_END:
630 case SID_CONNECTOR_CURVE_ARROW_END:
631 case SID_LINE_ARROW_END:
632 case SID_LINE_CIRCLE_ARROW:
633 case SID_LINE_SQUARE_ARROW:
635 // connector with arrow end
636 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
637 rAttr.Put(XLineEndWidthItem(nWidth));
639 break;
641 case SID_CONNECTOR_CIRCLES:
642 case SID_CONNECTOR_LINE_CIRCLES:
643 case SID_CONNECTOR_LINES_CIRCLES:
644 case SID_CONNECTOR_CURVE_CIRCLES:
646 // connector with circle ends
647 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
648 rAttr.Put(XLineStartWidthItem(nWidth));
649 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
650 rAttr.Put(XLineEndWidthItem(nWidth));
652 break;
654 case SID_CONNECTOR_CIRCLE_START:
655 case SID_CONNECTOR_LINE_CIRCLE_START:
656 case SID_CONNECTOR_LINES_CIRCLE_START:
657 case SID_CONNECTOR_CURVE_CIRCLE_START:
659 // connector with circle start
660 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
661 rAttr.Put(XLineStartWidthItem(nWidth));
663 break;
665 case SID_CONNECTOR_CIRCLE_END:
666 case SID_CONNECTOR_LINE_CIRCLE_END:
667 case SID_CONNECTOR_LINES_CIRCLE_END:
668 case SID_CONNECTOR_CURVE_CIRCLE_END:
670 // connector with circle ends
671 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
672 rAttr.Put(XLineEndWidthItem(nWidth));
674 break;
677 // and again, for the still missing ends
678 switch (nSlotId)
680 case SID_LINE_ARROW_CIRCLE:
682 // circle end
683 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
684 rAttr.Put(XLineEndWidthItem(nWidth));
686 break;
688 case SID_LINE_CIRCLE_ARROW:
690 // circle start
691 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
692 rAttr.Put(XLineStartWidthItem(nWidth));
694 break;
696 case SID_LINE_ARROW_SQUARE:
698 // square end
699 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
700 rAttr.Put(XLineEndWidthItem(nWidth));
702 break;
704 case SID_LINE_SQUARE_ARROW:
706 // square start
707 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
708 rAttr.Put(XLineStartWidthItem(nWidth));
710 break;
715 SdrObject* FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle)
717 DBG_ASSERT( (nID != SID_DRAW_FONTWORK) && (nID != SID_DRAW_FONTWORK_VERTICAL ), "FuConstRectangle::CreateDefaultObject can not create Fontwork shapes!" );
719 // case SID_DRAW_LINE:
720 // case SID_DRAW_XLINE:
721 // case SID_DRAW_MEASURELINE:
722 // case SID_LINE_ARROW_START:
723 // case SID_LINE_ARROW_END:
724 // case SID_LINE_ARROWS:
725 // case SID_LINE_ARROW_CIRCLE:
726 // case SID_LINE_CIRCLE_ARROW:
727 // case SID_LINE_ARROW_SQUARE:
728 // case SID_LINE_SQUARE_ARROW:
729 // case SID_DRAW_RECT:
730 // case SID_DRAW_RECT_NOFILL:
731 // case SID_DRAW_RECT_ROUND:
732 // case SID_DRAW_RECT_ROUND_NOFILL:
733 // case SID_DRAW_SQUARE:
734 // case SID_DRAW_SQUARE_NOFILL:
735 // case SID_DRAW_SQUARE_ROUND:
736 // case SID_DRAW_SQUARE_ROUND_NOFILL:
737 // case SID_DRAW_ELLIPSE:
738 // case SID_DRAW_ELLIPSE_NOFILL:
739 // case SID_DRAW_CIRCLE:
740 // case SID_DRAW_CIRCLE_NOFILL:
741 // case SID_DRAW_CAPTION:
742 // case SID_DRAW_CAPTION_VERTICAL:
743 // case SID_TOOL_CONNECTOR:
744 // case SID_CONNECTOR_ARROW_START:
745 // case SID_CONNECTOR_ARROW_END:
746 // case SID_CONNECTOR_ARROWS:
747 // case SID_CONNECTOR_CIRCLE_START:
748 // case SID_CONNECTOR_CIRCLE_END:
749 // case SID_CONNECTOR_CIRCLES:
750 // case SID_CONNECTOR_LINE:
751 // case SID_CONNECTOR_LINE_ARROW_START:
752 // case SID_CONNECTOR_LINE_ARROW_END:
753 // case SID_CONNECTOR_LINE_ARROWS:
754 // case SID_CONNECTOR_LINE_CIRCLE_START:
755 // case SID_CONNECTOR_LINE_CIRCLE_END:
756 // case SID_CONNECTOR_LINE_CIRCLES:
757 // case SID_CONNECTOR_CURVE:
758 // case SID_CONNECTOR_CURVE_ARROW_START:
759 // case SID_CONNECTOR_CURVE_ARROW_END:
760 // case SID_CONNECTOR_CURVE_ARROWS:
761 // case SID_CONNECTOR_CURVE_CIRCLE_START:
762 // case SID_CONNECTOR_CURVE_CIRCLE_END:
763 // case SID_CONNECTOR_CURVE_CIRCLES:
764 // case SID_CONNECTOR_LINES:
765 // case SID_CONNECTOR_LINES_ARROW_START:
766 // case SID_CONNECTOR_LINES_ARROW_END:
767 // case SID_CONNECTOR_LINES_ARROWS:
768 // case SID_CONNECTOR_LINES_CIRCLE_START:
769 // case SID_CONNECTOR_LINES_CIRCLE_END:
770 // case SID_CONNECTOR_LINES_CIRCLES:
772 SdrObject* pObj = SdrObjFactory::MakeNewObject(
773 mpView->getSdrModelFromSdrView(),
774 mpView->GetCurrentObjInventor(),
775 mpView->GetCurrentObjIdentifier());
777 if(pObj)
779 ::tools::Rectangle aRect(rRectangle);
781 if(SID_DRAW_SQUARE == nID ||
782 SID_DRAW_SQUARE_NOFILL == nID ||
783 SID_DRAW_SQUARE_ROUND == nID ||
784 SID_DRAW_SQUARE_ROUND_NOFILL == nID ||
785 SID_DRAW_CIRCLE == nID ||
786 SID_DRAW_CIRCLE_NOFILL == nID)
788 // force quadratic
789 ImpForceQuadratic(aRect);
792 Point aStart = aRect.TopLeft();
793 Point aEnd = aRect.BottomRight();
795 switch(nID)
797 case SID_DRAW_LINE:
798 case SID_DRAW_XLINE:
799 case SID_LINE_ARROW_START:
800 case SID_LINE_ARROW_END:
801 case SID_LINE_ARROWS:
802 case SID_LINE_ARROW_CIRCLE:
803 case SID_LINE_CIRCLE_ARROW:
804 case SID_LINE_ARROW_SQUARE:
805 case SID_LINE_SQUARE_ARROW:
807 if( dynamic_cast< const SdrPathObj *>( pObj ) != nullptr)
809 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
811 ::basegfx::B2DPolygon aB2DPolygon;
812 aB2DPolygon.append(::basegfx::B2DPoint(aStart.X(), nYMiddle));
813 aB2DPolygon.append(::basegfx::B2DPoint(aEnd.X(), nYMiddle));
814 static_cast<SdrPathObj*>(pObj)->SetPathPoly(::basegfx::B2DPolyPolygon(aB2DPolygon));
816 else
818 OSL_FAIL("Object is NO line object");
821 break;
824 case SID_DRAW_MEASURELINE:
826 if( auto pMeasureObj = dynamic_cast< SdrMeasureObj *>( pObj ) )
828 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
829 pMeasureObj->SetPoint(Point(aStart.X(), nYMiddle), 0);
830 pMeasureObj->SetPoint(Point(aEnd.X(), nYMiddle), 1);
832 else
834 OSL_FAIL("Object is NO measure object");
837 break;
840 case SID_TOOL_CONNECTOR:
841 case SID_CONNECTOR_ARROW_START:
842 case SID_CONNECTOR_ARROW_END:
843 case SID_CONNECTOR_ARROWS:
844 case SID_CONNECTOR_CIRCLE_START:
845 case SID_CONNECTOR_CIRCLE_END:
846 case SID_CONNECTOR_CIRCLES:
847 case SID_CONNECTOR_LINE:
848 case SID_CONNECTOR_LINE_ARROW_START:
849 case SID_CONNECTOR_LINE_ARROW_END:
850 case SID_CONNECTOR_LINE_ARROWS:
851 case SID_CONNECTOR_LINE_CIRCLE_START:
852 case SID_CONNECTOR_LINE_CIRCLE_END:
853 case SID_CONNECTOR_LINE_CIRCLES:
854 case SID_CONNECTOR_CURVE:
855 case SID_CONNECTOR_CURVE_ARROW_START:
856 case SID_CONNECTOR_CURVE_ARROW_END:
857 case SID_CONNECTOR_CURVE_ARROWS:
858 case SID_CONNECTOR_CURVE_CIRCLE_START:
859 case SID_CONNECTOR_CURVE_CIRCLE_END:
860 case SID_CONNECTOR_CURVE_CIRCLES:
861 case SID_CONNECTOR_LINES:
862 case SID_CONNECTOR_LINES_ARROW_START:
863 case SID_CONNECTOR_LINES_ARROW_END:
864 case SID_CONNECTOR_LINES_ARROWS:
865 case SID_CONNECTOR_LINES_CIRCLE_START:
866 case SID_CONNECTOR_LINES_CIRCLE_END:
867 case SID_CONNECTOR_LINES_CIRCLES:
869 if( auto pEdgeObj = dynamic_cast< SdrEdgeObj *>( pObj ) )
871 pEdgeObj->SetTailPoint(false, aStart);
872 pEdgeObj->SetTailPoint(true, aEnd);
874 else
876 OSL_FAIL("Object is NO connector object");
879 break;
881 case SID_DRAW_CAPTION:
882 case SID_DRAW_CAPTION_VERTICAL:
884 if( auto pCaptionObj = dynamic_cast< SdrCaptionObj *>( pObj ) )
886 bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
888 static_cast<SdrTextObj*>(pObj)->SetVerticalWriting(bIsVertical);
890 if(bIsVertical)
892 SfxItemSet aSet(pObj->GetMergedItemSet());
893 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
894 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
895 pObj->SetMergedItemSet(aSet);
898 // The default text is not inserted anymore.
900 pCaptionObj->SetLogicRect(aRect);
901 pCaptionObj->SetTailPos(
902 aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
904 else
906 OSL_FAIL("Object is NO caption object");
909 break;
912 default:
914 pObj->SetLogicRect(aRect);
916 break;
920 SfxItemSet aAttr(mpDoc->GetPool());
921 SetStyleSheet(aAttr, pObj);
922 SetAttributes(aAttr, pObj);
923 SetLineEnds(aAttr, *pObj);
924 pObj->SetMergedItemSet(aAttr);
927 return pObj;
930 } // end of namespace sd
932 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */