Update ooo320-m1
[ooovba.git] / sd / source / ui / func / fuediglu.cxx
blobf54949de4c04dcda85bfb1fa394bf7b97c1dd947
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: fuediglu.cxx,v $
10 * $Revision: 1.13 $
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 "fuediglu.hxx"
35 #include <svtools/eitem.hxx>
36 #include <svx/dialogs.hrc>
37 #include <svx/svdglue.hxx>
38 #include <sfx2/request.hxx>
41 #include "app.hrc"
42 #include "strings.hrc"
43 #include "res_bmp.hrc"
44 #ifndef SD_WINDOW_SHELL_HXX
45 #include "Window.hxx"
46 #endif
47 #include "drawdoc.hxx"
48 #ifndef SD_FRAMW_VIEW_HXX
49 #include "FrameView.hxx"
50 #endif
51 #include "View.hxx"
52 #include "ViewShell.hxx"
53 #include "ViewShellBase.hxx"
54 #include "ToolBarManager.hxx"
56 namespace sd {
58 TYPEINIT1( FuEditGluePoints, FuDraw );
60 /*************************************************************************
62 |* Konstruktor
64 \************************************************************************/
66 FuEditGluePoints::FuEditGluePoints (
67 ViewShell* pViewSh,
68 ::sd::Window* pWin,
69 ::sd::View* pView,
70 SdDrawDocument* pDoc,
71 SfxRequest& rReq)
72 : FuDraw(pViewSh, pWin, pView, pDoc, rReq)
76 FunctionReference FuEditGluePoints::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
78 FuEditGluePoints* pFunc;
79 FunctionReference xFunc( pFunc = new FuEditGluePoints( pViewSh, pWin, pView, pDoc, rReq ) );
80 xFunc->DoExecute(rReq);
81 pFunc->SetPermanent( bPermanent );
82 return xFunc;
85 void FuEditGluePoints::DoExecute( SfxRequest& rReq )
87 FuDraw::DoExecute( rReq );
88 mpView->SetInsGluePointMode(FALSE);
89 mpViewShell->GetViewShellBase().GetToolBarManager()->AddToolBar(
90 ToolBarManager::TBG_FUNCTION,
91 ToolBarManager::msGluePointsToolBar);
94 /*************************************************************************
96 |* Destruktor
98 \************************************************************************/
100 FuEditGluePoints::~FuEditGluePoints()
102 mpView->BrkAction();
103 mpView->UnmarkAllGluePoints();
104 mpView->SetInsGluePointMode(FALSE);
107 /*************************************************************************
109 |* MouseButtonDown-event
111 \************************************************************************/
113 BOOL FuEditGluePoints::MouseButtonDown(const MouseEvent& rMEvt)
115 mpView->SetActualWin( mpWindow );
117 BOOL bReturn = FuDraw::MouseButtonDown(rMEvt);
119 if (mpView->IsAction())
121 if (rMEvt.IsRight())
122 mpView->BckAction();
124 return TRUE;
127 if (rMEvt.IsLeft())
129 bReturn = TRUE;
130 USHORT nHitLog = USHORT ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
131 USHORT nDrgLog = USHORT ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
132 mpWindow->CaptureMouse();
134 SdrViewEvent aVEvt;
135 SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
137 if (eHit == SDRHIT_HANDLE)
139 /******************************************************************
140 * Handle draggen
141 ******************************************************************/
142 SdrHdl* pHdl = aVEvt.pHdl;
144 if (mpView->IsGluePointMarked(aVEvt.pObj, aVEvt.nGlueId) && rMEvt.IsShift())
146 mpView->UnmarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
147 pHdl = NULL;
150 if (pHdl)
152 // Handle draggen
153 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
156 else if (eHit == SDRHIT_MARKEDOBJECT && mpView->IsInsGluePointMode())
158 /******************************************************************
159 * Klebepunkt einfuegen
160 ******************************************************************/
161 mpView->BegInsGluePoint(aMDPos);
163 else if (eHit == SDRHIT_MARKEDOBJECT && rMEvt.IsMod1())
165 /******************************************************************
166 * Klebepunkt selektieren
167 ******************************************************************/
168 if (!rMEvt.IsShift())
169 mpView->UnmarkAllGluePoints();
171 mpView->BegMarkGluePoints(aMDPos);
173 else if (eHit == SDRHIT_MARKEDOBJECT && !rMEvt.IsShift() && !rMEvt.IsMod2())
175 /******************************************************************
176 * Objekt verschieben
177 ******************************************************************/
178 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, NULL, nDrgLog);
180 else if (eHit == SDRHIT_GLUEPOINT)
182 /******************************************************************
183 * Klebepunkt selektieren
184 ******************************************************************/
185 if (!rMEvt.IsShift())
186 mpView->UnmarkAllGluePoints();
188 mpView->MarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
189 SdrHdl* pHdl = mpView->GetGluePointHdl(aVEvt.pObj, aVEvt.nGlueId);
191 if (pHdl)
193 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
196 else
198 /******************************************************************
199 * Objekt selektieren oder draggen
200 ******************************************************************/
201 if (!rMEvt.IsShift() && !rMEvt.IsMod2() && eHit == SDRHIT_UNMARKEDOBJECT)
203 mpView->UnmarkAllObj();
206 BOOL bMarked = FALSE;
208 if (!rMEvt.IsMod1())
210 if (rMEvt.IsMod2())
212 bMarked = mpView->MarkNextObj(aMDPos, nHitLog, rMEvt.IsShift());
214 else
216 bMarked = mpView->MarkObj(aMDPos, nHitLog, rMEvt.IsShift());
220 if (bMarked &&
221 (!rMEvt.IsShift() || eHit == SDRHIT_MARKEDOBJECT))
223 // Objekt verschieben
224 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
226 else if (mpView->AreObjectsMarked())
228 /**************************************************************
229 * Klebepunkt selektieren
230 **************************************************************/
231 if (!rMEvt.IsShift())
232 mpView->UnmarkAllGluePoints();
234 mpView->BegMarkGluePoints(aMDPos);
236 else
238 /**************************************************************
239 * Objekt selektieren
240 **************************************************************/
241 mpView->BegMarkObj(aMDPos);
245 ForcePointer(&rMEvt);
248 return bReturn;
251 /*************************************************************************
253 |* MouseMove-event
255 \************************************************************************/
257 BOOL FuEditGluePoints::MouseMove(const MouseEvent& rMEvt)
259 mpView->SetActualWin( mpWindow );
261 FuDraw::MouseMove(rMEvt);
263 if (mpView->IsAction())
265 Point aPix(rMEvt.GetPosPixel());
266 Point aPnt( mpWindow->PixelToLogic(aPix) );
267 ForceScroll(aPix);
268 mpView->MovAction(aPnt);
271 ForcePointer(&rMEvt);
273 return TRUE;
276 /*************************************************************************
278 |* MouseButtonUp-event
280 \************************************************************************/
282 BOOL FuEditGluePoints::MouseButtonUp(const MouseEvent& rMEvt)
284 mpView->SetActualWin( mpWindow );
286 BOOL bReturn = FALSE;
288 if (mpView->IsAction())
290 bReturn = TRUE;
291 mpView->EndAction();
294 FuDraw::MouseButtonUp(rMEvt);
296 USHORT nDrgLog = USHORT ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
297 Point aPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
299 if (Abs(aMDPos.X() - aPos.X()) < nDrgLog &&
300 Abs(aMDPos.Y() - aPos.Y()) < nDrgLog &&
301 !rMEvt.IsShift() && !rMEvt.IsMod2())
303 SdrViewEvent aVEvt;
304 SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
306 if (eHit == SDRHIT_NONE)
308 // Klick auf der Stelle: deselektieren
309 mpView->UnmarkAllObj();
313 mpWindow->ReleaseMouse();
315 return bReturn;
318 /*************************************************************************
320 |* Tastaturereignisse bearbeiten
322 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
323 |* FALSE.
325 \************************************************************************/
327 BOOL FuEditGluePoints::KeyInput(const KeyEvent& rKEvt)
329 mpView->SetActualWin( mpWindow );
331 BOOL bReturn = FuDraw::KeyInput(rKEvt);
333 return bReturn;
336 /*************************************************************************
338 |* Command-event
340 \************************************************************************/
342 BOOL FuEditGluePoints::Command(const CommandEvent& rCEvt)
344 mpView->SetActualWin( mpWindow );
345 return FuPoor::Command( rCEvt );
348 /*************************************************************************
350 |* Funktion aktivieren
352 \************************************************************************/
354 void FuEditGluePoints::Activate()
356 mpView->SetGluePointEditMode();
357 FuDraw::Activate();
360 /*************************************************************************
362 |* Funktion deaktivieren
364 \************************************************************************/
366 void FuEditGluePoints::Deactivate()
368 mpView->SetGluePointEditMode( FALSE );
369 FuDraw::Deactivate();
372 /*************************************************************************
374 |* Request verarbeiten
376 \************************************************************************/
378 void FuEditGluePoints::ReceiveRequest(SfxRequest& rReq)
380 switch (rReq.GetSlot())
382 case SID_GLUE_INSERT_POINT:
384 mpView->SetInsGluePointMode(!mpView->IsInsGluePointMode());
386 break;
388 case SID_GLUE_ESCDIR_LEFT:
390 mpView->SetMarkedGluePointsEscDir( SDRESC_LEFT,
391 !mpView->IsMarkedGluePointsEscDir( SDRESC_LEFT ) );
393 break;
395 case SID_GLUE_ESCDIR_RIGHT:
397 mpView->SetMarkedGluePointsEscDir( SDRESC_RIGHT,
398 !mpView->IsMarkedGluePointsEscDir( SDRESC_RIGHT ) );
400 break;
402 case SID_GLUE_ESCDIR_TOP:
404 mpView->SetMarkedGluePointsEscDir( SDRESC_TOP,
405 !mpView->IsMarkedGluePointsEscDir( SDRESC_TOP ) );
407 break;
409 case SID_GLUE_ESCDIR_BOTTOM:
411 mpView->SetMarkedGluePointsEscDir( SDRESC_BOTTOM,
412 !mpView->IsMarkedGluePointsEscDir( SDRESC_BOTTOM ) );
414 break;
416 case SID_GLUE_PERCENT:
418 const SfxItemSet* pSet = rReq.GetArgs();
419 const SfxPoolItem& rItem = pSet->Get(SID_GLUE_PERCENT);
420 BOOL bPercent = ((const SfxBoolItem&) rItem).GetValue();
421 mpView->SetMarkedGluePointsPercent(bPercent);
423 break;
425 case SID_GLUE_HORZALIGN_CENTER:
427 mpView->SetMarkedGluePointsAlign(FALSE, SDRHORZALIGN_CENTER);
429 break;
431 case SID_GLUE_HORZALIGN_LEFT:
433 mpView->SetMarkedGluePointsAlign(FALSE, SDRHORZALIGN_LEFT);
435 break;
437 case SID_GLUE_HORZALIGN_RIGHT:
439 mpView->SetMarkedGluePointsAlign(FALSE, SDRHORZALIGN_RIGHT);
441 break;
443 case SID_GLUE_VERTALIGN_CENTER:
445 mpView->SetMarkedGluePointsAlign(TRUE, SDRVERTALIGN_CENTER);
447 break;
449 case SID_GLUE_VERTALIGN_TOP:
451 mpView->SetMarkedGluePointsAlign(TRUE, SDRVERTALIGN_TOP);
453 break;
455 case SID_GLUE_VERTALIGN_BOTTOM:
457 mpView->SetMarkedGluePointsAlign(TRUE, SDRVERTALIGN_BOTTOM);
459 break;
462 // Zum Schluss Basisklasse rufen
463 FuPoor::ReceiveRequest(rReq);
467 } // end of namespace sd