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 <sfx2/sidebar/Sidebar.hxx>
18 #include <sfx2/viewfrm.hxx>
19 
20 #include <AnnotationWin.hxx>
21 #include <comphelper/string.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 
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  sal_Int32 nStartPos = aStartPos.toInt32();
99 
100  itr = rParameters.find("END_POS");
101  assert(itr != rParameters.end());
102  OUString aEndPos = itr->second;
103  sal_Int32 nEndPos = aEndPos.toInt32();
104 
105  auto & shell = getWrtShell(mxEditWin);
106  sal_Int32 len;
107  if (auto const text = shell.GetCursor_()->GetPoint()->nNode.GetNode().GetTextNode()) {
108  len = text->GetText().getLength();
109  } else {
110  len = 0;
111  }
112  SAL_WARN_IF(
113  nStartPos < 0 || nStartPos > len || nEndPos < 0 || nEndPos > len, "sw.ui",
114  "SELECT START/END_POS " << nStartPos << ".." << nEndPos << " outside 0.." << len);
115  shell.SelectText(
116  std::clamp(nStartPos, sal_Int32(0), len), std::clamp(nEndPos, sal_Int32(0), len));
117  }
118  }
119  else if (rAction == "SIDEBAR")
120  {
121  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
122  DBG_ASSERT(pViewFrm, "SwEditWinUIObject::execute: no viewframe");
123  pViewFrm->ShowChildWindow(SID_SIDEBAR);
124 
125  if (rParameters.find("PANEL") != rParameters.end())
126  {
127  auto itr = rParameters.find("PANEL");
128  OUString aVal = itr->second;
130  }
131  }
132  else
133  WindowUIObject::execute(rAction, rParameters);
134 }
135 
137 {
138  return "SwEditWinUIObject";
139 }
140 
141 std::unique_ptr<UIObject> SwEditWinUIObject::create(vcl::Window* pWindow)
142 {
143  SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(pWindow);
144  assert(pEditWin);
145  return std::unique_ptr<UIObject>(new SwEditWinUIObject(pEditWin));
146 }
147 
149  WindowUIObject(xSwNavigationPI),
150  mxSwNavigationPI(xSwNavigationPI)
151 {
152 }
153 
155 {
157 
158  aMap["selectioncount"] = OUString::number(mxSwNavigationPI->m_xContentTree->count_selected_rows());
159  aMap["selectedtext"] = mxSwNavigationPI->m_xContentTree->get_selected_text();
160 
161  return aMap;
162 }
163 
164 void SwNavigationPIUIObject::execute(const OUString& rAction,
165  const StringMap& rParameters)
166 {
167  if (rAction == "ROOT")
168  {
169  mxSwNavigationPI->m_xContentTree->grab_focus();
170  mxSwNavigationPI->ToolBoxSelectHdl("root");
171  }
172  else
173  WindowUIObject::execute(rAction, rParameters);
174 }
175 
176 std::unique_ptr<UIObject> SwNavigationPIUIObject::create(vcl::Window* pWindow)
177 {
178  SwNavigationPI* pSwNavigationPI = dynamic_cast<SwNavigationPI*>(pWindow);
179  assert(pSwNavigationPI);
180  return std::unique_ptr<UIObject>(new SwNavigationPIUIObject(pSwNavigationPI));
181 }
182 
184 {
185  return "SwNavigationPIUIObject";
186 }
187 
189  WindowUIObject(xCommentUIObject),
190  mxCommentUIObject(xCommentUIObject)
191 {
192 }
193 
195 {
197  aMap["Author"] = mxCommentUIObject->GetAuthor();
198  aMap["ReadOnly"] = OUString::boolean(mxCommentUIObject->IsReadOnly());
199  aMap["Resolved"] = OUString::boolean(mxCommentUIObject->IsResolved());
200  aMap["Visible"] = OUString::boolean(mxCommentUIObject->IsVisible());
201 
202  aMap["Text"] = mxCommentUIObject->GetOutliner()->GetEditEngine().GetText();
203  aMap["SelectedText"] = mxCommentUIObject->GetOutlinerView()->GetEditView().GetSelected();
204  return aMap;
205 }
206 
207 void CommentUIObject::execute(const OUString& rAction,
208  const StringMap& rParameters)
209 {
210  if (rAction == "SELECT")
211  {
212  if (rParameters.find("FROM") != rParameters.end() &&
213  rParameters.find("TO") != rParameters.end())
214  {
215  tools::Long nMin = rParameters.find("FROM")->second.toInt32();
216  tools::Long nMax = rParameters.find("TO")->second.toInt32();
219  }
220  }
221  else if (rAction == "LEAVE")
222  {
224  }
225  else if (rAction == "HIDE")
226  {
228  }
229  else if (rAction == "SHOW")
230  {
232  }
233  else if (rAction == "DELETE")
234  {
236  }
237  else if (rAction == "RESOLVE")
238  {
240  }
241  else
242  WindowUIObject::execute(rAction, rParameters);
243 }
244 
245 std::unique_ptr<UIObject> CommentUIObject::create(vcl::Window* pWindow)
246 {
247  sw::annotation::SwAnnotationWin* pCommentUIObject = dynamic_cast<sw::annotation::SwAnnotationWin*>(pWindow);
248  assert(pCommentUIObject);
249  return std::unique_ptr<UIObject>(new CommentUIObject(pCommentUIObject));
250 }
251 
253 {
254  return "CommentUIObject";
255 }
256 
257 
258 
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString GetText(LineEnd eEnd=LINEEND_LF) const
virtual OUString get_name() const override
Definition: uiobject.cxx:136
bool IsSttPara() const
Definition: crsrsh.cxx:1094
const SwView & GetView() const
Definition: edtwin.hxx:244
bool IsStartOfDoc() const
Definition: crsrsh.cxx:2738
long Long
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:188
void GetPageNum(sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum, bool bAtCursorPos=true, const bool bCalcFrame=true)
Definition: crsrsh.cxx:1208
OUString get_name() const override
Definition: uiobject.cxx:252
sal_Int32 GetParagraphCount() const
SwWrtShell & GetWrtShell() const
Definition: view.hxx:399
bool IsStartSentence() const
Definition: crstrvl1.cxx:41
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
HashMap_OWString_Interface aMap
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
ESelection aNewSelection(GetSelection())
virtual StringMap get_state() override
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
SfxFrame & GetFrame() const
VclPtr< SwEditWin > mxEditWin
Definition: uiobject.hxx:40
SwEditWinUIObject(const VclPtr< SwEditWin > &xEditWin)
Definition: uiobject.cxx:25
std::unique_ptr< SwContentTree > m_xContentTree
Definition: navipi.hxx:73
EditView & GetEditView() const
virtual OUString GetSelectionText(bool bCompleteWords=false) override
Definition: view.cxx:1589
virtual StringMap get_state() override
Definition: uiobject.cxx:154
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:176
exports com.sun.star. text
#define DBG_ASSERT(sCon, aError)
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:207
sal_uInt16 GetPageCnt()
Definition: crsrsh.cxx:1290
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:245
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:141
virtual StringMap get_state() override
Definition: uiobject.cxx:40
std::map< const OUString, OUString > StringMap
static void ShowPanel(const OUString &rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
bool IsEndSentence() const
Definition: crstrvl1.cxx:45
const EditEngine & GetEditEngine() const
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
bool IsStartWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES) const
Definition: crstrvl1.cxx:27
SwNavigationPIUIObject(const VclPtr< SwNavigationPI > &xSwNavigationPI)
Definition: uiobject.cxx:148
void SetZoom(SvxZoomType eZoomType, short nFactor=100, bool bViewOnly=false)
Definition: viewmdi.cxx:72
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:164
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)
bool IsVisible() const
VclPtr< sw::annotation::SwAnnotationWin > mxCommentUIObject
Definition: uiobject.hxx:67
void ShowChildWindow(sal_uInt16, bool bVisible=true)
bool IsEndOfDoc() const
Definition: crsrsh.cxx:2750
virtual StringMap get_state() override
Definition: uiobject.cxx:194
bool IsEndPara() const
Definition: crsrsh.cxx:1113
OUString GetSelected() const
VclPtr< SwNavigationPI > mxSwNavigationPI
Definition: uiobject.hxx:46
OUString get_name() const override
Definition: uiobject.cxx:183