bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuediglu.cxx
blob8d0169eb6ee56a0adf82c30a8c9ab72699356693
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "fuediglu.hxx"
21 #include <svl/eitem.hxx>
22 #include <svx/dialogs.hrc>
23 #include <svx/svdglue.hxx>
24 #include <sfx2/request.hxx>
26 #include "app.hrc"
27 #include "strings.hrc"
28 #include "res_bmp.hrc"
29 #include "Window.hxx"
30 #include "drawdoc.hxx"
31 #include "FrameView.hxx"
32 #include "View.hxx"
33 #include "ViewShell.hxx"
34 #include "ViewShellBase.hxx"
35 #include "ToolBarManager.hxx"
37 namespace sd {
39 TYPEINIT1( FuEditGluePoints, FuDraw );
41 FuEditGluePoints::FuEditGluePoints (
42 ViewShell* pViewSh,
43 ::sd::Window* pWin,
44 ::sd::View* pView,
45 SdDrawDocument* pDoc,
46 SfxRequest& rReq)
47 : FuDraw(pViewSh, pWin, pView, pDoc, rReq)
48 //Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
49 //and SHIFT+ENTER key to decide the position and draw the new insert point
50 ,bBeginInsertPoint(false),
51 oldPoint(0,0)
55 rtl::Reference<FuPoor> FuEditGluePoints::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
57 FuEditGluePoints* pFunc;
58 rtl::Reference<FuPoor> xFunc( pFunc = new FuEditGluePoints( pViewSh, pWin, pView, pDoc, rReq ) );
59 xFunc->DoExecute(rReq);
60 pFunc->SetPermanent( bPermanent );
61 return xFunc;
64 void FuEditGluePoints::DoExecute( SfxRequest& rReq )
66 FuDraw::DoExecute( rReq );
67 mpView->SetInsGluePointMode(false);
68 mpViewShell->GetViewShellBase().GetToolBarManager()->AddToolBar(
69 ToolBarManager::TBG_FUNCTION,
70 ToolBarManager::msGluePointsToolBar);
73 FuEditGluePoints::~FuEditGluePoints()
75 mpView->BrkAction();
76 mpView->UnmarkAllGluePoints();
77 mpView->SetInsGluePointMode(false);
80 bool FuEditGluePoints::MouseButtonDown(const MouseEvent& rMEvt)
82 mpView->SetActualWin( mpWindow );
84 bool bReturn = FuDraw::MouseButtonDown(rMEvt);
86 if (mpView->IsAction())
88 if (rMEvt.IsRight())
89 mpView->BckAction();
91 return true;
94 if (rMEvt.IsLeft())
96 bReturn = true;
97 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
98 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
99 mpWindow->CaptureMouse();
101 SdrViewEvent aVEvt;
102 SdrHitKind eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
104 if (eHit == SDRHIT_HANDLE)
106 // drag handle
107 SdrHdl* pHdl = aVEvt.pHdl;
109 if (mpView->IsGluePointMarked(aVEvt.pObj, aVEvt.nGlueId) && rMEvt.IsShift())
111 mpView->UnmarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
112 pHdl = NULL;
115 if (pHdl)
117 // drag handle
118 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
121 else if (eHit == SDRHIT_MARKEDOBJECT && mpView->IsInsGluePointMode())
123 // insert glue points
124 mpView->BegInsGluePoint(aMDPos);
126 else if (eHit == SDRHIT_MARKEDOBJECT && rMEvt.IsMod1())
128 // select glue points
129 if (!rMEvt.IsShift())
130 mpView->UnmarkAllGluePoints();
132 mpView->BegMarkGluePoints(aMDPos);
134 else if (eHit == SDRHIT_MARKEDOBJECT && !rMEvt.IsShift() && !rMEvt.IsMod2())
136 // move object
137 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, NULL, nDrgLog);
139 else if (eHit == SDRHIT_GLUEPOINT)
141 // select glue points
142 if (!rMEvt.IsShift())
143 mpView->UnmarkAllGluePoints();
145 mpView->MarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
146 SdrHdl* pHdl = mpView->GetGluePointHdl(aVEvt.pObj, aVEvt.nGlueId);
148 if (pHdl)
150 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
153 else
155 // select or drag object
156 if (!rMEvt.IsShift() && !rMEvt.IsMod2() && eHit == SDRHIT_UNMARKEDOBJECT)
158 mpView->UnmarkAllObj();
161 bool bMarked = false;
163 if (!rMEvt.IsMod1())
165 if (rMEvt.IsMod2())
167 bMarked = mpView->MarkNextObj(aMDPos, nHitLog, rMEvt.IsShift());
169 else
171 bMarked = mpView->MarkObj(aMDPos, nHitLog, rMEvt.IsShift());
175 if (bMarked &&
176 (!rMEvt.IsShift() || eHit == SDRHIT_MARKEDOBJECT))
178 // move object
179 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
181 else if (mpView->AreObjectsMarked())
183 // select glue point
184 if (!rMEvt.IsShift())
185 mpView->UnmarkAllGluePoints();
187 mpView->BegMarkGluePoints(aMDPos);
189 else
191 // select object
192 mpView->BegMarkObj(aMDPos);
196 ForcePointer(&rMEvt);
199 return bReturn;
202 bool FuEditGluePoints::MouseMove(const MouseEvent& rMEvt)
204 mpView->SetActualWin( mpWindow );
206 FuDraw::MouseMove(rMEvt);
208 if (mpView->IsAction())
210 Point aPix(rMEvt.GetPosPixel());
211 Point aPnt( mpWindow->PixelToLogic(aPix) );
212 ForceScroll(aPix);
213 mpView->MovAction(aPnt);
216 ForcePointer(&rMEvt);
218 return true;
221 bool FuEditGluePoints::MouseButtonUp(const MouseEvent& rMEvt)
223 mpView->SetActualWin( mpWindow );
225 bool bReturn = false;
227 if (mpView->IsAction())
229 bReturn = true;
230 mpView->EndAction();
233 FuDraw::MouseButtonUp(rMEvt);
235 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
236 Point aPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
238 if (std::abs(aMDPos.X() - aPos.X()) < nDrgLog &&
239 std::abs(aMDPos.Y() - aPos.Y()) < nDrgLog &&
240 !rMEvt.IsShift() && !rMEvt.IsMod2())
242 SdrViewEvent aVEvt;
243 SdrHitKind eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
245 if (eHit == SDRHIT_NONE)
247 // click on position: deselect
248 mpView->UnmarkAllObj();
252 mpWindow->ReleaseMouse();
254 return bReturn;
258 * Process keyboard input
259 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
261 bool FuEditGluePoints::KeyInput(const KeyEvent& rKEvt)
263 mpView->SetActualWin( mpWindow );
265 //Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
266 //and SHIFT+ENTER key to decide the position and draw the new insert point
268 bool bReturn = false;
270 switch (rKEvt.GetKeyCode().GetCode())
272 case KEY_UP:
273 case KEY_DOWN:
274 case KEY_LEFT:
275 case KEY_RIGHT:
277 if(rKEvt.GetKeyCode().IsShift()&& mpView->IsInsGluePointMode() ){
278 long nX = 0;
279 long nY = 0;
280 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
281 if (nCode == KEY_UP)
283 // Scroll nach oben
284 nX = 0;
285 nY =-1;
287 else if (nCode == KEY_DOWN)
289 // Scroll nach unten
290 nX = 0;
291 nY = 1;
293 else if (nCode == KEY_LEFT)
295 // Scroll nach links
296 nX =-1;
297 nY = 0;
299 else if (nCode == KEY_RIGHT)
301 // Scroll nach rechts
302 nX = 1;
303 nY = 0;
305 Point centerPoint;
306 Rectangle rect = mpView->GetMarkedObjRect();
307 centerPoint = mpWindow->LogicToPixel(rect.Center());
308 Point aPoint = bBeginInsertPoint? oldPoint:centerPoint;
309 Point ePoint = aPoint + Point(nX,nY);
310 mpWindow->SetPointerPosPixel(ePoint);
311 //simulate mouse move action
312 MouseEvent eMevt(ePoint, 1, MouseEventModifiers::DRAGMOVE, MOUSE_LEFT, 0);
313 MouseMove(eMevt);
314 oldPoint = ePoint;
315 bBeginInsertPoint = true;
316 bReturn = true;
319 break;
320 case KEY_RETURN:
321 if(rKEvt.GetKeyCode().IsShift() && mpView->IsInsGluePointMode() )
323 if(bBeginInsertPoint)
325 mpWindow->SetPointerPosPixel(oldPoint);
326 //simulate mouse button down action
327 MouseEvent aMevt(oldPoint, 1,
328 MouseEventModifiers::SIMPLEMOVE | MouseEventModifiers::DRAGMOVE,
329 MOUSE_LEFT, KEY_SHIFT);
330 // MT IA2: Not used?
331 // sal_uInt16 ubuttons = aMevt.GetButtons();
332 // sal_uInt16 uMod = aMevt.GetModifier();
333 MouseButtonDown(aMevt);
334 mpWindow->CaptureMouse();
335 //simulate mouse button up action
336 MouseEvent rMEvt(oldPoint+Point(0,0), 1,
337 MouseEventModifiers::SIMPLEMOVE | MouseEventModifiers::ENTERWINDOW,
338 MOUSE_LEFT, KEY_SHIFT);
339 MouseButtonUp(rMEvt);
340 bReturn= true;
343 break;
346 if(!bReturn)
347 bReturn = FuDraw::KeyInput(rKEvt);
349 return bReturn;
352 //Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point, and
353 //SHIFT+ENTER key to decide the position and draw the new insert point
354 void FuEditGluePoints::ForcePointer(const MouseEvent* pMEvt)
356 if(bBeginInsertPoint && pMEvt)
358 MouseEvent aMEvt(pMEvt->GetPosPixel(), pMEvt->GetClicks(),
359 pMEvt->GetMode(), pMEvt->GetButtons(), pMEvt->GetModifier() & ~KEY_SHIFT);
360 FuDraw::ForcePointer(&aMEvt);
362 else
364 FuDraw::ForcePointer(pMEvt);
368 bool FuEditGluePoints::Command(const CommandEvent& rCEvt)
370 mpView->SetActualWin( mpWindow );
371 return FuPoor::Command( rCEvt );
374 void FuEditGluePoints::Activate()
376 mpView->SetGluePointEditMode();
377 FuDraw::Activate();
380 void FuEditGluePoints::Deactivate()
382 mpView->SetGluePointEditMode( false );
383 FuDraw::Deactivate();
386 void FuEditGluePoints::ReceiveRequest(SfxRequest& rReq)
388 switch (rReq.GetSlot())
390 case SID_GLUE_INSERT_POINT:
392 mpView->SetInsGluePointMode(!mpView->IsInsGluePointMode());
394 break;
396 case SID_GLUE_ESCDIR_LEFT:
398 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::LEFT,
399 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::LEFT ) );
401 break;
403 case SID_GLUE_ESCDIR_RIGHT:
405 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT,
406 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT ) );
408 break;
410 case SID_GLUE_ESCDIR_TOP:
412 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::TOP,
413 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::TOP ) );
415 break;
417 case SID_GLUE_ESCDIR_BOTTOM:
419 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM,
420 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM ) );
422 break;
424 case SID_GLUE_PERCENT:
426 const SfxItemSet* pSet = rReq.GetArgs();
427 const SfxPoolItem& rItem = pSet->Get(SID_GLUE_PERCENT);
428 bool bPercent = static_cast<const SfxBoolItem&>(rItem).GetValue();
429 mpView->SetMarkedGluePointsPercent(bPercent);
431 break;
433 case SID_GLUE_HORZALIGN_CENTER:
435 mpView->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_CENTER);
437 break;
439 case SID_GLUE_HORZALIGN_LEFT:
441 mpView->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_LEFT);
443 break;
445 case SID_GLUE_HORZALIGN_RIGHT:
447 mpView->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_RIGHT);
449 break;
451 case SID_GLUE_VERTALIGN_CENTER:
453 mpView->SetMarkedGluePointsAlign(true, SdrAlign::VERT_CENTER);
455 break;
457 case SID_GLUE_VERTALIGN_TOP:
459 mpView->SetMarkedGluePointsAlign(true, SdrAlign::VERT_TOP);
461 break;
463 case SID_GLUE_VERTALIGN_BOTTOM:
465 mpView->SetMarkedGluePointsAlign(true, SdrAlign::VERT_BOTTOM);
467 break;
470 // at the end, call base class
471 FuPoor::ReceiveRequest(rReq);
474 } // end of namespace sd
476 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */