LibreOffice Module sw (master)  1
OutlineContentVisibilityWin.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 <edtwin.hxx>
12 #include <view.hxx>
13 #include <wrtsh.hxx>
14 
15 #include <memory>
16 
18 #include <txtfrm.hxx>
19 #include <ndtxt.hxx>
20 #include <vcl/button.hxx>
21 #include <vcl/event.hxx>
22 #include <strings.hrc>
23 #include <svx/svdview.hxx>
24 
25 #define BUTTON_WIDTH 18
26 #define BUTTON_HEIGHT 20
27 
29  const SwFrame* pFrame)
30  : PushButton(pEditWin, 0)
31  , m_pEditWin(pEditWin)
32  , m_pFrame(pFrame)
33  , m_nDelayAppearing(0)
34  , m_bDestroyed(false)
35  , m_nOutlinePos(SwOutlineNodes::npos)
36 {
38 
41 }
42 
44 {
45  m_bDestroyed = true;
47 
48  m_pEditWin.clear();
49  m_pFrame = nullptr;
50 
52 }
53 
55 {
56  const SwTextFrame* pTextFrame = static_cast<const SwTextFrame*>(GetFrame());
57 
58  // outline node frame containing folded outline node content might be folded so need to hide it
59  if (!pTextFrame || pTextFrame->IsInDtor())
60  {
61  SetSymbol(SymbolType::DONTKNOW);
62  Hide();
63  return;
64  }
65  const SwTextNode* pTextNode = pTextFrame->GetTextNodeFirst();
67  const SwOutlineNodes& rOutlineNodes = rSh.GetNodes().GetOutLineNds();
68  if (!pTextNode
69  || !rOutlineNodes.Seek_Entry(static_cast<SwNode*>(const_cast<SwTextNode*>(pTextNode)),
72  {
73  assert(false); // should never get here
74  return;
75  }
76 
77  // don't set if no content and no subs with content
78  auto nPos = m_nOutlinePos;
79  SwNode* pSttNd = rOutlineNodes[nPos];
80  SwNode* pEndNd;
81  SwNodeIndex aIdx(*pSttNd);
82  while (true)
83  {
84  if (rOutlineNodes.size() > ++nPos)
85  pEndNd = rOutlineNodes[nPos];
86  else
87  pEndNd = &rSh.GetNodes().GetEndOfContent();
88  if (!pSttNd->IsEndNode())
89  aIdx.Assign(*pSttNd, +1);
90  if (pSttNd->IsEndNode()
91  || ((&aIdx.GetNode() == pEndNd && pEndNd->IsEndNode())
92  || (&aIdx.GetNode() == pEndNd && pSttNd->IsTextNode() && pEndNd->IsTextNode()
93  && pSttNd->GetTextNode()->GetAttrOutlineLevel()
94  >= pEndNd->GetTextNode()->GetAttrOutlineLevel())))
95  {
96  SetSymbol(SymbolType::DONTKNOW);
97  Hide();
98  return;
99  }
100  if (&aIdx.GetNode() != pEndNd)
101  break;
102  pSttNd = pEndNd;
103  }
104 
105  // set symbol displayed on button
106  SetSymbol(rSh.IsOutlineContentFolded(m_nOutlinePos) ? SymbolType::ARROW_RIGHT
107  : SymbolType::ARROW_DOWN);
108 
109  // set quick help
110  SwOutlineNodes::size_type nOutlineNodesCount
113  OUString sQuickHelp(SwResId(STR_OUTLINE_CONTENT_TOGGLE_VISIBILITY));
114  if (m_nOutlinePos + 1 < nOutlineNodesCount
116  sQuickHelp += " (" + SwResId(STR_OUTLINE_CONTENT_TOGGLE_VISIBILITY_EXT) + ")";
117  SetQuickHelpText(sQuickHelp);
118 
119  // Set the position of the window
120  SwRect aSwRect = GetFrame()->getFrameArea(); // not far in margin
121  //SwRect aSwRect = GetFrame()->GetPaintArea(); // far in margin
122  aSwRect.AddTop(GetFrame()->GetTopMargin());
124  aSwRect.TopLeft() - (aSwRect.TopLeft() - aSwRect.BottomLeft()) / 2));
125  aPxPt.AdjustX(-GetSizePixel().getWidth() + 1);
126  aPxPt.AdjustY(-GetSizePixel().getHeight() / 2);
127  SetPosPixel(aPxPt);
128 }
129 
131 {
132  if (bShow)
133  {
134  m_nDelayAppearing = 0;
137  if (!m_bDestroyed)
139  }
140  else
141  Hide();
142 }
143 
144 bool SwOutlineContentVisibilityWin::Contains(const Point& rDocPt) const
145 {
147  if (aRect.IsInside(rDocPt))
148  return true;
149  return false;
150 }
151 
153 {
155  rSh.LockView(true);
156  if (GetEditWin()->GetView().GetDrawView()->IsTextEdit())
157  rSh.EndTextEdit();
158  if (GetEditWin()->GetView().IsDrawMode())
160  rSh.EnterStdMode();
161  // set cursor position here so Navigator tracks outline
162  // when doc changed broadcast message is sent in toggle function
164  if (bSubs)
165  {
166  // toggle including sub levels
168  SwOutlineNodes::size_type nOutlineNodesCount
171  bool bFold = rSh.IsOutlineContentFolded(m_nOutlinePos);
172  do
173  {
174  if (rSh.IsOutlineContentFolded(nPos) == bFold)
176  } while (++nPos < nOutlineNodesCount
177  && rSh.getIDocumentOutlineNodesAccess()->getOutlineLevel(nPos) > nLevel);
178  }
179  else
181  SetSymbol(rSh.IsOutlineContentFolded(m_nOutlinePos) ? SymbolType::ARROW_RIGHT
182  : SymbolType::ARROW_DOWN);
183  rSh.LockView(false);
184 }
185 
187 {
188  vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
189  if (!aKeyCode.GetModifier()
190  && (aKeyCode.GetCode() == KEY_RETURN || aKeyCode.GetCode() == KEY_SPACE))
191  {
193  }
194  else if (aKeyCode.GetCode() == KEY_ESCAPE)
195  {
196  Hide();
198  }
199 }
200 
202 {
203  if (rMEvt.IsLeaveWindow())
204  {
205  // MouseMove event may not be seen by edit window
206  // hide collapse button and grab focus to document
207  if (GetSymbol() != SymbolType::ARROW_RIGHT)
208  Hide();
210  }
211  else if (rMEvt.IsEnterWindow())
212  {
215  // bring button to top and grab focus
216  SetZOrder(this, ZOrderFlags::First);
217  GrabFocus();
218  }
219  GetEditWin()->SetSavedOutlineFrame(const_cast<SwFrame*>(GetFrame()));
220 }
221 
223 {
225 }
226 
228 {
229  const int TICKS_BEFORE_WE_APPEAR = 5;
230  if (m_nDelayAppearing < TICKS_BEFORE_WE_APPEAR)
231  {
232  ++m_nDelayAppearing;
233  m_aDelayTimer.Start();
234  return;
235  }
236  if (GetEditWin()->GetSavedOutlineFrame() == GetFrame())
237  {
238  Show();
239  GrabFocus();
240  }
241  m_aDelayTimer.Stop();
242 }
243 
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Point GetPosPixel() const
Base class of the Writer layout elements.
Definition: frame.hxx:298
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
const SwNodes & GetNodes() const
Definition: viewsh.cxx:2090
virtual bool Contains(const Point &rDocPt) const override
Returns true if the point is inside the control.
const SwView & GetView() const
Definition: edtwin.hxx:244
const IDocumentOutlineNodes * getIDocumentOutlineNodesAccess() const
Definition: viewsh.cxx:2690
virtual SwEditWin * GetEditWin() override
virtual Size GetSizePixel() const
virtual void SetSizePixel(const Size &rNewSize)
sal_uInt16 GetCode() const
SwNode & GetNode() const
Definition: ndindex.hxx:119
void EnterStdMode()
Definition: select.cxx:550
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
constexpr sal_uInt16 KEY_SPACE
void SetQuickHelpText(const OUString &rHelpText)
int GetAttrOutlineLevel() const
Returns outline level of this text node.
Definition: ndtxt.cxx:3998
virtual void dispose() override
SwWrtShell & GetWrtShell() const
Definition: view.hxx:399
void AddTop(const tools::Long nAdd)
Definition: swrect.cxx:165
bool IsActive() const
bool IsOutlineContentFolded(const size_t nPos)
Definition: wrtsh1.cxx:1992
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
Point TopLeft() const
Definition: swrect.cxx:174
virtual const SwFrame * GetFrame() override
void ToggleOutlineContentVisibility(SwNode *pNd, bool bForceFold=false)
Definition: wrtsh1.cxx:2010
void SetSymbol(SymbolType eSymbol)
int m_nDelayAppearing
Before we show the control, wait a few timer ticks to avoid appearing with every mouse over...
const SwRect & getFrameArea() const
Definition: frame.hxx:178
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
#define BUTTON_WIDTH
bool IsEnterWindow() const
void SetSavedOutlineFrame(SwFrame *pFrame)
Definition: edtwin.hxx:295
sal_uInt16 GetModifier() const
size_type size() const
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:163
SwTextNode * GetTextNodeFirst()
Definition: txtfrm.hxx:448
bool IsInDtor() const
Definition: frame.hxx:873
void clear()
static constexpr auto npos
Definition: ndarr.hxx:79
bool IsLeaveWindow() const
#define BUTTON_HEIGHT
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
void ToggleOutlineContentVisibility(const bool bSubs)
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
virtual int getOutlineLevel(const tSortedOutlineNodeList::size_type nIdx) const =0
virtual tSortedOutlineNodeList::size_type getOutlineNodesCount() const =0
virtual void MouseMove(const MouseEvent &rMEvt) override
virtual void Start() override
void GrabFocusToDocument()
bool IsInside(const Point &rPOINT) const
Marks a node in the document model.
Definition: ndindex.hxx:31
bool IsEndNode() const
Definition: node.hxx:635
const SwOutlineNodes & GetOutLineNds() const
Array of all OutlineNodes.
Definition: ndarr.hxx:231
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
void LeaveDrawCreate()
Definition: view.hxx:524
virtual void ShowAll(bool bShow) override
void SetTimeout(sal_uInt64 nTimeoutMs)
void GrabFocus()
constexpr sal_uInt16 KEY_RETURN
Point LogicToPixel(const Point &rLogicPt) const
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
const vcl::KeyCode & GetKeyCode() const
void Stop()
SwOutlineContentVisibilityWin(SwEditWin *pEditWin, const SwFrame *pFrame)
void LockView(bool b)
Definition: viewsh.hxx:462
constexpr sal_uInt16 KEY_ESCAPE
::OutputDevice const * GetOutDev() const
IMPL_LINK_NOARG(SwOutlineContentVisibilityWin, DelayHandler, Timer *, void)
void GotoOutline(SwOutlineNodes::size_type nIdx)
Definition: move.cxx:612
void EndTextEdit()
Deletes object if required.
Definition: feshview.cxx:1217
void SetInvokeHandler(const Link< Timer *, void > &rLink)
void SetZOrder(vcl::Window *pRefWindow, ZOrderFlags nFlags)
bool IsRight() const
bool Seek_Entry(SwNode *rP, size_type *pnPos) const
Definition: ndnum.cxx:32
std::vector< SwNode * >::size_type size_type
virtual void KeyInput(const KeyEvent &rKEvt) override
bool IsTextNode() const
Definition: node.hxx:639
virtual void SetPosPixel(const Point &rNewPos)
SymbolType GetSymbol() const
sal_uInt16 nPos
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:845
SwNodeIndex & Assign(SwNodes const &rNds, sal_uLong)
Definition: ndindex.hxx:272
Point BottomLeft() const
Definition: swrect.cxx:176
Base class of the Writer document model elements.
Definition: node.hxx:79