Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / uitest / uiobject.cxx
blob097769e3704fed730362f8351b4dedc2637a9734
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/.
8 */
10 #include <memory>
11 #include <uiobject.hxx>
12 #include <edtwin.hxx>
13 #include <view.hxx>
14 #include <wrtsh.hxx>
15 #include <ndtxt.hxx>
16 #include <viewopt.hxx>
17 #include <sfx2/sidebar/Sidebar.hxx>
18 #include <sfx2/viewfrm.hxx>
20 #include <AnnotationWin.hxx>
21 #include <editeng/editeng.hxx>
22 #include <editeng/editview.hxx>
24 SwEditWinUIObject::SwEditWinUIObject(const VclPtr<SwEditWin>& xEditWin):
25 WindowUIObject(xEditWin),
26 mxEditWin(xEditWin)
30 namespace {
32 SwWrtShell& getWrtShell(VclPtr<SwEditWin> const & xEditWin)
34 return xEditWin->GetView().GetWrtShell();
39 StringMap SwEditWinUIObject::get_state()
41 StringMap aMap = WindowUIObject::get_state();
43 aMap["SelectedText"] = mxEditWin->GetView().GetSelectionText();
45 sal_uInt16 nPageNum = 0;
46 sal_uInt16 nVirtPageNum = 0;
47 SwWrtShell& rWrtShell = getWrtShell(mxEditWin);
48 rWrtShell.GetPageNum(nPageNum, nVirtPageNum);
49 aMap["CurrentPage"] = OUString::number(nPageNum);
50 rWrtShell.GetPageNum(nPageNum, nVirtPageNum, false);
51 aMap["TopVisiblePage"] = OUString::number(nPageNum);
52 aMap["Zoom"] = OUString::number(rWrtShell.GetViewOptions()->GetZoom());
54 sal_uInt16 nPages = rWrtShell.GetPageCnt();
55 aMap["Pages"] = OUString::number(nPages);
57 aMap["StartWord"] = OUString::boolean(rWrtShell.IsStartWord());
58 aMap["EndWord"] = OUString::boolean(rWrtShell.IsEndWord());
59 aMap["StartSentence"] = OUString::boolean(rWrtShell.IsStartSentence());
60 aMap["EndSentence"] = OUString::boolean(rWrtShell.IsEndSentence());
61 aMap["StartPara"] = OUString::boolean(rWrtShell.IsSttPara());
62 aMap["EndPara"] = OUString::boolean(rWrtShell.IsEndPara());
63 aMap["StartDoc"] = OUString::boolean(rWrtShell.IsStartOfDoc());
64 aMap["EndDoc"] = OUString::boolean(rWrtShell.IsEndOfDoc());
66 return aMap;
69 void SwEditWinUIObject::execute(const OUString& rAction,
70 const StringMap& rParameters)
72 if (rAction == "SET")
74 if (rParameters.find("ZOOM") != rParameters.end())
76 auto itr = rParameters.find("ZOOM");
77 OUString aVal = itr->second;
78 sal_Int32 nVal = aVal.toInt32();
79 mxEditWin->GetView().SetZoom(SvxZoomType::PERCENT, nVal);
82 else if (rAction == "GOTO")
84 if (rParameters.find("PAGE") != rParameters.end())
86 auto itr = rParameters.find("PAGE");
87 OUString aVal = itr->second;
88 sal_Int32 nVal = aVal.toInt32();
89 getWrtShell(mxEditWin).GotoPage(nVal, false);
92 else if (rAction == "SELECT")
94 if (rParameters.find("START_POS") != rParameters.end())
96 auto itr = rParameters.find("START_POS");
97 OUString aStartPos = itr->second;
98 TextFrameIndex const nStartPos(aStartPos.toInt32());
100 itr = rParameters.find("END_POS");
101 assert(itr != rParameters.end());
102 OUString aEndPos = itr->second;
103 TextFrameIndex const nEndPos(aEndPos.toInt32());
105 auto & shell = getWrtShell(mxEditWin);
106 if (shell.GetCursor_()->GetPoint()->GetNode().GetTextNode())
108 shell.Push();
109 shell.MovePara(GoCurrPara, fnParaEnd);
110 TextFrameIndex const len(shell.GetCursorPointAsViewIndex());
111 shell.Pop(SwCursorShell::PopMode::DeleteCurrent);
112 SAL_WARN_IF(
113 sal_Int32(nStartPos) < 0 || nStartPos > len || sal_Int32(nEndPos) < 0 || nEndPos > len, "sw.ui",
114 "SELECT START/END_POS " << sal_Int32(nStartPos) << ".." << sal_Int32(nEndPos) << " outside 0.." << sal_Int32(len));
115 shell.SelectTextView(
116 std::clamp(nStartPos, TextFrameIndex(0), len), std::clamp(nEndPos, TextFrameIndex(0), len));
118 else
120 SAL_WARN("sw.ui", "SELECT without SwTextNode");
124 else if (rAction == "SIDEBAR")
126 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
127 DBG_ASSERT(pViewFrm, "SwEditWinUIObject::execute: no viewframe");
128 pViewFrm->ShowChildWindow(SID_SIDEBAR);
130 if (rParameters.find("PANEL") != rParameters.end())
132 auto itr = rParameters.find("PANEL");
133 OUString aVal = itr->second;
134 ::sfx2::sidebar::Sidebar::ShowPanel(aVal, pViewFrm->GetFrame().GetFrameInterface());
137 else
138 WindowUIObject::execute(rAction, rParameters);
141 OUString SwEditWinUIObject::get_name() const
143 return "SwEditWinUIObject";
146 std::unique_ptr<UIObject> SwEditWinUIObject::create(vcl::Window* pWindow)
148 SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(pWindow);
149 assert(pEditWin);
150 return std::unique_ptr<UIObject>(new SwEditWinUIObject(pEditWin));
153 CommentUIObject::CommentUIObject(const VclPtr<sw::annotation::SwAnnotationWin>& xCommentUIObject):
154 WindowUIObject(xCommentUIObject),
155 mxCommentUIObject(xCommentUIObject)
159 StringMap CommentUIObject::get_state()
161 StringMap aMap = WindowUIObject::get_state();
162 aMap["Author"] = mxCommentUIObject->GetAuthor();
163 aMap["ReadOnly"] = OUString::boolean(mxCommentUIObject->IsReadOnly());
164 aMap["Resolved"] = OUString::boolean(mxCommentUIObject->IsResolved());
165 aMap["Visible"] = OUString::boolean(mxCommentUIObject->IsVisible());
167 aMap["Text"] = mxCommentUIObject->GetOutliner()->GetEditEngine().GetText();
168 aMap["SelectedText"] = mxCommentUIObject->GetOutlinerView()->GetEditView().GetSelected();
169 return aMap;
172 void CommentUIObject::execute(const OUString& rAction,
173 const StringMap& rParameters)
175 if (rAction == "SELECT")
177 if (rParameters.find("FROM") != rParameters.end() &&
178 rParameters.find("TO") != rParameters.end())
180 tools::Long nMin = rParameters.find("FROM")->second.toInt32();
181 tools::Long nMax = rParameters.find("TO")->second.toInt32();
182 ESelection aNewSelection( 0 , nMin, mxCommentUIObject->GetOutliner()->GetParagraphCount()-1, nMax );
183 mxCommentUIObject->GetOutlinerView()->SetSelection( aNewSelection );
186 else if (rAction == "LEAVE")
188 mxCommentUIObject->SwitchToFieldPos();
190 else if (rAction == "HIDE")
192 mxCommentUIObject->HideNote();
194 else if (rAction == "SHOW")
196 mxCommentUIObject->ShowNote();
198 else if (rAction == "DELETE")
200 mxCommentUIObject->Delete();
202 else if (rAction == "RESOLVE")
204 mxCommentUIObject->SetResolved(true);
206 else
207 WindowUIObject::execute(rAction, rParameters);
210 std::unique_ptr<UIObject> CommentUIObject::create(vcl::Window* pWindow)
212 sw::annotation::SwAnnotationWin* pCommentUIObject = dynamic_cast<sw::annotation::SwAnnotationWin*>(pWindow);
213 assert(pCommentUIObject);
214 return std::unique_ptr<UIObject>(new CommentUIObject(pCommentUIObject));
217 OUString CommentUIObject::get_name() const
219 return "CommentUIObject";
222 PageBreakUIObject::PageBreakUIObject(const VclPtr<SwBreakDashedLine>& xPageBreakUIObject):
223 WindowUIObject(xPageBreakUIObject),
224 mxPageBreakUIObject(xPageBreakUIObject)
228 void PageBreakUIObject::execute(const OUString& rAction,
229 const StringMap& rParameters)
231 if (rAction == "DELETE" || rAction == "EDIT")
232 mxPageBreakUIObject->execute(rAction.toAsciiLowerCase());
233 else
234 WindowUIObject::execute(rAction, rParameters);
237 std::unique_ptr<UIObject> PageBreakUIObject::create(vcl::Window* pWindow)
239 SwBreakDashedLine* pPageBreakWin = dynamic_cast<SwBreakDashedLine*>(pWindow);
240 assert(pPageBreakWin);
241 return std::unique_ptr<UIObject>(new PageBreakUIObject(pPageBreakWin));
244 OUString PageBreakUIObject::get_name() const
246 return "PageBreakUIObject";
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */