LibreOffice Module sd (master) 1
fusnapln.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <fusnapln.hxx>
21#include <svl/intitem.hxx>
22#include <sfx2/request.hxx>
23#include <svx/svxids.hrc>
24
25#include <strings.hrc>
26#include <sdattr.hrc>
27
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>
36
37namespace sd {
38
39
41 SdDrawDocument* pDoc, SfxRequest& rReq) :
42 FuPoor(pViewSh, pWin, pView, pDoc, rReq)
43{
44}
45
47{
48 rtl::Reference<FuPoor> xFunc( new FuSnapLine( pViewSh, pWin, pView, pDoc, rReq ) );
49 xFunc->DoExecute(rReq);
50 return xFunc;
51}
52
54{
55 const SfxItemSet* pArgs = rReq.GetArgs();
56 sal_uInt16 nHelpLine = 0;
57 bool bCreateNew = true;
58
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)
62 {
63 nHelpLine = static_cast<sal_uInt16>(pHelpLineIndex->GetValue());
64 // Reset the argument pointer to trigger the display of the dialog.
65 pArgs = nullptr;
66 }
67
69
70 if (!pArgs)
71 {
73 bool bLineExist (false);
74 Point aLinePos;
75
76 if (pHelpLineIndex == nullptr)
77 {
78 // The index of the snap line is not provided as argument to the
79 // request. Determine it from the mouse position.
80
81 aLinePos = static_cast<DrawViewShell*>(mpViewShell)->GetMousePos();
82
83 if ( aLinePos.X() >= 0 )
84 {
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();
92
93 pPV->LogicToPagePos(aLinePos);
94 }
95 else
96 aLinePos = Point(0,0);
97 }
98 else
99 {
100 assert(pPV!=nullptr);
101 aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
102 pPV->LogicToPagePos(aLinePos);
103 bLineExist = true;
104 }
105 aNewAttr.Put(SfxInt32Item(ATTR_SNAPLINE_X, aLinePos.X()));
106 aNewAttr.Put(SfxInt32Item(ATTR_SNAPLINE_Y, aLinePos.Y()));
107
110 ScopedVclPtr<AbstractSdSnapLineDlg> pDlg( pFact->CreateSdSnapLineDlg(pWin ? pWin->GetFrameWeld() : nullptr, aNewAttr, mpView) );
111
112 if ( bLineExist )
113 {
114 pDlg->HideRadioGroup();
115
116 const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
117
118 if ( rHelpLine.GetKind() == SdrHelpLineKind::Point )
119 {
120 pDlg->SetText(SdResId(STR_SNAPDLG_SETPOINT));
121 pDlg->SetInputFields(true, true);
122 }
123 else
124 {
125 pDlg->SetText(SdResId(STR_SNAPDLG_SETLINE));
126
127 if ( rHelpLine.GetKind() == SdrHelpLineKind::Vertical )
128 pDlg->SetInputFields(true, false);
129 else
130 pDlg->SetInputFields(false, true);
131 }
132 bCreateNew = false;
133 }
134 else
135 pDlg->HideDeleteBtn();
136
137 sal_uInt16 nResult = pDlg->Execute();
138
139 pDlg->GetAttr(aNewAttr);
140 pDlg.disposeAndClear();
141
142 switch( nResult )
143 {
144 case RET_OK:
145 rReq.Done(aNewAttr);
146 pArgs = rReq.GetArgs();
147 break;
148
149 case RET_SNAP_DELETE:
150 // delete snap object
151 if ( !bCreateNew )
152 pPV->DeleteHelpLine(nHelpLine);
153 [[fallthrough]];
154 default:
155 return;
156 }
157 }
158 Point aHlpPos;
159
160 aHlpPos.setX( pArgs->Get(ATTR_SNAPLINE_X).GetValue() );
161 aHlpPos.setY( pArgs->Get(ATTR_SNAPLINE_Y).GetValue() );
162 pPV->PagePosToLogic(aHlpPos);
163
164 if ( bCreateNew )
165 {
166 SdrHelpLineKind eKind;
167
168 pPV = mpView->GetSdrPageView();
169
170 switch ( static_cast<SnapKind>(pArgs->Get(ATTR_SNAPLINE_KIND).GetValue()) )
171 {
172 case SnapKind::Horizontal : eKind = SdrHelpLineKind::Horizontal; break;
173 case SnapKind::Vertical : eKind = SdrHelpLineKind::Vertical; break;
174 default : eKind = SdrHelpLineKind::Point; break;
175 }
176 pPV->InsertHelpLine(SdrHelpLine(eKind, aHlpPos));
177 }
178 else
179 {
180 const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
181 pPV->SetHelpLine(nHelpLine, SdrHelpLine(rHelpLine.GetKind(), aHlpPos));
182 }
183}
184
186{
187}
188
190{
191}
192
193} // end of namespace sd
194
195/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt32 GetValue() const
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
constexpr tools::Long X() const
virtual VclPtr< AbstractSdSnapLineDlg > CreateSdSnapLineDlg(weld::Window *pParent, const SfxItemSet &rInAttrs, ::sd::View *pView)=0
static SD_DLLPUBLIC SdAbstractDialogFactory * Create()
Definition: sdabstdlg.cxx:38
SdrHelpLineKind GetKind() const
void LogicToPagePos(Point &rPnt) const
void PagePosToLogic(Point &rPnt) const
const SdrHelpLineList & GetHelpLines() const
void DeleteHelpLine(sal_uInt16 nNum)
void SetHelpLine(sal_uInt16 nNum, const SdrHelpLine &rNewHelpLine)
void InsertHelpLine(const SdrHelpLine &rHL)
SdrPageView * GetSdrPageView() const
bool PickHelpLine(const Point &rPnt, short nTol, const OutputDevice &rOut, sal_uInt16 &rnHelpLineNum, SdrPageView *&rpPV) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
void Done(bool bRemove=false)
SfxItemPool & GetPool() const
void disposeAndClear()
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
Base class for all functions.
Definition: fupoor.hxx:48
VclPtr< ::sd::Window > mpWindow
Definition: fupoor.hxx:146
ViewShell * mpViewShell
Definition: fupoor.hxx:145
::sd::View * mpView
Definition: fupoor.hxx:144
static const int HITPIX
Definition: fupoor.hxx:50
virtual void DoExecute(SfxRequest &rReq) override
Definition: fusnapln.cxx:53
virtual void Deactivate() override
deactivates the function
Definition: fusnapln.cxx:189
virtual void Activate() override
activates the function
Definition: fusnapln.cxx:185
FuSnapLine(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fusnapln.cxx:40
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fusnapln.cxx:46
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
::sd::Window * GetActiveWindow() const
The active window is usually the mpContentWindow.
Definition: ViewShell.hxx:155
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
weld::Window * GetFrameWeld() const
#define RET_SNAP_DELETE
Definition: sdenumdef.hxx:22
SnapKind
Definition: sdenumdef.hxx:25
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
SdrHelpLineKind
RET_OK