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