merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / func / fusnapln.cxx
blobca271774f9f08d80897b1edbe52a776aac3bba0f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fusnapln.cxx,v $
10 * $Revision: 1.9 $
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"
42 #include "sdattr.hxx"
43 #include "View.hxx"
44 #include "ViewShell.hxx"
45 #include "DrawViewShell.hxx"
46 #ifndef SD_WINDOW_SHELL_HXX
47 #include "Window.hxx"
48 #endif
49 #include "sdenumdef.hxx"
50 #include "sdresid.hxx"
51 #include "sdabstdlg.hxx"
52 #include "app.hrc"
53 #include <svx/svdpagv.hxx>
55 namespace sd {
57 TYPEINIT1( FuSnapLine, FuPoor );
59 /*************************************************************************
61 |* Konstruktor
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);
75 return xFunc;
78 void FuSnapLine::DoExecute( SfxRequest& rReq )
80 const SfxItemSet* pArgs = rReq.GetArgs();
81 SdrPageView* pPV = 0;
82 USHORT nHelpLine = 0;
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.
91 pArgs = NULL;
94 if ( !pArgs )
96 SfxItemSet aNewAttr(mpViewShell->GetPool(), ATTR_SNAPLINE_START, ATTR_SNAPLINE_END);
97 bool bLineExist (false);
98 pPV = mpView->GetSdrPageView();
99 Point aLinePos;
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);
115 if ( bLineExist )
116 aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
117 else
118 pPV = mpView->GetSdrPageView();
120 pPV->LogicToPagePos(aLinePos);
122 else
123 aLinePos = Point(0,0);
125 else
127 OSL_ASSERT(pPV!=NULL);
128 aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
129 bLineExist = true;
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;
136 if( pDlg )
138 if ( bLineExist )
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);
149 else
151 pDlg->SetText(String(SdResId(STR_SNAPDLG_SETLINE)));
153 if ( rHelpLine.GetKind() == SDRHELPLINE_VERTICAL )
154 pDlg->SetInputFields(TRUE, FALSE);
155 else
156 pDlg->SetInputFields(FALSE, TRUE);
158 bCreateNew = FALSE;
160 else
161 pDlg->HideDeleteBtn();
163 USHORT nResult = pDlg->Execute();
165 pDlg->GetAttr(aNewAttr);
166 delete pDlg;
168 switch( nResult )
170 case RET_OK:
171 rReq.Done(aNewAttr);
172 pArgs = rReq.GetArgs();
173 break;
175 case RET_SNAP_DELETE:
176 // Fangobjekt loeschen
177 if ( !bCreateNew )
178 pPV->DeleteHelpLine(nHelpLine);
179 // und weiter wie bei default
180 default:
181 return;
185 Point aHlpPos;
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);
191 if ( bCreateNew )
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));
206 else
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