1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 #include <svl/itemset.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 <editeng/eeitem.hxx>
45 #include <svx/xtable.hxx>
46 #include <svx/xfltrit.hxx>
47 #include <svx/xflclit.hxx>
48 #include <svx/sdtagitm.hxx>
49 #include <svx/sdtditm.hxx>
51 #include <svx/svdocapt.hxx>
53 #include <svx/svdomeas.hxx>
54 #include <ViewShell.hxx>
55 #include <ViewShellBase.hxx>
56 #include <ToolBarManager.hxx>
57 #include <editeng/writingmodeitem.hxx>
58 #include <basegfx/polygon/b2dpolygontools.hxx>
59 #include <basegfx/polygon/b2dpolygon.hxx>
61 #include <sdresid.hxx>
65 #include <drawdoc.hxx>
66 #include <unokywds.hxx>
68 #include <strings.hrc>
73 FuConstructRectangle::FuConstructRectangle (
79 : FuConstruct(pViewSh
, pWin
, pView
, pDoc
, rReq
)
80 , mnFillTransparence(0)
81 , mnLineStyle(SAL_MAX_UINT16
)
87 /// Checks to see if the request has a parameter of IsSticky:bool=true
88 /// It means that the selected command/button will stay selected after use
89 bool isSticky(SfxRequest
& rReq
)
91 const SfxItemSet
*pArgs
= rReq
.GetArgs ();
94 const SfxBoolItem
* pIsSticky
= rReq
.GetArg
<SfxBoolItem
>(FN_PARAM_4
);
95 if (pIsSticky
&& pIsSticky
->GetValue())
104 rtl::Reference
<FuPoor
> FuConstructRectangle::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
106 FuConstructRectangle
* pFunc
;
107 rtl::Reference
<FuPoor
> xFunc( pFunc
= new FuConstructRectangle( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
108 xFunc
->DoExecute(rReq
);
109 pFunc
->SetPermanent(bPermanent
|| isSticky(rReq
));
113 void FuConstructRectangle::DoExecute( SfxRequest
& rReq
)
115 FuConstruct::DoExecute( rReq
);
117 mpViewShell
->GetViewShellBase().GetToolBarManager()->SetToolBar(
118 ToolBarManager::ToolBarGroup::Function
,
119 ToolBarManager::msDrawingObjectToolBar
);
121 const SfxItemSet
*pArgs
= rReq
.GetArgs ();
127 case SID_DRAW_ELLIPSE
:
129 const SfxUInt32Item
* pCenterX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_CENTER_X
);
130 const SfxUInt32Item
* pCenterY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_CENTER_Y
);
131 const SfxUInt32Item
* pAxisX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_AXIS_X
);
132 const SfxUInt32Item
* pAxisY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_AXIS_Y
);
134 if (!pCenterX
|| !pCenterY
|| !pAxisX
|| !pAxisY
)
137 ::tools::Rectangle
aNewRectangle (pCenterX
->GetValue () - pAxisX
->GetValue () / 2,
138 pCenterY
->GetValue () - pAxisY
->GetValue () / 2,
139 pCenterX
->GetValue () + pAxisX
->GetValue () / 2,
140 pCenterY
->GetValue () + pAxisY
->GetValue () / 2);
141 SdrCircObj
*pNewCircle
= new SdrCircObj(
142 mpView
->getSdrModelFromSdrView(),
145 SdrPageView
*pPV
= mpView
->GetSdrPageView();
147 mpView
->InsertObjectAtView(pNewCircle
, *pPV
, SdrInsertFlags::SETDEFLAYER
| SdrInsertFlags::SETDEFATTR
);
153 const SfxUInt32Item
* pMouseStartX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_MOUSESTART_X
);
154 const SfxUInt32Item
* pMouseStartY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_MOUSESTART_Y
);
155 const SfxUInt32Item
* pMouseEndX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_MOUSEEND_X
);
156 const SfxUInt32Item
* pMouseEndY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_MOUSEEND_Y
);
157 const SfxUInt16Item
* pFillTransparence
= rReq
.GetArg
<SfxUInt16Item
>(FN_PARAM_1
);
158 const SfxStringItem
* pFillColor
= rReq
.GetArg
<SfxStringItem
>(FN_PARAM_2
);
159 const SfxUInt16Item
* pLineStyle
= rReq
.GetArg
<SfxUInt16Item
>(FN_PARAM_3
);
160 const SfxStringItem
* pShapeName
= rReq
.GetArg
<SfxStringItem
>(SID_SHAPE_NAME
);
162 if (pFillTransparence
&& pFillTransparence
->GetValue() > 0)
164 mnFillTransparence
= pFillTransparence
->GetValue();
166 if (pFillColor
&& !pFillColor
->GetValue().isEmpty())
168 msFillColor
= pFillColor
->GetValue();
172 mnLineStyle
= pLineStyle
->GetValue();
174 if (pShapeName
&& !pShapeName
->GetValue().isEmpty())
176 msShapeName
= pShapeName
->GetValue();
179 if (!pMouseStartX
|| !pMouseStartY
|| !pMouseEndX
|| !pMouseEndY
)
182 ::tools::Rectangle
aNewRectangle (pMouseStartX
->GetValue (),
183 pMouseStartY
->GetValue (),
184 pMouseEndX
->GetValue (),
185 pMouseEndY
->GetValue ());
186 SdrRectObj
*pNewRect
= new SdrRectObj(
187 mpView
->getSdrModelFromSdrView(),
189 SdrPageView
*pPV
= mpView
->GetSdrPageView();
191 mpView
->InsertObjectAtView(pNewRect
, *pPV
, SdrInsertFlags::SETDEFLAYER
| SdrInsertFlags::SETDEFATTR
);
197 if (nSlotId
== SID_TOOL_CONNECTOR
||
198 nSlotId
== SID_CONNECTOR_ARROW_START
||
199 nSlotId
== SID_CONNECTOR_ARROW_END
||
200 nSlotId
== SID_CONNECTOR_ARROWS
||
201 nSlotId
== SID_CONNECTOR_CIRCLE_START
||
202 nSlotId
== SID_CONNECTOR_CIRCLE_END
||
203 nSlotId
== SID_CONNECTOR_CIRCLES
||
204 nSlotId
== SID_CONNECTOR_LINE
||
205 nSlotId
== SID_CONNECTOR_LINE_ARROW_START
||
206 nSlotId
== SID_CONNECTOR_LINE_ARROW_END
||
207 nSlotId
== SID_CONNECTOR_LINE_ARROWS
||
208 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_START
||
209 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_END
||
210 nSlotId
== SID_CONNECTOR_LINE_CIRCLES
||
211 nSlotId
== SID_CONNECTOR_CURVE
||
212 nSlotId
== SID_CONNECTOR_CURVE_ARROW_START
||
213 nSlotId
== SID_CONNECTOR_CURVE_ARROW_END
||
214 nSlotId
== SID_CONNECTOR_CURVE_ARROWS
||
215 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_START
||
216 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_END
||
217 nSlotId
== SID_CONNECTOR_CURVE_CIRCLES
||
218 nSlotId
== SID_CONNECTOR_LINES
||
219 nSlotId
== SID_CONNECTOR_LINES_ARROW_START
||
220 nSlotId
== SID_CONNECTOR_LINES_ARROW_END
||
221 nSlotId
== SID_CONNECTOR_LINES_ARROWS
||
222 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_START
||
223 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_END
||
224 nSlotId
== SID_CONNECTOR_LINES_CIRCLES
||
225 nSlotId
== SID_LINE_ARROW_START
||
226 nSlotId
== SID_LINE_ARROW_END
||
227 nSlotId
== SID_LINE_ARROWS
||
228 nSlotId
== SID_LINE_ARROW_CIRCLE
||
229 nSlotId
== SID_LINE_CIRCLE_ARROW
||
230 nSlotId
== SID_LINE_ARROW_SQUARE
||
231 nSlotId
== SID_LINE_SQUARE_ARROW
)
237 bool FuConstructRectangle::MouseButtonDown(const MouseEvent
& rMEvt
)
239 bool bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
241 if ( rMEvt
.IsLeft() && !mpView
->IsAction() )
243 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
245 mpWindow
->CaptureMouse();
246 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
248 if (mpView
->GetCurrentObjIdentifier() == OBJ_CAPTION
)
250 Size
aCaptionSize(846, 846); // (4x2)cm
251 bReturn
= mpView
->BegCreateCaptionObj(aPnt
, aCaptionSize
,
256 mpView
->BegCreateObj(aPnt
, nullptr, nDrgLog
);
259 SdrObject
* pObj
= mpView
->GetCreateObj();
263 SfxItemSet
aAttr(mpDoc
->GetPool());
264 SetStyleSheet(aAttr
, pObj
);
265 SetAttributes(aAttr
, pObj
);
266 SetLineEnds(aAttr
, *pObj
);
267 pObj
->SetMergedItemSet(aAttr
);
269 if( nSlotId
== SID_DRAW_CAPTION_VERTICAL
)
270 static_cast<SdrTextObj
*>(pObj
)->SetVerticalWriting( true );
276 bool FuConstructRectangle::MouseButtonUp(const MouseEvent
& rMEvt
)
280 if(mpView
->IsCreateObj() && rMEvt
.IsLeft())
282 SdrObject
* pObj
= mpView
->GetCreateObj();
284 if(pObj
&& mpView
->EndCreateObj(SdrCreateCmd::ForceEnd
))
286 if(SID_DRAW_MEASURELINE
== nSlotId
)
288 SdrLayerAdmin
& rAdmin
= mpDoc
->GetLayerAdmin();
289 pObj
->SetLayer(rAdmin
.GetLayerID(sUNO_LayerName_measurelines
));
292 // init text position when vertical caption object is created
293 if( dynamic_cast< const SdrCaptionObj
*>( pObj
) != nullptr && SID_DRAW_CAPTION_VERTICAL
== nSlotId
)
295 // draw text object, needs to be initialized when vertical text is used
296 SfxItemSet
aSet(pObj
->GetMergedItemSet());
298 aSet
.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER
));
299 aSet
.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT
));
301 // Correct the value of SDRATTR_TEXTDIRECTION to avoid SetItemSet
302 // calling SetVerticalWriting() again since this item may not yet
303 // be set at the object and thus may differ from vertical state of
305 aSet
.Put(SvxWritingModeItem(css::text::WritingMode_TB_RL
, SDRATTR_TEXTDIRECTION
));
306 pObj
->SetMergedItemSet(aSet
);
313 bReturn
= FuConstruct::MouseButtonUp (rMEvt
) || bReturn
;
316 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
321 void FuConstructRectangle::Activate()
327 case SID_LINE_ARROW_START
:
328 case SID_LINE_ARROW_END
:
329 case SID_LINE_ARROWS
:
330 case SID_LINE_ARROW_CIRCLE
:
331 case SID_LINE_CIRCLE_ARROW
:
332 case SID_LINE_ARROW_SQUARE
:
333 case SID_LINE_SQUARE_ARROW
:
334 mpView
->SetGlueVisible();
341 case SID_DRAW_MEASURELINE
:
343 aObjKind
= OBJ_MEASURE
;
348 case SID_DRAW_RECT_NOFILL
:
349 case SID_DRAW_RECT_ROUND
:
350 case SID_DRAW_RECT_ROUND_NOFILL
:
351 case SID_DRAW_SQUARE
:
352 case SID_DRAW_SQUARE_NOFILL
:
353 case SID_DRAW_SQUARE_ROUND
:
354 case SID_DRAW_SQUARE_ROUND_NOFILL
:
360 case SID_DRAW_ELLIPSE
:
361 case SID_DRAW_ELLIPSE_NOFILL
:
362 case SID_DRAW_CIRCLE
:
363 case SID_DRAW_CIRCLE_NOFILL
:
369 case SID_DRAW_CAPTION
:
370 case SID_DRAW_CAPTION_VERTICAL
:
372 aObjKind
= OBJ_CAPTION
;
376 case SID_TOOL_CONNECTOR
:
377 case SID_CONNECTOR_ARROW_START
:
378 case SID_CONNECTOR_ARROW_END
:
379 case SID_CONNECTOR_ARROWS
:
380 case SID_CONNECTOR_CIRCLE_START
:
381 case SID_CONNECTOR_CIRCLE_END
:
382 case SID_CONNECTOR_CIRCLES
:
383 case SID_CONNECTOR_LINE
:
384 case SID_CONNECTOR_LINE_ARROW_START
:
385 case SID_CONNECTOR_LINE_ARROW_END
:
386 case SID_CONNECTOR_LINE_ARROWS
:
387 case SID_CONNECTOR_LINE_CIRCLE_START
:
388 case SID_CONNECTOR_LINE_CIRCLE_END
:
389 case SID_CONNECTOR_LINE_CIRCLES
:
390 case SID_CONNECTOR_CURVE
:
391 case SID_CONNECTOR_CURVE_ARROW_START
:
392 case SID_CONNECTOR_CURVE_ARROW_END
:
393 case SID_CONNECTOR_CURVE_ARROWS
:
394 case SID_CONNECTOR_CURVE_CIRCLE_START
:
395 case SID_CONNECTOR_CURVE_CIRCLE_END
:
396 case SID_CONNECTOR_CURVE_CIRCLES
:
397 case SID_CONNECTOR_LINES
:
398 case SID_CONNECTOR_LINES_ARROW_START
:
399 case SID_CONNECTOR_LINES_ARROW_END
:
400 case SID_CONNECTOR_LINES_ARROWS
:
401 case SID_CONNECTOR_LINES_CIRCLE_START
:
402 case SID_CONNECTOR_LINES_CIRCLE_END
:
403 case SID_CONNECTOR_LINES_CIRCLES
:
406 mpView
->SetGlueVisible();
417 mpView
->SetCurrentObj(static_cast<sal_uInt16
>(aObjKind
));
419 FuConstruct::Activate();
422 void FuConstructRectangle::Deactivate()
424 if( nSlotId
== SID_TOOL_CONNECTOR
||
425 nSlotId
== SID_CONNECTOR_ARROW_START
||
426 nSlotId
== SID_CONNECTOR_ARROW_END
||
427 nSlotId
== SID_CONNECTOR_ARROWS
||
428 nSlotId
== SID_CONNECTOR_CIRCLE_START
||
429 nSlotId
== SID_CONNECTOR_CIRCLE_END
||
430 nSlotId
== SID_CONNECTOR_CIRCLES
||
431 nSlotId
== SID_CONNECTOR_LINE
||
432 nSlotId
== SID_CONNECTOR_LINE_ARROW_START
||
433 nSlotId
== SID_CONNECTOR_LINE_ARROW_END
||
434 nSlotId
== SID_CONNECTOR_LINE_ARROWS
||
435 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_START
||
436 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_END
||
437 nSlotId
== SID_CONNECTOR_LINE_CIRCLES
||
438 nSlotId
== SID_CONNECTOR_CURVE
||
439 nSlotId
== SID_CONNECTOR_CURVE_ARROW_START
||
440 nSlotId
== SID_CONNECTOR_CURVE_ARROW_END
||
441 nSlotId
== SID_CONNECTOR_CURVE_ARROWS
||
442 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_START
||
443 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_END
||
444 nSlotId
== SID_CONNECTOR_CURVE_CIRCLES
||
445 nSlotId
== SID_CONNECTOR_LINES
||
446 nSlotId
== SID_CONNECTOR_LINES_ARROW_START
||
447 nSlotId
== SID_CONNECTOR_LINES_ARROW_END
||
448 nSlotId
== SID_CONNECTOR_LINES_ARROWS
||
449 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_START
||
450 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_END
||
451 nSlotId
== SID_CONNECTOR_LINES_CIRCLES
||
452 nSlotId
== SID_LINE_ARROW_START
||
453 nSlotId
== SID_LINE_ARROW_END
||
454 nSlotId
== SID_LINE_ARROWS
||
455 nSlotId
== SID_LINE_ARROW_CIRCLE
||
456 nSlotId
== SID_LINE_CIRCLE_ARROW
||
457 nSlotId
== SID_LINE_ARROW_SQUARE
||
458 nSlotId
== SID_LINE_SQUARE_ARROW
)
460 mpView
->SetGlueVisible( false );
462 FuConstruct::Deactivate();
466 /// Returns the color based on the color names listed in core/include/tools/color.hxx
467 /// Feel free to extend with more color names from color.hxx
468 Color
strToColor(const OUString
& sColor
)
470 Color aColor
= COL_AUTO
;
472 if (sColor
== "COL_GRAY")
474 else if (sColor
== "COL_GRAY3")
476 else if (sColor
== "COL_GRAY7")
484 * set attribute for the object to be created
486 void FuConstructRectangle::SetAttributes(SfxItemSet
& rAttr
, SdrObject
* pObj
)
488 if (nSlotId
== SID_DRAW_RECT_ROUND
||
489 nSlotId
== SID_DRAW_RECT_ROUND_NOFILL
||
490 nSlotId
== SID_DRAW_SQUARE_ROUND
||
491 nSlotId
== SID_DRAW_SQUARE_ROUND_NOFILL
)
494 rAttr
.Put(makeSdrEckenradiusItem(500));
496 else if (nSlotId
== SID_CONNECTOR_LINE
||
497 nSlotId
== SID_CONNECTOR_LINE_ARROW_START
||
498 nSlotId
== SID_CONNECTOR_LINE_ARROW_END
||
499 nSlotId
== SID_CONNECTOR_LINE_ARROWS
||
500 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_START
||
501 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_END
||
502 nSlotId
== SID_CONNECTOR_LINE_CIRCLES
)
505 rAttr
.Put(SdrEdgeKindItem(SdrEdgeKind::OneLine
));
507 else if (nSlotId
== SID_CONNECTOR_LINES
||
508 nSlotId
== SID_CONNECTOR_LINES_ARROW_START
||
509 nSlotId
== SID_CONNECTOR_LINES_ARROW_END
||
510 nSlotId
== SID_CONNECTOR_LINES_ARROWS
||
511 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_START
||
512 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_END
||
513 nSlotId
== SID_CONNECTOR_LINES_CIRCLES
)
516 rAttr
.Put(SdrEdgeKindItem(SdrEdgeKind::ThreeLines
));
518 else if (nSlotId
== SID_CONNECTOR_CURVE
||
519 nSlotId
== SID_CONNECTOR_CURVE_ARROW_START
||
520 nSlotId
== SID_CONNECTOR_CURVE_ARROW_END
||
521 nSlotId
== SID_CONNECTOR_CURVE_ARROWS
||
522 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_START
||
523 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_END
||
524 nSlotId
== SID_CONNECTOR_CURVE_CIRCLES
)
527 rAttr
.Put(SdrEdgeKindItem(SdrEdgeKind::Bezier
));
529 else if ( nSlotId
== SID_DRAW_CAPTION
|| nSlotId
== SID_DRAW_CAPTION_VERTICAL
)
532 Size
aSize(pObj
->GetLogicRect().GetSize());
533 rAttr
.Put( makeSdrTextMinFrameHeightItem( aSize
.Height() ) );
534 rAttr
.Put( makeSdrTextMinFrameWidthItem( aSize
.Width() ) );
535 rAttr
.Put( makeSdrTextAutoGrowHeightItem( true ) );
536 rAttr
.Put( makeSdrTextAutoGrowWidthItem( true ) );
538 // Support full with for vertical caption objects, too
539 if(SID_DRAW_CAPTION
== nSlotId
)
540 rAttr
.Put( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK
) );
542 rAttr
.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_BLOCK
) );
544 rAttr
.Put( SvxAdjustItem( SvxAdjust::Center
, EE_PARA_JUST
) );
545 rAttr
.Put( makeSdrTextLeftDistItem( 100 ) );
546 rAttr
.Put( makeSdrTextRightDistItem( 100 ) );
547 rAttr
.Put( makeSdrTextUpperDistItem( 100 ) );
548 rAttr
.Put( makeSdrTextLowerDistItem( 100 ) );
550 else if (nSlotId
== SID_DRAW_MEASURELINE
)
553 SdPage
* pPage
= static_cast<SdPage
*>( mpView
->GetSdrPageView()->GetPage() );
554 OUString
aName(SdResId(STR_POOLSHEET_MEASURE
));
555 SfxStyleSheet
* pSheet(
556 static_cast< SfxStyleSheet
* >(
557 pPage
->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName
, SfxStyleFamily::Para
)));
558 DBG_ASSERT(pSheet
, "StyleSheet missing");
562 pObj
->SetStyleSheet(pSheet
, false);
565 SdrLayerAdmin
& rAdmin
= mpDoc
->GetLayerAdmin();
566 pObj
->SetLayer(rAdmin
.GetLayerID(sUNO_LayerName_measurelines
));
568 else if (nSlotId
== SID_DRAW_RECT
)
570 if (mnFillTransparence
> 0 && mnFillTransparence
<= 100)
571 rAttr
.Put(XFillTransparenceItem(mnFillTransparence
));
572 if (!msFillColor
.isEmpty())
573 rAttr
.Put(XFillColorItem(OUString(), strToColor(msFillColor
)));
574 if (!msShapeName
.isEmpty())
575 pObj
->SetName(msShapeName
);
580 rAttr
.Put( XLineStyleItem(css::drawing::LineStyle_NONE
) );
583 rAttr
.Put( XLineStyleItem(css::drawing::LineStyle_SOLID
) );
586 rAttr
.Put( XLineStyleItem(css::drawing::LineStyle_DASH
) );
589 // Leave it to the defaults
596 * set line starts and ends for the object to be created
598 static ::basegfx::B2DPolyPolygon
getPolygon(const char* pResId
, const SdrModel
& rModel
)
600 ::basegfx::B2DPolyPolygon aRetval
;
601 XLineEndListRef
pLineEndList(rModel
.GetLineEndList());
603 if( pLineEndList
.is() )
605 OUString
aArrowName(SvxResId(pResId
));
606 long nCount
= pLineEndList
->Count();
608 for( nIndex
= 0; nIndex
< nCount
; nIndex
++ )
610 const XLineEndEntry
* pEntry
= pLineEndList
->GetLineEnd(nIndex
);
611 if( pEntry
->GetName() == aArrowName
)
613 aRetval
= pEntry
->GetLineEnd();
622 void FuConstructRectangle::SetLineEnds(SfxItemSet
& rAttr
, SdrObject
const & rObj
)
624 if ( !((rObj
.GetObjIdentifier() == OBJ_EDGE
&&
625 nSlotId
!= SID_TOOL_CONNECTOR
&&
626 nSlotId
!= SID_CONNECTOR_LINE
&&
627 nSlotId
!= SID_CONNECTOR_LINES
&&
628 nSlotId
!= SID_CONNECTOR_CURVE
) ||
629 nSlotId
== SID_LINE_ARROW_START
||
630 nSlotId
== SID_LINE_ARROW_END
||
631 nSlotId
== SID_LINE_ARROWS
||
632 nSlotId
== SID_LINE_ARROW_CIRCLE
||
633 nSlotId
== SID_LINE_CIRCLE_ARROW
||
634 nSlotId
== SID_LINE_ARROW_SQUARE
||
635 nSlotId
== SID_LINE_SQUARE_ARROW
) )
638 // set attributes of line start and ends
639 SdrModel
& rModel(rObj
.getSdrModelFromSdrObject());
642 ::basegfx::B2DPolyPolygon
aArrow( getPolygon( RID_SVXSTR_ARROW
, rModel
) );
643 if( !aArrow
.count() )
645 ::basegfx::B2DPolygon aNewArrow
;
646 aNewArrow
.append(::basegfx::B2DPoint(10.0, 0.0));
647 aNewArrow
.append(::basegfx::B2DPoint(0.0, 30.0));
648 aNewArrow
.append(::basegfx::B2DPoint(20.0, 30.0));
649 aNewArrow
.setClosed(true);
650 aArrow
.append(aNewArrow
);
654 ::basegfx::B2DPolyPolygon
aCircle( getPolygon( RID_SVXSTR_CIRCLE
, rModel
) );
655 if( !aCircle
.count() )
657 ::basegfx::B2DPolygon aNewCircle
= ::basegfx::utils::createPolygonFromEllipse(::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0);
658 aNewCircle
.setClosed(true);
659 aCircle
.append(aNewCircle
);
663 ::basegfx::B2DPolyPolygon
aSquare( getPolygon( RID_SVXSTR_SQUARE
, rModel
) );
664 if( !aSquare
.count() )
666 ::basegfx::B2DPolygon aNewSquare
;
667 aNewSquare
.append(::basegfx::B2DPoint(0.0, 0.0));
668 aNewSquare
.append(::basegfx::B2DPoint(10.0, 0.0));
669 aNewSquare
.append(::basegfx::B2DPoint(10.0, 10.0));
670 aNewSquare
.append(::basegfx::B2DPoint(0.0, 10.0));
671 aNewSquare
.setClosed(true);
672 aSquare
.append(aNewSquare
);
675 SfxItemSet
aSet( mpDoc
->GetPool() );
676 mpView
->GetAttributes( aSet
);
678 // #i3908# Here, the default Line Start/End width for arrow construction is
679 // set. To have the same value in all situations (construction) in i3908
680 // it was decided to change the default to 0.03 cm for all situations.
681 long nWidth
= 300; // (1/100th mm)
683 // determine line width and calculate with it the line end width
684 if( aSet
.GetItemState( XATTR_LINEWIDTH
) != SfxItemState::DONTCARE
)
686 long nValue
= aSet
.Get( XATTR_LINEWIDTH
).GetValue();
693 case SID_CONNECTOR_ARROWS
:
694 case SID_CONNECTOR_LINE_ARROWS
:
695 case SID_CONNECTOR_LINES_ARROWS
:
696 case SID_CONNECTOR_CURVE_ARROWS
:
697 case SID_LINE_ARROWS
:
699 // connector with arrow ends
700 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW
), aArrow
));
701 rAttr
.Put(XLineStartWidthItem(nWidth
));
702 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW
), aArrow
));
703 rAttr
.Put(XLineEndWidthItem(nWidth
));
707 case SID_CONNECTOR_ARROW_START
:
708 case SID_CONNECTOR_LINE_ARROW_START
:
709 case SID_CONNECTOR_LINES_ARROW_START
:
710 case SID_CONNECTOR_CURVE_ARROW_START
:
711 case SID_LINE_ARROW_START
:
712 case SID_LINE_ARROW_CIRCLE
:
713 case SID_LINE_ARROW_SQUARE
:
715 // connector with arrow start
716 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW
), aArrow
));
717 rAttr
.Put(XLineStartWidthItem(nWidth
));
721 case SID_CONNECTOR_ARROW_END
:
722 case SID_CONNECTOR_LINE_ARROW_END
:
723 case SID_CONNECTOR_LINES_ARROW_END
:
724 case SID_CONNECTOR_CURVE_ARROW_END
:
725 case SID_LINE_ARROW_END
:
726 case SID_LINE_CIRCLE_ARROW
:
727 case SID_LINE_SQUARE_ARROW
:
729 // connector with arrow end
730 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW
), aArrow
));
731 rAttr
.Put(XLineEndWidthItem(nWidth
));
735 case SID_CONNECTOR_CIRCLES
:
736 case SID_CONNECTOR_LINE_CIRCLES
:
737 case SID_CONNECTOR_LINES_CIRCLES
:
738 case SID_CONNECTOR_CURVE_CIRCLES
:
740 // connector with circle ends
741 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
742 rAttr
.Put(XLineStartWidthItem(nWidth
));
743 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
744 rAttr
.Put(XLineEndWidthItem(nWidth
));
748 case SID_CONNECTOR_CIRCLE_START
:
749 case SID_CONNECTOR_LINE_CIRCLE_START
:
750 case SID_CONNECTOR_LINES_CIRCLE_START
:
751 case SID_CONNECTOR_CURVE_CIRCLE_START
:
753 // connector with circle start
754 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
755 rAttr
.Put(XLineStartWidthItem(nWidth
));
759 case SID_CONNECTOR_CIRCLE_END
:
760 case SID_CONNECTOR_LINE_CIRCLE_END
:
761 case SID_CONNECTOR_LINES_CIRCLE_END
:
762 case SID_CONNECTOR_CURVE_CIRCLE_END
:
764 // connector with circle ends
765 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
766 rAttr
.Put(XLineEndWidthItem(nWidth
));
771 // and again, for the still missing ends
774 case SID_LINE_ARROW_CIRCLE
:
777 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
778 rAttr
.Put(XLineEndWidthItem(nWidth
));
782 case SID_LINE_CIRCLE_ARROW
:
785 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
786 rAttr
.Put(XLineStartWidthItem(nWidth
));
790 case SID_LINE_ARROW_SQUARE
:
793 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE
), aSquare
));
794 rAttr
.Put(XLineEndWidthItem(nWidth
));
798 case SID_LINE_SQUARE_ARROW
:
801 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE
), aSquare
));
802 rAttr
.Put(XLineStartWidthItem(nWidth
));
808 SdrObjectUniquePtr
FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID
, const ::tools::Rectangle
& rRectangle
)
810 DBG_ASSERT( (nID
!= SID_DRAW_FONTWORK
) && (nID
!= SID_DRAW_FONTWORK_VERTICAL
), "FuConstRectangle::CreateDefaultObject can not create Fontwork shapes!" );
812 // case SID_DRAW_LINE:
813 // case SID_DRAW_XLINE:
814 // case SID_DRAW_MEASURELINE:
815 // case SID_LINE_ARROW_START:
816 // case SID_LINE_ARROW_END:
817 // case SID_LINE_ARROWS:
818 // case SID_LINE_ARROW_CIRCLE:
819 // case SID_LINE_CIRCLE_ARROW:
820 // case SID_LINE_ARROW_SQUARE:
821 // case SID_LINE_SQUARE_ARROW:
822 // case SID_DRAW_RECT:
823 // case SID_DRAW_RECT_NOFILL:
824 // case SID_DRAW_RECT_ROUND:
825 // case SID_DRAW_RECT_ROUND_NOFILL:
826 // case SID_DRAW_SQUARE:
827 // case SID_DRAW_SQUARE_NOFILL:
828 // case SID_DRAW_SQUARE_ROUND:
829 // case SID_DRAW_SQUARE_ROUND_NOFILL:
830 // case SID_DRAW_ELLIPSE:
831 // case SID_DRAW_ELLIPSE_NOFILL:
832 // case SID_DRAW_CIRCLE:
833 // case SID_DRAW_CIRCLE_NOFILL:
834 // case SID_DRAW_CAPTION:
835 // case SID_DRAW_CAPTION_VERTICAL:
836 // case SID_TOOL_CONNECTOR:
837 // case SID_CONNECTOR_ARROW_START:
838 // case SID_CONNECTOR_ARROW_END:
839 // case SID_CONNECTOR_ARROWS:
840 // case SID_CONNECTOR_CIRCLE_START:
841 // case SID_CONNECTOR_CIRCLE_END:
842 // case SID_CONNECTOR_CIRCLES:
843 // case SID_CONNECTOR_LINE:
844 // case SID_CONNECTOR_LINE_ARROW_START:
845 // case SID_CONNECTOR_LINE_ARROW_END:
846 // case SID_CONNECTOR_LINE_ARROWS:
847 // case SID_CONNECTOR_LINE_CIRCLE_START:
848 // case SID_CONNECTOR_LINE_CIRCLE_END:
849 // case SID_CONNECTOR_LINE_CIRCLES:
850 // case SID_CONNECTOR_CURVE:
851 // case SID_CONNECTOR_CURVE_ARROW_START:
852 // case SID_CONNECTOR_CURVE_ARROW_END:
853 // case SID_CONNECTOR_CURVE_ARROWS:
854 // case SID_CONNECTOR_CURVE_CIRCLE_START:
855 // case SID_CONNECTOR_CURVE_CIRCLE_END:
856 // case SID_CONNECTOR_CURVE_CIRCLES:
857 // case SID_CONNECTOR_LINES:
858 // case SID_CONNECTOR_LINES_ARROW_START:
859 // case SID_CONNECTOR_LINES_ARROW_END:
860 // case SID_CONNECTOR_LINES_ARROWS:
861 // case SID_CONNECTOR_LINES_CIRCLE_START:
862 // case SID_CONNECTOR_LINES_CIRCLE_END:
863 // case SID_CONNECTOR_LINES_CIRCLES:
865 SdrObjectUniquePtr
pObj(SdrObjFactory::MakeNewObject(
866 mpView
->getSdrModelFromSdrView(),
867 mpView
->GetCurrentObjInventor(),
868 mpView
->GetCurrentObjIdentifier()));
872 ::tools::Rectangle
aRect(rRectangle
);
874 if(SID_DRAW_SQUARE
== nID
||
875 SID_DRAW_SQUARE_NOFILL
== nID
||
876 SID_DRAW_SQUARE_ROUND
== nID
||
877 SID_DRAW_SQUARE_ROUND_NOFILL
== nID
||
878 SID_DRAW_CIRCLE
== nID
||
879 SID_DRAW_CIRCLE_NOFILL
== nID
)
882 ImpForceQuadratic(aRect
);
885 Point aStart
= aRect
.TopLeft();
886 Point aEnd
= aRect
.BottomRight();
892 case SID_LINE_ARROW_START
:
893 case SID_LINE_ARROW_END
:
894 case SID_LINE_ARROWS
:
895 case SID_LINE_ARROW_CIRCLE
:
896 case SID_LINE_CIRCLE_ARROW
:
897 case SID_LINE_ARROW_SQUARE
:
898 case SID_LINE_SQUARE_ARROW
:
900 if( auto pPathObj
= dynamic_cast<SdrPathObj
*>( pObj
.get() ) )
902 sal_Int32
nYMiddle((aRect
.Top() + aRect
.Bottom()) / 2);
904 ::basegfx::B2DPolygon aB2DPolygon
;
905 aB2DPolygon
.append(::basegfx::B2DPoint(aStart
.X(), nYMiddle
));
906 aB2DPolygon
.append(::basegfx::B2DPoint(aEnd
.X(), nYMiddle
));
907 pPathObj
->SetPathPoly(::basegfx::B2DPolyPolygon(aB2DPolygon
));
911 OSL_FAIL("Object is NO line object");
917 case SID_DRAW_MEASURELINE
:
919 if( auto pMeasureObj
= dynamic_cast< SdrMeasureObj
*>( pObj
.get() ) )
921 sal_Int32
nYMiddle((aRect
.Top() + aRect
.Bottom()) / 2);
922 pMeasureObj
->SetPoint(Point(aStart
.X(), nYMiddle
), 0);
923 pMeasureObj
->SetPoint(Point(aEnd
.X(), nYMiddle
), 1);
927 OSL_FAIL("Object is NO measure object");
933 case SID_TOOL_CONNECTOR
:
934 case SID_CONNECTOR_ARROW_START
:
935 case SID_CONNECTOR_ARROW_END
:
936 case SID_CONNECTOR_ARROWS
:
937 case SID_CONNECTOR_CIRCLE_START
:
938 case SID_CONNECTOR_CIRCLE_END
:
939 case SID_CONNECTOR_CIRCLES
:
940 case SID_CONNECTOR_LINE
:
941 case SID_CONNECTOR_LINE_ARROW_START
:
942 case SID_CONNECTOR_LINE_ARROW_END
:
943 case SID_CONNECTOR_LINE_ARROWS
:
944 case SID_CONNECTOR_LINE_CIRCLE_START
:
945 case SID_CONNECTOR_LINE_CIRCLE_END
:
946 case SID_CONNECTOR_LINE_CIRCLES
:
947 case SID_CONNECTOR_CURVE
:
948 case SID_CONNECTOR_CURVE_ARROW_START
:
949 case SID_CONNECTOR_CURVE_ARROW_END
:
950 case SID_CONNECTOR_CURVE_ARROWS
:
951 case SID_CONNECTOR_CURVE_CIRCLE_START
:
952 case SID_CONNECTOR_CURVE_CIRCLE_END
:
953 case SID_CONNECTOR_CURVE_CIRCLES
:
954 case SID_CONNECTOR_LINES
:
955 case SID_CONNECTOR_LINES_ARROW_START
:
956 case SID_CONNECTOR_LINES_ARROW_END
:
957 case SID_CONNECTOR_LINES_ARROWS
:
958 case SID_CONNECTOR_LINES_CIRCLE_START
:
959 case SID_CONNECTOR_LINES_CIRCLE_END
:
960 case SID_CONNECTOR_LINES_CIRCLES
:
962 if( auto pEdgeObj
= dynamic_cast< SdrEdgeObj
*>( pObj
.get() ) )
964 pEdgeObj
->SetTailPoint(false, aStart
);
965 pEdgeObj
->SetTailPoint(true, aEnd
);
969 OSL_FAIL("Object is NO connector object");
974 case SID_DRAW_CAPTION
:
975 case SID_DRAW_CAPTION_VERTICAL
:
977 if( auto pCaptionObj
= dynamic_cast< SdrCaptionObj
*>( pObj
.get() ) )
979 bool bIsVertical(SID_DRAW_CAPTION_VERTICAL
== nID
);
981 pCaptionObj
->SetVerticalWriting(bIsVertical
);
985 SfxItemSet
aSet(pObj
->GetMergedItemSet());
986 aSet
.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER
));
987 aSet
.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT
));
988 pObj
->SetMergedItemSet(aSet
);
991 // The default text is not inserted anymore.
993 pCaptionObj
->SetLogicRect(aRect
);
994 pCaptionObj
->SetTailPos(
995 aRect
.TopLeft() - Point(aRect
.GetWidth() / 2, aRect
.GetHeight() / 2));
999 OSL_FAIL("Object is NO caption object");
1007 pObj
->SetLogicRect(aRect
);
1013 SfxItemSet
aAttr(mpDoc
->GetPool());
1014 SetStyleSheet(aAttr
, pObj
.get());
1015 SetAttributes(aAttr
, pObj
.get());
1016 SetLineEnds(aAttr
, *pObj
);
1017 pObj
->SetMergedItemSet(aAttr
);
1023 } // end of namespace sd
1025 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */