1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/outliner.hxx>
21 #include <editeng/outlobj.hxx>
22 #include <svx/svdotext.hxx>
23 #include <svx/svdouno.hxx>
24 #include <sfx2/dispatch.hxx>
26 #include "fuconstr.hxx"
28 #include "tabvwsh.hxx"
31 #include "drawview.hxx"
32 #include "document.hxx"
33 #include "gridwin.hxx"
35 // Maximal erlaubte Mausbewegung um noch Drag&Drop zu starten
36 //! fusel,fuconstr,futext - zusammenfassen!
37 #define SC_MAXDRAGMOVE 3
39 /*************************************************************************
43 \************************************************************************/
45 FuConstruct::FuConstruct(ScTabViewShell
* pViewSh
, vcl::Window
* pWin
, ScDrawView
* pViewP
,
46 SdrModel
* pDoc
, SfxRequest
& rReq
) :
47 FuDraw(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
51 /*************************************************************************
55 \************************************************************************/
57 FuConstruct::~FuConstruct()
61 sal_uInt8
FuConstruct::Command(const CommandEvent
& rCEvt
)
63 return FuDraw::Command( rCEvt
);
66 // Calculate and return offset at current zoom. rInOutPos is adjusted by
67 // the calculated offset. rInOutPos now points to the position than when
68 // scaled to 100% actually would be at the position you see at the current zoom
69 // ( relative to the grid ) note: units are expected to be in 100th mm
70 Point
FuConstruct::CurrentGridSyncOffsetAndPos( Point
& rInOutPos
)
73 ScViewData
& rViewData
= pViewShell
->GetViewData();
74 ScDocument
* pDoc
= rViewData
.GetDocument();
77 // rInOutPos mightn't be where you think it is if there is zoom
78 // involved. Lets calculate where aPos would be at 100% zoom
79 // that's the actual correct position for the object ( when you
81 bool bNegative
= pDoc
->IsNegativePage(pView
->GetTab());
82 Rectangle
aObjRect( rInOutPos
, rInOutPos
);
83 ScRange aRange
= pDoc
->GetRange( pView
->GetTab(), aObjRect
);
84 ScAddress aOldStt
= aRange
.aStart
;
85 Point
aOldPos( pDoc
->GetColOffset( aOldStt
.Col(), aOldStt
.Tab() ), pDoc
->GetRowOffset( aOldStt
.Row(), aOldStt
.Tab() ) );
86 aOldPos
.X() = sc::TwipsToHMM( aOldPos
.X() );
87 aOldPos
.Y() = sc::TwipsToHMM( aOldPos
.Y() );
88 ScSplitPos eWhich
= rViewData
.GetActivePart();
89 ScGridWindow
* pGridWin
= rViewData
.GetActiveWin();
90 // and equiv screen pos
91 Point aScreenPos
= pViewShell
->GetViewData().GetScrPos( aOldStt
.Col(), aOldStt
.Row(), eWhich
, true );
92 MapMode aDrawMode
= pGridWin
->GetDrawMapMode();
93 Point aCurPosHmm
= pGridWin
->PixelToLogic(aScreenPos
, aDrawMode
);
94 Point aOff
= ( rInOutPos
- aCurPosHmm
);
95 rInOutPos
= aOldPos
+ aOff
;
96 aRetGridOff
= aCurPosHmm
- aOldPos
;
97 // fdo#64011 fix the X position when the sheet are RTL
100 aRetGridOff
.setX( aCurPosHmm
.getX() + aOldPos
.getX() );
101 rInOutPos
.setX( aOff
.getX() - aOldPos
.getX() );
106 /*************************************************************************
108 |* MouseButtonDown-event
110 \************************************************************************/
112 bool FuConstruct::MouseButtonDown(const MouseEvent
& rMEvt
)
114 // remember button state for creation of own MouseEvents
115 SetMouseButtonCode(rMEvt
.GetButtons());
117 bool bReturn
= FuDraw::MouseButtonDown(rMEvt
);
119 if ( pView
->IsAction() )
121 if ( rMEvt
.IsRight() )
128 aMDPos
= pWindow
->PixelToLogic( rMEvt
.GetPosPixel() );
130 if ( rMEvt
.IsLeft() )
132 pWindow
->CaptureMouse();
134 SdrHdl
* pHdl
= pView
->PickHandle(aMDPos
);
136 if ( pHdl
!= NULL
|| pView
->IsMarkedHit(aMDPos
) )
138 pView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, 1);
141 else if ( pView
->AreObjectsMarked() )
148 bIsInDragMode
= false;
153 /*************************************************************************
157 \************************************************************************/
159 bool FuConstruct::MouseMove(const MouseEvent
& rMEvt
)
161 FuDraw::MouseMove(rMEvt
);
163 if (aDragTimer
.IsActive() )
165 Point aOldPixel
= pWindow
->LogicToPixel( aMDPos
);
166 Point aNewPixel
= rMEvt
.GetPosPixel();
167 if ( std::abs( aOldPixel
.X() - aNewPixel
.X() ) > SC_MAXDRAGMOVE
||
168 std::abs( aOldPixel
.Y() - aNewPixel
.Y() ) > SC_MAXDRAGMOVE
)
172 Point
aPix(rMEvt
.GetPosPixel());
173 Point
aPnt( pWindow
->PixelToLogic(aPix
) );
175 // if object is being created then more than likely the mouse
176 // position has been 'adjusted' for the current zoom, need to
177 // restore the mouse position here to ensure resize works as expected
178 if ( pView
->GetCreateObj() )
179 aPnt
-= pView
->GetCreateObj()->GetGridOffset();
181 if ( pView
->IsAction() )
184 pView
->MovAction(aPnt
);
188 SdrHdl
* pHdl
=pView
->PickHandle(aPnt
);
192 pViewShell
->SetActivePointer(pHdl
->GetPointer());
194 else if ( pView
->IsMarkedHit(aPnt
) )
196 pViewShell
->SetActivePointer(Pointer(PointerStyle::Move
));
200 pViewShell
->SetActivePointer( aNewPointer
);
206 /*************************************************************************
208 |* MouseButtonUp-event
210 \************************************************************************/
212 bool FuConstruct::MouseButtonUp(const MouseEvent
& rMEvt
)
214 // remember button state for creation of own MouseEvents
215 SetMouseButtonCode(rMEvt
.GetButtons());
217 bool bReturn
= SimpleMouseButtonUp( rMEvt
);
219 // Doppelklick auf Textobjekt? (->fusel)
221 sal_uInt16 nClicks
= rMEvt
.GetClicks();
222 if ( nClicks
== 2 && rMEvt
.IsLeft() )
224 if ( pView
->AreObjectsMarked() )
226 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
227 if (rMarkList
.GetMarkCount() == 1)
229 SdrMark
* pMark
= rMarkList
.GetMark(0);
230 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
232 // bei Uno-Controls nicht in Textmodus
233 if ( pObj
->ISA(SdrTextObj
) && !pObj
->ISA(SdrUnoObj
) )
235 OutlinerParaObject
* pOPO
= pObj
->GetOutlinerParaObject();
236 bool bVertical
= ( pOPO
&& pOPO
->IsVertical() );
237 sal_uInt16 nTextSlotId
= bVertical
? SID_DRAW_TEXT_VERTICAL
: SID_DRAW_TEXT
;
239 pViewShell
->GetViewData().GetDispatcher().
240 Execute(nTextSlotId
, SfxCallMode::SLOT
| SfxCallMode::RECORD
);
242 // jetzt den erzeugten FuText holen und in den EditModus setzen
243 FuPoor
* pPoor
= pViewShell
->GetViewData().GetView()->GetDrawFuncPtr();
244 if ( pPoor
&& pPoor
->GetSlotID() == nTextSlotId
) // hat keine RTTI
246 FuText
* pText
= static_cast<FuText
*>(pPoor
);
247 Point aMousePixel
= rMEvt
.GetPosPixel();
248 pText
->SetInEditMode( pObj
, &aMousePixel
);
256 FuDraw::MouseButtonUp(rMEvt
);
261 // SimpleMouseButtonUp - ohne Test auf Doppelklick
263 bool FuConstruct::SimpleMouseButtonUp(const MouseEvent
& rMEvt
)
267 if (aDragTimer
.IsActive() )
272 Point
aPnt( pWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
274 if ( pView
->IsDragObj() )
275 pView
->EndDragObj( rMEvt
.IsMod1() );
277 else if ( pView
->IsMarkObj() )
280 else bReturn
= false;
282 if ( !pView
->IsAction() )
284 pWindow
->ReleaseMouse();
286 if ( !pView
->AreObjectsMarked() && rMEvt
.GetClicks() < 2 )
288 pView
->MarkObj(aPnt
, -2, false, rMEvt
.IsMod1());
290 SfxDispatcher
& rDisp
= pViewShell
->GetViewData().GetDispatcher();
291 if ( pView
->AreObjectsMarked() )
292 rDisp
.Execute(SID_OBJECT_SELECT
, SfxCallMode::SLOT
| SfxCallMode::RECORD
);
294 rDisp
.Execute(aSfxRequest
.GetSlot(), SfxCallMode::SLOT
| SfxCallMode::RECORD
);
301 /*************************************************************************
303 |* Tastaturereignisse bearbeiten
305 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
308 \************************************************************************/
310 bool FuConstruct::KeyInput(const KeyEvent
& rKEvt
)
312 bool bReturn
= false;
314 switch ( rKEvt
.GetKeyCode().GetCode() )
317 if ( pView
->IsAction() )
320 pWindow
->ReleaseMouse();
323 else // Zeichenmodus beenden
325 pViewShell
->GetViewData().GetDispatcher().
326 Execute(aSfxRequest
.GetSlot(), SfxCallMode::SLOT
| SfxCallMode::RECORD
);
331 pView
->DeleteMarked();
338 bReturn
= FuDraw::KeyInput(rKEvt
);
344 /*************************************************************************
346 |* Function aktivieren
348 \************************************************************************/
350 void FuConstruct::Activate()
355 /*************************************************************************
357 |* Function deaktivieren
359 \************************************************************************/
361 void FuConstruct::Deactivate()
363 FuDraw::Deactivate();
366 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */