Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / ui / drawfunc / fuconstr.cxx
blob28ce53300be9ba50b2c84c304308df1b1a1d425c
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 <editeng/outlobj.hxx>
21 #include <svx/svdotext.hxx>
22 #include <svx/svdouno.hxx>
23 #include <svx/svxids.hrc>
24 #include <sfx2/dispatch.hxx>
26 #include <fuconstr.hxx>
27 #include <fudraw.hxx>
28 #include <tabvwsh.hxx>
29 #include <futext.hxx>
30 #include <drawview.hxx>
32 // maximal permitted mouse movement to start Drag&Drop
33 //! fusel,fuconstr,futext - combine them!
34 #define SC_MAXDRAGMOVE 3
36 FuConstruct::FuConstruct(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawView* pViewP,
37 SdrModel* pDoc, const SfxRequest& rReq)
38 : FuDraw(rViewSh, pWin, pViewP, pDoc, rReq)
42 FuConstruct::~FuConstruct()
46 bool FuConstruct::MouseButtonDown(const MouseEvent& rMEvt)
48 // remember button state for creation of own MouseEvents
49 SetMouseButtonCode(rMEvt.GetButtons());
51 bool bReturn = FuDraw::MouseButtonDown(rMEvt);
53 if ( pView->IsAction() )
55 if ( rMEvt.IsRight() )
56 pView->BckAction();
57 return true;
60 aDragTimer.Start();
62 aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
64 if ( rMEvt.IsLeft() )
66 pWindow->CaptureMouse();
68 SdrHdl* pHdl = pView->PickHandle(aMDPos);
70 if ( pHdl != nullptr || pView->IsMarkedHit(aMDPos) )
72 pView->BegDragObj(aMDPos, nullptr, pHdl, 1);
73 bReturn = true;
75 else if ( pView->AreObjectsMarked() )
77 pView->UnmarkAll();
78 bReturn = true;
82 bIsInDragMode = false;
84 return bReturn;
87 bool FuConstruct::MouseMove(const MouseEvent& rMEvt)
89 FuDraw::MouseMove(rMEvt);
91 if (aDragTimer.IsActive() )
93 Point aOldPixel = pWindow->LogicToPixel( aMDPos );
94 Point aNewPixel = rMEvt.GetPosPixel();
95 if ( std::abs( aOldPixel.X() - aNewPixel.X() ) > SC_MAXDRAGMOVE ||
96 std::abs( aOldPixel.Y() - aNewPixel.Y() ) > SC_MAXDRAGMOVE )
97 aDragTimer.Stop();
100 Point aPix(rMEvt.GetPosPixel());
101 Point aPnt( pWindow->PixelToLogic(aPix) );
103 if ( pView->IsAction() )
105 ForceScroll(aPix);
106 pView->MovAction(aPnt);
108 else
110 SdrHdl* pHdl=pView->PickHandle(aPnt);
112 if ( pHdl != nullptr )
114 rViewShell.SetActivePointer(pHdl->GetPointer());
116 else if ( pView->IsMarkedHit(aPnt) )
118 rViewShell.SetActivePointer(PointerStyle::Move);
120 else
122 rViewShell.SetActivePointer( aNewPointer );
125 return true;
128 bool FuConstruct::MouseButtonUp(const MouseEvent& rMEvt)
130 // remember button state for creation of own MouseEvents
131 SetMouseButtonCode(rMEvt.GetButtons());
133 bool bReturn = SimpleMouseButtonUp( rMEvt );
135 // Double-click on text object? (->fusel)
137 sal_uInt16 nClicks = rMEvt.GetClicks();
138 if ( nClicks == 2 && rMEvt.IsLeft() )
140 if ( pView->AreObjectsMarked() )
142 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
143 if (rMarkList.GetMarkCount() == 1)
145 SdrMark* pMark = rMarkList.GetMark(0);
146 SdrObject* pObj = pMark->GetMarkedSdrObj();
148 // if Uno-Controls no text mode
149 if ( dynamic_cast<const SdrTextObj*>( pObj) != nullptr && dynamic_cast<const SdrUnoObj*>( pObj) == nullptr )
151 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
152 bool bVertical = ( pOPO && pOPO->IsVertical() );
153 sal_uInt16 nTextSlotId = bVertical ? SID_DRAW_TEXT_VERTICAL : SID_DRAW_TEXT;
155 rViewShell.GetViewData().GetDispatcher().
156 Execute(nTextSlotId, SfxCallMode::SLOT | SfxCallMode::RECORD);
158 // Get the created FuText now and change into EditMode
159 FuPoor* pPoor = rViewShell.GetViewData().GetView()->GetDrawFuncPtr();
160 if ( pPoor && pPoor->GetSlotID() == nTextSlotId ) // has no RTTI
162 FuText* pText = static_cast<FuText*>(pPoor);
163 Point aMousePixel = rMEvt.GetPosPixel();
164 pText->SetInEditMode( pObj, &aMousePixel );
166 bReturn = true;
172 FuDraw::MouseButtonUp(rMEvt);
174 return bReturn;
177 // SimpleMouseButtonUp - no test on double-click
179 bool FuConstruct::SimpleMouseButtonUp(const MouseEvent& rMEvt)
181 bool bReturn = true;
183 if (aDragTimer.IsActive() )
185 aDragTimer.Stop();
188 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
190 if ( pView->IsDragObj() )
191 pView->EndDragObj( rMEvt.IsMod1() );
193 else if ( pView->IsMarkObj() )
194 pView->EndMarkObj();
196 else bReturn = false;
198 if ( !pView->IsAction() )
200 pWindow->ReleaseMouse();
202 if ( !pView->AreObjectsMarked() && rMEvt.GetClicks() < 2 )
204 pView->MarkObj(aPnt, -2, false, rMEvt.IsMod1());
206 SfxDispatcher& rDisp = rViewShell.GetViewData().GetDispatcher();
207 if ( pView->AreObjectsMarked() )
208 rDisp.Execute(SID_OBJECT_SELECT, SfxCallMode::SLOT | SfxCallMode::RECORD);
209 else
210 rDisp.Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
214 return bReturn;
217 // If we handle a KeyEvent, then the return value is sal_True else FALSE.
218 bool FuConstruct::KeyInput(const KeyEvent& rKEvt)
220 bool bReturn = false;
222 switch ( rKEvt.GetKeyCode().GetCode() )
224 case KEY_ESCAPE:
225 if ( pView->IsAction() )
227 pView->BrkAction();
228 pWindow->ReleaseMouse();
229 bReturn = true;
231 else // end drawing mode
233 rViewShell.GetViewData().GetDispatcher().
234 Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
236 break;
238 case KEY_DELETE:
239 pView->DeleteMarked();
240 bReturn = true;
241 break;
244 if ( !bReturn )
246 bReturn = FuDraw::KeyInput(rKEvt);
249 return bReturn;
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */