xref: /aoo41x/main/sd/source/ui/func/fusnapln.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "fusnapln.hxx"
32*cdf0e10cSrcweir #include <svl/aeitem.hxx>
33*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
34*cdf0e10cSrcweir #include <sfx2/request.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "strings.hrc"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "sdattr.hxx"
40*cdf0e10cSrcweir #include "View.hxx"
41*cdf0e10cSrcweir #include "ViewShell.hxx"
42*cdf0e10cSrcweir #include "DrawViewShell.hxx"
43*cdf0e10cSrcweir #ifndef SD_WINDOW_SHELL_HXX
44*cdf0e10cSrcweir #include "Window.hxx"
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #include "sdenumdef.hxx"
47*cdf0e10cSrcweir #include "sdresid.hxx"
48*cdf0e10cSrcweir #include "sdabstdlg.hxx"
49*cdf0e10cSrcweir #include "app.hrc"
50*cdf0e10cSrcweir #include <svx/svdpagv.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir namespace sd {
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir TYPEINIT1( FuSnapLine, FuPoor );
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir /*************************************************************************
57*cdf0e10cSrcweir |*
58*cdf0e10cSrcweir |* Konstruktor
59*cdf0e10cSrcweir |*
60*cdf0e10cSrcweir \************************************************************************/
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir FuSnapLine::FuSnapLine(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
63*cdf0e10cSrcweir 					   SdDrawDocument* pDoc, SfxRequest& rReq) :
64*cdf0e10cSrcweir 	FuPoor(pViewSh, pWin, pView, pDoc, rReq)
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir FunctionReference FuSnapLine::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir 	FunctionReference xFunc( new FuSnapLine( pViewSh, pWin, pView, pDoc, rReq ) );
71*cdf0e10cSrcweir 	xFunc->DoExecute(rReq);
72*cdf0e10cSrcweir 	return xFunc;
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir void FuSnapLine::DoExecute( SfxRequest& rReq )
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir 	const SfxItemSet* pArgs = rReq.GetArgs();
78*cdf0e10cSrcweir 	SdrPageView* pPV = 0;
79*cdf0e10cSrcweir 	sal_uInt16	nHelpLine = 0;
80*cdf0e10cSrcweir 	sal_Bool	bCreateNew = sal_True;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     // Get index of snap line or snap point from the request.
83*cdf0e10cSrcweir     SFX_REQUEST_ARG (rReq, pHelpLineIndex, SfxUInt32Item, ID_VAL_INDEX, sal_False);
84*cdf0e10cSrcweir     if (pHelpLineIndex != NULL)
85*cdf0e10cSrcweir     {
86*cdf0e10cSrcweir         nHelpLine = static_cast<sal_uInt16>(pHelpLineIndex->GetValue());
87*cdf0e10cSrcweir         // Reset the argument pointer to trigger the display of the dialog.
88*cdf0e10cSrcweir         pArgs = NULL;
89*cdf0e10cSrcweir     }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 	if ( !pArgs )
92*cdf0e10cSrcweir 	{
93*cdf0e10cSrcweir 		SfxItemSet aNewAttr(mpViewShell->GetPool(), ATTR_SNAPLINE_START, ATTR_SNAPLINE_END);
94*cdf0e10cSrcweir         bool bLineExist (false);
95*cdf0e10cSrcweir         pPV = mpView->GetSdrPageView();
96*cdf0e10cSrcweir 		Point aLinePos;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir         if (pHelpLineIndex == NULL)
99*cdf0e10cSrcweir         {
100*cdf0e10cSrcweir             // The index of the snap line is not provided as argument to the
101*cdf0e10cSrcweir             // request.  Determine it from the mouse position.
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir             aLinePos = static_cast<DrawViewShell*>(mpViewShell)->GetMousePos();
104*cdf0e10cSrcweir             static_cast<DrawViewShell*>(mpViewShell)->SetMousePosFreezed( sal_False );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir             if ( aLinePos.X() >= 0 )
108*cdf0e10cSrcweir             {
109*cdf0e10cSrcweir                 aLinePos = mpWindow->PixelToLogic(aLinePos);
110*cdf0e10cSrcweir                 sal_uInt16 nHitLog = (sal_uInt16) mpWindow->PixelToLogic(Size(HITPIX,0)).Width();
111*cdf0e10cSrcweir                 bLineExist = mpView->PickHelpLine(aLinePos, nHitLog, *mpWindow, nHelpLine, pPV);
112*cdf0e10cSrcweir                 if ( bLineExist )
113*cdf0e10cSrcweir                     aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
114*cdf0e10cSrcweir                 else
115*cdf0e10cSrcweir                     pPV = mpView->GetSdrPageView();
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir                 pPV->LogicToPagePos(aLinePos);
118*cdf0e10cSrcweir             }
119*cdf0e10cSrcweir             else
120*cdf0e10cSrcweir                 aLinePos = Point(0,0);
121*cdf0e10cSrcweir         }
122*cdf0e10cSrcweir         else
123*cdf0e10cSrcweir         {
124*cdf0e10cSrcweir             OSL_ASSERT(pPV!=NULL);
125*cdf0e10cSrcweir             aLinePos = (pPV->GetHelpLines())[nHelpLine].GetPos();
126*cdf0e10cSrcweir 			pPV->LogicToPagePos(aLinePos);
127*cdf0e10cSrcweir             bLineExist = true;
128*cdf0e10cSrcweir         }
129*cdf0e10cSrcweir 		aNewAttr.Put(SfxUInt32Item(ATTR_SNAPLINE_X, aLinePos.X()));
130*cdf0e10cSrcweir 		aNewAttr.Put(SfxUInt32Item(ATTR_SNAPLINE_Y, aLinePos.Y()));
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 		SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
133*cdf0e10cSrcweir 		AbstractSdSnapLineDlg* pDlg = pFact ? pFact->CreateSdSnapLineDlg( NULL, aNewAttr, mpView ) : 0;
134*cdf0e10cSrcweir 		if( pDlg )
135*cdf0e10cSrcweir 		{
136*cdf0e10cSrcweir 			if ( bLineExist )
137*cdf0e10cSrcweir 			{
138*cdf0e10cSrcweir 				pDlg->HideRadioGroup();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 				const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 				if ( rHelpLine.GetKind() == SDRHELPLINE_POINT )
143*cdf0e10cSrcweir 				{
144*cdf0e10cSrcweir 					pDlg->SetText(String(SdResId(STR_SNAPDLG_SETPOINT)));
145*cdf0e10cSrcweir 					pDlg->SetInputFields(sal_True, sal_True);
146*cdf0e10cSrcweir 				}
147*cdf0e10cSrcweir 				else
148*cdf0e10cSrcweir 				{
149*cdf0e10cSrcweir 					pDlg->SetText(String(SdResId(STR_SNAPDLG_SETLINE)));
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 					if ( rHelpLine.GetKind() == SDRHELPLINE_VERTICAL )
152*cdf0e10cSrcweir 						pDlg->SetInputFields(sal_True, sal_False);
153*cdf0e10cSrcweir 					else
154*cdf0e10cSrcweir 						pDlg->SetInputFields(sal_False, sal_True);
155*cdf0e10cSrcweir 				}
156*cdf0e10cSrcweir 				bCreateNew = sal_False;
157*cdf0e10cSrcweir 			}
158*cdf0e10cSrcweir 			else
159*cdf0e10cSrcweir 				pDlg->HideDeleteBtn();
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 			sal_uInt16 nResult = pDlg->Execute();
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 			pDlg->GetAttr(aNewAttr);
164*cdf0e10cSrcweir 			delete pDlg;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 			switch( nResult )
167*cdf0e10cSrcweir 			{
168*cdf0e10cSrcweir 				case RET_OK:
169*cdf0e10cSrcweir 					rReq.Done(aNewAttr);
170*cdf0e10cSrcweir 					pArgs = rReq.GetArgs();
171*cdf0e10cSrcweir 					break;
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 				case RET_SNAP_DELETE:
174*cdf0e10cSrcweir 					// Fangobjekt loeschen
175*cdf0e10cSrcweir 					if ( !bCreateNew )
176*cdf0e10cSrcweir 						pPV->DeleteHelpLine(nHelpLine);
177*cdf0e10cSrcweir 					// und weiter wie bei default
178*cdf0e10cSrcweir 				default:
179*cdf0e10cSrcweir 					return;
180*cdf0e10cSrcweir 			}
181*cdf0e10cSrcweir 		}
182*cdf0e10cSrcweir 	}
183*cdf0e10cSrcweir 	Point aHlpPos;
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	aHlpPos.X() = ((const SfxUInt32Item&) pArgs->Get(ATTR_SNAPLINE_X)).GetValue();
186*cdf0e10cSrcweir 	aHlpPos.Y() = ((const SfxUInt32Item&) pArgs->Get(ATTR_SNAPLINE_Y)).GetValue();
187*cdf0e10cSrcweir 	pPV->PagePosToLogic(aHlpPos);
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 	if ( bCreateNew )
190*cdf0e10cSrcweir 	{
191*cdf0e10cSrcweir 		SdrHelpLineKind eKind;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 		pPV = mpView->GetSdrPageView();
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 		switch ( (SnapKind) ((const SfxAllEnumItem&)
196*cdf0e10cSrcweir 				 pArgs->Get(ATTR_SNAPLINE_KIND)).GetValue() )
197*cdf0e10cSrcweir 		{
198*cdf0e10cSrcweir 			case SK_HORIZONTAL	: eKind = SDRHELPLINE_HORIZONTAL;	break;
199*cdf0e10cSrcweir 			case SK_VERTICAL	: eKind = SDRHELPLINE_VERTICAL; 	break;
200*cdf0e10cSrcweir 			default 			: eKind = SDRHELPLINE_POINT;		break;
201*cdf0e10cSrcweir 		}
202*cdf0e10cSrcweir 		pPV->InsertHelpLine(SdrHelpLine(eKind, aHlpPos));
203*cdf0e10cSrcweir 	}
204*cdf0e10cSrcweir 	else
205*cdf0e10cSrcweir 	{
206*cdf0e10cSrcweir 		const SdrHelpLine& rHelpLine = (pPV->GetHelpLines())[nHelpLine];
207*cdf0e10cSrcweir 		pPV->SetHelpLine(nHelpLine, SdrHelpLine(rHelpLine.GetKind(), aHlpPos));
208*cdf0e10cSrcweir 	}
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir void FuSnapLine::Activate()
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir void FuSnapLine::Deactivate()
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir } // end of namespace sd
220