1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sd.hxx"
25 
26 #include "CanvasUpdateRequester.hxx"
27 #include <vcl/svapp.hxx>
28 #include <com/sun/star/lang/XComponent.hpp>
29 
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::uno;
32 using ::rtl::OUString;
33 
34 namespace sd { namespace presenter {
35 
36 //===== CanvasUpdateRequester::Deleter ========================================
37 
38 class CanvasUpdateRequester::Deleter
39 {
40 public:
operator ()(CanvasUpdateRequester * pObject)41     void operator() (CanvasUpdateRequester* pObject) { delete pObject; }
42 };
43 
44 
45 
46 
47 //===== CanvasUpdateRequester =================================================
48 
49 CanvasUpdateRequester::RequesterMap CanvasUpdateRequester::maRequesterMap;
50 
Instance(const Reference<rendering::XSpriteCanvas> & rxSharedCanvas)51 ::boost::shared_ptr<CanvasUpdateRequester> CanvasUpdateRequester::Instance (
52     const Reference<rendering::XSpriteCanvas>& rxSharedCanvas)
53 {
54     RequesterMap::const_iterator iRequester;
55     for (iRequester=maRequesterMap.begin(); iRequester!=maRequesterMap.end(); ++iRequester)
56     {
57         if (iRequester->first == rxSharedCanvas)
58             return iRequester->second;
59     }
60 
61     // No requester for the given canvas found.  Create a new one.
62     ::boost::shared_ptr<CanvasUpdateRequester> pRequester (
63         new CanvasUpdateRequester(rxSharedCanvas), Deleter());
64     maRequesterMap.push_back(RequesterMap::value_type(rxSharedCanvas,pRequester));
65     return pRequester;
66 }
67 
68 
69 
70 
CanvasUpdateRequester(const Reference<rendering::XSpriteCanvas> & rxCanvas)71 CanvasUpdateRequester::CanvasUpdateRequester (
72     const Reference<rendering::XSpriteCanvas>& rxCanvas)
73     : mxCanvas(rxCanvas),
74       mnUserEventId(0),
75       mbUpdateFlag(sal_False)
76 {
77     Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY);
78     if (xComponent.is())
79     {
80         //xComponent->addEventListener(this);
81     }
82 }
83 
84 
85 
86 
~CanvasUpdateRequester(void)87 CanvasUpdateRequester::~CanvasUpdateRequester (void)
88 {
89     if (mnUserEventId != 0)
90         Application::RemoveUserEvent(mnUserEventId);
91 }
92 
93 
94 
95 
RequestUpdate(const sal_Bool bUpdateAll)96 void CanvasUpdateRequester::RequestUpdate (const sal_Bool bUpdateAll)
97 {
98     if (mnUserEventId == 0)
99     {
100         mbUpdateFlag = bUpdateAll;
101         mnUserEventId = Application::PostUserEvent(LINK(this, CanvasUpdateRequester, Callback));
102     }
103     else
104     {
105         mbUpdateFlag |= bUpdateAll;
106     }
107 }
108 
109 
110 
IMPL_LINK(CanvasUpdateRequester,Callback,void *,EMPTYARG)111 IMPL_LINK(CanvasUpdateRequester, Callback, void*, EMPTYARG)
112 {
113     mnUserEventId = 0;
114     if (mxCanvas.is())
115     {
116         mxCanvas->updateScreen(mbUpdateFlag);
117         mbUpdateFlag = sal_False;
118     }
119     return 0;
120 }
121 
122 
123 } } // end of namespace ::sd::presenter
124