1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 #include <ViewShell.hxx>
30 #include <ViewShellBase.hxx>
31 #include <ToolBarManager.hxx>
36 FuEditGluePoints::FuEditGluePoints (
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),
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
);
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()
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())
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();
97 SdrHitKind eHit
= mpView
->PickAnything(rMEvt
, SdrMouseEventKind::BUTTONDOWN
, aVEvt
);
99 if (eHit
== SdrHitKind::Handle
)
102 SdrHdl
* pHdl
= aVEvt
.pHdl
;
104 if (mpView
->IsGluePointMarked(aVEvt
.pObj
, aVEvt
.nGlueId
) && rMEvt
.IsShift())
106 mpView
->UnmarkGluePoint(aVEvt
.pObj
, aVEvt
.nGlueId
);
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())
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
);
145 mpView
->BegDragObj(aMDPos
, nullptr, pHdl
, nDrgLog
);
150 // select or drag object
151 if (!rMEvt
.IsShift() && !rMEvt
.IsMod2() && eHit
== SdrHitKind::UnmarkedObject
)
153 mpView
->UnmarkAllObj();
156 bool bMarked
= false;
162 bMarked
= mpView
->MarkNextObj(aMDPos
, nHitLog
, rMEvt
.IsShift());
166 bMarked
= mpView
->MarkObj(aMDPos
, nHitLog
, rMEvt
.IsShift());
171 (!rMEvt
.IsShift() || eHit
== SdrHitKind::MarkedObject
))
174 mpView
->BegDragObj(aMDPos
, nullptr, aVEvt
.pHdl
, nDrgLog
);
176 else if (mpView
->AreObjectsMarked())
179 if (!rMEvt
.IsShift())
180 mpView
->UnmarkAllGluePoints();
182 mpView
->BegMarkGluePoints(aMDPos
);
187 mpView
->BegMarkObj(aMDPos
);
191 ForcePointer(&rMEvt
);
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
) );
208 mpView
->MovAction(aPnt
);
211 ForcePointer(&rMEvt
);
216 bool FuEditGluePoints::MouseButtonUp(const MouseEvent
& rMEvt
)
218 mpView
->SetActualWin( mpWindow
);
220 bool bReturn
= false;
222 if (mpView
->IsAction())
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())
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();
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())
272 if(rKEvt
.GetKeyCode().IsShift()&& mpView
->IsInsGluePointMode() ){
275 sal_uInt16 nCode
= rKEvt
.GetKeyCode().GetCode();
282 else if (nCode
== KEY_DOWN
)
288 else if (nCode
== KEY_LEFT
)
294 else if (nCode
== KEY_RIGHT
)
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);
310 bBeginInsertPoint
= true;
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
);
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
);
342 bReturn
= FuDraw::KeyInput(rKEvt
);
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
);
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();
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());
391 case SID_GLUE_ESCDIR_LEFT
:
393 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::LEFT
,
394 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::LEFT
) );
398 case SID_GLUE_ESCDIR_RIGHT
:
400 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT
,
401 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT
) );
405 case SID_GLUE_ESCDIR_TOP
:
407 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::TOP
,
408 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::TOP
) );
412 case SID_GLUE_ESCDIR_BOTTOM
:
414 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM
,
415 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM
) );
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
);
428 case SID_GLUE_HORZALIGN_CENTER
:
430 mpView
->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_CENTER
);
434 case SID_GLUE_HORZALIGN_LEFT
:
436 mpView
->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_LEFT
);
440 case SID_GLUE_HORZALIGN_RIGHT
:
442 mpView
->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_RIGHT
);
446 case SID_GLUE_VERTALIGN_CENTER
:
448 mpView
->SetMarkedGluePointsAlign(true, SdrAlign::VERT_CENTER
);
452 case SID_GLUE_VERTALIGN_TOP
:
454 mpView
->SetMarkedGluePointsAlign(true, SdrAlign::VERT_TOP
);
458 case SID_GLUE_VERTALIGN_BOTTOM
:
460 mpView
->SetMarkedGluePointsAlign(true, SdrAlign::VERT_BOTTOM
);
465 // at the end, call base class
466 FuPoor::ReceiveRequest(rReq
);
469 } // end of namespace sd
471 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */