xref: /trunk/main/sd/source/ui/func/fuediglu.cxx (revision a0d53b35b9c5a6bd9856ab272d521493ba628169)
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 //IAccessibility2 Implementation 2009-----
67      //Solution: Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
68      //and SHIFT+ENTER key to decide the postion and draw the new insert point
69      ,bBeginInsertPoint(sal_False),
70     oldPoint(0,0)
71 //-----IAccessibility2 Implementation 2009
72 {
73 }
74 
75 FunctionReference FuEditGluePoints::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
76 {
77     FuEditGluePoints* pFunc;
78     FunctionReference xFunc( pFunc = new FuEditGluePoints( pViewSh, pWin, pView, pDoc, rReq ) );
79     xFunc->DoExecute(rReq);
80     pFunc->SetPermanent( bPermanent );
81     return xFunc;
82 }
83 
84 void FuEditGluePoints::DoExecute( SfxRequest& rReq )
85 {
86     FuDraw::DoExecute( rReq );
87     mpView->SetInsGluePointMode(sal_False);
88     mpViewShell->GetViewShellBase().GetToolBarManager()->AddToolBar(
89         ToolBarManager::TBG_FUNCTION,
90         ToolBarManager::msGluePointsToolBar);
91 }
92 
93 /*************************************************************************
94 |*
95 |* Destruktor
96 |*
97 \************************************************************************/
98 
99 FuEditGluePoints::~FuEditGluePoints()
100 {
101     mpView->BrkAction();
102     mpView->UnmarkAllGluePoints();
103     mpView->SetInsGluePointMode(sal_False);
104 }
105 
106 /*************************************************************************
107 |*
108 |* MouseButtonDown-event
109 |*
110 \************************************************************************/
111 
112 sal_Bool FuEditGluePoints::MouseButtonDown(const MouseEvent& rMEvt)
113 {
114     mpView->SetActualWin( mpWindow );
115 
116     sal_Bool bReturn = FuDraw::MouseButtonDown(rMEvt);
117 
118     if (mpView->IsAction())
119     {
120         if (rMEvt.IsRight())
121             mpView->BckAction();
122 
123         return sal_True;
124     }
125 
126     if (rMEvt.IsLeft())
127     {
128         bReturn = sal_True;
129         sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
130         sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
131         mpWindow->CaptureMouse();
132 
133         SdrViewEvent aVEvt;
134         SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
135 
136         if (eHit == SDRHIT_HANDLE)
137         {
138             /******************************************************************
139             * Handle draggen
140             ******************************************************************/
141             SdrHdl* pHdl = aVEvt.pHdl;
142 
143             if (mpView->IsGluePointMarked(aVEvt.pObj, aVEvt.nGlueId) && rMEvt.IsShift())
144             {
145                 mpView->UnmarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
146                 pHdl = NULL;
147             }
148 
149             if (pHdl)
150             {
151                 // Handle draggen
152                 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
153             }
154         }
155         else if (eHit == SDRHIT_MARKEDOBJECT && mpView->IsInsGluePointMode())
156         {
157             /******************************************************************
158             * Klebepunkt einfuegen
159             ******************************************************************/
160             mpView->BegInsGluePoint(aMDPos);
161         }
162         else if (eHit == SDRHIT_MARKEDOBJECT && rMEvt.IsMod1())
163         {
164             /******************************************************************
165             * Klebepunkt selektieren
166             ******************************************************************/
167             if (!rMEvt.IsShift())
168                 mpView->UnmarkAllGluePoints();
169 
170             mpView->BegMarkGluePoints(aMDPos);
171         }
172         else if (eHit == SDRHIT_MARKEDOBJECT && !rMEvt.IsShift() && !rMEvt.IsMod2())
173         {
174             /******************************************************************
175             * Objekt verschieben
176             ******************************************************************/
177             mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, NULL, nDrgLog);
178         }
179         else if (eHit == SDRHIT_GLUEPOINT)
180         {
181             /******************************************************************
182             * Klebepunkt selektieren
183             ******************************************************************/
184             if (!rMEvt.IsShift())
185                 mpView->UnmarkAllGluePoints();
186 
187             mpView->MarkGluePoint(aVEvt.pObj, aVEvt.nGlueId, aVEvt.pPV);
188             SdrHdl* pHdl = mpView->GetGluePointHdl(aVEvt.pObj, aVEvt.nGlueId);
189 
190             if (pHdl)
191             {
192                 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
193             }
194         }
195         else
196         {
197             /******************************************************************
198             * Objekt selektieren oder draggen
199             ******************************************************************/
200             if (!rMEvt.IsShift() && !rMEvt.IsMod2() && eHit == SDRHIT_UNMARKEDOBJECT)
201             {
202                mpView->UnmarkAllObj();
203             }
204 
205             sal_Bool bMarked = sal_False;
206 
207             if (!rMEvt.IsMod1())
208             {
209                 if (rMEvt.IsMod2())
210                 {
211                     bMarked = mpView->MarkNextObj(aMDPos, nHitLog, rMEvt.IsShift());
212                 }
213                 else
214                 {
215                     bMarked = mpView->MarkObj(aMDPos, nHitLog, rMEvt.IsShift());
216                 }
217             }
218 
219             if (bMarked &&
220                 (!rMEvt.IsShift() || eHit == SDRHIT_MARKEDOBJECT))
221             {
222                 // Objekt verschieben
223                 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
224             }
225             else if (mpView->AreObjectsMarked())
226             {
227                 /**************************************************************
228                 * Klebepunkt selektieren
229                 **************************************************************/
230                 if (!rMEvt.IsShift())
231                     mpView->UnmarkAllGluePoints();
232 
233                 mpView->BegMarkGluePoints(aMDPos);
234             }
235             else
236             {
237                 /**************************************************************
238                 * Objekt selektieren
239                 **************************************************************/
240                 mpView->BegMarkObj(aMDPos);
241             }
242         }
243 
244         ForcePointer(&rMEvt);
245     }
246 
247     return bReturn;
248 }
249 
250 /*************************************************************************
251 |*
252 |* MouseMove-event
253 |*
254 \************************************************************************/
255 
256 sal_Bool FuEditGluePoints::MouseMove(const MouseEvent& rMEvt)
257 {
258     mpView->SetActualWin( mpWindow );
259 
260     FuDraw::MouseMove(rMEvt);
261 
262     if (mpView->IsAction())
263     {
264         Point aPix(rMEvt.GetPosPixel());
265         Point aPnt( mpWindow->PixelToLogic(aPix) );
266         ForceScroll(aPix);
267         mpView->MovAction(aPnt);
268     }
269 
270     ForcePointer(&rMEvt);
271 
272     return sal_True;
273 }
274 
275 /*************************************************************************
276 |*
277 |* MouseButtonUp-event
278 |*
279 \************************************************************************/
280 
281 sal_Bool FuEditGluePoints::MouseButtonUp(const MouseEvent& rMEvt)
282 {
283     mpView->SetActualWin( mpWindow );
284 
285     sal_Bool bReturn = sal_False;
286 
287     if (mpView->IsAction())
288     {
289         bReturn = sal_True;
290         mpView->EndAction();
291     }
292 
293     FuDraw::MouseButtonUp(rMEvt);
294 
295     sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
296     Point aPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
297 
298     if (Abs(aMDPos.X() - aPos.X()) < nDrgLog &&
299         Abs(aMDPos.Y() - aPos.Y()) < nDrgLog &&
300         !rMEvt.IsShift() && !rMEvt.IsMod2())
301     {
302         SdrViewEvent aVEvt;
303         SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
304 
305         if (eHit == SDRHIT_NONE)
306         {
307             // Klick auf der Stelle: deselektieren
308             mpView->UnmarkAllObj();
309         }
310     }
311 
312     mpWindow->ReleaseMouse();
313 
314     return bReturn;
315 }
316 
317 /*************************************************************************
318 |*
319 |* Tastaturereignisse bearbeiten
320 |*
321 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
322 |* sal_False.
323 |*
324 \************************************************************************/
325 
326 sal_Bool FuEditGluePoints::KeyInput(const KeyEvent& rKEvt)
327 {
328     mpView->SetActualWin( mpWindow );
329 
330 //IAccessibility2 Implementation 2009-----
331     //Solution: Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
332     //and SHIFT+ENTER key to decide the postion and draw the new insert point
333     //sal_Bool bReturn = FuDraw::KeyInput(rKEvt);
334 
335     sal_Bool bReturn = sal_False;
336 
337     switch (rKEvt.GetKeyCode().GetCode())
338     {
339         case KEY_UP:
340         case KEY_DOWN:
341         case KEY_LEFT:
342         case KEY_RIGHT:
343         {
344             if(rKEvt.GetKeyCode().IsShift()&& mpView->IsInsGluePointMode() ){
345                 long nX = 0;
346                 long nY = 0;
347                 sal_uInt16  nCode = rKEvt.GetKeyCode().GetCode();
348                 if (nCode == KEY_UP)
349                 {
350                     // Scroll nach oben
351                     nX = 0;
352                     nY =-1;
353                 }
354                 else if (nCode == KEY_DOWN)
355                 {
356                     // Scroll nach unten
357                     nX = 0;
358                     nY = 1;
359                 }
360                 else if (nCode == KEY_LEFT)
361                 {
362                     // Scroll nach links
363                     nX =-1;
364                     nY = 0;
365                 }
366                 else if (nCode == KEY_RIGHT)
367                 {
368                     // Scroll nach rechts
369                     nX = 1;
370                     nY = 0;
371                 }
372                 Point centerPoint;
373                 Rectangle rect = mpView->GetMarkedObjRect();
374                 centerPoint = mpWindow->LogicToPixel(rect.Center());
375                 Point aPoint = bBeginInsertPoint? oldPoint:centerPoint;
376                 Point ePoint = aPoint + Point(nX,nY);
377                 mpWindow->SetPointerPosPixel(ePoint);
378                 //simulate mouse move action
379                 MouseEvent eMevt(ePoint,1,2,MOUSE_LEFT, 0);
380                 MouseMove(eMevt);
381                          Point aPix(eMevt.GetPosPixel());
382                 oldPoint = ePoint;
383                 bBeginInsertPoint = sal_True;
384                 bReturn = sal_True;
385             }
386         }
387         break;
388         case KEY_RETURN:
389             if(rKEvt.GetKeyCode().IsShift() && mpView->IsInsGluePointMode() )
390             {
391                 if(bBeginInsertPoint)
392                 {
393                     mpWindow->SetPointerPosPixel(oldPoint);
394                     //simulate mouse button down action
395                     MouseEvent aMevt(oldPoint,1,3,MOUSE_LEFT,KEY_SHIFT);
396                     // MT IA2: Not used?
397                     // sal_uInt16 ubuttons = aMevt.GetButtons();
398                     // sal_uInt16 uMod      = aMevt.GetModifier();
399                     MouseButtonDown(aMevt);
400                     mpWindow->CaptureMouse();
401                     //simulate mouse button up action
402                     MouseEvent rMEvt(oldPoint+Point(0,0),1,17, MOUSE_LEFT, KEY_SHIFT);
403                     MouseButtonUp(rMEvt);
404                     bReturn= sal_True;
405                 }
406             }
407             break;
408     }
409     if(!bReturn)
410         bReturn = FuDraw::KeyInput(rKEvt);
411 //-----IAccessibility2 Implementation 2009
412     return bReturn;
413 }
414 
415 //IAccessibility2 Implementation 2009-----
416  //Solution: Add Shift+UP/DOWN/LEFT/RIGHT key to move the position of insert point,
417  //and SHIFT+ENTER key to decide the postion and draw the new insert point
418 void FuEditGluePoints::ForcePointer(const MouseEvent* pMEvt)
419 {
420     if(bBeginInsertPoint && pMEvt)
421     {
422         MouseEvent aMEvt(pMEvt->GetPosPixel(), pMEvt->GetClicks(),
423             pMEvt->GetMode(), pMEvt->GetButtons(), pMEvt->GetModifier() & ~KEY_SHIFT);
424         FuDraw::ForcePointer(&aMEvt);
425     }
426     else
427     {
428         FuDraw::ForcePointer(pMEvt);
429     }
430 }
431 //-----IAccessibility2 Implementation 2009
432 /*************************************************************************
433 |*
434 |* Command-event
435 |*
436 \************************************************************************/
437 
438 sal_Bool FuEditGluePoints::Command(const CommandEvent& rCEvt)
439 {
440     mpView->SetActualWin( mpWindow );
441     return FuPoor::Command( rCEvt );
442 }
443 
444 /*************************************************************************
445 |*
446 |* Funktion aktivieren
447 |*
448 \************************************************************************/
449 
450 void FuEditGluePoints::Activate()
451 {
452     mpView->SetGluePointEditMode();
453     FuDraw::Activate();
454 }
455 
456 /*************************************************************************
457 |*
458 |* Funktion deaktivieren
459 |*
460 \************************************************************************/
461 
462 void FuEditGluePoints::Deactivate()
463 {
464     mpView->SetGluePointEditMode( sal_False );
465     FuDraw::Deactivate();
466 }
467 
468 /*************************************************************************
469 |*
470 |* Request verarbeiten
471 |*
472 \************************************************************************/
473 
474 void FuEditGluePoints::ReceiveRequest(SfxRequest& rReq)
475 {
476     switch (rReq.GetSlot())
477     {
478         case SID_GLUE_INSERT_POINT:
479         {
480             mpView->SetInsGluePointMode(!mpView->IsInsGluePointMode());
481         }
482         break;
483 
484         case SID_GLUE_ESCDIR_LEFT:
485         {
486             mpView->SetMarkedGluePointsEscDir( SDRESC_LEFT,
487                     !mpView->IsMarkedGluePointsEscDir( SDRESC_LEFT ) );
488         }
489         break;
490 
491         case SID_GLUE_ESCDIR_RIGHT:
492         {
493             mpView->SetMarkedGluePointsEscDir( SDRESC_RIGHT,
494                     !mpView->IsMarkedGluePointsEscDir( SDRESC_RIGHT ) );
495         }
496         break;
497 
498         case SID_GLUE_ESCDIR_TOP:
499         {
500             mpView->SetMarkedGluePointsEscDir( SDRESC_TOP,
501                     !mpView->IsMarkedGluePointsEscDir( SDRESC_TOP ) );
502         }
503         break;
504 
505         case SID_GLUE_ESCDIR_BOTTOM:
506         {
507             mpView->SetMarkedGluePointsEscDir( SDRESC_BOTTOM,
508                     !mpView->IsMarkedGluePointsEscDir( SDRESC_BOTTOM ) );
509         }
510         break;
511 
512         case SID_GLUE_PERCENT:
513         {
514             const SfxItemSet* pSet = rReq.GetArgs();
515             const SfxPoolItem& rItem = pSet->Get(SID_GLUE_PERCENT);
516             sal_Bool bPercent = ((const SfxBoolItem&) rItem).GetValue();
517             mpView->SetMarkedGluePointsPercent(bPercent);
518         }
519         break;
520 
521         case SID_GLUE_HORZALIGN_CENTER:
522         {
523             mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_CENTER);
524         }
525         break;
526 
527         case SID_GLUE_HORZALIGN_LEFT:
528         {
529             mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_LEFT);
530         }
531         break;
532 
533         case SID_GLUE_HORZALIGN_RIGHT:
534         {
535             mpView->SetMarkedGluePointsAlign(sal_False, SDRHORZALIGN_RIGHT);
536         }
537         break;
538 
539         case SID_GLUE_VERTALIGN_CENTER:
540         {
541             mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_CENTER);
542         }
543         break;
544 
545         case SID_GLUE_VERTALIGN_TOP:
546         {
547             mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_TOP);
548         }
549         break;
550 
551         case SID_GLUE_VERTALIGN_BOTTOM:
552         {
553             mpView->SetMarkedGluePointsAlign(sal_True, SDRVERTALIGN_BOTTOM);
554         }
555         break;
556     }
557 
558     // Zum Schluss Basisklasse rufen
559     FuPoor::ReceiveRequest(rReq);
560 }
561 
562 
563 } // end of namespace sd
564