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