1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "fuconrec.hxx"
28cdf0e10cSrcweir #include "tabvwsh.hxx"
29cdf0e10cSrcweir #include "sc.hrc"
30cdf0e10cSrcweir #include "drawview.hxx"
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <editeng/outlobj.hxx>
33cdf0e10cSrcweir // #98185# Create default drawing objects via keyboard
34cdf0e10cSrcweir #include <svx/svdopath.hxx>
35cdf0e10cSrcweir #include <svx/svdocapt.hxx>
36cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
37cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include "scresid.hxx"
40cdf0e10cSrcweir
41cdf0e10cSrcweir //------------------------------------------------------------------------
42cdf0e10cSrcweir
43cdf0e10cSrcweir
44cdf0e10cSrcweir /*************************************************************************
45cdf0e10cSrcweir |*
46cdf0e10cSrcweir |* Konstruktor
47cdf0e10cSrcweir |*
48cdf0e10cSrcweir \************************************************************************/
49cdf0e10cSrcweir
FuConstRectangle(ScTabViewShell * pViewSh,Window * pWin,ScDrawView * pViewP,SdrModel * pDoc,SfxRequest & rReq)50cdf0e10cSrcweir FuConstRectangle::FuConstRectangle(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
51cdf0e10cSrcweir SdrModel* pDoc, SfxRequest& rReq)
52cdf0e10cSrcweir : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir
56cdf0e10cSrcweir /*************************************************************************
57cdf0e10cSrcweir |*
58cdf0e10cSrcweir |* Destruktor
59cdf0e10cSrcweir |*
60cdf0e10cSrcweir \************************************************************************/
61cdf0e10cSrcweir
~FuConstRectangle()62cdf0e10cSrcweir FuConstRectangle::~FuConstRectangle()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
66cdf0e10cSrcweir /*************************************************************************
67cdf0e10cSrcweir |*
68cdf0e10cSrcweir |* MouseButtonDown-event
69cdf0e10cSrcweir |*
70cdf0e10cSrcweir \************************************************************************/
71cdf0e10cSrcweir
MouseButtonDown(const MouseEvent & rMEvt)72cdf0e10cSrcweir sal_Bool __EXPORT FuConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir // #95491# remember button state for creation of own MouseEvents
75cdf0e10cSrcweir SetMouseButtonCode(rMEvt.GetButtons());
76cdf0e10cSrcweir
77cdf0e10cSrcweir sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
78cdf0e10cSrcweir
79cdf0e10cSrcweir if ( rMEvt.IsLeft() && !pView->IsAction() )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
82cdf0e10cSrcweir
83cdf0e10cSrcweir pWindow->CaptureMouse();
84cdf0e10cSrcweir
85cdf0e10cSrcweir if ( pView->GetCurrentObjIdentifier() == OBJ_CAPTION )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir Size aCaptionSize ( 2268, 1134 ); // 4x2cm
88cdf0e10cSrcweir
89cdf0e10cSrcweir bReturn = pView->BegCreateCaptionObj( aPos, aCaptionSize );
90cdf0e10cSrcweir
91cdf0e10cSrcweir // wie stellt man den Font ein, mit dem geschrieben wird
92cdf0e10cSrcweir }
93cdf0e10cSrcweir else
94cdf0e10cSrcweir bReturn = pView->BegCreateObj(aPos);
95cdf0e10cSrcweir }
96cdf0e10cSrcweir return bReturn;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
99cdf0e10cSrcweir /*************************************************************************
100cdf0e10cSrcweir |*
101cdf0e10cSrcweir |* MouseMove-event
102cdf0e10cSrcweir |*
103cdf0e10cSrcweir \************************************************************************/
104cdf0e10cSrcweir
MouseMove(const MouseEvent & rMEvt)105cdf0e10cSrcweir sal_Bool __EXPORT FuConstRectangle::MouseMove(const MouseEvent& rMEvt)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir return FuConstruct::MouseMove(rMEvt);
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir /*************************************************************************
111cdf0e10cSrcweir |*
112cdf0e10cSrcweir |* MouseButtonUp-event
113cdf0e10cSrcweir |*
114cdf0e10cSrcweir \************************************************************************/
115cdf0e10cSrcweir
MouseButtonUp(const MouseEvent & rMEvt)116cdf0e10cSrcweir sal_Bool __EXPORT FuConstRectangle::MouseButtonUp(const MouseEvent& rMEvt)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir // #95491# remember button state for creation of own MouseEvents
119cdf0e10cSrcweir SetMouseButtonCode(rMEvt.GetButtons());
120cdf0e10cSrcweir
121cdf0e10cSrcweir sal_Bool bReturn = sal_False;
122cdf0e10cSrcweir
123cdf0e10cSrcweir if ( pView->IsCreateObj() && rMEvt.IsLeft() )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
126cdf0e10cSrcweir pView->EndCreateObj(SDRCREATE_FORCEEND);
127cdf0e10cSrcweir
128cdf0e10cSrcweir if (aSfxRequest.GetSlot() == SID_DRAW_CAPTION_VERTICAL)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir // set vertical flag for caption object
131cdf0e10cSrcweir
132cdf0e10cSrcweir const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
133cdf0e10cSrcweir if (rMarkList.GetMark(0))
134cdf0e10cSrcweir {
135cdf0e10cSrcweir SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
136cdf0e10cSrcweir // create OutlinerParaObject now so it can be set to vertical
137cdf0e10cSrcweir if ( pObj->ISA(SdrTextObj) )
138cdf0e10cSrcweir ((SdrTextObj*)pObj)->ForceOutlinerParaObject();
139cdf0e10cSrcweir OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
140cdf0e10cSrcweir if( pOPO && !pOPO->IsVertical() )
141cdf0e10cSrcweir pOPO->SetVertical( sal_True );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir bReturn = sal_True;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
150cdf0e10cSrcweir /*************************************************************************
151cdf0e10cSrcweir |*
152cdf0e10cSrcweir |* Tastaturereignisse bearbeiten
153cdf0e10cSrcweir |*
154cdf0e10cSrcweir |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
155cdf0e10cSrcweir |* FALSE.
156cdf0e10cSrcweir |*
157cdf0e10cSrcweir \************************************************************************/
158cdf0e10cSrcweir
KeyInput(const KeyEvent & rKEvt)159cdf0e10cSrcweir sal_Bool __EXPORT FuConstRectangle::KeyInput(const KeyEvent& rKEvt)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
162cdf0e10cSrcweir return(bReturn);
163cdf0e10cSrcweir }
164cdf0e10cSrcweir
165cdf0e10cSrcweir /*************************************************************************
166cdf0e10cSrcweir |*
167cdf0e10cSrcweir |* Function aktivieren
168cdf0e10cSrcweir |*
169cdf0e10cSrcweir \************************************************************************/
170cdf0e10cSrcweir
Activate()171cdf0e10cSrcweir void FuConstRectangle::Activate()
172cdf0e10cSrcweir {
173cdf0e10cSrcweir SdrObjKind aObjKind;
174cdf0e10cSrcweir
175cdf0e10cSrcweir switch (aSfxRequest.GetSlot() )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir case SID_DRAW_LINE:
178cdf0e10cSrcweir aNewPointer = Pointer( POINTER_DRAW_LINE );
179cdf0e10cSrcweir aObjKind = OBJ_LINE;
180cdf0e10cSrcweir break;
181cdf0e10cSrcweir
182cdf0e10cSrcweir case SID_DRAW_RECT:
183cdf0e10cSrcweir aNewPointer = Pointer( POINTER_DRAW_RECT );
184cdf0e10cSrcweir aObjKind = OBJ_RECT;
185cdf0e10cSrcweir break;
186cdf0e10cSrcweir
187cdf0e10cSrcweir case SID_DRAW_ELLIPSE:
188cdf0e10cSrcweir aNewPointer = Pointer( POINTER_DRAW_ELLIPSE );
189cdf0e10cSrcweir aObjKind = OBJ_CIRC;
190cdf0e10cSrcweir break;
191cdf0e10cSrcweir
192cdf0e10cSrcweir case SID_DRAW_CAPTION:
193cdf0e10cSrcweir case SID_DRAW_CAPTION_VERTICAL:
194cdf0e10cSrcweir aNewPointer = Pointer( POINTER_DRAW_CAPTION );
195cdf0e10cSrcweir aObjKind = OBJ_CAPTION;
196cdf0e10cSrcweir break;
197cdf0e10cSrcweir
198cdf0e10cSrcweir default:
199cdf0e10cSrcweir aNewPointer = Pointer( POINTER_CROSS );
200cdf0e10cSrcweir aObjKind = OBJ_RECT;
201cdf0e10cSrcweir break;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
204cdf0e10cSrcweir pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(aObjKind));
205cdf0e10cSrcweir
206cdf0e10cSrcweir aOldPointer = pWindow->GetPointer();
207cdf0e10cSrcweir pViewShell->SetActivePointer( aNewPointer );
208cdf0e10cSrcweir
209cdf0e10cSrcweir FuConstruct::Activate();
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
212cdf0e10cSrcweir /*************************************************************************
213cdf0e10cSrcweir |*
214cdf0e10cSrcweir |* Function deaktivieren
215cdf0e10cSrcweir |*
216cdf0e10cSrcweir \************************************************************************/
217cdf0e10cSrcweir
Deactivate()218cdf0e10cSrcweir void FuConstRectangle::Deactivate()
219cdf0e10cSrcweir {
220cdf0e10cSrcweir FuConstruct::Deactivate();
221cdf0e10cSrcweir pViewShell->SetActivePointer( aOldPointer );
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
224cdf0e10cSrcweir // #98185# Create default drawing objects via keyboard
CreateDefaultObject(const sal_uInt16 nID,const Rectangle & rRectangle)225cdf0e10cSrcweir SdrObject* FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
226cdf0e10cSrcweir {
227cdf0e10cSrcweir // case SID_DRAW_LINE:
228cdf0e10cSrcweir // case SID_DRAW_RECT:
229cdf0e10cSrcweir // case SID_DRAW_ELLIPSE:
230cdf0e10cSrcweir // case SID_DRAW_CAPTION:
231cdf0e10cSrcweir // case SID_DRAW_CAPTION_VERTICAL:
232cdf0e10cSrcweir
233cdf0e10cSrcweir SdrObject* pObj = SdrObjFactory::MakeNewObject(
234cdf0e10cSrcweir pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
235cdf0e10cSrcweir 0L, pDrDoc);
236cdf0e10cSrcweir
237cdf0e10cSrcweir if(pObj)
238cdf0e10cSrcweir {
239cdf0e10cSrcweir Rectangle aRect(rRectangle);
240cdf0e10cSrcweir Point aStart = aRect.TopLeft();
241cdf0e10cSrcweir Point aEnd = aRect.BottomRight();
242cdf0e10cSrcweir
243cdf0e10cSrcweir switch(nID)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir case SID_DRAW_LINE:
246cdf0e10cSrcweir {
247cdf0e10cSrcweir if(pObj->ISA(SdrPathObj))
248cdf0e10cSrcweir {
249cdf0e10cSrcweir sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
250cdf0e10cSrcweir basegfx::B2DPolygon aPoly;
251cdf0e10cSrcweir aPoly.append(basegfx::B2DPoint(aStart.X(), nYMiddle));
252cdf0e10cSrcweir aPoly.append(basegfx::B2DPoint(aEnd.X(), nYMiddle));
253cdf0e10cSrcweir ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aPoly));
254cdf0e10cSrcweir }
255cdf0e10cSrcweir else
256cdf0e10cSrcweir {
257cdf0e10cSrcweir DBG_ERROR("Object is NO line object");
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir break;
261cdf0e10cSrcweir }
262cdf0e10cSrcweir case SID_DRAW_CAPTION:
263cdf0e10cSrcweir case SID_DRAW_CAPTION_VERTICAL:
264cdf0e10cSrcweir {
265cdf0e10cSrcweir if(pObj->ISA(SdrCaptionObj))
266cdf0e10cSrcweir {
267cdf0e10cSrcweir sal_Bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
268cdf0e10cSrcweir
269cdf0e10cSrcweir ((SdrTextObj*)pObj)->SetVerticalWriting(bIsVertical);
270cdf0e10cSrcweir
271cdf0e10cSrcweir if(bIsVertical)
272cdf0e10cSrcweir {
273cdf0e10cSrcweir SfxItemSet aSet(pObj->GetMergedItemSet());
274cdf0e10cSrcweir aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
275cdf0e10cSrcweir aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
276cdf0e10cSrcweir pObj->SetMergedItemSet(aSet);
277cdf0e10cSrcweir }
278cdf0e10cSrcweir
279cdf0e10cSrcweir // #105815# don't set default text, start edit mode instead
280cdf0e10cSrcweir // (Edit mode is started in ScTabViewShell::ExecDraw, because
281cdf0e10cSrcweir // it must be handled by FuText)
282cdf0e10cSrcweir // String aText(ScResId(STR_CAPTION_DEFAULT_TEXT));
283cdf0e10cSrcweir // ((SdrCaptionObj*)pObj)->SetText(aText);
284cdf0e10cSrcweir
285cdf0e10cSrcweir ((SdrCaptionObj*)pObj)->SetLogicRect(aRect);
286cdf0e10cSrcweir ((SdrCaptionObj*)pObj)->SetTailPos(
287cdf0e10cSrcweir aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
288cdf0e10cSrcweir }
289cdf0e10cSrcweir else
290cdf0e10cSrcweir {
291cdf0e10cSrcweir DBG_ERROR("Object is NO caption object");
292cdf0e10cSrcweir }
293cdf0e10cSrcweir
294cdf0e10cSrcweir break;
295cdf0e10cSrcweir }
296cdf0e10cSrcweir
297cdf0e10cSrcweir default:
298cdf0e10cSrcweir {
299cdf0e10cSrcweir pObj->SetLogicRect(aRect);
300cdf0e10cSrcweir
301cdf0e10cSrcweir break;
302cdf0e10cSrcweir }
303cdf0e10cSrcweir }
304cdf0e10cSrcweir
305cdf0e10cSrcweir SfxItemSet aAttr(pDrDoc->GetItemPool());
306cdf0e10cSrcweir pObj->SetMergedItemSet(aAttr);
307cdf0e10cSrcweir }
308cdf0e10cSrcweir
309cdf0e10cSrcweir return pObj;
310cdf0e10cSrcweir }
311