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 <vcl/msgbox.hxx>
23 #include <sfx2/request.hxx>
25 #include "strings.hrc"
29 #include "ViewShell.hxx"
30 #include "DrawViewShell.hxx"
32 #include "sdenumdef.hxx"
33 #include "sdresid.hxx"
34 #include "sdabstdlg.hxx"
36 #include <svx/svdpagv.hxx>
37 #include <boost/scoped_ptr.hpp>
41 TYPEINIT1( FuSnapLine
, FuPoor
);
43 FuSnapLine::FuSnapLine(ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
44 SdDrawDocument
* pDoc
, SfxRequest
& rReq
) :
45 FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
49 rtl::Reference
<FuPoor
> FuSnapLine::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
51 rtl::Reference
<FuPoor
> xFunc( new FuSnapLine( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
52 xFunc
->DoExecute(rReq
);
56 void FuSnapLine::DoExecute( SfxRequest
& rReq
)
58 const SfxItemSet
* pArgs
= rReq
.GetArgs();
59 sal_uInt16 nHelpLine
= 0;
60 bool bCreateNew
= true;
62 // Get index of snap line or snap point from the request.
63 SFX_REQUEST_ARG (rReq
, pHelpLineIndex
, SfxUInt32Item
, ID_VAL_INDEX
, false);
64 if (pHelpLineIndex
!= NULL
)
66 nHelpLine
= static_cast<sal_uInt16
>(pHelpLineIndex
->GetValue());
67 // Reset the argument pointer to trigger the display of the dialog.
71 SdrPageView
* pPV
= mpView
->GetSdrPageView();
75 SfxItemSet
aNewAttr(mpViewShell
->GetPool(), ATTR_SNAPLINE_START
, ATTR_SNAPLINE_END
);
76 bool bLineExist (false);
79 if (pHelpLineIndex
== NULL
)
81 // The index of the snap line is not provided as argument to the
82 // request. Determine it from the mouse position.
84 aLinePos
= static_cast<DrawViewShell
*>(mpViewShell
)->GetMousePos();
85 static_cast<DrawViewShell
*>(mpViewShell
)->SetMousePosFreezed( false );
87 if ( aLinePos
.X() >= 0 )
89 aLinePos
= mpWindow
->PixelToLogic(aLinePos
);
90 sal_uInt16 nHitLog
= (sal_uInt16
) mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width();
91 bLineExist
= mpView
->PickHelpLine(aLinePos
, nHitLog
, *mpWindow
, nHelpLine
, pPV
);
93 aLinePos
= (pPV
->GetHelpLines())[nHelpLine
].GetPos();
95 pPV
= mpView
->GetSdrPageView();
97 pPV
->LogicToPagePos(aLinePos
);
100 aLinePos
= Point(0,0);
105 aLinePos
= (pPV
->GetHelpLines())[nHelpLine
].GetPos();
106 pPV
->LogicToPagePos(aLinePos
);
109 aNewAttr
.Put(SfxInt32Item(ATTR_SNAPLINE_X
, aLinePos
.X()));
110 aNewAttr
.Put(SfxInt32Item(ATTR_SNAPLINE_Y
, aLinePos
.Y()));
112 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
113 boost::scoped_ptr
<AbstractSdSnapLineDlg
> pDlg(pFact
? pFact
->CreateSdSnapLineDlg( NULL
, aNewAttr
, mpView
) : 0);
120 pDlg
->HideRadioGroup();
122 const SdrHelpLine
& rHelpLine
= (pPV
->GetHelpLines())[nHelpLine
];
124 if ( rHelpLine
.GetKind() == SDRHELPLINE_POINT
)
126 pDlg
->SetText(SD_RESSTR(STR_SNAPDLG_SETPOINT
));
127 pDlg
->SetInputFields(true, true);
131 pDlg
->SetText(SD_RESSTR(STR_SNAPDLG_SETLINE
));
133 if ( rHelpLine
.GetKind() == SDRHELPLINE_VERTICAL
)
134 pDlg
->SetInputFields(true, false);
136 pDlg
->SetInputFields(false, true);
141 pDlg
->HideDeleteBtn();
143 sal_uInt16 nResult
= pDlg
->Execute();
145 pDlg
->GetAttr(aNewAttr
);
152 pArgs
= rReq
.GetArgs();
155 case RET_SNAP_DELETE
:
156 // delete snap object
158 pPV
->DeleteHelpLine(nHelpLine
);
166 aHlpPos
.X() = static_cast<const SfxInt32Item
&>( pArgs
->Get(ATTR_SNAPLINE_X
)).GetValue();
167 aHlpPos
.Y() = static_cast<const SfxInt32Item
&>( pArgs
->Get(ATTR_SNAPLINE_Y
)).GetValue();
168 pPV
->PagePosToLogic(aHlpPos
);
172 SdrHelpLineKind eKind
;
174 pPV
= mpView
->GetSdrPageView();
176 switch ( (SnapKind
) static_cast<const SfxAllEnumItem
&>(
177 pArgs
->Get(ATTR_SNAPLINE_KIND
)).GetValue() )
179 case SK_HORIZONTAL
: eKind
= SDRHELPLINE_HORIZONTAL
; break;
180 case SK_VERTICAL
: eKind
= SDRHELPLINE_VERTICAL
; break;
181 default : eKind
= SDRHELPLINE_POINT
; break;
183 pPV
->InsertHelpLine(SdrHelpLine(eKind
, aHlpPos
));
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: */