LibreOffice Module sw (master)  1
uiobject.cxx
Go to the documentation of this file.
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 
25  WindowUIObject(xEditWin),
26  mxEditWin(xEditWin)
27 {
28 }
29 
30 namespace {
31 
32 SwWrtShell& getWrtShell(VclPtr<SwEditWin> const & xEditWin)
33 {
34  return xEditWin->GetView().GetWrtShell();
35 }
36 
37 }
38 
40 {
42 
43  aMap["SelectedText"] = mxEditWin->GetView().GetSelectionText();
44 
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());
53 
54  sal_uInt16 nPages = rWrtShell.GetPageCnt();
55  aMap["Pages"] = OUString::number(nPages);
56 
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());
65 
66  return aMap;
67 }
68 
69 void SwEditWinUIObject::execute(const OUString& rAction,
70  const StringMap& rParameters)
71 {
72  if (rAction == "SET")
73  {
74  if (rParameters.find("ZOOM") != rParameters.end())
75  {
76  auto itr = rParameters.find("ZOOM");
77  OUString aVal = itr->second;
78  sal_Int32 nVal = aVal.toInt32();
79  mxEditWin->GetView().SetZoom(SvxZoomType::PERCENT, nVal);
80  }
81  }
82  else if (rAction == "GOTO")
83  {
84  if (rParameters.find("PAGE") != rParameters.end())
85  {
86  auto itr = rParameters.find("PAGE");
87  OUString aVal = itr->second;
88  sal_Int32 nVal = aVal.toInt32();
89  getWrtShell(mxEditWin).GotoPage(nVal, false);
90  }
91  }
92  else if (rAction == "SELECT")
93  {
94  if (rParameters.find("START_POS") != rParameters.end())
95  {
96  auto itr = rParameters.find("START_POS");
97  OUString aStartPos = itr->second;
98  TextFrameIndex const nStartPos(aStartPos.toInt32());
99 
100  itr = rParameters.find("END_POS");
101  assert(itr != rParameters.end());
102  OUString aEndPos = itr->second;
103  TextFrameIndex const nEndPos(aEndPos.toInt32());
104 
105  auto & shell = getWrtShell(mxEditWin);
106  if (shell.GetCursor_()->GetPoint()->nNode.GetNode().GetTextNode())
107  {
108  shell.Push();
109  shell.MovePara(GoCurrPara, fnParaEnd);
110  TextFrameIndex const len(shell.GetCursorPointAsViewIndex());
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));
117  }
118  else
119  {
120  SAL_WARN("sw.ui", "SELECT without SwTextNode");
121  }
122  }
123  }
124  else if (rAction == "SIDEBAR")
125  {
126  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
127  DBG_ASSERT(pViewFrm, "SwEditWinUIObject::execute: no viewframe");
128  pViewFrm->ShowChildWindow(SID_SIDEBAR);
129 
130  if (rParameters.find("PANEL") != rParameters.end())
131  {
132  auto itr = rParameters.find("PANEL");
133  OUString aVal = itr->second;
135  }
136  }
137  else
138  WindowUIObject::execute(rAction, rParameters);
139 }
140 
142 {
143  return "SwEditWinUIObject";
144 }
145 
146 std::unique_ptr<UIObject> SwEditWinUIObject::create(vcl::Window* pWindow)
147 {
148  SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(pWindow);
149  assert(pEditWin);
150  return std::unique_ptr<UIObject>(new SwEditWinUIObject(pEditWin));
151 }
152 
154  WindowUIObject(xCommentUIObject),
155  mxCommentUIObject(xCommentUIObject)
156 {
157 }
158 
160 {
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());
166 
167  aMap["Text"] = mxCommentUIObject->GetOutliner()->GetEditEngine().GetText();
168  aMap["SelectedText"] = mxCommentUIObject->GetOutlinerView()->GetEditView().GetSelected();
169  return aMap;
170 }
171 
172 void CommentUIObject::execute(const OUString& rAction,
173  const StringMap& rParameters)
174 {
175  if (rAction == "SELECT")
176  {
177  if (rParameters.find("FROM") != rParameters.end() &&
178  rParameters.find("TO") != rParameters.end())
179  {
180  tools::Long nMin = rParameters.find("FROM")->second.toInt32();
181  tools::Long nMax = rParameters.find("TO")->second.toInt32();
184  }
185  }
186  else if (rAction == "LEAVE")
187  {
189  }
190  else if (rAction == "HIDE")
191  {
193  }
194  else if (rAction == "SHOW")
195  {
197  }
198  else if (rAction == "DELETE")
199  {
201  }
202  else if (rAction == "RESOLVE")
203  {
205  }
206  else
207  WindowUIObject::execute(rAction, rParameters);
208 }
209 
210 std::unique_ptr<UIObject> CommentUIObject::create(vcl::Window* pWindow)
211 {
212  sw::annotation::SwAnnotationWin* pCommentUIObject = dynamic_cast<sw::annotation::SwAnnotationWin*>(pWindow);
213  assert(pCommentUIObject);
214  return std::unique_ptr<UIObject>(new CommentUIObject(pCommentUIObject));
215 }
216 
218 {
219  return "CommentUIObject";
220 }
221 
223  WindowUIObject(xPageBreakUIObject),
224  mxPageBreakUIObject(xPageBreakUIObject)
225 {
226 }
227 
228 void PageBreakUIObject::execute(const OUString& rAction,
229  const StringMap& rParameters)
230 {
231  if (rAction == "DELETE" || rAction == "EDIT")
232  mxPageBreakUIObject->execute(rAction.toAsciiLowerCase().toUtf8());
233  else
234  WindowUIObject::execute(rAction, rParameters);
235 }
236 
237 std::unique_ptr<UIObject> PageBreakUIObject::create(vcl::Window* pWindow)
238 {
239  SwPageBreakWin* pPageBreakWin = dynamic_cast<SwPageBreakWin*>(pWindow);
240  assert(pPageBreakWin);
241  return std::unique_ptr<UIObject>(new PageBreakUIObject(pPageBreakWin));
242 }
243 
245 {
246  return "PageBreakUIObject";
247 }
248 
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void ShowPanel(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
OUString GetText(LineEnd eEnd=LINEEND_LF) const
SwMoveFnCollection const & fnParaEnd
Definition: paminit.cxx:47
virtual OUString get_name() const override
Definition: uiobject.cxx:141
bool GoCurrPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
Definition: pam.cxx:1014
bool IsSttPara() const
Definition: crsrsh.cxx:1095
const SwView & GetView() const
Definition: edtwin.hxx:245
bool IsStartOfDoc() const
Definition: crsrsh.cxx:2760
long Long
PageBreakUIObject(const VclPtr< SwPageBreakWin > &xEditWin)
Definition: uiobject.cxx:222
bool IsEndWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES) const
Definition: crstrvl1.cxx:31
CommentUIObject(const VclPtr< sw::annotation::SwAnnotationWin > &xCommentUIObject)
Definition: uiobject.cxx:153
void GetPageNum(sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum, bool bAtCursorPos=true, const bool bCalcFrame=true)
Definition: crsrsh.cxx:1209
OUString get_name() const override
Definition: uiobject.cxx:217
sal_Int32 GetParagraphCount() const
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
bool IsStartSentence() const
Definition: crstrvl1.cxx:41
Used by the UI to modify the document model.
Definition: wrtsh.hxx:96
HashMap_OWString_Interface aMap
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
ESelection aNewSelection(GetSelection())
virtual StringMap get_state() override
Class for the page break control window.
SfxFrame & GetFrame() const
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:228
VclPtr< SwEditWin > mxEditWin
Definition: uiobject.hxx:38
SwEditWinUIObject(const VclPtr< SwEditWin > &xEditWin)
Definition: uiobject.cxx:24
EditView & GetEditView() const
virtual OUString GetSelectionText(bool bCompleteWords=false) override
Definition: view.cxx:1649
#define DBG_ASSERT(sCon, aError)
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:172
sal_uInt16 GetPageCnt()
Definition: crsrsh.cxx:1291
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:210
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:59
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:146
virtual StringMap get_state() override
Definition: uiobject.cxx:39
void execute(std::string_view rIdent)
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:237
bool IsEndSentence() const
Definition: crstrvl1.cxx:45
const EditEngine & GetEditEngine() const
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
VclPtr< SwPageBreakWin > mxPageBreakUIObject
Definition: uiobject.hxx:79
bool IsStartWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES) const
Definition: crstrvl1.cxx:27
void SetZoom(SvxZoomType eZoomType, short nFactor=100, bool bViewOnly=false)
Definition: viewmdi.cxx:72
void SetSelection(const ESelection &)
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:69
static SfxViewFrame * Current()
#define SAL_WARN_IF(condition, area, stream)
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:428
bool IsVisible() const
std::map< OUString, OUString > StringMap
sal_uInt16 GetZoom() const
Definition: viewopt.hxx:505
VclPtr< sw::annotation::SwAnnotationWin > mxCommentUIObject
Definition: uiobject.hxx:45
void ShowChildWindow(sal_uInt16, bool bVisible=true)
bool IsEndOfDoc() const
Definition: crsrsh.cxx:2772
virtual StringMap get_state() override
Definition: uiobject.cxx:159
#define SAL_WARN(area, stream)
bool IsEndPara() const
Definition: crsrsh.cxx:1114
OUString GetSelected() const
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
virtual OUString get_name() const override
Definition: uiobject.cxx:244