Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / source / uibase / uitest / uiobject.cxx
blobeb1f23677fd92373c4be9d583fcf2a0a5dbf8275
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <memory>
11 #include "uiobject.hxx"
12 #include "edtwin.hxx"
13 #include "view.hxx"
14 #include "wrtsh.hxx"
16 SwEditWinUIObject::SwEditWinUIObject(VclPtr<SwEditWin> xEditWin):
17 WindowUIObject(xEditWin),
18 mxEditWin(xEditWin)
22 namespace {
24 SwWrtShell& getWrtShell(VclPtr<SwEditWin> const & xEditWin)
26 return xEditWin->GetView().GetWrtShell();
31 StringMap SwEditWinUIObject::get_state()
33 StringMap aMap = WindowUIObject::get_state();
35 aMap["SelectedText"] = mxEditWin->GetView().GetSelectionText();
37 sal_uInt16 nPageNum = 0;
38 sal_uInt16 nVirtPageNum = 0;
39 SwWrtShell& rWrtShell = getWrtShell(mxEditWin);
40 rWrtShell.GetPageNum(nPageNum, nVirtPageNum);
41 aMap["CurrentPage"] = OUString::number(nPageNum);
42 rWrtShell.GetPageNum(nPageNum, nVirtPageNum, false);
43 aMap["TopVisiblePage"] = OUString::number(nPageNum);
45 sal_uInt16 nPages = rWrtShell.GetPageCnt();
46 aMap["Pages"] = OUString::number(nPages);
48 aMap["StartWord"] = OUString::boolean(rWrtShell.IsStartWord());
49 aMap["EndWord"] = OUString::boolean(rWrtShell.IsEndWord());
50 aMap["StartSentence"] = OUString::boolean(rWrtShell.IsStartSentence());
51 aMap["EndSentence"] = OUString::boolean(rWrtShell.IsEndSentence());
52 aMap["StartPara"] = OUString::boolean(rWrtShell.IsSttPara());
53 aMap["EndPara"] = OUString::boolean(rWrtShell.IsEndPara());
54 aMap["StartDoc"] = OUString::boolean(rWrtShell.IsStartOfDoc());
55 aMap["EndDoc"] = OUString::boolean(rWrtShell.IsEndOfDoc());
57 return aMap;
60 void SwEditWinUIObject::execute(const OUString& rAction,
61 const StringMap& rParameters)
63 if (rAction == "SET")
65 if (rParameters.find("ZOOM") != rParameters.end())
67 auto itr = rParameters.find("ZOOM");
68 OUString aVal = itr->second;
69 sal_Int32 nVal = aVal.toInt32();
70 mxEditWin->GetView().SetZoom(SvxZoomType::PERCENT, nVal);
73 else if (rAction == "GOTO")
75 if (rParameters.find("PAGE") != rParameters.end())
77 auto itr = rParameters.find("PAGE");
78 OUString aVal = itr->second;
79 sal_Int32 nVal = aVal.toInt32();
80 getWrtShell(mxEditWin).GotoPage(nVal, false);
83 else if (rAction == "SELECT")
85 if (rParameters.find("START_POS") != rParameters.end())
87 auto itr = rParameters.find("START_POS");
88 OUString aStartPos = itr->second;
89 sal_Int32 nStartPos = aStartPos.toInt32();
91 itr = rParameters.find("END_POS");
92 assert(itr != rParameters.end());
93 OUString aEndPos = itr->second;
94 sal_Int32 nEndPos = aEndPos.toInt32();
96 getWrtShell(mxEditWin).SelectText(nStartPos, nEndPos);
99 else
100 WindowUIObject::execute(rAction, rParameters);
103 OUString SwEditWinUIObject::get_name() const
105 return OUString("SwEditWinUIObject");
108 std::unique_ptr<UIObject> SwEditWinUIObject::create(vcl::Window* pWindow)
110 SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(pWindow);
111 assert(pEditWin);
112 return std::unique_ptr<UIObject>(new SwEditWinUIObject(pEditWin));
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */