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/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>
62 #include <sdresid.hxx>
66 #include <drawdoc.hxx>
67 #include <unokywds.hxx>
69 #include <strings.hrc>
74 FuConstructRectangle::FuConstructRectangle (
80 : FuConstruct(pViewSh
, pWin
, pView
, pDoc
, rReq
)
81 , mnFillTransparence(0)
82 , mnLineStyle(SAL_MAX_UINT16
)
88 /// Checks to see if the request has a parameter of IsSticky:bool=true
89 /// It means that the selected command/button will stay selected after use
90 bool isSticky(const SfxRequest
& rReq
)
92 const SfxItemSet
*pArgs
= rReq
.GetArgs ();
95 const SfxBoolItem
* pIsSticky
= rReq
.GetArg
<SfxBoolItem
>(FN_PARAM_4
);
96 if (pIsSticky
&& pIsSticky
->GetValue())
105 rtl::Reference
<FuPoor
> FuConstructRectangle::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
107 FuConstructRectangle
* pFunc
;
108 rtl::Reference
<FuPoor
> xFunc( pFunc
= new FuConstructRectangle( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
109 xFunc
->DoExecute(rReq
);
110 pFunc
->SetPermanent(bPermanent
|| isSticky(rReq
));
114 void FuConstructRectangle::DoExecute( SfxRequest
& rReq
)
116 FuConstruct::DoExecute( rReq
);
118 mpViewShell
->GetViewShellBase().GetToolBarManager()->SetToolBar(
119 ToolBarManager::ToolBarGroup::Function
,
120 ToolBarManager::msDrawingObjectToolBar
);
122 const SfxItemSet
*pArgs
= rReq
.GetArgs ();
128 case SID_DRAW_ELLIPSE
:
130 const SfxUInt32Item
* pCenterX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_CENTER_X
);
131 const SfxUInt32Item
* pCenterY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_CENTER_Y
);
132 const SfxUInt32Item
* pAxisX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_AXIS_X
);
133 const SfxUInt32Item
* pAxisY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_AXIS_Y
);
135 if (!pCenterX
|| !pCenterY
|| !pAxisX
|| !pAxisY
)
138 ::tools::Rectangle
aNewRectangle (pCenterX
->GetValue () - pAxisX
->GetValue () / 2,
139 pCenterY
->GetValue () - pAxisY
->GetValue () / 2,
140 pCenterX
->GetValue () + pAxisX
->GetValue () / 2,
141 pCenterY
->GetValue () + pAxisY
->GetValue () / 2);
142 SdrCircObj
*pNewCircle
= new SdrCircObj(
143 mpView
->getSdrModelFromSdrView(),
146 SdrPageView
*pPV
= mpView
->GetSdrPageView();
148 mpView
->InsertObjectAtView(pNewCircle
, *pPV
, SdrInsertFlags::SETDEFLAYER
| SdrInsertFlags::SETDEFATTR
);
154 const SfxUInt32Item
* pMouseStartX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_MOUSESTART_X
);
155 const SfxUInt32Item
* pMouseStartY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_MOUSESTART_Y
);
156 const SfxUInt32Item
* pMouseEndX
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_MOUSEEND_X
);
157 const SfxUInt32Item
* pMouseEndY
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_MOUSEEND_Y
);
158 const SfxUInt16Item
* pFillTransparence
= rReq
.GetArg
<SfxUInt16Item
>(FN_PARAM_1
);
159 const SfxStringItem
* pFillColor
= rReq
.GetArg
<SfxStringItem
>(FN_PARAM_2
);
160 const SfxUInt16Item
* pLineStyle
= rReq
.GetArg
<SfxUInt16Item
>(FN_PARAM_3
);
161 const SfxStringItem
* pShapeName
= rReq
.GetArg
<SfxStringItem
>(SID_SHAPE_NAME
);
163 if (pFillTransparence
&& pFillTransparence
->GetValue() > 0)
165 mnFillTransparence
= pFillTransparence
->GetValue();
167 if (pFillColor
&& !pFillColor
->GetValue().isEmpty())
169 msFillColor
= pFillColor
->GetValue();
173 mnLineStyle
= pLineStyle
->GetValue();
175 if (pShapeName
&& !pShapeName
->GetValue().isEmpty())
177 msShapeName
= pShapeName
->GetValue();
180 if (!pMouseStartX
|| !pMouseStartY
|| !pMouseEndX
|| !pMouseEndY
)
183 ::tools::Rectangle
aNewRectangle (pMouseStartX
->GetValue (),
184 pMouseStartY
->GetValue (),
185 pMouseEndX
->GetValue (),
186 pMouseEndY
->GetValue ());
187 SdrRectObj
*pNewRect
= new SdrRectObj(
188 mpView
->getSdrModelFromSdrView(),
190 SdrPageView
*pPV
= mpView
->GetSdrPageView();
192 mpView
->InsertObjectAtView(pNewRect
, *pPV
, SdrInsertFlags::SETDEFLAYER
| SdrInsertFlags::SETDEFATTR
);
198 if (nSlotId
== SID_TOOL_CONNECTOR
||
199 nSlotId
== SID_CONNECTOR_ARROW_START
||
200 nSlotId
== SID_CONNECTOR_ARROW_END
||
201 nSlotId
== SID_CONNECTOR_ARROWS
||
202 nSlotId
== SID_CONNECTOR_CIRCLE_START
||
203 nSlotId
== SID_CONNECTOR_CIRCLE_END
||
204 nSlotId
== SID_CONNECTOR_CIRCLES
||
205 nSlotId
== SID_CONNECTOR_LINE
||
206 nSlotId
== SID_CONNECTOR_LINE_ARROW_START
||
207 nSlotId
== SID_CONNECTOR_LINE_ARROW_END
||
208 nSlotId
== SID_CONNECTOR_LINE_ARROWS
||
209 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_START
||
210 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_END
||
211 nSlotId
== SID_CONNECTOR_LINE_CIRCLES
||
212 nSlotId
== SID_CONNECTOR_CURVE
||
213 nSlotId
== SID_CONNECTOR_CURVE_ARROW_START
||
214 nSlotId
== SID_CONNECTOR_CURVE_ARROW_END
||
215 nSlotId
== SID_CONNECTOR_CURVE_ARROWS
||
216 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_START
||
217 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_END
||
218 nSlotId
== SID_CONNECTOR_CURVE_CIRCLES
||
219 nSlotId
== SID_CONNECTOR_LINES
||
220 nSlotId
== SID_CONNECTOR_LINES_ARROW_START
||
221 nSlotId
== SID_CONNECTOR_LINES_ARROW_END
||
222 nSlotId
== SID_CONNECTOR_LINES_ARROWS
||
223 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_START
||
224 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_END
||
225 nSlotId
== SID_CONNECTOR_LINES_CIRCLES
||
226 nSlotId
== SID_LINE_ARROW_START
||
227 nSlotId
== SID_LINE_ARROW_END
||
228 nSlotId
== SID_LINE_ARROWS
||
229 nSlotId
== SID_LINE_ARROW_CIRCLE
||
230 nSlotId
== SID_LINE_CIRCLE_ARROW
||
231 nSlotId
== SID_LINE_ARROW_SQUARE
||
232 nSlotId
== SID_LINE_SQUARE_ARROW
)
238 bool FuConstructRectangle::MouseButtonDown(const MouseEvent
& rMEvt
)
240 bool bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
242 if ( rMEvt
.IsLeft() && !mpView
->IsAction() )
244 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
246 mpWindow
->CaptureMouse();
247 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
249 if (mpView
->GetCurrentObjIdentifier() == OBJ_CAPTION
)
251 Size
aCaptionSize(846, 846); // (4x2)cm
252 bReturn
= mpView
->BegCreateCaptionObj(aPnt
, aCaptionSize
,
257 mpView
->BegCreateObj(aPnt
, nullptr, nDrgLog
);
260 SdrObject
* pObj
= mpView
->GetCreateObj();
264 SfxItemSet
aAttr(mpDoc
->GetPool());
265 SetStyleSheet(aAttr
, pObj
);
266 SetAttributes(aAttr
, pObj
);
267 SetLineEnds(aAttr
, *pObj
);
268 pObj
->SetMergedItemSet(aAttr
);
270 if( nSlotId
== SID_DRAW_CAPTION_VERTICAL
)
271 static_cast<SdrTextObj
*>(pObj
)->SetVerticalWriting( true );
277 bool FuConstructRectangle::MouseButtonUp(const MouseEvent
& rMEvt
)
281 if(mpView
->IsCreateObj() && rMEvt
.IsLeft())
283 SdrObject
* pObj
= mpView
->GetCreateObj();
285 if(pObj
&& mpView
->EndCreateObj(SdrCreateCmd::ForceEnd
))
287 if(SID_DRAW_MEASURELINE
== nSlotId
)
289 SdrLayerAdmin
& rAdmin
= mpDoc
->GetLayerAdmin();
290 pObj
->SetLayer(rAdmin
.GetLayerID(sUNO_LayerName_measurelines
));
293 // init text position when vertical caption object is created
294 if( dynamic_cast< const SdrCaptionObj
*>( pObj
) != nullptr && SID_DRAW_CAPTION_VERTICAL
== nSlotId
)
296 // draw text object, needs to be initialized when vertical text is used
297 SfxItemSet
aSet(pObj
->GetMergedItemSet());
299 aSet
.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER
));
300 aSet
.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT
));
302 // Correct the value of SDRATTR_TEXTDIRECTION to avoid SetItemSet
303 // calling SetVerticalWriting() again since this item may not yet
304 // be set at the object and thus may differ from vertical state of
306 aSet
.Put(SvxWritingModeItem(css::text::WritingMode_TB_RL
, SDRATTR_TEXTDIRECTION
));
307 pObj
->SetMergedItemSet(aSet
);
314 bReturn
= FuConstruct::MouseButtonUp (rMEvt
) || bReturn
;
317 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
322 void FuConstructRectangle::Activate()
328 case SID_LINE_ARROW_START
:
329 case SID_LINE_ARROW_END
:
330 case SID_LINE_ARROWS
:
331 case SID_LINE_ARROW_CIRCLE
:
332 case SID_LINE_CIRCLE_ARROW
:
333 case SID_LINE_ARROW_SQUARE
:
334 case SID_LINE_SQUARE_ARROW
:
335 mpView
->SetGlueVisible();
342 case SID_DRAW_MEASURELINE
:
344 aObjKind
= OBJ_MEASURE
;
349 case SID_DRAW_RECT_NOFILL
:
350 case SID_DRAW_RECT_ROUND
:
351 case SID_DRAW_RECT_ROUND_NOFILL
:
352 case SID_DRAW_SQUARE
:
353 case SID_DRAW_SQUARE_NOFILL
:
354 case SID_DRAW_SQUARE_ROUND
:
355 case SID_DRAW_SQUARE_ROUND_NOFILL
:
361 case SID_DRAW_ELLIPSE
:
362 case SID_DRAW_ELLIPSE_NOFILL
:
363 case SID_DRAW_CIRCLE
:
364 case SID_DRAW_CIRCLE_NOFILL
:
370 case SID_DRAW_CAPTION
:
371 case SID_DRAW_CAPTION_VERTICAL
:
373 aObjKind
= OBJ_CAPTION
;
377 case SID_TOOL_CONNECTOR
:
378 case SID_CONNECTOR_ARROW_START
:
379 case SID_CONNECTOR_ARROW_END
:
380 case SID_CONNECTOR_ARROWS
:
381 case SID_CONNECTOR_CIRCLE_START
:
382 case SID_CONNECTOR_CIRCLE_END
:
383 case SID_CONNECTOR_CIRCLES
:
384 case SID_CONNECTOR_LINE
:
385 case SID_CONNECTOR_LINE_ARROW_START
:
386 case SID_CONNECTOR_LINE_ARROW_END
:
387 case SID_CONNECTOR_LINE_ARROWS
:
388 case SID_CONNECTOR_LINE_CIRCLE_START
:
389 case SID_CONNECTOR_LINE_CIRCLE_END
:
390 case SID_CONNECTOR_LINE_CIRCLES
:
391 case SID_CONNECTOR_CURVE
:
392 case SID_CONNECTOR_CURVE_ARROW_START
:
393 case SID_CONNECTOR_CURVE_ARROW_END
:
394 case SID_CONNECTOR_CURVE_ARROWS
:
395 case SID_CONNECTOR_CURVE_CIRCLE_START
:
396 case SID_CONNECTOR_CURVE_CIRCLE_END
:
397 case SID_CONNECTOR_CURVE_CIRCLES
:
398 case SID_CONNECTOR_LINES
:
399 case SID_CONNECTOR_LINES_ARROW_START
:
400 case SID_CONNECTOR_LINES_ARROW_END
:
401 case SID_CONNECTOR_LINES_ARROWS
:
402 case SID_CONNECTOR_LINES_CIRCLE_START
:
403 case SID_CONNECTOR_LINES_CIRCLE_END
:
404 case SID_CONNECTOR_LINES_CIRCLES
:
407 mpView
->SetGlueVisible();
418 mpView
->SetCurrentObj(static_cast<sal_uInt16
>(aObjKind
));
420 FuConstruct::Activate();
423 void FuConstructRectangle::Deactivate()
425 if( nSlotId
== SID_TOOL_CONNECTOR
||
426 nSlotId
== SID_CONNECTOR_ARROW_START
||
427 nSlotId
== SID_CONNECTOR_ARROW_END
||
428 nSlotId
== SID_CONNECTOR_ARROWS
||
429 nSlotId
== SID_CONNECTOR_CIRCLE_START
||
430 nSlotId
== SID_CONNECTOR_CIRCLE_END
||
431 nSlotId
== SID_CONNECTOR_CIRCLES
||
432 nSlotId
== SID_CONNECTOR_LINE
||
433 nSlotId
== SID_CONNECTOR_LINE_ARROW_START
||
434 nSlotId
== SID_CONNECTOR_LINE_ARROW_END
||
435 nSlotId
== SID_CONNECTOR_LINE_ARROWS
||
436 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_START
||
437 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_END
||
438 nSlotId
== SID_CONNECTOR_LINE_CIRCLES
||
439 nSlotId
== SID_CONNECTOR_CURVE
||
440 nSlotId
== SID_CONNECTOR_CURVE_ARROW_START
||
441 nSlotId
== SID_CONNECTOR_CURVE_ARROW_END
||
442 nSlotId
== SID_CONNECTOR_CURVE_ARROWS
||
443 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_START
||
444 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_END
||
445 nSlotId
== SID_CONNECTOR_CURVE_CIRCLES
||
446 nSlotId
== SID_CONNECTOR_LINES
||
447 nSlotId
== SID_CONNECTOR_LINES_ARROW_START
||
448 nSlotId
== SID_CONNECTOR_LINES_ARROW_END
||
449 nSlotId
== SID_CONNECTOR_LINES_ARROWS
||
450 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_START
||
451 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_END
||
452 nSlotId
== SID_CONNECTOR_LINES_CIRCLES
||
453 nSlotId
== SID_LINE_ARROW_START
||
454 nSlotId
== SID_LINE_ARROW_END
||
455 nSlotId
== SID_LINE_ARROWS
||
456 nSlotId
== SID_LINE_ARROW_CIRCLE
||
457 nSlotId
== SID_LINE_CIRCLE_ARROW
||
458 nSlotId
== SID_LINE_ARROW_SQUARE
||
459 nSlotId
== SID_LINE_SQUARE_ARROW
)
461 mpView
->SetGlueVisible( false );
463 FuConstruct::Deactivate();
467 /// Returns the color based on the color names listed in core/include/tools/color.hxx
468 /// Feel free to extend with more color names from color.hxx
469 Color
strToColor(const OUString
& sColor
)
471 Color aColor
= COL_AUTO
;
473 if (sColor
== "COL_GRAY")
475 else if (sColor
== "COL_GRAY3")
477 else if (sColor
== "COL_GRAY7")
485 * set attribute for the object to be created
487 void FuConstructRectangle::SetAttributes(SfxItemSet
& rAttr
, SdrObject
* pObj
)
489 if (nSlotId
== SID_DRAW_RECT_ROUND
||
490 nSlotId
== SID_DRAW_RECT_ROUND_NOFILL
||
491 nSlotId
== SID_DRAW_SQUARE_ROUND
||
492 nSlotId
== SID_DRAW_SQUARE_ROUND_NOFILL
)
495 rAttr
.Put(makeSdrEckenradiusItem(500));
497 else if (nSlotId
== SID_CONNECTOR_LINE
||
498 nSlotId
== SID_CONNECTOR_LINE_ARROW_START
||
499 nSlotId
== SID_CONNECTOR_LINE_ARROW_END
||
500 nSlotId
== SID_CONNECTOR_LINE_ARROWS
||
501 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_START
||
502 nSlotId
== SID_CONNECTOR_LINE_CIRCLE_END
||
503 nSlotId
== SID_CONNECTOR_LINE_CIRCLES
)
506 rAttr
.Put(SdrEdgeKindItem(SdrEdgeKind::OneLine
));
508 else if (nSlotId
== SID_CONNECTOR_LINES
||
509 nSlotId
== SID_CONNECTOR_LINES_ARROW_START
||
510 nSlotId
== SID_CONNECTOR_LINES_ARROW_END
||
511 nSlotId
== SID_CONNECTOR_LINES_ARROWS
||
512 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_START
||
513 nSlotId
== SID_CONNECTOR_LINES_CIRCLE_END
||
514 nSlotId
== SID_CONNECTOR_LINES_CIRCLES
)
517 rAttr
.Put(SdrEdgeKindItem(SdrEdgeKind::ThreeLines
));
519 else if (nSlotId
== SID_CONNECTOR_CURVE
||
520 nSlotId
== SID_CONNECTOR_CURVE_ARROW_START
||
521 nSlotId
== SID_CONNECTOR_CURVE_ARROW_END
||
522 nSlotId
== SID_CONNECTOR_CURVE_ARROWS
||
523 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_START
||
524 nSlotId
== SID_CONNECTOR_CURVE_CIRCLE_END
||
525 nSlotId
== SID_CONNECTOR_CURVE_CIRCLES
)
528 rAttr
.Put(SdrEdgeKindItem(SdrEdgeKind::Bezier
));
530 else if ( nSlotId
== SID_DRAW_CAPTION
|| nSlotId
== SID_DRAW_CAPTION_VERTICAL
)
533 Size
aSize(pObj
->GetLogicRect().GetSize());
534 rAttr
.Put( makeSdrTextMinFrameHeightItem( aSize
.Height() ) );
535 rAttr
.Put( makeSdrTextMinFrameWidthItem( aSize
.Width() ) );
536 rAttr
.Put( makeSdrTextAutoGrowHeightItem( true ) );
537 rAttr
.Put( makeSdrTextAutoGrowWidthItem( true ) );
539 // Support full with for vertical caption objects, too
540 if(SID_DRAW_CAPTION
== nSlotId
)
541 rAttr
.Put( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK
) );
543 rAttr
.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_BLOCK
) );
545 rAttr
.Put( SvxAdjustItem( SvxAdjust::Center
, EE_PARA_JUST
) );
546 rAttr
.Put( makeSdrTextLeftDistItem( 100 ) );
547 rAttr
.Put( makeSdrTextRightDistItem( 100 ) );
548 rAttr
.Put( makeSdrTextUpperDistItem( 100 ) );
549 rAttr
.Put( makeSdrTextLowerDistItem( 100 ) );
551 else if (nSlotId
== SID_DRAW_MEASURELINE
)
554 SdPage
* pPage
= static_cast<SdPage
*>( mpView
->GetSdrPageView()->GetPage() );
555 OUString
aName(SdResId(STR_POOLSHEET_MEASURE
));
556 SfxStyleSheet
* pSheet(
557 static_cast< SfxStyleSheet
* >(
558 pPage
->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName
, SfxStyleFamily::Para
)));
559 DBG_ASSERT(pSheet
, "StyleSheet missing");
563 pObj
->SetStyleSheet(pSheet
, false);
566 SdrLayerAdmin
& rAdmin
= mpDoc
->GetLayerAdmin();
567 pObj
->SetLayer(rAdmin
.GetLayerID(sUNO_LayerName_measurelines
));
569 else if (nSlotId
== SID_DRAW_RECT
)
571 if (mnFillTransparence
> 0 && mnFillTransparence
<= 100)
572 rAttr
.Put(XFillTransparenceItem(mnFillTransparence
));
573 if (!msFillColor
.isEmpty())
574 rAttr
.Put(XFillColorItem(OUString(), strToColor(msFillColor
)));
575 if (!msShapeName
.isEmpty())
576 pObj
->SetName(msShapeName
);
581 rAttr
.Put( XLineStyleItem(css::drawing::LineStyle_NONE
) );
584 rAttr
.Put( XLineStyleItem(css::drawing::LineStyle_SOLID
) );
587 rAttr
.Put( XLineStyleItem(css::drawing::LineStyle_DASH
) );
590 // Leave it to the defaults
597 * set line starts and ends for the object to be created
599 static ::basegfx::B2DPolyPolygon
getPolygon(const char* pResId
, const SdrModel
& rModel
)
601 ::basegfx::B2DPolyPolygon aRetval
;
602 XLineEndListRef
pLineEndList(rModel
.GetLineEndList());
604 if( pLineEndList
.is() )
606 OUString
aArrowName(SvxResId(pResId
));
607 long nCount
= pLineEndList
->Count();
609 for( nIndex
= 0; nIndex
< nCount
; nIndex
++ )
611 const XLineEndEntry
* pEntry
= pLineEndList
->GetLineEnd(nIndex
);
612 if( pEntry
->GetName() == aArrowName
)
614 aRetval
= pEntry
->GetLineEnd();
623 void FuConstructRectangle::SetLineEnds(SfxItemSet
& rAttr
, SdrObject
const & rObj
)
625 if ( !((rObj
.GetObjIdentifier() == OBJ_EDGE
&&
626 nSlotId
!= SID_TOOL_CONNECTOR
&&
627 nSlotId
!= SID_CONNECTOR_LINE
&&
628 nSlotId
!= SID_CONNECTOR_LINES
&&
629 nSlotId
!= SID_CONNECTOR_CURVE
) ||
630 nSlotId
== SID_LINE_ARROW_START
||
631 nSlotId
== SID_LINE_ARROW_END
||
632 nSlotId
== SID_LINE_ARROWS
||
633 nSlotId
== SID_LINE_ARROW_CIRCLE
||
634 nSlotId
== SID_LINE_CIRCLE_ARROW
||
635 nSlotId
== SID_LINE_ARROW_SQUARE
||
636 nSlotId
== SID_LINE_SQUARE_ARROW
) )
639 // set attributes of line start and ends
640 SdrModel
& rModel(rObj
.getSdrModelFromSdrObject());
643 ::basegfx::B2DPolyPolygon
aArrow( getPolygon( RID_SVXSTR_ARROW
, rModel
) );
644 if( !aArrow
.count() )
646 ::basegfx::B2DPolygon aNewArrow
;
647 aNewArrow
.append(::basegfx::B2DPoint(10.0, 0.0));
648 aNewArrow
.append(::basegfx::B2DPoint(0.0, 30.0));
649 aNewArrow
.append(::basegfx::B2DPoint(20.0, 30.0));
650 aNewArrow
.setClosed(true);
651 aArrow
.append(aNewArrow
);
655 ::basegfx::B2DPolyPolygon
aCircle( getPolygon( RID_SVXSTR_CIRCLE
, rModel
) );
656 if( !aCircle
.count() )
658 ::basegfx::B2DPolygon aNewCircle
= ::basegfx::utils::createPolygonFromEllipse(::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0);
659 aNewCircle
.setClosed(true);
660 aCircle
.append(aNewCircle
);
664 ::basegfx::B2DPolyPolygon
aSquare( getPolygon( RID_SVXSTR_SQUARE
, rModel
) );
665 if( !aSquare
.count() )
667 ::basegfx::B2DPolygon aNewSquare
;
668 aNewSquare
.append(::basegfx::B2DPoint(0.0, 0.0));
669 aNewSquare
.append(::basegfx::B2DPoint(10.0, 0.0));
670 aNewSquare
.append(::basegfx::B2DPoint(10.0, 10.0));
671 aNewSquare
.append(::basegfx::B2DPoint(0.0, 10.0));
672 aNewSquare
.setClosed(true);
673 aSquare
.append(aNewSquare
);
676 SfxItemSet
aSet( mpDoc
->GetPool() );
677 mpView
->GetAttributes( aSet
);
679 // #i3908# Here, the default Line Start/End width for arrow construction is
680 // set. To have the same value in all situations (construction) in i3908
681 // it was decided to change the default to 0.03 cm for all situations.
682 long nWidth
= 300; // (1/100th mm)
684 // determine line width and calculate with it the line end width
685 if( aSet
.GetItemState( XATTR_LINEWIDTH
) != SfxItemState::DONTCARE
)
687 long nValue
= aSet
.Get( XATTR_LINEWIDTH
).GetValue();
694 case SID_CONNECTOR_ARROWS
:
695 case SID_CONNECTOR_LINE_ARROWS
:
696 case SID_CONNECTOR_LINES_ARROWS
:
697 case SID_CONNECTOR_CURVE_ARROWS
:
698 case SID_LINE_ARROWS
:
700 // connector with arrow ends
701 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW
), aArrow
));
702 rAttr
.Put(XLineStartWidthItem(nWidth
));
703 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW
), aArrow
));
704 rAttr
.Put(XLineEndWidthItem(nWidth
));
708 case SID_CONNECTOR_ARROW_START
:
709 case SID_CONNECTOR_LINE_ARROW_START
:
710 case SID_CONNECTOR_LINES_ARROW_START
:
711 case SID_CONNECTOR_CURVE_ARROW_START
:
712 case SID_LINE_ARROW_START
:
713 case SID_LINE_ARROW_CIRCLE
:
714 case SID_LINE_ARROW_SQUARE
:
716 // connector with arrow start
717 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW
), aArrow
));
718 rAttr
.Put(XLineStartWidthItem(nWidth
));
722 case SID_CONNECTOR_ARROW_END
:
723 case SID_CONNECTOR_LINE_ARROW_END
:
724 case SID_CONNECTOR_LINES_ARROW_END
:
725 case SID_CONNECTOR_CURVE_ARROW_END
:
726 case SID_LINE_ARROW_END
:
727 case SID_LINE_CIRCLE_ARROW
:
728 case SID_LINE_SQUARE_ARROW
:
730 // connector with arrow end
731 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW
), aArrow
));
732 rAttr
.Put(XLineEndWidthItem(nWidth
));
736 case SID_CONNECTOR_CIRCLES
:
737 case SID_CONNECTOR_LINE_CIRCLES
:
738 case SID_CONNECTOR_LINES_CIRCLES
:
739 case SID_CONNECTOR_CURVE_CIRCLES
:
741 // connector with circle ends
742 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
743 rAttr
.Put(XLineStartWidthItem(nWidth
));
744 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
745 rAttr
.Put(XLineEndWidthItem(nWidth
));
749 case SID_CONNECTOR_CIRCLE_START
:
750 case SID_CONNECTOR_LINE_CIRCLE_START
:
751 case SID_CONNECTOR_LINES_CIRCLE_START
:
752 case SID_CONNECTOR_CURVE_CIRCLE_START
:
754 // connector with circle start
755 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
756 rAttr
.Put(XLineStartWidthItem(nWidth
));
760 case SID_CONNECTOR_CIRCLE_END
:
761 case SID_CONNECTOR_LINE_CIRCLE_END
:
762 case SID_CONNECTOR_LINES_CIRCLE_END
:
763 case SID_CONNECTOR_CURVE_CIRCLE_END
:
765 // connector with circle ends
766 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
767 rAttr
.Put(XLineEndWidthItem(nWidth
));
772 // and again, for the still missing ends
775 case SID_LINE_ARROW_CIRCLE
:
778 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
779 rAttr
.Put(XLineEndWidthItem(nWidth
));
783 case SID_LINE_CIRCLE_ARROW
:
786 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE
), aCircle
));
787 rAttr
.Put(XLineStartWidthItem(nWidth
));
791 case SID_LINE_ARROW_SQUARE
:
794 rAttr
.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE
), aSquare
));
795 rAttr
.Put(XLineEndWidthItem(nWidth
));
799 case SID_LINE_SQUARE_ARROW
:
802 rAttr
.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE
), aSquare
));
803 rAttr
.Put(XLineStartWidthItem(nWidth
));
809 SdrObjectUniquePtr
FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID
, const ::tools::Rectangle
& rRectangle
)
811 DBG_ASSERT( (nID
!= SID_DRAW_FONTWORK
) && (nID
!= SID_DRAW_FONTWORK_VERTICAL
), "FuConstRectangle::CreateDefaultObject can not create Fontwork shapes!" );
813 // case SID_DRAW_LINE:
814 // case SID_DRAW_XLINE:
815 // case SID_DRAW_MEASURELINE:
816 // case SID_LINE_ARROW_START:
817 // case SID_LINE_ARROW_END:
818 // case SID_LINE_ARROWS:
819 // case SID_LINE_ARROW_CIRCLE:
820 // case SID_LINE_CIRCLE_ARROW:
821 // case SID_LINE_ARROW_SQUARE:
822 // case SID_LINE_SQUARE_ARROW:
823 // case SID_DRAW_RECT:
824 // case SID_DRAW_RECT_NOFILL:
825 // case SID_DRAW_RECT_ROUND:
826 // case SID_DRAW_RECT_ROUND_NOFILL:
827 // case SID_DRAW_SQUARE:
828 // case SID_DRAW_SQUARE_NOFILL:
829 // case SID_DRAW_SQUARE_ROUND:
830 // case SID_DRAW_SQUARE_ROUND_NOFILL:
831 // case SID_DRAW_ELLIPSE:
832 // case SID_DRAW_ELLIPSE_NOFILL:
833 // case SID_DRAW_CIRCLE:
834 // case SID_DRAW_CIRCLE_NOFILL:
835 // case SID_DRAW_CAPTION:
836 // case SID_DRAW_CAPTION_VERTICAL:
837 // case SID_TOOL_CONNECTOR:
838 // case SID_CONNECTOR_ARROW_START:
839 // case SID_CONNECTOR_ARROW_END:
840 // case SID_CONNECTOR_ARROWS:
841 // case SID_CONNECTOR_CIRCLE_START:
842 // case SID_CONNECTOR_CIRCLE_END:
843 // case SID_CONNECTOR_CIRCLES:
844 // case SID_CONNECTOR_LINE:
845 // case SID_CONNECTOR_LINE_ARROW_START:
846 // case SID_CONNECTOR_LINE_ARROW_END:
847 // case SID_CONNECTOR_LINE_ARROWS:
848 // case SID_CONNECTOR_LINE_CIRCLE_START:
849 // case SID_CONNECTOR_LINE_CIRCLE_END:
850 // case SID_CONNECTOR_LINE_CIRCLES:
851 // case SID_CONNECTOR_CURVE:
852 // case SID_CONNECTOR_CURVE_ARROW_START:
853 // case SID_CONNECTOR_CURVE_ARROW_END:
854 // case SID_CONNECTOR_CURVE_ARROWS:
855 // case SID_CONNECTOR_CURVE_CIRCLE_START:
856 // case SID_CONNECTOR_CURVE_CIRCLE_END:
857 // case SID_CONNECTOR_CURVE_CIRCLES:
858 // case SID_CONNECTOR_LINES:
859 // case SID_CONNECTOR_LINES_ARROW_START:
860 // case SID_CONNECTOR_LINES_ARROW_END:
861 // case SID_CONNECTOR_LINES_ARROWS:
862 // case SID_CONNECTOR_LINES_CIRCLE_START:
863 // case SID_CONNECTOR_LINES_CIRCLE_END:
864 // case SID_CONNECTOR_LINES_CIRCLES:
866 SdrObjectUniquePtr
pObj(SdrObjFactory::MakeNewObject(
867 mpView
->getSdrModelFromSdrView(),
868 mpView
->GetCurrentObjInventor(),
869 mpView
->GetCurrentObjIdentifier()));
873 ::tools::Rectangle
aRect(rRectangle
);
875 if(SID_DRAW_SQUARE
== nID
||
876 SID_DRAW_SQUARE_NOFILL
== nID
||
877 SID_DRAW_SQUARE_ROUND
== nID
||
878 SID_DRAW_SQUARE_ROUND_NOFILL
== nID
||
879 SID_DRAW_CIRCLE
== nID
||
880 SID_DRAW_CIRCLE_NOFILL
== nID
)
883 ImpForceQuadratic(aRect
);
886 Point aStart
= aRect
.TopLeft();
887 Point aEnd
= aRect
.BottomRight();
893 case SID_LINE_ARROW_START
:
894 case SID_LINE_ARROW_END
:
895 case SID_LINE_ARROWS
:
896 case SID_LINE_ARROW_CIRCLE
:
897 case SID_LINE_CIRCLE_ARROW
:
898 case SID_LINE_ARROW_SQUARE
:
899 case SID_LINE_SQUARE_ARROW
:
901 if( auto pPathObj
= dynamic_cast<SdrPathObj
*>( pObj
.get() ) )
903 sal_Int32
nYMiddle((aRect
.Top() + aRect
.Bottom()) / 2);
905 ::basegfx::B2DPolygon aB2DPolygon
;
906 aB2DPolygon
.append(::basegfx::B2DPoint(aStart
.X(), nYMiddle
));
907 aB2DPolygon
.append(::basegfx::B2DPoint(aEnd
.X(), nYMiddle
));
908 pPathObj
->SetPathPoly(::basegfx::B2DPolyPolygon(aB2DPolygon
));
912 OSL_FAIL("Object is NO line object");
918 case SID_DRAW_MEASURELINE
:
920 if( auto pMeasureObj
= dynamic_cast< SdrMeasureObj
*>( pObj
.get() ) )
922 sal_Int32
nYMiddle((aRect
.Top() + aRect
.Bottom()) / 2);
923 pMeasureObj
->SetPoint(Point(aStart
.X(), nYMiddle
), 0);
924 pMeasureObj
->SetPoint(Point(aEnd
.X(), nYMiddle
), 1);
928 OSL_FAIL("Object is NO measure object");
934 case SID_TOOL_CONNECTOR
:
935 case SID_CONNECTOR_ARROW_START
:
936 case SID_CONNECTOR_ARROW_END
:
937 case SID_CONNECTOR_ARROWS
:
938 case SID_CONNECTOR_CIRCLE_START
:
939 case SID_CONNECTOR_CIRCLE_END
:
940 case SID_CONNECTOR_CIRCLES
:
941 case SID_CONNECTOR_LINE
:
942 case SID_CONNECTOR_LINE_ARROW_START
:
943 case SID_CONNECTOR_LINE_ARROW_END
:
944 case SID_CONNECTOR_LINE_ARROWS
:
945 case SID_CONNECTOR_LINE_CIRCLE_START
:
946 case SID_CONNECTOR_LINE_CIRCLE_END
:
947 case SID_CONNECTOR_LINE_CIRCLES
:
948 case SID_CONNECTOR_CURVE
:
949 case SID_CONNECTOR_CURVE_ARROW_START
:
950 case SID_CONNECTOR_CURVE_ARROW_END
:
951 case SID_CONNECTOR_CURVE_ARROWS
:
952 case SID_CONNECTOR_CURVE_CIRCLE_START
:
953 case SID_CONNECTOR_CURVE_CIRCLE_END
:
954 case SID_CONNECTOR_CURVE_CIRCLES
:
955 case SID_CONNECTOR_LINES
:
956 case SID_CONNECTOR_LINES_ARROW_START
:
957 case SID_CONNECTOR_LINES_ARROW_END
:
958 case SID_CONNECTOR_LINES_ARROWS
:
959 case SID_CONNECTOR_LINES_CIRCLE_START
:
960 case SID_CONNECTOR_LINES_CIRCLE_END
:
961 case SID_CONNECTOR_LINES_CIRCLES
:
963 if( auto pEdgeObj
= dynamic_cast< SdrEdgeObj
*>( pObj
.get() ) )
965 pEdgeObj
->SetTailPoint(false, aStart
);
966 pEdgeObj
->SetTailPoint(true, aEnd
);
970 OSL_FAIL("Object is NO connector object");
975 case SID_DRAW_CAPTION
:
976 case SID_DRAW_CAPTION_VERTICAL
:
978 if( auto pCaptionObj
= dynamic_cast< SdrCaptionObj
*>( pObj
.get() ) )
980 bool bIsVertical(SID_DRAW_CAPTION_VERTICAL
== nID
);
982 pCaptionObj
->SetVerticalWriting(bIsVertical
);
986 SfxItemSet
aSet(pObj
->GetMergedItemSet());
987 aSet
.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER
));
988 aSet
.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT
));
989 pObj
->SetMergedItemSet(aSet
);
992 // The default text is not inserted anymore.
994 pCaptionObj
->SetLogicRect(aRect
);
995 pCaptionObj
->SetTailPos(
996 aRect
.TopLeft() - Point(aRect
.GetWidth() / 2, aRect
.GetHeight() / 2));
1000 OSL_FAIL("Object is NO caption object");
1008 pObj
->SetLogicRect(aRect
);
1014 SfxItemSet
aAttr(mpDoc
->GetPool());
1015 SetStyleSheet(aAttr
, pObj
.get());
1016 SetAttributes(aAttr
, pObj
.get());
1017 SetLineEnds(aAttr
, *pObj
);
1018 pObj
->SetMergedItemSet(aAttr
);
1024 } // end of namespace sd
1026 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */