Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / embedserv / source / inprocserv / advisesink.cxx
blobeb6488c91c5837aa365f3ccbfd09ed710c483114
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #if defined _MSC_VER
21 #pragma warning(disable : 4668)
22 #endif
24 #include <advisesink.hxx>
26 namespace inprocserv
29 OleWrapperAdviseSink::OleWrapperAdviseSink()
30 : m_nRefCount( 0 )
31 , m_pFormatEtc( NULL )
32 , m_nAspect( DVASPECT_CONTENT )
33 , m_nRegID( 0 )
34 , m_bObjectAdvise( TRUE )
35 , m_nDataRegFlag( 0 )
36 , m_nViewRegFlag( 0 )
37 , m_bHandleClosed( TRUE )
38 , m_bClosed( FALSE )
42 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener )
43 : m_nRefCount( 0 )
44 , m_pListener( pListener )
45 , m_pFormatEtc( NULL )
46 , m_nAspect( DVASPECT_CONTENT )
47 , m_nRegID( 0 )
48 , m_bObjectAdvise( TRUE )
49 , m_nDataRegFlag( 0 )
50 , m_nViewRegFlag( 0 )
51 , m_bHandleClosed( FALSE )
52 , m_bClosed( FALSE )
56 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, FORMATETC* pFormatEtc, DWORD nDataRegFlag )
57 : m_nRefCount( 0 )
58 , m_pListener( pListener )
59 , m_pFormatEtc( NULL )
60 , m_nAspect( DVASPECT_CONTENT )
61 , m_nRegID( 0 )
62 , m_bObjectAdvise( FALSE )
63 , m_nDataRegFlag( nDataRegFlag )
64 , m_nViewRegFlag( 0 )
65 , m_bHandleClosed( FALSE )
66 , m_bClosed( FALSE )
68 if ( pFormatEtc )
70 m_pFormatEtc = new FORMATETC;
71 m_pFormatEtc->cfFormat = pFormatEtc->cfFormat;
72 m_pFormatEtc->ptd = NULL;
73 m_pFormatEtc->dwAspect = pFormatEtc->dwAspect;
74 m_pFormatEtc->lindex = pFormatEtc->lindex;
75 m_pFormatEtc->tymed = pFormatEtc->tymed;
79 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, DWORD nAspect, DWORD nViewRegFlag )
80 : m_nRefCount( 0 )
81 , m_pListener( pListener )
82 , m_pFormatEtc( NULL )
83 , m_nAspect( nAspect )
84 , m_nRegID( 0 )
85 , m_bObjectAdvise( TRUE )
86 , m_nDataRegFlag( 0 )
87 , m_nViewRegFlag( nViewRegFlag )
88 , m_bHandleClosed( FALSE )
89 , m_bClosed( FALSE )
93 OleWrapperAdviseSink::~OleWrapperAdviseSink()
95 delete m_pFormatEtc;
98 STDMETHODIMP OleWrapperAdviseSink::QueryInterface( REFIID riid , void** ppv )
100 *ppv=NULL;
102 if ( riid == IID_IUnknown )
103 *ppv = (IUnknown*)this;
105 if ( riid == IID_IAdviseSink )
106 *ppv = (IAdviseSink*)this;
108 if ( *ppv != NULL )
110 ((IUnknown*)*ppv)->AddRef();
111 return S_OK;
114 return E_NOINTERFACE;
117 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::AddRef()
119 return ++m_nRefCount;
122 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::Release()
124 ULONG nReturn = --m_nRefCount;
125 if ( m_nRefCount == 0 )
126 delete this;
128 return nReturn;
131 STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange( LPFORMATETC pFetc, LPSTGMEDIUM pMedium )
133 if ( m_pListener )
135 m_pListener->OnDataChange( pFetc, pMedium );
139 STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange( DWORD dwAspect, LONG lindex )
141 if ( m_pListener )
143 m_pListener->OnViewChange( dwAspect, lindex );
147 STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename( LPMONIKER pMoniker )
149 if ( m_pListener )
151 m_pListener->OnRename( pMoniker );
155 STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave()
157 if ( m_pListener )
159 m_pListener->OnSave();
163 STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose()
165 if ( m_pListener )
167 m_pListener->OnClose();
170 if ( m_bHandleClosed )
171 m_bClosed = TRUE;
174 } // namespace inprocserv
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */