tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / drawfunc / fuconstr.cxx
blob717bb3db7a5c7eeec75443feb7d16c7733b7bc48
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/svdouno.hxx>
22 #include <svx/svxids.hrc>
23 #include <sfx2/dispatch.hxx>
25 #include <fuconstr.hxx>
26 #include <fudraw.hxx>
27 #include <tabvwsh.hxx>
28 #include <futext.hxx>
29 #include <drawview.hxx>
31 // maximal permitted mouse movement to start Drag&Drop
32 //! fusel,fuconstr,futext - combine them!
33 #define SC_MAXDRAGMOVE 3
35 FuConstruct::FuConstruct(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawView* pViewP,
36 SdrModel* pDoc, const SfxRequest& rReq)
37 : FuDraw(rViewSh, pWin, pViewP, pDoc, rReq)
41 FuConstruct::~FuConstruct()
45 bool FuConstruct::MouseButtonDown(const MouseEvent& rMEvt)
47 // remember button state for creation of own MouseEvents
48 SetMouseButtonCode(rMEvt.GetButtons());
50 bool bReturn = FuDraw::MouseButtonDown(rMEvt);
52 if ( pView->IsAction() )
54 if ( rMEvt.IsRight() )
55 pView->BckAction();
56 return true;
59 aDragTimer.Start();
61 aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
63 if ( rMEvt.IsLeft() )
65 pWindow->CaptureMouse();
67 SdrHdl* pHdl = pView->PickHandle(aMDPos);
69 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
70 if ( pHdl != nullptr || pView->IsMarkedHit(aMDPos) )
72 pView->BegDragObj(aMDPos, nullptr, pHdl, 1);
73 bReturn = true;
75 else if ( rMarkList.GetMarkCount() != 0 )
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 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
141 if ( rMarkList.GetMarkCount() != 0 )
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 ( DynCastSdrTextObj( pObj) != nullptr && dynamic_cast<const SdrUnoObj*>( pObj) == nullptr )
151 assert(pObj);
152 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
153 bool bVertical = ( pOPO && pOPO->IsEffectivelyVertical() );
154 sal_uInt16 nTextSlotId = bVertical ? SID_DRAW_TEXT_VERTICAL : SID_DRAW_TEXT;
156 rViewShell.GetViewData().GetDispatcher().
157 Execute(nTextSlotId, SfxCallMode::SLOT | SfxCallMode::RECORD);
159 // Get the created FuText now and change into EditMode
160 FuPoor* pPoor = rViewShell.GetViewData().GetView()->GetDrawFuncPtr();
161 if ( pPoor && pPoor->GetSlotID() == nTextSlotId ) // has no RTTI
163 FuText* pText = static_cast<FuText*>(pPoor);
164 Point aMousePixel = rMEvt.GetPosPixel();
165 pText->SetInEditMode( pObj, &aMousePixel );
167 bReturn = true;
173 FuDraw::MouseButtonUp(rMEvt);
175 return bReturn;
178 // SimpleMouseButtonUp - no test on double-click
180 bool FuConstruct::SimpleMouseButtonUp(const MouseEvent& rMEvt)
182 bool bReturn = true;
184 if (aDragTimer.IsActive() )
186 aDragTimer.Stop();
189 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
191 if ( pView->IsDragObj() )
192 pView->EndDragObj( rMEvt.IsMod1() );
194 else if ( pView->IsMarkObj() )
195 pView->EndMarkObj();
197 else bReturn = false;
199 if ( !pView->IsAction() )
201 pWindow->ReleaseMouse();
203 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
204 if ( rMarkList.GetMarkCount() == 0 && rMEvt.GetClicks() < 2 )
206 pView->MarkObj(aPnt, -2, false, rMEvt.IsMod1());
208 SfxDispatcher& rDisp = rViewShell.GetViewData().GetDispatcher();
209 if ( rMarkList.GetMarkCount() != 0 )
210 rDisp.Execute(SID_OBJECT_SELECT, SfxCallMode::SLOT | SfxCallMode::RECORD);
211 else
212 rDisp.Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
216 return bReturn;
219 // If we handle a KeyEvent, then the return value is sal_True else FALSE.
220 bool FuConstruct::KeyInput(const KeyEvent& rKEvt)
222 bool bReturn = false;
224 switch ( rKEvt.GetKeyCode().GetCode() )
226 case KEY_ESCAPE:
227 if ( pView->IsAction() )
229 pView->BrkAction();
230 pWindow->ReleaseMouse();
231 bReturn = true;
233 else // end drawing mode
235 rViewShell.GetViewData().GetDispatcher().
236 Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
238 break;
240 case KEY_DELETE:
241 pView->DeleteMarked();
242 bReturn = true;
243 break;
246 if ( !bReturn )
248 bReturn = FuDraw::KeyInput(rKEvt);
251 return bReturn;
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */