xref: /trunk/main/sc/source/ui/drawfunc/fupoor.cxx (revision 86e1cf34)
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 <editeng/outliner.hxx>
28 #include <svx/svditer.hxx>
29 #include <svx/svdobj.hxx>
30 #include <svx/svdpagv.hxx>
31 
32 #include "fupoor.hxx"
33 #include "tabvwsh.hxx"
34 #include "drawview.hxx"
35 #include "detfunc.hxx"
36 #include "document.hxx"
37 #include <vcl/svapp.hxx>
38 #include <svx/sdrhittesthelper.hxx>
39 
40 /*************************************************************************
41 |*
42 |* Konstruktor
43 |*
44 \************************************************************************/
45 
FuPoor(ScTabViewShell * pViewSh,Window * pWin,ScDrawView * pViewP,SdrModel * pDoc,SfxRequest & rReq)46 FuPoor::FuPoor(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
47 			   SdrModel* pDoc, SfxRequest& rReq) :
48     pView(pViewP),
49 	pViewShell(pViewSh),
50 	pWindow(pWin),
51 	pDrDoc(pDoc),
52 	aSfxRequest(rReq),
53 	pDialog(NULL),
54 	bIsInDragMode(sal_False),
55 	// #95491# remember MouseButton state
56 	mnCode(0)
57 {
58 	aScrollTimer.SetTimeoutHdl( LINK(this, FuPoor, ScrollHdl) );
59 	aScrollTimer.SetTimeout(SELENG_AUTOREPEAT_INTERVAL);
60 
61 	aDragTimer.SetTimeoutHdl( LINK(this, FuPoor, DragTimerHdl) );
62 	aDragTimer.SetTimeout(SELENG_DRAGDROP_TIMEOUT);
63 }
64 
65 /*************************************************************************
66 |*
67 |* Destruktor
68 |*
69 \************************************************************************/
70 
~FuPoor()71 FuPoor::~FuPoor()
72 {
73 	aDragTimer.Stop();
74 	aScrollTimer.Stop();
75 
76 	if (pDialog)
77 		delete pDialog;
78 }
79 
80 /*************************************************************************
81 |*
82 |* Function aktivieren
83 |*
84 \************************************************************************/
85 
Activate()86 void FuPoor::Activate()
87 {
88 	if (pDialog)
89 	{
90 		pDialog->Show();
91 	}
92 }
93 
94 /*************************************************************************
95 |*
96 |* Function deaktivieren
97 |*
98 \************************************************************************/
99 
Deactivate()100 void FuPoor::Deactivate()
101 {
102 	aDragTimer.Stop();
103 	aScrollTimer.Stop();
104 
105 	if (pDialog)
106 	{
107 		pDialog->Hide();
108 	}
109 }
110 
111 /*************************************************************************
112 |*
113 |* Scrollen bei Erreichen des Fensterrandes; wird von
114 |* MouseMove aufgerufen
115 |*
116 \************************************************************************/
117 
ForceScroll(const Point & aPixPos)118 void FuPoor::ForceScroll(const Point& aPixPos)
119 {
120 	aScrollTimer.Stop();
121 
122 	Size aSize = pWindow->GetSizePixel();
123 	SCsCOL dx = 0;
124 	SCsROW dy = 0;
125 
126 	if ( aPixPos.X() <= 0			   ) dx = -1;
127 	if ( aPixPos.X() >= aSize.Width()  ) dx =  1;
128 	if ( aPixPos.Y() <= 0			   ) dy = -1;
129 	if ( aPixPos.Y() >= aSize.Height() ) dy =  1;
130 
131 	ScViewData* pViewData = pViewShell->GetViewData();
132 	if ( pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() ) )
133 		dx = -dx;
134 
135 	ScSplitPos eWhich = pViewData->GetActivePart();
136 	if ( dx > 0 && pViewData->GetHSplitMode() == SC_SPLIT_FIX && WhichH(eWhich) == SC_SPLIT_LEFT )
137 	{
138 		pViewShell->ActivatePart( ( eWhich == SC_SPLIT_TOPLEFT ) ?
139 						SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT );
140 		dx = 0;
141 	}
142 	if ( dy > 0 && pViewData->GetVSplitMode() == SC_SPLIT_FIX && WhichV(eWhich) == SC_SPLIT_TOP )
143 	{
144 		pViewShell->ActivatePart( ( eWhich == SC_SPLIT_TOPLEFT ) ?
145 						SC_SPLIT_BOTTOMLEFT : SC_SPLIT_BOTTOMRIGHT );
146 		dy = 0;
147 	}
148 
149 	if ( dx != 0 || dy != 0 )
150 	{
151 		ScrollStart();							// Scrollaktion in abgeleiteter Klasse
152 		pViewShell->ScrollLines(2*dx, 4*dy);
153 		ScrollEnd();
154 		aScrollTimer.Start();
155 	}
156 }
157 
158 /*************************************************************************
159 |*
160 |* Timer-Handler fuer Fensterscrolling
161 |*
162 \************************************************************************/
163 
IMPL_LINK_INLINE_START(FuPoor,ScrollHdl,Timer *,EMPTYARG)164 IMPL_LINK_INLINE_START( FuPoor, ScrollHdl, Timer *, EMPTYARG )
165 {
166 	Point aPosPixel = pWindow->GetPointerPosPixel();
167 
168 	// #95491# use remembered MouseButton state to create correct
169 	// MouseEvents for this artificial MouseMove.
170 	MouseMove(MouseEvent(aPosPixel, 1, 0, GetMouseButtonCode()));
171 
172 	return 0;
173 }
IMPL_LINK_INLINE_END(FuPoor,ScrollHdl,Timer *,pTimer)174 IMPL_LINK_INLINE_END( FuPoor, ScrollHdl, Timer *, pTimer )
175 
176 // #95491# moved from inline to *.cxx
177 sal_Bool FuPoor::MouseButtonUp(const MouseEvent& rMEvt)
178 {
179 	// #95491# remember button state for creation of own MouseEvents
180 	SetMouseButtonCode(rMEvt.GetButtons());
181 
182 	return sal_False;
183 }
184 
185 // #95491# moved from inline to *.cxx
MouseButtonDown(const MouseEvent & rMEvt)186 sal_Bool FuPoor::MouseButtonDown(const MouseEvent& rMEvt)
187 {
188 	// #95491# remember button state for creation of own MouseEvents
189 	SetMouseButtonCode(rMEvt.GetButtons());
190 
191 	return sal_False;
192 }
193 
194 /*************************************************************************
195 |*
196 |* String in Applikations-Statuszeile ausgeben
197 |*
198 \************************************************************************/
199 
200 //	WriteStatus gibt's nicht mehr
201 
202 /*************************************************************************
203 |*
204 |* Tastaturereignisse bearbeiten
205 |*
206 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
207 |* FALSE.
208 |*
209 \************************************************************************/
210 
KeyInput(const KeyEvent &)211 sal_Bool FuPoor::KeyInput(const KeyEvent& /* rKEvt */)
212 {
213 	sal_Bool bReturn = sal_False;
214 
215 	return(bReturn);
216 }
217 
Command(const CommandEvent & rCEvt)218 sal_uInt8 FuPoor::Command(const CommandEvent& rCEvt)
219 {
220 	if ( COMMAND_STARTDRAG == rCEvt.GetCommand() )
221 	{
222 		//!!! sollte Joe eigentlich machen:
223 		// nur, wenn im Outliner was selektiert ist, darf
224 		// Command sal_True zurueckliefern:
225 
226 		OutlinerView* pOutView = pView->GetTextEditOutlinerView();
227 
228 		if ( pOutView )
229 			return pOutView->HasSelection() ? pView->Command(rCEvt,pWindow) : SC_CMD_NONE;
230 		else
231 			return pView->Command(rCEvt,pWindow);
232 	}
233 	else
234 		return pView->Command(rCEvt,pWindow);
235 }
236 
237 /*************************************************************************
238 |*
239 |* Cut object to clipboard
240 |*
241 \************************************************************************/
242 
DoCut()243 void FuPoor::DoCut()
244 {
245 	if (pView)
246 	{
247 //!		pView->DoCut(pWindow);
248 	}
249 }
250 
251 /*************************************************************************
252 |*
253 |* Copy object to clipboard
254 |*
255 \************************************************************************/
256 
DoCopy()257 void FuPoor::DoCopy()
258 {
259 	if (pView)
260 	{
261 //!		pView->DoCopy(pWindow);
262 	}
263 }
264 
265 /*************************************************************************
266 |*
267 |* Paste object from clipboard
268 |*
269 \************************************************************************/
270 
DoPaste()271 void FuPoor::DoPaste()
272 {
273 	if (pView)
274 	{
275 //!		pView->DoPaste(pWindow);
276 	}
277 }
278 
279 /*************************************************************************
280 |*
281 |* Timer-Handler fuer Drag&Drop
282 |*
283 \************************************************************************/
284 
IMPL_LINK(FuPoor,DragTimerHdl,Timer *,EMPTYARG)285 IMPL_LINK( FuPoor, DragTimerHdl, Timer *, EMPTYARG )
286 {
287 	//	ExecuteDrag (und das damit verbundene Reschedule) direkt aus dem Timer
288 	//	aufzurufen, bringt die VCL-Timer-Verwaltung durcheinander, wenn dabei
289 	//	(z.B. im Drop) wieder ein Timer gestartet wird (z.B. ComeBack-Timer der
290 	//	DrawView fuer Solid Handles / ModelHasChanged) - der neue Timer laeuft
291 	//	dann um die Dauer des Drag&Drop zu spaet ab.
292 	//	Darum Drag&Drop aus eigenem Event:
293 
294 	Application::PostUserEvent( LINK( this, FuPoor, DragHdl ) );
295 	return 0;
296 }
297 
IMPL_LINK(FuPoor,DragHdl,void *,EMPTYARG)298 IMPL_LINK( FuPoor, DragHdl, void *, EMPTYARG )
299 {
300 	SdrHdl* pHdl = pView->PickHandle(aMDPos);
301 
302 	if ( pHdl==NULL && pView->IsMarkedHit(aMDPos) )
303 	{
304 		pWindow->ReleaseMouse();
305 		bIsInDragMode = sal_True;
306 
307 //		pView->BeginDrag(pWindow, aMDPos);
308 		pViewShell->GetScDrawView()->BeginDrag(pWindow, aMDPos);
309 	}
310 	return 0;
311 }
312 
313 //	Detektiv-Linie
314 
IsDetectiveHit(const Point & rLogicPos)315 sal_Bool FuPoor::IsDetectiveHit( const Point& rLogicPos )
316 {
317 	SdrPageView* pPV = pView->GetSdrPageView();
318 	if (!pPV)
319 		return sal_False;
320 
321 	sal_Bool bFound = sal_False;
322 	SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT );
323 	SdrObject* pObject = aIter.Next();
324 	while (pObject && !bFound)
325 	{
326 		if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
327 		{
328 			sal_uInt16 nHitLog = (sal_uInt16) pWindow->PixelToLogic(
329 								Size(pView->GetHitTolerancePixel(),0)).Width();
330 			if(SdrObjectPrimitiveHit(*pObject, rLogicPos, nHitLog, *pPV, 0, false))
331             {
332 				bFound = sal_True;
333             }
334 		}
335 
336 		pObject = aIter.Next();
337 	}
338 	return bFound;
339 }
340 
StopDragTimer()341 void FuPoor::StopDragTimer()
342 {
343 	if (aDragTimer.IsActive() )
344 		aDragTimer.Stop();
345 }
346 
347 /*************************************************************************
348 |*
349 |* #98185# Create default drawing objects via keyboard
350 |*
351 \************************************************************************/
352 
CreateDefaultObject(const sal_uInt16,const Rectangle &)353 SdrObject* FuPoor::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& /* rRectangle */)
354 {
355 	// empty base implementation
356 	return 0L;
357 }
358 
ImpForceQuadratic(Rectangle & rRect)359 void FuPoor::ImpForceQuadratic(Rectangle& rRect)
360 {
361 	if(rRect.GetWidth() > rRect.GetHeight())
362 	{
363 		rRect = Rectangle(
364 			Point(rRect.Left() + ((rRect.GetWidth() - rRect.GetHeight()) / 2), rRect.Top()),
365 			Size(rRect.GetHeight(), rRect.GetHeight()));
366 	}
367 	else
368 	{
369 		rRect = Rectangle(
370 			Point(rRect.Left(), rRect.Top() + ((rRect.GetHeight() - rRect.GetWidth()) / 2)),
371 			Size(rRect.GetWidth(), rRect.GetWidth()));
372 	}
373 }
374 
375 // #i33136#
doConstructOrthogonal() const376 bool FuPoor::doConstructOrthogonal() const
377 {
378 	return false;
379 }
380 
381 // eof
382