1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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>
39 #include "AccessibleText.hxx"
40 #include "AccessibleCell.hxx"
41 #include "tabvwsh.hxx"
42 #include "editutil.hxx"
43 #include "document.hxx"
45 #include "prevwsh.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
;
67 ScSplitPos meSplitPos
;
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;
80 ScViewForwarder::ScViewForwarder(ScTabViewShell
* pViewShell
, ScSplitPos eSplitPos
, const ScAddress
& rCell
)
82 mpViewShell(pViewShell
),
88 ScViewForwarder::~ScViewForwarder()
92 BOOL
ScViewForwarder::IsValid() const
94 return mpViewShell
!= NULL
;
97 Rectangle
ScViewForwarder::GetVisArea() const
102 Window
* pWindow
= mpViewShell
->GetWindowByPos(meSplitPos
);
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
);
120 DBG_ERROR("this ViewForwarder is not valid");
125 Point
ScViewForwarder::LogicToPixel( const Point
& rPoint
, const MapMode
& rMapMode
) const
129 Window
* pWindow
= mpViewShell
->GetWindowByPos(meSplitPos
);
131 return pWindow
->LogicToPixel( rPoint
, rMapMode
);
135 DBG_ERROR("this ViewForwarder is not valid");
140 Point
ScViewForwarder::PixelToLogic( const Point
& rPoint
, const MapMode
& rMapMode
) const
144 Window
* pWindow
= mpViewShell
->GetWindowByPos(meSplitPos
);
146 return pWindow
->PixelToLogic( rPoint
, rMapMode
);
150 DBG_ERROR("this ViewForwarder is not valid");
155 void ScViewForwarder::SetInvalid()
160 // ============================================================================
162 class ScEditObjectViewForwarder
: public SvxViewForwarder
165 // --> OD 2005-12-21 #i49561#
166 // - EditView needed for access to its visible area.
167 const EditView
* mpEditView
;
170 // --> OD 2005-12-21 #i49561#
171 ScEditObjectViewForwarder( Window
* pWindow
,
172 const EditView
* _pEditView
);
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;
184 // --> OD 2005-12-21 #i49561#
185 ScEditObjectViewForwarder::ScEditObjectViewForwarder( Window
* pWindow
,
186 const EditView
* _pEditView
)
189 mpEditView( _pEditView
)
194 ScEditObjectViewForwarder::~ScEditObjectViewForwarder()
198 BOOL
ScEditObjectViewForwarder::IsValid() const
200 return (mpWindow
!= NULL
);
203 Rectangle
ScEditObjectViewForwarder::GetVisArea() const
208 Rectangle
aVisRect(mpWindow
->GetWindowExtentsRelative(mpWindow
->GetAccessibleParentWindow()));
210 aVisRect
.SetPos(Point(0, 0));
216 DBG_ERROR("this ViewForwarder is not valid");
221 Point
ScEditObjectViewForwarder::LogicToPixel( const Point
& rPoint
, const MapMode
& rMapMode
) const
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
);
230 Rectangle
aEditViewVisArea( mpEditView
->GetVisArea() );
231 aPoint
+= aEditViewVisArea
.TopLeft();
233 return mpWindow
->LogicToPixel( aPoint
, rMapMode
);
238 DBG_ERROR("this ViewForwarder is not valid");
243 Point
ScEditObjectViewForwarder::PixelToLogic( const Point
& rPoint
, const MapMode
& rMapMode
) const
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
) );
252 Rectangle
aEditViewVisArea( mpEditView
->GetVisArea() );
253 aPoint
-= aEditViewVisArea
.TopLeft();
260 DBG_ERROR("this ViewForwarder is not valid");
265 void ScEditObjectViewForwarder::SetInvalid()
270 // ============================================================================
272 class ScPreviewViewForwarder
: public SvxViewForwarder
275 ScPreviewShell
* mpViewShell
;
276 mutable ScPreviewTableInfo
* mpTableInfo
;
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;
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
),
301 ScPreviewViewForwarder::~ScPreviewViewForwarder()
306 BOOL
ScPreviewViewForwarder::IsValid() const
308 return mpViewShell
!= NULL
;
311 Rectangle
ScPreviewViewForwarder::GetVisArea() const
314 DBG_ERROR("should be implemented in an abrevated class");
318 Point
ScPreviewViewForwarder::LogicToPixel( const Point
& rPoint
, const MapMode
& rMapMode
) const
322 Window
* pWindow
= mpViewShell
->GetWindow();
325 MapMode
aMapMode(pWindow
->GetMapMode().GetMapUnit());
326 Point
aPoint2( OutputDevice::LogicToLogic( rPoint
, rMapMode
, aMapMode
) );
327 return pWindow
->LogicToPixel(aPoint2
);
332 DBG_ERROR("this ViewForwarder is not valid");
337 Point
ScPreviewViewForwarder::PixelToLogic( const Point
& rPoint
, const MapMode
& rMapMode
) const
341 Window
* pWindow
= mpViewShell
->GetWindow();
344 MapMode
aMapMode(pWindow
->GetMapMode());
345 aMapMode
.SetOrigin(Point());
346 Point
aPoint1( pWindow
->PixelToLogic( rPoint
) );
347 Point
aPoint2( OutputDevice::LogicToLogic( aPoint1
,
348 aMapMode
.GetMapUnit(),
355 DBG_ERROR("this ViewForwarder is not valid");
360 void ScPreviewViewForwarder::SetInvalid()
365 Rectangle
ScPreviewViewForwarder::GetVisRect() const
370 Window
* pWindow
= mpViewShell
->GetWindow();
372 aOutputSize
= pWindow
->GetOutputSizePixel();
374 Rectangle
aVisRect( aPoint
, aOutputSize
);
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();
387 aVisArea
= pWin
->GetWindowExtentsRelative(pWin
).GetIntersection(aVisArea
);
389 sal_Int32
nX(aPos
.getX());
390 sal_Int32
nY(aPos
.getY());
400 aVisArea
.SetPos(Point(nX
, nY
));
405 // ============================================================================
407 class ScPreviewHeaderFooterViewForwarder
: public ScPreviewViewForwarder
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
),
424 ScPreviewHeaderFooterViewForwarder::~ScPreviewHeaderFooterViewForwarder()
428 Rectangle
ScPreviewHeaderFooterViewForwarder::GetVisArea() const
433 const ScPreviewLocationData
& rData
= mpViewShell
->GetLocationData();
435 rData
.GetHeaderPosition( aVisArea
);
437 rData
.GetFooterPosition( aVisArea
);
439 aVisArea
= CorrectVisArea(aVisArea
);
443 DBG_ERROR("this ViewForwarder is not valid");
448 // ============================================================================
450 class ScPreviewCellViewForwarder
: public ScPreviewViewForwarder
454 ScPreviewCellViewForwarder(ScPreviewShell
* pViewShell
,
456 virtual ~ScPreviewCellViewForwarder();
458 virtual Rectangle
GetVisArea() const;
461 ScPreviewCellViewForwarder::ScPreviewCellViewForwarder(ScPreviewShell
* pViewShell
,
464 ScPreviewViewForwarder(pViewShell
),
469 ScPreviewCellViewForwarder::~ScPreviewCellViewForwarder()
473 Rectangle
ScPreviewCellViewForwarder::GetVisArea() const
478 const ScPreviewLocationData
& rData
= mpViewShell
->GetLocationData();
479 aVisArea
= rData
.GetCellOutputRect(maCellPos
);
481 aVisArea
= CorrectVisArea(aVisArea
);
485 DBG_ERROR("this ViewForwarder is not valid");
490 // ============================================================================
492 class ScPreviewHeaderCellViewForwarder
: public ScPreviewViewForwarder
495 sal_Bool mbColHeader
;
496 sal_Bool mbRowHeader
;
498 ScPreviewHeaderCellViewForwarder(ScPreviewShell
* pViewShell
,
500 sal_Bool bColHeader
, sal_Bool bRowHeader
);
501 virtual ~ScPreviewHeaderCellViewForwarder();
503 virtual Rectangle
GetVisArea() const;
506 ScPreviewHeaderCellViewForwarder::ScPreviewHeaderCellViewForwarder(ScPreviewShell
* pViewShell
,
508 sal_Bool bColHeader
, sal_Bool bRowHeader
)
510 ScPreviewViewForwarder(pViewShell
),
512 mbColHeader(bColHeader
),
513 mbRowHeader(bRowHeader
)
517 ScPreviewHeaderCellViewForwarder::~ScPreviewHeaderCellViewForwarder()
521 Rectangle
ScPreviewHeaderCellViewForwarder::GetVisArea() const
526 const ScPreviewLocationData
& rData
= mpViewShell
->GetLocationData();
527 aVisArea
= rData
.GetHeaderCellOutputRect(GetVisRect(), maCellPos
, mbColHeader
);
529 aVisArea
= CorrectVisArea(aVisArea
);
533 DBG_ERROR("this ViewForwarder is not valid");
538 // ============================================================================
540 class ScPreviewNoteViewForwarder
: public ScPreviewViewForwarder
545 ScPreviewNoteViewForwarder(ScPreviewShell
* pViewShell
,
548 virtual ~ScPreviewNoteViewForwarder();
550 virtual Rectangle
GetVisArea() const;
553 ScPreviewNoteViewForwarder::ScPreviewNoteViewForwarder(ScPreviewShell
* pViewShell
,
557 ScPreviewViewForwarder(pViewShell
),
559 mbNoteMark(bNoteMark
)
563 ScPreviewNoteViewForwarder::~ScPreviewNoteViewForwarder()
567 Rectangle
ScPreviewNoteViewForwarder::GetVisArea() const
572 const ScPreviewLocationData
& rData
= mpViewShell
->GetLocationData();
573 aVisArea
= rData
.GetNoteInRangeOutputRect(GetVisRect(), mbNoteMark
, maCellPos
);
575 aVisArea
= CorrectVisArea(aVisArea
);
579 DBG_ERROR("this ViewForwarder is not valid");
584 // ============================================================================
586 class ScEditViewForwarder
: public SvxEditViewForwarder
588 EditView
* mpEditView
;
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();
609 ScEditViewForwarder::ScEditViewForwarder(EditView
* pEditView
, Window
* pWin
)
610 : mpEditView(pEditView
),
616 ScEditViewForwarder::~ScEditViewForwarder()
620 BOOL
ScEditViewForwarder::IsValid() const
622 sal_Bool
bResult(sal_False
);
623 if (mpWindow
&& mpEditView
)
630 Rectangle
ScEditViewForwarder::GetVisArea() const
633 if (IsValid() && mpEditView
->GetEditEngine())
635 MapMode
aMapMode(mpEditView
->GetEditEngine()->GetRefMapMode());
637 aVisArea
= mpWindow
->LogicToPixel( mpEditView
->GetVisArea(), aMapMode
);
641 DBG_ERROR("this EditViewForwarder is no longer valid");
646 Point
ScEditViewForwarder::LogicToPixel( const Point
& rPoint
, const MapMode
& rMapMode
) const
649 return mpWindow
->LogicToPixel( rPoint
, rMapMode
);
652 DBG_ERROR("this ViewForwarder is not valid");
657 Point
ScEditViewForwarder::PixelToLogic( const Point
& rPoint
, const MapMode
& rMapMode
) const
660 return mpWindow
->PixelToLogic( rPoint
, rMapMode
);
663 DBG_ERROR("this ViewForwarder is not valid");
668 sal_Bool
ScEditViewForwarder::GetSelection( ESelection
& rSelection
) const
670 sal_Bool
bResult(sal_False
);
673 rSelection
= mpEditView
->GetSelection();
678 DBG_ERROR("this ViewForwarder is not valid");
683 sal_Bool
ScEditViewForwarder::SetSelection( const ESelection
& rSelection
)
685 sal_Bool
bResult(sal_False
);
688 mpEditView
->SetSelection(rSelection
);
693 DBG_ERROR("this ViewForwarder is not valid");
698 sal_Bool
ScEditViewForwarder::Copy()
700 sal_Bool
bResult(sal_False
);
708 DBG_ERROR("this ViewForwarder is not valid");
713 sal_Bool
ScEditViewForwarder::Cut()
715 sal_Bool
bResult(sal_False
);
723 DBG_ERROR("this ViewForwarder is not valid");
728 sal_Bool
ScEditViewForwarder::Paste()
730 sal_Bool
bResult(sal_False
);
738 DBG_ERROR("this ViewForwarder is not valid");
743 void ScEditViewForwarder::GrabFocus()
747 void ScEditViewForwarder::SetInvalid()
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()
772 pEditEngine
->SetNotifyHdl(Link());
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
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();
808 // #104893#; use the displayed string
809 pDoc
->GetString(rCellPos
.Col(), rCellPos
.Row(), rCellPos
.Tab(), rText
);
812 const ScViewOptions
& aOptions
= mpViewShell
->GetViewData()->GetOptions();
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)
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)
840 DELETEZ( pForwarder );
842 DELETEZ( pEditEngine );
847 mpViewShell->GetViewData()->GetEditView( meSplitPos, pEditView, nCol, nRow );
850 pEditEngine = (ScFieldEditEngine*)pEditView->GetEditEngine();
851 pForwarder = new SvxEditEngineForwarder(*pEditEngine);
852 bHasForwarder = sal_True;
856 bHasForwarder = sal_True;
858 else if (mbViewEditEngine)
860 // remove Forwarder created with EditEngine from EditView
862 DELETEZ( pForwarder );
863 pEditEngine->SetNotifyHdl(Link());
864 // don't delete, because it is the EditEngine of the EditView
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
)
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
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
) );
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
);
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 ) );
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() );
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
) );
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
;
968 case SVX_HOR_JUSTIFY_RIGHT
:
973 case SVX_HOR_JUSTIFY_CENTER
:
975 nOffsetX
-= nDiffX
/ 2;
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
);
991 case SVX_VER_JUSTIFY_STANDARD
:
992 case SVX_VER_JUSTIFY_BOTTOM
:
994 nOffsetY
= nSizeY
- nBottomM
- nTextHeight
;
997 case SVX_VER_JUSTIFY_CENTER
:
999 nOffsetY
= ( nSizeY
- nTopM
- nBottomM
- nTextHeight
) / 2 + nTopM
;
1009 if ( mpAccessibleCell
)
1011 mpAccessibleCell
->SetOffset( Point( nOffsetX
, nOffsetY
) );
1014 pEditEngine
->SetNotifyHdl( LINK(this, ScAccessibleCellTextData
, NotifyHdl
) );
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)
1034 EditView* pEditView;
1035 mpViewShell->GetViewData()->GetEditView( meSplitPos, pEditView, nCol, nRow );
1037 mpEditViewForwarder = new ScEditViewForwarder(pEditView, mpViewShell->GetWindowByPos(meSplitPos));
1040 mpEditViewForwarder->GrabFocus();
1041 return mpEditViewForwarder;*/
1045 IMPL_LINK(ScAccessibleCellTextData
, NotifyHdl
, EENotify
*, aNotify
)
1049 ::std::auto_ptr
< SfxHint
> aHint
= SvxEditSourceHelper::EENotification2Hint( aNotify
);
1052 GetBroadcaster().Broadcast( *aHint
.get() );
1058 ScDocShell
* ScAccessibleCellTextData::GetDocShell(ScTabViewShell
* pViewShell
)
1060 ScDocShell
* pDocSh
= NULL
;
1062 pDocSh
= pViewShell
->GetViewData()->GetDocShell();
1067 // ============================================================================
1069 ScAccessibleEditObjectTextData::ScAccessibleEditObjectTextData(EditView
* pEditView
, Window
* pWin
)
1071 mpViewForwarder(NULL
),
1072 mpEditViewForwarder(NULL
),
1073 mpEditView(pEditView
),
1074 mpEditEngine(pEditView
? pEditView
->GetEditEngine() : 0),
1079 mpEditEngine
->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData
, NotifyHdl
) );
1082 ScAccessibleEditObjectTextData::~ScAccessibleEditObjectTextData()
1085 mpEditEngine
->SetNotifyHdl(Link());
1086 if (mpViewForwarder
)
1087 delete mpViewForwarder
;
1088 if (mpEditViewForwarder
)
1089 delete mpEditViewForwarder
;
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
)
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()))
1124 mpEditEngine
= mpEditView
->GetEditEngine();
1125 if (mpEditEngine
&& !mpEditEngine
->GetNotifyHdl().IsSet())
1126 mpEditEngine
->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData
, NotifyHdl
) );
1128 mpForwarder
= new SvxEditEngineForwarder(*mpEditEngine
);
1133 SvxViewForwarder
* ScAccessibleEditObjectTextData::GetViewForwarder()
1135 if (!mpViewForwarder
)
1137 // --> OD 2005-12-21 #i49561#
1138 mpViewForwarder
= new ScEditObjectViewForwarder( mpWindow
, mpEditView
);
1141 return mpViewForwarder
;
1144 SvxEditViewForwarder
* ScAccessibleEditObjectTextData::GetEditViewForwarder( sal_Bool bCreate
)
1146 if (!mpEditViewForwarder
&& mpEditView
)
1147 mpEditViewForwarder
= new ScEditViewForwarder(mpEditView
, mpWindow
);
1150 if (!mpEditView
&& mpEditViewForwarder
)
1152 DELETEZ(mpEditViewForwarder
);
1154 else if (mpEditViewForwarder
)
1155 mpEditViewForwarder
->GrabFocus();
1157 return mpEditViewForwarder
;
1160 IMPL_LINK(ScAccessibleEditObjectTextData
, NotifyHdl
, EENotify
*, aNotify
)
1164 ::std::auto_ptr
< SfxHint
> aHint
= SvxEditSourceHelper::EENotification2Hint( aNotify
);
1167 GetBroadcaster().Broadcast( *aHint
.get() );
1174 // ============================================================================
1176 ScAccessibleEditLineTextData::ScAccessibleEditLineTextData(EditView
* pEditView
, Window
* pWin
)
1178 ScAccessibleEditObjectTextData(pEditView
, pWin
),
1179 mbEditEngineCreated(sal_False
)
1181 ScTextWnd
* pTxtWnd
= (ScTextWnd
*)pWin
;
1184 pTxtWnd
->SetAccessibleTextData(this);
1187 ScAccessibleEditLineTextData::~ScAccessibleEditLineTextData()
1189 ScTextWnd
* pTxtWnd
= (ScTextWnd
*)mpWindow
;
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
1204 pTxtWnd
->GetEditView()->GetEditEngine()->SetNotifyHdl(Link());
1208 void ScAccessibleEditLineTextData::Dispose()
1210 ScTextWnd
* pTxtWnd
= (ScTextWnd
*)mpWindow
;
1213 pTxtWnd
->SetAccessibleTextData(NULL
);
1219 ScAccessibleTextData
* ScAccessibleEditLineTextData::Clone() const
1221 return new ScAccessibleEditLineTextData(mpEditView
, mpWindow
);
1224 SvxTextForwarder
* ScAccessibleEditLineTextData::GetTextForwarder()
1226 ScTextWnd
* pTxtWnd
= (ScTextWnd
*)mpWindow
;
1230 mpEditView
= pTxtWnd
->GetEditView();
1233 if (mbEditEngineCreated
&& mpEditEngine
)
1235 mbEditEngineCreated
= sal_False
;
1237 mpEditView
= pTxtWnd
->GetEditView();
1238 ScAccessibleEditObjectTextData::GetTextForwarder(); // fill the mpForwarder
1239 mpEditEngine
= NULL
;
1243 if (mpEditEngine
&& !mbEditEngineCreated
)
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
) );
1273 SvxEditViewForwarder
* ScAccessibleEditLineTextData::GetEditViewForwarder( sal_Bool bCreate
)
1275 ScTextWnd
* pTxtWnd
= (ScTextWnd
*)mpWindow
;
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
;
1320 mpEditEngine
->SetText(pTxtWnd
->GetTextString());
1324 void ScAccessibleEditLineTextData::StartEdit()
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
);
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()
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();
1396 aSize
= pWin
->PixelToLogic(aSize
, pEditEngine
->GetRefMapMode());
1397 pEditEngine
->SetPaperSize(aSize
);
1401 pEditEngine
->SetNotifyHdl( LINK(this, ScAccessibleCellTextData
, NotifyHdl
) );
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)
1415 //UNUSED2008-05 if( aNotify )
1417 //UNUSED2008-05 ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify);
1419 //UNUSED2008-05 if( aHint.get() )
1420 //UNUSED2008-05 GetBroadcaster().Broadcast( *aHint.get() );
1423 //UNUSED2008-05 return 0;
1426 ScDocShell
* ScAccessiblePreviewCellTextData::GetDocShell(ScPreviewShell
* pViewShell
)
1428 ScDocShell
* pDocSh
= NULL
;
1429 if (pViewShell
&& pViewShell
->GetDocument())
1430 pDocSh
= (ScDocShell
*) pViewShell
->GetDocument()->GetDocumentShell();
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
),
1445 mbColHeader(bColHeader
),
1446 mbRowHeader(bRowHeader
)
1450 ScAccessiblePreviewHeaderCellTextData::~ScAccessiblePreviewHeaderCellTextData()
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()
1484 ScDocument
* pDoc
= pDocShell
->GetDocument();
1485 pEditEngine
= pDoc
->CreateFieldEditEngine();
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
);
1498 pEditEngine
->SetRefDevice(pDocShell
->GetRefDevice());
1500 pEditEngine
->SetRefMapMode( MAP_100TH_MM
);
1501 pForwarder
= new SvxEditEngineForwarder(*pEditEngine
);
1507 if (maText
.Len() && pEditEngine
)
1513 Window
* pWindow
= mpViewShell
->GetWindow();
1515 aOutputSize
= pWindow
->GetOutputSizePixel();
1517 Rectangle
aVisRect( aPoint
, aOutputSize
);
1518 Size
aSize(mpViewShell
->GetLocationData().GetHeaderCellOutputRect(aVisRect
, aCellPos
, mbColHeader
).GetSize());
1520 aSize
= pWindow
->PixelToLogic(aSize
, pEditEngine
->GetRefMapMode());
1521 pEditEngine
->SetPaperSize(aSize
);
1523 pEditEngine
->SetText( maText
);
1529 pEditEngine
->SetNotifyHdl( LINK(this, ScAccessibleCellTextData
, NotifyHdl
) );
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)
1543 //UNUSED2008-05 if( aNotify )
1545 //UNUSED2008-05 ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify);
1547 //UNUSED2008-05 if( aHint.get() )
1548 //UNUSED2008-05 GetBroadcaster().Broadcast( *aHint.get() );
1551 //UNUSED2008-05 return 0;
1554 ScDocShell
* ScAccessiblePreviewHeaderCellTextData::GetDocShell(ScPreviewShell
* pViewShell
)
1556 ScDocShell
* pDocSh
= NULL
;
1557 if (pViewShell
&& pViewShell
->GetDocument())
1558 pDocSh
= (ScDocShell
*) pViewShell
->GetDocument()->GetDocumentShell();
1563 // ============================================================================
1565 ScAccessibleHeaderTextData::ScAccessibleHeaderTextData(ScPreviewShell
* pViewShell
,
1566 const EditTextObject
* pEditObj
, sal_Bool bHeader
, SvxAdjust eAdjust
)
1568 mpViewForwarder(NULL
),
1569 mpViewShell(pViewShell
),
1573 mpEditObj(pEditObj
),
1575 mbDataValid(sal_False
),
1578 if (pViewShell
&& pViewShell
->GetDocument())
1579 mpDocSh
= (ScDocShell
*) pViewShell
->GetDocument()->GetDocumentShell();
1581 mpDocSh
->GetDocument()->AddUnoObject(*this);
1584 ScAccessibleHeaderTextData::~ScAccessibleHeaderTextData()
1586 ScUnoGuard aGuard
; // needed for EditEngine dtor
1589 mpDocSh
->GetDocument()->RemoveUnoObject(*this);
1591 mpEditEngine
->SetNotifyHdl(Link());
1592 delete mpEditEngine
;
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
1610 if (mpViewForwarder
)
1611 mpViewForwarder
->SetInvalid();
1616 SvxTextForwarder
* ScAccessibleHeaderTextData::GetTextForwarder()
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
;
1643 mpViewShell
->FillFieldData(aData
);
1645 ScHeaderFooterTextObj::FillDummyFieldData( aData
);
1646 pHdrEngine
->SetData( aData
);
1648 mpEditEngine
= pHdrEngine
;
1649 mpForwarder
= new SvxEditEngineForwarder(*mpEditEngine
);
1658 mpViewShell
->GetLocationData().GetHeaderPosition(aVisRect
);
1659 Size
aSize(aVisRect
.GetSize());
1660 Window
* pWin
= mpViewShell
->GetWindow();
1662 aSize
= pWin
->PixelToLogic(aSize
, mpEditEngine
->GetRefMapMode());
1663 mpEditEngine
->SetPaperSize(aSize
);
1666 mpEditEngine
->SetText(*mpEditObj
);
1668 mbDataValid
= sal_True
;
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
),
1691 maCellPos(aCellPos
),
1692 mbMarkNote(bMarkNote
),
1693 mbDataValid(sal_False
)
1695 if (pViewShell
&& pViewShell
->GetDocument())
1696 mpDocSh
= (ScDocShell
*) pViewShell
->GetDocument()->GetDocumentShell();
1698 mpDocSh
->GetDocument()->AddUnoObject(*this);
1701 ScAccessibleNoteTextData::~ScAccessibleNoteTextData()
1703 ScUnoGuard aGuard
; // needed for EditEngine dtor
1706 mpDocSh
->GetDocument()->RemoveUnoObject(*this);
1708 mpEditEngine
->SetNotifyHdl(Link());
1709 delete mpEditEngine
;
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
1727 if (mpViewForwarder
)
1728 mpViewForwarder
->SetInvalid();
1733 SvxTextForwarder
* ScAccessibleNoteTextData::GetTextForwarder()
1739 ScDocument
* pDoc
= mpDocSh
->GetDocument();
1740 mpEditEngine
= pDoc
->CreateFieldEditEngine();
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
);
1753 mpEditEngine
->SetRefDevice(mpDocSh
->GetRefDevice());
1755 mpEditEngine
->SetRefMapMode( MAP_100TH_MM
);
1756 mpForwarder
= new SvxEditEngineForwarder(*mpEditEngine
);
1762 if (msText
.Len() && mpEditEngine
)
1768 Window
* pWindow
= mpViewShell
->GetWindow();
1770 aOutputSize
= pWindow
->GetOutputSizePixel();
1772 Rectangle
aVisRect( aPoint
, aOutputSize
);
1773 Size
aSize(mpViewShell
->GetLocationData().GetNoteInRangeOutputRect(aVisRect
, mbMarkNote
, maCellPos
).GetSize());
1775 aSize
= pWindow
->PixelToLogic(aSize
, mpEditEngine
->GetRefMapMode());
1776 mpEditEngine
->SetPaperSize(aSize
);
1778 mpEditEngine
->SetText( msText
);
1784 mpEditEngine
->SetNotifyHdl( LINK(this, ScAccessibleCellTextData
, NotifyHdl
) );
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
;
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;
1815 ScCsvViewForwarder::ScCsvViewForwarder( Window
* pWindow
, const Rectangle
& rBoundBox
) :
1816 maBoundBox( rBoundBox
),
1821 BOOL
ScCsvViewForwarder::IsValid() const
1823 return mpWindow
!= NULL
;
1826 Rectangle
ScCsvViewForwarder::GetVisArea() const
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()
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
)
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()
1890 mpEditEngine
->SetPaperSize( maCellSize
);
1891 mpEditEngine
->SetText( maCellText
);
1892 if( !mpTextForwarder
.get() )
1893 mpTextForwarder
.reset( new SvxEditEngineForwarder( *mpEditEngine
) );
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 */ )
1913 // ============================================================================