1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_sd.hxx" 29 30 #include "CanvasUpdateRequester.hxx" 31 #include <vcl/svapp.hxx> 32 #include <com/sun/star/lang/XComponent.hpp> 33 34 using namespace ::com::sun::star; 35 using namespace ::com::sun::star::uno; 36 using ::rtl::OUString; 37 38 namespace sd { namespace presenter { 39 40 //===== CanvasUpdateRequester::Deleter ======================================== 41 42 class CanvasUpdateRequester::Deleter 43 { 44 public: 45 void operator() (CanvasUpdateRequester* pObject) { delete pObject; } 46 }; 47 48 49 50 51 //===== CanvasUpdateRequester ================================================= 52 53 CanvasUpdateRequester::RequesterMap CanvasUpdateRequester::maRequesterMap; 54 55 ::boost::shared_ptr<CanvasUpdateRequester> CanvasUpdateRequester::Instance ( 56 const Reference<rendering::XSpriteCanvas>& rxSharedCanvas) 57 { 58 RequesterMap::const_iterator iRequester; 59 for (iRequester=maRequesterMap.begin(); iRequester!=maRequesterMap.end(); ++iRequester) 60 { 61 if (iRequester->first == rxSharedCanvas) 62 return iRequester->second; 63 } 64 65 // No requester for the given canvas found. Create a new one. 66 ::boost::shared_ptr<CanvasUpdateRequester> pRequester ( 67 new CanvasUpdateRequester(rxSharedCanvas), Deleter()); 68 maRequesterMap.push_back(RequesterMap::value_type(rxSharedCanvas,pRequester)); 69 return pRequester; 70 } 71 72 73 74 75 CanvasUpdateRequester::CanvasUpdateRequester ( 76 const Reference<rendering::XSpriteCanvas>& rxCanvas) 77 : mxCanvas(rxCanvas), 78 mnUserEventId(0), 79 mbUpdateFlag(sal_False) 80 { 81 Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY); 82 if (xComponent.is()) 83 { 84 //xComponent->addEventListener(this); 85 } 86 } 87 88 89 90 91 CanvasUpdateRequester::~CanvasUpdateRequester (void) 92 { 93 if (mnUserEventId != 0) 94 Application::RemoveUserEvent(mnUserEventId); 95 } 96 97 98 99 100 void CanvasUpdateRequester::RequestUpdate (const sal_Bool bUpdateAll) 101 { 102 if (mnUserEventId == 0) 103 { 104 mbUpdateFlag = bUpdateAll; 105 mnUserEventId = Application::PostUserEvent(LINK(this, CanvasUpdateRequester, Callback)); 106 } 107 else 108 { 109 mbUpdateFlag |= bUpdateAll; 110 } 111 } 112 113 114 115 IMPL_LINK(CanvasUpdateRequester, Callback, void*, EMPTYARG) 116 { 117 mnUserEventId = 0; 118 if (mxCanvas.is()) 119 { 120 mxCanvas->updateScreen(mbUpdateFlag); 121 mbUpdateFlag = sal_False; 122 } 123 return 0; 124 } 125 126 127 } } // end of namespace ::sd::presenter 128