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 <navipi.hxx>
16 #include <ndtxt.hxx>
17 #include <viewopt.hxx>
18 #include <sfx2/sidebar/Sidebar.hxx>
19 #include <sfx2/viewfrm.hxx>
20 
21 #include <AnnotationWin.hxx>
22 #include <editeng/editeng.hxx>
23 #include <editeng/editview.hxx>
24 
26  WindowUIObject(xEditWin),
27  mxEditWin(xEditWin)
28 {
29 }
30 
31 namespace {
32 
33 SwWrtShell& getWrtShell(VclPtr<SwEditWin> const & xEditWin)
34 {
35  return xEditWin->GetView().GetWrtShell();
36 }
37 
38 }
39 
41 {
43 
44  aMap["SelectedText"] = mxEditWin->GetView().GetSelectionText();
45 
46  sal_uInt16 nPageNum = 0;
47  sal_uInt16 nVirtPageNum = 0;
48  SwWrtShell& rWrtShell = getWrtShell(mxEditWin);
49  rWrtShell.GetPageNum(nPageNum, nVirtPageNum);
50  aMap["CurrentPage"] = OUString::number(nPageNum);
51  rWrtShell.GetPageNum(nPageNum, nVirtPageNum, false);
52  aMap["TopVisiblePage"] = OUString::number(nPageNum);
53  aMap["Zoom"] = OUString::number(rWrtShell.GetViewOptions()->GetZoom());
54 
55  sal_uInt16 nPages = rWrtShell.GetPageCnt();
56  aMap["Pages"] = OUString::number(nPages);
57 
58  aMap["StartWord"] = OUString::boolean(rWrtShell.IsStartWord());
59  aMap["EndWord"] = OUString::boolean(rWrtShell.IsEndWord());
60  aMap["StartSentence"] = OUString::boolean(rWrtShell.IsStartSentence());
61  aMap["EndSentence"] = OUString::boolean(rWrtShell.IsEndSentence());
62  aMap["StartPara"] = OUString::boolean(rWrtShell.IsSttPara());
63  aMap["EndPara"] = OUString::boolean(rWrtShell.IsEndPara());
64  aMap["StartDoc"] = OUString::boolean(rWrtShell.IsStartOfDoc());
65  aMap["EndDoc"] = OUString::boolean(rWrtShell.IsEndOfDoc());
66 
67  return aMap;
68 }
69 
70 void SwEditWinUIObject::execute(const OUString& rAction,
71  const StringMap& rParameters)
72 {
73  if (rAction == "SET")
74  {
75  if (rParameters.find("ZOOM") != rParameters.end())
76  {
77  auto itr = rParameters.find("ZOOM");
78  OUString aVal = itr->second;
79  sal_Int32 nVal = aVal.toInt32();
80  mxEditWin->GetView().SetZoom(SvxZoomType::PERCENT, nVal);
81  }
82  }
83  else if (rAction == "GOTO")
84  {
85  if (rParameters.find("PAGE") != rParameters.end())
86  {
87  auto itr = rParameters.find("PAGE");
88  OUString aVal = itr->second;
89  sal_Int32 nVal = aVal.toInt32();
90  getWrtShell(mxEditWin).GotoPage(nVal, false);
91  }
92  }
93  else if (rAction == "SELECT")
94  {
95  if (rParameters.find("START_POS") != rParameters.end())
96  {
97  auto itr = rParameters.find("START_POS");
98  OUString aStartPos = itr->second;
99  sal_Int32 nStartPos = aStartPos.toInt32();
100 
101  itr = rParameters.find("END_POS");
102  assert(itr != rParameters.end());
103  OUString aEndPos = itr->second;
104  sal_Int32 nEndPos = aEndPos.toInt32();
105 
106  auto & shell = getWrtShell(mxEditWin);
107  sal_Int32 len;
108  if (auto const text = shell.GetCursor_()->GetPoint()->nNode.GetNode().GetTextNode()) {
109  len = text->GetText().getLength();
110  } else {
111  len = 0;
112  }
113  SAL_WARN_IF(
114  nStartPos < 0 || nStartPos > len || nEndPos < 0 || nEndPos > len, "sw.ui",
115  "SELECT START/END_POS " << nStartPos << ".." << nEndPos << " outside 0.." << len);
116  shell.SelectText(
117  std::clamp(nStartPos, sal_Int32(0), len), std::clamp(nEndPos, sal_Int32(0), len));
118  }
119  }
120  else if (rAction == "SIDEBAR")
121  {
122  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
123  DBG_ASSERT(pViewFrm, "SwEditWinUIObject::execute: no viewframe");
124  pViewFrm->ShowChildWindow(SID_SIDEBAR);
125 
126  if (rParameters.find("PANEL") != rParameters.end())
127  {
128  auto itr = rParameters.find("PANEL");
129  OUString aVal = itr->second;
131  }
132  }
133  else
134  WindowUIObject::execute(rAction, rParameters);
135 }
136 
138 {
139  return "SwEditWinUIObject";
140 }
141 
142 std::unique_ptr<UIObject> SwEditWinUIObject::create(vcl::Window* pWindow)
143 {
144  SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(pWindow);
145  assert(pEditWin);
146  return std::unique_ptr<UIObject>(new SwEditWinUIObject(pEditWin));
147 }
148 
150  WindowUIObject(xCommentUIObject),
151  mxCommentUIObject(xCommentUIObject)
152 {
153 }
154 
156 {
158  aMap["Author"] = mxCommentUIObject->GetAuthor();
159  aMap["ReadOnly"] = OUString::boolean(mxCommentUIObject->IsReadOnly());
160  aMap["Resolved"] = OUString::boolean(mxCommentUIObject->IsResolved());
161  aMap["Visible"] = OUString::boolean(mxCommentUIObject->IsVisible());
162 
163  aMap["Text"] = mxCommentUIObject->GetOutliner()->GetEditEngine().GetText();
164  aMap["SelectedText"] = mxCommentUIObject->GetOutlinerView()->GetEditView().GetSelected();
165  return aMap;
166 }
167 
168 void CommentUIObject::execute(const OUString& rAction,
169  const StringMap& rParameters)
170 {
171  if (rAction == "SELECT")
172  {
173  if (rParameters.find("FROM") != rParameters.end() &&
174  rParameters.find("TO") != rParameters.end())
175  {
176  tools::Long nMin = rParameters.find("FROM")->second.toInt32();
177  tools::Long nMax = rParameters.find("TO")->second.toInt32();
180  }
181  }
182  else if (rAction == "LEAVE")
183  {
185  }
186  else if (rAction == "HIDE")
187  {
189  }
190  else if (rAction == "SHOW")
191  {
193  }
194  else if (rAction == "DELETE")
195  {
197  }
198  else if (rAction == "RESOLVE")
199  {
201  }
202  else
203  WindowUIObject::execute(rAction, rParameters);
204 }
205 
206 std::unique_ptr<UIObject> CommentUIObject::create(vcl::Window* pWindow)
207 {
208  sw::annotation::SwAnnotationWin* pCommentUIObject = dynamic_cast<sw::annotation::SwAnnotationWin*>(pWindow);
209  assert(pCommentUIObject);
210  return std::unique_ptr<UIObject>(new CommentUIObject(pCommentUIObject));
211 }
212 
214 {
215  return "CommentUIObject";
216 }
217 
219  WindowUIObject(xPageBreakUIObject),
220  mxPageBreakUIObject(xPageBreakUIObject)
221 {
222 }
223 
224 void PageBreakUIObject::execute(const OUString& rAction,
225  const StringMap& rParameters)
226 {
227  if (rAction == "DELETE" || rAction == "EDIT")
228  mxPageBreakUIObject->execute(rAction.toAsciiLowerCase().toUtf8());
229  else
230  WindowUIObject::execute(rAction, rParameters);
231 }
232 
233 std::unique_ptr<UIObject> PageBreakUIObject::create(vcl::Window* pWindow)
234 {
235  SwPageBreakWin* pPageBreakWin = dynamic_cast<SwPageBreakWin*>(pWindow);
236  assert(pPageBreakWin);
237  return std::unique_ptr<UIObject>(new PageBreakUIObject(pPageBreakWin));
238 }
239 
241 {
242  return "PageBreakUIObject";
243 }
244 
245 /* 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
virtual OUString get_name() const override
Definition: uiobject.cxx:137
bool IsSttPara() const
Definition: crsrsh.cxx:1095
const SwView & GetView() const
Definition: edtwin.hxx:244
bool IsStartOfDoc() const
Definition: crsrsh.cxx:2750
long Long
PageBreakUIObject(const VclPtr< SwPageBreakWin > &xEditWin)
Definition: uiobject.cxx:218
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:149
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:213
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:93
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:224
VclPtr< SwEditWin > mxEditWin
Definition: uiobject.hxx:39
SwEditWinUIObject(const VclPtr< SwEditWin > &xEditWin)
Definition: uiobject.cxx:25
EditView & GetEditView() const
virtual OUString GetSelectionText(bool bCompleteWords=false) override
Definition: view.cxx:1619
exports com.sun.star. text
#define DBG_ASSERT(sCon, aError)
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:168
sal_uInt16 GetPageCnt()
Definition: crsrsh.cxx:1291
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:206
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:142
virtual StringMap get_state() override
Definition: uiobject.cxx:40
void execute(std::string_view rIdent)
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:233
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:80
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:70
static SfxViewFrame * Current()
#define SAL_WARN_IF(condition, area, stream)
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:423
bool IsVisible() const
std::map< OUString, OUString > StringMap
sal_uInt16 GetZoom() const
Definition: viewopt.hxx:505
VclPtr< sw::annotation::SwAnnotationWin > mxCommentUIObject
Definition: uiobject.hxx:46
void ShowChildWindow(sal_uInt16, bool bVisible=true)
bool IsEndOfDoc() const
Definition: crsrsh.cxx:2762
virtual StringMap get_state() override
Definition: uiobject.cxx:155
bool IsEndPara() const
Definition: crsrsh.cxx:1114
OUString GetSelected() const
virtual OUString get_name() const override
Definition: uiobject.cxx:240