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 <sfx2/sidebar/Sidebar.hxx>
17 #include <sfx2/viewfrm.hxx>
18 
19 #include <AnnotationWin.hxx>
20 #include <comphelper/string.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 
53  sal_uInt16 nPages = rWrtShell.GetPageCnt();
54  aMap["Pages"] = OUString::number(nPages);
55 
56  aMap["StartWord"] = OUString::boolean(rWrtShell.IsStartWord());
57  aMap["EndWord"] = OUString::boolean(rWrtShell.IsEndWord());
58  aMap["StartSentence"] = OUString::boolean(rWrtShell.IsStartSentence());
59  aMap["EndSentence"] = OUString::boolean(rWrtShell.IsEndSentence());
60  aMap["StartPara"] = OUString::boolean(rWrtShell.IsSttPara());
61  aMap["EndPara"] = OUString::boolean(rWrtShell.IsEndPara());
62  aMap["StartDoc"] = OUString::boolean(rWrtShell.IsStartOfDoc());
63  aMap["EndDoc"] = OUString::boolean(rWrtShell.IsEndOfDoc());
64 
65  return aMap;
66 }
67 
68 void SwEditWinUIObject::execute(const OUString& rAction,
69  const StringMap& rParameters)
70 {
71  if (rAction == "SET")
72  {
73  if (rParameters.find("ZOOM") != rParameters.end())
74  {
75  auto itr = rParameters.find("ZOOM");
76  OUString aVal = itr->second;
77  sal_Int32 nVal = aVal.toInt32();
78  mxEditWin->GetView().SetZoom(SvxZoomType::PERCENT, nVal);
79  }
80  }
81  else if (rAction == "GOTO")
82  {
83  if (rParameters.find("PAGE") != rParameters.end())
84  {
85  auto itr = rParameters.find("PAGE");
86  OUString aVal = itr->second;
87  sal_Int32 nVal = aVal.toInt32();
88  getWrtShell(mxEditWin).GotoPage(nVal, false);
89  }
90  }
91  else if (rAction == "SELECT")
92  {
93  if (rParameters.find("START_POS") != rParameters.end())
94  {
95  auto itr = rParameters.find("START_POS");
96  OUString aStartPos = itr->second;
97  sal_Int32 nStartPos = aStartPos.toInt32();
98 
99  itr = rParameters.find("END_POS");
100  assert(itr != rParameters.end());
101  OUString aEndPos = itr->second;
102  sal_Int32 nEndPos = aEndPos.toInt32();
103 
104  getWrtShell(mxEditWin).SelectText(nStartPos, nEndPos);
105  }
106  }
107  else if (rAction == "SIDEBAR")
108  {
109  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
110  DBG_ASSERT(pViewFrm, "SwEditWinUIObject::execute: no viewframe");
111  pViewFrm->ShowChildWindow(SID_SIDEBAR);
112 
113  if (rParameters.find("PANEL") != rParameters.end())
114  {
115  auto itr = rParameters.find("PANEL");
116  OUString aVal = itr->second;
118  }
119  }
120  else
121  WindowUIObject::execute(rAction, rParameters);
122 }
123 
125 {
126  return "SwEditWinUIObject";
127 }
128 
129 std::unique_ptr<UIObject> SwEditWinUIObject::create(vcl::Window* pWindow)
130 {
131  SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(pWindow);
132  assert(pEditWin);
133  return std::unique_ptr<UIObject>(new SwEditWinUIObject(pEditWin));
134 }
135 
137  WindowUIObject(xSwNavigationPI),
138  mxSwNavigationPI(xSwNavigationPI)
139 {
140 }
141 
143 {
145 
146  aMap["selectioncount"] = OUString::number(mxSwNavigationPI->m_xContentTree->count_selected_rows());
147  aMap["selectedtext"] = mxSwNavigationPI->m_xContentTree->get_selected_text();
148 
149  return aMap;
150 }
151 
152 void SwNavigationPIUIObject::execute(const OUString& rAction,
153  const StringMap& rParameters)
154 {
155  if (rAction == "ROOT")
156  {
157  mxSwNavigationPI->m_xContentTree->grab_focus();
158  mxSwNavigationPI->ToolBoxSelectHdl("root");
159  }
160  else
161  WindowUIObject::execute(rAction, rParameters);
162 }
163 
164 std::unique_ptr<UIObject> SwNavigationPIUIObject::create(vcl::Window* pWindow)
165 {
166  SwNavigationPI* pSwNavigationPI = dynamic_cast<SwNavigationPI*>(pWindow);
167  assert(pSwNavigationPI);
168  return std::unique_ptr<UIObject>(new SwNavigationPIUIObject(pSwNavigationPI));
169 }
170 
172 {
173  return "SwNavigationPIUIObject";
174 }
175 
177  WindowUIObject(xCommentUIObject),
178  mxCommentUIObject(xCommentUIObject)
179 {
180 }
181 
183 {
185  aMap["Author"] = mxCommentUIObject->GetAuthor();
186  aMap["ReadOnly"] = OUString::boolean(mxCommentUIObject->IsReadOnly());
187  aMap["Resolved"] = OUString::boolean(mxCommentUIObject->IsResolved());
188  aMap["Visible"] = OUString::boolean(mxCommentUIObject->IsVisible());
189 
190  aMap["Text"] = mxCommentUIObject->GetOutliner()->GetEditEngine().GetText();
191  aMap["SelectedText"] = mxCommentUIObject->GetOutlinerView()->GetEditView().GetSelected();
192  return aMap;
193 }
194 
195 void CommentUIObject::execute(const OUString& rAction,
196  const StringMap& rParameters)
197 {
198  if (rAction == "SELECT")
199  {
200  if (rParameters.find("FROM") != rParameters.end() &&
201  rParameters.find("TO") != rParameters.end())
202  {
203  long nMin = rParameters.find("FROM")->second.toInt32();
204  long nMax = rParameters.find("TO")->second.toInt32();
207  }
208  }
209  else if (rAction == "LEAVE")
210  {
212  }
213  else if (rAction == "HIDE")
214  {
216  }
217  else if (rAction == "SHOW")
218  {
220  }
221  else if (rAction == "DELETE")
222  {
224  }
225  else if (rAction == "RESOLVE")
226  {
228  }
229  else
230  WindowUIObject::execute(rAction, rParameters);
231 }
232 
233 std::unique_ptr<UIObject> CommentUIObject::create(vcl::Window* pWindow)
234 {
235  sw::annotation::SwAnnotationWin* pCommentUIObject = dynamic_cast<sw::annotation::SwAnnotationWin*>(pWindow);
236  assert(pCommentUIObject);
237  return std::unique_ptr<UIObject>(new CommentUIObject(pCommentUIObject));
238 }
239 
241 {
242  return "CommentUIObject";
243 }
244 
245 
246 
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString GetText(LineEnd eEnd=LINEEND_LF) const
virtual OUString get_name() const override
Definition: uiobject.cxx:124
bool IsSttPara() const
Definition: crsrsh.cxx:1094
const SwView & GetView() const
Definition: edtwin.hxx:241
bool IsStartOfDoc() const
Definition: crsrsh.cxx:2734
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:176
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:240
sal_Int32 GetParagraphCount() const
SwWrtShell & GetWrtShell() const
Definition: view.hxx:398
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:24
std::unique_ptr< SwContentTree > m_xContentTree
Definition: navipi.hxx:70
EditView & GetEditView() const
virtual OUString GetSelectionText(bool bCompleteWords=false) override
Definition: view.cxx:1587
virtual StringMap get_state() override
Definition: uiobject.cxx:142
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:164
#define DBG_ASSERT(sCon, aError)
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:195
sal_uInt16 GetPageCnt()
Definition: crsrsh.cxx:1290
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:233
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:129
virtual StringMap get_state() override
Definition: uiobject.cxx:39
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:136
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:152
void SetSelection(const ESelection &)
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:68
static SfxViewFrame * Current()
bool IsVisible() const
std::map< OUString, OUString > StringMap
VclPtr< sw::annotation::SwAnnotationWin > mxCommentUIObject
Definition: uiobject.hxx:67
void ShowChildWindow(sal_uInt16, bool bVisible=true)
bool IsEndOfDoc() const
Definition: crsrsh.cxx:2746
virtual StringMap get_state() override
Definition: uiobject.cxx:182
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:171