1 /*************************************************************************
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * Copyright 2000, 2010 Oracle and/or its affiliates.
5  *
6  * OpenOffice.org - a multi-platform office productivity suite
7  *
8  * This file is part of OpenOffice.org.
9  *
10  * OpenOffice.org is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License version 3
12  * only, as published by the Free Software Foundation.
13  *
14  * OpenOffice.org is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License version 3 for more details
18  * (a copy is included in the LICENSE file that accompanied this code).
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with OpenOffice.org.  If not, see
22  * <http://www.openoffice.org/license.html>
23  * for a copy of the LGPLv3 License.
24  *
25  ************************************************************************/
26 
27 #include "precompiled_svtools.hxx"
28 
29 #include "toolpaneldrawerpeer.hxx"
30 #include "toolpaneldrawer.hxx"
31 
32 /** === begin UNO includes === **/
33 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
34 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
35 /** === end UNO includes === **/
36 
37 #include <tools/diagnose_ex.h>
38 #include <toolkit/awt/vclxaccessiblecomponent.hxx>
39 #include <unotools/accessiblestatesethelper.hxx>
40 #include <vcl/vclevent.hxx>
41 
42 //......................................................................................................................
43 namespace svt
44 {
45 //......................................................................................................................
46 
47 	/** === begin UNO using === **/
48 	using ::com::sun::star::uno::Reference;
49 	using ::com::sun::star::uno::XInterface;
50 	using ::com::sun::star::uno::UNO_QUERY;
51 	using ::com::sun::star::uno::UNO_QUERY_THROW;
52 	using ::com::sun::star::uno::UNO_SET_THROW;
53 	using ::com::sun::star::uno::Exception;
54 	using ::com::sun::star::uno::RuntimeException;
55 	using ::com::sun::star::uno::Any;
56 	using ::com::sun::star::uno::makeAny;
57 	using ::com::sun::star::uno::Sequence;
58 	using ::com::sun::star::uno::Type;
59     using ::com::sun::star::accessibility::XAccessibleContext;
60 	/** === end UNO using === **/
61     namespace AccessibleStateType = ::com::sun::star::accessibility::AccessibleStateType;
62     namespace AccessibleEventId = ::com::sun::star::accessibility::AccessibleEventId;
63 
64 	//==================================================================================================================
65 	//= ToolPanelDrawerContext
66 	//==================================================================================================================
67     class ToolPanelDrawerContext : public VCLXAccessibleComponent
68     {
69     public:
70         ToolPanelDrawerContext( VCLXWindow& i_rWindow )
71             :VCLXAccessibleComponent( &i_rWindow )
72         {
73         }
74 
75         virtual void	ProcessWindowEvent( const VclWindowEvent& i_rVclWindowEvent );
76         virtual void	FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& i_rStateSet );
77 
78     protected:
79         ~ToolPanelDrawerContext()
80         {
81         }
82     };
83 
84 	//------------------------------------------------------------------------------------------------------------------
85     void ToolPanelDrawerContext::ProcessWindowEvent( const VclWindowEvent& i_rVclWindowEvent )
86     {
87         VCLXAccessibleComponent::ProcessWindowEvent( i_rVclWindowEvent );
88 
89         switch ( i_rVclWindowEvent.GetId() )
90         {
91         case VCLEVENT_ITEM_EXPANDED:
92             NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, Any(), makeAny( AccessibleStateType::EXPANDED ) );
93             break;
94         case VCLEVENT_ITEM_COLLAPSED:
95             NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, makeAny( AccessibleStateType::EXPANDED ), Any() );
96             break;
97         }
98     }
99 
100 	//------------------------------------------------------------------------------------------------------------------
101     void ToolPanelDrawerContext::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& i_rStateSet )
102     {
103         VCLXAccessibleComponent::FillAccessibleStateSet( i_rStateSet );
104         if ( !GetWindow() )
105             return;
106 
107         i_rStateSet.AddState( AccessibleStateType::EXPANDABLE );
108         i_rStateSet.AddState( AccessibleStateType::FOCUSABLE );
109 
110         const ToolPanelDrawer* pDrawer( dynamic_cast< const ToolPanelDrawer* > ( GetWindow() ) );
111         ENSURE_OR_RETURN_VOID( pDrawer, "ToolPanelDrawerContext::FillAccessibleStateSet: illegal window!" );
112         if ( pDrawer->IsExpanded() )
113             i_rStateSet.AddState( AccessibleStateType::EXPANDED );
114 
115         if ( pDrawer->HasChildPathFocus() )
116             i_rStateSet.AddState( AccessibleStateType::FOCUSED );
117     }
118 
119 	//==================================================================================================================
120 	//= ToolPanelDrawerPeer
121 	//==================================================================================================================
122 	//------------------------------------------------------------------------------------------------------------------
123     ToolPanelDrawerPeer::ToolPanelDrawerPeer()
124         :VCLXWindow()
125     {
126     }
127 
128 	//------------------------------------------------------------------------------------------------------------------
129     ToolPanelDrawerPeer::~ToolPanelDrawerPeer()
130     {
131     }
132 
133 	//------------------------------------------------------------------------------------------------------------------
134     Reference< XAccessibleContext > ToolPanelDrawerPeer::CreateAccessibleContext()
135     {
136         ::vos::OGuard aSolarGuard( GetMutex() );
137         return new ToolPanelDrawerContext( *this );
138     }
139 
140 //......................................................................................................................
141 } // namespace svt
142 //......................................................................................................................
143