1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include "advisesink.hxx"
23 
24 namespace inprocserv
25 {
26 
OleWrapperAdviseSink()27 OleWrapperAdviseSink::OleWrapperAdviseSink()
28 : m_nRefCount( 0 )
29 , m_nAspect( DVASPECT_CONTENT )
30 , m_nRegID( 0 )
31 , m_bObjectAdvise( TRUE )
32 , m_nDataRegFlag( 0 )
33 , m_nViewRegFlag( 0 )
34 , m_bHandleClosed( TRUE )
35 , m_bClosed( FALSE )
36 {
37 }
38 
OleWrapperAdviseSink(const ComSmart<IAdviseSink> & pListener)39 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener )
40 : m_nRefCount( 0 )
41 , m_pListener( pListener )
42 , m_nAspect( DVASPECT_CONTENT )
43 , m_nRegID( 0 )
44 , m_bObjectAdvise( TRUE )
45 , m_nDataRegFlag( 0 )
46 , m_nViewRegFlag( 0 )
47 , m_bHandleClosed( FALSE )
48 , m_bClosed( FALSE )
49 {
50 }
51 
OleWrapperAdviseSink(const ComSmart<IAdviseSink> & pListener,FORMATETC * pFormatEtc,DWORD nDataRegFlag)52 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, FORMATETC* pFormatEtc, DWORD nDataRegFlag )
53 : m_nRefCount( 0 )
54 , m_pListener( pListener )
55 , m_nAspect( DVASPECT_CONTENT )
56 , m_nRegID( 0 )
57 , m_bObjectAdvise( FALSE )
58 , m_nDataRegFlag( nDataRegFlag )
59 , m_nViewRegFlag( 0 )
60 , m_bHandleClosed( FALSE )
61 , m_bClosed( FALSE )
62 {
63     if ( pFormatEtc )
64     {
65         m_pFormatEtc = std::make_unique<FORMATETC>();
66         m_pFormatEtc->cfFormat = pFormatEtc->cfFormat;
67         m_pFormatEtc->ptd = nullptr;
68         m_pFormatEtc->dwAspect = pFormatEtc->dwAspect;
69         m_pFormatEtc->lindex = pFormatEtc->lindex;
70         m_pFormatEtc->tymed = pFormatEtc->tymed;
71     }
72 }
73 
OleWrapperAdviseSink(const ComSmart<IAdviseSink> & pListener,DWORD nAspect,DWORD nViewRegFlag)74 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, DWORD nAspect, DWORD nViewRegFlag )
75 : m_nRefCount( 0 )
76 , m_pListener( pListener )
77 , m_nAspect( nAspect )
78 , m_nRegID( 0 )
79 , m_bObjectAdvise( TRUE )
80 , m_nDataRegFlag( 0 )
81 , m_nViewRegFlag( nViewRegFlag )
82 , m_bHandleClosed( FALSE )
83 , m_bClosed( FALSE )
84 {
85 }
86 
~OleWrapperAdviseSink()87 OleWrapperAdviseSink::~OleWrapperAdviseSink()
88 {}
89 
QueryInterface(REFIID riid,void ** ppv)90 STDMETHODIMP OleWrapperAdviseSink::QueryInterface( REFIID riid , void** ppv )
91 {
92     *ppv=nullptr;
93 
94     if ( riid == IID_IUnknown )
95         *ppv = static_cast<IUnknown*>(this);
96 
97     if ( riid == IID_IAdviseSink )
98         *ppv = static_cast<IAdviseSink*>(this);
99 
100     if ( *ppv != nullptr )
101     {
102         static_cast<IUnknown*>(*ppv)->AddRef();
103         return S_OK;
104     }
105 
106     return E_NOINTERFACE;
107 }
108 
STDMETHODIMP_(ULONG)109 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::AddRef()
110 {
111     return ++m_nRefCount;
112 }
113 
STDMETHODIMP_(ULONG)114 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::Release()
115 {
116     ULONG nReturn = --m_nRefCount;
117     if ( m_nRefCount == 0 )
118         delete this;
119 
120     return nReturn;
121 }
122 
STDMETHODIMP_(void)123 STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange( FORMATETC * pFetc, STGMEDIUM * pMedium )
124 {
125     if ( m_pListener )
126     {
127         m_pListener->OnDataChange( pFetc, pMedium );
128     }
129 }
130 
STDMETHODIMP_(void)131 STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange( DWORD dwAspect, LONG lindex )
132 {
133     if ( m_pListener )
134     {
135         m_pListener->OnViewChange( dwAspect, lindex );
136     }
137 }
138 
STDMETHODIMP_(void)139 STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename( IMoniker * pMoniker )
140 {
141     if ( m_pListener )
142     {
143         m_pListener->OnRename( pMoniker );
144     }
145 }
146 
STDMETHODIMP_(void)147 STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave()
148 {
149     if ( m_pListener )
150     {
151         m_pListener->OnSave();
152     }
153 }
154 
STDMETHODIMP_(void)155 STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose()
156 {
157     if ( m_pListener )
158     {
159         m_pListener->OnClose();
160     }
161 
162     if ( m_bHandleClosed )
163         m_bClosed = TRUE;
164 }
165 
166 } // namespace inprocserv
167 
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
169