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 .
20 #include <fusnapln.hxx>
21 #include <svl/aeitem.hxx>
22 #include <svl/intitem.hxx>
23 #include <sfx2/request.hxx>
24 #include <svx/svxids.hrc>
26 #include <strings.hrc>
30 #include <ViewShell.hxx>
31 #include <DrawViewShell.hxx>
33 #include <sdenumdef.hxx>
34 #include <sdresid.hxx>
35 #include <sdabstdlg.hxx>
36 #include <svx/svdpagv.hxx>
41 FuSnapLine::FuSnapLine(ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
42 SdDrawDocument
* pDoc
, SfxRequest
& rReq
) :
43 FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
47 rtl::Reference
<FuPoor
> FuSnapLine::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
49 rtl::Reference
<FuPoor
> xFunc( new FuSnapLine( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
50 xFunc
->DoExecute(rReq
);
54 void FuSnapLine::DoExecute( SfxRequest
& rReq
)
56 const SfxItemSet
* pArgs
= rReq
.GetArgs();
57 sal_uInt16 nHelpLine
= 0;
58 bool bCreateNew
= true;
60 // Get index of snap line or snap point from the request.
61 const SfxUInt32Item
* pHelpLineIndex
= rReq
.GetArg
<SfxUInt32Item
>(ID_VAL_INDEX
);
62 if (pHelpLineIndex
!= nullptr)
64 nHelpLine
= static_cast<sal_uInt16
>(pHelpLineIndex
->GetValue());
65 // Reset the argument pointer to trigger the display of the dialog.
69 SdrPageView
* pPV
= mpView
->GetSdrPageView();
73 SfxItemSet
aNewAttr(mpViewShell
->GetPool(), svl::Items
<ATTR_SNAPLINE_START
, ATTR_SNAPLINE_END
>{});
74 bool bLineExist (false);
77 if (pHelpLineIndex
== nullptr)
79 // The index of the snap line is not provided as argument to the
80 // request. Determine it from the mouse position.
82 aLinePos
= static_cast<DrawViewShell
*>(mpViewShell
)->GetMousePos();
83 static_cast<DrawViewShell
*>(mpViewShell
)->SetMousePosFreezed( false );
85 if ( aLinePos
.X() >= 0 )
87 aLinePos
= mpWindow
->PixelToLogic(aLinePos
);
88 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width());
89 bLineExist
= mpView
->PickHelpLine(aLinePos
, nHitLog
, *mpWindow
, nHelpLine
, pPV
);
91 aLinePos
= (pPV
->GetHelpLines())[nHelpLine
].GetPos();
93 pPV
= mpView
->GetSdrPageView();
95 pPV
->LogicToPagePos(aLinePos
);
98 aLinePos
= Point(0,0);
102 assert(pPV
!=nullptr);
103 aLinePos
= (pPV
->GetHelpLines())[nHelpLine
].GetPos();
104 pPV
->LogicToPagePos(aLinePos
);
107 aNewAttr
.Put(SfxInt32Item(ATTR_SNAPLINE_X
, aLinePos
.X()));
108 aNewAttr
.Put(SfxInt32Item(ATTR_SNAPLINE_Y
, aLinePos
.Y()));
110 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
111 vcl::Window
* pWin
= mpViewShell
->GetActiveWindow();
112 ScopedVclPtr
<AbstractSdSnapLineDlg
> pDlg( pFact
->CreateSdSnapLineDlg(pWin
? pWin
->GetFrameWeld() : nullptr, aNewAttr
, mpView
) );
116 pDlg
->HideRadioGroup();
118 const SdrHelpLine
& rHelpLine
= (pPV
->GetHelpLines())[nHelpLine
];
120 if ( rHelpLine
.GetKind() == SdrHelpLineKind::Point
)
122 pDlg
->SetText(SdResId(STR_SNAPDLG_SETPOINT
));
123 pDlg
->SetInputFields(true, true);
127 pDlg
->SetText(SdResId(STR_SNAPDLG_SETLINE
));
129 if ( rHelpLine
.GetKind() == SdrHelpLineKind::Vertical
)
130 pDlg
->SetInputFields(true, false);
132 pDlg
->SetInputFields(false, true);
137 pDlg
->HideDeleteBtn();
139 sal_uInt16 nResult
= pDlg
->Execute();
141 pDlg
->GetAttr(aNewAttr
);
142 pDlg
.disposeAndClear();
148 pArgs
= rReq
.GetArgs();
151 case RET_SNAP_DELETE
:
152 // delete snap object
154 pPV
->DeleteHelpLine(nHelpLine
);
162 aHlpPos
.setX( static_cast<const SfxInt32Item
&>( pArgs
->Get(ATTR_SNAPLINE_X
)).GetValue() );
163 aHlpPos
.setY( static_cast<const SfxInt32Item
&>( pArgs
->Get(ATTR_SNAPLINE_Y
)).GetValue() );
164 pPV
->PagePosToLogic(aHlpPos
);
168 SdrHelpLineKind eKind
;
170 pPV
= mpView
->GetSdrPageView();
172 switch ( static_cast<SnapKind
>(static_cast<const SfxAllEnumItem
&>(
173 pArgs
->Get(ATTR_SNAPLINE_KIND
)).GetValue()) )
175 case SK_HORIZONTAL
: eKind
= SdrHelpLineKind::Horizontal
; break;
176 case SK_VERTICAL
: eKind
= SdrHelpLineKind::Vertical
; break;
177 default : eKind
= SdrHelpLineKind::Point
; break;
179 pPV
->InsertHelpLine(SdrHelpLine(eKind
, aHlpPos
));
183 const SdrHelpLine
& rHelpLine
= (pPV
->GetHelpLines())[nHelpLine
];
184 pPV
->SetHelpLine(nHelpLine
, SdrHelpLine(rHelpLine
.GetKind(), aHlpPos
));
188 void FuSnapLine::Activate()
192 void FuSnapLine::Deactivate()
196 } // end of namespace sd
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */