1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 #include "scitems.hxx"
28 #include <editeng/eeitem.hxx>
29 
30 
31 #include <memory>
32 #include "AccessibleText.hxx"
33 #include "AccessibleCell.hxx"
34 #include "tabvwsh.hxx"
35 #include "editutil.hxx"
36 #include "document.hxx"
37 #include "scmod.hxx"
38 #include "prevwsh.hxx"
39 #include "docsh.hxx"
40 #include "prevloc.hxx"
41 #include "unoguard.hxx"
42 #include "patattr.hxx"
43 #include "inputwin.hxx"
44 #include <editeng/unofored.hxx>
45 #include <editeng/editview.hxx>
46 #include <editeng/unoedhlp.hxx>
47 #include <vcl/virdev.hxx>
48 #include <editeng/editobj.hxx>
49 #include <editeng/adjitem.hxx>
50 #include <svx/svdmodel.hxx>
51 #include <svx/algitem.hxx>
52 
53 
54 // ============================================================================
55 
56 class ScViewForwarder : public SvxViewForwarder
57 {
58 	ScTabViewShell*		mpViewShell;
59 	ScAddress			maCellPos;
60 	ScSplitPos			meSplitPos;
61 public:
62 						ScViewForwarder(ScTabViewShell* pViewShell, ScSplitPos eSplitPos, const ScAddress& rCell);
63 	virtual				~ScViewForwarder();
64 
65 	virtual sal_Bool		IsValid() const;
66     virtual Rectangle	GetVisArea() const;
67     virtual Point		LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const;
68     virtual Point		PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const;
69 
70     void                SetInvalid();
71 };
72 
73 ScViewForwarder::ScViewForwarder(ScTabViewShell* pViewShell, ScSplitPos eSplitPos, const ScAddress& rCell)
74 	:
75 	mpViewShell(pViewShell),
76 	maCellPos(rCell),
77 	meSplitPos(eSplitPos)
78 {
79 }
80 
81 ScViewForwarder::~ScViewForwarder()
82 {
83 }
84 
85 sal_Bool ScViewForwarder::IsValid() const
86 {
87 	return mpViewShell != NULL;
88 }
89 
90 Rectangle ScViewForwarder::GetVisArea() const
91 {
92 	Rectangle aVisArea;
93 	if (mpViewShell)
94 	{
95 		Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
96 		if (pWindow)
97 		{
98 			aVisArea.SetSize(pWindow->GetSizePixel());
99 
100 			ScHSplitPos eWhichH = ((meSplitPos == SC_SPLIT_TOPLEFT) || (meSplitPos == SC_SPLIT_BOTTOMLEFT)) ?
101 									SC_SPLIT_LEFT : SC_SPLIT_RIGHT;
102 			ScVSplitPos eWhichV = ((meSplitPos == SC_SPLIT_TOPLEFT) || (meSplitPos == SC_SPLIT_TOPRIGHT)) ?
103 									SC_SPLIT_TOP : SC_SPLIT_BOTTOM;
104 
105 			Point aBaseCellPos(mpViewShell->GetViewData()->GetScrPos(mpViewShell->GetViewData()->GetPosX(eWhichH),
106 				mpViewShell->GetViewData()->GetPosY(eWhichV), meSplitPos, sal_True));
107 			Point aCellPos(mpViewShell->GetViewData()->GetScrPos(maCellPos.Col(), maCellPos.Row(), meSplitPos, sal_True));
108 			aVisArea.SetPos(aCellPos - aBaseCellPos);
109 		}
110 	}
111 	else
112 	{
113 		DBG_ERROR("this ViewForwarder is not valid");
114 	}
115 	return aVisArea;
116 }
117 
118 Point ScViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
119 {
120 	if (mpViewShell)
121 	{
122 		Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
123 		if (pWindow)
124 			return pWindow->LogicToPixel( rPoint, rMapMode );
125 	}
126 	else
127 	{
128 		DBG_ERROR("this ViewForwarder is not valid");
129 	}
130 	return Point();
131 }
132 
133 Point ScViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
134 {
135 	if (mpViewShell)
136 	{
137 		Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
138 		if (pWindow)
139 			return pWindow->PixelToLogic( rPoint, rMapMode );
140 	}
141 	else
142 	{
143 		DBG_ERROR("this ViewForwarder is not valid");
144 	}
145 	return Point();
146 }
147 
148 void ScViewForwarder::SetInvalid()
149 {
150     mpViewShell = NULL;
151 }
152 
153 // ============================================================================
154 
155 class ScEditObjectViewForwarder : public SvxViewForwarder
156 {
157     Window*             mpWindow;
158     // --> OD 2005-12-21 #i49561#
159     // - EditView needed for access to its visible area.
160     const EditView* mpEditView;
161     // <--
162 public:
163                         // --> OD 2005-12-21 #i49561#
164                         ScEditObjectViewForwarder( Window* pWindow,
165                                                    const EditView* _pEditView);
166                         // <--
167 	virtual				~ScEditObjectViewForwarder();
168 
169 	virtual sal_Bool		IsValid() const;
170     virtual Rectangle	GetVisArea() const;
171     virtual Point		LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const;
172     virtual Point		PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const;
173 
174     void                SetInvalid();
175 };
176 
177 // --> OD 2005-12-21 #i49561#
178 ScEditObjectViewForwarder::ScEditObjectViewForwarder( Window* pWindow,
179                                                       const EditView* _pEditView )
180 	:
181     mpWindow(pWindow),
182     mpEditView( _pEditView )
183 {
184 }
185 // <--
186 
187 ScEditObjectViewForwarder::~ScEditObjectViewForwarder()
188 {
189 }
190 
191 sal_Bool ScEditObjectViewForwarder::IsValid() const
192 {
193 	return (mpWindow != NULL);
194 }
195 
196 Rectangle ScEditObjectViewForwarder::GetVisArea() const
197 {
198 	Rectangle aVisArea;
199 	if (mpWindow)
200 	{
201         Rectangle aVisRect(mpWindow->GetWindowExtentsRelative(mpWindow->GetAccessibleParentWindow()));
202 
203         aVisRect.SetPos(Point(0, 0));
204 
205         aVisArea = aVisRect;
206 	}
207 	else
208 	{
209 		DBG_ERROR("this ViewForwarder is not valid");
210 	}
211 	return aVisArea;
212 }
213 
214 Point ScEditObjectViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
215 {
216     if (mpWindow)
217     {
218         // --> OD 2005-12-21 #i49561# - consider offset of the visible area
219         // of the EditView before converting point to pixel.
220         Point aPoint( rPoint );
221         if ( mpEditView )
222         {
223             Rectangle aEditViewVisArea( mpEditView->GetVisArea() );
224             aPoint += aEditViewVisArea.TopLeft();
225         }
226         return mpWindow->LogicToPixel( aPoint, rMapMode );
227         // <--
228     }
229 	else
230 	{
231 		DBG_ERROR("this ViewForwarder is not valid");
232 	}
233 	return Point();
234 }
235 
236 Point ScEditObjectViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
237 {
238 	if (mpWindow)
239     {
240         // --> OD 2005-12-21 #i49561# - consider offset of the visible area
241         // of the EditView after converting point to logic.
242         Point aPoint( mpWindow->PixelToLogic( rPoint, rMapMode ) );
243         if ( mpEditView )
244         {
245             Rectangle aEditViewVisArea( mpEditView->GetVisArea() );
246             aPoint -= aEditViewVisArea.TopLeft();
247         }
248         return aPoint;
249         // <--
250     }
251 	else
252 	{
253 		DBG_ERROR("this ViewForwarder is not valid");
254 	}
255 	return Point();
256 }
257 
258 void ScEditObjectViewForwarder::SetInvalid()
259 {
260     mpWindow = NULL;
261 }
262 
263 // ============================================================================
264 
265 class ScPreviewViewForwarder : public SvxViewForwarder
266 {
267 protected:
268 	ScPreviewShell*		mpViewShell;
269 	mutable ScPreviewTableInfo*	mpTableInfo;
270 public:
271 						ScPreviewViewForwarder(ScPreviewShell* pViewShell);
272 	virtual				~ScPreviewViewForwarder();
273 
274 	virtual sal_Bool		IsValid() const;
275     virtual Rectangle	GetVisArea() const;
276     virtual Point		LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const;
277     virtual Point		PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const;
278 
279     void                SetInvalid();
280 
281     Rectangle GetVisRect() const;
282 
283     // clips the VisArea and calculates with the negativ coordinates
284     Rectangle CorrectVisArea(const Rectangle& rVisArea) const;
285 };
286 
287 ScPreviewViewForwarder::ScPreviewViewForwarder(ScPreviewShell* pViewShell)
288 	:
289 	mpViewShell(pViewShell),
290 	mpTableInfo(NULL)
291 {
292 }
293 
294 ScPreviewViewForwarder::~ScPreviewViewForwarder()
295 {
296 	delete mpTableInfo;
297 }
298 
299 sal_Bool ScPreviewViewForwarder::IsValid() const
300 {
301 	return mpViewShell != NULL;
302 }
303 
304 Rectangle ScPreviewViewForwarder::GetVisArea() const
305 {
306 	Rectangle aVisArea;
307 	DBG_ERROR("should be implemented in an abrevated class");
308 	return aVisArea;
309 }
310 
311 Point ScPreviewViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
312 {
313 	if (mpViewShell)
314 	{
315 		Window* pWindow = mpViewShell->GetWindow();
316 		if (pWindow)
317         {
318             MapMode aMapMode(pWindow->GetMapMode().GetMapUnit());
319             Point aPoint2( OutputDevice::LogicToLogic( rPoint, rMapMode, aMapMode) );
320             return pWindow->LogicToPixel(aPoint2);
321         }
322 	}
323 	else
324 	{
325 		DBG_ERROR("this ViewForwarder is not valid");
326 	}
327 	return Point();
328 }
329 
330 Point ScPreviewViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
331 {
332 	if (mpViewShell)
333 	{
334 		Window* pWindow = mpViewShell->GetWindow();
335 		if (pWindow)
336         {
337             MapMode aMapMode(pWindow->GetMapMode());
338             aMapMode.SetOrigin(Point());
339             Point aPoint1( pWindow->PixelToLogic( rPoint ) );
340             Point aPoint2( OutputDevice::LogicToLogic( aPoint1,
341                                                        aMapMode.GetMapUnit(),
342                                                        rMapMode ) );
343             return aPoint2;
344         }
345 	}
346 	else
347 	{
348 		DBG_ERROR("this ViewForwarder is not valid");
349 	}
350 	return Point();
351 }
352 
353 void ScPreviewViewForwarder::SetInvalid()
354 {
355     mpViewShell = NULL;
356 }
357 
358 Rectangle ScPreviewViewForwarder::GetVisRect() const
359 {
360 	if ( mpViewShell )
361 	{
362 		Size aOutputSize;
363 		Window* pWindow = mpViewShell->GetWindow();
364 		if ( pWindow )
365 			aOutputSize = pWindow->GetOutputSizePixel();
366         Point aPoint;
367 		Rectangle aVisRect( aPoint, aOutputSize );
368         return aVisRect;
369     }
370     return Rectangle();
371 }
372 
373 Rectangle ScPreviewViewForwarder::CorrectVisArea(const Rectangle& rVisArea) const
374 {
375     Rectangle aVisArea(rVisArea);
376     Point aPos = aVisArea.TopLeft(); // get first the position to remember negative positions after clipping
377 
378     Window* pWin = mpViewShell->GetWindow();
379     if (pWin)
380         aVisArea = pWin->GetWindowExtentsRelative(pWin).GetIntersection(aVisArea);
381 
382     sal_Int32 nX(aPos.getX());
383     sal_Int32 nY(aPos.getY());
384 
385     if (nX > 0)
386         nX = 0;
387     else if (nX < 0)
388         nX = -nX;
389     if (nY > 0)
390         nY = 0;
391     else if (nY < 0)
392         nY = -nY;
393     aVisArea.SetPos(Point(nX, nY));
394 
395     return aVisArea;
396 }
397 
398 // ============================================================================
399 
400 class ScPreviewHeaderFooterViewForwarder : public ScPreviewViewForwarder
401 {
402     sal_Bool            mbHeader;
403 public:
404 						ScPreviewHeaderFooterViewForwarder(ScPreviewShell* pViewShell, sal_Bool bHeader);
405 	virtual				~ScPreviewHeaderFooterViewForwarder();
406 
407     virtual Rectangle	GetVisArea() const;
408 };
409 
410 ScPreviewHeaderFooterViewForwarder::ScPreviewHeaderFooterViewForwarder(ScPreviewShell* pViewShell, sal_Bool bHeader)
411 	:
412 	ScPreviewViewForwarder(pViewShell),
413     mbHeader(bHeader)
414 {
415 }
416 
417 ScPreviewHeaderFooterViewForwarder::~ScPreviewHeaderFooterViewForwarder()
418 {
419 }
420 
421 Rectangle ScPreviewHeaderFooterViewForwarder::GetVisArea() const
422 {
423 	Rectangle aVisArea;
424 	if (mpViewShell)
425 	{
426 		const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
427 		if ( mbHeader )
428 			rData.GetHeaderPosition( aVisArea );
429 		else
430 			rData.GetFooterPosition( aVisArea );
431 
432         aVisArea = CorrectVisArea(aVisArea);
433 	}
434 	else
435 	{
436 		DBG_ERROR("this ViewForwarder is not valid");
437 	}
438 	return aVisArea;
439 }
440 
441 // ============================================================================
442 
443 class ScPreviewCellViewForwarder : public ScPreviewViewForwarder
444 {
445     ScAddress           maCellPos;
446 public:
447 						ScPreviewCellViewForwarder(ScPreviewShell* pViewShell,
448                             ScAddress aCellPos);
449 	virtual				~ScPreviewCellViewForwarder();
450 
451     virtual Rectangle	GetVisArea() const;
452 };
453 
454 ScPreviewCellViewForwarder::ScPreviewCellViewForwarder(ScPreviewShell* pViewShell,
455                                                        ScAddress aCellPos)
456 	:
457 	ScPreviewViewForwarder(pViewShell),
458     maCellPos(aCellPos)
459 {
460 }
461 
462 ScPreviewCellViewForwarder::~ScPreviewCellViewForwarder()
463 {
464 }
465 
466 Rectangle ScPreviewCellViewForwarder::GetVisArea() const
467 {
468 	Rectangle aVisArea;
469 	if (mpViewShell)
470 	{
471 		const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
472         aVisArea = rData.GetCellOutputRect(maCellPos);
473 
474         aVisArea = CorrectVisArea(aVisArea);
475 	}
476 	else
477 	{
478 		DBG_ERROR("this ViewForwarder is not valid");
479 	}
480 	return aVisArea;
481 }
482 
483 // ============================================================================
484 
485 class ScPreviewHeaderCellViewForwarder : public ScPreviewViewForwarder
486 {
487     ScAddress           maCellPos;
488     sal_Bool            mbColHeader;
489     sal_Bool            mbRowHeader;
490 public:
491 						ScPreviewHeaderCellViewForwarder(ScPreviewShell* pViewShell,
492                             ScAddress aCellPos,
493                             sal_Bool bColHeader, sal_Bool bRowHeader);
494 	virtual				~ScPreviewHeaderCellViewForwarder();
495 
496     virtual Rectangle	GetVisArea() const;
497 };
498 
499 ScPreviewHeaderCellViewForwarder::ScPreviewHeaderCellViewForwarder(ScPreviewShell* pViewShell,
500                                                                    ScAddress aCellPos,
501                                                                    sal_Bool bColHeader, sal_Bool bRowHeader)
502 	:
503 	ScPreviewViewForwarder(pViewShell),
504     maCellPos(aCellPos),
505     mbColHeader(bColHeader),
506     mbRowHeader(bRowHeader)
507 {
508 }
509 
510 ScPreviewHeaderCellViewForwarder::~ScPreviewHeaderCellViewForwarder()
511 {
512 }
513 
514 Rectangle ScPreviewHeaderCellViewForwarder::GetVisArea() const
515 {
516 	Rectangle aVisArea;
517 	if (mpViewShell)
518 	{
519 		const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
520         aVisArea = rData.GetHeaderCellOutputRect(GetVisRect(), maCellPos, mbColHeader);
521 
522         aVisArea = CorrectVisArea(aVisArea);
523     }
524 	else
525 	{
526 		DBG_ERROR("this ViewForwarder is not valid");
527 	}
528 	return aVisArea;
529 }
530 
531 // ============================================================================
532 
533 class ScPreviewNoteViewForwarder : public ScPreviewViewForwarder
534 {
535     ScAddress           maCellPos;
536     sal_Bool            mbNoteMark;
537 public:
538 						ScPreviewNoteViewForwarder(ScPreviewShell* pViewShell,
539                             ScAddress aCellPos,
540                             sal_Bool bNoteMark);
541 	virtual				~ScPreviewNoteViewForwarder();
542 
543     virtual Rectangle	GetVisArea() const;
544 };
545 
546 ScPreviewNoteViewForwarder::ScPreviewNoteViewForwarder(ScPreviewShell* pViewShell,
547                                                                    ScAddress aCellPos,
548                                                                    sal_Bool bNoteMark)
549 	:
550 	ScPreviewViewForwarder(pViewShell),
551     maCellPos(aCellPos),
552     mbNoteMark(bNoteMark)
553 {
554 }
555 
556 ScPreviewNoteViewForwarder::~ScPreviewNoteViewForwarder()
557 {
558 }
559 
560 Rectangle ScPreviewNoteViewForwarder::GetVisArea() const
561 {
562 	Rectangle aVisArea;
563 	if (mpViewShell)
564 	{
565 		const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
566         aVisArea = rData.GetNoteInRangeOutputRect(GetVisRect(), mbNoteMark, maCellPos);
567 
568         aVisArea = CorrectVisArea(aVisArea);
569     }
570 	else
571 	{
572 		DBG_ERROR("this ViewForwarder is not valid");
573 	}
574 	return aVisArea;
575 }
576 
577 // ============================================================================
578 
579 class ScEditViewForwarder : public SvxEditViewForwarder
580 {
581     EditView*           mpEditView;
582     Window*             mpWindow;
583 public:
584 						ScEditViewForwarder(EditView* pEditView, Window* pWin);
585 	virtual				~ScEditViewForwarder();
586 
587 	virtual sal_Bool		IsValid() const;
588     virtual Rectangle	GetVisArea() const;
589     virtual Point		LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const;
590     virtual Point		PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const;
591     virtual sal_Bool	GetSelection( ESelection& rSelection ) const;
592     virtual sal_Bool	SetSelection( const ESelection& rSelection );
593     virtual sal_Bool	Copy();
594     virtual sal_Bool	Cut();
595     virtual sal_Bool	Paste();
596 
597 	void				GrabFocus();
598 
599     void                SetInvalid();
600 };
601 
602 ScEditViewForwarder::ScEditViewForwarder(EditView* pEditView, Window* pWin)
603 	: mpEditView(pEditView),
604     mpWindow(pWin)
605 {
606 	GrabFocus();
607 }
608 
609 ScEditViewForwarder::~ScEditViewForwarder()
610 {
611 }
612 
613 sal_Bool ScEditViewForwarder::IsValid() const
614 {
615 	sal_Bool bResult(sal_False);
616 	if (mpWindow && mpEditView)
617 	{
618 		bResult = sal_True;
619 	}
620 	return bResult;
621 }
622 
623 Rectangle ScEditViewForwarder::GetVisArea() const
624 {
625 	Rectangle aVisArea;
626 	if (IsValid() && mpEditView->GetEditEngine())
627 	{
628 		MapMode aMapMode(mpEditView->GetEditEngine()->GetRefMapMode());
629 
630         aVisArea = mpWindow->LogicToPixel( mpEditView->GetVisArea(), aMapMode );
631 	}
632 	else
633 	{
634 		DBG_ERROR("this EditViewForwarder is no longer valid");
635 	}
636 	return aVisArea;
637 }
638 
639 Point ScEditViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
640 {
641 	if (mpWindow)
642 		return mpWindow->LogicToPixel( rPoint, rMapMode );
643 	else
644 	{
645 		DBG_ERROR("this ViewForwarder is not valid");
646 	}
647 	return Point();
648 }
649 
650 Point ScEditViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
651 {
652 	if (mpWindow)
653 		return mpWindow->PixelToLogic( rPoint, rMapMode );
654 	else
655 	{
656 		DBG_ERROR("this ViewForwarder is not valid");
657 	}
658 	return Point();
659 }
660 
661 sal_Bool ScEditViewForwarder::GetSelection( ESelection& rSelection ) const
662 {
663 	sal_Bool bResult(sal_False);
664 	if (IsValid())
665 	{
666 		rSelection = mpEditView->GetSelection();
667 		bResult = sal_True;
668 	}
669 	else
670 	{
671 		DBG_ERROR("this ViewForwarder is not valid");
672 	}
673 	return bResult;
674 }
675 
676 sal_Bool ScEditViewForwarder::SetSelection( const ESelection& rSelection )
677 {
678 	sal_Bool bResult(sal_False);
679 	if (IsValid())
680 	{
681 		mpEditView->SetSelection(rSelection);
682 		bResult = sal_True;
683 	}
684 	else
685 	{
686 		DBG_ERROR("this ViewForwarder is not valid");
687 	}
688 	return bResult;
689 }
690 
691 sal_Bool ScEditViewForwarder::Copy()
692 {
693 	sal_Bool bResult(sal_False);
694 	if (IsValid())
695 	{
696 		mpEditView->Copy();
697 		bResult = sal_True;
698 	}
699 	else
700 	{
701 		DBG_ERROR("this ViewForwarder is not valid");
702 	}
703 	return bResult;
704 }
705 
706 sal_Bool ScEditViewForwarder::Cut()
707 {
708 	sal_Bool bResult(sal_False);
709 	if (IsValid())
710 	{
711 		mpEditView->Cut();
712 		bResult = sal_True;
713 	}
714 	else
715 	{
716 		DBG_ERROR("this ViewForwarder is not valid");
717 	}
718 	return bResult;
719 }
720 
721 sal_Bool ScEditViewForwarder::Paste()
722 {
723 	sal_Bool bResult(sal_False);
724 	if (IsValid())
725 	{
726 		mpEditView->Paste();
727 		bResult = sal_True;
728 	}
729 	else
730 	{
731 		DBG_ERROR("this ViewForwarder is not valid");
732 	}
733 	return bResult;
734 }
735 
736 void ScEditViewForwarder::GrabFocus()
737 {
738 }
739 
740 void ScEditViewForwarder::SetInvalid()
741 {
742     mpWindow = NULL;
743     mpEditView = NULL;
744 }
745 
746 // ============================================================================
747 
748 //	ScAccessibleCellTextData: shared data between sub objects of a accessible cell text object
749 
750 ScAccessibleCellTextData::ScAccessibleCellTextData(ScTabViewShell* pViewShell,
751         const ScAddress& rP, ScSplitPos eSplitPos, ScAccessibleCell* pAccCell)
752 	: ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
753 	mpViewForwarder(NULL),
754 	mpEditViewForwarder(NULL),
755 	mpViewShell(pViewShell),
756 	meSplitPos(eSplitPos),
757     mbViewEditEngine(sal_False),
758     mpAccessibleCell( pAccCell )
759 {
760 }
761 
762 ScAccessibleCellTextData::~ScAccessibleCellTextData()
763 {
764     if (pEditEngine)
765         pEditEngine->SetNotifyHdl(Link());
766 	if (mpViewForwarder)
767 		delete mpViewForwarder;
768 	if (mpEditViewForwarder)
769 		delete mpEditViewForwarder;
770 }
771 
772 void ScAccessibleCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
773 {
774 	if ( rHint.ISA( SfxSimpleHint ) )
775 	{
776 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
777 		if ( nId == SFX_HINT_DYING )
778 		{
779 			mpViewShell = NULL;						// invalid now
780             if (mpViewForwarder)
781                 mpViewForwarder->SetInvalid();
782             if (mpEditViewForwarder)
783                 mpEditViewForwarder->SetInvalid();
784 		}
785 	}
786 	ScAccessibleCellBaseTextData::Notify(rBC, rHint);
787 }
788 
789 ScAccessibleTextData* ScAccessibleCellTextData::Clone() const
790 {
791     return new ScAccessibleCellTextData( mpViewShell, aCellPos, meSplitPos, mpAccessibleCell );
792 }
793 
794 void ScAccessibleCellTextData::GetCellText(const ScAddress& rCellPos, String& rText)
795 {
796 //  #104893#; don't use the input string
797 //    ScCellTextData::GetCellText(rCellPos, rText);
798     ScDocument* pDoc = pDocShell->GetDocument();
799     if (pDoc)
800     {
801         //  #104893#; use the displayed string
802         pDoc->GetString(rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), rText);
803         if (mpViewShell)
804         {
805             const ScViewOptions& aOptions = mpViewShell->GetViewData()->GetOptions();
806             CellType aCellType;
807             pDoc->GetCellType(rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), aCellType);
808             if (aCellType == CELLTYPE_FORMULA && aOptions.GetOption( VOPT_FORMULAS ))
809             {
810                 pDoc->GetFormula( rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), rText);
811             }
812             else if (!aOptions.GetOption( VOPT_NULLVALS ))
813             {
814                 if ((aCellType == CELLTYPE_VALUE || aCellType == CELLTYPE_FORMULA) && pDoc->GetValue(rCellPos) == 0.0)
815                     rText.Erase();
816             }
817         }
818     }
819 }
820 
821 SvxTextForwarder* ScAccessibleCellTextData::GetTextForwarder()
822 {
823 /*	sal_Bool bHasForwarder(sal_False);
824 	if (mpViewShell && mpViewShell->GetViewData() &&
825 		(mpViewShell->GetViewData()->GetCurPos() == aCellPos) &&
826 		(mpViewShell->GetViewData()->HasEditView(meSplitPos)) &&
827 		(mpViewShell->GetViewData()->GetEditViewCol() == aCellPos.Col()) &&
828 		(mpViewShell->GetViewData()->GetEditViewRow() == aCellPos.Row()))
829 	{
830 		if (!mbViewEditEngine)
831 		{
832 			if (pForwarder)
833 				DELETEZ( pForwarder );
834 			if (pEditEngine)
835 				DELETEZ( pEditEngine );
836 
837                 SCCOL nCol;
838                 SCROW nRow;
839                 EditView* pEditView;
840 			mpViewShell->GetViewData()->GetEditView( meSplitPos, pEditView, nCol, nRow );
841 			if (pEditView)
842 			{
843                 pEditEngine = (ScFieldEditEngine*)pEditView->GetEditEngine();
844 				pForwarder = new SvxEditEngineForwarder(*pEditEngine);
845 				bHasForwarder = sal_True;
846 			}
847 		}
848 		else
849 			bHasForwarder = sal_True;
850 	}
851 	else if (mbViewEditEngine)
852 	{
853 		// remove Forwarder created with EditEngine from EditView
854 		if (pForwarder)
855 			DELETEZ( pForwarder );
856         pEditEngine->SetNotifyHdl(Link());
857 		// don't delete, because it is the EditEngine of the EditView
858 		pEditEngine = NULL;
859         mbViewEditEngine = sal_False;
860 	}
861 
862 	if (!bHasForwarder)*/
863 		ScCellTextData::GetTextForwarder(); // creates Forwarder and EditEngine
864 
865     ScDocument* pDoc = ( pDocShell ? pDocShell->GetDocument() : NULL );
866     if ( pDoc && pEditEngine && mpViewShell )
867 	{
868 		long nSizeX, nSizeY;
869 		mpViewShell->GetViewData()->GetMergeSizePixel(
870 			aCellPos.Col(), aCellPos.Row(), nSizeX, nSizeY);
871 
872 		Size aSize(nSizeX, nSizeY);
873 
874         // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
875         long nIndent = 0;
876         const SvxHorJustifyItem* pHorJustifyItem = static_cast< const SvxHorJustifyItem* >(
877             pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_HOR_JUSTIFY ) );
878         SvxCellHorJustify eHorJust = ( pHorJustifyItem ? static_cast< SvxCellHorJustify >( pHorJustifyItem->GetValue() ) : SVX_HOR_JUSTIFY_STANDARD );
879         if ( eHorJust == SVX_HOR_JUSTIFY_LEFT )
880         {
881             const SfxUInt16Item* pIndentItem = static_cast< const SfxUInt16Item* >(
882                 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_INDENT ) );
883             if ( pIndentItem )
884             {
885                 nIndent = static_cast< long >( pIndentItem->GetValue() );
886             }
887         }
888 
889         const SvxMarginItem* pMarginItem = static_cast< const SvxMarginItem* >(
890             pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_MARGIN ) );
891         ScViewData* pViewData = mpViewShell->GetViewData();
892         double nPPTX = ( pViewData ? pViewData->GetPPTX() : 0 );
893         double nPPTY = ( pViewData ? pViewData->GetPPTY() : 0 );
894         long nLeftM = ( pMarginItem ? static_cast< long >( ( pMarginItem->GetLeftMargin() + nIndent ) * nPPTX ) : 0 );
895         long nTopM = ( pMarginItem ? static_cast< long >( pMarginItem->GetTopMargin() * nPPTY ) : 0 );
896         long nRightM = ( pMarginItem ? static_cast< long >( pMarginItem->GetRightMargin() * nPPTX ) : 0 );
897         long nBottomM = ( pMarginItem ? static_cast< long >( pMarginItem->GetBottomMargin() * nPPTY ) : 0 );
898         long nWidth = aSize.getWidth() - nLeftM - nRightM;
899         aSize.setWidth( nWidth );
900         aSize.setHeight( aSize.getHeight() - nTopM - nBottomM );
901 
902         Window* pWin = mpViewShell->GetWindowByPos( meSplitPos );
903         if ( pWin )
904         {
905             aSize = pWin->PixelToLogic( aSize, pEditEngine->GetRefMapMode() );
906         }
907 
908         /*  #i19430# Gnopernicus reads text partly if it sticks out of the cell
909             boundaries. This leads to wrong results in cases where the cell text
910             is rotated, because rotation is not taken into account when calcu-
911             lating the visible part of the text. In these cases we will expand
912             the cell size passed as paper size to the edit engine. The function
913             accessibility::AccessibleStaticTextBase::GetParagraphBoundingBox()
914             (see svx/source/accessibility/AccessibleStaticTextBase.cxx) will
915             return the size of the complete text then, which is used to expand
916             the cell bounding box in ScAccessibleCell::GetBoundingBox()
917             (see sc/source/ui/Accessibility/AccessibleCell.cxx). */
918         const SfxInt32Item* pItem = static_cast< const SfxInt32Item* >(
919             pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_ROTATE_VALUE ) );
920         if( pItem && (pItem->GetValue() != 0) )
921         {
922             pEditEngine->SetPaperSize( Size( LONG_MAX, aSize.getHeight() ) );
923             long nTxtWidth = static_cast< long >( pEditEngine->CalcTextWidth() );
924             aSize.setWidth( std::max( aSize.getWidth(), nTxtWidth + 2 ) );
925         }
926         else
927         {
928             // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
929             const SfxBoolItem* pLineBreakItem = static_cast< const SfxBoolItem* >(
930                 pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_LINEBREAK ) );
931             bool bLineBreak = ( pLineBreakItem && pLineBreakItem->GetValue() );
932             if ( !bLineBreak )
933             {
934                 long nTxtWidth = static_cast< long >( pEditEngine->CalcTextWidth() );
935                 aSize.setWidth( ::std::max( aSize.getWidth(), nTxtWidth ) );
936             }
937         }
938 
939         pEditEngine->SetPaperSize( aSize );
940 
941         // #i92143# text getRangeExtents reports incorrect 'x' values for spreadsheet cells
942         if ( eHorJust == SVX_HOR_JUSTIFY_STANDARD && pDoc->HasValueData( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ) )
943         {
944             pEditEngine->SetDefaultItem( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
945         }
946 
947         Size aTextSize;
948         if ( pWin )
949         {
950             aTextSize = pWin->LogicToPixel( Size( pEditEngine->CalcTextWidth(), pEditEngine->GetTextHeight() ), pEditEngine->GetRefMapMode() );
951         }
952         long nTextWidth = aTextSize.Width();
953         long nTextHeight = aTextSize.Height();
954 
955         long nOffsetX = nLeftM;
956         long nDiffX = nTextWidth - nWidth;
957         if ( nDiffX > 0 )
958         {
959             switch ( eHorJust )
960             {
961                 case SVX_HOR_JUSTIFY_RIGHT:
962                     {
963                         nOffsetX -= nDiffX;
964                     }
965                     break;
966                 case SVX_HOR_JUSTIFY_CENTER:
967                     {
968                         nOffsetX -= nDiffX / 2;
969                     }
970                     break;
971                 default:
972                     {
973                     }
974                     break;
975             }
976         }
977 
978         long nOffsetY = 0;
979         const SvxVerJustifyItem* pVerJustifyItem = static_cast< const SvxVerJustifyItem* >(
980             pDoc->GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_VER_JUSTIFY ) );
981         SvxCellVerJustify eVerJust = ( pVerJustifyItem ? static_cast< SvxCellVerJustify >( pVerJustifyItem->GetValue() ) : SVX_VER_JUSTIFY_STANDARD );
982         switch ( eVerJust )
983         {
984             case SVX_VER_JUSTIFY_STANDARD:
985             case SVX_VER_JUSTIFY_BOTTOM:
986                 {
987                     nOffsetY = nSizeY - nBottomM - nTextHeight;
988                 }
989                 break;
990             case SVX_VER_JUSTIFY_CENTER:
991                 {
992                     nOffsetY = ( nSizeY - nTopM - nBottomM - nTextHeight ) / 2 + nTopM;
993                 }
994                 break;
995             default:
996                 {
997                     nOffsetY = nTopM;
998                 }
999                 break;
1000         }
1001 
1002         if ( mpAccessibleCell )
1003         {
1004             mpAccessibleCell->SetOffset( Point( nOffsetX, nOffsetY ) );
1005         }
1006 
1007 		pEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1008 	}
1009 
1010 	return pForwarder;
1011 }
1012 
1013 SvxViewForwarder* ScAccessibleCellTextData::GetViewForwarder()
1014 {
1015 	if (!mpViewForwarder)
1016 		mpViewForwarder = new ScViewForwarder(mpViewShell, meSplitPos, aCellPos);
1017 	return mpViewForwarder;
1018 }
1019 
1020 SvxEditViewForwarder* ScAccessibleCellTextData::GetEditViewForwarder( sal_Bool /* bCreate */ )
1021 {
1022     //#102219#; there should no EditViewForwarder be, because the cell is now readonly in this interface
1023 /*	if (!mpEditViewForwarder)
1024     {
1025         SCCOL nCol;
1026         SCROW nRow;
1027         EditView* pEditView;
1028 		mpViewShell->GetViewData()->GetEditView( meSplitPos, pEditView, nCol, nRow );
1029 
1030 		mpEditViewForwarder = new ScEditViewForwarder(pEditView, mpViewShell->GetWindowByPos(meSplitPos));
1031     }
1032 	else if (bCreate)
1033 		mpEditViewForwarder->GrabFocus();
1034 	return mpEditViewForwarder;*/
1035     return NULL;
1036 }
1037 
1038 IMPL_LINK(ScAccessibleCellTextData, NotifyHdl, EENotify*, aNotify)
1039 {
1040     if( aNotify )
1041     {
1042         ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify );
1043 
1044         if( aHint.get() )
1045             GetBroadcaster().Broadcast( *aHint.get() );
1046     }
1047 
1048     return 0;
1049 }
1050 
1051 ScDocShell* ScAccessibleCellTextData::GetDocShell(ScTabViewShell* pViewShell)
1052 {
1053 	ScDocShell* pDocSh = NULL;
1054 	if (pViewShell)
1055 		pDocSh = pViewShell->GetViewData()->GetDocShell();
1056 	return pDocSh;
1057 }
1058 
1059 
1060 // ============================================================================
1061 //IAccessibility2 Implementation 2009-----
1062 //ScAccessibleEditObjectTextData::ScAccessibleEditObjectTextData(EditView* pEditView, Window* pWin)
1063 ScAccessibleEditObjectTextData::ScAccessibleEditObjectTextData(EditView* pEditView, Window* pWin, sal_Bool isClone)
1064 //-----IAccessibility2 Implementation 2009
1065 	:
1066 	mpViewForwarder(NULL),
1067 	mpEditViewForwarder(NULL),
1068     mpEditView(pEditView),
1069     mpEditEngine(pEditView ? pEditView->GetEditEngine() : 0),
1070     mpForwarder(NULL),
1071     mpWindow(pWin)
1072 {
1073 //IAccessibility2 Implementation 2009-----
1074 	// Solution: If the object is cloned, do NOT add notify hdl.
1075 	mbIsCloned = isClone;
1076     //if (mpEditEngine)
1077     if (mpEditEngine && !mbIsCloned)
1078 //-----IAccessibility2 Implementation 2009
1079         mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
1080 }
1081 
1082 ScAccessibleEditObjectTextData::~ScAccessibleEditObjectTextData()
1083 {
1084 //IAccessibility2 Implementation 2009-----
1085 	// Solution: If the object is cloned, do NOT set notify hdl.
1086     //if (mpEditEngine)
1087     if (mpEditEngine && !mbIsCloned)
1088 //-----IAccessibility2 Implementation 2009
1089         mpEditEngine->SetNotifyHdl(Link());
1090 	if (mpViewForwarder)
1091 		delete mpViewForwarder;
1092 	if (mpEditViewForwarder)
1093 		delete mpEditViewForwarder;
1094     if (mpForwarder)
1095         delete mpForwarder;
1096 }
1097 
1098 void ScAccessibleEditObjectTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1099 {
1100 	if ( rHint.ISA( SfxSimpleHint ) )
1101 	{
1102 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1103 		if ( nId == SFX_HINT_DYING )
1104 		{
1105             mpWindow = NULL;
1106             mpEditView = NULL;
1107             mpEditEngine = NULL;
1108             DELETEZ(mpForwarder);
1109         	if (mpViewForwarder)
1110             	mpViewForwarder->SetInvalid();
1111 	        if (mpEditViewForwarder)
1112             	mpEditViewForwarder->SetInvalid();
1113 		}
1114 	}
1115 	ScAccessibleTextData::Notify(rBC, rHint);
1116 }
1117 
1118 ScAccessibleTextData* ScAccessibleEditObjectTextData::Clone() const
1119 {
1120 //IAccessibility2 Implementation 2009-----
1121 	// Solution: Add para to indicate the object is cloned
1122 	//return new ScAccessibleEditObjectTextData(mpEditView, mpWindow);
1123 	return new ScAccessibleEditObjectTextData(mpEditView, mpWindow,sal_True);
1124 //-----IAccessibility2 Implementation 2009
1125 }
1126 
1127 SvxTextForwarder* ScAccessibleEditObjectTextData::GetTextForwarder()
1128 {
1129 	if ((!mpForwarder && mpEditView) || (mpEditEngine && !mpEditEngine->GetNotifyHdl().IsSet()))
1130 	{
1131         if (!mpEditEngine)
1132             mpEditEngine = mpEditView->GetEditEngine();
1133 //IAccessibility2 Implementation 2009-----
1134 			// Solution: If the object is cloned, do NOT add notify hdl.
1135         //if (mpEditEngine && !mpEditEngine->GetNotifyHdl().IsSet())
1136 	if (mpEditEngine && !mpEditEngine->GetNotifyHdl().IsSet()&&!mbIsCloned)
1137 //-----IAccessibility2 Implementation 2009
1138             mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
1139         if(!mpForwarder)
1140             mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1141 	}
1142 	return mpForwarder;
1143 }
1144 
1145 SvxViewForwarder* ScAccessibleEditObjectTextData::GetViewForwarder()
1146 {
1147 	if (!mpViewForwarder)
1148     {
1149         // --> OD 2005-12-21 #i49561#
1150         mpViewForwarder = new ScEditObjectViewForwarder( mpWindow, mpEditView );
1151         // <--
1152     }
1153 	return mpViewForwarder;
1154 }
1155 
1156 SvxEditViewForwarder* ScAccessibleEditObjectTextData::GetEditViewForwarder( sal_Bool bCreate )
1157 {
1158     if (!mpEditViewForwarder && mpEditView)
1159 		mpEditViewForwarder = new ScEditViewForwarder(mpEditView, mpWindow);
1160 	if (bCreate)
1161 	{
1162         if (!mpEditView && mpEditViewForwarder)
1163         {
1164             DELETEZ(mpEditViewForwarder);
1165         }
1166 		else if (mpEditViewForwarder)
1167 			mpEditViewForwarder->GrabFocus();
1168 	}
1169 	return mpEditViewForwarder;
1170 }
1171 
1172 IMPL_LINK(ScAccessibleEditObjectTextData, NotifyHdl, EENotify*, aNotify)
1173 {
1174     if( aNotify )
1175     {
1176         ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify );
1177 
1178         if( aHint.get() )
1179             GetBroadcaster().Broadcast( *aHint.get() );
1180     }
1181 
1182     return 0;
1183 }
1184 
1185 
1186 // ============================================================================
1187 
1188 ScAccessibleEditLineTextData::ScAccessibleEditLineTextData(EditView* pEditView, Window* pWin)
1189     :
1190     ScAccessibleEditObjectTextData(pEditView, pWin),
1191     mbEditEngineCreated(sal_False)
1192 {
1193     ScTextWnd* pTxtWnd = (ScTextWnd*)pWin;
1194 
1195     if (pTxtWnd)
1196         pTxtWnd->InsertAccessibleTextData( *this );
1197 }
1198 
1199 ScAccessibleEditLineTextData::~ScAccessibleEditLineTextData()
1200 {
1201     ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1202 
1203     if (pTxtWnd)
1204         pTxtWnd->RemoveAccessibleTextData( *this );
1205 
1206     if (mbEditEngineCreated && mpEditEngine)
1207     {
1208         delete mpEditEngine;
1209         mpEditEngine = NULL;    // #103346# don't access in ScAccessibleEditObjectTextData dtor!
1210     }
1211     else if (pTxtWnd && pTxtWnd->GetEditView() && pTxtWnd->GetEditView()->GetEditEngine())
1212     {
1213         //  #103346# the NotifyHdl also has to be removed from the ScTextWnd's EditEngine
1214         //  (it's set in ScAccessibleEditLineTextData::GetTextForwarder, and mpEditEngine
1215         //  is reset there)
1216         pTxtWnd->GetEditView()->GetEditEngine()->SetNotifyHdl(Link());
1217     }
1218 }
1219 
1220 void ScAccessibleEditLineTextData::Dispose()
1221 {
1222     ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1223 
1224     if (pTxtWnd)
1225         pTxtWnd->RemoveAccessibleTextData( *this );
1226 
1227     ResetEditMode();
1228     mpWindow = NULL;
1229 }
1230 
1231 ScAccessibleTextData* ScAccessibleEditLineTextData::Clone() const
1232 {
1233     return new ScAccessibleEditLineTextData(mpEditView, mpWindow);
1234 }
1235 
1236 SvxTextForwarder* ScAccessibleEditLineTextData::GetTextForwarder()
1237 {
1238     ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1239 
1240     if (pTxtWnd)
1241     {
1242         mpEditView = pTxtWnd->GetEditView();
1243         if (mpEditView)
1244         {
1245             if (mbEditEngineCreated && mpEditEngine)
1246                 ResetEditMode();
1247             mbEditEngineCreated = sal_False;
1248 
1249             mpEditView = pTxtWnd->GetEditView();
1250             ScAccessibleEditObjectTextData::GetTextForwarder(); // fill the mpForwarder
1251             mpEditEngine = NULL;
1252         }
1253         else
1254         {
1255             if (mpEditEngine && !mbEditEngineCreated)
1256                 ResetEditMode();
1257 	        if (!mpEditEngine)
1258 	        {
1259 			    SfxItemPool* pEnginePool = EditEngine::CreatePool();
1260 			    pEnginePool->FreezeIdRanges();
1261 			    mpEditEngine = new ScFieldEditEngine( pEnginePool, NULL, sal_True );
1262                 mbEditEngineCreated = sal_True;
1263 		        //	currently, GetPortions doesn't work if UpdateMode is sal_False,
1264 		        //	this will be fixed (in EditEngine) by src600
1265         //		pEditEngine->SetUpdateMode( sal_False );
1266 		        mpEditEngine->EnableUndo( sal_False );
1267 			    mpEditEngine->SetRefMapMode( MAP_100TH_MM );
1268 		        mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1269 
1270                 mpEditEngine->SetText(pTxtWnd->GetTextString());
1271 
1272 		        Size aSize(pTxtWnd->GetSizePixel());
1273 
1274 			    aSize = pTxtWnd->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1275 
1276 		        mpEditEngine->SetPaperSize(aSize);
1277 
1278 		        mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleEditObjectTextData, NotifyHdl) );
1279             }
1280         }
1281     }
1282     return mpForwarder;
1283 }
1284 
1285 SvxEditViewForwarder* ScAccessibleEditLineTextData::GetEditViewForwarder( sal_Bool bCreate )
1286 {
1287     ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1288 
1289     if (pTxtWnd)
1290     {
1291         mpEditView = pTxtWnd->GetEditView();
1292         if (!mpEditView && bCreate)
1293         {
1294 	        if ( !pTxtWnd->IsInputActive() )
1295 	        {
1296 		        pTxtWnd->StartEditEngine();
1297 		        pTxtWnd->GrabFocus();
1298 //		        pTxtWnd->SetTextString( rText );
1299 //		        pTxtWnd->GetEditView()->SetSelection( rSel );
1300 
1301                 mpEditView = pTxtWnd->GetEditView();
1302 	        }
1303         }
1304     }
1305 
1306     return ScAccessibleEditObjectTextData::GetEditViewForwarder(bCreate);
1307 }
1308 
1309 void ScAccessibleEditLineTextData::ResetEditMode()
1310 {
1311     ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1312 
1313     if (mbEditEngineCreated && mpEditEngine)
1314         delete mpEditEngine;
1315     else if (pTxtWnd && pTxtWnd->GetEditView() && pTxtWnd->GetEditView()->GetEditEngine())
1316         pTxtWnd->GetEditView()->GetEditEngine()->SetNotifyHdl(Link());
1317     mpEditEngine = NULL;
1318 
1319     DELETEZ(mpForwarder);
1320     DELETEZ(mpEditViewForwarder);
1321     DELETEZ(mpViewForwarder);
1322     mbEditEngineCreated = sal_False;
1323 }
1324 
1325 void ScAccessibleEditLineTextData::TextChanged()
1326 {
1327     if (mbEditEngineCreated && mpEditEngine)
1328     {
1329         ScTextWnd* pTxtWnd = (ScTextWnd*)mpWindow;
1330 
1331         if (pTxtWnd)
1332             mpEditEngine->SetText(pTxtWnd->GetTextString());
1333     }
1334 }
1335 
1336 void ScAccessibleEditLineTextData::StartEdit()
1337 {
1338     ResetEditMode();
1339     mpEditView = NULL;
1340 
1341     // send HINT_BEGEDIT
1342     SdrHint aHint(HINT_BEGEDIT);
1343 	GetBroadcaster().Broadcast( aHint );
1344 }
1345 
1346 void ScAccessibleEditLineTextData::EndEdit()
1347 {
1348     // send HINT_ENDEDIT
1349     SdrHint aHint(HINT_ENDEDIT);
1350 	GetBroadcaster().Broadcast( aHint );
1351 
1352     ResetEditMode();
1353     mpEditView = NULL;
1354 }
1355 
1356 
1357 // ============================================================================
1358 
1359 //	ScAccessiblePreviewCellTextData: shared data between sub objects of a accessible cell text object
1360 
1361 ScAccessiblePreviewCellTextData::ScAccessiblePreviewCellTextData(ScPreviewShell* pViewShell,
1362 							const ScAddress& rP)
1363 	: ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
1364 	mpViewForwarder(NULL),
1365 	mpViewShell(pViewShell)
1366 {
1367 }
1368 
1369 ScAccessiblePreviewCellTextData::~ScAccessiblePreviewCellTextData()
1370 {
1371     if (pEditEngine)
1372         pEditEngine->SetNotifyHdl(Link());
1373 	if (mpViewForwarder)
1374 		delete mpViewForwarder;
1375 }
1376 
1377 void ScAccessiblePreviewCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1378 {
1379 	if ( rHint.ISA( SfxSimpleHint ) )
1380 	{
1381 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1382 		if ( nId == SFX_HINT_DYING )
1383 		{
1384 			mpViewShell = NULL;						// invalid now
1385             if (mpViewForwarder)
1386                 mpViewForwarder->SetInvalid();
1387 		}
1388 	}
1389 	ScAccessibleCellBaseTextData::Notify(rBC, rHint);
1390 }
1391 
1392 ScAccessibleTextData* ScAccessiblePreviewCellTextData::Clone() const
1393 {
1394 	return new ScAccessiblePreviewCellTextData(mpViewShell, aCellPos);
1395 }
1396 
1397 SvxTextForwarder* ScAccessiblePreviewCellTextData::GetTextForwarder()
1398 {
1399 	sal_Bool bEditEngineBefore(pEditEngine != NULL);
1400 
1401 	ScCellTextData::GetTextForwarder(); // creates Forwarder and EditEngine
1402 
1403 	if (!bEditEngineBefore && pEditEngine)
1404 	{
1405 		Size aSize(mpViewShell->GetLocationData().GetCellOutputRect(aCellPos).GetSize());
1406 		Window* pWin = mpViewShell->GetWindow();
1407 		if (pWin)
1408 			aSize = pWin->PixelToLogic(aSize, pEditEngine->GetRefMapMode());
1409 		pEditEngine->SetPaperSize(aSize);
1410 	}
1411 
1412 	if (pEditEngine)
1413 		pEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1414 
1415 	return pForwarder;
1416 }
1417 
1418 SvxViewForwarder* ScAccessiblePreviewCellTextData::GetViewForwarder()
1419 {
1420 	if (!mpViewForwarder)
1421 		mpViewForwarder = new ScPreviewCellViewForwarder(mpViewShell, aCellPos);
1422 	return mpViewForwarder;
1423 }
1424 
1425 //UNUSED2008-05  IMPL_LINK(ScAccessiblePreviewCellTextData, NotifyHdl, EENotify*, aNotify)
1426 //UNUSED2008-05  {
1427 //UNUSED2008-05      if( aNotify )
1428 //UNUSED2008-05      {
1429 //UNUSED2008-05          ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify);
1430 //UNUSED2008-05
1431 //UNUSED2008-05          if( aHint.get() )
1432 //UNUSED2008-05              GetBroadcaster().Broadcast( *aHint.get() );
1433 //UNUSED2008-05      }
1434 //UNUSED2008-05
1435 //UNUSED2008-05      return 0;
1436 //UNUSED2008-05  }
1437 
1438 ScDocShell* ScAccessiblePreviewCellTextData::GetDocShell(ScPreviewShell* pViewShell)
1439 {
1440 	ScDocShell* pDocSh = NULL;
1441 	if (pViewShell && pViewShell->GetDocument())
1442 		pDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1443 	return pDocSh;
1444 }
1445 
1446 
1447 // ============================================================================
1448 
1449 //	ScAccessiblePreviewHeaderCellTextData: shared data between sub objects of a accessible cell text object
1450 
1451 ScAccessiblePreviewHeaderCellTextData::ScAccessiblePreviewHeaderCellTextData(ScPreviewShell* pViewShell,
1452 			const String& rText, const ScAddress& rP, sal_Bool bColHeader, sal_Bool bRowHeader)
1453 	: ScAccessibleCellBaseTextData(GetDocShell(pViewShell), rP),
1454 	mpViewForwarder(NULL),
1455 	mpViewShell(pViewShell),
1456 	maText(rText),
1457 	mbColHeader(bColHeader),
1458 	mbRowHeader(bRowHeader)
1459 {
1460 }
1461 
1462 ScAccessiblePreviewHeaderCellTextData::~ScAccessiblePreviewHeaderCellTextData()
1463 {
1464     if (pEditEngine)
1465         pEditEngine->SetNotifyHdl(Link());
1466 	if (mpViewForwarder)
1467 		delete mpViewForwarder;
1468 }
1469 
1470 void ScAccessiblePreviewHeaderCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1471 {
1472 	if ( rHint.ISA( SfxSimpleHint ) )
1473 	{
1474 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1475 		if ( nId == SFX_HINT_DYING )
1476 		{
1477 			mpViewShell = NULL;						// invalid now
1478             if (mpViewForwarder)
1479                 mpViewForwarder->SetInvalid();
1480 		}
1481 	}
1482 	ScAccessibleCellBaseTextData::Notify(rBC, rHint);
1483 }
1484 
1485 ScAccessibleTextData* ScAccessiblePreviewHeaderCellTextData::Clone() const
1486 {
1487 	return new ScAccessiblePreviewHeaderCellTextData(mpViewShell, maText, aCellPos, mbColHeader, mbRowHeader);
1488 }
1489 
1490 SvxTextForwarder* ScAccessiblePreviewHeaderCellTextData::GetTextForwarder()
1491 {
1492 	if (!pEditEngine)
1493 	{
1494 		if ( pDocShell )
1495 		{
1496 			ScDocument* pDoc = pDocShell->GetDocument();
1497 			pEditEngine = pDoc->CreateFieldEditEngine();
1498 		}
1499 		else
1500 		{
1501 			SfxItemPool* pEnginePool = EditEngine::CreatePool();
1502 			pEnginePool->FreezeIdRanges();
1503 			pEditEngine = new ScFieldEditEngine( pEnginePool, NULL, sal_True );
1504 		}
1505 		//	currently, GetPortions doesn't work if UpdateMode is sal_False,
1506 		//	this will be fixed (in EditEngine) by src600
1507 //		pEditEngine->SetUpdateMode( sal_False );
1508 		pEditEngine->EnableUndo( sal_False );
1509 		if (pDocShell)
1510 			pEditEngine->SetRefDevice(pDocShell->GetRefDevice());
1511 		else
1512 			pEditEngine->SetRefMapMode( MAP_100TH_MM );
1513 		pForwarder = new SvxEditEngineForwarder(*pEditEngine);
1514 	}
1515 
1516 	if (bDataValid)
1517 		return pForwarder;
1518 
1519 	if (maText.Len() && pEditEngine)
1520 	{
1521 
1522 		if ( mpViewShell  )
1523 		{
1524 			Size aOutputSize;
1525 			Window* pWindow = mpViewShell->GetWindow();
1526 			if ( pWindow )
1527 				aOutputSize = pWindow->GetOutputSizePixel();
1528 			Point aPoint;
1529 			Rectangle aVisRect( aPoint, aOutputSize );
1530 			Size aSize(mpViewShell->GetLocationData().GetHeaderCellOutputRect(aVisRect, aCellPos, mbColHeader).GetSize());
1531 			if (pWindow)
1532 				aSize = pWindow->PixelToLogic(aSize, pEditEngine->GetRefMapMode());
1533 			pEditEngine->SetPaperSize(aSize);
1534 		}
1535 		pEditEngine->SetText( maText );
1536 	}
1537 
1538 	bDataValid = sal_True;
1539 
1540 	if (pEditEngine)
1541 		pEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1542 
1543 	return pForwarder;
1544 }
1545 
1546 SvxViewForwarder* ScAccessiblePreviewHeaderCellTextData::GetViewForwarder()
1547 {
1548 	if (!mpViewForwarder)
1549 		mpViewForwarder = new ScPreviewHeaderCellViewForwarder(mpViewShell, aCellPos, mbColHeader, mbRowHeader);
1550 	return mpViewForwarder;
1551 }
1552 
1553 //UNUSED2008-05  IMPL_LINK(ScAccessiblePreviewHeaderCellTextData, NotifyHdl, EENotify*, aNotify)
1554 //UNUSED2008-05  {
1555 //UNUSED2008-05      if( aNotify )
1556 //UNUSED2008-05      {
1557 //UNUSED2008-05          ::std::auto_ptr< SfxHint > aHint = SvxEditSourceHelper::EENotification2Hint( aNotify);
1558 //UNUSED2008-05
1559 //UNUSED2008-05          if( aHint.get() )
1560 //UNUSED2008-05              GetBroadcaster().Broadcast( *aHint.get() );
1561 //UNUSED2008-05      }
1562 //UNUSED2008-05
1563 //UNUSED2008-05      return 0;
1564 //UNUSED2008-05  }
1565 
1566 ScDocShell* ScAccessiblePreviewHeaderCellTextData::GetDocShell(ScPreviewShell* pViewShell)
1567 {
1568 	ScDocShell* pDocSh = NULL;
1569 	if (pViewShell && pViewShell->GetDocument())
1570 		pDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1571 	return pDocSh;
1572 }
1573 
1574 
1575 // ============================================================================
1576 
1577 ScAccessibleHeaderTextData::ScAccessibleHeaderTextData(ScPreviewShell* pViewShell,
1578                             const EditTextObject* pEditObj, sal_Bool bHeader, SvxAdjust eAdjust)
1579     :
1580     mpViewForwarder(NULL),
1581     mpViewShell(pViewShell),
1582     mpEditEngine(NULL),
1583     mpForwarder(NULL),
1584     mpDocSh(NULL),
1585     mpEditObj(pEditObj),
1586     mbHeader(bHeader),
1587     mbDataValid(sal_False),
1588     meAdjust(eAdjust)
1589 {
1590 	if (pViewShell && pViewShell->GetDocument())
1591 		mpDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1592 	if (mpDocSh)
1593 		mpDocSh->GetDocument()->AddUnoObject(*this);
1594 }
1595 
1596 ScAccessibleHeaderTextData::~ScAccessibleHeaderTextData()
1597 {
1598 	ScUnoGuard aGuard;		//	needed for EditEngine dtor
1599 
1600 	if (mpDocSh)
1601 		mpDocSh->GetDocument()->RemoveUnoObject(*this);
1602     if (mpEditEngine)
1603         mpEditEngine->SetNotifyHdl(Link());
1604 	delete mpEditEngine;
1605 	delete mpForwarder;
1606 }
1607 
1608 ScAccessibleTextData* ScAccessibleHeaderTextData::Clone() const
1609 {
1610     return new ScAccessibleHeaderTextData(mpViewShell, mpEditObj, mbHeader, meAdjust);
1611 }
1612 
1613 void ScAccessibleHeaderTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
1614 {
1615 	if ( rHint.ISA( SfxSimpleHint ) )
1616 	{
1617 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1618 		if ( nId == SFX_HINT_DYING )
1619 		{
1620 			mpViewShell = NULL;// invalid now
1621             mpDocSh = NULL;
1622             if (mpViewForwarder)
1623                 mpViewForwarder->SetInvalid();
1624 		}
1625 	}
1626 }
1627 
1628 SvxTextForwarder* ScAccessibleHeaderTextData::GetTextForwarder()
1629 {
1630 	if (!mpEditEngine)
1631 	{
1632 		SfxItemPool* pEnginePool = EditEngine::CreatePool();
1633 		pEnginePool->FreezeIdRanges();
1634 		ScHeaderEditEngine* pHdrEngine = new ScHeaderEditEngine( pEnginePool, sal_True );
1635 
1636 		pHdrEngine->EnableUndo( sal_False );
1637 		pHdrEngine->SetRefMapMode( MAP_TWIP );
1638 
1639 		//	default font must be set, independently of document
1640 		//	-> use global pool from module
1641 
1642 		SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() );
1643 		const ScPatternAttr& rPattern = (const ScPatternAttr&)SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN);
1644 		rPattern.FillEditItemSet( &aDefaults );
1645 		//	FillEditItemSet adjusts font height to 1/100th mm,
1646 		//	but for header/footer twips is needed, as in the PatternAttr:
1647 		aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT );
1648 		aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK );
1649 		aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL );
1650 		aDefaults.Put( SvxAdjustItem( meAdjust, EE_PARA_JUST ) );
1651 		pHdrEngine->SetDefaults( aDefaults );
1652 
1653 		ScHeaderFieldData aData;
1654         if (mpViewShell)
1655             mpViewShell->FillFieldData(aData);
1656         else
1657 		    ScHeaderFooterTextObj::FillDummyFieldData( aData );
1658 		pHdrEngine->SetData( aData );
1659 
1660 		mpEditEngine = pHdrEngine;
1661 		mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1662 	}
1663 
1664 	if (mbDataValid)
1665 		return mpForwarder;
1666 
1667 	if ( mpViewShell  )
1668 	{
1669 		Rectangle aVisRect;
1670 		mpViewShell->GetLocationData().GetHeaderPosition(aVisRect);
1671         Size aSize(aVisRect.GetSize());
1672 		Window* pWin = mpViewShell->GetWindow();
1673 		if (pWin)
1674 			aSize = pWin->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1675 		mpEditEngine->SetPaperSize(aSize);
1676 	}
1677 	if (mpEditObj)
1678 		mpEditEngine->SetText(*mpEditObj);
1679 
1680 	mbDataValid = sal_True;
1681     return mpForwarder;
1682 }
1683 
1684 SvxViewForwarder* ScAccessibleHeaderTextData::GetViewForwarder()
1685 {
1686 	if (!mpViewForwarder)
1687 		mpViewForwarder = new ScPreviewHeaderFooterViewForwarder(mpViewShell, mbHeader);
1688 	return mpViewForwarder;
1689 }
1690 
1691 
1692 // ============================================================================
1693 
1694 ScAccessibleNoteTextData::ScAccessibleNoteTextData(ScPreviewShell* pViewShell,
1695                             const String& sText, const ScAddress& aCellPos, sal_Bool bMarkNote)
1696     :
1697     mpViewForwarder(NULL),
1698     mpViewShell(pViewShell),
1699     mpEditEngine(NULL),
1700     mpForwarder(NULL),
1701     mpDocSh(NULL),
1702     msText(sText),
1703     maCellPos(aCellPos),
1704     mbMarkNote(bMarkNote),
1705     mbDataValid(sal_False)
1706 {
1707 	if (pViewShell && pViewShell->GetDocument())
1708 		mpDocSh = (ScDocShell*) pViewShell->GetDocument()->GetDocumentShell();
1709 	if (mpDocSh)
1710 		mpDocSh->GetDocument()->AddUnoObject(*this);
1711 }
1712 
1713 ScAccessibleNoteTextData::~ScAccessibleNoteTextData()
1714 {
1715 	ScUnoGuard aGuard;		//	needed for EditEngine dtor
1716 
1717 	if (mpDocSh)
1718 		mpDocSh->GetDocument()->RemoveUnoObject(*this);
1719     if (mpEditEngine)
1720         mpEditEngine->SetNotifyHdl(Link());
1721 	delete mpEditEngine;
1722 	delete mpForwarder;
1723 }
1724 
1725 ScAccessibleTextData* ScAccessibleNoteTextData::Clone() const
1726 {
1727     return new ScAccessibleNoteTextData(mpViewShell, msText, maCellPos, mbMarkNote);
1728 }
1729 
1730 void ScAccessibleNoteTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
1731 {
1732 	if ( rHint.ISA( SfxSimpleHint ) )
1733 	{
1734 		sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1735 		if ( nId == SFX_HINT_DYING )
1736 		{
1737 			mpViewShell = NULL;// invalid now
1738             mpDocSh = NULL;
1739             if (mpViewForwarder)
1740                 mpViewForwarder->SetInvalid();
1741 		}
1742 	}
1743 }
1744 
1745 SvxTextForwarder* ScAccessibleNoteTextData::GetTextForwarder()
1746 {
1747 	if (!mpEditEngine)
1748 	{
1749 		if ( mpDocSh )
1750 		{
1751 			ScDocument* pDoc = mpDocSh->GetDocument();
1752 			mpEditEngine = pDoc->CreateFieldEditEngine();
1753 		}
1754 		else
1755 		{
1756 			SfxItemPool* pEnginePool = EditEngine::CreatePool();
1757 			pEnginePool->FreezeIdRanges();
1758 			mpEditEngine = new ScFieldEditEngine( pEnginePool, NULL, sal_True );
1759 		}
1760 		//	currently, GetPortions doesn't work if UpdateMode is sal_False,
1761 		//	this will be fixed (in EditEngine) by src600
1762 //		pEditEngine->SetUpdateMode( sal_False );
1763 		mpEditEngine->EnableUndo( sal_False );
1764 		if (mpDocSh)
1765 			mpEditEngine->SetRefDevice(mpDocSh->GetRefDevice());
1766 		else
1767 			mpEditEngine->SetRefMapMode( MAP_100TH_MM );
1768 		mpForwarder = new SvxEditEngineForwarder(*mpEditEngine);
1769 	}
1770 
1771 	if (mbDataValid)
1772 		return mpForwarder;
1773 
1774 	if (msText.Len() && mpEditEngine)
1775 	{
1776 
1777 		if ( mpViewShell  )
1778 		{
1779 			Size aOutputSize;
1780 			Window* pWindow = mpViewShell->GetWindow();
1781 			if ( pWindow )
1782 				aOutputSize = pWindow->GetOutputSizePixel();
1783 			Point aPoint;
1784 			Rectangle aVisRect( aPoint, aOutputSize );
1785 			Size aSize(mpViewShell->GetLocationData().GetNoteInRangeOutputRect(aVisRect, mbMarkNote, maCellPos).GetSize());
1786 			if (pWindow)
1787 				aSize = pWindow->PixelToLogic(aSize, mpEditEngine->GetRefMapMode());
1788 			mpEditEngine->SetPaperSize(aSize);
1789 		}
1790 		mpEditEngine->SetText( msText );
1791 	}
1792 
1793 	mbDataValid = sal_True;
1794 
1795 	if (mpEditEngine)
1796 		mpEditEngine->SetNotifyHdl( LINK(this, ScAccessibleCellTextData, NotifyHdl) );
1797 
1798 	return mpForwarder;
1799 }
1800 
1801 SvxViewForwarder* ScAccessibleNoteTextData::GetViewForwarder()
1802 {
1803 	if (!mpViewForwarder)
1804 		mpViewForwarder = new ScPreviewNoteViewForwarder(mpViewShell, maCellPos, mbMarkNote);
1805 	return mpViewForwarder;
1806 }
1807 
1808 
1809 // CSV import =================================================================
1810 
1811 class ScCsvViewForwarder : public SvxViewForwarder
1812 {
1813     Rectangle                   maBoundBox;
1814     Window*                     mpWindow;
1815 
1816 public:
1817     explicit                    ScCsvViewForwarder( Window* pWindow, const Rectangle& rBoundBox );
1818 
1819     virtual sal_Bool                IsValid() const;
1820     virtual Rectangle           GetVisArea() const;
1821     virtual Point               LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const;
1822     virtual Point               PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const;
1823 
1824     void                        SetInvalid();
1825 };
1826 
1827 ScCsvViewForwarder::ScCsvViewForwarder( Window* pWindow, const Rectangle& rBoundBox ) :
1828     maBoundBox( rBoundBox ),
1829     mpWindow( pWindow )
1830 {
1831 }
1832 
1833 sal_Bool ScCsvViewForwarder::IsValid() const
1834 {
1835     return mpWindow != NULL;
1836 }
1837 
1838 Rectangle ScCsvViewForwarder::GetVisArea() const
1839 {
1840     return maBoundBox;
1841 }
1842 
1843 Point ScCsvViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
1844 {
1845     if( !mpWindow ) return Point();
1846     return mpWindow->LogicToPixel( rPoint, rMapMode );
1847 }
1848 
1849 Point ScCsvViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
1850 {
1851     if( !mpWindow ) return Point();
1852     return mpWindow->PixelToLogic( rPoint, rMapMode );
1853 }
1854 
1855 void ScCsvViewForwarder::SetInvalid()
1856 {
1857     mpWindow = NULL;
1858 }
1859 
1860 // ----------------------------------------------------------------------------
1861 
1862 ScAccessibleCsvTextData::ScAccessibleCsvTextData(
1863         Window* pWindow, EditEngine* pEditEngine,
1864         const String& rCellText, const Rectangle& rBoundBox, const Size& rCellSize ) :
1865     mpWindow( pWindow ),
1866     mpEditEngine( pEditEngine ),
1867     maCellText( rCellText ),
1868     maBoundBox( rBoundBox ),
1869     maCellSize( rCellSize )
1870 {
1871 }
1872 
1873 ScAccessibleCsvTextData::~ScAccessibleCsvTextData()
1874 {
1875 }
1876 
1877 void ScAccessibleCsvTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1878 {
1879     if ( rHint.ISA( SfxSimpleHint ) )
1880     {
1881         sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1882         if( nId == SFX_HINT_DYING )
1883         {
1884             mpWindow = NULL;
1885             mpEditEngine = NULL;
1886             if (mpViewForwarder.get())
1887                 mpViewForwarder->SetInvalid();
1888         }
1889     }
1890     ScAccessibleTextData::Notify( rBC, rHint );
1891 }
1892 
1893 ScAccessibleTextData* ScAccessibleCsvTextData::Clone() const
1894 {
1895     return new ScAccessibleCsvTextData( mpWindow, mpEditEngine, maCellText, maBoundBox, maCellSize );
1896 }
1897 
1898 SvxTextForwarder* ScAccessibleCsvTextData::GetTextForwarder()
1899 {
1900     if( mpEditEngine )
1901     {
1902         mpEditEngine->SetPaperSize( maCellSize );
1903         mpEditEngine->SetText( maCellText );
1904         if( !mpTextForwarder.get() )
1905             mpTextForwarder.reset( new SvxEditEngineForwarder( *mpEditEngine ) );
1906     }
1907     else
1908         mpTextForwarder.reset( NULL );
1909     return mpTextForwarder.get();
1910 }
1911 
1912 SvxViewForwarder* ScAccessibleCsvTextData::GetViewForwarder()
1913 {
1914     if( !mpViewForwarder.get() )
1915         mpViewForwarder.reset( new ScCsvViewForwarder( mpWindow, maBoundBox ) );
1916     return mpViewForwarder.get();
1917 }
1918 
1919 SvxEditViewForwarder* ScAccessibleCsvTextData::GetEditViewForwarder( sal_Bool /* bCreate */ )
1920 {
1921     return NULL;
1922 }
1923 
1924 
1925 // ============================================================================
1926 
1927