bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fuediglu.cxx
blob2e5bd6f4d713c549b046bd0d6cc0e84a6b128bd5
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 .
21 #include "fuediglu.hxx"
22 #include <svl/eitem.hxx>
23 #include <svx/dialogs.hrc>
24 #include <svx/svdglue.hxx>
25 #include <sfx2/request.hxx>
28 #include "app.hrc"
29 #include "strings.hrc"
30 #include "res_bmp.hrc"
31 #include "Window.hxx"
32 #include "drawdoc.hxx"
33 #include "FrameView.hxx"
34 #include "View.hxx"
35 #include "ViewShell.hxx"
36 #include "ViewShellBase.hxx"
37 #include "ToolBarManager.hxx"
39 namespace sd {
41 TYPEINIT1( FuEditGluePoints, FuDraw );
44 FuEditGluePoints::FuEditGluePoints (
45 ViewShell* pViewSh,
46 ::sd::Window* pWin,
47 ::sd::View* pView,
48 SdDrawDocument* pDoc,
49 SfxRequest& rReq)
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 );
60 return xFunc;
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()
75 mpView->BrkAction();
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())
89 if (rMEvt.IsRight())
90 mpView->BckAction();
92 return sal_True;
95 if (rMEvt.IsLeft())
97 bReturn = sal_True;
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();
102 SdrViewEvent aVEvt;
103 SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
105 if (eHit == SDRHIT_HANDLE)
107 // drag 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);
113 pHdl = NULL;
116 if (pHdl)
118 // drag handle
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())
137 // move object
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);
149 if (pHdl)
151 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
154 else
156 // select or drag object
157 if (!rMEvt.IsShift() && !rMEvt.IsMod2() && eHit == SDRHIT_UNMARKEDOBJECT)
159 mpView->UnmarkAllObj();
162 sal_Bool bMarked = sal_False;
164 if (!rMEvt.IsMod1())
166 if (rMEvt.IsMod2())
168 bMarked = mpView->MarkNextObj(aMDPos, nHitLog, rMEvt.IsShift());
170 else
172 bMarked = mpView->MarkObj(aMDPos, nHitLog, rMEvt.IsShift());
176 if (bMarked &&
177 (!rMEvt.IsShift() || eHit == SDRHIT_MARKEDOBJECT))
179 // move object
180 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
182 else if (mpView->AreObjectsMarked())
184 // select glue point
185 if (!rMEvt.IsShift())
186 mpView->UnmarkAllGluePoints();
188 mpView->BegMarkGluePoints(aMDPos);
190 else
192 // select object
193 mpView->BegMarkObj(aMDPos);
197 ForcePointer(&rMEvt);
200 return bReturn;
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) );
214 ForceScroll(aPix);
215 mpView->MovAction(aPnt);
218 ForcePointer(&rMEvt);
220 return sal_True;
224 sal_Bool FuEditGluePoints::MouseButtonUp(const MouseEvent& rMEvt)
226 mpView->SetActualWin( mpWindow );
228 sal_Bool bReturn = sal_False;
230 if (mpView->IsAction())
232 bReturn = sal_True;
233 mpView->EndAction();
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())
245 SdrViewEvent aVEvt;
246 SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
248 if (eHit == SDRHIT_NONE)
250 // click on position: deselect
251 mpView->UnmarkAllObj();
255 mpWindow->ReleaseMouse();
257 return bReturn;
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);
270 return bReturn;
274 sal_Bool FuEditGluePoints::Command(const CommandEvent& rCEvt)
276 mpView->SetActualWin( mpWindow );
277 return FuPoor::Command( rCEvt );
281 void FuEditGluePoints::Activate()
283 mpView->SetGluePointEditMode();
284 FuDraw::Activate();
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());
303 break;
305 case SID_GLUE_ESCDIR_LEFT:
307 mpView->SetMarkedGluePointsEscDir( SDRESC_LEFT,
308 !mpView->IsMarkedGluePointsEscDir( SDRESC_LEFT ) );
310 break;
312 case SID_GLUE_ESCDIR_RIGHT:
314 mpView->SetMarkedGluePointsEscDir( SDRESC_RIGHT,
315 !mpView->IsMarkedGluePointsEscDir( SDRESC_RIGHT ) );
317 break;
319 case SID_GLUE_ESCDIR_TOP:
321 mpView->SetMarkedGluePointsEscDir( SDRESC_TOP,
322 !mpView->IsMarkedGluePointsEscDir( SDRESC_TOP ) );
324 break;
326 case SID_GLUE_ESCDIR_BOTTOM:
328 mpView->SetMarkedGluePointsEscDir( SDRESC_BOTTOM,
329 !mpView->IsMarkedGluePointsEscDir( SDRESC_BOTTOM ) );
331 break;
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);
340 break;
342 case SID_GLUE_HORZALIGN_CENTER:
344 mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_CENTER);
346 break;
348 case SID_GLUE_HORZALIGN_LEFT:
350 mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_LEFT);
352 break;
354 case SID_GLUE_HORZALIGN_RIGHT:
356 mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_RIGHT);
358 break;
360 case SID_GLUE_VERTALIGN_CENTER:
362 mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_CENTER);
364 break;
366 case SID_GLUE_VERTALIGN_TOP:
368 mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_TOP);
370 break;
372 case SID_GLUE_VERTALIGN_BOTTOM:
374 mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_BOTTOM);
376 break;
379 // at the end, call base class
380 FuPoor::ReceiveRequest(rReq);
384 } // end of namespace sd
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */