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 .
21 #include "fusnapln.hxx"
22 #include <svl/aeitem.hxx>
23 #include <vcl/msgbox.hxx>
24 #include <sfx2/request.hxx>
27 #include "strings.hrc"
31 #include "ViewShell.hxx"
32 #include "DrawViewShell.hxx"
34 #include "sdenumdef.hxx"
35 #include "sdresid.hxx"
36 #include "sdabstdlg.hxx"
38 #include <svx/svdpagv.hxx>
42 TYPEINIT1( FuSnapLine
, FuPoor
);
44 FuSnapLine::FuSnapLine(ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
45 SdDrawDocument
* pDoc
, SfxRequest
& rReq
) :
46 FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
50 FunctionReference
FuSnapLine::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
52 FunctionReference
xFunc( new FuSnapLine( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
53 xFunc
->DoExecute(rReq
);
57 void FuSnapLine::DoExecute( SfxRequest
& rReq
)
59 const SfxItemSet
* pArgs
= rReq
.GetArgs();
60 sal_uInt16 nHelpLine
= 0;
61 sal_Bool bCreateNew
= sal_True
;
63 // Get index of snap line or snap point from the request.
64 SFX_REQUEST_ARG (rReq
, pHelpLineIndex
, SfxUInt32Item
, ID_VAL_INDEX
, sal_False
);
65 if (pHelpLineIndex
!= NULL
)
67 nHelpLine
= static_cast<sal_uInt16
>(pHelpLineIndex
->GetValue());
68 // Reset the argument pointer to trigger the display of the dialog.
72 SdrPageView
* pPV
= mpView
->GetSdrPageView();
76 SfxItemSet
aNewAttr(mpViewShell
->GetPool(), ATTR_SNAPLINE_START
, ATTR_SNAPLINE_END
);
77 bool bLineExist (false);
80 if (pHelpLineIndex
== NULL
)
82 // The index of the snap line is not provided as argument to the
83 // request. Determine it from the mouse position.
85 aLinePos
= static_cast<DrawViewShell
*>(mpViewShell
)->GetMousePos();
86 static_cast<DrawViewShell
*>(mpViewShell
)->SetMousePosFreezed( sal_False
);
89 if ( aLinePos
.X() >= 0 )
91 aLinePos
= mpWindow
->PixelToLogic(aLinePos
);
92 sal_uInt16 nHitLog
= (sal_uInt16
) mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width();
93 bLineExist
= mpView
->PickHelpLine(aLinePos
, nHitLog
, *mpWindow
, nHelpLine
, pPV
);
95 aLinePos
= (pPV
->GetHelpLines())[nHelpLine
].GetPos();
97 pPV
= mpView
->GetSdrPageView();
99 pPV
->LogicToPagePos(aLinePos
);
102 aLinePos
= Point(0,0);
106 OSL_ASSERT(pPV
!=NULL
);
107 aLinePos
= (pPV
->GetHelpLines())[nHelpLine
].GetPos();
108 pPV
->LogicToPagePos(aLinePos
);
111 aNewAttr
.Put(SfxUInt32Item(ATTR_SNAPLINE_X
, aLinePos
.X()));
112 aNewAttr
.Put(SfxUInt32Item(ATTR_SNAPLINE_Y
, aLinePos
.Y()));
114 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
115 AbstractSdSnapLineDlg
* pDlg
= pFact
? pFact
->CreateSdSnapLineDlg( NULL
, aNewAttr
, mpView
) : 0;
122 pDlg
->HideRadioGroup();
124 const SdrHelpLine
& rHelpLine
= (pPV
->GetHelpLines())[nHelpLine
];
126 if ( rHelpLine
.GetKind() == SDRHELPLINE_POINT
)
128 pDlg
->SetText(String(SdResId(STR_SNAPDLG_SETPOINT
)));
129 pDlg
->SetInputFields(sal_True
, sal_True
);
133 pDlg
->SetText(String(SdResId(STR_SNAPDLG_SETLINE
)));
135 if ( rHelpLine
.GetKind() == SDRHELPLINE_VERTICAL
)
136 pDlg
->SetInputFields(sal_True
, sal_False
);
138 pDlg
->SetInputFields(sal_False
, sal_True
);
140 bCreateNew
= sal_False
;
143 pDlg
->HideDeleteBtn();
145 sal_uInt16 nResult
= pDlg
->Execute();
147 pDlg
->GetAttr(aNewAttr
);
154 pArgs
= rReq
.GetArgs();
157 case RET_SNAP_DELETE
:
158 // delete snap object
160 pPV
->DeleteHelpLine(nHelpLine
);
168 aHlpPos
.X() = ((const SfxUInt32Item
&) pArgs
->Get(ATTR_SNAPLINE_X
)).GetValue();
169 aHlpPos
.Y() = ((const SfxUInt32Item
&) pArgs
->Get(ATTR_SNAPLINE_Y
)).GetValue();
170 pPV
->PagePosToLogic(aHlpPos
);
174 SdrHelpLineKind eKind
;
176 pPV
= mpView
->GetSdrPageView();
178 switch ( (SnapKind
) ((const SfxAllEnumItem
&)
179 pArgs
->Get(ATTR_SNAPLINE_KIND
)).GetValue() )
181 case SK_HORIZONTAL
: eKind
= SDRHELPLINE_HORIZONTAL
; break;
182 case SK_VERTICAL
: eKind
= SDRHELPLINE_VERTICAL
; break;
183 default : eKind
= SDRHELPLINE_POINT
; break;
185 pPV
->InsertHelpLine(SdrHelpLine(eKind
, aHlpPos
));
189 const SdrHelpLine
& rHelpLine
= (pPV
->GetHelpLines())[nHelpLine
];
190 pPV
->SetHelpLine(nHelpLine
, SdrHelpLine(rHelpLine
.GetKind(), aHlpPos
));
194 void FuSnapLine::Activate()
198 void FuSnapLine::Deactivate()
202 } // end of namespace sd
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */