Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "fuconrec.hxx"
21 : #include <svx/svdpagv.hxx>
22 :
23 : #include <svx/svxids.hrc>
24 : #include <svx/dialogs.hrc>
25 : #include <svx/dialmgr.hxx>
26 :
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>
45 :
46 : #include <svx/svdocapt.hxx>
47 :
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>
55 :
56 : #include "sdresid.hxx"
57 : #include "View.hxx"
58 : #include "sdpage.hxx"
59 : #include "Window.hxx"
60 : #include "stlpool.hxx"
61 : #include "drawdoc.hxx"
62 : #include "res_bmp.hrc"
63 : #include "glob.hrc"
64 :
65 : namespace sd {
66 :
67 0 : TYPEINIT1( FuConstructRectangle, FuConstruct );
68 :
69 0 : FuConstructRectangle::FuConstructRectangle (
70 : ViewShell* pViewSh,
71 : ::sd::Window* pWin,
72 : ::sd::View* pView,
73 : SdDrawDocument* pDoc,
74 : SfxRequest& rReq)
75 0 : : FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
76 : {
77 0 : }
78 :
79 0 : rtl::Reference<FuPoor> FuConstructRectangle::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
80 : {
81 : FuConstructRectangle* pFunc;
82 0 : rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructRectangle( pViewSh, pWin, pView, pDoc, rReq ) );
83 0 : xFunc->DoExecute(rReq);
84 0 : pFunc->SetPermanent(bPermanent);
85 0 : return xFunc;
86 : }
87 :
88 0 : void FuConstructRectangle::DoExecute( SfxRequest& rReq )
89 : {
90 0 : FuConstruct::DoExecute( rReq );
91 :
92 0 : mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
93 : ToolBarManager::TBG_FUNCTION,
94 0 : ToolBarManager::msDrawingObjectToolBar);
95 :
96 0 : const SfxItemSet *pArgs = rReq.GetArgs ();
97 :
98 0 : if (pArgs)
99 : {
100 0 : switch (nSlotId)
101 : {
102 : case SID_DRAW_ELLIPSE :
103 : {
104 0 : SFX_REQUEST_ARG (rReq, pCenterX, SfxUInt32Item, ID_VAL_CENTER_X, false);
105 0 : SFX_REQUEST_ARG (rReq, pCenterY, SfxUInt32Item, ID_VAL_CENTER_Y, false);
106 0 : SFX_REQUEST_ARG (rReq, pAxisX, SfxUInt32Item, ID_VAL_AXIS_X, false);
107 0 : SFX_REQUEST_ARG (rReq, pAxisY, SfxUInt32Item, ID_VAL_AXIS_Y, false);
108 :
109 0 : Rectangle aNewRectangle (pCenterX->GetValue () - pAxisX->GetValue () / 2,
110 0 : pCenterY->GetValue () - pAxisY->GetValue () / 2,
111 0 : pCenterX->GetValue () + pAxisX->GetValue () / 2,
112 0 : pCenterY->GetValue () + pAxisY->GetValue () / 2);
113 0 : SdrCircObj *pNewCircle = new SdrCircObj (OBJ_CIRC, aNewRectangle);
114 0 : SdrPageView *pPV = mpView->GetSdrPageView();
115 :
116 0 : mpView->InsertObjectAtView(pNewCircle, *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
117 : }
118 0 : break;
119 :
120 : case SID_DRAW_RECT :
121 : {
122 0 : SFX_REQUEST_ARG (rReq, pMouseStartX, SfxUInt32Item, ID_VAL_MOUSESTART_X, false);
123 0 : SFX_REQUEST_ARG (rReq, pMouseStartY, SfxUInt32Item, ID_VAL_MOUSESTART_Y, false);
124 0 : SFX_REQUEST_ARG (rReq, pMouseEndX, SfxUInt32Item, ID_VAL_MOUSEEND_X, false);
125 0 : SFX_REQUEST_ARG (rReq, pMouseEndY, SfxUInt32Item, ID_VAL_MOUSEEND_Y, false);
126 :
127 0 : Rectangle aNewRectangle (pMouseStartX->GetValue (),
128 0 : pMouseStartY->GetValue (),
129 0 : pMouseEndX->GetValue (),
130 0 : pMouseEndY->GetValue ());
131 0 : SdrRectObj *pNewRect = new SdrRectObj (aNewRectangle);
132 0 : SdrPageView *pPV = mpView->GetSdrPageView();
133 :
134 0 : mpView->InsertObjectAtView(pNewRect, *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
135 : }
136 0 : break;
137 : }
138 : }
139 :
140 0 : if (nSlotId == SID_TOOL_CONNECTOR ||
141 0 : nSlotId == SID_CONNECTOR_ARROW_START ||
142 0 : nSlotId == SID_CONNECTOR_ARROW_END ||
143 0 : nSlotId == SID_CONNECTOR_ARROWS ||
144 0 : nSlotId == SID_CONNECTOR_CIRCLE_START ||
145 0 : nSlotId == SID_CONNECTOR_CIRCLE_END ||
146 0 : nSlotId == SID_CONNECTOR_CIRCLES ||
147 0 : nSlotId == SID_CONNECTOR_LINE ||
148 0 : nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
149 0 : nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
150 0 : nSlotId == SID_CONNECTOR_LINE_ARROWS ||
151 0 : nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
152 0 : nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
153 0 : nSlotId == SID_CONNECTOR_LINE_CIRCLES ||
154 0 : nSlotId == SID_CONNECTOR_CURVE ||
155 0 : nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
156 0 : nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
157 0 : nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
158 0 : nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
159 0 : nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
160 0 : nSlotId == SID_CONNECTOR_CURVE_CIRCLES ||
161 0 : nSlotId == SID_CONNECTOR_LINES ||
162 0 : nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
163 0 : nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
164 0 : nSlotId == SID_CONNECTOR_LINES_ARROWS ||
165 0 : nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
166 0 : nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
167 0 : nSlotId == SID_CONNECTOR_LINES_CIRCLES ||
168 0 : nSlotId == SID_LINE_ARROW_START ||
169 0 : nSlotId == SID_LINE_ARROW_END ||
170 0 : nSlotId == SID_LINE_ARROWS ||
171 0 : nSlotId == SID_LINE_ARROW_CIRCLE ||
172 0 : nSlotId == SID_LINE_CIRCLE_ARROW ||
173 0 : nSlotId == SID_LINE_ARROW_SQUARE ||
174 0 : nSlotId == SID_LINE_SQUARE_ARROW )
175 : {
176 0 : mpView->UnmarkAll();
177 : }
178 0 : }
179 :
180 0 : bool FuConstructRectangle::MouseButtonDown(const MouseEvent& rMEvt)
181 : {
182 0 : bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
183 :
184 0 : if ( rMEvt.IsLeft() && !mpView->IsAction() )
185 : {
186 0 : Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
187 :
188 0 : mpWindow->CaptureMouse();
189 0 : sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
190 :
191 0 : if (mpView->GetCurrentObjIdentifier() == OBJ_CAPTION)
192 : {
193 0 : Size aCaptionSize(846, 846); // (4x2)cm
194 : bReturn = mpView->BegCreateCaptionObj(aPnt, aCaptionSize,
195 0 : nullptr, nDrgLog);
196 : }
197 : else
198 : {
199 0 : mpView->BegCreateObj(aPnt, nullptr, nDrgLog);
200 : }
201 :
202 0 : SdrObject* pObj = mpView->GetCreateObj();
203 :
204 0 : if (pObj)
205 : {
206 0 : SfxItemSet aAttr(mpDoc->GetPool());
207 0 : SetStyleSheet(aAttr, pObj);
208 0 : SetAttributes(aAttr, pObj);
209 0 : SetLineEnds(aAttr, pObj);
210 0 : pObj->SetMergedItemSet(aAttr);
211 :
212 0 : if( nSlotId == SID_DRAW_CAPTION_VERTICAL )
213 0 : static_cast<SdrTextObj*>(pObj)->SetVerticalWriting( true );
214 : }
215 : }
216 0 : return bReturn;
217 : }
218 :
219 0 : bool FuConstructRectangle::MouseMove(const MouseEvent& rMEvt)
220 : {
221 0 : return FuConstruct::MouseMove(rMEvt);
222 : }
223 :
224 0 : bool FuConstructRectangle::MouseButtonUp(const MouseEvent& rMEvt)
225 : {
226 0 : bool bReturn(false);
227 :
228 0 : if(mpView->IsCreateObj() && rMEvt.IsLeft())
229 : {
230 0 : SdrObject* pObj = mpView->GetCreateObj();
231 :
232 0 : if(pObj && mpView->EndCreateObj(SDRCREATE_FORCEEND))
233 : {
234 0 : if(SID_DRAW_MEASURELINE == nSlotId)
235 : {
236 0 : SdrLayerAdmin& rAdmin = mpDoc->GetLayerAdmin();
237 0 : OUString aStr(SD_RESSTR(STR_LAYER_MEASURELINES));
238 0 : pObj->SetLayer(rAdmin.GetLayerID(aStr, false));
239 : }
240 :
241 : // init text position when vertical caption object is created
242 0 : if(pObj->ISA(SdrCaptionObj) && SID_DRAW_CAPTION_VERTICAL == nSlotId)
243 : {
244 : // draw text object, needs to be initialized when vertical text is used
245 0 : SfxItemSet aSet(pObj->GetMergedItemSet());
246 :
247 0 : aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
248 0 : aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
249 :
250 : // Correct the value of SDRATTR_TEXTDIRECTION to avoid SetItemSet
251 : // calling SetVerticalWriting() again since this item may not yet
252 : // be set at the object and thus may differ from vertical state of
253 : // the object.
254 0 : aSet.Put(SvxWritingModeItem(com::sun::star::text::WritingMode_TB_RL, SDRATTR_TEXTDIRECTION));
255 0 : pObj->SetMergedItemSet(aSet);
256 : }
257 :
258 0 : bReturn = true;
259 : }
260 : }
261 :
262 0 : bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
263 :
264 0 : if (!bPermanent)
265 0 : mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
266 :
267 0 : return bReturn;
268 : }
269 :
270 : /**
271 : * Process keyboard input
272 : * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
273 : */
274 0 : bool FuConstructRectangle::KeyInput(const KeyEvent& rKEvt)
275 : {
276 0 : return FuConstruct::KeyInput(rKEvt);
277 : }
278 :
279 0 : void FuConstructRectangle::Activate()
280 : {
281 : SdrObjKind aObjKind;
282 :
283 0 : switch (nSlotId)
284 : {
285 : case SID_LINE_ARROW_START:
286 : case SID_LINE_ARROW_END:
287 : case SID_LINE_ARROWS:
288 : case SID_LINE_ARROW_CIRCLE:
289 : case SID_LINE_CIRCLE_ARROW:
290 : case SID_LINE_ARROW_SQUARE:
291 : case SID_LINE_SQUARE_ARROW:
292 0 : mpView->SetGlueVisible();
293 : // no break !
294 : case SID_DRAW_LINE :
295 : case SID_DRAW_XLINE:
296 0 : aObjKind = OBJ_LINE;
297 0 : break;
298 :
299 : case SID_DRAW_MEASURELINE:
300 : {
301 0 : aObjKind = OBJ_MEASURE;
302 : }
303 0 : break;
304 :
305 : case SID_DRAW_RECT :
306 : case SID_DRAW_RECT_NOFILL :
307 : case SID_DRAW_RECT_ROUND :
308 : case SID_DRAW_RECT_ROUND_NOFILL:
309 : case SID_DRAW_SQUARE :
310 : case SID_DRAW_SQUARE_NOFILL :
311 : case SID_DRAW_SQUARE_ROUND :
312 : case SID_DRAW_SQUARE_ROUND_NOFILL:
313 : {
314 0 : aObjKind = OBJ_RECT;
315 : }
316 0 : break;
317 :
318 : case SID_DRAW_ELLIPSE :
319 : case SID_DRAW_ELLIPSE_NOFILL:
320 : case SID_DRAW_CIRCLE :
321 : case SID_DRAW_CIRCLE_NOFILL :
322 : {
323 0 : aObjKind = OBJ_CIRC;
324 : }
325 0 : break;
326 :
327 : case SID_DRAW_CAPTION:
328 : case SID_DRAW_CAPTION_VERTICAL:
329 : {
330 0 : aObjKind = OBJ_CAPTION;
331 : }
332 0 : break;
333 :
334 : case SID_TOOL_CONNECTOR:
335 : case SID_CONNECTOR_ARROW_START:
336 : case SID_CONNECTOR_ARROW_END:
337 : case SID_CONNECTOR_ARROWS:
338 : case SID_CONNECTOR_CIRCLE_START:
339 : case SID_CONNECTOR_CIRCLE_END:
340 : case SID_CONNECTOR_CIRCLES:
341 : case SID_CONNECTOR_LINE:
342 : case SID_CONNECTOR_LINE_ARROW_START:
343 : case SID_CONNECTOR_LINE_ARROW_END:
344 : case SID_CONNECTOR_LINE_ARROWS:
345 : case SID_CONNECTOR_LINE_CIRCLE_START:
346 : case SID_CONNECTOR_LINE_CIRCLE_END:
347 : case SID_CONNECTOR_LINE_CIRCLES:
348 : case SID_CONNECTOR_CURVE:
349 : case SID_CONNECTOR_CURVE_ARROW_START:
350 : case SID_CONNECTOR_CURVE_ARROW_END:
351 : case SID_CONNECTOR_CURVE_ARROWS:
352 : case SID_CONNECTOR_CURVE_CIRCLE_START:
353 : case SID_CONNECTOR_CURVE_CIRCLE_END:
354 : case SID_CONNECTOR_CURVE_CIRCLES:
355 : case SID_CONNECTOR_LINES:
356 : case SID_CONNECTOR_LINES_ARROW_START:
357 : case SID_CONNECTOR_LINES_ARROW_END:
358 : case SID_CONNECTOR_LINES_ARROWS:
359 : case SID_CONNECTOR_LINES_CIRCLE_START:
360 : case SID_CONNECTOR_LINES_CIRCLE_END:
361 : case SID_CONNECTOR_LINES_CIRCLES:
362 : {
363 0 : aObjKind = OBJ_EDGE;
364 0 : mpView->SetGlueVisible();
365 : }
366 0 : break;
367 :
368 : default:
369 : {
370 0 : aObjKind = OBJ_RECT;
371 : }
372 0 : break;
373 : }
374 :
375 0 : mpView->SetCurrentObj((sal_uInt16)aObjKind);
376 :
377 0 : FuConstruct::Activate();
378 0 : }
379 :
380 0 : void FuConstructRectangle::Deactivate()
381 : {
382 0 : if( nSlotId == SID_TOOL_CONNECTOR ||
383 0 : nSlotId == SID_CONNECTOR_ARROW_START ||
384 0 : nSlotId == SID_CONNECTOR_ARROW_END ||
385 0 : nSlotId == SID_CONNECTOR_ARROWS ||
386 0 : nSlotId == SID_CONNECTOR_CIRCLE_START ||
387 0 : nSlotId == SID_CONNECTOR_CIRCLE_END ||
388 0 : nSlotId == SID_CONNECTOR_CIRCLES ||
389 0 : nSlotId == SID_CONNECTOR_LINE ||
390 0 : nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
391 0 : nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
392 0 : nSlotId == SID_CONNECTOR_LINE_ARROWS ||
393 0 : nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
394 0 : nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
395 0 : nSlotId == SID_CONNECTOR_LINE_CIRCLES ||
396 0 : nSlotId == SID_CONNECTOR_CURVE ||
397 0 : nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
398 0 : nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
399 0 : nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
400 0 : nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
401 0 : nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
402 0 : nSlotId == SID_CONNECTOR_CURVE_CIRCLES ||
403 0 : nSlotId == SID_CONNECTOR_LINES ||
404 0 : nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
405 0 : nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
406 0 : nSlotId == SID_CONNECTOR_LINES_ARROWS ||
407 0 : nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
408 0 : nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
409 0 : nSlotId == SID_CONNECTOR_LINES_CIRCLES ||
410 0 : nSlotId == SID_LINE_ARROW_START ||
411 0 : nSlotId == SID_LINE_ARROW_END ||
412 0 : nSlotId == SID_LINE_ARROWS ||
413 0 : nSlotId == SID_LINE_ARROW_CIRCLE ||
414 0 : nSlotId == SID_LINE_CIRCLE_ARROW ||
415 0 : nSlotId == SID_LINE_ARROW_SQUARE ||
416 0 : nSlotId == SID_LINE_SQUARE_ARROW )
417 : {
418 0 : mpView->SetGlueVisible( false );
419 : }
420 0 : FuConstruct::Deactivate();
421 0 : }
422 :
423 : /**
424 : * set attribute for the object to be created
425 : */
426 0 : void FuConstructRectangle::SetAttributes(SfxItemSet& rAttr, SdrObject* pObj)
427 : {
428 0 : if (nSlotId == SID_DRAW_RECT_ROUND ||
429 0 : nSlotId == SID_DRAW_RECT_ROUND_NOFILL ||
430 0 : nSlotId == SID_DRAW_SQUARE_ROUND ||
431 0 : nSlotId == SID_DRAW_SQUARE_ROUND_NOFILL)
432 : {
433 : // round corner
434 0 : rAttr.Put(makeSdrEckenradiusItem(500));
435 : }
436 0 : else if (nSlotId == SID_CONNECTOR_LINE ||
437 0 : nSlotId == SID_CONNECTOR_LINE_ARROW_START ||
438 0 : nSlotId == SID_CONNECTOR_LINE_ARROW_END ||
439 0 : nSlotId == SID_CONNECTOR_LINE_ARROWS ||
440 0 : nSlotId == SID_CONNECTOR_LINE_CIRCLE_START ||
441 0 : nSlotId == SID_CONNECTOR_LINE_CIRCLE_END ||
442 0 : nSlotId == SID_CONNECTOR_LINE_CIRCLES)
443 : {
444 : // direct connector
445 0 : rAttr.Put(SdrEdgeKindItem(SDREDGE_ONELINE));
446 : }
447 0 : else if (nSlotId == SID_CONNECTOR_LINES ||
448 0 : nSlotId == SID_CONNECTOR_LINES_ARROW_START ||
449 0 : nSlotId == SID_CONNECTOR_LINES_ARROW_END ||
450 0 : nSlotId == SID_CONNECTOR_LINES_ARROWS ||
451 0 : nSlotId == SID_CONNECTOR_LINES_CIRCLE_START ||
452 0 : nSlotId == SID_CONNECTOR_LINES_CIRCLE_END ||
453 0 : nSlotId == SID_CONNECTOR_LINES_CIRCLES)
454 : {
455 : // line connector
456 0 : rAttr.Put(SdrEdgeKindItem(SDREDGE_THREELINES));
457 : }
458 0 : else if (nSlotId == SID_CONNECTOR_CURVE ||
459 0 : nSlotId == SID_CONNECTOR_CURVE_ARROW_START ||
460 0 : nSlotId == SID_CONNECTOR_CURVE_ARROW_END ||
461 0 : nSlotId == SID_CONNECTOR_CURVE_ARROWS ||
462 0 : nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START ||
463 0 : nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END ||
464 0 : nSlotId == SID_CONNECTOR_CURVE_CIRCLES)
465 : {
466 : // curve connector
467 0 : rAttr.Put(SdrEdgeKindItem(SDREDGE_BEZIER));
468 : }
469 0 : else if ( nSlotId == SID_DRAW_CAPTION || nSlotId == SID_DRAW_CAPTION_VERTICAL )
470 : {
471 : // legend object
472 0 : Size aSize(pObj->GetLogicRect().GetSize());
473 0 : rAttr.Put( makeSdrTextMinFrameHeightItem( aSize.Height() ) );
474 0 : rAttr.Put( makeSdrTextMinFrameWidthItem( aSize.Width() ) );
475 0 : rAttr.Put( makeSdrTextAutoGrowHeightItem( true ) );
476 0 : rAttr.Put( makeSdrTextAutoGrowWidthItem( true ) );
477 :
478 : // Support full with for vertical caption objects, too
479 0 : if(SID_DRAW_CAPTION == nSlotId)
480 0 : rAttr.Put( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
481 : else
482 0 : rAttr.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_BLOCK ) );
483 :
484 0 : rAttr.Put( SvxAdjustItem( SVX_ADJUST_CENTER, EE_PARA_JUST ) );
485 0 : rAttr.Put( makeSdrTextLeftDistItem( 100 ) );
486 0 : rAttr.Put( makeSdrTextRightDistItem( 100 ) );
487 0 : rAttr.Put( makeSdrTextUpperDistItem( 100 ) );
488 0 : rAttr.Put( makeSdrTextLowerDistItem( 100 ) );
489 : }
490 0 : else if (nSlotId == SID_DRAW_MEASURELINE)
491 : {
492 : // dimension line
493 0 : SdPage* pPage = static_cast<SdPage*>( mpView->GetSdrPageView()->GetPage() );
494 0 : OUString aName(SD_RESSTR(STR_POOLSHEET_MEASURE));
495 : SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>( pPage->GetModel()->
496 0 : GetStyleSheetPool()->
497 0 : Find(aName, SD_STYLE_FAMILY_GRAPHICS));
498 : DBG_ASSERT(pSheet, "StyleSheet missing");
499 :
500 0 : if (pSheet)
501 : {
502 0 : pObj->SetStyleSheet(pSheet, false);
503 : }
504 :
505 0 : SdrLayerAdmin& rAdmin = mpDoc->GetLayerAdmin();
506 0 : OUString aStr(SD_RESSTR(STR_LAYER_MEASURELINES));
507 0 : pObj->SetLayer(rAdmin.GetLayerID(aStr, false));
508 : }
509 0 : else if (nSlotId == OBJ_CUSTOMSHAPE )
510 : {
511 : }
512 0 : }
513 :
514 : /**
515 : * set line starts and ends for the object to be created
516 : */
517 0 : ::basegfx::B2DPolyPolygon getPolygon( sal_uInt16 nResId, SdrModel* pDoc )
518 : {
519 0 : ::basegfx::B2DPolyPolygon aRetval;
520 0 : XLineEndListRef pLineEndList = pDoc->GetLineEndList();
521 :
522 0 : if( pLineEndList.is() )
523 : {
524 0 : OUString aArrowName( SVX_RES(nResId) );
525 0 : long nCount = pLineEndList->Count();
526 : long nIndex;
527 0 : for( nIndex = 0L; nIndex < nCount; nIndex++ )
528 : {
529 0 : XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex);
530 0 : if( pEntry->GetName() == aArrowName )
531 : {
532 0 : aRetval = pEntry->GetLineEnd();
533 0 : break;
534 : }
535 0 : }
536 : }
537 :
538 0 : return aRetval;
539 : }
540 :
541 0 : void FuConstructRectangle::SetLineEnds(SfxItemSet& rAttr, SdrObject* pObj)
542 : {
543 0 : if ( (pObj->GetObjIdentifier() == OBJ_EDGE &&
544 0 : nSlotId != SID_TOOL_CONNECTOR &&
545 0 : nSlotId != SID_CONNECTOR_LINE &&
546 0 : nSlotId != SID_CONNECTOR_LINES &&
547 0 : nSlotId != SID_CONNECTOR_CURVE) ||
548 0 : nSlotId == SID_LINE_ARROW_START ||
549 0 : nSlotId == SID_LINE_ARROW_END ||
550 0 : nSlotId == SID_LINE_ARROWS ||
551 0 : nSlotId == SID_LINE_ARROW_CIRCLE ||
552 0 : nSlotId == SID_LINE_CIRCLE_ARROW ||
553 0 : nSlotId == SID_LINE_ARROW_SQUARE ||
554 0 : nSlotId == SID_LINE_SQUARE_ARROW )
555 : {
556 : // set attributes of line start and ends
557 :
558 : // arrowhead
559 0 : ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, mpDoc ) );
560 0 : if( !aArrow.count() )
561 : {
562 0 : ::basegfx::B2DPolygon aNewArrow;
563 0 : aNewArrow.append(::basegfx::B2DPoint(10.0, 0.0));
564 0 : aNewArrow.append(::basegfx::B2DPoint(0.0, 30.0));
565 0 : aNewArrow.append(::basegfx::B2DPoint(20.0, 30.0));
566 0 : aNewArrow.setClosed(true);
567 0 : aArrow.append(aNewArrow);
568 : }
569 :
570 : // Circles
571 0 : ::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, mpDoc ) );
572 0 : if( !aCircle.count() )
573 : {
574 0 : ::basegfx::B2DPolygon aNewCircle;
575 0 : aNewCircle = ::basegfx::tools::createPolygonFromEllipse(::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0);
576 0 : aNewCircle.setClosed(true);
577 0 : aCircle.append(aNewCircle);
578 : }
579 :
580 : // Square
581 0 : ::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, mpDoc ) );
582 0 : if( !aSquare.count() )
583 : {
584 0 : ::basegfx::B2DPolygon aNewSquare;
585 0 : aNewSquare.append(::basegfx::B2DPoint(0.0, 0.0));
586 0 : aNewSquare.append(::basegfx::B2DPoint(10.0, 0.0));
587 0 : aNewSquare.append(::basegfx::B2DPoint(10.0, 10.0));
588 0 : aNewSquare.append(::basegfx::B2DPoint(0.0, 10.0));
589 0 : aNewSquare.setClosed(true);
590 0 : aSquare.append(aNewSquare);
591 : }
592 :
593 0 : SfxItemSet aSet( mpDoc->GetPool() );
594 0 : mpView->GetAttributes( aSet );
595 :
596 : // #i3908# Here, the default Line Start/End width for arrow construction is
597 : // set. To have the same value in all situations (construction) in i3908
598 : // it was decided to change the default to 0.03 cm for all situations.
599 0 : long nWidth = 300; // (1/100th mm)
600 :
601 : // determine line width and calculate with it the line end width
602 0 : if( aSet.GetItemState( XATTR_LINEWIDTH ) != SfxItemState::DONTCARE )
603 : {
604 0 : long nValue = static_cast<const XLineWidthItem&>( aSet.Get( XATTR_LINEWIDTH ) ).GetValue();
605 0 : if( nValue > 0 )
606 0 : nWidth = nValue * 3;
607 : }
608 :
609 0 : switch (nSlotId)
610 : {
611 : case SID_CONNECTOR_ARROWS:
612 : case SID_CONNECTOR_LINE_ARROWS:
613 : case SID_CONNECTOR_LINES_ARROWS:
614 : case SID_CONNECTOR_CURVE_ARROWS:
615 : case SID_LINE_ARROWS:
616 : {
617 : // connector with arrow ends
618 0 : rAttr.Put(XLineStartItem(SVX_RESSTR(RID_SVXSTR_ARROW), aArrow));
619 0 : rAttr.Put(XLineStartWidthItem(nWidth));
620 0 : rAttr.Put(XLineEndItem(SVX_RESSTR(RID_SVXSTR_ARROW), aArrow));
621 0 : rAttr.Put(XLineEndWidthItem(nWidth));
622 : }
623 0 : break;
624 :
625 : case SID_CONNECTOR_ARROW_START:
626 : case SID_CONNECTOR_LINE_ARROW_START:
627 : case SID_CONNECTOR_LINES_ARROW_START:
628 : case SID_CONNECTOR_CURVE_ARROW_START:
629 : case SID_LINE_ARROW_START:
630 : case SID_LINE_ARROW_CIRCLE:
631 : case SID_LINE_ARROW_SQUARE:
632 : {
633 : // connector with arrow start
634 0 : rAttr.Put(XLineStartItem(SVX_RESSTR(RID_SVXSTR_ARROW), aArrow));
635 0 : rAttr.Put(XLineStartWidthItem(nWidth));
636 : }
637 0 : break;
638 :
639 : case SID_CONNECTOR_ARROW_END:
640 : case SID_CONNECTOR_LINE_ARROW_END:
641 : case SID_CONNECTOR_LINES_ARROW_END:
642 : case SID_CONNECTOR_CURVE_ARROW_END:
643 : case SID_LINE_ARROW_END:
644 : case SID_LINE_CIRCLE_ARROW:
645 : case SID_LINE_SQUARE_ARROW:
646 : {
647 : // connector with arrow end
648 0 : rAttr.Put(XLineEndItem(SVX_RESSTR(RID_SVXSTR_ARROW), aArrow));
649 0 : rAttr.Put(XLineEndWidthItem(nWidth));
650 : }
651 0 : break;
652 :
653 : case SID_CONNECTOR_CIRCLES:
654 : case SID_CONNECTOR_LINE_CIRCLES:
655 : case SID_CONNECTOR_LINES_CIRCLES:
656 : case SID_CONNECTOR_CURVE_CIRCLES:
657 : {
658 : // connector with circle ends
659 0 : rAttr.Put(XLineStartItem(SVX_RESSTR(RID_SVXSTR_CIRCLE), aCircle));
660 0 : rAttr.Put(XLineStartWidthItem(nWidth));
661 0 : rAttr.Put(XLineEndItem(SVX_RESSTR(RID_SVXSTR_CIRCLE), aCircle));
662 0 : rAttr.Put(XLineEndWidthItem(nWidth));
663 : }
664 0 : break;
665 :
666 : case SID_CONNECTOR_CIRCLE_START:
667 : case SID_CONNECTOR_LINE_CIRCLE_START:
668 : case SID_CONNECTOR_LINES_CIRCLE_START:
669 : case SID_CONNECTOR_CURVE_CIRCLE_START:
670 : {
671 : // connector with circle start
672 0 : rAttr.Put(XLineStartItem(SVX_RESSTR(RID_SVXSTR_CIRCLE), aCircle));
673 0 : rAttr.Put(XLineStartWidthItem(nWidth));
674 : }
675 0 : break;
676 :
677 : case SID_CONNECTOR_CIRCLE_END:
678 : case SID_CONNECTOR_LINE_CIRCLE_END:
679 : case SID_CONNECTOR_LINES_CIRCLE_END:
680 : case SID_CONNECTOR_CURVE_CIRCLE_END:
681 : {
682 : // connector with circle ends
683 0 : rAttr.Put(XLineEndItem(SVX_RESSTR(RID_SVXSTR_CIRCLE), aCircle));
684 0 : rAttr.Put(XLineEndWidthItem(nWidth));
685 : }
686 0 : break;
687 : }
688 :
689 : // and again, for the still missing ends
690 0 : switch (nSlotId)
691 : {
692 : case SID_LINE_ARROW_CIRCLE:
693 : {
694 : // circle end
695 0 : rAttr.Put(XLineEndItem(SVX_RESSTR(RID_SVXSTR_CIRCLE), aCircle));
696 0 : rAttr.Put(XLineEndWidthItem(nWidth));
697 : }
698 0 : break;
699 :
700 : case SID_LINE_CIRCLE_ARROW:
701 : {
702 : // circle start
703 0 : rAttr.Put(XLineStartItem(SVX_RESSTR(RID_SVXSTR_CIRCLE), aCircle));
704 0 : rAttr.Put(XLineStartWidthItem(nWidth));
705 : }
706 0 : break;
707 :
708 : case SID_LINE_ARROW_SQUARE:
709 : {
710 : // square end
711 0 : rAttr.Put(XLineEndItem(SVX_RESSTR(RID_SVXSTR_SQUARE), aSquare));
712 0 : rAttr.Put(XLineEndWidthItem(nWidth));
713 : }
714 0 : break;
715 :
716 : case SID_LINE_SQUARE_ARROW:
717 : {
718 : // square start
719 0 : rAttr.Put(XLineStartItem(SVX_RESSTR(RID_SVXSTR_SQUARE), aSquare));
720 0 : rAttr.Put(XLineStartWidthItem(nWidth));
721 : }
722 0 : break;
723 0 : }
724 : }
725 0 : }
726 :
727 0 : SdrObject* FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
728 : {
729 : DBG_ASSERT( (nID != SID_DRAW_FONTWORK) && (nID != SID_DRAW_FONTWORK_VERTICAL ), "FuConstRectangle::CreateDefaultObject can not create Fontwork shapes!" );
730 :
731 : // case SID_DRAW_LINE:
732 : // case SID_DRAW_XLINE:
733 : // case SID_DRAW_MEASURELINE:
734 : // case SID_LINE_ARROW_START:
735 : // case SID_LINE_ARROW_END:
736 : // case SID_LINE_ARROWS:
737 : // case SID_LINE_ARROW_CIRCLE:
738 : // case SID_LINE_CIRCLE_ARROW:
739 : // case SID_LINE_ARROW_SQUARE:
740 : // case SID_LINE_SQUARE_ARROW:
741 : // case SID_DRAW_RECT:
742 : // case SID_DRAW_RECT_NOFILL:
743 : // case SID_DRAW_RECT_ROUND:
744 : // case SID_DRAW_RECT_ROUND_NOFILL:
745 : // case SID_DRAW_SQUARE:
746 : // case SID_DRAW_SQUARE_NOFILL:
747 : // case SID_DRAW_SQUARE_ROUND:
748 : // case SID_DRAW_SQUARE_ROUND_NOFILL:
749 : // case SID_DRAW_ELLIPSE:
750 : // case SID_DRAW_ELLIPSE_NOFILL:
751 : // case SID_DRAW_CIRCLE:
752 : // case SID_DRAW_CIRCLE_NOFILL:
753 : // case SID_DRAW_CAPTION:
754 : // case SID_DRAW_CAPTION_VERTICAL:
755 : // case SID_TOOL_CONNECTOR:
756 : // case SID_CONNECTOR_ARROW_START:
757 : // case SID_CONNECTOR_ARROW_END:
758 : // case SID_CONNECTOR_ARROWS:
759 : // case SID_CONNECTOR_CIRCLE_START:
760 : // case SID_CONNECTOR_CIRCLE_END:
761 : // case SID_CONNECTOR_CIRCLES:
762 : // case SID_CONNECTOR_LINE:
763 : // case SID_CONNECTOR_LINE_ARROW_START:
764 : // case SID_CONNECTOR_LINE_ARROW_END:
765 : // case SID_CONNECTOR_LINE_ARROWS:
766 : // case SID_CONNECTOR_LINE_CIRCLE_START:
767 : // case SID_CONNECTOR_LINE_CIRCLE_END:
768 : // case SID_CONNECTOR_LINE_CIRCLES:
769 : // case SID_CONNECTOR_CURVE:
770 : // case SID_CONNECTOR_CURVE_ARROW_START:
771 : // case SID_CONNECTOR_CURVE_ARROW_END:
772 : // case SID_CONNECTOR_CURVE_ARROWS:
773 : // case SID_CONNECTOR_CURVE_CIRCLE_START:
774 : // case SID_CONNECTOR_CURVE_CIRCLE_END:
775 : // case SID_CONNECTOR_CURVE_CIRCLES:
776 : // case SID_CONNECTOR_LINES:
777 : // case SID_CONNECTOR_LINES_ARROW_START:
778 : // case SID_CONNECTOR_LINES_ARROW_END:
779 : // case SID_CONNECTOR_LINES_ARROWS:
780 : // case SID_CONNECTOR_LINES_CIRCLE_START:
781 : // case SID_CONNECTOR_LINES_CIRCLE_END:
782 : // case SID_CONNECTOR_LINES_CIRCLES:
783 :
784 : SdrObject* pObj = SdrObjFactory::MakeNewObject(
785 0 : mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
786 0 : 0L, mpDoc);
787 :
788 0 : if(pObj)
789 : {
790 0 : Rectangle aRect(rRectangle);
791 :
792 0 : if(SID_DRAW_SQUARE == nID ||
793 0 : SID_DRAW_SQUARE_NOFILL == nID ||
794 0 : SID_DRAW_SQUARE_ROUND == nID ||
795 0 : SID_DRAW_SQUARE_ROUND_NOFILL == nID ||
796 0 : SID_DRAW_CIRCLE == nID ||
797 : SID_DRAW_CIRCLE_NOFILL == nID)
798 : {
799 : // force quadratic
800 0 : ImpForceQuadratic(aRect);
801 : }
802 :
803 0 : Point aStart = aRect.TopLeft();
804 0 : Point aEnd = aRect.BottomRight();
805 :
806 0 : switch(nID)
807 : {
808 : case SID_DRAW_LINE:
809 : case SID_DRAW_XLINE:
810 : case SID_LINE_ARROW_START:
811 : case SID_LINE_ARROW_END:
812 : case SID_LINE_ARROWS:
813 : case SID_LINE_ARROW_CIRCLE:
814 : case SID_LINE_CIRCLE_ARROW:
815 : case SID_LINE_ARROW_SQUARE:
816 : case SID_LINE_SQUARE_ARROW:
817 : {
818 0 : if(pObj->ISA(SdrPathObj))
819 : {
820 0 : sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
821 :
822 0 : ::basegfx::B2DPolygon aB2DPolygon;
823 0 : aB2DPolygon.append(::basegfx::B2DPoint(aStart.X(), nYMiddle));
824 0 : aB2DPolygon.append(::basegfx::B2DPoint(aEnd.X(), nYMiddle));
825 0 : static_cast<SdrPathObj*>(pObj)->SetPathPoly(::basegfx::B2DPolyPolygon(aB2DPolygon));
826 : }
827 : else
828 : {
829 : OSL_FAIL("Object is NO line object");
830 : }
831 :
832 0 : break;
833 : }
834 :
835 : case SID_DRAW_MEASURELINE:
836 : {
837 0 : if(pObj->ISA(SdrMeasureObj))
838 : {
839 0 : sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
840 0 : static_cast<SdrMeasureObj*>(pObj)->SetPoint(Point(aStart.X(), nYMiddle), 0);
841 0 : static_cast<SdrMeasureObj*>(pObj)->SetPoint(Point(aEnd.X(), nYMiddle), 1);
842 : }
843 : else
844 : {
845 : OSL_FAIL("Object is NO measure object");
846 : }
847 :
848 0 : break;
849 : }
850 :
851 : case SID_TOOL_CONNECTOR:
852 : case SID_CONNECTOR_ARROW_START:
853 : case SID_CONNECTOR_ARROW_END:
854 : case SID_CONNECTOR_ARROWS:
855 : case SID_CONNECTOR_CIRCLE_START:
856 : case SID_CONNECTOR_CIRCLE_END:
857 : case SID_CONNECTOR_CIRCLES:
858 : case SID_CONNECTOR_LINE:
859 : case SID_CONNECTOR_LINE_ARROW_START:
860 : case SID_CONNECTOR_LINE_ARROW_END:
861 : case SID_CONNECTOR_LINE_ARROWS:
862 : case SID_CONNECTOR_LINE_CIRCLE_START:
863 : case SID_CONNECTOR_LINE_CIRCLE_END:
864 : case SID_CONNECTOR_LINE_CIRCLES:
865 : case SID_CONNECTOR_CURVE:
866 : case SID_CONNECTOR_CURVE_ARROW_START:
867 : case SID_CONNECTOR_CURVE_ARROW_END:
868 : case SID_CONNECTOR_CURVE_ARROWS:
869 : case SID_CONNECTOR_CURVE_CIRCLE_START:
870 : case SID_CONNECTOR_CURVE_CIRCLE_END:
871 : case SID_CONNECTOR_CURVE_CIRCLES:
872 : case SID_CONNECTOR_LINES:
873 : case SID_CONNECTOR_LINES_ARROW_START:
874 : case SID_CONNECTOR_LINES_ARROW_END:
875 : case SID_CONNECTOR_LINES_ARROWS:
876 : case SID_CONNECTOR_LINES_CIRCLE_START:
877 : case SID_CONNECTOR_LINES_CIRCLE_END:
878 : case SID_CONNECTOR_LINES_CIRCLES:
879 : {
880 0 : if(pObj->ISA(SdrEdgeObj))
881 : {
882 0 : static_cast<SdrEdgeObj*>(pObj)->SetTailPoint(false, aStart);
883 0 : static_cast<SdrEdgeObj*>(pObj)->SetTailPoint(true, aEnd);
884 : }
885 : else
886 : {
887 : OSL_FAIL("Object is NO connector object");
888 : }
889 :
890 0 : break;
891 : }
892 : case SID_DRAW_CAPTION:
893 : case SID_DRAW_CAPTION_VERTICAL:
894 : {
895 0 : if(pObj->ISA(SdrCaptionObj))
896 : {
897 0 : bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
898 :
899 0 : static_cast<SdrTextObj*>(pObj)->SetVerticalWriting(bIsVertical);
900 :
901 0 : if(bIsVertical)
902 : {
903 0 : SfxItemSet aSet(pObj->GetMergedItemSet());
904 0 : aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
905 0 : aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
906 0 : pObj->SetMergedItemSet(aSet);
907 : }
908 :
909 : // The default text is not inserted anymore.
910 :
911 0 : static_cast<SdrCaptionObj*>(pObj)->SetLogicRect(aRect);
912 : static_cast<SdrCaptionObj*>(pObj)->SetTailPos(
913 0 : aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
914 : }
915 : else
916 : {
917 : OSL_FAIL("Object is NO caption object");
918 : }
919 :
920 0 : break;
921 : }
922 :
923 : default:
924 : {
925 0 : pObj->SetLogicRect(aRect);
926 :
927 0 : break;
928 : }
929 : }
930 :
931 0 : SfxItemSet aAttr(mpDoc->GetPool());
932 0 : SetStyleSheet(aAttr, pObj);
933 0 : SetAttributes(aAttr, pObj);
934 0 : SetLineEnds(aAttr, pObj);
935 0 : pObj->SetMergedItemSet(aAttr);
936 : }
937 :
938 0 : return pObj;
939 : }
940 :
941 66 : } // end of namespace sd
942 :
943 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|