Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "fuediglu.hxx"
22 : #include <svl/eitem.hxx>
23 : #include <svx/dialogs.hrc>
24 : #include <svx/svdglue.hxx>
25 : #include <sfx2/request.hxx>
26 :
27 :
28 : #include "app.hrc"
29 : #include "strings.hrc"
30 : #include "res_bmp.hrc"
31 : #include "Window.hxx"
32 : #include "drawdoc.hxx"
33 : #include "FrameView.hxx"
34 : #include "View.hxx"
35 : #include "ViewShell.hxx"
36 : #include "ViewShellBase.hxx"
37 : #include "ToolBarManager.hxx"
38 :
39 : namespace sd {
40 :
41 0 : TYPEINIT1( FuEditGluePoints, FuDraw );
42 :
43 :
44 0 : FuEditGluePoints::FuEditGluePoints (
45 : ViewShell* pViewSh,
46 : ::sd::Window* pWin,
47 : ::sd::View* pView,
48 : SdDrawDocument* pDoc,
49 : SfxRequest& rReq)
50 0 : : FuDraw(pViewSh, pWin, pView, pDoc, rReq)
51 : {
52 0 : }
53 :
54 0 : FunctionReference FuEditGluePoints::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
55 : {
56 : FuEditGluePoints* pFunc;
57 0 : FunctionReference xFunc( pFunc = new FuEditGluePoints( pViewSh, pWin, pView, pDoc, rReq ) );
58 0 : xFunc->DoExecute(rReq);
59 0 : pFunc->SetPermanent( bPermanent );
60 0 : return xFunc;
61 : }
62 :
63 0 : void FuEditGluePoints::DoExecute( SfxRequest& rReq )
64 : {
65 0 : FuDraw::DoExecute( rReq );
66 0 : mpView->SetInsGluePointMode(sal_False);
67 0 : mpViewShell->GetViewShellBase().GetToolBarManager()->AddToolBar(
68 : ToolBarManager::TBG_FUNCTION,
69 0 : ToolBarManager::msGluePointsToolBar);
70 0 : }
71 :
72 :
73 0 : FuEditGluePoints::~FuEditGluePoints()
74 : {
75 0 : mpView->BrkAction();
76 0 : mpView->UnmarkAllGluePoints();
77 0 : mpView->SetInsGluePointMode(sal_False);
78 0 : }
79 :
80 :
81 0 : sal_Bool FuEditGluePoints::MouseButtonDown(const MouseEvent& rMEvt)
82 : {
83 0 : mpView->SetActualWin( mpWindow );
84 :
85 0 : sal_Bool bReturn = FuDraw::MouseButtonDown(rMEvt);
86 :
87 0 : if (mpView->IsAction())
88 : {
89 0 : if (rMEvt.IsRight())
90 0 : mpView->BckAction();
91 :
92 0 : return sal_True;
93 : }
94 :
95 0 : if (rMEvt.IsLeft())
96 : {
97 0 : bReturn = sal_True;
98 0 : sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
99 0 : sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
100 0 : mpWindow->CaptureMouse();
101 :
102 0 : SdrViewEvent aVEvt;
103 0 : SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
104 :
105 0 : if (eHit == SDRHIT_HANDLE)
106 : {
107 : // drag handle
108 0 : SdrHdl* pHdl = aVEvt.pHdl;
109 :
110 0 : if (mpView->IsGluePointMarked(aVEvt.pObj, aVEvt.nGlueId) && rMEvt.IsShift())
111 : {
112 0 : mpView->UnmarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
113 0 : pHdl = NULL;
114 : }
115 :
116 0 : if (pHdl)
117 : {
118 : // drag handle
119 0 : mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
120 : }
121 : }
122 0 : else if (eHit == SDRHIT_MARKEDOBJECT && mpView->IsInsGluePointMode())
123 : {
124 : // insert glue points
125 0 : mpView->BegInsGluePoint(aMDPos);
126 : }
127 0 : else if (eHit == SDRHIT_MARKEDOBJECT && rMEvt.IsMod1())
128 : {
129 : // select glue points
130 0 : if (!rMEvt.IsShift())
131 0 : mpView->UnmarkAllGluePoints();
132 :
133 0 : mpView->BegMarkGluePoints(aMDPos);
134 : }
135 0 : else if (eHit == SDRHIT_MARKEDOBJECT && !rMEvt.IsShift() && !rMEvt.IsMod2())
136 : {
137 : // move object
138 0 : mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, NULL, nDrgLog);
139 : }
140 0 : else if (eHit == SDRHIT_GLUEPOINT)
141 : {
142 : // select glue points
143 0 : if (!rMEvt.IsShift())
144 0 : mpView->UnmarkAllGluePoints();
145 :
146 0 : mpView->MarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
147 0 : SdrHdl* pHdl = mpView->GetGluePointHdl(aVEvt.pObj, aVEvt.nGlueId);
148 :
149 0 : if (pHdl)
150 : {
151 0 : mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
152 : }
153 : }
154 : else
155 : {
156 : // select or drag object
157 0 : if (!rMEvt.IsShift() && !rMEvt.IsMod2() && eHit == SDRHIT_UNMARKEDOBJECT)
158 : {
159 0 : mpView->UnmarkAllObj();
160 : }
161 :
162 0 : sal_Bool bMarked = sal_False;
163 :
164 0 : if (!rMEvt.IsMod1())
165 : {
166 0 : if (rMEvt.IsMod2())
167 : {
168 0 : bMarked = mpView->MarkNextObj(aMDPos, nHitLog, rMEvt.IsShift());
169 : }
170 : else
171 : {
172 0 : bMarked = mpView->MarkObj(aMDPos, nHitLog, rMEvt.IsShift());
173 : }
174 : }
175 :
176 0 : if (bMarked &&
177 0 : (!rMEvt.IsShift() || eHit == SDRHIT_MARKEDOBJECT))
178 : {
179 : // move object
180 0 : mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
181 : }
182 0 : else if (mpView->AreObjectsMarked())
183 : {
184 : // select glue point
185 0 : if (!rMEvt.IsShift())
186 0 : mpView->UnmarkAllGluePoints();
187 :
188 0 : mpView->BegMarkGluePoints(aMDPos);
189 : }
190 : else
191 : {
192 : // select object
193 0 : mpView->BegMarkObj(aMDPos);
194 : }
195 : }
196 :
197 0 : ForcePointer(&rMEvt);
198 : }
199 :
200 0 : return bReturn;
201 : }
202 :
203 :
204 0 : sal_Bool FuEditGluePoints::MouseMove(const MouseEvent& rMEvt)
205 : {
206 0 : mpView->SetActualWin( mpWindow );
207 :
208 0 : FuDraw::MouseMove(rMEvt);
209 :
210 0 : if (mpView->IsAction())
211 : {
212 0 : Point aPix(rMEvt.GetPosPixel());
213 0 : Point aPnt( mpWindow->PixelToLogic(aPix) );
214 0 : ForceScroll(aPix);
215 0 : mpView->MovAction(aPnt);
216 : }
217 :
218 0 : ForcePointer(&rMEvt);
219 :
220 0 : return sal_True;
221 : }
222 :
223 :
224 0 : sal_Bool FuEditGluePoints::MouseButtonUp(const MouseEvent& rMEvt)
225 : {
226 0 : mpView->SetActualWin( mpWindow );
227 :
228 0 : sal_Bool bReturn = sal_False;
229 :
230 0 : if (mpView->IsAction())
231 : {
232 0 : bReturn = sal_True;
233 0 : mpView->EndAction();
234 : }
235 :
236 0 : FuDraw::MouseButtonUp(rMEvt);
237 :
238 0 : sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
239 0 : Point aPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
240 :
241 0 : if (std::abs(aMDPos.X() - aPos.X()) < nDrgLog &&
242 0 : std::abs(aMDPos.Y() - aPos.Y()) < nDrgLog &&
243 0 : !rMEvt.IsShift() && !rMEvt.IsMod2())
244 : {
245 0 : SdrViewEvent aVEvt;
246 0 : SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
247 :
248 0 : if (eHit == SDRHIT_NONE)
249 : {
250 : // click on position: deselect
251 0 : mpView->UnmarkAllObj();
252 0 : }
253 : }
254 :
255 0 : mpWindow->ReleaseMouse();
256 :
257 0 : return bReturn;
258 : }
259 :
260 : /**
261 : * Process keyboard input
262 : * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
263 : */
264 0 : sal_Bool FuEditGluePoints::KeyInput(const KeyEvent& rKEvt)
265 : {
266 0 : mpView->SetActualWin( mpWindow );
267 :
268 0 : sal_Bool bReturn = FuDraw::KeyInput(rKEvt);
269 :
270 0 : return bReturn;
271 : }
272 :
273 :
274 0 : sal_Bool FuEditGluePoints::Command(const CommandEvent& rCEvt)
275 : {
276 0 : mpView->SetActualWin( mpWindow );
277 0 : return FuPoor::Command( rCEvt );
278 : }
279 :
280 :
281 0 : void FuEditGluePoints::Activate()
282 : {
283 0 : mpView->SetGluePointEditMode();
284 0 : FuDraw::Activate();
285 0 : }
286 :
287 :
288 0 : void FuEditGluePoints::Deactivate()
289 : {
290 0 : mpView->SetGluePointEditMode( sal_False );
291 0 : FuDraw::Deactivate();
292 0 : }
293 :
294 :
295 0 : void FuEditGluePoints::ReceiveRequest(SfxRequest& rReq)
296 : {
297 0 : switch (rReq.GetSlot())
298 : {
299 : case SID_GLUE_INSERT_POINT:
300 : {
301 0 : mpView->SetInsGluePointMode(!mpView->IsInsGluePointMode());
302 : }
303 0 : break;
304 :
305 : case SID_GLUE_ESCDIR_LEFT:
306 : {
307 : mpView->SetMarkedGluePointsEscDir( SDRESC_LEFT,
308 0 : !mpView->IsMarkedGluePointsEscDir( SDRESC_LEFT ) );
309 : }
310 0 : break;
311 :
312 : case SID_GLUE_ESCDIR_RIGHT:
313 : {
314 : mpView->SetMarkedGluePointsEscDir( SDRESC_RIGHT,
315 0 : !mpView->IsMarkedGluePointsEscDir( SDRESC_RIGHT ) );
316 : }
317 0 : break;
318 :
319 : case SID_GLUE_ESCDIR_TOP:
320 : {
321 : mpView->SetMarkedGluePointsEscDir( SDRESC_TOP,
322 0 : !mpView->IsMarkedGluePointsEscDir( SDRESC_TOP ) );
323 : }
324 0 : break;
325 :
326 : case SID_GLUE_ESCDIR_BOTTOM:
327 : {
328 : mpView->SetMarkedGluePointsEscDir( SDRESC_BOTTOM,
329 0 : !mpView->IsMarkedGluePointsEscDir( SDRESC_BOTTOM ) );
330 : }
331 0 : break;
332 :
333 : case SID_GLUE_PERCENT:
334 : {
335 0 : const SfxItemSet* pSet = rReq.GetArgs();
336 0 : const SfxPoolItem& rItem = pSet->Get(SID_GLUE_PERCENT);
337 0 : sal_Bool bPercent = ((const SfxBoolItem&) rItem).GetValue();
338 0 : mpView->SetMarkedGluePointsPercent(bPercent);
339 : }
340 0 : break;
341 :
342 : case SID_GLUE_HORZALIGN_CENTER:
343 : {
344 0 : mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_CENTER);
345 : }
346 0 : break;
347 :
348 : case SID_GLUE_HORZALIGN_LEFT:
349 : {
350 0 : mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_LEFT);
351 : }
352 0 : break;
353 :
354 : case SID_GLUE_HORZALIGN_RIGHT:
355 : {
356 0 : mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_RIGHT);
357 : }
358 0 : break;
359 :
360 : case SID_GLUE_VERTALIGN_CENTER:
361 : {
362 0 : mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_CENTER);
363 : }
364 0 : break;
365 :
366 : case SID_GLUE_VERTALIGN_TOP:
367 : {
368 0 : mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_TOP);
369 : }
370 0 : break;
371 :
372 : case SID_GLUE_VERTALIGN_BOTTOM:
373 : {
374 0 : mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_BOTTOM);
375 : }
376 0 : break;
377 : }
378 :
379 : // at the end, call base class
380 0 : FuPoor::ReceiveRequest(rReq);
381 0 : }
382 :
383 :
384 33 : } // end of namespace sd
385 :
386 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|