xref: /trunk/main/sc/source/ui/drawfunc/fumark.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/viewfrm.hxx>
33 
34 #include "fumark.hxx"
35 #include "sc.hrc"
36 #include "tabvwsh.hxx"
37 #include "scmod.hxx"
38 #include "reffact.hxx"
39 #include "document.hxx"
40 #include "scresid.hxx"
41 #include "drawview.hxx"
42 
43 //------------------------------------------------------------------
44 
45 /*************************************************************************
46 |*
47 |* Funktion zum Aufziehen eines Rechtecks
48 |*
49 \************************************************************************/
50 
51 FuMarkRect::FuMarkRect(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
52                SdrModel* pDoc, SfxRequest& rReq) :
53     FuPoor(pViewSh, pWin, pViewP, pDoc, rReq),
54     bVisible(sal_False),
55     bStartDrag(sal_False)
56 {
57 }
58 
59 /*************************************************************************
60 |*
61 |* Destruktor
62 |*
63 \************************************************************************/
64 
65 FuMarkRect::~FuMarkRect()
66 {
67 }
68 
69 /*************************************************************************
70 |*
71 |* MouseButtonDown-event
72 |*
73 \************************************************************************/
74 
75 sal_Bool FuMarkRect::MouseButtonDown(const MouseEvent& rMEvt)
76 {
77     // #95491# remember button state for creation of own MouseEvents
78     SetMouseButtonCode(rMEvt.GetButtons());
79 
80     pWindow->CaptureMouse();
81     pView->UnmarkAll();         // der Einheitlichkeit halber und wegen #50558#
82     bStartDrag = sal_True;
83 
84     aBeginPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
85     aZoomRect = Rectangle( aBeginPos, Size() );
86     return sal_True;
87 }
88 
89 /*************************************************************************
90 |*
91 |* MouseMove-event
92 |*
93 \************************************************************************/
94 
95 sal_Bool FuMarkRect::MouseMove(const MouseEvent& rMEvt)
96 {
97     if ( bStartDrag )
98     {
99         if ( bVisible )
100             pViewShell->DrawMarkRect(aZoomRect);
101         Point aPixPos= rMEvt.GetPosPixel();
102         ForceScroll(aPixPos);
103 
104         Point aEndPos = pWindow->PixelToLogic(aPixPos);
105         Rectangle aRect(aBeginPos, aEndPos);
106         aZoomRect = aRect;
107         aZoomRect.Justify();
108         pViewShell->DrawMarkRect(aZoomRect);
109         bVisible = sal_True;
110     }
111 
112     ForcePointer(&rMEvt);
113 
114     return bStartDrag;
115 }
116 
117 /*************************************************************************
118 |*
119 |* MouseButtonUp-event
120 |*
121 \************************************************************************/
122 
123 sal_Bool FuMarkRect::MouseButtonUp(const MouseEvent& rMEvt)
124 {
125     // #95491# remember button state for creation of own MouseEvents
126     SetMouseButtonCode(rMEvt.GetButtons());
127 
128     if ( bVisible )
129     {
130         // Hide ZoomRect
131         pViewShell->DrawMarkRect(aZoomRect);
132         bVisible = sal_False;
133     }
134 
135     Size aZoomSizePixel = pWindow->LogicToPixel(aZoomRect).GetSize();
136 
137     sal_uInt16 nMinMove = pView->GetMinMoveDistancePixel();
138     if ( aZoomSizePixel.Width() < nMinMove || aZoomSizePixel.Height() < nMinMove )
139     {
140         // Klick auf der Stelle
141 
142         aZoomRect.SetSize(Size());      // dann ganz leer
143     }
144 
145     bStartDrag = sal_False;
146     pWindow->ReleaseMouse();
147 
148     pViewShell->GetViewData()->GetDispatcher().
149         Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
150 
151         //  Daten an der View merken
152 
153     pViewShell->SetChartArea( aSourceRange, aZoomRect );
154 
155         //  Chart-Dialog starten:
156 
157 //  sal_uInt16 nId  = ScChartDlgWrapper::GetChildWindowId();
158 //  SfxChildWindow* pWnd = pViewShell->GetViewFrame()->GetChildWindow( nId );
159 //  SC_MOD()->SetRefDialog( nId, pWnd ? sal_False : sal_True );
160 
161     return sal_True;
162 }
163 
164 /*************************************************************************
165 |*
166 |* Command-event
167 |*
168 \************************************************************************/
169 
170 sal_uInt8 FuMarkRect::Command(const CommandEvent& rCEvt)
171 {
172     if ( COMMAND_STARTDRAG == rCEvt.GetCommand() )
173     {
174         //  #29877# nicht anfangen, auf der Tabelle rumzudraggen,
175         //  aber Maus-Status nicht zuruecksetzen
176         return SC_CMD_IGNORE;
177     }
178     else
179         return FuPoor::Command(rCEvt);
180 }
181 
182 /*************************************************************************
183 |*
184 |* Tastaturereignisse bearbeiten
185 |*
186 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
187 |* FALSE.
188 |*
189 \************************************************************************/
190 
191 sal_Bool FuMarkRect::KeyInput(const KeyEvent& rKEvt)
192 {
193     sal_Bool bReturn = sal_False;
194 
195     switch ( rKEvt.GetKeyCode().GetCode() )
196     {
197         case KEY_ESCAPE:
198             //  beenden
199             pViewShell->GetViewData()->GetDispatcher().
200                 Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
201             bReturn = sal_True;
202             break;
203     }
204 
205     if (!bReturn)
206     {
207         bReturn = FuPoor::KeyInput(rKEvt);
208     }
209 
210     return (bReturn);
211 }
212 
213 /*************************************************************************
214 |*
215 |* Vor dem Scrollen Selektionsdarstellung ausblenden
216 |*
217 \************************************************************************/
218 
219 void FuMarkRect::ScrollStart()
220 {
221 }
222 
223 /*************************************************************************
224 |*
225 |* Nach dem Scrollen Selektionsdarstellung wieder anzeigen
226 |*
227 \************************************************************************/
228 
229 void FuMarkRect::ScrollEnd()
230 {
231 }
232 
233 /*************************************************************************
234 |*
235 |* Function aktivieren
236 |*
237 \************************************************************************/
238 
239 void FuMarkRect::Activate()
240 {
241     FuPoor::Activate();
242 
243         //  Markierung merken, bevor evtl. Tabelle umgeschaltet wird
244 
245     ScViewData* pViewData = pViewShell->GetViewData();
246     ScMarkData& rMark = pViewData->GetMarkData();
247 
248     if ( !rMark.IsMultiMarked() && !rMark.IsMarked() )
249         pViewShell->MarkDataArea( sal_True );
250 
251     pViewData->GetMultiArea( aSourceRange );        // Mehrfachselektion erlaubt
252 
253 //  pViewShell->Unmark();
254 
255     ForcePointer(NULL);
256 }
257 
258 /*************************************************************************
259 |*
260 |* Function deaktivieren
261 |*
262 \************************************************************************/
263 
264 void FuMarkRect::Deactivate()
265 {
266     FuPoor::Deactivate();
267 
268     if (bVisible)
269     {
270         // Hide ZoomRect
271         pViewShell->DrawMarkRect(aZoomRect);
272         bVisible = sal_False;
273         bStartDrag = sal_False;
274     }
275 }
276 
277 /*************************************************************************
278 |*
279 |* Maus-Pointer umschalten
280 |*
281 \************************************************************************/
282 
283 void FuMarkRect::ForcePointer(const MouseEvent* /* pMEvt */)
284 {
285     pViewShell->SetActivePointer( Pointer( POINTER_CHART ) );
286 }
287 
288 
289 
290 
291