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