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 <ndtxt.hxx>
16#include <viewopt.hxx>
18#include <sfx2/viewfrm.hxx>
19
20#include <AnnotationWin.hxx>
21#include <editeng/editeng.hxx>
22#include <editeng/editview.hxx>
23
25 WindowUIObject(xEditWin),
26 mxEditWin(xEditWin)
27{
28}
29
30namespace {
31
32SwWrtShell& 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 aMap["Zoom"] = OUString::number(rWrtShell.GetViewOptions()->GetZoom());
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
69void 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 TextFrameIndex const nStartPos(aStartPos.toInt32());
99
100 itr = rParameters.find("END_POS");
101 assert(itr != rParameters.end());
102 OUString aEndPos = itr->second;
103 TextFrameIndex const nEndPos(aEndPos.toInt32());
104
105 auto & shell = getWrtShell(mxEditWin);
106 if (shell.GetCursor_()->GetPoint()->GetNode().GetTextNode())
107 {
108 shell.Push();
109 shell.MovePara(GoCurrPara, fnParaEnd);
110 TextFrameIndex const len(shell.GetCursorPointAsViewIndex());
113 sal_Int32(nStartPos) < 0 || nStartPos > len || sal_Int32(nEndPos) < 0 || nEndPos > len, "sw.ui",
114 "SELECT START/END_POS " << sal_Int32(nStartPos) << ".." << sal_Int32(nEndPos) << " outside 0.." << sal_Int32(len));
115 shell.SelectTextView(
116 std::clamp(nStartPos, TextFrameIndex(0), len), std::clamp(nEndPos, TextFrameIndex(0), len));
117 }
118 else
119 {
120 SAL_WARN("sw.ui", "SELECT without SwTextNode");
121 }
122 }
123 }
124 else if (rAction == "SIDEBAR")
125 {
127 DBG_ASSERT(pViewFrm, "SwEditWinUIObject::execute: no viewframe");
128 pViewFrm->ShowChildWindow(SID_SIDEBAR);
129
130 if (rParameters.find("PANEL") != rParameters.end())
131 {
132 auto itr = rParameters.find("PANEL");
133 OUString aVal = itr->second;
135 }
136 }
137 else
138 WindowUIObject::execute(rAction, rParameters);
139}
140
142{
143 return "SwEditWinUIObject";
144}
145
146std::unique_ptr<UIObject> SwEditWinUIObject::create(vcl::Window* pWindow)
147{
148 SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(pWindow);
149 assert(pEditWin);
150 return std::unique_ptr<UIObject>(new SwEditWinUIObject(pEditWin));
151}
152
154 WindowUIObject(xCommentUIObject),
155 mxCommentUIObject(xCommentUIObject)
156{
157}
158
160{
162 aMap["Author"] = mxCommentUIObject->GetAuthor();
163 aMap["ReadOnly"] = OUString::boolean(mxCommentUIObject->IsReadOnly());
164 aMap["Resolved"] = OUString::boolean(mxCommentUIObject->IsResolved());
165 aMap["Visible"] = OUString::boolean(mxCommentUIObject->IsVisible());
166
167 aMap["Text"] = mxCommentUIObject->GetOutliner()->GetEditEngine().GetText();
168 aMap["SelectedText"] = mxCommentUIObject->GetOutlinerView()->GetEditView().GetSelected();
169 return aMap;
170}
171
172void CommentUIObject::execute(const OUString& rAction,
173 const StringMap& rParameters)
174{
175 if (rAction == "SELECT")
176 {
177 if (rParameters.find("FROM") != rParameters.end() &&
178 rParameters.find("TO") != rParameters.end())
179 {
180 tools::Long nMin = rParameters.find("FROM")->second.toInt32();
181 tools::Long nMax = rParameters.find("TO")->second.toInt32();
182 ESelection aNewSelection( 0 , nMin, mxCommentUIObject->GetOutliner()->GetParagraphCount()-1, nMax );
183 mxCommentUIObject->GetOutlinerView()->SetSelection( aNewSelection );
184 }
185 }
186 else if (rAction == "LEAVE")
187 {
188 mxCommentUIObject->SwitchToFieldPos();
189 }
190 else if (rAction == "HIDE")
191 {
192 mxCommentUIObject->HideNote();
193 }
194 else if (rAction == "SHOW")
195 {
196 mxCommentUIObject->ShowNote();
197 }
198 else if (rAction == "DELETE")
199 {
200 mxCommentUIObject->Delete();
201 }
202 else if (rAction == "RESOLVE")
203 {
204 mxCommentUIObject->SetResolved(true);
205 }
206 else
207 WindowUIObject::execute(rAction, rParameters);
208}
209
210std::unique_ptr<UIObject> CommentUIObject::create(vcl::Window* pWindow)
211{
212 sw::annotation::SwAnnotationWin* pCommentUIObject = dynamic_cast<sw::annotation::SwAnnotationWin*>(pWindow);
213 assert(pCommentUIObject);
214 return std::unique_ptr<UIObject>(new CommentUIObject(pCommentUIObject));
215}
216
218{
219 return "CommentUIObject";
220}
221
223 WindowUIObject(xPageBreakUIObject),
224 mxPageBreakUIObject(xPageBreakUIObject)
225{
226}
227
228void PageBreakUIObject::execute(const OUString& rAction,
229 const StringMap& rParameters)
230{
231 if (rAction == "DELETE" || rAction == "EDIT")
232 mxPageBreakUIObject->execute(rAction.toAsciiLowerCase().toUtf8());
233 else
234 WindowUIObject::execute(rAction, rParameters);
235}
236
237std::unique_ptr<UIObject> PageBreakUIObject::create(vcl::Window* pWindow)
238{
239 SwBreakDashedLine* pPageBreakWin = dynamic_cast<SwBreakDashedLine*>(pWindow);
240 assert(pPageBreakWin);
241 return std::unique_ptr<UIObject>(new PageBreakUIObject(pPageBreakWin));
242}
243
245{
246 return "PageBreakUIObject";
247}
248
249/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
OUString get_name() const override
Definition: uiobject.cxx:217
CommentUIObject(const VclPtr< sw::annotation::SwAnnotationWin > &xCommentUIObject)
Definition: uiobject.cxx:153
virtual StringMap get_state() override
Definition: uiobject.cxx:159
VclPtr< sw::annotation::SwAnnotationWin > mxCommentUIObject
Definition: uiobject.hxx:45
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:210
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:172
PageBreakUIObject(const VclPtr< SwBreakDashedLine > &xEditWin)
Definition: uiobject.cxx:222
VclPtr< SwBreakDashedLine > mxPageBreakUIObject
Definition: uiobject.hxx:79
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:228
virtual OUString get_name() const override
Definition: uiobject.cxx:244
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:237
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
static SfxViewFrame * Current()
SfxFrame & GetFrame() const
void ShowChildWindow(sal_uInt16, bool bVisible=true)
Class for the page break control window.
bool IsStartSentence() const
Definition: crstrvl1.cxx:41
bool IsEndPara() const
Definition: crsrsh.cxx:1114
bool IsSttPara() const
Definition: crsrsh.cxx:1095
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:1209
bool IsStartOfDoc() const
Definition: crsrsh.cxx:2767
bool IsEndOfDoc() const
Definition: crsrsh.cxx:2779
bool IsStartWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES) const
Definition: crstrvl1.cxx:27
bool IsEndSentence() const
Definition: crstrvl1.cxx:45
sal_uInt16 GetPageCnt()
Definition: crsrsh.cxx:1291
virtual StringMap get_state() override
Definition: uiobject.cxx:39
SwEditWinUIObject(const VclPtr< SwEditWin > &xEditWin)
Definition: uiobject.cxx:24
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:146
VclPtr< SwEditWin > mxEditWin
Definition: uiobject.hxx:38
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:69
virtual OUString get_name() const override
Definition: uiobject.cxx:141
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:61
sal_uInt16 GetZoom() const
Definition: viewopt.hxx:613
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:433
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
virtual StringMap get_state() override
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
static void ShowPanel(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
#define DBG_ASSERT(sCon, aError)
ESelection aNewSelection(GetSelection())
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
long Long
HashMap_OWString_Interface aMap
bool GoCurrPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
Definition: pam.cxx:1224
SwMoveFnCollection const & fnParaEnd
Definition: paminit.cxx:49
std::map< OUString, OUString > StringMap