tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / sd / source / ui / func / fupoor.cxx
blob5d952d1e4a406a1fa834a640bb7a5955343cd84f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <fupoor.hxx>
22 #include <svx/svxids.hrc>
23 #include <svx/svdpagv.hxx>
24 #include <svx/svdoole2.hxx>
25 #include <svx/svdograf.hxx>
26 #include <vcl/seleng.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/bindings.hxx>
29 #include <sfx2/request.hxx>
30 #include <svl/stritem.hxx>
32 #include <app.hrc>
33 #include <fusel.hxx>
34 #include <sdpage.hxx>
35 #include <DrawViewShell.hxx>
36 #include <Window.hxx>
37 #include <drawdoc.hxx>
38 #include <DrawDocShell.hxx>
39 #include <zoomlist.hxx>
40 #include <slideshow.hxx>
41 #include <LayerTabBar.hxx>
43 #include <com/sun/star/embed/EmbedVerbs.hpp>
45 #include <sfx2/viewfrm.hxx>
47 #include <svx/svditer.hxx>
49 #include <editeng/editeng.hxx>
51 using namespace ::com::sun::star;
53 namespace sd {
56 FuPoor::FuPoor (
57 ViewShell* pViewSh,
58 ::sd::Window* pWin,
59 ::sd::View* pView,
60 SdDrawDocument* pDrDoc,
61 SfxRequest& rReq)
62 : mpView(pView),
63 mpViewShell(pViewSh),
64 mpWindow(pWin),
65 mpDocSh( pDrDoc->GetDocSh() ),
66 mpDoc(pDrDoc),
67 nSlotId( rReq.GetSlot() ),
68 aScrollTimer("sd FuPoor aScrollTimer"),
69 aDragTimer("sd FuPoor aDragTimer"),
70 bIsInDragMode(false),
71 bNoScrollUntilInside (true),
72 aDelayToScrollTimer("sd FuPoor aDelayToScrollTimer"),
73 bScrollable (false),
74 bDelayActive (false),
75 bFirstMouseMove (false),
76 // remember MouseButton state
77 mnCode(0)
79 ReceiveRequest(rReq);
81 aScrollTimer.SetInvokeHandler( LINK(this, FuPoor, ScrollHdl) );
82 aScrollTimer.SetTimeout(SELENG_AUTOREPEAT_INTERVAL);
84 aDragTimer.SetInvokeHandler( LINK(this, FuPoor, DragHdl) );
85 aDragTimer.SetTimeout(SELENG_DRAGDROP_TIMEOUT);
87 aDelayToScrollTimer.SetInvokeHandler( LINK(this, FuPoor, DelayHdl) );
88 aDelayToScrollTimer.SetTimeout(2000);
91 FuPoor::~FuPoor()
93 aDragTimer.Stop();
94 aScrollTimer.Stop();
95 aDelayToScrollTimer.Stop();
98 void FuPoor::Activate()
102 void FuPoor::Deactivate()
104 aDragTimer.Stop();
105 aScrollTimer.Stop();
106 aDelayToScrollTimer.Stop ();
107 bScrollable = bDelayActive = false;
109 if (mpWindow && mpWindow->IsMouseCaptured())
110 mpWindow->ReleaseMouse();
113 void FuPoor::SetWindow(::sd::Window* pWin)
115 mpWindow = pWin;
119 * scroll when approached the border of the window; is called by MouseMove
121 void FuPoor::ForceScroll(const Point& aPixPos)
123 aScrollTimer.Stop();
125 if ( mpView->IsDragHelpLine() || mpView->IsSetPageOrg() ||
126 (SlideShow::IsRunning( mpViewShell->GetViewShellBase() )
127 && !SlideShow::IsInteractiveSlideshow( &mpViewShell->GetViewShellBase() )) ) // IASS
128 return;
130 Point aPos = mpWindow->OutputToScreenPixel(aPixPos);
131 const ::tools::Rectangle& rRect = mpViewShell->GetAllWindowRect();
133 if ( bNoScrollUntilInside )
135 if ( rRect.Contains(aPos) )
136 bNoScrollUntilInside = false;
138 else
140 short dx = 0, dy = 0;
142 if ( aPos.X() <= rRect.Left() ) dx = -1;
143 if ( aPos.X() >= rRect.Right() ) dx = 1;
144 if ( aPos.Y() <= rRect.Top() ) dy = -1;
145 if ( aPos.Y() >= rRect.Bottom() ) dy = 1;
147 if ( dx != 0 || dy != 0 )
149 if (bScrollable)
151 // scroll action in derived class
152 mpViewShell->ScrollLines(dx, dy);
153 aScrollTimer.Start();
155 else if (! bDelayActive) StartDelayToScrollTimer ();
161 * timer handler for window scrolling
163 IMPL_LINK_NOARG(FuPoor, ScrollHdl, Timer *, void)
165 Point aPnt(mpWindow->GetPointerPosPixel());
167 // use remembered MouseButton state to create correct
168 // MouseEvents for this artificial MouseMove.
169 MouseMove(MouseEvent(aPnt, 1, MouseEventModifiers::NONE, GetMouseButtonCode()));
173 * handle keyboard events
174 * @returns sal_True if the event was handled, sal_False otherwise
176 bool FuPoor::KeyInput(const KeyEvent& rKEvt)
178 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
179 bool bReturn = false;
180 bool bSlideShow = SlideShow::IsRunning( mpViewShell->GetViewShellBase() )
181 && !SlideShow::IsInteractiveSlideshow( &mpViewShell->GetViewShellBase() ); // IASS
183 switch (nCode)
185 case KEY_RETURN:
187 if(rKEvt.GetKeyCode().IsMod1())
189 if( auto pDrawViewShell = dynamic_cast<DrawViewShell *>( mpViewShell ))
191 SdPage* pActualPage = pDrawViewShell->GetActualPage();
192 SdrTextObj* pCandidate = nullptr;
194 if(pActualPage)
196 SdrObjListIter aIter(pActualPage, SdrIterMode::DeepNoGroups);
198 while(aIter.IsMore() && !pCandidate)
200 SdrObject* pObj = aIter.Next();
202 if(auto pTextObj = DynCastSdrTextObj( pObj ))
204 SdrInventor nInv(pObj->GetObjInventor());
205 SdrObjKind nKnd(pObj->GetObjIdentifier());
207 if(SdrInventor::Default == nInv &&
208 (SdrObjKind::TitleText == nKnd || SdrObjKind::OutlineText == nKnd || SdrObjKind::Text == nKnd))
210 pCandidate = pTextObj;
216 if(pCandidate)
218 mpView->UnMarkAll();
219 mpView->MarkObj(pCandidate, mpView->GetSdrPageView());
221 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(
222 SID_ATTR_CHAR, SfxCallMode::ASYNCHRON);
224 else
226 // insert a new page with the same page layout
227 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(
228 SID_INSERTPAGE_QUICK, SfxCallMode::ASYNCHRON);
231 // consumed
232 bReturn = true;
235 else if (!mpDocSh->IsReadOnly())
237 // activate OLE object on RETURN for selected object
238 // activate text edit on RETURN for selected object
239 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
241 if( !mpView->IsTextEdit() && 1 == rMarkList.GetMarkCount() )
243 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
245 if( dynamic_cast< const SdrOle2Obj* >( pObj ) && !mpDocSh->IsUIActive() )
247 //HMHmpView->HideMarkHdl();
248 mpViewShell->ActivateObject(static_cast<SdrOle2Obj*>(pObj), css::embed::EmbedVerbs::MS_OLEVERB_PRIMARY);
250 else if( pObj && pObj->IsEmptyPresObj() && dynamic_cast< const SdrGrafObj *>( pObj ) != nullptr )
252 mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_INSERT_GRAPHIC, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
254 else
256 mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_ATTR_CHAR, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
259 // consumed
260 bReturn = true;
264 break;
266 case KEY_TAB:
268 // handle Mod1 and Mod2 to get travelling running on different systems
269 if(rKEvt.GetKeyCode().IsMod1() || rKEvt.GetKeyCode().IsMod2())
271 // do something with a selected handle?
272 const SdrHdlList& rHdlList = mpView->GetHdlList();
273 bool bForward(!rKEvt.GetKeyCode().IsShift());
275 const_cast<SdrHdlList&>(rHdlList).TravelFocusHdl(bForward);
277 // guarantee visibility of focused handle
278 SdrHdl* pHdl = rHdlList.GetFocusHdl();
280 if(pHdl)
282 Point aHdlPosition(pHdl->GetPos());
283 ::tools::Rectangle aVisRect(aHdlPosition - Point(100, 100), Size(200, 200));
284 mpView->MakeVisible(aVisRect, *mpWindow);
287 // consumed
288 bReturn = true;
291 break;
293 case KEY_ESCAPE:
295 bReturn = FuPoor::cancel();
297 break;
299 case KEY_ADD:
301 if (!mpView->IsTextEdit() && !bSlideShow && !mpDocSh->IsUIActive())
303 // increase zoom
304 mpViewShell->SetZoom(mpWindow->GetZoom() * 3 / 2);
306 if( auto pViewShell = dynamic_cast<DrawViewShell *>( mpViewShell ))
307 pViewShell->SetZoomOnPage(false);
309 bReturn = true;
312 break;
314 case KEY_SUBTRACT:
316 if (!mpView->IsTextEdit() && !bSlideShow && !mpDocSh->IsUIActive())
318 // decrease zoom
319 mpViewShell->SetZoom(mpWindow->GetZoom() * 2 / 3);
321 if( auto pViewShell = dynamic_cast<DrawViewShell *>( mpViewShell ))
322 pViewShell->SetZoomOnPage(false);
324 bReturn = true;
327 break;
329 case KEY_MULTIPLY:
331 if (!mpView->IsTextEdit() && !bSlideShow)
333 // zoom to page
334 mpViewShell->GetViewFrame()->GetDispatcher()->
335 Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
336 bReturn = true;
339 break;
341 case KEY_DIVIDE:
343 if (!mpView->IsTextEdit() && !bSlideShow)
345 // zoom to selected objects
346 mpViewShell->GetViewFrame()->GetDispatcher()->
347 Execute(SID_SIZE_OPTIMAL, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
348 bReturn = true;
351 break;
353 case KEY_POINT:
355 ZoomList* pZoomList = mpViewShell->GetZoomList();
357 if (!mpView->IsTextEdit() && pZoomList->IsNextPossible() && !bSlideShow && !mpDocSh->IsUIActive())
359 // use next ZoomRect
360 mpViewShell->SetZoomRect(pZoomList->GetNextZoomRect());
361 bReturn = true;
364 break;
366 case KEY_COMMA:
368 ZoomList* pZoomList = mpViewShell->GetZoomList();
370 if (!mpView->IsTextEdit() && pZoomList->IsPreviousPossible() && !bSlideShow && !mpDocSh->IsUIActive())
372 // use previous ZoomRect
373 mpViewShell->SetZoomRect(pZoomList->GetPreviousZoomRect());
374 bReturn = true;
377 break;
379 case KEY_HOME:
381 if (!mpView->IsTextEdit() && !bSlideShow)
382 if (auto pDrawViewShell = dynamic_cast<DrawViewShell *>( mpViewShell ))
384 // jump to first page
385 pDrawViewShell->SwitchPage(0);
386 bReturn = true;
389 break;
391 case KEY_END:
393 if (!mpView->IsTextEdit() && !bSlideShow)
394 if (auto pDrawViewShell = dynamic_cast<DrawViewShell *>( mpViewShell ))
396 // jump to last page
397 SdPage* pPage = pDrawViewShell->GetActualPage();
398 pDrawViewShell->SwitchPage(mpDoc->GetSdPageCount(
399 pPage->GetPageKind()) - 1);
400 bReturn = true;
403 break;
405 case KEY_PAGEUP:
407 if( rKEvt.GetKeyCode().IsMod1() && rKEvt.GetKeyCode().IsMod2() )
408 break;
409 if( bSlideShow)
410 break;
412 if( auto pDrawViewShell = dynamic_cast<DrawViewShell *>( mpViewShell ) )
414 // The page-up key switches layers or pages depending on the
415 // modifier key.
416 if ( ! rKEvt.GetKeyCode().GetModifier())
418 // With no modifier pressed we move to the previous
419 // slide.
420 mpView->SdrEndTextEdit();
422 // Previous page.
423 bReturn = true;
424 SdPage* pPage = pDrawViewShell->GetActualPage();
425 sal_uInt16 nSdPage = (pPage->GetPageNum() - 1) / 2;
427 if (nSdPage > 0)
429 // Switch the page and send events regarding
430 // deactivation the old page and activating the new
431 // one.
432 TabControl& rPageTabControl =
433 pDrawViewShell->GetPageTabControl();
434 if (rPageTabControl.IsReallyShown())
435 rPageTabControl.SendDeactivatePageEvent ();
436 pDrawViewShell->SwitchPage(nSdPage - 1);
437 if (rPageTabControl.IsReallyShown())
438 rPageTabControl.SendActivatePageEvent ();
441 else if (rKEvt.GetKeyCode().IsMod1())
443 // With the CONTROL modifier we switch layers.
444 if (pDrawViewShell->IsLayerModeActive())
446 // Moves to the previous layer.
447 SwitchLayer (-1);
452 break;
454 case KEY_PAGEDOWN:
456 if( rKEvt.GetKeyCode().IsMod1() && rKEvt.GetKeyCode().IsMod2() )
457 break;
458 if(dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr && !bSlideShow)
460 // The page-down key switches layers or pages depending on the
461 // modifier key.
462 if ( ! rKEvt.GetKeyCode().GetModifier())
464 // With no modifier pressed we move to the next slide.
465 mpView->SdrEndTextEdit();
467 // Next page.
468 bReturn = true;
469 SdPage* pPage = static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
470 sal_uInt16 nSdPage = (pPage->GetPageNum() - 1) / 2;
472 if (nSdPage < mpDoc->GetSdPageCount(pPage->GetPageKind()) - 1)
474 // Switch the page and send events regarding
475 // deactivation the old page and activating the new
476 // one.
477 TabControl& rPageTabControl =
478 static_cast<DrawViewShell*>(mpViewShell)->GetPageTabControl();
479 if (rPageTabControl.IsReallyShown())
480 rPageTabControl.SendDeactivatePageEvent ();
481 static_cast<DrawViewShell*>(mpViewShell)->SwitchPage(nSdPage + 1);
482 if (rPageTabControl.IsReallyShown())
483 rPageTabControl.SendActivatePageEvent ();
486 else if (rKEvt.GetKeyCode().IsMod1())
488 // With the CONTROL modifier we switch layers.
489 if (static_cast<DrawViewShell*>(mpViewShell)->IsLayerModeActive())
491 // With the layer mode active pressing page-down
492 // moves to the next layer.
493 SwitchLayer (+1);
498 break;
500 // change select state when focus is on poly point
501 case KEY_SPACE:
503 const SdrHdlList& rHdlList = mpView->GetHdlList();
504 SdrHdl* pHdl = rHdlList.GetFocusHdl();
506 if(pHdl)
508 if(pHdl->GetKind() == SdrHdlKind::Poly)
510 // rescue ID of point with focus
511 sal_uInt32 nPol(pHdl->GetPolyNum());
512 sal_uInt32 nPnt(pHdl->GetPointNum());
514 if(mpView->IsPointMarked(*pHdl))
516 if(rKEvt.GetKeyCode().IsShift())
518 mpView->UnmarkPoint(*pHdl);
521 else
523 if(!rKEvt.GetKeyCode().IsShift())
525 mpView->UnmarkAllPoints();
528 mpView->MarkPoint(*pHdl);
531 if(nullptr == rHdlList.GetFocusHdl())
533 // restore point with focus
534 SdrHdl* pNewOne = nullptr;
536 for(size_t a = 0; !pNewOne && a < rHdlList.GetHdlCount(); ++a)
538 SdrHdl* pAct = rHdlList.GetHdl(a);
540 if(pAct
541 && pAct->GetKind() == SdrHdlKind::Poly
542 && pAct->GetPolyNum() == nPol
543 && pAct->GetPointNum() == nPnt)
545 pNewOne = pAct;
549 if(pNewOne)
551 const_cast<SdrHdlList&>(rHdlList).SetFocusHdl(pNewOne);
555 bReturn = true;
559 break;
561 case KEY_UP:
562 case KEY_DOWN:
563 case KEY_LEFT:
564 case KEY_RIGHT:
566 if (!mpView->IsTextEdit() && !bSlideShow)
568 ::tools::Long nX = 0;
569 ::tools::Long nY = 0;
571 if (nCode == KEY_UP)
573 // scroll up
574 nX = 0;
575 nY =-1;
577 else if (nCode == KEY_DOWN)
579 // scroll down
580 nX = 0;
581 nY = 1;
583 else if (nCode == KEY_LEFT)
585 // scroll left
586 nX =-1;
587 nY = 0;
589 else if (nCode == KEY_RIGHT)
591 // scroll right
592 nX = 1;
593 nY = 0;
596 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
597 if (rMarkList.GetMarkCount() != 0 && !rKEvt.GetKeyCode().IsMod1() &&
598 !mpDocSh->IsReadOnly())
600 const SdrHdlList& rHdlList = mpView->GetHdlList();
601 SdrHdl* pHdl = rHdlList.GetFocusHdl();
603 bool bIsMoveOfConnectedHandle(false);
604 bool bOldSuppress = false;
605 SdrEdgeObj* pEdgeObj = nullptr;
606 if(pHdl)
607 pEdgeObj = dynamic_cast<SdrEdgeObj *>( pHdl->GetObj() );
609 if(pEdgeObj && 0 == pHdl->GetPolyNum())
611 if(0 == pHdl->GetPointNum())
613 if(pEdgeObj->GetConnection(true).GetSdrObject())
615 bIsMoveOfConnectedHandle = true;
618 if(1 == pHdl->GetPointNum())
620 if(pEdgeObj->GetConnection(false).GetSdrObject())
622 bIsMoveOfConnectedHandle = true;
627 if(pEdgeObj)
629 // Suppress default connects to inside object and object center
630 bOldSuppress = pEdgeObj->GetSuppressDefaultConnect();
631 pEdgeObj->SetSuppressDefaultConnect(true);
634 if(bIsMoveOfConnectedHandle)
636 sal_uInt16 nMarkHdSiz(mpView->GetMarkHdlSizePixel());
637 Size aHalfConSiz(nMarkHdSiz + 1, nMarkHdSiz + 1);
638 aHalfConSiz = mpWindow->PixelToLogic(aHalfConSiz);
640 if(100 < aHalfConSiz.Width())
641 nX *= aHalfConSiz.Width();
642 else
643 nX *= 100;
645 if(100 < aHalfConSiz.Height())
646 nY *= aHalfConSiz.Height();
647 else
648 nY *= 100;
650 else if(rKEvt.GetKeyCode().IsMod2())
652 // move in 1 pixel distance
653 Size aLogicSizeOnePixel = mpWindow->PixelToLogic(Size(1,1));
654 nX *= aLogicSizeOnePixel.Width();
655 nY *= aLogicSizeOnePixel.Height();
657 else if(rKEvt.GetKeyCode().IsShift())
659 nX *= 1000;
660 nY *= 1000;
662 else
664 // old, fixed move distance
665 nX *= 100;
666 nY *= 100;
669 if(nullptr == pHdl)
671 // only take action when move is allowed
672 if(mpView->IsMoveAllowed())
674 // restrict movement to WorkArea
675 const ::tools::Rectangle& rWorkArea = mpView->GetWorkArea();
677 if(!rWorkArea.IsEmpty())
679 ::tools::Rectangle aMarkRect(mpView->GetMarkedObjRect());
680 aMarkRect.Move(nX, nY);
682 if(!aMarkRect.Contains(rWorkArea))
684 if(aMarkRect.Left() < rWorkArea.Left())
686 nX += rWorkArea.Left() - aMarkRect.Left();
689 if(aMarkRect.Right() > rWorkArea.Right())
691 nX -= aMarkRect.Right() - rWorkArea.Right();
694 if(aMarkRect.Top() < rWorkArea.Top())
696 nY += rWorkArea.Top() - aMarkRect.Top();
699 if(aMarkRect.Bottom() > rWorkArea.Bottom())
701 nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
706 // no handle selected
707 if(0 != nX || 0 != nY)
709 mpView->MoveAllMarked(Size(nX, nY));
711 mpView->MakeVisible(mpView->GetAllMarkedRect(), *mpWindow);
715 else
717 // move handle with index nHandleIndex
718 if (nX || nY)
720 // now move the Handle (nX, nY)
721 Point aStartPoint(pHdl->GetPos());
722 Point aEndPoint(pHdl->GetPos() + Point(nX, nY));
723 const SdrDragStat& rDragStat = mpView->GetDragStat();
725 // start dragging
726 mpView->BegDragObj(aStartPoint, nullptr, pHdl, 0);
728 if(mpView->IsDragObj())
730 bool bWasNoSnap = rDragStat.IsNoSnap();
731 bool bWasSnapEnabled = mpView->IsSnapEnabled();
733 // switch snapping off
734 if(!bWasNoSnap)
735 const_cast<SdrDragStat&>(rDragStat).SetNoSnap();
736 if(bWasSnapEnabled)
737 mpView->SetSnapEnabled(false);
739 mpView->MovAction(aEndPoint);
740 mpView->EndDragObj();
742 // restore snap
743 if(!bWasNoSnap)
744 const_cast<SdrDragStat&>(rDragStat).SetNoSnap(bWasNoSnap);
745 if(bWasSnapEnabled)
746 mpView->SetSnapEnabled(bWasSnapEnabled);
749 // make moved handle visible
750 ::tools::Rectangle aVisRect(aEndPoint - Point(100, 100), Size(200, 200));
751 mpView->MakeVisible(aVisRect, *mpWindow);
755 if(pEdgeObj)
757 // Restore original suppress value
758 pEdgeObj->SetSuppressDefaultConnect(bOldSuppress);
761 else
763 // scroll page
764 mpViewShell->ScrollLines(nX, nY);
767 bReturn = true;
770 break;
773 if (bReturn)
775 mpWindow->ReleaseMouse();
778 // when a text-editable object is selected and the
779 // input character is printable, activate text edit on that object
780 // and feed character to object
781 if(!bReturn && !mpDocSh->IsReadOnly())
783 if (!mpView->IsTextEdit())
785 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
787 if(1 == rMarkList.GetMarkCount())
789 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
791 // #i118485# allow TextInput for OLEs, too
792 if( DynCastSdrTextObj( pObj ) != nullptr && pObj->HasTextEdit())
794 // use common IsSimpleCharInput from the EditEngine.
795 bool bPrintable(EditEngine::IsSimpleCharInput(rKEvt));
797 if(bPrintable)
799 // try to activate textedit mode for the selected object
800 SfxStringItem aInputString(SID_ATTR_CHAR, OUString(rKEvt.GetCharCode()));
802 mpViewShell->GetViewFrame()->GetDispatcher()->ExecuteList(
803 SID_ATTR_CHAR,
804 SfxCallMode::ASYNCHRON,
805 { &aInputString });
807 // consumed
808 bReturn = true;
812 else
814 // test if there is a title object there. If yes, try to
815 // set it to edit mode and start typing...
816 DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(mpViewShell);
817 if (pDrawViewShell && EditEngine::IsSimpleCharInput(rKEvt))
819 SdPage* pActualPage = pDrawViewShell->GetActualPage();
820 SdrTextObj* pCandidate = nullptr;
822 if(pActualPage)
824 SdrObjListIter aIter(pActualPage, SdrIterMode::DeepNoGroups);
826 while(aIter.IsMore() && !pCandidate)
828 SdrObject* pObj = aIter.Next();
830 if(auto pTextObj = DynCastSdrTextObj( pObj ))
832 SdrInventor nInv(pObj->GetObjInventor());
833 SdrObjKind nKnd(pObj->GetObjIdentifier());
835 if(SdrInventor::Default == nInv && SdrObjKind::TitleText == nKnd)
837 pCandidate = pTextObj;
843 // when candidate found and candidate is untouched, start editing text...
844 if(pCandidate && pCandidate->IsEmptyPresObj())
846 mpView->UnMarkAll();
847 mpView->MarkObj(pCandidate, mpView->GetSdrPageView());
848 SfxStringItem aInputString(SID_ATTR_CHAR, OUString(rKEvt.GetCharCode()));
850 mpViewShell->GetViewFrame()->GetDispatcher()->ExecuteList(
851 SID_ATTR_CHAR,
852 SfxCallMode::ASYNCHRON,
853 { &aInputString });
855 // consumed
856 bReturn = true;
863 return bReturn;
866 bool FuPoor::MouseMove(const MouseEvent& )
868 return false;
871 void FuPoor::SelectionHasChanged()
873 const SdrHdlList& rHdlList = mpView->GetHdlList();
874 const_cast<SdrHdlList&>(rHdlList).ResetFocusHdl();
878 * Cut object to clipboard
880 void FuPoor::DoCut()
882 if (mpView)
884 mpView->DoCut();
889 * Copy object to clipboard
891 void FuPoor::DoCopy()
893 if (mpView)
895 mpView->DoCopy();
900 * Paste object from clipboard
902 void FuPoor::DoPaste()
904 if (mpView)
906 mpView->DoPaste(mpWindow);
911 * Paste unformatted text from clipboard
913 void FuPoor::DoPasteUnformatted()
915 if (mpView)
917 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewShell->GetActiveWindow() ) );
918 if (aDataHelper.GetTransferable().is())
920 sal_Int8 nAction = DND_ACTION_COPY;
921 mpView->InsertData( aDataHelper,
922 mpWindow->PixelToLogic( ::tools::Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
923 nAction, false, SotClipboardFormatId::STRING);
929 * Timer handler for Drag&Drop
931 IMPL_LINK_NOARG(FuPoor, DragHdl, Timer *, void)
933 if( !mpView )
934 return;
936 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
937 SdrHdl* pHdl = mpView->PickHandle(aMDPos);
939 if ( pHdl==nullptr && mpView->IsMarkedHit(aMDPos, nHitLog)
940 && !mpView->IsPresObjSelected(false) )
942 mpWindow->ReleaseMouse();
943 bIsInDragMode = true;
944 mpView->StartDrag( aMDPos, mpWindow );
948 bool FuPoor::Command(const CommandEvent& rCEvt)
950 return mpView->Command(rCEvt,mpWindow);
954 * Timer handler for window scrolling
956 IMPL_LINK_NOARG(FuPoor, DelayHdl, Timer *, void)
958 aDelayToScrollTimer.Stop ();
959 bScrollable = true;
961 Point aPnt(mpWindow->GetPointerPosPixel());
963 // use remembered MouseButton state to create correct
964 // MouseEvents for this artificial MouseMove.
965 MouseMove(MouseEvent(aPnt, 1, MouseEventModifiers::NONE, GetMouseButtonCode()));
968 bool FuPoor::MouseButtonUp (const MouseEvent& rMEvt)
970 // remember button state for creation of own MouseEvents
971 SetMouseButtonCode(rMEvt.GetButtons());
973 aDelayToScrollTimer.Stop ();
974 bScrollable = bDelayActive = false;
975 return bScrollable;
978 bool FuPoor::MouseButtonDown(const MouseEvent& rMEvt)
980 // remember button state for creation of own MouseEvents
981 SetMouseButtonCode(rMEvt.GetButtons());
983 return false;
986 void FuPoor::StartDelayToScrollTimer ()
988 bDelayActive = true;
989 aDelayToScrollTimer.Start ();
992 bool FuPoor::RequestHelp(const HelpEvent& rHEvt)
994 bool bReturn = false;
996 SdrPageView* pPV = mpView->GetSdrPageView();
998 if (pPV)
1000 SdPage* pPage = static_cast<SdPage*>( pPV->GetPage() );
1002 if (pPage)
1004 bReturn = FmFormPage::RequestHelp(mpWindow, mpView, rHEvt);
1008 return bReturn;
1011 void FuPoor::ReceiveRequest(SfxRequest& /*rReq*/)
1015 rtl::Reference<SdrObject> FuPoor::CreateDefaultObject(const sal_uInt16, const ::tools::Rectangle& )
1017 // empty base implementation
1018 return nullptr;
1021 void FuPoor::ImpForceQuadratic(::tools::Rectangle& rRect)
1023 if(rRect.GetWidth() > rRect.GetHeight())
1025 rRect = ::tools::Rectangle(
1026 Point(rRect.Left() + ((rRect.GetWidth() - rRect.GetHeight()) / 2), rRect.Top()),
1027 Size(rRect.GetHeight(), rRect.GetHeight()));
1029 else
1031 rRect = ::tools::Rectangle(
1032 Point(rRect.Left(), rRect.Top() + ((rRect.GetHeight() - rRect.GetWidth()) / 2)),
1033 Size(rRect.GetWidth(), rRect.GetWidth()));
1037 void FuPoor::SwitchLayer (sal_Int32 nOffset)
1039 auto pDrawViewShell = dynamic_cast<DrawViewShell *>( mpViewShell );
1040 if(!pDrawViewShell)
1041 return;
1043 // Calculate the new index.
1044 sal_Int32 nIndex = pDrawViewShell->GetActiveTabLayerIndex() + nOffset;
1046 // Make sure the new index lies inside the range of valid indices.
1047 if (nIndex < 0)
1048 nIndex = 0;
1049 else if (nIndex >= pDrawViewShell->GetTabLayerCount ())
1050 nIndex = pDrawViewShell->GetTabLayerCount() - 1;
1052 // Set the new active layer.
1053 if (nIndex != pDrawViewShell->GetActiveTabLayerIndex ())
1055 LayerTabBar* pLayerTabControl =
1056 static_cast<DrawViewShell*>(mpViewShell)->GetLayerTabControl();
1057 if (pLayerTabControl != nullptr)
1058 pLayerTabControl->SendDeactivatePageEvent ();
1060 pDrawViewShell->SetActiveTabLayerIndex (nIndex);
1062 if (pLayerTabControl != nullptr)
1063 pLayerTabControl->SendActivatePageEvent ();
1067 /** is called when the current function should be aborted. <p>
1068 This is used when a function gets a KEY_ESCAPE but can also
1069 be called directly.
1071 @returns true if an active function was aborted
1073 bool FuPoor::cancel()
1075 if ( dynamic_cast< const FuSelection *>( this ) == nullptr )
1077 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
1078 return true;
1081 return false;
1084 // #i33136#
1085 bool FuPoor::doConstructOrthogonal() const
1087 // Check whether a media object is selected
1088 bool bResizeKeepRatio = false;
1089 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
1090 // tdf#89758 Avoid interactive crop preview from being proportionally scaled by default.
1091 if (rMarkList.GetMarkCount() != 0 && mpView->GetDragMode() != SdrDragMode::Crop)
1093 if (rMarkList.GetMarkCount() == 1)
1095 SdrObjKind aObjIdentifier = rMarkList.GetMark(0)->GetMarkedSdrObj()->GetObjIdentifier();
1096 bResizeKeepRatio = aObjIdentifier == SdrObjKind::Graphic ||
1097 aObjIdentifier == SdrObjKind::Media ||
1098 aObjIdentifier == SdrObjKind::OLE2;
1101 SdrHdl* pHdl = mpView->PickHandle(aMDPos);
1102 // Resize proportionally when media is selected and the user drags on a corner
1103 if (pHdl)
1104 bResizeKeepRatio = bResizeKeepRatio && pHdl->IsCornerHdl();
1106 return (
1107 bResizeKeepRatio ||
1108 SID_DRAW_XLINE == nSlotId ||
1109 SID_DRAW_CIRCLEARC == nSlotId ||
1110 SID_DRAW_SQUARE == nSlotId ||
1111 SID_DRAW_SQUARE_NOFILL == nSlotId ||
1112 SID_DRAW_SQUARE_ROUND == nSlotId ||
1113 SID_DRAW_SQUARE_ROUND_NOFILL == nSlotId ||
1114 SID_DRAW_CIRCLE == nSlotId ||
1115 SID_DRAW_CIRCLE_NOFILL == nSlotId ||
1116 SID_DRAW_CIRCLEPIE == nSlotId ||
1117 SID_DRAW_CIRCLEPIE_NOFILL == nSlotId ||
1118 SID_DRAW_CIRCLECUT == nSlotId ||
1119 SID_DRAW_CIRCLECUT_NOFILL == nSlotId ||
1120 SID_DRAW_XPOLYGON == nSlotId ||
1121 SID_DRAW_XPOLYGON_NOFILL == nSlotId ||
1122 SID_3D_CUBE == nSlotId ||
1123 SID_3D_SPHERE == nSlotId ||
1124 SID_3D_SHELL == nSlotId ||
1125 SID_3D_HALF_SPHERE == nSlotId ||
1126 SID_3D_TORUS == nSlotId ||
1127 SID_3D_CYLINDER == nSlotId ||
1128 SID_3D_CONE == nSlotId ||
1129 SID_3D_PYRAMID == nSlotId);
1132 void FuPoor::DoExecute( SfxRequest& )
1136 } // end of namespace sd
1138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */