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 
20  WindowUIObject(xEditWin),
21  mxEditWin(xEditWin)
22 {
23 }
24 
25 namespace {
26 
27 SwWrtShell& getWrtShell(VclPtr<SwEditWin> const & xEditWin)
28 {
29  return xEditWin->GetView().GetWrtShell();
30 }
31 
32 }
33 
35 {
37 
38  aMap["SelectedText"] = mxEditWin->GetView().GetSelectionText();
39 
40  sal_uInt16 nPageNum = 0;
41  sal_uInt16 nVirtPageNum = 0;
42  SwWrtShell& rWrtShell = getWrtShell(mxEditWin);
43  rWrtShell.GetPageNum(nPageNum, nVirtPageNum);
44  aMap["CurrentPage"] = OUString::number(nPageNum);
45  rWrtShell.GetPageNum(nPageNum, nVirtPageNum, false);
46  aMap["TopVisiblePage"] = OUString::number(nPageNum);
47 
48  sal_uInt16 nPages = rWrtShell.GetPageCnt();
49  aMap["Pages"] = OUString::number(nPages);
50 
51  aMap["StartWord"] = OUString::boolean(rWrtShell.IsStartWord());
52  aMap["EndWord"] = OUString::boolean(rWrtShell.IsEndWord());
53  aMap["StartSentence"] = OUString::boolean(rWrtShell.IsStartSentence());
54  aMap["EndSentence"] = OUString::boolean(rWrtShell.IsEndSentence());
55  aMap["StartPara"] = OUString::boolean(rWrtShell.IsSttPara());
56  aMap["EndPara"] = OUString::boolean(rWrtShell.IsEndPara());
57  aMap["StartDoc"] = OUString::boolean(rWrtShell.IsStartOfDoc());
58  aMap["EndDoc"] = OUString::boolean(rWrtShell.IsEndOfDoc());
59 
60  return aMap;
61 }
62 
63 void SwEditWinUIObject::execute(const OUString& rAction,
64  const StringMap& rParameters)
65 {
66  if (rAction == "SET")
67  {
68  if (rParameters.find("ZOOM") != rParameters.end())
69  {
70  auto itr = rParameters.find("ZOOM");
71  OUString aVal = itr->second;
72  sal_Int32 nVal = aVal.toInt32();
73  mxEditWin->GetView().SetZoom(SvxZoomType::PERCENT, nVal);
74  }
75  }
76  else if (rAction == "GOTO")
77  {
78  if (rParameters.find("PAGE") != rParameters.end())
79  {
80  auto itr = rParameters.find("PAGE");
81  OUString aVal = itr->second;
82  sal_Int32 nVal = aVal.toInt32();
83  getWrtShell(mxEditWin).GotoPage(nVal, false);
84  }
85  }
86  else if (rAction == "SELECT")
87  {
88  if (rParameters.find("START_POS") != rParameters.end())
89  {
90  auto itr = rParameters.find("START_POS");
91  OUString aStartPos = itr->second;
92  sal_Int32 nStartPos = aStartPos.toInt32();
93 
94  itr = rParameters.find("END_POS");
95  assert(itr != rParameters.end());
96  OUString aEndPos = itr->second;
97  sal_Int32 nEndPos = aEndPos.toInt32();
98 
99  getWrtShell(mxEditWin).SelectText(nStartPos, nEndPos);
100  }
101  }
102  else if (rAction == "SIDEBAR")
103  {
104  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
105  DBG_ASSERT(pViewFrm, "SwEditWinUIObject::execute: no viewframe");
106  pViewFrm->ShowChildWindow(SID_SIDEBAR);
107 
108  if (rParameters.find("PANEL") != rParameters.end())
109  {
110  auto itr = rParameters.find("PANEL");
111  OUString aVal = itr->second;
113  }
114  }
115  else
116  WindowUIObject::execute(rAction, rParameters);
117 }
118 
120 {
121  return "SwEditWinUIObject";
122 }
123 
124 std::unique_ptr<UIObject> SwEditWinUIObject::create(vcl::Window* pWindow)
125 {
126  SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(pWindow);
127  assert(pEditWin);
128  return std::unique_ptr<UIObject>(new SwEditWinUIObject(pEditWin));
129 }
130 
132  WindowUIObject(xSwNavigationPI),
133  mxSwNavigationPI(xSwNavigationPI)
134 {
135 }
136 
138 {
140 
141  aMap["selectioncount"] = OUString::number(mxSwNavigationPI->m_aContentTree->GetSelectionCount());
142 
143  return aMap;
144 }
145 
146 void SwNavigationPIUIObject::execute(const OUString& rAction,
147  const StringMap& rParameters)
148 {
149  if (rAction == "ROOT")
150  {
152  }
153  else
154  WindowUIObject::execute(rAction, rParameters);
155 }
156 
157 std::unique_ptr<UIObject> SwNavigationPIUIObject::create(vcl::Window* pWindow)
158 {
159  SwNavigationPI* pSwNavigationPI = dynamic_cast<SwNavigationPI*>(pWindow);
160  assert(pSwNavigationPI);
161  return std::unique_ptr<UIObject>(new SwNavigationPIUIObject(pSwNavigationPI));
162 }
163 
165 {
166  return "SwNavigationPIUIObject";
167 }
168 
169 
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString get_name() const override
Definition: uiobject.cxx:119
bool IsSttPara() const
Definition: crsrsh.cxx:1082
const SwView & GetView() const
Definition: edtwin.hxx:241
bool IsStartOfDoc() const
Definition: crsrsh.cxx:2715
bool IsEndWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES) const
Definition: crstrvl1.cxx:31
void GetPageNum(sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum, bool bAtCursorPos=true, const bool bCalcFrame=true)
Definition: crsrsh.cxx:1196
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
bool IsStartSentence() const
Definition: crstrvl1.cxx:41
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
virtual StringMap get_state() override
SfxFrame & GetFrame() const
VclPtr< SwEditWin > mxEditWin
Definition: uiobject.hxx:38
SwEditWinUIObject(const VclPtr< SwEditWin > &xEditWin)
Definition: uiobject.cxx:19
virtual OUString GetSelectionText(bool bCompleteWords=false) override
Definition: view.cxx:1607
virtual StringMap get_state() override
Definition: uiobject.cxx:137
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:157
#define DBG_ASSERT(sCon, aError)
sal_uInt16 GetPageCnt()
Definition: crsrsh.cxx:1278
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:124
virtual StringMap get_state() override
Definition: uiobject.cxx:34
VclPtr< SwContentTree > m_aContentTree
Definition: navipi.hxx:75
std::map< const OUString, OUString > StringMap
static void ShowPanel(const OUString &rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
VclPtr< SwNavHelpToolBox > m_aContentToolBox
Definition: navipi.hxx:71
bool IsEndSentence() const
Definition: crstrvl1.cxx:45
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:131
void SetZoom(SvxZoomType eZoomType, short nFactor=100, bool bViewOnly=false)
Definition: viewmdi.cxx:82
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:146
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:63
static SfxViewFrame * Current()
void TriggerItem(sal_uInt16 nItemId)
void ShowChildWindow(sal_uInt16, bool bVisible=true)
bool IsEndOfDoc() const
Definition: crsrsh.cxx:2727
sal_uInt16 GetItemId(ImplToolItems::size_type nPos) const
bool IsEndPara() const
Definition: crsrsh.cxx:1101
VclPtr< SwNavigationPI > mxSwNavigationPI
Definition: uiobject.hxx:44
sal_uLong GetSelectionCount() const
OUString get_name() const override
Definition: uiobject.cxx:164