Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "vcl/svapp.hxx"
31 : :
32 : : #include "xconnection.hxx"
33 : : #include "svdata.hxx"
34 : : #include "salinst.hxx"
35 : :
36 : : namespace {
37 : :
38 : : namespace css = com::sun::star;
39 : :
40 : : }
41 : :
42 : : using namespace osl;
43 : : using namespace vcl;
44 : : using namespace com::sun::star::uno;
45 : : using namespace com::sun::star::awt;
46 : :
47 : : using ::rtl::OUString;
48 : :
49 [ + - ][ + - ]: 113 : DisplayConnection::DisplayConnection()
[ + - ]
50 : : {
51 : : SalInstance::ConnectionIdentifierType eType;
52 : : int nBytes;
53 [ + - ][ + - ]: 113 : void* pBytes = ImplGetSVData()->mpDefInst->GetConnectionIdentifier( eType, nBytes );
54 [ + - - ]: 113 : switch( eType )
55 : : {
56 : : case SalInstance::AsciiCString:
57 [ + - ]: 113 : m_aAny <<= OUString::createFromAscii( (sal_Char*)pBytes );
58 : 113 : break;
59 : : case SalInstance::Blob:
60 [ # # ][ # # ]: 0 : m_aAny <<= Sequence< sal_Int8 >( (sal_Int8*)pBytes, nBytes );
[ # # ]
61 : 0 : break;
62 : : }
63 : 113 : }
64 : :
65 [ + - ]: 62 : DisplayConnection::~DisplayConnection()
66 [ - + ]: 124 : {}
67 : :
68 : 113 : void DisplayConnection::start()
69 : : {
70 : 113 : ImplSVData* pSVData = ImplGetSVData();
71 [ + - ]: 113 : pSVData->mpDefInst->SetEventCallback( this );
72 : 113 : }
73 : :
74 : 62 : void DisplayConnection::terminate()
75 : : {
76 [ + - ]: 62 : ImplSVData* pSVData = ImplGetSVData();
77 : :
78 [ + - ]: 62 : if( pSVData )
79 : : {
80 [ + - ]: 62 : pSVData->mpDefInst->SetEventCallback( NULL );
81 : : }
82 : :
83 [ + - ]: 62 : SolarMutexReleaser aRel;
84 : :
85 [ + - ]: 62 : MutexGuard aGuard( m_aMutex );
86 : 62 : Any aEvent;
87 [ + - ]: 62 : std::list< css::uno::Reference< XEventHandler > > aLocalList( m_aHandlers );
88 [ - + ]: 62 : for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = aLocalList.begin(); it != aLocalList.end(); ++it )
89 [ # # ][ # # ]: 62 : (*it)->handleEvent( aEvent );
[ + - ][ + - ]
90 : 62 : }
91 : :
92 : 0 : void SAL_CALL DisplayConnection::addEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler, sal_Int32 /*eventMask*/ ) throw()
93 : : {
94 [ # # ]: 0 : MutexGuard aGuard( m_aMutex );
95 : :
96 [ # # ][ # # ]: 0 : m_aHandlers.push_back( handler );
97 : 0 : }
98 : :
99 : 0 : void SAL_CALL DisplayConnection::removeEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler ) throw()
100 : : {
101 [ # # ]: 0 : MutexGuard aGuard( m_aMutex );
102 : :
103 [ # # ][ # # ]: 0 : m_aHandlers.remove( handler );
104 : 0 : }
105 : :
106 : 0 : void SAL_CALL DisplayConnection::addErrorHandler( const css::uno::Reference< XEventHandler >& handler ) throw()
107 : : {
108 [ # # ]: 0 : MutexGuard aGuard( m_aMutex );
109 : :
110 [ # # ][ # # ]: 0 : m_aErrorHandlers.push_back( handler );
111 : 0 : }
112 : :
113 : 0 : void SAL_CALL DisplayConnection::removeErrorHandler( const css::uno::Reference< XEventHandler >& handler ) throw()
114 : : {
115 [ # # ]: 0 : MutexGuard aGuard( m_aMutex );
116 : :
117 [ # # ][ # # ]: 0 : m_aErrorHandlers.remove( handler );
118 : 0 : }
119 : :
120 : 0 : Any SAL_CALL DisplayConnection::getIdentifier() throw()
121 : : {
122 : 0 : return m_aAny;
123 : : }
124 : :
125 : 0 : bool DisplayConnection::dispatchEvent( void* pData, int nBytes )
126 : : {
127 [ # # ]: 0 : SolarMutexReleaser aRel;
128 : :
129 [ # # ]: 0 : Sequence< sal_Int8 > aSeq( (sal_Int8*)pData, nBytes );
130 : 0 : Any aEvent;
131 [ # # ]: 0 : aEvent <<= aSeq;
132 [ # # ]: 0 : ::std::list< css::uno::Reference< XEventHandler > > handlers;
133 : : {
134 [ # # ]: 0 : MutexGuard aGuard( m_aMutex );
135 [ # # ][ # # ]: 0 : handlers = m_aHandlers;
136 : : }
137 [ # # ]: 0 : for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = handlers.begin(); it != handlers.end(); ++it )
138 [ # # ][ # # ]: 0 : if( (*it)->handleEvent( aEvent ) )
[ # # ]
139 : 0 : return true;
140 [ # # ][ # # ]: 0 : return false;
141 : : }
142 : :
143 : 0 : bool DisplayConnection::dispatchErrorEvent( void* pData, int nBytes )
144 : : {
145 [ # # ]: 0 : SolarMutexReleaser aRel;
146 : :
147 [ # # ]: 0 : Sequence< sal_Int8 > aSeq( (sal_Int8*)pData, nBytes );
148 : 0 : Any aEvent;
149 [ # # ]: 0 : aEvent <<= aSeq;
150 [ # # ]: 0 : ::std::list< css::uno::Reference< XEventHandler > > handlers;
151 : : {
152 [ # # ]: 0 : MutexGuard aGuard( m_aMutex );
153 [ # # ][ # # ]: 0 : handlers = m_aErrorHandlers;
154 : : }
155 [ # # ]: 0 : for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = handlers.begin(); it != handlers.end(); ++it )
156 [ # # ][ # # ]: 0 : if( (*it)->handleEvent( aEvent ) )
[ # # ]
157 : 0 : return true;
158 : :
159 [ # # ][ # # ]: 0 : return false;
160 : : }
161 : :
162 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|