Update ooo320-m1
[ooovba.git] / sc / source / ui / Accessibility / AccessibleText.cxx
blob864168d57ce4c2b8bf1153bbe7066e5041565f0b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleText.cxx,v $
10 * $Revision: 1.42.32.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "scitems.hxx"
35 #include <svx/eeitem.hxx>
38 #include <memory>
39 #include "AccessibleText.hxx"
40 #include "AccessibleCell.hxx"
41 #include "tabvwsh.hxx"
42 #include "editutil.hxx"
43 #include "document.hxx"
44 #include "scmod.hxx"
45 #include "prevwsh.hxx"
46 #include "docsh.hxx"
47 #include "prevloc.hxx"
48 #include "unoguard.hxx"
49 #include "patattr.hxx"
50 #include "inputwin.hxx"
51 #include <svx/unofored.hxx>
52 #include <svx/editview.hxx>
53 #include <svx/unoedhlp.hxx>
54 #include <vcl/virdev.hxx>
55 #include <svx/editobj.hxx>
56 #include <svx/adjitem.hxx>
57 #include <svx/svdmodel.hxx>
58 #include <svx/algitem.hxx>
61 // ============================================================================
63 class ScViewForwarder : public SvxViewForwarder
65 ScTabViewShell* mpViewShell;
66 ScAddress maCellPos;
67 ScSplitPos meSplitPos;
68 public:
69 ScViewForwarder(ScTabViewShell* pViewShell, ScSplitPos eSplitPos, const ScAddress& rCell);
70 virtual ~ScViewForwarder();
72 virtual BOOL IsValid() const;
73 virtual Rectangle GetVisArea() const;
74 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const;
75 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const;
77 void SetInvalid();
80 ScViewForwarder::ScViewForwarder(ScTabViewShell* pViewShell, ScSplitPos eSplitPos, const ScAddress& rCell)
82 mpViewShell(pViewShell),
83 maCellPos(rCell),
84 meSplitPos(eSplitPos)
88 ScViewForwarder::~ScViewForwarder()
92 BOOL ScViewForwarder::IsValid() const
94 return mpViewShell != NULL;
97 Rectangle ScViewForwarder::GetVisArea() const
99 Rectangle aVisArea;
100 if (mpViewShell)
102 Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
103 if (pWindow)
105 aVisArea.SetSize(pWindow->GetSizePixel());
107 ScHSplitPos eWhichH = ((meSplitPos == SC_SPLIT_TOPLEFT) || (meSplitPos == SC_SPLIT_BOTTOMLEFT)) ?
108 SC_SPLIT_LEFT : SC_SPLIT_RIGHT;
109 ScVSplitPos eWhichV = ((meSplitPos == SC_SPLIT_TOPLEFT) || (meSplitPos == SC_SPLIT_TOPRIGHT)) ?
110 SC_SPLIT_TOP : SC_SPLIT_BOTTOM;
112 Point aBaseCellPos(mpViewShell->GetViewData()->GetScrPos(mpViewShell->GetViewData()->GetPosX(eWhichH),
113 mpViewShell->GetViewData()->GetPosY(eWhichV), meSplitPos, sal_True));
114 Point aCellPos(mpViewShell->GetViewData()->GetScrPos(maCellPos.Col(), maCellPos.Row(), meSplitPos, sal_True));
115 aVisArea.SetPos(aCellPos - aBaseCellPos);
118 else
120 DBG_ERROR("this ViewForwarder is not valid");
122 return aVisArea;
125 Point ScViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
127 if (mpViewShell)
129 Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
130 if (pWindow)
131 return pWindow->LogicToPixel( rPoint, rMapMode );
133 else
135 DBG_ERROR("this ViewForwarder is not valid");
137 return Point();
140 Point ScViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
142 if (mpViewShell)
144 Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
145 if (pWindow)
146 return pWindow->PixelToLogic( rPoint, rMapMode );
148 else
150 DBG_ERROR("this ViewForwarder is not valid");
152 return Point();
155 void ScViewForwarder::SetInvalid()
157 mpViewShell = NULL;
160 // ============================================================================
162 class ScEditObjectViewForwarder : public SvxViewForwarder
164 Window* mpWindow;
165 // --> OD 2005-12-21 #i49561#
166 // - EditView needed for access to its visible area.
167 const EditView* mpEditView;
168 // <--
169 public:
170 // --> OD 2005-12-21 #i49561#
171 ScEditObjectViewForwarder( Window* pWindow,
172 const EditView* _pEditView);
173 // <--
174 virtual ~ScEditObjectViewForwarder();
176 virtual BOOL IsValid() const;
177 virtual Rectangle GetVisArea() const;
178 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const;
179 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const;
181 void SetInvalid();
184 // --> OD 2005-12-21 #i49561#
185 ScEditObjectViewForwarder::ScEditObjectViewForwarder( Window* pWindow,
186 const EditView* _pEditView )
188 mpWindow(pWindow),
189 mpEditView( _pEditView )
192 // <--
194 ScEditObjectViewForwarder::~ScEditObjectViewForwarder()
198 BOOL ScEditObjectViewForwarder::IsValid() const
200 return (mpWindow != NULL);
203 Rectangle ScEditObjectViewForwarder::GetVisArea() const
205 Rectangle aVisArea;
206 if (mpWindow)
208 Rectangle aVisRect(mpWindow->GetWindowExtentsRelative(mpWindow->GetAccessibleParentWindow()));
210 aVisRect.SetPos(Point(0, 0));
212 aVisArea = aVisRect;
214 else
216 DBG_ERROR("this ViewForwarder is not valid");
218 return aVisArea;
221 Point ScEditObjectViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
223 if (mpWindow)
225 // --> OD 2005-12-21 #i49561# - consider offset of the visible area
226 // of the EditView before converting point to pixel.
227 Point aPoint( rPoint );
228 if ( mpEditView )
230 Rectangle aEditViewVisArea( mpEditView->GetVisArea() );
231 aPoint += aEditViewVisArea.TopLeft();
233 return mpWindow->LogicToPixel( aPoint, rMapMode );
234 // <--
236 else
238 DBG_ERROR("this ViewForwarder is not valid");
240 return Point();
243 Point ScEditObjectViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
245 if (mpWindow)
247 // --> OD 2005-12-21 #i49561# - consider offset of the visible area
248 // of the EditView after converting point to logic.
249 Point aPoint( mpWindow->PixelToLogic( rPoint, rMapMode ) );
250 if ( mpEditView )
252 Rectangle aEditViewVisArea( mpEditView->GetVisArea() );
253 aPoint -= aEditViewVisArea.TopLeft();
255 return aPoint;
256 // <--
258 else
260 DBG_ERROR("this ViewForwarder is not valid");
262 return Point();
265 void ScEditObjectViewForwarder::SetInvalid()
267 mpWindow = NULL;
270 // ============================================================================
272 class ScPreviewViewForwarder : public SvxViewForwarder
274 protected:
275 ScPreviewShell* mpViewShell;
276 mutable ScPreviewTableInfo* mpTableInfo;
277 public:
278 ScPreviewViewForwarder(ScPreviewShell* pViewShell);
279 virtual ~ScPreviewViewForwarder();
281 virtual BOOL IsValid() const;
282 virtual Rectangle GetVisArea() const;
283 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const;
284 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const;
286 void SetInvalid();
288 Rectangle GetVisRect() const;
290 // clips the VisArea and calculates with the negativ coordinates
291 Rectangle CorrectVisArea(const Rectangle& rVisArea) const;
294 ScPreviewViewForwarder::ScPreviewViewForwarder(ScPreviewShell* pViewShell)
296 mpViewShell(pViewShell),
297 mpTableInfo(NULL)
301 ScPreviewViewForwarder::~ScPreviewViewForwarder()
303 delete mpTableInfo;
306 BOOL ScPreviewViewForwarder::IsValid() const
308 return mpViewShell != NULL;
311 Rectangle ScPreviewViewForwarder::GetVisArea() const
313 Rectangle aVisArea;
314 DBG_ERROR("should be implemented in an abrevated class");
315 return aVisArea;
318 Point ScPreviewViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
320 if (mpViewShell)
322 Window* pWindow = mpViewShell->GetWindow();
323 if (pWindow)
325 MapMode aMapMode(pWindow->GetMapMode().GetMapUnit());
326 Point aPoint2( OutputDevice::LogicToLogic( rPoint, rMapMode, aMapMode) );
327 return pWindow->LogicToPixel(aPoint2);
330 else
332 DBG_ERROR("this ViewForwarder is not valid");
334 return Point();
337 Point ScPreviewViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
339 if (mpViewShell)
341 Window* pWindow = mpViewShell->GetWindow();
342 if (pWindow)
344 MapMode aMapMode(pWindow->GetMapMode());
345 aMapMode.SetOrigin(Point());
346 Point aPoint1( pWindow->PixelToLogic( rPoint ) );
347 Point aPoint2( OutputDevice::LogicToLogic( aPoint1,
348 aMapMode.GetMapUnit(),
349 rMapMode ) );
350 return aPoint2;
353 else
355 DBG_ERROR("this ViewForwarder is not valid");
357 return Point();
360 void ScPreviewViewForwarder::SetInvalid()
362 mpViewShell = NULL;
365 Rectangle ScPreviewViewForwarder::GetVisRect() const
367 if ( mpViewShell )
369 Size aOutputSize;
370 Window* pWindow = mpViewShell->GetWindow();
371 if ( pWindow )
372 aOutputSize = pWindow->GetOutputSizePixel();
373 Point aPoint;
374 Rectangle aVisRect( aPoint, aOutputSize );
375 return aVisRect;
377 return Rectangle();
380 Rectangle ScPreviewViewForwarder::CorrectVisArea(const Rectangle& rVisArea) const
382 Rectangle aVisArea(rVisArea);
383 Point aPos = aVisArea.TopLeft(); // get first the position to remember negative positions after clipping
385 Window* pWin = mpViewShell->GetWindow();
386 if (pWin)
387 aVisArea = pWin->GetWindowExtentsRelative(pWin).GetIntersection(aVisArea);
389 sal_Int32 nX(aPos.getX());
390 sal_Int32 nY(aPos.getY());
392 if (nX > 0)
393 nX = 0;
394 else if (nX < 0)
395 nX = -nX;
396 if (nY > 0)
397 nY = 0;
398 else if (nY < 0)
399 nY = -nY;
400 aVisArea.SetPos(Point(nX, nY));
402 return aVisArea;
405 // ============================================================================
407 class ScPreviewHeaderFooterViewForwarder : public ScPreviewViewForwarder
409 sal_Bool mbHeader;
410 public:
411 ScPreviewHeaderFooterViewForwarder(ScPreviewShell* pViewShell, sal_Bool bHeader);
412 virtual ~ScPreviewHeaderFooterViewForwarder();
414 virtual Rectangle GetVisArea() const;
417 ScPreviewHeaderFooterViewForwarder::ScPreviewHeaderFooterViewForwarder(ScPreviewShell* pViewShell, sal_Bool bHeader)
419 ScPreviewViewForwarder(pViewShell),
420 mbHeader(bHeader)
424 ScPreviewHeaderFooterViewForwarder::~ScPreviewHeaderFooterViewForwarder()
428 Rectangle ScPreviewHeaderFooterViewForwarder::GetVisArea() const
430 Rectangle aVisArea;
431 if (mpViewShell)
433 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
434 if ( mbHeader )
435 rData.GetHeaderPosition( aVisArea );
436 else
437 rData.GetFooterPosition( aVisArea );
439 aVisArea = CorrectVisArea(aVisArea);
441 else
443 DBG_ERROR("this ViewForwarder is not valid");
445 return aVisArea;
448 // ============================================================================
450 class ScPreviewCellViewForwarder : public ScPreviewViewForwarder
452 ScAddress maCellPos;
453 public:
454 ScPreviewCellViewForwarder(ScPreviewShell* pViewShell,
455 ScAddress aCellPos);
456 virtual ~ScPreviewCellViewForwarder();
458 virtual Rectangle GetVisArea() const;
461 ScPreviewCellViewForwarder::ScPreviewCellViewForwarder(ScPreviewShell* pViewShell,
462 ScAddress aCellPos)
464 ScPreviewViewForwarder(pViewShell),
465 maCellPos(aCellPos)
469 ScPreviewCellViewForwarder::~ScPreviewCellViewForwarder()
473 Rectangle ScPreviewCellViewForwarder::GetVisArea() const
475 Rectangle aVisArea;
476 if (mpViewShell)
478 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
479 aVisArea = rData.GetCellOutputRect(maCellPos);
481 aVisArea = CorrectVisArea(aVisArea);
483 else
485 DBG_ERROR("this ViewForwarder is not valid");
487 return aVisArea;
490 // ============================================================================
492 class ScPreviewHeaderCellViewForwarder : public ScPreviewViewForwarder
494 ScAddress maCellPos;
495 sal_Bool mbColHeader;
496 sal_Bool mbRowHeader;
497 public:
498 ScPreviewHeaderCellViewForwarder(ScPreviewShell* pViewShell,
499 ScAddress aCellPos,
500 sal_Bool bColHeader, sal_Bool bRowHeader);
501 virtual ~ScPreviewHeaderCellViewForwarder();
503 virtual Rectangle GetVisArea() const;
506 ScPreviewHeaderCellViewForwarder::ScPreviewHeaderCellViewForwarder(ScPreviewShell* pViewShell,
507 ScAddress aCellPos,
508 sal_Bool bColHeader, sal_Bool bRowHeader)
510 ScPreviewViewForwarder(pViewShell),
511 maCellPos(aCellPos),
512 mbColHeader(bColHeader),
513 mbRowHeader(bRowHeader)
517 ScPreviewHeaderCellViewForwarder::~ScPreviewHeaderCellViewForwarder()
521 Rectangle ScPreviewHeaderCellViewForwarder::GetVisArea() const
523 Rectangle aVisArea;
524 if (mpViewShell)
526 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
527 aVisArea = rData.GetHeaderCellOutputRect(GetVisRect(), maCellPos, mbColHeader);
529 aVisArea = CorrectVisArea(aVisArea);
531 else
533 DBG_ERROR("this ViewForwarder is not valid");
535 return aVisArea;
538 // ============================================================================
540 class ScPreviewNoteViewForwarder : public ScPreviewViewForwarder
542 ScAddress maCellPos;
543 sal_Bool mbNoteMark;
544 public:
545 ScPreviewNoteViewForwarder(ScPreviewShell* pViewShell,
546 ScAddress aCellPos,
547 sal_Bool bNoteMark);
548 virtual ~ScPreviewNoteViewForwarder();
550 virtual Rectangle GetVisArea() const;
553 ScPreviewNoteViewForwarder::ScPreviewNoteViewForwarder(ScPreviewShell* pViewShell,
554 ScAddress aCellPos,
555 sal_Bool bNoteMark)
557 ScPreviewViewForwarder(pViewShell),
558 maCellPos(aCellPos),
559 mbNoteMark(bNoteMark)
563 ScPreviewNoteViewForwarder::~ScPreviewNoteViewForwarder()
567 Rectangle ScPreviewNoteViewForwarder::GetVisArea() const
569 Rectangle aVisArea;
570 if (mpViewShell)
572 const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
573 aVisArea = rData.GetNoteInRangeOutputRect(GetVisRect(), mbNoteMark, maCellPos);
575 aVisArea = CorrectVisArea(aVisArea);
577 else
579 DBG_ERROR("this ViewForwarder is not valid");
581 return aVisArea;
584 // ============================================================================
586 class ScEditViewForwarder : public SvxEditViewForwarder
588 EditView* mpEditView;
589 Window* mpWindow;
590 public:
591 ScEditViewForwarder(EditView* pEditView, Window* pWin);
592 virtual ~ScEditViewForwarder();
594 virtual BOOL IsValid() const;
595 virtual Rectangle GetVisArea() const;
596 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const;
597 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const;
598 virtual sal_Bool GetSelection( ESelection& rSelection ) const;
599 virtual sal_Bool SetSelection( const ESelection& rSelection );
600 virtual sal_Bool Copy();
601 virtual sal_Bool Cut();
602 virtual sal_Bool Paste();
604 void GrabFocus();
606 void SetInvalid();
609 ScEditViewForwarder::ScEditViewForwarder(EditView* pEditView, Window* pWin)
610 : mpEditView(pEditView),
611 mpWindow(pWin)
613 GrabFocus();
616 ScEditViewForwarder::~ScEditViewForwarder()
620 BOOL ScEditViewForwarder::IsValid() const
622 sal_Bool bResult(sal_False);
623 if (mpWindow && mpEditView)
625 bResult = sal_True;
627 return bResult;
630 Rectangle ScEditViewForwarder::GetVisArea() const
632 Rectangle aVisArea;
633 if (IsValid() && mpEditView->GetEditEngine())
635 MapMode aMapMode(mpEditView->GetEditEngine()->GetRefMapMode());
637 aVisArea = mpWindow->LogicToPixel( mpEditView->GetVisArea(), aMapMode );
639 else
641 DBG_ERROR("this EditViewForwarder is no longer valid");
643 return aVisArea;
646 Point ScEditViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
648 if (mpWindow)
649 return mpWindow->LogicToPixel( rPoint, rMapMode );
650 else
652 DBG_ERROR("this ViewForwarder is not valid");
654 return Point();
657 Point ScEditViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
659 if (mpWindow)
660 return mpWindow->PixelToLogic( rPoint, rMapMode );
661 else
663 DBG_ERROR("this ViewForwarder is not valid");
665 return Point();
668 sal_Bool ScEditViewForwarder::GetSelection( ESelection& rSelection ) const
670 sal_Bool bResult(sal_False);
671 if (IsValid())
673 rSelection = mpEditView->GetSelection();
674 bResult = sal_True;
676 else
678 DBG_ERROR("this ViewForwarder is not valid");
680 return bResult;
683 sal_Bool ScEditViewForwarder::SetSelection( const ESelection& rSelection )
685 sal_Bool bResult(sal_False);
686 if (IsValid())
688 mpEditView->SetSelection(rSelection);
689 bResult = sal_True;
691 else
693 DBG_ERROR("this ViewForwarder is not valid");
695 return bResult;
698 sal_Bool ScEditViewForwarder::Copy()
700 sal_Bool bResult(sal_False);
701 if (IsValid())
703 mpEditView->Copy();
704 bResult = sal_True;
706 else
708 DBG_ERROR("this ViewForwarder is not valid");
710 return bResult;
713 sal_Bool ScEditViewForwarder::Cut()
715 sal_Bool bResult(sal_False);
716 if (IsValid())
718 mpEditView->Cut();
719 bResult = sal_True;
721 else
723 DBG_ERROR("this ViewForwarder is not valid");
725 return bResult;
728 sal_Bool ScEditViewForwarder::Paste()
730 sal_Bool bResult(sal_False);
731 if (IsValid())
733 mpEditView->Paste();
734 bResult = sal_True;
736 else
738 DBG_ERROR("this ViewForwarder is not valid");
740 return bResult;
743 void ScEditViewForwarder::GrabFocus()
747 void ScEditViewForwarder::SetInvalid()
749 mpWindow = NULL;
750 mpEditView = NULL;
753 // ============================================================================
755 // ScAccessibleCellTextData: shared data between sub objects of a accessible cell text object
757 ScAccessibleCellTextData::ScAccessibleCellTextData(ScTabViewShell* pViewShell,
758 const ScAddress& rP, ScSplitPos eSplitPos, ScAccessibleCell* pAccCell)
759 : ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
760 mpViewForwarder(NULL),
761 mpEditViewForwarder(NULL),
762 mpViewShell(pViewShell),
763 meSplitPos(eSplitPos),
764 mbViewEditEngine(sal_False),
765 mpAccessibleCell( pAccCell )
769 ScAccessibleCellTextData::~ScAccessibleCellTextData()
771 if (pEditEngine)
772 pEditEngine->SetNotifyHdl(Link());
773 if (mpViewForwarder)
774 delete mpViewForwarder;
775 if (mpEditViewForwarder)
776 delete mpEditViewForwarder;
779 void ScAccessibleCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
781 if ( rHint.ISA( SfxSimpleHint ) )
783 ULONG nId = ((const SfxSimpleHint&)rHint).GetId();
784 if ( nId == SFX_HINT_DYING )
786 mpViewShell = NULL; // invalid now
787 if (mpViewForwarder)
788 mpViewForwarder->SetInvalid();
789 if (mpEditViewForwarder)
790 mpEditViewForwarder->SetInvalid();
793 ScAccessibleCellBaseTextData::Notify(rBC, rHint);
796 ScAccessibleTextData* ScAccessibleCellTextData::Clone() const
798 return new ScAccessibleCellTextData( mpViewShell, aCellPos, meSplitPos, mpAccessibleCell );
801 void ScAccessibleCellTextData::GetCellText(const ScAddress& rCellPos, String& rText)
803 // #104893#; don't use the input string
804 // ScCellTextData::GetCellText(rCellPos, rText);
805 ScDocument* pDoc = pDocShell->GetDocument();
806 if (pDoc)
808 // #104893#; use the displayed string
809 pDoc->GetString(rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), rText);
810 if (mpViewShell)
812 const ScViewOptions& aOptions = mpViewShell->GetViewData()->GetOptions();
813 CellType aCellType;
814 pDoc->GetCellType(rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), aCellType);
815 if (aCellType == CELLTYPE_FORMULA && aOptions.GetOption( VOPT_FORMULAS ))
817 pDoc->GetFormula( rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), rText);
819 else if (!aOptions.GetOption( VOPT_NULLVALS ))
821 if ((aCellType == CELLTYPE_VALUE || aCellType == CELLTYPE_FORMULA) && pDoc->GetValue(rCellPos) == 0.0)
822 rText.Erase();
828 SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
830 /* sal_Bool bHasForwarder(sal_False);
831 if (mpViewShell && mpViewShell->GetViewData() &&
832 (mpViewShell->GetViewData()->GetCurPos() == aCellPos) &&
833 (mpViewShell->GetViewData()->HasEditView(meSplitPos)) &&
834 (mpViewShell->GetViewData()->GetEditViewCol() == aCellPos.Col()) &&
835 (mpViewShell->GetViewData()->GetEditViewRow() == aCellPos.Row()))
837 if (!mbViewEditEngine)
839 if (pForwarder)
840 DELETEZ( pForwarder );
841 if (pEditEngine)
842 DELETEZ( pEditEngine );
844 SCCOL nCol;
845 SCROW nRow;
846 EditView* pEditView;
847 mpViewShell->GetViewData()->GetEditView( meSplitPos, pEditView, nCol, nRow );
848 if (pEditView)
850 pEditEngine = (ScFieldEditEngine*)pEditView->GetEditEngine();
851 pForwarder = new SvxEditEngineForwarder(*pEditEngine);
852 bHasForwarder = sal_True;
855 else
856 bHasForwarder = sal_True;
858 else if (mbViewEditEngine)
860 // remove Forwarder created with EditEngine from EditView
861 if (pForwarder)
862 DELETEZ( pForwarder );
863 pEditEngine->SetNotifyHdl(Link());
864 // don't delete, because it is the EditEngine of the EditView
865 pEditEngine = NULL;
866 mbViewEditEngine = sal_False;
869 if (!bHasForwarder)*/
870 ScCellTextData::GetTextForwarder(); // creates Forwarder and EditEngine
872 ScDocument* pDoc = ( pDocShell ? pDocShell->GetDocument() : NULL );
873 if ( pDoc && pEditEngine && mpViewShell )
875 long nSizeX, nSizeY;
876 mpViewShell->GetViewData()->GetMergeSizePixel(
877 aCellPos.Col(), aCellPos.Row(), nSizeX, nSizeY);
879 Size aSize(nSizeX, nSizeY);
881 // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
882 long nIndent = 0;
883 const SvxHorJustifyItem* pHorJustifyItem = static_cast< const SvxHorJustifyItem* >(
884 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_HOR_JUSTIFY ) );
885 SvxCellHorJustify eHorJust = ( pHorJustifyItem ? static_cast< SvxCellHorJustify >( pHorJustifyItem->GetValue() ) : SVX_HOR_JUSTIFY_STANDARD );
886 if ( eHorJust == SVX_HOR_JUSTIFY_LEFT )
888 const SfxUInt16Item* pIndentItem = static_cast< const SfxUInt16Item* >(
889 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_INDENT ) );
890 if ( pIndentItem )
892 nIndent = static_cast< long >( pIndentItem->GetValue() );
896 const SvxMarginItem* pMarginItem = static_cast< const SvxMarginItem* >(
897 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_MARGIN ) );
898 ScViewData* pViewData = mpViewShell->GetViewData();
899 double nPPTX = ( pViewData ? pViewData->GetPPTX() : 0 );
900 double nPPTY = ( pViewData ? pViewData->GetPPTY() : 0 );
901 long nLeftM = ( pMarginItem ? static_cast< long >( ( pMarginItem->GetLeftMargin() + nIndent ) * nPPTX ) : 0 );
902 long nTopM = ( pMarginItem ? static_cast< long >( pMarginItem->GetTopMargin() * nPPTY ) : 0 );
903 long nRightM = ( pMarginItem ? static_cast< long >( pMarginItem->GetRightMargin() * nPPTX ) : 0 );
904 long nBottomM = ( pMarginItem ? static_cast< long >( pMarginItem->GetBottomMargin() * nPPTY ) : 0 );
905 long nWidth = aSize.getWidth() - nLeftM - nRightM;
906 aSize.setWidth( nWidth );
907 aSize.setHeight( aSize.getHeight() - nTopM - nBottomM );
909 Window* pWin = mpViewShell->GetWindowByPos( meSplitPos );
910 if ( pWin )
912 aSize = pWin->PixelToLogic( aSize, pEditEngine->GetRefMapMode() );
915 /* #i19430# Gnopernicus reads text partly if it sticks out of the cell
916 boundaries. This leads to wrong results in cases where the cell text
917 is rotated, because rotation is not taken into account when calcu-
918 lating the visible part of the text. In these cases we will expand
919 the cell size passed as paper size to the edit engine. The function
920 accessibility::AccessibleStaticTextBase::GetParagraphBoundingBox()
921 (see svx/source/accessibility/AccessibleStaticTextBase.cxx) will
922 return the size of the complete text then, which is used to expand
923 the cell bounding box in ScAccessibleCell::GetBoundingBox()
924 (see sc/source/ui/Accessibility/AccessibleCell.cxx). */
925 const SfxInt32Item* pItem = static_cast< const SfxInt32Item* >(
926 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_ROTATE_VALUE ) );
927 if( pItem && (pItem->GetValue() != 0) )
929 pEditEngine->SetPaperSize( Size( LONG_MAX, aSize.getHeight() ) );
930 long nTxtWidth = static_cast< long >( pEditEngine->CalcTextWidth() );
931 aSize.setWidth( std::max( aSize.getWidth(), nTxtWidth + 2 ) );
933 else
935 // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
936 const SfxBoolItem* pLineBreakItem = static_cast< const SfxBoolItem* >(
937 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_LINEBREAK ) );
938 bool bLineBreak = ( pLineBreakItem && pLineBreakItem->GetValue() );
939 if ( !bLineBreak )
941 long nTxtWidth = static_cast< long >( pEditEngine->CalcTextWidth() );
942 aSize.setWidth( ::std::max( aSize.getWidth(), nTxtWidth ) );
946 pEditEngine->SetPaperSize( aSize );
948 // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
949 if ( eHorJust == SVX_HOR_JUSTIFY_STANDARD && pDoc->HasValueData( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ) )
951 pEditEngine->SetDefaultItem( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
954 Size aTextSize;
955 if ( pWin )
957 aTextSize = pWin->LogicToPixel( Size( pEditEngine->CalcTextWidth(), pEditEngine->GetTextHeight() ), pEditEngine->GetRefMapMode() );
959 long nTextWidth = aTextSize.Width();
960 long nTextHeight = aTextSize.Height();
962 long nOffsetX = nLeftM;
963 long nDiffX = nTextWidth - nWidth;
964 if ( nDiffX > 0 )
966 switch ( eHorJust )
968 case SVX_HOR_JUSTIFY_RIGHT:
970 nOffsetX -= nDiffX;
972 break;
973 case SVX_HOR_JUSTIFY_CENTER:
975 nOffsetX -= nDiffX / 2;
977 break;
978 default:
981 break;
985 long nOffsetY = 0;
986 const SvxVerJustifyItem* pVerJustifyItem = static_cast< const SvxVerJustifyItem* >(
987 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_VER_JUSTIFY ) );
988 SvxCellVerJustify eVerJust = ( pVerJustifyItem ? static_cast< SvxCellVerJustify >( pVerJustifyItem->GetValue() ) : SVX_VER_JUSTIFY_STANDARD );
989 switch ( eVerJust )
991 case SVX_VER_JUSTIFY_STANDARD:
992 case SVX_VER_JUSTIFY_BOTTOM:
994 nOffsetY = nSizeY - nBottomM - nTextHeight;
996 break;
997 case SVX_VER_JUSTIFY_CENTER:
999 nOffsetY = ( nSizeY - nTopM - nBottomM - nTextHeight ) / 2 + nTopM;
1001 break;
1002 default:
1004 nOffsetY = nTopM;
1006 break;
1009 if ( mpAccessibleCell )
1011 mpAccessibleCell->SetOffset( Point( nOffsetX, nOffsetY ) );
1014 pEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1017 return pForwarder;
1020 SvxViewForwarder* ScAccessibleCellTextData::GetViewForwarder()
1022 if (!mpViewForwarder)
1023 mpViewForwarder = new ScViewForwarder(mpViewShell, meSplitPos, aCellPos);
1024 return mpViewForwarder;
1027 SvxEditViewForwarder* ScAccessibleCellTextData::GetEditViewForwarder( sal_Bool /* bCreate */ )
1029 //#102219#; there should no EditViewForwarder be, because the cell is now readonly in this interface
1030 /* if (!mpEditViewForwarder)
1032 SCCOL nCol;
1033 SCROW nRow;
1034 EditView* pEditView;
1035 mpViewShell->GetViewData()->GetEditView( meSplitPos, pEditView, nCol, nRow );
1037 mpEditViewForwarder = new ScEditViewForwarder(pEditView, mpViewShell->GetWindowByPos(meSplitPos));
1039 else if (bCreate)
1040 mpEditViewForwarder->GrabFocus();
1041 return mpEditViewForwarder;*/
1042 return NULL;
1045 IMPL_LINK(ScAccessibleCellTextData, NotifyHdl, EENotify*, aNotify)
1047 if( aNotify )
1049 ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify );
1051 if( aHint.get() )
1052 GetBroadcaster().Broadcast( *aHint.get() );
1055 return 0;
1058 ScDocShell* ScAccessibleCellTextData::GetDocShell(ScTabViewShell* pViewShell)
1060 ScDocShell* pDocSh = NULL;
1061 if (pViewShell)
1062 pDocSh = pViewShell->GetViewData()->GetDocShell();
1063 return pDocSh;
1067 // ============================================================================
1069 ScAccessibleEditObjectTextData::ScAccessibleEditObjectTextData(EditView* pEditView, Window* pWin)
1071 mpViewForwarder(NULL),
1072 mpEditViewForwarder(NULL),
1073 mpEditView(pEditView),
1074 mpEditEngine(pEditView ? pEditView->GetEditEngine() : 0),
1075 mpForwarder(NULL),
1076 mpWindow(pWin)
1078 if (mpEditEngine)
1079 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
1082 ScAccessibleEditObjectTextData::~ScAccessibleEditObjectTextData()
1084 if (mpEditEngine)
1085 mpEditEngine->SetNotifyHdl(Link());
1086 if (mpViewForwarder)
1087 delete mpViewForwarder;
1088 if (mpEditViewForwarder)
1089 delete mpEditViewForwarder;
1090 if (mpForwarder)
1091 delete mpForwarder;
1094 void ScAccessibleEditObjectTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1096 if ( rHint.ISA( SfxSimpleHint ) )
1098 ULONG nId = ((const SfxSimpleHint&)rHint).GetId();
1099 if ( nId == SFX_HINT_DYING )
1101 mpWindow = NULL;
1102 mpEditView = NULL;
1103 mpEditEngine = NULL;
1104 DELETEZ(mpForwarder);
1105 if (mpViewForwarder)
1106 mpViewForwarder->SetInvalid();
1107 if (mpEditViewForwarder)
1108 mpEditViewForwarder->SetInvalid();
1111 ScAccessibleTextData::Notify(rBC, rHint);
1114 ScAccessibleTextData* ScAccessibleEditObjectTextData::Clone() const
1116 return new ScAccessibleEditObjectTextData(mpEditView, mpWindow);
1119 SvxTextForwarder* ScAccessibleEditObjectTextData::GetTextForwarder()
1121 if ((!mpForwarder && mpEditView) || (mpEditEngine && !mpEditEngine->GetNotifyHdl().IsSet()))
1123 if (!mpEditEngine)
1124 mpEditEngine = mpEditView->GetEditEngine();
1125 if (mpEditEngine && !mpEditEngine->GetNotifyHdl().IsSet())
1126 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
1127 if(!mpForwarder)
1128 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1130 return mpForwarder;
1133 SvxViewForwarder* ScAccessibleEditObjectTextData::GetViewForwarder()
1135 if (!mpViewForwarder)
1137 // --> OD 2005-12-21 #i49561#
1138 mpViewForwarder = new ScEditObjectViewForwarder( mpWindow, mpEditView );
1139 // <--
1141 return mpViewForwarder;
1144 SvxEditViewForwarder* ScAccessibleEditObjectTextData::GetEditViewForwarder( sal_Bool bCreate )
1146 if (!mpEditViewForwarder && mpEditView)
1147 mpEditViewForwarder = new ScEditViewForwarder(mpEditView, mpWindow);
1148 if (bCreate)
1150 if (!mpEditView && mpEditViewForwarder)
1152 DELETEZ(mpEditViewForwarder);
1154 else if (mpEditViewForwarder)
1155 mpEditViewForwarder->GrabFocus();
1157 return mpEditViewForwarder;
1160 IMPL_LINK(ScAccessibleEditObjectTextData, NotifyHdl, EENotify*, aNotify)
1162 if( aNotify )
1164 ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify );
1166 if( aHint.get() )
1167 GetBroadcaster().Broadcast( *aHint.get() );
1170 return 0;
1174 // ============================================================================
1176 ScAccessibleEditLineTextData::ScAccessibleEditLineTextData(EditView* pEditView, Window* pWin)
1178 ScAccessibleEditObjectTextData(pEditView, pWin),
1179 mbEditEngineCreated(sal_False)
1181 ScTextWnd* pTxtWnd = (ScTextWnd*)pWin;
1183 if (pTxtWnd)
1184 pTxtWnd->SetAccessibleTextData(this);
1187 ScAccessibleEditLineTextData::~ScAccessibleEditLineTextData()
1189 ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1191 if (pTxtWnd)
1192 pTxtWnd->SetAccessibleTextData(NULL);
1194 if (mbEditEngineCreated && mpEditEngine)
1196 delete mpEditEngine;
1197 mpEditEngine = NULL; // #103346# don't access in ScAccessibleEditObjectTextData dtor!
1199 else if (pTxtWnd && pTxtWnd->GetEditView() && pTxtWnd->GetEditView()->GetEditEngine())
1201 // #103346# the NotifyHdl also has to be removed from the ScTextWnd's EditEngine
1202 // (it's set in ScAccessibleEditLineTextData::GetTextForwarder, and mpEditEngine
1203 // is reset there)
1204 pTxtWnd->GetEditView()->GetEditEngine()->SetNotifyHdl(Link());
1208 void ScAccessibleEditLineTextData::Dispose()
1210 ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1212 if (pTxtWnd)
1213 pTxtWnd->SetAccessibleTextData(NULL);
1215 ResetEditMode();
1216 mpWindow = NULL;
1219 ScAccessibleTextData* ScAccessibleEditLineTextData::Clone() const
1221 return new ScAccessibleEditLineTextData(mpEditView, mpWindow);
1224 SvxTextForwarder* ScAccessibleEditLineTextData::GetTextForwarder()
1226 ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1228 if (pTxtWnd)
1230 mpEditView = pTxtWnd->GetEditView();
1231 if (mpEditView)
1233 if (mbEditEngineCreated && mpEditEngine)
1234 ResetEditMode();
1235 mbEditEngineCreated = sal_False;
1237 mpEditView = pTxtWnd->GetEditView();
1238 ScAccessibleEditObjectTextData::GetTextForwarder(); // fill the mpForwarder
1239 mpEditEngine = NULL;
1241 else
1243 if (mpEditEngine && !mbEditEngineCreated)
1244 ResetEditMode();
1245 if (!mpEditEngine)
1247 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1248 pEnginePool->FreezeIdRanges();
1249 mpEditEngine = new ScFieldEditEngine( pEnginePool, NULL, TRUE );
1250 mbEditEngineCreated = sal_True;
1251 // currently, GetPortions doesn't work if UpdateMode is FALSE,
1252 // this will be fixed (in EditEngine) by src600
1253 // pEditEngine->SetUpdateMode( FALSE );
1254 mpEditEngine->EnableUndo( FALSE );
1255 mpEditEngine->SetRefMapMode( MAP_100TH_MM );
1256 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1258 mpEditEngine->SetText(pTxtWnd->GetTextString());
1260 Size aSize(pTxtWnd->GetSizePixel());
1262 aSize = pTxtWnd->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1264 mpEditEngine->SetPaperSize(aSize);
1266 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
1270 return mpForwarder;
1273 SvxEditViewForwarder* ScAccessibleEditLineTextData::GetEditViewForwarder( sal_Bool bCreate )
1275 ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1277 if (pTxtWnd)
1279 mpEditView = pTxtWnd->GetEditView();
1280 if (!mpEditView && bCreate)
1282 if ( !pTxtWnd->IsInputActive() )
1284 pTxtWnd->StartEditEngine();
1285 pTxtWnd->GrabFocus();
1286 // pTxtWnd->SetTextString( rText );
1287 // pTxtWnd->GetEditView()->SetSelection( rSel );
1289 mpEditView = pTxtWnd->GetEditView();
1294 return ScAccessibleEditObjectTextData::GetEditViewForwarder(bCreate);
1297 void ScAccessibleEditLineTextData::ResetEditMode()
1299 ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1301 if (mbEditEngineCreated && mpEditEngine)
1302 delete mpEditEngine;
1303 else if (pTxtWnd && pTxtWnd->GetEditView() && pTxtWnd->GetEditView()->GetEditEngine())
1304 pTxtWnd->GetEditView()->GetEditEngine()->SetNotifyHdl(Link());
1305 mpEditEngine = NULL;
1307 DELETEZ(mpForwarder);
1308 DELETEZ(mpEditViewForwarder);
1309 DELETEZ(mpViewForwarder);
1310 mbEditEngineCreated = sal_False;
1313 void ScAccessibleEditLineTextData::TextChanged()
1315 if (mbEditEngineCreated && mpEditEngine)
1317 ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1319 if (pTxtWnd)
1320 mpEditEngine->SetText(pTxtWnd->GetTextString());
1324 void ScAccessibleEditLineTextData::StartEdit()
1326 ResetEditMode();
1327 mpEditView = NULL;
1329 // send HINT_BEGEDIT
1330 SdrHint aHint(HINT_BEGEDIT);
1331 GetBroadcaster().Broadcast( aHint );
1334 void ScAccessibleEditLineTextData::EndEdit()
1336 // send HINT_ENDEDIT
1337 SdrHint aHint(HINT_ENDEDIT);
1338 GetBroadcaster().Broadcast( aHint );
1340 ResetEditMode();
1341 mpEditView = NULL;
1345 // ============================================================================
1347 // ScAccessiblePreviewCellTextData: shared data between sub objects of a accessible cell text object
1349 ScAccessiblePreviewCellTextData::ScAccessiblePreviewCellTextData(ScPreviewShell* pViewShell,
1350 const ScAddress& rP)
1351 : ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
1352 mpViewForwarder(NULL),
1353 mpViewShell(pViewShell)
1357 ScAccessiblePreviewCellTextData::~ScAccessiblePreviewCellTextData()
1359 if (pEditEngine)
1360 pEditEngine->SetNotifyHdl(Link());
1361 if (mpViewForwarder)
1362 delete mpViewForwarder;
1365 void ScAccessiblePreviewCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1367 if ( rHint.ISA( SfxSimpleHint ) )
1369 ULONG nId = ((const SfxSimpleHint&)rHint).GetId();
1370 if ( nId == SFX_HINT_DYING )
1372 mpViewShell = NULL; // invalid now
1373 if (mpViewForwarder)
1374 mpViewForwarder->SetInvalid();
1377 ScAccessibleCellBaseTextData::Notify(rBC, rHint);
1380 ScAccessibleTextData* ScAccessiblePreviewCellTextData::Clone() const
1382 return new ScAccessiblePreviewCellTextData(mpViewShell, aCellPos);
1385 SvxTextForwarder* ScAccessiblePreviewCellTextData::GetTextForwarder()
1387 sal_Bool bEditEngineBefore(pEditEngine != NULL);
1389 ScCellTextData::GetTextForwarder(); // creates Forwarder and EditEngine
1391 if (!bEditEngineBefore && pEditEngine)
1393 Size aSize(mpViewShell->GetLocationData().GetCellOutputRect(aCellPos).GetSize());
1394 Window* pWin = mpViewShell->GetWindow();
1395 if (pWin)
1396 aSize = pWin->PixelToLogic(aSize, pEditEngine->GetRefMapMode());
1397 pEditEngine->SetPaperSize(aSize);
1400 if (pEditEngine)
1401 pEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1403 return pForwarder;
1406 SvxViewForwarder* ScAccessiblePreviewCellTextData::GetViewForwarder()
1408 if (!mpViewForwarder)
1409 mpViewForwarder = new ScPreviewCellViewForwarder(mpViewShell, aCellPos);
1410 return mpViewForwarder;
1413 //UNUSED2008-05 IMPL_LINK(ScAccessiblePreviewCellTextData, NotifyHdl, EENotify*, aNotify)
1414 //UNUSED2008-05 {
1415 //UNUSED2008-05 if( aNotify )
1416 //UNUSED2008-05 {
1417 //UNUSED2008-05 ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify);
1418 //UNUSED2008-05
1419 //UNUSED2008-05 if( aHint.get() )
1420 //UNUSED2008-05 GetBroadcaster().Broadcast( *aHint.get() );
1421 //UNUSED2008-05 }
1422 //UNUSED2008-05
1423 //UNUSED2008-05 return 0;
1424 //UNUSED2008-05 }
1426 ScDocShell* ScAccessiblePreviewCellTextData::GetDocShell(ScPreviewShell* pViewShell)
1428 ScDocShell* pDocSh = NULL;
1429 if (pViewShell && pViewShell->GetDocument())
1430 pDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1431 return pDocSh;
1435 // ============================================================================
1437 // ScAccessiblePreviewHeaderCellTextData: shared data between sub objects of a accessible cell text object
1439 ScAccessiblePreviewHeaderCellTextData::ScAccessiblePreviewHeaderCellTextData(ScPreviewShell* pViewShell,
1440 const String& rText, const ScAddress& rP, sal_Bool bColHeader, sal_Bool bRowHeader)
1441 : ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
1442 mpViewForwarder(NULL),
1443 mpViewShell(pViewShell),
1444 maText(rText),
1445 mbColHeader(bColHeader),
1446 mbRowHeader(bRowHeader)
1450 ScAccessiblePreviewHeaderCellTextData::~ScAccessiblePreviewHeaderCellTextData()
1452 if (pEditEngine)
1453 pEditEngine->SetNotifyHdl(Link());
1454 if (mpViewForwarder)
1455 delete mpViewForwarder;
1458 void ScAccessiblePreviewHeaderCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1460 if ( rHint.ISA( SfxSimpleHint ) )
1462 ULONG nId = ((const SfxSimpleHint&)rHint).GetId();
1463 if ( nId == SFX_HINT_DYING )
1465 mpViewShell = NULL; // invalid now
1466 if (mpViewForwarder)
1467 mpViewForwarder->SetInvalid();
1470 ScAccessibleCellBaseTextData::Notify(rBC, rHint);
1473 ScAccessibleTextData* ScAccessiblePreviewHeaderCellTextData::Clone() const
1475 return new ScAccessiblePreviewHeaderCellTextData(mpViewShell, maText, aCellPos, mbColHeader, mbRowHeader);
1478 SvxTextForwarder* ScAccessiblePreviewHeaderCellTextData::GetTextForwarder()
1480 if (!pEditEngine)
1482 if ( pDocShell )
1484 ScDocument* pDoc = pDocShell->GetDocument();
1485 pEditEngine = pDoc->CreateFieldEditEngine();
1487 else
1489 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1490 pEnginePool->FreezeIdRanges();
1491 pEditEngine = new ScFieldEditEngine( pEnginePool, NULL, TRUE );
1493 // currently, GetPortions doesn't work if UpdateMode is FALSE,
1494 // this will be fixed (in EditEngine) by src600
1495 // pEditEngine->SetUpdateMode( FALSE );
1496 pEditEngine->EnableUndo( FALSE );
1497 if (pDocShell)
1498 pEditEngine->SetRefDevice(pDocShell->GetRefDevice());
1499 else
1500 pEditEngine->SetRefMapMode( MAP_100TH_MM );
1501 pForwarder = new SvxEditEngineForwarder(*pEditEngine);
1504 if (bDataValid)
1505 return pForwarder;
1507 if (maText.Len() && pEditEngine)
1510 if ( mpViewShell )
1512 Size aOutputSize;
1513 Window* pWindow = mpViewShell->GetWindow();
1514 if ( pWindow )
1515 aOutputSize = pWindow->GetOutputSizePixel();
1516 Point aPoint;
1517 Rectangle aVisRect( aPoint, aOutputSize );
1518 Size aSize(mpViewShell->GetLocationData().GetHeaderCellOutputRect(aVisRect, aCellPos, mbColHeader).GetSize());
1519 if (pWindow)
1520 aSize = pWindow->PixelToLogic(aSize, pEditEngine->GetRefMapMode());
1521 pEditEngine->SetPaperSize(aSize);
1523 pEditEngine->SetText( maText );
1526 bDataValid = TRUE;
1528 if (pEditEngine)
1529 pEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1531 return pForwarder;
1534 SvxViewForwarder* ScAccessiblePreviewHeaderCellTextData::GetViewForwarder()
1536 if (!mpViewForwarder)
1537 mpViewForwarder = new ScPreviewHeaderCellViewForwarder(mpViewShell, aCellPos, mbColHeader, mbRowHeader);
1538 return mpViewForwarder;
1541 //UNUSED2008-05 IMPL_LINK(ScAccessiblePreviewHeaderCellTextData, NotifyHdl, EENotify*, aNotify)
1542 //UNUSED2008-05 {
1543 //UNUSED2008-05 if( aNotify )
1544 //UNUSED2008-05 {
1545 //UNUSED2008-05 ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify);
1546 //UNUSED2008-05
1547 //UNUSED2008-05 if( aHint.get() )
1548 //UNUSED2008-05 GetBroadcaster().Broadcast( *aHint.get() );
1549 //UNUSED2008-05 }
1550 //UNUSED2008-05
1551 //UNUSED2008-05 return 0;
1552 //UNUSED2008-05 }
1554 ScDocShell* ScAccessiblePreviewHeaderCellTextData::GetDocShell(ScPreviewShell* pViewShell)
1556 ScDocShell* pDocSh = NULL;
1557 if (pViewShell && pViewShell->GetDocument())
1558 pDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1559 return pDocSh;
1563 // ============================================================================
1565 ScAccessibleHeaderTextData::ScAccessibleHeaderTextData(ScPreviewShell* pViewShell,
1566 const EditTextObject* pEditObj, sal_Bool bHeader, SvxAdjust eAdjust)
1568 mpViewForwarder(NULL),
1569 mpViewShell(pViewShell),
1570 mpEditEngine(NULL),
1571 mpForwarder(NULL),
1572 mpDocSh(NULL),
1573 mpEditObj(pEditObj),
1574 mbHeader(bHeader),
1575 mbDataValid(sal_False),
1576 meAdjust(eAdjust)
1578 if (pViewShell && pViewShell->GetDocument())
1579 mpDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1580 if (mpDocSh)
1581 mpDocSh->GetDocument()->AddUnoObject(*this);
1584 ScAccessibleHeaderTextData::~ScAccessibleHeaderTextData()
1586 ScUnoGuard aGuard; // needed for EditEngine dtor
1588 if (mpDocSh)
1589 mpDocSh->GetDocument()->RemoveUnoObject(*this);
1590 if (mpEditEngine)
1591 mpEditEngine->SetNotifyHdl(Link());
1592 delete mpEditEngine;
1593 delete mpForwarder;
1596 ScAccessibleTextData* ScAccessibleHeaderTextData::Clone() const
1598 return new ScAccessibleHeaderTextData(mpViewShell, mpEditObj, mbHeader, meAdjust);
1601 void ScAccessibleHeaderTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
1603 if ( rHint.ISA( SfxSimpleHint ) )
1605 ULONG nId = ((const SfxSimpleHint&)rHint).GetId();
1606 if ( nId == SFX_HINT_DYING )
1608 mpViewShell = NULL;// invalid now
1609 mpDocSh = NULL;
1610 if (mpViewForwarder)
1611 mpViewForwarder->SetInvalid();
1616 SvxTextForwarder* ScAccessibleHeaderTextData::GetTextForwarder()
1618 if (!mpEditEngine)
1620 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1621 pEnginePool->FreezeIdRanges();
1622 ScHeaderEditEngine* pHdrEngine = new ScHeaderEditEngine( pEnginePool, TRUE );
1624 pHdrEngine->EnableUndo( FALSE );
1625 pHdrEngine->SetRefMapMode( MAP_TWIP );
1627 // default font must be set, independently of document
1628 // -> use global pool from module
1630 SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() );
1631 const ScPatternAttr& rPattern = (const ScPatternAttr&)SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN);
1632 rPattern.FillEditItemSet( &aDefaults );
1633 // FillEditItemSet adjusts font height to 1/100th mm,
1634 // but for header/footer twips is needed, as in the PatternAttr:
1635 aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT );
1636 aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK );
1637 aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL );
1638 aDefaults.Put( SvxAdjustItem( meAdjust, EE_PARA_JUST ) );
1639 pHdrEngine->SetDefaults( aDefaults );
1641 ScHeaderFieldData aData;
1642 if (mpViewShell)
1643 mpViewShell->FillFieldData(aData);
1644 else
1645 ScHeaderFooterTextObj::FillDummyFieldData( aData );
1646 pHdrEngine->SetData( aData );
1648 mpEditEngine = pHdrEngine;
1649 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1652 if (mbDataValid)
1653 return mpForwarder;
1655 if ( mpViewShell )
1657 Rectangle aVisRect;
1658 mpViewShell->GetLocationData().GetHeaderPosition(aVisRect);
1659 Size aSize(aVisRect.GetSize());
1660 Window* pWin = mpViewShell->GetWindow();
1661 if (pWin)
1662 aSize = pWin->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1663 mpEditEngine->SetPaperSize(aSize);
1665 if (mpEditObj)
1666 mpEditEngine->SetText(*mpEditObj);
1668 mbDataValid = sal_True;
1669 return mpForwarder;
1672 SvxViewForwarder* ScAccessibleHeaderTextData::GetViewForwarder()
1674 if (!mpViewForwarder)
1675 mpViewForwarder = new ScPreviewHeaderFooterViewForwarder(mpViewShell, mbHeader);
1676 return mpViewForwarder;
1680 // ============================================================================
1682 ScAccessibleNoteTextData::ScAccessibleNoteTextData(ScPreviewShell* pViewShell,
1683 const String& sText, const ScAddress& aCellPos, sal_Bool bMarkNote)
1685 mpViewForwarder(NULL),
1686 mpViewShell(pViewShell),
1687 mpEditEngine(NULL),
1688 mpForwarder(NULL),
1689 mpDocSh(NULL),
1690 msText(sText),
1691 maCellPos(aCellPos),
1692 mbMarkNote(bMarkNote),
1693 mbDataValid(sal_False)
1695 if (pViewShell && pViewShell->GetDocument())
1696 mpDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1697 if (mpDocSh)
1698 mpDocSh->GetDocument()->AddUnoObject(*this);
1701 ScAccessibleNoteTextData::~ScAccessibleNoteTextData()
1703 ScUnoGuard aGuard; // needed for EditEngine dtor
1705 if (mpDocSh)
1706 mpDocSh->GetDocument()->RemoveUnoObject(*this);
1707 if (mpEditEngine)
1708 mpEditEngine->SetNotifyHdl(Link());
1709 delete mpEditEngine;
1710 delete mpForwarder;
1713 ScAccessibleTextData* ScAccessibleNoteTextData::Clone() const
1715 return new ScAccessibleNoteTextData(mpViewShell, msText, maCellPos, mbMarkNote);
1718 void ScAccessibleNoteTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
1720 if ( rHint.ISA( SfxSimpleHint ) )
1722 ULONG nId = ((const SfxSimpleHint&)rHint).GetId();
1723 if ( nId == SFX_HINT_DYING )
1725 mpViewShell = NULL;// invalid now
1726 mpDocSh = NULL;
1727 if (mpViewForwarder)
1728 mpViewForwarder->SetInvalid();
1733 SvxTextForwarder* ScAccessibleNoteTextData::GetTextForwarder()
1735 if (!mpEditEngine)
1737 if ( mpDocSh )
1739 ScDocument* pDoc = mpDocSh->GetDocument();
1740 mpEditEngine = pDoc->CreateFieldEditEngine();
1742 else
1744 SfxItemPool* pEnginePool = EditEngine::CreatePool();
1745 pEnginePool->FreezeIdRanges();
1746 mpEditEngine = new ScFieldEditEngine( pEnginePool, NULL, TRUE );
1748 // currently, GetPortions doesn't work if UpdateMode is FALSE,
1749 // this will be fixed (in EditEngine) by src600
1750 // pEditEngine->SetUpdateMode( FALSE );
1751 mpEditEngine->EnableUndo( FALSE );
1752 if (mpDocSh)
1753 mpEditEngine->SetRefDevice(mpDocSh->GetRefDevice());
1754 else
1755 mpEditEngine->SetRefMapMode( MAP_100TH_MM );
1756 mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1759 if (mbDataValid)
1760 return mpForwarder;
1762 if (msText.Len() && mpEditEngine)
1765 if ( mpViewShell )
1767 Size aOutputSize;
1768 Window* pWindow = mpViewShell->GetWindow();
1769 if ( pWindow )
1770 aOutputSize = pWindow->GetOutputSizePixel();
1771 Point aPoint;
1772 Rectangle aVisRect( aPoint, aOutputSize );
1773 Size aSize(mpViewShell->GetLocationData().GetNoteInRangeOutputRect(aVisRect, mbMarkNote, maCellPos).GetSize());
1774 if (pWindow)
1775 aSize = pWindow->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1776 mpEditEngine->SetPaperSize(aSize);
1778 mpEditEngine->SetText( msText );
1781 mbDataValid = TRUE;
1783 if (mpEditEngine)
1784 mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1786 return mpForwarder;
1789 SvxViewForwarder* ScAccessibleNoteTextData::GetViewForwarder()
1791 if (!mpViewForwarder)
1792 mpViewForwarder = new ScPreviewNoteViewForwarder(mpViewShell, maCellPos, mbMarkNote);
1793 return mpViewForwarder;
1797 // CSV import =================================================================
1799 class ScCsvViewForwarder : public SvxViewForwarder
1801 Rectangle maBoundBox;
1802 Window* mpWindow;
1804 public:
1805 explicit ScCsvViewForwarder( Window* pWindow, const Rectangle& rBoundBox );
1807 virtual BOOL IsValid() const;
1808 virtual Rectangle GetVisArea() const;
1809 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const;
1810 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const;
1812 void SetInvalid();
1815 ScCsvViewForwarder::ScCsvViewForwarder( Window* pWindow, const Rectangle& rBoundBox ) :
1816 maBoundBox( rBoundBox ),
1817 mpWindow( pWindow )
1821 BOOL ScCsvViewForwarder::IsValid() const
1823 return mpWindow != NULL;
1826 Rectangle ScCsvViewForwarder::GetVisArea() const
1828 return maBoundBox;
1831 Point ScCsvViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
1833 if( !mpWindow ) return Point();
1834 return mpWindow->LogicToPixel( rPoint, rMapMode );
1837 Point ScCsvViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
1839 if( !mpWindow ) return Point();
1840 return mpWindow->PixelToLogic( rPoint, rMapMode );
1843 void ScCsvViewForwarder::SetInvalid()
1845 mpWindow = NULL;
1848 // ----------------------------------------------------------------------------
1850 ScAccessibleCsvTextData::ScAccessibleCsvTextData(
1851 Window* pWindow, EditEngine* pEditEngine,
1852 const String& rCellText, const Rectangle& rBoundBox, const Size& rCellSize ) :
1853 mpWindow( pWindow ),
1854 mpEditEngine( pEditEngine ),
1855 maCellText( rCellText ),
1856 maBoundBox( rBoundBox ),
1857 maCellSize( rCellSize )
1861 ScAccessibleCsvTextData::~ScAccessibleCsvTextData()
1865 void ScAccessibleCsvTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1867 if ( rHint.ISA( SfxSimpleHint ) )
1869 ULONG nId = ((const SfxSimpleHint&)rHint).GetId();
1870 if( nId == SFX_HINT_DYING )
1872 mpWindow = NULL;
1873 mpEditEngine = NULL;
1874 if (mpViewForwarder.get())
1875 mpViewForwarder->SetInvalid();
1878 ScAccessibleTextData::Notify( rBC, rHint );
1881 ScAccessibleTextData* ScAccessibleCsvTextData::Clone() const
1883 return new ScAccessibleCsvTextData( mpWindow, mpEditEngine, maCellText, maBoundBox, maCellSize );
1886 SvxTextForwarder* ScAccessibleCsvTextData::GetTextForwarder()
1888 if( mpEditEngine )
1890 mpEditEngine->SetPaperSize( maCellSize );
1891 mpEditEngine->SetText( maCellText );
1892 if( !mpTextForwarder.get() )
1893 mpTextForwarder.reset( new SvxEditEngineForwarder( *mpEditEngine ) );
1895 else
1896 mpTextForwarder.reset( NULL );
1897 return mpTextForwarder.get();
1900 SvxViewForwarder* ScAccessibleCsvTextData::GetViewForwarder()
1902 if( !mpViewForwarder.get() )
1903 mpViewForwarder.reset( new ScCsvViewForwarder( mpWindow, maBoundBox ) );
1904 return mpViewForwarder.get();
1907 SvxEditViewForwarder* ScAccessibleCsvTextData::GetEditViewForwarder( sal_Bool /* bCreate */ )
1909 return NULL;
1913 // ============================================================================