Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fuediglu.cxx
blob8317c7a817e15dd1a25a90bfc19871d53c8b262e
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>
28 #include <Window.hxx>
29 #include <drawdoc.hxx>
30 #include <FrameView.hxx>
31 #include <View.hxx>
32 #include <ViewShell.hxx>
33 #include <ViewShellBase.hxx>
34 #include <ToolBarManager.hxx>
36 namespace sd {
39 FuEditGluePoints::FuEditGluePoints (
40 ViewShell* pViewSh,
41 ::sd::Window* pWin,
42 ::sd::View* pView,
43 SdDrawDocument* pDoc,
44 SfxRequest& rReq)
45 : FuDraw(pViewSh, pWin, pView, pDoc, rReq)
46 //Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
47 //and SHIFT+ENTER key to decide the position and draw the new insert point
48 ,bBeginInsertPoint(false),
49 oldPoint(0,0)
53 rtl::Reference<FuPoor> FuEditGluePoints::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
55 FuEditGluePoints* pFunc;
56 rtl::Reference<FuPoor> xFunc( pFunc = new FuEditGluePoints( pViewSh, pWin, pView, pDoc, rReq ) );
57 xFunc->DoExecute(rReq);
58 pFunc->SetPermanent( bPermanent );
59 return xFunc;
62 void FuEditGluePoints::DoExecute( SfxRequest& rReq )
64 FuDraw::DoExecute( rReq );
65 mpView->SetInsGluePointMode(false);
66 mpViewShell->GetViewShellBase().GetToolBarManager()->AddToolBar(
67 ToolBarManager::ToolBarGroup::Function,
68 ToolBarManager::msGluePointsToolBar);
71 FuEditGluePoints::~FuEditGluePoints()
73 mpView->BrkAction();
74 mpView->UnmarkAllGluePoints();
75 mpView->SetInsGluePointMode(false);
78 bool FuEditGluePoints::MouseButtonDown(const MouseEvent& rMEvt)
80 mpView->SetActualWin( mpWindow );
82 bool bReturn = FuDraw::MouseButtonDown(rMEvt);
84 if (mpView->IsAction())
86 if (rMEvt.IsRight())
87 mpView->BckAction();
89 return true;
92 if (rMEvt.IsLeft())
94 bReturn = true;
95 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
96 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
97 mpWindow->CaptureMouse();
99 SdrViewEvent aVEvt;
100 SdrHitKind eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
102 if (eHit == SdrHitKind::Handle)
104 // drag handle
105 SdrHdl* pHdl = aVEvt.pHdl;
107 if (mpView->IsGluePointMarked(aVEvt.pObj, aVEvt.nGlueId) && rMEvt.IsShift())
109 mpView->UnmarkGluePoint(aVEvt.pObj, aVEvt.nGlueId);
110 pHdl = nullptr;
113 if (pHdl)
115 // drag handle
116 mpView->BegDragObj(aMDPos, nullptr, aVEvt.pHdl, nDrgLog);
119 else if (eHit == SdrHitKind::MarkedObject && mpView->IsInsGluePointMode())
121 // insert glue points
122 mpView->BegInsGluePoint(aMDPos);
124 else if (eHit == SdrHitKind::MarkedObject && rMEvt.IsMod1())
126 // select glue points
127 if (!rMEvt.IsShift())
128 mpView->UnmarkAllGluePoints();
130 mpView->BegMarkGluePoints(aMDPos);
132 else if (eHit == SdrHitKind::MarkedObject && !rMEvt.IsShift() && !rMEvt.IsMod2())
134 // move object
135 mpView->BegDragObj(aMDPos, nullptr, nullptr, nDrgLog);
137 else if (eHit == SdrHitKind::Gluepoint)
139 // select glue points
140 if (!rMEvt.IsShift())
141 mpView->UnmarkAllGluePoints();
143 mpView->MarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, false);
144 SdrHdl* pHdl = mpView->GetGluePointHdl(aVEvt.pObj, aVEvt.nGlueId);
146 if (pHdl)
148 mpView->BegDragObj(aMDPos, nullptr, pHdl, nDrgLog);
151 else
153 // select or drag object
154 if (!rMEvt.IsShift() && !rMEvt.IsMod2() && eHit == SdrHitKind::UnmarkedObject)
156 mpView->UnmarkAllObj();
159 bool bMarked = false;
161 if (!rMEvt.IsMod1())
163 if (rMEvt.IsMod2())
165 bMarked = mpView->MarkNextObj(aMDPos, nHitLog, rMEvt.IsShift());
167 else
169 bMarked = mpView->MarkObj(aMDPos, nHitLog, rMEvt.IsShift());
173 if (bMarked &&
174 (!rMEvt.IsShift() || eHit == SdrHitKind::MarkedObject))
176 // move object
177 mpView->BegDragObj(aMDPos, nullptr, aVEvt.pHdl, nDrgLog);
179 else if (mpView->AreObjectsMarked())
181 // select glue point
182 if (!rMEvt.IsShift())
183 mpView->UnmarkAllGluePoints();
185 mpView->BegMarkGluePoints(aMDPos);
187 else
189 // select object
190 mpView->BegMarkObj(aMDPos);
194 ForcePointer(&rMEvt);
197 return bReturn;
200 bool FuEditGluePoints::MouseMove(const MouseEvent& rMEvt)
202 mpView->SetActualWin( mpWindow );
204 FuDraw::MouseMove(rMEvt);
206 if (mpView->IsAction())
208 Point aPix(rMEvt.GetPosPixel());
209 Point aPnt( mpWindow->PixelToLogic(aPix) );
210 ForceScroll(aPix);
211 mpView->MovAction(aPnt);
214 ForcePointer(&rMEvt);
216 return true;
219 bool FuEditGluePoints::MouseButtonUp(const MouseEvent& rMEvt)
221 mpView->SetActualWin( mpWindow );
223 bool bReturn = false;
225 if (mpView->IsAction())
227 bReturn = true;
228 mpView->EndAction();
231 FuDraw::MouseButtonUp(rMEvt);
233 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
234 Point aPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
236 if (std::abs(aMDPos.X() - aPos.X()) < nDrgLog &&
237 std::abs(aMDPos.Y() - aPos.Y()) < nDrgLog &&
238 !rMEvt.IsShift() && !rMEvt.IsMod2())
240 SdrViewEvent aVEvt;
241 SdrHitKind eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
243 if (eHit == SdrHitKind::NONE)
245 // click on position: deselect
246 mpView->UnmarkAllObj();
250 mpWindow->ReleaseMouse();
252 return bReturn;
256 * Process keyboard input
257 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
259 bool FuEditGluePoints::KeyInput(const KeyEvent& rKEvt)
261 mpView->SetActualWin( mpWindow );
263 //Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
264 //and SHIFT+ENTER key to decide the position and draw the new insert point
266 bool bReturn = false;
268 switch (rKEvt.GetKeyCode().GetCode())
270 case KEY_UP:
271 case KEY_DOWN:
272 case KEY_LEFT:
273 case KEY_RIGHT:
275 if(rKEvt.GetKeyCode().IsShift()&& mpView->IsInsGluePointMode() ){
276 long nX = 0;
277 long nY = 0;
278 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
279 if (nCode == KEY_UP)
281 // scroll up
282 nX = 0;
283 nY =-1;
285 else if (nCode == KEY_DOWN)
287 // scroll down
288 nX = 0;
289 nY = 1;
291 else if (nCode == KEY_LEFT)
293 // scroll left
294 nX =-1;
295 nY = 0;
297 else if (nCode == KEY_RIGHT)
299 // scroll right
300 nX = 1;
301 nY = 0;
303 Point centerPoint;
304 ::tools::Rectangle rect = mpView->GetMarkedObjRect();
305 centerPoint = mpWindow->LogicToPixel(rect.Center());
306 Point aPoint = bBeginInsertPoint? oldPoint:centerPoint;
307 Point ePoint = aPoint + Point(nX,nY);
308 mpWindow->SetPointerPosPixel(ePoint);
309 //simulate mouse move action
310 MouseEvent eMevt(ePoint, 1, MouseEventModifiers::DRAGMOVE, MOUSE_LEFT, 0);
311 MouseMove(eMevt);
312 oldPoint = ePoint;
313 bBeginInsertPoint = true;
314 bReturn = true;
317 break;
318 case KEY_RETURN:
319 if(rKEvt.GetKeyCode().IsShift() && mpView->IsInsGluePointMode() )
321 if(bBeginInsertPoint)
323 mpWindow->SetPointerPosPixel(oldPoint);
324 //simulate mouse button down action
325 MouseEvent aMevt(oldPoint, 1,
326 MouseEventModifiers::SIMPLEMOVE | MouseEventModifiers::DRAGMOVE,
327 MOUSE_LEFT, KEY_SHIFT);
328 // MT IA2: Not used?
329 // sal_uInt16 ubuttons = aMevt.GetButtons();
330 // sal_uInt16 uMod = aMevt.GetModifier();
331 MouseButtonDown(aMevt);
332 mpWindow->CaptureMouse();
333 //simulate mouse button up action
334 MouseEvent rMEvt(oldPoint+Point(0,0), 1,
335 MouseEventModifiers::SIMPLEMOVE | MouseEventModifiers::ENTERWINDOW,
336 MOUSE_LEFT, KEY_SHIFT);
337 MouseButtonUp(rMEvt);
338 bReturn= true;
341 break;
344 if(!bReturn)
345 bReturn = FuDraw::KeyInput(rKEvt);
347 return bReturn;
350 //Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point, and
351 //SHIFT+ENTER key to decide the position and draw the new insert point
352 void FuEditGluePoints::ForcePointer(const MouseEvent* pMEvt)
354 if(bBeginInsertPoint && pMEvt)
356 MouseEvent aMEvt(pMEvt->GetPosPixel(), pMEvt->GetClicks(),
357 pMEvt->GetMode(), pMEvt->GetButtons(), pMEvt->GetModifier() & ~KEY_SHIFT);
358 FuDraw::ForcePointer(&aMEvt);
360 else
362 FuDraw::ForcePointer(pMEvt);
366 bool FuEditGluePoints::Command(const CommandEvent& rCEvt)
368 mpView->SetActualWin( mpWindow );
369 return FuPoor::Command( rCEvt );
372 void FuEditGluePoints::Activate()
374 mpView->SetGluePointEditMode();
375 FuDraw::Activate();
378 void FuEditGluePoints::Deactivate()
380 mpView->SetGluePointEditMode( false );
381 FuDraw::Deactivate();
384 void FuEditGluePoints::ReceiveRequest(SfxRequest& rReq)
386 switch (rReq.GetSlot())
388 case SID_GLUE_INSERT_POINT:
390 mpView->SetInsGluePointMode(!mpView->IsInsGluePointMode());
392 break;
394 case SID_GLUE_ESCDIR_LEFT:
396 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::LEFT,
397 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::LEFT ) );
399 break;
401 case SID_GLUE_ESCDIR_RIGHT:
403 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT,
404 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT ) );
406 break;
408 case SID_GLUE_ESCDIR_TOP:
410 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::TOP,
411 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::TOP ) );
413 break;
415 case SID_GLUE_ESCDIR_BOTTOM:
417 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM,
418 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM ) );
420 break;
422 case SID_GLUE_PERCENT:
424 const SfxItemSet* pSet = rReq.GetArgs();
425 const SfxPoolItem& rItem = pSet->Get(SID_GLUE_PERCENT);
426 bool bPercent = static_cast<const SfxBoolItem&>(rItem).GetValue();
427 mpView->SetMarkedGluePointsPercent(bPercent);
429 break;
431 case SID_GLUE_HORZALIGN_CENTER:
433 mpView->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_CENTER);
435 break;
437 case SID_GLUE_HORZALIGN_LEFT:
439 mpView->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_LEFT);
441 break;
443 case SID_GLUE_HORZALIGN_RIGHT:
445 mpView->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_RIGHT);
447 break;
449 case SID_GLUE_VERTALIGN_CENTER:
451 mpView->SetMarkedGluePointsAlign(true, SdrAlign::VERT_CENTER);
453 break;
455 case SID_GLUE_VERTALIGN_TOP:
457 mpView->SetMarkedGluePointsAlign(true, SdrAlign::VERT_TOP);
459 break;
461 case SID_GLUE_VERTALIGN_BOTTOM:
463 mpView->SetMarkedGluePointsAlign(true, SdrAlign::VERT_BOTTOM);
465 break;
468 // at the end, call base class
469 FuPoor::ReceiveRequest(rReq);
472 } // end of namespace sd
474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */