1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <fuconrec.hxx>
#include <tabvwsh.hxx>
#include <drawview.hxx>
#include <editeng/outlobj.hxx>
// Create default drawing objects via keyboard
#include <svx/svdopath.hxx>
#include <svx/svdocapt.hxx>
#include <svx/svxids.hrc>
#include <svx/strings.hrc>
#include <svx/xlnwtit.hxx>
#include <svx/xlnstwit.hxx>
#include <svx/xlnedwit.hxx>
#include <svx/xlnedit.hxx>
#include <svx/xlnstit.hxx>
#include <svx/dialmgr.hxx>
#include <svx/svdomeas.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/point/b2dpoint.hxx>
FuConstRectangle::FuConstRectangle(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawView* pViewP,
SdrModel* pDoc, const SfxRequest& rReq)
: FuConstruct(rViewSh, pWin, pViewP, pDoc, rReq)
{
}
FuConstRectangle::~FuConstRectangle()
{
}
/**
* set line starts and ends for the object to be created
*/
namespace {
::basegfx::B2DPolyPolygon getPolygon(const char* pResId, const SdrModel& rModel)
{
::basegfx::B2DPolyPolygon aRetval;
XLineEndListRef pLineEndList(rModel.GetLineEndList());
if( pLineEndList.is() )
{
OUString aArrowName( SvxResId(pResId) );
long nCount = pLineEndList->Count();
long nIndex;
for( nIndex = 0; nIndex < nCount; nIndex++ )
{
const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex);
if( pEntry->GetName() == aArrowName )
{
aRetval = pEntry->GetLineEnd();
break;
}
}
}
return aRetval;
}
}
bool FuConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)
{
// remember button state for creation of own MouseEvents
SetMouseButtonCode(rMEvt.GetButtons());
bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
if ( rMEvt.IsLeft() && !pView->IsAction() )
{
Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
pWindow->CaptureMouse();
if ( pView->GetCurrentObjIdentifier() == OBJ_CAPTION )
{
Size aCaptionSize ( 2268, 1134 ); // 4x2cm
bReturn = pView->BegCreateCaptionObj( aPos, aCaptionSize );
// How do you set the font for writing
}
else
bReturn = pView->BegCreateObj(aPos);
SdrObject* pObj = pView->GetCreateObj();
if (pObj)
{
SfxItemSet aAttr(pObj->getSdrModelFromSdrObject().GetItemPool());
SetLineEnds(aAttr, *pObj, aSfxRequest.GetSlot());
pObj->SetMergedItemSet(aAttr);
}
}
return bReturn;
}
bool FuConstRectangle::MouseButtonUp(const MouseEvent& rMEvt)
{
// remember button state for creation of own MouseEvents
SetMouseButtonCode(rMEvt.GetButtons());
bool bReturn = false;
if ( pView->IsCreateObj() && rMEvt.IsLeft() )
{
pView->EndCreateObj(SdrCreateCmd::ForceEnd);
if (aSfxRequest.GetSlot() == SID_DRAW_CAPTION_VERTICAL)
{
// set vertical flag for caption object
const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
if (rMarkList.GetMark(0))
{
SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
// create OutlinerParaObject now so it can be set to vertical
if ( dynamic_cast<const SdrTextObj*>( pObj) != nullptr )
static_cast<SdrTextObj*>(pObj)->ForceOutlinerParaObject();
OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
if( pOPO && !pOPO->IsVertical() )
pOPO->SetVertical( true );
}
}
bReturn = true;
}
return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
}
void FuConstRectangle::Activate()
{
SdrObjKind aObjKind;
switch (aSfxRequest.GetSlot() )
{
case SID_DRAW_LINE:
case SID_DRAW_XLINE:
case SID_LINE_ARROW_END:
case SID_LINE_ARROW_CIRCLE:
case SID_LINE_ARROW_SQUARE:
case SID_LINE_ARROW_START:
case SID_LINE_CIRCLE_ARROW:
case SID_LINE_SQUARE_ARROW:
case SID_LINE_ARROWS:
aNewPointer = PointerStyle::DrawLine;
aObjKind = OBJ_LINE;
break;
case SID_DRAW_MEASURELINE:
aNewPointer = PointerStyle::DrawLine;
aObjKind = OBJ_MEASURE;
break;
case SID_DRAW_RECT:
aNewPointer = PointerStyle::DrawRect;
aObjKind = OBJ_RECT;
break;
case SID_DRAW_ELLIPSE:
aNewPointer = PointerStyle::DrawEllipse;
aObjKind = OBJ_CIRC;
break;
case SID_DRAW_CAPTION:
case SID_DRAW_CAPTION_VERTICAL:
aNewPointer = PointerStyle::DrawCaption;
aObjKind = OBJ_CAPTION;
break;
default:
aNewPointer = PointerStyle::Cross;
aObjKind = OBJ_RECT;
break;
}
pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(aObjKind));
aOldPointer = pWindow->GetPointer();
rViewShell.SetActivePointer( aNewPointer );
FuConstruct::Activate();
}
void FuConstRectangle::SetLineEnds(SfxItemSet& rAttr, const SdrObject& rObj, sal_uInt16 nSlotId)
{
SdrModel& rModel(rObj.getSdrModelFromSdrObject());
if ( nSlotId == SID_LINE_ARROW_START ||
nSlotId == SID_LINE_ARROW_END ||
nSlotId == SID_LINE_ARROWS ||
nSlotId == SID_LINE_ARROW_CIRCLE ||
nSlotId == SID_LINE_CIRCLE_ARROW ||
nSlotId == SID_LINE_ARROW_SQUARE ||
nSlotId == SID_LINE_SQUARE_ARROW ||
nSlotId == SID_DRAW_MEASURELINE )
{
// set attributes of line start and ends
// arrowhead
::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, rModel ) );
if( !aArrow.count() )
{
::basegfx::B2DPolygon aNewArrow;
aNewArrow.append(::basegfx::B2DPoint(10.0, 0.0));
aNewArrow.append(::basegfx::B2DPoint(0.0, 30.0));
aNewArrow.append(::basegfx::B2DPoint(20.0, 30.0));
aNewArrow.setClosed(true);
aArrow.append(aNewArrow);
}
// Circles
::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, rModel ) );
if( !aCircle.count() )
{
::basegfx::B2DPolygon aNewCircle = ::basegfx::utils::createPolygonFromEllipse(::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0);
aNewCircle.setClosed(true);
aCircle.append(aNewCircle);
}
// Square
::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, rModel ) );
if( !aSquare.count() )
{
::basegfx::B2DPolygon aNewSquare;
aNewSquare.append(::basegfx::B2DPoint(0.0, 0.0));
aNewSquare.append(::basegfx::B2DPoint(10.0, 0.0));
aNewSquare.append(::basegfx::B2DPoint(10.0, 10.0));
aNewSquare.append(::basegfx::B2DPoint(0.0, 10.0));
aNewSquare.setClosed(true);
aSquare.append(aNewSquare);
}
SfxItemSet aSet( rModel.GetItemPool() );
long nWidth = 200; // (1/100th mm)
// determine line width and calculate with it the line end width
if( aSet.GetItemState( XATTR_LINEWIDTH ) != SfxItemState::DONTCARE )
{
long nValue = aSet.Get( XATTR_LINEWIDTH ).GetValue();
if( nValue > 0 )
nWidth = nValue * 3;
}
switch (nSlotId)
{
case SID_LINE_ARROWS:
case SID_DRAW_MEASURELINE:
{
// connector with arrow ends
rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
rAttr.Put(XLineStartWidthItem(nWidth));
rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
rAttr.Put(XLineEndWidthItem(nWidth));
}
break;
case SID_LINE_ARROW_START:
case SID_LINE_ARROW_CIRCLE:
case SID_LINE_ARROW_SQUARE:
{
// connector with arrow start
rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
rAttr.Put(XLineStartWidthItem(nWidth));
}
break;
case SID_LINE_ARROW_END:
case SID_LINE_CIRCLE_ARROW:
case SID_LINE_SQUARE_ARROW:
{
// connector with arrow end
rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
rAttr.Put(XLineEndWidthItem(nWidth));
}
break;
}
// and again, for the still missing ends
switch (nSlotId)
{
case SID_LINE_ARROW_CIRCLE:
{
// circle end
rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
rAttr.Put(XLineEndWidthItem(nWidth));
}
break;
case SID_LINE_CIRCLE_ARROW:
{
// circle start
rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
rAttr.Put(XLineStartWidthItem(nWidth));
}
break;
case SID_LINE_ARROW_SQUARE:
{
// square end
rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
rAttr.Put(XLineEndWidthItem(nWidth));
}
break;
case SID_LINE_SQUARE_ARROW:
{
// square start
rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
rAttr.Put(XLineStartWidthItem(nWidth));
}
break;
}
}
}
void FuConstRectangle::Deactivate()
{
FuConstruct::Deactivate();
rViewShell.SetActivePointer( aOldPointer );
}
// Create default drawing objects via keyboard
SdrObjectUniquePtr FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle& rRectangle)
{
SdrObjectUniquePtr pObj(SdrObjFactory::MakeNewObject(
*pDrDoc,
pView->GetCurrentObjInventor(),
pView->GetCurrentObjIdentifier()));
if(pObj)
{
tools::Rectangle aRect(rRectangle);
Point aStart = aRect.TopLeft();
Point aEnd = aRect.BottomRight();
switch(nID)
{
case SID_DRAW_LINE:
case SID_DRAW_XLINE:
case SID_LINE_ARROW_END:
case SID_LINE_ARROW_CIRCLE:
case SID_LINE_ARROW_SQUARE:
case SID_LINE_ARROW_START:
case SID_LINE_CIRCLE_ARROW:
case SID_LINE_SQUARE_ARROW:
case SID_LINE_ARROWS:
{
if(auto pPathObj = dynamic_cast<SdrPathObj*>( pObj.get() ))
{
sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
basegfx::B2DPolygon aPoly;
aPoly.append(basegfx::B2DPoint(aStart.X(), nYMiddle));
aPoly.append(basegfx::B2DPoint(aEnd.X(), nYMiddle));
pPathObj->SetPathPoly(basegfx::B2DPolyPolygon(aPoly));
}
else
{
OSL_FAIL("Object is NO line object");
}
break;
}
case SID_DRAW_MEASURELINE:
{
if(auto pMeasureObj = dynamic_cast<SdrMeasureObj*>( pObj.get() ))
{
sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
pMeasureObj->SetPoint(Point(aStart.X(), nYMiddle), 0);
pMeasureObj->SetPoint(Point(aEnd.X(), nYMiddle), 1);
}
break;
}
case SID_DRAW_CAPTION:
case SID_DRAW_CAPTION_VERTICAL:
{
if(auto pCaptionObj = dynamic_cast<SdrCaptionObj*>( pObj.get() ))
{
bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
pCaptionObj->SetVerticalWriting(bIsVertical);
if(bIsVertical)
{
SfxItemSet aSet(pObj->GetMergedItemSet());
aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
pObj->SetMergedItemSet(aSet);
}
// don't set default text, start edit mode instead
// (Edit mode is started in ScTabViewShell::ExecDraw, because
// it must be handled by FuText)
pCaptionObj->SetLogicRect(aRect);
pCaptionObj->SetTailPos(
aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
}
else
{
OSL_FAIL("Object is NO caption object");
}
break;
}
default:
{
pObj->SetLogicRect(aRect);
break;
}
}
SfxItemSet aAttr(pDrDoc->GetItemPool());
SetLineEnds(aAttr, *pObj, nID);
pObj->SetMergedItemSet(aAttr);
}
return pObj;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|