bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / func / fuediglu.cxx
blob678582736ceb418e69f1ebdc067a347b3e03a361
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/svdglue.hxx>
23 #include <sfx2/request.hxx>
25 #include <app.hrc>
27 #include <Window.hxx>
28 #include <View.hxx>
29 #include <ViewShell.hxx>
30 #include <ViewShellBase.hxx>
31 #include <ToolBarManager.hxx>
33 namespace sd {
36 FuEditGluePoints::FuEditGluePoints (
37 ViewShell* pViewSh,
38 ::sd::Window* pWin,
39 ::sd::View* pView,
40 SdDrawDocument* pDoc,
41 SfxRequest& rReq)
42 : FuDraw(pViewSh, pWin, pView, pDoc, rReq)
43 //Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
44 //and SHIFT+ENTER key to decide the position and draw the new insert point
45 ,bBeginInsertPoint(false),
46 oldPoint(0,0)
50 rtl::Reference<FuPoor> FuEditGluePoints::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
52 FuEditGluePoints* pFunc;
53 rtl::Reference<FuPoor> xFunc( pFunc = new FuEditGluePoints( pViewSh, pWin, pView, pDoc, rReq ) );
54 xFunc->DoExecute(rReq);
55 pFunc->SetPermanent( bPermanent );
56 return xFunc;
59 void FuEditGluePoints::DoExecute( SfxRequest& rReq )
61 FuDraw::DoExecute( rReq );
62 mpView->SetInsGluePointMode(false);
63 mpViewShell->GetViewShellBase().GetToolBarManager()->AddToolBar(
64 ToolBarManager::ToolBarGroup::Function,
65 ToolBarManager::msGluePointsToolBar);
68 FuEditGluePoints::~FuEditGluePoints()
70 mpView->BrkAction();
71 mpView->UnmarkAllGluePoints();
72 mpView->SetInsGluePointMode(false);
75 bool FuEditGluePoints::MouseButtonDown(const MouseEvent& rMEvt)
77 mpView->SetActualWin( mpWindow );
79 bool bReturn = FuDraw::MouseButtonDown(rMEvt);
81 if (mpView->IsAction())
83 if (rMEvt.IsRight())
84 mpView->BckAction();
86 return true;
89 if (rMEvt.IsLeft())
91 bReturn = true;
92 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
93 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
94 mpWindow->CaptureMouse();
96 SdrViewEvent aVEvt;
97 SdrHitKind eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
99 if (eHit == SdrHitKind::Handle)
101 // drag handle
102 SdrHdl* pHdl = aVEvt.pHdl;
104 if (mpView->IsGluePointMarked(aVEvt.pObj, aVEvt.nGlueId) && rMEvt.IsShift())
106 mpView->UnmarkGluePoint(aVEvt.pObj, aVEvt.nGlueId);
107 pHdl = nullptr;
110 if (pHdl)
112 // drag handle
113 mpView->BegDragObj(aMDPos, nullptr, aVEvt.pHdl, nDrgLog);
116 else if (eHit == SdrHitKind::MarkedObject && mpView->IsInsGluePointMode())
118 // insert glue points
119 mpView->BegInsGluePoint(aMDPos);
121 else if (eHit == SdrHitKind::MarkedObject && rMEvt.IsMod1())
123 // select glue points
124 if (!rMEvt.IsShift())
125 mpView->UnmarkAllGluePoints();
127 mpView->BegMarkGluePoints(aMDPos);
129 else if (eHit == SdrHitKind::MarkedObject && !rMEvt.IsShift() && !rMEvt.IsMod2())
131 // move object
132 mpView->BegDragObj(aMDPos, nullptr, nullptr, nDrgLog);
134 else if (eHit == SdrHitKind::Gluepoint)
136 // select glue points
137 if (!rMEvt.IsShift())
138 mpView->UnmarkAllGluePoints();
140 mpView->MarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, false);
141 SdrHdl* pHdl = mpView->GetGluePointHdl(aVEvt.pObj, aVEvt.nGlueId);
143 if (pHdl)
145 mpView->BegDragObj(aMDPos, nullptr, pHdl, nDrgLog);
148 else
150 // select or drag object
151 if (!rMEvt.IsShift() && !rMEvt.IsMod2() && eHit == SdrHitKind::UnmarkedObject)
153 mpView->UnmarkAllObj();
156 bool bMarked = false;
158 if (!rMEvt.IsMod1())
160 if (rMEvt.IsMod2())
162 bMarked = mpView->MarkNextObj(aMDPos, nHitLog, rMEvt.IsShift());
164 else
166 bMarked = mpView->MarkObj(aMDPos, nHitLog, rMEvt.IsShift());
170 if (bMarked &&
171 (!rMEvt.IsShift() || eHit == SdrHitKind::MarkedObject))
173 // move object
174 mpView->BegDragObj(aMDPos, nullptr, aVEvt.pHdl, nDrgLog);
176 else if (mpView->AreObjectsMarked())
178 // select glue point
179 if (!rMEvt.IsShift())
180 mpView->UnmarkAllGluePoints();
182 mpView->BegMarkGluePoints(aMDPos);
184 else
186 // select object
187 mpView->BegMarkObj(aMDPos);
191 ForcePointer(&rMEvt);
194 return bReturn;
197 bool FuEditGluePoints::MouseMove(const MouseEvent& rMEvt)
199 mpView->SetActualWin( mpWindow );
201 FuDraw::MouseMove(rMEvt);
203 if (mpView->IsAction())
205 Point aPix(rMEvt.GetPosPixel());
206 Point aPnt( mpWindow->PixelToLogic(aPix) );
207 ForceScroll(aPix);
208 mpView->MovAction(aPnt);
211 ForcePointer(&rMEvt);
213 return true;
216 bool FuEditGluePoints::MouseButtonUp(const MouseEvent& rMEvt)
218 mpView->SetActualWin( mpWindow );
220 bool bReturn = false;
222 if (mpView->IsAction())
224 bReturn = true;
225 mpView->EndAction();
228 FuDraw::MouseButtonUp(rMEvt);
230 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
231 Point aPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
233 if (std::abs(aMDPos.X() - aPos.X()) < nDrgLog &&
234 std::abs(aMDPos.Y() - aPos.Y()) < nDrgLog &&
235 !rMEvt.IsShift() && !rMEvt.IsMod2())
237 SdrViewEvent aVEvt;
238 SdrHitKind eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
240 if (eHit == SdrHitKind::NONE)
242 // click on position: deselect
243 mpView->UnmarkAllObj();
247 mpWindow->ReleaseMouse();
249 return bReturn;
253 * Process keyboard input
254 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
256 bool FuEditGluePoints::KeyInput(const KeyEvent& rKEvt)
258 mpView->SetActualWin( mpWindow );
260 //Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
261 //and SHIFT+ENTER key to decide the position and draw the new insert point
263 bool bReturn = false;
265 switch (rKEvt.GetKeyCode().GetCode())
267 case KEY_UP:
268 case KEY_DOWN:
269 case KEY_LEFT:
270 case KEY_RIGHT:
272 if(rKEvt.GetKeyCode().IsShift()&& mpView->IsInsGluePointMode() ){
273 long nX = 0;
274 long nY = 0;
275 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
276 if (nCode == KEY_UP)
278 // scroll up
279 nX = 0;
280 nY =-1;
282 else if (nCode == KEY_DOWN)
284 // scroll down
285 nX = 0;
286 nY = 1;
288 else if (nCode == KEY_LEFT)
290 // scroll left
291 nX =-1;
292 nY = 0;
294 else if (nCode == KEY_RIGHT)
296 // scroll right
297 nX = 1;
298 nY = 0;
300 Point centerPoint;
301 ::tools::Rectangle rect = mpView->GetMarkedObjRect();
302 centerPoint = mpWindow->LogicToPixel(rect.Center());
303 Point aPoint = bBeginInsertPoint? oldPoint:centerPoint;
304 Point ePoint = aPoint + Point(nX,nY);
305 mpWindow->SetPointerPosPixel(ePoint);
306 //simulate mouse move action
307 MouseEvent eMevt(ePoint, 1, MouseEventModifiers::DRAGMOVE, MOUSE_LEFT, 0);
308 MouseMove(eMevt);
309 oldPoint = ePoint;
310 bBeginInsertPoint = true;
311 bReturn = true;
314 break;
315 case KEY_RETURN:
316 if(rKEvt.GetKeyCode().IsShift() && mpView->IsInsGluePointMode() )
318 if(bBeginInsertPoint)
320 mpWindow->SetPointerPosPixel(oldPoint);
321 //simulate mouse button down action
322 MouseEvent aMevt(oldPoint, 1,
323 MouseEventModifiers::SIMPLEMOVE | MouseEventModifiers::DRAGMOVE,
324 MOUSE_LEFT, KEY_SHIFT);
325 // MT IA2: Not used?
326 // sal_uInt16 ubuttons = aMevt.GetButtons();
327 // sal_uInt16 uMod = aMevt.GetModifier();
328 MouseButtonDown(aMevt);
329 mpWindow->CaptureMouse();
330 //simulate mouse button up action
331 MouseEvent rMEvt(oldPoint+Point(0,0), 1,
332 MouseEventModifiers::SIMPLEMOVE | MouseEventModifiers::ENTERWINDOW,
333 MOUSE_LEFT, KEY_SHIFT);
334 MouseButtonUp(rMEvt);
335 bReturn= true;
338 break;
341 if(!bReturn)
342 bReturn = FuDraw::KeyInput(rKEvt);
344 return bReturn;
347 //Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point, and
348 //SHIFT+ENTER key to decide the position and draw the new insert point
349 void FuEditGluePoints::ForcePointer(const MouseEvent* pMEvt)
351 if(bBeginInsertPoint && pMEvt)
353 MouseEvent aMEvt(pMEvt->GetPosPixel(), pMEvt->GetClicks(),
354 pMEvt->GetMode(), pMEvt->GetButtons(), pMEvt->GetModifier() & ~KEY_SHIFT);
355 FuDraw::ForcePointer(&aMEvt);
357 else
359 FuDraw::ForcePointer(pMEvt);
363 bool FuEditGluePoints::Command(const CommandEvent& rCEvt)
365 mpView->SetActualWin( mpWindow );
366 return FuPoor::Command( rCEvt );
369 void FuEditGluePoints::Activate()
371 mpView->SetGluePointEditMode();
372 FuDraw::Activate();
375 void FuEditGluePoints::Deactivate()
377 mpView->SetGluePointEditMode( false );
378 FuDraw::Deactivate();
381 void FuEditGluePoints::ReceiveRequest(SfxRequest& rReq)
383 switch (rReq.GetSlot())
385 case SID_GLUE_INSERT_POINT:
387 mpView->SetInsGluePointMode(!mpView->IsInsGluePointMode());
389 break;
391 case SID_GLUE_ESCDIR_LEFT:
393 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::LEFT,
394 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::LEFT ) );
396 break;
398 case SID_GLUE_ESCDIR_RIGHT:
400 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT,
401 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT ) );
403 break;
405 case SID_GLUE_ESCDIR_TOP:
407 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::TOP,
408 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::TOP ) );
410 break;
412 case SID_GLUE_ESCDIR_BOTTOM:
414 mpView->SetMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM,
415 !mpView->IsMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM ) );
417 break;
419 case SID_GLUE_PERCENT:
421 const SfxItemSet* pSet = rReq.GetArgs();
422 const SfxPoolItem& rItem = pSet->Get(SID_GLUE_PERCENT);
423 bool bPercent = static_cast<const SfxBoolItem&>(rItem).GetValue();
424 mpView->SetMarkedGluePointsPercent(bPercent);
426 break;
428 case SID_GLUE_HORZALIGN_CENTER:
430 mpView->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_CENTER);
432 break;
434 case SID_GLUE_HORZALIGN_LEFT:
436 mpView->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_LEFT);
438 break;
440 case SID_GLUE_HORZALIGN_RIGHT:
442 mpView->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_RIGHT);
444 break;
446 case SID_GLUE_VERTALIGN_CENTER:
448 mpView->SetMarkedGluePointsAlign(true, SdrAlign::VERT_CENTER);
450 break;
452 case SID_GLUE_VERTALIGN_TOP:
454 mpView->SetMarkedGluePointsAlign(true, SdrAlign::VERT_TOP);
456 break;
458 case SID_GLUE_VERTALIGN_BOTTOM:
460 mpView->SetMarkedGluePointsAlign(true, SdrAlign::VERT_BOTTOM);
462 break;
465 // at the end, call base class
466 FuPoor::ReceiveRequest(rReq);
469 } // end of namespace sd
471 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */