android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / func / fusnapln.cxx
blob24808e24a91be2bf907a4090b317606328718aa6
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/intitem.hxx>
22 #include <sfx2/request.hxx>
23 #include <svx/svxids.hrc>
25 #include <strings.hrc>
26 #include <sdattr.hrc>
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 <svx/svdpagv.hxx>
37 namespace sd {
40 FuSnapLine::FuSnapLine(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
41 SdDrawDocument* pDoc, SfxRequest& rReq) :
42 FuPoor(pViewSh, pWin, pView, pDoc, rReq)
46 rtl::Reference<FuPoor> FuSnapLine::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
48 rtl::Reference<FuPoor> xFunc( new FuSnapLine( pViewSh, pWin, pView, pDoc, rReq ) );
49 xFunc->DoExecute(rReq);
50 return xFunc;
53 void FuSnapLine::DoExecute( SfxRequest& rReq )
55 const SfxItemSet* pArgs = rReq.GetArgs();
56 sal_uInt16 nHelpLine = 0;
57 bool bCreateNew = true;
59 // Get index of snap line or snap point from the request.
60 const SfxUInt32Item* pHelpLineIndex = rReq.GetArg<SfxUInt32Item>(ID_VAL_INDEX);
61 if (pHelpLineIndex != nullptr)
63 nHelpLine = static_cast<sal_uInt16>(pHelpLineIndex->GetValue());
64 // Reset the argument pointer to trigger the display of the dialog.
65 pArgs = nullptr;
68 SdrPageView* pPV = mpView->GetSdrPageView();
70 if (!pArgs)
72 SfxItemSetFixed<ATTR_SNAPLINE_START, ATTR_SNAPLINE_END> aNewAttr(mpViewShell->GetPool());
73 bool bLineExist (false);
74 Point aLinePos;
76 if (pHelpLineIndex == nullptr)
78 // The index of the snap line is not provided as argument to the
79 // request. Determine it from the mouse position.
81 aLinePos = static_cast<DrawViewShell*>(mpViewShell)->GetMousePos();
83 if ( aLinePos.X() >= 0 )
85 aLinePos = mpWindow->PixelToLogic(aLinePos);
86 sal_uInt16 nHitLog = static_cast<sal_uInt16>(mpWindow->PixelToLogic(Size(HITPIX,0)).Width());
87 bLineExist = mpView->PickHelpLine(aLinePos, nHitLog, *mpWindow->GetOutDev(), nHelpLine, pPV);
88 if ( bLineExist )
89 aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
90 else
91 pPV = mpView->GetSdrPageView();
93 pPV->LogicToPagePos(aLinePos);
95 else
96 aLinePos = Point(0,0);
98 else
100 assert(pPV!=nullptr);
101 aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
102 pPV->LogicToPagePos(aLinePos);
103 bLineExist = true;
105 aNewAttr.Put(SfxInt32Item(ATTR_SNAPLINE_X, aLinePos.X()));
106 aNewAttr.Put(SfxInt32Item(ATTR_SNAPLINE_Y, aLinePos.Y()));
108 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
109 vcl::Window* pWin = mpViewShell->GetActiveWindow();
110 ScopedVclPtr<AbstractSdSnapLineDlg> pDlg( pFact->CreateSdSnapLineDlg(pWin ? pWin->GetFrameWeld() : nullptr, aNewAttr, mpView) );
112 if ( bLineExist )
114 pDlg->HideRadioGroup();
116 const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
118 if ( rHelpLine.GetKind() == SdrHelpLineKind::Point )
120 pDlg->SetText(SdResId(STR_SNAPDLG_SETPOINT));
121 pDlg->SetInputFields(true, true);
123 else
125 pDlg->SetText(SdResId(STR_SNAPDLG_SETLINE));
127 if ( rHelpLine.GetKind() == SdrHelpLineKind::Vertical )
128 pDlg->SetInputFields(true, false);
129 else
130 pDlg->SetInputFields(false, true);
132 bCreateNew = false;
134 else
135 pDlg->HideDeleteBtn();
137 sal_uInt16 nResult = pDlg->Execute();
139 pDlg->GetAttr(aNewAttr);
140 pDlg.disposeAndClear();
142 switch( nResult )
144 case RET_OK:
145 rReq.Done(aNewAttr);
146 pArgs = rReq.GetArgs();
147 break;
149 case RET_SNAP_DELETE:
150 // delete snap object
151 if ( !bCreateNew )
152 pPV->DeleteHelpLine(nHelpLine);
153 [[fallthrough]];
154 default:
155 return;
158 Point aHlpPos;
160 aHlpPos.setX( pArgs->Get(ATTR_SNAPLINE_X).GetValue() );
161 aHlpPos.setY( pArgs->Get(ATTR_SNAPLINE_Y).GetValue() );
162 pPV->PagePosToLogic(aHlpPos);
164 if ( bCreateNew )
166 SdrHelpLineKind eKind;
168 pPV = mpView->GetSdrPageView();
170 switch ( static_cast<SnapKind>(pArgs->Get(ATTR_SNAPLINE_KIND).GetValue()) )
172 case SnapKind::Horizontal : eKind = SdrHelpLineKind::Horizontal; break;
173 case SnapKind::Vertical : eKind = SdrHelpLineKind::Vertical; break;
174 default : eKind = SdrHelpLineKind::Point; break;
176 pPV->InsertHelpLine(SdrHelpLine(eKind, aHlpPos));
178 else
180 const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
181 pPV->SetHelpLine(nHelpLine, SdrHelpLine(rHelpLine.GetKind(), aHlpPos));
185 void FuSnapLine::Activate()
189 void FuSnapLine::Deactivate()
193 } // end of namespace sd
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */