1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24
25 #include "precompiled_sw.hxx"
26
27 #include <SidebarTxtControlAcc.hxx>
28
29 #include <SidebarTxtControl.hxx>
30
31 #include <svl/brdcst.hxx>
32 #include <toolkit/awt/vclxaccessiblecomponent.hxx>
33 #include <editeng/unoedsrc.hxx>
34 #include <editeng/unoforou.hxx>
35 #include <editeng/unoviwou.hxx>
36 #include <editeng/unoedhlp.hxx>
37 #include <svx/AccessibleTextHelper.hxx>
38 #include <editeng/outliner.hxx>
39
40
41 namespace css = ::com::sun::star;
42
43 namespace sw { namespace sidebarwindows {
44
45 // =============================================================================
46 // declaration and implementation of <SvxEditSource>
47 // for <::accessibiliy::AccessibleTextHelper> instance
48 // =============================================================================
49 class SidebarTextEditSource : public SvxEditSource,
50 public SfxBroadcaster
51 {
52 public:
53 SidebarTextEditSource( SidebarTxtControl& rSidebarTxtControl );
54 virtual ~SidebarTextEditSource();
55
56 virtual SvxEditSource* Clone() const;
57
58 virtual SvxTextForwarder* GetTextForwarder();
59 virtual SvxViewForwarder* GetViewForwarder();
60 virtual SvxEditViewForwarder* GetEditViewForwarder( sal_Bool bCreate = sal_False );
61
62 virtual void UpdateData();
63
64 virtual SfxBroadcaster& GetBroadcaster() const;
65 DECL_LINK( NotifyHdl, EENotify* );
66
67 private:
68 SidebarTxtControl& mrSidebarTxtControl;
69 SvxOutlinerForwarder mTextForwarder;
70 SvxDrawOutlinerViewForwarder mViewForwarder;
71 };
72
SidebarTextEditSource(SidebarTxtControl & rSidebarTxtControl)73 SidebarTextEditSource::SidebarTextEditSource( SidebarTxtControl& rSidebarTxtControl )
74 : SvxEditSource()
75 , mrSidebarTxtControl( rSidebarTxtControl )
76 , mTextForwarder( *(rSidebarTxtControl.GetTextView()->GetOutliner()), sal_False )
77 , mViewForwarder( *(rSidebarTxtControl.GetTextView()) )
78 {
79 if ( mrSidebarTxtControl.GetTextView() )
80 {
81 mrSidebarTxtControl.GetTextView()->GetOutliner()->SetNotifyHdl( LINK(this, SidebarTextEditSource, NotifyHdl) );
82 }
83 }
84
~SidebarTextEditSource()85 SidebarTextEditSource::~SidebarTextEditSource()
86 {
87 if ( mrSidebarTxtControl.GetTextView() )
88 {
89 mrSidebarTxtControl.GetTextView()->GetOutliner()->SetNotifyHdl( Link() );
90 }
91 }
92
Clone() const93 SvxEditSource* SidebarTextEditSource::Clone() const
94 {
95 return new SidebarTextEditSource( mrSidebarTxtControl );
96 }
97
GetTextForwarder()98 SvxTextForwarder* SidebarTextEditSource::GetTextForwarder()
99 {
100 return &mTextForwarder;
101 }
102
GetViewForwarder()103 SvxViewForwarder* SidebarTextEditSource::GetViewForwarder()
104 {
105 return &mViewForwarder;
106 }
107
GetEditViewForwarder(sal_Bool)108 SvxEditViewForwarder* SidebarTextEditSource::GetEditViewForwarder( sal_Bool /*bCreate*/ )
109 {
110 return &mViewForwarder;
111 }
112
UpdateData()113 void SidebarTextEditSource::UpdateData()
114 {
115 // nothing to do
116 }
117
GetBroadcaster() const118 SfxBroadcaster& SidebarTextEditSource::GetBroadcaster() const
119 {
120 return *( const_cast< SidebarTextEditSource* > (this) );
121 }
122
IMPL_LINK(SidebarTextEditSource,NotifyHdl,EENotify *,pNotify)123 IMPL_LINK(SidebarTextEditSource, NotifyHdl, EENotify*, pNotify)
124 {
125 if ( pNotify )
126 {
127 ::std::auto_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( pNotify ) );
128
129 if( aHint.get() )
130 {
131 Broadcast( *aHint.get() );
132 }
133 }
134
135 return 0;
136 }
137
138
139 // =============================================================================
140 // declaration and implementation of accessible context for <SidebarTxtControl> instance
141 // =============================================================================
142 class SidebarTxtControlAccessibleContext : public VCLXAccessibleComponent
143 {
144 public:
145 explicit SidebarTxtControlAccessibleContext( SidebarTxtControl& rSidebarTxtControl );
146 virtual ~SidebarTxtControlAccessibleContext();
147
148 virtual sal_Int32 SAL_CALL
149 getAccessibleChildCount()
150 throw (::com::sun::star::uno::RuntimeException);
151 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
152 getAccessibleChild( sal_Int32 i )
153 throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
154
155 using WeakAggComponentImplHelperBase::addEventListener;
156 using WeakAggComponentImplHelperBase::removeEventListener;
157
158 virtual void SAL_CALL
159 addEventListener (
160 const ::com::sun::star::uno::Reference<
161 ::com::sun::star::accessibility::XAccessibleEventListener >& xListener)
162 throw (::com::sun::star::uno::RuntimeException);
163 virtual void SAL_CALL
164 removeEventListener (
165 const ::com::sun::star::uno::Reference<
166 ::com::sun::star::accessibility::XAccessibleEventListener >& xListener)
167 throw (::com::sun::star::uno::RuntimeException);
168
169 protected:
170 virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent );
171
172 private:
173 SidebarTxtControl& mrSidebarTxtControl;
174 ::accessibility::AccessibleTextHelper* mpAccessibleTextHelper;
175
176 ::vos::OMutex maMutex;
177
178 void defunc();
179 };
180
SidebarTxtControlAccessibleContext(SidebarTxtControl & rSidebarTxtControl)181 SidebarTxtControlAccessibleContext::SidebarTxtControlAccessibleContext( SidebarTxtControl& rSidebarTxtControl )
182 : VCLXAccessibleComponent( rSidebarTxtControl.GetWindowPeer() )
183 , mrSidebarTxtControl( rSidebarTxtControl )
184 , mpAccessibleTextHelper( 0 )
185 , maMutex()
186 {
187 ::std::auto_ptr<SvxEditSource> pEditSource(
188 new SidebarTextEditSource( mrSidebarTxtControl ) );
189 mpAccessibleTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
190 mpAccessibleTextHelper->SetEventSource( mrSidebarTxtControl.GetWindowPeer() );
191 }
192
~SidebarTxtControlAccessibleContext()193 SidebarTxtControlAccessibleContext::~SidebarTxtControlAccessibleContext()
194 {
195 defunc();
196 }
197
defunc()198 void SidebarTxtControlAccessibleContext::defunc()
199 {
200 delete mpAccessibleTextHelper;
201 mpAccessibleTextHelper = 0;
202 }
203
getAccessibleChildCount()204 sal_Int32 SAL_CALL SidebarTxtControlAccessibleContext::getAccessibleChildCount()
205 throw (::com::sun::star::uno::RuntimeException)
206 {
207 vos::OGuard aGuard( maMutex );
208
209 sal_Int32 nChildCount( 0 );
210
211 if ( mpAccessibleTextHelper )
212 {
213 nChildCount = mpAccessibleTextHelper->GetChildCount();
214 }
215
216 return nChildCount;
217 }
218
getAccessibleChild(sal_Int32 i)219 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL SidebarTxtControlAccessibleContext::getAccessibleChild( sal_Int32 i )
220 throw ( css::lang::IndexOutOfBoundsException, css::uno::RuntimeException )
221 {
222 vos::OGuard aGuard( maMutex );
223
224 css::uno::Reference< css::accessibility::XAccessible > xChild;
225
226 if ( mpAccessibleTextHelper )
227 {
228 xChild = mpAccessibleTextHelper->GetChild( i );
229 }
230
231 return xChild;
232 }
233
addEventListener(const css::uno::Reference<css::accessibility::XAccessibleEventListener> & xListener)234 void SAL_CALL SidebarTxtControlAccessibleContext::addEventListener (
235 const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener)
236 throw (css::uno::RuntimeException)
237 {
238 vos::OGuard aGuard( maMutex );
239
240 if ( mpAccessibleTextHelper )
241 {
242 mpAccessibleTextHelper->AddEventListener(xListener);
243 }
244 }
245
removeEventListener(const css::uno::Reference<css::accessibility::XAccessibleEventListener> & xListener)246 void SAL_CALL SidebarTxtControlAccessibleContext::removeEventListener (
247 const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener)
248 throw (css::uno::RuntimeException)
249 {
250 vos::OGuard aGuard( maMutex );
251
252 if ( mpAccessibleTextHelper )
253 {
254 mpAccessibleTextHelper->RemoveEventListener(xListener);
255 }
256 }
257
ProcessWindowEvent(const VclWindowEvent & rVclWindowEvent)258 void SidebarTxtControlAccessibleContext::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
259 {
260 if ( mpAccessibleTextHelper )
261 {
262 switch ( rVclWindowEvent.GetId() )
263 {
264 case VCLEVENT_OBJECT_DYING:
265 {
266 defunc();
267 }
268 break;
269 case VCLEVENT_WINDOW_GETFOCUS:
270 case VCLEVENT_CONTROL_GETFOCUS:
271 {
272 mpAccessibleTextHelper->SetFocus( sal_True );
273 }
274 break;
275 case VCLEVENT_WINDOW_LOSEFOCUS:
276 case VCLEVENT_CONTROL_LOSEFOCUS:
277 {
278 mpAccessibleTextHelper->SetFocus( sal_False );
279 }
280 break;
281 }
282 }
283
284 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
285 }
286
287 // =============================================================================
288 // implementaion of accessible for <SidebarTxtControl> instance
289 // =============================================================================
SidebarTxtControlAccessible(SidebarTxtControl & rSidebarTxtControl)290 SidebarTxtControlAccessible::SidebarTxtControlAccessible( SidebarTxtControl& rSidebarTxtControl )
291 : VCLXWindow()
292 , mrSidebarTxtControl( rSidebarTxtControl )
293 {
294 SetWindow( &mrSidebarTxtControl );
295 }
296
~SidebarTxtControlAccessible()297 SidebarTxtControlAccessible::~SidebarTxtControlAccessible()
298 {
299 }
300
CreateAccessibleContext()301 css::uno::Reference< css::accessibility::XAccessibleContext > SidebarTxtControlAccessible::CreateAccessibleContext()
302 {
303 SidebarTxtControlAccessibleContext* pAccContext(
304 new SidebarTxtControlAccessibleContext( mrSidebarTxtControl ) );
305 css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext );
306 return xAcc;
307 }
308
309 } } // end of namespace sw::sidebarwindows
310
311