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