xref: /AOO41X/main/sd/source/ui/func/fuediglu.cxx (revision ff0525f24f03981d56b7579b645949f111420994)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "fuediglu.hxx"
28 #include <svl/eitem.hxx>
29 #include <svx/dialogs.hrc>
30 #include <svx/svdglue.hxx>
31 #include <sfx2/request.hxx>
32 
33 
34 #include "app.hrc"
35 #include "strings.hrc"
36 #include "res_bmp.hrc"
37 #ifndef SD_WINDOW_SHELL_HXX
38 #include "Window.hxx"
39 #endif
40 #include "drawdoc.hxx"
41 #ifndef SD_FRAMW_VIEW_HXX
42 #include "FrameView.hxx"
43 #endif
44 #include "View.hxx"
45 #include "ViewShell.hxx"
46 #include "ViewShellBase.hxx"
47 #include "ToolBarManager.hxx"
48 
49 namespace sd {
50 
51 TYPEINIT1( FuEditGluePoints, FuDraw );
52 
53 /*************************************************************************
54 |*
55 |* Konstruktor
56 |*
57 \************************************************************************/
58 
59 FuEditGluePoints::FuEditGluePoints (
60     ViewShell* pViewSh,
61     ::sd::Window* pWin,
62     ::sd::View* pView,
63     SdDrawDocument* pDoc,
64     SfxRequest& rReq)
65     : FuDraw(pViewSh, pWin, pView, pDoc, rReq)
66 {
67 }
68 
69 FunctionReference FuEditGluePoints::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
70 {
71     FuEditGluePoints* pFunc;
72     FunctionReference xFunc( pFunc = new FuEditGluePoints( pViewSh, pWin, pView, pDoc, rReq ) );
73     xFunc->DoExecute(rReq);
74     pFunc->SetPermanent( bPermanent );
75     return xFunc;
76 }
77 
78 void FuEditGluePoints::DoExecute( SfxRequest& rReq )
79 {
80     FuDraw::DoExecute( rReq );
81     mpView->SetInsGluePointMode(sal_False);
82     mpViewShell->GetViewShellBase().GetToolBarManager()->AddToolBar(
83         ToolBarManager::TBG_FUNCTION,
84         ToolBarManager::msGluePointsToolBar);
85 }
86 
87 /*************************************************************************
88 |*
89 |* Destruktor
90 |*
91 \************************************************************************/
92 
93 FuEditGluePoints::~FuEditGluePoints()
94 {
95     mpView->BrkAction();
96     mpView->UnmarkAllGluePoints();
97     mpView->SetInsGluePointMode(sal_False);
98 }
99 
100 /*************************************************************************
101 |*
102 |* MouseButtonDown-event
103 |*
104 \************************************************************************/
105 
106 sal_Bool FuEditGluePoints::MouseButtonDown(const MouseEvent& rMEvt)
107 {
108     mpView->SetActualWin( mpWindow );
109 
110     sal_Bool bReturn = FuDraw::MouseButtonDown(rMEvt);
111 
112     if (mpView->IsAction())
113     {
114         if (rMEvt.IsRight())
115             mpView->BckAction();
116 
117         return sal_True;
118     }
119 
120     if (rMEvt.IsLeft())
121     {
122         bReturn = sal_True;
123         sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
124         sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
125         mpWindow->CaptureMouse();
126 
127         SdrViewEvent aVEvt;
128         SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
129 
130         if (eHit == SDRHIT_HANDLE)
131         {
132             /******************************************************************
133             * Handle draggen
134             ******************************************************************/
135             SdrHdl* pHdl = aVEvt.pHdl;
136 
137             if (mpView->IsGluePointMarked(aVEvt.pObj, aVEvt.nGlueId) && rMEvt.IsShift())
138             {
139                 mpView->UnmarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
140                 pHdl = NULL;
141             }
142 
143             if (pHdl)
144             {
145                 // Handle draggen
146                 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
147             }
148         }
149         else if (eHit == SDRHIT_MARKEDOBJECT && mpView->IsInsGluePointMode())
150         {
151             /******************************************************************
152             * Klebepunkt einfuegen
153             ******************************************************************/
154             mpView->BegInsGluePoint(aMDPos);
155         }
156         else if (eHit == SDRHIT_MARKEDOBJECT && rMEvt.IsMod1())
157         {
158             /******************************************************************
159             * Klebepunkt selektieren
160             ******************************************************************/
161             if (!rMEvt.IsShift())
162                 mpView->UnmarkAllGluePoints();
163 
164             mpView->BegMarkGluePoints(aMDPos);
165         }
166         else if (eHit == SDRHIT_MARKEDOBJECT && !rMEvt.IsShift() && !rMEvt.IsMod2())
167         {
168             /******************************************************************
169             * Objekt verschieben
170             ******************************************************************/
171             mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, NULL, nDrgLog);
172         }
173         else if (eHit == SDRHIT_GLUEPOINT)
174         {
175             /******************************************************************
176             * Klebepunkt selektieren
177             ******************************************************************/
178             if (!rMEvt.IsShift())
179                 mpView->UnmarkAllGluePoints();
180 
181             mpView->MarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
182             SdrHdl* pHdl = mpView->GetGluePointHdl(aVEvt.pObj, aVEvt.nGlueId);
183 
184             if (pHdl)
185             {
186                 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
187             }
188         }
189         else
190         {
191             /******************************************************************
192             * Objekt selektieren oder draggen
193             ******************************************************************/
194             if (!rMEvt.IsShift() && !rMEvt.IsMod2() && eHit == SDRHIT_UNMARKEDOBJECT)
195             {
196                mpView->UnmarkAllObj();
197             }
198 
199             sal_Bool bMarked = sal_False;
200 
201             if (!rMEvt.IsMod1())
202             {
203                 if (rMEvt.IsMod2())
204                 {
205                     bMarked = mpView->MarkNextObj(aMDPos, nHitLog, rMEvt.IsShift());
206                 }
207                 else
208                 {
209                     bMarked = mpView->MarkObj(aMDPos, nHitLog, rMEvt.IsShift());
210                 }
211             }
212 
213             if (bMarked &&
214                 (!rMEvt.IsShift() || eHit == SDRHIT_MARKEDOBJECT))
215             {
216                 // Objekt verschieben
217                 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
218             }
219             else if (mpView->AreObjectsMarked())
220             {
221                 /**************************************************************
222                 * Klebepunkt selektieren
223                 **************************************************************/
224                 if (!rMEvt.IsShift())
225                     mpView->UnmarkAllGluePoints();
226 
227                 mpView->BegMarkGluePoints(aMDPos);
228             }
229             else
230             {
231                 /**************************************************************
232                 * Objekt selektieren
233                 **************************************************************/
234                 mpView->BegMarkObj(aMDPos);
235             }
236         }
237 
238         ForcePointer(&rMEvt);
239     }
240 
241     return bReturn;
242 }
243 
244 /*************************************************************************
245 |*
246 |* MouseMove-event
247 |*
248 \************************************************************************/
249 
250 sal_Bool FuEditGluePoints::MouseMove(const MouseEvent& rMEvt)
251 {
252     mpView->SetActualWin( mpWindow );
253 
254     FuDraw::MouseMove(rMEvt);
255 
256     if (mpView->IsAction())
257     {
258         Point aPix(rMEvt.GetPosPixel());
259         Point aPnt( mpWindow->PixelToLogic(aPix) );
260         ForceScroll(aPix);
261         mpView->MovAction(aPnt);
262     }
263 
264     ForcePointer(&rMEvt);
265 
266     return sal_True;
267 }
268 
269 /*************************************************************************
270 |*
271 |* MouseButtonUp-event
272 |*
273 \************************************************************************/
274 
275 sal_Bool FuEditGluePoints::MouseButtonUp(const MouseEvent& rMEvt)
276 {
277     mpView->SetActualWin( mpWindow );
278 
279     sal_Bool bReturn = sal_False;
280 
281     if (mpView->IsAction())
282     {
283         bReturn = sal_True;
284         mpView->EndAction();
285     }
286 
287     FuDraw::MouseButtonUp(rMEvt);
288 
289     sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
290     Point aPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
291 
292     if (Abs(aMDPos.X() - aPos.X()) < nDrgLog &&
293         Abs(aMDPos.Y() - aPos.Y()) < nDrgLog &&
294         !rMEvt.IsShift() && !rMEvt.IsMod2())
295     {
296         SdrViewEvent aVEvt;
297         SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
298 
299         if (eHit == SDRHIT_NONE)
300         {
301             // Klick auf der Stelle: deselektieren
302             mpView->UnmarkAllObj();
303         }
304     }
305 
306     mpWindow->ReleaseMouse();
307 
308     return bReturn;
309 }
310 
311 /*************************************************************************
312 |*
313 |* Tastaturereignisse bearbeiten
314 |*
315 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
316 |* sal_False.
317 |*
318 \************************************************************************/
319 
320 sal_Bool FuEditGluePoints::KeyInput(const KeyEvent& rKEvt)
321 {
322     mpView->SetActualWin( mpWindow );
323 
324     sal_Bool bReturn = FuDraw::KeyInput(rKEvt);
325 
326     return bReturn;
327 }
328 
329 /*************************************************************************
330 |*
331 |* Command-event
332 |*
333 \************************************************************************/
334 
335 sal_Bool FuEditGluePoints::Command(const CommandEvent& rCEvt)
336 {
337     mpView->SetActualWin( mpWindow );
338     return FuPoor::Command( rCEvt );
339 }
340 
341 /*************************************************************************
342 |*
343 |* Funktion aktivieren
344 |*
345 \************************************************************************/
346 
347 void FuEditGluePoints::Activate()
348 {
349     mpView->SetGluePointEditMode();
350     FuDraw::Activate();
351 }
352 
353 /*************************************************************************
354 |*
355 |* Funktion deaktivieren
356 |*
357 \************************************************************************/
358 
359 void FuEditGluePoints::Deactivate()
360 {
361     mpView->SetGluePointEditMode( sal_False );
362     FuDraw::Deactivate();
363 }
364 
365 /*************************************************************************
366 |*
367 |* Request verarbeiten
368 |*
369 \************************************************************************/
370 
371 void FuEditGluePoints::ReceiveRequest(SfxRequest& rReq)
372 {
373     switch (rReq.GetSlot())
374     {
375         case SID_GLUE_INSERT_POINT:
376         {
377             mpView->SetInsGluePointMode(!mpView->IsInsGluePointMode());
378         }
379         break;
380 
381         case SID_GLUE_ESCDIR_LEFT:
382         {
383             mpView->SetMarkedGluePointsEscDir( SDRESC_LEFT,
384                     !mpView->IsMarkedGluePointsEscDir( SDRESC_LEFT ) );
385         }
386         break;
387 
388         case SID_GLUE_ESCDIR_RIGHT:
389         {
390             mpView->SetMarkedGluePointsEscDir( SDRESC_RIGHT,
391                     !mpView->IsMarkedGluePointsEscDir( SDRESC_RIGHT ) );
392         }
393         break;
394 
395         case SID_GLUE_ESCDIR_TOP:
396         {
397             mpView->SetMarkedGluePointsEscDir( SDRESC_TOP,
398                     !mpView->IsMarkedGluePointsEscDir( SDRESC_TOP ) );
399         }
400         break;
401 
402         case SID_GLUE_ESCDIR_BOTTOM:
403         {
404             mpView->SetMarkedGluePointsEscDir( SDRESC_BOTTOM,
405                     !mpView->IsMarkedGluePointsEscDir( SDRESC_BOTTOM ) );
406         }
407         break;
408 
409         case SID_GLUE_PERCENT:
410         {
411             const SfxItemSet* pSet = rReq.GetArgs();
412             const SfxPoolItem& rItem = pSet->Get(SID_GLUE_PERCENT);
413             sal_Bool bPercent = ((const SfxBoolItem&) rItem).GetValue();
414             mpView->SetMarkedGluePointsPercent(bPercent);
415         }
416         break;
417 
418         case SID_GLUE_HORZALIGN_CENTER:
419         {
420             mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_CENTER);
421         }
422         break;
423 
424         case SID_GLUE_HORZALIGN_LEFT:
425         {
426             mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_LEFT);
427         }
428         break;
429 
430         case SID_GLUE_HORZALIGN_RIGHT:
431         {
432             mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_RIGHT);
433         }
434         break;
435 
436         case SID_GLUE_VERTALIGN_CENTER:
437         {
438             mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_CENTER);
439         }
440         break;
441 
442         case SID_GLUE_VERTALIGN_TOP:
443         {
444             mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_TOP);
445         }
446         break;
447 
448         case SID_GLUE_VERTALIGN_BOTTOM:
449         {
450             mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_BOTTOM);
451         }
452         break;
453     }
454 
455     // Zum Schluss Basisklasse rufen
456     FuPoor::ReceiveRequest(rReq);
457 }
458 
459 
460 } // end of namespace sd
461