Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/uno/XInterface.hpp>
21 : #include <vcl/svapp.hxx>
22 :
23 : #include <svx/unoshtxt.hxx>
24 : #include <editeng/unoedhlp.hxx>
25 : #include <svl/lstner.hxx>
26 : #include <rtl/ref.hxx>
27 : #include <osl/mutex.hxx>
28 : #include <svl/hint.hxx>
29 : #include <svl/style.hxx>
30 : #include <svx/svdmodel.hxx>
31 : #include <svx/svdoutl.hxx>
32 : #include <svx/svdobj.hxx>
33 : #include <svx/svdview.hxx>
34 : #include <svx/svdetc.hxx>
35 : #include <editeng/outliner.hxx>
36 : #include <editeng/unoforou.hxx>
37 : #include <editeng/unoviwou.hxx>
38 : #include <editeng/outlobj.hxx>
39 : #include <svx/svdotext.hxx>
40 : #include <svx/svdpage.hxx>
41 : #include <editeng/editeng.hxx>
42 : #include <editeng/editobj.hxx>
43 :
44 : #include <editeng/unotext.hxx>
45 : #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
46 : #include <comphelper/processfactory.hxx>
47 : #include <svx/svdotable.hxx>
48 : #include "../table/cell.hxx"
49 : #include <svx/sdrpaintwindow.hxx>
50 : #include <boost/scoped_ptr.hpp>
51 :
52 : using namespace ::osl;
53 : using namespace ::rtl;
54 :
55 : using ::com::sun::star::uno::XInterface;
56 :
57 :
58 : // SvxTextEditSourceImpl
59 :
60 :
61 : /** @descr
62 : <p>This class essentially provides the text and view forwarders. If
63 : no SdrView is given, this class handles the UNO objects, which are
64 : currently not concerned with view issues. In this case,
65 : GetViewForwarder() always returns NULL and the underlying
66 : EditEngine of the SvxTextForwarder is a background one (i.e. not
67 : the official DrawOutliner, but one created exclusively for this
68 : object, with no relation to a view).
69 : </p>
70 :
71 : <p>If a SdrView is given at construction time, the caller is
72 : responsible for destroying this object when the view becomes
73 : invalid (the views cannot notify). If GetViewForwarder(sal_True)
74 : is called, the underlying shape is put into edit mode, the view
75 : forwarder returned encapsulates the OutlinerView and the next call
76 : to GetTextForwarder() yields a forwarder encapsulating the actual
77 : DrawOutliner. Thus, changes on that Outliner are immediately
78 : reflected on the screen. If the object leaves edit mode, the old
79 : behaviour is restored.</p>
80 : */
81 : class SvxTextEditSourceImpl : public SfxListener, public SfxBroadcaster, public sdr::ObjectUser
82 : {
83 : private:
84 : oslInterlockedCount maRefCount;
85 :
86 : SdrObject* mpObject;
87 : SdrText* mpText;
88 : SdrView* mpView;
89 : const Window* mpWindow;
90 : SdrModel* mpModel;
91 : SdrOutliner* mpOutliner;
92 : SvxOutlinerForwarder* mpTextForwarder;
93 : SvxDrawOutlinerViewForwarder* mpViewForwarder; // if non-NULL, use GetViewModeTextForwarder text forwarder
94 : css::uno::Reference< css::linguistic2::XLinguServiceManager2 > m_xLinguServiceManager;
95 : Point maTextOffset;
96 : bool mbDataValid;
97 : bool mbDestroyed;
98 : bool mbIsLocked;
99 : bool mbNeedsUpdate;
100 : sal_Bool mbOldUndoMode;
101 : bool mbForwarderIsEditMode; // have to reflect that, since ENDEDIT can happen more often
102 : bool mbShapeIsEditMode; // #104157# only true, if HINT_BEGEDIT was received
103 : bool mbNotificationsDisabled; // prevent EditEngine/Outliner notifications (e.g. when setting up forwarder)
104 :
105 : XInterface* mpOwner;
106 : SvxUnoTextRangeBaseList maTextRanges;
107 :
108 : SvxTextForwarder* GetBackgroundTextForwarder();
109 : SvxTextForwarder* GetEditModeTextForwarder();
110 : SvxDrawOutlinerViewForwarder* CreateViewForwarder();
111 :
112 : void SetupOutliner();
113 :
114 0 : bool HasView() const { return mpView ? true : false; }
115 0 : bool IsEditMode() const
116 : {
117 0 : SdrTextObj* pTextObj = PTR_CAST( SdrTextObj, mpObject );
118 0 : return mbShapeIsEditMode && pTextObj && pTextObj->IsTextEditActive() ? true : false;
119 : }
120 :
121 : void dispose();
122 :
123 : public:
124 : SvxTextEditSourceImpl( SdrObject* pObject, SdrText* pText, XInterface* pOwner );
125 : SvxTextEditSourceImpl( SdrObject& rObject, SdrText* pText, SdrView& rView, const Window& rWindow );
126 : virtual ~SvxTextEditSourceImpl();
127 :
128 : void SAL_CALL acquire();
129 : void SAL_CALL release();
130 :
131 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
132 :
133 : SvxTextForwarder* GetTextForwarder();
134 : SvxEditViewForwarder* GetEditViewForwarder( sal_Bool );
135 : void UpdateData();
136 :
137 : void addRange( SvxUnoTextRangeBase* pNewRange );
138 : void removeRange( SvxUnoTextRangeBase* pOldRange );
139 : const SvxUnoTextRangeBaseList& getRanges() const;
140 :
141 : void lock();
142 : void unlock();
143 :
144 : sal_Bool IsValid() const;
145 :
146 : Rectangle GetVisArea();
147 : Point LogicToPixel( const Point&, const MapMode& rMapMode );
148 : Point PixelToLogic( const Point&, const MapMode& rMapMode );
149 :
150 : DECL_LINK( NotifyHdl, EENotify* );
151 :
152 : virtual void ObjectInDestruction(const SdrObject& rObject) SAL_OVERRIDE;
153 :
154 : void ChangeModel( SdrModel* pNewModel );
155 :
156 : void UpdateOutliner();
157 : };
158 :
159 :
160 :
161 0 : SvxTextEditSourceImpl::SvxTextEditSourceImpl( SdrObject* pObject, SdrText* pText, XInterface* pOwner )
162 : : maRefCount ( 0 ),
163 : mpObject ( pObject ),
164 : mpText ( pText ),
165 : mpView ( NULL ),
166 : mpWindow ( NULL ),
167 : mpModel ( pObject ? pObject->GetModel() : NULL ),
168 : mpOutliner ( NULL ),
169 : mpTextForwarder ( NULL ),
170 : mpViewForwarder ( NULL ),
171 : mbDataValid ( false ),
172 : mbDestroyed ( false ),
173 : mbIsLocked ( false ),
174 : mbNeedsUpdate ( false ),
175 : mbOldUndoMode ( sal_False ),
176 : mbForwarderIsEditMode ( false ),
177 : mbShapeIsEditMode ( false ),
178 : mbNotificationsDisabled ( false ),
179 0 : mpOwner( pOwner )
180 : {
181 : DBG_ASSERT( mpObject, "invalid pObject!" );
182 :
183 0 : if( !mpText )
184 : {
185 0 : SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( mpObject );
186 0 : if( pTextObj )
187 0 : mpText = pTextObj->getText( 0 );
188 : }
189 :
190 0 : if( mpModel )
191 0 : StartListening( *mpModel );
192 :
193 0 : if( mpObject )
194 0 : mpObject->AddObjectUser( *this );
195 0 : }
196 :
197 :
198 :
199 0 : SvxTextEditSourceImpl::SvxTextEditSourceImpl( SdrObject& rObject, SdrText* pText, SdrView& rView, const Window& rWindow )
200 : : maRefCount ( 0 ),
201 : mpObject ( &rObject ),
202 : mpText ( pText ),
203 : mpView ( &rView ),
204 : mpWindow ( &rWindow ),
205 0 : mpModel ( rObject.GetModel() ),
206 : mpOutliner ( NULL ),
207 : mpTextForwarder ( NULL ),
208 : mpViewForwarder ( NULL ),
209 : mbDataValid ( false ),
210 : mbDestroyed ( false ),
211 : mbIsLocked ( false ),
212 : mbNeedsUpdate ( false ),
213 : mbOldUndoMode ( sal_False ),
214 : mbForwarderIsEditMode ( false ),
215 : mbShapeIsEditMode ( true ),
216 : mbNotificationsDisabled ( false ),
217 0 : mpOwner(0)
218 : {
219 0 : if( !mpText )
220 : {
221 0 : SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( mpObject );
222 0 : if( pTextObj )
223 0 : mpText = pTextObj->getText( 0 );
224 : }
225 :
226 0 : if( mpModel )
227 0 : StartListening( *mpModel );
228 0 : if( mpView )
229 0 : StartListening( *mpView );
230 0 : if( mpObject )
231 0 : mpObject->AddObjectUser( *this );
232 :
233 : // #104157# Init edit mode state from shape info (IsTextEditActive())
234 0 : mbShapeIsEditMode = IsEditMode();
235 0 : }
236 :
237 :
238 :
239 0 : SvxTextEditSourceImpl::~SvxTextEditSourceImpl()
240 : {
241 : DBG_ASSERT( mbIsLocked == false, "text edit source was not unlocked before dispose!" );
242 0 : if( mpObject )
243 0 : mpObject->RemoveObjectUser( *this );
244 :
245 0 : dispose();
246 0 : }
247 :
248 :
249 :
250 0 : void SvxTextEditSourceImpl::addRange( SvxUnoTextRangeBase* pNewRange )
251 : {
252 0 : if( pNewRange )
253 0 : if( std::find( maTextRanges.begin(), maTextRanges.end(), pNewRange ) == maTextRanges.end() )
254 0 : maTextRanges.push_back( pNewRange );
255 0 : }
256 :
257 :
258 :
259 0 : void SvxTextEditSourceImpl::removeRange( SvxUnoTextRangeBase* pOldRange )
260 : {
261 0 : if( pOldRange )
262 0 : maTextRanges.remove( pOldRange );
263 0 : }
264 :
265 :
266 :
267 0 : const SvxUnoTextRangeBaseList& SvxTextEditSourceImpl::getRanges() const
268 : {
269 0 : return maTextRanges;
270 : }
271 :
272 :
273 :
274 0 : void SAL_CALL SvxTextEditSourceImpl::acquire()
275 : {
276 0 : osl_atomic_increment( &maRefCount );
277 0 : }
278 :
279 :
280 :
281 0 : void SAL_CALL SvxTextEditSourceImpl::release()
282 : {
283 0 : if( ! osl_atomic_decrement( &maRefCount ) )
284 0 : delete this;
285 0 : }
286 :
287 0 : void SvxTextEditSourceImpl::ChangeModel( SdrModel* pNewModel )
288 : {
289 0 : if( mpModel != pNewModel )
290 : {
291 0 : if( mpModel )
292 0 : EndListening( *mpModel );
293 :
294 0 : if( mpOutliner )
295 : {
296 0 : if( mpModel )
297 0 : mpModel->disposeOutliner( mpOutliner );
298 : else
299 0 : delete mpOutliner;
300 0 : mpOutliner = 0;
301 : }
302 :
303 0 : if( mpView )
304 : {
305 0 : EndListening( *mpView );
306 0 : mpView = 0;
307 : }
308 :
309 0 : mpWindow = 0;
310 0 : m_xLinguServiceManager.clear();
311 0 : mpOwner = 0;
312 :
313 0 : mpModel = pNewModel;
314 :
315 0 : if( mpTextForwarder )
316 : {
317 0 : delete mpTextForwarder;
318 0 : mpTextForwarder = 0;
319 : }
320 :
321 0 : if( mpViewForwarder )
322 : {
323 0 : delete mpViewForwarder;
324 0 : mpViewForwarder = 0;
325 : }
326 :
327 0 : if( mpModel )
328 0 : StartListening( *mpModel );
329 : }
330 0 : }
331 :
332 :
333 :
334 0 : void SvxTextEditSourceImpl::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
335 : {
336 : // #i105988 keep reference to this object
337 0 : rtl::Reference< SvxTextEditSourceImpl > xThis( this );
338 :
339 0 : const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
340 0 : const SvxViewHint* pViewHint = PTR_CAST( SvxViewHint, &rHint );
341 0 : const SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
342 :
343 0 : if (pSimpleHint)
344 : {
345 0 : if (SFX_HINT_DYING == pSimpleHint->GetId())
346 : {
347 0 : if (&rBC == mpView)
348 : {
349 0 : mpView = 0;
350 0 : if (mpViewForwarder)
351 : {
352 0 : delete mpViewForwarder;
353 0 : mpViewForwarder = 0;
354 : }
355 : }
356 : }
357 : }
358 0 : else if( pViewHint )
359 : {
360 0 : switch( pViewHint->GetHintType() )
361 : {
362 : case SvxViewHint::SVX_HINT_VIEWCHANGED:
363 0 : Broadcast( *pViewHint );
364 0 : break;
365 : }
366 : }
367 0 : else if( pSdrHint )
368 : {
369 0 : switch( pSdrHint->GetKind() )
370 : {
371 : case HINT_OBJCHG:
372 : {
373 0 : mbDataValid = false; // Text muss neu geholt werden
374 :
375 0 : if( HasView() )
376 : {
377 : // #104157# Update maTextOffset, object has changed
378 : // #105196#, #105203#: Cannot call that // here,
379 : // since TakeTextRect() (called from there)
380 : // changes outliner content.
381 : // UpdateOutliner();
382 :
383 : // #101029# Broadcast object changes, as they might change visible attributes
384 0 : SvxViewHint aHint(SvxViewHint::SVX_HINT_VIEWCHANGED);
385 0 : Broadcast( aHint );
386 : }
387 0 : break;
388 : }
389 :
390 : case HINT_BEGEDIT:
391 0 : if( mpObject == pSdrHint->GetObject() )
392 : {
393 : // Once HINT_BEGEDIT is broadcast, each EditSource of
394 : // AccessibleCell will handle it here and call below:
395 : // mpView->GetTextEditOutliner()->SetNotifyHdl(), which
396 : // will replace the Notifer for current editable cell. It
397 : // is totally wrong. So add check here to avoid the
398 : // incorrect replacement of notifer.
399 :
400 : // Currently it only happens on the editsource of
401 : // AccessibleCell
402 0 : if (mpObject && mpText)
403 : {
404 0 : sdr::table::SdrTableObj* pTableObj = PTR_CAST( sdr::table::SdrTableObj, mpObject );
405 0 : if(pTableObj)
406 : {
407 0 : sdr::table::CellRef xCell = pTableObj->getActiveCell();
408 0 : if (xCell.is())
409 : {
410 0 : sdr::table::Cell* pCellObj = dynamic_cast< sdr::table::Cell* >( mpText );
411 0 : if (pCellObj && xCell.get() != pCellObj)
412 0 : break;
413 0 : }
414 : }
415 : }
416 : // invalidate old forwarder
417 0 : if( !mbForwarderIsEditMode )
418 : {
419 0 : delete mpTextForwarder;
420 0 : mpTextForwarder = NULL;
421 : }
422 :
423 : // register as listener - need to broadcast state change messages
424 0 : if( mpView && mpView->GetTextEditOutliner() )
425 0 : mpView->GetTextEditOutliner()->SetNotifyHdl( LINK(this, SvxTextEditSourceImpl, NotifyHdl) );
426 :
427 : // #104157# Only now we're really in edit mode
428 0 : mbShapeIsEditMode = true;
429 :
430 0 : Broadcast( *pSdrHint );
431 : }
432 0 : break;
433 :
434 : case HINT_ENDEDIT:
435 0 : if( mpObject == pSdrHint->GetObject() )
436 : {
437 0 : Broadcast( *pSdrHint );
438 :
439 : // #104157# We're no longer in edit mode
440 0 : mbShapeIsEditMode = false;
441 :
442 : // remove as listener - outliner might outlive ourselves
443 0 : if( mpView && mpView->GetTextEditOutliner() )
444 0 : mpView->GetTextEditOutliner()->SetNotifyHdl( Link() );
445 :
446 : // destroy view forwarder, OutlinerView no longer
447 : // valid (no need for UpdateData(), it's been
448 : // synched on SdrEndTextEdit)
449 0 : delete mpViewForwarder;
450 0 : mpViewForwarder = NULL;
451 :
452 : // #100424# Invalidate text forwarder, we might
453 : // not be called again before entering edit mode a
454 : // second time! Then, the old outliner might be
455 : // invalid.
456 0 : if( mbForwarderIsEditMode )
457 : {
458 0 : mbForwarderIsEditMode = false;
459 0 : delete mpTextForwarder;
460 0 : mpTextForwarder = NULL;
461 : }
462 : }
463 0 : break;
464 :
465 : case HINT_MODELCLEARED:
466 0 : dispose();
467 0 : break;
468 : default:
469 0 : break;
470 : }
471 0 : }
472 0 : }
473 :
474 : /* this is a callback from the attached SdrObject when it is actually deleted */
475 0 : void SvxTextEditSourceImpl::ObjectInDestruction(const SdrObject&)
476 : {
477 0 : mpObject = 0;
478 0 : dispose();
479 0 : Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
480 0 : }
481 :
482 : /* unregister at all objects and set all references to 0 */
483 0 : void SvxTextEditSourceImpl::dispose()
484 : {
485 0 : if( mpTextForwarder )
486 : {
487 0 : delete mpTextForwarder;
488 0 : mpTextForwarder = 0;
489 : }
490 :
491 0 : if( mpViewForwarder )
492 : {
493 0 : delete mpViewForwarder;
494 0 : mpViewForwarder = 0;
495 : }
496 :
497 0 : if( mpOutliner )
498 : {
499 0 : if( mpModel )
500 : {
501 0 : mpModel->disposeOutliner( mpOutliner );
502 : }
503 : else
504 : {
505 0 : delete mpOutliner;
506 : }
507 0 : mpOutliner = 0;
508 : }
509 :
510 0 : if( mpModel )
511 : {
512 0 : EndListening( *mpModel );
513 0 : mpModel = 0;
514 : }
515 :
516 0 : if( mpView )
517 : {
518 0 : EndListening( *mpView );
519 0 : mpView = 0;
520 : }
521 :
522 0 : if( mpObject )
523 : {
524 0 : mpObject->RemoveObjectUser( *this );
525 0 : mpObject = 0;
526 : }
527 0 : mpWindow = 0;
528 0 : }
529 :
530 :
531 :
532 0 : void SvxTextEditSourceImpl::SetupOutliner()
533 : {
534 : // #101029#
535 : // only for UAA edit source: setup outliner equivalently as in
536 : // SdrTextObj::Paint(), such that formatting equals screen
537 : // layout
538 0 : if( mpObject && mpOutliner )
539 : {
540 0 : SdrTextObj* pTextObj = PTR_CAST( SdrTextObj, mpObject );
541 0 : Rectangle aPaintRect;
542 0 : if( pTextObj )
543 : {
544 0 : Rectangle aBoundRect( pTextObj->GetCurrentBoundRect() );
545 0 : pTextObj->SetupOutlinerFormatting( *mpOutliner, aPaintRect );
546 :
547 : // #101029# calc text offset from shape anchor
548 0 : maTextOffset = aPaintRect.TopLeft() - aBoundRect.TopLeft();
549 : }
550 : }
551 0 : }
552 :
553 :
554 :
555 0 : void SvxTextEditSourceImpl::UpdateOutliner()
556 : {
557 : // #104157#
558 : // only for UAA edit source: update outliner equivalently as in
559 : // SdrTextObj::Paint(), such that formatting equals screen
560 : // layout
561 0 : if( mpObject && mpOutliner )
562 : {
563 0 : SdrTextObj* pTextObj = PTR_CAST( SdrTextObj, mpObject );
564 0 : Rectangle aPaintRect;
565 0 : if( pTextObj )
566 : {
567 0 : Rectangle aBoundRect( pTextObj->GetCurrentBoundRect() );
568 0 : pTextObj->UpdateOutlinerFormatting( *mpOutliner, aPaintRect );
569 :
570 : // #101029# calc text offset from shape anchor
571 0 : maTextOffset = aPaintRect.TopLeft() - aBoundRect.TopLeft();
572 : }
573 : }
574 0 : }
575 :
576 :
577 :
578 :
579 :
580 0 : SvxTextForwarder* SvxTextEditSourceImpl::GetBackgroundTextForwarder()
581 : {
582 0 : bool bCreated = false;
583 :
584 : // #99840#: prevent EE/Outliner notifications during setup
585 0 : mbNotificationsDisabled = true;
586 :
587 0 : if (!mpTextForwarder)
588 : {
589 0 : if( mpOutliner == NULL )
590 : {
591 0 : SdrTextObj* pTextObj = PTR_CAST( SdrTextObj, mpObject );
592 0 : sal_uInt16 nOutlMode = OUTLINERMODE_TEXTOBJECT;
593 0 : if( pTextObj && pTextObj->IsTextFrame() && pTextObj->GetTextKind() == OBJ_OUTLINETEXT )
594 0 : nOutlMode = OUTLINERMODE_OUTLINEOBJECT;
595 :
596 0 : mpOutliner = mpModel->createOutliner( nOutlMode );
597 :
598 : // #109151# Do the setup after outliner creation, would be useless otherwise
599 0 : if( HasView() )
600 : {
601 : // #101029#, #104157# Setup outliner _before_ filling it
602 0 : SetupOutliner();
603 : }
604 :
605 0 : mpOutliner->SetTextObjNoInit( pTextObj );
606 0 : if( mbIsLocked )
607 : {
608 0 : ((EditEngine*)&(mpOutliner->GetEditEngine()))->SetUpdateMode( false );
609 0 : mbOldUndoMode = ((EditEngine*)&(mpOutliner->GetEditEngine()))->IsUndoEnabled();
610 0 : ((EditEngine*)&(mpOutliner->GetEditEngine()))->EnableUndo( false );
611 : }
612 :
613 0 : if ( !m_xLinguServiceManager.is() )
614 : {
615 0 : css::uno::Reference< css::uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
616 0 : m_xLinguServiceManager.set(css::linguistic2::LinguServiceManager::create(xContext));
617 : }
618 :
619 0 : css::uno::Reference< css::linguistic2::XHyphenator > xHyphenator( m_xLinguServiceManager->getHyphenator(), css::uno::UNO_QUERY );
620 0 : if( xHyphenator.is() )
621 0 : mpOutliner->SetHyphenator( xHyphenator );
622 : }
623 :
624 :
625 0 : mpTextForwarder = new SvxOutlinerForwarder( *mpOutliner, (mpObject->GetObjInventor() == SdrInventor) && (mpObject->GetObjIdentifier() == OBJ_OUTLINETEXT) );
626 : // delay listener subscription and UAA initialization until Outliner is fully setup
627 0 : bCreated = true;
628 :
629 0 : mbForwarderIsEditMode = false;
630 : }
631 :
632 0 : if( mpObject && mpText && !mbDataValid && mpObject->IsInserted() && mpObject->GetPage() )
633 : {
634 0 : mpTextForwarder->flushCache();
635 :
636 0 : OutlinerParaObject* pOutlinerParaObject = NULL;
637 0 : SdrTextObj* pTextObj = PTR_CAST( SdrTextObj, mpObject );
638 0 : if( pTextObj && pTextObj->getActiveText() == mpText )
639 0 : pOutlinerParaObject = pTextObj->GetEditOutlinerParaObject(); // Get the OutlinerParaObject if text edit is active
640 0 : bool bOwnParaObj(false);
641 :
642 0 : if( pOutlinerParaObject )
643 0 : bOwnParaObj = true; // text edit active
644 : else
645 0 : pOutlinerParaObject = mpText->GetOutlinerParaObject();
646 :
647 0 : if( pOutlinerParaObject && ( bOwnParaObj || !mpObject->IsEmptyPresObj() || mpObject->GetPage()->IsMasterPage() ) )
648 : {
649 0 : mpOutliner->SetText( *pOutlinerParaObject );
650 :
651 : // #91254# put text to object and set EmptyPresObj to FALSE
652 0 : if( mpText && bOwnParaObj && pOutlinerParaObject && mpObject->IsEmptyPresObj() && pTextObj->IsRealyEdited() )
653 : {
654 0 : mpObject->SetEmptyPresObj( false );
655 0 : static_cast< SdrTextObj* >( mpObject)->NbcSetOutlinerParaObjectForText( pOutlinerParaObject, mpText );
656 :
657 : // #i103982# Here, due to mpObject->NbcSetOutlinerParaObjectForText, we LOSE ownership of the
658 : // OPO, so do NOT delete it when leaving this method (!)
659 0 : bOwnParaObj = false;
660 : }
661 : }
662 : else
663 : {
664 0 : bool bVertical = pOutlinerParaObject ? pOutlinerParaObject->IsVertical() : false;
665 :
666 : // set objects style sheet on empty outliner
667 0 : SfxStyleSheetPool* pPool = (SfxStyleSheetPool*)mpObject->GetModel()->GetStyleSheetPool();
668 0 : if( pPool )
669 0 : mpOutliner->SetStyleSheetPool( pPool );
670 :
671 0 : SfxStyleSheet* pStyleSheet = mpObject->GetPage()->GetTextStyleSheetForObject( mpObject );
672 0 : if( pStyleSheet )
673 0 : mpOutliner->SetStyleSheet( 0, pStyleSheet );
674 :
675 0 : if( bVertical )
676 0 : mpOutliner->SetVertical( true );
677 : }
678 :
679 : // evtually we have to set the border attributes
680 0 : if (mpOutliner->GetParagraphCount()==1)
681 : {
682 : // if we only have one paragraph we check if it is empty
683 0 : OUString aStr(mpOutliner->GetText(mpOutliner->GetParagraph(0)));
684 :
685 0 : if (aStr.isEmpty())
686 : {
687 : // its empty, so we have to force the outliner to initialise itself
688 0 : mpOutliner->SetText( "", mpOutliner->GetParagraph( 0 ) );
689 :
690 0 : if(mpObject->GetStyleSheet())
691 0 : mpOutliner->SetStyleSheet( 0, mpObject->GetStyleSheet());
692 0 : }
693 : }
694 :
695 0 : mbDataValid = true;
696 :
697 0 : if( bOwnParaObj )
698 0 : delete pOutlinerParaObject;
699 : }
700 :
701 0 : if( bCreated && mpOutliner && HasView() )
702 : {
703 : // register as listener - need to broadcast state change messages
704 : // registration delayed until outliner is completely set up
705 0 : mpOutliner->SetNotifyHdl( LINK(this, SvxTextEditSourceImpl, NotifyHdl) );
706 : }
707 :
708 : // #99840#: prevent EE/Outliner notifications during setup
709 0 : mbNotificationsDisabled = false;
710 :
711 0 : return mpTextForwarder;
712 : }
713 :
714 :
715 :
716 0 : SvxTextForwarder* SvxTextEditSourceImpl::GetEditModeTextForwarder()
717 : {
718 0 : if( !mpTextForwarder && HasView() )
719 : {
720 0 : SdrOutliner* pEditOutliner = mpView->GetTextEditOutliner();
721 :
722 0 : if( pEditOutliner )
723 : {
724 0 : mpTextForwarder = new SvxOutlinerForwarder( *pEditOutliner, (mpObject->GetObjInventor() == SdrInventor) && (mpObject->GetObjIdentifier() == OBJ_OUTLINETEXT) );
725 0 : mbForwarderIsEditMode = true;
726 : }
727 : }
728 :
729 0 : return mpTextForwarder;
730 : }
731 :
732 :
733 :
734 0 : SvxTextForwarder* SvxTextEditSourceImpl::GetTextForwarder()
735 : {
736 0 : if( mbDestroyed || mpObject == NULL )
737 0 : return NULL;
738 :
739 0 : if( mpModel == NULL )
740 0 : mpModel = mpObject->GetModel();
741 :
742 0 : if( mpModel == NULL )
743 0 : return NULL;
744 :
745 : // distinguish the cases
746 : // a) connected to view, maybe edit mode is active, can work directly on the EditOutliner
747 : // b) background Outliner, reflect changes into ParaOutlinerObject (this is exactly the old UNO code)
748 0 : if( HasView() )
749 : {
750 0 : if( IsEditMode() != mbForwarderIsEditMode )
751 : {
752 : // forwarder mismatch - create new
753 0 : delete mpTextForwarder;
754 0 : mpTextForwarder = NULL;
755 : }
756 :
757 0 : if( IsEditMode() )
758 0 : return GetEditModeTextForwarder();
759 : else
760 0 : return GetBackgroundTextForwarder();
761 : }
762 : else
763 0 : return GetBackgroundTextForwarder();
764 : }
765 :
766 :
767 :
768 0 : SvxDrawOutlinerViewForwarder* SvxTextEditSourceImpl::CreateViewForwarder()
769 : {
770 0 : if( mpView->GetTextEditOutlinerView() && mpObject )
771 : {
772 : // register as listener - need to broadcast state change messages
773 0 : mpView->GetTextEditOutliner()->SetNotifyHdl( LINK(this, SvxTextEditSourceImpl, NotifyHdl) );
774 :
775 0 : SdrTextObj* pTextObj = PTR_CAST( SdrTextObj, mpObject );
776 0 : if( pTextObj )
777 : {
778 0 : Rectangle aBoundRect( pTextObj->GetCurrentBoundRect() );
779 0 : OutlinerView& rOutlView = *mpView->GetTextEditOutlinerView();
780 :
781 0 : return new SvxDrawOutlinerViewForwarder( rOutlView, aBoundRect.TopLeft() );
782 : }
783 : }
784 :
785 0 : return NULL;
786 : }
787 :
788 0 : SvxEditViewForwarder* SvxTextEditSourceImpl::GetEditViewForwarder( sal_Bool bCreate )
789 : {
790 0 : if( mbDestroyed || mpObject == NULL )
791 0 : return NULL;
792 :
793 0 : if( mpModel == NULL )
794 0 : mpModel = mpObject->GetModel();
795 :
796 0 : if( mpModel == NULL )
797 0 : return NULL;
798 :
799 : // shall we delete?
800 0 : if( mpViewForwarder )
801 : {
802 0 : if( !IsEditMode() )
803 : {
804 : // destroy all forwarders (no need for UpdateData(),
805 : // it's been synched on SdrEndTextEdit)
806 0 : delete mpViewForwarder;
807 0 : mpViewForwarder = NULL;
808 : }
809 : }
810 : // which to create? Directly in edit mode, create new, or none?
811 0 : else if( mpView )
812 : {
813 0 : if( IsEditMode() )
814 : {
815 : // create new view forwarder
816 0 : mpViewForwarder = CreateViewForwarder();
817 : }
818 0 : else if( bCreate )
819 : {
820 : // dispose old text forwarder
821 0 : UpdateData();
822 :
823 0 : delete mpTextForwarder;
824 0 : mpTextForwarder = NULL;
825 :
826 : // enter edit mode
827 0 : mpView->SdrEndTextEdit();
828 :
829 0 : if(mpView->SdrBeginTextEdit(mpObject, 0L, 0L, false, (SdrOutliner*)0L, 0L, false, false))
830 : {
831 0 : SdrTextObj* pTextObj = PTR_CAST( SdrTextObj, mpObject );
832 0 : if( pTextObj->IsTextEditActive() )
833 : {
834 : // create new view forwarder
835 0 : mpViewForwarder = CreateViewForwarder();
836 : }
837 : else
838 : {
839 : // failure. Somehow, SdrBeginTextEdit did not set
840 : // our SdrTextObj into edit mode
841 0 : mpView->SdrEndTextEdit();
842 : }
843 : }
844 : }
845 : }
846 :
847 0 : return mpViewForwarder;
848 : }
849 :
850 :
851 :
852 0 : void SvxTextEditSourceImpl::UpdateData()
853 : {
854 : // if we have a view and in edit mode, we're working with the
855 : // DrawOutliner. Thus, all changes made on the text forwarder are
856 : // reflected on the view and committed to the model on
857 : // SdrEndTextEdit(). Thus, no need for explicit updates here.
858 0 : if( !HasView() || !IsEditMode() )
859 : {
860 0 : if( mbIsLocked )
861 : {
862 0 : mbNeedsUpdate = true;
863 : }
864 : else
865 : {
866 0 : if( mpOutliner && mpObject && mpText && !mbDestroyed )
867 : {
868 0 : SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( mpObject );
869 0 : if( pTextObj )
870 : {
871 0 : if( mpOutliner->GetParagraphCount() != 1 || mpOutliner->GetEditEngine().GetTextLen( 0 ) )
872 : {
873 0 : if( mpOutliner->GetParagraphCount() > 1 )
874 : {
875 0 : if( pTextObj && pTextObj->IsTextFrame() && pTextObj->GetTextKind() == OBJ_TITLETEXT )
876 : {
877 0 : while( mpOutliner->GetParagraphCount() > 1 )
878 : {
879 0 : ESelection aSel( 0,mpOutliner->GetEditEngine().GetTextLen( 0 ), 1,0 );
880 0 : mpOutliner->QuickInsertLineBreak( aSel );
881 : }
882 : }
883 : }
884 :
885 0 : pTextObj->NbcSetOutlinerParaObjectForText( mpOutliner->CreateParaObject(), mpText );
886 : }
887 : else
888 : {
889 0 : pTextObj->NbcSetOutlinerParaObjectForText( NULL,mpText );
890 : }
891 : }
892 :
893 0 : if( mpObject->IsEmptyPresObj() )
894 0 : mpObject->SetEmptyPresObj(false);
895 : }
896 : }
897 : }
898 0 : }
899 :
900 0 : void SvxTextEditSourceImpl::lock()
901 : {
902 0 : mbIsLocked = true;
903 0 : if( mpOutliner )
904 : {
905 0 : ((EditEngine*)&(mpOutliner->GetEditEngine()))->SetUpdateMode( false );
906 0 : mbOldUndoMode = ((EditEngine*)&(mpOutliner->GetEditEngine()))->IsUndoEnabled();
907 0 : ((EditEngine*)&(mpOutliner->GetEditEngine()))->EnableUndo( false );
908 : }
909 0 : }
910 :
911 0 : void SvxTextEditSourceImpl::unlock()
912 : {
913 0 : mbIsLocked = false;
914 :
915 0 : if( mbNeedsUpdate )
916 : {
917 0 : UpdateData();
918 0 : mbNeedsUpdate = false;
919 : }
920 :
921 0 : if( mpOutliner )
922 : {
923 0 : ((EditEngine*)&(mpOutliner->GetEditEngine()))->SetUpdateMode( true );
924 0 : ((EditEngine*)&(mpOutliner->GetEditEngine()))->EnableUndo( mbOldUndoMode );
925 : }
926 0 : }
927 :
928 0 : sal_Bool SvxTextEditSourceImpl::IsValid() const
929 : {
930 0 : return mpView && mpWindow ? sal_True : sal_False;
931 : }
932 :
933 0 : Rectangle SvxTextEditSourceImpl::GetVisArea()
934 : {
935 0 : if( IsValid() )
936 : {
937 0 : SdrPaintWindow* pPaintWindow = mpView->FindPaintWindow(*mpWindow);
938 0 : Rectangle aVisArea;
939 :
940 0 : if(pPaintWindow)
941 : {
942 0 : aVisArea = pPaintWindow->GetVisibleArea();
943 : }
944 :
945 : // offset vis area by edit engine left-top position
946 0 : SdrTextObj* pTextObj = PTR_CAST( SdrTextObj, mpObject );
947 0 : if( pTextObj )
948 : {
949 0 : Rectangle aAnchorRect;
950 0 : pTextObj->TakeTextAnchorRect( aAnchorRect );
951 0 : aVisArea.Move( -aAnchorRect.Left(), -aAnchorRect.Top() );
952 :
953 0 : MapMode aMapMode(mpWindow->GetMapMode());
954 0 : aMapMode.SetOrigin(Point());
955 0 : return mpWindow->LogicToPixel( aVisArea, aMapMode );
956 : }
957 : }
958 :
959 0 : return Rectangle();
960 : }
961 :
962 0 : Point SvxTextEditSourceImpl::LogicToPixel( const Point& rPoint, const MapMode& rMapMode )
963 : {
964 : // #101029#: The responsibilities of ViewForwarder happen to be
965 : // somewhat mixed in this case. On the one hand, we need the
966 : // different interface queries on the SvxEditSource interface,
967 : // since we need both VisAreas. On the other hand, if an
968 : // EditViewForwarder exists, maTextOffset does not remain static,
969 : // but may change with every key press.
970 0 : if( IsEditMode() )
971 : {
972 0 : SvxEditViewForwarder* pForwarder = GetEditViewForwarder(sal_False);
973 :
974 0 : if( pForwarder )
975 0 : return pForwarder->LogicToPixel( rPoint, rMapMode );
976 : }
977 0 : else if( IsValid() && mpModel )
978 : {
979 : // #101029#
980 0 : Point aPoint1( rPoint );
981 0 : aPoint1.X() += maTextOffset.X();
982 0 : aPoint1.Y() += maTextOffset.Y();
983 :
984 : Point aPoint2( OutputDevice::LogicToLogic( aPoint1, rMapMode,
985 0 : MapMode(mpModel->GetScaleUnit()) ) );
986 0 : MapMode aMapMode(mpWindow->GetMapMode());
987 0 : aMapMode.SetOrigin(Point());
988 0 : return mpWindow->LogicToPixel( aPoint2, aMapMode );
989 : }
990 :
991 0 : return Point();
992 : }
993 :
994 0 : Point SvxTextEditSourceImpl::PixelToLogic( const Point& rPoint, const MapMode& rMapMode )
995 : {
996 : // #101029#: The responsibilities of ViewForwarder happen to be
997 : // somewhat mixed in this case. On the one hand, we need the
998 : // different interface queries on the SvxEditSource interface,
999 : // since we need both VisAreas. On the other hand, if an
1000 : // EditViewForwarder exists, maTextOffset does not remain static,
1001 : // but may change with every key press.
1002 0 : if( IsEditMode() )
1003 : {
1004 0 : SvxEditViewForwarder* pForwarder = GetEditViewForwarder(sal_False);
1005 :
1006 0 : if( pForwarder )
1007 0 : return pForwarder->PixelToLogic( rPoint, rMapMode );
1008 : }
1009 0 : else if( IsValid() && mpModel )
1010 : {
1011 0 : MapMode aMapMode(mpWindow->GetMapMode());
1012 0 : aMapMode.SetOrigin(Point());
1013 0 : Point aPoint1( mpWindow->PixelToLogic( rPoint, aMapMode ) );
1014 : Point aPoint2( OutputDevice::LogicToLogic( aPoint1,
1015 : MapMode(mpModel->GetScaleUnit()),
1016 0 : rMapMode ) );
1017 : // #101029#
1018 0 : aPoint2.X() -= maTextOffset.X();
1019 0 : aPoint2.Y() -= maTextOffset.Y();
1020 :
1021 0 : return aPoint2;
1022 : }
1023 :
1024 0 : return Point();
1025 : }
1026 :
1027 0 : IMPL_LINK(SvxTextEditSourceImpl, NotifyHdl, EENotify*, aNotify)
1028 : {
1029 0 : if( aNotify && !mbNotificationsDisabled )
1030 : {
1031 0 : boost::scoped_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( aNotify) );
1032 :
1033 0 : if( aHint.get() )
1034 0 : Broadcast( *aHint.get() );
1035 : }
1036 :
1037 0 : return 0;
1038 : }
1039 :
1040 :
1041 :
1042 :
1043 : // SvxTextEditSource
1044 :
1045 :
1046 0 : SvxTextEditSource::SvxTextEditSource( SdrObject* pObject, SdrText* pText, XInterface* pOwner )
1047 : {
1048 0 : mpImpl = new SvxTextEditSourceImpl( pObject, pText, pOwner );
1049 0 : mpImpl->acquire();
1050 0 : }
1051 :
1052 :
1053 0 : SvxTextEditSource::SvxTextEditSource( SdrObject& rObj, SdrText* pText, SdrView& rView, const Window& rWindow )
1054 : {
1055 0 : mpImpl = new SvxTextEditSourceImpl( rObj, pText, rView, rWindow );
1056 0 : mpImpl->acquire();
1057 0 : }
1058 :
1059 :
1060 :
1061 0 : SvxTextEditSource::SvxTextEditSource( SvxTextEditSourceImpl* pImpl )
1062 : {
1063 0 : mpImpl = pImpl;
1064 0 : mpImpl->acquire();
1065 0 : }
1066 :
1067 :
1068 0 : SvxTextEditSource::~SvxTextEditSource()
1069 : {
1070 0 : ::SolarMutexGuard aGuard;
1071 :
1072 0 : mpImpl->release();
1073 0 : }
1074 :
1075 :
1076 0 : SvxEditSource* SvxTextEditSource::Clone() const
1077 : {
1078 0 : return new SvxTextEditSource( mpImpl );
1079 : }
1080 :
1081 :
1082 0 : SvxTextForwarder* SvxTextEditSource::GetTextForwarder()
1083 : {
1084 0 : return mpImpl->GetTextForwarder();
1085 : }
1086 :
1087 :
1088 0 : SvxEditViewForwarder* SvxTextEditSource::GetEditViewForwarder( bool bCreate )
1089 : {
1090 0 : return mpImpl->GetEditViewForwarder( bCreate );
1091 : }
1092 :
1093 :
1094 0 : SvxViewForwarder* SvxTextEditSource::GetViewForwarder()
1095 : {
1096 0 : return this;
1097 : }
1098 :
1099 :
1100 0 : void SvxTextEditSource::UpdateData()
1101 : {
1102 0 : mpImpl->UpdateData();
1103 0 : }
1104 :
1105 0 : SfxBroadcaster& SvxTextEditSource::GetBroadcaster() const
1106 : {
1107 0 : return *mpImpl;
1108 : }
1109 :
1110 0 : void SvxTextEditSource::lock()
1111 : {
1112 0 : mpImpl->lock();
1113 0 : }
1114 :
1115 0 : void SvxTextEditSource::unlock()
1116 : {
1117 0 : mpImpl->unlock();
1118 0 : }
1119 :
1120 0 : bool SvxTextEditSource::IsValid() const
1121 : {
1122 0 : return mpImpl->IsValid();
1123 : }
1124 :
1125 0 : Rectangle SvxTextEditSource::GetVisArea() const
1126 : {
1127 0 : return mpImpl->GetVisArea();
1128 : }
1129 :
1130 0 : Point SvxTextEditSource::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
1131 : {
1132 0 : return mpImpl->LogicToPixel( rPoint, rMapMode );
1133 : }
1134 :
1135 0 : Point SvxTextEditSource::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
1136 : {
1137 0 : return mpImpl->PixelToLogic( rPoint, rMapMode );
1138 : }
1139 :
1140 0 : void SvxTextEditSource::addRange( SvxUnoTextRangeBase* pNewRange )
1141 : {
1142 0 : mpImpl->addRange( pNewRange );
1143 0 : }
1144 :
1145 0 : void SvxTextEditSource::removeRange( SvxUnoTextRangeBase* pOldRange )
1146 : {
1147 0 : mpImpl->removeRange( pOldRange );
1148 0 : }
1149 :
1150 0 : const SvxUnoTextRangeBaseList& SvxTextEditSource::getRanges() const
1151 : {
1152 0 : return mpImpl->getRanges();
1153 : }
1154 :
1155 0 : void SvxTextEditSource::ChangeModel( SdrModel* pNewModel )
1156 : {
1157 0 : mpImpl->ChangeModel( pNewModel );
1158 0 : }
1159 :
1160 0 : void SvxTextEditSource::UpdateOutliner()
1161 : {
1162 0 : mpImpl->UpdateOutliner();
1163 0 : }
1164 :
1165 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|