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