1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
11 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
13 #include <comphelper/propertyvalue.hxx>
14 #include <comphelper/dispatchcommand.hxx>
16 #include <AccessibilityIssue.hxx>
17 #include <AccessibilityCheckStrings.hrc>
18 #include <drawdoc.hxx>
20 #include <IDocumentDrawModelAccess.hxx>
21 #include <OnlineAccessibilityCheck.hxx>
22 #include <swtypes.hxx>
26 #include <comphelper/lok.hxx>
27 #include <cui/dlgname.hxx>
28 #include <svx/svdpage.hxx>
29 #include <svx/svxdlg.hxx>
33 AccessibilityIssue::AccessibilityIssue(sfx::AccessibilityIssueID eIssueID
)
34 : sfx::AccessibilityIssue(eIssueID
)
35 , m_eIssueObject(IssueObject::UNKNOWN
)
38 , m_pTextFootnote(nullptr)
44 void AccessibilityIssue::setIssueObject(IssueObject eIssueObject
) { m_eIssueObject
= eIssueObject
; }
46 void AccessibilityIssue::setDoc(SwDoc
& rDoc
) { m_pDoc
= &rDoc
; }
48 void AccessibilityIssue::setObjectID(OUString
const& rID
) { m_sObjectID
= rID
; }
50 bool AccessibilityIssue::canGotoIssue() const
52 if (m_pDoc
&& m_eIssueObject
!= IssueObject::UNKNOWN
53 && m_eIssueObject
!= IssueObject::DOCUMENT_TITLE
54 && m_eIssueObject
!= IssueObject::DOCUMENT_BACKGROUND
55 && m_eIssueObject
!= IssueObject::LANGUAGE_NOT_SET
)
60 void AccessibilityIssue::gotoIssue() const
65 /* Copying the issueobject because the EnterSelFrameMode ends up calling some sidebar functions
66 that recreate the list of a11y issues and the AccessibilityIssue objects are stored by value in a vector
67 and the vector is being mutated there and so the instance is overwritten with something else. */
68 AccessibilityIssue
TempIssueObject(*this);
70 switch (TempIssueObject
.m_eIssueObject
)
72 case IssueObject::GRAPHIC
:
73 case IssueObject::OLE
:
74 case IssueObject::TEXTFRAME
:
76 SwWrtShell
* pWrtShell
= TempIssueObject
.m_pDoc
->GetDocShell()->GetWrtShell();
77 bool bSelected
= pWrtShell
->GotoFly(TempIssueObject
.m_sObjectID
, FLYCNTTYPE_ALL
, true);
78 if (bSelected
&& pWrtShell
->IsFrameSelected())
80 pWrtShell
->HideCursor();
81 pWrtShell
->EnterSelFrameMode();
84 if (!bSelected
&& TempIssueObject
.m_eIssueObject
== IssueObject::TEXTFRAME
)
85 pWrtShell
->GotoDrawingObject(TempIssueObject
.m_sObjectID
);
87 if (comphelper::LibreOfficeKit::isActive())
88 pWrtShell
->ShowCursor();
91 case IssueObject::SHAPE
:
93 SwWrtShell
* pWrtShell
= TempIssueObject
.m_pDoc
->GetDocShell()->GetWrtShell();
94 pWrtShell
->GotoDrawingObject(TempIssueObject
.m_sObjectID
);
95 if (comphelper::LibreOfficeKit::isActive())
96 pWrtShell
->ShowCursor();
99 case IssueObject::FORM
:
101 SwWrtShell
* pWrtShell
= TempIssueObject
.m_pDoc
->GetDocShell()->GetWrtShell();
102 bool bIsDesignMode
= pWrtShell
->GetView().GetFormShell()->IsDesignMode();
103 if (bIsDesignMode
|| (!bIsDesignMode
&& pWrtShell
->WarnSwitchToDesignModeDialog()))
106 pWrtShell
->GetView().GetFormShell()->SetDesignMode(true);
107 pWrtShell
->GotoDrawingObject(TempIssueObject
.m_sObjectID
);
108 if (comphelper::LibreOfficeKit::isActive())
109 pWrtShell
->ShowCursor();
113 case IssueObject::TABLE
:
115 SwWrtShell
* pWrtShell
= TempIssueObject
.m_pDoc
->GetDocShell()->GetWrtShell();
116 pWrtShell
->GotoTable(TempIssueObject
.m_sObjectID
);
117 if (comphelper::LibreOfficeKit::isActive())
118 pWrtShell
->ShowCursor();
121 case IssueObject::TEXT
:
123 SwWrtShell
* pWrtShell
= TempIssueObject
.m_pDoc
->GetDocShell()->GetWrtShell();
124 SwContentNode
* pContentNode
= TempIssueObject
.m_pNode
->GetContentNode();
125 SwPosition
aPoint(*pContentNode
, TempIssueObject
.m_nStart
);
126 SwPosition
aMark(*pContentNode
, TempIssueObject
.m_nEnd
);
127 pWrtShell
->EnterStdMode();
128 pWrtShell
->StartAllAction();
129 SwPaM
* pPaM
= pWrtShell
->GetCursor();
130 *pPaM
->GetPoint() = aPoint
;
132 *pPaM
->GetMark() = aMark
;
133 pWrtShell
->EndAllAction();
134 if (comphelper::LibreOfficeKit::isActive())
135 pWrtShell
->ShowCursor();
138 case IssueObject::FOOTENDNOTE
:
140 SwWrtShell
* pWrtShell
= TempIssueObject
.m_pDoc
->GetDocShell()->GetWrtShell();
141 if (TempIssueObject
.m_pTextFootnote
)
142 pWrtShell
->GotoFootnoteAnchor(*TempIssueObject
.m_pTextFootnote
);
143 if (comphelper::LibreOfficeKit::isActive())
144 pWrtShell
->ShowCursor();
150 TempIssueObject
.m_pDoc
->GetDocShell()->GetView()->GetEditWin().GrabFocus();
153 bool AccessibilityIssue::canQuickFixIssue() const
155 return m_eIssueObject
== IssueObject::GRAPHIC
|| m_eIssueObject
== IssueObject::OLE
156 || m_eIssueObject
== IssueObject::SHAPE
|| m_eIssueObject
== IssueObject::FORM
157 || m_eIssueObject
== IssueObject::DOCUMENT_TITLE
158 || m_eIssueObject
== IssueObject::DOCUMENT_BACKGROUND
159 || m_eIssueObject
== IssueObject::LANGUAGE_NOT_SET
;
162 void AccessibilityIssue::quickFixIssue() const
170 switch (m_eIssueObject
)
172 case IssueObject::GRAPHIC
:
173 case IssueObject::OLE
:
175 SwFlyFrameFormat
* pFlyFormat
176 = const_cast<SwFlyFrameFormat
*>(m_pDoc
->FindFlyByName(m_sObjectID
));
179 OUString
aDescription(pFlyFormat
->GetObjDescription());
180 OUString
aTitle(pFlyFormat
->GetObjTitle());
181 bool isDecorative(pFlyFormat
->IsDecorative());
183 SwWrtShell
* pWrtShell
= m_pDoc
->GetDocShell()->GetWrtShell();
184 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
185 ScopedVclPtr
<AbstractSvxObjectTitleDescDialog
> pDlg(
186 pFact
->CreateSvxObjectTitleDescDialog(pWrtShell
->GetView().GetFrameWeld(),
187 aTitle
, aDescription
, isDecorative
));
189 if (pDlg
->Execute() == RET_OK
)
191 pDlg
->GetTitle(aTitle
);
192 pDlg
->GetDescription(aDescription
);
193 pDlg
->IsDecorative(isDecorative
);
195 m_pDoc
->SetFlyFrameTitle(*pFlyFormat
, aTitle
);
196 m_pDoc
->SetFlyFrameDescription(*pFlyFormat
, aDescription
);
197 m_pDoc
->SetFlyFrameDecorative(*pFlyFormat
, isDecorative
);
199 pWrtShell
->SetModified();
204 case IssueObject::SHAPE
:
205 case IssueObject::FORM
:
207 SwWrtShell
* pWrtShell
= m_pDoc
->GetDocShell()->GetWrtShell();
208 auto pPage
= pWrtShell
->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
209 SdrObject
* pObj
= pPage
->GetObjByName(m_sObjectID
);
212 OUString
aTitle(pObj
->GetTitle());
213 OUString
aDescription(pObj
->GetDescription());
214 bool isDecorative(pObj
->IsDecorative());
216 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
217 ScopedVclPtr
<AbstractSvxObjectTitleDescDialog
> pDlg(
218 pFact
->CreateSvxObjectTitleDescDialog(pWrtShell
->GetView().GetFrameWeld(),
219 aTitle
, aDescription
, isDecorative
));
221 if (RET_OK
== pDlg
->Execute())
223 pDlg
->GetTitle(aTitle
);
224 pDlg
->GetDescription(aDescription
);
225 pDlg
->IsDecorative(isDecorative
);
227 pObj
->SetTitle(aTitle
);
228 pObj
->SetDescription(aDescription
);
229 pObj
->SetDecorative(isDecorative
);
231 pWrtShell
->SetModified();
236 case IssueObject::DOCUMENT_TITLE
:
238 OUString aDesc
= SwResId(STR_ENTER_DOCUMENT_TITLE
);
239 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
240 SwWrtShell
* pWrtShell
= m_pDoc
->GetDocShell()->GetWrtShell();
241 ScopedVclPtr
<AbstractSvxNameDialog
> aNameDialog(
242 pFact
->CreateSvxNameDialog(pWrtShell
->GetView().GetFrameWeld(), "", aDesc
));
243 if (aNameDialog
->Execute() == RET_OK
)
245 SwDocShell
* pShell
= m_pDoc
->GetDocShell();
249 const uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
250 pShell
->GetModel(), uno::UNO_QUERY_THROW
);
251 const uno::Reference
<document::XDocumentProperties
> xDocumentProperties(
252 xDPS
->getDocumentProperties());
254 aNameDialog
->GetName(sName
);
255 xDocumentProperties
->setTitle(sName
);
257 m_pDoc
->getOnlineAccessibilityCheck()->resetAndQueueDocumentLevel();
261 case IssueObject::DOCUMENT_BACKGROUND
:
263 uno::Reference
<frame::XModel
> xModel(m_pDoc
->GetDocShell()->GetModel(),
264 uno::UNO_QUERY_THROW
);
266 comphelper::dispatchCommand(".uno:PageAreaDialog",
267 xModel
->getCurrentController()->getFrame(), {});
270 case IssueObject::LANGUAGE_NOT_SET
:
272 uno::Reference
<frame::XModel
> xModel(m_pDoc
->GetDocShell()->GetModel(),
273 uno::UNO_QUERY_THROW
);
275 if (m_sObjectID
.isEmpty())
277 // open the dialog "Tools/Options/Language Settings - Language"
278 uno::Sequence
<beans::PropertyValue
> aArgs
{ comphelper::makePropertyValue(
279 "Language", OUString("*")) };
281 comphelper::dispatchCommand(".uno:LanguageStatus",
282 xModel
->getCurrentController()->getFrame(), aArgs
);
286 uno::Sequence
<beans::PropertyValue
> aArgs
{
287 comphelper::makePropertyValue("Param", m_sObjectID
),
288 comphelper::makePropertyValue("Family", sal_Int16(SfxStyleFamily::Para
))
291 comphelper::dispatchCommand(".uno:EditStyleFont",
292 xModel
->getCurrentController()->getFrame(), aArgs
);
300 m_pDoc
->getOnlineAccessibilityCheck()->resetAndQueue(m_pNode
);
303 } // end sw namespace
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */