LibreOffice Module embeddedobj (master) 1
advisesink.cxx
Go to the documentation of this file.
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 <osl/diagnose.h>
21#include "advisesink.hxx"
22#include "olecomponent.hxx"
23
24#include <rtl/ref.hxx>
25
27: m_nRefCount( 0 )
28, m_pOleComp( pOleComp )
29{
30 OSL_ENSURE( m_pOleComp, "No ole component is provided!" );
31}
32
34{
35}
36
37STDMETHODIMP OleWrapperAdviseSink::QueryInterface( REFIID riid , void** ppv )
38{
39 *ppv=nullptr;
40
41 if ( riid == IID_IUnknown )
42 *ppv = static_cast<IUnknown*>(this);
43
44 if ( riid == IID_IAdviseSink )
45 *ppv = static_cast<IAdviseSink*>(this);
46
47 if ( *ppv != nullptr )
48 {
49 static_cast<IUnknown*>(*ppv)->AddRef();
50 return S_OK;
51 }
52
53 return E_NOINTERFACE;
54}
55
56STDMETHODIMP_(ULONG) OleWrapperAdviseSink::AddRef()
57{
58 return osl_atomic_increment( &m_nRefCount);
59}
60
61STDMETHODIMP_(ULONG) OleWrapperAdviseSink::Release()
62{
63 ULONG nReturn = --m_nRefCount;
64 if ( m_nRefCount == 0 )
65 delete this;
66
67 return nReturn;
68}
69
71{
72 // must not be called from the descructor of OleComponent!!!
73 osl::MutexGuard aGuard( m_aMutex );
74 m_pOleComp = nullptr;
75}
76
77STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange(FORMATETC *, STGMEDIUM *)
78{
79 // Unused for now ( no registration for IDataObject events )
80}
81
82STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange(DWORD dwAspect, LONG)
83{
85
86 {
87 osl::MutexGuard aGuard( m_aMutex );
88 if ( m_pOleComp )
89 xLockComponent = m_pOleComp;
90 }
91
92 if ( xLockComponent.is() )
93 xLockComponent->OnViewChange_Impl( dwAspect );
94}
95
96STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename(IMoniker *)
97{
98 // handled by default inprocess handler
99}
100
101STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave()
102{
103 // TODO: ???
104 // The object already knows about document saving, since it controls it as ClientSide
105 // other interested listeners must be registered for the object
106}
107
108STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose()
109{
111
112 {
113 osl::MutexGuard aGuard( m_aMutex );
114 if ( m_pOleComp )
115 xLockComponent = m_pOleComp;
116 }
117
118 if ( xLockComponent.is() )
119 xLockComponent->OnClose_Impl();
120
121 // TODO: sometimes it can be necessary to simulate OnShowWindow( False ) here
122}
123
124/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
STDMETHODIMP_(ULONG) OleWrapperAdviseSink
Definition: advisesink.cxx:56
virtual ~OleWrapperAdviseSink()
Definition: advisesink.cxx:33
STDMETHODIMP QueryInterface(REFIID, void **) override
Definition: advisesink.cxx:37
void disconnectOleComponent()
Definition: advisesink.cxx:70
OleComponent * m_pOleComp
Definition: advisesink.hxx:32
oslInterlockedCount m_nRefCount
Definition: advisesink.hxx:31