Update ooo320-m1
[ooovba.git] / sc / source / ui / drawfunc / fuconrec.cxx
blob3e653413ef8b8d777f7419d537753ee9d4300c86
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuconrec.cxx,v $
10 * $Revision: 1.14.128.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "fuconrec.hxx"
35 #include "tabvwsh.hxx"
36 #include "sc.hrc"
37 #include "drawview.hxx"
39 #include <svx/outlobj.hxx>
40 // #98185# Create default drawing objects via keyboard
41 #include <svx/svdopath.hxx>
42 #include <svx/svdocapt.hxx>
43 #include <basegfx/polygon/b2dpolygon.hxx>
44 #include <basegfx/point/b2dpoint.hxx>
46 #include "scresid.hxx"
48 //------------------------------------------------------------------------
51 /*************************************************************************
53 |* Konstruktor
55 \************************************************************************/
57 FuConstRectangle::FuConstRectangle(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
58 SdrModel* pDoc, SfxRequest& rReq)
59 : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
63 /*************************************************************************
65 |* Destruktor
67 \************************************************************************/
69 FuConstRectangle::~FuConstRectangle()
73 /*************************************************************************
75 |* MouseButtonDown-event
77 \************************************************************************/
79 BOOL __EXPORT FuConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)
81 // #95491# remember button state for creation of own MouseEvents
82 SetMouseButtonCode(rMEvt.GetButtons());
84 BOOL bReturn = FuConstruct::MouseButtonDown(rMEvt);
86 if ( rMEvt.IsLeft() && !pView->IsAction() )
88 Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
90 pWindow->CaptureMouse();
92 if ( pView->GetCurrentObjIdentifier() == OBJ_CAPTION )
94 Size aCaptionSize ( 2268, 1134 ); // 4x2cm
96 bReturn = pView->BegCreateCaptionObj( aPos, aCaptionSize );
98 // wie stellt man den Font ein, mit dem geschrieben wird
100 else
101 bReturn = pView->BegCreateObj(aPos);
103 return bReturn;
106 /*************************************************************************
108 |* MouseMove-event
110 \************************************************************************/
112 BOOL __EXPORT FuConstRectangle::MouseMove(const MouseEvent& rMEvt)
114 return FuConstruct::MouseMove(rMEvt);
117 /*************************************************************************
119 |* MouseButtonUp-event
121 \************************************************************************/
123 BOOL __EXPORT FuConstRectangle::MouseButtonUp(const MouseEvent& rMEvt)
125 // #95491# remember button state for creation of own MouseEvents
126 SetMouseButtonCode(rMEvt.GetButtons());
128 BOOL bReturn = FALSE;
130 if ( pView->IsCreateObj() && rMEvt.IsLeft() )
132 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
133 pView->EndCreateObj(SDRCREATE_FORCEEND);
135 if (aSfxRequest.GetSlot() == SID_DRAW_CAPTION_VERTICAL)
137 // set vertical flag for caption object
139 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
140 if (rMarkList.GetMark(0))
142 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
143 // create OutlinerParaObject now so it can be set to vertical
144 if ( pObj->ISA(SdrTextObj) )
145 ((SdrTextObj*)pObj)->ForceOutlinerParaObject();
146 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
147 if( pOPO && !pOPO->IsVertical() )
148 pOPO->SetVertical( TRUE );
152 bReturn = TRUE;
154 return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
157 /*************************************************************************
159 |* Tastaturereignisse bearbeiten
161 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
162 |* FALSE.
164 \************************************************************************/
166 BOOL __EXPORT FuConstRectangle::KeyInput(const KeyEvent& rKEvt)
168 BOOL bReturn = FuConstruct::KeyInput(rKEvt);
169 return(bReturn);
172 /*************************************************************************
174 |* Function aktivieren
176 \************************************************************************/
178 void FuConstRectangle::Activate()
180 SdrObjKind aObjKind;
182 switch (aSfxRequest.GetSlot() )
184 case SID_DRAW_LINE:
185 aNewPointer = Pointer( POINTER_DRAW_LINE );
186 aObjKind = OBJ_LINE;
187 break;
189 case SID_DRAW_RECT:
190 aNewPointer = Pointer( POINTER_DRAW_RECT );
191 aObjKind = OBJ_RECT;
192 break;
194 case SID_DRAW_ELLIPSE:
195 aNewPointer = Pointer( POINTER_DRAW_ELLIPSE );
196 aObjKind = OBJ_CIRC;
197 break;
199 case SID_DRAW_CAPTION:
200 case SID_DRAW_CAPTION_VERTICAL:
201 aNewPointer = Pointer( POINTER_DRAW_CAPTION );
202 aObjKind = OBJ_CAPTION;
203 break;
205 default:
206 aNewPointer = Pointer( POINTER_CROSS );
207 aObjKind = OBJ_RECT;
208 break;
211 pView->SetCurrentObj(sal::static_int_cast<UINT16>(aObjKind));
213 aOldPointer = pWindow->GetPointer();
214 pViewShell->SetActivePointer( aNewPointer );
216 FuConstruct::Activate();
219 /*************************************************************************
221 |* Function deaktivieren
223 \************************************************************************/
225 void FuConstRectangle::Deactivate()
227 FuConstruct::Deactivate();
228 pViewShell->SetActivePointer( aOldPointer );
231 // #98185# Create default drawing objects via keyboard
232 SdrObject* FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
234 // case SID_DRAW_LINE:
235 // case SID_DRAW_RECT:
236 // case SID_DRAW_ELLIPSE:
237 // case SID_DRAW_CAPTION:
238 // case SID_DRAW_CAPTION_VERTICAL:
240 SdrObject* pObj = SdrObjFactory::MakeNewObject(
241 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
242 0L, pDrDoc);
244 if(pObj)
246 Rectangle aRect(rRectangle);
247 Point aStart = aRect.TopLeft();
248 Point aEnd = aRect.BottomRight();
250 switch(nID)
252 case SID_DRAW_LINE:
254 if(pObj->ISA(SdrPathObj))
256 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
257 basegfx::B2DPolygon aPoly;
258 aPoly.append(basegfx::B2DPoint(aStart.X(), nYMiddle));
259 aPoly.append(basegfx::B2DPoint(aEnd.X(), nYMiddle));
260 ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aPoly));
262 else
264 DBG_ERROR("Object is NO line object");
267 break;
269 case SID_DRAW_CAPTION:
270 case SID_DRAW_CAPTION_VERTICAL:
272 if(pObj->ISA(SdrCaptionObj))
274 sal_Bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
276 ((SdrTextObj*)pObj)->SetVerticalWriting(bIsVertical);
278 if(bIsVertical)
280 SfxItemSet aSet(pObj->GetMergedItemSet());
281 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
282 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
283 pObj->SetMergedItemSet(aSet);
286 // #105815# don't set default text, start edit mode instead
287 // (Edit mode is started in ScTabViewShell::ExecDraw, because
288 // it must be handled by FuText)
289 // String aText(ScResId(STR_CAPTION_DEFAULT_TEXT));
290 // ((SdrCaptionObj*)pObj)->SetText(aText);
292 ((SdrCaptionObj*)pObj)->SetLogicRect(aRect);
293 ((SdrCaptionObj*)pObj)->SetTailPos(
294 aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
296 else
298 DBG_ERROR("Object is NO caption object");
301 break;
304 default:
306 pObj->SetLogicRect(aRect);
308 break;
312 SfxItemSet aAttr(pDrDoc->GetItemPool());
313 pObj->SetMergedItemSet(aAttr);
316 return pObj;