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 .
21 #include "fuediglu.hxx"
22 #include <svl/eitem.hxx>
23 #include <svx/dialogs.hrc>
24 #include <svx/svdglue.hxx>
25 #include <sfx2/request.hxx>
29 #include "strings.hrc"
30 #include "res_bmp.hrc"
32 #include "drawdoc.hxx"
33 #include "FrameView.hxx"
35 #include "ViewShell.hxx"
36 #include "ViewShellBase.hxx"
37 #include "ToolBarManager.hxx"
41 TYPEINIT1( FuEditGluePoints
, FuDraw
);
44 FuEditGluePoints::FuEditGluePoints (
50 : FuDraw(pViewSh
, pWin
, pView
, pDoc
, rReq
)
54 FunctionReference
FuEditGluePoints::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
56 FuEditGluePoints
* pFunc
;
57 FunctionReference
xFunc( pFunc
= new FuEditGluePoints( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
58 xFunc
->DoExecute(rReq
);
59 pFunc
->SetPermanent( bPermanent
);
63 void FuEditGluePoints::DoExecute( SfxRequest
& rReq
)
65 FuDraw::DoExecute( rReq
);
66 mpView
->SetInsGluePointMode(sal_False
);
67 mpViewShell
->GetViewShellBase().GetToolBarManager()->AddToolBar(
68 ToolBarManager::TBG_FUNCTION
,
69 ToolBarManager::msGluePointsToolBar
);
73 FuEditGluePoints::~FuEditGluePoints()
76 mpView
->UnmarkAllGluePoints();
77 mpView
->SetInsGluePointMode(sal_False
);
81 sal_Bool
FuEditGluePoints::MouseButtonDown(const MouseEvent
& rMEvt
)
83 mpView
->SetActualWin( mpWindow
);
85 sal_Bool bReturn
= FuDraw::MouseButtonDown(rMEvt
);
87 if (mpView
->IsAction())
98 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
99 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
100 mpWindow
->CaptureMouse();
103 SdrHitKind eHit
= mpView
->PickAnything(rMEvt
, SDRMOUSEBUTTONDOWN
, aVEvt
);
105 if (eHit
== SDRHIT_HANDLE
)
108 SdrHdl
* pHdl
= aVEvt
.pHdl
;
110 if (mpView
->IsGluePointMarked(aVEvt
.pObj
, aVEvt
.nGlueId
) && rMEvt
.IsShift())
112 mpView
->UnmarkGluePoint(aVEvt
.pObj
, aVEvt
.nGlueId
, aVEvt
.pPV
);
119 mpView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, aVEvt
.pHdl
, nDrgLog
);
122 else if (eHit
== SDRHIT_MARKEDOBJECT
&& mpView
->IsInsGluePointMode())
124 // insert glue points
125 mpView
->BegInsGluePoint(aMDPos
);
127 else if (eHit
== SDRHIT_MARKEDOBJECT
&& rMEvt
.IsMod1())
129 // select glue points
130 if (!rMEvt
.IsShift())
131 mpView
->UnmarkAllGluePoints();
133 mpView
->BegMarkGluePoints(aMDPos
);
135 else if (eHit
== SDRHIT_MARKEDOBJECT
&& !rMEvt
.IsShift() && !rMEvt
.IsMod2())
138 mpView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, NULL
, nDrgLog
);
140 else if (eHit
== SDRHIT_GLUEPOINT
)
142 // select glue points
143 if (!rMEvt
.IsShift())
144 mpView
->UnmarkAllGluePoints();
146 mpView
->MarkGluePoint(aVEvt
.pObj
, aVEvt
.nGlueId
, aVEvt
.pPV
);
147 SdrHdl
* pHdl
= mpView
->GetGluePointHdl(aVEvt
.pObj
, aVEvt
.nGlueId
);
151 mpView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
156 // select or drag object
157 if (!rMEvt
.IsShift() && !rMEvt
.IsMod2() && eHit
== SDRHIT_UNMARKEDOBJECT
)
159 mpView
->UnmarkAllObj();
162 sal_Bool bMarked
= sal_False
;
168 bMarked
= mpView
->MarkNextObj(aMDPos
, nHitLog
, rMEvt
.IsShift());
172 bMarked
= mpView
->MarkObj(aMDPos
, nHitLog
, rMEvt
.IsShift());
177 (!rMEvt
.IsShift() || eHit
== SDRHIT_MARKEDOBJECT
))
180 mpView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, aVEvt
.pHdl
, nDrgLog
);
182 else if (mpView
->AreObjectsMarked())
185 if (!rMEvt
.IsShift())
186 mpView
->UnmarkAllGluePoints();
188 mpView
->BegMarkGluePoints(aMDPos
);
193 mpView
->BegMarkObj(aMDPos
);
197 ForcePointer(&rMEvt
);
204 sal_Bool
FuEditGluePoints::MouseMove(const MouseEvent
& rMEvt
)
206 mpView
->SetActualWin( mpWindow
);
208 FuDraw::MouseMove(rMEvt
);
210 if (mpView
->IsAction())
212 Point
aPix(rMEvt
.GetPosPixel());
213 Point
aPnt( mpWindow
->PixelToLogic(aPix
) );
215 mpView
->MovAction(aPnt
);
218 ForcePointer(&rMEvt
);
224 sal_Bool
FuEditGluePoints::MouseButtonUp(const MouseEvent
& rMEvt
)
226 mpView
->SetActualWin( mpWindow
);
228 sal_Bool bReturn
= sal_False
;
230 if (mpView
->IsAction())
236 FuDraw::MouseButtonUp(rMEvt
);
238 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
239 Point aPos
= mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() );
241 if (std::abs(aMDPos
.X() - aPos
.X()) < nDrgLog
&&
242 std::abs(aMDPos
.Y() - aPos
.Y()) < nDrgLog
&&
243 !rMEvt
.IsShift() && !rMEvt
.IsMod2())
246 SdrHitKind eHit
= mpView
->PickAnything(rMEvt
, SDRMOUSEBUTTONDOWN
, aVEvt
);
248 if (eHit
== SDRHIT_NONE
)
250 // click on position: deselect
251 mpView
->UnmarkAllObj();
255 mpWindow
->ReleaseMouse();
261 * Process keyboard input
262 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
264 sal_Bool
FuEditGluePoints::KeyInput(const KeyEvent
& rKEvt
)
266 mpView
->SetActualWin( mpWindow
);
268 sal_Bool bReturn
= FuDraw::KeyInput(rKEvt
);
274 sal_Bool
FuEditGluePoints::Command(const CommandEvent
& rCEvt
)
276 mpView
->SetActualWin( mpWindow
);
277 return FuPoor::Command( rCEvt
);
281 void FuEditGluePoints::Activate()
283 mpView
->SetGluePointEditMode();
288 void FuEditGluePoints::Deactivate()
290 mpView
->SetGluePointEditMode( sal_False
);
291 FuDraw::Deactivate();
295 void FuEditGluePoints::ReceiveRequest(SfxRequest
& rReq
)
297 switch (rReq
.GetSlot())
299 case SID_GLUE_INSERT_POINT
:
301 mpView
->SetInsGluePointMode(!mpView
->IsInsGluePointMode());
305 case SID_GLUE_ESCDIR_LEFT
:
307 mpView
->SetMarkedGluePointsEscDir( SDRESC_LEFT
,
308 !mpView
->IsMarkedGluePointsEscDir( SDRESC_LEFT
) );
312 case SID_GLUE_ESCDIR_RIGHT
:
314 mpView
->SetMarkedGluePointsEscDir( SDRESC_RIGHT
,
315 !mpView
->IsMarkedGluePointsEscDir( SDRESC_RIGHT
) );
319 case SID_GLUE_ESCDIR_TOP
:
321 mpView
->SetMarkedGluePointsEscDir( SDRESC_TOP
,
322 !mpView
->IsMarkedGluePointsEscDir( SDRESC_TOP
) );
326 case SID_GLUE_ESCDIR_BOTTOM
:
328 mpView
->SetMarkedGluePointsEscDir( SDRESC_BOTTOM
,
329 !mpView
->IsMarkedGluePointsEscDir( SDRESC_BOTTOM
) );
333 case SID_GLUE_PERCENT
:
335 const SfxItemSet
* pSet
= rReq
.GetArgs();
336 const SfxPoolItem
& rItem
= pSet
->Get(SID_GLUE_PERCENT
);
337 sal_Bool bPercent
= ((const SfxBoolItem
&) rItem
).GetValue();
338 mpView
->SetMarkedGluePointsPercent(bPercent
);
342 case SID_GLUE_HORZALIGN_CENTER
:
344 mpView
->SetMarkedGluePointsAlign(sal_False
, SDRHORZALIGN_CENTER
);
348 case SID_GLUE_HORZALIGN_LEFT
:
350 mpView
->SetMarkedGluePointsAlign(sal_False
, SDRHORZALIGN_LEFT
);
354 case SID_GLUE_HORZALIGN_RIGHT
:
356 mpView
->SetMarkedGluePointsAlign(sal_False
, SDRHORZALIGN_RIGHT
);
360 case SID_GLUE_VERTALIGN_CENTER
:
362 mpView
->SetMarkedGluePointsAlign(sal_True
, SDRVERTALIGN_CENTER
);
366 case SID_GLUE_VERTALIGN_TOP
:
368 mpView
->SetMarkedGluePointsAlign(sal_True
, SDRVERTALIGN_TOP
);
372 case SID_GLUE_VERTALIGN_BOTTOM
:
374 mpView
->SetMarkedGluePointsAlign(sal_True
, SDRVERTALIGN_BOTTOM
);
379 // at the end, call base class
380 FuPoor::ReceiveRequest(rReq
);
384 } // end of namespace sd
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */