Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / drawfunc / fumark.cxx
blobb0d5f102301978123c96bd570a36cdda7a3d6281
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 .
21 #include <sfx2/dispatch.hxx>
22 #include <sfx2/viewfrm.hxx>
24 #include "fumark.hxx"
25 #include "sc.hrc"
26 #include "tabvwsh.hxx"
27 #include "scmod.hxx"
28 #include "reffact.hxx"
29 #include "document.hxx"
30 #include "scresid.hxx"
31 #include "drawview.hxx"
32 #include "markdata.hxx"
34 //------------------------------------------------------------------
36 /*************************************************************************
38 |* Funktion zum Aufziehen eines Rechtecks
40 \************************************************************************/
42 FuMarkRect::FuMarkRect(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
43 SdrModel* pDoc, SfxRequest& rReq) :
44 FuPoor(pViewSh, pWin, pViewP, pDoc, rReq),
45 bVisible(false),
46 bStartDrag(false)
50 /*************************************************************************
52 |* Destruktor
54 \************************************************************************/
56 FuMarkRect::~FuMarkRect()
60 /*************************************************************************
62 |* MouseButtonDown-event
64 \************************************************************************/
66 sal_Bool FuMarkRect::MouseButtonDown(const MouseEvent& rMEvt)
68 // remember button state for creation of own MouseEvents
69 SetMouseButtonCode(rMEvt.GetButtons());
71 pWindow->CaptureMouse();
72 pView->UnmarkAll(); // der Einheitlichkeit halber und wegen #50558#
73 bStartDrag = sal_True;
75 aBeginPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
76 aZoomRect = Rectangle( aBeginPos, Size() );
77 return sal_True;
80 /*************************************************************************
82 |* MouseMove-event
84 \************************************************************************/
86 sal_Bool FuMarkRect::MouseMove(const MouseEvent& rMEvt)
88 if ( bStartDrag )
90 if ( bVisible )
91 pViewShell->DrawMarkRect(aZoomRect);
92 Point aPixPos= rMEvt.GetPosPixel();
93 ForceScroll(aPixPos);
95 Point aEndPos = pWindow->PixelToLogic(aPixPos);
96 Rectangle aRect(aBeginPos, aEndPos);
97 aZoomRect = aRect;
98 aZoomRect.Justify();
99 pViewShell->DrawMarkRect(aZoomRect);
100 bVisible = sal_True;
103 ForcePointer(&rMEvt);
105 return bStartDrag;
108 /*************************************************************************
110 |* MouseButtonUp-event
112 \************************************************************************/
114 sal_Bool FuMarkRect::MouseButtonUp(const MouseEvent& rMEvt)
116 // remember button state for creation of own MouseEvents
117 SetMouseButtonCode(rMEvt.GetButtons());
119 if ( bVisible )
121 // Hide ZoomRect
122 pViewShell->DrawMarkRect(aZoomRect);
123 bVisible = false;
126 Size aZoomSizePixel = pWindow->LogicToPixel(aZoomRect).GetSize();
128 sal_uInt16 nMinMove = pView->GetMinMoveDistancePixel();
129 if ( aZoomSizePixel.Width() < nMinMove || aZoomSizePixel.Height() < nMinMove )
131 // Klick auf der Stelle
133 aZoomRect.SetSize(Size()); // dann ganz leer
136 bStartDrag = false;
137 pWindow->ReleaseMouse();
139 pViewShell->GetViewData()->GetDispatcher().
140 Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
142 // Daten an der View merken
144 pViewShell->SetChartArea( aSourceRange, aZoomRect );
146 // Chart-Dialog starten:
148 // sal_uInt16 nId = ScChartDlgWrapper::GetChildWindowId();
149 // SfxChildWindow* pWnd = pViewShell->GetViewFrame()->GetChildWindow( nId );
150 // SC_MOD()->SetRefDialog( nId, pWnd ? sal_False : sal_True );
152 return sal_True;
155 /*************************************************************************
157 |* Command-event
159 \************************************************************************/
161 sal_uInt8 FuMarkRect::Command(const CommandEvent& rCEvt)
163 if ( COMMAND_STARTDRAG == rCEvt.GetCommand() )
165 // nicht anfangen, auf der Tabelle rumzudraggen,
166 // aber Maus-Status nicht zuruecksetzen
167 return SC_CMD_IGNORE;
169 else
170 return FuPoor::Command(rCEvt);
173 /*************************************************************************
175 |* Tastaturereignisse bearbeiten
177 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
178 |* FALSE.
180 \************************************************************************/
182 sal_Bool FuMarkRect::KeyInput(const KeyEvent& rKEvt)
184 sal_Bool bReturn = false;
186 switch ( rKEvt.GetKeyCode().GetCode() )
188 case KEY_ESCAPE:
189 // beenden
190 pViewShell->GetViewData()->GetDispatcher().
191 Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
192 bReturn = sal_True;
193 break;
196 if (!bReturn)
198 bReturn = FuPoor::KeyInput(rKEvt);
201 return (bReturn);
204 /*************************************************************************
206 |* Function aktivieren
208 \************************************************************************/
210 void FuMarkRect::Activate()
212 FuPoor::Activate();
214 // Markierung merken, bevor evtl. Tabelle umgeschaltet wird
216 ScViewData* pViewData = pViewShell->GetViewData();
217 ScMarkData& rMark = pViewData->GetMarkData();
219 if ( !rMark.IsMultiMarked() && !rMark.IsMarked() )
220 pViewShell->MarkDataArea( sal_True );
222 pViewData->GetMultiArea( aSourceRange ); // Mehrfachselektion erlaubt
224 // pViewShell->Unmark();
226 ForcePointer(NULL);
229 /*************************************************************************
231 |* Function deaktivieren
233 \************************************************************************/
235 void FuMarkRect::Deactivate()
237 FuPoor::Deactivate();
239 if (bVisible)
241 // Hide ZoomRect
242 pViewShell->DrawMarkRect(aZoomRect);
243 bVisible = false;
244 bStartDrag = false;
248 /*************************************************************************
250 |* Maus-Pointer umschalten
252 \************************************************************************/
254 void FuMarkRect::ForcePointer(const MouseEvent* /* pMEvt */)
256 pViewShell->SetActivePointer( Pointer( POINTER_CHART ) );
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */