Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / Accessibility / AccessibleText.cxx
blob00bb8646f5c992ddd1c7724afb125a7fb51fe57b
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 .
21 #include "scitems.hxx"
22 #include <editeng/eeitem.hxx>
24 #include <memory>
25 #include "AccessibleText.hxx"
26 #include "AccessibleCell.hxx"
27 #include "tabvwsh.hxx"
28 #include "editutil.hxx"
29 #include "document.hxx"
30 #include "scmod.hxx"
31 #include "prevwsh.hxx"
32 #include "docsh.hxx"
33 #include "prevloc.hxx"
34 #include "patattr.hxx"
35 #include "inputwin.hxx"
36 #include <editeng/unofored.hxx>
37 #include <editeng/editview.hxx>
38 #include <editeng/unoedhlp.hxx>
39 #include <vcl/virdev.hxx>
40 #include <editeng/editobj.hxx>
41 #include <editeng/adjustitem.hxx>
42 #include <editeng/justifyitem.hxx>
43 #include <svx/svdmodel.hxx>
44 #include <svx/algitem.hxx>
45 #include <vcl/svapp.hxx>
48 class ScViewForwarder : public SvxViewForwarder
50 ScTabViewShell* mpViewShell;
51 ScAddress maCellPos;
52 ScSplitPos meSplitPos;
53 public:
54 ScViewForwarder(ScTabViewShell* pViewShell, ScSplitPos eSplitPos, const ScAddress& rCell);
55 virtual ~ScViewForwarder();
57 virtual bool IsValid() const SAL_OVERRIDE;
58 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
59 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
60 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
62 void SetInvalid();
65 ScViewForwarder::ScViewForwarder(ScTabViewShell* pViewShell, ScSplitPos eSplitPos, const ScAddress& rCell)
67 mpViewShell(pViewShell),
68 maCellPos(rCell),
69 meSplitPos(eSplitPos)
73 ScViewForwarder::~ScViewForwarder()
77 bool ScViewForwarder::IsValid() const
79 return mpViewShell != NULL;
82 Rectangle ScViewForwarder::GetVisArea() const
84 Rectangle aVisArea;
85 if (mpViewShell)
87 Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
88 if (pWindow)
90 aVisArea.SetSize(pWindow->GetSizePixel());
92 ScHSplitPos eWhichH = ((meSplitPos == SC_SPLIT_TOPLEFT) || (meSplitPos == SC_SPLIT_BOTTOMLEFT)) ?
93 SC_SPLIT_LEFT : SC_SPLIT_RIGHT;
94 ScVSplitPos eWhichV = ((meSplitPos == SC_SPLIT_TOPLEFT) || (meSplitPos == SC_SPLIT_TOPRIGHT)) ?
95 SC_SPLIT_TOP : SC_SPLIT_BOTTOM;
97 Point aBaseCellPos(mpViewShell->GetViewData()->GetScrPos(mpViewShell->GetViewData()->GetPosX(eWhichH),
98 mpViewShell->GetViewData()->GetPosY(eWhichV), meSplitPos, true));
99 Point aCellPos(mpViewShell->GetViewData()->GetScrPos(maCellPos.Col(), maCellPos.Row(), meSplitPos, true));
100 aVisArea.SetPos(aCellPos - aBaseCellPos);
103 else
105 OSL_FAIL("this ViewForwarder is not valid");
107 return aVisArea;
110 Point ScViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
112 if (mpViewShell)
114 Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
115 if (pWindow)
116 return pWindow->LogicToPixel( rPoint, rMapMode );
118 else
120 OSL_FAIL("this ViewForwarder is not valid");
122 return Point();
125 Point ScViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
127 if (mpViewShell)
129 Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
130 if (pWindow)
131 return pWindow->PixelToLogic( rPoint, rMapMode );
133 else
135 OSL_FAIL("this ViewForwarder is not valid");
137 return Point();
140 void ScViewForwarder::SetInvalid()
142 mpViewShell = NULL;
145 class ScEditObjectViewForwarder : public SvxViewForwarder
147 Window* mpWindow;
148 // #i49561# EditView needed for access to its visible area.
149 const EditView* mpEditView;
150 public:
151 ScEditObjectViewForwarder( Window* pWindow,
152 const EditView* _pEditView);
153 virtual ~ScEditObjectViewForwarder();
155 virtual bool IsValid() const SAL_OVERRIDE;
156 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
157 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
158 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
160 void SetInvalid();
163 ScEditObjectViewForwarder::ScEditObjectViewForwarder( Window* pWindow,
164 const EditView* _pEditView )
166 mpWindow(pWindow),
167 mpEditView( _pEditView )
171 ScEditObjectViewForwarder::~ScEditObjectViewForwarder()
175 bool ScEditObjectViewForwarder::IsValid() const
177 return (mpWindow != NULL);
180 Rectangle ScEditObjectViewForwarder::GetVisArea() const
182 Rectangle aVisArea;
183 if (mpWindow)
185 Rectangle aVisRect(mpWindow->GetWindowExtentsRelative(mpWindow->GetAccessibleParentWindow()));
187 aVisRect.SetPos(Point(0, 0));
189 aVisArea = aVisRect;
191 else
193 OSL_FAIL("this ViewForwarder is not valid");
195 return aVisArea;
198 Point ScEditObjectViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
200 if (mpWindow)
202 // #i49561# - consider offset of the visible area
203 // of the EditView before converting point to pixel.
204 Point aPoint( rPoint );
205 if ( mpEditView )
207 Rectangle aEditViewVisArea( mpEditView->GetVisArea() );
208 aPoint += aEditViewVisArea.TopLeft();
210 return mpWindow->LogicToPixel( aPoint, rMapMode );
212 else
214 OSL_FAIL("this ViewForwarder is not valid");
216 return Point();
219 Point ScEditObjectViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
221 if (mpWindow)
223 // #i49561# - consider offset of the visible area
224 // of the EditView after converting point to logic.
225 Point aPoint( mpWindow->PixelToLogic( rPoint, rMapMode ) );
226 if ( mpEditView )
228 Rectangle aEditViewVisArea( mpEditView->GetVisArea() );
229 aPoint -= aEditViewVisArea.TopLeft();
231 return aPoint;
233 else
235 OSL_FAIL("this ViewForwarder is not valid");
237 return Point();
240 void ScEditObjectViewForwarder::SetInvalid()
242 mpWindow = NULL;
245 class ScPreviewViewForwarder : public SvxViewForwarder
247 protected:
248 ScPreviewShell* mpViewShell;
249 mutable ScPreviewTableInfo* mpTableInfo;
250 public:
251 ScPreviewViewForwarder(ScPreviewShell* pViewShell);
252 virtual ~ScPreviewViewForwarder();
254 virtual bool IsValid() const SAL_OVERRIDE;
255 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
256 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
257 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
259 void SetInvalid();
261 Rectangle GetVisRect() const;
263 // clips the VisArea and calculates with the negativ coordinates
264 Rectangle CorrectVisArea(const Rectangle& rVisArea) const;
267 ScPreviewViewForwarder::ScPreviewViewForwarder(ScPreviewShell* pViewShell)
269 mpViewShell(pViewShell),
270 mpTableInfo(NULL)
274 ScPreviewViewForwarder::~ScPreviewViewForwarder()
276 delete mpTableInfo;
279 bool ScPreviewViewForwarder::IsValid() const
281 return mpViewShell != NULL;
284 Rectangle ScPreviewViewForwarder::GetVisArea() const
286 Rectangle aVisArea;
287 OSL_FAIL("should be implemented in an abrevated class");
288 return aVisArea;
291 Point ScPreviewViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
293 if (mpViewShell)
295 Window* pWindow = mpViewShell->GetWindow();
296 if (pWindow)
298 MapMode aMapMode(pWindow->GetMapMode().GetMapUnit());
299 Point aPoint2( OutputDevice::LogicToLogic( rPoint, rMapMode, aMapMode) );
300 return pWindow->LogicToPixel(aPoint2);
303 else
305 OSL_FAIL("this ViewForwarder is not valid");
307 return Point();
310 Point ScPreviewViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
312 if (mpViewShell)
314 Window* pWindow = mpViewShell->GetWindow();
315 if (pWindow)
317 MapMode aMapMode(pWindow->GetMapMode());
318 aMapMode.SetOrigin(Point());
319 Point aPoint1( pWindow->PixelToLogic( rPoint ) );
320 Point aPoint2( OutputDevice::LogicToLogic( aPoint1,
321 aMapMode.GetMapUnit(),
322 rMapMode ) );
323 return aPoint2;
326 else
328 OSL_FAIL("this ViewForwarder is not valid");
330 return Point();
333 void ScPreviewViewForwarder::SetInvalid()
335 mpViewShell = NULL;
338 Rectangle ScPreviewViewForwarder::GetVisRect() const
340 if ( mpViewShell )
342 Size aOutputSize;
343 Window* pWindow = mpViewShell->GetWindow();
344 if ( pWindow )
345 aOutputSize = pWindow->GetOutputSizePixel();
346 Point aPoint;
347 Rectangle aVisRect( aPoint, aOutputSize );
348 return aVisRect;
350 return Rectangle();
353 Rectangle ScPreviewViewForwarder::CorrectVisArea(const Rectangle& rVisArea) const
355 Rectangle aVisArea(rVisArea);
356 Point aPos = aVisArea.TopLeft(); // get first the position to remember negative positions after clipping
358 Window* pWin = mpViewShell->GetWindow();
359 if (pWin)
360 aVisArea = pWin->GetWindowExtentsRelative(pWin).GetIntersection(aVisArea);
362 sal_Int32 nX(aPos.getX());
363 sal_Int32 nY(aPos.getY());
365 if (nX > 0)
366 nX = 0;
367 else if (nX < 0)
368 nX = -nX;
369 if (nY > 0)
370 nY = 0;
371 else if (nY < 0)
372 nY = -nY;
373 aVisArea.SetPos(Point(nX, nY));
375 return aVisArea;
378 class ScPreviewHeaderFooterViewForwarder : public ScPreviewViewForwarder
380 bool mbHeader;
381 public:
382 ScPreviewHeaderFooterViewForwarder(ScPreviewShell* pViewShell, bool bHeader);
383 virtual ~ScPreviewHeaderFooterViewForwarder();
385 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
388 ScPreviewHeaderFooterViewForwarder::ScPreviewHeaderFooterViewForwarder(ScPreviewShell* pViewShell, bool bHeader)
390 ScPreviewViewForwarder(pViewShell),
391 mbHeader(bHeader)
395 ScPreviewHeaderFooterViewForwarder::~ScPreviewHeaderFooterViewForwarder()
399 Rectangle ScPreviewHeaderFooterViewForwarder::GetVisArea() const
401 Rectangle aVisArea;
402 if (mpViewShell)
404 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
405 if ( mbHeader )
406 rData.GetHeaderPosition( aVisArea );
407 else
408 rData.GetFooterPosition( aVisArea );
410 aVisArea = CorrectVisArea(aVisArea);
412 else
414 OSL_FAIL("this ViewForwarder is not valid");
416 return aVisArea;
419 class ScPreviewCellViewForwarder : public ScPreviewViewForwarder
421 ScAddress maCellPos;
422 public:
423 ScPreviewCellViewForwarder(ScPreviewShell* pViewShell,
424 ScAddress aCellPos);
425 virtual ~ScPreviewCellViewForwarder();
427 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
430 ScPreviewCellViewForwarder::ScPreviewCellViewForwarder(ScPreviewShell* pViewShell,
431 ScAddress aCellPos)
433 ScPreviewViewForwarder(pViewShell),
434 maCellPos(aCellPos)
438 ScPreviewCellViewForwarder::~ScPreviewCellViewForwarder()
442 Rectangle ScPreviewCellViewForwarder::GetVisArea() const
444 Rectangle aVisArea;
445 if (mpViewShell)
447 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
448 aVisArea = rData.GetCellOutputRect(maCellPos);
450 aVisArea = CorrectVisArea(aVisArea);
452 else
454 OSL_FAIL("this ViewForwarder is not valid");
456 return aVisArea;
459 class ScPreviewHeaderCellViewForwarder : public ScPreviewViewForwarder
461 ScAddress maCellPos;
462 bool mbColHeader;
463 public:
464 ScPreviewHeaderCellViewForwarder(ScPreviewShell* pViewShell,
465 ScAddress aCellPos,
466 bool bColHeader);
467 virtual ~ScPreviewHeaderCellViewForwarder();
469 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
472 ScPreviewHeaderCellViewForwarder::ScPreviewHeaderCellViewForwarder(ScPreviewShell* pViewShell,
473 ScAddress aCellPos,
474 bool bColHeader)
476 ScPreviewViewForwarder(pViewShell),
477 maCellPos(aCellPos),
478 mbColHeader(bColHeader)
482 ScPreviewHeaderCellViewForwarder::~ScPreviewHeaderCellViewForwarder()
486 Rectangle ScPreviewHeaderCellViewForwarder::GetVisArea() const
488 Rectangle aVisArea;
489 if (mpViewShell)
491 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
492 aVisArea = rData.GetHeaderCellOutputRect(GetVisRect(), maCellPos, mbColHeader);
494 aVisArea = CorrectVisArea(aVisArea);
496 else
498 OSL_FAIL("this ViewForwarder is not valid");
500 return aVisArea;
503 class ScPreviewNoteViewForwarder : public ScPreviewViewForwarder
505 ScAddress maCellPos;
506 bool mbNoteMark;
507 public:
508 ScPreviewNoteViewForwarder(ScPreviewShell* pViewShell,
509 ScAddress aCellPos,
510 bool bNoteMark);
511 virtual ~ScPreviewNoteViewForwarder();
513 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
516 ScPreviewNoteViewForwarder::ScPreviewNoteViewForwarder(ScPreviewShell* pViewShell,
517 ScAddress aCellPos,
518 bool bNoteMark)
520 ScPreviewViewForwarder(pViewShell),
521 maCellPos(aCellPos),
522 mbNoteMark(bNoteMark)
526 ScPreviewNoteViewForwarder::~ScPreviewNoteViewForwarder()
530 Rectangle ScPreviewNoteViewForwarder::GetVisArea() const
532 Rectangle aVisArea;
533 if (mpViewShell)
535 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
536 aVisArea = rData.GetNoteInRangeOutputRect(GetVisRect(), mbNoteMark, maCellPos);
538 aVisArea = CorrectVisArea(aVisArea);
540 else
542 OSL_FAIL("this ViewForwarder is not valid");
544 return aVisArea;
547 class ScEditViewForwarder : public SvxEditViewForwarder
549 EditView* mpEditView;
550 Window* mpWindow;
551 public:
552 ScEditViewForwarder(EditView* pEditView, Window* pWin);
553 virtual ~ScEditViewForwarder();
555 virtual bool IsValid() const SAL_OVERRIDE;
556 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
557 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
558 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
559 virtual bool GetSelection( ESelection& rSelection ) const SAL_OVERRIDE;
560 virtual bool SetSelection( const ESelection& rSelection ) SAL_OVERRIDE;
561 virtual bool Copy() SAL_OVERRIDE;
562 virtual bool Cut() SAL_OVERRIDE;
563 virtual bool Paste() SAL_OVERRIDE;
565 void GrabFocus();
567 void SetInvalid();
570 ScEditViewForwarder::ScEditViewForwarder(EditView* pEditView, Window* pWin)
571 : mpEditView(pEditView),
572 mpWindow(pWin)
574 GrabFocus();
577 ScEditViewForwarder::~ScEditViewForwarder()
581 bool ScEditViewForwarder::IsValid() const
583 return mpWindow && mpEditView;
586 Rectangle ScEditViewForwarder::GetVisArea() const
588 Rectangle aVisArea;
589 if (IsValid() && mpEditView->GetEditEngine())
591 MapMode aMapMode(mpEditView->GetEditEngine()->GetRefMapMode());
593 aVisArea = mpWindow->LogicToPixel( mpEditView->GetVisArea(), aMapMode );
595 else
597 OSL_FAIL("this EditViewForwarder is no longer valid");
599 return aVisArea;
602 Point ScEditViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
604 if (mpWindow)
605 return mpWindow->LogicToPixel( rPoint, rMapMode );
606 else
608 OSL_FAIL("this ViewForwarder is not valid");
610 return Point();
613 Point ScEditViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
615 if (mpWindow)
616 return mpWindow->PixelToLogic( rPoint, rMapMode );
617 else
619 OSL_FAIL("this ViewForwarder is not valid");
621 return Point();
624 bool ScEditViewForwarder::GetSelection( ESelection& rSelection ) const
626 bool bResult(false);
627 if (IsValid())
629 rSelection = mpEditView->GetSelection();
630 bResult = true;
632 else
634 OSL_FAIL("this ViewForwarder is not valid");
636 return bResult;
639 bool ScEditViewForwarder::SetSelection( const ESelection& rSelection )
641 bool bResult(false);
642 if (IsValid())
644 mpEditView->SetSelection(rSelection);
645 bResult = true;
647 else
649 OSL_FAIL("this ViewForwarder is not valid");
651 return bResult;
654 bool ScEditViewForwarder::Copy()
656 bool bResult(false);
657 if (IsValid())
659 mpEditView->Copy();
660 bResult = true;
662 else
664 OSL_FAIL("this ViewForwarder is not valid");
666 return bResult;
669 bool ScEditViewForwarder::Cut()
671 bool bResult(false);
672 if (IsValid())
674 mpEditView->Cut();
675 bResult = true;
677 else
679 OSL_FAIL("this ViewForwarder is not valid");
681 return bResult;
684 bool ScEditViewForwarder::Paste()
686 bool bResult(false);
687 if (IsValid())
689 mpEditView->Paste();
690 bResult = true;
692 else
694 OSL_FAIL("this ViewForwarder is not valid");
696 return bResult;
699 void ScEditViewForwarder::GrabFocus()
703 void ScEditViewForwarder::SetInvalid()
705 mpWindow = NULL;
706 mpEditView = NULL;
709 // ScAccessibleCellTextData: shared data between sub objects of a accessible cell text object
711 ScAccessibleCellTextData::ScAccessibleCellTextData(ScTabViewShell* pViewShell,
712 const ScAddress& rP, ScSplitPos eSplitPos, ScAccessibleCell* pAccCell)
713 : ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
714 mpViewForwarder(NULL),
715 mpEditViewForwarder(NULL),
716 mpViewShell(pViewShell),
717 meSplitPos(eSplitPos),
718 mpAccessibleCell( pAccCell )
722 ScAccessibleCellTextData::~ScAccessibleCellTextData()
724 if (pEditEngine)
725 pEditEngine->SetNotifyHdl(Link());
726 if (mpViewForwarder)
727 delete mpViewForwarder;
728 if (mpEditViewForwarder)
729 delete mpEditViewForwarder;
732 void ScAccessibleCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
734 if ( rHint.ISA( SfxSimpleHint ) )
736 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
737 if ( nId == SFX_HINT_DYING )
739 mpViewShell = NULL; // invalid now
740 if (mpViewForwarder)
741 mpViewForwarder->SetInvalid();
742 if (mpEditViewForwarder)
743 mpEditViewForwarder->SetInvalid();
746 ScAccessibleCellBaseTextData::Notify(rBC, rHint);
749 ScAccessibleTextData* ScAccessibleCellTextData::Clone() const
751 return new ScAccessibleCellTextData( mpViewShell, aCellPos, meSplitPos, mpAccessibleCell );
754 void ScAccessibleCellTextData::GetCellText(const ScAddress& rCellPos, OUString& rText)
756 // #104893#; don't use the input string
757 // ScCellTextData::GetCellText(rCellPos, rText);
758 ScDocument* pDoc = pDocShell->GetDocument();
759 if (pDoc)
761 // #104893#; use the displayed string
762 rText = pDoc->GetString(rCellPos.Col(), rCellPos.Row(), rCellPos.Tab());
763 if (mpViewShell)
765 const ScViewOptions& aOptions = mpViewShell->GetViewData()->GetOptions();
766 CellType aCellType;
767 pDoc->GetCellType(rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), aCellType);
768 if (aCellType == CELLTYPE_FORMULA && aOptions.GetOption( VOPT_FORMULAS ))
770 pDoc->GetFormula( rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), rText);
772 else if (!aOptions.GetOption( VOPT_NULLVALS ))
774 if ((aCellType == CELLTYPE_VALUE || aCellType == CELLTYPE_FORMULA) && pDoc->GetValue(rCellPos) == 0.0)
775 rText = "";
781 SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
783 ScCellTextData::GetTextForwarder(); // creates Forwarder and EditEngine
785 ScDocument* pDoc = ( pDocShell ? pDocShell->GetDocument() : NULL );
786 if ( pDoc && pEditEngine && mpViewShell )
788 long nSizeX, nSizeY;
789 mpViewShell->GetViewData()->GetMergeSizePixel(
790 aCellPos.Col(), aCellPos.Row(), nSizeX, nSizeY);
792 Size aSize(nSizeX, nSizeY);
794 // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
795 long nIndent = 0;
796 const SvxHorJustifyItem* pHorJustifyItem = static_cast< const SvxHorJustifyItem* >(
797 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_HOR_JUSTIFY ) );
798 SvxCellHorJustify eHorJust = ( pHorJustifyItem ? static_cast< SvxCellHorJustify >( pHorJustifyItem->GetValue() ) : SVX_HOR_JUSTIFY_STANDARD );
799 if ( eHorJust == SVX_HOR_JUSTIFY_LEFT )
801 const SfxUInt16Item* pIndentItem = static_cast< const SfxUInt16Item* >(
802 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_INDENT ) );
803 if ( pIndentItem )
805 nIndent = static_cast< long >( pIndentItem->GetValue() );
809 const SvxMarginItem* pMarginItem = static_cast< const SvxMarginItem* >(
810 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_MARGIN ) );
811 ScViewData* pViewData = mpViewShell->GetViewData();
812 double nPPTX = ( pViewData ? pViewData->GetPPTX() : 0 );
813 double nPPTY = ( pViewData ? pViewData->GetPPTY() : 0 );
814 long nLeftM = ( pMarginItem ? static_cast< long >( ( pMarginItem->GetLeftMargin() + nIndent ) * nPPTX ) : 0 );
815 long nTopM = ( pMarginItem ? static_cast< long >( pMarginItem->GetTopMargin() * nPPTY ) : 0 );
816 long nRightM = ( pMarginItem ? static_cast< long >( pMarginItem->GetRightMargin() * nPPTX ) : 0 );
817 long nBottomM = ( pMarginItem ? static_cast< long >( pMarginItem->GetBottomMargin() * nPPTY ) : 0 );
818 long nWidth = aSize.getWidth() - nLeftM - nRightM;
819 aSize.setWidth( nWidth );
820 aSize.setHeight( aSize.getHeight() - nTopM - nBottomM );
822 Window* pWin = mpViewShell->GetWindowByPos( meSplitPos );
823 if ( pWin )
825 aSize = pWin->PixelToLogic( aSize, pEditEngine->GetRefMapMode() );
828 /* #i19430# Gnopernicus reads text partly if it sticks out of the cell
829 boundaries. This leads to wrong results in cases where the cell text
830 is rotated, because rotation is not taken into account when calcu-
831 lating the visible part of the text. In these cases we will expand
832 the cell size passed as paper size to the edit engine. The function
833 accessibility::AccessibleStaticTextBase::GetParagraphBoundingBox()
834 (see svx/source/accessibility/AccessibleStaticTextBase.cxx) will
835 return the size of the complete text then, which is used to expand
836 the cell bounding box in ScAccessibleCell::GetBoundingBox()
837 (see sc/source/ui/Accessibility/AccessibleCell.cxx). */
838 const SfxInt32Item* pItem = static_cast< const SfxInt32Item* >(
839 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_ROTATE_VALUE ) );
840 if( pItem && (pItem->GetValue() != 0) )
842 pEditEngine->SetPaperSize( Size( LONG_MAX, aSize.getHeight() ) );
843 long nTxtWidth = static_cast< long >( pEditEngine->CalcTextWidth() );
844 aSize.setWidth( std::max( aSize.getWidth(), nTxtWidth + 2 ) );
846 else
848 // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
849 const SfxBoolItem* pLineBreakItem = static_cast< const SfxBoolItem* >(
850 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_LINEBREAK ) );
851 bool bLineBreak = ( pLineBreakItem && pLineBreakItem->GetValue() );
852 if ( !bLineBreak )
854 long nTxtWidth = static_cast< long >( pEditEngine->CalcTextWidth() );
855 aSize.setWidth( ::std::max( aSize.getWidth(), nTxtWidth ) );
859 pEditEngine->SetPaperSize( aSize );
861 // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
862 if ( eHorJust == SVX_HOR_JUSTIFY_STANDARD && pDoc->HasValueData( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ) )
864 pEditEngine->SetDefaultItem( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
867 Size aTextSize;
868 if ( pWin )
870 aTextSize = pWin->LogicToPixel( Size( pEditEngine->CalcTextWidth(), pEditEngine->GetTextHeight() ), pEditEngine->GetRefMapMode() );
872 long nTextWidth = aTextSize.Width();
873 long nTextHeight = aTextSize.Height();
875 long nOffsetX = nLeftM;
876 long nDiffX = nTextWidth - nWidth;
877 if ( nDiffX > 0 )
879 switch ( eHorJust )
881 case SVX_HOR_JUSTIFY_RIGHT:
883 nOffsetX -= nDiffX;
885 break;
886 case SVX_HOR_JUSTIFY_CENTER:
888 nOffsetX -= nDiffX / 2;
890 break;
891 default:
894 break;
898 long nOffsetY = 0;
899 const SvxVerJustifyItem* pVerJustifyItem = static_cast< const SvxVerJustifyItem* >(
900 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_VER_JUSTIFY ) );
901 SvxCellVerJustify eVerJust = ( pVerJustifyItem ? static_cast< SvxCellVerJustify >( pVerJustifyItem->GetValue() ) : SVX_VER_JUSTIFY_STANDARD );
902 switch ( eVerJust )
904 case SVX_VER_JUSTIFY_STANDARD:
905 case SVX_VER_JUSTIFY_BOTTOM:
907 nOffsetY = nSizeY - nBottomM - nTextHeight;
909 break;
910 case SVX_VER_JUSTIFY_CENTER:
912 nOffsetY = ( nSizeY - nTopM - nBottomM - nTextHeight ) / 2 + nTopM;
914 break;
915 default:
917 nOffsetY = nTopM;
919 break;
922 if ( mpAccessibleCell )
924 mpAccessibleCell->SetOffset( Point( nOffsetX, nOffsetY ) );
927 pEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
930 return pForwarder;
933 SvxViewForwarder* ScAccessibleCellTextData::GetViewForwarder()
935 if (!mpViewForwarder)
936 mpViewForwarder = new ScViewForwarder(mpViewShell, meSplitPos, aCellPos);
937 return mpViewForwarder;
940 SvxEditViewForwarder* ScAccessibleCellTextData::GetEditViewForwarder( bool /* bCreate */ )
942 //#102219#; there should no EditViewForwarder be, because the cell is now readonly in this interface
943 return NULL;
946 IMPL_LINK(ScAccessibleCellTextData, NotifyHdl, EENotify*, aNotify)
948 if( aNotify )
950 SAL_WNODEPRECATED_DECLARATIONS_PUSH
951 ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify );
952 SAL_WNODEPRECATED_DECLARATIONS_POP
954 if( aHint.get() )
955 GetBroadcaster().Broadcast( *aHint.get() );
958 return 0;
961 ScDocShell* ScAccessibleCellTextData::GetDocShell(ScTabViewShell* pViewShell)
963 ScDocShell* pDocSh = NULL;
964 if (pViewShell)
965 pDocSh = pViewShell->GetViewData()->GetDocShell();
966 return pDocSh;
970 ScAccessibleEditObjectTextData::ScAccessibleEditObjectTextData(EditView* pEditView, Window* pWin, bool isClone)
972 mpViewForwarder(NULL),
973 mpEditViewForwarder(NULL),
974 mpEditView(pEditView),
975 mpEditEngine(pEditView ? pEditView->GetEditEngine() : 0),
976 mpForwarder(NULL),
977 mpWindow(pWin)
979 // If the object is cloned, do NOT add notify hdl.
980 mbIsCloned = isClone;
981 if (mpEditEngine && !mbIsCloned)
982 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
985 ScAccessibleEditObjectTextData::~ScAccessibleEditObjectTextData()
987 // If the object is cloned, do NOT set notify hdl.
988 if (mpEditEngine && !mbIsCloned)
989 mpEditEngine->SetNotifyHdl(Link());
990 if (mpViewForwarder)
991 delete mpViewForwarder;
992 if (mpEditViewForwarder)
993 delete mpEditViewForwarder;
994 if (mpForwarder)
995 delete mpForwarder;
998 void ScAccessibleEditObjectTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1000 if ( rHint.ISA( SfxSimpleHint ) )
1002 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1003 if ( nId == SFX_HINT_DYING )
1005 mpWindow = NULL;
1006 mpEditView = NULL;
1007 mpEditEngine = NULL;
1008 DELETEZ(mpForwarder);
1009 if (mpViewForwarder)
1010 mpViewForwarder->SetInvalid();
1011 if (mpEditViewForwarder)
1012 mpEditViewForwarder->SetInvalid();
1015 ScAccessibleTextData::Notify(rBC, rHint);
1018 ScAccessibleTextData* ScAccessibleEditObjectTextData::Clone() const
1020 // Add para to indicate the object is cloned
1021 return new ScAccessibleEditObjectTextData(mpEditView, mpWindow, true);
1024 SvxTextForwarder* ScAccessibleEditObjectTextData::GetTextForwarder()
1026 if ((!mpForwarder && mpEditView) || (mpEditEngine && !mpEditEngine->GetNotifyHdl().IsSet()))
1028 if (!mpEditEngine)
1029 mpEditEngine = mpEditView->GetEditEngine();
1030 // If the object is cloned, do NOT add notify hdl.
1031 if (mpEditEngine && !mpEditEngine->GetNotifyHdl().IsSet()&&!mbIsCloned)
1032 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
1033 if(!mpForwarder)
1034 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1036 return mpForwarder;
1039 SvxViewForwarder* ScAccessibleEditObjectTextData::GetViewForwarder()
1041 if (!mpViewForwarder)
1043 // i#49561 Get right-aligned cell content to be read by screenreader.
1044 mpViewForwarder = new ScEditObjectViewForwarder( mpWindow, mpEditView );
1046 return mpViewForwarder;
1049 SvxEditViewForwarder* ScAccessibleEditObjectTextData::GetEditViewForwarder( bool bCreate )
1051 if (!mpEditViewForwarder && mpEditView)
1052 mpEditViewForwarder = new ScEditViewForwarder(mpEditView, mpWindow);
1053 if (bCreate)
1055 if (!mpEditView && mpEditViewForwarder)
1057 DELETEZ(mpEditViewForwarder);
1059 else if (mpEditViewForwarder)
1060 mpEditViewForwarder->GrabFocus();
1062 return mpEditViewForwarder;
1065 IMPL_LINK(ScAccessibleEditObjectTextData, NotifyHdl, EENotify*, aNotify)
1067 if( aNotify )
1069 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1070 ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify );
1071 SAL_WNODEPRECATED_DECLARATIONS_POP
1073 if( aHint.get() )
1074 GetBroadcaster().Broadcast( *aHint.get() );
1077 return 0;
1080 ScAccessibleEditLineTextData::ScAccessibleEditLineTextData(EditView* pEditView, Window* pWin)
1082 ScAccessibleEditObjectTextData(pEditView, pWin),
1083 mbEditEngineCreated(false)
1085 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>( pWin );
1087 if (pTxtWnd)
1088 pTxtWnd->InsertAccessibleTextData( *this );
1091 ScAccessibleEditLineTextData::~ScAccessibleEditLineTextData()
1093 ScTextWnd* pTxtWnd = dynamic_cast< ScTextWnd* >(mpWindow);
1095 if (pTxtWnd)
1096 pTxtWnd->RemoveAccessibleTextData( *this );
1098 if (mbEditEngineCreated && mpEditEngine)
1100 delete mpEditEngine;
1101 mpEditEngine = NULL; // don't access in ScAccessibleEditObjectTextData dtor!
1103 else if (pTxtWnd && pTxtWnd->GetEditView() && pTxtWnd->GetEditView()->GetEditEngine())
1105 // the NotifyHdl also has to be removed from the ScTextWnd's EditEngine
1106 // (it's set in ScAccessibleEditLineTextData::GetTextForwarder, and mpEditEngine
1107 // is reset there)
1108 pTxtWnd->GetEditView()->GetEditEngine()->SetNotifyHdl(Link());
1112 void ScAccessibleEditLineTextData::Dispose()
1114 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>(mpWindow);
1116 if (pTxtWnd)
1117 pTxtWnd->RemoveAccessibleTextData( *this );
1119 ResetEditMode();
1120 mpWindow = NULL;
1123 ScAccessibleTextData* ScAccessibleEditLineTextData::Clone() const
1125 return new ScAccessibleEditLineTextData(mpEditView, mpWindow);
1128 SvxTextForwarder* ScAccessibleEditLineTextData::GetTextForwarder()
1130 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>(mpWindow);
1132 if (pTxtWnd)
1134 mpEditView = pTxtWnd->GetEditView();
1135 if (mpEditView)
1137 if (mbEditEngineCreated && mpEditEngine)
1138 ResetEditMode();
1139 mbEditEngineCreated = false;
1141 mpEditView = pTxtWnd->GetEditView();
1142 ScAccessibleEditObjectTextData::GetTextForwarder(); // fill the mpForwarder
1143 mpEditEngine = NULL;
1145 else
1147 if (mpEditEngine && !mbEditEngineCreated)
1148 ResetEditMode();
1149 if (!mpEditEngine)
1151 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1152 pEnginePool->FreezeIdRanges();
1153 mpEditEngine = new ScFieldEditEngine(NULL, pEnginePool, NULL, true);
1154 mbEditEngineCreated = true;
1155 mpEditEngine->EnableUndo( false );
1156 mpEditEngine->SetRefMapMode( MAP_100TH_MM );
1157 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1159 mpEditEngine->SetText(pTxtWnd->GetTextString());
1161 Size aSize(pTxtWnd->GetSizePixel());
1163 aSize = pTxtWnd->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1165 mpEditEngine->SetPaperSize(aSize);
1167 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
1171 return mpForwarder;
1174 SvxEditViewForwarder* ScAccessibleEditLineTextData::GetEditViewForwarder( bool bCreate )
1176 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>(mpWindow);
1178 if (pTxtWnd)
1180 mpEditView = pTxtWnd->GetEditView();
1181 if (!mpEditView && bCreate)
1183 if ( !pTxtWnd->IsInputActive() )
1185 pTxtWnd->StartEditEngine();
1186 pTxtWnd->GrabFocus();
1188 mpEditView = pTxtWnd->GetEditView();
1193 return ScAccessibleEditObjectTextData::GetEditViewForwarder(bCreate);
1196 void ScAccessibleEditLineTextData::ResetEditMode()
1198 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>(mpWindow);
1200 if (mbEditEngineCreated && mpEditEngine)
1201 delete mpEditEngine;
1202 else if (pTxtWnd && pTxtWnd->GetEditView() && pTxtWnd->GetEditView()->GetEditEngine())
1203 pTxtWnd->GetEditView()->GetEditEngine()->SetNotifyHdl(Link());
1204 mpEditEngine = NULL;
1206 DELETEZ(mpForwarder);
1207 DELETEZ(mpEditViewForwarder);
1208 DELETEZ(mpViewForwarder);
1209 mbEditEngineCreated = false;
1212 void ScAccessibleEditLineTextData::TextChanged()
1214 if (mbEditEngineCreated && mpEditEngine)
1216 ScTextWnd* pTxtWnd = dynamic_cast<ScTextWnd*>(mpWindow);
1218 if (pTxtWnd)
1219 mpEditEngine->SetText(pTxtWnd->GetTextString());
1223 void ScAccessibleEditLineTextData::StartEdit()
1225 ResetEditMode();
1226 mpEditView = NULL;
1228 // send HINT_BEGEDIT
1229 SdrHint aHint(HINT_BEGEDIT);
1230 GetBroadcaster().Broadcast( aHint );
1233 void ScAccessibleEditLineTextData::EndEdit()
1235 // send HINT_ENDEDIT
1236 SdrHint aHint(HINT_ENDEDIT);
1237 GetBroadcaster().Broadcast( aHint );
1239 ResetEditMode();
1240 mpEditView = NULL;
1244 // ScAccessiblePreviewCellTextData: shared data between sub objects of a accessible cell text object
1246 ScAccessiblePreviewCellTextData::ScAccessiblePreviewCellTextData(ScPreviewShell* pViewShell,
1247 const ScAddress& rP)
1248 : ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
1249 mpViewForwarder(NULL),
1250 mpViewShell(pViewShell)
1254 ScAccessiblePreviewCellTextData::~ScAccessiblePreviewCellTextData()
1256 if (pEditEngine)
1257 pEditEngine->SetNotifyHdl(Link());
1258 if (mpViewForwarder)
1259 delete mpViewForwarder;
1262 void ScAccessiblePreviewCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1264 if ( rHint.ISA( SfxSimpleHint ) )
1266 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1267 if ( nId == SFX_HINT_DYING )
1269 mpViewShell = NULL; // invalid now
1270 if (mpViewForwarder)
1271 mpViewForwarder->SetInvalid();
1274 ScAccessibleCellBaseTextData::Notify(rBC, rHint);
1277 ScAccessibleTextData* ScAccessiblePreviewCellTextData::Clone() const
1279 return new ScAccessiblePreviewCellTextData(mpViewShell, aCellPos);
1282 SvxTextForwarder* ScAccessiblePreviewCellTextData::GetTextForwarder()
1284 bool bEditEngineBefore(pEditEngine != NULL);
1286 ScCellTextData::GetTextForwarder(); // creates Forwarder and EditEngine
1288 if (!bEditEngineBefore && pEditEngine)
1290 Size aSize(mpViewShell->GetLocationData().GetCellOutputRect(aCellPos).GetSize());
1291 Window* pWin = mpViewShell->GetWindow();
1292 if (pWin)
1293 aSize = pWin->PixelToLogic(aSize, pEditEngine->GetRefMapMode());
1294 pEditEngine->SetPaperSize(aSize);
1297 if (pEditEngine)
1298 pEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1300 return pForwarder;
1303 SvxViewForwarder* ScAccessiblePreviewCellTextData::GetViewForwarder()
1305 if (!mpViewForwarder)
1306 mpViewForwarder = new ScPreviewCellViewForwarder(mpViewShell, aCellPos);
1307 return mpViewForwarder;
1310 ScDocShell* ScAccessiblePreviewCellTextData::GetDocShell(ScPreviewShell* pViewShell)
1312 ScDocShell* pDocSh = NULL;
1313 if (pViewShell && pViewShell->GetDocument())
1314 pDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1315 return pDocSh;
1319 // ScAccessiblePreviewHeaderCellTextData: shared data between sub objects of a accessible cell text object
1321 ScAccessiblePreviewHeaderCellTextData::ScAccessiblePreviewHeaderCellTextData(ScPreviewShell* pViewShell,
1322 const OUString& rText, const ScAddress& rP, bool bColHeader, bool bRowHeader)
1323 : ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
1324 mpViewForwarder(NULL),
1325 mpViewShell(pViewShell),
1326 maText(rText),
1327 mbColHeader(bColHeader),
1328 mbRowHeader(bRowHeader)
1332 ScAccessiblePreviewHeaderCellTextData::~ScAccessiblePreviewHeaderCellTextData()
1334 if (pEditEngine)
1335 pEditEngine->SetNotifyHdl(Link());
1336 if (mpViewForwarder)
1337 delete mpViewForwarder;
1340 void ScAccessiblePreviewHeaderCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1342 if ( rHint.ISA( SfxSimpleHint ) )
1344 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1345 if ( nId == SFX_HINT_DYING )
1347 mpViewShell = NULL; // invalid now
1348 if (mpViewForwarder)
1349 mpViewForwarder->SetInvalid();
1352 ScAccessibleCellBaseTextData::Notify(rBC, rHint);
1355 ScAccessibleTextData* ScAccessiblePreviewHeaderCellTextData::Clone() const
1357 return new ScAccessiblePreviewHeaderCellTextData(mpViewShell, maText, aCellPos, mbColHeader, mbRowHeader);
1360 SvxTextForwarder* ScAccessiblePreviewHeaderCellTextData::GetTextForwarder()
1362 if (!pEditEngine)
1364 if ( pDocShell )
1366 ScDocument* pDoc = pDocShell->GetDocument();
1367 pEditEngine = pDoc->CreateFieldEditEngine();
1369 else
1371 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1372 pEnginePool->FreezeIdRanges();
1373 pEditEngine = new ScFieldEditEngine(NULL, pEnginePool, NULL, true);
1375 pEditEngine->EnableUndo( false );
1376 if (pDocShell)
1377 pEditEngine->SetRefDevice(pDocShell->GetRefDevice());
1378 else
1379 pEditEngine->SetRefMapMode( MAP_100TH_MM );
1380 pForwarder = new SvxEditEngineForwarder(*pEditEngine);
1383 if (bDataValid)
1384 return pForwarder;
1386 if (!maText.isEmpty())
1388 if ( mpViewShell )
1390 Size aOutputSize;
1391 Window* pWindow = mpViewShell->GetWindow();
1392 if ( pWindow )
1393 aOutputSize = pWindow->GetOutputSizePixel();
1394 Point aPoint;
1395 Rectangle aVisRect( aPoint, aOutputSize );
1396 Size aSize(mpViewShell->GetLocationData().GetHeaderCellOutputRect(aVisRect, aCellPos, mbColHeader).GetSize());
1397 if (pWindow)
1398 aSize = pWindow->PixelToLogic(aSize, pEditEngine->GetRefMapMode());
1399 pEditEngine->SetPaperSize(aSize);
1401 pEditEngine->SetText( maText );
1404 bDataValid = true;
1406 pEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1408 return pForwarder;
1411 SvxViewForwarder* ScAccessiblePreviewHeaderCellTextData::GetViewForwarder()
1413 if (!mpViewForwarder)
1414 mpViewForwarder = new ScPreviewHeaderCellViewForwarder(mpViewShell, aCellPos, mbColHeader);
1415 return mpViewForwarder;
1418 ScDocShell* ScAccessiblePreviewHeaderCellTextData::GetDocShell(ScPreviewShell* pViewShell)
1420 ScDocShell* pDocSh = NULL;
1421 if (pViewShell && pViewShell->GetDocument())
1422 pDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1423 return pDocSh;
1426 ScAccessibleHeaderTextData::ScAccessibleHeaderTextData(ScPreviewShell* pViewShell,
1427 const EditTextObject* pEditObj, bool bHeader, SvxAdjust eAdjust)
1429 mpViewForwarder(NULL),
1430 mpViewShell(pViewShell),
1431 mpEditEngine(NULL),
1432 mpForwarder(NULL),
1433 mpDocSh(NULL),
1434 mpEditObj(pEditObj),
1435 mbHeader(bHeader),
1436 mbDataValid(false),
1437 meAdjust(eAdjust)
1439 if (pViewShell && pViewShell->GetDocument())
1440 mpDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1441 if (mpDocSh)
1442 mpDocSh->GetDocument()->AddUnoObject(*this);
1445 ScAccessibleHeaderTextData::~ScAccessibleHeaderTextData()
1447 SolarMutexGuard aGuard; // needed for EditEngine dtor
1449 if (mpDocSh)
1450 mpDocSh->GetDocument()->RemoveUnoObject(*this);
1451 if (mpEditEngine)
1452 mpEditEngine->SetNotifyHdl(Link());
1453 delete mpEditEngine;
1454 delete mpForwarder;
1457 ScAccessibleTextData* ScAccessibleHeaderTextData::Clone() const
1459 return new ScAccessibleHeaderTextData(mpViewShell, mpEditObj, mbHeader, meAdjust);
1462 void ScAccessibleHeaderTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
1464 if ( rHint.ISA( SfxSimpleHint ) )
1466 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1467 if ( nId == SFX_HINT_DYING )
1469 mpViewShell = NULL;// invalid now
1470 mpDocSh = NULL;
1471 if (mpViewForwarder)
1472 mpViewForwarder->SetInvalid();
1477 SvxTextForwarder* ScAccessibleHeaderTextData::GetTextForwarder()
1479 if (!mpEditEngine)
1481 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1482 pEnginePool->FreezeIdRanges();
1483 ScHeaderEditEngine* pHdrEngine = new ScHeaderEditEngine( pEnginePool, true );
1485 pHdrEngine->EnableUndo( false );
1486 pHdrEngine->SetRefMapMode( MAP_TWIP );
1488 // default font must be set, independently of document
1489 // -> use global pool from module
1491 SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() );
1492 const ScPatternAttr& rPattern = (const ScPatternAttr&)SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN);
1493 rPattern.FillEditItemSet( &aDefaults );
1494 // FillEditItemSet adjusts font height to 1/100th mm,
1495 // but for header/footer twips is needed, as in the PatternAttr:
1496 aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT );
1497 aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK );
1498 aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL );
1499 aDefaults.Put( SvxAdjustItem( meAdjust, EE_PARA_JUST ) );
1500 pHdrEngine->SetDefaults( aDefaults );
1502 ScHeaderFieldData aData;
1503 if (mpViewShell)
1504 mpViewShell->FillFieldData(aData);
1505 else
1506 ScHeaderFooterTextObj::FillDummyFieldData( aData );
1507 pHdrEngine->SetData( aData );
1509 mpEditEngine = pHdrEngine;
1510 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1513 if (mbDataValid)
1514 return mpForwarder;
1516 if ( mpViewShell )
1518 Rectangle aVisRect;
1519 mpViewShell->GetLocationData().GetHeaderPosition(aVisRect);
1520 Size aSize(aVisRect.GetSize());
1521 Window* pWin = mpViewShell->GetWindow();
1522 if (pWin)
1523 aSize = pWin->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1524 mpEditEngine->SetPaperSize(aSize);
1526 if (mpEditObj)
1527 mpEditEngine->SetText(*mpEditObj);
1529 mbDataValid = true;
1530 return mpForwarder;
1533 SvxViewForwarder* ScAccessibleHeaderTextData::GetViewForwarder()
1535 if (!mpViewForwarder)
1536 mpViewForwarder = new ScPreviewHeaderFooterViewForwarder(mpViewShell, mbHeader);
1537 return mpViewForwarder;
1540 ScAccessibleNoteTextData::ScAccessibleNoteTextData(ScPreviewShell* pViewShell,
1541 const OUString& sText, const ScAddress& aCellPos, bool bMarkNote)
1543 mpViewForwarder(NULL),
1544 mpViewShell(pViewShell),
1545 mpEditEngine(NULL),
1546 mpForwarder(NULL),
1547 mpDocSh(NULL),
1548 msText(sText),
1549 maCellPos(aCellPos),
1550 mbMarkNote(bMarkNote),
1551 mbDataValid(false)
1553 if (pViewShell && pViewShell->GetDocument())
1554 mpDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1555 if (mpDocSh)
1556 mpDocSh->GetDocument()->AddUnoObject(*this);
1559 ScAccessibleNoteTextData::~ScAccessibleNoteTextData()
1561 SolarMutexGuard aGuard; // needed for EditEngine dtor
1563 if (mpDocSh)
1564 mpDocSh->GetDocument()->RemoveUnoObject(*this);
1565 if (mpEditEngine)
1566 mpEditEngine->SetNotifyHdl(Link());
1567 delete mpEditEngine;
1568 delete mpForwarder;
1571 ScAccessibleTextData* ScAccessibleNoteTextData::Clone() const
1573 return new ScAccessibleNoteTextData(mpViewShell, msText, maCellPos, mbMarkNote);
1576 void ScAccessibleNoteTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
1578 if ( rHint.ISA( SfxSimpleHint ) )
1580 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1581 if ( nId == SFX_HINT_DYING )
1583 mpViewShell = NULL;// invalid now
1584 mpDocSh = NULL;
1585 if (mpViewForwarder)
1586 mpViewForwarder->SetInvalid();
1591 SvxTextForwarder* ScAccessibleNoteTextData::GetTextForwarder()
1593 if (!mpEditEngine)
1595 if ( mpDocSh )
1597 ScDocument* pDoc = mpDocSh->GetDocument();
1598 mpEditEngine = pDoc->CreateFieldEditEngine();
1600 else
1602 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1603 pEnginePool->FreezeIdRanges();
1604 mpEditEngine = new ScFieldEditEngine(NULL, pEnginePool, NULL, true);
1606 mpEditEngine->EnableUndo( false );
1607 if (mpDocSh)
1608 mpEditEngine->SetRefDevice(mpDocSh->GetRefDevice());
1609 else
1610 mpEditEngine->SetRefMapMode( MAP_100TH_MM );
1611 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1614 if (mbDataValid)
1615 return mpForwarder;
1617 if (!msText.isEmpty())
1620 if ( mpViewShell )
1622 Size aOutputSize;
1623 Window* pWindow = mpViewShell->GetWindow();
1624 if ( pWindow )
1625 aOutputSize = pWindow->GetOutputSizePixel();
1626 Point aPoint;
1627 Rectangle aVisRect( aPoint, aOutputSize );
1628 Size aSize(mpViewShell->GetLocationData().GetNoteInRangeOutputRect(aVisRect, mbMarkNote, maCellPos).GetSize());
1629 if (pWindow)
1630 aSize = pWindow->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1631 mpEditEngine->SetPaperSize(aSize);
1633 mpEditEngine->SetText( msText );
1636 mbDataValid = true;
1638 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1640 return mpForwarder;
1643 SvxViewForwarder* ScAccessibleNoteTextData::GetViewForwarder()
1645 if (!mpViewForwarder)
1646 mpViewForwarder = new ScPreviewNoteViewForwarder(mpViewShell, maCellPos, mbMarkNote);
1647 return mpViewForwarder;
1651 // CSV import =================================================================
1653 class ScCsvViewForwarder : public SvxViewForwarder
1655 Rectangle maBoundBox;
1656 Window* mpWindow;
1658 public:
1659 explicit ScCsvViewForwarder( Window* pWindow, const Rectangle& rBoundBox );
1661 virtual bool IsValid() const SAL_OVERRIDE;
1662 virtual Rectangle GetVisArea() const SAL_OVERRIDE;
1663 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
1664 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const SAL_OVERRIDE;
1666 void SetInvalid();
1669 ScCsvViewForwarder::ScCsvViewForwarder( Window* pWindow, const Rectangle& rBoundBox ) :
1670 maBoundBox( rBoundBox ),
1671 mpWindow( pWindow )
1675 bool ScCsvViewForwarder::IsValid() const
1677 return mpWindow != NULL;
1680 Rectangle ScCsvViewForwarder::GetVisArea() const
1682 return maBoundBox;
1685 Point ScCsvViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
1687 if( !mpWindow ) return Point();
1688 return mpWindow->LogicToPixel( rPoint, rMapMode );
1691 Point ScCsvViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
1693 if( !mpWindow ) return Point();
1694 return mpWindow->PixelToLogic( rPoint, rMapMode );
1697 void ScCsvViewForwarder::SetInvalid()
1699 mpWindow = NULL;
1702 ScAccessibleCsvTextData::ScAccessibleCsvTextData(
1703 Window* pWindow, EditEngine* pEditEngine,
1704 const OUString& rCellText, const Rectangle& rBoundBox, const Size& rCellSize ) :
1705 mpWindow( pWindow ),
1706 mpEditEngine( pEditEngine ),
1707 maCellText( rCellText ),
1708 maBoundBox( rBoundBox ),
1709 maCellSize( rCellSize )
1713 ScAccessibleCsvTextData::~ScAccessibleCsvTextData()
1717 void ScAccessibleCsvTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1719 if ( rHint.ISA( SfxSimpleHint ) )
1721 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1722 if( nId == SFX_HINT_DYING )
1724 mpWindow = NULL;
1725 mpEditEngine = NULL;
1726 if (mpViewForwarder.get())
1727 mpViewForwarder->SetInvalid();
1730 ScAccessibleTextData::Notify( rBC, rHint );
1733 ScAccessibleTextData* ScAccessibleCsvTextData::Clone() const
1735 return new ScAccessibleCsvTextData( mpWindow, mpEditEngine, maCellText, maBoundBox, maCellSize );
1738 SvxTextForwarder* ScAccessibleCsvTextData::GetTextForwarder()
1740 if( mpEditEngine )
1742 mpEditEngine->SetPaperSize( maCellSize );
1743 mpEditEngine->SetText( maCellText );
1744 if( !mpTextForwarder.get() )
1745 mpTextForwarder.reset( new SvxEditEngineForwarder( *mpEditEngine ) );
1747 else
1748 mpTextForwarder.reset();
1749 return mpTextForwarder.get();
1752 SvxViewForwarder* ScAccessibleCsvTextData::GetViewForwarder()
1754 if( !mpViewForwarder.get() )
1755 mpViewForwarder.reset( new ScCsvViewForwarder( mpWindow, maBoundBox ) );
1756 return mpViewForwarder.get();
1759 SvxEditViewForwarder* ScAccessibleCsvTextData::GetEditViewForwarder( bool /* bCreate */ )
1761 return NULL;
1764 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */