LibreOffice Module embedserv (master) 1
inprocembobj.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 <sal/types.h>
21
22#include <embservconst.h>
23#include "inprocembobj.h"
24
25namespace inprocserv
26{
27
28namespace {
29
30class ULONGGuard
31{
32 ULONG& m_rValue;
33
34public:
35 explicit ULONGGuard( ULONG& rValue )
36 : m_rValue( ++rValue )
37 {
38 }
39
40 ~ULONGGuard() { --m_rValue; }
41};
42
43void SetName( LPCOLESTR pszNameFromOutside, wchar_t*& pOwnName )
44{
45 if ( !pszNameFromOutside )
46 return;
47
48 // copy the string
49 size_t nLen = 0;
50 while( pszNameFromOutside[nLen] != 0 )
51 nLen++;
52
53 if ( pOwnName )
54 {
55 delete[] pOwnName;
56 pOwnName = nullptr;
57 }
58
59 pOwnName = new wchar_t[nLen+1];
60 for ( size_t nInd = 0; nInd < nLen; nInd++ )
61 pOwnName[nInd] = pszNameFromOutside[nInd];
62 pOwnName[nLen] = 0;
63}
64
65DWORD InsertAdviseLinkToList( const sal::systools::COMReference<OleWrapperAdviseSink>& pOwnAdvise, sal::systools::COMReference< OleWrapperAdviseSink > pAdvises[] )
66{
67 // the result should start from 1 in case of success, the element 0 can be used for own needs
68 DWORD nResult = 0;
69
70 if ( pOwnAdvise )
71 {
72 for ( DWORD nInd = 1; nInd < DEFAULT_ARRAY_LEN && nResult == 0; nInd++ )
73 {
74 if ( pAdvises[nInd].get() == pOwnAdvise.get() )
75 {
76 nResult = nInd;
77 }
78 else if ( pAdvises[nInd] == nullptr )
79 {
80 pAdvises[nInd] = pOwnAdvise;
81 nResult = nInd;
82 }
83 }
84 }
85
86 return nResult;
87}
88
89}
90
92{
93 // set the own listener
94 if ( m_pOleAdvises[0] == nullptr )
95 {
97 }
98 else
99 {
100 if ( m_pOleAdvises[0]->IsClosed() )
101 {
102 if ( m_pDefHandler )
103 {
104 // deregister all the listeners
105
106 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
107 if ( pOleObject )
108 {
109 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
110 if ( m_pOleAdvises[nInd] )
111 {
112 DWORD nID = m_pOleAdvises[nInd]->GetRegID();
113 pOleObject->Unadvise( nID );
114 m_pOleAdvises[nInd]->SetRegID( 0 );
115 }
116
117 pOleObject->SetClientSite( nullptr );
118 }
119
120 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
121 if ( pIDataObject )
122 {
123 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
124 if ( m_pDataAdvises[nInd] )
125 {
126 DWORD nID = m_pDataAdvises[nInd]->GetRegID();
127 pIDataObject->DUnadvise( nID );
128 m_pDataAdvises[nInd]->SetRegID( 0 );
129 }
130 }
131
132 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
133 if ( pIViewObject )
134 {
135 if ( m_pViewAdvise )
136 pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), nullptr );
137 }
138
139 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
140 if ( pPersist )
141 {
142 // disconnect the old wrapper from the storage
143 pPersist->HandsOffStorage();
144 }
145
146 m_pDefHandler = nullptr;
147 }
148
149 m_pOleAdvises[0]->UnsetClosed();
150 }
151 }
152
153 if ( m_nCallsOnStack )
154 return FALSE;
155
156 if ( !m_pDefHandler )
157 {
158 // create a new default inprocess handler
159 HRESULT hr = OleCreateDefaultHandler( m_guid, nullptr, IID_IUnknown, reinterpret_cast<void**>(&m_pDefHandler) );
160 if ( SUCCEEDED( hr ) )
161 {
163 {
164 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
165
166 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
167 if ( pPersist && m_pStorage )
168 hr = pPersist->InitNew( m_pStorage.get() );
169 }
170 else if ( m_nInitMode == LOAD_FROM_STORAGE )
171 {
172 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
173
174 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
175 if ( pPersist && m_pStorage )
176 hr = pPersist->Load( m_pStorage.get() );
177 }
178 else if ( m_nInitMode == LOAD_FROM_FILE )
179 {
180 sal::systools::COMReference< IPersistFile > pPersistFile(m_pDefHandler, sal::systools::COM_QUERY);
181
182 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
183 if ( pPersistFile && m_pFileName )
184 hr = pPersistFile->Load( m_pFileName, m_nFileOpenMode );
185 }
186 }
187
188 if ( !SUCCEEDED( hr ) || !m_pDefHandler )
189 {
190 m_pDefHandler = nullptr;
191 return FALSE;
192 }
193
194 // register all the listeners new
195
196 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
197 if ( pOleObject )
198 {
199 if ( m_pClientSite )
200 pOleObject->SetClientSite( m_pClientSite.get() );
201
202 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
203 if ( m_pOleAdvises[nInd] )
204 {
205 DWORD nRegID = 0;
206 if ( SUCCEEDED( pOleObject->Advise( m_pOleAdvises[nInd].get(), &nRegID ) ) && nRegID > 0 )
207 m_pOleAdvises[nInd]->SetRegID( nRegID );
208 }
209 }
210
211 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
212 if ( pIDataObject )
213 {
214 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
215 if ( m_pDataAdvises[nInd] )
216 {
217 DWORD nRegID = 0;
218 if ( SUCCEEDED( pIDataObject->DAdvise( m_pDataAdvises[nInd]->GetFormatEtc(), m_pDataAdvises[nInd]->GetDataAdviseFlag(), m_pDataAdvises[nInd].get(), &nRegID ) ) && nRegID > 0 )
219 m_pDataAdvises[nInd]->SetRegID( nRegID );
220 }
221 }
222
223 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
224 if ( pIViewObject )
225 {
226 if ( m_pViewAdvise )
227 pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), m_pViewAdvise.get() );
228 }
229 }
230
231
232 return TRUE;
233}
234
236{
237 m_pDefHandler = nullptr;
238
239 // no DisconnectOrigAdvise() call here, since it is no explicit disconnection
240 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
241 {
242 m_pOleAdvises[nInd].clear();
243 m_pDataAdvises[nInd].clear();
244 }
245
246 m_pViewAdvise = nullptr;
247
249 m_pStorage = nullptr;
250
251 if ( m_pOleContainer )
252 {
253 m_pOleContainer->LockContainer( FALSE );
254 m_pOleContainer = nullptr;
255 }
256
257 m_pClientSite = nullptr;
258
259 m_nFileOpenMode = 0;
260 if ( m_pFileName )
261 {
262 delete m_pFileName;
263 m_pFileName = nullptr;
264 }
265}
266
267// IUnknown
268
269COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::QueryInterface(REFIID riid, void** ppv)
270{
271 if(IsEqualIID(riid, IID_IUnknown))
272 {
273 AddRef();
274 *ppv = static_cast<IUnknown*>(static_cast<IPersistStorage*>(this));
275 return S_OK;
276 }
277 else if (IsEqualIID(riid, IID_IPersist))
278 {
279 AddRef();
280 *ppv = static_cast<IPersist*>(static_cast<IPersistStorage*>(this));
281 return S_OK;
282 }
283 else if (IsEqualIID(riid, IID_IPersistStorage))
284 {
285 AddRef();
286 *ppv = static_cast<IPersistStorage*>(this);
287 return S_OK;
288 }
289 else if (IsEqualIID(riid, IID_IDataObject))
290 {
291 AddRef();
292 *ppv = static_cast<IDataObject*>(this);
293 return S_OK;
294 }
295 else if (IsEqualIID(riid, IID_IOleObject))
296 {
297 AddRef();
298 *ppv = static_cast<IOleObject*>(this);
299 return S_OK;
300 }
301 else if (IsEqualIID(riid, IID_IPersistFile))
302 {
303 AddRef();
304 *ppv = static_cast<IPersistFile*>(this);
305 return S_OK;
306 }
307 else if (IsEqualIID(riid, IID_IRunnableObject))
308 {
309 AddRef();
310 *ppv = static_cast<IRunnableObject*>(this);
311 return S_OK;
312 }
313 else if (IsEqualIID(riid, IID_IViewObject))
314 {
315 AddRef();
316 *ppv = static_cast<IViewObject*>(this);
317 return S_OK;
318 }
319 else if (IsEqualIID(riid, IID_IViewObject2))
320 {
321 AddRef();
322 *ppv = static_cast<IViewObject2*>(this);
323 return S_OK;
324 }
325 else if (IsEqualIID(riid, IID_IOleCache))
326 {
327 AddRef();
328 *ppv = static_cast<IOleCache*>(&m_aInternalCache);
329 return S_OK;
330 }
331 else if (IsEqualIID(riid, IID_IOleCache2))
332 {
333 AddRef();
334 *ppv = static_cast<IOleCache2*>(&m_aInternalCache);
335 return S_OK;
336 }
337 else if (IsEqualIID(riid, IID_IOleWindow))
338 {
339 AddRef();
340 *ppv = static_cast<IOleWindow*>(this);
341 return S_OK;
342 }
343 else if (IsEqualIID(riid, IID_IOleInPlaceObject))
344 {
345 AddRef();
346 *ppv = static_cast<IOleInPlaceObject*>(this);
347 return S_OK;
348 }
349 else if (IsEqualIID(riid, IID_IDispatch))
350 {
351 AddRef();
352 *ppv = static_cast<IDispatch*>(this);
353 return S_OK;
354 }
355
356 *ppv = nullptr;
357 return ResultFromScode(E_NOINTERFACE);
358}
359
360
361COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::AddRef()
362{
363 return ++m_refCount;
364}
365
366
367COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::Release()
368{
369 // unfortunately there are reentrance problems in mfc that have to be workarounded
370 sal_Int32 nCount = m_refCount > 0 ? --m_refCount : 0;
371 if ( nCount == 0 && !m_bDeleted )
372 {
373 // deleting of this object can trigger deleting of mfc objects that will try to delete this object one more time
375
376 Clean();
377 delete this;
378 }
379 return nCount;
380}
381
382// IPersist
383
384COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetClassID( CLSID* pClassId )
385{
386 *pClassId = m_guid;
387 return S_OK;
388}
389
390// IPersistStorage
391
392COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::IsDirty()
393{
394 if ( m_pDefHandler == nullptr || m_pOleAdvises[0] == nullptr || m_pOleAdvises[0]->IsClosed() )
395 return S_FALSE;
396
397 if ( CheckDefHandler() )
398 {
399 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
400
401 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
402 if ( pPersist )
403 return pPersist->IsDirty();
404 }
405
406 return E_FAIL;
407}
408
409
410COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InitNew( IStorage *pStg )
411{
412 if ( CheckDefHandler() )
413 {
414 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
415
416 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
417 if ( pPersist )
418 {
419 HRESULT hr = pPersist->InitNew( pStg );
420 if ( SUCCEEDED( hr ) )
421 {
423 m_pStorage = pStg;
424
425 m_nFileOpenMode = 0;
426 if ( m_pFileName )
427 {
428 delete[] m_pFileName;
429 m_pFileName = nullptr;
430 }
431 }
432
433 return hr;
434 }
435 }
436
437 return E_FAIL;
438}
439
440
441COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Load( IStorage *pStg )
442{
443 if ( CheckDefHandler() )
444 {
445 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
446
447 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
448 if ( pPersist )
449 {
450 HRESULT hr = pPersist->Load( pStg );
451 if ( SUCCEEDED( hr ) )
452 {
454 m_pStorage = pStg;
455
456 m_nFileOpenMode = 0;
457 if ( m_pFileName )
458 {
459 delete[] m_pFileName;
460 m_pFileName = nullptr;
461 }
462 }
463
464 return hr;
465 }
466 }
467
468 return E_FAIL;
469}
470
471
472COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )
473{
474 if ( fSameAsLoad && ( m_pDefHandler == nullptr || m_pOleAdvises[0] == nullptr || m_pOleAdvises[0]->IsClosed() ) )
475 return S_OK;
476
477 if ( CheckDefHandler() )
478 {
479 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
480
481 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
482 if ( pPersist )
483 return pPersist->Save( pStgSave, fSameAsLoad );
484 }
485
486 return E_FAIL;
487}
488
489
490COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )
491{
492 if ( m_pDefHandler == nullptr || m_pOleAdvises[0] == nullptr || m_pOleAdvises[0]->IsClosed() )
493 {
494 if ( pStgNew )
495 m_pStorage = pStgNew;
496
497 return S_OK;
498 }
499
500 if ( CheckDefHandler() )
501 {
502 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
503
504 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
505 if ( pPersist )
506 {
507 HRESULT hr = pPersist->SaveCompleted( pStgNew );
508 if ( SUCCEEDED( hr ) )
509 {
511 if ( pStgNew )
512 {
513 m_pStorage = pStgNew;
514 }
515
516 m_nFileOpenMode = 0;
517 if ( m_pFileName )
518 {
519 delete[] m_pFileName;
520 m_pFileName = nullptr;
521 }
522 }
523
524 return hr;
525 }
526 }
527
528 return E_FAIL;
529}
530
531
532COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::HandsOffStorage()
533{
534 if ( CheckDefHandler() )
535 {
536 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
537
538 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
539 if ( pPersist )
540 {
541 HRESULT hr = pPersist->HandsOffStorage();
542 if ( SUCCEEDED( hr ) )
543 {
544 m_pStorage = nullptr;
545 }
546
547 return hr;
548 }
549 }
550
551 return E_FAIL;
552}
553
554// IPersistFile
555
556COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode )
557{
558 if ( CheckDefHandler() && pszFileName )
559 {
560 sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
561
562 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
563 if ( pPersist )
564 {
565 HRESULT hr = pPersist->Load( pszFileName, dwMode );
566 if ( SUCCEEDED( hr ) )
567 {
569 if ( m_pStorage )
570 m_pStorage = nullptr;
571
572 m_nFileOpenMode = dwMode;
573 // copy the string
574 SetName( pszFileName, m_pFileName );
575 }
576
577 return hr;
578 }
579 }
580
581 return E_FAIL;
582}
583
584
585COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember )
586{
587 if ( CheckDefHandler() )
588 {
589 sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
590
591 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
592 if ( pPersist )
593 return pPersist->Save( pszFileName, fRemember );
594 }
595
596 return E_FAIL;
597}
598
599
600COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName )
601{
602 if ( CheckDefHandler() )
603 {
604 sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
605
606 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
607 if ( pPersist )
608 {
609 HRESULT hr = pPersist->SaveCompleted( pszFileName );
610 if ( SUCCEEDED( hr ) )
611 {
613 if ( m_pStorage )
614 m_pStorage = nullptr;
615
616 m_nFileOpenMode = STGM_READWRITE; // was just written
617 // copy the string
618 SetName( pszFileName, m_pFileName );
619 }
620 }
621
622 }
623
624 return E_FAIL;
625}
626
627
628COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )
629{
630 if ( CheckDefHandler() )
631 {
632 sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
633
634 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
635 if ( pPersist )
636 return pPersist->GetCurFile( ppszFileName );
637 }
638
639 return E_FAIL;
640}
641
642// IOleObject
643
644COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )
645{
646 if ( pSite == m_pClientSite.get() )
647 return S_OK;
648
649 if ( !pSite )
650 {
651 m_pClientSite = nullptr;
652 if ( m_pOleContainer )
653 {
654 m_pOleContainer->LockContainer( FALSE );
655 m_pOleContainer = nullptr;
656 }
657 }
658
659 if ( CheckDefHandler() )
660 {
661 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
662
663 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
664 if ( pOleObject )
665 {
666 HRESULT hr2 = pOleObject->SetClientSite( pSite );
667 if ( SUCCEEDED( hr2 ) )
668 {
669 m_pClientSite = pSite;
670
671 if ( m_pOleContainer )
672 {
673 m_pOleContainer->LockContainer( FALSE );
674 m_pOleContainer = nullptr;
675 }
676
677 m_pClientSite->GetContainer( &m_pOleContainer );
678 if ( m_pOleContainer )
679 m_pOleContainer->LockContainer( TRUE );
680 }
681
682 return hr2;
683 }
684 }
685
686 return E_FAIL;
687}
688
689
690COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )
691{
692 if ( CheckDefHandler() )
693 {
694 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
695
696 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
697 if ( pOleObject )
698 return pOleObject->GetClientSite( pSite );
699 }
700
701 return E_FAIL;
702}
703
704
705COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )
706{
707
708 if ( CheckDefHandler() )
709 {
710 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
711
712 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
713 if ( pOleObject )
714 {
715 pOleObject->SetHostNames( szContainerApp, szContainerObj );
716 }
717 }
718
719 return S_OK;
720}
721
722
723COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )
724{
725 HRESULT ret = S_OK;
727 {
728 // no need to close if there is no default handler.
729 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
730
731 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
732 if ( pOleObject )
733 {
734 HRESULT hr = pOleObject->Close( dwSaveOption );
735 if (!SUCCEEDED(hr))
736 ret = hr;
737 hr = CoDisconnectObject( static_cast<IUnknown*>(static_cast<IPersistStorage*>(this)), 0 );
738 if (!SUCCEEDED(hr) && SUCCEEDED(ret))
739 ret = hr;
740 }
741 }
742
743 // if the object is closed from outside that means that it should go to uninitialized state
744 Clean();
745
746 return ret;
747}
748
749
750COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )
751{
752 if ( CheckDefHandler() )
753 {
754 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
755
756 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
757 if ( pOleObject )
758 return pOleObject->SetMoniker( dwWhichMoniker, pmk );
759 }
760
761 return E_FAIL;
762}
763
764
765COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )
766{
767 if ( CheckDefHandler() )
768 {
769 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
770
771 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
772 if ( pOleObject )
773 return pOleObject->GetMoniker( dwAssign, dwWhichMoniker, ppmk );
774 }
775
776 return E_FAIL;
777}
778
779
780COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )
781{
782 if ( CheckDefHandler() )
783 {
784 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
785
786 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
787 if ( pOleObject )
788 return pOleObject->InitFromData( pDataObject, fCreation, dwReserved );
789 }
790
791 return E_FAIL;
792}
793
794
795COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )
796{
797 if ( CheckDefHandler() )
798 {
799 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
800
801 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
802 if ( pOleObject )
803 return pOleObject->GetClipboardData( dwReserved, ppDataObject );
804 }
805
806 return E_FAIL;
807}
808
809
810COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::DoVerb(
811 LONG iVerb,
812 LPMSG pMsg,
813 IOleClientSite *pActiveSite,
814 LONG nLong,
815 HWND hWin,
816 LPCRECT pRect )
817{
818 if ( CheckDefHandler() )
819 {
820 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
821
822 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
823 if ( pOleObject )
824 {
825 return pOleObject->DoVerb( iVerb, pMsg, pActiveSite, nLong, hWin, pRect );
826 }
827
828 }
829
830 return E_FAIL;
831}
832
833
834COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )
835{
836 if ( CheckDefHandler() )
837 {
838 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
839
840 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
841 if ( pOleObject )
842 return pOleObject->EnumVerbs( ppEnumOleVerb );
843 }
844
845 return E_FAIL;
846}
847
848
849COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Update()
850{
851
853 {
854 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
855
856 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
857 if ( pOleObject )
858 return pOleObject->Update();
859 }
860
861 return S_OK;
862}
863
864
865COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::IsUpToDate()
866{
867 if ( CheckDefHandler() )
868 {
869 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
870
871 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
872 if ( pOleObject )
873 return pOleObject->IsUpToDate();
874 }
875
876 return E_FAIL;
877}
878
879
880COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )
881{
882 if ( pClsid )
883 *pClsid = m_guid;
884
885 return S_OK;
886}
887
888
889COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )
890{
891 if ( CheckDefHandler() )
892 {
893 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
894
895 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
896 if ( pOleObject )
897 return pOleObject->GetUserType( dwFormOfType, pszUserType );
898 }
899
900 return E_FAIL;
901}
902
903
904COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )
905{
906 if ( CheckDefHandler() )
907 {
908 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
909
910 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
911 if ( pOleObject )
912 return pOleObject->SetExtent( dwDrawAspect, psizel );
913 }
914
915 return E_FAIL;
916}
917
918
919COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )
920{
921 if ( CheckDefHandler() )
922 {
923 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
924
925 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
926 if ( pOleObject )
927 return pOleObject->GetExtent( dwDrawAspect, psizel );
928 }
929
930 return E_FAIL;
931}
932
933
934COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )
935{
936
937 if ( !pdwConnection )
938 return E_FAIL;
939
940 // CheckDefHandler will set the listener, avoid reusing of old listener
941 if ( DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pOleAdvises[*pdwConnection] )
942 {
943 m_pOleAdvises[*pdwConnection]->DisconnectOrigAdvise();
944 m_pOleAdvises[*pdwConnection] = nullptr;
945 }
946
947 if ( pAdvSink && CheckDefHandler() )
948 {
949 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
950
951 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
952 if ( pOleObject )
953 {
954 sal::systools::COMReference pOwnAdvise(new OleWrapperAdviseSink(pAdvSink));
955 DWORD nRegID = 0;
956
957 if ( SUCCEEDED( pOleObject->Advise( pOwnAdvise.get(), &nRegID ) ) && nRegID > 0 )
958 {
959 pOwnAdvise->SetRegID( nRegID );
960 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pOleAdvises );
961 if ( *pdwConnection )
962 return S_OK;
963 else
964 pOleObject->Unadvise( nRegID );
965 }
966 }
967 }
968
969 // return success always for now
970 return S_OK;
971}
972
973
974COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Unadvise( DWORD dwConnection )
975{
976 if ( DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pOleAdvises[dwConnection] )
977 {
978 if ( m_pDefHandler )
979 {
980 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
981
982 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
983 if ( pOleObject )
984 {
985 DWORD nID = m_pOleAdvises[dwConnection]->GetRegID();
986 pOleObject->Unadvise( nID );
987 }
988 }
989
990 m_pOleAdvises[dwConnection]->DisconnectOrigAdvise();
991 m_pOleAdvises[dwConnection] = nullptr;
992
993 return S_OK;
994 }
995
996 return E_FAIL;
997}
998
999
1000COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::EnumAdvise( IEnumSTATDATA ** /*ppenumAdvise*/ )
1001{
1002 return E_NOTIMPL;
1003}
1004
1005
1006COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )
1007{
1008 if ( CheckDefHandler() )
1009 {
1010 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
1011
1012 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1013 if ( pOleObject )
1014 return pOleObject->GetMiscStatus( dwAspect, pdwStatus );
1015 }
1016
1017 return E_FAIL;
1018}
1019
1020
1021COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )
1022{
1023 if ( CheckDefHandler() )
1024 {
1025 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
1026
1027 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1028 if ( pOleObject )
1029 return pOleObject->SetColorScheme( pLogpal );
1030 }
1031
1032 return E_FAIL;
1033}
1034
1035//IDataObject
1036
1037COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
1038{
1039 if ( CheckDefHandler() )
1040 {
1041 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1042
1043 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1044 if ( pIDataObject )
1045 return pIDataObject->GetData( pFormatetc, pMedium );
1046 }
1047
1048 return E_FAIL;
1049}
1050
1051
1052COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
1053{
1054 if ( CheckDefHandler() )
1055 {
1056 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1057
1058 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1059 if ( pIDataObject )
1060 return pIDataObject->GetDataHere( pFormatetc, pMedium );
1061 }
1062
1063 return E_FAIL;
1064}
1065
1066
1067COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )
1068{
1069 if ( CheckDefHandler() )
1070 {
1071 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1072
1073 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1074 if ( pIDataObject )
1075 return pIDataObject->QueryGetData( pFormatetc );
1076 }
1077
1078 return E_FAIL;
1079}
1080
1081
1082COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )
1083{
1084 if ( CheckDefHandler() )
1085 {
1086 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1087
1088 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1089 if ( pIDataObject )
1090 return pIDataObject->GetCanonicalFormatEtc( pFormatetcIn, pFormatetcOut );
1091 }
1092
1093 return E_FAIL;
1094}
1095
1096
1097COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )
1098{
1099 if ( CheckDefHandler() )
1100 {
1101 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1102
1103 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1104 if ( pIDataObject )
1105 return pIDataObject->SetData( pFormatetc, pMedium, fRelease );
1106 }
1107
1108 return E_FAIL;
1109}
1110
1111
1112COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )
1113{
1114 if ( CheckDefHandler() )
1115 {
1116 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1117
1118 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1119 if ( pIDataObject )
1120 return pIDataObject->EnumFormatEtc( dwDirection, ppFormatetc );
1121 }
1122
1123 return E_FAIL;
1124}
1125
1126
1127COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )
1128{
1129
1130 if ( !pdwConnection )
1131 return E_FAIL;
1132
1133 // avoid reusing of the old listener
1134 if ( m_pDefHandler && DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pDataAdvises[*pdwConnection] )
1135 {
1136 m_pDataAdvises[*pdwConnection]->DisconnectOrigAdvise();
1137 m_pDataAdvises[*pdwConnection] = nullptr;
1138 }
1139
1140 if ( pAdvSink && CheckDefHandler() )
1141 {
1142 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1143
1144 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1145 if ( pIDataObject )
1146 {
1147 sal::systools::COMReference pOwnAdvise( new OleWrapperAdviseSink( pAdvSink, pFormatetc, advf ) );
1148 DWORD nRegID = 0;
1149
1150 if ( SUCCEEDED( pIDataObject->DAdvise( pFormatetc, advf, pOwnAdvise.get(), &nRegID ) ) && nRegID > 0 )
1151 {
1152 pOwnAdvise->SetRegID( nRegID );
1153 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pDataAdvises );
1154 if ( *pdwConnection )
1155 return S_OK;
1156 else
1157 pIDataObject->DUnadvise( nRegID );
1158 }
1159 }
1160 }
1161
1162 // return success always for now
1163 return S_OK;
1164}
1165
1166
1167COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )
1168{
1169 if ( m_pDefHandler && DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pDataAdvises[dwConnection] )
1170 {
1171 if ( CheckDefHandler() )
1172 {
1173 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1174
1175 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1176 if ( pIDataObject )
1177 {
1178 DWORD nID = m_pDataAdvises[dwConnection]->GetRegID();
1179 pIDataObject->DUnadvise( nID );
1180 }
1181 }
1182
1183 m_pDataAdvises[dwConnection]->DisconnectOrigAdvise();
1184 m_pDataAdvises[dwConnection] = nullptr;
1185
1186 return S_OK;
1187 }
1188
1189 return E_FAIL;
1190}
1191
1192
1193COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )
1194{
1195 if ( CheckDefHandler() )
1196 {
1197 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1198
1199 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1200 if ( pIDataObject )
1201 return pIDataObject->EnumDAdvise( ppenumAdvise );
1202 }
1203
1204 return E_FAIL;
1205}
1206
1207// IRunnableObject
1208
1209COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )
1210{
1211 if ( CheckDefHandler() )
1212 {
1213 sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, sal::systools::COM_QUERY);
1214
1215 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1216 if ( pIRunObj )
1217 return pIRunObj->GetRunningClass( lpClsid );
1218 }
1219
1220 return E_FAIL;
1221}
1222
1223
1224COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )
1225{
1226 if ( CheckDefHandler() )
1227 {
1228 sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, sal::systools::COM_QUERY);
1229
1230 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1231 if ( pIRunObj )
1232 return pIRunObj->Run( pbc );
1233 }
1234
1235 return E_FAIL;
1236}
1237
1239{
1240 if (CheckDefHandler())
1241 {
1242 sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, sal::systools::COM_QUERY);
1243
1244 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1245 if ( pIRunObj )
1246 return pIRunObj->IsRunning();
1247 }
1248
1249 return FALSE;
1250}
1251
1252COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )
1253{
1254 if ( CheckDefHandler() )
1255 {
1256 sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, sal::systools::COM_QUERY);
1257
1258 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1259 if ( pIRunObj )
1260 return pIRunObj->LockRunning( fLock, fLastUnlockCloses );
1261 }
1262
1263 return E_FAIL;
1264}
1265
1266
1267COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)
1268{
1269 if ( CheckDefHandler() )
1270 {
1271 sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, sal::systools::COM_QUERY);
1272
1273 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1274 if ( pIRunObj )
1275 return pIRunObj->SetContainedObject( fContained );
1276 }
1277
1278 return E_FAIL;
1279}
1280
1281
1282// IViewObject methods
1283
1284COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Draw( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds, BOOL ( STDMETHODCALLTYPE *pfnContinue )( ULONG_PTR dwContinue ), ULONG_PTR dwContinue )
1285{
1286 if ( CheckDefHandler() )
1287 {
1288 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
1289
1290 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1291 if ( pIViewObject )
1292 return pIViewObject->Draw( dwDrawAspect, lindex, pvAspect, ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue );
1293 }
1294
1295 return E_FAIL;
1296}
1297
1298
1299COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )
1300{
1301 if ( CheckDefHandler() )
1302 {
1303 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
1304
1305 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1306 if ( pIViewObject )
1307 return pIViewObject->GetColorSet( dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet );
1308 }
1309
1310 return E_FAIL;
1311}
1312
1313
1314COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )
1315{
1316 if ( CheckDefHandler() )
1317 {
1318 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
1319
1320 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1321 if ( pIViewObject )
1322 return pIViewObject->Freeze( dwDrawAspect, lindex, pvAspect, pdwFreeze );
1323 }
1324
1325 return E_FAIL;
1326}
1327
1328
1329COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )
1330{
1331 if ( CheckDefHandler() )
1332 {
1333 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
1334
1335 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1336 if ( pIViewObject )
1337 return pIViewObject->Unfreeze( dwFreeze );
1338 }
1339
1340 return E_FAIL;
1341}
1342
1343
1344COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )
1345{
1346
1347 // CheckDefHandler will set the listener, avoid reusing of old listener
1348 if ( m_pViewAdvise )
1349 {
1350 m_pViewAdvise->DisconnectOrigAdvise();
1351 m_pViewAdvise = nullptr;
1352 }
1353
1354 if ( pAdvSink && CheckDefHandler() )
1355 {
1356 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
1357
1358 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1359 if ( pIViewObject )
1360 {
1361 sal::systools::COMReference pOwnAdvise(new OleWrapperAdviseSink(pAdvSink, aspects, advf));
1362
1363 if ( SUCCEEDED( pIViewObject->SetAdvise( aspects, advf, pOwnAdvise.get() ) ) )
1364 {
1365 m_pViewAdvise = pOwnAdvise;
1366 return S_OK;
1367 }
1368 }
1369 }
1370
1371 return S_OK;
1372}
1373
1374
1375COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetAdvise( DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink )
1376{
1377 if ( !ppAdvSink )
1378 return E_INVALIDARG;
1379
1380 if ( m_pViewAdvise )
1381 {
1382 if ( pAspects )
1383 *pAspects = m_pViewAdvise->GetAspect();
1384
1385 if ( pAdvf )
1386 *pAdvf = m_pViewAdvise->GetViewAdviseFlag();
1387
1388 *ppAdvSink = m_pViewAdvise->GetOrigAdvise().get();
1389 if ( *ppAdvSink )
1390 (*ppAdvSink)->AddRef();
1391 }
1392 else
1393 *ppAdvSink = nullptr;
1394
1395 return S_OK;
1396}
1397
1398// IViewObject2 methods
1399
1400COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )
1401{
1402 if ( CheckDefHandler() )
1403 {
1404 sal::systools::COMReference< IViewObject2 > pIViewObject2(m_pDefHandler, sal::systools::COM_QUERY);
1405
1406 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1407 if ( pIViewObject2 )
1408 return pIViewObject2->GetExtent( dwDrawAspect, lindex, ptd, lpsizel );
1409 }
1410
1411 return E_FAIL;
1412}
1413
1414
1415// IOleWindow methods
1416
1417COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )
1418{
1419 if ( CheckDefHandler() )
1420 {
1421 sal::systools::COMReference< IOleWindow > pIOleWindow(m_pDefHandler, sal::systools::COM_QUERY);
1422
1423 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1424 if ( pIOleWindow )
1425 return pIOleWindow->GetWindow( phwnd );
1426 }
1427
1428 return E_FAIL;
1429}
1430
1431
1432COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )
1433{
1434 if ( CheckDefHandler() )
1435 {
1436 sal::systools::COMReference< IOleWindow > pIOleWindow(m_pDefHandler, sal::systools::COM_QUERY);
1437
1438 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1439 if ( pIOleWindow )
1440 return pIOleWindow->ContextSensitiveHelp( fEnterMode );
1441 }
1442
1443 return E_FAIL;
1444}
1445
1446
1447// IOleInPlaceObject methods
1448
1449COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InPlaceDeactivate()
1450{
1451 if ( CheckDefHandler() )
1452 {
1453 sal::systools::COMReference< IOleInPlaceObject > pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
1454
1455 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1456 if ( pIOleInPlaceObject )
1457 return pIOleInPlaceObject->InPlaceDeactivate();
1458 }
1459
1460 return E_FAIL;
1461}
1462
1463
1464COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::UIDeactivate()
1465{
1466 if ( CheckDefHandler() )
1467 {
1468 sal::systools::COMReference< IOleInPlaceObject > pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
1469
1470 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1471 if ( pIOleInPlaceObject )
1472 return pIOleInPlaceObject->UIDeactivate();
1473 }
1474
1475 return E_FAIL;
1476}
1477
1478
1479COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )
1480{
1481 if ( CheckDefHandler() )
1482 {
1483 sal::systools::COMReference< IOleInPlaceObject > pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
1484
1485 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1486 if ( pIOleInPlaceObject )
1487 return pIOleInPlaceObject->SetObjectRects( lprcPosRect, lprcClipRect );
1488 }
1489
1490 return E_FAIL;
1491}
1492
1493
1494COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::ReactivateAndUndo()
1495{
1496 if ( CheckDefHandler() )
1497 {
1498 sal::systools::COMReference< IOleInPlaceObject > pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
1499
1500 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1501 if ( pIOleInPlaceObject )
1502 return pIOleInPlaceObject->ReactivateAndUndo();
1503 }
1504
1505 return E_FAIL;
1506}
1507
1508
1509// IDispatch methods
1510
1511COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )
1512{
1513 if ( CheckDefHandler() )
1514 {
1515 sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, sal::systools::COM_QUERY);
1516
1517 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1518 if ( pIDispatch )
1519 return pIDispatch->GetTypeInfoCount( pctinfo );
1520 }
1521
1522 return E_FAIL;
1523}
1524
1525
1526COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )
1527{
1528 if ( CheckDefHandler() )
1529 {
1530 sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, sal::systools::COM_QUERY);
1531
1532 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1533 if ( pIDispatch )
1534 return pIDispatch->GetTypeInfo( iTInfo, lcid, ppTInfo );
1535 }
1536
1537 return E_FAIL;
1538}
1539
1540
1541COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )
1542{
1543 if ( CheckDefHandler() )
1544 {
1545 sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, sal::systools::COM_QUERY);
1546
1547 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1548 if ( pIDispatch )
1549 return pIDispatch->GetIDsOfNames( riid, rgszNames, cNames, lcid, rgDispId );
1550 }
1551
1552 return E_FAIL;
1553}
1554
1555
1556COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )
1557{
1558 if ( CheckDefHandler() )
1559 {
1560 sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, sal::systools::COM_QUERY);
1561
1562 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1563 if ( pIDispatch )
1564 return pIDispatch->Invoke( dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
1565 }
1566
1567 return E_FAIL;
1568}
1569
1570
1571// InternalCacheWrapper
1572
1573
1574// IUnknown
1575
1576COM_DECLSPEC_NOTHROW STDMETHODIMP
1578{
1579 return m_rOwnDocument.QueryInterface( riid, ppv );
1580}
1581
1582
1583COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::AddRef()
1584{
1585 return m_rOwnDocument.AddRef();
1586}
1587
1588
1589COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::Release()
1590{
1591 return m_rOwnDocument.Release();
1592}
1593
1594// IOleCache methods
1595
1596COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )
1597{
1598 if ( m_rOwnDocument.CheckDefHandler() )
1599 {
1600 sal::systools::COMReference< IOleCache > pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1601
1602 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1603 if ( pIOleCache )
1604 return pIOleCache->Cache( pformatetc, advf, pdwConnection );
1605 }
1606
1607 return E_FAIL;
1608}
1609
1610
1611COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )
1612{
1613 if ( m_rOwnDocument.CheckDefHandler() )
1614 {
1615 sal::systools::COMReference< IOleCache > pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1616
1617 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1618 if ( pIOleCache )
1619 return pIOleCache->Uncache( dwConnection );
1620 }
1621
1622 return E_FAIL;
1623}
1624
1625
1626COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )
1627{
1628 if ( m_rOwnDocument.CheckDefHandler() )
1629 {
1630 sal::systools::COMReference< IOleCache > pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1631
1632 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1633 if ( pIOleCache )
1634 return pIOleCache->EnumCache( ppenumSTATDATA );
1635 }
1636
1637 return E_FAIL;
1638}
1639
1640
1641COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )
1642{
1643 if ( m_rOwnDocument.CheckDefHandler() )
1644 {
1645 sal::systools::COMReference< IOleCache > pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1646
1647 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1648 if ( pIOleCache )
1649 return pIOleCache->InitCache( pDataObject );
1650 }
1651
1652 return E_FAIL;
1653}
1654
1655
1656COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )
1657{
1658 if ( m_rOwnDocument.CheckDefHandler() )
1659 {
1660 sal::systools::COMReference< IOleCache > pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1661
1662 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1663 if ( pIOleCache )
1664 return pIOleCache->SetData( pformatetc, pmedium, fRelease );
1665 }
1666
1667 return E_FAIL;
1668}
1669
1670// IOleCache2 methods
1671
1672COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )
1673{
1674 if ( m_rOwnDocument.CheckDefHandler() )
1675 {
1676 sal::systools::COMReference< IOleCache2 > pIOleCache2(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1677
1678 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1679 if ( pIOleCache2 )
1680 return pIOleCache2->UpdateCache( pDataObject, grfUpdf, pReserved );
1681 }
1682
1683 return E_FAIL;
1684}
1685
1686
1687COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )
1688{
1689 if ( m_rOwnDocument.CheckDefHandler() )
1690 {
1691 sal::systools::COMReference< IOleCache2 > pIOleCache2(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1692
1693 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1694 if ( pIOleCache2 )
1695 return pIOleCache2->DiscardCache( dwDiscardOptions );
1696 }
1697
1698 return E_FAIL;
1699}
1700
1701}; // namespace inprocserv
1702
1703/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
STDMETHOD() Cache(FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection) override
STDMETHOD() InitCache(IDataObject *pDataObject) override
STDMETHOD() QueryInterface(REFIID riid, void **ppvObj) override
STDMETHOD() EnumCache(IEnumSTATDATA **ppenumSTATDATA) override
STDMETHOD() UpdateCache(LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved) override
STDMETHOD() SetData(FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease) override
STDMETHOD() Uncache(DWORD dwConnection) override
STDMETHOD() DiscardCache(DWORD dwDiscardOptions) override
STDMETHOD() GetClassID(CLSID *pClassID) override
STDMETHOD() SetContainedObject(BOOL fContained) override
STDMETHOD() GetWindow(HWND *phwnd) override
inprocserv::InprocEmbedDocument_Impl::InternalCacheWrapper m_aInternalCache
STDMETHOD() DoVerb(LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect) override
STDMETHOD() GetClipboardData(DWORD dwReserved, IDataObject **ppDataObject) override
STDMETHOD() GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) override
STDMETHOD() GetCanonicalFormatEtc(FORMATETC *pFormatetcIn, FORMATETC *pFormatetcOut) override
STDMETHOD() GetDataHere(FORMATETC *pFormatetc, STGMEDIUM *pMedium) override
STDMETHOD() EnumAdvise(IEnumSTATDATA **ppenumAdvise) override
STDMETHOD() Run(LPBINDCTX pbc) override
STDMETHOD() GetAdvise(DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink) override
STDMETHOD() Freeze(DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze) override
STDMETHOD() SetData(FORMATETC *pFormatetc, STGMEDIUM *pMedium, BOOL fRelease) override
STDMETHOD() GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) override
STDMETHOD() QueryGetData(FORMATETC *pFormatetc) override
sal::systools::COMReference< IUnknown > m_pDefHandler
Definition: inprocembobj.h:72
STDMETHOD() UIDeactivate(void) override
STDMETHOD() DAdvise(FORMATETC *pFormatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection) override
STDMETHOD() DUnadvise(DWORD dwConnection) override
sal::systools::COMReference< IOleClientSite > m_pClientSite
Definition: inprocembobj.h:80
STDMETHOD() Save(IStorage *pStgSave, BOOL fSameAsLoad) override
STDMETHOD() SaveCompleted(IStorage *pStgNew) override
STDMETHOD() QueryInterface(REFIID riid, void **ppvObj) override
STDMETHOD() GetData(FORMATETC *pFormatetc, STGMEDIUM *pMedium) override
STDMETHOD() InPlaceDeactivate(void) override
STDMETHOD() InitNew(IStorage *pStg) override
STDMETHOD() SetExtent(DWORD dwDrawAspect, SIZEL *psizel) override
STDMETHOD() GetRunningClass(LPCLSID lpClsid) override
STDMETHOD() Draw(DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds, BOOL(STDMETHODCALLTYPE *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue) override
STDMETHOD() HandsOffStorage(void) override
sal::systools::COMReference< OleWrapperAdviseSink > m_pDataAdvises[DEFAULT_ARRAY_LEN]
Definition: inprocembobj.h:88
STDMETHOD() SetColorScheme(LOGPALETTE *pLogpal) override
STDMETHOD() Unadvise(DWORD dwConnection) override
STDMETHOD() LockRunning(BOOL fLock, BOOL fLastUnlockCloses) override
sal::systools::COMReference< OleWrapperAdviseSink > m_pViewAdvise
Definition: inprocembobj.h:89
STDMETHOD() SetHostNames(LPCOLESTR szContainerApp, LPCOLESTR szContainerObj) override
STDMETHOD() GetUserClassID(CLSID *pClsid) override
STDMETHOD() Advise(IAdviseSink *pAdvSink, DWORD *pdwConnection) override
STDMETHOD() SetMoniker(DWORD dwWhichMoniker, IMoniker *pmk) override
STDMETHOD() GetTypeInfoCount(UINT *pctinfo) override
STDMETHOD() EnumDAdvise(IEnumSTATDATA **ppenumAdvise) override
sal::systools::COMReference< OleWrapperAdviseSink > m_pOleAdvises[DEFAULT_ARRAY_LEN]
Definition: inprocembobj.h:87
STDMETHOD() GetUserType(DWORD dwFormOfType, LPOLESTR *pszUserType) override
STDMETHOD() SetAdvise(DWORD aspects, DWORD advf, IAdviseSink *pAdvSink) override
STDMETHOD() SetObjectRects(LPCRECT lprcPosRect, LPCRECT lprcClipRect) override
STDMETHOD() EnumVerbs(IEnumOLEVERB **ppEnumOleVerb) override
STDMETHOD() ContextSensitiveHelp(BOOL fEnterMode) override
STDMETHOD() Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) override
STDMETHOD() GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk) override
virtual BOOL STDMETHODCALLTYPE IsRunning(void) override
STDMETHOD() GetMiscStatus(DWORD dwAspect, DWORD *pdwStatus) override
STDMETHOD() GetClientSite(IOleClientSite **pSite) override
sal::systools::COMReference< IOleContainer > m_pOleContainer
Definition: inprocembobj.h:81
sal::systools::COMReference< IStorage > m_pStorage
Definition: inprocembobj.h:78
STDMETHOD() GetCurFile(LPOLESTR *ppszFileName) override
STDMETHOD() Load(IStorage *pStr) override
STDMETHOD() EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppFormatetc) override
STDMETHOD() Close(DWORD dwSaveOption) override
STDMETHOD() ReactivateAndUndo(void) override
STDMETHOD() GetExtent(DWORD dwDrawAspect, SIZEL *psizel) override
STDMETHOD() InitFromData(IDataObject *pDataObject, BOOL fCreation, DWORD dwReserved) override
STDMETHOD() SetClientSite(IOleClientSite *pSite) override
STDMETHOD() GetColorSet(DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet) override
STDMETHOD() Unfreeze(DWORD dwFreeze) override
int nCount
#define TRUE
#define FALSE
ULONG & m_rValue
#define DEFAULT_ARRAY_LEN
Definition: inprocembobj.h:32
unsigned short WORD
lindex
STDMETHODIMP_(ULONG) OleWrapperAdviseSink
Definition: advisesink.cxx:109
@ INIT_FROM_STORAGE
Definition: inprocembobj.h:38
@ LOAD_FROM_STORAGE
Definition: inprocembobj.h:39
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
const wchar_t *typedef BOOL
return hr