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