merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / presenter / CanvasUpdateRequester.cxx
blob11b3ad7829e7e2efc9b04b75ffd5db91882b9d5b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CanvasUpdateRequester.cxx,v $
11 * $Revision: 1.3 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
34 #include "CanvasUpdateRequester.hxx"
35 #include <vcl/svapp.hxx>
36 #include <com/sun/star/lang/XComponent.hpp>
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using ::rtl::OUString;
42 namespace sd { namespace presenter {
44 //===== CanvasUpdateRequester::Deleter ========================================
46 class CanvasUpdateRequester::Deleter
48 public:
49 void operator() (CanvasUpdateRequester* pObject) { delete pObject; }
55 //===== CanvasUpdateRequester =================================================
57 CanvasUpdateRequester::RequesterMap CanvasUpdateRequester::maRequesterMap;
59 ::boost::shared_ptr<CanvasUpdateRequester> CanvasUpdateRequester::Instance (
60 const Reference<rendering::XSpriteCanvas>& rxSharedCanvas)
62 RequesterMap::const_iterator iRequester;
63 for (iRequester=maRequesterMap.begin(); iRequester!=maRequesterMap.end(); ++iRequester)
65 if (iRequester->first == rxSharedCanvas)
66 return iRequester->second;
69 // No requester for the given canvas found. Create a new one.
70 ::boost::shared_ptr<CanvasUpdateRequester> pRequester (
71 new CanvasUpdateRequester(rxSharedCanvas), Deleter());
72 maRequesterMap.push_back(RequesterMap::value_type(rxSharedCanvas,pRequester));
73 return pRequester;
79 CanvasUpdateRequester::CanvasUpdateRequester (
80 const Reference<rendering::XSpriteCanvas>& rxCanvas)
81 : mxCanvas(rxCanvas),
82 mnUserEventId(0),
83 mbUpdateFlag(sal_False)
85 Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY);
86 if (xComponent.is())
88 //xComponent->addEventListener(this);
95 CanvasUpdateRequester::~CanvasUpdateRequester (void)
97 if (mnUserEventId != 0)
98 Application::RemoveUserEvent(mnUserEventId);
104 void CanvasUpdateRequester::RequestUpdate (const sal_Bool bUpdateAll)
106 if (mnUserEventId == 0)
108 mbUpdateFlag = bUpdateAll;
109 mnUserEventId = Application::PostUserEvent(LINK(this, CanvasUpdateRequester, Callback));
111 else
113 mbUpdateFlag |= bUpdateAll;
119 IMPL_LINK(CanvasUpdateRequester, Callback, void*, EMPTYARG)
121 mnUserEventId = 0;
122 if (mxCanvas.is())
124 mxCanvas->updateScreen(mbUpdateFlag);
125 mbUpdateFlag = sal_False;
127 return 0;
131 } } // end of namespace ::sd::presenter