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"
35 //------------------------------------------------------------------------
38 /*************************************************************************
42 \************************************************************************/
44 FuConstRectangle::FuConstRectangle(ScTabViewShell
* pViewSh
, Window
* pWin
, ScDrawView
* pViewP
,
45 SdrModel
* pDoc
, SfxRequest
& rReq
)
46 : FuConstruct(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
50 /*************************************************************************
54 \************************************************************************/
56 FuConstRectangle::~FuConstRectangle()
60 /*************************************************************************
62 |* MouseButtonDown-event
64 \************************************************************************/
66 sal_Bool
FuConstRectangle::MouseButtonDown(const MouseEvent
& rMEvt
)
68 // remember button state for creation of own MouseEvents
69 SetMouseButtonCode(rMEvt
.GetButtons());
71 sal_Bool bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
73 if ( rMEvt
.IsLeft() && !pView
->IsAction() )
75 Point
aPos( pWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
76 // Hack to align object to nearest grid position where object
77 // would be anchored ( if it were cell anchored )
78 // Get grid offset for current position ( note: aPnt is
80 Point aGridOff
= CurrentGridSyncOffsetAndPos( aPos
);
81 pWindow
->CaptureMouse();
83 if ( pView
->GetCurrentObjIdentifier() == OBJ_CAPTION
)
85 Size
aCaptionSize ( 2268, 1134 ); // 4x2cm
87 bReturn
= pView
->BegCreateCaptionObj( aPos
, aCaptionSize
);
89 // wie stellt man den Font ein, mit dem geschrieben wird
92 bReturn
= pView
->BegCreateObj(aPos
);
94 pView
->GetCreateObj()->SetGridOffset( aGridOff
);
99 /*************************************************************************
103 \************************************************************************/
105 sal_Bool
FuConstRectangle::MouseMove(const MouseEvent
& rMEvt
)
107 return FuConstruct::MouseMove(rMEvt
);
110 /*************************************************************************
112 |* MouseButtonUp-event
114 \************************************************************************/
116 sal_Bool
FuConstRectangle::MouseButtonUp(const MouseEvent
& rMEvt
)
118 // remember button state for creation of own MouseEvents
119 SetMouseButtonCode(rMEvt
.GetButtons());
121 sal_Bool bReturn
= false;
123 if ( pView
->IsCreateObj() && rMEvt
.IsLeft() )
125 pView
->EndCreateObj(SDRCREATE_FORCEEND
);
127 if (aSfxRequest
.GetSlot() == SID_DRAW_CAPTION_VERTICAL
)
129 // set vertical flag for caption object
131 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
132 if (rMarkList
.GetMark(0))
134 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
135 // create OutlinerParaObject now so it can be set to vertical
136 if ( pObj
->ISA(SdrTextObj
) )
137 ((SdrTextObj
*)pObj
)->ForceOutlinerParaObject();
138 OutlinerParaObject
* pOPO
= pObj
->GetOutlinerParaObject();
139 if( pOPO
&& !pOPO
->IsVertical() )
140 pOPO
->SetVertical( sal_True
);
146 return (FuConstruct::MouseButtonUp(rMEvt
) || bReturn
);
149 /*************************************************************************
151 |* Tastaturereignisse bearbeiten
153 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
156 \************************************************************************/
158 sal_Bool
FuConstRectangle::KeyInput(const KeyEvent
& rKEvt
)
160 sal_Bool bReturn
= FuConstruct::KeyInput(rKEvt
);
164 /*************************************************************************
166 |* Function aktivieren
168 \************************************************************************/
170 void FuConstRectangle::Activate()
174 switch (aSfxRequest
.GetSlot() )
177 aNewPointer
= Pointer( POINTER_DRAW_LINE
);
182 aNewPointer
= Pointer( POINTER_DRAW_RECT
);
186 case SID_DRAW_ELLIPSE
:
187 aNewPointer
= Pointer( POINTER_DRAW_ELLIPSE
);
191 case SID_DRAW_CAPTION
:
192 case SID_DRAW_CAPTION_VERTICAL
:
193 aNewPointer
= Pointer( POINTER_DRAW_CAPTION
);
194 aObjKind
= OBJ_CAPTION
;
198 aNewPointer
= Pointer( POINTER_CROSS
);
203 pView
->SetCurrentObj(sal::static_int_cast
<sal_uInt16
>(aObjKind
));
205 aOldPointer
= pWindow
->GetPointer();
206 pViewShell
->SetActivePointer( aNewPointer
);
208 FuConstruct::Activate();
211 /*************************************************************************
213 |* Function deaktivieren
215 \************************************************************************/
217 void FuConstRectangle::Deactivate()
219 FuConstruct::Deactivate();
220 pViewShell
->SetActivePointer( aOldPointer
);
223 // Create default drawing objects via keyboard
224 SdrObject
* FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID
, const Rectangle
& rRectangle
)
226 SdrObject
* pObj
= SdrObjFactory::MakeNewObject(
227 pView
->GetCurrentObjInventor(), pView
->GetCurrentObjIdentifier(),
232 Rectangle
aRect(rRectangle
);
233 Point aStart
= aRect
.TopLeft();
234 Point aEnd
= aRect
.BottomRight();
240 if(pObj
->ISA(SdrPathObj
))
242 sal_Int32
nYMiddle((aRect
.Top() + aRect
.Bottom()) / 2);
243 basegfx::B2DPolygon aPoly
;
244 aPoly
.append(basegfx::B2DPoint(aStart
.X(), nYMiddle
));
245 aPoly
.append(basegfx::B2DPoint(aEnd
.X(), nYMiddle
));
246 ((SdrPathObj
*)pObj
)->SetPathPoly(basegfx::B2DPolyPolygon(aPoly
));
250 OSL_FAIL("Object is NO line object");
255 case SID_DRAW_CAPTION
:
256 case SID_DRAW_CAPTION_VERTICAL
:
258 if(pObj
->ISA(SdrCaptionObj
))
260 sal_Bool
bIsVertical(SID_DRAW_CAPTION_VERTICAL
== nID
);
262 ((SdrTextObj
*)pObj
)->SetVerticalWriting(bIsVertical
);
266 SfxItemSet
aSet(pObj
->GetMergedItemSet());
267 aSet
.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER
));
268 aSet
.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT
));
269 pObj
->SetMergedItemSet(aSet
);
272 // don't set default text, start edit mode instead
273 // (Edit mode is started in ScTabViewShell::ExecDraw, because
274 // it must be handled by FuText)
275 // String aText(ScResId(STR_CAPTION_DEFAULT_TEXT));
276 // ((SdrCaptionObj*)pObj)->SetText(aText);
278 ((SdrCaptionObj
*)pObj
)->SetLogicRect(aRect
);
279 ((SdrCaptionObj
*)pObj
)->SetTailPos(
280 aRect
.TopLeft() - Point(aRect
.GetWidth() / 2, aRect
.GetHeight() / 2));
284 OSL_FAIL("Object is NO caption object");
292 pObj
->SetLogicRect(aRect
);
298 SfxItemSet
aAttr(pDrDoc
->GetItemPool());
299 pObj
->SetMergedItemSet(aAttr
);
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */