Update ooo320-m1
[ooovba.git] / sc / source / ui / view / gridwin5.cxx
blobd7355b677c50e0ce0a068690918265a730dc1364
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gridwin5.cxx,v $
10 * $Revision: 1.23.128.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // INCLUDE ---------------------------------------------------------------
36 #include <svx/eeitem.hxx>
38 #include <svx/flditem.hxx>
40 #include <svx/editview.hxx>
41 #include <svx/svdobj.hxx>
42 #include <svx/svdpagv.hxx>
43 #include <svtools/imapobj.hxx>
44 #include <vcl/cursor.hxx>
45 #include <vcl/help.hxx>
46 #include <tools/urlobj.hxx>
47 #include <sfx2/viewfrm.hxx>
49 #include <unotools/localedatawrapper.hxx>
51 #include "viewuno.hxx"
52 #include "AccessibleDocument.hxx"
53 #include <com/sun/star/accessibility/XAccessible.hpp>
55 #include "gridwin.hxx"
56 #include "viewdata.hxx"
57 #include "drawview.hxx"
58 #include "drwlayer.hxx"
59 #include "drawpage.hxx"
60 #include "document.hxx"
61 #include "notemark.hxx"
62 #include "chgtrack.hxx"
63 #include "chgviset.hxx"
64 #include "dbfunc.hxx"
65 #include "tabvwsh.hxx"
66 #include "userdat.hxx"
67 #include "postit.hxx"
69 // -----------------------------------------------------------------------
71 ScHideTextCursor::ScHideTextCursor( ScViewData* pData, ScSplitPos eW ) :
72 pViewData(pData),
73 eWhich(eW)
75 Window* pWin = pViewData->GetView()->GetWindowByPos( eWhich );
76 if (pWin)
78 Cursor* pCur = pWin->GetCursor();
79 if ( pCur && pCur->IsVisible() )
80 pCur->Hide();
84 ScHideTextCursor::~ScHideTextCursor()
86 Window* pWin = pViewData->GetView()->GetWindowByPos( eWhich );
87 if (pWin)
89 // restore text cursor
90 if ( pViewData->HasEditView(eWhich) && pWin->HasFocus() )
91 pViewData->GetEditView(eWhich)->ShowCursor( FALSE, TRUE );
95 // -----------------------------------------------------------------------
97 BOOL ScGridWindow::ShowNoteMarker( SCsCOL nPosX, SCsROW nPosY, BOOL bKeyboard )
99 BOOL bDone = FALSE;
101 ScDocument* pDoc = pViewData->GetDocument();
102 SCTAB nTab = pViewData->GetTabNo();
103 ScAddress aCellPos( nPosX, nPosY, nTab );
105 String aTrackText;
106 BOOL bLeftEdge = FALSE;
108 // Change-Tracking
110 ScChangeTrack* pTrack = pDoc->GetChangeTrack();
111 ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings();
112 if ( pTrack && pTrack->GetFirst() && pSettings && pSettings->ShowChanges())
114 const ScChangeAction* pFound = NULL;
115 const ScChangeAction* pFoundContent = NULL;
116 const ScChangeAction* pFoundMove = NULL;
117 long nModified = 0;
118 const ScChangeAction* pAction = pTrack->GetFirst();
119 while (pAction)
121 if ( pAction->IsVisible() &&
122 ScViewUtil::IsActionShown( *pAction, *pSettings, *pDoc ) )
124 ScChangeActionType eType = pAction->GetType();
125 const ScBigRange& rBig = pAction->GetBigRange();
126 if ( rBig.aStart.Tab() == nTab )
128 ScRange aRange = rBig.MakeRange();
130 if ( eType == SC_CAT_DELETE_ROWS )
131 aRange.aEnd.SetRow( aRange.aStart.Row() );
132 else if ( eType == SC_CAT_DELETE_COLS )
133 aRange.aEnd.SetCol( aRange.aStart.Col() );
135 if ( aRange.In( aCellPos ) )
137 pFound = pAction; // der letzte gewinnt
138 switch ( eType )
140 case SC_CAT_CONTENT :
141 pFoundContent = pAction;
142 break;
143 case SC_CAT_MOVE :
144 pFoundMove = pAction;
145 break;
146 default:
148 // added to avoid warnings
151 ++nModified;
154 if ( eType == SC_CAT_MOVE )
156 ScRange aRange =
157 ((const ScChangeActionMove*)pAction)->
158 GetFromRange().MakeRange();
159 if ( aRange.In( aCellPos ) )
161 pFound = pAction;
162 ++nModified;
166 pAction = pAction->GetNext();
169 if ( pFound )
171 if ( pFoundContent && pFound->GetType() != SC_CAT_CONTENT )
172 pFound = pFoundContent; // Content gewinnt
173 if ( pFoundMove && pFound->GetType() != SC_CAT_MOVE &&
174 pFoundMove->GetActionNumber() >
175 pFound->GetActionNumber() )
176 pFound = pFoundMove; // Move gewinnt
178 // bei geloeschten Spalten: Pfeil auf die linke Seite der Zelle
179 if ( pFound->GetType() == SC_CAT_DELETE_COLS )
180 bLeftEdge = TRUE;
182 DateTime aDT = pFound->GetDateTime();
183 aTrackText = pFound->GetUser();
184 aTrackText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
185 aTrackText += ScGlobal::pLocaleData->getDate(aDT);
186 aTrackText += ' ';
187 aTrackText += ScGlobal::pLocaleData->getTime(aDT);
188 aTrackText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ":\n" ));
189 String aComStr=pFound->GetComment();
190 if(aComStr.Len()>0)
192 aTrackText += aComStr;
193 aTrackText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "\n( " ));
195 pFound->GetDescription( aTrackText, pDoc );
196 if(aComStr.Len()>0)
198 aTrackText +=')';
203 // Notiz nur, wenn sie nicht schon auf dem Drawing-Layer angezeigt wird:
204 const ScPostIt* pNote = pDoc->GetNote( aCellPos );
205 if ( (aTrackText.Len() > 0) || (pNote && !pNote->IsCaptionShown()) )
207 BOOL bNew = TRUE;
208 BOOL bFast = FALSE;
209 if ( pNoteMarker ) // schon eine Notiz angezeigt
211 if ( pNoteMarker->GetDocPos() == aCellPos ) // dieselbe
212 bNew = FALSE; // dann stehenlassen
213 else
214 bFast = TRUE; // sonst sofort
216 // marker which was shown for ctrl-F1 isn't removed by mouse events
217 if ( pNoteMarker->IsByKeyboard() && !bKeyboard )
218 bNew = FALSE;
220 if ( bNew )
222 if ( bKeyboard )
223 bFast = TRUE; // keyboard also shows the marker immediately
225 delete pNoteMarker;
227 bool bHSplit = pViewData->GetHSplitMode() != SC_SPLIT_NONE;
228 bool bVSplit = pViewData->GetVSplitMode() != SC_SPLIT_NONE;
230 Window* pLeft = pViewData->GetView()->GetWindowByPos( bVSplit ? SC_SPLIT_TOPLEFT : SC_SPLIT_BOTTOMLEFT );
231 Window* pRight = bHSplit ? pViewData->GetView()->GetWindowByPos( bVSplit ? SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT ) : 0;
232 Window* pBottom = bVSplit ? pViewData->GetView()->GetWindowByPos( SC_SPLIT_BOTTOMLEFT ) : 0;
233 Window* pDiagonal = (bHSplit && bVSplit) ? pViewData->GetView()->GetWindowByPos( SC_SPLIT_BOTTOMRIGHT ) : 0;
234 DBG_ASSERT( pLeft, "ScGridWindow::ShowNoteMarker - missing top-left grid window" );
236 /* If caption is shown from right or bottom windows, adjust
237 mapmode to include size of top-left window. */
238 MapMode aMapMode = GetDrawMapMode( TRUE );
239 Size aLeftSize = pLeft->PixelToLogic( pLeft->GetOutputSizePixel(), aMapMode );
240 Point aOrigin = aMapMode.GetOrigin();
241 if( (this == pRight) || (this == pDiagonal) )
242 aOrigin.X() += aLeftSize.Width();
243 if( (this == pBottom) || (this == pDiagonal) )
244 aOrigin.Y() += aLeftSize.Height();
245 aMapMode.SetOrigin( aOrigin );
247 pNoteMarker = new ScNoteMarker( pLeft, pRight, pBottom, pDiagonal,
248 pDoc, aCellPos, aTrackText,
249 aMapMode, bLeftEdge, bFast, bKeyboard );
252 bDone = TRUE; // something is shown (old or new)
255 return bDone;
258 // -----------------------------------------------------------------------
260 void ScGridWindow::RequestHelp(const HelpEvent& rHEvt)
262 BOOL bDone = FALSE;
263 BOOL bHelpEnabled = ( rHEvt.GetMode() & ( HELPMODE_BALLOON | HELPMODE_QUICK ) ) != 0;
264 SdrView* pDrView = pViewData->GetScDrawView();
266 BOOL bDrawTextEdit = FALSE;
267 if (pDrView)
268 bDrawTextEdit = pDrView->IsTextEdit();
270 // notes or change tracking
272 if ( bHelpEnabled && !bDrawTextEdit )
274 Point aPosPixel = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
275 SCsCOL nPosX;
276 SCsROW nPosY;
277 pViewData->GetPosFromPixel( aPosPixel.X(), aPosPixel.Y(), eWhich, nPosX, nPosY );
279 if ( ShowNoteMarker( nPosX, nPosY, FALSE ) )
281 Window::RequestHelp( rHEvt ); // alte Tip/Balloon ausschalten
282 bDone = TRUE;
286 if ( !bDone && pNoteMarker )
288 if ( pNoteMarker->IsByKeyboard() )
290 // marker which was shown for ctrl-F1 isn't removed by mouse events
292 else
293 DELETEZ(pNoteMarker);
296 // Image-Map / Text-URL
298 if ( bHelpEnabled && !bDone && !nButtonDown ) // nur ohne gedrueckten Button
300 String aHelpText;
301 Rectangle aPixRect;
302 Point aPosPixel = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
304 if ( pDrView ) // URL / Image-Map
306 SdrViewEvent aVEvt;
307 MouseEvent aMEvt( aPosPixel, 1, 0, MOUSE_LEFT );
308 SdrHitKind eHit = pDrView->PickAnything( aMEvt, SDRMOUSEBUTTONDOWN, aVEvt );
310 if ( eHit != SDRHIT_NONE && aVEvt.pObj != NULL )
312 // URL fuer IMapObject unter Pointer ist Hilfetext
313 if ( ScDrawLayer::GetIMapInfo( aVEvt.pObj ) )
315 Point aLogicPos = PixelToLogic( aPosPixel );
316 IMapObject* pIMapObj = ScDrawLayer::GetHitIMapObject(
317 aVEvt.pObj, aLogicPos, *this );
319 if ( pIMapObj )
321 // #44990# Bei ImageMaps die Description anzeigen, wenn vorhanden
322 aHelpText = pIMapObj->GetAltText();
323 if (!aHelpText.Len())
324 aHelpText = pIMapObj->GetURL();
325 aPixRect = LogicToPixel(aVEvt.pObj->GetLogicRect());
328 // URL in shape text or at shape itself (URL in text overrides object URL)
329 if ( aHelpText.Len() == 0 )
331 if( aVEvt.eEvent == SDREVENT_EXECUTEURL )
333 aHelpText = aVEvt.pURLField->GetURL();
334 aPixRect = LogicToPixel(aVEvt.pObj->GetLogicRect());
336 else
338 SdrObject* pObj = 0;
339 SdrPageView* pPV = 0;
340 Point aMDPos = PixelToLogic( aPosPixel );
341 if ( pDrView->PickObj(aMDPos, pDrView->getHitTolLog(), pObj, pPV, SDRSEARCH_ALSOONMASTER) )
343 if ( pObj->IsGroupObject() )
345 SdrObject* pHit = 0;
346 if ( pDrView->PickObj(aMDPos, pDrView->getHitTolLog(), pHit, pPV, SDRSEARCH_DEEP ) )
347 pObj = pHit;
349 ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
350 if ( pInfo && (pInfo->GetHlink().getLength() > 0) )
352 aPixRect = LogicToPixel(aVEvt.pObj->GetLogicRect());
353 aHelpText = pInfo->GetHlink();
361 if ( !aHelpText.Len() ) // Text-URL
363 String aUrl;
364 if ( GetEditUrl( aPosPixel, NULL, &aUrl, NULL ) )
366 aHelpText = INetURLObject::decode( aUrl, INET_HEX_ESCAPE,
367 INetURLObject::DECODE_UNAMBIGUOUS );
369 ScDocument* pDoc = pViewData->GetDocument();
370 SCsCOL nPosX;
371 SCsROW nPosY;
372 SCTAB nTab = pViewData->GetTabNo();
373 pViewData->GetPosFromPixel( aPosPixel.X(), aPosPixel.Y(), eWhich, nPosX, nPosY );
374 const ScPatternAttr* pPattern = pDoc->GetPattern( nPosX, nPosY, nTab );
376 ScHideTextCursor aHideCursor( pViewData, eWhich ); // MapMode is changed in GetEditArea
378 // bForceToTop = FALSE, use the cell's real position
379 aPixRect = pViewData->GetEditArea( eWhich, nPosX, nPosY, this, pPattern, FALSE );
383 if ( aHelpText.Len() )
385 Rectangle aScreenRect(OutputToScreenPixel(aPixRect.TopLeft()),
386 OutputToScreenPixel(aPixRect.BottomRight()));
388 if ( rHEvt.GetMode() & HELPMODE_BALLOON )
389 Help::ShowBalloon(this,rHEvt.GetMousePosPixel(), aScreenRect, aHelpText);
390 else if ( rHEvt.GetMode() & HELPMODE_QUICK )
391 Help::ShowQuickHelp(this,aScreenRect, aHelpText);
393 bDone = TRUE;
397 // Basic-Controls
399 if ( pDrView && bHelpEnabled && !bDone )
401 SdrPageView* pPV = pDrView->GetSdrPageView();
402 DBG_ASSERT( pPV, "SdrPageView* ist NULL" );
403 if (pPV)
404 bDone = ((ScDrawPage*)pPV->GetPage())->RequestHelp( this, pDrView, rHEvt );
407 // Wenn QuickHelp fuer AutoFill angezeigt wird, nicht wieder wegnehmen lassen
409 if ( nMouseStatus == SC_GM_TABDOWN && pViewData->GetRefType() == SC_REFTYPE_FILL &&
410 Help::IsQuickHelpEnabled() )
411 bDone = TRUE;
413 if (!bDone)
414 Window::RequestHelp( rHEvt );
417 BOOL ScGridWindow::IsMyModel(SdrEditView* pSdrView)
419 return pSdrView &&
420 pSdrView->GetModel() == pViewData->GetDocument()->GetDrawLayer();
423 void ScGridWindow::HideNoteMarker()
425 DELETEZ(pNoteMarker);
428 com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
429 ScGridWindow::CreateAccessible()
431 ScAccessibleDocument* pAccessibleDocument =
432 new ScAccessibleDocument(GetAccessibleParentWindow()->GetAccessible(),
433 pViewData->GetViewShell(), eWhich);
435 com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessible > xAccessible = pAccessibleDocument;
437 pAccessibleDocument->Init();
439 return xAccessible;