/src/libreoffice/sw/source/uibase/uitest/uiobject.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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 | | */ |
9 | | |
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> |
19 | | |
20 | | #include <AnnotationWin.hxx> |
21 | | #include <editeng/editeng.hxx> |
22 | | #include <editeng/editview.hxx> |
23 | | |
24 | | SwEditWinUIObject::SwEditWinUIObject(const VclPtr<SwEditWin>& xEditWin): |
25 | 0 | WindowUIObject(xEditWin), |
26 | 0 | mxEditWin(xEditWin) |
27 | 0 | { |
28 | 0 | } |
29 | | |
30 | | namespace { |
31 | | |
32 | | SwWrtShell& getWrtShell(VclPtr<SwEditWin> const & xEditWin) |
33 | 0 | { |
34 | 0 | return xEditWin->GetView().GetWrtShell(); |
35 | 0 | } |
36 | | |
37 | | } |
38 | | |
39 | | StringMap SwEditWinUIObject::get_state() |
40 | 0 | { |
41 | 0 | StringMap aMap = WindowUIObject::get_state(); |
42 | |
|
43 | 0 | aMap[u"SelectedText"_ustr] = mxEditWin->GetView().GetSelectionText(); |
44 | |
|
45 | 0 | sal_uInt16 nPageNum = 0; |
46 | 0 | sal_uInt16 nVirtPageNum = 0; |
47 | 0 | SwWrtShell& rWrtShell = getWrtShell(mxEditWin); |
48 | 0 | rWrtShell.GetPageNum(nPageNum, nVirtPageNum); |
49 | 0 | aMap[u"CurrentPage"_ustr] = OUString::number(nPageNum); |
50 | 0 | rWrtShell.GetPageNum(nPageNum, nVirtPageNum, false); |
51 | 0 | aMap[u"TopVisiblePage"_ustr] = OUString::number(nPageNum); |
52 | 0 | aMap[u"Zoom"_ustr] = OUString::number(rWrtShell.GetViewOptions()->GetZoom()); |
53 | |
|
54 | 0 | sal_uInt16 nPages = rWrtShell.GetPageCnt(); |
55 | 0 | aMap[u"Pages"_ustr] = OUString::number(nPages); |
56 | |
|
57 | 0 | aMap[u"StartWord"_ustr] = OUString::boolean(rWrtShell.IsStartWord()); |
58 | 0 | aMap[u"EndWord"_ustr] = OUString::boolean(rWrtShell.IsEndWord()); |
59 | 0 | aMap[u"StartSentence"_ustr] = OUString::boolean(rWrtShell.IsStartSentence()); |
60 | 0 | aMap[u"EndSentence"_ustr] = OUString::boolean(rWrtShell.IsEndSentence()); |
61 | 0 | aMap[u"StartPara"_ustr] = OUString::boolean(rWrtShell.IsSttPara()); |
62 | 0 | aMap[u"EndPara"_ustr] = OUString::boolean(rWrtShell.IsEndPara()); |
63 | 0 | aMap[u"StartDoc"_ustr] = OUString::boolean(rWrtShell.IsStartOfDoc()); |
64 | 0 | aMap[u"EndDoc"_ustr] = OUString::boolean(rWrtShell.IsEndOfDoc()); |
65 | |
|
66 | 0 | return aMap; |
67 | 0 | } |
68 | | |
69 | | void SwEditWinUIObject::execute(const OUString& rAction, |
70 | | const StringMap& rParameters) |
71 | 0 | { |
72 | 0 | if (rAction == "SET") |
73 | 0 | { |
74 | 0 | if (rParameters.find(u"ZOOM"_ustr) != rParameters.end()) |
75 | 0 | { |
76 | 0 | auto itr = rParameters.find(u"ZOOM"_ustr); |
77 | 0 | OUString aVal = itr->second; |
78 | 0 | sal_Int32 nVal = aVal.toInt32(); |
79 | 0 | mxEditWin->GetView().SetZoom(SvxZoomType::PERCENT, nVal); |
80 | 0 | } |
81 | 0 | } |
82 | 0 | else if (rAction == "GOTO") |
83 | 0 | { |
84 | 0 | if (rParameters.find(u"PAGE"_ustr) != rParameters.end()) |
85 | 0 | { |
86 | 0 | auto itr = rParameters.find(u"PAGE"_ustr); |
87 | 0 | OUString aVal = itr->second; |
88 | 0 | sal_Int32 nVal = aVal.toInt32(); |
89 | 0 | getWrtShell(mxEditWin).GotoPage(nVal, false); |
90 | 0 | } |
91 | 0 | } |
92 | 0 | else if (rAction == "SELECT") |
93 | 0 | { |
94 | 0 | if (rParameters.find(u"START_POS"_ustr) != rParameters.end()) |
95 | 0 | { |
96 | 0 | auto itr = rParameters.find(u"START_POS"_ustr); |
97 | 0 | OUString aStartPos = itr->second; |
98 | 0 | TextFrameIndex const nStartPos(aStartPos.toInt32()); |
99 | |
|
100 | 0 | itr = rParameters.find(u"END_POS"_ustr); |
101 | 0 | assert(itr != rParameters.end()); |
102 | 0 | OUString aEndPos = itr->second; |
103 | 0 | TextFrameIndex const nEndPos(aEndPos.toInt32()); |
104 | |
|
105 | 0 | auto & shell = getWrtShell(mxEditWin); |
106 | 0 | if (shell.GetCursor_()->GetPoint()->GetNode().GetTextNode()) |
107 | 0 | { |
108 | 0 | shell.Push(); |
109 | 0 | shell.MovePara(GoCurrPara, fnParaEnd); |
110 | 0 | TextFrameIndex const len(shell.GetCursorPointAsViewIndex()); |
111 | 0 | shell.Pop(SwCursorShell::PopMode::DeleteCurrent); |
112 | 0 | SAL_WARN_IF( |
113 | 0 | sal_Int32(nStartPos) < 0 || nStartPos > len || sal_Int32(nEndPos) < 0 || nEndPos > len, "sw.ui", |
114 | 0 | "SELECT START/END_POS " << sal_Int32(nStartPos) << ".." << sal_Int32(nEndPos) << " outside 0.." << sal_Int32(len)); |
115 | 0 | shell.SelectTextView( |
116 | 0 | std::clamp(nStartPos, TextFrameIndex(0), len), std::clamp(nEndPos, TextFrameIndex(0), len)); |
117 | 0 | } |
118 | 0 | else |
119 | 0 | { |
120 | 0 | SAL_WARN("sw.ui", "SELECT without SwTextNode"); |
121 | 0 | } |
122 | 0 | } |
123 | 0 | } |
124 | 0 | else if (rAction == "SIDEBAR") |
125 | 0 | { |
126 | 0 | SfxViewFrame* pViewFrm = SfxViewFrame::Current(); |
127 | 0 | assert(pViewFrm && "SwEditWinUIObject::execute: no viewframe"); |
128 | 0 | pViewFrm->ShowChildWindow(SID_SIDEBAR); |
129 | |
|
130 | 0 | if (rParameters.find(u"PANEL"_ustr) != rParameters.end()) |
131 | 0 | { |
132 | 0 | auto itr = rParameters.find(u"PANEL"_ustr); |
133 | 0 | OUString aVal = itr->second; |
134 | 0 | ::sfx2::sidebar::Sidebar::ShowPanel(aVal, pViewFrm->GetFrame().GetFrameInterface()); |
135 | 0 | } |
136 | 0 | } |
137 | 0 | else |
138 | 0 | WindowUIObject::execute(rAction, rParameters); |
139 | 0 | } |
140 | | |
141 | | OUString SwEditWinUIObject::get_name() const |
142 | 0 | { |
143 | 0 | return u"SwEditWinUIObject"_ustr; |
144 | 0 | } |
145 | | |
146 | | std::unique_ptr<UIObject> SwEditWinUIObject::create(vcl::Window* pWindow) |
147 | 0 | { |
148 | 0 | SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(pWindow); |
149 | 0 | assert(pEditWin); |
150 | 0 | return std::unique_ptr<UIObject>(new SwEditWinUIObject(pEditWin)); |
151 | 0 | } |
152 | | |
153 | | CommentUIObject::CommentUIObject(const VclPtr<sw::annotation::SwAnnotationWin>& xCommentUIObject): |
154 | 0 | WindowUIObject(xCommentUIObject), |
155 | 0 | mxCommentUIObject(xCommentUIObject) |
156 | 0 | { |
157 | 0 | } |
158 | | |
159 | | StringMap CommentUIObject::get_state() |
160 | 0 | { |
161 | 0 | StringMap aMap = WindowUIObject::get_state(); |
162 | 0 | aMap[u"Author"_ustr] = mxCommentUIObject->GetAuthor(); |
163 | 0 | aMap[u"ReadOnly"_ustr] = OUString::boolean(mxCommentUIObject->IsReadOnly()); |
164 | 0 | aMap[u"Resolved"_ustr] = OUString::boolean(mxCommentUIObject->IsResolved()); |
165 | 0 | aMap[u"Visible"_ustr] = OUString::boolean(mxCommentUIObject->IsVisible()); |
166 | |
|
167 | 0 | aMap[u"Text"_ustr] = mxCommentUIObject->GetOutliner()->GetEditEngine().GetText(); |
168 | 0 | aMap[u"SelectedText"_ustr] = mxCommentUIObject->GetOutlinerView()->GetEditView().GetSelected(); |
169 | 0 | return aMap; |
170 | 0 | } |
171 | | |
172 | | void CommentUIObject::execute(const OUString& rAction, |
173 | | const StringMap& rParameters) |
174 | 0 | { |
175 | 0 | if (rAction == "SELECT") |
176 | 0 | { |
177 | 0 | if (rParameters.find(u"FROM"_ustr) != rParameters.end() && |
178 | 0 | rParameters.find(u"TO"_ustr) != rParameters.end()) |
179 | 0 | { |
180 | 0 | tools::Long nMin = rParameters.find(u"FROM"_ustr)->second.toInt32(); |
181 | 0 | tools::Long nMax = rParameters.find(u"TO"_ustr)->second.toInt32(); |
182 | 0 | ESelection aNewSelection( 0 , nMin, mxCommentUIObject->GetOutliner()->GetParagraphCount()-1, nMax ); |
183 | 0 | mxCommentUIObject->GetOutlinerView()->SetSelection( aNewSelection ); |
184 | 0 | } |
185 | 0 | } |
186 | 0 | else if (rAction == "LEAVE") |
187 | 0 | { |
188 | 0 | mxCommentUIObject->SwitchToFieldPos(); |
189 | 0 | } |
190 | 0 | else if (rAction == "HIDE") |
191 | 0 | { |
192 | 0 | mxCommentUIObject->HideNote(); |
193 | 0 | } |
194 | 0 | else if (rAction == "SHOW") |
195 | 0 | { |
196 | 0 | mxCommentUIObject->ShowNote(); |
197 | 0 | } |
198 | 0 | else if (rAction == "DELETE") |
199 | 0 | { |
200 | 0 | mxCommentUIObject->Delete(); |
201 | 0 | } |
202 | 0 | else if (rAction == "RESOLVE") |
203 | 0 | { |
204 | 0 | mxCommentUIObject->SetResolved(true); |
205 | 0 | } |
206 | 0 | else |
207 | 0 | WindowUIObject::execute(rAction, rParameters); |
208 | 0 | } |
209 | | |
210 | | std::unique_ptr<UIObject> CommentUIObject::create(vcl::Window* pWindow) |
211 | 0 | { |
212 | 0 | sw::annotation::SwAnnotationWin* pCommentUIObject = dynamic_cast<sw::annotation::SwAnnotationWin*>(pWindow); |
213 | 0 | assert(pCommentUIObject); |
214 | 0 | return std::unique_ptr<UIObject>(new CommentUIObject(pCommentUIObject)); |
215 | 0 | } |
216 | | |
217 | | OUString CommentUIObject::get_name() const |
218 | 0 | { |
219 | 0 | return u"CommentUIObject"_ustr; |
220 | 0 | } |
221 | | |
222 | | PageBreakUIObject::PageBreakUIObject(const VclPtr<SwBreakDashedLine>& xPageBreakUIObject): |
223 | 0 | WindowUIObject(xPageBreakUIObject), |
224 | 0 | mxPageBreakUIObject(xPageBreakUIObject) |
225 | 0 | { |
226 | 0 | } |
227 | | |
228 | | void PageBreakUIObject::execute(const OUString& rAction, |
229 | | const StringMap& rParameters) |
230 | 0 | { |
231 | 0 | if (rAction == "DELETE" || rAction == "EDIT") |
232 | 0 | mxPageBreakUIObject->execute(rAction.toAsciiLowerCase()); |
233 | 0 | else |
234 | 0 | WindowUIObject::execute(rAction, rParameters); |
235 | 0 | } |
236 | | |
237 | | std::unique_ptr<UIObject> PageBreakUIObject::create(vcl::Window* pWindow) |
238 | 0 | { |
239 | 0 | SwBreakDashedLine* pPageBreakWin = dynamic_cast<SwBreakDashedLine*>(pWindow); |
240 | 0 | assert(pPageBreakWin); |
241 | 0 | return std::unique_ptr<UIObject>(new PageBreakUIObject(pPageBreakWin)); |
242 | 0 | } |
243 | | |
244 | | OUString PageBreakUIObject::get_name() const |
245 | 0 | { |
246 | 0 | return u"PageBreakUIObject"_ustr; |
247 | 0 | } |
248 | | |
249 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |