Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "scitems.hxx"
22 : #include <editeng/eeitem.hxx>
23 :
24 : #include <svx/svdoutl.hxx>
25 : #include <svx/svdotext.hxx>
26 : #include <svx/svdpagv.hxx>
27 : #include <editeng/sizeitem.hxx>
28 : #include <sfx2/bindings.hxx>
29 : #include <svl/ptitem.hxx>
30 :
31 : #include "tabvwsh.hxx"
32 : #include "gridwin.hxx"
33 : #include "dbfunc.hxx"
34 : #include "viewdata.hxx"
35 : #include "output.hxx"
36 : #include "drawview.hxx"
37 : #include "fupoor.hxx"
38 :
39 : #include "drawutil.hxx"
40 : #include "document.hxx"
41 : #include "drwlayer.hxx"
42 : #include <vcl/svapp.hxx>
43 : #include "userdat.hxx"
44 : #include "unitconv.hxx"
45 : #include <svx/svdpage.hxx>
46 : // -----------------------------------------------------------------------
47 :
48 0 : bool ScGridWindow::DrawMouseButtonDown(const MouseEvent& rMEvt)
49 : {
50 0 : bool bRet = false;
51 0 : FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
52 0 : if (pDraw && !pViewData->IsRefMode())
53 : {
54 0 : pDraw->SetWindow( this );
55 0 : Point aLogicPos = PixelToLogic(rMEvt.GetPosPixel());
56 0 : if ( pDraw->IsDetectiveHit( aLogicPos ) )
57 : {
58 : // auf Detektiv-Pfeilen gar nichts (Doppelklick wird bei ButtonUp ausgewertet)
59 0 : bRet = true;
60 : }
61 : else
62 : {
63 0 : bRet = pDraw->MouseButtonDown( rMEvt );
64 0 : if ( bRet )
65 0 : UpdateStatusPosSize();
66 : }
67 : }
68 :
69 : // bei rechter Taste Draw-Aktion abbrechen
70 :
71 0 : ScDrawView* pDrView = pViewData->GetScDrawView();
72 0 : if ( pDrView && !rMEvt.IsLeft() && !bRet )
73 : {
74 0 : pDrView->BrkAction();
75 0 : bRet = true;
76 : }
77 0 : return bRet;
78 : }
79 :
80 0 : bool ScGridWindow::DrawMouseButtonUp(const MouseEvent& rMEvt)
81 : {
82 0 : ScViewFunc* pView = pViewData->GetView();
83 0 : bool bRet = false;
84 0 : FuPoor* pDraw = pView->GetDrawFuncPtr();
85 0 : if (pDraw && !pViewData->IsRefMode())
86 : {
87 0 : pDraw->SetWindow( this );
88 0 : bRet = pDraw->MouseButtonUp( rMEvt );
89 :
90 : // execute "format paint brush" for drawing objects
91 0 : SfxItemSet* pDrawBrush = pView->GetDrawBrushSet();
92 0 : if ( pDrawBrush )
93 : {
94 0 : ScDrawView* pDrView = pViewData->GetScDrawView();
95 0 : if ( pDrView )
96 : {
97 0 : bool bReplaceAll = true;
98 0 : pDrView->SetAttrToMarked(*pDrawBrush, bReplaceAll);
99 : }
100 :
101 0 : if ( !pView->IsPaintBrushLocked() )
102 0 : pView->ResetBrushDocument(); // end paint brush mode if not locked
103 : }
104 : }
105 :
106 0 : return bRet;
107 : }
108 :
109 0 : bool ScGridWindow::DrawMouseMove(const MouseEvent& rMEvt)
110 : {
111 0 : FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
112 0 : if (pDraw && !pViewData->IsRefMode())
113 : {
114 0 : pDraw->SetWindow( this );
115 0 : bool bRet = pDraw->MouseMove( rMEvt );
116 0 : if ( bRet )
117 0 : UpdateStatusPosSize();
118 0 : return bRet;
119 : }
120 : else
121 : {
122 0 : SetPointer( Pointer( POINTER_ARROW ) );
123 0 : return false;
124 : }
125 : }
126 :
127 0 : void ScGridWindow::DrawEndAction()
128 : {
129 0 : ScDrawView* pDrView = pViewData->GetScDrawView();
130 0 : if ( pDrView && pDrView->IsAction() )
131 0 : pDrView->BrkAction();
132 :
133 0 : FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
134 0 : if (pDraw)
135 0 : pDraw->StopDragTimer();
136 :
137 : // ReleaseMouse beim Aufruf
138 0 : }
139 :
140 0 : bool ScGridWindow::DrawCommand(const CommandEvent& rCEvt)
141 : {
142 0 : ScDrawView* pDrView = pViewData->GetScDrawView();
143 0 : FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
144 0 : if (pDrView && pDraw && !pViewData->IsRefMode())
145 : {
146 0 : pDraw->SetWindow( this );
147 0 : sal_uInt8 nUsed = pDraw->Command( rCEvt );
148 0 : if( nUsed == SC_CMD_USED )
149 0 : nButtonDown = 0; // MouseButtonUp wird verschluckt...
150 0 : if( nUsed || pDrView->IsAction() )
151 0 : return true;
152 : }
153 :
154 0 : return false;
155 : }
156 :
157 0 : bool ScGridWindow::DrawKeyInput(const KeyEvent& rKEvt)
158 : {
159 0 : ScDrawView* pDrView = pViewData->GetScDrawView();
160 0 : FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
161 0 : if (pDrView && pDraw && !pViewData->IsRefMode())
162 : {
163 0 : pDraw->SetWindow( this );
164 0 : bool bOldMarked = pDrView->AreObjectsMarked();
165 0 : if (pDraw->KeyInput( rKEvt ))
166 : {
167 0 : bool bLeaveDraw = false;
168 0 : bool bUsed = true;
169 0 : bool bNewMarked = pDrView->AreObjectsMarked();
170 0 : if ( !pViewData->GetView()->IsDrawSelMode() )
171 0 : if ( !bNewMarked )
172 : {
173 0 : pViewData->GetViewShell()->SetDrawShell( false );
174 0 : bLeaveDraw = true;
175 0 : if ( !bOldMarked &&
176 0 : rKEvt.GetKeyCode().GetCode() == KEY_DELETE )
177 0 : bUsed = false; // nichts geloescht
178 : }
179 0 : if (!bLeaveDraw)
180 0 : UpdateStatusPosSize(); // for moving/resizing etc. by keyboard
181 0 : return bUsed;
182 : }
183 : }
184 :
185 0 : return false;
186 : }
187 :
188 0 : void ScGridWindow::DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, sal_uLong nLayer )
189 : {
190 : // #109985#
191 0 : const ScViewOptions& rOpts = pViewData->GetOptions();
192 :
193 : // use new flags at SdrPaintView for hiding objects
194 0 : const bool bDrawOle(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_OLE));
195 0 : const bool bDrawChart(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_CHART));
196 0 : const bool bDrawDraw(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_DRAW));
197 :
198 0 : if(bDrawOle || bDrawChart || bDrawDraw)
199 : {
200 0 : ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
201 :
202 0 : if(pDrView)
203 : {
204 0 : pDrView->setHideOle(!bDrawOle);
205 0 : pDrView->setHideChart(!bDrawChart);
206 0 : pDrView->setHideDraw(!bDrawDraw);
207 0 : pDrView->setHideFormControl(!bDrawDraw);
208 : }
209 :
210 0 : if(SC_UPDATE_CHANGED == eMode)
211 : {
212 0 : rOutputData.DrawingSingle((sal_uInt16)nLayer);
213 : }
214 : else
215 : {
216 0 : rOutputData.DrawSelectiveObjects((sal_uInt16)nLayer);
217 : }
218 : }
219 0 : }
220 :
221 0 : void ScGridWindow::DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev )
222 : {
223 : // Draw-Gitterlinien
224 :
225 0 : ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
226 0 : if ( pDrView && pDrView->IsGridVisible() )
227 : {
228 0 : SdrPageView* pPV = pDrView->GetSdrPageView();
229 : OSL_ENSURE(pPV, "keine PageView");
230 0 : if (pPV)
231 : {
232 0 : pContentDev->SetLineColor(COL_GRAY);
233 :
234 0 : pPV->DrawPageViewGrid( *pContentDev, rDrawingRect );
235 : }
236 : }
237 0 : }
238 :
239 0 : MapMode ScGridWindow::GetDrawMapMode( bool bForce )
240 : {
241 0 : ScDocument* pDoc = pViewData->GetDocument();
242 0 : SCTAB nTab = pViewData->GetTabNo();
243 0 : sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
244 :
245 0 : MapMode aDrawMode = pViewData->GetLogicMode();
246 :
247 0 : ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
248 0 : if ( pDrView || bForce )
249 : {
250 0 : Fraction aScaleX;
251 0 : Fraction aScaleY;
252 0 : if (pDrView)
253 0 : pDrView->GetScale( aScaleX, aScaleY );
254 : else
255 : {
256 0 : SCCOL nEndCol = 0;
257 0 : SCROW nEndRow = 0;
258 0 : pDoc->GetTableArea( nTab, nEndCol, nEndRow );
259 0 : if (nEndCol<20) nEndCol = 20;
260 0 : if (nEndRow<20) nEndRow = 1000;
261 : ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, this,
262 0 : pViewData->GetZoomX(),pViewData->GetZoomY(),
263 : pViewData->GetPPTX(),pViewData->GetPPTY(),
264 0 : aScaleX,aScaleY );
265 : }
266 0 : aDrawMode.SetScaleX(aScaleX);
267 0 : aDrawMode.SetScaleY(aScaleY);
268 : }
269 0 : aDrawMode.SetOrigin(Point());
270 0 : Point aStartPos = pViewData->GetPixPos(eWhich);
271 0 : if ( bNegativePage )
272 : {
273 : // RTL uses negative positions for drawing objects
274 0 : aStartPos.X() = -aStartPos.X() + GetOutputSizePixel().Width() - 1;
275 : }
276 0 : aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
277 :
278 0 : return aDrawMode;
279 : }
280 :
281 0 : void ScGridWindow::DrawAfterScroll()
282 : {
283 0 : Update(); // immer, damit das Verhalten mit/ohne DrawingLayer gleich ist
284 :
285 0 : ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
286 0 : if (pDrView)
287 : {
288 0 : OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
289 0 : if (pOlView && pOlView->GetWindow() == this)
290 0 : pOlView->ShowCursor(false); // ist beim Scrollen weggekommen
291 : }
292 0 : }
293 :
294 0 : void ScGridWindow::CreateAnchorHandle(SdrHdlList& rHdl, const ScAddress& rAddress)
295 : {
296 0 : ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
297 0 : if (pDrView)
298 : {
299 0 : const ScViewOptions& rOpts = pViewData->GetOptions();
300 0 : if(rOpts.GetOption( VOPT_ANCHOR ))
301 : {
302 0 : sal_Bool bNegativePage = pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() );
303 0 : Point aPos = pViewData->GetScrPos( rAddress.Col(), rAddress.Row(), eWhich, sal_True );
304 0 : aPos = PixelToLogic(aPos);
305 0 : rHdl.AddHdl(new SdrHdl(aPos, bNegativePage ? HDL_ANCHOR_TR : HDL_ANCHOR));
306 : }
307 : }
308 0 : }
309 :
310 0 : SdrObject* ScGridWindow::GetEditObject()
311 : {
312 0 : ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
313 0 : if (pDrView)
314 : {
315 0 : OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
316 0 : if (pOlView && pOlView->GetWindow() == this)
317 0 : return pDrView->GetTextEditObject();
318 : }
319 :
320 0 : return NULL;
321 : }
322 :
323 0 : void ScGridWindow::UpdateStatusPosSize()
324 : {
325 0 : ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
326 0 : if (!pDrView)
327 : return; // shouldn't be called in that case
328 :
329 0 : SdrPageView* pPV = pDrView->GetSdrPageView();
330 0 : if (!pPV)
331 : return; // shouldn't be called in that case either
332 :
333 0 : SfxItemSet aSet(pViewData->GetViewShell()->GetPool(), SID_ATTR_POSITION, SID_ATTR_SIZE);
334 :
335 : // Fill items for position and size:
336 : // show action rectangle during action,
337 : // position and size of selected object(s) if something is selected,
338 : // mouse position otherwise
339 :
340 0 : sal_Bool bActionItem = false;
341 0 : if ( pDrView->IsAction() ) // action rectangle
342 : {
343 0 : Rectangle aRect;
344 0 : pDrView->TakeActionRect( aRect );
345 0 : if ( !aRect.IsEmpty() )
346 : {
347 : // mouse position will have been adjusted for offset
348 : // at current position and zoom, restore that adjustment here
349 : // so status shows correct value
350 0 : aRect -= pDrView->GetGridOffset();
351 0 : pPV->LogicToPagePos(aRect);
352 0 : aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
353 : aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
354 0 : Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
355 0 : bActionItem = sal_True;
356 : }
357 : }
358 0 : if ( !bActionItem )
359 : {
360 0 : if ( pDrView->AreObjectsMarked() ) // selected objects
361 : {
362 0 : Rectangle aRect = pDrView->GetAllMarkedRect();
363 : // mouse position will have been adjusted for offset
364 : // at current position and zoom, restore that adjustment here
365 : // so status shows correct value
366 0 : aRect -= pDrView->GetGridOffset();
367 0 : pPV->LogicToPagePos(aRect);
368 0 : aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
369 : aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
370 0 : Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
371 : }
372 : else // mouse position
373 : {
374 0 : Point aPos = PixelToLogic(aCurMousePos);
375 0 : pPV->LogicToPagePos(aPos);
376 0 : aSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
377 0 : aSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
378 : }
379 : }
380 :
381 0 : pViewData->GetBindings().SetState(aSet);
382 : }
383 :
384 0 : bool ScGridWindow::DrawHasMarkedObj()
385 : {
386 0 : ScDrawView* p = pViewData->GetScDrawView();
387 0 : return p ? p->AreObjectsMarked() : false;
388 : }
389 :
390 0 : void ScGridWindow::DrawMarkDropObj( SdrObject* pObj )
391 : {
392 0 : ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
393 0 : if (pDrView)
394 0 : pDrView->MarkDropObj(pObj);
395 15 : }
396 :
397 :
398 :
399 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|