Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / view / gridwin5.cxx
blob9789a24ba8d1dab3940a9f85187e0ad1f75d95e2
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/eeitem.hxx>
22 #include <editeng/flditem.hxx>
24 #include <editeng/editview.hxx>
25 #include <svx/svdobj.hxx>
26 #include <svx/svdpagv.hxx>
27 #include <svtools/imapobj.hxx>
28 #include <vcl/cursor.hxx>
29 #include <vcl/help.hxx>
30 #include <tools/urlobj.hxx>
31 #include <sfx2/viewfrm.hxx>
33 #include <unotools/localedatawrapper.hxx>
35 #include "viewuno.hxx"
36 #include "AccessibleDocument.hxx"
37 #include <com/sun/star/accessibility/XAccessible.hpp>
39 #include "gridwin.hxx"
40 #include "viewdata.hxx"
41 #include "drawview.hxx"
42 #include "drwlayer.hxx"
43 #include "drawpage.hxx"
44 #include "document.hxx"
45 #include "notemark.hxx"
46 #include "chgtrack.hxx"
47 #include "chgviset.hxx"
48 #include "dbfunc.hxx"
49 #include "tabvwsh.hxx"
50 #include "userdat.hxx"
51 #include "postit.hxx"
53 // -----------------------------------------------------------------------
55 bool ScGridWindow::ShowNoteMarker( SCsCOL nPosX, SCsROW nPosY, bool bKeyboard )
57 bool bDone = false;
59 ScDocument* pDoc = pViewData->GetDocument();
60 SCTAB nTab = pViewData->GetTabNo();
61 ScAddress aCellPos( nPosX, nPosY, nTab );
63 String aTrackText;
64 bool bLeftEdge = false;
66 // Change-Tracking
68 ScChangeTrack* pTrack = pDoc->GetChangeTrack();
69 ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings();
70 if ( pTrack && pTrack->GetFirst() && pSettings && pSettings->ShowChanges())
72 const ScChangeAction* pFound = NULL;
73 const ScChangeAction* pFoundContent = NULL;
74 const ScChangeAction* pFoundMove = NULL;
75 long nModified = 0;
76 const ScChangeAction* pAction = pTrack->GetFirst();
77 while (pAction)
79 if ( pAction->IsVisible() &&
80 ScViewUtil::IsActionShown( *pAction, *pSettings, *pDoc ) )
82 ScChangeActionType eType = pAction->GetType();
83 const ScBigRange& rBig = pAction->GetBigRange();
84 if ( rBig.aStart.Tab() == nTab )
86 ScRange aRange = rBig.MakeRange();
88 if ( eType == SC_CAT_DELETE_ROWS )
89 aRange.aEnd.SetRow( aRange.aStart.Row() );
90 else if ( eType == SC_CAT_DELETE_COLS )
91 aRange.aEnd.SetCol( aRange.aStart.Col() );
93 if ( aRange.In( aCellPos ) )
95 pFound = pAction; // der letzte gewinnt
96 switch ( eType )
98 case SC_CAT_CONTENT :
99 pFoundContent = pAction;
100 break;
101 case SC_CAT_MOVE :
102 pFoundMove = pAction;
103 break;
104 default:
106 // added to avoid warnings
109 ++nModified;
112 if ( eType == SC_CAT_MOVE )
114 ScRange aRange =
115 ((const ScChangeActionMove*)pAction)->
116 GetFromRange().MakeRange();
117 if ( aRange.In( aCellPos ) )
119 pFound = pAction;
120 ++nModified;
124 pAction = pAction->GetNext();
127 if ( pFound )
129 if ( pFoundContent && pFound->GetType() != SC_CAT_CONTENT )
130 pFound = pFoundContent; // Content gewinnt
131 if ( pFoundMove && pFound->GetType() != SC_CAT_MOVE &&
132 pFoundMove->GetActionNumber() >
133 pFound->GetActionNumber() )
134 pFound = pFoundMove; // Move gewinnt
136 // bei geloeschten Spalten: Pfeil auf die linke Seite der Zelle
137 if ( pFound->GetType() == SC_CAT_DELETE_COLS )
138 bLeftEdge = true;
140 DateTime aDT = pFound->GetDateTime();
141 aTrackText = pFound->GetUser();
142 aTrackText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
143 aTrackText += ScGlobal::pLocaleData->getDate(aDT);
144 aTrackText += ' ';
145 aTrackText += ScGlobal::pLocaleData->getTime(aDT);
146 aTrackText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ":\n" ));
147 String aComStr=pFound->GetComment();
148 if(aComStr.Len()>0)
150 aTrackText += aComStr;
151 aTrackText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "\n( " ));
153 rtl::OUString aTmp;
154 pFound->GetDescription(aTmp, pDoc);
155 aTrackText += String(aTmp);
156 if(aComStr.Len()>0)
158 aTrackText +=')';
163 // Notiz nur, wenn sie nicht schon auf dem Drawing-Layer angezeigt wird:
164 const ScPostIt* pNote = pDoc->GetNotes( aCellPos.Tab() )->findByAddress( aCellPos );
165 if ( (aTrackText.Len() > 0) || (pNote && !pNote->IsCaptionShown()) )
167 bool bNew = true;
168 bool bFast = false;
169 if ( pNoteMarker ) // schon eine Notiz angezeigt
171 if ( pNoteMarker->GetDocPos() == aCellPos ) // dieselbe
172 bNew = false; // dann stehenlassen
173 else
174 bFast = true; // sonst sofort
176 // marker which was shown for ctrl-F1 isn't removed by mouse events
177 if ( pNoteMarker->IsByKeyboard() && !bKeyboard )
178 bNew = false;
180 if ( bNew )
182 if ( bKeyboard )
183 bFast = true; // keyboard also shows the marker immediately
185 delete pNoteMarker;
187 bool bHSplit = pViewData->GetHSplitMode() != SC_SPLIT_NONE;
188 bool bVSplit = pViewData->GetVSplitMode() != SC_SPLIT_NONE;
190 Window* pLeft = pViewData->GetView()->GetWindowByPos( bVSplit ? SC_SPLIT_TOPLEFT : SC_SPLIT_BOTTOMLEFT );
191 Window* pRight = bHSplit ? pViewData->GetView()->GetWindowByPos( bVSplit ? SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT ) : 0;
192 Window* pBottom = bVSplit ? pViewData->GetView()->GetWindowByPos( SC_SPLIT_BOTTOMLEFT ) : 0;
193 Window* pDiagonal = (bHSplit && bVSplit) ? pViewData->GetView()->GetWindowByPos( SC_SPLIT_BOTTOMRIGHT ) : 0;
194 OSL_ENSURE( pLeft, "ScGridWindow::ShowNoteMarker - missing top-left grid window" );
196 /* If caption is shown from right or bottom windows, adjust
197 mapmode to include size of top-left window. */
198 MapMode aMapMode = GetDrawMapMode( true );
199 Size aLeftSize = pLeft->PixelToLogic( pLeft->GetOutputSizePixel(), aMapMode );
200 Point aOrigin = aMapMode.GetOrigin();
201 if( (this == pRight) || (this == pDiagonal) )
202 aOrigin.X() += aLeftSize.Width();
203 if( (this == pBottom) || (this == pDiagonal) )
204 aOrigin.Y() += aLeftSize.Height();
205 aMapMode.SetOrigin( aOrigin );
207 pNoteMarker = new ScNoteMarker( pLeft, pRight, pBottom, pDiagonal,
208 pDoc, aCellPos, aTrackText,
209 aMapMode, bLeftEdge, bFast, bKeyboard );
210 if ( pViewData->GetScDrawView() )
212 // get position for aCellPos
213 if ( pDoc )
215 // get draw position in hmm for aCellPos
216 Point aOldPos( pDoc->GetColOffset( aCellPos.Col(), aCellPos.Tab() ), pDoc->GetRowOffset( aCellPos.Row(), aCellPos.Tab() ) );
217 aOldPos.X() = sc::TwipsToHMM( aOldPos.X() );
218 aOldPos.Y() = sc::TwipsToHMM( aOldPos.Y() );
219 // get screen pos in hmm for aCellPos
220 // and equiv screen pos
221 Point aScreenPos = pViewData->GetScrPos( aCellPos.Col(), aCellPos.Row(), eWhich, sal_True );
222 MapMode aDrawMode = GetDrawMapMode();
223 Point aCurPosHmm = PixelToLogic(aScreenPos, aDrawMode );
224 Point aGridOff = aCurPosHmm -aOldPos;
225 pNoteMarker->SetGridOff( aGridOff );
230 bDone = true; // something is shown (old or new)
233 return bDone;
236 // -----------------------------------------------------------------------
238 void ScGridWindow::RequestHelp(const HelpEvent& rHEvt)
240 sal_Bool bDone = false;
241 sal_Bool bHelpEnabled = ( rHEvt.GetMode() & ( HELPMODE_BALLOON | HELPMODE_QUICK ) ) != 0;
242 SdrView* pDrView = pViewData->GetScDrawView();
244 sal_Bool bDrawTextEdit = false;
245 if (pDrView)
246 bDrawTextEdit = pDrView->IsTextEdit();
248 // notes or change tracking
250 if ( bHelpEnabled && !bDrawTextEdit )
252 Point aPosPixel = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
253 SCsCOL nPosX;
254 SCsROW nPosY;
255 pViewData->GetPosFromPixel( aPosPixel.X(), aPosPixel.Y(), eWhich, nPosX, nPosY );
257 if ( ShowNoteMarker( nPosX, nPosY, false ) )
259 Window::RequestHelp( rHEvt ); // alte Tip/Balloon ausschalten
260 bDone = sal_True;
264 if ( !bDone && pNoteMarker )
266 if ( pNoteMarker->IsByKeyboard() )
268 // marker which was shown for ctrl-F1 isn't removed by mouse events
270 else
271 DELETEZ(pNoteMarker);
274 // Image-Map / Text-URL
276 if ( bHelpEnabled && !bDone && !nButtonDown ) // nur ohne gedrueckten Button
278 String aHelpText;
279 Rectangle aPixRect;
280 Point aPosPixel = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
282 if ( pDrView ) // URL / Image-Map
284 SdrViewEvent aVEvt;
285 MouseEvent aMEvt( aPosPixel, 1, 0, MOUSE_LEFT );
286 SdrHitKind eHit = pDrView->PickAnything( aMEvt, SDRMOUSEBUTTONDOWN, aVEvt );
288 if ( eHit != SDRHIT_NONE && aVEvt.pObj != NULL )
290 // URL fuer IMapObject unter Pointer ist Hilfetext
291 if ( ScDrawLayer::GetIMapInfo( aVEvt.pObj ) )
293 Point aLogicPos = PixelToLogic( aPosPixel );
294 IMapObject* pIMapObj = ScDrawLayer::GetHitIMapObject(
295 aVEvt.pObj, aLogicPos, *this );
297 if ( pIMapObj )
299 // Bei ImageMaps die Description anzeigen, wenn vorhanden
300 aHelpText = pIMapObj->GetAltText();
301 if (!aHelpText.Len())
302 aHelpText = pIMapObj->GetURL();
303 aPixRect = LogicToPixel(aVEvt.pObj->GetLogicRect());
306 // URL in shape text or at shape itself (URL in text overrides object URL)
307 if ( aHelpText.Len() == 0 )
309 if( aVEvt.eEvent == SDREVENT_EXECUTEURL )
311 aHelpText = aVEvt.pURLField->GetURL();
312 aPixRect = LogicToPixel(aVEvt.pObj->GetLogicRect());
314 else
316 SdrObject* pObj = 0;
317 SdrPageView* pPV = 0;
318 Point aMDPos = PixelToLogic( aPosPixel );
319 if ( pDrView->PickObj(aMDPos, pDrView->getHitTolLog(), pObj, pPV, SDRSEARCH_ALSOONMASTER) )
321 if ( pObj->IsGroupObject() )
323 SdrObject* pHit = 0;
324 if ( pDrView->PickObj(aMDPos, pDrView->getHitTolLog(), pHit, pPV, SDRSEARCH_DEEP ) )
325 pObj = pHit;
327 ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
328 if ( pInfo && (pInfo->GetHlink().getLength() > 0) )
330 aPixRect = LogicToPixel(aVEvt.pObj->GetLogicRect());
331 aHelpText = pInfo->GetHlink();
339 if ( !aHelpText.Len() ) // Text-URL
341 String aUrl;
342 if ( GetEditUrl( aPosPixel, NULL, &aUrl, NULL ) )
344 aHelpText = INetURLObject::decode( aUrl, INET_HEX_ESCAPE,
345 INetURLObject::DECODE_UNAMBIGUOUS );
347 ScDocument* pDoc = pViewData->GetDocument();
348 SCsCOL nPosX;
349 SCsROW nPosY;
350 SCTAB nTab = pViewData->GetTabNo();
351 pViewData->GetPosFromPixel( aPosPixel.X(), aPosPixel.Y(), eWhich, nPosX, nPosY );
352 const ScPatternAttr* pPattern = pDoc->GetPattern( nPosX, nPosY, nTab );
354 // bForceToTop = sal_False, use the cell's real position
355 aPixRect = pViewData->GetEditArea( eWhich, nPosX, nPosY, this, pPattern, false );
359 if ( aHelpText.Len() )
361 Rectangle aScreenRect(OutputToScreenPixel(aPixRect.TopLeft()),
362 OutputToScreenPixel(aPixRect.BottomRight()));
364 if ( rHEvt.GetMode() & HELPMODE_BALLOON )
365 Help::ShowBalloon(this,rHEvt.GetMousePosPixel(), aScreenRect, aHelpText);
366 else if ( rHEvt.GetMode() & HELPMODE_QUICK )
367 Help::ShowQuickHelp(this,aScreenRect, aHelpText);
369 bDone = sal_True;
373 // Basic-Controls
375 if ( pDrView && bHelpEnabled && !bDone )
377 SdrPageView* pPV = pDrView->GetSdrPageView();
378 OSL_ENSURE( pPV, "SdrPageView* ist NULL" );
379 if (pPV)
380 bDone = ((ScDrawPage*)pPV->GetPage())->RequestHelp( this, pDrView, rHEvt );
383 // Wenn QuickHelp fuer AutoFill angezeigt wird, nicht wieder wegnehmen lassen
385 if ( nMouseStatus == SC_GM_TABDOWN && pViewData->GetRefType() == SC_REFTYPE_FILL &&
386 Help::IsQuickHelpEnabled() )
387 bDone = sal_True;
389 if (!bDone)
390 Window::RequestHelp( rHEvt );
393 bool ScGridWindow::IsMyModel(SdrEditView* pSdrView)
395 return pSdrView &&
396 pSdrView->GetModel() == pViewData->GetDocument()->GetDrawLayer();
399 void ScGridWindow::HideNoteMarker()
401 DELETEZ(pNoteMarker);
404 com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
405 ScGridWindow::CreateAccessible()
407 ScAccessibleDocument* pAccessibleDocument =
408 new ScAccessibleDocument(GetAccessibleParentWindow()->GetAccessible(),
409 pViewData->GetViewShell(), eWhich);
411 com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessible > xAccessible = pAccessibleDocument;
413 pAccessibleDocument->Init();
415 return xAccessible;
418 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */