LibreOffice Module sc (master) 1
fuconrec.cxx
Go to the documentation of this file.
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 <tabvwsh.hxx>
22#include <drawview.hxx>
23
24#include <editeng/outlobj.hxx>
26// Create default drawing objects via keyboard
27#include <svx/svdopath.hxx>
28#include <svx/svdocapt.hxx>
29#include <svx/svxids.hrc>
30#include <svx/strings.hrc>
31#include <svx/xlnwtit.hxx>
32#include <svx/xlnstwit.hxx>
33#include <svx/xlnedwit.hxx>
34#include <svx/xlnedit.hxx>
35#include <svx/xlnstit.hxx>
36#include <svx/dialmgr.hxx>
37#include <svx/svdomeas.hxx>
38#include <osl/diagnose.h>
40
43
45 SdrModel* pDoc, const SfxRequest& rReq)
46 : FuConstruct(rViewSh, pWin, pViewP, pDoc, rReq)
47{
48}
49
51{
52}
53
55{
56 // remember button state for creation of own MouseEvents
58
59 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
60
61 if ( rMEvt.IsLeft() && !pView->IsAction() )
62 {
63 Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
64 pWindow->CaptureMouse();
65
66 if ( pView->GetCurrentObjIdentifier() == SdrObjKind::Caption )
67 {
68 Size aCaptionSize ( 2268, 1134 ); // 4x2cm
69
70 bReturn = pView->BegCreateCaptionObj( aPos, aCaptionSize );
71
72 // How do you set the font for writing
73 }
74 else
75 bReturn = pView->BegCreateObj(aPos);
76
77 SdrObject* pObj = pView->GetCreateObj();
78
79 if (pObj)
80 {
82 SetLineEnds(aAttr, *pObj, aSfxRequest.GetSlot());
83 pObj->SetMergedItemSet(aAttr);
84 }
85 }
86 return bReturn;
87}
88
90{
91 // remember button state for creation of own MouseEvents
93
94 bool bReturn = false;
95
96 if ( pView->IsCreateObj() && rMEvt.IsLeft() )
97 {
98 pView->EndCreateObj(SdrCreateCmd::ForceEnd);
99
100 if (aSfxRequest.GetSlot() == SID_DRAW_CAPTION_VERTICAL)
101 {
102 // set vertical flag for caption object
103
104 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
105 if (rMarkList.GetMark(0))
106 {
107 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
108 // create OutlinerParaObject now so it can be set to vertical
109 if ( auto pSdrTextObj = DynCastSdrTextObj( pObj) )
110 pSdrTextObj->ForceOutlinerParaObject();
112 if( pOPO && !pOPO->IsEffectivelyVertical() )
113 pOPO->SetVertical( true );
114 }
115 }
116
117 bReturn = true;
118 }
119 return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
120}
121
123{
124 SdrObjKind aObjKind;
125
126 switch (aSfxRequest.GetSlot() )
127 {
128 case SID_DRAW_LINE:
129 case SID_DRAW_XLINE:
130 case SID_LINE_ARROW_END:
131 case SID_LINE_ARROW_CIRCLE:
132 case SID_LINE_ARROW_SQUARE:
133 case SID_LINE_ARROW_START:
134 case SID_LINE_CIRCLE_ARROW:
135 case SID_LINE_SQUARE_ARROW:
136 case SID_LINE_ARROWS:
137 aNewPointer = PointerStyle::DrawLine;
138 aObjKind = SdrObjKind::Line;
139 break;
140
141 case SID_DRAW_MEASURELINE:
142 aNewPointer = PointerStyle::DrawLine;
143 aObjKind = SdrObjKind::Measure;
144 break;
145
146 case SID_DRAW_RECT:
147 aNewPointer = PointerStyle::DrawRect;
148 aObjKind = SdrObjKind::Rectangle;
149 break;
150
151 case SID_DRAW_ELLIPSE:
152 aNewPointer = PointerStyle::DrawEllipse;
153 aObjKind = SdrObjKind::CircleOrEllipse;
154 break;
155
156 case SID_DRAW_CAPTION:
157 case SID_DRAW_CAPTION_VERTICAL:
158 aNewPointer = PointerStyle::DrawCaption;
159 aObjKind = SdrObjKind::Caption;
160 break;
161
162 default:
163 aNewPointer = PointerStyle::Cross;
164 aObjKind = SdrObjKind::Rectangle;
165 break;
166 }
167
168 pView->SetCurrentObj(aObjKind);
169
170 aOldPointer = pWindow->GetPointer();
172
174}
175
176void FuConstRectangle::SetLineEnds(SfxItemSet& rAttr, const SdrObject& rObj, sal_uInt16 nSlotId)
177{
178 ConstructHelper::SetLineEnds(rAttr, rObj, nSlotId, 200);
179}
180
182{
185}
186
187// Create default drawing objects via keyboard
189{
191 *pDrDoc,
194
195 if(pObj)
196 {
197 tools::Rectangle aRect(rRectangle);
198 Point aStart = aRect.TopLeft();
199 Point aEnd = aRect.BottomRight();
200
201 switch(nID)
202 {
203 case SID_DRAW_LINE:
204 case SID_DRAW_XLINE:
205 case SID_LINE_ARROW_END:
206 case SID_LINE_ARROW_CIRCLE:
207 case SID_LINE_ARROW_SQUARE:
208 case SID_LINE_ARROW_START:
209 case SID_LINE_CIRCLE_ARROW:
210 case SID_LINE_SQUARE_ARROW:
211 case SID_LINE_ARROWS:
212 {
213 if(auto pPathObj = dynamic_cast<SdrPathObj*>( pObj.get() ))
214 {
215 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
217 aPoly.append(basegfx::B2DPoint(aStart.X(), nYMiddle));
218 aPoly.append(basegfx::B2DPoint(aEnd.X(), nYMiddle));
219 pPathObj->SetPathPoly(basegfx::B2DPolyPolygon(aPoly));
220 }
221 else
222 {
223 OSL_FAIL("Object is NO line object");
224 }
225
226 break;
227 }
228
229 case SID_DRAW_MEASURELINE:
230 {
231 if(auto pMeasureObj = dynamic_cast<SdrMeasureObj*>( pObj.get() ))
232 {
233 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
234 pMeasureObj->SetPoint(Point(aStart.X(), nYMiddle), 0);
235 pMeasureObj->SetPoint(Point(aEnd.X(), nYMiddle), 1);
236 }
237
238 break;
239 }
240
241 case SID_DRAW_CAPTION:
242 case SID_DRAW_CAPTION_VERTICAL:
243 {
244 if(auto pCaptionObj = dynamic_cast<SdrCaptionObj*>( pObj.get() ))
245 {
246 bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
247
248 pCaptionObj->SetVerticalWriting(bIsVertical);
249
250 if(bIsVertical)
251 {
252 SfxItemSet aSet(pObj->GetMergedItemSet());
255 pObj->SetMergedItemSet(aSet);
256 }
257
258 // don't set default text, start edit mode instead
259 // (Edit mode is started in ScTabViewShell::ExecDraw, because
260 // it must be handled by FuText)
261
262 pCaptionObj->SetLogicRect(aRect);
263 pCaptionObj->SetTailPos(
264 aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
265 }
266 else
267 {
268 OSL_FAIL("Object is NO caption object");
269 }
270
271 break;
272 }
273
274 default:
275 {
276 pObj->SetLogicRect(aRect);
277
278 break;
279 }
280 }
281
282 SfxItemSet aAttr(pDrDoc->GetItemPool());
283 SetLineEnds(aAttr, *pObj, nID);
284 pObj->SetMergedItemSet(aAttr);
285 }
286
287 return pObj;
288}
289
290/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void SetLineEnds(SfxItemSet &rAttr, const SdrObject &rObj, sal_uInt16 nSlotId, tools::Long nWidth)
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fuconrec.cxx:54
virtual ~FuConstRectangle() override
Definition: fuconrec.cxx:50
virtual void Activate() override
Definition: fuconrec.cxx:122
virtual rtl::Reference< SdrObject > CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle &rRectangle) override
Definition: fuconrec.cxx:188
FuConstRectangle(ScTabViewShell &rViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, const SfxRequest &rReq)
Definition: fuconrec.cxx:44
static void SetLineEnds(SfxItemSet &rAttr, const SdrObject &rObj, sal_uInt16 nSlotId)
Definition: fuconrec.cxx:176
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fuconrec.cxx:89
virtual void Deactivate() override
Definition: fuconrec.cxx:181
Draw rectangle.
Definition: fuconstr.hxx:28
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:128
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:46
PointerStyle aNewPointer
Definition: fudraw.hxx:30
PointerStyle aOldPointer
Definition: fudraw.hxx:31
ScDrawView * pView
Definition: fupoor.hxx:42
virtual void Activate()
Definition: fupoor.cxx:61
void SetMouseButtonCode(sal_uInt16 nNew)
Definition: fupoor.hxx:70
SfxRequest aSfxRequest
Definition: fupoor.hxx:47
SdrModel * pDrDoc
Definition: fupoor.hxx:45
virtual void Deactivate()
Definition: fupoor.cxx:65
ScTabViewShell & rViewShell
Definition: fupoor.hxx:43
VclPtr< vcl::Window > pWindow
Definition: fupoor.hxx:44
sal_uInt16 GetButtons() const
const Point & GetPosPixel() const
bool IsLeft() const
void SetVertical(bool bNew)
bool IsEffectivelyVertical() const
constexpr tools::Long X() const
void SetActivePointer(PointerStyle nPointer)
Definition: tabview.cxx:885
bool BegCreateObj(const Point &rPnt, OutputDevice *pOut=nullptr, short nMinMov=-3)
bool IsCreateObj() const
bool EndCreateObj(SdrCreateCmd eCmd)
SdrInventor GetCurrentObjInventor() const
SdrObjKind GetCurrentObjIdentifier() const
virtual bool IsAction() const override
void SetCurrentObj(SdrObjKind nIdent, SdrInventor nInvent=SdrInventor::Default)
SdrObject * GetCreateObj() const
bool BegCreateCaptionObj(const Point &rPnt, const Size &rObjSiz, OutputDevice *pOut=nullptr, short nMinMov=-3)
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
const SfxItemPool & GetItemPool() const
static rtl::Reference< SdrObject > MakeNewObject(SdrModel &rSdrModel, SdrInventor nInventor, SdrObjKind nObjIdentifier, const tools::Rectangle *pSnapRect=nullptr)
virtual OutlinerParaObject * GetOutlinerParaObject() const
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
SdrModel & getSdrModelFromSdrObject() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
constexpr tools::Long GetWidth() const
constexpr tools::Long Top() const
constexpr Point TopLeft() const
constexpr Point BottomRight() const
constexpr tools::Long GetHeight() const
constexpr tools::Long Bottom() const
SDRTEXTVERTADJUST_CENTER
SDRTEXTHORZADJUST_RIGHT
SVXCORE_DLLPUBLIC SdrTextObj * DynCastSdrTextObj(SdrObject *)
SdrObjKind