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 2008 by Sun Microsystems, Inc.
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 : : #include <SidebarTxtControlAcc.hxx>
30 : :
31 : : #include <SidebarTxtControl.hxx>
32 : :
33 : : #include <svl/brdcst.hxx>
34 : : #include <toolkit/awt/vclxaccessiblecomponent.hxx>
35 : : #include <editeng/unoedsrc.hxx>
36 : : #include <editeng/unoforou.hxx>
37 : : #include <editeng/unoviwou.hxx>
38 : : #include <editeng/unoedhlp.hxx>
39 : : #include <svx/AccessibleTextHelper.hxx>
40 : : #include <editeng/outliner.hxx>
41 : :
42 : :
43 : : namespace css = ::com::sun::star;
44 : :
45 : : namespace sw { namespace sidebarwindows {
46 : :
47 : : // =============================================================================
48 : : // declaration and implementation of <SvxEditSource>
49 : : // for <::accessibiliy::AccessibleTextHelper> instance
50 : : // =============================================================================
51 : : class SidebarTextEditSource : public SvxEditSource,
52 : : public SfxBroadcaster
53 : : {
54 : : public:
55 : : SidebarTextEditSource( SidebarTxtControl& rSidebarTxtControl );
56 : : virtual ~SidebarTextEditSource();
57 : :
58 : : virtual SvxEditSource* Clone() const;
59 : :
60 : : virtual SvxTextForwarder* GetTextForwarder();
61 : : virtual SvxViewForwarder* GetViewForwarder();
62 : : virtual SvxEditViewForwarder* GetEditViewForwarder( sal_Bool bCreate = sal_False );
63 : :
64 : : virtual void UpdateData();
65 : :
66 : : virtual SfxBroadcaster& GetBroadcaster() const;
67 : : DECL_LINK( NotifyHdl, EENotify* );
68 : :
69 : : private:
70 : : SidebarTxtControl& mrSidebarTxtControl;
71 : : SvxOutlinerForwarder mTextForwarder;
72 : : SvxDrawOutlinerViewForwarder mViewForwarder;
73 : : };
74 : :
75 : 0 : SidebarTextEditSource::SidebarTextEditSource( SidebarTxtControl& rSidebarTxtControl )
76 : : : SvxEditSource()
77 : : , mrSidebarTxtControl( rSidebarTxtControl )
78 [ # # ]: 0 : , mTextForwarder( *(rSidebarTxtControl.GetTextView()->GetOutliner()), sal_False )
79 [ # # # # ]: 0 : , mViewForwarder( *(rSidebarTxtControl.GetTextView()) )
[ # # ][ # # ]
80 : : {
81 [ # # ][ # # ]: 0 : if ( mrSidebarTxtControl.GetTextView() )
82 : : {
83 [ # # ][ # # ]: 0 : mrSidebarTxtControl.GetTextView()->GetOutliner()->SetNotifyHdl( LINK(this, SidebarTextEditSource, NotifyHdl) );
[ # # ]
84 : : }
85 : 0 : }
86 : :
87 [ # # ][ # # ]: 0 : SidebarTextEditSource::~SidebarTextEditSource()
[ # # ]
88 : : {
89 [ # # ][ # # ]: 0 : if ( mrSidebarTxtControl.GetTextView() )
90 : : {
91 [ # # ][ # # ]: 0 : mrSidebarTxtControl.GetTextView()->GetOutliner()->SetNotifyHdl( Link() );
[ # # ]
92 : : }
93 [ # # ]: 0 : }
94 : :
95 : 0 : SvxEditSource* SidebarTextEditSource::Clone() const
96 : : {
97 [ # # ]: 0 : return new SidebarTextEditSource( mrSidebarTxtControl );
98 : : }
99 : :
100 : 0 : SvxTextForwarder* SidebarTextEditSource::GetTextForwarder()
101 : : {
102 : 0 : return &mTextForwarder;
103 : : }
104 : :
105 : 0 : SvxViewForwarder* SidebarTextEditSource::GetViewForwarder()
106 : : {
107 : 0 : return &mViewForwarder;
108 : : }
109 : :
110 : 0 : SvxEditViewForwarder* SidebarTextEditSource::GetEditViewForwarder( sal_Bool /*bCreate*/ )
111 : : {
112 : 0 : return &mViewForwarder;
113 : : }
114 : :
115 : 0 : void SidebarTextEditSource::UpdateData()
116 : : {
117 : : // nothing to do
118 : 0 : }
119 : :
120 : 0 : SfxBroadcaster& SidebarTextEditSource::GetBroadcaster() const
121 : : {
122 : 0 : return *( const_cast< SidebarTextEditSource* > (this) );
123 : : }
124 : :
125 : 0 : IMPL_LINK(SidebarTextEditSource, NotifyHdl, EENotify*, pNotify)
126 : : {
127 [ # # ]: 0 : if ( pNotify )
128 : : {
129 [ # # ][ # # ]: 0 : ::std::auto_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( pNotify ) );
130 : :
131 [ # # ]: 0 : if( aHint.get() )
132 : : {
133 [ # # ]: 0 : Broadcast( *aHint.get() );
134 [ # # ]: 0 : }
135 : : }
136 : :
137 : 0 : return 0;
138 : : }
139 : :
140 : :
141 : : // =============================================================================
142 : : // declaration and implementation of accessible context for <SidebarTxtControl> instance
143 : : // =============================================================================
144 : : class SidebarTxtControlAccessibleContext : public VCLXAccessibleComponent
145 : : {
146 : : public:
147 : : explicit SidebarTxtControlAccessibleContext( SidebarTxtControl& rSidebarTxtControl );
148 : : virtual ~SidebarTxtControlAccessibleContext();
149 : :
150 : : virtual sal_Int32 SAL_CALL
151 : : getAccessibleChildCount()
152 : : throw (::com::sun::star::uno::RuntimeException);
153 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
154 : : getAccessibleChild( sal_Int32 i )
155 : : throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
156 : :
157 : : using WeakAggComponentImplHelperBase::addEventListener;
158 : : using WeakAggComponentImplHelperBase::removeEventListener;
159 : :
160 : : virtual void SAL_CALL
161 : : addEventListener (
162 : : const ::com::sun::star::uno::Reference<
163 : : ::com::sun::star::accessibility::XAccessibleEventListener >& xListener)
164 : : throw (::com::sun::star::uno::RuntimeException);
165 : : virtual void SAL_CALL
166 : : removeEventListener (
167 : : const ::com::sun::star::uno::Reference<
168 : : ::com::sun::star::accessibility::XAccessibleEventListener >& xListener)
169 : : throw (::com::sun::star::uno::RuntimeException);
170 : :
171 : : protected:
172 : : virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent );
173 : :
174 : : private:
175 : : SidebarTxtControl& mrSidebarTxtControl;
176 : : ::accessibility::AccessibleTextHelper* mpAccessibleTextHelper;
177 : :
178 : : ::osl::Mutex maMutex;
179 : :
180 : : void defunc();
181 : : };
182 : :
183 : 0 : SidebarTxtControlAccessibleContext::SidebarTxtControlAccessibleContext( SidebarTxtControl& rSidebarTxtControl )
184 : : : VCLXAccessibleComponent( rSidebarTxtControl.GetWindowPeer() )
185 : : , mrSidebarTxtControl( rSidebarTxtControl )
186 : : , mpAccessibleTextHelper( 0 )
187 [ # # ]: 0 : , maMutex()
188 : : {
189 : : ::std::auto_ptr<SvxEditSource> pEditSource(
190 [ # # ][ # # ]: 0 : new SidebarTextEditSource( mrSidebarTxtControl ) );
191 [ # # ][ # # ]: 0 : mpAccessibleTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
[ # # ]
192 [ # # ][ # # ]: 0 : mpAccessibleTextHelper->SetEventSource( mrSidebarTxtControl.GetWindowPeer() );
[ # # ][ # # ]
[ # # ]
193 : 0 : }
194 : :
195 [ # # ]: 0 : SidebarTxtControlAccessibleContext::~SidebarTxtControlAccessibleContext()
196 : : {
197 [ # # ]: 0 : defunc();
198 [ # # ]: 0 : }
199 : :
200 : 0 : void SidebarTxtControlAccessibleContext::defunc()
201 : : {
202 [ # # ]: 0 : delete mpAccessibleTextHelper;
203 : 0 : mpAccessibleTextHelper = 0;
204 : 0 : }
205 : :
206 : 0 : sal_Int32 SAL_CALL SidebarTxtControlAccessibleContext::getAccessibleChildCount()
207 : : throw (::com::sun::star::uno::RuntimeException)
208 : : {
209 [ # # ]: 0 : osl::MutexGuard aGuard( maMutex );
210 : :
211 : 0 : sal_Int32 nChildCount( 0 );
212 : :
213 [ # # ]: 0 : if ( mpAccessibleTextHelper )
214 : : {
215 [ # # ]: 0 : nChildCount = mpAccessibleTextHelper->GetChildCount();
216 : : }
217 : :
218 [ # # ]: 0 : return nChildCount;
219 : : }
220 : :
221 : 0 : css::uno::Reference< css::accessibility::XAccessible > SAL_CALL SidebarTxtControlAccessibleContext::getAccessibleChild( sal_Int32 i )
222 : : throw ( css::lang::IndexOutOfBoundsException, css::uno::RuntimeException )
223 : : {
224 [ # # ]: 0 : osl::MutexGuard aGuard( maMutex );
225 : :
226 : 0 : css::uno::Reference< css::accessibility::XAccessible > xChild;
227 : :
228 [ # # ]: 0 : if ( mpAccessibleTextHelper )
229 : : {
230 [ # # ][ # # ]: 0 : xChild = mpAccessibleTextHelper->GetChild( i );
231 : : }
232 : :
233 [ # # ]: 0 : return xChild;
234 : : }
235 : :
236 : 0 : void SAL_CALL SidebarTxtControlAccessibleContext::addEventListener (
237 : : const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener)
238 : : throw (css::uno::RuntimeException)
239 : : {
240 [ # # ]: 0 : osl::MutexGuard aGuard( maMutex );
241 : :
242 [ # # ]: 0 : if ( mpAccessibleTextHelper )
243 : : {
244 [ # # ]: 0 : mpAccessibleTextHelper->AddEventListener(xListener);
245 [ # # ]: 0 : }
246 : 0 : }
247 : :
248 : 0 : void SAL_CALL SidebarTxtControlAccessibleContext::removeEventListener (
249 : : const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener)
250 : : throw (css::uno::RuntimeException)
251 : : {
252 [ # # ]: 0 : osl::MutexGuard aGuard( maMutex );
253 : :
254 [ # # ]: 0 : if ( mpAccessibleTextHelper )
255 : : {
256 [ # # ]: 0 : mpAccessibleTextHelper->RemoveEventListener(xListener);
257 [ # # ]: 0 : }
258 : 0 : }
259 : :
260 : 0 : void SidebarTxtControlAccessibleContext::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
261 : : {
262 [ # # ]: 0 : if ( mpAccessibleTextHelper )
263 : : {
264 [ # # # # ]: 0 : switch ( rVclWindowEvent.GetId() )
265 : : {
266 : : case VCLEVENT_OBJECT_DYING:
267 : : {
268 : 0 : defunc();
269 : : }
270 : 0 : break;
271 : : case VCLEVENT_WINDOW_GETFOCUS:
272 : : case VCLEVENT_CONTROL_GETFOCUS:
273 : : {
274 : 0 : mpAccessibleTextHelper->SetFocus( sal_True );
275 : : }
276 : 0 : break;
277 : : case VCLEVENT_WINDOW_LOSEFOCUS:
278 : : case VCLEVENT_CONTROL_LOSEFOCUS:
279 : : {
280 : 0 : mpAccessibleTextHelper->SetFocus( sal_False );
281 : : }
282 : 0 : break;
283 : : }
284 : : }
285 : :
286 : 0 : VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
287 : 0 : }
288 : :
289 : : // =============================================================================
290 : : // implementaion of accessible for <SidebarTxtControl> instance
291 : : // =============================================================================
292 : 0 : SidebarTxtControlAccessible::SidebarTxtControlAccessible( SidebarTxtControl& rSidebarTxtControl )
293 : : : VCLXWindow()
294 : 0 : , mrSidebarTxtControl( rSidebarTxtControl )
295 : : {
296 [ # # ]: 0 : SetWindow( &mrSidebarTxtControl );
297 : 0 : }
298 : :
299 : 0 : SidebarTxtControlAccessible::~SidebarTxtControlAccessible()
300 : : {
301 [ # # ]: 0 : }
302 : :
303 : 0 : css::uno::Reference< css::accessibility::XAccessibleContext > SidebarTxtControlAccessible::CreateAccessibleContext()
304 : : {
305 : : SidebarTxtControlAccessibleContext* pAccContext(
306 [ # # ]: 0 : new SidebarTxtControlAccessibleContext( mrSidebarTxtControl ) );
307 [ # # ]: 0 : css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext );
308 : 0 : return xAcc;
309 : : }
310 : :
311 : : } } // end of namespace sw::sidebarwindows
312 : :
313 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|