fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / Accessibility / AccessibleText.cxx
bloba9add1cb7618f94dc23593cde48647eae43083c1
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 "scitems.hxx"
21 #include <editeng/eeitem.hxx>
23 #include <memory>
24 #include "AccessibleText.hxx"
25 #include "AccessibleCell.hxx"
26 #include "tabvwsh.hxx"
27 #include "editutil.hxx"
28 #include "document.hxx"
29 #include "scmod.hxx"
30 #include "prevwsh.hxx"
31 #include "docsh.hxx"
32 #include "prevloc.hxx"
33 #include "patattr.hxx"
34 #include "inputwin.hxx"
35 #include <editeng/unofored.hxx>
36 #include <editeng/editview.hxx>
37 #include <editeng/unoedhlp.hxx>
38 #include <vcl/virdev.hxx>
39 #include <editeng/editobj.hxx>
40 #include <editeng/adjustitem.hxx>
41 #include <editeng/justifyitem.hxx>
42 #include <svx/svdmodel.hxx>
43 #include <svx/algitem.hxx>
44 #include <vcl/svapp.hxx>
46 class ScViewForwarder : public SvxViewForwarder
48 ScTabViewShell* mpViewShell;
49 ScAddress maCellPos;
50 ScSplitPos meSplitPos;
51 public:
52 ScViewForwarder(ScTabViewShell* pViewShell, ScSplitPos eSplitPos, const ScAddress& rCell);
53 virtual ~ScViewForwarder();
55 virtual bool IsValid() const SAL_OVERRIDE;
56 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
57 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
58 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
60 void SetInvalid();
63 ScViewForwarder::ScViewForwarder(ScTabViewShell* pViewShell, ScSplitPos eSplitPos, const ScAddress& rCell)
65 mpViewShell(pViewShell),
66 maCellPos(rCell),
67 meSplitPos(eSplitPos)
71 ScViewForwarder::~ScViewForwarder()
75 bool ScViewForwarder::IsValid() const
77 return mpViewShell != NULL;
80 Rectangle ScViewForwarder::GetVisArea() const
82 Rectangle aVisArea;
83 if (mpViewShell)
85 vcl::Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
86 if (pWindow)
88 aVisArea.SetSize(pWindow->GetSizePixel());
90 ScHSplitPos eWhichH = ((meSplitPos == SC_SPLIT_TOPLEFT) || (meSplitPos == SC_SPLIT_BOTTOMLEFT)) ?
91 SC_SPLIT_LEFT : SC_SPLIT_RIGHT;
92 ScVSplitPos eWhichV = ((meSplitPos == SC_SPLIT_TOPLEFT) || (meSplitPos == SC_SPLIT_TOPRIGHT)) ?
93 SC_SPLIT_TOP : SC_SPLIT_BOTTOM;
95 Point aBaseCellPos(mpViewShell->GetViewData().GetScrPos(mpViewShell->GetViewData().GetPosX(eWhichH),
96 mpViewShell->GetViewData().GetPosY(eWhichV), meSplitPos, true));
97 Point aCellPos(mpViewShell->GetViewData().GetScrPos(maCellPos.Col(), maCellPos.Row(), meSplitPos, true));
98 aVisArea.SetPos(aCellPos - aBaseCellPos);
101 else
103 OSL_FAIL("this ViewForwarder is not valid");
105 return aVisArea;
108 Point ScViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
110 if (mpViewShell)
112 vcl::Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
113 if (pWindow)
114 return pWindow->LogicToPixel( rPoint, rMapMode );
116 else
118 OSL_FAIL("this ViewForwarder is not valid");
120 return Point();
123 Point ScViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
125 if (mpViewShell)
127 vcl::Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
128 if (pWindow)
129 return pWindow->PixelToLogic( rPoint, rMapMode );
131 else
133 OSL_FAIL("this ViewForwarder is not valid");
135 return Point();
138 void ScViewForwarder::SetInvalid()
140 mpViewShell = NULL;
143 class ScEditObjectViewForwarder : public SvxViewForwarder
145 VclPtr<vcl::Window> mpWindow;
146 // #i49561# EditView needed for access to its visible area.
147 const EditView* mpEditView;
148 public:
149 ScEditObjectViewForwarder( vcl::Window* pWindow,
150 const EditView* _pEditView);
151 virtual ~ScEditObjectViewForwarder();
153 virtual bool IsValid() const SAL_OVERRIDE;
154 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
155 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
156 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
158 void SetInvalid();
161 ScEditObjectViewForwarder::ScEditObjectViewForwarder( vcl::Window* pWindow,
162 const EditView* _pEditView )
164 mpWindow(pWindow),
165 mpEditView( _pEditView )
169 ScEditObjectViewForwarder::~ScEditObjectViewForwarder()
173 bool ScEditObjectViewForwarder::IsValid() const
175 return (mpWindow != nullptr);
178 Rectangle ScEditObjectViewForwarder::GetVisArea() const
180 Rectangle aVisArea;
181 if (mpWindow)
183 Rectangle aVisRect(mpWindow->GetWindowExtentsRelative(mpWindow->GetAccessibleParentWindow()));
185 aVisRect.SetPos(Point(0, 0));
187 aVisArea = aVisRect;
189 else
191 OSL_FAIL("this ViewForwarder is not valid");
193 return aVisArea;
196 Point ScEditObjectViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
198 if (mpWindow)
200 // #i49561# - consider offset of the visible area
201 // of the EditView before converting point to pixel.
202 Point aPoint( rPoint );
203 if ( mpEditView )
205 Rectangle aEditViewVisArea( mpEditView->GetVisArea() );
206 aPoint += aEditViewVisArea.TopLeft();
208 return mpWindow->LogicToPixel( aPoint, rMapMode );
210 else
212 OSL_FAIL("this ViewForwarder is not valid");
214 return Point();
217 Point ScEditObjectViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
219 if (mpWindow)
221 // #i49561# - consider offset of the visible area
222 // of the EditView after converting point to logic.
223 Point aPoint( mpWindow->PixelToLogic( rPoint, rMapMode ) );
224 if ( mpEditView )
226 Rectangle aEditViewVisArea( mpEditView->GetVisArea() );
227 aPoint -= aEditViewVisArea.TopLeft();
229 return aPoint;
231 else
233 OSL_FAIL("this ViewForwarder is not valid");
235 return Point();
238 void ScEditObjectViewForwarder::SetInvalid()
240 mpWindow = NULL;
243 class ScPreviewViewForwarder : public SvxViewForwarder
245 protected:
246 ScPreviewShell* mpViewShell;
247 mutable ScPreviewTableInfo* mpTableInfo;
248 public:
249 ScPreviewViewForwarder(ScPreviewShell* pViewShell);
250 virtual ~ScPreviewViewForwarder();
252 virtual bool IsValid() const SAL_OVERRIDE;
253 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
254 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
255 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
257 void SetInvalid();
259 Rectangle GetVisRect() const;
261 // clips the VisArea and calculates with the negativ coordinates
262 Rectangle CorrectVisArea(const Rectangle& rVisArea) const;
265 ScPreviewViewForwarder::ScPreviewViewForwarder(ScPreviewShell* pViewShell)
267 mpViewShell(pViewShell),
268 mpTableInfo(NULL)
272 ScPreviewViewForwarder::~ScPreviewViewForwarder()
274 delete mpTableInfo;
277 bool ScPreviewViewForwarder::IsValid() const
279 return mpViewShell != NULL;
282 Rectangle ScPreviewViewForwarder::GetVisArea() const
284 Rectangle aVisArea;
285 OSL_FAIL("should be implemented in an abrevated class");
286 return aVisArea;
289 Point ScPreviewViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
291 if (mpViewShell)
293 vcl::Window* pWindow = mpViewShell->GetWindow();
294 if (pWindow)
296 MapMode aMapMode(pWindow->GetMapMode().GetMapUnit());
297 Point aPoint2( OutputDevice::LogicToLogic( rPoint, rMapMode, aMapMode) );
298 return pWindow->LogicToPixel(aPoint2);
301 else
303 OSL_FAIL("this ViewForwarder is not valid");
305 return Point();
308 Point ScPreviewViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
310 if (mpViewShell)
312 vcl::Window* pWindow = mpViewShell->GetWindow();
313 if (pWindow)
315 MapMode aMapMode(pWindow->GetMapMode());
316 aMapMode.SetOrigin(Point());
317 Point aPoint1( pWindow->PixelToLogic( rPoint ) );
318 Point aPoint2( OutputDevice::LogicToLogic( aPoint1,
319 aMapMode.GetMapUnit(),
320 rMapMode ) );
321 return aPoint2;
324 else
326 OSL_FAIL("this ViewForwarder is not valid");
328 return Point();
331 void ScPreviewViewForwarder::SetInvalid()
333 mpViewShell = NULL;
336 Rectangle ScPreviewViewForwarder::GetVisRect() const
338 if ( mpViewShell )
340 Size aOutputSize;
341 vcl::Window* pWindow = mpViewShell->GetWindow();
342 if ( pWindow )
343 aOutputSize = pWindow->GetOutputSizePixel();
344 Point aPoint;
345 Rectangle aVisRect( aPoint, aOutputSize );
346 return aVisRect;
348 return Rectangle();
351 Rectangle ScPreviewViewForwarder::CorrectVisArea(const Rectangle& rVisArea) const
353 Rectangle aVisArea(rVisArea);
354 Point aPos = aVisArea.TopLeft(); // get first the position to remember negative positions after clipping
356 vcl::Window* pWin = mpViewShell->GetWindow();
357 if (pWin)
358 aVisArea = pWin->GetWindowExtentsRelative(pWin).GetIntersection(aVisArea);
360 sal_Int32 nX(aPos.getX());
361 sal_Int32 nY(aPos.getY());
363 if (nX > 0)
364 nX = 0;
365 else if (nX < 0)
366 nX = -nX;
367 if (nY > 0)
368 nY = 0;
369 else if (nY < 0)
370 nY = -nY;
371 aVisArea.SetPos(Point(nX, nY));
373 return aVisArea;
376 class ScPreviewHeaderFooterViewForwarder : public ScPreviewViewForwarder
378 bool mbHeader;
379 public:
380 ScPreviewHeaderFooterViewForwarder(ScPreviewShell* pViewShell, bool bHeader);
381 virtual ~ScPreviewHeaderFooterViewForwarder();
383 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
386 ScPreviewHeaderFooterViewForwarder::ScPreviewHeaderFooterViewForwarder(ScPreviewShell* pViewShell, bool bHeader)
388 ScPreviewViewForwarder(pViewShell),
389 mbHeader(bHeader)
393 ScPreviewHeaderFooterViewForwarder::~ScPreviewHeaderFooterViewForwarder()
397 Rectangle ScPreviewHeaderFooterViewForwarder::GetVisArea() const
399 Rectangle aVisArea;
400 if (mpViewShell)
402 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
403 if ( mbHeader )
404 rData.GetHeaderPosition( aVisArea );
405 else
406 rData.GetFooterPosition( aVisArea );
408 aVisArea = CorrectVisArea(aVisArea);
410 else
412 OSL_FAIL("this ViewForwarder is not valid");
414 return aVisArea;
417 class ScPreviewCellViewForwarder : public ScPreviewViewForwarder
419 ScAddress maCellPos;
420 public:
421 ScPreviewCellViewForwarder(ScPreviewShell* pViewShell,
422 ScAddress aCellPos);
423 virtual ~ScPreviewCellViewForwarder();
425 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
428 ScPreviewCellViewForwarder::ScPreviewCellViewForwarder(ScPreviewShell* pViewShell,
429 ScAddress aCellPos)
431 ScPreviewViewForwarder(pViewShell),
432 maCellPos(aCellPos)
436 ScPreviewCellViewForwarder::~ScPreviewCellViewForwarder()
440 Rectangle ScPreviewCellViewForwarder::GetVisArea() const
442 Rectangle aVisArea;
443 if (mpViewShell)
445 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
446 aVisArea = rData.GetCellOutputRect(maCellPos);
448 aVisArea = CorrectVisArea(aVisArea);
450 else
452 OSL_FAIL("this ViewForwarder is not valid");
454 return aVisArea;
457 class ScPreviewHeaderCellViewForwarder : public ScPreviewViewForwarder
459 ScAddress maCellPos;
460 bool mbColHeader;
461 public:
462 ScPreviewHeaderCellViewForwarder(ScPreviewShell* pViewShell,
463 ScAddress aCellPos,
464 bool bColHeader);
465 virtual ~ScPreviewHeaderCellViewForwarder();
467 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
470 ScPreviewHeaderCellViewForwarder::ScPreviewHeaderCellViewForwarder(ScPreviewShell* pViewShell,
471 ScAddress aCellPos,
472 bool bColHeader)
474 ScPreviewViewForwarder(pViewShell),
475 maCellPos(aCellPos),
476 mbColHeader(bColHeader)
480 ScPreviewHeaderCellViewForwarder::~ScPreviewHeaderCellViewForwarder()
484 Rectangle ScPreviewHeaderCellViewForwarder::GetVisArea() const
486 Rectangle aVisArea;
487 if (mpViewShell)
489 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
490 aVisArea = rData.GetHeaderCellOutputRect(GetVisRect(), maCellPos, mbColHeader);
492 aVisArea = CorrectVisArea(aVisArea);
494 else
496 OSL_FAIL("this ViewForwarder is not valid");
498 return aVisArea;
501 class ScPreviewNoteViewForwarder : public ScPreviewViewForwarder
503 ScAddress maCellPos;
504 bool mbNoteMark;
505 public:
506 ScPreviewNoteViewForwarder(ScPreviewShell* pViewShell,
507 ScAddress aCellPos,
508 bool bNoteMark);
509 virtual ~ScPreviewNoteViewForwarder();
511 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
514 ScPreviewNoteViewForwarder::ScPreviewNoteViewForwarder(ScPreviewShell* pViewShell,
515 ScAddress aCellPos,
516 bool bNoteMark)
518 ScPreviewViewForwarder(pViewShell),
519 maCellPos(aCellPos),
520 mbNoteMark(bNoteMark)
524 ScPreviewNoteViewForwarder::~ScPreviewNoteViewForwarder()
528 Rectangle ScPreviewNoteViewForwarder::GetVisArea() const
530 Rectangle aVisArea;
531 if (mpViewShell)
533 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
534 aVisArea = rData.GetNoteInRangeOutputRect(GetVisRect(), mbNoteMark, maCellPos);
536 aVisArea = CorrectVisArea(aVisArea);
538 else
540 OSL_FAIL("this ViewForwarder is not valid");
542 return aVisArea;
545 class ScEditViewForwarder : public SvxEditViewForwarder
547 EditView* mpEditView;
548 VclPtr<vcl::Window> mpWindow;
549 public:
550 ScEditViewForwarder(EditView* pEditView, vcl::Window* pWin);
551 virtual ~ScEditViewForwarder();
553 virtual bool IsValid() const SAL_OVERRIDE;
554 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
555 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
556 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
557 virtual bool GetSelection( ESelection& rSelection ) const SAL_OVERRIDE;
558 virtual bool SetSelection( const ESelection& rSelection ) SAL_OVERRIDE;
559 virtual bool Copy() SAL_OVERRIDE;
560 virtual bool Cut() SAL_OVERRIDE;
561 virtual bool Paste() SAL_OVERRIDE;
563 void SetInvalid();
566 ScEditViewForwarder::ScEditViewForwarder(EditView* pEditView, vcl::Window* pWin)
567 : mpEditView(pEditView),
568 mpWindow(pWin)
572 ScEditViewForwarder::~ScEditViewForwarder()
576 bool ScEditViewForwarder::IsValid() const
578 return mpWindow && mpEditView;
581 Rectangle ScEditViewForwarder::GetVisArea() const
583 Rectangle aVisArea;
584 if (IsValid() && mpEditView->GetEditEngine())
586 MapMode aMapMode(mpEditView->GetEditEngine()->GetRefMapMode());
588 aVisArea = mpWindow->LogicToPixel( mpEditView->GetVisArea(), aMapMode );
590 else
592 OSL_FAIL("this EditViewForwarder is no longer valid");
594 return aVisArea;
597 Point ScEditViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
599 if (mpWindow)
600 return mpWindow->LogicToPixel( rPoint, rMapMode );
601 else
603 OSL_FAIL("this ViewForwarder is not valid");
605 return Point();
608 Point ScEditViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
610 if (mpWindow)
611 return mpWindow->PixelToLogic( rPoint, rMapMode );
612 else
614 OSL_FAIL("this ViewForwarder is not valid");
616 return Point();
619 bool ScEditViewForwarder::GetSelection( ESelection& rSelection ) const
621 bool bResult(false);
622 if (IsValid())
624 rSelection = mpEditView->GetSelection();
625 bResult = true;
627 else
629 OSL_FAIL("this ViewForwarder is not valid");
631 return bResult;
634 bool ScEditViewForwarder::SetSelection( const ESelection& rSelection )
636 bool bResult(false);
637 if (IsValid())
639 mpEditView->SetSelection(rSelection);
640 bResult = true;
642 else
644 OSL_FAIL("this ViewForwarder is not valid");
646 return bResult;
649 bool ScEditViewForwarder::Copy()
651 bool bResult(false);
652 if (IsValid())
654 mpEditView->Copy();
655 bResult = true;
657 else
659 OSL_FAIL("this ViewForwarder is not valid");
661 return bResult;
664 bool ScEditViewForwarder::Cut()
666 bool bResult(false);
667 if (IsValid())
669 mpEditView->Cut();
670 bResult = true;
672 else
674 OSL_FAIL("this ViewForwarder is not valid");
676 return bResult;
679 bool ScEditViewForwarder::Paste()
681 bool bResult(false);
682 if (IsValid())
684 mpEditView->Paste();
685 bResult = true;
687 else
689 OSL_FAIL("this ViewForwarder is not valid");
691 return bResult;
694 void ScEditViewForwarder::SetInvalid()
696 mpWindow = NULL;
697 mpEditView = NULL;
700 // ScAccessibleCellTextData: shared data between sub objects of a accessible cell text object
702 ScAccessibleCellTextData::ScAccessibleCellTextData(ScTabViewShell* pViewShell,
703 const ScAddress& rP, ScSplitPos eSplitPos, ScAccessibleCell* pAccCell)
704 : ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
705 mpViewForwarder(NULL),
706 mpEditViewForwarder(NULL),
707 mpViewShell(pViewShell),
708 meSplitPos(eSplitPos),
709 mpAccessibleCell( pAccCell )
713 ScAccessibleCellTextData::~ScAccessibleCellTextData()
715 if (pEditEngine)
716 pEditEngine->SetNotifyHdl(Link<>());
717 if (mpViewForwarder)
718 delete mpViewForwarder;
719 if (mpEditViewForwarder)
720 delete mpEditViewForwarder;
723 void ScAccessibleCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
725 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
726 if ( pSimpleHint )
728 sal_uLong nId = pSimpleHint->GetId();
729 if ( nId == SFX_HINT_DYING )
731 mpViewShell = NULL; // invalid now
732 if (mpViewForwarder)
733 mpViewForwarder->SetInvalid();
734 if (mpEditViewForwarder)
735 mpEditViewForwarder->SetInvalid();
738 ScAccessibleCellBaseTextData::Notify(rBC, rHint);
741 ScAccessibleTextData* ScAccessibleCellTextData::Clone() const
743 return new ScAccessibleCellTextData( mpViewShell, aCellPos, meSplitPos, mpAccessibleCell );
746 void ScAccessibleCellTextData::GetCellText(const ScAddress& rCellPos, OUString& rText)
748 // #104893#; don't use the input string
749 // ScCellTextData::GetCellText(rCellPos, rText);
750 ScDocument& rDoc = pDocShell->GetDocument();
751 // #104893#; use the displayed string
752 rText = rDoc.GetString(rCellPos.Col(), rCellPos.Row(), rCellPos.Tab());
753 if (mpViewShell)
755 const ScViewOptions& aOptions = mpViewShell->GetViewData().GetOptions();
756 CellType aCellType;
757 rDoc.GetCellType(rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), aCellType);
758 if (aCellType == CELLTYPE_FORMULA && aOptions.GetOption( VOPT_FORMULAS ))
760 rDoc.GetFormula( rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), rText);
762 else if (!aOptions.GetOption( VOPT_NULLVALS ))
764 if ((aCellType == CELLTYPE_VALUE || aCellType == CELLTYPE_FORMULA) && rDoc.GetValue(rCellPos) == 0.0)
765 rText.clear();
770 SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
772 ScCellTextData::GetTextForwarder(); // creates Forwarder and EditEngine
774 if ( pDocShell && pEditEngine && mpViewShell )
776 ScDocument& rDoc = pDocShell->GetDocument();
777 long nSizeX, nSizeY;
778 mpViewShell->GetViewData().GetMergeSizePixel(
779 aCellPos.Col(), aCellPos.Row(), nSizeX, nSizeY);
781 Size aSize(nSizeX, nSizeY);
783 // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
784 long nIndent = 0;
785 const SvxHorJustifyItem* pHorJustifyItem = static_cast< const SvxHorJustifyItem* >(
786 rDoc.GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_HOR_JUSTIFY ) );
787 SvxCellHorJustify eHorJust = ( pHorJustifyItem ? static_cast< SvxCellHorJustify >( pHorJustifyItem->GetValue() ) : SVX_HOR_JUSTIFY_STANDARD );
788 if ( eHorJust == SVX_HOR_JUSTIFY_LEFT )
790 const SfxUInt16Item* pIndentItem = static_cast< const SfxUInt16Item* >(
791 rDoc.GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_INDENT ) );
792 if ( pIndentItem )
794 nIndent = static_cast< long >( pIndentItem->GetValue() );
798 const SvxMarginItem* pMarginItem = static_cast< const SvxMarginItem* >(
799 rDoc.GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_MARGIN ) );
800 ScViewData& rViewData = mpViewShell->GetViewData();
801 double nPPTX = rViewData.GetPPTX();
802 double nPPTY = rViewData.GetPPTY();
803 long nLeftM = ( pMarginItem ? static_cast< long >( ( pMarginItem->GetLeftMargin() + nIndent ) * nPPTX ) : 0 );
804 long nTopM = ( pMarginItem ? static_cast< long >( pMarginItem->GetTopMargin() * nPPTY ) : 0 );
805 long nRightM = ( pMarginItem ? static_cast< long >( pMarginItem->GetRightMargin() * nPPTX ) : 0 );
806 long nBottomM = ( pMarginItem ? static_cast< long >( pMarginItem->GetBottomMargin() * nPPTY ) : 0 );
807 long nWidth = aSize.getWidth() - nLeftM - nRightM;
808 aSize.setWidth( nWidth );
809 aSize.setHeight( aSize.getHeight() - nTopM - nBottomM );
811 vcl::Window* pWin = mpViewShell->GetWindowByPos( meSplitPos );
812 if ( pWin )
814 aSize = pWin->PixelToLogic( aSize, pEditEngine->GetRefMapMode() );
817 /* #i19430# Gnopernicus reads text partly if it sticks out of the cell
818 boundaries. This leads to wrong results in cases where the cell text
819 is rotated, because rotation is not taken into account when calcu-
820 lating the visible part of the text. In these cases we will expand
821 the cell size passed as paper size to the edit engine. The function
822 accessibility::AccessibleStaticTextBase::GetParagraphBoundingBox()
823 (see svx/source/accessibility/AccessibleStaticTextBase.cxx) will
824 return the size of the complete text then, which is used to expand
825 the cell bounding box in ScAccessibleCell::GetBoundingBox()
826 (see sc/source/ui/Accessibility/AccessibleCell.cxx). */
827 const SfxInt32Item* pItem = static_cast< const SfxInt32Item* >(
828 rDoc.GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_ROTATE_VALUE ) );
829 if( pItem && (pItem->GetValue() != 0) )
831 pEditEngine->SetPaperSize( Size( LONG_MAX, aSize.getHeight() ) );
832 long nTxtWidth = static_cast< long >( pEditEngine->CalcTextWidth() );
833 aSize.setWidth( std::max( aSize.getWidth(), nTxtWidth + 2 ) );
835 else
837 // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
838 const SfxBoolItem* pLineBreakItem = static_cast< const SfxBoolItem* >(
839 rDoc.GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_LINEBREAK ) );
840 bool bLineBreak = ( pLineBreakItem && pLineBreakItem->GetValue() );
841 if ( !bLineBreak )
843 long nTxtWidth = static_cast< long >( pEditEngine->CalcTextWidth() );
844 aSize.setWidth( ::std::max( aSize.getWidth(), nTxtWidth ) );
848 pEditEngine->SetPaperSize( aSize );
850 // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
851 if ( eHorJust == SVX_HOR_JUSTIFY_STANDARD && rDoc.HasValueData( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ) )
853 pEditEngine->SetDefaultItem( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
856 Size aTextSize;
857 if ( pWin )
859 aTextSize = pWin->LogicToPixel( Size( pEditEngine->CalcTextWidth(), pEditEngine->GetTextHeight() ), pEditEngine->GetRefMapMode() );
861 long nTextWidth = aTextSize.Width();
862 long nTextHeight = aTextSize.Height();
864 long nOffsetX = nLeftM;
865 long nDiffX = nTextWidth - nWidth;
866 if ( nDiffX > 0 )
868 switch ( eHorJust )
870 case SVX_HOR_JUSTIFY_RIGHT:
872 nOffsetX -= nDiffX;
874 break;
875 case SVX_HOR_JUSTIFY_CENTER:
877 nOffsetX -= nDiffX / 2;
879 break;
880 default:
883 break;
887 long nOffsetY = 0;
888 const SvxVerJustifyItem* pVerJustifyItem = static_cast< const SvxVerJustifyItem* >(
889 rDoc.GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_VER_JUSTIFY ) );
890 SvxCellVerJustify eVerJust = ( pVerJustifyItem ? static_cast< SvxCellVerJustify >( pVerJustifyItem->GetValue() ) : SVX_VER_JUSTIFY_STANDARD );
891 switch ( eVerJust )
893 case SVX_VER_JUSTIFY_STANDARD:
894 case SVX_VER_JUSTIFY_BOTTOM:
896 nOffsetY = nSizeY - nBottomM - nTextHeight;
898 break;
899 case SVX_VER_JUSTIFY_CENTER:
901 nOffsetY = ( nSizeY - nTopM - nBottomM - nTextHeight ) / 2 + nTopM;
903 break;
904 default:
906 nOffsetY = nTopM;
908 break;
911 if ( mpAccessibleCell )
913 mpAccessibleCell->SetOffset( Point( nOffsetX, nOffsetY ) );
916 pEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
919 return pForwarder;
922 SvxViewForwarder* ScAccessibleCellTextData::GetViewForwarder()
924 if (!mpViewForwarder)
925 mpViewForwarder = new ScViewForwarder(mpViewShell, meSplitPos, aCellPos);
926 return mpViewForwarder;
929 SvxEditViewForwarder* ScAccessibleCellTextData::GetEditViewForwarder( bool /* bCreate */ )
931 //#102219#; there should no EditViewForwarder be, because the cell is now readonly in this interface
932 return NULL;
935 IMPL_LINK(ScAccessibleTextData, NotifyHdl, EENotify*, aNotify)
937 if( aNotify )
939 ::std::unique_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify );
941 if( aHint.get() )
942 GetBroadcaster().Broadcast( *aHint.get() );
945 return 0;
948 ScDocShell* ScAccessibleCellTextData::GetDocShell(ScTabViewShell* pViewShell)
950 ScDocShell* pDocSh = NULL;
951 if (pViewShell)
952 pDocSh = pViewShell->GetViewData().GetDocShell();
953 return pDocSh;
956 ScAccessibleEditObjectTextData::ScAccessibleEditObjectTextData(EditView* pEditView, vcl::Window* pWin, bool isClone)
958 mpViewForwarder(NULL),
959 mpEditViewForwarder(NULL),
960 mpEditView(pEditView),
961 mpEditEngine(pEditView ? pEditView->GetEditEngine() : 0),
962 mpForwarder(NULL),
963 mpWindow(pWin)
965 // If the object is cloned, do NOT add notify hdl.
966 mbIsCloned = isClone;
967 if (mpEditEngine && !mbIsCloned)
968 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
971 ScAccessibleEditObjectTextData::~ScAccessibleEditObjectTextData()
973 // If the object is cloned, do NOT set notify hdl.
974 if (mpEditEngine && !mbIsCloned)
975 mpEditEngine->SetNotifyHdl(Link<>());
976 if (mpViewForwarder)
977 delete mpViewForwarder;
978 if (mpEditViewForwarder)
979 delete mpEditViewForwarder;
980 if (mpForwarder)
981 delete mpForwarder;
984 void ScAccessibleEditObjectTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
986 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
987 if ( pSimpleHint )
989 sal_uLong nId = pSimpleHint->GetId();
990 if ( nId == SFX_HINT_DYING )
992 mpWindow = NULL;
993 mpEditView = NULL;
994 mpEditEngine = NULL;
995 DELETEZ(mpForwarder);
996 if (mpViewForwarder)
997 mpViewForwarder->SetInvalid();
998 if (mpEditViewForwarder)
999 mpEditViewForwarder->SetInvalid();
1002 ScAccessibleTextData::Notify(rBC, rHint);
1005 ScAccessibleTextData* ScAccessibleEditObjectTextData::Clone() const
1007 // Add para to indicate the object is cloned
1008 return new ScAccessibleEditObjectTextData(mpEditView, mpWindow, true);
1011 SvxTextForwarder* ScAccessibleEditObjectTextData::GetTextForwarder()
1013 if ((!mpForwarder && mpEditView) || (mpEditEngine && !mpEditEngine->GetNotifyHdl().IsSet()))
1015 if (!mpEditEngine)
1016 mpEditEngine = mpEditView->GetEditEngine();
1017 // If the object is cloned, do NOT add notify hdl.
1018 if (mpEditEngine && !mpEditEngine->GetNotifyHdl().IsSet()&&!mbIsCloned)
1019 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
1020 if(!mpForwarder)
1021 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1023 return mpForwarder;
1026 SvxViewForwarder* ScAccessibleEditObjectTextData::GetViewForwarder()
1028 if (!mpViewForwarder)
1030 // i#49561 Get right-aligned cell content to be read by screenreader.
1031 mpViewForwarder = new ScEditObjectViewForwarder( mpWindow, mpEditView );
1033 return mpViewForwarder;
1036 SvxEditViewForwarder* ScAccessibleEditObjectTextData::GetEditViewForwarder( bool bCreate )
1038 if (!mpEditViewForwarder && mpEditView)
1039 mpEditViewForwarder = new ScEditViewForwarder(mpEditView, mpWindow);
1040 if (bCreate)
1042 if (!mpEditView && mpEditViewForwarder)
1044 DELETEZ(mpEditViewForwarder);
1047 return mpEditViewForwarder;
1050 IMPL_LINK(ScAccessibleEditObjectTextData, NotifyHdl, EENotify*, aNotify)
1052 if( aNotify )
1054 ::std::unique_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify );
1056 if( aHint.get() )
1057 GetBroadcaster().Broadcast( *aHint.get() );
1060 return 0;
1063 ScAccessibleEditLineTextData::ScAccessibleEditLineTextData(EditView* pEditView, vcl::Window* pWin)
1065 ScAccessibleEditObjectTextData(pEditView, pWin),
1066 mbEditEngineCreated(false)
1068 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>( pWin );
1070 if (pTxtWnd)
1071 pTxtWnd->InsertAccessibleTextData( *this );
1074 ScAccessibleEditLineTextData::~ScAccessibleEditLineTextData()
1076 ScTextWnd* pTxtWnd = dynamic_cast< ScTextWnd* >(mpWindow.get());
1078 if (pTxtWnd)
1079 pTxtWnd->RemoveAccessibleTextData( *this );
1081 if (mbEditEngineCreated && mpEditEngine)
1083 delete mpEditEngine;
1084 mpEditEngine = NULL; // don't access in ScAccessibleEditObjectTextData dtor!
1086 else if (pTxtWnd && pTxtWnd->GetEditView() && pTxtWnd->GetEditView()->GetEditEngine())
1088 // the NotifyHdl also has to be removed from the ScTextWnd's EditEngine
1089 // (it's set in ScAccessibleEditLineTextData::GetTextForwarder, and mpEditEngine
1090 // is reset there)
1091 pTxtWnd->GetEditView()->GetEditEngine()->SetNotifyHdl(Link<>());
1095 void ScAccessibleEditLineTextData::Dispose()
1097 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>(mpWindow.get());
1099 if (pTxtWnd)
1100 pTxtWnd->RemoveAccessibleTextData( *this );
1102 ResetEditMode();
1103 mpWindow = NULL;
1106 ScAccessibleTextData* ScAccessibleEditLineTextData::Clone() const
1108 return new ScAccessibleEditLineTextData(mpEditView, mpWindow);
1111 SvxTextForwarder* ScAccessibleEditLineTextData::GetTextForwarder()
1113 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>(mpWindow.get());
1115 if (pTxtWnd)
1117 mpEditView = pTxtWnd->GetEditView();
1118 if (mpEditView)
1120 if (mbEditEngineCreated && mpEditEngine)
1121 ResetEditMode();
1122 mbEditEngineCreated = false;
1124 mpEditView = pTxtWnd->GetEditView();
1125 ScAccessibleEditObjectTextData::GetTextForwarder(); // fill the mpForwarder
1126 mpEditEngine = NULL;
1128 else
1130 if (mpEditEngine && !mbEditEngineCreated)
1131 ResetEditMode();
1132 if (!mpEditEngine)
1134 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1135 pEnginePool->FreezeIdRanges();
1136 mpEditEngine = new ScFieldEditEngine(NULL, pEnginePool, NULL, true);
1137 mbEditEngineCreated = true;
1138 mpEditEngine->EnableUndo( false );
1139 mpEditEngine->SetRefMapMode( MAP_100TH_MM );
1140 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1142 mpEditEngine->SetText(pTxtWnd->GetTextString());
1144 Size aSize(pTxtWnd->GetSizePixel());
1146 aSize = pTxtWnd->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1148 mpEditEngine->SetPaperSize(aSize);
1150 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
1154 return mpForwarder;
1157 SvxEditViewForwarder* ScAccessibleEditLineTextData::GetEditViewForwarder( bool bCreate )
1159 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>(mpWindow.get());
1161 if (pTxtWnd)
1163 mpEditView = pTxtWnd->GetEditView();
1164 if (!mpEditView && bCreate)
1166 if ( !pTxtWnd->IsInputActive() )
1168 pTxtWnd->StartEditEngine();
1169 pTxtWnd->GrabFocus();
1171 mpEditView = pTxtWnd->GetEditView();
1176 return ScAccessibleEditObjectTextData::GetEditViewForwarder(bCreate);
1179 void ScAccessibleEditLineTextData::ResetEditMode()
1181 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>(mpWindow.get());
1183 if (mbEditEngineCreated && mpEditEngine)
1184 delete mpEditEngine;
1185 else if (pTxtWnd && pTxtWnd->GetEditView() && pTxtWnd->GetEditView()->GetEditEngine())
1186 pTxtWnd->GetEditView()->GetEditEngine()->SetNotifyHdl(Link<>());
1187 mpEditEngine = NULL;
1189 DELETEZ(mpForwarder);
1190 DELETEZ(mpEditViewForwarder);
1191 DELETEZ(mpViewForwarder);
1192 mbEditEngineCreated = false;
1195 void ScAccessibleEditLineTextData::TextChanged()
1197 if (mbEditEngineCreated && mpEditEngine)
1199 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>(mpWindow.get());
1201 if (pTxtWnd)
1202 mpEditEngine->SetText(pTxtWnd->GetTextString());
1206 void ScAccessibleEditLineTextData::StartEdit()
1208 ResetEditMode();
1209 mpEditView = NULL;
1211 // send HINT_BEGEDIT
1212 SdrHint aHint(HINT_BEGEDIT);
1213 GetBroadcaster().Broadcast( aHint );
1216 void ScAccessibleEditLineTextData::EndEdit()
1218 // send HINT_ENDEDIT
1219 SdrHint aHint(HINT_ENDEDIT);
1220 GetBroadcaster().Broadcast( aHint );
1222 ResetEditMode();
1223 mpEditView = NULL;
1226 // ScAccessiblePreviewCellTextData: shared data between sub objects of a accessible cell text object
1228 ScAccessiblePreviewCellTextData::ScAccessiblePreviewCellTextData(ScPreviewShell* pViewShell,
1229 const ScAddress& rP)
1230 : ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
1231 mpViewForwarder(NULL),
1232 mpViewShell(pViewShell)
1236 ScAccessiblePreviewCellTextData::~ScAccessiblePreviewCellTextData()
1238 if (pEditEngine)
1239 pEditEngine->SetNotifyHdl(Link<>());
1240 if (mpViewForwarder)
1241 delete mpViewForwarder;
1244 void ScAccessiblePreviewCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1246 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
1247 if ( pSimpleHint )
1249 sal_uLong nId = pSimpleHint->GetId();
1250 if ( nId == SFX_HINT_DYING )
1252 mpViewShell = NULL; // invalid now
1253 if (mpViewForwarder)
1254 mpViewForwarder->SetInvalid();
1257 ScAccessibleCellBaseTextData::Notify(rBC, rHint);
1260 ScAccessibleTextData* ScAccessiblePreviewCellTextData::Clone() const
1262 return new ScAccessiblePreviewCellTextData(mpViewShell, aCellPos);
1265 SvxTextForwarder* ScAccessiblePreviewCellTextData::GetTextForwarder()
1267 bool bEditEngineBefore(pEditEngine != NULL);
1269 ScCellTextData::GetTextForwarder(); // creates Forwarder and EditEngine
1271 if (!bEditEngineBefore && pEditEngine)
1273 Size aSize(mpViewShell->GetLocationData().GetCellOutputRect(aCellPos).GetSize());
1274 vcl::Window* pWin = mpViewShell->GetWindow();
1275 if (pWin)
1276 aSize = pWin->PixelToLogic(aSize, pEditEngine->GetRefMapMode());
1277 pEditEngine->SetPaperSize(aSize);
1280 if (pEditEngine)
1281 pEditEngine->SetNotifyHdl( LINK(this, ScAccessiblePreviewCellTextData, NotifyHdl) );
1283 return pForwarder;
1286 SvxViewForwarder* ScAccessiblePreviewCellTextData::GetViewForwarder()
1288 if (!mpViewForwarder)
1289 mpViewForwarder = new ScPreviewCellViewForwarder(mpViewShell, aCellPos);
1290 return mpViewForwarder;
1293 ScDocShell* ScAccessiblePreviewCellTextData::GetDocShell(ScPreviewShell* pViewShell)
1295 ScDocShell* pDocSh = NULL;
1296 if (pViewShell)
1297 pDocSh = static_cast<ScDocShell*>( pViewShell->GetDocument().GetDocumentShell());
1298 return pDocSh;
1301 // ScAccessiblePreviewHeaderCellTextData: shared data between sub objects of a accessible cell text object
1303 ScAccessiblePreviewHeaderCellTextData::ScAccessiblePreviewHeaderCellTextData(ScPreviewShell* pViewShell,
1304 const OUString& rText, const ScAddress& rP, bool bColHeader, bool bRowHeader)
1305 : ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
1306 mpViewForwarder(NULL),
1307 mpViewShell(pViewShell),
1308 maText(rText),
1309 mbColHeader(bColHeader),
1310 mbRowHeader(bRowHeader)
1314 ScAccessiblePreviewHeaderCellTextData::~ScAccessiblePreviewHeaderCellTextData()
1316 if (pEditEngine)
1317 pEditEngine->SetNotifyHdl(Link<>());
1318 if (mpViewForwarder)
1319 delete mpViewForwarder;
1322 void ScAccessiblePreviewHeaderCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1324 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
1325 if ( pSimpleHint )
1327 sal_uLong nId = pSimpleHint->GetId();
1328 if ( nId == SFX_HINT_DYING )
1330 mpViewShell = NULL; // invalid now
1331 if (mpViewForwarder)
1332 mpViewForwarder->SetInvalid();
1335 ScAccessibleCellBaseTextData::Notify(rBC, rHint);
1338 ScAccessibleTextData* ScAccessiblePreviewHeaderCellTextData::Clone() const
1340 return new ScAccessiblePreviewHeaderCellTextData(mpViewShell, maText, aCellPos, mbColHeader, mbRowHeader);
1343 SvxTextForwarder* ScAccessiblePreviewHeaderCellTextData::GetTextForwarder()
1345 if (!pEditEngine)
1347 if ( pDocShell )
1349 ScDocument& rDoc = pDocShell->GetDocument();
1350 pEditEngine = rDoc.CreateFieldEditEngine();
1352 else
1354 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1355 pEnginePool->FreezeIdRanges();
1356 pEditEngine = new ScFieldEditEngine(NULL, pEnginePool, NULL, true);
1358 pEditEngine->EnableUndo( false );
1359 if (pDocShell)
1360 pEditEngine->SetRefDevice(pDocShell->GetRefDevice());
1361 else
1362 pEditEngine->SetRefMapMode( MAP_100TH_MM );
1363 pForwarder = new SvxEditEngineForwarder(*pEditEngine);
1366 if (bDataValid)
1367 return pForwarder;
1369 if (!maText.isEmpty())
1371 if ( mpViewShell )
1373 Size aOutputSize;
1374 vcl::Window* pWindow = mpViewShell->GetWindow();
1375 if ( pWindow )
1376 aOutputSize = pWindow->GetOutputSizePixel();
1377 Point aPoint;
1378 Rectangle aVisRect( aPoint, aOutputSize );
1379 Size aSize(mpViewShell->GetLocationData().GetHeaderCellOutputRect(aVisRect, aCellPos, mbColHeader).GetSize());
1380 if (pWindow)
1381 aSize = pWindow->PixelToLogic(aSize, pEditEngine->GetRefMapMode());
1382 pEditEngine->SetPaperSize(aSize);
1384 pEditEngine->SetText( maText );
1387 bDataValid = true;
1389 pEditEngine->SetNotifyHdl( LINK(this, ScAccessiblePreviewHeaderCellTextData, NotifyHdl) );
1391 return pForwarder;
1394 SvxViewForwarder* ScAccessiblePreviewHeaderCellTextData::GetViewForwarder()
1396 if (!mpViewForwarder)
1397 mpViewForwarder = new ScPreviewHeaderCellViewForwarder(mpViewShell, aCellPos, mbColHeader);
1398 return mpViewForwarder;
1401 ScDocShell* ScAccessiblePreviewHeaderCellTextData::GetDocShell(ScPreviewShell* pViewShell)
1403 ScDocShell* pDocSh = NULL;
1404 if (pViewShell)
1405 pDocSh = static_cast<ScDocShell*>(pViewShell->GetDocument().GetDocumentShell());
1406 return pDocSh;
1409 ScAccessibleHeaderTextData::ScAccessibleHeaderTextData(ScPreviewShell* pViewShell,
1410 const EditTextObject* pEditObj, bool bHeader, SvxAdjust eAdjust)
1412 mpViewForwarder(NULL),
1413 mpViewShell(pViewShell),
1414 mpEditEngine(NULL),
1415 mpForwarder(NULL),
1416 mpDocSh(NULL),
1417 mpEditObj(pEditObj),
1418 mbHeader(bHeader),
1419 mbDataValid(false),
1420 meAdjust(eAdjust)
1422 if (pViewShell)
1423 mpDocSh = static_cast<ScDocShell*>(pViewShell->GetDocument().GetDocumentShell());
1424 if (mpDocSh)
1425 mpDocSh->GetDocument().AddUnoObject(*this);
1428 ScAccessibleHeaderTextData::~ScAccessibleHeaderTextData()
1430 SolarMutexGuard aGuard; // needed for EditEngine dtor
1432 if (mpDocSh)
1433 mpDocSh->GetDocument().RemoveUnoObject(*this);
1434 if (mpEditEngine)
1435 mpEditEngine->SetNotifyHdl(Link<>());
1436 delete mpEditEngine;
1437 delete mpForwarder;
1440 ScAccessibleTextData* ScAccessibleHeaderTextData::Clone() const
1442 return new ScAccessibleHeaderTextData(mpViewShell, mpEditObj, mbHeader, meAdjust);
1445 void ScAccessibleHeaderTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
1447 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
1448 if ( pSimpleHint )
1450 sal_uLong nId = pSimpleHint->GetId();
1451 if ( nId == SFX_HINT_DYING )
1453 mpViewShell = NULL;// invalid now
1454 mpDocSh = NULL;
1455 if (mpViewForwarder)
1456 mpViewForwarder->SetInvalid();
1461 SvxTextForwarder* ScAccessibleHeaderTextData::GetTextForwarder()
1463 if (!mpEditEngine)
1465 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1466 pEnginePool->FreezeIdRanges();
1467 ScHeaderEditEngine* pHdrEngine = new ScHeaderEditEngine( pEnginePool, true );
1469 pHdrEngine->EnableUndo( false );
1470 pHdrEngine->SetRefMapMode( MAP_TWIP );
1472 // default font must be set, independently of document
1473 // -> use global pool from module
1475 SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() );
1476 const ScPatternAttr& rPattern = static_cast<const ScPatternAttr&>(SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN));
1477 rPattern.FillEditItemSet( &aDefaults );
1478 // FillEditItemSet adjusts font height to 1/100th mm,
1479 // but for header/footer twips is needed, as in the PatternAttr:
1480 aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT );
1481 aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK );
1482 aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL );
1483 aDefaults.Put( SvxAdjustItem( meAdjust, EE_PARA_JUST ) );
1484 pHdrEngine->SetDefaults( aDefaults );
1486 ScHeaderFieldData aData;
1487 if (mpViewShell)
1488 mpViewShell->FillFieldData(aData);
1489 else
1490 ScHeaderFooterTextObj::FillDummyFieldData( aData );
1491 pHdrEngine->SetData( aData );
1493 mpEditEngine = pHdrEngine;
1494 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1497 if (mbDataValid)
1498 return mpForwarder;
1500 if ( mpViewShell )
1502 Rectangle aVisRect;
1503 mpViewShell->GetLocationData().GetHeaderPosition(aVisRect);
1504 Size aSize(aVisRect.GetSize());
1505 vcl::Window* pWin = mpViewShell->GetWindow();
1506 if (pWin)
1507 aSize = pWin->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1508 mpEditEngine->SetPaperSize(aSize);
1510 if (mpEditObj)
1511 mpEditEngine->SetText(*mpEditObj);
1513 mbDataValid = true;
1514 return mpForwarder;
1517 SvxViewForwarder* ScAccessibleHeaderTextData::GetViewForwarder()
1519 if (!mpViewForwarder)
1520 mpViewForwarder = new ScPreviewHeaderFooterViewForwarder(mpViewShell, mbHeader);
1521 return mpViewForwarder;
1524 ScAccessibleNoteTextData::ScAccessibleNoteTextData(ScPreviewShell* pViewShell,
1525 const OUString& sText, const ScAddress& aCellPos, bool bMarkNote)
1527 mpViewForwarder(NULL),
1528 mpViewShell(pViewShell),
1529 mpEditEngine(NULL),
1530 mpForwarder(NULL),
1531 mpDocSh(NULL),
1532 msText(sText),
1533 maCellPos(aCellPos),
1534 mbMarkNote(bMarkNote),
1535 mbDataValid(false)
1537 if (pViewShell)
1538 mpDocSh = static_cast<ScDocShell*>(pViewShell->GetDocument().GetDocumentShell());
1539 if (mpDocSh)
1540 mpDocSh->GetDocument().AddUnoObject(*this);
1543 ScAccessibleNoteTextData::~ScAccessibleNoteTextData()
1545 SolarMutexGuard aGuard; // needed for EditEngine dtor
1547 if (mpDocSh)
1548 mpDocSh->GetDocument().RemoveUnoObject(*this);
1549 if (mpEditEngine)
1550 mpEditEngine->SetNotifyHdl(Link<>());
1551 delete mpEditEngine;
1552 delete mpForwarder;
1555 ScAccessibleTextData* ScAccessibleNoteTextData::Clone() const
1557 return new ScAccessibleNoteTextData(mpViewShell, msText, maCellPos, mbMarkNote);
1560 void ScAccessibleNoteTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
1562 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
1563 if ( pSimpleHint )
1565 sal_uLong nId = pSimpleHint->GetId();
1566 if ( nId == SFX_HINT_DYING )
1568 mpViewShell = NULL;// invalid now
1569 mpDocSh = NULL;
1570 if (mpViewForwarder)
1571 mpViewForwarder->SetInvalid();
1576 SvxTextForwarder* ScAccessibleNoteTextData::GetTextForwarder()
1578 if (!mpEditEngine)
1580 if ( mpDocSh )
1582 ScDocument& rDoc = mpDocSh->GetDocument();
1583 mpEditEngine = rDoc.CreateFieldEditEngine();
1585 else
1587 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1588 pEnginePool->FreezeIdRanges();
1589 mpEditEngine = new ScFieldEditEngine(NULL, pEnginePool, NULL, true);
1591 mpEditEngine->EnableUndo( false );
1592 if (mpDocSh)
1593 mpEditEngine->SetRefDevice(mpDocSh->GetRefDevice());
1594 else
1595 mpEditEngine->SetRefMapMode( MAP_100TH_MM );
1596 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1599 if (mbDataValid)
1600 return mpForwarder;
1602 if (!msText.isEmpty())
1605 if ( mpViewShell )
1607 Size aOutputSize;
1608 vcl::Window* pWindow = mpViewShell->GetWindow();
1609 if ( pWindow )
1610 aOutputSize = pWindow->GetOutputSizePixel();
1611 Point aPoint;
1612 Rectangle aVisRect( aPoint, aOutputSize );
1613 Size aSize(mpViewShell->GetLocationData().GetNoteInRangeOutputRect(aVisRect, mbMarkNote, maCellPos).GetSize());
1614 if (pWindow)
1615 aSize = pWindow->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1616 mpEditEngine->SetPaperSize(aSize);
1618 mpEditEngine->SetText( msText );
1621 mbDataValid = true;
1623 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleNoteTextData, NotifyHdl) );
1625 return mpForwarder;
1628 SvxViewForwarder* ScAccessibleNoteTextData::GetViewForwarder()
1630 if (!mpViewForwarder)
1631 mpViewForwarder = new ScPreviewNoteViewForwarder(mpViewShell, maCellPos, mbMarkNote);
1632 return mpViewForwarder;
1635 // CSV import =================================================================
1637 class ScCsvViewForwarder : public SvxViewForwarder
1639 Rectangle maBoundBox;
1640 VclPtr<vcl::Window> mpWindow;
1642 public:
1643 explicit ScCsvViewForwarder( vcl::Window* pWindow, const Rectangle& rBoundBox );
1645 virtual bool IsValid() const SAL_OVERRIDE;
1646 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
1647 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
1648 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
1650 void SetInvalid();
1653 ScCsvViewForwarder::ScCsvViewForwarder( vcl::Window* pWindow, const Rectangle& rBoundBox ) :
1654 maBoundBox( rBoundBox ),
1655 mpWindow( pWindow )
1659 bool ScCsvViewForwarder::IsValid() const
1661 return mpWindow != nullptr;
1664 Rectangle ScCsvViewForwarder::GetVisArea() const
1666 return maBoundBox;
1669 Point ScCsvViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
1671 if( !mpWindow ) return Point();
1672 return mpWindow->LogicToPixel( rPoint, rMapMode );
1675 Point ScCsvViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
1677 if( !mpWindow ) return Point();
1678 return mpWindow->PixelToLogic( rPoint, rMapMode );
1681 void ScCsvViewForwarder::SetInvalid()
1683 mpWindow = NULL;
1686 ScAccessibleCsvTextData::ScAccessibleCsvTextData(
1687 vcl::Window* pWindow, EditEngine* pEditEngine,
1688 const OUString& rCellText, const Rectangle& rBoundBox, const Size& rCellSize ) :
1689 mpWindow( pWindow ),
1690 mpEditEngine( pEditEngine ),
1691 maCellText( rCellText ),
1692 maBoundBox( rBoundBox ),
1693 maCellSize( rCellSize )
1697 ScAccessibleCsvTextData::~ScAccessibleCsvTextData()
1701 void ScAccessibleCsvTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1703 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
1704 if ( pSimpleHint )
1706 sal_uLong nId = pSimpleHint->GetId();
1707 if( nId == SFX_HINT_DYING )
1709 mpWindow = NULL;
1710 mpEditEngine = NULL;
1711 if (mpViewForwarder.get())
1712 mpViewForwarder->SetInvalid();
1715 ScAccessibleTextData::Notify( rBC, rHint );
1718 ScAccessibleTextData* ScAccessibleCsvTextData::Clone() const
1720 return new ScAccessibleCsvTextData( mpWindow, mpEditEngine, maCellText, maBoundBox, maCellSize );
1723 SvxTextForwarder* ScAccessibleCsvTextData::GetTextForwarder()
1725 if( mpEditEngine )
1727 mpEditEngine->SetPaperSize( maCellSize );
1728 mpEditEngine->SetText( maCellText );
1729 if( !mpTextForwarder.get() )
1730 mpTextForwarder.reset( new SvxEditEngineForwarder( *mpEditEngine ) );
1732 else
1733 mpTextForwarder.reset();
1734 return mpTextForwarder.get();
1737 SvxViewForwarder* ScAccessibleCsvTextData::GetViewForwarder()
1739 if( !mpViewForwarder.get() )
1740 mpViewForwarder.reset( new ScCsvViewForwarder( mpWindow, maBoundBox ) );
1741 return mpViewForwarder.get();
1744 SvxEditViewForwarder* ScAccessibleCsvTextData::GetEditViewForwarder( bool /* bCreate */ )
1746 return NULL;
1749 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */