xref: /AOO41X/main/embeddedobj/source/msole/advisesink.cxx (revision bfd08df8d53be340829eb05b5154718deb4e1b3d)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_embeddedobj.hxx"
26 
27 #include <osl/diagnose.h>
28 #include <advisesink.hxx>
29 #include <olecomponent.hxx>
30 
31 #include <rtl/ref.hxx>
32 
OleWrapperAdviseSink(OleComponent * pOleComp)33 OleWrapperAdviseSink::OleWrapperAdviseSink( OleComponent* pOleComp )
34 : m_nRefCount( 0 )
35 , m_pOleComp( pOleComp )
36 {
37     OSL_ENSURE( m_pOleComp, "No ole component is provided!\n" );
38 }
39 
~OleWrapperAdviseSink()40 OleWrapperAdviseSink::~OleWrapperAdviseSink()
41 {
42 }
43 
QueryInterface(REFIID riid,void ** ppv)44 STDMETHODIMP OleWrapperAdviseSink::QueryInterface( REFIID riid , void** ppv )
45 {
46     *ppv=NULL;
47 
48     if ( riid == IID_IUnknown )
49         *ppv = (IUnknown*)this;
50 
51     if ( riid == IID_IAdviseSink )
52         *ppv = (IAdviseSink*)this;
53 
54     if ( *ppv != NULL )
55     {
56         ((IUnknown*)*ppv)->AddRef();
57         return S_OK;
58     }
59 
60     return E_NOINTERFACE;
61 }
62 
STDMETHODIMP_(ULONG)63 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::AddRef()
64 {
65     return osl_incrementInterlockedCount( &m_nRefCount);
66 }
67 
STDMETHODIMP_(ULONG)68 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::Release()
69 {
70     ULONG nReturn = --m_nRefCount;
71     if ( m_nRefCount == 0 )
72         delete this;
73 
74     return nReturn;
75 }
76 
disconnectOleComponent()77 void OleWrapperAdviseSink::disconnectOleComponent()
78 {
79     // must not be called from the descructor of OleComponent!!!
80     osl::MutexGuard aGuard( m_aMutex );
81     m_pOleComp = NULL;
82 }
83 
STDMETHODIMP_(void)84 STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange(LPFORMATETC, LPSTGMEDIUM)
85 {
86     // Unused for now ( no registration for IDataObject events )
87 }
88 
STDMETHODIMP_(void)89 STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange(DWORD dwAspect, LONG)
90 {
91     ::rtl::Reference< OleComponent > xLockComponent;
92 
93     {
94         osl::MutexGuard aGuard( m_aMutex );
95         if ( m_pOleComp )
96             xLockComponent = m_pOleComp;
97     }
98 
99     if ( xLockComponent.is() )
100         xLockComponent->OnViewChange_Impl( dwAspect );
101 }
102 
STDMETHODIMP_(void)103 STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename(LPMONIKER)
104 {
105     // handled by default inprocess handler
106 }
107 
STDMETHODIMP_(void)108 STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave(void)
109 {
110     // TODO: ???
111     // The object knows about document saving already since it contolls it as ClienSite
112     // other interested listeners must be registered for the object
113 }
114 
STDMETHODIMP_(void)115 STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose(void)
116 {
117     ::rtl::Reference< OleComponent > xLockComponent;
118 
119     {
120         osl::MutexGuard aGuard( m_aMutex );
121         if ( m_pOleComp )
122             xLockComponent = m_pOleComp;
123     }
124 
125     if ( xLockComponent.is() )
126         xLockComponent->OnClose_Impl();
127 
128     // TODO: sometimes it can be necessary to simulate OnShowWindow( False ) here
129 }
130 
131