android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / access / accpage.cxx
blobb3427559b3f8b2b31d4e1f22d3c1244095416b51
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/window.hxx>
21 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
22 #include <com/sun/star/accessibility/AccessibleRole.hpp>
23 #include <cppuhelper/supportsservice.hxx>
24 #include "accpage.hxx"
26 #include <strings.hrc>
27 #include <pagefrm.hxx>
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::accessibility;
32 using uno::Sequence;
34 constexpr OUStringLiteral sImplementationName = u"com.sun.star.comp.Writer.SwAccessiblePageView";
36 bool SwAccessiblePage::IsSelected()
38 return GetMap()->IsPageSelected( static_cast < const SwPageFrame * >( GetFrame() ) );
41 void SwAccessiblePage::GetStates( sal_Int64& rStateSet )
43 SwAccessibleContext::GetStates( rStateSet );
45 // FOCUSABLE
46 rStateSet |= AccessibleStateType::FOCUSABLE;
48 // FOCUSED
49 if( IsSelected() )
51 OSL_ENSURE( m_bIsSelected, "bSelected out of sync" );
52 ::rtl::Reference < SwAccessibleContext > xThis( this );
53 GetMap()->SetCursorContext( xThis );
55 vcl::Window *pWin = GetWindow();
56 if( pWin && pWin->HasFocus() )
57 rStateSet |= AccessibleStateType::FOCUSED;
61 void SwAccessiblePage::InvalidateCursorPos_()
63 bool bNewSelected = IsSelected();
64 bool bOldSelected;
67 std::scoped_lock aGuard( m_Mutex );
68 bOldSelected = m_bIsSelected;
69 m_bIsSelected = bNewSelected;
72 if( bNewSelected )
74 // remember that object as the one that has the caret. This is
75 // necessary to notify that object if the cursor leaves it.
76 ::rtl::Reference < SwAccessibleContext > xThis( this );
77 GetMap()->SetCursorContext( xThis );
80 if( bOldSelected != bNewSelected )
82 vcl::Window *pWin = GetWindow();
83 if( pWin && pWin->HasFocus() )
84 FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
88 void SwAccessiblePage::InvalidateFocus_()
90 vcl::Window *pWin = GetWindow();
91 if( !pWin )
92 return;
94 bool bSelected;
97 std::scoped_lock aGuard( m_Mutex );
98 bSelected = m_bIsSelected;
100 OSL_ENSURE( bSelected, "focus object should be selected" );
102 FireStateChangedEvent( AccessibleStateType::FOCUSED,
103 pWin->HasFocus() && bSelected );
106 SwAccessiblePage::SwAccessiblePage(std::shared_ptr<SwAccessibleMap> const& pInitMap,
107 const SwFrame* pFrame )
108 : SwAccessibleContext( pInitMap, AccessibleRole::PANEL, pFrame )
109 , m_bIsSelected( false )
111 assert(pFrame != nullptr);
112 assert(pInitMap != nullptr);
113 assert(pFrame->IsPageFrame());
115 OUString sPage = OUString::number(
116 static_cast<const SwPageFrame*>( GetFrame() )->GetPhyPageNum() );
117 SetName( GetResource( STR_ACCESS_PAGE_NAME, &sPage ) );
120 SwAccessiblePage::~SwAccessiblePage()
124 bool SwAccessiblePage::HasCursor()
126 std::scoped_lock aGuard( m_Mutex );
127 return m_bIsSelected;
130 OUString SwAccessiblePage::getImplementationName( )
132 return sImplementationName;
135 sal_Bool SwAccessiblePage::supportsService( const OUString& rServiceName)
137 return cppu::supportsService(this, rServiceName);
140 Sequence<OUString> SwAccessiblePage::getSupportedServiceNames( )
142 return { "com.sun.star.text.AccessiblePageView", sAccessibleServiceName };
145 Sequence< sal_Int8 > SAL_CALL SwAccessiblePage::getImplementationId()
147 return css::uno::Sequence<sal_Int8>();
150 OUString SwAccessiblePage::getAccessibleDescription( )
152 ThrowIfDisposed();
154 OUString sArg( GetFormattedPageNumber() );
155 return GetResource( STR_ACCESS_PAGE_DESC, &sArg );
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */