xref: /aoo41x/main/sd/source/ui/func/fuediglu.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_sd.hxx"
30 
31 #include "fuediglu.hxx"
32 #include <svl/eitem.hxx>
33 #include <svx/dialogs.hrc>
34 #include <svx/svdglue.hxx>
35 #include <sfx2/request.hxx>
36 
37 
38 #include "app.hrc"
39 #include "strings.hrc"
40 #include "res_bmp.hrc"
41 #ifndef SD_WINDOW_SHELL_HXX
42 #include "Window.hxx"
43 #endif
44 #include "drawdoc.hxx"
45 #ifndef SD_FRAMW_VIEW_HXX
46 #include "FrameView.hxx"
47 #endif
48 #include "View.hxx"
49 #include "ViewShell.hxx"
50 #include "ViewShellBase.hxx"
51 #include "ToolBarManager.hxx"
52 
53 namespace sd {
54 
55 TYPEINIT1( FuEditGluePoints, FuDraw );
56 
57 /*************************************************************************
58 |*
59 |* Konstruktor
60 |*
61 \************************************************************************/
62 
63 FuEditGluePoints::FuEditGluePoints (
64     ViewShell* pViewSh,
65     ::sd::Window* pWin,
66     ::sd::View* pView,
67     SdDrawDocument*	pDoc,
68     SfxRequest& rReq)
69     : FuDraw(pViewSh, pWin, pView, pDoc, rReq)
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 	sal_Bool bReturn = FuDraw::KeyInput(rKEvt);
329 
330 	return bReturn;
331 }
332 
333 /*************************************************************************
334 |*
335 |* Command-event
336 |*
337 \************************************************************************/
338 
339 sal_Bool FuEditGluePoints::Command(const CommandEvent& rCEvt)
340 {
341 	mpView->SetActualWin( mpWindow );
342 	return FuPoor::Command( rCEvt );
343 }
344 
345 /*************************************************************************
346 |*
347 |* Funktion aktivieren
348 |*
349 \************************************************************************/
350 
351 void FuEditGluePoints::Activate()
352 {
353 	mpView->SetGluePointEditMode();
354 	FuDraw::Activate();
355 }
356 
357 /*************************************************************************
358 |*
359 |* Funktion deaktivieren
360 |*
361 \************************************************************************/
362 
363 void FuEditGluePoints::Deactivate()
364 {
365 	mpView->SetGluePointEditMode( sal_False );
366 	FuDraw::Deactivate();
367 }
368 
369 /*************************************************************************
370 |*
371 |* Request verarbeiten
372 |*
373 \************************************************************************/
374 
375 void FuEditGluePoints::ReceiveRequest(SfxRequest& rReq)
376 {
377 	switch (rReq.GetSlot())
378 	{
379 		case SID_GLUE_INSERT_POINT:
380 		{
381 			mpView->SetInsGluePointMode(!mpView->IsInsGluePointMode());
382 		}
383 		break;
384 
385 		case SID_GLUE_ESCDIR_LEFT:
386 		{
387 			mpView->SetMarkedGluePointsEscDir( SDRESC_LEFT,
388 					!mpView->IsMarkedGluePointsEscDir( SDRESC_LEFT ) );
389 		}
390 		break;
391 
392 		case SID_GLUE_ESCDIR_RIGHT:
393 		{
394 			mpView->SetMarkedGluePointsEscDir( SDRESC_RIGHT,
395 					!mpView->IsMarkedGluePointsEscDir( SDRESC_RIGHT ) );
396 		}
397 		break;
398 
399 		case SID_GLUE_ESCDIR_TOP:
400 		{
401 			mpView->SetMarkedGluePointsEscDir( SDRESC_TOP,
402 					!mpView->IsMarkedGluePointsEscDir( SDRESC_TOP ) );
403 		}
404 		break;
405 
406 		case SID_GLUE_ESCDIR_BOTTOM:
407 		{
408 			mpView->SetMarkedGluePointsEscDir( SDRESC_BOTTOM,
409 					!mpView->IsMarkedGluePointsEscDir( SDRESC_BOTTOM ) );
410 		}
411 		break;
412 
413 		case SID_GLUE_PERCENT:
414 		{
415 			const SfxItemSet* pSet = rReq.GetArgs();
416 			const SfxPoolItem& rItem = pSet->Get(SID_GLUE_PERCENT);
417 			sal_Bool bPercent = ((const SfxBoolItem&) rItem).GetValue();
418 			mpView->SetMarkedGluePointsPercent(bPercent);
419 		}
420 		break;
421 
422 		case SID_GLUE_HORZALIGN_CENTER:
423 		{
424 			mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_CENTER);
425 		}
426 		break;
427 
428 		case SID_GLUE_HORZALIGN_LEFT:
429 		{
430 			mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_LEFT);
431 		}
432 		break;
433 
434 		case SID_GLUE_HORZALIGN_RIGHT:
435 		{
436 			mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_RIGHT);
437 		}
438 		break;
439 
440 		case SID_GLUE_VERTALIGN_CENTER:
441 		{
442 			mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_CENTER);
443 		}
444 		break;
445 
446 		case SID_GLUE_VERTALIGN_TOP:
447 		{
448 			mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_TOP);
449 		}
450 		break;
451 
452 		case SID_GLUE_VERTALIGN_BOTTOM:
453 		{
454 			mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_BOTTOM);
455 		}
456 		break;
457 	}
458 
459 	// Zum Schluss Basisklasse rufen
460 	FuPoor::ReceiveRequest(rReq);
461 }
462 
463 
464 } // end of namespace sd
465