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>
27 #include "strings.hrc"
28 #include "res_bmp.hrc"
30 #include "drawdoc.hxx"
31 #include "FrameView.hxx"
33 #include "ViewShell.hxx"
34 #include "ViewShellBase.hxx"
35 #include "ToolBarManager.hxx"
39 TYPEINIT1( FuEditGluePoints
, FuDraw
);
41 FuEditGluePoints::FuEditGluePoints (
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),
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
);
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()
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())
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();
102 SdrHitKind eHit
= mpView
->PickAnything(rMEvt
, SdrMouseEventKind::BUTTONDOWN
, aVEvt
);
104 if (eHit
== SDRHIT_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
);
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())
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
);
150 mpView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
155 // select or drag object
156 if (!rMEvt
.IsShift() && !rMEvt
.IsMod2() && eHit
== SDRHIT_UNMARKEDOBJECT
)
158 mpView
->UnmarkAllObj();
161 bool bMarked
= false;
167 bMarked
= mpView
->MarkNextObj(aMDPos
, nHitLog
, rMEvt
.IsShift());
171 bMarked
= mpView
->MarkObj(aMDPos
, nHitLog
, rMEvt
.IsShift());
176 (!rMEvt
.IsShift() || eHit
== SDRHIT_MARKEDOBJECT
))
179 mpView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, aVEvt
.pHdl
, nDrgLog
);
181 else if (mpView
->AreObjectsMarked())
184 if (!rMEvt
.IsShift())
185 mpView
->UnmarkAllGluePoints();
187 mpView
->BegMarkGluePoints(aMDPos
);
192 mpView
->BegMarkObj(aMDPos
);
196 ForcePointer(&rMEvt
);
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
) );
213 mpView
->MovAction(aPnt
);
216 ForcePointer(&rMEvt
);
221 bool FuEditGluePoints::MouseButtonUp(const MouseEvent
& rMEvt
)
223 mpView
->SetActualWin( mpWindow
);
225 bool bReturn
= false;
227 if (mpView
->IsAction())
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())
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();
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())
277 if(rKEvt
.GetKeyCode().IsShift()&& mpView
->IsInsGluePointMode() ){
280 sal_uInt16 nCode
= rKEvt
.GetKeyCode().GetCode();
287 else if (nCode
== KEY_DOWN
)
293 else if (nCode
== KEY_LEFT
)
299 else if (nCode
== KEY_RIGHT
)
301 // Scroll nach rechts
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);
315 bBeginInsertPoint
= true;
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
);
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
);
347 bReturn
= FuDraw::KeyInput(rKEvt
);
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
);
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();
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());
396 case SID_GLUE_ESCDIR_LEFT
:
398 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::LEFT
,
399 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::LEFT
) );
403 case SID_GLUE_ESCDIR_RIGHT
:
405 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT
,
406 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::RIGHT
) );
410 case SID_GLUE_ESCDIR_TOP
:
412 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::TOP
,
413 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::TOP
) );
417 case SID_GLUE_ESCDIR_BOTTOM
:
419 mpView
->SetMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM
,
420 !mpView
->IsMarkedGluePointsEscDir( SdrEscapeDirection::BOTTOM
) );
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
);
433 case SID_GLUE_HORZALIGN_CENTER
:
435 mpView
->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_CENTER
);
439 case SID_GLUE_HORZALIGN_LEFT
:
441 mpView
->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_LEFT
);
445 case SID_GLUE_HORZALIGN_RIGHT
:
447 mpView
->SetMarkedGluePointsAlign(false, SdrAlign::HORZ_RIGHT
);
451 case SID_GLUE_VERTALIGN_CENTER
:
453 mpView
->SetMarkedGluePointsAlign(true, SdrAlign::VERT_CENTER
);
457 case SID_GLUE_VERTALIGN_TOP
:
459 mpView
->SetMarkedGluePointsAlign(true, SdrAlign::VERT_TOP
);
463 case SID_GLUE_VERTALIGN_BOTTOM
:
465 mpView
->SetMarkedGluePointsAlign(true, SdrAlign::VERT_BOTTOM
);
470 // at the end, call base class
471 FuPoor::ReceiveRequest(rReq
);
474 } // end of namespace sd
476 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */