1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: querystatus.cxx,v $
*
* $Revision: 1.7 $
*
* last change: $Author: obo $ $Date: 2006-09-17 16:27:58 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sfx2.hxx"
#ifndef _SFXQUERYSTATUS_HXX
#include <querystatus.hxx>
#endif
#ifndef _SFXPOOLITEM_HXX //autogen
#include <svtools/poolitem.hxx>
#endif
#ifndef _SFXENUMITEM_HXX //autogen
#include <svtools/eitem.hxx>
#endif
#ifndef _SFXSTRITEM_HXX //autogen
#include <svtools/stritem.hxx>
#endif
#include <svtools/intitem.hxx>
#include <svtools/itemset.hxx>
#include <svtools/itemdel.hxx>
#include <svtools/visitem.hxx>
#ifndef _CPPUHELPER_WEAK_HXX_
#include <cppuhelper/weak.hxx>
#endif
#include <comphelper/processfactory.hxx>
#include <vos/mutex.hxx>
#include <vcl/svapp.hxx>
#ifndef _COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP_
#include <com/sun/star/util/XURLTransformer.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_STATUS_ITEMSTATUS_HPP_
#include <com/sun/star/frame/status/ItemStatus.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_STATUS_ITEMSTATE_HPP_
#include <com/sun/star/frame/status/ItemState.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_STATUS_VISIBILITY_HPP_
#include <com/sun/star/frame/status/Visibility.hpp>
#endif
using namespace ::rtl;
using namespace ::cppu;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::frame::status;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::util;
class SfxQueryStatus_Impl : public ::com::sun::star::frame::XStatusListener ,
public ::com::sun::star::lang::XTypeProvider ,
public ::cppu::OWeakObject
{
public:
SFX_DECL_XINTERFACE_XTYPEPROVIDER
SfxQueryStatus_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider, USHORT nSlotId, const rtl::OUString& aCommand );
virtual ~SfxQueryStatus_Impl();
// Query method
SfxItemState QueryState( SfxPoolItem*& pPoolItem );
// XEventListener
virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
// XStatusListener
virtual void SAL_CALL statusChanged(const ::com::sun::star::frame::FeatureStateEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
private:
SfxQueryStatus_Impl( const SfxQueryStatus& );
SfxQueryStatus_Impl();
SfxQueryStatus_Impl& operator=( const SfxQueryStatus& );
sal_Bool m_bQueryInProgress;
SfxItemState m_eState;
SfxPoolItem* m_pItem;
USHORT m_nSlotID;
osl::Condition m_aCondition;
::com::sun::star::util::URL m_aCommand;
com::sun::star::uno::Reference< com::sun::star::frame::XDispatch > m_xDispatch;
};
SFX_IMPL_XINTERFACE_2( SfxQueryStatus_Impl, OWeakObject, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
SFX_IMPL_XTYPEPROVIDER_2( SfxQueryStatus_Impl, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
SfxQueryStatus_Impl::SfxQueryStatus_Impl( const Reference< XDispatchProvider >& rDispatchProvider, USHORT nSlotId, const OUString& rCommand ) :
cppu::OWeakObject(),
m_bQueryInProgress( sal_False ),
m_eState( SFX_ITEM_DISABLED ),
m_pItem( 0 ),
m_nSlotID( nSlotId )
{
m_aCommand.Complete = rCommand;
Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
xTrans->parseStrict( m_aCommand );
if ( rDispatchProvider.is() )
m_xDispatch = rDispatchProvider->queryDispatch( m_aCommand, rtl::OUString(), 0 );
m_aCondition.reset();
}
SfxQueryStatus_Impl::~SfxQueryStatus_Impl()
{
}
void SAL_CALL SfxQueryStatus_Impl::disposing( const EventObject& )
throw( RuntimeException )
{
::vos::OGuard aGuard( Application::GetSolarMutex() );
m_xDispatch.clear();
}
void SAL_CALL SfxQueryStatus_Impl::statusChanged( const FeatureStateEvent& rEvent)
throw( RuntimeException )
{
::vos::OGuard aGuard( Application::GetSolarMutex() );
m_pItem = NULL;
m_eState = SFX_ITEM_DISABLED;
if ( rEvent.IsEnabled )
{
m_eState = SFX_ITEM_AVAILABLE;
::com::sun::star::uno::Type pType = rEvent.State.getValueType();
if ( pType == ::getBooleanCppuType() )
{
sal_Bool bTemp = false;
rEvent.State >>= bTemp ;
m_pItem = new SfxBoolItem( m_nSlotID, bTemp );
}
else if ( pType == ::getCppuType((const sal_uInt16*)0) )
{
sal_uInt16 nTemp = 0;
rEvent.State >>= nTemp ;
m_pItem = new SfxUInt16Item( m_nSlotID, nTemp );
}
else if ( pType == ::getCppuType((const sal_uInt32*)0) )
{
sal_uInt32 nTemp ;
rEvent.State >>= nTemp ;
m_pItem = new SfxUInt32Item( m_nSlotID, nTemp );
}
else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
{
::rtl::OUString sTemp ;
rEvent.State >>= sTemp ;
m_pItem = new SfxStringItem( m_nSlotID, sTemp );
}
else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
{
ItemStatus aItemStatus;
rEvent.State >>= aItemStatus;
m_eState = aItemStatus.State;
m_pItem = new SfxVoidItem( m_nSlotID );
}
else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
{
Visibility aVisibilityStatus;
rEvent.State >>= aVisibilityStatus;
m_pItem = new SfxVisibilityItem( m_nSlotID, aVisibilityStatus.bVisible );
}
else
{
m_eState = SFX_ITEM_UNKNOWN;
m_pItem = new SfxVoidItem( m_nSlotID );
}
}
if ( m_pItem )
DeleteItemOnIdle( m_pItem );
try
{
m_aCondition.set();
m_xDispatch->removeStatusListener( Reference< XStatusListener >( static_cast< cppu::OWeakObject* >( this ), UNO_QUERY ),
m_aCommand );
}
catch ( Exception& )
{
}
}
// Query method
SfxItemState SfxQueryStatus_Impl::QueryState( SfxPoolItem*& rpPoolItem )
{
::vos::OGuard aGuard( Application::GetSolarMutex() );
if ( !m_bQueryInProgress )
{
m_pItem = NULL;
m_eState = SFX_ITEM_DISABLED;
if ( m_xDispatch.is() )
{
try
{
m_aCondition.reset();
m_bQueryInProgress = sal_True;
m_xDispatch->addStatusListener( Reference< XStatusListener >( static_cast< cppu::OWeakObject* >( this ), UNO_QUERY ),
m_aCommand );
}
catch ( Exception& )
{
m_aCondition.set();
}
}
else
m_aCondition.set();
}
m_aCondition.wait();
m_bQueryInProgress = sal_False;
rpPoolItem = m_pItem;
return m_eState;
}
//*************************************************************************
SfxQueryStatus::SfxQueryStatus( const Reference< XDispatchProvider >& rDispatchProvider, USHORT nSlotId, const OUString& rCommand )
{
m_pSfxQueryStatusImpl = new SfxQueryStatus_Impl( rDispatchProvider, nSlotId, rCommand );
m_xStatusListener = Reference< XStatusListener >(
static_cast< cppu::OWeakObject* >( m_pSfxQueryStatusImpl ),
UNO_QUERY );
}
SfxQueryStatus::~SfxQueryStatus()
{
}
SfxItemState SfxQueryStatus::QueryState( SfxPoolItem*& rpPoolItem )
{
::vos::OGuard aGuard( Application::GetSolarMutex() );
return m_pSfxQueryStatusImpl->QueryState( rpPoolItem );
}
|