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 .
21 #include "fuconrec.hxx"
22 #include "tabvwsh.hxx"
24 #include "drawview.hxx"
26 #include <editeng/outlobj.hxx>
27 // Create default drawing objects via keyboard
28 #include <svx/svdopath.hxx>
29 #include <svx/svdocapt.hxx>
30 #include <basegfx/polygon/b2dpolygon.hxx>
31 #include <basegfx/point/b2dpoint.hxx>
33 #include "scresid.hxx"
36 /*************************************************************************
40 \************************************************************************/
42 FuConstRectangle::FuConstRectangle(ScTabViewShell
* pViewSh
, Window
* pWin
, ScDrawView
* pViewP
,
43 SdrModel
* pDoc
, SfxRequest
& rReq
)
44 : FuConstruct(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
48 /*************************************************************************
52 \************************************************************************/
54 FuConstRectangle::~FuConstRectangle()
58 /*************************************************************************
60 |* MouseButtonDown-event
62 \************************************************************************/
64 bool FuConstRectangle::MouseButtonDown(const MouseEvent
& rMEvt
)
66 // remember button state for creation of own MouseEvents
67 SetMouseButtonCode(rMEvt
.GetButtons());
69 bool bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
71 if ( rMEvt
.IsLeft() && !pView
->IsAction() )
73 Point
aPos( pWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
74 // Hack to align object to nearest grid position where object
75 // would be anchored ( if it were cell anchored )
76 // Get grid offset for current position ( note: aPnt is
78 Point aGridOff
= CurrentGridSyncOffsetAndPos( aPos
);
79 pWindow
->CaptureMouse();
81 if ( pView
->GetCurrentObjIdentifier() == OBJ_CAPTION
)
83 Size
aCaptionSize ( 2268, 1134 ); // 4x2cm
85 bReturn
= pView
->BegCreateCaptionObj( aPos
, aCaptionSize
);
87 // wie stellt man den Font ein, mit dem geschrieben wird
90 bReturn
= pView
->BegCreateObj(aPos
);
92 pView
->GetCreateObj()->SetGridOffset( aGridOff
);
97 /*************************************************************************
101 \************************************************************************/
103 bool FuConstRectangle::MouseMove(const MouseEvent
& rMEvt
)
105 return FuConstruct::MouseMove(rMEvt
);
108 /*************************************************************************
110 |* MouseButtonUp-event
112 \************************************************************************/
114 bool FuConstRectangle::MouseButtonUp(const MouseEvent
& rMEvt
)
116 // remember button state for creation of own MouseEvents
117 SetMouseButtonCode(rMEvt
.GetButtons());
119 bool bReturn
= false;
121 if ( pView
->IsCreateObj() && rMEvt
.IsLeft() )
123 pView
->EndCreateObj(SDRCREATE_FORCEEND
);
125 if (aSfxRequest
.GetSlot() == SID_DRAW_CAPTION_VERTICAL
)
127 // set vertical flag for caption object
129 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
130 if (rMarkList
.GetMark(0))
132 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
133 // create OutlinerParaObject now so it can be set to vertical
134 if ( pObj
->ISA(SdrTextObj
) )
135 ((SdrTextObj
*)pObj
)->ForceOutlinerParaObject();
136 OutlinerParaObject
* pOPO
= pObj
->GetOutlinerParaObject();
137 if( pOPO
&& !pOPO
->IsVertical() )
138 pOPO
->SetVertical( true );
144 return (FuConstruct::MouseButtonUp(rMEvt
) || bReturn
);
147 /*************************************************************************
149 |* Tastaturereignisse bearbeiten
151 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
154 \************************************************************************/
156 bool FuConstRectangle::KeyInput(const KeyEvent
& rKEvt
)
158 return FuConstruct::KeyInput(rKEvt
);
161 /*************************************************************************
163 |* Function aktivieren
165 \************************************************************************/
167 void FuConstRectangle::Activate()
171 switch (aSfxRequest
.GetSlot() )
174 aNewPointer
= Pointer( POINTER_DRAW_LINE
);
179 aNewPointer
= Pointer( POINTER_DRAW_RECT
);
183 case SID_DRAW_ELLIPSE
:
184 aNewPointer
= Pointer( POINTER_DRAW_ELLIPSE
);
188 case SID_DRAW_CAPTION
:
189 case SID_DRAW_CAPTION_VERTICAL
:
190 aNewPointer
= Pointer( POINTER_DRAW_CAPTION
);
191 aObjKind
= OBJ_CAPTION
;
195 aNewPointer
= Pointer( POINTER_CROSS
);
200 pView
->SetCurrentObj(sal::static_int_cast
<sal_uInt16
>(aObjKind
));
202 aOldPointer
= pWindow
->GetPointer();
203 pViewShell
->SetActivePointer( aNewPointer
);
205 FuConstruct::Activate();
208 /*************************************************************************
210 |* Function deaktivieren
212 \************************************************************************/
214 void FuConstRectangle::Deactivate()
216 FuConstruct::Deactivate();
217 pViewShell
->SetActivePointer( aOldPointer
);
220 // Create default drawing objects via keyboard
221 SdrObject
* FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID
, const Rectangle
& rRectangle
)
223 SdrObject
* pObj
= SdrObjFactory::MakeNewObject(
224 pView
->GetCurrentObjInventor(), pView
->GetCurrentObjIdentifier(),
229 Rectangle
aRect(rRectangle
);
230 Point aStart
= aRect
.TopLeft();
231 Point aEnd
= aRect
.BottomRight();
237 if(pObj
->ISA(SdrPathObj
))
239 sal_Int32
nYMiddle((aRect
.Top() + aRect
.Bottom()) / 2);
240 basegfx::B2DPolygon aPoly
;
241 aPoly
.append(basegfx::B2DPoint(aStart
.X(), nYMiddle
));
242 aPoly
.append(basegfx::B2DPoint(aEnd
.X(), nYMiddle
));
243 ((SdrPathObj
*)pObj
)->SetPathPoly(basegfx::B2DPolyPolygon(aPoly
));
247 OSL_FAIL("Object is NO line object");
252 case SID_DRAW_CAPTION
:
253 case SID_DRAW_CAPTION_VERTICAL
:
255 if(pObj
->ISA(SdrCaptionObj
))
257 bool bIsVertical(SID_DRAW_CAPTION_VERTICAL
== nID
);
259 ((SdrTextObj
*)pObj
)->SetVerticalWriting(bIsVertical
);
263 SfxItemSet
aSet(pObj
->GetMergedItemSet());
264 aSet
.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER
));
265 aSet
.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT
));
266 pObj
->SetMergedItemSet(aSet
);
269 // don't set default text, start edit mode instead
270 // (Edit mode is started in ScTabViewShell::ExecDraw, because
271 // it must be handled by FuText)
272 // String aText(ScResId(STR_CAPTION_DEFAULT_TEXT));
273 // ((SdrCaptionObj*)pObj)->SetText(aText);
275 ((SdrCaptionObj
*)pObj
)->SetLogicRect(aRect
);
276 ((SdrCaptionObj
*)pObj
)->SetTailPos(
277 aRect
.TopLeft() - Point(aRect
.GetWidth() / 2, aRect
.GetHeight() / 2));
281 OSL_FAIL("Object is NO caption object");
289 pObj
->SetLogicRect(aRect
);
295 SfxItemSet
aAttr(pDrDoc
->GetItemPool());
296 pObj
->SetMergedItemSet(aAttr
);
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */