Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fusnapln.cxx
bloba4719be2bcf96ea6d6d50bd2520c332393d89a99
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 .
20 #include <fusnapln.hxx>
21 #include <svl/aeitem.hxx>
22 #include <sfx2/request.hxx>
23 #include <svx/svxids.hrc>
25 #include <strings.hrc>
27 #include <sdattr.hxx>
28 #include <View.hxx>
29 #include <ViewShell.hxx>
30 #include <DrawViewShell.hxx>
31 #include <Window.hxx>
32 #include <sdenumdef.hxx>
33 #include <sdresid.hxx>
34 #include <sdabstdlg.hxx>
35 #include <app.hrc>
36 #include <svx/svdpagv.hxx>
37 #include <memory>
39 namespace sd {
42 FuSnapLine::FuSnapLine(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
43 SdDrawDocument* pDoc, SfxRequest& rReq) :
44 FuPoor(pViewSh, pWin, pView, pDoc, rReq)
48 rtl::Reference<FuPoor> FuSnapLine::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
50 rtl::Reference<FuPoor> xFunc( new FuSnapLine( pViewSh, pWin, pView, pDoc, rReq ) );
51 xFunc->DoExecute(rReq);
52 return xFunc;
55 void FuSnapLine::DoExecute( SfxRequest& rReq )
57 const SfxItemSet* pArgs = rReq.GetArgs();
58 sal_uInt16 nHelpLine = 0;
59 bool bCreateNew = true;
61 // Get index of snap line or snap point from the request.
62 const SfxUInt32Item* pHelpLineIndex = rReq.GetArg<SfxUInt32Item>(ID_VAL_INDEX);
63 if (pHelpLineIndex != nullptr)
65 nHelpLine = static_cast<sal_uInt16>(pHelpLineIndex->GetValue());
66 // Reset the argument pointer to trigger the display of the dialog.
67 pArgs = nullptr;
70 SdrPageView* pPV = mpView->GetSdrPageView();
72 if (!pArgs)
74 SfxItemSet aNewAttr(mpViewShell->GetPool(), svl::Items<ATTR_SNAPLINE_START, ATTR_SNAPLINE_END>{});
75 bool bLineExist (false);
76 Point aLinePos;
78 if (pHelpLineIndex == nullptr)
80 // The index of the snap line is not provided as argument to the
81 // request. Determine it from the mouse position.
83 aLinePos = static_cast<DrawViewShell*>(mpViewShell)->GetMousePos();
84 static_cast<DrawViewShell*>(mpViewShell)->SetMousePosFreezed( false );
86 if ( aLinePos.X() >= 0 )
88 aLinePos = mpWindow->PixelToLogic(aLinePos);
89 sal_uInt16 nHitLog = static_cast<sal_uInt16>(mpWindow->PixelToLogic(Size(HITPIX,0)).Width());
90 bLineExist = mpView->PickHelpLine(aLinePos, nHitLog, *mpWindow, nHelpLine, pPV);
91 if ( bLineExist )
92 aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
93 else
94 pPV = mpView->GetSdrPageView();
96 pPV->LogicToPagePos(aLinePos);
98 else
99 aLinePos = Point(0,0);
101 else
103 assert(pPV!=nullptr);
104 aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
105 pPV->LogicToPagePos(aLinePos);
106 bLineExist = true;
108 aNewAttr.Put(SfxInt32Item(ATTR_SNAPLINE_X, aLinePos.X()));
109 aNewAttr.Put(SfxInt32Item(ATTR_SNAPLINE_Y, aLinePos.Y()));
111 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
112 vcl::Window* pWin = mpViewShell->GetActiveWindow();
113 ScopedVclPtr<AbstractSdSnapLineDlg> pDlg(pFact ? pFact->CreateSdSnapLineDlg(pWin ? pWin->GetFrameWeld() : nullptr, aNewAttr, mpView) : nullptr);
114 OSL_ASSERT(pDlg);
115 if (!pDlg)
116 return;
118 if ( bLineExist )
120 pDlg->HideRadioGroup();
122 const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
124 if ( rHelpLine.GetKind() == SdrHelpLineKind::Point )
126 pDlg->SetText(SdResId(STR_SNAPDLG_SETPOINT));
127 pDlg->SetInputFields(true, true);
129 else
131 pDlg->SetText(SdResId(STR_SNAPDLG_SETLINE));
133 if ( rHelpLine.GetKind() == SdrHelpLineKind::Vertical )
134 pDlg->SetInputFields(true, false);
135 else
136 pDlg->SetInputFields(false, true);
138 bCreateNew = false;
140 else
141 pDlg->HideDeleteBtn();
143 sal_uInt16 nResult = pDlg->Execute();
145 pDlg->GetAttr(aNewAttr);
146 pDlg.disposeAndClear();
148 switch( nResult )
150 case RET_OK:
151 rReq.Done(aNewAttr);
152 pArgs = rReq.GetArgs();
153 break;
155 case RET_SNAP_DELETE:
156 // delete snap object
157 if ( !bCreateNew )
158 pPV->DeleteHelpLine(nHelpLine);
159 SAL_FALLTHROUGH;
160 default:
161 return;
164 Point aHlpPos;
166 aHlpPos.setX( static_cast<const SfxInt32Item&>( pArgs->Get(ATTR_SNAPLINE_X)).GetValue() );
167 aHlpPos.setY( static_cast<const SfxInt32Item&>( pArgs->Get(ATTR_SNAPLINE_Y)).GetValue() );
168 pPV->PagePosToLogic(aHlpPos);
170 if ( bCreateNew )
172 SdrHelpLineKind eKind;
174 pPV = mpView->GetSdrPageView();
176 switch ( static_cast<SnapKind>(static_cast<const SfxAllEnumItem&>(
177 pArgs->Get(ATTR_SNAPLINE_KIND)).GetValue()) )
179 case SK_HORIZONTAL : eKind = SdrHelpLineKind::Horizontal; break;
180 case SK_VERTICAL : eKind = SdrHelpLineKind::Vertical; break;
181 default : eKind = SdrHelpLineKind::Point; break;
183 pPV->InsertHelpLine(SdrHelpLine(eKind, aHlpPos));
185 else
187 const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
188 pPV->SetHelpLine(nHelpLine, SdrHelpLine(rHelpLine.GetKind(), aHlpPos));
192 void FuSnapLine::Activate()
196 void FuSnapLine::Deactivate()
200 } // end of namespace sd
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */