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/dialogs.hrc>
23 #include <svx/svdglue.hxx>
24 #include <sfx2/request.hxx>
29 #include <drawdoc.hxx>
30 #include <FrameView.hxx>
32 #include <ViewShell.hxx>
33 #include <ViewShellBase.hxx>
34 #include <ToolBarManager.hxx>
39 FuEditGluePoints::FuEditGluePoints (
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),
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
);
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()
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())
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();
100 SdrHitKind eHit
= mpView
->PickAnything(rMEvt
, SdrMouseEventKind::BUTTONDOWN
, aVEvt
);
102 if (eHit
== SdrHitKind::Handle
)
105 SdrHdl
* pHdl
= aVEvt
.pHdl
;
107 if (mpView
->IsGluePointMarked(aVEvt
.pObj
, aVEvt
.nGlueId
) && rMEvt
.IsShift())
109 mpView
->UnmarkGluePoint(aVEvt
.pObj
, aVEvt
.nGlueId
);
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())
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
);
148 mpView
->BegDragObj(aMDPos
, nullptr, pHdl
, nDrgLog
);
153 // select or drag object
154 if (!rMEvt
.IsShift() && !rMEvt
.IsMod2() && eHit
== SdrHitKind::UnmarkedObject
)
156 mpView
->UnmarkAllObj();
159 bool bMarked
= false;
165 bMarked
= mpView
->MarkNextObj(aMDPos
, nHitLog
, rMEvt
.IsShift());
169 bMarked
= mpView
->MarkObj(aMDPos
, nHitLog
, rMEvt
.IsShift());
174 (!rMEvt
.IsShift() || eHit
== SdrHitKind::MarkedObject
))
177 mpView
->BegDragObj(aMDPos
, nullptr, aVEvt
.pHdl
, nDrgLog
);
179 else if (mpView
->AreObjectsMarked())
182 if (!rMEvt
.IsShift())
183 mpView
->UnmarkAllGluePoints();
185 mpView
->BegMarkGluePoints(aMDPos
);
190 mpView
->BegMarkObj(aMDPos
);
194 ForcePointer(&rMEvt
);
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
) );
211 mpView
->MovAction(aPnt
);
214 ForcePointer(&rMEvt
);
219 bool FuEditGluePoints::MouseButtonUp(const MouseEvent
& rMEvt
)
221 mpView
->SetActualWin( mpWindow
);
223 bool bReturn
= false;
225 if (mpView
->IsAction())
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())
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();
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())
275 if(rKEvt
.GetKeyCode().IsShift()&& mpView
->IsInsGluePointMode() ){
278 sal_uInt16 nCode
= rKEvt
.GetKeyCode().GetCode();
285 else if (nCode
== KEY_DOWN
)
291 else if (nCode
== KEY_LEFT
)
297 else if (nCode
== KEY_RIGHT
)
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);
313 bBeginInsertPoint
= true;
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
);
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
);
345 bReturn
= FuDraw::KeyInput(rKEvt
);
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
);
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();
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());
394 case SID_GLUE_ESCDIR_LEFT
:
396 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::LEFT
,
397 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::LEFT
) );
401 case SID_GLUE_ESCDIR_RIGHT
:
403 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT
,
404 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT
) );
408 case SID_GLUE_ESCDIR_TOP
:
410 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::TOP
,
411 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::TOP
) );
415 case SID_GLUE_ESCDIR_BOTTOM
:
417 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM
,
418 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM
) );
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
);
431 case SID_GLUE_HORZALIGN_CENTER
:
433 mpView
->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_CENTER
);
437 case SID_GLUE_HORZALIGN_LEFT
:
439 mpView
->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_LEFT
);
443 case SID_GLUE_HORZALIGN_RIGHT
:
445 mpView
->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_RIGHT
);
449 case SID_GLUE_VERTALIGN_CENTER
:
451 mpView
->SetMarkedGluePointsAlign(true, SdrAlign::VERT_CENTER
);
455 case SID_GLUE_VERTALIGN_TOP
:
457 mpView
->SetMarkedGluePointsAlign(true, SdrAlign::VERT_TOP
);
461 case SID_GLUE_VERTALIGN_BOTTOM
:
463 mpView
->SetMarkedGluePointsAlign(true, SdrAlign::VERT_BOTTOM
);
468 // at the end, call base class
469 FuPoor::ReceiveRequest(rReq
);
472 } // end of namespace sd
474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */