summaryrefslogtreecommitdiff
path: root/svx/source/sdr/contact/objectcontact.cxx
blob: d404785af481df6b5a9147df03ca793429f6a837 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: objectcontact.cxx,v $
 * $Revision: 1.16 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"
#include <svx/sdr/contact/objectcontact.hxx>
#include <tools/debug.hxx>
#include <svx/sdr/contact/viewobjectcontact.hxx>
#include <svx/svdpage.hxx>
#include <svx/sdr/contact/viewcontact.hxx>
#include <svx/sdr/event/eventhandler.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <svx/sdr/animation/objectanimator.hxx>
#include <svx/sdr/event/eventhandler.hxx>

//////////////////////////////////////////////////////////////////////////////

using namespace com::sun::star;

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ObjectContact::ObjectContact()
        :   maViewObjectContactVector(),
            maPrimitiveAnimator(),
            mpEventHandler(0),
            mpViewObjectContactRedirector(0),
            maViewInformation2D(uno::Sequence< beans::PropertyValue >()),
            mbIsPreviewRenderer(false)
        {
        }

        ObjectContact::~ObjectContact()
        {
            // get rid of all registered contacts
            // #i84257# To avoid that each 'delete pCandidate' again uses
            // the local RemoveViewObjectContact with a search and removal in the
            // vector, simply copy and clear local vector.
            std::vector< ViewObjectContact* > aLocalVOCList(maViewObjectContactVector);
            maViewObjectContactVector.clear();

            while(aLocalVOCList.size())
            {
                ViewObjectContact* pCandidate = aLocalVOCList.back();
                aLocalVOCList.pop_back();
                DBG_ASSERT(pCandidate, "Corrupted ViewObjectContactList (!)");

                // ViewObjectContacts only make sense with View and Object contacts.
                // When the contact to the SdrObject is deleted like in this case,
                // all ViewObjectContacts can be deleted, too.
                delete pCandidate;
            }

            // assert when there were new entries added during deletion
            DBG_ASSERT(maViewObjectContactVector.empty(), "Corrupted ViewObjectContactList (!)");

            // delete the EventHandler. This will destroy all still contained events.
            DeleteEventHandler();
        }

        // LazyInvalidate request. Default implementation directly handles
        // this by calling back triggerLazyInvalidate() at the VOC
        void ObjectContact::setLazyInvalidate(ViewObjectContact& rVOC)
        {
            rVOC.triggerLazyInvalidate();
        }

        // call this to support evtl. preparations for repaint. Default does nothing
        void ObjectContact::PrepareProcessDisplay()
        {
        }

        // A new ViewObjectContact was created and shall be remembered.
        void ObjectContact::AddViewObjectContact(ViewObjectContact& rVOContact)
        {
            maViewObjectContactVector.push_back(&rVOContact);
        }

        // A ViewObjectContact was deleted and shall be forgotten.
        void ObjectContact::RemoveViewObjectContact(ViewObjectContact& rVOContact)
        {
            std::vector< ViewObjectContact* >::iterator aFindResult = std::find(maViewObjectContactVector.begin(), maViewObjectContactVector.end(), &rVOContact);

            if(aFindResult != maViewObjectContactVector.end())
            {
                maViewObjectContactVector.erase(aFindResult);
            }
        }

        // Process the whole displaying
        void ObjectContact::ProcessDisplay(DisplayInfo& /*rDisplayInfo*/)
        {
            // default does nothing
        }

        // test if visualizing of entered groups is switched on at all
        bool ObjectContact::DoVisualizeEnteredGroup() const
        {
            // Don not do that as default
            return false;
        }

        // get active group's (the entered group) ViewContact
        const ViewContact* ObjectContact::getActiveViewContact() const
        {
            // default has no active VC
            return 0;
        }

        // Invalidate given rectangle at the window/output which is represented by
        // this ObjectContact.
        void ObjectContact::InvalidatePartOfView(const basegfx::B2DRange& /*rRange*/) const
        {
            // nothing to do here in the default version
        }

        // Get info if given Rectangle is visible in this view
        bool ObjectContact::IsAreaVisible(const basegfx::B2DRange& /*rRange*/) const
        {
            // always visible in default version
            return true;
        }

        // Get info about the need to visualize GluePoints
        bool ObjectContact::AreGluePointsVisible() const
        {
            return false;
        }

        // method to create a EventHandler. Needs to give a result.
        sdr::event::TimerEventHandler* ObjectContact::CreateEventHandler()
        {
            // Create and return a new EventHandler
            return new sdr::event::TimerEventHandler();
        }

        // method to get the primitiveAnimator
        sdr::animation::primitiveAnimator& ObjectContact::getPrimitiveAnimator()
        {
            return maPrimitiveAnimator;
        }

        // method to get the EventHandler. It will
        // return a existing one or create a new one using CreateEventHandler().
        sdr::event::TimerEventHandler& ObjectContact::GetEventHandler() const
        {
            if(!HasEventHandler())
            {
                const_cast< ObjectContact* >(this)->mpEventHandler = const_cast< ObjectContact* >(this)->CreateEventHandler();
                DBG_ASSERT(mpEventHandler, "ObjectContact::GetEventHandler(): Got no EventHandler (!)");
            }

            return *mpEventHandler;
        }

        // delete the EventHandler
        void ObjectContact::DeleteEventHandler()
        {
            if(mpEventHandler)
            {
                // If there are still Events registered, something has went wrong
                delete mpEventHandler;
                mpEventHandler = 0L;
            }
        }

        // test if there is an EventHandler without creating one on demand
        bool ObjectContact::HasEventHandler() const
        {
            return (0L != mpEventHandler);
        }

        // check if text animation is allowed. Default is sal_true.
        bool ObjectContact::IsTextAnimationAllowed() const
        {
            return true;
        }

        // check if graphic animation is allowed. Default is sal_true.
        bool ObjectContact::IsGraphicAnimationAllowed() const
        {
            return true;
        }

        // check if asynchronious graphis loading is allowed. Default is false.
        bool ObjectContact::IsAsynchronGraphicsLoadingAllowed() const
        {
            return false;
        }

        // access to ViewObjectContactRedirector
        ViewObjectContactRedirector* ObjectContact::GetViewObjectContactRedirector() const
        {
            return mpViewObjectContactRedirector;
        }

        void ObjectContact::SetViewObjectContactRedirector(ViewObjectContactRedirector* pNew)
        {
            if(mpViewObjectContactRedirector != pNew)
            {
                mpViewObjectContactRedirector = pNew;
            }
        }

        // check if buffering of MasterPages is allowed. Default is false.
        bool ObjectContact::IsMasterPageBufferingAllowed() const
        {
            return false;
        }

        // print? Default is false
        bool ObjectContact::isOutputToPrinter() const
        {
            return false;
        }

        // window? Default is true
        bool ObjectContact::isOutputToWindow() const
        {
            return true;
        }

        // VirtualDevice? Default is false
        bool ObjectContact::isOutputToVirtualDevice() const
        {
            return false;
        }

        // recording MetaFile? Default is false
        bool ObjectContact::isOutputToRecordingMetaFile() const
        {
            return false;
        }

        // pdf export? Default is false
        bool ObjectContact::isOutputToPDFFile() const
        {
            return false;
        }

        // gray display mode
        bool ObjectContact::isDrawModeGray() const
        {
            return false;
        }

        // gray display mode
        bool ObjectContact::isDrawModeBlackWhite() const
        {
            return false;
        }

        // high contrast display mode
        bool ObjectContact::isDrawModeHighContrast() const
        {
            return false;
        }

        // access to SdrPageView. Default implementation returns NULL
        SdrPageView* ObjectContact::TryToGetSdrPageView() const
        {
            return 0;
        }

        // access to OutputDevice. Default implementation returns NULL
        OutputDevice* ObjectContact::TryToGetOutputDevice() const
        {
            return 0;
        }

        void ObjectContact::resetViewPort()
        {
            const drawinglayer::geometry::ViewInformation2D& rCurrentVI2D = getViewInformation2D();

            if(!rCurrentVI2D.getViewport().isEmpty())
            {
                const basegfx::B2DRange aEmptyRange;

                drawinglayer::geometry::ViewInformation2D aNewVI2D(
                    rCurrentVI2D.getObjectTransformation(),
                    rCurrentVI2D.getViewTransformation(),
                    aEmptyRange,
                    rCurrentVI2D.getVisualizedPage(),
                    rCurrentVI2D.getViewTime(),
                    rCurrentVI2D.getExtendedInformationSequence());

                updateViewInformation2D(aNewVI2D);
            }
        }

    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////
// eof