xref: /trunk/main/sd/source/ui/func/fuediglu.cxx (revision 4d7c9de0)
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_sd.hxx"
26 
27 #include "fuediglu.hxx"
28 #include <svl/eitem.hxx>
29 #include <svx/dialogs.hrc>
30 #include <svx/svdglue.hxx>
31 #include <sfx2/request.hxx>
32 
33 
34 #include "app.hrc"
35 #include "strings.hrc"
36 #include "res_bmp.hrc"
37 #ifndef SD_WINDOW_SHELL_HXX
38 #include "Window.hxx"
39 #endif
40 #include "drawdoc.hxx"
41 #ifndef SD_FRAMW_VIEW_HXX
42 #include "FrameView.hxx"
43 #endif
44 #include "View.hxx"
45 #include "ViewShell.hxx"
46 #include "ViewShellBase.hxx"
47 #include "ToolBarManager.hxx"
48 
49 namespace sd {
50 
51 TYPEINIT1( FuEditGluePoints, FuDraw );
52 
53 /*************************************************************************
54 |*
55 |* Konstruktor
56 |*
57 \************************************************************************/
58 
59 FuEditGluePoints::FuEditGluePoints (
60     ViewShell* pViewSh,
61     ::sd::Window* pWin,
62     ::sd::View* pView,
63     SdDrawDocument*	pDoc,
64     SfxRequest& rReq)
65     : FuDraw(pViewSh, pWin, pView, pDoc, rReq)
66 	 //Solution: Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
67 	 //and SHIFT+ENTER key to decide the postion and draw the new insert point
68 	 ,bBeginInsertPoint(sal_False),
69 	oldPoint(0,0)
70 {
71 }
72 
73 FunctionReference FuEditGluePoints::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
74 {
75 	FuEditGluePoints* pFunc;
76 	FunctionReference xFunc( pFunc = new FuEditGluePoints( pViewSh, pWin, pView, pDoc, rReq ) );
77 	xFunc->DoExecute(rReq);
78 	pFunc->SetPermanent( bPermanent );
79 	return xFunc;
80 }
81 
82 void FuEditGluePoints::DoExecute( SfxRequest& rReq )
83 {
84 	FuDraw::DoExecute( rReq );
85 	mpView->SetInsGluePointMode(sal_False);
86     mpViewShell->GetViewShellBase().GetToolBarManager()->AddToolBar(
87         ToolBarManager::TBG_FUNCTION,
88         ToolBarManager::msGluePointsToolBar);
89 }
90 
91 /*************************************************************************
92 |*
93 |* Destruktor
94 |*
95 \************************************************************************/
96 
97 FuEditGluePoints::~FuEditGluePoints()
98 {
99 	mpView->BrkAction();
100 	mpView->UnmarkAllGluePoints();
101 	mpView->SetInsGluePointMode(sal_False);
102 }
103 
104 /*************************************************************************
105 |*
106 |* MouseButtonDown-event
107 |*
108 \************************************************************************/
109 
110 sal_Bool FuEditGluePoints::MouseButtonDown(const MouseEvent& rMEvt)
111 {
112 	mpView->SetActualWin( mpWindow );
113 
114 	sal_Bool bReturn = FuDraw::MouseButtonDown(rMEvt);
115 
116 	if (mpView->IsAction())
117 	{
118 		if (rMEvt.IsRight())
119 			mpView->BckAction();
120 
121 		return sal_True;
122 	}
123 
124 	if (rMEvt.IsLeft())
125 	{
126 		bReturn = sal_True;
127 		sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
128 		sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
129 		mpWindow->CaptureMouse();
130 
131 		SdrViewEvent aVEvt;
132 		SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
133 
134 		if (eHit == SDRHIT_HANDLE)
135 		{
136 			/******************************************************************
137 			* Handle draggen
138 			******************************************************************/
139 			SdrHdl* pHdl = aVEvt.pHdl;
140 
141 			if (mpView->IsGluePointMarked(aVEvt.pObj, aVEvt.nGlueId) && rMEvt.IsShift())
142 			{
143 				mpView->UnmarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
144 				pHdl = NULL;
145 			}
146 
147 			if (pHdl)
148 			{
149 				// Handle draggen
150 				mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
151 			}
152 		}
153 		else if (eHit == SDRHIT_MARKEDOBJECT && mpView->IsInsGluePointMode())
154 		{
155 			/******************************************************************
156 			* Klebepunkt einfuegen
157 			******************************************************************/
158 			mpView->BegInsGluePoint(aMDPos);
159 		}
160 		else if (eHit == SDRHIT_MARKEDOBJECT && rMEvt.IsMod1())
161 		{
162 			/******************************************************************
163 			* Klebepunkt selektieren
164 			******************************************************************/
165 			if (!rMEvt.IsShift())
166 				mpView->UnmarkAllGluePoints();
167 
168 			mpView->BegMarkGluePoints(aMDPos);
169 		}
170 		else if (eHit == SDRHIT_MARKEDOBJECT && !rMEvt.IsShift() && !rMEvt.IsMod2())
171 		{
172 			/******************************************************************
173 			* Objekt verschieben
174 			******************************************************************/
175 			mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, NULL, nDrgLog);
176 		}
177 		else if (eHit == SDRHIT_GLUEPOINT)
178 		{
179 			/******************************************************************
180 			* Klebepunkt selektieren
181 			******************************************************************/
182 			if (!rMEvt.IsShift())
183 				mpView->UnmarkAllGluePoints();
184 
185 			mpView->MarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
186 			SdrHdl* pHdl = mpView->GetGluePointHdl(aVEvt.pObj, aVEvt.nGlueId);
187 
188 			if (pHdl)
189 			{
190 				mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
191 			}
192 		}
193 		else
194 		{
195 			/******************************************************************
196 			* Objekt selektieren oder draggen
197 			******************************************************************/
198 			if (!rMEvt.IsShift() && !rMEvt.IsMod2() && eHit == SDRHIT_UNMARKEDOBJECT)
199 			{
200 			   mpView->UnmarkAllObj();
201 			}
202 
203 			sal_Bool bMarked = sal_False;
204 
205 			if (!rMEvt.IsMod1())
206 			{
207 				if (rMEvt.IsMod2())
208 				{
209 					bMarked = mpView->MarkNextObj(aMDPos, nHitLog, rMEvt.IsShift());
210 				}
211 				else
212 				{
213 					bMarked = mpView->MarkObj(aMDPos, nHitLog, rMEvt.IsShift());
214 				}
215 			}
216 
217 			if (bMarked &&
218 				(!rMEvt.IsShift() || eHit == SDRHIT_MARKEDOBJECT))
219 			{
220 				// Objekt verschieben
221 				mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
222 			}
223 			else if (mpView->AreObjectsMarked())
224 			{
225 				/**************************************************************
226 				* Klebepunkt selektieren
227 				**************************************************************/
228 				if (!rMEvt.IsShift())
229 					mpView->UnmarkAllGluePoints();
230 
231 				mpView->BegMarkGluePoints(aMDPos);
232 			}
233 			else
234 			{
235 				/**************************************************************
236 				* Objekt selektieren
237 				**************************************************************/
238 				mpView->BegMarkObj(aMDPos);
239 			}
240 		}
241 
242 		ForcePointer(&rMEvt);
243 	}
244 
245 	return bReturn;
246 }
247 
248 /*************************************************************************
249 |*
250 |* MouseMove-event
251 |*
252 \************************************************************************/
253 
254 sal_Bool FuEditGluePoints::MouseMove(const MouseEvent& rMEvt)
255 {
256 	mpView->SetActualWin( mpWindow );
257 
258 	FuDraw::MouseMove(rMEvt);
259 
260 	if (mpView->IsAction())
261 	{
262 		Point aPix(rMEvt.GetPosPixel());
263 		Point aPnt( mpWindow->PixelToLogic(aPix) );
264 		ForceScroll(aPix);
265 		mpView->MovAction(aPnt);
266 	}
267 
268 	ForcePointer(&rMEvt);
269 
270 	return sal_True;
271 }
272 
273 /*************************************************************************
274 |*
275 |* MouseButtonUp-event
276 |*
277 \************************************************************************/
278 
279 sal_Bool FuEditGluePoints::MouseButtonUp(const MouseEvent& rMEvt)
280 {
281 	mpView->SetActualWin( mpWindow );
282 
283 	sal_Bool bReturn = sal_False;
284 
285 	if (mpView->IsAction())
286 	{
287 		bReturn = sal_True;
288 		mpView->EndAction();
289 	}
290 
291 	FuDraw::MouseButtonUp(rMEvt);
292 
293 	sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
294 	Point aPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
295 
296 	if (Abs(aMDPos.X() - aPos.X()) < nDrgLog &&
297 		Abs(aMDPos.Y() - aPos.Y()) < nDrgLog &&
298 		!rMEvt.IsShift() && !rMEvt.IsMod2())
299 	{
300 		SdrViewEvent aVEvt;
301 		SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
302 
303 		if (eHit == SDRHIT_NONE)
304 		{
305 			// Klick auf der Stelle: deselektieren
306 			mpView->UnmarkAllObj();
307 		}
308 	}
309 
310 	mpWindow->ReleaseMouse();
311 
312 	return bReturn;
313 }
314 
315 /*************************************************************************
316 |*
317 |* Tastaturereignisse bearbeiten
318 |*
319 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
320 |* sal_False.
321 |*
322 \************************************************************************/
323 
324 sal_Bool FuEditGluePoints::KeyInput(const KeyEvent& rKEvt)
325 {
326 	mpView->SetActualWin( mpWindow );
327 
328 	//Solution: Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
329 	//and SHIFT+ENTER key to decide the postion and draw the new insert point
330 	//sal_Bool bReturn = FuDraw::KeyInput(rKEvt);
331 
332 	sal_Bool bReturn = sal_False;
333 
334 	switch (rKEvt.GetKeyCode().GetCode())
335 	{
336 		case KEY_UP:
337 		case KEY_DOWN:
338 		case KEY_LEFT:
339 		case KEY_RIGHT:
340 		{
341 			if(rKEvt.GetKeyCode().IsShift()&& mpView->IsInsGluePointMode() ){
342 				long nX = 0;
343 				long nY = 0;
344 				sal_uInt16  nCode = rKEvt.GetKeyCode().GetCode();
345 				if (nCode == KEY_UP)
346 				{
347 					// Scroll nach oben
348 					nX = 0;
349 					nY =-1;
350 				}
351 				else if (nCode == KEY_DOWN)
352 				{
353 					// Scroll nach unten
354 					nX = 0;
355 					nY = 1;
356 				}
357 				else if (nCode == KEY_LEFT)
358 				{
359 					// Scroll nach links
360 					nX =-1;
361 					nY = 0;
362 				}
363 				else if (nCode == KEY_RIGHT)
364 				{
365 					// Scroll nach rechts
366 					nX = 1;
367 					nY = 0;
368 				}
369 				Point centerPoint;
370 				Rectangle rect = mpView->GetMarkedObjRect();
371 				centerPoint = mpWindow->LogicToPixel(rect.Center());
372 				Point aPoint = bBeginInsertPoint? oldPoint:centerPoint;
373 				Point ePoint = aPoint + Point(nX,nY);
374 				mpWindow->SetPointerPosPixel(ePoint);
375 				//simulate mouse move action
376 				MouseEvent eMevt(ePoint,1,2,MOUSE_LEFT, 0);
377 				MouseMove(eMevt);
378 	                     Point aPix(eMevt.GetPosPixel());
379 				oldPoint = ePoint;
380 				bBeginInsertPoint = sal_True;
381 				bReturn = sal_True;
382 			}
383 		}
384 		break;
385 		case KEY_RETURN:
386 			if(rKEvt.GetKeyCode().IsShift() && mpView->IsInsGluePointMode() )
387 			{
388 				if(bBeginInsertPoint)
389 				{
390 					mpWindow->SetPointerPosPixel(oldPoint);
391 					//simulate mouse button down action
392 					MouseEvent aMevt(oldPoint,1,3,MOUSE_LEFT,KEY_SHIFT);
393 					// MT IA2: Not used?
394 					// sal_uInt16 ubuttons = aMevt.GetButtons();
395 					// sal_uInt16 uMod		= aMevt.GetModifier();
396 					MouseButtonDown(aMevt);
397 					mpWindow->CaptureMouse();
398 					//simulate mouse button up action
399 					MouseEvent rMEvt(oldPoint+Point(0,0),1,17, MOUSE_LEFT, KEY_SHIFT);
400 					MouseButtonUp(rMEvt);
401 					bReturn= sal_True;
402 				}
403 			}
404 			break;
405 	}
406 	if(!bReturn)
407 		bReturn = FuDraw::KeyInput(rKEvt);
408 	return bReturn;
409 }
410 
411  //Solution: Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
412  //and SHIFT+ENTER key to decide the postion and draw the new insert point
413 void FuEditGluePoints::ForcePointer(const MouseEvent* pMEvt)
414 {
415 	if(bBeginInsertPoint && pMEvt)
416 	{
417 		MouseEvent aMEvt(pMEvt->GetPosPixel(), pMEvt->GetClicks(),
418 			pMEvt->GetMode(), pMEvt->GetButtons(), pMEvt->GetModifier() & ~KEY_SHIFT);
419 		FuDraw::ForcePointer(&aMEvt);
420 	}
421 	else
422 	{
423 		FuDraw::ForcePointer(pMEvt);
424 	}
425 }
426 /*************************************************************************
427 |*
428 |* Command-event
429 |*
430 \************************************************************************/
431 
432 sal_Bool FuEditGluePoints::Command(const CommandEvent& rCEvt)
433 {
434 	mpView->SetActualWin( mpWindow );
435 	return FuPoor::Command( rCEvt );
436 }
437 
438 /*************************************************************************
439 |*
440 |* Funktion aktivieren
441 |*
442 \************************************************************************/
443 
444 void FuEditGluePoints::Activate()
445 {
446 	mpView->SetGluePointEditMode();
447 	FuDraw::Activate();
448 }
449 
450 /*************************************************************************
451 |*
452 |* Funktion deaktivieren
453 |*
454 \************************************************************************/
455 
456 void FuEditGluePoints::Deactivate()
457 {
458 	mpView->SetGluePointEditMode( sal_False );
459 	FuDraw::Deactivate();
460 }
461 
462 /*************************************************************************
463 |*
464 |* Request verarbeiten
465 |*
466 \************************************************************************/
467 
468 void FuEditGluePoints::ReceiveRequest(SfxRequest& rReq)
469 {
470 	switch (rReq.GetSlot())
471 	{
472 		case SID_GLUE_INSERT_POINT:
473 		{
474 			mpView->SetInsGluePointMode(!mpView->IsInsGluePointMode());
475 		}
476 		break;
477 
478 		case SID_GLUE_ESCDIR_LEFT:
479 		{
480 			mpView->SetMarkedGluePointsEscDir( SDRESC_LEFT,
481 					!mpView->IsMarkedGluePointsEscDir( SDRESC_LEFT ) );
482 		}
483 		break;
484 
485 		case SID_GLUE_ESCDIR_RIGHT:
486 		{
487 			mpView->SetMarkedGluePointsEscDir( SDRESC_RIGHT,
488 					!mpView->IsMarkedGluePointsEscDir( SDRESC_RIGHT ) );
489 		}
490 		break;
491 
492 		case SID_GLUE_ESCDIR_TOP:
493 		{
494 			mpView->SetMarkedGluePointsEscDir( SDRESC_TOP,
495 					!mpView->IsMarkedGluePointsEscDir( SDRESC_TOP ) );
496 		}
497 		break;
498 
499 		case SID_GLUE_ESCDIR_BOTTOM:
500 		{
501 			mpView->SetMarkedGluePointsEscDir( SDRESC_BOTTOM,
502 					!mpView->IsMarkedGluePointsEscDir( SDRESC_BOTTOM ) );
503 		}
504 		break;
505 
506 		case SID_GLUE_PERCENT:
507 		{
508 			const SfxItemSet* pSet = rReq.GetArgs();
509 			const SfxPoolItem& rItem = pSet->Get(SID_GLUE_PERCENT);
510 			sal_Bool bPercent = ((const SfxBoolItem&) rItem).GetValue();
511 			mpView->SetMarkedGluePointsPercent(bPercent);
512 		}
513 		break;
514 
515 		case SID_GLUE_HORZALIGN_CENTER:
516 		{
517 			mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_CENTER);
518 		}
519 		break;
520 
521 		case SID_GLUE_HORZALIGN_LEFT:
522 		{
523 			mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_LEFT);
524 		}
525 		break;
526 
527 		case SID_GLUE_HORZALIGN_RIGHT:
528 		{
529 			mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_RIGHT);
530 		}
531 		break;
532 
533 		case SID_GLUE_VERTALIGN_CENTER:
534 		{
535 			mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_CENTER);
536 		}
537 		break;
538 
539 		case SID_GLUE_VERTALIGN_TOP:
540 		{
541 			mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_TOP);
542 		}
543 		break;
544 
545 		case SID_GLUE_VERTALIGN_BOTTOM:
546 		{
547 			mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_BOTTOM);
548 		}
549 		break;
550 	}
551 
552 	// Zum Schluss Basisklasse rufen
553 	FuPoor::ReceiveRequest(rReq);
554 }
555 
556 
557 } // end of namespace sd
558