xref: /trunk/main/sc/source/ui/drawfunc/fuconstr.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 <editeng/outliner.hxx>
32 #include <editeng/outlobj.hxx>
33 #include <svx/svdotext.hxx>
34 #include <svx/svdouno.hxx>
35 #include <sfx2/dispatch.hxx>
36 
37 #include "fuconstr.hxx"
38 #include "fudraw.hxx"
39 #include "tabvwsh.hxx"
40 #include "futext.hxx"
41 #include "sc.hrc"
42 #include "drawview.hxx"
43 
44 //	Maximal erlaubte Mausbewegung um noch Drag&Drop zu starten
45 //!	fusel,fuconstr,futext - zusammenfassen!
46 #define SC_MAXDRAGMOVE	3
47 
48 //------------------------------------------------------------------------
49 
50 /*************************************************************************
51 |*
52 |* Konstruktor
53 |*
54 \************************************************************************/
55 
56 FuConstruct::FuConstruct(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
57 				   SdrModel* pDoc, SfxRequest& rReq) :
58     FuDraw(pViewSh, pWin, pViewP, pDoc, rReq)
59 {
60 }
61 
62 /*************************************************************************
63 |*
64 |* Destruktor
65 |*
66 \************************************************************************/
67 
68 FuConstruct::~FuConstruct()
69 {
70 }
71 
72 sal_uInt8 FuConstruct::Command(const CommandEvent& rCEvt)
73 {
74 	//	special code for non-VCL OS2/UNX removed
75 
76 	return FuDraw::Command( rCEvt );
77 }
78 
79 /*************************************************************************
80 |*
81 |* MouseButtonDown-event
82 |*
83 \************************************************************************/
84 
85 sal_Bool __EXPORT FuConstruct::MouseButtonDown(const MouseEvent& rMEvt)
86 {
87 	// #95491# remember button state for creation of own MouseEvents
88 	SetMouseButtonCode(rMEvt.GetButtons());
89 
90 	sal_Bool bReturn = FuDraw::MouseButtonDown(rMEvt);
91 
92 	if ( pView->IsAction() )
93 	{
94 		if ( rMEvt.IsRight() )
95 			pView->BckAction();
96 		return sal_True;
97 	}
98 
99 	aDragTimer.Start();
100 
101 	aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
102 
103 	if ( rMEvt.IsLeft() )
104 	{
105 		pWindow->CaptureMouse();
106 
107 		SdrHdl* pHdl = pView->PickHandle(aMDPos);
108 
109 		if ( pHdl != NULL || pView->IsMarkedHit(aMDPos) )
110 		{
111 			pView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, 1);
112 			bReturn = sal_True;
113 		}
114 		else if ( pView->AreObjectsMarked() )
115 		{
116 			pView->UnmarkAll();
117 			bReturn = sal_True;
118 		}
119 	}
120 
121 	bIsInDragMode = sal_False;
122 
123 	return bReturn;
124 }
125 
126 /*************************************************************************
127 |*
128 |* MouseMove-event
129 |*
130 \************************************************************************/
131 
132 sal_Bool __EXPORT FuConstruct::MouseMove(const MouseEvent& rMEvt)
133 {
134 	FuDraw::MouseMove(rMEvt);
135 
136 	if (aDragTimer.IsActive() )
137 	{
138 		Point aOldPixel = pWindow->LogicToPixel( aMDPos );
139 		Point aNewPixel = rMEvt.GetPosPixel();
140 		if ( Abs( aOldPixel.X() - aNewPixel.X() ) > SC_MAXDRAGMOVE ||
141 			 Abs( aOldPixel.Y() - aNewPixel.Y() ) > SC_MAXDRAGMOVE )
142 			aDragTimer.Stop();
143 	}
144 
145 	Point aPix(rMEvt.GetPosPixel());
146 	Point aPnt( pWindow->PixelToLogic(aPix) );
147 
148 	if ( pView->IsAction() )
149 	{
150 		ForceScroll(aPix);
151 		pView->MovAction(aPnt);
152 	}
153 	else
154 	{
155 		SdrHdl* pHdl=pView->PickHandle(aPnt);
156 
157 		if ( pHdl != NULL )
158 		{
159 			pViewShell->SetActivePointer(pHdl->GetPointer());
160 		}
161 		else if ( pView->IsMarkedHit(aPnt) )
162 		{
163 			pViewShell->SetActivePointer(Pointer(POINTER_MOVE));
164 		}
165 		else
166 		{
167 			pViewShell->SetActivePointer( aNewPointer );
168 		}
169 	}
170 	return sal_True;
171 }
172 
173 /*************************************************************************
174 |*
175 |* MouseButtonUp-event
176 |*
177 \************************************************************************/
178 
179 sal_Bool __EXPORT FuConstruct::MouseButtonUp(const MouseEvent& rMEvt)
180 {
181 	// #95491# remember button state for creation of own MouseEvents
182 	SetMouseButtonCode(rMEvt.GetButtons());
183 
184 	sal_Bool bReturn = SimpleMouseButtonUp( rMEvt );
185 
186 	//		Doppelklick auf Textobjekt? (->fusel)
187 
188 	sal_uInt16 nClicks = rMEvt.GetClicks();
189 	if ( nClicks == 2 && rMEvt.IsLeft() )
190 	{
191 		if ( pView->AreObjectsMarked() )
192 		{
193 			const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
194 			if (rMarkList.GetMarkCount() == 1)
195 			{
196 				SdrMark* pMark = rMarkList.GetMark(0);
197 				SdrObject* pObj = pMark->GetMarkedSdrObj();
198 
199 				//	#49458# bei Uno-Controls nicht in Textmodus
200 				if ( pObj->ISA(SdrTextObj) && !pObj->ISA(SdrUnoObj) )
201 				{
202 					OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
203 					sal_Bool bVertical = ( pOPO && pOPO->IsVertical() );
204 					sal_uInt16 nTextSlotId = bVertical ? SID_DRAW_TEXT_VERTICAL : SID_DRAW_TEXT;
205 
206 					pViewShell->GetViewData()->GetDispatcher().
207 						Execute(nTextSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
208 
209 					// jetzt den erzeugten FuText holen und in den EditModus setzen
210 					FuPoor* pPoor = pViewShell->GetViewData()->GetView()->GetDrawFuncPtr();
211 					if ( pPoor && pPoor->GetSlotID() == nTextSlotId )	 //	hat keine RTTI
212 					{
213 						FuText* pText = (FuText*)pPoor;
214 						Point aMousePixel = rMEvt.GetPosPixel();
215 						pText->SetInEditMode( pObj, &aMousePixel );
216 					}
217 					bReturn = sal_True;
218 				}
219 			}
220 		}
221 	}
222 
223 	FuDraw::MouseButtonUp(rMEvt);
224 
225 	return bReturn;
226 }
227 
228 //		SimpleMouseButtonUp - ohne Test auf Doppelklick
229 
230 sal_Bool FuConstruct::SimpleMouseButtonUp(const MouseEvent& rMEvt)
231 {
232 	sal_Bool	bReturn = sal_True;
233 
234 	if (aDragTimer.IsActive() )
235 	{
236 		aDragTimer.Stop();
237 	}
238 
239 	Point	aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
240 
241 	if ( pView->IsDragObj() )
242 		 pView->EndDragObj( rMEvt.IsMod1() );
243 
244 	else if ( pView->IsMarkObj() )
245 		pView->EndMarkObj();
246 
247 	else bReturn = sal_False;
248 
249 	if ( !pView->IsAction() )
250 	{
251 		pWindow->ReleaseMouse();
252 
253 		if ( !pView->AreObjectsMarked() && rMEvt.GetClicks() < 2 )
254 		{
255 			pView->MarkObj(aPnt, -2, sal_False, rMEvt.IsMod1());
256 
257 			SfxDispatcher& rDisp = pViewShell->GetViewData()->GetDispatcher();
258 			if ( pView->AreObjectsMarked() )
259 				rDisp.Execute(SID_OBJECT_SELECT, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
260 			else
261 				rDisp.Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
262 		}
263 	}
264 
265 	return bReturn;
266 }
267 
268 /*************************************************************************
269 |*
270 |* Tastaturereignisse bearbeiten
271 |*
272 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
273 |* FALSE.
274 |*
275 \************************************************************************/
276 
277 sal_Bool __EXPORT FuConstruct::KeyInput(const KeyEvent& rKEvt)
278 {
279 	sal_Bool bReturn = sal_False;
280 
281 	switch ( rKEvt.GetKeyCode().GetCode() )
282 	{
283 		case KEY_ESCAPE:
284 			if ( pView->IsAction() )
285 			{
286 				pView->BrkAction();
287 				pWindow->ReleaseMouse();
288 				bReturn = sal_True;
289 			}
290 			else							// Zeichenmodus beenden
291 			{
292 				pViewShell->GetViewData()->GetDispatcher().
293 					Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
294 			}
295 			break;
296 
297 		case KEY_DELETE:
298 			pView->DeleteMarked();
299 			bReturn = sal_True;
300 			break;
301 	}
302 
303 	if ( !bReturn )
304 	{
305 		bReturn = FuDraw::KeyInput(rKEvt);
306 	}
307 
308 	return(bReturn);
309 }
310 
311 /*************************************************************************
312 |*
313 |* Function aktivieren
314 |*
315 \************************************************************************/
316 
317 void FuConstruct::Activate()
318 {
319 	FuDraw::Activate();
320 }
321 
322 /*************************************************************************
323 |*
324 |* Function deaktivieren
325 |*
326 \************************************************************************/
327 
328 void FuConstruct::Deactivate()
329 {
330 	FuDraw::Deactivate();
331 }
332 
333 
334 
335 
336