xref: /aoo4110/main/sd/source/ui/func/fuediglu.cxx (revision b1cdbd2c)
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 
FuEditGluePoints(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)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 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq,bool bPermanent)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 
DoExecute(SfxRequest & rReq)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 
~FuEditGluePoints()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 
MouseButtonDown(const MouseEvent & rMEvt)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 
MouseMove(const MouseEvent & rMEvt)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 
MouseButtonUp(const MouseEvent & rMEvt)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 
KeyInput(const KeyEvent & rKEvt)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 
331 	sal_Bool bReturn = sal_False;
332 
333 	switch (rKEvt.GetKeyCode().GetCode())
334 	{
335 		case KEY_UP:
336 		case KEY_DOWN:
337 		case KEY_LEFT:
338 		case KEY_RIGHT:
339 		{
340 			if(rKEvt.GetKeyCode().IsShift()&& mpView->IsInsGluePointMode() ){
341 				long nX = 0;
342 				long nY = 0;
343 				sal_uInt16  nCode = rKEvt.GetKeyCode().GetCode();
344 				if (nCode == KEY_UP)
345 				{
346 					// Scroll nach oben
347 					nX = 0;
348 					nY =-1;
349 				}
350 				else if (nCode == KEY_DOWN)
351 				{
352 					// Scroll nach unten
353 					nX = 0;
354 					nY = 1;
355 				}
356 				else if (nCode == KEY_LEFT)
357 				{
358 					// Scroll nach links
359 					nX =-1;
360 					nY = 0;
361 				}
362 				else if (nCode == KEY_RIGHT)
363 				{
364 					// Scroll nach rechts
365 					nX = 1;
366 					nY = 0;
367 				}
368 				Point centerPoint;
369 				Rectangle rect = mpView->GetMarkedObjRect();
370 				centerPoint = mpWindow->LogicToPixel(rect.Center());
371 				Point aPoint = bBeginInsertPoint? oldPoint:centerPoint;
372 				Point ePoint = aPoint + Point(nX,nY);
373 				mpWindow->SetPointerPosPixel(ePoint);
374 				//simulate mouse move action
375 				MouseEvent eMevt(ePoint,1,2,MOUSE_LEFT, 0);
376 				MouseMove(eMevt);
377 	                     Point aPix(eMevt.GetPosPixel());
378 				oldPoint = ePoint;
379 				bBeginInsertPoint = sal_True;
380 				bReturn = sal_True;
381 			}
382 		}
383 		break;
384 		case KEY_RETURN:
385 			if(rKEvt.GetKeyCode().IsShift() && mpView->IsInsGluePointMode() )
386 			{
387 				if(bBeginInsertPoint)
388 				{
389 					mpWindow->SetPointerPosPixel(oldPoint);
390 					//simulate mouse button down action
391 					MouseEvent aMevt(oldPoint,1,3,MOUSE_LEFT,KEY_SHIFT);
392 					// MT IA2: Not used?
393 					// sal_uInt16 ubuttons = aMevt.GetButtons();
394 					// sal_uInt16 uMod		= aMevt.GetModifier();
395 					MouseButtonDown(aMevt);
396 					mpWindow->CaptureMouse();
397 					//simulate mouse button up action
398 					MouseEvent rMEvt(oldPoint+Point(0,0),1,17, MOUSE_LEFT, KEY_SHIFT);
399 					MouseButtonUp(rMEvt);
400 					bReturn= sal_True;
401 				}
402 			}
403 			break;
404 	}
405 	if(!bReturn)
406 		bReturn = FuDraw::KeyInput(rKEvt);
407 	return bReturn;
408 }
409 
410  //Solution: Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
411  //and SHIFT+ENTER key to decide the postion and draw the new insert point
ForcePointer(const MouseEvent * pMEvt)412 void FuEditGluePoints::ForcePointer(const MouseEvent* pMEvt)
413 {
414 	if(bBeginInsertPoint && pMEvt)
415 	{
416 		MouseEvent aMEvt(pMEvt->GetPosPixel(), pMEvt->GetClicks(),
417 			pMEvt->GetMode(), pMEvt->GetButtons(), pMEvt->GetModifier() & ~KEY_SHIFT);
418 		FuDraw::ForcePointer(&aMEvt);
419 	}
420 	else
421 	{
422 		FuDraw::ForcePointer(pMEvt);
423 	}
424 }
425 /*************************************************************************
426 |*
427 |* Command-event
428 |*
429 \************************************************************************/
430 
Command(const CommandEvent & rCEvt)431 sal_Bool FuEditGluePoints::Command(const CommandEvent& rCEvt)
432 {
433 	mpView->SetActualWin( mpWindow );
434 	return FuPoor::Command( rCEvt );
435 }
436 
437 /*************************************************************************
438 |*
439 |* Funktion aktivieren
440 |*
441 \************************************************************************/
442 
Activate()443 void FuEditGluePoints::Activate()
444 {
445 	mpView->SetGluePointEditMode();
446 	FuDraw::Activate();
447 }
448 
449 /*************************************************************************
450 |*
451 |* Funktion deaktivieren
452 |*
453 \************************************************************************/
454 
Deactivate()455 void FuEditGluePoints::Deactivate()
456 {
457 	mpView->SetGluePointEditMode( sal_False );
458 	FuDraw::Deactivate();
459 }
460 
461 /*************************************************************************
462 |*
463 |* Request verarbeiten
464 |*
465 \************************************************************************/
466 
ReceiveRequest(SfxRequest & rReq)467 void FuEditGluePoints::ReceiveRequest(SfxRequest& rReq)
468 {
469 	switch (rReq.GetSlot())
470 	{
471 		case SID_GLUE_INSERT_POINT:
472 		{
473 			mpView->SetInsGluePointMode(!mpView->IsInsGluePointMode());
474 		}
475 		break;
476 
477 		case SID_GLUE_ESCDIR_LEFT:
478 		{
479 			mpView->SetMarkedGluePointsEscDir( SDRESC_LEFT,
480 					!mpView->IsMarkedGluePointsEscDir( SDRESC_LEFT ) );
481 		}
482 		break;
483 
484 		case SID_GLUE_ESCDIR_RIGHT:
485 		{
486 			mpView->SetMarkedGluePointsEscDir( SDRESC_RIGHT,
487 					!mpView->IsMarkedGluePointsEscDir( SDRESC_RIGHT ) );
488 		}
489 		break;
490 
491 		case SID_GLUE_ESCDIR_TOP:
492 		{
493 			mpView->SetMarkedGluePointsEscDir( SDRESC_TOP,
494 					!mpView->IsMarkedGluePointsEscDir( SDRESC_TOP ) );
495 		}
496 		break;
497 
498 		case SID_GLUE_ESCDIR_BOTTOM:
499 		{
500 			mpView->SetMarkedGluePointsEscDir( SDRESC_BOTTOM,
501 					!mpView->IsMarkedGluePointsEscDir( SDRESC_BOTTOM ) );
502 		}
503 		break;
504 
505 		case SID_GLUE_PERCENT:
506 		{
507 			const SfxItemSet* pSet = rReq.GetArgs();
508 			const SfxPoolItem& rItem = pSet->Get(SID_GLUE_PERCENT);
509 			sal_Bool bPercent = ((const SfxBoolItem&) rItem).GetValue();
510 			mpView->SetMarkedGluePointsPercent(bPercent);
511 		}
512 		break;
513 
514 		case SID_GLUE_HORZALIGN_CENTER:
515 		{
516 			mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_CENTER);
517 		}
518 		break;
519 
520 		case SID_GLUE_HORZALIGN_LEFT:
521 		{
522 			mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_LEFT);
523 		}
524 		break;
525 
526 		case SID_GLUE_HORZALIGN_RIGHT:
527 		{
528 			mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_RIGHT);
529 		}
530 		break;
531 
532 		case SID_GLUE_VERTALIGN_CENTER:
533 		{
534 			mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_CENTER);
535 		}
536 		break;
537 
538 		case SID_GLUE_VERTALIGN_TOP:
539 		{
540 			mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_TOP);
541 		}
542 		break;
543 
544 		case SID_GLUE_VERTALIGN_BOTTOM:
545 		{
546 			mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_BOTTOM);
547 		}
548 		break;
549 	}
550 
551 	// Zum Schluss Basisklasse rufen
552 	FuPoor::ReceiveRequest(rReq);
553 }
554 
555 
556 } // end of namespace sd
557