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 : #include <editeng/eeitem.hxx>
21 :
22 : #include <editeng/flditem.hxx>
23 :
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>
32 :
33 : #include <unotools/localedatawrapper.hxx>
34 : #include <unotools/securityoptions.hxx>
35 :
36 : #include "viewuno.hxx"
37 : #include "AccessibleDocument.hxx"
38 : #include <com/sun/star/accessibility/XAccessible.hpp>
39 :
40 : #include "gridwin.hxx"
41 : #include "viewdata.hxx"
42 : #include "drawview.hxx"
43 : #include "drwlayer.hxx"
44 : #include "drawpage.hxx"
45 : #include "document.hxx"
46 : #include "notemark.hxx"
47 : #include "chgtrack.hxx"
48 : #include "chgviset.hxx"
49 : #include "dbfunc.hxx"
50 : #include "tabvwsh.hxx"
51 : #include "userdat.hxx"
52 : #include "postit.hxx"
53 : #include "global.hxx"
54 : #include "globstr.hrc"
55 : // -----------------------------------------------------------------------
56 :
57 0 : bool ScGridWindow::ShowNoteMarker( SCsCOL nPosX, SCsROW nPosY, bool bKeyboard )
58 : {
59 0 : bool bDone = false;
60 :
61 0 : ScDocument* pDoc = pViewData->GetDocument();
62 0 : SCTAB nTab = pViewData->GetTabNo();
63 0 : ScAddress aCellPos( nPosX, nPosY, nTab );
64 :
65 0 : String aTrackText;
66 0 : bool bLeftEdge = false;
67 :
68 : // Change-Tracking
69 :
70 0 : ScChangeTrack* pTrack = pDoc->GetChangeTrack();
71 0 : ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings();
72 0 : if ( pTrack && pTrack->GetFirst() && pSettings && pSettings->ShowChanges())
73 : {
74 0 : const ScChangeAction* pFound = NULL;
75 0 : const ScChangeAction* pFoundContent = NULL;
76 0 : const ScChangeAction* pFoundMove = NULL;
77 0 : long nModified = 0;
78 0 : const ScChangeAction* pAction = pTrack->GetFirst();
79 0 : while (pAction)
80 : {
81 0 : if ( pAction->IsVisible() &&
82 0 : ScViewUtil::IsActionShown( *pAction, *pSettings, *pDoc ) )
83 : {
84 0 : ScChangeActionType eType = pAction->GetType();
85 0 : const ScBigRange& rBig = pAction->GetBigRange();
86 0 : if ( rBig.aStart.Tab() == nTab )
87 : {
88 0 : ScRange aRange = rBig.MakeRange();
89 :
90 0 : if ( eType == SC_CAT_DELETE_ROWS )
91 0 : aRange.aEnd.SetRow( aRange.aStart.Row() );
92 0 : else if ( eType == SC_CAT_DELETE_COLS )
93 0 : aRange.aEnd.SetCol( aRange.aStart.Col() );
94 :
95 0 : if ( aRange.In( aCellPos ) )
96 : {
97 0 : pFound = pAction; // der letzte gewinnt
98 0 : switch ( eType )
99 : {
100 : case SC_CAT_CONTENT :
101 0 : pFoundContent = pAction;
102 0 : break;
103 : case SC_CAT_MOVE :
104 0 : pFoundMove = pAction;
105 0 : break;
106 : default:
107 : {
108 : // added to avoid warnings
109 : }
110 : }
111 0 : ++nModified;
112 : }
113 : }
114 0 : if ( eType == SC_CAT_MOVE )
115 : {
116 : ScRange aRange =
117 : ((const ScChangeActionMove*)pAction)->
118 0 : GetFromRange().MakeRange();
119 0 : if ( aRange.In( aCellPos ) )
120 : {
121 0 : pFound = pAction;
122 0 : ++nModified;
123 : }
124 : }
125 : }
126 0 : pAction = pAction->GetNext();
127 : }
128 :
129 0 : if ( pFound )
130 : {
131 0 : if ( pFoundContent && pFound->GetType() != SC_CAT_CONTENT )
132 0 : pFound = pFoundContent; // Content gewinnt
133 0 : if ( pFoundMove && pFound->GetType() != SC_CAT_MOVE &&
134 0 : pFoundMove->GetActionNumber() >
135 0 : pFound->GetActionNumber() )
136 0 : pFound = pFoundMove; // Move gewinnt
137 :
138 : // bei geloeschten Spalten: Pfeil auf die linke Seite der Zelle
139 0 : if ( pFound->GetType() == SC_CAT_DELETE_COLS )
140 0 : bLeftEdge = true;
141 :
142 0 : DateTime aDT = pFound->GetDateTime();
143 0 : aTrackText = pFound->GetUser();
144 0 : aTrackText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
145 0 : aTrackText += ScGlobal::pLocaleData->getDate(aDT);
146 0 : aTrackText += ' ';
147 0 : aTrackText += ScGlobal::pLocaleData->getTime(aDT);
148 0 : aTrackText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ":\n" ));
149 0 : String aComStr=pFound->GetComment();
150 0 : if(aComStr.Len()>0)
151 : {
152 0 : aTrackText += aComStr;
153 0 : aTrackText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "\n( " ));
154 : }
155 0 : OUString aTmp;
156 0 : pFound->GetDescription(aTmp, pDoc);
157 0 : aTrackText += String(aTmp);
158 0 : if(aComStr.Len()>0)
159 : {
160 0 : aTrackText +=')';
161 0 : }
162 : }
163 : }
164 :
165 : // Notiz nur, wenn sie nicht schon auf dem Drawing-Layer angezeigt wird:
166 0 : const ScPostIt* pNote = pDoc->GetNotes( aCellPos.Tab() )->findByAddress( aCellPos );
167 0 : if ( (aTrackText.Len() > 0) || (pNote && !pNote->IsCaptionShown()) )
168 : {
169 0 : bool bNew = true;
170 0 : bool bFast = false;
171 0 : if ( pNoteMarker ) // schon eine Notiz angezeigt
172 : {
173 0 : if ( pNoteMarker->GetDocPos() == aCellPos ) // dieselbe
174 0 : bNew = false; // dann stehenlassen
175 : else
176 0 : bFast = true; // sonst sofort
177 :
178 : // marker which was shown for ctrl-F1 isn't removed by mouse events
179 0 : if ( pNoteMarker->IsByKeyboard() && !bKeyboard )
180 0 : bNew = false;
181 : }
182 0 : if ( bNew )
183 : {
184 0 : if ( bKeyboard )
185 0 : bFast = true; // keyboard also shows the marker immediately
186 :
187 0 : delete pNoteMarker;
188 :
189 0 : bool bHSplit = pViewData->GetHSplitMode() != SC_SPLIT_NONE;
190 0 : bool bVSplit = pViewData->GetVSplitMode() != SC_SPLIT_NONE;
191 :
192 0 : Window* pLeft = pViewData->GetView()->GetWindowByPos( bVSplit ? SC_SPLIT_TOPLEFT : SC_SPLIT_BOTTOMLEFT );
193 0 : Window* pRight = bHSplit ? pViewData->GetView()->GetWindowByPos( bVSplit ? SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT ) : 0;
194 0 : Window* pBottom = bVSplit ? pViewData->GetView()->GetWindowByPos( SC_SPLIT_BOTTOMLEFT ) : 0;
195 0 : Window* pDiagonal = (bHSplit && bVSplit) ? pViewData->GetView()->GetWindowByPos( SC_SPLIT_BOTTOMRIGHT ) : 0;
196 : OSL_ENSURE( pLeft, "ScGridWindow::ShowNoteMarker - missing top-left grid window" );
197 :
198 : /* If caption is shown from right or bottom windows, adjust
199 : mapmode to include size of top-left window. */
200 0 : MapMode aMapMode = GetDrawMapMode( true );
201 0 : Size aLeftSize = pLeft->PixelToLogic( pLeft->GetOutputSizePixel(), aMapMode );
202 0 : Point aOrigin = aMapMode.GetOrigin();
203 0 : if( (this == pRight) || (this == pDiagonal) )
204 0 : aOrigin.X() += aLeftSize.Width();
205 0 : if( (this == pBottom) || (this == pDiagonal) )
206 0 : aOrigin.Y() += aLeftSize.Height();
207 0 : aMapMode.SetOrigin( aOrigin );
208 :
209 : pNoteMarker = new ScNoteMarker( pLeft, pRight, pBottom, pDiagonal,
210 : pDoc, aCellPos, aTrackText,
211 0 : aMapMode, bLeftEdge, bFast, bKeyboard );
212 0 : if ( pViewData->GetScDrawView() )
213 : {
214 : // get position for aCellPos
215 0 : if ( pDoc )
216 : {
217 : // get draw position in hmm for aCellPos
218 0 : Point aOldPos( pDoc->GetColOffset( aCellPos.Col(), aCellPos.Tab() ), pDoc->GetRowOffset( aCellPos.Row(), aCellPos.Tab() ) );
219 0 : aOldPos.X() = sc::TwipsToHMM( aOldPos.X() );
220 0 : aOldPos.Y() = sc::TwipsToHMM( aOldPos.Y() );
221 : // get screen pos in hmm for aCellPos
222 : // and equiv screen pos
223 0 : Point aScreenPos = pViewData->GetScrPos( aCellPos.Col(), aCellPos.Row(), eWhich, sal_True );
224 0 : MapMode aDrawMode = GetDrawMapMode();
225 0 : Point aCurPosHmm = PixelToLogic(aScreenPos, aDrawMode );
226 0 : Point aGridOff = aCurPosHmm -aOldPos;
227 : // fdo#63323 fix the X Position for the showing comment when
228 : // the mouse over the cell when the sheet are RTL
229 0 : if ( pDoc->IsNegativePage(nTab))
230 0 : aGridOff.setX(aCurPosHmm.getX() + aOldPos.getX());
231 0 : pNoteMarker->SetGridOff( aGridOff );
232 : }
233 0 : }
234 : }
235 :
236 0 : bDone = true; // something is shown (old or new)
237 : }
238 :
239 0 : return bDone;
240 : }
241 :
242 : // -----------------------------------------------------------------------
243 :
244 0 : void ScGridWindow::RequestHelp(const HelpEvent& rHEvt)
245 : {
246 : //To know whether to prefix STR_CTRLCLICKHYERLINK or STR_CLICKHYPERLINK
247 : //to hyperlink tooltips/help text
248 0 : SvtSecurityOptions aSecOpt;
249 0 : bool bCtrlClickHlink = aSecOpt.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
250 : //Global string STR_CTRLCLICKHYPERLINK i.e, "ctrl+click to open hyperlink:"
251 0 : OUString aCtrlClickHlinkStr = ScGlobal::GetRscString( STR_CTRLCLICKHYPERLINK );
252 : //Global string STR_CLICKHYPERLINK i.e, "click to open hyperlink"
253 0 : OUString aClickHlinkStr = ScGlobal::GetRscString( STR_CLICKHYPERLINK );
254 0 : sal_Bool bDone = false;
255 0 : sal_Bool bHelpEnabled = ( rHEvt.GetMode() & ( HELPMODE_BALLOON | HELPMODE_QUICK ) ) != 0;
256 0 : SdrView* pDrView = pViewData->GetScDrawView();
257 0 : sal_Bool bDrawTextEdit = false;
258 0 : if (pDrView)
259 0 : bDrawTextEdit = pDrView->IsTextEdit();
260 : // notes or change tracking
261 0 : if ( bHelpEnabled && !bDrawTextEdit )
262 : {
263 0 : Point aPosPixel = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
264 : SCsCOL nPosX;
265 : SCsROW nPosY;
266 0 : pViewData->GetPosFromPixel( aPosPixel.X(), aPosPixel.Y(), eWhich, nPosX, nPosY );
267 :
268 0 : if ( ShowNoteMarker( nPosX, nPosY, false ) )
269 : {
270 0 : Window::RequestHelp( rHEvt ); // alte Tip/Balloon ausschalten
271 0 : bDone = sal_True;
272 : }
273 : }
274 :
275 0 : if ( !bDone && pNoteMarker )
276 : {
277 0 : if ( pNoteMarker->IsByKeyboard() )
278 : {
279 : // marker which was shown for ctrl-F1 isn't removed by mouse events
280 : }
281 : else
282 0 : DELETEZ(pNoteMarker);
283 : }
284 :
285 : // Image-Map / Text-URL
286 :
287 0 : if ( bHelpEnabled && !bDone && !nButtonDown ) // nur ohne gedrueckten Button
288 : {
289 0 : String aHelpText;
290 0 : Rectangle aPixRect;
291 0 : Point aPosPixel = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
292 :
293 0 : if ( pDrView ) // URL / Image-Map
294 : {
295 0 : SdrViewEvent aVEvt;
296 0 : MouseEvent aMEvt( aPosPixel, 1, 0, MOUSE_LEFT );
297 0 : SdrHitKind eHit = pDrView->PickAnything( aMEvt, SDRMOUSEBUTTONDOWN, aVEvt );
298 :
299 0 : if ( eHit != SDRHIT_NONE && aVEvt.pObj != NULL )
300 : {
301 : // URL fuer IMapObject unter Pointer ist Hilfetext
302 0 : if ( ScDrawLayer::GetIMapInfo( aVEvt.pObj ) )
303 : {
304 0 : Point aLogicPos = PixelToLogic( aPosPixel );
305 : IMapObject* pIMapObj = ScDrawLayer::GetHitIMapObject(
306 0 : aVEvt.pObj, aLogicPos, *this );
307 :
308 0 : if ( pIMapObj )
309 : {
310 : // Bei ImageMaps die Description anzeigen, wenn vorhanden
311 0 : aHelpText = pIMapObj->GetAltText();
312 0 : if (!aHelpText.Len())
313 0 : aHelpText = pIMapObj->GetURL();
314 0 : if( bCtrlClickHlink )
315 : {
316 : //prefix STR_CTRLCLICKHYPERLINK to aHelpText
317 0 : aHelpText = aCtrlClickHlinkStr + aHelpText;
318 : }
319 : else
320 : {
321 : //Option not set, so prefix STR_CLICKHYPERLINK
322 0 : aHelpText = aClickHlinkStr + aHelpText;
323 : }
324 0 : aPixRect = LogicToPixel(aVEvt.pObj->GetLogicRect());
325 : }
326 : }
327 : // URL in shape text or at shape itself (URL in text overrides object URL)
328 0 : if ( aHelpText.Len() == 0 )
329 : {
330 0 : if( aVEvt.eEvent == SDREVENT_EXECUTEURL )
331 : {
332 0 : aHelpText = aVEvt.pURLField->GetURL();
333 0 : aPixRect = LogicToPixel(aVEvt.pObj->GetLogicRect());
334 : }
335 : else
336 : {
337 0 : SdrObject* pObj = 0;
338 0 : SdrPageView* pPV = 0;
339 0 : Point aMDPos = PixelToLogic( aPosPixel );
340 0 : if ( pDrView->PickObj(aMDPos, pDrView->getHitTolLog(), pObj, pPV, SDRSEARCH_ALSOONMASTER) )
341 : {
342 0 : if ( pObj->IsGroupObject() )
343 : {
344 0 : SdrObject* pHit = 0;
345 0 : if ( pDrView->PickObj(aMDPos, pDrView->getHitTolLog(), pHit, pPV, SDRSEARCH_DEEP ) )
346 0 : pObj = pHit;
347 : }
348 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
349 0 : if ( pInfo && (pInfo->GetHlink().getLength() > 0) )
350 : {
351 0 : aPixRect = LogicToPixel(aVEvt.pObj->GetLogicRect());
352 0 : aHelpText = pInfo->GetHlink();
353 0 : if( bCtrlClickHlink )
354 : {
355 : //prefix STR_CTRLCLICKHYPERLINK to aHelpText
356 0 : aHelpText = aCtrlClickHlinkStr + aHelpText;
357 : }
358 : else
359 : {
360 : //Option not set, so prefix STR_CLICKHYPERLINK
361 0 : aHelpText = aClickHlinkStr + aHelpText;
362 : }
363 :
364 : }
365 : }
366 : }
367 : }
368 0 : }
369 : }
370 :
371 0 : if ( !aHelpText.Len() ) // Text-URL
372 : {
373 0 : String aUrl;
374 0 : if ( GetEditUrl( aPosPixel, NULL, &aUrl, NULL ) )
375 : {
376 0 : aHelpText = INetURLObject::decode( aUrl, INET_HEX_ESCAPE,
377 0 : INetURLObject::DECODE_UNAMBIGUOUS );
378 :
379 0 : if( bCtrlClickHlink )
380 : {
381 : //prefix STR_CTRLCLICKHYPERLINK to aHelpText
382 0 : aHelpText = aCtrlClickHlinkStr + aHelpText;
383 : }
384 : else
385 : {
386 : //Option not set, so prefix STR_CLICKHYPERLINK
387 0 : aHelpText = aClickHlinkStr + aHelpText;
388 : }
389 :
390 :
391 0 : ScDocument* pDoc = pViewData->GetDocument();
392 : SCsCOL nPosX;
393 : SCsROW nPosY;
394 0 : SCTAB nTab = pViewData->GetTabNo();
395 0 : pViewData->GetPosFromPixel( aPosPixel.X(), aPosPixel.Y(), eWhich, nPosX, nPosY );
396 0 : const ScPatternAttr* pPattern = pDoc->GetPattern( nPosX, nPosY, nTab );
397 :
398 : // bForceToTop = sal_False, use the cell's real position
399 0 : aPixRect = pViewData->GetEditArea( eWhich, nPosX, nPosY, this, pPattern, false );
400 0 : }
401 : }
402 :
403 0 : if ( aHelpText.Len() )
404 : {
405 0 : Rectangle aScreenRect(OutputToScreenPixel(aPixRect.TopLeft()),
406 0 : OutputToScreenPixel(aPixRect.BottomRight()));
407 :
408 0 : if ( rHEvt.GetMode() & HELPMODE_BALLOON )
409 0 : Help::ShowBalloon(this,rHEvt.GetMousePosPixel(), aScreenRect, aHelpText);
410 0 : else if ( rHEvt.GetMode() & HELPMODE_QUICK )
411 0 : Help::ShowQuickHelp(this,aScreenRect, aHelpText);
412 :
413 0 : bDone = sal_True;
414 0 : }
415 : }
416 :
417 : // Basic-Controls
418 :
419 0 : if ( pDrView && bHelpEnabled && !bDone )
420 : {
421 0 : SdrPageView* pPV = pDrView->GetSdrPageView();
422 : OSL_ENSURE( pPV, "SdrPageView* ist NULL" );
423 0 : if (pPV)
424 0 : bDone = ((ScDrawPage*)pPV->GetPage())->RequestHelp( this, pDrView, rHEvt );
425 : }
426 :
427 : // Wenn QuickHelp fuer AutoFill angezeigt wird, nicht wieder wegnehmen lassen
428 :
429 0 : if ( nMouseStatus == SC_GM_TABDOWN && pViewData->GetRefType() == SC_REFTYPE_FILL &&
430 0 : Help::IsQuickHelpEnabled() )
431 0 : bDone = sal_True;
432 :
433 0 : if (!bDone)
434 0 : Window::RequestHelp( rHEvt );
435 0 : }
436 :
437 0 : bool ScGridWindow::IsMyModel(SdrEditView* pSdrView)
438 : {
439 0 : return pSdrView &&
440 0 : pSdrView->GetModel() == pViewData->GetDocument()->GetDrawLayer();
441 : }
442 :
443 4124 : void ScGridWindow::HideNoteMarker()
444 : {
445 4124 : DELETEZ(pNoteMarker);
446 4124 : }
447 :
448 : com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
449 2 : ScGridWindow::CreateAccessible()
450 : {
451 : ScAccessibleDocument* pAccessibleDocument =
452 : new ScAccessibleDocument(GetAccessibleParentWindow()->GetAccessible(),
453 2 : pViewData->GetViewShell(), eWhich);
454 :
455 2 : com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessible > xAccessible = pAccessibleDocument;
456 :
457 2 : pAccessibleDocument->Init();
458 :
459 2 : return xAccessible;
460 93 : }
461 :
462 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|