1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fusnapln.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "fusnapln.hxx"
35 #include <svtools/aeitem.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <sfx2/request.hxx>
40 #include "strings.hrc"
44 #include "ViewShell.hxx"
45 #include "DrawViewShell.hxx"
46 #ifndef SD_WINDOW_SHELL_HXX
49 #include "sdenumdef.hxx"
50 #include "sdresid.hxx"
51 #include "sdabstdlg.hxx"
53 #include <svx/svdpagv.hxx>
57 TYPEINIT1( FuSnapLine
, FuPoor
);
59 /*************************************************************************
63 \************************************************************************/
65 FuSnapLine::FuSnapLine(ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
66 SdDrawDocument
* pDoc
, SfxRequest
& rReq
) :
67 FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
71 FunctionReference
FuSnapLine::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
73 FunctionReference
xFunc( new FuSnapLine( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
74 xFunc
->DoExecute(rReq
);
78 void FuSnapLine::DoExecute( SfxRequest
& rReq
)
80 const SfxItemSet
* pArgs
= rReq
.GetArgs();
83 BOOL bCreateNew
= TRUE
;
85 // Get index of snap line or snap point from the request.
86 SFX_REQUEST_ARG (rReq
, pHelpLineIndex
, SfxUInt32Item
, ID_VAL_INDEX
, FALSE
);
87 if (pHelpLineIndex
!= NULL
)
89 nHelpLine
= static_cast<USHORT
>(pHelpLineIndex
->GetValue());
90 // Reset the argument pointer to trigger the display of the dialog.
96 SfxItemSet
aNewAttr(mpViewShell
->GetPool(), ATTR_SNAPLINE_START
, ATTR_SNAPLINE_END
);
97 bool bLineExist (false);
98 pPV
= mpView
->GetSdrPageView();
101 if (pHelpLineIndex
== NULL
)
103 // The index of the snap line is not provided as argument to the
104 // request. Determine it from the mouse position.
106 aLinePos
= static_cast<DrawViewShell
*>(mpViewShell
)->GetMousePos();
107 static_cast<DrawViewShell
*>(mpViewShell
)->SetMousePosFreezed( FALSE
);
110 if ( aLinePos
.X() >= 0 )
112 aLinePos
= mpWindow
->PixelToLogic(aLinePos
);
113 USHORT nHitLog
= (USHORT
) mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width();
114 bLineExist
= mpView
->PickHelpLine(aLinePos
, nHitLog
, *mpWindow
, nHelpLine
, pPV
);
116 aLinePos
= (pPV
->GetHelpLines())[nHelpLine
].GetPos();
118 pPV
= mpView
->GetSdrPageView();
120 pPV
->LogicToPagePos(aLinePos
);
123 aLinePos
= Point(0,0);
127 OSL_ASSERT(pPV
!=NULL
);
128 aLinePos
= (pPV
->GetHelpLines())[nHelpLine
].GetPos();
131 aNewAttr
.Put(SfxUInt32Item(ATTR_SNAPLINE_X
, aLinePos
.X()));
132 aNewAttr
.Put(SfxUInt32Item(ATTR_SNAPLINE_Y
, aLinePos
.Y()));
134 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
135 AbstractSdSnapLineDlg
* pDlg
= pFact
? pFact
->CreateSdSnapLineDlg( NULL
, aNewAttr
, mpView
) : 0;
140 pDlg
->HideRadioGroup();
142 const SdrHelpLine
& rHelpLine
= (pPV
->GetHelpLines())[nHelpLine
];
144 if ( rHelpLine
.GetKind() == SDRHELPLINE_POINT
)
146 pDlg
->SetText(String(SdResId(STR_SNAPDLG_SETPOINT
)));
147 pDlg
->SetInputFields(TRUE
, TRUE
);
151 pDlg
->SetText(String(SdResId(STR_SNAPDLG_SETLINE
)));
153 if ( rHelpLine
.GetKind() == SDRHELPLINE_VERTICAL
)
154 pDlg
->SetInputFields(TRUE
, FALSE
);
156 pDlg
->SetInputFields(FALSE
, TRUE
);
161 pDlg
->HideDeleteBtn();
163 USHORT nResult
= pDlg
->Execute();
165 pDlg
->GetAttr(aNewAttr
);
172 pArgs
= rReq
.GetArgs();
175 case RET_SNAP_DELETE
:
176 // Fangobjekt loeschen
178 pPV
->DeleteHelpLine(nHelpLine
);
179 // und weiter wie bei default
187 aHlpPos
.X() = ((const SfxUInt32Item
&) pArgs
->Get(ATTR_SNAPLINE_X
)).GetValue();
188 aHlpPos
.Y() = ((const SfxUInt32Item
&) pArgs
->Get(ATTR_SNAPLINE_Y
)).GetValue();
189 pPV
->PagePosToLogic(aHlpPos
);
193 SdrHelpLineKind eKind
;
195 pPV
= mpView
->GetSdrPageView();
197 switch ( (SnapKind
) ((const SfxAllEnumItem
&)
198 pArgs
->Get(ATTR_SNAPLINE_KIND
)).GetValue() )
200 case SK_HORIZONTAL
: eKind
= SDRHELPLINE_HORIZONTAL
; break;
201 case SK_VERTICAL
: eKind
= SDRHELPLINE_VERTICAL
; break;
202 default : eKind
= SDRHELPLINE_POINT
; break;
204 pPV
->InsertHelpLine(SdrHelpLine(eKind
, aHlpPos
));
208 const SdrHelpLine
& rHelpLine
= (pPV
->GetHelpLines())[nHelpLine
];
209 pPV
->SetHelpLine(nHelpLine
, SdrHelpLine(rHelpLine
.GetKind(), aHlpPos
));
213 void FuSnapLine::Activate()
217 void FuSnapLine::Deactivate()
221 } // end of namespace sd